@adhdev/daemon-standalone 0.7.37 → 0.7.39
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 +636 -810
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/index-BWB-uX0D.js +68 -0
- package/public/assets/index-B_p34HFn.css +1 -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-8URTNXS9.js +0 -69
- package/public/assets/index-CgzZlVZo.css +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-CEvJri7V.js","assets/vendor-CPghmr9Y.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var ar=Object.defineProperty;var ir=(t,s,n)=>s in t?ar(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var ye=(t,s,n)=>ir(t,typeof s!="symbol"?s+"":s,n);import{r as a,j as e,M as zs,a as Fs,b as or,c as cr,u as tt,t as lr,d as dr,e as ur,R as hr,D as mr,f as pr,g as xr,h as es,i as fr,k as Us,B as br,l as gr,m as Le,N as Qe,n as yr}from"./vendor-CPghmr9Y.js";import{_ as vr}from"./terminal-CEvJri7V.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 Hs=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}),Vs=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function ms(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 zt(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 jr(t,s){var c,h,d,x,u,f,p;const n=Date.now();if(s.length===0)return t.map(l=>({...l,_lastUpdate:n}));const r=new Map;for(const l of s)r.set(l.id,l);for(const l of t){const b=r.get(l.id);if(!b){r.set(l.id,{...l,_lastUpdate:n});continue}const v=ms(l),j=ms(b);if(v>j){const m=(c=l.chats)!=null&&c.length?l.chats:b.chats,g=zt(b,l,{...b,...l,chats:m,_lastUpdate:n});r.set(l.id,g)}else if(v<j){const m={};if(l.status&&l.status!==b.status&&(m.status=l.status),l.cdpConnected!==void 0&&(m.cdpConnected=l.cdpConnected),(h=l.chats)!=null&&h.length&&!((d=b.chats)!=null&&d.length)&&(m.chats=l.chats),l.machineNickname!==void 0&&l.machineNickname!==b.machineNickname&&(m.machineNickname=l.machineNickname),l.version!==void 0&&(m.version=l.version),l.serverVersion!==void 0&&(m.serverVersion=l.serverVersion),l.versionMismatch===!0&&(m.versionMismatch=!0),Object.keys(m).length>0){const g=zt(b,l,{...b,...m,_lastUpdate:b._lastUpdate});r.set(l.id,g)}}else{const m=l.timestamp||n,g=b._lastUpdate||b.timestamp||0;if(m>=g){const S=(x=l.chats)!=null&&x.length?l.chats:b.chats,E=zt(b,l,{...b,...l,chats:S,_lastUpdate:n});r.set(l.id,E)}else(u=l.chats)!=null&&u.length&&!((f=b.chats)!=null&&f.length)&&r.set(l.id,{...b,chats:l.chats})}}const i=new Set(t.map(l=>l.id)),o=new Set;for(const l of t){const b=l.daemonId||((p=l.id)==null?void 0:p.split(":")[0]);b&&o.add(b)}for(const[l,b]of r){const v=b.daemonId||l.split(":")[0];if(!o.has(v))continue;const j=n-(b._lastUpdate||b.timestamp||0);(b.transport==="pty"&&!i.has(l)&&j>1e4||b.transport==="acp"&&!i.has(l)&&j>1e4||b.transport==="cdp-page"&&!i.has(l)&&j>3e4)&&r.delete(l)}for(const[l,b]of r)n-(b._lastUpdate||b.timestamp||0)>3e5&&b.status!=="online"&&r.delete(l);return Array.from(r.values())}function wr(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 kr({children:t,connectionOverrides:s}){const[n,r]=a.useState([]),[i,o]=a.useState({}),[c,h]=a.useState(!1),[d,x]=a.useState([]),[u,f]=a.useState(void 0),p=a.useRef(n);a.useEffect(()=>{p.current=n},[n]);const l=a.useCallback((S,E)=>{r(y=>{let C=!1;const k=y.map(w=>w.id!==S||w.chats===E?w:(C=!0,{...w,chats:E}));return C?k:y})},[]),b=a.useCallback(S=>{r(E=>{const y=E.length===0?S:jr(S,E);return wr(E,y)?E:y})},[]),v=a.useCallback(()=>h(!0),[]),j=a.useMemo(()=>({injectEntries:b,markLoaded:v,getIdes:()=>p.current}),[b,v]),m=s,g=a.useMemo(()=>({ides:n,updateIdeChats:l,screenshotMap:i,setScreenshotMap:o,initialLoaded:c,toasts:d,setToasts:x,wsStatus:(m==null?void 0:m.wsStatus)??"connected",isConnected:(m==null?void 0:m.isConnected)??!0,connectionStates:(m==null?void 0:m.connectionStates)??{},connectionTransports:(m==null?void 0:m.connectionTransports)??{},showReconnected:(m==null?void 0:m.showReconnected)??!1,retryConnection:m==null?void 0:m.retryConnection,isP2PActive:(m==null?void 0:m.isP2PActive)??!1,p2pStates:(m==null?void 0:m.p2pStates)??{},userRole:m==null?void 0:m.userRole,userName:u,setUserName:f}),[n,l,i,c,d,m==null?void 0:m.wsStatus,m==null?void 0:m.isConnected,m==null?void 0:m.connectionStates,m==null?void 0:m.connectionTransports,m==null?void 0:m.showReconnected,m==null?void 0:m.retryConnection,m==null?void 0:m.isP2PActive,m==null?void 0:m.p2pStates,m==null?void 0:m.userRole,u]);return e.jsx(Vs.Provider,{value:j,children:e.jsx(Hs.Provider,{value:g,children:t})})}function ut(){return a.useContext(Hs)}function ps(){return a.useContext(Vs)}function qs(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 d=n==null?void 0:n(),x=i(h),u=h.startsWith("http")?new URL(x):new URL(x,typeof window<"u"?window.location.origin:"http://localhost");return d&&u.searchParams.set("token",d),!h.startsWith("http")&&!s?`${u.pathname}${u.search}${u.hash}`:u.toString()}async function c(h,d={}){const x={"Content-Type":"application/json",...d.headers||{}},u=n==null?void 0:n();u&&(x.Authorization=`Bearer ${u}`);const f=i(h),p=await fetch(f,{...d,headers:x});if(p.status===401)throw r==null||r(),new Error("Unauthorized");if(!p.ok){const l=await p.json().catch(()=>({error:p.statusText}));throw new Error(l.error||`API Error: ${p.status}`)}return p.json()}return{getDaemons:()=>c("/api/v1/daemons"),getDaemonStatus:h=>c(`/api/v1/daemons/${h}/status`),sendCommand:(h,d,x={})=>c(`/api/v1/daemons/${h}/command`,{method:"POST",body:JSON.stringify({type:d,payload:x})}),execTerminal:(h,d,x)=>c(`/api/v1/daemons/${h}/terminal`,{method:"POST",body:JSON.stringify({command:d,name:x})}),sendAgentMessage:(h,d,x)=>c(`/api/v1/shortcuts/${h}/chat`,{method:"POST",body:JSON.stringify({agentType:d,message:x})}),getAgentStatus:h=>c(`/api/v1/shortcuts/${h}/status`),approveAgent:(h,d,x)=>c(`/api/v1/shortcuts/${h}/approve`,{method:"POST",body:JSON.stringify({agentType:d,action:x?"approve":"reject"})}),getMuxState:h=>c(`/api/v1/mux/${encodeURIComponent(h)}/state`),getMuxSocketInfo:h=>c(`/api/v1/mux/${encodeURIComponent(h)}/socket-info`),controlMux:(h,d,x={})=>c(`/api/v1/mux/${encodeURIComponent(h)}/control`,{method:"POST",body:JSON.stringify({type:d,payload:x})}),getMuxEventsUrl:h=>o(`/api/v1/mux/${encodeURIComponent(h)}/events`),getRuntimeEventsUrl:h=>o(`/api/v1/runtime/${encodeURIComponent(h)}/events`),request:c}}const Nr=qs({baseUrl:"http://localhost:3847"}),Sr=a.createContext(Nr);function Cr({client:t,children:s}){return e.jsx(Sr.Provider,{value:t,children:s})}const Ir={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Ys=a.createContext(Ir);function Mr({value:t,children:s}){return e.jsx(Ys.Provider,{value:t,children:s})}function We(){return a.useContext(Ys)}const me={size:18};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("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 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.9",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}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("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 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("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 Rr({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 Ar({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 Mt({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 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:"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 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("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 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("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 Zs({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 ht({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 Ee({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 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:"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 _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("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function Yt({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 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("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 ns({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 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("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 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("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 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("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]})}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("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 sn({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 nn({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 Lr({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 Dr({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 Dt({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 Br({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 Kr({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 Or({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 Wr({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 zr(t){const n=t.split(`
|
|
3
|
+
`).map(h=>{if(!h.includes("\r"))return h;const d=h.split("\r").map(f=>f.trim()).filter(Boolean);if(d.length===0)return"";const x=d.filter(f=>f.startsWith("⏺"));if(x.length>0)return x[x.length-1];const u=d.filter(f=>!(/^[❯›>]\s*$/.test(f)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(f)&&f.length<40||/^[╭╰│├╮╯─═]+$/.test(f)));return u.length>0?u[u.length-1]:d[d.length-1]}).join(`
|
|
4
|
+
`).split(`
|
|
5
|
+
`),r={},i=[];let o=!1;for(const h of n){const d=h.trim();if(d===""){o=!1,i.push("");continue}if(/^❯\s*$/.test(d)||/^>\s*$/.test(d)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(d)||/^◐\s/.test(d)||/\/effort/.test(d)||/^⎿\s+(Tip|Note|Hint):/.test(d)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(d)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(d)||/Brewing[…\.]{0,3}\s*\d*$/i.test(d)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(d)||/^Auto-updating/i.test(d))continue;if(/^[⏺●·⏵]/.test(h)){const u=h.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(u)r[u[1]]=(r[u[1]]||0)+1;else{const f=h.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);f&&(r[f]=(r[f]||0)+1)}o=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(h)||/^[╭╰│├╮╯─]+/.test(d)||/^\s+[⊙✓✗○◎▸►✦]/.test(h)||o&&/^\s{2,}/.test(h))continue;o=!1;const x=h.replace(/^❯\s+/,"");i.push(x)}const c=i.join(`
|
|
6
|
+
`).replace(/\n{3,}/g,`
|
|
7
|
+
|
|
8
|
+
`).trim();return{toolCounts:r,textContent:c,hasTools:Object.keys(r).length>0}}function Xt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function Fr(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function Ze(t,s){const n=t,r=typeof n.content=="string"?n.content:Array.isArray(n.content)?n.content.map(o=>(o==null?void 0:o.text)||"").join(`
|
|
9
|
+
`):String(n.content||"");return[n.id?`id:${n.id}`:"",n._localId?`local:${n._localId}`:"",n._turnKey?`turn:${n._turnKey}`:"",typeof n.index=="number"?`msgIndex:${n.index}`:"",n.timestamp?`ts:${n.timestamp}`:"",n.role?`role:${n.role}`:"",r?`content:${r.slice(0,80)}`:"",`fallback:${s}`].filter(Boolean).join("|")}const xs=700,Ur=a.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(zs,{remarkPlugins:[Fs],children:s.text}),e.jsx("span",{className:"action-time",children:Xt(s.timestamp)})]})},(t,s)=>t.log===s.log),Hr=a.memo(function({message:s,receivedAt:n,agentName:r,userName:i,isCliMode:o,isExpanded:c,isTextExpanded:h,onToggleExpanded:d,onToggleTextExpanded:x}){var E;const u=(s.role||"").toLowerCase(),f=u==="user"||u==="human",p=s.kind||(u==="tool"?"tool":"standard"),l=typeof s.content=="string"?s.content:(s.content||[]).map(y=>y.text||"").join(`
|
|
10
|
+
`);if(p==="thought"){const y=((E=s.meta)==null?void 0:E.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(Dr,{size:13}),e.jsx("span",{children:y})]}),e.jsx("div",{className:"chat-msg-body",children:l})]})}if(p==="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:l.split(`
|
|
11
|
+
`)[0].slice(0,80)})]});if(p==="terminal"){const y=s.meta||{},C=y.isRunning?"⏳":"✅",k=y.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:k})]}),e.jsx("pre",{className:"chat-msg-body",children:l})]})}if(p==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:l.slice(0,100)});const b=!f&&o?zr(l):null,v=b?b.textContent:l,j=b?Object.entries(b.toolCounts):[],m=o&&!f&&!c&&v.length>xs,g=c?l:m&&!h?v.slice(0,xs):v,S=Fr(g);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${f?"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(([y,C])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",y,C>1?` ×${C}`:""]},y)),(b==null?void 0:b.hasTools)&&e.jsx("button",{onClick:d,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:c?"Collapse":"Original"}),!v&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Xt(n)})]}),(v||f)&&e.jsxs("div",{className:`chat-bubble ${f?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${v?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:f?i||"You":r}),n!=null&&e.jsx("span",{className:"chat-time",children:Xt(n)})]}),v&&e.jsx("div",{className:"chat-markdown",children:S?e.jsx(zs,{remarkPlugins:[Fs,or,cr],children:g}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:g})}),m&&e.jsx("button",{onClick:x,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:h?"Collapse ↑":`Show more (${Math.round(v.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),Vr=a.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:h="",receivedAtMap:d={},emptyState:x,onLoadMore:u,isLoadingMore:f,hasMoreHistory:p,hiddenLiveCount:l=0,loadError:b},v){var ee;const j=a.useRef(null),m=a.useRef(null),g=a.useRef(null),S=a.useRef(0),E=a.useRef(""),y=a.useRef(!1),C=a.useRef(null),k=a.useRef(!1),w=a.useRef(null),_=a.useRef(!1),[B,D]=a.useState(new Set),[P,N]=a.useState(new Set),A=a.useRef(!1),$=()=>{const O=j.current;return O?O.scrollHeight-O.scrollTop-O.clientHeight<200:!0},T=a.useCallback((O="auto")=>{const Y=j.current;Y&&Y.scrollTo({top:Y.scrollHeight,behavior:O})},[]),G=a.useCallback(()=>{var J;const O=j.current,Y=(J=window.getSelection)==null?void 0:J.call(window);if(!O||!Y||Y.rangeCount===0||Y.isCollapsed){_.current=!1;return}const H=Y.anchorNode,I=Y.focusNode;_.current=!!(H&&I&&O.contains(H)&&O.contains(I))},[]),L=a.useCallback((O="auto")=>{C.current!=null&&cancelAnimationFrame(C.current),C.current=requestAnimationFrame(()=>{C.current=null,T(O)})},[T]),R=s.length>0?`${s.length}:${(((ee=s[s.length-1])==null?void 0:ee.content)||"").length}`:"0:0";a.useEffect(()=>{const O=!y.current,Y=E.current!==h;if(E.current=h,O||Y){y.current=!0,A.current=!1,k.current=!0,_.current||L("auto"),S.current=s.length;return}s.length>S.current?!A.current&&!_.current&&L("auto"):$()&&!A.current&&!_.current&&L("auto"),S.current=s.length},[R,h,c,s.length,L]),a.useEffect(()=>()=>{C.current!=null&&cancelAnimationFrame(C.current),w.current!=null&&window.clearTimeout(w.current)},[]),a.useEffect(()=>{const O=m.current;if(!O)return;const Y=()=>{w.current!=null&&window.clearTimeout(w.current),w.current=window.setTimeout(()=>{k.current=!1,w.current=null},180)},H=new ResizeObserver(()=>{k.current&&(_.current||(L("auto"),Y()))});return H.observe(O),()=>{H.disconnect(),w.current!=null&&(window.clearTimeout(w.current),w.current=null)}},[L,h]),a.useImperativeHandle(v,()=>({scrollToBottom:(O="smooth")=>{T(O)}}),[T]),a.useEffect(()=>{const O=j.current;if(!O)return;let Y;const H=()=>{clearTimeout(Y),Y=setTimeout(()=>{A.current=!$()},50)};return O.addEventListener("scroll",H,{passive:!0}),()=>{O.removeEventListener("scroll",H),clearTimeout(Y)}},[]),a.useEffect(()=>(document.addEventListener("selectionchange",G),()=>document.removeEventListener("selectionchange",G)),[G]);const U=a.useRef(0),z=a.useRef(!1);a.useEffect(()=>{const O=j.current;if(!O||!z.current||U.current===0)return;const Y=O.scrollHeight-U.current;Y>0&&(O.scrollTop=Y),U.current=0,z.current=!1},[s.length]);const W=()=>{const O=j.current;O&&(U.current=O.scrollHeight),z.current=!0,u==null||u()},Q=a.useMemo(()=>{const O=s.map((J,q)=>({type:"message",data:J,index:q,ts:J.receivedAt||d[Ze(J,q)]||0}));if(!n||n.length===0)return O;const Y=[...n].sort((J,q)=>J.timestamp-q.timestamp).map((J,q)=>({type:"action",data:J,index:q,ts:J.timestamp})),H=[];let I=0;for(const J of O){for(;I<Y.length&&J.ts>0&&Y[I].ts<J.ts;)H.push(Y[I++]);H.push(J)}for(;I<Y.length;)H.push(Y[I++]);return H},[s,n,d]),V=l>0||!!p,ie=l>0?`↑ Show ${Math.min(l,80)} earlier messages${l>80?` (${l} hidden)`:""}`:b?`↻ ${b}`:"↑ Load older messages";return e.jsx("div",{ref:j,"data-chat-scroll":!0,className:"chat-container",children:e.jsxs("div",{ref:m,className:"chat-container-content",children:[f&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),V&&!f&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:W,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${b&&l===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:ie})}),Q.length===0&&!V&&(x||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),Q.map(O=>{if(O.type==="action"){const de=O.data;return e.jsx(Ur,{log:de},`action-${O.index}`)}const Y=O.data,H=O.index,I=Ze(Y,H),J=Y.receivedAt||d[I],q=`${h}-${I}`,te=B.has(q),ue=P.has(q);return e.jsx(Hr,{message:Y,receivedAt:J,agentName:r,userName:i,isCliMode:o,isExpanded:te,isTextExpanded:ue,onToggleExpanded:()=>D(de=>{const le=new Set(de);return te?le.delete(q):le.add(q),le}),onToggleTextExpanded:()=>N(de=>{const le=new Set(de);return ue?le.delete(q):le.add(q),le})},`msg-${I}`)}),c&&e.jsx("div",{className:"self-start chat-typing-wrapper",children:e.jsxs("div",{className:"typing-indicator",children:[e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("span",{className:"text-[11px] text-text-muted ml-1",children:"Agent generating..."})]})}),e.jsx("div",{className:"min-h-10",ref:g})]})})}),qr=a.memo(Vr,(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 fs=!1;const rn=a.forwardRef(({onInput:t,onResize:s,fontSize:n=13,readOnly:r=!1},i)=>{const o=a.useRef(null),[c,h]=a.useState(null),d=a.useRef([]),x=a.useRef(!1),u=a.useRef(!1),f=a.useRef(!1),p=()=>{const l=o.current;if(l){x.current&&(l.clear(),x.current=!1);for(const b of d.current)l.write(b);d.current=[],u.current&&(l.fit(),u.current=!1),f.current&&(l.bumpResize(),f.current=!1)}};return a.useImperativeHandle(i,()=>({write:l=>{o.current?o.current.write(l):d.current.push(l)},clear:()=>{o.current?o.current.clear():(d.current=[],x.current=!0)},fit:()=>{o.current?o.current.fit():u.current=!0},bumpResize:()=>{o.current?o.current.bumpResize():f.current=!0}}),[]),a.useEffect(()=>{if(!c)return;const l=requestAnimationFrame(()=>{var b;p(),(b=o.current)==null||b.fit()});return()=>cancelAnimationFrame(l)},[c]),a.useEffect(()=>{let l=!1;return vr(()=>import("./terminal-CEvJri7V.js").then(b=>b.i),__vite__mapDeps([0,1])).then(b=>{fs||(fs=!0,console.info("[CliTerminal] renderer module loaded: ghostty-web")),l||h(()=>b.GhosttyTerminalView)}).catch(b=>{console.error("[CliTerminal] failed to load terminal renderer",b)}),()=>{l=!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"}})});rn.displayName="CliTerminal";function bt({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 bs({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 Yr({cursorPos:t,viewportRef:s,imgRef:n}){var g;if(!t||!n.current)return null;const r=n.current,i=r.getBoundingClientRect(),o=(g=s.current)==null?void 0:g.getBoundingClientRect();if(!o)return null;const c=r.naturalWidth||i.width,h=r.naturalHeight||i.height,d=c/h,x=i.width/i.height;let u,f,p,l;d>x?(u=i.width,f=i.width/d,p=0,l=(i.height-f)/2):(f=i.height,u=i.height*d,p=(i.width-u)/2,l=0);const b=i.left-o.left+p+u*t.nx,v=i.top-o.top+l+f*t.ny,j=Math.max(8,Math.min(o.width-8,b)),m=Math.max(8,Math.min(o.height-8,v));return e.jsxs("div",{style:{position:"absolute",left:j-8,top:m-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 Xr({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:i,setIsMenuOpen:o,imeText:c,setImeText:h,handleImeSubmit:d,isConnActive:x,zoom:u,isMobile:f,mobileFillZoom:p,onZoomOut:l,onZoomReset:b,onZoomIn:v,transportType:j,screenshotUsage:m,lastActionStatus:g}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:S=>S.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(S=>!S),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:S=>S.stopPropagation(),onChange:S=>h(S.target.value),onKeyDown:S=>{d(S)},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(S=>!S),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${i?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⚙️"})})}),e.jsx("div",{className:"w-px h-[18px] bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:x?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:x?"#22c55e":"#eab308",boxShadow:x?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:x?"#22c55e":"#eab308"},children:x?"Connected":"WS"})]}),u>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(u*100),"%"]}),j==="direct"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#22c55e",background:"rgba(34,197,94,0.12)"},title:"Direct P2P connection",children:"Direct"}),j==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 12%, transparent)"},title:"TURN relay in use",children:"Relay"}),m&&m.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:m.budgetExhausted?"#ef4444":"#c4b5fd",background:m.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:m.budgetExhausted?"TURN blocked":`TURN ${m.dailyUsedMinutes}/${m.dailyBudgetMinutes}m`}),g&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:g})]})]}),i&&e.jsxs("div",{onTouchStart:S=>S.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",u<=(f?p:1)+.01?f?"FILL":"FIT":`${Math.round(u*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:S=>{S.stopPropagation(),l()},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:S=>{S.stopPropagation(),b()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:9,fontWeight:800,cursor:"pointer"},children:f?"FILL":"FIT"}),e.jsx("button",{onClick:S=>{S.stopPropagation(),v()},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 Gr({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 Jr(){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 gs(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 mt(t,s){const n=a.useRef(null),r=a.useRef(0);a.useEffect(()=>{if(!Jr())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,gs(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,gs(s[c])]))}),n.current=s})}function Zr({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:i,minZoom:o,zoomRef:c,panXRef:h,panYRef:d,setPanX:x,setPanY:u,setZoom:f,lastWheelTimeRef:p,onAction:l,setLastActionStatus:b,spawnRippleFromNormalized:v,clampPan:j,isMobile:m,mobileFillZoom:g}){const[S,E]=a.useState(null),y=a.useRef(null),C=a.useRef(null),k=a.useRef(null),w=a.useRef(!1),_=a.useRef(null),B=a.useRef(0),D=a.useRef(null),P=a.useRef(1),N=a.useRef({x:0,y:0}),A=a.useRef(!1),$=a.useRef(r),T=a.useRef(l),G=()=>{if(y.current)return;const U={nx:.5,ny:.5};y.current=U,E(U)};return a.useEffect(()=>{$.current=r,r==="mouse"&&G()},[r]),a.useEffect(()=>{T.current=l},[l]),a.useEffect(()=>{const U=t.current;if(!U)return;const z=O=>{if(!n.current)return null;const Y=n.current.getBoundingClientRect();return!Y.width||!Y.height?null:{nx:Math.max(0,Math.min(1,(O.clientX-Y.left)/Y.width)),ny:Math.max(0,Math.min(1,(O.clientY-Y.top)/Y.height))}},W=(O,Y)=>{if(!n.current)return{dnx:0,dny:0};const H=n.current,I=H.getBoundingClientRect(),J=H.naturalWidth||I.width,q=H.naturalHeight||I.height,te=J/q,ue=I.width/I.height;let de,le;return te>ue?(de=I.width,le=I.width/te):(le=I.height,de=I.height*te),{dnx:O/de,dny:Y/le}},Q=(O,Y,H)=>{if(H<=1.05)return;const I=-(O-.5)*100,J=-(Y-.5)*100,q=j(I,J,H);(Math.abs(q.x-h.current)>.1||Math.abs(q.y-d.current)>.1)&&(x(q.x),u(q.y),h.current=q.x,d.current=q.y)},V=O=>{const Y=s.current;if(Y&&O.target instanceof Node&&Y.contains(O.target))O.preventDefault();else return;if(O.touches.length===1){const H=O.touches[0];C.current={x:H.clientX,y:H.clientY,time:Date.now()},k.current={x:H.clientX,y:H.clientY},A.current||(w.current=!1),_.current=setTimeout(()=>{if(!w.current&&!A.current)if(w.current=!0,$.current==="mouse"){const I=y.current||{nx:.5,ny:.5};b("Right Click"),v(I.nx,I.ny,"right"),T.current("input_click",{...I,button:"right"}).catch(()=>{})}else{const I=z(H);I&&(b("Right Click"),v(I.nx,I.ny,"right"),T.current("input_click",{...I,button:"right"}).catch(()=>{}))}},500);return}if(O.touches.length===2){_.current&&clearTimeout(_.current),w.current=!0,A.current=!0;const H=O.touches[1].clientX-O.touches[0].clientX,I=O.touches[1].clientY-O.touches[0].clientY;D.current=Math.sqrt(H*H+I*I),P.current=c.current,N.current={x:(O.touches[0].clientX+O.touches[1].clientX)/2,y:(O.touches[0].clientY+O.touches[1].clientY)/2}}},ie=O=>{const Y=s.current;if(Y&&O.target instanceof Node&&Y.contains(O.target)&&O.preventDefault(),O.touches.length===1&&k.current){const H=O.touches[0],I=H.clientX-k.current.x,J=H.clientY-k.current.y;if(!w.current&&C.current){const q=H.clientX-C.current.x,te=H.clientY-C.current.y;Math.sqrt(q*q+te*te)>8&&(w.current=!0,_.current&&clearTimeout(_.current))}if(w.current)if($.current==="mouse"){const q=W(I,J),te=y.current||{nx:.5,ny:.5},ue=Math.max(0,Math.min(1,te.nx+q.dnx)),de=Math.max(0,Math.min(1,te.ny+q.dny));y.current={nx:ue,ny:de},E({nx:ue,ny:de}),b(`Cursor: ${Math.round(ue*100)}%, ${Math.round(de*100)}%`),Q(ue,de,c.current);const le=Date.now();le-p.current>=30&&(p.current=le,T.current("input_mouseMoved",{nx:ue,ny:de}).catch(()=>{}))}else if(c.current>1){const q=s.current;if(q){const te=q.clientWidth,ue=q.clientHeight,de=h.current+I/te*100,le=d.current+J/ue*100,Z=j(de,le,c.current);x(Z.x),u(Z.y),h.current=Z.x,d.current=Z.y}}else{const q=z(H);if(q){const te=Date.now();te-p.current>=40&&(p.current=te,b("Scroll"),T.current("input_wheel",{nx:q.nx,ny:q.ny,deltaX:Math.round(-I*2.5),deltaY:Math.round(-J*2.5)}).catch(()=>{}))}}k.current={x:H.clientX,y:H.clientY};return}if(O.touches.length===2&&D.current!==null){const H=O.touches[1].clientX-O.touches[0].clientX,I=O.touches[1].clientY-O.touches[0].clientY,q=Math.sqrt(H*H+I*I)/D.current,te=(O.touches[0].clientX+O.touches[1].clientX)/2,ue=(O.touches[0].clientY+O.touches[1].clientY)/2,de=te-N.current.x,le=ue-N.current.y,Z=Math.abs(q-1)>.03;if($.current==="mouse"){if(Z){const oe=Math.max(o,Math.min(5,P.current*q));f(oe),c.current=oe}else if(Math.abs(de)>2||Math.abs(le)>2){const oe=y.current||{nx:.5,ny:.5},M=Date.now();M-p.current>=30&&(p.current=M,b("Scroll"),T.current("input_wheel",{nx:oe.nx,ny:oe.ny,deltaX:Math.round(-de*3),deltaY:Math.round(-le*3)}).catch(()=>{}))}}else{const oe=Math.max(o,Math.min(5,P.current*q));f(oe),c.current=oe;const M=s.current;if(M&&oe>1){const X=M.clientWidth,se=M.clientHeight,ne=h.current+de/X*100,xe=d.current+le/se*100,be=j(ne,xe,oe);x(be.x),u(be.y),h.current=be.x,d.current=be.y}}N.current={x:te,y:ue}}},ee=O=>{var Y;if(_.current&&clearTimeout(_.current),D.current=null,O.touches.length===1&&A.current){const H=O.touches[0];C.current={x:H.clientX,y:H.clientY,time:Date.now()},k.current={x:H.clientX,y:H.clientY},w.current=!0;return}if(O.touches.length===0){if(A.current){A.current=!1,w.current=!1;return}if(O.changedTouches.length===1&&!w.current){const H=O.changedTouches[0],I=Date.now(),J=I-(((Y=C.current)==null?void 0:Y.time)||0);if(J<60||J>400){w.current=!1;return}if(C.current){const q=H.clientX-C.current.x,te=H.clientY-C.current.y;if(Math.sqrt(q*q+te*te)>12){w.current=!1;return}}if($.current==="mouse"){const q=y.current||z(H);q&&(b(`Click: ${Math.round(q.nx*100)}%, ${Math.round(q.ny*100)}%`),v(q.nx,q.ny,"left"),T.current("input_click",{...q}).catch(()=>{}))}else{const q=z(H);if(!q)return;I-B.current<300?(b("Double tap"),v(q.nx,q.ny,"double"),T.current("input_click",{...q,clickCount:2}).catch(()=>{}),B.current=0):(b(`Tap: ${Math.round(q.nx*100)}%, ${Math.round(q.ny*100)}%`),v(q.nx,q.ny,"left"),T.current("input_click",{...q}).catch(()=>{}),B.current=I)}}w.current=!1}};return U.addEventListener("touchstart",V,{passive:!1}),U.addEventListener("touchmove",ie,{passive:!1}),U.addEventListener("touchend",ee,{passive:!1}),()=>{U.removeEventListener("touchstart",V),U.removeEventListener("touchmove",ie),U.removeEventListener("touchend",ee),_.current&&clearTimeout(_.current)}},[t,s,n,o,c,h,d,x,u,f,p,b,v,j]),{cursorPos:S,cursorPosRef:y,handleToggleInputMode:()=>{i(U=>{const z=U==="touch"?"mouse":"touch";return z==="mouse"&&G(),z})},handleZoomReset:()=>{const U=m?g:1;f(U),c.current=U,x(0),u(0),h.current=0,d.current=0}}}function an({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:i,transportType:o}){const c=a.useRef(null),h=a.useRef(null),d=a.useRef(null),[x,u]=a.useState(null),[f,p]=a.useState(""),[,l]=a.useState(!1),[b,v]=a.useState([]),j=a.useRef(0),[m,g]=a.useState(!1),[S,E]=a.useState(!1),y=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[C,k]=a.useState(y?"mouse":"touch"),[w,_]=a.useState(1),B=a.useRef(!1),[D,P]=a.useState(1),[N,A]=a.useState(0),[$,T]=a.useState(0);mt("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:C,zoom:D,panX:N,panY:$,isMenuOpen:m,isImeOpen:S});const G=a.useRef(0),L=a.useRef(D),R=a.useRef(N),U=a.useRef($);a.useEffect(()=>{L.current=D},[D]),a.useEffect(()=>{R.current=N},[N]),a.useEffect(()=>{U.current=$},[$]),a.useEffect(()=>{var Z;(Z=c.current)==null||Z.focus()},[]);const z=n==="connected",W=r,Q=z?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",V=z?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!y||B.current||!W)return;const Z=d.current,oe=h.current;if(!Z||!oe)return;const M=()=>{const X=oe.clientWidth,se=oe.clientHeight,ne=Z.naturalWidth,xe=Z.naturalHeight;if(!ne||!xe||!X||!se)return;const be=Math.min(X/ne,se/xe),ge=Math.max(X/ne,se/xe)/be;ge>1.01&&(_(ge),P(ge),L.current=ge),B.current=!0};Z.complete&&Z.naturalWidth?M():Z.addEventListener("load",M,{once:!0})},[W,y]);const ie=.5;a.useEffect(()=>{D<=ie&&(A(0),T(0))},[D,ie]);const ee=(Z,oe,M)=>{if(M<=ie)return{x:0,y:0};const X=(M-1)/(2*M)*100,se=(M-1)/(2*M)*100;return{x:Math.max(-X,Math.min(X,Z)),y:Math.max(-se,Math.min(se,oe))}},O=(Z,oe)=>{if(!d.current)return null;const M=d.current.getBoundingClientRect();return!M.width||!M.height?null:{nx:Math.max(0,Math.min(1,(Z-M.left)/M.width)),ny:Math.max(0,Math.min(1,(oe-M.top)/M.height))}},Y=(Z,oe,M)=>{const X=h.current;if(!X)return;const se=X.getBoundingClientRect(),ne=++j.current;v(xe=>[...xe,{id:ne,x:Z-se.left,y:oe-se.top,type:M}]),setTimeout(()=>v(xe=>xe.filter(be=>be.id!==ne)),600)},H=(Z,oe,M)=>{const X=d.current,se=h.current;if(!X||!se)return;const ne=X.getBoundingClientRect(),xe=se.getBoundingClientRect(),be=X.naturalWidth||ne.width,pe=X.naturalHeight||ne.height,ge=be/pe,K=ne.width/ne.height;let F,re,ce,ae;ge>K?(F=ne.width,re=ne.width/ge,ce=0,ae=(ne.height-re)/2):(re=ne.height,F=ne.height*ge,ce=(ne.width-F)/2,ae=0);const he=ne.left-xe.left+ce+F*Z,je=ne.top-xe.top+ae+re*oe,Ne=++j.current;v(Be=>[...Be,{id:Ne,x:he,y:je,type:M}]),setTimeout(()=>v(Be=>Be.filter(Ye=>Ye.id!==Ne)),600)},I=async Z=>{var M;const oe=O(Z.clientX,Z.clientY);if(oe){u(`Click: ${Math.round(oe.nx*100)}%, ${Math.round(oe.ny*100)}%`),Y(Z.clientX,Z.clientY,"left"),(M=c.current)==null||M.focus();try{const X=await t("input_click",{nx:oe.nx,ny:oe.ny});X!=null&&X.success||s(`❌ Click failed: ${X==null?void 0:X.error}`)}catch(X){s(`❌ Click error: ${X.message||X}`)}}},J=async(Z,oe,M,X=0)=>{try{await t("input_key",{type:M?"char":"keyDown",key:Z,code:oe,text:M?Z:void 0,unmodifiedText:M?Z:void 0,modifiers:X})}catch(se){s(`❌ Key error: ${se.message||se}`)}},q=async Z=>{if(Z.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(Z.key)&&Z.preventDefault();let M=0;Z.altKey&&(M|=1),Z.ctrlKey&&(M|=2),Z.metaKey&&(M|=4),Z.shiftKey&&(M|=8),u(`Key: ${Z.key}`),await J(Z.key,Z.code,Z.key.length===1,M)},te=async Z=>{if(Z.key==="Enter"){if(Z.nativeEvent.isComposing)return;if(f){const oe=f;p(""),u(`IME Sent: ${oe}`);try{const M=await t("input_type",{text:oe});M!=null&&M.success||s(`❌ IME error: ${M==null?void 0:M.error}`)}catch(M){s(`❌ IME error: ${M.message}`)}}else u("Key: Enter"),await J("Enter","Enter",!1)}};a.useEffect(()=>{const Z=c.current;if(!Z)return;const oe=M=>{var X;if((X=d.current)!=null&&X.contains(M.target)){M.preventDefault();const se=Date.now();if(se-G.current<40)return;G.current=se;const ne=O(M.clientX,M.clientY);if(!ne)return;u(`Scroll: ${Math.round(M.deltaY)}`),t("input_wheel",{nx:ne.nx,ny:ne.ny,deltaX:Math.round(M.deltaX),deltaY:Math.round(M.deltaY)}).catch(()=>{})}};return Z.addEventListener("wheel",oe,{passive:!1}),()=>Z.removeEventListener("wheel",oe)},[t]);const{cursorPos:ue,handleToggleInputMode:de,handleZoomReset:le}=Zr({containerRef:c,viewportRef:h,imgRef:d,inputMode:C,setInputMode:k,minZoom:ie,zoomRef:L,panXRef:R,panYRef:U,setPanX:A,setPanY:T,setZoom:P,lastWheelTimeRef:G,onAction:t,setLastActionStatus:u,spawnRippleFromNormalized:H,clampPan:ee,isMobile:y,mobileFillZoom:w});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:q,onContextMenu:Z=>Z.preventDefault(),onFocus:()=>l(!0),onBlur:()=>l(!1),tabIndex:0,children:[e.jsxs("div",{ref:h,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[W?e.jsx("img",{ref:d,src:W,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${D}) translate(${N}%, ${$}%)`,transformOrigin:"center center",cursor:C==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:I,onContextMenu:Z=>Z.preventDefault(),onDragStart:Z=>Z.preventDefault()}):e.jsx(Gr,{waitingLabel:Q,waitingHint:V,transportType:o}),C==="mouse"&&W&&e.jsx(Yr,{cursorPos:ue,viewportRef:h,imgRef:d}),b.map(Z=>{const M={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[Z.type];return e.jsxs("div",{style:{position:"absolute",left:Z.x,top:Z.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${M}, 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(${M}, 0.9)`,boxShadow:`0 0 12px rgba(${M}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},Z.id)})]}),e.jsx(Xr,{inputMode:C,onToggleInputMode:de,isImeOpen:S,setIsImeOpen:E,isMenuOpen:m,setIsMenuOpen:g,imeText:f,setImeText:p,handleImeSubmit:te,isConnActive:z,zoom:D,isMobile:y,mobileFillZoom:w,onZoomOut:()=>P(Z=>Math.max(.5,Z-.25)),onZoomReset:le,onZoomIn:()=>P(Z=>Math.min(5,Z+.25)),transportType:o,screenshotUsage:i,lastActionStatus:x}),e.jsx("style",{children:`
|
|
12
|
+
@keyframes slideUp {
|
|
13
|
+
from { opacity: 0; transform: translateY(6px); }
|
|
14
|
+
to { opacity: 1; transform: translateY(0); }
|
|
15
|
+
}
|
|
16
|
+
@keyframes slideUpSidebar {
|
|
17
|
+
from { opacity: 0; transform: translateY(6px); }
|
|
18
|
+
to { opacity: 1; transform: translateY(0); }
|
|
19
|
+
}
|
|
20
|
+
@keyframes click-ripple-ring {
|
|
21
|
+
0% { transform: scale(0.3); opacity: 1; }
|
|
22
|
+
100% { transform: scale(2.2); opacity: 0; }
|
|
23
|
+
}
|
|
24
|
+
@keyframes click-ripple-dot {
|
|
25
|
+
0% { transform: scale(1); opacity: 0.9; }
|
|
26
|
+
50% { transform: scale(1.8); opacity: 0.6; }
|
|
27
|
+
100% { transform: scale(0.5); opacity: 0; }
|
|
28
|
+
}
|
|
29
|
+
@keyframes remote-float {
|
|
30
|
+
0% { transform: translateY(0px); }
|
|
31
|
+
50% { transform: translateY(-7px); }
|
|
32
|
+
100% { transform: translateY(0px); }
|
|
33
|
+
}
|
|
34
|
+
`})]})}function Qr({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:r=!1,connectionState:i,onDismiss:o,onClickAt:c,onKeyDown:h,badge:d,emptyMessage:x,aspectRatio:u,className:f,style:p}){const l=a.useRef(null),b=a.useCallback(v=>{if(!r||!c||!l.current)return;const j=l.current,m=j.getBoundingClientRect(),g=(v.clientX-m.left)/m.width*j.naturalWidth,S=(v.clientY-m.top)/m.height*j.naturalHeight;c(g,S,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 ${f||""}`,style:{aspectRatio:u||"16/9",...p},children:[e.jsx("img",{ref:l,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),o&&e.jsx("button",{onClick:o,className:"absolute top-2.5 right-2.5 bg-black/50 border-none text-white w-5 h-5 rounded-full text-[10px] z-10 cursor-pointer flex items-center justify-center",children:"✕"})]}):null:t?e.jsxs("div",{className:`${r?"screenshot-interactive":""} ${f||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?h:void 0,style:p,children:[e.jsx("img",{ref:l,src:t,alt:"IDE Screenshot",onClick:r?b:void 0,className:"max-w-full max-h-full object-contain",style:{...r?{cursor:"crosshair"}:{},...n!==100?{transform:`scale(${n/100})`,transformOrigin:"center center"}:{}}}),d&&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:d})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${f||""}`,style:p,children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.22)] mb-1",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),e.jsx("p",{className:"text-base",children:x||"Waiting for screenshot stream..."}),i&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",i]}),e.jsx("style",{children:`
|
|
35
|
+
@keyframes remote-float {
|
|
36
|
+
0% { transform: translateY(0px); }
|
|
37
|
+
50% { transform: translateY(-7px); }
|
|
38
|
+
100% { transform: translateY(0px); }
|
|
39
|
+
}
|
|
40
|
+
`})]})}function on({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(ns,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((c,h)=>{const d=o(c).toLowerCase(),x=/^(run|approve|accept|yes|allow|always)/.test(d),u=/^(reject|deny|delete|remove|abort)/.test(d),f=n===c,p=n!==null;return e.jsx("button",{onClick:()=>i(c),disabled:p,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${x?"bg-white font-extrabold":u?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${p&&!f?"opacity-40":"opacity-100"} ${p?"cursor-not-allowed":"cursor-pointer"}`,style:x?{color:"var(--status-warning)"}:void 0,children:f?"⏳ ...":o(c)},h)})})]})]})}const ys=new Map,ea={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"};function ta({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:i,controls:o,controlValues:c,serverModel:h,serverMode:d}){const{sendCommand:x}=We(),u=`${t}:${s||r}`,f=ea[r]||"#94a3b8",[p,l]=a.useState({}),b=a.useRef(0),v={...h?{model:h}:{},...d?{mode:d}:{},...c||{},...Date.now()<b.current?p:{}};a.useEffect(()=>{c&&Date.now()>b.current&&l({})},[c]);const[j,m]=a.useState(ys.get(u)||{}),[g,S]=a.useState(null),[E,y]=a.useState(null),C=a.useCallback(async(N,A={})=>{const $={...A,...s&&{targetSessionId:s}};return await x(t,N,$)},[t,s,x]);if(!o||o.length===0)return null;const k=o.filter(N=>N.placement==="bar").sort((N,A)=>(N.order??50)-(A.order??50));if(k.length===0)return null;const w=async N=>{var $,T,G;if(g===N.id){S(null);return}if(((($=N.options)==null?void 0:$.map(L=>L.value))||j[N.id]||[]).length>0){S(N.id);return}if(N.dynamic&&N.listScript){y(N.id);try{const L=await C(N.listScript==="listModels"?"list_extension_models":N.listScript==="listModes"?"list_extension_modes":N.listScript,{agentType:r,ideType:n}),U=((L==null?void 0:L.models)||(L==null?void 0:L.modes)||((T=L==null?void 0:L.result)==null?void 0:T.models)||((G=L==null?void 0:L.result)==null?void 0:G.modes)||(L==null?void 0:L.options)||[]).map(z=>typeof z=="string"?z:(z==null?void 0:z.name)||(z==null?void 0:z.id)||(z==null?void 0:z.value)||String(z));m(z=>{const W={...z,[N.id]:U};return ys.set(u,W),W}),S(N.id)}catch{}finally{y(null)}}},_=async(N,A)=>{S(null),l($=>({...$,[N.id]:A})),b.current=Date.now()+5e3;try{if(!N.setScript)return;const $=Ft(N.setScript,r);await C($,{agentType:r,ideType:n,model:N.id==="model"?A:void 0,mode:N.id==="mode"?A:void 0,value:A})}catch{}},B=async N=>{var R;const A=((R=N.options)==null?void 0:R.map(U=>U.value))||j[N.id]||[];if(A.length===0)return;const $=String(v[N.id]||""),G=(A.indexOf($)+1)%A.length,L=A[G];if(typeof L=="string"){l(U=>({...U,[N.id]:L})),b.current=Date.now()+5e3;try{if(!N.setScript)return;const U=Ft(N.setScript,r);await C(U,{agentType:r,ideType:n,value:L})}catch{}}},D=async N=>{const $=!v[N.id];l(T=>({...T,[N.id]:$})),b.current=Date.now()+5e3;try{if(!N.setScript)return;const T=Ft(N.setScript,r);await C(T,{agentType:r,ideType:n,value:$})}catch{}},P=async N=>{if(N.invokeScript)try{await C("invoke_extension_script",{agentType:r,ideType:n,scriptName:N.invokeScript})}catch{}};return e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1 flex-wrap text-[10px] border-t border-border-subtle bg-[var(--surface-primary)]",children:[e.jsx("span",{className:"text-[9px] font-bold tracking-wide opacity-70",style:{color:f},children:i}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),k.map(N=>{var L;const A=String(v[N.id]||""),$=g===N.id,T=E===N.id,G=((L=N.options)==null?void 0:L.map(R=>R.value))||j[N.id]||[];switch(N.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:$?`${f}55`:"transparent",border:"1px solid",color:A?"var(--text-primary)":"var(--text-muted)"},onClick:()=>w(N),children:[N.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:N.icon}),T?"...":A||N.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),$&&G.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>S(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:N.label.toUpperCase()}),G.map(R=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:R===A?`${f}18`:"transparent",color:R===A?f:"var(--text-secondary)",fontWeight:R===A?600:400,borderLeft:R===A?`2px solid ${f}`:"2px solid transparent"},onMouseEnter:U=>{U.currentTarget.style.background=`${f}12`},onMouseLeave:U=>{U.currentTarget.style.background=R===A?`${f}18`:"transparent"},onClick:()=>_(N,R),children:R},R))]})]})]},N.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(N),title:`Click to cycle: ${G.join(" → ")}`,children:[N.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:N.icon}),A||N.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"⟳"})]},N.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?`${f}44`:"transparent",background:A?`${f}14`:"var(--surface-tertiary)",color:A?f:"var(--text-muted)"},onClick:()=>D(N),children:[N.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:N.icon}),N.label]},N.id);case"action":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all hover:bg-[var(--surface-tertiary-hover)] whitespace-nowrap",style:{border:"1px solid var(--border-default)",background:"var(--surface-tertiary)",color:"var(--text-primary)"},onClick:()=>P(N),children:[N.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:N.icon}),N.label]},N.id);default:return null}})]})}function Ft(t,s){return{setModel:"set_extension_model",setMode:"set_extension_mode",setThinkingLevel:"set_thought_level"}[t]||t}const sa=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 d=()=>{const x=c.trim();!x||r||(h(""),i(x))};return e.jsx("div",{className:"dashboard-input-area px-3 py-2.5 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:o,type:"text",placeholder:`Send message to ${n}...`,value:c,onChange:x=>h(x.target.value),onPaste:x=>{const u=x.clipboardData.getData("text");u&&h(f=>f+u),x.preventDefault()},onKeyDown:x=>{if(x.key==="Enter"){if(x.nativeEvent.isComposing){x.preventDefault();return}x.preventDefault(),d()}},onBlur:x=>{if(window.innerWidth<768){const u=x.relatedTarget;if((u==null?void 0:u.tagName)==="BUTTON")return;setTimeout(()=>{document.documentElement.scrollTop=0},300)}},className:"w-full h-10 rounded-[20px] px-4 bg-bg-secondary text-sm text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:d,disabled:!c.trim()||r,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${c.trim()&&!r?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:c.trim()&&!r?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:c.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})});var na=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function ra(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function Me(t,s){if(ra(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":na.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 cn(t){return Me(t)==="generating"}function ve(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function aa(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 vs(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function ln(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 ia(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 oa(t){return ia(t.trim().replace(/\.local$/i,""))}function ca(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function dn(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 oa(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function pt(t,s={}){return ca(t)||dn(t,s)}function Tt(t){return t.transport==="pty"}function it(t){return t.transport==="acp"}function js(t,s){return ve(t)}function la(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const i=(s||"").trim().toLowerCase(),o=(n||"").trim().toLowerCase(),c=ve(n||"").trim().toLowerCase();return r===i||r===o||r===c}function da(t){return Me(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function ua(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=Me(r.status);if(!o){s.set(i,{...r,status:c});continue}const h=n.indexOf(o.status||"idle"),d=n.indexOf(c||"idle");d>=0&&(h<0||d<h)&&s.set(i,{...r,status:c})}return Array.from(s.values())}function un({conversation:t,className:s="",onOpenNativeConversation:n,onOpenMachine:r}){var f;const i=tt(),o=t.daemonId||((f=t.ideId)==null?void 0:f.split(":")[0])||t.ideId,c=t.transport==="cdp-page"||t.transport==="cdp-webview",h=t.streamSource==="agent-stream"&&!!t.agentName,d=(()=>{var p,l;if(t.streamSource==="agent-stream"){const b=(l=(p=t.displaySecondary)==null?void 0:p.split("·")[0])==null?void 0:l.trim();if(b)return b}return ve(t.ideType||"")})(),x=a.useCallback(()=>{if(r){r();return}o&&i("/dashboard",{state:{openMachineId:o}})},[o,i,r]),u=a.useCallback(()=>{if(n){n();return}t.ideId&&i(`/dashboard?activeTab=${encodeURIComponent(t.ideId)}`)},[t.ideId,i,n]);return e.jsxs("div",{className:`conversation-meta-chips ${s}`.trim(),children:[c&&e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:u,title:d,children:[e.jsx(Ee,{size:12}),e.jsx("span",{children:d})]}),h&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:t.agentName,children:[e.jsx(et,{size:12}),e.jsx("span",{children:t.agentName})]}),t.machineName&&e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:x,title:t.machineName,children:[e.jsx(ts,{size:12}),e.jsx("span",{children:t.machineName})]})]})}const Se=t=>t.transport==="pty",ke=t=>t.transport==="acp";function ws(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 ks(t){const s=[];for(const n of t){const r=ws(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&&ws(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 ha=60,ma=60;function rs({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:i,isFocusingAgent:o,actionLogs:c,userName:h,showMetaChips:d=!1}){const x=a.useRef(new Map),{sendCommand:u}=We();mt("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:r});const f=a.useRef(new Map),p=a.useCallback(N=>(f.current.has(N)||f.current.set(N,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:ha}),f.current.get(N)),[]),l=a.useCallback((N,A)=>{const $=p(N);f.current.set(N,{...$,...A}),b(T=>T+1)},[p]),[,b]=a.useState(0),v=t.tabKey,j=p(v),m=j.messages,g=j.hasMore,S=j.error,E=Math.max(0,t.messages.length-j.visibleLiveCount),[y,C]=a.useState(!1),k=a.useCallback(async()=>{var $,T;if(y)return;const N=t.tabKey,A=p(N);if(t.messages.length>A.visibleLiveCount){l(N,{visibleLiveCount:Math.min(t.messages.length,A.visibleLiveCount+ma),error:null});return}C(!0),l(N,{error:null});try{const G=(s==null?void 0:s.daemonId)||(($=t.ideId)==null?void 0:$.split(":")[0])||"";if(!G){l(N,{hasMore:!1});return}const L=t.ideType||t.agentType||"",R=await u(G,"chat_history",{agentType:L,offset:A.offset,limit:30,targetSessionId:t.sessionId}),U=(R==null?void 0:R.result)??R;if(((T=U.messages)==null?void 0:T.length)>0){const z=p(N);l(N,{messages:[...U.messages,...z.messages],offset:z.offset+U.messages.length,hasMore:!!U.hasMore})}else l(N,{hasMore:!!U.hasMore})}catch(G){const L=(G==null?void 0:G.message)||"";L.includes("P2P not available")||L.includes("channel not open")||L.includes("P2P not connected")||L.includes("timeout")?l(N,{error:"Connection not ready — tap to retry"}):l(N,{hasMore:!1,error:"Failed to load history"})}finally{C(!1)}},[y,s,t,u,p,l]),{allMessages:w,receivedAtMap:_}=a.useMemo(()=>{const N=E>0?t.messages.slice(-j.visibleLiveCount):t.messages;if(m.length===0){const L=ks(N),R={};return L.forEach((U,z)=>{const W=`${t.tabKey}:${Ze(U,z)}`;let Q=U.receivedAt||x.current.get(W)||0;Q||(Q=Date.now(),x.current.set(W,Q)),R[Ze(U,z)]=Q}),{allMessages:L,receivedAtMap:R}}const A=new Set(N.map(L=>`${L.role}:${(L.content||"").slice(0,100)}`)),$=m.filter(L=>!A.has(`${L.role}:${(L.content||"").slice(0,100)}`)),T=ks([...$,...N]),G={};return T.forEach((L,R)=>{const U=`${t.tabKey}:${Ze(L,R)}`;let z=L.receivedAt||x.current.get(U)||0;z||(z=Date.now(),x.current.set(U,z)),G[Ze(L,R)]=z}),{allMessages:T,receivedAtMap:G}},[t.messages,t.tabKey,E,m,j.visibleLiveCount]),B=a.useMemo(()=>c.filter(N=>N.ideId===t.tabKey).sort((N,A)=>N.timestamp-A.timestamp),[c,t.tabKey]),D=t.displayPrimary||t.agentName||"Agent",P=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(et,{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(Yt,{size:14})," Open ",D," 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(en,{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(Yt,{size:14})," Open ",D," 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"&&!y)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,y,D]);return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[d&&e.jsx(un,{conversation:t,className:"chat-pane-meta-row"}),e.jsx(qr,{messages:w,actionLogs:B,agentName:t.agentName||t.displayPrimary||"Agent",userName:h,isCliMode:Se(t)||ke(t),isWorking:t.status==="generating",contextKey:t.tabKey,receivedAtMap:_,onLoadMore:k,isLoadingMore:y,hasMoreHistory:g,hiddenLiveCount:E,loadError:S??void 0,emptyState:P}),!Se(t)&&(()=>{const N=t.streamSource!=="agent-stream",A=N?t.ideType:t.agentType,$=N?s!=null&&s.type?ve(s.type):ve(t.ideType||""):t.agentName||ve(t.agentType||""),T=!N&&(s!=null&&s.childSessions)&&s.childSessions.find(R=>R.id===t.sessionId||R.providerType===t.agentType)||s,G=T==null?void 0:T.providerControls,L=T==null?void 0:T.controlValues;return e.jsx(ta,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:A,displayLabel:$,controls:G,controlValues:L,serverModel:(T==null?void 0:T.currentModel)||void 0,serverMode:(T==null?void 0:T.currentPlan)||void 0,acpConfigOptions:ke(t)?T==null?void 0:T.acpConfigOptions:void 0,acpModes:ke(t)?T==null?void 0:T.acpModes:void 0})})(),e.jsx(sa,{contextKey:t.tabKey,panelLabel:D,isSending:r,onSend:n})]})}let hn=ut;function as(){return hn()}class pa{constructor(){ye(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 mn=new pa;class xa{constructor(){ye(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 fe=new xa;function fa(t){t.dashboardWS&&(mn=t.dashboardWS),t.connectionManager&&(fe=t.connectionManager),t.useDaemonsHook&&(hn=t.useDaemonsHook)}function pn({activeConv:t,clearToken:s=0,terminalRef:n,handleSendChat:r,isSendingChat:i=!1}){var E;const o=a.useRef(null),{sendCommand:c,sendData:h}=We(),[d,x]=a.useState(""),[u,f]=a.useState(!1),p=a.useRef(0),l=a.useRef(!1),b=t.tabKey,v=t.sessionId||"",j=t.daemonId||((E=t.ideId)==null?void 0:E.split(":")[0])||t.ideId||"",m=()=>{var y;p.current=0,l.current=!1,f(!1),(y=n.current)==null||y.clear()},g=()=>{var y;p.current=0,l.current=!1,f(!0),(y=n.current)==null||y.clear()},S=(y,C=0)=>{var k,w;l.current||p.current>=C&&p.current!==0||(p.current=C,f(!0),(k=n.current)==null||k.clear(),y&&((w=n.current)==null||w.write(y)))};return a.useEffect(()=>{m()},[v]),a.useEffect(()=>{var C,k;if(!v)return;const y=((C=fe.onRuntimeEvent)==null?void 0:C.call(fe,v,w=>{var _;if(!(!w||w.sessionId!==v)){if(w.type==="runtime_snapshot"){S(w.text||"",w.seq||0);return}if(w.type==="session_output"){l.current=!0,typeof w.seq=="number"&&(p.current=Math.max(p.current,w.seq)),f(!0),typeof w.data=="string"&&((_=n.current)==null||_.write(w.data));return}w.type==="session_cleared"&&g()}}))||(()=>{});return(k=fe.requestRuntimeSnapshot)==null||k.call(fe,j,v).catch(()=>{}),()=>{y()}},[j,v,n]),a.useEffect(()=>{var C,k,w;if(!v)return;j&&((C=fe.getState)==null?void 0:C.call(fe,j))==="connected"&&(f(!0),(k=fe.requestRuntimeSnapshot)==null||k.call(fe,j,v).catch(()=>{}));const y=(w=fe.onStateChange)==null?void 0:w.call(fe,(_,B)=>{var D;_!==j||B!=="connected"||(f(!0),(D=fe.requestRuntimeSnapshot)==null||D.call(fe,j,v).catch(()=>{}))});return()=>{y==null||y()}},[j,v,n]),a.useEffect(()=>{s&&m()},[s,b,n]),a.useEffect(()=>{x("")},[t.tabKey]),a.useEffect(()=>{const y=C=>{var w;const k=C.detail;k!=null&&k.sessionId&&k.sessionId!==v||u&&((w=n.current)==null||w.fit())};return window.addEventListener("adhdev:fit-cli-terminal",y),()=>{window.removeEventListener("adhdev:fit-cli-terminal",y)}},[u,v,n]),a.useEffect(()=>{if(!u)return;const y=requestAnimationFrame(()=>{var C;(C=n.current)==null||C.fit()});return()=>cancelAnimationFrame(y)},[u,v,n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx(rn,{ref:n,readOnly:!u,onInput:y=>{u&&(h!=null&&h(j,{type:"pty_input",targetSessionId:v,data:y})||c(j,"pty_input",{targetSessionId:v,data:y}).catch(console.error))},onResize:(y,C)=>{u&&(h!=null&&h(j,{type:"pty_resize",targetSessionId:v,cols:y,rows:C})||c(j,"pty_resize",{targetSessionId:v,cols:y,rows:C,force:!0}).catch(()=>{}))}},t.tabKey),!u&&e.jsx("div",{className:"absolute inset-x-2 top-2 rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[11px] text-red-300 pointer-events-none",children:"Runtime terminal unavailable"})]}),e.jsx("div",{className:"px-3 py-2 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:o,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:d,onChange:y=>x(y.target.value),onPaste:y=>{const C=y.clipboardData.getData("text");C&&x(k=>k+C),y.preventDefault()},onKeyDown:y=>{if(y.key!=="Enter")return;if(y.nativeEvent.isComposing){y.preventDefault();return}y.preventDefault();const C=d.trim();!u||!C||i||(x(""),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 y=d.trim();!u||!y||i||(x(""),r(y))},disabled:!u||!d.trim()||i,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${d.trim()&&!i?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:d.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:d.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function ba({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 ga({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 ya(t,s={}){if(!t)return"";const{suffix:n="",nowLabel:r="now",nowThreshold:i=60}=s,o=Date.now()-t,c=Math.floor(o/1e3);if(c<i)return r;const h=Math.floor(c/60);if(h<60)return`${h}m${n}`;const d=Math.floor(h/60);if(d<24)return`${d}h${n}`;const x=Math.floor(d/24);return x<7?`${x}d${n}`:new Date(t).toLocaleDateString()}const at=t=>ya(t);function xn(t,s){return!!t.surfaceHidden}function va({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,conversations:i,onOpenHistory:o,onOpenRemote:c,onStopCli:h,onFitCli:d,onOpenConversation:x}){const u=as(),f=u.p2pStates||{},p=u.ides||[],l=!!t&&Se(t)&&!ke(t),[b,v]=a.useState(!1),j=a.useRef(null),m=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",g=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",S=p.filter(N=>N.type==="adhdev-daemon"),E=Object.values(f),y=E.filter(N=>N==="connected").length,C=E.filter(N=>N==="connecting"||N==="new"||N==="checking").length,w=n!=="connected"||S.length===0?null:C>0&&y===0?"P2P connecting...":y>0&&s===0?"Waiting for IDE...":null,_=a.useMemo(()=>i.filter(N=>!xn(N)),[i]),B=a.useMemo(()=>_.filter(N=>N.inboxBucket==="needs_attention"),[_]),D=a.useMemo(()=>_.filter(N=>N.inboxBucket==="task_complete"&&N.unread),[_]),P=B.length+D.length;return a.useEffect(()=>{if(!b)return;const N=A=>{var $;($=j.current)!=null&&$.contains(A.target)||v(!1)};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[b]),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(ht,{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:m,boxShadow:g}})})]}),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:m,boxShadow:g}}),w&&e.jsxs("span",{className:"header-subtitle-status",children:["· ",w]})]})]})})}),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:()=>v(N=>!N),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(Dt,{size:16}),P>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:P})]}),b&&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(N=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item is-attention",onClick:()=>{x==null||x(N),v(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:N.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:N.displaySecondary})]},N.tabKey))]}),D.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),D.map(N=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{x==null||x(N),v(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:N.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:N.displaySecondary})]},N.tabKey))]}),P===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]}),l&&h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:d,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&&!l&&!ke(t)&&e.jsx("button",{onClick:()=>o(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(ss,{size:16})}),t&&!l&&!ke(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Ee,{size:16})})]})]})}function ja({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,onClose:i,onNewChat:o,onSwitchSession:c,onRefreshHistory:h}){var f;const d=s.find(p=>p.id===t.ideId),x=(d==null?void 0:d.chats)||[],u=(f=d==null?void 0:d.activeChat)==null?void 0:f.id;return e.jsxs("div",{className:"fixed inset-0 z-[1300] flex items-center justify-center",children:[e.jsx("div",{onClick:i,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"card fade-in relative w-[90%] max-w-[500px] max-h-[80vh] flex flex-col p-0 overflow-hidden shadow-[0_20px_40px_rgba(0,0,0,0.4)] rounded-[20px]",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-subtle flex justify-between items-center bg-[var(--surface-primary)]",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"m-0 text-lg font-extrabold",children:"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",ve(t.ideType)]})]}),e.jsx("button",{onClick:i,className:"bg-transparent border-none text-xl text-text-muted cursor-pointer",children:"✕"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 bg-bg-primary",children:[e.jsx("button",{onClick:o,disabled:n,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:n?"⌛ Creating...":"+ Start New Chat Session"}),x.map(p=>e.jsxs("div",{onClick:()=>{c(t.ideId,p.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${u===p.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${u===p.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:p.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:[p.id.substring(0,12),"..."]}),u===p.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},p.id)),x.length===0&&e.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[e.jsx("div",{className:"text-3xl mb-3 opacity-60",children:e.jsx($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(Qs,{size:13})," Refresh History"]})})})]})]})}const Ns={success:"rgba(16, 185, 129, 0.95)",warning:"color-mix(in srgb, var(--status-warning) 95%, transparent)",info:"rgba(99, 102, 241, 0.95)"};function fn({toasts:t,onDismiss:s,onClickToast:n}){return e.jsx("div",{className:"fixed right-4 z-[9999] flex flex-col gap-2 pointer-events-none",style:{top:"calc(env(safe-area-inset-top, 0px) + 16px)"},children:t.map(r=>e.jsxs("div",{className:"fade-in text-white px-5 py-3 rounded-xl text-[13px] font-semibold shadow-[0_8px_32px_rgba(0,0,0,0.3)] backdrop-blur-lg pointer-events-auto cursor-pointer animate-[toast-in_0.3s_ease-out] max-w-[360px] relative group",style:{background:Ns[r.type]||Ns.info},onClick:()=>{var i;(i=r.actions)!=null&&i.length||(n&&n(r),s(r.id))},children:[e.jsx("button",{className:"absolute top-1.5 right-1.5 w-5 h-5 rounded-full flex items-center justify-center text-white/50 hover:text-white hover:bg-white/20 transition-all text-[11px] leading-none opacity-0 group-hover:opacity-100 cursor-pointer",onClick:i=>{i.stopPropagation(),s(r.id)},"aria-label":"Dismiss",children:"×"}),e.jsx("div",{className:"pr-4",children:r.message}),r.actions&&r.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-2",children:r.actions.map((i,o)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${i.variant==="primary"?"bg-white text-text-primary hover:bg-gray-100":i.variant==="danger"?"bg-red-500/30 text-white hover:bg-red-500/50":"bg-white/20 text-white hover:bg-white/30"}`,onClick:c=>{c.stopPropagation(),i.onClick(),s(r.id)},children:i.label},o))})]},r.id))})}function bn(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():Array.isArray(t)?t.map(s=>typeof s=="string"?s:s&&typeof s=="object"&&"text"in s?String(s.text||""):"").join(" ").replace(/\s+/g," ").trim():t&&typeof t=="object"&&"text"in t?String(t.text||"").replace(/\s+/g," ").trim():String(t||"").replace(/\s+/g," ").trim()}const wa=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function ka(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function Na(t){return t.sessionId||t.instanceId||t.agentType}function gt(t){return bn(t)}function Ss(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 gn(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=pt(r,{fallbackId:r.id}))}return s}function yn(t,s,n={}){var p,l,b,v,j,m;const r=[],i=n.machineName,o=n.connectionState,c=ka(t),h=ve(t.type),d=Array.isArray(t.childSessions)?t.childSessions.map(g=>{var S,E;return{sessionId:g.id,instanceId:g.id,agentType:g.providerType,agentName:g.providerName,status:g.status,title:g.title,messages:((S=g.activeChat)==null?void 0:S.messages)||[],activeModal:((E=g.activeChat)==null?void 0:E.activeModal)||void 0,recentKey:g.recentKey,unread:g.unread,lastSeenAt:g.lastSeenAt,inboxBucket:g.inboxBucket,surfaceHidden:g.surfaceHidden}}):[],x=wa(t),u=t.activeChat||{title:""},f=u.title&&String(u.title).trim()?String(u.title).trim():"";if(x){const g=t.sessionId||t.instanceId,S=js(t.type),E=(p=t.activeChat)==null?void 0:p.activeModal,y=E&&Array.isArray(E.buttons)&&E.buttons.length>0,C=Me((l=t.activeChat)==null?void 0:l.status,{activeModal:(b=t.activeChat)==null?void 0:b.activeModal})||Me((j=(v=t.agents)==null?void 0:v[0])==null?void 0:j.status)||"idle",k=t.activeChat||{title:"",messages:[]};let w=k.title&&String(k.title).trim()?String(k.title).trim():"";const _=(m=t.activeChat)==null?void 0:m.id,B=t.chats;if(_&&Array.isArray(B)&&B.length>0){const $=B.find(T=>T.id===_||T.id&&String(T.id)===String(_));$!=null&&$.title&&String($.title).trim()&&(w=String($.title).trim())}const D=k.messages||[],P=Ss(s,[t.id,g]),N=new Map;D.filter($=>$.role==="user").forEach($=>{const T=gt($.content);T&&N.set(T,(N.get(T)||0)+1)});const A=P.filter($=>{const T=gt($.content),G=N.get(T)||0;return G>0?(N.set(T,G-1),!1):!0});r.push({ideId:t.id,sessionId:g,transport:t.transport,daemonId:t.daemonId||void 0,mode:Se(t)?t.mode||"terminal":"chat",agentName:S,agentType:(Se(t)||ke(t))&&(t.cliType||t.acpType)||t.type,status:C,title:w,messages:[...D,...A],resume:t.resume,ideType:t.cliType||t.acpType||t.type,workspaceName:c,displayPrimary:w||c||(Se(t)||ke(t)?"Terminal":S),displaySecondary:h,cdpConnected:t.cdpConnected,recentKey:t.recentKey,modalButtons:y?E.buttons:void 0,modalMessage:y?E.message:void 0,unread:t.unread,lastSeenAt:t.lastSeenAt,inboxBucket:t.inboxBucket,surfaceHidden:t.surfaceHidden,streamSource:"native",tabKey:t.id,machineName:i,connectionState:o})}if(x&&(Se(t)||ke(t)))return r;for(const g of d){const S=g.activeModal&&Array.isArray(g.activeModal.buttons)&&g.activeModal.buttons.length>0,E=da(g),y=Na(g),C=`${t.id}:${y}`,k=g.title&&String(g.title).trim()||"",w=la(k,g.agentName,g.agentType)?"":k,_=g.messages||[],B=Ss(s,[C,g.sessionId,g.instanceId]),D=new Map;_.filter(N=>N.role==="user").forEach(N=>{const A=gt(N.content);A&&D.set(A,(D.get(A)||0)+1)});const P=B.filter(N=>{const A=gt(N.content),$=D.get(A)||0;return $>0?(D.set(A,$-1),!1):!0});r.push({ideId:t.id,sessionId:g.sessionId||g.instanceId,transport:g.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:g.agentName,agentType:g.agentType,status:E,title:w,messages:[..._,...P],ideType:g.agentType,workspaceName:c,displayPrimary:w||f||c||h,displaySecondary:`${h}·${g.agentName}`,cdpConnected:t.cdpConnected,recentKey:g.recentKey??g.id,modalButtons:S?g.activeModal.buttons:void 0,modalMessage:S?g.activeModal.message:void 0,unread:g.unread,lastSeenAt:g.lastSeenAt,inboxBucket:g.inboxBucket,surfaceHidden:g.surfaceHidden,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:js(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,surfaceHidden:t.surfaceHidden,streamSource:"native",tabKey:t.id,connectionState:o}),r}function Sa(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 Ca(t,s){const n=[],{daemonId:r,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now(),h=t.sessions||[],{topLevel:d,childrenByParent:x}=Sa(h),u=d.filter(l=>l.kind==="workspace"&&l.transport==="cdp-page"),f=d.filter(l=>l.kind==="agent"&&l.transport==="pty"),p=d.filter(l=>l.kind==="agent"&&l.transport==="acp");n.push({...i||{},id:r,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:c,...t.version&&{version:t.version},...t.machine&&{machine:t.machine,platform:t.machine.platform},...t.instanceId&&{instanceId:t.instanceId},...t.machineNickname!==void 0&&{machineNickname:t.machineNickname},...t.p2p&&{p2p:t.p2p},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.recentSessions&&{recentSessions:t.recentSessions},...t.terminalBackend&&{terminalBackend:t.terminalBackend},...t.detectedIdes&&{detectedIdes:t.detectedIdes},...t.availableProviders&&{availableProviders:t.availableProviders},cdpConnected:u.some(l=>!!l.cdpConnected)});for(const l of u){const b=x.get(l.id)||[];n.push({id:`${r}:ide:${l.id}`,sessionId:l.id,parentSessionId:l.parentId,sessionKind:l.kind,transport:l.transport,sessionCapabilities:l.capabilities,type:l.providerType,ideType:l.providerType,status:l.cdpConnected?"online":"detected",daemonId:r,instanceId:l.id,workspace:l.workspace,terminals:0,childSessions:b,agents:b.map(v=>({id:v.id,name:v.providerName,type:v.providerType,status:v.status})),activeChat:l.activeChat,chats:[],cdpConnected:l.cdpConnected,currentModel:l.currentModel,currentPlan:l.currentPlan,currentAutoApprove:l.currentAutoApprove,recentKey:l.recentKey,unread:l.unread,lastSeenAt:l.lastSeenAt,inboxBucket:l.inboxBucket,surfaceHidden:l.surfaceHidden,controlValues:l.controlValues,providerControls:l.providerControls,timestamp:c})}for(const l of f)n.push({id:`${r}:cli:${l.id}`,sessionId:l.id,parentSessionId:l.parentId,sessionKind:l.kind,transport:l.transport,sessionCapabilities:l.capabilities,type:l.providerType,ideType:l.providerType,agentType:l.providerType,status:l.status||"running",daemonId:r,instanceId:l.id,cliName:l.providerName,mode:"terminal",workspace:l.workspace||"",activeChat:l.activeChat,resume:l.resume,runtimeKey:l.runtimeKey,runtimeDisplayName:l.runtimeDisplayName,runtimeWorkspaceLabel:l.runtimeWorkspaceLabel,runtimeWriteOwner:l.runtimeWriteOwner??null,runtimeAttachedClients:l.runtimeAttachedClients??[],recentKey:l.recentKey,unread:l.unread,lastSeenAt:l.lastSeenAt,inboxBucket:l.inboxBucket,surfaceHidden:l.surfaceHidden,controlValues:l.controlValues,providerControls:l.providerControls,timestamp:c,_isCli:!0});for(const l of p)n.push({id:`${r}:acp:${l.id}`,sessionId:l.id,parentSessionId:l.parentId,sessionKind:l.kind,transport:l.transport,sessionCapabilities:l.capabilities,type:l.providerType,ideType:l.providerType,agentType:l.providerType,status:l.status||"running",daemonId:r,instanceId:l.id,cliName:l.providerName,mode:"chat",workspace:l.workspace||"",activeChat:l.activeChat,runtimeKey:l.runtimeKey,runtimeDisplayName:l.runtimeDisplayName,runtimeWorkspaceLabel:l.runtimeWorkspaceLabel,runtimeWriteOwner:l.runtimeWriteOwner??null,runtimeAttachedClients:l.runtimeAttachedClients??[],currentModel:l.currentModel,currentPlan:l.currentPlan,recentKey:l.recentKey,unread:l.unread,lastSeenAt:l.lastSeenAt,inboxBucket:l.inboxBucket,surfaceHidden:l.surfaceHidden,acpConfigOptions:l.acpConfigOptions,acpModes:l.acpModes,controlValues:l.controlValues,providerControls:l.providerControls,timestamp:c,_isAcp:!0});return n}function Ia(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 Ma(t,s){const n=Ia(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const vn=[{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:"💚"}],jn=[{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:"🧩"}],wn=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],kn="adhdev_notification_prefs",Cs={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function Ta(){try{const t=localStorage.getItem(kn);if(t){const s=JSON.parse(t);return{...Cs,...s}}}catch{}return{...Cs}}function Ra(t){try{localStorage.setItem(kn,JSON.stringify(t))}catch{}}let Pe=Ta(),kt=[];function Aa(){kt.forEach(t=>t())}function Ea(){return{...Pe}}function _a(t){Pe={...Pe,...t},Ra(Pe),Aa()}function Pa(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return kt.push(n),()=>{kt=kt.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{_a(n)},[]);return[{...Pe},s]}function ot(t){if(!Pe.globalEnabled)return!1;switch(t){case"disconnect":return Pe.disconnectAlert;case"completion":return Pe.completionAlert;case"approval":return Pe.approvalAlert;case"browser":return Pe.browserNotifications;default:return!0}}const La={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Da(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function Nn(){return"Notification"in window&&Notification.permission==="granted"}let Fe=null;async function $a(){if(Fe!==null)return Fe;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return Fe=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(Fe=!!await t.pushManager.getSubscription(),Fe):(Fe=!1,!1)}catch{return Fe=!1,!1}}function Gt(t,s,n){if(Nn())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 Ba(t,s={}){const n={...La,...s},r=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{$a().then(h=>{o.current=h})},[]);const c=a.useCallback((h,d,x)=>{const u=Date.now();u-i.current<n.throttleMs||(i.current=u,Gt(h,d,x))},[n.throttleMs]);a.useEffect(()=>{var h;if(!(!n.enabled||!Nn())&&ot("browser")&&o.current!==!0){if(document.hasFocus()){for(const d of t)r.current.set(d.id,Me(d.status,{activeModal:d.activeModal}));return}for(const d of t){const x=r.current.get(d.id),u=Me(d.status,{activeModal:d.activeModal}),f=d.name||d.id;if(n.onApproval&&ot("approval")&&u==="waiting_approval"&&x!=="waiting_approval"){const p=((h=d.activeModal)==null?void 0:h.message)||"Action requires your approval";c(`🔔 ${f} — Approval needed`,p.slice(0,120),`approval-${d.id}`)}n.onComplete&&ot("completion")&&cn(x)&&u==="idle"&&c(`✅ ${f} — Task complete`,"Agent has finished generating",`complete-${d.id}`),n.onError&&u==="error"&&x!=="error"&&c(`⚠️ ${f} — Error`,"Agent encountered an error",`error-${d.id}`),r.current.set(d.id,u)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class Ka{constructor(){ye(this,"dedupMap",new Map);ye(this,"DEDUP_WINDOW_MS",5e3);ye(this,"DEDUP_MAX_SIZE",50);ye(this,"DEDUP_CLEANUP_AGE_MS",1e4);ye(this,"toastCallbacks",[]);ye(this,"systemMessageCallbacks",[]);ye(this,"clearSystemMessageCallbacks",[]);ye(this,"resolveActionFn",null);ye(this,"viewRequestRespondFn",null);ye(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(n=>n!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(n=>n!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(n=>n!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const n of this.toastCallbacks)n(s)}showToast(s,n="info",r){const i=(r==null?void 0:r.id)||Date.now();this.emitToast({id:i,message:s,type:n,timestamp:i,duration:5e3,...r})}emitSystemMessage(s,n){for(const r of this.systemMessageCallbacks)r(s,n)}emitClearSystemMessage(s,n){for(const r of this.clearSystemMessageCallbacks)r(s,n)}isDuplicate(s){const n=Date.now(),r=this.dedupMap.get(s)||0;if(n-r<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,n),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,o]of this.dedupMap)n-o>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(i);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const i=this.ides.find(o=>o.id===s.ideId&&o.type==="adhdev-daemon");if(i)return i}let n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(i=>i.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),n){const i=n.daemonId;if(i){const o=this.ides.find(c=>c.id===i&&c.type==="adhdev-daemon");if(o)return o}}const r=this.ides.filter(i=>i.type==="adhdev-daemon");return r.length===1?r[0]:null}resolveRouteId(s,n){for(const r of this.ides)if(r.id.startsWith(s)&&(!n||n===r.type))return r.id;return s}findOwningSession(s){for(const n of this.ides)if(n.id===s||n.sessionId===s||(Array.isArray(n.childSessions)?n.childSessions:[]).some(i=>(i==null?void 0:i.id)===s))return n;return null}resolveActionRouteTarget(s){if(s.ideId){const n=s.agentType||s.ideType||"";return this.resolveRouteId(s.ideId,n)}if(s.targetSessionId){const n=this.findOwningSession(s.targetSessionId);return(n==null?void 0:n.id)||(n==null?void 0:n.daemonId)||null}return null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.ideId?s.ideId:null}handleRawEvent(s,n){var u,f;if(!s.ideId&&s.instanceId){for(const p of this.ides)if(p.id.endsWith(`:ide:${s.instanceId}`)||p.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=p.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=ve(s.ideType||"");const h=this.resolveOwningDaemon(s);if(h){const p=pt(h,{fallbackId:h.id});p&&(c=s.ideType==="adhdev-daemon"?p:`${p}/${c}`)}let d="",x="info";if(s.event==="agent:generating_completed"){const p=s.duration?` (${s.duration}s)`:"";d=`✅ ${c} agent task completed${p}`,x="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&Ea().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${p}`,_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(d=`⚡ ${c} approval needed`,x="warning",r){const p=s.modalMessage||"Approval requested",l=(u=s.modalButtons)!=null&&u.length?s.modalButtons.map(b=>`[${b}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${p}
|
|
42
|
+
${l}`,_localId:`sys_approval_${Date.now()}`})}if((f=s.modalButtons)!=null&&f.length&&this.resolveActionFn){const p=this.resolveActionRouteTarget(s);if(!p)return;const l=s.agentType||s.ideType||"",b=s.ideType||"",v=s.modalButtons,j=y=>y.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),m=this.resolveActionFn,g=v.map((y,C)=>{const k=j(y).toLowerCase(),w=/^(run|approve|accept|yes|allow|always)/.test(k),_=/^(reject|deny|delete|remove|abort|cancel|no)/.test(k);return{label:j(y),variant:w?"primary":_?"danger":"default",onClick:()=>{const B=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(k);m(p,"resolve_action",{action:B?"approve":"reject",button:y,buttonIndex:C,agentType:l,ideType:b,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),S=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:d,E=Date.now();this.emitToast({id:E,message:S,type:x,timestamp:E,targetKey:r||p,actions:g,duration:15e3}),d=""}}else if(s.event==="monitor:long_generating"){const p=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";d=`⚠️ ${c} agent is taking a long time${p}`,x="warning",ot("browser")&&!document.hasFocus()&&Gt(`⚠️ ${c} — Long Running`,`Agent has been generating for over ${p.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const p=s.requesterName||"A team member",l=s.requestId,b=s.orgId;if(d=`👁️ ${p} wants to view your session`,x="warning",l&&b&&this.viewRequestRespondFn){const v=this.viewRequestRespondFn,j=Date.now(),m=[{label:"Approve",variant:"primary",onClick:()=>{v(b,l,"approve").catch(g=>console.error("[EventManager] approve view request failed:",g))}},{label:"Decline",variant:"danger",onClick:()=>{v(b,l,"reject").catch(g=>console.error("[EventManager] reject view request failed:",g))}}];this.emitToast({id:j,message:d,type:x,timestamp:j,actions:m,duration:3e4}),d=""}ot("browser")&&!document.hasFocus()&&Gt("👁️ View Request",`${p} wants to view your session`,`view-request-${l}`)}else s.event==="team:view_request_approved"?(d="✅ View request approved",x="success"):s.event==="team:view_request_rejected"&&(d=`❌ ${s.targetName||"Team member"} declined your view request`,x="warning");if(d){const p=Date.now();this.emitToast({id:p,message:d,type:x,timestamp:p,targetKey:r||s.ideId,duration:5e3})}}}const Ke=new Ka;function qe(...t){return lr(dr(t))}function Oa({icon:t,title:s,subtitle:n,badge:r,actions:i,className:o}){return e.jsxs("div",{className:qe("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 Rt({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(Oa,{icon:t,title:s,subtitle:n,badge:r,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:qe("mx-auto flex w-full flex-col gap-4",o,c),children:h})})]})}function Ie({title:t,icon:s,description:n,accentColor:r,className:i,children:o}){return e.jsxs("div",{className:qe("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 is({icon:t,title:s,description:n,action:r,className:i}){return e.jsxs("div",{className:qe("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 Wa={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"},za={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function Fa({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:qe("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",Wa[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:za[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 Ua={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"},Ha={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Va({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:qe("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Ua[t],n),children:[e.jsx("span",{className:qe("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Ha[t])}),r]})}function qa(){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 Nt(t){return t==="system"?qa():t}function Ya(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Nt(Jt()))}function Sn(){const[t,s]=a.useState(Jt),[n,r]=a.useState(()=>Nt(Jt()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),h=d=>{t==="system"&&r(d.matches?"light":"dark")};return c.addEventListener("change",h),()=>c.removeEventListener("change",h)},[t]);const i=a.useCallback(c=>{s(c),r(Nt(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const h=c==="dark"?"light":c==="light"?"system":"dark";r(Nt(h));try{localStorage.setItem("theme",h)}catch{}return h})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function Oe({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 Xa({onPrefChange:t}){const[s,n]=Pa(),r=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Dt,{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(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ee,{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(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Br,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Kr,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(et,{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(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ht,{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 Ga({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(is,{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(Za,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i},c.id))})}function Is({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 ur.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 Ja(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...vn,...jn,...wn].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 Za({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){var A,$;const[o,c]=a.useState("idle"),[h,d]=a.useState(""),[x,u]=a.useState(null),[f,p]=a.useState("idle"),[l,b]=a.useState(""),v=t,j=v.version||v.daemonVersion||null,m=((A=v.machine)==null?void 0:A.platform)||(($=v.system)==null?void 0:$.platform)||"",g=pt(v,{fallbackId:t.id}),S=m==="win32"?"🪟":m==="darwin"?"🍎":"🐧",E=s.filter(T=>T.daemonId===t.id&&T.transport==="cdp-page"),y=s.filter(T=>T.daemonId===t.id&&T.transport==="pty"),C=s.filter(T=>T.daemonId===t.id&&T.transport==="acp"),k=v.p2p,w=async()=>{var T,G,L;if(n){c("upgrading"),d("Installing latest version...");try{const R=await n(t.id,"daemon_upgrade",{});(T=R==null?void 0:R.result)!=null&&T.upgraded||(G=R==null?void 0:R.result)!=null&&G.success?(c("done"),d(`Upgraded to v${R.result.version||"latest"}. Daemon is restarting...`)):(c("error"),d(((L=R==null?void 0:R.result)==null?void 0:L.error)||"Upgrade failed"))}catch(R){c("error"),d((R==null?void 0:R.message)||"Connection lost during upgrade")}}},_=async()=>{if(u(null),!!r){p("loading");try{await r(t.id),p("done"),b("Machine disconnected.")}catch(T){p("error"),b((T==null?void 0:T.message)||"Failed to disconnect")}}},B=async()=>{if(u(null),!!i){p("loading");try{await i(t.id),p("done"),b('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(T){p("error"),b((T==null?void 0:T.message)||"Failed to revoke token")}}},D="0.7.39",P=!j||j!==D,N=E.length+y.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:S}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:g}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),j&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${P?"":"bg-bg-secondary"}`,style:P?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",j,!P&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&P&&e.jsx("button",{onClick:w,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${D}`,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${D}`}`}),r&&e.jsx("button",{onClick:()=>u("disconnect"),disabled:f==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>u("revoke"),disabled:f==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Va,{status:t.status==="online"?"online":"error"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[k&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${k.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${k.state==="connecting"||k.state==="new"?"animate-pulse":""}`,style:k.state==="connecting"||k.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",k.state==="connected"?"connected":k.state==="connecting"||k.state==="new"?"connecting...":k.state||"off"]}),k.peers!==void 0&&k.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",k.peers," peer",k.peers!==1?"s":"",")"]})]}),k&&N>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),N>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[E.map(T=>{const G=Ja(T.type),L=T.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:G.icon}),e.jsx("span",{children:G.name}),L!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${L?"bg-green-400":"animate-pulse"}`,style:L?void 0:{background:"var(--status-warning)"},title:L?"CDP connected":"CDP connecting..."})]},T.id)}),y.map(T=>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:T.cliName||"CLI"})]},T.id)),C.map(T=>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:T.cliName||"ACP"})]},T.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(h||l)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||f==="error"?"text-red-400":o==="done"||f==="done"?"text-green-400":"text-text-muted"}`,children:l||h})]}),x==="disconnect"&&e.jsx(Is,{title:"🔌 Disconnect Machine",message:`Disconnect "${g}" from ADHDev?
|
|
43
|
+
|
|
44
|
+
This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
|
|
45
|
+
|
|
46
|
+
Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:_,onCancel:()=>u(null)}),x==="revoke"&&e.jsx(Is,{title:"⚠️ Remove Machine",message:`Remove "${g}" from your dashboard?
|
|
47
|
+
|
|
48
|
+
This will:
|
|
49
|
+
• Immediately disconnect the machine
|
|
50
|
+
• Delete the machine registration
|
|
51
|
+
• Require restarting "adhdev-standalone" on that machine
|
|
52
|
+
|
|
53
|
+
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:B,onCancel:()=>u(null)})]})}const Qa=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function ei(){const{preference:t,setPreference:s}=Sn();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},ti=[{id:"midnight",name:"Midnight",description:"Classic violet theme",preview:{dark:{userBubble:"#8b5cf6",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#7c3aed",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"ember",name:"Ember",description:"Default landing-inspired amber theme",preview:{dark:{userBubble:"#f59e0b",assistantBubble:"#111726",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0a0e1a",textColor:"#9ca3af"},light:{userBubble:"#f59e0b",assistantBubble:"#fffaf4",assistantBorder:"1px solid rgba(146,64,14,0.10)",containerBg:"#fff8ee",textColor:"#6f6255"}}},{id:"aurora",name:"Aurora",description:"Pink accent theme",preview:{dark:{userBubble:"#ec4899",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#ec4899",assistantBubble:"#fef2f8",assistantBorder:"1px solid rgba(236,72,153,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}},{id:"honey",name:"Honey",description:"Warm yellow accents",preview:{dark:{userBubble:"#fbbf24",assistantBubble:"#1c1c1e",assistantBorder:"1px solid rgba(255,255,255,0.06)",containerBg:"#111113",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#fbbf24",assistantBubble:"#fffbeb",assistantBorder:"1px solid rgba(251,191,36,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}}],Cn="adhdev-chat-theme",In="adhdev-chat-theme-custom";function St(){return typeof window>"u"?"ember":localStorage.getItem(Cn)||"ember"}function _e(t){try{const s=localStorage.getItem(In);if(s){const n=JSON.parse(s);return{...t==="dark"?Zt:Qt,...n[t]}}}catch{}return t==="dark"?Zt:Qt}function yt(t,s){localStorage.setItem(In,JSON.stringify({dark:t,light:s}))}function Re(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 At(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 si={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function ct(t,s){var i;const n=(i=si[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",At(n,24)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${At(n,18)})`),r.style.setProperty("--border-accent",Re(n,.35)),r.style.setProperty("--nav-active-bg",Re(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Re(n,.06)}`)}function He(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Re(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Re(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Re(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",Re(t.borderSubtle,.5)),s.style.setProperty("--border-default",Re(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",At(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${At(t.accentColor,40)})`),s.style.setProperty("--border-accent",Re(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Re(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Re(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 ${Re(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 os(){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 ni(t){if(localStorage.setItem(Cn,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Ve()?"dark":"light";He(_e(s))}else os(),ct(t,Ve()?"dark":"light")}function ri(){const t=St();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Ve()?"dark":"light";He(_e(s))}else os(),ct(t,Ve()?"dark":"light")}function Ve(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Ce({label:t,value:s,onChange:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("input",{type:"color",value:s,onChange:r=>n(r.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:r=>{/^#[0-9a-fA-F]{0,6}$/.test(r.target.value)&&n(r.target.value)},style:{width:72,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function st({title:t,children:s}){return e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("div",{style:{fontSize:"0.65rem",fontWeight:700,textTransform:"uppercase",color:"var(--text-muted)",letterSpacing:"0.08em",marginBottom:8,borderBottom:"1px solid var(--border-subtle)",paddingBottom:4},children:t}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s})]})}function ai({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,i]=a.useState(()=>_e(n));a.useEffect(()=>{i(_e(n))},[n]);const o=a.useCallback((c,h)=>{i(d=>{const x={...d,[c]:h},f=_e(n==="dark"?"light":"dark");return n==="dark"?yt(x,f):yt(f,x),He(x),s(x),x})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 18px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{children:[e.jsxs(st,{title:"App Background",children:[e.jsx(Ce,{label:"Background",value:r.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(Ce,{label:"Surface",value:r.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(Ce,{label:"Card",value:r.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(st,{title:"App Text",children:[e.jsx(Ce,{label:"Primary",value:r.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(Ce,{label:"Secondary",value:r.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(Ce,{label:"Muted",value:r.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(st,{title:"Borders & Accent",children:[e.jsx(Ce,{label:"Border subtle",value:r.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(Ce,{label:"Border default",value:r.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(Ce,{label:"Accent",value:r.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(st,{title:"Chat Bubbles",children:[e.jsx(Ce,{label:"User bubble",value:r.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(Ce,{label:"User text",value:r.userText,onChange:c=>o("userText",c)}),e.jsx(Ce,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(Ce,{label:"Agent text",value:r.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(st,{title:"Chat Layout",children:[e.jsx(Ce,{label:"Chat BG",value:r.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(Ce,{label:"Send button",value:r.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(Ce,{label:"Input border",value:r.inputBorder,onChange:c=>o("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:r.bubbleRadius,onChange:c=>o("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?Zt:Qt,d=_e(t?"light":"dark");t?yt(c,d):yt(d,c),i(c),He(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 ii(){const[t,s]=a.useState(St),[n,r]=a.useState(!0),[i,o]=a.useState(()=>_e("dark"));a.useEffect(()=>{r(Ve());const d=new MutationObserver(()=>{const f=Ve();r(f);const p=St();p==="custom"?He(_e(f?"dark":"light")):ct(p,f?"dark":"light")});d.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{const f=Ve();r(f);const p=St();p==="custom"?He(_e(f?"dark":"light")):ct(p,f?"dark":"light")};return x.addEventListener("change",u),()=>{d.disconnect(),x.removeEventListener("change",u)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?He(_e(n?"dark":"light")):(os(),ct(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{o(_e(n?"dark":"light"))},[n]);const c=d=>{s(d),ni(d)},h=[...ti,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:h.map(d=>{const x=t===d.id,u=n?d.preview.dark:d.preview.light,f=d.id==="honey"||d.id==="ember"?"#1a1a1a":d.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(d.id),className:"text-left rounded-xl p-3 transition-all",style:{background:x?"var(--bg-glass-hover)":"var(--bg-glass)",border:x?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:x?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:u.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.userBubble,color:f},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:d.id==="custom"?"🎨 Custom":d.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:d.description})]})]})]},d.id)})}),t==="custom"&&e.jsx(ai,{dark:n,onColorsChange:d=>o(d)})]})}const Mn="adhdev_mobileDashboardMode_v1";function Tn(){try{return localStorage.getItem(Mn)==="workspace"?"workspace":"chat"}catch{return"chat"}}function oi(t){try{localStorage.setItem(Mn,t)}catch{}}function ci(){const[t,s]=a.useState(!1);return a.useEffect(()=>{s(Tn()==="workspace")},[]),e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ht,{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),oi(n?"workspace":"chat")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Workspace":"Chat mode"})})}const Rn="adhdev_hiddenTabs";function li(){try{const t=localStorage.getItem(Rn);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function nt(t){try{localStorage.setItem(Rn,JSON.stringify([...t]))}catch{}}function An(){const[t,s]=a.useState(li),n=a.useCallback(d=>{s(x=>{const u=new Set(x);return u.has(d)?u.delete(d):u.add(d),nt(u),u})},[]),r=a.useCallback(d=>{s(x=>{if(x.has(d))return x;const u=new Set(x);return u.add(d),nt(u),u})},[]),i=a.useCallback(d=>{s(x=>{if(!x.has(d))return x;const u=new Set(x);return u.delete(d),nt(u),u})},[]),o=a.useCallback((d,x)=>{s(u=>{const f=new Set(u);for(const p of x)f.add(p);return nt(f),f})},[]),c=a.useCallback((d,x)=>{s(u=>{const f=new Set(u);for(const p of x)f.delete(p);return nt(f),f})},[]),h=a.useCallback(d=>t.has(d),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:i,hideAllForDaemon:o,showAllForDaemon:c,isHidden:h}}function di({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){a.useEffect(()=>{Da()},[]);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 Ba(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{n(h=>{const d=Date.now(),x={};for(const[u,f]of Object.entries(h))d-f<5e3&&(x[u]=f);return Object.keys(x).length===Object.keys(h).length?h:x})},5500);return()=>clearTimeout(c)},[s,n]),a.useEffect(()=>{const o=setInterval(()=>{const c=Date.now()-3e5;r(h=>{const d=h.filter(x=>x.timestamp>c).slice(-100);return d.length===h.length?h:d})},6e4);return()=>clearInterval(o)},[r]),null}function ui(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 vt(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 hi(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 mi(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 pi(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 xi({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:i}){const o=a.useRef([]),c=a.useRef([]),h=a.useRef([]),d=a.useRef([]),x=a.useMemo(()=>{const g=ui(t);return vt(o.current,g)?o.current:(o.current=g,g)},[t]),u=a.useMemo(()=>gn(t),[t]),f=a.useRef(new Map),p=a.useMemo(()=>{var E;const g=new Map,S=[];for(const y of x){const C=y.daemonId||((E=y.id)==null?void 0:E.split(":")[0])||y.id,k=s[C]||"new",w=y.daemonId&&u[y.daemonId]||void 0,_=mi(y,n),B=f.current.get(y.id);if(B&&B.ide===y&&B.connectionState===k&&B.machineName===w&&pi(B.localRefs,_)){g.set(y.id,B),S.push(...B.conversations);continue}const D=yn(y,n,{machineName:w,connectionState:k}),P={ide:y,connectionState:k,machineName:w,localRefs:_,conversations:D};g.set(y.id,P),S.push(...D)}return f.current=g,S},[x,n,s,u]),l=a.useMemo(()=>{const g=hi(p,r);return vt(c.current,g)?c.current:(c.current=g,g)},[p,r]),b=a.useMemo(()=>{const g=new Map;for(const S of l)S.sessionId&&g.set(S.sessionId,S),g.set(S.ideId,S),g.set(S.tabKey,S),g.set(S.ideType,S),g.set(S.agentType,S);return g},[l]),v=a.useCallback(g=>{if(g)return b.get(g)},[b]),j=a.useMemo(()=>{const g=l.filter(S=>!i.has(S.tabKey));return vt(h.current,g)?h.current:(h.current=g,g)},[l,i]),m=a.useMemo(()=>{const g=j.map(S=>S.tabKey);return vt(d.current,g)?d.current:(d.current=g,g)},[j]);return{chatIdes:x,conversations:l,visibleConversations:j,visibleTabKeys:m,resolveConversationByTarget:v}}function fi({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 d=new URLSearchParams(h);return d.delete("activeTab"),d},{replace:!0})},[r,s]);return{requestedDesktopTabKey:i,requestedMobileTabKey:o,consumeRequestedActiveTab:c}}function bi({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:i}){a.useEffect(()=>{Ke.setIdes(t)},[t]),a.useEffect(()=>{Ke.setResolveAction((o,c,h)=>{s(o,c,h).catch(()=>{})})},[s]),a.useEffect(()=>{const o=Ke.onToast(d=>{n(u=>u.some(p=>p.message===d.message&&d.timestamp-p.timestamp<3e3)?u:[...u.slice(-4),{id:d.id,message:d.message,type:d.type,timestamp:d.timestamp,targetKey:d.targetKey,actions:d.actions}]);const x=d.duration||5e3;setTimeout(()=>n(u=>u.filter(f=>f.id!==d.id)),x)}),c=Ke.onSystemMessage((d,x)=>{r(u=>({...u,[d]:[...u[d]||[],x]}))}),h=Ke.onClearSystemMessage((d,x)=>{r(u=>{var f;return(f=u[d])!=null&&f.length?{...u,[d]:u[d].filter(p=>{var l;return!(p.role==="system"&&((l=p._localId)!=null&&l.startsWith(x)))})}:u})});return()=>{o(),c(),h()}},[n,r]),a.useEffect(()=>{const o=mn.on("status_event",c=>Ke.handleRawEvent(c,"ws"));return()=>{o()}},[]),a.useEffect(()=>{var c;const o=h=>{const d=h.data;if((d==null?void 0:d.type)!=="notification_action"||d.action!=="approve"||!(d.ideId||d.targetSessionId||d.targetKey))return;const x=d.targetSessionId||d.targetKey||d.ideId,u=i(x),f=(u==null?void 0:u.ideId)||d.ideId;f&&s(f,"resolve_action",{action:"approve",button:"Approve",...(u==null?void 0:u.sessionId)&&{targetSessionId:u.sessionId},...d.targetSessionId&&{targetSessionId:d.targetSessionId}}).catch(p=>console.error("[SW Action] approve failed:",p))};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 gi="adhdev_dashboardLayout_v1",yi="adhdev_dashboardDockview_v1",rt={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function En(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function _n(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function Pn(t){return`${gi}:${t}`}function vi(t){const s=Pn(t);return En(s,null)}function ji(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=Pn(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Ln(t){return`${yi}:${t}`}function wi(t){const s=Ln(t);return En(s,null)}function ki(t,s){try{const n=Ln(t);if(!s){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function Ni(){return{groupAssignments:[...rt.groupAssignments],focusedGroup:rt.focusedGroup,groupActiveTabIds:{...rt.groupActiveTabIds},groupTabOrders:{...rt.groupTabOrders},groupSizes:[...rt.groupSizes]}}function Si(){const[t]=a.useState(()=>_n(typeof window<"u"?window.innerWidth:1280)),[s,n]=a.useState(()=>new Map),[r,i]=a.useState(0),[o,c]=a.useState({}),[h,d]=a.useState({}),[x,u]=a.useState([]),[f,p]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[l,b]=a.useState(!1),v=a.useCallback(()=>{if(l)return;const j=vi(t)??Ni();n(new Map(j.groupAssignments)),i(j.focusedGroup),c(j.groupActiveTabIds),d(j.groupTabOrders),u(j.groupSizes),b(!0)},[l,t]);return a.useEffect(()=>{l&&ji(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:o,groupTabOrders:h,groupSizes:x})},[l,t,s,r,o,h,x]),a.useEffect(()=>{const j=window.matchMedia("(max-width: 767px)"),m=g=>p(g.matches);return j.addEventListener("change",m),()=>j.removeEventListener("change",m)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:h,setGroupTabOrders:d,groupSizes:x,setGroupSizes:u,isMobile:f,hasHydratedStoredLayout:l,hydrateStoredLayout:v}}function Ci({urlActiveTab:t,conversations:s,resolveConversationByTarget:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:h,setSearchParams:d,historyModalOpen:x,activeConv:u,isRefreshingHistory:f,ides:p,handleRefreshHistory:l}){const b=a.useRef(!1),v=a.useRef(!1),j=a.useRef(null),m=a.useRef(!1);a.useEffect(()=>{if(!t||b.current||s.length===0)return;if(!i){o();return}const g=n(t);if(!g)return;const S=r.get(g.tabKey)??0;c(E=>({...E,[S]:g.tabKey})),h(S),b.current=!0,v.current=!0,j.current!=null&&(window.clearTimeout(j.current),j.current=null),d(E=>{const y=new URLSearchParams(E);return y.delete("activeTab"),y},{replace:!0})},[t,s,n,r,i,o,c,h,d]),a.useEffect(()=>{if(!(v.current||i)&&s.length!==0){if(!t){o(),v.current=!0;return}if(b.current){v.current=!0;return}if(j.current==null)return j.current=window.setTimeout(()=>{j.current=null,!(v.current||i)&&(o(),v.current=!0)},1500),()=>{j.current!=null&&(window.clearTimeout(j.current),j.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!x){m.current=!1;return}if(!u||m.current||f)return;const g=p.find(S=>S.id===u.ideId);g&&(!g.chats||g.chats.length===0)&&(m.current=!0,l())},[x,u,f,p,l]),a.useEffect(()=>{if(!u)return;let g=null,S=0,E=-1,y=0;const C=()=>{g=null;const k=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(_=>_.offsetParent!==null);if(k.length===0){S<18&&(S+=1,g=requestAnimationFrame(C));return}let w=0;for(const _ of k)_.scrollTop=_.scrollHeight,w+=_.scrollHeight;w===E?y+=1:(y=0,E=w),S+=1,!(y>=2||S>=18)&&(g=requestAnimationFrame(C))};return g=requestAnimationFrame(C),()=>{g!=null&&cancelAnimationFrame(g)}},[u==null?void 0:u.tabKey])}function Ii({isMobile:t,location:s,navigate:n,requestedRemoteTabTarget:r,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:h}){const[d,x]=a.useState(null),[u,f]=a.useState(null),p=a.useMemo(()=>{if(t||!r)return null;const m=h(r);return m&&!Se(m)&&!ke(m)?m:null},[t,r,h]),l=a.useMemo(()=>{const m=d==null?void 0:d.ideId;if(!m)return null;const g=d!=null&&d.tabKey?o.find(S=>S.tabKey===d.tabKey):i?o.find(S=>S.tabKey===i):null;return(g==null?void 0:g.ideId)===m?g:o.find(S=>S.ideId===m&&S.streamSource==="native")||o.find(S=>S.ideId===m)||null},[o,d,i]),b=a.useMemo(()=>{if(l)return c.find(m=>m.id===l.ideId)},[c,l]);a.useEffect(()=>{p&&(x({ideId:p.ideId,tabKey:p.streamSource==="native"?"native":p.tabKey}),f(p),n({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,n,p]);const v=a.useCallback(m=>{m&&(x({ideId:m.ideId,tabKey:m.streamSource==="native"?"native":m.tabKey}),f(m))},[]),j=a.useCallback(()=>{x(null),f(null)},[]);return{remoteDialogConv:l,remoteDialogIdeEntry:b,remoteDialogActiveConv:u,setRemoteDialogActiveConv:f,openRemoteDialog:v,closeRemoteDialog:j}}function lt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Se(t)||ke(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function Et(t){return t&&(t.ideId||t.daemonId)||""}function jt(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function Ms({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:i,setClearedTabs:o}){const[c,h]=a.useState(!1),[d,x]=a.useState(!1),u=a.useCallback(async b=>{try{await t("standalone","launch_ide",{ideType:b,enableCdp:!0})}catch(v){console.error("Launch failed",v)}},[t]),f=a.useCallback(async(b,v)=>{try{const j=b||(s==null?void 0:s.daemonId)||"",m=await t(j,"switch_chat",{id:v,sessionId:v,...lt(s)}),g=m==null?void 0:m.result;if((m==null?void 0:m.success)===!0||g==="switched"||g==="switched-by-title")return;g===!1||g==="not_found"?jt(r,"⚠️ Session tab not found — try refreshing history"):typeof g=="string"&&g.startsWith("error:")?jt(r,`⚠️ Switch error: ${g}`):jt(r,"⚠️ Session switch failed")}catch(j){console.error("Switch failed",j),jt(r,`❌ Switch failed: ${j.message||"connection error"}`)}},[s,t,r]),p=a.useCallback(async()=>{if(!(!s||c)){h(!0);try{const b=Et(s);await t(b,"new_chat",{...lt(s)}),o(v=>({...v,[s.tabKey]:Date.now()})),i(v=>({...v,[s.tabKey]:[]}))}catch(b){console.error("New chat failed",b)}finally{h(!1)}}},[s,c,t,o,i]),l=a.useCallback(async()=>{var b;if(!(!s||d)){x(!0);try{const v=Et(s),j=await t(v,"list_chats",{forceExpand:!0,...lt(s)}),m=(j==null?void 0:j.chats)||((b=j==null?void 0:j.result)==null?void 0:b.chats);j!=null&&j.success&&Array.isArray(m)&&n(s.ideId,m)}catch(v){console.error("Refresh history failed",v)}finally{x(!1)}}},[s,d,t,n]);return{isCreatingChat:c,isRefreshingHistory:d,handleLaunchIde:u,handleSwitchSession:f,handleNewChat:p,handleRefreshHistory:l}}function Mi(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 Ti(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function Ts(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 wt(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 d=i[h];typeof d=="number"&&d>0&&o.set(c,d)}return{assignments:o,groupCount:Math.max(1,r.length),mapping:i,usedGroups:r}}function Rs(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 Ri(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 Ai(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 As(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 Es(t){return Array(t).fill(100/t)}function Ei({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:h,visibleConversations:d,visibleTabKeys:x}){const u=a.useRef(null),f=a.useMemo(()=>wt(t,x),[t,x]),p=f.assignments,l=a.useMemo(()=>h?1:f.groupCount,[f.groupCount,h]),b=l>1,v=a.useCallback((y,C)=>{s(k=>{const w=new Map(wt(k,x).assignments);return C===0?w.delete(y):w.set(y,C),w}),r(k=>({...k,[C]:y})),n(C)},[s,x,r,n]),j=a.useCallback(y=>{s(C=>{const k=wt(C,x).assignments,w=new Map;for(const[_,B]of k)B!==y&&(B>y?w.set(_,B-1):w.set(_,B));return w}),c(C=>{if(C.length<=1)return[];const k=[...C];k.splice(y,1);const w=k.reduce((_,B)=>_+B,0);return w>0?k.map(_=>_/w*100):[]}),n(0)},[s,x,c,n]),m=a.useCallback((y,C)=>{C.preventDefault();const k=u.current;if(!k)return;const w=C.clientX,_=k.offsetWidth,B=o.length===l?[...o]:Es(l),D=N=>{const $=(N.clientX-w)/_*100,T=[...B];T[y]=Math.max(15,B[y]+$),T[y+1]=Math.max(15,B[y+1]-$),c(T)},P=()=>{document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",P),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",D),document.addEventListener("mouseup",P)},[o,l,c]),g=a.useCallback((y,C,k)=>{if(l>=4)return;const w=k==="left"?C:C+1;s(_=>{const B=wt(_,x).assignments,D=new Map;for(const P of d){const N=B.get(P.tabKey)??0,A=N>=w?N+1:N;A>0&&D.set(P.tabKey,A)}return w>0&&D.set(y,w),D}),c(_=>{const B=_.length===l?[..._]:Es(l),D=B[C]??100/l,P=Math.max(15,D/2),N=Math.max(15,D/2),A=[...B];A[C]=P,A.splice(w,0,N);const $=A.reduce((T,G)=>T+G,0);return A.map(T=>T/$*100)}),r(_=>{const B=As(_,w);return B[w]=y,B}),i(_=>{const B=As(_,w);return B[w]=[y],B}),n(w)},[l,s,x,d,c,r,i,n]);a.useEffect(()=>{Mi(t,p)||s(p)},[t,p,s]),a.useEffect(()=>{const{mapping:y,usedGroups:C}=f;r(k=>{const w=Rs(k,y);return Ts(k,w)?k:w}),i(k=>{const w=Rs(k,y);return Ts(k,w)?k:w}),n(k=>{const w=h?0:Ri(k,C,y);return k===w?k:w}),c(k=>{const w=h?[]:Ai(k,C,f.groupCount);return Ti(k,w)?k:w})},[f,h,r,i,n,c]);const S=a.useMemo(()=>{const y=Array.from({length:l},()=>[]);for(const C of d){const k=p.get(C.tabKey)??0,w=Math.min(k,l-1);y[w].push(C)}return y},[d,p,l]),E=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:u,normalizedGroupAssignments:p,numGroups:l,isSplitMode:b,groupedConvs:S,moveTabToGroup:v,closeGroup:j,handleResizeStart:m,splitTabRelative:g,clearAllSplits:E}}function _i({ides:t,sendDaemonCommand:s}){const n="0.7.39",r=a.useMemo(()=>t.filter(x=>{if(x.type!=="adhdev-daemon")return!1;const u=x.version||x.daemonVersion||null;return!u||!n?!1:u!==n}),[n,t]),[i,o]=a.useState(!1),[c,h]=a.useState({}),d=a.useCallback(async x=>{var u,f;h(p=>({...p,[x]:"upgrading"}));try{const p=await s(x,"daemon_upgrade",{});(u=p==null?void 0:p.result)!=null&&u.upgraded||(f=p==null?void 0:p.result)!=null&&f.success?h(l=>({...l,[x]:"done"})):h(l=>({...l,[x]:"error"}))}catch{h(p=>({...p,[x]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:d}}function $t({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:i}){const[o,c]=a.useState(!1),[h,d]=a.useState(!1),x=a.useRef(!1),u=a.useCallback(async b=>{if(!s)return;const v=b.trim();if(!v||x.current)return;const j=s.tabKey;x.current=!0,d(!0);const m=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,g={role:"user",content:v,timestamp:Date.now(),_localId:m};n(S=>({...S,[j]:[...S[j]||[],g]}));try{const S=Et(s);if(!S)return;await t(S,"send_chat",{message:v,text:v,...lt(s)}),setTimeout(()=>{const E=Date.now()-6e4;n(y=>{const C=y[j];if(!C)return y;const k=C.filter(w=>w.timestamp>E);return k.length===C.length?y:{...y,[j]:k}})},6e4)}catch(S){console.error("Send failed",S),n(E=>({...E,[j]:(E[j]||[]).filter(y=>y._localId!==m)}))}finally{x.current=!1,d(!1)}},[s,t,n]),f=a.useCallback(async()=>{if(s)try{await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0})}catch(b){console.error("Relaunch failed",b)}},[s,t]),p=a.useCallback(async b=>{if(s){r(v=>[...v,{ideId:s.tabKey,text:`🖱️ **${b}** clicked`,timestamp:Date.now()}]);try{const j=(s.modalButtons||[]).indexOf(b),m=b.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),g=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(m),S=Et(s);if(!S)return;(await t(S,"resolve_action",{button:b,action:g?"approve":"reject",...j>=0&&{buttonIndex:j},...lt(s)})).success||r(y=>[...y,{ideId:s.tabKey,text:`⚠️ **${b}** failed — button not found`,timestamp:Date.now()}])}catch(v){console.error("[ModalButton] Error:",v),r(j=>[...j,{ideId:s.tabKey,text:`❌ **${b}** error`,timestamp:Date.now()}])}}},[s,t,r]),l=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(b){console.error("Focus agent failed",b)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:h,isFocusingAgent:o,handleSendChat:u,handleRelaunch:f,handleModalButton:p,handleFocusAgent:l}}function Pi({selectedConversation:t,isAcp:s,selectedIdeEntry:n,actionLogs:r,userName:i,isSendingChat:o,isFocusingAgent:c,onBack:h,onOpenNativeConversation:d,onOpenMachine:x,onOpenHistory:u,onOpenRemote:f,handleSendChat:p,handleFocusAgent:l}){const b=a.useRef(null),v=Se(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(Gs,{size:18})}),e.jsxs("div",{className:"dashboard-mobile-chat-title-block",children:[e.jsx("div",{className:"dashboard-mobile-chat-title",children:t.displayPrimary||t.agentName}),e.jsx("div",{className:"dashboard-mobile-chat-subtitle",children:e.jsx(un,{conversation:t,onOpenNativeConversation:()=>d(t),onOpenMachine:()=>x(t)})})]})]}),e.jsxs("div",{className:"dashboard-mobile-chat-toolbar",children:[e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>u(t),type:"button",children:e.jsx(ss,{size:14})}),!s&&!v&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>f(t),type:"button",children:e.jsx(Ee,{size:14})})]})]}),e.jsx("div",{className:"dashboard-mobile-chat-thread",children:v?e.jsx(pn,{activeConv:t,terminalRef:b,handleSendChat:p,isSendingChat:o}):e.jsx(rs,{activeConv:t,ideEntry:n,showMetaChips:!1,handleSendChat:p,isSendingChat:o,handleFocusAgent:l,isFocusingAgent:c,actionLogs:r,userName:i},t.tabKey)})]})}function Li({section:t,attentionItems:s,unreadItems:n,workingItems:r,completedItems:i,machineCards:o,getAvatarText:c,getConversationPreview:h,onOpenConversation:d,onOpenMachine:x,onOpenSettings:u,onSectionChange:f}){const p=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:p})})}),t==="chats"&&(s.length>0||n.length>0)&&e.jsxs("div",{className:"dashboard-mobile-chat-header-pill",children:[e.jsx(Dt,{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(l=>e.jsxs("button",{className:"dashboard-mobile-chat-card",onClick:()=>x(l.id),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar machine",children:c(l.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:l.label}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:l.unread>0?`${l.unread} new`:`${l.total} chats`})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:l.subtitle}),e.jsxs("div",{className:"dashboard-mobile-chat-card-preview",children:[l.latestConversation.displayPrimary," · ",h(l.latestConversation)]})]})]},l.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(l=>e.jsxs("button",{className:"dashboard-mobile-chat-card is-unread",onClick:()=>d(l.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar unread",children:c(l.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:l.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:at(l.timestamp)})]}),e.jsxs("div",{className:"dashboard-mobile-chat-card-subtitle",children:[l.conversation.displaySecondary," · Action needed"]}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:l.preview})]}),e.jsx("span",{className:"dashboard-mobile-chat-unread-dot"})]},l.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(l=>e.jsxs("button",{className:"dashboard-mobile-chat-card is-unread",onClick:()=>d(l.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar unread",children:c(l.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:l.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:at(l.timestamp)})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:l.conversation.displaySecondary}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:l.preview})]}),e.jsx("span",{className:"dashboard-mobile-chat-unread-dot"})]},l.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(l=>e.jsxs("button",{className:"dashboard-mobile-chat-card",onClick:()=>d(l.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar working",children:c(l.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:l.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:at(l.timestamp)})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:l.conversation.displaySecondary}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:l.preview})]}),e.jsx("span",{className:"dashboard-mobile-chat-status-badge",children:"Live"})]},l.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(l=>e.jsxs("button",{className:"dashboard-mobile-chat-card is-muted",onClick:()=>d(l.conversation),type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar",children:c(l.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:l.conversation.displayPrimary}),e.jsx("span",{className:"dashboard-mobile-chat-card-time",children:at(l.timestamp)})]}),e.jsx("div",{className:"dashboard-mobile-chat-card-subtitle",children:l.conversation.displaySecondary}),e.jsx("div",{className:"dashboard-mobile-chat-card-preview",children:l.preview})]})]},l.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:u,type:"button",children:[e.jsx("span",{className:"dashboard-mobile-chat-avatar settings",children:e.jsx(Lt,{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(([l,b])=>e.jsx("button",{className:`dashboard-mobile-chat-nav-tab${t===l?" is-active":""}`,onClick:()=>f(l),type:"button",children:b},l))})]})}function Di({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentSessions:n,cliProviders:r,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:h,onBack:d,onOpenConversation:x,onOpenRecent:u,onOpenMachineDetails:f,onMachineUpgrade:p,onLaunchDetectedIde:l,onAddWorkspace:b,onLaunchWorkspaceProvider:v}){var z,W,Q;const j=(V,ie,ee)=>V?"ide":ie>0?"cli":ee>0?"acp":null,[m,g]=a.useState(!1),S=V=>V==="ide"?"IDE":V==="cli"?"CLI":"ACP",E=n.slice(0,4),y=s.slice(0,3),C=a.useMemo(()=>{const V=E.map(ee=>({key:`recent-session:${ee.id}`,type:"session",primary:ee.label,secondary:`${S(ee.kind)}${ee.subtitle?` · ${ee.subtitle}`:""}`,unread:!1,onClick:()=>u(ee)})),ie=y.map(ee=>({key:`recent-chat:${ee.conversation.tabKey}`,type:"conversation",primary:ee.conversation.displayPrimary,secondary:`Chat${ee.conversation.displaySecondary?` · ${ee.conversation.displaySecondary}`:""}${ee.timestamp?` · ${at(ee.timestamp)}`:""}`,unread:ee.unread,onClick:()=>x(ee.conversation)}));return[...V,...ie]},[x,u,y,E]),k=m?C:C.slice(0,5),w=C.length>0,_=(((z=t.detectedIdes)==null?void 0:z.length)||0)>0,B=a.useMemo(()=>t.workspaces||[],[t]),D=t.defaultWorkspaceId||null,[P,N]=a.useState(D||((W=B[0])==null?void 0:W.id)||""),[A,$]=a.useState(""),[T,G]=a.useState(j(_,r.length,i.length)),L=a.useRef(null),R=P==="__custom__"?A.trim():((Q=B.find(V=>V.id===P))==null?void 0:Q.path)||"",U=P==="__custom__"&&!!R&&h.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(h.message);return a.useEffect(()=>{var V;L.current!==t.id&&(L.current=t.id,N(D||((V=B[0])==null?void 0:V.id)||"__custom__"),$(""),G(j(_,r.length,i.length)))},[i.length,r.length,D,_,t.id,B]),a.useEffect(()=>{var V;P!=="__custom__"&&(P&&B.some(ie=>ie.id===P)||N(D||((V=B[0])==null?void 0:V.id)||"__custom__"))},[D,P,B]),a.useEffect(()=>{T==="ide"&&_||T==="cli"&&r.length>0||T==="acp"&&i.length>0||G(j(_,r.length,i.length))},[T,i.length,r.length,_]),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:d,type:"button","aria-label":"Back",children:e.jsx(Gs,{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:[w&&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:k.map(V=>e.jsxs("button",{className:`dashboard-mobile-machine-command-card${V.unread?" is-primary":""}`,type:"button",onClick:V.onClick,children:[e.jsx("span",{className:"dashboard-mobile-machine-command-label",children:V.primary}),e.jsx("span",{className:"dashboard-mobile-machine-command-meta",children:V.secondary})]},V.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:()=>g(V=>!V),children:m?"Show fewer":`Show ${C.length-5} more`})})]}),(_||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:P,onChange:V=>{N(V.target.value),V.target.value!=="__custom__"&&$("")},className:"dashboard-mobile-machine-workspace-select",children:B.length>0?e.jsxs(e.Fragment,{children:[B.map(V=>e.jsxs("option",{value:V.id,children:[V.id===D?"⭐ ":"",V.label||V.path.split("/").filter(Boolean).pop()||V.path]},V.id)),e.jsx("option",{value:"__custom__",children:"Custom path…"})]}):e.jsx("option",{value:"__custom__",children:"Enter workspace path…"})}),P==="__custom__"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",value:A,onChange:V=>$(V.target.value),placeholder:"/absolute/path",className:"dashboard-mobile-machine-workspace-input"}),e.jsx("button",{type:"button",className:"dashboard-mobile-machine-workspace-save",onClick:()=>{R&&b(R)},children:"Save workspace"})]}),R&&e.jsx("div",{className:"dashboard-mobile-machine-workspace-preview",children:R})]})}),e.jsxs("div",{className:"dashboard-mobile-machine-openwith",children:[_&&e.jsx("button",{className:`dashboard-mobile-machine-openwith-btn${T==="ide"?" is-active":""}`,type:"button",onClick:()=>G("ide"),children:"IDE"}),r.length>0&&e.jsx("button",{className:`dashboard-mobile-machine-openwith-btn${T==="cli"?" is-active":""}`,type:"button",onClick:()=>G("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`dashboard-mobile-machine-openwith-btn${T==="acp"?" is-active":""}`,type:"button",onClick:()=>G("acp"),children:"ACP"})]}),T&&e.jsxs("div",{className:"dashboard-mobile-machine-provider-picker",children:[e.jsx("div",{className:"dashboard-mobile-machine-provider-title",children:T==="ide"?"Choose an IDE":T==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"dashboard-mobile-machine-provider-grid",children:T==="ide"?(t.detectedIdes||[]).slice(0,6).map(V=>e.jsxs("button",{type:"button",className:"dashboard-mobile-machine-provider-btn",onClick:()=>l(V.type,{workspacePath:R||null}),children:[e.jsx("span",{className:"dashboard-mobile-machine-provider-name",children:V.name}),e.jsx("span",{className:"dashboard-mobile-machine-provider-meta",children:R||"Use selected workspace"})]},V.type)):(T==="cli"?r:i).map(V=>e.jsxs("button",{type:"button",className:"dashboard-mobile-machine-provider-btn",onClick:()=>v(T,V.type,{workspaceId:P!=="__custom__"?P:null,workspacePath:R||null}),children:[e.jsxs("span",{className:"dashboard-mobile-machine-provider-name",children:[V.icon?`${V.icon} `:"",V.displayName]}),e.jsx("span",{className:"dashboard-mobile-machine-provider-meta",children:R||"Use selected workspace"})]},V.type))})]}),h.message&&e.jsxs("div",{className:`dashboard-mobile-machine-action-note is-${h.state}`,children:[h.message,U&&e.jsx("div",{className:"dashboard-mobile-machine-action-cta-row",children:e.jsx("button",{type:"button",className:"dashboard-mobile-machine-action-cta",onClick:()=>b(R,{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:p,children:[e.jsxs("span",{className:"dashboard-mobile-machine-command-label",children:["Update to v",c]}),e.jsx("span",{className:"dashboard-mobile-machine-command-meta",children:"Restart this machine with the latest daemon"})]}),e.jsxs("button",{className:"dashboard-mobile-machine-command-card",type:"button",onClick:f,children:[e.jsx("span",{className:"dashboard-mobile-machine-command-label",children:"Machine details"}),e.jsx("span",{className:"dashboard-mobile-machine-command-meta",children:"Sessions, providers, system info, and logs"})]})]})]})]})]})}const Dn="adhdev_mobileChatReads_v1";function $i(){try{const t=localStorage.getItem(Dn);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 Bi(t){try{localStorage.setItem(Dn,JSON.stringify(t))}catch{}}function Ki(t){return bn(t)}function Je(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||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 _s(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1],n=Ki(s==null?void 0:s.content);return n||(t.title?t.title:t.displaySecondary||"No messages yet")}function Oi(t){return t.transport==="acp"?"acp":t.transport==="pty"?"cli":"ide"}function Wi(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function zi({conversations:t,ides:s,actionLogs:n,sendDaemonCommand:r,setLocalUserMessages:i,setActionLogs:o,isStandalone:c,userName:h,requestedActiveTabKey:d,onRequestedActiveTabConsumed:x,requestedMachineId:u,onRequestedMachineConsumed:f,onOpenHistory:p,onOpenRemote:l}){const[b,v]=a.useState(()=>{var K;return((K=t[0])==null?void 0:K.tabKey)||null}),[j,m]=a.useState(()=>t[0]?"chat":"inbox"),[g,S]=a.useState("chats"),[E,y]=a.useState(()=>$i()),[C,k]=a.useState(null),[w,_]=a.useState("inbox"),[B,D]=a.useState("idle"),[P,N]=a.useState(""),A=tt(),$="0.7.39",T=a.useMemo(()=>t.find(K=>K.tabKey===b)||t[0]||null,[t,b]),G=a.useMemo(()=>T?s.find(K=>K.id===T.ideId):void 0,[s,T]),L=a.useMemo(()=>s.filter(K=>K.type==="adhdev-daemon"||K.daemonMode),[s]),R=a.useMemo(()=>L.find(K=>K.id===C)||null,[L,C]),U=a.useMemo(()=>t.filter(K=>!xn(K)),[t]),z=$t({sendDaemonCommand:r,activeConv:T||void 0,setLocalUserMessages:i,setActionLogs:o,isStandalone:c}),W=a.useCallback(K=>{if(!K)return;const F=Math.max(Date.now(),Je(K));y(re=>{const ce={...re},ae=K.recentKey||K.tabKey;return(ce[ae]||0)>=F?re:(ce[ae]=F,Bi(ce),ce)}),r(K.daemonId||K.ideId,"mark_recent_seen",{recentKey:K.recentKey,kind:Oi(K),providerType:K.agentType||K.ideType,workspace:K.workspaceName||null,seenAt:F}).catch(()=>{})},[r]);a.useEffect(()=>{var K;if(!T){m("inbox"),v(((K=t[0])==null?void 0:K.tabKey)||null);return}j==="chat"&&W(T)},[t,W,j,T]),a.useEffect(()=>{if(!d)return;const K=t.find(F=>F.tabKey===d);K&&(v(K.tabKey),m("chat"),x==null||x())},[t,x,d]),a.useEffect(()=>{if(!u)return;const K=L.find(F=>F.id===u);K&&(k(K.id),D("idle"),N(""),S("machines"),_("inbox"),m("machine"),f==null||f())},[L,f,u]);const Q=a.useMemo(()=>U.map(K=>{const F=Je(K),re=_s(K),ce=K.inboxBucket||"idle",ae=ce==="working",he=ce==="needs_attention",je=j==="chat"&&(T==null?void 0:T.tabKey)===K.tabKey,Ne=K.recentKey||K.tabKey,Be=K.lastSeenAt||0,Ye=E[Ne]||0,Ot=Ye>Be&&F>0&&F<=Ye,Xe=ce==="task_complete"&&!je&&!!K.unread&&!Ot;return{conversation:K,timestamp:F,preview:re,unread:Xe,requiresAction:he,isWorking:ae,inboxBucket:he?"needs_attention":ae?"working":Xe?"task_complete":"idle"}}).sort((K,F)=>F.timestamp-K.timestamp),[U,E,j,T]),V=a.useMemo(()=>Q.filter(K=>K.requiresAction),[Q]),ie=a.useMemo(()=>Q.filter(K=>K.unread&&!K.requiresAction),[Q]),ee=a.useMemo(()=>Q.filter(K=>!K.unread&&!K.requiresAction&&K.isWorking),[Q]),O=a.useMemo(()=>Q.filter(K=>!K.unread&&!K.requiresAction&&!K.isWorking),[Q]),Y=a.useMemo(()=>R?Q.filter(K=>K.conversation.daemonId===R.id||K.conversation.ideId===R.id):[],[Q,R]),H=a.useMemo(()=>{if(!R)return[];const K=R.recentSessions||[];return K.length>0?K.map(F=>({id:F.id,sessionId:F.sessionId||F.id,label:F.title||F.providerName||F.providerType,kind:F.kind,providerType:F.providerType,subtitle:F.currentModel||F.workspace||void 0,workspace:F.workspace,currentModel:F.currentModel})):s.filter(F=>!F.daemonMode&&F.daemonId===R.id).map(F=>{var ce,ae,he,je,Ne;const re=Tt(F)?"cli":it(F)?"acp":"ide";return{id:F.id,sessionId:F.id,label:((ce=F.activeChat)==null?void 0:ce.title)||(Tt(F)?F.cliName||F.type:it(F)&&F.cliName||F.type),kind:re,providerType:F.type,subtitle:it(F)?F.currentModel||F.workspace||void 0:F.workspace||void 0,workspace:F.workspace||void 0,currentModel:F.currentModel,timestamp:((Ne=(je=(he=(ae=F.activeChat)==null?void 0:ae.messages)==null?void 0:he.at)==null?void 0:je.call(he,-1))==null?void 0:Ne.timestamp)||0}}).sort((F,re)=>re.timestamp-F.timestamp).map(({timestamp:F,...re})=>re)},[s,R]),I=(R==null?void 0:R.version)||(R==null?void 0:R.daemonVersion)||null,J=!!R&&!!I&&!0&&I!==$,q=a.useMemo(()=>(R==null?void 0:R.availableProviders)||[],[R]),te=a.useMemo(()=>q.filter(K=>K.category==="cli").map(K=>({type:K.type,displayName:K.displayName||K.type,icon:K.icon})),[q]),ue=a.useMemo(()=>q.filter(K=>K.category==="acp").map(K=>({type:K.type,displayName:K.displayName||K.type,icon:K.icon})),[q]),de=a.useMemo(()=>{const K=new Map;for(const F of Q){const re=F.conversation.daemonId||F.conversation.ideId,ce=K.get(re);if(!ce){K.set(re,{id:re,label:F.conversation.machineName||F.conversation.displaySecondary||"Machine",subtitle:F.conversation.connectionState==="connected"?"Connected":F.conversation.connectionState||"Unknown",unread:F.unread?1:0,total:1,latestConversation:F.conversation});continue}ce.total+=1,F.unread&&(ce.unread+=1),Je(F.conversation)>Je(ce.latestConversation)&&(ce.latestConversation=F.conversation)}return Array.from(K.values()).sort((F,re)=>Je(re.latestConversation)-Je(F.latestConversation))},[Q]),le=a.useCallback(K=>{v(K.tabKey),m("chat"),W(K)},[W]),Z=a.useCallback(K=>{const F=U.find(re=>re.ideId===K.ideId&&re.streamSource==="native");F&&(v(F.tabKey),m("chat"),W(F))},[W,U]),oe=a.useCallback(()=>{W(T),m("inbox")},[W,T]),M=a.useCallback(K=>{k(K),D("idle"),N(""),S("machines"),_("inbox"),m("machine")},[]),X=a.useCallback(K=>{var re;const F=K.daemonId||((re=K.ideId)==null?void 0:re.split(":")[0])||K.ideId;F&&(k(F),D("idle"),N(""),S("machines"),_("chat"),m("machine"))},[]),se=a.useCallback(()=>{m(w)},[w]),ne=a.useCallback(async(K,F,re)=>{var ce;try{D("loading"),N(`Launching ${F}…`);const ae={ideType:F,enableCdp:!0};(ce=re==null?void 0:re.workspacePath)!=null&&ce.trim()&&(ae.workspace=re.workspacePath.trim()),await r(K,"launch_ide",ae),D("done"),N(`${F} launch requested`)}catch(ae){D("error"),N(ae instanceof Error?ae.message:"Launch IDE failed"),console.error("Launch IDE failed",ae)}},[r]),xe=a.useCallback(async(K,F,re)=>{if(F.trim())try{D("loading"),N(re!=null&&re.createIfMissing?"Creating folder…":"Saving workspace…");const ce=await r(K,"workspace_add",{path:F.trim(),createIfMissing:(re==null?void 0:re.createIfMissing)===!0});if(ce!=null&&ce.success){D("done"),N(re!=null&&re.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}D("error"),N((ce==null?void 0:ce.error)||"Could not save workspace")}catch(ce){D("error"),N(ce instanceof Error?ce.message:"Could not save workspace")}},[r]),be=a.useCallback(async K=>{var F,re,ce,ae;try{D("loading"),N("Installing latest daemon…");const he=await r(K,"daemon_upgrade",{});if((F=he==null?void 0:he.result)!=null&&F.upgraded||(re=he==null?void 0:he.result)!=null&&re.success){D("done"),N(`Upgrading to v${((ce=he==null?void 0:he.result)==null?void 0:ce.version)||"latest"} and restarting…`);return}D("error"),N(((ae=he==null?void 0:he.result)==null?void 0:ae.error)||"Upgrade failed")}catch(he){D("error"),N(he instanceof Error?he.message:"Upgrade failed")}},[r]),pe=a.useCallback(async(K,F,re,ce)=>{var ae;try{D("loading"),N(`Launching ${re}…`);const he={cliType:re};(ae=ce==null?void 0:ce.workspacePath)!=null&&ae.trim()?he.dir=ce.workspacePath.trim():ce!=null&&ce.workspaceId&&(he.workspaceId=ce.workspaceId);const je=await r(K,"launch_cli",he),Ne=(je==null?void 0:je.result)||je;if(je!=null&&je.success&&(Ne!=null&&Ne.id)){D("done"),N(`${re} launched`),A(`/dashboard?activeTab=${encodeURIComponent(Ne.id)}`);return}D("error"),N((je==null?void 0:je.error)||(Ne==null?void 0:Ne.error)||`Could not launch ${F.toUpperCase()} workspace`)}catch(he){D("error"),N(he instanceof Error?he.message:`Could not launch ${F.toUpperCase()} workspace`)}},[A,r]),ge=a.useCallback(async K=>{if(K.sessionId){A(`/dashboard?activeTab=${encodeURIComponent(K.sessionId)}`);return}if(R){if(K.kind==="ide"&&K.providerType){await ne(R.id,K.providerType,{workspacePath:K.workspace||null});return}if((K.kind==="cli"||K.kind==="acp")&&K.providerType){await pe(R.id,K.kind,K.providerType,{workspacePath:K.workspace||null});return}}},[ne,pe,R]);return e.jsx("div",{className:"dashboard-mobile-chat",children:j==="chat"&&T?e.jsx(Pi,{selectedConversation:T,isAcp:ke(T),selectedIdeEntry:G,actionLogs:n,userName:h,isSendingChat:z.isSendingChat,isFocusingAgent:z.isFocusingAgent,onBack:oe,onOpenNativeConversation:Z,onOpenMachine:X,onOpenHistory:p,onOpenRemote:l,handleSendChat:z.handleSendChat,handleFocusAgent:z.handleFocusAgent}):j==="machine"&&R?e.jsx(Di,{selectedMachineEntry:R,selectedMachineConversations:Y,selectedMachineRecentSessions:H,cliProviders:te,acpProviders:ue,selectedMachineNeedsUpgrade:J,appVersion:$,machineAction:{state:B,message:P},onBack:se,onOpenConversation:le,onOpenRecent:ge,onOpenMachineDetails:()=>A(`/machines/${R.id}`),onMachineUpgrade:()=>be(R.id),onLaunchDetectedIde:(K,F)=>ne(R.id,K,F),onAddWorkspace:(K,F)=>xe(R.id,K,F),onLaunchWorkspaceProvider:(K,F,re)=>pe(R.id,K,F,re)}):e.jsx(Li,{section:g,attentionItems:V,unreadItems:ie,workingItems:ee,completedItems:O,machineCards:de,getAvatarText:Wi,getConversationPreview:_s,onOpenConversation:le,onOpenMachine:M,onOpenSettings:()=>A("/settings"),onSectionChange:S})})}function Ut(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Fi({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[h,d]=a.useState(!1),[x,u]=a.useState(null),f=a.useCallback(()=>{c.current=0,d(!1),u(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",f),window.addEventListener("drop",f),()=>{window.removeEventListener("dragend",f),window.removeEventListener("drop",f)}),[f]);const p=a.useCallback(j=>{j.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,d(!0))},[]),l=a.useCallback(j=>{if(!j.dataTransfer.types.includes("text/tab-key"))return;if(j.preventDefault(),!Ut(s,n)){u("merge");return}const m=j.currentTarget.getBoundingClientRect(),g=j.clientX-m.left,S=m.width/3;g<S?u("split-left"):g>S*2?u("split-right"):u("merge")},[s,n]),b=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,d(!1),u(null))},[]),v=a.useCallback(j=>{c.current=0,d(!1);const m=j.dataTransfer.getData("text/tab-key"),g=m?t.some(E=>E.tabKey===m):!1,S=x;if(u(null),o(),!!m){if(j.preventDefault(),S==="split-left"&&Ut(s,n)){n==null||n(m,"split-left");return}if(S==="split-right"&&Ut(s,n)){n==null||n(m,"split-right");return}if(g){i(m);return}r==null||r(m)}},[t,x,s,n,r,i,o]);return{dragOver:h,dropAction:x,resetDragState:f,handleDragEnter:p,handleDragOver:l,handleDragLeave:b,handleDrop:v}}function Ui(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 Hi({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[h,d]=a.useState(n??[]),[x,u]=a.useState(null),f=a.useRef(null),p=a.useRef(null),l=a.useRef(r),b=a.useRef(i);a.useEffect(()=>{l.current=r},[r]),a.useEffect(()=>{b.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{d(k=>{const w=Ui(k,t);return w.length===k.length&&w.every((_,B)=>_===k[B])?k:w})},[t]);const v=a.useMemo(()=>{const k=x??h;if(k.length===0)return t;const w=new Map(k.map((_,B)=>[_,B]));return[...t].sort((_,B)=>{const D=w.get(_.tabKey)??999,P=w.get(B.tabKey)??999;return D-P})},[t,x,h]);a.useEffect(()=>{var w,_;if(v.length===0){o!==null&&(c(null),(w=l.current)==null||w.call(l,null));return}if(o&&v.some(B=>B.tabKey===o))return;const k=v[0].tabKey;k!==o&&(c(k),(_=l.current)==null||_.call(l,k))},[v,o]);const j=a.useMemo(()=>v.find(k=>k.tabKey===o),[v,o]),m=a.useCallback(k=>{var w;c(k),(w=l.current)==null||w.call(l,k)},[]),g=a.useCallback((k,w,_)=>{d(B=>{var A;const D=B.filter($=>$!==k),P=D.indexOf(w);if(P<0)return B;const N=_==="left"?P:P+1;return D.splice(N,0,k),(A=b.current)==null||A.call(b,D),D}),u(null)},[]),S=a.useCallback((k,w,_)=>{const D=(h.length>0?h:t.map(A=>A.tabKey)).filter(A=>A!==k),P=D.indexOf(w);if(P<0)return;const N=_==="left"?P:P+1;D.splice(N,0,k),f.current=D,u(D)},[h,t]),E=a.useCallback(()=>{var w;const k=f.current;k&&(d(k),(w=b.current)==null||w.call(b,k))},[]),y=a.useCallback(()=>{f.current=null,u(null)},[]),C=a.useCallback(k=>{d(w=>{var B;const _=w.filter(D=>D!==k);return _.push(k),(B=b.current)==null||B.call(b,_),_})},[]);return{activeTabId:o,activeConv:j,sortedConversations:v,previewOrderRef:f,draggingTabRef:p,selectTab:m,handleTabReorder:g,updatePreviewOrder:S,commitPreviewOrder:E,clearPreviewOrder:y,moveTabToEnd:C,setDraggingTabKey:k=>{p.current=k}}}const $n=a.memo(function({activeConv:s,clearToken:n,isCli:r,ideEntry:i,screenshotUrl:o,clearScreenshot:c,terminalRef:h,handleModalButton:d,handleRelaunch:x,handleSendChat:u,isSendingChat:f,handleFocusAgent:p,isFocusingAgent:l,actionLogs:b,userName:v}){const j=a.useCallback(()=>{c()},[c]);return e.jsxs(e.Fragment,{children:[e.jsx(on,{activeConv:s,onModalButton:d}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!r&&s.transport!=="acp"&&o?e.jsx(Qr,{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(ns,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:x,children:"Relaunch with CDP"})]}):null}),r?e.jsx(pn,{activeConv:s,clearToken:n,terminalRef:h,handleSendChat:u,isSendingChat:f}):e.jsx(rs,{activeConv:s,ideEntry:i,handleSendChat:u,isSendingChat:f,handleFocusAgent:p,isFocusingAgent:l,actionLogs:b,userName:v})]})},(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 Vi({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 Ht={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 qi(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Yi(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":n;a.useEffect(()=>{s(qi())},[]);const h=a.useCallback(()=>{navigator.clipboard.writeText(Ht[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:Ht[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Ht[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 cs({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(Yi,{}),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(nn,{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 Bn="adhdev-tab-shortcuts";function Xi(){try{return JSON.parse(localStorage.getItem(Bn)||"{}")}catch{return{}}}function Gi({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,o]=a.useState(()=>Xi()),[c,h]=a.useState(null),d=a.useCallback(u=>{const f=[];return u.metaKey&&f.push(r?"⌘":"Meta"),u.ctrlKey&&f.push("Ctrl"),u.altKey&&f.push(r?"⌥":"Alt"),u.shiftKey&&f.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(u.key)?null:(f.push(u.key.length===1?u.key.toUpperCase():u.key),f.join("+"))},[r]),x=a.useCallback(u=>{o(u);try{localStorage.setItem(Bn,JSON.stringify(u))}catch{}},[]);return a.useEffect(()=>{if(!c)return;const u=f=>{if(f.preventDefault(),f.stopPropagation(),f.key==="Escape"){h(null);return}const p=d(f);if(!p)return;const l={...i};for(const[b,v]of Object.entries(l))v===p&&delete l[b];l[c]=p,x(l),h(null)};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[c,i,x,d]),a.useEffect(()=>{const u=f=>{if(!(!f.ctrlKey&&!f.metaKey&&!f.altKey)){for(const[p,l]of Object.entries(i))if(t.includes(p)&&d(f)===l){f.preventDefault(),s(),n(p);return}}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[i,t,s,n,d]),{isMac:r,tabShortcuts:i,shortcutListening:c,setShortcutListening:h,saveShortcuts:x}}const Ji=a.memo(function({conv:s,isActive:n,isDraggedTab:r,shortcut:i,conversationKeys:o,draggingTabRef:c,onFocus:h,onSelectTab:d,onConversationActivated:x,onPreviewReorder:u,onReorderTab:f,onCommitPreviewOrder:p,onClearPreviewOrder:l,onDragStateReset:b,onDragTabKeyChange:v,onReceiveTab:j,onOpenContextMenu:m,longPressTimer:g}){const S=s.status==="generating"?"agent-tab-generating":s.status==="waiting_approval"?"agent-tab-waiting":"",E=s.connectionState==="failed"||s.connectionState==="closed",y=a.useCallback(A=>{c.current=s.tabKey,v(s.tabKey),A.dataTransfer.setData("text/tab-key",s.tabKey),A.dataTransfer.effectAllowed="move"},[s.tabKey,c,v]),C=a.useCallback(()=>{c.current=null,v(null),p(),l(),b()},[c,v,p,l,b]),k=a.useCallback(A=>{const $=c.current;if(!(!$||$===s.tabKey)&&A.dataTransfer.types.includes("text/tab-key")){A.preventDefault(),A.stopPropagation();const T=A.currentTarget.getBoundingClientRect(),G=A.clientX<T.left+T.width/2?"left":"right";u($,s.tabKey,G)}},[s.tabKey,c,u]),w=a.useCallback(A=>{A.preventDefault(),A.stopPropagation();const $=A.dataTransfer.getData("text/tab-key");if($&&$!==s.tabKey){const T=A.currentTarget.getBoundingClientRect(),G=A.clientX<T.left+T.width/2?"left":"right";o.includes($)?f($,s.tabKey,G):j&&j($)}l()},[s.tabKey,o,f,j,l]),_=a.useCallback(A=>{A.stopPropagation(),h(),d(s.tabKey),x(s)},[s,x,h,d]),B=a.useCallback(A=>{A.preventDefault(),m(A.clientX,A.clientY,s.tabKey)},[s.tabKey,m]),D=a.useCallback(A=>{const $=A.touches[0];g.current=setTimeout(()=>{m($.clientX,$.clientY,s.tabKey)},600)},[s.tabKey,g,m]),P=a.useCallback(()=>{g.current&&clearTimeout(g.current)},[g]),N=["adhdev-dockview-tab",S,n&&"is-active",E&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:N,draggable:!0,onDragStart:y,onDragEnd:C,onDragOver:k,onDrop:w,onClick:_,onContextMenu:B,onTouchStart:D,onTouchEnd:P,onTouchMove:P,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:"▲"}):E?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:E?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 Zi({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,draggingTabRef:i,onFocus:o,onSelectTab:c,onConversationActivated:h,onPreviewReorder:d,onReorderTab:x,onCommitPreviewOrder:u,onClearPreviewOrder:f,onDragStateReset:p,onDragTabKeyChange:l,onMoveTab:b,onReceiveTab:v,onHideTab:j}){const[m,g]=a.useState(null),S=a.useRef(null),E=a.useRef(null),y=a.useMemo(()=>t.map(P=>P.tabKey),[t]);mt("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(m==null?void 0:m.tabKey)||null});const{isMac:C,tabShortcuts:k,shortcutListening:w,setShortcutListening:_,saveShortcuts:B}=Gi({sortedTabKeys:t.map(P=>P.tabKey),onFocus:o,onSelectTab:c});a.useEffect(()=>{if(!m)return;const P=N=>{const A=document.querySelector("[data-pane-context-menu]");A&&A.contains(N.target)||g(null)};return window.addEventListener("mousedown",P,!0),()=>window.removeEventListener("mousedown",P,!0)},[m]),a.useEffect(()=>{const P=E.current;if(!P)return;const N=A=>{Math.abs(A.deltaY)>Math.abs(A.deltaX)&&(A.preventDefault(),P.scrollLeft+=A.deltaY)};return P.addEventListener("wheel",N,{passive:!1}),()=>P.removeEventListener("wheel",N)},[]);const D=a.useCallback((P,N,A)=>{g({x:P,y:N,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:E,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(P=>e.jsx(Ji,{conv:P,isActive:s===P.tabKey,isDraggedTab:i.current===P.tabKey,shortcut:k[P.tabKey],conversationKeys:y,draggingTabRef:i,onFocus:o,onSelectTab:c,onConversationActivated:h,onPreviewReorder:d,onReorderTab:x,onCommitPreviewOrder:u,onClearPreviewOrder:f,onDragStateReset:p,onDragTabKeyChange:l,onReceiveTab:v,onOpenContextMenu:D,longPressTimer:S},P.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),m&&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:m.x,top:m.y},children:[b&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{b(m.tabKey,"left"),g(null)},children:"← Move to Left Group"}),b&&n<r-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{b(m.tabKey,"right"),g(null)},children:"Move to Right Group →"}),b&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{b(m.tabKey,"split-left"),g(null)},children:"⇤ Split Left"}),b&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{b(m.tabKey,"split-right"),g(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:P=>{P.stopPropagation(),_(m.tabKey),g(null)},children:["⌨ ",k[m.tabKey]?`Change shortcut (${k[m.tabKey]})`:"Set shortcut"]}),k[m.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 P={...k};delete P[m.tabKey],B(P),g(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(m.tabKey),g(null)},children:"🚫 Hide from Dashboard"})]}),!b&&!j&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),w&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>_(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:P=>P.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:d,isStandalone:x,userName:u,groupIndex:f,onFocus:p,isSplitMode:l,numGroups:b,onMoveTab:v,onReceiveTab:j,style:m,detectedIdes:g,handleLaunchIde:S,onActiveTabChange:E,initialActiveTabId:y,initialTabOrder:C,onTabOrderChange:k,onHideTab:w}){const{sendCommand:_}=We(),B=a.useRef(null),{activeTabId:D,activeConv:P,sortedConversations:N,draggingTabRef:A,selectTab:$,handleTabReorder:T,updatePreviewOrder:G,commitPreviewOrder:L,clearPreviewOrder:R,moveTabToEnd:U,setDraggingTabKey:z}=Hi({conversations:t,initialActiveTabId:y,initialTabOrder:C,onActiveTabChange:E,onTabOrderChange:k}),W=$t({sendDaemonCommand:c,activeConv:P,setLocalUserMessages:h,setActionLogs:d,isStandalone:x}),{dragOver:Q,dropAction:V,resetDragState:ie,handleDragEnter:ee,handleDragOver:O,handleDragLeave:Y,handleDrop:H}=Fi({conversations:t,numGroups:b,onMoveTab:v,onReceiveTab:j,onOwnTabDrop:U,onClearPreviewOrder:R}),I=P&&Se(P)&&!ke(P),J=a.useMemo(()=>P?s.find(le=>le.id===P.ideId):void 0,[s,P]),q=P?i[P.ideId]:void 0,te=a.useCallback(()=>{if(!P||!(P.ideId in i))return;const le={...i};delete le[P.ideId],o(le)},[P,i,o]),ue=a.useMemo(()=>P?r.filter(le=>le.ideId===P.tabKey):[],[r,P]);mt("PaneGroup",{groupIndex:f,conversationCount:t.length,activeTabId:D,dragOver:Q});const de=a.useCallback(le=>{le.streamSource==="agent-stream"&&le.agentType&&_(le.ideId,"focus_session",{agentType:le.agentType,...le.sessionId&&{targetSessionId:le.sessionId}}).catch(()=>{})},[_]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:p,style:{...m,outline:Q?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Zi,{conversations:N,activeTabId:D,groupIndex:f,numGroups:b,draggingTabRef:A,onFocus:p,onSelectTab:$,onConversationActivated:de,onPreviewReorder:G,onReorderTab:T,onCommitPreviewOrder:L,onClearPreviewOrder:R,onDragStateReset:ie,onDragTabKeyChange:z,onMoveTab:v,onReceiveTab:j,onHideTab:w}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:ee,onDragOver:O,onDragLeave:Y,onDrop:H,children:[Q&&e.jsx(Vi,{dropAction:V,canSplit:!!(b<4&&v)}),P?e.jsx($n,{activeConv:P,clearToken:n[P.tabKey]||0,isCli:!!I,ideEntry:J,screenshotUrl:q,clearScreenshot:te,terminalRef:B,handleModalButton:W.handleModalButton,handleRelaunch:W.handleRelaunch,handleSendChat:W.handleSendChat,isSendingChat:W.isSendingChat,handleFocusAgent:W.handleFocusAgent,isFocusingAgent:W.isFocusingAgent,actionLogs:ue,userName:u}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(cs,{conversationsCount:t.length,isSplitMode:l,isStandalone:x,detectedIdes:g,handleLaunchIde:S})})]})]})}function eo({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:h,screenshotMap:d,setScreenshotMap:x,sendDaemonCommand:u,setLocalUserMessages:f,setActionLogs:p,isStandalone:l,userName:b,setFocusedGroup:v,moveTabToGroup:j,splitTabRelative:m,closeGroup:g,handleResizeStart:S,detectedIdes:E,handleLaunchIde:y,groupActiveTabIds:C,setGroupActiveTabIds:k,groupTabOrders:w,setGroupTabOrders:_,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((D,P)=>{const N=s&&r.length===n?`${r[P]}%`:void 0;return e.jsxs(hr.Fragment,{children:[s&&P>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=>S(P-1,A),onDoubleClick:()=>g(P),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:N??`${100/n}%`,flexGrow:N?0:1,flexShrink:N?0:1}:void 0,conversations:D,clearedTabs:o,ides:c,actionLogs:h,screenshotMap:d,setScreenshotMap:x,sendDaemonCommand:u,setLocalUserMessages:f,setActionLogs:p,isStandalone:l,userName:b,groupIndex:P,onFocus:()=>v(P),isSplitMode:s,numGroups:n,onMoveTab:(A,$)=>{$==="left"&&P>0?j(A,P-1):$==="right"&&P<n-1?j(A,P+1):$==="split-left"&&n<4?m(A,P,"left"):$==="split-right"&&n<4&&m(A,P,"right")},onReceiveTab:A=>j(A,P),detectedIdes:P===0?E:void 0,handleLaunchIde:P===0?y:void 0,onActiveTabChange:A=>k($=>($[P]??null)===(A??null)?$:{...$,[P]:A}),initialActiveTabId:C[P],initialTabOrder:w[P],onTabOrderChange:A=>_($=>{const T=$[P]||[];return T.length===A.length&&T.every((G,L)=>G===A[L])?$:{...$,[P]:A}}),onHideTab:B})]},P)})})}function Kn({doId:t,ideId:s,ideType:n,connState:r,viewMode:i,instanceId:o}){const[c,h]=a.useState(null),[d,x]=a.useState(null),u=a.useMemo(()=>{if(!s)return n;const p=s.split(":");return p.length>=3&&p[1]==="ide"?p.slice(2).join(":"):n},[s,n]);a.useEffect(()=>t?fe.onScreenshot("ide-page",(l,b)=>{if(l!==t)return;const v=new FileReader;v.onload=()=>h(v.result),v.readAsDataURL(b)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&h(null)},[r]),a.useEffect(()=>{var l;return t?((l=fe.onStatus)==null?void 0:l.call(fe,(b,v)=>{b===t&&v!=null&&v.screenshotUsage&&x(v.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{h(null)},[t,s,u]),a.useEffect(()=>{const p=t?fe.get(t):null;if(!(!p||r!=="connected"))return i!=="chat"&&u?p.startScreenshots(u):p.stopScreenshots(u),()=>{p.stopScreenshots(u)}},[i,r,u,t]);const f=a.useCallback(async(p,l)=>{const b=t?fe.get(t):null;return!b||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):b.sendInput(p,l,o||u)},[t,r,o,u]);return{connScreenshot:c,screenshotUsage:d,handleRemoteAction:f}}const On=a.createContext(null);function Bt(){const t=a.useContext(On);if(!t)throw new Error("DashboardDockviewContext missing");return t}function Ct(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function to(t){return`remote:${t}`}function _t(t){return t.startsWith("remote:")}function Kt(t,s){return t.find(n=>n.ideId===s&&n.streamSource==="native")??t.find(n=>n.ideId===s)??null}function so(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 no(t,s,n){var h;const r=[s];let i;for(const d of r){let x;for(const u of d){const f=t.addPanel({id:u.tabKey,component:"conversation",title:Ct(u),params:{kind:"conversation",tabKey:u.tabKey},...x?{position:{referencePanel:x,direction:"within"},inactive:!0}:i?{position:{referencePanel:i,direction:"right"},inactive:!0}:{}});x||(x=f.id)}i=x??i}const o=n??((h=s[0])==null?void 0:h.tabKey)??null;if(!o)return;const c=t.getPanel(o);c&&c.group.model.openPanel(c)}function Ps(t,s){const n=new Set(s.map(r=>r.tabKey));for(const r of[...t.panels])_t(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!==Ct(r)&&i.api.setTitle(Ct(r));continue}t.addPanel({id:r.tabKey,component:"conversation",title:Ct(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 Ls(t,s,n){var d,x;const r=n?to(n):null;for(const u of[...t.panels])_t(u.id)&&(!r||u.id!==r)&&t.removePanel(u);if(!n||!r)return;const i=Kt(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)??((d=t.activePanel)==null?void 0:d.id)??((x=t.panels.find(u=>!_t(u.id)))==null?void 0:x.id);t.addPanel({id:r,component:"remote",title:c,params:{kind:"remote",ideId:n},...h?{position:{referencePanel:h,direction:"right"},inactive:!0}:{}})}function ro({params:t}){const s=Bt(),n=a.useRef(null),r=s.conversationsByTabKey.get(t.tabKey),i=$t({sendDaemonCommand:s.sendDaemonCommand,activeConv:r,setLocalUserMessages:s.setLocalUserMessages,setActionLogs:s.setActionLogs,isStandalone:s.isStandalone}),o=a.useMemo(()=>r?s.ides.find(u=>u.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 u={...s.screenshotMap};delete u[r.ideId],s.setScreenshotMap(u)},[r,s]),d=a.useMemo(()=>r?s.actionLogs.filter(u=>u.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(cs,{conversationsCount:0,isSplitMode:!1,isStandalone:s.isStandalone,detectedIdes:s.detectedIdes,handleLaunchIde:s.handleLaunchIde})});const x=Se(r)&&!ke(r);return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx($n,{activeConv:r,clearToken:s.clearedTabs[r.tabKey]||0,isCli:x,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:d,userName:s.userName})})}function ao({params:t}){var d;const s=Bt(),n=a.useMemo(()=>Kt([...s.conversationsByTabKey.values()],t.ideId),[s.conversationsByTabKey,t.ideId]),r=a.useMemo(()=>s.ides.find(x=>x.id===t.ideId),[s.ides,t.ideId]),i=(n==null?void 0:n.daemonId)||((d=n==null?void 0:n.ideId)==null?void 0:d.split(":")[0])||t.ideId.split(":")[0]||t.ideId,{connScreenshot:o,screenshotUsage:c,handleRemoteAction:h}=Kn({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(an,{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 io(){const t=Bt();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(cs,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function oo(t){var x,u;so(t);const s=Bt();if(t.params.kind==="remote"){const f=Kt([...s.conversationsByTabKey.values()],t.params.ideId),p=((x=t.api.group.activePanel)==null?void 0:x.id)===t.api.id,l=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${p?" is-active":""}${l?" 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:f!=null&&f.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:f.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=((u=t.api.group.activePanel)==null?void 0:u.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",d=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"}):d?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 co({visibleConversations:t,clearedTabs:s,ides:n,actionLogs:r,screenshotMap:i,setScreenshotMap:o,sendDaemonCommand:c,setLocalUserMessages:h,setActionLogs:d,isStandalone:x,userName:u,detectedIdes:f,handleLaunchIde:p,toggleHiddenTab:l,onActiveTabChange:b,requestedActiveTabKey:v,requestedRemoteIdeId:j,onRequestedActiveTabConsumed:m}){const{theme:g}=Sn(),{sendCommand:S}=We(),E=a.useRef(null),y=a.useRef(null),C=a.useRef(!1),[k,w]=a.useState(!1),[_,B]=a.useState(!1),D=a.useRef(null),P=a.useMemo(()=>_n(typeof window<"u"?window.innerWidth:1280),[]),N=a.useMemo(()=>new Map(t.map(W=>[W.tabKey,W])),[t]),A=a.useMemo(()=>({actionLogs:r,clearedTabs:s,conversationsByTabKey:N,detectedIdes:f,handleLaunchIde:p,ides:n,isStandalone:x,screenshotMap:i,sendDaemonCommand:c,setActionLogs:d,setLocalUserMessages:h,setScreenshotMap:o,toggleHiddenTab:l,userName:u}),[r,s,N,f,p,n,x,i,c,d,h,o,l,u]),$=a.useCallback(W=>{if(!W)return!1;const Q=E.current;if(!Q)return!1;const V=Q.getPanel(W);return V?(V.group.model.openPanel(V),m==null||m(),!0):!1},[m]),T=a.useCallback(()=>{const W=y.current;if(!W)return;const Q=W.querySelectorAll(".dv-drop-target-container, .dv-drop-target-anchor, .dv-drop-target-dropzone, .dv-drop-target-selection, .dv-render-overlay");for(const V of Q)V.setAttribute("data-adhdev-force-hidden","true")},[]),G=a.useCallback(()=>{const W=y.current;if(!W)return;const Q=W.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const V of Q)V.removeAttribute("data-adhdev-force-hidden")},[]),L=a.useCallback(()=>{const W=y.current;if(!W)return;const Q=W.querySelectorAll(".dv-drop-target-container");for(const ee of Q)ee.remove();const V=W.querySelectorAll(".dv-drop-target-dropzone");for(const ee of V)ee.remove();const ie=W.querySelectorAll(".dv-drop-target");for(const ee of ie)ee.classList.remove("dv-drop-target")},[]),R=a.useCallback(()=>{w(!1),B(!1),G(),T(),L(),!(typeof window>"u")&&(D.current!=null&&window.clearTimeout(D.current),window.requestAnimationFrame(()=>{T(),L()}),D.current=window.setTimeout(()=>{T(),L(),D.current=null},80))},[G,T,L]),U=a.useCallback(W=>{var V;E.current=W.api;const Q=wi(P);Q!=null&&Q.layout&&W.api.fromJSON(Q.layout,{reuseExistingPanels:!1}),Ps(W.api,t),Ls(W.api,t,j),W.api.totalPanels===0&&t.length>0?no(W.api,t,v):$(v)||$(Q==null?void 0:Q.activeTabId),C.current=!0,W.api.onDidActivePanelChange(ie=>{var O;if(ie&&_t(ie.id)){const Y=((O=ie.params)==null?void 0:O.ideId)||ie.id.slice(7),H=Kt(t,Y);b((H==null?void 0:H.tabKey)??null);return}if(b((ie==null?void 0:ie.id)??null),!ie)return;const ee=N.get(ie.id);(ee==null?void 0:ee.streamSource)==="agent-stream"&&ee.agentType&&S(ee.ideId,"focus_session",{agentType:ee.agentType,...ee.sessionId&&{targetSessionId:ee.sessionId}}).catch(()=>{})}),W.api.onDidLayoutChange(()=>{var ie;ki(P,{activeTabId:((ie=W.api.activePanel)==null?void 0:ie.id)??null,layout:W.api.toJSON()})}),W.api.onWillDragPanel(()=>{w(!0),B(!1),T()}),W.api.onWillDragGroup(()=>{w(!0),B(!1),T()}),W.api.onWillShowOverlay(()=>{G(),B(!0)}),W.api.onDidMovePanel(R),W.api.onDidDrop(R),b(((V=W.api.activePanel)==null?void 0:V.id)??null)},[$,R,G,N,P,T,L,b,v,S,t]);a.useEffect(()=>{const W=E.current;!W||!C.current||(Ps(W,t),Ls(W,t,j),!W.activePanel&&W.panels[0]&&W.panels[0].group.model.openPanel(W.panels[0]))},[j,t]),a.useEffect(()=>{C.current&&$(v)},[$,v]),a.useEffect(()=>{if(!k||typeof window>"u")return;const W=()=>R();return window.addEventListener("pointerup",W),window.addEventListener("mouseup",W),window.addEventListener("dragend",W),()=>{window.removeEventListener("pointerup",W),window.removeEventListener("mouseup",W),window.removeEventListener("dragend",W)}},[R,k]),a.useEffect(()=>()=>{typeof window>"u"||D.current!=null&&window.clearTimeout(D.current)},[]);const z=g==="light"?pr:xr;return e.jsx(On.Provider,{value:A,children:e.jsx("div",{ref:y,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(mr,{className:`h-full min-h-0 min-w-0 adhdev-dockview${k?" is-dragging-dockview":""}${_?" is-showing-dockview-overlay":""}`,components:{conversation:ro,remote:ao},defaultTabComponent:oo,watermarkComponent:io,onReady:U,singleTabMode:"default",tabAnimation:"smooth",theme:z})})})}function lo({showMobileChatMode:t,isMobile:s,activeConv:n,chatIdes:r,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:h,onFitCli:d,onStopCli:x,mobileChatConversations:u,ides:f,actionLogs:p,sendDaemonCommand:l,setLocalUserMessages:b,setActionLogs:v,isStandalone:j,userName:m,requestedMobileTabKey:g,onRequestedMobileTabConsumed:S,requestedMachineId:E,onRequestedMachineConsumed:y,containerRef:C,isSplitMode:k,numGroups:w,groupSizes:_,groupedConvs:B,clearedTabs:D,screenshotMap:P,setScreenshotMap:N,focusedGroup:A,setFocusedGroup:$,moveTabToGroup:T,splitTabRelative:G,closeGroup:L,handleResizeStart:R,detectedIdes:U,handleLaunchIde:z,groupActiveTabIds:W,setGroupActiveTabIds:Q,groupTabOrders:V,setGroupTabOrders:ie,toggleHiddenTab:ee,visibleConversations:O,requestedDesktopTabKey:Y,onRequestedDesktopTabConsumed:H,onDesktopActiveTabChange:I}){return e.jsxs(e.Fragment,{children:[!t&&e.jsx(va,{activeConv:n,agentCount:r.length,wsStatus:i,isConnected:o,conversations:O,onOpenHistory:c,onOpenConversation:J=>I(J.tabKey),onOpenRemote:()=>{!n||Se(n)||ke(n)||h(n)},onFitCli:d,onStopCli:x}),t?e.jsx(zi,{conversations:u,ides:f,actionLogs:p,sendDaemonCommand:l,setLocalUserMessages:b,setActionLogs:v,isStandalone:j,userName:m,requestedActiveTabKey:g,onRequestedActiveTabConsumed:S,requestedMachineId:E,onRequestedMachineConsumed:y,onOpenHistory:c,onOpenRemote:h}):s?e.jsx(eo,{containerRef:C,isSplitMode:k,numGroups:w,groupSizes:_,groupedConvs:B,clearedTabs:D,ides:f,actionLogs:p,screenshotMap:P,setScreenshotMap:N,sendDaemonCommand:l,setLocalUserMessages:b,setActionLogs:v,isStandalone:j,userName:m,focusedGroup:A,setFocusedGroup:$,moveTabToGroup:T,splitTabRelative:G,closeGroup:L,handleResizeStart:R,detectedIdes:U,handleLaunchIde:z,groupActiveTabIds:W,setGroupActiveTabIds:Q,groupTabOrders:V,setGroupTabOrders:ie,toggleHiddenTab:ee}):e.jsx(co,{visibleConversations:O,clearedTabs:D,ides:f,actionLogs:p,screenshotMap:P,setScreenshotMap:N,sendDaemonCommand:l,setLocalUserMessages:b,setActionLogs:v,isStandalone:j,userName:m,detectedIdes:U,handleLaunchIde:z,toggleHiddenTab:ee,onActiveTabChange:I,requestedActiveTabKey:Y,onRequestedActiveTabConsumed:H})]})}const Vt=[{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 uo({onClose:t}){const[s,n]=a.useState(0),r=Vt[s],i=s===Vt.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:Vt.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:`
|
|
54
|
+
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
|
|
55
|
+
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
|
|
56
|
+
`})]})}function ho({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",d=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)":d?"var(--accent-primary)":"#64748b",boxShadow:d?"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 mo({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:i,preferredTabKey:o}){const[c,h]=a.useState(()=>o||"native"),d=a.useMemo(()=>gn(s),[s]),x=a.useMemo(()=>{var j;if(!t)return[];const v=t.daemonId||((j=t.id)==null?void 0:j.split(":")[0])||t.id;return yn(t,r,{machineName:t.daemonId&&d[t.daemonId]||void 0,connectionState:n[v]||"new"})},[t,r,d,n]),u=a.useMemo(()=>x.find(v=>v.streamSource==="native"),[x]),f=a.useMemo(()=>x.filter(v=>v.streamSource==="agent-stream"),[x]);a.useEffect(()=>{o&&h(o)},[o]),a.useEffect(()=>{var v;c!=="native"&&(f.some(j=>j.tabKey===c)||h(((v=f[0])==null?void 0:v.tabKey)||"native"))},[c,f]),a.useEffect(()=>{c==="native"&&(u||f[0]&&h(f[0].tabKey))},[c,u,f]);const p=a.useMemo(()=>c==="native"&&u?u:f.find(v=>v.tabKey===c)||u||f[0],[c,u,f]),l=a.useMemo(()=>f.map(v=>({tabKey:v.tabKey,title:v.title||v.agentName||i,status:v.status})),[f,i]),b=a.useCallback(v=>{if(v)return x.find(j=>j.sessionId===v||j.ideId===v||j.tabKey===v||j.ideType===v||j.agentType===v)},[x]);return{activeChatTab:c,setActiveChatTab:h,activeConv:p,conversations:x,extensionTabs:l,hasExtensions:l.length>0,resolveConversationByTarget:b}}function po({activeConv:t,ideEntry:s,ides:n,connectionStates:r,actionLogs:i,localUserMessages:o,sendDaemonCommand:c,setLocalUserMessages:h,setActionLogs:d,isStandalone:x,userName:u,onOpenHistory:f,onConversationChange:p,onClose:l}){var $;const[b,v]=a.useState("split"),[j,m]=a.useState(()=>t.streamSource==="native"?"native":t.tabKey),g=a.useMemo(()=>s||n.find(T=>T.id===t.ideId),[t.ideId,s,n]),S=a.useMemo(()=>ve((g==null?void 0:g.type)||""),[g==null?void 0:g.type]),{conversations:E,extensionTabs:y,hasExtensions:C}=mo({ideData:g,allIdes:n,connectionStates:r,localUserMessages:o,ideName:S||"IDE",preferredTabKey:t.streamSource==="native"?"native":t.tabKey});a.useEffect(()=>{m(t.streamSource==="native"?"native":t.tabKey)},[t.streamSource,t.tabKey]);const k=a.useMemo(()=>j==="native"?E.find(T=>T.streamSource==="native")||t:E.find(T=>T.tabKey===j)||t,[t,E,j]),w=k.daemonId||(($=k.ideId)==null?void 0:$.split(":")[0])||k.ideId,_=$t({sendDaemonCommand:c,activeConv:k,setLocalUserMessages:h,setActionLogs:d,isStandalone:x}),{connScreenshot:B,screenshotUsage:D,handleRemoteAction:P}=Kn({doId:w,ideId:k.ideId,ideType:k.ideType,connState:k.connectionState||"new",viewMode:b,instanceId:g==null?void 0:g.instanceId}),N=a.useMemo(()=>i.filter(T=>T.ideId===k.tabKey),[i,k.tabKey]);a.useEffect(()=>{p==null||p(k)},[k,p]),a.useEffect(()=>{const T=G=>{G.key==="Escape"&&l()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[l]);const A=a.useCallback(T=>{T.stopPropagation()},[]);return e.jsx("div",{className:"dashboard-remote-dialog-overlay",onClick:l,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.jsx("div",{className:"dashboard-remote-dialog-title-block",children:e.jsxs("div",{className:"dashboard-remote-dialog-title",children:[e.jsx(Ee,{size:16}),e.jsx("span",{children:k.displayPrimary||k.agentName||"Remote"})]})}),e.jsxs("div",{className:"dashboard-remote-dialog-actions",children:[["split","remote"].map(T=>e.jsx("button",{className:`btn btn-secondary btn-sm dashboard-remote-dialog-mode${b===T?" is-active":""}`,onClick:()=>v(T),title:T==="split"?"Split view":"Remote only",children:T==="split"?"⊞":e.jsx(Ee,{size:14})},T)),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>f(k),title:"Chat History",children:e.jsx(ss,{size:14})}),e.jsx("button",{className:"btn btn-primary btn-sm",onClick:l,children:"Close"})]})]}),e.jsxs("div",{className:`dashboard-remote-dialog-body view-${b}`,children:[b!=="remote"&&e.jsxs("div",{className:"dashboard-remote-dialog-chat",children:[e.jsx(ho,{hasExtensions:C,ideName:S||"IDE",activeChatTab:j,extensionTabs:y,onSelectTab:m}),e.jsx(on,{activeConv:k,onModalButton:_.handleModalButton}),e.jsx(rs,{activeConv:k,ideEntry:g,showMetaChips:!1,handleSendChat:_.handleSendChat,isSendingChat:_.isSendingChat,handleFocusAgent:_.handleFocusAgent,isFocusingAgent:_.isFocusingAgent,actionLogs:N,userName:u})]}),e.jsx("div",{className:"dashboard-remote-dialog-remote",children:e.jsx(an,{addLog:()=>{},connState:k.connectionState||"new",connScreenshot:B,screenshotUsage:D,transportType:k.transport,onAction:P})})]})]})})}function xo({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 fo({historyModalOpen:t,historyTargetConv:s,ides:n,isHistoryCreatingChat:r,isHistoryRefreshingHistory:i,onCloseHistory:o,onNewHistoryChat:c,onSwitchHistorySession:h,onRefreshHistory:d,remoteDialogConv:x,remoteDialogIdeEntry:u,connectionStates:f,actionLogs:p,localUserMessages:l,sendDaemonCommand:b,setLocalUserMessages:v,setActionLogs:j,isStandalone:m,userName:g,onOpenRemoteHistory:S,onRemoteConversationChange:E,onCloseRemoteDialog:y,cliStopDialogOpen:C,activeConv:k,onCancelCliStop:w,onStopCliNow:_,onSaveCliAndStop:B,toasts:D,onDismissToast:P,onClickToast:N,showOnboarding:A,onCloseOnboarding:$}){return e.jsxs(e.Fragment,{children:[t&&s&&e.jsx(ja,{activeConv:s,ides:n,isCreatingChat:r,isRefreshingHistory:i,onClose:o,onNewChat:c,onSwitchSession:h,onRefreshHistory:d}),x&&e.jsx(po,{activeConv:x,ideEntry:u,ides:n,connectionStates:f,actionLogs:p,localUserMessages:l,sendDaemonCommand:b,setLocalUserMessages:v,setActionLogs:j,isStandalone:m,userName:g,onOpenHistory:S,onConversationChange:E,onClose:y}),C&&k&&Se(k)&&!ke(k)&&e.jsx(xo,{activeConv:k,onCancel:w,onStopNow:_,onSaveAndStop:B}),e.jsx(fn,{toasts:D,onDismiss:P,onClickToast:N}),A&&e.jsx(uo,{onClose:$})]})}function bo({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(Qs,{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=pt(o,{fallbackId:o.id}),h=n[o.id],d=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",d]}),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 go(){var us,hs;const{sendCommand:t}=We(),s=es(),n=tt(),[r,i]=fr(),o=r.get("activeTab"),c=((us=s.state)==null?void 0:us.openRemoteForTabKey)||null,h=((hs=s.state)==null?void 0:hs.openMachineId)||null,d=as(),{updateIdeChats:x,screenshotMap:u,setScreenshotMap:f}=d,p=d.ides||[],[l,b]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),v=d.toasts||[],j=d.setToasts||(()=>{}),m=d.wsStatus||"connected",g=d.isConnected??!0,S=d.connectionStates||{},E=d.showReconnected||!1,{groupAssignments:y,setGroupAssignments:C,focusedGroup:k,setFocusedGroup:w,groupActiveTabIds:_,setGroupActiveTabIds:B,groupTabOrders:D,setGroupTabOrders:P,groupSizes:N,setGroupSizes:A,isMobile:$,hasHydratedStoredLayout:T,hydrateStoredLayout:G}=Si(),[L,R]=a.useState(!1),[U,z]=a.useState(!1),[W]=a.useState(()=>Tn()),[Q,V]=a.useState([]),[ie,ee]=a.useState({}),[O,Y]=a.useState({}),[H,I]=a.useState(null);mt("Dashboard",{ideCount:p.length,toastCount:v.length,focusedGroup:k,groupCount:Object.keys(y).length,localMessageTabs:Object.keys(ie).length,actionLogCount:Q.length});const J=p.find(we=>we.type==="adhdev-daemon"),q=(J==null?void 0:J.detectedIdes)||[],te=!!J,ue=(J==null?void 0:J.terminalBackend)||null,{hiddenTabs:de,toggleTab:le}=An(),{chatIdes:Z,conversations:oe,visibleConversations:M,visibleTabKeys:X,resolveConversationByTarget:se}=xi({ides:p,connectionStates:S,localUserMessages:ie,clearedTabs:O,hiddenTabs:de}),{containerRef:ne,normalizedGroupAssignments:xe,numGroups:be,isSplitMode:pe,groupedConvs:ge,moveTabToGroup:K,closeGroup:F,handleResizeStart:re,splitTabRelative:ce}=Ei({groupAssignments:y,setGroupAssignments:C,setFocusedGroup:w,setGroupActiveTabIds:B,setGroupTabOrders:P,groupSizes:N,setGroupSizes:A,isMobile:$,visibleConversations:M,visibleTabKeys:X}),ae=a.useMemo(()=>{var Te,Ge;if(!$){if(H){const ze=oe.find(Wt=>Wt.tabKey===H);if(ze)return ze}return M[0]}const we=_[k];if(we){const ze=oe.find(Wt=>Wt.tabKey===we);if(ze)return ze}return((Te=ge[k])==null?void 0:Te[0])||((Ge=ge[0])==null?void 0:Ge[0])},[H,$,_,k,oe,ge,M]),{requestedDesktopTabKey:he,requestedMobileTabKey:je,consumeRequestedActiveTab:Ne}=fi({isMobile:$,urlActiveTab:o,resolveConversationByTarget:se,setSearchParams:i}),{remoteDialogConv:Be,remoteDialogIdeEntry:Ye,remoteDialogActiveConv:Ot,setRemoteDialogActiveConv:Xe,openRemoteDialog:ls,closeRemoteDialog:Wn}=Ii({isMobile:$,location:s,navigate:n,requestedRemoteTabTarget:c,requestedDesktopTabKey:he,conversations:oe,ides:p,resolveConversationByTarget:se}),ds=Ot||Be||ae,zn=a.useMemo(()=>M,[M]),xt=$&&W==="chat";di({visibleConversations:M,clearedTabs:O,setClearedTabs:Y,setActionLogs:V}),bi({ides:p,sendDaemonCommand:t,setToasts:j,setLocalUserMessages:ee,resolveConversationByTarget:se});const{isRefreshingHistory:Fn,handleLaunchIde:Un,handleRefreshHistory:Hn}=Ms({sendDaemonCommand:t,activeConv:ae,updateIdeChats:x,setToasts:j,setLocalUserMessages:ee,setClearedTabs:Y}),{isCreatingChat:Vn,isRefreshingHistory:qn,handleSwitchSession:Yn,handleNewChat:Xn,handleRefreshHistory:Gn}=Ms({sendDaemonCommand:t,activeConv:ds,updateIdeChats:x,setToasts:j,setLocalUserMessages:ee,setClearedTabs:Y});Ci({urlActiveTab:$&&!xt?o:null,conversations:oe,resolveConversationByTarget:se,normalizedGroupAssignments:xe,hasHydratedStoredLayout:$&&!xt?T:!0,hydrateStoredLayout:$&&!xt?G:()=>{},setGroupActiveTabIds:B,setFocusedGroup:w,setSearchParams:i,historyModalOpen:L,activeConv:ae,isRefreshingHistory:Fn,ides:p,handleRefreshHistory:Hn});const ft=a.useCallback(async we=>{if(!ae||!Se(ae)||ke(ae))return;const Te=ae.ideType||ae.agentType||"",Ge=ae.ideId||ae.daemonId||"";try{await t(Ge,"stop_cli",{cliType:Te,targetSessionId:ae.sessionId,mode:we})}catch(ze){console.error("Stop CLI failed:",ze)}},[ae,t]),Jn=a.useCallback(async()=>{var Te;if(!ae||!Se(ae)||ke(ae))return;if((Te=ae.resume)!=null&&Te.supported){z(!0);return}const we=ae.ideType||ae.agentType||"CLI";window.confirm(`Stop ${we}?
|
|
57
|
+
This will terminate the CLI process.`)&&await ft("hard")},[ae,ft]),Zn=a.useCallback(()=>{!ae||!Se(ae)||ke(ae)||!ae.sessionId||window.dispatchEvent(new CustomEvent("adhdev:fit-cli-terminal",{detail:{sessionId:ae.sessionId}}))},[ae]),{versionMismatchDaemons:Qn,appVersion:er,versionBannerDismissed:tr,setVersionBannerDismissed:sr,upgradingDaemons:nr,handleBannerUpgrade:rr}=_i({ides:p,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(ba,{wsStatus:m,showReconnected:E}),e.jsx(ga,{terminalBackend:ue,isStandalone:te}),!tr&&e.jsx(bo,{daemons:Qn,targetVersion:er,upgradingDaemons:nr,onUpgrade:rr,onDismiss:()=>sr(!0)}),e.jsx(lo,{showMobileChatMode:xt,isMobile:$,activeConv:ae,chatIdes:Z,wsStatus:m,isConnected:g,onOpenHistory:we=>{we&&Xe(we),R(!0)},onOpenRemote:ls,onFitCli:Zn,onStopCli:Jn,mobileChatConversations:zn,ides:p,actionLogs:Q,sendDaemonCommand:t,setLocalUserMessages:ee,setActionLogs:V,isStandalone:te,userName:d.userName,requestedMobileTabKey:je,onRequestedMobileTabConsumed:Ne,requestedMachineId:h,onRequestedMachineConsumed:()=>{n(s.pathname+s.search,{replace:!0,state:null})},containerRef:ne,isSplitMode:pe,numGroups:be,groupSizes:N,groupedConvs:ge,clearedTabs:O,screenshotMap:u,setScreenshotMap:f,focusedGroup:k,setFocusedGroup:w,moveTabToGroup:K,splitTabRelative:ce,closeGroup:F,handleResizeStart:re,detectedIdes:q,handleLaunchIde:Un,groupActiveTabIds:_,setGroupActiveTabIds:B,groupTabOrders:D,setGroupTabOrders:P,toggleHiddenTab:le,visibleConversations:M,requestedDesktopTabKey:he,onRequestedDesktopTabConsumed:Ne,onDesktopActiveTabChange:I}),e.jsx("style",{children:`
|
|
58
|
+
body { overflow: hidden; overscroll-behavior: none; }
|
|
59
|
+
`}),e.jsx(fo,{historyModalOpen:L,historyTargetConv:ds,ides:p,isHistoryCreatingChat:Vn,isHistoryRefreshingHistory:qn,onCloseHistory:()=>R(!1),onNewHistoryChat:Xn,onSwitchHistorySession:Yn,onRefreshHistory:Gn,remoteDialogConv:Be,remoteDialogIdeEntry:Ye,connectionStates:S,actionLogs:Q,localUserMessages:ie,sendDaemonCommand:t,setLocalUserMessages:ee,setActionLogs:V,isStandalone:te,userName:d.userName,onOpenRemoteHistory:we=>{we&&Xe(we),R(!0)},onRemoteConversationChange:Xe,onCloseRemoteDialog:Wn,cliStopDialogOpen:U,activeConv:ae,onCancelCliStop:()=>z(!1),onStopCliNow:async()=>{z(!1),await ft("hard")},onSaveCliAndStop:async()=>{z(!1),await ft("save")},toasts:v,onDismissToast:we=>j(Te=>Te.filter(Ge=>Ge.id!==we)),onClickToast:we=>{if(we.targetKey){const Te=se(we.targetKey);Te&&w(xe.get(Te.tabKey)??0)}},showOnboarding:l,onCloseOnboarding:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}b(!1)}})]})}function yo({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:i}){const[o,c]=a.useState([]),[h,d]=a.useState(null),[x,u]=a.useState(null),[f,p]=a.useState(!1),[l,b]=a.useState(null),[v,j]=a.useState(!1),[m,g]=a.useState(""),S=a.useRef(null),E=a.useCallback(L=>{S.current=L},[]),y=a.useCallback((L,R,U=!1)=>{c(z=>[...z.slice(-100),{timestamp:Date.now(),level:L,message:R}]),setTimeout(()=>{var z;return(z=i.current)==null?void 0:z.scrollIntoView({behavior:"smooth"})},100),U&&Ke.showToast(R,L==="error"||L==="warn"?"warning":"success")},[i]),C=a.useCallback(async(L,R)=>{var U;if(!t||h)return!1;d(L),y("info",`Launching ${ve(L)}${R!=null&&R.workspace?` in ${R.workspace}`:""}...`);try{const z={ideType:L,enableCdp:!0};(U=R==null?void 0:R.workspace)!=null&&U.trim()?z.workspace=R.workspace.trim():R!=null&&R.useDefaultWorkspace&&(z.useDefaultWorkspace=!0);const W=await n(t,"launch_ide",z);return y(W!=null&&W.success?"info":"error",W!=null&&W.success?`${ve(L)} launched`:`Failed: ${W==null?void 0:W.error}`,!0),!!(W!=null&&W.success)}catch(z){return y("error",`Launch error: ${z.message}`,!0),!1}finally{d(null)}},[t,h,y,n]),k=a.useCallback(async L=>{if(!t)return{success:!1};const{cliType:R,dir:U,workspaceId:z,useDefaultWorkspace:W,useHome:Q,argsStr:V,model:ie}=L;if(!R)return y("warn","Select a CLI or ACP provider first",!0),{success:!1};const ee=V?V.split(/\s+/).filter(Boolean):void 0,O=(U==null?void 0:U.trim())||(z?"(saved id)":W?"(default workspace)":Q?"(home)":"");y("info",`Launching ${R}${O?` in ${O}`:""}${ie?` (model: ${ie})`:""}...`),u(R);try{const Y={cliType:R,cliArgs:ee,initialModel:ie||void 0};U!=null&&U.trim()?Y.dir=U.trim():z?Y.workspaceId=z:W?Y.useDefaultWorkspace=!0:Q&&(Y.useHome=!0);const H=await n(t,"launch_cli",Y),I=(H==null?void 0:H.result)||H;return H!=null&&H.success?(y("info",`${R} launched`,!0),(I==null?void 0:I.launchSource)==="home"?y("info","📂 Running in home directory (explicit choice)"):(I==null?void 0:I.launchSource)==="defaultWorkspace"&&y("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:I==null?void 0:I.sessionId}):(y("error",`Failed: ${(H==null?void 0:H.error)||(I==null?void 0:I.error)}`,!0),(H==null?void 0:H.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&b({cliType:R,argsStr:V,model:ie}),{success:!1,sessionId:I==null?void 0:I.sessionId})}catch(Y){return y("error",`Launch error: ${Y.message}`,!0),{success:!1}}finally{u(null)}},[t,y,n]),w=a.useCallback(async(L,R,U,z)=>t?L?R.trim()?k({cliType:L,dir:R,argsStr:U,model:z}):(b({cliType:L,argsStr:U,model:z}),{success:!1}):(y("warn","Select a provider",!0),{success:!1}):{success:!1},[t,y,k]),_=a.useCallback(async(L,R,U)=>{if(t&&window.confirm(`Stop ${L}?
|
|
60
|
+
This will terminate the process.`))try{const z=await n(t,"stop_cli",{cliType:L,dir:R,targetSessionId:U});z!=null&&z.success?y("info",`${L} stopped`,!0):y("error",`Stop failed: ${(z==null?void 0:z.error)||"Unknown error"}`,!0)}catch(z){y("error",`Stop failed: ${z.message}`,!0)}},[t,y,n]),B=a.useCallback(async L=>{try{await n(L.daemonId,"restart_ide",{ideType:L.type}),y("info",`${ve(L.type)} restart initiated`,!0)}catch(R){y("error",`Restart failed: ${R.message}`,!0)}},[y,n]),D=a.useCallback(async L=>{if(window.confirm(`Stop ${ve(L.type)}?
|
|
61
|
+
This will disconnect CDP and optionally kill the process.`))try{const R=await n(L.daemonId,"stop_ide",{ideType:L.type,killProcess:!0});R!=null&&R.success?y("info",`${ve(L.type)} stopped`,!0):y("error",`Stop failed: ${(R==null?void 0:R.error)||"Unknown error"}`,!0)}catch(R){y("error",`Stop failed: ${R.message}`,!0)}},[y,n]),P=a.useCallback(async()=>{if(t)try{const L=await n(t,"detect_ides",{});y("info",`Found ${((L==null?void 0:L.result)||[]).length} IDE(s)`,!0)}catch(L){y("error",`Detection failed: ${L.message}`,!0)}},[t,y,n]),N=a.useCallback(async L=>{if(!(!t||!L.trim())){p(!0);try{const R=await n(t,"workspace_add",{path:L.trim()});R!=null&&R.success?y("info",`Workspace added: ${L.trim()}`):y("error",(R==null?void 0:R.error)||"workspace_add failed")}catch(R){y("error",R.message)}finally{p(!1)}return!0}},[t,y,n]),A=a.useCallback(async L=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){p(!0);try{const R=await n(t,"workspace_remove",{id:L});R!=null&&R.success?y("info","Workspace removed",!0):y("error",(R==null?void 0:R.error)||"workspace_remove failed",!0)}catch(R){y("error",R.message,!0)}finally{p(!1)}}},[t,y,n]),$=a.useCallback(async L=>{var R;if(t){p(!0);try{const U=await n(t,"workspace_set_default",L===null?{clear:!0}:{id:L});if(U!=null&&U.success){y("info",L?"Default workspace updated":"Default workspace cleared",!0);const z=typeof U.defaultWorkspacePath=="string"?U.defaultWorkspacePath:"";z&&((R=S.current)==null||R.call(S,z))}else y("error",(U==null?void 0:U.error)||"workspace_set_default failed",!0)}catch(U){y("error",U.message,!0)}finally{p(!1)}}},[t,y,n]),T=a.useCallback(async L=>{var U;if(!t||!L.trim())return;const R=L.trim();p(!0);try{const z=await n(t,"workspace_set_default",{path:R});z!=null&&z.success?(y("info","Default workspace set from history"),(U=S.current)==null||U.call(S,R)):y("error",(z==null?void 0:z.error)||"Could not set default (path missing on disk?)")}catch(z){y("error",z.message)}finally{p(!1)}},[t,y,n]),G=a.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:m}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:m})}catch(L){y("warn",`Live nickname updated, but account sync failed: ${L.message}`)}y("info",`Nickname set to "${m||"(cleared)"}"`),j(!1)}catch(L){y("error",`Failed: ${L.message}`)}},[t,m,s,y,r,n]);return{logs:o,launchingIde:h,launchingAgentType:x,workspaceBusy:f,launchPick:l,setLaunchPick:b,editingNickname:v,setEditingNickname:j,nicknameInput:m,setNicknameInput:g,addLog:y,handleLaunchIde:C,runLaunchCliCore:k,handleLaunchCli:w,handleStopCli:_,handleRestartIde:B,handleStopIde:D,handleDetectIdes:P,handleWorkspaceAdd:N,handleWorkspaceRemove:A,handleWorkspaceSetDefault:$,handleWorkspaceResumePath:T,handleSaveNickname:G,setOnDefaultWorkspaceChanged:E}}function vo({machine:t,ideSessions:s,cliSessions:n,acpSessions:r,actions:i,isDashboardHidden:o,onToggleDashboardVisibility:c}){const{workspaceBusy:h,handleWorkspaceAdd:d,handleWorkspaceRemove:x,handleWorkspaceSetDefault:u}=i,[f,p]=a.useState(""),l=t.availableMem??t.freeMem,b=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-l)/t.totalMem*100))):0,v=t.loadavg[0]||0,j=[...s.map(m=>({id:m.id,label:`IDE · ${m.type}`,workspace:m.workspace||""})),...n.map(m=>({id:m.id,label:`CLI · ${m.cliName}`,workspace:m.workspace||""})),...r.map(m=>({id:m.id,label:`ACP · ${m.acpName}`,workspace:m.workspace||""}))].filter(m=>o==null?void 0:o(m.id));return e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-5",children:[e.jsx(bt,{icon:e.jsx(tn,{size:16}),label:"Uptime",value:aa(t.uptime)}),e.jsx(bt,{icon:e.jsx(Ee,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(bt,{icon:e.jsx(sn,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(bt,{icon:e.jsx(Lr,{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(bs,{value:Math.min(Math.round(v/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${v.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(bs,{value:b,max:100,label:"Memory",color:"#3b82f6",detail:`${vs(t.totalMem-l)} / ${vs(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(Yt,{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:m=>void u(m.target.value===""?null:m.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(m=>e.jsx("option",{value:m.id,children:m.label||m.path},m.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:f,disabled:h,onChange:m=>p(m.target.value),onKeyDown:m=>m.key==="Enter"&&void(async()=>{await d(f)&&p("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:h,onClick:async()=>{await d(f)&&p("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1.5 max-h-40 overflow-y-auto",children:(t.workspaces||[]).map(m=>e.jsxs("li",{className:"flex items-start gap-2 text-[11px] text-text-muted rounded-lg border border-border-subtle bg-bg-primary px-2.5 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[m.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:ln(m.path,m.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:m.path,children:m.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:h,onClick:()=>void x(m.id),children:"Remove"})]},m.id))})]}),j.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:j.map(m=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[12px] font-medium text-text-primary truncate",children:m.label}),m.workspace&&e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:m.workspace,children:m.workspace})]}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] px-2.5 py-1 text-zinc-300 border-zinc-500/30",onClick:()=>c(m.id),children:"Show"})]},m.id))})]})]})}const Ds=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],jo=[{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 wo({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[i,o]=a.useState("config"),[c,h]=a.useState("codex-cli"),[d,x]=a.useState([]),[u,f]=a.useState(""),[p,l]=a.useState([]),[b,v]=a.useState(""),j=a.useRef(null),m=a.useRef(null),g=w=>{x(_=>_.includes(w)?_.filter(B=>B!==w):[..._,w])},S=()=>x([...Ds]),E=()=>x([]);a.useEffect(()=>{var w;(w=j.current)==null||w.scrollIntoView({behavior:"smooth"})},[p]),a.useEffect(()=>()=>{m.current&&clearInterval(m.current)},[]);const y=a.useCallback(()=>{m.current&&clearInterval(m.current),m.current=setInterval(async()=>{try{const w=await n(t,"provider_auto_fix_status",{providerType:s.type});(w==null?void 0:w.running)===!1&&i==="running"&&(o("done"),l(_=>[..._,`
|
|
62
|
+
✅ Auto-fix completed!`]),m.current&&clearInterval(m.current))}catch{}},3e3)},[t,s.type,n,i]),C=async()=>{if(d.length!==0){o("running"),l(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${d.join(", ")}`,u?`💬 Comment: ${u}`:"",""]),v("");try{const w=await n(t,"provider_auto_fix",{providerType:s.type,functions:d,agent:c,...u?{comment:u}:{}});w!=null&&w.success&&(w!=null&&w.started||w!=null&&w.running)?(l(_=>[..._,"✅ Agent started. Monitoring progress..."]),y()):(o("error"),v((w==null?void 0:w.error)||"Failed to start auto-fix"))}catch(w){o("error"),v((w==null?void 0:w.message)||"Connection failed")}}},k=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),l(w=>[...w,`
|
|
63
|
+
⚠️ Auto-fix cancelled.`]),o("done"),m.current&&clearInterval(m.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:w=>w.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:jo.map(w=>e.jsxs("button",{onClick:()=>h(w.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===w.value?w.color+"66":"var(--border-subtle)",background:c===w.value?w.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===w.value?w.color:"var(--text-primary)"},children:w.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:w.desc})]},w.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:S,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:E,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:Ds.map(w=>e.jsxs("button",{onClick:()=>g(w),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:d.includes(w)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:d.includes(w)?"rgba(139,92,246,0.08)":"transparent",color:d.includes(w)?"#a78bfa":"var(--text-secondary)"},children:[d.includes(w)?"☑ ":"☐ ",w]},w))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:["Additional Instructions ",e.jsx("span",{className:"text-text-muted font-normal",children:"(optional)"})]}),e.jsx("textarea",{value:u,onChange:w=>f(w.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:[p.map((w,_)=>e.jsx("div",{className:w.startsWith("✅")?"text-green-400":"",style:w.startsWith("❌")||w.startsWith("⚠")?{color:"var(--status-warning)"}:void 0,children:w},_)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:j})]}),b&&e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:b})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-between items-center",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[i==="config"&&d.length>0&&`${d.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:d.length===0,className:"machine-btn",style:{background:d.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:d.length>0?"rgba(139,92,246,0.4)":void 0,color:d.length>0?"#a78bfa":void 0,opacity:d.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:k,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(i==="done"||i==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{o("config"),l([]),v("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function ko({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:i}){var y;const o=s.filter(C=>C.category==="ide"),[c,h]=a.useState(((y=o[0])==null?void 0:y.type)||""),[d,x]=a.useState(""),[u,f]=a.useState(""),[p,l]=a.useState(!1),[b,v]=a.useState(""),[j,m]=a.useState(!1),g=C=>{const k=C.toLowerCase().replace(/[^a-z0-9-]/g,"");x(k),(!u||u===S(d))&&f(S(k))},S=C=>C.split("-").map(k=>k.charAt(0).toUpperCase()+k.slice(1)).join(" "),E=async()=>{if(!(!d||!u||!c)){l(!0),v("");try{const C=await n(t,"provider_clone",{type:d,name:u,category:"ide",location:"user",cloneFrom:c});C!=null&&C.success||C!=null&&C.created?(m(!0),i==null||i(d)):v((C==null?void 0:C.error)||"Failed to create provider")}catch(C){v((C==null?void 0:C.message)||"Connection failed")}l(!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:d})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",d,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",d]})," 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:d,onChange:C=>g(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/",d||"...","/"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Display Name"}),e.jsx("input",{value:u,onChange:C=>f(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"})]}),b&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:b})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children: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:E,disabled:!d||!u||p,className:"machine-btn",style:{background:d&&u?"rgba(34,197,94,0.12)":void 0,borderColor:d&&u?"rgba(34,197,94,0.3)":void 0,color:d&&u?"#86efac":void 0,opacity:!d||!u||p?.4:1},children:p?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function No({machineId:t,providers:s,sendDaemonCommand:n}){const[r,i]=a.useState([]),[o,c]=a.useState(!1),[h,d]=a.useState(null),[x,u]=a.useState("all"),[f,p]=a.useState(null),[l,b]=a.useState(!1),v=a.useCallback(async()=>{var m;if(t){c(!0);try{const g=await n(t,"get_provider_settings",{}),S=(g==null?void 0:g.result)||g;if(g!=null&&g.success&&(S!=null&&S.settings)){const E=[];for(const[y,C]of Object.entries(S.settings)){const k=s.find(w=>w.type===y);E.push({type:y,displayName:(k==null?void 0:k.displayName)||y,icon:(k==null?void 0:k.icon)||"",category:(k==null?void 0:k.category)||"unknown",schema:C,values:((m=S.values)==null?void 0:m[y])||{}})}E.sort((y,C)=>y.category.localeCompare(C.category)||y.displayName.localeCompare(C.displayName)),i(E)}}catch{}c(!1)}},[t,s,n]);a.useEffect(()=>{r.length===0&&v()},[]);const j=async(m,g,S)=>{d(`${m}.${g}`),i(E=>E.map(y=>y.type===m?{...y,values:{...y.values,[g]:S}}:y));try{const E=await n(t,"set_provider_setting",{providerType:m,key:g,value:S});E!=null&&E.success||v()}catch{v()}d(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(m=>e.jsx("button",{onClick:()=>u(m),className:`machine-btn text-[10px] px-2 py-0.5 ${x===m?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:m.toUpperCase()},m))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>b(!0),className:"machine-btn text-[10px] bg-green-500/[0.06] border-green-500/20 text-green-400 hover:bg-green-500/[0.12]",children:"✨ Create Provider"}),e.jsx("button",{onClick:v,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),x!=="all"&&r.filter(m=>m.category===x).length>1&&(()=>{const m=r.filter(y=>y.category===x),g=new Map;for(const y of m)for(const C of y.schema){if(C.type!=="boolean")continue;const k=g.get(C.key),w=!!(y.values[C.key]??C.default);k?(k.onCount+=w?1:0,k.total+=1):g.set(C.key,{label:C.label||C.key,onCount:w?1:0,total:1})}const S=[...g.entries()].filter(([,y])=>y.total===m.length);if(S.length===0)return null;const E=async(y,C)=>{for(const k of m)await j(k.type,y,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 ",x.toUpperCase()," providers (",m.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:S.map(([y,C])=>{const k=C.onCount===C.total,w=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 E(y,!0),disabled:k,className:`machine-btn text-[9px] px-1.5 py-px ${k?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void E(y,!1),disabled:w,className:`machine-btn text-[9px] px-1.5 py-px ${w?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},y)})})]})})(),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(m=>x==="all"||m.category===x).map(m=>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:m.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:m.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:m.category==="acp"?"rgba(139,92,246,0.08)":m.category==="cli"?"rgba(59,130,246,0.08)":m.category==="ide"?"rgba(34,197,94,0.08)":"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:m.category==="acp"?"#a78bfa":m.category==="cli"?"#60a5fa":m.category==="ide"?"#86efac":"var(--status-warning)"},children:m.category}),m.category==="ide"&&e.jsx("button",{onClick:()=>p(s.find(g=>g.type===m.type)||{type:m.type,name:m.displayName,displayName:m.displayName,icon:m.icon,category:m.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:m.schema.map(g=>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:[g.label||g.key,h===`${m.type}.${g.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),g.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:g.description})]}),e.jsx("div",{className:"shrink-0",children:g.type==="boolean"?e.jsx("button",{onClick:()=>j(m.type,g.key,!(m.values[g.key]??g.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:m.values[g.key]??g.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:m.values[g.key]??g.default?21:3}})}):g.type==="number"?e.jsx("input",{type:"number",value:m.values[g.key]??g.default??0,min:g.min,max:g.max,onChange:S=>{const E=parseInt(S.target.value)||0;g.min!==void 0&&E<g.min||g.max!==void 0&&E>g.max||j(m.type,g.key,E)},className:"machine-input w-20 text-center text-[11px]"}):g.type==="select"&&g.options?e.jsx("select",{value:m.values[g.key]??g.default??"",onChange:S=>j(m.type,g.key,S.target.value),className:"machine-input text-[11px]",children:g.options.map(S=>e.jsx("option",{value:S,children:S},S))}):e.jsx("input",{type:"text",value:m.values[g.key]??g.default??"",onBlur:S=>j(m.type,g.key,S.target.value),className:"machine-input w-[120px] text-[11px]"})})]},g.key))})]},m.type))}),f&&e.jsx(wo,{machineId:t,provider:f,sendDaemonCommand:n,onClose:()=>p(null)}),l&&e.jsx(ko,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>b(!1),onCreated:()=>{b(!1),v()}})]})}function So({machineId:t,sendDaemonCommand:s}){const[n,r]=a.useState([]),[i,o]=a.useState(0),[c,h]=a.useState(!0),[d,x]=a.useState("debug"),u=a.useRef(null),f=a.useRef(!1);return a.useEffect(()=>{if(!t||!c)return;const p=async()=>{try{const b=await s(t,"get_logs",{count:200,minLevel:d,since:i}),v=(b==null?void 0:b.result)||b;if(b!=null&&b.success&&Array.isArray(v==null?void 0:v.logs)&&v.logs.length>0){r(m=>[...m,...v.logs.map(S=>({timestamp:S.ts,level:S.level,message:`[${S.category}] ${S.message}`}))].slice(-300));const j=Math.max(...v.logs.map(m=>m.ts));o(j)}}catch{}};p();const l=setInterval(p,3e3);return()=>clearInterval(l)},[t,c,i,d,s]),a.useEffect(()=>{if(c&&n.length>0){const p=f.current?"smooth":"instant";setTimeout(()=>{var l;(l=u.current)==null||l.scrollIntoView({behavior:p}),f.current=!0},50)}},[n.length,c]),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-3",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Level"}),["debug","info","warn","error"].map(p=>e.jsx("button",{onClick:()=>{x(p),r([]),o(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${d===p?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:p.toUpperCase()},p))]}),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((p,l)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:p.level==="error"?"#ef4444":p.level==="warn"?"var(--status-warning)":p.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(p.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:p.level==="error"?"#ef4444":p.level==="warn"?"var(--status-warning)":p.level==="debug"?"#475569":"#8b5cf6"},children:p.level==="error"?"ERR":p.level==="warn"?"WRN":p.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:p.message})]},l)),e.jsx("div",{ref:u})]})]})}function Co({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 $s({children:t}){return e.jsx("div",{className:"machine-command-section-title",children:t})}function Io({machineEntry:t,providers:s,recentSessions:n,onUpgradeDaemon:r,onOpenLogs:i,onOpenRecent:o,onOpenWorkspace:c,onGoTab:h}){const d=t.detectedIdes||[],x=s.filter(b=>b.category==="cli"),u=s.filter(b=>b.category==="acp"),f=n.slice(0,4),p=[d.length>0?{id:"ide",kind:"ide",label:"IDE"}:null,x.length>0?{id:"cli",kind:"cli",label:"CLI"}:null,u.length>0?{id:"acp",kind:"acp",label:"ACP"}:null].filter(Boolean),l=b=>b==="ide"?"IDE":b==="cli"?"CLI":"ACP";return e.jsxs("div",{className:"machine-command-center",children:[f.length>0&&e.jsxs(e.Fragment,{children:[e.jsx($s,{children:"Recent"}),e.jsx("div",{className:"machine-command-links",children:f.map(b=>e.jsxs("button",{type:"button",className:"machine-command-link",onClick:()=>o(b),children:[e.jsx("span",{className:"machine-command-link-title",children:b.label}),e.jsxs("span",{className:"machine-command-link-meta",children:[l(b.kind),b.subtitle?` · ${b.subtitle}`:""]})]},b.id))})]}),p.length>0&&e.jsxs(e.Fragment,{children:[e.jsx($s,{children:"Start"}),e.jsx("div",{className:"machine-command-launch-grid",children:p.map(b=>e.jsxs("button",{type:"button",className:"machine-command-launch-btn",onClick:()=>c(b.kind),children:[e.jsx("span",{className:"machine-command-launch-title",children:b.label}),e.jsx("span",{className:"machine-command-launch-meta",children:"Choose workspace and provider"})]},b.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 Mo(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const To={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 qt({category:t,machine:s,machineId:n,providers:r,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:h,isDashboardHidden:d,onToggleDashboardVisibility:x,initialWorkspaceId:u,initialWorkspacePath:f}){const p=tt(),{handleLaunchIde:l,handleLaunchCli:b,handleStopCli:v,handleRestartIde:j,handleStopIde:m,handleDetectIdes:g,launchingIde:S,launchingAgentType:E}=c,[y,C]=a.useState(null),k=a.useCallback(M=>{M&&p({pathname:"/",search:`?activeTab=${encodeURIComponent(M)}`})},[p]),w=To[t],_=t==="ide",B=t==="acp",D=r.filter(M=>M.category===t),P=new Map(D.map(M=>[M.type,M.displayName||M.type])),[N,A]=a.useState(""),[$,T]=a.useState(""),[G,L]=a.useState(""),[R,U]=a.useState(f?"__custom__":u||s.defaultWorkspaceId||""),[z,W]=a.useState(f||""),[Q,V]=a.useState([]),ie=Q.filter(M=>!i.some(X=>X.type===M&&Me(X.status)!=="stopped")),ee=a.useRef({});a.useEffect(()=>{!N&&D.length>0&&A(D[0].type)},[N,D.length]),a.useEffect(()=>{s.defaultWorkspaceId&&!R&&U(s.defaultWorkspaceId)},[s.defaultWorkspaceId]),a.useEffect(()=>{if(f){U("__custom__"),W(f);return}u&&(U(u),W(""))},[u,f]);const O=(()=>{if(R==="__custom__")return z.trim();if(!R)return"";const M=(s.workspaces||[]).find(X=>X.id===R);return(M==null?void 0:M.path)||""})(),Y=a.useCallback(M=>{const X=ee.current[M];X&&(clearTimeout(X),delete ee.current[M]),V(se=>se.filter(ne=>ne!==M))},[]),H=a.useCallback(M=>{if(!M)return;V(se=>se.includes(M)?se:[...se,M]);const X=ee.current[M];X&&clearTimeout(X),ee.current[M]=setTimeout(()=>{V(se=>se.filter(ne=>ne!==M)),delete ee.current[M]},2e4)},[]);a.useEffect(()=>{for(const M of i)Me(M.status)!=="stopped"&&Y(M.type)},[i,Y]),a.useEffect(()=>()=>{Object.values(ee.current).forEach(clearTimeout),ee.current={}},[]);const[I,J]=a.useState({}),[q,te]=a.useState(null);a.useEffect(()=>{if(!_||!n||!h)return;(async()=>{try{const X=await h(n,"get_ide_extensions",{}),se=(X==null?void 0:X.result)||X;se!=null&&se.success&&(se!=null&&se.ideExtensions)&&J(se.ideExtensions)}catch{}})()},[_,n,h]);const ue=M=>_?ve(M.type):t==="cli"?M.cliName:M.acpName,de=_?s.detectedIdes||[]:[],le=()=>{(async()=>{if(_){await l(N,O?{workspace:O}:void 0)&&H(N);return}const M=await b(N,O,$||void 0,B&&G||void 0);M.success&&(H(N),M.sessionId&&k(M.sessionId))})()},Z=M=>{_?m(M):v(M.type,M.workspace,M.id)},oe=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:R,onChange:M=>{U(M.target.value),M.target.value!=="__custom__"&&W("")},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(M=>e.jsxs("option",{value:M.id,children:[M.id===s.defaultWorkspaceId?"⭐ ":"",ln(M.path,M.label)]},M.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…"})]})}),R==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:z,onChange:M=>W(M.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:R==="__custom__"?O?e.jsx("span",{className:"font-mono truncate block",title:O,children:O}):"Enter an absolute path to launch there.":O?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:R===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:O,children:O})]}):"No workspace selected. This launches in the home directory."})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${w.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",w.label]}),oe,_?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[de.map(M=>{const X=i.find(be=>(be.type||"").toLowerCase()===(M.type||"").toLowerCase()&&Me(be.status)!=="stopped"),se=M.running||!!X,ne=!!X&&X.cdpConnected,xe=Q.includes(M.type||M.id||"");return e.jsxs("button",{onClick:()=>{if(ne&&X){p(`/dashboard?activeTab=${encodeURIComponent(X.id)}`,{state:{openRemoteForTabKey:X.id}});return}xe||(async()=>await l(M.type||M.id||"",O?{workspace:O}:void 0)&&H(M.type||M.id||""))()},disabled:!!S||xe,className:`machine-btn-primary flex items-center gap-1.5 ${se?"!border-green-500/30":""}`,style:{opacity:S&&S!==M.type?.4:1},children:[e.jsx("span",{children:o(M.type)}),se&&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)]"}),xe?`⏳ Waiting for ${M.name||ve(M.type)}...`:ne?`Open ${M.name||ve(M.type)}`:S===M.type?"⏳ Launching...":`▶ ${M.name||ve(M.type)}`,se&&ne&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"running"})]},M.type)}),de.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:g,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(_r,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:N,onChange:M=>A(M.target.value),className:"machine-input",children:D.length>0?D.map(M=>e.jsxs("option",{value:M.type,children:[M.icon," ",M.displayName]},M.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),B&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:G,onChange:M=>L(M.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:$,onChange:M=>T(M.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:le,disabled:!!E,className:"machine-btn-primary",children:E===N?"⏳ Launching...":"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length+Q.filter(M=>!i.some(X=>X.type===M&&Me(X.status)!=="stopped")).length,")"]}),i.length===0&&ie.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 ",w.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[ie.map(M=>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(M)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:_?ve(M):P.get(M)||M}),e.jsx("div",{className:"text-[11px] text-text-muted",children:E===M?"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:${M}`)),i.map(M=>{const X=_?M:null,se=B?M:null,ne=!_&&!B?M:null,xe=Me(M.status),be=(d==null?void 0:d(M.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(M.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ue(M),(X==null?void 0:X.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",X.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:M.workspace||"—"}),(se==null?void 0:se.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",se.currentModel]}),(se==null?void 0:se.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",se.currentPlan]})]}),ne&&(ne.runtimeKey||ne.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[ne.runtimeKey&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-secondary",children:"Local terminal:"}),e.jsxs("span",{className:"font-mono text-text-secondary",children:["adhdev attach ",ne.runtimeKey]}),e.jsx("button",{type:"button",className:"machine-btn text-[9px] px-1.5 py-px",onClick:()=>{var pe;(pe=navigator.clipboard)==null||pe.writeText(`adhdev attach ${ne.runtimeKey}`),C(ne.runtimeKey||null),window.setTimeout(()=>{C(ge=>ge===ne.runtimeKey?null:ge)},1200)},children:y===ne.runtimeKey?"Copied":"Copy"})]}),ne.runtimeWriteOwner&&e.jsx("span",{style:{color:ne.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:ne.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:Mo(ne.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[x&&e.jsx("button",{onClick:()=>x(M.id),className:`machine-btn ${be?"text-zinc-300 border-zinc-500/30":"text-violet-400 border-violet-500/30"}`,title:be?"Show on Dashboard":"Hide from Dashboard",children:be?"Show":"Hide"}),e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${xe==="stopped"?"bg-red-500/[0.08] text-red-500":xe==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:xe}),_&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>p(`/dashboard?activeTab=${encodeURIComponent(M.id)}`,{state:{openRemoteForTabKey:M.id}}),className:"machine-btn flex items-center gap-1",children:[e.jsx(Ee,{size:13})," Control"]}),e.jsx("button",{onClick:()=>j(M),className:"machine-btn",style:{color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"},children:"↻"})]}),B&&e.jsx("button",{onClick:()=>p(`/dashboard?activeTab=${encodeURIComponent(M.id)}`),className:"machine-btn",title:"View chat",children:e.jsx(ht,{size:14})}),ne&&xe!=="stopped"&&e.jsxs("button",{onClick:()=>k(M.id),className:"machine-btn flex items-center gap-1",title:"Open terminal in dashboard",children:[e.jsx(Ee,{size:13})," Open"]}),xe==="stopped"?e.jsx("button",{onClick:()=>{(async()=>{if(_){await l(M.type,M.workspace?{workspace:M.workspace}:void 0)&&H(M.type);return}const pe=await b(M.type,M.workspace);pe.success&&(H(M.type),pe.sessionId&&k(pe.sessionId))})()},disabled:Q.includes(M.type),className:"machine-btn text-green-500 border-green-500/30",children:Q.includes(M.type)?"⏳":"▶"}):e.jsx("button",{onClick:()=>Z(M),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),X&&X.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:X.aiAgents.map(pe=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${cn(pe.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[pe.name," · ",Me(pe.status)]},pe.id))}),X&&(I[X.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:(I[X.type]||[]).map(pe=>e.jsxs("button",{disabled:q===`${X.type}.${pe.type}`,onClick:async()=>{const ge=`${X.type}.${pe.type}`;te(ge);try{await h(n,"set_ide_extension",{ideType:X.type,extensionType:pe.type,enabled:!pe.enabled}),J(K=>({...K,[X.type]:(K[X.type]||[]).map(F=>F.type===pe.type?{...F,enabled:!F.enabled}:F)}))}catch(K){console.error("Extension toggle failed:",K)}finally{te(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 ${pe.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 ${pe.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),pe.name,e.jsx("span",{className:"text-[9px] font-normal",children:pe.enabled?"ON":"OFF"})]},pe.type))})]})]},M.id)})]})]})}const Bs=[{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 Ro({machine:t,machineId:s,providers:n,ideSessions:r,cliSessions:i,acpSessions:o,actions:c,getIcon:h,initialCategory:d="ide",initialWorkspaceId:x,initialWorkspacePath:u,isDashboardHidden:f,onToggleDashboardVisibility:p,sendDaemonCommand:l}){var m;const[b,v]=a.useState(d);a.useEffect(()=>{v(d)},[d]);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:Bs.map(g=>e.jsxs("button",{type:"button",className:`machine-workspace-section-tab${b===g.id?" active":""}`,onClick:()=>v(g.id),children:[e.jsx("span",{children:g.label}),e.jsx("span",{className:"machine-workspace-section-count",children:j[g.id]})]},g.id))}),e.jsx("div",{className:"machine-workspace-section-helper",children:(m=Bs.find(g=>g.id===b))==null?void 0:m.helper}),b==="ide"&&e.jsx(qt,{category:"ide",machine:t,machineId:s,providers:n,managedEntries:r,getIcon:h,actions:c,isDashboardHidden:f,onToggleDashboardVisibility:p,sendDaemonCommand:l,initialWorkspaceId:x,initialWorkspacePath:u}),b==="cli"&&e.jsx(qt,{category:"cli",machine:t,machineId:s,providers:n,managedEntries:i,getIcon:h,actions:c,isDashboardHidden:f,onToggleDashboardVisibility:p,initialWorkspaceId:x,initialWorkspacePath:u}),b==="acp"&&e.jsx(qt,{category:"acp",machine:t,machineId:s,providers:n,managedEntries:o,getIcon:h,actions:c,isDashboardHidden:f,onToggleDashboardVisibility:p,initialWorkspaceId:x,initialWorkspacePath:u})]})}function Ao({onNicknameSynced:t}={}){var z,W,Q,V,ie,ee,O,Y,H;const{id:s}=Us(),n=tt(),r=es(),{sendCommand:i}=We(),o=as(),c=o.ides||[],h=o.initialLoaded??!0,{isHidden:d,toggleTab:x}=An(),u=c.find(I=>I.id===s&&I.daemonMode),[f,p]=a.useState("workspace"),[l,b]=a.useState("ide"),v=a.useRef(null),j=yo({machineId:s,registeredMachineId:(u==null?void 0:u.machineId)||null,sendDaemonCommand:i,onNicknameSynced:t,logsEndRef:v});a.useEffect(()=>Ke.onToast(J=>{o.setToasts(te=>{if(te.some(le=>le.message===J.message&&J.timestamp-le.timestamp<3e3))return te;const de={id:J.id,message:J.message,type:J.type,timestamp:J.timestamp,targetKey:J.targetKey,actions:J.actions};return[...te.slice(-4),de]});const q=J.duration||5e3;setTimeout(()=>o.setToasts(te=>te.filter(ue=>ue.id!==J.id)),q)}),[o]);const m=(u==null?void 0:u.availableProviders)||[],g={};for(const I of m)g[I.type]=I.icon;const S=I=>g[I]||"",E=u?{id:u.id,hostname:dn(u,{fallbackId:u.id}),platform:((z=u.machine)==null?void 0:z.platform)||"unknown",arch:((W=u.machine)==null?void 0:W.arch)||"",cpus:((Q=u.machine)==null?void 0:Q.cpus)||0,totalMem:((V=u.machine)==null?void 0:V.totalMem)||0,freeMem:((ie=u.machine)==null?void 0:ie.freeMem)||0,availableMem:(ee=u.machine)==null?void 0:ee.availableMem,loadavg:((O=u.machine)==null?void 0:O.loadavg)||[],uptime:((Y=u.machine)==null?void 0:Y.uptime)||0,release:((H=u.machine)==null?void 0:H.release)||"",cdpConnected:!!u.cdpConnected,machineNickname:u.machineNickname||null,p2p:u.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:u.detectedIdes||[],workspaces:u.workspaces||[],defaultWorkspaceId:u.defaultWorkspaceId??u.activeWorkspaceId??null,defaultWorkspacePath:u.defaultWorkspacePath??u.activeWorkspacePath??null}:null,y=c.filter(I=>I.daemonId===s&&!I.daemonMode).filter(I=>!Tt(I)&&!it(I)).map(I=>({id:I.id,type:I.type,version:I.version||"",instanceId:I.instanceId||"",status:I.status,workspace:I.workspace||null,terminals:I.terminals||0,aiAgents:ua(I.aiAgents||I.agents||[]),activeChat:I.activeChat||null,chats:I.chats||[],childSessions:I.childSessions||[],cdpConnected:I.cdpConnected||!1,daemonId:s})),C=c.filter(I=>I.daemonId===s&&Tt(I)).map(I=>({id:I.id,type:I.type,cliName:I.cliName||I.type,status:I.status,workspace:I.workspace||"",activeChat:I.activeChat||null,daemonId:s})),k=c.filter(I=>I.daemonId===s&&it(I)).map(I=>({id:I.id,type:I.type,acpName:I.cliName||I.type,status:I.status,workspace:I.workspace||"",activeChat:I.activeChat||null,currentModel:I.currentModel,currentPlan:I.currentPlan,daemonId:s}));if(!E)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 w=pt(u,{fallbackId:E.id}),_="workspace",B=r.state,D=B==null?void 0:B.initialMachineTab,P=B==null?void 0:B.initialWorkspaceCategory,N=B==null?void 0:B.initialWorkspaceId,A=B==null?void 0:B.initialWorkspacePath,$=D==="ides"||D==="clis"||D==="acps"?"workspace":D||_,T=D==="ides"?"ide":D==="clis"?"cli":D==="acps"?"acp":P,G=[...y.map(I=>{var J,q,te,ue,de;return{id:I.id,sessionId:I.id,label:((J=I.activeChat)==null?void 0:J.title)||I.type,kind:"ide",providerType:I.type,subtitle:I.workspace||void 0,workspace:I.workspace||void 0,timestamp:((de=(ue=(te=(q=I.activeChat)==null?void 0:q.messages)==null?void 0:te.at)==null?void 0:ue.call(te,-1))==null?void 0:de.timestamp)||0}}),...C.map(I=>{var J,q,te,ue,de;return{id:I.id,sessionId:I.id,label:((J=I.activeChat)==null?void 0:J.title)||I.cliName,kind:"cli",providerType:I.type,subtitle:I.workspace||void 0,workspace:I.workspace||void 0,timestamp:((de=(ue=(te=(q=I.activeChat)==null?void 0:q.messages)==null?void 0:te.at)==null?void 0:ue.call(te,-1))==null?void 0:de.timestamp)||0}}),...k.map(I=>{var J,q,te,ue,de;return{id:I.id,sessionId:I.id,label:((J=I.activeChat)==null?void 0:J.title)||I.acpName,kind:"acp",providerType:I.type,subtitle:I.currentModel||I.workspace||void 0,workspace:I.workspace||void 0,currentModel:I.currentModel,timestamp:((de=(ue=(te=(q=I.activeChat)==null?void 0:q.messages)==null?void 0:te.at)==null?void 0:ue.call(te,-1))==null?void 0:de.timestamp)||0}})].sort((I,J)=>J.timestamp-I.timestamp).map(({timestamp:I,...J})=>J),L=(u.recentSessions||[]).length>0?u.recentSessions.map(I=>({id:I.id,sessionId:I.sessionId||I.id,label:I.title||I.providerName||I.providerType,kind:I.kind,providerType:I.providerType,subtitle:I.currentModel||I.workspace||void 0,workspace:I.workspace,currentModel:I.currentModel})):G,R=async I=>{if(I.sessionId){n(`/dashboard?activeTab=${encodeURIComponent(I.sessionId)}`);return}if(I.kind==="ide"&&I.providerType){await j.handleLaunchIde(I.providerType,I.workspace?{workspace:I.workspace}:void 0);return}if((I.kind==="cli"||I.kind==="acp")&&I.providerType){await j.runLaunchCliCore({cliType:I.providerType,dir:I.workspace||"",model:I.kind==="acp"?I.currentModel:void 0});return}b(I.kind),p("workspace")};a.useEffect(()=>{p($)},[_,$,E.id]),a.useEffect(()=>{T&&b(T)},[T,E.id]);const U=[{id:"workspace",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ee,{size:14})," Workspace"]}),count:y.length+C.length+k.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Lt,{size:14})," Providers"]})},{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pr,{size:14})," System"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Er,{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:I=>j.setNicknameInput(I.target.value),onKeyDown:I=>{I.key==="Enter"&&j.handleSaveNickname(),I.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(E.machineNickname||"")},title:"Click to set nickname",children:w}),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:[E.platform," · ",E.arch]}),e.jsxs("span",{children:[E.cpus," cores"]}),(u==null?void 0:u.version)&&e.jsxs("span",{children:["v",u.version]}),E.p2p.available&&e.jsxs("span",{children:["P2P ",E.p2p.state==="connected"?"connected":E.p2p.state]}),E.cdpConnected&&e.jsx("span",{children:"CDP ready"}),E.machineNickname&&e.jsx("span",{className:"text-text-muted opacity-80 shrink-0",children:E.hostname})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:U.map(I=>e.jsxs("button",{onClick:()=>p(I.id),className:`machine-tab shrink-0${f===I.id?" active":""}`,children:[I.label,I.count!==void 0&&e.jsx("span",{className:"tab-count",children:I.count})]},I.id))})]}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:"machine-page-shell",children:e.jsxs("div",{className:"machine-tab-panel",children:[f==="workspace"&&e.jsxs("div",{className:"machine-workspace-panel",children:[e.jsx(Io,{machineEntry:u,providers:m,recentSessions:L,onUpgradeDaemon:async()=>{try{await i(s,"daemon_upgrade",{})}catch{}},onOpenLogs:()=>p("logs"),onOpenRecent:R,onOpenWorkspace:I=>{b(I),p("workspace")},onGoTab:p}),e.jsx(Ro,{machine:E,machineId:s,providers:m,ideSessions:y,cliSessions:C,acpSessions:k,actions:j,getIcon:S,initialCategory:l,initialWorkspaceId:N,initialWorkspacePath:A,isDashboardHidden:d,onToggleDashboardVisibility:x,sendDaemonCommand:i})]}),f==="providers"&&e.jsx(No,{machineId:s,providers:m,sendDaemonCommand:i}),f==="overview"&&e.jsx(vo,{machine:E,ideSessions:y,cliSessions:C,acpSessions:k,actions:j,isDashboardHidden:d,onToggleDashboardVisibility:x}),f==="logs"&&e.jsx(So,{machineId:s,sendDaemonCommand:i})]})})}),j.launchPick&&E&&e.jsx(Co,{machine:E,launchPick:j.launchPick,actions:j}),e.jsx(fn,{toasts:o.toasts||[],onDismiss:I=>o.setToasts(J=>J.filter(q=>q.id!==I)),onClickToast:I=>{I.targetKey}}),e.jsx("style",{children:`
|
|
64
|
+
@keyframes toast-in {
|
|
65
|
+
from { opacity: 0; transform: translateX(40px); }
|
|
66
|
+
to { opacity: 1; transform: translateX(0); }
|
|
67
|
+
}
|
|
68
|
+
`})]})}function Eo(){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=[],d=[],x=[],u=[];Object.values(c.providers||{}).forEach(p=>{const l={name:p.name||"Unknown",status:p.status||"Stable",details:p.details||"Community Provider"};p.category==="ide"?h.push(l):p.category==="cli"?d.push(l):p.category==="extension"?x.push(l):p.category==="acp"&&u.push(l)});const f=(p,l)=>{const b={Stable:1,Beta:2,WIP:3},v=b[p.status]||99,j=b[l.status]||99;return v!==j?v-j:p.name.localeCompare(l.name)};s({ide:h.sort(f),cli:d.sort(f),ext:x.sort(f),acp:u.sort(f)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>r(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Zs,{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(ns,{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(tn,{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,d)=>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})]},d))})]})});return n?e.jsx(Rt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Mt,{}),widthClassName:"max-w-5xl",children:e.jsx(is,{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(Rt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Mt,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(Ie,{title:"Registry overview",description:"Support status is loaded from the shared provider registry used across OSS and cloud surfaces.",children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"IDEs"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ide.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"CLI"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.cli.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"Extensions"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ext.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"ACP"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.acp.length})]})]})}),e.jsx(Ie,{title:"IDE support",icon:e.jsx(Ee,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(Ie,{title:"Standalone CLI agents",icon:e.jsx(sn,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(Ie,{title:"AI extensions",icon:e.jsx(et,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(Ie,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(et,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class _o{constructor(){ye(this,"adapters",new Map);ye(this,"states",new Map);ye(this,"ptyCallbacks",new Set);ye(this,"runtimeListeners",new Map);ye(this,"screenshotCallbacks",new Map);ye(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 De=new _o;function Po(){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 Ks=Po(),Os=3e3,Lo=3e4;let $e=null,Do=0;const Pt=new Map;let Ue=null,dt=null;function $o(t){return t==="connected"?"connected":t}async function It(t,s,n){const r=Ma(t,n||{}),i=$e;if(i&&i.readyState===WebSocket.OPEN){const c=`req_${++Do}_${Date.now()}`;return new Promise((h,d)=>{const x=setTimeout(()=>{Pt.delete(c),d(new Error(`WS command timeout: ${s}`))},3e4);Pt.set(c,{resolve:u=>{clearTimeout(x),h(u)},reject:u=>{clearTimeout(x),d(u)}}),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 Bo{constructor(s){ye(this,"daemonId");ye(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return($e==null?void 0:$e.readyState)===WebSocket.OPEN}get connectionState(){return($e==null?void 0:$e.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return It(this.daemonId,s,n)}async sendInput(s,n){return It(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,Ue&&(clearInterval(Ue),Ue=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await It(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());De.emitScreenshot(this.daemonId,i)}}catch{}};n(),Ue=setInterval(n,2e3)}stopScreenshots(s){Ue&&(clearInterval(Ue),Ue=null)}}let Ae=null;function Ko(t){return(!Ae||Ae.daemonId!==t)&&(Ae=new Bo(t)),Ae}function Oo({children:t}){const s=a.useRef(ps()),n=ps();s.current=n;const{setUserName:r}=ut(),i=a.useRef(r);i.current=r;const[,o]=a.useState("disconnected"),c=a.useCallback((p,l)=>{o(p),dt==null||dt(p,l)},[]),h=a.useRef(null),d=a.useRef(),x=a.useRef(Os),u=a.useRef(!0),f=a.useRef(!1);return a.useEffect(()=>{u.current=!0,f.current=!1;function p(){var v,j;if(!u.current||((v=h.current)==null?void 0:v.readyState)===WebSocket.OPEN||((j=h.current)==null?void 0:j.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${Ks}...`);let b;try{b=new WebSocket(Ks)}catch(m){console.error("[Standalone WS] Failed to create WebSocket:",m),l();return}h.current=b,b.onopen=()=>{if(!u.current){b.close();return}c("connected"),x.current=Os,console.log("[Standalone WS] Connected")},$e=b,b.onmessage=m=>{var g;try{const S=JSON.parse(m.data);if((S.type==="command_result"||S.type==="error")&&S.requestId){const E=Pt.get(S.requestId);E&&(Pt.delete(S.requestId),S.type==="error"?E.reject(new Error(((g=S.data)==null?void 0:g.message)||"Command failed")):E.resolve(S.data));return}if(S.type==="pty_output"){De.emitPtyOutput(S.cliId,S.data);return}if(S.type==="runtime_snapshot"){De.emitRuntimeSnapshot(S.sessionId,typeof S.text=="string"?S.text:"",typeof S.seq=="number"?S.seq:0,!!S.truncated);return}if(S.type==="status"||S.type==="initial_state"){const E=S.data;if(!E)return;const{injectEntries:y,markLoaded:C}=s.current,k=E.id||"standalone",w=Ko(k);De.register(k,w),De.setState(k,"connected"),c("connected",k),De.emitStatus(k,E);const _=Ca(E,{daemonId:k});_.length>0&&y(_),C(),E.userName&&i.current&&i.current(E.userName)}}catch(S){console.error("[Standalone WS] Parse error:",S)}},b.onclose=()=>{u.current&&(Ae==null||Ae.stopScreenshots(),Ae&&De.setState(Ae.daemonId,"disconnected"),c("disconnected"),h.current=null,l())},b.onerror=m=>{f.current||!u.current||console.warn("[Standalone WS] Error, will reconnect:",m)}}function l(){if(!u.current)return;clearTimeout(d.current);const b=x.current;console.log(`[Standalone WS] Reconnecting in ${b}ms...`),d.current=setTimeout(()=>{x.current=Math.min(x.current*1.5,Lo),p()},b)}return p(),()=>{u.current=!1,f.current=!0,clearTimeout(d.current),h.current&&(h.current.onerror=null,h.current.onclose=null,h.current.close(),h.current=null,$e=null),Ae&&(Ae.stopScreenshots(),De.unregister(Ae.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function Wo({children:t}){const[s,n]=a.useState("disconnected"),[r,i]=a.useState(null);a.useEffect(()=>(dt=(c,h)=>{n(c),h&&i(h)},()=>{dt=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",h=$o(s),d={};return r&&(d[r]=h),d.standalone=h,{wsStatus:s,isConnected:c,connectionStates:d}},[s,r]);return e.jsx(kr,{connectionOverrides:o,children:e.jsx(Oo,{children:t})})}const zo=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Xs,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(ts,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Lt,{}),label:"Settings"}];function Fo({children:t}){const s=tt(),n=es(),[r,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),h=u=>{s(u),i(!1)},d=()=>{c(u=>{const f=!u;try{localStorage.setItem("sidebar-collapsed",f?"1":"0")}catch{}return f})},x=u=>`nav-item${n.pathname.startsWith(u)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${o?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:u=>u.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${o?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!o&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:zo.map(u=>e.jsxs("div",{className:x(u.path),id:`nav-${u.id}`,onClick:()=>h(u.path),title:o?u.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:u.icon}),!o&&u.label]},u.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:o?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Mt,{})}),!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(Js,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.7.39"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:d,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 Uo=[{icon:e.jsx(ts,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(ht,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(en,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Ee,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(et,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Mt,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Ho=[{icon:e.jsx(nn,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(Xs,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(Dt,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Ar,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Tr,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Zs,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Vo=[{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 qo(){return e.jsxs(Rt,{icon:e.jsx(Js,{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.39"]}),children:[e.jsx(Ie,{children:e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("div",{className:"text-[11px] font-semibold tracking-[0.18em] uppercase text-emerald-400 mb-2",children:"Self-hosted edition"}),e.jsx("h2",{className:"text-2xl font-semibold tracking-tight text-text-primary mb-2",children:"Keep the same dashboard experience, with the runtime fully on-device."}),e.jsx("p",{className:"text-sm text-text-muted leading-relaxed",children:"Standalone keeps the browser, daemon, screenshots, and control path on your own machine. It is the same core product shape as cloud, just without the remote networking and team layers."})]}),e.jsxs("div",{className:"grid gap-2 min-w-[220px]",children:[e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"Docs ↗"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"GitHub ↗"}),e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex justify-center no-underline",children:"Try Cloud ↗"})]})]})}),e.jsx(Ie,{title:"Included in standalone",description:"The local-first feature set available without the cloud control plane.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Uo.map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4 transition-colors hover:border-border-default",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-accent/10 text-accent-light",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(Ie,{title:"Compatible with",description:"Supported editors and agent surfaces exposed in the standalone dashboard.",children:e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:[{label:"IDEs",items:vn.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:wn.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:jn.map(t=>`${t.icon} ${t.name}`)}].map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4",children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-3 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1.5",children:t.items.map(s=>e.jsx("div",{className:"rounded-md border border-border-subtle bg-bg-card px-2.5 py-1.5 text-[12px] text-text-secondary",children:s},s))})]},t.label))})}),e.jsx(Ie,{title:"Cloud-only extras",description:"Capabilities that need the hosted control plane or team infrastructure.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Ho.map(t=>e.jsxs("div",{className:"rounded-xl border border-violet-500/20 bg-violet-500/[0.04] px-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-violet-500/10 text-violet-400",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(Ie,{title:"Self-hosted vs Cloud",description:"The product split at a glance.",children:e.jsx("div",{className:"overflow-x-auto rounded-xl border border-border-subtle",children:e.jsxs("table",{className:"w-full text-[13px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary",children:[e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[110px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-violet-400 text-[11px] uppercase tracking-wider w-[110px]",children:"Cloud"})]})}),e.jsx("tbody",{children:Vo.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(is,{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(Wr,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Yo(){const{ides:t}=ut(),s=t.find(f=>f.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=We(),{userName:i}=ut(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const h=f=>{const p=f.target.value.trim();s!=null&&s.id&&p!==i&&r(s.id,"set_user_name",{userName:p}).catch(console.error)},[d,x]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),u=f=>{x(f);try{localStorage.setItem("adhdev_sound",f?"1":"0")}catch{}};return e.jsxs(Rt,{icon:e.jsx(Lt,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(Fa,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(Ie,{title:"Daemon",description:"Connection health and local endpoints for the self-hosted runtime.",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-x-4 gap-y-2.5 text-sm",children:[e.jsx("span",{className:"text-text-muted",children:"Version"}),e.jsxs("span",{className:"font-mono text-xs",children:["v","0.7.39"]}),e.jsx("span",{className:"text-text-muted",children:"Status"}),e.jsx("span",{className:s?"text-green-400":"text-yellow-400",children:s?"● Running":"○ Not connected"}),e.jsx("span",{className:"text-text-muted",children:"WebSocket"}),e.jsx("span",{className:"font-mono text-xs",children:"ws://localhost:19222"}),e.jsx("span",{className:"text-text-muted",children:"HTTP"}),e.jsx("span",{className:"font-mono text-xs",children:"http://localhost:19280"})]})}),e.jsx(Ie,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:n.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:n.map(f=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${f.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:f.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:f.type})]},f.type))})}),e.jsx(Ie,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Ga,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(Ie,{title:"Appearance",description:"Match the rest of the dashboard with a single place for mode and theme.",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Mode"}),e.jsx(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:"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(ii,{})]}),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(ci,{})]})]})}),e.jsx(Ie,{title:"Notifications",description:"Browser prompts and local sound cues for agent activity.",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Xa,{}),e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Or,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:d,onChange:u})]})}),e.jsx(Ie,{title:"Profile",description:"How your name appears in local chat threads and dashboard views.",children:e.jsx("div",{className:"flex flex-col gap-3",children:e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-4 bg-bg-glass rounded-xl border border-border-subtle hover:border-border-default transition-colors",children:[e.jsxs("div",{className:"flex flex-col gap-1 pr-4 max-w-[500px]",children:[e.jsxs("span",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(Rr,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:o,onChange:f=>c(f.target.value),onBlur:h,onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()}})]})})})]})}Ya();ri();const Xo=qs({baseUrl:""});function Ws(){const{ides:t}=ut(),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 Go(){const{id:t}=Us();return t?e.jsx(Qe,{to:`/dashboard?activeTab=${encodeURIComponent(t)}`,replace:!0}):e.jsx(Qe,{to:"/dashboard",replace:!0})}function Jo(){return e.jsx(br,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Cr,{client:Xo,children:e.jsx(Wo,{children:e.jsx(Mr,{value:{sendCommand:It,sendData:()=>!1},children:e.jsx(Fo,{children:e.jsxs(gr,{children:[e.jsx(Le,{path:"/dashboard",element:e.jsx(go,{})}),e.jsx(Le,{path:"/ide/:id",element:e.jsx(Go,{})}),e.jsx(Le,{path:"/machine",element:e.jsx(Ws,{})}),e.jsx(Le,{path:"/machines/:id",element:e.jsx(Ao,{})}),e.jsx(Le,{path:"/machines",element:e.jsx(Ws,{})}),e.jsx(Le,{path:"/capabilities",element:e.jsx(Eo,{})}),e.jsx(Le,{path:"/about",element:e.jsx(qo,{})}),e.jsx(Le,{path:"/settings",element:e.jsx(Yo,{})}),e.jsx(Le,{path:"*",element:e.jsx(Qe,{to:"/dashboard",replace:!0})})]})})})})})})}fa({connectionManager:De});yr(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Jo,{})}));
|