@adhdev/daemon-standalone 0.8.3 → 0.8.5
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.
- package/dist/index.js +39 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/index-D0aXnIOE.css +1 -0
- package/public/assets/index-rG_uc9Km.js +62 -0
- package/public/index.html +2 -2
- package/public/assets/index-CTcsu95F.css +0 -1
- package/public/assets/index-Cuj6Bj52.js +0 -62
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-PD6SznsC.js","assets/vendor-CPghmr9Y.js","assets/terminal-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
var ra=Object.defineProperty;var aa=(t,s,n)=>s in t?ra(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Be=(t,s,n)=>aa(t,typeof s!="symbol"?s+"":s,n);import{r as a,j as e,M as $n,a as Dn,b as ia,c as oa,u as wt,R as Ls,t as ca,d as la,e as da,D as ua,f as pa,g as xa,h as Ps,i as ma,k as fa,B as ha,l as ba,m as rt,N as Cs,n as ga}from"./vendor-CPghmr9Y.js";import{_ as ya}from"./terminal-PD6SznsC.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&r(c)}).observe(document,{childList:!0,subtree:!0});function n(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(i){if(i.ep)return;i.ep=!0;const o=n(i);fetch(i.href,o)}})();const Bn=a.createContext({ides:[],updateIdeChats:()=>{},initialLoaded:!1,toasts:[],setToasts:()=>{},wsStatus:"connected",isConnected:!0,connectionStates:{},connectionTransports:{},showReconnected:!1,userName:void 0,setUserName:()=>{},isP2PActive:!1,p2pStates:{},userRole:void 0}),Kn=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function tn(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 hs(t,s,n){if(n.type!=="adhdev-daemon")return n;const r={...n},i=s.version??n.version??t.version,o=s.serverVersion??t.serverVersion??n.serverVersion,c=s.versionMismatch===!0||t.versionMismatch===!0;return i&&(r.version=i),o&&(r.serverVersion=o),i&&o&&i===o?(delete r.versionMismatch,delete r.serverVersion,r):((s.versionMismatch===!0||c&&i&&o&&i!==o)&&(r.versionMismatch=!0),r)}function va(t,s,n){var l,f,u,m,h,p,g;const r=Date.now(),i=new Set((n==null?void 0:n.authoritativeDaemonIds)||[]);if(s.length===0)return t.map(x=>({...x,_lastUpdate:r}));const o=new Map;for(const x of s)o.set(x.id,x);for(const x of t){const j=o.get(x.id);if(!j){o.set(x.id,{...x,_lastUpdate:r});continue}const v=tn(x),y=tn(j);if(v>y){const w=(l=x.chats)!=null&&l.length?x.chats:j.chats,T=hs(j,x,{...j,...x,chats:w,_lastUpdate:r});o.set(x.id,T)}else if(v<y){const w={};if(x.status&&x.status!==j.status&&(w.status=x.status),x.cdpConnected!==void 0&&(w.cdpConnected=x.cdpConnected),(f=x.chats)!=null&&f.length&&!((u=j.chats)!=null&&u.length)&&(w.chats=x.chats),x.machineNickname!==void 0&&x.machineNickname!==j.machineNickname&&(w.machineNickname=x.machineNickname),x.version!==void 0&&(w.version=x.version),x.serverVersion!==void 0&&(w.serverVersion=x.serverVersion),x.versionMismatch===!0&&(w.versionMismatch=!0),Object.keys(w).length>0){const T=hs(j,x,{...j,...w,_lastUpdate:j._lastUpdate});o.set(x.id,T)}}else{const w=x.timestamp||r,T=j._lastUpdate||j.timestamp||0;if(w>=T){const b=(m=x.chats)!=null&&m.length?x.chats:j.chats,M=hs(j,x,{...j,...x,chats:b,_lastUpdate:r});o.set(x.id,M)}else(h=x.chats)!=null&&h.length&&!((p=j.chats)!=null&&p.length)&&o.set(x.id,{...j,chats:x.chats})}}const c=new Set(t.map(x=>x.id)),d=new Set;for(const x of t){const j=x.daemonId||((g=x.id)==null?void 0:g.split(":")[0]);j&&d.add(j)}for(const[x,j]of o){const v=j.daemonId||x.split(":")[0];if(!d.has(v))continue;if(i.has(v)&&!c.has(x)){o.delete(x);continue}const y=r-(j._lastUpdate||j.timestamp||0);(j.transport==="pty"&&!c.has(x)&&y>1e4||j.transport==="acp"&&!c.has(x)&&y>1e4||j.transport==="cdp-page"&&!c.has(x)&&y>3e4)&&o.delete(x)}for(const[x,j]of o)r-(j._lastUpdate||j.timestamp||0)>3e5&&j.status!=="online"&&o.delete(x);return Array.from(o.values())}function wa(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 ja({children:t,connectionOverrides:s}){const[n,r]=a.useState([]),[i,o]=a.useState(!1),[c,d]=a.useState([]),[l,f]=a.useState(void 0),u=a.useRef(n);a.useEffect(()=>{u.current=n},[n]);const m=a.useCallback((v,y)=>{r(w=>{let T=!1;const b=w.map(M=>M.id!==v||M.chats===y?M:(T=!0,{...M,chats:y}));return T?b:w})},[]),h=a.useCallback((v,y)=>{r(w=>{const T=w.length===0?v:va(v,w,y);return wa(w,T)?w:T})},[]),p=a.useCallback(()=>o(!0),[]),g=a.useMemo(()=>({injectEntries:h,markLoaded:p,getIdes:()=>u.current}),[h,p]),x=s,j=a.useMemo(()=>({ides:n,updateIdeChats:m,initialLoaded:i,toasts:c,setToasts:d,wsStatus:(x==null?void 0:x.wsStatus)??"connected",isConnected:(x==null?void 0:x.isConnected)??!0,connectionStates:(x==null?void 0:x.connectionStates)??{},connectionTransports:(x==null?void 0:x.connectionTransports)??{},showReconnected:(x==null?void 0:x.showReconnected)??!1,retryConnection:x==null?void 0:x.retryConnection,isP2PActive:(x==null?void 0:x.isP2PActive)??!1,p2pStates:(x==null?void 0:x.p2pStates)??{},userRole:x==null?void 0:x.userRole,userName:l,setUserName:f}),[n,m,i,c,x==null?void 0:x.wsStatus,x==null?void 0:x.isConnected,x==null?void 0:x.connectionStates,x==null?void 0:x.connectionTransports,x==null?void 0:x.showReconnected,x==null?void 0:x.retryConnection,x==null?void 0:x.isP2PActive,x==null?void 0:x.p2pStates,x==null?void 0:x.userRole,l]);return e.jsx(Kn.Provider,{value:g,children:e.jsx(Bn.Provider,{value:j,children:t})})}function Rt(){return a.useContext(Bn)}function sn(){return a.useContext(Kn)}function Wn(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;function i(d){return d.startsWith("http")?d:`${s}${d.startsWith("/")?"":"/"}${d}`}function o(d){const l=n==null?void 0:n(),f=i(d),u=d.startsWith("http")?new URL(f):new URL(f,typeof window<"u"?window.location.origin:"http://localhost");return l&&u.searchParams.set("token",l),!d.startsWith("http")&&!s?`${u.pathname}${u.search}${u.hash}`:u.toString()}async function c(d,l={}){const f={"Content-Type":"application/json",...l.headers||{}},u=n==null?void 0:n();u&&(f.Authorization=`Bearer ${u}`);const m=i(d),h=await fetch(m,{...l,headers:f});if(h.status===401)throw r==null||r(),new Error("Unauthorized");if(!h.ok){const p=await h.json().catch(()=>({error:h.statusText}));throw new Error(p.error||`API Error: ${h.status}`)}return h.json()}return{getDaemons:()=>c("/api/v1/daemons"),getDaemonStatus:d=>c(`/api/v1/daemons/${d}/status`),sendCommand:(d,l,f={})=>c(`/api/v1/daemons/${d}/command`,{method:"POST",body:JSON.stringify({type:l,payload:f})}),execTerminal:(d,l,f)=>c(`/api/v1/daemons/${d}/terminal`,{method:"POST",body:JSON.stringify({command:l,name:f})}),sendAgentMessage:(d,l,f)=>c(`/api/v1/shortcuts/${d}/chat`,{method:"POST",body:JSON.stringify({agentType:l,message:f})}),getAgentStatus:d=>c(`/api/v1/shortcuts/${d}/status`),approveAgent:(d,l,f)=>c(`/api/v1/shortcuts/${d}/approve`,{method:"POST",body:JSON.stringify({agentType:l,action:f?"approve":"reject"})}),getMuxState:d=>c(`/api/v1/mux/${encodeURIComponent(d)}/state`),getMuxSocketInfo:d=>c(`/api/v1/mux/${encodeURIComponent(d)}/socket-info`),controlMux:(d,l,f={})=>c(`/api/v1/mux/${encodeURIComponent(d)}/control`,{method:"POST",body:JSON.stringify({type:l,payload:f})}),getMuxEventsUrl:d=>o(`/api/v1/mux/${encodeURIComponent(d)}/events`),getRuntimeEventsUrl:d=>o(`/api/v1/runtime/${encodeURIComponent(d)}/events`),request:c}}const ka=Wn({baseUrl:"http://localhost:3847"}),Na=a.createContext(ka);function Sa({client:t,children:s}){return e.jsx(Na.Provider,{value:t,children:s})}const Ca={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},On=a.createContext(Ca);function Ia({value:t,children:s}){return e.jsx(On.Provider,{value:t,children:s})}function ct(){return a.useContext(On)}const ke={size:18};function zn({size:t=ke.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 Es({size:t=ke.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}function Jt({size:t=ke.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 Ma({size:t=ke.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 Un({size:t=ke.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 Ta({size:t=ke.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 Qt({size:t=ke.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 _a({size:t=ke.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 os({size:t=ke.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 Hn({size:t=ke.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 Fn({size:t=ke.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 ot({size:t=ke.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 ze({size:t=ke.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),e.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function $s({size:t=ke.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 Ra({size:t=ke.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 At({size:t=ke.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 Ds({size:t=ke.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 Bs({size:t=ke.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 gt({size:t=ke.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 Vn({size:t=ke.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 Aa({size:t=ke.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:"M17.94 17.94A10.94 10.94 0 0 1 12 20C5 20 1 12 1 12a21.8 21.8 0 0 1 5.06-5.94"}),e.jsx("path",{d:"M9.9 4.24A10.93 10.93 0 0 1 12 4c7 0 11 8 11 8a21.77 21.77 0 0 1-2.16 3.19"}),e.jsx("path",{d:"M14.12 14.12a3 3 0 1 1-4.24-4.24"}),e.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function qn({size:t=ke.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 La({size:t=ke.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 Ks({size:t=ke.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 Gn({size:t=ke.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:"5 3 19 12 5 21 5 3"})})}function yt({size:t=ke.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Yn({size:t=ke.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 Pa({size:t=ke.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 Ea({size:t=ke.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 $a({size:t=ke.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 cs({size:t=ke.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 Da({size:t=ke.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 Ba({size:t=ke.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 Ka({size:t=ke.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 Wa({size:t=ke.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 Oa(t){var l,f;const s=u=>u.replace(/^\d+;/,"").replace(/\u0007/g,"").trim(),r=t.split(`
|
|
3
|
-
`).map(u=>{if(!u.includes("\r"))return u;const m=u.split("\r").map(g=>g.trim()).filter(Boolean);if(m.length===0)return"";const h=m.filter(g=>g.startsWith("⏺"));if(h.length>0)return h[h.length-1];const p=m.filter(g=>!(/^[❯›>]\s*$/.test(g)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(g)&&g.length<40||/^[╭╰│├╮╯─═]+$/.test(g)));return p.length>0?p[p.length-1]:m[m.length-1]}).join(`
|
|
4
|
-
`).split(`
|
|
5
|
-
`),i={},o=[];let c=!1;for(const u of r){const m=s(u);if(m===""){c=!1,o.push("");continue}if(/^❯\s*$/.test(m)||/^>\s*$/.test(m)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(m)||/^◐\s/.test(m)||/\/effort/.test(m)||/^⎿\s+(Tip|Note|Hint):/.test(m)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(m)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(m)||/Brewing[…\.]{0,3}\s*\d*$/i.test(m)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(m)||/^Auto-updating/i.test(m)||/^✳\s*Debug (?:Claude Code|Codex) CLI/i.test(m)||/^(?:─|═|╭|╰|│|├|╮|╯|┌|┐|└|┘|┬|┴|┼)+$/.test(m))continue;if(/^[⏺●·⏵]/.test(u)){const p=u.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(p)i[p[1]]=(i[p[1]]||0)+1;else{const g=u.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);g&&(i[g]=(i[g]||0)+1)}c=!0;continue}if(/^(?:Bash|Read|Write|Edit|MultiEdit|Task|Glob|Grep|LS|NotebookEdit|Exact output)(?:\(|:)/.test(m)){const p=((f=(l=m.match(/^([A-Za-z][A-Za-z0-9_ ]+)/))==null?void 0:l[1])==null?void 0:f.trim())||"Tool";i[p]=(i[p]||0)+1,c=!0;continue}if(/^Read\s+\d+\s+files?(?:\s+\(.*\))?$/i.test(m)){i.Read=(i.Read||0)+1,c=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(u)||/^[╭╰│├╮╯─]+/.test(m)||/^\s+[⊙✓✗○◎▸►✦]/.test(u)||c&&/^\s{2,}/.test(u))continue;c=!1;const h=m.replace(/^❯\s+/,"");o.push(h)}const d=o.join(`
|
|
6
|
-
`).replace(/\n{3,}/g,`
|
|
7
|
-
|
|
8
|
-
`).trim();return{toolCounts:i,textContent:d,hasTools:Object.keys(i).length>0}}function Is(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function za(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function ht(t,s){const n=t,r=typeof n.content=="string"?n.content:Array.isArray(n.content)?n.content.map(o=>(o==null?void 0:o.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 nn=700,Ua=a.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx($n,{remarkPlugins:[Dn],children:s.text}),e.jsx("span",{className:"action-time",children:Is(s.timestamp)})]})},(t,s)=>t.log===s.log),Ha=a.memo(function({message:s,receivedAt:n,agentName:r,userName:i,isCliMode:o,isExpanded:c,isTextExpanded:d,onToggleExpanded:l,onToggleTextExpanded:f}){var T;const u=(s.role||"").toLowerCase(),m=u==="user"||u==="human",h=s.kind||(u==="tool"?"tool":"standard"),p=typeof s.content=="string"?s.content:(s.content||[]).map(b=>b.text||"").join(`
|
|
10
|
-
`);if(h==="thought"){const b=((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(Ea,{size:13}),e.jsx("span",{children:b})]}),e.jsx("div",{className:"chat-msg-body",children:p})]})}if(h==="tool")return e.jsxs("div",{className:"self-start chat-msg-tool",children:[e.jsx("span",{className:"tool-icon",children:"⏺"}),e.jsx("span",{className:"tool-text",children:p.split(`
|
|
11
|
-
`)[0].slice(0,80)})]});if(h==="terminal"){const b=s.meta||{},M=b.isRunning?"⏳":"✅",N=b.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:M}),e.jsx("span",{children:N})]}),e.jsx("pre",{className:"chat-msg-body",children:p})]})}if(h==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:p.slice(0,100)});const g=!m&&o?Oa(p):null,x=g?g.textContent:p,j=g?Object.entries(g.toolCounts):[],v=o&&!m&&!c&&x.length>nn,y=c?p:v&&!d?x.slice(0,nn):x,w=za(y);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${m?"self-end":"self-start"}`,children:[j.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[j.map(([b,M])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",b,M>1?` ×${M}`:""]},b)),(g==null?void 0:g.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:c?"Collapse":"Original"}),!x&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Is(n)})]}),(x||m)&&e.jsxs("div",{className:`chat-bubble ${m?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${x?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:m?i||"You":s.senderName||r}),n!=null&&e.jsx("span",{className:"chat-time",children:Is(n)})]}),x&&e.jsx("div",{className:"chat-markdown",children:w?e.jsx($n,{remarkPlugins:[Dn,ia,oa],children:y}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:y})}),v&&e.jsx("button",{onClick:f,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:d?"Collapse ↑":`Show more (${Math.round(x.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),Fa=a.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:d="",receivedAtMap:l={},emptyState:f,onLoadMore:u,isLoadingMore:m,hasMoreHistory:h,hiddenLiveCount:p=0,loadError:g},x){var ee;const j=a.useRef(null),v=a.useRef(null),y=a.useRef(null),w=a.useRef(0),T=a.useRef(""),b=a.useRef(!1),M=a.useRef(null),N=a.useRef(!1),k=a.useRef(null),B=a.useRef(!1),[R,$]=a.useState(new Set),[P,_]=a.useState(new Set),S=a.useRef(!1),W=()=>{const H=j.current;return H?H.scrollHeight-H.scrollTop-H.clientHeight<200:!0},L=a.useCallback((H="auto")=>{const Y=j.current;Y&&Y.scrollTo({top:Y.scrollHeight,behavior:H})},[]),U=a.useCallback(()=>{var se;const H=j.current,Y=(se=window.getSelection)==null?void 0:se.call(window);if(!H||!Y||Y.rangeCount===0||Y.isCollapsed){B.current=!1;return}const F=Y.anchorNode,J=Y.focusNode;B.current=!!(F&&J&&H.contains(F)&&H.contains(J))},[]),E=a.useCallback((H="auto")=>{M.current!=null&&cancelAnimationFrame(M.current),M.current=requestAnimationFrame(()=>{M.current=null,L(H)})},[L]),D=s.length>0?`${s.length}:${(((ee=s[s.length-1])==null?void 0:ee.content)||"").length}`:"0:0";a.useEffect(()=>{const H=!b.current,Y=T.current!==d;if(T.current=d,H||Y){b.current=!0,S.current=!1,N.current=!0,B.current||E("auto"),w.current=s.length;return}s.length>w.current?!S.current&&!B.current&&E("auto"):W()&&!S.current&&!B.current&&E("auto"),w.current=s.length},[D,d,c,s.length,E]),a.useEffect(()=>()=>{M.current!=null&&cancelAnimationFrame(M.current),k.current!=null&&window.clearTimeout(k.current)},[]),a.useEffect(()=>{const H=v.current;if(!H)return;const Y=()=>{k.current!=null&&window.clearTimeout(k.current),k.current=window.setTimeout(()=>{N.current=!1,k.current=null},180)},F=new ResizeObserver(()=>{N.current&&(B.current||(E("auto"),Y()))});return F.observe(H),()=>{F.disconnect(),k.current!=null&&(window.clearTimeout(k.current),k.current=null)}},[E,d]),a.useImperativeHandle(x,()=>({scrollToBottom:(H="smooth")=>{L(H)}}),[L]),a.useEffect(()=>{const H=j.current;if(!H)return;let Y;const F=()=>{clearTimeout(Y),Y=setTimeout(()=>{S.current=!W()},50)};return H.addEventListener("scroll",F,{passive:!0}),()=>{H.removeEventListener("scroll",F),clearTimeout(Y)}},[]),a.useEffect(()=>(document.addEventListener("selectionchange",U),()=>document.removeEventListener("selectionchange",U)),[U]);const O=a.useRef(0),A=a.useRef(!1);a.useEffect(()=>{const H=j.current;if(!H||!A.current||O.current===0)return;const Y=H.scrollHeight-O.current;Y>0&&(H.scrollTop=Y),O.current=0,A.current=!1},[s.length]);const Q=()=>{const H=j.current;H&&(O.current=H.scrollHeight),A.current=!0,u==null||u()},xe=a.useMemo(()=>{const H=s.map((se,X)=>({type:"message",data:se,index:X,ts:se.receivedAt||l[ht(se,X)]||0}));if(!n||n.length===0)return H;const Y=[...n].sort((se,X)=>se.timestamp-X.timestamp).map((se,X)=>({type:"action",data:se,index:X,ts:se.timestamp})),F=[];let J=0;for(const se of H){for(;J<Y.length&&se.ts>0&&Y[J].ts<se.ts;)F.push(Y[J++]);F.push(se)}for(;J<Y.length;)F.push(Y[J++]);return F},[s,n,l]),ue=p>0||!!h,te=p>0?`↑ Show ${Math.min(p,80)} earlier messages${p>80?` (${p} hidden)`:""}`:g?`↻ ${g}`:"↑ Load older messages";return e.jsx("div",{ref:j,"data-chat-scroll":!0,className:"chat-container",children:e.jsxs("div",{ref:v,className:"chat-container-content",children:[m&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),ue&&!m&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:Q,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${g&&p===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:te})}),xe.length===0&&!ue&&(f||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),xe.map(H=>{if(H.type==="action"){const pe=H.data;return e.jsx(Ua,{log:pe},`action-${H.index}`)}const Y=H.data,F=H.index,J=ht(Y,F),se=Y.receivedAt||l[J],X=`${d}-${J}`,le=R.has(X),ge=P.has(X);return e.jsx(Ha,{message:Y,receivedAt:se,agentName:r,userName:i,isCliMode:o,isExpanded:le,isTextExpanded:ge,onToggleExpanded:()=>$(pe=>{const ve=new Set(pe);return le?ve.delete(X):ve.add(X),ve}),onToggleTextExpanded:()=>_(pe=>{const ve=new Set(pe);return ge?ve.delete(X):ve.add(X),ve})},`msg-${J}`)}),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:y})]})})}),Va=a.memo(Fa,(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 rn=!1;const Xn=a.forwardRef(({onInput:t,onResize:s,fontSize:n=13,readOnly:r=!1},i)=>{const o=a.useRef(null),[c,d]=a.useState(null),l=a.useRef([]),f=a.useRef(!1),u=a.useRef(!1),m=a.useRef(!1),h=()=>{const p=o.current;if(p){f.current&&(p.clear(),f.current=!1);for(const g of l.current)p.write(g);l.current=[],u.current&&(p.fit(),u.current=!1),m.current&&(p.bumpResize(),m.current=!1)}};return a.useImperativeHandle(i,()=>({write:p=>{o.current?o.current.write(p):l.current.push(p)},clear:()=>{o.current?o.current.clear():(l.current=[],f.current=!0)},reset:()=>{o.current&&"reset"in o.current&&typeof o.current.reset=="function"?o.current.reset():(l.current=[],f.current=!0)},resize:(p,g)=>{o.current&&"resize"in o.current&&typeof o.current.resize=="function"&&o.current.resize(p,g)},fit:()=>{o.current?o.current.fit():u.current=!0},bumpResize:()=>{o.current?o.current.bumpResize():m.current=!0}}),[]),a.useEffect(()=>{if(!c)return;const p=requestAnimationFrame(()=>{h()});return()=>cancelAnimationFrame(p)},[c]),a.useEffect(()=>{let p=!1;return ya(()=>import("./terminal-PD6SznsC.js").then(g=>g.i),__vite__mapDeps([0,1,2])).then(g=>{rn||(rn=!0,console.info("[CliTerminal] renderer module loaded: ghostty-web")),p||d(()=>g.GhosttyTerminalView)}).catch(g=>{console.error("[CliTerminal] failed to load terminal renderer",g)}),()=>{p=!0}},[]),c?e.jsx(c,{ref:o,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"}})});Xn.displayName="CliTerminal";function Kt({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 an({value:t,max:s,label:n,color:r="#8b5cf6",detail:i,compact:o=!1}){const c=s>0?Math.min(Math.round(t/s*100),100):0,d=c>85?"#ef4444":c>60?"var(--status-warning)":r;return o?e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-0.5",children:[e.jsx("span",{className:"text-[9px] text-text-muted uppercase tracking-wide font-semibold",children:n}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-500",style:{width:`${c}%`,background:d}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:n}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-[600ms]",style:{width:`${c}%`,background:`linear-gradient(90deg, ${d}, ${d}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function qa({cursorPos:t,viewportRef:s,imgRef:n}){var y;if(!t||!n.current)return null;const r=n.current,i=r.getBoundingClientRect(),o=(y=s.current)==null?void 0:y.getBoundingClientRect();if(!o)return null;const c=r.naturalWidth||i.width,d=r.naturalHeight||i.height,l=c/d,f=i.width/i.height;let u,m,h,p;l>f?(u=i.width,m=i.width/l,h=0,p=(i.height-m)/2):(m=i.height,u=i.height*l,h=(i.width-u)/2,p=0);const g=i.left-o.left+h+u*t.nx,x=i.top-o.top+p+m*t.ny,j=Math.max(8,Math.min(o.width-8,g)),v=Math.max(8,Math.min(o.height-8,x));return e.jsxs("div",{style:{position:"absolute",left:j-8,top:v-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 Ga({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:i,setIsMenuOpen:o,imeText:c,setImeText:d,handleImeSubmit:l,isConnActive:f,zoom:u,isMobile:m,mobileFillZoom:h,onZoomOut:p,onZoomReset:g,onZoomIn:x,transportType:j,screenshotUsage:v,lastActionStatus:y}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:w=>w.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(w=>!w),o(!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:w=>w.stopPropagation(),onChange:w=>d(w.target.value),onKeyDown:w=>{l(w)},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:()=>{o(w=>!w),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${i?"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:f?"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:f?"#22c55e":"#eab308",boxShadow:f?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:f?"#22c55e":"#eab308"},children:f?"Connected":"WS"})]}),u>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(u*100),"%"]}),j==="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"}),j==="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"}),v&&v.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:v.budgetExhausted?"#ef4444":"#c4b5fd",background:v.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:v.budgetExhausted?"TURN blocked":`TURN ${v.dailyUsedMinutes}/${v.dailyBudgetMinutes}m`}),y&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:y})]})]}),i&&e.jsxs("div",{onTouchStart:w=>w.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<=(m?h:1)+.01?m?"FILL":"FIT":`${Math.round(u*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:w=>{w.stopPropagation(),p()},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:w=>{w.stopPropagation(),g()},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:m?"FILL":"FIT"}),e.jsx("button",{onClick:w=>{w.stopPropagation(),x()},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 Ya({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 Xa(){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 on(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 Pt(t,s){const n=a.useRef(null),r=a.useRef(0);a.useEffect(()=>{if(!Xa())return;r.current+=1;const i=n.current;if(!i){console.debug(`[render-trace] ${t}#${r.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([c,d])=>[c,on(d)]))}),n.current=s;return}const o=Object.keys({...i,...s}).filter(c=>!Object.is(i[c],s[c]));o.length>0&&console.debug(`[render-trace] ${t}#${r.current}`,{changed:o,snapshot:Object.fromEntries(o.map(c=>[c,on(s[c])]))}),n.current=s})}function Za({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:i,minZoom:o,zoomRef:c,panXRef:d,panYRef:l,setPanX:f,setPanY:u,setZoom:m,lastWheelTimeRef:h,onAction:p,setLastActionStatus:g,spawnRippleFromNormalized:x,clampPan:j,isMobile:v,mobileFillZoom:y}){const[w,T]=a.useState(null),b=a.useRef(null),M=a.useRef(null),N=a.useRef(null),k=a.useRef(!1),B=a.useRef(null),R=a.useRef(0),$=a.useRef(null),P=a.useRef(1),_=a.useRef({x:0,y:0}),S=a.useRef(!1),W=a.useRef(r),L=a.useRef(p),U=()=>{if(b.current)return;const O={nx:.5,ny:.5};b.current=O,T(O)};return a.useEffect(()=>{W.current=r,r==="mouse"&&U()},[r]),a.useEffect(()=>{L.current=p},[p]),a.useEffect(()=>{const O=t.current;if(!O)return;const A=H=>{if(!n.current)return null;const Y=n.current.getBoundingClientRect();return!Y.width||!Y.height?null:{nx:Math.max(0,Math.min(1,(H.clientX-Y.left)/Y.width)),ny:Math.max(0,Math.min(1,(H.clientY-Y.top)/Y.height))}},Q=(H,Y)=>{if(!n.current)return{dnx:0,dny:0};const F=n.current,J=F.getBoundingClientRect(),se=F.naturalWidth||J.width,X=F.naturalHeight||J.height,le=se/X,ge=J.width/J.height;let pe,ve;return le>ge?(pe=J.width,ve=J.width/le):(ve=J.height,pe=J.height*le),{dnx:H/pe,dny:Y/ve}},xe=(H,Y,F)=>{if(F<=1.05)return;const J=-(H-.5)*100,se=-(Y-.5)*100,X=j(J,se,F);(Math.abs(X.x-d.current)>.1||Math.abs(X.y-l.current)>.1)&&(f(X.x),u(X.y),d.current=X.x,l.current=X.y)},ue=H=>{const Y=s.current;if(Y&&H.target instanceof Node&&Y.contains(H.target))H.preventDefault();else return;if(H.touches.length===1){const F=H.touches[0];M.current={x:F.clientX,y:F.clientY,time:Date.now()},N.current={x:F.clientX,y:F.clientY},S.current||(k.current=!1),B.current=setTimeout(()=>{if(!k.current&&!S.current)if(k.current=!0,W.current==="mouse"){const J=b.current||{nx:.5,ny:.5};g("Right Click"),x(J.nx,J.ny,"right"),L.current("input_click",{...J,button:"right"}).catch(()=>{})}else{const J=A(F);J&&(g("Right Click"),x(J.nx,J.ny,"right"),L.current("input_click",{...J,button:"right"}).catch(()=>{}))}},500);return}if(H.touches.length===2){B.current&&clearTimeout(B.current),k.current=!0,S.current=!0;const F=H.touches[1].clientX-H.touches[0].clientX,J=H.touches[1].clientY-H.touches[0].clientY;$.current=Math.sqrt(F*F+J*J),P.current=c.current,_.current={x:(H.touches[0].clientX+H.touches[1].clientX)/2,y:(H.touches[0].clientY+H.touches[1].clientY)/2}}},te=H=>{const Y=s.current;if(Y&&H.target instanceof Node&&Y.contains(H.target)&&H.preventDefault(),H.touches.length===1&&N.current){const F=H.touches[0],J=F.clientX-N.current.x,se=F.clientY-N.current.y;if(!k.current&&M.current){const X=F.clientX-M.current.x,le=F.clientY-M.current.y;Math.sqrt(X*X+le*le)>8&&(k.current=!0,B.current&&clearTimeout(B.current))}if(k.current)if(W.current==="mouse"){const X=Q(J,se),le=b.current||{nx:.5,ny:.5},ge=Math.max(0,Math.min(1,le.nx+X.dnx)),pe=Math.max(0,Math.min(1,le.ny+X.dny));b.current={nx:ge,ny:pe},T({nx:ge,ny:pe}),g(`Cursor: ${Math.round(ge*100)}%, ${Math.round(pe*100)}%`),xe(ge,pe,c.current);const ve=Date.now();ve-h.current>=30&&(h.current=ve,L.current("input_mouseMoved",{nx:ge,ny:pe}).catch(()=>{}))}else if(c.current>1){const X=s.current;if(X){const le=X.clientWidth,ge=X.clientHeight,pe=d.current+J/le*100,ve=l.current+se/ge*100,Z=j(pe,ve,c.current);f(Z.x),u(Z.y),d.current=Z.x,l.current=Z.y}}else{const X=A(F);if(X){const le=Date.now();le-h.current>=40&&(h.current=le,g("Scroll"),L.current("input_wheel",{nx:X.nx,ny:X.ny,deltaX:Math.round(-J*2.5),deltaY:Math.round(-se*2.5)}).catch(()=>{}))}}N.current={x:F.clientX,y:F.clientY};return}if(H.touches.length===2&&$.current!==null){const F=H.touches[1].clientX-H.touches[0].clientX,J=H.touches[1].clientY-H.touches[0].clientY,X=Math.sqrt(F*F+J*J)/$.current,le=(H.touches[0].clientX+H.touches[1].clientX)/2,ge=(H.touches[0].clientY+H.touches[1].clientY)/2,pe=le-_.current.x,ve=ge-_.current.y,Z=Math.abs(X-1)>.03;if(W.current==="mouse"){if(Z){const ce=Math.max(o,Math.min(5,P.current*X));m(ce),c.current=ce}else if(Math.abs(pe)>2||Math.abs(ve)>2){const ce=b.current||{nx:.5,ny:.5},I=Date.now();I-h.current>=30&&(h.current=I,g("Scroll"),L.current("input_wheel",{nx:ce.nx,ny:ce.ny,deltaX:Math.round(-pe*3),deltaY:Math.round(-ve*3)}).catch(()=>{}))}}else{const ce=Math.max(o,Math.min(5,P.current*X));m(ce),c.current=ce;const I=s.current;if(I&&ce>1){const ae=I.clientWidth,me=I.clientHeight,oe=d.current+pe/ae*100,be=l.current+ve/me*100,je=j(oe,be,ce);f(je.x),u(je.y),d.current=je.x,l.current=je.y}}_.current={x:le,y:ge}}},ee=H=>{var Y;if(B.current&&clearTimeout(B.current),$.current=null,H.touches.length===1&&S.current){const F=H.touches[0];M.current={x:F.clientX,y:F.clientY,time:Date.now()},N.current={x:F.clientX,y:F.clientY},k.current=!0;return}if(H.touches.length===0){if(S.current){S.current=!1,k.current=!1;return}if(H.changedTouches.length===1&&!k.current){const F=H.changedTouches[0],J=Date.now(),se=J-(((Y=M.current)==null?void 0:Y.time)||0);if(se<60||se>400){k.current=!1;return}if(M.current){const X=F.clientX-M.current.x,le=F.clientY-M.current.y;if(Math.sqrt(X*X+le*le)>12){k.current=!1;return}}if(W.current==="mouse"){const X=b.current||A(F);X&&(g(`Click: ${Math.round(X.nx*100)}%, ${Math.round(X.ny*100)}%`),x(X.nx,X.ny,"left"),L.current("input_click",{...X}).catch(()=>{}))}else{const X=A(F);if(!X)return;J-R.current<300?(g("Double tap"),x(X.nx,X.ny,"double"),L.current("input_click",{...X,clickCount:2}).catch(()=>{}),R.current=0):(g(`Tap: ${Math.round(X.nx*100)}%, ${Math.round(X.ny*100)}%`),x(X.nx,X.ny,"left"),L.current("input_click",{...X}).catch(()=>{}),R.current=J)}}k.current=!1}};return O.addEventListener("touchstart",ue,{passive:!1}),O.addEventListener("touchmove",te,{passive:!1}),O.addEventListener("touchend",ee,{passive:!1}),()=>{O.removeEventListener("touchstart",ue),O.removeEventListener("touchmove",te),O.removeEventListener("touchend",ee),B.current&&clearTimeout(B.current)}},[t,s,n,o,c,d,l,f,u,m,h,g,x,j]),{cursorPos:w,cursorPosRef:b,handleToggleInputMode:()=>{i(O=>{const A=O==="touch"?"mouse":"touch";return A==="mouse"&&U(),A})},handleZoomReset:()=>{const O=v?y:1;m(O),c.current=O,f(0),u(0),d.current=0,l.current=0}}}function Zn({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:i,transportType:o}){const c=a.useRef(null),d=a.useRef(null),l=a.useRef(null),[f,u]=a.useState(null),[m,h]=a.useState(""),[,p]=a.useState(!1),[g,x]=a.useState([]),j=a.useRef(0),[v,y]=a.useState(!1),[w,T]=a.useState(!1),b=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[M,N]=a.useState(b?"mouse":"touch"),[k,B]=a.useState(1),R=a.useRef(!1),[$,P]=a.useState(1),[_,S]=a.useState(0),[W,L]=a.useState(0);Pt("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:M,zoom:$,panX:_,panY:W,isMenuOpen:v,isImeOpen:w});const U=a.useRef(0),E=a.useRef($),D=a.useRef(_),O=a.useRef(W);a.useEffect(()=>{E.current=$},[$]),a.useEffect(()=>{D.current=_},[_]),a.useEffect(()=>{O.current=W},[W]),a.useEffect(()=>{var Z;(Z=c.current)==null||Z.focus()},[]);const A=n==="connected",Q=r,xe=A?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",ue=A?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!b||R.current||!Q)return;const Z=l.current,ce=d.current;if(!Z||!ce)return;const I=()=>{const ae=ce.clientWidth,me=ce.clientHeight,oe=Z.naturalWidth,be=Z.naturalHeight;if(!oe||!be||!ae||!me)return;const je=Math.min(ae/oe,me/be),Te=Math.max(ae/oe,me/be)/je;Te>1.01&&(B(Te),P(Te),E.current=Te),R.current=!0};Z.complete&&Z.naturalWidth?I():Z.addEventListener("load",I,{once:!0})},[Q,b]);const te=.5;a.useEffect(()=>{$<=te&&(S(0),L(0))},[$,te]);const ee=(Z,ce,I)=>{if(I<=te)return{x:0,y:0};const ae=(I-1)/(2*I)*100,me=(I-1)/(2*I)*100;return{x:Math.max(-ae,Math.min(ae,Z)),y:Math.max(-me,Math.min(me,ce))}},H=(Z,ce)=>{if(!l.current)return null;const I=l.current.getBoundingClientRect();return!I.width||!I.height?null:{nx:Math.max(0,Math.min(1,(Z-I.left)/I.width)),ny:Math.max(0,Math.min(1,(ce-I.top)/I.height))}},Y=(Z,ce,I)=>{const ae=d.current;if(!ae)return;const me=ae.getBoundingClientRect(),oe=++j.current;x(be=>[...be,{id:oe,x:Z-me.left,y:ce-me.top,type:I}]),setTimeout(()=>x(be=>be.filter(je=>je.id!==oe)),600)},F=(Z,ce,I)=>{const ae=l.current,me=d.current;if(!ae||!me)return;const oe=ae.getBoundingClientRect(),be=me.getBoundingClientRect(),je=ae.naturalWidth||oe.width,Re=ae.naturalHeight||oe.height,Te=je/Re,tt=oe.width/oe.height;let Oe,Le,Ee,Ve;Te>tt?(Oe=oe.width,Le=oe.width/Te,Ee=0,Ve=(oe.height-Le)/2):(Le=oe.height,Oe=oe.height*Te,Ee=(oe.width-Oe)/2,Ve=0);const ne=oe.left-be.left+Ee+Oe*Z,we=oe.top-be.top+Ve+Le*ce,ye=++j.current;x(he=>[...he,{id:ye,x:ne,y:we,type:I}]),setTimeout(()=>x(he=>he.filter(He=>He.id!==ye)),600)},J=async Z=>{var I;const ce=H(Z.clientX,Z.clientY);if(ce){u(`Click: ${Math.round(ce.nx*100)}%, ${Math.round(ce.ny*100)}%`),Y(Z.clientX,Z.clientY,"left"),(I=c.current)==null||I.focus();try{const ae=await t("input_click",{nx:ce.nx,ny:ce.ny});ae!=null&&ae.success||s(`❌ Click failed: ${ae==null?void 0:ae.error}`)}catch(ae){s(`❌ Click error: ${ae.message||ae}`)}}},se=async(Z,ce,I,ae=0)=>{try{await t("input_key",{type:I?"char":"keyDown",key:Z,code:ce,text:I?Z:void 0,unmodifiedText:I?Z:void 0,modifiers:ae})}catch(me){s(`❌ Key error: ${me.message||me}`)}},X=async Z=>{if(Z.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(Z.key)&&Z.preventDefault();let I=0;Z.altKey&&(I|=1),Z.ctrlKey&&(I|=2),Z.metaKey&&(I|=4),Z.shiftKey&&(I|=8),u(`Key: ${Z.key}`),await se(Z.key,Z.code,Z.key.length===1,I)},le=async Z=>{if(Z.key==="Enter"){if(Z.nativeEvent.isComposing)return;if(m){const ce=m;h(""),u(`IME Sent: ${ce}`);try{const I=await t("input_type",{text:ce});I!=null&&I.success||s(`❌ IME error: ${I==null?void 0:I.error}`)}catch(I){s(`❌ IME error: ${I.message}`)}}else u("Key: Enter"),await se("Enter","Enter",!1)}};a.useEffect(()=>{const Z=c.current;if(!Z)return;const ce=I=>{var ae;if((ae=l.current)!=null&&ae.contains(I.target)){I.preventDefault();const me=Date.now();if(me-U.current<40)return;U.current=me;const oe=H(I.clientX,I.clientY);if(!oe)return;u(`Scroll: ${Math.round(I.deltaY)}`),t("input_wheel",{nx:oe.nx,ny:oe.ny,deltaX:Math.round(I.deltaX),deltaY:Math.round(I.deltaY)}).catch(()=>{})}};return Z.addEventListener("wheel",ce,{passive:!1}),()=>Z.removeEventListener("wheel",ce)},[t]);const{cursorPos:ge,handleToggleInputMode:pe,handleZoomReset:ve}=Za({containerRef:c,viewportRef:d,imgRef:l,inputMode:M,setInputMode:N,minZoom:te,zoomRef:E,panXRef:D,panYRef:O,setPanX:S,setPanY:L,setZoom:P,lastWheelTimeRef:U,onAction:t,setLastActionStatus:u,spawnRippleFromNormalized:F,clampPan:ee,isMobile:b,mobileFillZoom:k});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:X,onContextMenu:Z=>Z.preventDefault(),onFocus:()=>p(!0),onBlur:()=>p(!1),tabIndex:0,children:[e.jsxs("div",{ref:d,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[Q?e.jsx("img",{ref:l,src:Q,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${$}) translate(${_}%, ${W}%)`,transformOrigin:"center center",cursor:M==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:J,onContextMenu:Z=>Z.preventDefault(),onDragStart:Z=>Z.preventDefault()}):e.jsx(Ya,{waitingLabel:xe,waitingHint:ue,transportType:o}),M==="mouse"&&Q&&e.jsx(qa,{cursorPos:ge,viewportRef:d,imgRef:l}),g.map(Z=>{const I={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[Z.type];return e.jsxs("div",{style:{position:"absolute",left:Z.x,top:Z.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${I}, 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(${I}, 0.9)`,boxShadow:`0 0 12px rgba(${I}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},Z.id)})]}),e.jsx(Ga,{inputMode:M,onToggleInputMode:pe,isImeOpen:w,setIsImeOpen:T,isMenuOpen:v,setIsMenuOpen:y,imeText:m,setImeText:h,handleImeSubmit:le,isConnActive:A,zoom:$,isMobile:b,mobileFillZoom:k,onZoomOut:()=>P(Z=>Math.max(.5,Z-.25)),onZoomReset:ve,onZoomIn:()=>P(Z=>Math.min(5,Z+.25)),transportType:o,screenshotUsage:i,lastActionStatus:f}),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 Ja(t,s={}){if(!t)return"";const{suffix:n="",nowLabel:r="now",nowThreshold:i=60}=s,o=Date.now()-t,c=Math.floor(o/1e3);if(c<i)return r;const d=Math.floor(c/60);if(d<60)return`${d}m${n}`;const l=Math.floor(d/60);if(l<24)return`${l}h${n}`;const f=Math.floor(l/24);return f<7?`${f}d${n}`:new Date(t).toLocaleDateString()}const Jn=t=>Ja(t);function Qa(t){return{unread:!!t.unread,lastSeenAt:t.lastSeenAt||0,lastUpdated:t.lastUpdated||0,inboxBucket:t.inboxBucket||"idle",surfaceHidden:!!t.surfaceHidden}}function ls(t){const s=t.connectionState==="failed"||t.connectionState==="closed",n=t.connectionState==="connecting"||t.connectionState==="new",r=t.status==="generating",i=t.status==="waiting_approval";return{isReconnecting:s,isConnecting:n,isGenerating:r,isWaiting:i}}function Et(t){const s=new Map,n=(r,i)=>{r&&s.set(r,{sessionId:r,...Qa(i)})};for(const r of t)if(!r.daemonMode){n(r.sessionId,r);for(const i of r.childSessions||[])n(i.id,i)}return s}function bt(t,s){if(t.sessionId){const n=s.get(t.sessionId);if(n)return n}return{sessionId:t.sessionId||t.tabKey,unread:!1,lastSeenAt:0,lastUpdated:0,inboxBucket:"idle",surfaceHidden:!1}}function Lt(t,s,n){const r=bt(t,s),i=ls(t),o=i.isReconnecting,c=i.isConnecting,d=i.isGenerating,l=i.isWaiting,f=r.inboxBucket==="needs_attention"||t.status==="needs_attention"||t.status==="waiting_for_user_input"||l,u=r.inboxBucket==="working"||d,m=r.inboxBucket==="task_complete"&&r.unread&&!(n!=null&&n.hideOpenTaskCompleteUnread&&(n!=null&&n.isOpenConversation));return{unread:m,requiresAction:f,isWorking:u,isReconnecting:o,isConnecting:c,isGenerating:d,isWaiting:l,inboxBucket:f?"needs_attention":u?"working":m?"task_complete":"idle"}}function ei(t,s,n){return Lt(t,s,{hideOpenTaskCompleteUnread:!0,isOpenConversation:n==null?void 0:n.isOpenConversation}).unread}function ti(t,s,n){return bt(t,n||new Map).surfaceHidden}function Qn({activeConv:t,onModalButton:s}){const[n,r]=a.useState(null);if(a.useEffect(()=>{r(null)},[t.modalMessage,t.status,t.connectionState]),!ls(t).isWaiting||!t.modalButtons)return null;const o=d=>{n||(r(d),s(d))},c=d=>d.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(Bs,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((d,l)=>{const f=c(d).toLowerCase(),u=/^(run|approve|accept|yes|allow|always)/.test(f),m=/^(reject|deny|delete|remove|abort)/.test(f),h=n===d,p=n!==null;return e.jsx("button",{onClick:()=>o(d),disabled:p,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${u?"bg-white font-extrabold":m?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${p&&!h?"opacity-40":"opacity-100"} ${p?"cursor-not-allowed":"cursor-pointer"}`,style:u?{color:"var(--status-warning)"}:void 0,children:h?"⏳ ...":c(d)},l)})})]})]})}const cn=new Map,si={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"};function ni({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:i,controls:o,controlValues:c,serverModel:d,serverMode:l}){const{sendCommand:f}=ct(),u=`${t}:${s||r}`,m=si[r]||"#94a3b8",[h,p]=a.useState({}),g=a.useRef(0),x={...d?{model:d}:{},...l?{mode:l}:{},...c||{},...Date.now()<g.current?h:{}};a.useEffect(()=>{c&&Date.now()>g.current&&p({})},[c]);const[j,v]=a.useState(cn.get(u)||{}),[y,w]=a.useState(null),[T,b]=a.useState(null),M=a.useCallback(async(_,S={})=>{const W={...S,...s&&{targetSessionId:s}};return await f(t,_,W)},[t,s,f]);if(!o||o.length===0)return null;const N=o.filter(_=>_.placement==="bar").sort((_,S)=>(_.order??50)-(S.order??50));if(N.length===0)return null;const k=async _=>{var W,L,U;if(y===_.id){w(null);return}if((((W=_.options)==null?void 0:W.map(E=>E.value))||j[_.id]||[]).length>0){w(_.id);return}if(_.dynamic&&_.listScript){b(_.id);try{const E=await M(_.listScript==="listModels"?"list_extension_models":_.listScript==="listModes"?"list_extension_modes":_.listScript,{agentType:r,ideType:n}),O=((E==null?void 0:E.models)||(E==null?void 0:E.modes)||((L=E==null?void 0:E.result)==null?void 0:L.models)||((U=E==null?void 0:E.result)==null?void 0:U.modes)||(E==null?void 0:E.options)||[]).map(A=>typeof A=="string"?A:(A==null?void 0:A.name)||(A==null?void 0:A.id)||(A==null?void 0:A.value)||String(A));v(A=>{const Q={...A,[_.id]:O};return cn.set(u,Q),Q}),w(_.id)}catch{}finally{b(null)}}},B=async(_,S)=>{w(null),p(W=>({...W,[_.id]:S})),g.current=Date.now()+5e3;try{if(!_.setScript)return;const W=bs(_.setScript,r);await M(W,{agentType:r,ideType:n,model:_.id==="model"?S:void 0,mode:_.id==="mode"?S:void 0,value:S})}catch{}},R=async _=>{var D;const S=((D=_.options)==null?void 0:D.map(O=>O.value))||j[_.id]||[];if(S.length===0)return;const W=String(x[_.id]||""),U=(S.indexOf(W)+1)%S.length,E=S[U];if(typeof E=="string"){p(O=>({...O,[_.id]:E})),g.current=Date.now()+5e3;try{if(!_.setScript)return;const O=bs(_.setScript,r);await M(O,{agentType:r,ideType:n,value:E})}catch{}}},$=async _=>{const W=!x[_.id];p(L=>({...L,[_.id]:W})),g.current=Date.now()+5e3;try{if(!_.setScript)return;const L=bs(_.setScript,r);await M(L,{agentType:r,ideType:n,value:W})}catch{}},P=async _=>{if(_.invokeScript)try{await M("invoke_extension_script",{agentType:r,ideType:n,scriptName:_.invokeScript})}catch{}};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-surface-primary font-[var(--font)]",children:[e.jsx("span",{className:"text-[9px] font-bold tracking-wide opacity-70",style:{color:m},children:i}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),N.map(_=>{var E;const S=String(x[_.id]||""),W=y===_.id,L=T===_.id,U=((E=_.options)==null?void 0:E.map(D=>D.value))||j[_.id]||[];switch(_.type){case"select":return 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?`${m}55`:"transparent",border:"1px solid",color:S?"var(--text-primary)":"var(--text-muted)"},onClick:()=>k(_),children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),L?"...":S||_.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),W&&U.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>w(null)}),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:_.label.toUpperCase()}),U.map(D=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:D===S?`${m}18`:"transparent",color:D===S?m:"var(--text-secondary)",fontWeight:D===S?600:400,borderLeft:D===S?`2px solid ${m}`:"2px solid transparent"},onMouseEnter:O=>{O.currentTarget.style.background=`${m}12`},onMouseLeave:O=>{O.currentTarget.style.background=D===S?`${m}18`:"transparent"},onClick:()=>B(_,D),children:D},D))]})]})]},_.id);case"cycle":return 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",style:{border:"1px solid transparent",color:S?"var(--text-primary)":"var(--text-muted)"},onClick:()=>R(_),title:`Click to cycle: ${U.join(" → ")}`,children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),S||_.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"⟳"})]},_.id);case"toggle":return 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 whitespace-nowrap",style:{border:"1px solid",borderColor:S?`${m}44`:"transparent",background:S?`${m}14`:"var(--surface-tertiary)",color:S?m:"var(--text-muted)"},onClick:()=>$(_),children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),_.label]},_.id);case"action":return 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 hover:bg-[var(--surface-tertiary-hover)] whitespace-nowrap",style:{border:"1px solid var(--border-default)",background:"var(--surface-tertiary)",color:"var(--text-primary)"},onClick:()=>P(_),children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),_.label]},_.id);default:return null}})]})}function bs(t,s){return{setModel:"set_extension_model",setMode:"set_extension_mode",setThinkingLevel:"set_thought_level"}[t]||t}const ri=a.memo(function({contextKey:s,panelLabel:n,isSending:r,onSend:i}){const o=a.useRef(null),[c,d]=a.useState("");a.useEffect(()=>{d("")},[s]);const l=()=>{const f=c.trim();!f||r||(d(""),i(f))};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:o,type:"text",placeholder:`Send message to ${n}...`,value:c,onChange:f=>d(f.target.value),onPaste:f=>{const u=f.clipboardData.getData("text");u&&d(m=>m+u),f.preventDefault()},onKeyDown:f=>{if(f.key==="Enter"){if(f.nativeEvent.isComposing){f.preventDefault();return}f.preventDefault(),l()}},onBlur:f=>{if(window.innerWidth<768){const u=f.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"})})})]})})});var ai=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function ii(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function Ue(t,s){if(ii(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":ai.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 er(t){return Ue(t)==="generating"}function Ie(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function oi(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const n=Math.floor(s/60),r=s%60;if(n<24)return r>0?`${n}h ${r}m`:`${n}h`;const i=Math.floor(n/24),o=n%24;return`${i}d ${o}h`}function ln(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function tr(t,s){const n=typeof s=="string"?s.trim():"";if(n)return n;const r=typeof t=="string"?t.trim():"";if(!r)return"";const i=r.replace(/[\\/]+$/,""),o=i.split(/[\\/]/).filter(Boolean);return o[o.length-1]||i}function ci(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 li(t){const s=t.trim().toLowerCase();return s.startsWith("mach_")||s.startsWith("standalone_mach_")||s.startsWith("daemon_mach_")}function di(t){return ci(t.trim().replace(/\.local$/i,""))}function ui(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function sr(t,s={}){var i,o;const n=[t.hostname,(i=t.machine)==null?void 0:i.hostname,(o=t.system)==null?void 0:o.hostname].find(c=>typeof c=="string"&&c.trim().length>0&&!li(c));if(n&&n!=="Unknown")return di(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function et(t,s={}){return ui(t)||sr(t,s)}function es(t){return t.transport==="pty"}function Ct(t){return t.transport==="acp"}function dn(t,s){return Ie(t)}function pi(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const i=(s||"").trim().toLowerCase(),o=(n||"").trim().toLowerCase(),c=Ie(n||"").trim().toLowerCase();return r===i||r===o||r===c}function xi(t){return Ue(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function mi(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,n=["generating","waiting_approval","connected","idle","panel_hidden"];for(const r of t){const i=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),o=s.get(i),c=Ue(r.status);if(!o){s.set(i,{...r,status:c});continue}const d=n.indexOf(o.status||"idle"),l=n.indexOf(c||"idle");l>=0&&(d<0||l<d)&&s.set(i,{...r,status:c})}return Array.from(s.values())}function gs(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=Date.parse(t);if(Number.isFinite(s))return s}return 0}function fi(t){var n,r;const s=(r=(n=t==null?void 0:t.messages)==null?void 0:n.at)==null?void 0:r.call(n,-1);return s&&(gs(s.timestamp)||gs(s.receivedAt)||gs(s.createdAt))||0}function hi(t){return(t.recentLaunches||[]).reduce((n,r)=>Math.max(n,r.lastLaunchedAt||0),0)}function ts(t){return Math.max(hi(t),fi(t.activeChat))}function bi(t,s,n,r,i,o){const c=s-t;if(c!==0)return c;const d=n.localeCompare(r);return d!==0?d:i.localeCompare(o)}function gi(t,s){return bi(ts(t),ts(s),et(t,{fallbackId:t.id}),et(s,{fallbackId:s.id}),t.id,s.id)}function nr({conversation:t,className:s="",onOpenNativeConversation:n,onOpenMachine:r,interactive:i=!0}){var h;const o=wt(),c=t.daemonId||((h=t.ideId)==null?void 0:h.split(":")[0])||t.ideId,d=t.transport==="cdp-page"||t.transport==="cdp-webview",l=t.streamSource==="agent-stream"&&!!t.agentName,f=(()=>{var p,g;if(t.streamSource==="agent-stream"){const x=(g=(p=t.displaySecondary)==null?void 0:p.split("·")[0])==null?void 0:g.trim();if(x)return x}return Ie(t.ideType||"")})(),u=a.useCallback(()=>{if(r){r();return}c&&o("/dashboard",{state:{openMachineId:c}})},[c,o,r]),m=a.useCallback(()=>{if(n){n();return}const p=t.streamSource==="agent-stream"?t.nativeSessionId:t.sessionId;p&&o(`/dashboard?activeTab=${encodeURIComponent(p)}`)},[t.nativeSessionId,t.sessionId,t.streamSource,o,n]);return e.jsxs("div",{className:`conversation-meta-chips ${s}`.trim(),children:[d&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:m,title:f,children:[e.jsx(ze,{size:12}),e.jsx("span",{children:f})]}):e.jsxs("span",{className:"conversation-meta-chip",title:f,children:[e.jsx(ze,{size:12}),e.jsx("span",{children:f})]})),l&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:t.agentName,children:[e.jsx(gt,{size:12}),e.jsx("span",{children:t.agentName})]}),t.machineName&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:u,title:t.machineName,children:[e.jsx(Jt,{size:12}),e.jsx("span",{children:t.machineName})]}):e.jsxs("span",{className:"conversation-meta-chip",title:t.machineName,children:[e.jsx(Jt,{size:12}),e.jsx("span",{children:t.machineName})]}))]})}const Pe=t=>t.transport==="pty",vt=(t,s)=>Pe(t)?s||t.mode||"terminal":"chat",rr=(t,s)=>Pe(t)&&vt(t,s)==="terminal",Me=t=>t.transport==="acp";function un(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(`
|
|
35
|
-
`).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 pn(t){const s=[];for(const n of t){const r=un(n==null?void 0:n.content),i=n==null?void 0:n.role,o=!!(n!=null&&n._localId),c=s.findIndex(d=>(d==null?void 0:d.role)===i&&un(d==null?void 0:d.content)===r&&!!(d!=null&&d._localId)!==o);if(c>=0){if(o)continue;s.splice(c,1,n);continue}s.push(n)}return s}const yi=60,vi=60;function Ms({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:i,isFocusingAgent:o,actionLogs:c,userName:d,showMetaChips:l=!1}){const f=a.useRef(new Map),{sendCommand:u}=ct();Pt("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:r});const m=Ls.useMemo(()=>ls(t),[t.status,t.connectionState]),h=a.useRef(new Map),p=a.useCallback(S=>(h.current.has(S)||h.current.set(S,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:yi}),h.current.get(S)),[]),g=a.useCallback((S,W)=>{const L=p(S);h.current.set(S,{...L,...W}),x(U=>U+1)},[p]),[,x]=a.useState(0),j=t.tabKey,v=p(j),y=v.messages,w=v.hasMore,T=v.error,b=Math.max(0,t.messages.length-v.visibleLiveCount),[M,N]=a.useState(!1),k=a.useCallback(async()=>{var L,U;if(M)return;const S=t.tabKey,W=p(S);if(t.messages.length>W.visibleLiveCount){g(S,{visibleLiveCount:Math.min(t.messages.length,W.visibleLiveCount+vi),error:null});return}N(!0),g(S,{error:null});try{const E=(s==null?void 0:s.daemonId)||((L=t.ideId)==null?void 0:L.split(":")[0])||"";if(!E){g(S,{hasMore:!1});return}const D=t.ideType||t.agentType||"",O=await u(E,"chat_history",{agentType:D,offset:W.offset,limit:30,targetSessionId:t.sessionId,historySessionId:t.providerSessionId||t.sessionId}),A=(O==null?void 0:O.result)??O;if(((U=A.messages)==null?void 0:U.length)>0){const Q=p(S);g(S,{messages:[...A.messages,...Q.messages],offset:Q.offset+A.messages.length,hasMore:!!A.hasMore})}else g(S,{hasMore:!!A.hasMore})}catch(E){const D=(E==null?void 0:E.message)||"";D.includes("P2P not available")||D.includes("channel not open")||D.includes("P2P not connected")||D.includes("timeout")?g(S,{error:"Connection not ready — tap to retry"}):g(S,{hasMore:!1,error:"Failed to load history"})}finally{N(!1)}},[M,s,t,u,p,g]),{allMessages:B,receivedAtMap:R}=a.useMemo(()=>{const S=b>0?t.messages.slice(-v.visibleLiveCount):t.messages;if(y.length===0){const D=pn(S),O={};return D.forEach((A,Q)=>{const xe=`${t.tabKey}:${ht(A,Q)}`;let ue=A.receivedAt||f.current.get(xe)||0;ue||(ue=Date.now(),f.current.set(xe,ue)),O[ht(A,Q)]=ue}),{allMessages:D,receivedAtMap:O}}const W=new Set(S.map(D=>`${D.role}:${(D.content||"").slice(0,100)}`)),L=y.filter(D=>!W.has(`${D.role}:${(D.content||"").slice(0,100)}`)),U=pn([...L,...S]),E={};return U.forEach((D,O)=>{const A=`${t.tabKey}:${ht(D,O)}`;let Q=D.receivedAt||f.current.get(A)||0;Q||(Q=Date.now(),f.current.set(A,Q)),E[ht(D,O)]=Q}),{allMessages:U,receivedAtMap:E}},[t.messages,t.tabKey,b,y,v.visibleLiveCount]),$=a.useMemo(()=>c.filter(S=>S.ideId===t.tabKey).sort((S,W)=>S.timestamp-W.timestamp),[c,t.tabKey]),P=t.displayPrimary||t.agentName||"Agent",_=a.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((m.isGenerating||t.status==="streaming")&&N(!1),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(gt,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:i,disabled:o,className:"btn btn-primary",children:o?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(At,{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(Vn,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:i,disabled:o,className:"btn btn-primary",children:o?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(At,{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"&&!M)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,i,o,M,P,m.isGenerating]);return e.jsxs("div",{className:"flex-1 min-h-0 w-full flex flex-col",children:[l&&e.jsx(nr,{conversation:t,className:"chat-pane-meta-row"}),e.jsx(Va,{messages:B,actionLogs:$,agentName:t.agentName||t.displayPrimary||"Agent",userName:d,isCliMode:Pe(t)||Me(t),isWorking:m.isGenerating,contextKey:t.tabKey,receivedAtMap:R,onLoadMore:k,isLoadingMore:M,hasMoreHistory:w,hiddenLiveCount:b,loadError:T??void 0,emptyState:_}),!rr(t)&&(()=>{const S=t.streamSource!=="agent-stream",W=S?t.ideType:t.agentType,L=S?s!=null&&s.type?Ie(s.type):Ie(t.ideType||""):t.agentName||Ie(t.agentType||""),U=!S&&(s!=null&&s.childSessions)&&s.childSessions.find(O=>O.id===t.sessionId||O.providerType===t.agentType)||s,E=U==null?void 0:U.providerControls,D=U==null?void 0:U.controlValues;return e.jsx(ni,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:W,displayLabel:L,controls:E,controlValues:D,serverModel:(U==null?void 0:U.currentModel)||void 0,serverMode:(U==null?void 0:U.currentPlan)||void 0,acpConfigOptions:Me(t)?U==null?void 0:U.acpConfigOptions:void 0,acpModes:Me(t)?U==null?void 0:U.acpModes:void 0})})(),e.jsx(ri,{contextKey:t.tabKey,panelLabel:P,isSending:r,onSend:n})]})}let ar=Rt;function Ws(){return ar()}class wi{constructor(){Be(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,n){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(n),()=>{var r;(r=this.listeners.get(s))==null||r.delete(n)}}emit(s,...n){var r;(r=this.listeners.get(s))==null||r.forEach(i=>i(...n))}}let ir=new wi;class ji{sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,i){return!1}retryConnection(s){}getState(s){return"disconnected"}sendData(s,n){return!1}get(s){}onScreenshot(s,n){return()=>{}}onRuntimeEvent(s,n){return()=>{}}requestRuntimeSnapshot(s,n){return Promise.resolve()}}let _e=new ji;function ki(t){t.dashboardWS&&(ir=t.dashboardWS),t.connectionManager&&(_e=t.connectionManager),t.useDaemonsHook&&(ar=t.useDaemonsHook)}function Ni({activeConv:t,clearToken:s=0,terminalRef:n,handleSendChat:r,isSendingChat:i=!1,isVisible:o=!0}){var $;const c=a.useRef(null),{sendCommand:d,sendData:l}=ct(),[f,u]=a.useState(""),[m,h]=a.useState(!1),p=a.useRef(0),g=a.useRef(!1),x=a.useRef(""),j=a.useRef(null),v=a.useRef(!1),y=a.useRef(null),w=t.tabKey,T=t.sessionId||"",b=t.daemonId||(($=t.ideId)==null?void 0:$.split(":")[0])||t.ideId||"",M=()=>{var P,_;p.current=0,g.current=!1,x.current="",j.current=null,v.current=!1,y.current!==null&&(cancelAnimationFrame(y.current),y.current=null),h(!1),(_=(P=n.current)==null?void 0:P.reset)==null||_.call(P)},N=()=>{var P,_;p.current=0,g.current=!1,x.current="",j.current=null,v.current=!1,y.current!==null&&(cancelAnimationFrame(y.current),y.current=null),h(!0),(_=(P=n.current)==null?void 0:P.reset)==null||_.call(P)},k=()=>{var _;if(y.current=null,!o)return;const P=x.current;P&&(x.current="",(_=n.current)==null||_.write(P))},B=P=>{P&&(x.current+=P,o&&y.current===null&&(y.current=requestAnimationFrame(k)))},R=(P,_=0,S,W)=>{var L,U,E,D,O;_>0&&p.current>=_||_===0&&g.current||(p.current=_,h(!0),typeof S=="number"&&typeof W=="number"&&S>0&&W>0&&((U=(L=n.current)==null?void 0:L.resize)==null||U.call(L,S,W)),(D=(E=n.current)==null?void 0:E.reset)==null||D.call(E),P&&((O=n.current)==null||O.write(P)))};return a.useEffect(()=>{M()},[T]),a.useEffect(()=>{var _;if(!T)return;const P=((_=_e.onRuntimeEvent)==null?void 0:_.call(_e,T,S=>{if(!(!S||S.sessionId!==T)){if(S.type==="runtime_snapshot"){if(!o){j.current={text:S.text||"",seq:S.seq||0,cols:S.cols,rows:S.rows};return}R(S.text||"",S.seq||0,S.cols,S.rows);return}if(S.type==="session_output"){g.current=!0,typeof S.seq=="number"&&(p.current=Math.max(p.current,S.seq)),m||h(!0),typeof S.data=="string"&&B(S.data);return}if(S.type==="session_cleared"){if(!o){v.current=!0,x.current="",j.current=null;return}N()}}}))||(()=>{});return()=>{P()}},[b,T,n,o,m]),a.useEffect(()=>{var _,S,W;if(!T)return;b&&((_=_e.getState)==null?void 0:_.call(_e,b))==="connected"&&(h(!0),(S=_e.requestRuntimeSnapshot)==null||S.call(_e,b,T).catch(()=>{}));const P=(W=_e.onStateChange)==null?void 0:W.call(_e,(L,U)=>{var E;L!==b||U!=="connected"||(h(!0),(E=_e.requestRuntimeSnapshot)==null||E.call(_e,b,T).catch(()=>{}))});return()=>{P==null||P()}},[b,T,n]),a.useEffect(()=>{s&&M()},[s,w,n]),a.useEffect(()=>{u("")},[t.tabKey]),a.useEffect(()=>{var _;if(!o){(_=c.current)==null||_.blur();return}v.current&&(v.current=!1,N());const P=j.current;P&&(j.current=null,R(P.text,P.seq,P.cols,P.rows)),x.current&&y.current===null&&(y.current=requestAnimationFrame(k))},[o]),a.useEffect(()=>()=>{y.current!==null&&(cancelAnimationFrame(y.current),y.current=null)},[]),a.useEffect(()=>{const P=_=>{var W;const S=_.detail;S!=null&&S.sessionId&&S.sessionId!==T||m&&((W=n.current)==null||W.fit())};return window.addEventListener("adhdev:fit-cli-terminal",P),()=>{window.removeEventListener("adhdev:fit-cli-terminal",P)}},[m,T,n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx(Xn,{ref:n,readOnly:!m||!o,onInput:P=>{m&&(l!=null&&l(b,{type:"pty_input",targetSessionId:T,data:P})||d(b,"pty_input",{targetSessionId:T,data:P}).catch(console.error))},onResize:(P,_)=>{m&&(l!=null&&l(b,{type:"pty_resize",targetSessionId:T,cols:P,rows:_})||d(b,"pty_resize",{targetSessionId:T,cols:P,rows:_,force:!0}).catch(()=>{}))}}),!m&&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:c,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:f,disabled:!m||!o||i,onChange:P=>u(P.target.value),onPaste:P=>{const _=P.clipboardData.getData("text");_&&u(S=>S+_),P.preventDefault()},onKeyDown:P=>{if(P.key!=="Enter")return;if(P.nativeEvent.isComposing){P.preventDefault();return}P.preventDefault();const _=f.trim();!m||!_||i||(u(""),r(_))},className:"w-full h-9 rounded-[18px] px-4 bg-bg-secondary text-[13px] text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:()=>{const P=f.trim();!m||!P||i||(u(""),r(P))},disabled:!m||!o||!f.trim()||i,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${f.trim()&&!i?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:f.trim()&&!i?{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:f.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function Si({wsStatus:t,showReconnected:s,loginUrl:n}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"accent",o={red:"linear-gradient(90deg, rgba(239,68,68,0.12), rgba(239,68,68,0.04))",orange:"linear-gradient(90deg, rgba(255,107,53,0.12), rgba(255,107,53,0.04))",accent:"linear-gradient(90deg, color-mix(in srgb, var(--accent-primary) 18%, transparent), color-mix(in srgb, var(--accent-primary) 6%, transparent))"},c={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",accent:"1px solid color-mix(in srgb, var(--accent-primary) 28%, transparent)"},d={red:"#ef4444",orange:"#ff6b35",accent:"var(--accent-primary-light)"};return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:o[i],borderBottom:c[i],color:d[i]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(n?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:n,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — please restart the server.")]}),s&&t==="connected"&&e.jsxs("div",{className:"py-2 px-4 text-xs font-semibold flex items-center gap-2 justify-center bg-gradient-to-r from-green-500/[0.12] to-green-500/[0.04] text-green-400 border-b border-green-500/15 animate-[fadeIn_0.3s_ease]",children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),"Connected"]})]})}function Ci({terminalBackend:t,isStandalone:s=!1,machineLabel:n,machineKey:r}){const i=a.useMemo(()=>!r||!t?null:`adhdev:terminal-backend-banner:dismissed:${r}:${t.backend}`,[r,t]),[o,c]=a.useState(!1);if(a.useEffect(()=>{if(!i){c(!1);return}try{c(localStorage.getItem(i)==="1")}catch{c(!1)}},[i]),!s||!t||t.backend!=="xterm"||o)return null;const d=(n==null?void 0:n.trim())||"This machine",l=()=>{if(i)try{localStorage.setItem(i,"1")}catch{}c(!0)};return e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5",style:{background:"linear-gradient(90deg, rgba(245,158,11,0.12), rgba(245,158,11,0.04))",borderBottom:"1px solid rgba(245,158,11,0.2)",color:"#d97706"},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2.5 justify-center flex-wrap",children:[e.jsxs("span",{children:[d," is using `xterm` fallback."]}),e.jsx("span",{style:{opacity:.8},children:"ghostty-vt is unavailable on this machine, so terminal rendering may be less accurate."})]}),e.jsx("button",{type:"button",onClick:l,className:"shrink-0 text-[12px] font-semibold px-2 py-1 rounded-md transition-colors",style:{color:"#b45309",background:"rgba(245,158,11,0.1)",border:"1px solid rgba(245,158,11,0.18)"},"aria-label":"Dismiss terminal backend warning",title:"Dismiss",children:"Dismiss"})]})}function Os({mode:t,onChange:s,compact:n=!1}){const r=n?14:15;return e.jsx("button",{type:"button",onClick:()=>s(t==="chat"?"terminal":"chat"),className:"btn btn-sm btn-secondary",title:t==="chat"?"Switch to Terminal view":"Switch to Chat view",children:t==="chat"?e.jsx(Ks,{size:r}):e.jsx(ot,{size:r})})}function xn({conversation:t,isAttention:s,onClick:n}){return e.jsxs("button",{type:"button",className:`dashboard-header-inbox-item ${s?"is-attention":""}`.trim(),onClick:n,children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:t.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:t.displaySecondary})]})}function Ii({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,conversations:i,onOpenHistory:o,onOpenRemote:c,onStopCli:d,activeCliViewMode:l,onSetCliViewMode:f,onOpenConversation:u,onHideConversation:m,hiddenConversations:h=[],onShowConversation:p,onShowAllHidden:g}){const x=Ws(),j=x.p2pStates||{},v=x.ides||[],y=!!t&&Pe(t)&&!Me(t),w=l||(t?rr(t)?"terminal":"chat":null),[T,b]=a.useState(!1),[M,N]=a.useState(!1),[k,B]=a.useState(!1),R=a.useRef(null),$=a.useRef(null),P=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",_=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",S=v.filter(ee=>ee.type==="adhdev-daemon"),W=a.useMemo(()=>Et(v),[v]),L=Object.values(j),U=L.filter(ee=>ee==="connected").length,E=L.filter(ee=>ee==="connecting"||ee==="new"||ee==="checking").length,O=n!=="connected"||S.length===0?null:E>0&&U===0?"P2P connecting...":U>0&&s===0?"Waiting for IDE...":null,A=a.useMemo(()=>i.filter(ee=>!ti(ee,i,W)),[i,W]),Q=a.useMemo(()=>A.filter(ee=>Lt(ee,W).requiresAction),[A,W]),xe=a.useMemo(()=>A.filter(ee=>{const H=(t==null?void 0:t.tabKey)===ee.tabKey;return Lt(ee,W,{hideOpenTaskCompleteUnread:!0,isOpenConversation:H}).unread}),[t,A,W]),ue=Q.length+xe.length;a.useEffect(()=>{if(!T)return;const ee=H=>{var Y;(Y=R.current)!=null&&Y.contains(H.target)||b(!1)};return document.addEventListener("mousedown",ee),()=>document.removeEventListener("mousedown",ee)},[T]),a.useEffect(()=>{if(!M)return;const ee=H=>{var Y;(Y=$.current)!=null&&Y.contains(H.target)||N(!1)};return document.addEventListener("mousedown",ee),()=>document.removeEventListener("mousedown",ee)},[M]);const te=ee=>{if(!ee)return;const H=i.find(Y=>Y.tabKey===ee);H&&(m==null||m(H))};return e.jsxs("div",{className:"dashboard-header",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("div",{className:"header-title-block",children:e.jsxs("div",{className:"header-title-row",children:[e.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[e.jsx(ot,{size:18}),e.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),e.jsx("span",{className:"header-title-mobile",children:(t==null?void 0:t.displayPrimary)||"Dashboard"}),e.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:P,boxShadow:_}})})]}),e.jsxs("div",{className:"header-subtitle",children:[e.jsxs("span",{className:"header-subtitle-copy",children:[s," agent",s!==1?"s":""," active"]}),e.jsx("span",{title:r?"Connected":n==="connected"?"Partial":"Disconnected",className:"header-subtitle-dot inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:P,boxShadow:_}}),O&&e.jsxs("span",{className:"header-subtitle-status",children:["· ",O]})]})]})})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&(y||!Me(t))&&e.jsxs("div",{className:"dashboard-header-actions-group",children:[e.jsx("span",{className:"dashboard-header-action-target",title:t.displaySecondary||t.displayPrimary,children:t.displayPrimary}),y&&d&&e.jsxs(e.Fragment,{children:[f&&w&&e.jsx(Os,{mode:w,onChange:f,compact:!0}),e.jsx("button",{onClick:d,className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:e.jsx(yt,{size:14})})]}),!Me(t)&&e.jsx("button",{onClick:()=>o(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx($s,{size:14})}),!y&&!Me(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(ze,{size:14})})]}),e.jsxs("div",{className:"dashboard-header-inbox",ref:R,children:[e.jsxs("div",{className:`dashboard-header-hidden${k?" is-drop-target":""}`,ref:$,onDragEnter:ee=>{ee.dataTransfer.types.includes("text/tab-key")&&(ee.preventDefault(),B(!0))},onDragOver:ee=>{ee.dataTransfer.types.includes("text/tab-key")&&(ee.preventDefault(),ee.dataTransfer.dropEffect="move",B(!0))},onDragLeave:ee=>{ee.currentTarget.contains(ee.relatedTarget)||B(!1)},onDrop:ee=>{const H=ee.dataTransfer.getData("text/tab-key");ee.preventDefault(),B(!1),te(H)},children:[e.jsxs("button",{type:"button",onClick:()=>N(ee=>!ee),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:"Hidden tabs. Drag a tab here to hide it.",children:[e.jsx(Aa,{size:16}),h.length>0&&e.jsx("span",{className:"dashboard-header-hidden-badge",children:h.length})]}),M&&e.jsxs("div",{className:"dashboard-header-hidden-popover",children:[e.jsxs("div",{className:"dashboard-header-hidden-topbar",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title mb-0",children:"Hidden tabs"}),h.length>0&&g&&e.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{g(),N(!1)},children:"Restore all"})]}),t&&m&&e.jsxs("button",{type:"button",className:"dashboard-header-hidden-current",onClick:()=>m(t),children:[e.jsx("span",{className:"dashboard-header-hidden-current-label",children:"Hide current tab"}),e.jsx("span",{className:"dashboard-header-hidden-current-title",children:t.displayPrimary})]}),h.length>0?e.jsx("div",{className:"dashboard-header-hidden-list",children:h.map(ee=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{p==null||p(ee),N(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:ee.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:ee.displaySecondary})]},ee.tabKey))}):e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),e.jsxs("button",{type:"button",onClick:()=>b(ee=>!ee),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(cs,{size:16}),ue>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:ue})]}),T&&e.jsxs("div",{className:"dashboard-header-inbox-popover",children:[Q.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Needs attention"}),Q.map(ee=>e.jsx(xn,{conversation:ee,isAttention:!0,onClick:()=>{u==null||u(ee),b(!1)}},ee.tabKey))]}),xe.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),xe.map(ee=>e.jsx(xn,{conversation:ee,onClick:()=>{u==null||u(ee),b(!1)}},ee.tabKey))]}),ue===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function Mi(t){if(!t)return"";try{return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(new Date(t))}catch{return new Date(t).toLocaleString()}}function Ti({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,savedSessions:i=[],isSavedSessionsLoading:o=!1,isResumingSavedSessionId:c=null,onClose:d,onNewChat:l,onSwitchSession:f,onRefreshHistory:u,onResumeSavedSession:m}){var j;const h=s.find(v=>v.id===t.ideId),p=(h==null?void 0:h.chats)||[],g=(j=h==null?void 0:h.activeChat)==null?void 0:j.id,x=Pe(t)&&!Me(t);return e.jsxs("div",{className:"fixed inset-0 z-[1300] flex items-center justify-center",children:[e.jsx("div",{onClick:d,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:x?"Saved Sessions":"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",Ie(t.ideType)]})]}),e.jsx("button",{onClick:d,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:[!x&&e.jsx("button",{onClick:l,disabled:n,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:n?"⌛ Creating...":"+ Start New Chat Session"}),x?e.jsx(e.Fragment,{children:i.map(v=>{const y=t.providerSessionId===v.providerSessionId,w=y||!v.canResume||!!c;return e.jsxs("button",{type:"button",onClick:()=>{w||!m||m(v)},disabled:w,className:`w-full text-left p-4 rounded-xl mb-2 border transition-all ${y?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"} ${w?"opacity-70 cursor-default":"cursor-pointer hover:border-[var(--accent-primary-light)]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:`font-bold text-sm mb-1 truncate ${y?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:v.title||"Untitled Session"}),e.jsx("div",{className:"text-[11px] text-text-muted font-mono truncate",children:v.providerSessionId})]}),e.jsx("div",{className:"text-[11px] text-text-muted shrink-0",children:Mi(v.lastMessageAt)})]}),e.jsx("div",{className:"mt-2 text-[12px] text-text-muted line-clamp-2",children:v.preview||"No saved preview yet"}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-[11px] text-text-muted",children:[e.jsxs("div",{className:"truncate",children:[v.workspace||"Workspace unknown",v.currentModel?` · ${v.currentModel}`:"",v.messageCount>0?` · ${v.messageCount} msgs`:""]}),e.jsx("div",{className:"shrink-0",children:y?"ACTIVE":v.canResume?c===v.providerSessionId?"RESUMING...":"RESUME":"MISSING WORKSPACE"})]})]},v.id)})}):p.map(v=>e.jsxs("div",{onClick:()=>{f(t.ideId,v.id),d()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${g===v.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 ${g===v.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:v.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:[v.id.substring(0,12),"..."]}),g===v.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},v.id)),(x&&!o&&i.length===0||!x&&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($a,{size:32})}),e.jsx("div",{className:"text-[13px]",children:x?"No saved sessions found yet.":"No recent chat sessions found."})]}),x&&o&&e.jsx("div",{className:"py-10 px-5 text-center text-text-muted",children:e.jsx("div",{className:"text-[13px]",children:"Refreshing saved sessions…"})})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:u,disabled:r||o,className:"btn btn-secondary btn-sm rounded-[10px]",children:r||o?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ds,{size:13})," ",x?"Refresh Sessions":"Refresh History"]})})})]})]})}const mn={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 or({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:mn[r.type]||mn.info},onClick:()=>{var i;(i=r.actions)!=null&&i.length||(n&&n(r),s(r.id))},children:[e.jsx("button",{className:"absolute top-1.5 right-1.5 w-5 h-5 rounded-full flex items-center justify-center text-white/50 hover:text-white hover:bg-white/20 transition-all text-[11px] leading-none opacity-0 group-hover:opacity-100 cursor-pointer",onClick:i=>{i.stopPropagation(),s(r.id)},"aria-label":"Dismiss",children:"×"}),e.jsx("div",{className:"pr-4",children:r.message}),r.actions&&r.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-2",children:r.actions.map((i,o)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${i.variant==="primary"?"bg-white text-text-primary hover:bg-gray-100":i.variant==="danger"?"bg-red-500/30 text-white hover:bg-red-500/50":"bg-white/20 text-white hover:bg-white/30"}`,onClick:c=>{c.stopPropagation(),i.onClick(),s(r.id)},children:i.label},o))})]},r.id))})}function cr(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(" ").replace(/\s+/g," ").trim():t&&typeof t=="object"&&"text"in t?String(t.text||"").replace(/\s+/g," ").trim():String(t||"").replace(/\s+/g," ").trim()}const _i=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Ri(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function Ai(t){return t.sessionId||t.instanceId||t.agentType}function ys(t,s){return t||s}function Wt(t){return cr(t)}function fn(t,s){const n=new Set,r=[];for(const i of s)if(i)for(const o of t[i]||[]){const c=o._localId||`${o.role}:${o.timestamp}:${o.content}`;n.has(c)||(n.add(c),r.push(o))}return r.sort((i,o)=>i.timestamp-o.timestamp)}function lr(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=et(r,{fallbackId:r.id}))}return s}function dr(t,s,n={}){var h,p,g,x,j,v;const r=[],i=n.machineName,o=n.connectionState,c=Ri(t),d=Ie(t.type),l=Array.isArray(t.childSessions)?t.childSessions.map(y=>{var w,T;return{sessionId:y.id,instanceId:y.id,providerSessionId:y.providerSessionId,agentType:y.providerType,agentName:y.providerName,status:y.status,title:y.title,messages:((w=y.activeChat)==null?void 0:w.messages)||[],activeModal:((T=y.activeChat)==null?void 0:T.activeModal)||void 0,unread:y.unread,lastSeenAt:y.lastSeenAt,lastUpdated:y.lastUpdated,inboxBucket:y.inboxBucket,surfaceHidden:y.surfaceHidden}}):[],f=_i(t),u=t.activeChat||{title:""},m=u.title&&String(u.title).trim()?String(u.title).trim():"";if(f){const y=t.sessionId||t.instanceId,w=dn(t.type),T=(h=t.activeChat)==null?void 0:h.activeModal,b=T&&Array.isArray(T.buttons)&&T.buttons.length>0,M=Ue((p=t.activeChat)==null?void 0:p.status,{activeModal:(g=t.activeChat)==null?void 0:g.activeModal})||Ue((j=(x=t.agents)==null?void 0:x[0])==null?void 0:j.status)||"idle",N=t.activeChat||{title:"",messages:[]};let k=N.title&&String(N.title).trim()?String(N.title).trim():"";const B=(v=t.activeChat)==null?void 0:v.id,R=t.chats;if(B&&Array.isArray(R)&&R.length>0){const W=R.find(L=>L.id===B||L.id&&String(L.id)===String(B));W!=null&&W.title&&String(W.title).trim()&&(k=String(W.title).trim())}const $=N.messages||[],P=fn(s,[t.id,y]),_=new Map;$.filter(W=>W.role==="user").forEach(W=>{const L=Wt(W.content);L&&_.set(L,(_.get(L)||0)+1)});const S=P.filter(W=>{const L=Wt(W.content),U=_.get(L)||0;return U>0?(_.set(L,U-1),!1):!0});r.push({ideId:t.id,sessionId:y,providerSessionId:t.providerSessionId,nativeSessionId:y,transport:t.transport,daemonId:t.daemonId||void 0,mode:Pe(t)?t.mode||"terminal":"chat",agentName:w,agentType:(Pe(t)||Me(t))&&(t.cliType||t.acpType)||t.type,status:M,title:k,messages:[...$,...S],resume:t.resume,ideType:t.cliType||t.acpType||t.type,workspaceName:c,displayPrimary:k||c||(Pe(t)?t.mode==="chat"?w:"Terminal":w),displaySecondary:d,cdpConnected:t.cdpConnected,modalButtons:b?T.buttons:void 0,modalMessage:b?T.message:void 0,streamSource:"native",tabKey:ys(y,t.id),machineName:i,connectionState:o})}if(f&&(Pe(t)||Me(t)))return r;for(const y of l){const w=y.activeModal&&Array.isArray(y.activeModal.buttons)&&y.activeModal.buttons.length>0,T=xi(y),b=Ai(y),M=`${t.id}:${b}`,N=y.title&&String(y.title).trim()||"",k=pi(N,y.agentName,y.agentType)?"":N,B=y.messages||[],R=fn(s,[M,y.sessionId,y.instanceId]),$=new Map;B.filter(S=>S.role==="user").forEach(S=>{const W=Wt(S.content);W&&$.set(W,($.get(W)||0)+1)});const P=R.filter(S=>{const W=Wt(S.content),L=$.get(W)||0;return L>0?($.set(W,L-1),!1):!0});(B.length>0||P.length>0||w||k||!["idle","panel_hidden","disconnected","not_monitored"].includes(T))&&r.push({ideId:t.id,sessionId:y.sessionId||y.instanceId,providerSessionId:y.providerSessionId,nativeSessionId:t.sessionId||t.instanceId,transport:y.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:y.agentName,agentType:y.agentType,status:T,title:k,messages:[...B,...P],ideType:y.agentType,workspaceName:c,displayPrimary:k||m||c||d,displaySecondary:`${d}·${y.agentName}`,cdpConnected:t.cdpConnected,modalButtons:w?y.activeModal.buttons:void 0,modalMessage:w?y.activeModal.message:void 0,streamSource:"agent-stream",tabKey:ys(y.sessionId||y.instanceId,M),machineName:i,connectionState:o})}return r.length===0&&r.push({ideId:t.id,sessionId:t.sessionId||t.instanceId,providerSessionId:t.providerSessionId,nativeSessionId:t.sessionId||t.instanceId,transport:t.transport,daemonId:t.daemonId||void 0,mode:"chat",agentName:dn(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:c,displayPrimary:c||d,displaySecondary:d,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:ys(t.sessionId||t.instanceId,t.id),connectionState:o}),r}function Li(t){const s=[],n=new Map;for(const r of t)if(r.parentId){const i=n.get(r.parentId)||[];i.push(r),n.set(r.parentId,i)}else s.push(r);return{topLevel:s,childrenByParent:n}}function Pi(t,s){const n=[],{daemonId:r,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now(),d=t.sessions||[],{topLevel:l,childrenByParent:f}=Li(d),u=l.filter(p=>p.kind==="workspace"&&p.transport==="cdp-page"),m=l.filter(p=>p.kind==="agent"&&p.transport==="pty"),h=l.filter(p=>p.kind==="agent"&&p.transport==="acp");n.push({...i||{},id:r,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:c,...t.version&&{version:t.version},...t.machine&&{machine:t.machine,platform:t.machine.platform},...t.instanceId&&{instanceId:t.instanceId},...t.machineNickname!==void 0&&{machineNickname:t.machineNickname},...t.p2p&&{p2p:t.p2p},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.recentLaunches&&{recentLaunches:t.recentLaunches},...t.terminalBackend&&{terminalBackend:t.terminalBackend},...t.detectedIdes&&{detectedIdes:t.detectedIdes},...t.availableProviders&&{availableProviders:t.availableProviders},cdpConnected:u.some(p=>!!p.cdpConnected)});for(const p of u){const g=f.get(p.id)||[];n.push({id:`${r}:ide:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,status:p.cdpConnected?"online":"detected",daemonId:r,instanceId:p.id,workspace:p.workspace,terminals:0,childSessions:g,agents:g.map(x=>({id:x.id,name:x.providerName,type:x.providerType,status:x.status})),activeChat:p.activeChat,chats:[],cdpConnected:p.cdpConnected,currentModel:p.currentModel,currentPlan:p.currentPlan,currentAutoApprove:p.currentAutoApprove,lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c})}for(const p of m)n.push({id:`${r}:cli:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,agentType:p.providerType,status:p.status||"running",daemonId:r,instanceId:p.id,cliName:p.providerName,mode:p.mode||"terminal",workspace:p.workspace||"",activeChat:p.activeChat,resume:p.resume,runtimeKey:p.runtimeKey,runtimeDisplayName:p.runtimeDisplayName,runtimeWorkspaceLabel:p.runtimeWorkspaceLabel,runtimeWriteOwner:p.runtimeWriteOwner??null,runtimeAttachedClients:p.runtimeAttachedClients??[],lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c,_isCli:!0});for(const p of h)n.push({id:`${r}:acp:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,agentType:p.providerType,status:p.status||"running",daemonId:r,instanceId:p.id,cliName:p.providerName,mode:"chat",workspace:p.workspace||"",activeChat:p.activeChat,runtimeKey:p.runtimeKey,runtimeDisplayName:p.runtimeDisplayName,runtimeWorkspaceLabel:p.runtimeWorkspaceLabel,runtimeWriteOwner:p.runtimeWriteOwner??null,runtimeAttachedClients:p.runtimeAttachedClients??[],currentModel:p.currentModel,currentPlan:p.currentPlan,lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,acpConfigOptions:p.acpConfigOptions,acpModes:p.acpModes,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c,_isAcp:!0});return n}function Ei(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 $i(t,s){const n=Ei(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const ur=[{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:"💚"}],pr=[{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:"🧩"}],xr=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],mr="adhdev_notification_prefs",hn={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function Di(){try{const t=localStorage.getItem(mr);if(t){const s=JSON.parse(t);return{...hn,...s}}}catch{}return{...hn}}function Bi(t){try{localStorage.setItem(mr,JSON.stringify(t))}catch{}}let Qe=Di(),qt=[];function Ki(){qt.forEach(t=>t())}function Wi(){return{...Qe}}function Oi(t){Qe={...Qe,...t},Bi(Qe),Ki()}function zi(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return qt.push(n),()=>{qt=qt.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{Oi(n)},[]);return[{...Qe},s]}function It(t){if(!Qe.globalEnabled)return!1;switch(t){case"disconnect":return Qe.disconnectAlert;case"completion":return Qe.completionAlert;case"approval":return Qe.approvalAlert;case"browser":return Qe.browserNotifications;default:return!0}}const Ui={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Hi(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function fr(){return"Notification"in window&&Notification.permission==="granted"}let lt=null;async function Fi(){if(lt!==null)return lt;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return lt=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(lt=!!await t.pushManager.getSubscription(),lt):(lt=!1,!1)}catch{return lt=!1,!1}}function Ts(t,s,n){if(fr())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 Vi(t,s={}){const n={...Ui,...s},r=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{Fi().then(d=>{o.current=d})},[]);const c=a.useCallback((d,l,f)=>{const u=Date.now();u-i.current<n.throttleMs||(i.current=u,Ts(d,l,f))},[n.throttleMs]);a.useEffect(()=>{var d;if(!(!n.enabled||!fr())&&It("browser")&&o.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,Ue(l.status,{activeModal:l.activeModal}));return}for(const l of t){const f=r.current.get(l.id),u=Ue(l.status,{activeModal:l.activeModal}),m=l.name||l.id;if(n.onApproval&&It("approval")&&u==="waiting_approval"&&f!=="waiting_approval"){const h=((d=l.activeModal)==null?void 0:d.message)||"Action requires your approval";c(`🔔 ${m} — Approval needed`,h.slice(0,120),`approval-${l.id}`)}n.onComplete&&It("completion")&&er(f)&&u==="idle"&&c(`✅ ${m} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&u==="error"&&f!=="error"&&c(`⚠️ ${m} — 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 qi{constructor(){Be(this,"dedupMap",new Map);Be(this,"DEDUP_WINDOW_MS",5e3);Be(this,"DEDUP_MAX_SIZE",50);Be(this,"DEDUP_CLEANUP_AGE_MS",1e4);Be(this,"toastCallbacks",[]);Be(this,"systemMessageCallbacks",[]);Be(this,"clearSystemMessageCallbacks",[]);Be(this,"resolveActionFn",null);Be(this,"viewRequestRespondFn",null);Be(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(n=>n!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(n=>n!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(n=>n!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const n of this.toastCallbacks)n(s)}showToast(s,n="info",r){const i=(r==null?void 0:r.id)||Date.now();this.emitToast({id:i,message:s,type:n,timestamp:i,duration:5e3,...r})}emitSystemMessage(s,n){for(const r of this.systemMessageCallbacks)r(s,n)}emitClearSystemMessage(s,n){for(const r of this.clearSystemMessageCallbacks)r(s,n)}isDuplicate(s){const n=Date.now(),r=this.dedupMap.get(s)||0;if(n-r<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,n),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,o]of this.dedupMap)n-o>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(i);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const i=this.ides.find(o=>o.id===s.ideId&&o.type==="adhdev-daemon");if(i)return i}let n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(i=>i.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),n){const i=n.daemonId;if(i){const o=this.ides.find(c=>c.id===i&&c.type==="adhdev-daemon");if(o)return o}}const r=this.ides.filter(i=>i.type==="adhdev-daemon");return r.length===1?r[0]:null}resolveRouteId(s,n){for(const r of this.ides)if(r.id.startsWith(s)&&(!n||n===r.type))return r.id;return s}findOwningSession(s){for(const n of this.ides)if(n.id===s||n.sessionId===s||(Array.isArray(n.childSessions)?n.childSessions:[]).some(i=>(i==null?void 0:i.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,m;if(!s.ideId&&s.instanceId){for(const h of this.ides)if(h.id.endsWith(`:ide:${s.instanceId}`)||h.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=h.id;break}}const r=this.resolveConversationKey(s),o=`${r||s.instanceId||s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(o))return;let c=Ie(s.ideType||"");const d=this.resolveOwningDaemon(s);if(d){const h=et(d,{fallbackId:d.id});h&&(c=s.ideType==="adhdev-daemon"?h:`${h}/${c}`)}let l="",f="info";if(s.event==="agent:generating_completed"){const h=s.duration?` (${s.duration}s)`:"";l=`✅ ${c} agent task completed${h}`,f="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&Wi().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${h}`,_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`,f="warning",r){const h=s.modalMessage||"Approval requested",p=(u=s.modalButtons)!=null&&u.length?s.modalButtons.map(g=>`[${g}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${h}
|
|
36
|
-
${p}`,_localId:`sys_approval_${Date.now()}`})}if((m=s.modalButtons)!=null&&m.length&&this.resolveActionFn){const h=this.resolveActionRouteTarget(s);if(!h)return;const p=s.agentType||s.ideType||"",g=s.ideType||"",x=s.modalButtons,j=b=>b.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),v=this.resolveActionFn,y=x.map((b,M)=>{const N=j(b).toLowerCase(),k=/^(run|approve|accept|yes|allow|always)/.test(N),B=/^(reject|deny|delete|remove|abort|cancel|no)/.test(N);return{label:j(b),variant:k?"primary":B?"danger":"default",onClick:()=>{const R=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(N);v(h,"resolve_action",{action:R?"approve":"reject",button:b,buttonIndex:M,agentType:p,ideType:g,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),w=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,T=Date.now();this.emitToast({id:T,message:w,type:f,timestamp:T,targetKey:r||h,actions:y,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const h=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${c} agent is taking a long time${h}`,f="warning",It("browser")&&!document.hasFocus()&&Ts(`⚠️ ${c} — Long Running`,`Agent has been generating for over ${h.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const h=s.requesterName||"A team member",p=s.requestId,g=s.orgId;if(l=`👁️ ${h} wants to view your session`,f="warning",p&&g&&this.viewRequestRespondFn){const x=this.viewRequestRespondFn,j=Date.now(),v=[{label:"Approve",variant:"primary",onClick:()=>{x(g,p,"approve").catch(y=>console.error("[EventManager] approve view request failed:",y))}},{label:"Decline",variant:"danger",onClick:()=>{x(g,p,"reject").catch(y=>console.error("[EventManager] reject view request failed:",y))}}];this.emitToast({id:j,message:l,type:f,timestamp:j,actions:v,duration:3e4}),l=""}It("browser")&&!document.hasFocus()&&Ts("👁️ View Request",`${h} wants to view your session`,`view-request-${p}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",f="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,f="warning");if(l){const h=Date.now();this.emitToast({id:h,message:l,type:f,timestamp:h,targetKey:r||s.ideId,duration:5e3})}}}const at=new qi;function mt(...t){return ca(la(t))}function Gi({icon:t,title:s,subtitle:n,badge:r,actions:i,className:o}){return e.jsxs("div",{className:mt("dashboard-header",o),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"header-title flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center text-lg",children:t})," ",s,r&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[r.count!==void 0?r.count:""," ",r.text]})]}),n&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:n})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function ss({icon:t,title:s,subtitle:n,badge:r,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:d}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Gi,{icon:t,title:s,subtitle:n,badge:r,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:mt("mx-auto flex w-full flex-col gap-4",o,c),children:d})})]})}function We({title:t,icon:s,description:n,accentColor:r,className:i,children:o}){return e.jsxs("div",{className:mt("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",i),style:r?{borderLeftColor:r}:void 0,children:[(t||n)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),n&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:n})]}),o]})}function zs({icon:t,title:s,description:n,action:r,className:i}){return e.jsxs("div",{className:mt("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:n}),r]})}const Yi={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"},Xi={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function Zi({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:mt("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",Yi[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:Xi[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 Ji={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"},Qi={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function eo({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:mt("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Ji[t],n),children:[e.jsx("span",{className:mt("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Qi[t])}),r]})}function to(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function _s(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function Gt(t){return t==="system"?to():t}function so(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Gt(_s()))}function hr(){const[t,s]=a.useState(_s),[n,r]=a.useState(()=>Gt(_s()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),d=l=>{t==="system"&&r(l.matches?"light":"dark")};return c.addEventListener("change",d),()=>c.removeEventListener("change",d)},[t]);const i=a.useCallback(c=>{s(c),r(Gt(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const d=c==="dark"?"light":c==="light"?"system":"dark";r(Gt(d));try{localStorage.setItem("theme",d)}catch{}return d})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function it({label:t,description:s,checked:n,disabled:r,onChange:i,extra:o}){return e.jsxs("label",{className:`flex justify-between items-center ${r?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[e.jsxs("div",{className:"pr-4",children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:s})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[o,e.jsxs("div",{className:"relative inline-flex items-center",children:[e.jsx("input",{type:"checkbox",checked:n,disabled:r,onChange:c=>i(c.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-[40px] h-[22px] rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:n?"var(--accent-primary)":"color-mix(in srgb, var(--surface-primary) 60%, var(--border-default))"}}),e.jsx("div",{className:`absolute left-[1.5px] top-[1.5px] w-[19px] h-[19px] bg-white rounded-full transition-transform duration-200 ease-in-out shadow-[0_1px_2px_rgba(0,0,0,0.15)] ${n?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}function no({onPrefChange:t}){const[s,n]=zi(),r=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(it,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(cs,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>r("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(it,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ze,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>r("browserNotifications",i)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(it,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Da,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(it,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ba,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(it,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(gt,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("disconnectAlert",i)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(it,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ot,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:i=>r("chatTaskCompletionBubble",i)}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function ro({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){const o=t.filter(c=>c.type==="adhdev-daemon");return o.length===0?e.jsx(zs,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain mx-auto opacity-90"}),title:"No machines connected",description:s||"Run 'adhdev-standalone' to connect a local daemon instance."}):e.jsx("div",{className:"flex flex-col gap-2",children:o.map(c=>e.jsx(io,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i},c.id))})}function bn({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:i,onCancel:o}){const c=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return da.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:o,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:d=>d.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:o,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,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 ao(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...ur,...pr,...xr].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function io({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){var S,W;const[o,c]=a.useState("idle"),[d,l]=a.useState(""),[f,u]=a.useState(null),[m,h]=a.useState("idle"),[p,g]=a.useState(""),x=t,j=x.version||x.daemonVersion||null,v=((S=x.machine)==null?void 0:S.platform)||((W=x.system)==null?void 0:W.platform)||"",y=et(x,{fallbackId:t.id}),w=v==="win32"?"🪟":v==="darwin"?"🍎":"🐧",T=s.filter(L=>L.daemonId===t.id&&L.transport==="cdp-page"),b=s.filter(L=>L.daemonId===t.id&&L.transport==="pty"),M=s.filter(L=>L.daemonId===t.id&&L.transport==="acp"),N=x.p2p,k=async()=>{var L,U,E,D;if(n){c("upgrading"),l("Starting upgrade...");try{const O=await n(t.id,"daemon_upgrade",{});(L=O==null?void 0:O.result)!=null&&L.alreadyLatest?(c("done"),l(`Already on v${O.result.version||"latest"}.`)):(U=O==null?void 0:O.result)!=null&&U.upgraded||(E=O==null?void 0:O.result)!=null&&E.success?(c("done"),l(`Upgrade to v${O.result.version||"latest"} started. Daemon is restarting...`)):(c("error"),l(((D=O==null?void 0:O.result)==null?void 0:D.error)||"Upgrade failed"))}catch(O){c("error"),l((O==null?void 0:O.message)||"Connection lost during upgrade")}}},B=async()=>{if(u(null),!!r){h("loading");try{await r(t.id),h("done"),g("Machine disconnected.")}catch(L){h("error"),g((L==null?void 0:L.message)||"Failed to disconnect")}}},R=async()=>{if(u(null),!!i){h("loading");try{await i(t.id),h("done"),g('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(L){h("error"),g((L==null?void 0:L.message)||"Failed to revoke token")}}},$="0.8.3",P=!j||j!==$,_=T.length+b.length+M.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:w}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:y}),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),"…"]}),j&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${P?"":"bg-bg-secondary"}`,style:P?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",j,!P&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&P&&e.jsx("button",{onClick:k,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${$}`,children:o==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):o==="done"?"✓ Updated":`↑ Update${` to v${$}`}`}),r&&e.jsx("button",{onClick:()=>u("disconnect"),disabled:m==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>u("revoke"),disabled:m==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(eo,{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:[N&&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 ${N.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${N.state==="connecting"||N.state==="new"?"animate-pulse":""}`,style:N.state==="connecting"||N.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",N.state==="connected"?"connected":N.state==="connecting"||N.state==="new"?"connecting...":N.state||"off"]}),N.peers!==void 0&&N.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",N.peers," peer",N.peers!==1?"s":"",")"]})]}),N&&_>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),_>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[T.map(L=>{const U=ao(L.type),E=L.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:U.icon}),e.jsx("span",{children:U.name}),E!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${E?"bg-green-400":"animate-pulse"}`,style:E?void 0:{background:"var(--status-warning)"},title:E?"CDP connected":"CDP connecting..."})]},L.id)}),b.map(L=>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:L.cliName||"CLI"})]},L.id)),M.map(L=>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:L.cliName||"ACP"})]},L.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(d||p)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||m==="error"?"text-red-400":o==="done"||m==="done"?"text-green-400":"text-text-muted"}`,children:p||d})]}),f==="disconnect"&&e.jsx(bn,{title:"🔌 Disconnect Machine",message:`Disconnect "${y}" from ADHDev?
|
|
37
|
-
|
|
38
|
-
This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
|
|
39
|
-
|
|
40
|
-
Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:B,onCancel:()=>u(null)}),f==="revoke"&&e.jsx(bn,{title:"⚠️ Remove Machine",message:`Remove "${y}" from your dashboard?
|
|
41
|
-
|
|
42
|
-
This will:
|
|
43
|
-
• Immediately disconnect the machine
|
|
44
|
-
• Delete the machine registration
|
|
45
|
-
• Require restarting "adhdev-standalone" on that machine
|
|
46
|
-
|
|
47
|
-
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:R,onCancel:()=>u(null)})]})}const oo=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function co(){const{preference:t,setPreference:s}=hr();return e.jsx("div",{className:"flex gap-2",children:oo.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 Rs={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},As={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},lo=[{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"}}}],br="adhdev-chat-theme",gr="adhdev-chat-theme-custom";function Yt(){if(typeof window>"u")return"ember";try{return localStorage.getItem(br)||"ember"}catch{return"ember"}}function Ze(t){try{const s=localStorage.getItem(gr);if(s){const n=JSON.parse(s);return{...t==="dark"?Rs:As,...n[t]}}}catch{}return t==="dark"?Rs:As}function Ot(t,s){try{localStorage.setItem(gr,JSON.stringify({dark:t,light:s}))}catch{}}function Ge(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${i}, ${s})`}function ns(t,s){const n=Math.min(255,parseInt(t.slice(1,3),16)+s),r=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}const uo={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function Mt(t,s){var i;const n=(i=uo[t])==null?void 0:i[s];if(!n)return;const r=document.documentElement;r.style.setProperty("--accent-primary",n),r.style.setProperty("--accent-primary-light",ns(n,24)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${ns(n,18)})`),r.style.setProperty("--border-accent",Ge(n,.35)),r.style.setProperty("--nav-active-bg",Ge(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Ge(n,.06)}`)}function ut(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ge(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ge(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ge(t.borderSubtle,.25)),s.style.setProperty("--text-primary",t.textPrimary),s.style.setProperty("--text-secondary",t.textSecondary),s.style.setProperty("--text-muted",t.textMuted),s.style.setProperty("--border-subtle",Ge(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ge(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",ns(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${ns(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ge(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ge(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ge(t.accentColor,.06)}`),s.style.setProperty("--chat-user-bg",t.userBubble),s.style.setProperty("--chat-user-color",t.userText),s.style.setProperty("--chat-user-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px 4px ${t.bubbleRadius}px`),s.style.setProperty("--chat-assistant-bg",t.assistantBubble),s.style.setProperty("--chat-assistant-color",t.assistantText),s.style.setProperty("--chat-assistant-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px ${t.bubbleRadius}px 4px`),s.style.setProperty("--chat-assistant-border",`1px solid ${Ge(t.accentColor,.12)}`),s.style.setProperty("--chat-container-bg",t.containerBg),s.style.setProperty("--dashboard-pane-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 Us(){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","--dashboard-pane-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(n=>t.style.removeProperty(n))}function po(t){try{localStorage.setItem(br,t)}catch{}if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=pt()?"dark":"light";ut(Ze(s))}else Us(),Mt(t,pt()?"dark":"light")}function xo(){const t=Yt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=pt()?"dark":"light";ut(Ze(s))}else Us(),Mt(t,pt()?"dark":"light")}function pt(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Ke({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)",flex:"1 1 0",minWidth:0},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},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:68,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 kt({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 mo({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,i]=a.useState(()=>Ze(n));a.useEffect(()=>{i(Ze(n))},[n]);const o=a.useCallback((c,d)=>{i(l=>{const f={...l,[c]:d},m=Ze(n==="dark"?"light":"dark");return n==="dark"?Ot(f,m):Ot(m,f),ut(f),s(f),f})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 14px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12,overflow:"hidden"},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},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",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(kt,{title:"App Background",children:[e.jsx(Ke,{label:"Background",value:r.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(Ke,{label:"Surface",value:r.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(Ke,{label:"Card",value:r.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(kt,{title:"App Text",children:[e.jsx(Ke,{label:"Primary",value:r.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(Ke,{label:"Secondary",value:r.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(Ke,{label:"Muted",value:r.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(kt,{title:"Borders & Accent",children:[e.jsx(Ke,{label:"Border subtle",value:r.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(Ke,{label:"Border default",value:r.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(Ke,{label:"Accent",value:r.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(kt,{title:"Chat Bubbles",children:[e.jsx(Ke,{label:"User bubble",value:r.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(Ke,{label:"User text",value:r.userText,onChange:c=>o("userText",c)}),e.jsx(Ke,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(Ke,{label:"Agent text",value:r.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(kt,{title:"Chat Layout",children:[e.jsx(Ke,{label:"Chat BG",value:r.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(Ke,{label:"Send button",value:r.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(Ke,{label:"Input border",value:r.inputBorder,onChange:c=>o("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:r.bubbleRadius,onChange:c=>o("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?Rs:As,l=Ze(t?"light":"dark");t?Ot(c,l):Ot(l,c),i(c),ut(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 fo(){const[t,s]=a.useState(Yt),[n,r]=a.useState(!0),[i,o]=a.useState(()=>Ze("dark"));a.useEffect(()=>{r(pt());const l=new MutationObserver(()=>{const m=pt();r(m);const h=Yt();h==="custom"?ut(Ze(m?"dark":"light")):Mt(h,m?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const f=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{const m=pt();r(m);const h=Yt();h==="custom"?ut(Ze(m?"dark":"light")):Mt(h,m?"dark":"light")};return f.addEventListener("change",u),()=>{l.disconnect(),f.removeEventListener("change",u)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?ut(Ze(n?"dark":"light")):(Us(),Mt(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{o(Ze(n?"dark":"light"))},[n]);const c=l=>{s(l),po(l)},d=[...lo,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:d.map(l=>{const f=t===l.id,u=n?l.preview.dark:l.preview.light,m=l.id==="honey"||l.id==="ember"?"#1a1a1a":l.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:f?"var(--bg-glass-hover)":"var(--bg-glass)",border:f?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:f?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:m},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:[f&&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(mo,{dark:n,onColorsChange:l=>o(l)})]})}const yr="adhdev_mobileDashboardMode_v1";function vr(){try{return localStorage.getItem(yr)==="workspace"?"workspace":"chat"}catch{return"chat"}}function ho(t){try{localStorage.setItem(yr,t)}catch{}}function bo(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(vr()==="chat")},[]),e.jsx(it,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ot,{size:15})," Mobile Inbox (Chat Mode)"]}),description:t?"Use the chat-first mobile inbox layout. This keeps mobile closer to a messaging app.":"Use the full workspace layout on phones and tablets.",checked:t,onChange:n=>{s(n),ho(n?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}const wr="adhdev_hiddenTabs";function go(){try{const t=localStorage.getItem(wr);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function ft(t){try{localStorage.setItem(wr,JSON.stringify([...t]))}catch{}}function yo(){const[t,s]=a.useState(go),n=a.useCallback(f=>{s(u=>{const m=new Set(u);return m.has(f)?m.delete(f):m.add(f),ft(m),m})},[]),r=a.useCallback(f=>{s(u=>{if(u.has(f))return u;const m=new Set(u);return m.add(f),ft(m),m})},[]),i=a.useCallback(f=>{s(u=>{if(!u.has(f))return u;const m=new Set(u);return m.delete(f),ft(m),m})},[]),o=a.useCallback(()=>{s(f=>{if(f.size===0)return f;const u=new Set;return ft(u),u})},[]),c=a.useCallback((f,u)=>{s(m=>{const h=new Set(m);for(const p of u)h.add(p);return ft(h),h})},[]),d=a.useCallback((f,u)=>{s(m=>{const h=new Set(m);for(const p of u)h.delete(p);return ft(h),h})},[]),l=a.useCallback(f=>t.has(f),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:i,showAllTabs:o,hideAllForDaemon:c,showAllForDaemon:d,isHidden:l}}function vo({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){a.useEffect(()=>{Hi()},[]);const i=a.useMemo(()=>t.map(o=>({id:o.tabKey,name:o.title||o.agentName||o.ideId,status:o.status,activeModal:o.modalMessage?{message:o.modalMessage,buttons:o.modalButtons}:null})),[t]);return Vi(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{n(d=>{const l=Date.now(),f={};for(const[u,m]of Object.entries(d))l-m<5e3&&(f[u]=m);return Object.keys(f).length===Object.keys(d).length?d:f})},5500);return()=>clearTimeout(c)},[s,n]),a.useEffect(()=>{const o=setInterval(()=>{const c=Date.now()-3e5;r(d=>{const l=d.filter(f=>f.timestamp>c).slice(-100);return l.length===d.length?d:l})},6e4);return()=>clearInterval(o)},[r]),null}function vs(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=Date.parse(t);if(Number.isFinite(s))return s}return 0}function ds(t){const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1];return vs(s==null?void 0:s.timestamp)||vs(s==null?void 0:s.receivedAt)||vs(s==null?void 0:s.createdAt)||0}function ws(t,s=0){return ds(t)||s||0}function gn(t){return ds(t)}function jr(t,s){const n=gn(s)-gn(t);if(n!==0)return n;const r=(t.machineName||"").localeCompare(s.machineName||"");if(r!==0)return r;const i=t.displayPrimary.localeCompare(s.displayPrimary);if(i!==0)return i;const o=t.displaySecondary.localeCompare(s.displaySecondary);return o!==0?o:t.tabKey.localeCompare(s.tabKey)}function wo(t){const s=t.filter(r=>r.type!=="adhdev-daemon"),n=new Map;for(const r of s){const i=n.get(r.id);if(!i){n.set(r.id,r);continue}const o=(i.workspace?1:0)+(i.activeChat?1:0);((r.workspace?1:0)+(r.activeChat?1:0)>o||(r.timestamp||0)>(i.timestamp||0))&&n.set(r.id,r)}return Array.from(n.values())}function zt(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 jo(t,s){const n=Date.now();return t.map(r=>{const i=s[r.tabKey];return i&&n-i<5e3?{...r,messages:[],title:""}:r})}function ko(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 i of t.childSessions||[]){const o=i.id||i.providerType,c=`${t.id}:${o}`;n.push({key:c,ref:s[c]}),n.push({key:i.id,ref:s[i.id]})}return n}function No(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 So({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:i}){const o=a.useRef([]),c=a.useRef([]),d=a.useRef([]),l=a.useRef([]),f=a.useMemo(()=>{const T=wo(t);return zt(o.current,T)?o.current:(o.current=T,T)},[t]),u=a.useMemo(()=>lr(t),[t]),m=a.useRef(new Map),h=a.useMemo(()=>{var M;const T=new Map,b=[];for(const N of f){const k=N.daemonId||((M=N.id)==null?void 0:M.split(":")[0])||N.id,B=s[k]||"new",R=N.daemonId&&u[N.daemonId]||void 0,$=ko(N,n),P=m.current.get(N.id);if(P&&P.ide===N&&P.connectionState===B&&P.machineName===R&&No(P.localRefs,$)){T.set(N.id,P),b.push(...P.conversations);continue}const _=dr(N,n,{machineName:R,connectionState:B}),S={ide:N,connectionState:B,machineName:R,localRefs:$,conversations:_};T.set(N.id,S),b.push(..._)}return m.current=T,[...b].sort(jr)},[f,n,s,u]),p=a.useMemo(()=>{const T=jo(h,r);return zt(c.current,T)?c.current:(c.current=T,T)},[h,r]),g=a.useMemo(()=>{const T=new Map;for(const b of p)b.sessionId&&T.set(b.sessionId,b);return T},[p]),x=a.useMemo(()=>{const T=new Map;for(const b of p)b.sessionId&&T.set(b.sessionId,b),T.set(b.ideId,b),T.set(b.tabKey,b);return T},[p]),j=a.useCallback(T=>{if(T)return g.get(T)},[g]),v=a.useCallback(T=>{if(T)return x.get(T)},[x]),y=a.useMemo(()=>{const T=p.filter(b=>!i.has(b.tabKey));return zt(d.current,T)?d.current:(d.current=T,T)},[p,i]),w=a.useMemo(()=>{const T=y.map(b=>b.tabKey);return zt(l.current,T)?l.current:(l.current=T,T)},[y]);return{chatIdes:f,conversations:p,visibleConversations:y,visibleTabKeys:w,resolveConversationBySessionId:j,resolveConversationByTarget:v}}function Co({isMobile:t,urlActiveTab:s,resolveConversationBySessionId:n,setSearchParams:r}){const i=a.useMemo(()=>{var d;return t||!s?null:((d=n(s))==null?void 0:d.tabKey)??null},[t,n,s]),o=a.useMemo(()=>{var d;return!t||!s?null:((d=n(s))==null?void 0:d.tabKey)??null},[t,n,s]),c=a.useCallback(()=>{s&&r(d=>{const l=new URLSearchParams(d);return l.delete("activeTab"),l},{replace:!0})},[r,s]);return{requestedDesktopTabKey:i,requestedMobileTabKey:o,consumeRequestedActiveTab:c}}function Io({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:i}){a.useEffect(()=>{at.setIdes(t)},[t]),a.useEffect(()=>{at.setResolveAction((o,c,d)=>{s(o,c,d).catch(()=>{})})},[s]),a.useEffect(()=>{const o=at.onToast(l=>{n(u=>u.some(h=>h.message===l.message&&l.timestamp-h.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 f=l.duration||5e3;setTimeout(()=>n(u=>u.filter(m=>m.id!==l.id)),f)}),c=at.onSystemMessage((l,f)=>{var m;const u=i(l);(u==null?void 0:u.transport)==="pty"&&((m=f._localId)!=null&&m.startsWith("sys_approval_"))||r(h=>({...h,[l]:[...h[l]||[],f]}))}),d=at.onClearSystemMessage((l,f)=>{r(u=>{var m;return(m=u[l])!=null&&m.length?{...u,[l]:u[l].filter(h=>{var p;return!(h.role==="system"&&((p=h._localId)!=null&&p.startsWith(f)))})}:u})});return()=>{o(),c(),d()}},[n,r]),a.useEffect(()=>{const o=ir.on("status_event",c=>at.handleRawEvent(c,"ws"));return()=>{o()}},[]),a.useEffect(()=>{var c;const o=d=>{const l=d.data;if((l==null?void 0:l.type)!=="notification_action"||l.action!=="approve"||!(l.ideId||l.targetSessionId||l.targetKey))return;const f=l.targetSessionId||l.targetKey||l.ideId,u=i(f),m=(u==null?void 0:u.ideId)||l.ideId;m&&s(m,"resolve_action",{action:"approve",button:"Approve",...(u==null?void 0:u.sessionId)&&{targetSessionId:u.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(h=>console.error("[SW Action] approve failed:",h))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",o),()=>{var d;return(d=navigator.serviceWorker)==null?void 0:d.removeEventListener("message",o)}},[i,s])}const Mo="adhdev_dashboardLayout_v1",To="adhdev_dashboardDockview_v1",Nt={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function kr(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function Nr(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function Sr(t){return`${Mo}:${t}`}function _o(t){const s=Sr(t);return kr(s,null)}function Ro(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=Sr(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Cr(t){return`${To}:${t}`}function Ao(t){const s=Cr(t);return kr(s,null)}function Lo(t,s){try{const n=Cr(t);if(!s){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function Po(){return{groupAssignments:[...Nt.groupAssignments],focusedGroup:Nt.focusedGroup,groupActiveTabIds:{...Nt.groupActiveTabIds},groupTabOrders:{...Nt.groupTabOrders},groupSizes:[...Nt.groupSizes]}}function Eo(){const[t]=a.useState(()=>Nr(typeof window<"u"?window.innerWidth:1280)),[s,n]=a.useState(()=>new Map),[r,i]=a.useState(0),[o,c]=a.useState({}),[d,l]=a.useState({}),[f,u]=a.useState([]),[m,h]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[p,g]=a.useState(!1),x=a.useCallback(()=>{if(p)return;const j=_o(t)??Po();n(new Map(j.groupAssignments)),i(j.focusedGroup),c(j.groupActiveTabIds),l(j.groupTabOrders),u(j.groupSizes),g(!0)},[p,t]);return a.useEffect(()=>{p&&Ro(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:o,groupTabOrders:d,groupSizes:f})},[p,t,s,r,o,d,f]),a.useEffect(()=>{const j=window.matchMedia("(max-width: 767px)"),v=y=>h(y.matches);return j.addEventListener("change",v),()=>j.removeEventListener("change",v)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:d,setGroupTabOrders:l,groupSizes:f,setGroupSizes:u,isMobile:m,hasHydratedStoredLayout:p,hydrateStoredLayout:x}}function $o({urlActiveTab:t,conversations:s,resolveConversationBySessionId:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:d,setSearchParams:l,historyModalOpen:f,activeConv:u,isRefreshingHistory:m,ides:h,handleRefreshHistory:p}){const g=a.useRef(!1),x=a.useRef(!1),j=a.useRef(null),v=a.useRef(!1);a.useEffect(()=>{if(!t||g.current||s.length===0)return;if(!i){o();return}const y=n(t);if(!y)return;const w=r.get(y.tabKey)??0;c(T=>({...T,[w]:y.tabKey})),d(w),g.current=!0,x.current=!0,j.current!=null&&(window.clearTimeout(j.current),j.current=null),l(T=>{const b=new URLSearchParams(T);return b.delete("activeTab"),b},{replace:!0})},[t,s,n,r,i,o,c,d,l]),a.useEffect(()=>{if(!(x.current||i)&&s.length!==0){if(!t){o(),x.current=!0;return}if(g.current){x.current=!0;return}if(j.current==null)return j.current=window.setTimeout(()=>{j.current=null,!(x.current||i)&&(o(),x.current=!0)},1500),()=>{j.current!=null&&(window.clearTimeout(j.current),j.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!f){v.current=!1;return}if(!u||v.current||m)return;const y=h.find(w=>w.id===u.ideId);y&&(!y.chats||y.chats.length===0)&&(v.current=!0,p())},[f,u,m,h,p]),a.useEffect(()=>{if(!u)return;let y=null,w=0,T=-1,b=0;const M=()=>{y=null;const N=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(B=>B.offsetParent!==null);if(N.length===0){w<18&&(w+=1,y=requestAnimationFrame(M));return}let k=0;for(const B of N)B.scrollTop=B.scrollHeight,k+=B.scrollHeight;k===T?b+=1:(b=0,T=k),w+=1,!(b>=2||w>=18)&&(y=requestAnimationFrame(M))};return y=requestAnimationFrame(M),()=>{y!=null&&cancelAnimationFrame(y)}},[u==null?void 0:u.tabKey])}function Do({isMobile:t,location:s,navigate:n,requestedRemoteTabTarget:r,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:d}){const[l,f]=a.useState(null),[u,m]=a.useState(null),h=a.useMemo(()=>{if(t||!r)return null;const v=d(r);return v&&!Pe(v)&&!Me(v)?v:null},[t,r,d]),p=a.useMemo(()=>{const v=l==null?void 0:l.ideId;if(!v)return null;const y=l!=null&&l.tabKey?o.find(w=>w.tabKey===l.tabKey):i?o.find(w=>w.tabKey===i):null;return(y==null?void 0:y.ideId)===v?y:o.find(w=>w.ideId===v&&w.streamSource==="native")||o.find(w=>w.ideId===v)||null},[o,l,i]),g=a.useMemo(()=>{if(p)return c.find(v=>v.id===p.ideId)},[c,p]);a.useEffect(()=>{h&&(f({ideId:h.ideId,tabKey:h.streamSource==="native"?"native":h.tabKey}),m(h),n({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,n,h]);const x=a.useCallback(v=>{v&&(f({ideId:v.ideId,tabKey:v.streamSource==="native"?"native":v.tabKey}),m(v))},[]),j=a.useCallback(()=>{f(null),m(null)},[]);return{remoteDialogConv:p,remoteDialogIdeEntry:g,remoteDialogActiveConv:u,setRemoteDialogActiveConv:m,openRemoteDialog:x,closeRemoteDialog:j}}function Tt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Pe(t)||Me(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function rs(t){return t&&(t.ideId||t.daemonId)||""}function Ut(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function yn({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:i,setClearedTabs:o}){const[c,d]=a.useState(!1),[l,f]=a.useState(!1),u=a.useCallback(async g=>{try{await t("standalone","launch_ide",{ideType:g,enableCdp:!0})}catch(x){console.error("Launch failed",x)}},[t]),m=a.useCallback(async(g,x)=>{try{const j=g||(s==null?void 0:s.daemonId)||"",v=await t(j,"switch_chat",{id:x,sessionId:x,...Tt(s)}),y=v==null?void 0:v.result;if((v==null?void 0:v.success)===!0||y==="switched"||y==="switched-by-title")return;y===!1||y==="not_found"?Ut(r,"⚠️ Session tab not found — try refreshing history"):typeof y=="string"&&y.startsWith("error:")?Ut(r,`⚠️ Switch error: ${y}`):Ut(r,"⚠️ Session switch failed")}catch(j){console.error("Switch failed",j),Ut(r,`❌ Switch failed: ${j.message||"connection error"}`)}},[s,t,r]),h=a.useCallback(async()=>{if(!(!s||c)){d(!0);try{const g=rs(s);await t(g,"new_chat",{...Tt(s)}),o(x=>({...x,[s.tabKey]:Date.now()})),i(x=>({...x,[s.tabKey]:[]}))}catch(g){console.error("New chat failed",g)}finally{d(!1)}}},[s,c,t,o,i]),p=a.useCallback(async()=>{var g;if(!(!s||l)){f(!0);try{const x=rs(s),j=await t(x,"list_chats",{forceExpand:!0,...Tt(s)}),v=(j==null?void 0:j.chats)||((g=j==null?void 0:j.result)==null?void 0:g.chats);j!=null&&j.success&&Array.isArray(v)&&n(s.ideId,v)}catch(x){console.error("Refresh history failed",x)}finally{f(!1)}}},[s,l,t,n]);return{isCreatingChat:c,isRefreshingHistory:l,handleLaunchIde:u,handleSwitchSession:m,handleNewChat:h,handleRefreshHistory:p}}function Bo(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 Ko(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function vn(t,s){const n=Object.keys(t),r=Object.keys(s);return n.length!==r.length?!1:n.every(i=>s[Number(i)]===t[Number(i)])}function Ht(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[c,d]of t)!n.has(c)||d<=0||r.includes(d)||r.push(d);r.sort((c,d)=>c-d);const i={};r.forEach((c,d)=>{i[c]=d}),r.length===0&&(i[0]=0);const o=new Map;for(const[c,d]of t){if(!n.has(c)||d<=0)continue;const l=i[d];typeof l=="number"&&l>0&&o.set(c,l)}return{assignments:o,groupCount:Math.max(1,r.length),mapping:i,usedGroups:r}}function wn(t,s){const n={};for(const[r,i]of Object.entries(t)){const o=s[Number(r)];typeof o=="number"&&(n[o]=i)}return n}function Wo(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(i=>i<t)??s[0];return n[r]??0}function Oo(t,s,n){if(s.length<=1)return[];const r=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),i=r.length===s.length?r:Array(n).fill(100/n),o=i.reduce((c,d)=>c+d,0);return o>0?i.map(c=>c/o*100):Array(n).fill(100/n)}function jn(t,s){const n={};for(const[r,i]of Object.entries(t)){const o=Number(r);n[o>=s?o+1:o]=i}return n}function kn(t){return Array(t).fill(100/t)}function zo({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:d,visibleConversations:l,visibleTabKeys:f}){const u=a.useRef(null),m=a.useMemo(()=>Ht(t,f),[t,f]),h=m.assignments,p=a.useMemo(()=>d?1:m.groupCount,[m.groupCount,d]),g=p>1,x=a.useCallback((b,M)=>{s(N=>{const k=new Map(Ht(N,f).assignments);return M===0?k.delete(b):k.set(b,M),k}),r(N=>({...N,[M]:b})),n(M)},[s,f,r,n]),j=a.useCallback(b=>{s(M=>{const N=Ht(M,f).assignments,k=new Map;for(const[B,R]of N)R!==b&&(R>b?k.set(B,R-1):k.set(B,R));return k}),c(M=>{if(M.length<=1)return[];const N=[...M];N.splice(b,1);const k=N.reduce((B,R)=>B+R,0);return k>0?N.map(B=>B/k*100):[]}),n(0)},[s,f,c,n]),v=a.useCallback((b,M)=>{M.preventDefault();const N=u.current;if(!N)return;const k=M.clientX,B=N.offsetWidth,R=o.length===p?[...o]:kn(p),$=_=>{const W=(_.clientX-k)/B*100,L=[...R];L[b]=Math.max(15,R[b]+W),L[b+1]=Math.max(15,R[b+1]-W),c(L)},P=()=>{document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",P),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",$),document.addEventListener("mouseup",P)},[o,p,c]),y=a.useCallback((b,M,N)=>{if(p>=4)return;const k=N==="left"?M:M+1;s(B=>{const R=Ht(B,f).assignments,$=new Map;for(const P of l){const _=R.get(P.tabKey)??0,S=_>=k?_+1:_;S>0&&$.set(P.tabKey,S)}return k>0&&$.set(b,k),$}),c(B=>{const R=B.length===p?[...B]:kn(p),$=R[M]??100/p,P=Math.max(15,$/2),_=Math.max(15,$/2),S=[...R];S[M]=P,S.splice(k,0,_);const W=S.reduce((L,U)=>L+U,0);return S.map(L=>L/W*100)}),r(B=>{const R=jn(B,k);return R[k]=b,R}),i(B=>{const R=jn(B,k);return R[k]=[b],R}),n(k)},[p,s,f,l,c,r,i,n]);a.useEffect(()=>{Bo(t,h)||s(h)},[t,h,s]),a.useEffect(()=>{const{mapping:b,usedGroups:M}=m;r(N=>{const k=wn(N,b);return vn(N,k)?N:k}),i(N=>{const k=wn(N,b);return vn(N,k)?N:k}),n(N=>{const k=d?0:Wo(N,M,b);return N===k?N:k}),c(N=>{const k=d?[]:Oo(N,M,m.groupCount);return Ko(N,k)?N:k})},[m,d,r,i,n,c]);const w=a.useMemo(()=>{const b=Array.from({length:p},()=>[]);for(const M of l){const N=h.get(M.tabKey)??0,k=Math.min(N,p-1);b[k].push(M)}return b},[l,h,p]),T=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:u,normalizedGroupAssignments:h,numGroups:p,isSplitMode:g,groupedConvs:w,moveTabToGroup:x,closeGroup:j,handleResizeStart:v,splitTabRelative:y,clearAllSplits:T}}function Uo({ides:t,sendDaemonCommand:s}){const n="0.8.3",r=a.useMemo(()=>t.filter(f=>{if(f.type!=="adhdev-daemon")return!1;const u=f.version||f.daemonVersion||null;return!u||!n?!1:u!==n}),[n,t]),[i,o]=a.useState(!1),[c,d]=a.useState({}),l=a.useCallback(async f=>{var u,m;d(h=>({...h,[f]:"upgrading"}));try{const h=await s(f,"daemon_upgrade",{});(u=h==null?void 0:h.result)!=null&&u.upgraded||(m=h==null?void 0:h.result)!=null&&m.success?d(p=>({...p,[f]:"done"})):d(p=>({...p,[f]:"error"}))}catch{d(h=>({...h,[f]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:l}}function us({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:i}){const[o,c]=a.useState(!1),[d,l]=a.useState(!1),f=a.useRef(!1),u=a.useCallback(async g=>{if(!s)return;const x=g.trim();if(!x||f.current)return;const j=s.tabKey;f.current=!0,l(!0);const v=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,y={role:"user",content:x,timestamp:Date.now(),_localId:v};n(w=>({...w,[j]:[...w[j]||[],y]}));try{const w=rs(s);if(!w)return;await t(w,"send_chat",{message:x,text:x,...Tt(s)}),setTimeout(()=>{const T=Date.now()-6e4;n(b=>{const M=b[j];if(!M)return b;const N=M.filter(k=>k.timestamp>T);return N.length===M.length?b:{...b,[j]:N}})},6e4)}catch(w){console.error("Send failed",w),n(T=>({...T,[j]:(T[j]||[]).filter(b=>b._localId!==v)}))}finally{f.current=!1,l(!1)}},[s,t,n]),m=a.useCallback(async()=>{if(s)try{await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0})}catch(g){console.error("Relaunch failed",g)}},[s,t]),h=a.useCallback(async g=>{if(s){s.transport!=="pty"&&r(x=>[...x,{ideId:s.tabKey,text:`🖱️ **${g}** clicked`,timestamp:Date.now()}]);try{const j=(s.modalButtons||[]).indexOf(g),v=g.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),y=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(v),w=rs(s);if(!w)return;(await t(w,"resolve_action",{button:g,action:y?"approve":"reject",...j>=0&&{buttonIndex:j},...Tt(s)})).success||r(b=>[...b,{ideId:s.tabKey,text:`⚠️ **${g}** failed — button not found`,timestamp:Date.now()}])}catch(x){console.error("[ModalButton] Error:",x),r(j=>[...j,{ideId:s.tabKey,text:`❌ **${g}** error`,timestamp:Date.now()}])}}},[s,t,r]),p=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(g){console.error("Focus agent failed",g)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:d,isFocusingAgent:o,handleSendChat:u,handleRelaunch:m,handleModalButton:h,handleFocusAgent:p}}const Hs=a.memo(function({activeConv:s,clearToken:n,isCliTerminal:r,ideEntry:i,terminalRef:o,handleModalButton:c,handleRelaunch:d,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:m,actionLogs:h,userName:p}){return e.jsxs(e.Fragment,{children:[e.jsx(Qn,{activeConv:s,onModalButton:c}),s.transport!=="pty"&&s.transport!=="acp"&&s.cdpConnected===!1?e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children: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(Bs,{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:d,children:"Relaunch with CDP"})]})}):null,s.transport==="pty"?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:r?"flex":"none",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Ni,{activeConv:s,clearToken:n,terminalRef:o,handleSendChat:l,isSendingChat:f,isVisible:r})}),!r&&e.jsx("div",{style:{display:"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Ms,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:m,actionLogs:h,userName:p})})]}):e.jsx(Ms,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:m,actionLogs:h,userName:p})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCliTerminal===s.isCliTerminal&&t.ideEntry===s.ideEntry&&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 Ho({selectedConversation:t,isAcp:s,selectedIdeEntry:n,actionLogs:r,userName:i,isSendingChat:o,isFocusingAgent:c,onBack:d,onOpenNativeConversation:l,onOpenMachine:f,onOpenHistory:u,onOpenRemote:m,onHideConversation:h,onStopCli:p,cliViewMode:g,onSetCliViewMode:x,handleSendChat:j,handleFocusAgent:v,handleModalButton:y,handleRelaunch:w}){const T=a.useRef(null),b=Pe(t)&&!s,M=b&&g==="terminal";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5 border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[e.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:d,type:"button","aria-label":"Back",children:e.jsx(Es,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:t.displayPrimary||t.agentName}),e.jsx("div",{className:"min-w-0 overflow-hidden text-xs text-text-secondary",children:e.jsx(nr,{conversation:t,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>l(t),onOpenMachine:()=>f(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[b&&g&&e.jsx(Os,{mode:g,onChange:x,compact:!0}),b&&p&&e.jsx("button",{onClick:p,className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:e.jsx(yt,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>u(t),type:"button",children:e.jsx($s,{size:14})}),!s&&!b&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>m(t),type:"button",children:e.jsx(ze,{size:14})}),h&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(t),type:"button",title:"Close chat",children:e.jsx(yt,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(Hs,{activeConv:t,clearToken:0,isCliTerminal:M,ideEntry:n,terminalRef:T,handleModalButton:y,handleRelaunch:w,handleSendChat:j,isSendingChat:o,handleFocusAgent:v,isFocusingAgent:c,actionLogs:r,userName:i})})]})}const js={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 Fo(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Ir(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":n;a.useEffect(()=>{s(Fo())},[]);const d=a.useCallback(()=>{navigator.clipboard.writeText(js[c].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="powershell"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:d,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:js[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:js[c].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:i?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function Mr({section:t,onSectionChange:s}){return e.jsx("div",{className:"grid grid-cols-2 gap-2 px-3 py-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))] border-t border-[#ffffff0a] bg-bg-secondary/90 backdrop-blur-md shrink-0",children:[["machines","Machines"],["chats","Chats"]].map(([n,r])=>{const i=t===n;return e.jsx("button",{className:`min-h-[42px] rounded-xl text-[13px] font-bold tracking-tight transition-all border ${i?"bg-accent-primary border-transparent text-white shadow-glow":"bg-bg-primary border border-[#ffffff10] text-text-secondary hover:bg-bg-secondary hover:text-text-primary shadow-sm"}`,onClick:()=>s(n),type:"button",children:r},n)})})}function St({icon:t,title:s,subtitle:n,children:r}){return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 pt-12 pb-8 px-6 text-center",children:[e.jsx("div",{className:"mb-2",children:t}),e.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:s}),e.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:n}),r]})}function Ft({item:t,type:s,getAvatarText:n,onOpenConversation:r}){const i=s==="needs_attention"||s==="task_complete",o=s==="working",c=s==="earlier";return e.jsxs("button",{className:`flex items-start gap-3.5 p-3.5 w-full bg-bg-secondary/40 border border-[#ffffff0a] rounded-xl text-left relative overflow-hidden transition-all active:scale-[0.98] ${i?"bg-bg-secondary shadow-glow border-[#ffffff14]":c?"opacity-70 saturate-50":""}`,onClick:()=>r(t.conversation),type:"button",children:[e.jsx("span",{className:`w-10 h-10 rounded-[10px] flex items-center justify-center text-sm font-bold shrink-0 ${i?"bg-accent-primary text-white shadow-glow":o?"bg-bg-primary border border-accent-primary text-text-primary":"bg-bg-primary border border-[#ffffff1a] text-text-secondary"}`,children:n(t.conversation.displayPrimary)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:t.conversation.displayPrimary}),!o&&e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:Jn(t.timestamp)})]}),e.jsxs("div",{className:"text-[12px] font-medium text-text-secondary truncate flex items-center",children:[t.conversation.displaySecondary,t.conversation.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1 opacity-80",children:[e.jsx(ze,{size:11})," ",t.conversation.machineName]})]}),s==="needs_attention"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:"text-orange-400",children:"Action needed"})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:t.preview})]}),i&&e.jsx("span",{className:"absolute top-4 right-4 w-2 h-2 rounded-full bg-accent-primary shadow-glow"}),o&&e.jsx("span",{className:"absolute top-3.5 right-3 px-1.5 py-0.5 rounded-[4px] bg-accent-primary/20 text-accent-primary text-[10px] font-extrabold uppercase tracking-wide",children:"Live"})]},t.conversation.tabKey)}function Nn({size:t=32,label:s}){return e.jsxs("div",{className:"flex flex-col items-center gap-2.5",children:[e.jsx("div",{className:"rounded-full animate-spin border-[2.5px] border-accent-primary/20 border-t-accent-primary-light",style:{width:t,height:t}}),s&&e.jsx("div",{className:"text-xs font-semibold text-accent-primary-light tracking-tight",children:s})]})}function Vo({section:t,attentionItems:s,unreadItems:n,workingItems:r,completedItems:i,hiddenConversations:o,machineCards:c,getAvatarText:d,onOpenConversation:l,onShowConversation:f,onShowAllHidden:u,onOpenMachine:m,onOpenSettings:h,onOpenAccount:p,onSectionChange:g,wsStatus:x="connected",isStandalone:j=!1}){const v=x==="disconnected"||x==="reconnecting"||x==="offline"||x==="auth_failed",y=c.length>0,w=s.length>0||n.length>0||r.length>0||i.length>0,T=t==="machines"?"Machines":"Chats";return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden bg-bg-primary",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4 shrink-0 bg-bg-primary z-10",children:[e.jsx("div",{className:"text-2xl font-black tracking-tight text-text-primary px-1",children:T}),e.jsxs("div",{className:"flex items-center gap-3",children:[t==="chats"&&(s.length>0||n.length>0)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-accent-primary/20 text-accent-primary text-[11px] font-bold",children:[e.jsx(cs,{size:13}),e.jsx("span",{children:s.length+n.length})]}),e.jsx("button",{onClick:h,className:"w-8 h-8 flex items-center justify-center rounded-full bg-[#ffffff0a] text-text-secondary hover:text-text-primary hover:bg-[#ffffff14] transition-colors",children:e.jsx(os,{size:18})}),p&&e.jsx("button",{onClick:p,className:"w-8 h-8 flex items-center justify-center rounded-full bg-[#ffffff0a] text-text-secondary hover:text-text-primary hover:bg-[#ffffff14] transition-colors",children:e.jsx(Un,{size:18})})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))] flex flex-col gap-3 -webkit-overflow-scrolling-touch",children:[t==="chats"&&s.length>0&&e.jsx("section",{className:"flex flex-col gap-0",children:e.jsxs("div",{className:"mx-2 mb-2 p-3 rounded-2xl bg-accent-primary/10 text-text-secondary flex items-center justify-between gap-2.5 text-xs",children:[e.jsx("span",{className:"font-bold text-text-primary",children:"Needs attention"}),e.jsxs("span",{className:"font-bold text-accent-primary",children:[s.length," action needed"]})]})}),t==="chats"&&n.length>0&&e.jsx("section",{className:"flex flex-col gap-0",children:e.jsxs("div",{className:"mx-2 mb-2 p-3 rounded-2xl bg-accent-primary/10 text-text-secondary flex items-center justify-between gap-2.5 text-xs",children:[e.jsx("span",{className:"font-bold text-text-primary",children:"Task complete"}),e.jsxs("span",{className:"font-bold text-accent-primary",children:[n.length," unread"]})]})}),t==="machines"&&e.jsx("section",{className:"flex flex-col gap-2",children:v?e.jsx(St,{icon:e.jsx(Nn,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:x==="offline"?"Your device appears to be offline. Waiting for network…":x==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(St,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:j?"Waiting for your IDE":"Connect your first machine",subtitle:j?"Launch any supported IDE or CLI agent — it will appear here automatically.":"Install the ADHDev daemon on your machine, then it will show up here.",children:!j&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(Ir,{})})}):c.map(b=>e.jsxs("button",{className:"flex items-start gap-3.5 p-3.5 w-full bg-bg-secondary/40 border border-[#ffffff0a] rounded-xl text-left transition-all active:scale-[0.98]",onClick:()=>m(b.id),type:"button",children:[e.jsx("span",{className:"w-10 h-10 rounded-[10px] flex items-center justify-center text-sm font-bold shrink-0 bg-bg-secondary border border-[#ffffff14] text-text-primary shadow-[0_2px_8px_rgba(0,0,0,0.2)]",children:d(b.label)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:b.label}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:b.unread>0?e.jsxs("span",{className:"text-accent-primary",children:[b.unread," new"]}):b.total>0?`${b.total} chats`:"Idle"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:b.subtitle}),b.total>0?e.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[b.total," chat",b.total!==1?"s":"",b.unread>0?` · ${b.unread} unread`:""]}):e.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},b.id))}),t==="chats"&&s.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx("div",{className:"text-[12px] font-bold uppercase tracking-wider text-text-secondary px-1 mb-1",children:"Needs attention"}),s.map(b=>e.jsx(Ft,{item:b,type:"needs_attention",getAvatarText:d,onOpenConversation:l},b.conversation.tabKey))]}),t==="chats"&&n.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx("div",{className:"text-[12px] font-bold uppercase tracking-wider text-text-secondary px-1 mb-1 mt-2",children:"Task complete"}),n.map(b=>e.jsx(Ft,{item:b,type:"task_complete",getAvatarText:d,onOpenConversation:l},b.conversation.tabKey))]}),t==="chats"&&r.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx("div",{className:"text-[12px] font-bold uppercase tracking-wider text-text-secondary px-1 mb-1 mt-2",children:"Working now"}),r.map(b=>e.jsx(Ft,{item:b,type:"working",getAvatarText:d,onOpenConversation:l},b.conversation.tabKey))]}),t==="chats"&&e.jsxs("section",{className:"flex flex-col gap-2",children:[i.length>0&&e.jsx("div",{className:"text-[12px] font-bold uppercase tracking-wider text-text-secondary px-1 mb-1 mt-2",children:"Earlier"}),i.length>0?i.map(b=>e.jsx(Ft,{item:b,type:"earlier",getAvatarText:d,onOpenConversation:l},b.conversation.tabKey)):w?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):v?e.jsx(St,{icon:e.jsx(Nn,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):y?e.jsx(St,{icon:e.jsx("div",{className:"w-11 h-11 rounded-xl flex items-center justify-center bg-accent-primary/10 text-accent-primary-light",children:e.jsx(ot,{size:20})}),title:"No conversations yet",subtitle:"Your machines are connected. Open an IDE or launch a CLI agent to start your first conversation."}):e.jsx(St,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-10 h-10 object-contain opacity-70"}),title:"No machines connected",subtitle:"Switch to the Machines tab to connect your first machine and start chatting with AI agents."})]}),t==="chats"&&o.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-[12px] font-bold uppercase tracking-wider text-text-secondary px-1 mb-1 mt-4",children:[e.jsx("span",{children:"Hidden"}),e.jsx("button",{type:"button",className:"text-accent-primary normal-case font-semibold hover:underline",onClick:u,children:"Restore all"})]}),o.map(b=>e.jsxs("button",{className:"flex items-start gap-3.5 p-3.5 w-full bg-bg-secondary/20 border border-[#ffffff05] rounded-xl text-left transition-all active:scale-[0.98] opacity-50 saturate-0",onClick:()=>f(b),type:"button",children:[e.jsx("span",{className:"w-10 h-10 rounded-[10px] flex items-center justify-center text-sm font-bold shrink-0 bg-bg-primary border border-[#ffffff1a] text-text-secondary",children:d(b.displayPrimary)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:b.displayPrimary}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:"Hidden"})]}),e.jsxs("div",{className:"text-[12px] font-medium text-text-secondary truncate flex items-center",children:[b.displaySecondary,b.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1 opacity-80",children:[e.jsx(ze,{size:11})," ",b.machineName]})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:"Tap to restore and open"})]})]},b.tabKey))]})]}),e.jsx(Mr,{section:t,onSectionChange:g})]})}function qo(t){const s=t.replace(/[\\/]+$/,"");if(!s||s==="/"||/^[A-Za-z]:$/.test(s))return null;const n=s.includes("\\")?"\\":"/",r=s.split(/[\\/]/);return/^[A-Za-z]:$/.test(r[0]||"")?r.length<=2?`${r[0]}\\`:r.slice(0,-1).join("\\"):r.length<=2?n:r.slice(0,-1).join(n)||n}async function Tr(t,s,n){const r=await t(s,"file_list_browse",{path:n});if(!(r!=null&&r.success))throw new Error((r==null?void 0:r.error)||"Could not browse folder");const i=typeof(r==null?void 0:r.path)=="string"?r.path:n,o=i.includes("\\")?"\\":"/",c=(l,f)=>/^[A-Za-z]:\\?$/.test(l)?`${l.replace(/\\?$/,"\\")}${f}`:l==="/"||l==="\\"?`${o}${f}`:`${l.replace(/[\\/]+$/,"")}${o}${f}`,d=Array.isArray(r==null?void 0:r.files)?r.files.filter(l=>(l==null?void 0:l.type)==="directory"&&typeof(l==null?void 0:l.name)=="string").map(l=>({name:l.name,path:c(i,l.name)})).sort((l,f)=>l.name.localeCompare(f.name)):[];return{path:i,directories:d}}function Fs({title:t,description:s,currentPath:n,directories:r,busy:i=!1,error:o="",confirmLabel:c="Use this folder",onClose:d,onNavigate:l,onConfirm:f}){const u=qo(n);return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"workspace-browse-title",children:e.jsxs("div",{className:"w-full max-w-2xl max-h-[min(86vh,720px)] rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"workspace-browse-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:d,"aria-label":"Close folder browser",children:e.jsx(yt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-3 border-b border-border-subtle bg-bg-primary/60 flex items-center gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 min-h-[34px] px-3 rounded-lg border border-border-subtle bg-bg-secondary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors",onClick:()=>{!u||i||l(u)},disabled:!u||i,children:[e.jsx(Es,{size:15}),"Parent"]}),e.jsxs("div",{className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-0.5",children:"Current folder"}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:n||"Loading…"})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:i?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"Loading folders…"}):o?e.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:o}):r.length===0?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"No subfolders here."}):e.jsx("div",{className:"p-3",children:r.map(m=>e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3.5 py-3 rounded-xl text-left border border-transparent hover:border-border-subtle hover:bg-bg-secondary transition-colors",onClick:()=>l(m.path),children:[e.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:e.jsx(At,{size:17})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-sm font-medium text-text-primary truncate",children:m.name}),e.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:m.path})]})]},m.path))})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:d,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>f(n),disabled:!n||i,children:c})]})]})})}function Vs({title:t,description:s,details:n,workspaceOptions:r,selectedWorkspaceKey:i,onWorkspaceChange:o,confirmLabel:c="Launch",busy:d=!1,onConfirm:l,onCancel:f}){const u=r==null?void 0:r.find(m=>m.key===i);return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-confirm-title",children:e.jsxs("div",{className:"w-full max-w-lg rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"launch-confirm-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:f,"aria-label":"Close launch confirmation",children:e.jsx(yt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[r&&r.length>0&&o&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Workspace"}),e.jsx("select",{value:i||"",onChange:m=>o(m.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:d,children:r.map(m=>e.jsx("option",{value:m.key,children:m.label},m.key))}),(u==null?void 0:u.description)&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:u.description})]}),n.map(m=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:m.label}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:m.value})]},`${m.label}:${m.value}`))]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:f,disabled:d,children:"Cancel"}),e.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:l,disabled:d,children:[e.jsx(Gn,{size:14}),d?"Launching…":c]})]})]})})}function Sn(t,s){return s||t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t}function xt(t){const{machine:s,currentWorkspacePath:n,currentWorkspaceId:r,includeHome:i=!0}=t,o=[];i&&o.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const l of s.workspaces||[])o.push({key:`saved:${l.id}`,label:`${l.id===s.defaultWorkspaceId?"⭐ ":""}${Sn(l.path,l.label)}`,description:l.path,workspaceId:l.id,workspacePath:l.path});const c=(n==null?void 0:n.trim())||"",d=c?(s.workspaces||[]).find(l=>l.path===c):null;if(c&&!d&&o.push({key:`custom:${c}`,label:Sn(c),description:c,workspaceId:null,workspacePath:c}),r){const l=`saved:${r}`;if(o.some(f=>f.key===l))return{options:o,selectedKey:l}}return d?{options:o,selectedKey:`saved:${d.id}`}:c?{options:o,selectedKey:`custom:${c}`}:{options:o,selectedKey:"__home__"}}function Go({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:n,cliProviders:r,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:d,section:l,showBottomNav:f,onBack:u,onSectionChange:m,onOpenConversation:h,onOpenRecent:p,onOpenMachineDetails:g,onMachineUpgrade:x,onLaunchDetectedIde:j,onAddWorkspace:v,onBrowseDirectory:y,onLaunchWorkspaceProvider:w}){var Oe,Le,Ee,Ve;const T=(ne,we,ye)=>ne?"ide":we>0?"cli":ye>0?"acp":null,[b,M]=a.useState(!1),N=ne=>ne==="ide"?"IDE":ne==="cli"?"CLI":"ACP",k=n.slice(0,4),B=s.slice(0,3),R=(((Oe=t.detectedIdes)==null?void 0:Oe.length)||0)>0,$=a.useMemo(()=>t.workspaces||[],[t]),P=t.defaultWorkspaceId||null,[_,S]=a.useState(P||((Le=$[0])==null?void 0:Le.id)||""),[W,L]=a.useState(""),[U,E]=a.useState(""),[D,O]=a.useState([]),[A,Q]=a.useState(!1),[xe,ue]=a.useState(""),[te,ee]=a.useState(!1),[H,Y]=a.useState(T(R,r.length,i.length)),F=a.useRef(null),[J,se]=a.useState(null),X=a.useRef("__home__"),[le,ge]=a.useState("__home__"),[pe,ve]=a.useState(!1),Z=a.useRef(null),ce=_==="__custom__"?W.trim():((Ee=$.find(ne=>ne.id===_))==null?void 0:Ee.path)||"",I=_==="__custom__"&&!!ce&&d.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(d.message),ae=_!=="__custom__"&&((Ve=$.find(ne=>ne.id===_))==null?void 0:Ve.path)||"",me=a.useCallback(async ne=>{Q(!0),ue("");try{const we=await y(ne);E(we.path),L(we.path),O(we.directories)}catch(we){ue(we instanceof Error?we.message:"Could not load folder")}finally{Q(!1)}},[y]),oe=a.useCallback(()=>{var we,ye;S("__custom__"),ee(!0);const ne=W.trim()||ae||((we=$.find(he=>he.id===P))==null?void 0:we.path)||((ye=$[0])==null?void 0:ye.path)||"~";me(ne)},[W,P,me,ae,$]),be=a.useCallback((ne,we)=>{F.current=we,X.current=ne.selectedWorkspaceKey||"__home__",ge(ne.selectedWorkspaceKey||"__home__"),se(ne)},[]),je=a.useCallback(()=>{F.current&&(ve(!0),F.current().finally(()=>{F.current=null,ve(!1),se(null)}))},[]);a.useEffect(()=>{var ne;Z.current!==t.id&&(Z.current=t.id,S(P||((ne=$[0])==null?void 0:ne.id)||"__custom__"),L(""),E(""),O([]),ue(""),ee(!1),Y(T(R,r.length,i.length)))},[i.length,r.length,P,R,t.id,$]),a.useEffect(()=>{var ne;_!=="__custom__"&&(_&&$.some(we=>we.id===_)||S(P||((ne=$[0])==null?void 0:ne.id)||"__custom__"))},[P,_,$]),a.useEffect(()=>{H==="ide"&&R||H==="cli"&&r.length>0||H==="acp"&&i.length>0||Y(T(R,r.length,i.length))},[H,i.length,r.length,R]);const Re=a.useMemo(()=>{const ne=k.map(ye=>({key:`recent-launch:${ye.id}`,type:"session",primary:ye.label,secondary:`${N(ye.kind)}${ye.subtitle?` · ${ye.subtitle}`:""}`,unread:!1,onClick:()=>{const{options:he,selectedKey:He}=xt({machine:{workspaces:$,defaultWorkspaceId:P},currentWorkspacePath:ye.workspace});be({title:`Launch ${ye.label}?`,description:"Recent launches require one more confirmation before they run.",confirmLabel:"Launch",workspaceOptions:he,selectedWorkspaceKey:He,details:[{label:"Mode",value:N(ye.kind)},...ye.providerType?[{label:"Provider",value:ye.providerType}]:[]]},async()=>{const K=he.find(z=>z.key===X.current);K!=null&&K.workspaceId?(S(K.workspaceId),L("")):K!=null&&K.workspacePath?(S("__custom__"),L(K.workspacePath)):(S(""),L("")),await p({...ye,workspace:(K==null?void 0:K.workspacePath)??null})})}})),we=B.map(ye=>({key:`recent-chat:${ye.conversation.tabKey}`,type:"conversation",primary:ye.conversation.displayPrimary,secondary:`Chat${ye.conversation.displaySecondary?` · ${ye.conversation.displaySecondary}`:""}${ye.timestamp?` · ${Jn(ye.timestamp)}`:""}`,unread:ye.unread,onClick:()=>h(ye.conversation)}));return[...ne,...we]},[P,h,p,be,B,k,$]),Te=b?Re:Re.slice(0,5),tt=Re.length>0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center justify-between gap-3 px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3 border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md",children:e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[e.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:u,type:"button","aria-label":"Back",children:e.jsx(Es,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:et(t,{fallbackId:t.id})}),e.jsxs("div",{className:"min-w-0 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary truncate",children:[t.platform||"machine",t.version?` · v${t.version}`:""]})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto py-2 flex flex-col gap-2 -webkit-overflow-scrolling-touch",children:[tt&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:Te.map(ne=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${ne.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:ne.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:ne.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:ne.secondary})]},ne.key))}),Re.length>5&&e.jsx("div",{className:"flex justify-center px-4 pt-2",children:e.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>M(ne=>!ne),children:b?"Show fewer":`Show ${Re.length-5} more`})})]}),(R||r.length>0||i.length>0)&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Start"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:e.jsxs("div",{className:"flex flex-col gap-2.5 w-full p-3.5 rounded-2xl border border-border-default/80 bg-surface-primary/90",children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:"Workspace"}),e.jsx("div",{className:"text-xs leading-relaxed text-text-secondary",children:"Pick a saved workspace or browse folders before choosing IDE, CLI, or ACP."}),e.jsx("select",{value:_,onChange:ne=>{const we=ne.target.value;if(S(we),we==="__custom__"){oe();return}L("")},className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:$.length>0?e.jsxs(e.Fragment,{children:[$.map(ne=>e.jsxs("option",{value:ne.id,children:[ne.id===P?"⭐ ":"",ne.label||ne.path.split("/").filter(Boolean).pop()||ne.path]},ne.id)),e.jsx("option",{value:"__custom__",children:"Select workspace…"})]}):e.jsx("option",{value:"__custom__",children:"Select workspace…"})}),_==="__custom__"&&e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx("div",{className:"rounded-2xl border border-border-default/80 bg-bg-primary/80 px-3.5 py-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:e.jsx(At,{size:17})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-[0.08em] text-text-muted mb-1",children:"Selected folder"}),e.jsx("div",{className:"text-[12px] leading-relaxed text-text-primary break-all",children:ce||U||"No folder selected yet."})]})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-secondary text-[12px] font-bold",onClick:oe,children:"Select workspace…"}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-xl border border-accent-primary/30 bg-accent-primary/10 text-text-primary text-[12px] font-bold disabled:opacity-40",onClick:()=>{ce&&v(ce)},disabled:!ce||A,children:"Save as workspace"})]})]}),ce&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:ce})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[R&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${H==="ide"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>Y("ide"),children:"IDE"}),r.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${H==="cli"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>Y("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${H==="acp"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>Y("acp"),children:"ACP"})]}),H&&e.jsxs("div",{className:"flex flex-col gap-2.5 px-4 pt-3",children:[e.jsx("div",{className:"text-xs font-bold text-text-secondary",children:H==="ide"?"Choose an IDE":H==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:H==="ide"?(t.detectedIdes||[]).slice(0,6).map(ne=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:we,selectedKey:ye}=xt({machine:{workspaces:$,defaultWorkspaceId:P},currentWorkspaceId:_!=="__custom__"?_:null,currentWorkspacePath:ce});be({title:`Launch ${ne.name}?`,description:"Review or change the target folder before opening this IDE.",confirmLabel:"Launch IDE",workspaceOptions:we,selectedWorkspaceKey:ye,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:ne.name}]},async()=>{const he=we.find(He=>He.key===X.current);he!=null&&he.workspaceId?(S(he.workspaceId),L("")):he!=null&&he.workspacePath?(S("__custom__"),L(he.workspacePath)):(S(""),L("")),j(ne.type,{workspacePath:(he==null?void 0:he.workspacePath)??null})})},children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:ne.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:ce||"Use selected workspace"})]},ne.type)):(H==="cli"?r:i).map(ne=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:we,selectedKey:ye}=xt({machine:{workspaces:$,defaultWorkspaceId:P},currentWorkspaceId:_!=="__custom__"?_:null,currentWorkspacePath:ce});be({title:`Launch ${ne.displayName}?`,description:"Review or change the provider workspace before starting this session.",confirmLabel:`Launch ${H.toUpperCase()}`,workspaceOptions:we,selectedWorkspaceKey:ye,details:[{label:"Mode",value:H.toUpperCase()},{label:"Provider",value:ne.displayName}]},async()=>{const he=we.find(He=>He.key===X.current);he!=null&&he.workspaceId?(S(he.workspaceId),L("")):he!=null&&he.workspacePath?(S("__custom__"),L(he.workspacePath)):(S(""),L("")),w(H,ne.type,{workspaceId:(he==null?void 0:he.workspaceId)??null,workspacePath:(he==null?void 0:he.workspacePath)??null})})},children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[ne.icon?`${ne.icon} `:"",ne.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:ce||"Use selected workspace"})]},ne.type))})]}),d.message&&e.jsxs("div",{className:`mx-4 mt-2.5 p-3 rounded-xl text-xs leading-relaxed ${d.state==="error"?"text-status-error bg-status-error/10":"text-text-secondary bg-surface-primary/90"}`,children:[d.message,I&&e.jsx("div",{className:"mt-2",children:e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[34px] px-4 rounded-lg bg-surface-primary text-text-primary font-bold text-xs",onClick:()=>v(ce,{createIfMissing:!0}),children:"Create folder"})})]})]}),e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Inspect"}),e.jsxs("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:[o&&e.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-accent-primary/25 bg-accent-primary/5 text-text-primary",type:"button",onClick:x,children:[e.jsxs("span",{className:"text-sm font-bold text-text-primary",children:["Update to v",c]}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Restart this machine with the latest daemon"})]}),e.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:g,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:"Machine details"}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Sessions, providers, system info, and logs"})]})]})]})]}),te&&e.jsx(Fs,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:U,directories:D,busy:A,error:xe,confirmLabel:"Use this folder",onClose:()=>ee(!1),onNavigate:ne=>{me(ne)},onConfirm:ne=>{L(ne),S("__custom__"),ee(!1)}}),J&&e.jsx(Vs,{title:J.title,description:J.description,details:J.details,workspaceOptions:J.workspaceOptions,selectedWorkspaceKey:le,onWorkspaceChange:ne=>{X.current=ne,ge(ne)},confirmLabel:J.confirmLabel,busy:pe,onConfirm:je,onCancel:()=>{F.current=null,se(null)}}),f&&e.jsx(Mr,{section:l,onSectionChange:m})]})}function Yo(t){return cr(t)}function Cn(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1],n=Yo(s==null?void 0:s.content);return n||(t.title?t.title:t.displaySecondary||"No messages yet")}function Xo(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Vt(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function Zo({conversations:t,hiddenConversations:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,requestedActiveTabKey:f,onRequestedActiveTabConsumed:u,requestedMachineId:m,onRequestedMachineConsumed:h,requestedMobileSection:p,onRequestedMobileSectionConsumed:g,onOpenAccount:x,onOpenHistory:j,onOpenRemote:v,onStopCli:y,wsStatus:w,isConnected:T,onShowHiddenConversation:b,onShowAllHiddenConversations:M,onHideConversation:N}){const[k,B]=a.useState(()=>{var K;return((K=t[0])==null?void 0:K.tabKey)||null}),[R,$]=a.useState(()=>t[0]?"chat":"inbox"),[P,_]=a.useState("chats"),[S,W]=a.useState(null),[L,U]=a.useState("inbox"),[E,D]=a.useState("idle"),[O,A]=a.useState(""),Q=a.useRef(null),xe=wt(),ue="0.8.3",te=a.useMemo(()=>t.find(K=>K.tabKey===k)||t[0]||null,[t,k]),ee=a.useMemo(()=>te?n.find(K=>K.id===te.ideId):void 0,[n,te]),H=a.useMemo(()=>!te||Me(te)||!Pe(te)?null:vt(te),[te]),Y=a.useMemo(()=>n.filter(K=>K.type==="adhdev-daemon"||K.daemonMode).sort(gi),[n]),F=a.useMemo(()=>Y.find(K=>K.id===S)||null,[Y,S]),J=a.useMemo(()=>Et(n),[n]),se=us({sendDaemonCommand:i,activeConv:te||void 0,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),X=a.useCallback(K=>{if(!K||!K.sessionId)return;const z=bt(K,J),re=Math.max(Date.now(),ds(K),z.lastUpdated||0);Vt("mark_read:start",{tabKey:K.tabKey,sessionId:K.sessionId,displayPrimary:K.displayPrimary,inboxBucket:z.inboxBucket,unread:z.unread,lastSeenAt:z.lastSeenAt,lastUpdated:z.lastUpdated,activityAt:ws(K,z.lastUpdated),readAt:re}),i(K.daemonId||K.ideId,"mark_session_seen",{sessionId:K.sessionId,seenAt:re}).then(C=>{Vt("mark_read:result",{tabKey:K.tabKey,sessionId:K.sessionId,result:C})}).catch(C=>{Vt("mark_read:error",{tabKey:K.tabKey,sessionId:K.sessionId,error:C instanceof Error?C.message:String(C)})})},[J,i]);a.useEffect(()=>{var z;if(!te){$("inbox"),B(((z=t[0])==null?void 0:z.tabKey)||null),Q.current=null;return}if(R!=="chat"){Q.current=null;return}const K=`${te.tabKey}:${te.sessionId||""}`;Q.current!==K&&(Q.current=K,X(te))},[t,X,R,te]),a.useEffect(()=>{if(!f)return;const K=t.find(z=>z.tabKey===f);K&&(B(K.tabKey),$("chat"),u==null||u())},[t,u,f]),a.useEffect(()=>{if(!m)return;const K=Y.find(z=>z.id===m);K&&(W(K.id),D("idle"),A(""),_("machines"),U("inbox"),$("machine"),h==null||h())},[Y,h,m]),a.useEffect(()=>{p&&(_(p),$("inbox"),g==null||g())},[g,p]);const le=a.useMemo(()=>t.map(K=>{const z=R==="chat"&&(te==null?void 0:te.tabKey)===K.tabKey,re=Lt(K,J,{hideOpenTaskCompleteUnread:!0,isOpenConversation:z}),C=bt(K,J),V=ws(K,(C==null?void 0:C.lastUpdated)||0),ie=Cn(K);return{conversation:K,timestamp:V,preview:ie,unread:re.unread,requiresAction:re.requiresAction,isWorking:re.isWorking,inboxBucket:re.inboxBucket}}).sort((K,z)=>{const re=z.timestamp-K.timestamp;return re!==0?re:jr(K.conversation,z.conversation)}),[t,J,R,te]);a.useEffect(()=>{const K=le.filter(z=>z.inboxBucket==="task_complete"||z.unread);K.length!==0&&Vt("inbox_state",{screen:R,selectedTabKey:k,items:K.map(z=>{const re=bt(z.conversation,J);return{liveState:re,tabKey:z.conversation.tabKey,sessionId:z.conversation.sessionId,displayPrimary:z.conversation.displayPrimary,serverBucket:re.inboxBucket,computedBucket:z.inboxBucket,serverUnread:re.unread,computedUnread:z.unread,lastSeenAt:re.lastSeenAt,lastUpdated:re.lastUpdated,activityAt:ws(z.conversation,re.lastUpdated)}})})},[le,J,R,k]);const ge=a.useMemo(()=>le.filter(K=>K.requiresAction),[le]),pe=a.useMemo(()=>le.filter(K=>K.unread&&!K.requiresAction),[le]),ve=a.useMemo(()=>le.filter(K=>!K.unread&&!K.requiresAction&&K.isWorking),[le]),Z=a.useMemo(()=>le.filter(K=>!K.unread&&!K.requiresAction&&!K.isWorking),[le]),ce=a.useMemo(()=>F?le.filter(K=>K.conversation.daemonId===F.id||K.conversation.ideId===F.id):[],[le,F]),I=a.useMemo(()=>{if(!F)return[];const K=F.recentLaunches||[];return K.length>0?K.map(z=>({id:z.id,label:z.title||z.providerName||z.providerType,kind:z.kind,providerType:z.providerType,providerSessionId:z.providerSessionId,subtitle:z.currentModel||z.workspace||void 0,workspace:z.workspace,currentModel:z.currentModel})):n.filter(z=>!z.daemonMode&&z.daemonId===F.id).map(z=>{var C,V,ie,q,de;const re=es(z)?"cli":Ct(z)?"acp":"ide";return{id:`${re}:${z.type}:${z.workspace||""}`,label:((C=z.activeChat)==null?void 0:C.title)||(es(z)?z.cliName||z.type:Ct(z)&&z.cliName||z.type),kind:re,providerType:z.type,providerSessionId:z.providerSessionId,subtitle:Ct(z)?z.currentModel||z.workspace||void 0:z.workspace||void 0,workspace:z.workspace||void 0,currentModel:z.currentModel,timestamp:((de=(q=(ie=(V=z.activeChat)==null?void 0:V.messages)==null?void 0:ie.at)==null?void 0:q.call(ie,-1))==null?void 0:de.timestamp)||0}}).sort((z,re)=>re.timestamp-z.timestamp).map(({timestamp:z,...re})=>re)},[n,F]),ae=(F==null?void 0:F.version)||(F==null?void 0:F.daemonVersion)||null,me=!!F&&!!ae&&!0&&ae!==ue,oe=a.useMemo(()=>(F==null?void 0:F.availableProviders)||[],[F]),be=a.useMemo(()=>oe.filter(K=>K.category==="cli").map(K=>({type:K.type,displayName:K.displayName||K.type,icon:K.icon})),[oe]),je=a.useMemo(()=>oe.filter(K=>K.category==="acp").map(K=>({type:K.type,displayName:K.displayName||K.type,icon:K.icon})),[oe]),Re=a.useMemo(()=>{const K=new Map;for(const z of le){const re=z.conversation.daemonId||z.conversation.ideId,C=K.get(re);C?C.push(z):K.set(re,[z])}return Y.map(z=>{const re=K.get(z.id)||[],C=[...re].sort((G,Se)=>Se.timestamp-G.timestamp)[0]||null,V=(C==null?void 0:C.conversation)||null,ie=re.filter(G=>G.unread||G.requiresAction).length,q=z.status==="online"?"Connected":z.status||"Unknown",de=[z.platform||"machine",q].filter(Boolean);return{id:z.id,label:et(z,{fallbackId:z.id}),subtitle:de.join(" · "),unread:ie,total:re.length,latestConversation:V,latestTimestamp:(C==null?void 0:C.timestamp)||0,preview:V?`${V.displayPrimary} · ${Cn(V)}`:"No active conversations yet. Open the machine to launch an IDE, CLI, or ACP session."}}).sort((z,re)=>{const C=Math.max(z.latestTimestamp,ts(Y.find(ie=>ie.id===z.id))),V=Math.max(re.latestTimestamp,ts(Y.find(ie=>ie.id===re.id)));return V!==C?V-C:z.label.localeCompare(re.label)})},[le,Y]),Te=a.useCallback(K=>{B(K.tabKey),$("chat"),X(K)},[X]),tt=a.useCallback(K=>{const z=t.find(re=>re.ideId===K.ideId&&re.streamSource==="native");z&&(B(z.tabKey),$("chat"),X(z))},[t,X]),Oe=a.useCallback(()=>{X(te),$("inbox")},[X,te]),Le=a.useCallback(K=>{W(K),D("idle"),A(""),_("machines"),U("inbox"),$("machine")},[]),Ee=a.useCallback(K=>{var re;const z=K.daemonId||((re=K.ideId)==null?void 0:re.split(":")[0])||K.ideId;z&&(W(z),D("idle"),A(""),_("machines"),U("chat"),$("machine"))},[]),Ve=a.useCallback(()=>{$(L)},[L]),ne=a.useCallback(async(K,z,re)=>{var C;try{D("loading"),A(`Launching ${z}…`);const V={ideType:z,enableCdp:!0};(C=re==null?void 0:re.workspacePath)!=null&&C.trim()&&(V.workspace=re.workspacePath.trim()),await i(K,"launch_ide",V),D("done"),A(`${z} launch requested`)}catch(V){D("error"),A(V instanceof Error?V.message:"Launch IDE failed"),console.error("Launch IDE failed",V)}},[i]),we=a.useCallback(async(K,z,re)=>{if(z.trim())try{D("loading"),A(re!=null&&re.createIfMissing?"Creating folder…":"Saving workspace…");const C=await i(K,"workspace_add",{path:z.trim(),createIfMissing:(re==null?void 0:re.createIfMissing)===!0});if(C!=null&&C.success){D("done"),A(re!=null&&re.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}D("error"),A((C==null?void 0:C.error)||"Could not save workspace")}catch(C){D("error"),A(C instanceof Error?C.message:"Could not save workspace")}},[i]),ye=a.useCallback(async K=>{var z,re,C,V,ie,q;try{D("loading"),A("Starting daemon upgrade…");const de=await i(K,"daemon_upgrade",{});if((z=de==null?void 0:de.result)!=null&&z.alreadyLatest){D("done"),A(`Already on v${((re=de==null?void 0:de.result)==null?void 0:re.version)||"latest"}.`);return}if((C=de==null?void 0:de.result)!=null&&C.upgraded||(V=de==null?void 0:de.result)!=null&&V.success){D("done"),A(`Upgrade to v${((ie=de==null?void 0:de.result)==null?void 0:ie.version)||"latest"} started. Daemon is restarting…`);return}D("error"),A(((q=de==null?void 0:de.result)==null?void 0:q.error)||"Upgrade failed")}catch(de){D("error"),A(de instanceof Error?de.message:"Upgrade failed")}},[i]),he=a.useCallback(async(K,z,re,C)=>{var V;try{D("loading"),A(`Launching ${re}…`);const ie={cliType:re};(V=C==null?void 0:C.workspacePath)!=null&&V.trim()?ie.dir=C.workspacePath.trim():C!=null&&C.workspaceId&&(ie.workspaceId=C.workspaceId),C!=null&&C.resumeSessionId&&(ie.resumeSessionId=C.resumeSessionId);const q=await i(K,"launch_cli",ie),de=(q==null?void 0:q.result)||q,G=(de==null?void 0:de.sessionId)||(de==null?void 0:de.id);if(q!=null&&q.success&&G){D("done"),A(`${re} launched`),xe(`/dashboard?activeTab=${encodeURIComponent(G)}`);return}D("error"),A((q==null?void 0:q.error)||(de==null?void 0:de.error)||`Could not launch ${z.toUpperCase()} workspace`)}catch(ie){D("error"),A(ie instanceof Error?ie.message:`Could not launch ${z.toUpperCase()} workspace`)}},[xe,i]),He=a.useCallback(async K=>{if(F){if(K.kind==="ide"&&K.providerType){await ne(F.id,K.providerType,{workspacePath:K.workspace||null});return}if((K.kind==="cli"||K.kind==="acp")&&K.providerType){await he(F.id,K.kind,K.providerType,{workspacePath:K.workspace||null,resumeSessionId:K.providerSessionId||null});return}}},[ne,he,F]);return e.jsx("div",{className:"dashboard-mobile-chat",children:R==="chat"&&te?e.jsx(Ho,{selectedConversation:te,isAcp:Me(te),selectedIdeEntry:ee,actionLogs:r,userName:l,isSendingChat:se.isSendingChat,isFocusingAgent:se.isFocusingAgent,handleModalButton:se.handleModalButton,handleRelaunch:se.handleRelaunch,onBack:Oe,onOpenNativeConversation:tt,onOpenMachine:Ee,onHideConversation:N,onOpenHistory:j,onOpenRemote:v,onStopCli:y,cliViewMode:H,onSetCliViewMode:async K=>{if(te&&H!==K)try{await i(te.daemonId||te.ideId,"set_cli_view_mode",{targetSessionId:te.sessionId,cliType:te.ideType||te.agentType,mode:K})}catch(z){console.error("Failed to switch CLI view mode:",z)}},handleSendChat:se.handleSendChat,handleFocusAgent:se.handleFocusAgent}):R==="machine"&&F?e.jsx(Go,{selectedMachineEntry:F,selectedMachineConversations:ce,selectedMachineRecentLaunches:I,cliProviders:be,acpProviders:je,selectedMachineNeedsUpgrade:me,appVersion:ue,machineAction:{state:E,message:O},section:P,showBottomNav:L==="inbox",onBack:Ve,onSectionChange:K=>{_(K),$("inbox")},onOpenConversation:Te,onOpenRecent:He,onOpenMachineDetails:()=>xe(`/machines/${F.id}`),onMachineUpgrade:()=>ye(F.id),onLaunchDetectedIde:(K,z)=>ne(F.id,K,z),onAddWorkspace:(K,z)=>we(F.id,K,z),onBrowseDirectory:async K=>{const z=await i(F.id,"file_list_browse",{path:K});if(!(z!=null&&z.success))throw new Error((z==null?void 0:z.error)||"Could not browse folder");const re=typeof(z==null?void 0:z.path)=="string"?z.path:K,C=re.includes("\\")?"\\":"/",V=(q,de)=>/^[A-Za-z]:\\?$/.test(q)?`${q.replace(/\\?$/,"\\")}${de}`:q==="/"||q==="\\"?`${C}${de}`:`${q.replace(/[\\/]+$/,"")}${C}${de}`,ie=Array.isArray(z==null?void 0:z.files)?z.files.filter(q=>(q==null?void 0:q.type)==="directory"&&typeof(q==null?void 0:q.name)=="string").map(q=>({name:q.name,path:V(re,q.name)})).sort((q,de)=>q.name.localeCompare(de.name)):[];return{path:re,directories:ie}},onLaunchWorkspaceProvider:(K,z,re)=>he(F.id,K,z,re)}):e.jsx(Vo,{section:P,attentionItems:ge,unreadItems:pe,workingItems:ve,completedItems:Z,hiddenConversations:s,machineCards:Re,getAvatarText:Xo,onOpenConversation:Te,onShowConversation:b,onShowAllHidden:M,onOpenMachine:Le,onOpenSettings:()=>xe("/settings"),onOpenAccount:x,onSectionChange:_,wsStatus:w,isConnected:T,isStandalone:d})})}function ks(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Jo({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[d,l]=a.useState(!1),[f,u]=a.useState(null),m=a.useCallback(()=>{c.current=0,l(!1),u(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",m),window.addEventListener("drop",m),()=>{window.removeEventListener("dragend",m),window.removeEventListener("drop",m)}),[m]);const h=a.useCallback(j=>{j.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,l(!0))},[]),p=a.useCallback(j=>{if(!j.dataTransfer.types.includes("text/tab-key"))return;if(j.preventDefault(),!ks(s,n)){u("merge");return}const v=j.currentTarget.getBoundingClientRect(),y=j.clientX-v.left,w=v.width/3;y<w?u("split-left"):y>w*2?u("split-right"):u("merge")},[s,n]),g=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,l(!1),u(null))},[]),x=a.useCallback(j=>{c.current=0,l(!1);const v=j.dataTransfer.getData("text/tab-key"),y=v?t.some(T=>T.tabKey===v):!1,w=f;if(u(null),o(),!!v){if(j.preventDefault(),w==="split-left"&&ks(s,n)){n==null||n(v,"split-left");return}if(w==="split-right"&&ks(s,n)){n==null||n(v,"split-right");return}if(y){i(v);return}r==null||r(v)}},[t,f,s,n,r,i,o]);return{dragOver:d,dropAction:f,resetDragState:m,handleDragEnter:h,handleDragOver:p,handleDragLeave:g,handleDrop:x}}function Qo(t,s){const n=new Set(s.map(o=>o.tabKey)),r=t.filter(o=>n.has(o)),i=s.filter(o=>!t.includes(o.tabKey)).map(o=>o.tabKey);return[...r,...i]}function ec({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[d,l]=a.useState(n??[]),[f,u]=a.useState(null),m=a.useRef(null),h=a.useRef(null),p=a.useRef(r),g=a.useRef(i);a.useEffect(()=>{p.current=r},[r]),a.useEffect(()=>{g.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{l(N=>{const k=Qo(N,t);return k.length===N.length&&k.every((B,R)=>B===N[R])?N:k})},[t]);const x=a.useMemo(()=>{const N=f??d;if(N.length===0)return t;const k=new Map(N.map((B,R)=>[B,R]));return[...t].sort((B,R)=>{const $=k.get(B.tabKey)??999,P=k.get(R.tabKey)??999;return $-P})},[t,f,d]);a.useEffect(()=>{var k,B;if(x.length===0){o!==null&&(c(null),(k=p.current)==null||k.call(p,null));return}if(o&&x.some(R=>R.tabKey===o))return;const N=x[0].tabKey;N!==o&&(c(N),(B=p.current)==null||B.call(p,N))},[x,o]);const j=a.useMemo(()=>x.find(N=>N.tabKey===o),[x,o]),v=a.useCallback(N=>{var k;c(N),(k=p.current)==null||k.call(p,N)},[]),y=a.useCallback((N,k,B)=>{l(R=>{var S;const $=R.filter(W=>W!==N),P=$.indexOf(k);if(P<0)return R;const _=B==="left"?P:P+1;return $.splice(_,0,N),(S=g.current)==null||S.call(g,$),$}),u(null)},[]),w=a.useCallback((N,k,B)=>{const $=(d.length>0?d:t.map(S=>S.tabKey)).filter(S=>S!==N),P=$.indexOf(k);if(P<0)return;const _=B==="left"?P:P+1;$.splice(_,0,N),m.current=$,u($)},[d,t]),T=a.useCallback(()=>{var k;const N=m.current;N&&(l(N),(k=g.current)==null||k.call(g,N))},[]),b=a.useCallback(()=>{m.current=null,u(null)},[]),M=a.useCallback(N=>{l(k=>{var R;const B=k.filter($=>$!==N);return B.push(N),(R=g.current)==null||R.call(g,B),B})},[]);return{activeTabId:o,activeConv:j,sortedConversations:x,previewOrderRef:m,draggingTabRef:h,selectTab:v,handleTabReorder:y,updatePreviewOrder:w,commitPreviewOrder:T,clearPreviewOrder:b,moveTabToEnd:M,setDraggingTabKey:N=>{h.current=N}}}function tc({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"})})]})}function qs({conversationsCount:t,isSplitMode:s,isStandalone:n,detectedIdes:r,handleLaunchIde:i}){return t===0&&!s&&r&&i?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(Ir,{}),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(o=>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:()=>i(o.type),children:[e.jsx(Yn,{size:14,className:"opacity-70"})," Launch ",o.name]},o.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 _r="adhdev-tab-shortcuts";function sc(){try{return JSON.parse(localStorage.getItem(_r)||"{}")}catch{return{}}}function nc({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,o]=a.useState(()=>sc()),[c,d]=a.useState(null),l=a.useCallback(u=>{const m=[];return u.metaKey&&m.push(r?"⌘":"Meta"),u.ctrlKey&&m.push("Ctrl"),u.altKey&&m.push(r?"⌥":"Alt"),u.shiftKey&&m.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(u.key)?null:(m.push(u.key.length===1?u.key.toUpperCase():u.key),m.join("+"))},[r]),f=a.useCallback(u=>{o(u);try{localStorage.setItem(_r,JSON.stringify(u))}catch{}},[]);return a.useEffect(()=>{if(!c)return;const u=m=>{if(m.preventDefault(),m.stopPropagation(),m.key==="Escape"){d(null);return}const h=l(m);if(!h)return;const p={...i};for(const[g,x]of Object.entries(p))x===h&&delete p[g];p[c]=h,f(p),d(null)};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[c,i,f,l]),a.useEffect(()=>{const u=m=>{if(!(!m.ctrlKey&&!m.metaKey&&!m.altKey)){for(const[h,p]of Object.entries(i))if(t.includes(h)&&l(m)===p){m.preventDefault(),s(),n(h);return}}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[i,t,s,n,l]),{isMac:r,tabShortcuts:i,shortcutListening:c,setShortcutListening:d,saveShortcuts:f}}const rc=a.memo(function({conv:s,isActive:n,isDraggedTab:r,isTaskCompleteUnread:i,shortcut:o,conversationKeys:c,draggingTabRef:d,onFocus:l,onSelectTab:f,onConversationActivated:u,onPreviewReorder:m,onReorderTab:h,onCommitPreviewOrder:p,onClearPreviewOrder:g,onDragStateReset:x,onDragTabKeyChange:j,onReceiveTab:v,onOpenContextMenu:y,longPressTimer:w,isGroupActive:T}){const b=ls(s),M=b.isGenerating?"agent-tab-generating":b.isWaiting?"agent-tab-waiting":"",N=b.isReconnecting,k=a.useCallback(U=>{d.current=s.tabKey,j(s.tabKey),U.dataTransfer.setData("text/tab-key",s.tabKey),U.dataTransfer.effectAllowed="move"},[s.tabKey,d,j]),B=a.useCallback(()=>{d.current=null,j(null),p(),g(),x()},[d,j,p,g,x]),R=a.useCallback(U=>{const E=d.current;if(!(!E||E===s.tabKey)&&U.dataTransfer.types.includes("text/tab-key")){U.preventDefault(),U.stopPropagation();const D=U.currentTarget.getBoundingClientRect(),O=U.clientX<D.left+D.width/2?"left":"right";m(E,s.tabKey,O)}},[s.tabKey,d,m]),$=a.useCallback(U=>{U.preventDefault(),U.stopPropagation();const E=U.dataTransfer.getData("text/tab-key");if(E&&E!==s.tabKey){const D=U.currentTarget.getBoundingClientRect(),O=U.clientX<D.left+D.width/2?"left":"right";c.includes(E)?h(E,s.tabKey,O):v&&v(E)}g()},[s.tabKey,c,h,v,g]),P=a.useCallback(U=>{U.stopPropagation(),l(),f(s.tabKey),u(s)},[s,u,l,f]),_=a.useCallback(U=>{U.preventDefault(),y(U.clientX,U.clientY,s.tabKey)},[s.tabKey,y]),S=a.useCallback(U=>{const E=U.touches[0];w.current=setTimeout(()=>{y(E.clientX,E.clientY,s.tabKey)},600)},[s.tabKey,w,y]),W=a.useCallback(()=>{w.current&&clearTimeout(w.current)},[w]),L=["adhdev-dockview-tab",M,n&&"is-active",T&&"is-group-active",N&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:L,draggable:!0,onDragStart:k,onDragEnd:B,onDragOver:R,onDrop:$,onClick:P,onContextMenu:_,onTouchStart:S,onTouchEnd:W,onTouchMove:W,style:{cursor:"pointer",opacity:r?.4:void 0},children:[i&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status",children:b.isGenerating?e.jsx("div",{className:"tab-spinner"}):b.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):N?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):b.isConnecting?e.jsx("div",{className:"tab-connecting-spinner"}):s.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("span",{className:"adhdev-dockview-tab-primary",title:s.displayPrimary,children:s.displayPrimary}),e.jsx("span",{className:"adhdev-dockview-tab-meta",children:N?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):b.isConnecting?e.jsxs("span",{className:"adhdev-dockview-tab-connecting",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:"adhdev-dockview-tab-dot",children:"·"}),e.jsxs("span",{className:"adhdev-dockview-tab-machine",children:["🖥 ",s.machineName]})]})]})})]}),o&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${o}`,children:o})]})},(t,s)=>t.conv===s.conv&&t.isActive===s.isActive&&t.isDraggedTab===s.isDraggedTab&&t.isTaskCompleteUnread===s.isTaskCompleteUnread&&t.shortcut===s.shortcut&&t.conversationKeys===s.conversationKeys&&t.isGroupActive===s.isGroupActive);function ac({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,unreadTabKeys:i,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:u,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:p,onDragTabKeyChange:g,onMoveTab:x,onReceiveTab:j,onHideTab:v,isGroupActive:y}){const[w,T]=a.useState(null),b=a.useRef(null),M=a.useRef(null),N=a.useMemo(()=>t.map(S=>S.tabKey),[t]);Pt("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(w==null?void 0:w.tabKey)||null});const{isMac:k,tabShortcuts:B,shortcutListening:R,setShortcutListening:$,saveShortcuts:P}=nc({sortedTabKeys:t.map(S=>S.tabKey),onFocus:c,onSelectTab:d});a.useEffect(()=>{if(!w)return;const S=W=>{const L=document.querySelector("[data-pane-context-menu]");L&&L.contains(W.target)||T(null)};return window.addEventListener("mousedown",S,!0),()=>window.removeEventListener("mousedown",S,!0)},[w]),a.useEffect(()=>{const S=M.current;if(!S)return;const W=L=>{Math.abs(L.deltaY)>Math.abs(L.deltaX)&&(L.preventDefault(),S.scrollLeft+=L.deltaY)};return S.addEventListener("wheel",W,{passive:!1}),()=>S.removeEventListener("wheel",W)},[]);const _=a.useCallback((S,W,L)=>{T({x:S,y:W,tabKey:L})},[]);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-end shrink-0 gap-0",style:{background:"var(--surface-secondary)",paddingInline:8,paddingTop:6,paddingBottom:0},children:e.jsxs("div",{ref:M,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(S=>e.jsx(rc,{conv:S,isActive:s===S.tabKey,isDraggedTab:o.current===S.tabKey,isTaskCompleteUnread:i.has(S.tabKey),shortcut:B[S.tabKey],conversationKeys:N,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:u,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:p,onDragTabKeyChange:g,onReceiveTab:j,onOpenContextMenu:_,longPressTimer:b,isGroupActive:y},S.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),w&&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:w.x,top:w.y},children:[x&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{x(w.tabKey,"left"),T(null)},children:"← Move to Left Group"}),x&&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:()=>{x(w.tabKey,"right"),T(null)},children:"Move to Right Group →"}),x&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{x(w.tabKey,"split-left"),T(null)},children:"⇤ Split Left"}),x&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{x(w.tabKey,"split-right"),T(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:S=>{S.stopPropagation(),$(w.tabKey),T(null)},children:["⌨ ",B[w.tabKey]?`Change shortcut (${B[w.tabKey]})`:"Set shortcut"]}),B[w.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 S={...B};delete S[w.tabKey],P(S),T(null)},children:"✕ Remove shortcut"}),v&&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:()=>{v(w.tabKey),T(null)},children:"🚫 Hide from Dashboard"})]}),!x&&!v&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),R&&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:S=>S.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 ic({conversations:t,ides:s,clearedTabs:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,groupIndex:f,onFocus:u,isSplitMode:m,numGroups:h,onMoveTab:p,onReceiveTab:g,style:x,detectedIdes:j,handleLaunchIde:v,onActiveTabChange:y,initialActiveTabId:w,initialTabOrder:T,onTabOrderChange:b,onHideTab:M,isFocused:N}){const{sendCommand:k}=ct(),B=a.useRef(null),{activeTabId:R,activeConv:$,sortedConversations:P,draggingTabRef:_,selectTab:S,handleTabReorder:W,updatePreviewOrder:L,commitPreviewOrder:U,clearPreviewOrder:E,moveTabToEnd:D,setDraggingTabKey:O}=ec({conversations:t,initialActiveTabId:w,initialTabOrder:T,onActiveTabChange:y,onTabOrderChange:b}),A=us({sendDaemonCommand:i,activeConv:$,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),{dragOver:Q,dropAction:xe,resetDragState:ue,handleDragEnter:te,handleDragOver:ee,handleDragLeave:H,handleDrop:Y}=Jo({conversations:t,numGroups:h,onMoveTab:p,onReceiveTab:g,onOwnTabDrop:D,onClearPreviewOrder:E}),F=$&&!Me($)&&vt($)==="terminal",J=a.useMemo(()=>$?s.find(pe=>pe.id===$.ideId):void 0,[s,$]),se=a.useMemo(()=>$?r.filter(pe=>pe.ideId===$.tabKey):[],[r,$]),X=a.useMemo(()=>Et(s),[s]),le=a.useMemo(()=>new Set(P.filter(pe=>ei(pe,X,{isOpenConversation:pe.tabKey===R})).map(pe=>pe.tabKey)),[R,X,P]);Pt("PaneGroup",{groupIndex:f,conversationCount:t.length,activeTabId:R,dragOver:Q});const ge=a.useCallback(pe=>{pe.streamSource==="agent-stream"&&pe.agentType&&k(pe.ideId,"focus_session",{agentType:pe.agentType,...pe.sessionId&&{targetSessionId:pe.sessionId}}).catch(()=>{})},[k]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:u,style:{...x,outline:Q?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(ac,{conversations:P,activeTabId:R,groupIndex:f,numGroups:h,unreadTabKeys:le,draggingTabRef:_,onFocus:u,onSelectTab:S,onConversationActivated:ge,onPreviewReorder:L,onReorderTab:W,onCommitPreviewOrder:U,onClearPreviewOrder:E,onDragStateReset:ue,onDragTabKeyChange:O,onMoveTab:p,onReceiveTab:g,onHideTab:M,isGroupActive:N??!1}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:te,onDragOver:ee,onDragLeave:H,onDrop:Y,children:[Q&&e.jsx(tc,{dropAction:xe,canSplit:!!(h<4&&p)}),$?e.jsx(Hs,{activeConv:$,clearToken:n[$.tabKey]||0,isCliTerminal:!!F,ideEntry:J,terminalRef:B,handleModalButton:A.handleModalButton,handleRelaunch:A.handleRelaunch,handleSendChat:A.handleSendChat,isSendingChat:A.isSendingChat,handleFocusAgent:A.handleFocusAgent,isFocusingAgent:A.isFocusingAgent,actionLogs:se,userName:l}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(qs,{conversationsCount:t.length,isSplitMode:m,isStandalone:d,detectedIdes:j,handleLaunchIde:v})})]})]})}function oc({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:u,isStandalone:m,userName:h,focusedGroup:p,setFocusedGroup:g,moveTabToGroup:x,splitTabRelative:j,closeGroup:v,handleResizeStart:y,detectedIdes:w,handleLaunchIde:T,groupActiveTabIds:b,setGroupActiveTabIds:M,groupTabOrders:N,setGroupTabOrders:k,toggleHiddenTab:B}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:i.map((R,$)=>{const P=s&&r.length===n?`${r[$]}%`:void 0;return e.jsxs(Ls.Fragment,{children:[s&&$>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:_=>y($-1,_),onDoubleClick:()=>v($),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(ic,{style:s?{flexBasis:P??`${100/n}%`,flexGrow:P?0:1,flexShrink:P?0:1}:void 0,conversations:R,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:u,isStandalone:m,userName:h,groupIndex:$,isFocused:s&&p===$,onFocus:()=>g($),isSplitMode:s,numGroups:n,onMoveTab:(_,S)=>{S==="left"&&$>0?x(_,$-1):S==="right"&&$<n-1?x(_,$+1):S==="split-left"&&n<4?j(_,$,"left"):S==="split-right"&&n<4&&j(_,$,"right")},onReceiveTab:_=>x(_,$),detectedIdes:$===0?w:void 0,handleLaunchIde:$===0?T:void 0,onActiveTabChange:_=>M(S=>(S[$]??null)===(_??null)?S:{...S,[$]:_}),initialActiveTabId:b[$],initialTabOrder:N[$],onTabOrderChange:_=>k(S=>{const W=S[$]||[];return W.length===_.length&&W.every((L,U)=>L===_[U])?S:{...S,[$]:_}}),onHideTab:B})]},$)})})}function Rr({doId:t,ideId:s,ideType:n,connState:r,viewMode:i,instanceId:o}){const[c,d]=a.useState(null),[l,f]=a.useState(null),u=a.useMemo(()=>{if(!s)return n;const h=s.split(":");return h.length>=3&&h[1]==="ide"?h.slice(2).join(":"):n},[s,n]);a.useEffect(()=>t?_e.onScreenshot("ide-page",(p,g)=>{if(p!==t)return;const x=new FileReader;x.onload=()=>d(x.result),x.readAsDataURL(g)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&d(null)},[r]),a.useEffect(()=>{var p;return t?((p=_e.onStatus)==null?void 0:p.call(_e,(g,x)=>{g===t&&x!=null&&x.screenshotUsage&&f(x.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{d(null)},[t,s,u]),a.useEffect(()=>{const h=t?_e.get(t):null;if(!(!h||r!=="connected"))return i!=="chat"&&u?h.startScreenshots(u):h.stopScreenshots(u),()=>{h.stopScreenshots(u)}},[i,r,u,t]);const m=a.useCallback(async(h,p)=>{const g=t?_e.get(t):null;return!g||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):g.sendInput(h,p,o||u)},[t,r,o,u]);return{connScreenshot:c,screenshotUsage:l,handleRemoteAction:m}}const Ar=a.createContext(null);function ps(){const t=a.useContext(Ar);if(!t)throw new Error("DashboardDockviewContext missing");return t}function Xt(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function cc(t){return`remote:${t}`}function as(t){return t.startsWith("remote:")}function xs(t,s){return t.find(n=>n.ideId===s&&n.streamSource==="native")??t.find(n=>n.ideId===s)??null}function lc(t){const[,s]=a.useState(0);a.useEffect(()=>{const n=()=>s(i=>i+1),r=[t.api.onDidActiveGroupChange(n),t.api.onDidTitleChange(n),t.api.onDidGroupChange(n),t.containerApi.onDidActivePanelChange(n)];return()=>{for(const i of r)i.dispose()}},[t.api,t.containerApi])}function dc(t,s,n){var d;const r=[s];let i;for(const l of r){let f;for(const u of l){const m=t.addPanel({id:u.tabKey,component:"conversation",title:Xt(u),params:{kind:"conversation",tabKey:u.tabKey},...f?{position:{referencePanel:f,direction:"within"},inactive:!0}:i?{position:{referencePanel:i,direction:"right"},inactive:!0}:{}});f||(f=m.id)}i=f??i}const o=n??((d=s[0])==null?void 0:d.tabKey)??null;if(!o)return;const c=t.getPanel(o);c&&c.group.model.openPanel(c)}function In(t,s){const n=new Set(s.map(r=>r.tabKey));for(const r of[...t.panels])as(r.id)||n.has(r.id)||t.removePanel(r);for(const r of s){const i=t.getPanel(r.tabKey);if(i){i.update({params:{tabKey:r.tabKey}}),i.title!==Xt(r)&&i.api.setTitle(Xt(r));continue}t.addPanel({id:r.tabKey,component:"conversation",title:Xt(r),params:{kind:"conversation",tabKey:r.tabKey},...t.activePanel?{position:{referencePanel:t.activePanel.id,direction:"within"},inactive:!0}:t.panels[0]?{position:{referencePanel:t.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Mn(t,s,n){var l,f;const r=n?cc(n):null;for(const u of[...t.panels])as(u.id)&&(!r||u.id!==r)&&t.removePanel(u);if(!n||!r)return;const i=xs(s,n);if(!i&&t.totalPanels===0)return;const o=t.getPanel(r),c=i?`Remote · ${i.displayPrimary||i.workspaceName||i.agentName}`:"Remote";if(o){o.title!==c&&o.api.setTitle(c);return}const d=(i==null?void 0:i.tabKey)??((l=t.activePanel)==null?void 0:l.id)??((f=t.panels.find(u=>!as(u.id)))==null?void 0:f.id);t.addPanel({id:r,component:"remote",title:c,params:{kind:"remote",ideId:n},...d?{position:{referencePanel:d,direction:"right"},inactive:!0}:{}})}function uc({params:t}){const s=ps(),n=a.useRef(null),r=s.conversationsByTabKey.get(t.tabKey),i=us({sendDaemonCommand:s.sendDaemonCommand,activeConv:r,setLocalUserMessages:s.setLocalUserMessages,setActionLogs:s.setActionLogs,isStandalone:s.isStandalone}),o=a.useMemo(()=>r?s.ides.find(l=>l.id===r.ideId):void 0,[s.ides,r]),c=a.useMemo(()=>r?s.actionLogs.filter(l=>l.ideId===r.tabKey):[],[s.actionLogs,r]);if(!r)return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:e.jsx(qs,{conversationsCount:0,isSplitMode:!1,isStandalone:s.isStandalone,detectedIdes:s.detectedIdes,handleLaunchIde:s.handleLaunchIde})});const d=!Me(r)&&vt(r)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(Hs,{activeConv:r,clearToken:s.clearedTabs[r.tabKey]||0,isCliTerminal:d,ideEntry:o,terminalRef:n,handleModalButton:i.handleModalButton,handleRelaunch:i.handleRelaunch,handleSendChat:i.handleSendChat,isSendingChat:i.isSendingChat,handleFocusAgent:i.handleFocusAgent,isFocusingAgent:i.isFocusingAgent,actionLogs:c,userName:s.userName})})}function pc({params:t}){var l;const s=ps(),n=a.useMemo(()=>xs([...s.conversationsByTabKey.values()],t.ideId),[s.conversationsByTabKey,t.ideId]),r=a.useMemo(()=>s.ides.find(f=>f.id===t.ideId),[s.ides,t.ideId]),i=(n==null?void 0:n.daemonId)||((l=n==null?void 0:n.ideId)==null?void 0:l.split(":")[0])||t.ideId.split(":")[0]||t.ideId,{connScreenshot:o,screenshotUsage:c,handleRemoteAction:d}=Rr({doId:i,ideId:t.ideId,ideType:(n==null?void 0:n.ideType)||(r==null?void 0:r.type),connState:(n==null?void 0:n.connectionState)||"new",viewMode:"remote",instanceId:r==null?void 0:r.instanceId});return n?e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:e.jsx(Zn,{addLog:()=>{},connState:n.connectionState||"new",connScreenshot:o,screenshotUsage:c,transportType:n.transport,onAction:d})}):e.jsx("div",{className:"h-full min-h-0 min-w-0 flex items-center justify-center text-sm text-text-muted",children:"Remote view unavailable"})}function xc(){const t=ps();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(qs,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function mc(t){var m,h;lc(t);const s=ps();if(t.params.kind==="remote"){const p=xs([...s.conversationsByTabKey.values()],t.params.ideId),g=((m=t.api.group.activePanel)==null?void 0:m.id)===t.api.id,x=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${g?" is-active":""}${x?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(p==null?void 0:p.tabKey)||"",children:[e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||"Remote"}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:p!=null&&p.machineName?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Live remote view"}),e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsx("span",{className:"adhdev-dockview-tab-machine",children:p.machineName})]}):e.jsx("span",{children:"Live remote view"})})]})]})}const n=s.conversationsByTabKey.get(t.params.tabKey);if(!n)return e.jsx("div",{className:"adhdev-dockview-tab adhdev-dockview-tab-empty","data-tab-key":t.params.tabKey||"",children:e.jsx("div",{className:"adhdev-dockview-tab-copy",children:e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||t.params.tabKey})})});const r=((h=t.api.group.activePanel)==null?void 0:h.id)===t.api.id,i=t.api.isGroupActive,o=Lt(n,s.liveSessionInboxState,{isOpenConversation:r}),c=o.isReconnecting,d=o.isConnecting,l=o.isGenerating,f=o.isWaiting,u=o.unread;return e.jsxs("div",{className:`adhdev-dockview-tab${r?" is-active":""}${i?" is-group-active":""}${c?" is-reconnecting":""}`,title:n.displayPrimary,"data-tab-key":t.params.tabKey,children:[u&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:l?e.jsx("div",{className:"tab-spinner"}):f?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):c?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):d?e.jsx("div",{className:"tab-connecting-spinner"}):n.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:n.displayPrimary}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:c?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):d?e.jsx("span",{className:"adhdev-dockview-tab-connecting",children:"Connecting…"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:n.displaySecondary}),n.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsxs("span",{className:"adhdev-dockview-tab-machine",children:["🖥 ",n.machineName]})]})]})})]})]})}function fc({visibleConversations:t,clearedTabs:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,detectedIdes:f,handleLaunchIde:u,toggleHiddenTab:m,onActiveTabChange:h,requestedActiveTabKey:p,requestedRemoteIdeId:g,onRequestedActiveTabConsumed:x}){const{theme:j}=hr(),{sendCommand:v}=ct(),y=a.useRef(null),w=a.useRef(null),T=a.useRef(!1),[b,M]=a.useState(!1),[N,k]=a.useState(!1),B=a.useRef(null),R=a.useMemo(()=>Nr(typeof window<"u"?window.innerWidth:1280),[]),$=a.useMemo(()=>new Map(t.map(A=>[A.tabKey,A])),[t]),P=a.useMemo(()=>Et(n),[n]),_=a.useMemo(()=>({actionLogs:r,clearedTabs:s,conversationsByTabKey:$,detectedIdes:f,handleLaunchIde:u,ides:n,isStandalone:d,liveSessionInboxState:P,sendDaemonCommand:i,setActionLogs:c,setLocalUserMessages:o,toggleHiddenTab:m,userName:l}),[r,s,$,f,u,n,d,P,i,c,o,m,l]),S=a.useCallback(A=>{if(!A)return!1;const Q=y.current;if(!Q)return!1;const xe=Q.getPanel(A);return xe?(xe.group.model.openPanel(xe),x==null||x(),!0):!1},[x]),W=a.useCallback(()=>{const A=w.current;if(!A)return;const Q=A.querySelectorAll(".dv-drop-target-container, .dv-drop-target-anchor, .dv-drop-target-dropzone, .dv-drop-target-selection, .dv-render-overlay");for(const xe of Q)xe.setAttribute("data-adhdev-force-hidden","true")},[]),L=a.useCallback(()=>{const A=w.current;if(!A)return;const Q=A.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const xe of Q)xe.removeAttribute("data-adhdev-force-hidden")},[]),U=a.useCallback(()=>{const A=w.current;if(!A)return;const Q=A.querySelectorAll(".dv-drop-target-container");for(const te of Q)te.remove();const xe=A.querySelectorAll(".dv-drop-target-dropzone");for(const te of xe)te.remove();const ue=A.querySelectorAll(".dv-drop-target");for(const te of ue)te.classList.remove("dv-drop-target")},[]),E=a.useCallback(()=>{M(!1),k(!1),L(),W(),U(),!(typeof window>"u")&&(B.current!=null&&window.clearTimeout(B.current),window.requestAnimationFrame(()=>{W(),U()}),B.current=window.setTimeout(()=>{W(),U(),B.current=null},80))},[L,W,U]),D=a.useCallback(A=>{var xe;y.current=A.api;const Q=Ao(R);Q!=null&&Q.layout&&A.api.fromJSON(Q.layout,{reuseExistingPanels:!1}),In(A.api,t),Mn(A.api,t,g),A.api.totalPanels===0&&t.length>0?dc(A.api,t,p):S(p)||S(Q==null?void 0:Q.activeTabId),T.current=!0,A.api.onDidActivePanelChange(ue=>{var ee;if(ue&&as(ue.id)){const H=((ee=ue.params)==null?void 0:ee.ideId)||ue.id.slice(7),Y=xs(t,H);h((Y==null?void 0:Y.tabKey)??null);return}if(h((ue==null?void 0:ue.id)??null),!ue)return;const te=$.get(ue.id);(te==null?void 0:te.streamSource)==="agent-stream"&&te.agentType&&v(te.ideId,"focus_session",{agentType:te.agentType,...te.sessionId&&{targetSessionId:te.sessionId}}).catch(()=>{})}),A.api.onDidLayoutChange(()=>{var ue;Lo(R,{activeTabId:((ue=A.api.activePanel)==null?void 0:ue.id)??null,layout:A.api.toJSON()})}),A.api.onWillDragPanel(()=>{M(!0),k(!1),W()}),A.api.onWillDragGroup(()=>{M(!0),k(!1),W()}),A.api.onWillShowOverlay(()=>{L(),k(!0)}),A.api.onDidMovePanel(E),A.api.onDidDrop(E),h(((xe=A.api.activePanel)==null?void 0:xe.id)??null)},[S,E,L,$,R,W,U,h,p,v,t]);a.useEffect(()=>{const A=y.current;!A||!T.current||(In(A,t),Mn(A,t,g),!A.activePanel&&A.panels[0]&&A.panels[0].group.model.openPanel(A.panels[0]))},[g,t]),a.useEffect(()=>{T.current&&S(p)},[S,p]),a.useEffect(()=>{if(!b||typeof window>"u")return;const A=()=>E();return window.addEventListener("pointerup",A),window.addEventListener("mouseup",A),window.addEventListener("dragend",A),()=>{window.removeEventListener("pointerup",A),window.removeEventListener("mouseup",A),window.removeEventListener("dragend",A)}},[E,b]),a.useEffect(()=>()=>{typeof window>"u"||B.current!=null&&window.clearTimeout(B.current)},[]),a.useEffect(()=>{const A=Q=>{const xe=Q.target;if(!xe)return;const ue=xe.querySelector("[data-tab-key]")||xe.closest("[data-tab-key]");if(ue){const te=ue.getAttribute("data-tab-key");te&&Q.dataTransfer&&Q.dataTransfer.setData("text/tab-key",te)}};return window.addEventListener("dragstart",A),()=>window.removeEventListener("dragstart",A)},[]);const O=j==="light"?pa:xa;return e.jsx(Ar.Provider,{value:_,children:e.jsx("div",{ref:w,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(ua,{className:`h-full min-h-0 min-w-0 adhdev-dockview${b?" is-dragging-dockview":""}${N?" is-showing-dockview-overlay":""}`,components:{conversation:uc,remote:pc},defaultTabComponent:mc,watermarkComponent:xc,onReady:D,singleTabMode:"default",tabAnimation:"smooth",theme:O})})})}function hc({showMobileChatMode:t,isMobile:s,activeConv:n,chatIdes:r,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:d,onStopCli:l,activeCliViewMode:f,onSetActiveCliViewMode:u,mobileChatConversations:m,hiddenConversations:h,ides:p,actionLogs:g,sendDaemonCommand:x,setLocalUserMessages:j,setActionLogs:v,isStandalone:y,userName:w,requestedMobileTabKey:T,onRequestedMobileTabConsumed:b,requestedMachineId:M,onRequestedMachineConsumed:N,requestedMobileSection:k,onRequestedMobileSectionConsumed:B,containerRef:R,isSplitMode:$,numGroups:P,groupSizes:_,groupedConvs:S,clearedTabs:W,focusedGroup:L,setFocusedGroup:U,moveTabToGroup:E,splitTabRelative:D,closeGroup:O,handleResizeStart:A,detectedIdes:Q,handleLaunchIde:xe,groupActiveTabIds:ue,setGroupActiveTabIds:te,groupTabOrders:ee,setGroupTabOrders:H,toggleHiddenTab:Y,visibleConversations:F,requestedDesktopTabKey:J,onRequestedDesktopTabConsumed:se,onOpenAccount:X,onDesktopActiveTabChange:le,onHideConversation:ge,onShowHiddenConversation:pe,onShowAllHiddenConversations:ve}){return Ls.useEffect(()=>{const Z=ce=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?ce.metaKey&&ce.key.toLowerCase()==="w":ce.ctrlKey&&ce.key.toLowerCase()==="w")&&(ce.preventDefault(),n&&ge&&ge(n))};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[n,ge]),e.jsxs(e.Fragment,{children:[!t&&e.jsx(Ii,{activeConv:n,agentCount:r.length,wsStatus:i,isConnected:o,conversations:F,hiddenConversations:h,onOpenHistory:c,onOpenConversation:pe,onHideConversation:ge,onShowConversation:pe,onShowAllHidden:ve,onOpenRemote:()=>{!n||Pe(n)||Me(n)||d(n)},onStopCli:l,activeCliViewMode:f,onSetCliViewMode:u}),t?e.jsx(Zo,{conversations:m,hiddenConversations:h,ides:p,actionLogs:g,sendDaemonCommand:x,setLocalUserMessages:j,setActionLogs:v,isStandalone:y,userName:w,requestedActiveTabKey:T,onRequestedActiveTabConsumed:b,requestedMachineId:M,onRequestedMachineConsumed:N,requestedMobileSection:k,onRequestedMobileSectionConsumed:B,onOpenAccount:X,onOpenHistory:c,onOpenRemote:d,onStopCli:l,wsStatus:i,isConnected:o,onShowHiddenConversation:pe,onShowAllHiddenConversations:ve}):s?e.jsx(oc,{containerRef:R,isSplitMode:$,numGroups:P,groupSizes:_,groupedConvs:S,clearedTabs:W,ides:p,actionLogs:g,sendDaemonCommand:x,setLocalUserMessages:j,setActionLogs:v,isStandalone:y,userName:w,focusedGroup:L,setFocusedGroup:U,moveTabToGroup:E,splitTabRelative:D,closeGroup:O,handleResizeStart:A,detectedIdes:Q,handleLaunchIde:xe,groupActiveTabIds:ue,setGroupActiveTabIds:te,groupTabOrders:ee,setGroupTabOrders:H,toggleHiddenTab:Y}):e.jsx(fc,{visibleConversations:F,clearedTabs:W,ides:p,actionLogs:g,sendDaemonCommand:x,setLocalUserMessages:j,setActionLogs:v,isStandalone:y,userName:w,detectedIdes:Q,handleLaunchIde:xe,toggleHiddenTab:Y,onActiveTabChange:le,requestedActiveTabKey:J,onRequestedActiveTabConsumed:se})]})}const Ns=[{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 bc({onClose:t}){const[s,n]=a.useState(0),r=Ns[s],i=s===Ns.length-1;return e.jsxs("div",{className:"onboarding-overlay",style:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.3s ease-out"},onClick:o=>{o.target===o.currentTarget&&t()},children:[e.jsxs("div",{style:{background:"var(--bg-secondary, #1a1a2e)",border:"1px solid var(--border-subtle, #333)",borderRadius:"1.25rem",width:"min(440px, 92vw)",padding:"2.5rem 2rem 2rem",position:"relative",animation:"slideUp 0.3s ease-out"},children:[e.jsx("button",{onClick:t,style:{position:"absolute",top:12,right:16,background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"1.2rem",cursor:"pointer"},children:"✕"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:6,marginBottom:"1.5rem"},children:Ns.map((o,c)=>e.jsx("div",{style:{width:c===s?24:8,height:8,borderRadius:4,background:c===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},c))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:r.visual||r.icon}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx("span",{children:r.icon})," ",r.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:r.desc}),r.code&&e.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[e.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),r.code]}),i&&e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"var(--accent, #a78bfa)",textDecoration:"none"},children:"📚 Learn more in the docs →"})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"1.5rem"},children:[e.jsx("button",{onClick:t,style:{background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"0.85rem",cursor:"pointer"},children:"Skip"}),e.jsx("button",{onClick:()=>i?t():n(o=>o+1),className:"transition-opacity hover:opacity-90",style:{background:"linear-gradient(135deg, #7c3aed, #6366f1)",color:"#fff",border:"none",borderRadius:"0.5rem",padding:"0.55rem 1.5rem",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},children:i?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
|
|
48
|
-
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
|
|
49
|
-
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
|
|
50
|
-
`})]})}function gc({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,onSelectTab:i}){return t?e.jsxs("div",{className:"flex border-b border-border-subtle bg-surface-primary shrink-0",children:[e.jsx("button",{className:`flex-1 py-2.5 px-4 border-b-2 text-[11px] font-bold tracking-wide cursor-pointer transition-all font-[var(--font)] ${n==="native"?"text-text-primary border-accent-primary bg-bg-primary":"text-text-muted border-transparent bg-transparent hover:text-text-secondary"}`,onClick:()=>i("native"),children:s}),r.map(o=>{const c=n===o.tabKey,d=o.status==="waiting_approval",l=o.status==="generating";return e.jsxs("button",{className:`flex-1 py-2.5 px-4 border-b-2 text-[11px] font-bold tracking-wide cursor-pointer transition-all font-[var(--font)] flex items-center justify-center gap-1.5 ${c?"text-text-primary border-accent-primary bg-bg-primary":"text-text-muted border-transparent bg-transparent hover:text-text-secondary"}`,onClick:()=>i(o.tabKey),children:[e.jsx("span",{className:"shrink-0",style:{display:"inline-block",width:6,height:6,borderRadius:"50%",background:d?"var(--status-warning)":l?"var(--accent-primary)":"var(--text-muted)",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),o.title,d&&e.jsx("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full text-[10px] font-bold ml-0.5",style:{background:"color-mix(in srgb, var(--status-warning) 13%, transparent)",color:"var(--status-warning)"},children:"!"})]},o.tabKey)})]}):null}function yc({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:i,preferredTabKey:o}){const[c,d]=a.useState(()=>o||"native"),l=a.useMemo(()=>lr(s),[s]),f=a.useMemo(()=>{var j;if(!t)return[];const x=t.daemonId||((j=t.id)==null?void 0:j.split(":")[0])||t.id;return dr(t,r,{machineName:t.daemonId&&l[t.daemonId]||void 0,connectionState:n[x]||"new"})},[t,r,l,n]),u=a.useMemo(()=>f.find(x=>x.streamSource==="native"),[f]),m=a.useMemo(()=>f.filter(x=>x.streamSource==="agent-stream"),[f]);a.useEffect(()=>{o&&d(o)},[o]),a.useEffect(()=>{var x;c!=="native"&&(m.some(j=>j.tabKey===c)||d(((x=m[0])==null?void 0:x.tabKey)||"native"))},[c,m]),a.useEffect(()=>{c==="native"&&(u||m[0]&&d(m[0].tabKey))},[c,u,m]);const h=a.useMemo(()=>c==="native"&&u?u:m.find(x=>x.tabKey===c)||u||m[0],[c,u,m]),p=a.useMemo(()=>m.map(x=>({tabKey:x.tabKey,title:x.title||x.agentName||i,status:x.status})),[m,i]),g=a.useCallback(x=>{if(x)return f.find(j=>j.sessionId===x||j.ideId===x||j.tabKey===x||j.ideType===x||j.agentType===x)},[f]);return{activeChatTab:c,setActiveChatTab:d,activeConv:h,conversations:f,extensionTabs:p,hasExtensions:p.length>0,resolveConversationByTarget:g}}function vc({activeConv:t,ideEntry:s,ides:n,connectionStates:r,actionLogs:i,localUserMessages:o,sendDaemonCommand:c,setLocalUserMessages:d,setActionLogs:l,isStandalone:f,userName:u,onOpenHistory:m,onConversationChange:h,onClose:p}){var W;const[g,x]=a.useState("split"),[j,v]=a.useState(()=>t.streamSource==="native"?"native":t.tabKey),y=a.useMemo(()=>s||n.find(L=>L.id===t.ideId),[t.ideId,s,n]),w=a.useMemo(()=>Ie((y==null?void 0:y.type)||""),[y==null?void 0:y.type]),{conversations:T,extensionTabs:b,hasExtensions:M}=yc({ideData:y,allIdes:n,connectionStates:r,localUserMessages:o,ideName:w||"IDE",preferredTabKey:t.streamSource==="native"?"native":t.tabKey});a.useEffect(()=>{v(t.streamSource==="native"?"native":t.tabKey)},[t.streamSource,t.tabKey]);const N=a.useMemo(()=>j==="native"?T.find(L=>L.streamSource==="native")||t:T.find(L=>L.tabKey===j)||t,[t,T,j]),k=N.daemonId||((W=N.ideId)==null?void 0:W.split(":")[0])||N.ideId,B=us({sendDaemonCommand:c,activeConv:N,setLocalUserMessages:d,setActionLogs:l,isStandalone:f}),{connScreenshot:R,screenshotUsage:$,handleRemoteAction:P}=Rr({doId:k,ideId:N.ideId,ideType:N.ideType,connState:N.connectionState||"new",viewMode:g,instanceId:y==null?void 0:y.instanceId}),_=a.useMemo(()=>i.filter(L=>L.ideId===N.tabKey),[i,N.tabKey]);a.useEffect(()=>{h==null||h(N)},[N,h]),a.useEffect(()=>{const L=U=>{U.key==="Escape"&&p()};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[p]);const S=a.useCallback(L=>{L.stopPropagation()},[]);return e.jsx("div",{className:"fixed inset-0 z-[1200] flex items-center justify-center p-0 md:p-3 bg-[#030617]/[0.56] backdrop-blur-md",onClick:p,children:e.jsxs("div",{className:"w-full h-screen md:h-[calc(100vh-24px)] md:w-[calc(100vw-24px)] flex flex-col overflow-hidden md:rounded-[14px] md:border border-border-default bg-surface-primary shadow-[0_24px_80px_rgba(2,6,23,0.32)]",role:"dialog","aria-modal":"true",onClick:S,children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4 border-b border-border-subtle bg-bg-primary shrink-0 overflow-visible",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 min-w-0 w-full md:w-auto md:flex-1",children:[e.jsx("div",{className:"min-w-0 flex-1 flex flex-col justify-center",children:e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 font-extrabold text-[18px] md:text-xl tracking-tight text-text-primary",children:[e.jsx("span",{className:"w-7 h-7 flex items-center justify-center rounded-lg bg-accent-primary/10 text-accent-primary shrink-0",children:e.jsx(ze,{size:16})}),e.jsx("span",{className:"truncate",children:N.displayPrimary||N.agentName||"Remote"})]})}),e.jsx("button",{className:"btn btn-primary btn-sm h-8 px-4 rounded-lg font-bold md:hidden shrink-0",onClick:p,children:"Close"})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 w-full md:w-auto justify-end",children:[e.jsx("div",{className:"flex items-center gap-2 mr-auto md:mr-0",children:["split","remote"].map(L=>{const U=g===L;return e.jsx("button",{className:`w-8 h-8 rounded-lg flex items-center justify-center transition-all ${U?"bg-accent-primary text-white shadow-glow":"bg-bg-secondary border border-border-subtle text-text-secondary hover:bg-bg-glass hover:text-text-primary"}`,onClick:()=>x(L),title:L==="split"?"Split view":"Remote only",children:L==="split"?e.jsx("span",{className:"font-bold text-lg leading-none mb-0.5",children:"⊞"}):e.jsx(ze,{size:15})},L)})}),e.jsx("div",{className:"hidden md:block w-[1px] h-5 bg-border-subtle mx-1"}),e.jsxs("button",{className:"btn btn-secondary btn-sm h-8 px-2.5 md:px-3 rounded-lg",onClick:()=>m(N),title:"Chat History",children:[e.jsx($s,{size:14,className:"md:mr-1.5"}),e.jsx("span",{className:"hidden md:inline",children:"History"})]}),e.jsx("button",{className:"hidden md:inline-flex btn btn-primary btn-sm h-8 px-4 rounded-lg font-bold",onClick:p,children:"Close"})]})]}),e.jsxs("div",{className:`flex-1 min-h-0 grid bg-bg-primary ${g==="split"?"grid-cols-1 grid-rows-[1fr_minmax(320px,42vh)] md:grid-cols-[minmax(360px,0.92fr)_minmax(420px,1.08fr)] md:grid-rows-1":"grid-cols-1 grid-rows-1"}`,children:[g!=="remote"&&e.jsxs("div",{className:`flex flex-col min-w-0 min-h-0 bg-bg-primary ${g==="split"?"order-2 md:order-1 border-b md:border-b-0 md:border-r border-border-subtle":""}`,children:[e.jsx(gc,{hasExtensions:M,ideName:w||"IDE",activeChatTab:j,extensionTabs:b,onSelectTab:v}),e.jsx(Qn,{activeConv:N,onModalButton:B.handleModalButton}),e.jsx(Ms,{activeConv:N,ideEntry:y,showMetaChips:!1,handleSendChat:B.handleSendChat,isSendingChat:B.isSendingChat,handleFocusAgent:B.handleFocusAgent,isFocusingAgent:B.isFocusingAgent,actionLogs:_,userName:u})]}),e.jsx("div",{className:`flex flex-col min-w-0 min-h-0 bg-black ${g==="split"?"order-1 md:order-2":""}`,children:e.jsx(Zn,{addLog:()=>{},connState:N.connectionState||"new",connScreenshot:R,screenshotUsage:$,transportType:N.transport,onAction:P})})]})]})})}function wc({activeConv:t,onCancel:s,onStopNow:n,onSaveAndStop:r}){const i=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 ",i,"?"]}),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"})]})]})]})}function jc({historyModalOpen:t,historyTargetConv:s,ides:n,isHistoryCreatingChat:r,isHistoryRefreshingHistory:i,savedHistorySessions:o,isSavedHistoryLoading:c,isResumingSavedHistorySessionId:d,onCloseHistory:l,onNewHistoryChat:f,onSwitchHistorySession:u,onRefreshHistory:m,onResumeSavedHistorySession:h,remoteDialogConv:p,remoteDialogIdeEntry:g,connectionStates:x,actionLogs:j,localUserMessages:v,sendDaemonCommand:y,setLocalUserMessages:w,setActionLogs:T,isStandalone:b,userName:M,onOpenRemoteHistory:N,onRemoteConversationChange:k,onCloseRemoteDialog:B,cliStopDialogOpen:R,activeConv:$,onCancelCliStop:P,onStopCliNow:_,onSaveCliAndStop:S,toasts:W,onDismissToast:L,onClickToast:U,showOnboarding:E,onCloseOnboarding:D}){return e.jsxs(e.Fragment,{children:[t&&s&&e.jsx(Ti,{activeConv:s,ides:n,isCreatingChat:r,isRefreshingHistory:i,savedSessions:o,isSavedSessionsLoading:c,isResumingSavedSessionId:d,onClose:l,onNewChat:f,onSwitchSession:u,onRefreshHistory:m,onResumeSavedSession:h}),p&&e.jsx(vc,{activeConv:p,ideEntry:g,ides:n,connectionStates:x,actionLogs:j,localUserMessages:v,sendDaemonCommand:y,setLocalUserMessages:w,setActionLogs:T,isStandalone:b,userName:M,onOpenHistory:N,onConversationChange:k,onClose:B}),R&&$&&Pe($)&&!Me($)&&e.jsx(wc,{activeConv:$,onCancel:P,onStopNow:_,onSaveAndStop:S}),e.jsx(or,{toasts:W,onDismiss:L,onClickToast:U}),E&&e.jsx(bc,{onClose:D})]})}function kc({daemons:t,targetVersion:s,upgradingDaemons:n,onUpgrade:r,onDismiss:i}){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(Ds,{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(o=>{const c=et(o,{fallbackId:o.id}),d=n[o.id],l=o.version||o.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]}),d==="upgrading"?e.jsx("span",{className:"text-[10px] animate-pulse",style:{color:"var(--status-warning)"},children:"upgrading…"}):d==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):d==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>r(o.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(o.id),children:"Upgrade"})]},o.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:i,title:"Dismiss",children:"✕"})]})}function Nc(){var Xs,Zs,Js;const{sendCommand:t}=ct(),s=Ps(),n=wt(),[r,i]=ma(),o=r.get("activeTab"),c=((Xs=s.state)==null?void 0:Xs.openRemoteForTabKey)||null,d=((Zs=s.state)==null?void 0:Zs.openMachineId)||null,l=((Js=s.state)==null?void 0:Js.mobileSection)||null,f=Ws(),u=f.ides||[],{updateIdeChats:m}=f,[h,p]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),g=f.toasts||[],x=f.setToasts||(()=>{}),j=f.wsStatus||"connected",v=f.isConnected??!0,y=f.connectionStates||{},w=f.showReconnected||!1,{groupAssignments:T,setGroupAssignments:b,focusedGroup:M,setFocusedGroup:N,groupActiveTabIds:k,setGroupActiveTabIds:B,groupTabOrders:R,setGroupTabOrders:$,groupSizes:P,setGroupSizes:_,isMobile:S,hasHydratedStoredLayout:W,hydrateStoredLayout:L}=Eo(),[U,E]=a.useState(!1),[D,O]=a.useState(!1),[A,Q]=a.useState([]),[xe,ue]=a.useState(!1),[te,ee]=a.useState(null),[H]=a.useState(()=>vr()),[Y,F]=a.useState([]),[J,se]=a.useState({}),[X,le]=a.useState({}),[ge,pe]=a.useState(null),ve=a.useRef(null);Pt("Dashboard",{ideCount:u.length,toastCount:g.length,focusedGroup:M,groupCount:Object.keys(T).length,localMessageTabs:Object.keys(J).length,actionLogCount:Y.length});const Z=u.find(fe=>fe.type==="adhdev-daemon"),ce=(Z==null?void 0:Z.detectedIdes)||[],I=!!Z,ae=(Z==null?void 0:Z.terminalBackend)||null,me=Z?et(Z,{fallbackId:Z.id}):null,oe=(Z==null?void 0:Z.id)||null,{hiddenTabs:be,hideTab:je,toggleTab:Re,showTab:Te,showAllTabs:tt}=yo(),{chatIdes:Oe,conversations:Le,visibleConversations:Ee,visibleTabKeys:Ve,resolveConversationBySessionId:ne,resolveConversationByTarget:we}=So({ides:u,connectionStates:y,localUserMessages:J,clearedTabs:X,hiddenTabs:be}),ye=a.useMemo(()=>Et(u),[u]),he=a.useRef(null),{containerRef:He,normalizedGroupAssignments:K,numGroups:z,isSplitMode:re,groupedConvs:C,moveTabToGroup:V,closeGroup:ie,handleResizeStart:q,splitTabRelative:de}=zo({groupAssignments:T,setGroupAssignments:b,setFocusedGroup:N,setGroupActiveTabIds:B,setGroupTabOrders:$,groupSizes:P,setGroupSizes:_,isMobile:S,visibleConversations:Ee,visibleTabKeys:Ve}),G=a.useMemo(()=>{var Ne,Ae;if(!S){if(ge){const De=Le.find(qe=>qe.tabKey===ge);if(De)return De}return Ee[0]}const fe=k[M];if(fe){const De=Le.find(qe=>qe.tabKey===fe);if(De)return De}return((Ne=C[M])==null?void 0:Ne[0])||((Ae=C[0])==null?void 0:Ae[0])},[ge,S,k,M,Le,C,Ee]);a.useEffect(()=>{if(S){he.current=null;return}if(!(G!=null&&G.sessionId)){he.current=null;return}const fe=`${G.tabKey}:${G.sessionId}`;if(he.current===fe)return;he.current=fe;const Ne=bt(G,ye),Ae=Math.max(Date.now(),ds(G),Ne.lastUpdated||0);t(G.daemonId||G.ideId,"mark_session_seen",{sessionId:G.sessionId,seenAt:Ae}).catch(()=>{})},[G,S,ye,t]);const{requestedDesktopTabKey:Se,requestedMobileTabKey:Xe,consumeRequestedActiveTab:Fe}=Co({isMobile:S,urlActiveTab:o,resolveConversationBySessionId:ne,setSearchParams:i}),{remoteDialogConv:$e,remoteDialogIdeEntry:jt,remoteDialogActiveConv:Lr,setRemoteDialogActiveConv:ms,openRemoteDialog:Pr,closeRemoteDialog:Er}=Do({isMobile:S,location:s,navigate:n,requestedRemoteTabTarget:c,requestedDesktopTabKey:Se,conversations:Le,ides:u,resolveConversationByTarget:we}),Ce=Lr||$e||G,Je=!!Ce&&Pe(Ce)&&!Me(Ce),$t=a.useMemo(()=>{if(!Ce||!Je)return null;const fe=Ce.daemonId||Ce.ideId||"",Ne=Ce.agentType||Ce.ideType||"";return`${fe}:${Ne}`},[Ce,Je]),$r=a.useMemo(()=>Ee,[Ee]),Dt=S&&H==="chat",Dr=a.useMemo(()=>Le.filter(fe=>be.has(fe.tabKey)),[Le,be]);vo({visibleConversations:Ee,clearedTabs:X,setClearedTabs:le,setActionLogs:F}),Io({ides:u,sendDaemonCommand:t,setToasts:x,setLocalUserMessages:se,resolveConversationByTarget:we});const{isRefreshingHistory:Br,handleLaunchIde:Kr,handleRefreshHistory:Wr}=yn({sendDaemonCommand:t,activeConv:G,updateIdeChats:m,setToasts:x,setLocalUserMessages:se,setClearedTabs:le}),{isCreatingChat:Or,isRefreshingHistory:zr,handleSwitchSession:Ur,handleNewChat:Hr,handleRefreshHistory:Fr}=yn({sendDaemonCommand:t,activeConv:Ce,updateIdeChats:m,setToasts:x,setLocalUserMessages:se,setClearedTabs:le}),fs=a.useCallback(async()=>{if(!(!Ce||!Je||xe)){ue(!0);try{const fe=Ce.daemonId||Ce.ideId,Ne=Ce.agentType||Ce.ideType,Ae=await t(fe,"list_saved_sessions",{agentType:Ne,providerType:Ne,kind:"cli",limit:50}),De=(Ae==null?void 0:Ae.result)??Ae;Q(Array.isArray(De==null?void 0:De.sessions)?De.sessions:[])}catch(fe){console.error("Refresh saved sessions failed",fe),Q([])}finally{ue(!1)}}},[Ce,xe,Je,t]);a.useEffect(()=>{if(!U){ve.current=null;return}if(!Je){ve.current=null,Q([]),ue(!1);return}!$t||xe||ve.current!==$t&&(ve.current=$t,fs())},[fs,U,xe,Je,$t]);const Vr=a.useCallback(async fe=>{if(!Ce||!Je||!fe.providerSessionId||!fe.workspace)return;const Ne=Ce.daemonId||Ce.ideId,Ae=Ce.agentType||Ce.ideType;try{ee(fe.providerSessionId);const De=await t(Ne,"launch_cli",{cliType:Ae,dir:fe.workspace,resumeSessionId:fe.providerSessionId,initialModel:fe.currentModel}),qe=(De==null?void 0:De.result)??De,Qs=typeof(qe==null?void 0:qe.sessionId)=="string"?qe.sessionId:typeof(qe==null?void 0:qe.id)=="string"?qe.id:"";Qs&&i(na=>{const en=new URLSearchParams(na);return en.set("activeTab",Qs),en},{replace:!0}),E(!1)}catch(De){console.error("Resume saved session failed",De)}finally{ee(null)}},[Ce,Je,t,i]);$o({urlActiveTab:S&&!Dt?o:null,conversations:Le,resolveConversationBySessionId:ne,normalizedGroupAssignments:K,hasHydratedStoredLayout:S&&!Dt?W:!0,hydrateStoredLayout:S&&!Dt?L:()=>{},setGroupActiveTabIds:B,setFocusedGroup:N,setSearchParams:i,historyModalOpen:U,activeConv:G,isRefreshingHistory:Br,ides:u,handleRefreshHistory:Wr});const Bt=a.useCallback(async fe=>{if(!G||!Pe(G)||Me(G))return;const Ne=G.ideType||G.agentType||"",Ae=G.ideId||G.daemonId||"";try{await t(Ae,"stop_cli",{cliType:Ne,targetSessionId:G.sessionId,mode:fe})}catch(De){console.error("Stop CLI failed:",De)}},[G,t]),qr=a.useCallback(async()=>{var Ne;if(!G||!Pe(G)||Me(G))return;if((Ne=G.resume)!=null&&Ne.supported){O(!0);return}const fe=G.ideType||G.agentType||"CLI";window.confirm(`Stop ${fe}?
|
|
51
|
-
This will terminate the CLI process.`)&&await Bt("hard")},[G,Bt]),Gr=a.useMemo(()=>!G||!Pe(G)||Me(G)?null:vt(G),[G]),Yr=a.useCallback(async fe=>{if(!(!G||!Pe(G)||Me(G)||vt(G)===fe))try{await t(G.daemonId||G.ideId,"set_cli_view_mode",{targetSessionId:G.sessionId,cliType:G.ideType||G.agentType,mode:fe})}catch(Ae){console.error("Failed to switch CLI view mode:",Ae)}},[G,t]),{versionMismatchDaemons:Xr,appVersion:Zr,versionBannerDismissed:Jr,setVersionBannerDismissed:Qr,upgradingDaemons:ea,handleBannerUpgrade:ta}=Uo({ides:u,sendDaemonCommand:t}),Gs=a.useCallback(fe=>{pe(fe.tabKey),i(Ne=>{const Ae=new URLSearchParams(Ne);return fe.sessionId?Ae.set("activeTab",fe.sessionId):Ae.delete("activeTab"),Ae},{replace:!0})},[i]),Ys=a.useCallback(fe=>{Te(fe.tabKey),Gs(fe)},[Gs,Te]),sa=a.useCallback(fe=>{je(fe.tabKey)},[je]);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(Si,{wsStatus:j,showReconnected:w}),e.jsx(Ci,{terminalBackend:ae,isStandalone:I,machineLabel:me,machineKey:oe}),!Jr&&e.jsx(kc,{daemons:Xr,targetVersion:Zr,upgradingDaemons:ea,onUpgrade:ta,onDismiss:()=>Qr(!0)}),e.jsx(hc,{showMobileChatMode:Dt,isMobile:S,activeConv:G,chatIdes:Oe,wsStatus:j,isConnected:v,onOpenHistory:fe=>{fe&&ms(fe),E(!0)},onOpenRemote:Pr,onStopCli:qr,activeCliViewMode:Gr,onSetActiveCliViewMode:Yr,mobileChatConversations:$r,ides:u,actionLogs:Y,sendDaemonCommand:t,setLocalUserMessages:se,setActionLogs:F,isStandalone:I,userName:f.userName,requestedMobileTabKey:Xe,onRequestedMobileTabConsumed:Fe,requestedMachineId:d,onRequestedMachineConsumed:()=>{n(s.pathname+s.search,{replace:!0,state:null})},requestedMobileSection:l,onRequestedMobileSectionConsumed:()=>{n(s.pathname+s.search,{replace:!0,state:null})},containerRef:He,isSplitMode:re,numGroups:z,groupSizes:P,groupedConvs:C,clearedTabs:X,focusedGroup:M,setFocusedGroup:N,moveTabToGroup:V,splitTabRelative:de,closeGroup:ie,handleResizeStart:q,detectedIdes:ce,handleLaunchIde:Kr,groupActiveTabIds:k,setGroupActiveTabIds:B,groupTabOrders:R,setGroupTabOrders:$,toggleHiddenTab:Re,visibleConversations:Ee,hiddenConversations:Dr,requestedDesktopTabKey:Se,onRequestedDesktopTabConsumed:Fe,onOpenAccount:I?void 0:()=>n("/account"),onDesktopActiveTabChange:pe,onHideConversation:sa,onShowHiddenConversation:Ys,onShowAllHiddenConversations:tt}),e.jsx("style",{children:`
|
|
52
|
-
body { overflow: hidden; overscroll-behavior: none; }
|
|
53
|
-
`}),e.jsx(jc,{historyModalOpen:U,historyTargetConv:Ce,ides:u,isHistoryCreatingChat:Or,isHistoryRefreshingHistory:Je?!1:zr,savedHistorySessions:A,isSavedHistoryLoading:xe,isResumingSavedHistorySessionId:te,onCloseHistory:()=>E(!1),onNewHistoryChat:Hr,onSwitchHistorySession:Ur,onRefreshHistory:Je?fs:Fr,onResumeSavedHistorySession:Vr,remoteDialogConv:$e,remoteDialogIdeEntry:jt,connectionStates:y,actionLogs:Y,localUserMessages:J,sendDaemonCommand:t,setLocalUserMessages:se,setActionLogs:F,isStandalone:I,userName:f.userName,onOpenRemoteHistory:fe=>{fe&&ms(fe),E(!0)},onRemoteConversationChange:ms,onCloseRemoteDialog:Er,cliStopDialogOpen:D,activeConv:G,onCancelCliStop:()=>O(!1),onStopCliNow:async()=>{O(!1),await Bt("hard")},onSaveCliAndStop:async()=>{O(!1),await Bt("save")},toasts:g,onDismissToast:fe=>x(Ne=>Ne.filter(Ae=>Ae.id!==fe)),onClickToast:fe=>{if(fe.targetKey){const Ne=we(fe.targetKey);Ne&&(N(K.get(Ne.tabKey)??0),Ys(Ne))}},showOnboarding:h,onCloseOnboarding:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}p(!1)}})]})}function Sc({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:i}){const[o,c]=a.useState([]),[d,l]=a.useState(null),[f,u]=a.useState(null),[m,h]=a.useState(!1),[p,g]=a.useState(null),[x,j]=a.useState(!1),[v,y]=a.useState(""),w=a.useRef(null),T=a.useCallback(E=>{w.current=E},[]),b=a.useCallback((E,D,O=!1)=>{c(A=>[...A.slice(-100),{timestamp:Date.now(),level:E,message:D}]),setTimeout(()=>{var A;return(A=i.current)==null?void 0:A.scrollIntoView({behavior:"smooth"})},100),O&&at.showToast(D,E==="error"||E==="warn"?"warning":"success")},[i]),M=a.useCallback(async(E,D)=>{var O;if(!t||d)return!1;l(E),b("info",`Launching ${Ie(E)}${D!=null&&D.workspace?` in ${D.workspace}`:""}...`);try{const A={ideType:E,enableCdp:!0};(O=D==null?void 0:D.workspace)!=null&&O.trim()?A.workspace=D.workspace.trim():D!=null&&D.useDefaultWorkspace&&(A.useDefaultWorkspace=!0);const Q=await n(t,"launch_ide",A);return b(Q!=null&&Q.success?"info":"error",Q!=null&&Q.success?`${Ie(E)} launched`:`Failed: ${Q==null?void 0:Q.error}`,!0),!!(Q!=null&&Q.success)}catch(A){return b("error",`Launch error: ${A.message}`,!0),!1}finally{l(null)}},[t,d,b,n]),N=a.useCallback(async E=>{if(!t)return{success:!1};const{cliType:D,dir:O,workspaceId:A,useDefaultWorkspace:Q,useHome:xe,argsStr:ue,model:te,resumeSessionId:ee}=E;if(!D)return b("warn","Select a CLI or ACP provider first",!0),{success:!1};const H=ue?ue.split(/\s+/).filter(Boolean):void 0,Y=(O==null?void 0:O.trim())||(A?"(saved id)":Q?"(default workspace)":xe?"(home)":"");b("info",`Launching ${D}${Y?` in ${Y}`:""}${te?` (model: ${te})`:""}...`),u(D);try{const F={cliType:D,cliArgs:H,initialModel:te||void 0};O!=null&&O.trim()?F.dir=O.trim():A?F.workspaceId=A:Q?F.useDefaultWorkspace=!0:xe&&(F.useHome=!0),ee&&(F.resumeSessionId=ee);const J=await n(t,"launch_cli",F),se=(J==null?void 0:J.result)||J;return J!=null&&J.success?(b("info",`${D} launched`,!0),(se==null?void 0:se.launchSource)==="home"?b("info","📂 Running in home directory (explicit choice)"):(se==null?void 0:se.launchSource)==="defaultWorkspace"&&b("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:se==null?void 0:se.sessionId}):(b("error",`Failed: ${(J==null?void 0:J.error)||(se==null?void 0:se.error)}`,!0),(J==null?void 0:J.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&g({cliType:D,argsStr:ue,model:te}),{success:!1,sessionId:se==null?void 0:se.sessionId})}catch(F){return b("error",`Launch error: ${F.message}`,!0),{success:!1}}finally{u(null)}},[t,b,n]),k=a.useCallback(async(E,D,O,A)=>t?E?D.trim()?N({cliType:E,dir:D,argsStr:O,model:A}):(g({cliType:E,argsStr:O,model:A}),{success:!1}):(b("warn","Select a provider",!0),{success:!1}):{success:!1},[t,b,N]),B=a.useCallback(async(E,D,O)=>{if(t&&window.confirm(`Stop ${E}?
|
|
54
|
-
This will terminate the process.`))try{const A=await n(t,"stop_cli",{cliType:E,dir:D,targetSessionId:O});A!=null&&A.success?b("info",`${E} stopped`,!0):b("error",`Stop failed: ${(A==null?void 0:A.error)||"Unknown error"}`,!0)}catch(A){b("error",`Stop failed: ${A.message}`,!0)}},[t,b,n]),R=a.useCallback(async E=>{try{await n(E.daemonId,"restart_ide",{ideType:E.type}),b("info",`${Ie(E.type)} restart initiated`,!0)}catch(D){b("error",`Restart failed: ${D.message}`,!0)}},[b,n]),$=a.useCallback(async E=>{if(window.confirm(`Stop ${Ie(E.type)}?
|
|
55
|
-
This will disconnect CDP and optionally kill the process.`))try{const D=await n(E.daemonId,"stop_ide",{ideType:E.type,killProcess:!0});D!=null&&D.success?b("info",`${Ie(E.type)} stopped`,!0):b("error",`Stop failed: ${(D==null?void 0:D.error)||"Unknown error"}`,!0)}catch(D){b("error",`Stop failed: ${D.message}`,!0)}},[b,n]),P=a.useCallback(async()=>{if(t)try{const E=await n(t,"detect_ides",{});b("info",`Found ${((E==null?void 0:E.result)||[]).length} IDE(s)`,!0)}catch(E){b("error",`Detection failed: ${E.message}`,!0)}},[t,b,n]),_=a.useCallback(async E=>{if(!(!t||!E.trim())){h(!0);try{const D=await n(t,"workspace_add",{path:E.trim()});D!=null&&D.success?b("info",`Workspace added: ${E.trim()}`):b("error",(D==null?void 0:D.error)||"workspace_add failed")}catch(D){b("error",D.message)}finally{h(!1)}return!0}},[t,b,n]),S=a.useCallback(async E=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){h(!0);try{const D=await n(t,"workspace_remove",{id:E});D!=null&&D.success?b("info","Workspace removed",!0):b("error",(D==null?void 0:D.error)||"workspace_remove failed",!0)}catch(D){b("error",D.message,!0)}finally{h(!1)}}},[t,b,n]),W=a.useCallback(async E=>{var D;if(t){h(!0);try{const O=await n(t,"workspace_set_default",E===null?{clear:!0}:{id:E});if(O!=null&&O.success){b("info",E?"Default workspace updated":"Default workspace cleared",!0);const A=typeof O.defaultWorkspacePath=="string"?O.defaultWorkspacePath:"";A&&((D=w.current)==null||D.call(w,A))}else b("error",(O==null?void 0:O.error)||"workspace_set_default failed",!0)}catch(O){b("error",O.message,!0)}finally{h(!1)}}},[t,b,n]),L=a.useCallback(async E=>{var O;if(!t||!E.trim())return;const D=E.trim();h(!0);try{const A=await n(t,"workspace_set_default",{path:D});A!=null&&A.success?(b("info","Default workspace set from history"),(O=w.current)==null||O.call(w,D)):b("error",(A==null?void 0:A.error)||"Could not set default (path missing on disk?)")}catch(A){b("error",A.message)}finally{h(!1)}},[t,b,n]),U=a.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:v}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:v})}catch(E){b("warn",`Live nickname updated, but account sync failed: ${E.message}`)}b("info",`Nickname set to "${v||"(cleared)"}"`),j(!1)}catch(E){b("error",`Failed: ${E.message}`)}},[t,v,s,b,r,n]);return{logs:o,launchingIde:d,launchingAgentType:f,workspaceBusy:m,launchPick:p,setLaunchPick:g,editingNickname:x,setEditingNickname:j,nicknameInput:v,setNicknameInput:y,addLog:b,handleLaunchIde:M,runLaunchCliCore:N,handleLaunchCli:k,handleStopCli:B,handleRestartIde:R,handleStopIde:$,handleDetectIdes:P,handleWorkspaceAdd:_,handleWorkspaceRemove:S,handleWorkspaceSetDefault:W,handleWorkspaceResumePath:L,handleSaveNickname:U,setOnDefaultWorkspaceChanged:T}}function Cc({machineId:t,machine:s,ideSessions:n,cliSessions:r,acpSessions:i,actions:o,sendDaemonCommand:c}){const{workspaceBusy:d,handleWorkspaceAdd:l,handleWorkspaceRemove:f,handleWorkspaceSetDefault:u}=o,[m,h]=a.useState(!1),[p,g]=a.useState(""),[x,j]=a.useState([]),[v,y]=a.useState(!1),[w,T]=a.useState(""),b=a.useCallback(async R=>{y(!0),T("");try{const $=await Tr(c,t,R);g($.path),j($.directories)}catch($){T($ instanceof Error?$.message:"Could not load folder")}finally{y(!1)}},[t,c]),M=a.useCallback(()=>{var $;h(!0);const R=s.defaultWorkspacePath||(($=s.workspaces[0])==null?void 0:$.path)||"~";b(R)},[b,s.defaultWorkspacePath,s.workspaces]),N=s.availableMem??s.freeMem,k=s.totalMem>0?Math.min(100,Math.max(0,Math.round((s.totalMem-N)/s.totalMem*100))):0,B=s.loadavg[0]||0;return e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-5",children:[e.jsx(Kt,{icon:e.jsx(qn,{size:16}),label:"Uptime",value:oi(s.uptime)}),e.jsx(Kt,{icon:e.jsx(ze,{size:16}),label:"IDEs",value:`${n.length}`}),e.jsx(Kt,{icon:e.jsx(Ks,{size:16}),label:"CLIs",value:`${r.length}`}),e.jsx(Kt,{icon:e.jsx(Pa,{size:16}),label:"ACPs",value:`${i.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(an,{value:Math.min(Math.round(B/s.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${B.toFixed(2)} avg / ${s.cpus} cores`}),e.jsx(an,{value:k,max:100,label:"Memory",color:"#3b82f6",detail:`${ln(s.totalMem-N)} / ${ln(s.totalMem)}${s.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(At,{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:d,value:s.defaultWorkspaceId||"",onChange:R=>void u(R.target.value===""?null:R.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(s.workspaces||[]).map(R=>e.jsx("option",{value:R.id,children:R.label||R.path},R.id))]}),s.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:s.defaultWorkspacePath,children:s.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.jsx("button",{type:"button",className:"btn bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary px-3 py-1.5 rounded transition-colors text-xs",disabled:d,onClick:M,children:"Select workspace…"}),e.jsx("span",{className:"text-[11px] text-text-muted",children:"Add workspaces by selecting a folder in the explorer."})]}),(s.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1.5 max-h-40 overflow-y-auto",children:(s.workspaces||[]).map(R=>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:[R.id===s.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:tr(R.path,R.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:R.path,children:R.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:d,onClick:()=>void f(R.id),children:"Remove"})]},R.id))})]}),m&&e.jsx(Fs,{title:"Add workspace",description:"Browse the machine like a normal explorer, then add the current folder as a saved workspace.",currentPath:p,directories:x,busy:v,error:w,confirmLabel:"Add workspace",onClose:()=>h(!1),onNavigate:R=>{b(R)},onConfirm:R=>{(async()=>{if(!R)return;await l(R)&&h(!1)})()}})]})}const Tn=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],Ic=[{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 Mc({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[i,o]=a.useState("config"),[c,d]=a.useState("codex-cli"),[l,f]=a.useState([]),[u,m]=a.useState(""),[h,p]=a.useState([]),[g,x]=a.useState(""),j=a.useRef(null),v=a.useRef(null),y=k=>{f(B=>B.includes(k)?B.filter(R=>R!==k):[...B,k])},w=()=>f([...Tn]),T=()=>f([]);a.useEffect(()=>{var k;(k=j.current)==null||k.scrollIntoView({behavior:"smooth"})},[h]),a.useEffect(()=>()=>{v.current&&clearInterval(v.current)},[]);const b=a.useCallback(()=>{v.current&&clearInterval(v.current),v.current=setInterval(async()=>{try{const k=await n(t,"provider_auto_fix_status",{providerType:s.type});(k==null?void 0:k.running)===!1&&i==="running"&&(o("done"),p(B=>[...B,`
|
|
56
|
-
✅ Auto-fix completed!`]),v.current&&clearInterval(v.current))}catch{}},3e3)},[t,s.type,n,i]),M=async()=>{if(l.length!==0){o("running"),p(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${l.join(", ")}`,u?`💬 Comment: ${u}`:"",""]),x("");try{const k=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:c,...u?{comment:u}:{}});k!=null&&k.success&&(k!=null&&k.started||k!=null&&k.running)?(p(B=>[...B,"✅ Agent started. Monitoring progress..."]),b()):(o("error"),x((k==null?void 0:k.error)||"Failed to start auto-fix"))}catch(k){o("error"),x((k==null?void 0:k.message)||"Connection failed")}}},N=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),p(k=>[...k,`
|
|
57
|
-
⚠️ Auto-fix cancelled.`]),o("done"),v.current&&clearInterval(v.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick: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:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:s.icon||"🔧"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-text-primary",children:["Auto-Fix: ",s.displayName]}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"AI agent will implement provider scripts"})]})]}),e.jsx("button",{onClick:r,className:"text-text-muted hover:text-text-primary text-lg leading-none",children:"×"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[i==="config"&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"AI Agent"}),e.jsx("div",{className:"flex gap-2",children:Ic.map(k=>e.jsxs("button",{onClick:()=>d(k.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===k.value?k.color+"66":"var(--border-subtle)",background:c===k.value?k.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===k.value?k.color:"var(--text-primary)"},children:k.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:k.desc})]},k.value))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"Scripts to Fix"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:w,className:"text-[10px] text-violet-400 hover:text-violet-300",children:"All"}),e.jsx("span",{className:"text-[10px] text-text-muted",children:"|"}),e.jsx("button",{onClick: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:Tn.map(k=>e.jsxs("button",{onClick:()=>y(k),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(k)?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:l.includes(k)?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent",color:l.includes(k)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(k)?"☑ ":"☐ ",k]},k))})]}),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:k=>m(k.target.value),placeholder:"e.g. Also search buttons inside Shadow DOM, preserve code block formatting in readChat...",rows:2,className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] resize-none placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]})]}),(i==="running"||i==="done"||i==="error")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Agent Output"}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-[#0d0d0d] p-3 font-mono text-[11px] leading-relaxed text-text-secondary overflow-y-auto",style:{maxHeight:320,minHeight:200},children:[h.map((k,B)=>e.jsx("div",{className:k.startsWith("✅")?"text-green-400":"",style:k.startsWith("❌")||k.startsWith("⚠")?{color:"var(--status-warning)"}:void 0,children:k},B)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:j})]}),g&&e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:g})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-between items-center",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[i==="config"&&l.length>0&&`${l.length} script(s) selected`,i==="running"&&"Agent is generating...",i==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[i==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:M,disabled:l.length===0,className:"machine-btn",style:{background:l.length>0?"color-mix(in srgb, var(--accent-primary) 15%, transparent)":void 0,borderColor:l.length>0?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":void 0,color:l.length>0?"#a78bfa":void 0,opacity:l.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:N,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(i==="done"||i==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{o("config"),p([]),x("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function Tc({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:i}){var b;const o=s.filter(M=>M.category==="ide"),[c,d]=a.useState(((b=o[0])==null?void 0:b.type)||""),[l,f]=a.useState(""),[u,m]=a.useState(""),[h,p]=a.useState(!1),[g,x]=a.useState(""),[j,v]=a.useState(!1),y=M=>{const N=M.toLowerCase().replace(/[^a-z0-9-]/g,"");f(N),(!u||u===w(l))&&m(w(N))},w=M=>M.split("-").map(N=>N.charAt(0).toUpperCase()+N.slice(1)).join(" "),T=async()=>{if(!(!l||!u||!c)){p(!0),x("");try{const M=await n(t,"provider_clone",{type:l,name:u,category:"ide",location:"user",cloneFrom:c});M!=null&&M.success||M!=null&&M.created?(v(!0),i==null||i(l)):x((M==null?void 0:M.error)||"Failed to create provider")}catch(M){x((M==null?void 0:M.message)||"Connection failed")}p(!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:M=>M.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:j?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"text-3xl mb-2",children:"🎉"}),e.jsx("h3",{className:"text-[14px] font-semibold text-text-primary",children:"Provider Created!"}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:[e.jsx("code",{className:"text-violet-400",children:l})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",l,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",l]})," or use Auto-Fix to implement scripts."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Base Provider"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:o.map(M=>e.jsxs("button",{onClick:()=>d(M.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===M.type?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:c===M.type?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:M.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===M.type?"#a78bfa":"var(--text-secondary)"},children:M.displayName})]},M.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:M=>y(M.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:M=>m(M.target.value),placeholder:"My Custom IDE",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]}),g&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:g})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:j?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||h,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||h?.4:1},children:h?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function _c({machineId:t,providers:s,sendDaemonCommand:n}){const[r,i]=a.useState([]),[o,c]=a.useState(!1),[d,l]=a.useState(null),[f,u]=a.useState("all"),[m,h]=a.useState(null),[p,g]=a.useState(!1),x=a.useCallback(async()=>{var v;if(t){c(!0);try{const y=await n(t,"get_provider_settings",{}),w=(y==null?void 0:y.result)||y;if(y!=null&&y.success&&(w!=null&&w.settings)){const T=[];for(const[b,M]of Object.entries(w.settings)){const N=s.find(k=>k.type===b);T.push({type:b,displayName:(N==null?void 0:N.displayName)||b,icon:(N==null?void 0:N.icon)||"",category:(N==null?void 0:N.category)||"unknown",schema:M,values:((v=w.values)==null?void 0:v[b])||{}})}T.sort((b,M)=>b.category.localeCompare(M.category)||b.displayName.localeCompare(M.displayName)),i(T)}}catch{}c(!1)}},[t,s,n]);a.useEffect(()=>{r.length===0&&x()},[]);const j=async(v,y,w)=>{l(`${v}.${y}`),i(T=>T.map(b=>b.type===v?{...b,values:{...b.values,[y]:w}}:b));try{const T=await n(t,"set_provider_setting",{providerType:v,key:y,value:w});T!=null&&T.success||x()}catch{x()}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(v=>e.jsx("button",{onClick:()=>u(v),className:`machine-btn text-[10px] px-2 py-0.5 ${f===v?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:v.toUpperCase()},v))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>g(!0),className:"machine-btn text-[10px] bg-green-500/[0.06] border-green-500/20 text-green-400 hover:bg-green-500/[0.12]",children:"✨ Create Provider"}),e.jsx("button",{onClick:x,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),f!=="all"&&r.filter(v=>v.category===f).length>1&&(()=>{const v=r.filter(b=>b.category===f),y=new Map;for(const b of v)for(const M of b.schema){if(M.type!=="boolean")continue;const N=y.get(M.key),k=!!(b.values[M.key]??M.default);N?(N.onCount+=k?1:0,N.total+=1):y.set(M.key,{label:M.label||M.key,onCount:k?1:0,total:1})}const w=[...y.entries()].filter(([,b])=>b.total===v.length);if(w.length===0)return null;const T=async(b,M)=>{for(const N of v)await j(N.type,b,M)};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 ",f.toUpperCase()," providers (",v.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:w.map(([b,M])=>{const N=M.onCount===M.total,k=M.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:M.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",M.onCount,"/",M.total,")"]}),e.jsx("button",{onClick:()=>void T(b,!0),disabled:N,className:`machine-btn text-[9px] px-1.5 py-px ${N?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void T(b,!1),disabled:k,className:`machine-btn text-[9px] px-1.5 py-px ${k?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},b)})})]})})(),o&&r.length===0?e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading provider settings..."}):e.jsx("div",{className:"flex flex-col gap-2",children:r.filter(v=>f==="all"||v.category===f).map(v=>e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-lg",children:v.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:v.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:v.category==="acp"?"rgba(139,92,246,0.08)":v.category==="cli"?"rgba(59,130,246,0.08)":v.category==="ide"?"rgba(34,197,94,0.08)":"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:v.category==="acp"?"#a78bfa":v.category==="cli"?"#60a5fa":v.category==="ide"?"#86efac":"var(--status-warning)"},children:v.category}),v.category==="ide"&&e.jsx("button",{onClick:()=>h(s.find(y=>y.type===v.type)||{type:v.type,name:v.displayName,displayName:v.displayName,icon:v.icon,category:v.category}),className:"ml-auto machine-btn text-[9px] px-2 py-0.5 bg-violet-500/[0.06] border-violet-500/20 text-violet-400 hover:bg-violet-500/[0.12]",children:"🔧 Auto-Fix"})]}),e.jsx("div",{className:"flex flex-col gap-2",children:v.schema.map(y=>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:[y.label||y.key,d===`${v.type}.${y.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),y.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:y.description})]}),e.jsx("div",{className:"shrink-0",children:y.type==="boolean"?e.jsx("button",{onClick:()=>j(v.type,y.key,!(v.values[y.key]??y.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:v.values[y.key]??y.default?"#8b5cf6":"var(--border-subtle)"},children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-white absolute top-[3px] transition-[left] duration-200 shadow-[0_1px_3px_rgba(0,0,0,0.3)]",style:{left:v.values[y.key]??y.default?21:3}})}):y.type==="number"?e.jsx("input",{type:"number",value:v.values[y.key]??y.default??0,min:y.min,max:y.max,onChange:w=>{const T=parseInt(w.target.value)||0;y.min!==void 0&&T<y.min||y.max!==void 0&&T>y.max||j(v.type,y.key,T)},className:"machine-input w-20 text-center text-[11px]"}):y.type==="select"&&y.options?e.jsx("select",{value:v.values[y.key]??y.default??"",onChange:w=>j(v.type,y.key,w.target.value),className:"machine-input text-[11px]",children:y.options.map(w=>e.jsx("option",{value:w,children:w},w))}):e.jsx("input",{type:"text",value:v.values[y.key]??y.default??"",onBlur:w=>j(v.type,y.key,w.target.value),className:"machine-input w-[120px] text-[11px]"})})]},y.key))})]},v.type))}),m&&e.jsx(Mc,{machineId:t,provider:m,sendDaemonCommand:n,onClose:()=>h(null)}),p&&e.jsx(Tc,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>g(!1),onCreated:()=>{g(!1),x()}})]})}function Rc({machineId:t,sendDaemonCommand:s}){const[n,r]=a.useState([]),[i,o]=a.useState(0),[c,d]=a.useState(!0),[l,f]=a.useState("debug"),u=a.useRef(null),m=a.useRef(!1);return a.useEffect(()=>{if(!t||!c)return;const h=async()=>{try{const g=await s(t,"get_logs",{count:200,minLevel:l,since:i}),x=(g==null?void 0:g.result)||g;if(g!=null&&g.success&&Array.isArray(x==null?void 0:x.logs)&&x.logs.length>0){r(v=>[...v,...x.logs.map(w=>({timestamp:w.ts,level:w.level,message:`[${w.category}] ${w.message}`}))].slice(-300));const j=Math.max(...x.logs.map(v=>v.ts));o(j)}}catch{}};h();const p=setInterval(h,3e3);return()=>clearInterval(p)},[t,c,i,l,s]),a.useEffect(()=>{if(c&&n.length>0){const h=m.current?"smooth":"instant";setTimeout(()=>{var p;(p=u.current)==null||p.scrollIntoView({behavior:h}),m.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(h=>e.jsx("button",{onClick:()=>{f(h),r([]),o(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${l===h?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:h.toUpperCase()},h))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[n.length," entries"]}),e.jsx("button",{onClick:()=>d(!c),className:`machine-btn ${c?"text-green-500 border-green-500/30":""}`,children:c?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),o(0)},className:"machine-btn",children:"Clear"})]})]}),e.jsxs("div",{className:"bg-bg-secondary border border-border-subtle rounded-xl p-3 min-h-[200px] max-h-[500px] overflow-y-auto font-mono text-[11px] leading-relaxed",children:[n.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),n.map((h,p)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:h.level==="error"?"#ef4444":h.level==="warn"?"var(--status-warning)":h.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(h.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:h.level==="error"?"#ef4444":h.level==="warn"?"var(--status-warning)":h.level==="debug"?"#475569":"#8b5cf6"},children:h.level==="error"?"ERR":h.level==="warn"?"WRN":h.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:h.message})]},p)),e.jsx("div",{ref:u})]})]})}function Ac({machine:t,launchPick:s,actions:n}){const{runLaunchCliCore:r,setLaunchPick:i}=n;return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/55 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-pick-title",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-border-subtle bg-bg-secondary shadow-xl p-5",children:[e.jsx("h2",{id:"launch-pick-title",className:"text-sm font-semibold text-text-primary m-0 mb-1",children:"Where should this run?"}),e.jsx("p",{className:"text-[11px] text-text-muted m-0 mb-4",children:"Nothing is assumed. Pick a saved workspace, your default workspace, or home — or cancel and type a path."}),e.jsx("div",{className:"flex flex-col gap-2 mb-4 max-h-48 overflow-y-auto",children:(t.workspaces||[]).length===0?e.jsx("span",{className:"text-[11px] text-text-muted",children:"No saved workspaces yet. Add one in Overview or type a path above."}):(t.workspaces||[]).map(o=>e.jsxs("button",{type:"button",className:"text-left text-xs px-3 py-2 rounded-lg border border-border-subtle bg-bg-primary hover:bg-violet-500/10 transition-colors",onClick:()=>{i(null),r({cliType:s.cliType,workspaceId:o.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:o.label||o.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:o.path})]},o.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",disabled:!t.defaultWorkspacePath,onClick:()=>{i(null),r({cliType:s.cliType,useDefaultWorkspace:!0,argsStr:s.argsStr,model:s.model})},children:"Default workspace"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",onClick:()=>{i(null),r({cliType:s.cliType,useHome:!0,argsStr:s.argsStr,model:s.model})},children:"Home directory"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[80px]",onClick:()=>i(null),children:"Cancel"})]})]})})}function _n({children:t}){return e.jsx("div",{className:"text-xs font-semibold text-text-muted mb-2 tracking-wide uppercase",children:t})}function Lc({machineEntry:t,providers:s,recentLaunches:n,onUpgradeDaemon:r,onOpenLogs:i,onOpenRecent:o,onOpenWorkspace:c,onGoTab:d}){const l=t.detectedIdes||[],f=s.filter(g=>g.category==="cli"),u=s.filter(g=>g.category==="acp"),m=n.slice(0,4),h=[l.length>0?{id:"ide",kind:"ide",label:"IDE Workspace",desc:"Graphical app"}:null,f.length>0?{id:"cli",kind:"cli",label:"CLI Workspace",desc:"Terminal"}:null,u.length>0?{id:"acp",kind:"acp",label:"ACP Workspace",desc:"Agent"}:null].filter(Boolean),p=g=>g==="ide"?"IDE":g==="cli"?"CLI":"ACP";return e.jsxs("div",{className:"flex flex-col gap-6 md:min-w-[280px] md:max-w-[340px] shrink-0 border-r border-[#ffffff0a] pr-4 md:pr-6 md:h-full overflow-y-auto",children:[m.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(_n,{children:"Recent Activity"}),e.jsx("div",{className:"flex flex-col gap-1.5",children:m.map(g=>e.jsxs("button",{type:"button",className:"flex flex-col gap-1 items-start text-left p-3 rounded-xl bg-bg-surface border border-[#ffffff08] hover:bg-[#ffffff0a] hover:border-[#ffffff10] transition-colors cursor-pointer group",onClick:()=>o(g),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate w-full group-hover:text-accent-primary transition-colors",children:g.label}),e.jsxs("span",{className:"text-xs text-text-secondary truncate w-full opacity-80",children:[p(g.kind),g.subtitle?` · ${g.subtitle}`:""]})]},g.id))})]}),h.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(_n,{children:"New Workspace"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:h.map(g=>e.jsxs("button",{type:"button",className:"flex flex-col items-center justify-center p-3 gap-1 rounded-xl bg-bg-surface border border-[#ffffff08] hover:bg-[#ffffff0e] hover:scale-[1.02] active:scale-95 transition-all cursor-pointer",onClick:()=>c(g.kind),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary text-center",children:g.label.replace(" Workspace","")}),e.jsx("span",{className:"text-[10px] text-text-muted text-center uppercase tracking-wide",children:g.desc})]},g.id))})]}),e.jsxs("div",{className:"flex flex-col gap-2 mt-auto pt-4 border-t border-[#ffffff08]",children:[t.versionMismatch&&e.jsx("button",{type:"button",className:"btn btn-sm w-full bg-accent-primary/20 text-accent-primary border-accent-primary/30 hover:bg-accent-primary/30",onClick:r,children:"Update Daemon"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm flex-1",onClick:i,children:"Logs"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm flex-1",onClick:()=>d("providers"),children:"Providers"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm flex-1",onClick:()=>d("overview"),children:"System"})]})]})]})}function Pc(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const Ec={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 Ss({category:t,machine:s,machineId:n,providers:r,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:d,initialWorkspaceId:l,initialWorkspacePath:f}){const u=wt(),{handleLaunchIde:m,handleStopCli:h,handleRestartIde:p,handleStopIde:g,handleDetectIdes:x,launchingIde:j,launchingAgentType:v}=c,[y,w]=a.useState(null),T=a.useCallback(C=>{C&&u({pathname:"/",search:`?activeTab=${encodeURIComponent(C)}`})},[u]),b=Ec[t],M=t==="ide",N=t==="acp",k=r.filter(C=>C.category===t),B=new Map(k.map(C=>[C.type,C.displayName||C.type])),[R,$]=a.useState(""),[P,_]=a.useState(""),[S,W]=a.useState(""),[L,U]=a.useState(f?"__custom__":l||s.defaultWorkspaceId||""),[E,D]=a.useState(f||""),[O,A]=a.useState([]),[Q,xe]=a.useState(!1),[ue,te]=a.useState(""),[ee,H]=a.useState([]),[Y,F]=a.useState(!1),[J,se]=a.useState(""),X=a.useRef(null),[le,ge]=a.useState(null),pe=a.useRef("__home__"),[ve,Z]=a.useState("__home__"),[ce,I]=a.useState(!1),ae=O.filter(C=>!i.some(V=>V.type===C&&Ue(V.status)!=="stopped")),me=a.useRef({});a.useEffect(()=>{s.defaultWorkspaceId&&!L&&U(s.defaultWorkspaceId)},[s.defaultWorkspaceId]),a.useEffect(()=>{if(f){U("__custom__"),D(f);return}l&&(U(l),D(""))},[l,f]);const oe=(()=>{if(L==="__custom__")return E.trim();if(!L)return"";const C=(s.workspaces||[]).find(V=>V.id===L);return(C==null?void 0:C.path)||""})(),be=a.useCallback(C=>{const V=me.current[C];V&&(clearTimeout(V),delete me.current[C]),A(ie=>ie.filter(q=>q!==C))},[]),je=a.useCallback(async C=>{if(d){F(!0),se("");try{const V=await Tr(d,n,C);te(V.path),D(V.path),H(V.directories)}catch(V){se(V instanceof Error?V.message:"Could not load folder")}finally{F(!1)}}},[n,d]),Re=a.useCallback(()=>{var V;if(!d)return;U("__custom__"),xe(!0);const C=E.trim()||oe||s.defaultWorkspacePath||((V=s.workspaces[0])==null?void 0:V.path)||"~";je(C)},[E,je,s.defaultWorkspacePath,s.workspaces,oe,d]),Te=a.useCallback((C,V)=>{X.current=V,pe.current=C.selectedWorkspaceKey||"__home__",Z(C.selectedWorkspaceKey||"__home__"),ge(C)},[]),tt=a.useCallback(()=>{X.current&&(I(!0),X.current().finally(()=>{X.current=null,I(!1),ge(null)}))},[]),Oe=a.useCallback(C=>{if(!C)return;A(ie=>ie.includes(C)?ie:[...ie,C]);const V=me.current[C];V&&clearTimeout(V),me.current[C]=setTimeout(()=>{A(ie=>ie.filter(q=>q!==C)),delete me.current[C]},2e4)},[]);a.useEffect(()=>{for(const C of i)Ue(C.status)!=="stopped"&&be(C.type)},[i,be]),a.useEffect(()=>()=>{Object.values(me.current).forEach(clearTimeout),me.current={}},[]);const[Le,Ee]=a.useState({}),[Ve,ne]=a.useState(null);a.useEffect(()=>{if(!M||!n||!d)return;(async()=>{try{const V=await d(n,"get_ide_extensions",{}),ie=(V==null?void 0:V.result)||V;ie!=null&&ie.success&&(ie!=null&&ie.ideExtensions)&&Ee(ie.ideExtensions)}catch{}})()},[M,n,d]);const we=C=>M?Ie(C.type):t==="cli"?C.cliName:C.acpName,ye=M?s.detectedIdes||[]:[],he=a.useCallback(async C=>{const V=(C==null?void 0:C.type)||R,ie=(C==null?void 0:C.workspacePath)??oe;if(M){await m(V,ie?{workspace:ie}:void 0)&&Oe(V);return}const q=await c.runLaunchCliCore({cliType:V,dir:C!=null&&C.workspaceId?void 0:ie||void 0,workspaceId:(C==null?void 0:C.workspaceId)||void 0,useHome:(C==null?void 0:C.useHome)||!(C!=null&&C.workspaceId)&&!ie,argsStr:(C==null?void 0:C.argsStr)??(P||void 0),model:(C==null?void 0:C.model)??(N&&S||void 0)});q.success&&(Oe(V),q.sessionId&&T(q.sessionId))},[c,m,N,M,P,S,Oe,T,oe,R]),He=()=>{const C=M?Ie(R):B.get(R)||R,{options:V,selectedKey:ie}=xt({machine:s,currentWorkspaceId:L&&L!=="__custom__"?L:null,currentWorkspacePath:oe});Te({title:`Launch ${C}?`,description:"Review the provider and target folder before starting this session.",confirmLabel:"Launch",workspaceOptions:V,selectedWorkspaceKey:ie,details:[{label:"Mode",value:b.label},{label:"Provider",value:C},...!M&&P.trim()?[{label:"Arguments",value:P.trim()}]:[],...N&&S.trim()?[{label:"Model",value:S.trim()}]:[]]},async()=>{const q=V.find(de=>de.key===pe.current);q!=null&&q.workspaceId?(U(q.workspaceId),D("")):q!=null&&q.workspacePath?(U("__custom__"),D(q.workspacePath)):(U(""),D("")),await he({workspaceId:(q==null?void 0:q.workspaceId)??null,workspacePath:(q==null?void 0:q.workspacePath)??"",useHome:!(q!=null&&q.workspaceId)&&!(q!=null&&q.workspacePath)})})},K=C=>{M?g(C):h(C.type,C.workspace,C.id)},z=a.useCallback(async(C,V,ie=!1)=>{if(C.mode===V){ie&&C.sessionId&&T(C.sessionId);return}if(!d||!C.sessionId){ie&&C.sessionId&&T(C.sessionId);return}try{await d(n,"set_cli_view_mode",{targetSessionId:C.sessionId,cliType:C.type,mode:V}),ie&&T(C.sessionId)}catch(q){console.error("Failed to switch CLI view mode:",q)}},[n,T,d]),re=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:L,onChange:C=>{const V=C.target.value;if(U(V),V==="__custom__"&&d){Re();return}V!=="__custom__"&&D("")},className:"px-3 py-1.5 rounded-md min-w-[200px] flex-1 text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors",children:(s.workspaces||[]).length>0?e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspace — launch in home)"}),(s.workspaces||[]).map(C=>e.jsxs("option",{value:C.id,children:[C.id===s.defaultWorkspaceId?"⭐ ":"",tr(C.path,C.label)]},C.id)),e.jsx("option",{value:"__custom__",children:d?"📁 Select workspace…":"✏️ 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:d?"📁 Select workspace…":"✏️ Custom path…"})]})}),L==="__custom__"&&(d?e.jsx("button",{type:"button",className:"px-3 py-1.5 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] hover:border-accent-primary text-text-secondary hover:text-text-primary transition-colors",onClick:Re,children:"Select workspace…"}):e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:E,onChange:C=>D(C.target.value),className:"px-3 py-1.5 rounded-md flex-1 min-w-[200px] text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors",autoFocus:!0}))]}),e.jsx("div",{className:"mt-1.5 text-[10px] text-text-muted",children:L==="__custom__"?oe?e.jsx("span",{className:"font-mono truncate block",title:oe,children:oe}):d?"Browse to a folder before launching there.":"Enter an absolute path to launch there.":oe?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:L===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:oe,children:oe})]}):"No workspace selected. This launches in the home directory."})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-5 rounded-xl mb-6 bg-bg-secondary border ${b.accent} relative overflow-hidden`,children:[e.jsx("div",{className:"absolute top-0 left-0 w-full height-[1px] bg-gradient-to-r from-transparent via-[#ffffff20] to-transparent"}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-accent-primary/60"}),"Select ",b.label," to Launch"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:M?ye.length>0?ye.map(C=>{const V=i.find(Se=>(Se.type||"").toLowerCase()===(C.type||"").toLowerCase()&&Ue(Se.status)!=="stopped"),ie=C.running||!!V,q=!!V&&V.cdpConnected,de=O.includes(C.type||C.id||""),G=R===(C.type||"");return e.jsxs("button",{onClick:()=>{if(q&&V){const Se=V.sessionId;Se?u(`/dashboard?activeTab=${encodeURIComponent(Se)}`,{state:{openRemoteForTabKey:Se}}):u("/dashboard",{state:{openRemoteForTabKey:V.id}});return}de||$(Se=>Se===(C.type||"")?"":C.type||"")},disabled:!!j||de,className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${q?"bg-green-500/10 border-green-500/20 hover:bg-green-500/20":G?"bg-accent-primary/10 border-accent-primary scale-[1.02] shadow-glow":"bg-bg-primary border-[#ffffff1a] hover:bg-[#ffffff0c] hover:border-[#ffffff30]"}`,style:{opacity:j&&j!==C.type?.4:1},children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"text-2xl drop-shadow-sm transition-transform group-hover:scale-110 block",children:o(C.type)}),ie&&e.jsx("span",{className:`absolute -top-1 -right-1 w-2 h-2 rounded-full ${q?"bg-green-500 shadow-[0_0_6px_rgba(34,197,94,0.6)]":"bg-orange-500 shadow-[0_0_6px_rgba(249,115,22,0.6)] animate-pulse"}`})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs font-semibold text-text-primary text-center",children:C.name||Ie(C.type)}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${q?"text-green-400":de?"text-orange-400":G?"text-accent-primary":"text-text-muted"}`,children:q?"Open Session":de?"Starting...":G?"Configure":"Select"})]})]},C.type)}):e.jsxs("div",{className:"col-span-full py-6 flex flex-col items-center justify-center bg-bg-primary/50 border border-dashed border-[#ffffff1a] rounded-xl text-xs text-text-muted italic gap-2",children:["No IDEs detected.",e.jsxs("button",{onClick:x,className:"btn bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary px-3 py-1.5 rounded-lg flex items-center gap-1.5",children:[e.jsx(Ra,{size:14})," Scan System"]})]}):k.length>0?k.map(C=>{const V=R===C.type,ie=O.includes(C.type),de=!!i.find(G=>G.type===C.type&&Ue(G.status)!=="stopped");return e.jsxs("button",{onClick:()=>$(G=>G===C.type?"":C.type),className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${V?"bg-accent-primary/10 border-accent-primary scale-[1.02] shadow-glow":"bg-bg-primary border-[#ffffff1a] hover:bg-[#ffffff0c] hover:border-[#ffffff30]"}`,children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"text-2xl drop-shadow-sm transition-transform group-hover:scale-110 block",children:C.icon}),de&&e.jsx("span",{className:"absolute -top-1 -right-1 w-2 h-2 rounded-full bg-green-500 shadow-[0_0_6px_rgba(34,197,94,0.6)]"})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs font-semibold text-text-primary text-center",children:C.displayName}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${ie?"text-orange-400":V?"text-accent-primary":"text-text-muted"}`,children:ie?"Starting...":V?"Configure":"Select"})]})]},C.type)}):e.jsxs("div",{className:"col-span-full py-6 text-center bg-bg-primary/50 border border-dashed border-[#ffffff1a] rounded-xl text-xs text-text-muted",children:["No ",t.toUpperCase()," providers available"]})}),R&&(M?ye.find(C=>C.type===R):k.find(C=>C.type===R))&&e.jsxs("div",{className:"mt-5 pt-5 border-t border-[#ffffff1a] flex flex-col gap-4 animate-in slide-in-from-top-2 fade-in duration-200",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center justify-between",children:[e.jsx("span",{children:"Launch Settings"}),e.jsx("span",{className:"text-accent-primary font-bold",children:M?Ie(R):B.get(R)||R})]}),re,!M&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[N&&e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Target Model"}),e.jsx("input",{type:"text",placeholder:"Leave empty for default",value:S,onChange:C=>W(C.target.value),className:"px-3 py-2 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors w-full"})]}),e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Startup Arguments"}),e.jsx("input",{type:"text",placeholder:"Optional flags...",value:P,onChange:C=>_(C.target.value),className:"px-3 py-2 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors w-full"})]})]}),e.jsx("div",{className:"flex justify-end mt-2",children:e.jsx("button",{onClick:He,disabled:!!v||!!j||O.includes(R),className:"btn btn-primary h-9 px-6 font-bold transition-all flex items-center gap-2 hover:shadow-glow hover:-translate-y-px",children:v===R||j===R?"⏳ Launching...":"▶ Launch"})})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length+O.filter(C=>!i.some(V=>V.type===C&&Ue(V.status)!=="stopped")).length,")"]}),i.length===0&&ae.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 ",b.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[ae.map(C=>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:o(C)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:M?Ie(C):B.get(C)||C}),e.jsx("div",{className:"text-[11px] text-text-muted",children:v===C?"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:${C}`)),i.map(C=>{const V=M?C:null,ie=N?C:null,q=!M&&!N?C:null,de=Ue(C.status);return e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:o(C.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[we(C),(V==null?void 0:V.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",V.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:C.workspace||"—"}),(ie==null?void 0:ie.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",ie.currentModel]}),(ie==null?void 0:ie.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",ie.currentPlan]}),(q==null?void 0:q.mode)&&e.jsx("span",{className:q.mode==="chat"?"text-violet-400":"text-text-secondary",children:q.mode==="chat"?"Chat view":"Terminal view"})]}),q&&(q.runtimeKey||q.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[q.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 ",q.runtimeKey]}),e.jsx("button",{type:"button",className:"flex items-center justify-center px-1.5 py-0.5 rounded text-[9px] bg-[#ffffff0a] hover:bg-[#ffffff14] border border-[#ffffff0a] text-text-muted hover:text-text-primary transition-colors cursor-pointer",onClick:()=>{var G;(G=navigator.clipboard)==null||G.writeText(`adhdev attach ${q.runtimeKey}`),w(q.runtimeKey||null),window.setTimeout(()=>{w(Se=>Se===q.runtimeKey?null:Se)},1200)},children:y===q.runtimeKey?"Copied":"Copy"})]}),q.runtimeWriteOwner&&e.jsx("span",{style:{color:q.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:q.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:Pc(q.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${de==="stopped"?"bg-red-500/[0.08] text-red-500":de==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:de}),M&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{const G=C.sessionId;if(G){u(`/dashboard?activeTab=${encodeURIComponent(G)}`,{state:{openRemoteForTabKey:G}});return}u("/dashboard",{state:{openRemoteForTabKey:C.id}})},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-primary transition-colors cursor-pointer",title:"Open remote control",children:e.jsx(ze,{size:13})}),e.jsx("button",{onClick:()=>{const G=C.workspace||"",{options:Se,selectedKey:Xe}=xt({machine:s,currentWorkspacePath:G});Te({title:`Restart ${Ie(C.type)}?`,description:"Review or change the target workspace before restarting this IDE.",confirmLabel:"Restart",workspaceOptions:Se,selectedWorkspaceKey:Xe,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:Ie(C.type)}]},async()=>{const Fe=Se.find(jt=>jt.key===pe.current),$e=(Fe==null?void 0:Fe.workspacePath)??"";if($e&&$e!==G){await he({type:C.type,workspacePath:$e});return}await p(C)})},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-orange-500/20 text-orange-400 transition-colors cursor-pointer",title:"Restart",children:e.jsx(Ds,{size:14})})]}),N&&e.jsx("button",{onClick:()=>{const G=C.sessionId;G&&T(G)},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] disabled:opacity-50 disabled:cursor-not-allowed text-text-primary transition-colors cursor-pointer",title:"View chat",disabled:!C.sessionId,children:e.jsx(ot,{size:14})}),q&&de!=="stopped"&&e.jsxs(e.Fragment,{children:[q.mode&&e.jsx(Os,{mode:q.mode,onChange:G=>void z(q,G,!1),compact:!0}),e.jsx("button",{onClick:()=>{const G=C.sessionId;G&&T(G)},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] disabled:opacity-50 disabled:cursor-not-allowed text-text-primary transition-colors cursor-pointer",title:"Open current view in dashboard",disabled:!C.sessionId,children:q.mode==="chat"?e.jsx(ot,{size:14}):e.jsx(ze,{size:13})})]}),de==="stopped"?e.jsx("button",{onClick:()=>{const G=C.workspace||"",Se=M?Ie(C.type):we(C),{options:Xe,selectedKey:Fe}=xt({machine:s,currentWorkspacePath:G});Te({title:`Launch ${Se}?`,description:"Review or change the target workspace before launching this stopped session again.",confirmLabel:"Launch",workspaceOptions:Xe,selectedWorkspaceKey:Fe,details:[{label:"Mode",value:b.label},{label:"Provider",value:Se}]},async()=>{const $e=Xe.find(jt=>jt.key===pe.current);await he({type:C.type,workspaceId:($e==null?void 0:$e.workspaceId)??null,workspacePath:($e==null?void 0:$e.workspacePath)??"",useHome:!($e!=null&&$e.workspaceId)&&!($e!=null&&$e.workspacePath),model:ie==null?void 0:ie.currentModel})})},disabled:O.includes(C.type),className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-green-500/20 text-green-400 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",title:"Restart",children:O.includes(C.type)?"⏳":e.jsx(Gn,{size:14})}):e.jsx("button",{onClick:()=>K(C),className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-red-500/20 text-red-400 transition-colors cursor-pointer",title:"Stop",children:e.jsx(yt,{size:14})})]})]}),V&&V.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:V.aiAgents.map(G=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${er(G.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[G.name," · ",Ue(G.status)]},G.id))}),V&&(Le[V.type]||[]).length>0&&d&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(Le[V.type]||[]).map(G=>e.jsxs("button",{disabled:Ve===`${V.type}.${G.type}`,onClick:async()=>{const Se=`${V.type}.${G.type}`;ne(Se);try{await d(n,"set_ide_extension",{ideType:V.type,extensionType:G.type,enabled:!G.enabled}),Ee(Xe=>({...Xe,[V.type]:(Xe[V.type]||[]).map(Fe=>Fe.type===G.type?{...Fe,enabled:!Fe.enabled}:Fe)}))}catch(Xe){console.error("Extension toggle failed:",Xe)}finally{ne(null)}},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium border transition-colors duration-150 cursor-pointer ${G.enabled?"bg-accent-primary/10 border-accent-primary/20 text-accent-primary-light":"bg-bg-glass border-border-subtle text-text-muted"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${G.enabled?"bg-accent-primary shadow-glow":"bg-zinc-600"}`}),G.name,e.jsx("span",{className:"text-[9px] font-normal",children:G.enabled?"ON":"OFF"})]},G.type))})]})]},C.id)})]}),Q&&d&&e.jsx(Fs,{title:"Select workspace",description:"Choose a folder in a regular explorer-style dialog, then use it as the launch target.",currentPath:ue,directories:ee,busy:Y,error:J,confirmLabel:"Use this folder",onClose:()=>xe(!1),onNavigate:C=>{je(C)},onConfirm:C=>{D(C),U("__custom__"),xe(!1)}}),le&&e.jsx(Vs,{title:le.title,description:le.description,details:le.details,workspaceOptions:le.workspaceOptions,selectedWorkspaceKey:ve,onWorkspaceChange:C=>{pe.current=C,Z(C)},confirmLabel:le.confirmLabel,busy:ce,onConfirm:tt,onCancel:()=>{X.current=null,ge(null)}})]})}const Rn=[{id:"ide",label:"IDE",helper:"Open a graphical workspace and attach CDP"},{id:"cli",label:"CLI",helper:"Launch a terminal-first workspace on this machine"},{id:"acp",label:"ACP",helper:"Launch an ACP-backed workspace on this machine"}];function $c({machine:t,machineId:s,providers:n,ideSessions:r,cliSessions:i,acpSessions:o,actions:c,getIcon:d,initialCategory:l="ide",initialWorkspaceId:f,initialWorkspacePath:u,sendDaemonCommand:m}){var x;const[h,p]=a.useState(l);a.useEffect(()=>{p(l)},[l]);const g=a.useMemo(()=>({ide:r.length,cli:i.length,acp:o.length}),[r.length,i.length,o.length]);return e.jsxs("div",{className:"flex flex-col flex-1 min-w-0 h-full",children:[e.jsxs("div",{className:"flex flex-col gap-1 pb-4 border-b border-[#ffffff0a] mb-4",children:[e.jsx("div",{className:"text-lg font-semibold text-text-primary",children:"Workspace Launcher"}),e.jsx("div",{className:"text-sm text-text-secondary",children:"Choose a workspace context first, then pick how you want to open it."})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-baseline gap-4 mb-4",children:[e.jsx("div",{className:"flex bg-bg-surface p-1 rounded-lg border border-[#ffffff0a] w-fit",children:Rn.map(j=>e.jsxs("button",{type:"button",className:`flex items-center gap-2 px-4 py-1.5 rounded-md text-sm font-medium transition-all ${h===j.id?"bg-[#ffffff10] text-text-primary shadow-sm":"text-text-secondary hover:text-text-primary hover:bg-[#ffffff05]"}`,onClick:()=>p(j.id),children:[e.jsx("span",{children:j.label}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ${h===j.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:g[j.id]})]},j.id))}),e.jsx("div",{className:"text-xs text-text-muted italic",children:(x=Rn.find(j=>j.id===h))==null?void 0:x.helper})]}),h==="ide"&&e.jsx(Ss,{category:"ide",machine:t,machineId:s,providers:n,managedEntries:r,getIcon:d,actions:c,sendDaemonCommand:m,initialWorkspaceId:f,initialWorkspacePath:u}),h==="cli"&&e.jsx(Ss,{category:"cli",machine:t,machineId:s,providers:n,managedEntries:i,getIcon:d,actions:c,sendDaemonCommand:m,initialWorkspaceId:f,initialWorkspacePath:u}),h==="acp"&&e.jsx(Ss,{category:"acp",machine:t,machineId:s,providers:n,managedEntries:o,getIcon:d,actions:c,sendDaemonCommand:m,initialWorkspaceId:f,initialWorkspacePath:u})]})}function Dc({onNicknameSynced:t}={}){var J,se,X,le,ge,pe,ve,Z,ce;const{id:s}=fa(),n=wt(),r=Ps(),{sendCommand:i}=ct(),o=Ws(),c=o.ides||[],d=o.initialLoaded??!0,l=c.find(I=>I.id===s&&I.daemonMode),f=c.some(I=>I.type==="adhdev-daemon"),[u,m]=a.useState("workspace"),[h,p]=a.useState("ide"),g=a.useRef(null),[x,j]=a.useState(null),v=a.useRef("__home__"),[y,w]=a.useState("__home__"),[T,b]=a.useState(!1),M=a.useRef(null),N=()=>{if(f){n("/dashboard",{state:{mobileSection:"machines"}});return}n("/machines")},k=Sc({machineId:s,registeredMachineId:(l==null?void 0:l.machineId)||null,sendDaemonCommand:i,onNicknameSynced:t,logsEndRef:M});a.useEffect(()=>at.onToast(ae=>{o.setToasts(oe=>{if(oe.some(Re=>Re.message===ae.message&&ae.timestamp-Re.timestamp<3e3))return oe;const je={id:ae.id,message:ae.message,type:ae.type,timestamp:ae.timestamp,targetKey:ae.targetKey,actions:ae.actions};return[...oe.slice(-4),je]});const me=ae.duration||5e3;setTimeout(()=>o.setToasts(oe=>oe.filter(be=>be.id!==ae.id)),me)}),[o]);const B=(l==null?void 0:l.availableProviders)||[],R={};for(const I of B)R[I.type]=I.icon;const $=I=>R[I]||"",P=l?{id:l.id,hostname:sr(l,{fallbackId:l.id}),platform:((J=l.machine)==null?void 0:J.platform)||"unknown",arch:((se=l.machine)==null?void 0:se.arch)||"",cpus:((X=l.machine)==null?void 0:X.cpus)||0,totalMem:((le=l.machine)==null?void 0:le.totalMem)||0,freeMem:((ge=l.machine)==null?void 0:ge.freeMem)||0,availableMem:(pe=l.machine)==null?void 0:pe.availableMem,loadavg:((ve=l.machine)==null?void 0:ve.loadavg)||[],uptime:((Z=l.machine)==null?void 0:Z.uptime)||0,release:((ce=l.machine)==null?void 0:ce.release)||"",cdpConnected:!!l.cdpConnected,machineNickname:l.machineNickname||null,p2p:l.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:l.detectedIdes||[],workspaces:l.workspaces||[],defaultWorkspaceId:l.defaultWorkspaceId??l.activeWorkspaceId??null,defaultWorkspacePath:l.defaultWorkspacePath??l.activeWorkspacePath??null}:null,_=c.filter(I=>I.daemonId===s&&!I.daemonMode).filter(I=>!es(I)&&!Ct(I)).map(I=>({id:I.id,sessionId:I.sessionId,type:I.type,version:I.version||"",instanceId:I.instanceId||"",status:I.status,workspace:I.workspace||null,terminals:I.terminals||0,aiAgents:mi(I.aiAgents||I.agents||[]),activeChat:I.activeChat||null,chats:I.chats||[],childSessions:I.childSessions||[],cdpConnected:I.cdpConnected||!1,daemonId:s})),S=c.filter(I=>I.daemonId===s&&es(I)).map(I=>({id:I.id,sessionId:I.sessionId,type:I.type,cliName:I.cliName||I.type,status:I.status,workspace:I.workspace||"",activeChat:I.activeChat||null,providerSessionId:I.providerSessionId,mode:I.mode,daemonId:s})),W=c.filter(I=>I.daemonId===s&&Ct(I)).map(I=>({id:I.id,sessionId:I.sessionId,type:I.type,acpName:I.cliName||I.type,status:I.status,workspace:I.workspace||"",activeChat:I.activeChat||null,providerSessionId:I.providerSessionId,currentModel:I.currentModel,currentPlan:I.currentPlan,daemonId:s}));if(!P)return d?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,className:"machine-btn-back",children:"← Back"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const L=et(l,{fallbackId:P.id}),U="workspace",E=r.state,D=E==null?void 0:E.initialMachineTab,O=E==null?void 0:E.initialWorkspaceCategory,A=E==null?void 0:E.initialWorkspaceId,Q=E==null?void 0:E.initialWorkspacePath,xe=D==="ides"||D==="clis"||D==="acps"?"workspace":D||U,ue=D==="ides"?"ide":D==="clis"?"cli":D==="acps"?"acp":O,te=[..._.map(I=>{var ae,me,oe,be,je;return{id:`ide:${I.type}:${I.workspace||""}`,label:((ae=I.activeChat)==null?void 0:ae.title)||I.type,kind:"ide",providerType:I.type,subtitle:I.workspace||void 0,workspace:I.workspace||void 0,timestamp:((je=(be=(oe=(me=I.activeChat)==null?void 0:me.messages)==null?void 0:oe.at)==null?void 0:be.call(oe,-1))==null?void 0:je.timestamp)||0}}),...S.map(I=>{var ae,me,oe,be,je;return{id:`cli:${I.type}:${I.workspace||""}`,label:((ae=I.activeChat)==null?void 0:ae.title)||I.cliName,kind:"cli",providerType:I.type,providerSessionId:I.providerSessionId,subtitle:I.workspace||void 0,workspace:I.workspace||void 0,timestamp:((je=(be=(oe=(me=I.activeChat)==null?void 0:me.messages)==null?void 0:oe.at)==null?void 0:be.call(oe,-1))==null?void 0:je.timestamp)||0}}),...W.map(I=>{var ae,me,oe,be,je;return{id:`acp:${I.type}:${I.workspace||""}`,label:((ae=I.activeChat)==null?void 0:ae.title)||I.acpName,kind:"acp",providerType:I.type,providerSessionId:I.providerSessionId,subtitle:I.currentModel||I.workspace||void 0,workspace:I.workspace||void 0,currentModel:I.currentModel,timestamp:((je=(be=(oe=(me=I.activeChat)==null?void 0:me.messages)==null?void 0:oe.at)==null?void 0:be.call(oe,-1))==null?void 0:je.timestamp)||0}})].sort((I,ae)=>ae.timestamp-I.timestamp).map(({timestamp:I,...ae})=>ae),ee=(l.recentLaunches||[]).length>0?l.recentLaunches.map(I=>({id:I.id,label:I.title||I.providerName||I.providerType,kind:I.kind,providerType:I.providerType,providerSessionId:I.providerSessionId,subtitle:I.currentModel||I.workspace||void 0,workspace:I.workspace,currentModel:I.currentModel})):te,H=a.useCallback(()=>{g.current&&(b(!0),g.current().finally(()=>{g.current=null,b(!1),j(null)}))},[]),Y=a.useCallback(I=>{const{options:ae,selectedKey:me}=xt({machine:P,currentWorkspacePath:I.workspace}),oe=async()=>{p(I.kind),m("workspace")};g.current=async()=>{const be=ae.find(Te=>Te.key===v.current),je=(be==null?void 0:be.workspacePath)??null,Re=(be==null?void 0:be.workspaceId)??null;if(I.kind==="ide"&&I.providerType){await k.handleLaunchIde(I.providerType,je?{workspace:je}:void 0);return}if((I.kind==="cli"||I.kind==="acp")&&I.providerType){await k.runLaunchCliCore({cliType:I.providerType,dir:Re?void 0:je||"",workspaceId:Re||void 0,model:I.kind==="acp"?I.currentModel:void 0,resumeSessionId:I.providerSessionId});return}await oe()},v.current=me,w(me),j({title:`Launch ${I.label}?`,description:"Recent launches now require one more confirmation before they start.",confirmLabel:"Launch",workspaceOptions:ae,details:[{label:"Mode",value:I.kind.toUpperCase()},...I.providerType?[{label:"Provider",value:I.providerType}]:[]]})},[k,P]);a.useEffect(()=>{m(xe)},[U,xe,P.id]),a.useEffect(()=>{ue&&p(ue)},[ue,P.id]);const F=[{id:"workspace",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ze,{size:14})," Workspace"]}),count:_.length+S.length+W.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(os,{size:14})," Providers"]})},{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(La,{size:14})," System"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_a,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex flex-col w-full bg-bg-surface px-4 md:px-8 pt-6 pb-0 shrink-0 border-b border-[#ffffff0a]",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-3 w-full min-w-0",children:[e.jsx("button",{onClick:N,className:"flex items-center justify-center w-8 h-8 rounded-full bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary transition-colors shrink-0",children:"←"}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[k.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:k.nicknameInput,onChange:I=>k.setNicknameInput(I.target.value),onKeyDown:I=>{I.key==="Enter"&&k.handleSaveNickname(),I.key==="Escape"&&k.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:k.handleSaveNickname,className:"flex items-center justify-center px-3 py-1 rounded bg-green-500/20 text-green-400 hover:bg-green-500/30 text-sm font-medium transition-colors",children:"Save"}),e.jsx("button",{onClick:()=>k.setEditingNickname(!1),className:"flex items-center justify-center px-3 py-1 rounded bg-[#ffffff0a] text-text-muted hover:bg-[#ffffff14] hover:text-text-primary text-sm font-medium transition-colors",children:"Cancel"})]}):e.jsx("h1",{className:"text-xl md:text-2xl font-bold text-text-primary cursor-pointer truncate hover:text-accent-primary transition-colors",onClick:()=>{k.setEditingNickname(!0),k.setNicknameInput(P.machineNickname||"")},title:"Click to set nickname",children:L}),e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-green-500 shadow-[0_0_8px_rgba(34,197,94,0.6)] shrink-0"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-1 items-center mt-1.5 text-xs text-text-secondary opacity-80",children:[e.jsxs("span",{className:"font-mono bg-[#ffffff08] px-1.5 py-0.5 rounded",children:[P.platform," · ",P.arch]}),e.jsxs("span",{children:[P.cpus," cores"]}),(l==null?void 0:l.version)&&e.jsxs("span",{children:["v",l.version]}),P.p2p.available&&e.jsxs("span",{children:["P2P ",P.p2p.state==="connected"?"connected":P.p2p.state]}),P.machineNickname&&e.jsx("span",{className:"text-text-muted opacity-60 shrink-0",children:P.hostname})]})]})]})}),e.jsx("div",{className:"flex overflow-x-auto overflow-y-hidden mt-4 gap-6 px-1 border-b border-[#ffffff0a]",children:F.map(I=>e.jsxs("button",{onClick:()=>m(I.id),className:`pb-3 text-sm font-medium border-b-2 transition-colors flex items-center gap-2 px-1 whitespace-nowrap ${u===I.id?"border-accent-primary text-accent-primary":"border-transparent text-text-secondary hover:text-text-primary"}`,children:[I.label,I.count!==void 0&&e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ml-1 ${u===I.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:I.count})]},I.id))})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 md:px-8 py-6",children:e.jsx("div",{className:"max-w-7xl mx-auto h-full",children:e.jsxs("div",{className:"h-full",children:[u==="workspace"&&e.jsxs("div",{className:"flex flex-col md:flex-row gap-6 md:gap-10 h-full",children:[e.jsx(Lc,{machineEntry:l,providers:B,recentLaunches:ee,onUpgradeDaemon:async()=>{try{await i(s,"daemon_upgrade",{})}catch{}},onOpenLogs:()=>m("logs"),onOpenRecent:Y,onOpenWorkspace:I=>{p(I),m("workspace")},onGoTab:m}),e.jsx($c,{machine:P,machineId:s,providers:B,ideSessions:_,cliSessions:S,acpSessions:W,actions:k,getIcon:$,initialCategory:h,initialWorkspaceId:A,initialWorkspacePath:Q,sendDaemonCommand:i})]}),u==="providers"&&e.jsx(_c,{machineId:s,providers:B,sendDaemonCommand:i}),u==="overview"&&e.jsx(Cc,{machineId:s,machine:P,ideSessions:_,cliSessions:S,acpSessions:W,actions:k,sendDaemonCommand:i}),u==="logs"&&e.jsx(Rc,{machineId:s,sendDaemonCommand:i})]})})}),k.launchPick&&P&&e.jsx(Ac,{machine:P,launchPick:k.launchPick,actions:k}),x&&e.jsx(Vs,{title:x.title,description:x.description,details:x.details,workspaceOptions:x.workspaceOptions,selectedWorkspaceKey:y,onWorkspaceChange:I=>{v.current=I,w(I)},confirmLabel:x.confirmLabel,busy:T,onConfirm:H,onCancel:()=>{g.current=null,j(null)}}),e.jsx(or,{toasts:o.toasts||[],onDismiss:I=>o.setToasts(ae=>ae.filter(me=>me.id!==I)),onClickToast:I=>{I.targetKey}}),e.jsx("style",{children:`
|
|
58
|
-
@keyframes toast-in {
|
|
59
|
-
from { opacity: 0; transform: translateX(40px); }
|
|
60
|
-
to { opacity: 1; transform: translateX(0); }
|
|
61
|
-
}
|
|
62
|
-
`})]})}function Bc(){const[t,s]=a.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=a.useState(!0);a.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const d=[],l=[],f=[],u=[];Object.values(c.providers||{}).forEach(h=>{const p={name:h.name||"Unknown",status:h.status||"Stable",details:h.details||"Community Provider"};h.category==="ide"?d.push(p):h.category==="cli"?l.push(p):h.category==="extension"?f.push(p):h.category==="acp"&&u.push(p)});const m=(h,p)=>{const g={Stable:1,Beta:2,WIP:3},x=g[h.status]||99,j=g[p.status]||99;return x!==j?x-j:h.name.localeCompare(p.name)};s({ide:d.sort(m),cli:l.sort(m),ext:f.sort(m),acp:u.sort(m)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>r(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Fn,{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(Bs,{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(qn,{className:"w-4 h-4"})," ",e.jsx("span",{children:c})]}),o=c=>e.jsx("div",{className:"bg-bg-card border border-border-subtle rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary border-b border-border-subtle text-xs uppercase text-text-muted font-medium tracking-wider",children:[e.jsx("th",{className:"py-3 px-4 w-1/3",children:"Target"}),e.jsx("th",{className:"py-3 px-4 w-1/4",children:"Status"}),e.jsx("th",{className:"py-3 px-4",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-border-subtle text-sm",children:c.map((d,l)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:d.name}),e.jsx("td",{className:"py-3 px-4",children:i(d.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:d.details})]},l))})]})});return n?e.jsx(ss,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Qt,{}),widthClassName:"max-w-5xl",children:e.jsx(zs,{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(ss,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Qt,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(We,{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(We,{title:"IDE support",icon:e.jsx(ze,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(We,{title:"Standalone CLI agents",icon:e.jsx(Ks,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(We,{title:"AI extensions",icon:e.jsx(gt,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(We,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(gt,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class Kc{constructor(){Be(this,"adapters",new Map);Be(this,"states",new Map);Be(this,"runtimeListeners",new Map);Be(this,"screenshotCallbacks",new Map);Be(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const n of this.adapters.keys())if(n.startsWith("standalone"))return n}return null}register(s,n){this.adapters.set(s,n),this.states.set(s,n.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,n){this.states.set(s,n)}retryConnection(s){}get(s){const n=this.resolveDaemonId(s);return n?this.adapters.get(n):void 0}getState(s){const n=this.resolveDaemonId(s);return n&&this.states.get(n)||"disconnected"}sendData(s,n){return!1}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,i){return!1}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))}emitRuntimeSnapshot(s,n,r=0,i=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:r,text:n,truncated:i})}emitSessionOutput(s,n,r){!s||typeof n!="string"||!n||this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,...typeof r=="number"?{seq:r}:{},data:n})}onRuntimeEvent(s,n){const r=this.runtimeListeners.get(s)||new Set;return r.add(n),this.runtimeListeners.set(s,r),()=>{const i=this.runtimeListeners.get(s);i&&(i.delete(n),i.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 i=await r.json();this.emitRuntimeEvent(n,{type:"runtime_snapshot",sessionId:n,seq:typeof i.seq=="number"?i.seq:0,text:typeof i.text=="string"?i.text:"",truncated:!!i.truncated,cols:typeof i.cols=="number"?i.cols:void 0,rows:typeof i.rows=="number"?i.rows:void 0})}emitRuntimeEvent(s,n){var r;(r=this.runtimeListeners.get(s))==null||r.forEach(i=>i(n))}}const st=new Kc;function Wc(){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 An=Wc(),Ln=3e3,Oc=3e4;let nt=null,zc=0;const is=new Map;let dt=null,_t=null;function Pn(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function Uc(t){return t==="connected"?"connected":t}async function Zt(t,s,n){const r=$i(t,n||{}),i=nt;if(i&&i.readyState===WebSocket.OPEN){const o=`req_${++zc}_${Date.now()}`;return new Promise((c,d)=>{const l=setTimeout(()=>{is.delete(o),d(new Error(`WS command timeout: ${s}`))},3e4);is.set(o,{resolve:f=>{clearTimeout(l),c(f)},reject:f=>{clearTimeout(l),d(f)}}),i.send(JSON.stringify({type:"command",requestId:o,data:{type:s,payload:r.payload}}))})}throw new Error(`WS command channel unavailable: ${s}`)}class Hc{constructor(s){Be(this,"daemonId");Be(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(nt==null?void 0:nt.readyState)===WebSocket.OPEN}get connectionState(){return(nt==null?void 0:nt.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return Zt(this.daemonId,s,n)}async sendInput(s,n){return Zt(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,dt&&(clearInterval(dt),dt=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await Zt(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const i=await fetch(`data:image/jpeg;base64,${r.base64}`).then(o=>o.blob());st.emitScreenshot(this.daemonId,i)}}catch{}};n(),dt=setInterval(n,2e3)}stopScreenshots(s){dt&&(clearInterval(dt),dt=null)}}let Ye=null;function Fc(t){return(!Ye||Ye.daemonId!==t)&&(Ye=new Hc(t)),Ye}function Vc({children:t}){const s=a.useRef(sn()),n=sn();s.current=n;const{setUserName:r}=Rt(),i=a.useRef(r);i.current=r;const[,o]=a.useState("disconnected"),c=a.useCallback((h,p)=>{o(h),_t==null||_t(h,p)},[]),d=a.useRef(null),l=a.useRef(),f=a.useRef(Ln),u=a.useRef(!0),m=a.useRef(!1);return a.useEffect(()=>{u.current=!0,m.current=!1;function h(){var x,j;if(!u.current||((x=d.current)==null?void 0:x.readyState)===WebSocket.OPEN||((j=d.current)==null?void 0:j.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${An}...`);let g;try{g=new WebSocket(An)}catch(v){console.error("[Standalone WS] Failed to create WebSocket:",v),p();return}d.current=g,g.onopen=()=>{if(!u.current){g.close();return}c("connected"),f.current=Ln,console.log("[Standalone WS] Connected")},nt=g,g.onmessage=v=>{var y;try{const w=JSON.parse(v.data);if((w.type==="command_result"||w.type==="error")&&w.requestId){const T=is.get(w.requestId);T&&(is.delete(w.requestId),w.type==="error"?T.reject(new Error(((y=w.data)==null?void 0:y.message)||"Command failed")):T.resolve(w.data));return}if(w.type==="session_output"){const T=w.sessionId||w.cliId||w.cliType;T&&st.emitSessionOutput(T,typeof w.data=="string"?w.data:"",typeof w.seq=="number"?w.seq:void 0);return}if(w.type==="runtime_snapshot"){st.emitRuntimeSnapshot(w.sessionId,typeof w.text=="string"?w.text:"",typeof w.seq=="number"?w.seq:0,!!w.truncated);return}if(w.type==="status"||w.type==="initial_state"){const T=w.data;if(!T)return;const{injectEntries:b,markLoaded:M}=s.current,N=T.id||"standalone",k=Fc(N);st.register(N,k),st.setState(N,"connected"),c("connected",N),st.emitStatus(N,T);const B=Pi(T,{daemonId:N});Pn("ws_status",{type:w.type,daemonId:N,sessions:(T.sessions||[]).map(R=>({id:R.id,parentId:R.parentId,providerType:R.providerType,kind:R.kind,transport:R.transport,unread:R.unread,inboxBucket:R.inboxBucket,lastSeenAt:R.lastSeenAt,lastUpdated:R.lastUpdated,title:R.title})),recentLaunches:(T.recentLaunches||[]).map(R=>({id:R.id,providerType:R.providerType,kind:R.kind,workspace:R.workspace,lastLaunchedAt:R.lastLaunchedAt}))}),Pn("entries",{daemonId:N,entries:B.filter(R=>R.type!=="adhdev-daemon").map(R=>({id:R.id,type:R.type,unread:R.unread,inboxBucket:R.inboxBucket,lastSeenAt:R.lastSeenAt,lastUpdated:R.lastUpdated,sessionId:R.sessionId}))}),B.length>0&&b(B,{authoritativeDaemonIds:[N]}),M(),T.userName&&i.current&&i.current(T.userName)}}catch(w){console.error("[Standalone WS] Parse error:",w)}},g.onclose=()=>{u.current&&(Ye==null||Ye.stopScreenshots(),Ye&&st.setState(Ye.daemonId,"disconnected"),c("disconnected"),d.current=null,p())},g.onerror=v=>{m.current||!u.current||console.warn("[Standalone WS] Error, will reconnect:",v)}}function p(){if(!u.current)return;clearTimeout(l.current);const g=f.current;console.log(`[Standalone WS] Reconnecting in ${g}ms...`),l.current=setTimeout(()=>{f.current=Math.min(f.current*1.5,Oc),h()},g)}return h(),()=>{u.current=!1,m.current=!0,clearTimeout(l.current),d.current&&(d.current.onerror=null,d.current.onclose=null,d.current.close(),d.current=null,nt=null),Ye&&(Ye.stopScreenshots(),st.unregister(Ye.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function qc({children:t}){const[s,n]=a.useState("disconnected"),[r,i]=a.useState(null);a.useEffect(()=>(_t=(c,d)=>{n(c),d&&i(d)},()=>{_t=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",d=Uc(s),l={};return r&&(l[r]=d),l.standalone=d,{wsStatus:s,isConnected:c,connectionStates:l}},[s,r]);return e.jsx(ja,{connectionOverrides:o,children:e.jsx(Vc,{children:t})})}const Gc=[{id:"dashboard",path:"/dashboard",icon:e.jsx(zn,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Jt,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(os,{}),label:"Settings"}];function Yc({children:t}){const s=wt(),n=Ps(),[r,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),d=u=>{s(u),i(!1)},l=()=>{c(u=>{const m=!u;try{localStorage.setItem("sidebar-collapsed",m?"1":"0")}catch{}return m})},f=u=>`nav-item${n.pathname.startsWith(u)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${o?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:u=>u.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${o?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!o&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Gc.map(u=>e.jsxs("div",{className:f(u.path),id:`nav-${u.id}`,onClick:()=>d(u.path),title:o?u.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:u.icon}),!o&&u.label]},u.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:o?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Qt,{})}),!o&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${n.pathname==="/about"?" active":""} ${o?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:o?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Hn,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.3"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,title:o?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:o?"›":"‹"}),!o&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})]})]}),e.jsx("main",{className:"main-content relative",children:e.jsx("div",{className:"main-content-inner",children:t})})]})}const Xc=[{icon:e.jsx(Jt,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(ot,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Vn,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(ze,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(gt,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Qt,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Zc=[{icon:e.jsx(Yn,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(zn,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(cs,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Ta,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Ma,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Fn,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Jc=[{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 Qc(){return e.jsxs(ss,{icon:e.jsx(Hn,{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.8.3"]}),children:[e.jsx(We,{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(We,{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:Xc.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-bg-secondary text-text-secondary border border-border-subtle",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(We,{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:ur.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:xr.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:pr.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(We,{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:Zc.map(t=>e.jsxs("div",{className:"rounded-xl border border-accent-primary/20 bg-accent-primary/5 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-accent-primary/10 text-accent-primary",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(We,{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-accent-primary text-[11px] uppercase tracking-wider w-[110px]",children:"Cloud"})]})}),e.jsx("tbody",{children:Jc.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(zs,{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(Wa,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function el(){const{ides:t}=Rt(),s=t.find(m=>m.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=ct(),{userName:i}=Rt(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const d=m=>{const h=m.target.value.trim();s!=null&&s.id&&h!==i&&r(s.id,"set_user_name",{userName:h}).catch(console.error)},[l,f]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),u=m=>{f(m);try{localStorage.setItem("adhdev_sound",m?"1":"0")}catch{}};return e.jsxs(ss,{icon:e.jsx(os,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(Zi,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(We,{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.8.3"]}),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(We,{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(m=>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 ${m.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:m.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:m.type})]},m.type))})}),e.jsx(We,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(ro,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(We,{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(co,{})]}),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(fo,{})]}),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:"Mobile"}),e.jsx("p",{className:"text-[11px] text-text-muted mb-3",children:"Choose whether phones open the dashboard as a chat app first or in the full workspace layout."}),e.jsx(bo,{})]})]})}),e.jsx(We,{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(no,{}),e.jsx(it,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ka,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:u})]})}),e.jsx(We,{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(Un,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:o,onChange:m=>c(m.target.value),onBlur:d,onKeyDown:m=>{m.key==="Enter"&&m.currentTarget.blur()}})]})})})]})}so();xo();const tl=Wn({baseUrl:""});function En(){const{ides:t,initialLoaded:s}=Rt();if(!s)return e.jsx("div",{className:"p-10 text-center text-text-muted",children:"⏳ Loading machine..."});const n=t.find(r=>r.daemonMode||r.type==="adhdev-daemon");return n?e.jsx(Cs,{to:`/machines/${n.id}`,replace:!0}):e.jsx(Cs,{to:"/dashboard",replace:!0})}function sl(){return e.jsx(ha,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Sa,{client:tl,children:e.jsx(qc,{children:e.jsx(Ia,{value:{sendCommand:Zt,sendData:()=>!1},children:e.jsx(Yc,{children:e.jsxs(ba,{children:[e.jsx(rt,{path:"/dashboard",element:e.jsx(Nc,{})}),e.jsx(rt,{path:"/machine",element:e.jsx(En,{})}),e.jsx(rt,{path:"/machines/:id",element:e.jsx(Dc,{})}),e.jsx(rt,{path:"/machines",element:e.jsx(En,{})}),e.jsx(rt,{path:"/capabilities",element:e.jsx(Bc,{})}),e.jsx(rt,{path:"/about",element:e.jsx(Qc,{})}),e.jsx(rt,{path:"/settings",element:e.jsx(el,{})}),e.jsx(rt,{path:"*",element:e.jsx(Cs,{to:"/dashboard",replace:!0})})]})})})})})})}ki({connectionManager:st});ga(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(sl,{})}));
|