@adhdev/daemon-standalone 0.7.38 → 0.7.40
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 +799 -1000
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/index-B_p34HFn.css +1 -0
- package/public/assets/index-CX6n6DJi.js +68 -0
- package/public/assets/{terminal-CpeGxRuR.js → terminal-CEvJri7V.js} +1 -1
- package/public/assets/{vendor-BZmoHkrb.js → vendor-CPghmr9Y.js} +5 -5
- package/public/index.html +4 -4
- package/public/assets/index-BKq04Gnp.css +0 -1
- package/public/assets/index-DEIAOSoT.js +0 -69
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-CpeGxRuR.js","assets/vendor-BZmoHkrb.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
var er=Object.defineProperty;var tr=(t,s,n)=>s in t?er(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var fe=(t,s,n)=>tr(t,typeof s!="symbol"?s+"":s,n);import{r as a,j as e,M as Ks,a as Ws,b as sr,c as nr,t as rr,d as ar,e as ir,u as ot,R as or,D as cr,f as lr,g as dr,h as es,i as ur,k as Os,B as hr,l as mr,m as _e,N as qe,n as pr}from"./vendor-BZmoHkrb.js";import{_ as xr}from"./terminal-CpeGxRuR.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 zs=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}),Fs=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function ds(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 Ot(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 fr(t,s){var c,h,l,f,d,x,b;const n=Date.now();if(s.length===0)return t.map(m=>({...m,_lastUpdate:n}));const r=new Map;for(const m of s)r.set(m.id,m);for(const m of t){const u=r.get(m.id);if(!u){r.set(m.id,{...m,_lastUpdate:n});continue}const y=ds(m),j=ds(u);if(y>j){const g=(c=m.chats)!=null&&c.length?m.chats:u.chats,p=Ot(u,m,{...u,...m,chats:g,_lastUpdate:n});r.set(m.id,p)}else if(y<j){const g={};if(m.status&&m.status!==u.status&&(g.status=m.status),m.cdpConnected!==void 0&&(g.cdpConnected=m.cdpConnected),(h=m.chats)!=null&&h.length&&!((l=u.chats)!=null&&l.length)&&(g.chats=m.chats),m.machineNickname!==void 0&&m.machineNickname!==u.machineNickname&&(g.machineNickname=m.machineNickname),m.version!==void 0&&(g.version=m.version),m.serverVersion!==void 0&&(g.serverVersion=m.serverVersion),m.versionMismatch===!0&&(g.versionMismatch=!0),Object.keys(g).length>0){const p=Ot(u,m,{...u,...g,_lastUpdate:u._lastUpdate});r.set(m.id,p)}}else{const g=m.timestamp||n,p=u._lastUpdate||u.timestamp||0;if(g>=p){const I=(f=m.chats)!=null&&f.length?m.chats:u.chats,P=Ot(u,m,{...u,...m,chats:I,_lastUpdate:n});r.set(m.id,P)}else(d=m.chats)!=null&&d.length&&!((x=u.chats)!=null&&x.length)&&r.set(m.id,{...u,chats:m.chats})}}const i=new Set(t.map(m=>m.id)),o=new Set;for(const m of t){const u=m.daemonId||((b=m.id)==null?void 0:b.split(":")[0]);u&&o.add(u)}for(const[m,u]of r){const y=u.daemonId||m.split(":")[0];if(!o.has(y))continue;const j=n-(u._lastUpdate||u.timestamp||0);(u.transport==="pty"&&!i.has(m)&&j>1e4||u.transport==="acp"&&!i.has(m)&&j>1e4||u.transport==="cdp-page"&&!i.has(m)&&j>3e4)&&r.delete(m)}for(const[m,u]of r)n-(u._lastUpdate||u.timestamp||0)>3e5&&u.status!=="online"&&r.delete(m);return Array.from(r.values())}function br(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 gr({children:t,connectionOverrides:s}){const[n,r]=a.useState([]),[i,o]=a.useState({}),[c,h]=a.useState(!1),[l,f]=a.useState([]),[d,x]=a.useState(void 0),b=a.useRef(n);a.useEffect(()=>{b.current=n},[n]);const m=a.useCallback((I,P)=>{r(S=>{let C=!1;const v=S.map(N=>N.id!==I||N.chats===P?N:(C=!0,{...N,chats:P}));return C?v:S})},[]),u=a.useCallback(I=>{r(P=>{const S=P.length===0?I:fr(I,P);return br(P,S)?P:S})},[]),y=a.useCallback(()=>h(!0),[]),j=a.useMemo(()=>({injectEntries:u,markLoaded:y,getIdes:()=>b.current}),[u,y]),g=s,p=a.useMemo(()=>({ides:n,updateIdeChats:m,screenshotMap:i,setScreenshotMap:o,initialLoaded:c,toasts:l,setToasts:f,wsStatus:(g==null?void 0:g.wsStatus)??"connected",isConnected:(g==null?void 0:g.isConnected)??!0,connectionStates:(g==null?void 0:g.connectionStates)??{},connectionTransports:(g==null?void 0:g.connectionTransports)??{},showReconnected:(g==null?void 0:g.showReconnected)??!1,retryConnection:g==null?void 0:g.retryConnection,isP2PActive:(g==null?void 0:g.isP2PActive)??!1,p2pStates:(g==null?void 0:g.p2pStates)??{},userRole:g==null?void 0:g.userRole,userName:d,setUserName:x}),[n,m,i,c,l,g==null?void 0:g.wsStatus,g==null?void 0:g.isConnected,g==null?void 0:g.connectionStates,g==null?void 0:g.connectionTransports,g==null?void 0:g.showReconnected,g==null?void 0:g.retryConnection,g==null?void 0:g.isP2PActive,g==null?void 0:g.p2pStates,g==null?void 0:g.userRole,d]);return e.jsx(Fs.Provider,{value:j,children:e.jsx(zs.Provider,{value:p,children:t})})}function at(){return a.useContext(zs)}function us(){return a.useContext(Fs)}function Us(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;function i(h){return h.startsWith("http")?h:`${s}${h.startsWith("/")?"":"/"}${h}`}function o(h){const l=n==null?void 0:n(),f=i(h),d=h.startsWith("http")?new URL(f):new URL(f,typeof window<"u"?window.location.origin:"http://localhost");return l&&d.searchParams.set("token",l),!h.startsWith("http")&&!s?`${d.pathname}${d.search}${d.hash}`:d.toString()}async function c(h,l={}){const f={"Content-Type":"application/json",...l.headers||{}},d=n==null?void 0:n();d&&(f.Authorization=`Bearer ${d}`);const x=i(h),b=await fetch(x,{...l,headers:f});if(b.status===401)throw r==null||r(),new Error("Unauthorized");if(!b.ok){const m=await b.json().catch(()=>({error:b.statusText}));throw new Error(m.error||`API Error: ${b.status}`)}return b.json()}return{getDaemons:()=>c("/api/v1/daemons"),getDaemonStatus:h=>c(`/api/v1/daemons/${h}/status`),sendCommand:(h,l,f={})=>c(`/api/v1/daemons/${h}/command`,{method:"POST",body:JSON.stringify({type:l,payload:f})}),execTerminal:(h,l,f)=>c(`/api/v1/daemons/${h}/terminal`,{method:"POST",body:JSON.stringify({command:l,name:f})}),sendAgentMessage:(h,l,f)=>c(`/api/v1/shortcuts/${h}/chat`,{method:"POST",body:JSON.stringify({agentType:l,message:f})}),getAgentStatus:h=>c(`/api/v1/shortcuts/${h}/status`),approveAgent:(h,l,f)=>c(`/api/v1/shortcuts/${h}/approve`,{method:"POST",body:JSON.stringify({agentType:l,action:f?"approve":"reject"})}),getMuxState:h=>c(`/api/v1/mux/${encodeURIComponent(h)}/state`),getMuxSocketInfo:h=>c(`/api/v1/mux/${encodeURIComponent(h)}/socket-info`),controlMux:(h,l,f={})=>c(`/api/v1/mux/${encodeURIComponent(h)}/control`,{method:"POST",body:JSON.stringify({type:l,payload:f})}),getMuxEventsUrl:h=>o(`/api/v1/mux/${encodeURIComponent(h)}/events`),getRuntimeEventsUrl:h=>o(`/api/v1/runtime/${encodeURIComponent(h)}/events`),request:c}}const yr=Us({baseUrl:"http://localhost:3847"}),vr=a.createContext(yr);function jr({client:t,children:s}){return e.jsx(vr.Provider,{value:t,children:s})}const wr={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Hs=a.createContext(wr);function kr({value:t,children:s}){return e.jsx(Hs.Provider,{value:t,children:s})}function De(){return a.useContext(Hs)}const me={size:18};function Vs({size:t=me.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 qs({size:t=me.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 Ys({size:t=me.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 Nr({size:t=me.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 Sr({size:t=me.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 Cr({size:t=me.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 Ct({size:t=me.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 Ir({size:t=me.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 Et({size:t=me.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 Xs({size:t=me.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 Gs({size:t=me.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 ct({size:t=me.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 Ae({size:t=me.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 ts({size:t=me.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 Mr({size:t=me.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 qt({size:t=me.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 Js({size:t=me.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 ss({size:t=me.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 it({size:t=me.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 Zs({size:t=me.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 Qs({size:t=me.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 Tr({size:t=me.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 en({size:t=me.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 tn({size:t=me.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 Ar({size:t=me.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 Rr({size:t=me.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 _r({size:t=me.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 Lt({size:t=me.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 Er({size:t=me.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 Lr({size:t=me.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 Pr({size:t=me.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 $r({size:t=me.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 Dr(t){const n=t.split(`
|
|
3
|
-
`).map(h=>{if(!h.includes("\r"))return h;const l=h.split("\r").map(x=>x.trim()).filter(Boolean);if(l.length===0)return"";const f=l.filter(x=>x.startsWith("⏺"));if(f.length>0)return f[f.length-1];const d=l.filter(x=>!(/^[❯›>]\s*$/.test(x)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(x)&&x.length<40||/^[╭╰│├╮╯─═]+$/.test(x)));return d.length>0?d[d.length-1]:l[l.length-1]}).join(`
|
|
4
|
-
`).split(`
|
|
5
|
-
`),r={},i=[];let o=!1;for(const h of n){const l=h.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(h)){const d=h.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(d)r[d[1]]=(r[d[1]]||0)+1;else{const x=h.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);x&&(r[x]=(r[x]||0)+1)}o=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(h)||/^[╭╰│├╮╯─]+/.test(l)||/^\s+[⊙✓✗○◎▸►✦]/.test(h)||o&&/^\s{2,}/.test(h))continue;o=!1;const f=h.replace(/^❯\s+/,"");i.push(f)}const c=i.join(`
|
|
6
|
-
`).replace(/\n{3,}/g,`
|
|
7
|
-
|
|
8
|
-
`).trim();return{toolCounts:r,textContent:c,hasTools:Object.keys(r).length>0}}function Yt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function Br(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function Ve(t,s){const n=t,r=typeof n.content=="string"?n.content:Array.isArray(n.content)?n.content.map(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 hs=700,Kr=a.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(Ks,{remarkPlugins:[Ws],children:s.text}),e.jsx("span",{className:"action-time",children:Yt(s.timestamp)})]})},(t,s)=>t.log===s.log),Wr=a.memo(function({message:s,receivedAt:n,agentName:r,userName:i,isCliMode:o,isExpanded:c,isTextExpanded:h,onToggleExpanded:l,onToggleTextExpanded:f}){var P;const d=(s.role||"").toLowerCase(),x=d==="user"||d==="human",b=s.kind||(d==="tool"?"tool":"standard"),m=typeof s.content=="string"?s.content:(s.content||[]).map(S=>S.text||"").join(`
|
|
10
|
-
`);if(b==="thought"){const S=((P=s.meta)==null?void 0:P.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(Rr,{size:13}),e.jsx("span",{children:S})]}),e.jsx("div",{className:"chat-msg-body",children:m})]})}if(b==="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(b==="terminal"){const S=s.meta||{},C=S.isRunning?"⏳":"✅",v=S.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:C}),e.jsx("span",{children:v})]}),e.jsx("pre",{className:"chat-msg-body",children:m})]})}if(b==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:m.slice(0,100)});const u=!x&&o?Dr(m):null,y=u?u.textContent:m,j=u?Object.entries(u.toolCounts):[],g=o&&!x&&!c&&y.length>hs,p=c?m:g&&!h?y.slice(0,hs):y,I=Br(p);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${x?"self-end":"self-start"}`,children:[j.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[j.map(([S,C])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",S,C>1?` ×${C}`:""]},S)),(u==null?void 0:u.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:c?"Collapse":"Original"}),!y&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Yt(n)})]}),(y||x)&&e.jsxs("div",{className:`chat-bubble ${x?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${y?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:x?i||"You":r}),n!=null&&e.jsx("span",{className:"chat-time",children:Yt(n)})]}),y&&e.jsx("div",{className:"chat-markdown",children:I?e.jsx(Ks,{remarkPlugins:[Ws,sr,nr],children:p}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:p})}),g&&e.jsx("button",{onClick:f,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:h?"Collapse ↑":`Show more (${Math.round(y.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),Or=a.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:h="",receivedAtMap:l={},emptyState:f,onLoadMore:d,isLoadingMore:x,hasMoreHistory:b,hiddenLiveCount:m=0,loadError:u},y){var te;const j=a.useRef(null),g=a.useRef(null),p=a.useRef(null),I=a.useRef(0),P=a.useRef(""),S=a.useRef(!1),C=a.useRef(null),v=a.useRef(!1),N=a.useRef(null),E=a.useRef(!1),[B,K]=a.useState(new Set),[M,w]=a.useState(new Set),A=a.useRef(!1),R=()=>{const O=j.current;return O?O.scrollHeight-O.scrollTop-O.clientHeight<200:!0},L=a.useCallback((O="auto")=>{const D=j.current;D&&D.scrollTo({top:D.scrollHeight,behavior:O})},[]),Y=a.useCallback(()=>{var F;const O=j.current,D=(F=window.getSelection)==null?void 0:F.call(window);if(!O||!D||D.rangeCount===0||D.isCollapsed){E.current=!1;return}const $=D.anchorNode,k=D.focusNode;E.current=!!($&&k&&O.contains($)&&O.contains(k))},[]),V=a.useCallback((O="auto")=>{C.current!=null&&cancelAnimationFrame(C.current),C.current=requestAnimationFrame(()=>{C.current=null,L(O)})},[L]),q=s.length>0?`${s.length}:${(((te=s[s.length-1])==null?void 0:te.content)||"").length}`:"0:0";a.useEffect(()=>{const O=!S.current,D=P.current!==h;if(P.current=h,O||D){S.current=!0,A.current=!1,v.current=!0,E.current||V("auto"),I.current=s.length;return}s.length>I.current?!A.current&&!E.current&&V("auto"):R()&&!A.current&&!E.current&&V("auto"),I.current=s.length},[q,h,c,s.length,V]),a.useEffect(()=>()=>{C.current!=null&&cancelAnimationFrame(C.current),N.current!=null&&window.clearTimeout(N.current)},[]),a.useEffect(()=>{const O=g.current;if(!O)return;const D=()=>{N.current!=null&&window.clearTimeout(N.current),N.current=window.setTimeout(()=>{v.current=!1,N.current=null},180)},$=new ResizeObserver(()=>{v.current&&(E.current||(V("auto"),D()))});return $.observe(O),()=>{$.disconnect(),N.current!=null&&(window.clearTimeout(N.current),N.current=null)}},[V,h]),a.useImperativeHandle(y,()=>({scrollToBottom:(O="smooth")=>{L(O)}}),[L]),a.useEffect(()=>{const O=j.current;if(!O)return;let D;const $=()=>{clearTimeout(D),D=setTimeout(()=>{A.current=!R()},50)};return O.addEventListener("scroll",$,{passive:!0}),()=>{O.removeEventListener("scroll",$),clearTimeout(D)}},[]),a.useEffect(()=>(document.addEventListener("selectionchange",Y),()=>document.removeEventListener("selectionchange",Y)),[Y]);const Q=a.useRef(0),re=a.useRef(!1);a.useEffect(()=>{const O=j.current;if(!O||!re.current||Q.current===0)return;const D=O.scrollHeight-Q.current;D>0&&(O.scrollTop=D),Q.current=0,re.current=!1},[s.length]);const H=()=>{const O=j.current;O&&(Q.current=O.scrollHeight),re.current=!0,d==null||d()},ie=a.useMemo(()=>{const O=s.map((F,z)=>({type:"message",data:F,index:z,ts:F.receivedAt||l[Ve(F,z)]||0}));if(!n||n.length===0)return O;const D=[...n].sort((F,z)=>F.timestamp-z.timestamp).map((F,z)=>({type:"action",data:F,index:z,ts:F.timestamp})),$=[];let k=0;for(const F of O){for(;k<D.length&&F.ts>0&&D[k].ts<F.ts;)$.push(D[k++]);$.push(F)}for(;k<D.length;)$.push(D[k++]);return $},[s,n,l]),G=m>0||!!b,ae=m>0?`↑ Show ${Math.min(m,80)} earlier messages${m>80?` (${m} hidden)`:""}`:u?`↻ ${u}`:"↑ Load older messages";return e.jsx("div",{ref:j,"data-chat-scroll":!0,className:"chat-container",children:e.jsxs("div",{ref:g,className:"chat-container-content",children:[x&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),G&&!x&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:H,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${u&&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:ae})}),ie.length===0&&!G&&(f||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),ie.map(O=>{if(O.type==="action"){const oe=O.data;return e.jsx(Kr,{log:oe},`action-${O.index}`)}const D=O.data,$=O.index,k=Ve(D,$),F=D.receivedAt||l[k],z=`${h}-${k}`,ne=B.has(z),le=M.has(z);return e.jsx(Wr,{message:D,receivedAt:F,agentName:r,userName:i,isCliMode:o,isExpanded:ne,isTextExpanded:le,onToggleExpanded:()=>K(oe=>{const ce=new Set(oe);return ne?ce.delete(z):ce.add(z),ce}),onToggleTextExpanded:()=>w(oe=>{const ce=new Set(oe);return le?ce.delete(z):ce.add(z),ce})},`msg-${k}`)}),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:p})]})})}),zr=a.memo(Or,(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 ms=!1;const sn=a.forwardRef(({onInput:t,onResize:s,fontSize:n=13,readOnly:r=!1},i)=>{const o=a.useRef(null),[c,h]=a.useState(null),l=a.useRef([]),f=a.useRef(!1),d=a.useRef(!1),x=a.useRef(!1),b=()=>{const m=o.current;if(m){f.current&&(m.clear(),f.current=!1);for(const u of l.current)m.write(u);l.current=[],d.current&&(m.fit(),d.current=!1),x.current&&(m.bumpResize(),x.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=[],f.current=!0)},fit:()=>{o.current?o.current.fit():d.current=!0},bumpResize:()=>{o.current?o.current.bumpResize():x.current=!0}}),[]),a.useEffect(()=>{if(!c)return;const m=requestAnimationFrame(()=>{var u;b(),(u=o.current)==null||u.fit()});return()=>cancelAnimationFrame(m)},[c]),a.useEffect(()=>{let m=!1;return xr(()=>import("./terminal-CpeGxRuR.js").then(u=>u.i),__vite__mapDeps([0,1])).then(u=>{ms||(ms=!0,console.info("[CliTerminal] renderer module loaded: ghostty-web")),m||h(()=>u.GhosttyTerminalView)}).catch(u=>{console.error("[CliTerminal] failed to load terminal renderer",u)}),()=>{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"}})});sn.displayName="CliTerminal";function xt({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 ps({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,h=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:h}})})]}):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, ${h}, ${h}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function Fr({cursorPos:t,viewportRef:s,imgRef:n}){var p;if(!t||!n.current)return null;const r=n.current,i=r.getBoundingClientRect(),o=(p=s.current)==null?void 0:p.getBoundingClientRect();if(!o)return null;const c=r.naturalWidth||i.width,h=r.naturalHeight||i.height,l=c/h,f=i.width/i.height;let d,x,b,m;l>f?(d=i.width,x=i.width/l,b=0,m=(i.height-x)/2):(x=i.height,d=i.height*l,b=(i.width-d)/2,m=0);const u=i.left-o.left+b+d*t.nx,y=i.top-o.top+m+x*t.ny,j=Math.max(8,Math.min(o.width-8,u)),g=Math.max(8,Math.min(o.height-8,y));return e.jsxs("div",{style:{position:"absolute",left:j-8,top:g-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 Ur({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:i,setIsMenuOpen:o,imeText:c,setImeText:h,handleImeSubmit:l,isConnActive:f,zoom:d,isMobile:x,mobileFillZoom:b,onZoomOut:m,onZoomReset:u,onZoomIn:y,transportType:j,screenshotUsage:g,lastActionStatus:p}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:I=>I.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(I=>!I),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:I=>I.stopPropagation(),onChange:I=>h(I.target.value),onKeyDown:I=>{l(I)},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(I=>!I),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${i?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⚙️"})})}),e.jsx("div",{className:"w-px h-[18px] bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:f?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:f?"#22c55e":"#eab308",boxShadow:f?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:f?"#22c55e":"#eab308"},children:f?"Connected":"WS"})]}),d>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(d*100),"%"]}),j==="direct"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#22c55e",background:"rgba(34,197,94,0.12)"},title:"Direct P2P connection",children:"Direct"}),j==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 12%, transparent)"},title:"TURN relay in use",children:"Relay"}),g&&g.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:g.budgetExhausted?"#ef4444":"#c4b5fd",background:g.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:g.budgetExhausted?"TURN blocked":`TURN ${g.dailyUsedMinutes}/${g.dailyBudgetMinutes}m`}),p&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:p})]})]}),i&&e.jsxs("div",{onTouchStart:I=>I.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",d<=(x?b:1)+.01?x?"FILL":"FIT":`${Math.round(d*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:I=>{I.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:I=>{I.stopPropagation(),u()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:9,fontWeight:800,cursor:"pointer"},children:x?"FILL":"FIT"}),e.jsx("button",{onClick:I=>{I.stopPropagation(),y()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"+"})]})]})]})]})}function Hr({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 Vr(){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 xs(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 lt(t,s){const n=a.useRef(null),r=a.useRef(0);a.useEffect(()=>{if(!Vr())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,h])=>[c,xs(h)]))}),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,xs(s[c])]))}),n.current=s})}function qr({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:i,minZoom:o,zoomRef:c,panXRef:h,panYRef:l,setPanX:f,setPanY:d,setZoom:x,lastWheelTimeRef:b,onAction:m,setLastActionStatus:u,spawnRippleFromNormalized:y,clampPan:j,isMobile:g,mobileFillZoom:p}){const[I,P]=a.useState(null),S=a.useRef(null),C=a.useRef(null),v=a.useRef(null),N=a.useRef(!1),E=a.useRef(null),B=a.useRef(0),K=a.useRef(null),M=a.useRef(1),w=a.useRef({x:0,y:0}),A=a.useRef(!1),R=a.useRef(r),L=a.useRef(m),Y=()=>{if(S.current)return;const Q={nx:.5,ny:.5};S.current=Q,P(Q)};return a.useEffect(()=>{R.current=r,r==="mouse"&&Y()},[r]),a.useEffect(()=>{L.current=m},[m]),a.useEffect(()=>{const Q=t.current;if(!Q)return;const re=O=>{if(!n.current)return null;const D=n.current.getBoundingClientRect();return!D.width||!D.height?null:{nx:Math.max(0,Math.min(1,(O.clientX-D.left)/D.width)),ny:Math.max(0,Math.min(1,(O.clientY-D.top)/D.height))}},H=(O,D)=>{if(!n.current)return{dnx:0,dny:0};const $=n.current,k=$.getBoundingClientRect(),F=$.naturalWidth||k.width,z=$.naturalHeight||k.height,ne=F/z,le=k.width/k.height;let oe,ce;return ne>le?(oe=k.width,ce=k.width/ne):(ce=k.height,oe=k.height*ne),{dnx:O/oe,dny:D/ce}},ie=(O,D,$)=>{if($<=1.05)return;const k=-(O-.5)*100,F=-(D-.5)*100,z=j(k,F,$);(Math.abs(z.x-h.current)>.1||Math.abs(z.y-l.current)>.1)&&(f(z.x),d(z.y),h.current=z.x,l.current=z.y)},G=O=>{const D=s.current;if(D&&O.target instanceof Node&&D.contains(O.target))O.preventDefault();else return;if(O.touches.length===1){const $=O.touches[0];C.current={x:$.clientX,y:$.clientY,time:Date.now()},v.current={x:$.clientX,y:$.clientY},A.current||(N.current=!1),E.current=setTimeout(()=>{if(!N.current&&!A.current)if(N.current=!0,R.current==="mouse"){const k=S.current||{nx:.5,ny:.5};u("Right Click"),y(k.nx,k.ny,"right"),L.current("input_click",{...k,button:"right"}).catch(()=>{})}else{const k=re($);k&&(u("Right Click"),y(k.nx,k.ny,"right"),L.current("input_click",{...k,button:"right"}).catch(()=>{}))}},500);return}if(O.touches.length===2){E.current&&clearTimeout(E.current),N.current=!0,A.current=!0;const $=O.touches[1].clientX-O.touches[0].clientX,k=O.touches[1].clientY-O.touches[0].clientY;K.current=Math.sqrt($*$+k*k),M.current=c.current,w.current={x:(O.touches[0].clientX+O.touches[1].clientX)/2,y:(O.touches[0].clientY+O.touches[1].clientY)/2}}},ae=O=>{const D=s.current;if(D&&O.target instanceof Node&&D.contains(O.target)&&O.preventDefault(),O.touches.length===1&&v.current){const $=O.touches[0],k=$.clientX-v.current.x,F=$.clientY-v.current.y;if(!N.current&&C.current){const z=$.clientX-C.current.x,ne=$.clientY-C.current.y;Math.sqrt(z*z+ne*ne)>8&&(N.current=!0,E.current&&clearTimeout(E.current))}if(N.current)if(R.current==="mouse"){const z=H(k,F),ne=S.current||{nx:.5,ny:.5},le=Math.max(0,Math.min(1,ne.nx+z.dnx)),oe=Math.max(0,Math.min(1,ne.ny+z.dny));S.current={nx:le,ny:oe},P({nx:le,ny:oe}),u(`Cursor: ${Math.round(le*100)}%, ${Math.round(oe*100)}%`),ie(le,oe,c.current);const ce=Date.now();ce-b.current>=30&&(b.current=ce,L.current("input_mouseMoved",{nx:le,ny:oe}).catch(()=>{}))}else if(c.current>1){const z=s.current;if(z){const ne=z.clientWidth,le=z.clientHeight,oe=h.current+k/ne*100,ce=l.current+F/le*100,J=j(oe,ce,c.current);f(J.x),d(J.y),h.current=J.x,l.current=J.y}}else{const z=re($);if(z){const ne=Date.now();ne-b.current>=40&&(b.current=ne,u("Scroll"),L.current("input_wheel",{nx:z.nx,ny:z.ny,deltaX:Math.round(-k*2.5),deltaY:Math.round(-F*2.5)}).catch(()=>{}))}}v.current={x:$.clientX,y:$.clientY};return}if(O.touches.length===2&&K.current!==null){const $=O.touches[1].clientX-O.touches[0].clientX,k=O.touches[1].clientY-O.touches[0].clientY,z=Math.sqrt($*$+k*k)/K.current,ne=(O.touches[0].clientX+O.touches[1].clientX)/2,le=(O.touches[0].clientY+O.touches[1].clientY)/2,oe=ne-w.current.x,ce=le-w.current.y,J=Math.abs(z-1)>.03;if(R.current==="mouse"){if(J){const se=Math.max(o,Math.min(5,M.current*z));x(se),c.current=se}else if(Math.abs(oe)>2||Math.abs(ce)>2){const se=S.current||{nx:.5,ny:.5},Z=Date.now();Z-b.current>=30&&(b.current=Z,u("Scroll"),L.current("input_wheel",{nx:se.nx,ny:se.ny,deltaX:Math.round(-oe*3),deltaY:Math.round(-ce*3)}).catch(()=>{}))}}else{const se=Math.max(o,Math.min(5,M.current*z));x(se),c.current=se;const Z=s.current;if(Z&&se>1){const _=Z.clientWidth,W=Z.clientHeight,T=h.current+oe/_*100,U=l.current+ce/W*100,X=j(T,U,se);f(X.x),d(X.y),h.current=X.x,l.current=X.y}}w.current={x:ne,y:le}}},te=O=>{var D;if(E.current&&clearTimeout(E.current),K.current=null,O.touches.length===1&&A.current){const $=O.touches[0];C.current={x:$.clientX,y:$.clientY,time:Date.now()},v.current={x:$.clientX,y:$.clientY},N.current=!0;return}if(O.touches.length===0){if(A.current){A.current=!1,N.current=!1;return}if(O.changedTouches.length===1&&!N.current){const $=O.changedTouches[0],k=Date.now(),F=k-(((D=C.current)==null?void 0:D.time)||0);if(F<60||F>400){N.current=!1;return}if(C.current){const z=$.clientX-C.current.x,ne=$.clientY-C.current.y;if(Math.sqrt(z*z+ne*ne)>12){N.current=!1;return}}if(R.current==="mouse"){const z=S.current||re($);z&&(u(`Click: ${Math.round(z.nx*100)}%, ${Math.round(z.ny*100)}%`),y(z.nx,z.ny,"left"),L.current("input_click",{...z}).catch(()=>{}))}else{const z=re($);if(!z)return;k-B.current<300?(u("Double tap"),y(z.nx,z.ny,"double"),L.current("input_click",{...z,clickCount:2}).catch(()=>{}),B.current=0):(u(`Tap: ${Math.round(z.nx*100)}%, ${Math.round(z.ny*100)}%`),y(z.nx,z.ny,"left"),L.current("input_click",{...z}).catch(()=>{}),B.current=k)}}N.current=!1}};return Q.addEventListener("touchstart",G,{passive:!1}),Q.addEventListener("touchmove",ae,{passive:!1}),Q.addEventListener("touchend",te,{passive:!1}),()=>{Q.removeEventListener("touchstart",G),Q.removeEventListener("touchmove",ae),Q.removeEventListener("touchend",te),E.current&&clearTimeout(E.current)}},[t,s,n,o,c,h,l,f,d,x,b,u,y,j]),{cursorPos:I,cursorPosRef:S,handleToggleInputMode:()=>{i(Q=>{const re=Q==="touch"?"mouse":"touch";return re==="mouse"&&Y(),re})},handleZoomReset:()=>{const Q=g?p:1;x(Q),c.current=Q,f(0),d(0),h.current=0,l.current=0}}}function nn({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:i,transportType:o}){const c=a.useRef(null),h=a.useRef(null),l=a.useRef(null),[f,d]=a.useState(null),[x,b]=a.useState(""),[,m]=a.useState(!1),[u,y]=a.useState([]),j=a.useRef(0),[g,p]=a.useState(!1),[I,P]=a.useState(!1),S=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[C,v]=a.useState(S?"mouse":"touch"),[N,E]=a.useState(1),B=a.useRef(!1),[K,M]=a.useState(1),[w,A]=a.useState(0),[R,L]=a.useState(0);lt("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:C,zoom:K,panX:w,panY:R,isMenuOpen:g,isImeOpen:I});const Y=a.useRef(0),V=a.useRef(K),q=a.useRef(w),Q=a.useRef(R);a.useEffect(()=>{V.current=K},[K]),a.useEffect(()=>{q.current=w},[w]),a.useEffect(()=>{Q.current=R},[R]),a.useEffect(()=>{var J;(J=c.current)==null||J.focus()},[]);const re=n==="connected",H=r,ie=re?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",G=re?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!S||B.current||!H)return;const J=l.current,se=h.current;if(!J||!se)return;const Z=()=>{const _=se.clientWidth,W=se.clientHeight,T=J.naturalWidth,U=J.naturalHeight;if(!T||!U||!_||!W)return;const X=Math.min(_/T,W/U),de=Math.max(_/T,W/U)/X;de>1.01&&(E(de),M(de),V.current=de),B.current=!0};J.complete&&J.naturalWidth?Z():J.addEventListener("load",Z,{once:!0})},[H,S]);const ae=.5;a.useEffect(()=>{K<=ae&&(A(0),L(0))},[K,ae]);const te=(J,se,Z)=>{if(Z<=ae)return{x:0,y:0};const _=(Z-1)/(2*Z)*100,W=(Z-1)/(2*Z)*100;return{x:Math.max(-_,Math.min(_,J)),y:Math.max(-W,Math.min(W,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))}},D=(J,se,Z)=>{const _=h.current;if(!_)return;const W=_.getBoundingClientRect(),T=++j.current;y(U=>[...U,{id:T,x:J-W.left,y:se-W.top,type:Z}]),setTimeout(()=>y(U=>U.filter(X=>X.id!==T)),600)},$=(J,se,Z)=>{const _=l.current,W=h.current;if(!_||!W)return;const T=_.getBoundingClientRect(),U=W.getBoundingClientRect(),X=_.naturalWidth||T.width,ee=_.naturalHeight||T.height,de=X/ee,pe=T.width/T.height;let he,ke,ue,Ne;de>pe?(he=T.width,ke=T.width/de,ue=0,Ne=(T.height-ke)/2):(ke=T.height,he=T.height*de,ue=(T.width-he)/2,Ne=0);const ut=T.left-U.left+ue+he*J,ht=T.top-U.top+Ne+ke*se,Ye=++j.current;y(Xe=>[...Xe,{id:Ye,x:ut,y:ht,type:Z}]),setTimeout(()=>y(Xe=>Xe.filter(Bt=>Bt.id!==Ye)),600)},k=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)}%`),D(J.clientX,J.clientY,"left"),(Z=c.current)==null||Z.focus();try{const _=await t("input_click",{nx:se.nx,ny:se.ny});_!=null&&_.success||s(`❌ Click failed: ${_==null?void 0:_.error}`)}catch(_){s(`❌ Click error: ${_.message||_}`)}}},F=async(J,se,Z,_=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:_})}catch(W){s(`❌ Key error: ${W.message||W}`)}},z=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 F(J.key,J.code,J.key.length===1,Z)},ne=async J=>{if(J.key==="Enter"){if(J.nativeEvent.isComposing)return;if(x){const se=x;b(""),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 F("Enter","Enter",!1)}};a.useEffect(()=>{const J=c.current;if(!J)return;const se=Z=>{var _;if((_=l.current)!=null&&_.contains(Z.target)){Z.preventDefault();const W=Date.now();if(W-Y.current<40)return;Y.current=W;const T=O(Z.clientX,Z.clientY);if(!T)return;d(`Scroll: ${Math.round(Z.deltaY)}`),t("input_wheel",{nx:T.nx,ny:T.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:le,handleToggleInputMode:oe,handleZoomReset:ce}=qr({containerRef:c,viewportRef:h,imgRef:l,inputMode:C,setInputMode:v,minZoom:ae,zoomRef:V,panXRef:q,panYRef:Q,setPanX:A,setPanY:L,setZoom:M,lastWheelTimeRef:Y,onAction:t,setLastActionStatus:d,spawnRippleFromNormalized:$,clampPan:te,isMobile:S,mobileFillZoom:N});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:z,onContextMenu:J=>J.preventDefault(),onFocus:()=>m(!0),onBlur:()=>m(!1),tabIndex:0,children:[e.jsxs("div",{ref:h,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[H?e.jsx("img",{ref:l,src:H,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${K}) translate(${w}%, ${R}%)`,transformOrigin:"center center",cursor:C==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:k,onContextMenu:J=>J.preventDefault(),onDragStart:J=>J.preventDefault()}):e.jsx(Hr,{waitingLabel:ie,waitingHint:G,transportType:o}),C==="mouse"&&H&&e.jsx(Fr,{cursorPos:le,viewportRef:h,imgRef:l}),u.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(Ur,{inputMode:C,onToggleInputMode:oe,isImeOpen:I,setIsImeOpen:P,isMenuOpen:g,setIsMenuOpen:p,imeText:x,setImeText:b,handleImeSubmit:ne,isConnActive:re,zoom:K,isMobile:S,mobileFillZoom:N,onZoomOut:()=>M(J=>Math.max(.5,J-.25)),onZoomReset:ce,onZoomIn:()=>M(J=>Math.min(5,J+.25)),transportType:o,screenshotUsage:i,lastActionStatus:f}),e.jsx("style",{children:`
|
|
12
|
-
@keyframes slideUp {
|
|
13
|
-
from { opacity: 0; transform: translateY(6px); }
|
|
14
|
-
to { opacity: 1; transform: translateY(0); }
|
|
15
|
-
}
|
|
16
|
-
@keyframes slideUpSidebar {
|
|
17
|
-
from { opacity: 0; transform: translateY(6px); }
|
|
18
|
-
to { opacity: 1; transform: translateY(0); }
|
|
19
|
-
}
|
|
20
|
-
@keyframes click-ripple-ring {
|
|
21
|
-
0% { transform: scale(0.3); opacity: 1; }
|
|
22
|
-
100% { transform: scale(2.2); opacity: 0; }
|
|
23
|
-
}
|
|
24
|
-
@keyframes click-ripple-dot {
|
|
25
|
-
0% { transform: scale(1); opacity: 0.9; }
|
|
26
|
-
50% { transform: scale(1.8); opacity: 0.6; }
|
|
27
|
-
100% { transform: scale(0.5); opacity: 0; }
|
|
28
|
-
}
|
|
29
|
-
@keyframes remote-float {
|
|
30
|
-
0% { transform: translateY(0px); }
|
|
31
|
-
50% { transform: translateY(-7px); }
|
|
32
|
-
100% { transform: translateY(0px); }
|
|
33
|
-
}
|
|
34
|
-
`})]})}function Yr({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:r=!1,connectionState:i,onDismiss:o,onClickAt:c,onKeyDown:h,badge:l,emptyMessage:f,aspectRatio:d,className:x,style:b}){const m=a.useRef(null),u=a.useCallback(y=>{if(!r||!c||!m.current)return;const j=m.current,g=j.getBoundingClientRect(),p=(y.clientX-g.left)/g.width*j.naturalWidth,I=(y.clientY-g.top)/g.height*j.naturalHeight;c(p,I,j.naturalWidth,j.naturalHeight)},[r,c]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${x||""}`,style:{aspectRatio:d||"16/9",...b},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":""} ${x||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?h:void 0,style:b,children:[e.jsx("img",{ref:m,src:t,alt:"IDE Screenshot",onClick:r?u:void 0,className:"max-w-full max-h-full object-contain",style:{...r?{cursor:"crosshair"}:{},...n!==100?{transform:`scale(${n/100})`,transformOrigin:"center center"}:{}}}),l&&e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 bg-black/70 text-white px-3.5 py-1.5 rounded-[20px] text-xs font-semibold backdrop-blur-sm",children:l})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${x||""}`,style:b,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:f||"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 rn({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(ss,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((c,h)=>{const l=o(c).toLowerCase(),f=/^(run|approve|accept|yes|allow|always)/.test(l),d=/^(reject|deny|delete|remove|abort)/.test(l),x=n===c,b=n!==null;return e.jsx("button",{onClick:()=>i(c),disabled:b,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${f?"bg-white font-extrabold":d?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${b&&!x?"opacity-40":"opacity-100"} ${b?"cursor-not-allowed":"cursor-pointer"}`,style:f?{color:"var(--status-warning)"}:void 0,children:x?"⏳ ...":o(c)},h)})})]})]})}const fs=new Map,Xr={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"};function Gr({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:i,controls:o,controlValues:c,serverModel:h,serverMode:l}){const{sendCommand:f}=De(),d=`${t}:${s||r}`,x=Xr[r]||"#94a3b8",[b,m]=a.useState({}),u=a.useRef(0),y={...h?{model:h}:{},...l?{mode:l}:{},...c||{},...Date.now()<u.current?b:{}};a.useEffect(()=>{c&&Date.now()>u.current&&m({})},[c]);const[j,g]=a.useState(fs.get(d)||{}),[p,I]=a.useState(null),[P,S]=a.useState(null),C=a.useCallback(async(w,A={})=>{const R={...A,...s&&{targetSessionId:s}};return await f(t,w,R)},[t,s,f]);if(!o||o.length===0)return null;const v=o.filter(w=>w.placement==="bar").sort((w,A)=>(w.order??50)-(A.order??50));if(v.length===0)return null;const N=async w=>{var R,L,Y;if(p===w.id){I(null);return}if((((R=w.options)==null?void 0:R.map(V=>V.value))||j[w.id]||[]).length>0){I(w.id);return}if(w.dynamic&&w.listScript){S(w.id);try{const V=await C(w.listScript==="listModels"?"list_extension_models":w.listScript==="listModes"?"list_extension_modes":w.listScript,{agentType:r,ideType:n}),Q=((V==null?void 0:V.models)||(V==null?void 0:V.modes)||((L=V==null?void 0:V.result)==null?void 0:L.models)||((Y=V==null?void 0:V.result)==null?void 0:Y.modes)||(V==null?void 0:V.options)||[]).map(re=>typeof re=="string"?re:(re==null?void 0:re.name)||(re==null?void 0:re.id)||(re==null?void 0:re.value)||String(re));g(re=>{const H={...re,[w.id]:Q};return fs.set(d,H),H}),I(w.id)}catch{}finally{S(null)}}},E=async(w,A)=>{I(null),m(R=>({...R,[w.id]:A})),u.current=Date.now()+5e3;try{if(!w.setScript)return;const R=zt(w.setScript,r);await C(R,{agentType:r,ideType:n,model:w.id==="model"?A:void 0,mode:w.id==="mode"?A:void 0,value:A})}catch{}},B=async w=>{var q;const A=((q=w.options)==null?void 0:q.map(Q=>Q.value))||j[w.id]||[];if(A.length===0)return;const R=String(y[w.id]||""),Y=(A.indexOf(R)+1)%A.length,V=A[Y];if(typeof V=="string"){m(Q=>({...Q,[w.id]:V})),u.current=Date.now()+5e3;try{if(!w.setScript)return;const Q=zt(w.setScript,r);await C(Q,{agentType:r,ideType:n,value:V})}catch{}}},K=async w=>{const R=!y[w.id];m(L=>({...L,[w.id]:R})),u.current=Date.now()+5e3;try{if(!w.setScript)return;const L=zt(w.setScript,r);await C(L,{agentType:r,ideType:n,value:R})}catch{}},M=async w=>{if(w.invokeScript)try{await C("invoke_extension_script",{agentType:r,ideType:n,scriptName:w.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:x},children:i}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),v.map(w=>{var V;const A=String(y[w.id]||""),R=p===w.id,L=P===w.id,Y=((V=w.options)==null?void 0:V.map(q=>q.value))||j[w.id]||[];switch(w.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:R?`${x}55`:"transparent",border:"1px solid",color:A?"var(--text-primary)":"var(--text-muted)"},onClick:()=>N(w),children:[w.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:w.icon}),L?"...":A||w.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),R&&Y.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>I(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:w.label.toUpperCase()}),Y.map(q=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:q===A?`${x}18`:"transparent",color:q===A?x:"var(--text-secondary)",fontWeight:q===A?600:400,borderLeft:q===A?`2px solid ${x}`:"2px solid transparent"},onMouseEnter:Q=>{Q.currentTarget.style.background=`${x}12`},onMouseLeave:Q=>{Q.currentTarget.style.background=q===A?`${x}18`:"transparent"},onClick:()=>E(w,q),children:q},q))]})]})]},w.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:A?"var(--text-primary)":"var(--text-muted)"},onClick:()=>B(w),title:`Click to cycle: ${Y.join(" → ")}`,children:[w.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:w.icon}),A||w.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"⟳"})]},w.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:A?`${x}44`:"transparent",background:A?`${x}14`:"var(--surface-tertiary)",color:A?x:"var(--text-muted)"},onClick:()=>K(w),children:[w.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:w.icon}),w.label]},w.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:()=>M(w),children:[w.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:w.icon}),w.label]},w.id);default:return null}})]})}function zt(t,s){return{setModel:"set_extension_model",setMode:"set_extension_mode",setThinkingLevel:"set_thought_level"}[t]||t}const Jr=a.memo(function({contextKey:s,panelLabel:n,isSending:r,onSend:i}){const o=a.useRef(null),[c,h]=a.useState("");a.useEffect(()=>{h("")},[s]);const l=()=>{const f=c.trim();!f||r||(h(""),i(f))};return e.jsx("div",{className:"dashboard-input-area px-3 py-2.5 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:o,type:"text",placeholder:`Send message to ${n}...`,value:c,onChange:f=>h(f.target.value),onPaste:f=>{const d=f.clipboardData.getData("text");d&&h(x=>x+d),f.preventDefault()},onKeyDown:f=>{if(f.key==="Enter"){if(f.nativeEvent.isComposing){f.preventDefault();return}f.preventDefault(),l()}},onBlur:f=>{if(window.innerWidth<768){const d=f.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"})})})]})})}),ve=t=>t.transport==="pty",ye=t=>t.transport==="acp";var Zr=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function Qr(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function Se(t,s){if(Qr(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":Zr.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 an(t){return Se(t)==="generating"}function ge(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function ea(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 bs(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Xt(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 ta(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 sa(t){return ta(t.trim().replace(/\.local$/i,""))}function na(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function on(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);if(n&&n!=="Unknown")return sa(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function dt(t,s={}){return na(t)||on(t,s)}function It(t){return t.transport==="pty"}function et(t){return t.transport==="acp"}function gs(t,s){return ge(t)}function ra(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const i=(s||"").trim().toLowerCase(),o=(n||"").trim().toLowerCase(),c=ge(n||"").trim().toLowerCase();return r===i||r===o||r===c}function aa(t){return Se(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function ia(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=Se(r.status);if(!o){s.set(i,{...r,status:c});continue}const h=n.indexOf(o.status||"idle"),l=n.indexOf(c||"idle");l>=0&&(h<0||l<h)&&s.set(i,{...r,status:c})}return Array.from(s.values())}function ys(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 vs(t){const s=[];for(const n of t){const r=ys(n==null?void 0:n.content),i=n==null?void 0:n.role,o=!!(n!=null&&n._localId),c=s.findIndex(h=>(h==null?void 0:h.role)===i&&ys(h==null?void 0:h.content)===r&&!!(h!=null&&h._localId)!==o);if(c>=0){if(o)continue;s.splice(c,1,n);continue}s.push(n)}return s}const oa=60,ca=60;function ns({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:i,isFocusingAgent:o,actionLogs:c,userName:h}){const l=a.useRef(new Map),{sendCommand:f}=De();lt("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:r});const d=a.useRef(new Map),x=a.useCallback(M=>(d.current.has(M)||d.current.set(M,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:oa}),d.current.get(M)),[]),b=a.useCallback((M,w)=>{const A=x(M);d.current.set(M,{...A,...w}),m(R=>R+1)},[x]),[,m]=a.useState(0),u=t.tabKey,y=x(u),j=y.messages,g=y.hasMore,p=y.error,I=Math.max(0,t.messages.length-y.visibleLiveCount),[P,S]=a.useState(!1),C=a.useCallback(async()=>{var A,R;if(P)return;const M=t.tabKey,w=x(M);if(t.messages.length>w.visibleLiveCount){b(M,{visibleLiveCount:Math.min(t.messages.length,w.visibleLiveCount+ca),error:null});return}S(!0),b(M,{error:null});try{const L=(s==null?void 0:s.daemonId)||((A=t.ideId)==null?void 0:A.split(":")[0])||"";if(!L){b(M,{hasMore:!1});return}const Y=t.ideType||t.agentType||"",V=await f(L,"chat_history",{agentType:Y,offset:w.offset,limit:30,targetSessionId:t.sessionId}),q=(V==null?void 0:V.result)??V;if(((R=q.messages)==null?void 0:R.length)>0){const Q=x(M);b(M,{messages:[...q.messages,...Q.messages],offset:Q.offset+q.messages.length,hasMore:!!q.hasMore})}else b(M,{hasMore:!!q.hasMore})}catch(L){const Y=(L==null?void 0:L.message)||"";Y.includes("P2P not available")||Y.includes("channel not open")||Y.includes("P2P not connected")||Y.includes("timeout")?b(M,{error:"Connection not ready — tap to retry"}):b(M,{hasMore:!1,error:"Failed to load history"})}finally{S(!1)}},[P,s,t,f,x,b]),{allMessages:v,receivedAtMap:N}=a.useMemo(()=>{const M=I>0?t.messages.slice(-y.visibleLiveCount):t.messages;if(j.length===0){const Y=vs(M),V={};return Y.forEach((q,Q)=>{const re=`${t.tabKey}:${Ve(q,Q)}`;let H=q.receivedAt||l.current.get(re)||0;H||(H=Date.now(),l.current.set(re,H)),V[Ve(q,Q)]=H}),{allMessages:Y,receivedAtMap:V}}const w=new Set(M.map(Y=>`${Y.role}:${(Y.content||"").slice(0,100)}`)),A=j.filter(Y=>!w.has(`${Y.role}:${(Y.content||"").slice(0,100)}`)),R=vs([...A,...M]),L={};return R.forEach((Y,V)=>{const q=`${t.tabKey}:${Ve(Y,V)}`;let Q=Y.receivedAt||l.current.get(q)||0;Q||(Q=Date.now(),l.current.set(q,Q)),L[Ve(Y,V)]=Q}),{allMessages:R,receivedAtMap:L}},[t.messages,t.tabKey,I,j,y.visibleLiveCount]),E=a.useMemo(()=>c.filter(M=>M.ideId===t.tabKey).sort((M,w)=>M.timestamp-w.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(it,{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(qt,{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(Zs,{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(qt,{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"&&!P)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,P,B]);return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[e.jsx(zr,{messages:v,actionLogs:E,agentName:t.agentName||t.displayPrimary||"Agent",userName:h,isCliMode:ve(t)||ye(t),isWorking:t.status==="generating",contextKey:t.tabKey,receivedAtMap:N,onLoadMore:C,isLoadingMore:P,hasMoreHistory:g,hiddenLiveCount:I,loadError:p??void 0,emptyState:K}),!ve(t)&&(()=>{const M=t.streamSource!=="agent-stream",w=M?t.ideType:t.agentType,A=M?s!=null&&s.type?ge(s.type):ge(t.ideType||""):t.agentName||ge(t.agentType||""),R=!M&&(s!=null&&s.childSessions)&&s.childSessions.find(V=>V.id===t.sessionId||V.providerType===t.agentType)||s,L=R==null?void 0:R.providerControls,Y=R==null?void 0:R.controlValues;return e.jsx(Gr,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:w,displayLabel:A,controls:L,controlValues:Y,serverModel:(R==null?void 0:R.currentModel)||void 0,serverMode:(R==null?void 0:R.currentPlan)||void 0,acpConfigOptions:ye(t)?R==null?void 0:R.acpConfigOptions:void 0,acpModes:ye(t)?R==null?void 0:R.acpModes:void 0})})(),e.jsx(Jr,{contextKey:t.tabKey,panelLabel:B,isSending:r,onSend:n})]})}let cn=at;function rs(){return cn()}class la{constructor(){fe(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 ln=new la;class da{constructor(){fe(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 xe=new da;function ua(t){t.dashboardWS&&(ln=t.dashboardWS),t.connectionManager&&(xe=t.connectionManager),t.useDaemonsHook&&(cn=t.useDaemonsHook)}function dn({activeConv:t,clearToken:s=0,terminalRef:n,handleSendChat:r,isSendingChat:i=!1}){var P;const o=a.useRef(null),{sendCommand:c,sendData:h}=De(),[l,f]=a.useState(""),[d,x]=a.useState(!1),b=a.useRef(0),m=a.useRef(!1),u=t.tabKey,y=t.sessionId||"",j=t.daemonId||((P=t.ideId)==null?void 0:P.split(":")[0])||t.ideId||"",g=()=>{var S;b.current=0,m.current=!1,x(!1),(S=n.current)==null||S.clear()},p=()=>{var S;b.current=0,m.current=!1,x(!0),(S=n.current)==null||S.clear()},I=(S,C=0)=>{var v,N;m.current||b.current>=C&&b.current!==0||(b.current=C,x(!0),(v=n.current)==null||v.clear(),S&&((N=n.current)==null||N.write(S)))};return a.useEffect(()=>{g()},[y]),a.useEffect(()=>{var C,v;if(!y)return;const S=((C=xe.onRuntimeEvent)==null?void 0:C.call(xe,y,N=>{var E;if(!(!N||N.sessionId!==y)){if(N.type==="runtime_snapshot"){I(N.text||"",N.seq||0);return}if(N.type==="session_output"){m.current=!0,typeof N.seq=="number"&&(b.current=Math.max(b.current,N.seq)),x(!0),typeof N.data=="string"&&((E=n.current)==null||E.write(N.data));return}N.type==="session_cleared"&&p()}}))||(()=>{});return(v=xe.requestRuntimeSnapshot)==null||v.call(xe,j,y).catch(()=>{}),()=>{S()}},[j,y,n]),a.useEffect(()=>{var C,v,N;if(!y)return;j&&((C=xe.getState)==null?void 0:C.call(xe,j))==="connected"&&(x(!0),(v=xe.requestRuntimeSnapshot)==null||v.call(xe,j,y).catch(()=>{}));const S=(N=xe.onStateChange)==null?void 0:N.call(xe,(E,B)=>{var K;E!==j||B!=="connected"||(x(!0),(K=xe.requestRuntimeSnapshot)==null||K.call(xe,j,y).catch(()=>{}))});return()=>{S==null||S()}},[j,y,n]),a.useEffect(()=>{s&&g()},[s,u,n]),a.useEffect(()=>{f("")},[t.tabKey]),a.useEffect(()=>{const S=C=>{var N;const v=C.detail;v!=null&&v.sessionId&&v.sessionId!==y||d&&((N=n.current)==null||N.fit())};return window.addEventListener("adhdev:fit-cli-terminal",S),()=>{window.removeEventListener("adhdev:fit-cli-terminal",S)}},[d,y,n]),a.useEffect(()=>{if(!d)return;const S=requestAnimationFrame(()=>{var C;(C=n.current)==null||C.fit()});return()=>cancelAnimationFrame(S)},[d,y,n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx(sn,{ref:n,readOnly:!d,onInput:S=>{d&&(h!=null&&h(j,{type:"pty_input",targetSessionId:y,data:S})||c(j,"pty_input",{targetSessionId:y,data:S}).catch(console.error))},onResize:(S,C)=>{d&&(h!=null&&h(j,{type:"pty_resize",targetSessionId:y,cols:S,rows:C})||c(j,"pty_resize",{targetSessionId:y,cols:S,rows:C,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:S=>f(S.target.value),onPaste:S=>{const C=S.clipboardData.getData("text");C&&f(v=>v+C),S.preventDefault()},onKeyDown:S=>{if(S.key!=="Enter")return;if(S.nativeEvent.isComposing){S.preventDefault();return}S.preventDefault();const C=l.trim();!d||!C||i||(f(""),r(C))},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 S=l.trim();!d||!S||i||(f(""),r(S))},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 ha({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":"violet",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))",violet:"linear-gradient(90deg, rgba(139,92,246,0.12), rgba(139,92,246,0.04))"},c={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",violet:"1px solid rgba(139,92,246,0.2)"},h={red:"#ef4444",orange:"#ff6b35",violet:"#a78bfa"};return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:o[i],borderBottom:c[i],color:h[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 ma({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 pa({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,conversations:i,onOpenHistory:o,onOpenRemote:c,onStopCli:h,onFitCli:l,onOpenConversation:f}){const d=rs(),x=d.p2pStates||{},b=d.ides||[],m=!!t&&ve(t)&&!ye(t),[u,y]=a.useState(!1),j=a.useRef(null),g=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",p=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",I=b.filter(w=>w.type==="adhdev-daemon"),P=Object.values(x),S=P.filter(w=>w==="connected").length,C=P.filter(w=>w==="connecting"||w==="new"||w==="checking").length,N=n!=="connected"||I.length===0?null:C>0&&S===0?"P2P connecting...":S>0&&s===0?"Waiting for IDE...":null,E=a.useMemo(()=>i.filter(w=>w.streamSource!=="native"||w.transport!=="cdp-page"?!0:!i.some(A=>A.ideId===w.ideId&&A.tabKey!==w.tabKey&&A.streamSource==="agent-stream")),[i]),B=a.useMemo(()=>E.filter(w=>w.inboxBucket==="needs_attention"),[E]),K=a.useMemo(()=>E.filter(w=>w.inboxBucket==="task_complete"&&w.unread),[E]),M=B.length+K.length;return a.useEffect(()=>{if(!u)return;const w=A=>{var R;(R=j.current)!=null&&R.contains(A.target)||y(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[u]),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(ct,{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:p}})})]}),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:p}}),N&&e.jsxs("span",{className:"header-subtitle-status",children:["· ",N]})]})]})})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsxs("div",{className:"dashboard-header-inbox",ref:j,children:[e.jsxs("button",{type:"button",onClick:()=>y(w=>!w),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(Lt,{size:16}),M>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:M})]}),u&&e.jsxs("div",{className:"dashboard-header-inbox-popover",children:[B.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Needs attention"}),B.map(w=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item is-attention",onClick:()=>{f==null||f(w),y(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:w.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:w.displaySecondary})]},w.tabKey))]}),K.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),K.map(w=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{f==null||f(w),y(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:w.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:w.displaySecondary})]},w.tabKey))]}),M===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]}),m&&h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:l,className:"btn btn-secondary btn-sm",title:"Fit terminal to current view",children:"Fit"}),e.jsx("button",{onClick:h,className:"btn btn-secondary btn-sm text-red-400 border-red-500/25 hover:bg-red-500/10",title:"Stop CLI process",children:"Stop"})]}),t&&!m&&!ye(t)&&e.jsx("button",{onClick:()=>o(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(ts,{size:16})}),t&&!m&&!ye(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Ae,{size:16})})]})]})}function xa({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,onClose:i,onNewChat:o,onSwitchSession:c,onRefreshHistory:h}){var x;const l=s.find(b=>b.id===t.ideId),f=(l==null?void 0:l.chats)||[],d=(x=l==null?void 0:l.activeChat)==null?void 0:x.id;return e.jsxs("div",{className:"fixed inset-0 z-[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," — ",ge(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"}),f.map(b=>e.jsxs("div",{onClick:()=>{c(t.ideId,b.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${d===b.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===b.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:b.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:[b.id.substring(0,12),"..."]}),d===b.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},b.id)),f.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(_r,{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:h,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(Js,{size:13})," Refresh History"]})})})]})]})}const js={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 un({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:js[r.type]||js.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))})}const fa=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function ba(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function ga(t){return t.sessionId||t.instanceId||t.agentType}function ft(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(`
|
|
42
|
-
`).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 ws(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 hn(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=dt(r,{fallbackId:r.id}))}return s}function mn(t,s,n={}){var b,m,u,y,j,g;const r=[],i=n.machineName,o=n.connectionState,c=ba(t),h=ge(t.type),l=Array.isArray(t.childSessions)?t.childSessions.map(p=>{var I,P;return{sessionId:p.id,instanceId:p.id,agentType:p.providerType,agentName:p.providerName,status:p.status,title:p.title,messages:((I=p.activeChat)==null?void 0:I.messages)||[],activeModal:((P=p.activeChat)==null?void 0:P.activeModal)||void 0,recentKey:p.recentKey,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket}}):[],f=fa(t),d=t.activeChat||{title:""},x=d.title&&String(d.title).trim()?String(d.title).trim():"";if(f){const p=t.sessionId||t.instanceId,I=gs(t.type),P=(b=t.activeChat)==null?void 0:b.activeModal,S=P&&Array.isArray(P.buttons)&&P.buttons.length>0,C=Se((m=t.activeChat)==null?void 0:m.status,{activeModal:(u=t.activeChat)==null?void 0:u.activeModal})||Se((j=(y=t.agents)==null?void 0:y[0])==null?void 0:j.status)||"idle",v=t.activeChat||{title:"",messages:[]};let N=v.title&&String(v.title).trim()?String(v.title).trim():"";const E=(g=t.activeChat)==null?void 0:g.id,B=t.chats;if(E&&Array.isArray(B)&&B.length>0){const R=B.find(L=>L.id===E||L.id&&String(L.id)===String(E));R!=null&&R.title&&String(R.title).trim()&&(N=String(R.title).trim())}const K=v.messages||[],M=ws(s,[t.id,p]),w=new Map;K.filter(R=>R.role==="user").forEach(R=>{const L=ft(R.content);L&&w.set(L,(w.get(L)||0)+1)});const A=M.filter(R=>{const L=ft(R.content),Y=w.get(L)||0;return Y>0?(w.set(L,Y-1),!1):!0});r.push({ideId:t.id,sessionId:p,transport:t.transport,daemonId:t.daemonId||void 0,mode:ve(t)?t.mode||"terminal":"chat",agentName:I,agentType:(ve(t)||ye(t))&&(t.cliType||t.acpType)||t.type,status:C,title:N,messages:[...K,...A],resume:t.resume,ideType:t.cliType||t.acpType||t.type,workspaceName:c,displayPrimary:N||c||(ve(t)||ye(t)?"Terminal":I),displaySecondary:h,cdpConnected:t.cdpConnected,recentKey:t.recentKey,modalButtons:S?P.buttons:void 0,modalMessage:S?P.message:void 0,unread:t.unread,lastSeenAt:t.lastSeenAt,inboxBucket:t.inboxBucket,streamSource:"native",tabKey:t.id,machineName:i,connectionState:o})}if(f&&(ve(t)||ye(t)))return r;for(const p of l){const I=p.activeModal&&Array.isArray(p.activeModal.buttons)&&p.activeModal.buttons.length>0,P=aa(p),S=ga(p),C=`${t.id}:${S}`,v=p.title&&String(p.title).trim()||"",N=ra(v,p.agentName,p.agentType)?"":v,E=p.messages||[],B=ws(s,[C,p.sessionId,p.instanceId]),K=new Map;E.filter(w=>w.role==="user").forEach(w=>{const A=ft(w.content);A&&K.set(A,(K.get(A)||0)+1)});const M=B.filter(w=>{const A=ft(w.content),R=K.get(A)||0;return R>0?(K.set(A,R-1),!1):!0});r.push({ideId:t.id,sessionId:p.sessionId||p.instanceId,transport:p.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:p.agentName,agentType:p.agentType,status:P,title:N,messages:[...E,...M],ideType:p.agentType,workspaceName:c,displayPrimary:N||x||c||h,displaySecondary:`${h}·${p.agentName}`,cdpConnected:t.cdpConnected,recentKey:p.recentKey??p.id,modalButtons:I?p.activeModal.buttons:void 0,modalMessage:I?p.activeModal.message:void 0,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,streamSource:"agent-stream",tabKey:C,machineName:i,connectionState:o})}return r.length===0&&r.push({ideId:t.id,sessionId:t.sessionId||t.instanceId,transport:t.transport,daemonId:t.daemonId||void 0,mode:"chat",agentName:gs(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:c,displayPrimary:c||h,displaySecondary:h,cdpConnected:t.cdpConnected,recentKey:t.recentKey,unread:t.unread,lastSeenAt:t.lastSeenAt,inboxBucket:t.inboxBucket,streamSource:"native",tabKey:t.id,connectionState:o}),r}function ya(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 va(t,s){const n=[],r=t,{daemonId:i,existingDaemon:o,timestamp:c}=s,h=c||t.timestamp||Date.now(),l=t.sessions||[],{topLevel:f,childrenByParent:d}=ya(l),x=f.filter(u=>u.kind==="workspace"&&u.transport==="cdp-page"),b=f.filter(u=>u.kind==="agent"&&u.transport==="pty"),m=f.filter(u=>u.kind==="agent"&&u.transport==="acp");n.push({...o||{},id:i,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:h,...t.version&&{version:t.version},...t.machine&&{machine:t.machine,platform:t.machine.platform},...t.instanceId&&{instanceId:t.instanceId},...t.machineNickname!==void 0&&{machineNickname:t.machineNickname},...t.p2p&&{p2p:t.p2p},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.workspaceActivity&&{workspaceActivity:t.workspaceActivity},..."recentSessions"in t&&t.recentSessions&&{recentSessions:t.recentSessions},...r.terminalBackend&&{terminalBackend:r.terminalBackend},...t.detectedIdes&&{detectedIdes:t.detectedIdes},..."availableProviders"in t&&{availableProviders:t.availableProviders},cdpConnected:x.some(u=>!!u.cdpConnected)});for(const u of x){const y=d.get(u.id)||[];n.push({id:`${i}:ide:${u.id}`,sessionId:u.id,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,status:u.cdpConnected?"online":"detected",daemonId:i,instanceId:u.id,workspace:u.workspace,terminals:0,childSessions:y,agents:y.map(j=>({id:j.id,name:j.providerName,type:j.providerType,status:j.status})),activeChat:u.activeChat,chats:[],cdpConnected:u.cdpConnected,currentModel:u.currentModel,currentPlan:u.currentPlan,currentAutoApprove:u.currentAutoApprove,recentKey:u.recentKey,unread:u.unread,lastSeenAt:u.lastSeenAt,inboxBucket:u.inboxBucket,controlValues:u.controlValues,providerControls:u.providerControls,timestamp:h})}for(const u of b){const y=u.runtime;n.push({id:`${i}:cli:${u.id}`,sessionId:u.id,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,agentType:u.providerType,status:u.status||"running",daemonId:i,instanceId:u.id,cliName:u.providerName,mode:"terminal",workspace:u.workspace||"",activeChat:u.activeChat,resume:u.resume,runtimeKey:u.runtimeKey??(y==null?void 0:y.runtimeKey),runtimeDisplayName:u.runtimeDisplayName??(y==null?void 0:y.displayName),runtimeWorkspaceLabel:u.runtimeWorkspaceLabel??(y==null?void 0:y.workspaceLabel),runtimeWriteOwner:u.runtimeWriteOwner??(y==null?void 0:y.writeOwner)??null,runtimeAttachedClients:u.runtimeAttachedClients??(y==null?void 0:y.attachedClients)??[],recentKey:u.recentKey,unread:u.unread,lastSeenAt:u.lastSeenAt,inboxBucket:u.inboxBucket,controlValues:u.controlValues,providerControls:u.providerControls,timestamp:h,_isCli:!0})}for(const u of m){const y=u.runtime;n.push({id:`${i}:acp:${u.id}`,sessionId:u.id,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,agentType:u.providerType,status:u.status||"running",daemonId:i,instanceId:u.id,cliName:u.providerName,mode:"chat",workspace:u.workspace||"",activeChat:u.activeChat,runtimeKey:u.runtimeKey??(y==null?void 0:y.runtimeKey),runtimeDisplayName:u.runtimeDisplayName??(y==null?void 0:y.displayName),runtimeWorkspaceLabel:u.runtimeWorkspaceLabel??(y==null?void 0:y.workspaceLabel),runtimeWriteOwner:u.runtimeWriteOwner??(y==null?void 0:y.writeOwner)??null,runtimeAttachedClients:u.runtimeAttachedClients??(y==null?void 0:y.attachedClients)??[],currentModel:u.currentModel,currentPlan:u.currentPlan,recentKey:u.recentKey,unread:u.unread,lastSeenAt:u.lastSeenAt,inboxBucket:u.inboxBucket,acpConfigOptions:u.acpConfigOptions,acpModes:u.acpModes,controlValues:u.controlValues,providerControls:u.providerControls,timestamp:h,_isAcp:!0})}return n}function ja(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 wa(t,s){const n=ja(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const pn=[{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:"💚"}],xn=[{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:"🧩"}],fn=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],bn="adhdev_notification_prefs",ks={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function ka(){try{const t=localStorage.getItem(bn);if(t){const s=JSON.parse(t);return{...ks,...s}}}catch{}return{...ks}}function Na(t){try{localStorage.setItem(bn,JSON.stringify(t))}catch{}}let Re=ka(),jt=[];function Sa(){jt.forEach(t=>t())}function Ca(){return{...Re}}function Ia(t){Re={...Re,...t},Na(Re),Sa()}function Ma(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return jt.push(n),()=>{jt=jt.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{Ia(n)},[]);return[{...Re},s]}function tt(t){if(!Re.globalEnabled)return!1;switch(t){case"disconnect":return Re.disconnectAlert;case"completion":return Re.completionAlert;case"approval":return Re.approvalAlert;case"browser":return Re.browserNotifications;default:return!0}}const Ta={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Aa(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function gn(){return"Notification"in window&&Notification.permission==="granted"}let Ke=null;async function Ra(){if(Ke!==null)return Ke;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return Ke=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(Ke=!!await t.pushManager.getSubscription(),Ke):(Ke=!1,!1)}catch{return Ke=!1,!1}}function Gt(t,s,n){if(gn())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 _a(t,s={}){const n={...Ta,...s},r=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{Ra().then(h=>{o.current=h})},[]);const c=a.useCallback((h,l,f)=>{const d=Date.now();d-i.current<n.throttleMs||(i.current=d,Gt(h,l,f))},[n.throttleMs]);a.useEffect(()=>{var h;if(!(!n.enabled||!gn())&&tt("browser")&&o.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,Se(l.status,{activeModal:l.activeModal}));return}for(const l of t){const f=r.current.get(l.id),d=Se(l.status,{activeModal:l.activeModal}),x=l.name||l.id;if(n.onApproval&&tt("approval")&&d==="waiting_approval"&&f!=="waiting_approval"){const b=((h=l.activeModal)==null?void 0:h.message)||"Action requires your approval";c(`🔔 ${x} — Approval needed`,b.slice(0,120),`approval-${l.id}`)}n.onComplete&&tt("completion")&&an(f)&&d==="idle"&&c(`✅ ${x} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&d==="error"&&f!=="error"&&c(`⚠️ ${x} — 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 Ea{constructor(){fe(this,"dedupMap",new Map);fe(this,"DEDUP_WINDOW_MS",5e3);fe(this,"DEDUP_MAX_SIZE",50);fe(this,"DEDUP_CLEANUP_AGE_MS",1e4);fe(this,"toastCallbacks",[]);fe(this,"systemMessageCallbacks",[]);fe(this,"clearSystemMessageCallbacks",[]);fe(this,"resolveActionFn",null);fe(this,"viewRequestRespondFn",null);fe(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,x;if(!s.ideId&&s.instanceId){for(const b of this.ides)if(b.id.endsWith(`:ide:${s.instanceId}`)||b.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=b.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=ge(s.ideType||"");const h=this.resolveOwningDaemon(s);if(h){const b=dt(h,{fallbackId:h.id});b&&(c=s.ideType==="adhdev-daemon"?b:`${b}/${c}`)}let l="",f="info";if(s.event==="agent:generating_completed"){const b=s.duration?` (${s.duration}s)`:"";l=`✅ ${c} agent task completed${b}`,f="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&Ca().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${b}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")r&&this.emitClearSystemMessage(r,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(l=`⚡ ${c} approval needed`,f="warning",r){const b=s.modalMessage||"Approval requested",m=(d=s.modalButtons)!=null&&d.length?s.modalButtons.map(u=>`[${u}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${b}
|
|
43
|
-
${m}`,_localId:`sys_approval_${Date.now()}`})}if((x=s.modalButtons)!=null&&x.length&&this.resolveActionFn){const b=this.resolveActionRouteTarget(s);if(!b)return;const m=s.agentType||s.ideType||"",u=s.ideType||"",y=s.modalButtons,j=S=>S.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),g=this.resolveActionFn,p=y.map((S,C)=>{const v=j(S).toLowerCase(),N=/^(run|approve|accept|yes|allow|always)/.test(v),E=/^(reject|deny|delete|remove|abort|cancel|no)/.test(v);return{label:j(S),variant:N?"primary":E?"danger":"default",onClick:()=>{const B=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(v);g(b,"resolve_action",{action:B?"approve":"reject",button:S,buttonIndex:C,agentType:m,ideType:u,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),I=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,P=Date.now();this.emitToast({id:P,message:I,type:f,timestamp:P,targetKey:r||b,actions:p,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const b=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${c} agent is taking a long time${b}`,f="warning",tt("browser")&&!document.hasFocus()&&Gt(`⚠️ ${c} — Long Running`,`Agent has been generating for over ${b.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const b=s.requesterName||"A team member",m=s.requestId,u=s.orgId;if(l=`👁️ ${b} wants to view your session`,f="warning",m&&u&&this.viewRequestRespondFn){const y=this.viewRequestRespondFn,j=Date.now(),g=[{label:"Approve",variant:"primary",onClick:()=>{y(u,m,"approve").catch(p=>console.error("[EventManager] approve view request failed:",p))}},{label:"Decline",variant:"danger",onClick:()=>{y(u,m,"reject").catch(p=>console.error("[EventManager] reject view request failed:",p))}}];this.emitToast({id:j,message:l,type:f,timestamp:j,actions:g,duration:3e4}),l=""}tt("browser")&&!document.hasFocus()&&Gt("👁️ View Request",`${b} wants to view your session`,`view-request-${m}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",f="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,f="warning");if(l){const b=Date.now();this.emitToast({id:b,message:l,type:f,timestamp:b,targetKey:r||s.ideId,duration:5e3})}}}const Pe=new Ea;function Fe(...t){return rr(ar(t))}function La({icon:t,title:s,subtitle:n,badge:r,actions:i,className:o}){return e.jsxs("div",{className:Fe("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 Mt({icon:t,title:s,subtitle:n,badge:r,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:h}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(La,{icon:t,title:s,subtitle:n,badge:r,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:Fe("mx-auto flex w-full flex-col gap-4",o,c),children:h})})]})}function we({title:t,icon:s,description:n,accentColor:r,className:i,children:o}){return e.jsxs("div",{className:Fe("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",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 as({icon:t,title:s,description:n,action:r,className:i}){return e.jsxs("div",{className:Fe("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 Pa={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"},$a={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function Da({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:Fe("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",Pa[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:$a[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 Ba={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"},Ka={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Wa({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:Fe("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Ba[t],n),children:[e.jsx("span",{className:Fe("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Ka[t])}),r]})}function Oa(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Jt(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function wt(t){return t==="system"?Oa():t}function za(){typeof document>"u"||document.documentElement.setAttribute("data-theme",wt(Jt()))}function yn(){const[t,s]=a.useState(Jt),[n,r]=a.useState(()=>wt(Jt()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),h=l=>{t==="system"&&r(l.matches?"light":"dark")};return c.addEventListener("change",h),()=>c.removeEventListener("change",h)},[t]);const i=a.useCallback(c=>{s(c),r(wt(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const h=c==="dark"?"light":c==="light"?"system":"dark";r(wt(h));try{localStorage.setItem("theme",h)}catch{}return h})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function $e({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 Fa({onPrefChange:t}){const[s,n]=Ma(),r=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx($e,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Lt,{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($e,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ae,{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($e,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Er,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx($e,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Lr,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx($e,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(it,{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($e,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ct,{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 Ua({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(as,{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(Va,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i},c.id))})}function Ns({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 ir.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:h=>h.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 Ha(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...pn,...xn,...fn].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 Va({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){var A,R;const[o,c]=a.useState("idle"),[h,l]=a.useState(""),[f,d]=a.useState(null),[x,b]=a.useState("idle"),[m,u]=a.useState(""),y=t,j=y.version||y.daemonVersion||null,g=((A=y.machine)==null?void 0:A.platform)||((R=y.system)==null?void 0:R.platform)||"",p=dt(y,{fallbackId:t.id}),I=g==="win32"?"🪟":g==="darwin"?"🍎":"🐧",P=s.filter(L=>L.daemonId===t.id&&L.transport==="cdp-page"),S=s.filter(L=>L.daemonId===t.id&&L.transport==="pty"),C=s.filter(L=>L.daemonId===t.id&&L.transport==="acp"),v=y.p2p,N=async()=>{var L,Y,V;if(n){c("upgrading"),l("Installing latest version...");try{const q=await n(t.id,"daemon_upgrade",{});(L=q==null?void 0:q.result)!=null&&L.upgraded||(Y=q==null?void 0:q.result)!=null&&Y.success?(c("done"),l(`Upgraded to v${q.result.version||"latest"}. Daemon is restarting...`)):(c("error"),l(((V=q==null?void 0:q.result)==null?void 0:V.error)||"Upgrade failed"))}catch(q){c("error"),l((q==null?void 0:q.message)||"Connection lost during upgrade")}}},E=async()=>{if(d(null),!!r){b("loading");try{await r(t.id),b("done"),u("Machine disconnected.")}catch(L){b("error"),u((L==null?void 0:L.message)||"Failed to disconnect")}}},B=async()=>{if(d(null),!!i){b("loading");try{await i(t.id),b("done"),u('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(L){b("error"),u((L==null?void 0:L.message)||"Failed to revoke token")}}},K="0.7.38",M=!j||j!==K,w=P.length+S.length+C.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:I}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:p}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),j&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${M?"":"bg-bg-secondary"}`,style:M?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",j,!M&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&M&&e.jsx("button",{onClick:N,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${K}`,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${K}`}`}),r&&e.jsx("button",{onClick:()=>d("disconnect"),disabled:x==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>d("revoke"),disabled:x==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Wa,{status:t.status==="online"?"online":"error"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[v&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${v.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${v.state==="connecting"||v.state==="new"?"animate-pulse":""}`,style:v.state==="connecting"||v.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",v.state==="connected"?"connected":v.state==="connecting"||v.state==="new"?"connecting...":v.state||"off"]}),v.peers!==void 0&&v.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",v.peers," peer",v.peers!==1?"s":"",")"]})]}),v&&w>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),w>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[P.map(L=>{const Y=Ha(L.type),V=L.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:Y.icon}),e.jsx("span",{children:Y.name}),V!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${V?"bg-green-400":"animate-pulse"}`,style:V?void 0:{background:"var(--status-warning)"},title:V?"CDP connected":"CDP connecting..."})]},L.id)}),S.map(L=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"⌨️"}),e.jsx("span",{children:L.cliName||"CLI"})]},L.id)),C.map(L=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:L.cliName||"ACP"})]},L.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(h||m)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||x==="error"?"text-red-400":o==="done"||x==="done"?"text-green-400":"text-text-muted"}`,children:m||h})]}),f==="disconnect"&&e.jsx(Ns,{title:"🔌 Disconnect Machine",message:`Disconnect "${p}" from ADHDev?
|
|
44
|
-
|
|
45
|
-
This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
|
|
46
|
-
|
|
47
|
-
Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:E,onCancel:()=>d(null)}),f==="revoke"&&e.jsx(Ns,{title:"⚠️ Remove Machine",message:`Remove "${p}" from your dashboard?
|
|
48
|
-
|
|
49
|
-
This will:
|
|
50
|
-
• Immediately disconnect the machine
|
|
51
|
-
• Delete the machine registration
|
|
52
|
-
• Require restarting "adhdev-standalone" on that machine
|
|
53
|
-
|
|
54
|
-
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:B,onCancel:()=>d(null)})]})}const qa=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Ya(){const{preference:t,setPreference:s}=yn();return e.jsx("div",{className:"flex gap-2",children:qa.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 Zt={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},Qt={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},Xa=[{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"}}}],vn="adhdev-chat-theme",jn="adhdev-chat-theme-custom";function kt(){return typeof window>"u"?"ember":localStorage.getItem(vn)||"ember"}function Te(t){try{const s=localStorage.getItem(jn);if(s){const n=JSON.parse(s);return{...t==="dark"?Zt:Qt,...n[t]}}}catch{}return t==="dark"?Zt:Qt}function bt(t,s){localStorage.setItem(jn,JSON.stringify({dark:t,light:s}))}function Ie(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 Tt(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 Ga={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function st(t,s){var i;const n=(i=Ga[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",Tt(n,24)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${Tt(n,18)})`),r.style.setProperty("--border-accent",Ie(n,.35)),r.style.setProperty("--nav-active-bg",Ie(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Ie(n,.06)}`)}function Oe(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ie(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ie(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ie(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",Ie(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ie(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",Tt(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${Tt(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ie(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ie(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ie(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 ${Ie(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 is(){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 Ja(t){if(localStorage.setItem(vn,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ze()?"dark":"light";Oe(Te(s))}else is(),st(t,ze()?"dark":"light")}function Za(){const t=kt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ze()?"dark":"light";Oe(Te(s))}else is(),st(t,ze()?"dark":"light")}function ze(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function je({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 Ge({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 Qa({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,i]=a.useState(()=>Te(n));a.useEffect(()=>{i(Te(n))},[n]);const o=a.useCallback((c,h)=>{i(l=>{const f={...l,[c]:h},x=Te(n==="dark"?"light":"dark");return n==="dark"?bt(f,x):bt(x,f),Oe(f),s(f),f})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 18px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{children:[e.jsxs(Ge,{title:"App Background",children:[e.jsx(je,{label:"Background",value:r.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(je,{label:"Surface",value:r.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(je,{label:"Card",value:r.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(Ge,{title:"App Text",children:[e.jsx(je,{label:"Primary",value:r.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(je,{label:"Secondary",value:r.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(je,{label:"Muted",value:r.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(Ge,{title:"Borders & Accent",children:[e.jsx(je,{label:"Border subtle",value:r.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(je,{label:"Border default",value:r.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(je,{label:"Accent",value:r.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(Ge,{title:"Chat Bubbles",children:[e.jsx(je,{label:"User bubble",value:r.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(je,{label:"User text",value:r.userText,onChange:c=>o("userText",c)}),e.jsx(je,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(je,{label:"Agent text",value:r.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(Ge,{title:"Chat Layout",children:[e.jsx(je,{label:"Chat BG",value:r.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(je,{label:"Send button",value:r.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(je,{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?Zt:Qt,l=Te(t?"light":"dark");t?bt(c,l):bt(l,c),i(c),Oe(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(kt),[n,r]=a.useState(!0),[i,o]=a.useState(()=>Te("dark"));a.useEffect(()=>{r(ze());const l=new MutationObserver(()=>{const x=ze();r(x);const b=kt();b==="custom"?Oe(Te(x?"dark":"light")):st(b,x?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const f=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>{const x=ze();r(x);const b=kt();b==="custom"?Oe(Te(x?"dark":"light")):st(b,x?"dark":"light")};return f.addEventListener("change",d),()=>{l.disconnect(),f.removeEventListener("change",d)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Oe(Te(n?"dark":"light")):(is(),st(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{o(Te(n?"dark":"light"))},[n]);const c=l=>{s(l),Ja(l)},h=[...Xa,{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:h.map(l=>{const f=t===l.id,d=n?l.preview.dark:l.preview.light,x=l.id==="honey"||l.id==="ember"?"#1a1a1a":l.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:f?"var(--bg-glass-hover)":"var(--bg-glass)",border:f?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:f?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:d.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.userBubble,color:x},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[f&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(Qa,{dark:n,onColorsChange:l=>o(l)})]})}const wn="adhdev_mobileDashboardMode_v1";function kn(){try{return localStorage.getItem(wn)==="workspace"?"workspace":"chat"}catch{return"chat"}}function ti(t){try{localStorage.setItem(wn,t)}catch{}}function si(){const[t,s]=a.useState(!1);return a.useEffect(()=>{s(kn()==="workspace")},[]),e.jsx($e,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ct,{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),ti(n?"workspace":"chat")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Workspace":"Chat mode"})})}const Nn="adhdev_hiddenTabs";function ni(){try{const t=localStorage.getItem(Nn);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function Je(t){try{localStorage.setItem(Nn,JSON.stringify([...t]))}catch{}}function Sn(){const[t,s]=a.useState(ni),n=a.useCallback(l=>{s(f=>{const d=new Set(f);return d.has(l)?d.delete(l):d.add(l),Je(d),d})},[]),r=a.useCallback(l=>{s(f=>{if(f.has(l))return f;const d=new Set(f);return d.add(l),Je(d),d})},[]),i=a.useCallback(l=>{s(f=>{if(!f.has(l))return f;const d=new Set(f);return d.delete(l),Je(d),d})},[]),o=a.useCallback((l,f)=>{s(d=>{const x=new Set(d);for(const b of f)x.add(b);return Je(x),x})},[]),c=a.useCallback((l,f)=>{s(d=>{const x=new Set(d);for(const b of f)x.delete(b);return Je(x),x})},[]),h=a.useCallback(l=>t.has(l),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:i,hideAllForDaemon:o,showAllForDaemon:c,isHidden:h}}function ri({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){a.useEffect(()=>{Aa()},[]);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 _a(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{n(h=>{const l=Date.now(),f={};for(const[d,x]of Object.entries(h))l-x<5e3&&(f[d]=x);return Object.keys(f).length===Object.keys(h).length?h:f})},5500);return()=>clearTimeout(c)},[s,n]),a.useEffect(()=>{const o=setInterval(()=>{const c=Date.now()-3e5;r(h=>{const l=h.filter(f=>f.timestamp>c).slice(-100);return l.length===h.length?h:l})},6e4);return()=>clearInterval(o)},[r]),null}function ai(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 gt(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 ii(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 oi(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 ci(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 li({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:i}){const o=a.useRef([]),c=a.useRef([]),h=a.useRef([]),l=a.useRef([]),f=a.useMemo(()=>{const p=ai(t);return gt(o.current,p)?o.current:(o.current=p,p)},[t]),d=a.useMemo(()=>hn(t),[t]),x=a.useRef(new Map),b=a.useMemo(()=>{var P;const p=new Map,I=[];for(const S of f){const C=S.daemonId||((P=S.id)==null?void 0:P.split(":")[0])||S.id,v=s[C]||"new",N=S.daemonId&&d[S.daemonId]||void 0,E=oi(S,n),B=x.current.get(S.id);if(B&&B.ide===S&&B.connectionState===v&&B.machineName===N&&ci(B.localRefs,E)){p.set(S.id,B),I.push(...B.conversations);continue}const K=mn(S,n,{machineName:N,connectionState:v}),M={ide:S,connectionState:v,machineName:N,localRefs:E,conversations:K};p.set(S.id,M),I.push(...K)}return x.current=p,I},[f,n,s,d]),m=a.useMemo(()=>{const p=ii(b,r);return gt(c.current,p)?c.current:(c.current=p,p)},[b,r]),u=a.useMemo(()=>{const p=new Map;for(const I of m)I.sessionId&&p.set(I.sessionId,I),p.set(I.ideId,I),p.set(I.tabKey,I),p.set(I.ideType,I),p.set(I.agentType,I);return p},[m]),y=a.useCallback(p=>{if(p)return u.get(p)},[u]),j=a.useMemo(()=>{const p=m.filter(I=>!i.has(I.tabKey));return gt(h.current,p)?h.current:(h.current=p,p)},[m,i]),g=a.useMemo(()=>{const p=j.map(I=>I.tabKey);return gt(l.current,p)?l.current:(l.current=p,p)},[j]);return{chatIdes:f,conversations:m,visibleConversations:j,visibleTabKeys:g,resolveConversationByTarget:y}}function di({isMobile:t,urlActiveTab:s,resolveConversationByTarget:n,setSearchParams:r}){const i=a.useMemo(()=>{var h;return t||!s?null:((h=n(s))==null?void 0:h.tabKey)??null},[t,n,s]),o=a.useMemo(()=>{var h;return!t||!s?null:((h=n(s))==null?void 0:h.tabKey)??null},[t,n,s]),c=a.useCallback(()=>{s&&r(h=>{const l=new URLSearchParams(h);return l.delete("activeTab"),l},{replace:!0})},[r,s]);return{requestedDesktopTabKey:i,requestedMobileTabKey:o,consumeRequestedActiveTab:c}}function ui({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:i}){a.useEffect(()=>{Pe.setIdes(t)},[t]),a.useEffect(()=>{Pe.setResolveAction((o,c,h)=>{s(o,c,h).catch(()=>{})})},[s]),a.useEffect(()=>{const o=Pe.onToast(l=>{n(d=>d.some(b=>b.message===l.message&&l.timestamp-b.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 f=l.duration||5e3;setTimeout(()=>n(d=>d.filter(x=>x.id!==l.id)),f)}),c=Pe.onSystemMessage((l,f)=>{r(d=>({...d,[l]:[...d[l]||[],f]}))}),h=Pe.onClearSystemMessage((l,f)=>{r(d=>{var x;return(x=d[l])!=null&&x.length?{...d,[l]:d[l].filter(b=>{var m;return!(b.role==="system"&&((m=b._localId)!=null&&m.startsWith(f)))})}:d})});return()=>{o(),c(),h()}},[n,r]),a.useEffect(()=>{const o=ln.on("status_event",c=>Pe.handleRawEvent(c,"ws"));return()=>{o()}},[]),a.useEffect(()=>{var c;const o=h=>{const l=h.data;if((l==null?void 0:l.type)!=="notification_action"||l.action!=="approve"||!(l.ideId||l.targetSessionId||l.targetKey))return;const f=l.targetSessionId||l.targetKey||l.ideId,d=i(f),x=(d==null?void 0:d.ideId)||l.ideId;x&&s(x,"resolve_action",{action:"approve",button:"Approve",...(d==null?void 0:d.sessionId)&&{targetSessionId:d.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(b=>console.error("[SW Action] approve failed:",b))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",o),()=>{var h;return(h=navigator.serviceWorker)==null?void 0:h.removeEventListener("message",o)}},[i,s])}const hi="adhdev_dashboardLayout_v1",mi="adhdev_dashboardDockview_v1",Ze={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function Cn(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function In(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function Mn(t){return`${hi}:${t}`}function pi(t){const s=Mn(t);return Cn(s,null)}function xi(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=Mn(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Tn(t){return`${mi}:${t}`}function fi(t){const s=Tn(t);return Cn(s,null)}function bi(t,s){try{const n=Tn(t);if(!s){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function gi(){return{groupAssignments:[...Ze.groupAssignments],focusedGroup:Ze.focusedGroup,groupActiveTabIds:{...Ze.groupActiveTabIds},groupTabOrders:{...Ze.groupTabOrders},groupSizes:[...Ze.groupSizes]}}function yi(){const[t]=a.useState(()=>In(typeof window<"u"?window.innerWidth:1280)),[s,n]=a.useState(()=>new Map),[r,i]=a.useState(0),[o,c]=a.useState({}),[h,l]=a.useState({}),[f,d]=a.useState([]),[x,b]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[m,u]=a.useState(!1),y=a.useCallback(()=>{if(m)return;const j=pi(t)??gi();n(new Map(j.groupAssignments)),i(j.focusedGroup),c(j.groupActiveTabIds),l(j.groupTabOrders),d(j.groupSizes),u(!0)},[m,t]);return a.useEffect(()=>{m&&xi(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:o,groupTabOrders:h,groupSizes:f})},[m,t,s,r,o,h,f]),a.useEffect(()=>{const j=window.matchMedia("(max-width: 767px)"),g=p=>b(p.matches);return j.addEventListener("change",g),()=>j.removeEventListener("change",g)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:h,setGroupTabOrders:l,groupSizes:f,setGroupSizes:d,isMobile:x,hasHydratedStoredLayout:m,hydrateStoredLayout:y}}function vi({urlActiveTab:t,conversations:s,resolveConversationByTarget:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:h,setSearchParams:l,historyModalOpen:f,activeConv:d,isRefreshingHistory:x,ides:b,handleRefreshHistory:m}){const u=a.useRef(!1),y=a.useRef(!1),j=a.useRef(null),g=a.useRef(!1);a.useEffect(()=>{if(!t||u.current||s.length===0)return;if(!i){o();return}const p=n(t);if(!p)return;const I=r.get(p.tabKey)??0;c(P=>({...P,[I]:p.tabKey})),h(I),u.current=!0,y.current=!0,j.current!=null&&(window.clearTimeout(j.current),j.current=null),l(P=>{const S=new URLSearchParams(P);return S.delete("activeTab"),S},{replace:!0})},[t,s,n,r,i,o,c,h,l]),a.useEffect(()=>{if(!(y.current||i)&&s.length!==0){if(!t){o(),y.current=!0;return}if(u.current){y.current=!0;return}if(j.current==null)return j.current=window.setTimeout(()=>{j.current=null,!(y.current||i)&&(o(),y.current=!0)},1500),()=>{j.current!=null&&(window.clearTimeout(j.current),j.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!f){g.current=!1;return}if(!d||g.current||x)return;const p=b.find(I=>I.id===d.ideId);p&&(!p.chats||p.chats.length===0)&&(g.current=!0,m())},[f,d,x,b,m]),a.useEffect(()=>{if(!d)return;let p=null,I=0,P=-1,S=0;const C=()=>{p=null;const v=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(E=>E.offsetParent!==null);if(v.length===0){I<18&&(I+=1,p=requestAnimationFrame(C));return}let N=0;for(const E of v)E.scrollTop=E.scrollHeight,N+=E.scrollHeight;N===P?S+=1:(S=0,P=N),I+=1,!(S>=2||I>=18)&&(p=requestAnimationFrame(C))};return p=requestAnimationFrame(C),()=>{p!=null&&cancelAnimationFrame(p)}},[d==null?void 0:d.tabKey])}function ji({isMobile:t,location:s,navigate:n,requestedRemoteTabTarget:r,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:h}){const[l,f]=a.useState(null),[d,x]=a.useState(null),b=a.useMemo(()=>{if(t||!r)return null;const g=h(r);return g&&!ve(g)&&!ye(g)?g:null},[t,r,h]),m=a.useMemo(()=>{const g=l==null?void 0:l.ideId;if(!g)return null;const p=l!=null&&l.tabKey?o.find(I=>I.tabKey===l.tabKey):i?o.find(I=>I.tabKey===i):null;return(p==null?void 0:p.ideId)===g?p:o.find(I=>I.ideId===g&&I.streamSource==="native")||o.find(I=>I.ideId===g)||null},[o,l,i]),u=a.useMemo(()=>{if(m)return c.find(g=>g.id===m.ideId)},[c,m]);a.useEffect(()=>{b&&(f({ideId:b.ideId,tabKey:b.streamSource==="native"?"native":b.tabKey}),x(b),n({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,n,b]);const y=a.useCallback(g=>{g&&(f({ideId:g.ideId,tabKey:g.streamSource==="native"?"native":g.tabKey}),x(g))},[]),j=a.useCallback(()=>{f(null),x(null)},[]);return{remoteDialogConv:m,remoteDialogIdeEntry:u,remoteDialogActiveConv:d,setRemoteDialogActiveConv:x,openRemoteDialog:y,closeRemoteDialog:j}}function nt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return ve(t)||ye(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function At(t){return t&&(t.ideId||t.daemonId)||""}function yt(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function Ss({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:i,setClearedTabs:o}){const[c,h]=a.useState(!1),[l,f]=a.useState(!1),d=a.useCallback(async u=>{try{await t("standalone","launch_ide",{ideType:u,enableCdp:!0})}catch(y){console.error("Launch failed",y)}},[t]),x=a.useCallback(async(u,y)=>{try{const j=u||(s==null?void 0:s.daemonId)||"",g=await t(j,"switch_chat",{id:y,sessionId:y,...nt(s)}),p=g==null?void 0:g.result;if((g==null?void 0:g.success)===!0||p==="switched"||p==="switched-by-title")return;p===!1||p==="not_found"?yt(r,"⚠️ Session tab not found — try refreshing history"):typeof p=="string"&&p.startsWith("error:")?yt(r,`⚠️ Switch error: ${p}`):yt(r,"⚠️ Session switch failed")}catch(j){console.error("Switch failed",j),yt(r,`❌ Switch failed: ${j.message||"connection error"}`)}},[s,t,r]),b=a.useCallback(async()=>{if(!(!s||c)){h(!0);try{const u=At(s);await t(u,"new_chat",{...nt(s)}),o(y=>({...y,[s.tabKey]:Date.now()})),i(y=>({...y,[s.tabKey]:[]}))}catch(u){console.error("New chat failed",u)}finally{h(!1)}}},[s,c,t,o,i]),m=a.useCallback(async()=>{var u;if(!(!s||l)){f(!0);try{const y=At(s),j=await t(y,"list_chats",{forceExpand:!0,...nt(s)}),g=(j==null?void 0:j.chats)||((u=j==null?void 0:j.result)==null?void 0:u.chats);j!=null&&j.success&&Array.isArray(g)&&n(s.ideId,g)}catch(y){console.error("Refresh history failed",y)}finally{f(!1)}}},[s,l,t,n]);return{isCreatingChat:c,isRefreshingHistory:l,handleLaunchIde:d,handleSwitchSession:x,handleNewChat:b,handleRefreshHistory:m}}function wi(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 ki(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function Cs(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 vt(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[c,h]of t)!n.has(c)||h<=0||r.includes(h)||r.push(h);r.sort((c,h)=>c-h);const i={};r.forEach((c,h)=>{i[c]=h}),r.length===0&&(i[0]=0);const o=new Map;for(const[c,h]of t){if(!n.has(c)||h<=0)continue;const l=i[h];typeof l=="number"&&l>0&&o.set(c,l)}return{assignments:o,groupCount:Math.max(1,r.length),mapping:i,usedGroups:r}}function Is(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 Ni(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 Si(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,h)=>c+h,0);return o>0?i.map(c=>c/o*100):Array(n).fill(100/n)}function Ms(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 Ts(t){return Array(t).fill(100/t)}function Ci({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:h,visibleConversations:l,visibleTabKeys:f}){const d=a.useRef(null),x=a.useMemo(()=>vt(t,f),[t,f]),b=x.assignments,m=a.useMemo(()=>h?1:x.groupCount,[x.groupCount,h]),u=m>1,y=a.useCallback((S,C)=>{s(v=>{const N=new Map(vt(v,f).assignments);return C===0?N.delete(S):N.set(S,C),N}),r(v=>({...v,[C]:S})),n(C)},[s,f,r,n]),j=a.useCallback(S=>{s(C=>{const v=vt(C,f).assignments,N=new Map;for(const[E,B]of v)B!==S&&(B>S?N.set(E,B-1):N.set(E,B));return N}),c(C=>{if(C.length<=1)return[];const v=[...C];v.splice(S,1);const N=v.reduce((E,B)=>E+B,0);return N>0?v.map(E=>E/N*100):[]}),n(0)},[s,f,c,n]),g=a.useCallback((S,C)=>{C.preventDefault();const v=d.current;if(!v)return;const N=C.clientX,E=v.offsetWidth,B=o.length===m?[...o]:Ts(m),K=w=>{const R=(w.clientX-N)/E*100,L=[...B];L[S]=Math.max(15,B[S]+R),L[S+1]=Math.max(15,B[S+1]-R),c(L)},M=()=>{document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",M),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",K),document.addEventListener("mouseup",M)},[o,m,c]),p=a.useCallback((S,C,v)=>{if(m>=4)return;const N=v==="left"?C:C+1;s(E=>{const B=vt(E,f).assignments,K=new Map;for(const M of l){const w=B.get(M.tabKey)??0,A=w>=N?w+1:w;A>0&&K.set(M.tabKey,A)}return N>0&&K.set(S,N),K}),c(E=>{const B=E.length===m?[...E]:Ts(m),K=B[C]??100/m,M=Math.max(15,K/2),w=Math.max(15,K/2),A=[...B];A[C]=M,A.splice(N,0,w);const R=A.reduce((L,Y)=>L+Y,0);return A.map(L=>L/R*100)}),r(E=>{const B=Ms(E,N);return B[N]=S,B}),i(E=>{const B=Ms(E,N);return B[N]=[S],B}),n(N)},[m,s,f,l,c,r,i,n]);a.useEffect(()=>{wi(t,b)||s(b)},[t,b,s]),a.useEffect(()=>{const{mapping:S,usedGroups:C}=x;r(v=>{const N=Is(v,S);return Cs(v,N)?v:N}),i(v=>{const N=Is(v,S);return Cs(v,N)?v:N}),n(v=>{const N=h?0:Ni(v,C,S);return v===N?v:N}),c(v=>{const N=h?[]:Si(v,C,x.groupCount);return ki(v,N)?v:N})},[x,h,r,i,n,c]);const I=a.useMemo(()=>{const S=Array.from({length:m},()=>[]);for(const C of l){const v=b.get(C.tabKey)??0,N=Math.min(v,m-1);S[N].push(C)}return S},[l,b,m]),P=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:d,normalizedGroupAssignments:b,numGroups:m,isSplitMode:u,groupedConvs:I,moveTabToGroup:y,closeGroup:j,handleResizeStart:g,splitTabRelative:p,clearAllSplits:P}}function Ii({ides:t,sendDaemonCommand:s}){const n="0.7.38",r=a.useMemo(()=>t.filter(f=>{if(f.type!=="adhdev-daemon")return!1;const d=f.version||f.daemonVersion||null;return!d||!n?!1:d!==n}),[n,t]),[i,o]=a.useState(!1),[c,h]=a.useState({}),l=a.useCallback(async f=>{var d,x;h(b=>({...b,[f]:"upgrading"}));try{const b=await s(f,"daemon_upgrade",{});(d=b==null?void 0:b.result)!=null&&d.upgraded||(x=b==null?void 0:b.result)!=null&&x.success?h(m=>({...m,[f]:"done"})):h(m=>({...m,[f]:"error"}))}catch{h(b=>({...b,[f]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:l}}function Pt({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:i}){const[o,c]=a.useState(!1),[h,l]=a.useState(!1),f=a.useRef(!1),d=a.useCallback(async u=>{if(!s)return;const y=u.trim();if(!y||f.current)return;const j=s.tabKey;f.current=!0,l(!0);const g=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,p={role:"user",content:y,timestamp:Date.now(),_localId:g};n(I=>({...I,[j]:[...I[j]||[],p]}));try{const I=At(s);if(!I)return;await t(I,"send_chat",{message:y,text:y,...nt(s)}),setTimeout(()=>{const P=Date.now()-6e4;n(S=>{const C=S[j];if(!C)return S;const v=C.filter(N=>N.timestamp>P);return v.length===C.length?S:{...S,[j]:v}})},6e4)}catch(I){console.error("Send failed",I),n(P=>({...P,[j]:(P[j]||[]).filter(S=>S._localId!==g)}))}finally{f.current=!1,l(!1)}},[s,t,n]),x=a.useCallback(async()=>{if(s)try{if(i){await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0});return}await t(s.ideId,"vscode_command_exec",{commandId:"adhdev.relaunchWithCdp",args:[{force:!0}]})}catch(u){console.error("Relaunch failed",u)}},[s,i,t]),b=a.useCallback(async u=>{if(s){r(y=>[...y,{ideId:s.tabKey,text:`🖱️ **${u}** clicked`,timestamp:Date.now()}]);try{const j=(s.modalButtons||[]).indexOf(u),g=u.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),p=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(g),I=At(s);if(!I)return;(await t(I,"resolve_action",{button:u,action:p?"approve":"reject",...j>=0&&{buttonIndex:j},...nt(s)})).success||r(S=>[...S,{ideId:s.tabKey,text:`⚠️ **${u}** failed — button not found`,timestamp:Date.now()}])}catch(y){console.error("[ModalButton] Error:",y),r(j=>[...j,{ideId:s.tabKey,text:`❌ **${u}** 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(u){console.error("Focus agent failed",u)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:h,isFocusingAgent:o,handleSendChat:d,handleRelaunch:x,handleModalButton:b,handleFocusAgent:m}}function Mi({selectedConversation:t,isAcp:s,selectedIdeEntry:n,actionLogs:r,userName:i,isSendingChat:o,isFocusingAgent:c,onBack:h,onOpenHistory:l,onOpenRemote:f,handleSendChat:d,handleFocusAgent:x}){const b=a.useRef(null),m=ve(t)&&!s;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:h,type:"button","aria-label":"Back",children:e.jsx(qs,{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.jsxs("div",{className:"dashboard-mobile-chat-subtitle",children:[t.displaySecondary,t.machineName?` · ${t.machineName}`:""]})]})]}),e.jsxs("div",{className:"dashboard-mobile-chat-toolbar",children:[e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>l(t),type:"button",children:e.jsx(ts,{size:14})}),!s&&!m&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>f(t),type:"button",children:e.jsx(Ae,{size:14})})]})]}),e.jsx("div",{className:"dashboard-mobile-chat-thread",children:m?e.jsx(dn,{activeConv:t,terminalRef:b,handleSendChat:d,isSendingChat:o}):e.jsx(ns,{activeConv:t,ideEntry:n,handleSendChat:d,isSendingChat:o,handleFocusAgent:x,isFocusingAgent:c,actionLogs:r,userName:i},t.tabKey)})]})}function Qe(t){if(!t)return"";const s=Date.now()-t,n=Math.floor(s/6e4);if(n<1)return"now";if(n<60)return`${n}m`;const r=Math.floor(n/60);if(r<24)return`${r}h`;const i=Math.floor(r/24);return i<7?`${i}d`:new Date(t).toLocaleDateString()}function Ti({section:t,attentionItems:s,unreadItems:n,workingItems:r,completedItems:i,machineCards:o,getAvatarText:c,getConversationPreview:h,onOpenConversation:l,onOpenMachine:f,onOpenSettings:d,onSectionChange:x}){const b=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:b})})}),t==="chats"&&(s.length>0||n.length>0)&&e.jsxs("div",{className:"dashboard-mobile-chat-header-pill",children:[e.jsx(Lt,{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.jsx("section",{className:"dashboard-mobile-chat-section",children:o.map(m=>e.jsxs("button",{className:"dashboard-mobile-chat-card",onClick:()=>f(m.id),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar machine",children:c(m.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:m.label}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:m.unread>0?`${m.unread} new`:`${m.total} chats`})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:m.subtitle}),e.jsxs("div",{className:"dashboard-mobile-chat-card-preview",children:[m.latestConversation.displayPrimary," · ",h(m.latestConversation)]})]})]},m.id))}),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(m=>e.jsxs("button",{className:"dashboard-mobile-chat-card is-unread",onClick:()=>l(m.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar unread",children:c(m.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:m.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:Qe(m.timestamp)})]}),e.jsxs("div",{className:"dashboard-mobile-chat-card-subtitle",children:[m.conversation.displaySecondary," · Action needed"]}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:m.preview})]}),e.jsx("span",{className:"dashboard-mobile-chat-unread-dot"})]},m.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(m=>e.jsxs("button",{className:"dashboard-mobile-chat-card is-unread",onClick:()=>l(m.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar unread",children:c(m.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:m.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:Qe(m.timestamp)})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:m.conversation.displaySecondary}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:m.preview})]}),e.jsx("span",{className:"dashboard-mobile-chat-unread-dot"})]},m.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(m=>e.jsxs("button",{className:"dashboard-mobile-chat-card",onClick:()=>l(m.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar working",children:c(m.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:m.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:Qe(m.timestamp)})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:m.conversation.displaySecondary}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:m.preview})]}),e.jsx("span",{className:"dashboard-mobile-chat-status-badge",children:"Live"})]},m.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(m=>e.jsxs("button",{className:"dashboard-mobile-chat-card is-muted",onClick:()=>l(m.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar",children:c(m.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:m.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:Qe(m.timestamp)})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:m.conversation.displaySecondary}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:m.preview})]})]},m.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:d,type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar settings",children:e.jsx(Et,{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(([m,u])=>e.jsx("button",{className:`dashboard-mobile-chat-nav-tab${t===m?" is-active":""}`,onClick:()=>x(m),type:"button",children:u},m))})]})}function Ai({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentSessions:n,cliProviders:r,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:h,onBack:l,onOpenConversation:f,onOpenRecent:d,onOpenMachineDetails:x,onMachineUpgrade:b,onLaunchDetectedIde:m,onAddWorkspace:u,onLaunchWorkspaceProvider:y}){var re,H,ie;const j=(G,ae,te)=>G?"ide":ae>0?"cli":te>0?"acp":null,[g,p]=a.useState(!1),I=G=>G==="ide"?"IDE":G==="cli"?"CLI":"ACP",P=n.slice(0,4),S=s.slice(0,3),C=a.useMemo(()=>{const G=P.map(te=>({key:`recent-session:${te.id}`,type:"session",primary:te.label,secondary:`${I(te.kind)}${te.subtitle?` · ${te.subtitle}`:""}`,unread:!1,onClick:()=>d(te)})),ae=S.map(te=>({key:`recent-chat:${te.conversation.tabKey}`,type:"conversation",primary:te.conversation.displayPrimary,secondary:`Chat${te.conversation.displaySecondary?` · ${te.conversation.displaySecondary}`:""}${te.timestamp?` · ${Qe(te.timestamp)}`:""}`,unread:te.unread,onClick:()=>f(te.conversation)}));return[...G,...ae]},[f,d,S,P]),v=g?C:C.slice(0,5),N=C.length>0,E=(((re=t.detectedIdes)==null?void 0:re.length)||0)>0,B=a.useMemo(()=>t.workspaces||[],[t]),K=t.defaultWorkspaceId||null,[M,w]=a.useState(K||((H=B[0])==null?void 0:H.id)||""),[A,R]=a.useState(""),[L,Y]=a.useState(j(E,r.length,i.length)),V=a.useRef(null),q=M==="__custom__"?A.trim():((ie=B.find(G=>G.id===M))==null?void 0:ie.path)||"",Q=M==="__custom__"&&!!q&&h.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(h.message);return a.useEffect(()=>{var G;V.current!==t.id&&(V.current=t.id,w(K||((G=B[0])==null?void 0:G.id)||"__custom__"),R(""),Y(j(E,r.length,i.length)))},[i.length,r.length,K,E,t.id,B]),a.useEffect(()=>{var G;M!=="__custom__"&&(M&&B.some(ae=>ae.id===M)||w(K||((G=B[0])==null?void 0:G.id)||"__custom__"))},[K,M,B]),a.useEffect(()=>{L==="ide"&&E||L==="cli"&&r.length>0||L==="acp"&&i.length>0||Y(j(E,r.length,i.length))},[L,i.length,r.length,E]),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(qs,{size:18})}),e.jsxs("div",{className:"dashboard-mobile-chat-title-block",children:[e.jsx("div",{className:"dashboard-mobile-chat-title",children:t.nickname||t.hostname||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:[N&&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:v.map(G=>e.jsxs("button",{className:`dashboard-mobile-machine-command-card${G.unread?" is-primary":""}`,type:"button",onClick:G.onClick,children:[e.jsx("span",{className:"dashboard-mobile-machine-command-label",children:G.primary}),e.jsx("span",{className:"dashboard-mobile-machine-command-meta",children:G.secondary})]},G.key))}),C.length>5&&e.jsx("div",{className:"dashboard-mobile-machine-more-row",children:e.jsx("button",{type:"button",className:"dashboard-mobile-machine-more-btn",onClick:()=>p(G=>!G),children:g?"Show fewer":`Show ${C.length-5} more`})})]}),(E||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:M,onChange:G=>{w(G.target.value),G.target.value!=="__custom__"&&R("")},className:"dashboard-mobile-machine-workspace-select",children:B.length>0?e.jsxs(e.Fragment,{children:[B.map(G=>e.jsxs("option",{value:G.id,children:[G.id===K?"⭐ ":"",G.label||G.path.split("/").filter(Boolean).pop()||G.path]},G.id)),e.jsx("option",{value:"__custom__",children:"Custom path…"})]}):e.jsx("option",{value:"__custom__",children:"Enter workspace path…"})}),M==="__custom__"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",value:A,onChange:G=>R(G.target.value),placeholder:"/absolute/path",className:"dashboard-mobile-machine-workspace-input"}),e.jsx("button",{type:"button",className:"dashboard-mobile-machine-workspace-save",onClick:()=>{q&&u(q)},children:"Save workspace"})]}),q&&e.jsx("div",{className:"dashboard-mobile-machine-workspace-preview",children:q})]})}),e.jsxs("div",{className:"dashboard-mobile-machine-openwith",children:[E&&e.jsx("button",{className:`dashboard-mobile-machine-openwith-btn${L==="ide"?" is-active":""}`,type:"button",onClick:()=>Y("ide"),children:"IDE"}),r.length>0&&e.jsx("button",{className:`dashboard-mobile-machine-openwith-btn${L==="cli"?" is-active":""}`,type:"button",onClick:()=>Y("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`dashboard-mobile-machine-openwith-btn${L==="acp"?" is-active":""}`,type:"button",onClick:()=>Y("acp"),children:"ACP"})]}),L&&e.jsxs("div",{className:"dashboard-mobile-machine-provider-picker",children:[e.jsx("div",{className:"dashboard-mobile-machine-provider-title",children:L==="ide"?"Choose an IDE":L==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"dashboard-mobile-machine-provider-grid",children:L==="ide"?(t.detectedIdes||[]).slice(0,6).map(G=>e.jsxs("button",{type:"button",className:"dashboard-mobile-machine-provider-btn",onClick:()=>m(G.type,{workspacePath:q||null}),children:[e.jsx("span",{className:"dashboard-mobile-machine-provider-name",children:G.name}),e.jsx("span",{className:"dashboard-mobile-machine-provider-meta",children:q||"Use selected workspace"})]},G.type)):(L==="cli"?r:i).map(G=>e.jsxs("button",{type:"button",className:"dashboard-mobile-machine-provider-btn",onClick:()=>y(L,G.type,{workspaceId:M!=="__custom__"?M:null,workspacePath:q||null}),children:[e.jsxs("span",{className:"dashboard-mobile-machine-provider-name",children:[G.icon?`${G.icon} `:"",G.displayName]}),e.jsx("span",{className:"dashboard-mobile-machine-provider-meta",children:q||"Use selected workspace"})]},G.type))})]}),h.message&&e.jsxs("div",{className:`dashboard-mobile-machine-action-note is-${h.state}`,children:[h.message,Q&&e.jsx("div",{className:"dashboard-mobile-machine-action-cta-row",children:e.jsx("button",{type:"button",className:"dashboard-mobile-machine-action-cta",onClick:()=>u(q,{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:b,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:x,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"})]})]})]})]})]})}const An="adhdev_mobileChatReads_v1";function Ri(){try{const t=localStorage.getItem(An);if(!t)return{};const s=JSON.parse(t),n={};for(const[r,i]of Object.entries(s))typeof i=="number"&&Number.isFinite(i)&&(n[r]=i);return n}catch{return{}}}function _i(t){try{localStorage.setItem(An,JSON.stringify(t))}catch{}}function Ei(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():""}function He(t){const s=t.messages[t.messages.length-1],n=(s==null?void 0:s.timestamp)||(s==null?void 0:s.receivedAt)||0;return typeof n=="number"?n:Date.parse(String(n))||0}function As(t){const s=t.messages[t.messages.length-1],n=Ei(s==null?void 0:s.content);return n||(t.title?t.title:t.displaySecondary||"No messages yet")}function Li(t){return t.transport==="acp"?"acp":t.transport==="pty"?"cli":"ide"}function Pi(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function $i({conversations:t,ides:s,actionLogs:n,sendDaemonCommand:r,setLocalUserMessages:i,setActionLogs:o,isStandalone:c,userName:h,requestedActiveTabKey:l,onRequestedActiveTabConsumed:f,onOpenHistory:d,onOpenRemote:x}){const[b,m]=a.useState(()=>{var _;return((_=t[0])==null?void 0:_.tabKey)||null}),[u,y]=a.useState(()=>t[0]?"chat":"inbox"),[j,g]=a.useState("chats"),[p,I]=a.useState(()=>Ri()),[P,S]=a.useState(null),[C,v]=a.useState("idle"),[N,E]=a.useState(""),B=ot(),K="0.7.38",M=a.useMemo(()=>t.find(_=>_.tabKey===b)||t[0]||null,[t,b]),w=a.useMemo(()=>M?s.find(_=>_.id===M.ideId):void 0,[s,M]),A=a.useMemo(()=>s.filter(_=>_.type==="adhdev-daemon"||_.daemonMode),[s]),R=a.useMemo(()=>A.find(_=>_.id===P)||null,[A,P]),L=a.useMemo(()=>t.filter(_=>_.streamSource!=="native"||_.transport!=="cdp-page"?!0:!t.some(W=>W.ideId===_.ideId&&W.tabKey!==_.tabKey&&W.streamSource==="agent-stream")),[t]),Y=Pt({sendDaemonCommand:r,activeConv:M||void 0,setLocalUserMessages:i,setActionLogs:o,isStandalone:c}),V=a.useCallback(_=>{if(!_)return;const W=Math.max(Date.now(),He(_));I(T=>{const U={...T},X=_.recentKey||_.tabKey;return(U[X]||0)>=W?T:(U[X]=W,_i(U),U)}),r(_.daemonId||_.ideId,"mark_recent_seen",{recentKey:_.recentKey,kind:Li(_),providerType:_.agentType||_.ideType,workspace:_.workspaceName||null,seenAt:W}).catch(()=>{})},[r]);a.useEffect(()=>{var _;if(!M){y("inbox"),m(((_=t[0])==null?void 0:_.tabKey)||null);return}u==="chat"&&V(M)},[t,V,u,M]),a.useEffect(()=>{if(!l)return;const _=t.find(W=>W.tabKey===l);_&&(m(_.tabKey),y("chat"),f==null||f())},[t,f,l]);const q=a.useMemo(()=>L.map(_=>{const W=He(_),T=As(_),U=_.inboxBucket||"idle",X=U==="working",ee=U==="needs_attention",de=u==="chat"&&(M==null?void 0:M.tabKey)===_.tabKey,pe=_.recentKey||_.tabKey,he=_.lastSeenAt||0,ke=p[pe]||0,ue=ke>he&&W>0&&W<=ke,Ne=U==="task_complete"&&!de&&!!_.unread&&!ue;return{conversation:_,timestamp:W,preview:T,unread:Ne,requiresAction:ee,isWorking:X,inboxBucket:ee?"needs_attention":X?"working":Ne?"task_complete":"idle"}}).sort((_,W)=>W.timestamp-_.timestamp),[L,p,u,M]),Q=a.useMemo(()=>q.filter(_=>_.requiresAction),[q]),re=a.useMemo(()=>q.filter(_=>_.unread&&!_.requiresAction),[q]),H=a.useMemo(()=>q.filter(_=>!_.unread&&!_.requiresAction&&_.isWorking),[q]),ie=a.useMemo(()=>q.filter(_=>!_.unread&&!_.requiresAction&&!_.isWorking),[q]),G=a.useMemo(()=>R?q.filter(_=>_.conversation.daemonId===R.id||_.conversation.ideId===R.id):[],[q,R]),ae=a.useMemo(()=>{if(!R)return[];const _=R.recentSessions||[];return _.length>0?_.map(W=>({id:W.id,sessionId:W.sessionId||W.id,label:W.title||W.providerName||W.providerType,kind:W.kind,providerType:W.providerType,subtitle:W.currentModel||W.workspace||void 0,workspace:W.workspace,currentModel:W.currentModel})):s.filter(W=>!W.daemonMode&&W.daemonId===R.id).map(W=>{var U,X,ee,de,pe;const T=It(W)?"cli":et(W)?"acp":"ide";return{id:W.id,sessionId:W.id,label:((U=W.activeChat)==null?void 0:U.title)||(It(W)?W.cliName||W.type:et(W)&&W.cliName||W.type),kind:T,providerType:W.type,subtitle:et(W)?W.currentModel||W.workspace||void 0:W.workspace||void 0,workspace:W.workspace||void 0,currentModel:W.currentModel,timestamp:((pe=(de=(ee=(X=W.activeChat)==null?void 0:X.messages)==null?void 0:ee.at)==null?void 0:de.call(ee,-1))==null?void 0:pe.timestamp)||0}}).sort((W,T)=>T.timestamp-W.timestamp).map(({timestamp:W,...T})=>T)},[s,R]),te=(R==null?void 0:R.version)||(R==null?void 0:R.daemonVersion)||null,O=!!R&&!!te&&!0&&te!==K,D=a.useMemo(()=>(R==null?void 0:R.availableProviders)||[],[R]),$=a.useMemo(()=>D.filter(_=>_.category==="cli").map(_=>({type:_.type,displayName:_.displayName||_.type,icon:_.icon})),[D]),k=a.useMemo(()=>D.filter(_=>_.category==="acp").map(_=>({type:_.type,displayName:_.displayName||_.type,icon:_.icon})),[D]),F=a.useMemo(()=>{const _=new Map;for(const W of q){const T=W.conversation.daemonId||W.conversation.ideId,U=_.get(T);if(!U){_.set(T,{id:T,label:W.conversation.machineName||W.conversation.displaySecondary||"Machine",subtitle:W.conversation.connectionState==="connected"?"Connected":W.conversation.connectionState||"Unknown",unread:W.unread?1:0,total:1,latestConversation:W.conversation});continue}U.total+=1,W.unread&&(U.unread+=1),He(W.conversation)>He(U.latestConversation)&&(U.latestConversation=W.conversation)}return Array.from(_.values()).sort((W,T)=>He(T.latestConversation)-He(W.latestConversation))},[q]),z=a.useCallback(_=>{m(_.tabKey),y("chat"),V(_)},[V]),ne=a.useCallback(()=>{V(M),y("inbox")},[V,M]),le=a.useCallback(_=>{S(_),v("idle"),E(""),y("machine")},[]),oe=a.useCallback(async(_,W,T)=>{var U;try{v("loading"),E(`Launching ${W}…`);const X={ideType:W,enableCdp:!0};(U=T==null?void 0:T.workspacePath)!=null&&U.trim()&&(X.workspace=T.workspacePath.trim()),await r(_,"launch_ide",X),v("done"),E(`${W} launch requested`)}catch(X){v("error"),E(X instanceof Error?X.message:"Launch IDE failed"),console.error("Launch IDE failed",X)}},[r]),ce=a.useCallback(async(_,W,T)=>{if(W.trim())try{v("loading"),E(T!=null&&T.createIfMissing?"Creating folder…":"Saving workspace…");const U=await r(_,"workspace_add",{path:W.trim(),createIfMissing:(T==null?void 0:T.createIfMissing)===!0});if(U!=null&&U.success){v("done"),E(T!=null&&T.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}v("error"),E((U==null?void 0:U.error)||"Could not save workspace")}catch(U){v("error"),E(U instanceof Error?U.message:"Could not save workspace")}},[r]),J=a.useCallback(async _=>{var W,T,U,X;try{v("loading"),E("Installing latest daemon…");const ee=await r(_,"daemon_upgrade",{});if((W=ee==null?void 0:ee.result)!=null&&W.upgraded||(T=ee==null?void 0:ee.result)!=null&&T.success){v("done"),E(`Upgrading to v${((U=ee==null?void 0:ee.result)==null?void 0:U.version)||"latest"} and restarting…`);return}v("error"),E(((X=ee==null?void 0:ee.result)==null?void 0:X.error)||"Upgrade failed")}catch(ee){v("error"),E(ee instanceof Error?ee.message:"Upgrade failed")}},[r]),se=a.useCallback(async(_,W,T,U)=>{var X;try{v("loading"),E(`Launching ${T}…`);const ee={cliType:T};(X=U==null?void 0:U.workspacePath)!=null&&X.trim()?ee.dir=U.workspacePath.trim():U!=null&&U.workspaceId&&(ee.workspaceId=U.workspaceId);const de=await r(_,"launch_cli",ee),pe=(de==null?void 0:de.result)||de;if(de!=null&&de.success&&(pe!=null&&pe.id)){v("done"),E(`${T} launched`),B(`/dashboard?activeTab=${encodeURIComponent(pe.id)}`);return}v("error"),E((de==null?void 0:de.error)||(pe==null?void 0:pe.error)||`Could not launch ${W.toUpperCase()} workspace`)}catch(ee){v("error"),E(ee instanceof Error?ee.message:`Could not launch ${W.toUpperCase()} workspace`)}},[B,r]),Z=a.useCallback(async _=>{if(_.sessionId){B(`/dashboard?activeTab=${encodeURIComponent(_.sessionId)}`);return}if(R){if(_.kind==="ide"&&_.providerType){await oe(R.id,_.providerType,{workspacePath:_.workspace||null});return}if((_.kind==="cli"||_.kind==="acp")&&_.providerType){await se(R.id,_.kind,_.providerType,{workspacePath:_.workspace||null});return}}},[oe,se,R]);return e.jsx("div",{className:"dashboard-mobile-chat",children:u==="chat"&&M?e.jsx(Mi,{selectedConversation:M,isAcp:ye(M),selectedIdeEntry:w,actionLogs:n,userName:h,isSendingChat:Y.isSendingChat,isFocusingAgent:Y.isFocusingAgent,onBack:ne,onOpenHistory:d,onOpenRemote:x,handleSendChat:Y.handleSendChat,handleFocusAgent:Y.handleFocusAgent}):u==="machine"&&R?e.jsx(Ai,{selectedMachineEntry:R,selectedMachineConversations:G,selectedMachineRecentSessions:ae,cliProviders:$,acpProviders:k,selectedMachineNeedsUpgrade:O,appVersion:K,machineAction:{state:C,message:N},onBack:()=>y("inbox"),onOpenConversation:z,onOpenRecent:Z,onOpenMachineDetails:()=>B(`/machines/${R.id}`),onMachineUpgrade:()=>J(R.id),onLaunchDetectedIde:(_,W)=>oe(R.id,_,W),onAddWorkspace:(_,W)=>ce(R.id,_,W),onLaunchWorkspaceProvider:(_,W,T)=>se(R.id,_,W,T)}):e.jsx(Ti,{section:j,attentionItems:Q,unreadItems:re,workingItems:H,completedItems:ie,machineCards:F,getAvatarText:Pi,getConversationPreview:As,onOpenConversation:z,onOpenMachine:le,onOpenSettings:()=>B("/settings"),onSectionChange:g})})}function Ft(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Di({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[h,l]=a.useState(!1),[f,d]=a.useState(null),x=a.useCallback(()=>{c.current=0,l(!1),d(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",x),window.addEventListener("drop",x),()=>{window.removeEventListener("dragend",x),window.removeEventListener("drop",x)}),[x]);const b=a.useCallback(j=>{j.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,l(!0))},[]),m=a.useCallback(j=>{if(!j.dataTransfer.types.includes("text/tab-key"))return;if(j.preventDefault(),!Ft(s,n)){d("merge");return}const g=j.currentTarget.getBoundingClientRect(),p=j.clientX-g.left,I=g.width/3;p<I?d("split-left"):p>I*2?d("split-right"):d("merge")},[s,n]),u=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,l(!1),d(null))},[]),y=a.useCallback(j=>{c.current=0,l(!1);const g=j.dataTransfer.getData("text/tab-key"),p=g?t.some(P=>P.tabKey===g):!1,I=f;if(d(null),o(),!!g){if(j.preventDefault(),I==="split-left"&&Ft(s,n)){n==null||n(g,"split-left");return}if(I==="split-right"&&Ft(s,n)){n==null||n(g,"split-right");return}if(p){i(g);return}r==null||r(g)}},[t,f,s,n,r,i,o]);return{dragOver:h,dropAction:f,resetDragState:x,handleDragEnter:b,handleDragOver:m,handleDragLeave:u,handleDrop:y}}function Bi(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 Ki({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[h,l]=a.useState(n??[]),[f,d]=a.useState(null),x=a.useRef(null),b=a.useRef(null),m=a.useRef(r),u=a.useRef(i);a.useEffect(()=>{m.current=r},[r]),a.useEffect(()=>{u.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{l(v=>{const N=Bi(v,t);return N.length===v.length&&N.every((E,B)=>E===v[B])?v:N})},[t]);const y=a.useMemo(()=>{const v=f??h;if(v.length===0)return t;const N=new Map(v.map((E,B)=>[E,B]));return[...t].sort((E,B)=>{const K=N.get(E.tabKey)??999,M=N.get(B.tabKey)??999;return K-M})},[t,f,h]);a.useEffect(()=>{var N,E;if(y.length===0){o!==null&&(c(null),(N=m.current)==null||N.call(m,null));return}if(o&&y.some(B=>B.tabKey===o))return;const v=y[0].tabKey;v!==o&&(c(v),(E=m.current)==null||E.call(m,v))},[y,o]);const j=a.useMemo(()=>y.find(v=>v.tabKey===o),[y,o]),g=a.useCallback(v=>{var N;c(v),(N=m.current)==null||N.call(m,v)},[]),p=a.useCallback((v,N,E)=>{l(B=>{var A;const K=B.filter(R=>R!==v),M=K.indexOf(N);if(M<0)return B;const w=E==="left"?M:M+1;return K.splice(w,0,v),(A=u.current)==null||A.call(u,K),K}),d(null)},[]),I=a.useCallback((v,N,E)=>{const K=(h.length>0?h:t.map(A=>A.tabKey)).filter(A=>A!==v),M=K.indexOf(N);if(M<0)return;const w=E==="left"?M:M+1;K.splice(w,0,v),x.current=K,d(K)},[h,t]),P=a.useCallback(()=>{var N;const v=x.current;v&&(l(v),(N=u.current)==null||N.call(u,v))},[]),S=a.useCallback(()=>{x.current=null,d(null)},[]),C=a.useCallback(v=>{l(N=>{var B;const E=N.filter(K=>K!==v);return E.push(v),(B=u.current)==null||B.call(u,E),E})},[]);return{activeTabId:o,activeConv:j,sortedConversations:y,previewOrderRef:x,draggingTabRef:b,selectTab:g,handleTabReorder:p,updatePreviewOrder:I,commitPreviewOrder:P,clearPreviewOrder:S,moveTabToEnd:C,setDraggingTabKey:v=>{b.current=v}}}const Rn=a.memo(function({activeConv:s,clearToken:n,isCli:r,ideEntry:i,screenshotUrl:o,clearScreenshot:c,terminalRef:h,handleModalButton:l,handleRelaunch:f,handleSendChat:d,isSendingChat:x,handleFocusAgent:b,isFocusingAgent:m,actionLogs:u,userName:y}){const j=a.useCallback(()=>{c()},[c]);return e.jsxs(e.Fragment,{children:[e.jsx(rn,{activeConv:s,onModalButton:l}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!r&&s.transport!=="acp"&&o?e.jsx(Yr,{screenshotUrl:o,mode:"preview",onDismiss:j}):!r&&s.transport!=="acp"&&s.cdpConnected===!1?e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[e.jsx("span",{className:"text-sm",children:e.jsx(ss,{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:f,children:"Relaunch with CDP"})]}):null}),r?e.jsx(dn,{activeConv:s,clearToken:n,terminalRef:h,handleSendChat:d,isSendingChat:x}):e.jsx(ns,{activeConv:s,ideEntry:i,handleSendChat:d,isSendingChat:x,handleFocusAgent:b,isFocusingAgent:m,actionLogs:u,userName:y})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCli===s.isCli&&t.ideEntry===s.ideEntry&&t.screenshotUrl===s.screenshotUrl&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName);function Wi({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 Ut={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 Oi(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function zi(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":n;a.useEffect(()=>{s(Oi())},[]);const h=a.useCallback(()=>{navigator.clipboard.writeText(Ut[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:h,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Ut[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Ut[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 os({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(zi,{}),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(tn,{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 _n="adhdev-tab-shortcuts";function Fi(){try{return JSON.parse(localStorage.getItem(_n)||"{}")}catch{return{}}}function Ui({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,o]=a.useState(()=>Fi()),[c,h]=a.useState(null),l=a.useCallback(d=>{const x=[];return d.metaKey&&x.push(r?"⌘":"Meta"),d.ctrlKey&&x.push("Ctrl"),d.altKey&&x.push(r?"⌥":"Alt"),d.shiftKey&&x.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(d.key)?null:(x.push(d.key.length===1?d.key.toUpperCase():d.key),x.join("+"))},[r]),f=a.useCallback(d=>{o(d);try{localStorage.setItem(_n,JSON.stringify(d))}catch{}},[]);return a.useEffect(()=>{if(!c)return;const d=x=>{if(x.preventDefault(),x.stopPropagation(),x.key==="Escape"){h(null);return}const b=l(x);if(!b)return;const m={...i};for(const[u,y]of Object.entries(m))y===b&&delete m[u];m[c]=b,f(m),h(null)};return window.addEventListener("keydown",d,!0),()=>window.removeEventListener("keydown",d,!0)},[c,i,f,l]),a.useEffect(()=>{const d=x=>{if(!(!x.ctrlKey&&!x.metaKey&&!x.altKey)){for(const[b,m]of Object.entries(i))if(t.includes(b)&&l(x)===m){x.preventDefault(),s(),n(b);return}}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[i,t,s,n,l]),{isMac:r,tabShortcuts:i,shortcutListening:c,setShortcutListening:h,saveShortcuts:f}}const Hi=a.memo(function({conv:s,isActive:n,isDraggedTab:r,shortcut:i,conversationKeys:o,draggingTabRef:c,onFocus:h,onSelectTab:l,onConversationActivated:f,onPreviewReorder:d,onReorderTab:x,onCommitPreviewOrder:b,onClearPreviewOrder:m,onDragStateReset:u,onDragTabKeyChange:y,onReceiveTab:j,onOpenContextMenu:g,longPressTimer:p}){const I=s.status==="generating"?"agent-tab-generating":s.status==="waiting_approval"?"agent-tab-waiting":"",P=s.connectionState==="failed"||s.connectionState==="closed",S=a.useCallback(A=>{c.current=s.tabKey,y(s.tabKey),A.dataTransfer.setData("text/tab-key",s.tabKey),A.dataTransfer.effectAllowed="move"},[s.tabKey,c,y]),C=a.useCallback(()=>{c.current=null,y(null),b(),m(),u()},[c,y,b,m,u]),v=a.useCallback(A=>{const R=c.current;if(!(!R||R===s.tabKey)&&A.dataTransfer.types.includes("text/tab-key")){A.preventDefault(),A.stopPropagation();const L=A.currentTarget.getBoundingClientRect(),Y=A.clientX<L.left+L.width/2?"left":"right";d(R,s.tabKey,Y)}},[s.tabKey,c,d]),N=a.useCallback(A=>{A.preventDefault(),A.stopPropagation();const R=A.dataTransfer.getData("text/tab-key");if(R&&R!==s.tabKey){const L=A.currentTarget.getBoundingClientRect(),Y=A.clientX<L.left+L.width/2?"left":"right";o.includes(R)?x(R,s.tabKey,Y):j&&j(R)}m()},[s.tabKey,o,x,j,m]),E=a.useCallback(A=>{A.stopPropagation(),h(),l(s.tabKey),f(s)},[s,f,h,l]),B=a.useCallback(A=>{A.preventDefault(),g(A.clientX,A.clientY,s.tabKey)},[s.tabKey,g]),K=a.useCallback(A=>{const R=A.touches[0];p.current=setTimeout(()=>{g(R.clientX,R.clientY,s.tabKey)},600)},[s.tabKey,p,g]),M=a.useCallback(()=>{p.current&&clearTimeout(p.current)},[p]),w=["adhdev-dockview-tab",I,n&&"is-active",P&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:w,draggable:!0,onDragStart:S,onDragEnd:C,onDragOver:v,onDrop:N,onClick:E,onContextMenu:B,onTouchStart:K,onTouchEnd:M,onTouchMove:M,style:{cursor:"pointer",opacity:r?.4:void 0},children:[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:"▲"}):P?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:P?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]})]})]})})]}),i&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${i}`,children:i})]})},(t,s)=>t.conv===s.conv&&t.isActive===s.isActive&&t.isDraggedTab===s.isDraggedTab&&t.shortcut===s.shortcut&&t.conversationKeys===s.conversationKeys);function Vi({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,draggingTabRef:i,onFocus:o,onSelectTab:c,onConversationActivated:h,onPreviewReorder:l,onReorderTab:f,onCommitPreviewOrder:d,onClearPreviewOrder:x,onDragStateReset:b,onDragTabKeyChange:m,onMoveTab:u,onReceiveTab:y,onHideTab:j}){const[g,p]=a.useState(null),I=a.useRef(null),P=a.useRef(null),S=a.useMemo(()=>t.map(M=>M.tabKey),[t]);lt("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(g==null?void 0:g.tabKey)||null});const{isMac:C,tabShortcuts:v,shortcutListening:N,setShortcutListening:E,saveShortcuts:B}=Ui({sortedTabKeys:t.map(M=>M.tabKey),onFocus:o,onSelectTab:c});a.useEffect(()=>{if(!g)return;const M=w=>{const A=document.querySelector("[data-pane-context-menu]");A&&A.contains(w.target)||p(null)};return window.addEventListener("mousedown",M,!0),()=>window.removeEventListener("mousedown",M,!0)},[g]),a.useEffect(()=>{const M=P.current;if(!M)return;const w=A=>{Math.abs(A.deltaY)>Math.abs(A.deltaX)&&(A.preventDefault(),M.scrollLeft+=A.deltaY)};return M.addEventListener("wheel",w,{passive:!1}),()=>M.removeEventListener("wheel",w)},[]);const K=a.useCallback((M,w,A)=>{p({x:M,y:w,tabKey:A})},[]);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:P,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(M=>e.jsx(Hi,{conv:M,isActive:s===M.tabKey,isDraggedTab:i.current===M.tabKey,shortcut:v[M.tabKey],conversationKeys:S,draggingTabRef:i,onFocus:o,onSelectTab:c,onConversationActivated:h,onPreviewReorder:l,onReorderTab:f,onCommitPreviewOrder:d,onClearPreviewOrder:x,onDragStateReset:b,onDragTabKeyChange:m,onReceiveTab:y,onOpenContextMenu:K,longPressTimer:I},M.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),g&&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:g.x,top:g.y},children:[u&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{u(g.tabKey,"left"),p(null)},children:"← Move to Left Group"}),u&&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:()=>{u(g.tabKey,"right"),p(null)},children:"Move to Right Group →"}),u&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{u(g.tabKey,"split-left"),p(null)},children:"⇤ Split Left"}),u&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{u(g.tabKey,"split-right"),p(null)},children:"Split Right ⇥"}),e.jsx("div",{className:"border-t border-border-subtle my-1 "}),e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:M=>{M.stopPropagation(),E(g.tabKey),p(null)},children:["⌨ ",v[g.tabKey]?`Change shortcut (${v[g.tabKey]})`:"Set shortcut"]}),v[g.tabKey]&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onClick:()=>{const M={...v};delete M[g.tabKey],B(M),p(null)},children:"✕ Remove shortcut"}),j&&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:()=>{j(g.tabKey),p(null)},children:"🚫 Hide from Dashboard"})]}),!u&&!j&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),N&&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:()=>E(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:M=>M.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",C?"⌘+1":"Ctrl+1",", ",C?"⌥+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 qi({conversations:t,ides:s,clearedTabs:n,actionLogs:r,screenshotMap:i,setScreenshotMap:o,sendDaemonCommand:c,setLocalUserMessages:h,setActionLogs:l,isStandalone:f,userName:d,groupIndex:x,onFocus:b,isSplitMode:m,numGroups:u,onMoveTab:y,onReceiveTab:j,style:g,detectedIdes:p,handleLaunchIde:I,onActiveTabChange:P,initialActiveTabId:S,initialTabOrder:C,onTabOrderChange:v,onHideTab:N}){const{sendCommand:E}=De(),B=a.useRef(null),{activeTabId:K,activeConv:M,sortedConversations:w,draggingTabRef:A,selectTab:R,handleTabReorder:L,updatePreviewOrder:Y,commitPreviewOrder:V,clearPreviewOrder:q,moveTabToEnd:Q,setDraggingTabKey:re}=Ki({conversations:t,initialActiveTabId:S,initialTabOrder:C,onActiveTabChange:P,onTabOrderChange:v}),H=Pt({sendDaemonCommand:c,activeConv:M,setLocalUserMessages:h,setActionLogs:l,isStandalone:f}),{dragOver:ie,dropAction:G,resetDragState:ae,handleDragEnter:te,handleDragOver:O,handleDragLeave:D,handleDrop:$}=Di({conversations:t,numGroups:u,onMoveTab:y,onReceiveTab:j,onOwnTabDrop:Q,onClearPreviewOrder:q}),k=M&&ve(M)&&!ye(M),F=a.useMemo(()=>M?s.find(ce=>ce.id===M.ideId):void 0,[s,M]),z=M?i[M.ideId]:void 0,ne=a.useCallback(()=>{if(!M||!(M.ideId in i))return;const ce={...i};delete ce[M.ideId],o(ce)},[M,i,o]),le=a.useMemo(()=>M?r.filter(ce=>ce.ideId===M.tabKey):[],[r,M]);lt("PaneGroup",{groupIndex:x,conversationCount:t.length,activeTabId:K,dragOver:ie});const oe=a.useCallback(ce=>{ce.streamSource==="agent-stream"&&ce.agentType&&E(ce.ideId,"focus_session",{agentType:ce.agentType,...ce.sessionId&&{targetSessionId:ce.sessionId}}).catch(()=>{})},[E]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:b,style:{...g,outline:ie?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Vi,{conversations:w,activeTabId:K,groupIndex:x,numGroups:u,draggingTabRef:A,onFocus:b,onSelectTab:R,onConversationActivated:oe,onPreviewReorder:Y,onReorderTab:L,onCommitPreviewOrder:V,onClearPreviewOrder:q,onDragStateReset:ae,onDragTabKeyChange:re,onMoveTab:y,onReceiveTab:j,onHideTab:N}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:te,onDragOver:O,onDragLeave:D,onDrop:$,children:[ie&&e.jsx(Wi,{dropAction:G,canSplit:!!(u<4&&y)}),M?e.jsx(Rn,{activeConv:M,clearToken:n[M.tabKey]||0,isCli:!!k,ideEntry:F,screenshotUrl:z,clearScreenshot:ne,terminalRef:B,handleModalButton:H.handleModalButton,handleRelaunch:H.handleRelaunch,handleSendChat:H.handleSendChat,isSendingChat:H.isSendingChat,handleFocusAgent:H.handleFocusAgent,isFocusingAgent:H.isFocusingAgent,actionLogs:le,userName:d}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(os,{conversationsCount:t.length,isSplitMode:m,isStandalone:f,detectedIdes:p,handleLaunchIde:I})})]})]})}function Yi({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:h,screenshotMap:l,setScreenshotMap:f,sendDaemonCommand:d,setLocalUserMessages:x,setActionLogs:b,isStandalone:m,userName:u,setFocusedGroup:y,moveTabToGroup:j,splitTabRelative:g,closeGroup:p,handleResizeStart:I,detectedIdes:P,handleLaunchIde:S,groupActiveTabIds:C,setGroupActiveTabIds:v,groupTabOrders:N,setGroupTabOrders:E,toggleHiddenTab:B}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:i.map((K,M)=>{const w=s&&r.length===n?`${r[M]}%`:void 0;return e.jsxs(or.Fragment,{children:[s&&M>0&&e.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:A=>I(M-1,A),onDoubleClick:()=>p(M),title:"Drag to resize · Double-click to merge",children:e.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1 group-hover:bg-accent/10"})}),e.jsx(qi,{style:s?{flexBasis:w??`${100/n}%`,flexGrow:w?0:1,flexShrink:w?0:1}:void 0,conversations:K,clearedTabs:o,ides:c,actionLogs:h,screenshotMap:l,setScreenshotMap:f,sendDaemonCommand:d,setLocalUserMessages:x,setActionLogs:b,isStandalone:m,userName:u,groupIndex:M,onFocus:()=>y(M),isSplitMode:s,numGroups:n,onMoveTab:(A,R)=>{R==="left"&&M>0?j(A,M-1):R==="right"&&M<n-1?j(A,M+1):R==="split-left"&&n<4?g(A,M,"left"):R==="split-right"&&n<4&&g(A,M,"right")},onReceiveTab:A=>j(A,M),detectedIdes:M===0?P:void 0,handleLaunchIde:M===0?S:void 0,onActiveTabChange:A=>v(R=>(R[M]??null)===(A??null)?R:{...R,[M]:A}),initialActiveTabId:C[M],initialTabOrder:N[M],onTabOrderChange:A=>E(R=>{const L=R[M]||[];return L.length===A.length&&L.every((Y,V)=>Y===A[V])?R:{...R,[M]:A}}),onHideTab:B})]},M)})})}function En({doId:t,ideId:s,ideType:n,connState:r,viewMode:i,instanceId:o}){const[c,h]=a.useState(null),[l,f]=a.useState(null),d=a.useMemo(()=>{if(!s)return n;const b=s.split(":");return b.length>=3&&b[1]==="ide"?b.slice(2).join(":"):n},[s,n]);a.useEffect(()=>t?xe.onScreenshot("ide-page",(m,u)=>{if(m!==t)return;const y=new FileReader;y.onload=()=>h(y.result),y.readAsDataURL(u)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&h(null)},[r]),a.useEffect(()=>{var m;return t?((m=xe.onStatus)==null?void 0:m.call(xe,(u,y)=>{u===t&&y!=null&&y.screenshotUsage&&f(y.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{h(null)},[t,s,d]),a.useEffect(()=>{const b=t?xe.get(t):null;if(!(!b||r!=="connected"))return i!=="chat"&&d?b.startScreenshots(d):b.stopScreenshots(d),()=>{b.stopScreenshots(d)}},[i,r,d,t]);const x=a.useCallback(async(b,m)=>{const u=t?xe.get(t):null;return!u||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):u.sendInput(b,m,o||d)},[t,r,o,d]);return{connScreenshot:c,screenshotUsage:l,handleRemoteAction:x}}const Ln=a.createContext(null);function $t(){const t=a.useContext(Ln);if(!t)throw new Error("DashboardDockviewContext missing");return t}function Nt(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function Xi(t){return`remote:${t}`}function Rt(t){return t.startsWith("remote:")}function Dt(t,s){return t.find(n=>n.ideId===s&&n.streamSource==="native")??t.find(n=>n.ideId===s)??null}function Gi(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 Ji(t,s,n){var h;const r=[s];let i;for(const l of r){let f;for(const d of l){const x=t.addPanel({id:d.tabKey,component:"conversation",title:Nt(d),params:{kind:"conversation",tabKey:d.tabKey},...f?{position:{referencePanel:f,direction:"within"},inactive:!0}:i?{position:{referencePanel:i,direction:"right"},inactive:!0}:{}});f||(f=x.id)}i=f??i}const o=n??((h=s[0])==null?void 0:h.tabKey)??null;if(!o)return;const c=t.getPanel(o);c&&c.group.model.openPanel(c)}function Rs(t,s){const n=new Set(s.map(r=>r.tabKey));for(const r of[...t.panels])Rt(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!==Nt(r)&&i.api.setTitle(Nt(r));continue}t.addPanel({id:r.tabKey,component:"conversation",title:Nt(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 _s(t,s,n){var l,f;const r=n?Xi(n):null;for(const d of[...t.panels])Rt(d.id)&&(!r||d.id!==r)&&t.removePanel(d);if(!n||!r)return;const i=Dt(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 h=(i==null?void 0:i.tabKey)??((l=t.activePanel)==null?void 0:l.id)??((f=t.panels.find(d=>!Rt(d.id)))==null?void 0:f.id);t.addPanel({id:r,component:"remote",title:c,params:{kind:"remote",ideId:n},...h?{position:{referencePanel:h,direction:"right"},inactive:!0}:{}})}function Zi({params:t}){const s=$t(),n=a.useRef(null),r=s.conversationsByTabKey.get(t.tabKey),i=Pt({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,h=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(os,{conversationsCount:0,isSplitMode:!1,isStandalone:s.isStandalone,detectedIdes:s.detectedIdes,handleLaunchIde:s.handleLaunchIde})});const f=ve(r)&&!ye(r);return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(Rn,{activeConv:r,clearToken:s.clearedTabs[r.tabKey]||0,isCli:f,ideEntry:o,screenshotUrl:c,clearScreenshot:h,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 Qi({params:t}){var l;const s=$t(),n=a.useMemo(()=>Dt([...s.conversationsByTabKey.values()],t.ideId),[s.conversationsByTabKey,t.ideId]),r=a.useMemo(()=>s.ides.find(f=>f.id===t.ideId),[s.ides,t.ideId]),i=(n==null?void 0:n.daemonId)||((l=n==null?void 0:n.ideId)==null?void 0:l.split(":")[0])||t.ideId.split(":")[0]||t.ideId,{connScreenshot:o,screenshotUsage:c,handleRemoteAction:h}=En({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(nn,{addLog:()=>{},connState:n.connectionState||"new",connScreenshot:o,screenshotUsage:c,transportType:n.transport,onAction:h})}):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 eo(){const t=$t();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(os,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function to(t){var f,d;Gi(t);const s=$t();if(t.params.kind==="remote"){const x=Dt([...s.conversationsByTabKey.values()],t.params.ideId),b=((f=t.api.group.activePanel)==null?void 0:f.id)===t.api.id,m=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${b?" is-active":""}${m?" 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:x!=null&&x.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:x.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=((d=t.api.group.activePanel)==null?void 0:d.id)===t.api.id,i=t.api.isGroupActive,o=n.connectionState==="failed"||n.connectionState==="closed",c=n.connectionState==="connecting"||n.connectionState==="new",h=n.status==="generating",l=n.status==="waiting_approval";return e.jsxs("div",{className:`adhdev-dockview-tab${r?" is-active":""}${i?" is-group-active":""}${o?" is-reconnecting":""}`,title:n.displayPrimary,children:[e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:h?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 so({visibleConversations:t,clearedTabs:s,ides:n,actionLogs:r,screenshotMap:i,setScreenshotMap:o,sendDaemonCommand:c,setLocalUserMessages:h,setActionLogs:l,isStandalone:f,userName:d,detectedIdes:x,handleLaunchIde:b,toggleHiddenTab:m,onActiveTabChange:u,requestedActiveTabKey:y,requestedRemoteIdeId:j,onRequestedActiveTabConsumed:g}){const{theme:p}=yn(),{sendCommand:I}=De(),P=a.useRef(null),S=a.useRef(null),C=a.useRef(!1),[v,N]=a.useState(!1),[E,B]=a.useState(!1),K=a.useRef(null),M=a.useMemo(()=>In(typeof window<"u"?window.innerWidth:1280),[]),w=a.useMemo(()=>new Map(t.map(H=>[H.tabKey,H])),[t]),A=a.useMemo(()=>({actionLogs:r,clearedTabs:s,conversationsByTabKey:w,detectedIdes:x,handleLaunchIde:b,ides:n,isStandalone:f,screenshotMap:i,sendDaemonCommand:c,setActionLogs:l,setLocalUserMessages:h,setScreenshotMap:o,toggleHiddenTab:m,userName:d}),[r,s,w,x,b,n,f,i,c,l,h,o,m,d]),R=a.useCallback(H=>{if(!H)return!1;const ie=P.current;if(!ie)return!1;const G=ie.getPanel(H);return G?(G.group.model.openPanel(G),g==null||g(),!0):!1},[g]),L=a.useCallback(()=>{const H=S.current;if(!H)return;const ie=H.querySelectorAll(".dv-drop-target-container, .dv-drop-target-anchor, .dv-drop-target-dropzone, .dv-drop-target-selection, .dv-render-overlay");for(const G of ie)G.setAttribute("data-adhdev-force-hidden","true")},[]),Y=a.useCallback(()=>{const H=S.current;if(!H)return;const ie=H.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const G of ie)G.removeAttribute("data-adhdev-force-hidden")},[]),V=a.useCallback(()=>{const H=S.current;if(!H)return;const ie=H.querySelectorAll(".dv-drop-target-container");for(const te of ie)te.remove();const G=H.querySelectorAll(".dv-drop-target-dropzone");for(const te of G)te.remove();const ae=H.querySelectorAll(".dv-drop-target");for(const te of ae)te.classList.remove("dv-drop-target")},[]),q=a.useCallback(()=>{N(!1),B(!1),Y(),L(),V(),!(typeof window>"u")&&(K.current!=null&&window.clearTimeout(K.current),window.requestAnimationFrame(()=>{L(),V()}),K.current=window.setTimeout(()=>{L(),V(),K.current=null},80))},[Y,L,V]),Q=a.useCallback(H=>{var G;P.current=H.api;const ie=fi(M);ie!=null&&ie.layout&&H.api.fromJSON(ie.layout,{reuseExistingPanels:!1}),Rs(H.api,t),_s(H.api,t,j),H.api.totalPanels===0&&t.length>0?Ji(H.api,t,y):R(y)||R(ie==null?void 0:ie.activeTabId),C.current=!0,H.api.onDidActivePanelChange(ae=>{var O;if(ae&&Rt(ae.id)){const D=((O=ae.params)==null?void 0:O.ideId)||ae.id.slice(7),$=Dt(t,D);u(($==null?void 0:$.tabKey)??null);return}if(u((ae==null?void 0:ae.id)??null),!ae)return;const te=w.get(ae.id);(te==null?void 0:te.streamSource)==="agent-stream"&&te.agentType&&I(te.ideId,"focus_session",{agentType:te.agentType,...te.sessionId&&{targetSessionId:te.sessionId}}).catch(()=>{})}),H.api.onDidLayoutChange(()=>{var ae;bi(M,{activeTabId:((ae=H.api.activePanel)==null?void 0:ae.id)??null,layout:H.api.toJSON()})}),H.api.onWillDragPanel(()=>{N(!0),B(!1),L()}),H.api.onWillDragGroup(()=>{N(!0),B(!1),L()}),H.api.onWillShowOverlay(()=>{Y(),B(!0)}),H.api.onDidMovePanel(q),H.api.onDidDrop(q),u(((G=H.api.activePanel)==null?void 0:G.id)??null)},[R,q,Y,w,M,L,V,u,y,I,t]);a.useEffect(()=>{const H=P.current;!H||!C.current||(Rs(H,t),_s(H,t,j),!H.activePanel&&H.panels[0]&&H.panels[0].group.model.openPanel(H.panels[0]))},[j,t]),a.useEffect(()=>{C.current&&R(y)},[R,y]),a.useEffect(()=>{if(!v||typeof window>"u")return;const H=()=>q();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)}},[q,v]),a.useEffect(()=>()=>{typeof window>"u"||K.current!=null&&window.clearTimeout(K.current)},[]);const re=p==="light"?lr:dr;return e.jsx(Ln.Provider,{value:A,children:e.jsx("div",{ref:S,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(cr,{className:`h-full min-h-0 min-w-0 adhdev-dockview${v?" is-dragging-dockview":""}${E?" is-showing-dockview-overlay":""}`,components:{conversation:Zi,remote:Qi},defaultTabComponent:to,watermarkComponent:eo,onReady:Q,singleTabMode:"default",tabAnimation:"smooth",theme:re})})})}function no({showMobileChatMode:t,isMobile:s,activeConv:n,chatIdes:r,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:h,onFitCli:l,onStopCli:f,mobileChatConversations:d,ides:x,actionLogs:b,sendDaemonCommand:m,setLocalUserMessages:u,setActionLogs:y,isStandalone:j,userName:g,requestedMobileTabKey:p,onRequestedMobileTabConsumed:I,containerRef:P,isSplitMode:S,numGroups:C,groupSizes:v,groupedConvs:N,clearedTabs:E,screenshotMap:B,setScreenshotMap:K,focusedGroup:M,setFocusedGroup:w,moveTabToGroup:A,splitTabRelative:R,closeGroup:L,handleResizeStart:Y,detectedIdes:V,handleLaunchIde:q,groupActiveTabIds:Q,setGroupActiveTabIds:re,groupTabOrders:H,setGroupTabOrders:ie,toggleHiddenTab:G,visibleConversations:ae,requestedDesktopTabKey:te,onRequestedDesktopTabConsumed:O,onDesktopActiveTabChange:D}){return e.jsxs(e.Fragment,{children:[!t&&e.jsx(pa,{activeConv:n,agentCount:r.length,wsStatus:i,isConnected:o,conversations:ae,onOpenHistory:c,onOpenConversation:$=>D($.tabKey),onOpenRemote:()=>{!n||ve(n)||ye(n)||h(n)},onFitCli:l,onStopCli:f}),t?e.jsx($i,{conversations:d,ides:x,actionLogs:b,sendDaemonCommand:m,setLocalUserMessages:u,setActionLogs:y,isStandalone:j,userName:g,requestedActiveTabKey:p,onRequestedActiveTabConsumed:I,onOpenHistory:c,onOpenRemote:h}):s?e.jsx(Yi,{containerRef:P,isSplitMode:S,numGroups:C,groupSizes:v,groupedConvs:N,clearedTabs:E,ides:x,actionLogs:b,screenshotMap:B,setScreenshotMap:K,sendDaemonCommand:m,setLocalUserMessages:u,setActionLogs:y,isStandalone:j,userName:g,focusedGroup:M,setFocusedGroup:w,moveTabToGroup:A,splitTabRelative:R,closeGroup:L,handleResizeStart:Y,detectedIdes:V,handleLaunchIde:q,groupActiveTabIds:Q,setGroupActiveTabIds:re,groupTabOrders:H,setGroupTabOrders:ie,toggleHiddenTab:G}):e.jsx(so,{visibleConversations:ae,clearedTabs:E,ides:x,actionLogs:b,screenshotMap:B,setScreenshotMap:K,sendDaemonCommand:m,setLocalUserMessages:u,setActionLogs:y,isStandalone:j,userName:g,detectedIdes:V,handleLaunchIde:q,toggleHiddenTab:G,onActiveTabChange:D,requestedActiveTabKey:te,onRequestedActiveTabConsumed:O})]})}const Ht=[{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 ro({onClose:t}){const[s,n]=a.useState(0),r=Ht[s],i=s===Ht.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:Ht.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:`
|
|
55
|
-
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
|
|
56
|
-
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
|
|
57
|
-
`})]})}function ao({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,h=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:h?"var(--status-warning)":l?"var(--accent-primary)":"#64748b",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),o.title,h&&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 io({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:i,preferredTabKey:o}){const[c,h]=a.useState(()=>o||"native"),l=a.useMemo(()=>hn(s),[s]),f=a.useMemo(()=>{var j;if(!t)return[];const y=t.daemonId||((j=t.id)==null?void 0:j.split(":")[0])||t.id;return mn(t,r,{machineName:t.daemonId&&l[t.daemonId]||void 0,connectionState:n[y]||"new"})},[t,r,l,n]),d=a.useMemo(()=>f.find(y=>y.streamSource==="native"),[f]),x=a.useMemo(()=>f.filter(y=>y.streamSource==="agent-stream"),[f]);a.useEffect(()=>{o&&h(o)},[o]),a.useEffect(()=>{var y;c!=="native"&&(x.some(j=>j.tabKey===c)||h(((y=x[0])==null?void 0:y.tabKey)||"native"))},[c,x]),a.useEffect(()=>{c==="native"&&(d||x[0]&&h(x[0].tabKey))},[c,d,x]);const b=a.useMemo(()=>c==="native"&&d?d:x.find(y=>y.tabKey===c)||d||x[0],[c,d,x]),m=a.useMemo(()=>x.map(y=>({tabKey:y.tabKey,title:y.title||y.agentName||i,status:y.status})),[x,i]),u=a.useCallback(y=>{if(y)return f.find(j=>j.sessionId===y||j.ideId===y||j.tabKey===y||j.ideType===y||j.agentType===y)},[f]);return{activeChatTab:c,setActiveChatTab:h,activeConv:b,conversations:f,extensionTabs:m,hasExtensions:m.length>0,resolveConversationByTarget:u}}function oo({activeConv:t,ideEntry:s,ides:n,connectionStates:r,actionLogs:i,localUserMessages:o,sendDaemonCommand:c,setLocalUserMessages:h,setActionLogs:l,isStandalone:f,userName:d,onOpenHistory:x,onConversationChange:b,onClose:m}){var R;const[u,y]=a.useState("split"),[j,g]=a.useState(()=>t.streamSource==="native"?"native":t.tabKey),p=a.useMemo(()=>s||n.find(L=>L.id===t.ideId),[t.ideId,s,n]),I=a.useMemo(()=>ge((p==null?void 0:p.type)||""),[p==null?void 0:p.type]),{conversations:P,extensionTabs:S,hasExtensions:C}=io({ideData:p,allIdes:n,connectionStates:r,localUserMessages:o,ideName:I||"IDE",preferredTabKey:t.streamSource==="native"?"native":t.tabKey});a.useEffect(()=>{g(t.streamSource==="native"?"native":t.tabKey)},[t.streamSource,t.tabKey]);const v=a.useMemo(()=>j==="native"?P.find(L=>L.streamSource==="native")||t:P.find(L=>L.tabKey===j)||t,[t,P,j]),N=v.daemonId||((R=v.ideId)==null?void 0:R.split(":")[0])||v.ideId,E=Pt({sendDaemonCommand:c,activeConv:v,setLocalUserMessages:h,setActionLogs:l,isStandalone:f}),{connScreenshot:B,screenshotUsage:K,handleRemoteAction:M}=En({doId:N,ideId:v.ideId,ideType:v.ideType,connState:v.connectionState||"new",viewMode:u,instanceId:p==null?void 0:p.instanceId}),w=a.useMemo(()=>i.filter(L=>L.ideId===v.tabKey),[i,v.tabKey]);a.useEffect(()=>{b==null||b(v)},[v,b]),a.useEffect(()=>{const L=Y=>{Y.key==="Escape"&&m()};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[m]);const A=a.useCallback(L=>{L.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:A,children:[e.jsxs("div",{className:"dashboard-remote-dialog-header",children:[e.jsxs("div",{className:"dashboard-remote-dialog-title-block",children:[e.jsxs("div",{className:"dashboard-remote-dialog-title",children:[e.jsx(Ae,{size:16}),e.jsx("span",{children:v.displayPrimary||v.agentName||"Remote"})]}),e.jsxs("div",{className:"dashboard-remote-dialog-subtitle",children:[e.jsx("span",{children:v.displaySecondary}),v.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"dashboard-remote-dialog-dot",children:"·"}),e.jsx("span",{children:v.machineName})]})]})]}),e.jsxs("div",{className:"dashboard-remote-dialog-actions",children:[["split","remote"].map(L=>e.jsx("button",{className:`btn btn-secondary btn-sm dashboard-remote-dialog-mode${u===L?" is-active":""}`,onClick:()=>y(L),title:L==="split"?"Split view":"Remote only",children:L==="split"?"⊞":e.jsx(Ae,{size:14})},L)),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>x(v),title:"Chat History",children:e.jsx(ts,{size:14})}),e.jsx("button",{className:"btn btn-primary btn-sm",onClick:m,children:"Close"})]})]}),e.jsxs("div",{className:`dashboard-remote-dialog-body view-${u}`,children:[u!=="remote"&&e.jsxs("div",{className:"dashboard-remote-dialog-chat",children:[e.jsx(ao,{hasExtensions:C,ideName:I||"IDE",activeChatTab:j,extensionTabs:S,onSelectTab:g}),e.jsx(rn,{activeConv:v,onModalButton:E.handleModalButton}),e.jsx(ns,{activeConv:v,ideEntry:p,handleSendChat:E.handleSendChat,isSendingChat:E.isSendingChat,handleFocusAgent:E.handleFocusAgent,isFocusingAgent:E.isFocusingAgent,actionLogs:w,userName:d})]}),e.jsx("div",{className:"dashboard-remote-dialog-remote",children:e.jsx(nn,{addLog:()=>{},connState:v.connectionState||"new",connScreenshot:B,screenshotUsage:K,transportType:v.transport,onAction:M})})]})]})})}function co({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 lo({historyModalOpen:t,historyTargetConv:s,ides:n,isHistoryCreatingChat:r,isHistoryRefreshingHistory:i,onCloseHistory:o,onNewHistoryChat:c,onSwitchHistorySession:h,onRefreshHistory:l,remoteDialogConv:f,remoteDialogIdeEntry:d,connectionStates:x,actionLogs:b,localUserMessages:m,sendDaemonCommand:u,setLocalUserMessages:y,setActionLogs:j,isStandalone:g,userName:p,onOpenRemoteHistory:I,onRemoteConversationChange:P,onCloseRemoteDialog:S,cliStopDialogOpen:C,activeConv:v,onCancelCliStop:N,onStopCliNow:E,onSaveCliAndStop:B,toasts:K,onDismissToast:M,onClickToast:w,showOnboarding:A,onCloseOnboarding:R}){return e.jsxs(e.Fragment,{children:[t&&s&&e.jsx(xa,{activeConv:s,ides:n,isCreatingChat:r,isRefreshingHistory:i,onClose:o,onNewChat:c,onSwitchSession:h,onRefreshHistory:l}),f&&e.jsx(oo,{activeConv:f,ideEntry:d,ides:n,connectionStates:x,actionLogs:b,localUserMessages:m,sendDaemonCommand:u,setLocalUserMessages:y,setActionLogs:j,isStandalone:g,userName:p,onOpenHistory:I,onConversationChange:P,onClose:S}),C&&v&&ve(v)&&!ye(v)&&e.jsx(co,{activeConv:v,onCancel:N,onStopNow:E,onSaveAndStop:B}),e.jsx(un,{toasts:K,onDismiss:M,onClickToast:w}),A&&e.jsx(ro,{onClose:R})]})}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(Js,{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=dt(o,{fallbackId:o.id}),h=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]}),h==="upgrading"?e.jsx("span",{className:"text-[10px] animate-pulse",style:{color:"var(--status-warning)"},children:"upgrading…"}):h==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):h==="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 ho(){var ls;const{sendCommand:t}=De(),s=es(),n=ot(),[r,i]=ur(),o=r.get("activeTab"),c=((ls=s.state)==null?void 0:ls.openRemoteForTabKey)||null,h=rs(),{updateIdeChats:l,screenshotMap:f,setScreenshotMap:d}=h,x=h.ides||[],[b,m]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),u=h.toasts||[],y=h.setToasts||(()=>{}),j=h.wsStatus||"connected",g=h.isConnected??!0,p=h.connectionStates||{},I=h.showReconnected||!1,{groupAssignments:P,setGroupAssignments:S,focusedGroup:C,setFocusedGroup:v,groupActiveTabIds:N,setGroupActiveTabIds:E,groupTabOrders:B,setGroupTabOrders:K,groupSizes:M,setGroupSizes:w,isMobile:A,hasHydratedStoredLayout:R,hydrateStoredLayout:L}=yi(),[Y,V]=a.useState(!1),[q,Q]=a.useState(!1),[re]=a.useState(()=>kn()),[H,ie]=a.useState([]),[G,ae]=a.useState({}),[te,O]=a.useState({}),[D,$]=a.useState(null);lt("Dashboard",{ideCount:x.length,toastCount:u.length,focusedGroup:C,groupCount:Object.keys(P).length,localMessageTabs:Object.keys(G).length,actionLogCount:H.length});const k=x.find(be=>be.type==="adhdev-daemon"),F=(k==null?void 0:k.detectedIdes)||[],z=!!k,ne=(k==null?void 0:k.terminalBackend)||null,{hiddenTabs:le,toggleTab:oe}=Sn(),{chatIdes:ce,conversations:J,visibleConversations:se,visibleTabKeys:Z,resolveConversationByTarget:_}=li({ides:x,connectionStates:p,localUserMessages:G,clearedTabs:te,hiddenTabs:le}),{containerRef:W,normalizedGroupAssignments:T,numGroups:U,isSplitMode:X,groupedConvs:ee,moveTabToGroup:de,closeGroup:pe,handleResizeStart:he,splitTabRelative:ke}=Ci({groupAssignments:P,setGroupAssignments:S,setFocusedGroup:v,setGroupActiveTabIds:E,setGroupTabOrders:K,groupSizes:M,setGroupSizes:w,isMobile:A,visibleConversations:se,visibleTabKeys:Z}),ue=a.useMemo(()=>{var Ce,Ue;if(!A){if(D){const Be=J.find(Wt=>Wt.tabKey===D);if(Be)return Be}return se[0]}const be=N[C];if(be){const Be=J.find(Wt=>Wt.tabKey===be);if(Be)return Be}return((Ce=ee[C])==null?void 0:Ce[0])||((Ue=ee[0])==null?void 0:Ue[0])},[D,A,N,C,J,ee,se]),{requestedDesktopTabKey:Ne,requestedMobileTabKey:ut,consumeRequestedActiveTab:ht}=di({isMobile:A,urlActiveTab:o,resolveConversationByTarget:_,setSearchParams:i}),{remoteDialogConv:Ye,remoteDialogIdeEntry:Xe,remoteDialogActiveConv:Bt,setRemoteDialogActiveConv:Kt,openRemoteDialog:Pn,closeRemoteDialog:$n}=ji({isMobile:A,location:s,navigate:n,requestedRemoteTabTarget:c,requestedDesktopTabKey:Ne,conversations:J,ides:x,resolveConversationByTarget:_}),cs=Bt||Ye||ue,Dn=a.useMemo(()=>se,[se]),mt=A&&re==="chat";ri({visibleConversations:se,clearedTabs:te,setClearedTabs:O,setActionLogs:ie}),ui({ides:x,sendDaemonCommand:t,setToasts:y,setLocalUserMessages:ae,resolveConversationByTarget:_});const{isRefreshingHistory:Bn,handleLaunchIde:Kn,handleRefreshHistory:Wn}=Ss({sendDaemonCommand:t,activeConv:ue,updateIdeChats:l,setToasts:y,setLocalUserMessages:ae,setClearedTabs:O}),{isCreatingChat:On,isRefreshingHistory:zn,handleSwitchSession:Fn,handleNewChat:Un,handleRefreshHistory:Hn}=Ss({sendDaemonCommand:t,activeConv:cs,updateIdeChats:l,setToasts:y,setLocalUserMessages:ae,setClearedTabs:O});vi({urlActiveTab:A&&!mt?o:null,conversations:J,resolveConversationByTarget:_,normalizedGroupAssignments:T,hasHydratedStoredLayout:A&&!mt?R:!0,hydrateStoredLayout:A&&!mt?L:()=>{},setGroupActiveTabIds:E,setFocusedGroup:v,setSearchParams:i,historyModalOpen:Y,activeConv:ue,isRefreshingHistory:Bn,ides:x,handleRefreshHistory:Wn});const pt=a.useCallback(async be=>{if(!ue||!ve(ue)||ye(ue))return;const Ce=ue.ideType||ue.agentType||"",Ue=ue.ideId||ue.daemonId||"";try{await t(Ue,"stop_cli",{cliType:Ce,targetSessionId:ue.sessionId,mode:be})}catch(Be){console.error("Stop CLI failed:",Be)}},[ue,t]),Vn=a.useCallback(async()=>{var Ce;if(!ue||!ve(ue)||ye(ue))return;if((Ce=ue.resume)!=null&&Ce.supported){Q(!0);return}const be=ue.ideType||ue.agentType||"CLI";window.confirm(`Stop ${be}?
|
|
58
|
-
This will terminate the CLI process.`)&&await pt("hard")},[ue,pt]),qn=a.useCallback(()=>{!ue||!ve(ue)||ye(ue)||!ue.sessionId||window.dispatchEvent(new CustomEvent("adhdev:fit-cli-terminal",{detail:{sessionId:ue.sessionId}}))},[ue]),{versionMismatchDaemons:Yn,appVersion:Xn,versionBannerDismissed:Gn,setVersionBannerDismissed:Jn,upgradingDaemons:Zn,handleBannerUpgrade:Qn}=Ii({ides:x,sendDaemonCommand:t});return e.jsxs("div",{className:"page-dashboard flex-1 min-h-0 bg-bg-primary text-text-primary flex flex-col overflow-hidden",children:[e.jsx(ha,{wsStatus:j,showReconnected:I}),e.jsx(ma,{terminalBackend:ne,isStandalone:z}),!Gn&&e.jsx(uo,{daemons:Yn,targetVersion:Xn,upgradingDaemons:Zn,onUpgrade:Qn,onDismiss:()=>Jn(!0)}),e.jsx(no,{showMobileChatMode:mt,isMobile:A,activeConv:ue,chatIdes:ce,wsStatus:j,isConnected:g,onOpenHistory:be=>{be&&Kt(be),V(!0)},onOpenRemote:Pn,onFitCli:qn,onStopCli:Vn,mobileChatConversations:Dn,ides:x,actionLogs:H,sendDaemonCommand:t,setLocalUserMessages:ae,setActionLogs:ie,isStandalone:z,userName:h.userName,requestedMobileTabKey:ut,onRequestedMobileTabConsumed:ht,containerRef:W,isSplitMode:X,numGroups:U,groupSizes:M,groupedConvs:ee,clearedTabs:te,screenshotMap:f,setScreenshotMap:d,focusedGroup:C,setFocusedGroup:v,moveTabToGroup:de,splitTabRelative:ke,closeGroup:pe,handleResizeStart:he,detectedIdes:F,handleLaunchIde:Kn,groupActiveTabIds:N,setGroupActiveTabIds:E,groupTabOrders:B,setGroupTabOrders:K,toggleHiddenTab:oe,visibleConversations:se,requestedDesktopTabKey:Ne,onRequestedDesktopTabConsumed:ht,onDesktopActiveTabChange:$}),e.jsx("style",{children:`
|
|
59
|
-
body { overflow: hidden; overscroll-behavior: none; }
|
|
60
|
-
`}),e.jsx(lo,{historyModalOpen:Y,historyTargetConv:cs,ides:x,isHistoryCreatingChat:On,isHistoryRefreshingHistory:zn,onCloseHistory:()=>V(!1),onNewHistoryChat:Un,onSwitchHistorySession:Fn,onRefreshHistory:Hn,remoteDialogConv:Ye,remoteDialogIdeEntry:Xe,connectionStates:p,actionLogs:H,localUserMessages:G,sendDaemonCommand:t,setLocalUserMessages:ae,setActionLogs:ie,isStandalone:z,userName:h.userName,onOpenRemoteHistory:be=>{be&&Kt(be),V(!0)},onRemoteConversationChange:Kt,onCloseRemoteDialog:$n,cliStopDialogOpen:q,activeConv:ue,onCancelCliStop:()=>Q(!1),onStopCliNow:async()=>{Q(!1),await pt("hard")},onSaveCliAndStop:async()=>{Q(!1),await pt("save")},toasts:u,onDismissToast:be=>y(Ce=>Ce.filter(Ue=>Ue.id!==be)),onClickToast:be=>{if(be.targetKey){const Ce=_(be.targetKey);Ce&&v(T.get(Ce.tabKey)??0)}},showOnboarding:b,onCloseOnboarding:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}m(!1)}})]})}function mo({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:i}){const[o,c]=a.useState([]),[h,l]=a.useState(null),[f,d]=a.useState(null),[x,b]=a.useState(!1),[m,u]=a.useState(!1),[y,j]=a.useState(!1),[g,p]=a.useState([]),[I,P]=a.useState([]),[S,C]=a.useState(null),[v,N]=a.useState(!1),[E,B]=a.useState(""),K=a.useRef(null),M=a.useCallback(D=>{K.current=D},[]),w=a.useCallback((D,$,k=!1)=>{c(F=>[...F.slice(-100),{timestamp:Date.now(),level:D,message:$}]),setTimeout(()=>{var F;return(F=i.current)==null?void 0:F.scrollIntoView({behavior:"smooth"})},100),k&&Pe.showToast($,D==="error"||D==="warn"?"warning":"success")},[i]),A=a.useCallback(async(D,$)=>{var k;if(!t||h)return!1;l(D),w("info",`Launching ${ge(D)}${$!=null&&$.workspace?` in ${$.workspace}`:""}...`);try{const F={ideType:D,enableCdp:!0};(k=$==null?void 0:$.workspace)!=null&&k.trim()?F.workspace=$.workspace.trim():$!=null&&$.useDefaultWorkspace&&(F.useDefaultWorkspace=!0);const z=await n(t,"launch_ide",F);return w(z!=null&&z.success?"info":"error",z!=null&&z.success?`${ge(D)} launched`:`Failed: ${z==null?void 0:z.error}`,!0),!!(z!=null&&z.success)}catch(F){return w("error",`Launch error: ${F.message}`,!0),!1}finally{l(null)}},[t,h,w,n]),R=a.useCallback(async D=>{if(!t)return{success:!1};const{cliType:$,dir:k,workspaceId:F,useDefaultWorkspace:z,useHome:ne,argsStr:le,model:oe}=D;if(!$)return w("warn","Select a CLI or ACP provider first",!0),{success:!1};const ce=le?le.split(/\s+/).filter(Boolean):void 0,J=(k==null?void 0:k.trim())||(F?"(saved id)":z?"(default workspace)":ne?"(home)":"");w("info",`Launching ${$}${J?` in ${J}`:""}${oe?` (model: ${oe})`:""}...`),d($);try{const se={cliType:$,cliArgs:ce,initialModel:oe||void 0};k!=null&&k.trim()?se.dir=k.trim():F?se.workspaceId=F:z?se.useDefaultWorkspace=!0:ne&&(se.useHome=!0);const Z=await n(t,"launch_cli",se),_=(Z==null?void 0:Z.result)||Z;return Z!=null&&Z.success?(w("info",`${$} launched`,!0),(_==null?void 0:_.launchSource)==="home"?w("info","📂 Running in home directory (explicit choice)"):(_==null?void 0:_.launchSource)==="defaultWorkspace"&&w("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:_==null?void 0:_.sessionId}):(w("error",`Failed: ${(Z==null?void 0:Z.error)||(_==null?void 0:_.error)}`,!0),(Z==null?void 0:Z.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&C({cliType:$,argsStr:le,model:oe}),{success:!1,sessionId:_==null?void 0:_.sessionId})}catch(se){return w("error",`Launch error: ${se.message}`,!0),{success:!1}}finally{d(null)}},[t,w,n]),L=a.useCallback(async(D,$,k,F)=>t?D?$.trim()?R({cliType:D,dir:$,argsStr:k,model:F}):(C({cliType:D,argsStr:k,model:F}),{success:!1}):(w("warn","Select a provider",!0),{success:!1}):{success:!1},[t,w,R]),Y=a.useCallback(async(D,$,k)=>{if(t&&window.confirm(`Stop ${D}?
|
|
61
|
-
This will terminate the process.`))try{const F=await n(t,"stop_cli",{cliType:D,dir:$,targetSessionId:k});F!=null&&F.success?w("info",`${D} stopped`,!0):w("error",`Stop failed: ${(F==null?void 0:F.error)||"Unknown error"}`,!0)}catch(F){w("error",`Stop failed: ${F.message}`,!0)}},[t,w,n]),V=a.useCallback(async D=>{try{await n(D.daemonId,"restart_ide",{ideType:D.type}),w("info",`${ge(D.type)} restart initiated`,!0)}catch($){w("error",`Restart failed: ${$.message}`,!0)}},[w,n]),q=a.useCallback(async D=>{if(window.confirm(`Stop ${ge(D.type)}?
|
|
62
|
-
This will disconnect CDP and optionally kill the process.`))try{const $=await n(D.daemonId,"stop_ide",{ideType:D.type,killProcess:!0});$!=null&&$.success?w("info",`${ge(D.type)} stopped`,!0):w("error",`Stop failed: ${($==null?void 0:$.error)||"Unknown error"}`,!0)}catch($){w("error",`Stop failed: ${$.message}`,!0)}},[w,n]),Q=a.useCallback(async()=>{if(t)try{const D=await n(t,"detect_ides",{});w("info",`Found ${((D==null?void 0:D.result)||[]).length} IDE(s)`,!0)}catch(D){w("error",`Detection failed: ${D.message}`,!0)}},[t,w,n]),re=a.useCallback(async()=>{if(t){b(!0);try{const D=await n(t,"get_recent_workspaces",{});D!=null&&D.success&&Array.isArray(D==null?void 0:D.result)&&P(D.result)}catch(D){w("error",`Failed: ${D.message}`)}finally{b(!1)}}},[t,w,n]),H=a.useCallback(async D=>{if(!(!t||!D.trim())){u(!0);try{const $=await n(t,"workspace_add",{path:D.trim()});$!=null&&$.success?w("info",`Workspace added: ${D.trim()}`):w("error",($==null?void 0:$.error)||"workspace_add failed")}catch($){w("error",$.message)}finally{u(!1)}return!0}},[t,w,n]),ie=a.useCallback(async D=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){u(!0);try{const $=await n(t,"workspace_remove",{id:D});$!=null&&$.success?w("info","Workspace removed",!0):w("error",($==null?void 0:$.error)||"workspace_remove failed",!0)}catch($){w("error",$.message,!0)}finally{u(!1)}}},[t,w,n]),G=a.useCallback(async D=>{var $;if(t){u(!0);try{const k=await n(t,"workspace_set_default",D===null?{clear:!0}:{id:D});if(k!=null&&k.success){w("info",D?"Default workspace updated":"Default workspace cleared",!0);const F=typeof k.defaultWorkspacePath=="string"?k.defaultWorkspacePath:"";F&&(($=K.current)==null||$.call(K,F))}else w("error",(k==null?void 0:k.error)||"workspace_set_default failed",!0)}catch(k){w("error",k.message,!0)}finally{u(!1)}}},[t,w,n]),ae=a.useCallback(async D=>{var k;if(!t||!D.trim())return;const $=D.trim();u(!0);try{const F=await n(t,"workspace_set_default",{path:$});F!=null&&F.success?(w("info","Default workspace set from history"),(k=K.current)==null||k.call(K,$)):w("error",(F==null?void 0:F.error)||"Could not set default (path missing on disk?)")}catch(F){w("error",F.message)}finally{u(!1)}},[t,w,n]),te=a.useCallback(async()=>{var D;if(t){j(!0);try{const $=await n(t,"get_cli_history",{}),k=($==null?void 0:$.history)??((D=$==null?void 0:$.result)==null?void 0:D.history);$!=null&&$.success&&Array.isArray(k)&&p(k)}catch{}j(!1)}},[t,n]),O=a.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:E}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:E})}catch(D){w("warn",`Live nickname updated, but account sync failed: ${D.message}`)}w("info",`Nickname set to "${E||"(cleared)"}"`),N(!1)}catch(D){w("error",`Failed: ${D.message}`)}},[t,E,s,w,r,n]);return{logs:o,launchingIde:h,launchingAgentType:f,loadingWorkspaces:x,workspaceBusy:m,loadingHistory:y,cliHistory:g,recentWorkspaces:I,launchPick:S,setLaunchPick:C,editingNickname:v,setEditingNickname:N,nicknameInput:E,setNicknameInput:B,addLog:w,handleLaunchIde:A,runLaunchCliCore:R,handleLaunchCli:L,handleStopCli:Y,handleRestartIde:V,handleStopIde:q,handleDetectIdes:Q,handleLoadRecentWorkspaces:re,handleWorkspaceAdd:H,handleWorkspaceRemove:ie,handleWorkspaceSetDefault:G,handleWorkspaceResumePath:ae,loadCliHistory:te,handleSaveNickname:O,setOnDefaultWorkspaceChanged:M}}function po(t){const s=Math.floor((Date.now()-t)/1e3);return s<45?"just now":s<3600?`${Math.floor(s/60)}m ago`:s<86400?`${Math.floor(s/3600)}h ago`:`${Math.floor(s/86400)}d ago`}function xo({machine:t,ideSessions:s,cliSessions:n,acpSessions:r,actions:i,isDashboardHidden:o,onToggleDashboardVisibility:c}){const{workspaceBusy:h,handleWorkspaceAdd:l,handleWorkspaceRemove:f,handleWorkspaceSetDefault:d}=i,[x,b]=a.useState(""),m=t.availableMem??t.freeMem,u=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-m)/t.totalMem*100))):0,y=t.loadavg[0]||0,j=[...t.workspaceActivity||[]].sort((p,I)=>I.lastUsedAt-p.lastUsedAt).slice(0,5),g=[...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(xt,{icon:e.jsx(Qs,{size:16}),label:"Uptime",value:ea(t.uptime)}),e.jsx(xt,{icon:e.jsx(Ae,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(xt,{icon:e.jsx(en,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(xt,{icon:e.jsx(Ar,{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(ps,{value:Math.min(Math.round(y/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${y.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(ps,{value:u,max:100,label:"Memory",color:"#3b82f6",detail:`${bs(t.totalMem-m)} / ${bs(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(qt,{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:h,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:x,disabled:h,onChange:p=>b(p.target.value),onKeyDown:p=>p.key==="Enter"&&void(async()=>{await l(x)&&b("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:h,onClick:async()=>{await l(x)&&b("")},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:Xt(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:h,onClick:()=>void f(p.id),children:"Remove"})]},p.id))}),j.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-[10px] text-text-muted uppercase tracking-wide font-semibold mb-2",children:"Recent activity"}),e.jsx("div",{className:"space-y-1.5",children:j.map(p=>e.jsxs("div",{className:"flex items-center gap-2 text-[11px] rounded-lg border border-border-subtle bg-bg-primary px-2.5 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-text-primary truncate",children:Xt(p.path)}),e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:p.path,children:p.path})]}),e.jsxs("span",{className:"text-[10px] text-text-muted shrink-0",children:[p.kind?`${p.kind} · `:"",po(p.lastUsedAt)]})]},`${p.path}:${p.lastUsedAt}`))})]})]}),g.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:g.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 Es=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],fo=[{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 bo({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[i,o]=a.useState("config"),[c,h]=a.useState("codex-cli"),[l,f]=a.useState([]),[d,x]=a.useState(""),[b,m]=a.useState([]),[u,y]=a.useState(""),j=a.useRef(null),g=a.useRef(null),p=N=>{f(E=>E.includes(N)?E.filter(B=>B!==N):[...E,N])},I=()=>f([...Es]),P=()=>f([]);a.useEffect(()=>{var N;(N=j.current)==null||N.scrollIntoView({behavior:"smooth"})},[b]),a.useEffect(()=>()=>{g.current&&clearInterval(g.current)},[]);const S=a.useCallback(()=>{g.current&&clearInterval(g.current),g.current=setInterval(async()=>{try{const N=await n(t,"provider_auto_fix_status",{providerType:s.type});(N==null?void 0:N.running)===!1&&i==="running"&&(o("done"),m(E=>[...E,`
|
|
63
|
-
✅ Auto-fix completed!`]),g.current&&clearInterval(g.current))}catch{}},3e3)},[t,s.type,n,i]),C=async()=>{if(l.length!==0){o("running"),m(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${l.join(", ")}`,d?`💬 Comment: ${d}`:"",""]),y("");try{const N=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:c,...d?{comment:d}:{}});N!=null&&N.success&&(N!=null&&N.started||N!=null&&N.running)?(m(E=>[...E,"✅ Agent started. Monitoring progress..."]),S()):(o("error"),y((N==null?void 0:N.error)||"Failed to start auto-fix"))}catch(N){o("error"),y((N==null?void 0:N.message)||"Connection failed")}}},v=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),m(N=>[...N,`
|
|
64
|
-
⚠️ Auto-fix cancelled.`]),o("done"),g.current&&clearInterval(g.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:r,children:e.jsxs("div",{className:"w-full max-w-[560px] max-h-[85vh] overflow-hidden rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:s.icon||"🔧"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-text-primary",children:["Auto-Fix: ",s.displayName]}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"AI agent will implement provider scripts"})]})]}),e.jsx("button",{onClick:r,className:"text-text-muted hover:text-text-primary text-lg leading-none",children:"×"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[i==="config"&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"AI Agent"}),e.jsx("div",{className:"flex gap-2",children:fo.map(N=>e.jsxs("button",{onClick:()=>h(N.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===N.value?N.color+"66":"var(--border-subtle)",background:c===N.value?N.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===N.value?N.color:"var(--text-primary)"},children:N.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:N.desc})]},N.value))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"Scripts to Fix"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:I,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:P,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:Es.map(N=>e.jsxs("button",{onClick:()=>p(N),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(N)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:l.includes(N)?"rgba(139,92,246,0.08)":"transparent",color:l.includes(N)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(N)?"☑ ":"☐ ",N]},N))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:["Additional Instructions ",e.jsx("span",{className:"text-text-muted font-normal",children:"(optional)"})]}),e.jsx("textarea",{value:d,onChange:N=>x(N.target.value),placeholder:"e.g. Also search buttons inside Shadow DOM, preserve code block formatting in readChat...",rows:2,className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] resize-none placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]})]}),(i==="running"||i==="done"||i==="error")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Agent Output"}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-[#0d0d0d] p-3 font-mono text-[11px] leading-relaxed text-text-secondary overflow-y-auto",style:{maxHeight:320,minHeight:200},children:[b.map((N,E)=>e.jsx("div",{className:N.startsWith("✅")?"text-green-400":"",style:N.startsWith("❌")||N.startsWith("⚠")?{color:"var(--status-warning)"}:void 0,children:N},E)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:j})]}),u&&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:u})]})]}),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:C,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:v,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([]),y("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function go({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:i}){var S;const o=s.filter(C=>C.category==="ide"),[c,h]=a.useState(((S=o[0])==null?void 0:S.type)||""),[l,f]=a.useState(""),[d,x]=a.useState(""),[b,m]=a.useState(!1),[u,y]=a.useState(""),[j,g]=a.useState(!1),p=C=>{const v=C.toLowerCase().replace(/[^a-z0-9-]/g,"");f(v),(!d||d===I(l))&&x(I(v))},I=C=>C.split("-").map(v=>v.charAt(0).toUpperCase()+v.slice(1)).join(" "),P=async()=>{if(!(!l||!d||!c)){m(!0),y("");try{const C=await n(t,"provider_clone",{type:l,name:d,category:"ide",location:"user",cloneFrom:c});C!=null&&C.success||C!=null&&C.created?(g(!0),i==null||i(l)):y((C==null?void 0:C.error)||"Failed to create provider")}catch(C){y((C==null?void 0:C.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:C=>C.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-text-primary",children:"✨ Create User Provider"}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"Clone an upstream IDE provider to customize"})]}),e.jsx("div",{className:"px-5 py-4 flex flex-col gap-4",children:j?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"text-3xl mb-2",children:"🎉"}),e.jsx("h3",{className:"text-[14px] font-semibold text-text-primary",children:"Provider Created!"}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:[e.jsx("code",{className:"text-violet-400",children:l})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",l,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",l]})," or use Auto-Fix to implement scripts."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Base Provider"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:o.map(C=>e.jsxs("button",{onClick:()=>h(C.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===C.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:c===C.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:C.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===C.type?"#a78bfa":"var(--text-secondary)"},children:C.displayName})]},C.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:C=>p(C.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:C=>x(C.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"})]}),u&&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:u})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:j?e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:P,disabled:!l||!d||b,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||b?.4:1},children:b?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function yo({machineId:t,providers:s,sendDaemonCommand:n}){const[r,i]=a.useState([]),[o,c]=a.useState(!1),[h,l]=a.useState(null),[f,d]=a.useState("all"),[x,b]=a.useState(null),[m,u]=a.useState(!1),y=a.useCallback(async()=>{var g;if(t){c(!0);try{const p=await n(t,"get_provider_settings",{}),I=(p==null?void 0:p.result)||p;if(p!=null&&p.success&&(I!=null&&I.settings)){const P=[];for(const[S,C]of Object.entries(I.settings)){const v=s.find(N=>N.type===S);P.push({type:S,displayName:(v==null?void 0:v.displayName)||S,icon:(v==null?void 0:v.icon)||"",category:(v==null?void 0:v.category)||"unknown",schema:C,values:((g=I.values)==null?void 0:g[S])||{}})}P.sort((S,C)=>S.category.localeCompare(C.category)||S.displayName.localeCompare(C.displayName)),i(P)}}catch{}c(!1)}},[t,s,n]);a.useEffect(()=>{r.length===0&&y()},[]);const j=async(g,p,I)=>{l(`${g}.${p}`),i(P=>P.map(S=>S.type===g?{...S,values:{...S.values,[p]:I}}:S));try{const P=await n(t,"set_provider_setting",{providerType:g,key:p,value:I});P!=null&&P.success||y()}catch{y()}l(null)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Filter"}),["all","acp","cli","ide","extension"].map(g=>e.jsx("button",{onClick:()=>d(g),className:`machine-btn text-[10px] px-2 py-0.5 ${f===g?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:g.toUpperCase()},g))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>u(!0),className:"machine-btn text-[10px] bg-green-500/[0.06] border-green-500/20 text-green-400 hover:bg-green-500/[0.12]",children:"✨ Create Provider"}),e.jsx("button",{onClick:y,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),f!=="all"&&r.filter(g=>g.category===f).length>1&&(()=>{const g=r.filter(S=>S.category===f),p=new Map;for(const S of g)for(const C of S.schema){if(C.type!=="boolean")continue;const v=p.get(C.key),N=!!(S.values[C.key]??C.default);v?(v.onCount+=N?1:0,v.total+=1):p.set(C.key,{label:C.label||C.key,onCount:N?1:0,total:1})}const I=[...p.entries()].filter(([,S])=>S.total===g.length);if(I.length===0)return null;const P=async(S,C)=>{for(const v of g)await j(v.type,S,C)};return e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-500/[0.04] border border-violet-500/10 mb-4",children:[e.jsxs("div",{className:"text-[10px] text-violet-400 font-semibold uppercase tracking-wider mb-2",children:["Bulk — Apply to all ",f.toUpperCase()," providers (",g.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:I.map(([S,C])=>{const v=C.onCount===C.total,N=C.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:C.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",C.onCount,"/",C.total,")"]}),e.jsx("button",{onClick:()=>void P(S,!0),disabled:v,className:`machine-btn text-[9px] px-1.5 py-px ${v?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void P(S,!1),disabled:N,className:`machine-btn text-[9px] px-1.5 py-px ${N?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},S)})})]})})(),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(g=>f==="all"||g.category===f).map(g=>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:g.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:g.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:g.category==="acp"?"rgba(139,92,246,0.08)":g.category==="cli"?"rgba(59,130,246,0.08)":g.category==="ide"?"rgba(34,197,94,0.08)":"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:g.category==="acp"?"#a78bfa":g.category==="cli"?"#60a5fa":g.category==="ide"?"#86efac":"var(--status-warning)"},children:g.category}),g.category==="ide"&&e.jsx("button",{onClick:()=>b(s.find(p=>p.type===g.type)||{type:g.type,displayName:g.displayName,icon:g.icon,category:g.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:g.schema.map(p=>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:[p.label||p.key,h===`${g.type}.${p.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),p.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:p.description})]}),e.jsx("div",{className:"shrink-0",children:p.type==="boolean"?e.jsx("button",{onClick:()=>j(g.type,p.key,!(g.values[p.key]??p.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:g.values[p.key]??p.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:g.values[p.key]??p.default?21:3}})}):p.type==="number"?e.jsx("input",{type:"number",value:g.values[p.key]??p.default??0,min:p.min,max:p.max,onChange:I=>{const P=parseInt(I.target.value)||0;p.min!==void 0&&P<p.min||p.max!==void 0&&P>p.max||j(g.type,p.key,P)},className:"machine-input w-20 text-center text-[11px]"}):p.type==="select"&&p.options?e.jsx("select",{value:g.values[p.key]??p.default??"",onChange:I=>j(g.type,p.key,I.target.value),className:"machine-input text-[11px]",children:p.options.map(I=>e.jsx("option",{value:I,children:I},I))}):e.jsx("input",{type:"text",value:g.values[p.key]??p.default??"",onBlur:I=>j(g.type,p.key,I.target.value),className:"machine-input w-[120px] text-[11px]"})})]},p.key))})]},g.type))}),x&&e.jsx(bo,{machineId:t,provider:x,sendDaemonCommand:n,onClose:()=>b(null)}),m&&e.jsx(go,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>u(!1),onCreated:()=>{u(!1),y()}})]})}function vo({machineId:t,sendDaemonCommand:s}){const[n,r]=a.useState([]),[i,o]=a.useState(0),[c,h]=a.useState(!0),[l,f]=a.useState("debug"),d=a.useRef(null),x=a.useRef(!1);return a.useEffect(()=>{if(!t||!c)return;const b=async()=>{try{const u=await s(t,"get_logs",{count:200,minLevel:l,since:i}),y=(u==null?void 0:u.result)||u;if(u!=null&&u.success&&Array.isArray(y==null?void 0:y.logs)&&y.logs.length>0){r(g=>[...g,...y.logs.map(I=>({timestamp:I.ts,level:I.level,message:`[${I.category}] ${I.message}`}))].slice(-300));const j=Math.max(...y.logs.map(g=>g.ts));o(j)}}catch{}};b();const m=setInterval(b,3e3);return()=>clearInterval(m)},[t,c,i,l,s]),a.useEffect(()=>{if(c&&n.length>0){const b=x.current?"smooth":"instant";setTimeout(()=>{var m;(m=d.current)==null||m.scrollIntoView({behavior:b}),x.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(b=>e.jsx("button",{onClick:()=>{f(b),r([]),o(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${l===b?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:b.toUpperCase()},b))]}),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:()=>h(!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((b,m)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:b.level==="error"?"#ef4444":b.level==="warn"?"var(--status-warning)":b.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(b.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:b.level==="error"?"#ef4444":b.level==="warn"?"var(--status-warning)":b.level==="debug"?"#475569":"#8b5cf6"},children:b.level==="error"?"ERR":b.level==="warn"?"WRN":b.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:b.message})]},m)),e.jsx("div",{ref:d})]})]})}function jo({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 Ls({children:t}){return e.jsx("div",{className:"machine-command-section-title",children:t})}function wo({machineEntry:t,providers:s,recentSessions:n,onUpgradeDaemon:r,onOpenLogs:i,onOpenRecent:o,onOpenWorkspace:c,onGoTab:h}){const l=t.detectedIdes||[],f=s.filter(u=>u.category==="cli"),d=s.filter(u=>u.category==="acp"),x=n.slice(0,4),b=[l.length>0?{id:"ide",kind:"ide",label:"IDE"}:null,f.length>0?{id:"cli",kind:"cli",label:"CLI"}:null,d.length>0?{id:"acp",kind:"acp",label:"ACP"}:null].filter(Boolean),m=u=>u==="ide"?"IDE":u==="cli"?"CLI":"ACP";return e.jsxs("div",{className:"machine-command-center",children:[x.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ls,{children:"Recent"}),e.jsx("div",{className:"machine-command-links",children:x.map(u=>e.jsxs("button",{type:"button",className:"machine-command-link",onClick:()=>o(u),children:[e.jsx("span",{className:"machine-command-link-title",children:u.label}),e.jsxs("span",{className:"machine-command-link-meta",children:[m(u.kind),u.subtitle?` · ${u.subtitle}`:""]})]},u.id))})]}),b.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ls,{children:"Start"}),e.jsx("div",{className:"machine-command-launch-grid",children:b.map(u=>e.jsxs("button",{type:"button",className:"machine-command-launch-btn",onClick:()=>c(u.kind),children:[e.jsx("span",{className:"machine-command-launch-title",children:u.label}),e.jsx("span",{className:"machine-command-launch-meta",children:"Choose workspace and provider"})]},u.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:()=>h("providers"),children:"Providers"}),e.jsx("button",{type:"button",className:"machine-command-secondary-link",onClick:()=>h("overview"),children:"System"})]})]})}function ko(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const No={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 Vt({category:t,machine:s,machineId:n,providers:r,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:h,isDashboardHidden:l,onToggleDashboardVisibility:f,initialWorkspaceId:d,initialWorkspacePath:x}){const b=ot(),{handleLaunchIde:m,handleLaunchCli:u,handleStopCli:y,handleRestartIde:j,handleStopIde:g,handleDetectIdes:p,cliHistory:I,loadingHistory:P,loadCliHistory:S,launchingIde:C,launchingAgentType:v}=c,[N,E]=a.useState(null),B=a.useCallback(T=>{T&&b({pathname:"/",search:`?activeTab=${encodeURIComponent(T)}`})},[b]),K=No[t],M=t==="ide",w=t==="acp",A=r.filter(T=>T.category===t),R=new Map(A.map(T=>[T.type,T.displayName||T.type])),[L,Y]=a.useState(""),[V,q]=a.useState(""),[Q,re]=a.useState(""),[H,ie]=a.useState(x?"__custom__":d||s.defaultWorkspaceId||""),[G,ae]=a.useState(x||""),[te,O]=a.useState([]),D=te.filter(T=>!i.some(U=>U.type===T&&Se(U.status)!=="stopped")),$=a.useRef({});a.useEffect(()=>{!L&&A.length>0&&Y(A[0].type)},[L,A.length]),a.useEffect(()=>{s.defaultWorkspaceId&&!H&&ie(s.defaultWorkspaceId)},[s.defaultWorkspaceId]),a.useEffect(()=>{if(x){ie("__custom__"),ae(x);return}d&&(ie(d),ae(""))},[d,x]);const k=(()=>{if(H==="__custom__")return G.trim();if(!H)return"";const T=(s.workspaces||[]).find(U=>U.id===H);return(T==null?void 0:T.path)||""})(),F=a.useCallback(T=>{const U=$.current[T];U&&(clearTimeout(U),delete $.current[T]),O(X=>X.filter(ee=>ee!==T))},[]),z=a.useCallback(T=>{if(!T)return;O(X=>X.includes(T)?X:[...X,T]);const U=$.current[T];U&&clearTimeout(U),$.current[T]=setTimeout(()=>{O(X=>X.filter(ee=>ee!==T)),delete $.current[T]},2e4)},[]);a.useEffect(()=>{for(const T of i)Se(T.status)!=="stopped"&&F(T.type)},[i,F]),a.useEffect(()=>()=>{Object.values($.current).forEach(clearTimeout),$.current={}},[]);const[ne,le]=a.useState({}),[oe,ce]=a.useState(null);a.useEffect(()=>{if(!M||!n||!h)return;(async()=>{try{const U=await h(n,"get_ide_extensions",{}),X=(U==null?void 0:U.result)||U;X!=null&&X.success&&(X!=null&&X.ideExtensions)&&le(X.ideExtensions)}catch{}})()},[M,n,h]);const J=T=>M?ge(T.type):t==="cli"?T.cliName:T.acpName,se=M?s.detectedIdes||[]:[],Z=()=>{(async()=>{if(M){await m(L,k?{workspace:k}:void 0)&&z(L);return}const T=await u(L,k,V||void 0,w&&Q||void 0);T.success&&(z(L),T.sessionId&&B(T.sessionId))})()},_=T=>{M?g(T):y(T.type,T.workspace,T.id)},W=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:H,onChange:T=>{ie(T.target.value),T.target.value!=="__custom__"&&ae("")},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(T=>e.jsxs("option",{value:T.id,children:[T.id===s.defaultWorkspaceId?"⭐ ":"",Xt(T.path,T.label)]},T.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…"})]})}),H==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:G,onChange:T=>ae(T.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:H==="__custom__"?k?e.jsx("span",{className:"font-mono truncate block",title:k,children:k}):"Enter an absolute path to launch there.":k?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:H===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:k,children:k})]}):"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]}),W,M?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[se.map(T=>{const U=i.find(pe=>(pe.type||"").toLowerCase()===(T.type||"").toLowerCase()&&Se(pe.status)!=="stopped"),X=T.running||!!U,ee=!!U&&U.cdpConnected,de=te.includes(T.type||T.id||"");return e.jsxs("button",{onClick:()=>{if(ee&&U){b(`/dashboard?activeTab=${encodeURIComponent(U.id)}`,{state:{openRemoteForTabKey:U.id}});return}de||(async()=>await m(T.type||T.id||"",k?{workspace:k}:void 0)&&z(T.type||T.id||""))()},disabled:!!C||de,className:`machine-btn-primary flex items-center gap-1.5 ${X?"!border-green-500/30":""}`,style:{opacity:C&&C!==T.type?.4:1},children:[e.jsx("span",{children:o(T.type)}),X&&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)]"}),de?`⏳ Waiting for ${T.name||ge(T.type)}...`:ee?`Open ${T.name||ge(T.type)}`:C===T.type?"⏳ Launching...":`▶ ${T.name||ge(T.type)}`,X&&ee&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"running"})]},T.type)}),se.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:p,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(Mr,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:L,onChange:T=>Y(T.target.value),className:"machine-input",children:A.length>0?A.map(T=>e.jsxs("option",{value:T.type,children:[T.icon," ",T.displayName]},T.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),w&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:Q,onChange:T=>re(T.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:V,onChange:T=>q(T.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:Z,disabled:!!v,className:"machine-btn-primary",children:v===L?"⏳ Launching...":"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length+te.filter(T=>!i.some(U=>U.type===T&&Se(U.status)!=="stopped")).length,")"]}),i.length===0&&D.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:[D.map(T=>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(T)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:M?ge(T):R.get(T)||T}),e.jsx("div",{className:"text-[11px] text-text-muted",children:v===T?"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:${T}`)),i.map(T=>{const U=M?T:null,X=w?T:null,ee=!M&&!w?T:null,de=Se(T.status),pe=(l==null?void 0:l(T.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(T.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[J(T),(U==null?void 0:U.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",U.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:T.workspace||"—"}),(X==null?void 0:X.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",X.currentModel]}),(X==null?void 0:X.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",X.currentPlan]})]}),ee&&(ee.runtimeKey||ee.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[ee.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 ",ee.runtimeKey]}),e.jsx("button",{type:"button",className:"machine-btn text-[9px] px-1.5 py-px",onClick:()=>{var he;(he=navigator.clipboard)==null||he.writeText(`adhdev attach ${ee.runtimeKey}`),E(ee.runtimeKey||null),window.setTimeout(()=>{E(ke=>ke===ee.runtimeKey?null:ke)},1200)},children:N===ee.runtimeKey?"Copied":"Copy"})]}),ee.runtimeWriteOwner&&e.jsx("span",{style:{color:ee.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:ee.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:ko(ee.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[f&&e.jsx("button",{onClick:()=>f(T.id),className:`machine-btn ${pe?"text-zinc-300 border-zinc-500/30":"text-violet-400 border-violet-500/30"}`,title:pe?"Show on Dashboard":"Hide from Dashboard",children:pe?"Show":"Hide"}),e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${de==="stopped"?"bg-red-500/[0.08] text-red-500":de==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:de}),M&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>b(`/dashboard?activeTab=${encodeURIComponent(T.id)}`,{state:{openRemoteForTabKey:T.id}}),className:"machine-btn flex items-center gap-1",children:[e.jsx(Ae,{size:13})," Control"]}),e.jsx("button",{onClick:()=>j(T),className:"machine-btn",style:{color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"},children:"↻"})]}),w&&e.jsx("button",{onClick:()=>b(`/dashboard?activeTab=${encodeURIComponent(T.id)}`),className:"machine-btn",title:"View chat",children:e.jsx(ct,{size:14})}),ee&&de!=="stopped"&&e.jsxs("button",{onClick:()=>B(T.id),className:"machine-btn flex items-center gap-1",title:"Open terminal in dashboard",children:[e.jsx(Ae,{size:13})," Open"]}),de==="stopped"?e.jsx("button",{onClick:()=>{(async()=>{if(M){await m(T.type,T.workspace?{workspace:T.workspace}:void 0)&&z(T.type);return}const he=await u(T.type,T.workspace);he.success&&(z(T.type),he.sessionId&&B(he.sessionId))})()},disabled:te.includes(T.type),className:"machine-btn text-green-500 border-green-500/30",children:te.includes(T.type)?"⏳":"▶"}):e.jsx("button",{onClick:()=>_(T),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),U&&U.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:U.aiAgents.map(he=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${an(he.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[he.name," · ",Se(he.status)]},he.id))}),U&&(ne[U.type]||[]).length>0&&h&&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:(ne[U.type]||[]).map(he=>e.jsxs("button",{disabled:oe===`${U.type}.${he.type}`,onClick:async()=>{const ke=`${U.type}.${he.type}`;ce(ke);try{await h(n,"set_ide_extension",{ideType:U.type,extensionType:he.type,enabled:!he.enabled}),le(ue=>({...ue,[U.type]:(ue[U.type]||[]).map(Ne=>Ne.type===he.type?{...Ne,enabled:!Ne.enabled}:Ne)}))}catch(ue){console.error("Extension toggle failed:",ue)}finally{ce(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 ${he.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 ${he.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),he.name,e.jsx("span",{className:"text-[9px] font-normal",children:he.enabled?"ON":"OFF"})]},he.type))})]})]},T.id)})]}),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"History"}),e.jsx("button",{onClick:S,disabled:P,className:"machine-btn",children:P?"⏳":"↻ Load"})]}),(()=>{const T=new Set(A.map(X=>X.type)),U=I.filter(X=>(X.category||"cli")!==t?!1:t==="ide"?!0:T.has(X.cliType));return U.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:U.map((X,ee)=>{var de,pe;return e.jsxs("div",{onClick:()=>{Y(X.cliType),(X.workspace||X.dir)&&(ie("__custom__"),ae(X.workspace||X.dir)),q((X.cliArgs||[]).join(" ")),re(X.model||""),M&&(async()=>await m(X.cliType,X.workspace?{workspace:X.workspace}:void 0)&&z(X.cliType))()},className:"flex justify-between items-center px-2.5 py-1.5 rounded-md cursor-pointer bg-bg-glass border border-border-subtle text-xs transition-colors duration-150 hover:bg-bg-glass-hover",children:[e.jsxs("div",{className:"flex gap-1.5 items-center text-text-secondary",children:[e.jsx("span",{children:o(X.cliType)}),e.jsx("span",{children:((de=X.workspace||X.dir)==null?void 0:de.split("/").filter(Boolean).pop())||X.cliType||"root"}),X.model&&e.jsxs("span",{className:"text-cyan-500 text-[10px]",children:["model=",X.model]}),X.newWindow&&e.jsx("span",{className:"text-text-muted text-[10px]",children:"new window"}),((pe=X.cliArgs)==null?void 0:pe.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:X.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:X.timestamp?new Date(X.timestamp).toLocaleDateString():""})]},ee)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",K.label," launch history yet."]})})()]})]})}const Ps=[{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 So({machine:t,machineId:s,providers:n,ideSessions:r,cliSessions:i,acpSessions:o,actions:c,getIcon:h,initialCategory:l="ide",initialWorkspaceId:f,initialWorkspacePath:d,isDashboardHidden:x,onToggleDashboardVisibility:b,sendDaemonCommand:m}){var g;const[u,y]=a.useState(l);a.useEffect(()=>{y(l)},[l]);const j=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:Ps.map(p=>e.jsxs("button",{type:"button",className:`machine-workspace-section-tab${u===p.id?" active":""}`,onClick:()=>y(p.id),children:[e.jsx("span",{children:p.label}),e.jsx("span",{className:"machine-workspace-section-count",children:j[p.id]})]},p.id))}),e.jsx("div",{className:"machine-workspace-section-helper",children:(g=Ps.find(p=>p.id===u))==null?void 0:g.helper}),u==="ide"&&e.jsx(Vt,{category:"ide",machine:t,machineId:s,providers:n,managedEntries:r,getIcon:h,actions:c,isDashboardHidden:x,onToggleDashboardVisibility:b,sendDaemonCommand:m,initialWorkspaceId:f,initialWorkspacePath:d}),u==="cli"&&e.jsx(Vt,{category:"cli",machine:t,machineId:s,providers:n,managedEntries:i,getIcon:h,actions:c,isDashboardHidden:x,onToggleDashboardVisibility:b,initialWorkspaceId:f,initialWorkspacePath:d}),u==="acp"&&e.jsx(Vt,{category:"acp",machine:t,machineId:s,providers:n,managedEntries:o,getIcon:h,actions:c,isDashboardHidden:x,onToggleDashboardVisibility:b,initialWorkspaceId:f,initialWorkspacePath:d})]})}function Co({onNicknameSynced:t}={}){var re,H,ie,G,ae,te,O,D,$;const{id:s}=Os(),n=ot(),r=es(),{sendCommand:i}=De(),o=rs(),c=o.ides||[],h=o.initialLoaded??!0,{isHidden:l,toggleTab:f}=Sn(),d=c.find(k=>k.id===s&&k.daemonMode),[x,b]=a.useState("workspace"),[m,u]=a.useState("ide"),y=a.useRef(null),j=mo({machineId:s,registeredMachineId:(d==null?void 0:d.machineId)||null,sendDaemonCommand:i,onNicknameSynced:t,logsEndRef:y});a.useEffect(()=>Pe.onToast(F=>{o.setToasts(ne=>{if(ne.some(ce=>ce.message===F.message&&F.timestamp-ce.timestamp<3e3))return ne;const oe={id:F.id,message:F.message,type:F.type,timestamp:F.timestamp,targetKey:F.targetKey,actions:F.actions};return[...ne.slice(-4),oe]});const z=F.duration||5e3;setTimeout(()=>o.setToasts(ne=>ne.filter(le=>le.id!==F.id)),z)}),[o]);const g=((d==null?void 0:d.availableProviders)||[]).map(k=>({type:k.type,displayName:k.displayName,icon:k.icon,category:k.category})),p={};for(const k of g)p[k.type]=k.icon;const I=k=>p[k]||"",P=d?{id:d.id,hostname:on(d,{fallbackId:d.id}),platform:((re=d.machine)==null?void 0:re.platform)||"unknown",arch:((H=d.machine)==null?void 0:H.arch)||"",cpus:((ie=d.machine)==null?void 0:ie.cpus)||0,totalMem:((G=d.machine)==null?void 0:G.totalMem)||0,freeMem:((ae=d.machine)==null?void 0:ae.freeMem)||0,availableMem:(te=d.machine)==null?void 0:te.availableMem,loadavg:((O=d.machine)==null?void 0:O.loadavg)||[],uptime:((D=d.machine)==null?void 0:D.uptime)||0,release:(($=d.machine)==null?void 0:$.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,workspaceActivity:d.workspaceActivity||[]}:null,S=c.filter(k=>k.daemonId===s&&!k.daemonMode).filter(k=>!It(k)&&!et(k)).map(k=>({id:k.id,type:k.type,version:k.version||"",instanceId:k.instanceId||"",status:k.status,workspace:k.workspace||null,terminals:k.terminals||0,aiAgents:ia(k.aiAgents||k.agents||[]),activeChat:k.activeChat||null,chats:k.chats||[],childSessions:k.childSessions||[],cdpConnected:k.cdpConnected||!1,daemonId:s})),C=c.filter(k=>k.daemonId===s&&It(k)).map(k=>({id:k.id,type:k.type,cliName:k.cliName||k.type,status:k.status,workspace:k.workspace||"",activeChat:k.activeChat||null,daemonId:s})),v=c.filter(k=>k.daemonId===s&&et(k)).map(k=>({id:k.id,type:k.type,acpName:k.cliName||k.type,status:k.status,workspace:k.workspace||"",activeChat:k.activeChat||null,currentModel:k.currentModel,currentPlan:k.currentPlan,daemonId:s}));if(!P)return h?e.jsxs("div",{className:"p-10 text-center text-text-muted",children:[e.jsx("h2",{className:"text-text-primary",children:"Machine not found"}),e.jsx("p",{className:"mt-3",children:"The machine may be offline or not yet connected."}),e.jsx("button",{onClick:()=>n("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const N=dt(d,{fallbackId:P.id}),E="workspace",B=r.state,K=B==null?void 0:B.initialMachineTab,M=B==null?void 0:B.initialWorkspaceCategory,w=B==null?void 0:B.initialWorkspaceId,A=B==null?void 0:B.initialWorkspacePath,R=K==="ides"||K==="clis"||K==="acps"?"workspace":K||E,L=K==="ides"?"ide":K==="clis"?"cli":K==="acps"?"acp":M,Y=[...S.map(k=>{var F,z,ne,le,oe;return{id:k.id,sessionId:k.id,label:((F=k.activeChat)==null?void 0:F.title)||k.type,kind:"ide",providerType:k.type,subtitle:k.workspace||void 0,workspace:k.workspace||void 0,timestamp:((oe=(le=(ne=(z=k.activeChat)==null?void 0:z.messages)==null?void 0:ne.at)==null?void 0:le.call(ne,-1))==null?void 0:oe.timestamp)||0}}),...C.map(k=>{var F,z,ne,le,oe;return{id:k.id,sessionId:k.id,label:((F=k.activeChat)==null?void 0:F.title)||k.cliName,kind:"cli",providerType:k.type,subtitle:k.workspace||void 0,workspace:k.workspace||void 0,timestamp:((oe=(le=(ne=(z=k.activeChat)==null?void 0:z.messages)==null?void 0:ne.at)==null?void 0:le.call(ne,-1))==null?void 0:oe.timestamp)||0}}),...v.map(k=>{var F,z,ne,le,oe;return{id:k.id,sessionId:k.id,label:((F=k.activeChat)==null?void 0:F.title)||k.acpName,kind:"acp",providerType:k.type,subtitle:k.currentModel||k.workspace||void 0,workspace:k.workspace||void 0,currentModel:k.currentModel,timestamp:((oe=(le=(ne=(z=k.activeChat)==null?void 0:z.messages)==null?void 0:ne.at)==null?void 0:le.call(ne,-1))==null?void 0:oe.timestamp)||0}})].sort((k,F)=>F.timestamp-k.timestamp).map(({timestamp:k,...F})=>F),V=(d.recentSessions||[]).length>0?d.recentSessions.map(k=>({id:k.id,sessionId:k.sessionId||k.id,label:k.title||k.providerName||k.providerType,kind:k.kind,providerType:k.providerType,subtitle:k.currentModel||k.workspace||void 0,workspace:k.workspace,currentModel:k.currentModel})):Y,q=async k=>{if(k.sessionId){n(`/dashboard?activeTab=${encodeURIComponent(k.sessionId)}`);return}if(k.kind==="ide"&&k.providerType){await j.handleLaunchIde(k.providerType,k.workspace?{workspace:k.workspace}:void 0);return}if((k.kind==="cli"||k.kind==="acp")&&k.providerType){await j.runLaunchCliCore({cliType:k.providerType,dir:k.workspace||"",model:k.kind==="acp"?k.currentModel:void 0});return}u(k.kind),b("workspace")};a.useEffect(()=>{b(R)},[E,R,P.id]),a.useEffect(()=>{L&&u(L)},[L,P.id]);const Q=[{id:"workspace",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ae,{size:14})," Workspace"]}),count:S.length+C.length+v.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Et,{size:14})," Providers"]})},{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Tr,{size:14})," System"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ir,{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:[j.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:j.nicknameInput,onChange:k=>j.setNicknameInput(k.target.value),onKeyDown:k=>{k.key==="Enter"&&j.handleSaveNickname(),k.key==="Escape"&&j.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:j.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>j.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{j.setEditingNickname(!0),j.setNicknameInput(P.machineNickname||"")},title:"Click to set nickname",children:N}),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:[P.platform," · ",P.arch]}),e.jsxs("span",{children:[P.cpus," cores"]}),(d==null?void 0:d.version)&&e.jsxs("span",{children:["v",d.version]}),P.p2p.available&&e.jsxs("span",{children:["P2P ",P.p2p.state==="connected"?"connected":P.p2p.state]}),P.cdpConnected&&e.jsx("span",{children:"CDP ready"}),P.machineNickname&&e.jsx("span",{className:"text-text-muted opacity-80 shrink-0",children:P.hostname})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:Q.map(k=>e.jsxs("button",{onClick:()=>b(k.id),className:`machine-tab shrink-0${x===k.id?" active":""}`,children:[k.label,k.count!==void 0&&e.jsx("span",{className:"tab-count",children:k.count})]},k.id))})]}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:"machine-page-shell",children:e.jsxs("div",{className:"machine-tab-panel",children:[x==="workspace"&&e.jsxs("div",{className:"machine-workspace-panel",children:[e.jsx(wo,{machineEntry:d,providers:g,recentSessions:V,onUpgradeDaemon:async()=>{try{await i(s,"daemon_upgrade",{})}catch{}},onOpenLogs:()=>b("logs"),onOpenRecent:q,onOpenWorkspace:k=>{u(k),b("workspace")},onGoTab:b}),e.jsx(So,{machine:P,machineId:s,providers:g,ideSessions:S,cliSessions:C,acpSessions:v,actions:j,getIcon:I,initialCategory:m,initialWorkspaceId:w,initialWorkspacePath:A,isDashboardHidden:l,onToggleDashboardVisibility:f,sendDaemonCommand:i})]}),x==="providers"&&e.jsx(yo,{machineId:s,providers:g,sendDaemonCommand:i}),x==="overview"&&e.jsx(xo,{machine:P,ideSessions:S,cliSessions:C,acpSessions:v,actions:j,isDashboardHidden:l,onToggleDashboardVisibility:f}),x==="logs"&&e.jsx(vo,{machineId:s,sendDaemonCommand:i})]})})}),j.launchPick&&P&&e.jsx(jo,{machine:P,launchPick:j.launchPick,actions:j}),e.jsx(un,{toasts:o.toasts||[],onDismiss:k=>o.setToasts(F=>F.filter(z=>z.id!==k)),onClickToast:k=>{k.targetKey}}),e.jsx("style",{children:`
|
|
65
|
-
@keyframes toast-in {
|
|
66
|
-
from { opacity: 0; transform: translateX(40px); }
|
|
67
|
-
to { opacity: 1; transform: translateX(0); }
|
|
68
|
-
}
|
|
69
|
-
`})]})}function Io(){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 h=[],l=[],f=[],d=[];Object.values(c.providers||{}).forEach(b=>{const m={name:b.name||"Unknown",status:b.status||"Stable",details:b.details||"Community Provider"};b.category==="ide"?h.push(m):b.category==="cli"?l.push(m):b.category==="extension"?f.push(m):b.category==="acp"&&d.push(m)});const x=(b,m)=>{const u={Stable:1,Beta:2,WIP:3},y=u[b.status]||99,j=u[m.status]||99;return y!==j?y-j:b.name.localeCompare(m.name)};s({ide:h.sort(x),cli:l.sort(x),ext:f.sort(x),acp:d.sort(x)})}).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(Gs,{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(ss,{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(Qs,{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((h,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:h.name}),e.jsx("td",{className:"py-3 px-4",children:i(h.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:h.details})]},l))})]})});return n?e.jsx(Mt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Ct,{}),widthClassName:"max-w-5xl",children:e.jsx(as,{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(Mt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Ct,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(we,{title:"Registry overview",description:"Support status is loaded from the shared provider registry used across OSS and cloud surfaces.",children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"IDEs"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ide.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"CLI"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.cli.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"Extensions"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ext.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"ACP"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.acp.length})]})]})}),e.jsx(we,{title:"IDE support",icon:e.jsx(Ae,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(we,{title:"Standalone CLI agents",icon:e.jsx(en,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(we,{title:"AI extensions",icon:e.jsx(it,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(we,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(it,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class Mo{constructor(){fe(this,"adapters",new Map);fe(this,"states",new Map);fe(this,"ptyCallbacks",new Set);fe(this,"runtimeListeners",new Map);fe(this,"screenshotCallbacks",new Map);fe(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 Ee=new Mo;function To(){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 $s=To(),Ds=3e3,Ao=3e4;let Le=null,Ro=0;const _t=new Map;let We=null,rt=null;function _o(t){return t==="connected"?"connected":t}async function St(t,s,n){const r=wa(t,n||{}),i=Le;if(i&&i.readyState===WebSocket.OPEN){const c=`req_${++Ro}_${Date.now()}`;return new Promise((h,l)=>{const f=setTimeout(()=>{_t.delete(c),l(new Error(`WS command timeout: ${s}`))},3e4);_t.set(c,{resolve:d=>{clearTimeout(f),h(d)},reject:d=>{clearTimeout(f),l(d)}}),i.send(JSON.stringify({type:"command",requestId:c,data:{type:s,payload:r.payload}}))})}const o=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:r.payload})});if(!o.ok)throw new Error(`HTTP ${o.status}`);return o.json()}class Eo{constructor(s){fe(this,"daemonId");fe(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Le==null?void 0:Le.readyState)===WebSocket.OPEN}get connectionState(){return(Le==null?void 0:Le.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return St(this.daemonId,s,n)}async sendInput(s,n){return St(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,We&&(clearInterval(We),We=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await St(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());Ee.emitScreenshot(this.daemonId,i)}}catch{}};n(),We=setInterval(n,2e3)}stopScreenshots(s){We&&(clearInterval(We),We=null)}}let Me=null;function Lo(t){return(!Me||Me.daemonId!==t)&&(Me=new Eo(t)),Me}function Po({children:t}){const s=a.useRef(us()),n=us();s.current=n;const{setUserName:r}=at(),i=a.useRef(r);i.current=r;const[,o]=a.useState("disconnected"),c=a.useCallback((b,m)=>{o(b),rt==null||rt(b,m)},[]),h=a.useRef(null),l=a.useRef(),f=a.useRef(Ds),d=a.useRef(!0),x=a.useRef(!1);return a.useEffect(()=>{d.current=!0,x.current=!1;function b(){var y,j;if(!d.current||((y=h.current)==null?void 0:y.readyState)===WebSocket.OPEN||((j=h.current)==null?void 0:j.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${$s}...`);let u;try{u=new WebSocket($s)}catch(g){console.error("[Standalone WS] Failed to create WebSocket:",g),m();return}h.current=u,u.onopen=()=>{if(!d.current){u.close();return}c("connected"),f.current=Ds,console.log("[Standalone WS] Connected")},Le=u,u.onmessage=g=>{var p;try{const I=JSON.parse(g.data);if((I.type==="command_result"||I.type==="error")&&I.requestId){const P=_t.get(I.requestId);P&&(_t.delete(I.requestId),I.type==="error"?P.reject(new Error(((p=I.data)==null?void 0:p.message)||"Command failed")):P.resolve(I.data));return}if(I.type==="pty_output"){Ee.emitPtyOutput(I.cliId,I.data);return}if(I.type==="runtime_snapshot"){Ee.emitRuntimeSnapshot(I.sessionId,typeof I.text=="string"?I.text:"",typeof I.seq=="number"?I.seq:0,!!I.truncated);return}if(I.type==="status"||I.type==="initial_state"){const P=I.data;if(!P)return;const{injectEntries:S,markLoaded:C}=s.current,v=P.id||"standalone",N=Lo(v);Ee.register(v,N),Ee.setState(v,"connected"),c("connected",v),Ee.emitStatus(v,P);const E=va(P,{daemonId:v});E.length>0&&S(E),C(),P.userName&&i.current&&i.current(P.userName)}}catch(I){console.error("[Standalone WS] Parse error:",I)}},u.onclose=()=>{d.current&&(Me==null||Me.stopScreenshots(),Me&&Ee.setState(Me.daemonId,"disconnected"),c("disconnected"),h.current=null,m())},u.onerror=g=>{x.current||!d.current||console.warn("[Standalone WS] Error, will reconnect:",g)}}function m(){if(!d.current)return;clearTimeout(l.current);const u=f.current;console.log(`[Standalone WS] Reconnecting in ${u}ms...`),l.current=setTimeout(()=>{f.current=Math.min(f.current*1.5,Ao),b()},u)}return b(),()=>{d.current=!1,x.current=!0,clearTimeout(l.current),h.current&&(h.current.onerror=null,h.current.onclose=null,h.current.close(),h.current=null,Le=null),Me&&(Me.stopScreenshots(),Ee.unregister(Me.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function $o({children:t}){const[s,n]=a.useState("disconnected"),[r,i]=a.useState(null);a.useEffect(()=>(rt=(c,h)=>{n(c),h&&i(h)},()=>{rt=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",h=_o(s),l={};return r&&(l[r]=h),l.standalone=h,{wsStatus:s,isConnected:c,connectionStates:l}},[s,r]);return e.jsx(gr,{connectionOverrides:o,children:e.jsx(Po,{children:t})})}const Do=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Vs,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Ys,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Et,{}),label:"Settings"}];function Bo({children:t}){const s=ot(),n=es(),[r,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),h=d=>{s(d),i(!1)},l=()=>{c(d=>{const x=!d;try{localStorage.setItem("sidebar-collapsed",x?"1":"0")}catch{}return x})},f=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:Do.map(d=>e.jsxs("div",{className:f(d.path),id:`nav-${d.id}`,onClick:()=>h(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(Ct,{})}),!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(Xs,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.7.38"]}),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 Ko=[{icon:e.jsx(Ys,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(ct,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Zs,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Ae,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(it,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Ct,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Wo=[{icon:e.jsx(tn,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(Vs,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(Lt,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Cr,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Nr,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Gs,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Oo=[{feature:"Agent chat relay",selfhost:!0,cloud:!0},{feature:"Live IDE screenshots",selfhost:!0,cloud:!0},{feature:"Remote IDE control",selfhost:!0,cloud:!0},{feature:"Multi-IDE monitoring",selfhost:!0,cloud:!0},{feature:"Extension and CLI agents",selfhost:!0,cloud:!0},{feature:"Access from any network",selfhost:!1,cloud:!0},{feature:"WebRTC P2P streaming",selfhost:!1,cloud:!0},{feature:"Mobile push notifications",selfhost:!1,cloud:!0},{feature:"REST API and webhooks",selfhost:!1,cloud:!0},{feature:"Team collaboration",selfhost:!1,cloud:!0},{feature:"Multi-machine burrows",selfhost:!1,cloud:!0},{feature:"SSO, RBAC, audit logs",selfhost:!1,cloud:!0}];function zo(){return e.jsxs(Mt,{icon:e.jsx(Xs,{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.38"]}),children:[e.jsx(we,{children:e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("div",{className:"text-[11px] font-semibold tracking-[0.18em] uppercase text-emerald-400 mb-2",children:"Self-hosted edition"}),e.jsx("h2",{className:"text-2xl font-semibold tracking-tight text-text-primary mb-2",children:"Keep the same dashboard experience, with the runtime fully on-device."}),e.jsx("p",{className:"text-sm text-text-muted leading-relaxed",children:"Standalone keeps the browser, daemon, screenshots, and control path on your own machine. It is the same core product shape as cloud, just without the remote networking and team layers."})]}),e.jsxs("div",{className:"grid gap-2 min-w-[220px]",children:[e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"Docs ↗"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"GitHub ↗"}),e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex justify-center no-underline",children:"Try Cloud ↗"})]})]})}),e.jsx(we,{title:"Included in standalone",description:"The local-first feature set available without the cloud control plane.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Ko.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(we,{title:"Compatible with",description:"Supported editors and agent surfaces exposed in the standalone dashboard.",children:e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:[{label:"IDEs",items:pn.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:fn.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:xn.map(t=>`${t.icon} ${t.name}`)}].map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4",children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-3 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1.5",children:t.items.map(s=>e.jsx("div",{className:"rounded-md border border-border-subtle bg-bg-card px-2.5 py-1.5 text-[12px] text-text-secondary",children:s},s))})]},t.label))})}),e.jsx(we,{title:"Cloud-only extras",description:"Capabilities that need the hosted control plane or team infrastructure.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Wo.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(we,{title:"Self-hosted vs Cloud",description:"The product split at a glance.",children:e.jsx("div",{className:"overflow-x-auto rounded-xl border border-border-subtle",children:e.jsxs("table",{className:"w-full text-[13px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary",children:[e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[110px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-violet-400 text-[11px] uppercase tracking-wider w-[110px]",children:"Cloud"})]})}),e.jsx("tbody",{children:Oo.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"bg-transparent",children:[e.jsx("td",{className:"px-4 py-2.5 text-text-secondary",children:t.feature}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:t.selfhost?e.jsx("span",{className:"text-emerald-500",children:"✓"}):e.jsx("span",{className:"text-text-muted opacity-40",children:"—"})}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})}),e.jsx(as,{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($r,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Fo(){const{ides:t}=at(),s=t.find(x=>x.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=De(),{userName:i}=at(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const h=x=>{const b=x.target.value.trim();s!=null&&s.id&&b!==i&&r(s.id,"set_user_name",{userName:b}).catch(console.error)},[l,f]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),d=x=>{f(x);try{localStorage.setItem("adhdev_sound",x?"1":"0")}catch{}};return e.jsxs(Mt,{icon:e.jsx(Et,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(Da,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(we,{title:"Daemon",description:"Connection health and local endpoints for the self-hosted runtime.",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-x-4 gap-y-2.5 text-sm",children:[e.jsx("span",{className:"text-text-muted",children:"Version"}),e.jsxs("span",{className:"font-mono text-xs",children:["v","0.7.38"]}),e.jsx("span",{className:"text-text-muted",children:"Status"}),e.jsx("span",{className:s?"text-green-400":"text-yellow-400",children:s?"● Running":"○ Not connected"}),e.jsx("span",{className:"text-text-muted",children:"WebSocket"}),e.jsx("span",{className:"font-mono text-xs",children:"ws://localhost:19222"}),e.jsx("span",{className:"text-text-muted",children:"HTTP"}),e.jsx("span",{className:"font-mono text-xs",children:"http://localhost:19280"})]})}),e.jsx(we,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:n.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:n.map(x=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${x.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:x.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:x.type})]},x.type))})}),e.jsx(we,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Ua,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(we,{title:"Appearance",description:"Match the rest of the dashboard with a single place for mode and theme.",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Mode"}),e.jsx(Ya,{})]}),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(si,{})]})]})}),e.jsx(we,{title:"Notifications",description:"Browser prompts and local sound cues for agent activity.",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Fa,{}),e.jsx($e,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pr,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:d})]})}),e.jsx(we,{title:"Profile",description:"How your name appears in local chat threads and dashboard views.",children:e.jsx("div",{className:"flex flex-col gap-3",children:e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-4 bg-bg-glass rounded-xl border border-border-subtle hover:border-border-default transition-colors",children:[e.jsxs("div",{className:"flex flex-col gap-1 pr-4 max-w-[500px]",children:[e.jsxs("span",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(Sr,{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:x=>c(x.target.value),onBlur:h,onKeyDown:x=>{x.key==="Enter"&&x.currentTarget.blur()}})]})})})]})}za();Za();const Uo=Us({baseUrl:""});function Bs(){const{ides:t}=at(),s=t.find(n=>{var r;return n.daemonMode||((r=n.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(qe,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(qe,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(qe,{to:"/dashboard",replace:!0})}function Ho(){const{id:t}=Os();return t?e.jsx(qe,{to:`/dashboard?activeTab=${encodeURIComponent(t)}`,replace:!0}):e.jsx(qe,{to:"/dashboard",replace:!0})}function Vo(){return e.jsx(hr,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(jr,{client:Uo,children:e.jsx($o,{children:e.jsx(kr,{value:{sendCommand:St,sendData:()=>!1},children:e.jsx(Bo,{children:e.jsxs(mr,{children:[e.jsx(_e,{path:"/dashboard",element:e.jsx(ho,{})}),e.jsx(_e,{path:"/ide/:id",element:e.jsx(Ho,{})}),e.jsx(_e,{path:"/machine",element:e.jsx(Bs,{})}),e.jsx(_e,{path:"/machines/:id",element:e.jsx(Co,{})}),e.jsx(_e,{path:"/machines",element:e.jsx(Bs,{})}),e.jsx(_e,{path:"/capabilities",element:e.jsx(Io,{})}),e.jsx(_e,{path:"/about",element:e.jsx(zo,{})}),e.jsx(_e,{path:"/settings",element:e.jsx(Fo,{})}),e.jsx(_e,{path:"*",element:e.jsx(qe,{to:"/dashboard",replace:!0})})]})})})})})})}ua({connectionManager:Ee});pr(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Vo,{})}));
|