@adhdev/daemon-standalone 0.6.37 → 0.6.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,7 +6,7 @@ var Cs=Object.defineProperty;var Is=(t,s,a)=>s in t?Cs(t,s,{enumerable:!0,config
|
|
|
6
6
|
|
|
7
7
|
`).trim();return{toolCounts:r,textContent:o,hasTools:Object.keys(r).length>0}}function Nt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}const cn=n.forwardRef(function({messages:s,actionLogs:a,agentName:r="Agent",userName:i,isCliMode:c=!1,isWorking:o=!1,contextKey:p="",receivedAtMap:u={},emptyState:m,onLoadMore:l,isLoadingMore:d,hasMoreHistory:v,loadError:j},x){var re;const I=n.useRef(null),T=n.useRef(null),f=n.useRef(0),N=n.useRef(""),B=n.useRef(!1),[K,E]=n.useState(new Set),[A,$]=n.useState(new Set),C=n.useRef(!1),y=()=>{const V=I.current;return V?V.scrollHeight-V.scrollTop-V.clientHeight<200:!0},R=s.length>0?`${s.length}:${(((re=s[s.length-1])==null?void 0:re.content)||"").length}`:"0:0";n.useEffect(()=>{var ae,oe;const V=!B.current,ee=N.current!==p;if(N.current=p,V||ee){B.current=!0,C.current=!1;const ue=()=>{var ie;(ie=T.current)==null||ie.scrollIntoView({behavior:"instant"})};requestAnimationFrame(()=>requestAnimationFrame(ue)),setTimeout(ue,100),setTimeout(ue,300),f.current=s.length;return}s.length>f.current?C.current||(ae=T.current)==null||ae.scrollIntoView({behavior:"instant"}):y()&&!C.current&&((oe=T.current)==null||oe.scrollIntoView({behavior:"instant"})),f.current=s.length},[R,p,o]),n.useImperativeHandle(x,()=>({scrollToBottom:(V="smooth")=>{var ee;(ee=T.current)==null||ee.scrollIntoView({behavior:V})}})),n.useEffect(()=>{const V=I.current;if(!V)return;let ee;const O=()=>{clearTimeout(ee),ee=setTimeout(()=>{C.current=!y()},50)};return V.addEventListener("scroll",O,{passive:!0}),()=>{V.removeEventListener("scroll",O),clearTimeout(ee)}},[]);const F=n.useRef(0),H=n.useRef(!1);n.useEffect(()=>{const V=I.current;if(!V||!H.current||F.current===0)return;const ee=V.scrollHeight-F.current;ee>0&&(V.scrollTop=ee),F.current=0,H.current=!1},[s.length]);const Z=()=>{const V=I.current;V&&(F.current=V.scrollHeight),H.current=!0,l==null||l()},b=(()=>{const V=s.map((oe,ue)=>({type:"message",data:oe,index:ue,ts:oe.receivedAt||u[oe.id??`i-${ue}`]||0}));if(!a||a.length===0)return V;const ee=[...a].sort((oe,ue)=>oe.timestamp-ue.timestamp).map((oe,ue)=>({type:"action",data:oe,index:ue,ts:oe.timestamp})),O=[];let ae=0;for(const oe of V){for(;ae<ee.length&&oe.ts>0&&ee[ae].ts<oe.ts;)O.push(ee[ae++]);O.push(oe)}for(;ae<ee.length;)O.push(ee[ae++]);return O})(),G=700;return e.jsxs("div",{ref:I,"data-chat-scroll":!0,className:"chat-container",children:[d&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),v&&!d&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:Z,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${j?"bg-transparent border-yellow-500/30 text-yellow-400 opacity-80 hover:opacity-100":"bg-transparent border-border-subtle text-text-muted opacity-70 hover:opacity-100 hover:border-accent/40"}`,children:j?`↻ ${j}`:"↑ Load older messages"})}),b.length===0&&!v&&(m||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),b.map(V=>{var ke;if(V.type==="action"){const W=V.data;return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(Ot,{remarkPlugins:[Kt],children:W.text}),e.jsx("span",{className:"action-time",children:Nt(W.timestamp)})]},`action-${V.index}`)}const ee=V.data,O=V.index,ae=(ee.role||"").toLowerCase(),oe=ae==="user"||ae==="human",ue=ee.kind||(ae==="tool"?"tool":"standard"),ie=ee.receivedAt||u[ee.id??`i-${O}`],L=`${p}-${O}`,g=K.has(L),D=A.has(L),h=typeof ee.content=="string"?ee.content:(ee.content||[]).map(W=>W.text||"").join(`
|
|
8
8
|
`);if(ue==="thought"){const W=((ke=ee.meta)==null?void 0:ke.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(rn,{size:13}),e.jsx("span",{children:W})]}),e.jsx("div",{className:"chat-msg-body",children:h})]},`msg-${O}`)}if(ue==="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:h.split(`
|
|
9
|
-
`)[0].slice(0,80)})]},`msg-${O}`);if(ue==="terminal"){const W=ee.meta||{},te=W.isRunning?"⏳":"✅",me=W.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:te}),e.jsx("span",{children:me})]}),e.jsx("pre",{className:"chat-msg-body",children:h})]},`msg-${O}`)}if(ue==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:h.slice(0,100)},`msg-${O}`);const z=!oe&&c?on(h):null,Q=z?z.textContent:h,xe=z?Object.entries(z.toolCounts):[],ge=c&&!oe&&!g&&Q.length>G,he=g?h:ge&&!D?Q.slice(0,G):Q;return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${oe?"self-end":"self-start"}`,children:[xe.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[xe.map(([W,te])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",W,te>1?` ×${te}`:""]},W)),(z==null?void 0:z.hasTools)&&e.jsx("button",{onClick:()=>E(W=>{const te=new Set(W);return g?te.delete(L):te.add(L),te}),className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:g?"Collapse":"Original"}),!Q&&ie!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Nt(ie)})]}),(Q||oe)&&e.jsxs("div",{className:`chat-bubble ${oe?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${Q?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:oe?i||"You":r}),ie!=null&&e.jsx("span",{className:"chat-time",children:Nt(ie)})]}),Q&&e.jsx("div",{className:"chat-markdown",children:e.jsx(Ot,{remarkPlugins:[Kt,Ms,Ts],children:he})}),ge&&e.jsx("button",{onClick:()=>$(W=>{const te=new Set(W);return D?te.delete(L):te.add(L),te}),className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:D?"Collapse ↑":`Show more (${Math.round(Q.length/100)*100} chars) ↓`})]})]},`msg-${O}`)}),o&&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 working..."})]})}),e.jsx("div",{className:"min-h-10",ref:T})]})}),zt={background:"#0f1117",foreground:"#cdd6f4",cursor:"#f38ba8",cursorAccent:"#0f1117",selectionBackground:"rgba(166, 227, 161, 0.3)",selectionForeground:"#cdd6f4",black:"#45475a",red:"#f38ba8",green:"#a6e3a1",yellow:"#f9e2af",blue:"#89b4fa",magenta:"#cba6f7",cyan:"#94e2d5",white:"#bac2de",brightBlack:"#585b70",brightRed:"#f38ba8",brightGreen:"#a6e3a1",brightYellow:"#f9e2af",brightBlue:"#89b4fa",brightMagenta:"#cba6f7",brightCyan:"#94e2d5",brightWhite:"#a6adc8"},fs=n.forwardRef(({onInput:t,onResize:s,fontSize:a=13},r)=>{const i=n.useRef(null),c=n.useRef(null),o=n.useRef(null),[p,u]=n.useState(!1);return n.useImperativeHandle(r,()=>({write:m=>{var l;(l=c.current)==null||l.write(m)},clear:()=>{var m;(m=c.current)==null||m.clear()},fit:()=>{var m;try{(m=o.current)==null||m.fit(),c.current&&(s==null||s(c.current.cols,c.current.rows))}catch{}},bumpResize:()=>{var m;try{(m=o.current)==null||m.fit();const l=c.current;if(!l)return;const d=l.cols,v=l.rows;s==null||s(d+5,v),setTimeout(()=>{s==null||s(d,v)},100)}catch{}}})),n.useEffect(()=>{if(!i.current)return;const m=new Bs({cursorBlink:!0,cursorStyle:"bar",fontSize:a,fontFamily:"'JetBrains Mono', 'Fira Code', 'SF Mono', 'Menlo', monospace",fontWeight:"400",letterSpacing:0,lineHeight:1.2,theme:zt,allowTransparency:!0,scrollback:5e3,convertEol:!1}),l=new Ws,d=new Os;m.loadAddon(l),m.loadAddon(d),m.open(i.current),requestAnimationFrame(()=>{l.fit(),s==null||s(m.cols,m.rows),u(!0)});const v=m.onData(x=>{t(x)}),j=new ResizeObserver(()=>{requestAnimationFrame(()=>{try{l.fit(),s==null||s(m.cols,m.rows)}catch{}})});return j.observe(i.current),c.current=m,o.current=l,()=>{v.dispose(),j.disconnect(),m.dispose(),c.current=null,o.current=null}},[a]),e.jsx("div",{ref:i,className:"w-full h-full rounded-lg overflow-hidden transition-opacity duration-200",style:{background:zt.background,opacity:p?1:0}})});fs.displayName="CliTerminal";function ut({label:t,value:s,sub:a,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}),a&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:a})]})}function Ut({value:t,max:s,label:a,color:r="#8b5cf6",detail:i,compact:c=!1}){const o=s>0?Math.min(Math.round(t/s*100),100):0,p=o>85?"#ef4444":o>60?"#f59e0b":r;return c?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:a}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[o,"%"]})]}),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:`${o}%`,background:p}})})]}):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:a}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[o,"%"]})]}),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:`${o}%`,background:`linear-gradient(90deg, ${p}, ${p}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function ln({onAction:t,addLog:s,connState:a,connScreenshot:r,screenshotUsage:i}){const c=n.useRef(null),o=n.useRef(null),p=n.useRef(null),[u,m]=n.useState(null),[l,d]=n.useState(""),[,v]=n.useState(!1),[j,x]=n.useState([]),I=n.useRef(0),[T,f]=n.useState(!1),[N,B]=n.useState(!1),K=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[E,A]=n.useState(K?"mouse":"touch"),[$,C]=n.useState(1),y=n.useRef(!1),[R,F]=n.useState(1),[H,Z]=n.useState(0),[b,G]=n.useState(0),re=n.useRef(0),V=n.useRef(t),ee=n.useRef(null),O=n.useRef(null),ae=n.useRef(!1),oe=n.useRef(null),ue=n.useRef(0),ie=n.useRef(null),L=n.useRef(1),g=n.useRef({x:0,y:0}),D=n.useRef(!1),h=n.useRef(R),z=n.useRef(H),Q=n.useRef(b),xe=n.useRef(E);n.useEffect(()=>{h.current=R},[R]),n.useEffect(()=>{z.current=H},[H]),n.useEffect(()=>{Q.current=b},[b]),n.useEffect(()=>{V.current=t},[t]),n.useEffect(()=>{xe.current=E},[E]),n.useEffect(()=>{var P;(P=c.current)==null||P.focus()},[]);const ge=a==="connected",he=r;n.useEffect(()=>{if(!K||y.current||!he)return;const P=p.current,ne=o.current;if(!P||!ne)return;const J=()=>{const fe=ne.clientWidth,k=ne.clientHeight,U=P.naturalWidth,ce=P.naturalHeight;if(!U||!ce||!fe||!k)return;const Y=Math.min(fe/U,k/ce),q=Math.max(fe/U,k/ce)/Y;q>1.01&&(C(q),F(q),h.current=q),y.current=!0};P.complete&&P.naturalWidth?J():P.addEventListener("load",J,{once:!0})},[he,K]);const ke=.5;n.useEffect(()=>{R<=ke&&(Z(0),G(0))},[R,ke]);const W=(P,ne,J)=>{if(J<=ke)return{x:0,y:0};const fe=(J-1)/(2*J)*100,k=(J-1)/(2*J)*100;return{x:Math.max(-fe,Math.min(fe,P)),y:Math.max(-k,Math.min(k,ne))}},te=(P,ne)=>{if(!p.current)return null;const J=p.current.getBoundingClientRect();return!J.width||!J.height?null:{nx:Math.max(0,Math.min(1,(P-J.left)/J.width)),ny:Math.max(0,Math.min(1,(ne-J.top)/J.height))}},me=(P,ne,J)=>{const fe=o.current;if(!fe)return;const k=fe.getBoundingClientRect(),U=++I.current;x(ce=>[...ce,{id:U,x:P-k.left,y:ne-k.top,type:J}]),setTimeout(()=>x(ce=>ce.filter(Y=>Y.id!==U)),600)},be=(P,ne,J)=>{const fe=p.current,k=o.current;if(!fe||!k)return;const U=fe.getBoundingClientRect(),ce=k.getBoundingClientRect(),Y=fe.naturalWidth||U.width,le=fe.naturalHeight||U.height,q=Y/le,X=U.width/U.height;let pe,se,je,we;q>X?(pe=U.width,se=U.width/q,je=0,we=(U.height-se)/2):(se=U.height,pe=U.height*q,je=(U.width-pe)/2,we=0);const Ne=U.left-ce.left+je+pe*P,w=U.top-ce.top+we+se*ne,S=++I.current;x(M=>[...M,{id:S,x:Ne,y:w,type:J}]),setTimeout(()=>x(M=>M.filter(_=>_.id!==S)),600)},Pe=async P=>{var J;const ne=te(P.clientX,P.clientY);if(ne){m(`Click: ${Math.round(ne.nx*100)}%, ${Math.round(ne.ny*100)}%`),me(P.clientX,P.clientY,"left"),(J=c.current)==null||J.focus();try{const fe=await t("input_click",{nx:ne.nx,ny:ne.ny});fe!=null&&fe.success||s(`❌ Click failed: ${fe==null?void 0:fe.error}`)}catch(fe){s(`❌ Click error: ${fe.message||fe}`)}}},ve=async(P,ne,J,fe=0)=>{try{await t("input_key",{type:J?"char":"keyDown",key:P,code:ne,text:J?P:void 0,unmodifiedText:J?P:void 0,modifiers:fe})}catch(k){s(`❌ Key error: ${k.message||k}`)}},Me=async P=>{if(P.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(P.key)&&P.preventDefault();let J=0;P.altKey&&(J|=1),P.ctrlKey&&(J|=2),P.metaKey&&(J|=4),P.shiftKey&&(J|=8),m(`Key: ${P.key}`),await ve(P.key,P.code,P.key.length===1,J)},et=async P=>{if(P.key==="Enter"){if(P.nativeEvent.isComposing)return;if(l){const ne=l;d(""),m(`IME Sent: ${ne}`);try{const J=await t("input_type",{text:ne});J!=null&&J.success||s(`❌ IME error: ${J==null?void 0:J.error}`)}catch(J){s(`❌ IME error: ${J.message}`)}}else m("Key: Enter"),await ve("Enter","Enter",!1)}};n.useEffect(()=>{const P=c.current;if(!P)return;const ne=J=>{var fe;if((fe=p.current)!=null&&fe.contains(J.target)){J.preventDefault();const k=Date.now();if(k-re.current<40)return;re.current=k;const U=te(J.clientX,J.clientY);if(!U)return;m(`Scroll: ${Math.round(J.deltaY)}`),t("input_wheel",{nx:U.nx,ny:U.ny,deltaX:Math.round(J.deltaX),deltaY:Math.round(J.deltaY)}).catch(()=>{})}};return P.addEventListener("wheel",ne,{passive:!1}),()=>P.removeEventListener("wheel",ne)},[t]);const[_e,We]=n.useState(null),Ie=n.useRef(null);return n.useEffect(()=>{if(E==="mouse"&&!Ie.current){const P={nx:.5,ny:.5};Ie.current=P,We(P)}},[E]),n.useEffect(()=>{const P=c.current;if(!P)return;const ne=Y=>{if(!p.current)return null;const le=p.current.getBoundingClientRect();return!le.width||!le.height?null:{nx:Math.max(0,Math.min(1,(Y.clientX-le.left)/le.width)),ny:Math.max(0,Math.min(1,(Y.clientY-le.top)/le.height))}},J=(Y,le)=>{if(!p.current)return{dnx:0,dny:0};const q=p.current,X=q.getBoundingClientRect(),pe=q.naturalWidth||X.width,se=q.naturalHeight||X.height,je=pe/se,we=X.width/X.height;let Ne,w;return je>we?(Ne=X.width,w=X.width/je):(w=X.height,Ne=X.height*je),{dnx:Y/Ne,dny:le/w}},fe=(Y,le,q)=>{if(q<=1.05)return;const X=-(Y-.5)*100,pe=-(le-.5)*100,se=W(X,pe,q);(Math.abs(se.x-z.current)>.1||Math.abs(se.y-Q.current)>.1)&&(Z(se.x),G(se.y),z.current=se.x,Q.current=se.y)},k=Y=>{const le=o.current;if(le&&Y.target instanceof Node&&le.contains(Y.target))Y.preventDefault();else return;if(Y.touches.length===1){const q=Y.touches[0];ee.current={x:q.clientX,y:q.clientY,time:Date.now()},O.current={x:q.clientX,y:q.clientY},D.current||(ae.current=!1),oe.current=setTimeout(()=>{if(!ae.current&&!D.current)if(ae.current=!0,xe.current==="mouse"){const X=Ie.current||{nx:.5,ny:.5};m("Right Click"),be(X.nx,X.ny,"right"),V.current("input_click",{...X,button:"right"}).catch(()=>{})}else{const X=ne(q);X&&(m("Right Click"),be(X.nx,X.ny,"right"),V.current("input_click",{...X,button:"right"}).catch(()=>{}))}},500)}else if(Y.touches.length===2){clearTimeout(oe.current),ae.current=!0,D.current=!0;const q=Y.touches[1].clientX-Y.touches[0].clientX,X=Y.touches[1].clientY-Y.touches[0].clientY;ie.current=Math.sqrt(q*q+X*X),L.current=h.current,g.current={x:(Y.touches[0].clientX+Y.touches[1].clientX)/2,y:(Y.touches[0].clientY+Y.touches[1].clientY)/2}}},U=Y=>{const le=o.current;if(le&&Y.target instanceof Node&&le.contains(Y.target)&&Y.preventDefault(),Y.touches.length===1&&O.current){const q=Y.touches[0],X=q.clientX-O.current.x,pe=q.clientY-O.current.y;if(!ae.current&&ee.current){const se=q.clientX-ee.current.x,je=q.clientY-ee.current.y;Math.sqrt(se*se+je*je)>8&&(ae.current=!0,clearTimeout(oe.current))}if(ae.current)if(xe.current==="mouse"){const se=J(X,pe),je=Ie.current||{nx:.5,ny:.5},we=Math.max(0,Math.min(1,je.nx+se.dnx)),Ne=Math.max(0,Math.min(1,je.ny+se.dny));Ie.current={nx:we,ny:Ne},We({nx:we,ny:Ne}),m(`Cursor: ${Math.round(we*100)}%, ${Math.round(Ne*100)}%`),fe(we,Ne,h.current);const w=Date.now();w-re.current>=30&&(re.current=w,V.current("input_mouseMoved",{nx:we,ny:Ne}).catch(()=>{}))}else if(h.current>1){const se=o.current;if(se){const je=se.clientWidth,we=se.clientHeight,Ne=z.current+X/je*100,w=Q.current+pe/we*100,S=W(Ne,w,h.current);Z(S.x),G(S.y),z.current=S.x,Q.current=S.y}}else{const se=ne(q);if(se){const je=Date.now();je-re.current>=40&&(re.current=je,m("Scroll"),V.current("input_wheel",{nx:se.nx,ny:se.ny,deltaX:Math.round(-X*2.5),deltaY:Math.round(-pe*2.5)}).catch(()=>{}))}}O.current={x:q.clientX,y:q.clientY}}else if(Y.touches.length===2&&ie.current!==null){const q=Y.touches[1].clientX-Y.touches[0].clientX,X=Y.touches[1].clientY-Y.touches[0].clientY,se=Math.sqrt(q*q+X*X)/ie.current,je=(Y.touches[0].clientX+Y.touches[1].clientX)/2,we=(Y.touches[0].clientY+Y.touches[1].clientY)/2,Ne=je-g.current.x,w=we-g.current.y,S=Math.abs(se-1)>.03;if(xe.current==="mouse"){if(S){const M=Math.max(ke,Math.min(5,L.current*se));F(M),h.current=M}else if(Math.abs(Ne)>2||Math.abs(w)>2){const M=Ie.current||{nx:.5,ny:.5},_=Date.now();_-re.current>=30&&(re.current=_,m("Scroll"),V.current("input_wheel",{nx:M.nx,ny:M.ny,deltaX:Math.round(-Ne*3),deltaY:Math.round(-w*3)}).catch(()=>{}))}}else{const M=Math.max(ke,Math.min(5,L.current*se));F(M),h.current=M;const _=o.current;if(_&&M>1){const de=_.clientWidth,ye=_.clientHeight,Se=z.current+Ne/de*100,Ee=Q.current+w/ye*100,$e=W(Se,Ee,M);Z($e.x),G($e.y),z.current=$e.x,Q.current=$e.y}}g.current={x:je,y:we}}},ce=Y=>{var le;if(clearTimeout(oe.current),ie.current=null,Y.touches.length===1&&D.current){const q=Y.touches[0];ee.current={x:q.clientX,y:q.clientY,time:Date.now()},O.current={x:q.clientX,y:q.clientY},ae.current=!0;return}if(Y.touches.length===0){if(D.current){D.current=!1,ae.current=!1;return}if(Y.changedTouches.length===1&&!ae.current){const q=Y.changedTouches[0],X=Date.now(),pe=X-(((le=ee.current)==null?void 0:le.time)||0);if(pe<60||pe>400){ae.current=!1;return}if(ee.current){const se=q.clientX-ee.current.x,je=q.clientY-ee.current.y;if(Math.sqrt(se*se+je*je)>12){ae.current=!1;return}}if(xe.current==="mouse"){const se=Ie.current||ne(q);se&&(m(`Click: ${Math.round(se.nx*100)}%, ${Math.round(se.ny*100)}%`),be(se.nx,se.ny,"left"),V.current("input_click",{...se}).catch(()=>{}))}else{const se=ne(q);if(!se)return;X-ue.current<300?(m("Double tap"),be(se.nx,se.ny,"double"),V.current("input_click",{...se,clickCount:2}).catch(()=>{}),ue.current=0):(m(`Tap: ${Math.round(se.nx*100)}%, ${Math.round(se.ny*100)}%`),be(se.nx,se.ny,"left"),V.current("input_click",{...se}).catch(()=>{}),ue.current=X)}}ae.current=!1}};return P.addEventListener("touchstart",k,{passive:!1}),P.addEventListener("touchmove",U,{passive:!1}),P.addEventListener("touchend",ce,{passive:!1}),()=>{P.removeEventListener("touchstart",k),P.removeEventListener("touchmove",U),P.removeEventListener("touchend",ce),clearTimeout(oe.current)}},[]),e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:Me,onContextMenu:P=>P.preventDefault(),onFocus:()=>v(!0),onBlur:()=>v(!1),tabIndex:0,children:[e.jsxs("div",{ref:o,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[he?e.jsx("img",{ref:p,src:he,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${R}) translate(${H}%, ${b}%)`,transformOrigin:"center center",cursor:E==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:Pe,onContextMenu:P=>P.preventDefault(),onDragStart:P=>P.preventDefault()}):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:"Connecting to Host..."}),e.jsx("div",{className:"text-[11px] text-white/40",children:"Waiting for the remote stream to catch up"})]}),E==="mouse"&&_e&&he&&p.current&&(()=>{var Ne;const P=p.current,ne=P.getBoundingClientRect(),J=(Ne=o.current)==null?void 0:Ne.getBoundingClientRect();if(!J)return null;const fe=P.naturalWidth||ne.width,k=P.naturalHeight||ne.height,U=fe/k,ce=ne.width/ne.height;let Y,le,q,X;U>ce?(Y=ne.width,le=ne.width/U,q=0,X=(ne.height-le)/2):(le=ne.height,Y=ne.height*U,q=(ne.width-Y)/2,X=0);const pe=ne.left-J.left+q+Y*_e.nx,se=ne.top-J.top+X+le*_e.ny,je=Math.max(8,Math.min(J.width-8,pe)),we=Math.max(8,Math.min(J.height-8,se));return e.jsxs("div",{style:{position:"absolute",left:je-8,top:we-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)"}})]})})(),j.map(P=>{const J={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[P.type];return e.jsxs("div",{style:{position:"absolute",left:P.x,top:P.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${J}, 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(${J}, 0.9)`,boxShadow:`0 0 12px rgba(${J}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},P.id)})]}),e.jsxs("div",{onTouchStart:P=>P.stopPropagation(),className:"absolute bottom-0 left-0 right-0 z-[1000] 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:()=>{A(P=>{const ne=P==="touch"?"mouse":"touch";if(ne==="mouse"&&!Ie.current){const J={nx:.5,ny:.5};Ie.current=J,We(J)}return ne})},className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${E==="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:E==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${E==="mouse"?"text-blue-400":"text-slate-400"}`,children:E==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{B(!N),f(!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-[2000]",style:{animation:"slideUp 0.15s ease-out"},children:e.jsx("input",{type:"text",placeholder:"Type & Enter...",value:l,autoFocus:!0,onTouchStart:P=>P.stopPropagation(),onChange:P=>d(P.target.value),onKeyDown:et,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:()=>{f(!T),B(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${T?"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:ge?"rgba(16,185,129,0.12)":"rgba(251,191,36,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:ge?"#10b981":"#fbbf24"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:ge?"#10b981":"#fbbf24"},children:ge?"Connected":"WS"})]}),R>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(R*100),"%"]}),i&&i.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:i.budgetExhausted?"#ef4444":"#94a3b8",background:i.budgetExhausted?"rgba(239,68,68,0.1)":"transparent"},children:i.budgetExhausted?"⚠ Budget":`${i.dailyUsedMinutes}/${i.dailyBudgetMinutes}min`}),u&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:u})]})]}),T&&e.jsxs("div",{onTouchStart:P=>P.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:1001,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: ",R<=(K?$:1)+.01?K?"FILL":"FIT":`${Math.round(R*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:P=>{P.stopPropagation(),F(ne=>Math.max(.5,ne-.25))},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:P=>{P.stopPropagation();const ne=K?$:1;F(ne),h.current=ne,Z(0),G(0)},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:K?"FILL":"FIT"}),e.jsx("button",{onClick:P=>{P.stopPropagation(),F(ne=>Math.min(5,ne+.25))},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("style",{children:`
|
|
9
|
+
`)[0].slice(0,80)})]},`msg-${O}`);if(ue==="terminal"){const W=ee.meta||{},te=W.isRunning?"⏳":"✅",me=W.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:te}),e.jsx("span",{children:me})]}),e.jsx("pre",{className:"chat-msg-body",children:h})]},`msg-${O}`)}if(ue==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:h.slice(0,100)},`msg-${O}`);const z=!oe&&c?on(h):null,Q=z?z.textContent:h,xe=z?Object.entries(z.toolCounts):[],ge=c&&!oe&&!g&&Q.length>G,he=g?h:ge&&!D?Q.slice(0,G):Q;return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${oe?"self-end":"self-start"}`,children:[xe.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[xe.map(([W,te])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",W,te>1?` ×${te}`:""]},W)),(z==null?void 0:z.hasTools)&&e.jsx("button",{onClick:()=>E(W=>{const te=new Set(W);return g?te.delete(L):te.add(L),te}),className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:g?"Collapse":"Original"}),!Q&&ie!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Nt(ie)})]}),(Q||oe)&&e.jsxs("div",{className:`chat-bubble ${oe?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${Q?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:oe?i||"You":r}),ie!=null&&e.jsx("span",{className:"chat-time",children:Nt(ie)})]}),Q&&e.jsx("div",{className:"chat-markdown",children:e.jsx(Ot,{remarkPlugins:[Kt,Ms,Ts],children:he})}),ge&&e.jsx("button",{onClick:()=>$(W=>{const te=new Set(W);return D?te.delete(L):te.add(L),te}),className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:D?"Collapse ↑":`Show more (${Math.round(Q.length/100)*100} chars) ↓`})]})]},`msg-${O}`)}),o&&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 working..."})]})}),e.jsx("div",{className:"min-h-10",ref:T})]})}),zt={background:"#0f1117",foreground:"#cdd6f4",cursor:"#f38ba8",cursorAccent:"#0f1117",selectionBackground:"rgba(166, 227, 161, 0.3)",selectionForeground:"#cdd6f4",black:"#45475a",red:"#f38ba8",green:"#a6e3a1",yellow:"#f9e2af",blue:"#89b4fa",magenta:"#cba6f7",cyan:"#94e2d5",white:"#bac2de",brightBlack:"#585b70",brightRed:"#f38ba8",brightGreen:"#a6e3a1",brightYellow:"#f9e2af",brightBlue:"#89b4fa",brightMagenta:"#cba6f7",brightCyan:"#94e2d5",brightWhite:"#a6adc8"},fs=n.forwardRef(({onInput:t,onResize:s,fontSize:a=13},r)=>{const i=n.useRef(null),c=n.useRef(null),o=n.useRef(null),[p,u]=n.useState(!1);return n.useImperativeHandle(r,()=>({write:m=>{var l;(l=c.current)==null||l.write(m)},clear:()=>{var m;(m=c.current)==null||m.clear()},fit:()=>{var m;try{(m=o.current)==null||m.fit(),c.current&&(s==null||s(c.current.cols,c.current.rows))}catch{}},bumpResize:()=>{var m;try{(m=o.current)==null||m.fit();const l=c.current;if(!l)return;const d=l.cols,v=l.rows;s==null||s(d+5,v),setTimeout(()=>{s==null||s(d,v)},100)}catch{}}})),n.useEffect(()=>{if(!i.current)return;const m=new Bs({cursorBlink:!0,cursorStyle:"bar",fontSize:a,fontFamily:"'JetBrains Mono', 'Fira Code', 'SF Mono', 'Menlo', monospace",fontWeight:"400",letterSpacing:0,lineHeight:1.2,theme:zt,allowTransparency:!0,scrollback:5e3,convertEol:!1}),l=new Ws,d=new Os;m.loadAddon(l),m.loadAddon(d),m.open(i.current),requestAnimationFrame(()=>{l.fit(),s==null||s(m.cols,m.rows),u(!0)});const v=m.onData(x=>{t(x)}),j=new ResizeObserver(()=>{requestAnimationFrame(()=>{try{l.fit(),s==null||s(m.cols,m.rows)}catch{}})});return j.observe(i.current),c.current=m,o.current=l,()=>{v.dispose(),j.disconnect(),m.dispose(),c.current=null,o.current=null}},[a]),e.jsx("div",{ref:i,className:"w-full h-full rounded-lg overflow-hidden transition-opacity duration-200",style:{background:zt.background,opacity:p?1:0}})});fs.displayName="CliTerminal";function ut({label:t,value:s,sub:a,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}),a&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:a})]})}function Ut({value:t,max:s,label:a,color:r="#8b5cf6",detail:i,compact:c=!1}){const o=s>0?Math.min(Math.round(t/s*100),100):0,p=o>85?"#ef4444":o>60?"#f59e0b":r;return c?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:a}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[o,"%"]})]}),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:`${o}%`,background:p}})})]}):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:a}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[o,"%"]})]}),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:`${o}%`,background:`linear-gradient(90deg, ${p}, ${p}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function ln({onAction:t,addLog:s,connState:a,connScreenshot:r,screenshotUsage:i}){const c=n.useRef(null),o=n.useRef(null),p=n.useRef(null),[u,m]=n.useState(null),[l,d]=n.useState(""),[,v]=n.useState(!1),[j,x]=n.useState([]),I=n.useRef(0),[T,f]=n.useState(!1),[N,B]=n.useState(!1),K=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[E,A]=n.useState(K?"mouse":"touch"),[$,C]=n.useState(1),y=n.useRef(!1),[R,F]=n.useState(1),[H,Z]=n.useState(0),[b,G]=n.useState(0),re=n.useRef(0),V=n.useRef(t),ee=n.useRef(null),O=n.useRef(null),ae=n.useRef(!1),oe=n.useRef(null),ue=n.useRef(0),ie=n.useRef(null),L=n.useRef(1),g=n.useRef({x:0,y:0}),D=n.useRef(!1),h=n.useRef(R),z=n.useRef(H),Q=n.useRef(b),xe=n.useRef(E);n.useEffect(()=>{h.current=R},[R]),n.useEffect(()=>{z.current=H},[H]),n.useEffect(()=>{Q.current=b},[b]),n.useEffect(()=>{V.current=t},[t]),n.useEffect(()=>{xe.current=E},[E]),n.useEffect(()=>{var P;(P=c.current)==null||P.focus()},[]);const ge=a==="connected",he=r;n.useEffect(()=>{if(!K||y.current||!he)return;const P=p.current,ne=o.current;if(!P||!ne)return;const J=()=>{const fe=ne.clientWidth,k=ne.clientHeight,U=P.naturalWidth,ce=P.naturalHeight;if(!U||!ce||!fe||!k)return;const Y=Math.min(fe/U,k/ce),q=Math.max(fe/U,k/ce)/Y;q>1.01&&(C(q),F(q),h.current=q),y.current=!0};P.complete&&P.naturalWidth?J():P.addEventListener("load",J,{once:!0})},[he,K]);const ke=.5;n.useEffect(()=>{R<=ke&&(Z(0),G(0))},[R,ke]);const W=(P,ne,J)=>{if(J<=ke)return{x:0,y:0};const fe=(J-1)/(2*J)*100,k=(J-1)/(2*J)*100;return{x:Math.max(-fe,Math.min(fe,P)),y:Math.max(-k,Math.min(k,ne))}},te=(P,ne)=>{if(!p.current)return null;const J=p.current.getBoundingClientRect();return!J.width||!J.height?null:{nx:Math.max(0,Math.min(1,(P-J.left)/J.width)),ny:Math.max(0,Math.min(1,(ne-J.top)/J.height))}},me=(P,ne,J)=>{const fe=o.current;if(!fe)return;const k=fe.getBoundingClientRect(),U=++I.current;x(ce=>[...ce,{id:U,x:P-k.left,y:ne-k.top,type:J}]),setTimeout(()=>x(ce=>ce.filter(Y=>Y.id!==U)),600)},be=(P,ne,J)=>{const fe=p.current,k=o.current;if(!fe||!k)return;const U=fe.getBoundingClientRect(),ce=k.getBoundingClientRect(),Y=fe.naturalWidth||U.width,le=fe.naturalHeight||U.height,q=Y/le,X=U.width/U.height;let pe,se,je,we;q>X?(pe=U.width,se=U.width/q,je=0,we=(U.height-se)/2):(se=U.height,pe=U.height*q,je=(U.width-pe)/2,we=0);const Ne=U.left-ce.left+je+pe*P,w=U.top-ce.top+we+se*ne,S=++I.current;x(M=>[...M,{id:S,x:Ne,y:w,type:J}]),setTimeout(()=>x(M=>M.filter(_=>_.id!==S)),600)},Pe=async P=>{var J;const ne=te(P.clientX,P.clientY);if(ne){m(`Click: ${Math.round(ne.nx*100)}%, ${Math.round(ne.ny*100)}%`),me(P.clientX,P.clientY,"left"),(J=c.current)==null||J.focus();try{const fe=await t("input_click",{nx:ne.nx,ny:ne.ny});fe!=null&&fe.success||s(`❌ Click failed: ${fe==null?void 0:fe.error}`)}catch(fe){s(`❌ Click error: ${fe.message||fe}`)}}},ve=async(P,ne,J,fe=0)=>{try{await t("input_key",{type:J?"char":"keyDown",key:P,code:ne,text:J?P:void 0,unmodifiedText:J?P:void 0,modifiers:fe})}catch(k){s(`❌ Key error: ${k.message||k}`)}},Me=async P=>{if(P.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(P.key)&&P.preventDefault();let J=0;P.altKey&&(J|=1),P.ctrlKey&&(J|=2),P.metaKey&&(J|=4),P.shiftKey&&(J|=8),m(`Key: ${P.key}`),await ve(P.key,P.code,P.key.length===1,J)},et=async P=>{if(P.key==="Enter"){if(P.nativeEvent.isComposing)return;if(l){const ne=l;d(""),m(`IME Sent: ${ne}`);try{const J=await t("input_type",{text:ne});J!=null&&J.success||s(`❌ IME error: ${J==null?void 0:J.error}`)}catch(J){s(`❌ IME error: ${J.message}`)}}else m("Key: Enter"),await ve("Enter","Enter",!1)}};n.useEffect(()=>{const P=c.current;if(!P)return;const ne=J=>{var fe;if((fe=p.current)!=null&&fe.contains(J.target)){J.preventDefault();const k=Date.now();if(k-re.current<40)return;re.current=k;const U=te(J.clientX,J.clientY);if(!U)return;m(`Scroll: ${Math.round(J.deltaY)}`),t("input_wheel",{nx:U.nx,ny:U.ny,deltaX:Math.round(J.deltaX),deltaY:Math.round(J.deltaY)}).catch(()=>{})}};return P.addEventListener("wheel",ne,{passive:!1}),()=>P.removeEventListener("wheel",ne)},[t]);const[_e,We]=n.useState(null),Ie=n.useRef(null);return n.useEffect(()=>{if(E==="mouse"&&!Ie.current){const P={nx:.5,ny:.5};Ie.current=P,We(P)}},[E]),n.useEffect(()=>{const P=c.current;if(!P)return;const ne=Y=>{if(!p.current)return null;const le=p.current.getBoundingClientRect();return!le.width||!le.height?null:{nx:Math.max(0,Math.min(1,(Y.clientX-le.left)/le.width)),ny:Math.max(0,Math.min(1,(Y.clientY-le.top)/le.height))}},J=(Y,le)=>{if(!p.current)return{dnx:0,dny:0};const q=p.current,X=q.getBoundingClientRect(),pe=q.naturalWidth||X.width,se=q.naturalHeight||X.height,je=pe/se,we=X.width/X.height;let Ne,w;return je>we?(Ne=X.width,w=X.width/je):(w=X.height,Ne=X.height*je),{dnx:Y/Ne,dny:le/w}},fe=(Y,le,q)=>{if(q<=1.05)return;const X=-(Y-.5)*100,pe=-(le-.5)*100,se=W(X,pe,q);(Math.abs(se.x-z.current)>.1||Math.abs(se.y-Q.current)>.1)&&(Z(se.x),G(se.y),z.current=se.x,Q.current=se.y)},k=Y=>{const le=o.current;if(le&&Y.target instanceof Node&&le.contains(Y.target))Y.preventDefault();else return;if(Y.touches.length===1){const q=Y.touches[0];ee.current={x:q.clientX,y:q.clientY,time:Date.now()},O.current={x:q.clientX,y:q.clientY},D.current||(ae.current=!1),oe.current=setTimeout(()=>{if(!ae.current&&!D.current)if(ae.current=!0,xe.current==="mouse"){const X=Ie.current||{nx:.5,ny:.5};m("Right Click"),be(X.nx,X.ny,"right"),V.current("input_click",{...X,button:"right"}).catch(()=>{})}else{const X=ne(q);X&&(m("Right Click"),be(X.nx,X.ny,"right"),V.current("input_click",{...X,button:"right"}).catch(()=>{}))}},500)}else if(Y.touches.length===2){clearTimeout(oe.current),ae.current=!0,D.current=!0;const q=Y.touches[1].clientX-Y.touches[0].clientX,X=Y.touches[1].clientY-Y.touches[0].clientY;ie.current=Math.sqrt(q*q+X*X),L.current=h.current,g.current={x:(Y.touches[0].clientX+Y.touches[1].clientX)/2,y:(Y.touches[0].clientY+Y.touches[1].clientY)/2}}},U=Y=>{const le=o.current;if(le&&Y.target instanceof Node&&le.contains(Y.target)&&Y.preventDefault(),Y.touches.length===1&&O.current){const q=Y.touches[0],X=q.clientX-O.current.x,pe=q.clientY-O.current.y;if(!ae.current&&ee.current){const se=q.clientX-ee.current.x,je=q.clientY-ee.current.y;Math.sqrt(se*se+je*je)>8&&(ae.current=!0,clearTimeout(oe.current))}if(ae.current)if(xe.current==="mouse"){const se=J(X,pe),je=Ie.current||{nx:.5,ny:.5},we=Math.max(0,Math.min(1,je.nx+se.dnx)),Ne=Math.max(0,Math.min(1,je.ny+se.dny));Ie.current={nx:we,ny:Ne},We({nx:we,ny:Ne}),m(`Cursor: ${Math.round(we*100)}%, ${Math.round(Ne*100)}%`),fe(we,Ne,h.current);const w=Date.now();w-re.current>=30&&(re.current=w,V.current("input_mouseMoved",{nx:we,ny:Ne}).catch(()=>{}))}else if(h.current>1){const se=o.current;if(se){const je=se.clientWidth,we=se.clientHeight,Ne=z.current+X/je*100,w=Q.current+pe/we*100,S=W(Ne,w,h.current);Z(S.x),G(S.y),z.current=S.x,Q.current=S.y}}else{const se=ne(q);if(se){const je=Date.now();je-re.current>=40&&(re.current=je,m("Scroll"),V.current("input_wheel",{nx:se.nx,ny:se.ny,deltaX:Math.round(-X*2.5),deltaY:Math.round(-pe*2.5)}).catch(()=>{}))}}O.current={x:q.clientX,y:q.clientY}}else if(Y.touches.length===2&&ie.current!==null){const q=Y.touches[1].clientX-Y.touches[0].clientX,X=Y.touches[1].clientY-Y.touches[0].clientY,se=Math.sqrt(q*q+X*X)/ie.current,je=(Y.touches[0].clientX+Y.touches[1].clientX)/2,we=(Y.touches[0].clientY+Y.touches[1].clientY)/2,Ne=je-g.current.x,w=we-g.current.y,S=Math.abs(se-1)>.03;if(xe.current==="mouse"){if(S){const M=Math.max(ke,Math.min(5,L.current*se));F(M),h.current=M}else if(Math.abs(Ne)>2||Math.abs(w)>2){const M=Ie.current||{nx:.5,ny:.5},_=Date.now();_-re.current>=30&&(re.current=_,m("Scroll"),V.current("input_wheel",{nx:M.nx,ny:M.ny,deltaX:Math.round(-Ne*3),deltaY:Math.round(-w*3)}).catch(()=>{}))}}else{const M=Math.max(ke,Math.min(5,L.current*se));F(M),h.current=M;const _=o.current;if(_&&M>1){const de=_.clientWidth,ye=_.clientHeight,Se=z.current+Ne/de*100,Ee=Q.current+w/ye*100,$e=W(Se,Ee,M);Z($e.x),G($e.y),z.current=$e.x,Q.current=$e.y}}g.current={x:je,y:we}}},ce=Y=>{var le;if(clearTimeout(oe.current),ie.current=null,Y.touches.length===1&&D.current){const q=Y.touches[0];ee.current={x:q.clientX,y:q.clientY,time:Date.now()},O.current={x:q.clientX,y:q.clientY},ae.current=!0;return}if(Y.touches.length===0){if(D.current){D.current=!1,ae.current=!1;return}if(Y.changedTouches.length===1&&!ae.current){const q=Y.changedTouches[0],X=Date.now(),pe=X-(((le=ee.current)==null?void 0:le.time)||0);if(pe<60||pe>400){ae.current=!1;return}if(ee.current){const se=q.clientX-ee.current.x,je=q.clientY-ee.current.y;if(Math.sqrt(se*se+je*je)>12){ae.current=!1;return}}if(xe.current==="mouse"){const se=Ie.current||ne(q);se&&(m(`Click: ${Math.round(se.nx*100)}%, ${Math.round(se.ny*100)}%`),be(se.nx,se.ny,"left"),V.current("input_click",{...se}).catch(()=>{}))}else{const se=ne(q);if(!se)return;X-ue.current<300?(m("Double tap"),be(se.nx,se.ny,"double"),V.current("input_click",{...se,clickCount:2}).catch(()=>{}),ue.current=0):(m(`Tap: ${Math.round(se.nx*100)}%, ${Math.round(se.ny*100)}%`),be(se.nx,se.ny,"left"),V.current("input_click",{...se}).catch(()=>{}),ue.current=X)}}ae.current=!1}};return P.addEventListener("touchstart",k,{passive:!1}),P.addEventListener("touchmove",U,{passive:!1}),P.addEventListener("touchend",ce,{passive:!1}),()=>{P.removeEventListener("touchstart",k),P.removeEventListener("touchmove",U),P.removeEventListener("touchend",ce),clearTimeout(oe.current)}},[]),e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:Me,onContextMenu:P=>P.preventDefault(),onFocus:()=>v(!0),onBlur:()=>v(!1),tabIndex:0,children:[e.jsxs("div",{ref:o,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[he?e.jsx("img",{ref:p,src:he,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${R}) translate(${H}%, ${b}%)`,transformOrigin:"center center",cursor:E==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:Pe,onContextMenu:P=>P.preventDefault(),onDragStart:P=>P.preventDefault()}):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:"Connecting to Host..."}),e.jsx("div",{className:"text-[11px] text-white/40",children:"Waiting for the remote stream to catch up"})]}),E==="mouse"&&_e&&he&&p.current&&(()=>{var Ne;const P=p.current,ne=P.getBoundingClientRect(),J=(Ne=o.current)==null?void 0:Ne.getBoundingClientRect();if(!J)return null;const fe=P.naturalWidth||ne.width,k=P.naturalHeight||ne.height,U=fe/k,ce=ne.width/ne.height;let Y,le,q,X;U>ce?(Y=ne.width,le=ne.width/U,q=0,X=(ne.height-le)/2):(le=ne.height,Y=ne.height*U,q=(ne.width-Y)/2,X=0);const pe=ne.left-J.left+q+Y*_e.nx,se=ne.top-J.top+X+le*_e.ny,je=Math.max(8,Math.min(J.width-8,pe)),we=Math.max(8,Math.min(J.height-8,se));return e.jsxs("div",{style:{position:"absolute",left:je-8,top:we-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)"}})]})})(),j.map(P=>{const J={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[P.type];return e.jsxs("div",{style:{position:"absolute",left:P.x,top:P.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${J}, 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(${J}, 0.9)`,boxShadow:`0 0 12px rgba(${J}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},P.id)})]}),e.jsxs("div",{onTouchStart:P=>P.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:()=>{A(P=>{const ne=P==="touch"?"mouse":"touch";if(ne==="mouse"&&!Ie.current){const J={nx:.5,ny:.5};Ie.current=J,We(J)}return ne})},className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${E==="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:E==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${E==="mouse"?"text-blue-400":"text-slate-400"}`,children:E==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{B(!N),f(!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:l,autoFocus:!0,onTouchStart:P=>P.stopPropagation(),onChange:P=>d(P.target.value),onKeyDown:et,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:()=>{f(!T),B(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${T?"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:ge?"rgba(16,185,129,0.12)":"rgba(251,191,36,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:ge?"#10b981":"#fbbf24"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:ge?"#10b981":"#fbbf24"},children:ge?"Connected":"WS"})]}),R>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(R*100),"%"]}),i&&i.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:i.budgetExhausted?"#ef4444":"#94a3b8",background:i.budgetExhausted?"rgba(239,68,68,0.1)":"transparent"},children:i.budgetExhausted?"⚠ Budget":`${i.dailyUsedMinutes}/${i.dailyBudgetMinutes}min`}),u&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:u})]})]}),T&&e.jsxs("div",{onTouchStart:P=>P.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: ",R<=(K?$:1)+.01?K?"FILL":"FIT":`${Math.round(R*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:P=>{P.stopPropagation(),F(ne=>Math.max(.5,ne-.25))},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:P=>{P.stopPropagation();const ne=K?$:1;F(ne),h.current=ne,Z(0),G(0)},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:K?"FILL":"FIT"}),e.jsx("button",{onClick:P=>{P.stopPropagation(),F(ne=>Math.min(5,ne+.25))},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("style",{children:`
|
|
10
10
|
@keyframes slideUp {
|
|
11
11
|
from { opacity: 0; transform: translateY(6px); }
|
|
12
12
|
to { opacity: 1; transform: translateY(0); }
|
|
@@ -37,7 +37,7 @@ var Cs=Object.defineProperty;var Is=(t,s,a)=>s in t?Cs(t,s,{enumerable:!0,config
|
|
|
37
37
|
}
|
|
38
38
|
`})]})}function gs({activeConv:t,onModalButton:s}){const[a,r]=n.useState(null);if(n.useEffect(()=>{r(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const i=o=>{a||(r(o),s(o))},c=o=>o.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(xs,{size:14})," ",a?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((o,p)=>{const u=c(o).toLowerCase(),m=/^(run|approve|accept|yes|allow|always)/.test(u),l=/^(reject|deny|delete|remove|abort)/.test(u),d=a===o,v=a!==null;return e.jsx("button",{onClick:()=>i(o),disabled:v,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${m?"bg-white text-amber-700 font-extrabold":l?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${v&&!d?"opacity-40":"opacity-100"} ${v?"cursor-not-allowed":"cursor-pointer"}`,children:d?"⏳ ...":c(o)},p)})})]})]})}const Le=new Map;function un({ideId:t,ideType:s,agentType:a,agentName:r,serverModel:i,serverMode:c,acpConfigOptions:o,acpModes:p}){var L;const{sendCommand:u}=Ye(),m=!!(o||p),l=`${t}:${a}`,d=Le.get(l),[v,j]=n.useState(!1),[x,I]=n.useState(!1),[T,f]=n.useState((d==null?void 0:d.models)||[]),[N,B]=n.useState((d==null?void 0:d.modes)||[]),K=g=>g?typeof g=="string"?g:typeof g=="object"?g.name||g.id||JSON.stringify(g):String(g):"",[E,A]=n.useState(K(i)),[$,C]=n.useState(K(c)),[y,R]=n.useState(!1),[F,H]=n.useState(!1),Z=n.useRef(0),b=g=>g.map(D=>typeof D=="string"?D:(D==null?void 0:D.name)||(D==null?void 0:D.id)||String(D));n.useEffect(()=>{if(o){const g=o.find(D=>D.category==="model");if(g){const D=b(g.options.map(z=>z.value));f(D),g.currentValue&&A(K(g.currentValue));const h=Le.get(l)||{models:[],modes:[]};Le.set(l,{...h,models:D})}}if(p&&p.length>0){const g=b(p.map(h=>h.id));B(g);const D=Le.get(l)||{models:[],modes:[]};Le.set(l,{...D,modes:g})}else if(o){const g=o.find(D=>D.category!=="model");if(g){const D=b(g.options.map(z=>z.value));B(D),g.currentValue&&C(K(g.currentValue));const h=Le.get(l)||{models:[],modes:[]};Le.set(l,{...h,modes:D})}}},[o,p,l]),n.useEffect(()=>{j(!1),I(!1),A(K(i)),C(K(c));const g=Le.get(l);g?(f(g.models),B(g.modes)):(f([]),B([]))},[t,a]),n.useEffect(()=>{i&&Date.now()>Z.current&&A(K(i))},[i]),n.useEffect(()=>{c&&Date.now()>Z.current&&C(K(c))},[c]);const G=n.useCallback(async(g,D={})=>{const h={...D},z=t.split(":");return z.length>=3&&(z[1]==="ide"||z[1]==="cli"||z[1]==="acp")&&(h._targetInstance=z.slice(2).join(":"),h._targetType=z[1]),await u(t,g,h)},[t]),re=async()=>{var g,D;if(T.length>0){j(!v);return}if(m){j(!0);return}R(!0);try{const h=await G("list_extension_models",{agentType:a,ideType:s}),z=(h==null?void 0:h.models)||((g=h==null?void 0:h.result)==null?void 0:g.models)||[],Q=b(z);f(Q),h!=null&&h.current&&A(K(h.current)),(D=h==null?void 0:h.result)!=null&&D.current&&A(K(h.result.current));const xe=Le.get(l)||{models:[],modes:[]};Le.set(l,{...xe,models:Q}),j(!0)}catch{}finally{R(!1)}},V=async()=>{var g,D;if(N.length>0){I(!x);return}if(m){I(!0);return}H(!0);try{const h=await G("list_extension_modes",{agentType:a,ideType:s}),z=(h==null?void 0:h.modes)||((g=h==null?void 0:h.result)==null?void 0:g.modes)||[],Q=b(z);B(Q),h!=null&&h.current&&C(K(h.current)),(D=h==null?void 0:h.result)!=null&&D.current&&C(K(h.result.current));const xe=Le.get(l)||{models:[],modes:[]};Le.set(l,{...xe,modes:Q}),I(!0)}catch{}finally{H(!1)}},ee=async g=>{j(!1),A(g),Z.current=Date.now()+5e3;try{m?await G("change_model",{agentType:a,ideType:s,model:g}):await G("set_extension_model",{agentType:a,ideType:s,model:g})}catch{}},O=m&&!(p&&p.length>0)&&(o==null?void 0:o.some(g=>g.category!=="model")),ae=O?(L=o==null?void 0:o.find(g=>g.category!=="model"))==null?void 0:L.configId:void 0,oe=async g=>{I(!1),C(g),Z.current=Date.now()+5e3;try{m&&O&&ae?await G("set_thought_level",{agentType:a,ideType:s,configId:ae,value:g}):m?await G("set_mode",{agentType:a,ideType:s,mode:g}):await G("set_extension_mode",{agentType:a,ideType:s,mode:g})}catch{}},ie={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"}[a]||"#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 uppercase opacity-70",style:{color:ie},children:r}),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:v?`${ie}55`:"transparent",border:"1px solid",color:E?"var(--text-primary)":"var(--text-muted)"},onClick:re,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),y?"...":E||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),v&&T.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>j(!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"}),T.map(g=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:g===E?`${ie}18`:"transparent",color:g===E?ie:"var(--text-secondary)",fontWeight:g===E?600:400,borderLeft:g===E?`2px solid ${ie}`:"2px solid transparent"},onMouseEnter:D=>{D.currentTarget.style.background=`${ie}12`},onMouseLeave:D=>{D.currentTarget.style.background=g===E?`${ie}18`:"transparent"},onClick:()=>ee(g),children:g},g))]})]})]}),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:x?`${ie}55`:"transparent",border:"1px solid",color:$?"var(--text-primary)":"var(--text-muted)"},onClick:V,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:O?"🧠":"⚡"}),F?"...":$||(O?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),x&&N.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>I(!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:O?"SELECT THINKING LEVEL":"SELECT MODE"}),N.map(g=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:g===$?`${ie}18`:"transparent",color:g===$?ie:"var(--text-secondary)",fontWeight:g===$?600:400,borderLeft:g===$?`2px solid ${ie}`:"2px solid transparent"},onMouseEnter:D=>{D.currentTarget.style.background=`${ie}12`},onMouseLeave:D=>{D.currentTarget.style.background=g===$?`${ie}18`:"transparent"},onClick:()=>oe(g),children:g},g))]})]})]})]})}const Ue=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),Oe=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function bs({activeConv:t,ides:s,agentInput:a,setAgentInput:r,handleSendChat:i,handleFocusAgent:c,isFocusingAgent:o,messageReceivedAt:p,actionLogs:u,userName:m}){const l=n.useRef(null),{sendCommand:d}=Ye(),v=n.useRef(new Map),j=n.useCallback(y=>(v.current.has(y)||v.current.set(y,{messages:[],offset:0,hasMore:!0,error:null}),v.current.get(y)),[]),x=n.useCallback((y,R)=>{const F=j(y);v.current.set(y,{...F,...R}),I(H=>H+1)},[j]),[,I]=n.useState(0),T=t.tabKey,f=j(T),N=f.messages,B=f.hasMore,K=f.error,[E,A]=n.useState(!1),$=n.useCallback(async()=>{var F,H;if(E)return;const y=t.tabKey,R=j(y);A(!0),x(y,{error:null});try{const Z=s.find(ae=>ae.id===t.ideId),b=(Z==null?void 0:Z.daemonId)||((F=t.ideId)==null?void 0:F.split(":")[0])||"";if(!b){x(y,{hasMore:!1});return}const G=t.ideType||t.agentType||"",re=(t.ideId||"").split(":"),V=re.length>=3?re.slice(2).join(":"):void 0,ee=await d(b,"chat_history",{agentType:G,offset:R.offset,limit:30,instanceId:V}),O=(ee==null?void 0:ee.result)??ee;if(((H=O.messages)==null?void 0:H.length)>0){const ae=j(y);x(y,{messages:[...O.messages,...ae.messages],offset:ae.offset+O.messages.length,hasMore:!!O.hasMore})}else x(y,{hasMore:!!O.hasMore})}catch(Z){const b=(Z==null?void 0:Z.message)||"";b.includes("P2P not available")||b.includes("channel not open")||b.includes("P2P not connected")||b.includes("timeout")?x(y,{error:"Connection not ready — tap to retry"}):x(y,{hasMore:!1,error:"Failed to load history"})}finally{A(!1)}},[E,s,t,d,j,x]),C=(()=>{const y=t.messages.map((H,Z)=>{const b=`${t.ideId}-${H.id??`i-${Z}`}`;return{...H,receivedAt:H.receivedAt||p[b]||0}});if(N.length===0)return y;const R=new Set(y.map(H=>`${H.role}:${(H.content||"").slice(0,100)}`));return[...N.filter(H=>!R.has(`${H.role}:${(H.content||"").slice(0,100)}`)),...y]})();return e.jsxs(e.Fragment,{children:[e.jsx(cn,{messages:C,actionLogs:u.filter(y=>y.ideId===t.tabKey).sort((y,R)=>y.timestamp-R.timestamp),agentName:t.agentName||t.displayPrimary||"Agent",userName:m,isCliMode:Ue(t)||Oe(t),isWorking:t.status==="working",contextKey:t.tabKey,onLoadMore:$,isLoadingMore:E,hasMoreHistory:B,loadError:K??void 0,emptyState:t.messages.length===0?t.connectionState==="connecting"||t.connectionState==="new"?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"})]})]}):t.status==="not_monitored"?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(ms,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:c,disabled:o,className:"btn btn-primary",children:o?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(At,{size:14})," Open ",t.displayPrimary," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Click to switch monitoring to this agent"})]}):t.status==="panel_hidden"?e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx(en,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Panel is not visible in IDE"}),e.jsx("button",{onClick:c,disabled:o,className:"btn btn-primary",children:o?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(At,{size:14})," Open ",t.displayPrimary," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Open the agent sidebar in your IDE to start viewing messages"})]}):t.status==="idle"&&!E?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..."})]}):void 0:void 0}),!Ue(t)&&(()=>{var R,F,H,Z;const y=s.find(b=>b.id===t.ideId);return e.jsx(un,{ideId:t.ideId,ideType:t.ideType,agentType:t.streamSource==="agent-stream"?t.agentType:((F=(R=y==null?void 0:y.agents)==null?void 0:R[0])==null?void 0:F.type)||t.ideType,agentName:t.streamSource==="agent-stream"?t.agentName:((Z=(H=y==null?void 0:y.agents)==null?void 0:H[0])==null?void 0:Z.name)||t.agentName,serverModel:(y==null?void 0:y.currentModel)||void 0,serverMode:(y==null?void 0:y.currentPlan)||void 0,acpConfigOptions:Oe(t)?y==null?void 0:y.acpConfigOptions:void 0,acpModes:Oe(t)?y==null?void 0:y.acpModes:void 0})})(),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:l,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:a,onChange:y=>r(y.target.value),onPaste:y=>{const R=y.clipboardData.getData("text");R&&r(F=>F+R),y.preventDefault()},onKeyDown:y=>{if(y.key==="Enter"){if(y.nativeEvent.isComposing){y.preventDefault();return}y.preventDefault(),i()}},onBlur:y=>{if(window.innerWidth<768){const R=y.relatedTarget;if((R==null?void 0:R.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:i,disabled:!a.trim(),className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${a.trim()?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:a.trim()?{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:a.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}const kt=new Set,ys={emit(t,s){for(const a of kt)a(t,s)},on(t){return kt.add(t),()=>{kt.delete(t)}}};function xn({activeConv:t,ptyBuffers:s,terminalRef:a,agentInput:r,setAgentInput:i,handleSendChat:c,handleModalButton:o}){var j;const p=n.useRef(null),{sendCommand:u,sendData:m}=Ye(),l=(j=t.ideId)!=null&&j.includes(":cli:")?t.ideId.split(":cli:")[1]:"",d=t.tabKey,v=t.ideType||t.agentType||"";return n.useEffect(()=>{const x=s.current.get(d);if(x&&x.length>0){const I=setTimeout(()=>{var T;for(const f of x)(T=a.current)==null||T.write(f);requestAnimationFrame(()=>{var f;(f=a.current)==null||f.bumpResize()})},100);return()=>clearTimeout(I)}},[d]),n.useEffect(()=>{const x=ys.on((I,T)=>{var N;if(!T)return;(I===l||I===v)&&((N=a.current)==null||N.write(T))});return()=>{x()}},[l,v]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-[var(--surface-primary)] border-b border-border-subtle shrink-0",children:[e.jsx("div",{className:"flex gap-1",children:e.jsx("div",{className:"px-3 py-1 rounded-md text-[11px] font-semibold bg-accent text-white",children:"⬛ Terminal"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[t.agentName," — Terminal"]}),e.jsx("button",{onClick:()=>{if(!a.current||!t)return;const x=s.current.get(t.tabKey);if(x&&x.length>0)for(const I of x)a.current.write(I);requestAnimationFrame(()=>{requestAnimationFrame(()=>{var I;(I=a.current)==null||I.bumpResize()})})},title:"Refresh terminal (replay buffer + TUI redraw)",className:"px-2 py-0.5 rounded-[5px] text-[11px] bg-bg-secondary text-text-secondary border border-border-subtle cursor-pointer leading-none",children:"↺"}),e.jsx("button",{onClick:async()=>{var T;const x=(T=t.ideId)!=null&&T.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";if(!window.confirm(`Stop ${x}?
|
|
39
39
|
This will terminate the CLI process.`))return;const I=t.ideId||t.daemonId||"";try{await u(I,"stop_cli",{cliType:x})}catch(f){console.error("Stop CLI failed:",f)}},title:"Stop CLI process",className:"px-2 py-0.5 rounded-[5px] text-[11px] bg-red-500/[0.08] text-red-400 border border-red-500/30 cursor-pointer leading-none font-semibold",children:"■ Stop"})]})]}),e.jsx(gs,{activeConv:t,onModalButton:o}),e.jsx("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:e.jsx(fs,{ref:a,onInput:x=>{var f;const I=t.ideId||t.daemonId||"",T=(f=t.ideId)!=null&&f.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";m!=null&&m(I,{type:"pty_input",cliType:T,data:x})||u(I,"pty_input",{cliType:T,data:x}).catch(console.error)},onResize:(x,I)=>{var N;const T=t.ideId||t.daemonId||"",f=(N=t.ideId)!=null&&N.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";m!=null&&m(T,{type:"pty_resize",cliType:f,cols:x,rows:I})||u(T,"pty_resize",{cliType:f,cols:x,rows:I,force:!0}).catch(()=>{})}},t.tabKey)}),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:p,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:r,onChange:x=>i(x.target.value),onPaste:x=>{const I=x.clipboardData.getData("text");I&&i(T=>T+I),x.preventDefault()},onKeyDown:x=>{if(x.key==="Enter"){if(x.nativeEvent.isComposing){x.preventDefault();return}x.preventDefault(),c()}},className:"w-full h-9 rounded-[18px] px-4 bg-bg-secondary text-[13px] text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:c,disabled:!r.trim(),className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${r.trim()?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:r.trim()?{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:r.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function mn({wsStatus:t,showReconnected:s,loginUrl:a}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"violet",c={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))"},o={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)"},p={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:c[i],borderBottom:o[i],color:p[i]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(a?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:a,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"]})]})}let pn=ot;function jt(){return pn()}class hn{constructor(){Ae(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,a){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(a),()=>{var r;(r=this.listeners.get(s))==null||r.delete(a)}}emit(s,...a){var r;(r=this.listeners.get(s))==null||r.forEach(i=>i(...a))}}let fn=new hn;class gn{constructor(){Ae(this,"ptyCallbacks",new Set)}sendPtyInput(s,a,r){return!1}sendPtyResize(s,a,r,i){return!1}async requestChatHistory(s,a,r,i,c){return{messages:[],hasMore:!1}}retryConnection(s){}getState(s){return"disconnected"}sendData(s,a){return!1}get(s){}onScreenshot(s,a){return()=>{}}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,a){this.ptyCallbacks.forEach(r=>r(s,a))}}let Re=new gn,bn=Re;const St=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),Ct=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function yn({activeConv:t,agentCount:s,wsStatus:a,isConnected:r,onOpenHistory:i}){const c=lt(),o=jt(),p=o.p2pStates||{},u=o.ides||[],m=r?"#22c55e":a==="connected"?"#eab308":"#ef4444",l=r?"0 0 4px #22c55e80":a==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",d=u.filter(f=>f.type==="adhdev-daemon"),v=Object.values(p),j=v.filter(f=>f==="connected").length,x=v.filter(f=>f==="connecting"||f==="new"||f==="checking").length,T=a!=="connected"||d.length===0?null:x>0&&j===0?"P2P connecting...":j>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(bt,{size:18}),e.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),e.jsx("span",{className:"header-title-mobile",children:(t==null?void 0:t.displayPrimary)||"Dashboard"}),e.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:m,boxShadow:l}})})]}),e.jsxs("div",{className:"header-subtitle text-[11px] items-center gap-1",children:[s," agent",s!==1?"s":""," active",e.jsx("span",{title:r?"Connected":a==="connected"?"Partial":"Disconnected",className:"inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:m,boxShadow:l}}),T&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",T]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&!St(t)&&!Ct(t)&&e.jsxs("button",{onClick:()=>c(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(ps,{size:14})," IDE"]}),t&&!St(t)&&!Ct(t)&&e.jsx("button",{onClick:i,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Js,{size:16})}),t&&!St(t)&&!Ct(t)&&e.jsx("button",{onClick:()=>c(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(dt,{size:16})})]})]})}function De(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function jn(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const a=Math.floor(s/60),r=s%60;if(a<24)return r>0?`${a}h ${r}m`:`${a}h`;const i=Math.floor(a/24),c=a%24;return`${i}d ${c}h`}function Yt(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Gt(t){return(t.id||"").includes(":cli:")}function Xt(t){return(t.id||"").includes(":acp:")}function _t(t,s){return De(t)}function vn(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,a=["generating","streaming","active","connected","idle","panel_hidden"];for(const r of t){const i=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),c=s.get(i);if(!c){s.set(i,r);continue}const o=a.indexOf(c.status||"idle"),p=a.indexOf(r.status||"idle");p>=0&&(o<0||p<o)&&s.set(i,r)}return Array.from(s.values())}function wn({activeConv:t,ides:s,isCreatingChat:a,isRefreshingHistory:r,onClose:i,onNewChat:c,onSwitchSession:o,onRefreshHistory:p}){var d;const u=s.find(v=>v.id===t.ideId),m=(u==null?void 0:u.chats)||[],l=(d=u==null?void 0:u.activeChat)==null?void 0:d.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:i,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"card fade-in relative w-[90%] max-w-[500px] max-h-[80vh] flex flex-col p-0 overflow-hidden shadow-[0_20px_40px_rgba(0,0,0,0.4)] rounded-[20px]",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-subtle flex justify-between items-center bg-[var(--surface-primary)]",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"m-0 text-lg font-extrabold",children:"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",De(t.ideType)]})]}),e.jsx("button",{onClick:i,className:"bg-transparent border-none text-xl text-text-muted cursor-pointer",children:"✕"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 bg-bg-primary",children:[e.jsx("button",{onClick:c,disabled:a,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:a?"⌛ Creating...":"+ Start New Chat Session"}),m.map(v=>e.jsxs("div",{onClick:()=>{o(t.ideId,v.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${l===v.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${l===v.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:v.title||"Untitled Session"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[v.id.substring(0,12),"..."]}),l===v.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},v.id)),m.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(an,{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:p,disabled:r,className:"btn btn-secondary btn-sm rounded-[10px]",children:r?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Qs,{size:13})," Refresh History"]})})})]})]})}const Vt={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function Nn({toasts:t,onDismiss:s,onClickToast:a}){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]",style:{background:Vt[r.type]||Vt.info},onClick:()=>{var i;(i=r.actions)!=null&&i.length||(a&&a(r),s(r.id))},children:[e.jsx("div",{children:r.message}),r.actions&&r.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-2",children:r.actions.map((i,c)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${i.variant==="primary"?"bg-white text-amber-700 hover:bg-gray-100":i.variant==="danger"?"bg-red-500/30 text-white hover:bg-red-500/50":"bg-white/20 text-white hover:bg-white/30"}`,onClick:o=>{o.stopPropagation(),i.onClick(),s(r.id)},children:i.label},c))})]},r.id))})}const kn=t=>(t.id||"").includes(":cli:")||(t.id||"").includes(":acp:")||(t.id||"").includes(":ide:")?!0:t.daemonId!==t.id;function Sn(t){return t.workspace||""}function Cn(t,s,a,r){var c;const i={};if(a)for(const o of a){const p=o;if(p.type==="adhdev-daemon"||p.daemonMode){const u=p.machine||{},m=p.machineNickname,l=u.hostname||((c=p.system)==null?void 0:c.hostname)||"",d=m||(l&&l!=="Unknown"?l.replace(/\.local$/,""):null)||`Machine ${(p.id||"").substring(0,6)}`;i[p.id]=d}}return t.flatMap(o=>{var N,B,K,E,A;const p=[],u=o.daemonId&&i[o.daemonId]||void 0,m=o.daemonId||((N=o.id)==null?void 0:N.split(":")[0])||o.id,l=r?r[m]||"new":void 0,d=Sn(o),v=De(o.type),j=o.agentStreams,x=Array.isArray(j)?j.map($=>({...$,activeModal:$.activeModal??void 0})):[],I=kn(o),T=o.activeChat||{title:""},f=T.title&&String(T.title).trim()?String(T.title).trim():"";if(I){const $=_t(o.type),C=(B=o.agents)==null?void 0:B[0],y=(K=o.activeChat)==null?void 0:K.activeModal,R=y&&Array.isArray(y.buttons)&&y.buttons.length>0,F=(E=o.activeChat)==null?void 0:E.status,H=F==="generating"||F==="loading"||F&&F.toLowerCase()==="thinking",b=R||F==="waiting_approval"?"waiting_approval":H?"working":(C==null?void 0:C.status)||"idle",G=o.activeChat||{title:"",messages:[]};let re=G.title&&String(G.title).trim()?String(G.title).trim():"";const V=(A=o.activeChat)==null?void 0:A.id,ee=o.chats;if(V&&Array.isArray(ee)&&ee.length>0){const ie=ee.find(L=>L.id===V||L.id&&String(L.id)===String(V));ie!=null&&ie.title&&String(ie.title).trim()&&(re=String(ie.title).trim())}const O=G.messages||[],ae=s[o.id]||[],oe=new Map;O.filter(ie=>ie.role==="user").forEach(ie=>{oe.set(ie.content,(oe.get(ie.content)||0)+1)});const ue=ae.filter(ie=>{const L=oe.get(ie.content)||0;return L>0?(oe.set(ie.content,L-1),!1):!0});p.push({ideId:o.id,daemonId:o.daemonId||void 0,agentName:$,agentType:Ue(o)||Oe(o)?o.type:(C==null?void 0:C.type)||"ide-native",status:b,title:re,messages:[...O,...ue],ideType:o.type,workspaceName:d,displayPrimary:re||d||$,displaySecondary:v,cdpConnected:o.cdpConnected,modalButtons:R?y.buttons:void 0,modalMessage:R?y.message:void 0,streamSource:"native",tabKey:o.id,machineName:u,connectionState:l})}if(I&&(Ue(o)||Oe(o)))return p;for(const $ of x){const C=$.activeModal&&Array.isArray($.activeModal.buttons)&&$.activeModal.buttons.length>0,y=C?"waiting_approval":$.status==="streaming"?"working":$.status,R=`${o.id}:${$.agentType}`,F=$.messages||[],H=s[R]||[],Z=new Map;F.filter(G=>G.role==="user").forEach(G=>{Z.set(G.content,(Z.get(G.content)||0)+1)});const b=H.filter(G=>{const re=Z.get(G.content)||0;return re>0?(Z.set(G.content,re-1),!1):!0});p.push({ideId:o.id,daemonId:o.daemonId||void 0,agentName:$.agentName,agentType:$.agentType,status:y,title:"",messages:[...F,...b],ideType:$.agentType,workspaceName:d,displayPrimary:f||d||$.agentName,displaySecondary:`${v}·${$.agentName}`,cdpConnected:o.cdpConnected,modalButtons:C?$.activeModal.buttons:void 0,modalMessage:C?$.activeModal.message:void 0,streamSource:"agent-stream",tabKey:R,machineName:u,connectionState:l})}return p.length===0&&p.push({ideId:o.id,daemonId:o.daemonId||void 0,agentName:_t(o.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:o.type,workspaceName:d,displayPrimary:d||v,displaySecondary:v,cdpConnected:o.cdpConnected,streamSource:"native",tabKey:o.id,connectionState:l}),p})}function In(t,s){var p,u,m,l;const a=[],{daemonId:r,existingDaemon:i,timestamp:c}=s,o=c||t.timestamp||Date.now();a.push({...i||{},id:r,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:o,...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},..."system"in t&&{system:t.system},..."hostname"in t&&{hostname:t.hostname},...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:t.managedIdes.some(d=>d.cdpConnected),managedIdeIds:t.managedIdes.map(d=>`${r}:ide:${d.instanceId}`),managedCliIds:t.managedClis.map(d=>d.id?`${r}:cli:${d.id}`:`${r}:cli:${d.cliType}`),managedAcpIds:t.managedAcps.map(d=>d.id?`${r}:acp:${d.id}`:`${r}:acp:${d.acpType}`)});for(const d of t.managedIdes)a.push({id:`${r}:ide:${d.instanceId}`,type:d.ideType,ideType:d.ideType,version:d.ideVersion,status:d.cdpConnected?"online":"detected",daemonId:r,instanceId:d.instanceId,workspace:d.workspace,terminals:d.terminals,agents:d.aiAgents,activeChat:d.activeChat,chats:d.chats,agentStreams:d.agentStreams,cdpConnected:d.cdpConnected,currentModel:d.currentModel,currentPlan:d.currentPlan,currentAutoApprove:d.currentAutoApprove,timestamp:o});for(const d of t.managedClis){const v=d.id?`${r}:cli:${d.id}`:`${r}:cli:${d.cliType}`;a.push({id:v,type:d.cliType,ideType:d.cliType,agentType:d.cliType,status:d.status||"running",daemonId:r,instanceId:d.id,cliName:d.cliName,mode:d.mode||"terminal",workspace:d.workspace,activeChat:d.activeChat,agentStreams:[{agentType:d.cliType,agentName:d.cliName,extensionId:"cli-agent",status:d.status==="generating"?"streaming":d.status==="waiting_approval"?"waiting_approval":"idle",messages:((p=d.activeChat)==null?void 0:p.messages)||[],inputContent:"",activeModal:(u=d.activeChat)==null?void 0:u.activeModal}],timestamp:o,_isCli:!0})}for(const d of t.managedAcps){const v=d.id?`${r}:acp:${d.id}`:`${r}:acp:${d.acpType}`;a.push({id:v,type:d.acpType,ideType:d.acpType,agentType:d.acpType,status:d.status||"running",daemonId:r,instanceId:d.id,cliName:d.acpName,mode:"chat",workspace:d.workspace,activeChat:d.activeChat,currentModel:d.currentModel,currentPlan:d.currentPlan,acpConfigOptions:d.acpConfigOptions,acpModes:d.acpModes,agentStreams:[{agentType:d.acpType,agentName:d.acpName,extensionId:"acp-agent",status:d.status==="generating"?"streaming":d.status==="waiting_approval"?"waiting_approval":"idle",messages:((m=d.activeChat)==null?void 0:m.messages)||[],inputContent:"",activeModal:(l=d.activeChat)==null?void 0:l.activeModal}],timestamp:o,_isAcp:!0})}return a}const js="adhdev_notification_prefs",qt={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0};function Mn(){try{const t=localStorage.getItem(js);if(t){const s=JSON.parse(t);return{...qt,...s}}}catch{}return{...qt}}function Tn(t){try{localStorage.setItem(js,JSON.stringify(t))}catch{}}let He=Mn(),pt=[];function En(){pt.forEach(t=>t())}function $n(t){He={...He,...t},Tn(He),En()}function An(){const[,t]=n.useState(0);n.useEffect(()=>{const a=()=>t(r=>r+1);return pt.push(a),()=>{pt=pt.filter(r=>r!==a)}},[]);const s=n.useCallback(a=>{$n(a)},[]);return[{...He},s]}function nt(t){if(!He.globalEnabled)return!1;switch(t){case"disconnect":return He.disconnectAlert;case"completion":return He.completionAlert;case"approval":return He.approvalAlert;case"browser":return He.browserNotifications;default:return!0}}const _n={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Rn(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function vs(){return"Notification"in window&&Notification.permission==="granted"}let Ge=null;async function Pn(){if(Ge!==null)return Ge;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return Ge=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(Ge=!!await t.pushManager.getSubscription(),Ge):(Ge=!1,!1)}catch{return Ge=!1,!1}}function Rt(t,s,a){if(vs())try{const r=new Notification(t,{body:s,icon:"/otter-logo.png",tag:a||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>r.close(),8e3),r.onclick=()=>{window.focus(),r.close()}}catch{}}function Ln(t,s={}){const a={..._n,...s},r=n.useRef(new Map),i=n.useRef(0),c=n.useRef(null);n.useEffect(()=>{Pn().then(p=>{c.current=p})},[]);const o=n.useCallback((p,u,m)=>{const l=Date.now();l-i.current<a.throttleMs||(i.current=l,Rt(p,u,m))},[a.throttleMs]);n.useEffect(()=>{var p;if(!(!a.enabled||!vs())&&nt("browser")&&c.current!==!0){if(document.hasFocus()){for(const u of t)r.current.set(u.id,u.status||"idle");return}for(const u of t){const m=r.current.get(u.id),l=u.status||"idle",d=u.name||u.id;if(a.onApproval&&nt("approval")&&l==="waiting_approval"&&m!=="waiting_approval"){const v=((p=u.activeModal)==null?void 0:p.message)||"Action requires your approval";o(`🔔 ${d} — Approval needed`,v.slice(0,120),`approval-${u.id}`)}a.onComplete&&nt("completion")&&m==="generating"&&l==="idle"&&o(`✅ ${d} — Task complete`,"Agent has finished working",`complete-${u.id}`),a.onError&&l==="error"&&m!=="error"&&o(`⚠️ ${d} — Error`,"Agent encountered an error",`error-${u.id}`),r.current.set(u.id,l)}}},[t,a.enabled,a.onApproval,a.onComplete,a.onError,o])}class Dn{constructor(){Ae(this,"dedupMap",new Map);Ae(this,"DEDUP_WINDOW_MS",5e3);Ae(this,"DEDUP_MAX_SIZE",50);Ae(this,"DEDUP_CLEANUP_AGE_MS",1e4);Ae(this,"toastCallbacks",[]);Ae(this,"systemMessageCallbacks",[]);Ae(this,"clearSystemMessageCallbacks",[]);Ae(this,"resolveActionFn",null);Ae(this,"viewRequestRespondFn",null);Ae(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(a=>a!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(a=>a!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(a=>a!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const a of this.toastCallbacks)a(s)}emitSystemMessage(s,a){for(const r of this.systemMessageCallbacks)r(s,a)}emitClearSystemMessage(s,a){for(const r of this.clearSystemMessageCallbacks)r(s,a)}isDuplicate(s){const a=Date.now(),r=this.dedupMap.get(s)||0;if(a-r<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,a),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,c]of this.dedupMap)a-c>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(i);return!1}resolveRouteId(s,a){for(const r of this.ides)if(r.id.startsWith(s)&&(!a||a===r.type))return r.id;return s}handleRawEvent(s,a){var p,u,m;const r=`${s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(r))return;if(!s.ideId&&s.instanceId){for(const l of this.ides)if(l.id.endsWith(`:ide:${s.instanceId}`)||l.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=l.id;break}}let i=De(s.ideType||"");if(s.ideType==="adhdev-daemon"){const l=this.ides.find(d=>d.type==="adhdev-daemon");l&&(i=l.machineNickname||((p=l.machine)==null?void 0:p.hostname)||i)}let c="",o="info";if(s.event==="agent:generating_completed"){const l=s.duration?` (${s.duration}s)`:"";c=`✅ ${i} agent task completed${l}`,o="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}s.ideId&&this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`✅ Task completed${l}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")s.ideId&&this.emitClearSystemMessage(s.ideId,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(c=`⚡ ${i} approval needed`,o="warning",s.ideId){const l=s.modalMessage||"Approval requested",d=(u=s.modalButtons)!=null&&u.length?s.modalButtons.map(v=>`[${v}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${l}
|
|
40
|
-
${d}`,_localId:`sys_approval_${Date.now()}`})}if(s.ideId&&((m=s.modalButtons)!=null&&m.length)&&this.resolveActionFn){const l=s.ideId,d=s.agentType||s.ideType||"",v=s.ideType||"",j=s.modalButtons,x=B=>B.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),I=this.resolveActionFn,T=j.map((B,K)=>{const E=x(B).toLowerCase(),A=/^(run|approve|accept|yes|allow|always)/.test(E),$=/^(reject|deny|delete|remove|abort|cancel|no)/.test(E);return{label:x(B),variant:A?"primary":$?"danger":"default",onClick:()=>{const C=this.resolveRouteId(l,d),y=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(E);I(C,"resolve_action",{action:y?"approve":"reject",button:B,buttonIndex:K,agentType:d,ideType:v})}}}),f=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:c,N=Date.now();this.emitToast({id:N,message:f,type:o,timestamp:N,ideId:l,actions:T,duration:15e3}),c=""}}else if(s.event==="monitor:long_generating"){const l=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";c=`⚠️ ${i} agent is taking a long time${l}`,o="warning",nt("browser")&&!document.hasFocus()&&Rt(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${l.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const l=s.requesterName||"A team member",d=s.requestId,v=s.orgId;if(c=`👁️ ${l} wants to view your session`,o="warning",d&&v&&this.viewRequestRespondFn){const j=this.viewRequestRespondFn,x=Date.now(),I=[{label:"Approve",variant:"primary",onClick:()=>{j(v,d,"approve").catch(T=>console.error("[EventManager] approve view request failed:",T))}},{label:"Decline",variant:"danger",onClick:()=>{j(v,d,"reject").catch(T=>console.error("[EventManager] reject view request failed:",T))}}];this.emitToast({id:x,message:c,type:o,timestamp:x,actions:I,duration:3e4}),c=""}nt("browser")&&!document.hasFocus()&&Rt("👁️ View Request",`${l} wants to view your session`,`view-request-${d}`)}else s.event==="team:view_request_approved"?(c="✅ View request approved",o="success"):s.event==="team:view_request_rejected"&&(c=`❌ ${s.targetName||"Team member"} declined your view request`,o="warning");if(c){const l=Date.now();this.emitToast({id:l,message:c,type:o,timestamp:l,ideId:s.ideId,duration:5e3})}}}const Je=new Dn;function it(...t){return Es($s(t))}function Bn({icon:t,title:s,subtitle:a,badge:r,actions:i,className:c}){return e.jsxs("div",{className:it("dashboard-header",c),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]})]}),a&&e.jsx("div",{className:"header-subtitle mt-1 text-[11px] text-text-muted",children:a})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function Ze({title:t,icon:s,description:a,accentColor:r,className:i,children:c}){return e.jsxs("div",{className:it("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",i),style:r?{borderLeftColor:r}:void 0,children:[(t||a)&&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]}),a&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:a})]}),c]})}function Wn({icon:t,title:s,description:a,action:r,className:i}){return e.jsxs("div",{className:it("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:a}),r]})}const On={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"},Kn={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Fn({status:t,label:s,className:a}){const r=s||t;return e.jsxs("span",{className:it("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",On[t],a),children:[e.jsx("span",{className:it("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Kn[t])}),r]})}function Hn(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Jt(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function It(t){return t==="system"?Hn():t}function zn(){const[t,s]=n.useState(Jt),[a,r]=n.useState(()=>It(Jt()));n.useEffect(()=>{document.documentElement.setAttribute("data-theme",a)},[a]),n.useEffect(()=>{const o=window.matchMedia("(prefers-color-scheme: light)"),p=u=>{t==="system"&&r(u.matches?"light":"dark")};return o.addEventListener("change",p),()=>o.removeEventListener("change",p)},[t]);const i=n.useCallback(o=>{s(o),r(It(o));try{localStorage.setItem("theme",o)}catch{}},[]),c=n.useCallback(()=>{s(o=>{const p=o==="dark"?"light":o==="light"?"system":"dark";r(It(p));try{localStorage.setItem("theme",p)}catch{}return p})},[]);return{theme:a,preference:t,setPreference:i,cycleTheme:c,isDark:a==="dark"}}function Qe({label:t,description:s,checked:a,disabled:r,onChange:i,extra:c}){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:[c,e.jsx("input",{type:"checkbox",checked:a,disabled:r,onChange:o=>i(o.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function Un({onPrefChange:t}){const[s,a]=An(),r=(i,c)=>{a({[i]:c}),t==null||t(i,c)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Qe,{label:"🔔 Notifications",description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>r("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(Qe,{label:"🖥️ Browser Notifications",description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>r("browserNotifications",i)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(Qe,{label:"✅ Completion Alerts",description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(Qe,{label:"⚡ Approval Alerts",description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(Qe,{label:"📡 Connection Alerts",description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("disconnectAlert",i)})]}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function Yn({ides:t,emptyMessage:s,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i}){const c=t.filter(o=>o.type==="adhdev-daemon");return c.length===0?e.jsx(Wn,{icon:"🔌",title:"No machines connected",description:s||"Run 'adhdev daemon' on your machine to connect."}):e.jsx("div",{className:"flex flex-col gap-2",children:c.map(o=>e.jsx(Vn,{ide:o,allIdes:t,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i},o.id))})}function Zt({title:t,message:s,confirmLabel:a,confirmColor:r,onConfirm:i,onCancel:c}){const o=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 As.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:c,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:p=>p.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:c,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${o}`,children:a})]})]})}),document.body)}const Gn={vscode:{icon:"💠",name:"VS Code"},cursor:{icon:"⚡",name:"Cursor"},windsurf:{icon:"🏄",name:"Windsurf"},codex:{icon:"🤖",name:"Codex"},"claude-code":{icon:"🟠",name:"Claude Code"},aider:{icon:"🔧",name:"Aider"}};function Xn(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase();return Gn[s]||{icon:"📝",name:t}}function Vn({ide:t,allIdes:s,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i}){var G,re,V,ee;const[c,o]=n.useState("idle"),[p,u]=n.useState(""),[m,l]=n.useState(null),[d,v]=n.useState("idle"),[j,x]=n.useState(""),I=t,T=I.version||I.daemonVersion||null,f=((G=I.machine)==null?void 0:G.hostname)||((re=I.system)==null?void 0:re.hostname)||"",N=((V=I.machine)==null?void 0:V.platform)||((ee=I.system)==null?void 0:ee.platform)||"",B=I.machineNickname||(f==null?void 0:f.replace(/\.local$/,""))||"Machine",K=N==="win32"?"🪟":N==="darwin"?"🍎":"🐧",E=s.filter(O=>O.daemonId===t.id&&O.id.includes(":ide:")),A=s.filter(O=>O.daemonId===t.id&&O.id.includes(":cli:")),$=s.filter(O=>O.daemonId===t.id&&O.id.includes(":acp:")),C=I.p2p,y=async()=>{var O,ae,oe;if(a){o("upgrading"),u("Installing latest version...");try{const ue=await a(t.id,"daemon_upgrade",{});(O=ue==null?void 0:ue.result)!=null&&O.upgraded||(ae=ue==null?void 0:ue.result)!=null&&ae.success?(o("done"),u(`Upgraded to v${ue.result.version||"latest"}. Daemon is restarting...`)):(o("error"),u(((oe=ue==null?void 0:ue.result)==null?void 0:oe.error)||"Upgrade failed"))}catch(ue){o("error"),u((ue==null?void 0:ue.message)||"Connection lost during upgrade")}}},R=async()=>{if(l(null),!!r){v("loading");try{await r(t.id),v("done"),x("Machine disconnected.")}catch(O){v("error"),x((O==null?void 0:O.message)||"Failed to disconnect")}}},F=async()=>{if(l(null),!!i){v("loading");try{await i(t.id),v("done"),x('Token revoked. Machine must run "adhdev setup" to reconnect.')}catch(O){v("error"),x((O==null?void 0:O.message)||"Failed to revoke token")}}},H="0.6.37",Z=!T||T!==H,b=E.length+A.length+$.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:K}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:B}),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),"…"]}),T&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${Z?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",T,!Z&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a&&Z&&e.jsx("button",{onClick:y,disabled:c==="upgrading"||c==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${H}`,children:c==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):c==="done"?"✓ Updated":`↑ Update${` to v${H}`}`}),r&&e.jsx("button",{onClick:()=>l("disconnect"),disabled:d==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>l("revoke"),disabled:d==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Fn,{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:[C&&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 ${C.state==="connected"?"bg-green-400":C.state==="connecting"||C.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",C.state==="connected"?"connected":C.state==="connecting"||C.state==="new"?"connecting...":C.state||"off"]}),C.peers!==void 0&&C.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",C.peers," peer",C.peers!==1?"s":"",")"]})]}),C&&b>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),b>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[E.map(O=>{const ae=Xn(O.type),oe=O.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:ae.icon}),e.jsx("span",{children:ae.name}),oe!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${oe?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:oe?"CDP connected":"CDP connecting..."})]},O.id)}),A.map(O=>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:O.cliName||"CLI"})]},O.id)),$.map(O=>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:O.cliName||"ACP"})]},O.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(p||j)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${c==="error"||d==="error"?"text-red-400":c==="done"||d==="done"?"text-green-400":"text-text-muted"}`,children:j||p})]}),m==="disconnect"&&e.jsx(Zt,{title:"🔌 Disconnect Machine",message:`Disconnect "${B}" from ADHDev?
|
|
40
|
+
${d}`,_localId:`sys_approval_${Date.now()}`})}if(s.ideId&&((m=s.modalButtons)!=null&&m.length)&&this.resolveActionFn){const l=s.ideId,d=s.agentType||s.ideType||"",v=s.ideType||"",j=s.modalButtons,x=B=>B.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),I=this.resolveActionFn,T=j.map((B,K)=>{const E=x(B).toLowerCase(),A=/^(run|approve|accept|yes|allow|always)/.test(E),$=/^(reject|deny|delete|remove|abort|cancel|no)/.test(E);return{label:x(B),variant:A?"primary":$?"danger":"default",onClick:()=>{const C=this.resolveRouteId(l,d),y=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(E);I(C,"resolve_action",{action:y?"approve":"reject",button:B,buttonIndex:K,agentType:d,ideType:v})}}}),f=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:c,N=Date.now();this.emitToast({id:N,message:f,type:o,timestamp:N,ideId:l,actions:T,duration:15e3}),c=""}}else if(s.event==="monitor:long_generating"){const l=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";c=`⚠️ ${i} agent is taking a long time${l}`,o="warning",nt("browser")&&!document.hasFocus()&&Rt(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${l.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const l=s.requesterName||"A team member",d=s.requestId,v=s.orgId;if(c=`👁️ ${l} wants to view your session`,o="warning",d&&v&&this.viewRequestRespondFn){const j=this.viewRequestRespondFn,x=Date.now(),I=[{label:"Approve",variant:"primary",onClick:()=>{j(v,d,"approve").catch(T=>console.error("[EventManager] approve view request failed:",T))}},{label:"Decline",variant:"danger",onClick:()=>{j(v,d,"reject").catch(T=>console.error("[EventManager] reject view request failed:",T))}}];this.emitToast({id:x,message:c,type:o,timestamp:x,actions:I,duration:3e4}),c=""}nt("browser")&&!document.hasFocus()&&Rt("👁️ View Request",`${l} wants to view your session`,`view-request-${d}`)}else s.event==="team:view_request_approved"?(c="✅ View request approved",o="success"):s.event==="team:view_request_rejected"&&(c=`❌ ${s.targetName||"Team member"} declined your view request`,o="warning");if(c){const l=Date.now();this.emitToast({id:l,message:c,type:o,timestamp:l,ideId:s.ideId,duration:5e3})}}}const Je=new Dn;function it(...t){return Es($s(t))}function Bn({icon:t,title:s,subtitle:a,badge:r,actions:i,className:c}){return e.jsxs("div",{className:it("dashboard-header",c),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]})]}),a&&e.jsx("div",{className:"header-subtitle mt-1 text-[11px] text-text-muted",children:a})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function Ze({title:t,icon:s,description:a,accentColor:r,className:i,children:c}){return e.jsxs("div",{className:it("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",i),style:r?{borderLeftColor:r}:void 0,children:[(t||a)&&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]}),a&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:a})]}),c]})}function Wn({icon:t,title:s,description:a,action:r,className:i}){return e.jsxs("div",{className:it("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:a}),r]})}const On={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"},Kn={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Fn({status:t,label:s,className:a}){const r=s||t;return e.jsxs("span",{className:it("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",On[t],a),children:[e.jsx("span",{className:it("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Kn[t])}),r]})}function Hn(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Jt(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function It(t){return t==="system"?Hn():t}function zn(){const[t,s]=n.useState(Jt),[a,r]=n.useState(()=>It(Jt()));n.useEffect(()=>{document.documentElement.setAttribute("data-theme",a)},[a]),n.useEffect(()=>{const o=window.matchMedia("(prefers-color-scheme: light)"),p=u=>{t==="system"&&r(u.matches?"light":"dark")};return o.addEventListener("change",p),()=>o.removeEventListener("change",p)},[t]);const i=n.useCallback(o=>{s(o),r(It(o));try{localStorage.setItem("theme",o)}catch{}},[]),c=n.useCallback(()=>{s(o=>{const p=o==="dark"?"light":o==="light"?"system":"dark";r(It(p));try{localStorage.setItem("theme",p)}catch{}return p})},[]);return{theme:a,preference:t,setPreference:i,cycleTheme:c,isDark:a==="dark"}}function Qe({label:t,description:s,checked:a,disabled:r,onChange:i,extra:c}){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:[c,e.jsx("input",{type:"checkbox",checked:a,disabled:r,onChange:o=>i(o.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function Un({onPrefChange:t}){const[s,a]=An(),r=(i,c)=>{a({[i]:c}),t==null||t(i,c)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Qe,{label:"🔔 Notifications",description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>r("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(Qe,{label:"🖥️ Browser Notifications",description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>r("browserNotifications",i)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(Qe,{label:"✅ Completion Alerts",description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(Qe,{label:"⚡ Approval Alerts",description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(Qe,{label:"📡 Connection Alerts",description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("disconnectAlert",i)})]}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function Yn({ides:t,emptyMessage:s,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i}){const c=t.filter(o=>o.type==="adhdev-daemon");return c.length===0?e.jsx(Wn,{icon:"🔌",title:"No machines connected",description:s||"Run 'adhdev daemon' on your machine to connect."}):e.jsx("div",{className:"flex flex-col gap-2",children:c.map(o=>e.jsx(Vn,{ide:o,allIdes:t,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i},o.id))})}function Zt({title:t,message:s,confirmLabel:a,confirmColor:r,onConfirm:i,onCancel:c}){const o=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 As.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:c,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:p=>p.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:c,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${o}`,children:a})]})]})}),document.body)}const Gn={vscode:{icon:"💠",name:"VS Code"},cursor:{icon:"⚡",name:"Cursor"},windsurf:{icon:"🏄",name:"Windsurf"},codex:{icon:"🤖",name:"Codex"},"claude-code":{icon:"🟠",name:"Claude Code"},aider:{icon:"🔧",name:"Aider"}};function Xn(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase();return Gn[s]||{icon:"📝",name:t}}function Vn({ide:t,allIdes:s,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i}){var G,re,V,ee;const[c,o]=n.useState("idle"),[p,u]=n.useState(""),[m,l]=n.useState(null),[d,v]=n.useState("idle"),[j,x]=n.useState(""),I=t,T=I.version||I.daemonVersion||null,f=((G=I.machine)==null?void 0:G.hostname)||((re=I.system)==null?void 0:re.hostname)||"",N=((V=I.machine)==null?void 0:V.platform)||((ee=I.system)==null?void 0:ee.platform)||"",B=I.machineNickname||(f==null?void 0:f.replace(/\.local$/,""))||"Machine",K=N==="win32"?"🪟":N==="darwin"?"🍎":"🐧",E=s.filter(O=>O.daemonId===t.id&&O.id.includes(":ide:")),A=s.filter(O=>O.daemonId===t.id&&O.id.includes(":cli:")),$=s.filter(O=>O.daemonId===t.id&&O.id.includes(":acp:")),C=I.p2p,y=async()=>{var O,ae,oe;if(a){o("upgrading"),u("Installing latest version...");try{const ue=await a(t.id,"daemon_upgrade",{});(O=ue==null?void 0:ue.result)!=null&&O.upgraded||(ae=ue==null?void 0:ue.result)!=null&&ae.success?(o("done"),u(`Upgraded to v${ue.result.version||"latest"}. Daemon is restarting...`)):(o("error"),u(((oe=ue==null?void 0:ue.result)==null?void 0:oe.error)||"Upgrade failed"))}catch(ue){o("error"),u((ue==null?void 0:ue.message)||"Connection lost during upgrade")}}},R=async()=>{if(l(null),!!r){v("loading");try{await r(t.id),v("done"),x("Machine disconnected.")}catch(O){v("error"),x((O==null?void 0:O.message)||"Failed to disconnect")}}},F=async()=>{if(l(null),!!i){v("loading");try{await i(t.id),v("done"),x('Token revoked. Machine must run "adhdev setup" to reconnect.')}catch(O){v("error"),x((O==null?void 0:O.message)||"Failed to revoke token")}}},H="0.6.40",Z=!T||T!==H,b=E.length+A.length+$.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:K}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:B}),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),"…"]}),T&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${Z?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",T,!Z&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a&&Z&&e.jsx("button",{onClick:y,disabled:c==="upgrading"||c==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${H}`,children:c==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):c==="done"?"✓ Updated":`↑ Update${` to v${H}`}`}),r&&e.jsx("button",{onClick:()=>l("disconnect"),disabled:d==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>l("revoke"),disabled:d==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Fn,{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:[C&&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 ${C.state==="connected"?"bg-green-400":C.state==="connecting"||C.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",C.state==="connected"?"connected":C.state==="connecting"||C.state==="new"?"connecting...":C.state||"off"]}),C.peers!==void 0&&C.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",C.peers," peer",C.peers!==1?"s":"",")"]})]}),C&&b>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),b>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[E.map(O=>{const ae=Xn(O.type),oe=O.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:ae.icon}),e.jsx("span",{children:ae.name}),oe!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${oe?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:oe?"CDP connected":"CDP connecting..."})]},O.id)}),A.map(O=>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:O.cliName||"CLI"})]},O.id)),$.map(O=>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:O.cliName||"ACP"})]},O.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(p||j)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${c==="error"||d==="error"?"text-red-400":c==="done"||d==="done"?"text-green-400":"text-text-muted"}`,children:j||p})]}),m==="disconnect"&&e.jsx(Zt,{title:"🔌 Disconnect Machine",message:`Disconnect "${B}" from ADHDev?
|
|
41
41
|
|
|
42
42
|
This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
|
|
43
43
|
|
|
@@ -48,7 +48,7 @@ This will:
|
|
|
48
48
|
• Delete the machine registration
|
|
49
49
|
• Require running "adhdev setup" again on that machine
|
|
50
50
|
|
|
51
|
-
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:F,onCancel:()=>l(null)})]})}const qn=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Jn(){const{preference:t,setPreference:s}=zn();return e.jsx("div",{className:"flex gap-2",children:qn.map(a=>e.jsxs("button",{onClick:()=>s(a.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===a.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:a.icon}),a.label]},a.id))})}const Pt={bgPrimary:"#0f0f13",bgSecondary:"#18181d",surfacePrimary:"#111116",textPrimary:"#fafafa",textSecondary:"#a8a8b3",textMuted:"#7e7e8a",borderSubtle:"#1a1a22",borderDefault:"#2a2a35",accentColor:"#8b5cf6",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#1e1e24",assistantText:"#e0e0e0",containerBg:"#111114",sendButton:"#6366f1",inputBorder:"#2a2a35",bubbleRadius:16},Lt={bgPrimary:"#f0f1f5",bgSecondary:"#e8eaf0",surfacePrimary:"#ffffff",textPrimary:"#1a1a2e",textSecondary:"#3f3f50",textMuted:"#5c5c6e",borderSubtle:"#d8d8e0",borderDefault:"#c0c0cc",accentColor:"#7c3aed",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#f3f4f6",assistantText:"#1f2937",containerBg:"#f0f1f5",sendButton:"#6366f1",inputBorder:"#d1d5db",bubbleRadius:16},Zn=[{id:"midnight",name:"Midnight",description:"Default violet theme",preview:{dark:{userBubble:"linear-gradient(135deg, #8b5cf6, #4f46e5)",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"linear-gradient(135deg, #7c3aed, #0ea5e9)",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"aurora",name:"Aurora",description:"Pink-orange gradient",preview:{dark:{userBubble:"linear-gradient(135deg, #ec4899, #f97316)",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"linear-gradient(135deg, #ec4899, #f97316)",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"}}}],ws="adhdev-chat-theme",Ns="adhdev-chat-theme-custom";function ht(){return typeof window>"u"?"midnight":localStorage.getItem(ws)||"midnight"}function Be(t){try{const s=localStorage.getItem(Ns);if(s){const a=JSON.parse(s);return{...t==="dark"?Pt:Lt,...a[t]}}}catch{}return t==="dark"?Pt:Lt}function xt(t,s){localStorage.setItem(Ns,JSON.stringify({dark:t,light:s}))}function Ke(t,s){const a=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${a}, ${r}, ${i}, ${s})`}function Qt(t,s){const a=Math.min(255,parseInt(t.slice(1,3),16)+s),r=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${a.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}function qe(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ke(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ke(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ke(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",Ke(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ke(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",Qt(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${Qt(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ke(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ke(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ke(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 ${Ke(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 Qn(){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(a=>t.style.removeProperty(a))}function er(t){if(localStorage.setItem(ws,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=rt()?"dark":"light";qe(Be(s))}else Qn()}function tr(){const t=ht();if(t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=rt()?"dark":"light";qe(Be(s))}}function rt(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Te({label:t,value:s,onChange:a}){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=>a(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)&&a(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 tt({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 sr({dark:t,onColorsChange:s}){const a=t?"dark":"light",[r,i]=n.useState(()=>Be(a));n.useEffect(()=>{i(Be(a))},[a]);const c=n.useCallback((o,p)=>{i(u=>{const m={...u,[o]:p},d=Be(a==="dark"?"light":"dark");return a==="dark"?xt(m,d):xt(d,m),qe(m),s(m),m})},[a,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(tt,{title:"App Background",children:[e.jsx(Te,{label:"Background",value:r.bgPrimary,onChange:o=>c("bgPrimary",o)}),e.jsx(Te,{label:"Surface",value:r.bgSecondary,onChange:o=>c("bgSecondary",o)}),e.jsx(Te,{label:"Card",value:r.surfacePrimary,onChange:o=>c("surfacePrimary",o)})]}),e.jsxs(tt,{title:"App Text",children:[e.jsx(Te,{label:"Primary",value:r.textPrimary,onChange:o=>c("textPrimary",o)}),e.jsx(Te,{label:"Secondary",value:r.textSecondary,onChange:o=>c("textSecondary",o)}),e.jsx(Te,{label:"Muted",value:r.textMuted,onChange:o=>c("textMuted",o)})]}),e.jsxs(tt,{title:"Borders & Accent",children:[e.jsx(Te,{label:"Border subtle",value:r.borderSubtle,onChange:o=>c("borderSubtle",o)}),e.jsx(Te,{label:"Border default",value:r.borderDefault,onChange:o=>c("borderDefault",o)}),e.jsx(Te,{label:"Accent",value:r.accentColor,onChange:o=>c("accentColor",o)})]})]}),e.jsxs("div",{children:[e.jsxs(tt,{title:"Chat Bubbles",children:[e.jsx(Te,{label:"User bubble",value:r.userBubble,onChange:o=>c("userBubble",o)}),e.jsx(Te,{label:"User text",value:r.userText,onChange:o=>c("userText",o)}),e.jsx(Te,{label:"Agent bubble",value:r.assistantBubble,onChange:o=>c("assistantBubble",o)}),e.jsx(Te,{label:"Agent text",value:r.assistantText,onChange:o=>c("assistantText",o)})]}),e.jsxs(tt,{title:"Chat Layout",children:[e.jsx(Te,{label:"Chat BG",value:r.containerBg,onChange:o=>c("containerBg",o)}),e.jsx(Te,{label:"Send button",value:r.sendButton,onChange:o=>c("sendButton",o)}),e.jsx(Te,{label:"Input border",value:r.inputBorder,onChange:o=>c("inputBorder",o)}),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:o=>c("bubbleRadius",Number(o.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 o=t?Pt:Lt,u=Be(t?"light":"dark");t?xt(o,u):xt(u,o),i(o),qe(o),s(o)},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 nr(){const[t,s]=n.useState(ht),[a,r]=n.useState(!0),[i,c]=n.useState(()=>Be("dark"));n.useEffect(()=>{r(rt());const u=new MutationObserver(()=>{const d=rt();r(d),ht()==="custom"&&qe(Be(d?"dark":"light"))});u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const m=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{const d=rt();r(d),ht()==="custom"&&qe(Be(d?"dark":"light"))};return m.addEventListener("change",l),()=>{u.disconnect(),m.removeEventListener("change",l)}},[]),n.useEffect(()=>{t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"&&qe(Be(a?"dark":"light"))},[]),n.useEffect(()=>{c(Be(a?"dark":"light"))},[a]);const o=u=>{s(u),er(u),u==="midnight"&&document.documentElement.removeAttribute("data-chat-theme")},p=[...Zn,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:p.map(u=>{const m=t===u.id,l=a?u.preview.dark:u.preview.light,d=u.id==="honey"?"#1a1a1a":u.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>o(u.id),className:"text-left rounded-xl p-3 transition-all",style:{background:m?"var(--bg-glass-hover)":"var(--bg-glass)",border:m?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:m?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:l.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:l.assistantBubble,border:l.assistantBorder,color:l.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:l.userBubble,color:d},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:l.assistantBubble,border:l.assistantBorder,color:l.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[m&&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:u.id==="custom"?"🎨 Custom":u.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:u.description})]})]})]},u.id)})}),t==="custom"&&e.jsx(sr,{dark:a,onColorsChange:u=>c(u)})]})}const Dt="adhdev-accent-color",rr=[{name:"Violet",color:"#8b5cf6"},{name:"Indigo",color:"#6366f1"},{name:"Blue",color:"#3b82f6"},{name:"Cyan",color:"#06b6d4"},{name:"Emerald",color:"#10b981"},{name:"Rose",color:"#f43f5e"},{name:"Orange",color:"#f97316"},{name:"Amber",color:"#f59e0b"}],ct="#8b5cf6";function ar(t){const s=parseInt(t.slice(1,3),16)/255,a=parseInt(t.slice(3,5),16)/255,r=parseInt(t.slice(5,7),16)/255,i=Math.max(s,a,r),c=Math.min(s,a,r);let o=0,p=0;const u=(i+c)/2;if(i!==c){const m=i-c;switch(p=u>.5?m/(2-i-c):m/(i+c),i){case s:o=((a-r)/m+(a<r?6:0))/6;break;case a:o=((r-s)/m+2)/6;break;case r:o=((s-a)/m+4)/6;break}}return{h:Math.round(o*360),s:Math.round(p*100),l:Math.round(u*100)}}function es(t,s){const{h:a,s:r,l:i}=ar(t),c=Math.min(100,i+s);return`hsl(${a}, ${r}%, ${c}%)`}function ft(t,s){const a=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${a}, ${r}, ${i}, ${s})`}function ts(){return typeof window>"u"?ct:localStorage.getItem(Dt)||ct}function or(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",es(t,15)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${es(t,20)})`),s.style.setProperty("--border-accent",ft(t,.4)),s.style.setProperty("--nav-active-bg",ft(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${ft(t,.06)}`)}function ir(){const t=document.documentElement;["--accent-primary","--accent-primary-light","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow"].forEach(a=>t.style.removeProperty(a))}function cr(t){t===ct?(localStorage.removeItem(Dt),ir()):(localStorage.setItem(Dt,t),or(t))}function lr(){const[t,s]=n.useState(ts),[a,r]=n.useState("");n.useEffect(()=>{s(ts())},[]);const i=c=>{s(c),cr(c)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:rr.map(c=>{const o=t===c.color;return e.jsx("button",{onClick:()=>i(c.color),title:c.name,style:{width:36,height:36,borderRadius:10,background:c.color,border:o?"3px solid var(--text-primary)":"3px solid transparent",cursor:"pointer",position:"relative",transition:"transform 0.15s, border-color 0.15s",transform:o?"scale(1.1)":"scale(1)",boxShadow:o?`0 0 12px ${ft(c.color,.4)}`:"none"},children:o&&e.jsx("span",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:14,fontWeight:700,textShadow:"0 1px 2px rgba(0,0,0,0.5)"},children:"✓"})},c.color)})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"Custom:"}),e.jsx("input",{type:"color",value:t,onChange:c=>i(c.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:a||t,onChange:c=>{r(c.target.value),/^#[0-9a-fA-F]{6}$/.test(c.target.value)&&i(c.target.value)},onBlur:()=>r(""),style:{width:80,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}}),t!==ct&&e.jsx("button",{onClick:()=>i(ct),style:{fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:5,padding:"3px 8px",cursor:"pointer"},children:"Reset"})]})]})}const ks="adhdev_hiddenTabs";function dr(){try{const t=localStorage.getItem(ks);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function st(t){try{localStorage.setItem(ks,JSON.stringify([...t]))}catch{}}function ur(){const[t,s]=n.useState(dr),a=n.useCallback(u=>{s(m=>{const l=new Set(m);return l.has(u)?l.delete(u):l.add(u),st(l),l})},[]),r=n.useCallback(u=>{s(m=>{if(m.has(u))return m;const l=new Set(m);return l.add(u),st(l),l})},[]),i=n.useCallback(u=>{s(m=>{if(!m.has(u))return m;const l=new Set(m);return l.delete(u),st(l),l})},[]),c=n.useCallback((u,m)=>{s(l=>{const d=new Set(l);for(const v of m)d.add(v);return st(d),d})},[]),o=n.useCallback((u,m)=>{s(l=>{const d=new Set(l);for(const v of m)d.delete(v);return st(d),d})},[]),p=n.useCallback(u=>t.has(u),[t]);return{hiddenTabs:t,toggleTab:a,hideTab:r,showTab:i,hideAllForDaemon:c,showAllForDaemon:o,isHidden:p}}function Ss({sendDaemonCommand:t,activeConv:s,ides:a,updateIdeChats:r,setToasts:i,setLocalUserMessages:c,setClearedTabs:o,setActionLogs:p,pinTab:u,isStandalone:m}){const[l,d]=n.useState(""),[v,j]=n.useState(!1),[x,I]=n.useState(!1),[T,f]=n.useState(!1),N=n.useCallback(async()=>{if(!s)return;const R=l.trim();if(!R)return;const F=s.ideId,H=s.tabKey;d(""),u(H,[100,500,1500,3e3]);const Z=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,b={role:"user",content:R,timestamp:Date.now(),_localId:Z};c(G=>({...G,[H]:[...G[H]||[],b]}));try{if(Ue(s)&&!Oe(s)){const G=F||s.daemonId||"";if(!G)return;const re=s.ideType||s.agentType||"";await t(G,"agent_command",{agentType:re,cliType:re,action:"send_chat",message:R,text:R})}else if(Oe(s)){const G=F||s.daemonId||"";if(!G)return;await t(G,"send_chat",{message:R,text:R,agentType:s.agentType})}else{const G=F||s.daemonId||"";if(!G)return;await t(G,"send_chat",{message:R,text:R,...s.streamSource==="agent-stream"&&{agentType:s.agentType}})}setTimeout(()=>{const G=Date.now()-6e4;c(re=>{const V=re[H];if(!V)return re;const ee=V.filter(O=>O.timestamp>G);return ee.length===V.length?re:{...re,[H]:ee}})},6e4)}catch(G){console.error("Send failed",G),d(R),c(re=>({...re,[H]:(re[H]||[]).filter(V=>V._localId!==Z)}))}},[s,l,t,c,u]),B=n.useCallback(async()=>{if(s)try{m?await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0}):await t(s.ideId,"vscode_command_exec",{commandId:"adhdev.relaunchWithCdp",args:[{force:!0}]})}catch(R){console.error("Relaunch failed",R)}},[s,m,t]),K=n.useCallback(async R=>{try{await t("standalone","launch_ide",{ideType:R,enableCdp:!0})}catch(F){console.error("Launch failed",F)}},[t]),E=n.useCallback(async R=>{if(s){console.log("[ModalButton] ideId:",s.ideId,"button:",R),p(F=>[...F,{ideId:s.tabKey,text:`🖱️ **${R}** clicked`,timestamp:Date.now()}]);try{const H=(s.modalButtons||[]).indexOf(R),Z=R.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),b=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(Z),G=s.ideId||s.daemonId||"";(await t(G,"resolve_action",{button:R,action:b?"approve":"reject",...H>=0&&{buttonIndex:H},...s.streamSource==="agent-stream"&&{agentType:s.agentType}})).success||p(V=>[...V,{ideId:s.tabKey,text:`⚠️ **${R}** failed — button not found`,timestamp:Date.now()}])}catch(F){console.error("[ModalButton] Error:",F),p(H=>[...H,{ideId:s.tabKey,text:`❌ **${R}** error`,timestamp:Date.now()}])}}},[s,t,p]),A=n.useCallback(async(R,F)=>{try{const H=R||(s==null?void 0:s.daemonId)||"",Z=await t(H,"switch_chat",{id:F,sessionId:F,...(s==null?void 0:s.streamSource)==="agent-stream"&&{agentType:s==null?void 0:s.agentType}}),b=Z==null?void 0:Z.result;(Z==null?void 0:Z.success)===!0||b==="switched"||b==="switched-by-title"||(b===!1||b==="not_found"?i(re=>[...re,{id:Date.now(),message:"⚠️ Session tab not found — try refreshing history",type:"warning",timestamp:Date.now()}]):typeof b=="string"&&b.startsWith("error:")?i(re=>[...re,{id:Date.now(),message:`⚠️ Switch error: ${b}`,type:"warning",timestamp:Date.now()}]):i(re=>[...re,{id:Date.now(),message:"⚠️ Session switch failed",type:"warning",timestamp:Date.now()}]))}catch(H){console.error("Switch failed",H),i(Z=>[...Z,{id:Date.now(),message:`❌ Switch failed: ${H.message||"connection error"}`,type:"warning",timestamp:Date.now()}])}},[s,t,i]),$=n.useCallback(async()=>{if(!(!s||v)){j(!0);try{const R=s.ideId||s.daemonId||"";await t(R,"new_chat",{...s.streamSource==="agent-stream"&&{agentType:s.agentType}}),o(F=>({...F,[s.tabKey]:Date.now()})),c(F=>({...F,[s.tabKey]:[]}))}catch(R){console.error("New chat failed",R)}finally{j(!1)}}},[s,v,t,o,c]),C=n.useCallback(async()=>{if(!s||T)return;f(!0);const R=s.tabKey;try{await t(s.ideId,"agent_stream_focus",{agentType:s.agentType}),u(R,[200,1500,3e3])}catch(F){console.error("Focus agent failed",F)}finally{f(!1)}},[s,T,t,u]),y=n.useCallback(async()=>{var R;if(!(!s||x)){I(!0);try{const F=s.ideId||s.daemonId||"",H=await t(F,"list_chats",{forceExpand:!0,...s.streamSource==="agent-stream"&&{agentType:s.agentType}}),Z=(H==null?void 0:H.chats)||((R=H==null?void 0:H.result)==null?void 0:R.chats);H!=null&&H.success&&Array.isArray(Z)&&r(s.ideId,Z)}catch(F){console.error("Refresh history failed",F)}finally{I(!1)}}},[s,x,t,r]);return{agentInput:l,setAgentInput:d,isCreatingChat:v,isRefreshingHistory:x,isFocusingAgent:T,handleSendChat:N,handleRelaunch:B,handleLaunchIde:K,handleModalButton:E,handleSwitchSession:A,handleNewChat:$,handleFocusAgent:C,handleRefreshHistory:y}}let Mt=null;function xr({conversations:t,ides:s,messageReceivedAt:a,actionLogs:r,ptyBuffers:i,screenshotMap:c,setScreenshotMap:o,sendDaemonCommand:p,updateIdeChats:u,setToasts:m,setLocalUserMessages:l,setClearedTabs:d,setActionLogs:v,pinTab:j,isStandalone:x,userName:I,groupIndex:T,isFocused:f,onFocus:N,isSplitMode:B,numGroups:K,onMoveTab:E,onClose:A,onReceiveTab:$,style:C,detectedIdes:y,handleLaunchIde:R,onActiveTabChange:F,initialActiveTabId:H,initialTabOrder:Z,onTabOrderChange:b,onHideTab:G}){const{sendCommand:re}=Ye(),V=n.useRef(null),[ee,O]=n.useState(!1),ae=n.useRef(0),oe=n.useRef(null),[ue,ie]=n.useState(H??null);n.useEffect(()=>{H&&H!==ue&&ie(H)},[H]);const[L,g]=n.useState(Z??[]),[D,h]=n.useState(null),z=n.useRef(null),Q=n.useRef(null);n.useEffect(()=>{const k=new Set(t.map(U=>U.tabKey));g(U=>{const ce=U.filter(q=>k.has(q)),Y=t.filter(q=>!U.includes(q.tabKey)).map(q=>q.tabKey),le=[...ce,...Y];return le.length===U.length&&le.every((q,X)=>q===U[X])?U:le})},[t]);const xe=D??L,ge=n.useMemo(()=>{if(xe.length===0)return t;const k=new Map(xe.map((U,ce)=>[U,ce]));return[...t].sort((U,ce)=>{const Y=k.get(U.tabKey)??999,le=k.get(ce.tabKey)??999;return Y-le})},[t,xe]);n.useEffect(()=>{if(ge.length===0){ie(null),F==null||F(null);return}ue&&ge.some(k=>k.tabKey===ue)||(ie(ge[0].tabKey),F==null||F(ge[0].tabKey))},[ge,ue]);const he=ge.find(k=>k.tabKey===ue),ke=n.useCallback((k,U,ce)=>{g(Y=>{const le=Y.filter(pe=>pe!==k),q=le.indexOf(U);if(q<0)return Y;const X=ce==="left"?q:q+1;return le.splice(X,0,k),b==null||b(le),le}),h(null)},[b]),W=n.useCallback((k,U,ce)=>{const le=(L.length>0?L:t.map(pe=>pe.tabKey)).filter(pe=>pe!==k),q=le.indexOf(U);if(q<0)return;const X=ce==="left"?q:q+1;le.splice(X,0,k),z.current=le,h(le)},[L,t]),te=Ss({sendDaemonCommand:p,activeConv:he,ides:s,updateIdeChats:u,setToasts:m,setLocalUserMessages:l,setClearedTabs:d,setActionLogs:v,pinTab:j,isStandalone:x}),[me,be]=n.useState(null);n.useEffect(()=>{if(!me)return;const k=U=>{const ce=document.querySelector("[data-pane-context-menu]");ce&&ce.contains(U.target)||be(null)};return window.addEventListener("mousedown",k,!0),()=>window.removeEventListener("mousedown",k,!0)},[me]);const Pe="adhdev-tab-shortcuts",ve=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[Me,et]=n.useState(()=>{try{return JSON.parse(localStorage.getItem(Pe)||"{}")}catch{return{}}}),[_e,We]=n.useState(null),Ie=n.useCallback(k=>{const U=[];k.metaKey&&U.push(ve?"⌘":"Meta"),k.ctrlKey&&U.push("Ctrl"),k.altKey&&U.push(ve?"⌥":"Alt"),k.shiftKey&&U.push(ve?"⇧":"Shift");const ce=k.key;if(["Control","Alt","Shift","Meta"].includes(ce))return null;const Y=ce.length===1?ce.toUpperCase():ce;return U.push(Y),U.join("+")},[ve]),P=n.useCallback((k,U)=>Ie(k)===U,[Ie]),ne=n.useCallback(k=>{et(k),localStorage.setItem(Pe,JSON.stringify(k))},[]);n.useEffect(()=>{if(!_e)return;const k=U=>{if(U.preventDefault(),U.stopPropagation(),U.key==="Escape"){We(null);return}const ce=Ie(U);if(!ce)return;const Y={...Me};for(const[le,q]of Object.entries(Y))q===ce&&delete Y[le];Y[_e]=ce,ne(Y),We(null)};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)},[_e,Me,ne,Ie]),n.useEffect(()=>{const k=U=>{if(!(!U.ctrlKey&&!U.metaKey&&!U.altKey)){for(const[ce,Y]of Object.entries(Me))if(P(U,Y)&&ge.some(le=>le.tabKey===ce)){U.preventDefault(),N(),ie(ce),F==null||F(ce);return}}};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[Me,ge,N,F,P]);const J=he&&Ue(he)&&!Oe(he);n.useEffect(()=>{const k=()=>{ae.current=0,O(!1)};return window.addEventListener("dragend",k),window.addEventListener("drop",k),()=>{window.removeEventListener("dragend",k),window.removeEventListener("drop",k)}},[]);const fe=n.useRef(null);return n.useEffect(()=>{const k=fe.current;if(!k)return;const U=ce=>{Math.abs(ce.deltaY)>Math.abs(ce.deltaX)&&(ce.preventDefault(),k.scrollLeft+=ce.deltaY)};return k.addEventListener("wheel",U,{passive:!1}),()=>k.removeEventListener("wheel",U)},[]),e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:N,onDragEnter:k=>{if(k.dataTransfer.types.includes("text/tab-key")){ae.current++;const U=Mt;U&&t.some(Y=>Y.tabKey===U)||O(!0)}},onDragOver:k=>{k.dataTransfer.types.includes("text/tab-key")&&k.preventDefault()},onDragLeave:()=>{ae.current--,ae.current<=0&&(ae.current=0,O(!1))},onDrop:k=>{ae.current=0,O(!1),h(null);const U=k.dataTransfer.getData("text/tab-key");if(!U)return;k.preventDefault(),t.some(Y=>Y.tabKey===U)?g(Y=>{const le=Y.filter(q=>q!==U);return le.push(U),b==null||b(le),le}):$&&$(U)},style:{...C,outline:ee?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},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:fe,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:[ge.map((k,U)=>{const ce=ue===k.tabKey,Y=k.status==="working"?"agent-tab-working":k.status==="waiting_approval"?"agent-tab-waiting":"",le=k.connectionState==="failed"||k.connectionState==="closed",q=Q.current===k.tabKey;return e.jsxs("div",{"data-tabkey":k.tabKey,className:`${Y} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!("ontouchstart"in window),onDragStart:X=>{Mt=k.tabKey,Q.current=k.tabKey,X.dataTransfer.setData("text/tab-key",k.tabKey),X.dataTransfer.effectAllowed="move"},onDragEnd:()=>{Mt=null,Q.current=null;const X=z.current;X&&(g(X),b==null||b(X)),z.current=null,h(null),ae.current=0,O(!1)},onDragOver:X=>{const pe=Q.current;if(!(!pe||pe===k.tabKey)&&X.dataTransfer.types.includes("text/tab-key")){X.preventDefault(),X.stopPropagation();const se=X.currentTarget.getBoundingClientRect(),je=se.left+se.width/2,we=X.clientX<je?"left":"right";W(pe,k.tabKey,we)}},onDrop:X=>{X.preventDefault(),X.stopPropagation();const pe=X.dataTransfer.getData("text/tab-key");if(pe&&pe!==k.tabKey){const se=X.currentTarget.getBoundingClientRect(),je=se.left+se.width/2,we=X.clientX<je?"left":"right";ge.some(Ne=>Ne.tabKey===pe)?ke(pe,k.tabKey,we):$&&$(pe)}h(null)},onClick:X=>{X.stopPropagation(),N(),ie(k.tabKey),F==null||F(k.tabKey),k.streamSource==="agent-stream"&&k.agentType&&re(k.ideId,"agent_stream_focus",{agentType:k.agentType}).catch(()=>{}),Ue(k)&&setTimeout(()=>{var pe,se;return(se=(pe=V.current)==null?void 0:pe.bumpResize)==null?void 0:se.call(pe)},100)},onContextMenu:X=>{X.preventDefault(),be({x:X.clientX,y:X.clientY,tabKey:k.tabKey})},onTouchStart:X=>{const pe=X.touches[0],se=pe.clientX,je=pe.clientY;oe.current=setTimeout(()=>{be({x:se,y:je,tabKey:k.tabKey})},600)},onTouchEnd:()=>{oe.current&&clearTimeout(oe.current)},onTouchMove:()=>{oe.current&&clearTimeout(oe.current)},style:{background:ce?"var(--bg-primary)":"var(--bg-glass)",borderTop:ce?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:ce?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:ce?"1px solid var(--border-subtle)":"1px solid transparent",opacity:q?.4:le?ce?.6:.3:ce?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[k.status==="working"?e.jsx("div",{className:"tab-spinner"}):k.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):le?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400 animate-pulse",children:"○"}):k.connectionState==="connecting"||k.connectionState==="new"?e.jsx("div",{className:"tab-connecting-spinner"}):k.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:k.displayPrimary,children:k.displayPrimary}),e.jsx("div",{className:"text-[8px] opacity-50 flex gap-1 items-center",children:le?e.jsx("span",{className:"text-yellow-400 opacity-100",children:"Reconnecting…"}):k.connectionState==="connecting"||k.connectionState==="new"?e.jsxs("span",{className:"text-blue-400 opacity-100",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[k.displaySecondary,k.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{className:"opacity-70",children:["🖥 ",k.machineName]})]})]})})]}),Me[k.tabKey]&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${Me[k.tabKey]}`,children:Me[k.tabKey]})]},k.tabKey)}),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",children:he?e.jsxs(e.Fragment,{children:[e.jsx(gs,{activeConv:he,onModalButton:te.handleModalButton}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!J&&!Oe(he)&&c[he.ideId]?e.jsx(dn,{screenshotUrl:c[he.ideId],mode:"preview",onDismiss:()=>{const k={...c};delete k[he.ideId],o(k)}}):!J&&!Oe(he)&&he.cdpConnected===!1?e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[e.jsx("span",{className:"text-sm",children:e.jsx(xs,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:te.handleRelaunch,children:"Relaunch with CDP"})]}):null}),J?e.jsx(xn,{activeConv:he,ptyBuffers:i,terminalRef:V,agentInput:te.agentInput,setAgentInput:te.setAgentInput,handleSendChat:te.handleSendChat,handleModalButton:te.handleModalButton}):e.jsx(bs,{activeConv:he,ides:s,agentInput:te.agentInput,setAgentInput:te.setAgentInput,handleSendChat:te.handleSendChat,handleFocusAgent:te.handleFocusAgent,isFocusingAgent:te.isFocusingAgent,messageReceivedAt:a,actionLogs:r,userName:I})]}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:t.length===0&&!B&&y&&R?e.jsxs("div",{className:"empty-dashboard",children:[e.jsx("div",{className:"glow-orb",children:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-12 h-12"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"font-bold text-lg mb-1.5",children:"Waiting for your IDE"}),e.jsx("div",{className:"text-[13px] text-text-muted",style:{marginBottom:12},children:x?"Launch an IDE with CDP to start monitoring":"Install the daemon, then open your IDE — it connects automatically."}),!x&&e.jsxs("div",{style:{background:"var(--bg-secondary, #111)",borderRadius:"0.5rem",padding:"0.5rem 0.75rem",display:"inline-block",fontFamily:"monospace",fontSize:"0.75rem",color:"var(--accent, #a78bfa)",marginBottom:12,textAlign:"left",border:"1px solid var(--border-subtle, #333)"},children:[e.jsx("span",{style:{color:"var(--text-muted)"},children:"$ "}),"npm i -g adhdev && adhdev setup && adhdev daemon"]}),x&&y.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 justify-center",children:y.map(k=>e.jsx("button",{className:"btn btn-sm bg-violet-500/10 border border-violet-500/25 text-violet-400 text-xs font-semibold px-4 py-2 rounded-lg cursor-pointer flex items-center gap-1.5 transition-colors hover:bg-violet-500/20",onClick:()=>R(k.type),children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(nn,{size:14})," Launch ",k.name]})},k.type))}),e.jsx("div",{style:{marginTop:8},children:e.jsx("a",{href:"https://docs.adhf.dev/guide/getting-started",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"var(--accent, #a78bfa)",textDecoration:"none"},children:"📚 Setup guide →"})})]})]}):e.jsx("div",{className:"text-sm text-text-muted opacity-50",children:B?"Move a tab here to view":"No active agent"})})}),me&&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:me.x,top:me.y},children:[E&&T>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors hidden md:block",onClick:()=>{E(me.tabKey,"left"),be(null)},children:"← Move to Left Group"}),E&&T<K-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors hidden md:block",onClick:()=>{E(me.tabKey,"right"),be(null)},children:"Move to Right Group →"}),E&&K<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors hidden md:block",onClick:()=>{E(me.tabKey,"new"),be(null)},children:"Split to New Group ◨"}),e.jsx("div",{className:"border-t border-border-subtle my-1 hidden md:block"}),e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors hidden md:block",onClick:k=>{k.stopPropagation(),We(me.tabKey),be(null)},children:["⌨ ",Me[me.tabKey]?`Change shortcut (${Me[me.tabKey]})`:"Set shortcut"]}),Me[me.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 hidden md:block",onClick:()=>{const k={...Me};delete k[me.tabKey],ne(k),be(null)},children:"✕ Remove shortcut"}),G&&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:()=>{G(me.tabKey),be(null)},children:"🚫 Hide from Dashboard"})]}),!E&&!G&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),_e&&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:()=>We(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:k=>k.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. ",ve?"⌘+1":"Ctrl+1",", ",ve?"⌥+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"})]})})]})}const Tt=[{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 open your IDE — it connects automatically.",code:"curl -fsSL https://adhf.dev/install | sh"}];function mr({onClose:t}){const[s,a]=n.useState(0),r=Tt[s],i=s===Tt.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:c=>{c.target===c.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:Tt.map((c,o)=>e.jsx("div",{style:{width:o===s?24:8,height:8,borderRadius:4,background:o===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},o))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:r.visual||r.icon}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx("span",{children:r.icon})," ",r.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:r.desc}),r.code&&e.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[e.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),r.code]}),i&&e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"var(--accent, #a78bfa)",textDecoration:"none"},children:"📚 Learn more in the docs →"})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"1.5rem"},children:[e.jsx("button",{onClick:t,style:{background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"0.85rem",cursor:"pointer"},children:"Skip"}),e.jsx("button",{onClick:()=>i?t():a(c=>c+1),className:"transition-opacity hover:opacity-90",style:{background:"linear-gradient(135deg, #7c3aed, #6366f1)",color:"#fff",border:"none",borderRadius:"0.5rem",padding:"0.55rem 1.5rem",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},children:i?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
|
|
51
|
+
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:F,onCancel:()=>l(null)})]})}const qn=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Jn(){const{preference:t,setPreference:s}=zn();return e.jsx("div",{className:"flex gap-2",children:qn.map(a=>e.jsxs("button",{onClick:()=>s(a.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===a.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:a.icon}),a.label]},a.id))})}const Pt={bgPrimary:"#0f0f13",bgSecondary:"#18181d",surfacePrimary:"#111116",textPrimary:"#fafafa",textSecondary:"#a8a8b3",textMuted:"#7e7e8a",borderSubtle:"#1a1a22",borderDefault:"#2a2a35",accentColor:"#8b5cf6",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#1e1e24",assistantText:"#e0e0e0",containerBg:"#111114",sendButton:"#6366f1",inputBorder:"#2a2a35",bubbleRadius:16},Lt={bgPrimary:"#f0f1f5",bgSecondary:"#e8eaf0",surfacePrimary:"#ffffff",textPrimary:"#1a1a2e",textSecondary:"#3f3f50",textMuted:"#5c5c6e",borderSubtle:"#d8d8e0",borderDefault:"#c0c0cc",accentColor:"#7c3aed",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#f3f4f6",assistantText:"#1f2937",containerBg:"#f0f1f5",sendButton:"#6366f1",inputBorder:"#d1d5db",bubbleRadius:16},Zn=[{id:"midnight",name:"Midnight",description:"Default violet theme",preview:{dark:{userBubble:"linear-gradient(135deg, #8b5cf6, #4f46e5)",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"linear-gradient(135deg, #7c3aed, #0ea5e9)",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"aurora",name:"Aurora",description:"Pink-orange gradient",preview:{dark:{userBubble:"linear-gradient(135deg, #ec4899, #f97316)",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"linear-gradient(135deg, #ec4899, #f97316)",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"}}}],ws="adhdev-chat-theme",Ns="adhdev-chat-theme-custom";function ht(){return typeof window>"u"?"midnight":localStorage.getItem(ws)||"midnight"}function Be(t){try{const s=localStorage.getItem(Ns);if(s){const a=JSON.parse(s);return{...t==="dark"?Pt:Lt,...a[t]}}}catch{}return t==="dark"?Pt:Lt}function xt(t,s){localStorage.setItem(Ns,JSON.stringify({dark:t,light:s}))}function Ke(t,s){const a=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${a}, ${r}, ${i}, ${s})`}function Qt(t,s){const a=Math.min(255,parseInt(t.slice(1,3),16)+s),r=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${a.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}function qe(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ke(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ke(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ke(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",Ke(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ke(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",Qt(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${Qt(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ke(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ke(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ke(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 ${Ke(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 Qn(){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(a=>t.style.removeProperty(a))}function er(t){if(localStorage.setItem(ws,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=rt()?"dark":"light";qe(Be(s))}else Qn()}function tr(){const t=ht();if(t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=rt()?"dark":"light";qe(Be(s))}}function rt(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Te({label:t,value:s,onChange:a}){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=>a(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)&&a(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 tt({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 sr({dark:t,onColorsChange:s}){const a=t?"dark":"light",[r,i]=n.useState(()=>Be(a));n.useEffect(()=>{i(Be(a))},[a]);const c=n.useCallback((o,p)=>{i(u=>{const m={...u,[o]:p},d=Be(a==="dark"?"light":"dark");return a==="dark"?xt(m,d):xt(d,m),qe(m),s(m),m})},[a,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(tt,{title:"App Background",children:[e.jsx(Te,{label:"Background",value:r.bgPrimary,onChange:o=>c("bgPrimary",o)}),e.jsx(Te,{label:"Surface",value:r.bgSecondary,onChange:o=>c("bgSecondary",o)}),e.jsx(Te,{label:"Card",value:r.surfacePrimary,onChange:o=>c("surfacePrimary",o)})]}),e.jsxs(tt,{title:"App Text",children:[e.jsx(Te,{label:"Primary",value:r.textPrimary,onChange:o=>c("textPrimary",o)}),e.jsx(Te,{label:"Secondary",value:r.textSecondary,onChange:o=>c("textSecondary",o)}),e.jsx(Te,{label:"Muted",value:r.textMuted,onChange:o=>c("textMuted",o)})]}),e.jsxs(tt,{title:"Borders & Accent",children:[e.jsx(Te,{label:"Border subtle",value:r.borderSubtle,onChange:o=>c("borderSubtle",o)}),e.jsx(Te,{label:"Border default",value:r.borderDefault,onChange:o=>c("borderDefault",o)}),e.jsx(Te,{label:"Accent",value:r.accentColor,onChange:o=>c("accentColor",o)})]})]}),e.jsxs("div",{children:[e.jsxs(tt,{title:"Chat Bubbles",children:[e.jsx(Te,{label:"User bubble",value:r.userBubble,onChange:o=>c("userBubble",o)}),e.jsx(Te,{label:"User text",value:r.userText,onChange:o=>c("userText",o)}),e.jsx(Te,{label:"Agent bubble",value:r.assistantBubble,onChange:o=>c("assistantBubble",o)}),e.jsx(Te,{label:"Agent text",value:r.assistantText,onChange:o=>c("assistantText",o)})]}),e.jsxs(tt,{title:"Chat Layout",children:[e.jsx(Te,{label:"Chat BG",value:r.containerBg,onChange:o=>c("containerBg",o)}),e.jsx(Te,{label:"Send button",value:r.sendButton,onChange:o=>c("sendButton",o)}),e.jsx(Te,{label:"Input border",value:r.inputBorder,onChange:o=>c("inputBorder",o)}),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:o=>c("bubbleRadius",Number(o.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 o=t?Pt:Lt,u=Be(t?"light":"dark");t?xt(o,u):xt(u,o),i(o),qe(o),s(o)},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 nr(){const[t,s]=n.useState(ht),[a,r]=n.useState(!0),[i,c]=n.useState(()=>Be("dark"));n.useEffect(()=>{r(rt());const u=new MutationObserver(()=>{const d=rt();r(d),ht()==="custom"&&qe(Be(d?"dark":"light"))});u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const m=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{const d=rt();r(d),ht()==="custom"&&qe(Be(d?"dark":"light"))};return m.addEventListener("change",l),()=>{u.disconnect(),m.removeEventListener("change",l)}},[]),n.useEffect(()=>{t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"&&qe(Be(a?"dark":"light"))},[]),n.useEffect(()=>{c(Be(a?"dark":"light"))},[a]);const o=u=>{s(u),er(u),u==="midnight"&&document.documentElement.removeAttribute("data-chat-theme")},p=[...Zn,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:p.map(u=>{const m=t===u.id,l=a?u.preview.dark:u.preview.light,d=u.id==="honey"?"#1a1a1a":u.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>o(u.id),className:"text-left rounded-xl p-3 transition-all",style:{background:m?"var(--bg-glass-hover)":"var(--bg-glass)",border:m?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:m?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:l.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:l.assistantBubble,border:l.assistantBorder,color:l.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:l.userBubble,color:d},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:l.assistantBubble,border:l.assistantBorder,color:l.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[m&&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:u.id==="custom"?"🎨 Custom":u.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:u.description})]})]})]},u.id)})}),t==="custom"&&e.jsx(sr,{dark:a,onColorsChange:u=>c(u)})]})}const Dt="adhdev-accent-color",rr=[{name:"Violet",color:"#8b5cf6"},{name:"Indigo",color:"#6366f1"},{name:"Blue",color:"#3b82f6"},{name:"Cyan",color:"#06b6d4"},{name:"Emerald",color:"#10b981"},{name:"Rose",color:"#f43f5e"},{name:"Orange",color:"#f97316"},{name:"Amber",color:"#f59e0b"}],ct="#8b5cf6";function ar(t){const s=parseInt(t.slice(1,3),16)/255,a=parseInt(t.slice(3,5),16)/255,r=parseInt(t.slice(5,7),16)/255,i=Math.max(s,a,r),c=Math.min(s,a,r);let o=0,p=0;const u=(i+c)/2;if(i!==c){const m=i-c;switch(p=u>.5?m/(2-i-c):m/(i+c),i){case s:o=((a-r)/m+(a<r?6:0))/6;break;case a:o=((r-s)/m+2)/6;break;case r:o=((s-a)/m+4)/6;break}}return{h:Math.round(o*360),s:Math.round(p*100),l:Math.round(u*100)}}function es(t,s){const{h:a,s:r,l:i}=ar(t),c=Math.min(100,i+s);return`hsl(${a}, ${r}%, ${c}%)`}function ft(t,s){const a=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${a}, ${r}, ${i}, ${s})`}function ts(){return typeof window>"u"?ct:localStorage.getItem(Dt)||ct}function or(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",es(t,15)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${es(t,20)})`),s.style.setProperty("--border-accent",ft(t,.4)),s.style.setProperty("--nav-active-bg",ft(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${ft(t,.06)}`)}function ir(){const t=document.documentElement;["--accent-primary","--accent-primary-light","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow"].forEach(a=>t.style.removeProperty(a))}function cr(t){t===ct?(localStorage.removeItem(Dt),ir()):(localStorage.setItem(Dt,t),or(t))}function lr(){const[t,s]=n.useState(ts),[a,r]=n.useState("");n.useEffect(()=>{s(ts())},[]);const i=c=>{s(c),cr(c)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:rr.map(c=>{const o=t===c.color;return e.jsx("button",{onClick:()=>i(c.color),title:c.name,style:{width:36,height:36,borderRadius:10,background:c.color,border:o?"3px solid var(--text-primary)":"3px solid transparent",cursor:"pointer",position:"relative",transition:"transform 0.15s, border-color 0.15s",transform:o?"scale(1.1)":"scale(1)",boxShadow:o?`0 0 12px ${ft(c.color,.4)}`:"none"},children:o&&e.jsx("span",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:14,fontWeight:700,textShadow:"0 1px 2px rgba(0,0,0,0.5)"},children:"✓"})},c.color)})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"Custom:"}),e.jsx("input",{type:"color",value:t,onChange:c=>i(c.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:a||t,onChange:c=>{r(c.target.value),/^#[0-9a-fA-F]{6}$/.test(c.target.value)&&i(c.target.value)},onBlur:()=>r(""),style:{width:80,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}}),t!==ct&&e.jsx("button",{onClick:()=>i(ct),style:{fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:5,padding:"3px 8px",cursor:"pointer"},children:"Reset"})]})]})}const ks="adhdev_hiddenTabs";function dr(){try{const t=localStorage.getItem(ks);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function st(t){try{localStorage.setItem(ks,JSON.stringify([...t]))}catch{}}function ur(){const[t,s]=n.useState(dr),a=n.useCallback(u=>{s(m=>{const l=new Set(m);return l.has(u)?l.delete(u):l.add(u),st(l),l})},[]),r=n.useCallback(u=>{s(m=>{if(m.has(u))return m;const l=new Set(m);return l.add(u),st(l),l})},[]),i=n.useCallback(u=>{s(m=>{if(!m.has(u))return m;const l=new Set(m);return l.delete(u),st(l),l})},[]),c=n.useCallback((u,m)=>{s(l=>{const d=new Set(l);for(const v of m)d.add(v);return st(d),d})},[]),o=n.useCallback((u,m)=>{s(l=>{const d=new Set(l);for(const v of m)d.delete(v);return st(d),d})},[]),p=n.useCallback(u=>t.has(u),[t]);return{hiddenTabs:t,toggleTab:a,hideTab:r,showTab:i,hideAllForDaemon:c,showAllForDaemon:o,isHidden:p}}function Ss({sendDaemonCommand:t,activeConv:s,ides:a,updateIdeChats:r,setToasts:i,setLocalUserMessages:c,setClearedTabs:o,setActionLogs:p,pinTab:u,isStandalone:m}){const[l,d]=n.useState(""),[v,j]=n.useState(!1),[x,I]=n.useState(!1),[T,f]=n.useState(!1),N=n.useCallback(async()=>{if(!s)return;const R=l.trim();if(!R)return;const F=s.ideId,H=s.tabKey;d(""),u(H,[100,500,1500,3e3]);const Z=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,b={role:"user",content:R,timestamp:Date.now(),_localId:Z};c(G=>({...G,[H]:[...G[H]||[],b]}));try{if(Ue(s)&&!Oe(s)){const G=F||s.daemonId||"";if(!G)return;const re=s.ideType||s.agentType||"";await t(G,"agent_command",{agentType:re,cliType:re,action:"send_chat",message:R,text:R})}else if(Oe(s)){const G=F||s.daemonId||"";if(!G)return;await t(G,"send_chat",{message:R,text:R,agentType:s.agentType})}else{const G=F||s.daemonId||"";if(!G)return;await t(G,"send_chat",{message:R,text:R,...s.streamSource==="agent-stream"&&{agentType:s.agentType}})}setTimeout(()=>{const G=Date.now()-6e4;c(re=>{const V=re[H];if(!V)return re;const ee=V.filter(O=>O.timestamp>G);return ee.length===V.length?re:{...re,[H]:ee}})},6e4)}catch(G){console.error("Send failed",G),d(R),c(re=>({...re,[H]:(re[H]||[]).filter(V=>V._localId!==Z)}))}},[s,l,t,c,u]),B=n.useCallback(async()=>{if(s)try{m?await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0}):await t(s.ideId,"vscode_command_exec",{commandId:"adhdev.relaunchWithCdp",args:[{force:!0}]})}catch(R){console.error("Relaunch failed",R)}},[s,m,t]),K=n.useCallback(async R=>{try{await t("standalone","launch_ide",{ideType:R,enableCdp:!0})}catch(F){console.error("Launch failed",F)}},[t]),E=n.useCallback(async R=>{if(s){console.log("[ModalButton] ideId:",s.ideId,"button:",R),p(F=>[...F,{ideId:s.tabKey,text:`🖱️ **${R}** clicked`,timestamp:Date.now()}]);try{const H=(s.modalButtons||[]).indexOf(R),Z=R.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),b=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(Z),G=s.ideId||s.daemonId||"";(await t(G,"resolve_action",{button:R,action:b?"approve":"reject",...H>=0&&{buttonIndex:H},...s.streamSource==="agent-stream"&&{agentType:s.agentType}})).success||p(V=>[...V,{ideId:s.tabKey,text:`⚠️ **${R}** failed — button not found`,timestamp:Date.now()}])}catch(F){console.error("[ModalButton] Error:",F),p(H=>[...H,{ideId:s.tabKey,text:`❌ **${R}** error`,timestamp:Date.now()}])}}},[s,t,p]),A=n.useCallback(async(R,F)=>{try{const H=R||(s==null?void 0:s.daemonId)||"",Z=await t(H,"switch_chat",{id:F,sessionId:F,...(s==null?void 0:s.streamSource)==="agent-stream"&&{agentType:s==null?void 0:s.agentType}}),b=Z==null?void 0:Z.result;(Z==null?void 0:Z.success)===!0||b==="switched"||b==="switched-by-title"||(b===!1||b==="not_found"?i(re=>[...re,{id:Date.now(),message:"⚠️ Session tab not found — try refreshing history",type:"warning",timestamp:Date.now()}]):typeof b=="string"&&b.startsWith("error:")?i(re=>[...re,{id:Date.now(),message:`⚠️ Switch error: ${b}`,type:"warning",timestamp:Date.now()}]):i(re=>[...re,{id:Date.now(),message:"⚠️ Session switch failed",type:"warning",timestamp:Date.now()}]))}catch(H){console.error("Switch failed",H),i(Z=>[...Z,{id:Date.now(),message:`❌ Switch failed: ${H.message||"connection error"}`,type:"warning",timestamp:Date.now()}])}},[s,t,i]),$=n.useCallback(async()=>{if(!(!s||v)){j(!0);try{const R=s.ideId||s.daemonId||"";await t(R,"new_chat",{...s.streamSource==="agent-stream"&&{agentType:s.agentType}}),o(F=>({...F,[s.tabKey]:Date.now()})),c(F=>({...F,[s.tabKey]:[]}))}catch(R){console.error("New chat failed",R)}finally{j(!1)}}},[s,v,t,o,c]),C=n.useCallback(async()=>{if(!s||T)return;f(!0);const R=s.tabKey;try{await t(s.ideId,"agent_stream_focus",{agentType:s.agentType}),u(R,[200,1500,3e3])}catch(F){console.error("Focus agent failed",F)}finally{f(!1)}},[s,T,t,u]),y=n.useCallback(async()=>{var R;if(!(!s||x)){I(!0);try{const F=s.ideId||s.daemonId||"",H=await t(F,"list_chats",{forceExpand:!0,...s.streamSource==="agent-stream"&&{agentType:s.agentType}}),Z=(H==null?void 0:H.chats)||((R=H==null?void 0:H.result)==null?void 0:R.chats);H!=null&&H.success&&Array.isArray(Z)&&r(s.ideId,Z)}catch(F){console.error("Refresh history failed",F)}finally{I(!1)}}},[s,x,t,r]);return{agentInput:l,setAgentInput:d,isCreatingChat:v,isRefreshingHistory:x,isFocusingAgent:T,handleSendChat:N,handleRelaunch:B,handleLaunchIde:K,handleModalButton:E,handleSwitchSession:A,handleNewChat:$,handleFocusAgent:C,handleRefreshHistory:y}}let Mt=null;function xr({conversations:t,ides:s,messageReceivedAt:a,actionLogs:r,ptyBuffers:i,screenshotMap:c,setScreenshotMap:o,sendDaemonCommand:p,updateIdeChats:u,setToasts:m,setLocalUserMessages:l,setClearedTabs:d,setActionLogs:v,pinTab:j,isStandalone:x,userName:I,groupIndex:T,isFocused:f,onFocus:N,isSplitMode:B,numGroups:K,onMoveTab:E,onClose:A,onReceiveTab:$,style:C,detectedIdes:y,handleLaunchIde:R,onActiveTabChange:F,initialActiveTabId:H,initialTabOrder:Z,onTabOrderChange:b,onHideTab:G}){const{sendCommand:re}=Ye(),V=n.useRef(null),[ee,O]=n.useState(!1),ae=n.useRef(0),oe=n.useRef(null),[ue,ie]=n.useState(H??null);n.useEffect(()=>{H&&H!==ue&&ie(H)},[H]);const[L,g]=n.useState(Z??[]),[D,h]=n.useState(null),z=n.useRef(null),Q=n.useRef(null);n.useEffect(()=>{const k=new Set(t.map(U=>U.tabKey));g(U=>{const ce=U.filter(q=>k.has(q)),Y=t.filter(q=>!U.includes(q.tabKey)).map(q=>q.tabKey),le=[...ce,...Y];return le.length===U.length&&le.every((q,X)=>q===U[X])?U:le})},[t]);const xe=D??L,ge=n.useMemo(()=>{if(xe.length===0)return t;const k=new Map(xe.map((U,ce)=>[U,ce]));return[...t].sort((U,ce)=>{const Y=k.get(U.tabKey)??999,le=k.get(ce.tabKey)??999;return Y-le})},[t,xe]);n.useEffect(()=>{if(ge.length===0){ie(null),F==null||F(null);return}ue&&ge.some(k=>k.tabKey===ue)||(ie(ge[0].tabKey),F==null||F(ge[0].tabKey))},[ge,ue]);const he=ge.find(k=>k.tabKey===ue),ke=n.useCallback((k,U,ce)=>{g(Y=>{const le=Y.filter(pe=>pe!==k),q=le.indexOf(U);if(q<0)return Y;const X=ce==="left"?q:q+1;return le.splice(X,0,k),b==null||b(le),le}),h(null)},[b]),W=n.useCallback((k,U,ce)=>{const le=(L.length>0?L:t.map(pe=>pe.tabKey)).filter(pe=>pe!==k),q=le.indexOf(U);if(q<0)return;const X=ce==="left"?q:q+1;le.splice(X,0,k),z.current=le,h(le)},[L,t]),te=Ss({sendDaemonCommand:p,activeConv:he,ides:s,updateIdeChats:u,setToasts:m,setLocalUserMessages:l,setClearedTabs:d,setActionLogs:v,pinTab:j,isStandalone:x}),[me,be]=n.useState(null);n.useEffect(()=>{if(!me)return;const k=U=>{const ce=document.querySelector("[data-pane-context-menu]");ce&&ce.contains(U.target)||be(null)};return window.addEventListener("mousedown",k,!0),()=>window.removeEventListener("mousedown",k,!0)},[me]);const Pe="adhdev-tab-shortcuts",ve=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[Me,et]=n.useState(()=>{try{return JSON.parse(localStorage.getItem(Pe)||"{}")}catch{return{}}}),[_e,We]=n.useState(null),Ie=n.useCallback(k=>{const U=[];k.metaKey&&U.push(ve?"⌘":"Meta"),k.ctrlKey&&U.push("Ctrl"),k.altKey&&U.push(ve?"⌥":"Alt"),k.shiftKey&&U.push(ve?"⇧":"Shift");const ce=k.key;if(["Control","Alt","Shift","Meta"].includes(ce))return null;const Y=ce.length===1?ce.toUpperCase():ce;return U.push(Y),U.join("+")},[ve]),P=n.useCallback((k,U)=>Ie(k)===U,[Ie]),ne=n.useCallback(k=>{et(k),localStorage.setItem(Pe,JSON.stringify(k))},[]);n.useEffect(()=>{if(!_e)return;const k=U=>{if(U.preventDefault(),U.stopPropagation(),U.key==="Escape"){We(null);return}const ce=Ie(U);if(!ce)return;const Y={...Me};for(const[le,q]of Object.entries(Y))q===ce&&delete Y[le];Y[_e]=ce,ne(Y),We(null)};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)},[_e,Me,ne,Ie]),n.useEffect(()=>{const k=U=>{if(!(!U.ctrlKey&&!U.metaKey&&!U.altKey)){for(const[ce,Y]of Object.entries(Me))if(P(U,Y)&&ge.some(le=>le.tabKey===ce)){U.preventDefault(),N(),ie(ce),F==null||F(ce);return}}};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[Me,ge,N,F,P]);const J=he&&Ue(he)&&!Oe(he);n.useEffect(()=>{const k=()=>{ae.current=0,O(!1)};return window.addEventListener("dragend",k),window.addEventListener("drop",k),()=>{window.removeEventListener("dragend",k),window.removeEventListener("drop",k)}},[]);const fe=n.useRef(null);return n.useEffect(()=>{const k=fe.current;if(!k)return;const U=ce=>{Math.abs(ce.deltaY)>Math.abs(ce.deltaX)&&(ce.preventDefault(),k.scrollLeft+=ce.deltaY)};return k.addEventListener("wheel",U,{passive:!1}),()=>k.removeEventListener("wheel",U)},[]),e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:N,onDragEnter:k=>{if(k.dataTransfer.types.includes("text/tab-key")){ae.current++;const U=Mt;U&&t.some(Y=>Y.tabKey===U)||O(!0)}},onDragOver:k=>{k.dataTransfer.types.includes("text/tab-key")&&k.preventDefault()},onDragLeave:()=>{ae.current--,ae.current<=0&&(ae.current=0,O(!1))},onDrop:k=>{ae.current=0,O(!1),h(null);const U=k.dataTransfer.getData("text/tab-key");if(!U)return;k.preventDefault(),t.some(Y=>Y.tabKey===U)?g(Y=>{const le=Y.filter(q=>q!==U);return le.push(U),b==null||b(le),le}):$&&$(U)},style:{...C,outline:ee?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},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:fe,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:[ge.map((k,U)=>{const ce=ue===k.tabKey,Y=k.status==="working"?"agent-tab-working":k.status==="waiting_approval"?"agent-tab-waiting":"",le=k.connectionState==="failed"||k.connectionState==="closed",q=Q.current===k.tabKey;return e.jsxs("div",{"data-tabkey":k.tabKey,className:`${Y} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!("ontouchstart"in window),onDragStart:X=>{Mt=k.tabKey,Q.current=k.tabKey,X.dataTransfer.setData("text/tab-key",k.tabKey),X.dataTransfer.effectAllowed="move"},onDragEnd:()=>{Mt=null,Q.current=null;const X=z.current;X&&(g(X),b==null||b(X)),z.current=null,h(null),ae.current=0,O(!1)},onDragOver:X=>{const pe=Q.current;if(!(!pe||pe===k.tabKey)&&X.dataTransfer.types.includes("text/tab-key")){X.preventDefault(),X.stopPropagation();const se=X.currentTarget.getBoundingClientRect(),je=se.left+se.width/2,we=X.clientX<je?"left":"right";W(pe,k.tabKey,we)}},onDrop:X=>{X.preventDefault(),X.stopPropagation();const pe=X.dataTransfer.getData("text/tab-key");if(pe&&pe!==k.tabKey){const se=X.currentTarget.getBoundingClientRect(),je=se.left+se.width/2,we=X.clientX<je?"left":"right";ge.some(Ne=>Ne.tabKey===pe)?ke(pe,k.tabKey,we):$&&$(pe)}h(null)},onClick:X=>{X.stopPropagation(),N(),ie(k.tabKey),F==null||F(k.tabKey),k.streamSource==="agent-stream"&&k.agentType&&re(k.ideId,"agent_stream_focus",{agentType:k.agentType}).catch(()=>{}),Ue(k)&&setTimeout(()=>{var pe,se;return(se=(pe=V.current)==null?void 0:pe.bumpResize)==null?void 0:se.call(pe)},100)},onContextMenu:X=>{X.preventDefault(),be({x:X.clientX,y:X.clientY,tabKey:k.tabKey})},onTouchStart:X=>{const pe=X.touches[0],se=pe.clientX,je=pe.clientY;oe.current=setTimeout(()=>{be({x:se,y:je,tabKey:k.tabKey})},600)},onTouchEnd:()=>{oe.current&&clearTimeout(oe.current)},onTouchMove:()=>{oe.current&&clearTimeout(oe.current)},style:{background:ce?"var(--bg-primary)":"var(--bg-glass)",borderTop:ce?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:ce?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:ce?"1px solid var(--border-subtle)":"1px solid transparent",opacity:q?.4:le?ce?.6:.3:ce?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[k.status==="working"?e.jsx("div",{className:"tab-spinner"}):k.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):le?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400 animate-pulse",children:"○"}):k.connectionState==="connecting"||k.connectionState==="new"?e.jsx("div",{className:"tab-connecting-spinner"}):k.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:k.displayPrimary,children:k.displayPrimary}),e.jsx("div",{className:"text-[8px] opacity-50 flex gap-1 items-center",children:le?e.jsx("span",{className:"text-yellow-400 opacity-100",children:"Reconnecting…"}):k.connectionState==="connecting"||k.connectionState==="new"?e.jsxs("span",{className:"text-blue-400 opacity-100",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[k.displaySecondary,k.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{className:"opacity-70",children:["🖥 ",k.machineName]})]})]})})]}),Me[k.tabKey]&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${Me[k.tabKey]}`,children:Me[k.tabKey]})]},k.tabKey)}),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",children:he?e.jsxs(e.Fragment,{children:[e.jsx(gs,{activeConv:he,onModalButton:te.handleModalButton}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!J&&!Oe(he)&&c[he.ideId]?e.jsx(dn,{screenshotUrl:c[he.ideId],mode:"preview",onDismiss:()=>{const k={...c};delete k[he.ideId],o(k)}}):!J&&!Oe(he)&&he.cdpConnected===!1?e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[e.jsx("span",{className:"text-sm",children:e.jsx(xs,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:te.handleRelaunch,children:"Relaunch with CDP"})]}):null}),J?e.jsx(xn,{activeConv:he,ptyBuffers:i,terminalRef:V,agentInput:te.agentInput,setAgentInput:te.setAgentInput,handleSendChat:te.handleSendChat,handleModalButton:te.handleModalButton}):e.jsx(bs,{activeConv:he,ides:s,agentInput:te.agentInput,setAgentInput:te.setAgentInput,handleSendChat:te.handleSendChat,handleFocusAgent:te.handleFocusAgent,isFocusingAgent:te.isFocusingAgent,messageReceivedAt:a,actionLogs:r,userName:I})]}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:t.length===0&&!B&&y&&R?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("div",{className:"text-[64px]",children:"🦦"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-white shadow-sm",children:"Waiting for your IDE"}),e.jsx("p",{className:"text-[14px] text-zinc-400 mb-8 leading-relaxed max-w-md mx-auto",children:x?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!x&&e.jsxs("div",{className:"text-left bg-[#0c0c0e] border border-violet-500/20 rounded-xl p-5 font-mono text-[13px] shadow-2xl shadow-violet-500/10 w-full mx-auto leading-relaxed relative group select-all",children:[e.jsx("div",{className:"text-zinc-500 text-[10px] uppercase font-sans tracking-widest font-bold mb-2",children:"1. Install and authenticate"}),e.jsxs("div",{className:"mb-4 text-violet-400 flex items-center gap-3",children:[e.jsx("span",{className:"text-zinc-600 select-none",children:"$"}),e.jsx("span",{children:"npm install -g adhdev && adhdev setup"})]}),e.jsx("div",{className:"text-zinc-500 text-[10px] uppercase font-sans tracking-widest font-bold mb-2",children:"2. Start monitoring"}),e.jsxs("div",{className:"text-violet-400 flex items-center gap-3",children:[e.jsx("span",{className:"text-zinc-600 select-none",children:"$"}),e.jsx("span",{children:"adhdev daemon"})]})]}),x&&y&&y.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-zinc-500",children:"Fast Launch"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:y.map(k=>e.jsxs("button",{className:"btn btn-sm bg-violet-500/10 border border-violet-500/25 text-violet-300 text-xs font-medium px-4 py-2.5 rounded-lg cursor-pointer flex items-center gap-2 transition-all hover:bg-violet-500/20 hover:scale-105 active:scale-95",onClick:()=>R&&R(k.type),children:[e.jsx(nn,{size:14,className:"opacity-70"})," Launch ",k.name]},k.type))})]}),!x&&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-violet-400 hover:text-violet-300 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:B?"Move a tab here to view":"No active agent"})})}),me&&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:me.x,top:me.y},children:[E&&T>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors hidden md:block",onClick:()=>{E(me.tabKey,"left"),be(null)},children:"← Move to Left Group"}),E&&T<K-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors hidden md:block",onClick:()=>{E(me.tabKey,"right"),be(null)},children:"Move to Right Group →"}),E&&K<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors hidden md:block",onClick:()=>{E(me.tabKey,"new"),be(null)},children:"Split to New Group ◨"}),e.jsx("div",{className:"border-t border-border-subtle my-1 hidden md:block"}),e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors hidden md:block",onClick:k=>{k.stopPropagation(),We(me.tabKey),be(null)},children:["⌨ ",Me[me.tabKey]?`Change shortcut (${Me[me.tabKey]})`:"Set shortcut"]}),Me[me.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 hidden md:block",onClick:()=>{const k={...Me};delete k[me.tabKey],ne(k),be(null)},children:"✕ Remove shortcut"}),G&&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:()=>{G(me.tabKey),be(null)},children:"🚫 Hide from Dashboard"})]}),!E&&!G&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),_e&&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:()=>We(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:k=>k.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. ",ve?"⌘+1":"Ctrl+1",", ",ve?"⌥+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"})]})})]})}const Tt=[{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 && adhdev setup"}];function mr({onClose:t}){const[s,a]=n.useState(0),r=Tt[s],i=s===Tt.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:c=>{c.target===c.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:Tt.map((c,o)=>e.jsx("div",{style:{width:o===s?24:8,height:8,borderRadius:4,background:o===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},o))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:r.visual||r.icon}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx("span",{children:r.icon})," ",r.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:r.desc}),r.code&&e.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[e.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),r.code]}),i&&e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"var(--accent, #a78bfa)",textDecoration:"none"},children:"📚 Learn more in the docs →"})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"1.5rem"},children:[e.jsx("button",{onClick:t,style:{background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"0.85rem",cursor:"pointer"},children:"Skip"}),e.jsx("button",{onClick:()=>i?t():a(c=>c+1),className:"transition-opacity hover:opacity-90",style:{background:"linear-gradient(135deg, #7c3aed, #6366f1)",color:"#fff",border:"none",borderRadius:"0.5rem",padding:"0.55rem 1.5rem",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},children:i?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
|
|
52
52
|
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
|
|
53
53
|
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
|
|
54
54
|
`})]})}function pr(){const{sendCommand:t}=Ye(),[s,a]=os(),r=s.get("activeTab"),i=jt(),{updateIdeChats:c,screenshotMap:o,setScreenshotMap:p}=i,u=i.ides||[],[m,l]=n.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),d=i.toasts||[],v=i.setToasts||(()=>{}),j=i.wsStatus||"connected",x=i.isConnected??!0,I=i.connectionStates||{};i.retryConnection;const T=i.showReconnected||!1,[f,N]=n.useState(()=>{try{const w=localStorage.getItem("adhdev_splitGroups");if(w){const S=JSON.parse(w);return new Map(S)}}catch{}return new Map}),[B,K]=n.useState(()=>{try{const w=localStorage.getItem("adhdev_focusedGroup");if(w)return parseInt(w,10)||0}catch{}return 0}),[E,A]=n.useState(()=>{try{const w=localStorage.getItem("adhdev_groupActiveTabs");if(w)return JSON.parse(w)}catch{}return{}}),$=n.useRef(!1),[C,y]=n.useState(()=>{try{const w=localStorage.getItem("adhdev_groupTabOrders");if(w)return JSON.parse(w)}catch{}return{}}),[R,F]=n.useState(()=>{try{const w=localStorage.getItem("adhdev_splitSizes");if(w)return JSON.parse(w)}catch{}return[]});n.useEffect(()=>{try{f.size===0?localStorage.removeItem("adhdev_splitGroups"):localStorage.setItem("adhdev_splitGroups",JSON.stringify([...f.entries()]))}catch{}},[f]),n.useEffect(()=>{try{R.length>0?localStorage.setItem("adhdev_splitSizes",JSON.stringify(R)):localStorage.removeItem("adhdev_splitSizes")}catch{}},[R]),n.useEffect(()=>{try{localStorage.setItem("adhdev_focusedGroup",String(B))}catch{}},[B]),n.useEffect(()=>{try{localStorage.setItem("adhdev_groupActiveTabs",JSON.stringify(E))}catch{}},[E]),n.useEffect(()=>{try{localStorage.setItem("adhdev_groupTabOrders",JSON.stringify(C))}catch{}},[C]);const[H,Z]=n.useState(()=>typeof window<"u"&&window.innerWidth<768);n.useEffect(()=>{const w=window.matchMedia("(max-width: 767px)"),S=M=>Z(M.matches);return w.addEventListener("change",S),()=>w.removeEventListener("change",S)},[]);const b=n.useMemo(()=>H||f.size===0?1:Math.max(1,...f.values())+1,[f,H]),G=b>1,re=n.useCallback((w,S)=>{N(M=>{const _=new Map(M);return S===0?_.delete(w):_.set(w,S),_}),K(S)},[]),V=n.useCallback(w=>{N(S=>{const _=(S.size===0?0:Math.max(0,...S.values()))+1;if(_>=4)return S;const de=new Map(S);return de.set(w,_),de}),K(S=>S+1)},[]),ee=n.useCallback(w=>{N(S=>{const M=new Map;for(const[_,de]of S)de!==w&&(de>w?M.set(_,de-1):M.set(_,de));return M}),F(S=>{if(S.length<=1)return[];const M=[...S];M.splice(w,1);const _=M.reduce((de,ye)=>de+ye,0);return M.map(de=>de/_*100)}),K(0)},[]),O=n.useRef(null),ae=n.useCallback((w,S)=>{S.preventDefault();const M=O.current;if(!M)return;const _=S.clientX,de=M.offsetWidth,ye=R.length===b?[...R]:Array(b).fill(100/b),Se=$e=>{const Wt=($e.clientX-_)/de*100,wt=[...ye];wt[w]=Math.max(15,ye[w]+Wt),wt[w+1]=Math.max(15,ye[w+1]-Wt),F(wt)},Ee=()=>{document.removeEventListener("mousemove",Se),document.removeEventListener("mouseup",Ee),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",Se),document.addEventListener("mouseup",Ee)},[R,b]),[oe,ue]=n.useState({}),[ie,L]=n.useState(!1),[g,D]=n.useState([]),[h,z]=n.useState({}),[Q,xe]=n.useState({}),[ge,he]=n.useState(!1),[ke,W]=n.useState(!1);n.useEffect(()=>{const w=M=>{var _;(_=M.dataTransfer)!=null&&_.types.includes("text/tab-key")&&W(!0)},S=()=>{W(!1),he(!1)};return window.addEventListener("dragstart",w),window.addEventListener("dragend",S),window.addEventListener("drop",S),()=>{window.removeEventListener("dragstart",w),window.removeEventListener("dragend",S),window.removeEventListener("drop",S)}},[]);const te=u.find(w=>w.type==="adhdev-daemon"),me=(te==null?void 0:te.detectedIdes)||[],be=!!te,Pe=n.useMemo(()=>{const w=u.filter(M=>M.type!=="adhdev-daemon"),S=new Map;for(const M of w){const _=S.get(M.id);if(!_)S.set(M.id,M);else{const de=(_.workspace?1:0)+(_.activeChat?1:0);((M.workspace?1:0)+(M.activeChat?1:0)>de||(M.timestamp||0)>(_.timestamp||0))&&S.set(M.id,M)}}return Array.from(S.values())},[u]),ve=n.useMemo(()=>{const w=Cn(Pe,h,u,I),S=Date.now();return w.map(M=>{const _=Q[M.tabKey];return _&&S-_<5e3?{...M,messages:[],title:""}:M})},[Pe,h,Q,u]),{hiddenTabs:Me,toggleTab:et}=ur(),_e=n.useMemo(()=>ve.filter(w=>!Me.has(w.tabKey)),[ve,Me]);n.useEffect(()=>{Rn()},[]);const We=n.useMemo(()=>_e.map(w=>({id:w.tabKey,name:w.title||w.agentName||w.ideId,status:w.status,activeModal:w.modalMessage?{message:w.modalMessage,buttons:w.modalButtons}:null})),[_e]);Ln(We);const Ie=n.useMemo(()=>{const w=Array.from({length:b},()=>[]);for(const S of _e){const M=f.get(S.tabKey)??0,_=Math.min(M,b-1);w[_].push(S)}return w},[_e,f,b]);n.useEffect(()=>{const w=new Set(_e.map(S=>S.tabKey));N(S=>{let M=!1;const _=new Map;for(const[de,ye]of S)w.has(de)?_.set(de,ye):M=!0;return M?_:S})},[ve]),n.useEffect(()=>{if(G)for(let w=b-1;w>=1;w--)[...f.values()].some(M=>M===w)||ee(w)},[f,b,G,ee]),n.useEffect(()=>{if(!r||$.current||ve.length===0)return;const w=ve.find(S=>S.tabKey===r)||ve.find(S=>S.ideId===r)||ve.find(S=>S.ideType===r||S.agentType===r);if(w){const S=f.get(w.tabKey)??0;A(M=>({...M,[S]:w.tabKey})),K(S),$.current=!0,a(M=>{const _=new URLSearchParams(M);return _.delete("activeTab"),_},{replace:!0})}},[r,ve,f]),n.useEffect(()=>{if(Object.keys(Q).length===0)return;const S=setTimeout(()=>{xe(M=>{const _=Date.now(),de={};for(const[ye,Se]of Object.entries(M))_-Se<5e3&&(de[ye]=Se);return Object.keys(de).length===Object.keys(M).length?M:de})},5500);return()=>clearTimeout(S)},[Q]);const P=n.useMemo(()=>{var S,M;const w=E[B];if(w){const _=ve.find(de=>de.tabKey===w);if(_)return _}return((S=Ie[B])==null?void 0:S[0])||((M=Ie[0])==null?void 0:M[0])},[E,B,ve,Ie]),ne=n.useCallback((w,S)=>{},[]);n.useEffect(()=>{var _;const w=Date.now();let S=!1;const M={...oe};for(const de of ve)(_=de.messages)!=null&&_.length&&de.messages.forEach((ye,Se)=>{const Ee=`${de.ideId}-${ye.id??`i-${Se}`}`;M[Ee]==null&&(M[Ee]=w,S=!0)});S&&ue(M)},[ve]);const J=n.useRef(!1);n.useEffect(()=>{if(!ie){J.current=!1;return}if(!P||J.current||U)return;const w=u.find(S=>S.id===P.ideId);w&&(!w.chats||w.chats.length===0)&&(J.current=!0,q())},[ie,P==null?void 0:P.ideId]),n.useEffect(()=>{const w=setInterval(()=>{const S=Date.now()-3e5;D(M=>{const _=M.filter(de=>de.timestamp>S).slice(-100);return _.length===M.length?M:_})},6e4);return()=>clearInterval(w)},[]);const fe=n.useRef(new Map);n.useEffect(()=>{const w=(M,_)=>{var de;if(_){ys.emit(M,_);for(const ye of ve){if(!Ue(ye))continue;const Se=(de=ye.ideId)!=null&&de.includes(":cli:")?ye.ideId.split(":cli:")[1]:"";if(M===Se||M===ye.agentType||M===ye.ideType){const $e=fe.current.get(ye.tabKey)||[];$e.push(_),$e.length>1e4&&$e.splice(0,$e.length-5e3),fe.current.set(ye.tabKey,$e)}}}},S=bn.onPtyOutput(w);return()=>{S()}},[ve]),n.useEffect(()=>{const w=S=>{if(S.ctrlKey&&S.key==="\\"){if(S.preventDefault(),G)N(new Map),K(0);else{const M=ve[1];M&&V(M.tabKey)}return}S.ctrlKey&&(S.key==="["||S.key==="]")&&G&&(S.preventDefault(),K(M=>S.key==="]"?Math.min(M+1,b-1):Math.max(M-1,0)))};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[G,ve,V,b]),n.useEffect(()=>{Je.setIdes(u)},[u]),n.useEffect(()=>{Je.setResolveAction((w,S,M)=>{t(w,S,M).catch(()=>{})})},[t]),n.useEffect(()=>{const w=Je.onToast(_=>{v(ye=>ye.some(Ee=>Ee.message===_.message&&_.timestamp-Ee.timestamp<3e3)?ye:[...ye.slice(-4),{id:_.id,message:_.message,type:_.type,timestamp:_.timestamp,ideId:_.ideId,actions:_.actions}]);const de=_.duration||5e3;setTimeout(()=>v(ye=>ye.filter(Se=>Se.id!==_.id)),de)}),S=Je.onSystemMessage((_,de)=>{z(ye=>{for(const Se of Object.keys(ye))if(Se.includes(_))return{...ye,[Se]:[...ye[Se]||[],de]};return ye})}),M=Je.onClearSystemMessage((_,de)=>{z(ye=>{const Se={...ye};for(const Ee of Object.keys(Se))Ee.includes(_)&&(Se[Ee]=(Se[Ee]||[]).filter($e=>{var vt;return!($e.role==="system"&&((vt=$e._localId)!=null&&vt.startsWith(de)))}));return Se})});return()=>{w(),S(),M()}},[]),n.useEffect(()=>{const w=fn.on("status_event",S=>Je.handleRawEvent(S,"ws"));return()=>{w()}},[]),n.useEffect(()=>{var S;const w=M=>{const _=M.data;(_==null?void 0:_.type)==="notification_action"&&_.action==="approve"&&_.ideId&&t(_.ideId,"resolve_action",{action:"approve",button:"Approve"}).catch(de=>console.error("[SW Action] approve failed:",de))};return(S=navigator.serviceWorker)==null||S.addEventListener("message",w),()=>{var M;return(M=navigator.serviceWorker)==null?void 0:M.removeEventListener("message",w)}},[]);const{isCreatingChat:k,isRefreshingHistory:U,handleLaunchIde:ce,handleSwitchSession:Y,handleNewChat:le,handleRefreshHistory:q}=Ss({sendDaemonCommand:t,activeConv:P,ides:u,updateIdeChats:c,setToasts:v,setLocalUserMessages:z,setClearedTabs:xe,setActionLogs:D,pinTab:ne,isStandalone:be}),X=n.useMemo(()=>u.filter(w=>w.type==="adhdev-daemon"&&w.versionMismatch),[u]),[pe,se]=n.useState(!1),[je,we]=n.useState({}),Ne=n.useCallback(async w=>{var S,M;we(_=>({..._,[w]:"upgrading"}));try{const _=await t(w,"daemon_upgrade",{});(S=_==null?void 0:_.result)!=null&&S.upgraded||(M=_==null?void 0:_.result)!=null&&M.success?we(de=>({...de,[w]:"done"})):we(de=>({...de,[w]:"error"}))}catch{we(_=>({..._,[w]:"error"}))}},[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(mn,{wsStatus:j,showReconnected:T}),X.length>0&&!pe&&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",children:"🔄"}),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",X[0].version]})," → ",e.jsxs("strong",{children:["v",X[0].serverVersion]})]}),X.map(w=>{var _;const S=w.machineNickname||((_=w.machine)==null?void 0:_.hostname)||w.hostname||"Machine",M=je[w.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:S}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",w.version]}),M==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):M==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):M==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>Ne(w.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:()=>Ne(w.id),children:"Upgrade"})]},w.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:()=>se(!0),title:"Dismiss",children:"✕"})]}),e.jsx(yn,{activeConv:P,agentCount:Pe.length,wsStatus:j,isConnected:x,onOpenHistory:()=>L(!0)}),e.jsxs("div",{ref:O,className:`flex-1 min-h-0 flex ${G?"flex-row":"flex-col"} overflow-hidden`,children:[Ie.map((w,S)=>{const M=G&&R.length===b?`${R[S]}%`:void 0;return e.jsxs(_s.Fragment,{children:[G&&S>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:_=>ae(S-1,_),onDoubleClick:()=>ee(S),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(xr,{style:G?{flexBasis:M??`${100/b}%`,flexGrow:M?0:1,flexShrink:M?0:1}:void 0,conversations:w,ides:u,messageReceivedAt:oe,actionLogs:g,ptyBuffers:fe,screenshotMap:o,setScreenshotMap:p,sendDaemonCommand:t,updateIdeChats:c,setToasts:v,setLocalUserMessages:z,setClearedTabs:xe,setActionLogs:D,pinTab:ne,isStandalone:be,userName:i.userName,groupIndex:S,isFocused:B===S,onFocus:()=>K(S),isSplitMode:G,numGroups:b,onMoveTab:(_,de)=>{de==="left"&&S>0?re(_,S-1):de==="right"&&S<b-1?re(_,S+1):de==="new"&&b<4&&V(_)},onClose:G?()=>ee(S):void 0,onReceiveTab:_=>re(_,S),detectedIdes:S===0?me:void 0,handleLaunchIde:S===0?ce:void 0,onActiveTabChange:_=>A(de=>({...de,[S]:_})),initialActiveTabId:E[S],initialTabOrder:C[S],onTabOrderChange:_=>y(de=>({...de,[S]:_})),onHideTab:et})]},S)}),!H&&b<4&&e.jsxs("div",{className:"relative shrink-0 w-0 z-50",children:[e.jsx("div",{className:"fixed right-0 top-0 bottom-0 w-16",style:{pointerEvents:ke?"auto":"none"},onDragOver:w=>{w.dataTransfer.types.includes("text/tab-key")&&(w.preventDefault(),he(!0))},onDragLeave:()=>he(!1),onDrop:w=>{w.preventDefault(),he(!1);const S=w.dataTransfer.getData("text/tab-key");S&&V(S)}}),e.jsx("div",{className:"fixed right-0 top-0 bottom-0 pointer-events-none transition-all duration-200",style:{width:ge?"120px":"0px",background:"var(--accent-primary)",opacity:ge?.15:0,borderLeft:ge?"2px dashed var(--accent-primary)":"none"}})]})]}),ie&&P&&e.jsx(wn,{activeConv:P,ides:u,isCreatingChat:k,isRefreshingHistory:U,onClose:()=>L(!1),onNewChat:le,onSwitchSession:Y,onRefreshHistory:q}),e.jsx("style",{children:`
|
|
@@ -68,4 +68,4 @@ Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Mach
|
|
|
68
68
|
This will terminate the process.`))try{const h=await s(t,"stop_cli",{cliType:L,dir:g,_targetInstance:D});h!=null&&h.success?y("info",`${L} stopped`):y("error",`Stop failed: ${(h==null?void 0:h.error)||"Unknown error"}`)}catch(h){y("error",`Stop failed: ${h.message}`)}},[t,y,s]),b=n.useCallback(async L=>{try{await s(L.daemonId,"restart_ide",{ideType:L.type}),y("info",`${De(L.type)} restart initiated`)}catch(g){y("error",`Restart failed: ${g.message}`)}},[y,s]),G=n.useCallback(async L=>{if(window.confirm(`Stop ${De(L.type)}?
|
|
69
69
|
This will disconnect CDP and optionally kill the process.`))try{const g=await s(L.daemonId,"stop_ide",{ideType:L.type,killProcess:!0});g!=null&&g.success?y("info",`${De(L.type)} stopped`):y("error",`Stop failed: ${(g==null?void 0:g.error)||"Unknown error"}`)}catch(g){y("error",`Stop failed: ${g.message}`)}},[y,s]),re=n.useCallback(async()=>{if(t)try{const L=await s(t,"detect_ides",{});y("info",`Found ${((L==null?void 0:L.result)||[]).length} IDE(s)`)}catch(L){y("error",`Detection failed: ${L.message}`)}},[t,y,s]),V=n.useCallback(async()=>{if(t){u(!0);try{const L=await s(t,"get_recent_workspaces",{});L!=null&&L.success&&Array.isArray(L==null?void 0:L.result)&&T(L.result)}catch(L){y("error",`Failed: ${L.message}`)}finally{u(!1)}}},[t,y,s]),ee=n.useCallback(async L=>{if(!(!t||!L.trim())){l(!0);try{const g=await s(t,"workspace_add",{path:L.trim()});g!=null&&g.success?y("info",`Workspace added: ${L.trim()}`):y("error",(g==null?void 0:g.error)||"workspace_add failed")}catch(g){y("error",g.message)}finally{l(!1)}return!0}},[t,y,s]),O=n.useCallback(async L=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){l(!0);try{const g=await s(t,"workspace_remove",{id:L});g!=null&&g.success?y("info","Workspace removed"):y("error",(g==null?void 0:g.error)||"workspace_remove failed")}catch(g){y("error",g.message)}finally{l(!1)}}},[t,y,s]),ae=n.useCallback(async L=>{var g;if(t){l(!0);try{const D=await s(t,"workspace_set_default",L===null?{clear:!0}:{id:L});if(D!=null&&D.success){y("info",L?"Default workspace updated":"Default workspace cleared");const h=typeof D.defaultWorkspacePath=="string"?D.defaultWorkspacePath:"";h&&((g=$.current)==null||g.call($,h))}else y("error",(D==null?void 0:D.error)||"workspace_set_default failed")}catch(D){y("error",D.message)}finally{l(!1)}}},[t,y,s]),oe=n.useCallback(async L=>{var D;if(!t||!L.trim())return;const g=L.trim();l(!0);try{const h=await s(t,"workspace_set_default",{path:g});h!=null&&h.success?(y("info","Default workspace set from history"),(D=$.current)==null||D.call($,g)):y("error",(h==null?void 0:h.error)||"Could not set default (path missing on disk?)")}catch(h){y("error",h.message)}finally{l(!1)}},[t,y,s]),ue=n.useCallback(async()=>{var L;if(t){v(!0);try{const g=await s(t,"get_cli_history",{}),D=(g==null?void 0:g.history)??((L=g==null?void 0:g.result)==null?void 0:L.history);g!=null&&g.success&&Array.isArray(D)&&x(D)}catch{}v(!1)}},[t,s]),ie=n.useCallback(async()=>{if(t)try{await s(t,"set_machine_nickname",{nickname:E}),y("info",`Nickname set to "${E||"(cleared)"}"`),K(!1)}catch(L){y("error",`Failed: ${L.message}`)}},[t,E,y,s]);return{logs:r,launchingIde:c,loadingWorkspaces:p,workspaceBusy:m,loadingHistory:d,cliHistory:j,recentWorkspaces:I,launchPick:f,setLaunchPick:N,editingNickname:B,setEditingNickname:K,nicknameInput:E,setNicknameInput:A,addLog:y,handleLaunchIde:R,runLaunchCliCore:F,handleLaunchCli:H,handleStopCli:Z,handleRestartIde:b,handleStopIde:G,handleDetectIdes:re,handleLoadRecentWorkspaces:V,handleWorkspaceAdd:ee,handleWorkspaceRemove:O,handleWorkspaceSetDefault:ae,handleWorkspaceResumePath:oe,loadCliHistory:ue,handleSaveNickname:ie,setOnDefaultWorkspaceChanged:C}}function br({machine:t,managedIdes:s,managedClis:a,managedAcps:r,actions:i}){const{workspaceBusy:c,handleWorkspaceAdd:o,handleWorkspaceRemove:p,handleWorkspaceSetDefault:u}=i,[m,l]=n.useState(""),d=t.availableMem??t.freeMem,v=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-d)/t.totalMem*100))):0,j=t.loadavg[0]||0;return e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-5",children:[e.jsx(ut,{icon:e.jsx(tn,{size:16}),label:"Uptime",value:jn(t.uptime)}),e.jsx(ut,{icon:e.jsx(dt,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(ut,{icon:e.jsx(ps,{size:16}),label:"CLIs",value:`${a.length}`}),e.jsx(ut,{icon:e.jsx(hs,{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(Ut,{value:Math.min(Math.round(j/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${j.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Ut,{value:v,max:100,label:"Memory",color:"#3b82f6",detail:`${Yt(t.totalMem-d)} / ${Yt(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(At,{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:c,value:t.defaultWorkspaceId||"",onChange:x=>void u(x.target.value===""?null:x.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(x=>e.jsx("option",{value:x.id,children:x.label||x.path},x.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:m,disabled:c,onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&void(async()=>{await o(m)&&l("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:c,onClick:async()=>{await o(m)&&l("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1 max-h-32 overflow-y-auto",children:(t.workspaces||[]).map(x=>e.jsxs("li",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[x.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-mono truncate flex-1",title:x.path,children:x.path}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline",disabled:c,onClick:()=>void p(x.id),children:"Remove"})]},x.id))})]})]})}const yr={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 Et({category:t,machine:s,machineId:a,providers:r,managedEntries:i,getIcon:c,actions:o,sendDaemonCommand:p}){const u=lt(),{handleLaunchIde:m,handleLaunchCli:l,handleStopCli:d,handleRestartIde:v,handleStopIde:j,handleDetectIdes:x,cliHistory:I,loadingHistory:T,loadCliHistory:f,launchingIde:N}=o,B=yr[t],K=t==="ide",E=t==="acp",A=r.filter(h=>h.category===t),[$,C]=n.useState(""),[y,R]=n.useState(""),[F,H]=n.useState(""),[Z,b]=n.useState(s.defaultWorkspaceId||""),[G,re]=n.useState("");n.useEffect(()=>{!$&&A.length>0&&C(A[0].type)},[$,A.length]),n.useEffect(()=>{s.defaultWorkspaceId&&!Z&&b(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const V=(()=>{if(Z==="__custom__")return G.trim();if(!Z)return"";const h=(s.workspaces||[]).find(z=>z.id===Z);return(h==null?void 0:h.path)||""})(),[ee,O]=n.useState({}),[ae,oe]=n.useState(null);n.useEffect(()=>{if(!K||!a||!p)return;(async()=>{try{const z=await p(a,"get_ide_extensions",{}),Q=(z==null?void 0:z.result)||z;Q!=null&&Q.success&&(Q!=null&&Q.ides)&&O(Q.ides)}catch{}})()},[K,a,p]);const ue=h=>K?De(h.type):t==="cli"?h.cliName:h.acpName,ie=K?s.detectedIdes||[]:[],L=()=>{K?m($,V?{workspace:V}:void 0):l($,V,y||void 0,E&&F||void 0)},g=h=>{K?j(h):d(h.type,h.workspace,h.id)},D=e.jsxs("div",{className:"flex gap-2 items-center flex-wrap mb-3",children:[e.jsx("select",{value:Z,onChange:h=>{b(h.target.value),h.target.value!=="__custom__"&&re("")},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(h=>e.jsxs("option",{value:h.id,children:[h.id===s.defaultWorkspaceId?"⭐ ":"",h.label||h.path.split("/").filter(Boolean).pop()||h.path," — ",h.path]},h.id)),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]})}),Z==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:G,onChange:h=>re(h.target.value),className:"machine-input flex-1 min-w-[200px]",autoFocus:!0})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${B.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",B.label]}),D,K?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ie.map(h=>{const z=h.running||i.some(Q=>(Q.type||"").toLowerCase()===(h.type||"").toLowerCase());return e.jsxs("button",{onClick:()=>m(h.type||h.id||"",V?{workspace:V}:void 0),disabled:!!N,className:`machine-btn-primary flex items-center gap-1.5 ${z?"!border-green-500/30":""}`,style:{opacity:N&&N!==h.type?.4:1},children:[e.jsx("span",{children:c(h.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)]"}),N===h.type?"⏳ Launching...":`▶ ${h.name||De(h.type)}`,z&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"+ window"})]},h.type)}),ie.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:x,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(Zs,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:$,onChange:h=>C(h.target.value),className:"machine-input",children:A.length>0?A.map(h=>e.jsxs("option",{value:h.type,children:[h.icon," ",h.displayName]},h.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),E&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:F,onChange:h=>H(h.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:y,onChange:h=>R(h.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:L,className:"machine-btn-primary",children:"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length,")"]}),i.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 ",B.plural," running"]}):e.jsx("div",{className:"flex flex-col gap-2.5 mb-5",children:i.map(h=>{const z=K?h:null,Q=E?h:null;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:c(h.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ue(h),(z==null?void 0:z.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",z.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:h.workspace||"—"}),(Q==null?void 0:Q.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",Q.currentModel]}),(Q==null?void 0:Q.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",Q.currentPlan]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${h.status==="stopped"?"bg-red-500/[0.08] text-red-500":h.status==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:h.status}),K&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>u(`/ide/${h.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(dt,{size:13})," Control"]}),e.jsx("button",{onClick:()=>v(h),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),E&&e.jsx("button",{onClick:()=>u(`/ide/${h.id}`),className:"machine-btn",title:"View chat",children:e.jsx(bt,{size:14})}),h.status==="stopped"?e.jsx("button",{onClick:()=>K?m(h.type,h.workspace?{workspace:h.workspace}:void 0):l(h.type,h.workspace),className:"machine-btn text-green-500 border-green-500/30",children:"▶"}):e.jsx("button",{onClick:()=>g(h),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),z&&z.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:z.aiAgents.map(xe=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${xe.status==="generating"||xe.status==="streaming"?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[xe.name," · ",xe.status]},xe.id))}),z&&(ee[z.type]||[]).length>0&&p&&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:(ee[z.type]||[]).map(xe=>e.jsxs("button",{disabled:ae===`${z.type}.${xe.type}`,onClick:async()=>{const ge=`${z.type}.${xe.type}`;oe(ge);try{await p(a,"set_ide_extension",{ideType:z.type,extensionType:xe.type,enabled:!xe.enabled}),O(he=>({...he,[z.type]:(he[z.type]||[]).map(ke=>ke.type===xe.type?{...ke,enabled:!ke.enabled}:ke)}))}catch(he){console.error("Extension toggle failed:",he)}finally{oe(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 ${xe.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 ${xe.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),xe.name,e.jsx("span",{className:"text-[9px] font-normal",children:xe.enabled?"ON":"OFF"})]},xe.type))})]})]},h.id)})}),!K&&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:f,disabled:T,className:"machine-btn",children:T?"⏳":"↻ Load"})]}),(()=>{const h=new Set(A.map(Q=>Q.type)),z=I.filter(Q=>h.has(Q.cliType));return z.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:z.map((Q,xe)=>{var ge,he;return e.jsxs("div",{onClick:()=>{C(Q.cliType),b("__custom__"),re(Q.dir),R((Q.cliArgs||[]).join(" "))},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:c(Q.cliType)}),e.jsx("span",{children:((ge=Q.dir)==null?void 0:ge.split("/").filter(Boolean).pop())||"root"}),((he=Q.cliArgs)==null?void 0:he.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:Q.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:Q.timestamp?new Date(Q.timestamp).toLocaleDateString():""})]},xe)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",B.label," launch history yet."]})})()]})]})}const ss=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],jr=[{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 vr({machineId:t,provider:s,sendDaemonCommand:a,onClose:r}){const[i,c]=n.useState("config"),[o,p]=n.useState("codex-cli"),[u,m]=n.useState([]),[l,d]=n.useState(""),[v,j]=n.useState([]),[x,I]=n.useState(""),T=n.useRef(null),f=n.useRef(null),N=C=>{m(y=>y.includes(C)?y.filter(R=>R!==C):[...y,C])},B=()=>m([...ss]),K=()=>m([]);n.useEffect(()=>{var C;(C=T.current)==null||C.scrollIntoView({behavior:"smooth"})},[v]),n.useEffect(()=>()=>{f.current&&clearInterval(f.current)},[]);const E=n.useCallback(()=>{f.current&&clearInterval(f.current),f.current=setInterval(async()=>{try{const C=await a(t,"provider_auto_fix_status",{providerType:s.type});(C==null?void 0:C.running)===!1&&i==="running"&&(c("done"),j(y=>[...y,`
|
|
70
70
|
✅ Auto-fix completed!`]),f.current&&clearInterval(f.current))}catch{}},3e3)},[t,s.type,a,i]),A=async()=>{if(u.length!==0){c("running"),j(["🚀 Starting auto-fix...",`Agent: ${o}`,`Scripts: ${u.join(", ")}`,l?`💬 Comment: ${l}`:"",""]),I("");try{const C=await a(t,"provider_auto_fix",{providerType:s.type,functions:u,agent:o,...l?{comment:l}:{}});C!=null&&C.success&&(C!=null&&C.started||C!=null&&C.running)?(j(y=>[...y,"✅ Agent started. Monitoring progress..."]),E()):(c("error"),I((C==null?void 0:C.error)||"Failed to start auto-fix"))}catch(C){c("error"),I((C==null?void 0:C.message)||"Connection failed")}}},$=async()=>{try{await a(t,"provider_auto_fix_cancel",{providerType:s.type}),j(C=>[...C,`
|
|
71
|
-
⚠️ Auto-fix cancelled.`]),c("done"),f.current&&clearInterval(f.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:C=>C.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:s.icon||"🔧"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-text-primary",children:["Auto-Fix: ",s.displayName]}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"AI agent will implement provider scripts"})]})]}),e.jsx("button",{onClick:r,className:"text-text-muted hover:text-text-primary text-lg leading-none",children:"×"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[i==="config"&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"AI Agent"}),e.jsx("div",{className:"flex gap-2",children:jr.map(C=>e.jsxs("button",{onClick:()=>p(C.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:o===C.value?C.color+"66":"var(--border-subtle)",background:o===C.value?C.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:o===C.value?C.color:"var(--text-primary)"},children:C.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:C.desc})]},C.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:B,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:K,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:ss.map(C=>e.jsxs("button",{onClick:()=>N(C),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:u.includes(C)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:u.includes(C)?"rgba(139,92,246,0.08)":"transparent",color:u.includes(C)?"#a78bfa":"var(--text-secondary)"},children:[u.includes(C)?"☑ ":"☐ ",C]},C))})]}),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:l,onChange:C=>d(C.target.value),placeholder:"e.g. Shadow DOM 안의 버튼도 탐색해줘, readChat에서 코드블럭 포맷 유지해...",rows:2,className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] resize-none placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]})]}),(i==="running"||i==="done"||i==="error")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Agent Output"}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-[#0d0d0d] p-3 font-mono text-[11px] leading-relaxed text-text-secondary overflow-y-auto",style:{maxHeight:320,minHeight:200},children:[v.map((C,y)=>e.jsx("div",{className:C.startsWith("✅")?"text-green-400":C.startsWith("❌")||C.startsWith("⚠")?"text-amber-400":"",children:C},y)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:T})]}),x&&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:x})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-between items-center",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[i==="config"&&u.length>0&&`${u.length} script(s) selected`,i==="running"&&"Agent is working...",i==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[i==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:A,disabled:u.length===0,className:"machine-btn",style:{background:u.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:u.length>0?"rgba(139,92,246,0.4)":void 0,color:u.length>0?"#a78bfa":void 0,opacity:u.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:$,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(i==="done"||i==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{c("config"),j([]),I("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function wr({machineId:t,providers:s,sendDaemonCommand:a,onClose:r,onCreated:i}){var E;const c=s.filter(A=>A.category==="ide"),[o,p]=n.useState(((E=c[0])==null?void 0:E.type)||""),[u,m]=n.useState(""),[l,d]=n.useState(""),[v,j]=n.useState(!1),[x,I]=n.useState(""),[T,f]=n.useState(!1),N=A=>{const $=A.toLowerCase().replace(/[^a-z0-9-]/g,"");m($),(!l||l===B(u))&&d(B($))},B=A=>A.split("-").map($=>$.charAt(0).toUpperCase()+$.slice(1)).join(" "),K=async()=>{if(!(!u||!l||!o)){j(!0),I("");try{const A=await a(t,"provider_clone",{type:u,name:l,category:"ide",location:"user",cloneFrom:o});A!=null&&A.success||A!=null&&A.created?(f(!0),i==null||i(u)):I((A==null?void 0:A.error)||"Failed to create provider")}catch(A){I((A==null?void 0:A.message)||"Connection failed")}j(!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:A=>A.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:T?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:u})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",u,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",u]})," 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:c.map(A=>e.jsxs("button",{onClick:()=>p(A.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:o===A.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:o===A.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:A.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:o===A.type?"#a78bfa":"var(--text-secondary)"},children:A.displayName})]},A.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:u,onChange:A=>N(A.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/",u||"...","/"]})]})]}),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:l,onChange:A=>d(A.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"})]}),x&&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:x})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:T?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:K,disabled:!u||!l||v,className:"machine-btn",style:{background:u&&l?"rgba(34,197,94,0.12)":void 0,borderColor:u&&l?"rgba(34,197,94,0.3)":void 0,color:u&&l?"#86efac":void 0,opacity:!u||!l||v?.4:1},children:v?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function Nr({machineId:t,providers:s,sendDaemonCommand:a}){const[r,i]=n.useState([]),[c,o]=n.useState(!1),[p,u]=n.useState(null),[m,l]=n.useState("all"),[d,v]=n.useState(null),[j,x]=n.useState(!1),I=n.useCallback(async()=>{var f;if(t){o(!0);try{const N=await a(t,"get_provider_settings",{}),B=(N==null?void 0:N.result)||N;if(N!=null&&N.success&&(B!=null&&B.settings)){const K=[];for(const[E,A]of Object.entries(B.settings)){const $=s.find(C=>C.type===E);K.push({type:E,displayName:($==null?void 0:$.displayName)||E,icon:($==null?void 0:$.icon)||"",category:($==null?void 0:$.category)||"unknown",schema:A,values:((f=B.values)==null?void 0:f[E])||{}})}K.sort((E,A)=>E.category.localeCompare(A.category)||E.displayName.localeCompare(A.displayName)),i(K)}}catch{}o(!1)}},[t,s,a]);n.useEffect(()=>{r.length===0&&I()},[]);const T=async(f,N,B)=>{u(`${f}.${N}`),i(K=>K.map(E=>E.type===f?{...E,values:{...E.values,[N]:B}}:E));try{const K=await a(t,"set_provider_setting",{providerType:f,key:N,value:B});K!=null&&K.success||I()}catch{I()}u(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(f=>e.jsx("button",{onClick:()=>l(f),className:`machine-btn text-[10px] px-2 py-0.5 ${m===f?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:f.toUpperCase()},f))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>x(!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:I,disabled:c,className:"machine-btn",children:c?"⏳ Loading...":"↻ Refresh"})]})]}),m!=="all"&&r.filter(f=>f.category===m).length>1&&(()=>{const f=r.filter(E=>E.category===m),N=new Map;for(const E of f)for(const A of E.schema){if(A.type!=="boolean")continue;const $=N.get(A.key),C=!!(E.values[A.key]??A.default);$?($.onCount+=C?1:0,$.total+=1):N.set(A.key,{label:A.label||A.key,onCount:C?1:0,total:1})}const B=[...N.entries()].filter(([,E])=>E.total===f.length);if(B.length===0)return null;const K=async(E,A)=>{for(const $ of f)await T($.type,E,A)};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 ",m.toUpperCase()," providers (",f.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:B.map(([E,A])=>{const $=A.onCount===A.total,C=A.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:A.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",A.onCount,"/",A.total,")"]}),e.jsx("button",{onClick:()=>void K(E,!0),disabled:$,className:`machine-btn text-[9px] px-1.5 py-px ${$?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void K(E,!1),disabled:C,className:`machine-btn text-[9px] px-1.5 py-px ${C?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},E)})})]})})(),c&&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(f=>m==="all"||f.category===m).map(f=>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:f.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:f.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:f.category==="acp"?"rgba(139,92,246,0.08)":f.category==="cli"?"rgba(59,130,246,0.08)":f.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:f.category==="acp"?"#a78bfa":f.category==="cli"?"#60a5fa":f.category==="ide"?"#86efac":"#fbbf24"},children:f.category}),f.category==="ide"&&e.jsx("button",{onClick:()=>v(s.find(N=>N.type===f.type)||{type:f.type,displayName:f.displayName,icon:f.icon,category:f.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:f.schema.map(N=>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:[N.label||N.key,p===`${f.type}.${N.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),N.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:N.description})]}),e.jsx("div",{className:"shrink-0",children:N.type==="boolean"?e.jsx("button",{onClick:()=>T(f.type,N.key,!(f.values[N.key]??N.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:f.values[N.key]??N.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:f.values[N.key]??N.default?21:3}})}):N.type==="number"?e.jsx("input",{type:"number",value:f.values[N.key]??N.default??0,min:N.min,max:N.max,onChange:B=>{const K=parseInt(B.target.value)||0;N.min!==void 0&&K<N.min||N.max!==void 0&&K>N.max||T(f.type,N.key,K)},className:"machine-input w-20 text-center text-[11px]"}):N.type==="select"&&N.options?e.jsx("select",{value:f.values[N.key]??N.default??"",onChange:B=>T(f.type,N.key,B.target.value),className:"machine-input text-[11px]",children:N.options.map(B=>e.jsx("option",{value:B,children:B},B))}):e.jsx("input",{type:"text",value:f.values[N.key]??N.default??"",onBlur:B=>T(f.type,N.key,B.target.value),className:"machine-input w-[120px] text-[11px]"})})]},N.key))})]},f.type))}),d&&e.jsx(vr,{machineId:t,provider:d,sendDaemonCommand:a,onClose:()=>v(null)}),j&&e.jsx(wr,{machineId:t,providers:s,sendDaemonCommand:a,onClose:()=>x(!1),onCreated:()=>{x(!1),I()}})]})}function kr({machineId:t,sendDaemonCommand:s}){const[a,r]=n.useState([]),[i,c]=n.useState(0),[o,p]=n.useState(!0),[u,m]=n.useState("debug"),l=n.useRef(null),d=n.useRef(!1);return n.useEffect(()=>{if(!t||!o)return;const v=async()=>{try{const x=await s(t,"get_logs",{count:200,minLevel:u,since:i}),I=(x==null?void 0:x.result)||x;if(x!=null&&x.success&&Array.isArray(I==null?void 0:I.logs)&&I.logs.length>0){r(f=>[...f,...I.logs.map(B=>({timestamp:B.ts,level:B.level,message:`[${B.category}] ${B.message}`}))].slice(-300));const T=Math.max(...I.logs.map(f=>f.ts));c(T)}}catch{}};v();const j=setInterval(v,3e3);return()=>clearInterval(j)},[t,o,i,u,s]),n.useEffect(()=>{if(o&&a.length>0){const v=d.current?"smooth":"instant";setTimeout(()=>{var j;(j=l.current)==null||j.scrollIntoView({behavior:v}),d.current=!0},50)}},[a.length,o]),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(v=>e.jsx("button",{onClick:()=>{m(v),r([]),c(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${u===v?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:v.toUpperCase()},v))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[a.length," entries"]}),e.jsx("button",{onClick:()=>p(!o),className:`machine-btn ${o?"text-green-500 border-green-500/30":""}`,children:o?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),c(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:[a.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),a.map((v,j)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:v.level==="error"?"#ef4444":v.level==="warn"?"#f59e0b":v.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(v.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:v.level==="error"?"#ef4444":v.level==="warn"?"#f59e0b":v.level==="debug"?"#475569":"#8b5cf6"},children:v.level==="error"?"ERR":v.level==="warn"?"WRN":v.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:v.message})]},j)),e.jsx("div",{ref:l})]})]})}function Sr({machine:t,launchPick:s,actions:a}){const{runLaunchCliCore:r,setLaunchPick:i}=a;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(c=>e.jsxs("button",{type:"button",className:"text-left text-xs px-3 py-2 rounded-lg border border-border-subtle bg-bg-primary hover:bg-violet-500/10 transition-colors",onClick:()=>{i(null),r({cliType:s.cliType,workspaceId:c.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:c.label||c.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:c.path})]},c.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",disabled:!t.defaultWorkspacePath,onClick:()=>{i(null),r({cliType:s.cliType,useDefaultWorkspace:!0,argsStr:s.argsStr,model:s.model})},children:"Default workspace"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",onClick:()=>{i(null),r({cliType:s.cliType,useHome:!0,argsStr:s.argsStr,model:s.model})},children:"Home directory"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[80px]",onClick:()=>i(null),children:"Cancel"})]})]})})}function Cr(){var K,E,A,$,C,y,R,F,H,Z;const{id:t}=is(),s=lt(),{sendCommand:a}=Ye(),r=jt(),i=r.ides||[],c=r.initialLoaded??!0,[o,p]=n.useState("overview"),u=n.useRef(null),m=gr({machineId:t,sendDaemonCommand:a,logsEndRef:u}),l=i.find(b=>b.id===t&&b.daemonMode),d=((l==null?void 0:l.availableProviders)||[]).map(b=>({type:b.type,displayName:b.displayName,icon:b.icon,category:b.category})),v={};for(const b of d)v[b.type]=b.icon;const j=b=>v[b]||"",x=l?{id:l.id,hostname:((K=l.machine)==null?void 0:K.hostname)||l.id,platform:((E=l.machine)==null?void 0:E.platform)||"unknown",arch:((A=l.machine)==null?void 0:A.arch)||"",cpus:(($=l.machine)==null?void 0:$.cpus)||0,totalMem:((C=l.machine)==null?void 0:C.totalMem)||0,freeMem:((y=l.machine)==null?void 0:y.freeMem)||0,availableMem:(R=l.machine)==null?void 0:R.availableMem,loadavg:((F=l.machine)==null?void 0:F.loadavg)||[],uptime:((H=l.machine)==null?void 0:H.uptime)||0,release:((Z=l.machine)==null?void 0:Z.release)||"",cdpConnected:!!(l.ides||[]).some(b=>b.cdpConnected),machineNickname:l.machineNickname||null,p2p:l.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:l.detectedIdes||[],managedIdeIds:l.managedIdeIds||[],managedCliIds:l.managedCliIds||[],workspaces:l.workspaces||[],defaultWorkspaceId:l.defaultWorkspaceId??l.activeWorkspaceId??null,defaultWorkspacePath:l.defaultWorkspacePath??l.activeWorkspacePath??null,workspaceActivity:l.workspaceActivity||[]}:null,I=i.filter(b=>b.daemonId===t&&!b.daemonMode).filter(b=>!Gt(b)&&!Xt(b)).map(b=>({id:b.id,type:b.type,version:b.version||"",instanceId:b.instanceId||"",status:b.status,workspace:b.workspace||null,terminals:b.terminals||0,aiAgents:vn(b.aiAgents||b.agents||[]),activeChat:b.activeChat||null,chats:b.chats||[],agentStreams:b.agentStreams||[],cdpConnected:b.cdpConnected||!1,daemonId:t})),T=i.filter(b=>b.daemonId===t&&Gt(b)).map(b=>({id:b.id,type:b.type,cliName:b.cliName||b.type,status:b.status,workspace:b.workspace||"",activeChat:b.activeChat||null,daemonId:t})),f=i.filter(b=>b.daemonId===t&&Xt(b)).map(b=>({id:b.id,type:b.type,acpName:b.cliName||b.type,status:b.status,workspace:b.workspace||"",activeChat:b.activeChat||null,currentModel:b.currentModel,currentPlan:b.currentPlan,daemonId:t}));if(!x)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:()=>s("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const N=x.machineNickname||x.hostname,B=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(sn,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(dt,{size:14})," IDEs"]}),count:I.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ms,{size:14})," CLIs"]}),count:T.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(hs,{size:14})," ACP Agents"]}),count:f.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(us,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Vs,{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:()=>s("/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:[m.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:m.nicknameInput,onChange:b=>m.setNicknameInput(b.target.value),onKeyDown:b=>{b.key==="Enter"&&m.handleSaveNickname(),b.key==="Escape"&&m.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:m.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>m.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{m.setEditingNickname(!0),m.setNicknameInput(x.machineNickname||"")},title:"Click to set nickname",children:N}),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:[x.platform," · ",x.arch," · ",x.cpus," cores"]}),(l==null?void 0:l.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",l.version]}),(l==null?void 0:l.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 a(t,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",l.serverVersion]}),x.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:x.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:x.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",x.p2p.state==="connected"?`● ${x.p2p.peers}`:"○"]}),x.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 ●"}),x.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",x.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:B.map(b=>e.jsxs("button",{onClick:()=>p(b.id),className:`machine-tab shrink-0${o===b.id?" active":""}`,children:[b.label,b.count!==void 0&&e.jsx("span",{className:"tab-count",children:b.count})]},b.id))})]}),e.jsxs("div",{className:"page-content",children:[o==="overview"&&e.jsx(br,{machine:x,managedIdes:I,managedClis:T,managedAcps:f,actions:m}),o==="ides"&&e.jsx(Et,{category:"ide",machine:x,machineId:t,providers:d,managedEntries:I,getIcon:j,actions:m,sendDaemonCommand:a}),o==="clis"&&e.jsx(Et,{category:"cli",machine:x,machineId:t,providers:d,managedEntries:T,getIcon:j,actions:m}),o==="acps"&&e.jsx(Et,{category:"acp",machine:x,machineId:t,providers:d,managedEntries:f,getIcon:j,actions:m}),o==="providers"&&e.jsx(Nr,{machineId:t,providers:d,sendDaemonCommand:a}),o==="logs"&&e.jsx(kr,{machineId:t,sendDaemonCommand:a})]}),m.launchPick&&x&&e.jsx(Sr,{machine:x,launchPick:m.launchPick,actions:m})]})}function Ir(){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 ns=Ir(),rs=3e3,Mr=3e4;let Fe=null,Tr=0;const yt=new Map,Bt=new Set;let Xe=null,Er=null,at=null;async function gt(t,s,a){const r=Fe;if(r&&r.readyState===WebSocket.OPEN){const c=`req_${++Tr}_${Date.now()}`;return new Promise((o,p)=>{const u=setTimeout(()=>{yt.delete(c),p(new Error(`WS command timeout: ${s}`))},3e4);yt.set(c,{resolve:m=>{clearTimeout(u),o(m)},reject:m=>{clearTimeout(u),p(m)}}),r.send(JSON.stringify({type:"command",requestId:c,data:{type:s,payload:a||{},target:t}}))})}const i=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:a||{},target:t})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}class $r{constructor(s){Ae(this,"daemonId");Ae(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Fe==null?void 0:Fe.readyState)===WebSocket.OPEN}get connectionState(){return(Fe==null?void 0:Fe.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,a){return gt(this.daemonId,s,a)}async sendInput(s,a){const r=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId;return gt(r,"cdp_remote_action",{action:s,params:a})}startScreenshots(s){this.screenshotIdeType=s||null,Xe&&(clearInterval(Xe),Xe=null);const a=async()=>{if(this.hasCommandChannel)try{const r=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId,i=await gt(r,"screenshot",{width:1280});if(i!=null&&i.success&&(i!=null&&i.base64)){const c=await fetch(`data:image/jpeg;base64,${i.base64}`).then(o=>o.blob());Bt.forEach(o=>o(this.daemonId,c))}}catch{}};a(),Xe=setInterval(a,2e3)}stopScreenshots(s){Xe&&(clearInterval(Xe),Xe=null)}}let Ve=null;function Ar(t){(!Ve||Ve.daemonId!==t)&&(Ve=new $r(t));const s=Re._originalGet||Re.get.bind(Re);Re._originalGet=s,Re.get=a=>a===t||a.startsWith("standalone")?Ve:s(a),Re.getState=a=>(a===t||a.startsWith("standalone"))&&(Ve==null?void 0:Ve.connectionState)||"disconnected",Re.onScreenshot=(a,r)=>(Bt.add(r),()=>{Bt.delete(r)})}function _r({children:t}){const s=n.useRef(Ht()),a=Ht();s.current=a;const{setUserName:r}=ot(),i=n.useRef(r);i.current=r;const[,c]=n.useState("disconnected"),o=n.useCallback((d,v)=>{c(d),at==null||at(d,v)},[]),p=n.useRef(null),u=n.useRef(),m=n.useRef(rs),l=n.useRef(!0);return n.useEffect(()=>{l.current=!0;function d(){var x,I;if(!l.current||((x=p.current)==null?void 0:x.readyState)===WebSocket.OPEN||((I=p.current)==null?void 0:I.readyState)===WebSocket.CONNECTING)return;o("connecting"),console.log(`[Standalone WS] Connecting to ${ns}...`);let j;try{j=new WebSocket(ns)}catch(T){console.error("[Standalone WS] Failed to create WebSocket:",T),v();return}p.current=j,j.onopen=()=>{if(!l.current){j.close();return}o("connected"),m.current=rs,console.log("[Standalone WS] Connected")},Fe=j,j.onmessage=T=>{var f;try{const N=JSON.parse(T.data);if((N.type==="command_result"||N.type==="error")&&N.requestId){const B=yt.get(N.requestId);B&&(yt.delete(N.requestId),N.type==="error"?B.reject(new Error(((f=N.data)==null?void 0:f.message)||"Command failed")):B.resolve(N.data));return}if(N.type==="status"||N.type==="initial_state"){const B=N.data;if(!B)return;const{injectEntries:K,markLoaded:E}=s.current,A=B.id||"standalone";Er=A,Ar(A),o("connected",A);const $=In(B,{daemonId:A});$.length>0&&K($),E(),B.userName&&i.current&&i.current(B.userName)}}catch(N){console.error("[Standalone WS] Parse error:",N)}},j.onclose=()=>{l.current&&(o("disconnected"),p.current=null,v())},j.onerror=T=>{console.warn("[Standalone WS] Error, will reconnect:",T)}}function v(){if(!l.current)return;clearTimeout(u.current);const j=m.current;console.log(`[Standalone WS] Reconnecting in ${j}ms...`),u.current=setTimeout(()=>{m.current=Math.min(m.current*1.5,Mr),d()},j)}return d(),()=>{l.current=!1,clearTimeout(u.current),p.current&&(p.current.onclose=null,p.current.close(),p.current=null,Fe=null)}},[]),e.jsx(e.Fragment,{children:t})}function Rr({children:t}){const[s,a]=n.useState("disconnected"),[r,i]=n.useState(null);n.useEffect(()=>(at=(o,p)=>{a(o),p&&i(p)},()=>{at=null}),[]);const c=n.useMemo(()=>{const o=s==="connected",p={};return r&&(p[r]=o?"connected":"connecting"),p.standalone=o?"connected":"connecting",{wsStatus:s,isConnected:o,connectionStates:p}},[s,r]);return e.jsx(Fs,{connectionOverrides:c,children:e.jsx(_r,{children:t})})}const Pr=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Gs,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Xs,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(us,{}),label:"Settings"}];function Lr({children:t}){const s=lt(),a=Rs(),[r,i]=n.useState(!1),[c,o]=n.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),p=l=>{s(l),i(!1)},u=()=>{o(l=>{const d=!l;try{localStorage.setItem("sidebar-collapsed",d?"1":"0")}catch{}return d})},m=l=>`nav-item${a.pathname.startsWith(l)?" active":""} cursor-pointer ${c?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${c?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:l=>l.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${c?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!c&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Pr.map(l=>e.jsxs("div",{className:m(l.path),id:`nav-${l.id}`,onClick:()=>p(l.path),title:c?l.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:l.icon}),!c&&l.label]},l.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer${a.pathname==="/about"?" active":""} ${c?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:c?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(qs,{})}),!c&&"About"]}),!c&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.6.37"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${c?"justify-center py-2.5 px-0":"mt-1"}`,onClick:u,title:c?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:c?"›":"‹"}),!c&&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 Dr=[{icon:"🏠",title:"Local-first",desc:"Everything runs on your machine. No data leaves your network. Full privacy by design."},{icon:"💬",title:"Agent chat relay",desc:"Read and respond to AI conversations in real-time across all connected IDEs."},{icon:"📸",title:"Live screenshots",desc:"View your IDE screens directly in the browser via local WebSocket streaming."},{icon:"🎛️",title:"Remote control",desc:"Click, type, and interact with your IDE from the dashboard — no window switching."},{icon:"🔌",title:"Multi-IDE support",desc:"Monitor and control multiple IDEs simultaneously — VS Code, Cursor, Windsurf, and more."},{icon:"⚡",title:"Extension agents",desc:"Manage extension-based agents like Cline and Roo Code alongside native IDE agents."}],Br=[{icon:"🌍",title:"Access from anywhere",desc:"Control your agents from any device, any network. No VPN or port forwarding needed."},{icon:"🔗",title:"WebRTC P2P streaming",desc:"End-to-end encrypted peer-to-peer connection for zero-latency remote screenshots and control."},{icon:"📱",title:"Mobile notifications",desc:"Get push notifications when agents need approval. Quick approve/reject from your phone."},{icon:"📡",title:"REST API access",desc:"Integrate with Slack, CI/CD pipelines, or custom tools. Scoped API keys with granular permissions."},{icon:"👥",title:"Team dashboard",desc:"Share a unified view across your team. See who's running what, where, in real time."},{icon:"🔐",title:"Enterprise security",desc:"SSO, RBAC, audit logs, and SLA guarantees for production teams."}],Wr=[{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 agent support",selfhost:!0,cloud:!0},{feature:"CLI agent support",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 & 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}],$t={ides:["VS Code","Cursor","Antigravity","Windsurf","Trae","PearAI","Kiro","VSCodium","VS Code Insiders"],agents:["GitHub Copilot","Cline","Roo Code"],cli:["Gemini CLI","Claude Code","Codex CLI"]};function Or(){return e.jsxs("div",{className:"py-8 px-6 max-w-[860px] mx-auto text-text-primary",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-14 h-14 mb-3 mx-auto"}),e.jsx("h1",{className:"text-[26px] font-extrabold mb-1.5 text-text-primary",children:"ADHDev"}),e.jsx("p",{className:"text-[13px] text-text-muted",children:"Agent Dashboard Hub for Dev — Self-hosted Edition"}),e.jsxs("div",{className:"inline-block mt-3 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.6.37"]})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"✅"})," What's included"]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(250px,1fr))] gap-3",children:Dr.map(t=>e.jsxs("div",{className:"bg-bg-glass border border-border-subtle rounded-xl px-4 py-4 transition-colors hover:border-border-default",children:[e.jsx("div",{className:"text-xl mb-1.5",children:t.icon}),e.jsx("div",{className:"font-semibold text-[13px] mb-1",children:t.title}),e.jsx("div",{className:"text-[12px] text-text-muted leading-relaxed",children:t.desc})]},t.title))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsx("h2",{className:"text-lg font-bold mb-4",children:"Compatible with"}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-5",children:[{label:"IDEs",items:$t.ides},{label:"Extension agents",items:$t.agents},{label:"CLI agents",items:$t.cli}].map(t=>e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-2 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1",children:t.items.map(s=>e.jsx("div",{className:"text-[12px] px-2.5 py-1.5 bg-bg-glass rounded-md border border-border-subtle",children:s},s))})]},t.label))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"⚖️"})," Self-hosted vs Cloud"]}),e.jsx("div",{className:"rounded-xl border border-border-subtle overflow-hidden",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-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[100px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-[11px] uppercase tracking-wider w-[100px] text-violet-500",children:"Cloud"})]})}),e.jsx("tbody",{children:Wr.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"",children:[e.jsx("td",{className:"px-4 py-2 text-text-secondary",children:t.feature}),e.jsx("td",{className:"text-center px-4 py-2",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:"text-center px-4 py-2",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})]}),e.jsx("section",{className:"mb-10",children:e.jsx("div",{className:"rounded-2xl border border-violet-500/20 bg-violet-500/[0.04] px-6 py-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"text-3xl shrink-0",children:"🚀"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-bold text-[15px] mb-1.5",children:"Unlock more with ADHDev Cloud"}),e.jsx("p",{className:"text-[13px] text-text-muted leading-relaxed mb-4",children:"Access your agents from anywhere — your phone, another laptop, or a coffee shop. Cloud adds WebRTC P2P streaming, mobile push notifications, REST API, team collaboration, and multi-machine support. Your local setup stays exactly the same."}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-2.5 mb-5",children:Br.map(t=>e.jsxs("div",{className:"flex gap-2.5 items-start",children:[e.jsx("span",{className:"text-base shrink-0 mt-0.5",children:t.icon}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[12px]",children:t.title}),e.jsx("div",{className:"text-[11px] text-text-muted leading-snug",children:t.desc})]})]},t.title))}),e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Try ADHDev Cloud →"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"GitHub"}),e.jsx("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Discord"})]})]})]})})}),e.jsxs("div",{className:"text-center text-xs text-text-muted pt-4 border-t border-border-subtle",children:[e.jsx("p",{children:"© 2026 RacoLab · ADHDev, Your AI sidekick otter 🦦"}),e.jsx("p",{className:"mt-1 opacity-60",children:"Self-hosted edition — all data stays on your machine"})]})]})}function Kr(){const{ides:t}=ot(),s=t.find(d=>d.type==="adhdev-daemon"),a=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=Ye(),{userName:i}=ot(),[c,o]=n.useState(i||"");n.useEffect(()=>{i!==void 0&&o(i)},[i]);const p=d=>{const v=d.target.value.trim();s!=null&&s.id&&v!==i&&r(s.id,"set_user_name",{userName:v}).catch(console.error)},[u,m]=n.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),l=d=>{m(d);try{localStorage.setItem("adhdev_sound",d?"1":"0")}catch{}};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Bn,{icon:"⚙️",title:"Settings",subtitle:"Local daemon configuration & preferences"}),e.jsxs("div",{className:"page-content",children:[e.jsx(Ze,{title:"Daemon",className:"mb-4",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.6.37"]}),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(Ze,{title:"Detected IDEs",className:"mb-4",children:a.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:a.map(d=>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 ${d.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:d.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:d.type})]},d.type))})}),e.jsx(Ze,{title:"Machine",className:"mb-4",children:e.jsx(Yn,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(Ze,{title:"Theme",className:"mb-4",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:"Site theme"}),e.jsx(Jn,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Chat theme"}),e.jsx(nr,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Accent color"}),e.jsx(lr,{})]})]})}),e.jsx(Ze,{title:"Notifications",className:"mb-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Un,{}),e.jsx(Qe,{label:"🔊 Sound Effects",description:"Play a sound when agent completes or needs approval",checked:u,onChange:l})]})}),e.jsx(Ze,{title:"Preferences",className:"mb-4",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.jsx("span",{className:"text-sm font-semibold flex items-center gap-2",children:"👤 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:c,onChange:d=>o(d.target.value),onBlur:p,onKeyDown:d=>{d.key==="Enter"&&d.currentTarget.blur()}})]})})})]})]})}tr();function as(){const{ides:t}=ot(),s=t.find(a=>{var r;return a.daemonMode||((r=a.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(mt,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(mt,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(mt,{to:"/dashboard",replace:!0})}function Fr(){return e.jsx(Ps,{children:e.jsx(Rr,{children:e.jsx(Ys,{value:{sendCommand:gt,sendData:()=>!1},children:e.jsx(Lr,{children:e.jsxs(Ls,{children:[e.jsx(ze,{path:"/dashboard",element:e.jsx(pr,{})}),e.jsx(ze,{path:"/ide/:id",element:e.jsx(fr,{})}),e.jsx(ze,{path:"/machine",element:e.jsx(as,{})}),e.jsx(ze,{path:"/machines/:id",element:e.jsx(Cr,{})}),e.jsx(ze,{path:"/machines",element:e.jsx(as,{})}),e.jsx(ze,{path:"/about",element:e.jsx(Or,{})}),e.jsx(ze,{path:"/settings",element:e.jsx(Kr,{})}),e.jsx(ze,{path:"*",element:e.jsx(mt,{to:"/dashboard",replace:!0})})]})})})})})}Ds(document.getElementById("root")).render(e.jsx(n.StrictMode,{children:e.jsx(Fr,{})}));
|
|
71
|
+
⚠️ Auto-fix cancelled.`]),c("done"),f.current&&clearInterval(f.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:C=>C.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:s.icon||"🔧"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-text-primary",children:["Auto-Fix: ",s.displayName]}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"AI agent will implement provider scripts"})]})]}),e.jsx("button",{onClick:r,className:"text-text-muted hover:text-text-primary text-lg leading-none",children:"×"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[i==="config"&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"AI Agent"}),e.jsx("div",{className:"flex gap-2",children:jr.map(C=>e.jsxs("button",{onClick:()=>p(C.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:o===C.value?C.color+"66":"var(--border-subtle)",background:o===C.value?C.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:o===C.value?C.color:"var(--text-primary)"},children:C.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:C.desc})]},C.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:B,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:K,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:ss.map(C=>e.jsxs("button",{onClick:()=>N(C),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:u.includes(C)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:u.includes(C)?"rgba(139,92,246,0.08)":"transparent",color:u.includes(C)?"#a78bfa":"var(--text-secondary)"},children:[u.includes(C)?"☑ ":"☐ ",C]},C))})]}),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:l,onChange:C=>d(C.target.value),placeholder:"e.g. Shadow DOM 안의 버튼도 탐색해줘, readChat에서 코드블럭 포맷 유지해...",rows:2,className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] resize-none placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]})]}),(i==="running"||i==="done"||i==="error")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Agent Output"}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-[#0d0d0d] p-3 font-mono text-[11px] leading-relaxed text-text-secondary overflow-y-auto",style:{maxHeight:320,minHeight:200},children:[v.map((C,y)=>e.jsx("div",{className:C.startsWith("✅")?"text-green-400":C.startsWith("❌")||C.startsWith("⚠")?"text-amber-400":"",children:C},y)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:T})]}),x&&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:x})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-between items-center",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[i==="config"&&u.length>0&&`${u.length} script(s) selected`,i==="running"&&"Agent is working...",i==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[i==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:A,disabled:u.length===0,className:"machine-btn",style:{background:u.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:u.length>0?"rgba(139,92,246,0.4)":void 0,color:u.length>0?"#a78bfa":void 0,opacity:u.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:$,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(i==="done"||i==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{c("config"),j([]),I("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function wr({machineId:t,providers:s,sendDaemonCommand:a,onClose:r,onCreated:i}){var E;const c=s.filter(A=>A.category==="ide"),[o,p]=n.useState(((E=c[0])==null?void 0:E.type)||""),[u,m]=n.useState(""),[l,d]=n.useState(""),[v,j]=n.useState(!1),[x,I]=n.useState(""),[T,f]=n.useState(!1),N=A=>{const $=A.toLowerCase().replace(/[^a-z0-9-]/g,"");m($),(!l||l===B(u))&&d(B($))},B=A=>A.split("-").map($=>$.charAt(0).toUpperCase()+$.slice(1)).join(" "),K=async()=>{if(!(!u||!l||!o)){j(!0),I("");try{const A=await a(t,"provider_clone",{type:u,name:l,category:"ide",location:"user",cloneFrom:o});A!=null&&A.success||A!=null&&A.created?(f(!0),i==null||i(u)):I((A==null?void 0:A.error)||"Failed to create provider")}catch(A){I((A==null?void 0:A.message)||"Connection failed")}j(!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:A=>A.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:T?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:u})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",u,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",u]})," 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:c.map(A=>e.jsxs("button",{onClick:()=>p(A.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:o===A.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:o===A.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:A.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:o===A.type?"#a78bfa":"var(--text-secondary)"},children:A.displayName})]},A.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:u,onChange:A=>N(A.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/",u||"...","/"]})]})]}),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:l,onChange:A=>d(A.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"})]}),x&&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:x})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:T?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:K,disabled:!u||!l||v,className:"machine-btn",style:{background:u&&l?"rgba(34,197,94,0.12)":void 0,borderColor:u&&l?"rgba(34,197,94,0.3)":void 0,color:u&&l?"#86efac":void 0,opacity:!u||!l||v?.4:1},children:v?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function Nr({machineId:t,providers:s,sendDaemonCommand:a}){const[r,i]=n.useState([]),[c,o]=n.useState(!1),[p,u]=n.useState(null),[m,l]=n.useState("all"),[d,v]=n.useState(null),[j,x]=n.useState(!1),I=n.useCallback(async()=>{var f;if(t){o(!0);try{const N=await a(t,"get_provider_settings",{}),B=(N==null?void 0:N.result)||N;if(N!=null&&N.success&&(B!=null&&B.settings)){const K=[];for(const[E,A]of Object.entries(B.settings)){const $=s.find(C=>C.type===E);K.push({type:E,displayName:($==null?void 0:$.displayName)||E,icon:($==null?void 0:$.icon)||"",category:($==null?void 0:$.category)||"unknown",schema:A,values:((f=B.values)==null?void 0:f[E])||{}})}K.sort((E,A)=>E.category.localeCompare(A.category)||E.displayName.localeCompare(A.displayName)),i(K)}}catch{}o(!1)}},[t,s,a]);n.useEffect(()=>{r.length===0&&I()},[]);const T=async(f,N,B)=>{u(`${f}.${N}`),i(K=>K.map(E=>E.type===f?{...E,values:{...E.values,[N]:B}}:E));try{const K=await a(t,"set_provider_setting",{providerType:f,key:N,value:B});K!=null&&K.success||I()}catch{I()}u(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(f=>e.jsx("button",{onClick:()=>l(f),className:`machine-btn text-[10px] px-2 py-0.5 ${m===f?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:f.toUpperCase()},f))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>x(!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:I,disabled:c,className:"machine-btn",children:c?"⏳ Loading...":"↻ Refresh"})]})]}),m!=="all"&&r.filter(f=>f.category===m).length>1&&(()=>{const f=r.filter(E=>E.category===m),N=new Map;for(const E of f)for(const A of E.schema){if(A.type!=="boolean")continue;const $=N.get(A.key),C=!!(E.values[A.key]??A.default);$?($.onCount+=C?1:0,$.total+=1):N.set(A.key,{label:A.label||A.key,onCount:C?1:0,total:1})}const B=[...N.entries()].filter(([,E])=>E.total===f.length);if(B.length===0)return null;const K=async(E,A)=>{for(const $ of f)await T($.type,E,A)};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 ",m.toUpperCase()," providers (",f.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:B.map(([E,A])=>{const $=A.onCount===A.total,C=A.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:A.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",A.onCount,"/",A.total,")"]}),e.jsx("button",{onClick:()=>void K(E,!0),disabled:$,className:`machine-btn text-[9px] px-1.5 py-px ${$?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void K(E,!1),disabled:C,className:`machine-btn text-[9px] px-1.5 py-px ${C?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},E)})})]})})(),c&&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(f=>m==="all"||f.category===m).map(f=>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:f.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:f.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:f.category==="acp"?"rgba(139,92,246,0.08)":f.category==="cli"?"rgba(59,130,246,0.08)":f.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:f.category==="acp"?"#a78bfa":f.category==="cli"?"#60a5fa":f.category==="ide"?"#86efac":"#fbbf24"},children:f.category}),f.category==="ide"&&e.jsx("button",{onClick:()=>v(s.find(N=>N.type===f.type)||{type:f.type,displayName:f.displayName,icon:f.icon,category:f.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:f.schema.map(N=>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:[N.label||N.key,p===`${f.type}.${N.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),N.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:N.description})]}),e.jsx("div",{className:"shrink-0",children:N.type==="boolean"?e.jsx("button",{onClick:()=>T(f.type,N.key,!(f.values[N.key]??N.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:f.values[N.key]??N.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:f.values[N.key]??N.default?21:3}})}):N.type==="number"?e.jsx("input",{type:"number",value:f.values[N.key]??N.default??0,min:N.min,max:N.max,onChange:B=>{const K=parseInt(B.target.value)||0;N.min!==void 0&&K<N.min||N.max!==void 0&&K>N.max||T(f.type,N.key,K)},className:"machine-input w-20 text-center text-[11px]"}):N.type==="select"&&N.options?e.jsx("select",{value:f.values[N.key]??N.default??"",onChange:B=>T(f.type,N.key,B.target.value),className:"machine-input text-[11px]",children:N.options.map(B=>e.jsx("option",{value:B,children:B},B))}):e.jsx("input",{type:"text",value:f.values[N.key]??N.default??"",onBlur:B=>T(f.type,N.key,B.target.value),className:"machine-input w-[120px] text-[11px]"})})]},N.key))})]},f.type))}),d&&e.jsx(vr,{machineId:t,provider:d,sendDaemonCommand:a,onClose:()=>v(null)}),j&&e.jsx(wr,{machineId:t,providers:s,sendDaemonCommand:a,onClose:()=>x(!1),onCreated:()=>{x(!1),I()}})]})}function kr({machineId:t,sendDaemonCommand:s}){const[a,r]=n.useState([]),[i,c]=n.useState(0),[o,p]=n.useState(!0),[u,m]=n.useState("debug"),l=n.useRef(null),d=n.useRef(!1);return n.useEffect(()=>{if(!t||!o)return;const v=async()=>{try{const x=await s(t,"get_logs",{count:200,minLevel:u,since:i}),I=(x==null?void 0:x.result)||x;if(x!=null&&x.success&&Array.isArray(I==null?void 0:I.logs)&&I.logs.length>0){r(f=>[...f,...I.logs.map(B=>({timestamp:B.ts,level:B.level,message:`[${B.category}] ${B.message}`}))].slice(-300));const T=Math.max(...I.logs.map(f=>f.ts));c(T)}}catch{}};v();const j=setInterval(v,3e3);return()=>clearInterval(j)},[t,o,i,u,s]),n.useEffect(()=>{if(o&&a.length>0){const v=d.current?"smooth":"instant";setTimeout(()=>{var j;(j=l.current)==null||j.scrollIntoView({behavior:v}),d.current=!0},50)}},[a.length,o]),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(v=>e.jsx("button",{onClick:()=>{m(v),r([]),c(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${u===v?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:v.toUpperCase()},v))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[a.length," entries"]}),e.jsx("button",{onClick:()=>p(!o),className:`machine-btn ${o?"text-green-500 border-green-500/30":""}`,children:o?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),c(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:[a.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),a.map((v,j)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:v.level==="error"?"#ef4444":v.level==="warn"?"#f59e0b":v.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(v.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:v.level==="error"?"#ef4444":v.level==="warn"?"#f59e0b":v.level==="debug"?"#475569":"#8b5cf6"},children:v.level==="error"?"ERR":v.level==="warn"?"WRN":v.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:v.message})]},j)),e.jsx("div",{ref:l})]})]})}function Sr({machine:t,launchPick:s,actions:a}){const{runLaunchCliCore:r,setLaunchPick:i}=a;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(c=>e.jsxs("button",{type:"button",className:"text-left text-xs px-3 py-2 rounded-lg border border-border-subtle bg-bg-primary hover:bg-violet-500/10 transition-colors",onClick:()=>{i(null),r({cliType:s.cliType,workspaceId:c.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:c.label||c.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:c.path})]},c.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",disabled:!t.defaultWorkspacePath,onClick:()=>{i(null),r({cliType:s.cliType,useDefaultWorkspace:!0,argsStr:s.argsStr,model:s.model})},children:"Default workspace"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",onClick:()=>{i(null),r({cliType:s.cliType,useHome:!0,argsStr:s.argsStr,model:s.model})},children:"Home directory"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[80px]",onClick:()=>i(null),children:"Cancel"})]})]})})}function Cr(){var K,E,A,$,C,y,R,F,H,Z;const{id:t}=is(),s=lt(),{sendCommand:a}=Ye(),r=jt(),i=r.ides||[],c=r.initialLoaded??!0,[o,p]=n.useState("overview"),u=n.useRef(null),m=gr({machineId:t,sendDaemonCommand:a,logsEndRef:u}),l=i.find(b=>b.id===t&&b.daemonMode),d=((l==null?void 0:l.availableProviders)||[]).map(b=>({type:b.type,displayName:b.displayName,icon:b.icon,category:b.category})),v={};for(const b of d)v[b.type]=b.icon;const j=b=>v[b]||"",x=l?{id:l.id,hostname:((K=l.machine)==null?void 0:K.hostname)||l.id,platform:((E=l.machine)==null?void 0:E.platform)||"unknown",arch:((A=l.machine)==null?void 0:A.arch)||"",cpus:(($=l.machine)==null?void 0:$.cpus)||0,totalMem:((C=l.machine)==null?void 0:C.totalMem)||0,freeMem:((y=l.machine)==null?void 0:y.freeMem)||0,availableMem:(R=l.machine)==null?void 0:R.availableMem,loadavg:((F=l.machine)==null?void 0:F.loadavg)||[],uptime:((H=l.machine)==null?void 0:H.uptime)||0,release:((Z=l.machine)==null?void 0:Z.release)||"",cdpConnected:!!(l.ides||[]).some(b=>b.cdpConnected),machineNickname:l.machineNickname||null,p2p:l.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:l.detectedIdes||[],managedIdeIds:l.managedIdeIds||[],managedCliIds:l.managedCliIds||[],workspaces:l.workspaces||[],defaultWorkspaceId:l.defaultWorkspaceId??l.activeWorkspaceId??null,defaultWorkspacePath:l.defaultWorkspacePath??l.activeWorkspacePath??null,workspaceActivity:l.workspaceActivity||[]}:null,I=i.filter(b=>b.daemonId===t&&!b.daemonMode).filter(b=>!Gt(b)&&!Xt(b)).map(b=>({id:b.id,type:b.type,version:b.version||"",instanceId:b.instanceId||"",status:b.status,workspace:b.workspace||null,terminals:b.terminals||0,aiAgents:vn(b.aiAgents||b.agents||[]),activeChat:b.activeChat||null,chats:b.chats||[],agentStreams:b.agentStreams||[],cdpConnected:b.cdpConnected||!1,daemonId:t})),T=i.filter(b=>b.daemonId===t&&Gt(b)).map(b=>({id:b.id,type:b.type,cliName:b.cliName||b.type,status:b.status,workspace:b.workspace||"",activeChat:b.activeChat||null,daemonId:t})),f=i.filter(b=>b.daemonId===t&&Xt(b)).map(b=>({id:b.id,type:b.type,acpName:b.cliName||b.type,status:b.status,workspace:b.workspace||"",activeChat:b.activeChat||null,currentModel:b.currentModel,currentPlan:b.currentPlan,daemonId:t}));if(!x)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:()=>s("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const N=x.machineNickname||x.hostname,B=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(sn,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(dt,{size:14})," IDEs"]}),count:I.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ms,{size:14})," CLIs"]}),count:T.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(hs,{size:14})," ACP Agents"]}),count:f.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(us,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Vs,{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:()=>s("/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:[m.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:m.nicknameInput,onChange:b=>m.setNicknameInput(b.target.value),onKeyDown:b=>{b.key==="Enter"&&m.handleSaveNickname(),b.key==="Escape"&&m.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:m.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>m.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{m.setEditingNickname(!0),m.setNicknameInput(x.machineNickname||"")},title:"Click to set nickname",children:N}),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:[x.platform," · ",x.arch," · ",x.cpus," cores"]}),(l==null?void 0:l.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",l.version]}),(l==null?void 0:l.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 a(t,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",l.serverVersion]}),x.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:x.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:x.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",x.p2p.state==="connected"?`● ${x.p2p.peers}`:"○"]}),x.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 ●"}),x.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",x.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:B.map(b=>e.jsxs("button",{onClick:()=>p(b.id),className:`machine-tab shrink-0${o===b.id?" active":""}`,children:[b.label,b.count!==void 0&&e.jsx("span",{className:"tab-count",children:b.count})]},b.id))})]}),e.jsxs("div",{className:"page-content",children:[o==="overview"&&e.jsx(br,{machine:x,managedIdes:I,managedClis:T,managedAcps:f,actions:m}),o==="ides"&&e.jsx(Et,{category:"ide",machine:x,machineId:t,providers:d,managedEntries:I,getIcon:j,actions:m,sendDaemonCommand:a}),o==="clis"&&e.jsx(Et,{category:"cli",machine:x,machineId:t,providers:d,managedEntries:T,getIcon:j,actions:m}),o==="acps"&&e.jsx(Et,{category:"acp",machine:x,machineId:t,providers:d,managedEntries:f,getIcon:j,actions:m}),o==="providers"&&e.jsx(Nr,{machineId:t,providers:d,sendDaemonCommand:a}),o==="logs"&&e.jsx(kr,{machineId:t,sendDaemonCommand:a})]}),m.launchPick&&x&&e.jsx(Sr,{machine:x,launchPick:m.launchPick,actions:m})]})}function Ir(){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 ns=Ir(),rs=3e3,Mr=3e4;let Fe=null,Tr=0;const yt=new Map,Bt=new Set;let Xe=null,Er=null,at=null;async function gt(t,s,a){const r=Fe;if(r&&r.readyState===WebSocket.OPEN){const c=`req_${++Tr}_${Date.now()}`;return new Promise((o,p)=>{const u=setTimeout(()=>{yt.delete(c),p(new Error(`WS command timeout: ${s}`))},3e4);yt.set(c,{resolve:m=>{clearTimeout(u),o(m)},reject:m=>{clearTimeout(u),p(m)}}),r.send(JSON.stringify({type:"command",requestId:c,data:{type:s,payload:a||{},target:t}}))})}const i=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:a||{},target:t})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}class $r{constructor(s){Ae(this,"daemonId");Ae(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Fe==null?void 0:Fe.readyState)===WebSocket.OPEN}get connectionState(){return(Fe==null?void 0:Fe.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,a){return gt(this.daemonId,s,a)}async sendInput(s,a){const r=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId;return gt(r,"cdp_remote_action",{action:s,params:a})}startScreenshots(s){this.screenshotIdeType=s||null,Xe&&(clearInterval(Xe),Xe=null);const a=async()=>{if(this.hasCommandChannel)try{const r=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId,i=await gt(r,"screenshot",{width:1280});if(i!=null&&i.success&&(i!=null&&i.base64)){const c=await fetch(`data:image/jpeg;base64,${i.base64}`).then(o=>o.blob());Bt.forEach(o=>o(this.daemonId,c))}}catch{}};a(),Xe=setInterval(a,2e3)}stopScreenshots(s){Xe&&(clearInterval(Xe),Xe=null)}}let Ve=null;function Ar(t){(!Ve||Ve.daemonId!==t)&&(Ve=new $r(t));const s=Re._originalGet||Re.get.bind(Re);Re._originalGet=s,Re.get=a=>a===t||a.startsWith("standalone")?Ve:s(a),Re.getState=a=>(a===t||a.startsWith("standalone"))&&(Ve==null?void 0:Ve.connectionState)||"disconnected",Re.onScreenshot=(a,r)=>(Bt.add(r),()=>{Bt.delete(r)})}function _r({children:t}){const s=n.useRef(Ht()),a=Ht();s.current=a;const{setUserName:r}=ot(),i=n.useRef(r);i.current=r;const[,c]=n.useState("disconnected"),o=n.useCallback((d,v)=>{c(d),at==null||at(d,v)},[]),p=n.useRef(null),u=n.useRef(),m=n.useRef(rs),l=n.useRef(!0);return n.useEffect(()=>{l.current=!0;function d(){var x,I;if(!l.current||((x=p.current)==null?void 0:x.readyState)===WebSocket.OPEN||((I=p.current)==null?void 0:I.readyState)===WebSocket.CONNECTING)return;o("connecting"),console.log(`[Standalone WS] Connecting to ${ns}...`);let j;try{j=new WebSocket(ns)}catch(T){console.error("[Standalone WS] Failed to create WebSocket:",T),v();return}p.current=j,j.onopen=()=>{if(!l.current){j.close();return}o("connected"),m.current=rs,console.log("[Standalone WS] Connected")},Fe=j,j.onmessage=T=>{var f;try{const N=JSON.parse(T.data);if((N.type==="command_result"||N.type==="error")&&N.requestId){const B=yt.get(N.requestId);B&&(yt.delete(N.requestId),N.type==="error"?B.reject(new Error(((f=N.data)==null?void 0:f.message)||"Command failed")):B.resolve(N.data));return}if(N.type==="status"||N.type==="initial_state"){const B=N.data;if(!B)return;const{injectEntries:K,markLoaded:E}=s.current,A=B.id||"standalone";Er=A,Ar(A),o("connected",A);const $=In(B,{daemonId:A});$.length>0&&K($),E(),B.userName&&i.current&&i.current(B.userName)}}catch(N){console.error("[Standalone WS] Parse error:",N)}},j.onclose=()=>{l.current&&(o("disconnected"),p.current=null,v())},j.onerror=T=>{console.warn("[Standalone WS] Error, will reconnect:",T)}}function v(){if(!l.current)return;clearTimeout(u.current);const j=m.current;console.log(`[Standalone WS] Reconnecting in ${j}ms...`),u.current=setTimeout(()=>{m.current=Math.min(m.current*1.5,Mr),d()},j)}return d(),()=>{l.current=!1,clearTimeout(u.current),p.current&&(p.current.onclose=null,p.current.close(),p.current=null,Fe=null)}},[]),e.jsx(e.Fragment,{children:t})}function Rr({children:t}){const[s,a]=n.useState("disconnected"),[r,i]=n.useState(null);n.useEffect(()=>(at=(o,p)=>{a(o),p&&i(p)},()=>{at=null}),[]);const c=n.useMemo(()=>{const o=s==="connected",p={};return r&&(p[r]=o?"connected":"connecting"),p.standalone=o?"connected":"connecting",{wsStatus:s,isConnected:o,connectionStates:p}},[s,r]);return e.jsx(Fs,{connectionOverrides:c,children:e.jsx(_r,{children:t})})}const Pr=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Gs,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Xs,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(us,{}),label:"Settings"}];function Lr({children:t}){const s=lt(),a=Rs(),[r,i]=n.useState(!1),[c,o]=n.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),p=l=>{s(l),i(!1)},u=()=>{o(l=>{const d=!l;try{localStorage.setItem("sidebar-collapsed",d?"1":"0")}catch{}return d})},m=l=>`nav-item${a.pathname.startsWith(l)?" active":""} cursor-pointer ${c?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${c?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:l=>l.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${c?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!c&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Pr.map(l=>e.jsxs("div",{className:m(l.path),id:`nav-${l.id}`,onClick:()=>p(l.path),title:c?l.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:l.icon}),!c&&l.label]},l.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer${a.pathname==="/about"?" active":""} ${c?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:c?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(qs,{})}),!c&&"About"]}),!c&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.6.40"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${c?"justify-center py-2.5 px-0":"mt-1"}`,onClick:u,title:c?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:c?"›":"‹"}),!c&&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 Dr=[{icon:"🏠",title:"Local-first",desc:"Everything runs on your machine. No data leaves your network. Full privacy by design."},{icon:"💬",title:"Agent chat relay",desc:"Read and respond to AI conversations in real-time across all connected IDEs."},{icon:"📸",title:"Live screenshots",desc:"View your IDE screens directly in the browser via local WebSocket streaming."},{icon:"🎛️",title:"Remote control",desc:"Click, type, and interact with your IDE from the dashboard — no window switching."},{icon:"🔌",title:"Multi-IDE support",desc:"Monitor and control multiple IDEs simultaneously — VS Code, Cursor, Windsurf, and more."},{icon:"⚡",title:"Extension agents",desc:"Manage extension-based agents like Cline and Roo Code alongside native IDE agents."}],Br=[{icon:"🌍",title:"Access from anywhere",desc:"Control your agents from any device, any network. No VPN or port forwarding needed."},{icon:"🔗",title:"WebRTC P2P streaming",desc:"End-to-end encrypted peer-to-peer connection for zero-latency remote screenshots and control."},{icon:"📱",title:"Mobile notifications",desc:"Get push notifications when agents need approval. Quick approve/reject from your phone."},{icon:"📡",title:"REST API access",desc:"Integrate with Slack, CI/CD pipelines, or custom tools. Scoped API keys with granular permissions."},{icon:"👥",title:"Team dashboard",desc:"Share a unified view across your team. See who's running what, where, in real time."},{icon:"🔐",title:"Enterprise security",desc:"SSO, RBAC, audit logs, and SLA guarantees for production teams."}],Wr=[{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 agent support",selfhost:!0,cloud:!0},{feature:"CLI agent support",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 & 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}],$t={ides:["VS Code","Cursor","Antigravity","Windsurf","Trae","PearAI","Kiro","VSCodium","VS Code Insiders"],agents:["GitHub Copilot","Cline","Roo Code"],cli:["Gemini CLI","Claude Code","Codex CLI"]};function Or(){return e.jsxs("div",{className:"py-8 px-6 max-w-[860px] mx-auto text-text-primary",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-14 h-14 mb-3 mx-auto"}),e.jsx("h1",{className:"text-[26px] font-extrabold mb-1.5 text-text-primary",children:"ADHDev"}),e.jsx("p",{className:"text-[13px] text-text-muted",children:"Agent Dashboard Hub for Dev — Self-hosted Edition"}),e.jsxs("div",{className:"inline-block mt-3 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.6.40"]})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"✅"})," What's included"]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(250px,1fr))] gap-3",children:Dr.map(t=>e.jsxs("div",{className:"bg-bg-glass border border-border-subtle rounded-xl px-4 py-4 transition-colors hover:border-border-default",children:[e.jsx("div",{className:"text-xl mb-1.5",children:t.icon}),e.jsx("div",{className:"font-semibold text-[13px] mb-1",children:t.title}),e.jsx("div",{className:"text-[12px] text-text-muted leading-relaxed",children:t.desc})]},t.title))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsx("h2",{className:"text-lg font-bold mb-4",children:"Compatible with"}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-5",children:[{label:"IDEs",items:$t.ides},{label:"Extension agents",items:$t.agents},{label:"CLI agents",items:$t.cli}].map(t=>e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-2 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1",children:t.items.map(s=>e.jsx("div",{className:"text-[12px] px-2.5 py-1.5 bg-bg-glass rounded-md border border-border-subtle",children:s},s))})]},t.label))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"⚖️"})," Self-hosted vs Cloud"]}),e.jsx("div",{className:"rounded-xl border border-border-subtle overflow-hidden",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-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[100px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-[11px] uppercase tracking-wider w-[100px] text-violet-500",children:"Cloud"})]})}),e.jsx("tbody",{children:Wr.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"",children:[e.jsx("td",{className:"px-4 py-2 text-text-secondary",children:t.feature}),e.jsx("td",{className:"text-center px-4 py-2",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:"text-center px-4 py-2",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})]}),e.jsx("section",{className:"mb-10",children:e.jsx("div",{className:"rounded-2xl border border-violet-500/20 bg-violet-500/[0.04] px-6 py-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"text-3xl shrink-0",children:"🚀"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-bold text-[15px] mb-1.5",children:"Unlock more with ADHDev Cloud"}),e.jsx("p",{className:"text-[13px] text-text-muted leading-relaxed mb-4",children:"Access your agents from anywhere — your phone, another laptop, or a coffee shop. Cloud adds WebRTC P2P streaming, mobile push notifications, REST API, team collaboration, and multi-machine support. Your local setup stays exactly the same."}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-2.5 mb-5",children:Br.map(t=>e.jsxs("div",{className:"flex gap-2.5 items-start",children:[e.jsx("span",{className:"text-base shrink-0 mt-0.5",children:t.icon}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[12px]",children:t.title}),e.jsx("div",{className:"text-[11px] text-text-muted leading-snug",children:t.desc})]})]},t.title))}),e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Try ADHDev Cloud →"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"GitHub"}),e.jsx("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Discord"})]})]})]})})}),e.jsxs("div",{className:"text-center text-xs text-text-muted pt-4 border-t border-border-subtle",children:[e.jsx("p",{children:"© 2026 RacoLab · ADHDev, Your AI sidekick otter 🦦"}),e.jsx("p",{className:"mt-1 opacity-60",children:"Self-hosted edition — all data stays on your machine"})]})]})}function Kr(){const{ides:t}=ot(),s=t.find(d=>d.type==="adhdev-daemon"),a=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=Ye(),{userName:i}=ot(),[c,o]=n.useState(i||"");n.useEffect(()=>{i!==void 0&&o(i)},[i]);const p=d=>{const v=d.target.value.trim();s!=null&&s.id&&v!==i&&r(s.id,"set_user_name",{userName:v}).catch(console.error)},[u,m]=n.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),l=d=>{m(d);try{localStorage.setItem("adhdev_sound",d?"1":"0")}catch{}};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Bn,{icon:"⚙️",title:"Settings",subtitle:"Local daemon configuration & preferences"}),e.jsxs("div",{className:"page-content",children:[e.jsx(Ze,{title:"Daemon",className:"mb-4",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.6.40"]}),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(Ze,{title:"Detected IDEs",className:"mb-4",children:a.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:a.map(d=>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 ${d.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:d.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:d.type})]},d.type))})}),e.jsx(Ze,{title:"Machine",className:"mb-4",children:e.jsx(Yn,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(Ze,{title:"Theme",className:"mb-4",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:"Site theme"}),e.jsx(Jn,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Chat theme"}),e.jsx(nr,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Accent color"}),e.jsx(lr,{})]})]})}),e.jsx(Ze,{title:"Notifications",className:"mb-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Un,{}),e.jsx(Qe,{label:"🔊 Sound Effects",description:"Play a sound when agent completes or needs approval",checked:u,onChange:l})]})}),e.jsx(Ze,{title:"Preferences",className:"mb-4",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.jsx("span",{className:"text-sm font-semibold flex items-center gap-2",children:"👤 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:c,onChange:d=>o(d.target.value),onBlur:p,onKeyDown:d=>{d.key==="Enter"&&d.currentTarget.blur()}})]})})})]})]})}tr();function as(){const{ides:t}=ot(),s=t.find(a=>{var r;return a.daemonMode||((r=a.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(mt,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(mt,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(mt,{to:"/dashboard",replace:!0})}function Fr(){return e.jsx(Ps,{children:e.jsx(Rr,{children:e.jsx(Ys,{value:{sendCommand:gt,sendData:()=>!1},children:e.jsx(Lr,{children:e.jsxs(Ls,{children:[e.jsx(ze,{path:"/dashboard",element:e.jsx(pr,{})}),e.jsx(ze,{path:"/ide/:id",element:e.jsx(fr,{})}),e.jsx(ze,{path:"/machine",element:e.jsx(as,{})}),e.jsx(ze,{path:"/machines/:id",element:e.jsx(Cr,{})}),e.jsx(ze,{path:"/machines",element:e.jsx(as,{})}),e.jsx(ze,{path:"/about",element:e.jsx(Or,{})}),e.jsx(ze,{path:"/settings",element:e.jsx(Kr,{})}),e.jsx(ze,{path:"*",element:e.jsx(mt,{to:"/dashboard",replace:!0})})]})})})})})}Ds(document.getElementById("root")).render(e.jsx(n.StrictMode,{children:e.jsx(Fr,{})}));
|