@adhdev/daemon-standalone 0.7.16 → 0.7.17
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 +27 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/index-CFr5TK-K.js +68 -0
- package/public/index.html +1 -1
- package/public/assets/index-BWW2S6O1.js +0 -68
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-5UKRXqR3.js","assets/vendor-tc3018Wt.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var un=Object.defineProperty;var xn=(t,s,n)=>s in t?un(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var ue=(t,s,n)=>xn(t,typeof s!="symbol"?s+"":s,n);import{r as o,j as e,M as ms,a as fs,b as hn,c as pn,u as it,t as mn,d as fn,e as gn,R as bn,f as gs,g as bs,h as yn,B as jn,i as vn,k as Ee,N as gt,l as wn}from"./vendor-tc3018Wt.js";import{_ as Nn}from"./terminal-5UKRXqR3.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const i of a)if(i.type==="childList")for(const c of i.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&r(c)}).observe(document,{childList:!0,subtree:!0});function n(a){const i={};return a.integrity&&(i.integrity=a.integrity),a.referrerPolicy&&(i.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?i.credentials="include":a.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(a){if(a.ep)return;a.ep=!0;const i=n(a);fetch(a.href,i)}})();const ys=o.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}),js=o.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function Yt(t){var n,r;let s=0;return"activeChat"in t&&(s+=4),(n=t.agentStreams)!=null&&n.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(r=t.agents)!=null&&r.length&&(s+=1),s}function Et(t,s,n){if(n.type!=="adhdev-daemon")return n;const r={...n},a=s.version??n.version??t.version,i=s.serverVersion??t.serverVersion??n.serverVersion,c=s.versionMismatch===!0||t.versionMismatch===!0;return a&&(r.version=a),i&&(r.serverVersion=i),a&&i&&a===i?(delete r.versionMismatch,delete r.serverVersion,r):((s.versionMismatch===!0||c&&a&&i&&a!==i)&&(r.versionMismatch=!0),r)}function kn(t,s){var c,u,l,x,d,h,g;const n=Date.now();if(s.length===0)return t.map(f=>({...f,_lastUpdate:n}));const r=new Map;for(const f of s)r.set(f.id,f);for(const f of t){const b=r.get(f.id);if(!b){r.set(f.id,{...f,_lastUpdate:n});continue}const k=Yt(f),S=Yt(b);if(k>S){const p=(c=f.chats)!=null&&c.length?f.chats:b.chats,y=Et(b,f,{...b,...f,chats:p,_lastUpdate:n});r.set(f.id,y)}else if(k<S){const p={};if(f.status&&f.status!==b.status&&(p.status=f.status),f.cdpConnected!==void 0&&(p.cdpConnected=f.cdpConnected),(u=f.chats)!=null&&u.length&&!((l=b.chats)!=null&&l.length)&&(p.chats=f.chats),f.machineNickname!==void 0&&f.machineNickname!==b.machineNickname&&(p.machineNickname=f.machineNickname),f.version!==void 0&&(p.version=f.version),f.serverVersion!==void 0&&(p.serverVersion=f.serverVersion),f.versionMismatch===!0&&(p.versionMismatch=!0),Object.keys(p).length>0){const y=Et(b,f,{...b,...p,_lastUpdate:b._lastUpdate});r.set(f.id,y)}}else{const p=f.timestamp||n,y=b._lastUpdate||b.timestamp||0;if(p>=y){const N=(x=f.chats)!=null&&x.length?f.chats:b.chats,T=Et(b,f,{...b,...f,chats:N,_lastUpdate:n});r.set(f.id,T)}else(d=f.chats)!=null&&d.length&&!((h=b.chats)!=null&&h.length)&&r.set(f.id,{...b,chats:f.chats})}}const a=new Set(t.map(f=>f.id)),i=new Set;for(const f of t){const b=f.daemonId||((g=f.id)==null?void 0:g.split(":")[0]);b&&i.add(b)}for(const[f,b]of r){const k=b.daemonId||f.split(":")[0];if(!i.has(k))continue;const S=n-(b._lastUpdate||b.timestamp||0);(b.transport==="pty"&&!a.has(f)&&S>1e4||b.transport==="acp"&&!a.has(f)&&S>1e4||b.transport==="cdp-page"&&!a.has(f)&&S>3e4)&&r.delete(f)}for(const[f,b]of r)n-(b._lastUpdate||b.timestamp||0)>3e5&&b.status!=="online"&&r.delete(f);return Array.from(r.values())}function Sn(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 Cn({children:t,connectionOverrides:s}){const[n,r]=o.useState([]),[a,i]=o.useState({}),[c,u]=o.useState(!1),[l,x]=o.useState([]),[d,h]=o.useState(void 0),g=o.useRef(n);o.useEffect(()=>{g.current=n},[n]);const f=o.useCallback((N,T)=>{r(m=>{let j=!1;const v=m.map(w=>w.id!==N||w.chats===T?w:(j=!0,{...w,chats:T}));return j?v:m})},[]),b=o.useCallback(N=>{r(T=>{const m=T.length===0?N:kn(N,T);return Sn(T,m)?T:m})},[]),k=o.useCallback(()=>u(!0),[]),S=o.useMemo(()=>({injectEntries:b,markLoaded:k,getIdes:()=>g.current}),[b,k]),p=s,y=o.useMemo(()=>({ides:n,updateIdeChats:f,screenshotMap:a,setScreenshotMap:i,initialLoaded:c,toasts:l,setToasts:x,wsStatus:(p==null?void 0:p.wsStatus)??"connected",isConnected:(p==null?void 0:p.isConnected)??!0,connectionStates:(p==null?void 0:p.connectionStates)??{},connectionTransports:(p==null?void 0:p.connectionTransports)??{},showReconnected:(p==null?void 0:p.showReconnected)??!1,retryConnection:p==null?void 0:p.retryConnection,isP2PActive:(p==null?void 0:p.isP2PActive)??!1,p2pStates:(p==null?void 0:p.p2pStates)??{},userRole:p==null?void 0:p.userRole,userName:d,setUserName:h}),[n,f,a,c,l,p==null?void 0:p.wsStatus,p==null?void 0:p.isConnected,p==null?void 0:p.connectionStates,p==null?void 0:p.connectionTransports,p==null?void 0:p.showReconnected,p==null?void 0:p.retryConnection,p==null?void 0:p.isP2PActive,p==null?void 0:p.p2pStates,p==null?void 0:p.userRole,d]);return e.jsx(js.Provider,{value:S,children:e.jsx(ys.Provider,{value:y,children:t})})}function ot(){return o.useContext(ys)}function Xt(){return o.useContext(js)}function vs(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;function a(u){return u.startsWith("http")?u:`${s}${u.startsWith("/")?"":"/"}${u}`}function i(u){const l=n==null?void 0:n(),x=a(u),d=u.startsWith("http")?new URL(x):new URL(x,typeof window<"u"?window.location.origin:"http://localhost");return l&&d.searchParams.set("token",l),!u.startsWith("http")&&!s?`${d.pathname}${d.search}${d.hash}`:d.toString()}async function c(u,l={}){const x={"Content-Type":"application/json",...l.headers||{}},d=n==null?void 0:n();d&&(x.Authorization=`Bearer ${d}`);const h=a(u),g=await fetch(h,{...l,headers:x});if(g.status===401)throw r==null||r(),new Error("Unauthorized");if(!g.ok){const f=await g.json().catch(()=>({error:g.statusText}));throw new Error(f.error||`API Error: ${g.status}`)}return g.json()}return{getDaemons:()=>c("/api/v1/daemons"),getDaemonStatus:u=>c(`/api/v1/daemons/${u}/status`),sendCommand:(u,l,x={})=>c(`/api/v1/daemons/${u}/command`,{method:"POST",body:JSON.stringify({type:l,payload:x})}),execTerminal:(u,l,x)=>c(`/api/v1/daemons/${u}/terminal`,{method:"POST",body:JSON.stringify({command:l,name:x})}),sendAgentMessage:(u,l,x)=>c(`/api/v1/shortcuts/${u}/chat`,{method:"POST",body:JSON.stringify({agentType:l,message:x})}),getAgentStatus:u=>c(`/api/v1/shortcuts/${u}/status`),approveAgent:(u,l,x)=>c(`/api/v1/shortcuts/${u}/approve`,{method:"POST",body:JSON.stringify({agentType:l,action:x?"approve":"reject"})}),getMuxState:u=>c(`/api/v1/mux/${encodeURIComponent(u)}/state`),getMuxSocketInfo:u=>c(`/api/v1/mux/${encodeURIComponent(u)}/socket-info`),controlMux:(u,l,x={})=>c(`/api/v1/mux/${encodeURIComponent(u)}/control`,{method:"POST",body:JSON.stringify({type:l,payload:x})}),getMuxEventsUrl:u=>i(`/api/v1/mux/${encodeURIComponent(u)}/events`),getRuntimeSnapshot:u=>c(`/api/v1/runtime/${encodeURIComponent(u)}/snapshot`),getRuntimeEventsUrl:u=>i(`/api/v1/runtime/${encodeURIComponent(u)}/events`),request:c}}const In=vs({baseUrl:"http://localhost:3847"}),Mn=o.createContext(In);function Tn({client:t,children:s}){return e.jsx(Mn.Provider,{value:t,children:s})}const En={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},ws=o.createContext(En);function An({value:t,children:s}){return e.jsx(ws.Provider,{value:t,children:s})}function Pe(){return o.useContext(ws)}const ce={size:18};function Ns({size:t=ce.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 ks({size:t=ce.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 Rn({size:t=ce.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function _n({size:t=ce.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 Ln({size:t=ce.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 wt({size:t=ce.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 $n({size:t=ce.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 Ht({size:t=ce.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 Ss({size:t=ce.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 Cs({size:t=ce.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 qe({size:t=ce.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function Le({size:t=ce.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 Is({size:t=ce.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 Pn({size:t=ce.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 Pt({size:t=ce.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 Ms({size:t=ce.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 Ft({size:t=ce.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 Ye({size:t=ce.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 Ts({size:t=ce.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 Es({size:t=ce.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 Dn({size:t=ce.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 Ut({size:t=ce.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 As({size:t=ce.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 Rs({size:t=ce.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 Bn({size:t=ce.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 Wn({size:t=ce.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 _s({size:t=ce.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 On({size:t=ce.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 Kn({size:t=ce.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 zn({size:t=ce.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 Hn({size:t=ce.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 Fn(t){const n=t.split(`
|
|
3
|
+
`).map(u=>{if(!u.includes("\r"))return u;const l=u.split("\r").map(h=>h.trim()).filter(Boolean);if(l.length===0)return"";const x=l.filter(h=>h.startsWith("⏺"));if(x.length>0)return x[x.length-1];const d=l.filter(h=>!(/^[❯›>]\s*$/.test(h)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(h)&&h.length<40||/^[╭╰│├╮╯─═]+$/.test(h)));return d.length>0?d[d.length-1]:l[l.length-1]}).join(`
|
|
4
|
+
`).split(`
|
|
5
|
+
`),r={},a=[];let i=!1;for(const u of n){const l=u.trim();if(l===""){i=!1,a.push("");continue}if(/^❯\s*$/.test(l)||/^>\s*$/.test(l)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(l)||/^◐\s/.test(l)||/\/effort/.test(l)||/^⎿\s+(Tip|Note|Hint):/.test(l)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(l)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(l)||/Brewing[…\.]{0,3}\s*\d*$/i.test(l)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(l)||/^Auto-updating/i.test(l))continue;if(/^[⏺●·⏵]/.test(u)){const d=u.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(d)r[d[1]]=(r[d[1]]||0)+1;else{const h=u.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);h&&(r[h]=(r[h]||0)+1)}i=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(u)||/^[╭╰│├╮╯─]+/.test(l)||/^\s+[⊙✓✗○◎▸►✦]/.test(u)||i&&/^\s{2,}/.test(u))continue;i=!1;const x=u.replace(/^❯\s+/,"");a.push(x)}const c=a.join(`
|
|
6
|
+
`).replace(/\n{3,}/g,`
|
|
7
|
+
|
|
8
|
+
`).trim();return{toolCounts:r,textContent:c,hasTools:Object.keys(r).length>0}}function Dt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function Un(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function Ve(t,s){const n=t,r=typeof n.content=="string"?n.content:Array.isArray(n.content)?n.content.map(i=>(i==null?void 0:i.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 Gt=700,Vn=o.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(ms,{remarkPlugins:[fs],children:s.text}),e.jsx("span",{className:"action-time",children:Dt(s.timestamp)})]})},(t,s)=>t.log===s.log),qn=o.memo(function({message:s,receivedAt:n,agentName:r,userName:a,isCliMode:i,isExpanded:c,isTextExpanded:u,onToggleExpanded:l,onToggleTextExpanded:x}){var T;const d=(s.role||"").toLowerCase(),h=d==="user"||d==="human",g=s.kind||(d==="tool"?"tool":"standard"),f=typeof s.content=="string"?s.content:(s.content||[]).map(m=>m.text||"").join(`
|
|
10
|
+
`);if(g==="thought"){const m=((T=s.meta)==null?void 0:T.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(Bn,{size:13}),e.jsx("span",{children:m})]}),e.jsx("div",{className:"chat-msg-body",children:f})]})}if(g==="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:f.split(`
|
|
11
|
+
`)[0].slice(0,80)})]});if(g==="terminal"){const m=s.meta||{},j=m.isRunning?"⏳":"✅",v=m.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:j}),e.jsx("span",{children:v})]}),e.jsx("pre",{className:"chat-msg-body",children:f})]})}if(g==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:f.slice(0,100)});const b=!h&&i?Fn(f):null,k=b?b.textContent:f,S=b?Object.entries(b.toolCounts):[],p=i&&!h&&!c&&k.length>Gt,y=c?f:p&&!u?k.slice(0,Gt):k,N=Un(y);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${h?"self-end":"self-start"}`,children:[S.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[S.map(([m,j])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",m,j>1?` ×${j}`:""]},m)),(b==null?void 0:b.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:c?"Collapse":"Original"}),!k&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Dt(n)})]}),(k||h)&&e.jsxs("div",{className:`chat-bubble ${h?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${k?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:h?a||"You":r}),n!=null&&e.jsx("span",{className:"chat-time",children:Dt(n)})]}),k&&e.jsx("div",{className:"chat-markdown",children:N?e.jsx(ms,{remarkPlugins:[fs,hn,pn],children:y}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:y})}),p&&e.jsx("button",{onClick:x,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:u?"Collapse ↑":`Show more (${Math.round(k.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),Yn=o.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:a,isCliMode:i=!1,isWorking:c=!1,contextKey:u="",receivedAtMap:l={},emptyState:x,onLoadMore:d,isLoadingMore:h,hasMoreHistory:g,hiddenLiveCount:f=0,loadError:b},k){var se;const S=o.useRef(null),p=o.useRef(null),y=o.useRef(0),N=o.useRef(""),T=o.useRef(!1),m=o.useRef(null),[j,v]=o.useState(new Set),[w,R]=o.useState(new Set),A=o.useRef(!1),O=()=>{const X=S.current;return X?X.scrollHeight-X.scrollTop-X.clientHeight<200:!0},_=o.useCallback((X="auto")=>{const te=S.current;te&&te.scrollTo({top:te.scrollHeight,behavior:X})},[]),I=o.useCallback((X="auto")=>{m.current!=null&&cancelAnimationFrame(m.current),m.current=requestAnimationFrame(()=>{m.current=null,_(X)})},[_]),P=s.length>0?`${s.length}:${(((se=s[s.length-1])==null?void 0:se.content)||"").length}`:"0:0";o.useEffect(()=>{const X=!T.current,te=N.current!==u;if(N.current=u,X||te){T.current=!0,A.current=!1,I("auto"),y.current=s.length;return}s.length>y.current?A.current||I("auto"):O()&&!A.current&&I("auto"),y.current=s.length},[P,u,c,s.length,I]),o.useEffect(()=>()=>{m.current!=null&&cancelAnimationFrame(m.current)},[]),o.useImperativeHandle(k,()=>({scrollToBottom:(X="smooth")=>{_(X)}}),[_]),o.useEffect(()=>{const X=S.current;if(!X)return;let te;const ee=()=>{clearTimeout(te),te=setTimeout(()=>{A.current=!O()},50)};return X.addEventListener("scroll",ee,{passive:!0}),()=>{X.removeEventListener("scroll",ee),clearTimeout(te)}},[]);const K=o.useRef(0),C=o.useRef(!1);o.useEffect(()=>{const X=S.current;if(!X||!C.current||K.current===0)return;const te=X.scrollHeight-K.current;te>0&&(X.scrollTop=te),K.current=0,C.current=!1},[s.length]);const F=()=>{const X=S.current;X&&(K.current=X.scrollHeight),C.current=!0,d==null||d()},Q=o.useMemo(()=>{const X=s.map((W,$)=>({type:"message",data:W,index:$,ts:W.receivedAt||l[Ve(W,$)]||0}));if(!n||n.length===0)return X;const te=[...n].sort((W,$)=>W.timestamp-$.timestamp).map((W,$)=>({type:"action",data:W,index:$,ts:W.timestamp})),ee=[];let oe=0;for(const W of X){for(;oe<te.length&&W.ts>0&&te[oe].ts<W.ts;)ee.push(te[oe++]);ee.push(W)}for(;oe<te.length;)ee.push(te[oe++]);return ee},[s,n,l]),J=f>0||!!g,G=f>0?`↑ Show ${Math.min(f,80)} earlier messages${f>80?` (${f} hidden)`:""}`:b?`↻ ${b}`:"↑ Load older messages";return e.jsxs("div",{ref:S,"data-chat-scroll":!0,className:"chat-container",children:[h&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),J&&!h&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:F,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${b&&f===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:G})}),Q.length===0&&!J&&(x||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),Q.map(X=>{if(X.type==="action"){const D=X.data;return e.jsx(Vn,{log:D},`action-${X.index}`)}const te=X.data,ee=X.index,oe=Ve(te,ee),W=te.receivedAt||l[oe],$=`${u}-${oe}`,E=j.has($),L=w.has($);return e.jsx(qn,{message:te,receivedAt:W,agentName:r,userName:a,isCliMode:i,isExpanded:E,isTextExpanded:L,onToggleExpanded:()=>v(D=>{const U=new Set(D);return E?U.delete($):U.add($),U}),onToggleTextExpanded:()=>R(D=>{const U=new Set(D);return L?U.delete($):U.add($),U})},`msg-${oe}`)}),c&&e.jsx("div",{className:"self-start chat-typing-wrapper",children:e.jsxs("div",{className:"typing-indicator",children:[e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("span",{className:"text-[11px] text-text-muted ml-1",children:"Agent generating..."})]})}),e.jsx("div",{className:"min-h-10",ref:p})]})}),Xn=o.memo(Yn,(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),Ls=o.forwardRef(({onInput:t,onResize:s,fontSize:n=13,readOnly:r=!1},a)=>{const i=o.useRef(null),[c,u]=o.useState(null),l=o.useRef([]),x=o.useRef(!1),d=o.useRef(!1),h=o.useRef(!1),g=()=>{const f=i.current;if(f){x.current&&(f.clear(),x.current=!1);for(const b of l.current)f.write(b);l.current=[],d.current&&(f.fit(),d.current=!1),h.current&&(f.bumpResize(),h.current=!1)}};return o.useImperativeHandle(a,()=>({write:f=>{i.current?i.current.write(f):l.current.push(f)},clear:()=>{i.current?i.current.clear():(l.current=[],x.current=!0)},fit:()=>{i.current?i.current.fit():d.current=!0},bumpResize:()=>{i.current?i.current.bumpResize():h.current=!0}}),[]),o.useEffect(()=>{if(!c)return;const f=requestAnimationFrame(()=>{var b;g(),(b=i.current)==null||b.fit()});return()=>cancelAnimationFrame(f)},[c]),o.useEffect(()=>{let f=!1;return Nn(()=>import("./terminal-5UKRXqR3.js").then(b=>b.i),__vite__mapDeps([0,1])).then(b=>{f||u(()=>b.GhosttyTerminalView)}).catch(b=>{console.error("[CliTerminal] failed to load terminal renderer",b)}),()=>{f=!0}},[]),c?e.jsx(c,{ref:i,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"}})});Ls.displayName="CliTerminal";function ut({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 Jt({value:t,max:s,label:n,color:r="#8b5cf6",detail:a,compact:i=!1}){const c=s>0?Math.min(Math.round(t/s*100),100):0,u=c>85?"#ef4444":c>60?"#f59e0b":r;return i?e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-0.5",children:[e.jsx("span",{className:"text-[9px] text-text-muted uppercase tracking-wide font-semibold",children:n}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-500",style:{width:`${c}%`,background:u}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:n}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-[600ms]",style:{width:`${c}%`,background:`linear-gradient(90deg, ${u}, ${u}cc)`}})}),a&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:a})]})}function Gn({cursorPos:t,viewportRef:s,imgRef:n}){var y;if(!t||!n.current)return null;const r=n.current,a=r.getBoundingClientRect(),i=(y=s.current)==null?void 0:y.getBoundingClientRect();if(!i)return null;const c=r.naturalWidth||a.width,u=r.naturalHeight||a.height,l=c/u,x=a.width/a.height;let d,h,g,f;l>x?(d=a.width,h=a.width/l,g=0,f=(a.height-h)/2):(h=a.height,d=a.height*l,g=(a.width-d)/2,f=0);const b=a.left-i.left+g+d*t.nx,k=a.top-i.top+f+h*t.ny,S=Math.max(8,Math.min(i.width-8,b)),p=Math.max(8,Math.min(i.height-8,k));return e.jsxs("div",{style:{position:"absolute",left:S-8,top:p-8,width:16,height:16,pointerEvents:"none",zIndex:100},children:[e.jsx("div",{style:{position:"absolute",left:7,top:0,width:2,height:16,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:0,top:7,width:16,height:2,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:5,top:5,width:6,height:6,borderRadius:"50%",background:"#3b82f6",boxShadow:"0 0 8px rgba(59,130,246,0.6)"}})]})}function Jn({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:a,setIsMenuOpen:i,imeText:c,setImeText:u,handleImeSubmit:l,isConnActive:x,zoom:d,isMobile:h,mobileFillZoom:g,onZoomOut:f,onZoomReset:b,onZoomIn:k,transportType:S,screenshotUsage:p,lastActionStatus:y}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:N=>N.stopPropagation(),className:"absolute bottom-0 left-0 right-0 z-20 flex items-center justify-center gap-1.5 px-3 py-2 bg-black/75 backdrop-blur-xl border-t border-white/[0.08] touch-none",children:[e.jsxs("div",{onClick:s,className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${t==="mouse"?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:[e.jsx("span",{className:"text-sm",children:t==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${t==="mouse"?"text-blue-400":"text-slate-400"}`,children:t==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{r(N=>!N),i(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${n?"bg-emerald-500/25 border border-emerald-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⌨️"})}),n&&e.jsx("div",{className:"absolute bottom-10 left-1/2 -translate-x-1/2 w-[220px] bg-neutral-950/[0.98] backdrop-blur-[30px] rounded-xl border border-white/20 p-[10px_12px] shadow-[0_10px_30px_rgba(0,0,0,0.8)] flex flex-col gap-2 z-20",style:{animation:"slideUp 0.15s ease-out"},children:e.jsx("input",{type:"text",placeholder:"Type & Enter...",value:c,autoFocus:!0,onTouchStart:N=>N.stopPropagation(),onChange:N=>u(N.target.value),onKeyDown:N=>{l(N)},className:"w-full bg-black/60 border border-white/15 rounded-lg px-2.5 py-2 text-white text-[13px] outline-none"})})]}),e.jsx("div",{className:"relative",children:e.jsx("div",{onClick:()=>{i(N=>!N),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${a?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⚙️"})})}),e.jsx("div",{className:"w-px h-[18px] bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:x?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:x?"#22c55e":"#eab308",boxShadow:x?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:x?"#22c55e":"#eab308"},children:x?"Connected":"WS"})]}),d>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(d*100),"%"]}),S==="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"}),S==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#f59e0b",background:"rgba(245,158,11,0.12)"},title:"TURN relay in use",children:"Relay"}),p&&p.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:p.budgetExhausted?"#ef4444":"#c4b5fd",background:p.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:p.budgetExhausted?"TURN blocked":`TURN ${p.dailyUsedMinutes}/${p.dailyBudgetMinutes}m`}),y&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:y})]})]}),a&&e.jsxs("div",{onTouchStart:N=>N.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",d<=(h?g:1)+.01?h?"FILL":"FIT":`${Math.round(d*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:N=>{N.stopPropagation(),f()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),e.jsx("button",{onClick:N=>{N.stopPropagation(),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:h?"FILL":"FIT"}),e.jsx("button",{onClick:N=>{N.stopPropagation(),k()},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 Zn({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] text-amber-300/80",children:"TURN relay active"})]})}function Qn(){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 Zt(t){return t==null||typeof t=="number"||typeof t=="boolean"?t:typeof t=="string"?t.length>64?`${t.slice(0,61)}...`:t:Array.isArray(t)?`Array(${t.length})`:typeof t=="object"?"Object":typeof t}function ct(t,s){const n=o.useRef(null),r=o.useRef(0);o.useEffect(()=>{if(!Qn())return;r.current+=1;const a=n.current;if(!a){console.debug(`[render-trace] ${t}#${r.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([c,u])=>[c,Zt(u)]))}),n.current=s;return}const i=Object.keys({...a,...s}).filter(c=>!Object.is(a[c],s[c]));i.length>0&&console.debug(`[render-trace] ${t}#${r.current}`,{changed:i,snapshot:Object.fromEntries(i.map(c=>[c,Zt(s[c])]))}),n.current=s})}function er({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:a,minZoom:i,zoomRef:c,panXRef:u,panYRef:l,setPanX:x,setPanY:d,setZoom:h,lastWheelTimeRef:g,onAction:f,setLastActionStatus:b,spawnRippleFromNormalized:k,clampPan:S,isMobile:p,mobileFillZoom:y}){const[N,T]=o.useState(null),m=o.useRef(null),j=o.useRef(null),v=o.useRef(null),w=o.useRef(!1),R=o.useRef(null),A=o.useRef(0),O=o.useRef(null),_=o.useRef(1),I=o.useRef({x:0,y:0}),P=o.useRef(!1),K=o.useRef(r),C=o.useRef(f),F=()=>{if(m.current)return;const G={nx:.5,ny:.5};m.current=G,T(G)};return o.useEffect(()=>{K.current=r,r==="mouse"&&F()},[r]),o.useEffect(()=>{C.current=f},[f]),o.useEffect(()=>{const G=t.current;if(!G)return;const se=$=>{if(!n.current)return null;const E=n.current.getBoundingClientRect();return!E.width||!E.height?null:{nx:Math.max(0,Math.min(1,($.clientX-E.left)/E.width)),ny:Math.max(0,Math.min(1,($.clientY-E.top)/E.height))}},X=($,E)=>{if(!n.current)return{dnx:0,dny:0};const L=n.current,D=L.getBoundingClientRect(),U=L.naturalWidth||D.width,V=L.naturalHeight||D.height,re=U/V,le=D.width/D.height;let ie,de;return re>le?(ie=D.width,de=D.width/re):(de=D.height,ie=D.height*re),{dnx:$/ie,dny:E/de}},te=($,E,L)=>{if(L<=1.05)return;const D=-($-.5)*100,U=-(E-.5)*100,V=S(D,U,L);(Math.abs(V.x-u.current)>.1||Math.abs(V.y-l.current)>.1)&&(x(V.x),d(V.y),u.current=V.x,l.current=V.y)},ee=$=>{const E=s.current;if(E&&$.target instanceof Node&&E.contains($.target))$.preventDefault();else return;if($.touches.length===1){const L=$.touches[0];j.current={x:L.clientX,y:L.clientY,time:Date.now()},v.current={x:L.clientX,y:L.clientY},P.current||(w.current=!1),R.current=setTimeout(()=>{if(!w.current&&!P.current)if(w.current=!0,K.current==="mouse"){const D=m.current||{nx:.5,ny:.5};b("Right Click"),k(D.nx,D.ny,"right"),C.current("input_click",{...D,button:"right"}).catch(()=>{})}else{const D=se(L);D&&(b("Right Click"),k(D.nx,D.ny,"right"),C.current("input_click",{...D,button:"right"}).catch(()=>{}))}},500);return}if($.touches.length===2){R.current&&clearTimeout(R.current),w.current=!0,P.current=!0;const L=$.touches[1].clientX-$.touches[0].clientX,D=$.touches[1].clientY-$.touches[0].clientY;O.current=Math.sqrt(L*L+D*D),_.current=c.current,I.current={x:($.touches[0].clientX+$.touches[1].clientX)/2,y:($.touches[0].clientY+$.touches[1].clientY)/2}}},oe=$=>{const E=s.current;if(E&&$.target instanceof Node&&E.contains($.target)&&$.preventDefault(),$.touches.length===1&&v.current){const L=$.touches[0],D=L.clientX-v.current.x,U=L.clientY-v.current.y;if(!w.current&&j.current){const V=L.clientX-j.current.x,re=L.clientY-j.current.y;Math.sqrt(V*V+re*re)>8&&(w.current=!0,R.current&&clearTimeout(R.current))}if(w.current)if(K.current==="mouse"){const V=X(D,U),re=m.current||{nx:.5,ny:.5},le=Math.max(0,Math.min(1,re.nx+V.dnx)),ie=Math.max(0,Math.min(1,re.ny+V.dny));m.current={nx:le,ny:ie},T({nx:le,ny:ie}),b(`Cursor: ${Math.round(le*100)}%, ${Math.round(ie*100)}%`),te(le,ie,c.current);const de=Date.now();de-g.current>=30&&(g.current=de,C.current("input_mouseMoved",{nx:le,ny:ie}).catch(()=>{}))}else if(c.current>1){const V=s.current;if(V){const re=V.clientWidth,le=V.clientHeight,ie=u.current+D/re*100,de=l.current+U/le*100,B=S(ie,de,c.current);x(B.x),d(B.y),u.current=B.x,l.current=B.y}}else{const V=se(L);if(V){const re=Date.now();re-g.current>=40&&(g.current=re,b("Scroll"),C.current("input_wheel",{nx:V.nx,ny:V.ny,deltaX:Math.round(-D*2.5),deltaY:Math.round(-U*2.5)}).catch(()=>{}))}}v.current={x:L.clientX,y:L.clientY};return}if($.touches.length===2&&O.current!==null){const L=$.touches[1].clientX-$.touches[0].clientX,D=$.touches[1].clientY-$.touches[0].clientY,V=Math.sqrt(L*L+D*D)/O.current,re=($.touches[0].clientX+$.touches[1].clientX)/2,le=($.touches[0].clientY+$.touches[1].clientY)/2,ie=re-I.current.x,de=le-I.current.y,B=Math.abs(V-1)>.03;if(K.current==="mouse"){if(B){const Y=Math.max(i,Math.min(5,_.current*V));h(Y),c.current=Y}else if(Math.abs(ie)>2||Math.abs(de)>2){const Y=m.current||{nx:.5,ny:.5},H=Date.now();H-g.current>=30&&(g.current=H,b("Scroll"),C.current("input_wheel",{nx:Y.nx,ny:Y.ny,deltaX:Math.round(-ie*3),deltaY:Math.round(-de*3)}).catch(()=>{}))}}else{const Y=Math.max(i,Math.min(5,_.current*V));h(Y),c.current=Y;const H=s.current;if(H&&Y>1){const M=H.clientWidth,q=H.clientHeight,z=u.current+ie/M*100,ne=l.current+de/q*100,Z=S(z,ne,Y);x(Z.x),d(Z.y),u.current=Z.x,l.current=Z.y}}I.current={x:re,y:le}}},W=$=>{var E;if(R.current&&clearTimeout(R.current),O.current=null,$.touches.length===1&&P.current){const L=$.touches[0];j.current={x:L.clientX,y:L.clientY,time:Date.now()},v.current={x:L.clientX,y:L.clientY},w.current=!0;return}if($.touches.length===0){if(P.current){P.current=!1,w.current=!1;return}if($.changedTouches.length===1&&!w.current){const L=$.changedTouches[0],D=Date.now(),U=D-(((E=j.current)==null?void 0:E.time)||0);if(U<60||U>400){w.current=!1;return}if(j.current){const V=L.clientX-j.current.x,re=L.clientY-j.current.y;if(Math.sqrt(V*V+re*re)>12){w.current=!1;return}}if(K.current==="mouse"){const V=m.current||se(L);V&&(b(`Click: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),k(V.nx,V.ny,"left"),C.current("input_click",{...V}).catch(()=>{}))}else{const V=se(L);if(!V)return;D-A.current<300?(b("Double tap"),k(V.nx,V.ny,"double"),C.current("input_click",{...V,clickCount:2}).catch(()=>{}),A.current=0):(b(`Tap: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),k(V.nx,V.ny,"left"),C.current("input_click",{...V}).catch(()=>{}),A.current=D)}}w.current=!1}};return G.addEventListener("touchstart",ee,{passive:!1}),G.addEventListener("touchmove",oe,{passive:!1}),G.addEventListener("touchend",W,{passive:!1}),()=>{G.removeEventListener("touchstart",ee),G.removeEventListener("touchmove",oe),G.removeEventListener("touchend",W),R.current&&clearTimeout(R.current)}},[t,s,n,i,c,u,l,x,d,h,g,b,k,S]),{cursorPos:N,cursorPosRef:m,handleToggleInputMode:()=>{a(G=>{const se=G==="touch"?"mouse":"touch";return se==="mouse"&&F(),se})},handleZoomReset:()=>{const G=p?y:1;h(G),c.current=G,x(0),d(0),u.current=0,l.current=0}}}function tr({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:a,transportType:i}){const c=o.useRef(null),u=o.useRef(null),l=o.useRef(null),[x,d]=o.useState(null),[h,g]=o.useState(""),[,f]=o.useState(!1),[b,k]=o.useState([]),S=o.useRef(0),[p,y]=o.useState(!1),[N,T]=o.useState(!1),m=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[j,v]=o.useState(m?"mouse":"touch"),[w,R]=o.useState(1),A=o.useRef(!1),[O,_]=o.useState(1),[I,P]=o.useState(0),[K,C]=o.useState(0);ct("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:j,zoom:O,panX:I,panY:K,isMenuOpen:p,isImeOpen:N});const F=o.useRef(0),Q=o.useRef(O),J=o.useRef(I),G=o.useRef(K);o.useEffect(()=>{Q.current=O},[O]),o.useEffect(()=>{J.current=I},[I]),o.useEffect(()=>{G.current=K},[K]),o.useEffect(()=>{var B;(B=c.current)==null||B.focus()},[]);const se=n==="connected",X=r,te=se?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",ee=se?"The remote stream is warming up":"Waiting for the remote stream to catch up";o.useEffect(()=>{if(!m||A.current||!X)return;const B=l.current,Y=u.current;if(!B||!Y)return;const H=()=>{const M=Y.clientWidth,q=Y.clientHeight,z=B.naturalWidth,ne=B.naturalHeight;if(!z||!ne||!M||!q)return;const Z=Math.min(M/z,q/ne),ae=Math.max(M/z,q/ne)/Z;ae>1.01&&(R(ae),_(ae),Q.current=ae),A.current=!0};B.complete&&B.naturalWidth?H():B.addEventListener("load",H,{once:!0})},[X,m]);const oe=.5;o.useEffect(()=>{O<=oe&&(P(0),C(0))},[O,oe]);const W=(B,Y,H)=>{if(H<=oe)return{x:0,y:0};const M=(H-1)/(2*H)*100,q=(H-1)/(2*H)*100;return{x:Math.max(-M,Math.min(M,B)),y:Math.max(-q,Math.min(q,Y))}},$=(B,Y)=>{if(!l.current)return null;const H=l.current.getBoundingClientRect();return!H.width||!H.height?null:{nx:Math.max(0,Math.min(1,(B-H.left)/H.width)),ny:Math.max(0,Math.min(1,(Y-H.top)/H.height))}},E=(B,Y,H)=>{const M=u.current;if(!M)return;const q=M.getBoundingClientRect(),z=++S.current;k(ne=>[...ne,{id:z,x:B-q.left,y:Y-q.top,type:H}]),setTimeout(()=>k(ne=>ne.filter(Z=>Z.id!==z)),600)},L=(B,Y,H)=>{const M=l.current,q=u.current;if(!M||!q)return;const z=M.getBoundingClientRect(),ne=q.getBoundingClientRect(),Z=M.naturalWidth||z.width,be=M.naturalHeight||z.height,ae=Z/be,Me=z.width/z.height;let Se,Ce,Ge,He;ae>Me?(Se=z.width,Ce=z.width/ae,Ge=0,He=(z.height-Ce)/2):(Ce=z.height,Se=z.height*ae,Ge=(z.width-Se)/2,He=0);const Fe=z.left-ne.left+Ge+Se*B,Mt=z.top-ne.top+He+Ce*Y,lt=++S.current;k(Je=>[...Je,{id:lt,x:Fe,y:Mt,type:H}]),setTimeout(()=>k(Je=>Je.filter(Tt=>Tt.id!==lt)),600)},D=async B=>{var H;const Y=$(B.clientX,B.clientY);if(Y){d(`Click: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),E(B.clientX,B.clientY,"left"),(H=c.current)==null||H.focus();try{const M=await t("input_click",{nx:Y.nx,ny:Y.ny});M!=null&&M.success||s(`❌ Click failed: ${M==null?void 0:M.error}`)}catch(M){s(`❌ Click error: ${M.message||M}`)}}},U=async(B,Y,H,M=0)=>{try{await t("input_key",{type:H?"char":"keyDown",key:B,code:Y,text:H?B:void 0,unmodifiedText:H?B:void 0,modifiers:M})}catch(q){s(`❌ Key error: ${q.message||q}`)}},V=async B=>{if(B.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(B.key)&&B.preventDefault();let H=0;B.altKey&&(H|=1),B.ctrlKey&&(H|=2),B.metaKey&&(H|=4),B.shiftKey&&(H|=8),d(`Key: ${B.key}`),await U(B.key,B.code,B.key.length===1,H)},re=async B=>{if(B.key==="Enter"){if(B.nativeEvent.isComposing)return;if(h){const Y=h;g(""),d(`IME Sent: ${Y}`);try{const H=await t("input_type",{text:Y});H!=null&&H.success||s(`❌ IME error: ${H==null?void 0:H.error}`)}catch(H){s(`❌ IME error: ${H.message}`)}}else d("Key: Enter"),await U("Enter","Enter",!1)}};o.useEffect(()=>{const B=c.current;if(!B)return;const Y=H=>{var M;if((M=l.current)!=null&&M.contains(H.target)){H.preventDefault();const q=Date.now();if(q-F.current<40)return;F.current=q;const z=$(H.clientX,H.clientY);if(!z)return;d(`Scroll: ${Math.round(H.deltaY)}`),t("input_wheel",{nx:z.nx,ny:z.ny,deltaX:Math.round(H.deltaX),deltaY:Math.round(H.deltaY)}).catch(()=>{})}};return B.addEventListener("wheel",Y,{passive:!1}),()=>B.removeEventListener("wheel",Y)},[t]);const{cursorPos:le,handleToggleInputMode:ie,handleZoomReset:de}=er({containerRef:c,viewportRef:u,imgRef:l,inputMode:j,setInputMode:v,minZoom:oe,zoomRef:Q,panXRef:J,panYRef:G,setPanX:P,setPanY:C,setZoom:_,lastWheelTimeRef:F,onAction:t,setLastActionStatus:d,spawnRippleFromNormalized:L,clampPan:W,isMobile:m,mobileFillZoom:w});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:V,onContextMenu:B=>B.preventDefault(),onFocus:()=>f(!0),onBlur:()=>f(!1),tabIndex:0,children:[e.jsxs("div",{ref:u,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[X?e.jsx("img",{ref:l,src:X,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${O}) translate(${I}%, ${K}%)`,transformOrigin:"center center",cursor:j==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:D,onContextMenu:B=>B.preventDefault(),onDragStart:B=>B.preventDefault()}):e.jsx(Zn,{waitingLabel:te,waitingHint:ee,transportType:i}),j==="mouse"&&X&&e.jsx(Gn,{cursorPos:le,viewportRef:u,imgRef:l}),b.map(B=>{const H={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[B.type];return e.jsxs("div",{style:{position:"absolute",left:B.x,top:B.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${H}, 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(${H}, 0.9)`,boxShadow:`0 0 12px rgba(${H}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},B.id)})]}),e.jsx(Jn,{inputMode:j,onToggleInputMode:ie,isImeOpen:N,setIsImeOpen:T,isMenuOpen:p,setIsMenuOpen:y,imeText:h,setImeText:g,handleImeSubmit:re,isConnActive:se,zoom:O,isMobile:m,mobileFillZoom:w,onZoomOut:()=>_(B=>Math.max(.5,B-.25)),onZoomReset:de,onZoomIn:()=>_(B=>Math.min(5,B+.25)),transportType:i,screenshotUsage:a,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 sr({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:r=!1,connectionState:a,onDismiss:i,onClickAt:c,onKeyDown:u,badge:l,emptyMessage:x,aspectRatio:d,className:h,style:g}){const f=o.useRef(null),b=o.useCallback(k=>{if(!r||!c||!f.current)return;const S=f.current,p=S.getBoundingClientRect(),y=(k.clientX-p.left)/p.width*S.naturalWidth,N=(k.clientY-p.top)/p.height*S.naturalHeight;c(y,N,S.naturalWidth,S.naturalHeight)},[r,c]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${h||""}`,style:{aspectRatio:d||"16/9",...g},children:[e.jsx("img",{ref:f,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),i&&e.jsx("button",{onClick:i,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":""} ${h||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?u:void 0,style:g,children:[e.jsx("img",{ref:f,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"}:{}}}),l&&e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 bg-black/70 text-white px-3.5 py-1.5 rounded-[20px] text-xs font-semibold backdrop-blur-sm",children:l})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${h||""}`,style:g,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..."}),a&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",a]}),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 $s({activeConv:t,onModalButton:s}){const[n,r]=o.useState(null);if(o.useEffect(()=>{r(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const a=c=>{n||(r(c),s(c))},i=c=>c.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"bg-gradient-to-br from-amber-600 to-amber-700 text-white py-2.5 px-4 shrink-0 z-[5]",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(Ft,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((c,u)=>{const l=i(c).toLowerCase(),x=/^(run|approve|accept|yes|allow|always)/.test(l),d=/^(reject|deny|delete|remove|abort)/.test(l),h=n===c,g=n!==null;return e.jsx("button",{onClick:()=>a(c),disabled:g,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${x?"bg-white text-amber-700 font-extrabold":d?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${g&&!h?"opacity-40":"opacity-100"} ${g?"cursor-not-allowed":"cursor-pointer"}`,children:h?"⏳ ...":i(c)},u)})})]})]})}const we=new Map;function nr({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:a,serverModel:i,serverMode:c,acpConfigOptions:u,acpModes:l}){var oe;const{sendCommand:x}=Pe(),d=!!(u||l),h=`${t}:${s||r}`,g=we.get(h),[f,b]=o.useState(!1),[k,S]=o.useState(!1),[p,y]=o.useState((g==null?void 0:g.models)||[]),[N,T]=o.useState((g==null?void 0:g.modes)||[]),m=W=>W?typeof W=="string"?W:typeof W=="object"?W.name||W.id||JSON.stringify(W):String(W):"",[j,v]=o.useState(m(i)),[w,R]=o.useState(m(c)),[A,O]=o.useState(!1),[_,I]=o.useState(!1),P=o.useRef(0),K=W=>W.map($=>typeof $=="string"?$:($==null?void 0:$.name)||($==null?void 0:$.id)||String($));o.useEffect(()=>{if(u){const W=u.find($=>$.category==="model");if(W){const $=K(W.options.map(L=>L.value));y($),W.currentValue&&v(m(W.currentValue));const E=we.get(h)||{models:[],modes:[]};we.set(h,{...E,models:$})}}if(l&&l.length>0){const W=K(l.map(E=>E.id));T(W);const $=we.get(h)||{models:[],modes:[]};we.set(h,{...$,modes:W})}else if(u){const W=u.find($=>$.category!=="model");if(W){const $=K(W.options.map(L=>L.value));T($),W.currentValue&&R(m(W.currentValue));const E=we.get(h)||{models:[],modes:[]};we.set(h,{...E,modes:$})}}},[u,l,h]),o.useEffect(()=>{b(!1),S(!1),v(m(i)),R(m(c));const W=we.get(h);W?(y(W.models),T(W.modes)):(y([]),T([]))},[t,r,s]),o.useEffect(()=>{i&&Date.now()>P.current&&v(m(i))},[i]),o.useEffect(()=>{c&&Date.now()>P.current&&R(m(c))},[c]);const C=o.useCallback(async(W,$={})=>{const E={...$,...s&&{targetSessionId:s}};return await x(t,W,E)},[t,s,x]),F=async()=>{var W,$;if(p.length>0){b(!f);return}if(d){b(!0);return}O(!0);try{const E=await C("list_extension_models",{agentType:r,ideType:n}),L=(E==null?void 0:E.models)||((W=E==null?void 0:E.result)==null?void 0:W.models)||[],D=K(L);y(D),E!=null&&E.current&&v(m(E.current)),($=E==null?void 0:E.result)!=null&&$.current&&v(m(E.result.current));const U=we.get(h)||{models:[],modes:[]};we.set(h,{...U,models:D}),b(!0)}catch{}finally{O(!1)}},Q=async()=>{var W,$;if(N.length>0){S(!k);return}if(d){S(!0);return}I(!0);try{const E=await C("list_extension_modes",{agentType:r,ideType:n}),L=(E==null?void 0:E.modes)||((W=E==null?void 0:E.result)==null?void 0:W.modes)||[],D=K(L);T(D),E!=null&&E.current&&R(m(E.current)),($=E==null?void 0:E.result)!=null&&$.current&&R(m(E.result.current));const U=we.get(h)||{models:[],modes:[]};we.set(h,{...U,modes:D}),S(!0)}catch{}finally{I(!1)}},J=async W=>{b(!1),v(W),P.current=Date.now()+5e3;try{d?await C("change_model",{agentType:r,ideType:n,model:W}):await C("set_extension_model",{agentType:r,ideType:n,model:W})}catch{}},G=d&&!(l&&l.length>0)&&(u==null?void 0:u.some(W=>W.category!=="model")),se=G?(oe=u==null?void 0:u.find(W=>W.category!=="model"))==null?void 0:oe.configId:void 0,X=async W=>{S(!1),R(W),P.current=Date.now()+5e3;try{d&&G&&se?await C("set_thought_level",{agentType:r,ideType:n,configId:se,value:W}):d?await C("set_mode",{agentType:r,ideType:n,mode:W}):await C("set_extension_mode",{agentType:r,ideType:n,mode:W})}catch{}},ee={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"}[r]||"#94a3b8";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:ee},children:a}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),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?`${ee}55`:"transparent",border:"1px solid",color:j?"var(--text-primary)":"var(--text-muted)"},onClick:F,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),A?"...":j||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),f&&p.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>b(!1)}),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:"SELECT MODEL"}),p.map(W=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:W===j?`${ee}18`:"transparent",color:W===j?ee:"var(--text-secondary)",fontWeight:W===j?600:400,borderLeft:W===j?`2px solid ${ee}`:"2px solid transparent"},onMouseEnter:$=>{$.currentTarget.style.background=`${ee}12`},onMouseLeave:$=>{$.currentTarget.style.background=W===j?`${ee}18`:"transparent"},onClick:()=>J(W),children:W},W))]})]})]}),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:k?`${ee}55`:"transparent",border:"1px solid",color:w?"var(--text-primary)":"var(--text-muted)"},onClick:Q,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:G?"🧠":"⚡"}),_?"...":w||(G?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),k&&N.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>S(!1)}),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:G?"SELECT THINKING LEVEL":"SELECT MODE"}),N.map(W=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:W===w?`${ee}18`:"transparent",color:W===w?ee:"var(--text-secondary)",fontWeight:W===w?600:400,borderLeft:W===w?`2px solid ${ee}`:"2px solid transparent"},onMouseEnter:$=>{$.currentTarget.style.background=`${ee}12`},onMouseLeave:$=>{$.currentTarget.style.background=W===w?`${ee}18`:"transparent"},onClick:()=>X(W),children:W},W))]})]})]})]})}const rr=o.memo(function({contextKey:s,panelLabel:n,isSending:r,onSend:a}){const i=o.useRef(null),[c,u]=o.useState("");o.useEffect(()=>{u("")},[s]);const l=()=>{const x=c.trim();!x||r||(u(""),a(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:i,type:"text",placeholder:`Send message to ${n}...`,value:c,onChange:x=>u(x.target.value),onPaste:x=>{const d=x.clipboardData.getData("text");d&&u(h=>h+d),x.preventDefault()},onKeyDown:x=>{if(x.key==="Enter"){if(x.nativeEvent.isComposing){x.preventDefault();return}x.preventDefault(),l()}},onBlur:x=>{if(window.innerWidth<768){const d=x.relatedTarget;if((d==null?void 0:d.tagName)==="BUTTON")return;setTimeout(()=>{document.documentElement.scrollTop=0},300)}},className:"w-full h-10 rounded-[20px] px-4 bg-bg-secondary text-sm text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:l,disabled:!c.trim()||r,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${c.trim()&&!r?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:c.trim()&&!r?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:c.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})}),ye=t=>t.transport==="pty",ge=t=>t.transport==="acp";var ar=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function or(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function me(t,s){if(or(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":ar.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 Ps(t){return me(t)==="generating"}function he(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function ir(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 a=Math.floor(n/24),i=n%24;return`${a}d ${i}h`}function Qt(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Bt(t,s){const n=typeof s=="string"?s.trim():"";if(n)return n;const r=typeof t=="string"?t.trim():"";if(!r)return"";const a=r.replace(/[\\/]+$/,""),i=a.split(/[\\/]/).filter(Boolean);return i[i.length-1]||a}function cr(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 lr(t){return cr(t.trim().replace(/\.local$/i,""))}function dr(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function Ds(t,s={}){var a,i;const n=[t.hostname,(a=t.machine)==null?void 0:a.hostname,(i=t.system)==null?void 0:i.hostname].find(c=>typeof c=="string"&&c.trim().length>0);if(n&&n!=="Unknown")return lr(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function Xe(t,s={}){return dr(t)||Ds(t,s)}function es(t){return t.transport==="pty"}function ts(t){return t.transport==="acp"}function ss(t,s){return he(t)}function ur(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const a=(s||"").trim().toLowerCase(),i=(n||"").trim().toLowerCase(),c=he(n||"").trim().toLowerCase();return r===a||r===i||r===c}function xr(t){return me(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function hr(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 a=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),i=s.get(a),c=me(r.status);if(!i){s.set(a,{...r,status:c});continue}const u=n.indexOf(i.status||"idle"),l=n.indexOf(c||"idle");l>=0&&(u<0||l<u)&&s.set(a,{...r,status:c})}return Array.from(s.values())}const pr=60,mr=60;function Bs({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:a,isFocusingAgent:i,actionLogs:c,userName:u}){const l=o.useRef(new Map),{sendCommand:x}=Pe();ct("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:r});const d=o.useRef(new Map),h=o.useCallback(_=>(d.current.has(_)||d.current.set(_,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:pr}),d.current.get(_)),[]),g=o.useCallback((_,I)=>{const P=h(_);d.current.set(_,{...P,...I}),f(K=>K+1)},[h]),[,f]=o.useState(0),b=t.tabKey,k=h(b),S=k.messages,p=k.hasMore,y=k.error,N=Math.max(0,t.messages.length-k.visibleLiveCount),[T,m]=o.useState(!1),j=o.useCallback(async()=>{var P,K;if(T)return;const _=t.tabKey,I=h(_);if(t.messages.length>I.visibleLiveCount){g(_,{visibleLiveCount:Math.min(t.messages.length,I.visibleLiveCount+mr),error:null});return}m(!0),g(_,{error:null});try{const C=(s==null?void 0:s.daemonId)||((P=t.ideId)==null?void 0:P.split(":")[0])||"";if(!C){g(_,{hasMore:!1});return}const F=t.ideType||t.agentType||"",Q=await x(C,"chat_history",{agentType:F,offset:I.offset,limit:30,targetSessionId:t.sessionId}),J=(Q==null?void 0:Q.result)??Q;if(((K=J.messages)==null?void 0:K.length)>0){const G=h(_);g(_,{messages:[...J.messages,...G.messages],offset:G.offset+J.messages.length,hasMore:!!J.hasMore})}else g(_,{hasMore:!!J.hasMore})}catch(C){const F=(C==null?void 0:C.message)||"";F.includes("P2P not available")||F.includes("channel not open")||F.includes("P2P not connected")||F.includes("timeout")?g(_,{error:"Connection not ready — tap to retry"}):g(_,{hasMore:!1,error:"Failed to load history"})}finally{m(!1)}},[T,s,t,x,h,g]),{allMessages:v,receivedAtMap:w}=o.useMemo(()=>{const _=N>0?t.messages.slice(-k.visibleLiveCount):t.messages;if(S.length===0){const F={};return _.forEach((Q,J)=>{const G=`${t.tabKey}:${Ve(Q,J)}`;let se=Q.receivedAt||l.current.get(G)||0;se||(se=Date.now(),l.current.set(G,se)),F[Ve(Q,J)]=se}),{allMessages:_,receivedAtMap:F}}const I=new Set(_.map(F=>`${F.role}:${(F.content||"").slice(0,100)}`)),K=[...S.filter(F=>!I.has(`${F.role}:${(F.content||"").slice(0,100)}`)),..._],C={};return K.forEach((F,Q)=>{const J=`${t.tabKey}:${Ve(F,Q)}`;let G=F.receivedAt||l.current.get(J)||0;G||(G=Date.now(),l.current.set(J,G)),C[Ve(F,Q)]=G}),{allMessages:K,receivedAtMap:C}},[t.messages,t.tabKey,N,S,k.visibleLiveCount]),R=o.useMemo(()=>c.filter(_=>_.ideId===t.tabKey).sort((_,I)=>_.timestamp-I.timestamp),[c,t.tabKey]),A=t.displayPrimary||t.agentName||"Agent",O=o.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(Ye,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:a,disabled:i,className:"btn btn-primary",children:i?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pt,{size:14})," Open ",A," 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(Ts,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:a,disabled:i,className:"btn btn-primary",children:i?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pt,{size:14})," Open ",A," 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"&&!T)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,a,i,T,A]);return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[e.jsx(Xn,{messages:v,actionLogs:R,agentName:t.agentName||t.displayPrimary||"Agent",userName:u,isCliMode:ye(t)||ge(t),isWorking:t.status==="generating",contextKey:t.tabKey,receivedAtMap:w,onLoadMore:j,isLoadingMore:T,hasMoreHistory:p,hiddenLiveCount:N,loadError:y??void 0,emptyState:O}),!ye(t)&&(()=>{const _=t.streamSource!=="agent-stream",I=_?t.ideType:t.agentType,P=_?s!=null&&s.type?he(s.type):he(t.ideType||""):t.agentName||he(t.agentType||"");return e.jsx(nr,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:I,displayLabel:P,serverModel:(s==null?void 0:s.currentModel)||void 0,serverMode:(s==null?void 0:s.currentPlan)||void 0,acpConfigOptions:ge(t)?s==null?void 0:s.acpConfigOptions:void 0,acpModes:ge(t)?s==null?void 0:s.acpModes:void 0})})(),e.jsx(rr,{contextKey:t.tabKey,panelLabel:A,isSending:r,onSend:n})]})}let Ws=ot;function It(){return Ws()}class fr{constructor(){ue(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(a=>a(...n))}}let Os=new fr;class gr{constructor(){ue(this,"ptyCallbacks",new Set)}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,a){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(a=>a(s,n,r))}getRuntimeSnapshot(s){return Promise.resolve(null)}onRuntimeEvent(s,n){return()=>{}}}let xe=new gr;function br(t){t.dashboardWS&&(Os=t.dashboardWS),t.connectionManager&&(xe=t.connectionManager),t.useDaemonsHook&&(Ws=t.useDaemonsHook)}function yr({activeConv:t,clearToken:s=0,ptyBuffers:n,terminalRef:r,handleSendChat:a,isSendingChat:i=!1}){var m;const c=o.useRef(null),{sendCommand:u,sendData:l}=Pe(),[x,d]=o.useState(""),[h,g]=o.useState(!1),f=o.useRef(0),b=o.useRef(!1),k=t.tabKey,S=t.sessionId||"",p=t.daemonId||((m=t.ideId)==null?void 0:m.split(":")[0])||t.ideId||"",y=()=>{var j;f.current=0,b.current=!1,g(!1),(j=r.current)==null||j.clear()},N=()=>{var j;f.current=0,b.current=!1,g(!0),(j=r.current)==null||j.clear()},T=(j,v=0)=>{var w,R;b.current||f.current>=v&&f.current!==0||(f.current=v,g(!0),(w=r.current)==null||w.clear(),j&&((R=r.current)==null||R.write(j)))};return o.useEffect(()=>{y()},[S]),o.useEffect(()=>{var w,R;if(!S)return;let j=!1;(w=xe.getRuntimeSnapshot)==null||w.call(xe,S).then(A=>{j||!A||A.sessionId!==S||T(A.text||"",A.seq||0)}).catch(()=>{});const v=((R=xe.onRuntimeEvent)==null?void 0:R.call(xe,S,A=>{var O;if(!(!A||A.sessionId!==S)){if(A.type==="runtime_snapshot"){T(A.text||"",A.seq||0);return}if(A.type==="session_output"){b.current=!0,typeof A.seq=="number"&&(f.current=Math.max(f.current,A.seq)),g(!0),typeof A.data=="string"&&((O=r.current)==null||O.write(A.data));return}A.type==="session_cleared"&&N()}}))||(()=>{});return()=>{j=!0,v()}},[S,r]),o.useEffect(()=>{var v,w;if(!S)return;p&&((v=xe.getState)==null?void 0:v.call(xe,p))==="connected"&&g(!0);const j=(w=xe.onStateChange)==null?void 0:w.call(xe,(R,A)=>{R!==p||A!=="connected"||g(!0)});return()=>{j==null||j()}},[p,S,r]),o.useEffect(()=>{s&&(n.current.delete(k),y())},[s,k,n,r]),o.useEffect(()=>{d("")},[t.tabKey]),o.useEffect(()=>{const j=v=>{var R;const w=v.detail;w!=null&&w.sessionId&&w.sessionId!==S||h&&((R=r.current)==null||R.fit())};return window.addEventListener("adhdev:fit-cli-terminal",j),()=>{window.removeEventListener("adhdev:fit-cli-terminal",j)}},[h,S,r]),o.useEffect(()=>{if(!h)return;const j=requestAnimationFrame(()=>{var v;(v=r.current)==null||v.fit()});return()=>cancelAnimationFrame(j)},[h,S,r]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx(Ls,{ref:r,readOnly:!h,onInput:j=>{h&&(l!=null&&l(p,{type:"pty_input",targetSessionId:S,data:j})||u(p,"pty_input",{targetSessionId:S,data:j}).catch(console.error))},onResize:(j,v)=>{h&&(l!=null&&l(p,{type:"pty_resize",targetSessionId:S,cols:j,rows:v})||u(p,"pty_resize",{targetSessionId:S,cols:j,rows:v,force:!0}).catch(()=>{}))}},t.tabKey),!h&&e.jsx("div",{className:"absolute inset-x-2 top-2 rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[11px] text-red-300 pointer-events-none",children:"Runtime terminal unavailable"})]}),e.jsx("div",{className:"px-3 py-2 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:c,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:x,onChange:j=>d(j.target.value),onPaste:j=>{const v=j.clipboardData.getData("text");v&&d(w=>w+v),j.preventDefault()},onKeyDown:j=>{if(j.key!=="Enter")return;if(j.nativeEvent.isComposing){j.preventDefault();return}j.preventDefault();const v=x.trim();!h||!v||i||(d(""),a(v))},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 j=x.trim();!h||!j||i||(d(""),a(j))},disabled:!h||!x.trim()||i,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${x.trim()&&!i?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:x.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:x.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function jr({wsStatus:t,showReconnected:s,loginUrl:n}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",a=t==="auth_failed"?"red":t==="offline"?"orange":"violet",i={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)"},u={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:i[a],borderBottom:c[a],color:u[a]},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 vr({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,onOpenHistory:a,onStopCli:i,onFitCli:c}){const u=it(),l=It(),x=l.p2pStates||{},d=l.ides||[],h=!!t&&ye(t)&&!ge(t),g=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",f=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",b=d.filter(T=>T.type==="adhdev-daemon"),k=Object.values(x),S=k.filter(T=>T==="connected").length,p=k.filter(T=>T==="connecting"||T==="new"||T==="checking").length,N=n!=="connected"||b.length===0?null:p>0&&S===0?"P2P connecting...":S>0&&s===0?"Waiting for IDE...":null;return e.jsxs("div",{className:"dashboard-header",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"leading-tight",children:[e.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[e.jsx(qe,{size:18}),e.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),e.jsx("span",{className:"header-title-mobile",children:(t==null?void 0:t.displayPrimary)||"Dashboard"}),e.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:g,boxShadow:f}})})]}),e.jsxs("div",{className:"header-subtitle text-xs items-center gap-1",children:[s," agent",s!==1?"s":""," active",e.jsx("span",{title:r?"Connected":n==="connected"?"Partial":"Disconnected",className:"inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:g,boxShadow:f}}),N&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",N]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[h&&i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Fit terminal to current view",children:"Fit"}),e.jsx("button",{onClick:i,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&&!h&&!ge(t)&&e.jsxs("button",{onClick:()=>u(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Ut,{size:14})," IDE"]}),t&&!h&&!ge(t)&&e.jsx("button",{onClick:a,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Is,{size:16})}),t&&!h&&!ge(t)&&e.jsx("button",{onClick:()=>u(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Le,{size:16})})]})]})}function Ks({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,onClose:a,onNewChat:i,onSwitchSession:c,onRefreshHistory:u}){var h;const l=s.find(g=>g.id===t.ideId),x=(l==null?void 0:l.chats)||[],d=(h=l==null?void 0:l.activeChat)==null?void 0:h.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:a,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," — ",he(t.ideType)]})]}),e.jsx("button",{onClick:a,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:i,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(g=>e.jsxs("div",{onClick:()=>{c(t.ideId,g.id),a()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${d===g.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${d===g.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:g.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:[g.id.substring(0,12),"..."]}),d===g.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},g.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(Wn,{size:32})}),e.jsx("div",{className:"text-[13px]",children:"No recent chat sessions found."})]})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:u,disabled:r,className:"btn btn-secondary btn-sm rounded-[10px]",children:r?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ms,{size:13})," Refresh History"]})})})]})]})}const ns={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function zs({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 a;(a=r.actions)!=null&&a.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:a=>{a.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((a,i)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${a.variant==="primary"?"bg-white text-amber-700 hover:bg-gray-100":a.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(),a.onClick(),s(r.id)},children:a.label},i))})]},r.id))})}const wr=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Nr(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function kr(t){return t.sessionId||t.instanceId||t.agentType}function xt(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 rs(t,s){const n=new Set,r=[];for(const a of s)if(a)for(const i of t[a]||[]){const c=i._localId||`${i.role}:${i.timestamp}:${i.content}`;n.has(c)||(n.add(c),r.push(i))}return r.sort((a,i)=>a.timestamp-i.timestamp)}function Hs(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=Xe(r,{fallbackId:r.id}))}return s}function Fs(t,s,n={}){var f,b,k,S,p,y;const r=[],a=n.machineName,i=n.connectionState,c=Nr(t),u=he(t.type),l=t.agentStreams,x=Array.isArray(l)?l.map(N=>({...N,activeModal:N.activeModal??void 0})):[],d=wr(t),h=t.activeChat||{title:""},g=h.title&&String(h.title).trim()?String(h.title).trim():"";if(d){const N=t.sessionId||t.instanceId,T=ss(t.type),m=(f=t.activeChat)==null?void 0:f.activeModal,j=m&&Array.isArray(m.buttons)&&m.buttons.length>0,v=me((b=t.activeChat)==null?void 0:b.status,{activeModal:(k=t.activeChat)==null?void 0:k.activeModal})||me((p=(S=t.agents)==null?void 0:S[0])==null?void 0:p.status)||"idle",w=t.activeChat||{title:"",messages:[]};let R=w.title&&String(w.title).trim()?String(w.title).trim():"";const A=(y=t.activeChat)==null?void 0:y.id,O=t.chats;if(A&&Array.isArray(O)&&O.length>0){const C=O.find(F=>F.id===A||F.id&&String(F.id)===String(A));C!=null&&C.title&&String(C.title).trim()&&(R=String(C.title).trim())}const _=w.messages||[],I=rs(s,[t.id,N]),P=new Map;_.filter(C=>C.role==="user").forEach(C=>{const F=xt(C.content);F&&P.set(F,(P.get(F)||0)+1)});const K=I.filter(C=>{const F=xt(C.content),Q=P.get(F)||0;return Q>0?(P.set(F,Q-1),!1):!0});r.push({ideId:t.id,sessionId:N,transport:t.transport,daemonId:t.daemonId||void 0,mode:ye(t)?t.mode||"terminal":"chat",agentName:T,agentType:(ye(t)||ge(t))&&(t.cliType||t.acpType)||t.type,status:v,title:R,messages:[..._,...K],terminalHistory:typeof w.terminalHistory=="string"?w.terminalHistory:"",resume:t.resume,ideType:t.cliType||t.acpType||t.type,workspaceName:c,displayPrimary:R||c||(ye(t)||ge(t)?"Terminal":T),displaySecondary:u,cdpConnected:t.cdpConnected,modalButtons:j?m.buttons:void 0,modalMessage:j?m.message:void 0,streamSource:"native",tabKey:t.id,machineName:a,connectionState:i})}if(d&&(ye(t)||ge(t)))return r;for(const N of x){const T=N.activeModal&&Array.isArray(N.activeModal.buttons)&&N.activeModal.buttons.length>0,m=xr(N),j=kr(N),v=`${t.id}:${j}`,w=N.title&&String(N.title).trim()||"",R=ur(w,N.agentName,N.agentType)?"":w,A=N.messages||[],O=rs(s,[v,N.sessionId,N.instanceId]),_=new Map;A.filter(P=>P.role==="user").forEach(P=>{const K=xt(P.content);K&&_.set(K,(_.get(K)||0)+1)});const I=O.filter(P=>{const K=xt(P.content),C=_.get(K)||0;return C>0?(_.set(K,C-1),!1):!0});r.push({ideId:t.id,sessionId:N.sessionId||N.instanceId,transport:N.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:N.agentName,agentType:N.agentType,status:m,title:R,messages:[...A,...I],ideType:N.agentType,workspaceName:c,displayPrimary:R||g||c||u,displaySecondary:`${u}·${N.agentName}`,cdpConnected:t.cdpConnected,modalButtons:T?N.activeModal.buttons:void 0,modalMessage:T?N.activeModal.message:void 0,streamSource:"agent-stream",tabKey:v,machineName:a,connectionState:i})}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:ss(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:c,displayPrimary:c||u,displaySecondary:u,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:t.id,connectionState:i}),r}function Sr(t){const s=[],n=new Map;for(const r of t)if(r.parentId){const a=n.get(r.parentId)||[];a.push(r),n.set(r.parentId,a)}else s.push(r);return{topLevel:s,childrenByParent:n}}function Cr(t,s){var f,b,k,S,p,y,N,T;const n=[],{daemonId:r,existingDaemon:a,timestamp:i}=s,c=i||t.timestamp||Date.now(),u=t.sessions||[],{topLevel:l,childrenByParent:x}=Sr(u),d=l.filter(m=>m.kind==="workspace"&&m.transport==="cdp-page"),h=l.filter(m=>m.kind==="agent"&&m.transport==="pty"),g=l.filter(m=>m.kind==="agent"&&m.transport==="acp");n.push({...a||{},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.workspaceActivity&&{workspaceActivity:t.workspaceActivity},...t.detectedIdes&&{detectedIdes:t.detectedIdes},..."availableProviders"in t&&{availableProviders:t.availableProviders},cdpConnected:d.some(m=>!!m.cdpConnected)});for(const m of d){const j=x.get(m.id)||[];n.push({id:`${r}:ide:${m.id}`,sessionId:m.id,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,status:m.cdpConnected?"online":"detected",daemonId:r,instanceId:m.id,workspace:m.workspace,terminals:0,agents:j.map(v=>({id:v.id,name:v.providerName,type:v.providerType,status:v.status})),activeChat:m.activeChat,chats:[],agentStreams:j.map(v=>{var w,R,A,O;return{sessionId:v.id,instanceId:v.id,parentSessionId:v.parentId,agentType:v.providerType,agentName:v.providerName,extensionId:v.providerType,transport:v.transport,status:me(v.status,{activeModal:(w=v.activeChat)==null?void 0:w.activeModal}),title:v.title,messages:((R=v.activeChat)==null?void 0:R.messages)||[],inputContent:((A=v.activeChat)==null?void 0:A.inputContent)||"",activeModal:((O=v.activeChat)==null?void 0:O.activeModal)||null,model:v.currentModel}}),cdpConnected:m.cdpConnected,currentModel:m.currentModel,currentPlan:m.currentPlan,currentAutoApprove:m.currentAutoApprove,timestamp:c})}for(const m of h){const j=m.runtime;n.push({id:`${r}:cli:${m.id}`,sessionId:m.id,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,agentType:m.providerType,status:m.status||"running",daemonId:r,instanceId:m.id,cliName:m.providerName,mode:"terminal",workspace:m.workspace||"",activeChat:m.activeChat,resume:m.resume,runtimeKey:m.runtimeKey??(j==null?void 0:j.runtimeKey),runtimeDisplayName:m.runtimeDisplayName??(j==null?void 0:j.displayName),runtimeWorkspaceLabel:m.runtimeWorkspaceLabel??(j==null?void 0:j.workspaceLabel),runtimeWriteOwner:m.runtimeWriteOwner??(j==null?void 0:j.writeOwner)??null,runtimeAttachedClients:m.runtimeAttachedClients??(j==null?void 0:j.attachedClients)??[],agentStreams:[{sessionId:m.id,instanceId:m.id,parentSessionId:m.parentId,agentType:m.providerType,agentName:m.providerName,extensionId:"cli-agent",transport:m.transport,status:me(m.status,{activeModal:(f=m.activeChat)==null?void 0:f.activeModal}),title:m.title,messages:((b=m.activeChat)==null?void 0:b.messages)||[],inputContent:((k=m.activeChat)==null?void 0:k.inputContent)||"",activeModal:(S=m.activeChat)==null?void 0:S.activeModal}],timestamp:c,_isCli:!0})}for(const m of g){const j=m.runtime;n.push({id:`${r}:acp:${m.id}`,sessionId:m.id,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,agentType:m.providerType,status:m.status||"running",daemonId:r,instanceId:m.id,cliName:m.providerName,mode:"chat",workspace:m.workspace||"",activeChat:m.activeChat,runtimeKey:m.runtimeKey??(j==null?void 0:j.runtimeKey),runtimeDisplayName:m.runtimeDisplayName??(j==null?void 0:j.displayName),runtimeWorkspaceLabel:m.runtimeWorkspaceLabel??(j==null?void 0:j.workspaceLabel),runtimeWriteOwner:m.runtimeWriteOwner??(j==null?void 0:j.writeOwner)??null,runtimeAttachedClients:m.runtimeAttachedClients??(j==null?void 0:j.attachedClients)??[],currentModel:m.currentModel,currentPlan:m.currentPlan,acpConfigOptions:m.acpConfigOptions,acpModes:m.acpModes,agentStreams:[{sessionId:m.id,instanceId:m.id,parentSessionId:m.parentId,agentType:m.providerType,agentName:m.providerName,extensionId:"acp-agent",transport:m.transport,status:me(m.status,{activeModal:(p=m.activeChat)==null?void 0:p.activeModal}),title:m.title,messages:((y=m.activeChat)==null?void 0:y.messages)||[],inputContent:((N=m.activeChat)==null?void 0:N.inputContent)||"",activeModal:(T=m.activeChat)==null?void 0:T.activeModal}],timestamp:c,_isAcp:!0})}return n}function Us(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 Ir(t,s){const n=Us(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const Vs=[{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:"💚"}],qs=[{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:"🧩"}],Ys=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],Xs="adhdev_notification_prefs",as={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function Mr(){try{const t=localStorage.getItem(Xs);if(t){const s=JSON.parse(t);return{...as,...s}}}catch{}return{...as}}function Tr(t){try{localStorage.setItem(Xs,JSON.stringify(t))}catch{}}let Te=Mr(),bt=[];function Er(){bt.forEach(t=>t())}function Ar(){return{...Te}}function Rr(t){Te={...Te,...t},Tr(Te),Er()}function _r(){const[,t]=o.useState(0);o.useEffect(()=>{const n=()=>t(r=>r+1);return bt.push(n),()=>{bt=bt.filter(r=>r!==n)}},[]);const s=o.useCallback(n=>{Rr(n)},[]);return[{...Te},s]}function nt(t){if(!Te.globalEnabled)return!1;switch(t){case"disconnect":return Te.disconnectAlert;case"completion":return Te.completionAlert;case"approval":return Te.approvalAlert;case"browser":return Te.browserNotifications;default:return!0}}const Lr={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function $r(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function Gs(){return"Notification"in window&&Notification.permission==="granted"}let De=null;async function Pr(){if(De!==null)return De;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return De=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(De=!!await t.pushManager.getSubscription(),De):(De=!1,!1)}catch{return De=!1,!1}}function Wt(t,s,n){if(Gs())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 Dr(t,s={}){const n={...Lr,...s},r=o.useRef(new Map),a=o.useRef(0),i=o.useRef(null);o.useEffect(()=>{Pr().then(u=>{i.current=u})},[]);const c=o.useCallback((u,l,x)=>{const d=Date.now();d-a.current<n.throttleMs||(a.current=d,Wt(u,l,x))},[n.throttleMs]);o.useEffect(()=>{var u;if(!(!n.enabled||!Gs())&&nt("browser")&&i.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,me(l.status,{activeModal:l.activeModal}));return}for(const l of t){const x=r.current.get(l.id),d=me(l.status,{activeModal:l.activeModal}),h=l.name||l.id;if(n.onApproval&&nt("approval")&&d==="waiting_approval"&&x!=="waiting_approval"){const g=((u=l.activeModal)==null?void 0:u.message)||"Action requires your approval";c(`🔔 ${h} — Approval needed`,g.slice(0,120),`approval-${l.id}`)}n.onComplete&&nt("completion")&&Ps(x)&&d==="idle"&&c(`✅ ${h} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&d==="error"&&x!=="error"&&c(`⚠️ ${h} — Error`,"Agent encountered an error",`error-${l.id}`),r.current.set(l.id,d)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class Br{constructor(){ue(this,"dedupMap",new Map);ue(this,"DEDUP_WINDOW_MS",5e3);ue(this,"DEDUP_MAX_SIZE",50);ue(this,"DEDUP_CLEANUP_AGE_MS",1e4);ue(this,"toastCallbacks",[]);ue(this,"systemMessageCallbacks",[]);ue(this,"clearSystemMessageCallbacks",[]);ue(this,"resolveActionFn",null);ue(this,"viewRequestRespondFn",null);ue(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 a=(r==null?void 0:r.id)||Date.now();this.emitToast({id:a,message:s,type:n,timestamp:a,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[a,i]of this.dedupMap)n-i>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(a);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const a=this.ides.find(i=>i.id===s.ideId&&i.type==="adhdev-daemon");if(a)return a}let n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(a=>a.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(a=>a.id.endsWith(`:ide:${s.instanceId}`)||a.id.endsWith(`:cli:${s.instanceId}`))),n){const a=n.daemonId;if(a){const i=this.ides.find(c=>c.id===a&&c.type==="adhdev-daemon");if(i)return i}}const r=this.ides.filter(a=>a.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.agentStreams)?n.agentStreams:[]).some(a=>(a==null?void 0:a.sessionId)===s))return n;return null}resolveActionRouteTarget(s){if(s.ideId){const n=s.agentType||s.ideType||"";return this.resolveRouteId(s.ideId,n)}if(s.targetSessionId){const n=this.findOwningSession(s.targetSessionId);return(n==null?void 0:n.id)||(n==null?void 0:n.daemonId)||null}return null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.ideId?s.ideId:null}handleRawEvent(s,n){var d,h;if(!s.ideId&&s.instanceId){for(const g of this.ides)if(g.id.endsWith(`:ide:${s.instanceId}`)||g.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=g.id;break}}const r=this.resolveConversationKey(s),i=`${r||s.instanceId||s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(i))return;let c=he(s.ideType||"");const u=this.resolveOwningDaemon(s);if(u){const g=Xe(u,{fallbackId:u.id});g&&(c=s.ideType==="adhdev-daemon"?g:`${g}/${c}`)}let l="",x="info";if(s.event==="agent:generating_completed"){const g=s.duration?` (${s.duration}s)`:"";l=`✅ ${c} agent task completed${g}`,x="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&Ar().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${g}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")r&&this.emitClearSystemMessage(r,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(l=`⚡ ${c} approval needed`,x="warning",r){const g=s.modalMessage||"Approval requested",f=(d=s.modalButtons)!=null&&d.length?s.modalButtons.map(b=>`[${b}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${g}
|
|
42
|
+
${f}`,_localId:`sys_approval_${Date.now()}`})}if((h=s.modalButtons)!=null&&h.length&&this.resolveActionFn){const g=this.resolveActionRouteTarget(s);if(!g)return;const f=s.agentType||s.ideType||"",b=s.ideType||"",k=s.modalButtons,S=m=>m.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),p=this.resolveActionFn,y=k.map((m,j)=>{const v=S(m).toLowerCase(),w=/^(run|approve|accept|yes|allow|always)/.test(v),R=/^(reject|deny|delete|remove|abort|cancel|no)/.test(v);return{label:S(m),variant:w?"primary":R?"danger":"default",onClick:()=>{const A=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(v);p(g,"resolve_action",{action:A?"approve":"reject",button:m,buttonIndex:j,agentType:f,ideType:b,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),N=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,T=Date.now();this.emitToast({id:T,message:N,type:x,timestamp:T,targetKey:r||g,actions:y,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const g=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${c} agent is taking a long time${g}`,x="warning",nt("browser")&&!document.hasFocus()&&Wt(`⚠️ ${c} — Long Running`,`Agent has been generating for over ${g.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const g=s.requesterName||"A team member",f=s.requestId,b=s.orgId;if(l=`👁️ ${g} wants to view your session`,x="warning",f&&b&&this.viewRequestRespondFn){const k=this.viewRequestRespondFn,S=Date.now(),p=[{label:"Approve",variant:"primary",onClick:()=>{k(b,f,"approve").catch(y=>console.error("[EventManager] approve view request failed:",y))}},{label:"Decline",variant:"danger",onClick:()=>{k(b,f,"reject").catch(y=>console.error("[EventManager] reject view request failed:",y))}}];this.emitToast({id:S,message:l,type:x,timestamp:S,actions:p,duration:3e4}),l=""}nt("browser")&&!document.hasFocus()&&Wt("👁️ View Request",`${g} wants to view your session`,`view-request-${f}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",x="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,x="warning");if(l){const g=Date.now();this.emitToast({id:g,message:l,type:x,timestamp:g,targetKey:r||s.ideId,duration:5e3})}}}const $e=new Br;function ze(...t){return mn(fn(t))}function Wr({icon:t,title:s,subtitle:n,badge:r,actions:a,className:i}){return e.jsxs("div",{className:ze("dashboard-header",i),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})]}),a&&e.jsx("div",{className:"flex gap-2",children:a})]})}function Nt({icon:t,title:s,subtitle:n,badge:r,actions:a,widthClassName:i="max-w-6xl",contentClassName:c,children:u}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Wr,{icon:t,title:s,subtitle:n,badge:r,actions:a}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:ze("mx-auto flex w-full flex-col gap-4",i,c),children:u})})]})}function fe({title:t,icon:s,description:n,accentColor:r,className:a,children:i}){return e.jsxs("div",{className:ze("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]",a),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})]}),i]})}function Vt({icon:t,title:s,description:n,action:r,className:a}){return e.jsxs("div",{className:ze("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",a),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 Or={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"},Kr={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function zr({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:ze("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",Or[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:Kr[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 Hr={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"},Fr={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Ur({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:ze("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Hr[t],n),children:[e.jsx("span",{className:ze("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Fr[t])}),r]})}function Vr(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Ot(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function yt(t){return t==="system"?Vr():t}function qr(){typeof document>"u"||document.documentElement.setAttribute("data-theme",yt(Ot()))}function Yr(){const[t,s]=o.useState(Ot),[n,r]=o.useState(()=>yt(Ot()));o.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),o.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),u=l=>{t==="system"&&r(l.matches?"light":"dark")};return c.addEventListener("change",u),()=>c.removeEventListener("change",u)},[t]);const a=o.useCallback(c=>{s(c),r(yt(c));try{localStorage.setItem("theme",c)}catch{}},[]),i=o.useCallback(()=>{s(c=>{const u=c==="dark"?"light":c==="light"?"system":"dark";r(yt(u));try{localStorage.setItem("theme",u)}catch{}return u})},[]);return{theme:n,preference:t,setPreference:a,cycleTheme:i,isDark:n==="dark"}}function We({label:t,description:s,checked:n,disabled:r,onChange:a,extra:i}){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:[i,e.jsx("input",{type:"checkbox",checked:n,disabled:r,onChange:c=>a(c.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function Xr({onPrefChange:t}){const[s,n]=_r(),r=(a,i)=>{n({[a]:i}),t==null||t(a,i)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_s,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:a=>r("globalEnabled",a)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:a=>r("browserNotifications",a)}),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(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(On,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:a=>r("completionAlert",a)}),e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Kn,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:a=>r("approvalAlert",a)}),e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ye,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:a=>r("disconnectAlert",a)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(qe,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:a=>r("chatTaskCompletionBubble",a)}),!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 Gr({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:a}){const i=t.filter(c=>c.type==="adhdev-daemon");return i.length===0?e.jsx(Vt,{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:i.map(c=>e.jsx(Zr,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:a},c.id))})}function os({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:a,onCancel:i}){const c=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"bg-amber-500/20 text-amber-400 border-amber-500/30 hover:bg-amber-500/30";return gn.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:i,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:u=>u.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:i,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:a,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,children:n})]})]})}),document.body)}function Jr(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...Vs,...qs,...Ys].find(a=>a.id===s||s.includes(a.id)||a.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function Zr({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:a}){var P,K;const[i,c]=o.useState("idle"),[u,l]=o.useState(""),[x,d]=o.useState(null),[h,g]=o.useState("idle"),[f,b]=o.useState(""),k=t,S=k.version||k.daemonVersion||null,p=((P=k.machine)==null?void 0:P.platform)||((K=k.system)==null?void 0:K.platform)||"",y=Xe(k,{fallbackId:t.id}),N=p==="win32"?"🪟":p==="darwin"?"🍎":"🐧",T=s.filter(C=>C.daemonId===t.id&&C.transport==="cdp-page"),m=s.filter(C=>C.daemonId===t.id&&C.transport==="pty"),j=s.filter(C=>C.daemonId===t.id&&C.transport==="acp"),v=k.p2p,w=async()=>{var C,F,Q;if(n){c("upgrading"),l("Installing latest version...");try{const J=await n(t.id,"daemon_upgrade",{});(C=J==null?void 0:J.result)!=null&&C.upgraded||(F=J==null?void 0:J.result)!=null&&F.success?(c("done"),l(`Upgraded to v${J.result.version||"latest"}. Daemon is restarting...`)):(c("error"),l(((Q=J==null?void 0:J.result)==null?void 0:Q.error)||"Upgrade failed"))}catch(J){c("error"),l((J==null?void 0:J.message)||"Connection lost during upgrade")}}},R=async()=>{if(d(null),!!r){g("loading");try{await r(t.id),g("done"),b("Machine disconnected.")}catch(C){g("error"),b((C==null?void 0:C.message)||"Failed to disconnect")}}},A=async()=>{if(d(null),!!a){g("loading");try{await a(t.id),g("done"),b('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(C){g("error"),b((C==null?void 0:C.message)||"Failed to revoke token")}}},O="0.7.17",_=!S||S!==O,I=T.length+m.length+j.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:N}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:y}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),S&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${_?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",S,!_&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&_&&e.jsx("button",{onClick:w,disabled:i==="upgrading"||i==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${O}`,children:i==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):i==="done"?"✓ Updated":`↑ Update${` to v${O}`}`}),r&&e.jsx("button",{onClick:()=>d("disconnect"),disabled:h==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),a&&e.jsx("button",{onClick:()=>d("revoke"),disabled:h==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Ur,{status:t.status==="online"?"online":"error"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[v&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${v.state==="connected"?"bg-green-400":v.state==="connecting"||v.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",v.state==="connected"?"connected":v.state==="connecting"||v.state==="new"?"connecting...":v.state||"off"]}),v.peers!==void 0&&v.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",v.peers," peer",v.peers!==1?"s":"",")"]})]}),v&&I>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),I>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[T.map(C=>{const F=Jr(C.type),Q=C.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:F.icon}),e.jsx("span",{children:F.name}),Q!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Q?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:Q?"CDP connected":"CDP connecting..."})]},C.id)}),m.map(C=>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:C.cliName||"CLI"})]},C.id)),j.map(C=>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:C.cliName||"ACP"})]},C.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(u||f)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${i==="error"||h==="error"?"text-red-400":i==="done"||h==="done"?"text-green-400":"text-text-muted"}`,children:f||u})]}),x==="disconnect"&&e.jsx(os,{title:"🔌 Disconnect Machine",message:`Disconnect "${y}" 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:R,onCancel:()=>d(null)}),x==="revoke"&&e.jsx(os,{title:"⚠️ Remove Machine",message:`Remove "${y}" 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:A,onCancel:()=>d(null)})]})}const Qr=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function ea(){const{preference:t,setPreference:s}=Yr();return e.jsx("div",{className:"flex gap-2",children:Qr.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 Kt={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},zt={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},ta=[{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"}}}],Js="adhdev-chat-theme",Zs="adhdev-chat-theme-custom";function jt(){return typeof window>"u"?"ember":localStorage.getItem(Js)||"ember"}function Ie(t){try{const s=localStorage.getItem(Zs);if(s){const n=JSON.parse(s);return{...t==="dark"?Kt:zt,...n[t]}}}catch{}return t==="dark"?Kt:zt}function ht(t,s){localStorage.setItem(Zs,JSON.stringify({dark:t,light:s}))}function Ne(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),a=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${a}, ${s})`}function kt(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),a=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}`}const sa={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function rt(t,s){var a;const n=(a=sa[t])==null?void 0:a[s];if(!n)return;const r=document.documentElement;r.style.setProperty("--accent-primary",n),r.style.setProperty("--accent-primary-light",kt(n,24)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${kt(n,18)})`),r.style.setProperty("--border-accent",Ne(n,.35)),r.style.setProperty("--nav-active-bg",Ne(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Ne(n,.06)}`)}function Oe(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ne(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ne(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ne(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",Ne(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ne(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",kt(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${kt(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ne(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ne(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ne(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 ${Ne(t.accentColor,.12)}`),s.style.setProperty("--chat-container-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 qt(){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","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(n=>t.style.removeProperty(n))}function na(t){if(localStorage.setItem(Js,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Ke()?"dark":"light";Oe(Ie(s))}else qt(),rt(t,Ke()?"dark":"light")}function ra(){const t=jt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Ke()?"dark":"light";Oe(Ie(s))}else qt(),rt(t,Ke()?"dark":"light")}function Ke(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function pe({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 Ze({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 aa({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,a]=o.useState(()=>Ie(n));o.useEffect(()=>{a(Ie(n))},[n]);const i=o.useCallback((c,u)=>{a(l=>{const x={...l,[c]:u},h=Ie(n==="dark"?"light":"dark");return n==="dark"?ht(x,h):ht(h,x),Oe(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(Ze,{title:"App Background",children:[e.jsx(pe,{label:"Background",value:r.bgPrimary,onChange:c=>i("bgPrimary",c)}),e.jsx(pe,{label:"Surface",value:r.bgSecondary,onChange:c=>i("bgSecondary",c)}),e.jsx(pe,{label:"Card",value:r.surfacePrimary,onChange:c=>i("surfacePrimary",c)})]}),e.jsxs(Ze,{title:"App Text",children:[e.jsx(pe,{label:"Primary",value:r.textPrimary,onChange:c=>i("textPrimary",c)}),e.jsx(pe,{label:"Secondary",value:r.textSecondary,onChange:c=>i("textSecondary",c)}),e.jsx(pe,{label:"Muted",value:r.textMuted,onChange:c=>i("textMuted",c)})]}),e.jsxs(Ze,{title:"Borders & Accent",children:[e.jsx(pe,{label:"Border subtle",value:r.borderSubtle,onChange:c=>i("borderSubtle",c)}),e.jsx(pe,{label:"Border default",value:r.borderDefault,onChange:c=>i("borderDefault",c)}),e.jsx(pe,{label:"Accent",value:r.accentColor,onChange:c=>i("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(Ze,{title:"Chat Bubbles",children:[e.jsx(pe,{label:"User bubble",value:r.userBubble,onChange:c=>i("userBubble",c)}),e.jsx(pe,{label:"User text",value:r.userText,onChange:c=>i("userText",c)}),e.jsx(pe,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>i("assistantBubble",c)}),e.jsx(pe,{label:"Agent text",value:r.assistantText,onChange:c=>i("assistantText",c)})]}),e.jsxs(Ze,{title:"Chat Layout",children:[e.jsx(pe,{label:"Chat BG",value:r.containerBg,onChange:c=>i("containerBg",c)}),e.jsx(pe,{label:"Send button",value:r.sendButton,onChange:c=>i("sendButton",c)}),e.jsx(pe,{label:"Input border",value:r.inputBorder,onChange:c=>i("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=>i("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?Kt:zt,l=Ie(t?"light":"dark");t?ht(c,l):ht(l,c),a(c),Oe(c),s(c)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:"Reset to defaults"})]})}function oa(){const[t,s]=o.useState(jt),[n,r]=o.useState(!0),[a,i]=o.useState(()=>Ie("dark"));o.useEffect(()=>{r(Ke());const l=new MutationObserver(()=>{const h=Ke();r(h);const g=jt();g==="custom"?Oe(Ie(h?"dark":"light")):rt(g,h?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>{const h=Ke();r(h);const g=jt();g==="custom"?Oe(Ie(h?"dark":"light")):rt(g,h?"dark":"light")};return x.addEventListener("change",d),()=>{l.disconnect(),x.removeEventListener("change",d)}},[]),o.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Oe(Ie(n?"dark":"light")):(qt(),rt(t,n?"dark":"light"))},[t,n]),o.useEffect(()=>{i(Ie(n?"dark":"light"))},[n]);const c=l=>{s(l),na(l)},u=[...ta,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:a.userBubble,assistantBubble:a.assistantBubble,assistantBorder:`1px solid ${a.accentColor}22`,containerBg:a.containerBg,textColor:a.assistantText},light:{userBubble:a.userBubble,assistantBubble:a.assistantBubble,assistantBorder:`1px solid ${a.accentColor}22`,containerBg:a.containerBg,textColor:a.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:u.map(l=>{const x=t===l.id,d=n?l.preview.dark:l.preview.light,h=l.id==="honey"||l.id==="ember"?"#1a1a1a":l.id==="custom"?a.userText:"#fff";return e.jsxs("button",{onClick:()=>c(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:x?"var(--bg-glass-hover)":"var(--bg-glass)",border:x?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:x?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:d.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.userBubble,color:h},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(aa,{dark:n,onColorsChange:l=>i(l)})]})}const Qs="adhdev_hiddenTabs";function ia(){try{const t=localStorage.getItem(Qs);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function Qe(t){try{localStorage.setItem(Qs,JSON.stringify([...t]))}catch{}}function en(){const[t,s]=o.useState(ia),n=o.useCallback(l=>{s(x=>{const d=new Set(x);return d.has(l)?d.delete(l):d.add(l),Qe(d),d})},[]),r=o.useCallback(l=>{s(x=>{if(x.has(l))return x;const d=new Set(x);return d.add(l),Qe(d),d})},[]),a=o.useCallback(l=>{s(x=>{if(!x.has(l))return x;const d=new Set(x);return d.delete(l),Qe(d),d})},[]),i=o.useCallback((l,x)=>{s(d=>{const h=new Set(d);for(const g of x)h.add(g);return Qe(h),h})},[]),c=o.useCallback((l,x)=>{s(d=>{const h=new Set(d);for(const g of x)h.delete(g);return Qe(h),h})},[]),u=o.useCallback(l=>t.has(l),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:a,hideAllForDaemon:i,showAllForDaemon:c,isHidden:u}}const At=new Set,ca={emit(t,s){for(const n of At)n(t,s)},on(t){return At.add(t),()=>{At.delete(t)}}};function tn({conversations:t,visibleConversations:s,clearedTabs:n,setClearedTabs:r,setActionLogs:a}){const i=o.useRef(new Map);o.useEffect(()=>{$r()},[]);const c=o.useMemo(()=>s.map(u=>({id:u.tabKey,name:u.title||u.agentName||u.ideId,status:u.status,activeModal:u.modalMessage?{message:u.modalMessage,buttons:u.modalButtons}:null})),[s]);return Dr(c),o.useEffect(()=>{if(Object.keys(n).length===0)return;const l=setTimeout(()=>{r(x=>{const d=Date.now(),h={};for(const[g,f]of Object.entries(x))d-f<5e3&&(h[g]=f);return Object.keys(h).length===Object.keys(x).length?x:h})},5500);return()=>clearTimeout(l)},[n,r]),o.useEffect(()=>{const u=setInterval(()=>{const l=Date.now()-3e5;a(x=>{const d=x.filter(h=>h.timestamp>l).slice(-100);return d.length===x.length?x:d})},6e4);return()=>clearInterval(u)},[a]),o.useEffect(()=>{const u=(x,d,h)=>{if(d){ca.emit(x,d);for(const g of t){if(!ye(g)||!(x===g.sessionId||x===g.ideId||x===g.tabKey))continue;const b=h!=null&&h.scrollback?[d]:i.current.get(g.tabKey)||[];h!=null&&h.scrollback||b.push(d),b.length>1e4&&b.splice(0,b.length-5e3),i.current.set(g.tabKey,b)}}},l=xe.onPtyOutput(u);return()=>{l()}},[t]),{ptyBuffers:i}}function la(t){const s=t.filter(r=>r.type!=="adhdev-daemon"),n=new Map;for(const r of s){const a=n.get(r.id);if(!a){n.set(r.id,r);continue}const i=(a.workspace?1:0)+(a.activeChat?1:0);((r.workspace?1:0)+(r.activeChat?1:0)>i||(r.timestamp||0)>(a.timestamp||0))&&n.set(r.id,r)}return Array.from(n.values())}function pt(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 da(t,s){const n=Date.now();return t.map(r=>{const a=s[r.tabKey];return a&&n-a<5e3?{...r,messages:[],title:""}:r})}function ua(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 a of t.agentStreams||[]){const i=a.sessionId||a.instanceId||a.agentType,c=`${t.id}:${i}`;n.push({key:c,ref:s[c]}),a.sessionId&&n.push({key:a.sessionId,ref:s[a.sessionId]}),a.instanceId&&n.push({key:a.instanceId,ref:s[a.instanceId]})}return n}function xa(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 ha({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:a}){const i=o.useRef([]),c=o.useRef([]),u=o.useRef([]),l=o.useRef([]),x=o.useMemo(()=>{const y=la(t);return pt(i.current,y)?i.current:(i.current=y,y)},[t]),d=o.useMemo(()=>Hs(t),[t]),h=o.useRef(new Map),g=o.useMemo(()=>{var T;const y=new Map,N=[];for(const m of x){const j=m.daemonId||((T=m.id)==null?void 0:T.split(":")[0])||m.id,v=s[j]||"new",w=m.daemonId&&d[m.daemonId]||void 0,R=ua(m,n),A=h.current.get(m.id);if(A&&A.ide===m&&A.connectionState===v&&A.machineName===w&&xa(A.localRefs,R)){y.set(m.id,A),N.push(...A.conversations);continue}const O=Fs(m,n,{machineName:w,connectionState:v}),_={ide:m,connectionState:v,machineName:w,localRefs:R,conversations:O};y.set(m.id,_),N.push(...O)}return h.current=y,N},[x,n,s,d]),f=o.useMemo(()=>{const y=da(g,r);return pt(c.current,y)?c.current:(c.current=y,y)},[g,r]),b=o.useMemo(()=>{const y=new Map;for(const N of f)N.sessionId&&y.set(N.sessionId,N),y.set(N.ideId,N),y.set(N.tabKey,N),y.set(N.ideType,N),y.set(N.agentType,N);return y},[f]),k=o.useCallback(y=>{if(y)return b.get(y)},[b]),S=o.useMemo(()=>{const y=f.filter(N=>!a.has(N.tabKey));return pt(u.current,y)?u.current:(u.current=y,y)},[f,a]),p=o.useMemo(()=>{const y=S.map(N=>N.tabKey);return pt(l.current,y)?l.current:(l.current=y,y)},[S]);return{chatIdes:x,conversations:f,visibleConversations:S,visibleTabKeys:p,resolveConversationByTarget:k}}function sn({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:a}){o.useEffect(()=>{$e.setIdes(t)},[t]),o.useEffect(()=>{$e.setResolveAction((i,c,u)=>{s(i,c,u).catch(()=>{})})},[s]),o.useEffect(()=>{const i=$e.onToast(l=>{n(d=>d.some(g=>g.message===l.message&&l.timestamp-g.timestamp<3e3)?d:[...d.slice(-4),{id:l.id,message:l.message,type:l.type,timestamp:l.timestamp,targetKey:l.targetKey,actions:l.actions}]);const x=l.duration||5e3;setTimeout(()=>n(d=>d.filter(h=>h.id!==l.id)),x)}),c=$e.onSystemMessage((l,x)=>{r(d=>({...d,[l]:[...d[l]||[],x]}))}),u=$e.onClearSystemMessage((l,x)=>{r(d=>{var h;return(h=d[l])!=null&&h.length?{...d,[l]:d[l].filter(g=>{var f;return!(g.role==="system"&&((f=g._localId)!=null&&f.startsWith(x)))})}:d})});return()=>{i(),c(),u()}},[n,r]),o.useEffect(()=>{const i=Os.on("status_event",c=>$e.handleRawEvent(c,"ws"));return()=>{i()}},[]),o.useEffect(()=>{var c;const i=u=>{const l=u.data;if((l==null?void 0:l.type)!=="notification_action"||l.action!=="approve"||!(l.ideId||l.targetSessionId||l.targetKey))return;const x=l.targetSessionId||l.targetKey||l.ideId,d=a(x),h=(d==null?void 0:d.ideId)||l.ideId;h&&s(h,"resolve_action",{action:"approve",button:"Approve",...(d==null?void 0:d.sessionId)&&{targetSessionId:d.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(g=>console.error("[SW Action] approve failed:",g))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",i),()=>{var u;return(u=navigator.serviceWorker)==null?void 0:u.removeEventListener("message",i)}},[a,s])}const pa="adhdev_dashboardLayout_v1",et={splitGroups:"adhdev_splitGroups",focusedGroup:"adhdev_focusedGroup",groupActiveTabs:"adhdev_groupActiveTabs",groupTabOrders:"adhdev_groupTabOrders",splitSizes:"adhdev_splitSizes"},tt={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function st(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function ma(t){try{return localStorage.getItem(t)}catch{return null}}function fa(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function nn(t){return`${pa}:${t}`}function ga(){const t=ma(et.focusedGroup),s=st(et.splitGroups,[]),n=st(et.groupActiveTabs,{}),r=st(et.groupTabOrders,{}),a=st(et.splitSizes,[]);return t!==null||s.length>0||Object.keys(n).length>0||Object.keys(r).length>0||a.length>0?{groupAssignments:s,focusedGroup:t&&parseInt(t,10)||0,groupActiveTabIds:n,groupTabOrders:r,groupSizes:a}:null}function ba(t){const s=nn(t),n=st(s,null);return n||ga()}function ya(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=nn(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function ja(){return{groupAssignments:[...tt.groupAssignments],focusedGroup:tt.focusedGroup,groupActiveTabIds:{...tt.groupActiveTabIds},groupTabOrders:{...tt.groupTabOrders},groupSizes:[...tt.groupSizes]}}function va(){const[t]=o.useState(()=>fa(typeof window<"u"?window.innerWidth:1280)),[s,n]=o.useState(()=>new Map),[r,a]=o.useState(0),[i,c]=o.useState({}),[u,l]=o.useState({}),[x,d]=o.useState([]),[h,g]=o.useState(()=>typeof window<"u"&&window.innerWidth<768),[f,b]=o.useState(!1),k=o.useCallback(()=>{if(f)return;const S=ba(t)??ja();n(new Map(S.groupAssignments)),a(S.focusedGroup),c(S.groupActiveTabIds),l(S.groupTabOrders),d(S.groupSizes),b(!0)},[f,t]);return o.useEffect(()=>{f&&ya(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:i,groupTabOrders:u,groupSizes:x})},[f,t,s,r,i,u,x]),o.useEffect(()=>{const S=window.matchMedia("(max-width: 767px)"),p=y=>g(y.matches);return S.addEventListener("change",p),()=>S.removeEventListener("change",p)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:a,groupActiveTabIds:i,setGroupActiveTabIds:c,groupTabOrders:u,setGroupTabOrders:l,groupSizes:x,setGroupSizes:d,isMobile:h,hasHydratedStoredLayout:f,hydrateStoredLayout:k}}function wa({urlActiveTab:t,conversations:s,resolveConversationByTarget:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:a,hydrateStoredLayout:i,setGroupActiveTabIds:c,setFocusedGroup:u,setSearchParams:l,historyModalOpen:x,activeConv:d,isRefreshingHistory:h,ides:g,handleRefreshHistory:f,isSplitMode:b,splitTabRelative:k,numGroups:S,clearAllSplits:p}){const y=o.useRef(!1),N=o.useRef(!1),T=o.useRef(null),m=o.useRef(!1);o.useEffect(()=>{if(!t||y.current||s.length===0)return;if(!a){i();return}const j=n(t);if(!j)return;const v=r.get(j.tabKey)??0;c(w=>({...w,[v]:j.tabKey})),u(v),y.current=!0,N.current=!0,T.current!=null&&(window.clearTimeout(T.current),T.current=null),l(w=>{const R=new URLSearchParams(w);return R.delete("activeTab"),R},{replace:!0})},[t,s,n,r,a,i,c,u,l]),o.useEffect(()=>{if(!(N.current||a)&&s.length!==0){if(!t){i(),N.current=!0;return}if(y.current){N.current=!0;return}if(T.current==null)return T.current=window.setTimeout(()=>{T.current=null,!(N.current||a)&&(i(),N.current=!0)},1500),()=>{T.current!=null&&(window.clearTimeout(T.current),T.current=null)}}},[t,s.length,a,i]),o.useEffect(()=>{if(!x){m.current=!1;return}if(!d||m.current||h)return;const j=g.find(v=>v.id===d.ideId);j&&(!j.chats||j.chats.length===0)&&(m.current=!0,f())},[x,d,h,g,f]),o.useEffect(()=>{const j=v=>{if(v.ctrlKey&&v.key==="\\"){if(v.preventDefault(),b)p();else{const w=s[1];w&&k(w.tabKey,0,"right")}return}v.ctrlKey&&(v.key==="["||v.key==="]")&&b&&(v.preventDefault(),u(w=>v.key==="]"?Math.min(w+1,S-1):Math.max(w-1,0)))};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[b,s,k,S,p,u]),o.useEffect(()=>{if(!d)return;let j=null,v=0,w=-1,R=0;const A=()=>{j=null;const O=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(I=>I.offsetParent!==null);if(O.length===0){v<18&&(v+=1,j=requestAnimationFrame(A));return}let _=0;for(const I of O)I.scrollTop=I.scrollHeight,_+=I.scrollHeight;_===w?R+=1:(R=0,w=_),v+=1,!(R>=2||v>=18)&&(j=requestAnimationFrame(A))};return j=requestAnimationFrame(A),()=>{j!=null&&cancelAnimationFrame(j)}},[d==null?void 0:d.tabKey])}function _e(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return ye(t)||ge(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function St(t){return t&&(t.ideId||t.daemonId)||""}function mt(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function Na({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:a,setClearedTabs:i}){const[c,u]=o.useState(!1),[l,x]=o.useState(!1),d=o.useCallback(async b=>{try{await t("standalone","launch_ide",{ideType:b,enableCdp:!0})}catch(k){console.error("Launch failed",k)}},[t]),h=o.useCallback(async(b,k)=>{try{const S=b||(s==null?void 0:s.daemonId)||"",p=await t(S,"switch_chat",{id:k,sessionId:k,..._e(s)}),y=p==null?void 0:p.result;if((p==null?void 0:p.success)===!0||y==="switched"||y==="switched-by-title")return;y===!1||y==="not_found"?mt(r,"⚠️ Session tab not found — try refreshing history"):typeof y=="string"&&y.startsWith("error:")?mt(r,`⚠️ Switch error: ${y}`):mt(r,"⚠️ Session switch failed")}catch(S){console.error("Switch failed",S),mt(r,`❌ Switch failed: ${S.message||"connection error"}`)}},[s,t,r]),g=o.useCallback(async()=>{if(!(!s||c)){u(!0);try{const b=St(s);await t(b,"new_chat",{..._e(s)}),i(k=>({...k,[s.tabKey]:Date.now()})),a(k=>({...k,[s.tabKey]:[]}))}catch(b){console.error("New chat failed",b)}finally{u(!1)}}},[s,c,t,i,a]),f=o.useCallback(async()=>{var b;if(!(!s||l)){x(!0);try{const k=St(s),S=await t(k,"list_chats",{forceExpand:!0,..._e(s)}),p=(S==null?void 0:S.chats)||((b=S==null?void 0:S.result)==null?void 0:b.chats);S!=null&&S.success&&Array.isArray(p)&&n(s.ideId,p)}catch(k){console.error("Refresh history failed",k)}finally{x(!1)}}},[s,l,t,n]);return{isCreatingChat:c,isRefreshingHistory:l,handleLaunchIde:d,handleSwitchSession:h,handleNewChat:g,handleRefreshHistory:f}}function ka(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 Sa(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function is(t,s){const n=Object.keys(t),r=Object.keys(s);return n.length!==r.length?!1:n.every(a=>s[Number(a)]===t[Number(a)])}function ft(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[c,u]of t)!n.has(c)||u<=0||r.includes(u)||r.push(u);r.sort((c,u)=>c-u);const a={};r.forEach((c,u)=>{a[c]=u}),r.length===0&&(a[0]=0);const i=new Map;for(const[c,u]of t){if(!n.has(c)||u<=0)continue;const l=a[u];typeof l=="number"&&l>0&&i.set(c,l)}return{assignments:i,groupCount:Math.max(1,r.length),mapping:a,usedGroups:r}}function cs(t,s){const n={};for(const[r,a]of Object.entries(t)){const i=s[Number(r)];typeof i=="number"&&(n[i]=a)}return n}function Ca(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(a=>a<t)??s[0];return n[r]??0}function Ia(t,s,n){if(s.length<=1)return[];const r=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),a=r.length===s.length?r:Array(n).fill(100/n),i=a.reduce((c,u)=>c+u,0);return i>0?a.map(c=>c/i*100):Array(n).fill(100/n)}function ls(t,s){const n={};for(const[r,a]of Object.entries(t)){const i=Number(r);n[i>=s?i+1:i]=a}return n}function ds(t){return Array(t).fill(100/t)}function Ma({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:a,groupSizes:i,setGroupSizes:c,isMobile:u,visibleConversations:l,visibleTabKeys:x}){const d=o.useRef(null),h=o.useMemo(()=>ft(t,x),[t,x]),g=h.assignments,f=o.useMemo(()=>u?1:h.groupCount,[h.groupCount,u]),b=f>1,k=o.useCallback((m,j)=>{s(v=>{const w=new Map(ft(v,x).assignments);return j===0?w.delete(m):w.set(m,j),w}),r(v=>({...v,[j]:m})),n(j)},[s,x,r,n]),S=o.useCallback(m=>{s(j=>{const v=ft(j,x).assignments,w=new Map;for(const[R,A]of v)A!==m&&(A>m?w.set(R,A-1):w.set(R,A));return w}),c(j=>{if(j.length<=1)return[];const v=[...j];v.splice(m,1);const w=v.reduce((R,A)=>R+A,0);return w>0?v.map(R=>R/w*100):[]}),n(0)},[s,x,c,n]),p=o.useCallback((m,j)=>{j.preventDefault();const v=d.current;if(!v)return;const w=j.clientX,R=v.offsetWidth,A=i.length===f?[...i]:ds(f),O=I=>{const K=(I.clientX-w)/R*100,C=[...A];C[m]=Math.max(15,A[m]+K),C[m+1]=Math.max(15,A[m+1]-K),c(C)},_=()=>{document.removeEventListener("mousemove",O),document.removeEventListener("mouseup",_),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",O),document.addEventListener("mouseup",_)},[i,f,c]),y=o.useCallback((m,j,v)=>{if(f>=4)return;const w=v==="left"?j:j+1;s(R=>{const A=ft(R,x).assignments,O=new Map;for(const _ of l){const I=A.get(_.tabKey)??0,P=I>=w?I+1:I;P>0&&O.set(_.tabKey,P)}return w>0&&O.set(m,w),O}),c(R=>{const A=R.length===f?[...R]:ds(f),O=A[j]??100/f,_=Math.max(15,O/2),I=Math.max(15,O/2),P=[...A];P[j]=_,P.splice(w,0,I);const K=P.reduce((C,F)=>C+F,0);return P.map(C=>C/K*100)}),r(R=>{const A=ls(R,w);return A[w]=m,A}),a(R=>{const A=ls(R,w);return A[w]=[m],A}),n(w)},[f,s,x,l,c,r,a,n]);o.useEffect(()=>{ka(t,g)||s(g)},[t,g,s]),o.useEffect(()=>{const{mapping:m,usedGroups:j}=h;r(v=>{const w=cs(v,m);return is(v,w)?v:w}),a(v=>{const w=cs(v,m);return is(v,w)?v:w}),n(v=>{const w=u?0:Ca(v,j,m);return v===w?v:w}),c(v=>{const w=u?[]:Ia(v,j,h.groupCount);return Sa(v,w)?v:w})},[h,u,r,a,n,c]);const N=o.useMemo(()=>{const m=Array.from({length:f},()=>[]);for(const j of l){const v=g.get(j.tabKey)??0,w=Math.min(v,f-1);m[w].push(j)}return m},[l,g,f]),T=o.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:d,normalizedGroupAssignments:g,numGroups:f,isSplitMode:b,groupedConvs:N,moveTabToGroup:k,closeGroup:S,handleResizeStart:p,splitTabRelative:y,clearAllSplits:T}}function Ta({ides:t,sendDaemonCommand:s}){const n=o.useMemo(()=>t.filter(l=>l.type==="adhdev-daemon"&&l.versionMismatch),[t]),[r,a]=o.useState(!1),[i,c]=o.useState({}),u=o.useCallback(async l=>{var x,d;c(h=>({...h,[l]:"upgrading"}));try{const h=await s(l,"daemon_upgrade",{});(x=h==null?void 0:h.result)!=null&&x.upgraded||(d=h==null?void 0:h.result)!=null&&d.success?c(g=>({...g,[l]:"done"})):c(g=>({...g,[l]:"error"}))}catch{c(h=>({...h,[l]:"error"}))}},[s]);return{versionMismatchDaemons:n,versionBannerDismissed:r,setVersionBannerDismissed:a,upgradingDaemons:i,handleBannerUpgrade:u}}function rn({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:a}){const[i,c]=o.useState(!1),[u,l]=o.useState(!1),x=o.useRef(!1),d=o.useCallback(async b=>{if(!s)return;const k=b.trim();if(!k||x.current)return;const S=s.tabKey;x.current=!0,l(!0);const p=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,y={role:"user",content:k,timestamp:Date.now(),_localId:p};n(N=>({...N,[S]:[...N[S]||[],y]}));try{const N=St(s);if(!N)return;await t(N,"send_chat",{message:k,text:k,..._e(s)}),setTimeout(()=>{const T=Date.now()-6e4;n(m=>{const j=m[S];if(!j)return m;const v=j.filter(w=>w.timestamp>T);return v.length===j.length?m:{...m,[S]:v}})},6e4)}catch(N){console.error("Send failed",N),n(T=>({...T,[S]:(T[S]||[]).filter(m=>m._localId!==p)}))}finally{x.current=!1,l(!1)}},[s,t,n]),h=o.useCallback(async()=>{if(s)try{if(a){await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0});return}await t(s.ideId,"vscode_command_exec",{commandId:"adhdev.relaunchWithCdp",args:[{force:!0}]})}catch(b){console.error("Relaunch failed",b)}},[s,a,t]),g=o.useCallback(async b=>{if(s){r(k=>[...k,{ideId:s.tabKey,text:`🖱️ **${b}** clicked`,timestamp:Date.now()}]);try{const S=(s.modalButtons||[]).indexOf(b),p=b.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),y=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(p),N=St(s);if(!N)return;(await t(N,"resolve_action",{button:b,action:y?"approve":"reject",...S>=0&&{buttonIndex:S},..._e(s)})).success||r(m=>[...m,{ideId:s.tabKey,text:`⚠️ **${b}** failed — button not found`,timestamp:Date.now()}])}catch(k){console.error("[ModalButton] Error:",k),r(S=>[...S,{ideId:s.tabKey,text:`❌ **${b}** error`,timestamp:Date.now()}])}}},[s,t,r]),f=o.useCallback(async()=>{if(!(!s||i)){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,i,t]);return{isSendingChat:u,isFocusingAgent:i,handleSendChat:d,handleRelaunch:h,handleModalButton:g,handleFocusAgent:f}}function Rt(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Ea({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:a,onClearPreviewOrder:i}){const c=o.useRef(0),[u,l]=o.useState(!1),[x,d]=o.useState(null),h=o.useCallback(()=>{c.current=0,l(!1),d(null)},[]);o.useEffect(()=>(window.addEventListener("dragend",h),window.addEventListener("drop",h),()=>{window.removeEventListener("dragend",h),window.removeEventListener("drop",h)}),[h]);const g=o.useCallback(S=>{S.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,l(!0))},[]),f=o.useCallback(S=>{if(!S.dataTransfer.types.includes("text/tab-key"))return;if(S.preventDefault(),!Rt(s,n)){d("merge");return}const p=S.currentTarget.getBoundingClientRect(),y=S.clientX-p.left,N=p.width/3;y<N?d("split-left"):y>N*2?d("split-right"):d("merge")},[s,n]),b=o.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,l(!1),d(null))},[]),k=o.useCallback(S=>{c.current=0,l(!1);const p=S.dataTransfer.getData("text/tab-key"),y=p?t.some(T=>T.tabKey===p):!1,N=x;if(d(null),i(),!!p){if(S.preventDefault(),N==="split-left"&&Rt(s,n)){n==null||n(p,"split-left");return}if(N==="split-right"&&Rt(s,n)){n==null||n(p,"split-right");return}if(y){a(p);return}r==null||r(p)}},[t,x,s,n,r,a,i]);return{dragOver:u,dropAction:x,resetDragState:h,handleDragEnter:g,handleDragOver:f,handleDragLeave:b,handleDrop:k}}function Aa(t,s){const n=new Set(s.map(i=>i.tabKey)),r=t.filter(i=>n.has(i)),a=s.filter(i=>!t.includes(i.tabKey)).map(i=>i.tabKey);return[...r,...a]}function Ra({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:a}){const[i,c]=o.useState(s??null),[u,l]=o.useState(n??[]),[x,d]=o.useState(null),h=o.useRef(null),g=o.useRef(null),f=o.useRef(r),b=o.useRef(a);o.useEffect(()=>{f.current=r},[r]),o.useEffect(()=>{b.current=a},[a]),o.useEffect(()=>{s&&s!==i&&c(s)},[s,i]),o.useEffect(()=>{l(v=>{const w=Aa(v,t);return w.length===v.length&&w.every((R,A)=>R===v[A])?v:w})},[t]);const k=o.useMemo(()=>{const v=x??u;if(v.length===0)return t;const w=new Map(v.map((R,A)=>[R,A]));return[...t].sort((R,A)=>{const O=w.get(R.tabKey)??999,_=w.get(A.tabKey)??999;return O-_})},[t,x,u]);o.useEffect(()=>{var w,R;if(k.length===0){i!==null&&(c(null),(w=f.current)==null||w.call(f,null));return}if(i&&k.some(A=>A.tabKey===i))return;const v=k[0].tabKey;v!==i&&(c(v),(R=f.current)==null||R.call(f,v))},[k,i]);const S=o.useMemo(()=>k.find(v=>v.tabKey===i),[k,i]),p=o.useCallback(v=>{var w;c(v),(w=f.current)==null||w.call(f,v)},[]),y=o.useCallback((v,w,R)=>{l(A=>{var P;const O=A.filter(K=>K!==v),_=O.indexOf(w);if(_<0)return A;const I=R==="left"?_:_+1;return O.splice(I,0,v),(P=b.current)==null||P.call(b,O),O}),d(null)},[]),N=o.useCallback((v,w,R)=>{const O=(u.length>0?u:t.map(P=>P.tabKey)).filter(P=>P!==v),_=O.indexOf(w);if(_<0)return;const I=R==="left"?_:_+1;O.splice(I,0,v),h.current=O,d(O)},[u,t]),T=o.useCallback(()=>{var w;const v=h.current;v&&(l(v),(w=b.current)==null||w.call(b,v))},[]),m=o.useCallback(()=>{h.current=null,d(null)},[]),j=o.useCallback(v=>{l(w=>{var A;const R=w.filter(O=>O!==v);return R.push(v),(A=b.current)==null||A.call(b,R),R})},[]);return{activeTabId:i,activeConv:S,sortedConversations:k,previewOrderRef:h,draggingTabRef:g,selectTab:p,handleTabReorder:y,updatePreviewOrder:N,commitPreviewOrder:T,clearPreviewOrder:m,moveTabToEnd:j,setDraggingTabKey:v=>{g.current=v}}}const _a=o.memo(function({activeConv:s,clearToken:n,isCli:r,ideEntry:a,screenshotUrl:i,clearScreenshot:c,ptyBuffers:u,terminalRef:l,handleModalButton:x,handleRelaunch:d,handleSendChat:h,isSendingChat:g,handleFocusAgent:f,isFocusingAgent:b,actionLogs:k,userName:S}){const p=o.useCallback(()=>{c()},[c]);return e.jsxs(e.Fragment,{children:[e.jsx($s,{activeConv:s,onModalButton:x}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!r&&s.transport!=="acp"&&i?e.jsx(sr,{screenshotUrl:i,mode:"preview",onDismiss:p}):!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(Ft,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:d,children:"Relaunch with CDP"})]}):null}),r?e.jsx(yr,{activeConv:s,clearToken:n,ptyBuffers:u,terminalRef:l,handleSendChat:h,isSendingChat:g}):e.jsx(Bs,{activeConv:s,ideEntry:a,handleSendChat:h,isSendingChat:g,handleFocusAgent:f,isFocusingAgent:b,actionLogs:k,userName:S})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCli===s.isCli&&t.ideEntry===s.ideEntry&&t.screenshotUrl===s.screenshotUrl&&t.ptyBuffers===s.ptyBuffers&&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 La({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 _t={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 $a(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Pa(){const[t,s]=o.useState("unix"),[n,r]=o.useState("powershell"),[a,i]=o.useState(!1),c=t==="unix"?"unix":n;o.useEffect(()=>{s($a())},[]);const u=o.useCallback(()=>{navigator.clipboard.writeText(_t[c].cmd).catch(()=>{}),i(!0),setTimeout(()=>i(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="powershell"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-accent cursor-pointer group",onClick:u,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:_t[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:_t[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:a?"✓":"📋"})]}),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 Da({conversationsCount:t,isSplitMode:s,isStandalone:n,detectedIdes:r,handleLaunchIde:a}){return t===0&&!s&&r&&a?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(Pa,{}),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(i=>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:()=>a(i.type),children:[e.jsx(As,{size:14,className:"opacity-70"})," Launch ",i.name]},i.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 an="adhdev-tab-shortcuts";function Ba(){try{return JSON.parse(localStorage.getItem(an)||"{}")}catch{return{}}}function Wa({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[a,i]=o.useState(()=>Ba()),[c,u]=o.useState(null),l=o.useCallback(d=>{const h=[];return d.metaKey&&h.push(r?"⌘":"Meta"),d.ctrlKey&&h.push("Ctrl"),d.altKey&&h.push(r?"⌥":"Alt"),d.shiftKey&&h.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(d.key)?null:(h.push(d.key.length===1?d.key.toUpperCase():d.key),h.join("+"))},[r]),x=o.useCallback(d=>{i(d);try{localStorage.setItem(an,JSON.stringify(d))}catch{}},[]);return o.useEffect(()=>{if(!c)return;const d=h=>{if(h.preventDefault(),h.stopPropagation(),h.key==="Escape"){u(null);return}const g=l(h);if(!g)return;const f={...a};for(const[b,k]of Object.entries(f))k===g&&delete f[b];f[c]=g,x(f),u(null)};return window.addEventListener("keydown",d,!0),()=>window.removeEventListener("keydown",d,!0)},[c,a,x,l]),o.useEffect(()=>{const d=h=>{if(!(!h.ctrlKey&&!h.metaKey&&!h.altKey)){for(const[g,f]of Object.entries(a))if(t.includes(g)&&l(h)===f){h.preventDefault(),s(),n(g);return}}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[a,t,s,n,l]),{isMac:r,tabShortcuts:a,shortcutListening:c,setShortcutListening:u,saveShortcuts:x}}const Oa=o.memo(function({conv:s,isActive:n,isDraggedTab:r,shortcut:a,conversationKeys:i,draggingTabRef:c,onFocus:u,onSelectTab:l,onConversationActivated:x,onPreviewReorder:d,onReorderTab:h,onCommitPreviewOrder:g,onClearPreviewOrder:f,onDragStateReset:b,onDragTabKeyChange:k,onReceiveTab:S,onOpenContextMenu:p,longPressTimer:y}){const N=s.status==="generating"?"agent-tab-generating":s.status==="waiting_approval"?"agent-tab-waiting":"",T=s.connectionState==="failed"||s.connectionState==="closed",m=o.useCallback(I=>{c.current=s.tabKey,k(s.tabKey),I.dataTransfer.setData("text/tab-key",s.tabKey),I.dataTransfer.effectAllowed="move"},[s.tabKey,c,k]),j=o.useCallback(()=>{c.current=null,k(null),g(),f(),b()},[c,k,g,f,b]),v=o.useCallback(I=>{const P=c.current;if(!(!P||P===s.tabKey)&&I.dataTransfer.types.includes("text/tab-key")){I.preventDefault(),I.stopPropagation();const K=I.currentTarget.getBoundingClientRect(),C=I.clientX<K.left+K.width/2?"left":"right";d(P,s.tabKey,C)}},[s.tabKey,c,d]),w=o.useCallback(I=>{I.preventDefault(),I.stopPropagation();const P=I.dataTransfer.getData("text/tab-key");if(P&&P!==s.tabKey){const K=I.currentTarget.getBoundingClientRect(),C=I.clientX<K.left+K.width/2?"left":"right";i.includes(P)?h(P,s.tabKey,C):S&&S(P)}f()},[s.tabKey,i,h,S,f]),R=o.useCallback(I=>{I.stopPropagation(),u(),l(s.tabKey),x(s)},[s,x,u,l]),A=o.useCallback(I=>{I.preventDefault(),p(I.clientX,I.clientY,s.tabKey)},[s.tabKey,p]),O=o.useCallback(I=>{const P=I.touches[0];y.current=setTimeout(()=>{p(P.clientX,P.clientY,s.tabKey)},600)},[s.tabKey,y,p]),_=o.useCallback(()=>{y.current&&clearTimeout(y.current)},[y]);return e.jsxs("div",{"data-tabkey":s.tabKey,className:`${N} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:m,onDragEnd:j,onDragOver:v,onDrop:w,onClick:R,onContextMenu:A,onTouchStart:O,onTouchEnd:_,onTouchMove:_,style:{background:n?"var(--bg-primary)":"var(--bg-glass)",borderTop:n?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:n?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:n?"1px solid var(--border-subtle)":"1px solid transparent",opacity:r?.4:T?n?.6:.3:n?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[s.status==="generating"?e.jsx("div",{className:"tab-spinner"}):s.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):T?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400 animate-pulse",children:"○"}):s.connectionState==="connecting"||s.connectionState==="new"?e.jsx("div",{className:"tab-connecting-spinner"}):s.connectionState==="connected"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-green-400",children:"●"}):e.jsx("span",{className:"text-[8px] px-[5px] py-px text-text-muted animate-pulse",children:"○"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-bold whitespace-nowrap overflow-hidden text-ellipsis",style:{maxWidth:"10ch"},title:s.displayPrimary,children:s.displayPrimary}),e.jsx("div",{className:"text-[8px] opacity-50 flex gap-1 items-center",children:T?e.jsx("span",{className:"text-yellow-400 opacity-100",children:"Reconnecting…"}):s.connectionState==="connecting"||s.connectionState==="new"?e.jsxs("span",{className:"text-blue-400 opacity-100",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:"opacity-40",children:"·"}),e.jsxs("span",{className:"opacity-70",children:["🖥 ",s.machineName]})]})]})})]}),a&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${a}`,children:a})]})},(t,s)=>t.conv===s.conv&&t.isActive===s.isActive&&t.isDraggedTab===s.isDraggedTab&&t.shortcut===s.shortcut&&t.conversationKeys===s.conversationKeys);function Ka({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,draggingTabRef:a,onFocus:i,onSelectTab:c,onConversationActivated:u,onPreviewReorder:l,onReorderTab:x,onCommitPreviewOrder:d,onClearPreviewOrder:h,onDragStateReset:g,onDragTabKeyChange:f,onMoveTab:b,onReceiveTab:k,onHideTab:S}){const[p,y]=o.useState(null),N=o.useRef(null),T=o.useRef(null),m=o.useMemo(()=>t.map(_=>_.tabKey),[t]);ct("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(p==null?void 0:p.tabKey)||null});const{isMac:j,tabShortcuts:v,shortcutListening:w,setShortcutListening:R,saveShortcuts:A}=Wa({sortedTabKeys:t.map(_=>_.tabKey),onFocus:i,onSelectTab:c});o.useEffect(()=>{if(!p)return;const _=I=>{const P=document.querySelector("[data-pane-context-menu]");P&&P.contains(I.target)||y(null)};return window.addEventListener("mousedown",_,!0),()=>window.removeEventListener("mousedown",_,!0)},[p]),o.useEffect(()=>{const _=T.current;if(!_)return;const I=P=>{Math.abs(P.deltaY)>Math.abs(P.deltaX)&&(P.preventDefault(),_.scrollLeft+=P.deltaY)};return _.addEventListener("wheel",I,{passive:!1}),()=>_.removeEventListener("wheel",I)},[]);const O=o.useCallback((_,I,P)=>{y({x:_,y:I,tabKey:P})},[]);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center bg-bg-secondary border-b border-border-subtle shrink-0 gap-0",children:e.jsxs("div",{ref:T,className:"flex-1 flex overflow-x-auto overflow-y-visible pt-1.5 pb-0 gap-1 select-none",style:{paddingLeft:8,paddingRight:4,scrollbarWidth:"none"},children:[t.map(_=>e.jsx(Oa,{conv:_,isActive:s===_.tabKey,isDraggedTab:a.current===_.tabKey,shortcut:v[_.tabKey],conversationKeys:m,draggingTabRef:a,onFocus:i,onSelectTab:c,onConversationActivated:u,onPreviewReorder:l,onReorderTab:x,onCommitPreviewOrder:d,onClearPreviewOrder:h,onDragStateReset:g,onDragTabKeyChange:f,onReceiveTab:k,onOpenContextMenu:O,longPressTimer:N},_.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),p&&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:p.x,top:p.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(p.tabKey,"left"),y(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(p.tabKey,"right"),y(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(p.tabKey,"split-left"),y(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(p.tabKey,"split-right"),y(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:_=>{_.stopPropagation(),R(p.tabKey),y(null)},children:["⌨ ",v[p.tabKey]?`Change shortcut (${v[p.tabKey]})`:"Set shortcut"]}),v[p.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 _={...v};delete _[p.tabKey],A(_),y(null)},children:"✕ Remove shortcut"}),S&&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:()=>{S(p.tabKey),y(null)},children:"🚫 Hide from Dashboard"})]}),!b&&!S&&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:()=>R(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:_=>_.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",j?"⌘+1":"Ctrl+1",", ",j?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}function za({conversations:t,ides:s,clearedTabs:n,actionLogs:r,ptyBuffers:a,screenshotMap:i,setScreenshotMap:c,sendDaemonCommand:u,setLocalUserMessages:l,setActionLogs:x,isStandalone:d,userName:h,groupIndex:g,onFocus:f,isSplitMode:b,numGroups:k,onMoveTab:S,onReceiveTab:p,style:y,detectedIdes:N,handleLaunchIde:T,onActiveTabChange:m,initialActiveTabId:j,initialTabOrder:v,onTabOrderChange:w,onHideTab:R}){const{sendCommand:A}=Pe(),O=o.useRef(null),{activeTabId:_,activeConv:I,sortedConversations:P,draggingTabRef:K,selectTab:C,handleTabReorder:F,updatePreviewOrder:Q,commitPreviewOrder:J,clearPreviewOrder:G,moveTabToEnd:se,setDraggingTabKey:X}=Ra({conversations:t,initialActiveTabId:j,initialTabOrder:v,onActiveTabChange:m,onTabOrderChange:w}),te=rn({sendDaemonCommand:u,activeConv:I,setLocalUserMessages:l,setActionLogs:x,isStandalone:d}),{dragOver:ee,dropAction:oe,resetDragState:W,handleDragEnter:$,handleDragOver:E,handleDragLeave:L,handleDrop:D}=Ea({conversations:t,numGroups:k,onMoveTab:S,onReceiveTab:p,onOwnTabDrop:se,onClearPreviewOrder:G}),U=I&&ye(I)&&!ge(I),V=o.useMemo(()=>I?s.find(B=>B.id===I.ideId):void 0,[s,I]),re=I?i[I.ideId]:void 0,le=o.useCallback(()=>{if(!I||!(I.ideId in i))return;const B={...i};delete B[I.ideId],c(B)},[I,i,c]),ie=o.useMemo(()=>I?r.filter(B=>B.ideId===I.tabKey):[],[r,I]);ct("PaneGroup",{groupIndex:g,conversationCount:t.length,activeTabId:_,dragOver:ee});const de=o.useCallback(B=>{B.streamSource==="agent-stream"&&B.agentType&&A(B.ideId,"focus_session",{agentType:B.agentType,...B.sessionId&&{targetSessionId:B.sessionId}}).catch(()=>{})},[A]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:f,style:{...y,outline:ee?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Ka,{conversations:P,activeTabId:_,groupIndex:g,numGroups:k,draggingTabRef:K,onFocus:f,onSelectTab:C,onConversationActivated:de,onPreviewReorder:Q,onReorderTab:F,onCommitPreviewOrder:J,onClearPreviewOrder:G,onDragStateReset:W,onDragTabKeyChange:X,onMoveTab:S,onReceiveTab:p,onHideTab:R}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:$,onDragOver:E,onDragLeave:L,onDrop:D,children:[ee&&e.jsx(La,{dropAction:oe,canSplit:!!(k<4&&S)}),I?e.jsx(_a,{activeConv:I,clearToken:n[I.tabKey]||0,isCli:!!U,ideEntry:V,screenshotUrl:re,clearScreenshot:le,ptyBuffers:a,terminalRef:O,handleModalButton:te.handleModalButton,handleRelaunch:te.handleRelaunch,handleSendChat:te.handleSendChat,isSendingChat:te.isSendingChat,handleFocusAgent:te.handleFocusAgent,isFocusingAgent:te.isFocusingAgent,actionLogs:ie,userName:h}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(Da,{conversationsCount:t.length,isSplitMode:b,isStandalone:d,detectedIdes:N,handleLaunchIde:T})})]})]})}function Ha({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:a,clearedTabs:i,ides:c,actionLogs:u,ptyBuffers:l,screenshotMap:x,setScreenshotMap:d,sendDaemonCommand:h,setLocalUserMessages:g,setActionLogs:f,isStandalone:b,userName:k,setFocusedGroup:S,moveTabToGroup:p,splitTabRelative:y,closeGroup:N,handleResizeStart:T,detectedIdes:m,handleLaunchIde:j,groupActiveTabIds:v,setGroupActiveTabIds:w,groupTabOrders:R,setGroupTabOrders:A,toggleHiddenTab:O}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:a.map((_,I)=>{const P=s&&r.length===n?`${r[I]}%`:void 0;return e.jsxs(bn.Fragment,{children:[s&&I>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:K=>T(I-1,K),onDoubleClick:()=>N(I),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(za,{style:s?{flexBasis:P??`${100/n}%`,flexGrow:P?0:1,flexShrink:P?0:1}:void 0,conversations:_,clearedTabs:i,ides:c,actionLogs:u,ptyBuffers:l,screenshotMap:x,setScreenshotMap:d,sendDaemonCommand:h,setLocalUserMessages:g,setActionLogs:f,isStandalone:b,userName:k,groupIndex:I,onFocus:()=>S(I),isSplitMode:s,numGroups:n,onMoveTab:(K,C)=>{C==="left"&&I>0?p(K,I-1):C==="right"&&I<n-1?p(K,I+1):C==="split-left"&&n<4?y(K,I,"left"):C==="split-right"&&n<4&&y(K,I,"right")},onReceiveTab:K=>p(K,I),detectedIdes:I===0?m:void 0,handleLaunchIde:I===0?j:void 0,onActiveTabChange:K=>w(C=>(C[I]??null)===(K??null)?C:{...C,[I]:K}),initialActiveTabId:v[I],initialTabOrder:R[I],onTabOrderChange:K=>A(C=>{const F=C[I]||[];return F.length===K.length&&F.every((Q,J)=>Q===K[J])?C:{...C,[I]:K}}),onHideTab:O})]},I)})})}function Fa({daemons:t,upgradingDaemons:s,onUpgrade:n,onDismiss:r}){if(t.length===0)return null;const a=t[0];return e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 bg-amber-500/[0.08] border-b border-amber-500/20 text-xs text-text-secondary shrink-0 flex-wrap",children:[e.jsx("span",{className:"text-sm shrink-0 mt-0.5",children:e.jsx(Ms,{size:14,className:"text-amber-500"})}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available: ",e.jsxs("strong",{children:["v",a.version]})," → ",e.jsxs("strong",{children:["v",a.serverVersion]})]}),t.map(i=>{const c=Xe(i,{fallbackId:i.id}),u=s[i.id];return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-amber-500/[0.08] border border-amber-500/15",children:[e.jsx("span",{className:"font-medium text-text-primary",children:c}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",i.version]}),u==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):u==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):u==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>n(i.id),children:"retry"}):e.jsx("button",{className:"text-[10px] font-semibold text-amber-400 hover:text-amber-300 cursor-pointer px-1.5 py-px rounded bg-amber-500/10 border border-amber-500/20 transition-colors",onClick:()=>n(i.id),children:"Upgrade"})]},i.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:r,title:"Dismiss",children:"✕"})]})}function Ua({activeConv:t,onCancel:s,onStopNow:n,onSaveAndStop:r}){const a=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 ",a,"?"]}),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"})]})]})]})}const Lt=[{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 Va({onClose:t}){const[s,n]=o.useState(0),r=Lt[s],a=s===Lt.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:i=>{i.target===i.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:Lt.map((i,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]}),a&&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:()=>a?t():n(i=>i+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:a?"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 qa(){const{sendCommand:t}=Pe(),[s,n]=gs(),r=s.get("activeTab"),a=It(),{updateIdeChats:i,screenshotMap:c,setScreenshotMap:u}=a,l=a.ides||[],[x,d]=o.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),h=a.toasts||[],g=a.setToasts||(()=>{}),f=a.wsStatus||"connected",b=a.isConnected??!0,k=a.connectionStates||{},S=a.showReconnected||!1,{groupAssignments:p,setGroupAssignments:y,focusedGroup:N,setFocusedGroup:T,groupActiveTabIds:m,setGroupActiveTabIds:j,groupTabOrders:v,setGroupTabOrders:w,groupSizes:R,setGroupSizes:A,isMobile:O,hasHydratedStoredLayout:_,hydrateStoredLayout:I}=va(),[P,K]=o.useState(!1),[C,F]=o.useState(!1),[Q,J]=o.useState([]),[G,se]=o.useState({}),[X,te]=o.useState({});ct("Dashboard",{ideCount:l.length,toastCount:h.length,focusedGroup:N,groupCount:Object.keys(p).length,localMessageTabs:Object.keys(G).length,actionLogCount:Q.length});const ee=l.find(je=>je.type==="adhdev-daemon"),oe=(ee==null?void 0:ee.detectedIdes)||[],W=!!ee,{hiddenTabs:$,toggleTab:E}=en(),{chatIdes:L,conversations:D,visibleConversations:U,visibleTabKeys:V,resolveConversationByTarget:re}=ha({ides:l,connectionStates:k,localUserMessages:G,clearedTabs:X,hiddenTabs:$}),{containerRef:le,normalizedGroupAssignments:ie,numGroups:de,isSplitMode:B,groupedConvs:Y,moveTabToGroup:H,closeGroup:M,handleResizeStart:q,splitTabRelative:z,clearAllSplits:ne}=Ma({groupAssignments:p,setGroupAssignments:y,setFocusedGroup:T,setGroupActiveTabIds:j,setGroupTabOrders:w,groupSizes:R,setGroupSizes:A,isMobile:O,visibleConversations:U,visibleTabKeys:V}),Z=o.useMemo(()=>{var ve,Ue;const je=m[N];if(je){const dt=D.find(dn=>dn.tabKey===je);if(dt)return dt}return((ve=Y[N])==null?void 0:ve[0])||((Ue=Y[0])==null?void 0:Ue[0])},[m,N,D,Y]),{ptyBuffers:be}=tn({conversations:D,visibleConversations:U,clearedTabs:X,setClearedTabs:te,setActionLogs:J});sn({ides:l,sendDaemonCommand:t,setToasts:g,setLocalUserMessages:se,resolveConversationByTarget:re});const{isCreatingChat:ae,isRefreshingHistory:Me,handleLaunchIde:Se,handleSwitchSession:Ce,handleNewChat:Ge,handleRefreshHistory:He}=Na({sendDaemonCommand:t,activeConv:Z,updateIdeChats:i,setToasts:g,setLocalUserMessages:se,setClearedTabs:te});wa({urlActiveTab:r,conversations:D,resolveConversationByTarget:re,normalizedGroupAssignments:ie,hasHydratedStoredLayout:_,hydrateStoredLayout:I,setGroupActiveTabIds:j,setFocusedGroup:T,setSearchParams:n,historyModalOpen:P,activeConv:Z,isRefreshingHistory:Me,ides:l,handleRefreshHistory:He,isSplitMode:B,splitTabRelative:z,numGroups:de,clearAllSplits:ne});const Fe=o.useCallback(async je=>{if(!Z||!ye(Z)||ge(Z))return;const ve=Z.ideType||Z.agentType||"",Ue=Z.ideId||Z.daemonId||"";try{await t(Ue,"stop_cli",{cliType:ve,targetSessionId:Z.sessionId,mode:je})}catch(dt){console.error("Stop CLI failed:",dt)}},[Z,t]),Mt=o.useCallback(async()=>{var ve;if(!Z||!ye(Z)||ge(Z))return;if((ve=Z.resume)!=null&&ve.supported){F(!0);return}const je=Z.ideType||Z.agentType||"CLI";window.confirm(`Stop ${je}?
|
|
57
|
+
This will terminate the CLI process.`)&&await Fe("hard")},[Z,Fe]),lt=o.useCallback(()=>{!Z||!ye(Z)||ge(Z)||!Z.sessionId||window.dispatchEvent(new CustomEvent("adhdev:fit-cli-terminal",{detail:{sessionId:Z.sessionId}}))},[Z]),{versionMismatchDaemons:Je,versionBannerDismissed:Tt,setVersionBannerDismissed:on,upgradingDaemons:cn,handleBannerUpgrade:ln}=Ta({ides:l,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(jr,{wsStatus:f,showReconnected:S}),!Tt&&e.jsx(Fa,{daemons:Je,upgradingDaemons:cn,onUpgrade:ln,onDismiss:()=>on(!0)}),e.jsx(vr,{activeConv:Z,agentCount:L.length,wsStatus:f,isConnected:b,onOpenHistory:()=>K(!0),onFitCli:lt,onStopCli:Mt}),e.jsx(Ha,{containerRef:le,isSplitMode:B,numGroups:de,groupSizes:R,groupedConvs:Y,clearedTabs:X,ides:l,actionLogs:Q,ptyBuffers:be,screenshotMap:c,setScreenshotMap:u,sendDaemonCommand:t,setLocalUserMessages:se,setActionLogs:J,isStandalone:W,userName:a.userName,focusedGroup:N,setFocusedGroup:T,moveTabToGroup:H,splitTabRelative:z,closeGroup:M,handleResizeStart:q,detectedIdes:oe,handleLaunchIde:Se,groupActiveTabIds:m,setGroupActiveTabIds:j,groupTabOrders:v,setGroupTabOrders:w,toggleHiddenTab:E}),P&&Z&&e.jsx(Ks,{activeConv:Z,ides:l,isCreatingChat:ae,isRefreshingHistory:Me,onClose:()=>K(!1),onNewChat:Ge,onSwitchSession:Ce,onRefreshHistory:He}),C&&Z&&ye(Z)&&!ge(Z)&&e.jsx(Ua,{activeConv:Z,onCancel:()=>F(!1),onStopNow:async()=>{F(!1),await Fe("hard")},onSaveAndStop:async()=>{F(!1),await Fe("save")}}),e.jsx("style",{children:`
|
|
58
|
+
body { overflow: hidden; overscroll-behavior: none; }
|
|
59
|
+
`}),e.jsx(zs,{toasts:h,onDismiss:je=>g(ve=>ve.filter(Ue=>Ue.id!==je)),onClickToast:je=>{if(je.targetKey){const ve=re(je.targetKey);ve&&T(ie.get(ve.tabKey)??0)}}}),x&&e.jsx(Va,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}d(!1)}})]})}function Ya({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,onSelectTab:a}){return t?e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${n==="native"?"active":""}`,onClick:()=>a("native"),children:s}),r.map(i=>{const c=n===i.tabKey,u=i.status==="waiting_approval",l=i.status==="generating";return e.jsxs("button",{className:`ide-chat-tab ${c?"active":""}`,onClick:()=>a(i.tabKey),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:u?"#f59e0b":l?"var(--accent-primary)":"#64748b",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),i.title,u&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},i.tabKey)})]}):null}function Xa({ideName:t,workspaceName:s,connState:n,machineName:r,viewMode:a,onChangeView:i,onOpenHistory:c,headerActions:u,onBack:l}){return e.jsxs("header",{className:"ide-header",children:[e.jsxs("div",{className:"ide-header-left",children:[e.jsxs("div",{className:"ide-title",children:[e.jsx(qe,{size:16}),e.jsx("span",{className:"ide-name",children:t}),e.jsx("span",{className:"ide-name-mobile",children:"IDE"}),s&&e.jsx("span",{className:"ide-workspace",children:s}),e.jsx("span",{className:"ide-badge",children:"REMOTE"})]}),e.jsxs("div",{className:"ide-status-pill",children:[e.jsx("span",{className:`ide-dot ${n==="connected"?"online":"connecting"}`}),e.jsx("span",{className:"ide-status-text",children:n==="connected"?"Connected":n==="connecting"?"Connecting":"WS"})]}),r&&e.jsx("span",{className:"ide-machine-label",children:r})]}),e.jsxs("div",{className:"ide-header-right",children:[["chat","split","remote"].map(x=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:a===x?"1px solid var(--accent-primary)":"none",background:a===x?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:a===x?"var(--accent-primary)":void 0},onClick:()=>i(x),children:x==="chat"?e.jsx(qe,{size:14}):x==="split"?"⊞":e.jsx(Le,{size:14})},x)),e.jsx("button",{className:"btn btn-secondary btn-sm flex items-center justify-center shrink-0",onClick:c,title:"Chat History",children:e.jsx(Is,{size:14})}),u,e.jsxs("button",{className:"btn btn-primary btn-sm flex items-center justify-center shrink-0",onClick:l,children:["←",e.jsx("span",{className:"hidden md:inline ml-1",children:"Back"})]})]})]})}function Ga({toasts:t,onDismiss:s}){return t.length===0?null:e.jsx("div",{className:"ide-toasts",children:t.map(n=>e.jsx("div",{className:`ide-toast ${n.type}`,onClick:()=>s(n.id),children:n.message},n.id))})}function Ja({ideId:t,activeConv:s,historyModalOpen:n,chats:r,sendDaemonCommand:a,updateIdeChats:i,pushToast:c}){const[u,l]=o.useState(!1),[x,d]=o.useState(!1),[h,g]=o.useState(!1),f=o.useRef(!1),b=o.useCallback(async y=>{const N=y.trim();if(!(!N||!t||h||!s)){g(!0);try{await a(t,"send_chat",{message:N,text:N,waitForResponse:!0,..._e(s)})}catch(T){console.error("[IDE] Send failed:",T)}finally{g(!1)}}},[t,h,a,s]),k=o.useCallback(async()=>{var y;if(!(!t||x||!s)){d(!0);try{const N=await a(t,"list_chats",{forceExpand:!0,..._e(s)}),T=(N==null?void 0:N.chats)||((y=N==null?void 0:N.result)==null?void 0:y.chats);N!=null&&N.success&&Array.isArray(T)&&i(t,T)}catch(N){console.error("[IDE] Refresh history failed:",N),c("히스토리 새로고침에 실패했습니다.","warning")}finally{d(!1)}}},[t,x,a,s,i,c]),S=o.useCallback(async(y,N)=>{if(!(!t||!s))try{const T=await a(t,"switch_chat",{id:N,sessionId:N,..._e(s)}),m=T==null?void 0:T.result;if((T==null?void 0:T.success)===!0||m==="switched"||m==="switched-by-title")return;m===!1||m==="not_found"?c("세션 탭을 찾지 못했습니다. 히스토리를 새로고침해 보세요.","warning"):typeof m=="string"&&m.startsWith("error:")?c(`세션 전환 오류: ${m}`,"warning"):c("세션 전환에 실패했습니다.","warning")}catch(T){console.error("[IDE] Switch session failed:",T),c(`세션 전환 실패: ${(T==null?void 0:T.message)||"connection error"}`,"warning")}},[t,a,s,c]),p=o.useCallback(async()=>{if(!(!t||u||!s)){l(!0);try{await a(t,"new_chat",{..._e(s)})}catch(y){console.error("[IDE] New chat failed:",y),c("새 채팅 생성에 실패했습니다.","warning")}finally{l(!1)}}},[t,u,a,s,c]);return o.useEffect(()=>{if(!n){f.current=!1;return}f.current||x||(!r||r.length===0)&&(f.current=!0,k())},[n,r,x,k]),{isSendingChat:h,isCreatingChat:u,isRefreshingHistory:x,handleSendAgent:b,handleRefreshHistory:k,handleSwitchSession:S,handleNewChat:p}}function Za({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:a}){const[i,c]=o.useState("native"),u=o.useMemo(()=>Hs(s),[s]),l=o.useMemo(()=>{var k;if(!t)return[];const b=t.daemonId||((k=t.id)==null?void 0:k.split(":")[0])||t.id;return Fs(t,r,{machineName:t.daemonId&&u[t.daemonId]||void 0,connectionState:n[b]||"new"})},[t,r,u,n]),x=o.useMemo(()=>l.find(b=>b.streamSource==="native"),[l]),d=o.useMemo(()=>l.filter(b=>b.streamSource==="agent-stream"),[l]);o.useEffect(()=>{var b;i!=="native"&&(d.some(k=>k.tabKey===i)||c(((b=d[0])==null?void 0:b.tabKey)||"native"))},[i,d]),o.useEffect(()=>{i==="native"&&(x||d[0]&&c(d[0].tabKey))},[i,x,d]);const h=o.useMemo(()=>i==="native"&&x?x:d.find(b=>b.tabKey===i)||x||d[0],[i,x,d]),g=o.useMemo(()=>d.map(b=>({tabKey:b.tabKey,title:b.title||b.agentName||a,status:b.status})),[d,a]),f=o.useCallback(b=>{if(b)return l.find(k=>k.sessionId===b||k.ideId===b||k.tabKey===b||k.ideType===b||k.agentType===b)},[l]);return{activeChatTab:i,setActiveChatTab:c,activeConv:h,conversations:l,extensionTabs:g,hasExtensions:g.length>0,resolveConversationByTarget:f}}function Qa({doId:t,ideId:s,ideType:n,connState:r,viewMode:a,instanceId:i}){const[c,u]=o.useState(null),[l,x]=o.useState(null),d=o.useMemo(()=>{if(!s)return n;const g=s.split(":");return g.length>=3&&g[1]==="ide"?g.slice(2).join(":"):n},[s,n]);o.useEffect(()=>t?xe.onScreenshot("ide-page",(f,b)=>{if(f!==t)return;const k=new FileReader;k.onload=()=>u(k.result),k.readAsDataURL(b)}):void 0,[t]),o.useEffect(()=>{r!=="connected"&&u(null)},[r]),o.useEffect(()=>{var f;return t?((f=xe.onStatus)==null?void 0:f.call(xe,(b,k)=>{b===t&&k!=null&&k.screenshotUsage&&x(k.screenshotUsage)}))||(()=>{}):void 0},[t]),o.useEffect(()=>{u(null)},[t,s,d]),o.useEffect(()=>{const g=t?xe.get(t):null;if(!(!g||r!=="connected"))return a!=="chat"&&d?g.startScreenshots(d):g.stopScreenshots(d),()=>{g.stopScreenshots(d)}},[a,r,d,t]);const h=o.useCallback(async(g,f)=>{const b=t?xe.get(t):null;return!b||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):b.sendInput(g,f,i||d)},[t,r,i,d]);return{connScreenshot:c,screenshotUsage:l,handleRemoteAction:h}}function eo(){const[t,s]=o.useState([]),n=o.useCallback(a=>{s(i=>i.filter(c=>c.id!==a))},[]),r=o.useCallback((a,i="warning")=>{const c=Date.now()+Math.floor(Math.random()*1e3);s(u=>[...u,{id:c,message:a,type:i}]),window.setTimeout(()=>{s(u=>u.filter(l=>l.id!==c))},5e3)},[]);return{toasts:t,setToasts:s,dismissToast:n,pushToast:r}}function to({renderHeaderActions:t}={}){var de;const{id:s}=bs(),n=it(),r=It(),a=r.ides||[],i=r.updateIdeChats||(()=>{}),c=r.connectionStates||{},{sendCommand:u}=Pe(),l=o.useMemo(()=>Us(s||"").daemonId,[s]),x=o.useMemo(()=>a.find(B=>B.id===s),[a,s]),d=(x==null?void 0:x.type)||void 0,h=d?d.charAt(0).toUpperCase()+d.slice(1):"IDE",g=r.isConnected??!0,f=c[l]||(g?"connected":"new"),b=((de=r.connectionTransports)==null?void 0:de[l])||"unknown",k=o.useMemo(()=>a.find(B=>B.id===l||B.daemonId===l),[a,l]),S=k?Xe(k,{fallbackId:l}):"",p=(x==null?void 0:x.workspace)||"",[y]=gs(),N=typeof window<"u"&&window.innerWidth<=768,T=y.get("view")||(N?"chat":"split"),[m,j]=o.useState(T),[v,w]=o.useState(!1),{toasts:R,setToasts:A,dismissToast:O,pushToast:_}=eo(),[I,P]=o.useState([]),[K,C]=o.useState({}),[F,Q]=o.useState({}),{activeChatTab:J,setActiveChatTab:G,activeConv:se,conversations:X,extensionTabs:te,hasExtensions:ee,resolveConversationByTarget:oe}=Za({ideData:x,allIdes:a,connectionStates:c,localUserMessages:K,ideName:h});tn({conversations:X,visibleConversations:X,clearedTabs:F,setClearedTabs:Q,setActionLogs:P});const{connScreenshot:W,screenshotUsage:$,handleRemoteAction:E}=Qa({doId:l,ideId:s||"",ideType:d,connState:f,viewMode:m,instanceId:x==null?void 0:x.instanceId}),L=!!a.find(B=>B.type==="adhdev-daemon"),D=rn({sendDaemonCommand:u,activeConv:se,setLocalUserMessages:C,setActionLogs:P,isStandalone:L}),{isCreatingChat:U,isRefreshingHistory:V,handleRefreshHistory:re,handleSwitchSession:le,handleNewChat:ie}=Ja({ideId:s||"",activeConv:se,historyModalOpen:v,chats:x==null?void 0:x.chats,sendDaemonCommand:u,updateIdeChats:i,pushToast:_});return sn({ides:a,sendDaemonCommand:u,setToasts:A,setLocalUserMessages:C,resolveConversationByTarget:oe}),s?se?e.jsxs("div",{className:"ide-page",children:[e.jsx(Xa,{ideName:h,workspaceName:p,connState:f,machineName:S,viewMode:m,onChangeView:j,onOpenHistory:()=>w(!0),headerActions:t==null?void 0:t({daemonId:l,ideInstanceId:s||""}),onBack:()=>n(-1)}),e.jsxs("div",{className:"ide-content",children:[e.jsxs("div",{className:`ide-chat-panel ${m==="chat"?"full":""} ${m==="remote"?"hidden":""}`,children:[e.jsx(Ya,{hasExtensions:ee,ideName:h,activeChatTab:J,extensionTabs:te,onSelectTab:B=>{G(B);const Y=X.find(H=>H.tabKey===B);(Y==null?void 0:Y.streamSource)==="agent-stream"&&u(Y.ideId,"focus_session",{agentType:Y.agentType,...Y.sessionId&&{targetSessionId:Y.sessionId}}).catch(()=>{})}}),e.jsx($s,{activeConv:se,onModalButton:D.handleModalButton}),e.jsx(Bs,{activeConv:se,ideEntry:a.find(B=>B.id===se.ideId),handleSendChat:D.handleSendChat,isSendingChat:D.isSendingChat,handleFocusAgent:D.handleFocusAgent,isFocusingAgent:D.isFocusingAgent,actionLogs:I,userName:r.userName})]}),e.jsx("div",{className:`ide-remote-panel ${m==="remote"?"full":""} ${m==="chat"?"hidden":""}`,children:e.jsx(tr,{addLog:()=>{},connState:f,connScreenshot:W,screenshotUsage:$,transportType:b,onAction:E})})]}),e.jsx(Ga,{toasts:R,onDismiss:O}),v&&e.jsx(Ks,{activeConv:se,ides:a,isCreatingChat:U,isRefreshingHistory:V,onClose:()=>w(!1),onNewChat:ie,onSwitchSession:le,onRefreshHistory:re})]}):e.jsx("div",{className:"ide-empty",children:"IDE session not available"}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function so({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:a}){const[i,c]=o.useState([]),[u,l]=o.useState(null),[x,d]=o.useState(null),[h,g]=o.useState(!1),[f,b]=o.useState(!1),[k,S]=o.useState(!1),[p,y]=o.useState([]),[N,T]=o.useState([]),[m,j]=o.useState(null),[v,w]=o.useState(!1),[R,A]=o.useState(""),O=o.useRef(null),_=o.useCallback(E=>{O.current=E},[]),I=o.useCallback((E,L,D=!1)=>{c(U=>[...U.slice(-100),{timestamp:Date.now(),level:E,message:L}]),setTimeout(()=>{var U;return(U=a.current)==null?void 0:U.scrollIntoView({behavior:"smooth"})},100),D&&$e.showToast(L,E==="error"||E==="warn"?"warning":"success")},[a]),P=o.useCallback(async(E,L)=>{var D;if(!t||u)return!1;l(E),I("info",`Launching ${he(E)}${L!=null&&L.workspace?` in ${L.workspace}`:""}...`);try{const U={ideType:E,enableCdp:!0};(D=L==null?void 0:L.workspace)!=null&&D.trim()?U.workspace=L.workspace.trim():L!=null&&L.useDefaultWorkspace&&(U.useDefaultWorkspace=!0);const V=await n(t,"launch_ide",U);return I(V!=null&&V.success?"info":"error",V!=null&&V.success?`${he(E)} launched`:`Failed: ${V==null?void 0:V.error}`,!0),!!(V!=null&&V.success)}catch(U){return I("error",`Launch error: ${U.message}`,!0),!1}finally{l(null)}},[t,u,I,n]),K=o.useCallback(async E=>{if(!t)return{success:!1};const{cliType:L,dir:D,workspaceId:U,useDefaultWorkspace:V,useHome:re,argsStr:le,model:ie}=E;if(!L)return I("warn","Select a CLI or ACP provider first",!0),{success:!1};const de=le?le.split(/\s+/).filter(Boolean):void 0,B=(D==null?void 0:D.trim())||(U?"(saved id)":V?"(default workspace)":re?"(home)":"");I("info",`Launching ${L}${B?` in ${B}`:""}${ie?` (model: ${ie})`:""}...`),d(L);try{const Y={cliType:L,cliArgs:de,initialModel:ie||void 0};D!=null&&D.trim()?Y.dir=D.trim():U?Y.workspaceId=U:V?Y.useDefaultWorkspace=!0:re&&(Y.useHome=!0);const H=await n(t,"launch_cli",Y),M=(H==null?void 0:H.result)||H;return H!=null&&H.success?(I("info",`${L} launched`,!0),(M==null?void 0:M.launchSource)==="home"?I("info","📂 Running in home directory (explicit choice)"):(M==null?void 0:M.launchSource)==="defaultWorkspace"&&I("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:M==null?void 0:M.sessionId}):(I("error",`Failed: ${(H==null?void 0:H.error)||(M==null?void 0:M.error)}`,!0),(H==null?void 0:H.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&j({cliType:L,argsStr:le,model:ie}),{success:!1,sessionId:M==null?void 0:M.sessionId})}catch(Y){return I("error",`Launch error: ${Y.message}`,!0),{success:!1}}finally{d(null)}},[t,I,n]),C=o.useCallback(async(E,L,D,U)=>t?E?L.trim()?K({cliType:E,dir:L,argsStr:D,model:U}):(j({cliType:E,argsStr:D,model:U}),{success:!1}):(I("warn","Select a provider",!0),{success:!1}):{success:!1},[t,I,K]),F=o.useCallback(async(E,L,D)=>{if(t&&window.confirm(`Stop ${E}?
|
|
60
|
+
This will terminate the process.`))try{const U=await n(t,"stop_cli",{cliType:E,dir:L,targetSessionId:D});U!=null&&U.success?I("info",`${E} stopped`,!0):I("error",`Stop failed: ${(U==null?void 0:U.error)||"Unknown error"}`,!0)}catch(U){I("error",`Stop failed: ${U.message}`,!0)}},[t,I,n]),Q=o.useCallback(async E=>{try{await n(E.daemonId,"restart_ide",{ideType:E.type}),I("info",`${he(E.type)} restart initiated`,!0)}catch(L){I("error",`Restart failed: ${L.message}`,!0)}},[I,n]),J=o.useCallback(async E=>{if(window.confirm(`Stop ${he(E.type)}?
|
|
61
|
+
This will disconnect CDP and optionally kill the process.`))try{const L=await n(E.daemonId,"stop_ide",{ideType:E.type,killProcess:!0});L!=null&&L.success?I("info",`${he(E.type)} stopped`,!0):I("error",`Stop failed: ${(L==null?void 0:L.error)||"Unknown error"}`,!0)}catch(L){I("error",`Stop failed: ${L.message}`,!0)}},[I,n]),G=o.useCallback(async()=>{if(t)try{const E=await n(t,"detect_ides",{});I("info",`Found ${((E==null?void 0:E.result)||[]).length} IDE(s)`,!0)}catch(E){I("error",`Detection failed: ${E.message}`,!0)}},[t,I,n]),se=o.useCallback(async()=>{if(t){g(!0);try{const E=await n(t,"get_recent_workspaces",{});E!=null&&E.success&&Array.isArray(E==null?void 0:E.result)&&T(E.result)}catch(E){I("error",`Failed: ${E.message}`)}finally{g(!1)}}},[t,I,n]),X=o.useCallback(async E=>{if(!(!t||!E.trim())){b(!0);try{const L=await n(t,"workspace_add",{path:E.trim()});L!=null&&L.success?I("info",`Workspace added: ${E.trim()}`):I("error",(L==null?void 0:L.error)||"workspace_add failed")}catch(L){I("error",L.message)}finally{b(!1)}return!0}},[t,I,n]),te=o.useCallback(async E=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){b(!0);try{const L=await n(t,"workspace_remove",{id:E});L!=null&&L.success?I("info","Workspace removed",!0):I("error",(L==null?void 0:L.error)||"workspace_remove failed",!0)}catch(L){I("error",L.message,!0)}finally{b(!1)}}},[t,I,n]),ee=o.useCallback(async E=>{var L;if(t){b(!0);try{const D=await n(t,"workspace_set_default",E===null?{clear:!0}:{id:E});if(D!=null&&D.success){I("info",E?"Default workspace updated":"Default workspace cleared",!0);const U=typeof D.defaultWorkspacePath=="string"?D.defaultWorkspacePath:"";U&&((L=O.current)==null||L.call(O,U))}else I("error",(D==null?void 0:D.error)||"workspace_set_default failed",!0)}catch(D){I("error",D.message,!0)}finally{b(!1)}}},[t,I,n]),oe=o.useCallback(async E=>{var D;if(!t||!E.trim())return;const L=E.trim();b(!0);try{const U=await n(t,"workspace_set_default",{path:L});U!=null&&U.success?(I("info","Default workspace set from history"),(D=O.current)==null||D.call(O,L)):I("error",(U==null?void 0:U.error)||"Could not set default (path missing on disk?)")}catch(U){I("error",U.message)}finally{b(!1)}},[t,I,n]),W=o.useCallback(async()=>{var E;if(t){S(!0);try{const L=await n(t,"get_cli_history",{}),D=(L==null?void 0:L.history)??((E=L==null?void 0:L.result)==null?void 0:E.history);L!=null&&L.success&&Array.isArray(D)&&y(D)}catch{}S(!1)}},[t,n]),$=o.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:R}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:R})}catch(E){I("warn",`Live nickname updated, but account sync failed: ${E.message}`)}I("info",`Nickname set to "${R||"(cleared)"}"`),w(!1)}catch(E){I("error",`Failed: ${E.message}`)}},[t,R,s,I,r,n]);return{logs:i,launchingIde:u,launchingAgentType:x,loadingWorkspaces:h,workspaceBusy:f,loadingHistory:k,cliHistory:p,recentWorkspaces:N,launchPick:m,setLaunchPick:j,editingNickname:v,setEditingNickname:w,nicknameInput:R,setNicknameInput:A,addLog:I,handleLaunchIde:P,runLaunchCliCore:K,handleLaunchCli:C,handleStopCli:F,handleRestartIde:Q,handleStopIde:J,handleDetectIdes:G,handleLoadRecentWorkspaces:se,handleWorkspaceAdd:X,handleWorkspaceRemove:te,handleWorkspaceSetDefault:ee,handleWorkspaceResumePath:oe,loadCliHistory:W,handleSaveNickname:$,setOnDefaultWorkspaceChanged:_}}function no(t){const s=Math.floor((Date.now()-t)/1e3);return s<45?"just now":s<3600?`${Math.floor(s/60)}m ago`:s<86400?`${Math.floor(s/3600)}h ago`:`${Math.floor(s/86400)}d ago`}function ro({machine:t,ideSessions:s,cliSessions:n,acpSessions:r,actions:a,isDashboardHidden:i,onToggleDashboardVisibility:c}){const{workspaceBusy:u,handleWorkspaceAdd:l,handleWorkspaceRemove:x,handleWorkspaceSetDefault:d}=a,[h,g]=o.useState(""),f=t.availableMem??t.freeMem,b=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-f)/t.totalMem*100))):0,k=t.loadavg[0]||0,S=[...t.workspaceActivity||[]].sort((y,N)=>N.lastUsedAt-y.lastUsedAt).slice(0,5),p=[...s.map(y=>({id:y.id,label:`IDE · ${y.type}`,workspace:y.workspace||""})),...n.map(y=>({id:y.id,label:`CLI · ${y.cliName}`,workspace:y.workspace||""})),...r.map(y=>({id:y.id,label:`ACP · ${y.acpName}`,workspace:y.workspace||""}))].filter(y=>i==null?void 0:i(y.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(ut,{icon:e.jsx(Es,{size:16}),label:"Uptime",value:ir(t.uptime)}),e.jsx(ut,{icon:e.jsx(Le,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(ut,{icon:e.jsx(Ut,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(ut,{icon:e.jsx(Rs,{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(Jt,{value:Math.min(Math.round(k/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${k.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Jt,{value:b,max:100,label:"Memory",color:"#3b82f6",detail:`${Qt(t.totalMem-f)} / ${Qt(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(Pt,{size:14})," Workspaces"]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center mb-3",children:[e.jsx("span",{className:"text-[10px] text-text-muted",children:"Default:"}),e.jsxs("select",{className:"text-xs bg-bg-primary border border-border-subtle rounded-lg px-2 py-1 max-w-[min(100%,420px)]",disabled:u,value:t.defaultWorkspaceId||"",onChange:y=>void d(y.target.value===""?null:y.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(y=>e.jsx("option",{value:y.id,children:y.label||y.path},y.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:h,disabled:u,onChange:y=>g(y.target.value),onKeyDown:y=>y.key==="Enter"&&void(async()=>{await l(h)&&g("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:u,onClick:async()=>{await l(h)&&g("")},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(y=>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:[y.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:Bt(y.path,y.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:y.path,children:y.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:u,onClick:()=>void x(y.id),children:"Remove"})]},y.id))}),S.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-[10px] text-text-muted uppercase tracking-wide font-semibold mb-2",children:"Recent activity"}),e.jsx("div",{className:"space-y-1.5",children:S.map(y=>e.jsxs("div",{className:"flex items-center gap-2 text-[11px] rounded-lg border border-border-subtle bg-bg-primary px-2.5 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-text-primary truncate",children:Bt(y.path)}),e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:y.path,children:y.path})]}),e.jsxs("span",{className:"text-[10px] text-text-muted shrink-0",children:[y.kind?`${y.kind} · `:"",no(y.lastUsedAt)]})]},`${y.path}:${y.lastUsedAt}`))})]})]}),p.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:p.map(y=>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:y.label}),y.workspace&&e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:y.workspace,children:y.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(y.id),children:"Show"})]},y.id))})]})]})}function ao(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const oo={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 $t({category:t,machine:s,machineId:n,providers:r,managedEntries:a,getIcon:i,actions:c,sendDaemonCommand:u,isDashboardHidden:l,onToggleDashboardVisibility:x}){const d=it(),{handleLaunchIde:h,handleLaunchCli:g,handleStopCli:f,handleRestartIde:b,handleStopIde:k,handleDetectIdes:S,cliHistory:p,loadingHistory:y,loadCliHistory:N,launchingIde:T,launchingAgentType:m}=c,[j,v]=o.useState(null),w=o.useCallback(M=>{M&&d({pathname:"/",search:`?activeTab=${encodeURIComponent(M)}`})},[d]),R=oo[t],A=t==="ide",O=t==="acp",_=r.filter(M=>M.category===t),I=new Map(_.map(M=>[M.type,M.displayName||M.type])),[P,K]=o.useState(""),[C,F]=o.useState(""),[Q,J]=o.useState(""),[G,se]=o.useState(s.defaultWorkspaceId||""),[X,te]=o.useState(""),[ee,oe]=o.useState([]),W=ee.filter(M=>!a.some(q=>q.type===M&&me(q.status)!=="stopped")),$=o.useRef({});o.useEffect(()=>{!P&&_.length>0&&K(_[0].type)},[P,_.length]),o.useEffect(()=>{s.defaultWorkspaceId&&!G&&se(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const E=(()=>{if(G==="__custom__")return X.trim();if(!G)return"";const M=(s.workspaces||[]).find(q=>q.id===G);return(M==null?void 0:M.path)||""})(),L=o.useCallback(M=>{const q=$.current[M];q&&(clearTimeout(q),delete $.current[M]),oe(z=>z.filter(ne=>ne!==M))},[]),D=o.useCallback(M=>{if(!M)return;oe(z=>z.includes(M)?z:[...z,M]);const q=$.current[M];q&&clearTimeout(q),$.current[M]=setTimeout(()=>{oe(z=>z.filter(ne=>ne!==M)),delete $.current[M]},2e4)},[]);o.useEffect(()=>{for(const M of a)me(M.status)!=="stopped"&&L(M.type)},[a,L]),o.useEffect(()=>()=>{Object.values($.current).forEach(clearTimeout),$.current={}},[]);const[U,V]=o.useState({}),[re,le]=o.useState(null);o.useEffect(()=>{if(!A||!n||!u)return;(async()=>{try{const q=await u(n,"get_ide_extensions",{}),z=(q==null?void 0:q.result)||q;z!=null&&z.success&&(z!=null&&z.ideExtensions)&&V(z.ideExtensions)}catch{}})()},[A,n,u]);const ie=M=>A?he(M.type):t==="cli"?M.cliName:M.acpName,de=A?s.detectedIdes||[]:[],B=()=>{(async()=>{if(A){await h(P,E?{workspace:E}:void 0)&&D(P);return}const M=await g(P,E,C||void 0,O&&Q||void 0);M.success&&(D(P),M.sessionId&&w(M.sessionId))})()},Y=M=>{A?k(M):f(M.type,M.workspace,M.id)},H=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:G,onChange:M=>{se(M.target.value),M.target.value!=="__custom__"&&te("")},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?"⭐ ":"",Bt(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…"})]})}),G==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:X,onChange:M=>te(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:G==="__custom__"?E?e.jsx("span",{className:"font-mono truncate block",title:E,children:E}):"Enter an absolute path to launch there.":E?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:G===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:E,children:E})]}):"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 ${R.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",R.label]}),H,A?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[de.map(M=>{const q=a.find(be=>(be.type||"").toLowerCase()===(M.type||"").toLowerCase()&&me(be.status)!=="stopped"),z=M.running||!!q,ne=!!q&&q.cdpConnected,Z=ee.includes(M.type||M.id||"");return e.jsxs("button",{onClick:()=>{if(ne&&q){d(`/ide/${q.id}`);return}Z||(async()=>await h(M.type||M.id||"",E?{workspace:E}:void 0)&&D(M.type||M.id||""))()},disabled:!!T||Z,className:`machine-btn-primary flex items-center gap-1.5 ${z?"!border-green-500/30":""}`,style:{opacity:T&&T!==M.type?.4:1},children:[e.jsx("span",{children:i(M.type)}),z&&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)]"}),Z?`⏳ Waiting for ${M.name||he(M.type)}...`:ne?`Open ${M.name||he(M.type)}`:T===M.type?"⏳ Launching...":`▶ ${M.name||he(M.type)}`,z&&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:S,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(Pn,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:P,onChange:M=>K(M.target.value),className:"machine-input",children:_.length>0?_.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"]})}),O&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:Q,onChange:M=>J(M.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:C,onChange:M=>F(M.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:B,disabled:!!m,className:"machine-btn-primary",children:m===P?"⏳ Launching...":"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",a.length+ee.filter(M=>!a.some(q=>q.type===M&&me(q.status)!=="stopped")).length,")"]}),a.length===0&&W.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 ",R.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[W.map(M=>e.jsx("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-amber-500/20",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:i(M)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:A?he(M):I.get(M)||M}),e.jsx("div",{className:"text-[11px] text-text-muted",children:m===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 bg-amber-500/[0.08] text-amber-400",children:"starting"})]})},`pending:${M}`)),a.map(M=>{const q=A?M:null,z=O?M:null,ne=!A&&!O?M:null,Z=me(M.status),be=(l==null?void 0:l(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:i(M.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ie(M),(q==null?void 0:q.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",q.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:M.workspace||"—"}),(z==null?void 0:z.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",z.currentModel]}),(z==null?void 0:z.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",z.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 ae;(ae=navigator.clipboard)==null||ae.writeText(`adhdev attach ${ne.runtimeKey}`),v(ne.runtimeKey||null),window.setTimeout(()=>{v(Me=>Me===ne.runtimeKey?null:Me)},1200)},children:j===ne.runtimeKey?"Copied":"Copy"})]}),ne.runtimeWriteOwner&&e.jsx("span",{className:ne.runtimeWriteOwner.ownerType==="user"?"text-amber-500":"text-violet-400",children:ao(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 ${Z==="stopped"?"bg-red-500/[0.08] text-red-500":Z==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:Z}),A&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>d(`/ide/${M.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(Le,{size:13})," Control"]}),e.jsx("button",{onClick:()=>b(M),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),O&&e.jsx("button",{onClick:()=>d(`/ide/${M.id}`),className:"machine-btn",title:"View chat",children:e.jsx(qe,{size:14})}),ne&&Z!=="stopped"&&e.jsxs("button",{onClick:()=>w(M.id),className:"machine-btn flex items-center gap-1",title:"Open terminal in dashboard",children:[e.jsx(Le,{size:13})," Open"]}),Z==="stopped"?e.jsx("button",{onClick:()=>{(async()=>{if(A){await h(M.type,M.workspace?{workspace:M.workspace}:void 0)&&D(M.type);return}const ae=await g(M.type,M.workspace);ae.success&&(D(M.type),ae.sessionId&&w(ae.sessionId))})()},disabled:ee.includes(M.type),className:"machine-btn text-green-500 border-green-500/30",children:ee.includes(M.type)?"⏳":"▶"}):e.jsx("button",{onClick:()=>Y(M),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),q&&q.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:q.aiAgents.map(ae=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${Ps(ae.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[ae.name," · ",me(ae.status)]},ae.id))}),q&&(U[q.type]||[]).length>0&&u&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(U[q.type]||[]).map(ae=>e.jsxs("button",{disabled:re===`${q.type}.${ae.type}`,onClick:async()=>{const Me=`${q.type}.${ae.type}`;le(Me);try{await u(n,"set_ide_extension",{ideType:q.type,extensionType:ae.type,enabled:!ae.enabled}),V(Se=>({...Se,[q.type]:(Se[q.type]||[]).map(Ce=>Ce.type===ae.type?{...Ce,enabled:!Ce.enabled}:Ce)}))}catch(Se){console.error("Extension toggle failed:",Se)}finally{le(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 ${ae.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 ${ae.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),ae.name,e.jsx("span",{className:"text-[9px] font-normal",children:ae.enabled?"ON":"OFF"})]},ae.type))})]})]},M.id)})]}),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"History"}),e.jsx("button",{onClick:N,disabled:y,className:"machine-btn",children:y?"⏳":"↻ Load"})]}),(()=>{const M=new Set(_.map(z=>z.type)),q=p.filter(z=>(z.category||"cli")!==t?!1:t==="ide"?!0:M.has(z.cliType));return q.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:q.map((z,ne)=>{var Z,be;return e.jsxs("div",{onClick:()=>{K(z.cliType),(z.workspace||z.dir)&&(se("__custom__"),te(z.workspace||z.dir)),F((z.cliArgs||[]).join(" ")),J(z.model||""),A&&(async()=>await h(z.cliType,z.workspace?{workspace:z.workspace}:void 0)&&D(z.cliType))()},className:"flex justify-between items-center px-2.5 py-1.5 rounded-md cursor-pointer bg-bg-glass border border-border-subtle text-xs transition-colors duration-150 hover:bg-bg-glass-hover",children:[e.jsxs("div",{className:"flex gap-1.5 items-center text-text-secondary",children:[e.jsx("span",{children:i(z.cliType)}),e.jsx("span",{children:((Z=z.workspace||z.dir)==null?void 0:Z.split("/").filter(Boolean).pop())||z.cliType||"root"}),z.model&&e.jsxs("span",{className:"text-cyan-500 text-[10px]",children:["model=",z.model]}),z.newWindow&&e.jsx("span",{className:"text-text-muted text-[10px]",children:"new window"}),((be=z.cliArgs)==null?void 0:be.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:z.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:z.timestamp?new Date(z.timestamp).toLocaleDateString():""})]},ne)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",R.label," launch history yet."]})})()]})]})}const us=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],io=[{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 co({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[a,i]=o.useState("config"),[c,u]=o.useState("codex-cli"),[l,x]=o.useState([]),[d,h]=o.useState(""),[g,f]=o.useState([]),[b,k]=o.useState(""),S=o.useRef(null),p=o.useRef(null),y=w=>{x(R=>R.includes(w)?R.filter(A=>A!==w):[...R,w])},N=()=>x([...us]),T=()=>x([]);o.useEffect(()=>{var w;(w=S.current)==null||w.scrollIntoView({behavior:"smooth"})},[g]),o.useEffect(()=>()=>{p.current&&clearInterval(p.current)},[]);const m=o.useCallback(()=>{p.current&&clearInterval(p.current),p.current=setInterval(async()=>{try{const w=await n(t,"provider_auto_fix_status",{providerType:s.type});(w==null?void 0:w.running)===!1&&a==="running"&&(i("done"),f(R=>[...R,`
|
|
62
|
+
✅ Auto-fix completed!`]),p.current&&clearInterval(p.current))}catch{}},3e3)},[t,s.type,n,a]),j=async()=>{if(l.length!==0){i("running"),f(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${l.join(", ")}`,d?`💬 Comment: ${d}`:"",""]),k("");try{const w=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:c,...d?{comment:d}:{}});w!=null&&w.success&&(w!=null&&w.started||w!=null&&w.running)?(f(R=>[...R,"✅ Agent started. Monitoring progress..."]),m()):(i("error"),k((w==null?void 0:w.error)||"Failed to start auto-fix"))}catch(w){i("error"),k((w==null?void 0:w.message)||"Connection failed")}}},v=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),f(w=>[...w,`
|
|
63
|
+
⚠️ Auto-fix cancelled.`]),i("done"),p.current&&clearInterval(p.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:r,children:e.jsxs("div",{className:"w-full max-w-[560px] max-h-[85vh] overflow-hidden rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick: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:[a==="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:io.map(w=>e.jsxs("button",{onClick:()=>u(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:N,className:"text-[10px] text-violet-400 hover:text-violet-300",children:"All"}),e.jsx("span",{className:"text-[10px] text-text-muted",children:"|"}),e.jsx("button",{onClick:T,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:us.map(w=>e.jsxs("button",{onClick:()=>y(w),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(w)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:l.includes(w)?"rgba(139,92,246,0.08)":"transparent",color:l.includes(w)?"#a78bfa":"var(--text-secondary)"},children:[l.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:d,onChange:w=>h(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"})]})]}),(a==="running"||a==="done"||a==="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:[g.map((w,R)=>e.jsx("div",{className:w.startsWith("✅")?"text-green-400":w.startsWith("❌")||w.startsWith("⚠")?"text-amber-400":"",children:w},R)),a==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:S})]}),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:[a==="config"&&l.length>0&&`${l.length} script(s) selected`,a==="running"&&"Agent is generating...",a==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[a==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:j,disabled:l.length===0,className:"machine-btn",style:{background:l.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:l.length>0?"rgba(139,92,246,0.4)":void 0,color:l.length>0?"#a78bfa":void 0,opacity:l.length===0?.4:1},children:"🚀 Start Fix"})]}),a==="running"&&e.jsx("button",{onClick:v,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(a==="done"||a==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{i("config"),f([]),k("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function lo({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:a}){var m;const i=s.filter(j=>j.category==="ide"),[c,u]=o.useState(((m=i[0])==null?void 0:m.type)||""),[l,x]=o.useState(""),[d,h]=o.useState(""),[g,f]=o.useState(!1),[b,k]=o.useState(""),[S,p]=o.useState(!1),y=j=>{const v=j.toLowerCase().replace(/[^a-z0-9-]/g,"");x(v),(!d||d===N(l))&&h(N(v))},N=j=>j.split("-").map(v=>v.charAt(0).toUpperCase()+v.slice(1)).join(" "),T=async()=>{if(!(!l||!d||!c)){f(!0),k("");try{const j=await n(t,"provider_clone",{type:l,name:d,category:"ide",location:"user",cloneFrom:c});j!=null&&j.success||j!=null&&j.created?(p(!0),a==null||a(l)):k((j==null?void 0:j.error)||"Failed to create provider")}catch(j){k((j==null?void 0:j.message)||"Connection failed")}f(!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:j=>j.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:S?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"text-3xl mb-2",children:"🎉"}),e.jsx("h3",{className:"text-[14px] font-semibold text-text-primary",children:"Provider Created!"}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:[e.jsx("code",{className:"text-violet-400",children:l})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",l,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",l]})," or use Auto-Fix to implement scripts."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Base Provider"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:i.map(j=>e.jsxs("button",{onClick:()=>u(j.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===j.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:c===j.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:j.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===j.type?"#a78bfa":"var(--text-secondary)"},children:j.displayName})]},j.type))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Provider Type (ID)"}),e.jsx("input",{value:l,onChange:j=>y(j.target.value),placeholder:"my-cursor, custom-windsurf...",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"}),e.jsxs("p",{className:"text-[10px] text-text-muted mt-1",children:["Lowercase, alphanumeric + hyphens only. Will be created at ",e.jsxs("code",{className:"text-violet-400",children:["~/.adhdev/providers/",l||"...","/"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Display Name"}),e.jsx("input",{value:d,onChange:j=>h(j.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:S?e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:T,disabled:!l||!d||g,className:"machine-btn",style:{background:l&&d?"rgba(34,197,94,0.12)":void 0,borderColor:l&&d?"rgba(34,197,94,0.3)":void 0,color:l&&d?"#86efac":void 0,opacity:!l||!d||g?.4:1},children:g?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function uo({machineId:t,providers:s,sendDaemonCommand:n}){const[r,a]=o.useState([]),[i,c]=o.useState(!1),[u,l]=o.useState(null),[x,d]=o.useState("all"),[h,g]=o.useState(null),[f,b]=o.useState(!1),k=o.useCallback(async()=>{var p;if(t){c(!0);try{const y=await n(t,"get_provider_settings",{}),N=(y==null?void 0:y.result)||y;if(y!=null&&y.success&&(N!=null&&N.settings)){const T=[];for(const[m,j]of Object.entries(N.settings)){const v=s.find(w=>w.type===m);T.push({type:m,displayName:(v==null?void 0:v.displayName)||m,icon:(v==null?void 0:v.icon)||"",category:(v==null?void 0:v.category)||"unknown",schema:j,values:((p=N.values)==null?void 0:p[m])||{}})}T.sort((m,j)=>m.category.localeCompare(j.category)||m.displayName.localeCompare(j.displayName)),a(T)}}catch{}c(!1)}},[t,s,n]);o.useEffect(()=>{r.length===0&&k()},[]);const S=async(p,y,N)=>{l(`${p}.${y}`),a(T=>T.map(m=>m.type===p?{...m,values:{...m.values,[y]:N}}:m));try{const T=await n(t,"set_provider_setting",{providerType:p,key:y,value:N});T!=null&&T.success||k()}catch{k()}l(null)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Filter"}),["all","acp","cli","ide","extension"].map(p=>e.jsx("button",{onClick:()=>d(p),className:`machine-btn text-[10px] px-2 py-0.5 ${x===p?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:p.toUpperCase()},p))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>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:k,disabled:i,className:"machine-btn",children:i?"⏳ Loading...":"↻ Refresh"})]})]}),x!=="all"&&r.filter(p=>p.category===x).length>1&&(()=>{const p=r.filter(m=>m.category===x),y=new Map;for(const m of p)for(const j of m.schema){if(j.type!=="boolean")continue;const v=y.get(j.key),w=!!(m.values[j.key]??j.default);v?(v.onCount+=w?1:0,v.total+=1):y.set(j.key,{label:j.label||j.key,onCount:w?1:0,total:1})}const N=[...y.entries()].filter(([,m])=>m.total===p.length);if(N.length===0)return null;const T=async(m,j)=>{for(const v of p)await S(v.type,m,j)};return e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-500/[0.04] border border-violet-500/10 mb-4",children:[e.jsxs("div",{className:"text-[10px] text-violet-400 font-semibold uppercase tracking-wider mb-2",children:["Bulk — Apply to all ",x.toUpperCase()," providers (",p.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:N.map(([m,j])=>{const v=j.onCount===j.total,w=j.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:j.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",j.onCount,"/",j.total,")"]}),e.jsx("button",{onClick:()=>void T(m,!0),disabled:v,className:`machine-btn text-[9px] px-1.5 py-px ${v?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void T(m,!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"})]},m)})})]})})(),i&&r.length===0?e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading provider settings..."}):e.jsx("div",{className:"flex flex-col gap-2",children:r.filter(p=>x==="all"||p.category===x).map(p=>e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-lg",children:p.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:p.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:p.category==="acp"?"rgba(139,92,246,0.08)":p.category==="cli"?"rgba(59,130,246,0.08)":p.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:p.category==="acp"?"#a78bfa":p.category==="cli"?"#60a5fa":p.category==="ide"?"#86efac":"#fbbf24"},children:p.category}),p.category==="ide"&&e.jsx("button",{onClick:()=>g(s.find(y=>y.type===p.type)||{type:p.type,displayName:p.displayName,icon:p.icon,category:p.category}),className:"ml-auto machine-btn text-[9px] px-2 py-0.5 bg-violet-500/[0.06] border-violet-500/20 text-violet-400 hover:bg-violet-500/[0.12]",children:"🔧 Auto-Fix"})]}),e.jsx("div",{className:"flex flex-col gap-2",children:p.schema.map(y=>e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-xs font-medium text-text-primary",children:[y.label||y.key,u===`${p.type}.${y.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),y.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:y.description})]}),e.jsx("div",{className:"shrink-0",children:y.type==="boolean"?e.jsx("button",{onClick:()=>S(p.type,y.key,!(p.values[y.key]??y.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:p.values[y.key]??y.default?"#8b5cf6":"var(--border-subtle)"},children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-white absolute top-[3px] transition-[left] duration-200 shadow-[0_1px_3px_rgba(0,0,0,0.3)]",style:{left:p.values[y.key]??y.default?21:3}})}):y.type==="number"?e.jsx("input",{type:"number",value:p.values[y.key]??y.default??0,min:y.min,max:y.max,onChange:N=>{const T=parseInt(N.target.value)||0;y.min!==void 0&&T<y.min||y.max!==void 0&&T>y.max||S(p.type,y.key,T)},className:"machine-input w-20 text-center text-[11px]"}):y.type==="select"&&y.options?e.jsx("select",{value:p.values[y.key]??y.default??"",onChange:N=>S(p.type,y.key,N.target.value),className:"machine-input text-[11px]",children:y.options.map(N=>e.jsx("option",{value:N,children:N},N))}):e.jsx("input",{type:"text",value:p.values[y.key]??y.default??"",onBlur:N=>S(p.type,y.key,N.target.value),className:"machine-input w-[120px] text-[11px]"})})]},y.key))})]},p.type))}),h&&e.jsx(co,{machineId:t,provider:h,sendDaemonCommand:n,onClose:()=>g(null)}),f&&e.jsx(lo,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>b(!1),onCreated:()=>{b(!1),k()}})]})}function xo({machineId:t,sendDaemonCommand:s}){const[n,r]=o.useState([]),[a,i]=o.useState(0),[c,u]=o.useState(!0),[l,x]=o.useState("debug"),d=o.useRef(null),h=o.useRef(!1);return o.useEffect(()=>{if(!t||!c)return;const g=async()=>{try{const b=await s(t,"get_logs",{count:200,minLevel:l,since:a}),k=(b==null?void 0:b.result)||b;if(b!=null&&b.success&&Array.isArray(k==null?void 0:k.logs)&&k.logs.length>0){r(p=>[...p,...k.logs.map(N=>({timestamp:N.ts,level:N.level,message:`[${N.category}] ${N.message}`}))].slice(-300));const S=Math.max(...k.logs.map(p=>p.ts));i(S)}}catch{}};g();const f=setInterval(g,3e3);return()=>clearInterval(f)},[t,c,a,l,s]),o.useEffect(()=>{if(c&&n.length>0){const g=h.current?"smooth":"instant";setTimeout(()=>{var f;(f=d.current)==null||f.scrollIntoView({behavior:g}),h.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(g=>e.jsx("button",{onClick:()=>{x(g),r([]),i(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${l===g?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:g.toUpperCase()},g))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[n.length," entries"]}),e.jsx("button",{onClick:()=>u(!c),className:`machine-btn ${c?"text-green-500 border-green-500/30":""}`,children:c?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),i(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((g,f)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"#f59e0b":g.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(g.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"#f59e0b":g.level==="debug"?"#475569":"#8b5cf6"},children:g.level==="error"?"ERR":g.level==="warn"?"WRN":g.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:g.message})]},f)),e.jsx("div",{ref:d})]})]})}function ho({machine:t,launchPick:s,actions:n}){const{runLaunchCliCore:r,setLaunchPick:a}=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(i=>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:()=>{a(null),r({cliType:s.cliType,workspaceId:i.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:i.label||i.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:i.path})]},i.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:()=>{a(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:()=>{a(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:()=>a(null),children:"Cancel"})]})]})})}function po({onNicknameSynced:t}={}){var v,w,R,A,O,_,I,P,K;const{id:s}=bs(),n=it(),{sendCommand:r}=Pe(),a=It(),i=a.ides||[],c=a.initialLoaded??!0,{isHidden:u,toggleTab:l}=en(),x=i.find(C=>C.id===s&&C.daemonMode),[d,h]=o.useState("overview"),g=o.useRef(null),f=so({machineId:s,registeredMachineId:(x==null?void 0:x.machineId)||null,sendDaemonCommand:r,onNicknameSynced:t,logsEndRef:g});o.useEffect(()=>$e.onToast(F=>{a.setToasts(J=>{if(J.some(X=>X.message===F.message&&F.timestamp-X.timestamp<3e3))return J;const se={id:F.id,message:F.message,type:F.type,timestamp:F.timestamp,targetKey:F.targetKey,actions:F.actions};return[...J.slice(-4),se]});const Q=F.duration||5e3;setTimeout(()=>a.setToasts(J=>J.filter(G=>G.id!==F.id)),Q)}),[a]);const b=((x==null?void 0:x.availableProviders)||[]).map(C=>({type:C.type,displayName:C.displayName,icon:C.icon,category:C.category})),k={};for(const C of b)k[C.type]=C.icon;const S=C=>k[C]||"",p=x?{id:x.id,hostname:Ds(x,{fallbackId:x.id}),platform:((v=x.machine)==null?void 0:v.platform)||"unknown",arch:((w=x.machine)==null?void 0:w.arch)||"",cpus:((R=x.machine)==null?void 0:R.cpus)||0,totalMem:((A=x.machine)==null?void 0:A.totalMem)||0,freeMem:((O=x.machine)==null?void 0:O.freeMem)||0,availableMem:(_=x.machine)==null?void 0:_.availableMem,loadavg:((I=x.machine)==null?void 0:I.loadavg)||[],uptime:((P=x.machine)==null?void 0:P.uptime)||0,release:((K=x.machine)==null?void 0:K.release)||"",cdpConnected:!!x.cdpConnected,machineNickname:x.machineNickname||null,p2p:x.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:x.detectedIdes||[],workspaces:x.workspaces||[],defaultWorkspaceId:x.defaultWorkspaceId??x.activeWorkspaceId??null,defaultWorkspacePath:x.defaultWorkspacePath??x.activeWorkspacePath??null,workspaceActivity:x.workspaceActivity||[]}:null,y=i.filter(C=>C.daemonId===s&&!C.daemonMode).filter(C=>!es(C)&&!ts(C)).map(C=>({id:C.id,type:C.type,version:C.version||"",instanceId:C.instanceId||"",status:C.status,workspace:C.workspace||null,terminals:C.terminals||0,aiAgents:hr(C.aiAgents||C.agents||[]),activeChat:C.activeChat||null,chats:C.chats||[],agentStreams:C.agentStreams||[],cdpConnected:C.cdpConnected||!1,daemonId:s})),N=i.filter(C=>C.daemonId===s&&es(C)).map(C=>({id:C.id,type:C.type,cliName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,daemonId:s})),T=i.filter(C=>C.daemonId===s&&ts(C)).map(C=>({id:C.id,type:C.type,acpName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,currentModel:C.currentModel,currentPlan:C.currentPlan,daemonId:s}));if(!p)return c?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 m=Xe(x,{fallbackId:p.id}),j=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Dn,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{size:14})," IDEs"]}),count:y.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ye,{size:14})," CLIs"]}),count:N.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Rs,{size:14})," ACP Agents"]}),count:T.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ht,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($n,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"dashboard-header !flex-col !items-stretch",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"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:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[f.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:f.nicknameInput,onChange:C=>f.setNicknameInput(C.target.value),onKeyDown:C=>{C.key==="Enter"&&f.handleSaveNickname(),C.key==="Escape"&&f.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:f.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>f.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{f.setEditingNickname(!0),f.setNicknameInput(p.machineNickname||"")},title:"Click to set nickname",children:m}),e.jsx("span",{className:"status-dot-md online shrink-0"})]}),e.jsxs("div",{className:"header-subtitle mt-1 flex-wrap gap-1 md:gap-2 items-center display-none-mobile",children:[e.jsxs("span",{children:[p.platform," · ",p.arch," · ",p.cpus," cores"]}),(x==null?void 0:x.version)&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-bg-glass border border-border-subtle text-text-muted shrink-0",children:["v",x.version]}),(x==null?void 0:x.versionMismatch)&&e.jsxs("button",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-amber-500/[0.08] border border-amber-500/20 text-amber-400 cursor-pointer hover:bg-amber-500/[0.15] transition-colors shrink-0",onClick:async()=>{try{await r(s,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",x.serverVersion]}),p.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:p.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:p.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",p.p2p.state==="connected"?`● ${p.p2p.peers}`:"○"]}),p.cdpConnected&&e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-green-500/[0.08] text-green-500 shrink-0",children:"CDP ●"}),p.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",p.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:j.map(C=>e.jsxs("button",{onClick:()=>h(C.id),className:`machine-tab shrink-0${d===C.id?" active":""}`,children:[C.label,C.count!==void 0&&e.jsx("span",{className:"tab-count",children:C.count})]},C.id))})]}),e.jsxs("div",{className:"page-content",children:[d==="overview"&&e.jsx(ro,{machine:p,ideSessions:y,cliSessions:N,acpSessions:T,actions:f,isDashboardHidden:u,onToggleDashboardVisibility:l}),d==="ides"&&e.jsx($t,{category:"ide",machine:p,machineId:s,providers:b,managedEntries:y,getIcon:S,actions:f,isDashboardHidden:u,onToggleDashboardVisibility:l,sendDaemonCommand:r}),d==="clis"&&e.jsx($t,{category:"cli",machine:p,machineId:s,providers:b,managedEntries:N,getIcon:S,actions:f,isDashboardHidden:u,onToggleDashboardVisibility:l}),d==="acps"&&e.jsx($t,{category:"acp",machine:p,machineId:s,providers:b,managedEntries:T,getIcon:S,actions:f,isDashboardHidden:u,onToggleDashboardVisibility:l}),d==="providers"&&e.jsx(uo,{machineId:s,providers:b,sendDaemonCommand:r}),d==="logs"&&e.jsx(xo,{machineId:s,sendDaemonCommand:r})]}),f.launchPick&&p&&e.jsx(ho,{machine:p,launchPick:f.launchPick,actions:f}),e.jsx(zs,{toasts:a.toasts||[],onDismiss:C=>a.setToasts(F=>F.filter(Q=>Q.id!==C)),onClickToast:C=>{C.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 mo(){const[t,s]=o.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=o.useState(!0);o.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const u=[],l=[],x=[],d=[];Object.values(c.providers||{}).forEach(g=>{const f={name:g.name||"Unknown",status:g.status||"Stable",details:g.details||"Community Provider"};g.category==="ide"?u.push(f):g.category==="cli"?l.push(f):g.category==="extension"?x.push(f):g.category==="acp"&&d.push(f)});const h=(g,f)=>{const b={Stable:1,Beta:2,WIP:3},k=b[g.status]||99,S=b[f.status]||99;return k!==S?k-S:g.name.localeCompare(f.name)};s({ide:u.sort(h),cli:l.sort(h),ext:x.sort(h),acp:d.sort(h)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>r(!1))},[]);const a=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Cs,{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(Ft,{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(Es,{className:"w-4 h-4"})," ",e.jsx("span",{children:c})]}),i=c=>e.jsx("div",{className:"bg-bg-card border border-border-subtle rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary border-b border-border-subtle text-xs uppercase text-text-muted font-medium tracking-wider",children:[e.jsx("th",{className:"py-3 px-4 w-1/3",children:"Target"}),e.jsx("th",{className:"py-3 px-4 w-1/4",children:"Status"}),e.jsx("th",{className:"py-3 px-4",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-border-subtle text-sm",children:c.map((u,l)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:u.name}),e.jsx("td",{className:"py-3 px-4",children:a(u.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:u.details})]},l))})]})});return n?e.jsx(Nt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(wt,{}),widthClassName:"max-w-5xl",children:e.jsx(Vt,{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(Nt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(wt,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(fe,{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(fe,{title:"IDE support",icon:e.jsx(Le,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:i(t.ide)}),e.jsx(fe,{title:"Standalone CLI agents",icon:e.jsx(Ut,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:i(t.cli)}),e.jsx(fe,{title:"AI extensions",icon:e.jsx(Ye,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:i(t.ext)}),e.jsx(fe,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(Ye,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:i(t.acp)})]})}class fo{constructor(){ue(this,"adapters",new Map);ue(this,"states",new Map);ue(this,"ptyCallbacks",new Set);ue(this,"runtimeListeners",new Map);ue(this,"runtimeBuffers",new Map);ue(this,"runtimeSeqs",new Map);ue(this,"screenshotCallbacks",new Map);ue(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,a){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){if(r!=null&&r.scrollback){const a=(this.runtimeSeqs.get(s)||0)+1;this.runtimeBuffers.set(s,typeof n=="string"?n:""),this.runtimeSeqs.set(s,a),this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:a,text:typeof n=="string"?n:"",truncated:!1})}else if(typeof n=="string"&&n){const i=(this.runtimeBuffers.get(s)||"")+n,c=i.length>64*1024?i.slice(-65536):i,u=(this.runtimeSeqs.get(s)||0)+1;this.runtimeBuffers.set(s,c),this.runtimeSeqs.set(s,u),this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,seq:u,data:n})}this.ptyCallbacks.forEach(a=>a(s,n,r))}emitRuntimeSnapshot(s,n,r=0,a=!1){this.runtimeBuffers.set(s,n),this.runtimeSeqs.set(s,r),this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:r,text:n,truncated:a})}getRuntimeSnapshot(s){return Promise.resolve({sessionId:s,seq:this.runtimeSeqs.get(s)||0,text:this.runtimeBuffers.get(s)||"",truncated:!1})}onRuntimeEvent(s,n){const r=this.runtimeListeners.get(s)||new Set;return r.add(n),this.runtimeListeners.set(s,r),()=>{const a=this.runtimeListeners.get(s);a&&(a.delete(n),a.size===0&&this.runtimeListeners.delete(s))}}emitRuntimeEvent(s,n){var r;(r=this.runtimeListeners.get(s))==null||r.forEach(a=>a(n))}}const Ae=new fo;function go(){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 xs=go(),hs=3e3,bo=3e4;let Re=null,yo=0;const Ct=new Map;let Be=null,at=null;function jo(t){return t==="connected"?"connected":t}async function vt(t,s,n){const r=Ir(t,n||{}),a=Re;if(a&&a.readyState===WebSocket.OPEN){const c=`req_${++yo}_${Date.now()}`;return new Promise((u,l)=>{const x=setTimeout(()=>{Ct.delete(c),l(new Error(`WS command timeout: ${s}`))},3e4);Ct.set(c,{resolve:d=>{clearTimeout(x),u(d)},reject:d=>{clearTimeout(x),l(d)}}),a.send(JSON.stringify({type:"command",requestId:c,data:{type:s,payload:r.payload}}))})}const i=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:r.payload})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}class vo{constructor(s){ue(this,"daemonId");ue(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Re==null?void 0:Re.readyState)===WebSocket.OPEN}get connectionState(){return(Re==null?void 0:Re.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return vt(this.daemonId,s,n)}async sendInput(s,n){return vt(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,Be&&(clearInterval(Be),Be=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await vt(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const a=await fetch(`data:image/jpeg;base64,${r.base64}`).then(i=>i.blob());Ae.emitScreenshot(this.daemonId,a)}}catch{}};n(),Be=setInterval(n,2e3)}stopScreenshots(s){Be&&(clearInterval(Be),Be=null)}}let ke=null;function wo(t){return(!ke||ke.daemonId!==t)&&(ke=new vo(t)),ke}function No({children:t}){const s=o.useRef(Xt()),n=Xt();s.current=n;const{setUserName:r}=ot(),a=o.useRef(r);a.current=r;const[,i]=o.useState("disconnected"),c=o.useCallback((g,f)=>{i(g),at==null||at(g,f)},[]),u=o.useRef(null),l=o.useRef(),x=o.useRef(hs),d=o.useRef(!0),h=o.useRef(!1);return o.useEffect(()=>{d.current=!0,h.current=!1;function g(){var k,S;if(!d.current||((k=u.current)==null?void 0:k.readyState)===WebSocket.OPEN||((S=u.current)==null?void 0:S.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${xs}...`);let b;try{b=new WebSocket(xs)}catch(p){console.error("[Standalone WS] Failed to create WebSocket:",p),f();return}u.current=b,b.onopen=()=>{if(!d.current){b.close();return}c("connected"),x.current=hs,console.log("[Standalone WS] Connected")},Re=b,b.onmessage=p=>{var y;try{const N=JSON.parse(p.data);if((N.type==="command_result"||N.type==="error")&&N.requestId){const T=Ct.get(N.requestId);T&&(Ct.delete(N.requestId),N.type==="error"?T.reject(new Error(((y=N.data)==null?void 0:y.message)||"Command failed")):T.resolve(N.data));return}if(N.type==="pty_output"){Ae.emitPtyOutput(N.cliId,N.data);return}if(N.type==="runtime_snapshot"){Ae.emitRuntimeSnapshot(N.sessionId,typeof N.text=="string"?N.text:"",typeof N.seq=="number"?N.seq:0,!!N.truncated);return}if(N.type==="status"||N.type==="initial_state"){const T=N.data;if(!T)return;const{injectEntries:m,markLoaded:j}=s.current,v=T.id||"standalone",w=wo(v);Ae.register(v,w),Ae.setState(v,"connected"),c("connected",v),Ae.emitStatus(v,T);const R=Cr(T,{daemonId:v});R.length>0&&m(R),j(),T.userName&&a.current&&a.current(T.userName)}}catch(N){console.error("[Standalone WS] Parse error:",N)}},b.onclose=()=>{d.current&&(ke==null||ke.stopScreenshots(),ke&&Ae.setState(ke.daemonId,"disconnected"),c("disconnected"),u.current=null,f())},b.onerror=p=>{h.current||!d.current||console.warn("[Standalone WS] Error, will reconnect:",p)}}function f(){if(!d.current)return;clearTimeout(l.current);const b=x.current;console.log(`[Standalone WS] Reconnecting in ${b}ms...`),l.current=setTimeout(()=>{x.current=Math.min(x.current*1.5,bo),g()},b)}return g(),()=>{d.current=!1,h.current=!0,clearTimeout(l.current),u.current&&(u.current.onerror=null,u.current.onclose=null,u.current.close(),u.current=null,Re=null),ke&&(ke.stopScreenshots(),Ae.unregister(ke.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function ko({children:t}){const[s,n]=o.useState("disconnected"),[r,a]=o.useState(null);o.useEffect(()=>(at=(c,u)=>{n(c),u&&a(u)},()=>{at=null}),[]);const i=o.useMemo(()=>{const c=s==="connected",u=jo(s),l={};return r&&(l[r]=u),l.standalone=u,{wsStatus:s,isConnected:c,connectionStates:l}},[s,r]);return e.jsx(Cn,{connectionOverrides:i,children:e.jsx(No,{children:t})})}const So=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Ns,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(ks,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Ht,{}),label:"Settings"}];function Co({children:t}){const s=it(),n=yn(),[r,a]=o.useState(!1),[i,c]=o.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),u=d=>{s(d),a(!1)},l=()=>{c(d=>{const h=!d;try{localStorage.setItem("sidebar-collapsed",h?"1":"0")}catch{}return h})},x=d=>`nav-item${n.pathname.startsWith(d)?" active":""} cursor-pointer ${i?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${i?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>a(!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:()=>a(!1),onKeyDown:d=>d.key==="Escape"&&a(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${i?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!i&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>a(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:So.map(d=>e.jsxs("div",{className:x(d.path),id:`nav-${d.id}`,onClick:()=>u(d.path),title:i?d.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:d.icon}),!i&&d.label]},d.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${i?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:i?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(wt,{})}),!i&&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":""} ${i?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:i?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Ss,{})}),!i&&"About"]}),!i&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.7.17"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${i?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,title:i?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:i?"›":"‹"}),!i&&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 Io=[{icon:e.jsx(ks,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(qe,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Ts,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Le,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(Ye,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(wt,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Mo=[{icon:e.jsx(As,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(Ns,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(_s,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Ln,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Rn,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Cs,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],To=[{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 Eo(){return e.jsxs(Nt,{icon:e.jsx(Ss,{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.17"]}),children:[e.jsx(fe,{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(fe,{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:Io.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(fe,{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:Vs.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:Ys.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:qs.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(fe,{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:Mo.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(fe,{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:To.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(Vt,{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(Hn,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Ao(){const{ides:t}=ot(),s=t.find(h=>h.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=Pe(),{userName:a}=ot(),[i,c]=o.useState(a||"");o.useEffect(()=>{a!==void 0&&c(a)},[a]);const u=h=>{const g=h.target.value.trim();s!=null&&s.id&&g!==a&&r(s.id,"set_user_name",{userName:g}).catch(console.error)},[l,x]=o.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),d=h=>{x(h);try{localStorage.setItem("adhdev_sound",h?"1":"0")}catch{}};return e.jsxs(Nt,{icon:e.jsx(Ht,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(zr,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(fe,{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.17"]}),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(fe,{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(h=>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 ${h.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:h.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:h.type})]},h.type))})}),e.jsx(fe,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Gr,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(fe,{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(ea,{})]}),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(oa,{})]})]})}),e.jsx(fe,{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(Xr,{}),e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(zn,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:d})]})}),e.jsx(fe,{title:"Profile",description:"How your name appears in local chat threads and dashboard views.",children:e.jsx("div",{className:"flex flex-col gap-3",children:e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-4 bg-bg-glass rounded-xl border border-border-subtle hover:border-border-default transition-colors",children:[e.jsxs("div",{className:"flex flex-col gap-1 pr-4 max-w-[500px]",children:[e.jsxs("span",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(_n,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:i,onChange:h=>c(h.target.value),onBlur:u,onKeyDown:h=>{h.key==="Enter"&&h.currentTarget.blur()}})]})})})]})}qr();ra();const Ro=vs({baseUrl:""});function ps(){const{ides:t}=ot(),s=t.find(n=>{var r;return n.daemonMode||((r=n.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(gt,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(gt,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(gt,{to:"/dashboard",replace:!0})}function _o(){return e.jsx(jn,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Tn,{client:Ro,children:e.jsx(ko,{children:e.jsx(An,{value:{sendCommand:vt,sendData:()=>!1},children:e.jsx(Co,{children:e.jsxs(vn,{children:[e.jsx(Ee,{path:"/dashboard",element:e.jsx(qa,{})}),e.jsx(Ee,{path:"/ide/:id",element:e.jsx(to,{})}),e.jsx(Ee,{path:"/machine",element:e.jsx(ps,{})}),e.jsx(Ee,{path:"/machines/:id",element:e.jsx(po,{})}),e.jsx(Ee,{path:"/machines",element:e.jsx(ps,{})}),e.jsx(Ee,{path:"/capabilities",element:e.jsx(mo,{})}),e.jsx(Ee,{path:"/about",element:e.jsx(Eo,{})}),e.jsx(Ee,{path:"/settings",element:e.jsx(Ao,{})}),e.jsx(Ee,{path:"*",element:e.jsx(gt,{to:"/dashboard",replace:!0})})]})})})})})})}br({connectionManager:Ae});wn(document.getElementById("root")).render(e.jsx(o.StrictMode,{children:e.jsx(_o,{})}));
|