@adhdev/daemon-standalone 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,14 +1,14 @@
|
|
|
1
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 Xr=Object.defineProperty;var Jr=(t,s,n)=>s in t?Xr(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Ce=(t,s,n)=>Jr(t,typeof s!="symbol"?s+"":s,n);import{r as a,j as e,M as Mn,a as Tn,b as Zr,c as Qr,u as mt,R as Is,t as ea,d as ta,e as sa,D as na,f as ra,g as aa,h as Ms,i as ia,k as oa,B as ca,l as la,m as Ze,N as ys,n as da}from"./vendor-CPghmr9Y.js";import{_ as ua}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 An=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}),Rn=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function Gs(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 ls(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 xa(t,s,n){var l,f,x,m,h,u,b;const r=Date.now(),i=new Set((n==null?void 0:n.authoritativeDaemonIds)||[]);if(s.length===0)return t.map(p=>({...p,_lastUpdate:r}));const o=new Map;for(const p of s)o.set(p.id,p);for(const p of t){const w=o.get(p.id);if(!w){o.set(p.id,{...p,_lastUpdate:r});continue}const v=Gs(p),y=Gs(w);if(v>y){const j=(l=p.chats)!=null&&l.length?p.chats:w.chats,I=ls(w,p,{...w,...p,chats:j,_lastUpdate:r});o.set(p.id,I)}else if(v<y){const j={};if(p.status&&p.status!==w.status&&(j.status=p.status),p.cdpConnected!==void 0&&(j.cdpConnected=p.cdpConnected),(f=p.chats)!=null&&f.length&&!((x=w.chats)!=null&&x.length)&&(j.chats=p.chats),p.machineNickname!==void 0&&p.machineNickname!==w.machineNickname&&(j.machineNickname=p.machineNickname),p.version!==void 0&&(j.version=p.version),p.serverVersion!==void 0&&(j.serverVersion=p.serverVersion),p.versionMismatch===!0&&(j.versionMismatch=!0),Object.keys(j).length>0){const I=ls(w,p,{...w,...j,_lastUpdate:w._lastUpdate});o.set(p.id,I)}}else{const j=p.timestamp||r,I=w._lastUpdate||w.timestamp||0;if(j>=I){const g=(m=p.chats)!=null&&m.length?p.chats:w.chats,M=ls(w,p,{...w,...p,chats:g,_lastUpdate:r});o.set(p.id,M)}else(h=p.chats)!=null&&h.length&&!((u=w.chats)!=null&&u.length)&&o.set(p.id,{...w,chats:p.chats})}}const c=new Set(t.map(p=>p.id)),d=new Set;for(const p of t){const w=p.daemonId||((b=p.id)==null?void 0:b.split(":")[0]);w&&d.add(w)}for(const[p,w]of o){const v=w.daemonId||p.split(":")[0];if(!d.has(v))continue;if(i.has(v)&&!c.has(p)){o.delete(p);continue}const y=r-(w._lastUpdate||w.timestamp||0);(w.transport==="pty"&&!c.has(p)&&y>1e4||w.transport==="acp"&&!c.has(p)&&y>1e4||w.transport==="cdp-page"&&!c.has(p)&&y>3e4)&&o.delete(p)}for(const[p,w]of o)r-(w._lastUpdate||w.timestamp||0)>3e5&&w.status!=="online"&&o.delete(p);return Array.from(o.values())}function pa(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 ma({children:t,connectionOverrides:s}){const[n,r]=a.useState([]),[i,o]=a.useState(!1),[c,d]=a.useState([]),[l,f]=a.useState(void 0),x=a.useRef(n);a.useEffect(()=>{x.current=n},[n]);const m=a.useCallback((v,y)=>{r(j=>{let I=!1;const g=j.map(M=>M.id!==v||M.chats===y?M:(I=!0,{...M,chats:y}));return I?g:j})},[]),h=a.useCallback((v,y)=>{r(j=>{const I=j.length===0?v:xa(v,j,y);return pa(j,I)?j:I})},[]),u=a.useCallback(()=>o(!0),[]),b=a.useMemo(()=>({injectEntries:h,markLoaded:u,getIdes:()=>x.current}),[h,u]),p=s,w=a.useMemo(()=>({ides:n,updateIdeChats:m,initialLoaded:i,toasts:c,setToasts:d,wsStatus:(p==null?void 0:p.wsStatus)??"connected",isConnected:(p==null?void 0:p.isConnected)??!0,connectionStates:(p==null?void 0:p.connectionStates)??{},connectionTransports:(p==null?void 0:p.connectionTransports)??{},showReconnected:(p==null?void 0:p.showReconnected)??!1,retryConnection:p==null?void 0:p.retryConnection,isP2PActive:(p==null?void 0:p.isP2PActive)??!1,p2pStates:(p==null?void 0:p.p2pStates)??{},userRole:p==null?void 0:p.userRole,userName:l,setUserName:f}),[n,m,i,c,p==null?void 0:p.wsStatus,p==null?void 0:p.isConnected,p==null?void 0:p.connectionStates,p==null?void 0:p.connectionTransports,p==null?void 0:p.showReconnected,p==null?void 0:p.retryConnection,p==null?void 0:p.isP2PActive,p==null?void 0:p.p2pStates,p==null?void 0:p.userRole,l]);return e.jsx(Rn.Provider,{value:b,children:e.jsx(An.Provider,{value:w,children:t})})}function Nt(){return a.useContext(An)}function Ys(){return a.useContext(Rn)}function _n(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),x=d.startsWith("http")?new URL(f):new URL(f,typeof window<"u"?window.location.origin:"http://localhost");return l&&x.searchParams.set("token",l),!d.startsWith("http")&&!s?`${x.pathname}${x.search}${x.hash}`:x.toString()}async function c(d,l={}){const f={"Content-Type":"application/json",...l.headers||{}},x=n==null?void 0:n();x&&(f.Authorization=`Bearer ${x}`);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 u=await h.json().catch(()=>({error:h.statusText}));throw new Error(u.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 fa=_n({baseUrl:"http://localhost:3847"}),ha=a.createContext(fa);function ga({client:t,children:s}){return e.jsx(ha.Provider,{value:t,children:s})}const ba={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Ln=a.createContext(ba);function ya({value:t,children:s}){return e.jsx(Ln.Provider,{value:t,children:s})}function st(){return a.useContext(Ln)}const fe={size:18};function En({size:t=fe.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 Dn({size:t=fe.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 Ts({size:t=fe.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 va({size:t=fe.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function $n({size:t=fe.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 ja({size:t=fe.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})})}function Ft({size:t=fe.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 wa({size:t=fe.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 es({size:t=fe.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 Pn({size:t=fe.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 Bn({size:t=fe.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 tt({size:t=fe.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function Le({size:t=fe.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 As({size:t=fe.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 ka({size:t=fe.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 vs({size:t=fe.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 Rs({size:t=fe.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 _s({size:t=fe.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 xt({size:t=fe.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 Kn({size:t=fe.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 Na({size:t=fe.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 Wn({size:t=fe.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 Sa({size:t=fe.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 Ls({size:t=fe.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 Ca({size:t=fe.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 Vt({size:t=fe.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 On({size:t=fe.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 Ia({size:t=fe.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 Ma({size:t=fe.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 Ta({size:t=fe.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 ts({size:t=fe.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 Aa({size:t=fe.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 Ra({size:t=fe.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 _a({size:t=fe.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 La({size:t=fe.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 Ea(t){var l,f;const s=x=>x.replace(/^\d+;/,"").replace(/\u0007/g,"").trim(),r=t.split(`
|
|
2
|
+
var Zr=Object.defineProperty;var Qr=(t,s,n)=>s in t?Zr(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Me=(t,s,n)=>Qr(t,typeof s!="symbol"?s+"":s,n);import{r as a,j as e,M as Tn,a as An,b as ea,c as ta,u as pt,R as Is,t as sa,d as na,e as ra,D as aa,f as ia,g as oa,h as Ms,i as ca,k as la,B as da,l as ua,m as Ye,N as ys,n as xa}from"./vendor-CPghmr9Y.js";import{_ as pa}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 Rn=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}),_n=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function Ys(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 ls(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 ma(t,s,n){var l,f,x,m,h,u,b;const r=Date.now(),i=new Set((n==null?void 0:n.authoritativeDaemonIds)||[]);if(s.length===0)return t.map(p=>({...p,_lastUpdate:r}));const o=new Map;for(const p of s)o.set(p.id,p);for(const p of t){const w=o.get(p.id);if(!w){o.set(p.id,{...p,_lastUpdate:r});continue}const v=Ys(p),y=Ys(w);if(v>y){const j=(l=p.chats)!=null&&l.length?p.chats:w.chats,I=ls(w,p,{...w,...p,chats:j,_lastUpdate:r});o.set(p.id,I)}else if(v<y){const j={};if(p.status&&p.status!==w.status&&(j.status=p.status),p.cdpConnected!==void 0&&(j.cdpConnected=p.cdpConnected),(f=p.chats)!=null&&f.length&&!((x=w.chats)!=null&&x.length)&&(j.chats=p.chats),p.machineNickname!==void 0&&p.machineNickname!==w.machineNickname&&(j.machineNickname=p.machineNickname),p.version!==void 0&&(j.version=p.version),p.serverVersion!==void 0&&(j.serverVersion=p.serverVersion),p.versionMismatch===!0&&(j.versionMismatch=!0),Object.keys(j).length>0){const I=ls(w,p,{...w,...j,_lastUpdate:w._lastUpdate});o.set(p.id,I)}}else{const j=p.timestamp||r,I=w._lastUpdate||w.timestamp||0;if(j>=I){const g=(m=p.chats)!=null&&m.length?p.chats:w.chats,M=ls(w,p,{...w,...p,chats:g,_lastUpdate:r});o.set(p.id,M)}else(h=p.chats)!=null&&h.length&&!((u=w.chats)!=null&&u.length)&&o.set(p.id,{...w,chats:p.chats})}}const c=new Set(t.map(p=>p.id)),d=new Set;for(const p of t){const w=p.daemonId||((b=p.id)==null?void 0:b.split(":")[0]);w&&d.add(w)}for(const[p,w]of o){const v=w.daemonId||p.split(":")[0];if(!d.has(v))continue;if(i.has(v)&&!c.has(p)){o.delete(p);continue}const y=r-(w._lastUpdate||w.timestamp||0);(w.transport==="pty"&&!c.has(p)&&y>1e4||w.transport==="acp"&&!c.has(p)&&y>1e4||w.transport==="cdp-page"&&!c.has(p)&&y>3e4)&&o.delete(p)}for(const[p,w]of o)r-(w._lastUpdate||w.timestamp||0)>3e5&&w.status!=="online"&&o.delete(p);return Array.from(o.values())}function fa(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 ha({children:t,connectionOverrides:s}){const[n,r]=a.useState([]),[i,o]=a.useState(!1),[c,d]=a.useState([]),[l,f]=a.useState(void 0),x=a.useRef(n);a.useEffect(()=>{x.current=n},[n]);const m=a.useCallback((v,y)=>{r(j=>{let I=!1;const g=j.map(M=>M.id!==v||M.chats===y?M:(I=!0,{...M,chats:y}));return I?g:j})},[]),h=a.useCallback((v,y)=>{r(j=>{const I=j.length===0?v:ma(v,j,y);return fa(j,I)?j:I})},[]),u=a.useCallback(()=>o(!0),[]),b=a.useMemo(()=>({injectEntries:h,markLoaded:u,getIdes:()=>x.current}),[h,u]),p=s,w=a.useMemo(()=>({ides:n,updateIdeChats:m,initialLoaded:i,toasts:c,setToasts:d,wsStatus:(p==null?void 0:p.wsStatus)??"connected",isConnected:(p==null?void 0:p.isConnected)??!0,connectionStates:(p==null?void 0:p.connectionStates)??{},connectionTransports:(p==null?void 0:p.connectionTransports)??{},showReconnected:(p==null?void 0:p.showReconnected)??!1,retryConnection:p==null?void 0:p.retryConnection,isP2PActive:(p==null?void 0:p.isP2PActive)??!1,p2pStates:(p==null?void 0:p.p2pStates)??{},userRole:p==null?void 0:p.userRole,userName:l,setUserName:f}),[n,m,i,c,p==null?void 0:p.wsStatus,p==null?void 0:p.isConnected,p==null?void 0:p.connectionStates,p==null?void 0:p.connectionTransports,p==null?void 0:p.showReconnected,p==null?void 0:p.retryConnection,p==null?void 0:p.isP2PActive,p==null?void 0:p.p2pStates,p==null?void 0:p.userRole,l]);return e.jsx(_n.Provider,{value:b,children:e.jsx(Rn.Provider,{value:w,children:t})})}function Nt(){return a.useContext(Rn)}function Xs(){return a.useContext(_n)}function Ln(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),x=d.startsWith("http")?new URL(f):new URL(f,typeof window<"u"?window.location.origin:"http://localhost");return l&&x.searchParams.set("token",l),!d.startsWith("http")&&!s?`${x.pathname}${x.search}${x.hash}`:x.toString()}async function c(d,l={}){const f={"Content-Type":"application/json",...l.headers||{}},x=n==null?void 0:n();x&&(f.Authorization=`Bearer ${x}`);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 u=await h.json().catch(()=>({error:h.statusText}));throw new Error(u.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 ga=Ln({baseUrl:"http://localhost:3847"}),ba=a.createContext(ga);function ya({client:t,children:s}){return e.jsx(ba.Provider,{value:t,children:s})}const va={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Dn=a.createContext(va);function ja({value:t,children:s}){return e.jsx(Dn.Provider,{value:t,children:s})}function Qe(){return a.useContext(Dn)}const fe={size:18};function En({size:t=fe.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 $n({size:t=fe.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 Ts({size:t=fe.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 wa({size:t=fe.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 Pn({size:t=fe.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 ka({size:t=fe.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})})}function Ft({size:t=fe.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 Na({size:t=fe.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 es({size:t=fe.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 Bn({size:t=fe.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 Kn({size:t=fe.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 Ze({size:t=fe.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 De({size:t=fe.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 As({size:t=fe.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 Sa({size:t=fe.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 vs({size:t=fe.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 Rs({size:t=fe.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 _s({size:t=fe.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function ut({size:t=fe.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 Wn({size:t=fe.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 Ca({size:t=fe.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 On({size:t=fe.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 Ia({size:t=fe.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 Ls({size:t=fe.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 Ma({size:t=fe.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 Vt({size:t=fe.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 zn({size:t=fe.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 Ta({size:t=fe.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 Aa({size:t=fe.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 Ra({size:t=fe.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 ts({size:t=fe.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 _a({size:t=fe.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 La({size:t=fe.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 Da({size:t=fe.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 Ea({size:t=fe.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 $a(t){var l,f;const s=x=>x.replace(/^\d+;/,"").replace(/\u0007/g,"").trim(),r=t.split(`
|
|
3
3
|
`).map(x=>{if(!x.includes("\r"))return x;const m=x.split("\r").map(b=>b.trim()).filter(Boolean);if(m.length===0)return"";const h=m.filter(b=>b.startsWith("⏺"));if(h.length>0)return h[h.length-1];const u=m.filter(b=>!(/^[❯›>]\s*$/.test(b)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(b)&&b.length<40||/^[╭╰│├╮╯─═]+$/.test(b)));return u.length>0?u[u.length-1]:m[m.length-1]}).join(`
|
|
4
4
|
`).split(`
|
|
5
5
|
`),i={},o=[];let c=!1;for(const x of r){const m=s(x);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(x)){const u=x.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(u)i[u[1]]=(i[u[1]]||0)+1;else{const b=x.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);b&&(i[b]=(i[b]||0)+1)}c=!0;continue}if(/^(?:Bash|Read|Write|Edit|MultiEdit|Task|Glob|Grep|LS|NotebookEdit|Exact output)(?:\(|:)/.test(m)){const u=((f=(l=m.match(/^([A-Za-z][A-Za-z0-9_ ]+)/))==null?void 0:l[1])==null?void 0:f.trim())||"Tool";i[u]=(i[u]||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(x)||/^[╭╰│├╮╯─]+/.test(m)||/^\s+[⊙✓✗○◎▸►✦]/.test(x)||c&&/^\s{2,}/.test(x))continue;c=!1;const h=m.replace(/^❯\s+/,"");o.push(h)}const d=o.join(`
|
|
6
6
|
`).replace(/\n{3,}/g,`
|
|
7
7
|
|
|
8
|
-
`).trim();return{toolCounts:i,textContent:d,hasTools:Object.keys(i).length>0}}function js(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function
|
|
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
|
|
10
|
-
`);if(h==="thought"){const g=((I=s.meta)==null?void 0:I.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(
|
|
11
|
-
`)[0].slice(0,80)})]});if(h==="terminal"){const g=s.meta||{},M=g.isRunning?"⏳":"✅",k=g.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:k})]}),e.jsx("pre",{className:"chat-msg-body",children:u})]})}if(h==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:u.slice(0,100)});const b=!m&&o?Ea(u):null,p=b?b.textContent:u,w=b?Object.entries(b.toolCounts):[],v=o&&!m&&!c&&p.length>Xs,y=c?u:v&&!d?p.slice(0,Xs):p,j=Da(y);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${m?"self-end":"self-start"}`,children:[w.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[w.map(([g,M])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",g,M>1?` ×${M}`:""]},g)),(b==null?void 0:b.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:c?"Collapse":"Original"}),!p&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:js(n)})]}),(p||m)&&e.jsxs("div",{className:`chat-bubble ${m?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${p?"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:js(n)})]}),p&&e.jsx("div",{className:"chat-markdown",children:j?e.jsx(Mn,{remarkPlugins:[Tn,Zr,Qr],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(p.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),Ba=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:x,isLoadingMore:m,hasMoreHistory:h,hiddenLiveCount:u=0,loadError:b},p){var Z;const w=a.useRef(null),v=a.useRef(null),y=a.useRef(null),j=a.useRef(0),I=a.useRef(""),g=a.useRef(!1),M=a.useRef(null),k=a.useRef(!1),N=a.useRef(null),P=a.useRef(!1),[K,L]=a.useState(new Set),[B,T]=a.useState(new Set),S=a.useRef(!1),W=()=>{const D=w.current;return D?D.scrollHeight-D.scrollTop-D.clientHeight<200:!0},$=a.useCallback((D="auto")=>{const G=w.current;G&&G.scrollTo({top:G.scrollHeight,behavior:D})},[]),z=a.useCallback(()=>{var X;const D=w.current,G=(X=window.getSelection)==null?void 0:X.call(window);if(!D||!G||G.rangeCount===0||G.isCollapsed){P.current=!1;return}const H=G.anchorNode,C=G.focusNode;P.current=!!(H&&C&&D.contains(H)&&D.contains(C))},[]),E=a.useCallback((D="auto")=>{M.current!=null&&cancelAnimationFrame(M.current),M.current=requestAnimationFrame(()=>{M.current=null,$(D)})},[$]),_=s.length>0?`${s.length}:${(((Z=s[s.length-1])==null?void 0:Z.content)||"").length}`:"0:0";a.useEffect(()=>{const D=!g.current,G=I.current!==d;if(I.current=d,D||G){g.current=!0,S.current=!1,k.current=!0,P.current||E("auto"),j.current=s.length;return}s.length>j.current?!S.current&&!P.current&&E("auto"):W()&&!S.current&&!P.current&&E("auto"),j.current=s.length},[_,d,c,s.length,E]),a.useEffect(()=>()=>{M.current!=null&&cancelAnimationFrame(M.current),N.current!=null&&window.clearTimeout(N.current)},[]),a.useEffect(()=>{const D=v.current;if(!D)return;const G=()=>{N.current!=null&&window.clearTimeout(N.current),N.current=window.setTimeout(()=>{k.current=!1,N.current=null},180)},H=new ResizeObserver(()=>{k.current&&(P.current||(E("auto"),G()))});return H.observe(D),()=>{H.disconnect(),N.current!=null&&(window.clearTimeout(N.current),N.current=null)}},[E,d]),a.useImperativeHandle(p,()=>({scrollToBottom:(D="smooth")=>{$(D)}}),[$]),a.useEffect(()=>{const D=w.current;if(!D)return;let G;const H=()=>{clearTimeout(G),G=setTimeout(()=>{S.current=!W()},50)};return D.addEventListener("scroll",H,{passive:!0}),()=>{D.removeEventListener("scroll",H),clearTimeout(G)}},[]),a.useEffect(()=>(document.addEventListener("selectionchange",z),()=>document.removeEventListener("selectionchange",z)),[z]);const O=a.useRef(0),A=a.useRef(!1);a.useEffect(()=>{const D=w.current;if(!D||!A.current||O.current===0)return;const G=D.scrollHeight-O.current;G>0&&(D.scrollTop=G),O.current=0,A.current=!1},[s.length]);const q=()=>{const D=w.current;D&&(O.current=D.scrollHeight),A.current=!0,x==null||x()},ce=a.useMemo(()=>{const D=s.map((X,Y)=>({type:"message",data:X,index:Y,ts:X.receivedAt||l[dt(X,Y)]||0}));if(!n||n.length===0)return D;const G=[...n].sort((X,Y)=>X.timestamp-Y.timestamp).map((X,Y)=>({type:"action",data:X,index:Y,ts:X.timestamp})),H=[];let C=0;for(const X of D){for(;C<G.length&&X.ts>0&&G[C].ts<X.ts;)H.push(G[C++]);H.push(X)}for(;C<G.length;)H.push(G[C++]);return H},[s,n,l]),re=u>0||!!h,J=u>0?`↑ Show ${Math.min(u,80)} earlier messages${u>80?` (${u} hidden)`:""}`:b?`↻ ${b}`:"↑ Load older messages";return e.jsx("div",{ref:w,"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..."}),re&&!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 ${b&&u===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:J})}),ce.length===0&&!re&&(f||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),ce.map(D=>{if(D.type==="action"){const ie=D.data;return e.jsx($a,{log:ie},`action-${D.index}`)}const G=D.data,H=D.index,C=dt(G,H),X=G.receivedAt||l[C],Y=`${d}-${C}`,ee=K.has(Y),xe=B.has(Y);return e.jsx(Pa,{message:G,receivedAt:X,agentName:r,userName:i,isCliMode:o,isExpanded:ee,isTextExpanded:xe,onToggleExpanded:()=>L(ie=>{const me=new Set(ie);return ee?me.delete(Y):me.add(Y),me}),onToggleTextExpanded:()=>T(ie=>{const me=new Set(ie);return xe?me.delete(Y):me.add(Y),me})},`msg-${C}`)}),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})]})})}),Ka=a.memo(Ba,(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 Js=!1;const zn=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),x=a.useRef(!1),m=a.useRef(!1),h=()=>{const u=o.current;if(u){f.current&&(u.clear(),f.current=!1);for(const b of l.current)u.write(b);l.current=[],x.current&&(u.fit(),x.current=!1),m.current&&(u.bumpResize(),m.current=!1)}};return a.useImperativeHandle(i,()=>({write:u=>{o.current?o.current.write(u):l.current.push(u)},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:(u,b)=>{o.current&&"resize"in o.current&&typeof o.current.resize=="function"&&o.current.resize(u,b)},fit:()=>{o.current?o.current.fit():x.current=!0},bumpResize:()=>{o.current?o.current.bumpResize():m.current=!0}}),[]),a.useEffect(()=>{if(!c)return;const u=requestAnimationFrame(()=>{h()});return()=>cancelAnimationFrame(u)},[c]),a.useEffect(()=>{let u=!1;return ua(()=>import("./terminal-PD6SznsC.js").then(b=>b.i),__vite__mapDeps([0,1,2])).then(b=>{Js||(Js=!0,console.info("[CliTerminal] renderer module loaded: ghostty-web")),u||d(()=>b.GhosttyTerminalView)}).catch(b=>{console.error("[CliTerminal] failed to load terminal renderer",b)}),()=>{u=!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"}})});zn.displayName="CliTerminal";function _t({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 Zs({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 Wa({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 x,m,h,u;l>f?(x=i.width,m=i.width/l,h=0,u=(i.height-m)/2):(m=i.height,x=i.height*l,h=(i.width-x)/2,u=0);const b=i.left-o.left+h+x*t.nx,p=i.top-o.top+u+m*t.ny,w=Math.max(8,Math.min(o.width-8,b)),v=Math.max(8,Math.min(o.height-8,p));return e.jsxs("div",{style:{position:"absolute",left:w-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 Oa({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:i,setIsMenuOpen:o,imeText:c,setImeText:d,handleImeSubmit:l,isConnActive:f,zoom:x,isMobile:m,mobileFillZoom:h,onZoomOut:u,onZoomReset:b,onZoomIn:p,transportType:w,screenshotUsage:v,lastActionStatus:y}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:j=>j.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(j=>!j),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:j=>j.stopPropagation(),onChange:j=>d(j.target.value),onKeyDown:j=>{l(j)},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(j=>!j),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"})]}),x>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(x*100),"%"]}),w==="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"}),w==="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:j=>j.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: ",x<=(m?h:1)+.01?m?"FILL":"FIT":`${Math.round(x*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:j=>{j.stopPropagation(),u()},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:j=>{j.stopPropagation(),b()},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:j=>{j.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:"+"})]})]})]})]})}function za({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 Ua(){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 Qs(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 Ct(t,s){const n=a.useRef(null),r=a.useRef(0);a.useEffect(()=>{if(!Ua())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,Qs(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,Qs(s[c])]))}),n.current=s})}function Ha({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:i,minZoom:o,zoomRef:c,panXRef:d,panYRef:l,setPanX:f,setPanY:x,setZoom:m,lastWheelTimeRef:h,onAction:u,setLastActionStatus:b,spawnRippleFromNormalized:p,clampPan:w,isMobile:v,mobileFillZoom:y}){const[j,I]=a.useState(null),g=a.useRef(null),M=a.useRef(null),k=a.useRef(null),N=a.useRef(!1),P=a.useRef(null),K=a.useRef(0),L=a.useRef(null),B=a.useRef(1),T=a.useRef({x:0,y:0}),S=a.useRef(!1),W=a.useRef(r),$=a.useRef(u),z=()=>{if(g.current)return;const O={nx:.5,ny:.5};g.current=O,I(O)};return a.useEffect(()=>{W.current=r,r==="mouse"&&z()},[r]),a.useEffect(()=>{$.current=u},[u]),a.useEffect(()=>{const O=t.current;if(!O)return;const A=D=>{if(!n.current)return null;const G=n.current.getBoundingClientRect();return!G.width||!G.height?null:{nx:Math.max(0,Math.min(1,(D.clientX-G.left)/G.width)),ny:Math.max(0,Math.min(1,(D.clientY-G.top)/G.height))}},q=(D,G)=>{if(!n.current)return{dnx:0,dny:0};const H=n.current,C=H.getBoundingClientRect(),X=H.naturalWidth||C.width,Y=H.naturalHeight||C.height,ee=X/Y,xe=C.width/C.height;let ie,me;return ee>xe?(ie=C.width,me=C.width/ee):(me=C.height,ie=C.height*ee),{dnx:D/ie,dny:G/me}},ce=(D,G,H)=>{if(H<=1.05)return;const C=-(D-.5)*100,X=-(G-.5)*100,Y=w(C,X,H);(Math.abs(Y.x-d.current)>.1||Math.abs(Y.y-l.current)>.1)&&(f(Y.x),x(Y.y),d.current=Y.x,l.current=Y.y)},re=D=>{const G=s.current;if(G&&D.target instanceof Node&&G.contains(D.target))D.preventDefault();else return;if(D.touches.length===1){const H=D.touches[0];M.current={x:H.clientX,y:H.clientY,time:Date.now()},k.current={x:H.clientX,y:H.clientY},S.current||(N.current=!1),P.current=setTimeout(()=>{if(!N.current&&!S.current)if(N.current=!0,W.current==="mouse"){const C=g.current||{nx:.5,ny:.5};b("Right Click"),p(C.nx,C.ny,"right"),$.current("input_click",{...C,button:"right"}).catch(()=>{})}else{const C=A(H);C&&(b("Right Click"),p(C.nx,C.ny,"right"),$.current("input_click",{...C,button:"right"}).catch(()=>{}))}},500);return}if(D.touches.length===2){P.current&&clearTimeout(P.current),N.current=!0,S.current=!0;const H=D.touches[1].clientX-D.touches[0].clientX,C=D.touches[1].clientY-D.touches[0].clientY;L.current=Math.sqrt(H*H+C*C),B.current=c.current,T.current={x:(D.touches[0].clientX+D.touches[1].clientX)/2,y:(D.touches[0].clientY+D.touches[1].clientY)/2}}},J=D=>{const G=s.current;if(G&&D.target instanceof Node&&G.contains(D.target)&&D.preventDefault(),D.touches.length===1&&k.current){const H=D.touches[0],C=H.clientX-k.current.x,X=H.clientY-k.current.y;if(!N.current&&M.current){const Y=H.clientX-M.current.x,ee=H.clientY-M.current.y;Math.sqrt(Y*Y+ee*ee)>8&&(N.current=!0,P.current&&clearTimeout(P.current))}if(N.current)if(W.current==="mouse"){const Y=q(C,X),ee=g.current||{nx:.5,ny:.5},xe=Math.max(0,Math.min(1,ee.nx+Y.dnx)),ie=Math.max(0,Math.min(1,ee.ny+Y.dny));g.current={nx:xe,ny:ie},I({nx:xe,ny:ie}),b(`Cursor: ${Math.round(xe*100)}%, ${Math.round(ie*100)}%`),ce(xe,ie,c.current);const me=Date.now();me-h.current>=30&&(h.current=me,$.current("input_mouseMoved",{nx:xe,ny:ie}).catch(()=>{}))}else if(c.current>1){const Y=s.current;if(Y){const ee=Y.clientWidth,xe=Y.clientHeight,ie=d.current+C/ee*100,me=l.current+X/xe*100,Q=w(ie,me,c.current);f(Q.x),x(Q.y),d.current=Q.x,l.current=Q.y}}else{const Y=A(H);if(Y){const ee=Date.now();ee-h.current>=40&&(h.current=ee,b("Scroll"),$.current("input_wheel",{nx:Y.nx,ny:Y.ny,deltaX:Math.round(-C*2.5),deltaY:Math.round(-X*2.5)}).catch(()=>{}))}}k.current={x:H.clientX,y:H.clientY};return}if(D.touches.length===2&&L.current!==null){const H=D.touches[1].clientX-D.touches[0].clientX,C=D.touches[1].clientY-D.touches[0].clientY,Y=Math.sqrt(H*H+C*C)/L.current,ee=(D.touches[0].clientX+D.touches[1].clientX)/2,xe=(D.touches[0].clientY+D.touches[1].clientY)/2,ie=ee-T.current.x,me=xe-T.current.y,Q=Math.abs(Y-1)>.03;if(W.current==="mouse"){if(Q){const R=Math.max(o,Math.min(5,B.current*Y));m(R),c.current=R}else if(Math.abs(ie)>2||Math.abs(me)>2){const R=g.current||{nx:.5,ny:.5},V=Date.now();V-h.current>=30&&(h.current=V,b("Scroll"),$.current("input_wheel",{nx:R.nx,ny:R.ny,deltaX:Math.round(-ie*3),deltaY:Math.round(-me*3)}).catch(()=>{}))}}else{const R=Math.max(o,Math.min(5,B.current*Y));m(R),c.current=R;const V=s.current;if(V&&R>1){const te=V.clientWidth,ae=V.clientHeight,ue=d.current+ie/te*100,oe=l.current+me/ae*100,he=w(ue,oe,R);f(he.x),x(he.y),d.current=he.x,l.current=he.y}}T.current={x:ee,y:xe}}},Z=D=>{var G;if(P.current&&clearTimeout(P.current),L.current=null,D.touches.length===1&&S.current){const H=D.touches[0];M.current={x:H.clientX,y:H.clientY,time:Date.now()},k.current={x:H.clientX,y:H.clientY},N.current=!0;return}if(D.touches.length===0){if(S.current){S.current=!1,N.current=!1;return}if(D.changedTouches.length===1&&!N.current){const H=D.changedTouches[0],C=Date.now(),X=C-(((G=M.current)==null?void 0:G.time)||0);if(X<60||X>400){N.current=!1;return}if(M.current){const Y=H.clientX-M.current.x,ee=H.clientY-M.current.y;if(Math.sqrt(Y*Y+ee*ee)>12){N.current=!1;return}}if(W.current==="mouse"){const Y=g.current||A(H);Y&&(b(`Click: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),p(Y.nx,Y.ny,"left"),$.current("input_click",{...Y}).catch(()=>{}))}else{const Y=A(H);if(!Y)return;C-K.current<300?(b("Double tap"),p(Y.nx,Y.ny,"double"),$.current("input_click",{...Y,clickCount:2}).catch(()=>{}),K.current=0):(b(`Tap: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),p(Y.nx,Y.ny,"left"),$.current("input_click",{...Y}).catch(()=>{}),K.current=C)}}N.current=!1}};return O.addEventListener("touchstart",re,{passive:!1}),O.addEventListener("touchmove",J,{passive:!1}),O.addEventListener("touchend",Z,{passive:!1}),()=>{O.removeEventListener("touchstart",re),O.removeEventListener("touchmove",J),O.removeEventListener("touchend",Z),P.current&&clearTimeout(P.current)}},[t,s,n,o,c,d,l,f,x,m,h,b,p,w]),{cursorPos:j,cursorPosRef:g,handleToggleInputMode:()=>{i(O=>{const A=O==="touch"?"mouse":"touch";return A==="mouse"&&z(),A})},handleZoomReset:()=>{const O=v?y:1;m(O),c.current=O,f(0),x(0),d.current=0,l.current=0}}}function Un({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,x]=a.useState(null),[m,h]=a.useState(""),[,u]=a.useState(!1),[b,p]=a.useState([]),w=a.useRef(0),[v,y]=a.useState(!1),[j,I]=a.useState(!1),g=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[M,k]=a.useState(g?"mouse":"touch"),[N,P]=a.useState(1),K=a.useRef(!1),[L,B]=a.useState(1),[T,S]=a.useState(0),[W,$]=a.useState(0);Ct("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:M,zoom:L,panX:T,panY:W,isMenuOpen:v,isImeOpen:j});const z=a.useRef(0),E=a.useRef(L),_=a.useRef(T),O=a.useRef(W);a.useEffect(()=>{E.current=L},[L]),a.useEffect(()=>{_.current=T},[T]),a.useEffect(()=>{O.current=W},[W]),a.useEffect(()=>{var Q;(Q=c.current)==null||Q.focus()},[]);const A=n==="connected",q=r,ce=A?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",re=A?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!g||K.current||!q)return;const Q=l.current,R=d.current;if(!Q||!R)return;const V=()=>{const te=R.clientWidth,ae=R.clientHeight,ue=Q.naturalWidth,oe=Q.naturalHeight;if(!ue||!oe||!te||!ae)return;const he=Math.min(te/ue,ae/oe),Me=Math.max(te/ue,ae/oe)/he;Me>1.01&&(P(Me),B(Me),E.current=Me),K.current=!0};Q.complete&&Q.naturalWidth?V():Q.addEventListener("load",V,{once:!0})},[q,g]);const J=.5;a.useEffect(()=>{L<=J&&(S(0),$(0))},[L,J]);const Z=(Q,R,V)=>{if(V<=J)return{x:0,y:0};const te=(V-1)/(2*V)*100,ae=(V-1)/(2*V)*100;return{x:Math.max(-te,Math.min(te,Q)),y:Math.max(-ae,Math.min(ae,R))}},D=(Q,R)=>{if(!l.current)return null;const V=l.current.getBoundingClientRect();return!V.width||!V.height?null:{nx:Math.max(0,Math.min(1,(Q-V.left)/V.width)),ny:Math.max(0,Math.min(1,(R-V.top)/V.height))}},G=(Q,R,V)=>{const te=d.current;if(!te)return;const ae=te.getBoundingClientRect(),ue=++w.current;p(oe=>[...oe,{id:ue,x:Q-ae.left,y:R-ae.top,type:V}]),setTimeout(()=>p(oe=>oe.filter(he=>he.id!==ue)),600)},H=(Q,R,V)=>{const te=l.current,ae=d.current;if(!te||!ae)return;const ue=te.getBoundingClientRect(),oe=ae.getBoundingClientRect(),he=te.naturalWidth||ue.width,Pe=te.naturalHeight||ue.height,Me=he/Pe,Be=ue.width/ue.height;let Re,Ge,Ye,Ue;Me>Be?(Re=ue.width,Ge=ue.width/Me,Ye=0,Ue=(ue.height-Ge)/2):(Ge=ue.height,Re=ue.height*Me,Ye=(ue.width-Re)/2,Ue=0);const Xe=ue.left-oe.left+Ye+Re*Q,Je=ue.top-oe.top+Ue+Ge*R,ct=++w.current;p(We=>[...We,{id:ct,x:Xe,y:Je,type:V}]),setTimeout(()=>p(We=>We.filter(ft=>ft.id!==ct)),600)},C=async Q=>{var V;const R=D(Q.clientX,Q.clientY);if(R){x(`Click: ${Math.round(R.nx*100)}%, ${Math.round(R.ny*100)}%`),G(Q.clientX,Q.clientY,"left"),(V=c.current)==null||V.focus();try{const te=await t("input_click",{nx:R.nx,ny:R.ny});te!=null&&te.success||s(`❌ Click failed: ${te==null?void 0:te.error}`)}catch(te){s(`❌ Click error: ${te.message||te}`)}}},X=async(Q,R,V,te=0)=>{try{await t("input_key",{type:V?"char":"keyDown",key:Q,code:R,text:V?Q:void 0,unmodifiedText:V?Q:void 0,modifiers:te})}catch(ae){s(`❌ Key error: ${ae.message||ae}`)}},Y=async Q=>{if(Q.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(Q.key)&&Q.preventDefault();let V=0;Q.altKey&&(V|=1),Q.ctrlKey&&(V|=2),Q.metaKey&&(V|=4),Q.shiftKey&&(V|=8),x(`Key: ${Q.key}`),await X(Q.key,Q.code,Q.key.length===1,V)},ee=async Q=>{if(Q.key==="Enter"){if(Q.nativeEvent.isComposing)return;if(m){const R=m;h(""),x(`IME Sent: ${R}`);try{const V=await t("input_type",{text:R});V!=null&&V.success||s(`❌ IME error: ${V==null?void 0:V.error}`)}catch(V){s(`❌ IME error: ${V.message}`)}}else x("Key: Enter"),await X("Enter","Enter",!1)}};a.useEffect(()=>{const Q=c.current;if(!Q)return;const R=V=>{var te;if((te=l.current)!=null&&te.contains(V.target)){V.preventDefault();const ae=Date.now();if(ae-z.current<40)return;z.current=ae;const ue=D(V.clientX,V.clientY);if(!ue)return;x(`Scroll: ${Math.round(V.deltaY)}`),t("input_wheel",{nx:ue.nx,ny:ue.ny,deltaX:Math.round(V.deltaX),deltaY:Math.round(V.deltaY)}).catch(()=>{})}};return Q.addEventListener("wheel",R,{passive:!1}),()=>Q.removeEventListener("wheel",R)},[t]);const{cursorPos:xe,handleToggleInputMode:ie,handleZoomReset:me}=Ha({containerRef:c,viewportRef:d,imgRef:l,inputMode:M,setInputMode:k,minZoom:J,zoomRef:E,panXRef:_,panYRef:O,setPanX:S,setPanY:$,setZoom:B,lastWheelTimeRef:z,onAction:t,setLastActionStatus:x,spawnRippleFromNormalized:H,clampPan:Z,isMobile:g,mobileFillZoom:N});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:Y,onContextMenu:Q=>Q.preventDefault(),onFocus:()=>u(!0),onBlur:()=>u(!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(${L}) translate(${T}%, ${W}%)`,transformOrigin:"center center",cursor:M==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:C,onContextMenu:Q=>Q.preventDefault(),onDragStart:Q=>Q.preventDefault()}):e.jsx(za,{waitingLabel:ce,waitingHint:re,transportType:o}),M==="mouse"&&q&&e.jsx(Wa,{cursorPos:xe,viewportRef:d,imgRef:l}),b.map(Q=>{const V={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[Q.type];return e.jsxs("div",{style:{position:"absolute",left:Q.x,top:Q.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${V}, 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(${V}, 0.9)`,boxShadow:`0 0 12px rgba(${V}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},Q.id)})]}),e.jsx(Oa,{inputMode:M,onToggleInputMode:ie,isImeOpen:j,setIsImeOpen:I,isMenuOpen:v,setIsMenuOpen:y,imeText:m,setImeText:h,handleImeSubmit:ee,isConnActive:A,zoom:L,isMobile:g,mobileFillZoom:N,onZoomOut:()=>B(Q=>Math.max(.5,Q-.25)),onZoomReset:me,onZoomIn:()=>B(Q=>Math.min(5,Q+.25)),transportType:o,screenshotUsage:i,lastActionStatus:f}),e.jsx("style",{children:`
|
|
8
|
+
`).trim();return{toolCounts:i,textContent:d,hasTools:Object.keys(i).length>0}}function js(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function Pa(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function lt(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 Js=700,Ba=a.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(Tn,{remarkPlugins:[An],children:s.text}),e.jsx("span",{className:"action-time",children:js(s.timestamp)})]})},(t,s)=>t.log===s.log),Ka=a.memo(function({message:s,receivedAt:n,agentName:r,userName:i,isCliMode:o,isExpanded:c,isTextExpanded:d,onToggleExpanded:l,onToggleTextExpanded:f}){var I;const x=(s.role||"").toLowerCase(),m=x==="user"||x==="human",h=s.kind||(x==="tool"?"tool":"standard"),u=typeof s.content=="string"?s.content:(s.content||[]).map(g=>g.text||"").join(`
|
|
10
|
+
`);if(h==="thought"){const g=((I=s.meta)==null?void 0:I.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(Aa,{size:13}),e.jsx("span",{children:g})]}),e.jsx("div",{className:"chat-msg-body",children:u})]})}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:u.split(`
|
|
11
|
+
`)[0].slice(0,80)})]});if(h==="terminal"){const g=s.meta||{},M=g.isRunning?"⏳":"✅",k=g.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:k})]}),e.jsx("pre",{className:"chat-msg-body",children:u})]})}if(h==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:u.slice(0,100)});const b=!m&&o?$a(u):null,p=b?b.textContent:u,w=b?Object.entries(b.toolCounts):[],v=o&&!m&&!c&&p.length>Js,y=c?u:v&&!d?p.slice(0,Js):p,j=Pa(y);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${m?"self-end":"self-start"}`,children:[w.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[w.map(([g,M])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",g,M>1?` ×${M}`:""]},g)),(b==null?void 0:b.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:c?"Collapse":"Original"}),!p&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:js(n)})]}),(p||m)&&e.jsxs("div",{className:`chat-bubble ${m?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${p?"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:js(n)})]}),p&&e.jsx("div",{className:"chat-markdown",children:j?e.jsx(Tn,{remarkPlugins:[An,ea,ta],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(p.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),Wa=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:x,isLoadingMore:m,hasMoreHistory:h,hiddenLiveCount:u=0,loadError:b},p){var Q;const w=a.useRef(null),v=a.useRef(null),y=a.useRef(null),j=a.useRef(0),I=a.useRef(""),g=a.useRef(!1),M=a.useRef(null),k=a.useRef(!1),N=a.useRef(null),P=a.useRef(!1),[K,L]=a.useState(new Set),[B,T]=a.useState(new Set),S=a.useRef(!1),W=()=>{const E=w.current;return E?E.scrollHeight-E.scrollTop-E.clientHeight<200:!0},$=a.useCallback((E="auto")=>{const G=w.current;G&&G.scrollTo({top:G.scrollHeight,behavior:E})},[]),z=a.useCallback(()=>{var X;const E=w.current,G=(X=window.getSelection)==null?void 0:X.call(window);if(!E||!G||G.rangeCount===0||G.isCollapsed){P.current=!1;return}const H=G.anchorNode,C=G.focusNode;P.current=!!(H&&C&&E.contains(H)&&E.contains(C))},[]),D=a.useCallback((E="auto")=>{M.current!=null&&cancelAnimationFrame(M.current),M.current=requestAnimationFrame(()=>{M.current=null,$(E)})},[$]),_=s.length>0?`${s.length}:${(((Q=s[s.length-1])==null?void 0:Q.content)||"").length}`:"0:0";a.useEffect(()=>{const E=!g.current,G=I.current!==d;if(I.current=d,E||G){g.current=!0,S.current=!1,k.current=!0,P.current||D("auto"),j.current=s.length;return}s.length>j.current?!S.current&&!P.current&&D("auto"):W()&&!S.current&&!P.current&&D("auto"),j.current=s.length},[_,d,c,s.length,D]),a.useEffect(()=>()=>{M.current!=null&&cancelAnimationFrame(M.current),N.current!=null&&window.clearTimeout(N.current)},[]),a.useEffect(()=>{const E=v.current;if(!E)return;const G=()=>{N.current!=null&&window.clearTimeout(N.current),N.current=window.setTimeout(()=>{k.current=!1,N.current=null},180)},H=new ResizeObserver(()=>{k.current&&(P.current||(D("auto"),G()))});return H.observe(E),()=>{H.disconnect(),N.current!=null&&(window.clearTimeout(N.current),N.current=null)}},[D,d]),a.useImperativeHandle(p,()=>({scrollToBottom:(E="smooth")=>{$(E)}}),[$]),a.useEffect(()=>{const E=w.current;if(!E)return;let G;const H=()=>{clearTimeout(G),G=setTimeout(()=>{S.current=!W()},50)};return E.addEventListener("scroll",H,{passive:!0}),()=>{E.removeEventListener("scroll",H),clearTimeout(G)}},[]),a.useEffect(()=>(document.addEventListener("selectionchange",z),()=>document.removeEventListener("selectionchange",z)),[z]);const O=a.useRef(0),A=a.useRef(!1);a.useEffect(()=>{const E=w.current;if(!E||!A.current||O.current===0)return;const G=E.scrollHeight-O.current;G>0&&(E.scrollTop=G),O.current=0,A.current=!1},[s.length]);const q=()=>{const E=w.current;E&&(O.current=E.scrollHeight),A.current=!0,x==null||x()},ce=a.useMemo(()=>{const E=s.map((X,Y)=>({type:"message",data:X,index:Y,ts:X.receivedAt||l[lt(X,Y)]||0}));if(!n||n.length===0)return E;const G=[...n].sort((X,Y)=>X.timestamp-Y.timestamp).map((X,Y)=>({type:"action",data:X,index:Y,ts:X.timestamp})),H=[];let C=0;for(const X of E){for(;C<G.length&&X.ts>0&&G[C].ts<X.ts;)H.push(G[C++]);H.push(X)}for(;C<G.length;)H.push(G[C++]);return H},[s,n,l]),ne=u>0||!!h,Z=u>0?`↑ Show ${Math.min(u,80)} earlier messages${u>80?` (${u} hidden)`:""}`:b?`↻ ${b}`:"↑ Load older messages";return e.jsx("div",{ref:w,"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..."}),ne&&!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 ${b&&u===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:Z})}),ce.length===0&&!ne&&(f||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),ce.map(E=>{if(E.type==="action"){const ae=E.data;return e.jsx(Ba,{log:ae},`action-${E.index}`)}const G=E.data,H=E.index,C=lt(G,H),X=G.receivedAt||l[C],Y=`${d}-${C}`,ee=K.has(Y),ue=B.has(Y);return e.jsx(Ka,{message:G,receivedAt:X,agentName:r,userName:i,isCliMode:o,isExpanded:ee,isTextExpanded:ue,onToggleExpanded:()=>L(ae=>{const me=new Set(ae);return ee?me.delete(Y):me.add(Y),me}),onToggleTextExpanded:()=>T(ae=>{const me=new Set(ae);return ue?me.delete(Y):me.add(Y),me})},`msg-${C}`)}),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})]})})}),Oa=a.memo(Wa,(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 Zs=!1;const Un=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),x=a.useRef(!1),m=a.useRef(!1),h=()=>{const u=o.current;if(u){f.current&&(u.clear(),f.current=!1);for(const b of l.current)u.write(b);l.current=[],x.current&&(u.fit(),x.current=!1),m.current&&(u.bumpResize(),m.current=!1)}};return a.useImperativeHandle(i,()=>({write:u=>{o.current?o.current.write(u):l.current.push(u)},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:(u,b)=>{o.current&&"resize"in o.current&&typeof o.current.resize=="function"&&o.current.resize(u,b)},fit:()=>{o.current?o.current.fit():x.current=!0},bumpResize:()=>{o.current?o.current.bumpResize():m.current=!0}}),[]),a.useEffect(()=>{if(!c)return;const u=requestAnimationFrame(()=>{h()});return()=>cancelAnimationFrame(u)},[c]),a.useEffect(()=>{let u=!1;return pa(()=>import("./terminal-PD6SznsC.js").then(b=>b.i),__vite__mapDeps([0,1,2])).then(b=>{Zs||(Zs=!0,console.info("[CliTerminal] renderer module loaded: ghostty-web")),u||d(()=>b.GhosttyTerminalView)}).catch(b=>{console.error("[CliTerminal] failed to load terminal renderer",b)}),()=>{u=!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"}})});Un.displayName="CliTerminal";function _t({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 Qs({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 za({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 x,m,h,u;l>f?(x=i.width,m=i.width/l,h=0,u=(i.height-m)/2):(m=i.height,x=i.height*l,h=(i.width-x)/2,u=0);const b=i.left-o.left+h+x*t.nx,p=i.top-o.top+u+m*t.ny,w=Math.max(8,Math.min(o.width-8,b)),v=Math.max(8,Math.min(o.height-8,p));return e.jsxs("div",{style:{position:"absolute",left:w-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 Ua({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:i,setIsMenuOpen:o,imeText:c,setImeText:d,handleImeSubmit:l,isConnActive:f,zoom:x,isMobile:m,mobileFillZoom:h,onZoomOut:u,onZoomReset:b,onZoomIn:p,transportType:w,screenshotUsage:v,lastActionStatus:y}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:j=>j.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(j=>!j),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:j=>j.stopPropagation(),onChange:j=>d(j.target.value),onKeyDown:j=>{l(j)},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(j=>!j),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"})]}),x>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(x*100),"%"]}),w==="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"}),w==="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:j=>j.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: ",x<=(m?h:1)+.01?m?"FILL":"FIT":`${Math.round(x*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:j=>{j.stopPropagation(),u()},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:j=>{j.stopPropagation(),b()},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:j=>{j.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:"+"})]})]})]})]})}function Ha({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 Fa(){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 en(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 Ct(t,s){const n=a.useRef(null),r=a.useRef(0);a.useEffect(()=>{if(!Fa())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,en(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,en(s[c])]))}),n.current=s})}function Va({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:i,minZoom:o,zoomRef:c,panXRef:d,panYRef:l,setPanX:f,setPanY:x,setZoom:m,lastWheelTimeRef:h,onAction:u,setLastActionStatus:b,spawnRippleFromNormalized:p,clampPan:w,isMobile:v,mobileFillZoom:y}){const[j,I]=a.useState(null),g=a.useRef(null),M=a.useRef(null),k=a.useRef(null),N=a.useRef(!1),P=a.useRef(null),K=a.useRef(0),L=a.useRef(null),B=a.useRef(1),T=a.useRef({x:0,y:0}),S=a.useRef(!1),W=a.useRef(r),$=a.useRef(u),z=()=>{if(g.current)return;const O={nx:.5,ny:.5};g.current=O,I(O)};return a.useEffect(()=>{W.current=r,r==="mouse"&&z()},[r]),a.useEffect(()=>{$.current=u},[u]),a.useEffect(()=>{const O=t.current;if(!O)return;const A=E=>{if(!n.current)return null;const G=n.current.getBoundingClientRect();return!G.width||!G.height?null:{nx:Math.max(0,Math.min(1,(E.clientX-G.left)/G.width)),ny:Math.max(0,Math.min(1,(E.clientY-G.top)/G.height))}},q=(E,G)=>{if(!n.current)return{dnx:0,dny:0};const H=n.current,C=H.getBoundingClientRect(),X=H.naturalWidth||C.width,Y=H.naturalHeight||C.height,ee=X/Y,ue=C.width/C.height;let ae,me;return ee>ue?(ae=C.width,me=C.width/ee):(me=C.height,ae=C.height*ee),{dnx:E/ae,dny:G/me}},ce=(E,G,H)=>{if(H<=1.05)return;const C=-(E-.5)*100,X=-(G-.5)*100,Y=w(C,X,H);(Math.abs(Y.x-d.current)>.1||Math.abs(Y.y-l.current)>.1)&&(f(Y.x),x(Y.y),d.current=Y.x,l.current=Y.y)},ne=E=>{const G=s.current;if(G&&E.target instanceof Node&&G.contains(E.target))E.preventDefault();else return;if(E.touches.length===1){const H=E.touches[0];M.current={x:H.clientX,y:H.clientY,time:Date.now()},k.current={x:H.clientX,y:H.clientY},S.current||(N.current=!1),P.current=setTimeout(()=>{if(!N.current&&!S.current)if(N.current=!0,W.current==="mouse"){const C=g.current||{nx:.5,ny:.5};b("Right Click"),p(C.nx,C.ny,"right"),$.current("input_click",{...C,button:"right"}).catch(()=>{})}else{const C=A(H);C&&(b("Right Click"),p(C.nx,C.ny,"right"),$.current("input_click",{...C,button:"right"}).catch(()=>{}))}},500);return}if(E.touches.length===2){P.current&&clearTimeout(P.current),N.current=!0,S.current=!0;const H=E.touches[1].clientX-E.touches[0].clientX,C=E.touches[1].clientY-E.touches[0].clientY;L.current=Math.sqrt(H*H+C*C),B.current=c.current,T.current={x:(E.touches[0].clientX+E.touches[1].clientX)/2,y:(E.touches[0].clientY+E.touches[1].clientY)/2}}},Z=E=>{const G=s.current;if(G&&E.target instanceof Node&&G.contains(E.target)&&E.preventDefault(),E.touches.length===1&&k.current){const H=E.touches[0],C=H.clientX-k.current.x,X=H.clientY-k.current.y;if(!N.current&&M.current){const Y=H.clientX-M.current.x,ee=H.clientY-M.current.y;Math.sqrt(Y*Y+ee*ee)>8&&(N.current=!0,P.current&&clearTimeout(P.current))}if(N.current)if(W.current==="mouse"){const Y=q(C,X),ee=g.current||{nx:.5,ny:.5},ue=Math.max(0,Math.min(1,ee.nx+Y.dnx)),ae=Math.max(0,Math.min(1,ee.ny+Y.dny));g.current={nx:ue,ny:ae},I({nx:ue,ny:ae}),b(`Cursor: ${Math.round(ue*100)}%, ${Math.round(ae*100)}%`),ce(ue,ae,c.current);const me=Date.now();me-h.current>=30&&(h.current=me,$.current("input_mouseMoved",{nx:ue,ny:ae}).catch(()=>{}))}else if(c.current>1){const Y=s.current;if(Y){const ee=Y.clientWidth,ue=Y.clientHeight,ae=d.current+C/ee*100,me=l.current+X/ue*100,J=w(ae,me,c.current);f(J.x),x(J.y),d.current=J.x,l.current=J.y}}else{const Y=A(H);if(Y){const ee=Date.now();ee-h.current>=40&&(h.current=ee,b("Scroll"),$.current("input_wheel",{nx:Y.nx,ny:Y.ny,deltaX:Math.round(-C*2.5),deltaY:Math.round(-X*2.5)}).catch(()=>{}))}}k.current={x:H.clientX,y:H.clientY};return}if(E.touches.length===2&&L.current!==null){const H=E.touches[1].clientX-E.touches[0].clientX,C=E.touches[1].clientY-E.touches[0].clientY,Y=Math.sqrt(H*H+C*C)/L.current,ee=(E.touches[0].clientX+E.touches[1].clientX)/2,ue=(E.touches[0].clientY+E.touches[1].clientY)/2,ae=ee-T.current.x,me=ue-T.current.y,J=Math.abs(Y-1)>.03;if(W.current==="mouse"){if(J){const R=Math.max(o,Math.min(5,B.current*Y));m(R),c.current=R}else if(Math.abs(ae)>2||Math.abs(me)>2){const R=g.current||{nx:.5,ny:.5},F=Date.now();F-h.current>=30&&(h.current=F,b("Scroll"),$.current("input_wheel",{nx:R.nx,ny:R.ny,deltaX:Math.round(-ae*3),deltaY:Math.round(-me*3)}).catch(()=>{}))}}else{const R=Math.max(o,Math.min(5,B.current*Y));m(R),c.current=R;const F=s.current;if(F&&R>1){const te=F.clientWidth,ie=F.clientHeight,xe=d.current+ae/te*100,re=l.current+me/ie*100,he=w(xe,re,R);f(he.x),x(he.y),d.current=he.x,l.current=he.y}}T.current={x:ee,y:ue}}},Q=E=>{var G;if(P.current&&clearTimeout(P.current),L.current=null,E.touches.length===1&&S.current){const H=E.touches[0];M.current={x:H.clientX,y:H.clientY,time:Date.now()},k.current={x:H.clientX,y:H.clientY},N.current=!0;return}if(E.touches.length===0){if(S.current){S.current=!1,N.current=!1;return}if(E.changedTouches.length===1&&!N.current){const H=E.changedTouches[0],C=Date.now(),X=C-(((G=M.current)==null?void 0:G.time)||0);if(X<60||X>400){N.current=!1;return}if(M.current){const Y=H.clientX-M.current.x,ee=H.clientY-M.current.y;if(Math.sqrt(Y*Y+ee*ee)>12){N.current=!1;return}}if(W.current==="mouse"){const Y=g.current||A(H);Y&&(b(`Click: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),p(Y.nx,Y.ny,"left"),$.current("input_click",{...Y}).catch(()=>{}))}else{const Y=A(H);if(!Y)return;C-K.current<300?(b("Double tap"),p(Y.nx,Y.ny,"double"),$.current("input_click",{...Y,clickCount:2}).catch(()=>{}),K.current=0):(b(`Tap: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),p(Y.nx,Y.ny,"left"),$.current("input_click",{...Y}).catch(()=>{}),K.current=C)}}N.current=!1}};return O.addEventListener("touchstart",ne,{passive:!1}),O.addEventListener("touchmove",Z,{passive:!1}),O.addEventListener("touchend",Q,{passive:!1}),()=>{O.removeEventListener("touchstart",ne),O.removeEventListener("touchmove",Z),O.removeEventListener("touchend",Q),P.current&&clearTimeout(P.current)}},[t,s,n,o,c,d,l,f,x,m,h,b,p,w]),{cursorPos:j,cursorPosRef:g,handleToggleInputMode:()=>{i(O=>{const A=O==="touch"?"mouse":"touch";return A==="mouse"&&z(),A})},handleZoomReset:()=>{const O=v?y:1;m(O),c.current=O,f(0),x(0),d.current=0,l.current=0}}}function Hn({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,x]=a.useState(null),[m,h]=a.useState(""),[,u]=a.useState(!1),[b,p]=a.useState([]),w=a.useRef(0),[v,y]=a.useState(!1),[j,I]=a.useState(!1),g=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[M,k]=a.useState(g?"mouse":"touch"),[N,P]=a.useState(1),K=a.useRef(!1),[L,B]=a.useState(1),[T,S]=a.useState(0),[W,$]=a.useState(0);Ct("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:M,zoom:L,panX:T,panY:W,isMenuOpen:v,isImeOpen:j});const z=a.useRef(0),D=a.useRef(L),_=a.useRef(T),O=a.useRef(W);a.useEffect(()=>{D.current=L},[L]),a.useEffect(()=>{_.current=T},[T]),a.useEffect(()=>{O.current=W},[W]),a.useEffect(()=>{var J;(J=c.current)==null||J.focus()},[]);const A=n==="connected",q=r,ce=A?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",ne=A?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!g||K.current||!q)return;const J=l.current,R=d.current;if(!J||!R)return;const F=()=>{const te=R.clientWidth,ie=R.clientHeight,xe=J.naturalWidth,re=J.naturalHeight;if(!xe||!re||!te||!ie)return;const he=Math.min(te/xe,ie/re),Ce=Math.max(te/xe,ie/re)/he;Ce>1.01&&(P(Ce),B(Ce),D.current=Ce),K.current=!0};J.complete&&J.naturalWidth?F():J.addEventListener("load",F,{once:!0})},[q,g]);const Z=.5;a.useEffect(()=>{L<=Z&&(S(0),$(0))},[L,Z]);const Q=(J,R,F)=>{if(F<=Z)return{x:0,y:0};const te=(F-1)/(2*F)*100,ie=(F-1)/(2*F)*100;return{x:Math.max(-te,Math.min(te,J)),y:Math.max(-ie,Math.min(ie,R))}},E=(J,R)=>{if(!l.current)return null;const F=l.current.getBoundingClientRect();return!F.width||!F.height?null:{nx:Math.max(0,Math.min(1,(J-F.left)/F.width)),ny:Math.max(0,Math.min(1,(R-F.top)/F.height))}},G=(J,R,F)=>{const te=d.current;if(!te)return;const ie=te.getBoundingClientRect(),xe=++w.current;p(re=>[...re,{id:xe,x:J-ie.left,y:R-ie.top,type:F}]),setTimeout(()=>p(re=>re.filter(he=>he.id!==xe)),600)},H=(J,R,F)=>{const te=l.current,ie=d.current;if(!te||!ie)return;const xe=te.getBoundingClientRect(),re=ie.getBoundingClientRect(),he=te.naturalWidth||xe.width,We=te.naturalHeight||xe.height,Ce=he/We,mt=xe.width/xe.height;let qe,_e,Ee,et;Ce>mt?(qe=xe.width,_e=xe.width/Ce,Ee=0,et=(xe.height-_e)/2):(_e=xe.height,qe=xe.height*Ce,Ee=(xe.width-qe)/2,et=0);const Ge=xe.left-re.left+Ee+qe*J,tt=xe.top-re.top+et+_e*R,st=++w.current;p($e=>[...$e,{id:st,x:Ge,y:tt,type:F}]),setTimeout(()=>p($e=>$e.filter(ft=>ft.id!==st)),600)},C=async J=>{var F;const R=E(J.clientX,J.clientY);if(R){x(`Click: ${Math.round(R.nx*100)}%, ${Math.round(R.ny*100)}%`),G(J.clientX,J.clientY,"left"),(F=c.current)==null||F.focus();try{const te=await t("input_click",{nx:R.nx,ny:R.ny});te!=null&&te.success||s(`❌ Click failed: ${te==null?void 0:te.error}`)}catch(te){s(`❌ Click error: ${te.message||te}`)}}},X=async(J,R,F,te=0)=>{try{await t("input_key",{type:F?"char":"keyDown",key:J,code:R,text:F?J:void 0,unmodifiedText:F?J:void 0,modifiers:te})}catch(ie){s(`❌ Key error: ${ie.message||ie}`)}},Y=async J=>{if(J.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(J.key)&&J.preventDefault();let F=0;J.altKey&&(F|=1),J.ctrlKey&&(F|=2),J.metaKey&&(F|=4),J.shiftKey&&(F|=8),x(`Key: ${J.key}`),await X(J.key,J.code,J.key.length===1,F)},ee=async J=>{if(J.key==="Enter"){if(J.nativeEvent.isComposing)return;if(m){const R=m;h(""),x(`IME Sent: ${R}`);try{const F=await t("input_type",{text:R});F!=null&&F.success||s(`❌ IME error: ${F==null?void 0:F.error}`)}catch(F){s(`❌ IME error: ${F.message}`)}}else x("Key: Enter"),await X("Enter","Enter",!1)}};a.useEffect(()=>{const J=c.current;if(!J)return;const R=F=>{var te;if((te=l.current)!=null&&te.contains(F.target)){F.preventDefault();const ie=Date.now();if(ie-z.current<40)return;z.current=ie;const xe=E(F.clientX,F.clientY);if(!xe)return;x(`Scroll: ${Math.round(F.deltaY)}`),t("input_wheel",{nx:xe.nx,ny:xe.ny,deltaX:Math.round(F.deltaX),deltaY:Math.round(F.deltaY)}).catch(()=>{})}};return J.addEventListener("wheel",R,{passive:!1}),()=>J.removeEventListener("wheel",R)},[t]);const{cursorPos:ue,handleToggleInputMode:ae,handleZoomReset:me}=Va({containerRef:c,viewportRef:d,imgRef:l,inputMode:M,setInputMode:k,minZoom:Z,zoomRef:D,panXRef:_,panYRef:O,setPanX:S,setPanY:$,setZoom:B,lastWheelTimeRef:z,onAction:t,setLastActionStatus:x,spawnRippleFromNormalized:H,clampPan:Q,isMobile:g,mobileFillZoom:N});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:Y,onContextMenu:J=>J.preventDefault(),onFocus:()=>u(!0),onBlur:()=>u(!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(${L}) translate(${T}%, ${W}%)`,transformOrigin:"center center",cursor:M==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:C,onContextMenu:J=>J.preventDefault(),onDragStart:J=>J.preventDefault()}):e.jsx(Ha,{waitingLabel:ce,waitingHint:ne,transportType:o}),M==="mouse"&&q&&e.jsx(za,{cursorPos:ue,viewportRef:d,imgRef:l}),b.map(J=>{const F={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[J.type];return e.jsxs("div",{style:{position:"absolute",left:J.x,top:J.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${F}, 0.8)`,animation:"click-ripple-ring 0.5s ease-out forwards",position:"absolute",left:-20,top:-20}}),e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:`rgba(${F}, 0.9)`,boxShadow:`0 0 12px rgba(${F}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},J.id)})]}),e.jsx(Ua,{inputMode:M,onToggleInputMode:ae,isImeOpen:j,setIsImeOpen:I,isMenuOpen:v,setIsMenuOpen:y,imeText:m,setImeText:h,handleImeSubmit:ee,isConnActive:A,zoom:L,isMobile:g,mobileFillZoom:N,onZoomOut:()=>B(J=>Math.max(.5,J-.25)),onZoomReset:me,onZoomIn:()=>B(J=>Math.min(5,J+.25)),transportType:o,screenshotUsage:i,lastActionStatus:f}),e.jsx("style",{children:`
|
|
12
12
|
@keyframes slideUp {
|
|
13
13
|
from { opacity: 0; transform: translateY(6px); }
|
|
14
14
|
to { opacity: 1; transform: translateY(0); }
|
|
@@ -31,32 +31,32 @@ var Xr=Object.defineProperty;var Jr=(t,s,n)=>s in t?Xr(t,s,{enumerable:!0,config
|
|
|
31
31
|
50% { transform: translateY(-7px); }
|
|
32
32
|
100% { transform: translateY(0px); }
|
|
33
33
|
}
|
|
34
|
-
`})]})}function Fa(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 Hn=t=>Fa(t);function Va(t){return{unread:!!t.unread,lastSeenAt:t.lastSeenAt||0,lastUpdated:t.lastUpdated||0,inboxBucket:t.inboxBucket||"idle",surfaceHidden:!!t.surfaceHidden}}function ss(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 It(t){const s=new Map,n=(r,i)=>{r&&s.set(r,{sessionId:r,...Va(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 ut(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 St(t,s,n){const r=ut(t,s),i=ss(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,x=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:x,isReconnecting:o,isConnecting:c,isGenerating:d,isWaiting:l,inboxBucket:f?"needs_attention":x?"working":m?"task_complete":"idle"}}function qa(t,s,n){return St(t,s,{hideOpenTaskCompleteUnread:!0,isOpenConversation:n==null?void 0:n.isOpenConversation}).unread}function Ga(t,s,n){return ut(t,n||new Map).surfaceHidden}function Fn({activeConv:t,onModalButton:s}){const[n,r]=a.useState(null);if(a.useEffect(()=>{r(null)},[t.modalMessage,t.status,t.connectionState]),!ss(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(_s,{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(),x=/^(run|approve|accept|yes|allow|always)/.test(f),m=/^(reject|deny|delete|remove|abort)/.test(f),h=n===d,u=n!==null;return e.jsx("button",{onClick:()=>o(d),disabled:u,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${x?"bg-white font-extrabold":m?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${u&&!h?"opacity-40":"opacity-100"} ${u?"cursor-not-allowed":"cursor-pointer"}`,style:x?{color:"var(--status-warning)"}:void 0,children:h?"⏳ ...":c(d)},l)})})]})]})}const en=new Map,Ya={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"};function Xa({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:i,controls:o,controlValues:c,serverModel:d,serverMode:l}){const{sendCommand:f}=st(),x=`${t}:${s||r}`,m=Ya[r]||"#94a3b8",[h,u]=a.useState({}),b=a.useRef(0),p={...d?{model:d}:{},...l?{mode:l}:{},...c||{},...Date.now()<b.current?h:{}};a.useEffect(()=>{c&&Date.now()>b.current&&u({})},[c]);const[w,v]=a.useState(en.get(x)||{}),[y,j]=a.useState(null),[I,g]=a.useState(null),M=a.useCallback(async(T,S={})=>{const W={...S,...s&&{targetSessionId:s}};return await f(t,T,W)},[t,s,f]);if(!o||o.length===0)return null;const k=o.filter(T=>T.placement==="bar").sort((T,S)=>(T.order??50)-(S.order??50));if(k.length===0)return null;const N=async T=>{var W,$,z;if(y===T.id){j(null);return}if((((W=T.options)==null?void 0:W.map(E=>E.value))||w[T.id]||[]).length>0){j(T.id);return}if(T.dynamic&&T.listScript){g(T.id);try{const E=await M(T.listScript==="listModels"?"list_extension_models":T.listScript==="listModes"?"list_extension_modes":T.listScript,{agentType:r,ideType:n}),O=((E==null?void 0:E.models)||(E==null?void 0:E.modes)||(($=E==null?void 0:E.result)==null?void 0:$.models)||((z=E==null?void 0:E.result)==null?void 0:z.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,[T.id]:O};return en.set(x,q),q}),j(T.id)}catch{}finally{g(null)}}},P=async(T,S)=>{j(null),u(W=>({...W,[T.id]:S})),b.current=Date.now()+5e3;try{if(!T.setScript)return;const W=ds(T.setScript,r);await M(W,{agentType:r,ideType:n,model:T.id==="model"?S:void 0,mode:T.id==="mode"?S:void 0,value:S})}catch{}},K=async T=>{var _;const S=((_=T.options)==null?void 0:_.map(O=>O.value))||w[T.id]||[];if(S.length===0)return;const W=String(p[T.id]||""),z=(S.indexOf(W)+1)%S.length,E=S[z];if(typeof E=="string"){u(O=>({...O,[T.id]:E})),b.current=Date.now()+5e3;try{if(!T.setScript)return;const O=ds(T.setScript,r);await M(O,{agentType:r,ideType:n,value:E})}catch{}}},L=async T=>{const W=!p[T.id];u($=>({...$,[T.id]:W})),b.current=Date.now()+5e3;try{if(!T.setScript)return;const $=ds(T.setScript,r);await M($,{agentType:r,ideType:n,value:W})}catch{}},B=async T=>{if(T.invokeScript)try{await M("invoke_extension_script",{agentType:r,ideType:n,scriptName:T.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-[var(--surface-primary)]",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:"│"}),k.map(T=>{var E;const S=String(p[T.id]||""),W=y===T.id,$=I===T.id,z=((E=T.options)==null?void 0:E.map(_=>_.value))||w[T.id]||[];switch(T.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:()=>N(T),children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),$?"...":S||T.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),W&&z.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>j(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:T.label.toUpperCase()}),z.map(_=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:_===S?`${m}18`:"transparent",color:_===S?m:"var(--text-secondary)",fontWeight:_===S?600:400,borderLeft:_===S?`2px solid ${m}`:"2px solid transparent"},onMouseEnter:O=>{O.currentTarget.style.background=`${m}12`},onMouseLeave:O=>{O.currentTarget.style.background=_===S?`${m}18`:"transparent"},onClick:()=>P(T,_),children:_},_))]})]})]},T.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:()=>K(T),title:`Click to cycle: ${z.join(" → ")}`,children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),S||T.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"⟳"})]},T.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:()=>L(T),children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),T.label]},T.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:()=>B(T),children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),T.label]},T.id);default:return null}})]})}function ds(t,s){return{setModel:"set_extension_model",setMode:"set_extension_mode",setThinkingLevel:"set_thought_level"}[t]||t}const Ja=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 x=f.clipboardData.getData("text");x&&d(m=>m+x),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 x=f.relatedTarget;if((x==null?void 0:x.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 Za=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function Qa(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function _e(t,s){if(Qa(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":Za.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 Vn(t){return _e(t)==="generating"}function Ie(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function ei(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 tn(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function qn(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 ti(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 si(t){const s=t.trim().toLowerCase();return s.startsWith("mach_")||s.startsWith("standalone_mach_")||s.startsWith("daemon_mach_")}function ni(t){return ti(t.trim().replace(/\.local$/i,""))}function ri(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function Gn(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&&!si(c));if(n&&n!=="Unknown")return ni(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function qe(t,s={}){return ri(t)||Gn(t,s)}function qt(t){return t.transport==="pty"}function yt(t){return t.transport==="acp"}function sn(t,s){return Ie(t)}function ai(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 ii(t){return _e(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function oi(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=_e(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 us(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 ci(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&&(us(s.timestamp)||us(s.receivedAt)||us(s.createdAt))||0}function li(t){return(t.recentLaunches||[]).reduce((n,r)=>Math.max(n,r.lastLaunchedAt||0),0)}function Gt(t){return Math.max(li(t),ci(t.activeChat))}function di(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 ui(t,s){return di(Gt(t),Gt(s),qe(t,{fallbackId:t.id}),qe(s,{fallbackId:s.id}),t.id,s.id)}function Yn({conversation:t,className:s="",onOpenNativeConversation:n,onOpenMachine:r}){var m;const i=mt(),o=t.daemonId||((m=t.ideId)==null?void 0:m.split(":")[0])||t.ideId,c=t.transport==="cdp-page"||t.transport==="cdp-webview",d=t.streamSource==="agent-stream"&&!!t.agentName,l=(()=>{var h,u;if(t.streamSource==="agent-stream"){const b=(u=(h=t.displaySecondary)==null?void 0:h.split("·")[0])==null?void 0:u.trim();if(b)return b}return Ie(t.ideType||"")})(),f=a.useCallback(()=>{if(r){r();return}o&&i("/dashboard",{state:{openMachineId:o}})},[o,i,r]),x=a.useCallback(()=>{if(n){n();return}const h=t.streamSource==="agent-stream"?t.nativeSessionId:t.sessionId;h&&i(`/dashboard?activeTab=${encodeURIComponent(h)}`)},[t.nativeSessionId,t.sessionId,t.streamSource,i,n]);return e.jsxs("div",{className:`conversation-meta-chips ${s}`.trim(),children:[c&&e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:x,title:l,children:[e.jsx(Le,{size:12}),e.jsx("span",{children:l})]}),d&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:t.agentName,children:[e.jsx(xt,{size:12}),e.jsx("span",{children:t.agentName})]}),t.machineName&&e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:f,title:t.machineName,children:[e.jsx(Ts,{size:12}),e.jsx("span",{children:t.machineName})]})]})}const Ne=t=>t.transport==="pty",pt=(t,s)=>Ne(t)?s||t.mode||"terminal":"chat",Xn=(t,s)=>Ne(t)&&pt(t,s)==="terminal",je=t=>t.transport==="acp";function nn(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 rn(t){const s=[];for(const n of t){const r=nn(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&&nn(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 xi=60,pi=60;function ws({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:x}=st();Ct("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:r});const m=Is.useMemo(()=>ss(t),[t.status,t.connectionState]),h=a.useRef(new Map),u=a.useCallback(S=>(h.current.has(S)||h.current.set(S,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:xi}),h.current.get(S)),[]),b=a.useCallback((S,W)=>{const $=u(S);h.current.set(S,{...$,...W}),p(z=>z+1)},[u]),[,p]=a.useState(0),w=t.tabKey,v=u(w),y=v.messages,j=v.hasMore,I=v.error,g=Math.max(0,t.messages.length-v.visibleLiveCount),[M,k]=a.useState(!1),N=a.useCallback(async()=>{var $,z;if(M)return;const S=t.tabKey,W=u(S);if(t.messages.length>W.visibleLiveCount){b(S,{visibleLiveCount:Math.min(t.messages.length,W.visibleLiveCount+pi),error:null});return}k(!0),b(S,{error:null});try{const E=(s==null?void 0:s.daemonId)||(($=t.ideId)==null?void 0:$.split(":")[0])||"";if(!E){b(S,{hasMore:!1});return}const _=t.ideType||t.agentType||"",O=await x(E,"chat_history",{agentType:_,offset:W.offset,limit:30,targetSessionId:t.sessionId,historySessionId:t.providerSessionId||t.sessionId}),A=(O==null?void 0:O.result)??O;if(((z=A.messages)==null?void 0:z.length)>0){const q=u(S);b(S,{messages:[...A.messages,...q.messages],offset:q.offset+A.messages.length,hasMore:!!A.hasMore})}else b(S,{hasMore:!!A.hasMore})}catch(E){const _=(E==null?void 0:E.message)||"";_.includes("P2P not available")||_.includes("channel not open")||_.includes("P2P not connected")||_.includes("timeout")?b(S,{error:"Connection not ready — tap to retry"}):b(S,{hasMore:!1,error:"Failed to load history"})}finally{k(!1)}},[M,s,t,x,u,b]),{allMessages:P,receivedAtMap:K}=a.useMemo(()=>{const S=g>0?t.messages.slice(-v.visibleLiveCount):t.messages;if(y.length===0){const _=rn(S),O={};return _.forEach((A,q)=>{const ce=`${t.tabKey}:${dt(A,q)}`;let re=A.receivedAt||f.current.get(ce)||0;re||(re=Date.now(),f.current.set(ce,re)),O[dt(A,q)]=re}),{allMessages:_,receivedAtMap:O}}const W=new Set(S.map(_=>`${_.role}:${(_.content||"").slice(0,100)}`)),$=y.filter(_=>!W.has(`${_.role}:${(_.content||"").slice(0,100)}`)),z=rn([...$,...S]),E={};return z.forEach((_,O)=>{const A=`${t.tabKey}:${dt(_,O)}`;let q=_.receivedAt||f.current.get(A)||0;q||(q=Date.now(),f.current.set(A,q)),E[dt(_,O)]=q}),{allMessages:z,receivedAtMap:E}},[t.messages,t.tabKey,g,y,v.visibleLiveCount]),L=a.useMemo(()=>c.filter(S=>S.ideId===t.tabKey).sort((S,W)=>S.timestamp-W.timestamp),[c,t.tabKey]),B=t.displayPrimary||t.agentName||"Agent",T=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")&&k(!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(xt,{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(vs,{size:14})," Open ",B," 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(Kn,{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(vs,{size:14})," Open ",B," 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,B,m.isGenerating]);return e.jsxs("div",{className:"flex-1 min-h-0 w-full flex flex-col",children:[l&&e.jsx(Yn,{conversation:t,className:"chat-pane-meta-row"}),e.jsx(Ka,{messages:P,actionLogs:L,agentName:t.agentName||t.displayPrimary||"Agent",userName:d,isCliMode:Ne(t)||je(t),isWorking:m.isGenerating,contextKey:t.tabKey,receivedAtMap:K,onLoadMore:N,isLoadingMore:M,hasMoreHistory:j,hiddenLiveCount:g,loadError:I??void 0,emptyState:T}),!Xn(t)&&(()=>{const S=t.streamSource!=="agent-stream",W=S?t.ideType:t.agentType,$=S?s!=null&&s.type?Ie(s.type):Ie(t.ideType||""):t.agentName||Ie(t.agentType||""),z=!S&&(s!=null&&s.childSessions)&&s.childSessions.find(O=>O.id===t.sessionId||O.providerType===t.agentType)||s,E=z==null?void 0:z.providerControls,_=z==null?void 0:z.controlValues;return e.jsx(Xa,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:W,displayLabel:$,controls:E,controlValues:_,serverModel:(z==null?void 0:z.currentModel)||void 0,serverMode:(z==null?void 0:z.currentPlan)||void 0,acpConfigOptions:je(t)?z==null?void 0:z.acpConfigOptions:void 0,acpModes:je(t)?z==null?void 0:z.acpModes:void 0})})(),e.jsx(Ja,{contextKey:t.tabKey,panelLabel:B,isSending:r,onSend:n})]})}let Jn=Nt;function Es(){return Jn()}class mi{constructor(){Ce(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,n){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(n),()=>{var r;(r=this.listeners.get(s))==null||r.delete(n)}}emit(s,...n){var r;(r=this.listeners.get(s))==null||r.forEach(i=>i(...n))}}let Zn=new mi;class fi{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 we=new fi;function hi(t){t.dashboardWS&&(Zn=t.dashboardWS),t.connectionManager&&(we=t.connectionManager),t.useDaemonsHook&&(Jn=t.useDaemonsHook)}function gi({activeConv:t,clearToken:s=0,terminalRef:n,handleSendChat:r,isSendingChat:i=!1,isVisible:o=!0}){var L;const c=a.useRef(null),{sendCommand:d,sendData:l}=st(),[f,x]=a.useState(""),[m,h]=a.useState(!1),u=a.useRef(0),b=a.useRef(!1),p=a.useRef(""),w=a.useRef(null),v=a.useRef(!1),y=a.useRef(null),j=t.tabKey,I=t.sessionId||"",g=t.daemonId||((L=t.ideId)==null?void 0:L.split(":")[0])||t.ideId||"",M=()=>{var B,T;u.current=0,b.current=!1,p.current="",w.current=null,v.current=!1,y.current!==null&&(cancelAnimationFrame(y.current),y.current=null),h(!1),(T=(B=n.current)==null?void 0:B.reset)==null||T.call(B)},k=()=>{var B,T;u.current=0,b.current=!1,p.current="",w.current=null,v.current=!1,y.current!==null&&(cancelAnimationFrame(y.current),y.current=null),h(!0),(T=(B=n.current)==null?void 0:B.reset)==null||T.call(B)},N=()=>{var T;if(y.current=null,!o)return;const B=p.current;B&&(p.current="",(T=n.current)==null||T.write(B))},P=B=>{B&&(p.current+=B,o&&y.current===null&&(y.current=requestAnimationFrame(N)))},K=(B,T=0,S,W)=>{var $,z,E,_,O;T>0&&u.current>=T||T===0&&b.current||(u.current=T,h(!0),typeof S=="number"&&typeof W=="number"&&S>0&&W>0&&((z=($=n.current)==null?void 0:$.resize)==null||z.call($,S,W)),(_=(E=n.current)==null?void 0:E.reset)==null||_.call(E),B&&((O=n.current)==null||O.write(B)))};return a.useEffect(()=>{M()},[I]),a.useEffect(()=>{var T;if(!I)return;const B=((T=we.onRuntimeEvent)==null?void 0:T.call(we,I,S=>{if(!(!S||S.sessionId!==I)){if(S.type==="runtime_snapshot"){if(!o){w.current={text:S.text||"",seq:S.seq||0,cols:S.cols,rows:S.rows};return}K(S.text||"",S.seq||0,S.cols,S.rows);return}if(S.type==="session_output"){b.current=!0,typeof S.seq=="number"&&(u.current=Math.max(u.current,S.seq)),m||h(!0),typeof S.data=="string"&&P(S.data);return}if(S.type==="session_cleared"){if(!o){v.current=!0,p.current="",w.current=null;return}k()}}}))||(()=>{});return()=>{B()}},[g,I,n,o,m]),a.useEffect(()=>{var T,S,W;if(!I)return;g&&((T=we.getState)==null?void 0:T.call(we,g))==="connected"&&(h(!0),(S=we.requestRuntimeSnapshot)==null||S.call(we,g,I).catch(()=>{}));const B=(W=we.onStateChange)==null?void 0:W.call(we,($,z)=>{var E;$!==g||z!=="connected"||(h(!0),(E=we.requestRuntimeSnapshot)==null||E.call(we,g,I).catch(()=>{}))});return()=>{B==null||B()}},[g,I,n]),a.useEffect(()=>{s&&M()},[s,j,n]),a.useEffect(()=>{x("")},[t.tabKey]),a.useEffect(()=>{var T;if(!o){(T=c.current)==null||T.blur();return}v.current&&(v.current=!1,k());const B=w.current;B&&(w.current=null,K(B.text,B.seq,B.cols,B.rows)),p.current&&y.current===null&&(y.current=requestAnimationFrame(N))},[o]),a.useEffect(()=>()=>{y.current!==null&&(cancelAnimationFrame(y.current),y.current=null)},[]),a.useEffect(()=>{const B=T=>{var W;const S=T.detail;S!=null&&S.sessionId&&S.sessionId!==I||m&&((W=n.current)==null||W.fit())};return window.addEventListener("adhdev:fit-cli-terminal",B),()=>{window.removeEventListener("adhdev:fit-cli-terminal",B)}},[m,I,n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx(zn,{ref:n,readOnly:!m||!o,onInput:B=>{m&&(l!=null&&l(g,{type:"pty_input",targetSessionId:I,data:B})||d(g,"pty_input",{targetSessionId:I,data:B}).catch(console.error))},onResize:(B,T)=>{m&&(l!=null&&l(g,{type:"pty_resize",targetSessionId:I,cols:B,rows:T})||d(g,"pty_resize",{targetSessionId:I,cols:B,rows:T,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:B=>x(B.target.value),onPaste:B=>{const T=B.clipboardData.getData("text");T&&x(S=>S+T),B.preventDefault()},onKeyDown:B=>{if(B.key!=="Enter")return;if(B.nativeEvent.isComposing){B.preventDefault();return}B.preventDefault();const T=f.trim();!m||!T||i||(x(""),r(T))},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 B=f.trim();!m||!B||i||(x(""),r(B))},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 bi({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 yi({terminalBackend:t,isStandalone:s=!1}){return!s||!t||t.backend!=="xterm"?null:e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",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.jsx("span",{children:"Terminal 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."})]})}function Ds({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(Ls,{size:r}):e.jsx(tt,{size:r})})}function an({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 vi({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,conversations:i,onOpenHistory:o,onOpenRemote:c,onStopCli:d,activeCliViewMode:l,onSetCliViewMode:f,onOpenConversation:x,onHideConversation:m,hiddenConversations:h=[],onShowConversation:u,onShowAllHidden:b}){const p=Es(),w=p.p2pStates||{},v=p.ides||[],y=!!t&&Ne(t)&&!je(t),j=l||(t?Xn(t)?"terminal":"chat":null),[I,g]=a.useState(!1),[M,k]=a.useState(!1),[N,P]=a.useState(!1),K=a.useRef(null),L=a.useRef(null),B=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",T=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",S=v.filter(Z=>Z.type==="adhdev-daemon"),W=a.useMemo(()=>It(v),[v]),$=Object.values(w),z=$.filter(Z=>Z==="connected").length,E=$.filter(Z=>Z==="connecting"||Z==="new"||Z==="checking").length,O=n!=="connected"||S.length===0?null:E>0&&z===0?"P2P connecting...":z>0&&s===0?"Waiting for IDE...":null,A=a.useMemo(()=>i.filter(Z=>!Ga(Z,i,W)),[i,W]),q=a.useMemo(()=>A.filter(Z=>St(Z,W).requiresAction),[A,W]),ce=a.useMemo(()=>A.filter(Z=>{const D=(t==null?void 0:t.tabKey)===Z.tabKey;return St(Z,W,{hideOpenTaskCompleteUnread:!0,isOpenConversation:D}).unread}),[t,A,W]),re=q.length+ce.length;a.useEffect(()=>{if(!I)return;const Z=D=>{var G;(G=K.current)!=null&&G.contains(D.target)||g(!1)};return document.addEventListener("mousedown",Z),()=>document.removeEventListener("mousedown",Z)},[I]),a.useEffect(()=>{if(!M)return;const Z=D=>{var G;(G=L.current)!=null&&G.contains(D.target)||k(!1)};return document.addEventListener("mousedown",Z),()=>document.removeEventListener("mousedown",Z)},[M]);const J=Z=>{if(!Z)return;const D=i.find(G=>G.tabKey===Z);D&&(m==null||m(D))};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(tt,{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:B,boxShadow:T}})})]}),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:B,boxShadow:T}}),O&&e.jsxs("span",{className:"header-subtitle-status",children:["· ",O]})]})]})})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&(y||!je(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&&j&&e.jsx(Ds,{mode:j,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(Vt,{size:14})})]}),!je(t)&&e.jsx("button",{onClick:()=>o(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(As,{size:14})}),!y&&!je(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Le,{size:14})})]}),e.jsxs("div",{className:"dashboard-header-inbox",ref:K,children:[e.jsxs("div",{className:`dashboard-header-hidden${N?" is-drop-target":""}`,ref:L,onDragEnter:Z=>{Z.dataTransfer.types.includes("text/tab-key")&&(Z.preventDefault(),P(!0))},onDragOver:Z=>{Z.dataTransfer.types.includes("text/tab-key")&&(Z.preventDefault(),Z.dataTransfer.dropEffect="move",P(!0))},onDragLeave:Z=>{Z.currentTarget.contains(Z.relatedTarget)||P(!1)},onDrop:Z=>{const D=Z.dataTransfer.getData("text/tab-key");Z.preventDefault(),P(!1),J(D)},children:[e.jsxs("button",{type:"button",onClick:()=>k(Z=>!Z),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:"Hidden tabs. Drag a tab here to hide it.",children:[e.jsx(Na,{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&&b&&e.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{b(),k(!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(Z=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{u==null||u(Z),k(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:Z.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:Z.displaySecondary})]},Z.tabKey))}):e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),e.jsxs("button",{type:"button",onClick:()=>g(Z=>!Z),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(ts,{size:16}),re>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:re})]}),I&&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(Z=>e.jsx(an,{conversation:Z,isAttention:!0,onClick:()=>{x==null||x(Z),g(!1)}},Z.tabKey))]}),ce.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),ce.map(Z=>e.jsx(an,{conversation:Z,onClick:()=>{x==null||x(Z),g(!1)}},Z.tabKey))]}),re===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function ji(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 wi({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,savedSessions:i=[],isSavedSessionsLoading:o=!1,isResumingSavedSessionId:c=null,onClose:d,onNewChat:l,onSwitchSession:f,onRefreshHistory:x,onResumeSavedSession:m}){var w;const h=s.find(v=>v.id===t.ideId),u=(h==null?void 0:h.chats)||[],b=(w=h==null?void 0:h.activeChat)==null?void 0:w.id,p=Ne(t)&&!je(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:p?"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:[!p&&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"}),p?e.jsx(e.Fragment,{children:i.map(v=>{const y=t.providerSessionId===v.providerSessionId,j=y||!v.canResume||!!c;return e.jsxs("button",{type:"button",onClick:()=>{j||!m||m(v)},disabled:j,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"} ${j?"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:ji(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)})}):u.map(v=>e.jsxs("div",{onClick:()=>{f(t.ideId,v.id),d()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${b===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 ${b===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),"..."]}),b===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)),(p&&!o&&i.length===0||!p&&u.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(Ta,{size:32})}),e.jsx("div",{className:"text-[13px]",children:p?"No saved sessions found yet.":"No recent chat sessions found."})]}),p&&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:x,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(Rs,{size:13})," ",p?"Refresh Sessions":"Refresh History"]})})})]})]})}const on={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 Qn({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:on[r.type]||on.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 er(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 ki=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Ni(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function Si(t){return t.sessionId||t.instanceId||t.agentType}function xs(t,s){return t||s}function Lt(t){return er(t)}function cn(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 tr(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=qe(r,{fallbackId:r.id}))}return s}function sr(t,s,n={}){var h,u,b,p,w,v;const r=[],i=n.machineName,o=n.connectionState,c=Ni(t),d=Ie(t.type),l=Array.isArray(t.childSessions)?t.childSessions.map(y=>{var j,I;return{sessionId:y.id,instanceId:y.id,providerSessionId:y.providerSessionId,agentType:y.providerType,agentName:y.providerName,status:y.status,title:y.title,messages:((j=y.activeChat)==null?void 0:j.messages)||[],activeModal:((I=y.activeChat)==null?void 0:I.activeModal)||void 0,unread:y.unread,lastSeenAt:y.lastSeenAt,lastUpdated:y.lastUpdated,inboxBucket:y.inboxBucket,surfaceHidden:y.surfaceHidden}}):[],f=ki(t),x=t.activeChat||{title:""},m=x.title&&String(x.title).trim()?String(x.title).trim():"";if(f){const y=t.sessionId||t.instanceId,j=sn(t.type),I=(h=t.activeChat)==null?void 0:h.activeModal,g=I&&Array.isArray(I.buttons)&&I.buttons.length>0,M=_e((u=t.activeChat)==null?void 0:u.status,{activeModal:(b=t.activeChat)==null?void 0:b.activeModal})||_e((w=(p=t.agents)==null?void 0:p[0])==null?void 0:w.status)||"idle",k=t.activeChat||{title:"",messages:[]};let N=k.title&&String(k.title).trim()?String(k.title).trim():"";const P=(v=t.activeChat)==null?void 0:v.id,K=t.chats;if(P&&Array.isArray(K)&&K.length>0){const W=K.find($=>$.id===P||$.id&&String($.id)===String(P));W!=null&&W.title&&String(W.title).trim()&&(N=String(W.title).trim())}const L=k.messages||[],B=cn(s,[t.id,y]),T=new Map;L.filter(W=>W.role==="user").forEach(W=>{const $=Lt(W.content);$&&T.set($,(T.get($)||0)+1)});const S=B.filter(W=>{const $=Lt(W.content),z=T.get($)||0;return z>0?(T.set($,z-1),!1):!0});r.push({ideId:t.id,sessionId:y,providerSessionId:t.providerSessionId,nativeSessionId:y,transport:t.transport,daemonId:t.daemonId||void 0,mode:Ne(t)?t.mode||"terminal":"chat",agentName:j,agentType:(Ne(t)||je(t))&&(t.cliType||t.acpType)||t.type,status:M,title:N,messages:[...L,...S],resume:t.resume,ideType:t.cliType||t.acpType||t.type,workspaceName:c,displayPrimary:N||c||(Ne(t)?t.mode==="chat"?j:"Terminal":j),displaySecondary:d,cdpConnected:t.cdpConnected,modalButtons:g?I.buttons:void 0,modalMessage:g?I.message:void 0,streamSource:"native",tabKey:xs(y,t.id),machineName:i,connectionState:o})}if(f&&(Ne(t)||je(t)))return r;for(const y of l){const j=y.activeModal&&Array.isArray(y.activeModal.buttons)&&y.activeModal.buttons.length>0,I=ii(y),g=Si(y),M=`${t.id}:${g}`,k=y.title&&String(y.title).trim()||"",N=ai(k,y.agentName,y.agentType)?"":k,P=y.messages||[],K=cn(s,[M,y.sessionId,y.instanceId]),L=new Map;P.filter(S=>S.role==="user").forEach(S=>{const W=Lt(S.content);W&&L.set(W,(L.get(W)||0)+1)});const B=K.filter(S=>{const W=Lt(S.content),$=L.get(W)||0;return $>0?(L.set(W,$-1),!1):!0});(P.length>0||B.length>0||j||N||!["idle","panel_hidden","disconnected","not_monitored"].includes(I))&&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:I,title:N,messages:[...P,...B],ideType:y.agentType,workspaceName:c,displayPrimary:N||m||c||d,displaySecondary:`${d}·${y.agentName}`,cdpConnected:t.cdpConnected,modalButtons:j?y.activeModal.buttons:void 0,modalMessage:j?y.activeModal.message:void 0,streamSource:"agent-stream",tabKey:xs(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:sn(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:xs(t.sessionId||t.instanceId,t.id),connectionState:o}),r}function Ci(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 Ii(t,s){const n=[],{daemonId:r,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now(),d=t.sessions||[],{topLevel:l,childrenByParent:f}=Ci(d),x=l.filter(u=>u.kind==="workspace"&&u.transport==="cdp-page"),m=l.filter(u=>u.kind==="agent"&&u.transport==="pty"),h=l.filter(u=>u.kind==="agent"&&u.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:x.some(u=>!!u.cdpConnected)});for(const u of x){const b=f.get(u.id)||[];n.push({id:`${r}:ide:${u.id}`,sessionId:u.id,providerSessionId:u.providerSessionId,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,status:u.cdpConnected?"online":"detected",daemonId:r,instanceId:u.id,workspace:u.workspace,terminals:0,childSessions:b,agents:b.map(p=>({id:p.id,name:p.providerName,type:p.providerType,status:p.status})),activeChat:u.activeChat,chats:[],cdpConnected:u.cdpConnected,currentModel:u.currentModel,currentPlan:u.currentPlan,currentAutoApprove:u.currentAutoApprove,lastUpdated:u.lastUpdated,unread:u.unread,lastSeenAt:u.lastSeenAt,inboxBucket:u.inboxBucket,surfaceHidden:u.surfaceHidden,controlValues:u.controlValues,providerControls:u.providerControls,timestamp:c})}for(const u of m)n.push({id:`${r}:cli:${u.id}`,sessionId:u.id,providerSessionId:u.providerSessionId,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,agentType:u.providerType,status:u.status||"running",daemonId:r,instanceId:u.id,cliName:u.providerName,mode:u.mode||"terminal",workspace:u.workspace||"",activeChat:u.activeChat,resume:u.resume,runtimeKey:u.runtimeKey,runtimeDisplayName:u.runtimeDisplayName,runtimeWorkspaceLabel:u.runtimeWorkspaceLabel,runtimeWriteOwner:u.runtimeWriteOwner??null,runtimeAttachedClients:u.runtimeAttachedClients??[],lastUpdated:u.lastUpdated,unread:u.unread,lastSeenAt:u.lastSeenAt,inboxBucket:u.inboxBucket,surfaceHidden:u.surfaceHidden,controlValues:u.controlValues,providerControls:u.providerControls,timestamp:c,_isCli:!0});for(const u of h)n.push({id:`${r}:acp:${u.id}`,sessionId:u.id,providerSessionId:u.providerSessionId,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,agentType:u.providerType,status:u.status||"running",daemonId:r,instanceId:u.id,cliName:u.providerName,mode:"chat",workspace:u.workspace||"",activeChat:u.activeChat,runtimeKey:u.runtimeKey,runtimeDisplayName:u.runtimeDisplayName,runtimeWorkspaceLabel:u.runtimeWorkspaceLabel,runtimeWriteOwner:u.runtimeWriteOwner??null,runtimeAttachedClients:u.runtimeAttachedClients??[],currentModel:u.currentModel,currentPlan:u.currentPlan,lastUpdated:u.lastUpdated,unread:u.unread,lastSeenAt:u.lastSeenAt,inboxBucket:u.inboxBucket,surfaceHidden:u.surfaceHidden,acpConfigOptions:u.acpConfigOptions,acpModes:u.acpModes,controlValues:u.controlValues,providerControls:u.providerControls,timestamp:c,_isAcp:!0});return n}function Mi(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 Ti(t,s){const n=Mi(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const nr=[{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:"💚"}],rr=[{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:"🧩"}],ar=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],ir="adhdev_notification_prefs",ln={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function Ai(){try{const t=localStorage.getItem(ir);if(t){const s=JSON.parse(t);return{...ln,...s}}}catch{}return{...ln}}function Ri(t){try{localStorage.setItem(ir,JSON.stringify(t))}catch{}}let ze=Ai(),Wt=[];function _i(){Wt.forEach(t=>t())}function Li(){return{...ze}}function Ei(t){ze={...ze,...t},Ri(ze),_i()}function Di(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return Wt.push(n),()=>{Wt=Wt.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{Ei(n)},[]);return[{...ze},s]}function vt(t){if(!ze.globalEnabled)return!1;switch(t){case"disconnect":return ze.disconnectAlert;case"completion":return ze.completionAlert;case"approval":return ze.approvalAlert;case"browser":return ze.browserNotifications;default:return!0}}const $i={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Pi(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function or(){return"Notification"in window&&Notification.permission==="granted"}let nt=null;async function Bi(){if(nt!==null)return nt;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return nt=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(nt=!!await t.pushManager.getSubscription(),nt):(nt=!1,!1)}catch{return nt=!1,!1}}function ks(t,s,n){if(or())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 Ki(t,s={}){const n={...$i,...s},r=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{Bi().then(d=>{o.current=d})},[]);const c=a.useCallback((d,l,f)=>{const x=Date.now();x-i.current<n.throttleMs||(i.current=x,ks(d,l,f))},[n.throttleMs]);a.useEffect(()=>{var d;if(!(!n.enabled||!or())&&vt("browser")&&o.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,_e(l.status,{activeModal:l.activeModal}));return}for(const l of t){const f=r.current.get(l.id),x=_e(l.status,{activeModal:l.activeModal}),m=l.name||l.id;if(n.onApproval&&vt("approval")&&x==="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&&vt("completion")&&Vn(f)&&x==="idle"&&c(`✅ ${m} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&x==="error"&&f!=="error"&&c(`⚠️ ${m} — Error`,"Agent encountered an error",`error-${l.id}`),r.current.set(l.id,x)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class Wi{constructor(){Ce(this,"dedupMap",new Map);Ce(this,"DEDUP_WINDOW_MS",5e3);Ce(this,"DEDUP_MAX_SIZE",50);Ce(this,"DEDUP_CLEANUP_AGE_MS",1e4);Ce(this,"toastCallbacks",[]);Ce(this,"systemMessageCallbacks",[]);Ce(this,"clearSystemMessageCallbacks",[]);Ce(this,"resolveActionFn",null);Ce(this,"viewRequestRespondFn",null);Ce(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(n=>n!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(n=>n!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(n=>n!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const n of this.toastCallbacks)n(s)}showToast(s,n="info",r){const 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 x,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=qe(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&&Li().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",u=(x=s.modalButtons)!=null&&x.length?s.modalButtons.map(b=>`[${b}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${h}
|
|
36
|
-
${u}`,_localId:`sys_approval_${Date.now()}`})}if((m=s.modalButtons)!=null&&m.length&&this.resolveActionFn){const h=this.resolveActionRouteTarget(s);if(!h)return;const u=s.agentType||s.ideType||"",b=s.ideType||"",p=s.modalButtons,w=g=>g.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),v=this.resolveActionFn,y=p.map((g,M)=>{const k=w(g).toLowerCase(),N=/^(run|approve|accept|yes|allow|always)/.test(k),P=/^(reject|deny|delete|remove|abort|cancel|no)/.test(k);return{label:w(g),variant:N?"primary":P?"danger":"default",onClick:()=>{const K=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(k);v(h,"resolve_action",{action:K?"approve":"reject",button:g,buttonIndex:M,agentType:u,ideType:b,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),j=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,I=Date.now();this.emitToast({id:I,message:j,type:f,timestamp:I,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",vt("browser")&&!document.hasFocus()&&ks(`⚠️ ${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",u=s.requestId,b=s.orgId;if(l=`👁️ ${h} wants to view your session`,f="warning",u&&b&&this.viewRequestRespondFn){const p=this.viewRequestRespondFn,w=Date.now(),v=[{label:"Approve",variant:"primary",onClick:()=>{p(b,u,"approve").catch(y=>console.error("[EventManager] approve view request failed:",y))}},{label:"Decline",variant:"danger",onClick:()=>{p(b,u,"reject").catch(y=>console.error("[EventManager] reject view request failed:",y))}}];this.emitToast({id:w,message:l,type:f,timestamp:w,actions:v,duration:3e4}),l=""}vt("browser")&&!document.hasFocus()&&ks("👁️ View Request",`${h} wants to view your session`,`view-request-${u}`)}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 Qe=new Wi;function ot(...t){return ea(ta(t))}function Oi({icon:t,title:s,subtitle:n,badge:r,actions:i,className:o}){return e.jsxs("div",{className:ot("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 Yt({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(Oi,{icon:t,title:s,subtitle:n,badge:r,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:ot("mx-auto flex w-full flex-col gap-4",o,c),children:d})})]})}function Ae({title:t,icon:s,description:n,accentColor:r,className:i,children:o}){return e.jsxs("div",{className:ot("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 $s({icon:t,title:s,description:n,action:r,className:i}){return e.jsxs("div",{className:ot("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 zi={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"},Ui={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function Hi({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:ot("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",zi[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:Ui[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 Fi={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"},Vi={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function qi({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:ot("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Fi[t],n),children:[e.jsx("span",{className:ot("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Vi[t])}),r]})}function Gi(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Ns(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function Ot(t){return t==="system"?Gi():t}function Yi(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Ot(Ns()))}function cr(){const[t,s]=a.useState(Ns),[n,r]=a.useState(()=>Ot(Ns()));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(Ot(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const d=c==="dark"?"light":c==="light"?"system":"dark";r(Ot(d));try{localStorage.setItem("theme",d)}catch{}return d})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function et({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 Xi({onPrefChange:t}){const[s,n]=Di(),r=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(et,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ts,{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(et,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange: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(et,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Aa,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(et,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ra,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(et,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(xt,{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(et,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(tt,{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 Ji({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($s,{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(Qi,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i},c.id))})}function dn({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 sa.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 Zi(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...nr,...rr,...ar].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 Qi({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){var S,W;const[o,c]=a.useState("idle"),[d,l]=a.useState(""),[f,x]=a.useState(null),[m,h]=a.useState("idle"),[u,b]=a.useState(""),p=t,w=p.version||p.daemonVersion||null,v=((S=p.machine)==null?void 0:S.platform)||((W=p.system)==null?void 0:W.platform)||"",y=qe(p,{fallbackId:t.id}),j=v==="win32"?"🪟":v==="darwin"?"🍎":"🐧",I=s.filter($=>$.daemonId===t.id&&$.transport==="cdp-page"),g=s.filter($=>$.daemonId===t.id&&$.transport==="pty"),M=s.filter($=>$.daemonId===t.id&&$.transport==="acp"),k=p.p2p,N=async()=>{var $,z,E,_;if(n){c("upgrading"),l("Starting upgrade...");try{const O=await n(t.id,"daemon_upgrade",{});($=O==null?void 0:O.result)!=null&&$.alreadyLatest?(c("done"),l(`Already on v${O.result.version||"latest"}.`)):(z=O==null?void 0:O.result)!=null&&z.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(((_=O==null?void 0:O.result)==null?void 0:_.error)||"Upgrade failed"))}catch(O){c("error"),l((O==null?void 0:O.message)||"Connection lost during upgrade")}}},P=async()=>{if(x(null),!!r){h("loading");try{await r(t.id),h("done"),b("Machine disconnected.")}catch($){h("error"),b(($==null?void 0:$.message)||"Failed to disconnect")}}},K=async()=>{if(x(null),!!i){h("loading");try{await i(t.id),h("done"),b('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch($){h("error"),b(($==null?void 0:$.message)||"Failed to revoke token")}}},L="0.8.0",B=!w||w!==L,T=I.length+g.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:j}),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),"…"]}),w&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${B?"":"bg-bg-secondary"}`,style:B?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",w,!B&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&B&&e.jsx("button",{onClick:N,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${L}`,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${L}`}`}),r&&e.jsx("button",{onClick:()=>x("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:()=>x("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(qi,{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:[k&&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 ${k.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${k.state==="connecting"||k.state==="new"?"animate-pulse":""}`,style:k.state==="connecting"||k.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",k.state==="connected"?"connected":k.state==="connecting"||k.state==="new"?"connecting...":k.state||"off"]}),k.peers!==void 0&&k.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",k.peers," peer",k.peers!==1?"s":"",")"]})]}),k&&T>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),T>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[I.map($=>{const z=Zi($.type),E=$.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:z.icon}),e.jsx("span",{children:z.name}),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..."})]},$.id)}),g.map($=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"⌨️"}),e.jsx("span",{children:$.cliName||"CLI"})]},$.id)),M.map($=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:$.cliName||"ACP"})]},$.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(d||u)&&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:u||d})]}),f==="disconnect"&&e.jsx(dn,{title:"🔌 Disconnect Machine",message:`Disconnect "${y}" from ADHDev?
|
|
34
|
+
`})]})}function qa(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 Fn=t=>qa(t);function Ga(t){return{unread:!!t.unread,lastSeenAt:t.lastSeenAt||0,lastUpdated:t.lastUpdated||0,inboxBucket:t.inboxBucket||"idle",surfaceHidden:!!t.surfaceHidden}}function ss(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 It(t){const s=new Map,n=(r,i)=>{r&&s.set(r,{sessionId:r,...Ga(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 dt(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 St(t,s,n){const r=dt(t,s),i=ss(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,x=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:x,isReconnecting:o,isConnecting:c,isGenerating:d,isWaiting:l,inboxBucket:f?"needs_attention":x?"working":m?"task_complete":"idle"}}function Ya(t,s,n){return St(t,s,{hideOpenTaskCompleteUnread:!0,isOpenConversation:n==null?void 0:n.isOpenConversation}).unread}function Xa(t,s,n){return dt(t,n||new Map).surfaceHidden}function Vn({activeConv:t,onModalButton:s}){const[n,r]=a.useState(null);if(a.useEffect(()=>{r(null)},[t.modalMessage,t.status,t.connectionState]),!ss(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(_s,{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(),x=/^(run|approve|accept|yes|allow|always)/.test(f),m=/^(reject|deny|delete|remove|abort)/.test(f),h=n===d,u=n!==null;return e.jsx("button",{onClick:()=>o(d),disabled:u,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${x?"bg-white font-extrabold":m?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${u&&!h?"opacity-40":"opacity-100"} ${u?"cursor-not-allowed":"cursor-pointer"}`,style:x?{color:"var(--status-warning)"}:void 0,children:h?"⏳ ...":c(d)},l)})})]})]})}const tn=new Map,Ja={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"};function Za({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:i,controls:o,controlValues:c,serverModel:d,serverMode:l}){const{sendCommand:f}=Qe(),x=`${t}:${s||r}`,m=Ja[r]||"#94a3b8",[h,u]=a.useState({}),b=a.useRef(0),p={...d?{model:d}:{},...l?{mode:l}:{},...c||{},...Date.now()<b.current?h:{}};a.useEffect(()=>{c&&Date.now()>b.current&&u({})},[c]);const[w,v]=a.useState(tn.get(x)||{}),[y,j]=a.useState(null),[I,g]=a.useState(null),M=a.useCallback(async(T,S={})=>{const W={...S,...s&&{targetSessionId:s}};return await f(t,T,W)},[t,s,f]);if(!o||o.length===0)return null;const k=o.filter(T=>T.placement==="bar").sort((T,S)=>(T.order??50)-(S.order??50));if(k.length===0)return null;const N=async T=>{var W,$,z;if(y===T.id){j(null);return}if((((W=T.options)==null?void 0:W.map(D=>D.value))||w[T.id]||[]).length>0){j(T.id);return}if(T.dynamic&&T.listScript){g(T.id);try{const D=await M(T.listScript==="listModels"?"list_extension_models":T.listScript==="listModes"?"list_extension_modes":T.listScript,{agentType:r,ideType:n}),O=((D==null?void 0:D.models)||(D==null?void 0:D.modes)||(($=D==null?void 0:D.result)==null?void 0:$.models)||((z=D==null?void 0:D.result)==null?void 0:z.modes)||(D==null?void 0:D.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,[T.id]:O};return tn.set(x,q),q}),j(T.id)}catch{}finally{g(null)}}},P=async(T,S)=>{j(null),u(W=>({...W,[T.id]:S})),b.current=Date.now()+5e3;try{if(!T.setScript)return;const W=ds(T.setScript,r);await M(W,{agentType:r,ideType:n,model:T.id==="model"?S:void 0,mode:T.id==="mode"?S:void 0,value:S})}catch{}},K=async T=>{var _;const S=((_=T.options)==null?void 0:_.map(O=>O.value))||w[T.id]||[];if(S.length===0)return;const W=String(p[T.id]||""),z=(S.indexOf(W)+1)%S.length,D=S[z];if(typeof D=="string"){u(O=>({...O,[T.id]:D})),b.current=Date.now()+5e3;try{if(!T.setScript)return;const O=ds(T.setScript,r);await M(O,{agentType:r,ideType:n,value:D})}catch{}}},L=async T=>{const W=!p[T.id];u($=>({...$,[T.id]:W})),b.current=Date.now()+5e3;try{if(!T.setScript)return;const $=ds(T.setScript,r);await M($,{agentType:r,ideType:n,value:W})}catch{}},B=async T=>{if(T.invokeScript)try{await M("invoke_extension_script",{agentType:r,ideType:n,scriptName:T.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-[var(--surface-primary)]",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:"│"}),k.map(T=>{var D;const S=String(p[T.id]||""),W=y===T.id,$=I===T.id,z=((D=T.options)==null?void 0:D.map(_=>_.value))||w[T.id]||[];switch(T.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:()=>N(T),children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),$?"...":S||T.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),W&&z.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>j(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:T.label.toUpperCase()}),z.map(_=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:_===S?`${m}18`:"transparent",color:_===S?m:"var(--text-secondary)",fontWeight:_===S?600:400,borderLeft:_===S?`2px solid ${m}`:"2px solid transparent"},onMouseEnter:O=>{O.currentTarget.style.background=`${m}12`},onMouseLeave:O=>{O.currentTarget.style.background=_===S?`${m}18`:"transparent"},onClick:()=>P(T,_),children:_},_))]})]})]},T.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:()=>K(T),title:`Click to cycle: ${z.join(" → ")}`,children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),S||T.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"⟳"})]},T.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:()=>L(T),children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),T.label]},T.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:()=>B(T),children:[T.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:T.icon}),T.label]},T.id);default:return null}})]})}function ds(t,s){return{setModel:"set_extension_model",setMode:"set_extension_mode",setThinkingLevel:"set_thought_level"}[t]||t}const Qa=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 x=f.clipboardData.getData("text");x&&d(m=>m+x),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 x=f.relatedTarget;if((x==null?void 0:x.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 ei=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function ti(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function Le(t,s){if(ti(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":ei.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 qn(t){return Le(t)==="generating"}function Te(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function si(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 sn(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Gn(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 ni(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 ri(t){const s=t.trim().toLowerCase();return s.startsWith("mach_")||s.startsWith("standalone_mach_")||s.startsWith("daemon_mach_")}function ai(t){return ni(t.trim().replace(/\.local$/i,""))}function ii(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function Yn(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&&!ri(c));if(n&&n!=="Unknown")return ai(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function He(t,s={}){return ii(t)||Yn(t,s)}function qt(t){return t.transport==="pty"}function yt(t){return t.transport==="acp"}function nn(t,s){return Te(t)}function oi(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const i=(s||"").trim().toLowerCase(),o=(n||"").trim().toLowerCase(),c=Te(n||"").trim().toLowerCase();return r===i||r===o||r===c}function ci(t){return Le(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function li(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=Le(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 us(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 di(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&&(us(s.timestamp)||us(s.receivedAt)||us(s.createdAt))||0}function ui(t){return(t.recentLaunches||[]).reduce((n,r)=>Math.max(n,r.lastLaunchedAt||0),0)}function Gt(t){return Math.max(ui(t),di(t.activeChat))}function xi(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 pi(t,s){return xi(Gt(t),Gt(s),He(t,{fallbackId:t.id}),He(s,{fallbackId:s.id}),t.id,s.id)}function Xn({conversation:t,className:s="",onOpenNativeConversation:n,onOpenMachine:r}){var m;const i=pt(),o=t.daemonId||((m=t.ideId)==null?void 0:m.split(":")[0])||t.ideId,c=t.transport==="cdp-page"||t.transport==="cdp-webview",d=t.streamSource==="agent-stream"&&!!t.agentName,l=(()=>{var h,u;if(t.streamSource==="agent-stream"){const b=(u=(h=t.displaySecondary)==null?void 0:h.split("·")[0])==null?void 0:u.trim();if(b)return b}return Te(t.ideType||"")})(),f=a.useCallback(()=>{if(r){r();return}o&&i("/dashboard",{state:{openMachineId:o}})},[o,i,r]),x=a.useCallback(()=>{if(n){n();return}const h=t.streamSource==="agent-stream"?t.nativeSessionId:t.sessionId;h&&i(`/dashboard?activeTab=${encodeURIComponent(h)}`)},[t.nativeSessionId,t.sessionId,t.streamSource,i,n]);return e.jsxs("div",{className:`conversation-meta-chips ${s}`.trim(),children:[c&&e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:x,title:l,children:[e.jsx(De,{size:12}),e.jsx("span",{children:l})]}),d&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:t.agentName,children:[e.jsx(ut,{size:12}),e.jsx("span",{children:t.agentName})]}),t.machineName&&e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:f,title:t.machineName,children:[e.jsx(Ts,{size:12}),e.jsx("span",{children:t.machineName})]})]})}const Se=t=>t.transport==="pty",xt=(t,s)=>Se(t)?s||t.mode||"terminal":"chat",Jn=(t,s)=>Se(t)&&xt(t,s)==="terminal",je=t=>t.transport==="acp";function rn(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 an(t){const s=[];for(const n of t){const r=rn(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&&rn(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 mi=60,fi=60;function ws({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:x}=Qe();Ct("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:r});const m=Is.useMemo(()=>ss(t),[t.status,t.connectionState]),h=a.useRef(new Map),u=a.useCallback(S=>(h.current.has(S)||h.current.set(S,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:mi}),h.current.get(S)),[]),b=a.useCallback((S,W)=>{const $=u(S);h.current.set(S,{...$,...W}),p(z=>z+1)},[u]),[,p]=a.useState(0),w=t.tabKey,v=u(w),y=v.messages,j=v.hasMore,I=v.error,g=Math.max(0,t.messages.length-v.visibleLiveCount),[M,k]=a.useState(!1),N=a.useCallback(async()=>{var $,z;if(M)return;const S=t.tabKey,W=u(S);if(t.messages.length>W.visibleLiveCount){b(S,{visibleLiveCount:Math.min(t.messages.length,W.visibleLiveCount+fi),error:null});return}k(!0),b(S,{error:null});try{const D=(s==null?void 0:s.daemonId)||(($=t.ideId)==null?void 0:$.split(":")[0])||"";if(!D){b(S,{hasMore:!1});return}const _=t.ideType||t.agentType||"",O=await x(D,"chat_history",{agentType:_,offset:W.offset,limit:30,targetSessionId:t.sessionId,historySessionId:t.providerSessionId||t.sessionId}),A=(O==null?void 0:O.result)??O;if(((z=A.messages)==null?void 0:z.length)>0){const q=u(S);b(S,{messages:[...A.messages,...q.messages],offset:q.offset+A.messages.length,hasMore:!!A.hasMore})}else b(S,{hasMore:!!A.hasMore})}catch(D){const _=(D==null?void 0:D.message)||"";_.includes("P2P not available")||_.includes("channel not open")||_.includes("P2P not connected")||_.includes("timeout")?b(S,{error:"Connection not ready — tap to retry"}):b(S,{hasMore:!1,error:"Failed to load history"})}finally{k(!1)}},[M,s,t,x,u,b]),{allMessages:P,receivedAtMap:K}=a.useMemo(()=>{const S=g>0?t.messages.slice(-v.visibleLiveCount):t.messages;if(y.length===0){const _=an(S),O={};return _.forEach((A,q)=>{const ce=`${t.tabKey}:${lt(A,q)}`;let ne=A.receivedAt||f.current.get(ce)||0;ne||(ne=Date.now(),f.current.set(ce,ne)),O[lt(A,q)]=ne}),{allMessages:_,receivedAtMap:O}}const W=new Set(S.map(_=>`${_.role}:${(_.content||"").slice(0,100)}`)),$=y.filter(_=>!W.has(`${_.role}:${(_.content||"").slice(0,100)}`)),z=an([...$,...S]),D={};return z.forEach((_,O)=>{const A=`${t.tabKey}:${lt(_,O)}`;let q=_.receivedAt||f.current.get(A)||0;q||(q=Date.now(),f.current.set(A,q)),D[lt(_,O)]=q}),{allMessages:z,receivedAtMap:D}},[t.messages,t.tabKey,g,y,v.visibleLiveCount]),L=a.useMemo(()=>c.filter(S=>S.ideId===t.tabKey).sort((S,W)=>S.timestamp-W.timestamp),[c,t.tabKey]),B=t.displayPrimary||t.agentName||"Agent",T=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")&&k(!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(ut,{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(vs,{size:14})," Open ",B," 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(Wn,{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(vs,{size:14})," Open ",B," 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,B,m.isGenerating]);return e.jsxs("div",{className:"flex-1 min-h-0 w-full flex flex-col",children:[l&&e.jsx(Xn,{conversation:t,className:"chat-pane-meta-row"}),e.jsx(Oa,{messages:P,actionLogs:L,agentName:t.agentName||t.displayPrimary||"Agent",userName:d,isCliMode:Se(t)||je(t),isWorking:m.isGenerating,contextKey:t.tabKey,receivedAtMap:K,onLoadMore:N,isLoadingMore:M,hasMoreHistory:j,hiddenLiveCount:g,loadError:I??void 0,emptyState:T}),!Jn(t)&&(()=>{const S=t.streamSource!=="agent-stream",W=S?t.ideType:t.agentType,$=S?s!=null&&s.type?Te(s.type):Te(t.ideType||""):t.agentName||Te(t.agentType||""),z=!S&&(s!=null&&s.childSessions)&&s.childSessions.find(O=>O.id===t.sessionId||O.providerType===t.agentType)||s,D=z==null?void 0:z.providerControls,_=z==null?void 0:z.controlValues;return e.jsx(Za,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:W,displayLabel:$,controls:D,controlValues:_,serverModel:(z==null?void 0:z.currentModel)||void 0,serverMode:(z==null?void 0:z.currentPlan)||void 0,acpConfigOptions:je(t)?z==null?void 0:z.acpConfigOptions:void 0,acpModes:je(t)?z==null?void 0:z.acpModes:void 0})})(),e.jsx(Qa,{contextKey:t.tabKey,panelLabel:B,isSending:r,onSend:n})]})}let Zn=Nt;function Ds(){return Zn()}class hi{constructor(){Me(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 Qn=new hi;class gi{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 we=new gi;function bi(t){t.dashboardWS&&(Qn=t.dashboardWS),t.connectionManager&&(we=t.connectionManager),t.useDaemonsHook&&(Zn=t.useDaemonsHook)}function yi({activeConv:t,clearToken:s=0,terminalRef:n,handleSendChat:r,isSendingChat:i=!1,isVisible:o=!0}){var L;const c=a.useRef(null),{sendCommand:d,sendData:l}=Qe(),[f,x]=a.useState(""),[m,h]=a.useState(!1),u=a.useRef(0),b=a.useRef(!1),p=a.useRef(""),w=a.useRef(null),v=a.useRef(!1),y=a.useRef(null),j=t.tabKey,I=t.sessionId||"",g=t.daemonId||((L=t.ideId)==null?void 0:L.split(":")[0])||t.ideId||"",M=()=>{var B,T;u.current=0,b.current=!1,p.current="",w.current=null,v.current=!1,y.current!==null&&(cancelAnimationFrame(y.current),y.current=null),h(!1),(T=(B=n.current)==null?void 0:B.reset)==null||T.call(B)},k=()=>{var B,T;u.current=0,b.current=!1,p.current="",w.current=null,v.current=!1,y.current!==null&&(cancelAnimationFrame(y.current),y.current=null),h(!0),(T=(B=n.current)==null?void 0:B.reset)==null||T.call(B)},N=()=>{var T;if(y.current=null,!o)return;const B=p.current;B&&(p.current="",(T=n.current)==null||T.write(B))},P=B=>{B&&(p.current+=B,o&&y.current===null&&(y.current=requestAnimationFrame(N)))},K=(B,T=0,S,W)=>{var $,z,D,_,O;T>0&&u.current>=T||T===0&&b.current||(u.current=T,h(!0),typeof S=="number"&&typeof W=="number"&&S>0&&W>0&&((z=($=n.current)==null?void 0:$.resize)==null||z.call($,S,W)),(_=(D=n.current)==null?void 0:D.reset)==null||_.call(D),B&&((O=n.current)==null||O.write(B)))};return a.useEffect(()=>{M()},[I]),a.useEffect(()=>{var T;if(!I)return;const B=((T=we.onRuntimeEvent)==null?void 0:T.call(we,I,S=>{if(!(!S||S.sessionId!==I)){if(S.type==="runtime_snapshot"){if(!o){w.current={text:S.text||"",seq:S.seq||0,cols:S.cols,rows:S.rows};return}K(S.text||"",S.seq||0,S.cols,S.rows);return}if(S.type==="session_output"){b.current=!0,typeof S.seq=="number"&&(u.current=Math.max(u.current,S.seq)),m||h(!0),typeof S.data=="string"&&P(S.data);return}if(S.type==="session_cleared"){if(!o){v.current=!0,p.current="",w.current=null;return}k()}}}))||(()=>{});return()=>{B()}},[g,I,n,o,m]),a.useEffect(()=>{var T,S,W;if(!I)return;g&&((T=we.getState)==null?void 0:T.call(we,g))==="connected"&&(h(!0),(S=we.requestRuntimeSnapshot)==null||S.call(we,g,I).catch(()=>{}));const B=(W=we.onStateChange)==null?void 0:W.call(we,($,z)=>{var D;$!==g||z!=="connected"||(h(!0),(D=we.requestRuntimeSnapshot)==null||D.call(we,g,I).catch(()=>{}))});return()=>{B==null||B()}},[g,I,n]),a.useEffect(()=>{s&&M()},[s,j,n]),a.useEffect(()=>{x("")},[t.tabKey]),a.useEffect(()=>{var T;if(!o){(T=c.current)==null||T.blur();return}v.current&&(v.current=!1,k());const B=w.current;B&&(w.current=null,K(B.text,B.seq,B.cols,B.rows)),p.current&&y.current===null&&(y.current=requestAnimationFrame(N))},[o]),a.useEffect(()=>()=>{y.current!==null&&(cancelAnimationFrame(y.current),y.current=null)},[]),a.useEffect(()=>{const B=T=>{var W;const S=T.detail;S!=null&&S.sessionId&&S.sessionId!==I||m&&((W=n.current)==null||W.fit())};return window.addEventListener("adhdev:fit-cli-terminal",B),()=>{window.removeEventListener("adhdev:fit-cli-terminal",B)}},[m,I,n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx(Un,{ref:n,readOnly:!m||!o,onInput:B=>{m&&(l!=null&&l(g,{type:"pty_input",targetSessionId:I,data:B})||d(g,"pty_input",{targetSessionId:I,data:B}).catch(console.error))},onResize:(B,T)=>{m&&(l!=null&&l(g,{type:"pty_resize",targetSessionId:I,cols:B,rows:T})||d(g,"pty_resize",{targetSessionId:I,cols:B,rows:T,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:B=>x(B.target.value),onPaste:B=>{const T=B.clipboardData.getData("text");T&&x(S=>S+T),B.preventDefault()},onKeyDown:B=>{if(B.key!=="Enter")return;if(B.nativeEvent.isComposing){B.preventDefault();return}B.preventDefault();const T=f.trim();!m||!T||i||(x(""),r(T))},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 B=f.trim();!m||!B||i||(x(""),r(B))},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 vi({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 ji({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 Es({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(Ls,{size:r}):e.jsx(Ze,{size:r})})}function on({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 wi({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,conversations:i,onOpenHistory:o,onOpenRemote:c,onStopCli:d,activeCliViewMode:l,onSetCliViewMode:f,onOpenConversation:x,onHideConversation:m,hiddenConversations:h=[],onShowConversation:u,onShowAllHidden:b}){const p=Ds(),w=p.p2pStates||{},v=p.ides||[],y=!!t&&Se(t)&&!je(t),j=l||(t?Jn(t)?"terminal":"chat":null),[I,g]=a.useState(!1),[M,k]=a.useState(!1),[N,P]=a.useState(!1),K=a.useRef(null),L=a.useRef(null),B=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",T=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",S=v.filter(Q=>Q.type==="adhdev-daemon"),W=a.useMemo(()=>It(v),[v]),$=Object.values(w),z=$.filter(Q=>Q==="connected").length,D=$.filter(Q=>Q==="connecting"||Q==="new"||Q==="checking").length,O=n!=="connected"||S.length===0?null:D>0&&z===0?"P2P connecting...":z>0&&s===0?"Waiting for IDE...":null,A=a.useMemo(()=>i.filter(Q=>!Xa(Q,i,W)),[i,W]),q=a.useMemo(()=>A.filter(Q=>St(Q,W).requiresAction),[A,W]),ce=a.useMemo(()=>A.filter(Q=>{const E=(t==null?void 0:t.tabKey)===Q.tabKey;return St(Q,W,{hideOpenTaskCompleteUnread:!0,isOpenConversation:E}).unread}),[t,A,W]),ne=q.length+ce.length;a.useEffect(()=>{if(!I)return;const Q=E=>{var G;(G=K.current)!=null&&G.contains(E.target)||g(!1)};return document.addEventListener("mousedown",Q),()=>document.removeEventListener("mousedown",Q)},[I]),a.useEffect(()=>{if(!M)return;const Q=E=>{var G;(G=L.current)!=null&&G.contains(E.target)||k(!1)};return document.addEventListener("mousedown",Q),()=>document.removeEventListener("mousedown",Q)},[M]);const Z=Q=>{if(!Q)return;const E=i.find(G=>G.tabKey===Q);E&&(m==null||m(E))};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(Ze,{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:B,boxShadow:T}})})]}),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:B,boxShadow:T}}),O&&e.jsxs("span",{className:"header-subtitle-status",children:["· ",O]})]})]})})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&(y||!je(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&&j&&e.jsx(Es,{mode:j,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(Vt,{size:14})})]}),!je(t)&&e.jsx("button",{onClick:()=>o(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(As,{size:14})}),!y&&!je(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(De,{size:14})})]}),e.jsxs("div",{className:"dashboard-header-inbox",ref:K,children:[e.jsxs("div",{className:`dashboard-header-hidden${N?" is-drop-target":""}`,ref:L,onDragEnter:Q=>{Q.dataTransfer.types.includes("text/tab-key")&&(Q.preventDefault(),P(!0))},onDragOver:Q=>{Q.dataTransfer.types.includes("text/tab-key")&&(Q.preventDefault(),Q.dataTransfer.dropEffect="move",P(!0))},onDragLeave:Q=>{Q.currentTarget.contains(Q.relatedTarget)||P(!1)},onDrop:Q=>{const E=Q.dataTransfer.getData("text/tab-key");Q.preventDefault(),P(!1),Z(E)},children:[e.jsxs("button",{type:"button",onClick:()=>k(Q=>!Q),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:"Hidden tabs. Drag a tab here to hide it.",children:[e.jsx(Ca,{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&&b&&e.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{b(),k(!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(Q=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{u==null||u(Q),k(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:Q.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:Q.displaySecondary})]},Q.tabKey))}):e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),e.jsxs("button",{type:"button",onClick:()=>g(Q=>!Q),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(ts,{size:16}),ne>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:ne})]}),I&&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(Q=>e.jsx(on,{conversation:Q,isAttention:!0,onClick:()=>{x==null||x(Q),g(!1)}},Q.tabKey))]}),ce.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),ce.map(Q=>e.jsx(on,{conversation:Q,onClick:()=>{x==null||x(Q),g(!1)}},Q.tabKey))]}),ne===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function ki(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 Ni({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,savedSessions:i=[],isSavedSessionsLoading:o=!1,isResumingSavedSessionId:c=null,onClose:d,onNewChat:l,onSwitchSession:f,onRefreshHistory:x,onResumeSavedSession:m}){var w;const h=s.find(v=>v.id===t.ideId),u=(h==null?void 0:h.chats)||[],b=(w=h==null?void 0:h.activeChat)==null?void 0:w.id,p=Se(t)&&!je(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:p?"Saved Sessions":"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",Te(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:[!p&&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"}),p?e.jsx(e.Fragment,{children:i.map(v=>{const y=t.providerSessionId===v.providerSessionId,j=y||!v.canResume||!!c;return e.jsxs("button",{type:"button",onClick:()=>{j||!m||m(v)},disabled:j,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"} ${j?"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:ki(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)})}):u.map(v=>e.jsxs("div",{onClick:()=>{f(t.ideId,v.id),d()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${b===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 ${b===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),"..."]}),b===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)),(p&&!o&&i.length===0||!p&&u.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(Ra,{size:32})}),e.jsx("div",{className:"text-[13px]",children:p?"No saved sessions found yet.":"No recent chat sessions found."})]}),p&&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:x,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(Rs,{size:13})," ",p?"Refresh Sessions":"Refresh History"]})})})]})]})}const cn={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 er({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:cn[r.type]||cn.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 tr(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 Si=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Ci(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function Ii(t){return t.sessionId||t.instanceId||t.agentType}function xs(t,s){return t||s}function Lt(t){return tr(t)}function ln(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 sr(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=He(r,{fallbackId:r.id}))}return s}function nr(t,s,n={}){var h,u,b,p,w,v;const r=[],i=n.machineName,o=n.connectionState,c=Ci(t),d=Te(t.type),l=Array.isArray(t.childSessions)?t.childSessions.map(y=>{var j,I;return{sessionId:y.id,instanceId:y.id,providerSessionId:y.providerSessionId,agentType:y.providerType,agentName:y.providerName,status:y.status,title:y.title,messages:((j=y.activeChat)==null?void 0:j.messages)||[],activeModal:((I=y.activeChat)==null?void 0:I.activeModal)||void 0,unread:y.unread,lastSeenAt:y.lastSeenAt,lastUpdated:y.lastUpdated,inboxBucket:y.inboxBucket,surfaceHidden:y.surfaceHidden}}):[],f=Si(t),x=t.activeChat||{title:""},m=x.title&&String(x.title).trim()?String(x.title).trim():"";if(f){const y=t.sessionId||t.instanceId,j=nn(t.type),I=(h=t.activeChat)==null?void 0:h.activeModal,g=I&&Array.isArray(I.buttons)&&I.buttons.length>0,M=Le((u=t.activeChat)==null?void 0:u.status,{activeModal:(b=t.activeChat)==null?void 0:b.activeModal})||Le((w=(p=t.agents)==null?void 0:p[0])==null?void 0:w.status)||"idle",k=t.activeChat||{title:"",messages:[]};let N=k.title&&String(k.title).trim()?String(k.title).trim():"";const P=(v=t.activeChat)==null?void 0:v.id,K=t.chats;if(P&&Array.isArray(K)&&K.length>0){const W=K.find($=>$.id===P||$.id&&String($.id)===String(P));W!=null&&W.title&&String(W.title).trim()&&(N=String(W.title).trim())}const L=k.messages||[],B=ln(s,[t.id,y]),T=new Map;L.filter(W=>W.role==="user").forEach(W=>{const $=Lt(W.content);$&&T.set($,(T.get($)||0)+1)});const S=B.filter(W=>{const $=Lt(W.content),z=T.get($)||0;return z>0?(T.set($,z-1),!1):!0});r.push({ideId:t.id,sessionId:y,providerSessionId:t.providerSessionId,nativeSessionId:y,transport:t.transport,daemonId:t.daemonId||void 0,mode:Se(t)?t.mode||"terminal":"chat",agentName:j,agentType:(Se(t)||je(t))&&(t.cliType||t.acpType)||t.type,status:M,title:N,messages:[...L,...S],resume:t.resume,ideType:t.cliType||t.acpType||t.type,workspaceName:c,displayPrimary:N||c||(Se(t)?t.mode==="chat"?j:"Terminal":j),displaySecondary:d,cdpConnected:t.cdpConnected,modalButtons:g?I.buttons:void 0,modalMessage:g?I.message:void 0,streamSource:"native",tabKey:xs(y,t.id),machineName:i,connectionState:o})}if(f&&(Se(t)||je(t)))return r;for(const y of l){const j=y.activeModal&&Array.isArray(y.activeModal.buttons)&&y.activeModal.buttons.length>0,I=ci(y),g=Ii(y),M=`${t.id}:${g}`,k=y.title&&String(y.title).trim()||"",N=oi(k,y.agentName,y.agentType)?"":k,P=y.messages||[],K=ln(s,[M,y.sessionId,y.instanceId]),L=new Map;P.filter(S=>S.role==="user").forEach(S=>{const W=Lt(S.content);W&&L.set(W,(L.get(W)||0)+1)});const B=K.filter(S=>{const W=Lt(S.content),$=L.get(W)||0;return $>0?(L.set(W,$-1),!1):!0});(P.length>0||B.length>0||j||N||!["idle","panel_hidden","disconnected","not_monitored"].includes(I))&&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:I,title:N,messages:[...P,...B],ideType:y.agentType,workspaceName:c,displayPrimary:N||m||c||d,displaySecondary:`${d}·${y.agentName}`,cdpConnected:t.cdpConnected,modalButtons:j?y.activeModal.buttons:void 0,modalMessage:j?y.activeModal.message:void 0,streamSource:"agent-stream",tabKey:xs(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:nn(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:xs(t.sessionId||t.instanceId,t.id),connectionState:o}),r}function Mi(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 Ti(t,s){const n=[],{daemonId:r,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now(),d=t.sessions||[],{topLevel:l,childrenByParent:f}=Mi(d),x=l.filter(u=>u.kind==="workspace"&&u.transport==="cdp-page"),m=l.filter(u=>u.kind==="agent"&&u.transport==="pty"),h=l.filter(u=>u.kind==="agent"&&u.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:x.some(u=>!!u.cdpConnected)});for(const u of x){const b=f.get(u.id)||[];n.push({id:`${r}:ide:${u.id}`,sessionId:u.id,providerSessionId:u.providerSessionId,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,status:u.cdpConnected?"online":"detected",daemonId:r,instanceId:u.id,workspace:u.workspace,terminals:0,childSessions:b,agents:b.map(p=>({id:p.id,name:p.providerName,type:p.providerType,status:p.status})),activeChat:u.activeChat,chats:[],cdpConnected:u.cdpConnected,currentModel:u.currentModel,currentPlan:u.currentPlan,currentAutoApprove:u.currentAutoApprove,lastUpdated:u.lastUpdated,unread:u.unread,lastSeenAt:u.lastSeenAt,inboxBucket:u.inboxBucket,surfaceHidden:u.surfaceHidden,controlValues:u.controlValues,providerControls:u.providerControls,timestamp:c})}for(const u of m)n.push({id:`${r}:cli:${u.id}`,sessionId:u.id,providerSessionId:u.providerSessionId,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,agentType:u.providerType,status:u.status||"running",daemonId:r,instanceId:u.id,cliName:u.providerName,mode:u.mode||"terminal",workspace:u.workspace||"",activeChat:u.activeChat,resume:u.resume,runtimeKey:u.runtimeKey,runtimeDisplayName:u.runtimeDisplayName,runtimeWorkspaceLabel:u.runtimeWorkspaceLabel,runtimeWriteOwner:u.runtimeWriteOwner??null,runtimeAttachedClients:u.runtimeAttachedClients??[],lastUpdated:u.lastUpdated,unread:u.unread,lastSeenAt:u.lastSeenAt,inboxBucket:u.inboxBucket,surfaceHidden:u.surfaceHidden,controlValues:u.controlValues,providerControls:u.providerControls,timestamp:c,_isCli:!0});for(const u of h)n.push({id:`${r}:acp:${u.id}`,sessionId:u.id,providerSessionId:u.providerSessionId,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,agentType:u.providerType,status:u.status||"running",daemonId:r,instanceId:u.id,cliName:u.providerName,mode:"chat",workspace:u.workspace||"",activeChat:u.activeChat,runtimeKey:u.runtimeKey,runtimeDisplayName:u.runtimeDisplayName,runtimeWorkspaceLabel:u.runtimeWorkspaceLabel,runtimeWriteOwner:u.runtimeWriteOwner??null,runtimeAttachedClients:u.runtimeAttachedClients??[],currentModel:u.currentModel,currentPlan:u.currentPlan,lastUpdated:u.lastUpdated,unread:u.unread,lastSeenAt:u.lastSeenAt,inboxBucket:u.inboxBucket,surfaceHidden:u.surfaceHidden,acpConfigOptions:u.acpConfigOptions,acpModes:u.acpModes,controlValues:u.controlValues,providerControls:u.providerControls,timestamp:c,_isAcp:!0});return n}function Ai(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 Ri(t,s){const n=Ai(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const rr=[{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:"💚"}],ar=[{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:"🧩"}],ir=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],or="adhdev_notification_prefs",dn={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function _i(){try{const t=localStorage.getItem(or);if(t){const s=JSON.parse(t);return{...dn,...s}}}catch{}return{...dn}}function Li(t){try{localStorage.setItem(or,JSON.stringify(t))}catch{}}let Ue=_i(),Wt=[];function Di(){Wt.forEach(t=>t())}function Ei(){return{...Ue}}function $i(t){Ue={...Ue,...t},Li(Ue),Di()}function Pi(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return Wt.push(n),()=>{Wt=Wt.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{$i(n)},[]);return[{...Ue},s]}function vt(t){if(!Ue.globalEnabled)return!1;switch(t){case"disconnect":return Ue.disconnectAlert;case"completion":return Ue.completionAlert;case"approval":return Ue.approvalAlert;case"browser":return Ue.browserNotifications;default:return!0}}const Bi={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Ki(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function cr(){return"Notification"in window&&Notification.permission==="granted"}let nt=null;async function Wi(){if(nt!==null)return nt;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return nt=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(nt=!!await t.pushManager.getSubscription(),nt):(nt=!1,!1)}catch{return nt=!1,!1}}function ks(t,s,n){if(cr())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 Oi(t,s={}){const n={...Bi,...s},r=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{Wi().then(d=>{o.current=d})},[]);const c=a.useCallback((d,l,f)=>{const x=Date.now();x-i.current<n.throttleMs||(i.current=x,ks(d,l,f))},[n.throttleMs]);a.useEffect(()=>{var d;if(!(!n.enabled||!cr())&&vt("browser")&&o.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,Le(l.status,{activeModal:l.activeModal}));return}for(const l of t){const f=r.current.get(l.id),x=Le(l.status,{activeModal:l.activeModal}),m=l.name||l.id;if(n.onApproval&&vt("approval")&&x==="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&&vt("completion")&&qn(f)&&x==="idle"&&c(`✅ ${m} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&x==="error"&&f!=="error"&&c(`⚠️ ${m} — Error`,"Agent encountered an error",`error-${l.id}`),r.current.set(l.id,x)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class zi{constructor(){Me(this,"dedupMap",new Map);Me(this,"DEDUP_WINDOW_MS",5e3);Me(this,"DEDUP_MAX_SIZE",50);Me(this,"DEDUP_CLEANUP_AGE_MS",1e4);Me(this,"toastCallbacks",[]);Me(this,"systemMessageCallbacks",[]);Me(this,"clearSystemMessageCallbacks",[]);Me(this,"resolveActionFn",null);Me(this,"viewRequestRespondFn",null);Me(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 x,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=Te(s.ideType||"");const d=this.resolveOwningDaemon(s);if(d){const h=He(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&&Ei().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",u=(x=s.modalButtons)!=null&&x.length?s.modalButtons.map(b=>`[${b}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${h}
|
|
36
|
+
${u}`,_localId:`sys_approval_${Date.now()}`})}if((m=s.modalButtons)!=null&&m.length&&this.resolveActionFn){const h=this.resolveActionRouteTarget(s);if(!h)return;const u=s.agentType||s.ideType||"",b=s.ideType||"",p=s.modalButtons,w=g=>g.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),v=this.resolveActionFn,y=p.map((g,M)=>{const k=w(g).toLowerCase(),N=/^(run|approve|accept|yes|allow|always)/.test(k),P=/^(reject|deny|delete|remove|abort|cancel|no)/.test(k);return{label:w(g),variant:N?"primary":P?"danger":"default",onClick:()=>{const K=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(k);v(h,"resolve_action",{action:K?"approve":"reject",button:g,buttonIndex:M,agentType:u,ideType:b,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),j=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,I=Date.now();this.emitToast({id:I,message:j,type:f,timestamp:I,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",vt("browser")&&!document.hasFocus()&&ks(`⚠️ ${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",u=s.requestId,b=s.orgId;if(l=`👁️ ${h} wants to view your session`,f="warning",u&&b&&this.viewRequestRespondFn){const p=this.viewRequestRespondFn,w=Date.now(),v=[{label:"Approve",variant:"primary",onClick:()=>{p(b,u,"approve").catch(y=>console.error("[EventManager] approve view request failed:",y))}},{label:"Decline",variant:"danger",onClick:()=>{p(b,u,"reject").catch(y=>console.error("[EventManager] reject view request failed:",y))}}];this.emitToast({id:w,message:l,type:f,timestamp:w,actions:v,duration:3e4}),l=""}vt("browser")&&!document.hasFocus()&&ks("👁️ View Request",`${h} wants to view your session`,`view-request-${u}`)}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 Xe=new zi;function ot(...t){return sa(na(t))}function Ui({icon:t,title:s,subtitle:n,badge:r,actions:i,className:o}){return e.jsxs("div",{className:ot("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 Yt({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(Ui,{icon:t,title:s,subtitle:n,badge:r,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:ot("mx-auto flex w-full flex-col gap-4",o,c),children:d})})]})}function Re({title:t,icon:s,description:n,accentColor:r,className:i,children:o}){return e.jsxs("div",{className:ot("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 $s({icon:t,title:s,description:n,action:r,className:i}){return e.jsxs("div",{className:ot("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 Hi={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"},Fi={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function Vi({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:ot("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",Hi[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:Fi[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 qi={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"},Gi={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Yi({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:ot("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",qi[t],n),children:[e.jsx("span",{className:ot("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Gi[t])}),r]})}function Xi(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Ns(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function Ot(t){return t==="system"?Xi():t}function Ji(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Ot(Ns()))}function lr(){const[t,s]=a.useState(Ns),[n,r]=a.useState(()=>Ot(Ns()));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(Ot(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const d=c==="dark"?"light":c==="light"?"system":"dark";r(Ot(d));try{localStorage.setItem("theme",d)}catch{}return d})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function Je({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 Zi({onPrefChange:t}){const[s,n]=Pi(),r=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Je,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ts,{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(Je,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(De,{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(Je,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_a,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(Je,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(La,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(Je,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ut,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("disconnectAlert",i)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(Je,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ze,{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 Qi({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($s,{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(to,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i},c.id))})}function un({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 ra.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 eo(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...rr,...ar,...ir].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 to({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){var S,W;const[o,c]=a.useState("idle"),[d,l]=a.useState(""),[f,x]=a.useState(null),[m,h]=a.useState("idle"),[u,b]=a.useState(""),p=t,w=p.version||p.daemonVersion||null,v=((S=p.machine)==null?void 0:S.platform)||((W=p.system)==null?void 0:W.platform)||"",y=He(p,{fallbackId:t.id}),j=v==="win32"?"🪟":v==="darwin"?"🍎":"🐧",I=s.filter($=>$.daemonId===t.id&&$.transport==="cdp-page"),g=s.filter($=>$.daemonId===t.id&&$.transport==="pty"),M=s.filter($=>$.daemonId===t.id&&$.transport==="acp"),k=p.p2p,N=async()=>{var $,z,D,_;if(n){c("upgrading"),l("Starting upgrade...");try{const O=await n(t.id,"daemon_upgrade",{});($=O==null?void 0:O.result)!=null&&$.alreadyLatest?(c("done"),l(`Already on v${O.result.version||"latest"}.`)):(z=O==null?void 0:O.result)!=null&&z.upgraded||(D=O==null?void 0:O.result)!=null&&D.success?(c("done"),l(`Upgrade to v${O.result.version||"latest"} started. Daemon is restarting...`)):(c("error"),l(((_=O==null?void 0:O.result)==null?void 0:_.error)||"Upgrade failed"))}catch(O){c("error"),l((O==null?void 0:O.message)||"Connection lost during upgrade")}}},P=async()=>{if(x(null),!!r){h("loading");try{await r(t.id),h("done"),b("Machine disconnected.")}catch($){h("error"),b(($==null?void 0:$.message)||"Failed to disconnect")}}},K=async()=>{if(x(null),!!i){h("loading");try{await i(t.id),h("done"),b('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch($){h("error"),b(($==null?void 0:$.message)||"Failed to revoke token")}}},L="0.8.1",B=!w||w!==L,T=I.length+g.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:j}),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),"…"]}),w&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${B?"":"bg-bg-secondary"}`,style:B?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",w,!B&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&B&&e.jsx("button",{onClick:N,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${L}`,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${L}`}`}),r&&e.jsx("button",{onClick:()=>x("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:()=>x("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(Yi,{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:[k&&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 ${k.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${k.state==="connecting"||k.state==="new"?"animate-pulse":""}`,style:k.state==="connecting"||k.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",k.state==="connected"?"connected":k.state==="connecting"||k.state==="new"?"connecting...":k.state||"off"]}),k.peers!==void 0&&k.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",k.peers," peer",k.peers!==1?"s":"",")"]})]}),k&&T>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),T>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[I.map($=>{const z=eo($.type),D=$.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:z.icon}),e.jsx("span",{children:z.name}),D!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${D?"bg-green-400":"animate-pulse"}`,style:D?void 0:{background:"var(--status-warning)"},title:D?"CDP connected":"CDP connecting..."})]},$.id)}),g.map($=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"⌨️"}),e.jsx("span",{children:$.cliName||"CLI"})]},$.id)),M.map($=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:$.cliName||"ACP"})]},$.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(d||u)&&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:u||d})]}),f==="disconnect"&&e.jsx(un,{title:"🔌 Disconnect Machine",message:`Disconnect "${y}" from ADHDev?
|
|
37
37
|
|
|
38
38
|
This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
|
|
39
39
|
|
|
40
|
-
Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:P,onCancel:()=>x(null)}),f==="revoke"&&e.jsx(
|
|
40
|
+
Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:P,onCancel:()=>x(null)}),f==="revoke"&&e.jsx(un,{title:"⚠️ Remove Machine",message:`Remove "${y}" from your dashboard?
|
|
41
41
|
|
|
42
42
|
This will:
|
|
43
43
|
• Immediately disconnect the machine
|
|
44
44
|
• Delete the machine registration
|
|
45
45
|
• Require restarting "adhdev-standalone" on that machine
|
|
46
46
|
|
|
47
|
-
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:K,onCancel:()=>x(null)})]})}const eo=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function to(){const{preference:t,setPreference:s}=cr();return e.jsx("div",{className:"flex gap-2",children:eo.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 Ss={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},Cs={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},so=[{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"}}}],lr="adhdev-chat-theme",dr="adhdev-chat-theme-custom";function zt(){return typeof window>"u"?"ember":localStorage.getItem(lr)||"ember"}function Ke(t){try{const s=localStorage.getItem(dr);if(s){const n=JSON.parse(s);return{...t==="dark"?Ss:Cs,...n[t]}}}catch{}return t==="dark"?Ss:Cs}function Et(t,s){localStorage.setItem(dr,JSON.stringify({dark:t,light:s}))}function De(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 Xt(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 no={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function jt(t,s){var i;const n=(i=no[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",Xt(n,24)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${Xt(n,18)})`),r.style.setProperty("--border-accent",De(n,.35)),r.style.setProperty("--nav-active-bg",De(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${De(n,.06)}`)}function at(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",De(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",De(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",De(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",De(t.borderSubtle,.5)),s.style.setProperty("--border-default",De(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",Xt(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${Xt(t.accentColor,40)})`),s.style.setProperty("--border-accent",De(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",De(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${De(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 ${De(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 Ps(){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 ro(t){if(localStorage.setItem(lr,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=it()?"dark":"light";at(Ke(s))}else Ps(),jt(t,it()?"dark":"light")}function ao(){const t=zt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=it()?"dark":"light";at(Ke(s))}else Ps(),jt(t,it()?"dark":"light")}function it(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Te({label:t,value:s,onChange:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("input",{type:"color",value:s,onChange:r=>n(r.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:r=>{/^#[0-9a-fA-F]{0,6}$/.test(r.target.value)&&n(r.target.value)},style:{width:72,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function ht({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 io({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,i]=a.useState(()=>Ke(n));a.useEffect(()=>{i(Ke(n))},[n]);const o=a.useCallback((c,d)=>{i(l=>{const f={...l,[c]:d},m=Ke(n==="dark"?"light":"dark");return n==="dark"?Et(f,m):Et(m,f),at(f),s(f),f})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 18px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{children:[e.jsxs(ht,{title:"App Background",children:[e.jsx(Te,{label:"Background",value:r.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(Te,{label:"Surface",value:r.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(Te,{label:"Card",value:r.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(ht,{title:"App Text",children:[e.jsx(Te,{label:"Primary",value:r.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(Te,{label:"Secondary",value:r.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(Te,{label:"Muted",value:r.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(ht,{title:"Borders & Accent",children:[e.jsx(Te,{label:"Border subtle",value:r.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(Te,{label:"Border default",value:r.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(Te,{label:"Accent",value:r.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(ht,{title:"Chat Bubbles",children:[e.jsx(Te,{label:"User bubble",value:r.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(Te,{label:"User text",value:r.userText,onChange:c=>o("userText",c)}),e.jsx(Te,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(Te,{label:"Agent text",value:r.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(ht,{title:"Chat Layout",children:[e.jsx(Te,{label:"Chat BG",value:r.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(Te,{label:"Send button",value:r.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(Te,{label:"Input border",value:r.inputBorder,onChange:c=>o("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:r.bubbleRadius,onChange:c=>o("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?Ss:Cs,l=Ke(t?"light":"dark");t?Et(c,l):Et(l,c),i(c),at(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 oo(){const[t,s]=a.useState(zt),[n,r]=a.useState(!0),[i,o]=a.useState(()=>Ke("dark"));a.useEffect(()=>{r(it());const l=new MutationObserver(()=>{const m=it();r(m);const h=zt();h==="custom"?at(Ke(m?"dark":"light")):jt(h,m?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const f=window.matchMedia("(prefers-color-scheme: dark)"),x=()=>{const m=it();r(m);const h=zt();h==="custom"?at(Ke(m?"dark":"light")):jt(h,m?"dark":"light")};return f.addEventListener("change",x),()=>{l.disconnect(),f.removeEventListener("change",x)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?at(Ke(n?"dark":"light")):(Ps(),jt(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{o(Ke(n?"dark":"light"))},[n]);const c=l=>{s(l),ro(l)},d=[...so,{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,x=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:x.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:x.assistantBubble,border:x.assistantBorder,color:x.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:x.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:x.assistantBubble,border:x.assistantBorder,color:x.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(io,{dark:n,onColorsChange:l=>o(l)})]})}const ur="adhdev_mobileDashboardMode_v1";function xr(){try{return localStorage.getItem(ur)==="workspace"?"workspace":"chat"}catch{return"chat"}}function co(t){try{localStorage.setItem(ur,t)}catch{}}function lo(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(xr()==="chat")},[]),e.jsx(et,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(tt,{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),co(n?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}const pr="adhdev_hiddenTabs";function uo(){try{const t=localStorage.getItem(pr);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function lt(t){try{localStorage.setItem(pr,JSON.stringify([...t]))}catch{}}function xo(){const[t,s]=a.useState(uo),n=a.useCallback(f=>{s(x=>{const m=new Set(x);return m.has(f)?m.delete(f):m.add(f),lt(m),m})},[]),r=a.useCallback(f=>{s(x=>{if(x.has(f))return x;const m=new Set(x);return m.add(f),lt(m),m})},[]),i=a.useCallback(f=>{s(x=>{if(!x.has(f))return x;const m=new Set(x);return m.delete(f),lt(m),m})},[]),o=a.useCallback(()=>{s(f=>{if(f.size===0)return f;const x=new Set;return lt(x),x})},[]),c=a.useCallback((f,x)=>{s(m=>{const h=new Set(m);for(const u of x)h.add(u);return lt(h),h})},[]),d=a.useCallback((f,x)=>{s(m=>{const h=new Set(m);for(const u of x)h.delete(u);return lt(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 po({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){a.useEffect(()=>{Pi()},[]);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 Ki(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{n(d=>{const l=Date.now(),f={};for(const[x,m]of Object.entries(d))l-m<5e3&&(f[x]=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 ps(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 ns(t){const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1];return ps(s==null?void 0:s.timestamp)||ps(s==null?void 0:s.receivedAt)||ps(s==null?void 0:s.createdAt)||0}function ms(t,s=0){return ns(t)||s||0}function un(t){return ns(t)}function mr(t,s){const n=un(s)-un(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 mo(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 Dt(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 fo(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 ho(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 go(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 bo({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 I=mo(t);return Dt(o.current,I)?o.current:(o.current=I,I)},[t]),x=a.useMemo(()=>tr(t),[t]),m=a.useRef(new Map),h=a.useMemo(()=>{var M;const I=new Map,g=[];for(const k of f){const N=k.daemonId||((M=k.id)==null?void 0:M.split(":")[0])||k.id,P=s[N]||"new",K=k.daemonId&&x[k.daemonId]||void 0,L=ho(k,n),B=m.current.get(k.id);if(B&&B.ide===k&&B.connectionState===P&&B.machineName===K&&go(B.localRefs,L)){I.set(k.id,B),g.push(...B.conversations);continue}const T=sr(k,n,{machineName:K,connectionState:P}),S={ide:k,connectionState:P,machineName:K,localRefs:L,conversations:T};I.set(k.id,S),g.push(...T)}return m.current=I,[...g].sort(mr)},[f,n,s,x]),u=a.useMemo(()=>{const I=fo(h,r);return Dt(c.current,I)?c.current:(c.current=I,I)},[h,r]),b=a.useMemo(()=>{const I=new Map;for(const g of u)g.sessionId&&I.set(g.sessionId,g);return I},[u]),p=a.useMemo(()=>{const I=new Map;for(const g of u)g.sessionId&&I.set(g.sessionId,g),I.set(g.ideId,g),I.set(g.tabKey,g);return I},[u]),w=a.useCallback(I=>{if(I)return b.get(I)},[b]),v=a.useCallback(I=>{if(I)return p.get(I)},[p]),y=a.useMemo(()=>{const I=u.filter(g=>!i.has(g.tabKey));return Dt(d.current,I)?d.current:(d.current=I,I)},[u,i]),j=a.useMemo(()=>{const I=y.map(g=>g.tabKey);return Dt(l.current,I)?l.current:(l.current=I,I)},[y]);return{chatIdes:f,conversations:u,visibleConversations:y,visibleTabKeys:j,resolveConversationBySessionId:w,resolveConversationByTarget:v}}function yo({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 vo({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:i}){a.useEffect(()=>{Qe.setIdes(t)},[t]),a.useEffect(()=>{Qe.setResolveAction((o,c,d)=>{s(o,c,d).catch(()=>{})})},[s]),a.useEffect(()=>{const o=Qe.onToast(l=>{n(x=>x.some(h=>h.message===l.message&&l.timestamp-h.timestamp<3e3)?x:[...x.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(x=>x.filter(m=>m.id!==l.id)),f)}),c=Qe.onSystemMessage((l,f)=>{var m;const x=i(l);(x==null?void 0:x.transport)==="pty"&&((m=f._localId)!=null&&m.startsWith("sys_approval_"))||r(h=>({...h,[l]:[...h[l]||[],f]}))}),d=Qe.onClearSystemMessage((l,f)=>{r(x=>{var m;return(m=x[l])!=null&&m.length?{...x,[l]:x[l].filter(h=>{var u;return!(h.role==="system"&&((u=h._localId)!=null&&u.startsWith(f)))})}:x})});return()=>{o(),c(),d()}},[n,r]),a.useEffect(()=>{const o=Zn.on("status_event",c=>Qe.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,x=i(f),m=(x==null?void 0:x.ideId)||l.ideId;m&&s(m,"resolve_action",{action:"approve",button:"Approve",...(x==null?void 0:x.sessionId)&&{targetSessionId:x.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 jo="adhdev_dashboardLayout_v1",wo="adhdev_dashboardDockview_v1",gt={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function fr(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function hr(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function gr(t){return`${jo}:${t}`}function ko(t){const s=gr(t);return fr(s,null)}function No(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=gr(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function br(t){return`${wo}:${t}`}function So(t){const s=br(t);return fr(s,null)}function Co(t,s){try{const n=br(t);if(!s){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function Io(){return{groupAssignments:[...gt.groupAssignments],focusedGroup:gt.focusedGroup,groupActiveTabIds:{...gt.groupActiveTabIds},groupTabOrders:{...gt.groupTabOrders},groupSizes:[...gt.groupSizes]}}function Mo(){const[t]=a.useState(()=>hr(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,x]=a.useState([]),[m,h]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[u,b]=a.useState(!1),p=a.useCallback(()=>{if(u)return;const w=ko(t)??Io();n(new Map(w.groupAssignments)),i(w.focusedGroup),c(w.groupActiveTabIds),l(w.groupTabOrders),x(w.groupSizes),b(!0)},[u,t]);return a.useEffect(()=>{u&&No(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:o,groupTabOrders:d,groupSizes:f})},[u,t,s,r,o,d,f]),a.useEffect(()=>{const w=window.matchMedia("(max-width: 767px)"),v=y=>h(y.matches);return w.addEventListener("change",v),()=>w.removeEventListener("change",v)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:d,setGroupTabOrders:l,groupSizes:f,setGroupSizes:x,isMobile:m,hasHydratedStoredLayout:u,hydrateStoredLayout:p}}function To({urlActiveTab:t,conversations:s,resolveConversationBySessionId:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:d,setSearchParams:l,historyModalOpen:f,activeConv:x,isRefreshingHistory:m,ides:h,handleRefreshHistory:u}){const b=a.useRef(!1),p=a.useRef(!1),w=a.useRef(null),v=a.useRef(!1);a.useEffect(()=>{if(!t||b.current||s.length===0)return;if(!i){o();return}const y=n(t);if(!y)return;const j=r.get(y.tabKey)??0;c(I=>({...I,[j]:y.tabKey})),d(j),b.current=!0,p.current=!0,w.current!=null&&(window.clearTimeout(w.current),w.current=null),l(I=>{const g=new URLSearchParams(I);return g.delete("activeTab"),g},{replace:!0})},[t,s,n,r,i,o,c,d,l]),a.useEffect(()=>{if(!(p.current||i)&&s.length!==0){if(!t){o(),p.current=!0;return}if(b.current){p.current=!0;return}if(w.current==null)return w.current=window.setTimeout(()=>{w.current=null,!(p.current||i)&&(o(),p.current=!0)},1500),()=>{w.current!=null&&(window.clearTimeout(w.current),w.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!f){v.current=!1;return}if(!x||v.current||m)return;const y=h.find(j=>j.id===x.ideId);y&&(!y.chats||y.chats.length===0)&&(v.current=!0,u())},[f,x,m,h,u]),a.useEffect(()=>{if(!x)return;let y=null,j=0,I=-1,g=0;const M=()=>{y=null;const k=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(P=>P.offsetParent!==null);if(k.length===0){j<18&&(j+=1,y=requestAnimationFrame(M));return}let N=0;for(const P of k)P.scrollTop=P.scrollHeight,N+=P.scrollHeight;N===I?g+=1:(g=0,I=N),j+=1,!(g>=2||j>=18)&&(y=requestAnimationFrame(M))};return y=requestAnimationFrame(M),()=>{y!=null&&cancelAnimationFrame(y)}},[x==null?void 0:x.tabKey])}function Ao({isMobile:t,location:s,navigate:n,requestedRemoteTabTarget:r,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:d}){const[l,f]=a.useState(null),[x,m]=a.useState(null),h=a.useMemo(()=>{if(t||!r)return null;const v=d(r);return v&&!Ne(v)&&!je(v)?v:null},[t,r,d]),u=a.useMemo(()=>{const v=l==null?void 0:l.ideId;if(!v)return null;const y=l!=null&&l.tabKey?o.find(j=>j.tabKey===l.tabKey):i?o.find(j=>j.tabKey===i):null;return(y==null?void 0:y.ideId)===v?y:o.find(j=>j.ideId===v&&j.streamSource==="native")||o.find(j=>j.ideId===v)||null},[o,l,i]),b=a.useMemo(()=>{if(u)return c.find(v=>v.id===u.ideId)},[c,u]);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 p=a.useCallback(v=>{v&&(f({ideId:v.ideId,tabKey:v.streamSource==="native"?"native":v.tabKey}),m(v))},[]),w=a.useCallback(()=>{f(null),m(null)},[]);return{remoteDialogConv:u,remoteDialogIdeEntry:b,remoteDialogActiveConv:x,setRemoteDialogActiveConv:m,openRemoteDialog:p,closeRemoteDialog:w}}function wt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Ne(t)||je(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function Jt(t){return t&&(t.ideId||t.daemonId)||""}function $t(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function xn({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:i,setClearedTabs:o}){const[c,d]=a.useState(!1),[l,f]=a.useState(!1),x=a.useCallback(async b=>{try{await t("standalone","launch_ide",{ideType:b,enableCdp:!0})}catch(p){console.error("Launch failed",p)}},[t]),m=a.useCallback(async(b,p)=>{try{const w=b||(s==null?void 0:s.daemonId)||"",v=await t(w,"switch_chat",{id:p,sessionId:p,...wt(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"?$t(r,"⚠️ Session tab not found — try refreshing history"):typeof y=="string"&&y.startsWith("error:")?$t(r,`⚠️ Switch error: ${y}`):$t(r,"⚠️ Session switch failed")}catch(w){console.error("Switch failed",w),$t(r,`❌ Switch failed: ${w.message||"connection error"}`)}},[s,t,r]),h=a.useCallback(async()=>{if(!(!s||c)){d(!0);try{const b=Jt(s);await t(b,"new_chat",{...wt(s)}),o(p=>({...p,[s.tabKey]:Date.now()})),i(p=>({...p,[s.tabKey]:[]}))}catch(b){console.error("New chat failed",b)}finally{d(!1)}}},[s,c,t,o,i]),u=a.useCallback(async()=>{var b;if(!(!s||l)){f(!0);try{const p=Jt(s),w=await t(p,"list_chats",{forceExpand:!0,...wt(s)}),v=(w==null?void 0:w.chats)||((b=w==null?void 0:w.result)==null?void 0:b.chats);w!=null&&w.success&&Array.isArray(v)&&n(s.ideId,v)}catch(p){console.error("Refresh history failed",p)}finally{f(!1)}}},[s,l,t,n]);return{isCreatingChat:c,isRefreshingHistory:l,handleLaunchIde:x,handleSwitchSession:m,handleNewChat:h,handleRefreshHistory:u}}function Ro(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 _o(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function pn(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 Pt(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 mn(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 Lo(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 Eo(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 fn(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 hn(t){return Array(t).fill(100/t)}function Do({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:d,visibleConversations:l,visibleTabKeys:f}){const x=a.useRef(null),m=a.useMemo(()=>Pt(t,f),[t,f]),h=m.assignments,u=a.useMemo(()=>d?1:m.groupCount,[m.groupCount,d]),b=u>1,p=a.useCallback((g,M)=>{s(k=>{const N=new Map(Pt(k,f).assignments);return M===0?N.delete(g):N.set(g,M),N}),r(k=>({...k,[M]:g})),n(M)},[s,f,r,n]),w=a.useCallback(g=>{s(M=>{const k=Pt(M,f).assignments,N=new Map;for(const[P,K]of k)K!==g&&(K>g?N.set(P,K-1):N.set(P,K));return N}),c(M=>{if(M.length<=1)return[];const k=[...M];k.splice(g,1);const N=k.reduce((P,K)=>P+K,0);return N>0?k.map(P=>P/N*100):[]}),n(0)},[s,f,c,n]),v=a.useCallback((g,M)=>{M.preventDefault();const k=x.current;if(!k)return;const N=M.clientX,P=k.offsetWidth,K=o.length===u?[...o]:hn(u),L=T=>{const W=(T.clientX-N)/P*100,$=[...K];$[g]=Math.max(15,K[g]+W),$[g+1]=Math.max(15,K[g+1]-W),c($)},B=()=>{document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",B),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",L),document.addEventListener("mouseup",B)},[o,u,c]),y=a.useCallback((g,M,k)=>{if(u>=4)return;const N=k==="left"?M:M+1;s(P=>{const K=Pt(P,f).assignments,L=new Map;for(const B of l){const T=K.get(B.tabKey)??0,S=T>=N?T+1:T;S>0&&L.set(B.tabKey,S)}return N>0&&L.set(g,N),L}),c(P=>{const K=P.length===u?[...P]:hn(u),L=K[M]??100/u,B=Math.max(15,L/2),T=Math.max(15,L/2),S=[...K];S[M]=B,S.splice(N,0,T);const W=S.reduce(($,z)=>$+z,0);return S.map($=>$/W*100)}),r(P=>{const K=fn(P,N);return K[N]=g,K}),i(P=>{const K=fn(P,N);return K[N]=[g],K}),n(N)},[u,s,f,l,c,r,i,n]);a.useEffect(()=>{Ro(t,h)||s(h)},[t,h,s]),a.useEffect(()=>{const{mapping:g,usedGroups:M}=m;r(k=>{const N=mn(k,g);return pn(k,N)?k:N}),i(k=>{const N=mn(k,g);return pn(k,N)?k:N}),n(k=>{const N=d?0:Lo(k,M,g);return k===N?k:N}),c(k=>{const N=d?[]:Eo(k,M,m.groupCount);return _o(k,N)?k:N})},[m,d,r,i,n,c]);const j=a.useMemo(()=>{const g=Array.from({length:u},()=>[]);for(const M of l){const k=h.get(M.tabKey)??0,N=Math.min(k,u-1);g[N].push(M)}return g},[l,h,u]),I=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:x,normalizedGroupAssignments:h,numGroups:u,isSplitMode:b,groupedConvs:j,moveTabToGroup:p,closeGroup:w,handleResizeStart:v,splitTabRelative:y,clearAllSplits:I}}function $o({ides:t,sendDaemonCommand:s}){const n="0.8.0",r=a.useMemo(()=>t.filter(f=>{if(f.type!=="adhdev-daemon")return!1;const x=f.version||f.daemonVersion||null;return!x||!n?!1:x!==n}),[n,t]),[i,o]=a.useState(!1),[c,d]=a.useState({}),l=a.useCallback(async f=>{var x,m;d(h=>({...h,[f]:"upgrading"}));try{const h=await s(f,"daemon_upgrade",{});(x=h==null?void 0:h.result)!=null&&x.upgraded||(m=h==null?void 0:h.result)!=null&&m.success?d(u=>({...u,[f]:"done"})):d(u=>({...u,[f]:"error"}))}catch{d(h=>({...h,[f]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:l}}function rs({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),x=a.useCallback(async b=>{if(!s)return;const p=b.trim();if(!p||f.current)return;const w=s.tabKey;f.current=!0,l(!0);const v=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,y={role:"user",content:p,timestamp:Date.now(),_localId:v};n(j=>({...j,[w]:[...j[w]||[],y]}));try{const j=Jt(s);if(!j)return;await t(j,"send_chat",{message:p,text:p,...wt(s)}),setTimeout(()=>{const I=Date.now()-6e4;n(g=>{const M=g[w];if(!M)return g;const k=M.filter(N=>N.timestamp>I);return k.length===M.length?g:{...g,[w]:k}})},6e4)}catch(j){console.error("Send failed",j),n(I=>({...I,[w]:(I[w]||[]).filter(g=>g._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(b){console.error("Relaunch failed",b)}},[s,t]),h=a.useCallback(async b=>{if(s){s.transport!=="pty"&&r(p=>[...p,{ideId:s.tabKey,text:`🖱️ **${b}** clicked`,timestamp:Date.now()}]);try{const w=(s.modalButtons||[]).indexOf(b),v=b.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),y=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(v),j=Jt(s);if(!j)return;(await t(j,"resolve_action",{button:b,action:y?"approve":"reject",...w>=0&&{buttonIndex:w},...wt(s)})).success||r(g=>[...g,{ideId:s.tabKey,text:`⚠️ **${b}** failed — button not found`,timestamp:Date.now()}])}catch(p){console.error("[ModalButton] Error:",p),r(w=>[...w,{ideId:s.tabKey,text:`❌ **${b}** error`,timestamp:Date.now()}])}}},[s,t,r]),u=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(b){console.error("Focus agent failed",b)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:d,isFocusingAgent:o,handleSendChat:x,handleRelaunch:m,handleModalButton:h,handleFocusAgent:u}}const Bs=a.memo(function({activeConv:s,clearToken:n,isCliTerminal:r,ideEntry:i,terminalRef:o,handleModalButton:c,handleRelaunch:d,handleSendChat:l,isSendingChat:f,handleFocusAgent:x,isFocusingAgent:m,actionLogs:h,userName:u}){return e.jsxs(e.Fragment,{children:[e.jsx(Fn,{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(_s,{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(gi,{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(ws,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:x,isFocusingAgent:m,actionLogs:h,userName:u})})]}):e.jsx(ws,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:x,isFocusingAgent:m,actionLogs:h,userName:u})]})},(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 Po({selectedConversation:t,isAcp:s,selectedIdeEntry:n,actionLogs:r,userName:i,isSendingChat:o,isFocusingAgent:c,onBack:d,onOpenNativeConversation:l,onOpenMachine:f,onOpenHistory:x,onOpenRemote:m,onHideConversation:h,onStopCli:u,cliViewMode:b,onSetCliViewMode:p,handleSendChat:w,handleFocusAgent:v,handleModalButton:y,handleRelaunch:j}){const I=a.useRef(null),g=Ne(t)&&!s,M=g&&b==="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(Dn,{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 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary",children:e.jsx(Yn,{conversation:t,onOpenNativeConversation:()=>l(t),onOpenMachine:()=>f(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[g&&b&&e.jsx(Ds,{mode:b,onChange:p,compact:!0}),g&&u&&e.jsx("button",{onClick:u,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(Vt,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>x(t),type:"button",children:e.jsx(As,{size:14})}),!s&&!g&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>m(t),type:"button",children:e.jsx(Le,{size:14})}),h&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(t),type:"button",title:"Close chat",children:e.jsx(Vt,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(Bs,{activeConv:t,clearToken:0,isCliTerminal:M,ideEntry:n,terminalRef:I,handleModalButton:y,handleRelaunch:j,handleSendChat:w,isSendingChat:o,handleFocusAgent:v,isFocusingAgent:c,actionLogs:r,userName:i})})]})}const fs={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 Bo(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function yr(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":n;a.useEffect(()=>{s(Bo())},[]);const d=a.useCallback(()=>{navigator.clipboard.writeText(fs[c].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="powershell"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-accent cursor-pointer group",onClick:d,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:fs[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:fs[c].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-text-muted opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:i?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function vr({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 bt({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 Bt({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}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:Hn(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(Le,{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 gn({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 Ko({section:t,attentionItems:s,unreadItems:n,workingItems:r,completedItems:i,hiddenConversations:o,machineCards:c,getAvatarText:d,onOpenConversation:l,onShowConversation:f,onShowAllHidden:x,onOpenMachine:m,onOpenSettings:h,onOpenAccount:u,onSectionChange:b,wsStatus:p="connected",isStandalone:w=!1}){const v=p==="disconnected"||p==="reconnecting"||p==="offline"||p==="auth_failed",y=c.length>0,j=s.length>0||n.length>0||r.length>0||i.length>0,I=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:I}),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(ts,{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(es,{size:18})}),u&&e.jsx("button",{onClick:u,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($n,{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(bt,{icon:e.jsx(gn,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:p==="offline"?"Your device appears to be offline. Waiting for network…":p==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(bt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:w?"Waiting for your IDE":"Connect your first machine",subtitle:w?"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:!w&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(yr,{})})}):c.map(g=>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(g.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(g.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:g.label}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:g.unread>0?e.jsxs("span",{className:"text-accent-primary",children:[g.unread," new"]}):g.total>0?`${g.total} chats`:"Idle"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:g.subtitle}),g.total>0?e.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[g.total," chat",g.total!==1?"s":"",g.unread>0?` · ${g.unread} unread`:""]}):e.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},g.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(g=>e.jsx(Bt,{item:g,type:"needs_attention",getAvatarText:d,onOpenConversation:l},g.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(g=>e.jsx(Bt,{item:g,type:"task_complete",getAvatarText:d,onOpenConversation:l},g.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(g=>e.jsx(Bt,{item:g,type:"working",getAvatarText:d,onOpenConversation:l},g.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(g=>e.jsx(Bt,{item:g,type:"earlier",getAvatarText:d,onOpenConversation:l},g.conversation.tabKey)):j?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):v?e.jsx(bt,{icon:e.jsx(gn,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):y?e.jsx(bt,{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(tt,{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(bt,{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:x,children:"Restore all"})]}),o.map(g=>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(g),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(g.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:g.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:[g.displaySecondary,g.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(Le,{size:11})," ",g.machineName]})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:"Tap to restore and open"})]})]},g.tabKey))]})]}),e.jsx(vr,{section:t,onSectionChange:b})]})}function Wo({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:n,cliProviders:r,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:d,section:l,showBottomNav:f,onBack:x,onSectionChange:m,onOpenConversation:h,onOpenRecent:u,onOpenMachineDetails:b,onMachineUpgrade:p,onLaunchDetectedIde:w,onAddWorkspace:v,onLaunchWorkspaceProvider:y}){var re,J,Z;const j=(D,G,H)=>D?"ide":G>0?"cli":H>0?"acp":null,[I,g]=a.useState(!1),M=D=>D==="ide"?"IDE":D==="cli"?"CLI":"ACP",k=n.slice(0,4),N=s.slice(0,3),P=a.useMemo(()=>{const D=k.map(H=>({key:`recent-launch:${H.id}`,type:"session",primary:H.label,secondary:`${M(H.kind)}${H.subtitle?` · ${H.subtitle}`:""}`,unread:!1,onClick:()=>u(H)})),G=N.map(H=>({key:`recent-chat:${H.conversation.tabKey}`,type:"conversation",primary:H.conversation.displayPrimary,secondary:`Chat${H.conversation.displaySecondary?` · ${H.conversation.displaySecondary}`:""}${H.timestamp?` · ${Hn(H.timestamp)}`:""}`,unread:H.unread,onClick:()=>h(H.conversation)}));return[...D,...G]},[h,u,N,k]),K=I?P:P.slice(0,5),L=P.length>0,B=(((re=t.detectedIdes)==null?void 0:re.length)||0)>0,T=a.useMemo(()=>t.workspaces||[],[t]),S=t.defaultWorkspaceId||null,[W,$]=a.useState(S||((J=T[0])==null?void 0:J.id)||""),[z,E]=a.useState(""),[_,O]=a.useState(j(B,r.length,i.length)),A=a.useRef(null),q=W==="__custom__"?z.trim():((Z=T.find(D=>D.id===W))==null?void 0:Z.path)||"",ce=W==="__custom__"&&!!q&&d.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(d.message);return a.useEffect(()=>{var D;A.current!==t.id&&(A.current=t.id,$(S||((D=T[0])==null?void 0:D.id)||"__custom__"),E(""),O(j(B,r.length,i.length)))},[i.length,r.length,S,B,t.id,T]),a.useEffect(()=>{var D;W!=="__custom__"&&(W&&T.some(G=>G.id===W)||$(S||((D=T[0])==null?void 0:D.id)||"__custom__"))},[S,W,T]),a.useEffect(()=>{_==="ide"&&B||_==="cli"&&r.length>0||_==="acp"&&i.length>0||O(j(B,r.length,i.length))},[_,i.length,r.length,B]),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:x,type:"button","aria-label":"Back",children:e.jsx(Dn,{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:qe(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:[L&&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:K.map(D=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${D.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:D.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:D.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:D.secondary})]},D.key))}),P.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:()=>g(D=>!D),children:I?"Show fewer":`Show ${P.length-5} more`})})]}),(B||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 enter a path before choosing IDE, CLI, or ACP."}),e.jsx("select",{value:W,onChange:D=>{$(D.target.value),D.target.value!=="__custom__"&&E("")},className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:T.length>0?e.jsxs(e.Fragment,{children:[T.map(D=>e.jsxs("option",{value:D.id,children:[D.id===S?"⭐ ":"",D.label||D.path.split("/").filter(Boolean).pop()||D.path]},D.id)),e.jsx("option",{value:"__custom__",children:"Custom path…"})]}):e.jsx("option",{value:"__custom__",children:"Enter workspace path…"})}),W==="__custom__"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",value:z,onChange:D=>E(D.target.value),placeholder:"/absolute/path",className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm"}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[40px] rounded-xl border border-accent-primary/30 bg-accent-primary/10 text-text-primary text-[13px] font-bold",onClick:()=>{q&&v(q)},children:"Save workspace"})]}),q&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:q})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[B&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${_==="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:()=>O("ide"),children:"IDE"}),r.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${_==="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:()=>O("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${_==="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:()=>O("acp"),children:"ACP"})]}),_&&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:_==="ide"?"Choose an IDE":_==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:_==="ide"?(t.detectedIdes||[]).slice(0,6).map(D=>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:()=>w(D.type,{workspacePath:q||null}),children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:D.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:q||"Use selected workspace"})]},D.type)):(_==="cli"?r:i).map(D=>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:()=>y(_,D.type,{workspaceId:W!=="__custom__"?W:null,workspacePath:q||null}),children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[D.icon?`${D.icon} `:"",D.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:q||"Use selected workspace"})]},D.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,ce&&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(q,{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:p,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:b,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"})]})]})]})]}),f&&e.jsx(vr,{section:l,onSectionChange:m})]})}function Oo(t){return er(t)}function bn(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1],n=Oo(s==null?void 0:s.content);return n||(t.title?t.title:t.displaySecondary||"No messages yet")}function zo(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Kt(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function Uo({conversations:t,hiddenConversations:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,requestedActiveTabKey:f,onRequestedActiveTabConsumed:x,requestedMachineId:m,onRequestedMachineConsumed:h,requestedMobileSection:u,onRequestedMobileSectionConsumed:b,onOpenAccount:p,onOpenHistory:w,onOpenRemote:v,onStopCli:y,wsStatus:j,isConnected:I,onShowHiddenConversation:g,onShowAllHiddenConversations:M,onHideConversation:k}){const[N,P]=a.useState(()=>{var U;return((U=t[0])==null?void 0:U.tabKey)||null}),[K,L]=a.useState(()=>t[0]?"chat":"inbox"),[B,T]=a.useState("chats"),[S,W]=a.useState(null),[$,z]=a.useState("inbox"),[E,_]=a.useState("idle"),[O,A]=a.useState(""),q=a.useRef(null),ce=mt(),re="0.8.0",J=a.useMemo(()=>t.find(U=>U.tabKey===N)||t[0]||null,[t,N]),Z=a.useMemo(()=>J?n.find(U=>U.id===J.ideId):void 0,[n,J]),D=a.useMemo(()=>!J||je(J)||!Ne(J)?null:pt(J),[J]),G=a.useMemo(()=>n.filter(U=>U.type==="adhdev-daemon"||U.daemonMode).sort(ui),[n]),H=a.useMemo(()=>G.find(U=>U.id===S)||null,[G,S]),C=a.useMemo(()=>It(n),[n]),X=rs({sendDaemonCommand:i,activeConv:J||void 0,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),Y=a.useCallback(U=>{if(!U||!U.sessionId)return;const F=ut(U,C),se=Math.max(Date.now(),ns(U),F.lastUpdated||0);Kt("mark_read:start",{tabKey:U.tabKey,sessionId:U.sessionId,displayPrimary:U.displayPrimary,inboxBucket:F.inboxBucket,unread:F.unread,lastSeenAt:F.lastSeenAt,lastUpdated:F.lastUpdated,activityAt:ms(U,F.lastUpdated),readAt:se}),i(U.daemonId||U.ideId,"mark_session_seen",{sessionId:U.sessionId,seenAt:se}).then(le=>{Kt("mark_read:result",{tabKey:U.tabKey,sessionId:U.sessionId,result:le})}).catch(le=>{Kt("mark_read:error",{tabKey:U.tabKey,sessionId:U.sessionId,error:le instanceof Error?le.message:String(le)})})},[C,i]);a.useEffect(()=>{var F;if(!J){L("inbox"),P(((F=t[0])==null?void 0:F.tabKey)||null),q.current=null;return}if(K!=="chat"){q.current=null;return}const U=`${J.tabKey}:${J.sessionId||""}`;q.current!==U&&(q.current=U,Y(J))},[t,Y,K,J]),a.useEffect(()=>{if(!f)return;const U=t.find(F=>F.tabKey===f);U&&(P(U.tabKey),L("chat"),x==null||x())},[t,x,f]),a.useEffect(()=>{if(!m)return;const U=G.find(F=>F.id===m);U&&(W(U.id),_("idle"),A(""),T("machines"),z("inbox"),L("machine"),h==null||h())},[G,h,m]),a.useEffect(()=>{u&&(T(u),L("inbox"),b==null||b())},[b,u]);const ee=a.useMemo(()=>t.map(U=>{const F=K==="chat"&&(J==null?void 0:J.tabKey)===U.tabKey,se=St(U,C,{hideOpenTaskCompleteUnread:!0,isOpenConversation:F}),le=ut(U,C),ge=ms(U,(le==null?void 0:le.lastUpdated)||0),be=bn(U);return{conversation:U,timestamp:ge,preview:be,unread:se.unread,requiresAction:se.requiresAction,isWorking:se.isWorking,inboxBucket:se.inboxBucket}}).sort((U,F)=>{const se=F.timestamp-U.timestamp;return se!==0?se:mr(U.conversation,F.conversation)}),[t,C,K,J]);a.useEffect(()=>{const U=ee.filter(F=>F.inboxBucket==="task_complete"||F.unread);U.length!==0&&Kt("inbox_state",{screen:K,selectedTabKey:N,items:U.map(F=>{const se=ut(F.conversation,C);return{liveState:se,tabKey:F.conversation.tabKey,sessionId:F.conversation.sessionId,displayPrimary:F.conversation.displayPrimary,serverBucket:se.inboxBucket,computedBucket:F.inboxBucket,serverUnread:se.unread,computedUnread:F.unread,lastSeenAt:se.lastSeenAt,lastUpdated:se.lastUpdated,activityAt:ms(F.conversation,se.lastUpdated)}})})},[ee,C,K,N]);const xe=a.useMemo(()=>ee.filter(U=>U.requiresAction),[ee]),ie=a.useMemo(()=>ee.filter(U=>U.unread&&!U.requiresAction),[ee]),me=a.useMemo(()=>ee.filter(U=>!U.unread&&!U.requiresAction&&U.isWorking),[ee]),Q=a.useMemo(()=>ee.filter(U=>!U.unread&&!U.requiresAction&&!U.isWorking),[ee]),R=a.useMemo(()=>H?ee.filter(U=>U.conversation.daemonId===H.id||U.conversation.ideId===H.id):[],[ee,H]),V=a.useMemo(()=>{if(!H)return[];const U=H.recentLaunches||[];return U.length>0?U.map(F=>({id:F.id,label:F.title||F.providerName||F.providerType,kind:F.kind,providerType:F.providerType,providerSessionId:F.providerSessionId,subtitle:F.currentModel||F.workspace||void 0,workspace:F.workspace,currentModel:F.currentModel})):n.filter(F=>!F.daemonMode&&F.daemonId===H.id).map(F=>{var le,ge,be,ne,pe;const se=qt(F)?"cli":yt(F)?"acp":"ide";return{id:`${se}:${F.type}:${F.workspace||""}`,label:((le=F.activeChat)==null?void 0:le.title)||(qt(F)?F.cliName||F.type:yt(F)&&F.cliName||F.type),kind:se,providerType:F.type,providerSessionId:F.providerSessionId,subtitle:yt(F)?F.currentModel||F.workspace||void 0:F.workspace||void 0,workspace:F.workspace||void 0,currentModel:F.currentModel,timestamp:((pe=(ne=(be=(ge=F.activeChat)==null?void 0:ge.messages)==null?void 0:be.at)==null?void 0:ne.call(be,-1))==null?void 0:pe.timestamp)||0}}).sort((F,se)=>se.timestamp-F.timestamp).map(({timestamp:F,...se})=>se)},[n,H]),te=(H==null?void 0:H.version)||(H==null?void 0:H.daemonVersion)||null,ae=!!H&&!!te&&!0&&te!==re,ue=a.useMemo(()=>(H==null?void 0:H.availableProviders)||[],[H]),oe=a.useMemo(()=>ue.filter(U=>U.category==="cli").map(U=>({type:U.type,displayName:U.displayName||U.type,icon:U.icon})),[ue]),he=a.useMemo(()=>ue.filter(U=>U.category==="acp").map(U=>({type:U.type,displayName:U.displayName||U.type,icon:U.icon})),[ue]),Pe=a.useMemo(()=>{const U=new Map;for(const F of ee){const se=F.conversation.daemonId||F.conversation.ideId,le=U.get(se);le?le.push(F):U.set(se,[F])}return G.map(F=>{const se=U.get(F.id)||[],le=[...se].sort((He,Mt)=>Mt.timestamp-He.timestamp)[0]||null,ge=(le==null?void 0:le.conversation)||null,be=se.filter(He=>He.unread||He.requiresAction).length,ne=F.status==="online"?"Connected":F.status||"Unknown",pe=[F.platform||"machine",ne].filter(Boolean);return{id:F.id,label:qe(F,{fallbackId:F.id}),subtitle:pe.join(" · "),unread:be,total:se.length,latestConversation:ge,latestTimestamp:(le==null?void 0:le.timestamp)||0,preview:ge?`${ge.displayPrimary} · ${bn(ge)}`:"No active conversations yet. Open the machine to launch an IDE, CLI, or ACP session."}}).sort((F,se)=>{const le=Math.max(F.latestTimestamp,Gt(G.find(be=>be.id===F.id))),ge=Math.max(se.latestTimestamp,Gt(G.find(be=>be.id===se.id)));return ge!==le?ge-le:F.label.localeCompare(se.label)})},[ee,G]),Me=a.useCallback(U=>{P(U.tabKey),L("chat"),Y(U)},[Y]),Be=a.useCallback(U=>{const F=t.find(se=>se.ideId===U.ideId&&se.streamSource==="native");F&&(P(F.tabKey),L("chat"),Y(F))},[t,Y]),Re=a.useCallback(()=>{Y(J),L("inbox")},[Y,J]),Ge=a.useCallback(U=>{W(U),_("idle"),A(""),T("machines"),z("inbox"),L("machine")},[]),Ye=a.useCallback(U=>{var se;const F=U.daemonId||((se=U.ideId)==null?void 0:se.split(":")[0])||U.ideId;F&&(W(F),_("idle"),A(""),T("machines"),z("chat"),L("machine"))},[]),Ue=a.useCallback(()=>{L($)},[$]),Xe=a.useCallback(async(U,F,se)=>{var le;try{_("loading"),A(`Launching ${F}…`);const ge={ideType:F,enableCdp:!0};(le=se==null?void 0:se.workspacePath)!=null&&le.trim()&&(ge.workspace=se.workspacePath.trim()),await i(U,"launch_ide",ge),_("done"),A(`${F} launch requested`)}catch(ge){_("error"),A(ge instanceof Error?ge.message:"Launch IDE failed"),console.error("Launch IDE failed",ge)}},[i]),Je=a.useCallback(async(U,F,se)=>{if(F.trim())try{_("loading"),A(se!=null&&se.createIfMissing?"Creating folder…":"Saving workspace…");const le=await i(U,"workspace_add",{path:F.trim(),createIfMissing:(se==null?void 0:se.createIfMissing)===!0});if(le!=null&&le.success){_("done"),A(se!=null&&se.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}_("error"),A((le==null?void 0:le.error)||"Could not save workspace")}catch(le){_("error"),A(le instanceof Error?le.message:"Could not save workspace")}},[i]),ct=a.useCallback(async U=>{var F,se,le,ge,be,ne;try{_("loading"),A("Starting daemon upgrade…");const pe=await i(U,"daemon_upgrade",{});if((F=pe==null?void 0:pe.result)!=null&&F.alreadyLatest){_("done"),A(`Already on v${((se=pe==null?void 0:pe.result)==null?void 0:se.version)||"latest"}.`);return}if((le=pe==null?void 0:pe.result)!=null&&le.upgraded||(ge=pe==null?void 0:pe.result)!=null&&ge.success){_("done"),A(`Upgrade to v${((be=pe==null?void 0:pe.result)==null?void 0:be.version)||"latest"} started. Daemon is restarting…`);return}_("error"),A(((ne=pe==null?void 0:pe.result)==null?void 0:ne.error)||"Upgrade failed")}catch(pe){_("error"),A(pe instanceof Error?pe.message:"Upgrade failed")}},[i]),We=a.useCallback(async(U,F,se,le)=>{var ge;try{_("loading"),A(`Launching ${se}…`);const be={cliType:se};(ge=le==null?void 0:le.workspacePath)!=null&&ge.trim()?be.dir=le.workspacePath.trim():le!=null&&le.workspaceId&&(be.workspaceId=le.workspaceId),le!=null&&le.resumeSessionId&&(be.resumeSessionId=le.resumeSessionId);const ne=await i(U,"launch_cli",be),pe=(ne==null?void 0:ne.result)||ne,He=(pe==null?void 0:pe.sessionId)||(pe==null?void 0:pe.id);if(ne!=null&&ne.success&&He){_("done"),A(`${se} launched`),ce(`/dashboard?activeTab=${encodeURIComponent(He)}`);return}_("error"),A((ne==null?void 0:ne.error)||(pe==null?void 0:pe.error)||`Could not launch ${F.toUpperCase()} workspace`)}catch(be){_("error"),A(be instanceof Error?be.message:`Could not launch ${F.toUpperCase()} workspace`)}},[ce,i]),ft=a.useCallback(async U=>{if(H){if(U.kind==="ide"&&U.providerType){await Xe(H.id,U.providerType,{workspacePath:U.workspace||null});return}if((U.kind==="cli"||U.kind==="acp")&&U.providerType){await We(H.id,U.kind,U.providerType,{workspacePath:U.workspace||null,resumeSessionId:U.providerSessionId||null});return}}},[Xe,We,H]);return e.jsx("div",{className:"dashboard-mobile-chat",children:K==="chat"&&J?e.jsx(Po,{selectedConversation:J,isAcp:je(J),selectedIdeEntry:Z,actionLogs:r,userName:l,isSendingChat:X.isSendingChat,isFocusingAgent:X.isFocusingAgent,handleModalButton:X.handleModalButton,handleRelaunch:X.handleRelaunch,onBack:Re,onOpenNativeConversation:Be,onOpenMachine:Ye,onHideConversation:k,onOpenHistory:w,onOpenRemote:v,onStopCli:y,cliViewMode:D,onSetCliViewMode:async U=>{if(J&&D!==U)try{await i(J.daemonId||J.ideId,"set_cli_view_mode",{targetSessionId:J.sessionId,cliType:J.ideType||J.agentType,mode:U})}catch(F){console.error("Failed to switch CLI view mode:",F)}},handleSendChat:X.handleSendChat,handleFocusAgent:X.handleFocusAgent}):K==="machine"&&H?e.jsx(Wo,{selectedMachineEntry:H,selectedMachineConversations:R,selectedMachineRecentLaunches:V,cliProviders:oe,acpProviders:he,selectedMachineNeedsUpgrade:ae,appVersion:re,machineAction:{state:E,message:O},section:B,showBottomNav:$==="inbox",onBack:Ue,onSectionChange:U=>{T(U),L("inbox")},onOpenConversation:Me,onOpenRecent:ft,onOpenMachineDetails:()=>ce(`/machines/${H.id}`),onMachineUpgrade:()=>ct(H.id),onLaunchDetectedIde:(U,F)=>Xe(H.id,U,F),onAddWorkspace:(U,F)=>Je(H.id,U,F),onLaunchWorkspaceProvider:(U,F,se)=>We(H.id,U,F,se)}):e.jsx(Ko,{section:B,attentionItems:xe,unreadItems:ie,workingItems:me,completedItems:Q,hiddenConversations:s,machineCards:Pe,getAvatarText:zo,onOpenConversation:Me,onShowConversation:g,onShowAllHidden:M,onOpenMachine:Ge,onOpenSettings:()=>ce("/settings"),onOpenAccount:p,onSectionChange:T,wsStatus:j,isConnected:I,isStandalone:d})})}function hs(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Ho({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[d,l]=a.useState(!1),[f,x]=a.useState(null),m=a.useCallback(()=>{c.current=0,l(!1),x(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",m),window.addEventListener("drop",m),()=>{window.removeEventListener("dragend",m),window.removeEventListener("drop",m)}),[m]);const h=a.useCallback(w=>{w.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,l(!0))},[]),u=a.useCallback(w=>{if(!w.dataTransfer.types.includes("text/tab-key"))return;if(w.preventDefault(),!hs(s,n)){x("merge");return}const v=w.currentTarget.getBoundingClientRect(),y=w.clientX-v.left,j=v.width/3;y<j?x("split-left"):y>j*2?x("split-right"):x("merge")},[s,n]),b=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,l(!1),x(null))},[]),p=a.useCallback(w=>{c.current=0,l(!1);const v=w.dataTransfer.getData("text/tab-key"),y=v?t.some(I=>I.tabKey===v):!1,j=f;if(x(null),o(),!!v){if(w.preventDefault(),j==="split-left"&&hs(s,n)){n==null||n(v,"split-left");return}if(j==="split-right"&&hs(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:u,handleDragLeave:b,handleDrop:p}}function Fo(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 Vo({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[d,l]=a.useState(n??[]),[f,x]=a.useState(null),m=a.useRef(null),h=a.useRef(null),u=a.useRef(r),b=a.useRef(i);a.useEffect(()=>{u.current=r},[r]),a.useEffect(()=>{b.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{l(k=>{const N=Fo(k,t);return N.length===k.length&&N.every((P,K)=>P===k[K])?k:N})},[t]);const p=a.useMemo(()=>{const k=f??d;if(k.length===0)return t;const N=new Map(k.map((P,K)=>[P,K]));return[...t].sort((P,K)=>{const L=N.get(P.tabKey)??999,B=N.get(K.tabKey)??999;return L-B})},[t,f,d]);a.useEffect(()=>{var N,P;if(p.length===0){o!==null&&(c(null),(N=u.current)==null||N.call(u,null));return}if(o&&p.some(K=>K.tabKey===o))return;const k=p[0].tabKey;k!==o&&(c(k),(P=u.current)==null||P.call(u,k))},[p,o]);const w=a.useMemo(()=>p.find(k=>k.tabKey===o),[p,o]),v=a.useCallback(k=>{var N;c(k),(N=u.current)==null||N.call(u,k)},[]),y=a.useCallback((k,N,P)=>{l(K=>{var S;const L=K.filter(W=>W!==k),B=L.indexOf(N);if(B<0)return K;const T=P==="left"?B:B+1;return L.splice(T,0,k),(S=b.current)==null||S.call(b,L),L}),x(null)},[]),j=a.useCallback((k,N,P)=>{const L=(d.length>0?d:t.map(S=>S.tabKey)).filter(S=>S!==k),B=L.indexOf(N);if(B<0)return;const T=P==="left"?B:B+1;L.splice(T,0,k),m.current=L,x(L)},[d,t]),I=a.useCallback(()=>{var N;const k=m.current;k&&(l(k),(N=b.current)==null||N.call(b,k))},[]),g=a.useCallback(()=>{m.current=null,x(null)},[]),M=a.useCallback(k=>{l(N=>{var K;const P=N.filter(L=>L!==k);return P.push(k),(K=b.current)==null||K.call(b,P),P})},[]);return{activeTabId:o,activeConv:w,sortedConversations:p,previewOrderRef:m,draggingTabRef:h,selectTab:v,handleTabReorder:y,updatePreviewOrder:j,commitPreviewOrder:I,clearPreviewOrder:g,moveTabToEnd:M,setDraggingTabKey:k=>{h.current=k}}}function qo({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 Ks({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(yr,{}),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(On,{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 jr="adhdev-tab-shortcuts";function Go(){try{return JSON.parse(localStorage.getItem(jr)||"{}")}catch{return{}}}function Yo({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,o]=a.useState(()=>Go()),[c,d]=a.useState(null),l=a.useCallback(x=>{const m=[];return x.metaKey&&m.push(r?"⌘":"Meta"),x.ctrlKey&&m.push("Ctrl"),x.altKey&&m.push(r?"⌥":"Alt"),x.shiftKey&&m.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(x.key)?null:(m.push(x.key.length===1?x.key.toUpperCase():x.key),m.join("+"))},[r]),f=a.useCallback(x=>{o(x);try{localStorage.setItem(jr,JSON.stringify(x))}catch{}},[]);return a.useEffect(()=>{if(!c)return;const x=m=>{if(m.preventDefault(),m.stopPropagation(),m.key==="Escape"){d(null);return}const h=l(m);if(!h)return;const u={...i};for(const[b,p]of Object.entries(u))p===h&&delete u[b];u[c]=h,f(u),d(null)};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[c,i,f,l]),a.useEffect(()=>{const x=m=>{if(!(!m.ctrlKey&&!m.metaKey&&!m.altKey)){for(const[h,u]of Object.entries(i))if(t.includes(h)&&l(m)===u){m.preventDefault(),s(),n(h);return}}};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[i,t,s,n,l]),{isMac:r,tabShortcuts:i,shortcutListening:c,setShortcutListening:d,saveShortcuts:f}}const Xo=a.memo(function({conv:s,isActive:n,isDraggedTab:r,isTaskCompleteUnread:i,shortcut:o,conversationKeys:c,draggingTabRef:d,onFocus:l,onSelectTab:f,onConversationActivated:x,onPreviewReorder:m,onReorderTab:h,onCommitPreviewOrder:u,onClearPreviewOrder:b,onDragStateReset:p,onDragTabKeyChange:w,onReceiveTab:v,onOpenContextMenu:y,longPressTimer:j,isGroupActive:I}){const g=ss(s),M=g.isGenerating?"agent-tab-generating":g.isWaiting?"agent-tab-waiting":"",k=g.isReconnecting,N=a.useCallback(z=>{d.current=s.tabKey,w(s.tabKey),z.dataTransfer.setData("text/tab-key",s.tabKey),z.dataTransfer.effectAllowed="move"},[s.tabKey,d,w]),P=a.useCallback(()=>{d.current=null,w(null),u(),b(),p()},[d,w,u,b,p]),K=a.useCallback(z=>{const E=d.current;if(!(!E||E===s.tabKey)&&z.dataTransfer.types.includes("text/tab-key")){z.preventDefault(),z.stopPropagation();const _=z.currentTarget.getBoundingClientRect(),O=z.clientX<_.left+_.width/2?"left":"right";m(E,s.tabKey,O)}},[s.tabKey,d,m]),L=a.useCallback(z=>{z.preventDefault(),z.stopPropagation();const E=z.dataTransfer.getData("text/tab-key");if(E&&E!==s.tabKey){const _=z.currentTarget.getBoundingClientRect(),O=z.clientX<_.left+_.width/2?"left":"right";c.includes(E)?h(E,s.tabKey,O):v&&v(E)}b()},[s.tabKey,c,h,v,b]),B=a.useCallback(z=>{z.stopPropagation(),l(),f(s.tabKey),x(s)},[s,x,l,f]),T=a.useCallback(z=>{z.preventDefault(),y(z.clientX,z.clientY,s.tabKey)},[s.tabKey,y]),S=a.useCallback(z=>{const E=z.touches[0];j.current=setTimeout(()=>{y(E.clientX,E.clientY,s.tabKey)},600)},[s.tabKey,j,y]),W=a.useCallback(()=>{j.current&&clearTimeout(j.current)},[j]),$=["adhdev-dockview-tab",M,n&&"is-active",I&&"is-group-active",k&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:$,draggable:!0,onDragStart:N,onDragEnd:P,onDragOver:K,onDrop:L,onClick:B,onContextMenu:T,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:g.isGenerating?e.jsx("div",{className:"tab-spinner"}):g.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):k?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):g.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:k?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):g.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 Jo({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,unreadTabKeys:i,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:x,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:u,onDragTabKeyChange:b,onMoveTab:p,onReceiveTab:w,onHideTab:v,isGroupActive:y}){const[j,I]=a.useState(null),g=a.useRef(null),M=a.useRef(null),k=a.useMemo(()=>t.map(S=>S.tabKey),[t]);Ct("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(j==null?void 0:j.tabKey)||null});const{isMac:N,tabShortcuts:P,shortcutListening:K,setShortcutListening:L,saveShortcuts:B}=Yo({sortedTabKeys:t.map(S=>S.tabKey),onFocus:c,onSelectTab:d});a.useEffect(()=>{if(!j)return;const S=W=>{const $=document.querySelector("[data-pane-context-menu]");$&&$.contains(W.target)||I(null)};return window.addEventListener("mousedown",S,!0),()=>window.removeEventListener("mousedown",S,!0)},[j]),a.useEffect(()=>{const S=M.current;if(!S)return;const W=$=>{Math.abs($.deltaY)>Math.abs($.deltaX)&&($.preventDefault(),S.scrollLeft+=$.deltaY)};return S.addEventListener("wheel",W,{passive:!1}),()=>S.removeEventListener("wheel",W)},[]);const T=a.useCallback((S,W,$)=>{I({x:S,y:W,tabKey:$})},[]);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(Xo,{conv:S,isActive:s===S.tabKey,isDraggedTab:o.current===S.tabKey,isTaskCompleteUnread:i.has(S.tabKey),shortcut:P[S.tabKey],conversationKeys:k,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:x,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:u,onDragTabKeyChange:b,onReceiveTab:w,onOpenContextMenu:T,longPressTimer:g,isGroupActive:y},S.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),j&&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:j.x,top:j.y},children:[p&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{p(j.tabKey,"left"),I(null)},children:"← Move to Left Group"}),p&&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:()=>{p(j.tabKey,"right"),I(null)},children:"Move to Right Group →"}),p&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{p(j.tabKey,"split-left"),I(null)},children:"⇤ Split Left"}),p&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{p(j.tabKey,"split-right"),I(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(),L(j.tabKey),I(null)},children:["⌨ ",P[j.tabKey]?`Change shortcut (${P[j.tabKey]})`:"Set shortcut"]}),P[j.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={...P};delete S[j.tabKey],B(S),I(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(j.tabKey),I(null)},children:"🚫 Hide from Dashboard"})]}),!p&&!v&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),K&&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:()=>L(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. ",N?"⌘+1":"Ctrl+1",", ",N?"⌥+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 Zo({conversations:t,ides:s,clearedTabs:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,groupIndex:f,onFocus:x,isSplitMode:m,numGroups:h,onMoveTab:u,onReceiveTab:b,style:p,detectedIdes:w,handleLaunchIde:v,onActiveTabChange:y,initialActiveTabId:j,initialTabOrder:I,onTabOrderChange:g,onHideTab:M,isFocused:k}){const{sendCommand:N}=st(),P=a.useRef(null),{activeTabId:K,activeConv:L,sortedConversations:B,draggingTabRef:T,selectTab:S,handleTabReorder:W,updatePreviewOrder:$,commitPreviewOrder:z,clearPreviewOrder:E,moveTabToEnd:_,setDraggingTabKey:O}=Vo({conversations:t,initialActiveTabId:j,initialTabOrder:I,onActiveTabChange:y,onTabOrderChange:g}),A=rs({sendDaemonCommand:i,activeConv:L,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),{dragOver:q,dropAction:ce,resetDragState:re,handleDragEnter:J,handleDragOver:Z,handleDragLeave:D,handleDrop:G}=Ho({conversations:t,numGroups:h,onMoveTab:u,onReceiveTab:b,onOwnTabDrop:_,onClearPreviewOrder:E}),H=L&&!je(L)&&pt(L)==="terminal",C=a.useMemo(()=>L?s.find(ie=>ie.id===L.ideId):void 0,[s,L]),X=a.useMemo(()=>L?r.filter(ie=>ie.ideId===L.tabKey):[],[r,L]),Y=a.useMemo(()=>It(s),[s]),ee=a.useMemo(()=>new Set(B.filter(ie=>qa(ie,Y,{isOpenConversation:ie.tabKey===K})).map(ie=>ie.tabKey)),[K,Y,B]);Ct("PaneGroup",{groupIndex:f,conversationCount:t.length,activeTabId:K,dragOver:q});const xe=a.useCallback(ie=>{ie.streamSource==="agent-stream"&&ie.agentType&&N(ie.ideId,"focus_session",{agentType:ie.agentType,...ie.sessionId&&{targetSessionId:ie.sessionId}}).catch(()=>{})},[N]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:x,style:{...p,outline:q?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Jo,{conversations:B,activeTabId:K,groupIndex:f,numGroups:h,unreadTabKeys:ee,draggingTabRef:T,onFocus:x,onSelectTab:S,onConversationActivated:xe,onPreviewReorder:$,onReorderTab:W,onCommitPreviewOrder:z,onClearPreviewOrder:E,onDragStateReset:re,onDragTabKeyChange:O,onMoveTab:u,onReceiveTab:b,onHideTab:M,isGroupActive:k??!1}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:J,onDragOver:Z,onDragLeave:D,onDrop:G,children:[q&&e.jsx(qo,{dropAction:ce,canSplit:!!(h<4&&u)}),L?e.jsx(Bs,{activeConv:L,clearToken:n[L.tabKey]||0,isCliTerminal:!!H,ideEntry:C,terminalRef:P,handleModalButton:A.handleModalButton,handleRelaunch:A.handleRelaunch,handleSendChat:A.handleSendChat,isSendingChat:A.isSendingChat,handleFocusAgent:A.handleFocusAgent,isFocusingAgent:A.isFocusingAgent,actionLogs:X,userName:l}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(Ks,{conversationsCount:t.length,isSplitMode:m,isStandalone:d,detectedIdes:w,handleLaunchIde:v})})]})]})}function Qo({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:x,isStandalone:m,userName:h,focusedGroup:u,setFocusedGroup:b,moveTabToGroup:p,splitTabRelative:w,closeGroup:v,handleResizeStart:y,detectedIdes:j,handleLaunchIde:I,groupActiveTabIds:g,setGroupActiveTabIds:M,groupTabOrders:k,setGroupTabOrders:N,toggleHiddenTab:P}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:i.map((K,L)=>{const B=s&&r.length===n?`${r[L]}%`:void 0;return e.jsxs(Is.Fragment,{children:[s&&L>0&&e.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:T=>y(L-1,T),onDoubleClick:()=>v(L),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(Zo,{style:s?{flexBasis:B??`${100/n}%`,flexGrow:B?0:1,flexShrink:B?0:1}:void 0,conversations:K,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:x,isStandalone:m,userName:h,groupIndex:L,isFocused:s&&u===L,onFocus:()=>b(L),isSplitMode:s,numGroups:n,onMoveTab:(T,S)=>{S==="left"&&L>0?p(T,L-1):S==="right"&&L<n-1?p(T,L+1):S==="split-left"&&n<4?w(T,L,"left"):S==="split-right"&&n<4&&w(T,L,"right")},onReceiveTab:T=>p(T,L),detectedIdes:L===0?j:void 0,handleLaunchIde:L===0?I:void 0,onActiveTabChange:T=>M(S=>(S[L]??null)===(T??null)?S:{...S,[L]:T}),initialActiveTabId:g[L],initialTabOrder:k[L],onTabOrderChange:T=>N(S=>{const W=S[L]||[];return W.length===T.length&&W.every(($,z)=>$===T[z])?S:{...S,[L]:T}}),onHideTab:P})]},L)})})}function wr({doId:t,ideId:s,ideType:n,connState:r,viewMode:i,instanceId:o}){const[c,d]=a.useState(null),[l,f]=a.useState(null),x=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?we.onScreenshot("ide-page",(u,b)=>{if(u!==t)return;const p=new FileReader;p.onload=()=>d(p.result),p.readAsDataURL(b)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&d(null)},[r]),a.useEffect(()=>{var u;return t?((u=we.onStatus)==null?void 0:u.call(we,(b,p)=>{b===t&&p!=null&&p.screenshotUsage&&f(p.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{d(null)},[t,s,x]),a.useEffect(()=>{const h=t?we.get(t):null;if(!(!h||r!=="connected"))return i!=="chat"&&x?h.startScreenshots(x):h.stopScreenshots(x),()=>{h.stopScreenshots(x)}},[i,r,x,t]);const m=a.useCallback(async(h,u)=>{const b=t?we.get(t):null;return!b||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):b.sendInput(h,u,o||x)},[t,r,o,x]);return{connScreenshot:c,screenshotUsage:l,handleRemoteAction:m}}const kr=a.createContext(null);function as(){const t=a.useContext(kr);if(!t)throw new Error("DashboardDockviewContext missing");return t}function Ut(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function ec(t){return`remote:${t}`}function Zt(t){return t.startsWith("remote:")}function is(t,s){return t.find(n=>n.ideId===s&&n.streamSource==="native")??t.find(n=>n.ideId===s)??null}function tc(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 sc(t,s,n){var d;const r=[s];let i;for(const l of r){let f;for(const x of l){const m=t.addPanel({id:x.tabKey,component:"conversation",title:Ut(x),params:{kind:"conversation",tabKey:x.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 yn(t,s){const n=new Set(s.map(r=>r.tabKey));for(const r of[...t.panels])Zt(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!==Ut(r)&&i.api.setTitle(Ut(r));continue}t.addPanel({id:r.tabKey,component:"conversation",title:Ut(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 vn(t,s,n){var l,f;const r=n?ec(n):null;for(const x of[...t.panels])Zt(x.id)&&(!r||x.id!==r)&&t.removePanel(x);if(!n||!r)return;const i=is(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(x=>!Zt(x.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 nc({params:t}){const s=as(),n=a.useRef(null),r=s.conversationsByTabKey.get(t.tabKey),i=rs({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(Ks,{conversationsCount:0,isSplitMode:!1,isStandalone:s.isStandalone,detectedIdes:s.detectedIdes,handleLaunchIde:s.handleLaunchIde})});const d=!je(r)&&pt(r)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(Bs,{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 rc({params:t}){var l;const s=as(),n=a.useMemo(()=>is([...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}=wr({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(Un,{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 ac(){const t=as();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(Ks,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function ic(t){var m,h;tc(t);const s=as();if(t.params.kind==="remote"){const u=is([...s.conversationsByTabKey.values()],t.params.ideId),b=((m=t.api.group.activePanel)==null?void 0:m.id)===t.api.id,p=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${b?" is-active":""}${p?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(u==null?void 0:u.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:u!=null&&u.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:u.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=St(n,s.liveSessionInboxState,{isOpenConversation:r}),c=o.isReconnecting,d=o.isConnecting,l=o.isGenerating,f=o.isWaiting,x=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:[x&&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 oc({visibleConversations:t,clearedTabs:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,detectedIdes:f,handleLaunchIde:x,toggleHiddenTab:m,onActiveTabChange:h,requestedActiveTabKey:u,requestedRemoteIdeId:b,onRequestedActiveTabConsumed:p}){const{theme:w}=cr(),{sendCommand:v}=st(),y=a.useRef(null),j=a.useRef(null),I=a.useRef(!1),[g,M]=a.useState(!1),[k,N]=a.useState(!1),P=a.useRef(null),K=a.useMemo(()=>hr(typeof window<"u"?window.innerWidth:1280),[]),L=a.useMemo(()=>new Map(t.map(A=>[A.tabKey,A])),[t]),B=a.useMemo(()=>It(n),[n]),T=a.useMemo(()=>({actionLogs:r,clearedTabs:s,conversationsByTabKey:L,detectedIdes:f,handleLaunchIde:x,ides:n,isStandalone:d,liveSessionInboxState:B,sendDaemonCommand:i,setActionLogs:c,setLocalUserMessages:o,toggleHiddenTab:m,userName:l}),[r,s,L,f,x,n,d,B,i,c,o,m,l]),S=a.useCallback(A=>{if(!A)return!1;const q=y.current;if(!q)return!1;const ce=q.getPanel(A);return ce?(ce.group.model.openPanel(ce),p==null||p(),!0):!1},[p]),W=a.useCallback(()=>{const A=j.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 ce of q)ce.setAttribute("data-adhdev-force-hidden","true")},[]),$=a.useCallback(()=>{const A=j.current;if(!A)return;const q=A.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const ce of q)ce.removeAttribute("data-adhdev-force-hidden")},[]),z=a.useCallback(()=>{const A=j.current;if(!A)return;const q=A.querySelectorAll(".dv-drop-target-container");for(const J of q)J.remove();const ce=A.querySelectorAll(".dv-drop-target-dropzone");for(const J of ce)J.remove();const re=A.querySelectorAll(".dv-drop-target");for(const J of re)J.classList.remove("dv-drop-target")},[]),E=a.useCallback(()=>{M(!1),N(!1),$(),W(),z(),!(typeof window>"u")&&(P.current!=null&&window.clearTimeout(P.current),window.requestAnimationFrame(()=>{W(),z()}),P.current=window.setTimeout(()=>{W(),z(),P.current=null},80))},[$,W,z]),_=a.useCallback(A=>{var ce;y.current=A.api;const q=So(K);q!=null&&q.layout&&A.api.fromJSON(q.layout,{reuseExistingPanels:!1}),yn(A.api,t),vn(A.api,t,b),A.api.totalPanels===0&&t.length>0?sc(A.api,t,u):S(u)||S(q==null?void 0:q.activeTabId),I.current=!0,A.api.onDidActivePanelChange(re=>{var Z;if(re&&Zt(re.id)){const D=((Z=re.params)==null?void 0:Z.ideId)||re.id.slice(7),G=is(t,D);h((G==null?void 0:G.tabKey)??null);return}if(h((re==null?void 0:re.id)??null),!re)return;const J=L.get(re.id);(J==null?void 0:J.streamSource)==="agent-stream"&&J.agentType&&v(J.ideId,"focus_session",{agentType:J.agentType,...J.sessionId&&{targetSessionId:J.sessionId}}).catch(()=>{})}),A.api.onDidLayoutChange(()=>{var re;Co(K,{activeTabId:((re=A.api.activePanel)==null?void 0:re.id)??null,layout:A.api.toJSON()})}),A.api.onWillDragPanel(()=>{M(!0),N(!1),W()}),A.api.onWillDragGroup(()=>{M(!0),N(!1),W()}),A.api.onWillShowOverlay(()=>{$(),N(!0)}),A.api.onDidMovePanel(E),A.api.onDidDrop(E),h(((ce=A.api.activePanel)==null?void 0:ce.id)??null)},[S,E,$,L,K,W,z,h,u,v,t]);a.useEffect(()=>{const A=y.current;!A||!I.current||(yn(A,t),vn(A,t,b),!A.activePanel&&A.panels[0]&&A.panels[0].group.model.openPanel(A.panels[0]))},[b,t]),a.useEffect(()=>{I.current&&S(u)},[S,u]),a.useEffect(()=>{if(!g||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,g]),a.useEffect(()=>()=>{typeof window>"u"||P.current!=null&&window.clearTimeout(P.current)},[]),a.useEffect(()=>{const A=q=>{const ce=q.target;if(!ce)return;const re=ce.querySelector("[data-tab-key]")||ce.closest("[data-tab-key]");if(re){const J=re.getAttribute("data-tab-key");J&&q.dataTransfer&&q.dataTransfer.setData("text/tab-key",J)}};return window.addEventListener("dragstart",A),()=>window.removeEventListener("dragstart",A)},[]);const O=w==="light"?ra:aa;return e.jsx(kr.Provider,{value:T,children:e.jsx("div",{ref:j,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(na,{className:`h-full min-h-0 min-w-0 adhdev-dockview${g?" is-dragging-dockview":""}${k?" is-showing-dockview-overlay":""}`,components:{conversation:nc,remote:rc},defaultTabComponent:ic,watermarkComponent:ac,onReady:_,singleTabMode:"default",tabAnimation:"smooth",theme:O})})})}function cc({showMobileChatMode:t,isMobile:s,activeConv:n,chatIdes:r,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:d,onStopCli:l,activeCliViewMode:f,onSetActiveCliViewMode:x,mobileChatConversations:m,hiddenConversations:h,ides:u,actionLogs:b,sendDaemonCommand:p,setLocalUserMessages:w,setActionLogs:v,isStandalone:y,userName:j,requestedMobileTabKey:I,onRequestedMobileTabConsumed:g,requestedMachineId:M,onRequestedMachineConsumed:k,requestedMobileSection:N,onRequestedMobileSectionConsumed:P,containerRef:K,isSplitMode:L,numGroups:B,groupSizes:T,groupedConvs:S,clearedTabs:W,focusedGroup:$,setFocusedGroup:z,moveTabToGroup:E,splitTabRelative:_,closeGroup:O,handleResizeStart:A,detectedIdes:q,handleLaunchIde:ce,groupActiveTabIds:re,setGroupActiveTabIds:J,groupTabOrders:Z,setGroupTabOrders:D,toggleHiddenTab:G,visibleConversations:H,requestedDesktopTabKey:C,onRequestedDesktopTabConsumed:X,onOpenAccount:Y,onDesktopActiveTabChange:ee,onHideConversation:xe,onShowHiddenConversation:ie,onShowAllHiddenConversations:me}){return Is.useEffect(()=>{const Q=R=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?R.metaKey&&R.key.toLowerCase()==="w":R.ctrlKey&&R.key.toLowerCase()==="w")&&(R.preventDefault(),n&&xe&&xe(n))};return window.addEventListener("keydown",Q),()=>window.removeEventListener("keydown",Q)},[n,xe]),e.jsxs(e.Fragment,{children:[!t&&e.jsx(vi,{activeConv:n,agentCount:r.length,wsStatus:i,isConnected:o,conversations:H,hiddenConversations:h,onOpenHistory:c,onOpenConversation:ie,onHideConversation:xe,onShowConversation:ie,onShowAllHidden:me,onOpenRemote:()=>{!n||Ne(n)||je(n)||d(n)},onStopCli:l,activeCliViewMode:f,onSetCliViewMode:x}),t?e.jsx(Uo,{conversations:m,hiddenConversations:h,ides:u,actionLogs:b,sendDaemonCommand:p,setLocalUserMessages:w,setActionLogs:v,isStandalone:y,userName:j,requestedActiveTabKey:I,onRequestedActiveTabConsumed:g,requestedMachineId:M,onRequestedMachineConsumed:k,requestedMobileSection:N,onRequestedMobileSectionConsumed:P,onOpenAccount:Y,onOpenHistory:c,onOpenRemote:d,onStopCli:l,wsStatus:i,isConnected:o,onShowHiddenConversation:ie,onShowAllHiddenConversations:me}):s?e.jsx(Qo,{containerRef:K,isSplitMode:L,numGroups:B,groupSizes:T,groupedConvs:S,clearedTabs:W,ides:u,actionLogs:b,sendDaemonCommand:p,setLocalUserMessages:w,setActionLogs:v,isStandalone:y,userName:j,focusedGroup:$,setFocusedGroup:z,moveTabToGroup:E,splitTabRelative:_,closeGroup:O,handleResizeStart:A,detectedIdes:q,handleLaunchIde:ce,groupActiveTabIds:re,setGroupActiveTabIds:J,groupTabOrders:Z,setGroupTabOrders:D,toggleHiddenTab:G}):e.jsx(oc,{visibleConversations:H,clearedTabs:W,ides:u,actionLogs:b,sendDaemonCommand:p,setLocalUserMessages:w,setActionLogs:v,isStandalone:y,userName:j,detectedIdes:q,handleLaunchIde:ce,toggleHiddenTab:G,onActiveTabChange:ee,requestedActiveTabKey:C,onRequestedActiveTabConsumed:X})]})}const gs=[{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 lc({onClose:t}){const[s,n]=a.useState(0),r=gs[s],i=s===gs.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:gs.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:`
|
|
47
|
+
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:K,onCancel:()=>x(null)})]})}const so=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function no(){const{preference:t,setPreference:s}=lr();return e.jsx("div",{className:"flex gap-2",children:so.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 Ss={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},Cs={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},ro=[{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"}}}],dr="adhdev-chat-theme",ur="adhdev-chat-theme-custom";function zt(){return typeof window>"u"?"ember":localStorage.getItem(dr)||"ember"}function Oe(t){try{const s=localStorage.getItem(ur);if(s){const n=JSON.parse(s);return{...t==="dark"?Ss:Cs,...n[t]}}}catch{}return t==="dark"?Ss:Cs}function Dt(t,s){localStorage.setItem(ur,JSON.stringify({dark:t,light:s}))}function Be(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 Xt(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 ao={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function jt(t,s){var i;const n=(i=ao[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",Xt(n,24)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${Xt(n,18)})`),r.style.setProperty("--border-accent",Be(n,.35)),r.style.setProperty("--nav-active-bg",Be(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Be(n,.06)}`)}function at(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Be(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Be(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Be(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",Be(t.borderSubtle,.5)),s.style.setProperty("--border-default",Be(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",Xt(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${Xt(t.accentColor,40)})`),s.style.setProperty("--border-accent",Be(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Be(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Be(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 ${Be(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 Ps(){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 io(t){if(localStorage.setItem(dr,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=it()?"dark":"light";at(Oe(s))}else Ps(),jt(t,it()?"dark":"light")}function oo(){const t=zt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=it()?"dark":"light";at(Oe(s))}else Ps(),jt(t,it()?"dark":"light")}function it(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Ae({label:t,value:s,onChange:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("input",{type:"color",value:s,onChange:r=>n(r.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:r=>{/^#[0-9a-fA-F]{0,6}$/.test(r.target.value)&&n(r.target.value)},style:{width:72,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function ht({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 co({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,i]=a.useState(()=>Oe(n));a.useEffect(()=>{i(Oe(n))},[n]);const o=a.useCallback((c,d)=>{i(l=>{const f={...l,[c]:d},m=Oe(n==="dark"?"light":"dark");return n==="dark"?Dt(f,m):Dt(m,f),at(f),s(f),f})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 18px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{children:[e.jsxs(ht,{title:"App Background",children:[e.jsx(Ae,{label:"Background",value:r.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(Ae,{label:"Surface",value:r.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(Ae,{label:"Card",value:r.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(ht,{title:"App Text",children:[e.jsx(Ae,{label:"Primary",value:r.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(Ae,{label:"Secondary",value:r.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(Ae,{label:"Muted",value:r.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(ht,{title:"Borders & Accent",children:[e.jsx(Ae,{label:"Border subtle",value:r.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(Ae,{label:"Border default",value:r.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(Ae,{label:"Accent",value:r.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(ht,{title:"Chat Bubbles",children:[e.jsx(Ae,{label:"User bubble",value:r.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(Ae,{label:"User text",value:r.userText,onChange:c=>o("userText",c)}),e.jsx(Ae,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(Ae,{label:"Agent text",value:r.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(ht,{title:"Chat Layout",children:[e.jsx(Ae,{label:"Chat BG",value:r.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(Ae,{label:"Send button",value:r.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(Ae,{label:"Input border",value:r.inputBorder,onChange:c=>o("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:r.bubbleRadius,onChange:c=>o("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?Ss:Cs,l=Oe(t?"light":"dark");t?Dt(c,l):Dt(l,c),i(c),at(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 lo(){const[t,s]=a.useState(zt),[n,r]=a.useState(!0),[i,o]=a.useState(()=>Oe("dark"));a.useEffect(()=>{r(it());const l=new MutationObserver(()=>{const m=it();r(m);const h=zt();h==="custom"?at(Oe(m?"dark":"light")):jt(h,m?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const f=window.matchMedia("(prefers-color-scheme: dark)"),x=()=>{const m=it();r(m);const h=zt();h==="custom"?at(Oe(m?"dark":"light")):jt(h,m?"dark":"light")};return f.addEventListener("change",x),()=>{l.disconnect(),f.removeEventListener("change",x)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?at(Oe(n?"dark":"light")):(Ps(),jt(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{o(Oe(n?"dark":"light"))},[n]);const c=l=>{s(l),io(l)},d=[...ro,{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,x=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:x.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:x.assistantBubble,border:x.assistantBorder,color:x.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:x.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:x.assistantBubble,border:x.assistantBorder,color:x.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(co,{dark:n,onColorsChange:l=>o(l)})]})}const xr="adhdev_mobileDashboardMode_v1";function pr(){try{return localStorage.getItem(xr)==="workspace"?"workspace":"chat"}catch{return"chat"}}function uo(t){try{localStorage.setItem(xr,t)}catch{}}function xo(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(pr()==="chat")},[]),e.jsx(Je,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ze,{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),uo(n?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}const mr="adhdev_hiddenTabs";function po(){try{const t=localStorage.getItem(mr);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function ct(t){try{localStorage.setItem(mr,JSON.stringify([...t]))}catch{}}function mo(){const[t,s]=a.useState(po),n=a.useCallback(f=>{s(x=>{const m=new Set(x);return m.has(f)?m.delete(f):m.add(f),ct(m),m})},[]),r=a.useCallback(f=>{s(x=>{if(x.has(f))return x;const m=new Set(x);return m.add(f),ct(m),m})},[]),i=a.useCallback(f=>{s(x=>{if(!x.has(f))return x;const m=new Set(x);return m.delete(f),ct(m),m})},[]),o=a.useCallback(()=>{s(f=>{if(f.size===0)return f;const x=new Set;return ct(x),x})},[]),c=a.useCallback((f,x)=>{s(m=>{const h=new Set(m);for(const u of x)h.add(u);return ct(h),h})},[]),d=a.useCallback((f,x)=>{s(m=>{const h=new Set(m);for(const u of x)h.delete(u);return ct(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 fo({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){a.useEffect(()=>{Ki()},[]);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 Oi(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{n(d=>{const l=Date.now(),f={};for(const[x,m]of Object.entries(d))l-m<5e3&&(f[x]=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 ps(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 ns(t){const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1];return ps(s==null?void 0:s.timestamp)||ps(s==null?void 0:s.receivedAt)||ps(s==null?void 0:s.createdAt)||0}function ms(t,s=0){return ns(t)||s||0}function xn(t){return ns(t)}function fr(t,s){const n=xn(s)-xn(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 ho(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 Et(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 go(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 bo(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 yo(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 vo({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 I=ho(t);return Et(o.current,I)?o.current:(o.current=I,I)},[t]),x=a.useMemo(()=>sr(t),[t]),m=a.useRef(new Map),h=a.useMemo(()=>{var M;const I=new Map,g=[];for(const k of f){const N=k.daemonId||((M=k.id)==null?void 0:M.split(":")[0])||k.id,P=s[N]||"new",K=k.daemonId&&x[k.daemonId]||void 0,L=bo(k,n),B=m.current.get(k.id);if(B&&B.ide===k&&B.connectionState===P&&B.machineName===K&&yo(B.localRefs,L)){I.set(k.id,B),g.push(...B.conversations);continue}const T=nr(k,n,{machineName:K,connectionState:P}),S={ide:k,connectionState:P,machineName:K,localRefs:L,conversations:T};I.set(k.id,S),g.push(...T)}return m.current=I,[...g].sort(fr)},[f,n,s,x]),u=a.useMemo(()=>{const I=go(h,r);return Et(c.current,I)?c.current:(c.current=I,I)},[h,r]),b=a.useMemo(()=>{const I=new Map;for(const g of u)g.sessionId&&I.set(g.sessionId,g);return I},[u]),p=a.useMemo(()=>{const I=new Map;for(const g of u)g.sessionId&&I.set(g.sessionId,g),I.set(g.ideId,g),I.set(g.tabKey,g);return I},[u]),w=a.useCallback(I=>{if(I)return b.get(I)},[b]),v=a.useCallback(I=>{if(I)return p.get(I)},[p]),y=a.useMemo(()=>{const I=u.filter(g=>!i.has(g.tabKey));return Et(d.current,I)?d.current:(d.current=I,I)},[u,i]),j=a.useMemo(()=>{const I=y.map(g=>g.tabKey);return Et(l.current,I)?l.current:(l.current=I,I)},[y]);return{chatIdes:f,conversations:u,visibleConversations:y,visibleTabKeys:j,resolveConversationBySessionId:w,resolveConversationByTarget:v}}function jo({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 wo({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:i}){a.useEffect(()=>{Xe.setIdes(t)},[t]),a.useEffect(()=>{Xe.setResolveAction((o,c,d)=>{s(o,c,d).catch(()=>{})})},[s]),a.useEffect(()=>{const o=Xe.onToast(l=>{n(x=>x.some(h=>h.message===l.message&&l.timestamp-h.timestamp<3e3)?x:[...x.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(x=>x.filter(m=>m.id!==l.id)),f)}),c=Xe.onSystemMessage((l,f)=>{var m;const x=i(l);(x==null?void 0:x.transport)==="pty"&&((m=f._localId)!=null&&m.startsWith("sys_approval_"))||r(h=>({...h,[l]:[...h[l]||[],f]}))}),d=Xe.onClearSystemMessage((l,f)=>{r(x=>{var m;return(m=x[l])!=null&&m.length?{...x,[l]:x[l].filter(h=>{var u;return!(h.role==="system"&&((u=h._localId)!=null&&u.startsWith(f)))})}:x})});return()=>{o(),c(),d()}},[n,r]),a.useEffect(()=>{const o=Qn.on("status_event",c=>Xe.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,x=i(f),m=(x==null?void 0:x.ideId)||l.ideId;m&&s(m,"resolve_action",{action:"approve",button:"Approve",...(x==null?void 0:x.sessionId)&&{targetSessionId:x.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 ko="adhdev_dashboardLayout_v1",No="adhdev_dashboardDockview_v1",gt={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function hr(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function gr(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function br(t){return`${ko}:${t}`}function So(t){const s=br(t);return hr(s,null)}function Co(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=br(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function yr(t){return`${No}:${t}`}function Io(t){const s=yr(t);return hr(s,null)}function Mo(t,s){try{const n=yr(t);if(!s){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function To(){return{groupAssignments:[...gt.groupAssignments],focusedGroup:gt.focusedGroup,groupActiveTabIds:{...gt.groupActiveTabIds},groupTabOrders:{...gt.groupTabOrders},groupSizes:[...gt.groupSizes]}}function Ao(){const[t]=a.useState(()=>gr(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,x]=a.useState([]),[m,h]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[u,b]=a.useState(!1),p=a.useCallback(()=>{if(u)return;const w=So(t)??To();n(new Map(w.groupAssignments)),i(w.focusedGroup),c(w.groupActiveTabIds),l(w.groupTabOrders),x(w.groupSizes),b(!0)},[u,t]);return a.useEffect(()=>{u&&Co(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:o,groupTabOrders:d,groupSizes:f})},[u,t,s,r,o,d,f]),a.useEffect(()=>{const w=window.matchMedia("(max-width: 767px)"),v=y=>h(y.matches);return w.addEventListener("change",v),()=>w.removeEventListener("change",v)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:d,setGroupTabOrders:l,groupSizes:f,setGroupSizes:x,isMobile:m,hasHydratedStoredLayout:u,hydrateStoredLayout:p}}function Ro({urlActiveTab:t,conversations:s,resolveConversationBySessionId:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:d,setSearchParams:l,historyModalOpen:f,activeConv:x,isRefreshingHistory:m,ides:h,handleRefreshHistory:u}){const b=a.useRef(!1),p=a.useRef(!1),w=a.useRef(null),v=a.useRef(!1);a.useEffect(()=>{if(!t||b.current||s.length===0)return;if(!i){o();return}const y=n(t);if(!y)return;const j=r.get(y.tabKey)??0;c(I=>({...I,[j]:y.tabKey})),d(j),b.current=!0,p.current=!0,w.current!=null&&(window.clearTimeout(w.current),w.current=null),l(I=>{const g=new URLSearchParams(I);return g.delete("activeTab"),g},{replace:!0})},[t,s,n,r,i,o,c,d,l]),a.useEffect(()=>{if(!(p.current||i)&&s.length!==0){if(!t){o(),p.current=!0;return}if(b.current){p.current=!0;return}if(w.current==null)return w.current=window.setTimeout(()=>{w.current=null,!(p.current||i)&&(o(),p.current=!0)},1500),()=>{w.current!=null&&(window.clearTimeout(w.current),w.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!f){v.current=!1;return}if(!x||v.current||m)return;const y=h.find(j=>j.id===x.ideId);y&&(!y.chats||y.chats.length===0)&&(v.current=!0,u())},[f,x,m,h,u]),a.useEffect(()=>{if(!x)return;let y=null,j=0,I=-1,g=0;const M=()=>{y=null;const k=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(P=>P.offsetParent!==null);if(k.length===0){j<18&&(j+=1,y=requestAnimationFrame(M));return}let N=0;for(const P of k)P.scrollTop=P.scrollHeight,N+=P.scrollHeight;N===I?g+=1:(g=0,I=N),j+=1,!(g>=2||j>=18)&&(y=requestAnimationFrame(M))};return y=requestAnimationFrame(M),()=>{y!=null&&cancelAnimationFrame(y)}},[x==null?void 0:x.tabKey])}function _o({isMobile:t,location:s,navigate:n,requestedRemoteTabTarget:r,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:d}){const[l,f]=a.useState(null),[x,m]=a.useState(null),h=a.useMemo(()=>{if(t||!r)return null;const v=d(r);return v&&!Se(v)&&!je(v)?v:null},[t,r,d]),u=a.useMemo(()=>{const v=l==null?void 0:l.ideId;if(!v)return null;const y=l!=null&&l.tabKey?o.find(j=>j.tabKey===l.tabKey):i?o.find(j=>j.tabKey===i):null;return(y==null?void 0:y.ideId)===v?y:o.find(j=>j.ideId===v&&j.streamSource==="native")||o.find(j=>j.ideId===v)||null},[o,l,i]),b=a.useMemo(()=>{if(u)return c.find(v=>v.id===u.ideId)},[c,u]);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 p=a.useCallback(v=>{v&&(f({ideId:v.ideId,tabKey:v.streamSource==="native"?"native":v.tabKey}),m(v))},[]),w=a.useCallback(()=>{f(null),m(null)},[]);return{remoteDialogConv:u,remoteDialogIdeEntry:b,remoteDialogActiveConv:x,setRemoteDialogActiveConv:m,openRemoteDialog:p,closeRemoteDialog:w}}function wt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Se(t)||je(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function Jt(t){return t&&(t.ideId||t.daemonId)||""}function $t(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function pn({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:i,setClearedTabs:o}){const[c,d]=a.useState(!1),[l,f]=a.useState(!1),x=a.useCallback(async b=>{try{await t("standalone","launch_ide",{ideType:b,enableCdp:!0})}catch(p){console.error("Launch failed",p)}},[t]),m=a.useCallback(async(b,p)=>{try{const w=b||(s==null?void 0:s.daemonId)||"",v=await t(w,"switch_chat",{id:p,sessionId:p,...wt(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"?$t(r,"⚠️ Session tab not found — try refreshing history"):typeof y=="string"&&y.startsWith("error:")?$t(r,`⚠️ Switch error: ${y}`):$t(r,"⚠️ Session switch failed")}catch(w){console.error("Switch failed",w),$t(r,`❌ Switch failed: ${w.message||"connection error"}`)}},[s,t,r]),h=a.useCallback(async()=>{if(!(!s||c)){d(!0);try{const b=Jt(s);await t(b,"new_chat",{...wt(s)}),o(p=>({...p,[s.tabKey]:Date.now()})),i(p=>({...p,[s.tabKey]:[]}))}catch(b){console.error("New chat failed",b)}finally{d(!1)}}},[s,c,t,o,i]),u=a.useCallback(async()=>{var b;if(!(!s||l)){f(!0);try{const p=Jt(s),w=await t(p,"list_chats",{forceExpand:!0,...wt(s)}),v=(w==null?void 0:w.chats)||((b=w==null?void 0:w.result)==null?void 0:b.chats);w!=null&&w.success&&Array.isArray(v)&&n(s.ideId,v)}catch(p){console.error("Refresh history failed",p)}finally{f(!1)}}},[s,l,t,n]);return{isCreatingChat:c,isRefreshingHistory:l,handleLaunchIde:x,handleSwitchSession:m,handleNewChat:h,handleRefreshHistory:u}}function Lo(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 Do(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function mn(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 Pt(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 fn(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 Eo(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 $o(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 hn(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 gn(t){return Array(t).fill(100/t)}function Po({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:d,visibleConversations:l,visibleTabKeys:f}){const x=a.useRef(null),m=a.useMemo(()=>Pt(t,f),[t,f]),h=m.assignments,u=a.useMemo(()=>d?1:m.groupCount,[m.groupCount,d]),b=u>1,p=a.useCallback((g,M)=>{s(k=>{const N=new Map(Pt(k,f).assignments);return M===0?N.delete(g):N.set(g,M),N}),r(k=>({...k,[M]:g})),n(M)},[s,f,r,n]),w=a.useCallback(g=>{s(M=>{const k=Pt(M,f).assignments,N=new Map;for(const[P,K]of k)K!==g&&(K>g?N.set(P,K-1):N.set(P,K));return N}),c(M=>{if(M.length<=1)return[];const k=[...M];k.splice(g,1);const N=k.reduce((P,K)=>P+K,0);return N>0?k.map(P=>P/N*100):[]}),n(0)},[s,f,c,n]),v=a.useCallback((g,M)=>{M.preventDefault();const k=x.current;if(!k)return;const N=M.clientX,P=k.offsetWidth,K=o.length===u?[...o]:gn(u),L=T=>{const W=(T.clientX-N)/P*100,$=[...K];$[g]=Math.max(15,K[g]+W),$[g+1]=Math.max(15,K[g+1]-W),c($)},B=()=>{document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",B),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",L),document.addEventListener("mouseup",B)},[o,u,c]),y=a.useCallback((g,M,k)=>{if(u>=4)return;const N=k==="left"?M:M+1;s(P=>{const K=Pt(P,f).assignments,L=new Map;for(const B of l){const T=K.get(B.tabKey)??0,S=T>=N?T+1:T;S>0&&L.set(B.tabKey,S)}return N>0&&L.set(g,N),L}),c(P=>{const K=P.length===u?[...P]:gn(u),L=K[M]??100/u,B=Math.max(15,L/2),T=Math.max(15,L/2),S=[...K];S[M]=B,S.splice(N,0,T);const W=S.reduce(($,z)=>$+z,0);return S.map($=>$/W*100)}),r(P=>{const K=hn(P,N);return K[N]=g,K}),i(P=>{const K=hn(P,N);return K[N]=[g],K}),n(N)},[u,s,f,l,c,r,i,n]);a.useEffect(()=>{Lo(t,h)||s(h)},[t,h,s]),a.useEffect(()=>{const{mapping:g,usedGroups:M}=m;r(k=>{const N=fn(k,g);return mn(k,N)?k:N}),i(k=>{const N=fn(k,g);return mn(k,N)?k:N}),n(k=>{const N=d?0:Eo(k,M,g);return k===N?k:N}),c(k=>{const N=d?[]:$o(k,M,m.groupCount);return Do(k,N)?k:N})},[m,d,r,i,n,c]);const j=a.useMemo(()=>{const g=Array.from({length:u},()=>[]);for(const M of l){const k=h.get(M.tabKey)??0,N=Math.min(k,u-1);g[N].push(M)}return g},[l,h,u]),I=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:x,normalizedGroupAssignments:h,numGroups:u,isSplitMode:b,groupedConvs:j,moveTabToGroup:p,closeGroup:w,handleResizeStart:v,splitTabRelative:y,clearAllSplits:I}}function Bo({ides:t,sendDaemonCommand:s}){const n="0.8.1",r=a.useMemo(()=>t.filter(f=>{if(f.type!=="adhdev-daemon")return!1;const x=f.version||f.daemonVersion||null;return!x||!n?!1:x!==n}),[n,t]),[i,o]=a.useState(!1),[c,d]=a.useState({}),l=a.useCallback(async f=>{var x,m;d(h=>({...h,[f]:"upgrading"}));try{const h=await s(f,"daemon_upgrade",{});(x=h==null?void 0:h.result)!=null&&x.upgraded||(m=h==null?void 0:h.result)!=null&&m.success?d(u=>({...u,[f]:"done"})):d(u=>({...u,[f]:"error"}))}catch{d(h=>({...h,[f]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:l}}function rs({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),x=a.useCallback(async b=>{if(!s)return;const p=b.trim();if(!p||f.current)return;const w=s.tabKey;f.current=!0,l(!0);const v=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,y={role:"user",content:p,timestamp:Date.now(),_localId:v};n(j=>({...j,[w]:[...j[w]||[],y]}));try{const j=Jt(s);if(!j)return;await t(j,"send_chat",{message:p,text:p,...wt(s)}),setTimeout(()=>{const I=Date.now()-6e4;n(g=>{const M=g[w];if(!M)return g;const k=M.filter(N=>N.timestamp>I);return k.length===M.length?g:{...g,[w]:k}})},6e4)}catch(j){console.error("Send failed",j),n(I=>({...I,[w]:(I[w]||[]).filter(g=>g._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(b){console.error("Relaunch failed",b)}},[s,t]),h=a.useCallback(async b=>{if(s){s.transport!=="pty"&&r(p=>[...p,{ideId:s.tabKey,text:`🖱️ **${b}** clicked`,timestamp:Date.now()}]);try{const w=(s.modalButtons||[]).indexOf(b),v=b.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),y=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(v),j=Jt(s);if(!j)return;(await t(j,"resolve_action",{button:b,action:y?"approve":"reject",...w>=0&&{buttonIndex:w},...wt(s)})).success||r(g=>[...g,{ideId:s.tabKey,text:`⚠️ **${b}** failed — button not found`,timestamp:Date.now()}])}catch(p){console.error("[ModalButton] Error:",p),r(w=>[...w,{ideId:s.tabKey,text:`❌ **${b}** error`,timestamp:Date.now()}])}}},[s,t,r]),u=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(b){console.error("Focus agent failed",b)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:d,isFocusingAgent:o,handleSendChat:x,handleRelaunch:m,handleModalButton:h,handleFocusAgent:u}}const Bs=a.memo(function({activeConv:s,clearToken:n,isCliTerminal:r,ideEntry:i,terminalRef:o,handleModalButton:c,handleRelaunch:d,handleSendChat:l,isSendingChat:f,handleFocusAgent:x,isFocusingAgent:m,actionLogs:h,userName:u}){return e.jsxs(e.Fragment,{children:[e.jsx(Vn,{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(_s,{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(yi,{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(ws,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:x,isFocusingAgent:m,actionLogs:h,userName:u})})]}):e.jsx(ws,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:x,isFocusingAgent:m,actionLogs:h,userName:u})]})},(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 Ko({selectedConversation:t,isAcp:s,selectedIdeEntry:n,actionLogs:r,userName:i,isSendingChat:o,isFocusingAgent:c,onBack:d,onOpenNativeConversation:l,onOpenMachine:f,onOpenHistory:x,onOpenRemote:m,onHideConversation:h,onStopCli:u,cliViewMode:b,onSetCliViewMode:p,handleSendChat:w,handleFocusAgent:v,handleModalButton:y,handleRelaunch:j}){const I=a.useRef(null),g=Se(t)&&!s,M=g&&b==="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($n,{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 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary",children:e.jsx(Xn,{conversation:t,onOpenNativeConversation:()=>l(t),onOpenMachine:()=>f(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[g&&b&&e.jsx(Es,{mode:b,onChange:p,compact:!0}),g&&u&&e.jsx("button",{onClick:u,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(Vt,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>x(t),type:"button",children:e.jsx(As,{size:14})}),!s&&!g&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>m(t),type:"button",children:e.jsx(De,{size:14})}),h&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(t),type:"button",title:"Close chat",children:e.jsx(Vt,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(Bs,{activeConv:t,clearToken:0,isCliTerminal:M,ideEntry:n,terminalRef:I,handleModalButton:y,handleRelaunch:j,handleSendChat:w,isSendingChat:o,handleFocusAgent:v,isFocusingAgent:c,actionLogs:r,userName:i})})]})}const fs={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 Wo(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function vr(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":n;a.useEffect(()=>{s(Wo())},[]);const d=a.useCallback(()=>{navigator.clipboard.writeText(fs[c].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="powershell"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-accent cursor-pointer group",onClick:d,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:fs[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:fs[c].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-text-muted opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:i?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function jr({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 bt({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 Bt({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}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:Fn(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(De,{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 bn({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 Oo({section:t,attentionItems:s,unreadItems:n,workingItems:r,completedItems:i,hiddenConversations:o,machineCards:c,getAvatarText:d,onOpenConversation:l,onShowConversation:f,onShowAllHidden:x,onOpenMachine:m,onOpenSettings:h,onOpenAccount:u,onSectionChange:b,wsStatus:p="connected",isStandalone:w=!1}){const v=p==="disconnected"||p==="reconnecting"||p==="offline"||p==="auth_failed",y=c.length>0,j=s.length>0||n.length>0||r.length>0||i.length>0,I=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:I}),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(ts,{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(es,{size:18})}),u&&e.jsx("button",{onClick:u,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(Pn,{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(bt,{icon:e.jsx(bn,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:p==="offline"?"Your device appears to be offline. Waiting for network…":p==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(bt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:w?"Waiting for your IDE":"Connect your first machine",subtitle:w?"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:!w&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(vr,{})})}):c.map(g=>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(g.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(g.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:g.label}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:g.unread>0?e.jsxs("span",{className:"text-accent-primary",children:[g.unread," new"]}):g.total>0?`${g.total} chats`:"Idle"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:g.subtitle}),g.total>0?e.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[g.total," chat",g.total!==1?"s":"",g.unread>0?` · ${g.unread} unread`:""]}):e.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},g.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(g=>e.jsx(Bt,{item:g,type:"needs_attention",getAvatarText:d,onOpenConversation:l},g.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(g=>e.jsx(Bt,{item:g,type:"task_complete",getAvatarText:d,onOpenConversation:l},g.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(g=>e.jsx(Bt,{item:g,type:"working",getAvatarText:d,onOpenConversation:l},g.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(g=>e.jsx(Bt,{item:g,type:"earlier",getAvatarText:d,onOpenConversation:l},g.conversation.tabKey)):j?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):v?e.jsx(bt,{icon:e.jsx(bn,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):y?e.jsx(bt,{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(Ze,{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(bt,{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:x,children:"Restore all"})]}),o.map(g=>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(g),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(g.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:g.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:[g.displaySecondary,g.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(De,{size:11})," ",g.machineName]})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:"Tap to restore and open"})]})]},g.tabKey))]})]}),e.jsx(jr,{section:t,onSectionChange:b})]})}function zo({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:n,cliProviders:r,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:d,section:l,showBottomNav:f,onBack:x,onSectionChange:m,onOpenConversation:h,onOpenRecent:u,onOpenMachineDetails:b,onMachineUpgrade:p,onLaunchDetectedIde:w,onAddWorkspace:v,onLaunchWorkspaceProvider:y}){var ne,Z,Q;const j=(E,G,H)=>E?"ide":G>0?"cli":H>0?"acp":null,[I,g]=a.useState(!1),M=E=>E==="ide"?"IDE":E==="cli"?"CLI":"ACP",k=n.slice(0,4),N=s.slice(0,3),P=a.useMemo(()=>{const E=k.map(H=>({key:`recent-launch:${H.id}`,type:"session",primary:H.label,secondary:`${M(H.kind)}${H.subtitle?` · ${H.subtitle}`:""}`,unread:!1,onClick:()=>u(H)})),G=N.map(H=>({key:`recent-chat:${H.conversation.tabKey}`,type:"conversation",primary:H.conversation.displayPrimary,secondary:`Chat${H.conversation.displaySecondary?` · ${H.conversation.displaySecondary}`:""}${H.timestamp?` · ${Fn(H.timestamp)}`:""}`,unread:H.unread,onClick:()=>h(H.conversation)}));return[...E,...G]},[h,u,N,k]),K=I?P:P.slice(0,5),L=P.length>0,B=(((ne=t.detectedIdes)==null?void 0:ne.length)||0)>0,T=a.useMemo(()=>t.workspaces||[],[t]),S=t.defaultWorkspaceId||null,[W,$]=a.useState(S||((Z=T[0])==null?void 0:Z.id)||""),[z,D]=a.useState(""),[_,O]=a.useState(j(B,r.length,i.length)),A=a.useRef(null),q=W==="__custom__"?z.trim():((Q=T.find(E=>E.id===W))==null?void 0:Q.path)||"",ce=W==="__custom__"&&!!q&&d.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(d.message);return a.useEffect(()=>{var E;A.current!==t.id&&(A.current=t.id,$(S||((E=T[0])==null?void 0:E.id)||"__custom__"),D(""),O(j(B,r.length,i.length)))},[i.length,r.length,S,B,t.id,T]),a.useEffect(()=>{var E;W!=="__custom__"&&(W&&T.some(G=>G.id===W)||$(S||((E=T[0])==null?void 0:E.id)||"__custom__"))},[S,W,T]),a.useEffect(()=>{_==="ide"&&B||_==="cli"&&r.length>0||_==="acp"&&i.length>0||O(j(B,r.length,i.length))},[_,i.length,r.length,B]),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:x,type:"button","aria-label":"Back",children:e.jsx($n,{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:He(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:[L&&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:K.map(E=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${E.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:E.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:E.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:E.secondary})]},E.key))}),P.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:()=>g(E=>!E),children:I?"Show fewer":`Show ${P.length-5} more`})})]}),(B||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 enter a path before choosing IDE, CLI, or ACP."}),e.jsx("select",{value:W,onChange:E=>{$(E.target.value),E.target.value!=="__custom__"&&D("")},className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:T.length>0?e.jsxs(e.Fragment,{children:[T.map(E=>e.jsxs("option",{value:E.id,children:[E.id===S?"⭐ ":"",E.label||E.path.split("/").filter(Boolean).pop()||E.path]},E.id)),e.jsx("option",{value:"__custom__",children:"Custom path…"})]}):e.jsx("option",{value:"__custom__",children:"Enter workspace path…"})}),W==="__custom__"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",value:z,onChange:E=>D(E.target.value),placeholder:"/absolute/path",className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm"}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[40px] rounded-xl border border-accent-primary/30 bg-accent-primary/10 text-text-primary text-[13px] font-bold",onClick:()=>{q&&v(q)},children:"Save workspace"})]}),q&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:q})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[B&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${_==="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:()=>O("ide"),children:"IDE"}),r.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${_==="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:()=>O("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${_==="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:()=>O("acp"),children:"ACP"})]}),_&&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:_==="ide"?"Choose an IDE":_==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:_==="ide"?(t.detectedIdes||[]).slice(0,6).map(E=>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:()=>w(E.type,{workspacePath:q||null}),children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:E.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:q||"Use selected workspace"})]},E.type)):(_==="cli"?r:i).map(E=>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:()=>y(_,E.type,{workspaceId:W!=="__custom__"?W:null,workspacePath:q||null}),children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[E.icon?`${E.icon} `:"",E.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:q||"Use selected workspace"})]},E.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,ce&&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(q,{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:p,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:b,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"})]})]})]})]}),f&&e.jsx(jr,{section:l,onSectionChange:m})]})}function Uo(t){return tr(t)}function yn(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1],n=Uo(s==null?void 0:s.content);return n||(t.title?t.title:t.displaySecondary||"No messages yet")}function Ho(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Kt(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function Fo({conversations:t,hiddenConversations:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,requestedActiveTabKey:f,onRequestedActiveTabConsumed:x,requestedMachineId:m,onRequestedMachineConsumed:h,requestedMobileSection:u,onRequestedMobileSectionConsumed:b,onOpenAccount:p,onOpenHistory:w,onOpenRemote:v,onStopCli:y,wsStatus:j,isConnected:I,onShowHiddenConversation:g,onShowAllHiddenConversations:M,onHideConversation:k}){const[N,P]=a.useState(()=>{var U;return((U=t[0])==null?void 0:U.tabKey)||null}),[K,L]=a.useState(()=>t[0]?"chat":"inbox"),[B,T]=a.useState("chats"),[S,W]=a.useState(null),[$,z]=a.useState("inbox"),[D,_]=a.useState("idle"),[O,A]=a.useState(""),q=a.useRef(null),ce=pt(),ne="0.8.1",Z=a.useMemo(()=>t.find(U=>U.tabKey===N)||t[0]||null,[t,N]),Q=a.useMemo(()=>Z?n.find(U=>U.id===Z.ideId):void 0,[n,Z]),E=a.useMemo(()=>!Z||je(Z)||!Se(Z)?null:xt(Z),[Z]),G=a.useMemo(()=>n.filter(U=>U.type==="adhdev-daemon"||U.daemonMode).sort(pi),[n]),H=a.useMemo(()=>G.find(U=>U.id===S)||null,[G,S]),C=a.useMemo(()=>It(n),[n]),X=rs({sendDaemonCommand:i,activeConv:Z||void 0,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),Y=a.useCallback(U=>{if(!U||!U.sessionId)return;const V=dt(U,C),se=Math.max(Date.now(),ns(U),V.lastUpdated||0);Kt("mark_read:start",{tabKey:U.tabKey,sessionId:U.sessionId,displayPrimary:U.displayPrimary,inboxBucket:V.inboxBucket,unread:V.unread,lastSeenAt:V.lastSeenAt,lastUpdated:V.lastUpdated,activityAt:ms(U,V.lastUpdated),readAt:se}),i(U.daemonId||U.ideId,"mark_session_seen",{sessionId:U.sessionId,seenAt:se}).then(oe=>{Kt("mark_read:result",{tabKey:U.tabKey,sessionId:U.sessionId,result:oe})}).catch(oe=>{Kt("mark_read:error",{tabKey:U.tabKey,sessionId:U.sessionId,error:oe instanceof Error?oe.message:String(oe)})})},[C,i]);a.useEffect(()=>{var V;if(!Z){L("inbox"),P(((V=t[0])==null?void 0:V.tabKey)||null),q.current=null;return}if(K!=="chat"){q.current=null;return}const U=`${Z.tabKey}:${Z.sessionId||""}`;q.current!==U&&(q.current=U,Y(Z))},[t,Y,K,Z]),a.useEffect(()=>{if(!f)return;const U=t.find(V=>V.tabKey===f);U&&(P(U.tabKey),L("chat"),x==null||x())},[t,x,f]),a.useEffect(()=>{if(!m)return;const U=G.find(V=>V.id===m);U&&(W(U.id),_("idle"),A(""),T("machines"),z("inbox"),L("machine"),h==null||h())},[G,h,m]),a.useEffect(()=>{u&&(T(u),L("inbox"),b==null||b())},[b,u]);const ee=a.useMemo(()=>t.map(U=>{const V=K==="chat"&&(Z==null?void 0:Z.tabKey)===U.tabKey,se=St(U,C,{hideOpenTaskCompleteUnread:!0,isOpenConversation:V}),oe=dt(U,C),ge=ms(U,(oe==null?void 0:oe.lastUpdated)||0),be=yn(U);return{conversation:U,timestamp:ge,preview:be,unread:se.unread,requiresAction:se.requiresAction,isWorking:se.isWorking,inboxBucket:se.inboxBucket}}).sort((U,V)=>{const se=V.timestamp-U.timestamp;return se!==0?se:fr(U.conversation,V.conversation)}),[t,C,K,Z]);a.useEffect(()=>{const U=ee.filter(V=>V.inboxBucket==="task_complete"||V.unread);U.length!==0&&Kt("inbox_state",{screen:K,selectedTabKey:N,items:U.map(V=>{const se=dt(V.conversation,C);return{liveState:se,tabKey:V.conversation.tabKey,sessionId:V.conversation.sessionId,displayPrimary:V.conversation.displayPrimary,serverBucket:se.inboxBucket,computedBucket:V.inboxBucket,serverUnread:se.unread,computedUnread:V.unread,lastSeenAt:se.lastSeenAt,lastUpdated:se.lastUpdated,activityAt:ms(V.conversation,se.lastUpdated)}})})},[ee,C,K,N]);const ue=a.useMemo(()=>ee.filter(U=>U.requiresAction),[ee]),ae=a.useMemo(()=>ee.filter(U=>U.unread&&!U.requiresAction),[ee]),me=a.useMemo(()=>ee.filter(U=>!U.unread&&!U.requiresAction&&U.isWorking),[ee]),J=a.useMemo(()=>ee.filter(U=>!U.unread&&!U.requiresAction&&!U.isWorking),[ee]),R=a.useMemo(()=>H?ee.filter(U=>U.conversation.daemonId===H.id||U.conversation.ideId===H.id):[],[ee,H]),F=a.useMemo(()=>{if(!H)return[];const U=H.recentLaunches||[];return U.length>0?U.map(V=>({id:V.id,label:V.title||V.providerName||V.providerType,kind:V.kind,providerType:V.providerType,providerSessionId:V.providerSessionId,subtitle:V.currentModel||V.workspace||void 0,workspace:V.workspace,currentModel:V.currentModel})):n.filter(V=>!V.daemonMode&&V.daemonId===H.id).map(V=>{var oe,ge,be,Ne,pe;const se=qt(V)?"cli":yt(V)?"acp":"ide";return{id:`${se}:${V.type}:${V.workspace||""}`,label:((oe=V.activeChat)==null?void 0:oe.title)||(qt(V)?V.cliName||V.type:yt(V)&&V.cliName||V.type),kind:se,providerType:V.type,providerSessionId:V.providerSessionId,subtitle:yt(V)?V.currentModel||V.workspace||void 0:V.workspace||void 0,workspace:V.workspace||void 0,currentModel:V.currentModel,timestamp:((pe=(Ne=(be=(ge=V.activeChat)==null?void 0:ge.messages)==null?void 0:be.at)==null?void 0:Ne.call(be,-1))==null?void 0:pe.timestamp)||0}}).sort((V,se)=>se.timestamp-V.timestamp).map(({timestamp:V,...se})=>se)},[n,H]),te=(H==null?void 0:H.version)||(H==null?void 0:H.daemonVersion)||null,ie=!!H&&!!te&&!0&&te!==ne,xe=a.useMemo(()=>(H==null?void 0:H.availableProviders)||[],[H]),re=a.useMemo(()=>xe.filter(U=>U.category==="cli").map(U=>({type:U.type,displayName:U.displayName||U.type,icon:U.icon})),[xe]),he=a.useMemo(()=>xe.filter(U=>U.category==="acp").map(U=>({type:U.type,displayName:U.displayName||U.type,icon:U.icon})),[xe]),We=a.useMemo(()=>{const U=new Map;for(const V of ee){const se=V.conversation.daemonId||V.conversation.ideId,oe=U.get(se);oe?oe.push(V):U.set(se,[V])}return G.map(V=>{const se=U.get(V.id)||[],oe=[...se].sort((le,Mt)=>Mt.timestamp-le.timestamp)[0]||null,ge=(oe==null?void 0:oe.conversation)||null,be=se.filter(le=>le.unread||le.requiresAction).length,Ne=V.status==="online"?"Connected":V.status||"Unknown",pe=[V.platform||"machine",Ne].filter(Boolean);return{id:V.id,label:He(V,{fallbackId:V.id}),subtitle:pe.join(" · "),unread:be,total:se.length,latestConversation:ge,latestTimestamp:(oe==null?void 0:oe.timestamp)||0,preview:ge?`${ge.displayPrimary} · ${yn(ge)}`:"No active conversations yet. Open the machine to launch an IDE, CLI, or ACP session."}}).sort((V,se)=>{const oe=Math.max(V.latestTimestamp,Gt(G.find(be=>be.id===V.id))),ge=Math.max(se.latestTimestamp,Gt(G.find(be=>be.id===se.id)));return ge!==oe?ge-oe:V.label.localeCompare(se.label)})},[ee,G]),Ce=a.useCallback(U=>{P(U.tabKey),L("chat"),Y(U)},[Y]),mt=a.useCallback(U=>{const V=t.find(se=>se.ideId===U.ideId&&se.streamSource==="native");V&&(P(V.tabKey),L("chat"),Y(V))},[t,Y]),qe=a.useCallback(()=>{Y(Z),L("inbox")},[Y,Z]),_e=a.useCallback(U=>{W(U),_("idle"),A(""),T("machines"),z("inbox"),L("machine")},[]),Ee=a.useCallback(U=>{var se;const V=U.daemonId||((se=U.ideId)==null?void 0:se.split(":")[0])||U.ideId;V&&(W(V),_("idle"),A(""),T("machines"),z("chat"),L("machine"))},[]),et=a.useCallback(()=>{L($)},[$]),Ge=a.useCallback(async(U,V,se)=>{var oe;try{_("loading"),A(`Launching ${V}…`);const ge={ideType:V,enableCdp:!0};(oe=se==null?void 0:se.workspacePath)!=null&&oe.trim()&&(ge.workspace=se.workspacePath.trim()),await i(U,"launch_ide",ge),_("done"),A(`${V} launch requested`)}catch(ge){_("error"),A(ge instanceof Error?ge.message:"Launch IDE failed"),console.error("Launch IDE failed",ge)}},[i]),tt=a.useCallback(async(U,V,se)=>{if(V.trim())try{_("loading"),A(se!=null&&se.createIfMissing?"Creating folder…":"Saving workspace…");const oe=await i(U,"workspace_add",{path:V.trim(),createIfMissing:(se==null?void 0:se.createIfMissing)===!0});if(oe!=null&&oe.success){_("done"),A(se!=null&&se.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}_("error"),A((oe==null?void 0:oe.error)||"Could not save workspace")}catch(oe){_("error"),A(oe instanceof Error?oe.message:"Could not save workspace")}},[i]),st=a.useCallback(async U=>{var V,se,oe,ge,be,Ne;try{_("loading"),A("Starting daemon upgrade…");const pe=await i(U,"daemon_upgrade",{});if((V=pe==null?void 0:pe.result)!=null&&V.alreadyLatest){_("done"),A(`Already on v${((se=pe==null?void 0:pe.result)==null?void 0:se.version)||"latest"}.`);return}if((oe=pe==null?void 0:pe.result)!=null&&oe.upgraded||(ge=pe==null?void 0:pe.result)!=null&&ge.success){_("done"),A(`Upgrade to v${((be=pe==null?void 0:pe.result)==null?void 0:be.version)||"latest"} started. Daemon is restarting…`);return}_("error"),A(((Ne=pe==null?void 0:pe.result)==null?void 0:Ne.error)||"Upgrade failed")}catch(pe){_("error"),A(pe instanceof Error?pe.message:"Upgrade failed")}},[i]),$e=a.useCallback(async(U,V,se,oe)=>{var ge;try{_("loading"),A(`Launching ${se}…`);const be={cliType:se};(ge=oe==null?void 0:oe.workspacePath)!=null&&ge.trim()?be.dir=oe.workspacePath.trim():oe!=null&&oe.workspaceId&&(be.workspaceId=oe.workspaceId),oe!=null&&oe.resumeSessionId&&(be.resumeSessionId=oe.resumeSessionId);const Ne=await i(U,"launch_cli",be),pe=(Ne==null?void 0:Ne.result)||Ne,le=(pe==null?void 0:pe.sessionId)||(pe==null?void 0:pe.id);if(Ne!=null&&Ne.success&&le){_("done"),A(`${se} launched`),ce(`/dashboard?activeTab=${encodeURIComponent(le)}`);return}_("error"),A((Ne==null?void 0:Ne.error)||(pe==null?void 0:pe.error)||`Could not launch ${V.toUpperCase()} workspace`)}catch(be){_("error"),A(be instanceof Error?be.message:`Could not launch ${V.toUpperCase()} workspace`)}},[ce,i]),ft=a.useCallback(async U=>{if(H){if(U.kind==="ide"&&U.providerType){await Ge(H.id,U.providerType,{workspacePath:U.workspace||null});return}if((U.kind==="cli"||U.kind==="acp")&&U.providerType){await $e(H.id,U.kind,U.providerType,{workspacePath:U.workspace||null,resumeSessionId:U.providerSessionId||null});return}}},[Ge,$e,H]);return e.jsx("div",{className:"dashboard-mobile-chat",children:K==="chat"&&Z?e.jsx(Ko,{selectedConversation:Z,isAcp:je(Z),selectedIdeEntry:Q,actionLogs:r,userName:l,isSendingChat:X.isSendingChat,isFocusingAgent:X.isFocusingAgent,handleModalButton:X.handleModalButton,handleRelaunch:X.handleRelaunch,onBack:qe,onOpenNativeConversation:mt,onOpenMachine:Ee,onHideConversation:k,onOpenHistory:w,onOpenRemote:v,onStopCli:y,cliViewMode:E,onSetCliViewMode:async U=>{if(Z&&E!==U)try{await i(Z.daemonId||Z.ideId,"set_cli_view_mode",{targetSessionId:Z.sessionId,cliType:Z.ideType||Z.agentType,mode:U})}catch(V){console.error("Failed to switch CLI view mode:",V)}},handleSendChat:X.handleSendChat,handleFocusAgent:X.handleFocusAgent}):K==="machine"&&H?e.jsx(zo,{selectedMachineEntry:H,selectedMachineConversations:R,selectedMachineRecentLaunches:F,cliProviders:re,acpProviders:he,selectedMachineNeedsUpgrade:ie,appVersion:ne,machineAction:{state:D,message:O},section:B,showBottomNav:$==="inbox",onBack:et,onSectionChange:U=>{T(U),L("inbox")},onOpenConversation:Ce,onOpenRecent:ft,onOpenMachineDetails:()=>ce(`/machines/${H.id}`),onMachineUpgrade:()=>st(H.id),onLaunchDetectedIde:(U,V)=>Ge(H.id,U,V),onAddWorkspace:(U,V)=>tt(H.id,U,V),onLaunchWorkspaceProvider:(U,V,se)=>$e(H.id,U,V,se)}):e.jsx(Oo,{section:B,attentionItems:ue,unreadItems:ae,workingItems:me,completedItems:J,hiddenConversations:s,machineCards:We,getAvatarText:Ho,onOpenConversation:Ce,onShowConversation:g,onShowAllHidden:M,onOpenMachine:_e,onOpenSettings:()=>ce("/settings"),onOpenAccount:p,onSectionChange:T,wsStatus:j,isConnected:I,isStandalone:d})})}function hs(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Vo({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[d,l]=a.useState(!1),[f,x]=a.useState(null),m=a.useCallback(()=>{c.current=0,l(!1),x(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",m),window.addEventListener("drop",m),()=>{window.removeEventListener("dragend",m),window.removeEventListener("drop",m)}),[m]);const h=a.useCallback(w=>{w.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,l(!0))},[]),u=a.useCallback(w=>{if(!w.dataTransfer.types.includes("text/tab-key"))return;if(w.preventDefault(),!hs(s,n)){x("merge");return}const v=w.currentTarget.getBoundingClientRect(),y=w.clientX-v.left,j=v.width/3;y<j?x("split-left"):y>j*2?x("split-right"):x("merge")},[s,n]),b=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,l(!1),x(null))},[]),p=a.useCallback(w=>{c.current=0,l(!1);const v=w.dataTransfer.getData("text/tab-key"),y=v?t.some(I=>I.tabKey===v):!1,j=f;if(x(null),o(),!!v){if(w.preventDefault(),j==="split-left"&&hs(s,n)){n==null||n(v,"split-left");return}if(j==="split-right"&&hs(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:u,handleDragLeave:b,handleDrop:p}}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 Go({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[d,l]=a.useState(n??[]),[f,x]=a.useState(null),m=a.useRef(null),h=a.useRef(null),u=a.useRef(r),b=a.useRef(i);a.useEffect(()=>{u.current=r},[r]),a.useEffect(()=>{b.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{l(k=>{const N=qo(k,t);return N.length===k.length&&N.every((P,K)=>P===k[K])?k:N})},[t]);const p=a.useMemo(()=>{const k=f??d;if(k.length===0)return t;const N=new Map(k.map((P,K)=>[P,K]));return[...t].sort((P,K)=>{const L=N.get(P.tabKey)??999,B=N.get(K.tabKey)??999;return L-B})},[t,f,d]);a.useEffect(()=>{var N,P;if(p.length===0){o!==null&&(c(null),(N=u.current)==null||N.call(u,null));return}if(o&&p.some(K=>K.tabKey===o))return;const k=p[0].tabKey;k!==o&&(c(k),(P=u.current)==null||P.call(u,k))},[p,o]);const w=a.useMemo(()=>p.find(k=>k.tabKey===o),[p,o]),v=a.useCallback(k=>{var N;c(k),(N=u.current)==null||N.call(u,k)},[]),y=a.useCallback((k,N,P)=>{l(K=>{var S;const L=K.filter(W=>W!==k),B=L.indexOf(N);if(B<0)return K;const T=P==="left"?B:B+1;return L.splice(T,0,k),(S=b.current)==null||S.call(b,L),L}),x(null)},[]),j=a.useCallback((k,N,P)=>{const L=(d.length>0?d:t.map(S=>S.tabKey)).filter(S=>S!==k),B=L.indexOf(N);if(B<0)return;const T=P==="left"?B:B+1;L.splice(T,0,k),m.current=L,x(L)},[d,t]),I=a.useCallback(()=>{var N;const k=m.current;k&&(l(k),(N=b.current)==null||N.call(b,k))},[]),g=a.useCallback(()=>{m.current=null,x(null)},[]),M=a.useCallback(k=>{l(N=>{var K;const P=N.filter(L=>L!==k);return P.push(k),(K=b.current)==null||K.call(b,P),P})},[]);return{activeTabId:o,activeConv:w,sortedConversations:p,previewOrderRef:m,draggingTabRef:h,selectTab:v,handleTabReorder:y,updatePreviewOrder:j,commitPreviewOrder:I,clearPreviewOrder:g,moveTabToEnd:M,setDraggingTabKey:k=>{h.current=k}}}function Yo({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 Ks({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(vr,{}),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(zn,{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 wr="adhdev-tab-shortcuts";function Xo(){try{return JSON.parse(localStorage.getItem(wr)||"{}")}catch{return{}}}function Jo({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,o]=a.useState(()=>Xo()),[c,d]=a.useState(null),l=a.useCallback(x=>{const m=[];return x.metaKey&&m.push(r?"⌘":"Meta"),x.ctrlKey&&m.push("Ctrl"),x.altKey&&m.push(r?"⌥":"Alt"),x.shiftKey&&m.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(x.key)?null:(m.push(x.key.length===1?x.key.toUpperCase():x.key),m.join("+"))},[r]),f=a.useCallback(x=>{o(x);try{localStorage.setItem(wr,JSON.stringify(x))}catch{}},[]);return a.useEffect(()=>{if(!c)return;const x=m=>{if(m.preventDefault(),m.stopPropagation(),m.key==="Escape"){d(null);return}const h=l(m);if(!h)return;const u={...i};for(const[b,p]of Object.entries(u))p===h&&delete u[b];u[c]=h,f(u),d(null)};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[c,i,f,l]),a.useEffect(()=>{const x=m=>{if(!(!m.ctrlKey&&!m.metaKey&&!m.altKey)){for(const[h,u]of Object.entries(i))if(t.includes(h)&&l(m)===u){m.preventDefault(),s(),n(h);return}}};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[i,t,s,n,l]),{isMac:r,tabShortcuts:i,shortcutListening:c,setShortcutListening:d,saveShortcuts:f}}const Zo=a.memo(function({conv:s,isActive:n,isDraggedTab:r,isTaskCompleteUnread:i,shortcut:o,conversationKeys:c,draggingTabRef:d,onFocus:l,onSelectTab:f,onConversationActivated:x,onPreviewReorder:m,onReorderTab:h,onCommitPreviewOrder:u,onClearPreviewOrder:b,onDragStateReset:p,onDragTabKeyChange:w,onReceiveTab:v,onOpenContextMenu:y,longPressTimer:j,isGroupActive:I}){const g=ss(s),M=g.isGenerating?"agent-tab-generating":g.isWaiting?"agent-tab-waiting":"",k=g.isReconnecting,N=a.useCallback(z=>{d.current=s.tabKey,w(s.tabKey),z.dataTransfer.setData("text/tab-key",s.tabKey),z.dataTransfer.effectAllowed="move"},[s.tabKey,d,w]),P=a.useCallback(()=>{d.current=null,w(null),u(),b(),p()},[d,w,u,b,p]),K=a.useCallback(z=>{const D=d.current;if(!(!D||D===s.tabKey)&&z.dataTransfer.types.includes("text/tab-key")){z.preventDefault(),z.stopPropagation();const _=z.currentTarget.getBoundingClientRect(),O=z.clientX<_.left+_.width/2?"left":"right";m(D,s.tabKey,O)}},[s.tabKey,d,m]),L=a.useCallback(z=>{z.preventDefault(),z.stopPropagation();const D=z.dataTransfer.getData("text/tab-key");if(D&&D!==s.tabKey){const _=z.currentTarget.getBoundingClientRect(),O=z.clientX<_.left+_.width/2?"left":"right";c.includes(D)?h(D,s.tabKey,O):v&&v(D)}b()},[s.tabKey,c,h,v,b]),B=a.useCallback(z=>{z.stopPropagation(),l(),f(s.tabKey),x(s)},[s,x,l,f]),T=a.useCallback(z=>{z.preventDefault(),y(z.clientX,z.clientY,s.tabKey)},[s.tabKey,y]),S=a.useCallback(z=>{const D=z.touches[0];j.current=setTimeout(()=>{y(D.clientX,D.clientY,s.tabKey)},600)},[s.tabKey,j,y]),W=a.useCallback(()=>{j.current&&clearTimeout(j.current)},[j]),$=["adhdev-dockview-tab",M,n&&"is-active",I&&"is-group-active",k&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:$,draggable:!0,onDragStart:N,onDragEnd:P,onDragOver:K,onDrop:L,onClick:B,onContextMenu:T,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:g.isGenerating?e.jsx("div",{className:"tab-spinner"}):g.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):k?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):g.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:k?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):g.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 Qo({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,unreadTabKeys:i,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:x,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:u,onDragTabKeyChange:b,onMoveTab:p,onReceiveTab:w,onHideTab:v,isGroupActive:y}){const[j,I]=a.useState(null),g=a.useRef(null),M=a.useRef(null),k=a.useMemo(()=>t.map(S=>S.tabKey),[t]);Ct("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(j==null?void 0:j.tabKey)||null});const{isMac:N,tabShortcuts:P,shortcutListening:K,setShortcutListening:L,saveShortcuts:B}=Jo({sortedTabKeys:t.map(S=>S.tabKey),onFocus:c,onSelectTab:d});a.useEffect(()=>{if(!j)return;const S=W=>{const $=document.querySelector("[data-pane-context-menu]");$&&$.contains(W.target)||I(null)};return window.addEventListener("mousedown",S,!0),()=>window.removeEventListener("mousedown",S,!0)},[j]),a.useEffect(()=>{const S=M.current;if(!S)return;const W=$=>{Math.abs($.deltaY)>Math.abs($.deltaX)&&($.preventDefault(),S.scrollLeft+=$.deltaY)};return S.addEventListener("wheel",W,{passive:!1}),()=>S.removeEventListener("wheel",W)},[]);const T=a.useCallback((S,W,$)=>{I({x:S,y:W,tabKey:$})},[]);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(Zo,{conv:S,isActive:s===S.tabKey,isDraggedTab:o.current===S.tabKey,isTaskCompleteUnread:i.has(S.tabKey),shortcut:P[S.tabKey],conversationKeys:k,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:x,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:u,onDragTabKeyChange:b,onReceiveTab:w,onOpenContextMenu:T,longPressTimer:g,isGroupActive:y},S.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),j&&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:j.x,top:j.y},children:[p&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{p(j.tabKey,"left"),I(null)},children:"← Move to Left Group"}),p&&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:()=>{p(j.tabKey,"right"),I(null)},children:"Move to Right Group →"}),p&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{p(j.tabKey,"split-left"),I(null)},children:"⇤ Split Left"}),p&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{p(j.tabKey,"split-right"),I(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(),L(j.tabKey),I(null)},children:["⌨ ",P[j.tabKey]?`Change shortcut (${P[j.tabKey]})`:"Set shortcut"]}),P[j.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={...P};delete S[j.tabKey],B(S),I(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(j.tabKey),I(null)},children:"🚫 Hide from Dashboard"})]}),!p&&!v&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),K&&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:()=>L(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. ",N?"⌘+1":"Ctrl+1",", ",N?"⌥+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 ec({conversations:t,ides:s,clearedTabs:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,groupIndex:f,onFocus:x,isSplitMode:m,numGroups:h,onMoveTab:u,onReceiveTab:b,style:p,detectedIdes:w,handleLaunchIde:v,onActiveTabChange:y,initialActiveTabId:j,initialTabOrder:I,onTabOrderChange:g,onHideTab:M,isFocused:k}){const{sendCommand:N}=Qe(),P=a.useRef(null),{activeTabId:K,activeConv:L,sortedConversations:B,draggingTabRef:T,selectTab:S,handleTabReorder:W,updatePreviewOrder:$,commitPreviewOrder:z,clearPreviewOrder:D,moveTabToEnd:_,setDraggingTabKey:O}=Go({conversations:t,initialActiveTabId:j,initialTabOrder:I,onActiveTabChange:y,onTabOrderChange:g}),A=rs({sendDaemonCommand:i,activeConv:L,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),{dragOver:q,dropAction:ce,resetDragState:ne,handleDragEnter:Z,handleDragOver:Q,handleDragLeave:E,handleDrop:G}=Vo({conversations:t,numGroups:h,onMoveTab:u,onReceiveTab:b,onOwnTabDrop:_,onClearPreviewOrder:D}),H=L&&!je(L)&&xt(L)==="terminal",C=a.useMemo(()=>L?s.find(ae=>ae.id===L.ideId):void 0,[s,L]),X=a.useMemo(()=>L?r.filter(ae=>ae.ideId===L.tabKey):[],[r,L]),Y=a.useMemo(()=>It(s),[s]),ee=a.useMemo(()=>new Set(B.filter(ae=>Ya(ae,Y,{isOpenConversation:ae.tabKey===K})).map(ae=>ae.tabKey)),[K,Y,B]);Ct("PaneGroup",{groupIndex:f,conversationCount:t.length,activeTabId:K,dragOver:q});const ue=a.useCallback(ae=>{ae.streamSource==="agent-stream"&&ae.agentType&&N(ae.ideId,"focus_session",{agentType:ae.agentType,...ae.sessionId&&{targetSessionId:ae.sessionId}}).catch(()=>{})},[N]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:x,style:{...p,outline:q?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Qo,{conversations:B,activeTabId:K,groupIndex:f,numGroups:h,unreadTabKeys:ee,draggingTabRef:T,onFocus:x,onSelectTab:S,onConversationActivated:ue,onPreviewReorder:$,onReorderTab:W,onCommitPreviewOrder:z,onClearPreviewOrder:D,onDragStateReset:ne,onDragTabKeyChange:O,onMoveTab:u,onReceiveTab:b,onHideTab:M,isGroupActive:k??!1}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:Z,onDragOver:Q,onDragLeave:E,onDrop:G,children:[q&&e.jsx(Yo,{dropAction:ce,canSplit:!!(h<4&&u)}),L?e.jsx(Bs,{activeConv:L,clearToken:n[L.tabKey]||0,isCliTerminal:!!H,ideEntry:C,terminalRef:P,handleModalButton:A.handleModalButton,handleRelaunch:A.handleRelaunch,handleSendChat:A.handleSendChat,isSendingChat:A.isSendingChat,handleFocusAgent:A.handleFocusAgent,isFocusingAgent:A.isFocusingAgent,actionLogs:X,userName:l}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(Ks,{conversationsCount:t.length,isSplitMode:m,isStandalone:d,detectedIdes:w,handleLaunchIde:v})})]})]})}function tc({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:x,isStandalone:m,userName:h,focusedGroup:u,setFocusedGroup:b,moveTabToGroup:p,splitTabRelative:w,closeGroup:v,handleResizeStart:y,detectedIdes:j,handleLaunchIde:I,groupActiveTabIds:g,setGroupActiveTabIds:M,groupTabOrders:k,setGroupTabOrders:N,toggleHiddenTab:P}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:i.map((K,L)=>{const B=s&&r.length===n?`${r[L]}%`:void 0;return e.jsxs(Is.Fragment,{children:[s&&L>0&&e.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:T=>y(L-1,T),onDoubleClick:()=>v(L),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(ec,{style:s?{flexBasis:B??`${100/n}%`,flexGrow:B?0:1,flexShrink:B?0:1}:void 0,conversations:K,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:x,isStandalone:m,userName:h,groupIndex:L,isFocused:s&&u===L,onFocus:()=>b(L),isSplitMode:s,numGroups:n,onMoveTab:(T,S)=>{S==="left"&&L>0?p(T,L-1):S==="right"&&L<n-1?p(T,L+1):S==="split-left"&&n<4?w(T,L,"left"):S==="split-right"&&n<4&&w(T,L,"right")},onReceiveTab:T=>p(T,L),detectedIdes:L===0?j:void 0,handleLaunchIde:L===0?I:void 0,onActiveTabChange:T=>M(S=>(S[L]??null)===(T??null)?S:{...S,[L]:T}),initialActiveTabId:g[L],initialTabOrder:k[L],onTabOrderChange:T=>N(S=>{const W=S[L]||[];return W.length===T.length&&W.every(($,z)=>$===T[z])?S:{...S,[L]:T}}),onHideTab:P})]},L)})})}function kr({doId:t,ideId:s,ideType:n,connState:r,viewMode:i,instanceId:o}){const[c,d]=a.useState(null),[l,f]=a.useState(null),x=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?we.onScreenshot("ide-page",(u,b)=>{if(u!==t)return;const p=new FileReader;p.onload=()=>d(p.result),p.readAsDataURL(b)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&d(null)},[r]),a.useEffect(()=>{var u;return t?((u=we.onStatus)==null?void 0:u.call(we,(b,p)=>{b===t&&p!=null&&p.screenshotUsage&&f(p.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{d(null)},[t,s,x]),a.useEffect(()=>{const h=t?we.get(t):null;if(!(!h||r!=="connected"))return i!=="chat"&&x?h.startScreenshots(x):h.stopScreenshots(x),()=>{h.stopScreenshots(x)}},[i,r,x,t]);const m=a.useCallback(async(h,u)=>{const b=t?we.get(t):null;return!b||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):b.sendInput(h,u,o||x)},[t,r,o,x]);return{connScreenshot:c,screenshotUsage:l,handleRemoteAction:m}}const Nr=a.createContext(null);function as(){const t=a.useContext(Nr);if(!t)throw new Error("DashboardDockviewContext missing");return t}function Ut(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function sc(t){return`remote:${t}`}function Zt(t){return t.startsWith("remote:")}function is(t,s){return t.find(n=>n.ideId===s&&n.streamSource==="native")??t.find(n=>n.ideId===s)??null}function nc(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 rc(t,s,n){var d;const r=[s];let i;for(const l of r){let f;for(const x of l){const m=t.addPanel({id:x.tabKey,component:"conversation",title:Ut(x),params:{kind:"conversation",tabKey:x.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 vn(t,s){const n=new Set(s.map(r=>r.tabKey));for(const r of[...t.panels])Zt(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!==Ut(r)&&i.api.setTitle(Ut(r));continue}t.addPanel({id:r.tabKey,component:"conversation",title:Ut(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 jn(t,s,n){var l,f;const r=n?sc(n):null;for(const x of[...t.panels])Zt(x.id)&&(!r||x.id!==r)&&t.removePanel(x);if(!n||!r)return;const i=is(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(x=>!Zt(x.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 ac({params:t}){const s=as(),n=a.useRef(null),r=s.conversationsByTabKey.get(t.tabKey),i=rs({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(Ks,{conversationsCount:0,isSplitMode:!1,isStandalone:s.isStandalone,detectedIdes:s.detectedIdes,handleLaunchIde:s.handleLaunchIde})});const d=!je(r)&&xt(r)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(Bs,{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 ic({params:t}){var l;const s=as(),n=a.useMemo(()=>is([...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}=kr({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(Hn,{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 oc(){const t=as();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(Ks,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function cc(t){var m,h;nc(t);const s=as();if(t.params.kind==="remote"){const u=is([...s.conversationsByTabKey.values()],t.params.ideId),b=((m=t.api.group.activePanel)==null?void 0:m.id)===t.api.id,p=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${b?" is-active":""}${p?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(u==null?void 0:u.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:u!=null&&u.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:u.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=St(n,s.liveSessionInboxState,{isOpenConversation:r}),c=o.isReconnecting,d=o.isConnecting,l=o.isGenerating,f=o.isWaiting,x=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:[x&&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 lc({visibleConversations:t,clearedTabs:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,detectedIdes:f,handleLaunchIde:x,toggleHiddenTab:m,onActiveTabChange:h,requestedActiveTabKey:u,requestedRemoteIdeId:b,onRequestedActiveTabConsumed:p}){const{theme:w}=lr(),{sendCommand:v}=Qe(),y=a.useRef(null),j=a.useRef(null),I=a.useRef(!1),[g,M]=a.useState(!1),[k,N]=a.useState(!1),P=a.useRef(null),K=a.useMemo(()=>gr(typeof window<"u"?window.innerWidth:1280),[]),L=a.useMemo(()=>new Map(t.map(A=>[A.tabKey,A])),[t]),B=a.useMemo(()=>It(n),[n]),T=a.useMemo(()=>({actionLogs:r,clearedTabs:s,conversationsByTabKey:L,detectedIdes:f,handleLaunchIde:x,ides:n,isStandalone:d,liveSessionInboxState:B,sendDaemonCommand:i,setActionLogs:c,setLocalUserMessages:o,toggleHiddenTab:m,userName:l}),[r,s,L,f,x,n,d,B,i,c,o,m,l]),S=a.useCallback(A=>{if(!A)return!1;const q=y.current;if(!q)return!1;const ce=q.getPanel(A);return ce?(ce.group.model.openPanel(ce),p==null||p(),!0):!1},[p]),W=a.useCallback(()=>{const A=j.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 ce of q)ce.setAttribute("data-adhdev-force-hidden","true")},[]),$=a.useCallback(()=>{const A=j.current;if(!A)return;const q=A.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const ce of q)ce.removeAttribute("data-adhdev-force-hidden")},[]),z=a.useCallback(()=>{const A=j.current;if(!A)return;const q=A.querySelectorAll(".dv-drop-target-container");for(const Z of q)Z.remove();const ce=A.querySelectorAll(".dv-drop-target-dropzone");for(const Z of ce)Z.remove();const ne=A.querySelectorAll(".dv-drop-target");for(const Z of ne)Z.classList.remove("dv-drop-target")},[]),D=a.useCallback(()=>{M(!1),N(!1),$(),W(),z(),!(typeof window>"u")&&(P.current!=null&&window.clearTimeout(P.current),window.requestAnimationFrame(()=>{W(),z()}),P.current=window.setTimeout(()=>{W(),z(),P.current=null},80))},[$,W,z]),_=a.useCallback(A=>{var ce;y.current=A.api;const q=Io(K);q!=null&&q.layout&&A.api.fromJSON(q.layout,{reuseExistingPanels:!1}),vn(A.api,t),jn(A.api,t,b),A.api.totalPanels===0&&t.length>0?rc(A.api,t,u):S(u)||S(q==null?void 0:q.activeTabId),I.current=!0,A.api.onDidActivePanelChange(ne=>{var Q;if(ne&&Zt(ne.id)){const E=((Q=ne.params)==null?void 0:Q.ideId)||ne.id.slice(7),G=is(t,E);h((G==null?void 0:G.tabKey)??null);return}if(h((ne==null?void 0:ne.id)??null),!ne)return;const Z=L.get(ne.id);(Z==null?void 0:Z.streamSource)==="agent-stream"&&Z.agentType&&v(Z.ideId,"focus_session",{agentType:Z.agentType,...Z.sessionId&&{targetSessionId:Z.sessionId}}).catch(()=>{})}),A.api.onDidLayoutChange(()=>{var ne;Mo(K,{activeTabId:((ne=A.api.activePanel)==null?void 0:ne.id)??null,layout:A.api.toJSON()})}),A.api.onWillDragPanel(()=>{M(!0),N(!1),W()}),A.api.onWillDragGroup(()=>{M(!0),N(!1),W()}),A.api.onWillShowOverlay(()=>{$(),N(!0)}),A.api.onDidMovePanel(D),A.api.onDidDrop(D),h(((ce=A.api.activePanel)==null?void 0:ce.id)??null)},[S,D,$,L,K,W,z,h,u,v,t]);a.useEffect(()=>{const A=y.current;!A||!I.current||(vn(A,t),jn(A,t,b),!A.activePanel&&A.panels[0]&&A.panels[0].group.model.openPanel(A.panels[0]))},[b,t]),a.useEffect(()=>{I.current&&S(u)},[S,u]),a.useEffect(()=>{if(!g||typeof window>"u")return;const A=()=>D();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)}},[D,g]),a.useEffect(()=>()=>{typeof window>"u"||P.current!=null&&window.clearTimeout(P.current)},[]),a.useEffect(()=>{const A=q=>{const ce=q.target;if(!ce)return;const ne=ce.querySelector("[data-tab-key]")||ce.closest("[data-tab-key]");if(ne){const Z=ne.getAttribute("data-tab-key");Z&&q.dataTransfer&&q.dataTransfer.setData("text/tab-key",Z)}};return window.addEventListener("dragstart",A),()=>window.removeEventListener("dragstart",A)},[]);const O=w==="light"?ia:oa;return e.jsx(Nr.Provider,{value:T,children:e.jsx("div",{ref:j,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(aa,{className:`h-full min-h-0 min-w-0 adhdev-dockview${g?" is-dragging-dockview":""}${k?" is-showing-dockview-overlay":""}`,components:{conversation:ac,remote:ic},defaultTabComponent:cc,watermarkComponent:oc,onReady:_,singleTabMode:"default",tabAnimation:"smooth",theme:O})})})}function dc({showMobileChatMode:t,isMobile:s,activeConv:n,chatIdes:r,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:d,onStopCli:l,activeCliViewMode:f,onSetActiveCliViewMode:x,mobileChatConversations:m,hiddenConversations:h,ides:u,actionLogs:b,sendDaemonCommand:p,setLocalUserMessages:w,setActionLogs:v,isStandalone:y,userName:j,requestedMobileTabKey:I,onRequestedMobileTabConsumed:g,requestedMachineId:M,onRequestedMachineConsumed:k,requestedMobileSection:N,onRequestedMobileSectionConsumed:P,containerRef:K,isSplitMode:L,numGroups:B,groupSizes:T,groupedConvs:S,clearedTabs:W,focusedGroup:$,setFocusedGroup:z,moveTabToGroup:D,splitTabRelative:_,closeGroup:O,handleResizeStart:A,detectedIdes:q,handleLaunchIde:ce,groupActiveTabIds:ne,setGroupActiveTabIds:Z,groupTabOrders:Q,setGroupTabOrders:E,toggleHiddenTab:G,visibleConversations:H,requestedDesktopTabKey:C,onRequestedDesktopTabConsumed:X,onOpenAccount:Y,onDesktopActiveTabChange:ee,onHideConversation:ue,onShowHiddenConversation:ae,onShowAllHiddenConversations:me}){return Is.useEffect(()=>{const J=R=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?R.metaKey&&R.key.toLowerCase()==="w":R.ctrlKey&&R.key.toLowerCase()==="w")&&(R.preventDefault(),n&&ue&&ue(n))};return window.addEventListener("keydown",J),()=>window.removeEventListener("keydown",J)},[n,ue]),e.jsxs(e.Fragment,{children:[!t&&e.jsx(wi,{activeConv:n,agentCount:r.length,wsStatus:i,isConnected:o,conversations:H,hiddenConversations:h,onOpenHistory:c,onOpenConversation:ae,onHideConversation:ue,onShowConversation:ae,onShowAllHidden:me,onOpenRemote:()=>{!n||Se(n)||je(n)||d(n)},onStopCli:l,activeCliViewMode:f,onSetCliViewMode:x}),t?e.jsx(Fo,{conversations:m,hiddenConversations:h,ides:u,actionLogs:b,sendDaemonCommand:p,setLocalUserMessages:w,setActionLogs:v,isStandalone:y,userName:j,requestedActiveTabKey:I,onRequestedActiveTabConsumed:g,requestedMachineId:M,onRequestedMachineConsumed:k,requestedMobileSection:N,onRequestedMobileSectionConsumed:P,onOpenAccount:Y,onOpenHistory:c,onOpenRemote:d,onStopCli:l,wsStatus:i,isConnected:o,onShowHiddenConversation:ae,onShowAllHiddenConversations:me}):s?e.jsx(tc,{containerRef:K,isSplitMode:L,numGroups:B,groupSizes:T,groupedConvs:S,clearedTabs:W,ides:u,actionLogs:b,sendDaemonCommand:p,setLocalUserMessages:w,setActionLogs:v,isStandalone:y,userName:j,focusedGroup:$,setFocusedGroup:z,moveTabToGroup:D,splitTabRelative:_,closeGroup:O,handleResizeStart:A,detectedIdes:q,handleLaunchIde:ce,groupActiveTabIds:ne,setGroupActiveTabIds:Z,groupTabOrders:Q,setGroupTabOrders:E,toggleHiddenTab:G}):e.jsx(lc,{visibleConversations:H,clearedTabs:W,ides:u,actionLogs:b,sendDaemonCommand:p,setLocalUserMessages:w,setActionLogs:v,isStandalone:y,userName:j,detectedIdes:q,handleLaunchIde:ce,toggleHiddenTab:G,onActiveTabChange:ee,requestedActiveTabKey:C,onRequestedActiveTabConsumed:X})]})}const gs=[{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 uc({onClose:t}){const[s,n]=a.useState(0),r=gs[s],i=s===gs.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:gs.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
48
|
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
|
|
49
49
|
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
|
|
50
|
-
`})]})}function dc({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,onSelectTab:i}){return t?e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${n==="native"?"active":""}`,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:`ide-chat-tab ${c?"active":""}`,onClick:()=>i(o.tabKey),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:d?"var(--status-warning)":l?"var(--accent-primary)":"#64748b",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),o.title,d&&e.jsx("span",{className:"ide-ext-badge",style:{background:"color-mix(in srgb, var(--status-warning) 13%, transparent)",color:"var(--status-warning)",marginLeft:4},children:"!"})]},o.tabKey)})]}):null}function uc({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:i,preferredTabKey:o}){const[c,d]=a.useState(()=>o||"native"),l=a.useMemo(()=>tr(s),[s]),f=a.useMemo(()=>{var w;if(!t)return[];const p=t.daemonId||((w=t.id)==null?void 0:w.split(":")[0])||t.id;return sr(t,r,{machineName:t.daemonId&&l[t.daemonId]||void 0,connectionState:n[p]||"new"})},[t,r,l,n]),x=a.useMemo(()=>f.find(p=>p.streamSource==="native"),[f]),m=a.useMemo(()=>f.filter(p=>p.streamSource==="agent-stream"),[f]);a.useEffect(()=>{o&&d(o)},[o]),a.useEffect(()=>{var p;c!=="native"&&(m.some(w=>w.tabKey===c)||d(((p=m[0])==null?void 0:p.tabKey)||"native"))},[c,m]),a.useEffect(()=>{c==="native"&&(x||m[0]&&d(m[0].tabKey))},[c,x,m]);const h=a.useMemo(()=>c==="native"&&x?x:m.find(p=>p.tabKey===c)||x||m[0],[c,x,m]),u=a.useMemo(()=>m.map(p=>({tabKey:p.tabKey,title:p.title||p.agentName||i,status:p.status})),[m,i]),b=a.useCallback(p=>{if(p)return f.find(w=>w.sessionId===p||w.ideId===p||w.tabKey===p||w.ideType===p||w.agentType===p)},[f]);return{activeChatTab:c,setActiveChatTab:d,activeConv:h,conversations:f,extensionTabs:u,hasExtensions:u.length>0,resolveConversationByTarget:b}}function xc({activeConv:t,ideEntry:s,ides:n,connectionStates:r,actionLogs:i,localUserMessages:o,sendDaemonCommand:c,setLocalUserMessages:d,setActionLogs:l,isStandalone:f,userName:x,onOpenHistory:m,onConversationChange:h,onClose:u}){var W;const[b,p]=a.useState("split"),[w,v]=a.useState(()=>t.streamSource==="native"?"native":t.tabKey),y=a.useMemo(()=>s||n.find($=>$.id===t.ideId),[t.ideId,s,n]),j=a.useMemo(()=>Ie((y==null?void 0:y.type)||""),[y==null?void 0:y.type]),{conversations:I,extensionTabs:g,hasExtensions:M}=uc({ideData:y,allIdes:n,connectionStates:r,localUserMessages:o,ideName:j||"IDE",preferredTabKey:t.streamSource==="native"?"native":t.tabKey});a.useEffect(()=>{v(t.streamSource==="native"?"native":t.tabKey)},[t.streamSource,t.tabKey]);const k=a.useMemo(()=>w==="native"?I.find($=>$.streamSource==="native")||t:I.find($=>$.tabKey===w)||t,[t,I,w]),N=k.daemonId||((W=k.ideId)==null?void 0:W.split(":")[0])||k.ideId,P=rs({sendDaemonCommand:c,activeConv:k,setLocalUserMessages:d,setActionLogs:l,isStandalone:f}),{connScreenshot:K,screenshotUsage:L,handleRemoteAction:B}=wr({doId:N,ideId:k.ideId,ideType:k.ideType,connState:k.connectionState||"new",viewMode:b,instanceId:y==null?void 0:y.instanceId}),T=a.useMemo(()=>i.filter($=>$.ideId===k.tabKey),[i,k.tabKey]);a.useEffect(()=>{h==null||h(k)},[k,h]),a.useEffect(()=>{const $=z=>{z.key==="Escape"&&u()};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[u]);const S=a.useCallback($=>{$.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:u,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 items-center justify-between gap-3 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.jsx("div",{className:"flex-1 min-w-0 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(Le,{size:16})}),e.jsx("span",{className:"truncate",children:k.displayPrimary||k.agentName||"Remote"})]})}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[["split","remote"].map($=>{const z=b===$;return e.jsx("button",{className:`w-8 h-8 rounded-lg flex items-center justify-center transition-all ${z?"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:()=>p($),title:$==="split"?"Split view":"Remote only",children:$==="split"?e.jsx("span",{className:"font-bold text-lg leading-none mb-0.5",children:"⊞"}):e.jsx(Le,{size:15})},$)}),e.jsx("div",{className:"w-[1px] h-5 bg-border-subtle mx-1"}),e.jsxs("button",{className:"btn btn-secondary btn-sm h-8 px-3 rounded-lg",onClick:()=>m(k),title:"Chat History",children:[e.jsx(As,{size:14,className:"mr-1.5"})," History"]}),e.jsx("button",{className:"btn btn-primary btn-sm h-8 px-4 rounded-lg font-bold",onClick:u,children:"Close"})]})]}),e.jsxs("div",{className:`flex-1 min-h-0 grid bg-bg-primary ${b==="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:[b!=="remote"&&e.jsxs("div",{className:`flex flex-col min-w-0 min-h-0 bg-bg-primary ${b==="split"?"order-2 md:order-1 border-b md:border-b-0 md:border-r border-border-subtle":""}`,children:[e.jsx(dc,{hasExtensions:M,ideName:j||"IDE",activeChatTab:w,extensionTabs:g,onSelectTab:v}),e.jsx(Fn,{activeConv:k,onModalButton:P.handleModalButton}),e.jsx(ws,{activeConv:k,ideEntry:y,showMetaChips:!1,handleSendChat:P.handleSendChat,isSendingChat:P.isSendingChat,handleFocusAgent:P.handleFocusAgent,isFocusingAgent:P.isFocusingAgent,actionLogs:T,userName:x})]}),e.jsx("div",{className:`flex flex-col min-w-0 min-h-0 bg-black ${b==="split"?"order-1 md:order-2":""}`,children:e.jsx(Un,{addLog:()=>{},connState:k.connectionState||"new",connScreenshot:K,screenshotUsage:L,transportType:k.transport,onAction:B})})]})]})})}function pc({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 mc({historyModalOpen:t,historyTargetConv:s,ides:n,isHistoryCreatingChat:r,isHistoryRefreshingHistory:i,savedHistorySessions:o,isSavedHistoryLoading:c,isResumingSavedHistorySessionId:d,onCloseHistory:l,onNewHistoryChat:f,onSwitchHistorySession:x,onRefreshHistory:m,onResumeSavedHistorySession:h,remoteDialogConv:u,remoteDialogIdeEntry:b,connectionStates:p,actionLogs:w,localUserMessages:v,sendDaemonCommand:y,setLocalUserMessages:j,setActionLogs:I,isStandalone:g,userName:M,onOpenRemoteHistory:k,onRemoteConversationChange:N,onCloseRemoteDialog:P,cliStopDialogOpen:K,activeConv:L,onCancelCliStop:B,onStopCliNow:T,onSaveCliAndStop:S,toasts:W,onDismissToast:$,onClickToast:z,showOnboarding:E,onCloseOnboarding:_}){return e.jsxs(e.Fragment,{children:[t&&s&&e.jsx(wi,{activeConv:s,ides:n,isCreatingChat:r,isRefreshingHistory:i,savedSessions:o,isSavedSessionsLoading:c,isResumingSavedSessionId:d,onClose:l,onNewChat:f,onSwitchSession:x,onRefreshHistory:m,onResumeSavedSession:h}),u&&e.jsx(xc,{activeConv:u,ideEntry:b,ides:n,connectionStates:p,actionLogs:w,localUserMessages:v,sendDaemonCommand:y,setLocalUserMessages:j,setActionLogs:I,isStandalone:g,userName:M,onOpenHistory:k,onConversationChange:N,onClose:P}),K&&L&&Ne(L)&&!je(L)&&e.jsx(pc,{activeConv:L,onCancel:B,onStopNow:T,onSaveAndStop:S}),e.jsx(Qn,{toasts:W,onDismiss:$,onClickToast:z}),E&&e.jsx(lc,{onClose:_})]})}function fc({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(Rs,{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=qe(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 hc(){var Us,Hs,Fs;const{sendCommand:t}=st(),s=Ms(),n=mt(),[r,i]=ia(),o=r.get("activeTab"),c=((Us=s.state)==null?void 0:Us.openRemoteForTabKey)||null,d=((Hs=s.state)==null?void 0:Hs.openMachineId)||null,l=((Fs=s.state)==null?void 0:Fs.mobileSection)||null,f=Es(),x=f.ides||[],{updateIdeChats:m}=f,[h,u]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),b=f.toasts||[],p=f.setToasts||(()=>{}),w=f.wsStatus||"connected",v=f.isConnected??!0,y=f.connectionStates||{},j=f.showReconnected||!1,{groupAssignments:I,setGroupAssignments:g,focusedGroup:M,setFocusedGroup:k,groupActiveTabIds:N,setGroupActiveTabIds:P,groupTabOrders:K,setGroupTabOrders:L,groupSizes:B,setGroupSizes:T,isMobile:S,hasHydratedStoredLayout:W,hydrateStoredLayout:$}=Mo(),[z,E]=a.useState(!1),[_,O]=a.useState(!1),[A,q]=a.useState([]),[ce,re]=a.useState(!1),[J,Z]=a.useState(null),[D]=a.useState(()=>xr()),[G,H]=a.useState([]),[C,X]=a.useState({}),[Y,ee]=a.useState({}),[xe,ie]=a.useState(null),me=a.useRef(null);Ct("Dashboard",{ideCount:x.length,toastCount:b.length,focusedGroup:M,groupCount:Object.keys(I).length,localMessageTabs:Object.keys(C).length,actionLogCount:G.length});const Q=x.find(de=>de.type==="adhdev-daemon"),R=(Q==null?void 0:Q.detectedIdes)||[],V=!!Q,te=(Q==null?void 0:Q.terminalBackend)||null,{hiddenTabs:ae,hideTab:ue,toggleTab:oe,showTab:he,showAllTabs:Pe}=xo(),{chatIdes:Me,conversations:Be,visibleConversations:Re,visibleTabKeys:Ge,resolveConversationBySessionId:Ye,resolveConversationByTarget:Ue}=bo({ides:x,connectionStates:y,localUserMessages:C,clearedTabs:Y,hiddenTabs:ae}),Xe=a.useMemo(()=>It(x),[x]),Je=a.useRef(null),{containerRef:ct,normalizedGroupAssignments:We,numGroups:ft,isSplitMode:U,groupedConvs:F,moveTabToGroup:se,closeGroup:le,handleResizeStart:ge,splitTabRelative:be}=Do({groupAssignments:I,setGroupAssignments:g,setFocusedGroup:k,setGroupActiveTabIds:P,setGroupTabOrders:L,groupSizes:B,setGroupSizes:T,isMobile:S,visibleConversations:Re,visibleTabKeys:Ge}),ne=a.useMemo(()=>{var ye,ke;if(!S){if(xe){const Se=Be.find(Ee=>Ee.tabKey===xe);if(Se)return Se}return Re[0]}const de=N[M];if(de){const Se=Be.find(Ee=>Ee.tabKey===de);if(Se)return Se}return((ye=F[M])==null?void 0:ye[0])||((ke=F[0])==null?void 0:ke[0])},[xe,S,N,M,Be,F,Re]);a.useEffect(()=>{if(S){Je.current=null;return}if(!(ne!=null&&ne.sessionId)){Je.current=null;return}const de=`${ne.tabKey}:${ne.sessionId}`;if(Je.current===de)return;Je.current=de;const ye=ut(ne,Xe),ke=Math.max(Date.now(),ns(ne),ye.lastUpdated||0);t(ne.daemonId||ne.ideId,"mark_session_seen",{sessionId:ne.sessionId,seenAt:ke}).catch(()=>{})},[ne,S,Xe,t]);const{requestedDesktopTabKey:pe,requestedMobileTabKey:He,consumeRequestedActiveTab:Mt}=yo({isMobile:S,urlActiveTab:o,resolveConversationBySessionId:Ye,setSearchParams:i}),{remoteDialogConv:Ws,remoteDialogIdeEntry:Nr,remoteDialogActiveConv:Sr,setRemoteDialogActiveConv:os,openRemoteDialog:Cr,closeRemoteDialog:Ir}=Ao({isMobile:S,location:s,navigate:n,requestedRemoteTabTarget:c,requestedDesktopTabKey:pe,conversations:Be,ides:x,resolveConversationByTarget:Ue}),ve=Sr||Ws||ne,Oe=!!ve&&Ne(ve)&&!je(ve),Tt=a.useMemo(()=>{if(!ve||!Oe)return null;const de=ve.daemonId||ve.ideId||"",ye=ve.agentType||ve.ideType||"";return`${de}:${ye}`},[ve,Oe]),Mr=a.useMemo(()=>Re,[Re]),At=S&&D==="chat",Tr=a.useMemo(()=>Be.filter(de=>ae.has(de.tabKey)),[Be,ae]);po({visibleConversations:Re,clearedTabs:Y,setClearedTabs:ee,setActionLogs:H}),vo({ides:x,sendDaemonCommand:t,setToasts:p,setLocalUserMessages:X,resolveConversationByTarget:Ue});const{isRefreshingHistory:Ar,handleLaunchIde:Rr,handleRefreshHistory:_r}=xn({sendDaemonCommand:t,activeConv:ne,updateIdeChats:m,setToasts:p,setLocalUserMessages:X,setClearedTabs:ee}),{isCreatingChat:Lr,isRefreshingHistory:Er,handleSwitchSession:Dr,handleNewChat:$r,handleRefreshHistory:Pr}=xn({sendDaemonCommand:t,activeConv:ve,updateIdeChats:m,setToasts:p,setLocalUserMessages:X,setClearedTabs:ee}),cs=a.useCallback(async()=>{if(!(!ve||!Oe||ce)){re(!0);try{const de=ve.daemonId||ve.ideId,ye=ve.agentType||ve.ideType,ke=await t(de,"list_saved_sessions",{agentType:ye,providerType:ye,kind:"cli",limit:50}),Se=(ke==null?void 0:ke.result)??ke;q(Array.isArray(Se==null?void 0:Se.sessions)?Se.sessions:[])}catch(de){console.error("Refresh saved sessions failed",de),q([])}finally{re(!1)}}},[ve,ce,Oe,t]);a.useEffect(()=>{if(!z){me.current=null;return}if(!Oe){me.current=null,q([]),re(!1);return}!Tt||ce||me.current!==Tt&&(me.current=Tt,cs())},[cs,z,ce,Oe,Tt]);const Br=a.useCallback(async de=>{if(!ve||!Oe||!de.providerSessionId||!de.workspace)return;const ye=ve.daemonId||ve.ideId,ke=ve.agentType||ve.ideType;try{Z(de.providerSessionId);const Se=await t(ye,"launch_cli",{cliType:ke,dir:de.workspace,resumeSessionId:de.providerSessionId,initialModel:de.currentModel}),Ee=(Se==null?void 0:Se.result)??Se,Vs=typeof(Ee==null?void 0:Ee.sessionId)=="string"?Ee.sessionId:typeof(Ee==null?void 0:Ee.id)=="string"?Ee.id:"";Vs&&i(Yr=>{const qs=new URLSearchParams(Yr);return qs.set("activeTab",Vs),qs},{replace:!0}),E(!1)}catch(Se){console.error("Resume saved session failed",Se)}finally{Z(null)}},[ve,Oe,t,i]);To({urlActiveTab:S&&!At?o:null,conversations:Be,resolveConversationBySessionId:Ye,normalizedGroupAssignments:We,hasHydratedStoredLayout:S&&!At?W:!0,hydrateStoredLayout:S&&!At?$:()=>{},setGroupActiveTabIds:P,setFocusedGroup:k,setSearchParams:i,historyModalOpen:z,activeConv:ne,isRefreshingHistory:Ar,ides:x,handleRefreshHistory:_r});const Rt=a.useCallback(async de=>{if(!ne||!Ne(ne)||je(ne))return;const ye=ne.ideType||ne.agentType||"",ke=ne.ideId||ne.daemonId||"";try{await t(ke,"stop_cli",{cliType:ye,targetSessionId:ne.sessionId,mode:de})}catch(Se){console.error("Stop CLI failed:",Se)}},[ne,t]),Kr=a.useCallback(async()=>{var ye;if(!ne||!Ne(ne)||je(ne))return;if((ye=ne.resume)!=null&&ye.supported){O(!0);return}const de=ne.ideType||ne.agentType||"CLI";window.confirm(`Stop ${de}?
|
|
51
|
-
This will terminate the CLI process.`)&&await Rt("hard")},[
|
|
50
|
+
`})]})}function xc({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,onSelectTab:i}){return t?e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${n==="native"?"active":""}`,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:`ide-chat-tab ${c?"active":""}`,onClick:()=>i(o.tabKey),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:d?"var(--status-warning)":l?"var(--accent-primary)":"#64748b",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),o.title,d&&e.jsx("span",{className:"ide-ext-badge",style:{background:"color-mix(in srgb, var(--status-warning) 13%, transparent)",color:"var(--status-warning)",marginLeft:4},children:"!"})]},o.tabKey)})]}):null}function pc({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:i,preferredTabKey:o}){const[c,d]=a.useState(()=>o||"native"),l=a.useMemo(()=>sr(s),[s]),f=a.useMemo(()=>{var w;if(!t)return[];const p=t.daemonId||((w=t.id)==null?void 0:w.split(":")[0])||t.id;return nr(t,r,{machineName:t.daemonId&&l[t.daemonId]||void 0,connectionState:n[p]||"new"})},[t,r,l,n]),x=a.useMemo(()=>f.find(p=>p.streamSource==="native"),[f]),m=a.useMemo(()=>f.filter(p=>p.streamSource==="agent-stream"),[f]);a.useEffect(()=>{o&&d(o)},[o]),a.useEffect(()=>{var p;c!=="native"&&(m.some(w=>w.tabKey===c)||d(((p=m[0])==null?void 0:p.tabKey)||"native"))},[c,m]),a.useEffect(()=>{c==="native"&&(x||m[0]&&d(m[0].tabKey))},[c,x,m]);const h=a.useMemo(()=>c==="native"&&x?x:m.find(p=>p.tabKey===c)||x||m[0],[c,x,m]),u=a.useMemo(()=>m.map(p=>({tabKey:p.tabKey,title:p.title||p.agentName||i,status:p.status})),[m,i]),b=a.useCallback(p=>{if(p)return f.find(w=>w.sessionId===p||w.ideId===p||w.tabKey===p||w.ideType===p||w.agentType===p)},[f]);return{activeChatTab:c,setActiveChatTab:d,activeConv:h,conversations:f,extensionTabs:u,hasExtensions:u.length>0,resolveConversationByTarget:b}}function mc({activeConv:t,ideEntry:s,ides:n,connectionStates:r,actionLogs:i,localUserMessages:o,sendDaemonCommand:c,setLocalUserMessages:d,setActionLogs:l,isStandalone:f,userName:x,onOpenHistory:m,onConversationChange:h,onClose:u}){var W;const[b,p]=a.useState("split"),[w,v]=a.useState(()=>t.streamSource==="native"?"native":t.tabKey),y=a.useMemo(()=>s||n.find($=>$.id===t.ideId),[t.ideId,s,n]),j=a.useMemo(()=>Te((y==null?void 0:y.type)||""),[y==null?void 0:y.type]),{conversations:I,extensionTabs:g,hasExtensions:M}=pc({ideData:y,allIdes:n,connectionStates:r,localUserMessages:o,ideName:j||"IDE",preferredTabKey:t.streamSource==="native"?"native":t.tabKey});a.useEffect(()=>{v(t.streamSource==="native"?"native":t.tabKey)},[t.streamSource,t.tabKey]);const k=a.useMemo(()=>w==="native"?I.find($=>$.streamSource==="native")||t:I.find($=>$.tabKey===w)||t,[t,I,w]),N=k.daemonId||((W=k.ideId)==null?void 0:W.split(":")[0])||k.ideId,P=rs({sendDaemonCommand:c,activeConv:k,setLocalUserMessages:d,setActionLogs:l,isStandalone:f}),{connScreenshot:K,screenshotUsage:L,handleRemoteAction:B}=kr({doId:N,ideId:k.ideId,ideType:k.ideType,connState:k.connectionState||"new",viewMode:b,instanceId:y==null?void 0:y.instanceId}),T=a.useMemo(()=>i.filter($=>$.ideId===k.tabKey),[i,k.tabKey]);a.useEffect(()=>{h==null||h(k)},[k,h]),a.useEffect(()=>{const $=z=>{z.key==="Escape"&&u()};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[u]);const S=a.useCallback($=>{$.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:u,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 items-center justify-between gap-3 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.jsx("div",{className:"flex-1 min-w-0 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(De,{size:16})}),e.jsx("span",{className:"truncate",children:k.displayPrimary||k.agentName||"Remote"})]})}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[["split","remote"].map($=>{const z=b===$;return e.jsx("button",{className:`w-8 h-8 rounded-lg flex items-center justify-center transition-all ${z?"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:()=>p($),title:$==="split"?"Split view":"Remote only",children:$==="split"?e.jsx("span",{className:"font-bold text-lg leading-none mb-0.5",children:"⊞"}):e.jsx(De,{size:15})},$)}),e.jsx("div",{className:"w-[1px] h-5 bg-border-subtle mx-1"}),e.jsxs("button",{className:"btn btn-secondary btn-sm h-8 px-3 rounded-lg",onClick:()=>m(k),title:"Chat History",children:[e.jsx(As,{size:14,className:"mr-1.5"})," History"]}),e.jsx("button",{className:"btn btn-primary btn-sm h-8 px-4 rounded-lg font-bold",onClick:u,children:"Close"})]})]}),e.jsxs("div",{className:`flex-1 min-h-0 grid bg-bg-primary ${b==="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:[b!=="remote"&&e.jsxs("div",{className:`flex flex-col min-w-0 min-h-0 bg-bg-primary ${b==="split"?"order-2 md:order-1 border-b md:border-b-0 md:border-r border-border-subtle":""}`,children:[e.jsx(xc,{hasExtensions:M,ideName:j||"IDE",activeChatTab:w,extensionTabs:g,onSelectTab:v}),e.jsx(Vn,{activeConv:k,onModalButton:P.handleModalButton}),e.jsx(ws,{activeConv:k,ideEntry:y,showMetaChips:!1,handleSendChat:P.handleSendChat,isSendingChat:P.isSendingChat,handleFocusAgent:P.handleFocusAgent,isFocusingAgent:P.isFocusingAgent,actionLogs:T,userName:x})]}),e.jsx("div",{className:`flex flex-col min-w-0 min-h-0 bg-black ${b==="split"?"order-1 md:order-2":""}`,children:e.jsx(Hn,{addLog:()=>{},connState:k.connectionState||"new",connScreenshot:K,screenshotUsage:L,transportType:k.transport,onAction:B})})]})]})})}function fc({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 hc({historyModalOpen:t,historyTargetConv:s,ides:n,isHistoryCreatingChat:r,isHistoryRefreshingHistory:i,savedHistorySessions:o,isSavedHistoryLoading:c,isResumingSavedHistorySessionId:d,onCloseHistory:l,onNewHistoryChat:f,onSwitchHistorySession:x,onRefreshHistory:m,onResumeSavedHistorySession:h,remoteDialogConv:u,remoteDialogIdeEntry:b,connectionStates:p,actionLogs:w,localUserMessages:v,sendDaemonCommand:y,setLocalUserMessages:j,setActionLogs:I,isStandalone:g,userName:M,onOpenRemoteHistory:k,onRemoteConversationChange:N,onCloseRemoteDialog:P,cliStopDialogOpen:K,activeConv:L,onCancelCliStop:B,onStopCliNow:T,onSaveCliAndStop:S,toasts:W,onDismissToast:$,onClickToast:z,showOnboarding:D,onCloseOnboarding:_}){return e.jsxs(e.Fragment,{children:[t&&s&&e.jsx(Ni,{activeConv:s,ides:n,isCreatingChat:r,isRefreshingHistory:i,savedSessions:o,isSavedSessionsLoading:c,isResumingSavedSessionId:d,onClose:l,onNewChat:f,onSwitchSession:x,onRefreshHistory:m,onResumeSavedSession:h}),u&&e.jsx(mc,{activeConv:u,ideEntry:b,ides:n,connectionStates:p,actionLogs:w,localUserMessages:v,sendDaemonCommand:y,setLocalUserMessages:j,setActionLogs:I,isStandalone:g,userName:M,onOpenHistory:k,onConversationChange:N,onClose:P}),K&&L&&Se(L)&&!je(L)&&e.jsx(fc,{activeConv:L,onCancel:B,onStopNow:T,onSaveAndStop:S}),e.jsx(er,{toasts:W,onDismiss:$,onClickToast:z}),D&&e.jsx(uc,{onClose:_})]})}function gc({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(Rs,{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=He(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 bc(){var Hs,Fs,Vs;const{sendCommand:t}=Qe(),s=Ms(),n=pt(),[r,i]=ca(),o=r.get("activeTab"),c=((Hs=s.state)==null?void 0:Hs.openRemoteForTabKey)||null,d=((Fs=s.state)==null?void 0:Fs.openMachineId)||null,l=((Vs=s.state)==null?void 0:Vs.mobileSection)||null,f=Ds(),x=f.ides||[],{updateIdeChats:m}=f,[h,u]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),b=f.toasts||[],p=f.setToasts||(()=>{}),w=f.wsStatus||"connected",v=f.isConnected??!0,y=f.connectionStates||{},j=f.showReconnected||!1,{groupAssignments:I,setGroupAssignments:g,focusedGroup:M,setFocusedGroup:k,groupActiveTabIds:N,setGroupActiveTabIds:P,groupTabOrders:K,setGroupTabOrders:L,groupSizes:B,setGroupSizes:T,isMobile:S,hasHydratedStoredLayout:W,hydrateStoredLayout:$}=Ao(),[z,D]=a.useState(!1),[_,O]=a.useState(!1),[A,q]=a.useState([]),[ce,ne]=a.useState(!1),[Z,Q]=a.useState(null),[E]=a.useState(()=>pr()),[G,H]=a.useState([]),[C,X]=a.useState({}),[Y,ee]=a.useState({}),[ue,ae]=a.useState(null),me=a.useRef(null);Ct("Dashboard",{ideCount:x.length,toastCount:b.length,focusedGroup:M,groupCount:Object.keys(I).length,localMessageTabs:Object.keys(C).length,actionLogCount:G.length});const J=x.find(de=>de.type==="adhdev-daemon"),R=(J==null?void 0:J.detectedIdes)||[],F=!!J,te=(J==null?void 0:J.terminalBackend)||null,ie=J?He(J,{fallbackId:J.id}):null,xe=(J==null?void 0:J.id)||null,{hiddenTabs:re,hideTab:he,toggleTab:We,showTab:Ce,showAllTabs:mt}=mo(),{chatIdes:qe,conversations:_e,visibleConversations:Ee,visibleTabKeys:et,resolveConversationBySessionId:Ge,resolveConversationByTarget:tt}=vo({ides:x,connectionStates:y,localUserMessages:C,clearedTabs:Y,hiddenTabs:re}),st=a.useMemo(()=>It(x),[x]),$e=a.useRef(null),{containerRef:ft,normalizedGroupAssignments:U,numGroups:V,isSplitMode:se,groupedConvs:oe,moveTabToGroup:ge,closeGroup:be,handleResizeStart:Ne,splitTabRelative:pe}=Po({groupAssignments:I,setGroupAssignments:g,setFocusedGroup:k,setGroupActiveTabIds:P,setGroupTabOrders:L,groupSizes:B,setGroupSizes:T,isMobile:S,visibleConversations:Ee,visibleTabKeys:et}),le=a.useMemo(()=>{var ye,ke;if(!S){if(ue){const Ie=_e.find(Pe=>Pe.tabKey===ue);if(Ie)return Ie}return Ee[0]}const de=N[M];if(de){const Ie=_e.find(Pe=>Pe.tabKey===de);if(Ie)return Ie}return((ye=oe[M])==null?void 0:ye[0])||((ke=oe[0])==null?void 0:ke[0])},[ue,S,N,M,_e,oe,Ee]);a.useEffect(()=>{if(S){$e.current=null;return}if(!(le!=null&&le.sessionId)){$e.current=null;return}const de=`${le.tabKey}:${le.sessionId}`;if($e.current===de)return;$e.current=de;const ye=dt(le,st),ke=Math.max(Date.now(),ns(le),ye.lastUpdated||0);t(le.daemonId||le.ideId,"mark_session_seen",{sessionId:le.sessionId,seenAt:ke}).catch(()=>{})},[le,S,st,t]);const{requestedDesktopTabKey:Mt,requestedMobileTabKey:Sr,consumeRequestedActiveTab:Ws}=jo({isMobile:S,urlActiveTab:o,resolveConversationBySessionId:Ge,setSearchParams:i}),{remoteDialogConv:Os,remoteDialogIdeEntry:Cr,remoteDialogActiveConv:Ir,setRemoteDialogActiveConv:os,openRemoteDialog:Mr,closeRemoteDialog:Tr}=_o({isMobile:S,location:s,navigate:n,requestedRemoteTabTarget:c,requestedDesktopTabKey:Mt,conversations:_e,ides:x,resolveConversationByTarget:tt}),ve=Ir||Os||le,ze=!!ve&&Se(ve)&&!je(ve),Tt=a.useMemo(()=>{if(!ve||!ze)return null;const de=ve.daemonId||ve.ideId||"",ye=ve.agentType||ve.ideType||"";return`${de}:${ye}`},[ve,ze]),Ar=a.useMemo(()=>Ee,[Ee]),At=S&&E==="chat",Rr=a.useMemo(()=>_e.filter(de=>re.has(de.tabKey)),[_e,re]);fo({visibleConversations:Ee,clearedTabs:Y,setClearedTabs:ee,setActionLogs:H}),wo({ides:x,sendDaemonCommand:t,setToasts:p,setLocalUserMessages:X,resolveConversationByTarget:tt});const{isRefreshingHistory:_r,handleLaunchIde:Lr,handleRefreshHistory:Dr}=pn({sendDaemonCommand:t,activeConv:le,updateIdeChats:m,setToasts:p,setLocalUserMessages:X,setClearedTabs:ee}),{isCreatingChat:Er,isRefreshingHistory:$r,handleSwitchSession:Pr,handleNewChat:Br,handleRefreshHistory:Kr}=pn({sendDaemonCommand:t,activeConv:ve,updateIdeChats:m,setToasts:p,setLocalUserMessages:X,setClearedTabs:ee}),cs=a.useCallback(async()=>{if(!(!ve||!ze||ce)){ne(!0);try{const de=ve.daemonId||ve.ideId,ye=ve.agentType||ve.ideType,ke=await t(de,"list_saved_sessions",{agentType:ye,providerType:ye,kind:"cli",limit:50}),Ie=(ke==null?void 0:ke.result)??ke;q(Array.isArray(Ie==null?void 0:Ie.sessions)?Ie.sessions:[])}catch(de){console.error("Refresh saved sessions failed",de),q([])}finally{ne(!1)}}},[ve,ce,ze,t]);a.useEffect(()=>{if(!z){me.current=null;return}if(!ze){me.current=null,q([]),ne(!1);return}!Tt||ce||me.current!==Tt&&(me.current=Tt,cs())},[cs,z,ce,ze,Tt]);const Wr=a.useCallback(async de=>{if(!ve||!ze||!de.providerSessionId||!de.workspace)return;const ye=ve.daemonId||ve.ideId,ke=ve.agentType||ve.ideType;try{Q(de.providerSessionId);const Ie=await t(ye,"launch_cli",{cliType:ke,dir:de.workspace,resumeSessionId:de.providerSessionId,initialModel:de.currentModel}),Pe=(Ie==null?void 0:Ie.result)??Ie,qs=typeof(Pe==null?void 0:Pe.sessionId)=="string"?Pe.sessionId:typeof(Pe==null?void 0:Pe.id)=="string"?Pe.id:"";qs&&i(Jr=>{const Gs=new URLSearchParams(Jr);return Gs.set("activeTab",qs),Gs},{replace:!0}),D(!1)}catch(Ie){console.error("Resume saved session failed",Ie)}finally{Q(null)}},[ve,ze,t,i]);Ro({urlActiveTab:S&&!At?o:null,conversations:_e,resolveConversationBySessionId:Ge,normalizedGroupAssignments:U,hasHydratedStoredLayout:S&&!At?W:!0,hydrateStoredLayout:S&&!At?$:()=>{},setGroupActiveTabIds:P,setFocusedGroup:k,setSearchParams:i,historyModalOpen:z,activeConv:le,isRefreshingHistory:_r,ides:x,handleRefreshHistory:Dr});const Rt=a.useCallback(async de=>{if(!le||!Se(le)||je(le))return;const ye=le.ideType||le.agentType||"",ke=le.ideId||le.daemonId||"";try{await t(ke,"stop_cli",{cliType:ye,targetSessionId:le.sessionId,mode:de})}catch(Ie){console.error("Stop CLI failed:",Ie)}},[le,t]),Or=a.useCallback(async()=>{var ye;if(!le||!Se(le)||je(le))return;if((ye=le.resume)!=null&&ye.supported){O(!0);return}const de=le.ideType||le.agentType||"CLI";window.confirm(`Stop ${de}?
|
|
51
|
+
This will terminate the CLI process.`)&&await Rt("hard")},[le,Rt]),zr=a.useMemo(()=>!le||!Se(le)||je(le)?null:xt(le),[le]),Ur=a.useCallback(async de=>{if(!(!le||!Se(le)||je(le)||xt(le)===de))try{await t(le.daemonId||le.ideId,"set_cli_view_mode",{targetSessionId:le.sessionId,cliType:le.ideType||le.agentType,mode:de})}catch(ke){console.error("Failed to switch CLI view mode:",ke)}},[le,t]),{versionMismatchDaemons:Hr,appVersion:Fr,versionBannerDismissed:Vr,setVersionBannerDismissed:qr,upgradingDaemons:Gr,handleBannerUpgrade:Yr}=Bo({ides:x,sendDaemonCommand:t}),zs=a.useCallback(de=>{ae(de.tabKey),i(ye=>{const ke=new URLSearchParams(ye);return de.sessionId?ke.set("activeTab",de.sessionId):ke.delete("activeTab"),ke},{replace:!0})},[i]),Us=a.useCallback(de=>{Ce(de.tabKey),zs(de)},[zs,Ce]),Xr=a.useCallback(de=>{he(de.tabKey)},[he]);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(vi,{wsStatus:w,showReconnected:j}),e.jsx(ji,{terminalBackend:te,isStandalone:F,machineLabel:ie,machineKey:xe}),!Vr&&e.jsx(gc,{daemons:Hr,targetVersion:Fr,upgradingDaemons:Gr,onUpgrade:Yr,onDismiss:()=>qr(!0)}),e.jsx(dc,{showMobileChatMode:At,isMobile:S,activeConv:le,chatIdes:qe,wsStatus:w,isConnected:v,onOpenHistory:de=>{de&&os(de),D(!0)},onOpenRemote:Mr,onStopCli:Or,activeCliViewMode:zr,onSetActiveCliViewMode:Ur,mobileChatConversations:Ar,ides:x,actionLogs:G,sendDaemonCommand:t,setLocalUserMessages:X,setActionLogs:H,isStandalone:F,userName:f.userName,requestedMobileTabKey:Sr,onRequestedMobileTabConsumed:Ws,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:ft,isSplitMode:se,numGroups:V,groupSizes:B,groupedConvs:oe,clearedTabs:Y,focusedGroup:M,setFocusedGroup:k,moveTabToGroup:ge,splitTabRelative:pe,closeGroup:be,handleResizeStart:Ne,detectedIdes:R,handleLaunchIde:Lr,groupActiveTabIds:N,setGroupActiveTabIds:P,groupTabOrders:K,setGroupTabOrders:L,toggleHiddenTab:We,visibleConversations:Ee,hiddenConversations:Rr,requestedDesktopTabKey:Mt,onRequestedDesktopTabConsumed:Ws,onOpenAccount:F?void 0:()=>n("/account"),onDesktopActiveTabChange:ae,onHideConversation:Xr,onShowHiddenConversation:Us,onShowAllHiddenConversations:mt}),e.jsx("style",{children:`
|
|
52
52
|
body { overflow: hidden; overscroll-behavior: none; }
|
|
53
|
-
`}),e.jsx(
|
|
54
|
-
This will terminate the process.`))try{const A=await n(t,"stop_cli",{cliType:
|
|
55
|
-
This will disconnect CDP and optionally kill the process.`))try{const _=await n(
|
|
53
|
+
`}),e.jsx(hc,{historyModalOpen:z,historyTargetConv:ve,ides:x,isHistoryCreatingChat:Er,isHistoryRefreshingHistory:ze?!1:$r,savedHistorySessions:A,isSavedHistoryLoading:ce,isResumingSavedHistorySessionId:Z,onCloseHistory:()=>D(!1),onNewHistoryChat:Br,onSwitchHistorySession:Pr,onRefreshHistory:ze?cs:Kr,onResumeSavedHistorySession:Wr,remoteDialogConv:Os,remoteDialogIdeEntry:Cr,connectionStates:y,actionLogs:G,localUserMessages:C,sendDaemonCommand:t,setLocalUserMessages:X,setActionLogs:H,isStandalone:F,userName:f.userName,onOpenRemoteHistory:de=>{de&&os(de),D(!0)},onRemoteConversationChange:os,onCloseRemoteDialog:Tr,cliStopDialogOpen:_,activeConv:le,onCancelCliStop:()=>O(!1),onStopCliNow:async()=>{O(!1),await Rt("hard")},onSaveCliAndStop:async()=>{O(!1),await Rt("save")},toasts:b,onDismissToast:de=>p(ye=>ye.filter(ke=>ke.id!==de)),onClickToast:de=>{if(de.targetKey){const ye=tt(de.targetKey);ye&&(k(U.get(ye.tabKey)??0),Us(ye))}},showOnboarding:h,onCloseOnboarding:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}u(!1)}})]})}function yc({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:i}){const[o,c]=a.useState([]),[d,l]=a.useState(null),[f,x]=a.useState(null),[m,h]=a.useState(!1),[u,b]=a.useState(null),[p,w]=a.useState(!1),[v,y]=a.useState(""),j=a.useRef(null),I=a.useCallback(D=>{j.current=D},[]),g=a.useCallback((D,_,O=!1)=>{c(A=>[...A.slice(-100),{timestamp:Date.now(),level:D,message:_}]),setTimeout(()=>{var A;return(A=i.current)==null?void 0:A.scrollIntoView({behavior:"smooth"})},100),O&&Xe.showToast(_,D==="error"||D==="warn"?"warning":"success")},[i]),M=a.useCallback(async(D,_)=>{var O;if(!t||d)return!1;l(D),g("info",`Launching ${Te(D)}${_!=null&&_.workspace?` in ${_.workspace}`:""}...`);try{const A={ideType:D,enableCdp:!0};(O=_==null?void 0:_.workspace)!=null&&O.trim()?A.workspace=_.workspace.trim():_!=null&&_.useDefaultWorkspace&&(A.useDefaultWorkspace=!0);const q=await n(t,"launch_ide",A);return g(q!=null&&q.success?"info":"error",q!=null&&q.success?`${Te(D)} launched`:`Failed: ${q==null?void 0:q.error}`,!0),!!(q!=null&&q.success)}catch(A){return g("error",`Launch error: ${A.message}`,!0),!1}finally{l(null)}},[t,d,g,n]),k=a.useCallback(async D=>{if(!t)return{success:!1};const{cliType:_,dir:O,workspaceId:A,useDefaultWorkspace:q,useHome:ce,argsStr:ne,model:Z,resumeSessionId:Q}=D;if(!_)return g("warn","Select a CLI or ACP provider first",!0),{success:!1};const E=ne?ne.split(/\s+/).filter(Boolean):void 0,G=(O==null?void 0:O.trim())||(A?"(saved id)":q?"(default workspace)":ce?"(home)":"");g("info",`Launching ${_}${G?` in ${G}`:""}${Z?` (model: ${Z})`:""}...`),x(_);try{const H={cliType:_,cliArgs:E,initialModel:Z||void 0};O!=null&&O.trim()?H.dir=O.trim():A?H.workspaceId=A:q?H.useDefaultWorkspace=!0:ce&&(H.useHome=!0),Q&&(H.resumeSessionId=Q);const C=await n(t,"launch_cli",H),X=(C==null?void 0:C.result)||C;return C!=null&&C.success?(g("info",`${_} launched`,!0),(X==null?void 0:X.launchSource)==="home"?g("info","📂 Running in home directory (explicit choice)"):(X==null?void 0:X.launchSource)==="defaultWorkspace"&&g("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:X==null?void 0:X.sessionId}):(g("error",`Failed: ${(C==null?void 0:C.error)||(X==null?void 0:X.error)}`,!0),(C==null?void 0:C.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&b({cliType:_,argsStr:ne,model:Z}),{success:!1,sessionId:X==null?void 0:X.sessionId})}catch(H){return g("error",`Launch error: ${H.message}`,!0),{success:!1}}finally{x(null)}},[t,g,n]),N=a.useCallback(async(D,_,O,A)=>t?D?_.trim()?k({cliType:D,dir:_,argsStr:O,model:A}):(b({cliType:D,argsStr:O,model:A}),{success:!1}):(g("warn","Select a provider",!0),{success:!1}):{success:!1},[t,g,k]),P=a.useCallback(async(D,_,O)=>{if(t&&window.confirm(`Stop ${D}?
|
|
54
|
+
This will terminate the process.`))try{const A=await n(t,"stop_cli",{cliType:D,dir:_,targetSessionId:O});A!=null&&A.success?g("info",`${D} stopped`,!0):g("error",`Stop failed: ${(A==null?void 0:A.error)||"Unknown error"}`,!0)}catch(A){g("error",`Stop failed: ${A.message}`,!0)}},[t,g,n]),K=a.useCallback(async D=>{try{await n(D.daemonId,"restart_ide",{ideType:D.type}),g("info",`${Te(D.type)} restart initiated`,!0)}catch(_){g("error",`Restart failed: ${_.message}`,!0)}},[g,n]),L=a.useCallback(async D=>{if(window.confirm(`Stop ${Te(D.type)}?
|
|
55
|
+
This will disconnect CDP and optionally kill the process.`))try{const _=await n(D.daemonId,"stop_ide",{ideType:D.type,killProcess:!0});_!=null&&_.success?g("info",`${Te(D.type)} stopped`,!0):g("error",`Stop failed: ${(_==null?void 0:_.error)||"Unknown error"}`,!0)}catch(_){g("error",`Stop failed: ${_.message}`,!0)}},[g,n]),B=a.useCallback(async()=>{if(t)try{const D=await n(t,"detect_ides",{});g("info",`Found ${((D==null?void 0:D.result)||[]).length} IDE(s)`,!0)}catch(D){g("error",`Detection failed: ${D.message}`,!0)}},[t,g,n]),T=a.useCallback(async D=>{if(!(!t||!D.trim())){h(!0);try{const _=await n(t,"workspace_add",{path:D.trim()});_!=null&&_.success?g("info",`Workspace added: ${D.trim()}`):g("error",(_==null?void 0:_.error)||"workspace_add failed")}catch(_){g("error",_.message)}finally{h(!1)}return!0}},[t,g,n]),S=a.useCallback(async D=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){h(!0);try{const _=await n(t,"workspace_remove",{id:D});_!=null&&_.success?g("info","Workspace removed",!0):g("error",(_==null?void 0:_.error)||"workspace_remove failed",!0)}catch(_){g("error",_.message,!0)}finally{h(!1)}}},[t,g,n]),W=a.useCallback(async D=>{var _;if(t){h(!0);try{const O=await n(t,"workspace_set_default",D===null?{clear:!0}:{id:D});if(O!=null&&O.success){g("info",D?"Default workspace updated":"Default workspace cleared",!0);const A=typeof O.defaultWorkspacePath=="string"?O.defaultWorkspacePath:"";A&&((_=j.current)==null||_.call(j,A))}else g("error",(O==null?void 0:O.error)||"workspace_set_default failed",!0)}catch(O){g("error",O.message,!0)}finally{h(!1)}}},[t,g,n]),$=a.useCallback(async D=>{var O;if(!t||!D.trim())return;const _=D.trim();h(!0);try{const A=await n(t,"workspace_set_default",{path:_});A!=null&&A.success?(g("info","Default workspace set from history"),(O=j.current)==null||O.call(j,_)):g("error",(A==null?void 0:A.error)||"Could not set default (path missing on disk?)")}catch(A){g("error",A.message)}finally{h(!1)}},[t,g,n]),z=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(D){g("warn",`Live nickname updated, but account sync failed: ${D.message}`)}g("info",`Nickname set to "${v||"(cleared)"}"`),w(!1)}catch(D){g("error",`Failed: ${D.message}`)}},[t,v,s,g,r,n]);return{logs:o,launchingIde:d,launchingAgentType:f,workspaceBusy:m,launchPick:u,setLaunchPick:b,editingNickname:p,setEditingNickname:w,nicknameInput:v,setNicknameInput:y,addLog:g,handleLaunchIde:M,runLaunchCliCore:k,handleLaunchCli:N,handleStopCli:P,handleRestartIde:K,handleStopIde:L,handleDetectIdes:B,handleWorkspaceAdd:T,handleWorkspaceRemove:S,handleWorkspaceSetDefault:W,handleWorkspaceResumePath:$,handleSaveNickname:z,setOnDefaultWorkspaceChanged:I}}function vc({machine:t,ideSessions:s,cliSessions:n,acpSessions:r,actions:i}){const{workspaceBusy:o,handleWorkspaceAdd:c,handleWorkspaceRemove:d,handleWorkspaceSetDefault:l}=i,[f,x]=a.useState(""),m=t.availableMem??t.freeMem,h=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-m)/t.totalMem*100))):0,u=t.loadavg[0]||0;return e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-5",children:[e.jsx(_t,{icon:e.jsx(On,{size:16}),label:"Uptime",value:si(t.uptime)}),e.jsx(_t,{icon:e.jsx(De,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(_t,{icon:e.jsx(Ls,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(_t,{icon:e.jsx(Ta,{size:16}),label:"ACPs",value:`${r.length}`})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsx("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-3",children:"Resource Usage"}),e.jsxs("div",{className:"flex gap-6",children:[e.jsx(Qs,{value:Math.min(Math.round(u/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${u.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Qs,{value:h,max:100,label:"Memory",color:"#3b82f6",detail:`${sn(t.totalMem-m)} / ${sn(t.totalMem)}${t.platform==="darwin"?" (approx.)":""}`})]})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center gap-1.5 mb-3",children:[e.jsx(vs,{size:14})," Workspaces"]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center mb-3",children:[e.jsx("span",{className:"text-[10px] text-text-muted",children:"Default:"}),e.jsxs("select",{className:"text-xs bg-bg-primary border border-border-subtle rounded-lg px-2 py-1 max-w-[min(100%,420px)]",disabled:o,value:t.defaultWorkspaceId||"",onChange:b=>void l(b.target.value===""?null:b.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(b=>e.jsx("option",{value:b.id,children:b.label||b.path},b.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:f,disabled:o,onChange:b=>x(b.target.value),onKeyDown:b=>b.key==="Enter"&&void(async()=>{await c(f)&&x("")})()}),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:o,onClick:async()=>{await c(f)&&x("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1.5 max-h-40 overflow-y-auto",children:(t.workspaces||[]).map(b=>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:[b.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:Gn(b.path,b.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:b.path,children:b.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:o,onClick:()=>void d(b.id),children:"Remove"})]},b.id))})]})]})}const wn=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],jc=[{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 wc({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[i,o]=a.useState("config"),[c,d]=a.useState("codex-cli"),[l,f]=a.useState([]),[x,m]=a.useState(""),[h,u]=a.useState([]),[b,p]=a.useState(""),w=a.useRef(null),v=a.useRef(null),y=N=>{f(P=>P.includes(N)?P.filter(K=>K!==N):[...P,N])},j=()=>f([...wn]),I=()=>f([]);a.useEffect(()=>{var N;(N=w.current)==null||N.scrollIntoView({behavior:"smooth"})},[h]),a.useEffect(()=>()=>{v.current&&clearInterval(v.current)},[]);const g=a.useCallback(()=>{v.current&&clearInterval(v.current),v.current=setInterval(async()=>{try{const N=await n(t,"provider_auto_fix_status",{providerType:s.type});(N==null?void 0:N.running)===!1&&i==="running"&&(o("done"),u(P=>[...P,`
|
|
56
56
|
✅ Auto-fix completed!`]),v.current&&clearInterval(v.current))}catch{}},3e3)},[t,s.type,n,i]),M=async()=>{if(l.length!==0){o("running"),u(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${l.join(", ")}`,x?`💬 Comment: ${x}`:"",""]),p("");try{const N=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:c,...x?{comment:x}:{}});N!=null&&N.success&&(N!=null&&N.started||N!=null&&N.running)?(u(P=>[...P,"✅ Agent started. Monitoring progress..."]),g()):(o("error"),p((N==null?void 0:N.error)||"Failed to start auto-fix"))}catch(N){o("error"),p((N==null?void 0:N.message)||"Connection failed")}}},k=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),u(N=>[...N,`
|
|
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:N=>N.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:yc.map(N=>e.jsxs("button",{onClick:()=>d(N.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===N.value?N.color+"66":"var(--border-subtle)",background:c===N.value?N.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===N.value?N.color:"var(--text-primary)"},children:N.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:N.desc})]},N.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:j,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:I,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:jn.map(N=>e.jsxs("button",{onClick:()=>y(N),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(N)?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:l.includes(N)?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent",color:l.includes(N)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(N)?"☑ ":"☐ ",N]},N))})]}),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:x,onChange:N=>m(N.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((N,P)=>e.jsx("div",{className:N.startsWith("✅")?"text-green-400":"",style:N.startsWith("❌")||N.startsWith("⚠")?{color:"var(--status-warning)"}:void 0,children:N},P)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:w})]}),b&&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:b})]})]}),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:k,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"),u([]),p("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function jc({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:i}){var g;const o=s.filter(M=>M.category==="ide"),[c,d]=a.useState(((g=o[0])==null?void 0:g.type)||""),[l,f]=a.useState(""),[x,m]=a.useState(""),[h,u]=a.useState(!1),[b,p]=a.useState(""),[w,v]=a.useState(!1),y=M=>{const k=M.toLowerCase().replace(/[^a-z0-9-]/g,"");f(k),(!x||x===j(l))&&m(j(k))},j=M=>M.split("-").map(k=>k.charAt(0).toUpperCase()+k.slice(1)).join(" "),I=async()=>{if(!(!l||!x||!c)){u(!0),p("");try{const M=await n(t,"provider_clone",{type:l,name:x,category:"ide",location:"user",cloneFrom:c});M!=null&&M.success||M!=null&&M.created?(v(!0),i==null||i(l)):p((M==null?void 0:M.error)||"Failed to create provider")}catch(M){p((M==null?void 0:M.message)||"Connection failed")}u(!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:w?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:x,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"})]}),b&&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:b})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:w?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:I,disabled:!l||!x||h,className:"machine-btn",style:{background:l&&x?"rgba(34,197,94,0.12)":void 0,borderColor:l&&x?"rgba(34,197,94,0.3)":void 0,color:l&&x?"#86efac":void 0,opacity:!l||!x||h?.4:1},children:h?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function wc({machineId:t,providers:s,sendDaemonCommand:n}){const[r,i]=a.useState([]),[o,c]=a.useState(!1),[d,l]=a.useState(null),[f,x]=a.useState("all"),[m,h]=a.useState(null),[u,b]=a.useState(!1),p=a.useCallback(async()=>{var v;if(t){c(!0);try{const y=await n(t,"get_provider_settings",{}),j=(y==null?void 0:y.result)||y;if(y!=null&&y.success&&(j!=null&&j.settings)){const I=[];for(const[g,M]of Object.entries(j.settings)){const k=s.find(N=>N.type===g);I.push({type:g,displayName:(k==null?void 0:k.displayName)||g,icon:(k==null?void 0:k.icon)||"",category:(k==null?void 0:k.category)||"unknown",schema:M,values:((v=j.values)==null?void 0:v[g])||{}})}I.sort((g,M)=>g.category.localeCompare(M.category)||g.displayName.localeCompare(M.displayName)),i(I)}}catch{}c(!1)}},[t,s,n]);a.useEffect(()=>{r.length===0&&p()},[]);const w=async(v,y,j)=>{l(`${v}.${y}`),i(I=>I.map(g=>g.type===v?{...g,values:{...g.values,[y]:j}}:g));try{const I=await n(t,"set_provider_setting",{providerType:v,key:y,value:j});I!=null&&I.success||p()}catch{p()}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:()=>x(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:()=>b(!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:p,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),f!=="all"&&r.filter(v=>v.category===f).length>1&&(()=>{const v=r.filter(g=>g.category===f),y=new Map;for(const g of v)for(const M of g.schema){if(M.type!=="boolean")continue;const k=y.get(M.key),N=!!(g.values[M.key]??M.default);k?(k.onCount+=N?1:0,k.total+=1):y.set(M.key,{label:M.label||M.key,onCount:N?1:0,total:1})}const j=[...y.entries()].filter(([,g])=>g.total===v.length);if(j.length===0)return null;const I=async(g,M)=>{for(const k of v)await w(k.type,g,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:j.map(([g,M])=>{const k=M.onCount===M.total,N=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 I(g,!0),disabled:k,className:`machine-btn text-[9px] px-1.5 py-px ${k?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void I(g,!1),disabled:N,className:`machine-btn text-[9px] px-1.5 py-px ${N?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},g)})})]})})(),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:()=>w(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:j=>{const I=parseInt(j.target.value)||0;y.min!==void 0&&I<y.min||y.max!==void 0&&I>y.max||w(v.type,y.key,I)},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:j=>w(v.type,y.key,j.target.value),className:"machine-input text-[11px]",children:y.options.map(j=>e.jsx("option",{value:j,children:j},j))}):e.jsx("input",{type:"text",value:v.values[y.key]??y.default??"",onBlur:j=>w(v.type,y.key,j.target.value),className:"machine-input w-[120px] text-[11px]"})})]},y.key))})]},v.type))}),m&&e.jsx(vc,{machineId:t,provider:m,sendDaemonCommand:n,onClose:()=>h(null)}),u&&e.jsx(jc,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>b(!1),onCreated:()=>{b(!1),p()}})]})}function kc({machineId:t,sendDaemonCommand:s}){const[n,r]=a.useState([]),[i,o]=a.useState(0),[c,d]=a.useState(!0),[l,f]=a.useState("debug"),x=a.useRef(null),m=a.useRef(!1);return a.useEffect(()=>{if(!t||!c)return;const h=async()=>{try{const b=await s(t,"get_logs",{count:200,minLevel:l,since:i}),p=(b==null?void 0:b.result)||b;if(b!=null&&b.success&&Array.isArray(p==null?void 0:p.logs)&&p.logs.length>0){r(v=>[...v,...p.logs.map(j=>({timestamp:j.ts,level:j.level,message:`[${j.category}] ${j.message}`}))].slice(-300));const w=Math.max(...p.logs.map(v=>v.ts));o(w)}}catch{}};h();const u=setInterval(h,3e3);return()=>clearInterval(u)},[t,c,i,l,s]),a.useEffect(()=>{if(c&&n.length>0){const h=m.current?"smooth":"instant";setTimeout(()=>{var u;(u=x.current)==null||u.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,u)=>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})]},u)),e.jsx("div",{ref:x})]})]})}function Nc({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 wn({children:t}){return e.jsx("div",{className:"text-xs font-semibold text-text-muted mb-2 tracking-wide uppercase",children:t})}function Sc({machineEntry:t,providers:s,recentLaunches:n,onUpgradeDaemon:r,onOpenLogs:i,onOpenRecent:o,onOpenWorkspace:c,onGoTab:d}){const l=t.detectedIdes||[],f=s.filter(b=>b.category==="cli"),x=s.filter(b=>b.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,x.length>0?{id:"acp",kind:"acp",label:"ACP Workspace",desc:"Agent"}:null].filter(Boolean),u=b=>b==="ide"?"IDE":b==="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(wn,{children:"Recent Activity"}),e.jsx("div",{className:"flex flex-col gap-1.5",children:m.map(b=>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(b),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate w-full group-hover:text-accent-primary transition-colors",children:b.label}),e.jsxs("span",{className:"text-xs text-text-secondary truncate w-full opacity-80",children:[u(b.kind),b.subtitle?` · ${b.subtitle}`:""]})]},b.id))})]}),h.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(wn,{children:"New Workspace"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:h.map(b=>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(b.kind),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary text-center",children:b.label.replace(" Workspace","")}),e.jsx("span",{className:"text-[10px] text-text-muted text-center uppercase tracking-wide",children:b.desc})]},b.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 Cc(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const Ic={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 bs({category:t,machine:s,machineId:n,providers:r,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:d,initialWorkspaceId:l,initialWorkspacePath:f}){const x=mt(),{handleLaunchIde:m,handleLaunchCli:h,handleStopCli:u,handleRestartIde:b,handleStopIde:p,handleDetectIdes:w,launchingIde:v,launchingAgentType:y}=c,[j,I]=a.useState(null),g=a.useCallback(R=>{R&&x({pathname:"/",search:`?activeTab=${encodeURIComponent(R)}`})},[x]),M=Ic[t],k=t==="ide",N=t==="acp",P=r.filter(R=>R.category===t),K=new Map(P.map(R=>[R.type,R.displayName||R.type])),[L,B]=a.useState(""),[T,S]=a.useState(""),[W,$]=a.useState(""),[z,E]=a.useState(f?"__custom__":l||s.defaultWorkspaceId||""),[_,O]=a.useState(f||""),[A,q]=a.useState([]),ce=A.filter(R=>!i.some(V=>V.type===R&&_e(V.status)!=="stopped")),re=a.useRef({});a.useEffect(()=>{s.defaultWorkspaceId&&!z&&E(s.defaultWorkspaceId)},[s.defaultWorkspaceId]),a.useEffect(()=>{if(f){E("__custom__"),O(f);return}l&&(E(l),O(""))},[l,f]);const J=(()=>{if(z==="__custom__")return _.trim();if(!z)return"";const R=(s.workspaces||[]).find(V=>V.id===z);return(R==null?void 0:R.path)||""})(),Z=a.useCallback(R=>{const V=re.current[R];V&&(clearTimeout(V),delete re.current[R]),q(te=>te.filter(ae=>ae!==R))},[]),D=a.useCallback(R=>{if(!R)return;q(te=>te.includes(R)?te:[...te,R]);const V=re.current[R];V&&clearTimeout(V),re.current[R]=setTimeout(()=>{q(te=>te.filter(ae=>ae!==R)),delete re.current[R]},2e4)},[]);a.useEffect(()=>{for(const R of i)_e(R.status)!=="stopped"&&Z(R.type)},[i,Z]),a.useEffect(()=>()=>{Object.values(re.current).forEach(clearTimeout),re.current={}},[]);const[G,H]=a.useState({}),[C,X]=a.useState(null);a.useEffect(()=>{if(!k||!n||!d)return;(async()=>{try{const V=await d(n,"get_ide_extensions",{}),te=(V==null?void 0:V.result)||V;te!=null&&te.success&&(te!=null&&te.ideExtensions)&&H(te.ideExtensions)}catch{}})()},[k,n,d]);const Y=R=>k?Ie(R.type):t==="cli"?R.cliName:R.acpName,ee=k?s.detectedIdes||[]:[],xe=()=>{(async()=>{if(k){await m(L,J?{workspace:J}:void 0)&&D(L);return}const R=await h(L,J,T||void 0,N&&W||void 0);R.success&&(D(L),R.sessionId&&g(R.sessionId))})()},ie=R=>{k?p(R):u(R.type,R.workspace,R.id)},me=a.useCallback(async(R,V,te=!1)=>{if(R.mode===V){te&&R.sessionId&&g(R.sessionId);return}if(!d||!R.sessionId){te&&R.sessionId&&g(R.sessionId);return}try{await d(n,"set_cli_view_mode",{targetSessionId:R.sessionId,cliType:R.type,mode:V}),te&&g(R.sessionId)}catch(ae){console.error("Failed to switch CLI view mode:",ae)}},[n,g,d]),Q=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:z,onChange:R=>{E(R.target.value),R.target.value!=="__custom__"&&O("")},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(R=>e.jsxs("option",{value:R.id,children:[R.id===s.defaultWorkspaceId?"⭐ ":"",qn(R.path,R.label)]},R.id)),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]})}),z==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:_,onChange:R=>O(R.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:z==="__custom__"?J?e.jsx("span",{className:"font-mono truncate block",title:J,children:J}):"Enter an absolute path to launch there.":J?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:z===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:J,children:J})]}):"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 ${M.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 ",M.label," to Launch"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:k?ee.length>0?ee.map(R=>{const V=i.find(he=>(he.type||"").toLowerCase()===(R.type||"").toLowerCase()&&_e(he.status)!=="stopped"),te=R.running||!!V,ae=!!V&&V.cdpConnected,ue=A.includes(R.type||R.id||""),oe=L===(R.type||"");return e.jsxs("button",{onClick:()=>{if(ae&&V){const he=V.sessionId;he?x(`/dashboard?activeTab=${encodeURIComponent(he)}`,{state:{openRemoteForTabKey:he}}):x("/dashboard",{state:{openRemoteForTabKey:V.id}});return}ue||B(he=>he===(R.type||"")?"":R.type||"")},disabled:!!v||ue,className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${ae?"bg-green-500/10 border-green-500/20 hover:bg-green-500/20":oe?"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:v&&v!==R.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(R.type)}),te&&e.jsx("span",{className:`absolute -top-1 -right-1 w-2 h-2 rounded-full ${ae?"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:R.name||Ie(R.type)}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${ae?"text-green-400":ue?"text-orange-400":oe?"text-accent-primary":"text-text-muted"}`,children:ae?"Open Session":ue?"Starting...":oe?"Configure":"Select"})]})]},R.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:w,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(ka,{size:14})," Scan System"]})]}):P.length>0?P.map(R=>{const V=L===R.type,te=A.includes(R.type),ue=!!i.find(oe=>oe.type===R.type&&_e(oe.status)!=="stopped");return e.jsxs("button",{onClick:()=>B(oe=>oe===R.type?"":R.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:R.icon}),ue&&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:R.displayName}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${te?"text-orange-400":V?"text-accent-primary":"text-text-muted"}`,children:te?"Starting...":V?"Configure":"Select"})]})]},R.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"]})}),L&&(k?ee.find(R=>R.type===L):P.find(R=>R.type===L))&&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:k?Ie(L):K.get(L)||L})]}),Q,!k&&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:W,onChange:R=>$(R.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:T,onChange:R=>S(R.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:xe,disabled:!!y||!!v||A.includes(L),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:y===L||v===L?"⏳ Launching...":"▶ Launch"})})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length+A.filter(R=>!i.some(V=>V.type===R&&_e(V.status)!=="stopped")).length,")"]}),i.length===0&&ce.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 ",M.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[ce.map(R=>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(R)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:k?Ie(R):K.get(R)||R}),e.jsx("div",{className:"text-[11px] text-text-muted",children:y===R?"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:${R}`)),i.map(R=>{const V=k?R:null,te=N?R:null,ae=!k&&!N?R:null,ue=_e(R.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(R.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[Y(R),(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:R.workspace||"—"}),(te==null?void 0:te.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",te.currentModel]}),(te==null?void 0:te.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",te.currentPlan]}),(ae==null?void 0:ae.mode)&&e.jsx("span",{className:ae.mode==="chat"?"text-violet-400":"text-text-secondary",children:ae.mode==="chat"?"Chat view":"Terminal view"})]}),ae&&(ae.runtimeKey||ae.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[ae.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 ",ae.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 oe;(oe=navigator.clipboard)==null||oe.writeText(`adhdev attach ${ae.runtimeKey}`),I(ae.runtimeKey||null),window.setTimeout(()=>{I(he=>he===ae.runtimeKey?null:he)},1200)},children:j===ae.runtimeKey?"Copied":"Copy"})]}),ae.runtimeWriteOwner&&e.jsx("span",{style:{color:ae.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:ae.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:Cc(ae.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 ${ue==="stopped"?"bg-red-500/[0.08] text-red-500":ue==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:ue}),k&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{const oe=R.sessionId;if(oe){x(`/dashboard?activeTab=${encodeURIComponent(oe)}`,{state:{openRemoteForTabKey:oe}});return}x("/dashboard",{state:{openRemoteForTabKey:R.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(Le,{size:13})}),e.jsx("button",{onClick:()=>b(R),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(Rs,{size:14})})]}),N&&e.jsx("button",{onClick:()=>{const oe=R.sessionId;oe&&g(oe)},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:!R.sessionId,children:e.jsx(tt,{size:14})}),ae&&ue!=="stopped"&&e.jsxs(e.Fragment,{children:[ae.mode&&e.jsx(Ds,{mode:ae.mode,onChange:oe=>void me(ae,oe,!1),compact:!0}),e.jsx("button",{onClick:()=>{const oe=R.sessionId;oe&&g(oe)},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:!R.sessionId,children:ae.mode==="chat"?e.jsx(tt,{size:14}):e.jsx(Le,{size:13})})]}),ue==="stopped"?e.jsx("button",{onClick:()=>{(async()=>{if(k){await m(R.type,R.workspace?{workspace:R.workspace}:void 0)&&D(R.type);return}const oe=await h(R.type,R.workspace);oe.success&&(D(R.type),oe.sessionId&&g(oe.sessionId))})()},disabled:A.includes(R.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:A.includes(R.type)?"⏳":e.jsx(Ca,{size:14})}):e.jsx("button",{onClick:()=>ie(R),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(Vt,{size:14})})]})]}),V&&V.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:V.aiAgents.map(oe=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${Vn(oe.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[oe.name," · ",_e(oe.status)]},oe.id))}),V&&(G[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:(G[V.type]||[]).map(oe=>e.jsxs("button",{disabled:C===`${V.type}.${oe.type}`,onClick:async()=>{const he=`${V.type}.${oe.type}`;X(he);try{await d(n,"set_ide_extension",{ideType:V.type,extensionType:oe.type,enabled:!oe.enabled}),H(Pe=>({...Pe,[V.type]:(Pe[V.type]||[]).map(Me=>Me.type===oe.type?{...Me,enabled:!Me.enabled}:Me)}))}catch(Pe){console.error("Extension toggle failed:",Pe)}finally{X(null)}},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium border transition-colors duration-150 cursor-pointer ${oe.enabled?"bg-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 ${oe.enabled?"bg-accent-primary shadow-glow":"bg-zinc-600"}`}),oe.name,e.jsx("span",{className:"text-[9px] font-normal",children:oe.enabled?"ON":"OFF"})]},oe.type))})]})]},R.id)})]})]})}const kn=[{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 Mc({machine:t,machineId:s,providers:n,ideSessions:r,cliSessions:i,acpSessions:o,actions:c,getIcon:d,initialCategory:l="ide",initialWorkspaceId:f,initialWorkspacePath:x,sendDaemonCommand:m}){var p;const[h,u]=a.useState(l);a.useEffect(()=>{u(l)},[l]);const b=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:kn.map(w=>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===w.id?"bg-[#ffffff10] text-text-primary shadow-sm":"text-text-secondary hover:text-text-primary hover:bg-[#ffffff05]"}`,onClick:()=>u(w.id),children:[e.jsx("span",{children:w.label}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ${h===w.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:b[w.id]})]},w.id))}),e.jsx("div",{className:"text-xs text-text-muted italic",children:(p=kn.find(w=>w.id===h))==null?void 0:p.helper})]}),h==="ide"&&e.jsx(bs,{category:"ide",machine:t,machineId:s,providers:n,managedEntries:r,getIcon:d,actions:c,sendDaemonCommand:m,initialWorkspaceId:f,initialWorkspacePath:x}),h==="cli"&&e.jsx(bs,{category:"cli",machine:t,machineId:s,providers:n,managedEntries:i,getIcon:d,actions:c,initialWorkspaceId:f,initialWorkspacePath:x}),h==="acp"&&e.jsx(bs,{category:"acp",machine:t,machineId:s,providers:n,managedEntries:o,getIcon:d,actions:c,initialWorkspaceId:f,initialWorkspacePath:x})]})}function Tc({onNicknameSynced:t}={}){var A,q,ce,re,J,Z,D,G,H;const{id:s}=oa(),n=mt(),r=Ms(),{sendCommand:i}=st(),o=Es(),c=o.ides||[],d=o.initialLoaded??!0,l=c.find(C=>C.id===s&&C.daemonMode),f=c.some(C=>C.type==="adhdev-daemon"),[x,m]=a.useState("workspace"),[h,u]=a.useState("ide"),b=a.useRef(null),p=()=>{if(f){n("/dashboard",{state:{mobileSection:"machines"}});return}n("/machines")},w=gc({machineId:s,registeredMachineId:(l==null?void 0:l.machineId)||null,sendDaemonCommand:i,onNicknameSynced:t,logsEndRef:b});a.useEffect(()=>Qe.onToast(X=>{o.setToasts(ee=>{if(ee.some(me=>me.message===X.message&&X.timestamp-me.timestamp<3e3))return ee;const ie={id:X.id,message:X.message,type:X.type,timestamp:X.timestamp,targetKey:X.targetKey,actions:X.actions};return[...ee.slice(-4),ie]});const Y=X.duration||5e3;setTimeout(()=>o.setToasts(ee=>ee.filter(xe=>xe.id!==X.id)),Y)}),[o]);const v=(l==null?void 0:l.availableProviders)||[],y={};for(const C of v)y[C.type]=C.icon;const j=C=>y[C]||"",I=l?{id:l.id,hostname:Gn(l,{fallbackId:l.id}),platform:((A=l.machine)==null?void 0:A.platform)||"unknown",arch:((q=l.machine)==null?void 0:q.arch)||"",cpus:((ce=l.machine)==null?void 0:ce.cpus)||0,totalMem:((re=l.machine)==null?void 0:re.totalMem)||0,freeMem:((J=l.machine)==null?void 0:J.freeMem)||0,availableMem:(Z=l.machine)==null?void 0:Z.availableMem,loadavg:((D=l.machine)==null?void 0:D.loadavg)||[],uptime:((G=l.machine)==null?void 0:G.uptime)||0,release:((H=l.machine)==null?void 0:H.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,g=c.filter(C=>C.daemonId===s&&!C.daemonMode).filter(C=>!qt(C)&&!yt(C)).map(C=>({id:C.id,sessionId:C.sessionId,type:C.type,version:C.version||"",instanceId:C.instanceId||"",status:C.status,workspace:C.workspace||null,terminals:C.terminals||0,aiAgents:oi(C.aiAgents||C.agents||[]),activeChat:C.activeChat||null,chats:C.chats||[],childSessions:C.childSessions||[],cdpConnected:C.cdpConnected||!1,daemonId:s})),M=c.filter(C=>C.daemonId===s&&qt(C)).map(C=>({id:C.id,sessionId:C.sessionId,type:C.type,cliName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,providerSessionId:C.providerSessionId,mode:C.mode,daemonId:s})),k=c.filter(C=>C.daemonId===s&&yt(C)).map(C=>({id:C.id,sessionId:C.sessionId,type:C.type,acpName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,providerSessionId:C.providerSessionId,currentModel:C.currentModel,currentPlan:C.currentPlan,daemonId:s}));if(!I)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:p,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 N=qe(l,{fallbackId:I.id}),P="workspace",K=r.state,L=K==null?void 0:K.initialMachineTab,B=K==null?void 0:K.initialWorkspaceCategory,T=K==null?void 0:K.initialWorkspaceId,S=K==null?void 0:K.initialWorkspacePath,W=L==="ides"||L==="clis"||L==="acps"?"workspace":L||P,$=L==="ides"?"ide":L==="clis"?"cli":L==="acps"?"acp":B,z=[...g.map(C=>{var X,Y,ee,xe,ie;return{id:`ide:${C.type}:${C.workspace||""}`,label:((X=C.activeChat)==null?void 0:X.title)||C.type,kind:"ide",providerType:C.type,subtitle:C.workspace||void 0,workspace:C.workspace||void 0,timestamp:((ie=(xe=(ee=(Y=C.activeChat)==null?void 0:Y.messages)==null?void 0:ee.at)==null?void 0:xe.call(ee,-1))==null?void 0:ie.timestamp)||0}}),...M.map(C=>{var X,Y,ee,xe,ie;return{id:`cli:${C.type}:${C.workspace||""}`,label:((X=C.activeChat)==null?void 0:X.title)||C.cliName,kind:"cli",providerType:C.type,providerSessionId:C.providerSessionId,subtitle:C.workspace||void 0,workspace:C.workspace||void 0,timestamp:((ie=(xe=(ee=(Y=C.activeChat)==null?void 0:Y.messages)==null?void 0:ee.at)==null?void 0:xe.call(ee,-1))==null?void 0:ie.timestamp)||0}}),...k.map(C=>{var X,Y,ee,xe,ie;return{id:`acp:${C.type}:${C.workspace||""}`,label:((X=C.activeChat)==null?void 0:X.title)||C.acpName,kind:"acp",providerType:C.type,providerSessionId:C.providerSessionId,subtitle:C.currentModel||C.workspace||void 0,workspace:C.workspace||void 0,currentModel:C.currentModel,timestamp:((ie=(xe=(ee=(Y=C.activeChat)==null?void 0:Y.messages)==null?void 0:ee.at)==null?void 0:xe.call(ee,-1))==null?void 0:ie.timestamp)||0}})].sort((C,X)=>X.timestamp-C.timestamp).map(({timestamp:C,...X})=>X),E=(l.recentLaunches||[]).length>0?l.recentLaunches.map(C=>({id:C.id,label:C.title||C.providerName||C.providerType,kind:C.kind,providerType:C.providerType,providerSessionId:C.providerSessionId,subtitle:C.currentModel||C.workspace||void 0,workspace:C.workspace,currentModel:C.currentModel})):z,_=async C=>{if(C.kind==="ide"&&C.providerType){await w.handleLaunchIde(C.providerType,C.workspace?{workspace:C.workspace}:void 0);return}if((C.kind==="cli"||C.kind==="acp")&&C.providerType){await w.runLaunchCliCore({cliType:C.providerType,dir:C.workspace||"",model:C.kind==="acp"?C.currentModel:void 0,resumeSessionId:C.providerSessionId});return}u(C.kind),m("workspace")};a.useEffect(()=>{m(W)},[P,W,I.id]),a.useEffect(()=>{$&&u($)},[$,I.id]);const O=[{id:"workspace",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{size:14})," Workspace"]}),count:g.length+M.length+k.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(es,{size:14})," Providers"]})},{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Sa,{size:14})," System"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(wa,{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:p,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:[w.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:w.nicknameInput,onChange:C=>w.setNicknameInput(C.target.value),onKeyDown:C=>{C.key==="Enter"&&w.handleSaveNickname(),C.key==="Escape"&&w.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:w.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:()=>w.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:()=>{w.setEditingNickname(!0),w.setNicknameInput(I.machineNickname||"")},title:"Click to set nickname",children:N}),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:[I.platform," · ",I.arch]}),e.jsxs("span",{children:[I.cpus," cores"]}),(l==null?void 0:l.version)&&e.jsxs("span",{children:["v",l.version]}),I.p2p.available&&e.jsxs("span",{children:["P2P ",I.p2p.state==="connected"?"connected":I.p2p.state]}),I.cdpConnected&&e.jsx("span",{className:"text-green-400 px-1.5 py-0.5 bg-green-400/10 rounded",children:"CDP ready"}),I.machineNickname&&e.jsx("span",{className:"text-text-muted opacity-60 shrink-0",children:I.hostname})]})]})]})}),e.jsx("div",{className:"flex overflow-x-auto overflow-y-hidden mt-4 gap-6 px-1 border-b border-[#ffffff0a]",children:O.map(C=>e.jsxs("button",{onClick:()=>m(C.id),className:`pb-3 text-sm font-medium border-b-2 transition-colors flex items-center gap-2 px-1 whitespace-nowrap ${x===C.id?"border-accent-primary text-accent-primary":"border-transparent text-text-secondary hover:text-text-primary"}`,children:[C.label,C.count!==void 0&&e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ml-1 ${x===C.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:C.count})]},C.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:[x==="workspace"&&e.jsxs("div",{className:"flex flex-col md:flex-row gap-6 md:gap-10 h-full",children:[e.jsx(Sc,{machineEntry:l,providers:v,recentLaunches:E,onUpgradeDaemon:async()=>{try{await i(s,"daemon_upgrade",{})}catch{}},onOpenLogs:()=>m("logs"),onOpenRecent:_,onOpenWorkspace:C=>{u(C),m("workspace")},onGoTab:m}),e.jsx(Mc,{machine:I,machineId:s,providers:v,ideSessions:g,cliSessions:M,acpSessions:k,actions:w,getIcon:j,initialCategory:h,initialWorkspaceId:T,initialWorkspacePath:S,sendDaemonCommand:i})]}),x==="providers"&&e.jsx(wc,{machineId:s,providers:v,sendDaemonCommand:i}),x==="overview"&&e.jsx(bc,{machine:I,ideSessions:g,cliSessions:M,acpSessions:k,actions:w}),x==="logs"&&e.jsx(kc,{machineId:s,sendDaemonCommand:i})]})})}),w.launchPick&&I&&e.jsx(Nc,{machine:I,launchPick:w.launchPick,actions:w}),e.jsx(Qn,{toasts:o.toasts||[],onDismiss:C=>o.setToasts(X=>X.filter(Y=>Y.id!==C)),onClickToast:C=>{C.targetKey}}),e.jsx("style",{children:`
|
|
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:N=>N.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:jc.map(N=>e.jsxs("button",{onClick:()=>d(N.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===N.value?N.color+"66":"var(--border-subtle)",background:c===N.value?N.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===N.value?N.color:"var(--text-primary)"},children:N.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:N.desc})]},N.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:j,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:I,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:wn.map(N=>e.jsxs("button",{onClick:()=>y(N),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(N)?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:l.includes(N)?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent",color:l.includes(N)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(N)?"☑ ":"☐ ",N]},N))})]}),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:x,onChange:N=>m(N.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((N,P)=>e.jsx("div",{className:N.startsWith("✅")?"text-green-400":"",style:N.startsWith("❌")||N.startsWith("⚠")?{color:"var(--status-warning)"}:void 0,children:N},P)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:w})]}),b&&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:b})]})]}),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:k,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"),u([]),p("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function kc({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:i}){var g;const o=s.filter(M=>M.category==="ide"),[c,d]=a.useState(((g=o[0])==null?void 0:g.type)||""),[l,f]=a.useState(""),[x,m]=a.useState(""),[h,u]=a.useState(!1),[b,p]=a.useState(""),[w,v]=a.useState(!1),y=M=>{const k=M.toLowerCase().replace(/[^a-z0-9-]/g,"");f(k),(!x||x===j(l))&&m(j(k))},j=M=>M.split("-").map(k=>k.charAt(0).toUpperCase()+k.slice(1)).join(" "),I=async()=>{if(!(!l||!x||!c)){u(!0),p("");try{const M=await n(t,"provider_clone",{type:l,name:x,category:"ide",location:"user",cloneFrom:c});M!=null&&M.success||M!=null&&M.created?(v(!0),i==null||i(l)):p((M==null?void 0:M.error)||"Failed to create provider")}catch(M){p((M==null?void 0:M.message)||"Connection failed")}u(!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:w?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:x,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"})]}),b&&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:b})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:w?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:I,disabled:!l||!x||h,className:"machine-btn",style:{background:l&&x?"rgba(34,197,94,0.12)":void 0,borderColor:l&&x?"rgba(34,197,94,0.3)":void 0,color:l&&x?"#86efac":void 0,opacity:!l||!x||h?.4:1},children:h?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function Nc({machineId:t,providers:s,sendDaemonCommand:n}){const[r,i]=a.useState([]),[o,c]=a.useState(!1),[d,l]=a.useState(null),[f,x]=a.useState("all"),[m,h]=a.useState(null),[u,b]=a.useState(!1),p=a.useCallback(async()=>{var v;if(t){c(!0);try{const y=await n(t,"get_provider_settings",{}),j=(y==null?void 0:y.result)||y;if(y!=null&&y.success&&(j!=null&&j.settings)){const I=[];for(const[g,M]of Object.entries(j.settings)){const k=s.find(N=>N.type===g);I.push({type:g,displayName:(k==null?void 0:k.displayName)||g,icon:(k==null?void 0:k.icon)||"",category:(k==null?void 0:k.category)||"unknown",schema:M,values:((v=j.values)==null?void 0:v[g])||{}})}I.sort((g,M)=>g.category.localeCompare(M.category)||g.displayName.localeCompare(M.displayName)),i(I)}}catch{}c(!1)}},[t,s,n]);a.useEffect(()=>{r.length===0&&p()},[]);const w=async(v,y,j)=>{l(`${v}.${y}`),i(I=>I.map(g=>g.type===v?{...g,values:{...g.values,[y]:j}}:g));try{const I=await n(t,"set_provider_setting",{providerType:v,key:y,value:j});I!=null&&I.success||p()}catch{p()}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:()=>x(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:()=>b(!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:p,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),f!=="all"&&r.filter(v=>v.category===f).length>1&&(()=>{const v=r.filter(g=>g.category===f),y=new Map;for(const g of v)for(const M of g.schema){if(M.type!=="boolean")continue;const k=y.get(M.key),N=!!(g.values[M.key]??M.default);k?(k.onCount+=N?1:0,k.total+=1):y.set(M.key,{label:M.label||M.key,onCount:N?1:0,total:1})}const j=[...y.entries()].filter(([,g])=>g.total===v.length);if(j.length===0)return null;const I=async(g,M)=>{for(const k of v)await w(k.type,g,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:j.map(([g,M])=>{const k=M.onCount===M.total,N=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 I(g,!0),disabled:k,className:`machine-btn text-[9px] px-1.5 py-px ${k?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void I(g,!1),disabled:N,className:`machine-btn text-[9px] px-1.5 py-px ${N?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},g)})})]})})(),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:()=>w(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:j=>{const I=parseInt(j.target.value)||0;y.min!==void 0&&I<y.min||y.max!==void 0&&I>y.max||w(v.type,y.key,I)},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:j=>w(v.type,y.key,j.target.value),className:"machine-input text-[11px]",children:y.options.map(j=>e.jsx("option",{value:j,children:j},j))}):e.jsx("input",{type:"text",value:v.values[y.key]??y.default??"",onBlur:j=>w(v.type,y.key,j.target.value),className:"machine-input w-[120px] text-[11px]"})})]},y.key))})]},v.type))}),m&&e.jsx(wc,{machineId:t,provider:m,sendDaemonCommand:n,onClose:()=>h(null)}),u&&e.jsx(kc,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>b(!1),onCreated:()=>{b(!1),p()}})]})}function Sc({machineId:t,sendDaemonCommand:s}){const[n,r]=a.useState([]),[i,o]=a.useState(0),[c,d]=a.useState(!0),[l,f]=a.useState("debug"),x=a.useRef(null),m=a.useRef(!1);return a.useEffect(()=>{if(!t||!c)return;const h=async()=>{try{const b=await s(t,"get_logs",{count:200,minLevel:l,since:i}),p=(b==null?void 0:b.result)||b;if(b!=null&&b.success&&Array.isArray(p==null?void 0:p.logs)&&p.logs.length>0){r(v=>[...v,...p.logs.map(j=>({timestamp:j.ts,level:j.level,message:`[${j.category}] ${j.message}`}))].slice(-300));const w=Math.max(...p.logs.map(v=>v.ts));o(w)}}catch{}};h();const u=setInterval(h,3e3);return()=>clearInterval(u)},[t,c,i,l,s]),a.useEffect(()=>{if(c&&n.length>0){const h=m.current?"smooth":"instant";setTimeout(()=>{var u;(u=x.current)==null||u.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,u)=>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})]},u)),e.jsx("div",{ref:x})]})]})}function Cc({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 kn({children:t}){return e.jsx("div",{className:"text-xs font-semibold text-text-muted mb-2 tracking-wide uppercase",children:t})}function Ic({machineEntry:t,providers:s,recentLaunches:n,onUpgradeDaemon:r,onOpenLogs:i,onOpenRecent:o,onOpenWorkspace:c,onGoTab:d}){const l=t.detectedIdes||[],f=s.filter(b=>b.category==="cli"),x=s.filter(b=>b.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,x.length>0?{id:"acp",kind:"acp",label:"ACP Workspace",desc:"Agent"}:null].filter(Boolean),u=b=>b==="ide"?"IDE":b==="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(kn,{children:"Recent Activity"}),e.jsx("div",{className:"flex flex-col gap-1.5",children:m.map(b=>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(b),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate w-full group-hover:text-accent-primary transition-colors",children:b.label}),e.jsxs("span",{className:"text-xs text-text-secondary truncate w-full opacity-80",children:[u(b.kind),b.subtitle?` · ${b.subtitle}`:""]})]},b.id))})]}),h.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(kn,{children:"New Workspace"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:h.map(b=>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(b.kind),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary text-center",children:b.label.replace(" Workspace","")}),e.jsx("span",{className:"text-[10px] text-text-muted text-center uppercase tracking-wide",children:b.desc})]},b.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 Mc(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const Tc={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 bs({category:t,machine:s,machineId:n,providers:r,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:d,initialWorkspaceId:l,initialWorkspacePath:f}){const x=pt(),{handleLaunchIde:m,handleLaunchCli:h,handleStopCli:u,handleRestartIde:b,handleStopIde:p,handleDetectIdes:w,launchingIde:v,launchingAgentType:y}=c,[j,I]=a.useState(null),g=a.useCallback(R=>{R&&x({pathname:"/",search:`?activeTab=${encodeURIComponent(R)}`})},[x]),M=Tc[t],k=t==="ide",N=t==="acp",P=r.filter(R=>R.category===t),K=new Map(P.map(R=>[R.type,R.displayName||R.type])),[L,B]=a.useState(""),[T,S]=a.useState(""),[W,$]=a.useState(""),[z,D]=a.useState(f?"__custom__":l||s.defaultWorkspaceId||""),[_,O]=a.useState(f||""),[A,q]=a.useState([]),ce=A.filter(R=>!i.some(F=>F.type===R&&Le(F.status)!=="stopped")),ne=a.useRef({});a.useEffect(()=>{s.defaultWorkspaceId&&!z&&D(s.defaultWorkspaceId)},[s.defaultWorkspaceId]),a.useEffect(()=>{if(f){D("__custom__"),O(f);return}l&&(D(l),O(""))},[l,f]);const Z=(()=>{if(z==="__custom__")return _.trim();if(!z)return"";const R=(s.workspaces||[]).find(F=>F.id===z);return(R==null?void 0:R.path)||""})(),Q=a.useCallback(R=>{const F=ne.current[R];F&&(clearTimeout(F),delete ne.current[R]),q(te=>te.filter(ie=>ie!==R))},[]),E=a.useCallback(R=>{if(!R)return;q(te=>te.includes(R)?te:[...te,R]);const F=ne.current[R];F&&clearTimeout(F),ne.current[R]=setTimeout(()=>{q(te=>te.filter(ie=>ie!==R)),delete ne.current[R]},2e4)},[]);a.useEffect(()=>{for(const R of i)Le(R.status)!=="stopped"&&Q(R.type)},[i,Q]),a.useEffect(()=>()=>{Object.values(ne.current).forEach(clearTimeout),ne.current={}},[]);const[G,H]=a.useState({}),[C,X]=a.useState(null);a.useEffect(()=>{if(!k||!n||!d)return;(async()=>{try{const F=await d(n,"get_ide_extensions",{}),te=(F==null?void 0:F.result)||F;te!=null&&te.success&&(te!=null&&te.ideExtensions)&&H(te.ideExtensions)}catch{}})()},[k,n,d]);const Y=R=>k?Te(R.type):t==="cli"?R.cliName:R.acpName,ee=k?s.detectedIdes||[]:[],ue=()=>{(async()=>{if(k){await m(L,Z?{workspace:Z}:void 0)&&E(L);return}const R=await h(L,Z,T||void 0,N&&W||void 0);R.success&&(E(L),R.sessionId&&g(R.sessionId))})()},ae=R=>{k?p(R):u(R.type,R.workspace,R.id)},me=a.useCallback(async(R,F,te=!1)=>{if(R.mode===F){te&&R.sessionId&&g(R.sessionId);return}if(!d||!R.sessionId){te&&R.sessionId&&g(R.sessionId);return}try{await d(n,"set_cli_view_mode",{targetSessionId:R.sessionId,cliType:R.type,mode:F}),te&&g(R.sessionId)}catch(ie){console.error("Failed to switch CLI view mode:",ie)}},[n,g,d]),J=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:z,onChange:R=>{D(R.target.value),R.target.value!=="__custom__"&&O("")},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(R=>e.jsxs("option",{value:R.id,children:[R.id===s.defaultWorkspaceId?"⭐ ":"",Gn(R.path,R.label)]},R.id)),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]})}),z==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:_,onChange:R=>O(R.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:z==="__custom__"?Z?e.jsx("span",{className:"font-mono truncate block",title:Z,children:Z}):"Enter an absolute path to launch there.":Z?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:z===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:Z,children:Z})]}):"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 ${M.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 ",M.label," to Launch"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:k?ee.length>0?ee.map(R=>{const F=i.find(he=>(he.type||"").toLowerCase()===(R.type||"").toLowerCase()&&Le(he.status)!=="stopped"),te=R.running||!!F,ie=!!F&&F.cdpConnected,xe=A.includes(R.type||R.id||""),re=L===(R.type||"");return e.jsxs("button",{onClick:()=>{if(ie&&F){const he=F.sessionId;he?x(`/dashboard?activeTab=${encodeURIComponent(he)}`,{state:{openRemoteForTabKey:he}}):x("/dashboard",{state:{openRemoteForTabKey:F.id}});return}xe||B(he=>he===(R.type||"")?"":R.type||"")},disabled:!!v||xe,className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${ie?"bg-green-500/10 border-green-500/20 hover:bg-green-500/20":re?"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:v&&v!==R.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(R.type)}),te&&e.jsx("span",{className:`absolute -top-1 -right-1 w-2 h-2 rounded-full ${ie?"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:R.name||Te(R.type)}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${ie?"text-green-400":xe?"text-orange-400":re?"text-accent-primary":"text-text-muted"}`,children:ie?"Open Session":xe?"Starting...":re?"Configure":"Select"})]})]},R.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:w,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(Sa,{size:14})," Scan System"]})]}):P.length>0?P.map(R=>{const F=L===R.type,te=A.includes(R.type),xe=!!i.find(re=>re.type===R.type&&Le(re.status)!=="stopped");return e.jsxs("button",{onClick:()=>B(re=>re===R.type?"":R.type),className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${F?"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:R.icon}),xe&&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:R.displayName}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${te?"text-orange-400":F?"text-accent-primary":"text-text-muted"}`,children:te?"Starting...":F?"Configure":"Select"})]})]},R.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"]})}),L&&(k?ee.find(R=>R.type===L):P.find(R=>R.type===L))&&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:k?Te(L):K.get(L)||L})]}),J,!k&&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:W,onChange:R=>$(R.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:T,onChange:R=>S(R.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:ue,disabled:!!y||!!v||A.includes(L),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:y===L||v===L?"⏳ Launching...":"▶ Launch"})})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length+A.filter(R=>!i.some(F=>F.type===R&&Le(F.status)!=="stopped")).length,")"]}),i.length===0&&ce.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 ",M.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[ce.map(R=>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(R)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:k?Te(R):K.get(R)||R}),e.jsx("div",{className:"text-[11px] text-text-muted",children:y===R?"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:${R}`)),i.map(R=>{const F=k?R:null,te=N?R:null,ie=!k&&!N?R:null,xe=Le(R.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(R.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[Y(R),(F==null?void 0:F.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",F.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:R.workspace||"—"}),(te==null?void 0:te.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",te.currentModel]}),(te==null?void 0:te.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",te.currentPlan]}),(ie==null?void 0:ie.mode)&&e.jsx("span",{className:ie.mode==="chat"?"text-violet-400":"text-text-secondary",children:ie.mode==="chat"?"Chat view":"Terminal view"})]}),ie&&(ie.runtimeKey||ie.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[ie.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 ",ie.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 re;(re=navigator.clipboard)==null||re.writeText(`adhdev attach ${ie.runtimeKey}`),I(ie.runtimeKey||null),window.setTimeout(()=>{I(he=>he===ie.runtimeKey?null:he)},1200)},children:j===ie.runtimeKey?"Copied":"Copy"})]}),ie.runtimeWriteOwner&&e.jsx("span",{style:{color:ie.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:ie.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:Mc(ie.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 ${xe==="stopped"?"bg-red-500/[0.08] text-red-500":xe==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:xe}),k&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{const re=R.sessionId;if(re){x(`/dashboard?activeTab=${encodeURIComponent(re)}`,{state:{openRemoteForTabKey:re}});return}x("/dashboard",{state:{openRemoteForTabKey:R.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(De,{size:13})}),e.jsx("button",{onClick:()=>b(R),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(Rs,{size:14})})]}),N&&e.jsx("button",{onClick:()=>{const re=R.sessionId;re&&g(re)},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:!R.sessionId,children:e.jsx(Ze,{size:14})}),ie&&xe!=="stopped"&&e.jsxs(e.Fragment,{children:[ie.mode&&e.jsx(Es,{mode:ie.mode,onChange:re=>void me(ie,re,!1),compact:!0}),e.jsx("button",{onClick:()=>{const re=R.sessionId;re&&g(re)},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:!R.sessionId,children:ie.mode==="chat"?e.jsx(Ze,{size:14}):e.jsx(De,{size:13})})]}),xe==="stopped"?e.jsx("button",{onClick:()=>{(async()=>{if(k){await m(R.type,R.workspace?{workspace:R.workspace}:void 0)&&E(R.type);return}const re=await h(R.type,R.workspace);re.success&&(E(R.type),re.sessionId&&g(re.sessionId))})()},disabled:A.includes(R.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:A.includes(R.type)?"⏳":e.jsx(Ma,{size:14})}):e.jsx("button",{onClick:()=>ae(R),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(Vt,{size:14})})]})]}),F&&F.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:F.aiAgents.map(re=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${qn(re.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[re.name," · ",Le(re.status)]},re.id))}),F&&(G[F.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:(G[F.type]||[]).map(re=>e.jsxs("button",{disabled:C===`${F.type}.${re.type}`,onClick:async()=>{const he=`${F.type}.${re.type}`;X(he);try{await d(n,"set_ide_extension",{ideType:F.type,extensionType:re.type,enabled:!re.enabled}),H(We=>({...We,[F.type]:(We[F.type]||[]).map(Ce=>Ce.type===re.type?{...Ce,enabled:!Ce.enabled}:Ce)}))}catch(We){console.error("Extension toggle failed:",We)}finally{X(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 ${re.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 ${re.enabled?"bg-accent-primary shadow-glow":"bg-zinc-600"}`}),re.name,e.jsx("span",{className:"text-[9px] font-normal",children:re.enabled?"ON":"OFF"})]},re.type))})]})]},R.id)})]})]})}const Nn=[{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 Ac({machine:t,machineId:s,providers:n,ideSessions:r,cliSessions:i,acpSessions:o,actions:c,getIcon:d,initialCategory:l="ide",initialWorkspaceId:f,initialWorkspacePath:x,sendDaemonCommand:m}){var p;const[h,u]=a.useState(l);a.useEffect(()=>{u(l)},[l]);const b=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:Nn.map(w=>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===w.id?"bg-[#ffffff10] text-text-primary shadow-sm":"text-text-secondary hover:text-text-primary hover:bg-[#ffffff05]"}`,onClick:()=>u(w.id),children:[e.jsx("span",{children:w.label}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ${h===w.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:b[w.id]})]},w.id))}),e.jsx("div",{className:"text-xs text-text-muted italic",children:(p=Nn.find(w=>w.id===h))==null?void 0:p.helper})]}),h==="ide"&&e.jsx(bs,{category:"ide",machine:t,machineId:s,providers:n,managedEntries:r,getIcon:d,actions:c,sendDaemonCommand:m,initialWorkspaceId:f,initialWorkspacePath:x}),h==="cli"&&e.jsx(bs,{category:"cli",machine:t,machineId:s,providers:n,managedEntries:i,getIcon:d,actions:c,initialWorkspaceId:f,initialWorkspacePath:x}),h==="acp"&&e.jsx(bs,{category:"acp",machine:t,machineId:s,providers:n,managedEntries:o,getIcon:d,actions:c,initialWorkspaceId:f,initialWorkspacePath:x})]})}function Rc({onNicknameSynced:t}={}){var A,q,ce,ne,Z,Q,E,G,H;const{id:s}=la(),n=pt(),r=Ms(),{sendCommand:i}=Qe(),o=Ds(),c=o.ides||[],d=o.initialLoaded??!0,l=c.find(C=>C.id===s&&C.daemonMode),f=c.some(C=>C.type==="adhdev-daemon"),[x,m]=a.useState("workspace"),[h,u]=a.useState("ide"),b=a.useRef(null),p=()=>{if(f){n("/dashboard",{state:{mobileSection:"machines"}});return}n("/machines")},w=yc({machineId:s,registeredMachineId:(l==null?void 0:l.machineId)||null,sendDaemonCommand:i,onNicknameSynced:t,logsEndRef:b});a.useEffect(()=>Xe.onToast(X=>{o.setToasts(ee=>{if(ee.some(me=>me.message===X.message&&X.timestamp-me.timestamp<3e3))return ee;const ae={id:X.id,message:X.message,type:X.type,timestamp:X.timestamp,targetKey:X.targetKey,actions:X.actions};return[...ee.slice(-4),ae]});const Y=X.duration||5e3;setTimeout(()=>o.setToasts(ee=>ee.filter(ue=>ue.id!==X.id)),Y)}),[o]);const v=(l==null?void 0:l.availableProviders)||[],y={};for(const C of v)y[C.type]=C.icon;const j=C=>y[C]||"",I=l?{id:l.id,hostname:Yn(l,{fallbackId:l.id}),platform:((A=l.machine)==null?void 0:A.platform)||"unknown",arch:((q=l.machine)==null?void 0:q.arch)||"",cpus:((ce=l.machine)==null?void 0:ce.cpus)||0,totalMem:((ne=l.machine)==null?void 0:ne.totalMem)||0,freeMem:((Z=l.machine)==null?void 0:Z.freeMem)||0,availableMem:(Q=l.machine)==null?void 0:Q.availableMem,loadavg:((E=l.machine)==null?void 0:E.loadavg)||[],uptime:((G=l.machine)==null?void 0:G.uptime)||0,release:((H=l.machine)==null?void 0:H.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,g=c.filter(C=>C.daemonId===s&&!C.daemonMode).filter(C=>!qt(C)&&!yt(C)).map(C=>({id:C.id,sessionId:C.sessionId,type:C.type,version:C.version||"",instanceId:C.instanceId||"",status:C.status,workspace:C.workspace||null,terminals:C.terminals||0,aiAgents:li(C.aiAgents||C.agents||[]),activeChat:C.activeChat||null,chats:C.chats||[],childSessions:C.childSessions||[],cdpConnected:C.cdpConnected||!1,daemonId:s})),M=c.filter(C=>C.daemonId===s&&qt(C)).map(C=>({id:C.id,sessionId:C.sessionId,type:C.type,cliName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,providerSessionId:C.providerSessionId,mode:C.mode,daemonId:s})),k=c.filter(C=>C.daemonId===s&&yt(C)).map(C=>({id:C.id,sessionId:C.sessionId,type:C.type,acpName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,providerSessionId:C.providerSessionId,currentModel:C.currentModel,currentPlan:C.currentPlan,daemonId:s}));if(!I)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:p,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 N=He(l,{fallbackId:I.id}),P="workspace",K=r.state,L=K==null?void 0:K.initialMachineTab,B=K==null?void 0:K.initialWorkspaceCategory,T=K==null?void 0:K.initialWorkspaceId,S=K==null?void 0:K.initialWorkspacePath,W=L==="ides"||L==="clis"||L==="acps"?"workspace":L||P,$=L==="ides"?"ide":L==="clis"?"cli":L==="acps"?"acp":B,z=[...g.map(C=>{var X,Y,ee,ue,ae;return{id:`ide:${C.type}:${C.workspace||""}`,label:((X=C.activeChat)==null?void 0:X.title)||C.type,kind:"ide",providerType:C.type,subtitle:C.workspace||void 0,workspace:C.workspace||void 0,timestamp:((ae=(ue=(ee=(Y=C.activeChat)==null?void 0:Y.messages)==null?void 0:ee.at)==null?void 0:ue.call(ee,-1))==null?void 0:ae.timestamp)||0}}),...M.map(C=>{var X,Y,ee,ue,ae;return{id:`cli:${C.type}:${C.workspace||""}`,label:((X=C.activeChat)==null?void 0:X.title)||C.cliName,kind:"cli",providerType:C.type,providerSessionId:C.providerSessionId,subtitle:C.workspace||void 0,workspace:C.workspace||void 0,timestamp:((ae=(ue=(ee=(Y=C.activeChat)==null?void 0:Y.messages)==null?void 0:ee.at)==null?void 0:ue.call(ee,-1))==null?void 0:ae.timestamp)||0}}),...k.map(C=>{var X,Y,ee,ue,ae;return{id:`acp:${C.type}:${C.workspace||""}`,label:((X=C.activeChat)==null?void 0:X.title)||C.acpName,kind:"acp",providerType:C.type,providerSessionId:C.providerSessionId,subtitle:C.currentModel||C.workspace||void 0,workspace:C.workspace||void 0,currentModel:C.currentModel,timestamp:((ae=(ue=(ee=(Y=C.activeChat)==null?void 0:Y.messages)==null?void 0:ee.at)==null?void 0:ue.call(ee,-1))==null?void 0:ae.timestamp)||0}})].sort((C,X)=>X.timestamp-C.timestamp).map(({timestamp:C,...X})=>X),D=(l.recentLaunches||[]).length>0?l.recentLaunches.map(C=>({id:C.id,label:C.title||C.providerName||C.providerType,kind:C.kind,providerType:C.providerType,providerSessionId:C.providerSessionId,subtitle:C.currentModel||C.workspace||void 0,workspace:C.workspace,currentModel:C.currentModel})):z,_=async C=>{if(C.kind==="ide"&&C.providerType){await w.handleLaunchIde(C.providerType,C.workspace?{workspace:C.workspace}:void 0);return}if((C.kind==="cli"||C.kind==="acp")&&C.providerType){await w.runLaunchCliCore({cliType:C.providerType,dir:C.workspace||"",model:C.kind==="acp"?C.currentModel:void 0,resumeSessionId:C.providerSessionId});return}u(C.kind),m("workspace")};a.useEffect(()=>{m(W)},[P,W,I.id]),a.useEffect(()=>{$&&u($)},[$,I.id]);const O=[{id:"workspace",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(De,{size:14})," Workspace"]}),count:g.length+M.length+k.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(es,{size:14})," Providers"]})},{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ia,{size:14})," System"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Na,{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:p,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:[w.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:w.nicknameInput,onChange:C=>w.setNicknameInput(C.target.value),onKeyDown:C=>{C.key==="Enter"&&w.handleSaveNickname(),C.key==="Escape"&&w.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:w.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:()=>w.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:()=>{w.setEditingNickname(!0),w.setNicknameInput(I.machineNickname||"")},title:"Click to set nickname",children:N}),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:[I.platform," · ",I.arch]}),e.jsxs("span",{children:[I.cpus," cores"]}),(l==null?void 0:l.version)&&e.jsxs("span",{children:["v",l.version]}),I.p2p.available&&e.jsxs("span",{children:["P2P ",I.p2p.state==="connected"?"connected":I.p2p.state]}),I.cdpConnected&&e.jsx("span",{className:"text-green-400 px-1.5 py-0.5 bg-green-400/10 rounded",children:"CDP ready"}),I.machineNickname&&e.jsx("span",{className:"text-text-muted opacity-60 shrink-0",children:I.hostname})]})]})]})}),e.jsx("div",{className:"flex overflow-x-auto overflow-y-hidden mt-4 gap-6 px-1 border-b border-[#ffffff0a]",children:O.map(C=>e.jsxs("button",{onClick:()=>m(C.id),className:`pb-3 text-sm font-medium border-b-2 transition-colors flex items-center gap-2 px-1 whitespace-nowrap ${x===C.id?"border-accent-primary text-accent-primary":"border-transparent text-text-secondary hover:text-text-primary"}`,children:[C.label,C.count!==void 0&&e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ml-1 ${x===C.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:C.count})]},C.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:[x==="workspace"&&e.jsxs("div",{className:"flex flex-col md:flex-row gap-6 md:gap-10 h-full",children:[e.jsx(Ic,{machineEntry:l,providers:v,recentLaunches:D,onUpgradeDaemon:async()=>{try{await i(s,"daemon_upgrade",{})}catch{}},onOpenLogs:()=>m("logs"),onOpenRecent:_,onOpenWorkspace:C=>{u(C),m("workspace")},onGoTab:m}),e.jsx(Ac,{machine:I,machineId:s,providers:v,ideSessions:g,cliSessions:M,acpSessions:k,actions:w,getIcon:j,initialCategory:h,initialWorkspaceId:T,initialWorkspacePath:S,sendDaemonCommand:i})]}),x==="providers"&&e.jsx(Nc,{machineId:s,providers:v,sendDaemonCommand:i}),x==="overview"&&e.jsx(vc,{machine:I,ideSessions:g,cliSessions:M,acpSessions:k,actions:w}),x==="logs"&&e.jsx(Sc,{machineId:s,sendDaemonCommand:i})]})})}),w.launchPick&&I&&e.jsx(Cc,{machine:I,launchPick:w.launchPick,actions:w}),e.jsx(er,{toasts:o.toasts||[],onDismiss:C=>o.setToasts(X=>X.filter(Y=>Y.id!==C)),onClickToast:C=>{C.targetKey}}),e.jsx("style",{children:`
|
|
58
58
|
@keyframes toast-in {
|
|
59
59
|
from { opacity: 0; transform: translateX(40px); }
|
|
60
60
|
to { opacity: 1; transform: translateX(0); }
|
|
61
61
|
}
|
|
62
|
-
`})]})}function Ac(){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=[],x=[];Object.values(c.providers||{}).forEach(h=>{const u={name:h.name||"Unknown",status:h.status||"Stable",details:h.details||"Community Provider"};h.category==="ide"?d.push(u):h.category==="cli"?l.push(u):h.category==="extension"?f.push(u):h.category==="acp"&&x.push(u)});const m=(h,u)=>{const b={Stable:1,Beta:2,WIP:3},p=b[h.status]||99,w=b[u.status]||99;return p!==w?p-w:h.name.localeCompare(u.name)};s({ide:d.sort(m),cli:l.sort(m),ext:f.sort(m),acp:x.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(Bn,{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(_s,{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(Wn,{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(Yt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Ft,{}),widthClassName:"max-w-5xl",children:e.jsx($s,{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(Yt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Ft,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(Ae,{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(Ae,{title:"IDE support",icon:e.jsx(Le,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(Ae,{title:"Standalone CLI agents",icon:e.jsx(Ls,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(Ae,{title:"AI extensions",icon:e.jsx(xt,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(Ae,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(xt,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class Rc{constructor(){Ce(this,"adapters",new Map);Ce(this,"states",new Map);Ce(this,"runtimeListeners",new Map);Ce(this,"screenshotCallbacks",new Map);Ce(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const n of this.adapters.keys())if(n.startsWith("standalone"))return n}return null}register(s,n){this.adapters.set(s,n),this.states.set(s,n.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,n){this.states.set(s,n)}retryConnection(s){}get(s){const n=this.resolveDaemonId(s);return n?this.adapters.get(n):void 0}getState(s){const n=this.resolveDaemonId(s);return n&&this.states.get(n)||"disconnected"}sendData(s,n){return!1}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,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 Fe=new Rc;function _c(){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 Nn=_c(),Sn=3e3,Lc=3e4;let Ve=null,Ec=0;const Qt=new Map;let rt=null,kt=null;function Cn(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function Dc(t){return t==="connected"?"connected":t}async function Ht(t,s,n){const r=Ti(t,n||{}),i=Ve;if(i&&i.readyState===WebSocket.OPEN){const o=`req_${++Ec}_${Date.now()}`;return new Promise((c,d)=>{const l=setTimeout(()=>{Qt.delete(o),d(new Error(`WS command timeout: ${s}`))},3e4);Qt.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 $c{constructor(s){Ce(this,"daemonId");Ce(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Ve==null?void 0:Ve.readyState)===WebSocket.OPEN}get connectionState(){return(Ve==null?void 0:Ve.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return Ht(this.daemonId,s,n)}async sendInput(s,n){return Ht(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,rt&&(clearInterval(rt),rt=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await Ht(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());Fe.emitScreenshot(this.daemonId,i)}}catch{}};n(),rt=setInterval(n,2e3)}stopScreenshots(s){rt&&(clearInterval(rt),rt=null)}}let $e=null;function Pc(t){return(!$e||$e.daemonId!==t)&&($e=new $c(t)),$e}function Bc({children:t}){const s=a.useRef(Ys()),n=Ys();s.current=n;const{setUserName:r}=Nt(),i=a.useRef(r);i.current=r;const[,o]=a.useState("disconnected"),c=a.useCallback((h,u)=>{o(h),kt==null||kt(h,u)},[]),d=a.useRef(null),l=a.useRef(),f=a.useRef(Sn),x=a.useRef(!0),m=a.useRef(!1);return a.useEffect(()=>{x.current=!0,m.current=!1;function h(){var p,w;if(!x.current||((p=d.current)==null?void 0:p.readyState)===WebSocket.OPEN||((w=d.current)==null?void 0:w.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${Nn}...`);let b;try{b=new WebSocket(Nn)}catch(v){console.error("[Standalone WS] Failed to create WebSocket:",v),u();return}d.current=b,b.onopen=()=>{if(!x.current){b.close();return}c("connected"),f.current=Sn,console.log("[Standalone WS] Connected")},Ve=b,b.onmessage=v=>{var y;try{const j=JSON.parse(v.data);if((j.type==="command_result"||j.type==="error")&&j.requestId){const I=Qt.get(j.requestId);I&&(Qt.delete(j.requestId),j.type==="error"?I.reject(new Error(((y=j.data)==null?void 0:y.message)||"Command failed")):I.resolve(j.data));return}if(j.type==="session_output"){const I=j.sessionId||j.cliId||j.cliType;I&&Fe.emitSessionOutput(I,typeof j.data=="string"?j.data:"",typeof j.seq=="number"?j.seq:void 0);return}if(j.type==="runtime_snapshot"){Fe.emitRuntimeSnapshot(j.sessionId,typeof j.text=="string"?j.text:"",typeof j.seq=="number"?j.seq:0,!!j.truncated);return}if(j.type==="status"||j.type==="initial_state"){const I=j.data;if(!I)return;const{injectEntries:g,markLoaded:M}=s.current,k=I.id||"standalone",N=Pc(k);Fe.register(k,N),Fe.setState(k,"connected"),c("connected",k),Fe.emitStatus(k,I);const P=Ii(I,{daemonId:k});Cn("ws_status",{type:j.type,daemonId:k,sessions:(I.sessions||[]).map(K=>({id:K.id,parentId:K.parentId,providerType:K.providerType,kind:K.kind,transport:K.transport,unread:K.unread,inboxBucket:K.inboxBucket,lastSeenAt:K.lastSeenAt,lastUpdated:K.lastUpdated,title:K.title})),recentLaunches:(I.recentLaunches||[]).map(K=>({id:K.id,providerType:K.providerType,kind:K.kind,workspace:K.workspace,lastLaunchedAt:K.lastLaunchedAt}))}),Cn("entries",{daemonId:k,entries:P.filter(K=>K.type!=="adhdev-daemon").map(K=>({id:K.id,type:K.type,unread:K.unread,inboxBucket:K.inboxBucket,lastSeenAt:K.lastSeenAt,lastUpdated:K.lastUpdated,sessionId:K.sessionId}))}),P.length>0&&g(P,{authoritativeDaemonIds:[k]}),M(),I.userName&&i.current&&i.current(I.userName)}}catch(j){console.error("[Standalone WS] Parse error:",j)}},b.onclose=()=>{x.current&&($e==null||$e.stopScreenshots(),$e&&Fe.setState($e.daemonId,"disconnected"),c("disconnected"),d.current=null,u())},b.onerror=v=>{m.current||!x.current||console.warn("[Standalone WS] Error, will reconnect:",v)}}function u(){if(!x.current)return;clearTimeout(l.current);const b=f.current;console.log(`[Standalone WS] Reconnecting in ${b}ms...`),l.current=setTimeout(()=>{f.current=Math.min(f.current*1.5,Lc),h()},b)}return h(),()=>{x.current=!1,m.current=!0,clearTimeout(l.current),d.current&&(d.current.onerror=null,d.current.onclose=null,d.current.close(),d.current=null,Ve=null),$e&&($e.stopScreenshots(),Fe.unregister($e.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function Kc({children:t}){const[s,n]=a.useState("disconnected"),[r,i]=a.useState(null);a.useEffect(()=>(kt=(c,d)=>{n(c),d&&i(d)},()=>{kt=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",d=Dc(s),l={};return r&&(l[r]=d),l.standalone=d,{wsStatus:s,isConnected:c,connectionStates:l}},[s,r]);return e.jsx(ma,{connectionOverrides:o,children:e.jsx(Bc,{children:t})})}const Wc=[{id:"dashboard",path:"/dashboard",icon:e.jsx(En,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Ts,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(es,{}),label:"Settings"}];function Oc({children:t}){const s=mt(),n=Ms(),[r,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),d=x=>{s(x),i(!1)},l=()=>{c(x=>{const m=!x;try{localStorage.setItem("sidebar-collapsed",m?"1":"0")}catch{}return m})},f=x=>`nav-item${n.pathname.startsWith(x)?" 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:x=>x.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:Wc.map(x=>e.jsxs("div",{className:f(x.path),id:`nav-${x.id}`,onClick:()=>d(x.path),title:o?x.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:x.icon}),!o&&x.label]},x.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(Ft,{})}),!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(Pn,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.0"]}),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 zc=[{icon:e.jsx(Ts,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(tt,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Kn,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Le,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(xt,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Ft,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Uc=[{icon:e.jsx(On,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(En,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(ts,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(ja,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(va,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Bn,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Hc=[{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 Fc(){return e.jsxs(Yt,{icon:e.jsx(Pn,{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.0"]}),children:[e.jsx(Ae,{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(Ae,{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:zc.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(Ae,{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:nr.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:ar.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:rr.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(Ae,{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:Uc.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(Ae,{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:Hc.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($s,{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(La,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Vc(){const{ides:t}=Nt(),s=t.find(m=>m.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=st(),{userName:i}=Nt(),[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}}),x=m=>{f(m);try{localStorage.setItem("adhdev_sound",m?"1":"0")}catch{}};return e.jsxs(Yt,{icon:e.jsx(es,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(Hi,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(Ae,{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.0"]}),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(Ae,{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(Ae,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Ji,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(Ae,{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(to,{})]}),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(oo,{})]}),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(lo,{})]})]})}),e.jsx(Ae,{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(Xi,{}),e.jsx(et,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_a,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:x})]})}),e.jsx(Ae,{title:"Profile",description:"How your name appears in local chat threads and dashboard views.",children:e.jsx("div",{className:"flex flex-col gap-3",children:e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-4 bg-bg-glass rounded-xl border border-border-subtle hover:border-border-default transition-colors",children:[e.jsxs("div",{className:"flex flex-col gap-1 pr-4 max-w-[500px]",children:[e.jsxs("span",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx($n,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:o,onChange:m=>c(m.target.value),onBlur:d,onKeyDown:m=>{m.key==="Enter"&&m.currentTarget.blur()}})]})})})]})}Yi();ao();const qc=_n({baseUrl:""});function In(){const{ides:t,initialLoaded:s}=Nt();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(ys,{to:`/machines/${n.id}`,replace:!0}):e.jsx(ys,{to:"/dashboard",replace:!0})}function Gc(){return e.jsx(ca,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(ga,{client:qc,children:e.jsx(Kc,{children:e.jsx(ya,{value:{sendCommand:Ht,sendData:()=>!1},children:e.jsx(Oc,{children:e.jsxs(la,{children:[e.jsx(Ze,{path:"/dashboard",element:e.jsx(hc,{})}),e.jsx(Ze,{path:"/machine",element:e.jsx(In,{})}),e.jsx(Ze,{path:"/machines/:id",element:e.jsx(Tc,{})}),e.jsx(Ze,{path:"/machines",element:e.jsx(In,{})}),e.jsx(Ze,{path:"/capabilities",element:e.jsx(Ac,{})}),e.jsx(Ze,{path:"/about",element:e.jsx(Fc,{})}),e.jsx(Ze,{path:"/settings",element:e.jsx(Vc,{})}),e.jsx(Ze,{path:"*",element:e.jsx(ys,{to:"/dashboard",replace:!0})})]})})})})})})}hi({connectionManager:Fe});da(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Gc,{})}));
|
|
62
|
+
`})]})}function _c(){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=[],x=[];Object.values(c.providers||{}).forEach(h=>{const u={name:h.name||"Unknown",status:h.status||"Stable",details:h.details||"Community Provider"};h.category==="ide"?d.push(u):h.category==="cli"?l.push(u):h.category==="extension"?f.push(u):h.category==="acp"&&x.push(u)});const m=(h,u)=>{const b={Stable:1,Beta:2,WIP:3},p=b[h.status]||99,w=b[u.status]||99;return p!==w?p-w:h.name.localeCompare(u.name)};s({ide:d.sort(m),cli:l.sort(m),ext:f.sort(m),acp:x.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(Kn,{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(_s,{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(On,{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(Yt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Ft,{}),widthClassName:"max-w-5xl",children:e.jsx($s,{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(Yt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Ft,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(Re,{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(Re,{title:"IDE support",icon:e.jsx(De,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(Re,{title:"Standalone CLI agents",icon:e.jsx(Ls,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(Re,{title:"AI extensions",icon:e.jsx(ut,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(Re,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(ut,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class Lc{constructor(){Me(this,"adapters",new Map);Me(this,"states",new Map);Me(this,"runtimeListeners",new Map);Me(this,"screenshotCallbacks",new Map);Me(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 Fe=new Lc;function Dc(){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 Sn=Dc(),Cn=3e3,Ec=3e4;let Ve=null,$c=0;const Qt=new Map;let rt=null,kt=null;function In(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function Pc(t){return t==="connected"?"connected":t}async function Ht(t,s,n){const r=Ri(t,n||{}),i=Ve;if(i&&i.readyState===WebSocket.OPEN){const o=`req_${++$c}_${Date.now()}`;return new Promise((c,d)=>{const l=setTimeout(()=>{Qt.delete(o),d(new Error(`WS command timeout: ${s}`))},3e4);Qt.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 Bc{constructor(s){Me(this,"daemonId");Me(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Ve==null?void 0:Ve.readyState)===WebSocket.OPEN}get connectionState(){return(Ve==null?void 0:Ve.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return Ht(this.daemonId,s,n)}async sendInput(s,n){return Ht(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,rt&&(clearInterval(rt),rt=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await Ht(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());Fe.emitScreenshot(this.daemonId,i)}}catch{}};n(),rt=setInterval(n,2e3)}stopScreenshots(s){rt&&(clearInterval(rt),rt=null)}}let Ke=null;function Kc(t){return(!Ke||Ke.daemonId!==t)&&(Ke=new Bc(t)),Ke}function Wc({children:t}){const s=a.useRef(Xs()),n=Xs();s.current=n;const{setUserName:r}=Nt(),i=a.useRef(r);i.current=r;const[,o]=a.useState("disconnected"),c=a.useCallback((h,u)=>{o(h),kt==null||kt(h,u)},[]),d=a.useRef(null),l=a.useRef(),f=a.useRef(Cn),x=a.useRef(!0),m=a.useRef(!1);return a.useEffect(()=>{x.current=!0,m.current=!1;function h(){var p,w;if(!x.current||((p=d.current)==null?void 0:p.readyState)===WebSocket.OPEN||((w=d.current)==null?void 0:w.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${Sn}...`);let b;try{b=new WebSocket(Sn)}catch(v){console.error("[Standalone WS] Failed to create WebSocket:",v),u();return}d.current=b,b.onopen=()=>{if(!x.current){b.close();return}c("connected"),f.current=Cn,console.log("[Standalone WS] Connected")},Ve=b,b.onmessage=v=>{var y;try{const j=JSON.parse(v.data);if((j.type==="command_result"||j.type==="error")&&j.requestId){const I=Qt.get(j.requestId);I&&(Qt.delete(j.requestId),j.type==="error"?I.reject(new Error(((y=j.data)==null?void 0:y.message)||"Command failed")):I.resolve(j.data));return}if(j.type==="session_output"){const I=j.sessionId||j.cliId||j.cliType;I&&Fe.emitSessionOutput(I,typeof j.data=="string"?j.data:"",typeof j.seq=="number"?j.seq:void 0);return}if(j.type==="runtime_snapshot"){Fe.emitRuntimeSnapshot(j.sessionId,typeof j.text=="string"?j.text:"",typeof j.seq=="number"?j.seq:0,!!j.truncated);return}if(j.type==="status"||j.type==="initial_state"){const I=j.data;if(!I)return;const{injectEntries:g,markLoaded:M}=s.current,k=I.id||"standalone",N=Kc(k);Fe.register(k,N),Fe.setState(k,"connected"),c("connected",k),Fe.emitStatus(k,I);const P=Ti(I,{daemonId:k});In("ws_status",{type:j.type,daemonId:k,sessions:(I.sessions||[]).map(K=>({id:K.id,parentId:K.parentId,providerType:K.providerType,kind:K.kind,transport:K.transport,unread:K.unread,inboxBucket:K.inboxBucket,lastSeenAt:K.lastSeenAt,lastUpdated:K.lastUpdated,title:K.title})),recentLaunches:(I.recentLaunches||[]).map(K=>({id:K.id,providerType:K.providerType,kind:K.kind,workspace:K.workspace,lastLaunchedAt:K.lastLaunchedAt}))}),In("entries",{daemonId:k,entries:P.filter(K=>K.type!=="adhdev-daemon").map(K=>({id:K.id,type:K.type,unread:K.unread,inboxBucket:K.inboxBucket,lastSeenAt:K.lastSeenAt,lastUpdated:K.lastUpdated,sessionId:K.sessionId}))}),P.length>0&&g(P,{authoritativeDaemonIds:[k]}),M(),I.userName&&i.current&&i.current(I.userName)}}catch(j){console.error("[Standalone WS] Parse error:",j)}},b.onclose=()=>{x.current&&(Ke==null||Ke.stopScreenshots(),Ke&&Fe.setState(Ke.daemonId,"disconnected"),c("disconnected"),d.current=null,u())},b.onerror=v=>{m.current||!x.current||console.warn("[Standalone WS] Error, will reconnect:",v)}}function u(){if(!x.current)return;clearTimeout(l.current);const b=f.current;console.log(`[Standalone WS] Reconnecting in ${b}ms...`),l.current=setTimeout(()=>{f.current=Math.min(f.current*1.5,Ec),h()},b)}return h(),()=>{x.current=!1,m.current=!0,clearTimeout(l.current),d.current&&(d.current.onerror=null,d.current.onclose=null,d.current.close(),d.current=null,Ve=null),Ke&&(Ke.stopScreenshots(),Fe.unregister(Ke.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function Oc({children:t}){const[s,n]=a.useState("disconnected"),[r,i]=a.useState(null);a.useEffect(()=>(kt=(c,d)=>{n(c),d&&i(d)},()=>{kt=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",d=Pc(s),l={};return r&&(l[r]=d),l.standalone=d,{wsStatus:s,isConnected:c,connectionStates:l}},[s,r]);return e.jsx(ha,{connectionOverrides:o,children:e.jsx(Wc,{children:t})})}const zc=[{id:"dashboard",path:"/dashboard",icon:e.jsx(En,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Ts,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(es,{}),label:"Settings"}];function Uc({children:t}){const s=pt(),n=Ms(),[r,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),d=x=>{s(x),i(!1)},l=()=>{c(x=>{const m=!x;try{localStorage.setItem("sidebar-collapsed",m?"1":"0")}catch{}return m})},f=x=>`nav-item${n.pathname.startsWith(x)?" 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:x=>x.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:zc.map(x=>e.jsxs("div",{className:f(x.path),id:`nav-${x.id}`,onClick:()=>d(x.path),title:o?x.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:x.icon}),!o&&x.label]},x.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(Ft,{})}),!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(Bn,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.1"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,title:o?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:o?"›":"‹"}),!o&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})]})]}),e.jsx("main",{className:"main-content relative",children:e.jsx("div",{className:"main-content-inner",children:t})})]})}const Hc=[{icon:e.jsx(Ts,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(Ze,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Wn,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(De,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(ut,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Ft,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Fc=[{icon:e.jsx(zn,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(En,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(ts,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(ka,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(wa,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Kn,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Vc=[{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(Yt,{icon:e.jsx(Bn,{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.1"]}),children:[e.jsx(Re,{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(Re,{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:Hc.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(Re,{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:rr.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:ir.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:ar.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(Re,{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:Fc.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(Re,{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:Vc.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($s,{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(Ea,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Gc(){const{ides:t}=Nt(),s=t.find(m=>m.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=Qe(),{userName:i}=Nt(),[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}}),x=m=>{f(m);try{localStorage.setItem("adhdev_sound",m?"1":"0")}catch{}};return e.jsxs(Yt,{icon:e.jsx(es,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(Vi,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(Re,{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.1"]}),e.jsx("span",{className:"text-text-muted",children:"Status"}),e.jsx("span",{className:s?"text-green-400":"text-yellow-400",children:s?"● Running":"○ Not connected"}),e.jsx("span",{className:"text-text-muted",children:"WebSocket"}),e.jsx("span",{className:"font-mono text-xs",children:"ws://localhost:19222"}),e.jsx("span",{className:"text-text-muted",children:"HTTP"}),e.jsx("span",{className:"font-mono text-xs",children:"http://localhost:19280"})]})}),e.jsx(Re,{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(Re,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Qi,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(Re,{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(no,{})]}),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(lo,{})]}),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(xo,{})]})]})}),e.jsx(Re,{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(Zi,{}),e.jsx(Je,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Da,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:x})]})}),e.jsx(Re,{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(Pn,{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()}})]})})})]})}Ji();oo();const Yc=Ln({baseUrl:""});function Mn(){const{ides:t,initialLoaded:s}=Nt();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(ys,{to:`/machines/${n.id}`,replace:!0}):e.jsx(ys,{to:"/dashboard",replace:!0})}function Xc(){return e.jsx(da,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(ya,{client:Yc,children:e.jsx(Oc,{children:e.jsx(ja,{value:{sendCommand:Ht,sendData:()=>!1},children:e.jsx(Uc,{children:e.jsxs(ua,{children:[e.jsx(Ye,{path:"/dashboard",element:e.jsx(bc,{})}),e.jsx(Ye,{path:"/machine",element:e.jsx(Mn,{})}),e.jsx(Ye,{path:"/machines/:id",element:e.jsx(Rc,{})}),e.jsx(Ye,{path:"/machines",element:e.jsx(Mn,{})}),e.jsx(Ye,{path:"/capabilities",element:e.jsx(_c,{})}),e.jsx(Ye,{path:"/about",element:e.jsx(qc,{})}),e.jsx(Ye,{path:"/settings",element:e.jsx(Gc,{})}),e.jsx(Ye,{path:"*",element:e.jsx(ys,{to:"/dashboard",replace:!0})})]})})})})})})}bi({connectionManager:Fe});xa(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Xc,{})}));
|