@adhdev/daemon-standalone 0.7.45 → 0.7.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +40772 -29747
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/index-B7gMWsoX.js +68 -0
- package/public/assets/index-DiWCXoGV.css +1 -0
- package/public/assets/terminal-PD6SznsC.js +13 -0
- package/public/index.html +3 -3
- package/vendor/session-host-daemon/index.js +29 -7
- package/vendor/session-host-daemon/index.js.map +1 -1
- package/vendor/session-host-daemon/index.mjs +29 -7
- package/vendor/session-host-daemon/index.mjs.map +1 -1
- package/public/assets/index-DO9uKh_p.css +0 -1
- package/public/assets/index-DyZAxHxl.js +0 -70
- package/public/assets/terminal-D6QYasuF.js +0 -13
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-D6QYasuF.js","assets/vendor-CPghmr9Y.js","assets/terminal-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
var kr=Object.defineProperty;var Nr=(t,s,n)=>s in t?kr(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var je=(t,s,n)=>Nr(t,typeof s!="symbol"?s+"":s,n);import{r as a,j as e,M as nn,a as rn,b as Sr,c as Cr,u as tt,t as Ir,d as Mr,e as Tr,R as Ar,D as Rr,f as Lr,g as _r,h as us,i as Er,k as Pr,B as Dr,l as $r,m as Oe,N as rs,n as Br}from"./vendor-CPghmr9Y.js";import{_ as Kr}from"./terminal-D6QYasuF.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:()=>{},screenshotMap:{},setScreenshotMap:()=>{},initialLoaded:!1,toasts:[],setToasts:()=>{},wsStatus:"connected",isConnected:!0,connectionStates:{},connectionTransports:{},showReconnected:!1,userName:void 0,setUserName:()=>{},isP2PActive:!1,p2pStates:{},userRole:void 0}),on=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function Is(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 Xt(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 Wr(t,s,n){var l,x,d,f,h,m,w;const r=Date.now(),i=new Set((n==null?void 0:n.authoritativeDaemonIds)||[]);if(s.length===0)return t.map(b=>({...b,_lastUpdate:r}));const o=new Map;for(const b of s)o.set(b.id,b);for(const b of t){const y=o.get(b.id);if(!y){o.set(b.id,{...b,_lastUpdate:r});continue}const p=Is(b),v=Is(y);if(p>v){const N=(l=b.chats)!=null&&l.length?b.chats:y.chats,M=Xt(y,b,{...y,...b,chats:N,_lastUpdate:r});o.set(b.id,M)}else if(p<v){const N={};if(b.status&&b.status!==y.status&&(N.status=b.status),b.cdpConnected!==void 0&&(N.cdpConnected=b.cdpConnected),(x=b.chats)!=null&&x.length&&!((d=y.chats)!=null&&d.length)&&(N.chats=b.chats),b.machineNickname!==void 0&&b.machineNickname!==y.machineNickname&&(N.machineNickname=b.machineNickname),b.version!==void 0&&(N.version=b.version),b.serverVersion!==void 0&&(N.serverVersion=b.serverVersion),b.versionMismatch===!0&&(N.versionMismatch=!0),Object.keys(N).length>0){const M=Xt(y,b,{...y,...N,_lastUpdate:y._lastUpdate});o.set(b.id,M)}}else{const N=b.timestamp||r,M=y._lastUpdate||y.timestamp||0;if(N>=M){const g=(f=b.chats)!=null&&f.length?b.chats:y.chats,S=Xt(y,b,{...y,...b,chats:g,_lastUpdate:r});o.set(b.id,S)}else(h=b.chats)!=null&&h.length&&!((m=y.chats)!=null&&m.length)&&o.set(b.id,{...y,chats:b.chats})}}const c=new Set(t.map(b=>b.id)),u=new Set;for(const b of t){const y=b.daemonId||((w=b.id)==null?void 0:w.split(":")[0]);y&&u.add(y)}for(const[b,y]of o){const p=y.daemonId||b.split(":")[0];if(!u.has(p))continue;if(i.has(p)&&!c.has(b)){o.delete(b);continue}const v=r-(y._lastUpdate||y.timestamp||0);(y.transport==="pty"&&!c.has(b)&&v>1e4||y.transport==="acp"&&!c.has(b)&&v>1e4||y.transport==="cdp-page"&&!c.has(b)&&v>3e4)&&o.delete(b)}for(const[b,y]of o)r-(y._lastUpdate||y.timestamp||0)>3e5&&y.status!=="online"&&o.delete(b);return Array.from(o.values())}function Or(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 zr({children:t,connectionOverrides:s}){const[n,r]=a.useState([]),[i,o]=a.useState({}),[c,u]=a.useState(!1),[l,x]=a.useState([]),[d,f]=a.useState(void 0),h=a.useRef(n);a.useEffect(()=>{h.current=n},[n]);const m=a.useCallback((N,M)=>{r(g=>{let S=!1;const j=g.map(k=>k.id!==N||k.chats===M?k:(S=!0,{...k,chats:M}));return S?j:g})},[]),w=a.useCallback((N,M)=>{r(g=>{const S=g.length===0?N:Wr(N,g,M);return Or(g,S)?g:S})},[]),b=a.useCallback(()=>u(!0),[]),y=a.useMemo(()=>({injectEntries:w,markLoaded:b,getIdes:()=>h.current}),[w,b]),p=s,v=a.useMemo(()=>({ides:n,updateIdeChats:m,screenshotMap:i,setScreenshotMap:o,initialLoaded:c,toasts:l,setToasts:x,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:d,setUserName:f}),[n,m,i,c,l,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,d]);return e.jsx(on.Provider,{value:y,children:e.jsx(an.Provider,{value:v,children:t})})}function mt(){return a.useContext(an)}function Ms(){return a.useContext(on)}function cn(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;function i(u){return u.startsWith("http")?u:`${s}${u.startsWith("/")?"":"/"}${u}`}function o(u){const l=n==null?void 0:n(),x=i(u),d=u.startsWith("http")?new URL(x):new URL(x,typeof window<"u"?window.location.origin:"http://localhost");return l&&d.searchParams.set("token",l),!u.startsWith("http")&&!s?`${d.pathname}${d.search}${d.hash}`:d.toString()}async function c(u,l={}){const x={"Content-Type":"application/json",...l.headers||{}},d=n==null?void 0:n();d&&(x.Authorization=`Bearer ${d}`);const f=i(u),h=await fetch(f,{...l,headers:x});if(h.status===401)throw r==null||r(),new Error("Unauthorized");if(!h.ok){const m=await h.json().catch(()=>({error:h.statusText}));throw new Error(m.error||`API Error: ${h.status}`)}return h.json()}return{getDaemons:()=>c("/api/v1/daemons"),getDaemonStatus:u=>c(`/api/v1/daemons/${u}/status`),sendCommand:(u,l,x={})=>c(`/api/v1/daemons/${u}/command`,{method:"POST",body:JSON.stringify({type:l,payload:x})}),execTerminal:(u,l,x)=>c(`/api/v1/daemons/${u}/terminal`,{method:"POST",body:JSON.stringify({command:l,name:x})}),sendAgentMessage:(u,l,x)=>c(`/api/v1/shortcuts/${u}/chat`,{method:"POST",body:JSON.stringify({agentType:l,message:x})}),getAgentStatus:u=>c(`/api/v1/shortcuts/${u}/status`),approveAgent:(u,l,x)=>c(`/api/v1/shortcuts/${u}/approve`,{method:"POST",body:JSON.stringify({agentType:l,action:x?"approve":"reject"})}),getMuxState:u=>c(`/api/v1/mux/${encodeURIComponent(u)}/state`),getMuxSocketInfo:u=>c(`/api/v1/mux/${encodeURIComponent(u)}/socket-info`),controlMux:(u,l,x={})=>c(`/api/v1/mux/${encodeURIComponent(u)}/control`,{method:"POST",body:JSON.stringify({type:l,payload:x})}),getMuxEventsUrl:u=>o(`/api/v1/mux/${encodeURIComponent(u)}/events`),getRuntimeEventsUrl:u=>o(`/api/v1/runtime/${encodeURIComponent(u)}/events`),request:c}}const Ur=cn({baseUrl:"http://localhost:3847"}),Fr=a.createContext(Ur);function Hr({client:t,children:s}){return e.jsx(Fr.Provider,{value:t,children:s})}const Vr={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},ln=a.createContext(Vr);function qr({value:t,children:s}){return e.jsx(ln.Provider,{value:t,children:s})}function Fe(){return a.useContext(ln)}const pe={size:18};function dn({size:t=pe.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 un({size:t=pe.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 hs({size:t=pe.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 Yr({size:t=pe.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 Xr({size:t=pe.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 Gr({size:t=pe.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 Rt({size:t=pe.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 Jr({size:t=pe.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 Wt({size:t=pe.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function hn({size:t=pe.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 mn({size:t=pe.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 Ge({size:t=pe.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 Pe({size:t=pe.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 ms({size:t=pe.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 Zr({size:t=pe.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 as({size:t=pe.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 ps({size:t=pe.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 xs({size:t=pe.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 Qe({size:t=pe.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 fs({size:t=pe.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 Qr({size:t=pe.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 pn({size:t=pe.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 ea({size:t=pe.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 bs({size:t=pe.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 ta({size:t=pe.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:"9 3 3 3 3 9"}),e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("polyline",{points:"9 21 3 21 3 15"}),e.jsx("polyline",{points:"15 21 21 21 21 15"}),e.jsx("line",{x1:"8",y1:"8",x2:"3",y2:"3"}),e.jsx("line",{x1:"16",y1:"8",x2:"21",y2:"3"}),e.jsx("line",{x1:"8",y1:"16",x2:"3",y2:"21"}),e.jsx("line",{x1:"16",y1:"16",x2:"21",y2:"21"})]})}function sa({size:t=pe.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 xn({size:t=pe.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 fn({size:t=pe.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 na({size:t=pe.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 ra({size:t=pe.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 aa({size:t=pe.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 Ot({size:t=pe.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 ia({size:t=pe.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 oa({size:t=pe.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 ca({size:t=pe.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=pe.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 da(t){const n=t.split(`
|
|
3
|
-
`).map(u=>{if(!u.includes("\r"))return u;const l=u.split("\r").map(f=>f.trim()).filter(Boolean);if(l.length===0)return"";const x=l.filter(f=>f.startsWith("⏺"));if(x.length>0)return x[x.length-1];const d=l.filter(f=>!(/^[❯›>]\s*$/.test(f)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(f)&&f.length<40||/^[╭╰│├╮╯─═]+$/.test(f)));return d.length>0?d[d.length-1]:l[l.length-1]}).join(`
|
|
4
|
-
`).split(`
|
|
5
|
-
`),r={},i=[];let o=!1;for(const u of n){const l=u.trim();if(l===""){o=!1,i.push("");continue}if(/^❯\s*$/.test(l)||/^>\s*$/.test(l)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(l)||/^◐\s/.test(l)||/\/effort/.test(l)||/^⎿\s+(Tip|Note|Hint):/.test(l)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(l)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(l)||/Brewing[…\.]{0,3}\s*\d*$/i.test(l)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(l)||/^Auto-updating/i.test(l))continue;if(/^[⏺●·⏵]/.test(u)){const d=u.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(d)r[d[1]]=(r[d[1]]||0)+1;else{const f=u.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);f&&(r[f]=(r[f]||0)+1)}o=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(u)||/^[╭╰│├╮╯─]+/.test(l)||/^\s+[⊙✓✗○◎▸►✦]/.test(u)||o&&/^\s{2,}/.test(u))continue;o=!1;const x=u.replace(/^❯\s+/,"");i.push(x)}const c=i.join(`
|
|
6
|
-
`).replace(/\n{3,}/g,`
|
|
7
|
-
|
|
8
|
-
`).trim();return{toolCounts:r,textContent:c,hasTools:Object.keys(r).length>0}}function is(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function ua(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function Ze(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 Ts=700,ha=a.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(nn,{remarkPlugins:[rn],children:s.text}),e.jsx("span",{className:"action-time",children:is(s.timestamp)})]})},(t,s)=>t.log===s.log),ma=a.memo(function({message:s,receivedAt:n,agentName:r,userName:i,isCliMode:o,isExpanded:c,isTextExpanded:u,onToggleExpanded:l,onToggleTextExpanded:x}){var M;const d=(s.role||"").toLowerCase(),f=d==="user"||d==="human",h=s.kind||(d==="tool"?"tool":"standard"),m=typeof s.content=="string"?s.content:(s.content||[]).map(g=>g.text||"").join(`
|
|
10
|
-
`);if(h==="thought"){const g=((M=s.meta)==null?void 0:M.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(ra,{size:13}),e.jsx("span",{children:g})]}),e.jsx("div",{className:"chat-msg-body",children:m})]})}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:m.split(`
|
|
11
|
-
`)[0].slice(0,80)})]});if(h==="terminal"){const g=s.meta||{},S=g.isRunning?"⏳":"✅",j=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:S}),e.jsx("span",{children:j})]}),e.jsx("pre",{className:"chat-msg-body",children:m})]})}if(h==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:m.slice(0,100)});const w=!f&&o?da(m):null,b=w?w.textContent:m,y=w?Object.entries(w.toolCounts):[],p=o&&!f&&!c&&b.length>Ts,v=c?m:p&&!u?b.slice(0,Ts):b,N=ua(v);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${f?"self-end":"self-start"}`,children:[y.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[y.map(([g,S])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",g,S>1?` ×${S}`:""]},g)),(w==null?void 0:w.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:c?"Collapse":"Original"}),!b&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:is(n)})]}),(b||f)&&e.jsxs("div",{className:`chat-bubble ${f?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${b?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:f?i||"You":r}),n!=null&&e.jsx("span",{className:"chat-time",children:is(n)})]}),b&&e.jsx("div",{className:"chat-markdown",children:N?e.jsx(nn,{remarkPlugins:[rn,Sr,Cr],children:v}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:v})}),p&&e.jsx("button",{onClick:x,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:u?"Collapse ↑":`Show more (${Math.round(b.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),pa=a.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:u="",receivedAtMap:l={},emptyState:x,onLoadMore:d,isLoadingMore:f,hasMoreHistory:h,hiddenLiveCount:m=0,loadError:w},b){var ne;const y=a.useRef(null),p=a.useRef(null),v=a.useRef(null),N=a.useRef(0),M=a.useRef(""),g=a.useRef(!1),S=a.useRef(null),j=a.useRef(!1),k=a.useRef(null),L=a.useRef(!1),[P,B]=a.useState(new Set),[K,C]=a.useState(new Set),D=a.useRef(!1),T=()=>{const O=y.current;return O?O.scrollHeight-O.scrollTop-O.clientHeight<200:!0},R=a.useCallback((O="auto")=>{const X=y.current;X&&X.scrollTo({top:X.scrollHeight,behavior:O})},[]),q=a.useCallback(()=>{var G;const O=y.current,X=(G=window.getSelection)==null?void 0:G.call(window);if(!O||!X||X.rangeCount===0||X.isCollapsed){L.current=!1;return}const V=X.anchorNode,I=X.focusNode;L.current=!!(V&&I&&O.contains(V)&&O.contains(I))},[]),A=a.useCallback((O="auto")=>{S.current!=null&&cancelAnimationFrame(S.current),S.current=requestAnimationFrame(()=>{S.current=null,R(O)})},[R]),_=s.length>0?`${s.length}:${(((ne=s[s.length-1])==null?void 0:ne.content)||"").length}`:"0:0";a.useEffect(()=>{const O=!g.current,X=M.current!==u;if(M.current=u,O||X){g.current=!0,D.current=!1,j.current=!0,L.current||A("auto"),N.current=s.length;return}s.length>N.current?!D.current&&!L.current&&A("auto"):T()&&!D.current&&!L.current&&A("auto"),N.current=s.length},[_,u,c,s.length,A]),a.useEffect(()=>()=>{S.current!=null&&cancelAnimationFrame(S.current),k.current!=null&&window.clearTimeout(k.current)},[]),a.useEffect(()=>{const O=p.current;if(!O)return;const X=()=>{k.current!=null&&window.clearTimeout(k.current),k.current=window.setTimeout(()=>{j.current=!1,k.current=null},180)},V=new ResizeObserver(()=>{j.current&&(L.current||(A("auto"),X()))});return V.observe(O),()=>{V.disconnect(),k.current!=null&&(window.clearTimeout(k.current),k.current=null)}},[A,u]),a.useImperativeHandle(b,()=>({scrollToBottom:(O="smooth")=>{R(O)}}),[R]),a.useEffect(()=>{const O=y.current;if(!O)return;let X;const V=()=>{clearTimeout(X),X=setTimeout(()=>{D.current=!T()},50)};return O.addEventListener("scroll",V,{passive:!0}),()=>{O.removeEventListener("scroll",V),clearTimeout(X)}},[]),a.useEffect(()=>(document.addEventListener("selectionchange",q),()=>document.removeEventListener("selectionchange",q)),[q]);const W=a.useRef(0),U=a.useRef(!1);a.useEffect(()=>{const O=y.current;if(!O||!U.current||W.current===0)return;const X=O.scrollHeight-W.current;X>0&&(O.scrollTop=X),W.current=0,U.current=!1},[s.length]);const ie=()=>{const O=y.current;O&&(W.current=O.scrollHeight),U.current=!0,d==null||d()},H=a.useMemo(()=>{const O=s.map((G,Y)=>({type:"message",data:G,index:Y,ts:G.receivedAt||l[Ze(G,Y)]||0}));if(!n||n.length===0)return O;const X=[...n].sort((G,Y)=>G.timestamp-Y.timestamp).map((G,Y)=>({type:"action",data:G,index:Y,ts:G.timestamp})),V=[];let I=0;for(const G of O){for(;I<X.length&&G.ts>0&&X[I].ts<G.ts;)V.push(X[I++]);V.push(G)}for(;I<X.length;)V.push(X[I++]);return V},[s,n,l]),F=m>0||!!h,le=m>0?`↑ Show ${Math.min(m,80)} earlier messages${m>80?` (${m} hidden)`:""}`:w?`↻ ${w}`:"↑ Load older messages";return e.jsx("div",{ref:y,"data-chat-scroll":!0,className:"chat-container",children:e.jsxs("div",{ref:p,className:"chat-container-content",children:[f&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),F&&!f&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:ie,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${w&&m===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:le})}),H.length===0&&!F&&(x||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),H.map(O=>{if(O.type==="action"){const ue=O.data;return e.jsx(ha,{log:ue},`action-${O.index}`)}const X=O.data,V=O.index,I=Ze(X,V),G=X.receivedAt||l[I],Y=`${u}-${I}`,ae=P.has(Y),me=K.has(Y);return e.jsx(ma,{message:X,receivedAt:G,agentName:r,userName:i,isCliMode:o,isExpanded:ae,isTextExpanded:me,onToggleExpanded:()=>B(ue=>{const xe=new Set(ue);return ae?xe.delete(Y):xe.add(Y),xe}),onToggleTextExpanded:()=>C(ue=>{const xe=new Set(ue);return me?xe.delete(Y):xe.add(Y),xe})},`msg-${I}`)}),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:v})]})})}),xa=a.memo(pa,(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 As=!1;const bn=a.forwardRef(({onInput:t,onResize:s,fontSize:n=13,readOnly:r=!1},i)=>{const o=a.useRef(null),[c,u]=a.useState(null),l=a.useRef([]),x=a.useRef(!1),d=a.useRef(!1),f=a.useRef(!1),h=()=>{const m=o.current;if(m){x.current&&(m.clear(),x.current=!1);for(const w of l.current)m.write(w);l.current=[],d.current&&(m.fit(),d.current=!1),f.current&&(m.bumpResize(),f.current=!1)}};return a.useImperativeHandle(i,()=>({write:m=>{o.current?o.current.write(m):l.current.push(m)},clear:()=>{o.current?o.current.clear():(l.current=[],x.current=!0)},reset:()=>{o.current&&"reset"in o.current&&typeof o.current.reset=="function"?o.current.reset():(l.current=[],x.current=!0)},fit:()=>{o.current?o.current.fit():d.current=!0},bumpResize:()=>{o.current?o.current.bumpResize():f.current=!0}}),[]),a.useEffect(()=>{if(!c)return;const m=requestAnimationFrame(()=>{h()});return()=>cancelAnimationFrame(m)},[c]),a.useEffect(()=>{let m=!1;return Kr(()=>import("./terminal-D6QYasuF.js").then(w=>w.i),__vite__mapDeps([0,1,2])).then(w=>{As||(As=!0,console.info("[CliTerminal] renderer module loaded: ghostty-web")),m||u(()=>w.GhosttyTerminalView)}).catch(w=>{console.error("[CliTerminal] failed to load terminal renderer",w)}),()=>{m=!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"}})});bn.displayName="CliTerminal";function gt({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 Rs({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,u=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:u}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:n}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[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, ${u}, ${u}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function fa({cursorPos:t,viewportRef:s,imgRef:n}){var v;if(!t||!n.current)return null;const r=n.current,i=r.getBoundingClientRect(),o=(v=s.current)==null?void 0:v.getBoundingClientRect();if(!o)return null;const c=r.naturalWidth||i.width,u=r.naturalHeight||i.height,l=c/u,x=i.width/i.height;let d,f,h,m;l>x?(d=i.width,f=i.width/l,h=0,m=(i.height-f)/2):(f=i.height,d=i.height*l,h=(i.width-d)/2,m=0);const w=i.left-o.left+h+d*t.nx,b=i.top-o.top+m+f*t.ny,y=Math.max(8,Math.min(o.width-8,w)),p=Math.max(8,Math.min(o.height-8,b));return e.jsxs("div",{style:{position:"absolute",left:y-8,top:p-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 ba({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:i,setIsMenuOpen:o,imeText:c,setImeText:u,handleImeSubmit:l,isConnActive:x,zoom:d,isMobile:f,mobileFillZoom:h,onZoomOut:m,onZoomReset:w,onZoomIn:b,transportType:y,screenshotUsage:p,lastActionStatus:v}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:N=>N.stopPropagation(),className:"absolute bottom-0 left-0 right-0 z-20 flex items-center justify-center gap-1.5 px-3 py-2 bg-black/75 backdrop-blur-xl border-t border-white/[0.08] touch-none",children:[e.jsxs("div",{onClick:s,className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${t==="mouse"?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:[e.jsx("span",{className:"text-sm",children:t==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${t==="mouse"?"text-blue-400":"text-slate-400"}`,children:t==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{r(N=>!N),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:N=>N.stopPropagation(),onChange:N=>u(N.target.value),onKeyDown:N=>{l(N)},className:"w-full bg-black/60 border border-white/15 rounded-lg px-2.5 py-2 text-white text-[13px] outline-none"})})]}),e.jsx("div",{className:"relative",children:e.jsx("div",{onClick:()=>{o(N=>!N),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:x?"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:x?"#22c55e":"#eab308",boxShadow:x?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:x?"#22c55e":"#eab308"},children:x?"Connected":"WS"})]}),d>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(d*100),"%"]}),y==="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"}),y==="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"}),p&&p.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:p.budgetExhausted?"#ef4444":"#c4b5fd",background:p.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:p.budgetExhausted?"TURN blocked":`TURN ${p.dailyUsedMinutes}/${p.dailyBudgetMinutes}m`}),v&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:v})]})]}),i&&e.jsxs("div",{onTouchStart:N=>N.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",d<=(f?h:1)+.01?f?"FILL":"FIT":`${Math.round(d*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:N=>{N.stopPropagation(),m()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),e.jsx("button",{onClick:N=>{N.stopPropagation(),w()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:9,fontWeight:800,cursor:"pointer"},children:f?"FILL":"FIT"}),e.jsx("button",{onClick:N=>{N.stopPropagation(),b()},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 ga({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 ya(){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 Ls(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 xt(t,s){const n=a.useRef(null),r=a.useRef(0);a.useEffect(()=>{if(!ya())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,u])=>[c,Ls(u)]))}),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,Ls(s[c])]))}),n.current=s})}function va({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:i,minZoom:o,zoomRef:c,panXRef:u,panYRef:l,setPanX:x,setPanY:d,setZoom:f,lastWheelTimeRef:h,onAction:m,setLastActionStatus:w,spawnRippleFromNormalized:b,clampPan:y,isMobile:p,mobileFillZoom:v}){const[N,M]=a.useState(null),g=a.useRef(null),S=a.useRef(null),j=a.useRef(null),k=a.useRef(!1),L=a.useRef(null),P=a.useRef(0),B=a.useRef(null),K=a.useRef(1),C=a.useRef({x:0,y:0}),D=a.useRef(!1),T=a.useRef(r),R=a.useRef(m),q=()=>{if(g.current)return;const W={nx:.5,ny:.5};g.current=W,M(W)};return a.useEffect(()=>{T.current=r,r==="mouse"&&q()},[r]),a.useEffect(()=>{R.current=m},[m]),a.useEffect(()=>{const W=t.current;if(!W)return;const U=O=>{if(!n.current)return null;const X=n.current.getBoundingClientRect();return!X.width||!X.height?null:{nx:Math.max(0,Math.min(1,(O.clientX-X.left)/X.width)),ny:Math.max(0,Math.min(1,(O.clientY-X.top)/X.height))}},ie=(O,X)=>{if(!n.current)return{dnx:0,dny:0};const V=n.current,I=V.getBoundingClientRect(),G=V.naturalWidth||I.width,Y=V.naturalHeight||I.height,ae=G/Y,me=I.width/I.height;let ue,xe;return ae>me?(ue=I.width,xe=I.width/ae):(xe=I.height,ue=I.height*ae),{dnx:O/ue,dny:X/xe}},H=(O,X,V)=>{if(V<=1.05)return;const I=-(O-.5)*100,G=-(X-.5)*100,Y=y(I,G,V);(Math.abs(Y.x-u.current)>.1||Math.abs(Y.y-l.current)>.1)&&(x(Y.x),d(Y.y),u.current=Y.x,l.current=Y.y)},F=O=>{const X=s.current;if(X&&O.target instanceof Node&&X.contains(O.target))O.preventDefault();else return;if(O.touches.length===1){const V=O.touches[0];S.current={x:V.clientX,y:V.clientY,time:Date.now()},j.current={x:V.clientX,y:V.clientY},D.current||(k.current=!1),L.current=setTimeout(()=>{if(!k.current&&!D.current)if(k.current=!0,T.current==="mouse"){const I=g.current||{nx:.5,ny:.5};w("Right Click"),b(I.nx,I.ny,"right"),R.current("input_click",{...I,button:"right"}).catch(()=>{})}else{const I=U(V);I&&(w("Right Click"),b(I.nx,I.ny,"right"),R.current("input_click",{...I,button:"right"}).catch(()=>{}))}},500);return}if(O.touches.length===2){L.current&&clearTimeout(L.current),k.current=!0,D.current=!0;const V=O.touches[1].clientX-O.touches[0].clientX,I=O.touches[1].clientY-O.touches[0].clientY;B.current=Math.sqrt(V*V+I*I),K.current=c.current,C.current={x:(O.touches[0].clientX+O.touches[1].clientX)/2,y:(O.touches[0].clientY+O.touches[1].clientY)/2}}},le=O=>{const X=s.current;if(X&&O.target instanceof Node&&X.contains(O.target)&&O.preventDefault(),O.touches.length===1&&j.current){const V=O.touches[0],I=V.clientX-j.current.x,G=V.clientY-j.current.y;if(!k.current&&S.current){const Y=V.clientX-S.current.x,ae=V.clientY-S.current.y;Math.sqrt(Y*Y+ae*ae)>8&&(k.current=!0,L.current&&clearTimeout(L.current))}if(k.current)if(T.current==="mouse"){const Y=ie(I,G),ae=g.current||{nx:.5,ny:.5},me=Math.max(0,Math.min(1,ae.nx+Y.dnx)),ue=Math.max(0,Math.min(1,ae.ny+Y.dny));g.current={nx:me,ny:ue},M({nx:me,ny:ue}),w(`Cursor: ${Math.round(me*100)}%, ${Math.round(ue*100)}%`),H(me,ue,c.current);const xe=Date.now();xe-h.current>=30&&(h.current=xe,R.current("input_mouseMoved",{nx:me,ny:ue}).catch(()=>{}))}else if(c.current>1){const Y=s.current;if(Y){const ae=Y.clientWidth,me=Y.clientHeight,ue=u.current+I/ae*100,xe=l.current+G/me*100,J=y(ue,xe,c.current);x(J.x),d(J.y),u.current=J.x,l.current=J.y}}else{const Y=U(V);if(Y){const ae=Date.now();ae-h.current>=40&&(h.current=ae,w("Scroll"),R.current("input_wheel",{nx:Y.nx,ny:Y.ny,deltaX:Math.round(-I*2.5),deltaY:Math.round(-G*2.5)}).catch(()=>{}))}}j.current={x:V.clientX,y:V.clientY};return}if(O.touches.length===2&&B.current!==null){const V=O.touches[1].clientX-O.touches[0].clientX,I=O.touches[1].clientY-O.touches[0].clientY,Y=Math.sqrt(V*V+I*I)/B.current,ae=(O.touches[0].clientX+O.touches[1].clientX)/2,me=(O.touches[0].clientY+O.touches[1].clientY)/2,ue=ae-C.current.x,xe=me-C.current.y,J=Math.abs(Y-1)>.03;if(T.current==="mouse"){if(J){const se=Math.max(o,Math.min(5,K.current*Y));f(se),c.current=se}else if(Math.abs(ue)>2||Math.abs(xe)>2){const se=g.current||{nx:.5,ny:.5},Z=Date.now();Z-h.current>=30&&(h.current=Z,w("Scroll"),R.current("input_wheel",{nx:se.nx,ny:se.ny,deltaX:Math.round(-ue*3),deltaY:Math.round(-xe*3)}).catch(()=>{}))}}else{const se=Math.max(o,Math.min(5,K.current*Y));f(se),c.current=se;const Z=s.current;if(Z&&se>1){const E=Z.clientWidth,Q=Z.clientHeight,re=u.current+ue/E*100,oe=l.current+xe/Q*100,ge=y(re,oe,se);x(ge.x),d(ge.y),u.current=ge.x,l.current=ge.y}}C.current={x:ae,y:me}}},ne=O=>{var X;if(L.current&&clearTimeout(L.current),B.current=null,O.touches.length===1&&D.current){const V=O.touches[0];S.current={x:V.clientX,y:V.clientY,time:Date.now()},j.current={x:V.clientX,y:V.clientY},k.current=!0;return}if(O.touches.length===0){if(D.current){D.current=!1,k.current=!1;return}if(O.changedTouches.length===1&&!k.current){const V=O.changedTouches[0],I=Date.now(),G=I-(((X=S.current)==null?void 0:X.time)||0);if(G<60||G>400){k.current=!1;return}if(S.current){const Y=V.clientX-S.current.x,ae=V.clientY-S.current.y;if(Math.sqrt(Y*Y+ae*ae)>12){k.current=!1;return}}if(T.current==="mouse"){const Y=g.current||U(V);Y&&(w(`Click: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),b(Y.nx,Y.ny,"left"),R.current("input_click",{...Y}).catch(()=>{}))}else{const Y=U(V);if(!Y)return;I-P.current<300?(w("Double tap"),b(Y.nx,Y.ny,"double"),R.current("input_click",{...Y,clickCount:2}).catch(()=>{}),P.current=0):(w(`Tap: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),b(Y.nx,Y.ny,"left"),R.current("input_click",{...Y}).catch(()=>{}),P.current=I)}}k.current=!1}};return W.addEventListener("touchstart",F,{passive:!1}),W.addEventListener("touchmove",le,{passive:!1}),W.addEventListener("touchend",ne,{passive:!1}),()=>{W.removeEventListener("touchstart",F),W.removeEventListener("touchmove",le),W.removeEventListener("touchend",ne),L.current&&clearTimeout(L.current)}},[t,s,n,o,c,u,l,x,d,f,h,w,b,y]),{cursorPos:N,cursorPosRef:g,handleToggleInputMode:()=>{i(W=>{const U=W==="touch"?"mouse":"touch";return U==="mouse"&&q(),U})},handleZoomReset:()=>{const W=p?v:1;f(W),c.current=W,x(0),d(0),u.current=0,l.current=0}}}function gn({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:i,transportType:o}){const c=a.useRef(null),u=a.useRef(null),l=a.useRef(null),[x,d]=a.useState(null),[f,h]=a.useState(""),[,m]=a.useState(!1),[w,b]=a.useState([]),y=a.useRef(0),[p,v]=a.useState(!1),[N,M]=a.useState(!1),g=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[S,j]=a.useState(g?"mouse":"touch"),[k,L]=a.useState(1),P=a.useRef(!1),[B,K]=a.useState(1),[C,D]=a.useState(0),[T,R]=a.useState(0);xt("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:S,zoom:B,panX:C,panY:T,isMenuOpen:p,isImeOpen:N});const q=a.useRef(0),A=a.useRef(B),_=a.useRef(C),W=a.useRef(T);a.useEffect(()=>{A.current=B},[B]),a.useEffect(()=>{_.current=C},[C]),a.useEffect(()=>{W.current=T},[T]),a.useEffect(()=>{var J;(J=c.current)==null||J.focus()},[]);const U=n==="connected",ie=r,H=U?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",F=U?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!g||P.current||!ie)return;const J=l.current,se=u.current;if(!J||!se)return;const Z=()=>{const E=se.clientWidth,Q=se.clientHeight,re=J.naturalWidth,oe=J.naturalHeight;if(!re||!oe||!E||!Q)return;const ge=Math.min(E/re,Q/oe),de=Math.max(E/re,Q/oe)/ge;de>1.01&&(L(de),K(de),A.current=de),P.current=!0};J.complete&&J.naturalWidth?Z():J.addEventListener("load",Z,{once:!0})},[ie,g]);const le=.5;a.useEffect(()=>{B<=le&&(D(0),R(0))},[B,le]);const ne=(J,se,Z)=>{if(Z<=le)return{x:0,y:0};const E=(Z-1)/(2*Z)*100,Q=(Z-1)/(2*Z)*100;return{x:Math.max(-E,Math.min(E,J)),y:Math.max(-Q,Math.min(Q,se))}},O=(J,se)=>{if(!l.current)return null;const Z=l.current.getBoundingClientRect();return!Z.width||!Z.height?null:{nx:Math.max(0,Math.min(1,(J-Z.left)/Z.width)),ny:Math.max(0,Math.min(1,(se-Z.top)/Z.height))}},X=(J,se,Z)=>{const E=u.current;if(!E)return;const Q=E.getBoundingClientRect(),re=++y.current;b(oe=>[...oe,{id:re,x:J-Q.left,y:se-Q.top,type:Z}]),setTimeout(()=>b(oe=>oe.filter(ge=>ge.id!==re)),600)},V=(J,se,Z)=>{const E=l.current,Q=u.current;if(!E||!Q)return;const re=E.getBoundingClientRect(),oe=Q.getBoundingClientRect(),ge=E.naturalWidth||re.width,Ne=E.naturalHeight||re.height,de=ge/Ne,Te=re.width/re.height;let $,z,te,ce;de>Te?($=re.width,z=re.width/de,te=0,ce=(re.height-z)/2):(z=re.height,$=re.height*de,te=(re.width-$)/2,ce=0);const ee=re.left-oe.left+te+$*J,fe=re.top-oe.top+ce+z*se,ye=++y.current;b(he=>[...he,{id:ye,x:ee,y:fe,type:Z}]),setTimeout(()=>b(he=>he.filter(Re=>Re.id!==ye)),600)},I=async J=>{var Z;const se=O(J.clientX,J.clientY);if(se){d(`Click: ${Math.round(se.nx*100)}%, ${Math.round(se.ny*100)}%`),X(J.clientX,J.clientY,"left"),(Z=c.current)==null||Z.focus();try{const E=await t("input_click",{nx:se.nx,ny:se.ny});E!=null&&E.success||s(`❌ Click failed: ${E==null?void 0:E.error}`)}catch(E){s(`❌ Click error: ${E.message||E}`)}}},G=async(J,se,Z,E=0)=>{try{await t("input_key",{type:Z?"char":"keyDown",key:J,code:se,text:Z?J:void 0,unmodifiedText:Z?J:void 0,modifiers:E})}catch(Q){s(`❌ Key error: ${Q.message||Q}`)}},Y=async J=>{if(J.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(J.key)&&J.preventDefault();let Z=0;J.altKey&&(Z|=1),J.ctrlKey&&(Z|=2),J.metaKey&&(Z|=4),J.shiftKey&&(Z|=8),d(`Key: ${J.key}`),await G(J.key,J.code,J.key.length===1,Z)},ae=async J=>{if(J.key==="Enter"){if(J.nativeEvent.isComposing)return;if(f){const se=f;h(""),d(`IME Sent: ${se}`);try{const Z=await t("input_type",{text:se});Z!=null&&Z.success||s(`❌ IME error: ${Z==null?void 0:Z.error}`)}catch(Z){s(`❌ IME error: ${Z.message}`)}}else d("Key: Enter"),await G("Enter","Enter",!1)}};a.useEffect(()=>{const J=c.current;if(!J)return;const se=Z=>{var E;if((E=l.current)!=null&&E.contains(Z.target)){Z.preventDefault();const Q=Date.now();if(Q-q.current<40)return;q.current=Q;const re=O(Z.clientX,Z.clientY);if(!re)return;d(`Scroll: ${Math.round(Z.deltaY)}`),t("input_wheel",{nx:re.nx,ny:re.ny,deltaX:Math.round(Z.deltaX),deltaY:Math.round(Z.deltaY)}).catch(()=>{})}};return J.addEventListener("wheel",se,{passive:!1}),()=>J.removeEventListener("wheel",se)},[t]);const{cursorPos:me,handleToggleInputMode:ue,handleZoomReset:xe}=va({containerRef:c,viewportRef:u,imgRef:l,inputMode:S,setInputMode:j,minZoom:le,zoomRef:A,panXRef:_,panYRef:W,setPanX:D,setPanY:R,setZoom:K,lastWheelTimeRef:q,onAction:t,setLastActionStatus:d,spawnRippleFromNormalized:V,clampPan:ne,isMobile:g,mobileFillZoom:k});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:()=>m(!0),onBlur:()=>m(!1),tabIndex:0,children:[e.jsxs("div",{ref:u,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[ie?e.jsx("img",{ref:l,src:ie,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${B}) translate(${C}%, ${T}%)`,transformOrigin:"center center",cursor:S==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:I,onContextMenu:J=>J.preventDefault(),onDragStart:J=>J.preventDefault()}):e.jsx(ga,{waitingLabel:H,waitingHint:F,transportType:o}),S==="mouse"&&ie&&e.jsx(fa,{cursorPos:me,viewportRef:u,imgRef:l}),w.map(J=>{const Z={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(${Z}, 0.8)`,animation:"click-ripple-ring 0.5s ease-out forwards",position:"absolute",left:-20,top:-20}}),e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:`rgba(${Z}, 0.9)`,boxShadow:`0 0 12px rgba(${Z}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},J.id)})]}),e.jsx(ba,{inputMode:S,onToggleInputMode:ue,isImeOpen:N,setIsImeOpen:M,isMenuOpen:p,setIsMenuOpen:v,imeText:f,setImeText:h,handleImeSubmit:ae,isConnActive:U,zoom:B,isMobile:g,mobileFillZoom:k,onZoomOut:()=>K(J=>Math.max(.5,J-.25)),onZoomReset:xe,onZoomIn:()=>K(J=>Math.min(5,J+.25)),transportType:o,screenshotUsage:i,lastActionStatus:x}),e.jsx("style",{children:`
|
|
12
|
-
@keyframes slideUp {
|
|
13
|
-
from { opacity: 0; transform: translateY(6px); }
|
|
14
|
-
to { opacity: 1; transform: translateY(0); }
|
|
15
|
-
}
|
|
16
|
-
@keyframes slideUpSidebar {
|
|
17
|
-
from { opacity: 0; transform: translateY(6px); }
|
|
18
|
-
to { opacity: 1; transform: translateY(0); }
|
|
19
|
-
}
|
|
20
|
-
@keyframes click-ripple-ring {
|
|
21
|
-
0% { transform: scale(0.3); opacity: 1; }
|
|
22
|
-
100% { transform: scale(2.2); opacity: 0; }
|
|
23
|
-
}
|
|
24
|
-
@keyframes click-ripple-dot {
|
|
25
|
-
0% { transform: scale(1); opacity: 0.9; }
|
|
26
|
-
50% { transform: scale(1.8); opacity: 0.6; }
|
|
27
|
-
100% { transform: scale(0.5); opacity: 0; }
|
|
28
|
-
}
|
|
29
|
-
@keyframes remote-float {
|
|
30
|
-
0% { transform: translateY(0px); }
|
|
31
|
-
50% { transform: translateY(-7px); }
|
|
32
|
-
100% { transform: translateY(0px); }
|
|
33
|
-
}
|
|
34
|
-
`})]})}function ja({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:r=!1,connectionState:i,onDismiss:o,onClickAt:c,onKeyDown:u,badge:l,emptyMessage:x,aspectRatio:d,className:f,style:h}){const m=a.useRef(null),w=a.useCallback(b=>{if(!r||!c||!m.current)return;const y=m.current,p=y.getBoundingClientRect(),v=(b.clientX-p.left)/p.width*y.naturalWidth,N=(b.clientY-p.top)/p.height*y.naturalHeight;c(v,N,y.naturalWidth,y.naturalHeight)},[r,c]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${f||""}`,style:{aspectRatio:d||"16/9",...h},children:[e.jsx("img",{ref:m,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),o&&e.jsx("button",{onClick:o,className:"absolute top-2.5 right-2.5 bg-black/50 border-none text-white w-5 h-5 rounded-full text-[10px] z-10 cursor-pointer flex items-center justify-center",children:"✕"})]}):null:t?e.jsxs("div",{className:`${r?"screenshot-interactive":""} ${f||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?u:void 0,style:h,children:[e.jsx("img",{ref:m,src:t,alt:"IDE Screenshot",onClick:r?w:void 0,className:"max-w-full max-h-full object-contain",style:{...r?{cursor:"crosshair"}:{},...n!==100?{transform:`scale(${n/100})`,transformOrigin:"center center"}:{}}}),l&&e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 bg-black/70 text-white px-3.5 py-1.5 rounded-[20px] text-xs font-semibold backdrop-blur-sm",children:l})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${f||""}`,style:h,children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.22)] mb-1",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),e.jsx("p",{className:"text-base",children:x||"Waiting for screenshot stream..."}),i&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",i]}),e.jsx("style",{children:`
|
|
35
|
-
@keyframes remote-float {
|
|
36
|
-
0% { transform: translateY(0px); }
|
|
37
|
-
50% { transform: translateY(-7px); }
|
|
38
|
-
100% { transform: translateY(0px); }
|
|
39
|
-
}
|
|
40
|
-
`})]})}function yn({activeConv:t,onModalButton:s}){const[n,r]=a.useState(null);if(a.useEffect(()=>{r(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const i=c=>{n||(r(c),s(c))},o=c=>c.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"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(xs,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((c,u)=>{const l=o(c).toLowerCase(),x=/^(run|approve|accept|yes|allow|always)/.test(l),d=/^(reject|deny|delete|remove|abort)/.test(l),f=n===c,h=n!==null;return e.jsx("button",{onClick:()=>i(c),disabled:h,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${x?"bg-white font-extrabold":d?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${h&&!f?"opacity-40":"opacity-100"} ${h?"cursor-not-allowed":"cursor-pointer"}`,style:x?{color:"var(--status-warning)"}:void 0,children:f?"⏳ ...":o(c)},u)})})]})]})}const _s=new Map,wa={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"};function ka({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:i,controls:o,controlValues:c,serverModel:u,serverMode:l}){const{sendCommand:x}=Fe(),d=`${t}:${s||r}`,f=wa[r]||"#94a3b8",[h,m]=a.useState({}),w=a.useRef(0),b={...u?{model:u}:{},...l?{mode:l}:{},...c||{},...Date.now()<w.current?h:{}};a.useEffect(()=>{c&&Date.now()>w.current&&m({})},[c]);const[y,p]=a.useState(_s.get(d)||{}),[v,N]=a.useState(null),[M,g]=a.useState(null),S=a.useCallback(async(C,D={})=>{const T={...D,...s&&{targetSessionId:s}};return await x(t,C,T)},[t,s,x]);if(!o||o.length===0)return null;const j=o.filter(C=>C.placement==="bar").sort((C,D)=>(C.order??50)-(D.order??50));if(j.length===0)return null;const k=async C=>{var T,R,q;if(v===C.id){N(null);return}if((((T=C.options)==null?void 0:T.map(A=>A.value))||y[C.id]||[]).length>0){N(C.id);return}if(C.dynamic&&C.listScript){g(C.id);try{const A=await S(C.listScript==="listModels"?"list_extension_models":C.listScript==="listModes"?"list_extension_modes":C.listScript,{agentType:r,ideType:n}),W=((A==null?void 0:A.models)||(A==null?void 0:A.modes)||((R=A==null?void 0:A.result)==null?void 0:R.models)||((q=A==null?void 0:A.result)==null?void 0:q.modes)||(A==null?void 0:A.options)||[]).map(U=>typeof U=="string"?U:(U==null?void 0:U.name)||(U==null?void 0:U.id)||(U==null?void 0:U.value)||String(U));p(U=>{const ie={...U,[C.id]:W};return _s.set(d,ie),ie}),N(C.id)}catch{}finally{g(null)}}},L=async(C,D)=>{N(null),m(T=>({...T,[C.id]:D})),w.current=Date.now()+5e3;try{if(!C.setScript)return;const T=Gt(C.setScript,r);await S(T,{agentType:r,ideType:n,model:C.id==="model"?D:void 0,mode:C.id==="mode"?D:void 0,value:D})}catch{}},P=async C=>{var _;const D=((_=C.options)==null?void 0:_.map(W=>W.value))||y[C.id]||[];if(D.length===0)return;const T=String(b[C.id]||""),q=(D.indexOf(T)+1)%D.length,A=D[q];if(typeof A=="string"){m(W=>({...W,[C.id]:A})),w.current=Date.now()+5e3;try{if(!C.setScript)return;const W=Gt(C.setScript,r);await S(W,{agentType:r,ideType:n,value:A})}catch{}}},B=async C=>{const T=!b[C.id];m(R=>({...R,[C.id]:T})),w.current=Date.now()+5e3;try{if(!C.setScript)return;const R=Gt(C.setScript,r);await S(R,{agentType:r,ideType:n,value:T})}catch{}},K=async C=>{if(C.invokeScript)try{await S("invoke_extension_script",{agentType:r,ideType:n,scriptName:C.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:f},children:i}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),j.map(C=>{var A;const D=String(b[C.id]||""),T=v===C.id,R=M===C.id,q=((A=C.options)==null?void 0:A.map(_=>_.value))||y[C.id]||[];switch(C.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:T?`${f}55`:"transparent",border:"1px solid",color:D?"var(--text-primary)":"var(--text-muted)"},onClick:()=>k(C),children:[C.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:C.icon}),R?"...":D||C.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),T&&q.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>N(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:C.label.toUpperCase()}),q.map(_=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:_===D?`${f}18`:"transparent",color:_===D?f:"var(--text-secondary)",fontWeight:_===D?600:400,borderLeft:_===D?`2px solid ${f}`:"2px solid transparent"},onMouseEnter:W=>{W.currentTarget.style.background=`${f}12`},onMouseLeave:W=>{W.currentTarget.style.background=_===D?`${f}18`:"transparent"},onClick:()=>L(C,_),children:_},_))]})]})]},C.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:D?"var(--text-primary)":"var(--text-muted)"},onClick:()=>P(C),title:`Click to cycle: ${q.join(" → ")}`,children:[C.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:C.icon}),D||C.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"⟳"})]},C.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:D?`${f}44`:"transparent",background:D?`${f}14`:"var(--surface-tertiary)",color:D?f:"var(--text-muted)"},onClick:()=>B(C),children:[C.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:C.icon}),C.label]},C.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:()=>K(C),children:[C.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:C.icon}),C.label]},C.id);default:return null}})]})}function Gt(t,s){return{setModel:"set_extension_model",setMode:"set_extension_mode",setThinkingLevel:"set_thought_level"}[t]||t}const Na=a.memo(function({contextKey:s,panelLabel:n,isSending:r,onSend:i}){const o=a.useRef(null),[c,u]=a.useState("");a.useEffect(()=>{u("")},[s]);const l=()=>{const x=c.trim();!x||r||(u(""),i(x))};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:x=>u(x.target.value),onPaste:x=>{const d=x.clipboardData.getData("text");d&&u(f=>f+d),x.preventDefault()},onKeyDown:x=>{if(x.key==="Enter"){if(x.nativeEvent.isComposing){x.preventDefault();return}x.preventDefault(),l()}},onBlur:x=>{if(window.innerWidth<768){const d=x.relatedTarget;if((d==null?void 0:d.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 Sa=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function Ca(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function Ae(t,s){if(Ca(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":Sa.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 Ae(t)==="generating"}function ke(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function Ia(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 Es(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function jn(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 Ma(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 Ta(t){const s=t.trim().toLowerCase();return s.startsWith("mach_")||s.startsWith("standalone_mach_")||s.startsWith("daemon_mach_")}function Aa(t){return Ma(t.trim().replace(/\.local$/i,""))}function Ra(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function wn(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&&!Ta(c));if(n&&n!=="Unknown")return Aa(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function We(t,s={}){return Ra(t)||wn(t,s)}function Lt(t){return t.transport==="pty"}function it(t){return t.transport==="acp"}function Ps(t,s){return ke(t)}function La(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const i=(s||"").trim().toLowerCase(),o=(n||"").trim().toLowerCase(),c=ke(n||"").trim().toLowerCase();return r===i||r===o||r===c}function _a(t){return Ae(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function Ea(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=Ae(r.status);if(!o){s.set(i,{...r,status:c});continue}const u=n.indexOf(o.status||"idle"),l=n.indexOf(c||"idle");l>=0&&(u<0||l<u)&&s.set(i,{...r,status:c})}return Array.from(s.values())}function Jt(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 Pa(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&&(Jt(s.timestamp)||Jt(s.receivedAt)||Jt(s.createdAt))||0}function Da(t){return(t.recentLaunches||[]).reduce((n,r)=>Math.max(n,r.lastLaunchedAt||0),0)}function _t(t){return Math.max(Da(t),Pa(t.activeChat),t.lastUpdated||0)}function $a(t,s,n,r,i,o){const c=s-t;if(c!==0)return c;const u=n.localeCompare(r);return u!==0?u:i.localeCompare(o)}function Ba(t,s){return $a(_t(t),_t(s),We(t,{fallbackId:t.id}),We(s,{fallbackId:s.id}),t.id,s.id)}function kn({conversation:t,className:s="",onOpenNativeConversation:n,onOpenMachine:r}){var f;const i=tt(),o=t.daemonId||((f=t.ideId)==null?void 0:f.split(":")[0])||t.ideId,c=t.transport==="cdp-page"||t.transport==="cdp-webview",u=t.streamSource==="agent-stream"&&!!t.agentName,l=(()=>{var h,m;if(t.streamSource==="agent-stream"){const w=(m=(h=t.displaySecondary)==null?void 0:h.split("·")[0])==null?void 0:m.trim();if(w)return w}return ke(t.ideType||"")})(),x=a.useCallback(()=>{if(r){r();return}o&&i("/dashboard",{state:{openMachineId:o}})},[o,i,r]),d=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:d,title:l,children:[e.jsx(Pe,{size:12}),e.jsx("span",{children:l})]}),u&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:t.agentName,children:[e.jsx(Qe,{size:12}),e.jsx("span",{children:t.agentName})]}),t.machineName&&e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:x,title:t.machineName,children:[e.jsx(hs,{size:12}),e.jsx("span",{children:t.machineName})]})]})}const Se=t=>t.transport==="pty",et=(t,s)=>Se(t)?s||t.mode||"terminal":"chat",gs=(t,s)=>Se(t)&&et(t,s)==="terminal",we=t=>t.transport==="acp";function Ds(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():Array.isArray(t)?t.map(s=>typeof s=="string"?s:s&&typeof s=="object"&&"text"in s?String(s.text||""):"").join(`
|
|
41
|
-
`).replace(/\s+/g," ").trim():t&&typeof t=="object"&&"text"in t?String(t.text||"").replace(/\s+/g," ").trim():String(t||"").replace(/\s+/g," ").trim()}function $s(t){const s=[];for(const n of t){const r=Ds(n==null?void 0:n.content),i=n==null?void 0:n.role,o=!!(n!=null&&n._localId),c=s.findIndex(u=>(u==null?void 0:u.role)===i&&Ds(u==null?void 0:u.content)===r&&!!(u!=null&&u._localId)!==o);if(c>=0){if(o)continue;s.splice(c,1,n);continue}s.push(n)}return s}const Ka=60,Wa=60;function pt({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:i,isFocusingAgent:o,actionLogs:c,userName:u,showMetaChips:l=!1}){const x=a.useRef(new Map),{sendCommand:d}=Fe();xt("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:r});const f=a.useRef(new Map),h=a.useCallback(C=>(f.current.has(C)||f.current.set(C,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:Ka}),f.current.get(C)),[]),m=a.useCallback((C,D)=>{const T=h(C);f.current.set(C,{...T,...D}),w(R=>R+1)},[h]),[,w]=a.useState(0),b=t.tabKey,y=h(b),p=y.messages,v=y.hasMore,N=y.error,M=Math.max(0,t.messages.length-y.visibleLiveCount),[g,S]=a.useState(!1),j=a.useCallback(async()=>{var T,R;if(g)return;const C=t.tabKey,D=h(C);if(t.messages.length>D.visibleLiveCount){m(C,{visibleLiveCount:Math.min(t.messages.length,D.visibleLiveCount+Wa),error:null});return}S(!0),m(C,{error:null});try{const q=(s==null?void 0:s.daemonId)||((T=t.ideId)==null?void 0:T.split(":")[0])||"";if(!q){m(C,{hasMore:!1});return}const A=t.ideType||t.agentType||"",_=await d(q,"chat_history",{agentType:A,offset:D.offset,limit:30,targetSessionId:t.sessionId}),W=(_==null?void 0:_.result)??_;if(((R=W.messages)==null?void 0:R.length)>0){const U=h(C);m(C,{messages:[...W.messages,...U.messages],offset:U.offset+W.messages.length,hasMore:!!W.hasMore})}else m(C,{hasMore:!!W.hasMore})}catch(q){const A=(q==null?void 0:q.message)||"";A.includes("P2P not available")||A.includes("channel not open")||A.includes("P2P not connected")||A.includes("timeout")?m(C,{error:"Connection not ready — tap to retry"}):m(C,{hasMore:!1,error:"Failed to load history"})}finally{S(!1)}},[g,s,t,d,h,m]),{allMessages:k,receivedAtMap:L}=a.useMemo(()=>{const C=M>0?t.messages.slice(-y.visibleLiveCount):t.messages;if(p.length===0){const A=$s(C),_={};return A.forEach((W,U)=>{const ie=`${t.tabKey}:${Ze(W,U)}`;let H=W.receivedAt||x.current.get(ie)||0;H||(H=Date.now(),x.current.set(ie,H)),_[Ze(W,U)]=H}),{allMessages:A,receivedAtMap:_}}const D=new Set(C.map(A=>`${A.role}:${(A.content||"").slice(0,100)}`)),T=p.filter(A=>!D.has(`${A.role}:${(A.content||"").slice(0,100)}`)),R=$s([...T,...C]),q={};return R.forEach((A,_)=>{const W=`${t.tabKey}:${Ze(A,_)}`;let U=A.receivedAt||x.current.get(W)||0;U||(U=Date.now(),x.current.set(W,U)),q[Ze(A,_)]=U}),{allMessages:R,receivedAtMap:q}},[t.messages,t.tabKey,M,p,y.visibleLiveCount]),P=a.useMemo(()=>c.filter(C=>C.ideId===t.tabKey).sort((C,D)=>C.timestamp-D.timestamp),[c,t.tabKey]),B=t.displayPrimary||t.agentName||"Agent",K=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(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(Qe,{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(as,{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(fs,{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(as,{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"&&!g)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,g,B]);return e.jsxs("div",{className:"flex-1 min-h-0 w-full flex flex-col",children:[l&&e.jsx(kn,{conversation:t,className:"chat-pane-meta-row"}),e.jsx(xa,{messages:k,actionLogs:P,agentName:t.agentName||t.displayPrimary||"Agent",userName:u,isCliMode:Se(t)||we(t),isWorking:t.status==="generating",contextKey:t.tabKey,receivedAtMap:L,onLoadMore:j,isLoadingMore:g,hasMoreHistory:v,hiddenLiveCount:M,loadError:N??void 0,emptyState:K}),!gs(t)&&(()=>{const C=t.streamSource!=="agent-stream",D=C?t.ideType:t.agentType,T=C?s!=null&&s.type?ke(s.type):ke(t.ideType||""):t.agentName||ke(t.agentType||""),R=!C&&(s!=null&&s.childSessions)&&s.childSessions.find(_=>_.id===t.sessionId||_.providerType===t.agentType)||s,q=R==null?void 0:R.providerControls,A=R==null?void 0:R.controlValues;return e.jsx(ka,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:D,displayLabel:T,controls:q,controlValues:A,serverModel:(R==null?void 0:R.currentModel)||void 0,serverMode:(R==null?void 0:R.currentPlan)||void 0,acpConfigOptions:we(t)?R==null?void 0:R.acpConfigOptions:void 0,acpModes:we(t)?R==null?void 0:R.acpModes:void 0})})(),e.jsx(Na,{contextKey:t.tabKey,panelLabel:B,isSending:r,onSend:n})]})}let Nn=mt;function ys(){return Nn()}class Oa{constructor(){je(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 Sn=new Oa;class za{constructor(){je(this,"ptyCallbacks",new Set)}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()=>{}}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,n,r){this.ptyCallbacks.forEach(i=>i(s,n,r))}onRuntimeEvent(s,n){return()=>{}}requestRuntimeSnapshot(s,n){return Promise.resolve()}}let ve=new za;function Ua(t){t.dashboardWS&&(Sn=t.dashboardWS),t.connectionManager&&(ve=t.connectionManager),t.useDaemonsHook&&(Nn=t.useDaemonsHook)}function Cn({activeConv:t,clearToken:s=0,terminalRef:n,handleSendChat:r,isSendingChat:i=!1}){var M;const o=a.useRef(null),{sendCommand:c,sendData:u}=Fe(),[l,x]=a.useState(""),[d,f]=a.useState(!1),h=a.useRef(0),m=a.useRef(!1),w=t.tabKey,b=t.sessionId||"",y=t.daemonId||((M=t.ideId)==null?void 0:M.split(":")[0])||t.ideId||"",p=()=>{var g,S;h.current=0,m.current=!1,f(!1),(S=(g=n.current)==null?void 0:g.reset)==null||S.call(g)},v=()=>{var g,S;h.current=0,m.current=!1,f(!0),(S=(g=n.current)==null?void 0:g.reset)==null||S.call(g)},N=(g,S=0)=>{var j,k,L;S>0&&h.current>=S||S===0&&m.current||(h.current=S,f(!0),(k=(j=n.current)==null?void 0:j.reset)==null||k.call(j),g&&((L=n.current)==null||L.write(g)))};return a.useEffect(()=>{p()},[b]),a.useEffect(()=>{var S;if(!b)return;const g=((S=ve.onRuntimeEvent)==null?void 0:S.call(ve,b,j=>{var k;if(!(!j||j.sessionId!==b)){if(j.type==="runtime_snapshot"){N(j.text||"",j.seq||0);return}if(j.type==="session_output"){m.current=!0,typeof j.seq=="number"&&(h.current=Math.max(h.current,j.seq)),f(!0),typeof j.data=="string"&&((k=n.current)==null||k.write(j.data));return}j.type==="session_cleared"&&v()}}))||(()=>{});return()=>{g()}},[y,b,n]),a.useEffect(()=>{var S,j,k;if(!b)return;y&&((S=ve.getState)==null?void 0:S.call(ve,y))==="connected"&&(f(!0),(j=ve.requestRuntimeSnapshot)==null||j.call(ve,y,b).catch(()=>{}));const g=(k=ve.onStateChange)==null?void 0:k.call(ve,(L,P)=>{var B;L!==y||P!=="connected"||(f(!0),(B=ve.requestRuntimeSnapshot)==null||B.call(ve,y,b).catch(()=>{}))});return()=>{g==null||g()}},[y,b,n]),a.useEffect(()=>{s&&p()},[s,w,n]),a.useEffect(()=>{x("")},[t.tabKey]),a.useEffect(()=>{const g=S=>{var k;const j=S.detail;j!=null&&j.sessionId&&j.sessionId!==b||d&&((k=n.current)==null||k.fit())};return window.addEventListener("adhdev:fit-cli-terminal",g),()=>{window.removeEventListener("adhdev:fit-cli-terminal",g)}},[d,b,n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx(bn,{ref:n,readOnly:!d,onInput:g=>{d&&(u!=null&&u(y,{type:"pty_input",targetSessionId:b,data:g})||c(y,"pty_input",{targetSessionId:b,data:g}).catch(console.error))},onResize:(g,S)=>{d&&(u!=null&&u(y,{type:"pty_resize",targetSessionId:b,cols:g,rows:S})||c(y,"pty_resize",{targetSessionId:b,cols:g,rows:S,force:!0}).catch(()=>{}))}},t.tabKey),!d&&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:o,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:l,onChange:g=>x(g.target.value),onPaste:g=>{const S=g.clipboardData.getData("text");S&&x(j=>j+S),g.preventDefault()},onKeyDown:g=>{if(g.key!=="Enter")return;if(g.nativeEvent.isComposing){g.preventDefault();return}g.preventDefault();const S=l.trim();!d||!S||i||(x(""),r(S))},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 g=l.trim();!d||!g||i||(x(""),r(g))},disabled:!d||!l.trim()||i,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${l.trim()&&!i?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:l.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:l.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function Fa({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)"},u={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:u[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 Ha({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 Va(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 u=Math.floor(c/60);if(u<60)return`${u}m${n}`;const l=Math.floor(u/60);if(l<24)return`${l}h${n}`;const x=Math.floor(l/24);return x<7?`${x}d${n}`:new Date(t).toLocaleDateString()}const at=t=>Va(t);function qa(t){return{unread:!!t.unread,lastSeenAt:t.lastSeenAt||0,lastUpdated:t.lastUpdated||0,inboxBucket:t.inboxBucket||"idle",surfaceHidden:!!t.surfaceHidden}}function zt(t){const s=new Map,n=(r,i)=>{r&&s.set(r,{sessionId:r,...qa(i)})};for(const r of t)if(!r.daemonMode){n(r.sessionId,r);for(const i of r.childSessions||[])n(i.id,i)}return s}function ot(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 Et(t,s,n){const r=ot(t,s),i=r.inboxBucket==="needs_attention",o=r.inboxBucket==="working",c=r.inboxBucket==="task_complete"&&r.unread&&!(n!=null&&n.hideOpenTaskCompleteUnread&&(n!=null&&n.isOpenConversation));return{unread:c,requiresAction:i,isWorking:o,inboxBucket:i?"needs_attention":o?"working":c?"task_complete":"idle"}}function In(t,s){return Et(t,s).unread}function Mn(t,s,n){return ot(t,n||new Map).surfaceHidden}function vs({mode:t,onChange:s,compact:n=!1}){const r=n?"h-7 w-7":"h-8 w-8";return e.jsxs("div",{className:"inline-flex items-center rounded-lg border border-border-subtle bg-bg-secondary/80 p-0.5 shadow-sm",role:"tablist","aria-label":"CLI view mode",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":t==="chat",onClick:()=>s("chat"),className:`${r} inline-flex items-center justify-center rounded-md transition-colors ${t==="chat"?"bg-violet-500/15 text-violet-300":"text-text-muted hover:text-text-primary hover:bg-bg-glass"}`,title:"Parsed chat view",children:e.jsx(Ge,{size:15})}),e.jsx("button",{type:"button",role:"tab","aria-selected":t==="terminal",onClick:()=>s("terminal"),className:`${r} inline-flex items-center justify-center rounded-md transition-colors ${t==="terminal"?"bg-sky-500/15 text-sky-300":"text-text-muted hover:text-text-primary hover:bg-bg-glass"}`,title:"Terminal view",children:e.jsx(bs,{size:15})})]})}function Ya({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,conversations:i,onOpenHistory:o,onOpenRemote:c,onStopCli:u,onFitCli:l,activeCliViewMode:x,onSetCliViewMode:d,onOpenConversation:f}){const h=ys(),m=h.p2pStates||{},w=h.ides||[],b=!!t&&Se(t)&&!we(t),y=x||(t?gs(t)?"terminal":"chat":null),p=!!t&&b&&y==="terminal",[v,N]=a.useState(!1),M=a.useRef(null),g=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",S=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",j=w.filter(A=>A.type==="adhdev-daemon"),k=a.useMemo(()=>zt(w),[w]),L=Object.values(m),P=L.filter(A=>A==="connected").length,B=L.filter(A=>A==="connecting"||A==="new"||A==="checking").length,C=n!=="connected"||j.length===0?null:B>0&&P===0?"P2P connecting...":P>0&&s===0?"Waiting for IDE...":null,D=a.useMemo(()=>i.filter(A=>!Mn(A,i,k)),[i,k]),T=a.useMemo(()=>D.filter(A=>Et(A,k).requiresAction),[D,k]),R=a.useMemo(()=>D.filter(A=>{const _=(t==null?void 0:t.tabKey)===A.tabKey;return Et(A,k,{hideOpenTaskCompleteUnread:!0,isOpenConversation:_}).unread}),[t,D,k]),q=T.length+R.length;return a.useEffect(()=>{if(!v)return;const A=_=>{var W;(W=M.current)!=null&&W.contains(_.target)||N(!1)};return document.addEventListener("mousedown",A),()=>document.removeEventListener("mousedown",A)},[v]),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(Ge,{size:18}),e.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),e.jsx("span",{className:"header-title-mobile",children:(t==null?void 0:t.displayPrimary)||"Dashboard"}),e.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:g,boxShadow:S}})})]}),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:g,boxShadow:S}}),C&&e.jsxs("span",{className:"header-subtitle-status",children:["· ",C]})]})]})})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsxs("div",{className:"dashboard-header-inbox",ref:M,children:[e.jsxs("button",{type:"button",onClick:()=>N(A=>!A),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(Ot,{size:16}),q>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:q})]}),v&&e.jsxs("div",{className:"dashboard-header-inbox-popover",children:[T.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Needs attention"}),T.map(A=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item is-attention",onClick:()=>{f==null||f(A),N(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:A.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:A.displaySecondary})]},A.tabKey))]}),R.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),R.map(A=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{f==null||f(A),N(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:A.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:A.displaySecondary})]},A.tabKey))]}),q===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]}),b&&u&&e.jsxs(e.Fragment,{children:[d&&y&&e.jsx(vs,{mode:y,onChange:d}),p&&e.jsx("button",{onClick:l,className:"btn btn-secondary btn-sm",title:"Fit terminal to current view",children:e.jsx(ta,{size:16})}),e.jsx("button",{onClick:u,className:"btn btn-secondary btn-sm text-red-400 border-red-500/25 hover:bg-red-500/10",title:"Stop CLI process",children:e.jsx(xn,{size:16})})]}),t&&!p&&!we(t)&&e.jsx("button",{onClick:()=>o(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(ms,{size:16})}),t&&!b&&!we(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Pe,{size:16})})]})]})}function Xa({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,onClose:i,onNewChat:o,onSwitchSession:c,onRefreshHistory:u}){var f;const l=s.find(h=>h.id===t.ideId),x=(l==null?void 0:l.chats)||[],d=(f=l==null?void 0:l.activeChat)==null?void 0:f.id;return e.jsxs("div",{className:"fixed inset-0 z-[1300] flex items-center justify-center",children:[e.jsx("div",{onClick:i,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"card fade-in relative w-[90%] max-w-[500px] max-h-[80vh] flex flex-col p-0 overflow-hidden shadow-[0_20px_40px_rgba(0,0,0,0.4)] rounded-[20px]",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-subtle flex justify-between items-center bg-[var(--surface-primary)]",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"m-0 text-lg font-extrabold",children:"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",ke(t.ideType)]})]}),e.jsx("button",{onClick:i,className:"bg-transparent border-none text-xl text-text-muted cursor-pointer",children:"✕"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 bg-bg-primary",children:[e.jsx("button",{onClick:o,disabled:n,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:n?"⌛ Creating...":"+ Start New Chat Session"}),x.map(h=>e.jsxs("div",{onClick:()=>{c(t.ideId,h.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${d===h.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${d===h.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:h.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:[h.id.substring(0,12),"..."]}),d===h.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},h.id)),x.length===0&&e.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[e.jsx("div",{className:"text-3xl mb-3 opacity-60",children:e.jsx(aa,{size:32})}),e.jsx("div",{className:"text-[13px]",children:"No recent chat sessions found."})]})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:u,disabled:r,className:"btn btn-secondary btn-sm rounded-[10px]",children:r?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ps,{size:13})," Refresh History"]})})})]})]})}const Bs={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 Tn({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:Bs[r.type]||Bs.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 An(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 Ga=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Ja(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function Za(t){return t.sessionId||t.instanceId||t.agentType}function Zt(t,s){return t||s}function yt(t){return An(t)}function Ks(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 Rn(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=We(r,{fallbackId:r.id}))}return s}function Ln(t,s,n={}){var h,m,w,b,y,p;const r=[],i=n.machineName,o=n.connectionState,c=Ja(t),u=ke(t.type),l=Array.isArray(t.childSessions)?t.childSessions.map(v=>{var N,M;return{sessionId:v.id,instanceId:v.id,agentType:v.providerType,agentName:v.providerName,status:v.status,title:v.title,messages:((N=v.activeChat)==null?void 0:N.messages)||[],activeModal:((M=v.activeChat)==null?void 0:M.activeModal)||void 0,unread:v.unread,lastSeenAt:v.lastSeenAt,lastUpdated:v.lastUpdated,inboxBucket:v.inboxBucket,surfaceHidden:v.surfaceHidden}}):[],x=Ga(t),d=t.activeChat||{title:""},f=d.title&&String(d.title).trim()?String(d.title).trim():"";if(x){const v=t.sessionId||t.instanceId,N=Ps(t.type),M=(h=t.activeChat)==null?void 0:h.activeModal,g=M&&Array.isArray(M.buttons)&&M.buttons.length>0,S=Ae((m=t.activeChat)==null?void 0:m.status,{activeModal:(w=t.activeChat)==null?void 0:w.activeModal})||Ae((y=(b=t.agents)==null?void 0:b[0])==null?void 0:y.status)||"idle",j=t.activeChat||{title:"",messages:[]};let k=j.title&&String(j.title).trim()?String(j.title).trim():"";const L=(p=t.activeChat)==null?void 0:p.id,P=t.chats;if(L&&Array.isArray(P)&&P.length>0){const T=P.find(R=>R.id===L||R.id&&String(R.id)===String(L));T!=null&&T.title&&String(T.title).trim()&&(k=String(T.title).trim())}const B=j.messages||[],K=Ks(s,[t.id,v]),C=new Map;B.filter(T=>T.role==="user").forEach(T=>{const R=yt(T.content);R&&C.set(R,(C.get(R)||0)+1)});const D=K.filter(T=>{const R=yt(T.content),q=C.get(R)||0;return q>0?(C.set(R,q-1),!1):!0});r.push({ideId:t.id,sessionId:v,nativeSessionId:v,transport:t.transport,daemonId:t.daemonId||void 0,mode:Se(t)?t.mode||"terminal":"chat",agentName:N,agentType:(Se(t)||we(t))&&(t.cliType||t.acpType)||t.type,status:S,title:k,messages:[...B,...D],resume:t.resume,ideType:t.cliType||t.acpType||t.type,workspaceName:c,displayPrimary:k||c||(Se(t)?t.mode==="chat"?N:"Terminal":N),displaySecondary:u,cdpConnected:t.cdpConnected,modalButtons:g?M.buttons:void 0,modalMessage:g?M.message:void 0,streamSource:"native",tabKey:Zt(v,t.id),machineName:i,connectionState:o})}if(x&&(Se(t)||we(t)))return r;for(const v of l){const N=v.activeModal&&Array.isArray(v.activeModal.buttons)&&v.activeModal.buttons.length>0,M=_a(v),g=Za(v),S=`${t.id}:${g}`,j=v.title&&String(v.title).trim()||"",k=La(j,v.agentName,v.agentType)?"":j,L=v.messages||[],P=Ks(s,[S,v.sessionId,v.instanceId]),B=new Map;L.filter(D=>D.role==="user").forEach(D=>{const T=yt(D.content);T&&B.set(T,(B.get(T)||0)+1)});const K=P.filter(D=>{const T=yt(D.content),R=B.get(T)||0;return R>0?(B.set(T,R-1),!1):!0});(L.length>0||K.length>0||N||k||!["idle","panel_hidden","disconnected","not_monitored"].includes(M))&&r.push({ideId:t.id,sessionId:v.sessionId||v.instanceId,nativeSessionId:t.sessionId||t.instanceId,transport:v.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:v.agentName,agentType:v.agentType,status:M,title:k,messages:[...L,...K],ideType:v.agentType,workspaceName:c,displayPrimary:k||f||c||u,displaySecondary:`${u}·${v.agentName}`,cdpConnected:t.cdpConnected,modalButtons:N?v.activeModal.buttons:void 0,modalMessage:N?v.activeModal.message:void 0,streamSource:"agent-stream",tabKey:Zt(v.sessionId||v.instanceId,S),machineName:i,connectionState:o})}return r.length===0&&r.push({ideId:t.id,sessionId:t.sessionId||t.instanceId,nativeSessionId:t.sessionId||t.instanceId,transport:t.transport,daemonId:t.daemonId||void 0,mode:"chat",agentName:Ps(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:c,displayPrimary:c||u,displaySecondary:u,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:Zt(t.sessionId||t.instanceId,t.id),connectionState:o}),r}function Qa(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 ei(t,s){const n=[],{daemonId:r,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now(),u=t.sessions||[],{topLevel:l,childrenByParent:x}=Qa(u),d=l.filter(m=>m.kind==="workspace"&&m.transport==="cdp-page"),f=l.filter(m=>m.kind==="agent"&&m.transport==="pty"),h=l.filter(m=>m.kind==="agent"&&m.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:d.some(m=>!!m.cdpConnected)});for(const m of d){const w=x.get(m.id)||[];n.push({id:`${r}:ide:${m.id}`,sessionId:m.id,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,status:m.cdpConnected?"online":"detected",daemonId:r,instanceId:m.id,workspace:m.workspace,terminals:0,childSessions:w,agents:w.map(b=>({id:b.id,name:b.providerName,type:b.providerType,status:b.status})),activeChat:m.activeChat,chats:[],cdpConnected:m.cdpConnected,currentModel:m.currentModel,currentPlan:m.currentPlan,currentAutoApprove:m.currentAutoApprove,lastUpdated:m.lastUpdated,unread:m.unread,lastSeenAt:m.lastSeenAt,inboxBucket:m.inboxBucket,surfaceHidden:m.surfaceHidden,controlValues:m.controlValues,providerControls:m.providerControls,timestamp:c})}for(const m of f)n.push({id:`${r}:cli:${m.id}`,sessionId:m.id,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,agentType:m.providerType,status:m.status||"running",daemonId:r,instanceId:m.id,cliName:m.providerName,mode:m.mode||"terminal",workspace:m.workspace||"",activeChat:m.activeChat,resume:m.resume,runtimeKey:m.runtimeKey,runtimeDisplayName:m.runtimeDisplayName,runtimeWorkspaceLabel:m.runtimeWorkspaceLabel,runtimeWriteOwner:m.runtimeWriteOwner??null,runtimeAttachedClients:m.runtimeAttachedClients??[],lastUpdated:m.lastUpdated,unread:m.unread,lastSeenAt:m.lastSeenAt,inboxBucket:m.inboxBucket,surfaceHidden:m.surfaceHidden,controlValues:m.controlValues,providerControls:m.providerControls,timestamp:c,_isCli:!0});for(const m of h)n.push({id:`${r}:acp:${m.id}`,sessionId:m.id,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,agentType:m.providerType,status:m.status||"running",daemonId:r,instanceId:m.id,cliName:m.providerName,mode:"chat",workspace:m.workspace||"",activeChat:m.activeChat,runtimeKey:m.runtimeKey,runtimeDisplayName:m.runtimeDisplayName,runtimeWorkspaceLabel:m.runtimeWorkspaceLabel,runtimeWriteOwner:m.runtimeWriteOwner??null,runtimeAttachedClients:m.runtimeAttachedClients??[],currentModel:m.currentModel,currentPlan:m.currentPlan,lastUpdated:m.lastUpdated,unread:m.unread,lastSeenAt:m.lastSeenAt,inboxBucket:m.inboxBucket,surfaceHidden:m.surfaceHidden,acpConfigOptions:m.acpConfigOptions,acpModes:m.acpModes,controlValues:m.controlValues,providerControls:m.providerControls,timestamp:c,_isAcp:!0});return n}function ti(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 si(t,s){const n=ti(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const _n=[{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:"💚"}],En=[{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:"🧩"}],Pn=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],Dn="adhdev_notification_prefs",Ws={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function ni(){try{const t=localStorage.getItem(Dn);if(t){const s=JSON.parse(t);return{...Ws,...s}}}catch{}return{...Ws}}function ri(t){try{localStorage.setItem(Dn,JSON.stringify(t))}catch{}}let $e=ni(),St=[];function ai(){St.forEach(t=>t())}function ii(){return{...$e}}function oi(t){$e={...$e,...t},ri($e),ai()}function ci(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return St.push(n),()=>{St=St.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{oi(n)},[]);return[{...$e},s]}function ct(t){if(!$e.globalEnabled)return!1;switch(t){case"disconnect":return $e.disconnectAlert;case"completion":return $e.completionAlert;case"approval":return $e.approvalAlert;case"browser":return $e.browserNotifications;default:return!0}}const li={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function di(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function $n(){return"Notification"in window&&Notification.permission==="granted"}let Ve=null;async function ui(){if(Ve!==null)return Ve;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return Ve=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(Ve=!!await t.pushManager.getSubscription(),Ve):(Ve=!1,!1)}catch{return Ve=!1,!1}}function os(t,s,n){if($n())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 hi(t,s={}){const n={...li,...s},r=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{ui().then(u=>{o.current=u})},[]);const c=a.useCallback((u,l,x)=>{const d=Date.now();d-i.current<n.throttleMs||(i.current=d,os(u,l,x))},[n.throttleMs]);a.useEffect(()=>{var u;if(!(!n.enabled||!$n())&&ct("browser")&&o.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,Ae(l.status,{activeModal:l.activeModal}));return}for(const l of t){const x=r.current.get(l.id),d=Ae(l.status,{activeModal:l.activeModal}),f=l.name||l.id;if(n.onApproval&&ct("approval")&&d==="waiting_approval"&&x!=="waiting_approval"){const h=((u=l.activeModal)==null?void 0:u.message)||"Action requires your approval";c(`🔔 ${f} — Approval needed`,h.slice(0,120),`approval-${l.id}`)}n.onComplete&&ct("completion")&&vn(x)&&d==="idle"&&c(`✅ ${f} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&d==="error"&&x!=="error"&&c(`⚠️ ${f} — Error`,"Agent encountered an error",`error-${l.id}`),r.current.set(l.id,d)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class mi{constructor(){je(this,"dedupMap",new Map);je(this,"DEDUP_WINDOW_MS",5e3);je(this,"DEDUP_MAX_SIZE",50);je(this,"DEDUP_CLEANUP_AGE_MS",1e4);je(this,"toastCallbacks",[]);je(this,"systemMessageCallbacks",[]);je(this,"clearSystemMessageCallbacks",[]);je(this,"resolveActionFn",null);je(this,"viewRequestRespondFn",null);je(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 d,f;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=ke(s.ideType||"");const u=this.resolveOwningDaemon(s);if(u){const h=We(u,{fallbackId:u.id});h&&(c=s.ideType==="adhdev-daemon"?h:`${h}/${c}`)}let l="",x="info";if(s.event==="agent:generating_completed"){const h=s.duration?` (${s.duration}s)`:"";l=`✅ ${c} agent task completed${h}`,x="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&ii().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`,x="warning",r){const h=s.modalMessage||"Approval requested",m=(d=s.modalButtons)!=null&&d.length?s.modalButtons.map(w=>`[${w}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${h}
|
|
42
|
-
${m}`,_localId:`sys_approval_${Date.now()}`})}if((f=s.modalButtons)!=null&&f.length&&this.resolveActionFn){const h=this.resolveActionRouteTarget(s);if(!h)return;const m=s.agentType||s.ideType||"",w=s.ideType||"",b=s.modalButtons,y=g=>g.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),p=this.resolveActionFn,v=b.map((g,S)=>{const j=y(g).toLowerCase(),k=/^(run|approve|accept|yes|allow|always)/.test(j),L=/^(reject|deny|delete|remove|abort|cancel|no)/.test(j);return{label:y(g),variant:k?"primary":L?"danger":"default",onClick:()=>{const P=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(j);p(h,"resolve_action",{action:P?"approve":"reject",button:g,buttonIndex:S,agentType:m,ideType:w,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),N=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,M=Date.now();this.emitToast({id:M,message:N,type:x,timestamp:M,targetKey:r||h,actions:v,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}`,x="warning",ct("browser")&&!document.hasFocus()&&os(`⚠️ ${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",m=s.requestId,w=s.orgId;if(l=`👁️ ${h} wants to view your session`,x="warning",m&&w&&this.viewRequestRespondFn){const b=this.viewRequestRespondFn,y=Date.now(),p=[{label:"Approve",variant:"primary",onClick:()=>{b(w,m,"approve").catch(v=>console.error("[EventManager] approve view request failed:",v))}},{label:"Decline",variant:"danger",onClick:()=>{b(w,m,"reject").catch(v=>console.error("[EventManager] reject view request failed:",v))}}];this.emitToast({id:y,message:l,type:x,timestamp:y,actions:p,duration:3e4}),l=""}ct("browser")&&!document.hasFocus()&&os("👁️ View Request",`${h} wants to view your session`,`view-request-${m}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",x="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,x="warning");if(l){const h=Date.now();this.emitToast({id:h,message:l,type:x,timestamp:h,targetKey:r||s.ideId,duration:5e3})}}}const ze=new mi;function Je(...t){return Ir(Mr(t))}function pi({icon:t,title:s,subtitle:n,badge:r,actions:i,className:o}){return e.jsxs("div",{className:Je("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 Pt({icon:t,title:s,subtitle:n,badge:r,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:u}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(pi,{icon:t,title:s,subtitle:n,badge:r,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:Je("mx-auto flex w-full flex-col gap-4",o,c),children:u})})]})}function Ie({title:t,icon:s,description:n,accentColor:r,className:i,children:o}){return e.jsxs("div",{className:Je("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 js({icon:t,title:s,description:n,action:r,className:i}){return e.jsxs("div",{className:Je("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 xi={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 bi({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:Je("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",xi[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 gi={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"},yi={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function vi({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:Je("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",gi[t],n),children:[e.jsx("span",{className:Je("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",yi[t])}),r]})}function ji(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function cs(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function Ct(t){return t==="system"?ji():t}function wi(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Ct(cs()))}function Bn(){const[t,s]=a.useState(cs),[n,r]=a.useState(()=>Ct(cs()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),u=l=>{t==="system"&&r(l.matches?"light":"dark")};return c.addEventListener("change",u),()=>c.removeEventListener("change",u)},[t]);const i=a.useCallback(c=>{s(c),r(Ct(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const u=c==="dark"?"light":c==="light"?"system":"dark";r(Ct(u));try{localStorage.setItem("theme",u)}catch{}return u})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function Ue({label:t,description:s,checked:n,disabled:r,onChange:i,extra:o}){return e.jsxs("label",{className:"flex justify-between items-center cursor-pointer",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted",children:s})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[o,e.jsx("input",{type:"checkbox",checked:n,disabled:r,onChange:c=>i(c.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function ki({onPrefChange:t}){const[s,n]=ci(),r=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Ue,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ot,{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(Ue,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pe,{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(Ue,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ia,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(Ue,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(oa,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(Ue,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Qe,{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(Ue,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ge,{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 Ni({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(js,{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(Ci,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i},c.id))})}function Os({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 Tr.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:u=>u.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick: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 Si(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[..._n,...En,...Pn].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 Ci({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){var D,T;const[o,c]=a.useState("idle"),[u,l]=a.useState(""),[x,d]=a.useState(null),[f,h]=a.useState("idle"),[m,w]=a.useState(""),b=t,y=b.version||b.daemonVersion||null,p=((D=b.machine)==null?void 0:D.platform)||((T=b.system)==null?void 0:T.platform)||"",v=We(b,{fallbackId:t.id}),N=p==="win32"?"🪟":p==="darwin"?"🍎":"🐧",M=s.filter(R=>R.daemonId===t.id&&R.transport==="cdp-page"),g=s.filter(R=>R.daemonId===t.id&&R.transport==="pty"),S=s.filter(R=>R.daemonId===t.id&&R.transport==="acp"),j=b.p2p,k=async()=>{var R,q,A,_;if(n){c("upgrading"),l("Starting upgrade...");try{const W=await n(t.id,"daemon_upgrade",{});(R=W==null?void 0:W.result)!=null&&R.alreadyLatest?(c("done"),l(`Already on v${W.result.version||"latest"}.`)):(q=W==null?void 0:W.result)!=null&&q.upgraded||(A=W==null?void 0:W.result)!=null&&A.success?(c("done"),l(`Upgrade to v${W.result.version||"latest"} started. Daemon is restarting...`)):(c("error"),l(((_=W==null?void 0:W.result)==null?void 0:_.error)||"Upgrade failed"))}catch(W){c("error"),l((W==null?void 0:W.message)||"Connection lost during upgrade")}}},L=async()=>{if(d(null),!!r){h("loading");try{await r(t.id),h("done"),w("Machine disconnected.")}catch(R){h("error"),w((R==null?void 0:R.message)||"Failed to disconnect")}}},P=async()=>{if(d(null),!!i){h("loading");try{await i(t.id),h("done"),w('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(R){h("error"),w((R==null?void 0:R.message)||"Failed to revoke token")}}},B="0.7.45",K=!y||y!==B,C=M.length+g.length+S.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:N}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:v}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),y&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${K?"":"bg-bg-secondary"}`,style:K?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",y,!K&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&K&&e.jsx("button",{onClick:k,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${B}`,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${B}`}`}),r&&e.jsx("button",{onClick:()=>d("disconnect"),disabled:f==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>d("revoke"),disabled:f==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(vi,{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:[j&&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 ${j.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${j.state==="connecting"||j.state==="new"?"animate-pulse":""}`,style:j.state==="connecting"||j.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",j.state==="connected"?"connected":j.state==="connecting"||j.state==="new"?"connecting...":j.state||"off"]}),j.peers!==void 0&&j.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",j.peers," peer",j.peers!==1?"s":"",")"]})]}),j&&C>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),C>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[M.map(R=>{const q=Si(R.type),A=R.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:q.icon}),e.jsx("span",{children:q.name}),A!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${A?"bg-green-400":"animate-pulse"}`,style:A?void 0:{background:"var(--status-warning)"},title:A?"CDP connected":"CDP connecting..."})]},R.id)}),g.map(R=>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:R.cliName||"CLI"})]},R.id)),S.map(R=>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:R.cliName||"ACP"})]},R.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(u||m)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||f==="error"?"text-red-400":o==="done"||f==="done"?"text-green-400":"text-text-muted"}`,children:m||u})]}),x==="disconnect"&&e.jsx(Os,{title:"🔌 Disconnect Machine",message:`Disconnect "${v}" from ADHDev?
|
|
43
|
-
|
|
44
|
-
This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
|
|
45
|
-
|
|
46
|
-
Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:L,onCancel:()=>d(null)}),x==="revoke"&&e.jsx(Os,{title:"⚠️ Remove Machine",message:`Remove "${v}" from your dashboard?
|
|
47
|
-
|
|
48
|
-
This will:
|
|
49
|
-
• Immediately disconnect the machine
|
|
50
|
-
• Delete the machine registration
|
|
51
|
-
• Require restarting "adhdev-standalone" on that machine
|
|
52
|
-
|
|
53
|
-
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:P,onCancel:()=>d(null)})]})}const Ii=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Mi(){const{preference:t,setPreference:s}=Bn();return e.jsx("div",{className:"flex gap-2",children:Ii.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 ls={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},ds={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},Ti=[{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"}}}],Kn="adhdev-chat-theme",Wn="adhdev-chat-theme-custom";function It(){return typeof window>"u"?"ember":localStorage.getItem(Kn)||"ember"}function De(t){try{const s=localStorage.getItem(Wn);if(s){const n=JSON.parse(s);return{...t==="dark"?ls:ds,...n[t]}}}catch{}return t==="dark"?ls:ds}function vt(t,s){localStorage.setItem(Wn,JSON.stringify({dark:t,light:s}))}function _e(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 Dt(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 Ai={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function lt(t,s){var i;const n=(i=Ai[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",Dt(n,24)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${Dt(n,18)})`),r.style.setProperty("--border-accent",_e(n,.35)),r.style.setProperty("--nav-active-bg",_e(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${_e(n,.06)}`)}function Ye(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",_e(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",_e(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",_e(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",_e(t.borderSubtle,.5)),s.style.setProperty("--border-default",_e(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",Dt(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${Dt(t.accentColor,40)})`),s.style.setProperty("--border-accent",_e(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",_e(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${_e(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 ${_e(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 ws(){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 Ri(t){if(localStorage.setItem(Kn,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Xe()?"dark":"light";Ye(De(s))}else ws(),lt(t,Xe()?"dark":"light")}function Li(){const t=It();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Xe()?"dark":"light";Ye(De(s))}else ws(),lt(t,Xe()?"dark":"light")}function Xe(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Ce({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 st({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 _i({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,i]=a.useState(()=>De(n));a.useEffect(()=>{i(De(n))},[n]);const o=a.useCallback((c,u)=>{i(l=>{const x={...l,[c]:u},f=De(n==="dark"?"light":"dark");return n==="dark"?vt(x,f):vt(f,x),Ye(x),s(x),x})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 18px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{children:[e.jsxs(st,{title:"App Background",children:[e.jsx(Ce,{label:"Background",value:r.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(Ce,{label:"Surface",value:r.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(Ce,{label:"Card",value:r.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(st,{title:"App Text",children:[e.jsx(Ce,{label:"Primary",value:r.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(Ce,{label:"Secondary",value:r.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(Ce,{label:"Muted",value:r.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(st,{title:"Borders & Accent",children:[e.jsx(Ce,{label:"Border subtle",value:r.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(Ce,{label:"Border default",value:r.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(Ce,{label:"Accent",value:r.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(st,{title:"Chat Bubbles",children:[e.jsx(Ce,{label:"User bubble",value:r.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(Ce,{label:"User text",value:r.userText,onChange:c=>o("userText",c)}),e.jsx(Ce,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(Ce,{label:"Agent text",value:r.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(st,{title:"Chat Layout",children:[e.jsx(Ce,{label:"Chat BG",value:r.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(Ce,{label:"Send button",value:r.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(Ce,{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?ls:ds,l=De(t?"light":"dark");t?vt(c,l):vt(l,c),i(c),Ye(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 Ei(){const[t,s]=a.useState(It),[n,r]=a.useState(!0),[i,o]=a.useState(()=>De("dark"));a.useEffect(()=>{r(Xe());const l=new MutationObserver(()=>{const f=Xe();r(f);const h=It();h==="custom"?Ye(De(f?"dark":"light")):lt(h,f?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>{const f=Xe();r(f);const h=It();h==="custom"?Ye(De(f?"dark":"light")):lt(h,f?"dark":"light")};return x.addEventListener("change",d),()=>{l.disconnect(),x.removeEventListener("change",d)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Ye(De(n?"dark":"light")):(ws(),lt(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{o(De(n?"dark":"light"))},[n]);const c=l=>{s(l),Ri(l)},u=[...Ti,{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:u.map(l=>{const x=t===l.id,d=n?l.preview.dark:l.preview.light,f=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:x?"var(--bg-glass-hover)":"var(--bg-glass)",border:x?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:x?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:d.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.userBubble,color:f},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(_i,{dark:n,onColorsChange:l=>o(l)})]})}const On="adhdev_mobileDashboardMode_v1";function zn(){try{return localStorage.getItem(On)==="workspace"?"workspace":"chat"}catch{return"chat"}}function Pi(t){try{localStorage.setItem(On,t)}catch{}}function Di(){const[t,s]=a.useState(!1);return a.useEffect(()=>{s(zn()==="workspace")},[]),e.jsx(Ue,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ge,{size:15})," Mobile dashboard layout"]}),description:t?"Use the full workspace layout on phones and tablets.":"Use the chat-first mobile inbox by default. This keeps mobile closer to a messaging app.",checked:t,onChange:n=>{s(n),Pi(n?"workspace":"chat")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Workspace":"Chat mode"})})}const Un="adhdev_hiddenTabs";function $i(){try{const t=localStorage.getItem(Un);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function nt(t){try{localStorage.setItem(Un,JSON.stringify([...t]))}catch{}}function Fn(){const[t,s]=a.useState($i),n=a.useCallback(l=>{s(x=>{const d=new Set(x);return d.has(l)?d.delete(l):d.add(l),nt(d),d})},[]),r=a.useCallback(l=>{s(x=>{if(x.has(l))return x;const d=new Set(x);return d.add(l),nt(d),d})},[]),i=a.useCallback(l=>{s(x=>{if(!x.has(l))return x;const d=new Set(x);return d.delete(l),nt(d),d})},[]),o=a.useCallback((l,x)=>{s(d=>{const f=new Set(d);for(const h of x)f.add(h);return nt(f),f})},[]),c=a.useCallback((l,x)=>{s(d=>{const f=new Set(d);for(const h of x)f.delete(h);return nt(f),f})},[]),u=a.useCallback(l=>t.has(l),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:i,hideAllForDaemon:o,showAllForDaemon:c,isHidden:u}}function Bi(){return typeof window>"u"?!0:window.confirm(`Fitting the terminal may resize or visually break some CLI apps.
|
|
54
|
-
|
|
55
|
-
Resize the terminal anyway?`)}function Ki({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){a.useEffect(()=>{di()},[]);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 hi(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{n(u=>{const l=Date.now(),x={};for(const[d,f]of Object.entries(u))l-f<5e3&&(x[d]=f);return Object.keys(x).length===Object.keys(u).length?u:x})},5500);return()=>clearTimeout(c)},[s,n]),a.useEffect(()=>{const o=setInterval(()=>{const c=Date.now()-3e5;r(u=>{const l=u.filter(x=>x.timestamp>c).slice(-100);return l.length===u.length?u:l})},6e4);return()=>clearInterval(o)},[r]),null}function Qt(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 Mt(t){const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1];return Qt(s==null?void 0:s.timestamp)||Qt(s==null?void 0:s.receivedAt)||Qt(s==null?void 0:s.createdAt)||0}function dt(t,s=0){return Mt(t)||s||0}function Hn(t,s){const n=dt(s)-dt(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 Wi(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 jt(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 Oi(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 zi(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 Ui(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 Fi({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:i}){const o=a.useRef([]),c=a.useRef([]),u=a.useRef([]),l=a.useRef([]),x=a.useMemo(()=>{const M=Wi(t);return jt(o.current,M)?o.current:(o.current=M,M)},[t]),d=a.useMemo(()=>Rn(t),[t]),f=a.useRef(new Map),h=a.useMemo(()=>{var S;const M=new Map,g=[];for(const j of x){const k=j.daemonId||((S=j.id)==null?void 0:S.split(":")[0])||j.id,L=s[k]||"new",P=j.daemonId&&d[j.daemonId]||void 0,B=zi(j,n),K=f.current.get(j.id);if(K&&K.ide===j&&K.connectionState===L&&K.machineName===P&&Ui(K.localRefs,B)){M.set(j.id,K),g.push(...K.conversations);continue}const C=Ln(j,n,{machineName:P,connectionState:L}),D={ide:j,connectionState:L,machineName:P,localRefs:B,conversations:C};M.set(j.id,D),g.push(...C)}return f.current=M,[...g].sort(Hn)},[x,n,s,d]),m=a.useMemo(()=>{const M=Oi(h,r);return jt(c.current,M)?c.current:(c.current=M,M)},[h,r]),w=a.useMemo(()=>{const M=new Map;for(const g of m)g.sessionId&&M.set(g.sessionId,g);return M},[m]),b=a.useMemo(()=>{const M=new Map;for(const g of m)g.sessionId&&M.set(g.sessionId,g),M.set(g.ideId,g),M.set(g.tabKey,g);return M},[m]),y=a.useCallback(M=>{if(M)return w.get(M)},[w]),p=a.useCallback(M=>{if(M)return b.get(M)},[b]),v=a.useMemo(()=>{const M=m.filter(g=>!i.has(g.tabKey));return jt(u.current,M)?u.current:(u.current=M,M)},[m,i]),N=a.useMemo(()=>{const M=v.map(g=>g.tabKey);return jt(l.current,M)?l.current:(l.current=M,M)},[v]);return{chatIdes:x,conversations:m,visibleConversations:v,visibleTabKeys:N,resolveConversationBySessionId:y,resolveConversationByTarget:p}}function Hi({isMobile:t,urlActiveTab:s,resolveConversationBySessionId:n,setSearchParams:r}){const i=a.useMemo(()=>{var u;return t||!s?null:((u=n(s))==null?void 0:u.tabKey)??null},[t,n,s]),o=a.useMemo(()=>{var u;return!t||!s?null:((u=n(s))==null?void 0:u.tabKey)??null},[t,n,s]),c=a.useCallback(()=>{s&&r(u=>{const l=new URLSearchParams(u);return l.delete("activeTab"),l},{replace:!0})},[r,s]);return{requestedDesktopTabKey:i,requestedMobileTabKey:o,consumeRequestedActiveTab:c}}function Vi({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:i}){a.useEffect(()=>{ze.setIdes(t)},[t]),a.useEffect(()=>{ze.setResolveAction((o,c,u)=>{s(o,c,u).catch(()=>{})})},[s]),a.useEffect(()=>{const o=ze.onToast(l=>{n(d=>d.some(h=>h.message===l.message&&l.timestamp-h.timestamp<3e3)?d:[...d.slice(-4),{id:l.id,message:l.message,type:l.type,timestamp:l.timestamp,targetKey:l.targetKey,actions:l.actions}]);const x=l.duration||5e3;setTimeout(()=>n(d=>d.filter(f=>f.id!==l.id)),x)}),c=ze.onSystemMessage((l,x)=>{r(d=>({...d,[l]:[...d[l]||[],x]}))}),u=ze.onClearSystemMessage((l,x)=>{r(d=>{var f;return(f=d[l])!=null&&f.length?{...d,[l]:d[l].filter(h=>{var m;return!(h.role==="system"&&((m=h._localId)!=null&&m.startsWith(x)))})}:d})});return()=>{o(),c(),u()}},[n,r]),a.useEffect(()=>{const o=Sn.on("status_event",c=>ze.handleRawEvent(c,"ws"));return()=>{o()}},[]),a.useEffect(()=>{var c;const o=u=>{const l=u.data;if((l==null?void 0:l.type)!=="notification_action"||l.action!=="approve"||!(l.ideId||l.targetSessionId||l.targetKey))return;const x=l.targetSessionId||l.targetKey||l.ideId,d=i(x),f=(d==null?void 0:d.ideId)||l.ideId;f&&s(f,"resolve_action",{action:"approve",button:"Approve",...(d==null?void 0:d.sessionId)&&{targetSessionId:d.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 u;return(u=navigator.serviceWorker)==null?void 0:u.removeEventListener("message",o)}},[i,s])}const qi="adhdev_dashboardLayout_v1",Yi="adhdev_dashboardDockview_v1",rt={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function Vn(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function qn(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function Yn(t){return`${qi}:${t}`}function Xi(t){const s=Yn(t);return Vn(s,null)}function Gi(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=Yn(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Xn(t){return`${Yi}:${t}`}function Ji(t){const s=Xn(t);return Vn(s,null)}function Zi(t,s){try{const n=Xn(t);if(!s){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function Qi(){return{groupAssignments:[...rt.groupAssignments],focusedGroup:rt.focusedGroup,groupActiveTabIds:{...rt.groupActiveTabIds},groupTabOrders:{...rt.groupTabOrders},groupSizes:[...rt.groupSizes]}}function eo(){const[t]=a.useState(()=>qn(typeof window<"u"?window.innerWidth:1280)),[s,n]=a.useState(()=>new Map),[r,i]=a.useState(0),[o,c]=a.useState({}),[u,l]=a.useState({}),[x,d]=a.useState([]),[f,h]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[m,w]=a.useState(!1),b=a.useCallback(()=>{if(m)return;const y=Xi(t)??Qi();n(new Map(y.groupAssignments)),i(y.focusedGroup),c(y.groupActiveTabIds),l(y.groupTabOrders),d(y.groupSizes),w(!0)},[m,t]);return a.useEffect(()=>{m&&Gi(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:o,groupTabOrders:u,groupSizes:x})},[m,t,s,r,o,u,x]),a.useEffect(()=>{const y=window.matchMedia("(max-width: 767px)"),p=v=>h(v.matches);return y.addEventListener("change",p),()=>y.removeEventListener("change",p)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:u,setGroupTabOrders:l,groupSizes:x,setGroupSizes:d,isMobile:f,hasHydratedStoredLayout:m,hydrateStoredLayout:b}}function to({urlActiveTab:t,conversations:s,resolveConversationBySessionId:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:u,setSearchParams:l,historyModalOpen:x,activeConv:d,isRefreshingHistory:f,ides:h,handleRefreshHistory:m}){const w=a.useRef(!1),b=a.useRef(!1),y=a.useRef(null),p=a.useRef(!1);a.useEffect(()=>{if(!t||w.current||s.length===0)return;if(!i){o();return}const v=n(t);if(!v)return;const N=r.get(v.tabKey)??0;c(M=>({...M,[N]:v.tabKey})),u(N),w.current=!0,b.current=!0,y.current!=null&&(window.clearTimeout(y.current),y.current=null),l(M=>{const g=new URLSearchParams(M);return g.delete("activeTab"),g},{replace:!0})},[t,s,n,r,i,o,c,u,l]),a.useEffect(()=>{if(!(b.current||i)&&s.length!==0){if(!t){o(),b.current=!0;return}if(w.current){b.current=!0;return}if(y.current==null)return y.current=window.setTimeout(()=>{y.current=null,!(b.current||i)&&(o(),b.current=!0)},1500),()=>{y.current!=null&&(window.clearTimeout(y.current),y.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!x){p.current=!1;return}if(!d||p.current||f)return;const v=h.find(N=>N.id===d.ideId);v&&(!v.chats||v.chats.length===0)&&(p.current=!0,m())},[x,d,f,h,m]),a.useEffect(()=>{if(!d)return;let v=null,N=0,M=-1,g=0;const S=()=>{v=null;const j=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(L=>L.offsetParent!==null);if(j.length===0){N<18&&(N+=1,v=requestAnimationFrame(S));return}let k=0;for(const L of j)L.scrollTop=L.scrollHeight,k+=L.scrollHeight;k===M?g+=1:(g=0,M=k),N+=1,!(g>=2||N>=18)&&(v=requestAnimationFrame(S))};return v=requestAnimationFrame(S),()=>{v!=null&&cancelAnimationFrame(v)}},[d==null?void 0:d.tabKey])}function so({isMobile:t,location:s,navigate:n,requestedRemoteTabTarget:r,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:u}){const[l,x]=a.useState(null),[d,f]=a.useState(null),h=a.useMemo(()=>{if(t||!r)return null;const p=u(r);return p&&!Se(p)&&!we(p)?p:null},[t,r,u]),m=a.useMemo(()=>{const p=l==null?void 0:l.ideId;if(!p)return null;const v=l!=null&&l.tabKey?o.find(N=>N.tabKey===l.tabKey):i?o.find(N=>N.tabKey===i):null;return(v==null?void 0:v.ideId)===p?v:o.find(N=>N.ideId===p&&N.streamSource==="native")||o.find(N=>N.ideId===p)||null},[o,l,i]),w=a.useMemo(()=>{if(m)return c.find(p=>p.id===m.ideId)},[c,m]);a.useEffect(()=>{h&&(x({ideId:h.ideId,tabKey:h.streamSource==="native"?"native":h.tabKey}),f(h),n({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,n,h]);const b=a.useCallback(p=>{p&&(x({ideId:p.ideId,tabKey:p.streamSource==="native"?"native":p.tabKey}),f(p))},[]),y=a.useCallback(()=>{x(null),f(null)},[]);return{remoteDialogConv:m,remoteDialogIdeEntry:w,remoteDialogActiveConv:d,setRemoteDialogActiveConv:f,openRemoteDialog:b,closeRemoteDialog:y}}function ut(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Se(t)||we(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function $t(t){return t&&(t.ideId||t.daemonId)||""}function wt(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function zs({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:i,setClearedTabs:o}){const[c,u]=a.useState(!1),[l,x]=a.useState(!1),d=a.useCallback(async w=>{try{await t("standalone","launch_ide",{ideType:w,enableCdp:!0})}catch(b){console.error("Launch failed",b)}},[t]),f=a.useCallback(async(w,b)=>{try{const y=w||(s==null?void 0:s.daemonId)||"",p=await t(y,"switch_chat",{id:b,sessionId:b,...ut(s)}),v=p==null?void 0:p.result;if((p==null?void 0:p.success)===!0||v==="switched"||v==="switched-by-title")return;v===!1||v==="not_found"?wt(r,"⚠️ Session tab not found — try refreshing history"):typeof v=="string"&&v.startsWith("error:")?wt(r,`⚠️ Switch error: ${v}`):wt(r,"⚠️ Session switch failed")}catch(y){console.error("Switch failed",y),wt(r,`❌ Switch failed: ${y.message||"connection error"}`)}},[s,t,r]),h=a.useCallback(async()=>{if(!(!s||c)){u(!0);try{const w=$t(s);await t(w,"new_chat",{...ut(s)}),o(b=>({...b,[s.tabKey]:Date.now()})),i(b=>({...b,[s.tabKey]:[]}))}catch(w){console.error("New chat failed",w)}finally{u(!1)}}},[s,c,t,o,i]),m=a.useCallback(async()=>{var w;if(!(!s||l)){x(!0);try{const b=$t(s),y=await t(b,"list_chats",{forceExpand:!0,...ut(s)}),p=(y==null?void 0:y.chats)||((w=y==null?void 0:y.result)==null?void 0:w.chats);y!=null&&y.success&&Array.isArray(p)&&n(s.ideId,p)}catch(b){console.error("Refresh history failed",b)}finally{x(!1)}}},[s,l,t,n]);return{isCreatingChat:c,isRefreshingHistory:l,handleLaunchIde:d,handleSwitchSession:f,handleNewChat:h,handleRefreshHistory:m}}function no(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 ro(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function Us(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 kt(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[c,u]of t)!n.has(c)||u<=0||r.includes(u)||r.push(u);r.sort((c,u)=>c-u);const i={};r.forEach((c,u)=>{i[c]=u}),r.length===0&&(i[0]=0);const o=new Map;for(const[c,u]of t){if(!n.has(c)||u<=0)continue;const l=i[u];typeof l=="number"&&l>0&&o.set(c,l)}return{assignments:o,groupCount:Math.max(1,r.length),mapping:i,usedGroups:r}}function Fs(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 ao(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 io(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,u)=>c+u,0);return o>0?i.map(c=>c/o*100):Array(n).fill(100/n)}function Hs(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 Vs(t){return Array(t).fill(100/t)}function oo({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:u,visibleConversations:l,visibleTabKeys:x}){const d=a.useRef(null),f=a.useMemo(()=>kt(t,x),[t,x]),h=f.assignments,m=a.useMemo(()=>u?1:f.groupCount,[f.groupCount,u]),w=m>1,b=a.useCallback((g,S)=>{s(j=>{const k=new Map(kt(j,x).assignments);return S===0?k.delete(g):k.set(g,S),k}),r(j=>({...j,[S]:g})),n(S)},[s,x,r,n]),y=a.useCallback(g=>{s(S=>{const j=kt(S,x).assignments,k=new Map;for(const[L,P]of j)P!==g&&(P>g?k.set(L,P-1):k.set(L,P));return k}),c(S=>{if(S.length<=1)return[];const j=[...S];j.splice(g,1);const k=j.reduce((L,P)=>L+P,0);return k>0?j.map(L=>L/k*100):[]}),n(0)},[s,x,c,n]),p=a.useCallback((g,S)=>{S.preventDefault();const j=d.current;if(!j)return;const k=S.clientX,L=j.offsetWidth,P=o.length===m?[...o]:Vs(m),B=C=>{const T=(C.clientX-k)/L*100,R=[...P];R[g]=Math.max(15,P[g]+T),R[g+1]=Math.max(15,P[g+1]-T),c(R)},K=()=>{document.removeEventListener("mousemove",B),document.removeEventListener("mouseup",K),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",B),document.addEventListener("mouseup",K)},[o,m,c]),v=a.useCallback((g,S,j)=>{if(m>=4)return;const k=j==="left"?S:S+1;s(L=>{const P=kt(L,x).assignments,B=new Map;for(const K of l){const C=P.get(K.tabKey)??0,D=C>=k?C+1:C;D>0&&B.set(K.tabKey,D)}return k>0&&B.set(g,k),B}),c(L=>{const P=L.length===m?[...L]:Vs(m),B=P[S]??100/m,K=Math.max(15,B/2),C=Math.max(15,B/2),D=[...P];D[S]=K,D.splice(k,0,C);const T=D.reduce((R,q)=>R+q,0);return D.map(R=>R/T*100)}),r(L=>{const P=Hs(L,k);return P[k]=g,P}),i(L=>{const P=Hs(L,k);return P[k]=[g],P}),n(k)},[m,s,x,l,c,r,i,n]);a.useEffect(()=>{no(t,h)||s(h)},[t,h,s]),a.useEffect(()=>{const{mapping:g,usedGroups:S}=f;r(j=>{const k=Fs(j,g);return Us(j,k)?j:k}),i(j=>{const k=Fs(j,g);return Us(j,k)?j:k}),n(j=>{const k=u?0:ao(j,S,g);return j===k?j:k}),c(j=>{const k=u?[]:io(j,S,f.groupCount);return ro(j,k)?j:k})},[f,u,r,i,n,c]);const N=a.useMemo(()=>{const g=Array.from({length:m},()=>[]);for(const S of l){const j=h.get(S.tabKey)??0,k=Math.min(j,m-1);g[k].push(S)}return g},[l,h,m]),M=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:d,normalizedGroupAssignments:h,numGroups:m,isSplitMode:w,groupedConvs:N,moveTabToGroup:b,closeGroup:y,handleResizeStart:p,splitTabRelative:v,clearAllSplits:M}}function co({ides:t,sendDaemonCommand:s}){const n="0.7.45",r=a.useMemo(()=>t.filter(x=>{if(x.type!=="adhdev-daemon")return!1;const d=x.version||x.daemonVersion||null;return!d||!n?!1:d!==n}),[n,t]),[i,o]=a.useState(!1),[c,u]=a.useState({}),l=a.useCallback(async x=>{var d,f;u(h=>({...h,[x]:"upgrading"}));try{const h=await s(x,"daemon_upgrade",{});(d=h==null?void 0:h.result)!=null&&d.upgraded||(f=h==null?void 0:h.result)!=null&&f.success?u(m=>({...m,[x]:"done"})):u(m=>({...m,[x]:"error"}))}catch{u(h=>({...h,[x]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:l}}function Ut({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:i}){const[o,c]=a.useState(!1),[u,l]=a.useState(!1),x=a.useRef(!1),d=a.useCallback(async w=>{if(!s)return;const b=w.trim();if(!b||x.current)return;const y=s.tabKey;x.current=!0,l(!0);const p=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,v={role:"user",content:b,timestamp:Date.now(),_localId:p};n(N=>({...N,[y]:[...N[y]||[],v]}));try{const N=$t(s);if(!N)return;await t(N,"send_chat",{message:b,text:b,...ut(s)}),setTimeout(()=>{const M=Date.now()-6e4;n(g=>{const S=g[y];if(!S)return g;const j=S.filter(k=>k.timestamp>M);return j.length===S.length?g:{...g,[y]:j}})},6e4)}catch(N){console.error("Send failed",N),n(M=>({...M,[y]:(M[y]||[]).filter(g=>g._localId!==p)}))}finally{x.current=!1,l(!1)}},[s,t,n]),f=a.useCallback(async()=>{if(s)try{await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0})}catch(w){console.error("Relaunch failed",w)}},[s,t]),h=a.useCallback(async w=>{if(s){r(b=>[...b,{ideId:s.tabKey,text:`🖱️ **${w}** clicked`,timestamp:Date.now()}]);try{const y=(s.modalButtons||[]).indexOf(w),p=w.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),v=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(p),N=$t(s);if(!N)return;(await t(N,"resolve_action",{button:w,action:v?"approve":"reject",...y>=0&&{buttonIndex:y},...ut(s)})).success||r(g=>[...g,{ideId:s.tabKey,text:`⚠️ **${w}** failed — button not found`,timestamp:Date.now()}])}catch(b){console.error("[ModalButton] Error:",b),r(y=>[...y,{ideId:s.tabKey,text:`❌ **${w}** error`,timestamp:Date.now()}])}}},[s,t,r]),m=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(w){console.error("Focus agent failed",w)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:u,isFocusingAgent:o,handleSendChat:d,handleRelaunch:f,handleModalButton:h,handleFocusAgent:m}}function lo({selectedConversation:t,isAcp:s,selectedIdeEntry:n,actionLogs:r,userName:i,isSendingChat:o,isFocusingAgent:c,onBack:u,onOpenNativeConversation:l,onOpenMachine:x,onOpenHistory:d,onOpenRemote:f,cliViewMode:h,onSetCliViewMode:m,handleSendChat:w,handleFocusAgent:b}){const y=a.useRef(null),p=Se(t)&&!s,v=p&&h==="terminal";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dashboard-mobile-chat-header",children:[e.jsxs("div",{className:"dashboard-mobile-chat-header-row",children:[e.jsx("button",{className:"dashboard-mobile-chat-back",onClick:u,type:"button","aria-label":"Back",children:e.jsx(un,{size:18})}),e.jsxs("div",{className:"dashboard-mobile-chat-title-block",children:[e.jsx("div",{className:"dashboard-mobile-chat-title",children:t.displayPrimary||t.agentName}),e.jsx("div",{className:"dashboard-mobile-chat-subtitle",children:e.jsx(kn,{conversation:t,onOpenNativeConversation:()=>l(t),onOpenMachine:()=>x(t)})})]})]}),e.jsxs("div",{className:"dashboard-mobile-chat-toolbar",children:[p&&h&&e.jsx(vs,{mode:h,onChange:m,compact:!0}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>d(t),type:"button",children:e.jsx(ms,{size:14})}),!s&&!p&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>f(t),type:"button",children:e.jsx(Pe,{size:14})})]})]}),e.jsx("div",{className:"dashboard-mobile-chat-thread",children:p?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:v?"flex":"none",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Cn,{activeConv:t,terminalRef:y,handleSendChat:w,isSendingChat:o})}),e.jsx("div",{style:{display:v?"none":"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(pt,{activeConv:t,ideEntry:n,showMetaChips:!1,handleSendChat:w,isSendingChat:o,handleFocusAgent:b,isFocusingAgent:c,actionLogs:r,userName:i})})]}):e.jsx(pt,{activeConv:t,ideEntry:n,showMetaChips:!1,handleSendChat:w,isSendingChat:o,handleFocusAgent:b,isFocusingAgent:c,actionLogs:r,userName:i},t.tabKey)})]})}function uo({section:t,attentionItems:s,unreadItems:n,workingItems:r,completedItems:i,machineCards:o,getAvatarText:c,onOpenConversation:u,onOpenMachine:l,onOpenSettings:x,onSectionChange:d}){const f=t==="machines"?"Machines":t==="settings"?"Settings":"Chats";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dashboard-mobile-chat-inbox-header",children:[e.jsx("div",{className:"dashboard-mobile-chat-inbox-title",children:e.jsx("div",{className:"dashboard-mobile-chat-app-title",children:e.jsx("span",{children:f})})}),t==="chats"&&(s.length>0||n.length>0)&&e.jsxs("div",{className:"dashboard-mobile-chat-header-pill",children:[e.jsx(Ot,{size:13}),e.jsx("span",{children:s.length+n.length})]})]}),e.jsxs("div",{className:"dashboard-mobile-chat-inbox",children:[t==="chats"&&s.length>0&&e.jsx("section",{className:"dashboard-mobile-chat-section",children:e.jsxs("div",{className:"dashboard-mobile-chat-alert-panel",children:[e.jsx("span",{className:"dashboard-mobile-chat-alert-title",children:"Needs attention"}),e.jsxs("span",{className:"dashboard-mobile-chat-alert-meta",children:[s.length," action needed"]})]})}),t==="chats"&&n.length>0&&e.jsx("section",{className:"dashboard-mobile-chat-section",children:e.jsxs("div",{className:"dashboard-mobile-chat-alert-panel",children:[e.jsx("span",{className:"dashboard-mobile-chat-alert-title",children:"Task complete"}),e.jsxs("span",{className:"dashboard-mobile-chat-alert-meta",children:[n.length," unread"]})]})}),t==="machines"&&e.jsxs("section",{className:"dashboard-mobile-chat-section",children:[o.map(h=>e.jsxs("button",{className:"dashboard-mobile-chat-card",onClick:()=>l(h.id),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar machine",children:c(h.label)}),e.jsxs("div",{className:"dashboard-mobile-chat-card-main",children:[e.jsxs("div",{className:"dashboard-mobile-chat-card-top",children:[e.jsx("span",{className:"dashboard-mobile-chat-card-title",children:h.label}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:h.unread>0?`${h.unread} new`:h.total>0?`${h.total} chats`:"Idle"})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:h.subtitle}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:h.preview})]})]},h.id)),o.length===0&&e.jsx("div",{className:"dashboard-mobile-chat-empty",children:"No connected machines yet."})]}),t==="chats"&&s.length>0&&e.jsxs("section",{className:"dashboard-mobile-chat-section",children:[e.jsx("div",{className:"dashboard-mobile-chat-section-title",children:"Needs attention"}),s.map(h=>e.jsxs("button",{className:"dashboard-mobile-chat-card is-unread",onClick:()=>u(h.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar unread",children:c(h.conversation.displayPrimary)}),e.jsxs("div",{className:"dashboard-mobile-chat-card-main",children:[e.jsxs("div",{className:"dashboard-mobile-chat-card-top",children:[e.jsx("span",{className:"dashboard-mobile-chat-card-title",children:h.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:at(h.timestamp)})]}),e.jsxs("div",{className:"dashboard-mobile-chat-card-subtitle",children:[h.conversation.displaySecondary," · Action needed"]}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:h.preview})]}),e.jsx("span",{className:"dashboard-mobile-chat-unread-dot"})]},h.conversation.tabKey))]}),t==="chats"&&n.length>0&&e.jsxs("section",{className:"dashboard-mobile-chat-section",children:[e.jsx("div",{className:"dashboard-mobile-chat-section-title",children:"Task complete"}),n.map(h=>e.jsxs("button",{className:"dashboard-mobile-chat-card is-unread",onClick:()=>u(h.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar unread",children:c(h.conversation.displayPrimary)}),e.jsxs("div",{className:"dashboard-mobile-chat-card-main",children:[e.jsxs("div",{className:"dashboard-mobile-chat-card-top",children:[e.jsx("span",{className:"dashboard-mobile-chat-card-title",children:h.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:at(h.timestamp)})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:h.conversation.displaySecondary}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:h.preview})]}),e.jsx("span",{className:"dashboard-mobile-chat-unread-dot"})]},h.conversation.tabKey))]}),t==="chats"&&r.length>0&&e.jsxs("section",{className:"dashboard-mobile-chat-section",children:[e.jsx("div",{className:"dashboard-mobile-chat-section-title",children:"Working now"}),r.map(h=>e.jsxs("button",{className:"dashboard-mobile-chat-card",onClick:()=>u(h.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar working",children:c(h.conversation.displayPrimary)}),e.jsxs("div",{className:"dashboard-mobile-chat-card-main",children:[e.jsxs("div",{className:"dashboard-mobile-chat-card-top",children:[e.jsx("span",{className:"dashboard-mobile-chat-card-title",children:h.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:at(h.timestamp)})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:h.conversation.displaySecondary}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:h.preview})]}),e.jsx("span",{className:"dashboard-mobile-chat-status-badge",children:"Live"})]},h.conversation.tabKey))]}),t==="chats"&&e.jsxs("section",{className:"dashboard-mobile-chat-section",children:[i.length>0&&e.jsx("div",{className:"dashboard-mobile-chat-section-title",children:"Earlier"}),i.length>0?i.map(h=>e.jsxs("button",{className:"dashboard-mobile-chat-card is-muted",onClick:()=>u(h.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar",children:c(h.conversation.displayPrimary)}),e.jsxs("div",{className:"dashboard-mobile-chat-card-main",children:[e.jsxs("div",{className:"dashboard-mobile-chat-card-top",children:[e.jsx("span",{className:"dashboard-mobile-chat-card-title",children:h.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:at(h.timestamp)})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:h.conversation.displaySecondary}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:h.preview})]})]},h.conversation.tabKey)):e.jsx("div",{className:"dashboard-mobile-chat-empty",children:"No completed conversations yet."})]}),t==="settings"&&e.jsxs("section",{className:"dashboard-mobile-chat-section",children:[e.jsxs("button",{className:"dashboard-mobile-chat-card",onClick:x,type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar settings",children:e.jsx(Wt,{size:16})}),e.jsxs("div",{className:"dashboard-mobile-chat-card-main",children:[e.jsx("div",{className:"dashboard-mobile-chat-card-top",children:e.jsx("span",{className:"dashboard-mobile-chat-card-title",children:"Appearance & chat settings"})}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:"Theme, accent, chat visuals"}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:"Open the full settings page for theme, notifications, and provider preferences."})]})]}),e.jsx("div",{className:"dashboard-mobile-chat-settings-note",children:"Notifications panel: unread and action-needed conversations are surfaced in the Chats section. Mobile workspace mode can be enabled from Settings."})]})]}),e.jsx("div",{className:"dashboard-mobile-chat-nav",children:[["machines","Machines"],["chats","Chats"],["settings","Settings"]].map(([h,m])=>e.jsx("button",{className:`dashboard-mobile-chat-nav-tab${t===h?" is-active":""}`,onClick:()=>d(h),type:"button",children:m},h))})]})}function ho({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:n,cliProviders:r,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:u,onBack:l,onOpenConversation:x,onOpenRecent:d,onOpenMachineDetails:f,onMachineUpgrade:h,onLaunchDetectedIde:m,onAddWorkspace:w,onLaunchWorkspaceProvider:b}){var U,ie,H;const y=(F,le,ne)=>F?"ide":le>0?"cli":ne>0?"acp":null,[p,v]=a.useState(!1),N=F=>F==="ide"?"IDE":F==="cli"?"CLI":"ACP",M=n.slice(0,4),g=s.slice(0,3),S=a.useMemo(()=>{const F=M.map(ne=>({key:`recent-launch:${ne.id}`,type:"session",primary:ne.label,secondary:`${N(ne.kind)}${ne.subtitle?` · ${ne.subtitle}`:""}`,unread:!1,onClick:()=>d(ne)})),le=g.map(ne=>({key:`recent-chat:${ne.conversation.tabKey}`,type:"conversation",primary:ne.conversation.displayPrimary,secondary:`Chat${ne.conversation.displaySecondary?` · ${ne.conversation.displaySecondary}`:""}${ne.timestamp?` · ${at(ne.timestamp)}`:""}`,unread:ne.unread,onClick:()=>x(ne.conversation)}));return[...F,...le]},[x,d,g,M]),j=p?S:S.slice(0,5),k=S.length>0,L=(((U=t.detectedIdes)==null?void 0:U.length)||0)>0,P=a.useMemo(()=>t.workspaces||[],[t]),B=t.defaultWorkspaceId||null,[K,C]=a.useState(B||((ie=P[0])==null?void 0:ie.id)||""),[D,T]=a.useState(""),[R,q]=a.useState(y(L,r.length,i.length)),A=a.useRef(null),_=K==="__custom__"?D.trim():((H=P.find(F=>F.id===K))==null?void 0:H.path)||"",W=K==="__custom__"&&!!_&&u.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(u.message);return a.useEffect(()=>{var F;A.current!==t.id&&(A.current=t.id,C(B||((F=P[0])==null?void 0:F.id)||"__custom__"),T(""),q(y(L,r.length,i.length)))},[i.length,r.length,B,L,t.id,P]),a.useEffect(()=>{var F;K!=="__custom__"&&(K&&P.some(le=>le.id===K)||C(B||((F=P[0])==null?void 0:F.id)||"__custom__"))},[B,K,P]),a.useEffect(()=>{R==="ide"&&L||R==="cli"&&r.length>0||R==="acp"&&i.length>0||q(y(L,r.length,i.length))},[R,i.length,r.length,L]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"dashboard-mobile-chat-header",children:e.jsxs("div",{className:"dashboard-mobile-chat-header-row",children:[e.jsx("button",{className:"dashboard-mobile-chat-back",onClick:l,type:"button","aria-label":"Back",children:e.jsx(un,{size:18})}),e.jsxs("div",{className:"dashboard-mobile-chat-title-block",children:[e.jsx("div",{className:"dashboard-mobile-chat-title",children:We(t,{fallbackId:t.id})}),e.jsxs("div",{className:"dashboard-mobile-chat-subtitle",children:[t.platform||"machine",t.version?` · v${t.version}`:""]})]})]})}),e.jsxs("div",{className:"dashboard-mobile-chat-inbox",children:[k&&e.jsxs("section",{className:"dashboard-mobile-chat-section",children:[e.jsx("div",{className:"dashboard-mobile-chat-section-title",children:"Recent"}),e.jsx("div",{className:"dashboard-mobile-machine-command-grid",children:j.map(F=>e.jsxs("button",{className:`dashboard-mobile-machine-command-card${F.unread?" is-primary":""}`,type:"button",onClick:F.onClick,children:[e.jsx("span",{className:"dashboard-mobile-machine-command-label",children:F.primary}),e.jsx("span",{className:"dashboard-mobile-machine-command-meta",children:F.secondary})]},F.key))}),S.length>5&&e.jsx("div",{className:"dashboard-mobile-machine-more-row",children:e.jsx("button",{type:"button",className:"dashboard-mobile-machine-more-btn",onClick:()=>v(F=>!F),children:p?"Show fewer":`Show ${S.length-5} more`})})]}),(L||r.length>0||i.length>0)&&e.jsxs("section",{className:"dashboard-mobile-chat-section",children:[e.jsx("div",{className:"dashboard-mobile-chat-section-title",children:"Start"}),e.jsx("div",{className:"dashboard-mobile-machine-command-grid",children:e.jsxs("div",{className:"dashboard-mobile-machine-workspace-card",children:[e.jsx("div",{className:"dashboard-mobile-machine-command-label",children:"Workspace"}),e.jsx("div",{className:"dashboard-mobile-machine-command-meta",children:"Pick a saved workspace or enter a path before choosing IDE, CLI, or ACP."}),e.jsx("select",{value:K,onChange:F=>{C(F.target.value),F.target.value!=="__custom__"&&T("")},className:"dashboard-mobile-machine-workspace-select",children:P.length>0?e.jsxs(e.Fragment,{children:[P.map(F=>e.jsxs("option",{value:F.id,children:[F.id===B?"⭐ ":"",F.label||F.path.split("/").filter(Boolean).pop()||F.path]},F.id)),e.jsx("option",{value:"__custom__",children:"Custom path…"})]}):e.jsx("option",{value:"__custom__",children:"Enter workspace path…"})}),K==="__custom__"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",value:D,onChange:F=>T(F.target.value),placeholder:"/absolute/path",className:"dashboard-mobile-machine-workspace-input"}),e.jsx("button",{type:"button",className:"dashboard-mobile-machine-workspace-save",onClick:()=>{_&&w(_)},children:"Save workspace"})]}),_&&e.jsx("div",{className:"dashboard-mobile-machine-workspace-preview",children:_})]})}),e.jsxs("div",{className:"dashboard-mobile-machine-openwith",children:[L&&e.jsx("button",{className:`dashboard-mobile-machine-openwith-btn${R==="ide"?" is-active":""}`,type:"button",onClick:()=>q("ide"),children:"IDE"}),r.length>0&&e.jsx("button",{className:`dashboard-mobile-machine-openwith-btn${R==="cli"?" is-active":""}`,type:"button",onClick:()=>q("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`dashboard-mobile-machine-openwith-btn${R==="acp"?" is-active":""}`,type:"button",onClick:()=>q("acp"),children:"ACP"})]}),R&&e.jsxs("div",{className:"dashboard-mobile-machine-provider-picker",children:[e.jsx("div",{className:"dashboard-mobile-machine-provider-title",children:R==="ide"?"Choose an IDE":R==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"dashboard-mobile-machine-provider-grid",children:R==="ide"?(t.detectedIdes||[]).slice(0,6).map(F=>e.jsxs("button",{type:"button",className:"dashboard-mobile-machine-provider-btn",onClick:()=>m(F.type,{workspacePath:_||null}),children:[e.jsx("span",{className:"dashboard-mobile-machine-provider-name",children:F.name}),e.jsx("span",{className:"dashboard-mobile-machine-provider-meta",children:_||"Use selected workspace"})]},F.type)):(R==="cli"?r:i).map(F=>e.jsxs("button",{type:"button",className:"dashboard-mobile-machine-provider-btn",onClick:()=>b(R,F.type,{workspaceId:K!=="__custom__"?K:null,workspacePath:_||null}),children:[e.jsxs("span",{className:"dashboard-mobile-machine-provider-name",children:[F.icon?`${F.icon} `:"",F.displayName]}),e.jsx("span",{className:"dashboard-mobile-machine-provider-meta",children:_||"Use selected workspace"})]},F.type))})]}),u.message&&e.jsxs("div",{className:`dashboard-mobile-machine-action-note is-${u.state}`,children:[u.message,W&&e.jsx("div",{className:"dashboard-mobile-machine-action-cta-row",children:e.jsx("button",{type:"button",className:"dashboard-mobile-machine-action-cta",onClick:()=>w(_,{createIfMissing:!0}),children:"Create folder"})})]})]}),e.jsxs("section",{className:"dashboard-mobile-chat-section",children:[e.jsx("div",{className:"dashboard-mobile-chat-section-title",children:"Inspect"}),e.jsxs("div",{className:"dashboard-mobile-machine-command-grid",children:[o&&e.jsxs("button",{className:"dashboard-mobile-machine-command-card is-primary",type:"button",onClick:h,children:[e.jsxs("span",{className:"dashboard-mobile-machine-command-label",children:["Update to v",c]}),e.jsx("span",{className:"dashboard-mobile-machine-command-meta",children:"Restart this machine with the latest daemon"})]}),e.jsxs("button",{className:"dashboard-mobile-machine-command-card",type:"button",onClick:f,children:[e.jsx("span",{className:"dashboard-mobile-machine-command-label",children:"Machine details"}),e.jsx("span",{className:"dashboard-mobile-machine-command-meta",children:"Sessions, providers, system info, and logs"})]})]})]})]})]})}function mo(t){return An(t)}function qs(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1],n=mo(s==null?void 0:s.content);return n||(t.title?t.title:t.displaySecondary||"No messages yet")}function po(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Nt(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function xo({conversations:t,ides:s,actionLogs:n,sendDaemonCommand:r,setLocalUserMessages:i,setActionLogs:o,isStandalone:c,userName:u,requestedActiveTabKey:l,onRequestedActiveTabConsumed:x,requestedMachineId:d,onRequestedMachineConsumed:f,onOpenHistory:h,onOpenRemote:m}){const[w,b]=a.useState(()=>{var $;return(($=t[0])==null?void 0:$.tabKey)||null}),[y,p]=a.useState(()=>t[0]?"chat":"inbox"),[v,N]=a.useState("chats"),[M,g]=a.useState(null),[S,j]=a.useState("inbox"),[k,L]=a.useState("idle"),[P,B]=a.useState(""),K=a.useRef(null),C=tt(),D="0.7.45",T=a.useMemo(()=>t.find($=>$.tabKey===w)||t[0]||null,[t,w]),R=a.useMemo(()=>T?s.find($=>$.id===T.ideId):void 0,[s,T]),q=a.useMemo(()=>!T||we(T)||!Se(T)?null:et(T),[T]),A=a.useMemo(()=>s.filter($=>$.type==="adhdev-daemon"||$.daemonMode).sort(Ba),[s]),_=a.useMemo(()=>A.find($=>$.id===M)||null,[A,M]),W=a.useMemo(()=>zt(s),[s]),U=a.useMemo(()=>t.filter($=>!Mn($,t,W)),[t,W]),ie=Ut({sendDaemonCommand:r,activeConv:T||void 0,setLocalUserMessages:i,setActionLogs:o,isStandalone:c}),H=a.useCallback($=>{if(!$||!$.sessionId)return;const z=ot($,W),te=Math.max(Date.now(),Mt($),z.lastUpdated||0);Nt("mark_read:start",{tabKey:$.tabKey,sessionId:$.sessionId,displayPrimary:$.displayPrimary,inboxBucket:z.inboxBucket,unread:z.unread,lastSeenAt:z.lastSeenAt,lastUpdated:z.lastUpdated,activityAt:dt($,z.lastUpdated),readAt:te}),r($.daemonId||$.ideId,"mark_session_seen",{sessionId:$.sessionId,seenAt:te}).then(ce=>{Nt("mark_read:result",{tabKey:$.tabKey,sessionId:$.sessionId,result:ce})}).catch(ce=>{Nt("mark_read:error",{tabKey:$.tabKey,sessionId:$.sessionId,error:ce instanceof Error?ce.message:String(ce)})})},[W,r]);a.useEffect(()=>{var z;if(!T){p("inbox"),b(((z=t[0])==null?void 0:z.tabKey)||null),K.current=null;return}if(y!=="chat"){K.current=null;return}const $=`${T.tabKey}:${T.sessionId||""}`;K.current!==$&&(K.current=$,H(T))},[t,H,y,T]),a.useEffect(()=>{if(!l)return;const $=t.find(z=>z.tabKey===l);$&&(b($.tabKey),p("chat"),x==null||x())},[t,x,l]),a.useEffect(()=>{if(!d)return;const $=A.find(z=>z.id===d);$&&(g($.id),L("idle"),B(""),N("machines"),j("inbox"),p("machine"),f==null||f())},[A,f,d]);const F=a.useMemo(()=>U.map($=>{const z=ot($,W),te=dt($,z.lastUpdated),ce=qs($),ee=y==="chat"&&(T==null?void 0:T.tabKey)===$.tabKey,fe=Et($,W,{hideOpenTaskCompleteUnread:!0,isOpenConversation:ee});return{conversation:$,timestamp:te,preview:ce,unread:fe.unread,requiresAction:fe.requiresAction,isWorking:fe.isWorking,inboxBucket:fe.inboxBucket}}).sort(($,z)=>{const te=z.timestamp-$.timestamp;return te!==0?te:Hn($.conversation,z.conversation)}),[W,U,y,T]);a.useEffect(()=>{const $=F.filter(z=>z.inboxBucket==="task_complete"||z.unread);$.length!==0&&Nt("inbox_state",{screen:y,selectedTabKey:w,items:$.map(z=>{const te=ot(z.conversation,W);return{liveState:te,tabKey:z.conversation.tabKey,sessionId:z.conversation.sessionId,displayPrimary:z.conversation.displayPrimary,serverBucket:te.inboxBucket,computedBucket:z.inboxBucket,serverUnread:te.unread,computedUnread:z.unread,lastSeenAt:te.lastSeenAt,lastUpdated:te.lastUpdated,activityAt:dt(z.conversation,te.lastUpdated)}})})},[F,W,y,w]);const le=a.useMemo(()=>F.filter($=>$.requiresAction),[F]),ne=a.useMemo(()=>F.filter($=>$.unread&&!$.requiresAction),[F]),O=a.useMemo(()=>F.filter($=>!$.unread&&!$.requiresAction&&$.isWorking),[F]),X=a.useMemo(()=>F.filter($=>!$.unread&&!$.requiresAction&&!$.isWorking),[F]),V=a.useMemo(()=>_?F.filter($=>$.conversation.daemonId===_.id||$.conversation.ideId===_.id):[],[F,_]),I=a.useMemo(()=>{if(!_)return[];const $=_.recentLaunches||[];return $.length>0?$.map(z=>({id:z.id,label:z.title||z.providerName||z.providerType,kind:z.kind,providerType:z.providerType,subtitle:z.currentModel||z.workspace||void 0,workspace:z.workspace,currentModel:z.currentModel})):s.filter(z=>!z.daemonMode&&z.daemonId===_.id).map(z=>{var ce,ee,fe,ye,he;const te=Lt(z)?"cli":it(z)?"acp":"ide";return{id:`${te}:${z.type}:${z.workspace||""}`,label:((ce=z.activeChat)==null?void 0:ce.title)||(Lt(z)?z.cliName||z.type:it(z)&&z.cliName||z.type),kind:te,providerType:z.type,subtitle:it(z)?z.currentModel||z.workspace||void 0:z.workspace||void 0,workspace:z.workspace||void 0,currentModel:z.currentModel,timestamp:((he=(ye=(fe=(ee=z.activeChat)==null?void 0:ee.messages)==null?void 0:fe.at)==null?void 0:ye.call(fe,-1))==null?void 0:he.timestamp)||0}}).sort((z,te)=>te.timestamp-z.timestamp).map(({timestamp:z,...te})=>te)},[s,_]),G=(_==null?void 0:_.version)||(_==null?void 0:_.daemonVersion)||null,Y=!!_&&!!G&&!0&&G!==D,ae=a.useMemo(()=>(_==null?void 0:_.availableProviders)||[],[_]),me=a.useMemo(()=>ae.filter($=>$.category==="cli").map($=>({type:$.type,displayName:$.displayName||$.type,icon:$.icon})),[ae]),ue=a.useMemo(()=>ae.filter($=>$.category==="acp").map($=>({type:$.type,displayName:$.displayName||$.type,icon:$.icon})),[ae]),xe=a.useMemo(()=>{const $=new Map;for(const z of F){const te=z.conversation.daemonId||z.conversation.ideId,ce=$.get(te);ce?ce.push(z):$.set(te,[z])}return A.map(z=>{const te=$.get(z.id)||[],ce=[...te].sort((Re,Vt)=>Vt.timestamp-Re.timestamp)[0]||null,ee=(ce==null?void 0:ce.conversation)||null,fe=te.filter(Re=>Re.unread||Re.requiresAction).length,ye=z.status==="online"?"Connected":z.status||"Unknown",he=[z.platform||"machine",ye].filter(Boolean);return{id:z.id,label:We(z,{fallbackId:z.id}),subtitle:he.join(" · "),unread:fe,total:te.length,latestConversation:ee,preview:ee?`${ee.displayPrimary} · ${qs(ee)}`:"No active conversations yet. Open the machine to launch an IDE, CLI, or ACP session."}}).sort((z,te)=>{const ce=Math.max(z.latestConversation?Mt(z.latestConversation):0,_t(A.find(fe=>fe.id===z.id))),ee=Math.max(te.latestConversation?Mt(te.latestConversation):0,_t(A.find(fe=>fe.id===te.id)));return ee!==ce?ee-ce:z.label.localeCompare(te.label)})},[F,A]),J=a.useCallback($=>{b($.tabKey),p("chat"),H($)},[H]),se=a.useCallback($=>{const z=U.find(te=>te.ideId===$.ideId&&te.streamSource==="native");z&&(b(z.tabKey),p("chat"),H(z))},[H,U]),Z=a.useCallback(()=>{H(T),p("inbox")},[H,T]),E=a.useCallback($=>{g($),L("idle"),B(""),N("machines"),j("inbox"),p("machine")},[]),Q=a.useCallback($=>{var te;const z=$.daemonId||((te=$.ideId)==null?void 0:te.split(":")[0])||$.ideId;z&&(g(z),L("idle"),B(""),N("machines"),j("chat"),p("machine"))},[]),re=a.useCallback(()=>{p(S)},[S]),oe=a.useCallback(async($,z,te)=>{var ce;try{L("loading"),B(`Launching ${z}…`);const ee={ideType:z,enableCdp:!0};(ce=te==null?void 0:te.workspacePath)!=null&&ce.trim()&&(ee.workspace=te.workspacePath.trim()),await r($,"launch_ide",ee),L("done"),B(`${z} launch requested`)}catch(ee){L("error"),B(ee instanceof Error?ee.message:"Launch IDE failed"),console.error("Launch IDE failed",ee)}},[r]),ge=a.useCallback(async($,z,te)=>{if(z.trim())try{L("loading"),B(te!=null&&te.createIfMissing?"Creating folder…":"Saving workspace…");const ce=await r($,"workspace_add",{path:z.trim(),createIfMissing:(te==null?void 0:te.createIfMissing)===!0});if(ce!=null&&ce.success){L("done"),B(te!=null&&te.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}L("error"),B((ce==null?void 0:ce.error)||"Could not save workspace")}catch(ce){L("error"),B(ce instanceof Error?ce.message:"Could not save workspace")}},[r]),Ne=a.useCallback(async $=>{var z,te,ce,ee,fe,ye;try{L("loading"),B("Starting daemon upgrade…");const he=await r($,"daemon_upgrade",{});if((z=he==null?void 0:he.result)!=null&&z.alreadyLatest){L("done"),B(`Already on v${((te=he==null?void 0:he.result)==null?void 0:te.version)||"latest"}.`);return}if((ce=he==null?void 0:he.result)!=null&&ce.upgraded||(ee=he==null?void 0:he.result)!=null&&ee.success){L("done"),B(`Upgrade to v${((fe=he==null?void 0:he.result)==null?void 0:fe.version)||"latest"} started. Daemon is restarting…`);return}L("error"),B(((ye=he==null?void 0:he.result)==null?void 0:ye.error)||"Upgrade failed")}catch(he){L("error"),B(he instanceof Error?he.message:"Upgrade failed")}},[r]),de=a.useCallback(async($,z,te,ce)=>{var ee;try{L("loading"),B(`Launching ${te}…`);const fe={cliType:te};(ee=ce==null?void 0:ce.workspacePath)!=null&&ee.trim()?fe.dir=ce.workspacePath.trim():ce!=null&&ce.workspaceId&&(fe.workspaceId=ce.workspaceId);const ye=await r($,"launch_cli",fe),he=(ye==null?void 0:ye.result)||ye,Re=(he==null?void 0:he.sessionId)||(he==null?void 0:he.id);if(ye!=null&&ye.success&&Re){L("done"),B(`${te} launched`),C(`/dashboard?activeTab=${encodeURIComponent(Re)}`);return}L("error"),B((ye==null?void 0:ye.error)||(he==null?void 0:he.error)||`Could not launch ${z.toUpperCase()} workspace`)}catch(fe){L("error"),B(fe instanceof Error?fe.message:`Could not launch ${z.toUpperCase()} workspace`)}},[C,r]),Te=a.useCallback(async $=>{if(_){if($.kind==="ide"&&$.providerType){await oe(_.id,$.providerType,{workspacePath:$.workspace||null});return}if(($.kind==="cli"||$.kind==="acp")&&$.providerType){await de(_.id,$.kind,$.providerType,{workspacePath:$.workspace||null});return}}},[oe,de,_]);return e.jsx("div",{className:"dashboard-mobile-chat",children:y==="chat"&&T?e.jsx(lo,{selectedConversation:T,isAcp:we(T),selectedIdeEntry:R,actionLogs:n,userName:u,isSendingChat:ie.isSendingChat,isFocusingAgent:ie.isFocusingAgent,onBack:Z,onOpenNativeConversation:se,onOpenMachine:Q,onOpenHistory:h,onOpenRemote:m,cliViewMode:q,onSetCliViewMode:async $=>{if(T&&q!==$)try{await r(T.daemonId||T.ideId,"set_cli_view_mode",{targetSessionId:T.sessionId,cliType:T.ideType||T.agentType,mode:$})}catch(z){console.error("Failed to switch CLI view mode:",z)}},handleSendChat:ie.handleSendChat,handleFocusAgent:ie.handleFocusAgent}):y==="machine"&&_?e.jsx(ho,{selectedMachineEntry:_,selectedMachineConversations:V,selectedMachineRecentLaunches:I,cliProviders:me,acpProviders:ue,selectedMachineNeedsUpgrade:Y,appVersion:D,machineAction:{state:k,message:P},onBack:re,onOpenConversation:J,onOpenRecent:Te,onOpenMachineDetails:()=>C(`/machines/${_.id}`),onMachineUpgrade:()=>Ne(_.id),onLaunchDetectedIde:($,z)=>oe(_.id,$,z),onAddWorkspace:($,z)=>ge(_.id,$,z),onLaunchWorkspaceProvider:($,z,te)=>de(_.id,$,z,te)}):e.jsx(uo,{section:v,attentionItems:le,unreadItems:ne,workingItems:O,completedItems:X,machineCards:xe,getAvatarText:po,onOpenConversation:J,onOpenMachine:E,onOpenSettings:()=>C("/settings"),onSectionChange:N})})}function es(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function fo({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[u,l]=a.useState(!1),[x,d]=a.useState(null),f=a.useCallback(()=>{c.current=0,l(!1),d(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",f),window.addEventListener("drop",f),()=>{window.removeEventListener("dragend",f),window.removeEventListener("drop",f)}),[f]);const h=a.useCallback(y=>{y.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,l(!0))},[]),m=a.useCallback(y=>{if(!y.dataTransfer.types.includes("text/tab-key"))return;if(y.preventDefault(),!es(s,n)){d("merge");return}const p=y.currentTarget.getBoundingClientRect(),v=y.clientX-p.left,N=p.width/3;v<N?d("split-left"):v>N*2?d("split-right"):d("merge")},[s,n]),w=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,l(!1),d(null))},[]),b=a.useCallback(y=>{c.current=0,l(!1);const p=y.dataTransfer.getData("text/tab-key"),v=p?t.some(M=>M.tabKey===p):!1,N=x;if(d(null),o(),!!p){if(y.preventDefault(),N==="split-left"&&es(s,n)){n==null||n(p,"split-left");return}if(N==="split-right"&&es(s,n)){n==null||n(p,"split-right");return}if(v){i(p);return}r==null||r(p)}},[t,x,s,n,r,i,o]);return{dragOver:u,dropAction:x,resetDragState:f,handleDragEnter:h,handleDragOver:m,handleDragLeave:w,handleDrop:b}}function bo(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),[u,l]=a.useState(n??[]),[x,d]=a.useState(null),f=a.useRef(null),h=a.useRef(null),m=a.useRef(r),w=a.useRef(i);a.useEffect(()=>{m.current=r},[r]),a.useEffect(()=>{w.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{l(j=>{const k=bo(j,t);return k.length===j.length&&k.every((L,P)=>L===j[P])?j:k})},[t]);const b=a.useMemo(()=>{const j=x??u;if(j.length===0)return t;const k=new Map(j.map((L,P)=>[L,P]));return[...t].sort((L,P)=>{const B=k.get(L.tabKey)??999,K=k.get(P.tabKey)??999;return B-K})},[t,x,u]);a.useEffect(()=>{var k,L;if(b.length===0){o!==null&&(c(null),(k=m.current)==null||k.call(m,null));return}if(o&&b.some(P=>P.tabKey===o))return;const j=b[0].tabKey;j!==o&&(c(j),(L=m.current)==null||L.call(m,j))},[b,o]);const y=a.useMemo(()=>b.find(j=>j.tabKey===o),[b,o]),p=a.useCallback(j=>{var k;c(j),(k=m.current)==null||k.call(m,j)},[]),v=a.useCallback((j,k,L)=>{l(P=>{var D;const B=P.filter(T=>T!==j),K=B.indexOf(k);if(K<0)return P;const C=L==="left"?K:K+1;return B.splice(C,0,j),(D=w.current)==null||D.call(w,B),B}),d(null)},[]),N=a.useCallback((j,k,L)=>{const B=(u.length>0?u:t.map(D=>D.tabKey)).filter(D=>D!==j),K=B.indexOf(k);if(K<0)return;const C=L==="left"?K:K+1;B.splice(C,0,j),f.current=B,d(B)},[u,t]),M=a.useCallback(()=>{var k;const j=f.current;j&&(l(j),(k=w.current)==null||k.call(w,j))},[]),g=a.useCallback(()=>{f.current=null,d(null)},[]),S=a.useCallback(j=>{l(k=>{var P;const L=k.filter(B=>B!==j);return L.push(j),(P=w.current)==null||P.call(w,L),L})},[]);return{activeTabId:o,activeConv:y,sortedConversations:b,previewOrderRef:f,draggingTabRef:h,selectTab:p,handleTabReorder:v,updatePreviewOrder:N,commitPreviewOrder:M,clearPreviewOrder:g,moveTabToEnd:S,setDraggingTabKey:j=>{h.current=j}}}const Gn=a.memo(function({activeConv:s,clearToken:n,isCliTerminal:r,ideEntry:i,screenshotUrl:o,clearScreenshot:c,terminalRef:u,handleModalButton:l,handleRelaunch:x,handleSendChat:d,isSendingChat:f,handleFocusAgent:h,isFocusingAgent:m,actionLogs:w,userName:b}){const y=a.useCallback(()=>{c()},[c]);return e.jsxs(e.Fragment,{children:[e.jsx(yn,{activeConv:s,onModalButton:l}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:s.transport!=="pty"&&s.transport!=="acp"&&o?e.jsx(ja,{screenshotUrl:o,mode:"preview",onDismiss:y}):s.transport!=="pty"&&s.transport!=="acp"&&s.cdpConnected===!1?e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[e.jsx("span",{className:"text-sm",children:e.jsx(xs,{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:x,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(Cn,{activeConv:s,clearToken:n,terminalRef:u,handleSendChat:d,isSendingChat:f})}),e.jsx("div",{style:{display:r?"none":"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(pt,{activeConv:s,ideEntry:i,handleSendChat:d,isSendingChat:f,handleFocusAgent:h,isFocusingAgent:m,actionLogs:w,userName:b})})]}):e.jsx(pt,{activeConv:s,ideEntry:i,handleSendChat:d,isSendingChat:f,handleFocusAgent:h,isFocusingAgent:m,actionLogs:w,userName:b})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCliTerminal===s.isCliTerminal&&t.ideEntry===s.ideEntry&&t.screenshotUrl===s.screenshotUrl&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName);function 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"})})]})}const ts={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 vo(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function jo(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":n;a.useEffect(()=>{s(vo())},[]);const u=a.useCallback(()=>{navigator.clipboard.writeText(ts[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:u,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:ts[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:ts[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 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(jo,{}),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(fn,{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 Jn="adhdev-tab-shortcuts";function wo(){try{return JSON.parse(localStorage.getItem(Jn)||"{}")}catch{return{}}}function ko({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,o]=a.useState(()=>wo()),[c,u]=a.useState(null),l=a.useCallback(d=>{const f=[];return d.metaKey&&f.push(r?"⌘":"Meta"),d.ctrlKey&&f.push("Ctrl"),d.altKey&&f.push(r?"⌥":"Alt"),d.shiftKey&&f.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(d.key)?null:(f.push(d.key.length===1?d.key.toUpperCase():d.key),f.join("+"))},[r]),x=a.useCallback(d=>{o(d);try{localStorage.setItem(Jn,JSON.stringify(d))}catch{}},[]);return a.useEffect(()=>{if(!c)return;const d=f=>{if(f.preventDefault(),f.stopPropagation(),f.key==="Escape"){u(null);return}const h=l(f);if(!h)return;const m={...i};for(const[w,b]of Object.entries(m))b===h&&delete m[w];m[c]=h,x(m),u(null)};return window.addEventListener("keydown",d,!0),()=>window.removeEventListener("keydown",d,!0)},[c,i,x,l]),a.useEffect(()=>{const d=f=>{if(!(!f.ctrlKey&&!f.metaKey&&!f.altKey)){for(const[h,m]of Object.entries(i))if(t.includes(h)&&l(f)===m){f.preventDefault(),s(),n(h);return}}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[i,t,s,n,l]),{isMac:r,tabShortcuts:i,shortcutListening:c,setShortcutListening:u,saveShortcuts:x}}const No=a.memo(function({conv:s,isActive:n,isDraggedTab:r,isTaskCompleteUnread:i,shortcut:o,conversationKeys:c,draggingTabRef:u,onFocus:l,onSelectTab:x,onConversationActivated:d,onPreviewReorder:f,onReorderTab:h,onCommitPreviewOrder:m,onClearPreviewOrder:w,onDragStateReset:b,onDragTabKeyChange:y,onReceiveTab:p,onOpenContextMenu:v,longPressTimer:N}){const M=s.status==="generating"?"agent-tab-generating":s.status==="waiting_approval"?"agent-tab-waiting":"",g=s.connectionState==="failed"||s.connectionState==="closed",S=a.useCallback(T=>{u.current=s.tabKey,y(s.tabKey),T.dataTransfer.setData("text/tab-key",s.tabKey),T.dataTransfer.effectAllowed="move"},[s.tabKey,u,y]),j=a.useCallback(()=>{u.current=null,y(null),m(),w(),b()},[u,y,m,w,b]),k=a.useCallback(T=>{const R=u.current;if(!(!R||R===s.tabKey)&&T.dataTransfer.types.includes("text/tab-key")){T.preventDefault(),T.stopPropagation();const q=T.currentTarget.getBoundingClientRect(),A=T.clientX<q.left+q.width/2?"left":"right";f(R,s.tabKey,A)}},[s.tabKey,u,f]),L=a.useCallback(T=>{T.preventDefault(),T.stopPropagation();const R=T.dataTransfer.getData("text/tab-key");if(R&&R!==s.tabKey){const q=T.currentTarget.getBoundingClientRect(),A=T.clientX<q.left+q.width/2?"left":"right";c.includes(R)?h(R,s.tabKey,A):p&&p(R)}w()},[s.tabKey,c,h,p,w]),P=a.useCallback(T=>{T.stopPropagation(),l(),x(s.tabKey),d(s)},[s,d,l,x]),B=a.useCallback(T=>{T.preventDefault(),v(T.clientX,T.clientY,s.tabKey)},[s.tabKey,v]),K=a.useCallback(T=>{const R=T.touches[0];N.current=setTimeout(()=>{v(R.clientX,R.clientY,s.tabKey)},600)},[s.tabKey,N,v]),C=a.useCallback(()=>{N.current&&clearTimeout(N.current)},[N]),D=["adhdev-dockview-tab",M,n&&"is-active",g&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:D,draggable:!0,onDragStart:S,onDragEnd:j,onDragOver:k,onDrop:L,onClick:P,onContextMenu:B,onTouchStart:K,onTouchEnd:C,onTouchMove:C,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:s.status==="generating"?e.jsx("div",{className:"tab-spinner"}):s.status==="waiting_approval"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):g?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):s.connectionState==="connecting"||s.connectionState==="new"?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:g?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):s.connectionState==="connecting"||s.connectionState==="new"?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);function So({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,unreadTabKeys:i,draggingTabRef:o,onFocus:c,onSelectTab:u,onConversationActivated:l,onPreviewReorder:x,onReorderTab:d,onCommitPreviewOrder:f,onClearPreviewOrder:h,onDragStateReset:m,onDragTabKeyChange:w,onMoveTab:b,onReceiveTab:y,onHideTab:p}){const[v,N]=a.useState(null),M=a.useRef(null),g=a.useRef(null),S=a.useMemo(()=>t.map(C=>C.tabKey),[t]);xt("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(v==null?void 0:v.tabKey)||null});const{isMac:j,tabShortcuts:k,shortcutListening:L,setShortcutListening:P,saveShortcuts:B}=ko({sortedTabKeys:t.map(C=>C.tabKey),onFocus:c,onSelectTab:u});a.useEffect(()=>{if(!v)return;const C=D=>{const T=document.querySelector("[data-pane-context-menu]");T&&T.contains(D.target)||N(null)};return window.addEventListener("mousedown",C,!0),()=>window.removeEventListener("mousedown",C,!0)},[v]),a.useEffect(()=>{const C=g.current;if(!C)return;const D=T=>{Math.abs(T.deltaY)>Math.abs(T.deltaX)&&(T.preventDefault(),C.scrollLeft+=T.deltaY)};return C.addEventListener("wheel",D,{passive:!1}),()=>C.removeEventListener("wheel",D)},[]);const K=a.useCallback((C,D,T)=>{N({x:C,y:D,tabKey:T})},[]);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:g,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(C=>e.jsx(No,{conv:C,isActive:s===C.tabKey,isDraggedTab:o.current===C.tabKey,isTaskCompleteUnread:i.has(C.tabKey),shortcut:k[C.tabKey],conversationKeys:S,draggingTabRef:o,onFocus:c,onSelectTab:u,onConversationActivated:l,onPreviewReorder:x,onReorderTab:d,onCommitPreviewOrder:f,onClearPreviewOrder:h,onDragStateReset:m,onDragTabKeyChange:w,onReceiveTab:y,onOpenContextMenu:K,longPressTimer:M},C.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),v&&e.jsxs("div",{"data-pane-context-menu":!0,className:"fixed z-50 bg-bg-primary border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",style:{left:v.x,top:v.y},children:[b&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{b(v.tabKey,"left"),N(null)},children:"← Move to Left Group"}),b&&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:()=>{b(v.tabKey,"right"),N(null)},children:"Move to Right Group →"}),b&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{b(v.tabKey,"split-left"),N(null)},children:"⇤ Split Left"}),b&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{b(v.tabKey,"split-right"),N(null)},children:"Split Right ⇥"}),e.jsx("div",{className:"border-t border-border-subtle my-1 "}),e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:C=>{C.stopPropagation(),P(v.tabKey),N(null)},children:["⌨ ",k[v.tabKey]?`Change shortcut (${k[v.tabKey]})`:"Set shortcut"]}),k[v.tabKey]&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onClick:()=>{const C={...k};delete C[v.tabKey],B(C),N(null)},children:"✕ Remove shortcut"}),p&&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:()=>{p(v.tabKey),N(null)},children:"🚫 Hide from Dashboard"})]}),!b&&!p&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),L&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>P(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:C=>C.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",j?"⌘+1":"Ctrl+1",", ",j?"⌥+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 Co({conversations:t,ides:s,clearedTabs:n,actionLogs:r,screenshotMap:i,setScreenshotMap:o,sendDaemonCommand:c,setLocalUserMessages:u,setActionLogs:l,isStandalone:x,userName:d,groupIndex:f,onFocus:h,isSplitMode:m,numGroups:w,onMoveTab:b,onReceiveTab:y,style:p,detectedIdes:v,handleLaunchIde:N,onActiveTabChange:M,initialActiveTabId:g,initialTabOrder:S,onTabOrderChange:j,onHideTab:k}){const{sendCommand:L}=Fe(),P=a.useRef(null),{activeTabId:B,activeConv:K,sortedConversations:C,draggingTabRef:D,selectTab:T,handleTabReorder:R,updatePreviewOrder:q,commitPreviewOrder:A,clearPreviewOrder:_,moveTabToEnd:W,setDraggingTabKey:U}=go({conversations:t,initialActiveTabId:g,initialTabOrder:S,onActiveTabChange:M,onTabOrderChange:j}),ie=Ut({sendDaemonCommand:c,activeConv:K,setLocalUserMessages:u,setActionLogs:l,isStandalone:x}),{dragOver:H,dropAction:F,resetDragState:le,handleDragEnter:ne,handleDragOver:O,handleDragLeave:X,handleDrop:V}=fo({conversations:t,numGroups:w,onMoveTab:b,onReceiveTab:y,onOwnTabDrop:W,onClearPreviewOrder:_}),I=K&&!we(K)&&et(K)==="terminal",G=a.useMemo(()=>K?s.find(se=>se.id===K.ideId):void 0,[s,K]),Y=K?i[K.ideId]:void 0,ae=a.useCallback(()=>{if(!K||!(K.ideId in i))return;const se={...i};delete se[K.ideId],o(se)},[K,i,o]),me=a.useMemo(()=>K?r.filter(se=>se.ideId===K.tabKey):[],[r,K]),ue=a.useMemo(()=>zt(s),[s]),xe=a.useMemo(()=>new Set(C.filter(se=>In(se,ue)).map(se=>se.tabKey)),[ue,C]);xt("PaneGroup",{groupIndex:f,conversationCount:t.length,activeTabId:B,dragOver:H});const J=a.useCallback(se=>{se.streamSource==="agent-stream"&&se.agentType&&L(se.ideId,"focus_session",{agentType:se.agentType,...se.sessionId&&{targetSessionId:se.sessionId}}).catch(()=>{})},[L]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:h,style:{...p,outline:H?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(So,{conversations:C,activeTabId:B,groupIndex:f,numGroups:w,unreadTabKeys:xe,draggingTabRef:D,onFocus:h,onSelectTab:T,onConversationActivated:J,onPreviewReorder:q,onReorderTab:R,onCommitPreviewOrder:A,onClearPreviewOrder:_,onDragStateReset:le,onDragTabKeyChange:U,onMoveTab:b,onReceiveTab:y,onHideTab:k}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:ne,onDragOver:O,onDragLeave:X,onDrop:V,children:[H&&e.jsx(yo,{dropAction:F,canSplit:!!(w<4&&b)}),K?e.jsx(Gn,{activeConv:K,clearToken:n[K.tabKey]||0,isCliTerminal:!!I,ideEntry:G,screenshotUrl:Y,clearScreenshot:ae,terminalRef:P,handleModalButton:ie.handleModalButton,handleRelaunch:ie.handleRelaunch,handleSendChat:ie.handleSendChat,isSendingChat:ie.isSendingChat,handleFocusAgent:ie.handleFocusAgent,isFocusingAgent:ie.isFocusingAgent,actionLogs:me,userName:d}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(ks,{conversationsCount:t.length,isSplitMode:m,isStandalone:x,detectedIdes:v,handleLaunchIde:N})})]})]})}function Io({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:u,screenshotMap:l,setScreenshotMap:x,sendDaemonCommand:d,setLocalUserMessages:f,setActionLogs:h,isStandalone:m,userName:w,setFocusedGroup:b,moveTabToGroup:y,splitTabRelative:p,closeGroup:v,handleResizeStart:N,detectedIdes:M,handleLaunchIde:g,groupActiveTabIds:S,setGroupActiveTabIds:j,groupTabOrders:k,setGroupTabOrders:L,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((B,K)=>{const C=s&&r.length===n?`${r[K]}%`:void 0;return e.jsxs(Ar.Fragment,{children:[s&&K>0&&e.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:D=>N(K-1,D),onDoubleClick:()=>v(K),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(Co,{style:s?{flexBasis:C??`${100/n}%`,flexGrow:C?0:1,flexShrink:C?0:1}:void 0,conversations:B,clearedTabs:o,ides:c,actionLogs:u,screenshotMap:l,setScreenshotMap:x,sendDaemonCommand:d,setLocalUserMessages:f,setActionLogs:h,isStandalone:m,userName:w,groupIndex:K,onFocus:()=>b(K),isSplitMode:s,numGroups:n,onMoveTab:(D,T)=>{T==="left"&&K>0?y(D,K-1):T==="right"&&K<n-1?y(D,K+1):T==="split-left"&&n<4?p(D,K,"left"):T==="split-right"&&n<4&&p(D,K,"right")},onReceiveTab:D=>y(D,K),detectedIdes:K===0?M:void 0,handleLaunchIde:K===0?g:void 0,onActiveTabChange:D=>j(T=>(T[K]??null)===(D??null)?T:{...T,[K]:D}),initialActiveTabId:S[K],initialTabOrder:k[K],onTabOrderChange:D=>L(T=>{const R=T[K]||[];return R.length===D.length&&R.every((q,A)=>q===D[A])?T:{...T,[K]:D}}),onHideTab:P})]},K)})})}function Zn({doId:t,ideId:s,ideType:n,connState:r,viewMode:i,instanceId:o}){const[c,u]=a.useState(null),[l,x]=a.useState(null),d=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?ve.onScreenshot("ide-page",(m,w)=>{if(m!==t)return;const b=new FileReader;b.onload=()=>u(b.result),b.readAsDataURL(w)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&u(null)},[r]),a.useEffect(()=>{var m;return t?((m=ve.onStatus)==null?void 0:m.call(ve,(w,b)=>{w===t&&b!=null&&b.screenshotUsage&&x(b.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{u(null)},[t,s,d]),a.useEffect(()=>{const h=t?ve.get(t):null;if(!(!h||r!=="connected"))return i!=="chat"&&d?h.startScreenshots(d):h.stopScreenshots(d),()=>{h.stopScreenshots(d)}},[i,r,d,t]);const f=a.useCallback(async(h,m)=>{const w=t?ve.get(t):null;return!w||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):w.sendInput(h,m,o||d)},[t,r,o,d]);return{connScreenshot:c,screenshotUsage:l,handleRemoteAction:f}}const Qn=a.createContext(null);function Ft(){const t=a.useContext(Qn);if(!t)throw new Error("DashboardDockviewContext missing");return t}function Tt(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function Mo(t){return`remote:${t}`}function Bt(t){return t.startsWith("remote:")}function Ht(t,s){return t.find(n=>n.ideId===s&&n.streamSource==="native")??t.find(n=>n.ideId===s)??null}function To(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 Ao(t,s,n){var u;const r=[s];let i;for(const l of r){let x;for(const d of l){const f=t.addPanel({id:d.tabKey,component:"conversation",title:Tt(d),params:{kind:"conversation",tabKey:d.tabKey},...x?{position:{referencePanel:x,direction:"within"},inactive:!0}:i?{position:{referencePanel:i,direction:"right"},inactive:!0}:{}});x||(x=f.id)}i=x??i}const o=n??((u=s[0])==null?void 0:u.tabKey)??null;if(!o)return;const c=t.getPanel(o);c&&c.group.model.openPanel(c)}function Ys(t,s){const n=new Set(s.map(r=>r.tabKey));for(const r of[...t.panels])Bt(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!==Tt(r)&&i.api.setTitle(Tt(r));continue}t.addPanel({id:r.tabKey,component:"conversation",title:Tt(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 Xs(t,s,n){var l,x;const r=n?Mo(n):null;for(const d of[...t.panels])Bt(d.id)&&(!r||d.id!==r)&&t.removePanel(d);if(!n||!r)return;const i=Ht(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 u=(i==null?void 0:i.tabKey)??((l=t.activePanel)==null?void 0:l.id)??((x=t.panels.find(d=>!Bt(d.id)))==null?void 0:x.id);t.addPanel({id:r,component:"remote",title:c,params:{kind:"remote",ideId:n},...u?{position:{referencePanel:u,direction:"right"},inactive:!0}:{}})}function Ro({params:t}){const s=Ft(),n=a.useRef(null),r=s.conversationsByTabKey.get(t.tabKey),i=Ut({sendDaemonCommand:s.sendDaemonCommand,activeConv:r,setLocalUserMessages:s.setLocalUserMessages,setActionLogs:s.setActionLogs,isStandalone:s.isStandalone}),o=a.useMemo(()=>r?s.ides.find(d=>d.id===r.ideId):void 0,[s.ides,r]),c=r?s.screenshotMap[r.ideId]:void 0,u=a.useCallback(()=>{if(!r||!(r.ideId in s.screenshotMap))return;const d={...s.screenshotMap};delete d[r.ideId],s.setScreenshotMap(d)},[r,s]),l=a.useMemo(()=>r?s.actionLogs.filter(d=>d.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 x=!we(r)&&et(r)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(Gn,{activeConv:r,clearToken:s.clearedTabs[r.tabKey]||0,isCliTerminal:x,ideEntry:o,screenshotUrl:c,clearScreenshot:u,terminalRef:n,handleModalButton:i.handleModalButton,handleRelaunch:i.handleRelaunch,handleSendChat:i.handleSendChat,isSendingChat:i.isSendingChat,handleFocusAgent:i.handleFocusAgent,isFocusingAgent:i.isFocusingAgent,actionLogs:l,userName:s.userName})})}function Lo({params:t}){var l;const s=Ft(),n=a.useMemo(()=>Ht([...s.conversationsByTabKey.values()],t.ideId),[s.conversationsByTabKey,t.ideId]),r=a.useMemo(()=>s.ides.find(x=>x.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:u}=Zn({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(gn,{addLog:()=>{},connState:n.connectionState||"new",connScreenshot:o,screenshotUsage:c,transportType:n.transport,onAction:u})}):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 _o(){const t=Ft();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 Eo(t){var d,f;To(t);const s=Ft();if(t.params.kind==="remote"){const h=Ht([...s.conversationsByTabKey.values()],t.params.ideId),m=((d=t.api.group.activePanel)==null?void 0:d.id)===t.api.id,w=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${m?" is-active":""}${w?" is-group-active":""}`,title:t.api.title||"Remote",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:h!=null&&h.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:h.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",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=((f=t.api.group.activePanel)==null?void 0:f.id)===t.api.id,i=t.api.isGroupActive,o=n.connectionState==="failed"||n.connectionState==="closed",c=n.connectionState==="connecting"||n.connectionState==="new",u=n.status==="generating",l=n.status==="waiting_approval",x=In(n,s.liveSessionInboxState);return e.jsxs("div",{className:`adhdev-dockview-tab${r?" is-active":""}${i?" is-group-active":""}${o?" is-reconnecting":""}`,title:n.displayPrimary,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:u?e.jsx("div",{className:"tab-spinner"}):l?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):o?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):c?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:o?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):c?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 Po({visibleConversations:t,clearedTabs:s,ides:n,actionLogs:r,screenshotMap:i,setScreenshotMap:o,sendDaemonCommand:c,setLocalUserMessages:u,setActionLogs:l,isStandalone:x,userName:d,detectedIdes:f,handleLaunchIde:h,toggleHiddenTab:m,onActiveTabChange:w,requestedActiveTabKey:b,requestedRemoteIdeId:y,onRequestedActiveTabConsumed:p}){const{theme:v}=Bn(),{sendCommand:N}=Fe(),M=a.useRef(null),g=a.useRef(null),S=a.useRef(!1),[j,k]=a.useState(!1),[L,P]=a.useState(!1),B=a.useRef(null),K=a.useMemo(()=>qn(typeof window<"u"?window.innerWidth:1280),[]),C=a.useMemo(()=>new Map(t.map(H=>[H.tabKey,H])),[t]),D=a.useMemo(()=>zt(n),[n]),T=a.useMemo(()=>({actionLogs:r,clearedTabs:s,conversationsByTabKey:C,detectedIdes:f,handleLaunchIde:h,ides:n,isStandalone:x,liveSessionInboxState:D,screenshotMap:i,sendDaemonCommand:c,setActionLogs:l,setLocalUserMessages:u,setScreenshotMap:o,toggleHiddenTab:m,userName:d}),[r,s,C,f,h,n,x,D,i,c,l,u,o,m,d]),R=a.useCallback(H=>{if(!H)return!1;const F=M.current;if(!F)return!1;const le=F.getPanel(H);return le?(le.group.model.openPanel(le),p==null||p(),!0):!1},[p]),q=a.useCallback(()=>{const H=g.current;if(!H)return;const F=H.querySelectorAll(".dv-drop-target-container, .dv-drop-target-anchor, .dv-drop-target-dropzone, .dv-drop-target-selection, .dv-render-overlay");for(const le of F)le.setAttribute("data-adhdev-force-hidden","true")},[]),A=a.useCallback(()=>{const H=g.current;if(!H)return;const F=H.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const le of F)le.removeAttribute("data-adhdev-force-hidden")},[]),_=a.useCallback(()=>{const H=g.current;if(!H)return;const F=H.querySelectorAll(".dv-drop-target-container");for(const O of F)O.remove();const le=H.querySelectorAll(".dv-drop-target-dropzone");for(const O of le)O.remove();const ne=H.querySelectorAll(".dv-drop-target");for(const O of ne)O.classList.remove("dv-drop-target")},[]),W=a.useCallback(()=>{k(!1),P(!1),A(),q(),_(),!(typeof window>"u")&&(B.current!=null&&window.clearTimeout(B.current),window.requestAnimationFrame(()=>{q(),_()}),B.current=window.setTimeout(()=>{q(),_(),B.current=null},80))},[A,q,_]),U=a.useCallback(H=>{var le;M.current=H.api;const F=Ji(K);F!=null&&F.layout&&H.api.fromJSON(F.layout,{reuseExistingPanels:!1}),Ys(H.api,t),Xs(H.api,t,y),H.api.totalPanels===0&&t.length>0?Ao(H.api,t,b):R(b)||R(F==null?void 0:F.activeTabId),S.current=!0,H.api.onDidActivePanelChange(ne=>{var X;if(ne&&Bt(ne.id)){const V=((X=ne.params)==null?void 0:X.ideId)||ne.id.slice(7),I=Ht(t,V);w((I==null?void 0:I.tabKey)??null);return}if(w((ne==null?void 0:ne.id)??null),!ne)return;const O=C.get(ne.id);(O==null?void 0:O.streamSource)==="agent-stream"&&O.agentType&&N(O.ideId,"focus_session",{agentType:O.agentType,...O.sessionId&&{targetSessionId:O.sessionId}}).catch(()=>{})}),H.api.onDidLayoutChange(()=>{var ne;Zi(K,{activeTabId:((ne=H.api.activePanel)==null?void 0:ne.id)??null,layout:H.api.toJSON()})}),H.api.onWillDragPanel(()=>{k(!0),P(!1),q()}),H.api.onWillDragGroup(()=>{k(!0),P(!1),q()}),H.api.onWillShowOverlay(()=>{A(),P(!0)}),H.api.onDidMovePanel(W),H.api.onDidDrop(W),w(((le=H.api.activePanel)==null?void 0:le.id)??null)},[R,W,A,C,K,q,_,w,b,N,t]);a.useEffect(()=>{const H=M.current;!H||!S.current||(Ys(H,t),Xs(H,t,y),!H.activePanel&&H.panels[0]&&H.panels[0].group.model.openPanel(H.panels[0]))},[y,t]),a.useEffect(()=>{S.current&&R(b)},[R,b]),a.useEffect(()=>{if(!j||typeof window>"u")return;const H=()=>W();return window.addEventListener("pointerup",H),window.addEventListener("mouseup",H),window.addEventListener("dragend",H),()=>{window.removeEventListener("pointerup",H),window.removeEventListener("mouseup",H),window.removeEventListener("dragend",H)}},[W,j]),a.useEffect(()=>()=>{typeof window>"u"||B.current!=null&&window.clearTimeout(B.current)},[]);const ie=v==="light"?Lr:_r;return e.jsx(Qn.Provider,{value:T,children:e.jsx("div",{ref:g,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(Rr,{className:`h-full min-h-0 min-w-0 adhdev-dockview${j?" is-dragging-dockview":""}${L?" is-showing-dockview-overlay":""}`,components:{conversation:Ro,remote:Lo},defaultTabComponent:Eo,watermarkComponent:_o,onReady:U,singleTabMode:"default",tabAnimation:"smooth",theme:ie})})})}function Do({showMobileChatMode:t,isMobile:s,activeConv:n,chatIdes:r,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:u,onFitCli:l,onStopCli:x,activeCliViewMode:d,onSetActiveCliViewMode:f,mobileChatConversations:h,ides:m,actionLogs:w,sendDaemonCommand:b,setLocalUserMessages:y,setActionLogs:p,isStandalone:v,userName:N,requestedMobileTabKey:M,onRequestedMobileTabConsumed:g,requestedMachineId:S,onRequestedMachineConsumed:j,containerRef:k,isSplitMode:L,numGroups:P,groupSizes:B,groupedConvs:K,clearedTabs:C,screenshotMap:D,setScreenshotMap:T,focusedGroup:R,setFocusedGroup:q,moveTabToGroup:A,splitTabRelative:_,closeGroup:W,handleResizeStart:U,detectedIdes:ie,handleLaunchIde:H,groupActiveTabIds:F,setGroupActiveTabIds:le,groupTabOrders:ne,setGroupTabOrders:O,toggleHiddenTab:X,visibleConversations:V,requestedDesktopTabKey:I,onRequestedDesktopTabConsumed:G,onDesktopActiveTabChange:Y,onOpenDesktopConversation:ae}){return e.jsxs(e.Fragment,{children:[!t&&e.jsx(Ya,{activeConv:n,agentCount:r.length,wsStatus:i,isConnected:o,conversations:V,onOpenHistory:c,onOpenConversation:ae,onOpenRemote:()=>{!n||Se(n)||we(n)||u(n)},onFitCli:l,onStopCli:x,activeCliViewMode:d,onSetCliViewMode:f}),t?e.jsx(xo,{conversations:h,ides:m,actionLogs:w,sendDaemonCommand:b,setLocalUserMessages:y,setActionLogs:p,isStandalone:v,userName:N,requestedActiveTabKey:M,onRequestedActiveTabConsumed:g,requestedMachineId:S,onRequestedMachineConsumed:j,onOpenHistory:c,onOpenRemote:u}):s?e.jsx(Io,{containerRef:k,isSplitMode:L,numGroups:P,groupSizes:B,groupedConvs:K,clearedTabs:C,ides:m,actionLogs:w,screenshotMap:D,setScreenshotMap:T,sendDaemonCommand:b,setLocalUserMessages:y,setActionLogs:p,isStandalone:v,userName:N,focusedGroup:R,setFocusedGroup:q,moveTabToGroup:A,splitTabRelative:_,closeGroup:W,handleResizeStart:U,detectedIdes:ie,handleLaunchIde:H,groupActiveTabIds:F,setGroupActiveTabIds:le,groupTabOrders:ne,setGroupTabOrders:O,toggleHiddenTab:X}):e.jsx(Po,{visibleConversations:V,clearedTabs:C,ides:m,actionLogs:w,screenshotMap:D,setScreenshotMap:T,sendDaemonCommand:b,setLocalUserMessages:y,setActionLogs:p,isStandalone:v,userName:N,detectedIdes:ie,handleLaunchIde:H,toggleHiddenTab:X,onActiveTabChange:Y,requestedActiveTabKey:I,onRequestedActiveTabConsumed:G})]})}const ss=[{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 $o({onClose:t}){const[s,n]=a.useState(0),r=ss[s],i=s===ss.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:ss.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:`
|
|
56
|
-
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
|
|
57
|
-
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
|
|
58
|
-
`})]})}function Bo({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,u=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:u?"var(--status-warning)":l?"var(--accent-primary)":"#64748b",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),o.title,u&&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 Ko({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:i,preferredTabKey:o}){const[c,u]=a.useState(()=>o||"native"),l=a.useMemo(()=>Rn(s),[s]),x=a.useMemo(()=>{var y;if(!t)return[];const b=t.daemonId||((y=t.id)==null?void 0:y.split(":")[0])||t.id;return Ln(t,r,{machineName:t.daemonId&&l[t.daemonId]||void 0,connectionState:n[b]||"new"})},[t,r,l,n]),d=a.useMemo(()=>x.find(b=>b.streamSource==="native"),[x]),f=a.useMemo(()=>x.filter(b=>b.streamSource==="agent-stream"),[x]);a.useEffect(()=>{o&&u(o)},[o]),a.useEffect(()=>{var b;c!=="native"&&(f.some(y=>y.tabKey===c)||u(((b=f[0])==null?void 0:b.tabKey)||"native"))},[c,f]),a.useEffect(()=>{c==="native"&&(d||f[0]&&u(f[0].tabKey))},[c,d,f]);const h=a.useMemo(()=>c==="native"&&d?d:f.find(b=>b.tabKey===c)||d||f[0],[c,d,f]),m=a.useMemo(()=>f.map(b=>({tabKey:b.tabKey,title:b.title||b.agentName||i,status:b.status})),[f,i]),w=a.useCallback(b=>{if(b)return x.find(y=>y.sessionId===b||y.ideId===b||y.tabKey===b||y.ideType===b||y.agentType===b)},[x]);return{activeChatTab:c,setActiveChatTab:u,activeConv:h,conversations:x,extensionTabs:m,hasExtensions:m.length>0,resolveConversationByTarget:w}}function Wo({activeConv:t,ideEntry:s,ides:n,connectionStates:r,actionLogs:i,localUserMessages:o,sendDaemonCommand:c,setLocalUserMessages:u,setActionLogs:l,isStandalone:x,userName:d,onOpenHistory:f,onConversationChange:h,onClose:m}){var T;const[w,b]=a.useState("split"),[y,p]=a.useState(()=>t.streamSource==="native"?"native":t.tabKey),v=a.useMemo(()=>s||n.find(R=>R.id===t.ideId),[t.ideId,s,n]),N=a.useMemo(()=>ke((v==null?void 0:v.type)||""),[v==null?void 0:v.type]),{conversations:M,extensionTabs:g,hasExtensions:S}=Ko({ideData:v,allIdes:n,connectionStates:r,localUserMessages:o,ideName:N||"IDE",preferredTabKey:t.streamSource==="native"?"native":t.tabKey});a.useEffect(()=>{p(t.streamSource==="native"?"native":t.tabKey)},[t.streamSource,t.tabKey]);const j=a.useMemo(()=>y==="native"?M.find(R=>R.streamSource==="native")||t:M.find(R=>R.tabKey===y)||t,[t,M,y]),k=j.daemonId||((T=j.ideId)==null?void 0:T.split(":")[0])||j.ideId,L=Ut({sendDaemonCommand:c,activeConv:j,setLocalUserMessages:u,setActionLogs:l,isStandalone:x}),{connScreenshot:P,screenshotUsage:B,handleRemoteAction:K}=Zn({doId:k,ideId:j.ideId,ideType:j.ideType,connState:j.connectionState||"new",viewMode:w,instanceId:v==null?void 0:v.instanceId}),C=a.useMemo(()=>i.filter(R=>R.ideId===j.tabKey),[i,j.tabKey]);a.useEffect(()=>{h==null||h(j)},[j,h]),a.useEffect(()=>{const R=q=>{q.key==="Escape"&&m()};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[m]);const D=a.useCallback(R=>{R.stopPropagation()},[]);return e.jsx("div",{className:"dashboard-remote-dialog-overlay",onClick:m,children:e.jsxs("div",{className:"dashboard-remote-dialog is-fullscreen",role:"dialog","aria-modal":"true",onClick:D,children:[e.jsxs("div",{className:"dashboard-remote-dialog-header",children:[e.jsx("div",{className:"dashboard-remote-dialog-title-block",children:e.jsxs("div",{className:"dashboard-remote-dialog-title",children:[e.jsx(Pe,{size:16}),e.jsx("span",{children:j.displayPrimary||j.agentName||"Remote"})]})}),e.jsxs("div",{className:"dashboard-remote-dialog-actions",children:[["split","remote"].map(R=>e.jsx("button",{className:`btn btn-secondary btn-sm dashboard-remote-dialog-mode${w===R?" is-active":""}`,onClick:()=>b(R),title:R==="split"?"Split view":"Remote only",children:R==="split"?"⊞":e.jsx(Pe,{size:14})},R)),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>f(j),title:"Chat History",children:e.jsx(ms,{size:14})}),e.jsx("button",{className:"btn btn-primary btn-sm",onClick:m,children:"Close"})]})]}),e.jsxs("div",{className:`dashboard-remote-dialog-body view-${w}`,children:[w!=="remote"&&e.jsxs("div",{className:"dashboard-remote-dialog-chat",children:[e.jsx(Bo,{hasExtensions:S,ideName:N||"IDE",activeChatTab:y,extensionTabs:g,onSelectTab:p}),e.jsx(yn,{activeConv:j,onModalButton:L.handleModalButton}),e.jsx(pt,{activeConv:j,ideEntry:v,showMetaChips:!1,handleSendChat:L.handleSendChat,isSendingChat:L.isSendingChat,handleFocusAgent:L.handleFocusAgent,isFocusingAgent:L.isFocusingAgent,actionLogs:C,userName:d})]}),e.jsx("div",{className:"dashboard-remote-dialog-remote",children:e.jsx(gn,{addLog:()=>{},connState:j.connectionState||"new",connScreenshot:P,screenshotUsage:B,transportType:j.transport,onAction:K})})]})]})})}function Oo({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 zo({historyModalOpen:t,historyTargetConv:s,ides:n,isHistoryCreatingChat:r,isHistoryRefreshingHistory:i,onCloseHistory:o,onNewHistoryChat:c,onSwitchHistorySession:u,onRefreshHistory:l,remoteDialogConv:x,remoteDialogIdeEntry:d,connectionStates:f,actionLogs:h,localUserMessages:m,sendDaemonCommand:w,setLocalUserMessages:b,setActionLogs:y,isStandalone:p,userName:v,onOpenRemoteHistory:N,onRemoteConversationChange:M,onCloseRemoteDialog:g,cliStopDialogOpen:S,activeConv:j,onCancelCliStop:k,onStopCliNow:L,onSaveCliAndStop:P,toasts:B,onDismissToast:K,onClickToast:C,showOnboarding:D,onCloseOnboarding:T}){return e.jsxs(e.Fragment,{children:[t&&s&&e.jsx(Xa,{activeConv:s,ides:n,isCreatingChat:r,isRefreshingHistory:i,onClose:o,onNewChat:c,onSwitchSession:u,onRefreshHistory:l}),x&&e.jsx(Wo,{activeConv:x,ideEntry:d,ides:n,connectionStates:f,actionLogs:h,localUserMessages:m,sendDaemonCommand:w,setLocalUserMessages:b,setActionLogs:y,isStandalone:p,userName:v,onOpenHistory:N,onConversationChange:M,onClose:g}),S&&j&&Se(j)&&!we(j)&&e.jsx(Oo,{activeConv:j,onCancel:k,onStopNow:L,onSaveAndStop:P}),e.jsx(Tn,{toasts:B,onDismiss:K,onClickToast:C}),D&&e.jsx($o,{onClose:T})]})}function Uo({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(ps,{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=We(o,{fallbackId:o.id}),u=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]}),u==="upgrading"?e.jsx("span",{className:"text-[10px] animate-pulse",style:{color:"var(--status-warning)"},children:"upgrading…"}):u==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):u==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>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 Fo(){var Ss,Cs;const{sendCommand:t}=Fe(),s=us(),n=tt(),[r,i]=Er(),o=r.get("activeTab"),c=((Ss=s.state)==null?void 0:Ss.openRemoteForTabKey)||null,u=((Cs=s.state)==null?void 0:Cs.openMachineId)||null,l=ys(),{updateIdeChats:x,screenshotMap:d,setScreenshotMap:f}=l,h=l.ides||[],[m,w]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),b=l.toasts||[],y=l.setToasts||(()=>{}),p=l.wsStatus||"connected",v=l.isConnected??!0,N=l.connectionStates||{},M=l.showReconnected||!1,{groupAssignments:g,setGroupAssignments:S,focusedGroup:j,setFocusedGroup:k,groupActiveTabIds:L,setGroupActiveTabIds:P,groupTabOrders:B,setGroupTabOrders:K,groupSizes:C,setGroupSizes:D,isMobile:T,hasHydratedStoredLayout:R,hydrateStoredLayout:q}=eo(),[A,_]=a.useState(!1),[W,U]=a.useState(!1),[ie]=a.useState(()=>zn()),[H,F]=a.useState([]),[le,ne]=a.useState({}),[O,X]=a.useState({}),[V,I]=a.useState(null);xt("Dashboard",{ideCount:h.length,toastCount:b.length,focusedGroup:j,groupCount:Object.keys(g).length,localMessageTabs:Object.keys(le).length,actionLogCount:H.length});const G=h.find(be=>be.type==="adhdev-daemon"),Y=(G==null?void 0:G.detectedIdes)||[],ae=!!G,me=(G==null?void 0:G.terminalBackend)||null,{hiddenTabs:ue,toggleTab:xe}=Fn(),{chatIdes:J,conversations:se,visibleConversations:Z,visibleTabKeys:E,resolveConversationBySessionId:Q,resolveConversationByTarget:re}=Fi({ides:h,connectionStates:N,localUserMessages:le,clearedTabs:O,hiddenTabs:ue}),{containerRef:oe,normalizedGroupAssignments:ge,numGroups:Ne,isSplitMode:de,groupedConvs:Te,moveTabToGroup:$,closeGroup:z,handleResizeStart:te,splitTabRelative:ce}=oo({groupAssignments:g,setGroupAssignments:S,setFocusedGroup:k,setGroupActiveTabIds:P,setGroupTabOrders:K,groupSizes:C,setGroupSizes:D,isMobile:T,visibleConversations:Z,visibleTabKeys:E}),ee=a.useMemo(()=>{var Me,Le;if(!T){if(V){const He=se.find(Yt=>Yt.tabKey===V);if(He)return He}return Z[0]}const be=L[j];if(be){const He=se.find(Yt=>Yt.tabKey===be);if(He)return He}return((Me=Te[j])==null?void 0:Me[0])||((Le=Te[0])==null?void 0:Le[0])},[V,T,L,j,se,Te,Z]),{requestedDesktopTabKey:fe,requestedMobileTabKey:ye,consumeRequestedActiveTab:he}=Hi({isMobile:T,urlActiveTab:o,resolveConversationBySessionId:Q,setSearchParams:i}),{remoteDialogConv:Re,remoteDialogIdeEntry:Vt,remoteDialogActiveConv:er,setRemoteDialogActiveConv:qt,openRemoteDialog:tr,closeRemoteDialog:sr}=so({isMobile:T,location:s,navigate:n,requestedRemoteTabTarget:c,requestedDesktopTabKey:fe,conversations:se,ides:h,resolveConversationByTarget:re}),Ns=er||Re||ee,nr=a.useMemo(()=>Z,[Z]),ft=T&&ie==="chat";Ki({visibleConversations:Z,clearedTabs:O,setClearedTabs:X,setActionLogs:F}),Vi({ides:h,sendDaemonCommand:t,setToasts:y,setLocalUserMessages:ne,resolveConversationByTarget:re});const{isRefreshingHistory:rr,handleLaunchIde:ar,handleRefreshHistory:ir}=zs({sendDaemonCommand:t,activeConv:ee,updateIdeChats:x,setToasts:y,setLocalUserMessages:ne,setClearedTabs:X}),{isCreatingChat:or,isRefreshingHistory:cr,handleSwitchSession:lr,handleNewChat:dr,handleRefreshHistory:ur}=zs({sendDaemonCommand:t,activeConv:Ns,updateIdeChats:x,setToasts:y,setLocalUserMessages:ne,setClearedTabs:X});to({urlActiveTab:T&&!ft?o:null,conversations:se,resolveConversationBySessionId:Q,normalizedGroupAssignments:ge,hasHydratedStoredLayout:T&&!ft?R:!0,hydrateStoredLayout:T&&!ft?q:()=>{},setGroupActiveTabIds:P,setFocusedGroup:k,setSearchParams:i,historyModalOpen:A,activeConv:ee,isRefreshingHistory:rr,ides:h,handleRefreshHistory:ir});const bt=a.useCallback(async be=>{if(!ee||!Se(ee)||we(ee))return;const Me=ee.ideType||ee.agentType||"",Le=ee.ideId||ee.daemonId||"";try{await t(Le,"stop_cli",{cliType:Me,targetSessionId:ee.sessionId,mode:be})}catch(He){console.error("Stop CLI failed:",He)}},[ee,t]),hr=a.useCallback(async()=>{var Me;if(!ee||!Se(ee)||we(ee))return;if((Me=ee.resume)!=null&&Me.supported){U(!0);return}const be=ee.ideType||ee.agentType||"CLI";window.confirm(`Stop ${be}?
|
|
59
|
-
This will terminate the CLI process.`)&&await bt("hard")},[ee,bt]),mr=a.useMemo(()=>!ee||!Se(ee)||we(ee)?null:et(ee),[ee]),pr=a.useCallback(async be=>{if(!(!ee||!Se(ee)||we(ee)||et(ee)===be))try{await t(ee.daemonId||ee.ideId,"set_cli_view_mode",{targetSessionId:ee.sessionId,cliType:ee.ideType||ee.agentType,mode:be})}catch(Le){console.error("Failed to switch CLI view mode:",Le)}},[ee,t]),xr=a.useCallback(()=>{!ee||!gs(ee)||we(ee)||!ee.sessionId||Bi()&&window.dispatchEvent(new CustomEvent("adhdev:fit-cli-terminal",{detail:{sessionId:ee.sessionId}}))},[ee]),{versionMismatchDaemons:fr,appVersion:br,versionBannerDismissed:gr,setVersionBannerDismissed:yr,upgradingDaemons:vr,handleBannerUpgrade:jr}=co({ides:h,sendDaemonCommand:t}),wr=a.useCallback(be=>{I(be.tabKey),i(Me=>{const Le=new URLSearchParams(Me);return be.sessionId?Le.set("activeTab",be.sessionId):Le.delete("activeTab"),Le},{replace:!0})},[i]);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(Fa,{wsStatus:p,showReconnected:M}),e.jsx(Ha,{terminalBackend:me,isStandalone:ae}),!gr&&e.jsx(Uo,{daemons:fr,targetVersion:br,upgradingDaemons:vr,onUpgrade:jr,onDismiss:()=>yr(!0)}),e.jsx(Do,{showMobileChatMode:ft,isMobile:T,activeConv:ee,chatIdes:J,wsStatus:p,isConnected:v,onOpenHistory:be=>{be&&qt(be),_(!0)},onOpenRemote:tr,onFitCli:xr,onStopCli:hr,activeCliViewMode:mr,onSetActiveCliViewMode:pr,mobileChatConversations:nr,ides:h,actionLogs:H,sendDaemonCommand:t,setLocalUserMessages:ne,setActionLogs:F,isStandalone:ae,userName:l.userName,requestedMobileTabKey:ye,onRequestedMobileTabConsumed:he,requestedMachineId:u,onRequestedMachineConsumed:()=>{n(s.pathname+s.search,{replace:!0,state:null})},containerRef:oe,isSplitMode:de,numGroups:Ne,groupSizes:C,groupedConvs:Te,clearedTabs:O,screenshotMap:d,setScreenshotMap:f,focusedGroup:j,setFocusedGroup:k,moveTabToGroup:$,splitTabRelative:ce,closeGroup:z,handleResizeStart:te,detectedIdes:Y,handleLaunchIde:ar,groupActiveTabIds:L,setGroupActiveTabIds:P,groupTabOrders:B,setGroupTabOrders:K,toggleHiddenTab:xe,visibleConversations:Z,requestedDesktopTabKey:fe,onRequestedDesktopTabConsumed:he,onDesktopActiveTabChange:I,onOpenDesktopConversation:wr}),e.jsx("style",{children:`
|
|
60
|
-
body { overflow: hidden; overscroll-behavior: none; }
|
|
61
|
-
`}),e.jsx(zo,{historyModalOpen:A,historyTargetConv:Ns,ides:h,isHistoryCreatingChat:or,isHistoryRefreshingHistory:cr,onCloseHistory:()=>_(!1),onNewHistoryChat:dr,onSwitchHistorySession:lr,onRefreshHistory:ur,remoteDialogConv:Re,remoteDialogIdeEntry:Vt,connectionStates:N,actionLogs:H,localUserMessages:le,sendDaemonCommand:t,setLocalUserMessages:ne,setActionLogs:F,isStandalone:ae,userName:l.userName,onOpenRemoteHistory:be=>{be&&qt(be),_(!0)},onRemoteConversationChange:qt,onCloseRemoteDialog:sr,cliStopDialogOpen:W,activeConv:ee,onCancelCliStop:()=>U(!1),onStopCliNow:async()=>{U(!1),await bt("hard")},onSaveCliAndStop:async()=>{U(!1),await bt("save")},toasts:b,onDismissToast:be=>y(Me=>Me.filter(Le=>Le.id!==be)),onClickToast:be=>{if(be.targetKey){const Me=re(be.targetKey);Me&&k(ge.get(Me.tabKey)??0)}},showOnboarding:m,onCloseOnboarding:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}w(!1)}})]})}function Ho({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:i}){const[o,c]=a.useState([]),[u,l]=a.useState(null),[x,d]=a.useState(null),[f,h]=a.useState(!1),[m,w]=a.useState(null),[b,y]=a.useState(!1),[p,v]=a.useState(""),N=a.useRef(null),M=a.useCallback(A=>{N.current=A},[]),g=a.useCallback((A,_,W=!1)=>{c(U=>[...U.slice(-100),{timestamp:Date.now(),level:A,message:_}]),setTimeout(()=>{var U;return(U=i.current)==null?void 0:U.scrollIntoView({behavior:"smooth"})},100),W&&ze.showToast(_,A==="error"||A==="warn"?"warning":"success")},[i]),S=a.useCallback(async(A,_)=>{var W;if(!t||u)return!1;l(A),g("info",`Launching ${ke(A)}${_!=null&&_.workspace?` in ${_.workspace}`:""}...`);try{const U={ideType:A,enableCdp:!0};(W=_==null?void 0:_.workspace)!=null&&W.trim()?U.workspace=_.workspace.trim():_!=null&&_.useDefaultWorkspace&&(U.useDefaultWorkspace=!0);const ie=await n(t,"launch_ide",U);return g(ie!=null&&ie.success?"info":"error",ie!=null&&ie.success?`${ke(A)} launched`:`Failed: ${ie==null?void 0:ie.error}`,!0),!!(ie!=null&&ie.success)}catch(U){return g("error",`Launch error: ${U.message}`,!0),!1}finally{l(null)}},[t,u,g,n]),j=a.useCallback(async A=>{if(!t)return{success:!1};const{cliType:_,dir:W,workspaceId:U,useDefaultWorkspace:ie,useHome:H,argsStr:F,model:le}=A;if(!_)return g("warn","Select a CLI or ACP provider first",!0),{success:!1};const ne=F?F.split(/\s+/).filter(Boolean):void 0,O=(W==null?void 0:W.trim())||(U?"(saved id)":ie?"(default workspace)":H?"(home)":"");g("info",`Launching ${_}${O?` in ${O}`:""}${le?` (model: ${le})`:""}...`),d(_);try{const X={cliType:_,cliArgs:ne,initialModel:le||void 0};W!=null&&W.trim()?X.dir=W.trim():U?X.workspaceId=U:ie?X.useDefaultWorkspace=!0:H&&(X.useHome=!0);const V=await n(t,"launch_cli",X),I=(V==null?void 0:V.result)||V;return V!=null&&V.success?(g("info",`${_} launched`,!0),(I==null?void 0:I.launchSource)==="home"?g("info","📂 Running in home directory (explicit choice)"):(I==null?void 0:I.launchSource)==="defaultWorkspace"&&g("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:I==null?void 0:I.sessionId}):(g("error",`Failed: ${(V==null?void 0:V.error)||(I==null?void 0:I.error)}`,!0),(V==null?void 0:V.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&w({cliType:_,argsStr:F,model:le}),{success:!1,sessionId:I==null?void 0:I.sessionId})}catch(X){return g("error",`Launch error: ${X.message}`,!0),{success:!1}}finally{d(null)}},[t,g,n]),k=a.useCallback(async(A,_,W,U)=>t?A?_.trim()?j({cliType:A,dir:_,argsStr:W,model:U}):(w({cliType:A,argsStr:W,model:U}),{success:!1}):(g("warn","Select a provider",!0),{success:!1}):{success:!1},[t,g,j]),L=a.useCallback(async(A,_,W)=>{if(t&&window.confirm(`Stop ${A}?
|
|
62
|
-
This will terminate the process.`))try{const U=await n(t,"stop_cli",{cliType:A,dir:_,targetSessionId:W});U!=null&&U.success?g("info",`${A} stopped`,!0):g("error",`Stop failed: ${(U==null?void 0:U.error)||"Unknown error"}`,!0)}catch(U){g("error",`Stop failed: ${U.message}`,!0)}},[t,g,n]),P=a.useCallback(async A=>{try{await n(A.daemonId,"restart_ide",{ideType:A.type}),g("info",`${ke(A.type)} restart initiated`,!0)}catch(_){g("error",`Restart failed: ${_.message}`,!0)}},[g,n]),B=a.useCallback(async A=>{if(window.confirm(`Stop ${ke(A.type)}?
|
|
63
|
-
This will disconnect CDP and optionally kill the process.`))try{const _=await n(A.daemonId,"stop_ide",{ideType:A.type,killProcess:!0});_!=null&&_.success?g("info",`${ke(A.type)} stopped`,!0):g("error",`Stop failed: ${(_==null?void 0:_.error)||"Unknown error"}`,!0)}catch(_){g("error",`Stop failed: ${_.message}`,!0)}},[g,n]),K=a.useCallback(async()=>{if(t)try{const A=await n(t,"detect_ides",{});g("info",`Found ${((A==null?void 0:A.result)||[]).length} IDE(s)`,!0)}catch(A){g("error",`Detection failed: ${A.message}`,!0)}},[t,g,n]),C=a.useCallback(async A=>{if(!(!t||!A.trim())){h(!0);try{const _=await n(t,"workspace_add",{path:A.trim()});_!=null&&_.success?g("info",`Workspace added: ${A.trim()}`):g("error",(_==null?void 0:_.error)||"workspace_add failed")}catch(_){g("error",_.message)}finally{h(!1)}return!0}},[t,g,n]),D=a.useCallback(async A=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){h(!0);try{const _=await n(t,"workspace_remove",{id:A});_!=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]),T=a.useCallback(async A=>{var _;if(t){h(!0);try{const W=await n(t,"workspace_set_default",A===null?{clear:!0}:{id:A});if(W!=null&&W.success){g("info",A?"Default workspace updated":"Default workspace cleared",!0);const U=typeof W.defaultWorkspacePath=="string"?W.defaultWorkspacePath:"";U&&((_=N.current)==null||_.call(N,U))}else g("error",(W==null?void 0:W.error)||"workspace_set_default failed",!0)}catch(W){g("error",W.message,!0)}finally{h(!1)}}},[t,g,n]),R=a.useCallback(async A=>{var W;if(!t||!A.trim())return;const _=A.trim();h(!0);try{const U=await n(t,"workspace_set_default",{path:_});U!=null&&U.success?(g("info","Default workspace set from history"),(W=N.current)==null||W.call(N,_)):g("error",(U==null?void 0:U.error)||"Could not set default (path missing on disk?)")}catch(U){g("error",U.message)}finally{h(!1)}},[t,g,n]),q=a.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:p}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:p})}catch(A){g("warn",`Live nickname updated, but account sync failed: ${A.message}`)}g("info",`Nickname set to "${p||"(cleared)"}"`),y(!1)}catch(A){g("error",`Failed: ${A.message}`)}},[t,p,s,g,r,n]);return{logs:o,launchingIde:u,launchingAgentType:x,workspaceBusy:f,launchPick:m,setLaunchPick:w,editingNickname:b,setEditingNickname:y,nicknameInput:p,setNicknameInput:v,addLog:g,handleLaunchIde:S,runLaunchCliCore:j,handleLaunchCli:k,handleStopCli:L,handleRestartIde:P,handleStopIde:B,handleDetectIdes:K,handleWorkspaceAdd:C,handleWorkspaceRemove:D,handleWorkspaceSetDefault:T,handleWorkspaceResumePath:R,handleSaveNickname:q,setOnDefaultWorkspaceChanged:M}}function Vo({machine:t,ideSessions:s,cliSessions:n,acpSessions:r,actions:i,isDashboardHidden:o,onToggleDashboardVisibility:c}){const{workspaceBusy:u,handleWorkspaceAdd:l,handleWorkspaceRemove:x,handleWorkspaceSetDefault:d}=i,[f,h]=a.useState(""),m=t.availableMem??t.freeMem,w=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-m)/t.totalMem*100))):0,b=t.loadavg[0]||0,y=[...s.map(p=>({id:p.id,label:`IDE · ${p.type}`,workspace:p.workspace||""})),...n.map(p=>({id:p.id,label:`CLI · ${p.cliName}`,workspace:p.workspace||""})),...r.map(p=>({id:p.id,label:`ACP · ${p.acpName}`,workspace:p.workspace||""}))].filter(p=>o==null?void 0:o(p.id));return e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-5",children:[e.jsx(gt,{icon:e.jsx(pn,{size:16}),label:"Uptime",value:Ia(t.uptime)}),e.jsx(gt,{icon:e.jsx(Pe,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(gt,{icon:e.jsx(bs,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(gt,{icon:e.jsx(na,{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(Rs,{value:Math.min(Math.round(b/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${b.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Rs,{value:w,max:100,label:"Memory",color:"#3b82f6",detail:`${Es(t.totalMem-m)} / ${Es(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(as,{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:u,value:t.defaultWorkspaceId||"",onChange:p=>void d(p.target.value===""?null:p.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(p=>e.jsx("option",{value:p.id,children:p.label||p.path},p.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:u,onChange:p=>h(p.target.value),onKeyDown:p=>p.key==="Enter"&&void(async()=>{await l(f)&&h("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:u,onClick:async()=>{await l(f)&&h("")},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(p=>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:[p.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:jn(p.path,p.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:p.path,children:p.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:u,onClick:()=>void x(p.id),children:"Remove"})]},p.id))})]}),y.length>0&&c&&e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsx("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-3",children:"Hidden From Dashboard"}),e.jsx("div",{className:"flex flex-col gap-2",children:y.map(p=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[12px] font-medium text-text-primary truncate",children:p.label}),p.workspace&&e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:p.workspace,children:p.workspace})]}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] px-2.5 py-1 text-zinc-300 border-zinc-500/30",onClick:()=>c(p.id),children:"Show"})]},p.id))})]})]})}const Gs=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],qo=[{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 Yo({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[i,o]=a.useState("config"),[c,u]=a.useState("codex-cli"),[l,x]=a.useState([]),[d,f]=a.useState(""),[h,m]=a.useState([]),[w,b]=a.useState(""),y=a.useRef(null),p=a.useRef(null),v=k=>{x(L=>L.includes(k)?L.filter(P=>P!==k):[...L,k])},N=()=>x([...Gs]),M=()=>x([]);a.useEffect(()=>{var k;(k=y.current)==null||k.scrollIntoView({behavior:"smooth"})},[h]),a.useEffect(()=>()=>{p.current&&clearInterval(p.current)},[]);const g=a.useCallback(()=>{p.current&&clearInterval(p.current),p.current=setInterval(async()=>{try{const k=await n(t,"provider_auto_fix_status",{providerType:s.type});(k==null?void 0:k.running)===!1&&i==="running"&&(o("done"),m(L=>[...L,`
|
|
64
|
-
✅ Auto-fix completed!`]),p.current&&clearInterval(p.current))}catch{}},3e3)},[t,s.type,n,i]),S=async()=>{if(l.length!==0){o("running"),m(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${l.join(", ")}`,d?`💬 Comment: ${d}`:"",""]),b("");try{const k=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:c,...d?{comment:d}:{}});k!=null&&k.success&&(k!=null&&k.started||k!=null&&k.running)?(m(L=>[...L,"✅ Agent started. Monitoring progress..."]),g()):(o("error"),b((k==null?void 0:k.error)||"Failed to start auto-fix"))}catch(k){o("error"),b((k==null?void 0:k.message)||"Connection failed")}}},j=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),m(k=>[...k,`
|
|
65
|
-
⚠️ Auto-fix cancelled.`]),o("done"),p.current&&clearInterval(p.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:r,children:e.jsxs("div",{className:"w-full max-w-[560px] max-h-[85vh] overflow-hidden rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:s.icon||"🔧"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-text-primary",children:["Auto-Fix: ",s.displayName]}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"AI agent will implement provider scripts"})]})]}),e.jsx("button",{onClick:r,className:"text-text-muted hover:text-text-primary text-lg leading-none",children:"×"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[i==="config"&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"AI Agent"}),e.jsx("div",{className:"flex gap-2",children:qo.map(k=>e.jsxs("button",{onClick:()=>u(k.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===k.value?k.color+"66":"var(--border-subtle)",background:c===k.value?k.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===k.value?k.color:"var(--text-primary)"},children:k.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:k.desc})]},k.value))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"Scripts to Fix"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:N,className:"text-[10px] text-violet-400 hover:text-violet-300",children:"All"}),e.jsx("span",{className:"text-[10px] text-text-muted",children:"|"}),e.jsx("button",{onClick:M,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:Gs.map(k=>e.jsxs("button",{onClick:()=>v(k),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(k)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:l.includes(k)?"rgba(139,92,246,0.08)":"transparent",color:l.includes(k)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(k)?"☑ ":"☐ ",k]},k))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:["Additional Instructions ",e.jsx("span",{className:"text-text-muted font-normal",children:"(optional)"})]}),e.jsx("textarea",{value:d,onChange:k=>f(k.target.value),placeholder:"e.g. Also search buttons inside Shadow DOM, preserve code block formatting in readChat...",rows:2,className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] resize-none placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]})]}),(i==="running"||i==="done"||i==="error")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Agent Output"}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-[#0d0d0d] p-3 font-mono text-[11px] leading-relaxed text-text-secondary overflow-y-auto",style:{maxHeight:320,minHeight:200},children:[h.map((k,L)=>e.jsx("div",{className:k.startsWith("✅")?"text-green-400":"",style:k.startsWith("❌")||k.startsWith("⚠")?{color:"var(--status-warning)"}:void 0,children:k},L)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:y})]}),w&&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:w})]})]}),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:S,disabled:l.length===0,className:"machine-btn",style:{background:l.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:l.length>0?"rgba(139,92,246,0.4)":void 0,color:l.length>0?"#a78bfa":void 0,opacity:l.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:j,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"),m([]),b("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function Xo({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:i}){var g;const o=s.filter(S=>S.category==="ide"),[c,u]=a.useState(((g=o[0])==null?void 0:g.type)||""),[l,x]=a.useState(""),[d,f]=a.useState(""),[h,m]=a.useState(!1),[w,b]=a.useState(""),[y,p]=a.useState(!1),v=S=>{const j=S.toLowerCase().replace(/[^a-z0-9-]/g,"");x(j),(!d||d===N(l))&&f(N(j))},N=S=>S.split("-").map(j=>j.charAt(0).toUpperCase()+j.slice(1)).join(" "),M=async()=>{if(!(!l||!d||!c)){m(!0),b("");try{const S=await n(t,"provider_clone",{type:l,name:d,category:"ide",location:"user",cloneFrom:c});S!=null&&S.success||S!=null&&S.created?(p(!0),i==null||i(l)):b((S==null?void 0:S.error)||"Failed to create provider")}catch(S){b((S==null?void 0:S.message)||"Connection failed")}m(!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:S=>S.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:y?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(S=>e.jsxs("button",{onClick:()=>u(S.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===S.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:c===S.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:S.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===S.type?"#a78bfa":"var(--text-secondary)"},children:S.displayName})]},S.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:S=>v(S.target.value),placeholder:"my-cursor, custom-windsurf...",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"}),e.jsxs("p",{className:"text-[10px] text-text-muted mt-1",children:["Lowercase, alphanumeric + hyphens only. Will be created at ",e.jsxs("code",{className:"text-violet-400",children:["~/.adhdev/providers/",l||"...","/"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Display Name"}),e.jsx("input",{value:d,onChange:S=>f(S.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"})]}),w&&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:w})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:y?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:M,disabled:!l||!d||h,className:"machine-btn",style:{background:l&&d?"rgba(34,197,94,0.12)":void 0,borderColor:l&&d?"rgba(34,197,94,0.3)":void 0,color:l&&d?"#86efac":void 0,opacity:!l||!d||h?.4:1},children:h?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function Go({machineId:t,providers:s,sendDaemonCommand:n}){const[r,i]=a.useState([]),[o,c]=a.useState(!1),[u,l]=a.useState(null),[x,d]=a.useState("all"),[f,h]=a.useState(null),[m,w]=a.useState(!1),b=a.useCallback(async()=>{var p;if(t){c(!0);try{const v=await n(t,"get_provider_settings",{}),N=(v==null?void 0:v.result)||v;if(v!=null&&v.success&&(N!=null&&N.settings)){const M=[];for(const[g,S]of Object.entries(N.settings)){const j=s.find(k=>k.type===g);M.push({type:g,displayName:(j==null?void 0:j.displayName)||g,icon:(j==null?void 0:j.icon)||"",category:(j==null?void 0:j.category)||"unknown",schema:S,values:((p=N.values)==null?void 0:p[g])||{}})}M.sort((g,S)=>g.category.localeCompare(S.category)||g.displayName.localeCompare(S.displayName)),i(M)}}catch{}c(!1)}},[t,s,n]);a.useEffect(()=>{r.length===0&&b()},[]);const y=async(p,v,N)=>{l(`${p}.${v}`),i(M=>M.map(g=>g.type===p?{...g,values:{...g.values,[v]:N}}:g));try{const M=await n(t,"set_provider_setting",{providerType:p,key:v,value:N});M!=null&&M.success||b()}catch{b()}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(p=>e.jsx("button",{onClick:()=>d(p),className:`machine-btn text-[10px] px-2 py-0.5 ${x===p?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:p.toUpperCase()},p))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>w(!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:b,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),x!=="all"&&r.filter(p=>p.category===x).length>1&&(()=>{const p=r.filter(g=>g.category===x),v=new Map;for(const g of p)for(const S of g.schema){if(S.type!=="boolean")continue;const j=v.get(S.key),k=!!(g.values[S.key]??S.default);j?(j.onCount+=k?1:0,j.total+=1):v.set(S.key,{label:S.label||S.key,onCount:k?1:0,total:1})}const N=[...v.entries()].filter(([,g])=>g.total===p.length);if(N.length===0)return null;const M=async(g,S)=>{for(const j of p)await y(j.type,g,S)};return e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-500/[0.04] border border-violet-500/10 mb-4",children:[e.jsxs("div",{className:"text-[10px] text-violet-400 font-semibold uppercase tracking-wider mb-2",children:["Bulk — Apply to all ",x.toUpperCase()," providers (",p.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:N.map(([g,S])=>{const j=S.onCount===S.total,k=S.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:S.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",S.onCount,"/",S.total,")"]}),e.jsx("button",{onClick:()=>void M(g,!0),disabled:j,className:`machine-btn text-[9px] px-1.5 py-px ${j?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void M(g,!1),disabled:k,className:`machine-btn text-[9px] px-1.5 py-px ${k?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},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(p=>x==="all"||p.category===x).map(p=>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:p.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:p.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:p.category==="acp"?"rgba(139,92,246,0.08)":p.category==="cli"?"rgba(59,130,246,0.08)":p.category==="ide"?"rgba(34,197,94,0.08)":"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:p.category==="acp"?"#a78bfa":p.category==="cli"?"#60a5fa":p.category==="ide"?"#86efac":"var(--status-warning)"},children:p.category}),p.category==="ide"&&e.jsx("button",{onClick:()=>h(s.find(v=>v.type===p.type)||{type:p.type,name:p.displayName,displayName:p.displayName,icon:p.icon,category:p.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:p.schema.map(v=>e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-xs font-medium text-text-primary",children:[v.label||v.key,u===`${p.type}.${v.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),v.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:v.description})]}),e.jsx("div",{className:"shrink-0",children:v.type==="boolean"?e.jsx("button",{onClick:()=>y(p.type,v.key,!(p.values[v.key]??v.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:p.values[v.key]??v.default?"#8b5cf6":"var(--border-subtle)"},children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-white absolute top-[3px] transition-[left] duration-200 shadow-[0_1px_3px_rgba(0,0,0,0.3)]",style:{left:p.values[v.key]??v.default?21:3}})}):v.type==="number"?e.jsx("input",{type:"number",value:p.values[v.key]??v.default??0,min:v.min,max:v.max,onChange:N=>{const M=parseInt(N.target.value)||0;v.min!==void 0&&M<v.min||v.max!==void 0&&M>v.max||y(p.type,v.key,M)},className:"machine-input w-20 text-center text-[11px]"}):v.type==="select"&&v.options?e.jsx("select",{value:p.values[v.key]??v.default??"",onChange:N=>y(p.type,v.key,N.target.value),className:"machine-input text-[11px]",children:v.options.map(N=>e.jsx("option",{value:N,children:N},N))}):e.jsx("input",{type:"text",value:p.values[v.key]??v.default??"",onBlur:N=>y(p.type,v.key,N.target.value),className:"machine-input w-[120px] text-[11px]"})})]},v.key))})]},p.type))}),f&&e.jsx(Yo,{machineId:t,provider:f,sendDaemonCommand:n,onClose:()=>h(null)}),m&&e.jsx(Xo,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>w(!1),onCreated:()=>{w(!1),b()}})]})}function Jo({machineId:t,sendDaemonCommand:s}){const[n,r]=a.useState([]),[i,o]=a.useState(0),[c,u]=a.useState(!0),[l,x]=a.useState("debug"),d=a.useRef(null),f=a.useRef(!1);return a.useEffect(()=>{if(!t||!c)return;const h=async()=>{try{const w=await s(t,"get_logs",{count:200,minLevel:l,since:i}),b=(w==null?void 0:w.result)||w;if(w!=null&&w.success&&Array.isArray(b==null?void 0:b.logs)&&b.logs.length>0){r(p=>[...p,...b.logs.map(N=>({timestamp:N.ts,level:N.level,message:`[${N.category}] ${N.message}`}))].slice(-300));const y=Math.max(...b.logs.map(p=>p.ts));o(y)}}catch{}};h();const m=setInterval(h,3e3);return()=>clearInterval(m)},[t,c,i,l,s]),a.useEffect(()=>{if(c&&n.length>0){const h=f.current?"smooth":"instant";setTimeout(()=>{var m;(m=d.current)==null||m.scrollIntoView({behavior:h}),f.current=!0},50)}},[n.length,c]),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-3",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Level"}),["debug","info","warn","error"].map(h=>e.jsx("button",{onClick:()=>{x(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:()=>u(!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,m)=>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})]},m)),e.jsx("div",{ref:d})]})]})}function Zo({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 Js({children:t}){return e.jsx("div",{className:"machine-command-section-title",children:t})}function Qo({machineEntry:t,providers:s,recentLaunches:n,onUpgradeDaemon:r,onOpenLogs:i,onOpenRecent:o,onOpenWorkspace:c,onGoTab:u}){const l=t.detectedIdes||[],x=s.filter(w=>w.category==="cli"),d=s.filter(w=>w.category==="acp"),f=n.slice(0,4),h=[l.length>0?{id:"ide",kind:"ide",label:"IDE"}:null,x.length>0?{id:"cli",kind:"cli",label:"CLI"}:null,d.length>0?{id:"acp",kind:"acp",label:"ACP"}:null].filter(Boolean),m=w=>w==="ide"?"IDE":w==="cli"?"CLI":"ACP";return e.jsxs("div",{className:"machine-command-center",children:[f.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Js,{children:"Recent"}),e.jsx("div",{className:"machine-command-links",children:f.map(w=>e.jsxs("button",{type:"button",className:"machine-command-link",onClick:()=>o(w),children:[e.jsx("span",{className:"machine-command-link-title",children:w.label}),e.jsxs("span",{className:"machine-command-link-meta",children:[m(w.kind),w.subtitle?` · ${w.subtitle}`:""]})]},w.id))})]}),h.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Js,{children:"Start"}),e.jsx("div",{className:"machine-command-launch-grid",children:h.map(w=>e.jsxs("button",{type:"button",className:"machine-command-launch-btn",onClick:()=>c(w.kind),children:[e.jsx("span",{className:"machine-command-launch-title",children:w.label}),e.jsx("span",{className:"machine-command-launch-meta",children:"Choose workspace and provider"})]},w.id))})]}),e.jsxs("div",{className:"machine-command-secondary",children:[t.versionMismatch&&e.jsx("button",{type:"button",className:"machine-command-secondary-link machine-command-secondary-link-accent",onClick:r,children:"Update daemon"}),e.jsx("button",{type:"button",className:"machine-command-secondary-link",onClick:i,children:"Logs"}),e.jsx("button",{type:"button",className:"machine-command-secondary-link",onClick:()=>u("providers"),children:"Providers"}),e.jsx("button",{type:"button",className:"machine-command-secondary-link",onClick:()=>u("overview"),children:"System"})]})]})}function ec(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 ns({category:t,machine:s,machineId:n,providers:r,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:u,isDashboardHidden:l,onToggleDashboardVisibility:x,initialWorkspaceId:d,initialWorkspacePath:f}){const h=tt(),{handleLaunchIde:m,handleLaunchCli:w,handleStopCli:b,handleRestartIde:y,handleStopIde:p,handleDetectIdes:v,launchingIde:N,launchingAgentType:M}=c,[g,S]=a.useState(null),j=a.useCallback(E=>{E&&h({pathname:"/",search:`?activeTab=${encodeURIComponent(E)}`})},[h]),k=tc[t],L=t==="ide",P=t==="acp",B=r.filter(E=>E.category===t),K=new Map(B.map(E=>[E.type,E.displayName||E.type])),[C,D]=a.useState(""),[T,R]=a.useState(""),[q,A]=a.useState(""),[_,W]=a.useState(f?"__custom__":d||s.defaultWorkspaceId||""),[U,ie]=a.useState(f||""),[H,F]=a.useState([]),le=H.filter(E=>!i.some(Q=>Q.type===E&&Ae(Q.status)!=="stopped")),ne=a.useRef({});a.useEffect(()=>{!C&&B.length>0&&D(B[0].type)},[C,B.length]),a.useEffect(()=>{s.defaultWorkspaceId&&!_&&W(s.defaultWorkspaceId)},[s.defaultWorkspaceId]),a.useEffect(()=>{if(f){W("__custom__"),ie(f);return}d&&(W(d),ie(""))},[d,f]);const O=(()=>{if(_==="__custom__")return U.trim();if(!_)return"";const E=(s.workspaces||[]).find(Q=>Q.id===_);return(E==null?void 0:E.path)||""})(),X=a.useCallback(E=>{const Q=ne.current[E];Q&&(clearTimeout(Q),delete ne.current[E]),F(re=>re.filter(oe=>oe!==E))},[]),V=a.useCallback(E=>{if(!E)return;F(re=>re.includes(E)?re:[...re,E]);const Q=ne.current[E];Q&&clearTimeout(Q),ne.current[E]=setTimeout(()=>{F(re=>re.filter(oe=>oe!==E)),delete ne.current[E]},2e4)},[]);a.useEffect(()=>{for(const E of i)Ae(E.status)!=="stopped"&&X(E.type)},[i,X]),a.useEffect(()=>()=>{Object.values(ne.current).forEach(clearTimeout),ne.current={}},[]);const[I,G]=a.useState({}),[Y,ae]=a.useState(null);a.useEffect(()=>{if(!L||!n||!u)return;(async()=>{try{const Q=await u(n,"get_ide_extensions",{}),re=(Q==null?void 0:Q.result)||Q;re!=null&&re.success&&(re!=null&&re.ideExtensions)&&G(re.ideExtensions)}catch{}})()},[L,n,u]);const me=E=>L?ke(E.type):t==="cli"?E.cliName:E.acpName,ue=L?s.detectedIdes||[]:[],xe=()=>{(async()=>{if(L){await m(C,O?{workspace:O}:void 0)&&V(C);return}const E=await w(C,O,T||void 0,P&&q||void 0);E.success&&(V(C),E.sessionId&&j(E.sessionId))})()},J=E=>{L?p(E):b(E.type,E.workspace,E.id)},se=a.useCallback(async(E,Q,re=!1)=>{if(E.mode===Q){re&&E.sessionId&&j(E.sessionId);return}if(!u||!E.sessionId){re&&E.sessionId&&j(E.sessionId);return}try{await u(n,"set_cli_view_mode",{targetSessionId:E.sessionId,cliType:E.type,mode:Q}),re&&j(E.sessionId)}catch(oe){console.error("Failed to switch CLI view mode:",oe)}},[n,j,u]),Z=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:_,onChange:E=>{W(E.target.value),E.target.value!=="__custom__"&&ie("")},className:"machine-input min-w-[200px] flex-1",children:(s.workspaces||[]).length>0?e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspace — launch in home)"}),(s.workspaces||[]).map(E=>e.jsxs("option",{value:E.id,children:[E.id===s.defaultWorkspaceId?"⭐ ":"",jn(E.path,E.label)]},E.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…"})]})}),_==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:U,onChange:E=>ie(E.target.value),className:"machine-input flex-1 min-w-[200px]",autoFocus:!0})]}),e.jsx("div",{className:"mt-1.5 text-[10px] text-text-muted",children:_==="__custom__"?O?e.jsx("span",{className:"font-mono truncate block",title:O,children:O}):"Enter an absolute path to launch there.":O?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:_===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:O,children:O})]}):"No workspace selected. This launches in the home directory."})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${k.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",k.label]}),Z,L?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ue.map(E=>{const Q=i.find(Ne=>(Ne.type||"").toLowerCase()===(E.type||"").toLowerCase()&&Ae(Ne.status)!=="stopped"),re=E.running||!!Q,oe=!!Q&&Q.cdpConnected,ge=H.includes(E.type||E.id||"");return e.jsxs("button",{onClick:()=>{if(oe&&Q){const Ne=Q.sessionId;Ne?h(`/dashboard?activeTab=${encodeURIComponent(Ne)}`,{state:{openRemoteForTabKey:Ne}}):h("/dashboard",{state:{openRemoteForTabKey:Q.id}});return}ge||(async()=>await m(E.type||E.id||"",O?{workspace:O}:void 0)&&V(E.type||E.id||""))()},disabled:!!N||ge,className:`machine-btn-primary flex items-center gap-1.5 ${re?"!border-green-500/30":""}`,style:{opacity:N&&N!==E.type?.4:1},children:[e.jsx("span",{children:o(E.type)}),re&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 shadow-[0_0_4px_rgba(34,197,94,0.4)]"}),ge?`⏳ Waiting for ${E.name||ke(E.type)}...`:oe?`Open ${E.name||ke(E.type)}`:N===E.type?"⏳ Launching...":`▶ ${E.name||ke(E.type)}`,re&&oe&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"running"})]},E.type)}),ue.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:v,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(Zr,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:C,onChange:E=>D(E.target.value),className:"machine-input",children:B.length>0?B.map(E=>e.jsxs("option",{value:E.type,children:[E.icon," ",E.displayName]},E.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),P&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:q,onChange:E=>A(E.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:T,onChange:E=>R(E.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:xe,disabled:!!M,className:"machine-btn-primary",children:M===C?"⏳ Launching...":"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length+H.filter(E=>!i.some(Q=>Q.type===E&&Ae(Q.status)!=="stopped")).length,")"]}),i.length===0&&le.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 ",k.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[le.map(E=>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(E)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:L?ke(E):K.get(E)||E}),e.jsx("div",{className:"text-[11px] text-text-muted",children:M===E?"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:${E}`)),i.map(E=>{const Q=L?E:null,re=P?E:null,oe=!L&&!P?E:null,ge=Ae(E.status),Ne=(l==null?void 0:l(E.id))??!1;return e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:o(E.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[me(E),(Q==null?void 0:Q.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",Q.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:E.workspace||"—"}),(re==null?void 0:re.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",re.currentModel]}),(re==null?void 0:re.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",re.currentPlan]}),(oe==null?void 0:oe.mode)&&e.jsx("span",{className:oe.mode==="chat"?"text-violet-400":"text-text-secondary",children:oe.mode==="chat"?"Chat view":"Terminal view"})]}),oe&&(oe.runtimeKey||oe.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[oe.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 ",oe.runtimeKey]}),e.jsx("button",{type:"button",className:"machine-btn text-[9px] px-1.5 py-px",onClick:()=>{var de;(de=navigator.clipboard)==null||de.writeText(`adhdev attach ${oe.runtimeKey}`),S(oe.runtimeKey||null),window.setTimeout(()=>{S(Te=>Te===oe.runtimeKey?null:Te)},1200)},children:g===oe.runtimeKey?"Copied":"Copy"})]}),oe.runtimeWriteOwner&&e.jsx("span",{style:{color:oe.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:oe.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:ec(oe.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[x&&e.jsx("button",{onClick:()=>x(E.id),className:`machine-btn ${Ne?"text-zinc-300 border-zinc-500/30":"text-violet-400 border-violet-500/30"}`,title:Ne?"Show on Dashboard":"Hide from Dashboard",children:Ne?e.jsx(fs,{size:14}):e.jsx(Qr,{size:14})}),e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${ge==="stopped"?"bg-red-500/[0.08] text-red-500":ge==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:ge}),L&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{const de=E.sessionId;if(de){h(`/dashboard?activeTab=${encodeURIComponent(de)}`,{state:{openRemoteForTabKey:de}});return}h("/dashboard",{state:{openRemoteForTabKey:E.id}})},className:"machine-btn flex items-center gap-1",title:"Open remote control",children:e.jsx(Pe,{size:13})}),e.jsx("button",{onClick:()=>y(E),className:"machine-btn",style:{color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"},title:"Restart",children:e.jsx(ps,{size:14})})]}),P&&e.jsx("button",{onClick:()=>{const de=E.sessionId;de&&j(de)},className:"machine-btn",title:"View chat",disabled:!E.sessionId,children:e.jsx(Ge,{size:14})}),oe&&ge!=="stopped"&&e.jsxs(e.Fragment,{children:[oe.mode&&e.jsx(vs,{mode:oe.mode,onChange:de=>void se(oe,de,!1),compact:!0}),e.jsx("button",{onClick:()=>{const de=E.sessionId;de&&j(de)},className:"machine-btn flex items-center gap-1",title:"Open current view in dashboard",disabled:!E.sessionId,children:oe.mode==="chat"?e.jsx(Ge,{size:14}):e.jsx(Pe,{size:13})})]}),ge==="stopped"?e.jsx("button",{onClick:()=>{(async()=>{if(L){await m(E.type,E.workspace?{workspace:E.workspace}:void 0)&&V(E.type);return}const de=await w(E.type,E.workspace);de.success&&(V(E.type),de.sessionId&&j(de.sessionId))})()},disabled:H.includes(E.type),className:"machine-btn text-green-500 border-green-500/30",title:"Restart",children:H.includes(E.type)?"⏳":e.jsx(sa,{size:14})}):e.jsx("button",{onClick:()=>J(E),className:"machine-btn text-red-500 border-red-500/30",title:"Stop",children:e.jsx(xn,{size:14})})]})]}),Q&&Q.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:Q.aiAgents.map(de=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${vn(de.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[de.name," · ",Ae(de.status)]},de.id))}),Q&&(I[Q.type]||[]).length>0&&u&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(I[Q.type]||[]).map(de=>e.jsxs("button",{disabled:Y===`${Q.type}.${de.type}`,onClick:async()=>{const Te=`${Q.type}.${de.type}`;ae(Te);try{await u(n,"set_ide_extension",{ideType:Q.type,extensionType:de.type,enabled:!de.enabled}),G($=>({...$,[Q.type]:($[Q.type]||[]).map(z=>z.type===de.type?{...z,enabled:!z.enabled}:z)}))}catch($){console.error("Extension toggle failed:",$)}finally{ae(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 ${de.enabled?"bg-violet-500/[0.08] border-violet-500/20 text-violet-400":"bg-bg-glass border-border-subtle text-text-muted"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${de.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),de.name,e.jsx("span",{className:"text-[9px] font-normal",children:de.enabled?"ON":"OFF"})]},de.type))})]})]},E.id)})]})]})}const Zs=[{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 sc({machine:t,machineId:s,providers:n,ideSessions:r,cliSessions:i,acpSessions:o,actions:c,getIcon:u,initialCategory:l="ide",initialWorkspaceId:x,initialWorkspacePath:d,isDashboardHidden:f,onToggleDashboardVisibility:h,sendDaemonCommand:m}){var p;const[w,b]=a.useState(l);a.useEffect(()=>{b(l)},[l]);const y=a.useMemo(()=>({ide:r.length,cli:i.length,acp:o.length}),[r.length,i.length,o.length]);return e.jsxs("div",{className:"machine-workspace-tab",children:[e.jsxs("div",{className:"machine-workspace-tab-header",children:[e.jsx("div",{className:"machine-workspace-tab-title",children:"Workspace launcher"}),e.jsx("div",{className:"machine-workspace-tab-subtitle",children:"Choose a workspace context first, then pick how you want to open it."})]}),e.jsx("div",{className:"machine-workspace-section-tabs",children:Zs.map(v=>e.jsxs("button",{type:"button",className:`machine-workspace-section-tab${w===v.id?" active":""}`,onClick:()=>b(v.id),children:[e.jsx("span",{children:v.label}),e.jsx("span",{className:"machine-workspace-section-count",children:y[v.id]})]},v.id))}),e.jsx("div",{className:"machine-workspace-section-helper",children:(p=Zs.find(v=>v.id===w))==null?void 0:p.helper}),w==="ide"&&e.jsx(ns,{category:"ide",machine:t,machineId:s,providers:n,managedEntries:r,getIcon:u,actions:c,isDashboardHidden:f,onToggleDashboardVisibility:h,sendDaemonCommand:m,initialWorkspaceId:x,initialWorkspacePath:d}),w==="cli"&&e.jsx(ns,{category:"cli",machine:t,machineId:s,providers:n,managedEntries:i,getIcon:u,actions:c,isDashboardHidden:f,onToggleDashboardVisibility:h,initialWorkspaceId:x,initialWorkspacePath:d}),w==="acp"&&e.jsx(ns,{category:"acp",machine:t,machineId:s,providers:n,managedEntries:o,getIcon:u,actions:c,isDashboardHidden:f,onToggleDashboardVisibility:h,initialWorkspaceId:x,initialWorkspacePath:d})]})}function nc({onNicknameSynced:t}={}){var U,ie,H,F,le,ne,O,X,V;const{id:s}=Pr(),n=tt(),r=us(),{sendCommand:i}=Fe(),o=ys(),c=o.ides||[],u=o.initialLoaded??!0,{isHidden:l,toggleTab:x}=Fn(),d=c.find(I=>I.id===s&&I.daemonMode),[f,h]=a.useState("workspace"),[m,w]=a.useState("ide"),b=a.useRef(null),y=Ho({machineId:s,registeredMachineId:(d==null?void 0:d.machineId)||null,sendDaemonCommand:i,onNicknameSynced:t,logsEndRef:b});a.useEffect(()=>ze.onToast(G=>{o.setToasts(ae=>{if(ae.some(xe=>xe.message===G.message&&G.timestamp-xe.timestamp<3e3))return ae;const ue={id:G.id,message:G.message,type:G.type,timestamp:G.timestamp,targetKey:G.targetKey,actions:G.actions};return[...ae.slice(-4),ue]});const Y=G.duration||5e3;setTimeout(()=>o.setToasts(ae=>ae.filter(me=>me.id!==G.id)),Y)}),[o]);const p=(d==null?void 0:d.availableProviders)||[],v={};for(const I of p)v[I.type]=I.icon;const N=I=>v[I]||"",M=d?{id:d.id,hostname:wn(d,{fallbackId:d.id}),platform:((U=d.machine)==null?void 0:U.platform)||"unknown",arch:((ie=d.machine)==null?void 0:ie.arch)||"",cpus:((H=d.machine)==null?void 0:H.cpus)||0,totalMem:((F=d.machine)==null?void 0:F.totalMem)||0,freeMem:((le=d.machine)==null?void 0:le.freeMem)||0,availableMem:(ne=d.machine)==null?void 0:ne.availableMem,loadavg:((O=d.machine)==null?void 0:O.loadavg)||[],uptime:((X=d.machine)==null?void 0:X.uptime)||0,release:((V=d.machine)==null?void 0:V.release)||"",cdpConnected:!!d.cdpConnected,machineNickname:d.machineNickname||null,p2p:d.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:d.detectedIdes||[],workspaces:d.workspaces||[],defaultWorkspaceId:d.defaultWorkspaceId??d.activeWorkspaceId??null,defaultWorkspacePath:d.defaultWorkspacePath??d.activeWorkspacePath??null}:null,g=c.filter(I=>I.daemonId===s&&!I.daemonMode).filter(I=>!Lt(I)&&!it(I)).map(I=>({id:I.id,sessionId:I.sessionId,type:I.type,version:I.version||"",instanceId:I.instanceId||"",status:I.status,workspace:I.workspace||null,terminals:I.terminals||0,aiAgents:Ea(I.aiAgents||I.agents||[]),activeChat:I.activeChat||null,chats:I.chats||[],childSessions:I.childSessions||[],cdpConnected:I.cdpConnected||!1,daemonId:s})),S=c.filter(I=>I.daemonId===s&&Lt(I)).map(I=>({id:I.id,sessionId:I.sessionId,type:I.type,cliName:I.cliName||I.type,status:I.status,workspace:I.workspace||"",activeChat:I.activeChat||null,mode:I.mode,daemonId:s})),j=c.filter(I=>I.daemonId===s&&it(I)).map(I=>({id:I.id,sessionId:I.sessionId,type:I.type,acpName:I.cliName||I.type,status:I.status,workspace:I.workspace||"",activeChat:I.activeChat||null,currentModel:I.currentModel,currentPlan:I.currentPlan,daemonId:s}));if(!M)return u?e.jsxs("div",{className:"p-10 text-center text-text-muted",children:[e.jsx("h2",{className:"text-text-primary",children:"Machine not found"}),e.jsx("p",{className:"mt-3",children:"The machine may be offline or not yet connected."}),e.jsx("button",{onClick:()=>n("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const k=We(d,{fallbackId:M.id}),L="workspace",P=r.state,B=P==null?void 0:P.initialMachineTab,K=P==null?void 0:P.initialWorkspaceCategory,C=P==null?void 0:P.initialWorkspaceId,D=P==null?void 0:P.initialWorkspacePath,T=B==="ides"||B==="clis"||B==="acps"?"workspace":B||L,R=B==="ides"?"ide":B==="clis"?"cli":B==="acps"?"acp":K,q=[...g.map(I=>{var G,Y,ae,me,ue;return{id:`ide:${I.type}:${I.workspace||""}`,label:((G=I.activeChat)==null?void 0:G.title)||I.type,kind:"ide",providerType:I.type,subtitle:I.workspace||void 0,workspace:I.workspace||void 0,timestamp:((ue=(me=(ae=(Y=I.activeChat)==null?void 0:Y.messages)==null?void 0:ae.at)==null?void 0:me.call(ae,-1))==null?void 0:ue.timestamp)||0}}),...S.map(I=>{var G,Y,ae,me,ue;return{id:`cli:${I.type}:${I.workspace||""}`,label:((G=I.activeChat)==null?void 0:G.title)||I.cliName,kind:"cli",providerType:I.type,subtitle:I.workspace||void 0,workspace:I.workspace||void 0,timestamp:((ue=(me=(ae=(Y=I.activeChat)==null?void 0:Y.messages)==null?void 0:ae.at)==null?void 0:me.call(ae,-1))==null?void 0:ue.timestamp)||0}}),...j.map(I=>{var G,Y,ae,me,ue;return{id:`acp:${I.type}:${I.workspace||""}`,label:((G=I.activeChat)==null?void 0:G.title)||I.acpName,kind:"acp",providerType:I.type,subtitle:I.currentModel||I.workspace||void 0,workspace:I.workspace||void 0,currentModel:I.currentModel,timestamp:((ue=(me=(ae=(Y=I.activeChat)==null?void 0:Y.messages)==null?void 0:ae.at)==null?void 0:me.call(ae,-1))==null?void 0:ue.timestamp)||0}})].sort((I,G)=>G.timestamp-I.timestamp).map(({timestamp:I,...G})=>G),A=(d.recentLaunches||[]).length>0?d.recentLaunches.map(I=>({id:I.id,label:I.title||I.providerName||I.providerType,kind:I.kind,providerType:I.providerType,subtitle:I.currentModel||I.workspace||void 0,workspace:I.workspace,currentModel:I.currentModel})):q,_=async I=>{if(I.kind==="ide"&&I.providerType){await y.handleLaunchIde(I.providerType,I.workspace?{workspace:I.workspace}:void 0);return}if((I.kind==="cli"||I.kind==="acp")&&I.providerType){await y.runLaunchCliCore({cliType:I.providerType,dir:I.workspace||"",model:I.kind==="acp"?I.currentModel:void 0});return}w(I.kind),h("workspace")};a.useEffect(()=>{h(T)},[L,T,M.id]),a.useEffect(()=>{R&&w(R)},[R,M.id]);const W=[{id:"workspace",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pe,{size:14})," Workspace"]}),count:g.length+S.length+j.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Wt,{size:14})," Providers"]})},{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ea,{size:14})," System"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Jr,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"dashboard-header machine-detail-header !flex-col !items-stretch",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"machine-detail-header-row flex items-center gap-2 md:gap-3.5 w-full min-w-0",children:[e.jsx("button",{onClick:()=>n("/machines"),className:"machine-btn-back flex shrink-0",children:"←"}),e.jsxs("div",{className:"machine-detail-title-wrap min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[y.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:y.nicknameInput,onChange:I=>y.setNicknameInput(I.target.value),onKeyDown:I=>{I.key==="Enter"&&y.handleSaveNickname(),I.key==="Escape"&&y.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:y.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>y.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{y.setEditingNickname(!0),y.setNicknameInput(M.machineNickname||"")},title:"Click to set nickname",children:k}),e.jsx("span",{className:"status-dot-md online shrink-0"})]}),e.jsxs("div",{className:"header-subtitle machine-detail-subtitle mt-1 flex-wrap gap-1 md:gap-2 items-center display-none-mobile",children:[e.jsxs("span",{children:[M.platform," · ",M.arch]}),e.jsxs("span",{children:[M.cpus," cores"]}),(d==null?void 0:d.version)&&e.jsxs("span",{children:["v",d.version]}),M.p2p.available&&e.jsxs("span",{children:["P2P ",M.p2p.state==="connected"?"connected":M.p2p.state]}),M.cdpConnected&&e.jsx("span",{children:"CDP ready"}),M.machineNickname&&e.jsx("span",{className:"text-text-muted opacity-80 shrink-0",children:M.hostname})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:W.map(I=>e.jsxs("button",{onClick:()=>h(I.id),className:`machine-tab shrink-0${f===I.id?" active":""}`,children:[I.label,I.count!==void 0&&e.jsx("span",{className:"tab-count",children:I.count})]},I.id))})]}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:"machine-page-shell",children:e.jsxs("div",{className:"machine-tab-panel",children:[f==="workspace"&&e.jsxs("div",{className:"machine-workspace-panel",children:[e.jsx(Qo,{machineEntry:d,providers:p,recentLaunches:A,onUpgradeDaemon:async()=>{try{await i(s,"daemon_upgrade",{})}catch{}},onOpenLogs:()=>h("logs"),onOpenRecent:_,onOpenWorkspace:I=>{w(I),h("workspace")},onGoTab:h}),e.jsx(sc,{machine:M,machineId:s,providers:p,ideSessions:g,cliSessions:S,acpSessions:j,actions:y,getIcon:N,initialCategory:m,initialWorkspaceId:C,initialWorkspacePath:D,isDashboardHidden:l,onToggleDashboardVisibility:x,sendDaemonCommand:i})]}),f==="providers"&&e.jsx(Go,{machineId:s,providers:p,sendDaemonCommand:i}),f==="overview"&&e.jsx(Vo,{machine:M,ideSessions:g,cliSessions:S,acpSessions:j,actions:y,isDashboardHidden:l,onToggleDashboardVisibility:x}),f==="logs"&&e.jsx(Jo,{machineId:s,sendDaemonCommand:i})]})})}),y.launchPick&&M&&e.jsx(Zo,{machine:M,launchPick:y.launchPick,actions:y}),e.jsx(Tn,{toasts:o.toasts||[],onDismiss:I=>o.setToasts(G=>G.filter(Y=>Y.id!==I)),onClickToast:I=>{I.targetKey}}),e.jsx("style",{children:`
|
|
66
|
-
@keyframes toast-in {
|
|
67
|
-
from { opacity: 0; transform: translateX(40px); }
|
|
68
|
-
to { opacity: 1; transform: translateX(0); }
|
|
69
|
-
}
|
|
70
|
-
`})]})}function rc(){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 u=[],l=[],x=[],d=[];Object.values(c.providers||{}).forEach(h=>{const m={name:h.name||"Unknown",status:h.status||"Stable",details:h.details||"Community Provider"};h.category==="ide"?u.push(m):h.category==="cli"?l.push(m):h.category==="extension"?x.push(m):h.category==="acp"&&d.push(m)});const f=(h,m)=>{const w={Stable:1,Beta:2,WIP:3},b=w[h.status]||99,y=w[m.status]||99;return b!==y?b-y:h.name.localeCompare(m.name)};s({ide:u.sort(f),cli:l.sort(f),ext:x.sort(f),acp:d.sort(f)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>r(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(mn,{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(xs,{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(pn,{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((u,l)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:u.name}),e.jsx("td",{className:"py-3 px-4",children:i(u.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:u.details})]},l))})]})});return n?e.jsx(Pt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Rt,{}),widthClassName:"max-w-5xl",children:e.jsx(js,{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(Pt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Rt,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(Ie,{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(Ie,{title:"IDE support",icon:e.jsx(Pe,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(Ie,{title:"Standalone CLI agents",icon:e.jsx(bs,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(Ie,{title:"AI extensions",icon:e.jsx(Qe,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(Ie,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(Qe,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class ac{constructor(){je(this,"adapters",new Map);je(this,"states",new Map);je(this,"ptyCallbacks",new Set);je(this,"runtimeListeners",new Map);je(this,"screenshotCallbacks",new Map);je(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))}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,n,r){r!=null&&r.scrollback?this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:0,text:typeof n=="string"?n:"",truncated:!1}):typeof n=="string"&&n&&this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,data:n}),this.ptyCallbacks.forEach(i=>i(s,n,r))}emitRuntimeSnapshot(s,n,r=0,i=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:r,text:n,truncated:i})}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})}emitRuntimeEvent(s,n){var r;(r=this.runtimeListeners.get(s))==null||r.forEach(i=>i(n))}}const Be=new ac;function ic(){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 Qs=ic(),en=3e3,oc=3e4;let Ke=null,cc=0;const Kt=new Map;let qe=null,ht=null;function tn(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function lc(t){return t==="connected"?"connected":t}async function At(t,s,n){const r=si(t,n||{}),i=Ke;if(i&&i.readyState===WebSocket.OPEN){const o=`req_${++cc}_${Date.now()}`;return new Promise((c,u)=>{const l=setTimeout(()=>{Kt.delete(o),u(new Error(`WS command timeout: ${s}`))},3e4);Kt.set(o,{resolve:x=>{clearTimeout(l),c(x)},reject:x=>{clearTimeout(l),u(x)}}),i.send(JSON.stringify({type:"command",requestId:o,data:{type:s,payload:r.payload}}))})}throw new Error(`WS command channel unavailable: ${s}`)}class dc{constructor(s){je(this,"daemonId");je(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Ke==null?void 0:Ke.readyState)===WebSocket.OPEN}get connectionState(){return(Ke==null?void 0:Ke.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return At(this.daemonId,s,n)}async sendInput(s,n){return At(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,qe&&(clearInterval(qe),qe=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await At(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());Be.emitScreenshot(this.daemonId,i)}}catch{}};n(),qe=setInterval(n,2e3)}stopScreenshots(s){qe&&(clearInterval(qe),qe=null)}}let Ee=null;function uc(t){return(!Ee||Ee.daemonId!==t)&&(Ee=new dc(t)),Ee}function hc({children:t}){const s=a.useRef(Ms()),n=Ms();s.current=n;const{setUserName:r}=mt(),i=a.useRef(r);i.current=r;const[,o]=a.useState("disconnected"),c=a.useCallback((h,m)=>{o(h),ht==null||ht(h,m)},[]),u=a.useRef(null),l=a.useRef(),x=a.useRef(en),d=a.useRef(!0),f=a.useRef(!1);return a.useEffect(()=>{d.current=!0,f.current=!1;function h(){var b,y;if(!d.current||((b=u.current)==null?void 0:b.readyState)===WebSocket.OPEN||((y=u.current)==null?void 0:y.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${Qs}...`);let w;try{w=new WebSocket(Qs)}catch(p){console.error("[Standalone WS] Failed to create WebSocket:",p),m();return}u.current=w,w.onopen=()=>{if(!d.current){w.close();return}c("connected"),x.current=en,console.log("[Standalone WS] Connected")},Ke=w,w.onmessage=p=>{var v;try{const N=JSON.parse(p.data);if((N.type==="command_result"||N.type==="error")&&N.requestId){const M=Kt.get(N.requestId);M&&(Kt.delete(N.requestId),N.type==="error"?M.reject(new Error(((v=N.data)==null?void 0:v.message)||"Command failed")):M.resolve(N.data));return}if(N.type==="pty_output"){const M=N.sessionId||N.cliId||N.cliType;M&&Be.emitPtyOutput(M,N.data);return}if(N.type==="runtime_snapshot"){Be.emitRuntimeSnapshot(N.sessionId,typeof N.text=="string"?N.text:"",typeof N.seq=="number"?N.seq:0,!!N.truncated);return}if(N.type==="status"||N.type==="initial_state"){const M=N.data;if(!M)return;const{injectEntries:g,markLoaded:S}=s.current,j=M.id||"standalone",k=uc(j);Be.register(j,k),Be.setState(j,"connected"),c("connected",j),Be.emitStatus(j,M);const L=ei(M,{daemonId:j});tn("ws_status",{type:N.type,daemonId:j,sessions:(M.sessions||[]).map(P=>({id:P.id,parentId:P.parentId,providerType:P.providerType,kind:P.kind,transport:P.transport,unread:P.unread,inboxBucket:P.inboxBucket,lastSeenAt:P.lastSeenAt,lastUpdated:P.lastUpdated,title:P.title})),recentLaunches:(M.recentLaunches||[]).map(P=>({id:P.id,providerType:P.providerType,kind:P.kind,workspace:P.workspace,lastLaunchedAt:P.lastLaunchedAt}))}),tn("entries",{daemonId:j,entries:L.filter(P=>P.type!=="adhdev-daemon").map(P=>({id:P.id,type:P.type,unread:P.unread,inboxBucket:P.inboxBucket,lastSeenAt:P.lastSeenAt,lastUpdated:P.lastUpdated,sessionId:P.sessionId}))}),L.length>0&&g(L,{authoritativeDaemonIds:[j]}),S(),M.userName&&i.current&&i.current(M.userName)}}catch(N){console.error("[Standalone WS] Parse error:",N)}},w.onclose=()=>{d.current&&(Ee==null||Ee.stopScreenshots(),Ee&&Be.setState(Ee.daemonId,"disconnected"),c("disconnected"),u.current=null,m())},w.onerror=p=>{f.current||!d.current||console.warn("[Standalone WS] Error, will reconnect:",p)}}function m(){if(!d.current)return;clearTimeout(l.current);const w=x.current;console.log(`[Standalone WS] Reconnecting in ${w}ms...`),l.current=setTimeout(()=>{x.current=Math.min(x.current*1.5,oc),h()},w)}return h(),()=>{d.current=!1,f.current=!0,clearTimeout(l.current),u.current&&(u.current.onerror=null,u.current.onclose=null,u.current.close(),u.current=null,Ke=null),Ee&&(Ee.stopScreenshots(),Be.unregister(Ee.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function mc({children:t}){const[s,n]=a.useState("disconnected"),[r,i]=a.useState(null);a.useEffect(()=>(ht=(c,u)=>{n(c),u&&i(u)},()=>{ht=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",u=lc(s),l={};return r&&(l[r]=u),l.standalone=u,{wsStatus:s,isConnected:c,connectionStates:l}},[s,r]);return e.jsx(zr,{connectionOverrides:o,children:e.jsx(hc,{children:t})})}const pc=[{id:"dashboard",path:"/dashboard",icon:e.jsx(dn,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(hs,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Wt,{}),label:"Settings"}];function xc({children:t}){const s=tt(),n=us(),[r,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),u=d=>{s(d),i(!1)},l=()=>{c(d=>{const f=!d;try{localStorage.setItem("sidebar-collapsed",f?"1":"0")}catch{}return f})},x=d=>`nav-item${n.pathname.startsWith(d)?" 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:d=>d.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:pc.map(d=>e.jsxs("div",{className:x(d.path),id:`nav-${d.id}`,onClick:()=>u(d.path),title:o?d.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:d.icon}),!o&&d.label]},d.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${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(Rt,{})}),!o&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${n.pathname==="/about"?" active":""} ${o?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:o?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(hn,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.7.45"]}),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 fc=[{icon:e.jsx(hs,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(Ge,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(fs,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Pe,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(Qe,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Rt,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],bc=[{icon:e.jsx(fn,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(dn,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(Ot,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Gr,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Yr,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(mn,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],gc=[{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 yc(){return e.jsxs(Pt,{icon:e.jsx(hn,{className:"text-text-primary"}),title:"About",subtitle:"Self-hosted ADHDev overview, supported surfaces, and what changes in Cloud",widthClassName:"max-w-5xl",actions:e.jsxs("div",{className:"px-3 py-1 text-[11px] font-semibold tracking-wide rounded-full bg-emerald-500/10 text-emerald-500 border border-emerald-500/20",children:["SELFHOST v","0.7.45"]}),children:[e.jsx(Ie,{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(Ie,{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:fc.map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4 transition-colors hover:border-border-default",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-accent/10 text-accent-light",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(Ie,{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:_n.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:Pn.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:En.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(Ie,{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:bc.map(t=>e.jsxs("div",{className:"rounded-xl border border-violet-500/20 bg-violet-500/[0.04] px-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-violet-500/10 text-violet-400",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(Ie,{title:"Self-hosted vs Cloud",description:"The product split at a glance.",children:e.jsx("div",{className:"overflow-x-auto rounded-xl border border-border-subtle",children:e.jsxs("table",{className:"w-full text-[13px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary",children:[e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[110px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-violet-400 text-[11px] uppercase tracking-wider w-[110px]",children:"Cloud"})]})}),e.jsx("tbody",{children:gc.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(js,{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}=mt(),s=t.find(f=>f.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=Fe(),{userName:i}=mt(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const u=f=>{const h=f.target.value.trim();s!=null&&s.id&&h!==i&&r(s.id,"set_user_name",{userName:h}).catch(console.error)},[l,x]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),d=f=>{x(f);try{localStorage.setItem("adhdev_sound",f?"1":"0")}catch{}};return e.jsxs(Pt,{icon:e.jsx(Wt,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(bi,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(Ie,{title:"Daemon",description:"Connection health and local endpoints for the self-hosted runtime.",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-x-4 gap-y-2.5 text-sm",children:[e.jsx("span",{className:"text-text-muted",children:"Version"}),e.jsxs("span",{className:"font-mono text-xs",children:["v","0.7.45"]}),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(Ie,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:n.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:n.map(f=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${f.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:f.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:f.type})]},f.type))})}),e.jsx(Ie,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Ni,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(Ie,{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(Mi,{})]}),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(Ei,{})]}),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(Di,{})]})]})}),e.jsx(Ie,{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(ki,{}),e.jsx(Ue,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ca,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:d})]})}),e.jsx(Ie,{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(Xr,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:o,onChange:f=>c(f.target.value),onBlur:u,onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()}})]})})})]})}wi();Li();const jc=cn({baseUrl:""});function sn(){const{ides:t,initialLoaded:s}=mt();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(rs,{to:`/machines/${n.id}`,replace:!0}):e.jsx(rs,{to:"/dashboard",replace:!0})}function wc(){return e.jsx(Dr,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Hr,{client:jc,children:e.jsx(mc,{children:e.jsx(qr,{value:{sendCommand:At,sendData:()=>!1},children:e.jsx(xc,{children:e.jsxs($r,{children:[e.jsx(Oe,{path:"/dashboard",element:e.jsx(Fo,{})}),e.jsx(Oe,{path:"/machine",element:e.jsx(sn,{})}),e.jsx(Oe,{path:"/machines/:id",element:e.jsx(nc,{})}),e.jsx(Oe,{path:"/machines",element:e.jsx(sn,{})}),e.jsx(Oe,{path:"/capabilities",element:e.jsx(rc,{})}),e.jsx(Oe,{path:"/about",element:e.jsx(yc,{})}),e.jsx(Oe,{path:"/settings",element:e.jsx(vc,{})}),e.jsx(Oe,{path:"*",element:e.jsx(rs,{to:"/dashboard",replace:!0})})]})})})})})})}Ua({connectionManager:Be});Br(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(wc,{})}));
|