groove-dev 0.27.154 → 0.27.156
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@groove-dev/cli/package.json +1 -1
- package/node_modules/@groove-dev/daemon/package.json +1 -1
- package/node_modules/@groove-dev/daemon/src/routes/files.js +26 -4
- package/node_modules/@groove-dev/daemon/src/tunnel-manager.js +0 -2
- package/node_modules/@groove-dev/gui/dist/assets/{index-BTLb6zTD.js → index-COQYX12F.js} +2 -2
- package/node_modules/@groove-dev/gui/dist/index.html +1 -1
- package/node_modules/@groove-dev/gui/package.json +1 -1
- package/node_modules/@groove-dev/gui/src/components/agents/agent-file-tree.jsx +12 -14
- package/node_modules/@groove-dev/gui/src/components/editor/file-tree.jsx +6 -8
- package/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/daemon/package.json +1 -1
- package/packages/daemon/src/routes/files.js +26 -4
- package/packages/daemon/src/tunnel-manager.js +0 -2
- package/packages/gui/dist/assets/{index-BTLb6zTD.js → index-COQYX12F.js} +2 -2
- package/packages/gui/dist/index.html +1 -1
- package/packages/gui/package.json +1 -1
- package/packages/gui/src/components/agents/agent-file-tree.jsx +12 -14
- package/packages/gui/src/components/editor/file-tree.jsx +6 -8
|
@@ -945,7 +945,7 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
945
945
|
`),n=[];let a=0,r=[];for(;a<s.length;){const l=s[a];if(l.includes("|")&&a+1<s.length&&/^\|?\s*[-:]+/.test(s[a+1])){r.length>0&&(n.push({type:"text",content:r.join(`
|
|
946
946
|
`)}),r=[]);const c=l.split("|").map(f=>f.trim()).filter(Boolean);a+=2;const A=[];for(;a<s.length&&s[a].includes("|");)A.push(s[a].split("|").map(f=>f.trim()).filter(Boolean)),a++;n.push({type:"table",headers:c,rows:A})}else r.push(l),a++}return r.length>0&&n.push({type:"text",content:r.join(`
|
|
947
947
|
`)}),n}function aX({text:e}){if(!e)return null;const s=nX(e);return t.jsx(t.Fragment,{children:s.map((n,a)=>{if(n.type==="table")return t.jsx(Xb,{headers:n.headers,rows:n.rows},a);const r=n.content.split(/(```[\s\S]*?```|`[^`]+`|\*\*[^*]+\*\*|\*[^*]+\*)/g);return t.jsx("span",{children:r.map((l,c)=>{if(!l)return null;if(l.startsWith("```")&&l.endsWith("```")){const A=l.slice(3,-3),f=A.indexOf(`
|
|
948
|
-
`),m=f>=0?A.slice(f+1):A;return t.jsx("pre",{className:"my-2 px-3 py-2 rounded-lg bg-surface-0 border border-border-subtle overflow-x-auto",children:t.jsx("code",{className:"text-xs font-mono text-text-1 whitespace-pre",children:m})},c)}return l.startsWith("`")&&l.endsWith("`")?t.jsx("code",{className:"px-1.5 py-0.5 rounded bg-surface-0 text-xs font-mono text-accent",children:l.slice(1,-1)},c):l.startsWith("**")&&l.endsWith("**")?t.jsx("strong",{className:"font-semibold text-text-0",children:l.slice(2,-2)},c):l.startsWith("*")&&l.endsWith("*")?t.jsx("em",{className:"italic",children:l.slice(1,-1)},c):t.jsx("span",{children:l},c)})},a)})})}function rX({msg:e}){return e.role==="user"?t.jsx("div",{className:"flex justify-end animate-chat-fade-in",children:t.jsxs("div",{className:"max-w-[85%]",children:[e.screenshot&&t.jsx("img",{src:e.screenshot,alt:"Screenshot",className:"mb-2 rounded-lg border border-border-subtle max-h-40 object-contain"}),t.jsx("div",{className:"px-4 py-3 rounded-2xl rounded-br-md bg-gradient-to-br from-accent/12 to-accent/6 border border-accent/15",children:t.jsx("p",{className:"text-sm text-text-0 font-sans whitespace-pre-wrap break-words leading-relaxed",children:e.content})}),t.jsx("div",{className:"text-2xs text-text-4 font-sans mt-1 text-right",children:ls(e.timestamp)})]})}):t.jsxs("div",{className:"max-w-[85%] animate-chat-fade-in",children:[t.jsx("div",{className:"rounded-2xl rounded-tl-md bg-surface-1/80 border border-border-subtle px-4 py-3",children:t.jsx("p",{className:"text-sm text-text-1 font-sans whitespace-pre-wrap break-words leading-relaxed",children:t.jsx(aX,{text:e.content})})}),t.jsx("div",{className:"text-2xs text-text-4 font-sans mt-1",children:ls(e.timestamp)})]})}function oX(){const e=U(O=>O.previewChat),s=U(O=>O.previewState),n=U(O=>O.iteratePreview),a=U(O=>O.previewIterating),[r,l]=p.useState(""),c=p.useRef(null),A=p.useRef(null),f=p.useRef(!0);p.useEffect(()=>{const O=c.current;if(!O)return;function b(){f.current=O.scrollHeight-O.scrollTop-O.clientHeight<50}return O.addEventListener("scroll",b),()=>O.removeEventListener("scroll",b)},[]),p.useEffect(()=>{f.current&&c.current&&(c.current.scrollTop=c.current.scrollHeight)},[e==null?void 0:e.length]);const m=p.useCallback(()=>{const O=A.current;O&&(O.style.height="auto",O.style.height=Math.min(O.scrollHeight,160)+"px")},[]);p.useEffect(()=>{m()},[r,m]);function h(){const O=r.trim();!O||a||(n(O),l(""),A.current&&(A.current.style.height="auto"))}function g(O){O.key==="Enter"&&!O.shiftKey&&(O.preventDefault(),h())}return t.jsxs("div",{className:"flex flex-col h-full bg-surface-0",children:[t.jsx("div",{className:"flex-shrink-0 h-10 flex items-center px-4 border-b border-border bg-surface-3",children:t.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Iterate"})}),t.jsx("div",{className:"flex-shrink-0 px-4 py-2 bg-accent/5 border-b border-accent/10",children:t.jsxs("p",{className:"text-2xs text-accent font-sans",children:["Iterating on ",t.jsx("span",{className:"font-semibold",children:s.teamId||"project"})," — changes auto-refresh via hot reload"]})}),t.jsxs("div",{ref:c,className:"flex-1 overflow-y-auto px-4 py-4 space-y-4",children:[e.length===0&&t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"max-w-xs w-full px-5 py-5 bg-surface-1 border border-border-subtle rounded-xl text-center",children:[t.jsx(Po,{size:24,className:"mx-auto text-accent mb-3"}),t.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans mb-3",children:"Preview is live!"}),t.jsxs("ul",{className:"text-left space-y-2 text-2xs text-text-2 font-sans",children:[t.jsxs("li",{className:"flex gap-2",children:[t.jsx(ra,{size:11,className:"text-text-3 mt-0.5 flex-shrink-0"}),t.jsx("span",{children:"Type a message to request changes — your feedback goes to the team planner who routes it to the right agent"})]}),t.jsxs("li",{className:"flex gap-2",children:[t.jsx(oN,{size:11,className:"text-text-3 mt-0.5 flex-shrink-0"}),t.jsx("span",{children:"Use the camera icon to screenshot a specific area and annotate it"})]}),t.jsxs("li",{className:"flex gap-2",children:[t.jsx(Ks,{size:11,className:"text-text-3 mt-0.5 flex-shrink-0"}),t.jsx("span",{children:"Changes auto-refresh via hot module reload"})]})]})]})}),e.map((O,b)=>t.jsx(rX,{msg:O},b)),a&&t.jsx("div",{className:"max-w-[85%] animate-chat-fade-in",children:t.jsx("div",{className:"rounded-2xl rounded-tl-md bg-surface-1/80 border border-border-subtle px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ie,{size:14,className:"text-accent animate-spin"}),t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Routing to planner..."})]})})})]}),t.jsx("div",{className:"flex-shrink-0 px-3 py-3 border-t border-border",children:t.jsxs("div",{className:"flex items-end gap-2 rounded-2xl bg-surface-1/80 border border-accent/8 px-3 py-2",children:[t.jsx("textarea",{ref:A,value:r,onChange:O=>l(O.target.value),onKeyDown:g,placeholder:"Describe changes...",rows:1,style:{minHeight:"36px"},className:"flex-1 resize-none bg-transparent text-sm text-text-0 font-sans placeholder:text-text-4 focus:outline-none py-1.5"}),t.jsx("button",{onClick:h,disabled:!r.trim()||a,className:V("w-9 h-9 flex items-center justify-center rounded-xl transition-all cursor-pointer flex-shrink-0","disabled:opacity-20 disabled:cursor-not-allowed",r.trim()&&!a?"bg-accent/15 text-accent hover:bg-accent/25 border border-accent/25":"bg-surface-4 text-text-4"),children:t.jsx(ra,{size:16})})]})})]})}function iX(){return t.jsx("div",{className:"flex-1 flex items-center justify-center bg-surface-0",children:t.jsxs("div",{className:"text-center space-y-3",children:[t.jsx(bM,{size:40,className:"mx-auto text-text-4"}),t.jsx("h2",{className:"text-lg font-semibold text-text-1 font-sans",children:"No preview active"}),t.jsx("p",{className:"text-sm text-text-3 font-sans max-w-xs",children:"Build a project with a planner team to see it here."})]})})}const lX={desktop:"100%",tablet:"768px",mobile:"375px"};function cX({embedded:e=!1}){const s=U(m=>m.previewState),n=p.useRef(null),[a,r]=p.useState(0),l=p.useCallback(()=>{r(m=>m+1)},[]);if(!s.url)return t.jsx(iX,{});const c=s.teamId?`/api/preview/${s.teamId}/proxy/`:s.url,A=lX[s.deviceSize]||"100%",f=s.deviceSize==="desktop";return t.jsxs("div",{className:"flex flex-col h-full bg-surface-0 md:flex-row",children:[t.jsxs("div",{className:"flex flex-col flex-[3] min-w-0 min-h-0",children:[t.jsx(kz,{onRefresh:l}),t.jsxs("div",{className:"flex-1 relative overflow-hidden bg-surface-1",children:[s.screenshotMode&&t.jsx(sX,{iframeRef:n}),t.jsx("div",{className:V("h-full transition-all duration-200",f?"w-full":"mx-auto"),style:f?void 0:{width:A,maxWidth:"100%"},children:t.jsx("iframe",{ref:n,src:c,title:"Preview",className:"w-full h-full border-0 bg-white",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"},a)})]})]}),!e&&t.jsx("div",{className:"flex-[2] min-w-[280px] max-w-[480px] border-l border-border md:max-w-none md:flex-[2]",children:t.jsx(oX,{})})]})}var AX=p.createContext(void 0);function Ad(e){const s=p.useContext(AX);return e||s||"ltr"}function yO(e,[s,n]){return Math.min(n,Math.max(s,e))}function dX(e,s){return p.useReducer((n,a)=>s[n][a]??n,e)}var Zb="ScrollArea",[hC]=La(Zb),[uX,oa]=hC(Zb),pC=p.forwardRef((e,s)=>{const{__scopeScrollArea:n,type:a="hover",dir:r,scrollHideDelay:l=600,...c}=e,[A,f]=p.useState(null),[m,h]=p.useState(null),[g,O]=p.useState(null),[b,v]=p.useState(null),[w,N]=p.useState(null),[Q,S]=p.useState(0),[C,k]=p.useState(0),[F,B]=p.useState(!1),[T,$]=p.useState(!1),M=lt(s,se=>f(se)),I=Ad(r);return t.jsx(uX,{scope:n,type:a,dir:I,scrollHideDelay:l,scrollArea:A,viewport:m,onViewportChange:h,content:g,onContentChange:O,scrollbarX:b,onScrollbarXChange:v,scrollbarXEnabled:F,onScrollbarXEnabledChange:B,scrollbarY:w,onScrollbarYChange:N,scrollbarYEnabled:T,onScrollbarYEnabledChange:$,onCornerWidthChange:S,onCornerHeightChange:k,children:t.jsx(Ge.div,{dir:I,...c,ref:M,style:{position:"relative","--radix-scroll-area-corner-width":Q+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});pC.displayName=Zb;var gC="ScrollAreaViewport",OC=p.forwardRef((e,s)=>{const{__scopeScrollArea:n,children:a,nonce:r,...l}=e,c=oa(gC,n),A=p.useRef(null),f=lt(s,A,c.onViewportChange);return t.jsxs(t.Fragment,{children:[t.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),t.jsx(Ge.div,{"data-radix-scroll-area-viewport":"",...l,ref:f,style:{overflowX:c.scrollbarXEnabled?"scroll":"hidden",overflowY:c.scrollbarYEnabled?"scroll":"hidden",...e.style},children:t.jsx("div",{ref:c.onContentChange,style:{minWidth:"100%",display:"table"},children:a})})]})});OC.displayName=gC;var Za="ScrollAreaScrollbar",bC=p.forwardRef((e,s)=>{const{forceMount:n,...a}=e,r=oa(Za,e.__scopeScrollArea),{onScrollbarXEnabledChange:l,onScrollbarYEnabledChange:c}=r,A=e.orientation==="horizontal";return p.useEffect(()=>(A?l(!0):c(!0),()=>{A?l(!1):c(!1)}),[A,l,c]),r.type==="hover"?t.jsx(fX,{...a,ref:s,forceMount:n}):r.type==="scroll"?t.jsx(xX,{...a,ref:s,forceMount:n}):r.type==="auto"?t.jsx(vC,{...a,ref:s,forceMount:n}):r.type==="always"?t.jsx(Gb,{...a,ref:s}):null});bC.displayName=Za;var fX=p.forwardRef((e,s)=>{const{forceMount:n,...a}=e,r=oa(Za,e.__scopeScrollArea),[l,c]=p.useState(!1);return p.useEffect(()=>{const A=r.scrollArea;let f=0;if(A){const m=()=>{window.clearTimeout(f),c(!0)},h=()=>{f=window.setTimeout(()=>c(!1),r.scrollHideDelay)};return A.addEventListener("pointerenter",m),A.addEventListener("pointerleave",h),()=>{window.clearTimeout(f),A.removeEventListener("pointerenter",m),A.removeEventListener("pointerleave",h)}}},[r.scrollArea,r.scrollHideDelay]),t.jsx(tn,{present:n||l,children:t.jsx(vC,{"data-state":l?"visible":"hidden",...a,ref:s})})}),xX=p.forwardRef((e,s)=>{const{forceMount:n,...a}=e,r=oa(Za,e.__scopeScrollArea),l=e.orientation==="horizontal",c=em(()=>f("SCROLL_END"),100),[A,f]=dX("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return p.useEffect(()=>{if(A==="idle"){const m=window.setTimeout(()=>f("HIDE"),r.scrollHideDelay);return()=>window.clearTimeout(m)}},[A,r.scrollHideDelay,f]),p.useEffect(()=>{const m=r.viewport,h=l?"scrollLeft":"scrollTop";if(m){let g=m[h];const O=()=>{const b=m[h];g!==b&&(f("SCROLL"),c()),g=b};return m.addEventListener("scroll",O),()=>m.removeEventListener("scroll",O)}},[r.viewport,l,f,c]),t.jsx(tn,{present:n||A!=="hidden",children:t.jsx(Gb,{"data-state":A==="hidden"?"hidden":"visible",...a,ref:s,onPointerEnter:Be(e.onPointerEnter,()=>f("POINTER_ENTER")),onPointerLeave:Be(e.onPointerLeave,()=>f("POINTER_LEAVE"))})})}),vC=p.forwardRef((e,s)=>{const n=oa(Za,e.__scopeScrollArea),{forceMount:a,...r}=e,[l,c]=p.useState(!1),A=e.orientation==="horizontal",f=em(()=>{if(n.viewport){const m=n.viewport.offsetWidth<n.viewport.scrollWidth,h=n.viewport.offsetHeight<n.viewport.scrollHeight;c(A?m:h)}},10);return ec(n.viewport,f),ec(n.content,f),t.jsx(tn,{present:a||l,children:t.jsx(Gb,{"data-state":l?"visible":"hidden",...r,ref:s})})}),Gb=p.forwardRef((e,s)=>{const{orientation:n="vertical",...a}=e,r=oa(Za,e.__scopeScrollArea),l=p.useRef(null),c=p.useRef(0),[A,f]=p.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),m=SC(A.viewport,A.content),h={...a,sizes:A,onSizesChange:f,hasThumb:m>0&&m<1,onThumbChange:O=>l.current=O,onThumbPointerUp:()=>c.current=0,onThumbPointerDown:O=>c.current=O};function g(O,b){return bX(O,c.current,A,b)}return n==="horizontal"?t.jsx(mX,{...h,ref:s,onThumbPositionChange:()=>{if(r.viewport&&l.current){const O=r.viewport.scrollLeft,b=f2(O,A,r.dir);l.current.style.transform=`translate3d(${b}px, 0, 0)`}},onWheelScroll:O=>{r.viewport&&(r.viewport.scrollLeft=O)},onDragScroll:O=>{r.viewport&&(r.viewport.scrollLeft=g(O,r.dir))}}):n==="vertical"?t.jsx(hX,{...h,ref:s,onThumbPositionChange:()=>{if(r.viewport&&l.current){const O=r.viewport.scrollTop,b=f2(O,A);l.current.style.transform=`translate3d(0, ${b}px, 0)`}},onWheelScroll:O=>{r.viewport&&(r.viewport.scrollTop=O)},onDragScroll:O=>{r.viewport&&(r.viewport.scrollTop=g(O))}}):null}),mX=p.forwardRef((e,s)=>{const{sizes:n,onSizesChange:a,...r}=e,l=oa(Za,e.__scopeScrollArea),[c,A]=p.useState(),f=p.useRef(null),m=lt(s,f,l.onScrollbarXChange);return p.useEffect(()=>{f.current&&A(getComputedStyle(f.current))},[f]),t.jsx(wC,{"data-orientation":"horizontal",...r,ref:m,sizes:n,style:{bottom:0,left:l.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:l.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Jx(n)+"px",...e.style},onThumbPointerDown:h=>e.onThumbPointerDown(h.x),onDragScroll:h=>e.onDragScroll(h.x),onWheelScroll:(h,g)=>{if(l.viewport){const O=l.viewport.scrollLeft+h.deltaX;e.onWheelScroll(O),BC(O,g)&&h.preventDefault()}},onResize:()=>{f.current&&l.viewport&&c&&a({content:l.viewport.scrollWidth,viewport:l.viewport.offsetWidth,scrollbar:{size:f.current.clientWidth,paddingStart:lx(c.paddingLeft),paddingEnd:lx(c.paddingRight)}})}})}),hX=p.forwardRef((e,s)=>{const{sizes:n,onSizesChange:a,...r}=e,l=oa(Za,e.__scopeScrollArea),[c,A]=p.useState(),f=p.useRef(null),m=lt(s,f,l.onScrollbarYChange);return p.useEffect(()=>{f.current&&A(getComputedStyle(f.current))},[f]),t.jsx(wC,{"data-orientation":"vertical",...r,ref:m,sizes:n,style:{top:0,right:l.dir==="ltr"?0:void 0,left:l.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Jx(n)+"px",...e.style},onThumbPointerDown:h=>e.onThumbPointerDown(h.y),onDragScroll:h=>e.onDragScroll(h.y),onWheelScroll:(h,g)=>{if(l.viewport){const O=l.viewport.scrollTop+h.deltaY;e.onWheelScroll(O),BC(O,g)&&h.preventDefault()}},onResize:()=>{f.current&&l.viewport&&c&&a({content:l.viewport.scrollHeight,viewport:l.viewport.offsetHeight,scrollbar:{size:f.current.clientHeight,paddingStart:lx(c.paddingTop),paddingEnd:lx(c.paddingBottom)}})}})}),[pX,yC]=hC(Za),wC=p.forwardRef((e,s)=>{const{__scopeScrollArea:n,sizes:a,hasThumb:r,onThumbChange:l,onThumbPointerUp:c,onThumbPointerDown:A,onThumbPositionChange:f,onDragScroll:m,onWheelScroll:h,onResize:g,...O}=e,b=oa(Za,n),[v,w]=p.useState(null),N=lt(s,M=>w(M)),Q=p.useRef(null),S=p.useRef(""),C=b.viewport,k=a.content-a.viewport,F=js(h),B=js(f),T=em(g,10);function $(M){if(Q.current){const I=M.clientX-Q.current.left,se=M.clientY-Q.current.top;m({x:I,y:se})}}return p.useEffect(()=>{const M=I=>{const se=I.target;(v==null?void 0:v.contains(se))&&F(I,k)};return document.addEventListener("wheel",M,{passive:!1}),()=>document.removeEventListener("wheel",M,{passive:!1})},[C,v,k,F]),p.useEffect(B,[a,B]),ec(v,T),ec(b.content,T),t.jsx(pX,{scope:n,scrollbar:v,hasThumb:r,onThumbChange:js(l),onThumbPointerUp:js(c),onThumbPositionChange:B,onThumbPointerDown:js(A),children:t.jsx(Ge.div,{...O,ref:N,style:{position:"absolute",...O.style},onPointerDown:Be(e.onPointerDown,M=>{M.button===0&&(M.target.setPointerCapture(M.pointerId),Q.current=v.getBoundingClientRect(),S.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",b.viewport&&(b.viewport.style.scrollBehavior="auto"),$(M))}),onPointerMove:Be(e.onPointerMove,$),onPointerUp:Be(e.onPointerUp,M=>{const I=M.target;I.hasPointerCapture(M.pointerId)&&I.releasePointerCapture(M.pointerId),document.body.style.webkitUserSelect=S.current,b.viewport&&(b.viewport.style.scrollBehavior=""),Q.current=null})})})}),ix="ScrollAreaThumb",jC=p.forwardRef((e,s)=>{const{forceMount:n,...a}=e,r=yC(ix,e.__scopeScrollArea);return t.jsx(tn,{present:n||r.hasThumb,children:t.jsx(gX,{ref:s,...a})})}),gX=p.forwardRef((e,s)=>{const{__scopeScrollArea:n,style:a,...r}=e,l=oa(ix,n),c=yC(ix,n),{onThumbPositionChange:A}=c,f=lt(s,g=>c.onThumbChange(g)),m=p.useRef(void 0),h=em(()=>{m.current&&(m.current(),m.current=void 0)},100);return p.useEffect(()=>{const g=l.viewport;if(g){const O=()=>{if(h(),!m.current){const b=vX(g,A);m.current=b,A()}};return A(),g.addEventListener("scroll",O),()=>g.removeEventListener("scroll",O)}},[l.viewport,h,A]),t.jsx(Ge.div,{"data-state":c.hasThumb?"visible":"hidden",...r,ref:f,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...a},onPointerDownCapture:Be(e.onPointerDownCapture,g=>{const b=g.target.getBoundingClientRect(),v=g.clientX-b.left,w=g.clientY-b.top;c.onThumbPointerDown({x:v,y:w})}),onPointerUp:Be(e.onPointerUp,c.onThumbPointerUp)})});jC.displayName=ix;var Vb="ScrollAreaCorner",QC=p.forwardRef((e,s)=>{const n=oa(Vb,e.__scopeScrollArea),a=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&a?t.jsx(OX,{...e,ref:s}):null});QC.displayName=Vb;var OX=p.forwardRef((e,s)=>{const{__scopeScrollArea:n,...a}=e,r=oa(Vb,n),[l,c]=p.useState(0),[A,f]=p.useState(0),m=!!(l&&A);return ec(r.scrollbarX,()=>{var g;const h=((g=r.scrollbarX)==null?void 0:g.offsetHeight)||0;r.onCornerHeightChange(h),f(h)}),ec(r.scrollbarY,()=>{var g;const h=((g=r.scrollbarY)==null?void 0:g.offsetWidth)||0;r.onCornerWidthChange(h),c(h)}),m?t.jsx(Ge.div,{...a,ref:s,style:{width:l,height:A,position:"absolute",right:r.dir==="ltr"?0:void 0,left:r.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function lx(e){return e?parseInt(e,10):0}function SC(e,s){const n=e/s;return isNaN(n)?0:n}function Jx(e){const s=SC(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,a=(e.scrollbar.size-n)*s;return Math.max(a,18)}function bX(e,s,n,a="ltr"){const r=Jx(n),l=r/2,c=s||l,A=r-c,f=n.scrollbar.paddingStart+c,m=n.scrollbar.size-n.scrollbar.paddingEnd-A,h=n.content-n.viewport,g=a==="ltr"?[0,h]:[h*-1,0];return NC([f,m],g)(e)}function f2(e,s,n="ltr"){const a=Jx(s),r=s.scrollbar.paddingStart+s.scrollbar.paddingEnd,l=s.scrollbar.size-r,c=s.content-s.viewport,A=l-a,f=n==="ltr"?[0,c]:[c*-1,0],m=yO(e,f);return NC([0,c],[0,A])(m)}function NC(e,s){return n=>{if(e[0]===e[1]||s[0]===s[1])return s[0];const a=(s[1]-s[0])/(e[1]-e[0]);return s[0]+a*(n-e[0])}}function BC(e,s){return e>0&&e<s}var vX=(e,s=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},a=0;return(function r(){const l={left:e.scrollLeft,top:e.scrollTop},c=n.left!==l.left,A=n.top!==l.top;(c||A)&&s(),n=l,a=window.requestAnimationFrame(r)})(),()=>window.cancelAnimationFrame(a)};function em(e,s){const n=js(e),a=p.useRef(0);return p.useEffect(()=>()=>window.clearTimeout(a.current),[]),p.useCallback(()=>{window.clearTimeout(a.current),a.current=window.setTimeout(n,s)},[n,s])}function ec(e,s){const n=js(s);Rs(()=>{let a=0;if(e){const r=new ResizeObserver(()=>{cancelAnimationFrame(a),a=window.requestAnimationFrame(n)});return r.observe(e),()=>{window.cancelAnimationFrame(a),r.unobserve(e)}}},[e,n])}var yX=pC,wX=OC,x2=bC,m2=jC,jX=QC;function bt({children:e,className:s,...n}){return t.jsxs(yX,{className:V("overflow-hidden",s),...n,children:[t.jsx(wX,{className:"h-full w-full rounded-[inherit]",children:e}),t.jsx(x2,{orientation:"vertical",className:"flex touch-none select-none p-0.5 transition-colors w-2",children:t.jsx(m2,{className:"relative flex-1 rounded-full bg-surface-5 hover:bg-surface-6"})}),t.jsx(x2,{orientation:"horizontal",className:"flex touch-none select-none flex-col p-0.5 transition-colors h-2",children:t.jsx(m2,{className:"relative flex-1 rounded-full bg-surface-5 hover:bg-surface-6"})}),t.jsx(jX,{})]})}const QX={js:"text-text-2",jsx:"text-text-2",ts:"text-text-2",tsx:"text-text-2",css:"text-text-3",html:"text-text-3",json:"text-text-3",md:"text-text-3",py:"text-text-2",rs:"text-text-3",go:"text-text-2",sh:"text-text-3",yaml:"text-text-3",yml:"text-text-3",sql:"text-text-3",xml:"text-text-3",svg:"text-text-3"};function SX(e){var n;const s=(n=e.split(".").pop())==null?void 0:n.toLowerCase();return QX[s]||"text-text-3"}function h2({defaultValue:e="",placeholder:s,onSubmit:n,onCancel:a,depth:r=0}){const[l,c]=p.useState(e),A=p.useRef(null);p.useEffect(()=>{var m,h;(m=A.current)==null||m.focus(),e&&((h=A.current)==null||h.select())},[e]);function f(m){if(m.key==="Enter"){const h=l.trim();h&&n(h)}m.key==="Escape"&&a()}return t.jsx("div",{className:"flex items-center py-0.5",style:{paddingLeft:r*16+8},children:t.jsx("input",{ref:A,value:l,onChange:m=>c(m.target.value),onKeyDown:f,onBlur:a,placeholder:s,className:"w-full h-5 px-1.5 text-xs bg-surface-0 border border-accent rounded text-text-0 font-sans focus:outline-none"})})}function NX({x:e,y:s,items:n,onClose:a}){const r=p.useRef(null);return p.useEffect(()=>{function l(c){r.current&&!r.current.contains(c.target)&&a()}return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[a]),t.jsx("div",{ref:r,className:"fixed z-50 min-w-[160px] py-1 bg-surface-2 border border-border rounded-lg shadow-xl",style:{left:e,top:s},children:n.map((l,c)=>l.separator?t.jsx("div",{className:"h-px bg-border-subtle my-1"},c):t.jsxs("button",{onClick:()=>{l.action(),a()},className:V("w-full flex items-center gap-2.5 px-3 py-1.5 text-xs font-sans text-left cursor-pointer transition-colors",l.danger?"text-danger hover:bg-danger/10":"text-text-1 hover:bg-surface-5"),children:[l.icon&&t.jsx(l.icon,{size:12,className:l.danger?"text-danger":"text-text-3"}),l.label]},c))})}function BX(e){const s=document.createElement("a");s.href=`/api/files/download?path=${encodeURIComponent(e)}`,s.download=e.split("/").pop(),document.body.appendChild(s),s.click(),s.remove()}function CC({entry:e,depth:s,onOpen:n,expandedDirs:a,onToggleDir:r,onContextMenu:l,dragState:c,onDragStartEntry:A,onDragEndEntry:f,onSetDragOver:m,onDropOnDir:h}){var Q;const g=e.type==="dir",O=a.has(e.path),b=g?"text-accent":SX(e.name),v=(c==null?void 0:c.draggingPath)===e.path,w=g&&(c==null?void 0:c.dragOverPath)===e.path;function N(S){S.preventDefault(),S.stopPropagation(),l==null||l(S,e)}return t.jsxs(t.Fragment,{children:[t.jsxs("button",{draggable:!0,onDragStart:S=>{S.dataTransfer.setData("application/json",JSON.stringify({path:e.path,name:e.name,type:e.type})),S.dataTransfer.effectAllowed="move",A(e.path)},onDragEnd:f,onDragOver:g?S=>{S.preventDefault(),S.stopPropagation(),m(e.path)}:void 0,onDrop:g?S=>h(e.path,S):void 0,onClick:()=>g?r(e.path):n(e.path),onDoubleClick:N,onContextMenu:N,className:V("w-full flex items-center gap-1.5 py-[3px] text-xs font-sans cursor-pointer","hover:bg-surface-4/50 transition-colors text-left",v&&"opacity-50",w&&"bg-accent/15 ring-1 ring-accent/50 rounded"),style:{paddingLeft:s*14+8},children:[g?t.jsxs(t.Fragment,{children:[O?t.jsx(dt,{size:12,className:"text-text-4 flex-shrink-0"}):t.jsx(Ct,{size:12,className:"text-text-4 flex-shrink-0"}),O?t.jsx(Vs,{size:13,className:V(b,"flex-shrink-0")}):t.jsx(Pi,{size:13,className:V(b,"flex-shrink-0")})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-3 flex-shrink-0"}),t.jsx(Eo,{size:13,className:V(b,"flex-shrink-0")})]}),t.jsx("span",{className:"truncate text-text-1",children:e.name})]}),g&&O&&((Q=e.children)==null?void 0:Q.map(S=>t.jsx(CC,{entry:S,depth:s+1,onOpen:n,expandedDirs:a,onToggleDir:r,onContextMenu:l,dragState:c,onDragStartEntry:A,onDragEndEntry:f,onSetDragOver:m,onDropOnDir:h},S.path)))]})}function CX({agentId:e,onCollapse:s}){const n=U(W=>W.agents),a=U(W=>W.openFile),r=U(W=>W.editorActiveFile),l=U(W=>W.createFile),c=U(W=>W.addToast);U(W=>W.fetchTreeDir);const A=U(W=>W.projectDir),f=n.find(W=>W.id===e),m=(f==null?void 0:f.scope)||[];f!=null&&f.workingDir;const h=(f==null?void 0:f.status)==="running"||(f==null?void 0:f.status)==="starting",[g,O]=p.useState([]),[b,v]=p.useState(new Set),[w,N]=p.useState(!0),[Q,S]=p.useState([]),[C,k]=p.useState(null),[F,B]=p.useState(null),[T,$]=p.useState({draggingPath:null,dragOverPath:null}),M=p.useRef(new Set);p.useEffect(()=>{let W=!1;async function Oe(){try{const J=await G.get(`/agents/${encodeURIComponent(e)}/files-touched`);!W&&J.files&&S(J.files.filter(be=>be.exists!==!1&&be.writes>0))}catch{}}Oe();const me=h?setInterval(Oe,5e3):null;return()=>{W=!0,me&&clearInterval(me)}},[e,h]);const I=p.useCallback(async W=>{if(!M.current.has(W)){M.current.add(W);try{return(await G.get(`/files/tree?path=${encodeURIComponent(W)}`)).entries||[]}catch{return[]}}},[]);p.useEffect(()=>{let W=!1;async function Oe(){if(N(!0),M.current=new Set,m.length===0){const be=await I("");W||O(be),N(!1);return}const me=new Set;for(const be of m){const Se=be.split("/");let He="";for(let We=0;We<Se.length&&!Se[We].includes("*");We++)He=He?`${He}/${Se[We]}`:Se[We];He&&me.add(He)}if(me.size===0){const be=await I("");W||O(be),N(!1);return}const J=[];for(const be of me){const Se=await I(be);Se.length>0&&J.push({name:be.split("/").pop(),path:be,type:"dir",children:Se})}W||O(J),N(!1)}return Oe(),()=>{W=!0}},[e,m.join(","),I]);async function se(W){const Oe=new Set(b);if(Oe.has(W))Oe.delete(W);else{Oe.add(W);const me=await I(W);O(J=>kC(J,W,me))}v(Oe)}function H(W){a(W)}function ne(){k({type:"file",onSubmit:async W=>{k(null),await(l==null?void 0:l(W))},onCancel:()=>k(null)})}function K(){k({type:"folder",onSubmit:async W=>{k(null);try{await G.post("/files/mkdir",{path:W}),c("success",`Created ${W}/`),L()}catch(Oe){c("error","Create folder failed",Oe.message)}},onCancel:()=>k(null)})}function L(){M.current=new Set,v(new Set),N(!0),I("").then(W=>{O(W||[]),N(!1)})}function E(){v(new Set)}function q(W){$({draggingPath:W,dragOverPath:null})}function D(){$({draggingPath:null,dragOverPath:null})}function R(W){$(Oe=>Oe.dragOverPath===W?Oe:{...Oe,dragOverPath:W})}async function _(W,Oe){const me=[];for(const J of Oe){const be=await new Promise((Se,He)=>{const We=new FileReader;We.onload=()=>Se(We.result.split(",")[1]),We.onerror=He,We.readAsDataURL(J)});me.push({name:J.name,content:be})}try{const J=await G.post("/files/upload",{dir:W,files:me});c("success",`Uploaded ${J.total} file${J.total!==1?"s":""}`),L()}catch(J){c("error","Upload failed",J.message)}}async function oe(W,Oe){var Se,He;if(Oe.preventDefault(),Oe.stopPropagation(),$({draggingPath:null,dragOverPath:null}),((He=(Se=Oe.dataTransfer)==null?void 0:Se.files)==null?void 0:He.length)>0){_(W,Array.from(Oe.dataTransfer.files));return}let me;try{me=JSON.parse(Oe.dataTransfer.getData("application/json"))}catch{return}if(!(me!=null&&me.path))return;if(me.type==="dir"&&(W===me.path||W.startsWith(me.path+"/"))){c("error","Cannot move a folder into itself");return}if(Z(me.path)===W)return;const be=W?`${W}/${me.name}`:me.name;try{await G.post("/files/rename",{oldPath:me.path,newPath:be}),c("success",`Moved ${me.name} to ${W||"/"}`),L()}catch(We){c("error","Move failed",We.message)}}function Z(W){const Oe=W.split("/");return Oe.pop(),Oe.join("/")}function ee(W,Oe){var me;(me=W.preventDefault)==null||me.call(W),B({x:W.clientX,y:W.clientY,entry:Oe})}function le(W){v(Oe=>new Set([...Oe,W])),k({type:"file",parentPath:W,onSubmit:async Oe=>{const me=W?`${W}/${Oe}`:Oe;try{await G.post("/files/create",{path:me,content:""}),c("success",`Created ${Oe}`),L(),a(me)}catch(J){c("error","Create failed",J.message)}k(null)},onCancel:()=>k(null)})}function ae(W){v(Oe=>new Set([...Oe,W])),k({type:"folder",parentPath:W,onSubmit:async Oe=>{const me=W?`${W}/${Oe}`:Oe;try{await G.post("/files/mkdir",{path:me}),c("success",`Created ${Oe}/`),L()}catch(J){c("error","Create folder failed",J.message)}k(null)},onCancel:()=>k(null)})}function X(W){k({type:"rename",renamePath:W.path,defaultValue:W.name,onSubmit:async Oe=>{const me=Z(W.path),J=me?`${me}/${Oe}`:Oe;try{await G.post("/files/rename",{oldPath:W.path,newPath:J}),c("success",`Renamed to ${Oe}`),L()}catch(be){c("error","Rename failed",be.message)}k(null)},onCancel:()=>k(null)})}async function te(W){const Oe=W.type==="dir"?`folder "${W.name}" and all contents`:`"${W.name}"`;if(window.confirm(`Delete ${Oe}?`))try{await G.delete(`/files/delete?path=${encodeURIComponent(W.path)}`),c("success",`Deleted ${W.name}`),L()}catch(me){c("error","Delete failed",me.message)}}function he(W){const Oe=W.type==="dir",me=[];return Oe?(me.push({icon:Ml,label:"New File",action:()=>le(W.path)}),me.push({icon:BA,label:"New Folder",action:()=>ae(W.path)}),me.push({separator:!0})):(me.push({icon:Zs,label:"Download",action:()=>BX(W.path)}),me.push({separator:!0})),me.push({icon:Fo,label:"Rename",action:()=>X(W)}),me.push({icon:qt,label:"Delete",danger:!0,action:()=>te(W)}),me}return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center gap-0.5 px-2 py-1.5 border-b border-border-subtle flex-shrink-0",children:[t.jsx("span",{className:"flex-1 text-2xs font-semibold text-text-3 uppercase tracking-wider px-1",children:"Files"}),t.jsx("button",{onClick:ne,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New file",children:t.jsx(Ml,{size:12})}),t.jsx("button",{onClick:K,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New folder",children:t.jsx(BA,{size:12})}),t.jsx("button",{onClick:L,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Refresh",children:t.jsx(Ks,{size:12})}),t.jsx("button",{onClick:E,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse all",children:t.jsx(lN,{size:12})}),s&&t.jsx("button",{onClick:s,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse sidebar",children:t.jsx(Px,{size:12})})]}),t.jsx(bt,{className:"flex-1 min-h-0",children:t.jsxs("div",{className:"py-2",children:[C&&t.jsx(h2,{placeholder:C.type==="file"?"filename.ext":"folder-name",onSubmit:C.onSubmit,onCancel:C.onCancel,depth:0}),Q.length>0&&t.jsxs("div",{className:"mb-3",children:[t.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-2xs font-semibold text-text-3 uppercase tracking-wider",children:[t.jsx(IA,{size:10}),"Agent Files"]}),Q.slice(0,15).map(W=>{const Oe=W.path.split("/").pop(),me=W.writes>0;return t.jsxs("button",{onClick:()=>a(W.path),onContextMenu:J=>{J.preventDefault(),J.stopPropagation(),ee(J,{path:W.path,name:Oe,type:"file"})},onDoubleClick:J=>{J.preventDefault(),J.stopPropagation(),ee(J,{path:W.path,name:Oe,type:"file"})},className:V("w-full flex items-center gap-1.5 px-3 py-1 text-xs font-sans cursor-pointer","hover:bg-surface-4/50 transition-colors text-left",r===W.path&&"bg-accent/8 text-accent"),children:[me?t.jsx(IA,{size:12,className:"text-warning flex-shrink-0"}):t.jsx(Hs,{size:12,className:"text-info flex-shrink-0"}),t.jsx("span",{className:"truncate text-text-1 flex-1",children:Oe}),me&&(W.additions!=null||W.deletions!=null?t.jsxs("span",{className:"flex items-center gap-1 text-2xs flex-shrink-0 font-mono",children:[W.additions>0&&t.jsxs("span",{className:"text-success",children:["+",W.additions]}),W.deletions>0&&t.jsxs("span",{className:"text-danger",children:["-",W.deletions]}),!W.additions&&!W.deletions&&t.jsx("span",{className:"text-warning/60",children:"new"})]}):t.jsxs("span",{className:"text-2xs text-warning/60 flex-shrink-0",children:[W.writes," ",W.writes===1?"write":"writes"]}))]},W.path)}),t.jsx("div",{className:"h-px bg-border-subtle mx-3 mt-2"})]}),w?t.jsx("div",{className:"flex items-center justify-center py-8 text-text-4 text-xs font-sans",children:"Loading..."}):g.length===0?t.jsx("div",{className:"flex items-center justify-center py-8 text-text-4 text-xs font-sans",children:"No files in scope"}):t.jsxs("div",{className:"px-1",onDragOver:W=>{W.preventDefault(),T.draggingPath&&R(null)},onDrop:W=>oe("",W),children:[t.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-2xs font-semibold text-text-3 uppercase tracking-wider",children:[t.jsx(Pi,{size:10}),"Scope"]}),g.map(W=>(C==null?void 0:C.renamePath)===W.path?t.jsx(h2,{defaultValue:W.name,onSubmit:C.onSubmit,onCancel:C.onCancel,depth:0},W.path):t.jsx(CC,{entry:W,depth:0,onOpen:H,expandedDirs:b,onToggleDir:se,onContextMenu:ee,dragState:T,onDragStartEntry:q,onDragEndEntry:D,onSetDragOver:R,onDropOnDir:oe},W.path))]})]})}),F&&t.jsx(NX,{x:F.x,y:F.y,items:he(F.entry),onClose:()=>B(null)})]})}function kC(e,s,n){return e.map(a=>a.path===s?{...a,children:n}:a.children?{...a,children:kC(a.children,s,n)}:a)}function kX(e,s){const n=(e||"").split(`
|
|
948
|
+
`),m=f>=0?A.slice(f+1):A;return t.jsx("pre",{className:"my-2 px-3 py-2 rounded-lg bg-surface-0 border border-border-subtle overflow-x-auto",children:t.jsx("code",{className:"text-xs font-mono text-text-1 whitespace-pre",children:m})},c)}return l.startsWith("`")&&l.endsWith("`")?t.jsx("code",{className:"px-1.5 py-0.5 rounded bg-surface-0 text-xs font-mono text-accent",children:l.slice(1,-1)},c):l.startsWith("**")&&l.endsWith("**")?t.jsx("strong",{className:"font-semibold text-text-0",children:l.slice(2,-2)},c):l.startsWith("*")&&l.endsWith("*")?t.jsx("em",{className:"italic",children:l.slice(1,-1)},c):t.jsx("span",{children:l},c)})},a)})})}function rX({msg:e}){return e.role==="user"?t.jsx("div",{className:"flex justify-end animate-chat-fade-in",children:t.jsxs("div",{className:"max-w-[85%]",children:[e.screenshot&&t.jsx("img",{src:e.screenshot,alt:"Screenshot",className:"mb-2 rounded-lg border border-border-subtle max-h-40 object-contain"}),t.jsx("div",{className:"px-4 py-3 rounded-2xl rounded-br-md bg-gradient-to-br from-accent/12 to-accent/6 border border-accent/15",children:t.jsx("p",{className:"text-sm text-text-0 font-sans whitespace-pre-wrap break-words leading-relaxed",children:e.content})}),t.jsx("div",{className:"text-2xs text-text-4 font-sans mt-1 text-right",children:ls(e.timestamp)})]})}):t.jsxs("div",{className:"max-w-[85%] animate-chat-fade-in",children:[t.jsx("div",{className:"rounded-2xl rounded-tl-md bg-surface-1/80 border border-border-subtle px-4 py-3",children:t.jsx("p",{className:"text-sm text-text-1 font-sans whitespace-pre-wrap break-words leading-relaxed",children:t.jsx(aX,{text:e.content})})}),t.jsx("div",{className:"text-2xs text-text-4 font-sans mt-1",children:ls(e.timestamp)})]})}function oX(){const e=U(O=>O.previewChat),s=U(O=>O.previewState),n=U(O=>O.iteratePreview),a=U(O=>O.previewIterating),[r,l]=p.useState(""),c=p.useRef(null),A=p.useRef(null),f=p.useRef(!0);p.useEffect(()=>{const O=c.current;if(!O)return;function b(){f.current=O.scrollHeight-O.scrollTop-O.clientHeight<50}return O.addEventListener("scroll",b),()=>O.removeEventListener("scroll",b)},[]),p.useEffect(()=>{f.current&&c.current&&(c.current.scrollTop=c.current.scrollHeight)},[e==null?void 0:e.length]);const m=p.useCallback(()=>{const O=A.current;O&&(O.style.height="auto",O.style.height=Math.min(O.scrollHeight,160)+"px")},[]);p.useEffect(()=>{m()},[r,m]);function h(){const O=r.trim();!O||a||(n(O),l(""),A.current&&(A.current.style.height="auto"))}function g(O){O.key==="Enter"&&!O.shiftKey&&(O.preventDefault(),h())}return t.jsxs("div",{className:"flex flex-col h-full bg-surface-0",children:[t.jsx("div",{className:"flex-shrink-0 h-10 flex items-center px-4 border-b border-border bg-surface-3",children:t.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Iterate"})}),t.jsx("div",{className:"flex-shrink-0 px-4 py-2 bg-accent/5 border-b border-accent/10",children:t.jsxs("p",{className:"text-2xs text-accent font-sans",children:["Iterating on ",t.jsx("span",{className:"font-semibold",children:s.teamId||"project"})," — changes auto-refresh via hot reload"]})}),t.jsxs("div",{ref:c,className:"flex-1 overflow-y-auto px-4 py-4 space-y-4",children:[e.length===0&&t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"max-w-xs w-full px-5 py-5 bg-surface-1 border border-border-subtle rounded-xl text-center",children:[t.jsx(Po,{size:24,className:"mx-auto text-accent mb-3"}),t.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans mb-3",children:"Preview is live!"}),t.jsxs("ul",{className:"text-left space-y-2 text-2xs text-text-2 font-sans",children:[t.jsxs("li",{className:"flex gap-2",children:[t.jsx(ra,{size:11,className:"text-text-3 mt-0.5 flex-shrink-0"}),t.jsx("span",{children:"Type a message to request changes — your feedback goes to the team planner who routes it to the right agent"})]}),t.jsxs("li",{className:"flex gap-2",children:[t.jsx(oN,{size:11,className:"text-text-3 mt-0.5 flex-shrink-0"}),t.jsx("span",{children:"Use the camera icon to screenshot a specific area and annotate it"})]}),t.jsxs("li",{className:"flex gap-2",children:[t.jsx(Ks,{size:11,className:"text-text-3 mt-0.5 flex-shrink-0"}),t.jsx("span",{children:"Changes auto-refresh via hot module reload"})]})]})]})}),e.map((O,b)=>t.jsx(rX,{msg:O},b)),a&&t.jsx("div",{className:"max-w-[85%] animate-chat-fade-in",children:t.jsx("div",{className:"rounded-2xl rounded-tl-md bg-surface-1/80 border border-border-subtle px-4 py-3",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ie,{size:14,className:"text-accent animate-spin"}),t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Routing to planner..."})]})})})]}),t.jsx("div",{className:"flex-shrink-0 px-3 py-3 border-t border-border",children:t.jsxs("div",{className:"flex items-end gap-2 rounded-2xl bg-surface-1/80 border border-accent/8 px-3 py-2",children:[t.jsx("textarea",{ref:A,value:r,onChange:O=>l(O.target.value),onKeyDown:g,placeholder:"Describe changes...",rows:1,style:{minHeight:"36px"},className:"flex-1 resize-none bg-transparent text-sm text-text-0 font-sans placeholder:text-text-4 focus:outline-none py-1.5"}),t.jsx("button",{onClick:h,disabled:!r.trim()||a,className:V("w-9 h-9 flex items-center justify-center rounded-xl transition-all cursor-pointer flex-shrink-0","disabled:opacity-20 disabled:cursor-not-allowed",r.trim()&&!a?"bg-accent/15 text-accent hover:bg-accent/25 border border-accent/25":"bg-surface-4 text-text-4"),children:t.jsx(ra,{size:16})})]})})]})}function iX(){return t.jsx("div",{className:"flex-1 flex items-center justify-center bg-surface-0",children:t.jsxs("div",{className:"text-center space-y-3",children:[t.jsx(bM,{size:40,className:"mx-auto text-text-4"}),t.jsx("h2",{className:"text-lg font-semibold text-text-1 font-sans",children:"No preview active"}),t.jsx("p",{className:"text-sm text-text-3 font-sans max-w-xs",children:"Build a project with a planner team to see it here."})]})})}const lX={desktop:"100%",tablet:"768px",mobile:"375px"};function cX({embedded:e=!1}){const s=U(m=>m.previewState),n=p.useRef(null),[a,r]=p.useState(0),l=p.useCallback(()=>{r(m=>m+1)},[]);if(!s.url)return t.jsx(iX,{});const c=s.teamId?`/api/preview/${s.teamId}/proxy/`:s.url,A=lX[s.deviceSize]||"100%",f=s.deviceSize==="desktop";return t.jsxs("div",{className:"flex flex-col h-full bg-surface-0 md:flex-row",children:[t.jsxs("div",{className:"flex flex-col flex-[3] min-w-0 min-h-0",children:[t.jsx(kz,{onRefresh:l}),t.jsxs("div",{className:"flex-1 relative overflow-hidden bg-surface-1",children:[s.screenshotMode&&t.jsx(sX,{iframeRef:n}),t.jsx("div",{className:V("h-full transition-all duration-200",f?"w-full":"mx-auto"),style:f?void 0:{width:A,maxWidth:"100%"},children:t.jsx("iframe",{ref:n,src:c,title:"Preview",className:"w-full h-full border-0 bg-white",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"},a)})]})]}),!e&&t.jsx("div",{className:"flex-[2] min-w-[280px] max-w-[480px] border-l border-border md:max-w-none md:flex-[2]",children:t.jsx(oX,{})})]})}var AX=p.createContext(void 0);function Ad(e){const s=p.useContext(AX);return e||s||"ltr"}function yO(e,[s,n]){return Math.min(n,Math.max(s,e))}function dX(e,s){return p.useReducer((n,a)=>s[n][a]??n,e)}var Zb="ScrollArea",[hC]=La(Zb),[uX,oa]=hC(Zb),pC=p.forwardRef((e,s)=>{const{__scopeScrollArea:n,type:a="hover",dir:r,scrollHideDelay:l=600,...c}=e,[A,f]=p.useState(null),[m,h]=p.useState(null),[g,O]=p.useState(null),[b,v]=p.useState(null),[w,N]=p.useState(null),[Q,S]=p.useState(0),[C,k]=p.useState(0),[F,B]=p.useState(!1),[T,$]=p.useState(!1),M=lt(s,se=>f(se)),I=Ad(r);return t.jsx(uX,{scope:n,type:a,dir:I,scrollHideDelay:l,scrollArea:A,viewport:m,onViewportChange:h,content:g,onContentChange:O,scrollbarX:b,onScrollbarXChange:v,scrollbarXEnabled:F,onScrollbarXEnabledChange:B,scrollbarY:w,onScrollbarYChange:N,scrollbarYEnabled:T,onScrollbarYEnabledChange:$,onCornerWidthChange:S,onCornerHeightChange:k,children:t.jsx(Ge.div,{dir:I,...c,ref:M,style:{position:"relative","--radix-scroll-area-corner-width":Q+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});pC.displayName=Zb;var gC="ScrollAreaViewport",OC=p.forwardRef((e,s)=>{const{__scopeScrollArea:n,children:a,nonce:r,...l}=e,c=oa(gC,n),A=p.useRef(null),f=lt(s,A,c.onViewportChange);return t.jsxs(t.Fragment,{children:[t.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),t.jsx(Ge.div,{"data-radix-scroll-area-viewport":"",...l,ref:f,style:{overflowX:c.scrollbarXEnabled?"scroll":"hidden",overflowY:c.scrollbarYEnabled?"scroll":"hidden",...e.style},children:t.jsx("div",{ref:c.onContentChange,style:{minWidth:"100%",display:"table"},children:a})})]})});OC.displayName=gC;var Za="ScrollAreaScrollbar",bC=p.forwardRef((e,s)=>{const{forceMount:n,...a}=e,r=oa(Za,e.__scopeScrollArea),{onScrollbarXEnabledChange:l,onScrollbarYEnabledChange:c}=r,A=e.orientation==="horizontal";return p.useEffect(()=>(A?l(!0):c(!0),()=>{A?l(!1):c(!1)}),[A,l,c]),r.type==="hover"?t.jsx(fX,{...a,ref:s,forceMount:n}):r.type==="scroll"?t.jsx(xX,{...a,ref:s,forceMount:n}):r.type==="auto"?t.jsx(vC,{...a,ref:s,forceMount:n}):r.type==="always"?t.jsx(Gb,{...a,ref:s}):null});bC.displayName=Za;var fX=p.forwardRef((e,s)=>{const{forceMount:n,...a}=e,r=oa(Za,e.__scopeScrollArea),[l,c]=p.useState(!1);return p.useEffect(()=>{const A=r.scrollArea;let f=0;if(A){const m=()=>{window.clearTimeout(f),c(!0)},h=()=>{f=window.setTimeout(()=>c(!1),r.scrollHideDelay)};return A.addEventListener("pointerenter",m),A.addEventListener("pointerleave",h),()=>{window.clearTimeout(f),A.removeEventListener("pointerenter",m),A.removeEventListener("pointerleave",h)}}},[r.scrollArea,r.scrollHideDelay]),t.jsx(tn,{present:n||l,children:t.jsx(vC,{"data-state":l?"visible":"hidden",...a,ref:s})})}),xX=p.forwardRef((e,s)=>{const{forceMount:n,...a}=e,r=oa(Za,e.__scopeScrollArea),l=e.orientation==="horizontal",c=em(()=>f("SCROLL_END"),100),[A,f]=dX("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return p.useEffect(()=>{if(A==="idle"){const m=window.setTimeout(()=>f("HIDE"),r.scrollHideDelay);return()=>window.clearTimeout(m)}},[A,r.scrollHideDelay,f]),p.useEffect(()=>{const m=r.viewport,h=l?"scrollLeft":"scrollTop";if(m){let g=m[h];const O=()=>{const b=m[h];g!==b&&(f("SCROLL"),c()),g=b};return m.addEventListener("scroll",O),()=>m.removeEventListener("scroll",O)}},[r.viewport,l,f,c]),t.jsx(tn,{present:n||A!=="hidden",children:t.jsx(Gb,{"data-state":A==="hidden"?"hidden":"visible",...a,ref:s,onPointerEnter:Be(e.onPointerEnter,()=>f("POINTER_ENTER")),onPointerLeave:Be(e.onPointerLeave,()=>f("POINTER_LEAVE"))})})}),vC=p.forwardRef((e,s)=>{const n=oa(Za,e.__scopeScrollArea),{forceMount:a,...r}=e,[l,c]=p.useState(!1),A=e.orientation==="horizontal",f=em(()=>{if(n.viewport){const m=n.viewport.offsetWidth<n.viewport.scrollWidth,h=n.viewport.offsetHeight<n.viewport.scrollHeight;c(A?m:h)}},10);return ec(n.viewport,f),ec(n.content,f),t.jsx(tn,{present:a||l,children:t.jsx(Gb,{"data-state":l?"visible":"hidden",...r,ref:s})})}),Gb=p.forwardRef((e,s)=>{const{orientation:n="vertical",...a}=e,r=oa(Za,e.__scopeScrollArea),l=p.useRef(null),c=p.useRef(0),[A,f]=p.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),m=SC(A.viewport,A.content),h={...a,sizes:A,onSizesChange:f,hasThumb:m>0&&m<1,onThumbChange:O=>l.current=O,onThumbPointerUp:()=>c.current=0,onThumbPointerDown:O=>c.current=O};function g(O,b){return bX(O,c.current,A,b)}return n==="horizontal"?t.jsx(mX,{...h,ref:s,onThumbPositionChange:()=>{if(r.viewport&&l.current){const O=r.viewport.scrollLeft,b=f2(O,A,r.dir);l.current.style.transform=`translate3d(${b}px, 0, 0)`}},onWheelScroll:O=>{r.viewport&&(r.viewport.scrollLeft=O)},onDragScroll:O=>{r.viewport&&(r.viewport.scrollLeft=g(O,r.dir))}}):n==="vertical"?t.jsx(hX,{...h,ref:s,onThumbPositionChange:()=>{if(r.viewport&&l.current){const O=r.viewport.scrollTop,b=f2(O,A);l.current.style.transform=`translate3d(0, ${b}px, 0)`}},onWheelScroll:O=>{r.viewport&&(r.viewport.scrollTop=O)},onDragScroll:O=>{r.viewport&&(r.viewport.scrollTop=g(O))}}):null}),mX=p.forwardRef((e,s)=>{const{sizes:n,onSizesChange:a,...r}=e,l=oa(Za,e.__scopeScrollArea),[c,A]=p.useState(),f=p.useRef(null),m=lt(s,f,l.onScrollbarXChange);return p.useEffect(()=>{f.current&&A(getComputedStyle(f.current))},[f]),t.jsx(wC,{"data-orientation":"horizontal",...r,ref:m,sizes:n,style:{bottom:0,left:l.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:l.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Jx(n)+"px",...e.style},onThumbPointerDown:h=>e.onThumbPointerDown(h.x),onDragScroll:h=>e.onDragScroll(h.x),onWheelScroll:(h,g)=>{if(l.viewport){const O=l.viewport.scrollLeft+h.deltaX;e.onWheelScroll(O),BC(O,g)&&h.preventDefault()}},onResize:()=>{f.current&&l.viewport&&c&&a({content:l.viewport.scrollWidth,viewport:l.viewport.offsetWidth,scrollbar:{size:f.current.clientWidth,paddingStart:lx(c.paddingLeft),paddingEnd:lx(c.paddingRight)}})}})}),hX=p.forwardRef((e,s)=>{const{sizes:n,onSizesChange:a,...r}=e,l=oa(Za,e.__scopeScrollArea),[c,A]=p.useState(),f=p.useRef(null),m=lt(s,f,l.onScrollbarYChange);return p.useEffect(()=>{f.current&&A(getComputedStyle(f.current))},[f]),t.jsx(wC,{"data-orientation":"vertical",...r,ref:m,sizes:n,style:{top:0,right:l.dir==="ltr"?0:void 0,left:l.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Jx(n)+"px",...e.style},onThumbPointerDown:h=>e.onThumbPointerDown(h.y),onDragScroll:h=>e.onDragScroll(h.y),onWheelScroll:(h,g)=>{if(l.viewport){const O=l.viewport.scrollTop+h.deltaY;e.onWheelScroll(O),BC(O,g)&&h.preventDefault()}},onResize:()=>{f.current&&l.viewport&&c&&a({content:l.viewport.scrollHeight,viewport:l.viewport.offsetHeight,scrollbar:{size:f.current.clientHeight,paddingStart:lx(c.paddingTop),paddingEnd:lx(c.paddingBottom)}})}})}),[pX,yC]=hC(Za),wC=p.forwardRef((e,s)=>{const{__scopeScrollArea:n,sizes:a,hasThumb:r,onThumbChange:l,onThumbPointerUp:c,onThumbPointerDown:A,onThumbPositionChange:f,onDragScroll:m,onWheelScroll:h,onResize:g,...O}=e,b=oa(Za,n),[v,w]=p.useState(null),N=lt(s,M=>w(M)),Q=p.useRef(null),S=p.useRef(""),C=b.viewport,k=a.content-a.viewport,F=js(h),B=js(f),T=em(g,10);function $(M){if(Q.current){const I=M.clientX-Q.current.left,se=M.clientY-Q.current.top;m({x:I,y:se})}}return p.useEffect(()=>{const M=I=>{const se=I.target;(v==null?void 0:v.contains(se))&&F(I,k)};return document.addEventListener("wheel",M,{passive:!1}),()=>document.removeEventListener("wheel",M,{passive:!1})},[C,v,k,F]),p.useEffect(B,[a,B]),ec(v,T),ec(b.content,T),t.jsx(pX,{scope:n,scrollbar:v,hasThumb:r,onThumbChange:js(l),onThumbPointerUp:js(c),onThumbPositionChange:B,onThumbPointerDown:js(A),children:t.jsx(Ge.div,{...O,ref:N,style:{position:"absolute",...O.style},onPointerDown:Be(e.onPointerDown,M=>{M.button===0&&(M.target.setPointerCapture(M.pointerId),Q.current=v.getBoundingClientRect(),S.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",b.viewport&&(b.viewport.style.scrollBehavior="auto"),$(M))}),onPointerMove:Be(e.onPointerMove,$),onPointerUp:Be(e.onPointerUp,M=>{const I=M.target;I.hasPointerCapture(M.pointerId)&&I.releasePointerCapture(M.pointerId),document.body.style.webkitUserSelect=S.current,b.viewport&&(b.viewport.style.scrollBehavior=""),Q.current=null})})})}),ix="ScrollAreaThumb",jC=p.forwardRef((e,s)=>{const{forceMount:n,...a}=e,r=yC(ix,e.__scopeScrollArea);return t.jsx(tn,{present:n||r.hasThumb,children:t.jsx(gX,{ref:s,...a})})}),gX=p.forwardRef((e,s)=>{const{__scopeScrollArea:n,style:a,...r}=e,l=oa(ix,n),c=yC(ix,n),{onThumbPositionChange:A}=c,f=lt(s,g=>c.onThumbChange(g)),m=p.useRef(void 0),h=em(()=>{m.current&&(m.current(),m.current=void 0)},100);return p.useEffect(()=>{const g=l.viewport;if(g){const O=()=>{if(h(),!m.current){const b=vX(g,A);m.current=b,A()}};return A(),g.addEventListener("scroll",O),()=>g.removeEventListener("scroll",O)}},[l.viewport,h,A]),t.jsx(Ge.div,{"data-state":c.hasThumb?"visible":"hidden",...r,ref:f,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...a},onPointerDownCapture:Be(e.onPointerDownCapture,g=>{const b=g.target.getBoundingClientRect(),v=g.clientX-b.left,w=g.clientY-b.top;c.onThumbPointerDown({x:v,y:w})}),onPointerUp:Be(e.onPointerUp,c.onThumbPointerUp)})});jC.displayName=ix;var Vb="ScrollAreaCorner",QC=p.forwardRef((e,s)=>{const n=oa(Vb,e.__scopeScrollArea),a=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&a?t.jsx(OX,{...e,ref:s}):null});QC.displayName=Vb;var OX=p.forwardRef((e,s)=>{const{__scopeScrollArea:n,...a}=e,r=oa(Vb,n),[l,c]=p.useState(0),[A,f]=p.useState(0),m=!!(l&&A);return ec(r.scrollbarX,()=>{var g;const h=((g=r.scrollbarX)==null?void 0:g.offsetHeight)||0;r.onCornerHeightChange(h),f(h)}),ec(r.scrollbarY,()=>{var g;const h=((g=r.scrollbarY)==null?void 0:g.offsetWidth)||0;r.onCornerWidthChange(h),c(h)}),m?t.jsx(Ge.div,{...a,ref:s,style:{width:l,height:A,position:"absolute",right:r.dir==="ltr"?0:void 0,left:r.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function lx(e){return e?parseInt(e,10):0}function SC(e,s){const n=e/s;return isNaN(n)?0:n}function Jx(e){const s=SC(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,a=(e.scrollbar.size-n)*s;return Math.max(a,18)}function bX(e,s,n,a="ltr"){const r=Jx(n),l=r/2,c=s||l,A=r-c,f=n.scrollbar.paddingStart+c,m=n.scrollbar.size-n.scrollbar.paddingEnd-A,h=n.content-n.viewport,g=a==="ltr"?[0,h]:[h*-1,0];return NC([f,m],g)(e)}function f2(e,s,n="ltr"){const a=Jx(s),r=s.scrollbar.paddingStart+s.scrollbar.paddingEnd,l=s.scrollbar.size-r,c=s.content-s.viewport,A=l-a,f=n==="ltr"?[0,c]:[c*-1,0],m=yO(e,f);return NC([0,c],[0,A])(m)}function NC(e,s){return n=>{if(e[0]===e[1]||s[0]===s[1])return s[0];const a=(s[1]-s[0])/(e[1]-e[0]);return s[0]+a*(n-e[0])}}function BC(e,s){return e>0&&e<s}var vX=(e,s=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},a=0;return(function r(){const l={left:e.scrollLeft,top:e.scrollTop},c=n.left!==l.left,A=n.top!==l.top;(c||A)&&s(),n=l,a=window.requestAnimationFrame(r)})(),()=>window.cancelAnimationFrame(a)};function em(e,s){const n=js(e),a=p.useRef(0);return p.useEffect(()=>()=>window.clearTimeout(a.current),[]),p.useCallback(()=>{window.clearTimeout(a.current),a.current=window.setTimeout(n,s)},[n,s])}function ec(e,s){const n=js(s);Rs(()=>{let a=0;if(e){const r=new ResizeObserver(()=>{cancelAnimationFrame(a),a=window.requestAnimationFrame(n)});return r.observe(e),()=>{window.cancelAnimationFrame(a),r.unobserve(e)}}},[e,n])}var yX=pC,wX=OC,x2=bC,m2=jC,jX=QC;function bt({children:e,className:s,...n}){return t.jsxs(yX,{className:V("overflow-hidden",s),...n,children:[t.jsx(wX,{className:"h-full w-full rounded-[inherit]",children:e}),t.jsx(x2,{orientation:"vertical",className:"flex touch-none select-none p-0.5 transition-colors w-2",children:t.jsx(m2,{className:"relative flex-1 rounded-full bg-surface-5 hover:bg-surface-6"})}),t.jsx(x2,{orientation:"horizontal",className:"flex touch-none select-none flex-col p-0.5 transition-colors h-2",children:t.jsx(m2,{className:"relative flex-1 rounded-full bg-surface-5 hover:bg-surface-6"})}),t.jsx(jX,{})]})}const QX={js:"text-text-2",jsx:"text-text-2",ts:"text-text-2",tsx:"text-text-2",css:"text-text-3",html:"text-text-3",json:"text-text-3",md:"text-text-3",py:"text-text-2",rs:"text-text-3",go:"text-text-2",sh:"text-text-3",yaml:"text-text-3",yml:"text-text-3",sql:"text-text-3",xml:"text-text-3",svg:"text-text-3"};function SX(e){var n;const s=(n=e.split(".").pop())==null?void 0:n.toLowerCase();return QX[s]||"text-text-3"}function h2({defaultValue:e="",placeholder:s,onSubmit:n,onCancel:a,depth:r=0}){const[l,c]=p.useState(e),A=p.useRef(null);p.useEffect(()=>{var m,h;(m=A.current)==null||m.focus(),e&&((h=A.current)==null||h.select())},[e]);function f(m){if(m.key==="Enter"){const h=l.trim();h&&n(h)}m.key==="Escape"&&a()}return t.jsx("div",{className:"flex items-center py-0.5",style:{paddingLeft:r*16+8},children:t.jsx("input",{ref:A,value:l,onChange:m=>c(m.target.value),onKeyDown:f,onBlur:a,placeholder:s,className:"w-full h-5 px-1.5 text-xs bg-surface-0 border border-accent rounded text-text-0 font-sans focus:outline-none"})})}function NX({x:e,y:s,items:n,onClose:a}){const r=p.useRef(null);return p.useEffect(()=>{function l(c){r.current&&!r.current.contains(c.target)&&a()}return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[a]),t.jsx("div",{ref:r,className:"fixed z-50 min-w-[160px] py-1 bg-surface-2 border border-border rounded-lg shadow-xl",style:{left:e,top:s},children:n.map((l,c)=>l.separator?t.jsx("div",{className:"h-px bg-border-subtle my-1"},c):t.jsxs("button",{onClick:()=>{l.action(),a()},className:V("w-full flex items-center gap-2.5 px-3 py-1.5 text-xs font-sans text-left cursor-pointer transition-colors",l.danger?"text-danger hover:bg-danger/10":"text-text-1 hover:bg-surface-5"),children:[l.icon&&t.jsx(l.icon,{size:12,className:l.danger?"text-danger":"text-text-3"}),l.label]},c))})}function BX(e,s){const n=document.createElement("a");n.href=`/api/files/download?path=${encodeURIComponent(e)}`,n.download=s?`${e.split("/").pop()}.zip`:e.split("/").pop(),document.body.appendChild(n),n.click(),n.remove()}function CC({entry:e,depth:s,onOpen:n,expandedDirs:a,onToggleDir:r,onContextMenu:l,dragState:c,onDragStartEntry:A,onDragEndEntry:f,onSetDragOver:m,onDropOnDir:h}){var Q;const g=e.type==="dir",O=a.has(e.path),b=g?"text-accent":SX(e.name),v=(c==null?void 0:c.draggingPath)===e.path,w=g&&(c==null?void 0:c.dragOverPath)===e.path;function N(S){S.preventDefault(),S.stopPropagation(),l==null||l(S,e)}return t.jsxs(t.Fragment,{children:[t.jsxs("button",{draggable:!0,onDragStart:S=>{S.dataTransfer.setData("application/json",JSON.stringify({path:e.path,name:e.name,type:e.type})),S.dataTransfer.effectAllowed="move",A(e.path)},onDragEnd:f,onDragOver:S=>{S.preventDefault(),g&&(S.stopPropagation(),m(e.path))},onDrop:S=>h(g?e.path:e.path.includes("/")?e.path.split("/").slice(0,-1).join("/"):"",S),onClick:()=>g?r(e.path):n(e.path),onDoubleClick:N,onContextMenu:N,className:V("w-full flex items-center gap-1.5 py-[3px] text-xs font-sans cursor-pointer","hover:bg-surface-4/50 transition-colors text-left",v&&"opacity-50",w&&"bg-accent/15 ring-1 ring-accent/50 rounded"),style:{paddingLeft:s*14+8},children:[g?t.jsxs(t.Fragment,{children:[O?t.jsx(dt,{size:12,className:"text-text-4 flex-shrink-0"}):t.jsx(Ct,{size:12,className:"text-text-4 flex-shrink-0"}),O?t.jsx(Vs,{size:13,className:V(b,"flex-shrink-0")}):t.jsx(Pi,{size:13,className:V(b,"flex-shrink-0")})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-3 flex-shrink-0"}),t.jsx(Eo,{size:13,className:V(b,"flex-shrink-0")})]}),t.jsx("span",{className:"truncate text-text-1",children:e.name})]}),g&&O&&((Q=e.children)==null?void 0:Q.map(S=>t.jsx(CC,{entry:S,depth:s+1,onOpen:n,expandedDirs:a,onToggleDir:r,onContextMenu:l,dragState:c,onDragStartEntry:A,onDragEndEntry:f,onSetDragOver:m,onDropOnDir:h},S.path)))]})}function CX({agentId:e,onCollapse:s}){const n=U(W=>W.agents),a=U(W=>W.openFile),r=U(W=>W.editorActiveFile),l=U(W=>W.createFile),c=U(W=>W.addToast);U(W=>W.fetchTreeDir);const A=U(W=>W.projectDir),f=n.find(W=>W.id===e),m=(f==null?void 0:f.scope)||[];f!=null&&f.workingDir;const h=(f==null?void 0:f.status)==="running"||(f==null?void 0:f.status)==="starting",[g,O]=p.useState([]),[b,v]=p.useState(new Set),[w,N]=p.useState(!0),[Q,S]=p.useState([]),[C,k]=p.useState(null),[F,B]=p.useState(null),[T,$]=p.useState({draggingPath:null,dragOverPath:null}),M=p.useRef(new Set);p.useEffect(()=>{let W=!1;async function Oe(){try{const J=await G.get(`/agents/${encodeURIComponent(e)}/files-touched`);!W&&J.files&&S(J.files.filter(be=>be.exists!==!1&&be.writes>0))}catch{}}Oe();const me=h?setInterval(Oe,5e3):null;return()=>{W=!0,me&&clearInterval(me)}},[e,h]);const I=p.useCallback(async W=>{if(!M.current.has(W)){M.current.add(W);try{return(await G.get(`/files/tree?path=${encodeURIComponent(W)}`)).entries||[]}catch{return[]}}},[]);p.useEffect(()=>{let W=!1;async function Oe(){if(N(!0),M.current=new Set,m.length===0){const be=await I("");W||O(be),N(!1);return}const me=new Set;for(const be of m){const Se=be.split("/");let He="";for(let We=0;We<Se.length&&!Se[We].includes("*");We++)He=He?`${He}/${Se[We]}`:Se[We];He&&me.add(He)}if(me.size===0){const be=await I("");W||O(be),N(!1);return}const J=[];for(const be of me){const Se=await I(be);Se.length>0&&J.push({name:be.split("/").pop(),path:be,type:"dir",children:Se})}W||O(J),N(!1)}return Oe(),()=>{W=!0}},[e,m.join(","),I]);async function se(W){const Oe=new Set(b);if(Oe.has(W))Oe.delete(W);else{Oe.add(W);const me=await I(W);O(J=>kC(J,W,me))}v(Oe)}function H(W){a(W)}function ne(){k({type:"file",onSubmit:async W=>{k(null),await(l==null?void 0:l(W))},onCancel:()=>k(null)})}function K(){k({type:"folder",onSubmit:async W=>{k(null);try{await G.post("/files/mkdir",{path:W}),c("success",`Created ${W}/`),L()}catch(Oe){c("error","Create folder failed",Oe.message)}},onCancel:()=>k(null)})}function L(){M.current=new Set,v(new Set),N(!0),I("").then(W=>{O(W||[]),N(!1)})}function E(){v(new Set)}function q(W){$({draggingPath:W,dragOverPath:null})}function D(){$({draggingPath:null,dragOverPath:null})}function R(W){$(Oe=>Oe.dragOverPath===W?Oe:{...Oe,dragOverPath:W})}async function _(W,Oe){const me=[];for(const J of Oe){const be=await new Promise((Se,He)=>{const We=new FileReader;We.onload=()=>Se(We.result.split(",")[1]),We.onerror=He,We.readAsDataURL(J)});me.push({name:J.name,content:be})}try{const J=await G.post("/files/upload",{dir:W,files:me});c("success",`Uploaded ${J.total} file${J.total!==1?"s":""}`),L()}catch(J){c("error","Upload failed",J.message)}}async function oe(W,Oe){var Se,He;if(Oe.preventDefault(),Oe.stopPropagation(),$({draggingPath:null,dragOverPath:null}),((He=(Se=Oe.dataTransfer)==null?void 0:Se.files)==null?void 0:He.length)>0){_(W,Array.from(Oe.dataTransfer.files));return}let me;try{me=JSON.parse(Oe.dataTransfer.getData("application/json"))}catch{return}if(!(me!=null&&me.path))return;if(me.type==="dir"&&(W===me.path||W.startsWith(me.path+"/"))){c("error","Cannot move a folder into itself");return}if(Z(me.path)===W)return;const be=W?`${W}/${me.name}`:me.name;try{await G.post("/files/rename",{oldPath:me.path,newPath:be}),c("success",`Moved ${me.name} to ${W||"/"}`),L()}catch(We){c("error","Move failed",We.message)}}function Z(W){const Oe=W.split("/");return Oe.pop(),Oe.join("/")}function ee(W,Oe){var me;(me=W.preventDefault)==null||me.call(W),B({x:W.clientX,y:W.clientY,entry:Oe})}function le(W){v(Oe=>new Set([...Oe,W])),k({type:"file",parentPath:W,onSubmit:async Oe=>{const me=W?`${W}/${Oe}`:Oe;try{await G.post("/files/create",{path:me,content:""}),c("success",`Created ${Oe}`),L(),a(me)}catch(J){c("error","Create failed",J.message)}k(null)},onCancel:()=>k(null)})}function ae(W){v(Oe=>new Set([...Oe,W])),k({type:"folder",parentPath:W,onSubmit:async Oe=>{const me=W?`${W}/${Oe}`:Oe;try{await G.post("/files/mkdir",{path:me}),c("success",`Created ${Oe}/`),L()}catch(J){c("error","Create folder failed",J.message)}k(null)},onCancel:()=>k(null)})}function X(W){k({type:"rename",renamePath:W.path,defaultValue:W.name,onSubmit:async Oe=>{const me=Z(W.path),J=me?`${me}/${Oe}`:Oe;try{await G.post("/files/rename",{oldPath:W.path,newPath:J}),c("success",`Renamed to ${Oe}`),L()}catch(be){c("error","Rename failed",be.message)}k(null)},onCancel:()=>k(null)})}async function te(W){const Oe=W.type==="dir"?`folder "${W.name}" and all contents`:`"${W.name}"`;if(window.confirm(`Delete ${Oe}?`))try{await G.delete(`/files/delete?path=${encodeURIComponent(W.path)}`),c("success",`Deleted ${W.name}`),L()}catch(me){c("error","Delete failed",me.message)}}function he(W){const Oe=W.type==="dir",me=[];return Oe&&(me.push({icon:Ml,label:"New File",action:()=>le(W.path)}),me.push({icon:BA,label:"New Folder",action:()=>ae(W.path)})),me.push({icon:Zs,label:Oe?"Download as ZIP":"Download",action:()=>BX(W.path,Oe)}),me.push({separator:!0}),me.push({icon:Fo,label:"Rename",action:()=>X(W)}),me.push({icon:qt,label:"Delete",danger:!0,action:()=>te(W)}),me}return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center gap-0.5 px-2 py-1.5 border-b border-border-subtle flex-shrink-0",children:[t.jsx("span",{className:"flex-1 text-2xs font-semibold text-text-3 uppercase tracking-wider px-1",children:"Files"}),t.jsx("button",{onClick:ne,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New file",children:t.jsx(Ml,{size:12})}),t.jsx("button",{onClick:K,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New folder",children:t.jsx(BA,{size:12})}),t.jsx("button",{onClick:L,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Refresh",children:t.jsx(Ks,{size:12})}),t.jsx("button",{onClick:E,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse all",children:t.jsx(lN,{size:12})}),s&&t.jsx("button",{onClick:s,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse sidebar",children:t.jsx(Px,{size:12})})]}),t.jsx(bt,{className:"flex-1 min-h-0",children:t.jsxs("div",{className:"py-2 min-h-full",onDragOver:W=>{W.preventDefault(),T.draggingPath&&R(null)},onDrop:W=>oe("",W),children:[C&&t.jsx(h2,{placeholder:C.type==="file"?"filename.ext":"folder-name",onSubmit:C.onSubmit,onCancel:C.onCancel,depth:0}),Q.length>0&&t.jsxs("div",{className:"mb-3",children:[t.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-2xs font-semibold text-text-3 uppercase tracking-wider",children:[t.jsx(IA,{size:10}),"Agent Files"]}),Q.slice(0,15).map(W=>{const Oe=W.path.split("/").pop(),me=W.writes>0;return t.jsxs("button",{onClick:()=>a(W.path),onContextMenu:J=>{J.preventDefault(),J.stopPropagation(),ee(J,{path:W.path,name:Oe,type:"file"})},onDoubleClick:J=>{J.preventDefault(),J.stopPropagation(),ee(J,{path:W.path,name:Oe,type:"file"})},className:V("w-full flex items-center gap-1.5 px-3 py-1 text-xs font-sans cursor-pointer","hover:bg-surface-4/50 transition-colors text-left",r===W.path&&"bg-accent/8 text-accent"),children:[me?t.jsx(IA,{size:12,className:"text-warning flex-shrink-0"}):t.jsx(Hs,{size:12,className:"text-info flex-shrink-0"}),t.jsx("span",{className:"truncate text-text-1 flex-1",children:Oe}),me&&(W.additions!=null||W.deletions!=null?t.jsxs("span",{className:"flex items-center gap-1 text-2xs flex-shrink-0 font-mono",children:[W.additions>0&&t.jsxs("span",{className:"text-success",children:["+",W.additions]}),W.deletions>0&&t.jsxs("span",{className:"text-danger",children:["-",W.deletions]}),!W.additions&&!W.deletions&&t.jsx("span",{className:"text-warning/60",children:"new"})]}):t.jsxs("span",{className:"text-2xs text-warning/60 flex-shrink-0",children:[W.writes," ",W.writes===1?"write":"writes"]}))]},W.path)}),t.jsx("div",{className:"h-px bg-border-subtle mx-3 mt-2"})]}),w?t.jsx("div",{className:"flex items-center justify-center py-8 text-text-4 text-xs font-sans",children:"Loading..."}):g.length===0?t.jsx("div",{className:"flex items-center justify-center py-8 text-text-4 text-xs font-sans",children:"No files in scope"}):t.jsxs("div",{className:"px-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-2xs font-semibold text-text-3 uppercase tracking-wider",children:[t.jsx(Pi,{size:10}),"Scope"]}),g.map(W=>(C==null?void 0:C.renamePath)===W.path?t.jsx(h2,{defaultValue:W.name,onSubmit:C.onSubmit,onCancel:C.onCancel,depth:0},W.path):t.jsx(CC,{entry:W,depth:0,onOpen:H,expandedDirs:b,onToggleDir:se,onContextMenu:ee,dragState:T,onDragStartEntry:q,onDragEndEntry:D,onSetDragOver:R,onDropOnDir:oe},W.path))]})]})}),F&&t.jsx(NX,{x:F.x,y:F.y,items:he(F.entry),onClose:()=>B(null)})]})}function kC(e,s,n){return e.map(a=>a.path===s?{...a,children:n}:a.children?{...a,children:kC(a.children,s,n)}:a)}function kX(e,s){const n=(e||"").split(`
|
|
949
949
|
`),a=(s||"").split(`
|
|
950
950
|
`),r=[];let l=0,c=0;for(;l<n.length||c<a.length;)if(l>=n.length)r.push({type:"add",lineNum:c+1,text:a[c]}),c++;else if(c>=a.length)r.push({type:"del",lineNum:l+1,text:n[l]}),l++;else if(n[l]===a[c])r.push({type:"same",lineNum:c+1,origLineNum:l+1,text:a[c]}),l++,c++;else{let A=-1,f=-1;const m=Math.min(10,Math.max(n.length-l,a.length-c));for(let h=1;h<=m;h++)if(c+h<a.length&&n[l]===a[c+h]){f=c+h;break}for(let h=1;h<=m;h++)if(l+h<n.length&&n[l+h]===a[c]){A=l+h;break}if(f>=0&&(A<0||f-c<=A-l))for(;c<f;)r.push({type:"add",lineNum:c+1,text:a[c]}),c++;else if(A>=0)for(;l<A;)r.push({type:"del",lineNum:l+1,text:n[l]}),l++;else r.push({type:"del",lineNum:l+1,text:n[l]}),r.push({type:"add",lineNum:c+1,text:a[c]}),l++,c++}return r}function TX(e){const s=[];let n=0;for(;n<e.length;){const a=e[n];a.type==="same"?(s.push({left:{num:a.origLineNum,text:a.text,type:"same"},right:{num:a.lineNum,text:a.text,type:"same"}}),n++):a.type==="del"?n+1<e.length&&e[n+1].type==="add"?(s.push({left:{num:a.lineNum,text:a.text,type:"mod"},right:{num:e[n+1].lineNum,text:e[n+1].text,type:"mod"}}),n+=2):(s.push({left:{num:a.lineNum,text:a.text,type:"del"},right:{num:"",text:"",type:"empty"}}),n++):(s.push({left:{num:"",text:"",type:"empty"},right:{num:a.lineNum,text:a.text,type:"add"}}),n++)}return s}function UX({diffLines:e}){return t.jsx("div",{className:"font-mono text-xs leading-5 overflow-x-auto",children:e.map((s,n)=>t.jsxs("div",{className:V("flex",s.type==="add"&&"bg-success/15",s.type==="del"&&"bg-danger/15"),children:[t.jsx("span",{className:V("w-12 flex-shrink-0 text-right pr-3 select-none",s.type==="add"?"text-success/60":s.type==="del"?"text-danger/60":"text-text-4"),children:s.type==="add"?"":s.origLineNum||s.lineNum}),t.jsx("span",{className:V("w-12 flex-shrink-0 text-right pr-3 select-none",s.type==="add"?"text-success/60":s.type==="del"?"text-danger/60":"text-text-4"),children:s.type==="del"?"":s.lineNum}),t.jsx("span",{className:V("w-5 flex-shrink-0 text-center select-none font-bold",s.type==="add"?"text-success":s.type==="del"?"text-danger":"text-text-4"),children:s.type==="add"?"+":s.type==="del"?"-":" "}),t.jsx("span",{className:V("whitespace-pre px-2 flex-1",s.type==="add"?"text-success":s.type==="del"?"text-danger":"text-text-1"),children:s.text})]},n))})}function EX({pairs:e}){return t.jsx("div",{className:"font-mono text-xs leading-5 overflow-x-auto",children:e.map((s,n)=>t.jsxs("div",{className:"flex",children:[t.jsxs("div",{className:V("flex flex-1 min-w-0 border-r border-border-subtle",s.left.type==="del"&&"bg-danger/15",s.left.type==="mod"&&"bg-warning/10",s.left.type==="empty"&&"bg-surface-2/50"),children:[t.jsx("span",{className:V("w-10 flex-shrink-0 text-right pr-2 select-none",s.left.type==="del"||s.left.type==="mod"?"text-danger/60":"text-text-4"),children:s.left.num}),t.jsx("span",{className:V("whitespace-pre px-1",s.left.type==="del"?"text-danger":s.left.type==="mod"?"text-warning":s.left.type==="empty"?"":"text-text-1"),children:s.left.text})]}),t.jsxs("div",{className:V("flex flex-1 min-w-0",s.right.type==="add"&&"bg-success/15",s.right.type==="mod"&&"bg-success/10",s.right.type==="empty"&&"bg-surface-2/50"),children:[t.jsx("span",{className:V("w-10 flex-shrink-0 text-right pr-2 select-none",s.right.type==="add"||s.right.type==="mod"?"text-success/60":"text-text-4"),children:s.right.num}),t.jsx("span",{className:V("whitespace-pre px-1",s.right.type==="add"||s.right.type==="mod"?"text-success":s.right.type==="empty"?"":"text-text-1"),children:s.right.text})]})]},n))})}function TC({filePath:e,gitDiffData:s,originalContent:n,modifiedContent:a}){const r=U(w=>w.editorFiles[e]),l=U(w=>w.workspaceSnapshots[e]),[c,A]=p.useState("side-by-side"),[f,m]=p.useState(null);p.useEffect(()=>{(s==null?void 0:s.original)!==void 0?m(s.original):n===void 0&&!l&&!(r!=null&&r.originalContent)&&G.get(`/files/git-diff?path=${encodeURIComponent(e)}`).then(w=>{(w==null?void 0:w.original)!==void 0&&m(w.original)}).catch(()=>{})},[e,s,l,r==null?void 0:r.originalContent,n]);const h=n??f??l??(r==null?void 0:r.originalContent)??"",g=a??(r==null?void 0:r.content)??"",O=p.useMemo(()=>kX(h,g),[h,g]),b=p.useMemo(()=>TX(O),[O]),v=p.useMemo(()=>{let w=0,N=0;for(const Q of O)Q.type==="add"&&w++,Q.type==="del"&&N++;return{adds:w,dels:N}},[O]);return!h&&!g?t.jsx("div",{className:"flex items-center justify-center h-full text-text-4 text-xs font-sans",children:"No file loaded"}):h===g&&!s?t.jsx("div",{className:"flex items-center justify-center h-full text-text-4 text-xs font-sans",children:"No changes detected"}):t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 bg-surface-1 border-b border-border-subtle text-xs font-sans flex-shrink-0",children:[t.jsx("span",{className:"text-text-2 flex-1",children:e.split("/").pop()}),t.jsxs("span",{className:"text-success",children:["+",v.adds]}),t.jsxs("span",{className:"text-danger",children:["-",v.dels]}),t.jsx("div",{className:"w-px h-4 bg-border-subtle"}),t.jsxs("div",{className:"flex items-center gap-0.5 bg-surface-2 rounded-md p-0.5",children:[t.jsxs("button",{onClick:()=>A("side-by-side"),className:V("flex items-center gap-1 px-2 py-0.5 text-2xs rounded cursor-pointer transition-colors",c==="side-by-side"?"bg-surface-4 text-text-0":"text-text-3 hover:text-text-1"),children:[t.jsx(sR,{size:10})," Split"]}),t.jsxs("button",{onClick:()=>A("unified"),className:V("flex items-center gap-1 px-2 py-0.5 text-2xs rounded cursor-pointer transition-colors",c==="unified"?"bg-surface-4 text-text-0":"text-text-3 hover:text-text-1"),children:[t.jsx(BI,{size:10})," Unified"]})]})]}),t.jsx(bt,{className:"flex-1",children:c==="side-by-side"?t.jsx(EX,{pairs:b}):t.jsx(UX,{diffLines:O})})]})}function PX(e){return e==="added"?t.jsx(Ml,{size:12,className:"text-success"}):e==="deleted"?t.jsx(pR,{size:12,className:"text-danger"}):t.jsx(IA,{size:12,className:"text-warning"})}function FX({agentId:e,onBack:s}){const n=U(R=>R.workspaceAgentId),a=e||n,r=U(R=>R.agents),l=U(R=>R.instructAgent),c=U(R=>R.setEditorViewMode),A=r.find(R=>R.id===a),f=(A==null?void 0:A.status)==="running"||(A==null?void 0:A.status)==="starting",[m,h]=p.useState([]),[g,O]=p.useState(!0),[b,v]=p.useState(null),[w,N]=p.useState({}),[Q,S]=p.useState({}),[C,k]=p.useState({}),[F,B]=p.useState(null),[T,$]=p.useState(""),M=p.useCallback(async()=>{O(!0);try{const R=a?`/files/git-diff?agentId=${encodeURIComponent(a)}`:"/files/git-diff",oe=((await G.get(R)).diffs||[]).filter(Z=>!Z.path.endsWith("/"));h(oe)}catch{h([])}O(!1)},[a]);p.useEffect(()=>{M()},[M]);async function I(R){if(!w[R])try{const[_,oe]=await Promise.all([G.get(`/files/git-show?path=${encodeURIComponent(R)}`),G.get(`/files/read?path=${encodeURIComponent(R)}`).catch(()=>null)]);N(Z=>({...Z,[R]:{original:_.content??"",modified:(oe==null?void 0:oe.content)??""}}))}catch{N(_=>({..._,[R]:{original:"",modified:"",error:!0}}))}}function se(R){b===R?v(null):(v(R),I(R))}async function H(R){S(_=>({..._,[R]:!0}));try{await G.post("/files/revert",{path:R}),h(_=>_.filter(oe=>oe.path!==R)),N(_=>{const oe={..._};return delete oe[R],oe}),b===R&&v(null)}catch(_){U.getState().addToast("error","Failed to revert",_.message)}S(_=>({..._,[R]:!1}))}async function ne(){for(const R of m)await H(R.path)}function K(R){T.trim()&&(k(_=>({..._,[R]:T.trim()})),$(""),B(null))}async function L(){if(!a)return;const R=m.filter(_=>C[_.path]).map(_=>`${_.path}: ${C[_.path]}`);R.length!==0&&(await l(a,`Code review feedback:
|
|
951
951
|
${R.join(`
|
|
@@ -979,7 +979,7 @@ ${R.join(`
|
|
|
979
979
|
[&::-moz-range-thumb]:bg-accent [&::-moz-range-thumb]:border-none
|
|
980
980
|
[&::-moz-range-thumb]:shadow-[0_0_0_2px_var(--color-surface-1)]
|
|
981
981
|
[&::-moz-range-track]:bg-transparent
|
|
982
|
-
disabled:cursor-not-allowed`})]}),t.jsx("span",{className:"text-[11px] text-accent font-mono font-medium w-9 text-right shrink-0 tabular-nums",children:O})]})}const _J={agentNode:dB,rootNode:uB},Sg=220,Ng=82,xf=260,mf=130,ao=4,zs="__groove_root__";function SA(e){if(!e)return{};try{return JSON.parse(localStorage.getItem(`groove:nodePositions:${e}`)||"{}")}catch{return{}}}function f4(){let e=!1;for(const s of["groove:chatHistory","groove:activityLog"])localStorage.getItem(s)!==null&&(localStorage.removeItem(s),e=!0);return e}function xQ(e,s){if(!e)return;const n=`groove:nodePositions:${e}`,a=JSON.stringify(s);try{localStorage.setItem(n,a);return}catch{}if(f4())try{localStorage.setItem(n,a)}catch{}}function x4(){try{return JSON.parse(localStorage.getItem("groove:roleLayout")||"{}")}catch{return{}}}function zJ(e){const s="groove:roleLayout",n=JSON.stringify(e);try{localStorage.setItem(s,n);return}catch{}if(f4())try{localStorage.setItem(s,n)}catch{}}function m4(){try{return JSON.parse(localStorage.getItem("groove:teamViewports")||"{}")}catch{return{}}}function LJ(e,s){try{const n=m4();n[e]=s,localStorage.setItem("groove:teamViewports",JSON.stringify(n))}catch{}}function DJ(e,s){const n=e.filter(c=>{var A;return c.teamId===s&&!((A=c.metadata)!=null&&A.scheduled)});return n.length===0?"idle":n.some(c=>c.status==="running"||c.status==="starting")?"working":n.every(c=>c.status==="completed")?"completed":n.some(c=>c.status==="crashed")?"crashed":"idle"}function HJ(){const e=U(E=>E.teams),s=U(E=>E.activeTeamId),n=U(E=>E.agents),a=U(E=>E.switchTeam),r=U(E=>E.createTeam),l=U(E=>E.deleteTeamPermanently),c=U(E=>E.renameTeam),A=U(E=>E.cloneTeam),f=U(E=>E.reorderTeams),m=U(E=>E.addToast),[h,g]=p.useState(!1),[O,b]=p.useState(""),[v,w]=p.useState(null),[N,Q]=p.useState(""),S=p.useRef(!1),[C,k]=p.useState(null),[F,B]=p.useState(null),T=p.useRef(null),[$,M]=p.useState(!1),[I,se]=p.useState(!1),H=p.useCallback(()=>{const E=T.current;E&&(M(E.scrollLeft>0),se(E.scrollLeft+E.clientWidth<E.scrollWidth-1))},[]);p.useEffect(()=>{const E=T.current;if(!E)return;H(),E.addEventListener("scroll",H);const q=new ResizeObserver(H);return q.observe(E),()=>{E.removeEventListener("scroll",H),q.disconnect()}},[H,e.length]);function ne(){const E=O.trim();!E||S.current||(S.current=!0,b(""),g(!1),r(E).finally(()=>{S.current=!1,setTimeout(()=>{T.current&&T.current.scrollTo({left:T.current.scrollWidth,behavior:"smooth"})},100)}))}function K(E){w(E.id),Q(E.name)}function L(){const E=N.trim();if(!E||!v){w(null);return}c(v,E),w(null)}return t.jsxs("div",{className:"flex items-end px-0 pt-0 pb-0 bg-surface-1 border-b border-border gap-0 flex-shrink-0 overflow-hidden",children:[$&&t.jsx("button",{onClick:()=>{var E;return(E=T.current)==null?void 0:E.scrollBy({left:-300,behavior:"smooth"})},className:"w-6 h-9 flex items-center justify-center bg-accent/15 text-accent hover:bg-accent/25 transition-colors flex-shrink-0 cursor-pointer",children:t.jsx(Ei,{size:14})}),t.jsxs("div",{ref:T,className:"flex items-end flex-1 min-w-0 overflow-x-auto gap-0",style:{scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch"},children:[e.map(E=>{const q=n.filter(oe=>{var Z;return oe.teamId===E.id&&!((Z=oe.metadata)!=null&&Z.scheduled)}).length,D=E.id===s,R=v===E.id,_=n.filter(oe=>{var Z;return oe.teamId===E.id&&!((Z=oe.metadata)!=null&&Z.scheduled)&&(oe.status==="running"||oe.status==="starting")}).length;return t.jsxs(gv,{children:[t.jsx(Ov,{asChild:!0,children:t.jsxs("div",{draggable:!R,onDragStart:oe=>{k(E.id),oe.dataTransfer.effectAllowed="move",oe.dataTransfer.setData("text/plain","")},onDragEnd:()=>{k(null),B(null)},onDragOver:oe=>{oe.preventDefault(),oe.dataTransfer.dropEffect="move",C&&C!==E.id&&B(E.id)},onDragLeave:()=>{F===E.id&&B(null)},onDrop:oe=>{if(oe.preventDefault(),!C||C===E.id)return;const Z=e.findIndex(le=>le.id===C),ee=e.findIndex(le=>le.id===E.id);Z!==-1&&ee!==-1&&f(Z,ee),k(null),B(null)},onClick:()=>!R&&a(E.id),onDoubleClick:()=>K(E),className:V("relative flex items-center gap-2 px-3 h-9 text-xs font-sans cursor-pointer select-none transition-colors flex-shrink-0",D?"text-text-0 font-semibold border-x border-x-[#242830] bg-[#242830]":"text-text-3 hover:text-text-1 hover:bg-surface-3/50",C===E.id&&"opacity-40",F===E.id&&C!==E.id&&"border-l-2 !border-l-accent"),children:[D&&t.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-accent",style:{height:"0.5px"}}),(()=>{const oe=DJ(n,E.id),Z=oe==="working"||oe==="completed"?"text-green-400":oe==="crashed"?"text-red-400":D?"text-accent":"text-text-4";return t.jsxs("span",{className:"relative flex-shrink-0",children:[t.jsx(Fn,{size:13,className:V(Z,oe==="working"&&"animate-pulse")}),oe==="working"&&t.jsx("span",{className:"absolute -top-0.5 -right-0.5 w-1.5 h-1.5 rounded-full bg-green-400 animate-pulse"})]})})(),R?t.jsx("input",{value:N,onChange:oe=>Q(oe.target.value),onKeyDown:oe=>{oe.key==="Enter"&&L(),oe.key==="Escape"&&w(null)},onBlur:L,className:"h-5 w-24 px-1.5 text-xs bg-surface-0 border border-accent rounded text-text-0 font-sans focus:outline-none",autoFocus:!0,onClick:oe=>oe.stopPropagation()}):t.jsx("span",{className:"truncate max-w-[120px]",children:E.name}),q>0&&!R&&t.jsx("span",{className:V("flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full text-2xs font-mono font-semibold",_>0?"bg-accent/15 text-accent":"bg-surface-4 text-text-3"),children:q}),D&&t.jsx("div",{className:"absolute bottom-[-1px] left-0 right-0 h-px bg-[#242830]"})]})}),t.jsxs(bv,{children:[t.jsxs(ma,{onSelect:()=>K(E),children:[t.jsx(Fo,{size:12})," Rename"]}),t.jsxs(ma,{onSelect:()=>A(E.id),children:[t.jsx(za,{size:12})," Clone"]}),t.jsx(vv,{}),t.jsxs(ma,{danger:!0,onSelect:()=>{if(n.filter(Z=>Z.teamId===E.id).some(Z=>Z.status==="running"||Z.status==="starting")){m("error","Stop running agents first");return}l(E.id)},children:[t.jsx(qt,{size:12})," Delete"]})]})]},E.id)}),h?t.jsxs("div",{className:"flex items-center gap-1.5 px-3 h-9 flex-shrink-0",children:[t.jsx("input",{value:O,onChange:E=>b(E.target.value),onKeyDown:E=>{E.key==="Enter"&&ne(),E.key==="Escape"&&(g(!1),b(""))},placeholder:"Team name...",className:"h-5 w-28 px-1.5 text-xs bg-surface-0 border border-border-subtle rounded text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),t.jsx("button",{onClick:ne,disabled:!O.trim(),className:"p-1 rounded text-accent hover:bg-accent/10 cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",children:t.jsx(Je,{size:12})}),t.jsx("button",{onClick:()=>{g(!1),b("")},className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(Ze,{size:12})})]}):t.jsx("button",{onClick:()=>g(!0),className:"flex items-center justify-center w-6 h-6 my-auto mx-2 rounded-full bg-accent/15 text-accent hover:bg-accent/25 cursor-pointer transition-colors flex-shrink-0",title:"New team",children:t.jsx(At,{size:12})})]}),I&&t.jsx("button",{onClick:()=>{var E;return(E=T.current)==null?void 0:E.scrollBy({left:300,behavior:"smooth"})},className:"w-6 h-9 flex items-center justify-center bg-accent/15 text-accent hover:bg-accent/25 transition-colors flex-shrink-0 cursor-pointer",children:t.jsx(Ct,{size:14})})]})}function XJ(){const e=U(K=>K.agents),s=U(K=>K.activeTeamId),n=U(K=>K.tokenTimeline),a=U(K=>K.selectAgent),r=U(K=>K.closeDetail),l=p.useRef([]),c=p.useMemo(()=>{const K=e.filter(E=>{var q;return E.teamId===s&&!((q=E.metadata)!=null&&q.scheduled)}).sort((E,q)=>(E.name||E.id).localeCompare(q.name||q.id)),L=l.current;return L.length===K.length&&L.every((E,q)=>E.id===K[q].id&&E.status===K[q].status&&E.name===K[q].name&&E.model===K[q].model&&E.tokensUsed===K[q].tokensUsed&&E.contextUsage===K[q].contextUsage)?L:(l.current=K,K)},[e,s]),A=p.useRef(SA(s)),f=p.useRef(s);f.current!==s&&(f.current=s,A.current=SA(s));const{fitView:m,setViewport:h}=dE(),[g,O]=p.useState(0),b=p.useRef(s),v=p.useMemo(()=>{const K=A.current,L=x4(),E=c.filter(ee=>ee.status==="running").length,q=K[zs]||L[zs]||{x:0,y:0},D=[{id:zs,type:"rootNode",position:q,data:{agentCount:c.length,runningCount:E},draggable:!0,selectable:!1}],R=new Set,_=(ee,le)=>`${Math.round(ee/100)},${Math.round(le/100)}`;R.add(_(q.x,q.y));const oe=[];c.forEach(ee=>{const le=ee.name||ee.id;if(K[le]){const ae=K[le];R.add(_(ae.x,ae.y)),D.push({id:ee.id,type:"agentNode",position:ae,data:{agent:ee,timeline:n[ee.id]||[]},draggable:!0,selectable:!0})}else oe.push(ee)});const Z=new Map;return oe.forEach((ee,le)=>{const ae=ee.role||"agent",X=Z.get(ae)||0;Z.set(ae,X+1);const te=X===0?ae:`${ae}-${X}`;let he;if(L[te])he={...L[te]};else{const W=Math.floor(le/ao),Oe=le%ao;he={x:-((Math.min(oe.length-W*ao,ao)-1)*xf)/2+Oe*xf,y:mf+W*mf}}for(;R.has(_(he.x,he.y));)he={x:he.x,y:he.y+mf};R.add(_(he.x,he.y)),ee.name||ee.id,D.push({id:ee.id,type:"agentNode",position:he,data:{agent:ee,timeline:n[ee.id]||[]},draggable:!0,selectable:!0})}),D},[c,n,s]);p.useEffect(()=>{const K={};v.forEach(L=>{var q,D;const E=L.id===zs?zs:((D=(q=L.data)==null?void 0:q.agent)==null?void 0:D.name)||L.id;A.current[E]||(K[E]=L.position)}),Object.keys(K).length>0&&(Object.assign(A.current,K),xQ(s,A.current))},[v,s]);const w=p.useMemo(()=>{const K=SA(s),L=K[zs]||{x:0,y:0};return c.map((E,q)=>{const D=E.name||E.id,R=Math.floor(q/ao),_=q%ao,Z=-((Math.min(c.length-R*ao,ao)-1)*xf)/2,ee=K[D]||{x:Z+_*xf,y:140+R*mf},le=ee.x+Sg/2-L.x,ae=ee.y+Ng/2-L.y;let X,te;return Math.abs(ae)>Math.abs(le)?(X=ae>0?"bottom":"top",te=ae>0?"top":"bottom"):(X=le>0?"right":"left",te=le>0?"left":"right"),{id:`e-${zs}-${E.id}`,source:zs,target:E.id,sourceHandle:X,targetHandle:te,type:"default",animated:E.status==="running"}})},[c,s]),[N,Q,S]=uE(v),[C,k,F]=fE(w),B=p.useRef(new Set);p.useEffect(()=>{Q(K=>{const L=new Map(K.map(E=>[E.id,E]));return v.map(E=>{const q=L.get(E.id);return q?{...q,data:E.data}:E})})},[v,Q]),p.useEffect(()=>{k(()=>{const K=N.find(E=>E.id===zs);if(!K)return w;const L=K.position;return w.map(E=>{const q=N.find(Z=>Z.id===E.target);if(!q)return E;const D=q.position.x+Sg/2-L.x,R=q.position.y+Ng/2-L.y;let _,oe;return Math.abs(R)>Math.abs(D)?(_=R>0?"bottom":"top",oe=R>0?"top":"bottom"):(_=D>0?"right":"left",oe=D>0?"left":"right"),{...E,sourceHandle:_,targetHandle:oe}})})},[w,N,k]);const T=c.map(K=>K.id).join(","),$=p.useRef(null);p.useEffect(()=>{if(b.current!==s){b.current=s,B.current=new Set(c.map(q=>q.id)),O(c.length);const E=m4()[s];E?h(E,{duration:200}):c.length>0&&m({padding:.3,maxZoom:1.2,duration:200});return}const K=new Set(c.map(E=>E.id)),L=c.length>0&&[...K].some(E=>!B.current.has(E));B.current=K,g===0&&c.length>0?m({padding:.3,maxZoom:1.2,duration:0}):L&&(clearTimeout($.current),$.current=setTimeout(()=>m({padding:.3,maxZoom:1.2,duration:300}),500)),O(c.length)},[T,g,m,s,h]);const M=p.useCallback((K,L)=>{LJ(s,L)},[s]),I=p.useCallback((K,L)=>{L.id!==zs&&a(L.id)},[a]),se=p.useCallback(()=>{r()},[r]),H=p.useCallback((K,L)=>{const E=N.find(D=>D.id===zs);if(!E)return;const q=E.position;k(D=>D.map(R=>{const _=R.source===L.id,oe=R.target===L.id;if(!_&&!oe)return R;const Z=L.position,ee=Z.x+Sg/2-q.x,le=Z.y+Ng/2-q.y;let ae,X;return Math.abs(le)>Math.abs(ee)?(ae=le>0?"bottom":"top",X=le>0?"top":"bottom"):(ae=ee>0?"right":"left",X=ee>0?"left":"right"),{...R,sourceHandle:ae,targetHandle:X}}))},[N,k]),ne=p.useCallback((K,L)=>{var D,R;const E=L.id===zs?zs:((R=(D=L.data)==null?void 0:D.agent)==null?void 0:R.name)||L.id;A.current[E]=L.position;const q=SA(s);q[E]=L.position,xQ(s,q)},[s]);return t.jsx(xE,{nodes:N,edges:C,nodeTypes:_J,onNodesChange:S,onEdgesChange:F,onNodeClick:I,onPaneClick:se,onNodeDrag:H,onNodeDragStop:ne,onMoveEnd:M,defaultViewport:{x:0,y:0,zoom:1.2},proOptions:{hideAttribution:!0},minZoom:.2,maxZoom:1.5,className:"bg-surface-2",children:t.jsx(mE,{color:"rgba(97,175,239,0.03)",gap:24,size:1})})}const wv=new Set(["codex","grok","local"]),ZJ=new Set(["codex"]);function GJ({open:e,onOpenChange:s,onLaunch:n}){const a=U(B=>B.fetchProviders),[r,l]=p.useState([]),[c,A]=p.useState(""),[f,m]=p.useState(""),[h,g]=p.useState(50),[O,b]=p.useState(.5),[v,w]=p.useState(50);p.useEffect(()=>{e&&a().then(B=>{var $;if(!Array.isArray(B))return;const T=B.filter(M=>M.installed);if(l(T),!c&&T.length>0){const M=T.find(se=>se.isDefault)||T[0];A(M.id);const I=(($=M.models)==null?void 0:$.filter(se=>se.type!=="image"))||[];I.length>0&&m(I[0].id)}}).catch(()=>{})},[e]);const N=r.find(B=>B.id===c),Q=((N==null?void 0:N.models)||[]).filter(B=>B.type!=="image"&&!B.disabled),S=wv.has(c),C=ZJ.has(c);function k(B){var M;A(B);const T=r.find(I=>I.id===B),$=((T==null?void 0:T.models)||[]).filter(I=>I.type!=="image"&&!I.disabled);m(((M=$[0])==null?void 0:M.id)||"")}function F(){const B={provider:c,model:f,reasoningEffort:h,...S&&{temperature:O},...C&&{verbosity:v}};U.setState({teamLaunchConfig:B}),n(B)}return t.jsx(_t,{open:e,onOpenChange:s,children:t.jsxs(zt,{title:"Configure Planner",description:"Set provider, model, and tuning before launching the planner",children:[t.jsxs("div",{className:"px-5 py-4 space-y-4",children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Provider"}),t.jsxs(Cn,{value:c,onValueChange:k,children:[t.jsx(kn,{placeholder:"Select provider",className:"bg-surface-3"}),t.jsx(Tn,{children:r.map(B=>t.jsx(is,{value:B.id,children:B.displayName||B.name||B.id},B.id))})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Model"}),t.jsxs(Cn,{value:f,onValueChange:m,children:[t.jsx(kn,{placeholder:"Select model",className:"bg-surface-3"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"auto",children:"Auto"}),Q.map(B=>t.jsx(is,{value:B.id,children:B.name||B.id},B.id))]})]})]}),t.jsxs("div",{className:"space-y-1 pt-1",children:[t.jsx(_a,{label:"Reasoning Effort",value:h,onChange:g,min:0,max:100,step:1}),S&&t.jsx(_a,{label:"Temperature",value:O,onChange:b,min:0,max:1,step:.01,formatValue:B=>B.toFixed(2)}),C&&t.jsx(_a,{label:"Verbosity",value:v,onChange:w,min:0,max:100,step:1})]})]}),t.jsx("div",{className:"px-5 py-4 border-t border-border-subtle",children:t.jsxs(ge,{variant:"primary",size:"md",onClick:F,className:"w-full gap-2",children:[t.jsx(Wt,{size:14}),"Launch Planner"]})})]})})}const mQ={chat:Po,planner:ji,backend:Qs,frontend:rd,fullstack:un,testing:$x,devops:gb,docs:Bn,security:Pn,database:Ob,cmo:Sb,cfo:rN,ea:NN,support:xN,analyst:Ux,creative:vN,slides:wN,ambassador:aa},Bg=[{id:"planner",label:"Planner",desc:"Analyzes tasks and designs team plans"},{id:"frontend",label:"Frontend",desc:"React, UI components, views, styling"},{id:"backend",label:"Backend",desc:"APIs, server logic, database, services"},{id:"fullstack",label:"Fullstack",desc:"Cross-stack work, QC, integration testing"},{id:"testing",label:"Testing",desc:"Test suites, coverage, quality assurance"},{id:"devops",label:"DevOps",desc:"CI/CD, deployment, infrastructure"},{id:"security",label:"Security",desc:"Security audits, vulnerability analysis"},{id:"database",label:"Database",desc:"Schema design, queries, migrations"},{id:"docs",label:"Docs",desc:"Documentation, guides, API docs"},{id:"cmo",label:"CMO",desc:"Marketing strategy, campaigns, content"},{id:"cfo",label:"CFO",desc:"Financial analysis, budgeting, forecasting"},{id:"ea",label:"EA",desc:"Executive assistance, coordination, briefings"},{id:"support",label:"Support",desc:"Customer support, issue triage"},{id:"analyst",label:"Analyst",desc:"Data analysis, research, reporting"},{id:"creative",label:"Writer",desc:"Design, copywriting, visual assets"},{id:"slides",label:"Slides",desc:"Presentations, decks, pitch materials"}],VJ=[{name:"Dev Team",icon:un,roles:["frontend","backend","testing"],desc:"3 agents"},{name:"Full Stack",icon:Wl,roles:["frontend","backend","fullstack","testing","devops"],desc:"5 agents"},{name:"Marketing",icon:Sb,roles:["cmo","creative","analyst"],desc:"3 agents"},{name:"Business",icon:Ux,roles:["cfo","analyst","ea"],desc:"3 agents"},{name:"Security Audit",icon:Pn,roles:["security","testing","devops"],desc:"3 agents"},{name:"Docs",icon:Bn,roles:["docs","frontend","analyst"],desc:"3 agents"}];function KJ(){const e=U(Z=>Z.teamBuilderOpen),s=U(Z=>Z.teamBuilderRoles),n=U(Z=>Z.teamBuilderSettings),a=U(Z=>Z.teamBuilderTask),r=U(Z=>Z.teamTemplates),l=U(Z=>Z.closeTeamBuilder),c=U(Z=>Z.addTeamBuilderRole),A=U(Z=>Z.removeTeamBuilderRole),f=U(Z=>Z.updateTeamBuilderRole),m=U(Z=>Z.applyTemplate),h=U(Z=>Z.setTeamBuilderSettings),g=U(Z=>Z.setTeamBuilderTask),O=U(Z=>Z.launchTeamBuilder),b=U(Z=>Z.saveTeamTemplate),v=U(Z=>Z.fetchTeamTemplates),w=U(Z=>Z.fetchProviders),[N,Q]=p.useState([]),[S,C]=p.useState(""),[k,F]=p.useState(null),[B,T]=p.useState(!1),[$,M]=p.useState(null),[I,se]=p.useState(!1),[H,ne]=p.useState("");if(p.useEffect(()=>{e&&(w().then(Z=>{Array.isArray(Z)&&Q(Z.filter(ee=>ee.installed))}).catch(()=>{}),v())},[e]),!e)return null;const K=S?Bg.filter(Z=>Z.label.toLowerCase().includes(S.toLowerCase())||Z.desc.toLowerCase().includes(S.toLowerCase())):Bg,L=N.find(Z=>Z.id===n.provider),E=((L==null?void 0:L.models)||[]).filter(Z=>Z.type!=="image"&&!Z.disabled);function q(Z){var ae;h({provider:Z});const ee=N.find(X=>X.id===Z),le=((ee==null?void 0:ee.models)||[]).filter(X=>X.type!=="image"&&!X.disabled);h({provider:Z,model:((ae=le[0])==null?void 0:ae.id)||""})}function D(Z){m(Z),M(Z.name)}async function R(){T(!0);try{await O()}catch{}T(!1)}function _(){const Z=H.trim();Z&&(b(Z),se(!1),ne(""))}const oe=[...VJ,...(r.custom||[]).map(Z=>{var ee;return{...Z,icon:Wl,desc:`${((ee=Z.roles)==null?void 0:ee.length)||0} agents`,custom:!0}})];return t.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:[t.jsxs("div",{className:"w-full max-w-5xl max-h-[90vh] bg-surface-1 border border-border rounded-xl shadow-2xl flex flex-col overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border-subtle",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg bg-info/15 flex items-center justify-center",children:t.jsx(Fn,{size:16,className:"text-info"})}),t.jsx("h2",{className:"text-lg font-bold text-text-0 font-sans",children:"Team Builder"})]}),t.jsx("button",{onClick:l,className:"p-2 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-3 transition-colors cursor-pointer",children:t.jsx(Ze,{size:18})})]}),t.jsx("div",{className:"px-6 py-3 border-b border-border-subtle",children:t.jsxs("div",{className:"flex items-center gap-2 overflow-x-auto pb-1",style:{scrollbarWidth:"none"},children:[oe.map(Z=>{const ee=Z.icon||Wl,le=$===Z.name;return t.jsxs("button",{onClick:()=>D(Z),className:V("flex flex-col items-center gap-1.5 px-4 py-2.5 rounded-lg border text-center transition-all cursor-pointer flex-shrink-0 min-w-[100px]",le?"border-accent bg-accent/5":"border-border-subtle bg-surface-3 hover:border-accent/30 hover:bg-surface-4"),children:[t.jsx(ee,{size:16,className:le?"text-accent":"text-text-2"}),t.jsx("span",{className:"text-2xs font-semibold text-text-0 font-sans",children:Z.name}),t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:Z.desc})]},Z.name)}),t.jsx(ot,{content:"Save current roster as template",children:t.jsxs("button",{onClick:()=>{se(!0),ne("")},disabled:s.length===0,className:"flex flex-col items-center gap-1.5 px-4 py-2.5 rounded-lg border border-dashed border-border-subtle bg-surface-2 hover:border-accent/30 transition-all cursor-pointer flex-shrink-0 min-w-[100px] disabled:opacity-30 disabled:cursor-not-allowed",children:[t.jsx(Bo,{size:16,className:"text-text-3"}),t.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans",children:"Save"}),t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Template"})]})})]})}),t.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[t.jsxs("div",{className:"w-[40%] border-r border-border-subtle flex flex-col",children:[t.jsx("div",{className:"px-4 py-3 border-b border-border-subtle",children:t.jsxs("div",{className:"relative",children:[t.jsx(Ms,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),t.jsx("input",{type:"text",value:S,onChange:Z=>C(Z.target.value),placeholder:"Filter roles...",className:"w-full h-8 pl-8 pr-3 text-xs bg-surface-3 border border-border-subtle rounded-md text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent font-sans"})]})}),t.jsx(bt,{className:"flex-1",children:t.jsx("div",{className:"p-3 grid grid-cols-2 gap-2",children:K.map(Z=>{const ee=mQ[Z.id]||un;return t.jsxs("button",{onClick:()=>c(Z.id),className:"flex items-start gap-2.5 p-2.5 rounded-lg border border-border-subtle bg-surface-2 hover:border-accent/30 hover:bg-surface-3 transition-all cursor-pointer text-left group",children:[t.jsx("div",{className:"w-7 h-7 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/15 transition-colors",children:t.jsx(ee,{size:14,className:"text-text-2 group-hover:text-accent transition-colors"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:Z.label}),t.jsx(At,{size:12,className:"text-text-4 group-hover:text-accent transition-colors flex-shrink-0"})]}),t.jsx("p",{className:"text-2xs text-text-3 font-sans leading-tight mt-0.5",children:Z.desc})]})]},Z.id)})})})]}),t.jsxs("div",{className:"flex-1 flex flex-col",children:[t.jsx("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center justify-between",children:t.jsxs("span",{className:"text-xs font-semibold text-text-1 font-sans uppercase tracking-wider",children:["Your Team (",s.length,")"]})}),t.jsx(bt,{className:"flex-1",children:t.jsx("div",{className:"p-3 space-y-1.5",children:s.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[t.jsx(Fn,{size:32,className:"text-text-4 mb-3"}),t.jsx("p",{className:"text-sm text-text-2 font-sans",children:"Add roles from the left or pick a template above"})]}):s.map((Z,ee)=>{var he;const le=mQ[Z.role]||un,ae=k===ee,X=Z.provider?N.find(W=>W.id===Z.provider):null,te=((X==null?void 0:X.models)||[]).filter(W=>W.type!=="image"&&!W.disabled);return t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[t.jsx(fN,{size:12,className:"text-text-4 flex-shrink-0 cursor-grab"}),t.jsx("div",{className:"w-6 h-6 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:t.jsx(le,{size:12,className:"text-text-1"})}),t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans flex-1",children:((he=Bg.find(W=>W.id===Z.role))==null?void 0:he.label)||Z.role}),t.jsx("button",{onClick:()=>F(ae?null:ee),className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(dt,{size:12,className:V("transition-transform duration-200",ae&&"rotate-180")})}),t.jsx("button",{onClick:()=>{A(ee),k===ee?F(null):k>ee&&F(k-1)},className:"p-1 rounded text-text-4 hover:text-danger cursor-pointer",children:t.jsx(Ze,{size:12})})]}),ae&&t.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-3 border-t border-border-subtle bg-surface-1",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Name Override"}),t.jsx("input",{type:"text",value:Z.name,onChange:W=>f(ee,{name:h4(W.target.value)}),placeholder:Z.role,className:"w-full h-7 px-2.5 text-xs bg-surface-3 border border-border-subtle rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",maxLength:64,spellCheck:!1})]}),t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),t.jsxs(Cn,{value:Z.provider||"__default__",onValueChange:W=>{var be;const Oe=W==="__default__"?null:W,me=N.find(Se=>Se.id===Oe),J=((me==null?void 0:me.models)||[]).filter(Se=>Se.type!=="image"&&!Se.disabled);f(ee,{provider:Oe,model:((be=J[0])==null?void 0:be.id)||null})},children:[t.jsx(kn,{placeholder:"Team Default",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"__default__",children:"Team Default"}),N.map(W=>t.jsx(is,{value:W.id,children:W.displayName||W.name||W.id},W.id))]})]})]}),t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),t.jsxs(Cn,{value:Z.model||"__default__",onValueChange:W=>f(ee,{model:W==="__default__"?null:W}),children:[t.jsx(kn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"__default__",children:"Default"}),te.map(W=>t.jsx(is,{value:W.id,children:W.name||W.id},W.id))]})]})]})]}),t.jsx(_a,{label:"Reasoning",value:Z.reasoningEffort??n.reasoningEffort,onChange:W=>f(ee,{reasoningEffort:W}),min:0,max:100,step:1}),wv.has(Z.provider||n.provider)&&t.jsx(_a,{label:"Temperature",value:Z.temperature??n.temperature,onChange:W=>f(ee,{temperature:W}),min:0,max:1,step:.01,formatValue:W=>W.toFixed(2)})]})]},ee)})})})]})]}),t.jsx("div",{className:"border-t border-border-subtle px-6 py-4",children:t.jsxs("div",{className:"flex gap-4",children:[t.jsxs("div",{className:"flex-1 space-y-1.5",children:[t.jsx("textarea",{value:a,onChange:Z=>g(Z.target.value),placeholder:"Describe what you want to build... (optional)",rows:3,className:"w-full px-3 py-2 text-sm bg-surface-3 border border-border-subtle rounded-md text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent resize-none"}),t.jsx("p",{className:"text-2xs text-text-4 font-sans italic",children:"Leave empty to spawn agents awaiting instructions"})]}),t.jsxs("div",{className:"w-64 flex flex-col gap-2",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("div",{className:"flex-1 space-y-0.5",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),t.jsxs(Cn,{value:n.provider||"__default__",onValueChange:Z=>q(Z==="__default__"?"":Z),children:[t.jsx(kn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"__default__",children:"Default"}),N.map(Z=>t.jsx(is,{value:Z.id,children:Z.displayName||Z.name||Z.id},Z.id))]})]})]}),t.jsxs("div",{className:"flex-1 space-y-0.5",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),t.jsxs(Cn,{value:n.model||"__default__",onValueChange:Z=>h({model:Z==="__default__"?"":Z}),children:[t.jsx(kn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"__default__",children:"Auto"}),E.map(Z=>t.jsx(is,{value:Z.id,children:Z.name||Z.id},Z.id))]})]})]})]}),t.jsxs(ge,{variant:"primary",size:"md",onClick:R,disabled:B||s.length===0,className:"w-full gap-2 mt-1",children:[t.jsx(Wt,{size:14}),B?"Launching...":`Plan & Launch (${s.length})`]})]})]})})]}),I&&t.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40",children:t.jsxs("div",{className:"w-full max-w-sm bg-surface-2 border border-border rounded-lg shadow-2xl p-5 space-y-4",children:[t.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:"Save as Template"}),t.jsx("input",{type:"text",value:H,onChange:Z=>ne(Z.target.value),placeholder:"Template name...",className:"w-full h-8 px-3 text-sm bg-surface-3 border border-border-subtle rounded-md text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0,onKeyDown:Z=>{Z.key==="Enter"&&_(),Z.key==="Escape"&&se(!1)}}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>se(!1),children:"Cancel"}),t.jsx(ge,{variant:"primary",size:"sm",onClick:_,disabled:!H.trim(),children:"Save"})]})]})})]})}function qJ({onPlanner:e,onSpawn:s,onTeamBuilder:n}){var a;return t.jsx("div",{className:"w-full h-full flex items-center justify-center",children:t.jsxs("div",{className:"max-w-2xl w-full text-center space-y-10 px-8",children:[t.jsxs("div",{className:"relative mx-auto w-20 h-20",children:[t.jsx("div",{className:"absolute inset-0 rounded-full bg-accent/8 animate-pulse"}),t.jsx("div",{className:"absolute inset-1 rounded-full bg-surface-3 border border-border-subtle flex items-center justify-center shadow-lg shadow-accent/5",children:t.jsx("img",{src:"/favicon.png",alt:"Groove",className:"h-10 w-10 rounded-full"})})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsx("h1",{className:"text-3xl font-bold text-text-0 font-sans tracking-tight",children:"Welcome to Groove"}),t.jsx("p",{className:"text-base text-text-2 font-sans max-w-md mx-auto leading-relaxed",children:"Your mission control for AI agents. Spawn, orchestrate, and ship faster than ever."})]}),t.jsxs("div",{className:"space-y-3 max-w-xl mx-auto",children:[t.jsxs("button",{onClick:e,className:"w-full flex items-center gap-4 p-5 rounded-lg border border-accent/25 bg-gradient-to-r from-accent/8 to-accent/3 hover:from-accent/14 hover:to-accent/6 hover:border-accent/40 transition-all cursor-pointer group text-left",children:[t.jsx("div",{className:"w-12 h-12 rounded-lg bg-accent/20 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:t.jsx(Wt,{size:24,className:"text-accent"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-base font-semibold text-text-0 font-sans",children:"Start with a Planner"}),t.jsx("div",{className:"text-sm text-text-2 font-sans mt-0.5",children:"Describe what you want to build and let AI plan the perfect team"})]}),t.jsx("div",{className:"text-accent text-xs font-semibold font-sans flex-shrink-0 opacity-60 group-hover:opacity-100 transition-opacity",children:"Recommended"})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{onClick:n,className:"flex items-center gap-3 p-4 rounded-lg border border-info/25 bg-gradient-to-r from-info/6 to-info/2 hover:from-info/12 hover:to-info/5 hover:border-info/35 transition-all cursor-pointer group text-left",children:[t.jsx("div",{className:"w-10 h-10 rounded-lg bg-info/15 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:t.jsx(BN,{size:20,className:"text-info"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Build a Team"}),t.jsx("div",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Pick roles and configure"})]})]}),t.jsxs("button",{onClick:s,className:"flex items-center gap-3 p-4 rounded-lg border border-border bg-surface-1 hover:bg-surface-2 hover:border-border transition-all cursor-pointer group text-left",children:[t.jsx("div",{className:"w-10 h-10 rounded-lg bg-surface-4 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:t.jsx(At,{size:20,className:"text-text-1"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn Agent"}),t.jsx("div",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Choose a role and configure"})]})]})]})]}),((a=window.groove)==null?void 0:a.openFolder)&&t.jsxs("div",{className:"max-w-sm mx-auto",children:[t.jsx("p",{className:"text-xs text-text-3 mb-2",children:"Or open a different project"}),t.jsxs("button",{onClick:()=>window.groove.openFolder(),className:"w-full h-10 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 text-sm text-text-1 font-medium flex items-center justify-center gap-2 cursor-pointer transition-colors",children:[t.jsx(Vs,{size:16,className:"text-accent"}),"Open Folder"]})]}),t.jsxs("p",{className:"text-xs text-text-4 font-sans",children:[t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+K"}),t.jsx("span",{className:"mx-1.5",children:"command palette"}),t.jsx("span",{className:"text-text-4 mx-1",children:"·"}),t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+N"}),t.jsx("span",{className:"mx-1.5",children:"spawn"}),t.jsx("span",{className:"text-text-4 mx-1",children:"·"}),t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+J"}),t.jsx("span",{className:"mx-1.5",children:"terminal"})]})]})})}const WJ={backend:Qs,frontend:rd,fullstack:un,testing:$x,security:Pn},YJ=/^[a-zA-Z0-9_-]{1,64}$/;function h4(e){return e.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,64)}function JJ(){var D;const e=U(R=>R.recommendedTeam),s=U(R=>R.launchRecommendedTeam),n=U(R=>R.teamLaunchConfig),a=U(R=>R.fetchProviders),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,m]=p.useState(!1),[h,g]=p.useState([]),[O,b]=p.useState((n==null?void 0:n.provider)||""),[v,w]=p.useState((n==null?void 0:n.model)||""),[N,Q]=p.useState((n==null?void 0:n.reasoningEffort)??50),[S,C]=p.useState((n==null?void 0:n.temperature)??.5),[k,F]=p.useState(null);if(p.useEffect(()=>{a().then(R=>{Array.isArray(R)&&g(R.filter(_=>_.installed))}).catch(()=>{})},[]),!((D=e==null?void 0:e.agents)!=null&&D.length))return null;const B=e.agents,T=B.filter(R=>!R.phase||R.phase===1),$=B.filter(R=>R.phase===2),M=c??T.map(R=>({...R,name:R.name||""})),I=h.find(R=>R.id===O),se=((I==null?void 0:I.models)||[]).filter(R=>R.type!=="image"&&!R.disabled),H=wv.has(O);function ne(R,_){const oe=M.map((Z,ee)=>ee===R?{...Z,name:h4(_)}:Z);A(oe)}function K(R,_){if(typeof _=="string"){const[oe,Z]=[_,arguments[2]];A(ee=>(ee??M).map((le,ae)=>ae===R?{...le,[oe]:Z}:le))}else A(oe=>(oe??M).map((Z,ee)=>ee===R?{...Z,..._}:Z))}function L(R){var Z;b(R);const _=h.find(ee=>ee.id===R),oe=((_==null?void 0:_.models)||[]).filter(ee=>ee.type!=="image"&&!ee.disabled);w(((Z=oe[0])==null?void 0:Z.id)||"")}async function E(){l(!0),U.setState({teamLaunchConfig:{...O&&{provider:O,model:v},reasoningEffort:N,...H&&{temperature:S}}});try{const R=[...M,...$];await s(R)}catch{}l(!1)}function q(){U.setState({recommendedTeam:null})}return t.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 z-50 w-full max-w-lg",children:t.jsxs("div",{className:"mx-4 rounded-lg border border-accent/30 bg-surface-2/95 backdrop-blur-md shadow-xl shadow-accent/5 overflow-hidden",children:[t.jsxs("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center gap-2",children:[t.jsx(ji,{size:16,className:"text-accent"}),t.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Planner Recommends a Team"}),t.jsx("button",{onClick:q,className:"text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(Ze,{size:14})})]}),t.jsxs("div",{className:"border-b border-border-subtle",children:[t.jsxs("button",{onClick:()=>m(!f),className:"w-full flex items-center gap-2 px-4 py-2 text-left cursor-pointer hover:bg-surface-3/50 transition-colors",children:[t.jsx(dt,{size:12,className:V("text-text-4 transition-transform duration-200",!f&&"-rotate-90")}),t.jsx(QN,{size:12,className:"text-text-3"}),t.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider",children:"Team Settings"}),O&&t.jsxs("span",{className:"ml-auto text-2xs text-accent font-mono",children:[O,v?` / ${v}`:""]})]}),f&&t.jsxs("div",{className:"px-4 pb-3 space-y-3",children:[t.jsxs("div",{className:"flex gap-3",children:[t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),t.jsxs(Cn,{value:O,onValueChange:L,children:[t.jsx(kn,{placeholder:"Default",className:"bg-surface-4 h-7 text-xs"}),t.jsx(Tn,{children:h.map(R=>t.jsx(is,{value:R.id,children:R.displayName||R.name||R.id},R.id))})]})]}),t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),t.jsxs(Cn,{value:v,onValueChange:w,children:[t.jsx(kn,{placeholder:"Auto",className:"bg-surface-4 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"auto",children:"Auto"}),se.map(R=>t.jsx(is,{value:R.id,children:R.name||R.id},R.id))]})]})]})]}),t.jsx(_a,{label:"Reasoning",value:N,onChange:Q,min:0,max:100,step:1}),H&&t.jsx(_a,{label:"Temperature",value:S,onChange:C,min:0,max:1,step:.01,formatValue:R=>R.toFixed(2)})]})]}),t.jsxs("div",{className:"px-4 py-3 space-y-1.5",children:[M.map((R,_)=>{var X;const oe=WJ[R.role]||un,Z=!R.name||YJ.test(R.name),ee=k===_,le=h.find(te=>te.id===(R.provider||O)),ae=((le==null?void 0:le.models)||[]).filter(te=>te.type!=="image"&&!te.disabled);return t.jsxs("div",{className:"rounded-md bg-surface-4 border border-border-subtle overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 cursor-pointer hover:bg-surface-5/50 transition-colors",onClick:()=>F(ee?null:_),children:[t.jsx(oe,{size:12,className:"text-text-2 shrink-0"}),t.jsx("input",{type:"text",value:R.name,onChange:te=>ne(_,te.target.value),onClick:te=>te.stopPropagation(),placeholder:R.role,className:V("flex-1 min-w-0 bg-transparent text-xs font-mono text-text-0 outline-none placeholder:text-text-4",!Z&&"text-red-400"),maxLength:64,spellCheck:!1}),R.provider&&R.provider!==O&&t.jsx("span",{className:"text-2xs text-accent font-mono shrink-0",children:R.provider}),((X=R.scope)==null?void 0:X.length)>0&&t.jsxs("span",{className:"text-2xs text-text-4 font-mono shrink-0 truncate max-w-[120px]",children:[R.scope[0],R.scope.length>1?` +${R.scope.length-1}`:""]}),t.jsx(dt,{size:10,className:V("text-text-4 shrink-0 transition-transform duration-200",!ee&&"-rotate-90")})]}),ee&&t.jsxs("div",{className:"px-2.5 pb-2.5 pt-1 space-y-2.5 border-t border-border-subtle",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[t.jsx(ya,{size:10}),"Provider"]}),t.jsxs(Cn,{value:R.provider||"",onValueChange:te=>{var Oe;const he=h.find(me=>me.id===te),W=((he==null?void 0:he.models)||[]).filter(me=>me.type!=="image"&&!me.disabled);K(_,{provider:te,model:((Oe=W[0])==null?void 0:Oe.id)||""})},children:[t.jsx(kn,{placeholder:"Team default",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"",children:"Team default"}),h.map(te=>t.jsx(is,{value:te.id,children:te.displayName||te.name||te.id},te.id))]})]})]}),t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),t.jsxs(Cn,{value:R.model||"",onValueChange:te=>K(_,"model",te),children:[t.jsx(kn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"",children:"Auto"}),ae.map(te=>t.jsx(is,{value:te.id,children:te.name||te.id},te.id))]})]})]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[t.jsx(Vl,{size:10}),"Model Routing"]}),t.jsx("div",{className:"flex bg-surface-3 rounded-md p-0.5 border border-border-subtle",children:[{value:"fixed",label:"Fixed"},{value:"auto",label:"Auto"},{value:"auto-floor",label:"Auto + Floor"}].map(te=>t.jsx("button",{onClick:()=>K(_,"routingMode",te.value),className:V("flex-1 px-2 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(R.routingMode||"auto")===te.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:te.label},te.value))})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[t.jsx(dN,{size:10}),"Effort Level"]}),t.jsx("div",{className:"flex bg-surface-3 rounded-md p-0.5 border border-border-subtle",children:[{value:"min",label:"Min"},{value:"low",label:"Low"},{value:"default",label:"Default"},{value:"high",label:"High"},{value:"max",label:"Max"}].map(te=>t.jsx("button",{onClick:()=>K(_,"effort",te.value),className:V("flex-1 px-1.5 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(R.effort||"default")===te.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:te.label},te.value))})]})]})]},_)}),e.projectDir&&t.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-2 font-mono pt-0.5",children:[t.jsx("span",{className:"text-text-4",children:"Project:"}),t.jsxs("span",{className:"text-accent",children:[e.projectDir,"/"]})]}),$.length>0&&t.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans",children:[t.jsx(Pn,{size:10}),t.jsxs("span",{children:[$.length," QC agent",$.length>1?"s":""," will auto-spawn after builders complete"]})]})]}),t.jsx("div",{className:"px-4 py-3 border-t border-border-subtle",children:t.jsxs(ge,{variant:"primary",size:"md",onClick:E,disabled:r,className:"w-full gap-2",children:[t.jsx(Wt,{size:14}),r?"Launching...":`Launch ${T.length} Agent${T.length>1?"s":""}`]})})]})})}function Cg(){var M;const e=U(I=>I.agents),s=U(I=>I.activeTeamId),n=U(I=>I.openDetail),a=U(I=>I.spawnAgent),r=U(I=>I.selectAgent);U(I=>I.recommendedTeam);const l=U(I=>I.checkRecommendedTeam),c=U(I=>I.addToast),A=U(I=>I.showPreviewInAgents),f=U(I=>I.previewState),m=U(I=>I.togglePreviewInAgents),h=U(I=>I.teamPreviews),g=U(I=>I.relaunchPreview),O=U(I=>I.openPreview),b=U(I=>I.workspaceMode),v=U(I=>I.setWorkspaceMode),w=U(I=>I.openTeamBuilder),[N,Q]=p.useState(!1);p.useEffect(()=>{if(!e.some(H=>H.role==="planner"&&(H.status==="running"||H.status==="starting")))return;const se=setInterval(()=>l(),5e3);return()=>clearInterval(se)},[e,l]);function S(){Q(!0)}async function C(I){Q(!1);try{const se=await a({role:"planner",provider:I.provider,model:I.model,reasoningEffort:I.reasoningEffort,temperature:I.temperature,verbosity:I.verbosity});se!=null&&se.id&&r(se.id)}catch{}}const k=e.filter(I=>{var se;return I.teamId===s&&!((se=I.metadata)!=null&&se.scheduled)}),F=U(I=>I.hydrated),[B,T]=p.useState(!0);p.useEffect(()=>{const I=setTimeout(()=>T(!1),1200);return()=>clearTimeout(I)},[]);const $=B||!F;return t.jsxs("div",{className:"flex flex-col h-full relative",children:[t.jsx("div",{className:"flex-1 min-h-0",children:$?t.jsxs("div",{className:V("flex flex-col items-center justify-center h-full transition-opacity duration-500",!B&&F?"opacity-0":"opacity-100"),children:[t.jsxs("div",{className:"relative w-12 h-12 mb-5",children:[t.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-accent/20 animate-ping",style:{animationDuration:"2s"}}),t.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent animate-spin",style:{animationDuration:"1s"}}),t.jsx("span",{className:"absolute inset-[6px] rounded-full bg-accent/8 flex items-center justify-center",children:t.jsx(Wt,{size:16,className:"text-accent animate-pulse"})})]}),t.jsx("p",{className:"text-sm font-medium text-text-1 font-sans animate-pulse",children:"Connecting to agents"}),t.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Syncing with daemon..."})]}):k.length===0?t.jsx(qJ,{onPlanner:S,onSpawn:()=>n({type:"spawn"}),onTeamBuilder:w}):b?t.jsx(CW,{}):A&&f.url&&f.teamId===s&&((M=h[s])!=null&&M.active)?t.jsx(cX,{embedded:!0}):t.jsx(AE,{children:t.jsx(XJ,{})},s)}),!b&&t.jsx(JJ,{}),!$&&k.length>0&&!b&&t.jsxs("div",{className:"absolute bottom-3 left-3 z-40 flex items-center gap-1.5",children:[t.jsx(ot,{content:"Spawn agent",side:"top",children:t.jsx("button",{onClick:()=>n({type:"spawn"}),className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:t.jsx(At,{size:15})})}),t.jsx(ot,{content:Object.keys(x4()).length>0?"Update layout":"Save layout",side:"top",children:t.jsx("button",{onClick:()=>{const I=SA(s),se={},H=new Map;[...k].sort((ne,K)=>(ne.name||ne.id).localeCompare(K.name||K.id)).forEach(ne=>{const K=ne.name||ne.id,L=I[K];if(!L)return;const E=ne.role||"agent",q=H.get(E)||0;H.set(E,q+1);const D=q===0?E:`${E}-${q}`;se[D]=L}),I[zs]&&(se[zs]=I[zs]),zJ(se),c("success","Layout saved","Future spawns will use these positions")},className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:t.jsx(JR,{size:15})})}),t.jsx(ot,{content:"Workspace",side:"top",children:t.jsx("button",{onClick:()=>v(!0),className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:t.jsx(un,{size:15})})}),(()=>{const I=h[s];if(!I)return null;const se=I.active&&f.url&&f.teamId===s,H=se&&A,ne=H?"Show team":se?"Show preview":"Relaunch preview";return t.jsx(ot,{content:ne,side:"top",children:t.jsx("button",{onClick:()=>{se?A?m():O(I.url,s,I.kind):g(s)},className:V("flex items-center justify-center w-8 h-8 rounded border bg-surface-2/50 transition-colors cursor-pointer",se?"border-text-3/25 text-text-3 hover:text-info hover:border-info/40 hover:bg-info/10":"border-text-4/25 text-text-4 hover:text-warning hover:border-warning/40 hover:bg-warning/10"),children:H?t.jsx(Fn,{size:15}):t.jsx(Hs,{size:15})})})})()]}),t.jsx(GJ,{open:N,onOpenChange:Q,onLaunch:C}),t.jsx(KJ,{})]})}function eee({children:e,detailContent:s,terminalContent:n}){const a=U(B=>B.activeView),r=U(B=>B.detailPanel),l=U(B=>B.connected),c=U(B=>B.tunneled),A=U(B=>B.daemonHost),f=U(B=>B.agents),m=U(B=>B.editorActiveFile),h=U(B=>B.detailPanelWidth),g=U(B=>B.terminalVisible),O=U(B=>B.terminalFullHeight),b=U(B=>B.setActiveView),v=U(B=>B.openDetail),w=U(B=>B.closeDetail),N=U(B=>B.setDetailPanelWidth),Q=U(B=>B.setTerminalVisible),S=U(B=>B.toggleCommandPalette),C=p.useMemo(()=>f.filter(B=>B.status==="running").length,[f]),k=p.useMemo(()=>[{key:"k",meta:!0,handler:()=>U.getState().toggleCommandPalette()},{key:"p",meta:!0,shift:!0,handler:()=>U.getState().toggleCommandPalette()},{key:"j",meta:!0,handler:()=>{const B=U.getState();B.setTerminalVisible(!B.terminalVisible)}},{key:"n",meta:!0,handler:()=>U.getState().openDetail({type:"spawn"})},{key:"1",meta:!0,handler:()=>U.getState().setActiveView("agents")},{key:"2",meta:!0,handler:()=>U.getState().setActiveView("editor")},{key:"3",meta:!0,handler:()=>U.getState().setActiveView("dashboard")},{key:"4",meta:!0,handler:()=>U.getState().setActiveView("marketplace")},{key:"5",meta:!0,handler:()=>U.getState().setActiveView("teams")},{key:"Escape",handler:()=>{const B=U.getState();B.commandPaletteOpen?B.toggleCommandPalette():B.detailPanel&&B.closeDetail()}}],[]);sS(k);const F=r&&r.type!=="spawn";return t.jsx(t$,{children:t.jsxs("div",{className:V("w-full h-full flex flex-col bg-surface-2 text-text-1 font-sans",JA()&&"electron-app"),children:[t.jsx(r_,{activeView:a,connected:l,tunneled:c,daemonHost:A,editorActiveFile:m,onOpenCommandPalette:S}),t.jsxs("div",{className:"flex-1 flex min-h-0",children:[t.jsx(t_,{activeView:a,detailPanel:r,onNavigate:b,onTogglePanel:B=>{(r==null?void 0:r.type)===B?w():v({type:B})}}),t.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[a==="agents"&&t.jsx(HJ,{}),t.jsxs("div",{className:"flex-1 flex min-h-0",children:[t.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[!(g&&O)&&t.jsx("main",{className:"flex-1 min-h-0 overflow-hidden relative",children:e}),n]}),F&&t.jsx(mz,{width:h,onWidthChange:N,onClose:w,children:s})]})]})]}),t.jsx(xz,{connected:l,agentCount:f.length,runningCount:C,terminalVisible:g,onToggleTerminal:()=>Q(!g)}),t.jsx(pz,{}),t.jsx(AB,{}),t.jsx(gz,{}),t.jsx(Oz,{}),t.jsx(TN,{})]})})}function tee({id:e,name:s,subtitle:n,models:a,authType:r,recommended:l,installed:c,installing:A,failed:f,selected:m,onInstall:h,gradientFrom:g,letter:O,statusChecking:b}){return t.jsxs(En.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.25},className:V("relative flex flex-col rounded-md border p-6 transition-all duration-200","bg-surface-2 hover:bg-surface-3 hover:shadow-lg hover:shadow-black/20",m?"border-accent ring-1 ring-accent/30 shadow-md shadow-accent/10":"border-border-subtle",A&&"pointer-events-none opacity-70"),children:[m&&t.jsx("div",{className:"absolute top-3 left-3 w-5 h-5 rounded-full bg-accent flex items-center justify-center",children:t.jsx(Je,{className:"w-3 h-3 text-surface-0",strokeWidth:3})}),t.jsxs("div",{className:"flex items-start gap-4 mb-5",children:[t.jsx("div",{className:V("w-14 h-14 rounded-md flex items-center justify-center text-lg font-bold font-mono shrink-0",g),children:O}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"text-sm font-semibold text-text-0",children:s}),l&&t.jsx(ke,{variant:"purple",className:"text-2xs",children:"Recommended"})]}),t.jsx("p",{className:"text-xs text-text-2 mt-0.5",children:n})]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",children:a.map(v=>t.jsx("span",{className:"text-xs text-text-2 bg-surface-4 px-2 py-0.5 rounded font-mono",children:v},v))}),t.jsx("p",{className:"text-2xs text-text-3 mb-4",children:r}),t.jsx("div",{className:"mt-auto pt-4 border-t border-border-subtle",children:A?t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ie,{className:"w-4 h-4 text-accent animate-spin"}),t.jsx("span",{className:"text-xs text-accent font-medium",children:"Installing..."})]}),t.jsx("div",{className:"h-1 bg-surface-4 rounded-full overflow-hidden",children:t.jsx(En.div,{className:"h-full bg-accent rounded-full",initial:{width:"0%"},animate:{width:"90%"},transition:{duration:15,ease:"easeOut"}})})]}):c?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Vf,{className:"w-4 h-4 text-success"}),t.jsx("span",{className:"text-xs text-success font-medium",children:"Ready"})]}):f?t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Xs,{className:"w-4 h-4 text-danger"}),t.jsx("span",{className:"text-xs text-danger font-medium",children:"Failed"})]}),t.jsxs("button",{type:"button",className:"h-8 px-5 rounded-full text-xs font-medium bg-danger/15 text-danger hover:bg-danger/25 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-danger flex items-center gap-1.5",onClick:v=>{v.stopPropagation(),h==null||h(e)},children:[t.jsx(No,{className:"w-3 h-3"}),"Retry"]})]}):b?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ie,{className:"w-3.5 h-3.5 text-text-4 animate-spin"}),t.jsx("span",{className:"text-xs text-text-4",children:"Checking..."})]}):t.jsx("div",{className:"flex items-center justify-end",children:t.jsxs("button",{type:"button",className:"h-8 px-5 rounded-full text-xs font-medium bg-accent text-surface-0 hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent flex items-center gap-1.5",onClick:v=>{v.stopPropagation(),h==null||h(e)},children:[t.jsx(Zs,{className:"w-3.5 h-3.5"}),"Install"]})})})]})}const ha=[{id:"claude-code",name:"Claude Code",subtitle:"by Anthropic",models:["Opus 4.6","Sonnet 4.6","Haiku 4.5"],authType:"Subscription or API key",authModes:["subscription","apikey"],recommended:!0,letter:"C",gradientFrom:"bg-purple/20 text-purple",keyPlaceholder:"sk-ant-...",keyLabel:"Anthropic API Key"},{id:"codex",name:"Codex",subtitle:"by OpenAI",models:["GPT-5.4 Pro","Standard","Mini","Nano"],authType:"API key or ChatGPT Plus",authModes:["apikey","chatgpt-plus"],recommended:!1,letter:"X",gradientFrom:"bg-success/20 text-success",keyPlaceholder:"sk-...",keyLabel:"OpenAI API Key"},{id:"gemini",name:"Gemini CLI",subtitle:"by Google",models:["Gemini 3.1 Pro","3 Flash"],authType:"API key",authModes:["apikey"],recommended:!1,letter:"G",gradientFrom:"bg-info/20 text-info",keyPlaceholder:"AIza...",keyLabel:"Gemini API Key"}],see={enter:e=>({x:e>0?80:-80,opacity:0}),center:{x:0,opacity:1},exit:e=>({x:e<0?80:-80,opacity:0})},nee={duration:.25,ease:[.4,0,.2,1]};function aee({current:e,total:s}){return t.jsx("div",{className:"flex items-center gap-2.5",children:Array.from({length:s},(n,a)=>t.jsx("div",{className:V("h-2 rounded-full transition-all duration-300",a===e?"w-7 bg-accent":a<e?"w-2 bg-accent/50":"w-2 bg-surface-5")},a))})}function ree({onNext:e,onSkip:s}){return t.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[t.jsx(En.img,{src:"/favicon.png",alt:"Groove",className:"w-20 h-20",initial:{scale:.5,opacity:0},animate:{scale:1,opacity:1},transition:{duration:.4,ease:"easeOut"}}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"Welcome to Groove"}),t.jsx("p",{className:"text-sm text-text-2",children:"Your AI coding team, ready in minutes"})]}),t.jsx("p",{className:"text-xs text-text-3 leading-relaxed max-w-sm",children:"Let's set up your AI providers so you can start spawning agents. This only takes a moment."}),t.jsxs("button",{type:"button",onClick:e,className:"mt-4 h-11 px-8 rounded-full bg-accent text-surface-0 font-semibold text-sm hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-0 flex items-center gap-2",autoFocus:!0,children:["Get Started",t.jsx(So,{className:"w-4 h-4"})]}),t.jsx("button",{type:"button",onClick:s,className:"text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent rounded px-2 py-1",children:"Skip setup"})]})}function oee({selectedDir:e,onSelectDir:s}){const n=U(A=>A.remoteHomedir),[a,r]=p.useState(!1),l=new URLSearchParams(window.location.search).has("instance");async function c(){var f,m;if(l){r(!0);return}const A=await n3({title:"Choose your project folder",defaultPath:e||void 0});A?s(A):(m=(f=window.groove)==null?void 0:f.folders)!=null&&m.select||r(!0)}return t.jsxs("div",{className:"flex flex-col items-center max-w-lg mx-auto w-full text-center",children:[t.jsxs("div",{className:"mb-8",children:[t.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your project folder"}),t.jsx("p",{className:"text-sm text-text-2",children:"Pick the root directory where your code lives. Groove will manage agents from here."})]}),t.jsx("div",{className:"w-full bg-surface-2 border border-border-subtle rounded-lg p-5 mb-6",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-12 h-12 rounded-lg bg-accent/10 flex items-center justify-center",children:t.jsx(Vs,{className:"w-6 h-6 text-accent"})}),t.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[t.jsx("p",{className:"text-xs text-text-3 mb-0.5",children:"Working directory"}),t.jsx("p",{className:"text-sm font-mono text-text-0 truncate",children:e||"No folder selected"})]})]})}),t.jsxs("button",{type:"button",onClick:c,className:"h-10 px-6 rounded-lg bg-accent text-surface-0 font-medium text-sm hover:bg-accent/80 transition-colors cursor-pointer flex items-center gap-2",children:[t.jsx(Vs,{className:"w-4 h-4"}),e?"Change Folder":"Select Folder"]}),t.jsx("p",{className:"mt-4 text-2xs text-text-4",children:"You can change this anytime in Settings."}),a&&t.jsx(Ac,{open:a,onOpenChange:r,currentPath:e||n||"/",homePath:n,onSelect:A=>{s(A),r(!1)}})]})}function iee({providerStatus:e,selected:s,onInstall:n,installing:a,statusChecking:r}){const l=ha.filter(A=>{var f;return(f=e[A.id])==null?void 0:f.installed}).length,c=l===ha.length;return t.jsxs("div",{className:"flex flex-col items-center max-w-4xl mx-auto w-full",children:[t.jsxs("div",{className:"text-center mb-10",children:[t.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your AI providers"}),t.jsx("p",{className:"text-sm text-text-2",children:"Install the coding tools you want to use. You can always add more later."})]}),t.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 w-full mb-8",children:ha.map(A=>{var f,m;return t.jsx(tee,{...A,installed:(f=e[A.id])==null?void 0:f.installed,installing:a[A.id],failed:(m=e[A.id])==null?void 0:m.failed,selected:s.includes(A.id),onInstall:n,statusChecking:r},A.id)})}),t.jsx("p",{className:V("text-xs text-center",c?"text-success":l>0?"text-text-2":"text-text-4"),children:c?"All providers installed — you're ready to go!":l>0?`${l} of ${ha.length} providers installed`:"Click Install to set up a provider"})]})}function lee({provider:e,providerStatus:s,onSaveKey:n}){const[a,r]=p.useState(e.authModes.includes("subscription")?"subscription":"apikey"),[l,c]=p.useState(""),[A,f]=p.useState(!1),[m,h]=p.useState(!1),[g,O]=p.useState((s==null?void 0:s.authenticated)||!1),b=async()=>{if(l.trim()){h(!0);try{await n(e.id,l.trim()),O(!0)}catch{}finally{h(!1)}}},v=(s==null?void 0:s.maskedKey)||(g&&l?`${l.slice(0,6)}${"•".repeat(20)}`:null);return t.jsxs(En.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.2},className:"bg-surface-2 border border-border-subtle rounded-md p-5",children:[t.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[t.jsx("div",{className:V("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono",e.gradientFrom),children:e.letter}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-sm font-semibold text-text-0",children:e.name}),t.jsx("p",{className:"text-2xs text-text-3",children:e.subtitle})]}),(g||(s==null?void 0:s.authenticated))&&t.jsx(ke,{variant:"success",className:"ml-auto",children:"Connected"})]}),e.authModes.length>1&&t.jsx("div",{className:"flex gap-1 mb-4 bg-surface-3 p-0.5 rounded-md",children:e.authModes.map(w=>t.jsx("button",{type:"button",onClick:()=>r(w),className:V("flex-1 h-7 rounded text-xs font-medium transition-colors duration-100 cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",a===w?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:w==="subscription"?"Subscription":w==="chatgpt-plus"?"ChatGPT Plus":"API Key"},w))}),a==="subscription"&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"text-xs text-text-2",children:"Sign in via the terminal with your Claude subscription."}),t.jsx("div",{className:"space-y-1.5",children:t.jsxs("p",{className:"text-2xs text-text-2 font-sans",children:["Open a terminal and run: ",t.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"claude"})," — then follow the prompts to sign in."]})}),(s==null?void 0:s.authenticated)&&t.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[t.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="chatgpt-plus"&&t.jsxs("div",{className:"space-y-3",children:[t.jsxs("p",{className:"text-xs text-text-2",children:["Run ",t.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"codex login"})," in your terminal to authenticate with ChatGPT Plus."]}),(s==null?void 0:s.authenticated)&&t.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[t.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="apikey"&&t.jsx("div",{className:"space-y-3",children:g||s!=null&&s.authenticated?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"flex-1 h-8 rounded-md bg-surface-1 border border-border px-3 flex items-center",children:t.jsx("span",{className:"text-xs text-text-3 font-mono truncate",children:v||"••••••••••••••"})}),t.jsx("button",{type:"button",onClick:()=>{O(!1),c("")},className:"h-8 px-3 rounded-md text-xs text-text-3 hover:text-text-1 bg-surface-4 hover:bg-surface-5 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:"Change"})]}):t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("div",{className:"relative flex-1",children:[t.jsx("input",{type:A?"text":"password",value:l,onChange:w=>c(w.target.value),placeholder:e.keyPlaceholder,className:"h-8 w-full rounded-md px-3 pr-8 text-sm bg-surface-1 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent transition-colors duration-100 font-mono",onKeyDown:w=>w.key==="Enter"&&b(),"aria-label":e.keyLabel}),t.jsx("button",{type:"button",onClick:()=>f(!A),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer","aria-label":A?"Hide key":"Show key",children:A?t.jsx(Oo,{className:"w-3.5 h-3.5"}):t.jsx(Hs,{className:"w-3.5 h-3.5"})})]}),t.jsx("button",{type:"button",onClick:b,disabled:!l.trim()||m,className:"h-8 px-4 rounded-md bg-accent text-surface-0 text-xs font-medium hover:bg-accent/80 transition-colors duration-100 cursor-pointer disabled:opacity-40 disabled:pointer-events-none focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:m?"Saving...":"Save"})]})})]})}function cee({providerStatus:e,installedIds:s,onSaveKey:n}){const a=ha.filter(r=>{var l;return s.includes(r.id)||((l=e[r.id])==null?void 0:l.installed)});return a.some(r=>{var l;return(l=e[r.id])==null?void 0:l.authenticated}),t.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Connect your accounts"}),t.jsx("p",{className:"text-sm text-text-2",children:"Add credentials for your installed providers."})]}),t.jsx("div",{className:"flex flex-col gap-4 w-full mb-6",children:a.map(r=>t.jsx(lee,{provider:r,providerStatus:e[r.id]||{},onSaveKey:n},r.id))}),a.length===0&&t.jsx("p",{className:"text-sm text-text-3 text-center",children:"No providers installed yet. Go back to install one."})]})}function Aee({providerStatus:e,installedIds:s,defaultProvider:n,defaultModel:a,onSetDefault:r}){var c;const l=ha.filter(A=>{var f,m;return(s.includes(A.id)||((f=e[A.id])==null?void 0:f.installed))&&((m=e[A.id])==null?void 0:m.authenticated)});return t.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Set your default"}),t.jsx("p",{className:"text-sm text-text-2",children:"Choose which provider and model to use by default. You can switch per-agent anytime."})]}),t.jsxs("div",{className:"flex flex-col gap-3 w-full max-w-md mb-6",children:[l.map(A=>t.jsxs("button",{type:"button",onClick:()=>r(A.id,A.models[0]),className:V("flex items-center gap-4 p-4 rounded-md border transition-all duration-200 text-left cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",n===A.id?"bg-accent/8 border-accent ring-1 ring-accent/30":"bg-surface-2 border-border-subtle hover:bg-surface-3"),children:[t.jsx("div",{className:V("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono shrink-0",A.gradientFrom),children:A.letter}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h3",{className:"text-sm font-semibold text-text-0",children:A.name}),t.jsx("p",{className:"text-2xs text-text-3",children:A.subtitle})]}),t.jsx("div",{className:V("w-5 h-5 rounded-full border-2 flex items-center justify-center transition-colors",n===A.id?"border-accent bg-accent":"border-border"),children:n===A.id&&t.jsx("div",{className:"w-2 h-2 rounded-full bg-surface-0"})})]},A.id)),l.length===0&&t.jsx("p",{className:"text-sm text-text-3 text-center",children:"No authenticated providers. Go back to connect one."})]}),n&&t.jsxs("div",{className:"w-full max-w-md",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 mb-2 block",children:"Model"}),t.jsx("div",{className:"flex flex-wrap gap-2",children:(c=ha.find(A=>A.id===n))==null?void 0:c.models.map(A=>t.jsx("button",{type:"button",onClick:()=>r(n,A),className:V("h-7 px-3 rounded-full text-xs font-medium transition-colors duration-100 cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",a===A?"bg-accent text-surface-0":"bg-surface-4 text-text-2 hover:bg-surface-5 hover:text-text-0"),children:A},A))})]})]})}function dee({providerStatus:e,defaultProvider:s,defaultModel:n,onFinish:a}){var c;const r=ha.filter(A=>{var f;return(f=e[A.id])==null?void 0:f.installed}).length,l=(c=ha.find(A=>A.id===s))==null?void 0:c.name;return t.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[t.jsx(En.div,{initial:{scale:0},animate:{scale:1},transition:{type:"spring",stiffness:300,damping:20},className:"w-20 h-20 rounded-full bg-success/15 flex items-center justify-center",children:t.jsx(Je,{className:"w-10 h-10 text-success",strokeWidth:2.5})}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"You're all set!"}),t.jsxs("p",{className:"text-sm text-text-2",children:[r," provider",r!==1?"s":""," installed",l?`, default: ${l}`:"",n?` (${n})`:""]})]}),t.jsx(En.div,{className:"flex gap-3 mt-4",initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.3},children:t.jsxs("button",{type:"button",onClick:a,className:"h-11 px-8 rounded-full bg-accent text-surface-0 font-semibold text-sm hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-0 flex items-center gap-2",autoFocus:!0,children:[t.jsx(fn,{className:"w-4 h-4"}),"Start Building"]})})]})}const fA=6;function uee(){const e=U(D=>D.dismissOnboarding),s=U(D=>D.installProvider),n=U(D=>D.setDefaultProvider),a=U(D=>D.addToast),[r,l]=p.useState(0),[c,A]=p.useState(1),[f,m]=p.useState(["claude-code"]),[h,g]=p.useState({}),[O,b]=p.useState({}),[v,w]=p.useState(null),[N,Q]=p.useState(null),[S,C]=p.useState(!0),[k,F]=p.useState(null),B=p.useRef(null);p.useEffect(()=>{let D=!1;async function R(){var oe;try{const Z=await fetch("/api/onboarding/status").then(ee=>ee.ok?ee.json():null);if(Z!=null&&Z.providers){const ee={},le=[];for(const ae of Z.providers){const X=ae.authStatus==="authenticated"||ae.authStatus==="key-set";ee[ae.id]={installed:ae.installed,authenticated:X},ae.installed&&le.push(ae.id)}return{status:ee,installedIds:le,workingDir:((oe=Z.config)==null?void 0:oe.defaultWorkingDir)||null}}}catch{}try{const Z=await fetch("/api/providers").then(ee=>ee.ok?ee.json():null);if(Z){const ee={},le=[],ae=Array.isArray(Z)?Z:Z.providers||[];for(const X of ae){const te=X.installed||X.authStatus==="authenticated"||X.authStatus==="key-set"||!1;ee[X.id]={installed:te,authenticated:X.authenticated||!1},te&&le.push(X.id)}return{status:ee,installedIds:le}}}catch{}return null}async function _(){C(!0);let oe=await R();if(!D&&oe&&oe.installedIds.length===0)for(let Z=0;Z<2;Z++){if(await new Promise(ee=>setTimeout(ee,2e3)),D)return;if(oe=await R(),oe&&oe.installedIds.length>0)break}!D&&oe&&(b(oe.status),oe.installedIds.length>0&&m(Z=>[...new Set([...Z,...oe.installedIds])]),oe.workingDir&&!k&&F(oe.workingDir)),D||C(!1)}return _(),()=>{D=!0}},[r]);const T=p.useCallback(()=>{r<fA-1&&(A(1),l(D=>D+1))},[r]),$=p.useCallback(()=>{r>0&&(A(-1),l(D=>D-1))},[r]),M=p.useCallback(()=>{e()},[e]),I=p.useCallback(async()=>{if(k)try{await F(k)}catch{a("error","Failed to set project directory")}e()},[e,k,a]),se=p.useCallback(async D=>{g(R=>({...R,[D]:!0}));try{await s(D),b(R=>({...R,[D]:{...R[D],installed:!0}})),m(R=>R.includes(D)?R:[...R,D])}catch{b(R=>({...R,[D]:{...R[D],failed:!0}}))}finally{g(R=>({...R,[D]:!1}))}},[s]),H=p.useCallback(async(D,R)=>{try{if(!(await fetch(`/api/credentials/${encodeURIComponent(D)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:R})})).ok)throw new Error("Failed to save key");b(oe=>({...oe,[D]:{...oe[D],authenticated:!0,maskedKey:`${R.slice(0,6)}${"•".repeat(20)}`}})),a("success","API key saved")}catch(_){throw a("error","Failed to save key",_.message),_}},[a]),ne=p.useCallback(async(D,R)=>{w(D),Q(R);try{await n(D,R)}catch{}},[n]),K=ha.some(D=>{var R;return(R=O[D.id])==null?void 0:R.installed}),L=ha.some(D=>{var R;return(R=O[D.id])==null?void 0:R.authenticated}),E=r===0||r===1?!0:r===2?K:r===3?L:r===4?!!v:!1;p.useEffect(()=>{const D=R=>{R.key==="Enter"&&r<fA-1&&E&&T(),R.key==="Escape"&&M()};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[r,E,T,M]);const q=[t.jsx(ree,{onNext:T,onSkip:M},"welcome"),t.jsx(oee,{selectedDir:k,onSelectDir:F},"folder"),t.jsx(iee,{providerStatus:O,selected:f,onInstall:se,installing:h,statusChecking:S},"install"),t.jsx(cee,{providerStatus:O,installedIds:f,onSaveKey:H},"auth"),t.jsx(Aee,{providerStatus:O,installedIds:f,defaultProvider:v,defaultModel:N,onSetDefault:ne},"default"),t.jsx(dee,{providerStatus:O,defaultProvider:v,defaultModel:N,onFinish:I},"done")];return t.jsxs("div",{ref:B,className:"fixed inset-0 z-50 bg-gradient-to-b from-surface-0 to-surface-1 flex flex-col font-sans overflow-hidden",children:[JA()&&t.jsx("div",{className:"h-8 w-full electron-drag shrink-0"}),t.jsxs("div",{className:"flex items-center justify-between px-8 py-4 shrink-0",children:[t.jsx(aee,{current:r,total:fA}),r>0&&r<fA-1&&t.jsx("button",{type:"button",onClick:M,className:"text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent rounded px-2 py-1",children:"Skip setup"})]}),t.jsx("div",{className:"flex-1 flex items-center justify-center px-8 py-4 overflow-y-auto",children:t.jsx(Ci,{mode:"wait",custom:c,children:t.jsx(En.div,{custom:c,variants:see,initial:"enter",animate:"center",exit:"exit",transition:nee,className:"w-full",children:q[r]},r)})}),r>0&&r<fA-1&&t.jsxs("div",{className:"flex items-center justify-between px-8 py-8 shrink-0",children:[t.jsxs("button",{type:"button",onClick:$,className:"h-10 px-6 rounded-md text-sm text-text-2 hover:text-text-0 bg-surface-3 hover:bg-surface-4 transition-colors duration-100 cursor-pointer flex items-center gap-1.5 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[t.jsx(Ei,{className:"w-4 h-4"}),"Back"]}),t.jsxs("button",{type:"button",onClick:T,disabled:!E,className:"h-10 px-8 rounded-md text-sm font-medium bg-accent text-surface-0 hover:bg-accent/80 transition-colors duration-100 cursor-pointer disabled:opacity-40 disabled:pointer-events-none flex items-center gap-1.5 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[r===4?"Finish Setup":"Continue",t.jsx(Ct,{className:"w-4 h-4"})]})]})]})}const fee=[{icon:Qs,label:"Federation",desc:"Multi-machine daemon pairing"},{icon:gb,label:"Cloud Teams",desc:"Coming soon"}];function hQ(){var w;const e=U(N=>N.upgradeModalOpen),s=U(N=>N.setUpgradeModalOpen),n=U(N=>N.marketplaceAuthenticated),a=U(N=>N.marketplaceLogin),r=U(N=>N.startCheckout),l=U(N=>N.addToast),[c,A]=p.useState(null),[f,m]=p.useState("monthly"),[h,g]=p.useState(!1);p.useEffect(()=>{e&&!c&&U.getState().fetchSubscriptionPlans().then(N=>A(N)).catch(()=>{})},[e,c]);const O=(w=c==null?void 0:c.pro)==null?void 0:w[f],b=f==="annual"?`$${Math.round(((O==null?void 0:O.price)||96)/12)}/mo`:`$${(O==null?void 0:O.price)||10}/mo`;async function v(){var N;if(!n){a();return}if(!(O!=null&&O.priceId)){zg("https://groovedev.ai/pro"),s(!1);return}g(!0);try{await r(O.priceId),s(!1)}catch(Q){Q.status===401||(N=Q.message)!=null&&N.includes("Not authenticated")?(l("info","Please sign in first"),a()):Q.status===409&&(l("info","You already have a subscription"),s(!1))}finally{g(!1)}}return t.jsx(_t,{open:e,onOpenChange:s,children:t.jsx(zt,{title:"Upgrade to Pro",className:"max-w-[440px]",children:t.jsxs("div",{className:"px-6 py-5",children:[t.jsxs("div",{className:"text-center mb-6",children:[t.jsx("div",{className:"mx-auto mb-3 w-12 h-12 rounded-full bg-accent/10 flex items-center justify-center",children:t.jsx(fn,{size:22,className:"text-accent"})}),t.jsx("h2",{className:"text-lg font-bold text-text-0",children:"Upgrade to Groove Pro"}),t.jsx("p",{className:"text-sm text-text-2 mt-1",children:"Unlock powerful features for your AI workflow"})]}),t.jsx("div",{className:"space-y-3 mb-6",children:fee.map(N=>t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:t.jsx(N.icon,{size:15,className:"text-accent"})}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-medium text-text-0",children:N.label}),t.jsx("p",{className:"text-2xs text-text-3",children:N.desc})]}),t.jsx(Je,{size:14,className:"text-success ml-auto flex-shrink-0"})]},N.label))}),t.jsxs("div",{className:"flex gap-1 mb-5 bg-surface-3 p-0.5 rounded-md",children:[t.jsx("button",{type:"button",onClick:()=>m("monthly"),className:V("flex-1 h-8 rounded text-xs font-medium transition-colors cursor-pointer",f==="monthly"?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:"Monthly"}),t.jsxs("button",{type:"button",onClick:()=>m("annual"),className:V("flex-1 h-8 rounded text-xs font-medium transition-colors cursor-pointer",f==="annual"?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:["Annual",t.jsx("span",{className:"ml-1 text-success text-2xs",children:"Save 20%"})]})]}),t.jsxs("div",{className:"text-center mb-5",children:[t.jsx("span",{className:"text-3xl font-bold text-text-0",children:b}),f==="annual"&&t.jsxs("p",{className:"text-2xs text-text-3 mt-1",children:["Billed $",(O==null?void 0:O.price)||96,"/year"]})]}),t.jsx("button",{type:"button",onClick:v,disabled:h,className:"w-full h-10 rounded-lg bg-accent text-white font-semibold text-sm hover:bg-accent/90 transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none flex items-center justify-center gap-2",children:h?"Processing...":n?t.jsxs(t.Fragment,{children:[t.jsx(fn,{size:15})," Subscribe — ",b]}):t.jsxs(t.Fragment,{children:[t.jsx(pN,{size:15})," Sign in to subscribe"]})}),t.jsx("button",{type:"button",onClick:()=>s(!1),className:"w-full mt-2 text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer py-1",children:"Maybe later"})]})})})}function xee(){const e=U(l=>l.dataSharingModalOpen),s=U(l=>l.setTrainingOptIn),n=U(l=>l.dismissDataSharingModal),[a,r]=p.useState(!1);return t.jsx(_t,{open:e,children:t.jsxs(zt,{className:"max-w-md",description:"Help improve Groove by sharing usage data",onInteractOutside:l=>l.preventDefault(),onEscapeKeyDown:l=>l.preventDefault(),children:[t.jsxs("div",{className:"relative bg-gradient-to-br from-accent/5 to-transparent px-6 pt-8 pb-6 text-center",children:[t.jsx("div",{className:"flex justify-center mb-3",children:t.jsx("div",{className:"w-14 h-14 rounded-xl bg-accent/10 flex items-center justify-center",children:t.jsx(fn,{size:32,className:"text-accent"})})}),t.jsx(Lx,{className:"text-xl font-bold text-text-0 font-sans",children:"Help Build a Better Groove"}),t.jsx("p",{className:"text-sm text-text-2 font-sans mt-2 max-w-md mx-auto",children:"We collect errors and usage reports to improve the quality of Groove for everyone."})]}),t.jsx("div",{className:"px-6 pt-4",children:t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2/30 p-4",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[t.jsx(Pn,{size:14,className:"text-text-2"}),t.jsx("span",{className:"text-xs font-semibold uppercase text-text-3 tracking-wider font-sans",children:"What We Never Collect"})]}),t.jsx("div",{className:"space-y-1.5",children:["Your source code or file contents","API keys, passwords, or credentials","Personal information — emails, names, file paths","Anything that could identify you, your IP or projects"].map(l=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ze,{size:12,className:"text-danger flex-shrink-0"}),t.jsx("span",{className:"text-xs text-text-1 font-sans",children:l})]},l))}),t.jsx("p",{className:"text-xs text-text-0 font-sans font-medium mt-3",children:"PII is automatically scrubbed before any data leaves your machine."})]})}),t.jsxs("div",{className:"border-t border-border-subtle mt-5 pt-4 pb-1 px-6",children:[t.jsxs("button",{type:"button",onClick:()=>s(!0),className:"w-full h-10 rounded-lg bg-accent text-white font-semibold text-sm hover:bg-accent/90 transition-colors cursor-pointer flex items-center justify-center gap-2",children:[t.jsx(fn,{size:15}),"Turn On Sharing"]}),t.jsx("div",{className:"text-center mt-2.5",children:t.jsx("button",{type:"button",onClick:()=>n(a),className:"text-xs text-text-3 hover:text-text-1 transition-colors font-sans cursor-pointer",children:"Maybe Later"})}),t.jsxs("div",{className:"flex items-center justify-center gap-2 mt-3",children:[t.jsx("input",{type:"checkbox",id:"data-sharing-dismiss",checked:a,onChange:l=>r(l.target.checked),className:"w-3.5 h-3.5 rounded border-border accent-accent cursor-pointer"}),t.jsx("label",{htmlFor:"data-sharing-dismiss",className:"text-2xs text-text-3 font-sans cursor-pointer select-none",children:"Don't show this again"})]}),t.jsx("p",{className:"text-center text-2xs text-text-4 font-sans mt-2 mb-1",children:"You can always enable this later in Settings"})]})]})})}function mee(){const e=U(k=>k.recentProjects),s=U(k=>k.setProjectDir),n=U(k=>k.removeRecentProject),a=U(k=>k.remoteHomedir),r=U(k=>k.savedTunnels),l=U(k=>k.fetchTunnels),c=U(k=>k.deleteTunnel),A=U(k=>k.connectTunnel),f=U(k=>k.disconnectTunnel),m=U(k=>k.toggleQuickConnect),h=U(k=>k.addToast),[g,O]=p.useState(!1),[b,v]=p.useState(null);p.useEffect(()=>{l()},[l]);const w=(e||[]).slice(0,8),N=w.length>0,Q=r.length>0,S=N||Q;async function C(k){var F,B;if(k.active){(B=(F=window.groove)==null?void 0:F.remote)!=null&&B.openWindow?window.groove.remote.openWindow(k.localPort,k.name):window.open(`http://localhost:${k.localPort}?instance=${encodeURIComponent(k.name)}`,"_blank");return}v(k.id);try{await A(k.id)}catch(T){h("error","Connection failed",(T==null?void 0:T.message)||"Unknown error")}v(null)}return t.jsxs("div",{className:"fixed inset-0 z-50 overflow-y-auto welcome-bg",children:[t.jsx("div",{className:"pointer-events-none fixed top-0 left-1/2 -translate-x-1/2 w-[800px] h-[600px] rounded-full bg-accent/[0.03] blur-[120px]"}),t.jsxs("div",{className:"relative min-h-screen flex flex-col items-center px-8 pt-[14vh] pb-12 max-sm:pt-[8vh] max-sm:px-5",children:[t.jsxs("div",{className:"flex flex-col items-center text-center mb-14",children:[t.jsxs("div",{className:"relative mb-8",children:[t.jsx("div",{className:"absolute -inset-10 rounded-full bg-accent/[0.06] blur-3xl animate-welcome-breathe"}),t.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/25 animate-welcome-ring"}),t.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/15 animate-welcome-ring-delayed"}),t.jsx("div",{className:"relative w-[88px] h-[88px] rounded-full bg-accent/[0.07] border border-accent/20 flex items-center justify-center welcome-logo-shadow",children:t.jsx("img",{src:"/favicon.png",className:"w-12 h-12 rounded-full",alt:"Groove"})})]}),t.jsx("h1",{className:"text-4xl font-bold text-text-0 tracking-tight mb-3 font-sans max-sm:text-3xl",children:"Welcome to Groove"}),t.jsxs("p",{className:"text-base text-text-2 font-sans max-w-md leading-relaxed max-sm:text-sm",children:["The most powerful agenticOS ever built.",t.jsx("br",{className:"max-sm:hidden"}),t.jsx("span",{className:"max-sm:hidden",children:" "}),"Spawn fast. Stay aware. Never lose context."]})]}),t.jsxs("div",{className:"w-full max-w-2xl grid grid-cols-2 gap-4 mb-14 max-sm:grid-cols-1 max-sm:max-w-sm",children:[t.jsxs("button",{onClick:()=>O(!0),className:"group relative overflow-hidden rounded-xl border border-accent/20 bg-gradient-to-br from-accent/[0.08] via-accent/[0.03] to-transparent p-6 text-left hover:border-accent/40 hover:from-accent/[0.14] hover:via-accent/[0.06] transition-all duration-300 cursor-pointer",children:[t.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/15 border border-accent/20 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300",children:t.jsx(Vs,{size:24,className:"text-accent"})}),t.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Open Project"}),t.jsx("div",{className:"text-sm text-text-2 font-sans",children:"Browse the filesystem to pick a project"}),t.jsxs("div",{className:"flex items-center gap-1 text-xs text-accent font-sans mt-4 opacity-0 group-hover:opacity-100 transition-opacity duration-300",children:["Browse files ",t.jsx(So,{size:12})]})]}),t.jsxs("button",{onClick:m,className:"group relative overflow-hidden rounded-xl border border-border bg-surface-1 p-6 text-left hover:border-accent/30 hover:bg-surface-2 transition-all duration-300 cursor-pointer",children:[t.jsx("div",{className:"w-12 h-12 rounded-xl bg-surface-4 border border-border-subtle flex items-center justify-center mb-4 group-hover:scale-110 group-hover:bg-accent/10 group-hover:border-accent/20 transition-all duration-300",children:t.jsx(wi,{size:24,className:"text-text-2 group-hover:text-accent transition-colors duration-300"})}),t.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Connect to Remote"}),t.jsx("div",{className:"text-sm text-text-2 font-sans",children:"SSH tunnel to a server running Groove"}),t.jsxs("div",{className:"flex items-center gap-1 text-xs text-accent font-sans mt-4 opacity-0 group-hover:opacity-100 transition-opacity duration-300",children:["Setup connection ",t.jsx(So,{size:12})]})]})]}),S&&t.jsxs("div",{className:V("w-full max-w-4xl gap-6 mb-14 max-sm:flex max-sm:flex-col max-sm:gap-6",N&&Q?"grid grid-cols-2":"flex justify-center"),children:[N&&t.jsxs("div",{className:V(!Q&&"w-full max-w-lg"),children:[t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsx(va,{size:13,className:"text-text-3"}),t.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Recent Projects"})]}),t.jsx("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:w.map(k=>t.jsxs("div",{className:"group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg bg-surface-3 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/10 transition-colors",children:t.jsx(Vs,{size:14,className:"text-text-3 group-hover:text-accent transition-colors"})}),t.jsxs("button",{onClick:()=>s(k.path),className:"flex-1 min-w-0 text-left cursor-pointer",children:[t.jsx("div",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:k.name}),t.jsx("div",{className:"text-2xs font-mono text-text-4 truncate",children:k.path})]}),t.jsx("button",{onClick:F=>{F.stopPropagation(),n(k.path)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all flex-shrink-0",title:"Remove from recent",children:t.jsx(Ze,{size:14})})]},k.path))})]}),Q&&t.jsxs("div",{className:V(!N&&"w-full max-w-lg"),children:[t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsx(Qs,{size:13,className:"text-text-3"}),t.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"SSH Connections"})]}),t.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:[r.map(k=>t.jsxs("div",{className:V("group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",b===k.id&&"opacity-60 pointer-events-none"),children:[t.jsx("div",{className:V("w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0 transition-colors",k.active?"bg-success/10":"bg-surface-3 group-hover:bg-accent/10"),children:t.jsx(Qs,{size:14,className:V("transition-colors",k.active?"text-success":"text-text-3 group-hover:text-accent")})}),t.jsxs("button",{onClick:()=>C(k),disabled:b===k.id,className:"flex-1 min-w-0 text-left cursor-pointer",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:k.name}),k.active&&t.jsx(ss,{status:"running",size:"sm"})]}),t.jsxs("div",{className:"text-2xs font-mono text-text-4 truncate",children:[k.user,"@",k.host]})]}),t.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[b===k.id?t.jsx(Ie,{size:14,className:"text-text-3 animate-spin"}):k.active?t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>C(k),className:"opacity-0 group-hover:opacity-100 flex items-center gap-0.5 text-2xs text-success hover:text-success/80 cursor-pointer transition-all font-sans",children:[t.jsx(Gs,{size:11})," Open"]}),t.jsx("button",{onClick:async()=>{await f(k.id),h("info","Disconnected",k.name)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all",title:"Disconnect",children:t.jsx(Rx,{size:12})})]}):null,t.jsx("button",{onClick:F=>{F.stopPropagation(),c(k.id)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all flex-shrink-0",title:"Remove connection",children:t.jsx(Ze,{size:14})})]})]},k.id)),t.jsxs("button",{onClick:m,className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer transition-colors w-full px-4 py-2.5 hover:bg-surface-2/30",children:[t.jsx(At,{size:11})," Add Connection"]})]})]})]}),t.jsx("div",{className:"mt-auto pt-8 flex flex-col items-center gap-4",children:t.jsxs("div",{className:"flex items-center gap-5 text-xs text-text-4 font-sans",children:[t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘K"}),t.jsx("span",{children:"palette"})]}),t.jsx("span",{className:"text-border",children:"·"}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘N"}),t.jsx("span",{children:"spawn"})]}),t.jsx("span",{className:"text-border",children:"·"}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘J"}),t.jsx("span",{children:"terminal"})]})]})})]}),t.jsx(Ac,{open:g,onOpenChange:O,currentPath:a||"/home",homePath:a,onSelect:k=>{O(!1),s(k)}}),t.jsx(AB,{}),t.jsx(TN,{})]})}const hee={js:"text-text-2",jsx:"text-text-2",ts:"text-text-2",tsx:"text-text-2",css:"text-text-3",html:"text-text-3",json:"text-text-3",md:"text-text-3",py:"text-text-2",rs:"text-text-3",go:"text-text-2",sh:"text-text-3",yaml:"text-text-3",yml:"text-text-3",sql:"text-text-3",xml:"text-text-3",svg:"text-text-3"};function pee(e){var n;const s=(n=e.split(".").pop())==null?void 0:n.toLowerCase();return hee[s]||"text-text-3"}function gee({x:e,y:s,items:n,onClose:a}){const r=p.useRef(null);return p.useEffect(()=>{function l(c){r.current&&!r.current.contains(c.target)&&a()}return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[a]),t.jsx("div",{ref:r,className:"fixed z-50 min-w-[160px] py-1 bg-surface-2 border border-border rounded-lg shadow-xl",style:{left:e,top:s},children:n.map((l,c)=>l.separator?t.jsx("div",{className:"h-px bg-border-subtle my-1"},c):t.jsxs("button",{onClick:()=>{l.action(),a()},className:V("w-full flex items-center gap-2.5 px-3 py-1.5 text-xs font-sans text-left cursor-pointer transition-colors",l.danger?"text-danger hover:bg-danger/10":"text-text-1 hover:bg-surface-5"),children:[l.icon&&t.jsx(l.icon,{size:12,className:l.danger?"text-danger":"text-text-3"}),l.label]},c))})}function bx({defaultValue:e="",placeholder:s,onSubmit:n,onCancel:a,depth:r=0}){const[l,c]=p.useState(e),A=p.useRef(null);p.useEffect(()=>{var m,h;(m=A.current)==null||m.focus(),e&&((h=A.current)==null||h.select())},[e]);function f(m){if(m.key==="Enter"){const h=l.trim();h&&n(h)}m.key==="Escape"&&a()}return t.jsx("div",{className:"flex items-center py-0.5",style:{paddingLeft:r*16+8},children:t.jsx("input",{ref:A,value:l,onChange:m=>c(m.target.value),onKeyDown:f,onBlur:a,placeholder:s,className:"w-full h-5 px-1.5 text-xs bg-surface-0 border border-accent rounded text-text-0 font-sans focus:outline-none"})})}function Oee({status:e}){if(!e)return null;const s=e==="A"||e==="?"?"bg-success":e==="D"?"bg-danger":"bg-warning";return t.jsx("span",{className:V("w-1.5 h-1.5 rounded-full flex-shrink-0",s)})}function bee(e){const s=document.createElement("a");s.href=`/api/files/download?path=${encodeURIComponent(e)}`,s.download=e.split("/").pop(),document.body.appendChild(s),s.click(),s.remove()}function p4({entry:e,depth:s=0,activePath:n,onFileClick:a,onDirToggle:r,expanded:l,onContextMenu:c,dragState:A,onDragStartEntry:f,onDragEndEntry:m,onSetDragOver:h,onDropOnDir:g,gitStatusMap:O}){const b=e.type==="dir",v=n===e.path,w=l.has(e.path),N=s*16+8,Q=(A==null?void 0:A.draggingPath)===e.path,S=b&&(A==null?void 0:A.dragOverPath)===e.path,C=b?null:O==null?void 0:O[e.path];function k(F){F.preventDefault(),F.stopPropagation(),c(F,e)}return t.jsxs("button",{draggable:!0,onDragStart:F=>{F.dataTransfer.setData("application/json",JSON.stringify({path:e.path,name:e.name,type:e.type})),F.dataTransfer.effectAllowed="move",f(e.path)},onDragEnd:m,onDragOver:b?F=>{F.preventDefault(),F.stopPropagation(),h(e.path)}:void 0,onDrop:b?F=>g(e.path,F):void 0,onClick:()=>b?r(e.path):a(e.path),onDoubleClick:k,onContextMenu:k,className:V("w-full flex items-center gap-1.5 py-[3px] text-xs font-sans cursor-pointer","hover:bg-surface-5 transition-colors text-left select-none",v&&"bg-accent/10 text-text-0",!v&&"text-text-1",Q&&"opacity-50",S&&"bg-accent/15 ring-1 ring-accent/50 rounded"),style:{paddingLeft:N},children:[b?t.jsxs(t.Fragment,{children:[w?t.jsx(dt,{size:12,className:"text-text-4 flex-shrink-0"}):t.jsx(Ct,{size:12,className:"text-text-4 flex-shrink-0"}),w?t.jsx(Vs,{size:14,className:"text-accent flex-shrink-0"}):t.jsx(Pi,{size:14,className:"text-text-3 flex-shrink-0"})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-3"}),t.jsx(Eo,{size:14,className:V("flex-shrink-0",pee(e.name))})]}),t.jsx("span",{className:"truncate flex-1",children:e.name}),C&&t.jsx(Oee,{status:C})]})}function g4({dirPath:e,depth:s,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:m,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:w}){const N=c[e]||[];return p.useEffect(()=>{r.has(e)&&!c[e]&&A(e)},[r,e,c,A]),r.has(e)?t.jsxs(t.Fragment,{children:[(m==null?void 0:m.parentPath)===e&&t.jsx(bx,{placeholder:m.type==="file"?"filename.ext":"folder-name",onSubmit:m.onSubmit,onCancel:m.onCancel,depth:s}),N.map(Q=>t.jsxs("div",{children:[(m==null?void 0:m.renamePath)===Q.path?t.jsx(bx,{defaultValue:Q.name,onSubmit:m.onSubmit,onCancel:m.onCancel,depth:s}):t.jsx(p4,{entry:Q,depth:s,activePath:n,onFileClick:a,onDirToggle:l,expanded:r,onContextMenu:f,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:w}),Q.type==="dir"&&t.jsx(g4,{dirPath:Q.path,depth:s+1,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:m,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:w})]},Q.path))]}):null}function vee({rootDir:e,onCollapse:s}){const n=U(_=>_.editorTreeCache),a=U(_=>_.editorActiveFile),r=U(_=>_.openFile),l=U(_=>_.fetchTreeDir),c=U(_=>_.addToast),[A,f]=p.useState(new Set([""])),[m,h]=p.useState(""),[g,O]=p.useState(null),[b,v]=p.useState(null),[w,N]=p.useState({draggingPath:null,dragOverPath:null}),[Q,S]=p.useState([]);p.useEffect(()=>{l("")},[l,e]),p.useEffect(()=>{G.get("/files/git-status").then(_=>{S(_.entries||[])}).catch(()=>S([]))},[e]);const C={};for(const _ of Q)C[_.path]=_.status;function k(_){f(oe=>{const Z=new Set(oe);return Z.has(_)?Z.delete(_):Z.add(_),Z})}function F(){f(new Set([""]))}function B(_){N({draggingPath:_,dragOverPath:null})}function T(){N({draggingPath:null,dragOverPath:null})}function $(_){N(oe=>oe.dragOverPath===_?oe:{...oe,dragOverPath:_})}async function M(_,oe){var ae,X;if(oe.preventDefault(),oe.stopPropagation(),N({draggingPath:null,dragOverPath:null}),((X=(ae=oe.dataTransfer)==null?void 0:ae.files)==null?void 0:X.length)>0){q(_,Array.from(oe.dataTransfer.files));return}let Z;try{Z=JSON.parse(oe.dataTransfer.getData("application/json"))}catch{return}if(!(Z!=null&&Z.path))return;if(Z.type==="dir"&&(_===Z.path||_.startsWith(Z.path+"/"))){c("error","Cannot move a folder into itself");return}const ee=H(Z.path);if(ee===_)return;const le=_?`${_}/${Z.name}`:Z.name;try{await G.post("/files/rename",{oldPath:Z.path,newPath:le}),l(ee),l(_),c("success",`Moved ${Z.name} to ${_||"/"}`)}catch(te){c("error","Move failed",te.message)}}function I(_,oe){O({x:_.clientX,y:_.clientY,entry:oe})}function se(_){_.preventDefault(),O({x:_.clientX,y:_.clientY,entry:{type:"dir",path:"",name:"root"}})}function H(_){const oe=_.split("/");return oe.pop(),oe.join("/")}async function ne(_){f(oe=>new Set([...oe,_])),v({type:"file",parentPath:_,onSubmit:async oe=>{const Z=_?`${_}/${oe}`:oe;try{await G.post("/files/create",{path:Z,content:""}),l(_),r(Z),c("success",`Created ${oe}`)}catch(ee){c("error","Create failed",ee.message)}v(null)},onCancel:()=>v(null)})}async function K(_){f(oe=>new Set([...oe,_])),v({type:"folder",parentPath:_,onSubmit:async oe=>{const Z=_?`${_}/${oe}`:oe;try{await G.post("/files/mkdir",{path:Z}),l(_),f(ee=>new Set([...ee,Z])),c("success",`Created ${oe}/`)}catch(ee){c("error","Create folder failed",ee.message)}v(null)},onCancel:()=>v(null)})}async function L(_){v({type:"rename",renamePath:_.path,onSubmit:async oe=>{const Z=H(_.path),ee=Z?`${Z}/${oe}`:oe;try{await G.post("/files/rename",{oldPath:_.path,newPath:ee}),l(Z),c("success",`Renamed to ${oe}`)}catch(le){c("error","Rename failed",le.message)}v(null)},onCancel:()=>v(null)})}async function E(_){const oe=_.type==="dir"?`folder "${_.name}" and all contents`:`"${_.name}"`;if(window.confirm(`Delete ${oe}?`))try{await G.delete(`/files/delete?path=${encodeURIComponent(_.path)}`),l(H(_.path)),c("success",`Deleted ${_.name}`)}catch(Z){c("error","Delete failed",Z.message)}}async function q(_,oe){const Z=[];for(const ee of oe){const le=await new Promise((ae,X)=>{const te=new FileReader;te.onload=()=>ae(te.result.split(",")[1]),te.onerror=X,te.readAsDataURL(ee)});Z.push({name:ee.name,content:le})}try{const ee=await G.post("/files/upload",{dir:_,files:Z});c("success",`Uploaded ${ee.total} file${ee.total!==1?"s":""}`),l(_)}catch(ee){c("error","Upload failed",ee.message)}}function D(_){const oe=_.type==="dir",Z=[];return oe&&(Z.push({icon:Ml,label:"New File",action:()=>ne(_.path)}),Z.push({icon:BA,label:"New Folder",action:()=>K(_.path)})),_.name!=="root"?(oe||Z.push({icon:Zs,label:"Download",action:()=>bee(_.path)}),Z.length>0&&Z.push({separator:!0}),Z.push({icon:Fo,label:"Rename",action:()=>L(_)}),Z.push({icon:qt,label:"Delete",danger:!0,action:()=>E(_)})):(Z.length=0,Z.push({icon:Ml,label:"New File",action:()=>ne("")}),Z.push({icon:BA,label:"New Folder",action:()=>K("")})),Z}const R=n[""]||[];return t.jsxs("div",{className:"flex flex-col h-full bg-surface-1",onContextMenu:se,children:[t.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border-subtle",children:[t.jsxs("div",{className:"flex-1 relative",children:[t.jsx(Ms,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-4"}),t.jsx("input",{value:m,onChange:_=>h(_.target.value),placeholder:"Filter...",className:"w-full h-6 pl-6 pr-2 text-xs bg-surface-0 border border-border-subtle rounded text-text-1 placeholder:text-text-4 focus:outline-none focus:border-accent font-sans"})]}),t.jsx("button",{onClick:()=>ne(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New file",children:t.jsx(Ml,{size:12})}),t.jsx("button",{onClick:()=>K(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New folder",children:t.jsx(BA,{size:12})}),t.jsx("button",{onClick:()=>l(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Refresh",children:t.jsx(Ks,{size:12})}),t.jsx("button",{onClick:F,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse all",children:t.jsx(lN,{size:12})}),s&&t.jsx("button",{onClick:s,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse sidebar",children:t.jsx(Px,{size:12})})]}),t.jsx(bt,{className:"flex-1",children:t.jsxs("div",{className:"py-1",onDragOver:_=>{_.preventDefault(),w.draggingPath&&$(null)},onDrop:_=>M("",_),children:[(b==null?void 0:b.parentPath)===""&&t.jsx(bx,{placeholder:b.type==="file"?"filename.ext":"folder-name",onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}),R.filter(_=>!m||_.name.toLowerCase().includes(m.toLowerCase())).map(_=>t.jsxs("div",{children:[(b==null?void 0:b.renamePath)===_.path?t.jsx(bx,{defaultValue:_.name,onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}):t.jsx(p4,{entry:_,depth:0,activePath:a,onFileClick:r,onDirToggle:k,expanded:A,onContextMenu:I,dragState:w,onDragStartEntry:B,onDragEndEntry:T,onSetDragOver:$,onDropOnDir:M,gitStatusMap:C}),_.type==="dir"&&t.jsx(g4,{dirPath:_.path,depth:1,activePath:a,onFileClick:r,expanded:A,onDirToggle:k,treeCache:n,fetchTreeDir:l,onContextMenu:I,inlineInput:b,dragState:w,onDragStartEntry:B,onDragEndEntry:T,onSetDragOver:$,onDropOnDir:M,gitStatusMap:C})]},_.path)),R.length===0&&!m&&t.jsxs("div",{className:"px-3 py-6 text-center",children:[t.jsx("p",{className:"text-xs text-text-4",children:"No files found"}),t.jsx("button",{onClick:()=>l(""),className:"mt-2 text-xs text-accent hover:underline cursor-pointer",children:"Retry"})]})]})}),g&&t.jsx(gee,{x:g.x,y:g.y,items:D(g.entry),onClose:()=>O(null)})]})}function yee(){const e=U(w=>w.editorOpenTabs),s=U(w=>w.editorActiveFile),n=U(w=>w.editorFiles),a=U(w=>w.setActiveFile),r=U(w=>w.closeFile),l=p.useRef(null),[c,A]=p.useState(!1),f=p.useCallback(()=>{const w=l.current;w&&A(w.scrollWidth>w.clientWidth)},[]);p.useEffect(()=>{f();const w=l.current;if(!w)return;const N=new ResizeObserver(f);return N.observe(w),()=>N.disconnect()},[f,e.length]);function m(){var w;(w=l.current)==null||w.scrollBy({left:-120,behavior:"smooth"})}function h(){var w;(w=l.current)==null||w.scrollBy({left:120,behavior:"smooth"})}function g(w){e.filter(N=>N!==w).forEach(N=>r(N))}function O(){[...e].forEach(w=>r(w))}function b(w){const N=e.indexOf(w);e.slice(N+1).forEach(Q=>r(Q))}function v(w){var N;(N=navigator.clipboard)==null||N.writeText(w)}return e.length===0?null:t.jsxs("div",{className:"flex items-stretch h-9 bg-surface-3 border-b border-border-subtle flex-shrink-0",children:[c&&t.jsx("button",{onClick:m,className:"flex-shrink-0 px-1 h-full text-text-4 hover:text-text-1 hover:bg-surface-4 transition-colors cursor-pointer",children:t.jsx(Ei,{size:14})}),t.jsx("div",{ref:l,className:"flex items-stretch flex-1 min-w-0 overflow-x-auto scrollbar-none scroll-smooth",style:{scrollSnapType:"x mandatory"},children:e.map(w=>{const N=w===s,Q=n[w],S=Q&&Q.content!==Q.originalContent,C=w.split("/").pop();return t.jsxs(gv,{children:[t.jsx(Ov,{asChild:!0,children:t.jsxs("div",{className:V("flex items-center gap-1.5 px-3 text-xs font-sans cursor-pointer select-none","border-r border-white/5","transition-colors duration-75 flex-shrink-0",N?"bg-surface-0 text-text-0 border-b border-b-accent":"bg-surface-3 text-text-4 hover:text-text-1 hover:bg-surface-4 border-b border-b-transparent"),style:{scrollSnapAlign:"start"},onClick:()=>a(w),onAuxClick:k=>{k.button===1&&(k.preventDefault(),r(w))},children:[t.jsx("span",{className:"truncate max-w-[120px]",children:C}),S&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-warning flex-shrink-0"}),t.jsx("button",{onClick:k=>{k.stopPropagation(),r(w)},className:"p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 transition-colors cursor-pointer ml-0.5",children:t.jsx(Ze,{size:12})})]})}),t.jsxs(bv,{children:[t.jsxs(ma,{onSelect:()=>r(w),children:[t.jsx(Ze,{size:12,className:"text-text-3"})," Close"]}),t.jsxs(ma,{onSelect:()=>g(w),children:[t.jsx(Kg,{size:12,className:"text-text-3"})," Close Others"]}),t.jsxs(ma,{onSelect:()=>O(),children:[t.jsx(Kg,{size:12,className:"text-text-3"})," Close All"]}),t.jsxs(ma,{onSelect:()=>b(w),children:[t.jsx(Ct,{size:12,className:"text-text-3"})," Close to the Right"]}),t.jsx(vv,{}),t.jsxs(ma,{onSelect:()=>v(w),children:[t.jsx(za,{size:12,className:"text-text-3"})," Copy Path"]})]})]},w)})}),c&&t.jsx("button",{onClick:h,className:"flex-shrink-0 px-1 h-full text-text-4 hover:text-text-1 hover:bg-surface-4 transition-colors cursor-pointer",children:t.jsx(Ct,{size:14})})]})}const wee={javascript:"JavaScript",typescript:"TypeScript",css:"CSS",html:"HTML",json:"JSON",markdown:"Markdown",python:"Python"},O4=Object.keys(wo),b4=O4.filter(e=>!["githubLight","vscodeLight","eclipse","xcodeLight","solarizedLight","gruvboxLight","materialLight","duotoneLight","quietlight","bbedit","tokyoNightDay","basicLight"].includes(e)),jee=O4.filter(e=>!b4.includes(e));function Qee({cursorPos:e,language:s}){var A;const n=U(f=>f.editorTheme),a=U(f=>f.setEditorTheme),[r,l]=p.useState(!1),c=p.useRef(null);return p.useEffect(()=>{if(!r)return;function f(m){c.current&&!c.current.contains(m.target)&&l(!1)}return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[r]),t.jsxs("div",{className:"flex items-center justify-between h-6 px-3 bg-surface-1 border-t border-border-subtle text-2xs font-sans text-text-3 flex-shrink-0 select-none",children:[t.jsx("div",{className:"flex items-center gap-3",children:t.jsxs("span",{children:["Ln ",e.line,", Col ",e.col]})}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"relative",ref:c,children:[t.jsxs("button",{onClick:()=>l(!r),className:"flex items-center gap-1.5 hover:text-text-0 transition-colors cursor-pointer",children:[t.jsx(SM,{size:10}),t.jsx("span",{children:((A=wo[n])==null?void 0:A.label)||n})]}),r&&t.jsxs("div",{className:"absolute bottom-6 right-0 w-48 max-h-72 overflow-y-auto rounded-md border border-border bg-surface-2 shadow-xl z-50 py-1 scrollbar-thin",children:[t.jsx("div",{className:"px-2 py-1 text-2xs text-text-4 font-semibold uppercase tracking-wider",children:"Dark"}),b4.map(f=>t.jsx("button",{onClick:()=>{a(f),l(!1)},className:V("w-full text-left px-3 py-1 text-2xs font-sans cursor-pointer transition-colors",f===n?"text-accent bg-accent/10":"text-text-1 hover:bg-surface-4"),children:wo[f].label},f)),t.jsx("div",{className:"px-2 py-1 mt-1 text-2xs text-text-4 font-semibold uppercase tracking-wider border-t border-border-subtle",children:"Light"}),jee.map(f=>t.jsx("button",{onClick:()=>{a(f),l(!1)},className:V("w-full text-left px-3 py-1 text-2xs font-sans cursor-pointer transition-colors",f===n?"text-accent bg-accent/10":"text-text-1 hover:bg-surface-4"),children:wo[f].label},f))]})]}),t.jsx("span",{className:"cursor-default",children:wee[s]||s||"Plain Text"}),t.jsx("span",{children:"Spaces: 2"}),t.jsx("span",{children:"UTF-8"})]})]})}function See({currentLine:e,onGoto:s,onClose:n}){const[a,r]=p.useState(""),l=p.useRef(null);p.useEffect(()=>{var A;(A=l.current)==null||A.focus()},[]);function c(A){if(A.key==="Enter"){const f=parseInt(a,10);f>0&&s(f),n()}A.key==="Escape"&&n()}return t.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20 flex items-center gap-2 bg-surface-2 border border-border rounded-lg shadow-xl p-2",children:[t.jsx("label",{className:"text-2xs font-sans text-text-3 whitespace-nowrap",children:"Go to Line:"}),t.jsx("input",{ref:l,value:a,onChange:A=>r(A.target.value),onKeyDown:c,onBlur:n,placeholder:String(e),className:"w-20 h-6 px-2 text-xs bg-surface-0 border border-border-subtle rounded text-text-0 font-mono focus:outline-none focus:border-accent"})]})}function Nee({path:e}){if(!e)return null;const s=e.split("/").filter(Boolean);return t.jsx("div",{className:"flex items-center h-7 px-3 bg-surface-2 border-b border-border-subtle text-2xs font-sans text-text-3 overflow-hidden flex-shrink-0 select-none",children:s.map((n,a)=>{const r=a===s.length-1;return t.jsxs("span",{className:"flex items-center min-w-0",children:[a>0&&t.jsx(Ct,{size:10,className:"mx-0.5 flex-shrink-0 text-text-4"}),t.jsx("span",{className:r?"text-text-1 font-medium truncate":"hover:text-text-1 cursor-pointer truncate transition-colors",children:n})]},a)})})}function Bee(e){var n;const s=(n=e==null?void 0:e.split(".").pop())==null?void 0:n.toLowerCase();return s==="html"||s==="htm"}const Cee=240,kee=160,Tee=400;function Uee(){const e=U(H=>H.editorActiveFile),s=U(H=>H.editorFiles),n=U(H=>H.updateFileContent),a=U(H=>H.saveFile),r=U(H=>H.editorSidebarWidth),l=U(H=>H.setEditorSidebarWidth),c=U(H=>H.projectDir),[A,f]=p.useState(""),[m,h]=p.useState(!1),[g,O]=p.useState(0),[b,v]=p.useState({line:1,col:1}),[w,N]=p.useState(!1),[Q,S]=p.useState(!1),C=p.useRef(null),k=p.useRef(!1),F=p.useRef(0),B=p.useRef(0);p.useEffect(()=>{G.get("/files/root").then(H=>f(H.root||"")).catch(()=>{})},[c]),p.useEffect(()=>{h(!1)},[e]),p.useEffect(()=>{function H(ne){(ne.metaKey||ne.ctrlKey)&&ne.key==="g"&&(ne.preventDefault(),N(!0))}return document.addEventListener("keydown",H),()=>document.removeEventListener("keydown",H)},[]);const T=p.useCallback(H=>{H.preventDefault(),k.current=!0,F.current=H.clientX,B.current=r;function ne(L){if(!k.current)return;const E=L.clientX-F.current,q=Math.min(Math.max(B.current+E,kee),Tee);l(q)}function K(){k.current=!1,document.removeEventListener("mousemove",ne),document.removeEventListener("mouseup",K)}document.addEventListener("mousemove",ne),document.addEventListener("mouseup",K)},[r,l]);function $(H){const ne=C.current;if(!ne)return;const K=ne.state.doc.line(Math.min(H,ne.state.doc.lines));ne.dispatch({selection:{anchor:K.from},scrollIntoView:!0}),ne.focus()}const M=e?s[e]:null,I=e&&s5(e),se=e&&Bee(e);return t.jsxs("div",{className:"flex h-full",children:[t.jsxs("div",{className:V("relative flex-shrink-0 border-r border-border transition-all duration-200 overflow-hidden",Q&&"w-0 border-r-0"),style:Q?void 0:{width:r},children:[t.jsx(vee,{rootDir:A,onCollapse:()=>S(!0)}),t.jsx("div",{className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:T,onDoubleClick:()=>l(Cee)})]}),Q&&t.jsx("button",{onClick:()=>S(!1),className:"flex-shrink-0 w-6 flex items-start justify-center pt-2 border-r border-border bg-surface-2 text-text-4 hover:text-text-0 hover:bg-surface-3 transition-colors cursor-pointer",title:"Show sidebar",children:t.jsx(Fx,{size:14})}),t.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-surface-1",children:[t.jsx(yee,{}),e&&!I&&t.jsx(Nee,{path:e}),t.jsxs("div",{className:"flex-1 relative min-h-0",children:[w&&t.jsx(See,{currentLine:b.line,onGoto:$,onClose:()=>N(!1)}),!e&&t.jsx("div",{className:"w-full h-full flex items-center justify-center text-text-4 font-sans",children:t.jsxs("div",{className:"text-center space-y-2",children:[t.jsx(un,{size:32,className:"mx-auto"}),t.jsx("p",{className:"text-sm",children:"Open a file from the tree"})]})}),e&&I&&t.jsx(n5,{path:e}),e&&!I&&se&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"absolute top-0 right-4 z-10 flex items-center gap-0.5 mt-2 bg-surface-2 border border-border-subtle rounded-md p-0.5",children:[t.jsxs("button",{onClick:()=>h(!1),className:V("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",m?"text-text-3 hover:text-text-1":"bg-surface-4 text-text-0 font-medium"),children:[t.jsx(vb,{size:12})," Code"]}),t.jsxs("button",{onClick:()=>{h(!0),O(H=>H+1)},className:V("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",m?"bg-surface-4 text-text-0 font-medium":"text-text-3 hover:text-text-1"),children:[t.jsx(Hs,{size:12})," Preview"]})]}),m?t.jsx("iframe",{src:`/api/files/raw?path=${encodeURIComponent(e)}`,className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin",title:"HTML Preview"},g):M&&t.jsx(PO,{content:M.content,language:M.language,onChange:H=>n(e,H),onSave:()=>a(e),onCursorChange:v,viewRef:C})]}),e&&!I&&!se&&M&&t.jsx(PO,{content:M.content,language:M.language,onChange:H=>n(e,H),onSave:()=>a(e),onCursorChange:v,viewRef:C})]}),e&&!I&&t.jsx(Qee,{cursorPos:b,language:M==null?void 0:M.language})]})]})}function Eee(){var C;const e=U(k=>k.connected),s=U(k=>k.agents),[n,a]=p.useState(null),[r,l]=p.useState([]),[c,A]=p.useState({constraints:[],discoveries:[],roles:[],specializations:null}),[f,m]=p.useState(!0),[h,g]=p.useState({tokens:[],cost:[],saved:[],efficiency:[],cache:[],inputOutput:[],agents:[],turns:[]}),O=p.useRef(0);p.useEffect(()=>{if(!e)return;let k=!0;async function F(){try{const[T,$,M,I,se,H]=await Promise.all([G.get("/dashboard"),G.get("/tokens/by-team").catch(()=>({teams:[]})),G.get("/memory/constraints").catch(()=>({constraints:[]})),G.get("/memory/discoveries?limit=20").catch(()=>({discoveries:[]})),G.get("/memory/handoff-chain").catch(()=>({roles:[]})),G.get("/memory/specializations").catch(()=>({perAgent:{},perProjectRole:{}}))]);if(!k)return;a(T),l(($==null?void 0:$.teams)||[]),A({constraints:(M==null?void 0:M.constraints)||[],discoveries:(I==null?void 0:I.discoveries)||[],roles:(se==null?void 0:se.roles)||[],specializations:H||{perAgent:{},perProjectRole:{}}}),m(!1),O.current=Date.now(),g(ne=>{var Z,ee,le,ae,X,te,he,W,Oe;const K=Date.now(),L=(me,J)=>[...me.slice(-59),{t:K,v:J||0}],E=((Z=T.tokens)==null?void 0:Z.totalTokens)||0,q=((ee=T.tokens)==null?void 0:ee.totalInputTokens)||0,D=((le=T.tokens)==null?void 0:le.totalOutputTokens)||0,_=(((ae=T.agents)==null?void 0:ae.breakdown)||[]).filter(me=>{var J;return((J=me.quality)==null?void 0:J.score)!=null}),oe=_.length>0?_.reduce((me,J)=>me+J.quality.score,0)/_.length:0;return{tokens:L(ne.tokens,E),cost:L(ne.cost,(X=T.tokens)==null?void 0:X.totalCostUsd),saved:L(ne.saved,oe),efficiency:L(ne.efficiency,((te=T.rotation)==null?void 0:te.totalRotations)||0),cache:L(ne.cache,(he=T.tokens)==null?void 0:he.cacheHitRate),inputOutput:L(ne.inputOutput,D>0?q/D:0),agents:L(ne.agents,((W=T.agents)==null?void 0:W.running)||0),turns:L(ne.turns,(Oe=T.tokens)==null?void 0:Oe.totalTurns)}})}catch{k&&m(!1)}}F();const B=setInterval(F,4e3);return()=>{k=!1,clearInterval(B)}},[e]);const b=((C=n==null?void 0:n.agents)==null?void 0:C.breakdown)||[],v=(n==null?void 0:n.routing)||null,w=(n==null?void 0:n.rotation)||null,N=(n==null?void 0:n.adaptive)||[],Q=(n==null?void 0:n.journalist)||null,S=(w==null?void 0:w.rotating)||[];return{data:n,loading:f,agents:s,connected:e,kpiHistory:h,lastFetch:O.current,agentBreakdown:b,routing:v,rotation:w,adaptive:N,journalist:Q,rotating:S,teamBurn:r,memory:c}}const pQ=p.memo(function({connected:s,runningCount:n,totalCount:a,uptime:r,lastFetch:l,activeTeam:c}){return t.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 bg-surface-1 border-b border-border",children:[t.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Command Center"}),c&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-text-4",children:"/"}),t.jsx("span",{className:"text-xs font-mono text-text-2",children:c.name})]}),t.jsx("div",{className:"flex-1"}),s&&t.jsxs("div",{className:"flex items-center gap-3.5 text-xs font-mono text-text-2",children:[t.jsxs("span",{children:[t.jsx("span",{className:"text-text-1",children:n}),t.jsxs("span",{className:"text-text-3",children:["/",a]}),t.jsx("span",{className:"ml-1 text-text-3",children:"agents"})]}),r>0&&t.jsxs("span",{className:"text-text-3",children:["Up ",Ro(r)]}),l>0&&t.jsxs("span",{className:"flex items-center gap-1 text-text-4",children:[t.jsx(Ks,{size:9}),t.jsx("span",{children:ls(l)})]})]}),t.jsx(ss,{status:s?"running":"crashed",size:"sm"})]})});function qe(e,s){const n=parseInt(e.slice(1,3),16),a=parseInt(e.slice(3,5),16),r=parseInt(e.slice(5,7),16);return`rgba(${n},${a},${r},${s})`}const ce={surface0:"#1a1e25",surface3:"#282c34",surface4:"#2c313a",surface5:"#333842",text0:"#e6e6e6",text1:"#bcc2cd",text2:"#8b929e",text3:"#6e7681",text4:"#505862",accent:"#33afbc",success:"#4ae168",warning:"#e5c07b",danger:"#e06c75",info:"#61afef",purple:"#c678dd",orange:"#d19a66"};function Pee({data:e,color:s=ce.text3,width:n=72,height:a=22}){if(!e||e.length<2)return t.jsx("div",{style:{width:n,height:a}});const r=e.map(h=>h.v),l=Math.min(...r),A=Math.max(...r)-l||1,f=e.map((h,g)=>{const O=g/(e.length-1)*n,b=a-(h.v-l)/A*(a-2)-1;return`${O},${b}`}).join(" "),m=`kpi-${s.replace("#","")}`;return t.jsxs("svg",{width:n,height:a,className:"flex-shrink-0",children:[t.jsx("defs",{children:t.jsxs("linearGradient",{id:m,x1:"0",y1:"0",x2:"0",y2:"1",children:[t.jsx("stop",{offset:"0%",stopColor:s,stopOpacity:"0.2"}),t.jsx("stop",{offset:"100%",stopColor:s,stopOpacity:"0"})]})}),t.jsx("polygon",{points:`0,${a} ${f} ${n},${a}`,fill:`url(#${m})`}),t.jsx("polyline",{points:f,fill:"none",stroke:s,strokeWidth:"1.5",strokeLinejoin:"round",strokeOpacity:"0.8"})]})}const Fee=p.memo(function({label:s,value:n,sparkData:a,color:r=ce.text3,hint:l,className:c}){return t.jsxs("div",{className:V("flex items-center gap-2.5 px-3 py-2.5 min-w-0","bg-surface-1",c),children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5 truncate flex items-center gap-1",children:[s,l&&t.jsx(ot,{content:t.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:l}),side:"bottom",children:t.jsx(vi,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors"})})]}),t.jsx("div",{className:"text-base font-semibold font-mono text-text-0 tabular-nums leading-none",children:n})]}),t.jsx(Pee,{data:a,color:r})]})});function $ee({kpis:e}){return t.jsx("div",{className:"flex flex-wrap border-b border-border bg-surface-0",children:e.map(s=>t.jsx(Fee,{label:s.label,value:s.value,sparkData:s.sparkData,color:s.color,hint:s.hint,className:V("flex-1 basis-[12.5%] min-w-[140px]","border-b border-r border-border")},s.label))})}const Ree={actual:"ACT",estimated:"EST",local:"LOC"};function Mee(e){if(!e||e==="auto"||e==="default")return"default";const s=e.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:e.startsWith("gemini-")?e.replace("gemini-","Gem ").replace("-preview",""):e.length>12?e.slice(0,12)+"...":e}const Iee=p.memo(function({agent:s,isRotating:n}){const a=s.status==="running"||s.status==="starting",r=Math.round((s.contextUsage||0)*100),l=n?ce.accent:Ub(s.status),c=s.quality,A=(c==null?void 0:c.toolSuccessRate)!=null?Math.round(c.toolSuccessRate*100):null,f=s.rotationThreshold?Math.round(s.rotationThreshold*100):null,m=$a(s.role),h=ce.text1;return t.jsxs("div",{className:"px-3 pl-6 py-2 hover:bg-surface-4 transition-colors space-y-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[t.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:l}}),a&&t.jsx("span",{className:"absolute inset-[-2px] rounded-sm",style:{background:l,opacity:.15,animation:"node-pulse-bar 2s ease-in-out infinite"}})]}),t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate leading-none flex-shrink-0 max-w-[80px]",children:s.name}),t.jsx("span",{className:"text-2xs font-mono font-semibold px-1.5 py-px rounded-sm flex-shrink-0 capitalize",style:{background:m.bg,color:m.text},children:(s.role||"").toLowerCase()}),t.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1 py-px rounded-sm flex-shrink-0 truncate max-w-[72px]",children:Mee(s.model)}),t.jsx("div",{className:"flex-1"}),A!=null&&t.jsxs("span",{className:"text-2xs font-mono font-bold px-1 py-px rounded-sm flex-shrink-0 text-text-1 bg-surface-4",children:[A,"%"]}),s.costSource&&s.costSource!=="actual"&&t.jsx("span",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex-shrink-0",children:Ree[s.costSource]||""}),t.jsxs("div",{className:"text-right flex-shrink-0",children:[t.jsx("div",{className:"text-xs font-mono text-text-1 tabular-nums leading-none",children:Qt(s.tokens||0)}),(s.costUsd||0)>0&&t.jsx("div",{className:"text-2xs font-mono text-text-3 mt-0.5",children:$o(s.costUsd)})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative flex-1 h-0.5 rounded-sm overflow-visible",style:{background:qe(ce.text4,.2)},children:[t.jsx("div",{className:"absolute inset-y-0 left-0 rounded-sm transition-all duration-700",style:{width:`${Math.max(r,1)}%`,background:h}}),f&&t.jsx("div",{className:"absolute top-[-1px] w-px h-[4px]",style:{left:`${f}%`,background:ce.text3},title:`Rotation at ${f}%`})]}),t.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums flex-shrink-0 w-7 text-right",children:[r,"%"]})]})]})});function _ee({team:e,members:s,rotatingSet:n}){const[a,r]=p.useState(!0),l=s.filter(m=>m.status==="running"||m.status==="starting").length,c=l>0,A=s.reduce((m,h)=>m+(h.tokens||0),0),f=s.reduce((m,h)=>m+(h.costUsd||0),0);return t.jsxs("div",{children:[t.jsxs("button",{onClick:()=>r(m=>!m),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-surface-4 bg-surface-3",style:{borderLeft:c?`2px solid ${ce.accent}`:"2px solid transparent"},children:[a?t.jsx(dt,{size:10,className:"text-text-4 flex-shrink-0"}):t.jsx(Ct,{size:10,className:"text-text-4 flex-shrink-0"}),t.jsx("span",{className:"text-2xs font-mono font-semibold text-text-2 uppercase tracking-widest flex-1 truncate",children:e}),t.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:Qt(A)}),f>0&&t.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums ml-1",children:$o(f)}),t.jsxs("span",{className:"text-2xs font-mono tabular-nums flex-shrink-0 ml-1.5",style:{color:c?ce.text1:void 0},children:[l,"/",s.length]})]}),a&&s.map(m=>t.jsx(Iee,{agent:m,isRotating:n.has(m.id)},m.id))]})}const zee=p.memo(function({agentBreakdown:s,rotating:n=[],teams:a=[]}){if(!(s!=null&&s.length))return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono p-4",children:"No agents"});const r={};for(const A of a)r[A.id]=A.name;const l={};for(const A of s){const f=A.teamId||"ungrouped";l[f]||(l[f]=[]),l[f].push(A)}const c=new Set(n);return t.jsx(bt,{className:"flex-1",children:t.jsx("div",{className:"py-1",children:Object.entries(l).map(([A,f])=>t.jsx(_ee,{team:r[A]||(A==="ungrouped"?"Ungrouped":A),members:f,rotatingSet:c},A))})})}),Ps=36,LO=3,_f=(Ps-LO)/2,hf=2*Math.PI*_f,gQ=-90;function Lee(){return ce.text1}function Dee({name:e,pct:s,threshold:n}){const a=Lee(),r=s/100*hf;return t.jsxs("div",{className:"flex flex-col items-center gap-0.5",title:`${e}: ${s}% context used`,children:[t.jsxs("svg",{width:Ps,height:Ps,viewBox:`0 0 ${Ps} ${Ps}`,children:[t.jsx("circle",{cx:Ps/2,cy:Ps/2,r:_f,fill:"none",strokeWidth:LO,className:"stroke-surface-4"}),t.jsx("circle",{cx:Ps/2,cy:Ps/2,r:_f,fill:"none",strokeWidth:LO,strokeLinecap:"round",style:{stroke:a,strokeDasharray:`${r} ${hf-r}`,strokeDashoffset:0,transition:"stroke-dasharray 0.5s ease"},transform:`rotate(${gQ} ${Ps/2} ${Ps/2})`}),n&&t.jsx("circle",{cx:Ps/2,cy:Ps/2,r:_f,fill:"none",strokeWidth:1,strokeLinecap:"butt",style:{stroke:ce.text3,strokeDasharray:`1 ${hf-1}`,strokeDashoffset:-(n/100)*hf},transform:`rotate(${gQ} ${Ps/2} ${Ps/2})`}),t.jsx("text",{x:Ps/2,y:Ps/2+1,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-1 font-mono font-semibold",style:{fontSize:9},children:s})]}),t.jsx("span",{className:"text-2xs font-mono text-text-3 truncate max-w-[40px] leading-none",children:e})]})}function Hee({zones:e}){return t.jsxs("div",{className:"flex items-center gap-2 text-2xs font-mono",children:[t.jsx("span",{className:"text-text-2",children:e.healthy}),t.jsx("span",{className:"text-text-4",children:"/"}),t.jsx("span",{className:"text-text-2",children:e.warning}),t.jsx("span",{className:"text-text-4",children:"/"}),t.jsx("span",{className:"text-text-2",children:e.critical})]})}const Xee=p.memo(function({agentBreakdown:s}){const n=(s||[]).filter(r=>r.status==="running"||r.status==="starting");if(n.length===0)return null;const a={healthy:0,warning:0,critical:0};for(const r of n){const l=Math.round((r.contextUsage||0)*100);l>80?a.critical++:l>60?a.warning++:a.healthy++}return t.jsxs("div",{className:"px-3 py-2 flex-shrink-0 border-b border-border",children:[t.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Context Health"}),t.jsx(Hee,{zones:a})]}),t.jsx("div",{className:"flex items-start gap-2 overflow-x-auto",children:n.map(r=>{const l=Math.round((r.contextUsage||0)*100),c=r.rotationThreshold?Math.round(r.rotationThreshold*100):null;return t.jsx(Dee,{name:r.name,pct:l,threshold:c},r.id)})})]})}),Zee=p.memo(function({data:s}){const n=p.useRef(null),a=p.useRef(null),[r,l]=p.useState({width:0,height:0}),[c,A]=p.useState(null),{width:f,height:m}=r,h={top:28,right:12,bottom:8,left:12},g=Math.max(f-h.left-h.right,0),O=Math.max(m-h.top-h.bottom,0),b=p.useMemo(()=>!s||s.length<2?[]:s.slice(1).map((N,Q)=>{const S=s[Q],C=(N.t-S.t)/6e4,k=Math.max((N.tokens||0)-(S.tokens||0),0);return{burnRate:C>0?Math.round(k/C):0,cacheHitRate:N.cacheHitRate||0,running:N.running||0,agents:N.agents||0,t:N.t}}),[s]);p.useEffect(()=>{const N=n.current;if(!N)return;const Q=new ResizeObserver(S=>{const{width:C,height:k}=S[0].contentRect;C>0&&k>0&&l({width:Math.floor(C),height:Math.floor(k)})});return Q.observe(N),()=>Q.disconnect()},[]);const v=p.useCallback(N=>{const Q=a.current;if(!Q||!b.length||g<=0)return;const S=Q.getBoundingClientRect(),C=N.clientX-S.left-h.left;if(C<0||C>g){A(null);return}const k=Math.round(C/g*(b.length-1));A({x:h.left+k/Math.max(b.length-1,1)*g,index:k})},[b,g,h.left]),w=p.useCallback(()=>A(null),[]);return p.useEffect(()=>{const N=a.current;if(!N||!b.length||f<=0||m<=0||g<=0||O<=0)return;const Q=N.getContext("2d"),S=window.devicePixelRatio||1;N.width=f*S,N.height=m*S,Q.scale(S,S),Q.clearRect(0,0,f,m);const C=b.map(E=>E.burnRate),k=b.map(E=>E.cacheHitRate),F=b.map(E=>E.running),B=Math.max(...C,100),T=Math.max(...F,1),$=E=>h.left+E/Math.max(b.length-1,1)*g,M=E=>h.top+O-E/B*O,I=E=>h.top+O-E*O,se=Math.max(g/b.length-1,2);for(let E=0;E<b.length;E++){const q=F[E];if(q<=0)continue;const D=q/T*O*.3,R=$(E)-se/2,_=h.top+O-D;Q.fillStyle=qe(ce.surface5,.5),Q.fillRect(R,_,se,D)}Q.setLineDash([2,4]),Q.strokeStyle=qe(ce.text4,.2),Q.lineWidth=1;for(let E=1;E<=3;E++){const q=h.top+O/4*E;Q.beginPath(),Q.moveTo(h.left,q),Q.lineTo(h.left+g,q),Q.stroke()}Q.setLineDash([]),Q.font="9px 'JetBrains Mono Variable', monospace",Q.textAlign="left",Q.fillStyle=qe(ce.text3,.5),Q.fillText(`${Qt(B)}/m`,h.left+4,h.top+10),Q.fillText(`${Qt(Math.round(B/2))}/m`,h.left+4,h.top+O/2+4),Q.beginPath(),Q.moveTo(h.left,h.top+O);for(let E=0;E<b.length;E++)Q.lineTo($(E),M(C[E]));Q.lineTo($(b.length-1),h.top+O),Q.closePath();const H=Q.createLinearGradient(0,h.top,0,h.top+O);H.addColorStop(0,qe(ce.accent,.2)),H.addColorStop(.7,qe(ce.accent,.04)),H.addColorStop(1,qe(ce.accent,0)),Q.fillStyle=H,Q.fill(),Q.beginPath(),Q.strokeStyle=ce.accent,Q.lineWidth=1.5,Q.lineJoin="round";for(let E=0;E<b.length;E++){const q=$(E),D=M(C[E]);E===0?Q.moveTo(q,D):Q.lineTo(q,D)}Q.stroke();const ne=k.some(E=>E>0);if(ne){Q.beginPath(),Q.strokeStyle=qe(ce.text2,.5),Q.lineWidth=1,Q.lineJoin="round",Q.setLineDash([2,3]);for(let E=0;E<b.length;E++){const q=$(E),D=I(k[E]);E===0?Q.moveTo(q,D):Q.lineTo(q,D)}Q.stroke(),Q.setLineDash([])}Q.font="9px 'Inter Variable', sans-serif",Q.textAlign="right";let K=f-h.right-4;const L=14;if(ne&&(Q.fillStyle=qe(ce.text2,.5),Q.fillText("Cache %",K,L),K-=Q.measureText("Cache %").width+4,Q.beginPath(),Q.arc(K,L-3,2.5,0,Math.PI*2),Q.fill(),K-=14),Q.fillStyle=qe(ce.surface5,.7),Q.fillText("Agents",K,L),K-=Q.measureText("Agents").width+4,Q.beginPath(),Q.arc(K,L-3,2.5,0,Math.PI*2),Q.fill(),K-=14,Q.fillStyle=ce.accent,Q.fillText("Burn Rate",K,L),K-=Q.measureText("Burn Rate").width+4,Q.beginPath(),Q.arc(K,L-3,2.5,0,Math.PI*2),Q.fill(),c&&c.index>=0&&c.index<b.length){const E=c.x,q=b[c.index];Q.beginPath(),Q.moveTo(E,h.top),Q.lineTo(E,h.top+O),Q.strokeStyle=qe(ce.text1,.15),Q.lineWidth=1,Q.stroke();const D=M(q.burnRate);Q.beginPath(),Q.arc(E,D,3,0,Math.PI*2),Q.fillStyle=ce.accent,Q.fill();const R=[{label:"Burn",value:`${Qt(q.burnRate)}/m`,color:ce.accent},{label:"Cache",value:cc(q.cacheHitRate*100),color:ce.text2},{label:"Agents",value:`${q.running}/${q.agents}`,color:ce.text3}],_=104,oe=R.length*16+12;let Z=E+12;Z+_>f-8&&(Z=E-_-12);const ee=Math.max(h.top,D-oe/2);Q.fillStyle=qe(ce.surface0,.92),Q.beginPath(),Q.roundRect(Z,ee,_,oe,4),Q.fill(),Q.strokeStyle=qe(ce.text4,.2),Q.lineWidth=1,Q.stroke(),Q.textAlign="left",R.forEach((le,ae)=>{const X=ee+14+ae*16;Q.beginPath(),Q.arc(Z+8,X-3,2,0,Math.PI*2),Q.fillStyle=le.color,Q.fill(),Q.font="8px 'Inter Variable', sans-serif",Q.fillStyle=ce.text3,Q.fillText(le.label,Z+14,X),Q.font="9px 'JetBrains Mono Variable', monospace",Q.fillStyle=ce.text0,Q.textAlign="right",Q.fillText(le.value,Z+_-8,X),Q.textAlign="left"})}},[b,f,m,c,g,O,h]),t.jsx("div",{ref:n,className:"absolute inset-0",children:f>0&&m>0&&t.jsx("canvas",{ref:a,style:{width:f,height:m},className:"block cursor-crosshair",onMouseMove:v,onMouseLeave:w})})}),Gee=p.memo(function({cacheRead:s=0,cacheCreation:n=0,totalInput:a=0,size:r=140}){const l=p.useRef(null),c=s+n,A=c,f=c>0?s/c*100:0;return p.useEffect(()=>{const m=l.current;if(!m)return;const h=window.devicePixelRatio||1;m.width=r*h,m.height=r*h;const g=m.getContext("2d");g.scale(h,h),g.clearRect(0,0,r,r);const O=r/2,b=r/2,v=(r-12)/2,w=5,N=135*Math.PI/180,Q=405*Math.PI/180,S=Q-N;if(g.beginPath(),g.arc(O,b,v,N,Q),g.strokeStyle=ce.surface4,g.lineWidth=w,g.lineCap="round",g.stroke(),A>0){const C=s/A,k=n/A;if(C>0){const F=N+S*C;g.beginPath(),g.arc(O,b,v,N,F),g.strokeStyle=ce.text0,g.lineWidth=w,g.lineCap="round",g.stroke()}if(k>0){const F=N+S*C,B=F+S*k;g.beginPath(),g.arc(O,b,v,F,B),g.strokeStyle=ce.text3,g.lineWidth=w,g.lineCap="butt",g.stroke()}}g.textAlign="center",g.textBaseline="middle",g.font=`600 ${r*.2}px 'JetBrains Mono Variable', monospace`,g.fillStyle=ce.text0,g.fillText(`${Math.round(f)}%`,O,b-3),g.font=`500 ${r*.08}px 'JetBrains Mono Variable', monospace`,g.fillStyle=ce.text3,g.fillText("CACHE",O,b+r*.13)},[s,n,a,r,A,f]),t.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-3 py-3",children:[t.jsx("canvas",{ref:l,className:"flex-shrink-0",style:{width:r,height:r}}),t.jsxs("div",{className:"w-full mt-3 space-y-1.5 max-w-[160px]",children:[t.jsx(kg,{color:ce.text0,label:"Read",value:Qt(s)}),t.jsx(kg,{color:ce.text3,label:"Create",value:Qt(n)}),t.jsx(kg,{color:ce.surface5,label:"Miss",value:Qt(Math.max(a-s-n,0))})]})]})});function kg({color:e,label:s,value:n}){return t.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono",children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:e}}),t.jsx("span",{className:"text-text-3 uppercase tracking-wider flex-1",children:s}),t.jsx("span",{className:"text-text-1 tabular-nums",children:n})]})}const v4={heavy:ce.text0,medium:ce.text2,light:ce.text4},Vee={heavy:"Heavy",medium:"Medium",light:"Light"},Ys=80,DO=6,HO=(Ys-DO)/2,OQ=2*Math.PI*HO;function Kee({byTier:e,total:s,tiers:n}){let a=0;const r=[];for(const l of n){const c=e[l]||0;if(c===0)continue;const f=c/s*OQ;r.push({tier:l,dashLen:f,offset:a}),a+=f}return s>0&&Math.round((e.heavy||0)/s*100),t.jsxs("svg",{width:Ys,height:Ys,viewBox:`0 0 ${Ys} ${Ys}`,className:"flex-shrink-0",children:[t.jsx("circle",{cx:Ys/2,cy:Ys/2,r:HO,fill:"none",strokeWidth:DO,className:"stroke-surface-4"}),r.map(l=>t.jsx("circle",{cx:Ys/2,cy:Ys/2,r:HO,fill:"none",strokeWidth:DO,strokeLinecap:"butt",style:{stroke:v4[l.tier],strokeDasharray:`${l.dashLen} ${OQ-l.dashLen}`,strokeDashoffset:-l.offset},transform:`rotate(-90 ${Ys/2} ${Ys/2})`},l.tier)),t.jsx("text",{x:Ys/2,y:Ys/2-2,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-0 text-sm font-mono font-semibold",children:Qt(s)}),t.jsx("text",{x:Ys/2,y:Ys/2+11,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-3 font-mono",style:{fontSize:7},children:"decisions"})]})}const qee=p.memo(function({routing:s,agentBreakdown:n}){if(!s)return null;const{byTier:a={},totalDecisions:r=0,autoRoutedCount:l=0}=s,c=["heavy","medium","light"],A=c.reduce((g,O)=>g+(a[O]||0),0),f={};for(const g of n||[]){const O=g.model||"default";f[O]||(f[O]={tokens:0,agents:0}),f[O].tokens+=g.tokens||0,f[O].agents+=1}const m=Object.entries(f).sort((g,O)=>O[1].tokens-g[1].tokens),h=m.length>0?m[0][1].tokens:0;return t.jsxs("div",{className:"flex flex-col h-full px-3 py-3 overflow-y-auto",children:[A>0&&t.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[t.jsx(Kee,{byTier:a,total:A,tiers:c}),t.jsxs("div",{className:"flex flex-col gap-1.5 flex-1 min-w-0",children:[c.map(g=>{const O=a[g]||0;if(O===0)return null;const b=O/A*100;return t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:v4[g]}}),t.jsx("span",{className:"text-2xs font-mono text-text-2 flex-1",children:Vee[g]}),t.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums",children:O}),t.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums w-8 text-right",children:cc(b)})]},g)}),l>0&&t.jsxs("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:[l," auto-routed"]})]})]}),m.length>0&&t.jsxs("div",{className:"space-y-1.5 flex-1",children:[t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Models in Use"}),t.jsx("div",{className:"space-y-1.5",children:m.map(([g,O])=>{const b=h>0?O.tokens/h*100:0;return t.jsxs("div",{className:"space-y-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs font-mono text-text-1 flex-1 truncate",children:Wee(g)}),t.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[O.agents," agent",O.agents!==1?"s":""]}),t.jsx("span",{className:"text-xs font-mono text-text-1 tabular-nums",children:Qt(O.tokens)})]}),t.jsx("div",{className:"h-0.5 bg-surface-4 rounded-sm overflow-hidden",children:t.jsx("div",{className:"h-full rounded-sm transition-all duration-500",style:{width:`${Math.max(b,2)}%`,background:ce.text2}})})]},g)})})]}),A===0&&m.length===0&&t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono",children:"No routing data"})]})});function Wee(e){if(!e||e==="auto"||e==="default")return"Default";const s=e.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:e.startsWith("gemini-")?e.replace("gemini-","Gemini ").replace("-preview",""):e}function y4({text:e}){return t.jsx(ot,{content:t.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:e}),side:"bottom",children:t.jsx(vi,{size:9,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors ml-0.5"})})}function Yee({children:e,tip:s}){return t.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex items-center gap-0.5",children:[e,s&&t.jsx(y4,{text:s})]})}function pf({label:e,value:s,tip:n}){return t.jsxs("div",{children:[t.jsx(Yee,{tip:n,children:e}),t.jsx("div",{className:"text-sm font-mono font-semibold text-text-1 tabular-nums leading-snug",children:s})]})}function xd({title:e,children:s,tip:n}){return t.jsxs("div",{className:"px-3 py-2.5",children:[t.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider mb-2 flex items-center gap-0.5",children:[e,n&&t.jsx(y4,{text:n})]}),s]})}function fc(){return t.jsx("div",{className:"h-px bg-border mx-3"})}function Jee({tokens:e,rotation:s,agentBreakdown:n}){const r=(n||[]).filter(c=>{var A;return((A=c.quality)==null?void 0:A.score)!=null}),l=r.length>0?Math.round(r.reduce((c,A)=>c+A.quality.score,0)/r.length):null;return t.jsxs("div",{className:"px-3 py-3 flex items-start gap-5",children:[t.jsx(pf,{label:"Quality",value:l??"—",tip:"Average session quality (0-100). Below 40 triggers auto-rotation."}),t.jsx(pf,{label:"Cache",value:cc(((e==null?void 0:e.cacheHitRate)||0)*100),tip:"Prompt cache hit rate. Higher = faster + cheaper."}),t.jsx(pf,{label:"Rotations",value:(s==null?void 0:s.totalRotations)||0,tip:"Total context rotations this session."}),((e==null?void 0:e.totalCostUsd)||0)>0&&t.jsx(pf,{label:"Cost",value:$o(e.totalCostUsd),tip:"Total cost reported by providers."})]})}function ete({agentBreakdown:e,rotation:s}){const n=(s==null?void 0:s.liveScores)||{},a=(e||[]).filter(r=>r.status==="running");return a.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsx(xd,{title:"Live agents",children:t.jsx("div",{className:"space-y-0",children:a.map(r=>{var m;const l=r.quality||{},c=((m=n[r.id])==null?void 0:m.score)??l.score,A=$a(r.role),f=[l.errorCount>0&&`${l.errorCount} err`,l.repetitions>0&&`${l.repetitions} rep`,l.fileChurn>0&&`${l.fileChurn} churn`].filter(Boolean);return t.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[t.jsx("span",{className:"text-2xs font-semibold capitalize px-1 py-px rounded-sm flex-shrink-0",style:{background:A.bg,color:A.text},children:r.role}),t.jsx("span",{className:"text-text-2 truncate flex-1",children:r.name}),f.length>0&&t.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:f.join(" · ")}),t.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0 w-6 text-right",children:c??"—"})]},r.id)})})})]})}function tte({rotation:e}){const s=((e==null?void 0:e.history)||[]).slice(-5).reverse();if(s.length===0)return null;function n(a){return a.reason==="quality_degradation"?`Q:${a.qualityScore}`:a.reason==="token_limit_exceeded"?"tokens":a.reason==="runaway_velocity"?"velocity":a.reason==="natural_compaction"?"compacted":cc((a.contextUsage||0)*100)}return t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsx(xd,{title:"Recent rotations",children:t.jsx("div",{className:"space-y-0",children:s.map((a,r)=>t.jsxs("div",{className:"flex items-center gap-2 py-0.5 text-xs font-mono",children:[t.jsx("span",{className:"text-text-2 truncate flex-1",children:a.agentName||a.role}),t.jsx("span",{className:"text-text-3 flex-shrink-0",children:n(a)}),t.jsx("span",{className:"text-text-4 flex-shrink-0 w-10 text-right",children:ls(a.timestamp)})]},r))})})]})}function ste({adaptive:e}){if(!(e!=null&&e.length))return null;function s(n){const a=n.split(":");return{provider:a[0]||n,role:a[1]||""}}return t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsx(xd,{title:"Adaptive thresholds",tip:"Per-role rotation thresholds. GROOVE learns when each role benefits from rotation and adjusts automatically.",children:t.jsx("div",{className:"space-y-0",children:e.map(n=>{const{provider:a,role:r}=s(n.key),l=r||a,c=$a(l);return t.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[t.jsx("span",{className:"text-2xs font-semibold capitalize px-1 py-px rounded-sm flex-shrink-0",style:{background:c.bg,color:c.text},children:l}),r&&t.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:a}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0",children:cc(n.threshold*100)}),n.converged?t.jsx("span",{className:"text-2xs font-semibold flex-shrink-0",style:{color:ce.accent},children:"Converged"}):t.jsxs("span",{className:"text-2xs text-text-3 flex-shrink-0 flex items-center gap-1",children:[t.jsx("span",{className:"w-1 h-1 rounded-full [animation:node-pulse-bar_1.5s_ease-in-out_infinite]",style:{background:ce.text3}}),"Learning"]})]},n.key)})})})]})}function nte({journalist:e}){return!e||!((e.cycleCount||0)>0)&&!e.synthesizing?null:t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsxs(xd,{title:"Journalist",children:[t.jsxs("div",{className:"flex items-center gap-3 text-xs font-mono",children:[t.jsxs("span",{className:"text-text-2",children:[e.cycleCount||0," cycles"]}),e.lastCycleAt&&t.jsx("span",{className:"text-text-4",children:ls(e.lastCycleAt)}),e.synthesizing&&t.jsx("span",{className:"font-semibold text-accent animate-pulse",children:"Synthesizing"})]}),e.lastSummary&&t.jsx("div",{className:"text-xs text-text-3 leading-relaxed mt-1.5 line-clamp-3",children:e.lastSummary})]})]})}function ate({memory:e}){var f,m;const s=(e==null?void 0:e.constraints)||[],n=(e==null?void 0:e.discoveries)||[],a=(e==null?void 0:e.roles)||[],r=((f=e==null?void 0:e.specializations)==null?void 0:f.perProjectRole)||{},l=Object.keys(((m=e==null?void 0:e.specializations)==null?void 0:m.perAgent)||{}).length;if(s.length+n.length+a.length+l===0)return null;const A=[s.length>0&&`${s.length} constraints`,n.length>0&&`${n.length} discoveries`,a.length>0&&`${a.length} role chains`,l>0&&`${l} specializations`].filter(Boolean);return t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsxs(xd,{title:"Memory",tip:"Persistent knowledge across agent rotations. Constraints, error→fix discoveries, and handoff chains.",children:[t.jsx("div",{className:"text-xs font-mono text-text-3 mb-1.5",children:A.join(" · ")}),s.length>0&&t.jsxs("div",{className:"mt-2 space-y-0",children:[t.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Constraints"}),s.slice(0,3).map(h=>t.jsx("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:h.text},h.hash)),s.length>3&&t.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",s.length-3," more"]})]}),n.length>0&&t.jsxs("div",{className:"mt-2 space-y-0",children:[t.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Discoveries"}),n.slice(0,3).map((h,g)=>t.jsxs("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:[t.jsx("span",{className:"text-text-4",children:h.trigger})," → ",h.fix]},g)),n.length>3&&t.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",n.length-3," more"]})]}),Object.keys(r).length>0&&t.jsxs("div",{className:"mt-2",children:[t.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Role quality"}),t.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-0.5",children:Object.entries(r).map(([h,g])=>t.jsxs("span",{className:"text-xs font-mono text-text-3",children:[t.jsx("span",{className:"text-text-2 capitalize",children:h})," Q:",g.avgQualityScore," ",t.jsxs("span",{className:"text-text-4",children:["(",g.sessionCount,"s)"]})]},h))})]})]})]})}function rte({tokens:e}){var r,l;if(!((r=e==null?void 0:e.internalOverhead)!=null&&r.tokens)||!((l=e==null?void 0:e.savings)!=null&&l.total))return null;const s=e.internalOverhead,n=e.savings,a=e.totalTokens>0?Math.round(s.tokens/e.totalTokens*100):0;return t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsxs("div",{className:"px-3 py-2.5 flex items-center gap-3 text-xs font-mono",children:[t.jsx("span",{className:"text-text-4",children:"Overhead"}),t.jsxs("span",{className:"text-text-3 tabular-nums",children:[Qt(s.tokens)," (",a,"%)"]}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-text-4",children:"Saved"}),t.jsx("span",{className:"text-text-3 tabular-nums",children:Qt(n.total)})]})]})}const ote=p.memo(function({tokens:s,rotation:n,adaptive:a,journalist:r,agentBreakdown:l,memory:c}){return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx("div",{className:"flex-shrink-0 px-3 pt-2.5 pb-1.5",children:t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Intel"})}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[t.jsx(Jee,{tokens:s,rotation:n,agentBreakdown:l}),t.jsx(ete,{agentBreakdown:l,rotation:n}),t.jsx(tte,{rotation:n}),t.jsx(ste,{adaptive:a}),t.jsx(nte,{journalist:r}),t.jsx(ate,{memory:c}),t.jsx(rte,{tokens:s}),t.jsx("div",{className:"h-3"})]})]})}),ite=p.memo(function({teams:s=[]}){const n=s.reduce((r,l)=>r+(l.totalTokens||0),0),a=s.reduce((r,l)=>Math.max(r,l.totalTokens||0),0);return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0 flex items-center justify-between",children:[t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Team Burn"}),t.jsxs("span",{className:"text-2xs font-mono text-text-3",children:[Qt(n)," total"]})]}),t.jsx(bt,{className:"flex-1 min-h-0",children:s.length===0?t.jsx("div",{className:"px-3 py-6 text-center text-xs text-text-3 font-mono",children:"No team activity yet"}):t.jsx("div",{className:"px-3 py-3 space-y-3",children:s.map(r=>{const l=a>0?r.totalTokens/a*100:0;return t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:r.teamName}),r.isDefault&&t.jsx("span",{className:"text-[9px] font-mono text-text-3 uppercase tracking-wider",children:"default"}),t.jsxs("span",{className:"text-2xs font-mono text-text-3 flex-shrink-0",children:[r.agentCount," ",r.agentCount===1?"agent":"agents"]})]}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 font-mono text-2xs",children:[t.jsx("span",{className:"text-text-1",children:Qt(r.totalTokens)}),t.jsx("span",{className:"text-text-3",children:$o(r.totalCostUsd)})]})]}),t.jsx("div",{className:"h-0.5 bg-surface-2 rounded-sm overflow-hidden",children:t.jsx("div",{className:"h-full rounded-sm transition-all",style:{width:`${l}%`,background:ce.text3}})})]},r.teamId)})})})]})}),lte={spawn:BN,complete:Ma,crash:sa,kill:Kg,rotate:od,error:Cb},cte={spawn:"text-text-2",complete:"text-text-2",crash:"text-danger",kill:"text-text-3",rotate:"text-text-2",error:"text-danger"};function Ate(e){const s=e.agentName||e.role||"";switch(e.type){case"spawn":return`${s} spawned`;case"complete":return`${s} completed`;case"crash":return`${s} crashed`;case"kill":return`${s} killed`;case"rotate":return`${s} rotated`;default:return e.text||e.type||"event"}}const dte=p.memo(function({events:s=[]}){return s.length?t.jsx("div",{className:"flex items-center gap-3 overflow-x-auto py-2 px-3",children:s.slice(-15).reverse().map((n,a)=>{const r=lte[n.type]||Wt,l=cte[n.type]||"text-text-3",c=Ate(n);return t.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[t.jsx(r,{size:11,className:l}),t.jsx("span",{className:"text-xs font-sans text-text-2 whitespace-nowrap",children:c}),t.jsx("span",{className:"text-2xs font-mono text-text-4",children:ls(n.t||n.timestamp)})]},a)})}):t.jsx("div",{className:"text-xs text-text-3 font-mono py-2.5 text-center",children:"No recent activity"})});function Jn({className:e,...s}){return t.jsx("div",{className:V("rounded-md bg-surface-4","bg-gradient-to-r from-surface-4 via-surface-5 to-surface-4","bg-[length:200%_100%] animate-[shimmer_1.5s_ease-in-out_infinite]",e),...s})}function ute(){return t.jsxs("div",{className:"flex-1 grid gap-px p-0 bg-surface-3",style:{gridTemplateRows:"auto minmax(0, 1fr) minmax(0, 1fr)",gridTemplateColumns:"2fr 2.5fr 1.5fr"},children:[t.jsx("div",{className:"col-span-3",children:t.jsx(Jn,{className:"h-[72px] rounded-none"})}),t.jsx(Jn,{className:"rounded-none"}),t.jsx(Jn,{className:"rounded-none"}),t.jsx(Jn,{className:"rounded-none"}),t.jsx(Jn,{className:"rounded-none"}),t.jsx("div",{className:"col-span-2",children:t.jsx(Jn,{className:"h-full rounded-none"})})]})}function fte(){const{data:e,loading:s,agents:n,connected:a,kpiHistory:r,lastFetch:l,agentBreakdown:c,routing:A,rotation:f,adaptive:m,journalist:h,rotating:g,teamBurn:O,memory:b}=Eee(),v=U(I=>I.teams),w=n.filter(I=>I.status==="running").length;if(!a)return t.jsx("div",{className:"w-full h-full flex items-center justify-center",children:t.jsxs("div",{className:"text-center space-y-2 text-text-3 font-mono",children:[t.jsx(Ux,{size:28,className:"mx-auto"}),t.jsx("p",{className:"text-xs",children:"Connecting to daemon..."})]})});if(s||!e)return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx(pQ,{connected:a,runningCount:0,totalCount:0,uptime:0,lastFetch:0}),t.jsx(ute,{})]});const N=e.tokens||{},Q={totalTokens:N.totalTokens||0,totalCostUsd:N.totalCostUsd||0,totalInputTokens:N.totalInputTokens||0,totalOutputTokens:N.totalOutputTokens||0,cacheReadTokens:N.cacheReadTokens||0,cacheCreationTokens:N.cacheCreationTokens||0,cacheHitRate:N.cacheHitRate||0,totalTurns:N.totalTurns||0,agentCount:N.agentCount||0,savings:N.savings||{},internalOverhead:N.internalOverhead||{tokens:0,costUsd:0,components:{}}},S=Q.totalOutputTokens>0?(Q.totalInputTokens/Q.totalOutputTokens).toFixed(1):"—",C=(f==null?void 0:f.totalRotations)||0,k=(c||[]).filter(I=>{var se;return((se=I.quality)==null?void 0:se.score)!=null}),F=k.length>0?Math.round(k.reduce((I,se)=>I+se.quality.score,0)/k.length):null,B=e.timeline||{},T=B.snapshots||[],$=B.events||e.events||[],M=[{label:"Tokens Used",value:Qt(Q.totalTokens),sparkData:r.tokens,color:ce.text3,hint:"Total tokens consumed across all agents — input, output, and cache tokens combined."},{label:"Total Cost",value:$o(Q.totalCostUsd),sparkData:r.cost,color:ce.text3,hint:"Actual cost reported by providers. Claude Code reports real billing; other providers use estimated rates."},{label:"Quality",value:F!=null?`${F}`:"—",sparkData:r.saved,color:ce.text3,hint:"Average session quality score (0-100) across running agents. Based on error rate, repetitions, file churn, and tool success. Below 40 triggers auto-rotation."},{label:"Cache Rate",value:cc(Q.cacheHitRate*100),sparkData:r.cache,color:ce.text3,hint:"Percentage of input tokens served from prompt cache. Higher = faster responses and lower cost. Managed by your AI provider."},{label:"Rotations",value:`${C}`,sparkData:r.efficiency,color:ce.text3,hint:"Total context rotations — includes quality-based (auto), context threshold, natural compaction (provider-managed), and manual rotations."},{label:"I/O Ratio",value:`${S}:1`,sparkData:r.inputOutput,color:ce.text3,hint:"Ratio of input to output tokens. High ratios mean agents are reading more than writing — common for analysis tasks."},{label:"Agents",value:`${w}/${n.length}`,sparkData:r.agents,color:ce.text3,hint:"Running agents out of total spawned this session (including completed and crashed)."},{label:"Turns",value:Qt(Q.totalTurns),sparkData:r.turns,color:ce.text3,hint:"Total conversation turns across all agents. Each turn is one request-response cycle with the AI provider."}];return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx(pQ,{connected:a,runningCount:w,totalCount:n.length,uptime:e.uptime||0,lastFetch:l,activeTeam:e.activeTeam}),t.jsx($ee,{kpis:M}),t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col bg-surface-3 gap-px",children:[t.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"3fr 1.5fr 1.5fr"},children:[t.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 relative",children:t.jsx(Zee,{data:T})}),t.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[t.jsx("div",{className:"px-3 pt-2.5 pb-1",children:t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Cache Performance"})}),t.jsx(Gee,{cacheRead:Q.cacheReadTokens,cacheCreation:Q.cacheCreationTokens,totalInput:Q.totalInputTokens})]}),t.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[t.jsx("div",{className:"px-3 pt-2.5 pb-1",children:t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Model Routing"})}),t.jsx(qee,{routing:A,agentBreakdown:c})]})]}),t.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"2fr 2.5fr 1.5fr"},children:[t.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-border",children:[t.jsx("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0",children:t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Agent Fleet"})}),t.jsx(Xee,{agentBreakdown:c}),t.jsx(zee,{agentBreakdown:c,rotating:g,teams:v})]}),t.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:t.jsx(ote,{tokens:Q,rotation:f,adaptive:m,journalist:h,agentBreakdown:c,memory:b})}),t.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:t.jsx(ite,{teams:O})})]})]}),t.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-t border-border",children:t.jsx(dte,{events:$})})]})}const bQ={sm:12,md:16,lg:20};function xte({fill:e="full",size:s,color:n="#fbbf24",emptyColor:a="rgba(255,255,255,0.4)"}){const r=`star-${Math.random().toString(36).slice(2,8)}`;return t.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",children:[e==="half"&&t.jsx("defs",{children:t.jsxs("linearGradient",{id:r,children:[t.jsx("stop",{offset:"50%",stopColor:n}),t.jsx("stop",{offset:"50%",stopColor:a})]})}),t.jsx("path",{d:"M10 1.5l2.47 5.01 5.53.8-4 3.9.94 5.49L10 14.27 5.06 16.7 6 11.21l-4-3.9 5.53-.8L10 1.5z",fill:e==="full"?n:e==="half"?`url(#${r})`:a})]})}function mte({rating:e=0,count:s,size:n="sm"}){const a=bQ[n]||bQ.sm,r=[];for(let l=1;l<=5;l++)e>=l?r.push("full"):e>=l-.5?r.push("half"):r.push("empty");return t.jsxs("span",{className:"inline-flex items-center",style:{gap:1},children:[r.map((l,c)=>t.jsx(xte,{fill:l,size:a},c)),s!=null&&t.jsxs("span",{className:"ml-1 text-[11px] text-[var(--text-dim,#6b7f95)] font-sans",children:["(",s,")"]})]})}const vQ={design:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},quality:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},devtools:{color:"#33afbc",bg:"rgba(51,175,188,0.14)"},workflow:{color:"#fbbf24",bg:"rgba(251,191,36,0.12)"},security:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},specialized:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},verified:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},anthropic:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},published:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},draft:{color:"#6b7f95",bg:"rgba(255,255,255,0.06)"},review:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},rejected:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},free:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"}};function hte({label:e,variant:s,className:n}){const a=vQ[s]||vQ.draft;return t.jsx("span",{className:V("inline-flex items-center whitespace-nowrap font-sans select-none",n),style:{padding:"3px 8px",borderRadius:4,fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",lineHeight:1.4,color:a.color,background:a.bg},children:e})}function pte({price:e=0,size:s="sm"}){const n=!e||e===0,a={sm:"text-2xs px-2 py-0.5",md:"text-xs px-2.5 py-0.5",lg:"text-xs px-3 py-1"};return t.jsx("span",{className:`inline-flex items-center font-mono font-semibold rounded whitespace-nowrap ${a[s]||a.sm} ${n?"bg-success/12 text-success":"bg-white/8 text-text-1"}`,children:n?"Free":`$${e.toFixed(2)}`})}function gte({type:e="verified",size:s=12}){const n=e==="claude-official"||e==="anthropic"?"#f59e0b":"#4ade80";return t.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",className:"inline-block flex-shrink-0",children:[t.jsx("path",{d:"M10 0l2.36 3.15L16.18 2l.68 3.93L20.8 7.1l-1.87 3.52L20.8 14.14l-3.94 1.17-.68 3.93-3.82-1.15L10 21.24l-2.36-3.15-3.82 1.15-.68-3.93-3.94-1.17 1.87-3.52L-.8 7.1l3.94-1.17.68-3.93 3.82 1.15L10 0z",fill:n}),t.jsx("path",{d:"M7 10.5l2 2 4-4.5",fill:"none",stroke:"#24282f",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Ote(){return t.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md animate-pulse",style:{padding:20,minHeight:280},children:[t.jsx("div",{className:"w-10 h-10 rounded-full bg-surface-4"}),t.jsx("div",{className:"mt-3 h-4 w-[70%] rounded bg-surface-4"}),t.jsx("div",{className:"mt-2 h-3 w-[40%] rounded bg-surface-4"}),t.jsx("div",{className:"mt-3.5 h-3 w-full rounded bg-surface-4"}),t.jsx("div",{className:"mt-1.5 h-3 w-[90%] rounded bg-surface-4"}),t.jsx("div",{className:"mt-1.5 h-3 w-[60%] rounded bg-surface-4"}),t.jsx("div",{className:"mt-3.5 h-5 w-[50px] rounded bg-surface-4"}),t.jsx("div",{className:"h-px bg-surface-4 my-3"}),t.jsxs("div",{className:"flex justify-between",children:[t.jsx("div",{className:"h-3 w-16 rounded bg-surface-4"}),t.jsx("div",{className:"h-3 w-12 rounded bg-surface-4"}),t.jsx("div",{className:"h-3 w-10 rounded bg-surface-4"})]})]})}const pi={"google-workspace":"https://cdn.simpleicons.org/google/white",slack:"https://cdn.simpleicons.org/slack/E01E5A",discord:"https://cdn.simpleicons.org/discord/5865F2",github:"https://cdn.simpleicons.org/github/white",stripe:"https://cdn.simpleicons.org/stripe/635BFF",gmail:"https://cdn.simpleicons.org/gmail/EA4335","google-calendar":"https://cdn.simpleicons.org/googlecalendar/4285F4","google-drive":"https://cdn.simpleicons.org/googledrive/4285F4","google-docs":"https://cdn.simpleicons.org/googledocs/4285F4","google-sheets":"https://cdn.simpleicons.org/googlesheets/34A853","google-slides":"https://cdn.simpleicons.org/googleslides/FBBC04","google-maps":"https://cdn.simpleicons.org/googlemaps/4285F4",postgres:"https://cdn.simpleicons.org/postgresql/4169E1",notion:"https://cdn.simpleicons.org/notion/white",linear:"https://cdn.simpleicons.org/linear/5E6AD2","brave-search":"https://cdn.simpleicons.org/brave/FB542B","home-assistant":"https://cdn.simpleicons.org/homeassistant/18BCF2",sentry:"https://cdn.simpleicons.org/sentry/362D59",elevenlabs:"https://cdn.simpleicons.org/elevenlabs/white",hubspot:"https://cdn.simpleicons.org/hubspot/FF7A59",jira:"https://cdn.simpleicons.org/jira/0052CC",sendgrid:"https://cdn.simpleicons.org/sendgrid/1A82E2",resend:"https://cdn.simpleicons.org/resend/white",replicate:"https://cdn.simpleicons.org/replicate/white",vercel:"https://cdn.simpleicons.org/vercel/white",supabase:"https://cdn.simpleicons.org/supabase/3FCF8E",mixpanel:"https://cdn.simpleicons.org/mixpanel/7856FF",datadog:"https://cdn.simpleicons.org/datadog/632CA6",airtable:"https://cdn.simpleicons.org/airtable/18BFFF",zendesk:"https://cdn.simpleicons.org/zendesk/03363D",intercom:"https://cdn.simpleicons.org/intercom/6AFDEF",twilio:"https://cdn.simpleicons.org/twilio/F22F46",telnyx:"https://cdn.simpleicons.org/telnyx/00C08B",aws:"https://cdn.simpleicons.org/amazonaws/FF9900",plaid:"https://cdn.simpleicons.org/plaid/white"};function bte({item:e,size:s=40}){const n=pi[e.id];if(n)return t.jsxs("div",{className:"rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:[t.jsx("img",{src:n,alt:e.name,className:"w-5 h-5",onError:l=>{l.target.style.display="none",l.target.nextSibling.style.display="flex"}}),t.jsx("div",{className:"hidden items-center justify-center w-full h-full text-lg font-bold font-sans text-text-1",children:(e.name||"?")[0]})]});const a=(e.name||"?")[0].toUpperCase(),r=e.name?e.name.charCodeAt(0)*37%360:200;return t.jsx("div",{className:"rounded-md flex items-center justify-center flex-shrink-0 text-lg font-bold font-sans",style:{width:s,height:s,background:`hsl(${r}, 40%, 18%)`,color:`hsl(${r}, 60%, 65%)`},children:a})}function vx({item:e,onClick:s,className:n,statusBadge:a}){var l;const r=e.installed;return t.jsxs("button",{onClick:()=>s(e),className:V("flex flex-col p-5 rounded-md border border-border-subtle bg-surface-1 text-left","hover:border-accent/30 hover:bg-surface-2","transition-all duration-150 cursor-pointer group",n),style:{minHeight:200},children:[t.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[t.jsx(bte,{item:e,size:36}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-[14px] font-semibold text-text-0 font-sans truncate",children:e.name}),(e.verified||e.verified==="mcp-official")&&t.jsx(Ma,{size:11,className:"text-accent flex-shrink-0"})]}),t.jsx("span",{className:"text-2xs text-text-3 font-sans",children:e.author||"Community"})]})]}),t.jsx("p",{className:"text-xs text-text-2 font-sans line-clamp-3 mb-3 flex-1 leading-relaxed",children:e.description}),t.jsx("div",{className:"h-px bg-border-subtle my-2"}),t.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(Zs,{size:10}),Qt(e.downloads||0)]}),(e.rating||0)>0&&t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(kb,{size:10,className:"text-warning",fill:"currentColor"}),(l=e.rating)==null?void 0:l.toFixed(1)]}),t.jsx("span",{className:"flex-1"}),a||r&&t.jsx(ke,{variant:"accent",className:"text-2xs",children:e._installedCount?`${e._installedCount} active`:"Installed"})]})]})}function w4({value:e,onChange:s,placeholder:n="Search skills, tags, authors...",large:a}){const[r,l]=p.useState(e||""),c=p.useRef(null);p.useEffect(()=>{l(e||"")},[e]);function A(f){const m=f.target.value;l(m),clearTimeout(c.current),c.current=setTimeout(()=>s(m),300)}return t.jsxs("div",{className:"relative w-full",children:[t.jsx(Ms,{size:16,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),t.jsx("input",{value:r,onChange:A,placeholder:n,className:V("w-full font-sans outline-none","bg-surface-0 border border-border text-text-0 placeholder:text-text-4","focus:border-accent/40 transition-colors",a?"py-3 pl-11 pr-12 text-[15px] rounded-lg":"py-2.5 pl-10 pr-3 text-sm rounded-md")}),a&&t.jsx("kbd",{className:"absolute right-3.5 top-1/2 -translate-y-1/2 bg-surface-4 text-text-4 px-2 py-0.5 rounded text-xs font-mono",children:"/"})]})}function la(){const e=U(s=>s.addToast);return{success:(s,n)=>e("success",s,n),error:(s,n)=>e("error",s,n),info:(s,n)=>e("info",s,n),warning:(s,n)=>e("warning",s,n)}}const Kt=p.forwardRef(({className:e,label:s,error:n,mono:a,...r},l)=>t.jsxs("div",{className:"flex flex-col gap-1",children:[s&&t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),t.jsx("input",{ref:l,className:V("h-8 w-full rounded-md px-3 text-sm","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",a?"font-mono":"font-sans",n&&"border-danger focus:ring-danger",e),...r}),n&&t.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));Kt.displayName="Input";const jv=p.forwardRef(({className:e,label:s,error:n,mono:a,...r},l)=>t.jsxs("div",{className:"flex flex-col gap-1",children:[s&&t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),t.jsx("textarea",{ref:l,className:V("w-full rounded-md px-3 py-2 text-sm resize-none","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",a?"font-mono":"font-sans",n&&"border-danger focus:ring-danger",e),...r}),n&&t.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));jv.displayName="Textarea";const yQ=["bg-accent/15 text-accent","bg-purple/15 text-purple","bg-success/15 text-success","bg-warning/15 text-warning","bg-danger/15 text-danger","bg-info/15 text-info"];function Dl({item:e,size:s=48}){const n=pi[e.id];if(n)return t.jsx("div",{className:"rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:t.jsx("img",{src:n,alt:e.name,className:"w-6 h-6",onError:l=>{l.target.classList.add("hidden")}})});const a=(e.name||"?")[0].toUpperCase(),r=yQ[(e.name||"").charCodeAt(0)%yQ.length];return t.jsx("div",{className:`rounded-lg flex items-center justify-center flex-shrink-0 text-xl font-bold font-sans ${r}`,style:{width:s,height:s},children:a})}function XO({value:e,onChange:s,placeholder:n,disabled:a}){const[r,l]=p.useState(!1);return t.jsxs("div",{className:"relative",children:[t.jsx(Kt,{type:r?"text":"password",value:e,onChange:c=>s(c.target.value),placeholder:n,disabled:a,mono:!0,className:"pr-9"}),t.jsx("button",{type:"button",onClick:()=>l(c=>!c),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded text-text-4 hover:text-text-1 transition-colors cursor-pointer",tabIndex:-1,children:r?t.jsx(Oo,{size:14}):t.jsx(Hs,{size:14})})]})}function vte({integrationId:e,envKey:s,onSaved:n}){const a=la(),[r,l]=p.useState(""),[c,A]=p.useState(!1),[f,m]=p.useState(s.set),[h,g]=p.useState(!1);async function O(){if(r.trim()){A(!0);try{await G.post(`/integrations/${e}/credentials`,{key:s.key,value:r.trim()}),m(!0),l(""),a.success(`${s.label} saved`),n==null||n()}catch(v){a.error("Failed to save",v.message)}A(!1)}}async function b(){g(!0);try{await G.delete(`/integrations/${e}/credentials/${s.key}`),m(!1),a.success(`${s.label} removed`),n==null||n()}catch(v){a.error("Failed to remove",v.message)}g(!1)}return t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[t.jsx(yi,{size:11,className:"text-text-4"}),s.label,s.required&&t.jsx("span",{className:"text-danger",children:"*"})]}),f&&t.jsxs("span",{className:"flex items-center gap-1 text-2xs text-success font-sans",children:[t.jsx(Je,{size:10})," Set"]})]}),f?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"flex-1 h-8 rounded-md px-3 bg-surface-2 border border-border-subtle flex items-center",children:t.jsx("span",{className:"text-xs text-text-4 font-mono tracking-widest",children:"*".repeat(16)})}),t.jsx(ge,{variant:"ghost",size:"sm",onClick:b,disabled:h,className:"text-text-3 hover:text-danger",children:h?t.jsx(Ie,{size:12,className:"animate-spin"}):t.jsx(qt,{size:12})})]}):t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"flex-1",children:t.jsx(XO,{value:r,onChange:l,placeholder:s.placeholder||`Enter ${s.label.toLowerCase()}...`,disabled:c})}),t.jsx(ge,{variant:"primary",size:"sm",onClick:O,disabled:c||!r.trim(),children:c?t.jsx(Ie,{size:12,className:"animate-spin"}):"Save"})]})]})}function yte({item:e,status:s,installing:n,onInstall:a,onUninstall:r,onNext:l}){var A;const c=s==null?void 0:s.installed;return t.jsxs("div",{className:"px-5 py-5 space-y-5",children:[t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx(Dl,{item:e,size:52}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:e.name}),(e.verified==="mcp-official"||e.verified==="verified")&&t.jsxs(ke,{variant:"accent",className:"text-2xs gap-1",children:[t.jsx(Pn,{size:9})," Verified"]})]}),t.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:e.author||"Community"}),e.category&&t.jsx(ke,{variant:"default",className:"text-2xs mt-2",children:e.category})]})]}),t.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed",children:e.description}),((A=e.tags)==null?void 0:A.length)>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.tags.map(f=>t.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:f},f))}),t.jsx("div",{className:"h-px bg-border-subtle"}),c?t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[t.jsx(Ma,{size:16,className:"text-success"}),t.jsx("span",{className:"text-sm font-medium text-success font-sans",children:"Installed"})]}),t.jsxs(ge,{variant:"ghost",size:"sm",onClick:r,className:"text-text-3 hover:text-danger gap-1.5",children:[t.jsx(qt,{size:12})," Uninstall"]}),t.jsxs(ge,{variant:"primary",size:"sm",onClick:l,className:"gap-1",children:["Configure ",t.jsx(Ct,{size:12})]})]}):t.jsx(ge,{variant:"primary",size:"lg",onClick:a,disabled:n,className:"w-full gap-2",children:n?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:14,className:"animate-spin"}),"Installing..."]}):"Install"}),n&&t.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"This may take up to 30 seconds..."})]})}function wte({item:e,onClose:s}){const n=U(Q=>Q.agents),a=U(Q=>Q.teams),r=U(Q=>Q.installViaExistingAgent),l=U(Q=>Q.spawnIntegrationTeam),[c,A]=p.useState(null),[f,m]=p.useState(!1),[h,g]=p.useState(null),O=n.filter(Q=>Q.status==="running"||Q.status==="idle"),b={};for(const Q of O){const S=Q.teamId||"_none";b[S]||(b[S]=[]),b[S].push(Q)}const v={};for(const Q of a)v[Q.id]=Q.name;async function w(){h&&(await r(e,h),s())}async function N(){m(!0);try{await l(e),s()}catch{m(!1)}}return c?c==="spawn"?t.jsxs("div",{className:"px-5 py-5 space-y-5",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Dl,{item:e,size:36}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Spawn Integration Agent"}),t.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Creates a team and planner for ",e.name]})]})]}),t.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[t.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"What happens next"}),t.jsx("ol",{className:"space-y-1.5",children:[`A new team "${e.name}" will be created`,"A planner agent will spawn with full integration context","The agent will handle installation and configuration"].map((Q,S)=>t.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[t.jsxs("span",{className:"text-accent font-mono flex-shrink-0 w-4 text-right",children:[S+1,"."]}),t.jsx("span",{children:Q})]},S))})]}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ge,{variant:"secondary",size:"lg",onClick:()=>A(null),className:"flex-1",disabled:f,children:"Back"}),t.jsx(ge,{variant:"primary",size:"lg",onClick:N,disabled:f,className:"flex-1 gap-2",children:f?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:14,className:"animate-spin"})," Spawning..."]}):t.jsxs(t.Fragment,{children:[t.jsx(ji,{size:14})," Spawn Agent"]})})]})]}):t.jsxs("div",{className:"px-5 py-5 space-y-4",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Dl,{item:e,size:36}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Choose an Agent"}),t.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Send ",e.name," setup instructions to a running agent"]})]})]}),t.jsx(bt,{className:"max-h-64",children:t.jsx("div",{className:"space-y-3",children:Object.entries(b).map(([Q,S])=>t.jsxs("div",{children:[t.jsx("div",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5 px-1",children:v[Q]||"Unassigned"}),t.jsx("div",{className:"space-y-1",children:S.map(C=>t.jsxs("button",{onClick:()=>g(C.id),className:`w-full text-left px-3 py-2.5 rounded-md border transition-all cursor-pointer flex items-center gap-3 ${h===C.id?"border-accent bg-accent/8":"border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-border"}`,children:[t.jsx(bi,{size:14,className:h===C.id?"text-accent":"text-text-4"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:C.name||C.id}),t.jsx("div",{className:"text-2xs text-text-3 font-sans",children:C.role})]}),h===C.id&&t.jsx(Je,{size:14,className:"text-accent flex-shrink-0"})]},C.id))})]},Q))})}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ge,{variant:"secondary",size:"lg",onClick:()=>{A(null),g(null)},className:"flex-1",children:"Back"}),t.jsxs(ge,{variant:"primary",size:"lg",onClick:w,disabled:!h,className:"flex-1 gap-2",children:[t.jsx(bi,{size:14})," Send Instructions"]})]})]}):t.jsxs("div",{className:"px-5 py-5 space-y-5",children:[t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx(Dl,{item:e,size:52}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("h2",{className:"text-base font-bold text-text-0 font-sans",children:["Install ",e.name]}),t.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Choose how to set up this integration"})]})]}),t.jsx("div",{className:"h-px bg-border-subtle"}),t.jsxs("div",{className:"space-y-2.5",children:[t.jsx("button",{onClick:()=>O.length>0?A("existing"):null,disabled:O.length===0,className:"w-full text-left px-4 py-3.5 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-accent/30 transition-all cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed group",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/15 transition-colors",children:t.jsx(Fn,{size:18,className:"text-accent"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Use Existing Agent"}),t.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:O.length>0?`Send setup instructions to one of ${O.length} running agent${O.length!==1?"s":""}`:"No agents running — spawn one first"})]}),O.length>0&&t.jsx(Ct,{size:14,className:"text-text-4 group-hover:text-accent transition-colors"})]})}),t.jsx("button",{onClick:()=>A("spawn"),className:"w-full text-left px-4 py-3.5 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-accent/30 transition-all cursor-pointer group",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-9 h-9 rounded-lg bg-purple/10 flex items-center justify-center flex-shrink-0 group-hover:bg-purple/15 transition-colors",children:t.jsx(ji,{size:18,className:"text-purple"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn New Agent"}),t.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:"Create a dedicated team and planner for this integration"})]}),t.jsx(Ct,{size:14,className:"text-text-4 group-hover:text-accent transition-colors"})]})})]})]})}const jte={gmail:"Gmail API","google-calendar":"Google Calendar API","google-drive":"Google Drive API","google-docs":"Google Docs API","google-sheets":"Google Sheets API","google-slides":"Google Slides API"};function j4({integrationId:e,onConfigured:s}){const n=la(),[a,r]=p.useState(""),[l,c]=p.useState(""),[A,f]=p.useState(!1),m=jte[e]||"the relevant Google API";async function h(){if(!(!a.trim()||!l.trim())){f(!0);try{await G.post("/integrations/google-oauth/setup",{clientId:a.trim(),clientSecret:l.trim()}),n.success("Google OAuth credentials saved"),s()}catch(O){n.error("Failed to save",O.message)}f(!1)}}const g=[{text:"Go to the Google Cloud Console and sign in with your Google account",link:{url:"https://console.cloud.google.com",label:"Open Google Cloud Console"}},{text:"Create a new project (or select an existing one). Any name is fine — this is just a container for your credentials."},{text:t.jsxs(t.Fragment,{children:["Enable the ",t.jsx("strong",{children:m})," — search for it in the API Library and click ",t.jsx("strong",{children:"Enable"})]}),link:{url:"https://console.cloud.google.com/apis/library",label:"Open API Library"}},{text:t.jsxs(t.Fragment,{children:["Go to ",t.jsx("strong",{children:"Credentials"})," and click ",t.jsx("strong",{children:"Create Credentials"})," → ",t.jsx("strong",{children:"OAuth client ID"})]}),link:{url:"https://console.cloud.google.com/apis/credentials",label:"Open Credentials page"}},{text:t.jsxs(t.Fragment,{children:["If prompted to configure the consent screen, choose ",t.jsx("strong",{children:"External"}),', fill in an app name (e.g. "Groove"), your email, and save. You can skip optional fields.']})},{text:t.jsxs(t.Fragment,{children:["Go to ",t.jsx("strong",{children:"Audience"})," and click ",t.jsx("strong",{children:"Publish App"}),". Then scroll down to ",t.jsx("strong",{children:"Test users"}),", click ",t.jsx("strong",{children:"Add Users"}),", enter your Google email address, and save."]})},{text:t.jsxs(t.Fragment,{children:["For Application type, choose ",t.jsx("strong",{children:"Desktop app"})," (not Web application). Give it any name."]})},{text:t.jsxs(t.Fragment,{children:["Click ",t.jsx("strong",{children:"Create"}),", then copy the ",t.jsx("strong",{children:"Client ID"})," and ",t.jsx("strong",{children:"Client Secret"})," and paste them below."]})}];return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-3",children:[t.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"How to get your Google credentials"}),t.jsx("ol",{className:"space-y-2.5",children:g.map((O,b)=>t.jsxs("li",{className:"flex gap-2.5 text-xs text-text-2 font-sans leading-relaxed",children:[t.jsxs("span",{className:"text-accent font-mono font-bold flex-shrink-0 w-4 text-right",children:[b+1,"."]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("span",{children:O.text}),O.link&&t.jsxs("a",{href:O.link.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-2xs text-accent font-sans hover:underline mt-0.5",children:[t.jsx(Gs,{size:9}),O.link.label]}),O.copyable&&t.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[t.jsx("code",{className:"flex-1 min-w-0 text-2xs font-mono text-accent bg-surface-4 px-2.5 py-1.5 rounded select-all break-all",children:O.copyable}),t.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(O.copyable)},className:"flex-shrink-0 p-1.5 rounded text-text-3 hover:text-accent hover:bg-accent/10 transition-colors cursor-pointer",title:"Copy to clipboard",children:t.jsx(za,{size:12})})]})]})]},b))})]}),t.jsx("div",{className:"bg-accent/8 border border-accent/15 rounded-md px-4 py-2.5",children:t.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[t.jsx("strong",{className:"text-text-1",children:"One-time setup"})," — these same credentials work for Gmail, Calendar, Drive, Docs, Sheets, and Slides. You only need to do this once. For each integration, just enable the matching API in your Google Cloud project."]})}),t.jsx("div",{className:"bg-warning/8 border border-warning/15 rounded-md px-4 py-2.5",children:t.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[t.jsx("strong",{className:"text-text-1",children:'Google "unverified app" warning'})," — when signing in, Google may show a warning that the app isn't verified. This is normal for personal OAuth apps. Click ",t.jsx("strong",{children:"Advanced"}),", then ",t.jsx("strong",{children:"Go to [your app name] (unsafe)"})," to continue. Your credentials stay local and are never sent to Groove servers."]})}),t.jsx("div",{className:"h-px bg-border-subtle"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[t.jsx(yi,{size:11,className:"text-text-4"}),"Client ID ",t.jsx("span",{className:"text-danger",children:"*"})]}),t.jsx(XO,{value:a,onChange:r,placeholder:"123456789.apps.googleusercontent.com",disabled:A})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[t.jsx(yi,{size:11,className:"text-text-4"}),"Client Secret ",t.jsx("span",{className:"text-danger",children:"*"})]}),t.jsx(XO,{value:l,onChange:c,placeholder:"GOCSPX-...",disabled:A})]})]}),t.jsx(ge,{variant:"primary",size:"lg",onClick:h,disabled:A||!a.trim()||!l.trim(),className:"w-full gap-2",children:A?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:14,className:"animate-spin"})," Saving..."]}):"Save Credentials"})]})}function Qte({item:e,status:s,onDone:n,onRefreshStatus:a}){var N;const r=la(),[l,c]=p.useState(!1),[A,f]=p.useState(null),m=e.authType,h=m==="google-autoauth"||m==="oauth-google";p.useEffect(()=>{h&&G.get("/integrations/google-oauth/status").then(Q=>f(Q.configured)).catch(()=>f(!1))},[h]);const g=p.useRef(null);p.useEffect(()=>()=>{g.current&&clearInterval(g.current)},[]);async function O(){c(!0);try{const Q=await G.post(`/integrations/${e.id}/oauth/start`);if(Q.url){const S=await aS(Q.url);if(S!=null&&S.error){r.error("Sign-in failed",S.error),c(!1);return}r.success("Browser opened — complete sign-in there");let C=0;g.current&&clearInterval(g.current),g.current=setInterval(async()=>{if(C+=2e3,C>6e4){clearInterval(g.current),g.current=null,c(!1);return}try{const k=await G.get(`/integrations/${e.id}/status`);((k==null?void 0:k.envKeys)||[]).some(T=>T.key==="GOOGLE_REFRESH_TOKEN"&&T.set)&&(clearInterval(g.current),g.current=null,r.success("Connected!",`${e.name} is now authenticated`),a(),c(!1))}catch{}},2e3)}}catch(Q){r.error("Sign-in failed",Q.message),c(!1)}}const b=(s==null?void 0:s.envKeys)||[],v=b.filter(Q=>Q.required&&!Q.hidden),w=v.length===0||v.every(Q=>Q.set);return t.jsxs("div",{className:"px-5 py-5 space-y-5",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Dl,{item:e,size:36}),t.jsxs("div",{children:[t.jsxs("h2",{className:"text-sm font-bold text-text-0 font-sans",children:["Configure ",e.name]}),t.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Set up credentials to connect"})]})]}),((N=e.setupSteps)==null?void 0:N.length)>0&&!(h&&A===!1)&&t.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[t.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Setup guide"}),t.jsx("ol",{className:"space-y-1.5",children:e.setupSteps.map((Q,S)=>t.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[t.jsxs("span",{className:"text-text-4 font-mono flex-shrink-0 w-4 text-right",children:[S+1,"."]}),t.jsx("span",{children:Q})]},S))}),e.setupUrl&&t.jsxs("a",{href:e.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-accent font-sans hover:underline mt-1",children:[t.jsx(Gs,{size:11}),new URL(e.setupUrl).hostname]})]}),!(h&&A===!1)&&t.jsx("div",{className:"h-px bg-border-subtle"}),m==="api-key"&&t.jsx("div",{className:"space-y-4",children:b.filter(Q=>!Q.hidden).map(Q=>t.jsx(vte,{integrationId:e.id,envKey:Q,onSaved:a},Q.key))}),h&&A===!1&&t.jsx(j4,{integrationId:e.id,onConfigured:()=>f(!0)}),h&&A&&t.jsxs("div",{className:"space-y-3",children:[t.jsx(ge,{variant:"primary",size:"lg",onClick:O,disabled:l,className:"w-full gap-2",children:l?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:14,className:"animate-spin"}),"Opening browser..."]}):t.jsxs(t.Fragment,{children:[t.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),t.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["A browser window will open — sign in and allow access to your ",e.name]}),t.jsx("button",{type:"button",onClick:()=>f(!1),className:"w-full text-2xs text-text-4 font-sans hover:text-text-2 transition-colors cursor-pointer py-1",children:"Reconfigure Google OAuth credentials"})]}),h&&A===null&&t.jsx("div",{className:"flex justify-center py-3",children:t.jsx(Ie,{size:16,className:"animate-spin text-text-4"})}),t.jsx(ge,{variant:w?"primary":"secondary",size:"lg",onClick:n,className:"w-full gap-1.5",children:w?t.jsxs(t.Fragment,{children:[t.jsx(Je,{size:14}),"Done"]}):"Skip for now"})]})}function Ste({item:e,onClose:s}){return t.jsxs("div",{className:"px-5 py-10 flex flex-col items-center text-center space-y-4",children:[t.jsx("div",{className:"w-14 h-14 rounded-full bg-success/15 flex items-center justify-center",children:t.jsx(Ma,{size:28,className:"text-success"})}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:"Integration ready"}),t.jsxs("p",{className:"text-sm text-text-3 font-sans mt-1",children:[e.name," is installed and configured. Agents can now use it."]})]}),t.jsx(ge,{variant:"primary",size:"lg",onClick:s,className:"mt-2",children:"Close"})]})}function Q4({integration:e,open:s,onClose:n}){const a=la(),[r,l]=p.useState("overview"),[c,A]=p.useState(null),[f,m]=p.useState(!1),[h,g]=p.useState(!0),O=e==null?void 0:e.id,b=p.useCallback(async()=>{if(O){try{const C=await G.get(`/integrations/${O}/status`);A(C)}catch{A(null)}g(!1)}},[O]);p.useEffect(()=>{s&&e&&(l("overview"),g(!0),b())},[s,e,b]);function v(){l("agent-setup")}async function w(){try{await G.delete(`/integrations/${e.id}`),a.success(`${e.name} uninstalled`),await b()}catch(C){a.error("Uninstall failed",C.message)}}function N(){l("configure")}function Q(){l("done")}if(!e)return null;const S={overview:e.name,"agent-setup":"Install",configure:"Configure",done:"Complete"};return t.jsx(_t,{open:s,onOpenChange:C=>{C||n()},children:t.jsx(zt,{title:S[r]||e.name,description:`Setup wizard for ${e.name}`,className:"max-w-md",children:h?t.jsx("div",{className:"px-5 py-10 flex items-center justify-center",children:t.jsx(Ie,{size:20,className:"animate-spin text-text-4"})}):r==="overview"?t.jsx(yte,{item:e,status:c,installing:f,onInstall:v,onUninstall:w,onNext:N}):r==="agent-setup"?t.jsx(wte,{item:e,onClose:n}):r==="configure"?t.jsx(Qte,{item:e,status:c,onDone:Q,onRefreshStatus:b}):t.jsx(Ste,{item:e,onClose:n})})})}const Nte=["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"];function Bte({item:e,status:s,onInstall:n,onUninstall:a,busy:r}){const l=s==null?void 0:s.installed,c=s==null?void 0:s.authenticated;return t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-2 border border-border-subtle",children:[t.jsx(Dl,{item:e,size:32}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans",children:e.name}),t.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:e.description})]}),l&&c&&!(s!=null&&s.needsReauth)&&t.jsxs(ke,{variant:"success",className:"text-2xs flex-shrink-0 gap-1",children:[t.jsx(Je,{size:8})," Ready"]}),l&&c&&(s==null?void 0:s.needsReauth)&&t.jsxs(ke,{variant:"warning",className:"text-2xs flex-shrink-0 gap-1",children:[t.jsx(Ks,{size:8})," Update"]}),l&&!c&&t.jsx(ke,{variant:"warning",className:"text-2xs flex-shrink-0",children:"Needs sign-in"}),t.jsx(ge,{variant:l?"ghost":"primary",size:"sm",onClick:()=>l?a(e.id):n(e.id),disabled:r===e.id,className:l?"text-text-3 hover:text-danger":"",children:r===e.id?t.jsx(Ie,{size:12,className:"animate-spin"}):l?t.jsx(qt,{size:12}):"Install"})]})}function Cte({integrations:e,open:s,onClose:n}){const a=la(),[r,l]=p.useState(null),[c,A]=p.useState({}),[f,m]=p.useState(null),[h,g]=p.useState(!1),[O,b]=p.useState(!0),v=p.useRef(null),w=e.filter(T=>Nte.includes(T.id)),N=p.useCallback(async()=>{const T={};await Promise.all(w.map(async $=>{try{T[$.id]=await G.get(`/integrations/${$.id}/status`)}catch{T[$.id]=null}})),A(T),b(!1)},[w.map(T=>T.id).join(",")]);p.useEffect(()=>(s&&(b(!0),G.get("/integrations/google-oauth/status").then(T=>l(T.configured)).catch(()=>l(!1)),N()),()=>{v.current&&clearInterval(v.current)}),[s]);const Q=Object.entries(c).filter(([,T])=>T==null?void 0:T.installed).map(([T])=>T),S=Q.length>0&&Q.every(T=>{var $;return($=c[T])==null?void 0:$.authenticated});Q.some(T=>{var $;return!(($=c[T])!=null&&$.authenticated)});const C=S&&Q.some(T=>{var $;return($=c[T])==null?void 0:$.needsReauth});async function k(T){var $;m(T);try{await G.post(`/integrations/${T}/install`),a.success(`${($=w.find(M=>M.id===T))==null?void 0:$.name} installed`),await N()}catch(M){a.error("Install failed",M.message)}m(null)}async function F(T){var $;m(T);try{await G.delete(`/integrations/${T}`),a.success(`${($=w.find(M=>M.id===T))==null?void 0:$.name} removed`),await N()}catch(M){a.error("Uninstall failed",M.message)}m(null)}async function B(){if(!Q.length){a.error("Install at least one service first");return}g(!0);try{const T=await G.post("/integrations/google-workspace/oauth/start",{integrationIds:Q});if(T.url){const $=await aS(T.url);if($!=null&&$.error){a.error("Sign-in failed",$.error),g(!1);return}a.success("Browser opened — complete sign-in there"),v.current&&clearInterval(v.current),v.current=setInterval(async()=>{await N()},3e3),setTimeout(()=>{v.current&&clearInterval(v.current)},18e4)}}catch(T){a.error("Sign-in failed",T.message)}g(!1)}return p.useEffect(()=>{S&&v.current&&(clearInterval(v.current),v.current=null)},[S]),s?t.jsx(_t,{open:s,onOpenChange:T=>{T||n()},children:t.jsx(zt,{title:"Google Workspace",description:"Connect your Google services",className:"max-w-md",children:t.jsxs("div",{className:"px-5 py-5 space-y-5",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-11 h-11 rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0",children:t.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"Google",className:"w-6 h-6"})}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Google Workspace"}),t.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"One set of credentials for all Google services"})]})]}),r===!1&&t.jsx(j4,{integrationId:"gmail",onConfigured:()=>l(!0)}),r===null&&t.jsx("div",{className:"flex justify-center py-3",children:t.jsx(Ie,{size:16,className:"animate-spin text-text-4"})}),r&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans",children:"Services"}),t.jsx("div",{className:"space-y-1.5",children:O?Array.from({length:4}).map((T,$)=>t.jsx("div",{className:"h-14 rounded-md bg-surface-2 animate-pulse"},$)):w.map(T=>t.jsx(Bte,{item:T,status:c[T.id],onInstall:k,onUninstall:F,busy:f},T.id))})]}),t.jsx("div",{className:"h-px bg-border-subtle"}),Q.length>0&&!S&&t.jsxs("div",{className:"space-y-3",children:[t.jsx(ge,{variant:"primary",size:"lg",onClick:B,disabled:h,className:"w-full gap-2",children:h?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:14,className:"animate-spin"})," Opening browser..."]}):t.jsxs(t.Fragment,{children:[t.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),t.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["Connects ",Q.length," service",Q.length!==1?"s":""," with one sign-in"]})]}),S&&Q.length>0&&t.jsxs("div",{className:"flex flex-col items-center text-center gap-2 py-2",children:[t.jsx("div",{className:"w-10 h-10 rounded-full bg-success/15 flex items-center justify-center",children:t.jsx(Ma,{size:20,className:"text-success"})}),t.jsx("p",{className:"text-sm font-medium text-success font-sans",children:"All services connected"}),t.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Your agents can now use these Google integrations."}),C?t.jsxs("div",{className:"w-full space-y-2 pt-2",children:[t.jsx("p",{className:"text-2xs text-warning font-sans",children:"New permissions available — re-authenticate to enable all features."}),t.jsx(ge,{variant:"secondary",size:"sm",onClick:B,disabled:h,className:"w-full gap-2",children:h?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:12,className:"animate-spin"})," Opening browser..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Ks,{size:12})," Re-authenticate"]})})]}):t.jsx("button",{onClick:B,disabled:h,className:"text-2xs text-text-4 hover:text-text-2 font-sans underline underline-offset-2 transition-colors mt-1",children:h?"Opening browser...":"Re-authenticate"})]}),Q.length===0&&!O&&t.jsx("p",{className:"text-xs text-text-4 font-sans text-center py-2",children:"Install at least one service above, then connect with Google."})]}),t.jsx(ge,{variant:"secondary",size:"lg",onClick:n,className:"w-full",children:S&&Q.length>0?"Done":"Close"})]})})}):null}const Tg=/github\.com\/([^/]+)\/([^/\s#?]+)/;function kte(){const[e,s]=p.useState("input"),[n,a]=p.useState(""),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,m]=p.useState("standalone"),[h,g]=p.useState(""),[O,b]=p.useState(!0),[v,w]=p.useState(""),N=U(T=>T.previewRepo),Q=U(T=>T.importRepo),S=U(T=>T.importInProgress),C=la(),k=p.useCallback(async T=>{const $=T.match(Tg);if($){l(!0);try{const M=await N(T);A(M),w(M.name||$[2]),s("preview")}catch(M){C.error("Preview failed",M.message)}finally{l(!1)}}},[N,C]),F=p.useCallback(T=>{const $=T.target.value;a($),Tg.test($)&&e==="input"&&k($)},[e,k]),B=p.useCallback(async()=>{if(!c)return;let T;f==="standalone"?T=`~/Projects/${c.name}`:f==="subdirectory"?T=`./packages/${c.name}`:T=h;try{await Q(n,T,O,v),C.success(`Importing ${c.name}`,"Setup agent will handle the rest"),s("input"),a(""),A(null)}catch($){C.error("Import failed",$.message)}},[c,f,h,n,O,v,Q,C]);if(e==="input")return t.jsxs("div",{className:"relative",children:[t.jsx(Ms,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),t.jsx("input",{type:"text",value:n,onChange:F,placeholder:"Paste a GitHub URL...",className:V("w-full h-9 rounded-lg pl-9 pr-20 text-sm font-sans","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors duration-100")}),t.jsx(ge,{variant:"primary",size:"sm",className:"absolute right-1.5 top-1/2 -translate-y-1/2",onClick:()=>k(n),disabled:!Tg.test(n)||r,children:r?t.jsx(Ie,{size:12,className:"animate-spin"}):"Preview"})]});if(e==="preview"&&c)return t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-5",children:t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/8 flex items-center justify-center flex-shrink-0",children:t.jsx(Il,{size:22,className:"text-accent"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[t.jsx("span",{className:"text-lg font-bold text-text-0 font-sans",children:c.name}),t.jsx("span",{className:"text-xs text-text-4 font-sans",children:c.owner})]}),t.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[c.language&&t.jsx(ke,{variant:"outline",className:"text-2xs",children:c.language}),c.stars!=null&&t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(kb,{size:10,className:"text-warning",fill:"currentColor"}),Qt(c.stars)]}),c.license&&t.jsx("span",{children:c.license})]})]}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[t.jsxs(ge,{variant:"primary",size:"sm",onClick:()=>s("configure"),className:"h-8 text-xs gap-1.5 px-4",children:[t.jsx(Vs,{size:13}),"Clone & Setup"]}),t.jsxs(ge,{variant:"ghost",size:"sm",onClick:()=>{try{const T=n.startsWith("http")?n:`https://${n}`,$=new URL(T);($.protocol==="https:"||$.protocol==="http:")&&window.open(T,"_blank")}catch{}},className:"h-8 text-xs gap-1.5",children:[t.jsx(Gs,{size:12}),"GitHub"]}),t.jsx("button",{onClick:()=>{s("input"),A(null)},className:"text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 ml-1",children:"Cancel"})]})]})}),c.description&&t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[t.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2",children:"About"}),t.jsx("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:c.description})]}),c.readmePreview&&t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[t.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-3",children:"README"}),t.jsx("div",{className:"text-sm text-text-2 font-sans leading-relaxed whitespace-pre-wrap",children:c.readmePreview})]})]});if(e==="configure"&&c){const T=[{id:"standalone",icon:ad,title:"Standalone project",description:"Clone to its own directory, separate from this workspace",path:`~/Projects/${c.name}`},{id:"subdirectory",icon:Nb,title:"Workspace package",description:"Add as a package inside this project's monorepo",path:`./packages/${c.name}`},{id:"custom",icon:$M,title:"Custom location",description:"Choose your own path",path:null}];return t.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-2 overflow-hidden",children:[t.jsx("div",{className:"px-5 py-4 border-b border-border-subtle bg-surface-3/50",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0",children:t.jsx(Zs,{size:16,className:"text-accent"})}),t.jsxs("div",{children:[t.jsxs("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:["Clone ",c.name]}),t.jsxs("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:[c.owner,"/",c.name," — configure where to install"]})]})]})}),t.jsxs("div",{className:"px-5 py-4 space-y-5",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2.5 block",children:"Install location"}),t.jsx("div",{className:"space-y-2",children:T.map($=>{const M=$.icon,I=f===$.id;return t.jsx("button",{onClick:()=>m($.id),className:V("w-full text-left rounded-lg border p-3.5 transition-all duration-150 cursor-pointer",I?"border-accent bg-accent/5 ring-1 ring-accent/30":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-1/80"),children:t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:V("w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0 mt-0.5",I?"bg-accent/15 text-accent":"bg-surface-3 text-text-4"),children:t.jsx(M,{size:15})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:V("text-xs font-semibold font-sans",I?"text-text-0":"text-text-2"),children:$.title}),I&&t.jsx("div",{className:"w-4 h-4 rounded-full bg-accent flex items-center justify-center",children:t.jsx(Je,{size:10,className:"text-white"})})]}),t.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5 leading-relaxed",children:$.description}),$.path&&I&&t.jsx("code",{className:"text-2xs text-accent/80 font-mono mt-1.5 block truncate",children:$.path})]})]})},$.id)})}),f==="custom"&&t.jsx("div",{className:"mt-2.5 ml-11",children:t.jsx("input",{value:h,onChange:$=>g($.target.value),placeholder:"/path/to/clone",autoFocus:!0,className:V("w-full h-9 px-3 text-xs font-mono rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]}),t.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-3 flex items-center justify-center",children:t.jsx(Fn,{size:14,className:"text-text-4"})}),t.jsxs("div",{children:[t.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans block",children:"Create a team"}),t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Organize agents working on this repo into their own team"})]})]}),t.jsx("button",{onClick:()=>b(!O),className:V("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer flex-shrink-0",O?"bg-accent":"bg-surface-5"),children:t.jsx("div",{className:V("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",O?"translate-x-4":"translate-x-0")})})]}),O&&t.jsx("div",{className:"mt-2.5 ml-11",children:t.jsx("input",{value:v,onChange:$=>w($.target.value),placeholder:"Team name",className:V("w-full h-9 px-3 text-xs font-sans rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]})]}),t.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle bg-surface-3/30 flex items-center justify-between",children:[t.jsxs("button",{onClick:()=>s("preview"),className:"flex items-center gap-1.5 text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 transition-colors",children:[t.jsx(nN,{size:11}),"Back"]}),t.jsx(ge,{variant:"primary",size:"sm",onClick:B,disabled:S||f==="custom"&&!h.trim(),className:"h-8 text-xs gap-1.5 px-5",children:S?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:12,className:"animate-spin"})," Importing..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Zs,{size:12})," Clone & Setup"]})})]})]})}return null}function Tte({repo:e,onRemove:s,onNuke:n,onOpen:a}){return t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-3 flex items-center gap-3",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:e.repoName||e.name}),t.jsx("span",{className:"text-2xs text-text-3 font-sans",children:e.repoOwner||e.owner})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.language&&t.jsx(ke,{variant:"outline",className:"text-2xs",children:e.language}),t.jsx("span",{className:"text-2xs text-text-4 font-mono truncate max-w-[180px]",children:e.clonedTo||e.path})]}),t.jsx("span",{className:"text-2xs text-text-4 font-sans mt-0.5 block",children:e.clonedAt?`Imported ${ls(e.clonedAt)}`:e.status||""})]}),t.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a&&t.jsxs("button",{onClick:()=>a(e),className:V("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-accent bg-accent/10 hover:bg-accent/20 border-0 transition-colors"),children:[t.jsx(Vs,{size:11}),"Open"]}),s&&t.jsxs("button",{onClick:()=>s(e),className:V("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-text-3 hover:text-text-1 hover:bg-surface-4 bg-transparent border-0 transition-colors"),children:[t.jsx(qt,{size:11}),"Remove"]}),n&&t.jsxs("button",{onClick:()=>n(e),className:V("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-danger bg-danger/10 hover:bg-danger/20 border-0 transition-colors"),children:[t.jsx(b$,{size:11}),"Nuke"]})]})]})}function Ute({repo:e,open:s,onClose:n,onConfirm:a}){var h,g,O;const[r,l]=p.useState(!0);if(!e)return null;const c=((h=e.agents)==null?void 0:h.length)||0,A=((g=e.processes)==null?void 0:g.length)||0,f=((O=e.credentialKeys)==null?void 0:O.length)||0,m=e.fileCount||0;return t.jsx(_t,{open:s,onOpenChange:b=>{b||n()},children:t.jsx(zt,{title:`Nuke ${e.repoName||e.name}?`,description:"Confirm destructive removal of imported repo",children:t.jsxs("div",{className:"px-5 py-4 space-y-4",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(sa,{size:16,className:"text-danger flex-shrink-0 mt-0.5"}),t.jsx("p",{className:"text-sm text-text-1 font-sans",children:"This cannot be undone."})]}),t.jsxs("div",{className:"space-y-1.5 text-xs text-text-2 font-sans",children:[c>0&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-success",children:"✓"})," Kill ",c," agent",c!==1?"s":""]}),A>0&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-success",children:"✓"})," Stop ",A," process",A!==1?"es":""]}),f>0&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-success",children:"✓"})," Remove ",f," credential",f!==1?"s":""]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-success",children:"✓"}),' Delete team "',e.teamId||e.repoName||e.name,'"']}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-success",children:"✓"})," Clean all .groove state"]})]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:b=>l(b.target.checked),className:"accent-[var(--color-danger)]"}),t.jsxs("span",{className:"text-xs text-text-1 font-sans",children:["Delete repo files",m>0?` (${m} files)`:""]})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(ge,{variant:"danger",size:"sm",onClick:()=>a(r),children:"Nuke Everything"}),t.jsx(ge,{variant:"ghost",size:"sm",onClick:n,children:"Cancel"})]})]})})})}function Ete({skill:e,onBack:s}){var F,B,T;const n=la(),[a,r]=p.useState(""),[l,c]=p.useState(!1),[A,f]=p.useState(!1),[m,h]=p.useState(!1),[g,O]=p.useState(!1),[b,v]=p.useState(e.installed),[w,N]=p.useState(!0);p.useEffect(()=>{N(!0),G.get(`/skills/${e.id}/content`).then($=>{r($.content||""),c($.requiresPurchase||!1)}).catch(()=>{}).finally(()=>N(!1))},[e.id]);async function Q(){f(!0);try{await G.post(`/skills/${e.id}/install`),v(!0),n.success(`${e.name} installed`)}catch($){n.error("Install failed",$.message)}f(!1)}async function S(){h(!0);try{await G.post(`/skills/${e.id}/update`),n.success(`${e.name} updated to latest`);const $=await G.get(`/skills/${e.id}/content`);$.content&&r($.content)}catch($){n.error("Update failed",$.message)}h(!1)}async function C(){O(!0);try{await G.delete(`/skills/${e.id}`),v(!1),n.success(`${e.name} uninstalled`)}catch($){n.error("Uninstall failed",$.message)}O(!1)}async function k(){const{marketplaceAuthenticated:$,marketplaceLogin:M,marketplaceCheckout:I}=U.getState();if(!$){M();return}try{await I(e.id)}catch{}}return t.jsx(bt,{className:"h-full",children:t.jsxs("div",{className:"px-6 py-5",children:[t.jsxs("button",{onClick:s,className:"flex items-center gap-1 text-xs text-text-3 font-sans hover:text-text-0 cursor-pointer bg-transparent border-0 mb-4",children:[t.jsx(Ei,{size:14})," Back"]}),t.jsxs("div",{className:"flex gap-8",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"w-11 h-11 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-[22px]",children:e.icon||((B=(F=e.name)==null?void 0:F[0])==null?void 0:B.toUpperCase())}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:e.name}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-text-3 font-sans",children:[t.jsx("span",{children:e.author||"Community"}),(e.source==="claude-official"||e.verified)&&t.jsx(gte,{type:e.source,size:13})]})]})]}),t.jsx("p",{className:"mt-3 text-sm text-text-2 font-sans leading-relaxed",children:e.description}),((T=e.tags)==null?void 0:T.length)>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:e.tags.map($=>t.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:$},$))}),t.jsx("div",{className:"h-px bg-border-subtle my-5"}),w?t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"h-3 w-48 bg-surface-4 rounded animate-pulse"}),t.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),t.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}):a?t.jsxs("div",{className:"text-sm text-text-2 font-sans leading-relaxed",children:[t.jsx("h2",{className:"text-sm font-semibold text-text-0 mb-2",children:"About"}),t.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:a})]}):l?t.jsxs("div",{className:"bg-warning/5 border border-warning/15 rounded-lg px-4 py-3",children:[t.jsx("p",{className:"text-sm text-text-1 font-sans font-medium",children:"Paid skill — purchase to view content"}),t.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Sign in and purchase this skill to access its full instructions."})]}):t.jsx("p",{className:"text-xs text-text-4 font-sans",children:"Content loading failed — check your connection."})]}),t.jsx("div",{className:"w-[240px] flex-shrink-0",children:t.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-lg p-4 sticky top-4",children:[t.jsx(pte,{price:e.price||0,size:"md"}),l&&!b?t.jsxs("button",{onClick:k,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 flex items-center justify-center gap-2 border bg-warning/15 text-warning border-warning/20 hover:bg-warning/25",children:["Buy $",(e.price||0).toFixed(2)]}):b?t.jsxs("div",{className:"mt-3 flex flex-col gap-1.5",children:[t.jsxs("button",{onClick:S,disabled:m,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:[t.jsx(Ks,{size:12,className:m?"animate-spin":""}),m?"Updating...":"Pull Latest"]}),t.jsxs("button",{onClick:C,disabled:g,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-error/10 text-error border-error/20 hover:bg-error/15",children:[t.jsx(qt,{size:12}),g?"Removing...":"Uninstall"]})]}):t.jsx("button",{onClick:Q,disabled:A,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:A?"Installing...":"Install"}),t.jsx("div",{className:"mt-4 flex flex-col gap-2.5",children:[["Downloads",t.jsx("span",{className:"font-mono text-text-0",children:Qt(e.downloads||0)},"d")],["Rating",t.jsx(mte,{rating:e.rating||0,count:e.rating_count||e.ratingCount,size:"sm"},"r")],["Version",t.jsx("span",{className:"font-mono text-text-0",children:e.version||"1.0.0"},"v")],["Category",t.jsx(hte,{label:e.category||"general",variant:e.category||"draft"},"c")],["Source",t.jsx("span",{className:"text-text-0",children:e.source==="claude-official"?"Anthropic":"Community"},"s")]].map(([$,M])=>t.jsxs("div",{className:"flex justify-between items-center text-xs font-sans",children:[t.jsx("span",{className:"text-text-3",children:$}),M]},$))})]})})]})]})})}function Pte({open:e,onClose:s}){const[n,a]=p.useState("new"),[r,l]=p.useState(""),[c,A]=p.useState(""),[f,m]=p.useState(""),[h,g]=p.useState(""),[O,b]=p.useState(""),[v,w]=p.useState(!1),N=U(M=>M.teams),Q=U(M=>M.activeTeamId),S=U(M=>M.createTeam),C=U(M=>M.spawnAgent),k=U(M=>M.setActiveView),F=U(M=>M.selectAgent),B=la();p.useEffect(()=>{e&&(a("new"),l(""),A(Q||""),m(""),g(""),b(""),w(!1))},[e,Q]);async function T(){if(f.trim()){w(!0);try{let M;n==="new"?M=(await S(r.trim()||f.trim())).id:M=c;const I=[`The user wants to integrate the **${f.trim()}** API into their project.`,""];h.trim()&&I.push(`**API Documentation:** ${h.trim()}`),O.trim()&&I.push("**API Key:** The user has provided an API key. Store it securely using environment variables — never hardcode it."),I.push("","Start by:","1. Reviewing the API documentation to understand available endpoints and authentication","2. Asking the user what they want to build with this API","3. Setting up the necessary configuration and authentication","4. Building the integration together","","Ask the user about their project and how they'd like to use this API.");const se=I.join(`
|
|
982
|
+
disabled:cursor-not-allowed`})]}),t.jsx("span",{className:"text-[11px] text-accent font-mono font-medium w-9 text-right shrink-0 tabular-nums",children:O})]})}const _J={agentNode:dB,rootNode:uB},Sg=220,Ng=82,xf=260,mf=130,ao=4,zs="__groove_root__";function SA(e){if(!e)return{};try{return JSON.parse(localStorage.getItem(`groove:nodePositions:${e}`)||"{}")}catch{return{}}}function f4(){let e=!1;for(const s of["groove:chatHistory","groove:activityLog"])localStorage.getItem(s)!==null&&(localStorage.removeItem(s),e=!0);return e}function xQ(e,s){if(!e)return;const n=`groove:nodePositions:${e}`,a=JSON.stringify(s);try{localStorage.setItem(n,a);return}catch{}if(f4())try{localStorage.setItem(n,a)}catch{}}function x4(){try{return JSON.parse(localStorage.getItem("groove:roleLayout")||"{}")}catch{return{}}}function zJ(e){const s="groove:roleLayout",n=JSON.stringify(e);try{localStorage.setItem(s,n);return}catch{}if(f4())try{localStorage.setItem(s,n)}catch{}}function m4(){try{return JSON.parse(localStorage.getItem("groove:teamViewports")||"{}")}catch{return{}}}function LJ(e,s){try{const n=m4();n[e]=s,localStorage.setItem("groove:teamViewports",JSON.stringify(n))}catch{}}function DJ(e,s){const n=e.filter(c=>{var A;return c.teamId===s&&!((A=c.metadata)!=null&&A.scheduled)});return n.length===0?"idle":n.some(c=>c.status==="running"||c.status==="starting")?"working":n.every(c=>c.status==="completed")?"completed":n.some(c=>c.status==="crashed")?"crashed":"idle"}function HJ(){const e=U(E=>E.teams),s=U(E=>E.activeTeamId),n=U(E=>E.agents),a=U(E=>E.switchTeam),r=U(E=>E.createTeam),l=U(E=>E.deleteTeamPermanently),c=U(E=>E.renameTeam),A=U(E=>E.cloneTeam),f=U(E=>E.reorderTeams),m=U(E=>E.addToast),[h,g]=p.useState(!1),[O,b]=p.useState(""),[v,w]=p.useState(null),[N,Q]=p.useState(""),S=p.useRef(!1),[C,k]=p.useState(null),[F,B]=p.useState(null),T=p.useRef(null),[$,M]=p.useState(!1),[I,se]=p.useState(!1),H=p.useCallback(()=>{const E=T.current;E&&(M(E.scrollLeft>0),se(E.scrollLeft+E.clientWidth<E.scrollWidth-1))},[]);p.useEffect(()=>{const E=T.current;if(!E)return;H(),E.addEventListener("scroll",H);const q=new ResizeObserver(H);return q.observe(E),()=>{E.removeEventListener("scroll",H),q.disconnect()}},[H,e.length]);function ne(){const E=O.trim();!E||S.current||(S.current=!0,b(""),g(!1),r(E).finally(()=>{S.current=!1,setTimeout(()=>{T.current&&T.current.scrollTo({left:T.current.scrollWidth,behavior:"smooth"})},100)}))}function K(E){w(E.id),Q(E.name)}function L(){const E=N.trim();if(!E||!v){w(null);return}c(v,E),w(null)}return t.jsxs("div",{className:"flex items-end px-0 pt-0 pb-0 bg-surface-1 border-b border-border gap-0 flex-shrink-0 overflow-hidden",children:[$&&t.jsx("button",{onClick:()=>{var E;return(E=T.current)==null?void 0:E.scrollBy({left:-300,behavior:"smooth"})},className:"w-6 h-9 flex items-center justify-center bg-accent/15 text-accent hover:bg-accent/25 transition-colors flex-shrink-0 cursor-pointer",children:t.jsx(Ei,{size:14})}),t.jsxs("div",{ref:T,className:"flex items-end flex-1 min-w-0 overflow-x-auto gap-0",style:{scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch"},children:[e.map(E=>{const q=n.filter(oe=>{var Z;return oe.teamId===E.id&&!((Z=oe.metadata)!=null&&Z.scheduled)}).length,D=E.id===s,R=v===E.id,_=n.filter(oe=>{var Z;return oe.teamId===E.id&&!((Z=oe.metadata)!=null&&Z.scheduled)&&(oe.status==="running"||oe.status==="starting")}).length;return t.jsxs(gv,{children:[t.jsx(Ov,{asChild:!0,children:t.jsxs("div",{draggable:!R,onDragStart:oe=>{k(E.id),oe.dataTransfer.effectAllowed="move",oe.dataTransfer.setData("text/plain","")},onDragEnd:()=>{k(null),B(null)},onDragOver:oe=>{oe.preventDefault(),oe.dataTransfer.dropEffect="move",C&&C!==E.id&&B(E.id)},onDragLeave:()=>{F===E.id&&B(null)},onDrop:oe=>{if(oe.preventDefault(),!C||C===E.id)return;const Z=e.findIndex(le=>le.id===C),ee=e.findIndex(le=>le.id===E.id);Z!==-1&&ee!==-1&&f(Z,ee),k(null),B(null)},onClick:()=>!R&&a(E.id),onDoubleClick:()=>K(E),className:V("relative flex items-center gap-2 px-3 h-9 text-xs font-sans cursor-pointer select-none transition-colors flex-shrink-0",D?"text-text-0 font-semibold border-x border-x-[#242830] bg-[#242830]":"text-text-3 hover:text-text-1 hover:bg-surface-3/50",C===E.id&&"opacity-40",F===E.id&&C!==E.id&&"border-l-2 !border-l-accent"),children:[D&&t.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-accent",style:{height:"0.5px"}}),(()=>{const oe=DJ(n,E.id),Z=oe==="working"||oe==="completed"?"text-green-400":oe==="crashed"?"text-red-400":D?"text-accent":"text-text-4";return t.jsxs("span",{className:"relative flex-shrink-0",children:[t.jsx(Fn,{size:13,className:V(Z,oe==="working"&&"animate-pulse")}),oe==="working"&&t.jsx("span",{className:"absolute -top-0.5 -right-0.5 w-1.5 h-1.5 rounded-full bg-green-400 animate-pulse"})]})})(),R?t.jsx("input",{value:N,onChange:oe=>Q(oe.target.value),onKeyDown:oe=>{oe.key==="Enter"&&L(),oe.key==="Escape"&&w(null)},onBlur:L,className:"h-5 w-24 px-1.5 text-xs bg-surface-0 border border-accent rounded text-text-0 font-sans focus:outline-none",autoFocus:!0,onClick:oe=>oe.stopPropagation()}):t.jsx("span",{className:"truncate max-w-[120px]",children:E.name}),q>0&&!R&&t.jsx("span",{className:V("flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full text-2xs font-mono font-semibold",_>0?"bg-accent/15 text-accent":"bg-surface-4 text-text-3"),children:q}),D&&t.jsx("div",{className:"absolute bottom-[-1px] left-0 right-0 h-px bg-[#242830]"})]})}),t.jsxs(bv,{children:[t.jsxs(ma,{onSelect:()=>K(E),children:[t.jsx(Fo,{size:12})," Rename"]}),t.jsxs(ma,{onSelect:()=>A(E.id),children:[t.jsx(za,{size:12})," Clone"]}),t.jsx(vv,{}),t.jsxs(ma,{danger:!0,onSelect:()=>{if(n.filter(Z=>Z.teamId===E.id).some(Z=>Z.status==="running"||Z.status==="starting")){m("error","Stop running agents first");return}l(E.id)},children:[t.jsx(qt,{size:12})," Delete"]})]})]},E.id)}),h?t.jsxs("div",{className:"flex items-center gap-1.5 px-3 h-9 flex-shrink-0",children:[t.jsx("input",{value:O,onChange:E=>b(E.target.value),onKeyDown:E=>{E.key==="Enter"&&ne(),E.key==="Escape"&&(g(!1),b(""))},placeholder:"Team name...",className:"h-5 w-28 px-1.5 text-xs bg-surface-0 border border-border-subtle rounded text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),t.jsx("button",{onClick:ne,disabled:!O.trim(),className:"p-1 rounded text-accent hover:bg-accent/10 cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",children:t.jsx(Je,{size:12})}),t.jsx("button",{onClick:()=>{g(!1),b("")},className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(Ze,{size:12})})]}):t.jsx("button",{onClick:()=>g(!0),className:"flex items-center justify-center w-6 h-6 my-auto mx-2 rounded-full bg-accent/15 text-accent hover:bg-accent/25 cursor-pointer transition-colors flex-shrink-0",title:"New team",children:t.jsx(At,{size:12})})]}),I&&t.jsx("button",{onClick:()=>{var E;return(E=T.current)==null?void 0:E.scrollBy({left:300,behavior:"smooth"})},className:"w-6 h-9 flex items-center justify-center bg-accent/15 text-accent hover:bg-accent/25 transition-colors flex-shrink-0 cursor-pointer",children:t.jsx(Ct,{size:14})})]})}function XJ(){const e=U(K=>K.agents),s=U(K=>K.activeTeamId),n=U(K=>K.tokenTimeline),a=U(K=>K.selectAgent),r=U(K=>K.closeDetail),l=p.useRef([]),c=p.useMemo(()=>{const K=e.filter(E=>{var q;return E.teamId===s&&!((q=E.metadata)!=null&&q.scheduled)}).sort((E,q)=>(E.name||E.id).localeCompare(q.name||q.id)),L=l.current;return L.length===K.length&&L.every((E,q)=>E.id===K[q].id&&E.status===K[q].status&&E.name===K[q].name&&E.model===K[q].model&&E.tokensUsed===K[q].tokensUsed&&E.contextUsage===K[q].contextUsage)?L:(l.current=K,K)},[e,s]),A=p.useRef(SA(s)),f=p.useRef(s);f.current!==s&&(f.current=s,A.current=SA(s));const{fitView:m,setViewport:h}=dE(),[g,O]=p.useState(0),b=p.useRef(s),v=p.useMemo(()=>{const K=A.current,L=x4(),E=c.filter(ee=>ee.status==="running").length,q=K[zs]||L[zs]||{x:0,y:0},D=[{id:zs,type:"rootNode",position:q,data:{agentCount:c.length,runningCount:E},draggable:!0,selectable:!1}],R=new Set,_=(ee,le)=>`${Math.round(ee/100)},${Math.round(le/100)}`;R.add(_(q.x,q.y));const oe=[];c.forEach(ee=>{const le=ee.name||ee.id;if(K[le]){const ae=K[le];R.add(_(ae.x,ae.y)),D.push({id:ee.id,type:"agentNode",position:ae,data:{agent:ee,timeline:n[ee.id]||[]},draggable:!0,selectable:!0})}else oe.push(ee)});const Z=new Map;return oe.forEach((ee,le)=>{const ae=ee.role||"agent",X=Z.get(ae)||0;Z.set(ae,X+1);const te=X===0?ae:`${ae}-${X}`;let he;if(L[te])he={...L[te]};else{const W=Math.floor(le/ao),Oe=le%ao;he={x:-((Math.min(oe.length-W*ao,ao)-1)*xf)/2+Oe*xf,y:mf+W*mf}}for(;R.has(_(he.x,he.y));)he={x:he.x,y:he.y+mf};R.add(_(he.x,he.y)),ee.name||ee.id,D.push({id:ee.id,type:"agentNode",position:he,data:{agent:ee,timeline:n[ee.id]||[]},draggable:!0,selectable:!0})}),D},[c,n,s]);p.useEffect(()=>{const K={};v.forEach(L=>{var q,D;const E=L.id===zs?zs:((D=(q=L.data)==null?void 0:q.agent)==null?void 0:D.name)||L.id;A.current[E]||(K[E]=L.position)}),Object.keys(K).length>0&&(Object.assign(A.current,K),xQ(s,A.current))},[v,s]);const w=p.useMemo(()=>{const K=SA(s),L=K[zs]||{x:0,y:0};return c.map((E,q)=>{const D=E.name||E.id,R=Math.floor(q/ao),_=q%ao,Z=-((Math.min(c.length-R*ao,ao)-1)*xf)/2,ee=K[D]||{x:Z+_*xf,y:140+R*mf},le=ee.x+Sg/2-L.x,ae=ee.y+Ng/2-L.y;let X,te;return Math.abs(ae)>Math.abs(le)?(X=ae>0?"bottom":"top",te=ae>0?"top":"bottom"):(X=le>0?"right":"left",te=le>0?"left":"right"),{id:`e-${zs}-${E.id}`,source:zs,target:E.id,sourceHandle:X,targetHandle:te,type:"default",animated:E.status==="running"}})},[c,s]),[N,Q,S]=uE(v),[C,k,F]=fE(w),B=p.useRef(new Set);p.useEffect(()=>{Q(K=>{const L=new Map(K.map(E=>[E.id,E]));return v.map(E=>{const q=L.get(E.id);return q?{...q,data:E.data}:E})})},[v,Q]),p.useEffect(()=>{k(()=>{const K=N.find(E=>E.id===zs);if(!K)return w;const L=K.position;return w.map(E=>{const q=N.find(Z=>Z.id===E.target);if(!q)return E;const D=q.position.x+Sg/2-L.x,R=q.position.y+Ng/2-L.y;let _,oe;return Math.abs(R)>Math.abs(D)?(_=R>0?"bottom":"top",oe=R>0?"top":"bottom"):(_=D>0?"right":"left",oe=D>0?"left":"right"),{...E,sourceHandle:_,targetHandle:oe}})})},[w,N,k]);const T=c.map(K=>K.id).join(","),$=p.useRef(null);p.useEffect(()=>{if(b.current!==s){b.current=s,B.current=new Set(c.map(q=>q.id)),O(c.length);const E=m4()[s];E?h(E,{duration:200}):c.length>0&&m({padding:.3,maxZoom:1.2,duration:200});return}const K=new Set(c.map(E=>E.id)),L=c.length>0&&[...K].some(E=>!B.current.has(E));B.current=K,g===0&&c.length>0?m({padding:.3,maxZoom:1.2,duration:0}):L&&(clearTimeout($.current),$.current=setTimeout(()=>m({padding:.3,maxZoom:1.2,duration:300}),500)),O(c.length)},[T,g,m,s,h]);const M=p.useCallback((K,L)=>{LJ(s,L)},[s]),I=p.useCallback((K,L)=>{L.id!==zs&&a(L.id)},[a]),se=p.useCallback(()=>{r()},[r]),H=p.useCallback((K,L)=>{const E=N.find(D=>D.id===zs);if(!E)return;const q=E.position;k(D=>D.map(R=>{const _=R.source===L.id,oe=R.target===L.id;if(!_&&!oe)return R;const Z=L.position,ee=Z.x+Sg/2-q.x,le=Z.y+Ng/2-q.y;let ae,X;return Math.abs(le)>Math.abs(ee)?(ae=le>0?"bottom":"top",X=le>0?"top":"bottom"):(ae=ee>0?"right":"left",X=ee>0?"left":"right"),{...R,sourceHandle:ae,targetHandle:X}}))},[N,k]),ne=p.useCallback((K,L)=>{var D,R;const E=L.id===zs?zs:((R=(D=L.data)==null?void 0:D.agent)==null?void 0:R.name)||L.id;A.current[E]=L.position;const q=SA(s);q[E]=L.position,xQ(s,q)},[s]);return t.jsx(xE,{nodes:N,edges:C,nodeTypes:_J,onNodesChange:S,onEdgesChange:F,onNodeClick:I,onPaneClick:se,onNodeDrag:H,onNodeDragStop:ne,onMoveEnd:M,defaultViewport:{x:0,y:0,zoom:1.2},proOptions:{hideAttribution:!0},minZoom:.2,maxZoom:1.5,className:"bg-surface-2",children:t.jsx(mE,{color:"rgba(97,175,239,0.03)",gap:24,size:1})})}const wv=new Set(["codex","grok","local"]),ZJ=new Set(["codex"]);function GJ({open:e,onOpenChange:s,onLaunch:n}){const a=U(B=>B.fetchProviders),[r,l]=p.useState([]),[c,A]=p.useState(""),[f,m]=p.useState(""),[h,g]=p.useState(50),[O,b]=p.useState(.5),[v,w]=p.useState(50);p.useEffect(()=>{e&&a().then(B=>{var $;if(!Array.isArray(B))return;const T=B.filter(M=>M.installed);if(l(T),!c&&T.length>0){const M=T.find(se=>se.isDefault)||T[0];A(M.id);const I=(($=M.models)==null?void 0:$.filter(se=>se.type!=="image"))||[];I.length>0&&m(I[0].id)}}).catch(()=>{})},[e]);const N=r.find(B=>B.id===c),Q=((N==null?void 0:N.models)||[]).filter(B=>B.type!=="image"&&!B.disabled),S=wv.has(c),C=ZJ.has(c);function k(B){var M;A(B);const T=r.find(I=>I.id===B),$=((T==null?void 0:T.models)||[]).filter(I=>I.type!=="image"&&!I.disabled);m(((M=$[0])==null?void 0:M.id)||"")}function F(){const B={provider:c,model:f,reasoningEffort:h,...S&&{temperature:O},...C&&{verbosity:v}};U.setState({teamLaunchConfig:B}),n(B)}return t.jsx(_t,{open:e,onOpenChange:s,children:t.jsxs(zt,{title:"Configure Planner",description:"Set provider, model, and tuning before launching the planner",children:[t.jsxs("div",{className:"px-5 py-4 space-y-4",children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Provider"}),t.jsxs(Cn,{value:c,onValueChange:k,children:[t.jsx(kn,{placeholder:"Select provider",className:"bg-surface-3"}),t.jsx(Tn,{children:r.map(B=>t.jsx(is,{value:B.id,children:B.displayName||B.name||B.id},B.id))})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Model"}),t.jsxs(Cn,{value:f,onValueChange:m,children:[t.jsx(kn,{placeholder:"Select model",className:"bg-surface-3"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"auto",children:"Auto"}),Q.map(B=>t.jsx(is,{value:B.id,children:B.name||B.id},B.id))]})]})]}),t.jsxs("div",{className:"space-y-1 pt-1",children:[t.jsx(_a,{label:"Reasoning Effort",value:h,onChange:g,min:0,max:100,step:1}),S&&t.jsx(_a,{label:"Temperature",value:O,onChange:b,min:0,max:1,step:.01,formatValue:B=>B.toFixed(2)}),C&&t.jsx(_a,{label:"Verbosity",value:v,onChange:w,min:0,max:100,step:1})]})]}),t.jsx("div",{className:"px-5 py-4 border-t border-border-subtle",children:t.jsxs(ge,{variant:"primary",size:"md",onClick:F,className:"w-full gap-2",children:[t.jsx(Wt,{size:14}),"Launch Planner"]})})]})})}const mQ={chat:Po,planner:ji,backend:Qs,frontend:rd,fullstack:un,testing:$x,devops:gb,docs:Bn,security:Pn,database:Ob,cmo:Sb,cfo:rN,ea:NN,support:xN,analyst:Ux,creative:vN,slides:wN,ambassador:aa},Bg=[{id:"planner",label:"Planner",desc:"Analyzes tasks and designs team plans"},{id:"frontend",label:"Frontend",desc:"React, UI components, views, styling"},{id:"backend",label:"Backend",desc:"APIs, server logic, database, services"},{id:"fullstack",label:"Fullstack",desc:"Cross-stack work, QC, integration testing"},{id:"testing",label:"Testing",desc:"Test suites, coverage, quality assurance"},{id:"devops",label:"DevOps",desc:"CI/CD, deployment, infrastructure"},{id:"security",label:"Security",desc:"Security audits, vulnerability analysis"},{id:"database",label:"Database",desc:"Schema design, queries, migrations"},{id:"docs",label:"Docs",desc:"Documentation, guides, API docs"},{id:"cmo",label:"CMO",desc:"Marketing strategy, campaigns, content"},{id:"cfo",label:"CFO",desc:"Financial analysis, budgeting, forecasting"},{id:"ea",label:"EA",desc:"Executive assistance, coordination, briefings"},{id:"support",label:"Support",desc:"Customer support, issue triage"},{id:"analyst",label:"Analyst",desc:"Data analysis, research, reporting"},{id:"creative",label:"Writer",desc:"Design, copywriting, visual assets"},{id:"slides",label:"Slides",desc:"Presentations, decks, pitch materials"}],VJ=[{name:"Dev Team",icon:un,roles:["frontend","backend","testing"],desc:"3 agents"},{name:"Full Stack",icon:Wl,roles:["frontend","backend","fullstack","testing","devops"],desc:"5 agents"},{name:"Marketing",icon:Sb,roles:["cmo","creative","analyst"],desc:"3 agents"},{name:"Business",icon:Ux,roles:["cfo","analyst","ea"],desc:"3 agents"},{name:"Security Audit",icon:Pn,roles:["security","testing","devops"],desc:"3 agents"},{name:"Docs",icon:Bn,roles:["docs","frontend","analyst"],desc:"3 agents"}];function KJ(){const e=U(Z=>Z.teamBuilderOpen),s=U(Z=>Z.teamBuilderRoles),n=U(Z=>Z.teamBuilderSettings),a=U(Z=>Z.teamBuilderTask),r=U(Z=>Z.teamTemplates),l=U(Z=>Z.closeTeamBuilder),c=U(Z=>Z.addTeamBuilderRole),A=U(Z=>Z.removeTeamBuilderRole),f=U(Z=>Z.updateTeamBuilderRole),m=U(Z=>Z.applyTemplate),h=U(Z=>Z.setTeamBuilderSettings),g=U(Z=>Z.setTeamBuilderTask),O=U(Z=>Z.launchTeamBuilder),b=U(Z=>Z.saveTeamTemplate),v=U(Z=>Z.fetchTeamTemplates),w=U(Z=>Z.fetchProviders),[N,Q]=p.useState([]),[S,C]=p.useState(""),[k,F]=p.useState(null),[B,T]=p.useState(!1),[$,M]=p.useState(null),[I,se]=p.useState(!1),[H,ne]=p.useState("");if(p.useEffect(()=>{e&&(w().then(Z=>{Array.isArray(Z)&&Q(Z.filter(ee=>ee.installed))}).catch(()=>{}),v())},[e]),!e)return null;const K=S?Bg.filter(Z=>Z.label.toLowerCase().includes(S.toLowerCase())||Z.desc.toLowerCase().includes(S.toLowerCase())):Bg,L=N.find(Z=>Z.id===n.provider),E=((L==null?void 0:L.models)||[]).filter(Z=>Z.type!=="image"&&!Z.disabled);function q(Z){var ae;h({provider:Z});const ee=N.find(X=>X.id===Z),le=((ee==null?void 0:ee.models)||[]).filter(X=>X.type!=="image"&&!X.disabled);h({provider:Z,model:((ae=le[0])==null?void 0:ae.id)||""})}function D(Z){m(Z),M(Z.name)}async function R(){T(!0);try{await O()}catch{}T(!1)}function _(){const Z=H.trim();Z&&(b(Z),se(!1),ne(""))}const oe=[...VJ,...(r.custom||[]).map(Z=>{var ee;return{...Z,icon:Wl,desc:`${((ee=Z.roles)==null?void 0:ee.length)||0} agents`,custom:!0}})];return t.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:[t.jsxs("div",{className:"w-full max-w-5xl max-h-[90vh] bg-surface-1 border border-border rounded-xl shadow-2xl flex flex-col overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border-subtle",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg bg-info/15 flex items-center justify-center",children:t.jsx(Fn,{size:16,className:"text-info"})}),t.jsx("h2",{className:"text-lg font-bold text-text-0 font-sans",children:"Team Builder"})]}),t.jsx("button",{onClick:l,className:"p-2 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-3 transition-colors cursor-pointer",children:t.jsx(Ze,{size:18})})]}),t.jsx("div",{className:"px-6 py-3 border-b border-border-subtle",children:t.jsxs("div",{className:"flex items-center gap-2 overflow-x-auto pb-1",style:{scrollbarWidth:"none"},children:[oe.map(Z=>{const ee=Z.icon||Wl,le=$===Z.name;return t.jsxs("button",{onClick:()=>D(Z),className:V("flex flex-col items-center gap-1.5 px-4 py-2.5 rounded-lg border text-center transition-all cursor-pointer flex-shrink-0 min-w-[100px]",le?"border-accent bg-accent/5":"border-border-subtle bg-surface-3 hover:border-accent/30 hover:bg-surface-4"),children:[t.jsx(ee,{size:16,className:le?"text-accent":"text-text-2"}),t.jsx("span",{className:"text-2xs font-semibold text-text-0 font-sans",children:Z.name}),t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:Z.desc})]},Z.name)}),t.jsx(ot,{content:"Save current roster as template",children:t.jsxs("button",{onClick:()=>{se(!0),ne("")},disabled:s.length===0,className:"flex flex-col items-center gap-1.5 px-4 py-2.5 rounded-lg border border-dashed border-border-subtle bg-surface-2 hover:border-accent/30 transition-all cursor-pointer flex-shrink-0 min-w-[100px] disabled:opacity-30 disabled:cursor-not-allowed",children:[t.jsx(Bo,{size:16,className:"text-text-3"}),t.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans",children:"Save"}),t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Template"})]})})]})}),t.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[t.jsxs("div",{className:"w-[40%] border-r border-border-subtle flex flex-col",children:[t.jsx("div",{className:"px-4 py-3 border-b border-border-subtle",children:t.jsxs("div",{className:"relative",children:[t.jsx(Ms,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),t.jsx("input",{type:"text",value:S,onChange:Z=>C(Z.target.value),placeholder:"Filter roles...",className:"w-full h-8 pl-8 pr-3 text-xs bg-surface-3 border border-border-subtle rounded-md text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent font-sans"})]})}),t.jsx(bt,{className:"flex-1",children:t.jsx("div",{className:"p-3 grid grid-cols-2 gap-2",children:K.map(Z=>{const ee=mQ[Z.id]||un;return t.jsxs("button",{onClick:()=>c(Z.id),className:"flex items-start gap-2.5 p-2.5 rounded-lg border border-border-subtle bg-surface-2 hover:border-accent/30 hover:bg-surface-3 transition-all cursor-pointer text-left group",children:[t.jsx("div",{className:"w-7 h-7 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/15 transition-colors",children:t.jsx(ee,{size:14,className:"text-text-2 group-hover:text-accent transition-colors"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:Z.label}),t.jsx(At,{size:12,className:"text-text-4 group-hover:text-accent transition-colors flex-shrink-0"})]}),t.jsx("p",{className:"text-2xs text-text-3 font-sans leading-tight mt-0.5",children:Z.desc})]})]},Z.id)})})})]}),t.jsxs("div",{className:"flex-1 flex flex-col",children:[t.jsx("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center justify-between",children:t.jsxs("span",{className:"text-xs font-semibold text-text-1 font-sans uppercase tracking-wider",children:["Your Team (",s.length,")"]})}),t.jsx(bt,{className:"flex-1",children:t.jsx("div",{className:"p-3 space-y-1.5",children:s.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[t.jsx(Fn,{size:32,className:"text-text-4 mb-3"}),t.jsx("p",{className:"text-sm text-text-2 font-sans",children:"Add roles from the left or pick a template above"})]}):s.map((Z,ee)=>{var he;const le=mQ[Z.role]||un,ae=k===ee,X=Z.provider?N.find(W=>W.id===Z.provider):null,te=((X==null?void 0:X.models)||[]).filter(W=>W.type!=="image"&&!W.disabled);return t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[t.jsx(fN,{size:12,className:"text-text-4 flex-shrink-0 cursor-grab"}),t.jsx("div",{className:"w-6 h-6 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:t.jsx(le,{size:12,className:"text-text-1"})}),t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans flex-1",children:((he=Bg.find(W=>W.id===Z.role))==null?void 0:he.label)||Z.role}),t.jsx("button",{onClick:()=>F(ae?null:ee),className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(dt,{size:12,className:V("transition-transform duration-200",ae&&"rotate-180")})}),t.jsx("button",{onClick:()=>{A(ee),k===ee?F(null):k>ee&&F(k-1)},className:"p-1 rounded text-text-4 hover:text-danger cursor-pointer",children:t.jsx(Ze,{size:12})})]}),ae&&t.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-3 border-t border-border-subtle bg-surface-1",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Name Override"}),t.jsx("input",{type:"text",value:Z.name,onChange:W=>f(ee,{name:h4(W.target.value)}),placeholder:Z.role,className:"w-full h-7 px-2.5 text-xs bg-surface-3 border border-border-subtle rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",maxLength:64,spellCheck:!1})]}),t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),t.jsxs(Cn,{value:Z.provider||"__default__",onValueChange:W=>{var be;const Oe=W==="__default__"?null:W,me=N.find(Se=>Se.id===Oe),J=((me==null?void 0:me.models)||[]).filter(Se=>Se.type!=="image"&&!Se.disabled);f(ee,{provider:Oe,model:((be=J[0])==null?void 0:be.id)||null})},children:[t.jsx(kn,{placeholder:"Team Default",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"__default__",children:"Team Default"}),N.map(W=>t.jsx(is,{value:W.id,children:W.displayName||W.name||W.id},W.id))]})]})]}),t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),t.jsxs(Cn,{value:Z.model||"__default__",onValueChange:W=>f(ee,{model:W==="__default__"?null:W}),children:[t.jsx(kn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"__default__",children:"Default"}),te.map(W=>t.jsx(is,{value:W.id,children:W.name||W.id},W.id))]})]})]})]}),t.jsx(_a,{label:"Reasoning",value:Z.reasoningEffort??n.reasoningEffort,onChange:W=>f(ee,{reasoningEffort:W}),min:0,max:100,step:1}),wv.has(Z.provider||n.provider)&&t.jsx(_a,{label:"Temperature",value:Z.temperature??n.temperature,onChange:W=>f(ee,{temperature:W}),min:0,max:1,step:.01,formatValue:W=>W.toFixed(2)})]})]},ee)})})})]})]}),t.jsx("div",{className:"border-t border-border-subtle px-6 py-4",children:t.jsxs("div",{className:"flex gap-4",children:[t.jsxs("div",{className:"flex-1 space-y-1.5",children:[t.jsx("textarea",{value:a,onChange:Z=>g(Z.target.value),placeholder:"Describe what you want to build... (optional)",rows:3,className:"w-full px-3 py-2 text-sm bg-surface-3 border border-border-subtle rounded-md text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent resize-none"}),t.jsx("p",{className:"text-2xs text-text-4 font-sans italic",children:"Leave empty to spawn agents awaiting instructions"})]}),t.jsxs("div",{className:"w-64 flex flex-col gap-2",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("div",{className:"flex-1 space-y-0.5",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),t.jsxs(Cn,{value:n.provider||"__default__",onValueChange:Z=>q(Z==="__default__"?"":Z),children:[t.jsx(kn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"__default__",children:"Default"}),N.map(Z=>t.jsx(is,{value:Z.id,children:Z.displayName||Z.name||Z.id},Z.id))]})]})]}),t.jsxs("div",{className:"flex-1 space-y-0.5",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),t.jsxs(Cn,{value:n.model||"__default__",onValueChange:Z=>h({model:Z==="__default__"?"":Z}),children:[t.jsx(kn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"__default__",children:"Auto"}),E.map(Z=>t.jsx(is,{value:Z.id,children:Z.name||Z.id},Z.id))]})]})]})]}),t.jsxs(ge,{variant:"primary",size:"md",onClick:R,disabled:B||s.length===0,className:"w-full gap-2 mt-1",children:[t.jsx(Wt,{size:14}),B?"Launching...":`Plan & Launch (${s.length})`]})]})]})})]}),I&&t.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40",children:t.jsxs("div",{className:"w-full max-w-sm bg-surface-2 border border-border rounded-lg shadow-2xl p-5 space-y-4",children:[t.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:"Save as Template"}),t.jsx("input",{type:"text",value:H,onChange:Z=>ne(Z.target.value),placeholder:"Template name...",className:"w-full h-8 px-3 text-sm bg-surface-3 border border-border-subtle rounded-md text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0,onKeyDown:Z=>{Z.key==="Enter"&&_(),Z.key==="Escape"&&se(!1)}}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>se(!1),children:"Cancel"}),t.jsx(ge,{variant:"primary",size:"sm",onClick:_,disabled:!H.trim(),children:"Save"})]})]})})]})}function qJ({onPlanner:e,onSpawn:s,onTeamBuilder:n}){var a;return t.jsx("div",{className:"w-full h-full flex items-center justify-center",children:t.jsxs("div",{className:"max-w-2xl w-full text-center space-y-10 px-8",children:[t.jsxs("div",{className:"relative mx-auto w-20 h-20",children:[t.jsx("div",{className:"absolute inset-0 rounded-full bg-accent/8 animate-pulse"}),t.jsx("div",{className:"absolute inset-1 rounded-full bg-surface-3 border border-border-subtle flex items-center justify-center shadow-lg shadow-accent/5",children:t.jsx("img",{src:"/favicon.png",alt:"Groove",className:"h-10 w-10 rounded-full"})})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsx("h1",{className:"text-3xl font-bold text-text-0 font-sans tracking-tight",children:"Welcome to Groove"}),t.jsx("p",{className:"text-base text-text-2 font-sans max-w-md mx-auto leading-relaxed",children:"Your mission control for AI agents. Spawn, orchestrate, and ship faster than ever."})]}),t.jsxs("div",{className:"space-y-3 max-w-xl mx-auto",children:[t.jsxs("button",{onClick:e,className:"w-full flex items-center gap-4 p-5 rounded-lg border border-accent/25 bg-gradient-to-r from-accent/8 to-accent/3 hover:from-accent/14 hover:to-accent/6 hover:border-accent/40 transition-all cursor-pointer group text-left",children:[t.jsx("div",{className:"w-12 h-12 rounded-lg bg-accent/20 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:t.jsx(Wt,{size:24,className:"text-accent"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-base font-semibold text-text-0 font-sans",children:"Start with a Planner"}),t.jsx("div",{className:"text-sm text-text-2 font-sans mt-0.5",children:"Describe what you want to build and let AI plan the perfect team"})]}),t.jsx("div",{className:"text-accent text-xs font-semibold font-sans flex-shrink-0 opacity-60 group-hover:opacity-100 transition-opacity",children:"Recommended"})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{onClick:n,className:"flex items-center gap-3 p-4 rounded-lg border border-info/25 bg-gradient-to-r from-info/6 to-info/2 hover:from-info/12 hover:to-info/5 hover:border-info/35 transition-all cursor-pointer group text-left",children:[t.jsx("div",{className:"w-10 h-10 rounded-lg bg-info/15 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:t.jsx(BN,{size:20,className:"text-info"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Build a Team"}),t.jsx("div",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Pick roles and configure"})]})]}),t.jsxs("button",{onClick:s,className:"flex items-center gap-3 p-4 rounded-lg border border-border bg-surface-1 hover:bg-surface-2 hover:border-border transition-all cursor-pointer group text-left",children:[t.jsx("div",{className:"w-10 h-10 rounded-lg bg-surface-4 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:t.jsx(At,{size:20,className:"text-text-1"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn Agent"}),t.jsx("div",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Choose a role and configure"})]})]})]})]}),((a=window.groove)==null?void 0:a.openFolder)&&t.jsxs("div",{className:"max-w-sm mx-auto",children:[t.jsx("p",{className:"text-xs text-text-3 mb-2",children:"Or open a different project"}),t.jsxs("button",{onClick:()=>window.groove.openFolder(),className:"w-full h-10 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 text-sm text-text-1 font-medium flex items-center justify-center gap-2 cursor-pointer transition-colors",children:[t.jsx(Vs,{size:16,className:"text-accent"}),"Open Folder"]})]}),t.jsxs("p",{className:"text-xs text-text-4 font-sans",children:[t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+K"}),t.jsx("span",{className:"mx-1.5",children:"command palette"}),t.jsx("span",{className:"text-text-4 mx-1",children:"·"}),t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+N"}),t.jsx("span",{className:"mx-1.5",children:"spawn"}),t.jsx("span",{className:"text-text-4 mx-1",children:"·"}),t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+J"}),t.jsx("span",{className:"mx-1.5",children:"terminal"})]})]})})}const WJ={backend:Qs,frontend:rd,fullstack:un,testing:$x,security:Pn},YJ=/^[a-zA-Z0-9_-]{1,64}$/;function h4(e){return e.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,64)}function JJ(){var D;const e=U(R=>R.recommendedTeam),s=U(R=>R.launchRecommendedTeam),n=U(R=>R.teamLaunchConfig),a=U(R=>R.fetchProviders),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,m]=p.useState(!1),[h,g]=p.useState([]),[O,b]=p.useState((n==null?void 0:n.provider)||""),[v,w]=p.useState((n==null?void 0:n.model)||""),[N,Q]=p.useState((n==null?void 0:n.reasoningEffort)??50),[S,C]=p.useState((n==null?void 0:n.temperature)??.5),[k,F]=p.useState(null);if(p.useEffect(()=>{a().then(R=>{Array.isArray(R)&&g(R.filter(_=>_.installed))}).catch(()=>{})},[]),!((D=e==null?void 0:e.agents)!=null&&D.length))return null;const B=e.agents,T=B.filter(R=>!R.phase||R.phase===1),$=B.filter(R=>R.phase===2),M=c??T.map(R=>({...R,name:R.name||""})),I=h.find(R=>R.id===O),se=((I==null?void 0:I.models)||[]).filter(R=>R.type!=="image"&&!R.disabled),H=wv.has(O);function ne(R,_){const oe=M.map((Z,ee)=>ee===R?{...Z,name:h4(_)}:Z);A(oe)}function K(R,_){if(typeof _=="string"){const[oe,Z]=[_,arguments[2]];A(ee=>(ee??M).map((le,ae)=>ae===R?{...le,[oe]:Z}:le))}else A(oe=>(oe??M).map((Z,ee)=>ee===R?{...Z,..._}:Z))}function L(R){var Z;b(R);const _=h.find(ee=>ee.id===R),oe=((_==null?void 0:_.models)||[]).filter(ee=>ee.type!=="image"&&!ee.disabled);w(((Z=oe[0])==null?void 0:Z.id)||"")}async function E(){l(!0),U.setState({teamLaunchConfig:{...O&&{provider:O,model:v},reasoningEffort:N,...H&&{temperature:S}}});try{const R=[...M,...$];await s(R)}catch{}l(!1)}function q(){U.setState({recommendedTeam:null})}return t.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 z-50 w-full max-w-lg",children:t.jsxs("div",{className:"mx-4 rounded-lg border border-accent/30 bg-surface-2/95 backdrop-blur-md shadow-xl shadow-accent/5 overflow-hidden",children:[t.jsxs("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center gap-2",children:[t.jsx(ji,{size:16,className:"text-accent"}),t.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Planner Recommends a Team"}),t.jsx("button",{onClick:q,className:"text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(Ze,{size:14})})]}),t.jsxs("div",{className:"border-b border-border-subtle",children:[t.jsxs("button",{onClick:()=>m(!f),className:"w-full flex items-center gap-2 px-4 py-2 text-left cursor-pointer hover:bg-surface-3/50 transition-colors",children:[t.jsx(dt,{size:12,className:V("text-text-4 transition-transform duration-200",!f&&"-rotate-90")}),t.jsx(QN,{size:12,className:"text-text-3"}),t.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider",children:"Team Settings"}),O&&t.jsxs("span",{className:"ml-auto text-2xs text-accent font-mono",children:[O,v?` / ${v}`:""]})]}),f&&t.jsxs("div",{className:"px-4 pb-3 space-y-3",children:[t.jsxs("div",{className:"flex gap-3",children:[t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),t.jsxs(Cn,{value:O,onValueChange:L,children:[t.jsx(kn,{placeholder:"Default",className:"bg-surface-4 h-7 text-xs"}),t.jsx(Tn,{children:h.map(R=>t.jsx(is,{value:R.id,children:R.displayName||R.name||R.id},R.id))})]})]}),t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),t.jsxs(Cn,{value:v,onValueChange:w,children:[t.jsx(kn,{placeholder:"Auto",className:"bg-surface-4 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"auto",children:"Auto"}),se.map(R=>t.jsx(is,{value:R.id,children:R.name||R.id},R.id))]})]})]})]}),t.jsx(_a,{label:"Reasoning",value:N,onChange:Q,min:0,max:100,step:1}),H&&t.jsx(_a,{label:"Temperature",value:S,onChange:C,min:0,max:1,step:.01,formatValue:R=>R.toFixed(2)})]})]}),t.jsxs("div",{className:"px-4 py-3 space-y-1.5",children:[M.map((R,_)=>{var X;const oe=WJ[R.role]||un,Z=!R.name||YJ.test(R.name),ee=k===_,le=h.find(te=>te.id===(R.provider||O)),ae=((le==null?void 0:le.models)||[]).filter(te=>te.type!=="image"&&!te.disabled);return t.jsxs("div",{className:"rounded-md bg-surface-4 border border-border-subtle overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 cursor-pointer hover:bg-surface-5/50 transition-colors",onClick:()=>F(ee?null:_),children:[t.jsx(oe,{size:12,className:"text-text-2 shrink-0"}),t.jsx("input",{type:"text",value:R.name,onChange:te=>ne(_,te.target.value),onClick:te=>te.stopPropagation(),placeholder:R.role,className:V("flex-1 min-w-0 bg-transparent text-xs font-mono text-text-0 outline-none placeholder:text-text-4",!Z&&"text-red-400"),maxLength:64,spellCheck:!1}),R.provider&&R.provider!==O&&t.jsx("span",{className:"text-2xs text-accent font-mono shrink-0",children:R.provider}),((X=R.scope)==null?void 0:X.length)>0&&t.jsxs("span",{className:"text-2xs text-text-4 font-mono shrink-0 truncate max-w-[120px]",children:[R.scope[0],R.scope.length>1?` +${R.scope.length-1}`:""]}),t.jsx(dt,{size:10,className:V("text-text-4 shrink-0 transition-transform duration-200",!ee&&"-rotate-90")})]}),ee&&t.jsxs("div",{className:"px-2.5 pb-2.5 pt-1 space-y-2.5 border-t border-border-subtle",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[t.jsx(ya,{size:10}),"Provider"]}),t.jsxs(Cn,{value:R.provider||"",onValueChange:te=>{var Oe;const he=h.find(me=>me.id===te),W=((he==null?void 0:he.models)||[]).filter(me=>me.type!=="image"&&!me.disabled);K(_,{provider:te,model:((Oe=W[0])==null?void 0:Oe.id)||""})},children:[t.jsx(kn,{placeholder:"Team default",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"",children:"Team default"}),h.map(te=>t.jsx(is,{value:te.id,children:te.displayName||te.name||te.id},te.id))]})]})]}),t.jsxs("div",{className:"flex-1 space-y-1",children:[t.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),t.jsxs(Cn,{value:R.model||"",onValueChange:te=>K(_,"model",te),children:[t.jsx(kn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),t.jsxs(Tn,{children:[t.jsx(is,{value:"",children:"Auto"}),ae.map(te=>t.jsx(is,{value:te.id,children:te.name||te.id},te.id))]})]})]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[t.jsx(Vl,{size:10}),"Model Routing"]}),t.jsx("div",{className:"flex bg-surface-3 rounded-md p-0.5 border border-border-subtle",children:[{value:"fixed",label:"Fixed"},{value:"auto",label:"Auto"},{value:"auto-floor",label:"Auto + Floor"}].map(te=>t.jsx("button",{onClick:()=>K(_,"routingMode",te.value),className:V("flex-1 px-2 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(R.routingMode||"auto")===te.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:te.label},te.value))})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[t.jsx(dN,{size:10}),"Effort Level"]}),t.jsx("div",{className:"flex bg-surface-3 rounded-md p-0.5 border border-border-subtle",children:[{value:"min",label:"Min"},{value:"low",label:"Low"},{value:"default",label:"Default"},{value:"high",label:"High"},{value:"max",label:"Max"}].map(te=>t.jsx("button",{onClick:()=>K(_,"effort",te.value),className:V("flex-1 px-1.5 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(R.effort||"default")===te.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:te.label},te.value))})]})]})]},_)}),e.projectDir&&t.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-2 font-mono pt-0.5",children:[t.jsx("span",{className:"text-text-4",children:"Project:"}),t.jsxs("span",{className:"text-accent",children:[e.projectDir,"/"]})]}),$.length>0&&t.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans",children:[t.jsx(Pn,{size:10}),t.jsxs("span",{children:[$.length," QC agent",$.length>1?"s":""," will auto-spawn after builders complete"]})]})]}),t.jsx("div",{className:"px-4 py-3 border-t border-border-subtle",children:t.jsxs(ge,{variant:"primary",size:"md",onClick:E,disabled:r,className:"w-full gap-2",children:[t.jsx(Wt,{size:14}),r?"Launching...":`Launch ${T.length} Agent${T.length>1?"s":""}`]})})]})})}function Cg(){var M;const e=U(I=>I.agents),s=U(I=>I.activeTeamId),n=U(I=>I.openDetail),a=U(I=>I.spawnAgent),r=U(I=>I.selectAgent);U(I=>I.recommendedTeam);const l=U(I=>I.checkRecommendedTeam),c=U(I=>I.addToast),A=U(I=>I.showPreviewInAgents),f=U(I=>I.previewState),m=U(I=>I.togglePreviewInAgents),h=U(I=>I.teamPreviews),g=U(I=>I.relaunchPreview),O=U(I=>I.openPreview),b=U(I=>I.workspaceMode),v=U(I=>I.setWorkspaceMode),w=U(I=>I.openTeamBuilder),[N,Q]=p.useState(!1);p.useEffect(()=>{if(!e.some(H=>H.role==="planner"&&(H.status==="running"||H.status==="starting")))return;const se=setInterval(()=>l(),5e3);return()=>clearInterval(se)},[e,l]);function S(){Q(!0)}async function C(I){Q(!1);try{const se=await a({role:"planner",provider:I.provider,model:I.model,reasoningEffort:I.reasoningEffort,temperature:I.temperature,verbosity:I.verbosity});se!=null&&se.id&&r(se.id)}catch{}}const k=e.filter(I=>{var se;return I.teamId===s&&!((se=I.metadata)!=null&&se.scheduled)}),F=U(I=>I.hydrated),[B,T]=p.useState(!0);p.useEffect(()=>{const I=setTimeout(()=>T(!1),1200);return()=>clearTimeout(I)},[]);const $=B||!F;return t.jsxs("div",{className:"flex flex-col h-full relative",children:[t.jsx("div",{className:"flex-1 min-h-0",children:$?t.jsxs("div",{className:V("flex flex-col items-center justify-center h-full transition-opacity duration-500",!B&&F?"opacity-0":"opacity-100"),children:[t.jsxs("div",{className:"relative w-12 h-12 mb-5",children:[t.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-accent/20 animate-ping",style:{animationDuration:"2s"}}),t.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent animate-spin",style:{animationDuration:"1s"}}),t.jsx("span",{className:"absolute inset-[6px] rounded-full bg-accent/8 flex items-center justify-center",children:t.jsx(Wt,{size:16,className:"text-accent animate-pulse"})})]}),t.jsx("p",{className:"text-sm font-medium text-text-1 font-sans animate-pulse",children:"Connecting to agents"}),t.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Syncing with daemon..."})]}):k.length===0?t.jsx(qJ,{onPlanner:S,onSpawn:()=>n({type:"spawn"}),onTeamBuilder:w}):b?t.jsx(CW,{}):A&&f.url&&f.teamId===s&&((M=h[s])!=null&&M.active)?t.jsx(cX,{embedded:!0}):t.jsx(AE,{children:t.jsx(XJ,{})},s)}),!b&&t.jsx(JJ,{}),!$&&k.length>0&&!b&&t.jsxs("div",{className:"absolute bottom-3 left-3 z-40 flex items-center gap-1.5",children:[t.jsx(ot,{content:"Spawn agent",side:"top",children:t.jsx("button",{onClick:()=>n({type:"spawn"}),className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:t.jsx(At,{size:15})})}),t.jsx(ot,{content:Object.keys(x4()).length>0?"Update layout":"Save layout",side:"top",children:t.jsx("button",{onClick:()=>{const I=SA(s),se={},H=new Map;[...k].sort((ne,K)=>(ne.name||ne.id).localeCompare(K.name||K.id)).forEach(ne=>{const K=ne.name||ne.id,L=I[K];if(!L)return;const E=ne.role||"agent",q=H.get(E)||0;H.set(E,q+1);const D=q===0?E:`${E}-${q}`;se[D]=L}),I[zs]&&(se[zs]=I[zs]),zJ(se),c("success","Layout saved","Future spawns will use these positions")},className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:t.jsx(JR,{size:15})})}),t.jsx(ot,{content:"Workspace",side:"top",children:t.jsx("button",{onClick:()=>v(!0),className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:t.jsx(un,{size:15})})}),(()=>{const I=h[s];if(!I)return null;const se=I.active&&f.url&&f.teamId===s,H=se&&A,ne=H?"Show team":se?"Show preview":"Relaunch preview";return t.jsx(ot,{content:ne,side:"top",children:t.jsx("button",{onClick:()=>{se?A?m():O(I.url,s,I.kind):g(s)},className:V("flex items-center justify-center w-8 h-8 rounded border bg-surface-2/50 transition-colors cursor-pointer",se?"border-text-3/25 text-text-3 hover:text-info hover:border-info/40 hover:bg-info/10":"border-text-4/25 text-text-4 hover:text-warning hover:border-warning/40 hover:bg-warning/10"),children:H?t.jsx(Fn,{size:15}):t.jsx(Hs,{size:15})})})})()]}),t.jsx(GJ,{open:N,onOpenChange:Q,onLaunch:C}),t.jsx(KJ,{})]})}function eee({children:e,detailContent:s,terminalContent:n}){const a=U(B=>B.activeView),r=U(B=>B.detailPanel),l=U(B=>B.connected),c=U(B=>B.tunneled),A=U(B=>B.daemonHost),f=U(B=>B.agents),m=U(B=>B.editorActiveFile),h=U(B=>B.detailPanelWidth),g=U(B=>B.terminalVisible),O=U(B=>B.terminalFullHeight),b=U(B=>B.setActiveView),v=U(B=>B.openDetail),w=U(B=>B.closeDetail),N=U(B=>B.setDetailPanelWidth),Q=U(B=>B.setTerminalVisible),S=U(B=>B.toggleCommandPalette),C=p.useMemo(()=>f.filter(B=>B.status==="running").length,[f]),k=p.useMemo(()=>[{key:"k",meta:!0,handler:()=>U.getState().toggleCommandPalette()},{key:"p",meta:!0,shift:!0,handler:()=>U.getState().toggleCommandPalette()},{key:"j",meta:!0,handler:()=>{const B=U.getState();B.setTerminalVisible(!B.terminalVisible)}},{key:"n",meta:!0,handler:()=>U.getState().openDetail({type:"spawn"})},{key:"1",meta:!0,handler:()=>U.getState().setActiveView("agents")},{key:"2",meta:!0,handler:()=>U.getState().setActiveView("editor")},{key:"3",meta:!0,handler:()=>U.getState().setActiveView("dashboard")},{key:"4",meta:!0,handler:()=>U.getState().setActiveView("marketplace")},{key:"5",meta:!0,handler:()=>U.getState().setActiveView("teams")},{key:"Escape",handler:()=>{const B=U.getState();B.commandPaletteOpen?B.toggleCommandPalette():B.detailPanel&&B.closeDetail()}}],[]);sS(k);const F=r&&r.type!=="spawn";return t.jsx(t$,{children:t.jsxs("div",{className:V("w-full h-full flex flex-col bg-surface-2 text-text-1 font-sans",JA()&&"electron-app"),children:[t.jsx(r_,{activeView:a,connected:l,tunneled:c,daemonHost:A,editorActiveFile:m,onOpenCommandPalette:S}),t.jsxs("div",{className:"flex-1 flex min-h-0",children:[t.jsx(t_,{activeView:a,detailPanel:r,onNavigate:b,onTogglePanel:B=>{(r==null?void 0:r.type)===B?w():v({type:B})}}),t.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[a==="agents"&&t.jsx(HJ,{}),t.jsxs("div",{className:"flex-1 flex min-h-0",children:[t.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[!(g&&O)&&t.jsx("main",{className:"flex-1 min-h-0 overflow-hidden relative",children:e}),n]}),F&&t.jsx(mz,{width:h,onWidthChange:N,onClose:w,children:s})]})]})]}),t.jsx(xz,{connected:l,agentCount:f.length,runningCount:C,terminalVisible:g,onToggleTerminal:()=>Q(!g)}),t.jsx(pz,{}),t.jsx(AB,{}),t.jsx(gz,{}),t.jsx(Oz,{}),t.jsx(TN,{})]})})}function tee({id:e,name:s,subtitle:n,models:a,authType:r,recommended:l,installed:c,installing:A,failed:f,selected:m,onInstall:h,gradientFrom:g,letter:O,statusChecking:b}){return t.jsxs(En.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.25},className:V("relative flex flex-col rounded-md border p-6 transition-all duration-200","bg-surface-2 hover:bg-surface-3 hover:shadow-lg hover:shadow-black/20",m?"border-accent ring-1 ring-accent/30 shadow-md shadow-accent/10":"border-border-subtle",A&&"pointer-events-none opacity-70"),children:[m&&t.jsx("div",{className:"absolute top-3 left-3 w-5 h-5 rounded-full bg-accent flex items-center justify-center",children:t.jsx(Je,{className:"w-3 h-3 text-surface-0",strokeWidth:3})}),t.jsxs("div",{className:"flex items-start gap-4 mb-5",children:[t.jsx("div",{className:V("w-14 h-14 rounded-md flex items-center justify-center text-lg font-bold font-mono shrink-0",g),children:O}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"text-sm font-semibold text-text-0",children:s}),l&&t.jsx(ke,{variant:"purple",className:"text-2xs",children:"Recommended"})]}),t.jsx("p",{className:"text-xs text-text-2 mt-0.5",children:n})]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",children:a.map(v=>t.jsx("span",{className:"text-xs text-text-2 bg-surface-4 px-2 py-0.5 rounded font-mono",children:v},v))}),t.jsx("p",{className:"text-2xs text-text-3 mb-4",children:r}),t.jsx("div",{className:"mt-auto pt-4 border-t border-border-subtle",children:A?t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ie,{className:"w-4 h-4 text-accent animate-spin"}),t.jsx("span",{className:"text-xs text-accent font-medium",children:"Installing..."})]}),t.jsx("div",{className:"h-1 bg-surface-4 rounded-full overflow-hidden",children:t.jsx(En.div,{className:"h-full bg-accent rounded-full",initial:{width:"0%"},animate:{width:"90%"},transition:{duration:15,ease:"easeOut"}})})]}):c?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Vf,{className:"w-4 h-4 text-success"}),t.jsx("span",{className:"text-xs text-success font-medium",children:"Ready"})]}):f?t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Xs,{className:"w-4 h-4 text-danger"}),t.jsx("span",{className:"text-xs text-danger font-medium",children:"Failed"})]}),t.jsxs("button",{type:"button",className:"h-8 px-5 rounded-full text-xs font-medium bg-danger/15 text-danger hover:bg-danger/25 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-danger flex items-center gap-1.5",onClick:v=>{v.stopPropagation(),h==null||h(e)},children:[t.jsx(No,{className:"w-3 h-3"}),"Retry"]})]}):b?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ie,{className:"w-3.5 h-3.5 text-text-4 animate-spin"}),t.jsx("span",{className:"text-xs text-text-4",children:"Checking..."})]}):t.jsx("div",{className:"flex items-center justify-end",children:t.jsxs("button",{type:"button",className:"h-8 px-5 rounded-full text-xs font-medium bg-accent text-surface-0 hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent flex items-center gap-1.5",onClick:v=>{v.stopPropagation(),h==null||h(e)},children:[t.jsx(Zs,{className:"w-3.5 h-3.5"}),"Install"]})})})]})}const ha=[{id:"claude-code",name:"Claude Code",subtitle:"by Anthropic",models:["Opus 4.6","Sonnet 4.6","Haiku 4.5"],authType:"Subscription or API key",authModes:["subscription","apikey"],recommended:!0,letter:"C",gradientFrom:"bg-purple/20 text-purple",keyPlaceholder:"sk-ant-...",keyLabel:"Anthropic API Key"},{id:"codex",name:"Codex",subtitle:"by OpenAI",models:["GPT-5.4 Pro","Standard","Mini","Nano"],authType:"API key or ChatGPT Plus",authModes:["apikey","chatgpt-plus"],recommended:!1,letter:"X",gradientFrom:"bg-success/20 text-success",keyPlaceholder:"sk-...",keyLabel:"OpenAI API Key"},{id:"gemini",name:"Gemini CLI",subtitle:"by Google",models:["Gemini 3.1 Pro","3 Flash"],authType:"API key",authModes:["apikey"],recommended:!1,letter:"G",gradientFrom:"bg-info/20 text-info",keyPlaceholder:"AIza...",keyLabel:"Gemini API Key"}],see={enter:e=>({x:e>0?80:-80,opacity:0}),center:{x:0,opacity:1},exit:e=>({x:e<0?80:-80,opacity:0})},nee={duration:.25,ease:[.4,0,.2,1]};function aee({current:e,total:s}){return t.jsx("div",{className:"flex items-center gap-2.5",children:Array.from({length:s},(n,a)=>t.jsx("div",{className:V("h-2 rounded-full transition-all duration-300",a===e?"w-7 bg-accent":a<e?"w-2 bg-accent/50":"w-2 bg-surface-5")},a))})}function ree({onNext:e,onSkip:s}){return t.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[t.jsx(En.img,{src:"/favicon.png",alt:"Groove",className:"w-20 h-20",initial:{scale:.5,opacity:0},animate:{scale:1,opacity:1},transition:{duration:.4,ease:"easeOut"}}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"Welcome to Groove"}),t.jsx("p",{className:"text-sm text-text-2",children:"Your AI coding team, ready in minutes"})]}),t.jsx("p",{className:"text-xs text-text-3 leading-relaxed max-w-sm",children:"Let's set up your AI providers so you can start spawning agents. This only takes a moment."}),t.jsxs("button",{type:"button",onClick:e,className:"mt-4 h-11 px-8 rounded-full bg-accent text-surface-0 font-semibold text-sm hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-0 flex items-center gap-2",autoFocus:!0,children:["Get Started",t.jsx(So,{className:"w-4 h-4"})]}),t.jsx("button",{type:"button",onClick:s,className:"text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent rounded px-2 py-1",children:"Skip setup"})]})}function oee({selectedDir:e,onSelectDir:s}){const n=U(A=>A.remoteHomedir),[a,r]=p.useState(!1),l=new URLSearchParams(window.location.search).has("instance");async function c(){var f,m;if(l){r(!0);return}const A=await n3({title:"Choose your project folder",defaultPath:e||void 0});A?s(A):(m=(f=window.groove)==null?void 0:f.folders)!=null&&m.select||r(!0)}return t.jsxs("div",{className:"flex flex-col items-center max-w-lg mx-auto w-full text-center",children:[t.jsxs("div",{className:"mb-8",children:[t.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your project folder"}),t.jsx("p",{className:"text-sm text-text-2",children:"Pick the root directory where your code lives. Groove will manage agents from here."})]}),t.jsx("div",{className:"w-full bg-surface-2 border border-border-subtle rounded-lg p-5 mb-6",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-12 h-12 rounded-lg bg-accent/10 flex items-center justify-center",children:t.jsx(Vs,{className:"w-6 h-6 text-accent"})}),t.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[t.jsx("p",{className:"text-xs text-text-3 mb-0.5",children:"Working directory"}),t.jsx("p",{className:"text-sm font-mono text-text-0 truncate",children:e||"No folder selected"})]})]})}),t.jsxs("button",{type:"button",onClick:c,className:"h-10 px-6 rounded-lg bg-accent text-surface-0 font-medium text-sm hover:bg-accent/80 transition-colors cursor-pointer flex items-center gap-2",children:[t.jsx(Vs,{className:"w-4 h-4"}),e?"Change Folder":"Select Folder"]}),t.jsx("p",{className:"mt-4 text-2xs text-text-4",children:"You can change this anytime in Settings."}),a&&t.jsx(Ac,{open:a,onOpenChange:r,currentPath:e||n||"/",homePath:n,onSelect:A=>{s(A),r(!1)}})]})}function iee({providerStatus:e,selected:s,onInstall:n,installing:a,statusChecking:r}){const l=ha.filter(A=>{var f;return(f=e[A.id])==null?void 0:f.installed}).length,c=l===ha.length;return t.jsxs("div",{className:"flex flex-col items-center max-w-4xl mx-auto w-full",children:[t.jsxs("div",{className:"text-center mb-10",children:[t.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your AI providers"}),t.jsx("p",{className:"text-sm text-text-2",children:"Install the coding tools you want to use. You can always add more later."})]}),t.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 w-full mb-8",children:ha.map(A=>{var f,m;return t.jsx(tee,{...A,installed:(f=e[A.id])==null?void 0:f.installed,installing:a[A.id],failed:(m=e[A.id])==null?void 0:m.failed,selected:s.includes(A.id),onInstall:n,statusChecking:r},A.id)})}),t.jsx("p",{className:V("text-xs text-center",c?"text-success":l>0?"text-text-2":"text-text-4"),children:c?"All providers installed — you're ready to go!":l>0?`${l} of ${ha.length} providers installed`:"Click Install to set up a provider"})]})}function lee({provider:e,providerStatus:s,onSaveKey:n}){const[a,r]=p.useState(e.authModes.includes("subscription")?"subscription":"apikey"),[l,c]=p.useState(""),[A,f]=p.useState(!1),[m,h]=p.useState(!1),[g,O]=p.useState((s==null?void 0:s.authenticated)||!1),b=async()=>{if(l.trim()){h(!0);try{await n(e.id,l.trim()),O(!0)}catch{}finally{h(!1)}}},v=(s==null?void 0:s.maskedKey)||(g&&l?`${l.slice(0,6)}${"•".repeat(20)}`:null);return t.jsxs(En.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.2},className:"bg-surface-2 border border-border-subtle rounded-md p-5",children:[t.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[t.jsx("div",{className:V("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono",e.gradientFrom),children:e.letter}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-sm font-semibold text-text-0",children:e.name}),t.jsx("p",{className:"text-2xs text-text-3",children:e.subtitle})]}),(g||(s==null?void 0:s.authenticated))&&t.jsx(ke,{variant:"success",className:"ml-auto",children:"Connected"})]}),e.authModes.length>1&&t.jsx("div",{className:"flex gap-1 mb-4 bg-surface-3 p-0.5 rounded-md",children:e.authModes.map(w=>t.jsx("button",{type:"button",onClick:()=>r(w),className:V("flex-1 h-7 rounded text-xs font-medium transition-colors duration-100 cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",a===w?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:w==="subscription"?"Subscription":w==="chatgpt-plus"?"ChatGPT Plus":"API Key"},w))}),a==="subscription"&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"text-xs text-text-2",children:"Sign in via the terminal with your Claude subscription."}),t.jsx("div",{className:"space-y-1.5",children:t.jsxs("p",{className:"text-2xs text-text-2 font-sans",children:["Open a terminal and run: ",t.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"claude"})," — then follow the prompts to sign in."]})}),(s==null?void 0:s.authenticated)&&t.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[t.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="chatgpt-plus"&&t.jsxs("div",{className:"space-y-3",children:[t.jsxs("p",{className:"text-xs text-text-2",children:["Run ",t.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"codex login"})," in your terminal to authenticate with ChatGPT Plus."]}),(s==null?void 0:s.authenticated)&&t.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[t.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="apikey"&&t.jsx("div",{className:"space-y-3",children:g||s!=null&&s.authenticated?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"flex-1 h-8 rounded-md bg-surface-1 border border-border px-3 flex items-center",children:t.jsx("span",{className:"text-xs text-text-3 font-mono truncate",children:v||"••••••••••••••"})}),t.jsx("button",{type:"button",onClick:()=>{O(!1),c("")},className:"h-8 px-3 rounded-md text-xs text-text-3 hover:text-text-1 bg-surface-4 hover:bg-surface-5 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:"Change"})]}):t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("div",{className:"relative flex-1",children:[t.jsx("input",{type:A?"text":"password",value:l,onChange:w=>c(w.target.value),placeholder:e.keyPlaceholder,className:"h-8 w-full rounded-md px-3 pr-8 text-sm bg-surface-1 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent transition-colors duration-100 font-mono",onKeyDown:w=>w.key==="Enter"&&b(),"aria-label":e.keyLabel}),t.jsx("button",{type:"button",onClick:()=>f(!A),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer","aria-label":A?"Hide key":"Show key",children:A?t.jsx(Oo,{className:"w-3.5 h-3.5"}):t.jsx(Hs,{className:"w-3.5 h-3.5"})})]}),t.jsx("button",{type:"button",onClick:b,disabled:!l.trim()||m,className:"h-8 px-4 rounded-md bg-accent text-surface-0 text-xs font-medium hover:bg-accent/80 transition-colors duration-100 cursor-pointer disabled:opacity-40 disabled:pointer-events-none focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:m?"Saving...":"Save"})]})})]})}function cee({providerStatus:e,installedIds:s,onSaveKey:n}){const a=ha.filter(r=>{var l;return s.includes(r.id)||((l=e[r.id])==null?void 0:l.installed)});return a.some(r=>{var l;return(l=e[r.id])==null?void 0:l.authenticated}),t.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Connect your accounts"}),t.jsx("p",{className:"text-sm text-text-2",children:"Add credentials for your installed providers."})]}),t.jsx("div",{className:"flex flex-col gap-4 w-full mb-6",children:a.map(r=>t.jsx(lee,{provider:r,providerStatus:e[r.id]||{},onSaveKey:n},r.id))}),a.length===0&&t.jsx("p",{className:"text-sm text-text-3 text-center",children:"No providers installed yet. Go back to install one."})]})}function Aee({providerStatus:e,installedIds:s,defaultProvider:n,defaultModel:a,onSetDefault:r}){var c;const l=ha.filter(A=>{var f,m;return(s.includes(A.id)||((f=e[A.id])==null?void 0:f.installed))&&((m=e[A.id])==null?void 0:m.authenticated)});return t.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Set your default"}),t.jsx("p",{className:"text-sm text-text-2",children:"Choose which provider and model to use by default. You can switch per-agent anytime."})]}),t.jsxs("div",{className:"flex flex-col gap-3 w-full max-w-md mb-6",children:[l.map(A=>t.jsxs("button",{type:"button",onClick:()=>r(A.id,A.models[0]),className:V("flex items-center gap-4 p-4 rounded-md border transition-all duration-200 text-left cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",n===A.id?"bg-accent/8 border-accent ring-1 ring-accent/30":"bg-surface-2 border-border-subtle hover:bg-surface-3"),children:[t.jsx("div",{className:V("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono shrink-0",A.gradientFrom),children:A.letter}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h3",{className:"text-sm font-semibold text-text-0",children:A.name}),t.jsx("p",{className:"text-2xs text-text-3",children:A.subtitle})]}),t.jsx("div",{className:V("w-5 h-5 rounded-full border-2 flex items-center justify-center transition-colors",n===A.id?"border-accent bg-accent":"border-border"),children:n===A.id&&t.jsx("div",{className:"w-2 h-2 rounded-full bg-surface-0"})})]},A.id)),l.length===0&&t.jsx("p",{className:"text-sm text-text-3 text-center",children:"No authenticated providers. Go back to connect one."})]}),n&&t.jsxs("div",{className:"w-full max-w-md",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 mb-2 block",children:"Model"}),t.jsx("div",{className:"flex flex-wrap gap-2",children:(c=ha.find(A=>A.id===n))==null?void 0:c.models.map(A=>t.jsx("button",{type:"button",onClick:()=>r(n,A),className:V("h-7 px-3 rounded-full text-xs font-medium transition-colors duration-100 cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",a===A?"bg-accent text-surface-0":"bg-surface-4 text-text-2 hover:bg-surface-5 hover:text-text-0"),children:A},A))})]})]})}function dee({providerStatus:e,defaultProvider:s,defaultModel:n,onFinish:a}){var c;const r=ha.filter(A=>{var f;return(f=e[A.id])==null?void 0:f.installed}).length,l=(c=ha.find(A=>A.id===s))==null?void 0:c.name;return t.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[t.jsx(En.div,{initial:{scale:0},animate:{scale:1},transition:{type:"spring",stiffness:300,damping:20},className:"w-20 h-20 rounded-full bg-success/15 flex items-center justify-center",children:t.jsx(Je,{className:"w-10 h-10 text-success",strokeWidth:2.5})}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"You're all set!"}),t.jsxs("p",{className:"text-sm text-text-2",children:[r," provider",r!==1?"s":""," installed",l?`, default: ${l}`:"",n?` (${n})`:""]})]}),t.jsx(En.div,{className:"flex gap-3 mt-4",initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.3},children:t.jsxs("button",{type:"button",onClick:a,className:"h-11 px-8 rounded-full bg-accent text-surface-0 font-semibold text-sm hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-0 flex items-center gap-2",autoFocus:!0,children:[t.jsx(fn,{className:"w-4 h-4"}),"Start Building"]})})]})}const fA=6;function uee(){const e=U(D=>D.dismissOnboarding),s=U(D=>D.installProvider),n=U(D=>D.setDefaultProvider),a=U(D=>D.addToast),[r,l]=p.useState(0),[c,A]=p.useState(1),[f,m]=p.useState(["claude-code"]),[h,g]=p.useState({}),[O,b]=p.useState({}),[v,w]=p.useState(null),[N,Q]=p.useState(null),[S,C]=p.useState(!0),[k,F]=p.useState(null),B=p.useRef(null);p.useEffect(()=>{let D=!1;async function R(){var oe;try{const Z=await fetch("/api/onboarding/status").then(ee=>ee.ok?ee.json():null);if(Z!=null&&Z.providers){const ee={},le=[];for(const ae of Z.providers){const X=ae.authStatus==="authenticated"||ae.authStatus==="key-set";ee[ae.id]={installed:ae.installed,authenticated:X},ae.installed&&le.push(ae.id)}return{status:ee,installedIds:le,workingDir:((oe=Z.config)==null?void 0:oe.defaultWorkingDir)||null}}}catch{}try{const Z=await fetch("/api/providers").then(ee=>ee.ok?ee.json():null);if(Z){const ee={},le=[],ae=Array.isArray(Z)?Z:Z.providers||[];for(const X of ae){const te=X.installed||X.authStatus==="authenticated"||X.authStatus==="key-set"||!1;ee[X.id]={installed:te,authenticated:X.authenticated||!1},te&&le.push(X.id)}return{status:ee,installedIds:le}}}catch{}return null}async function _(){C(!0);let oe=await R();if(!D&&oe&&oe.installedIds.length===0)for(let Z=0;Z<2;Z++){if(await new Promise(ee=>setTimeout(ee,2e3)),D)return;if(oe=await R(),oe&&oe.installedIds.length>0)break}!D&&oe&&(b(oe.status),oe.installedIds.length>0&&m(Z=>[...new Set([...Z,...oe.installedIds])]),oe.workingDir&&!k&&F(oe.workingDir)),D||C(!1)}return _(),()=>{D=!0}},[r]);const T=p.useCallback(()=>{r<fA-1&&(A(1),l(D=>D+1))},[r]),$=p.useCallback(()=>{r>0&&(A(-1),l(D=>D-1))},[r]),M=p.useCallback(()=>{e()},[e]),I=p.useCallback(async()=>{if(k)try{await F(k)}catch{a("error","Failed to set project directory")}e()},[e,k,a]),se=p.useCallback(async D=>{g(R=>({...R,[D]:!0}));try{await s(D),b(R=>({...R,[D]:{...R[D],installed:!0}})),m(R=>R.includes(D)?R:[...R,D])}catch{b(R=>({...R,[D]:{...R[D],failed:!0}}))}finally{g(R=>({...R,[D]:!1}))}},[s]),H=p.useCallback(async(D,R)=>{try{if(!(await fetch(`/api/credentials/${encodeURIComponent(D)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:R})})).ok)throw new Error("Failed to save key");b(oe=>({...oe,[D]:{...oe[D],authenticated:!0,maskedKey:`${R.slice(0,6)}${"•".repeat(20)}`}})),a("success","API key saved")}catch(_){throw a("error","Failed to save key",_.message),_}},[a]),ne=p.useCallback(async(D,R)=>{w(D),Q(R);try{await n(D,R)}catch{}},[n]),K=ha.some(D=>{var R;return(R=O[D.id])==null?void 0:R.installed}),L=ha.some(D=>{var R;return(R=O[D.id])==null?void 0:R.authenticated}),E=r===0||r===1?!0:r===2?K:r===3?L:r===4?!!v:!1;p.useEffect(()=>{const D=R=>{R.key==="Enter"&&r<fA-1&&E&&T(),R.key==="Escape"&&M()};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[r,E,T,M]);const q=[t.jsx(ree,{onNext:T,onSkip:M},"welcome"),t.jsx(oee,{selectedDir:k,onSelectDir:F},"folder"),t.jsx(iee,{providerStatus:O,selected:f,onInstall:se,installing:h,statusChecking:S},"install"),t.jsx(cee,{providerStatus:O,installedIds:f,onSaveKey:H},"auth"),t.jsx(Aee,{providerStatus:O,installedIds:f,defaultProvider:v,defaultModel:N,onSetDefault:ne},"default"),t.jsx(dee,{providerStatus:O,defaultProvider:v,defaultModel:N,onFinish:I},"done")];return t.jsxs("div",{ref:B,className:"fixed inset-0 z-50 bg-gradient-to-b from-surface-0 to-surface-1 flex flex-col font-sans overflow-hidden",children:[JA()&&t.jsx("div",{className:"h-8 w-full electron-drag shrink-0"}),t.jsxs("div",{className:"flex items-center justify-between px-8 py-4 shrink-0",children:[t.jsx(aee,{current:r,total:fA}),r>0&&r<fA-1&&t.jsx("button",{type:"button",onClick:M,className:"text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent rounded px-2 py-1",children:"Skip setup"})]}),t.jsx("div",{className:"flex-1 flex items-center justify-center px-8 py-4 overflow-y-auto",children:t.jsx(Ci,{mode:"wait",custom:c,children:t.jsx(En.div,{custom:c,variants:see,initial:"enter",animate:"center",exit:"exit",transition:nee,className:"w-full",children:q[r]},r)})}),r>0&&r<fA-1&&t.jsxs("div",{className:"flex items-center justify-between px-8 py-8 shrink-0",children:[t.jsxs("button",{type:"button",onClick:$,className:"h-10 px-6 rounded-md text-sm text-text-2 hover:text-text-0 bg-surface-3 hover:bg-surface-4 transition-colors duration-100 cursor-pointer flex items-center gap-1.5 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[t.jsx(Ei,{className:"w-4 h-4"}),"Back"]}),t.jsxs("button",{type:"button",onClick:T,disabled:!E,className:"h-10 px-8 rounded-md text-sm font-medium bg-accent text-surface-0 hover:bg-accent/80 transition-colors duration-100 cursor-pointer disabled:opacity-40 disabled:pointer-events-none flex items-center gap-1.5 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[r===4?"Finish Setup":"Continue",t.jsx(Ct,{className:"w-4 h-4"})]})]})]})}const fee=[{icon:Qs,label:"Federation",desc:"Multi-machine daemon pairing"},{icon:gb,label:"Cloud Teams",desc:"Coming soon"}];function hQ(){var w;const e=U(N=>N.upgradeModalOpen),s=U(N=>N.setUpgradeModalOpen),n=U(N=>N.marketplaceAuthenticated),a=U(N=>N.marketplaceLogin),r=U(N=>N.startCheckout),l=U(N=>N.addToast),[c,A]=p.useState(null),[f,m]=p.useState("monthly"),[h,g]=p.useState(!1);p.useEffect(()=>{e&&!c&&U.getState().fetchSubscriptionPlans().then(N=>A(N)).catch(()=>{})},[e,c]);const O=(w=c==null?void 0:c.pro)==null?void 0:w[f],b=f==="annual"?`$${Math.round(((O==null?void 0:O.price)||96)/12)}/mo`:`$${(O==null?void 0:O.price)||10}/mo`;async function v(){var N;if(!n){a();return}if(!(O!=null&&O.priceId)){zg("https://groovedev.ai/pro"),s(!1);return}g(!0);try{await r(O.priceId),s(!1)}catch(Q){Q.status===401||(N=Q.message)!=null&&N.includes("Not authenticated")?(l("info","Please sign in first"),a()):Q.status===409&&(l("info","You already have a subscription"),s(!1))}finally{g(!1)}}return t.jsx(_t,{open:e,onOpenChange:s,children:t.jsx(zt,{title:"Upgrade to Pro",className:"max-w-[440px]",children:t.jsxs("div",{className:"px-6 py-5",children:[t.jsxs("div",{className:"text-center mb-6",children:[t.jsx("div",{className:"mx-auto mb-3 w-12 h-12 rounded-full bg-accent/10 flex items-center justify-center",children:t.jsx(fn,{size:22,className:"text-accent"})}),t.jsx("h2",{className:"text-lg font-bold text-text-0",children:"Upgrade to Groove Pro"}),t.jsx("p",{className:"text-sm text-text-2 mt-1",children:"Unlock powerful features for your AI workflow"})]}),t.jsx("div",{className:"space-y-3 mb-6",children:fee.map(N=>t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:t.jsx(N.icon,{size:15,className:"text-accent"})}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-medium text-text-0",children:N.label}),t.jsx("p",{className:"text-2xs text-text-3",children:N.desc})]}),t.jsx(Je,{size:14,className:"text-success ml-auto flex-shrink-0"})]},N.label))}),t.jsxs("div",{className:"flex gap-1 mb-5 bg-surface-3 p-0.5 rounded-md",children:[t.jsx("button",{type:"button",onClick:()=>m("monthly"),className:V("flex-1 h-8 rounded text-xs font-medium transition-colors cursor-pointer",f==="monthly"?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:"Monthly"}),t.jsxs("button",{type:"button",onClick:()=>m("annual"),className:V("flex-1 h-8 rounded text-xs font-medium transition-colors cursor-pointer",f==="annual"?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:["Annual",t.jsx("span",{className:"ml-1 text-success text-2xs",children:"Save 20%"})]})]}),t.jsxs("div",{className:"text-center mb-5",children:[t.jsx("span",{className:"text-3xl font-bold text-text-0",children:b}),f==="annual"&&t.jsxs("p",{className:"text-2xs text-text-3 mt-1",children:["Billed $",(O==null?void 0:O.price)||96,"/year"]})]}),t.jsx("button",{type:"button",onClick:v,disabled:h,className:"w-full h-10 rounded-lg bg-accent text-white font-semibold text-sm hover:bg-accent/90 transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none flex items-center justify-center gap-2",children:h?"Processing...":n?t.jsxs(t.Fragment,{children:[t.jsx(fn,{size:15})," Subscribe — ",b]}):t.jsxs(t.Fragment,{children:[t.jsx(pN,{size:15})," Sign in to subscribe"]})}),t.jsx("button",{type:"button",onClick:()=>s(!1),className:"w-full mt-2 text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer py-1",children:"Maybe later"})]})})})}function xee(){const e=U(l=>l.dataSharingModalOpen),s=U(l=>l.setTrainingOptIn),n=U(l=>l.dismissDataSharingModal),[a,r]=p.useState(!1);return t.jsx(_t,{open:e,children:t.jsxs(zt,{className:"max-w-md",description:"Help improve Groove by sharing usage data",onInteractOutside:l=>l.preventDefault(),onEscapeKeyDown:l=>l.preventDefault(),children:[t.jsxs("div",{className:"relative bg-gradient-to-br from-accent/5 to-transparent px-6 pt-8 pb-6 text-center",children:[t.jsx("div",{className:"flex justify-center mb-3",children:t.jsx("div",{className:"w-14 h-14 rounded-xl bg-accent/10 flex items-center justify-center",children:t.jsx(fn,{size:32,className:"text-accent"})})}),t.jsx(Lx,{className:"text-xl font-bold text-text-0 font-sans",children:"Help Build a Better Groove"}),t.jsx("p",{className:"text-sm text-text-2 font-sans mt-2 max-w-md mx-auto",children:"We collect errors and usage reports to improve the quality of Groove for everyone."})]}),t.jsx("div",{className:"px-6 pt-4",children:t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2/30 p-4",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[t.jsx(Pn,{size:14,className:"text-text-2"}),t.jsx("span",{className:"text-xs font-semibold uppercase text-text-3 tracking-wider font-sans",children:"What We Never Collect"})]}),t.jsx("div",{className:"space-y-1.5",children:["Your source code or file contents","API keys, passwords, or credentials","Personal information — emails, names, file paths","Anything that could identify you, your IP or projects"].map(l=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ze,{size:12,className:"text-danger flex-shrink-0"}),t.jsx("span",{className:"text-xs text-text-1 font-sans",children:l})]},l))}),t.jsx("p",{className:"text-xs text-text-0 font-sans font-medium mt-3",children:"PII is automatically scrubbed before any data leaves your machine."})]})}),t.jsxs("div",{className:"border-t border-border-subtle mt-5 pt-4 pb-1 px-6",children:[t.jsxs("button",{type:"button",onClick:()=>s(!0),className:"w-full h-10 rounded-lg bg-accent text-white font-semibold text-sm hover:bg-accent/90 transition-colors cursor-pointer flex items-center justify-center gap-2",children:[t.jsx(fn,{size:15}),"Turn On Sharing"]}),t.jsx("div",{className:"text-center mt-2.5",children:t.jsx("button",{type:"button",onClick:()=>n(a),className:"text-xs text-text-3 hover:text-text-1 transition-colors font-sans cursor-pointer",children:"Maybe Later"})}),t.jsxs("div",{className:"flex items-center justify-center gap-2 mt-3",children:[t.jsx("input",{type:"checkbox",id:"data-sharing-dismiss",checked:a,onChange:l=>r(l.target.checked),className:"w-3.5 h-3.5 rounded border-border accent-accent cursor-pointer"}),t.jsx("label",{htmlFor:"data-sharing-dismiss",className:"text-2xs text-text-3 font-sans cursor-pointer select-none",children:"Don't show this again"})]}),t.jsx("p",{className:"text-center text-2xs text-text-4 font-sans mt-2 mb-1",children:"You can always enable this later in Settings"})]})]})})}function mee(){const e=U(k=>k.recentProjects),s=U(k=>k.setProjectDir),n=U(k=>k.removeRecentProject),a=U(k=>k.remoteHomedir),r=U(k=>k.savedTunnels),l=U(k=>k.fetchTunnels),c=U(k=>k.deleteTunnel),A=U(k=>k.connectTunnel),f=U(k=>k.disconnectTunnel),m=U(k=>k.toggleQuickConnect),h=U(k=>k.addToast),[g,O]=p.useState(!1),[b,v]=p.useState(null);p.useEffect(()=>{l()},[l]);const w=(e||[]).slice(0,8),N=w.length>0,Q=r.length>0,S=N||Q;async function C(k){var F,B;if(k.active){(B=(F=window.groove)==null?void 0:F.remote)!=null&&B.openWindow?window.groove.remote.openWindow(k.localPort,k.name):window.open(`http://localhost:${k.localPort}?instance=${encodeURIComponent(k.name)}`,"_blank");return}v(k.id);try{await A(k.id)}catch(T){h("error","Connection failed",(T==null?void 0:T.message)||"Unknown error")}v(null)}return t.jsxs("div",{className:"fixed inset-0 z-50 overflow-y-auto welcome-bg",children:[t.jsx("div",{className:"pointer-events-none fixed top-0 left-1/2 -translate-x-1/2 w-[800px] h-[600px] rounded-full bg-accent/[0.03] blur-[120px]"}),t.jsxs("div",{className:"relative min-h-screen flex flex-col items-center px-8 pt-[14vh] pb-12 max-sm:pt-[8vh] max-sm:px-5",children:[t.jsxs("div",{className:"flex flex-col items-center text-center mb-14",children:[t.jsxs("div",{className:"relative mb-8",children:[t.jsx("div",{className:"absolute -inset-10 rounded-full bg-accent/[0.06] blur-3xl animate-welcome-breathe"}),t.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/25 animate-welcome-ring"}),t.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/15 animate-welcome-ring-delayed"}),t.jsx("div",{className:"relative w-[88px] h-[88px] rounded-full bg-accent/[0.07] border border-accent/20 flex items-center justify-center welcome-logo-shadow",children:t.jsx("img",{src:"/favicon.png",className:"w-12 h-12 rounded-full",alt:"Groove"})})]}),t.jsx("h1",{className:"text-4xl font-bold text-text-0 tracking-tight mb-3 font-sans max-sm:text-3xl",children:"Welcome to Groove"}),t.jsxs("p",{className:"text-base text-text-2 font-sans max-w-md leading-relaxed max-sm:text-sm",children:["The most powerful agenticOS ever built.",t.jsx("br",{className:"max-sm:hidden"}),t.jsx("span",{className:"max-sm:hidden",children:" "}),"Spawn fast. Stay aware. Never lose context."]})]}),t.jsxs("div",{className:"w-full max-w-2xl grid grid-cols-2 gap-4 mb-14 max-sm:grid-cols-1 max-sm:max-w-sm",children:[t.jsxs("button",{onClick:()=>O(!0),className:"group relative overflow-hidden rounded-xl border border-accent/20 bg-gradient-to-br from-accent/[0.08] via-accent/[0.03] to-transparent p-6 text-left hover:border-accent/40 hover:from-accent/[0.14] hover:via-accent/[0.06] transition-all duration-300 cursor-pointer",children:[t.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/15 border border-accent/20 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300",children:t.jsx(Vs,{size:24,className:"text-accent"})}),t.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Open Project"}),t.jsx("div",{className:"text-sm text-text-2 font-sans",children:"Browse the filesystem to pick a project"}),t.jsxs("div",{className:"flex items-center gap-1 text-xs text-accent font-sans mt-4 opacity-0 group-hover:opacity-100 transition-opacity duration-300",children:["Browse files ",t.jsx(So,{size:12})]})]}),t.jsxs("button",{onClick:m,className:"group relative overflow-hidden rounded-xl border border-border bg-surface-1 p-6 text-left hover:border-accent/30 hover:bg-surface-2 transition-all duration-300 cursor-pointer",children:[t.jsx("div",{className:"w-12 h-12 rounded-xl bg-surface-4 border border-border-subtle flex items-center justify-center mb-4 group-hover:scale-110 group-hover:bg-accent/10 group-hover:border-accent/20 transition-all duration-300",children:t.jsx(wi,{size:24,className:"text-text-2 group-hover:text-accent transition-colors duration-300"})}),t.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Connect to Remote"}),t.jsx("div",{className:"text-sm text-text-2 font-sans",children:"SSH tunnel to a server running Groove"}),t.jsxs("div",{className:"flex items-center gap-1 text-xs text-accent font-sans mt-4 opacity-0 group-hover:opacity-100 transition-opacity duration-300",children:["Setup connection ",t.jsx(So,{size:12})]})]})]}),S&&t.jsxs("div",{className:V("w-full max-w-4xl gap-6 mb-14 max-sm:flex max-sm:flex-col max-sm:gap-6",N&&Q?"grid grid-cols-2":"flex justify-center"),children:[N&&t.jsxs("div",{className:V(!Q&&"w-full max-w-lg"),children:[t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsx(va,{size:13,className:"text-text-3"}),t.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Recent Projects"})]}),t.jsx("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:w.map(k=>t.jsxs("div",{className:"group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg bg-surface-3 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/10 transition-colors",children:t.jsx(Vs,{size:14,className:"text-text-3 group-hover:text-accent transition-colors"})}),t.jsxs("button",{onClick:()=>s(k.path),className:"flex-1 min-w-0 text-left cursor-pointer",children:[t.jsx("div",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:k.name}),t.jsx("div",{className:"text-2xs font-mono text-text-4 truncate",children:k.path})]}),t.jsx("button",{onClick:F=>{F.stopPropagation(),n(k.path)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all flex-shrink-0",title:"Remove from recent",children:t.jsx(Ze,{size:14})})]},k.path))})]}),Q&&t.jsxs("div",{className:V(!N&&"w-full max-w-lg"),children:[t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsx(Qs,{size:13,className:"text-text-3"}),t.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"SSH Connections"})]}),t.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:[r.map(k=>t.jsxs("div",{className:V("group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",b===k.id&&"opacity-60 pointer-events-none"),children:[t.jsx("div",{className:V("w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0 transition-colors",k.active?"bg-success/10":"bg-surface-3 group-hover:bg-accent/10"),children:t.jsx(Qs,{size:14,className:V("transition-colors",k.active?"text-success":"text-text-3 group-hover:text-accent")})}),t.jsxs("button",{onClick:()=>C(k),disabled:b===k.id,className:"flex-1 min-w-0 text-left cursor-pointer",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:k.name}),k.active&&t.jsx(ss,{status:"running",size:"sm"})]}),t.jsxs("div",{className:"text-2xs font-mono text-text-4 truncate",children:[k.user,"@",k.host]})]}),t.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[b===k.id?t.jsx(Ie,{size:14,className:"text-text-3 animate-spin"}):k.active?t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>C(k),className:"opacity-0 group-hover:opacity-100 flex items-center gap-0.5 text-2xs text-success hover:text-success/80 cursor-pointer transition-all font-sans",children:[t.jsx(Gs,{size:11})," Open"]}),t.jsx("button",{onClick:async()=>{await f(k.id),h("info","Disconnected",k.name)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all",title:"Disconnect",children:t.jsx(Rx,{size:12})})]}):null,t.jsx("button",{onClick:F=>{F.stopPropagation(),c(k.id)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all flex-shrink-0",title:"Remove connection",children:t.jsx(Ze,{size:14})})]})]},k.id)),t.jsxs("button",{onClick:m,className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer transition-colors w-full px-4 py-2.5 hover:bg-surface-2/30",children:[t.jsx(At,{size:11})," Add Connection"]})]})]})]}),t.jsx("div",{className:"mt-auto pt-8 flex flex-col items-center gap-4",children:t.jsxs("div",{className:"flex items-center gap-5 text-xs text-text-4 font-sans",children:[t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘K"}),t.jsx("span",{children:"palette"})]}),t.jsx("span",{className:"text-border",children:"·"}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘N"}),t.jsx("span",{children:"spawn"})]}),t.jsx("span",{className:"text-border",children:"·"}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘J"}),t.jsx("span",{children:"terminal"})]})]})})]}),t.jsx(Ac,{open:g,onOpenChange:O,currentPath:a||"/home",homePath:a,onSelect:k=>{O(!1),s(k)}}),t.jsx(AB,{}),t.jsx(TN,{})]})}const hee={js:"text-text-2",jsx:"text-text-2",ts:"text-text-2",tsx:"text-text-2",css:"text-text-3",html:"text-text-3",json:"text-text-3",md:"text-text-3",py:"text-text-2",rs:"text-text-3",go:"text-text-2",sh:"text-text-3",yaml:"text-text-3",yml:"text-text-3",sql:"text-text-3",xml:"text-text-3",svg:"text-text-3"};function pee(e){var n;const s=(n=e.split(".").pop())==null?void 0:n.toLowerCase();return hee[s]||"text-text-3"}function gee({x:e,y:s,items:n,onClose:a}){const r=p.useRef(null);return p.useEffect(()=>{function l(c){r.current&&!r.current.contains(c.target)&&a()}return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[a]),t.jsx("div",{ref:r,className:"fixed z-50 min-w-[160px] py-1 bg-surface-2 border border-border rounded-lg shadow-xl",style:{left:e,top:s},children:n.map((l,c)=>l.separator?t.jsx("div",{className:"h-px bg-border-subtle my-1"},c):t.jsxs("button",{onClick:()=>{l.action(),a()},className:V("w-full flex items-center gap-2.5 px-3 py-1.5 text-xs font-sans text-left cursor-pointer transition-colors",l.danger?"text-danger hover:bg-danger/10":"text-text-1 hover:bg-surface-5"),children:[l.icon&&t.jsx(l.icon,{size:12,className:l.danger?"text-danger":"text-text-3"}),l.label]},c))})}function bx({defaultValue:e="",placeholder:s,onSubmit:n,onCancel:a,depth:r=0}){const[l,c]=p.useState(e),A=p.useRef(null);p.useEffect(()=>{var m,h;(m=A.current)==null||m.focus(),e&&((h=A.current)==null||h.select())},[e]);function f(m){if(m.key==="Enter"){const h=l.trim();h&&n(h)}m.key==="Escape"&&a()}return t.jsx("div",{className:"flex items-center py-0.5",style:{paddingLeft:r*16+8},children:t.jsx("input",{ref:A,value:l,onChange:m=>c(m.target.value),onKeyDown:f,onBlur:a,placeholder:s,className:"w-full h-5 px-1.5 text-xs bg-surface-0 border border-accent rounded text-text-0 font-sans focus:outline-none"})})}function Oee({status:e}){if(!e)return null;const s=e==="A"||e==="?"?"bg-success":e==="D"?"bg-danger":"bg-warning";return t.jsx("span",{className:V("w-1.5 h-1.5 rounded-full flex-shrink-0",s)})}function bee(e,s){const n=document.createElement("a");n.href=`/api/files/download?path=${encodeURIComponent(e)}`,n.download=s?`${e.split("/").pop()}.zip`:e.split("/").pop(),document.body.appendChild(n),n.click(),n.remove()}function p4({entry:e,depth:s=0,activePath:n,onFileClick:a,onDirToggle:r,expanded:l,onContextMenu:c,dragState:A,onDragStartEntry:f,onDragEndEntry:m,onSetDragOver:h,onDropOnDir:g,gitStatusMap:O}){const b=e.type==="dir",v=n===e.path,w=l.has(e.path),N=s*16+8,Q=(A==null?void 0:A.draggingPath)===e.path,S=b&&(A==null?void 0:A.dragOverPath)===e.path,C=b?null:O==null?void 0:O[e.path];function k(F){F.preventDefault(),F.stopPropagation(),c(F,e)}return t.jsxs("button",{draggable:!0,onDragStart:F=>{F.dataTransfer.setData("application/json",JSON.stringify({path:e.path,name:e.name,type:e.type})),F.dataTransfer.effectAllowed="move",f(e.path)},onDragEnd:m,onDragOver:F=>{F.preventDefault(),b&&(F.stopPropagation(),h(e.path))},onDrop:F=>g(b?e.path:e.path.includes("/")?e.path.split("/").slice(0,-1).join("/"):"",F),onClick:()=>b?r(e.path):a(e.path),onDoubleClick:k,onContextMenu:k,className:V("w-full flex items-center gap-1.5 py-[3px] text-xs font-sans cursor-pointer","hover:bg-surface-5 transition-colors text-left select-none",v&&"bg-accent/10 text-text-0",!v&&"text-text-1",Q&&"opacity-50",S&&"bg-accent/15 ring-1 ring-accent/50 rounded"),style:{paddingLeft:N},children:[b?t.jsxs(t.Fragment,{children:[w?t.jsx(dt,{size:12,className:"text-text-4 flex-shrink-0"}):t.jsx(Ct,{size:12,className:"text-text-4 flex-shrink-0"}),w?t.jsx(Vs,{size:14,className:"text-accent flex-shrink-0"}):t.jsx(Pi,{size:14,className:"text-text-3 flex-shrink-0"})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-3"}),t.jsx(Eo,{size:14,className:V("flex-shrink-0",pee(e.name))})]}),t.jsx("span",{className:"truncate flex-1",children:e.name}),C&&t.jsx(Oee,{status:C})]})}function g4({dirPath:e,depth:s,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:m,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:w}){const N=c[e]||[];return p.useEffect(()=>{r.has(e)&&!c[e]&&A(e)},[r,e,c,A]),r.has(e)?t.jsxs(t.Fragment,{children:[(m==null?void 0:m.parentPath)===e&&t.jsx(bx,{placeholder:m.type==="file"?"filename.ext":"folder-name",onSubmit:m.onSubmit,onCancel:m.onCancel,depth:s}),N.map(Q=>t.jsxs("div",{children:[(m==null?void 0:m.renamePath)===Q.path?t.jsx(bx,{defaultValue:Q.name,onSubmit:m.onSubmit,onCancel:m.onCancel,depth:s}):t.jsx(p4,{entry:Q,depth:s,activePath:n,onFileClick:a,onDirToggle:l,expanded:r,onContextMenu:f,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:w}),Q.type==="dir"&&t.jsx(g4,{dirPath:Q.path,depth:s+1,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:m,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:w})]},Q.path))]}):null}function vee({rootDir:e,onCollapse:s}){const n=U(_=>_.editorTreeCache),a=U(_=>_.editorActiveFile),r=U(_=>_.openFile),l=U(_=>_.fetchTreeDir),c=U(_=>_.addToast),[A,f]=p.useState(new Set([""])),[m,h]=p.useState(""),[g,O]=p.useState(null),[b,v]=p.useState(null),[w,N]=p.useState({draggingPath:null,dragOverPath:null}),[Q,S]=p.useState([]);p.useEffect(()=>{l("")},[l,e]),p.useEffect(()=>{G.get("/files/git-status").then(_=>{S(_.entries||[])}).catch(()=>S([]))},[e]);const C={};for(const _ of Q)C[_.path]=_.status;function k(_){f(oe=>{const Z=new Set(oe);return Z.has(_)?Z.delete(_):Z.add(_),Z})}function F(){f(new Set([""]))}function B(_){N({draggingPath:_,dragOverPath:null})}function T(){N({draggingPath:null,dragOverPath:null})}function $(_){N(oe=>oe.dragOverPath===_?oe:{...oe,dragOverPath:_})}async function M(_,oe){var ae,X;if(oe.preventDefault(),oe.stopPropagation(),N({draggingPath:null,dragOverPath:null}),((X=(ae=oe.dataTransfer)==null?void 0:ae.files)==null?void 0:X.length)>0){q(_,Array.from(oe.dataTransfer.files));return}let Z;try{Z=JSON.parse(oe.dataTransfer.getData("application/json"))}catch{return}if(!(Z!=null&&Z.path))return;if(Z.type==="dir"&&(_===Z.path||_.startsWith(Z.path+"/"))){c("error","Cannot move a folder into itself");return}const ee=H(Z.path);if(ee===_)return;const le=_?`${_}/${Z.name}`:Z.name;try{await G.post("/files/rename",{oldPath:Z.path,newPath:le}),l(ee),l(_),c("success",`Moved ${Z.name} to ${_||"/"}`)}catch(te){c("error","Move failed",te.message)}}function I(_,oe){O({x:_.clientX,y:_.clientY,entry:oe})}function se(_){_.preventDefault(),O({x:_.clientX,y:_.clientY,entry:{type:"dir",path:"",name:"root"}})}function H(_){const oe=_.split("/");return oe.pop(),oe.join("/")}async function ne(_){f(oe=>new Set([...oe,_])),v({type:"file",parentPath:_,onSubmit:async oe=>{const Z=_?`${_}/${oe}`:oe;try{await G.post("/files/create",{path:Z,content:""}),l(_),r(Z),c("success",`Created ${oe}`)}catch(ee){c("error","Create failed",ee.message)}v(null)},onCancel:()=>v(null)})}async function K(_){f(oe=>new Set([...oe,_])),v({type:"folder",parentPath:_,onSubmit:async oe=>{const Z=_?`${_}/${oe}`:oe;try{await G.post("/files/mkdir",{path:Z}),l(_),f(ee=>new Set([...ee,Z])),c("success",`Created ${oe}/`)}catch(ee){c("error","Create folder failed",ee.message)}v(null)},onCancel:()=>v(null)})}async function L(_){v({type:"rename",renamePath:_.path,onSubmit:async oe=>{const Z=H(_.path),ee=Z?`${Z}/${oe}`:oe;try{await G.post("/files/rename",{oldPath:_.path,newPath:ee}),l(Z),c("success",`Renamed to ${oe}`)}catch(le){c("error","Rename failed",le.message)}v(null)},onCancel:()=>v(null)})}async function E(_){const oe=_.type==="dir"?`folder "${_.name}" and all contents`:`"${_.name}"`;if(window.confirm(`Delete ${oe}?`))try{await G.delete(`/files/delete?path=${encodeURIComponent(_.path)}`),l(H(_.path)),c("success",`Deleted ${_.name}`)}catch(Z){c("error","Delete failed",Z.message)}}async function q(_,oe){const Z=[];for(const ee of oe){const le=await new Promise((ae,X)=>{const te=new FileReader;te.onload=()=>ae(te.result.split(",")[1]),te.onerror=X,te.readAsDataURL(ee)});Z.push({name:ee.name,content:le})}try{const ee=await G.post("/files/upload",{dir:_,files:Z});c("success",`Uploaded ${ee.total} file${ee.total!==1?"s":""}`),l(_)}catch(ee){c("error","Upload failed",ee.message)}}function D(_){const oe=_.type==="dir",Z=[];return oe&&(Z.push({icon:Ml,label:"New File",action:()=>ne(_.path)}),Z.push({icon:BA,label:"New Folder",action:()=>K(_.path)})),_.name!=="root"?(Z.push({icon:Zs,label:oe?"Download as ZIP":"Download",action:()=>bee(_.path,oe)}),Z.length>0&&Z.push({separator:!0}),Z.push({icon:Fo,label:"Rename",action:()=>L(_)}),Z.push({icon:qt,label:"Delete",danger:!0,action:()=>E(_)})):(Z.length=0,Z.push({icon:Ml,label:"New File",action:()=>ne("")}),Z.push({icon:BA,label:"New Folder",action:()=>K("")})),Z}const R=n[""]||[];return t.jsxs("div",{className:"flex flex-col h-full bg-surface-1",onContextMenu:se,children:[t.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border-subtle",children:[t.jsxs("div",{className:"flex-1 relative",children:[t.jsx(Ms,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-4"}),t.jsx("input",{value:m,onChange:_=>h(_.target.value),placeholder:"Filter...",className:"w-full h-6 pl-6 pr-2 text-xs bg-surface-0 border border-border-subtle rounded text-text-1 placeholder:text-text-4 focus:outline-none focus:border-accent font-sans"})]}),t.jsx("button",{onClick:()=>ne(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New file",children:t.jsx(Ml,{size:12})}),t.jsx("button",{onClick:()=>K(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New folder",children:t.jsx(BA,{size:12})}),t.jsx("button",{onClick:()=>l(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Refresh",children:t.jsx(Ks,{size:12})}),t.jsx("button",{onClick:F,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse all",children:t.jsx(lN,{size:12})}),s&&t.jsx("button",{onClick:s,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse sidebar",children:t.jsx(Px,{size:12})})]}),t.jsx(bt,{className:"flex-1",children:t.jsxs("div",{className:"py-1 min-h-full",onDragOver:_=>{_.preventDefault(),w.draggingPath&&$(null)},onDrop:_=>M("",_),children:[(b==null?void 0:b.parentPath)===""&&t.jsx(bx,{placeholder:b.type==="file"?"filename.ext":"folder-name",onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}),R.filter(_=>!m||_.name.toLowerCase().includes(m.toLowerCase())).map(_=>t.jsxs("div",{children:[(b==null?void 0:b.renamePath)===_.path?t.jsx(bx,{defaultValue:_.name,onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}):t.jsx(p4,{entry:_,depth:0,activePath:a,onFileClick:r,onDirToggle:k,expanded:A,onContextMenu:I,dragState:w,onDragStartEntry:B,onDragEndEntry:T,onSetDragOver:$,onDropOnDir:M,gitStatusMap:C}),_.type==="dir"&&t.jsx(g4,{dirPath:_.path,depth:1,activePath:a,onFileClick:r,expanded:A,onDirToggle:k,treeCache:n,fetchTreeDir:l,onContextMenu:I,inlineInput:b,dragState:w,onDragStartEntry:B,onDragEndEntry:T,onSetDragOver:$,onDropOnDir:M,gitStatusMap:C})]},_.path)),R.length===0&&!m&&t.jsxs("div",{className:"px-3 py-6 text-center",children:[t.jsx("p",{className:"text-xs text-text-4",children:"No files found"}),t.jsx("button",{onClick:()=>l(""),className:"mt-2 text-xs text-accent hover:underline cursor-pointer",children:"Retry"})]})]})}),g&&t.jsx(gee,{x:g.x,y:g.y,items:D(g.entry),onClose:()=>O(null)})]})}function yee(){const e=U(w=>w.editorOpenTabs),s=U(w=>w.editorActiveFile),n=U(w=>w.editorFiles),a=U(w=>w.setActiveFile),r=U(w=>w.closeFile),l=p.useRef(null),[c,A]=p.useState(!1),f=p.useCallback(()=>{const w=l.current;w&&A(w.scrollWidth>w.clientWidth)},[]);p.useEffect(()=>{f();const w=l.current;if(!w)return;const N=new ResizeObserver(f);return N.observe(w),()=>N.disconnect()},[f,e.length]);function m(){var w;(w=l.current)==null||w.scrollBy({left:-120,behavior:"smooth"})}function h(){var w;(w=l.current)==null||w.scrollBy({left:120,behavior:"smooth"})}function g(w){e.filter(N=>N!==w).forEach(N=>r(N))}function O(){[...e].forEach(w=>r(w))}function b(w){const N=e.indexOf(w);e.slice(N+1).forEach(Q=>r(Q))}function v(w){var N;(N=navigator.clipboard)==null||N.writeText(w)}return e.length===0?null:t.jsxs("div",{className:"flex items-stretch h-9 bg-surface-3 border-b border-border-subtle flex-shrink-0",children:[c&&t.jsx("button",{onClick:m,className:"flex-shrink-0 px-1 h-full text-text-4 hover:text-text-1 hover:bg-surface-4 transition-colors cursor-pointer",children:t.jsx(Ei,{size:14})}),t.jsx("div",{ref:l,className:"flex items-stretch flex-1 min-w-0 overflow-x-auto scrollbar-none scroll-smooth",style:{scrollSnapType:"x mandatory"},children:e.map(w=>{const N=w===s,Q=n[w],S=Q&&Q.content!==Q.originalContent,C=w.split("/").pop();return t.jsxs(gv,{children:[t.jsx(Ov,{asChild:!0,children:t.jsxs("div",{className:V("flex items-center gap-1.5 px-3 text-xs font-sans cursor-pointer select-none","border-r border-white/5","transition-colors duration-75 flex-shrink-0",N?"bg-surface-0 text-text-0 border-b border-b-accent":"bg-surface-3 text-text-4 hover:text-text-1 hover:bg-surface-4 border-b border-b-transparent"),style:{scrollSnapAlign:"start"},onClick:()=>a(w),onAuxClick:k=>{k.button===1&&(k.preventDefault(),r(w))},children:[t.jsx("span",{className:"truncate max-w-[120px]",children:C}),S&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-warning flex-shrink-0"}),t.jsx("button",{onClick:k=>{k.stopPropagation(),r(w)},className:"p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 transition-colors cursor-pointer ml-0.5",children:t.jsx(Ze,{size:12})})]})}),t.jsxs(bv,{children:[t.jsxs(ma,{onSelect:()=>r(w),children:[t.jsx(Ze,{size:12,className:"text-text-3"})," Close"]}),t.jsxs(ma,{onSelect:()=>g(w),children:[t.jsx(Kg,{size:12,className:"text-text-3"})," Close Others"]}),t.jsxs(ma,{onSelect:()=>O(),children:[t.jsx(Kg,{size:12,className:"text-text-3"})," Close All"]}),t.jsxs(ma,{onSelect:()=>b(w),children:[t.jsx(Ct,{size:12,className:"text-text-3"})," Close to the Right"]}),t.jsx(vv,{}),t.jsxs(ma,{onSelect:()=>v(w),children:[t.jsx(za,{size:12,className:"text-text-3"})," Copy Path"]})]})]},w)})}),c&&t.jsx("button",{onClick:h,className:"flex-shrink-0 px-1 h-full text-text-4 hover:text-text-1 hover:bg-surface-4 transition-colors cursor-pointer",children:t.jsx(Ct,{size:14})})]})}const wee={javascript:"JavaScript",typescript:"TypeScript",css:"CSS",html:"HTML",json:"JSON",markdown:"Markdown",python:"Python"},O4=Object.keys(wo),b4=O4.filter(e=>!["githubLight","vscodeLight","eclipse","xcodeLight","solarizedLight","gruvboxLight","materialLight","duotoneLight","quietlight","bbedit","tokyoNightDay","basicLight"].includes(e)),jee=O4.filter(e=>!b4.includes(e));function Qee({cursorPos:e,language:s}){var A;const n=U(f=>f.editorTheme),a=U(f=>f.setEditorTheme),[r,l]=p.useState(!1),c=p.useRef(null);return p.useEffect(()=>{if(!r)return;function f(m){c.current&&!c.current.contains(m.target)&&l(!1)}return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[r]),t.jsxs("div",{className:"flex items-center justify-between h-6 px-3 bg-surface-1 border-t border-border-subtle text-2xs font-sans text-text-3 flex-shrink-0 select-none",children:[t.jsx("div",{className:"flex items-center gap-3",children:t.jsxs("span",{children:["Ln ",e.line,", Col ",e.col]})}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"relative",ref:c,children:[t.jsxs("button",{onClick:()=>l(!r),className:"flex items-center gap-1.5 hover:text-text-0 transition-colors cursor-pointer",children:[t.jsx(SM,{size:10}),t.jsx("span",{children:((A=wo[n])==null?void 0:A.label)||n})]}),r&&t.jsxs("div",{className:"absolute bottom-6 right-0 w-48 max-h-72 overflow-y-auto rounded-md border border-border bg-surface-2 shadow-xl z-50 py-1 scrollbar-thin",children:[t.jsx("div",{className:"px-2 py-1 text-2xs text-text-4 font-semibold uppercase tracking-wider",children:"Dark"}),b4.map(f=>t.jsx("button",{onClick:()=>{a(f),l(!1)},className:V("w-full text-left px-3 py-1 text-2xs font-sans cursor-pointer transition-colors",f===n?"text-accent bg-accent/10":"text-text-1 hover:bg-surface-4"),children:wo[f].label},f)),t.jsx("div",{className:"px-2 py-1 mt-1 text-2xs text-text-4 font-semibold uppercase tracking-wider border-t border-border-subtle",children:"Light"}),jee.map(f=>t.jsx("button",{onClick:()=>{a(f),l(!1)},className:V("w-full text-left px-3 py-1 text-2xs font-sans cursor-pointer transition-colors",f===n?"text-accent bg-accent/10":"text-text-1 hover:bg-surface-4"),children:wo[f].label},f))]})]}),t.jsx("span",{className:"cursor-default",children:wee[s]||s||"Plain Text"}),t.jsx("span",{children:"Spaces: 2"}),t.jsx("span",{children:"UTF-8"})]})]})}function See({currentLine:e,onGoto:s,onClose:n}){const[a,r]=p.useState(""),l=p.useRef(null);p.useEffect(()=>{var A;(A=l.current)==null||A.focus()},[]);function c(A){if(A.key==="Enter"){const f=parseInt(a,10);f>0&&s(f),n()}A.key==="Escape"&&n()}return t.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20 flex items-center gap-2 bg-surface-2 border border-border rounded-lg shadow-xl p-2",children:[t.jsx("label",{className:"text-2xs font-sans text-text-3 whitespace-nowrap",children:"Go to Line:"}),t.jsx("input",{ref:l,value:a,onChange:A=>r(A.target.value),onKeyDown:c,onBlur:n,placeholder:String(e),className:"w-20 h-6 px-2 text-xs bg-surface-0 border border-border-subtle rounded text-text-0 font-mono focus:outline-none focus:border-accent"})]})}function Nee({path:e}){if(!e)return null;const s=e.split("/").filter(Boolean);return t.jsx("div",{className:"flex items-center h-7 px-3 bg-surface-2 border-b border-border-subtle text-2xs font-sans text-text-3 overflow-hidden flex-shrink-0 select-none",children:s.map((n,a)=>{const r=a===s.length-1;return t.jsxs("span",{className:"flex items-center min-w-0",children:[a>0&&t.jsx(Ct,{size:10,className:"mx-0.5 flex-shrink-0 text-text-4"}),t.jsx("span",{className:r?"text-text-1 font-medium truncate":"hover:text-text-1 cursor-pointer truncate transition-colors",children:n})]},a)})})}function Bee(e){var n;const s=(n=e==null?void 0:e.split(".").pop())==null?void 0:n.toLowerCase();return s==="html"||s==="htm"}const Cee=240,kee=160,Tee=400;function Uee(){const e=U(H=>H.editorActiveFile),s=U(H=>H.editorFiles),n=U(H=>H.updateFileContent),a=U(H=>H.saveFile),r=U(H=>H.editorSidebarWidth),l=U(H=>H.setEditorSidebarWidth),c=U(H=>H.projectDir),[A,f]=p.useState(""),[m,h]=p.useState(!1),[g,O]=p.useState(0),[b,v]=p.useState({line:1,col:1}),[w,N]=p.useState(!1),[Q,S]=p.useState(!1),C=p.useRef(null),k=p.useRef(!1),F=p.useRef(0),B=p.useRef(0);p.useEffect(()=>{G.get("/files/root").then(H=>f(H.root||"")).catch(()=>{})},[c]),p.useEffect(()=>{h(!1)},[e]),p.useEffect(()=>{function H(ne){(ne.metaKey||ne.ctrlKey)&&ne.key==="g"&&(ne.preventDefault(),N(!0))}return document.addEventListener("keydown",H),()=>document.removeEventListener("keydown",H)},[]);const T=p.useCallback(H=>{H.preventDefault(),k.current=!0,F.current=H.clientX,B.current=r;function ne(L){if(!k.current)return;const E=L.clientX-F.current,q=Math.min(Math.max(B.current+E,kee),Tee);l(q)}function K(){k.current=!1,document.removeEventListener("mousemove",ne),document.removeEventListener("mouseup",K)}document.addEventListener("mousemove",ne),document.addEventListener("mouseup",K)},[r,l]);function $(H){const ne=C.current;if(!ne)return;const K=ne.state.doc.line(Math.min(H,ne.state.doc.lines));ne.dispatch({selection:{anchor:K.from},scrollIntoView:!0}),ne.focus()}const M=e?s[e]:null,I=e&&s5(e),se=e&&Bee(e);return t.jsxs("div",{className:"flex h-full",children:[t.jsxs("div",{className:V("relative flex-shrink-0 border-r border-border transition-all duration-200 overflow-hidden",Q&&"w-0 border-r-0"),style:Q?void 0:{width:r},children:[t.jsx(vee,{rootDir:A,onCollapse:()=>S(!0)}),t.jsx("div",{className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:T,onDoubleClick:()=>l(Cee)})]}),Q&&t.jsx("button",{onClick:()=>S(!1),className:"flex-shrink-0 w-6 flex items-start justify-center pt-2 border-r border-border bg-surface-2 text-text-4 hover:text-text-0 hover:bg-surface-3 transition-colors cursor-pointer",title:"Show sidebar",children:t.jsx(Fx,{size:14})}),t.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-surface-1",children:[t.jsx(yee,{}),e&&!I&&t.jsx(Nee,{path:e}),t.jsxs("div",{className:"flex-1 relative min-h-0",children:[w&&t.jsx(See,{currentLine:b.line,onGoto:$,onClose:()=>N(!1)}),!e&&t.jsx("div",{className:"w-full h-full flex items-center justify-center text-text-4 font-sans",children:t.jsxs("div",{className:"text-center space-y-2",children:[t.jsx(un,{size:32,className:"mx-auto"}),t.jsx("p",{className:"text-sm",children:"Open a file from the tree"})]})}),e&&I&&t.jsx(n5,{path:e}),e&&!I&&se&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"absolute top-0 right-4 z-10 flex items-center gap-0.5 mt-2 bg-surface-2 border border-border-subtle rounded-md p-0.5",children:[t.jsxs("button",{onClick:()=>h(!1),className:V("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",m?"text-text-3 hover:text-text-1":"bg-surface-4 text-text-0 font-medium"),children:[t.jsx(vb,{size:12})," Code"]}),t.jsxs("button",{onClick:()=>{h(!0),O(H=>H+1)},className:V("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",m?"bg-surface-4 text-text-0 font-medium":"text-text-3 hover:text-text-1"),children:[t.jsx(Hs,{size:12})," Preview"]})]}),m?t.jsx("iframe",{src:`/api/files/raw?path=${encodeURIComponent(e)}`,className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin",title:"HTML Preview"},g):M&&t.jsx(PO,{content:M.content,language:M.language,onChange:H=>n(e,H),onSave:()=>a(e),onCursorChange:v,viewRef:C})]}),e&&!I&&!se&&M&&t.jsx(PO,{content:M.content,language:M.language,onChange:H=>n(e,H),onSave:()=>a(e),onCursorChange:v,viewRef:C})]}),e&&!I&&t.jsx(Qee,{cursorPos:b,language:M==null?void 0:M.language})]})]})}function Eee(){var C;const e=U(k=>k.connected),s=U(k=>k.agents),[n,a]=p.useState(null),[r,l]=p.useState([]),[c,A]=p.useState({constraints:[],discoveries:[],roles:[],specializations:null}),[f,m]=p.useState(!0),[h,g]=p.useState({tokens:[],cost:[],saved:[],efficiency:[],cache:[],inputOutput:[],agents:[],turns:[]}),O=p.useRef(0);p.useEffect(()=>{if(!e)return;let k=!0;async function F(){try{const[T,$,M,I,se,H]=await Promise.all([G.get("/dashboard"),G.get("/tokens/by-team").catch(()=>({teams:[]})),G.get("/memory/constraints").catch(()=>({constraints:[]})),G.get("/memory/discoveries?limit=20").catch(()=>({discoveries:[]})),G.get("/memory/handoff-chain").catch(()=>({roles:[]})),G.get("/memory/specializations").catch(()=>({perAgent:{},perProjectRole:{}}))]);if(!k)return;a(T),l(($==null?void 0:$.teams)||[]),A({constraints:(M==null?void 0:M.constraints)||[],discoveries:(I==null?void 0:I.discoveries)||[],roles:(se==null?void 0:se.roles)||[],specializations:H||{perAgent:{},perProjectRole:{}}}),m(!1),O.current=Date.now(),g(ne=>{var Z,ee,le,ae,X,te,he,W,Oe;const K=Date.now(),L=(me,J)=>[...me.slice(-59),{t:K,v:J||0}],E=((Z=T.tokens)==null?void 0:Z.totalTokens)||0,q=((ee=T.tokens)==null?void 0:ee.totalInputTokens)||0,D=((le=T.tokens)==null?void 0:le.totalOutputTokens)||0,_=(((ae=T.agents)==null?void 0:ae.breakdown)||[]).filter(me=>{var J;return((J=me.quality)==null?void 0:J.score)!=null}),oe=_.length>0?_.reduce((me,J)=>me+J.quality.score,0)/_.length:0;return{tokens:L(ne.tokens,E),cost:L(ne.cost,(X=T.tokens)==null?void 0:X.totalCostUsd),saved:L(ne.saved,oe),efficiency:L(ne.efficiency,((te=T.rotation)==null?void 0:te.totalRotations)||0),cache:L(ne.cache,(he=T.tokens)==null?void 0:he.cacheHitRate),inputOutput:L(ne.inputOutput,D>0?q/D:0),agents:L(ne.agents,((W=T.agents)==null?void 0:W.running)||0),turns:L(ne.turns,(Oe=T.tokens)==null?void 0:Oe.totalTurns)}})}catch{k&&m(!1)}}F();const B=setInterval(F,4e3);return()=>{k=!1,clearInterval(B)}},[e]);const b=((C=n==null?void 0:n.agents)==null?void 0:C.breakdown)||[],v=(n==null?void 0:n.routing)||null,w=(n==null?void 0:n.rotation)||null,N=(n==null?void 0:n.adaptive)||[],Q=(n==null?void 0:n.journalist)||null,S=(w==null?void 0:w.rotating)||[];return{data:n,loading:f,agents:s,connected:e,kpiHistory:h,lastFetch:O.current,agentBreakdown:b,routing:v,rotation:w,adaptive:N,journalist:Q,rotating:S,teamBurn:r,memory:c}}const pQ=p.memo(function({connected:s,runningCount:n,totalCount:a,uptime:r,lastFetch:l,activeTeam:c}){return t.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 bg-surface-1 border-b border-border",children:[t.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Command Center"}),c&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-text-4",children:"/"}),t.jsx("span",{className:"text-xs font-mono text-text-2",children:c.name})]}),t.jsx("div",{className:"flex-1"}),s&&t.jsxs("div",{className:"flex items-center gap-3.5 text-xs font-mono text-text-2",children:[t.jsxs("span",{children:[t.jsx("span",{className:"text-text-1",children:n}),t.jsxs("span",{className:"text-text-3",children:["/",a]}),t.jsx("span",{className:"ml-1 text-text-3",children:"agents"})]}),r>0&&t.jsxs("span",{className:"text-text-3",children:["Up ",Ro(r)]}),l>0&&t.jsxs("span",{className:"flex items-center gap-1 text-text-4",children:[t.jsx(Ks,{size:9}),t.jsx("span",{children:ls(l)})]})]}),t.jsx(ss,{status:s?"running":"crashed",size:"sm"})]})});function qe(e,s){const n=parseInt(e.slice(1,3),16),a=parseInt(e.slice(3,5),16),r=parseInt(e.slice(5,7),16);return`rgba(${n},${a},${r},${s})`}const ce={surface0:"#1a1e25",surface3:"#282c34",surface4:"#2c313a",surface5:"#333842",text0:"#e6e6e6",text1:"#bcc2cd",text2:"#8b929e",text3:"#6e7681",text4:"#505862",accent:"#33afbc",success:"#4ae168",warning:"#e5c07b",danger:"#e06c75",info:"#61afef",purple:"#c678dd",orange:"#d19a66"};function Pee({data:e,color:s=ce.text3,width:n=72,height:a=22}){if(!e||e.length<2)return t.jsx("div",{style:{width:n,height:a}});const r=e.map(h=>h.v),l=Math.min(...r),A=Math.max(...r)-l||1,f=e.map((h,g)=>{const O=g/(e.length-1)*n,b=a-(h.v-l)/A*(a-2)-1;return`${O},${b}`}).join(" "),m=`kpi-${s.replace("#","")}`;return t.jsxs("svg",{width:n,height:a,className:"flex-shrink-0",children:[t.jsx("defs",{children:t.jsxs("linearGradient",{id:m,x1:"0",y1:"0",x2:"0",y2:"1",children:[t.jsx("stop",{offset:"0%",stopColor:s,stopOpacity:"0.2"}),t.jsx("stop",{offset:"100%",stopColor:s,stopOpacity:"0"})]})}),t.jsx("polygon",{points:`0,${a} ${f} ${n},${a}`,fill:`url(#${m})`}),t.jsx("polyline",{points:f,fill:"none",stroke:s,strokeWidth:"1.5",strokeLinejoin:"round",strokeOpacity:"0.8"})]})}const Fee=p.memo(function({label:s,value:n,sparkData:a,color:r=ce.text3,hint:l,className:c}){return t.jsxs("div",{className:V("flex items-center gap-2.5 px-3 py-2.5 min-w-0","bg-surface-1",c),children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5 truncate flex items-center gap-1",children:[s,l&&t.jsx(ot,{content:t.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:l}),side:"bottom",children:t.jsx(vi,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors"})})]}),t.jsx("div",{className:"text-base font-semibold font-mono text-text-0 tabular-nums leading-none",children:n})]}),t.jsx(Pee,{data:a,color:r})]})});function $ee({kpis:e}){return t.jsx("div",{className:"flex flex-wrap border-b border-border bg-surface-0",children:e.map(s=>t.jsx(Fee,{label:s.label,value:s.value,sparkData:s.sparkData,color:s.color,hint:s.hint,className:V("flex-1 basis-[12.5%] min-w-[140px]","border-b border-r border-border")},s.label))})}const Ree={actual:"ACT",estimated:"EST",local:"LOC"};function Mee(e){if(!e||e==="auto"||e==="default")return"default";const s=e.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:e.startsWith("gemini-")?e.replace("gemini-","Gem ").replace("-preview",""):e.length>12?e.slice(0,12)+"...":e}const Iee=p.memo(function({agent:s,isRotating:n}){const a=s.status==="running"||s.status==="starting",r=Math.round((s.contextUsage||0)*100),l=n?ce.accent:Ub(s.status),c=s.quality,A=(c==null?void 0:c.toolSuccessRate)!=null?Math.round(c.toolSuccessRate*100):null,f=s.rotationThreshold?Math.round(s.rotationThreshold*100):null,m=$a(s.role),h=ce.text1;return t.jsxs("div",{className:"px-3 pl-6 py-2 hover:bg-surface-4 transition-colors space-y-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[t.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:l}}),a&&t.jsx("span",{className:"absolute inset-[-2px] rounded-sm",style:{background:l,opacity:.15,animation:"node-pulse-bar 2s ease-in-out infinite"}})]}),t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate leading-none flex-shrink-0 max-w-[80px]",children:s.name}),t.jsx("span",{className:"text-2xs font-mono font-semibold px-1.5 py-px rounded-sm flex-shrink-0 capitalize",style:{background:m.bg,color:m.text},children:(s.role||"").toLowerCase()}),t.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1 py-px rounded-sm flex-shrink-0 truncate max-w-[72px]",children:Mee(s.model)}),t.jsx("div",{className:"flex-1"}),A!=null&&t.jsxs("span",{className:"text-2xs font-mono font-bold px-1 py-px rounded-sm flex-shrink-0 text-text-1 bg-surface-4",children:[A,"%"]}),s.costSource&&s.costSource!=="actual"&&t.jsx("span",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex-shrink-0",children:Ree[s.costSource]||""}),t.jsxs("div",{className:"text-right flex-shrink-0",children:[t.jsx("div",{className:"text-xs font-mono text-text-1 tabular-nums leading-none",children:Qt(s.tokens||0)}),(s.costUsd||0)>0&&t.jsx("div",{className:"text-2xs font-mono text-text-3 mt-0.5",children:$o(s.costUsd)})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative flex-1 h-0.5 rounded-sm overflow-visible",style:{background:qe(ce.text4,.2)},children:[t.jsx("div",{className:"absolute inset-y-0 left-0 rounded-sm transition-all duration-700",style:{width:`${Math.max(r,1)}%`,background:h}}),f&&t.jsx("div",{className:"absolute top-[-1px] w-px h-[4px]",style:{left:`${f}%`,background:ce.text3},title:`Rotation at ${f}%`})]}),t.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums flex-shrink-0 w-7 text-right",children:[r,"%"]})]})]})});function _ee({team:e,members:s,rotatingSet:n}){const[a,r]=p.useState(!0),l=s.filter(m=>m.status==="running"||m.status==="starting").length,c=l>0,A=s.reduce((m,h)=>m+(h.tokens||0),0),f=s.reduce((m,h)=>m+(h.costUsd||0),0);return t.jsxs("div",{children:[t.jsxs("button",{onClick:()=>r(m=>!m),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-surface-4 bg-surface-3",style:{borderLeft:c?`2px solid ${ce.accent}`:"2px solid transparent"},children:[a?t.jsx(dt,{size:10,className:"text-text-4 flex-shrink-0"}):t.jsx(Ct,{size:10,className:"text-text-4 flex-shrink-0"}),t.jsx("span",{className:"text-2xs font-mono font-semibold text-text-2 uppercase tracking-widest flex-1 truncate",children:e}),t.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:Qt(A)}),f>0&&t.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums ml-1",children:$o(f)}),t.jsxs("span",{className:"text-2xs font-mono tabular-nums flex-shrink-0 ml-1.5",style:{color:c?ce.text1:void 0},children:[l,"/",s.length]})]}),a&&s.map(m=>t.jsx(Iee,{agent:m,isRotating:n.has(m.id)},m.id))]})}const zee=p.memo(function({agentBreakdown:s,rotating:n=[],teams:a=[]}){if(!(s!=null&&s.length))return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono p-4",children:"No agents"});const r={};for(const A of a)r[A.id]=A.name;const l={};for(const A of s){const f=A.teamId||"ungrouped";l[f]||(l[f]=[]),l[f].push(A)}const c=new Set(n);return t.jsx(bt,{className:"flex-1",children:t.jsx("div",{className:"py-1",children:Object.entries(l).map(([A,f])=>t.jsx(_ee,{team:r[A]||(A==="ungrouped"?"Ungrouped":A),members:f,rotatingSet:c},A))})})}),Ps=36,LO=3,_f=(Ps-LO)/2,hf=2*Math.PI*_f,gQ=-90;function Lee(){return ce.text1}function Dee({name:e,pct:s,threshold:n}){const a=Lee(),r=s/100*hf;return t.jsxs("div",{className:"flex flex-col items-center gap-0.5",title:`${e}: ${s}% context used`,children:[t.jsxs("svg",{width:Ps,height:Ps,viewBox:`0 0 ${Ps} ${Ps}`,children:[t.jsx("circle",{cx:Ps/2,cy:Ps/2,r:_f,fill:"none",strokeWidth:LO,className:"stroke-surface-4"}),t.jsx("circle",{cx:Ps/2,cy:Ps/2,r:_f,fill:"none",strokeWidth:LO,strokeLinecap:"round",style:{stroke:a,strokeDasharray:`${r} ${hf-r}`,strokeDashoffset:0,transition:"stroke-dasharray 0.5s ease"},transform:`rotate(${gQ} ${Ps/2} ${Ps/2})`}),n&&t.jsx("circle",{cx:Ps/2,cy:Ps/2,r:_f,fill:"none",strokeWidth:1,strokeLinecap:"butt",style:{stroke:ce.text3,strokeDasharray:`1 ${hf-1}`,strokeDashoffset:-(n/100)*hf},transform:`rotate(${gQ} ${Ps/2} ${Ps/2})`}),t.jsx("text",{x:Ps/2,y:Ps/2+1,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-1 font-mono font-semibold",style:{fontSize:9},children:s})]}),t.jsx("span",{className:"text-2xs font-mono text-text-3 truncate max-w-[40px] leading-none",children:e})]})}function Hee({zones:e}){return t.jsxs("div",{className:"flex items-center gap-2 text-2xs font-mono",children:[t.jsx("span",{className:"text-text-2",children:e.healthy}),t.jsx("span",{className:"text-text-4",children:"/"}),t.jsx("span",{className:"text-text-2",children:e.warning}),t.jsx("span",{className:"text-text-4",children:"/"}),t.jsx("span",{className:"text-text-2",children:e.critical})]})}const Xee=p.memo(function({agentBreakdown:s}){const n=(s||[]).filter(r=>r.status==="running"||r.status==="starting");if(n.length===0)return null;const a={healthy:0,warning:0,critical:0};for(const r of n){const l=Math.round((r.contextUsage||0)*100);l>80?a.critical++:l>60?a.warning++:a.healthy++}return t.jsxs("div",{className:"px-3 py-2 flex-shrink-0 border-b border-border",children:[t.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Context Health"}),t.jsx(Hee,{zones:a})]}),t.jsx("div",{className:"flex items-start gap-2 overflow-x-auto",children:n.map(r=>{const l=Math.round((r.contextUsage||0)*100),c=r.rotationThreshold?Math.round(r.rotationThreshold*100):null;return t.jsx(Dee,{name:r.name,pct:l,threshold:c},r.id)})})]})}),Zee=p.memo(function({data:s}){const n=p.useRef(null),a=p.useRef(null),[r,l]=p.useState({width:0,height:0}),[c,A]=p.useState(null),{width:f,height:m}=r,h={top:28,right:12,bottom:8,left:12},g=Math.max(f-h.left-h.right,0),O=Math.max(m-h.top-h.bottom,0),b=p.useMemo(()=>!s||s.length<2?[]:s.slice(1).map((N,Q)=>{const S=s[Q],C=(N.t-S.t)/6e4,k=Math.max((N.tokens||0)-(S.tokens||0),0);return{burnRate:C>0?Math.round(k/C):0,cacheHitRate:N.cacheHitRate||0,running:N.running||0,agents:N.agents||0,t:N.t}}),[s]);p.useEffect(()=>{const N=n.current;if(!N)return;const Q=new ResizeObserver(S=>{const{width:C,height:k}=S[0].contentRect;C>0&&k>0&&l({width:Math.floor(C),height:Math.floor(k)})});return Q.observe(N),()=>Q.disconnect()},[]);const v=p.useCallback(N=>{const Q=a.current;if(!Q||!b.length||g<=0)return;const S=Q.getBoundingClientRect(),C=N.clientX-S.left-h.left;if(C<0||C>g){A(null);return}const k=Math.round(C/g*(b.length-1));A({x:h.left+k/Math.max(b.length-1,1)*g,index:k})},[b,g,h.left]),w=p.useCallback(()=>A(null),[]);return p.useEffect(()=>{const N=a.current;if(!N||!b.length||f<=0||m<=0||g<=0||O<=0)return;const Q=N.getContext("2d"),S=window.devicePixelRatio||1;N.width=f*S,N.height=m*S,Q.scale(S,S),Q.clearRect(0,0,f,m);const C=b.map(E=>E.burnRate),k=b.map(E=>E.cacheHitRate),F=b.map(E=>E.running),B=Math.max(...C,100),T=Math.max(...F,1),$=E=>h.left+E/Math.max(b.length-1,1)*g,M=E=>h.top+O-E/B*O,I=E=>h.top+O-E*O,se=Math.max(g/b.length-1,2);for(let E=0;E<b.length;E++){const q=F[E];if(q<=0)continue;const D=q/T*O*.3,R=$(E)-se/2,_=h.top+O-D;Q.fillStyle=qe(ce.surface5,.5),Q.fillRect(R,_,se,D)}Q.setLineDash([2,4]),Q.strokeStyle=qe(ce.text4,.2),Q.lineWidth=1;for(let E=1;E<=3;E++){const q=h.top+O/4*E;Q.beginPath(),Q.moveTo(h.left,q),Q.lineTo(h.left+g,q),Q.stroke()}Q.setLineDash([]),Q.font="9px 'JetBrains Mono Variable', monospace",Q.textAlign="left",Q.fillStyle=qe(ce.text3,.5),Q.fillText(`${Qt(B)}/m`,h.left+4,h.top+10),Q.fillText(`${Qt(Math.round(B/2))}/m`,h.left+4,h.top+O/2+4),Q.beginPath(),Q.moveTo(h.left,h.top+O);for(let E=0;E<b.length;E++)Q.lineTo($(E),M(C[E]));Q.lineTo($(b.length-1),h.top+O),Q.closePath();const H=Q.createLinearGradient(0,h.top,0,h.top+O);H.addColorStop(0,qe(ce.accent,.2)),H.addColorStop(.7,qe(ce.accent,.04)),H.addColorStop(1,qe(ce.accent,0)),Q.fillStyle=H,Q.fill(),Q.beginPath(),Q.strokeStyle=ce.accent,Q.lineWidth=1.5,Q.lineJoin="round";for(let E=0;E<b.length;E++){const q=$(E),D=M(C[E]);E===0?Q.moveTo(q,D):Q.lineTo(q,D)}Q.stroke();const ne=k.some(E=>E>0);if(ne){Q.beginPath(),Q.strokeStyle=qe(ce.text2,.5),Q.lineWidth=1,Q.lineJoin="round",Q.setLineDash([2,3]);for(let E=0;E<b.length;E++){const q=$(E),D=I(k[E]);E===0?Q.moveTo(q,D):Q.lineTo(q,D)}Q.stroke(),Q.setLineDash([])}Q.font="9px 'Inter Variable', sans-serif",Q.textAlign="right";let K=f-h.right-4;const L=14;if(ne&&(Q.fillStyle=qe(ce.text2,.5),Q.fillText("Cache %",K,L),K-=Q.measureText("Cache %").width+4,Q.beginPath(),Q.arc(K,L-3,2.5,0,Math.PI*2),Q.fill(),K-=14),Q.fillStyle=qe(ce.surface5,.7),Q.fillText("Agents",K,L),K-=Q.measureText("Agents").width+4,Q.beginPath(),Q.arc(K,L-3,2.5,0,Math.PI*2),Q.fill(),K-=14,Q.fillStyle=ce.accent,Q.fillText("Burn Rate",K,L),K-=Q.measureText("Burn Rate").width+4,Q.beginPath(),Q.arc(K,L-3,2.5,0,Math.PI*2),Q.fill(),c&&c.index>=0&&c.index<b.length){const E=c.x,q=b[c.index];Q.beginPath(),Q.moveTo(E,h.top),Q.lineTo(E,h.top+O),Q.strokeStyle=qe(ce.text1,.15),Q.lineWidth=1,Q.stroke();const D=M(q.burnRate);Q.beginPath(),Q.arc(E,D,3,0,Math.PI*2),Q.fillStyle=ce.accent,Q.fill();const R=[{label:"Burn",value:`${Qt(q.burnRate)}/m`,color:ce.accent},{label:"Cache",value:cc(q.cacheHitRate*100),color:ce.text2},{label:"Agents",value:`${q.running}/${q.agents}`,color:ce.text3}],_=104,oe=R.length*16+12;let Z=E+12;Z+_>f-8&&(Z=E-_-12);const ee=Math.max(h.top,D-oe/2);Q.fillStyle=qe(ce.surface0,.92),Q.beginPath(),Q.roundRect(Z,ee,_,oe,4),Q.fill(),Q.strokeStyle=qe(ce.text4,.2),Q.lineWidth=1,Q.stroke(),Q.textAlign="left",R.forEach((le,ae)=>{const X=ee+14+ae*16;Q.beginPath(),Q.arc(Z+8,X-3,2,0,Math.PI*2),Q.fillStyle=le.color,Q.fill(),Q.font="8px 'Inter Variable', sans-serif",Q.fillStyle=ce.text3,Q.fillText(le.label,Z+14,X),Q.font="9px 'JetBrains Mono Variable', monospace",Q.fillStyle=ce.text0,Q.textAlign="right",Q.fillText(le.value,Z+_-8,X),Q.textAlign="left"})}},[b,f,m,c,g,O,h]),t.jsx("div",{ref:n,className:"absolute inset-0",children:f>0&&m>0&&t.jsx("canvas",{ref:a,style:{width:f,height:m},className:"block cursor-crosshair",onMouseMove:v,onMouseLeave:w})})}),Gee=p.memo(function({cacheRead:s=0,cacheCreation:n=0,totalInput:a=0,size:r=140}){const l=p.useRef(null),c=s+n,A=c,f=c>0?s/c*100:0;return p.useEffect(()=>{const m=l.current;if(!m)return;const h=window.devicePixelRatio||1;m.width=r*h,m.height=r*h;const g=m.getContext("2d");g.scale(h,h),g.clearRect(0,0,r,r);const O=r/2,b=r/2,v=(r-12)/2,w=5,N=135*Math.PI/180,Q=405*Math.PI/180,S=Q-N;if(g.beginPath(),g.arc(O,b,v,N,Q),g.strokeStyle=ce.surface4,g.lineWidth=w,g.lineCap="round",g.stroke(),A>0){const C=s/A,k=n/A;if(C>0){const F=N+S*C;g.beginPath(),g.arc(O,b,v,N,F),g.strokeStyle=ce.text0,g.lineWidth=w,g.lineCap="round",g.stroke()}if(k>0){const F=N+S*C,B=F+S*k;g.beginPath(),g.arc(O,b,v,F,B),g.strokeStyle=ce.text3,g.lineWidth=w,g.lineCap="butt",g.stroke()}}g.textAlign="center",g.textBaseline="middle",g.font=`600 ${r*.2}px 'JetBrains Mono Variable', monospace`,g.fillStyle=ce.text0,g.fillText(`${Math.round(f)}%`,O,b-3),g.font=`500 ${r*.08}px 'JetBrains Mono Variable', monospace`,g.fillStyle=ce.text3,g.fillText("CACHE",O,b+r*.13)},[s,n,a,r,A,f]),t.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-3 py-3",children:[t.jsx("canvas",{ref:l,className:"flex-shrink-0",style:{width:r,height:r}}),t.jsxs("div",{className:"w-full mt-3 space-y-1.5 max-w-[160px]",children:[t.jsx(kg,{color:ce.text0,label:"Read",value:Qt(s)}),t.jsx(kg,{color:ce.text3,label:"Create",value:Qt(n)}),t.jsx(kg,{color:ce.surface5,label:"Miss",value:Qt(Math.max(a-s-n,0))})]})]})});function kg({color:e,label:s,value:n}){return t.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono",children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:e}}),t.jsx("span",{className:"text-text-3 uppercase tracking-wider flex-1",children:s}),t.jsx("span",{className:"text-text-1 tabular-nums",children:n})]})}const v4={heavy:ce.text0,medium:ce.text2,light:ce.text4},Vee={heavy:"Heavy",medium:"Medium",light:"Light"},Ys=80,DO=6,HO=(Ys-DO)/2,OQ=2*Math.PI*HO;function Kee({byTier:e,total:s,tiers:n}){let a=0;const r=[];for(const l of n){const c=e[l]||0;if(c===0)continue;const f=c/s*OQ;r.push({tier:l,dashLen:f,offset:a}),a+=f}return s>0&&Math.round((e.heavy||0)/s*100),t.jsxs("svg",{width:Ys,height:Ys,viewBox:`0 0 ${Ys} ${Ys}`,className:"flex-shrink-0",children:[t.jsx("circle",{cx:Ys/2,cy:Ys/2,r:HO,fill:"none",strokeWidth:DO,className:"stroke-surface-4"}),r.map(l=>t.jsx("circle",{cx:Ys/2,cy:Ys/2,r:HO,fill:"none",strokeWidth:DO,strokeLinecap:"butt",style:{stroke:v4[l.tier],strokeDasharray:`${l.dashLen} ${OQ-l.dashLen}`,strokeDashoffset:-l.offset},transform:`rotate(-90 ${Ys/2} ${Ys/2})`},l.tier)),t.jsx("text",{x:Ys/2,y:Ys/2-2,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-0 text-sm font-mono font-semibold",children:Qt(s)}),t.jsx("text",{x:Ys/2,y:Ys/2+11,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-3 font-mono",style:{fontSize:7},children:"decisions"})]})}const qee=p.memo(function({routing:s,agentBreakdown:n}){if(!s)return null;const{byTier:a={},totalDecisions:r=0,autoRoutedCount:l=0}=s,c=["heavy","medium","light"],A=c.reduce((g,O)=>g+(a[O]||0),0),f={};for(const g of n||[]){const O=g.model||"default";f[O]||(f[O]={tokens:0,agents:0}),f[O].tokens+=g.tokens||0,f[O].agents+=1}const m=Object.entries(f).sort((g,O)=>O[1].tokens-g[1].tokens),h=m.length>0?m[0][1].tokens:0;return t.jsxs("div",{className:"flex flex-col h-full px-3 py-3 overflow-y-auto",children:[A>0&&t.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[t.jsx(Kee,{byTier:a,total:A,tiers:c}),t.jsxs("div",{className:"flex flex-col gap-1.5 flex-1 min-w-0",children:[c.map(g=>{const O=a[g]||0;if(O===0)return null;const b=O/A*100;return t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:v4[g]}}),t.jsx("span",{className:"text-2xs font-mono text-text-2 flex-1",children:Vee[g]}),t.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums",children:O}),t.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums w-8 text-right",children:cc(b)})]},g)}),l>0&&t.jsxs("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:[l," auto-routed"]})]})]}),m.length>0&&t.jsxs("div",{className:"space-y-1.5 flex-1",children:[t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Models in Use"}),t.jsx("div",{className:"space-y-1.5",children:m.map(([g,O])=>{const b=h>0?O.tokens/h*100:0;return t.jsxs("div",{className:"space-y-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs font-mono text-text-1 flex-1 truncate",children:Wee(g)}),t.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[O.agents," agent",O.agents!==1?"s":""]}),t.jsx("span",{className:"text-xs font-mono text-text-1 tabular-nums",children:Qt(O.tokens)})]}),t.jsx("div",{className:"h-0.5 bg-surface-4 rounded-sm overflow-hidden",children:t.jsx("div",{className:"h-full rounded-sm transition-all duration-500",style:{width:`${Math.max(b,2)}%`,background:ce.text2}})})]},g)})})]}),A===0&&m.length===0&&t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono",children:"No routing data"})]})});function Wee(e){if(!e||e==="auto"||e==="default")return"Default";const s=e.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:e.startsWith("gemini-")?e.replace("gemini-","Gemini ").replace("-preview",""):e}function y4({text:e}){return t.jsx(ot,{content:t.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:e}),side:"bottom",children:t.jsx(vi,{size:9,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors ml-0.5"})})}function Yee({children:e,tip:s}){return t.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex items-center gap-0.5",children:[e,s&&t.jsx(y4,{text:s})]})}function pf({label:e,value:s,tip:n}){return t.jsxs("div",{children:[t.jsx(Yee,{tip:n,children:e}),t.jsx("div",{className:"text-sm font-mono font-semibold text-text-1 tabular-nums leading-snug",children:s})]})}function xd({title:e,children:s,tip:n}){return t.jsxs("div",{className:"px-3 py-2.5",children:[t.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider mb-2 flex items-center gap-0.5",children:[e,n&&t.jsx(y4,{text:n})]}),s]})}function fc(){return t.jsx("div",{className:"h-px bg-border mx-3"})}function Jee({tokens:e,rotation:s,agentBreakdown:n}){const r=(n||[]).filter(c=>{var A;return((A=c.quality)==null?void 0:A.score)!=null}),l=r.length>0?Math.round(r.reduce((c,A)=>c+A.quality.score,0)/r.length):null;return t.jsxs("div",{className:"px-3 py-3 flex items-start gap-5",children:[t.jsx(pf,{label:"Quality",value:l??"—",tip:"Average session quality (0-100). Below 40 triggers auto-rotation."}),t.jsx(pf,{label:"Cache",value:cc(((e==null?void 0:e.cacheHitRate)||0)*100),tip:"Prompt cache hit rate. Higher = faster + cheaper."}),t.jsx(pf,{label:"Rotations",value:(s==null?void 0:s.totalRotations)||0,tip:"Total context rotations this session."}),((e==null?void 0:e.totalCostUsd)||0)>0&&t.jsx(pf,{label:"Cost",value:$o(e.totalCostUsd),tip:"Total cost reported by providers."})]})}function ete({agentBreakdown:e,rotation:s}){const n=(s==null?void 0:s.liveScores)||{},a=(e||[]).filter(r=>r.status==="running");return a.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsx(xd,{title:"Live agents",children:t.jsx("div",{className:"space-y-0",children:a.map(r=>{var m;const l=r.quality||{},c=((m=n[r.id])==null?void 0:m.score)??l.score,A=$a(r.role),f=[l.errorCount>0&&`${l.errorCount} err`,l.repetitions>0&&`${l.repetitions} rep`,l.fileChurn>0&&`${l.fileChurn} churn`].filter(Boolean);return t.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[t.jsx("span",{className:"text-2xs font-semibold capitalize px-1 py-px rounded-sm flex-shrink-0",style:{background:A.bg,color:A.text},children:r.role}),t.jsx("span",{className:"text-text-2 truncate flex-1",children:r.name}),f.length>0&&t.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:f.join(" · ")}),t.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0 w-6 text-right",children:c??"—"})]},r.id)})})})]})}function tte({rotation:e}){const s=((e==null?void 0:e.history)||[]).slice(-5).reverse();if(s.length===0)return null;function n(a){return a.reason==="quality_degradation"?`Q:${a.qualityScore}`:a.reason==="token_limit_exceeded"?"tokens":a.reason==="runaway_velocity"?"velocity":a.reason==="natural_compaction"?"compacted":cc((a.contextUsage||0)*100)}return t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsx(xd,{title:"Recent rotations",children:t.jsx("div",{className:"space-y-0",children:s.map((a,r)=>t.jsxs("div",{className:"flex items-center gap-2 py-0.5 text-xs font-mono",children:[t.jsx("span",{className:"text-text-2 truncate flex-1",children:a.agentName||a.role}),t.jsx("span",{className:"text-text-3 flex-shrink-0",children:n(a)}),t.jsx("span",{className:"text-text-4 flex-shrink-0 w-10 text-right",children:ls(a.timestamp)})]},r))})})]})}function ste({adaptive:e}){if(!(e!=null&&e.length))return null;function s(n){const a=n.split(":");return{provider:a[0]||n,role:a[1]||""}}return t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsx(xd,{title:"Adaptive thresholds",tip:"Per-role rotation thresholds. GROOVE learns when each role benefits from rotation and adjusts automatically.",children:t.jsx("div",{className:"space-y-0",children:e.map(n=>{const{provider:a,role:r}=s(n.key),l=r||a,c=$a(l);return t.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[t.jsx("span",{className:"text-2xs font-semibold capitalize px-1 py-px rounded-sm flex-shrink-0",style:{background:c.bg,color:c.text},children:l}),r&&t.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:a}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0",children:cc(n.threshold*100)}),n.converged?t.jsx("span",{className:"text-2xs font-semibold flex-shrink-0",style:{color:ce.accent},children:"Converged"}):t.jsxs("span",{className:"text-2xs text-text-3 flex-shrink-0 flex items-center gap-1",children:[t.jsx("span",{className:"w-1 h-1 rounded-full [animation:node-pulse-bar_1.5s_ease-in-out_infinite]",style:{background:ce.text3}}),"Learning"]})]},n.key)})})})]})}function nte({journalist:e}){return!e||!((e.cycleCount||0)>0)&&!e.synthesizing?null:t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsxs(xd,{title:"Journalist",children:[t.jsxs("div",{className:"flex items-center gap-3 text-xs font-mono",children:[t.jsxs("span",{className:"text-text-2",children:[e.cycleCount||0," cycles"]}),e.lastCycleAt&&t.jsx("span",{className:"text-text-4",children:ls(e.lastCycleAt)}),e.synthesizing&&t.jsx("span",{className:"font-semibold text-accent animate-pulse",children:"Synthesizing"})]}),e.lastSummary&&t.jsx("div",{className:"text-xs text-text-3 leading-relaxed mt-1.5 line-clamp-3",children:e.lastSummary})]})]})}function ate({memory:e}){var f,m;const s=(e==null?void 0:e.constraints)||[],n=(e==null?void 0:e.discoveries)||[],a=(e==null?void 0:e.roles)||[],r=((f=e==null?void 0:e.specializations)==null?void 0:f.perProjectRole)||{},l=Object.keys(((m=e==null?void 0:e.specializations)==null?void 0:m.perAgent)||{}).length;if(s.length+n.length+a.length+l===0)return null;const A=[s.length>0&&`${s.length} constraints`,n.length>0&&`${n.length} discoveries`,a.length>0&&`${a.length} role chains`,l>0&&`${l} specializations`].filter(Boolean);return t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsxs(xd,{title:"Memory",tip:"Persistent knowledge across agent rotations. Constraints, error→fix discoveries, and handoff chains.",children:[t.jsx("div",{className:"text-xs font-mono text-text-3 mb-1.5",children:A.join(" · ")}),s.length>0&&t.jsxs("div",{className:"mt-2 space-y-0",children:[t.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Constraints"}),s.slice(0,3).map(h=>t.jsx("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:h.text},h.hash)),s.length>3&&t.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",s.length-3," more"]})]}),n.length>0&&t.jsxs("div",{className:"mt-2 space-y-0",children:[t.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Discoveries"}),n.slice(0,3).map((h,g)=>t.jsxs("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:[t.jsx("span",{className:"text-text-4",children:h.trigger})," → ",h.fix]},g)),n.length>3&&t.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",n.length-3," more"]})]}),Object.keys(r).length>0&&t.jsxs("div",{className:"mt-2",children:[t.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Role quality"}),t.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-0.5",children:Object.entries(r).map(([h,g])=>t.jsxs("span",{className:"text-xs font-mono text-text-3",children:[t.jsx("span",{className:"text-text-2 capitalize",children:h})," Q:",g.avgQualityScore," ",t.jsxs("span",{className:"text-text-4",children:["(",g.sessionCount,"s)"]})]},h))})]})]})]})}function rte({tokens:e}){var r,l;if(!((r=e==null?void 0:e.internalOverhead)!=null&&r.tokens)||!((l=e==null?void 0:e.savings)!=null&&l.total))return null;const s=e.internalOverhead,n=e.savings,a=e.totalTokens>0?Math.round(s.tokens/e.totalTokens*100):0;return t.jsxs(t.Fragment,{children:[t.jsx(fc,{}),t.jsxs("div",{className:"px-3 py-2.5 flex items-center gap-3 text-xs font-mono",children:[t.jsx("span",{className:"text-text-4",children:"Overhead"}),t.jsxs("span",{className:"text-text-3 tabular-nums",children:[Qt(s.tokens)," (",a,"%)"]}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-text-4",children:"Saved"}),t.jsx("span",{className:"text-text-3 tabular-nums",children:Qt(n.total)})]})]})}const ote=p.memo(function({tokens:s,rotation:n,adaptive:a,journalist:r,agentBreakdown:l,memory:c}){return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx("div",{className:"flex-shrink-0 px-3 pt-2.5 pb-1.5",children:t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Intel"})}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[t.jsx(Jee,{tokens:s,rotation:n,agentBreakdown:l}),t.jsx(ete,{agentBreakdown:l,rotation:n}),t.jsx(tte,{rotation:n}),t.jsx(ste,{adaptive:a}),t.jsx(nte,{journalist:r}),t.jsx(ate,{memory:c}),t.jsx(rte,{tokens:s}),t.jsx("div",{className:"h-3"})]})]})}),ite=p.memo(function({teams:s=[]}){const n=s.reduce((r,l)=>r+(l.totalTokens||0),0),a=s.reduce((r,l)=>Math.max(r,l.totalTokens||0),0);return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0 flex items-center justify-between",children:[t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Team Burn"}),t.jsxs("span",{className:"text-2xs font-mono text-text-3",children:[Qt(n)," total"]})]}),t.jsx(bt,{className:"flex-1 min-h-0",children:s.length===0?t.jsx("div",{className:"px-3 py-6 text-center text-xs text-text-3 font-mono",children:"No team activity yet"}):t.jsx("div",{className:"px-3 py-3 space-y-3",children:s.map(r=>{const l=a>0?r.totalTokens/a*100:0;return t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:r.teamName}),r.isDefault&&t.jsx("span",{className:"text-[9px] font-mono text-text-3 uppercase tracking-wider",children:"default"}),t.jsxs("span",{className:"text-2xs font-mono text-text-3 flex-shrink-0",children:[r.agentCount," ",r.agentCount===1?"agent":"agents"]})]}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 font-mono text-2xs",children:[t.jsx("span",{className:"text-text-1",children:Qt(r.totalTokens)}),t.jsx("span",{className:"text-text-3",children:$o(r.totalCostUsd)})]})]}),t.jsx("div",{className:"h-0.5 bg-surface-2 rounded-sm overflow-hidden",children:t.jsx("div",{className:"h-full rounded-sm transition-all",style:{width:`${l}%`,background:ce.text3}})})]},r.teamId)})})})]})}),lte={spawn:BN,complete:Ma,crash:sa,kill:Kg,rotate:od,error:Cb},cte={spawn:"text-text-2",complete:"text-text-2",crash:"text-danger",kill:"text-text-3",rotate:"text-text-2",error:"text-danger"};function Ate(e){const s=e.agentName||e.role||"";switch(e.type){case"spawn":return`${s} spawned`;case"complete":return`${s} completed`;case"crash":return`${s} crashed`;case"kill":return`${s} killed`;case"rotate":return`${s} rotated`;default:return e.text||e.type||"event"}}const dte=p.memo(function({events:s=[]}){return s.length?t.jsx("div",{className:"flex items-center gap-3 overflow-x-auto py-2 px-3",children:s.slice(-15).reverse().map((n,a)=>{const r=lte[n.type]||Wt,l=cte[n.type]||"text-text-3",c=Ate(n);return t.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[t.jsx(r,{size:11,className:l}),t.jsx("span",{className:"text-xs font-sans text-text-2 whitespace-nowrap",children:c}),t.jsx("span",{className:"text-2xs font-mono text-text-4",children:ls(n.t||n.timestamp)})]},a)})}):t.jsx("div",{className:"text-xs text-text-3 font-mono py-2.5 text-center",children:"No recent activity"})});function Jn({className:e,...s}){return t.jsx("div",{className:V("rounded-md bg-surface-4","bg-gradient-to-r from-surface-4 via-surface-5 to-surface-4","bg-[length:200%_100%] animate-[shimmer_1.5s_ease-in-out_infinite]",e),...s})}function ute(){return t.jsxs("div",{className:"flex-1 grid gap-px p-0 bg-surface-3",style:{gridTemplateRows:"auto minmax(0, 1fr) minmax(0, 1fr)",gridTemplateColumns:"2fr 2.5fr 1.5fr"},children:[t.jsx("div",{className:"col-span-3",children:t.jsx(Jn,{className:"h-[72px] rounded-none"})}),t.jsx(Jn,{className:"rounded-none"}),t.jsx(Jn,{className:"rounded-none"}),t.jsx(Jn,{className:"rounded-none"}),t.jsx(Jn,{className:"rounded-none"}),t.jsx("div",{className:"col-span-2",children:t.jsx(Jn,{className:"h-full rounded-none"})})]})}function fte(){const{data:e,loading:s,agents:n,connected:a,kpiHistory:r,lastFetch:l,agentBreakdown:c,routing:A,rotation:f,adaptive:m,journalist:h,rotating:g,teamBurn:O,memory:b}=Eee(),v=U(I=>I.teams),w=n.filter(I=>I.status==="running").length;if(!a)return t.jsx("div",{className:"w-full h-full flex items-center justify-center",children:t.jsxs("div",{className:"text-center space-y-2 text-text-3 font-mono",children:[t.jsx(Ux,{size:28,className:"mx-auto"}),t.jsx("p",{className:"text-xs",children:"Connecting to daemon..."})]})});if(s||!e)return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx(pQ,{connected:a,runningCount:0,totalCount:0,uptime:0,lastFetch:0}),t.jsx(ute,{})]});const N=e.tokens||{},Q={totalTokens:N.totalTokens||0,totalCostUsd:N.totalCostUsd||0,totalInputTokens:N.totalInputTokens||0,totalOutputTokens:N.totalOutputTokens||0,cacheReadTokens:N.cacheReadTokens||0,cacheCreationTokens:N.cacheCreationTokens||0,cacheHitRate:N.cacheHitRate||0,totalTurns:N.totalTurns||0,agentCount:N.agentCount||0,savings:N.savings||{},internalOverhead:N.internalOverhead||{tokens:0,costUsd:0,components:{}}},S=Q.totalOutputTokens>0?(Q.totalInputTokens/Q.totalOutputTokens).toFixed(1):"—",C=(f==null?void 0:f.totalRotations)||0,k=(c||[]).filter(I=>{var se;return((se=I.quality)==null?void 0:se.score)!=null}),F=k.length>0?Math.round(k.reduce((I,se)=>I+se.quality.score,0)/k.length):null,B=e.timeline||{},T=B.snapshots||[],$=B.events||e.events||[],M=[{label:"Tokens Used",value:Qt(Q.totalTokens),sparkData:r.tokens,color:ce.text3,hint:"Total tokens consumed across all agents — input, output, and cache tokens combined."},{label:"Total Cost",value:$o(Q.totalCostUsd),sparkData:r.cost,color:ce.text3,hint:"Actual cost reported by providers. Claude Code reports real billing; other providers use estimated rates."},{label:"Quality",value:F!=null?`${F}`:"—",sparkData:r.saved,color:ce.text3,hint:"Average session quality score (0-100) across running agents. Based on error rate, repetitions, file churn, and tool success. Below 40 triggers auto-rotation."},{label:"Cache Rate",value:cc(Q.cacheHitRate*100),sparkData:r.cache,color:ce.text3,hint:"Percentage of input tokens served from prompt cache. Higher = faster responses and lower cost. Managed by your AI provider."},{label:"Rotations",value:`${C}`,sparkData:r.efficiency,color:ce.text3,hint:"Total context rotations — includes quality-based (auto), context threshold, natural compaction (provider-managed), and manual rotations."},{label:"I/O Ratio",value:`${S}:1`,sparkData:r.inputOutput,color:ce.text3,hint:"Ratio of input to output tokens. High ratios mean agents are reading more than writing — common for analysis tasks."},{label:"Agents",value:`${w}/${n.length}`,sparkData:r.agents,color:ce.text3,hint:"Running agents out of total spawned this session (including completed and crashed)."},{label:"Turns",value:Qt(Q.totalTurns),sparkData:r.turns,color:ce.text3,hint:"Total conversation turns across all agents. Each turn is one request-response cycle with the AI provider."}];return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx(pQ,{connected:a,runningCount:w,totalCount:n.length,uptime:e.uptime||0,lastFetch:l,activeTeam:e.activeTeam}),t.jsx($ee,{kpis:M}),t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col bg-surface-3 gap-px",children:[t.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"3fr 1.5fr 1.5fr"},children:[t.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 relative",children:t.jsx(Zee,{data:T})}),t.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[t.jsx("div",{className:"px-3 pt-2.5 pb-1",children:t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Cache Performance"})}),t.jsx(Gee,{cacheRead:Q.cacheReadTokens,cacheCreation:Q.cacheCreationTokens,totalInput:Q.totalInputTokens})]}),t.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[t.jsx("div",{className:"px-3 pt-2.5 pb-1",children:t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Model Routing"})}),t.jsx(qee,{routing:A,agentBreakdown:c})]})]}),t.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"2fr 2.5fr 1.5fr"},children:[t.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-border",children:[t.jsx("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0",children:t.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Agent Fleet"})}),t.jsx(Xee,{agentBreakdown:c}),t.jsx(zee,{agentBreakdown:c,rotating:g,teams:v})]}),t.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:t.jsx(ote,{tokens:Q,rotation:f,adaptive:m,journalist:h,agentBreakdown:c,memory:b})}),t.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:t.jsx(ite,{teams:O})})]})]}),t.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-t border-border",children:t.jsx(dte,{events:$})})]})}const bQ={sm:12,md:16,lg:20};function xte({fill:e="full",size:s,color:n="#fbbf24",emptyColor:a="rgba(255,255,255,0.4)"}){const r=`star-${Math.random().toString(36).slice(2,8)}`;return t.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",children:[e==="half"&&t.jsx("defs",{children:t.jsxs("linearGradient",{id:r,children:[t.jsx("stop",{offset:"50%",stopColor:n}),t.jsx("stop",{offset:"50%",stopColor:a})]})}),t.jsx("path",{d:"M10 1.5l2.47 5.01 5.53.8-4 3.9.94 5.49L10 14.27 5.06 16.7 6 11.21l-4-3.9 5.53-.8L10 1.5z",fill:e==="full"?n:e==="half"?`url(#${r})`:a})]})}function mte({rating:e=0,count:s,size:n="sm"}){const a=bQ[n]||bQ.sm,r=[];for(let l=1;l<=5;l++)e>=l?r.push("full"):e>=l-.5?r.push("half"):r.push("empty");return t.jsxs("span",{className:"inline-flex items-center",style:{gap:1},children:[r.map((l,c)=>t.jsx(xte,{fill:l,size:a},c)),s!=null&&t.jsxs("span",{className:"ml-1 text-[11px] text-[var(--text-dim,#6b7f95)] font-sans",children:["(",s,")"]})]})}const vQ={design:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},quality:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},devtools:{color:"#33afbc",bg:"rgba(51,175,188,0.14)"},workflow:{color:"#fbbf24",bg:"rgba(251,191,36,0.12)"},security:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},specialized:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},verified:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},anthropic:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},published:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},draft:{color:"#6b7f95",bg:"rgba(255,255,255,0.06)"},review:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},rejected:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},free:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"}};function hte({label:e,variant:s,className:n}){const a=vQ[s]||vQ.draft;return t.jsx("span",{className:V("inline-flex items-center whitespace-nowrap font-sans select-none",n),style:{padding:"3px 8px",borderRadius:4,fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",lineHeight:1.4,color:a.color,background:a.bg},children:e})}function pte({price:e=0,size:s="sm"}){const n=!e||e===0,a={sm:"text-2xs px-2 py-0.5",md:"text-xs px-2.5 py-0.5",lg:"text-xs px-3 py-1"};return t.jsx("span",{className:`inline-flex items-center font-mono font-semibold rounded whitespace-nowrap ${a[s]||a.sm} ${n?"bg-success/12 text-success":"bg-white/8 text-text-1"}`,children:n?"Free":`$${e.toFixed(2)}`})}function gte({type:e="verified",size:s=12}){const n=e==="claude-official"||e==="anthropic"?"#f59e0b":"#4ade80";return t.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",className:"inline-block flex-shrink-0",children:[t.jsx("path",{d:"M10 0l2.36 3.15L16.18 2l.68 3.93L20.8 7.1l-1.87 3.52L20.8 14.14l-3.94 1.17-.68 3.93-3.82-1.15L10 21.24l-2.36-3.15-3.82 1.15-.68-3.93-3.94-1.17 1.87-3.52L-.8 7.1l3.94-1.17.68-3.93 3.82 1.15L10 0z",fill:n}),t.jsx("path",{d:"M7 10.5l2 2 4-4.5",fill:"none",stroke:"#24282f",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Ote(){return t.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md animate-pulse",style:{padding:20,minHeight:280},children:[t.jsx("div",{className:"w-10 h-10 rounded-full bg-surface-4"}),t.jsx("div",{className:"mt-3 h-4 w-[70%] rounded bg-surface-4"}),t.jsx("div",{className:"mt-2 h-3 w-[40%] rounded bg-surface-4"}),t.jsx("div",{className:"mt-3.5 h-3 w-full rounded bg-surface-4"}),t.jsx("div",{className:"mt-1.5 h-3 w-[90%] rounded bg-surface-4"}),t.jsx("div",{className:"mt-1.5 h-3 w-[60%] rounded bg-surface-4"}),t.jsx("div",{className:"mt-3.5 h-5 w-[50px] rounded bg-surface-4"}),t.jsx("div",{className:"h-px bg-surface-4 my-3"}),t.jsxs("div",{className:"flex justify-between",children:[t.jsx("div",{className:"h-3 w-16 rounded bg-surface-4"}),t.jsx("div",{className:"h-3 w-12 rounded bg-surface-4"}),t.jsx("div",{className:"h-3 w-10 rounded bg-surface-4"})]})]})}const pi={"google-workspace":"https://cdn.simpleicons.org/google/white",slack:"https://cdn.simpleicons.org/slack/E01E5A",discord:"https://cdn.simpleicons.org/discord/5865F2",github:"https://cdn.simpleicons.org/github/white",stripe:"https://cdn.simpleicons.org/stripe/635BFF",gmail:"https://cdn.simpleicons.org/gmail/EA4335","google-calendar":"https://cdn.simpleicons.org/googlecalendar/4285F4","google-drive":"https://cdn.simpleicons.org/googledrive/4285F4","google-docs":"https://cdn.simpleicons.org/googledocs/4285F4","google-sheets":"https://cdn.simpleicons.org/googlesheets/34A853","google-slides":"https://cdn.simpleicons.org/googleslides/FBBC04","google-maps":"https://cdn.simpleicons.org/googlemaps/4285F4",postgres:"https://cdn.simpleicons.org/postgresql/4169E1",notion:"https://cdn.simpleicons.org/notion/white",linear:"https://cdn.simpleicons.org/linear/5E6AD2","brave-search":"https://cdn.simpleicons.org/brave/FB542B","home-assistant":"https://cdn.simpleicons.org/homeassistant/18BCF2",sentry:"https://cdn.simpleicons.org/sentry/362D59",elevenlabs:"https://cdn.simpleicons.org/elevenlabs/white",hubspot:"https://cdn.simpleicons.org/hubspot/FF7A59",jira:"https://cdn.simpleicons.org/jira/0052CC",sendgrid:"https://cdn.simpleicons.org/sendgrid/1A82E2",resend:"https://cdn.simpleicons.org/resend/white",replicate:"https://cdn.simpleicons.org/replicate/white",vercel:"https://cdn.simpleicons.org/vercel/white",supabase:"https://cdn.simpleicons.org/supabase/3FCF8E",mixpanel:"https://cdn.simpleicons.org/mixpanel/7856FF",datadog:"https://cdn.simpleicons.org/datadog/632CA6",airtable:"https://cdn.simpleicons.org/airtable/18BFFF",zendesk:"https://cdn.simpleicons.org/zendesk/03363D",intercom:"https://cdn.simpleicons.org/intercom/6AFDEF",twilio:"https://cdn.simpleicons.org/twilio/F22F46",telnyx:"https://cdn.simpleicons.org/telnyx/00C08B",aws:"https://cdn.simpleicons.org/amazonaws/FF9900",plaid:"https://cdn.simpleicons.org/plaid/white"};function bte({item:e,size:s=40}){const n=pi[e.id];if(n)return t.jsxs("div",{className:"rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:[t.jsx("img",{src:n,alt:e.name,className:"w-5 h-5",onError:l=>{l.target.style.display="none",l.target.nextSibling.style.display="flex"}}),t.jsx("div",{className:"hidden items-center justify-center w-full h-full text-lg font-bold font-sans text-text-1",children:(e.name||"?")[0]})]});const a=(e.name||"?")[0].toUpperCase(),r=e.name?e.name.charCodeAt(0)*37%360:200;return t.jsx("div",{className:"rounded-md flex items-center justify-center flex-shrink-0 text-lg font-bold font-sans",style:{width:s,height:s,background:`hsl(${r}, 40%, 18%)`,color:`hsl(${r}, 60%, 65%)`},children:a})}function vx({item:e,onClick:s,className:n,statusBadge:a}){var l;const r=e.installed;return t.jsxs("button",{onClick:()=>s(e),className:V("flex flex-col p-5 rounded-md border border-border-subtle bg-surface-1 text-left","hover:border-accent/30 hover:bg-surface-2","transition-all duration-150 cursor-pointer group",n),style:{minHeight:200},children:[t.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[t.jsx(bte,{item:e,size:36}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-[14px] font-semibold text-text-0 font-sans truncate",children:e.name}),(e.verified||e.verified==="mcp-official")&&t.jsx(Ma,{size:11,className:"text-accent flex-shrink-0"})]}),t.jsx("span",{className:"text-2xs text-text-3 font-sans",children:e.author||"Community"})]})]}),t.jsx("p",{className:"text-xs text-text-2 font-sans line-clamp-3 mb-3 flex-1 leading-relaxed",children:e.description}),t.jsx("div",{className:"h-px bg-border-subtle my-2"}),t.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(Zs,{size:10}),Qt(e.downloads||0)]}),(e.rating||0)>0&&t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(kb,{size:10,className:"text-warning",fill:"currentColor"}),(l=e.rating)==null?void 0:l.toFixed(1)]}),t.jsx("span",{className:"flex-1"}),a||r&&t.jsx(ke,{variant:"accent",className:"text-2xs",children:e._installedCount?`${e._installedCount} active`:"Installed"})]})]})}function w4({value:e,onChange:s,placeholder:n="Search skills, tags, authors...",large:a}){const[r,l]=p.useState(e||""),c=p.useRef(null);p.useEffect(()=>{l(e||"")},[e]);function A(f){const m=f.target.value;l(m),clearTimeout(c.current),c.current=setTimeout(()=>s(m),300)}return t.jsxs("div",{className:"relative w-full",children:[t.jsx(Ms,{size:16,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),t.jsx("input",{value:r,onChange:A,placeholder:n,className:V("w-full font-sans outline-none","bg-surface-0 border border-border text-text-0 placeholder:text-text-4","focus:border-accent/40 transition-colors",a?"py-3 pl-11 pr-12 text-[15px] rounded-lg":"py-2.5 pl-10 pr-3 text-sm rounded-md")}),a&&t.jsx("kbd",{className:"absolute right-3.5 top-1/2 -translate-y-1/2 bg-surface-4 text-text-4 px-2 py-0.5 rounded text-xs font-mono",children:"/"})]})}function la(){const e=U(s=>s.addToast);return{success:(s,n)=>e("success",s,n),error:(s,n)=>e("error",s,n),info:(s,n)=>e("info",s,n),warning:(s,n)=>e("warning",s,n)}}const Kt=p.forwardRef(({className:e,label:s,error:n,mono:a,...r},l)=>t.jsxs("div",{className:"flex flex-col gap-1",children:[s&&t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),t.jsx("input",{ref:l,className:V("h-8 w-full rounded-md px-3 text-sm","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",a?"font-mono":"font-sans",n&&"border-danger focus:ring-danger",e),...r}),n&&t.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));Kt.displayName="Input";const jv=p.forwardRef(({className:e,label:s,error:n,mono:a,...r},l)=>t.jsxs("div",{className:"flex flex-col gap-1",children:[s&&t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),t.jsx("textarea",{ref:l,className:V("w-full rounded-md px-3 py-2 text-sm resize-none","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",a?"font-mono":"font-sans",n&&"border-danger focus:ring-danger",e),...r}),n&&t.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));jv.displayName="Textarea";const yQ=["bg-accent/15 text-accent","bg-purple/15 text-purple","bg-success/15 text-success","bg-warning/15 text-warning","bg-danger/15 text-danger","bg-info/15 text-info"];function Dl({item:e,size:s=48}){const n=pi[e.id];if(n)return t.jsx("div",{className:"rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:t.jsx("img",{src:n,alt:e.name,className:"w-6 h-6",onError:l=>{l.target.classList.add("hidden")}})});const a=(e.name||"?")[0].toUpperCase(),r=yQ[(e.name||"").charCodeAt(0)%yQ.length];return t.jsx("div",{className:`rounded-lg flex items-center justify-center flex-shrink-0 text-xl font-bold font-sans ${r}`,style:{width:s,height:s},children:a})}function XO({value:e,onChange:s,placeholder:n,disabled:a}){const[r,l]=p.useState(!1);return t.jsxs("div",{className:"relative",children:[t.jsx(Kt,{type:r?"text":"password",value:e,onChange:c=>s(c.target.value),placeholder:n,disabled:a,mono:!0,className:"pr-9"}),t.jsx("button",{type:"button",onClick:()=>l(c=>!c),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded text-text-4 hover:text-text-1 transition-colors cursor-pointer",tabIndex:-1,children:r?t.jsx(Oo,{size:14}):t.jsx(Hs,{size:14})})]})}function vte({integrationId:e,envKey:s,onSaved:n}){const a=la(),[r,l]=p.useState(""),[c,A]=p.useState(!1),[f,m]=p.useState(s.set),[h,g]=p.useState(!1);async function O(){if(r.trim()){A(!0);try{await G.post(`/integrations/${e}/credentials`,{key:s.key,value:r.trim()}),m(!0),l(""),a.success(`${s.label} saved`),n==null||n()}catch(v){a.error("Failed to save",v.message)}A(!1)}}async function b(){g(!0);try{await G.delete(`/integrations/${e}/credentials/${s.key}`),m(!1),a.success(`${s.label} removed`),n==null||n()}catch(v){a.error("Failed to remove",v.message)}g(!1)}return t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[t.jsx(yi,{size:11,className:"text-text-4"}),s.label,s.required&&t.jsx("span",{className:"text-danger",children:"*"})]}),f&&t.jsxs("span",{className:"flex items-center gap-1 text-2xs text-success font-sans",children:[t.jsx(Je,{size:10})," Set"]})]}),f?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"flex-1 h-8 rounded-md px-3 bg-surface-2 border border-border-subtle flex items-center",children:t.jsx("span",{className:"text-xs text-text-4 font-mono tracking-widest",children:"*".repeat(16)})}),t.jsx(ge,{variant:"ghost",size:"sm",onClick:b,disabled:h,className:"text-text-3 hover:text-danger",children:h?t.jsx(Ie,{size:12,className:"animate-spin"}):t.jsx(qt,{size:12})})]}):t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"flex-1",children:t.jsx(XO,{value:r,onChange:l,placeholder:s.placeholder||`Enter ${s.label.toLowerCase()}...`,disabled:c})}),t.jsx(ge,{variant:"primary",size:"sm",onClick:O,disabled:c||!r.trim(),children:c?t.jsx(Ie,{size:12,className:"animate-spin"}):"Save"})]})]})}function yte({item:e,status:s,installing:n,onInstall:a,onUninstall:r,onNext:l}){var A;const c=s==null?void 0:s.installed;return t.jsxs("div",{className:"px-5 py-5 space-y-5",children:[t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx(Dl,{item:e,size:52}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:e.name}),(e.verified==="mcp-official"||e.verified==="verified")&&t.jsxs(ke,{variant:"accent",className:"text-2xs gap-1",children:[t.jsx(Pn,{size:9})," Verified"]})]}),t.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:e.author||"Community"}),e.category&&t.jsx(ke,{variant:"default",className:"text-2xs mt-2",children:e.category})]})]}),t.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed",children:e.description}),((A=e.tags)==null?void 0:A.length)>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.tags.map(f=>t.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:f},f))}),t.jsx("div",{className:"h-px bg-border-subtle"}),c?t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[t.jsx(Ma,{size:16,className:"text-success"}),t.jsx("span",{className:"text-sm font-medium text-success font-sans",children:"Installed"})]}),t.jsxs(ge,{variant:"ghost",size:"sm",onClick:r,className:"text-text-3 hover:text-danger gap-1.5",children:[t.jsx(qt,{size:12})," Uninstall"]}),t.jsxs(ge,{variant:"primary",size:"sm",onClick:l,className:"gap-1",children:["Configure ",t.jsx(Ct,{size:12})]})]}):t.jsx(ge,{variant:"primary",size:"lg",onClick:a,disabled:n,className:"w-full gap-2",children:n?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:14,className:"animate-spin"}),"Installing..."]}):"Install"}),n&&t.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"This may take up to 30 seconds..."})]})}function wte({item:e,onClose:s}){const n=U(Q=>Q.agents),a=U(Q=>Q.teams),r=U(Q=>Q.installViaExistingAgent),l=U(Q=>Q.spawnIntegrationTeam),[c,A]=p.useState(null),[f,m]=p.useState(!1),[h,g]=p.useState(null),O=n.filter(Q=>Q.status==="running"||Q.status==="idle"),b={};for(const Q of O){const S=Q.teamId||"_none";b[S]||(b[S]=[]),b[S].push(Q)}const v={};for(const Q of a)v[Q.id]=Q.name;async function w(){h&&(await r(e,h),s())}async function N(){m(!0);try{await l(e),s()}catch{m(!1)}}return c?c==="spawn"?t.jsxs("div",{className:"px-5 py-5 space-y-5",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Dl,{item:e,size:36}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Spawn Integration Agent"}),t.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Creates a team and planner for ",e.name]})]})]}),t.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[t.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"What happens next"}),t.jsx("ol",{className:"space-y-1.5",children:[`A new team "${e.name}" will be created`,"A planner agent will spawn with full integration context","The agent will handle installation and configuration"].map((Q,S)=>t.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[t.jsxs("span",{className:"text-accent font-mono flex-shrink-0 w-4 text-right",children:[S+1,"."]}),t.jsx("span",{children:Q})]},S))})]}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ge,{variant:"secondary",size:"lg",onClick:()=>A(null),className:"flex-1",disabled:f,children:"Back"}),t.jsx(ge,{variant:"primary",size:"lg",onClick:N,disabled:f,className:"flex-1 gap-2",children:f?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:14,className:"animate-spin"})," Spawning..."]}):t.jsxs(t.Fragment,{children:[t.jsx(ji,{size:14})," Spawn Agent"]})})]})]}):t.jsxs("div",{className:"px-5 py-5 space-y-4",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Dl,{item:e,size:36}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Choose an Agent"}),t.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Send ",e.name," setup instructions to a running agent"]})]})]}),t.jsx(bt,{className:"max-h-64",children:t.jsx("div",{className:"space-y-3",children:Object.entries(b).map(([Q,S])=>t.jsxs("div",{children:[t.jsx("div",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5 px-1",children:v[Q]||"Unassigned"}),t.jsx("div",{className:"space-y-1",children:S.map(C=>t.jsxs("button",{onClick:()=>g(C.id),className:`w-full text-left px-3 py-2.5 rounded-md border transition-all cursor-pointer flex items-center gap-3 ${h===C.id?"border-accent bg-accent/8":"border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-border"}`,children:[t.jsx(bi,{size:14,className:h===C.id?"text-accent":"text-text-4"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:C.name||C.id}),t.jsx("div",{className:"text-2xs text-text-3 font-sans",children:C.role})]}),h===C.id&&t.jsx(Je,{size:14,className:"text-accent flex-shrink-0"})]},C.id))})]},Q))})}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ge,{variant:"secondary",size:"lg",onClick:()=>{A(null),g(null)},className:"flex-1",children:"Back"}),t.jsxs(ge,{variant:"primary",size:"lg",onClick:w,disabled:!h,className:"flex-1 gap-2",children:[t.jsx(bi,{size:14})," Send Instructions"]})]})]}):t.jsxs("div",{className:"px-5 py-5 space-y-5",children:[t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx(Dl,{item:e,size:52}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("h2",{className:"text-base font-bold text-text-0 font-sans",children:["Install ",e.name]}),t.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Choose how to set up this integration"})]})]}),t.jsx("div",{className:"h-px bg-border-subtle"}),t.jsxs("div",{className:"space-y-2.5",children:[t.jsx("button",{onClick:()=>O.length>0?A("existing"):null,disabled:O.length===0,className:"w-full text-left px-4 py-3.5 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-accent/30 transition-all cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed group",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/15 transition-colors",children:t.jsx(Fn,{size:18,className:"text-accent"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Use Existing Agent"}),t.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:O.length>0?`Send setup instructions to one of ${O.length} running agent${O.length!==1?"s":""}`:"No agents running — spawn one first"})]}),O.length>0&&t.jsx(Ct,{size:14,className:"text-text-4 group-hover:text-accent transition-colors"})]})}),t.jsx("button",{onClick:()=>A("spawn"),className:"w-full text-left px-4 py-3.5 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-accent/30 transition-all cursor-pointer group",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-9 h-9 rounded-lg bg-purple/10 flex items-center justify-center flex-shrink-0 group-hover:bg-purple/15 transition-colors",children:t.jsx(ji,{size:18,className:"text-purple"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn New Agent"}),t.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:"Create a dedicated team and planner for this integration"})]}),t.jsx(Ct,{size:14,className:"text-text-4 group-hover:text-accent transition-colors"})]})})]})]})}const jte={gmail:"Gmail API","google-calendar":"Google Calendar API","google-drive":"Google Drive API","google-docs":"Google Docs API","google-sheets":"Google Sheets API","google-slides":"Google Slides API"};function j4({integrationId:e,onConfigured:s}){const n=la(),[a,r]=p.useState(""),[l,c]=p.useState(""),[A,f]=p.useState(!1),m=jte[e]||"the relevant Google API";async function h(){if(!(!a.trim()||!l.trim())){f(!0);try{await G.post("/integrations/google-oauth/setup",{clientId:a.trim(),clientSecret:l.trim()}),n.success("Google OAuth credentials saved"),s()}catch(O){n.error("Failed to save",O.message)}f(!1)}}const g=[{text:"Go to the Google Cloud Console and sign in with your Google account",link:{url:"https://console.cloud.google.com",label:"Open Google Cloud Console"}},{text:"Create a new project (or select an existing one). Any name is fine — this is just a container for your credentials."},{text:t.jsxs(t.Fragment,{children:["Enable the ",t.jsx("strong",{children:m})," — search for it in the API Library and click ",t.jsx("strong",{children:"Enable"})]}),link:{url:"https://console.cloud.google.com/apis/library",label:"Open API Library"}},{text:t.jsxs(t.Fragment,{children:["Go to ",t.jsx("strong",{children:"Credentials"})," and click ",t.jsx("strong",{children:"Create Credentials"})," → ",t.jsx("strong",{children:"OAuth client ID"})]}),link:{url:"https://console.cloud.google.com/apis/credentials",label:"Open Credentials page"}},{text:t.jsxs(t.Fragment,{children:["If prompted to configure the consent screen, choose ",t.jsx("strong",{children:"External"}),', fill in an app name (e.g. "Groove"), your email, and save. You can skip optional fields.']})},{text:t.jsxs(t.Fragment,{children:["Go to ",t.jsx("strong",{children:"Audience"})," and click ",t.jsx("strong",{children:"Publish App"}),". Then scroll down to ",t.jsx("strong",{children:"Test users"}),", click ",t.jsx("strong",{children:"Add Users"}),", enter your Google email address, and save."]})},{text:t.jsxs(t.Fragment,{children:["For Application type, choose ",t.jsx("strong",{children:"Desktop app"})," (not Web application). Give it any name."]})},{text:t.jsxs(t.Fragment,{children:["Click ",t.jsx("strong",{children:"Create"}),", then copy the ",t.jsx("strong",{children:"Client ID"})," and ",t.jsx("strong",{children:"Client Secret"})," and paste them below."]})}];return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-3",children:[t.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"How to get your Google credentials"}),t.jsx("ol",{className:"space-y-2.5",children:g.map((O,b)=>t.jsxs("li",{className:"flex gap-2.5 text-xs text-text-2 font-sans leading-relaxed",children:[t.jsxs("span",{className:"text-accent font-mono font-bold flex-shrink-0 w-4 text-right",children:[b+1,"."]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("span",{children:O.text}),O.link&&t.jsxs("a",{href:O.link.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-2xs text-accent font-sans hover:underline mt-0.5",children:[t.jsx(Gs,{size:9}),O.link.label]}),O.copyable&&t.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[t.jsx("code",{className:"flex-1 min-w-0 text-2xs font-mono text-accent bg-surface-4 px-2.5 py-1.5 rounded select-all break-all",children:O.copyable}),t.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(O.copyable)},className:"flex-shrink-0 p-1.5 rounded text-text-3 hover:text-accent hover:bg-accent/10 transition-colors cursor-pointer",title:"Copy to clipboard",children:t.jsx(za,{size:12})})]})]})]},b))})]}),t.jsx("div",{className:"bg-accent/8 border border-accent/15 rounded-md px-4 py-2.5",children:t.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[t.jsx("strong",{className:"text-text-1",children:"One-time setup"})," — these same credentials work for Gmail, Calendar, Drive, Docs, Sheets, and Slides. You only need to do this once. For each integration, just enable the matching API in your Google Cloud project."]})}),t.jsx("div",{className:"bg-warning/8 border border-warning/15 rounded-md px-4 py-2.5",children:t.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[t.jsx("strong",{className:"text-text-1",children:'Google "unverified app" warning'})," — when signing in, Google may show a warning that the app isn't verified. This is normal for personal OAuth apps. Click ",t.jsx("strong",{children:"Advanced"}),", then ",t.jsx("strong",{children:"Go to [your app name] (unsafe)"})," to continue. Your credentials stay local and are never sent to Groove servers."]})}),t.jsx("div",{className:"h-px bg-border-subtle"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[t.jsx(yi,{size:11,className:"text-text-4"}),"Client ID ",t.jsx("span",{className:"text-danger",children:"*"})]}),t.jsx(XO,{value:a,onChange:r,placeholder:"123456789.apps.googleusercontent.com",disabled:A})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[t.jsx(yi,{size:11,className:"text-text-4"}),"Client Secret ",t.jsx("span",{className:"text-danger",children:"*"})]}),t.jsx(XO,{value:l,onChange:c,placeholder:"GOCSPX-...",disabled:A})]})]}),t.jsx(ge,{variant:"primary",size:"lg",onClick:h,disabled:A||!a.trim()||!l.trim(),className:"w-full gap-2",children:A?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:14,className:"animate-spin"})," Saving..."]}):"Save Credentials"})]})}function Qte({item:e,status:s,onDone:n,onRefreshStatus:a}){var N;const r=la(),[l,c]=p.useState(!1),[A,f]=p.useState(null),m=e.authType,h=m==="google-autoauth"||m==="oauth-google";p.useEffect(()=>{h&&G.get("/integrations/google-oauth/status").then(Q=>f(Q.configured)).catch(()=>f(!1))},[h]);const g=p.useRef(null);p.useEffect(()=>()=>{g.current&&clearInterval(g.current)},[]);async function O(){c(!0);try{const Q=await G.post(`/integrations/${e.id}/oauth/start`);if(Q.url){const S=await aS(Q.url);if(S!=null&&S.error){r.error("Sign-in failed",S.error),c(!1);return}r.success("Browser opened — complete sign-in there");let C=0;g.current&&clearInterval(g.current),g.current=setInterval(async()=>{if(C+=2e3,C>6e4){clearInterval(g.current),g.current=null,c(!1);return}try{const k=await G.get(`/integrations/${e.id}/status`);((k==null?void 0:k.envKeys)||[]).some(T=>T.key==="GOOGLE_REFRESH_TOKEN"&&T.set)&&(clearInterval(g.current),g.current=null,r.success("Connected!",`${e.name} is now authenticated`),a(),c(!1))}catch{}},2e3)}}catch(Q){r.error("Sign-in failed",Q.message),c(!1)}}const b=(s==null?void 0:s.envKeys)||[],v=b.filter(Q=>Q.required&&!Q.hidden),w=v.length===0||v.every(Q=>Q.set);return t.jsxs("div",{className:"px-5 py-5 space-y-5",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Dl,{item:e,size:36}),t.jsxs("div",{children:[t.jsxs("h2",{className:"text-sm font-bold text-text-0 font-sans",children:["Configure ",e.name]}),t.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Set up credentials to connect"})]})]}),((N=e.setupSteps)==null?void 0:N.length)>0&&!(h&&A===!1)&&t.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[t.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Setup guide"}),t.jsx("ol",{className:"space-y-1.5",children:e.setupSteps.map((Q,S)=>t.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[t.jsxs("span",{className:"text-text-4 font-mono flex-shrink-0 w-4 text-right",children:[S+1,"."]}),t.jsx("span",{children:Q})]},S))}),e.setupUrl&&t.jsxs("a",{href:e.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-accent font-sans hover:underline mt-1",children:[t.jsx(Gs,{size:11}),new URL(e.setupUrl).hostname]})]}),!(h&&A===!1)&&t.jsx("div",{className:"h-px bg-border-subtle"}),m==="api-key"&&t.jsx("div",{className:"space-y-4",children:b.filter(Q=>!Q.hidden).map(Q=>t.jsx(vte,{integrationId:e.id,envKey:Q,onSaved:a},Q.key))}),h&&A===!1&&t.jsx(j4,{integrationId:e.id,onConfigured:()=>f(!0)}),h&&A&&t.jsxs("div",{className:"space-y-3",children:[t.jsx(ge,{variant:"primary",size:"lg",onClick:O,disabled:l,className:"w-full gap-2",children:l?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:14,className:"animate-spin"}),"Opening browser..."]}):t.jsxs(t.Fragment,{children:[t.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),t.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["A browser window will open — sign in and allow access to your ",e.name]}),t.jsx("button",{type:"button",onClick:()=>f(!1),className:"w-full text-2xs text-text-4 font-sans hover:text-text-2 transition-colors cursor-pointer py-1",children:"Reconfigure Google OAuth credentials"})]}),h&&A===null&&t.jsx("div",{className:"flex justify-center py-3",children:t.jsx(Ie,{size:16,className:"animate-spin text-text-4"})}),t.jsx(ge,{variant:w?"primary":"secondary",size:"lg",onClick:n,className:"w-full gap-1.5",children:w?t.jsxs(t.Fragment,{children:[t.jsx(Je,{size:14}),"Done"]}):"Skip for now"})]})}function Ste({item:e,onClose:s}){return t.jsxs("div",{className:"px-5 py-10 flex flex-col items-center text-center space-y-4",children:[t.jsx("div",{className:"w-14 h-14 rounded-full bg-success/15 flex items-center justify-center",children:t.jsx(Ma,{size:28,className:"text-success"})}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:"Integration ready"}),t.jsxs("p",{className:"text-sm text-text-3 font-sans mt-1",children:[e.name," is installed and configured. Agents can now use it."]})]}),t.jsx(ge,{variant:"primary",size:"lg",onClick:s,className:"mt-2",children:"Close"})]})}function Q4({integration:e,open:s,onClose:n}){const a=la(),[r,l]=p.useState("overview"),[c,A]=p.useState(null),[f,m]=p.useState(!1),[h,g]=p.useState(!0),O=e==null?void 0:e.id,b=p.useCallback(async()=>{if(O){try{const C=await G.get(`/integrations/${O}/status`);A(C)}catch{A(null)}g(!1)}},[O]);p.useEffect(()=>{s&&e&&(l("overview"),g(!0),b())},[s,e,b]);function v(){l("agent-setup")}async function w(){try{await G.delete(`/integrations/${e.id}`),a.success(`${e.name} uninstalled`),await b()}catch(C){a.error("Uninstall failed",C.message)}}function N(){l("configure")}function Q(){l("done")}if(!e)return null;const S={overview:e.name,"agent-setup":"Install",configure:"Configure",done:"Complete"};return t.jsx(_t,{open:s,onOpenChange:C=>{C||n()},children:t.jsx(zt,{title:S[r]||e.name,description:`Setup wizard for ${e.name}`,className:"max-w-md",children:h?t.jsx("div",{className:"px-5 py-10 flex items-center justify-center",children:t.jsx(Ie,{size:20,className:"animate-spin text-text-4"})}):r==="overview"?t.jsx(yte,{item:e,status:c,installing:f,onInstall:v,onUninstall:w,onNext:N}):r==="agent-setup"?t.jsx(wte,{item:e,onClose:n}):r==="configure"?t.jsx(Qte,{item:e,status:c,onDone:Q,onRefreshStatus:b}):t.jsx(Ste,{item:e,onClose:n})})})}const Nte=["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"];function Bte({item:e,status:s,onInstall:n,onUninstall:a,busy:r}){const l=s==null?void 0:s.installed,c=s==null?void 0:s.authenticated;return t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-2 border border-border-subtle",children:[t.jsx(Dl,{item:e,size:32}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans",children:e.name}),t.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:e.description})]}),l&&c&&!(s!=null&&s.needsReauth)&&t.jsxs(ke,{variant:"success",className:"text-2xs flex-shrink-0 gap-1",children:[t.jsx(Je,{size:8})," Ready"]}),l&&c&&(s==null?void 0:s.needsReauth)&&t.jsxs(ke,{variant:"warning",className:"text-2xs flex-shrink-0 gap-1",children:[t.jsx(Ks,{size:8})," Update"]}),l&&!c&&t.jsx(ke,{variant:"warning",className:"text-2xs flex-shrink-0",children:"Needs sign-in"}),t.jsx(ge,{variant:l?"ghost":"primary",size:"sm",onClick:()=>l?a(e.id):n(e.id),disabled:r===e.id,className:l?"text-text-3 hover:text-danger":"",children:r===e.id?t.jsx(Ie,{size:12,className:"animate-spin"}):l?t.jsx(qt,{size:12}):"Install"})]})}function Cte({integrations:e,open:s,onClose:n}){const a=la(),[r,l]=p.useState(null),[c,A]=p.useState({}),[f,m]=p.useState(null),[h,g]=p.useState(!1),[O,b]=p.useState(!0),v=p.useRef(null),w=e.filter(T=>Nte.includes(T.id)),N=p.useCallback(async()=>{const T={};await Promise.all(w.map(async $=>{try{T[$.id]=await G.get(`/integrations/${$.id}/status`)}catch{T[$.id]=null}})),A(T),b(!1)},[w.map(T=>T.id).join(",")]);p.useEffect(()=>(s&&(b(!0),G.get("/integrations/google-oauth/status").then(T=>l(T.configured)).catch(()=>l(!1)),N()),()=>{v.current&&clearInterval(v.current)}),[s]);const Q=Object.entries(c).filter(([,T])=>T==null?void 0:T.installed).map(([T])=>T),S=Q.length>0&&Q.every(T=>{var $;return($=c[T])==null?void 0:$.authenticated});Q.some(T=>{var $;return!(($=c[T])!=null&&$.authenticated)});const C=S&&Q.some(T=>{var $;return($=c[T])==null?void 0:$.needsReauth});async function k(T){var $;m(T);try{await G.post(`/integrations/${T}/install`),a.success(`${($=w.find(M=>M.id===T))==null?void 0:$.name} installed`),await N()}catch(M){a.error("Install failed",M.message)}m(null)}async function F(T){var $;m(T);try{await G.delete(`/integrations/${T}`),a.success(`${($=w.find(M=>M.id===T))==null?void 0:$.name} removed`),await N()}catch(M){a.error("Uninstall failed",M.message)}m(null)}async function B(){if(!Q.length){a.error("Install at least one service first");return}g(!0);try{const T=await G.post("/integrations/google-workspace/oauth/start",{integrationIds:Q});if(T.url){const $=await aS(T.url);if($!=null&&$.error){a.error("Sign-in failed",$.error),g(!1);return}a.success("Browser opened — complete sign-in there"),v.current&&clearInterval(v.current),v.current=setInterval(async()=>{await N()},3e3),setTimeout(()=>{v.current&&clearInterval(v.current)},18e4)}}catch(T){a.error("Sign-in failed",T.message)}g(!1)}return p.useEffect(()=>{S&&v.current&&(clearInterval(v.current),v.current=null)},[S]),s?t.jsx(_t,{open:s,onOpenChange:T=>{T||n()},children:t.jsx(zt,{title:"Google Workspace",description:"Connect your Google services",className:"max-w-md",children:t.jsxs("div",{className:"px-5 py-5 space-y-5",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-11 h-11 rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0",children:t.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"Google",className:"w-6 h-6"})}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Google Workspace"}),t.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"One set of credentials for all Google services"})]})]}),r===!1&&t.jsx(j4,{integrationId:"gmail",onConfigured:()=>l(!0)}),r===null&&t.jsx("div",{className:"flex justify-center py-3",children:t.jsx(Ie,{size:16,className:"animate-spin text-text-4"})}),r&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans",children:"Services"}),t.jsx("div",{className:"space-y-1.5",children:O?Array.from({length:4}).map((T,$)=>t.jsx("div",{className:"h-14 rounded-md bg-surface-2 animate-pulse"},$)):w.map(T=>t.jsx(Bte,{item:T,status:c[T.id],onInstall:k,onUninstall:F,busy:f},T.id))})]}),t.jsx("div",{className:"h-px bg-border-subtle"}),Q.length>0&&!S&&t.jsxs("div",{className:"space-y-3",children:[t.jsx(ge,{variant:"primary",size:"lg",onClick:B,disabled:h,className:"w-full gap-2",children:h?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:14,className:"animate-spin"})," Opening browser..."]}):t.jsxs(t.Fragment,{children:[t.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),t.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["Connects ",Q.length," service",Q.length!==1?"s":""," with one sign-in"]})]}),S&&Q.length>0&&t.jsxs("div",{className:"flex flex-col items-center text-center gap-2 py-2",children:[t.jsx("div",{className:"w-10 h-10 rounded-full bg-success/15 flex items-center justify-center",children:t.jsx(Ma,{size:20,className:"text-success"})}),t.jsx("p",{className:"text-sm font-medium text-success font-sans",children:"All services connected"}),t.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Your agents can now use these Google integrations."}),C?t.jsxs("div",{className:"w-full space-y-2 pt-2",children:[t.jsx("p",{className:"text-2xs text-warning font-sans",children:"New permissions available — re-authenticate to enable all features."}),t.jsx(ge,{variant:"secondary",size:"sm",onClick:B,disabled:h,className:"w-full gap-2",children:h?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:12,className:"animate-spin"})," Opening browser..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Ks,{size:12})," Re-authenticate"]})})]}):t.jsx("button",{onClick:B,disabled:h,className:"text-2xs text-text-4 hover:text-text-2 font-sans underline underline-offset-2 transition-colors mt-1",children:h?"Opening browser...":"Re-authenticate"})]}),Q.length===0&&!O&&t.jsx("p",{className:"text-xs text-text-4 font-sans text-center py-2",children:"Install at least one service above, then connect with Google."})]}),t.jsx(ge,{variant:"secondary",size:"lg",onClick:n,className:"w-full",children:S&&Q.length>0?"Done":"Close"})]})})}):null}const Tg=/github\.com\/([^/]+)\/([^/\s#?]+)/;function kte(){const[e,s]=p.useState("input"),[n,a]=p.useState(""),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,m]=p.useState("standalone"),[h,g]=p.useState(""),[O,b]=p.useState(!0),[v,w]=p.useState(""),N=U(T=>T.previewRepo),Q=U(T=>T.importRepo),S=U(T=>T.importInProgress),C=la(),k=p.useCallback(async T=>{const $=T.match(Tg);if($){l(!0);try{const M=await N(T);A(M),w(M.name||$[2]),s("preview")}catch(M){C.error("Preview failed",M.message)}finally{l(!1)}}},[N,C]),F=p.useCallback(T=>{const $=T.target.value;a($),Tg.test($)&&e==="input"&&k($)},[e,k]),B=p.useCallback(async()=>{if(!c)return;let T;f==="standalone"?T=`~/Projects/${c.name}`:f==="subdirectory"?T=`./packages/${c.name}`:T=h;try{await Q(n,T,O,v),C.success(`Importing ${c.name}`,"Setup agent will handle the rest"),s("input"),a(""),A(null)}catch($){C.error("Import failed",$.message)}},[c,f,h,n,O,v,Q,C]);if(e==="input")return t.jsxs("div",{className:"relative",children:[t.jsx(Ms,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),t.jsx("input",{type:"text",value:n,onChange:F,placeholder:"Paste a GitHub URL...",className:V("w-full h-9 rounded-lg pl-9 pr-20 text-sm font-sans","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors duration-100")}),t.jsx(ge,{variant:"primary",size:"sm",className:"absolute right-1.5 top-1/2 -translate-y-1/2",onClick:()=>k(n),disabled:!Tg.test(n)||r,children:r?t.jsx(Ie,{size:12,className:"animate-spin"}):"Preview"})]});if(e==="preview"&&c)return t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-5",children:t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/8 flex items-center justify-center flex-shrink-0",children:t.jsx(Il,{size:22,className:"text-accent"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[t.jsx("span",{className:"text-lg font-bold text-text-0 font-sans",children:c.name}),t.jsx("span",{className:"text-xs text-text-4 font-sans",children:c.owner})]}),t.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[c.language&&t.jsx(ke,{variant:"outline",className:"text-2xs",children:c.language}),c.stars!=null&&t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(kb,{size:10,className:"text-warning",fill:"currentColor"}),Qt(c.stars)]}),c.license&&t.jsx("span",{children:c.license})]})]}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[t.jsxs(ge,{variant:"primary",size:"sm",onClick:()=>s("configure"),className:"h-8 text-xs gap-1.5 px-4",children:[t.jsx(Vs,{size:13}),"Clone & Setup"]}),t.jsxs(ge,{variant:"ghost",size:"sm",onClick:()=>{try{const T=n.startsWith("http")?n:`https://${n}`,$=new URL(T);($.protocol==="https:"||$.protocol==="http:")&&window.open(T,"_blank")}catch{}},className:"h-8 text-xs gap-1.5",children:[t.jsx(Gs,{size:12}),"GitHub"]}),t.jsx("button",{onClick:()=>{s("input"),A(null)},className:"text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 ml-1",children:"Cancel"})]})]})}),c.description&&t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[t.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2",children:"About"}),t.jsx("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:c.description})]}),c.readmePreview&&t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[t.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-3",children:"README"}),t.jsx("div",{className:"text-sm text-text-2 font-sans leading-relaxed whitespace-pre-wrap",children:c.readmePreview})]})]});if(e==="configure"&&c){const T=[{id:"standalone",icon:ad,title:"Standalone project",description:"Clone to its own directory, separate from this workspace",path:`~/Projects/${c.name}`},{id:"subdirectory",icon:Nb,title:"Workspace package",description:"Add as a package inside this project's monorepo",path:`./packages/${c.name}`},{id:"custom",icon:$M,title:"Custom location",description:"Choose your own path",path:null}];return t.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-2 overflow-hidden",children:[t.jsx("div",{className:"px-5 py-4 border-b border-border-subtle bg-surface-3/50",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0",children:t.jsx(Zs,{size:16,className:"text-accent"})}),t.jsxs("div",{children:[t.jsxs("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:["Clone ",c.name]}),t.jsxs("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:[c.owner,"/",c.name," — configure where to install"]})]})]})}),t.jsxs("div",{className:"px-5 py-4 space-y-5",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2.5 block",children:"Install location"}),t.jsx("div",{className:"space-y-2",children:T.map($=>{const M=$.icon,I=f===$.id;return t.jsx("button",{onClick:()=>m($.id),className:V("w-full text-left rounded-lg border p-3.5 transition-all duration-150 cursor-pointer",I?"border-accent bg-accent/5 ring-1 ring-accent/30":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-1/80"),children:t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:V("w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0 mt-0.5",I?"bg-accent/15 text-accent":"bg-surface-3 text-text-4"),children:t.jsx(M,{size:15})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:V("text-xs font-semibold font-sans",I?"text-text-0":"text-text-2"),children:$.title}),I&&t.jsx("div",{className:"w-4 h-4 rounded-full bg-accent flex items-center justify-center",children:t.jsx(Je,{size:10,className:"text-white"})})]}),t.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5 leading-relaxed",children:$.description}),$.path&&I&&t.jsx("code",{className:"text-2xs text-accent/80 font-mono mt-1.5 block truncate",children:$.path})]})]})},$.id)})}),f==="custom"&&t.jsx("div",{className:"mt-2.5 ml-11",children:t.jsx("input",{value:h,onChange:$=>g($.target.value),placeholder:"/path/to/clone",autoFocus:!0,className:V("w-full h-9 px-3 text-xs font-mono rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]}),t.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-3 flex items-center justify-center",children:t.jsx(Fn,{size:14,className:"text-text-4"})}),t.jsxs("div",{children:[t.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans block",children:"Create a team"}),t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Organize agents working on this repo into their own team"})]})]}),t.jsx("button",{onClick:()=>b(!O),className:V("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer flex-shrink-0",O?"bg-accent":"bg-surface-5"),children:t.jsx("div",{className:V("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",O?"translate-x-4":"translate-x-0")})})]}),O&&t.jsx("div",{className:"mt-2.5 ml-11",children:t.jsx("input",{value:v,onChange:$=>w($.target.value),placeholder:"Team name",className:V("w-full h-9 px-3 text-xs font-sans rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]})]}),t.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle bg-surface-3/30 flex items-center justify-between",children:[t.jsxs("button",{onClick:()=>s("preview"),className:"flex items-center gap-1.5 text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 transition-colors",children:[t.jsx(nN,{size:11}),"Back"]}),t.jsx(ge,{variant:"primary",size:"sm",onClick:B,disabled:S||f==="custom"&&!h.trim(),className:"h-8 text-xs gap-1.5 px-5",children:S?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:12,className:"animate-spin"})," Importing..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Zs,{size:12})," Clone & Setup"]})})]})]})}return null}function Tte({repo:e,onRemove:s,onNuke:n,onOpen:a}){return t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-3 flex items-center gap-3",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:e.repoName||e.name}),t.jsx("span",{className:"text-2xs text-text-3 font-sans",children:e.repoOwner||e.owner})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.language&&t.jsx(ke,{variant:"outline",className:"text-2xs",children:e.language}),t.jsx("span",{className:"text-2xs text-text-4 font-mono truncate max-w-[180px]",children:e.clonedTo||e.path})]}),t.jsx("span",{className:"text-2xs text-text-4 font-sans mt-0.5 block",children:e.clonedAt?`Imported ${ls(e.clonedAt)}`:e.status||""})]}),t.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a&&t.jsxs("button",{onClick:()=>a(e),className:V("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-accent bg-accent/10 hover:bg-accent/20 border-0 transition-colors"),children:[t.jsx(Vs,{size:11}),"Open"]}),s&&t.jsxs("button",{onClick:()=>s(e),className:V("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-text-3 hover:text-text-1 hover:bg-surface-4 bg-transparent border-0 transition-colors"),children:[t.jsx(qt,{size:11}),"Remove"]}),n&&t.jsxs("button",{onClick:()=>n(e),className:V("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-danger bg-danger/10 hover:bg-danger/20 border-0 transition-colors"),children:[t.jsx(b$,{size:11}),"Nuke"]})]})]})}function Ute({repo:e,open:s,onClose:n,onConfirm:a}){var h,g,O;const[r,l]=p.useState(!0);if(!e)return null;const c=((h=e.agents)==null?void 0:h.length)||0,A=((g=e.processes)==null?void 0:g.length)||0,f=((O=e.credentialKeys)==null?void 0:O.length)||0,m=e.fileCount||0;return t.jsx(_t,{open:s,onOpenChange:b=>{b||n()},children:t.jsx(zt,{title:`Nuke ${e.repoName||e.name}?`,description:"Confirm destructive removal of imported repo",children:t.jsxs("div",{className:"px-5 py-4 space-y-4",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(sa,{size:16,className:"text-danger flex-shrink-0 mt-0.5"}),t.jsx("p",{className:"text-sm text-text-1 font-sans",children:"This cannot be undone."})]}),t.jsxs("div",{className:"space-y-1.5 text-xs text-text-2 font-sans",children:[c>0&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-success",children:"✓"})," Kill ",c," agent",c!==1?"s":""]}),A>0&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-success",children:"✓"})," Stop ",A," process",A!==1?"es":""]}),f>0&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-success",children:"✓"})," Remove ",f," credential",f!==1?"s":""]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-success",children:"✓"}),' Delete team "',e.teamId||e.repoName||e.name,'"']}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-success",children:"✓"})," Clean all .groove state"]})]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:b=>l(b.target.checked),className:"accent-[var(--color-danger)]"}),t.jsxs("span",{className:"text-xs text-text-1 font-sans",children:["Delete repo files",m>0?` (${m} files)`:""]})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(ge,{variant:"danger",size:"sm",onClick:()=>a(r),children:"Nuke Everything"}),t.jsx(ge,{variant:"ghost",size:"sm",onClick:n,children:"Cancel"})]})]})})})}function Ete({skill:e,onBack:s}){var F,B,T;const n=la(),[a,r]=p.useState(""),[l,c]=p.useState(!1),[A,f]=p.useState(!1),[m,h]=p.useState(!1),[g,O]=p.useState(!1),[b,v]=p.useState(e.installed),[w,N]=p.useState(!0);p.useEffect(()=>{N(!0),G.get(`/skills/${e.id}/content`).then($=>{r($.content||""),c($.requiresPurchase||!1)}).catch(()=>{}).finally(()=>N(!1))},[e.id]);async function Q(){f(!0);try{await G.post(`/skills/${e.id}/install`),v(!0),n.success(`${e.name} installed`)}catch($){n.error("Install failed",$.message)}f(!1)}async function S(){h(!0);try{await G.post(`/skills/${e.id}/update`),n.success(`${e.name} updated to latest`);const $=await G.get(`/skills/${e.id}/content`);$.content&&r($.content)}catch($){n.error("Update failed",$.message)}h(!1)}async function C(){O(!0);try{await G.delete(`/skills/${e.id}`),v(!1),n.success(`${e.name} uninstalled`)}catch($){n.error("Uninstall failed",$.message)}O(!1)}async function k(){const{marketplaceAuthenticated:$,marketplaceLogin:M,marketplaceCheckout:I}=U.getState();if(!$){M();return}try{await I(e.id)}catch{}}return t.jsx(bt,{className:"h-full",children:t.jsxs("div",{className:"px-6 py-5",children:[t.jsxs("button",{onClick:s,className:"flex items-center gap-1 text-xs text-text-3 font-sans hover:text-text-0 cursor-pointer bg-transparent border-0 mb-4",children:[t.jsx(Ei,{size:14})," Back"]}),t.jsxs("div",{className:"flex gap-8",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"w-11 h-11 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-[22px]",children:e.icon||((B=(F=e.name)==null?void 0:F[0])==null?void 0:B.toUpperCase())}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:e.name}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-text-3 font-sans",children:[t.jsx("span",{children:e.author||"Community"}),(e.source==="claude-official"||e.verified)&&t.jsx(gte,{type:e.source,size:13})]})]})]}),t.jsx("p",{className:"mt-3 text-sm text-text-2 font-sans leading-relaxed",children:e.description}),((T=e.tags)==null?void 0:T.length)>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:e.tags.map($=>t.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:$},$))}),t.jsx("div",{className:"h-px bg-border-subtle my-5"}),w?t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"h-3 w-48 bg-surface-4 rounded animate-pulse"}),t.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),t.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}):a?t.jsxs("div",{className:"text-sm text-text-2 font-sans leading-relaxed",children:[t.jsx("h2",{className:"text-sm font-semibold text-text-0 mb-2",children:"About"}),t.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:a})]}):l?t.jsxs("div",{className:"bg-warning/5 border border-warning/15 rounded-lg px-4 py-3",children:[t.jsx("p",{className:"text-sm text-text-1 font-sans font-medium",children:"Paid skill — purchase to view content"}),t.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Sign in and purchase this skill to access its full instructions."})]}):t.jsx("p",{className:"text-xs text-text-4 font-sans",children:"Content loading failed — check your connection."})]}),t.jsx("div",{className:"w-[240px] flex-shrink-0",children:t.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-lg p-4 sticky top-4",children:[t.jsx(pte,{price:e.price||0,size:"md"}),l&&!b?t.jsxs("button",{onClick:k,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 flex items-center justify-center gap-2 border bg-warning/15 text-warning border-warning/20 hover:bg-warning/25",children:["Buy $",(e.price||0).toFixed(2)]}):b?t.jsxs("div",{className:"mt-3 flex flex-col gap-1.5",children:[t.jsxs("button",{onClick:S,disabled:m,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:[t.jsx(Ks,{size:12,className:m?"animate-spin":""}),m?"Updating...":"Pull Latest"]}),t.jsxs("button",{onClick:C,disabled:g,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-error/10 text-error border-error/20 hover:bg-error/15",children:[t.jsx(qt,{size:12}),g?"Removing...":"Uninstall"]})]}):t.jsx("button",{onClick:Q,disabled:A,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:A?"Installing...":"Install"}),t.jsx("div",{className:"mt-4 flex flex-col gap-2.5",children:[["Downloads",t.jsx("span",{className:"font-mono text-text-0",children:Qt(e.downloads||0)},"d")],["Rating",t.jsx(mte,{rating:e.rating||0,count:e.rating_count||e.ratingCount,size:"sm"},"r")],["Version",t.jsx("span",{className:"font-mono text-text-0",children:e.version||"1.0.0"},"v")],["Category",t.jsx(hte,{label:e.category||"general",variant:e.category||"draft"},"c")],["Source",t.jsx("span",{className:"text-text-0",children:e.source==="claude-official"?"Anthropic":"Community"},"s")]].map(([$,M])=>t.jsxs("div",{className:"flex justify-between items-center text-xs font-sans",children:[t.jsx("span",{className:"text-text-3",children:$}),M]},$))})]})})]})]})})}function Pte({open:e,onClose:s}){const[n,a]=p.useState("new"),[r,l]=p.useState(""),[c,A]=p.useState(""),[f,m]=p.useState(""),[h,g]=p.useState(""),[O,b]=p.useState(""),[v,w]=p.useState(!1),N=U(M=>M.teams),Q=U(M=>M.activeTeamId),S=U(M=>M.createTeam),C=U(M=>M.spawnAgent),k=U(M=>M.setActiveView),F=U(M=>M.selectAgent),B=la();p.useEffect(()=>{e&&(a("new"),l(""),A(Q||""),m(""),g(""),b(""),w(!1))},[e,Q]);async function T(){if(f.trim()){w(!0);try{let M;n==="new"?M=(await S(r.trim()||f.trim())).id:M=c;const I=[`The user wants to integrate the **${f.trim()}** API into their project.`,""];h.trim()&&I.push(`**API Documentation:** ${h.trim()}`),O.trim()&&I.push("**API Key:** The user has provided an API key. Store it securely using environment variables — never hardcode it."),I.push("","Start by:","1. Reviewing the API documentation to understand available endpoints and authentication","2. Asking the user what they want to build with this API","3. Setting up the necessary configuration and authentication","4. Building the integration together","","Ask the user about their project and how they'd like to use this API.");const se=I.join(`
|
|
983
983
|
`),H=await C({role:"fullstack",prompt:se,teamId:M});O.trim()&&await G.post(`/agents/${H.id}/instruct`,{message:`Here is the API key for ${f.trim()}: \`${O.trim()}\`
|
|
984
984
|
|
|
985
985
|
Store this in a .env file as an environment variable. Do not commit it to git.`}).catch(()=>{}),k("agents"),F(H.id),s()}catch(M){B("error","Failed to start integration",M.message),w(!1)}}}const $=f.trim()&&(n==="new"||c);return t.jsx(_t,{open:e,onOpenChange:M=>!M&&s(),children:t.jsx(zt,{title:"New Integration",description:"Set up a custom API integration",children:t.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[t.jsx(Kt,{label:"Integration name",placeholder:"e.g. NASA APOD, Stripe, Twilio…",value:f,onChange:M=>m(M.target.value),autoFocus:!0}),t.jsx(Kt,{label:"Documentation URL",placeholder:"https://api.example.com/docs",value:h,onChange:M=>g(M.target.value)}),t.jsx(Kt,{label:"API key (optional)",placeholder:"sk-...",value:O,onChange:M=>b(M.target.value),mono:!0,type:"password"}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("span",{className:"text-xs font-medium text-text-2 font-sans",children:"Team"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("button",{onClick:()=>a("new"),className:`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-md text-xs font-medium font-sans border transition-colors cursor-pointer ${n==="new"?"border-accent bg-accent/10 text-accent":"border-border bg-surface-0 text-text-2 hover:border-accent/50"}`,children:[t.jsx(At,{size:12}),"New team"]}),t.jsxs("button",{onClick:()=>a("existing"),className:`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-md text-xs font-medium font-sans border transition-colors cursor-pointer ${n==="existing"?"border-accent bg-accent/10 text-accent":"border-border bg-surface-0 text-text-2 hover:border-accent/50"}`,children:[t.jsx(Fn,{size:12}),"Existing team"]})]}),n==="new"?t.jsx(Kt,{placeholder:f?f.trim():"Team name (defaults to integration name)",value:r,onChange:M=>l(M.target.value)}):t.jsxs("select",{value:c,onChange:M=>A(M.target.value),className:"h-8 w-full rounded-md px-3 text-sm font-sans bg-surface-1 border border-border text-text-0 focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent cursor-pointer",children:[t.jsx("option",{value:"",children:"Select a team…"}),N.map(M=>t.jsx("option",{value:M.id,children:M.name},M.id))]})]}),t.jsx(ge,{onClick:T,disabled:!$||v,className:"w-full mt-1",children:v?t.jsxs(t.Fragment,{children:[t.jsx(Ie,{size:14,className:"animate-spin"})," Setting up…"]}):"Go"})]})})})}const wQ=new Set(["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"]);function Fte(){const[e,s]=p.useState([]),[n,a]=p.useState(!0),[r,l]=p.useState(""),[c,A]=p.useState(null),[f,m]=p.useState(!1),[h,g]=p.useState(!1),[O,b]=p.useState(!1),v=()=>{a(!0),G.get(`/integrations/registry?search=${encodeURIComponent(r)}`).then(F=>s(F.integrations||F.items||(Array.isArray(F)?F:[]))).catch(()=>s([])).finally(()=>a(!1))};p.useEffect(()=>{v()},[r]);const w=e.filter(F=>wQ.has(F.id)),N=e.filter(F=>!wQ.has(F.id)),Q=w.filter(F=>F.installed).length;function S(F){A(F),m(!0)}function C(){m(!1),A(null),v()}const k=!r||"google workspace gmail calendar drive docs sheets slides".includes(r.toLowerCase());return t.jsxs(bt,{className:"h-full",children:[t.jsxs("div",{className:"px-5 py-4",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-72",children:t.jsx(w4,{value:r,onChange:l,placeholder:"Search integrations..."})}),t.jsx("div",{className:"flex-1"}),t.jsxs(ge,{variant:"ghost",size:"sm",onClick:()=>b(!0),className:"gap-1 text-xs",children:[t.jsx(At,{size:13}),"New"]}),t.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:N.length+(w.length>0?1:0)})]}),t.jsx("div",{className:"mt-4 grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:n?Array.from({length:6}).map((F,B)=>t.jsx(Ote,{},B)):t.jsxs(t.Fragment,{children:[w.length>0&&k&&t.jsx(vx,{item:{id:"google-workspace",name:"Google Workspace",description:"Gmail, Calendar, Drive, Docs, Sheets, Slides — one sign-in for all",category:"productivity",tags:["google","email","calendar","drive","docs"],verified:"mcp-official",installed:Q>0,_installedCount:Q},onClick:()=>g(!0)},"google-workspace"),N.map(F=>t.jsx(vx,{item:F,onClick:()=>S(F)},F.id))]})}),!n&&N.length===0&&w.length===0&&t.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No integrations found."})]}),t.jsx(Q4,{integration:c,open:f,onClose:C}),t.jsx(Cte,{integrations:e,open:h,onClose:()=>{g(!1),v()}}),t.jsx(Pte,{open:O,onClose:()=>b(!1)})]})}function $te(){const e=U(K=>K.marketplaceAuthenticated),s=U(K=>K.marketplaceLogin),[n,a]=p.useState([]),[r,l]=p.useState([]),[c,A]=p.useState([]),[f,m]=p.useState(!0),[h,g]=p.useState("all"),[O,b]=p.useState(""),[v,w]=p.useState(null),[N,Q]=p.useState(null),[S,C]=p.useState(!1),k=la(),F=p.useRef(null),B=async()=>{const[K,L]=await Promise.all([G.get("/skills/installed").catch(()=>[]),G.get("/integrations/installed").catch(()=>[])]);l(Array.isArray(K)?K:K.skills||[]),A(Array.isArray(L)?L:L.integrations||[])};p.useEffect(()=>{m(!0),Promise.all([e?G.get("/auth/purchases").then(K=>K.purchases||[]).catch(()=>[]):Promise.resolve([]),G.get("/skills/installed").then(K=>Array.isArray(K)?K:K.skills||[]).catch(()=>[]),G.get("/integrations/installed").then(K=>Array.isArray(K)?K:K.integrations||[]).catch(()=>[])]).then(([K,L,E])=>{a(K),l(L),A(E)}).finally(()=>m(!1))},[e]);async function T(K){var E;const L=(E=K.target.files)==null?void 0:E[0];if(L){try{const q=await L.text(),D=L.name.replace(/\.md$/i,"");await G.post("/skills/import",{name:D,content:q}),k.success(`Imported "${D}"`),await B()}catch(q){k.error("Import failed",q.message)}K.target.value=""}}if(v)return t.jsx(Ete,{skill:v,onBack:()=>w(null)});const $=O.toLowerCase(),M=h==="all"||h==="skills"?r.filter(K=>!$||(K.name||K.id||"").toLowerCase().includes($)||(K.description||"").toLowerCase().includes($)):[],I=h==="all"||h==="integrations"?c.filter(K=>!$||(K.name||K.id||"").toLowerCase().includes($)||(K.description||"").toLowerCase().includes($)):[],se=[...M.map(K=>({...K,_type:"skill"})),...I.map(K=>({...K,_type:"integration"}))],H=[{id:"all",label:"All"},{id:"skills",label:"Skills"},{id:"integrations",label:"Integrations"}],ne={all:"No skills or integrations installed yet. Visit the Marketplace to get started.",skills:"No skills installed.",integrations:"No integrations installed."};return f?t.jsx("div",{className:"p-5 space-y-3",children:[...Array(4)].map((K,L)=>t.jsx(Jn,{className:"h-14 rounded-md"},L))}):t.jsxs(bt,{className:"h-full",children:[t.jsxs("div",{className:"px-5 py-4 space-y-5",children:[t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[t.jsx("div",{className:"w-72",children:t.jsx(w4,{value:O,onChange:b,placeholder:"Search library..."})}),t.jsx("div",{className:"flex items-center gap-1",children:H.map(K=>t.jsx("button",{onClick:()=>g(K.id),className:`px-3 py-1.5 text-xs font-semibold font-sans rounded-full cursor-pointer select-none transition-colors ${h===K.id?"bg-accent/15 text-accent border border-accent/25":"text-text-3 hover:text-text-1 border border-transparent hover:border-border-subtle"}`,children:K.label},K.id))}),t.jsx("div",{className:"flex-1"}),t.jsx("input",{ref:F,type:"file",accept:".md",onChange:T,className:"hidden"}),t.jsxs(ge,{variant:"secondary",size:"md",onClick:()=>{var K;return(K=F.current)==null?void 0:K.click()},className:"gap-1.5",children:[t.jsx(SN,{size:13}),"Import .md"]}),t.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:se.length})]}),e&&n.length>0&&t.jsxs("div",{children:[t.jsxs("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[t.jsx(kp,{size:12}),"Purchases (",n.length,")"]}),t.jsx("div",{className:"space-y-1.5",children:n.map(K=>{var L,E;return t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-1 border border-border-subtle",children:[t.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center text-sm flex-shrink-0",children:K.skill_icon||((E=(L=K.skill_name)==null?void 0:L[0])==null?void 0:E.toUpperCase())||"?"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:K.skill_name||K.skill_id}),t.jsxs("div",{className:"text-2xs text-text-4 font-sans",children:["$",(K.amount||0).toFixed(2)," · ",ls(K.created_at)]})]}),t.jsx(ke,{variant:"success",className:"text-2xs flex-shrink-0",children:"Owned"})]},K.id||K.skill_id)})})]}),e&&n.length===0&&t.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[t.jsx(kp,{size:20,className:"mx-auto text-text-4 mb-2"}),t.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No purchases yet"})]}),!e&&t.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[t.jsx(kp,{size:20,className:"mx-auto text-text-4 mb-2"}),t.jsx("p",{className:"text-xs text-text-2 font-sans mb-3",children:"Sign in to see your purchases"}),t.jsxs(ge,{variant:"primary",size:"sm",onClick:s,className:"gap-1.5 mx-auto",children:[t.jsx(pN,{size:12})," Sign in"]})]}),se.length>0?t.jsx("div",{className:"grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:se.map(K=>K._type==="skill"?t.jsx(vx,{item:{...K,installed:!0},onClick:()=>w(K)},`skill-${K.id}`):t.jsx(vx,{item:{...K,installed:!0},onClick:()=>{Q(K),C(!0)},statusBadge:t.jsx(ke,{variant:K.configured?"success":"warning",className:"text-2xs",children:K.configured?"Active":"Not configured"})},`int-${K.id}`))}):t.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:ne[h]})]}),t.jsx(Q4,{integration:N,open:S,onClose:()=>{C(!1),Q(null),B()}})]})}function Rte(){const e=U(m=>m.importedRepos),s=U(m=>m.fetchImportedRepos),n=U(m=>m.softRemoveRepo),a=U(m=>m.hardNukeRepo),r=la(),[l,c]=p.useState(null);p.useEffect(()=>{s()},[]);async function A(m){try{await n(m.id),r.success(`Removed ${m.repoName||m.name}`)}catch(h){r.error("Remove failed",h.message)}}async function f(m){if(l){try{m?await a(l.id):await n(l.id),r.success(`${m?"Nuked":"Removed"} ${l.name||l.repo}`)}catch(h){r.error("Nuke failed",h.message)}c(null)}}return t.jsxs(bt,{className:"h-full",children:[t.jsxs("div",{className:"px-5 py-4 space-y-5",children:[t.jsx(kte,{}),e.length>0&&t.jsxs("div",{children:[t.jsx("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3",children:"Recently Imported"}),t.jsx("div",{className:"space-y-2",children:(Array.isArray(e)?e:[]).map(m=>t.jsx(Tte,{repo:m,onRemove:()=>A(m),onNuke:()=>c(m)},m.id))})]}),e.length===0&&t.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No repos imported yet. Paste a GitHub URL above to get started."})]}),t.jsx(Ute,{repo:l,open:!!l,onClose:()=>c(null),onConfirm:f})]})}function Mte(){const[e,s]=p.useState("integrations"),n=[{id:"integrations",label:"Integrations",icon:en},{id:"github",label:"GitHub",icon:Il},{id:"library",label:"My Library",icon:Nb}];return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-b border-border-subtle",children:t.jsxs("div",{className:"flex items-center px-5 h-11",children:[t.jsx("div",{className:"flex items-center",children:n.map(a=>{const r=a.icon;return t.jsxs("button",{onClick:()=>s(a.id),className:`flex items-center gap-1.5 px-3 py-2.5 text-xs font-semibold font-sans cursor-pointer select-none border-b-2 -mb-px transition-colors ${e===a.id?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"}`,children:[t.jsx(r,{size:12}),a.label]},a.id)})}),t.jsx("div",{className:"flex-1"})]})}),t.jsxs("div",{className:"flex-1 min-h-0",children:[e==="integrations"&&t.jsx(Fte,{}),e==="github"&&t.jsx(Rte,{}),e==="library"&&t.jsx($te,{})]})]})}const Qv=[{label:"Every hour",cron:"0 * * * *",description:"Runs at the start of every hour"},{label:"Every morning",cron:"0 9 * * *",description:"Daily at 9:00 AM"},{label:"Twice daily",cron:"0 9,17 * * *",description:"9:00 AM and 5:00 PM"},{label:"Every weekday",cron:"0 9 * * 1-5",description:"Monday-Friday at 9:00 AM"},{label:"Mon & Thu",cron:"0 9 * * 1,4",description:"Monday and Thursday at 9:00 AM"},{label:"Weekly",cron:"0 9 * * 1",description:"Every Monday at 9:00 AM"},{label:"Monthly",cron:"0 9 1 * *",description:"1st of each month at 9:00 AM"}],Ite=new Map(Qv.map(e=>[e.cron,e.description]));function _te(e){if(!e)return"";const s=e.trim(),n=Ite.get(s);return n||s}const zte=[{name:"minute",min:0,max:59},{name:"hour",min:0,max:23},{name:"day of month",min:1,max:31},{name:"month",min:1,max:12},{name:"day of week",min:0,max:7}];function Lte(e,s){if(e==="*")return null;if(/^\*\/\d+$/.test(e)){const a=parseInt(e.slice(2),10);return a<1||a>s.max?`Invalid step ${a} for ${s.name}`:null}const n=e.split(",");for(const a of n)if(a.includes("-")){const[r,l]=a.split("-").map(Number);if(isNaN(r)||isNaN(l)||r<s.min||l>s.max||r>l)return`Invalid range ${a} for ${s.name} (${s.min}-${s.max})`}else{const r=Number(a);if(isNaN(r)||r<s.min||r>s.max)return`Invalid value ${a} for ${s.name} (${s.min}-${s.max})`}return null}function Dte(e){if(!e||typeof e!="string")return{valid:!1,error:"Expression is required"};const s=e.trim().split(/\s+/);if(s.length!==5)return{valid:!1,error:`Expected 5 fields, got ${s.length}`};for(let n=0;n<5;n++){const a=Lte(s[n],zte[n]);if(a)return{valid:!1,error:a}}return{valid:!0}}function Hte({automation:e}){var B,T,$,M,I,se,H,ne,K,L;const s=U(E=>E.toggleAutomation),n=U(E=>E.deleteAutomation),a=U(E=>E.duplicateAutomation),r=U(E=>E.runAutomation),l=U(E=>E.setEditingAutomation),c=U(E=>E.openAutomationWizard),A=U(E=>E.openDetail),f=U(E=>E.agents),[m,h]=p.useState(!1),g=p.useRef(null);p.useEffect(()=>{if(!m)return;function E(q){g.current&&!g.current.contains(q.target)&&h(!1)}return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[m]);const O=e,b=O.teamConfig||(O.agentConfig?[O.agentConfig]:O.role?[{role:O.role}]:[]),v=((B=O.instructionSource)==null?void 0:B.type)==="inline"?O.instructionSource.content:((T=O.instructionSource)==null?void 0:T.type)==="file"?null:O.prompt||null,w=(($=O.instructionSource)==null?void 0:$.type)==="file"?O.instructionSource.filePath:null,N=((M=O.outputConfig)==null?void 0:M.gatewayIds)||[],Q=O.lastRunStatus||(O.lastRunAt?"completed":null),S=(O.activeAgentIds||[]).map(E=>f.find(q=>q.id===E)).filter(Boolean),C=(I=O.lastRun)!=null&&I.agentId?O.lastRun.agentId.split(",").filter(Boolean):[],k=O.isRunning?[]:C.map(E=>f.find(q=>q.id===E)).filter(Boolean);function F(E){A({type:"agent",agentId:E})}return t.jsxs("div",{className:V("rounded-md border bg-surface-1 overflow-hidden transition-colors",O.enabled?"border-border-subtle":"border-border-subtle/50 opacity-75"),children:[t.jsxs("div",{className:"px-4 py-3 flex items-start gap-3",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans truncate",children:O.name}),t.jsx(ke,{variant:O.enabled?"success":"default",className:"text-2xs flex-shrink-0",children:O.enabled?"Active":"Paused"})]}),O.description&&t.jsx("p",{className:"text-2xs text-text-3 font-sans truncate mt-0.5",children:O.description})]}),t.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[t.jsx("button",{onClick:()=>s(O.id,O.enabled),className:V("p-1.5 rounded transition-colors cursor-pointer",O.enabled?"text-success hover:text-success/80":"text-text-4 hover:text-text-2"),title:O.enabled?"Pause automation":"Enable automation",children:O.enabled?t.jsx(bN,{size:13}):t.jsx(bo,{size:13})}),t.jsxs("div",{ref:g,className:"relative",children:[t.jsx("button",{onClick:()=>h(!m),className:"p-1.5 rounded text-text-4 hover:text-text-2 transition-colors cursor-pointer",children:t.jsx(bb,{size:13})}),m&&t.jsxs("div",{className:"absolute right-0 top-full mt-1 z-50 min-w-[150px] bg-surface-2 border border-border rounded-md shadow-lg py-1",children:[t.jsxs("button",{onClick:()=>{l(O.id),c(),h(!1)},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-5 transition-colors cursor-pointer flex items-center gap-2",children:[t.jsx(Fo,{size:10})," Edit"]}),t.jsxs("button",{onClick:()=>{a(O.id),h(!1)},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-5 transition-colors cursor-pointer flex items-center gap-2",children:[t.jsx(za,{size:10})," Duplicate"]}),t.jsxs("button",{onClick:()=>{r(O.id),h(!1)},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-5 transition-colors cursor-pointer flex items-center gap-2",children:[t.jsx(bo,{size:10})," Run Now"]}),t.jsx("div",{className:"h-px my-1 bg-border-subtle"}),t.jsxs("button",{onClick:()=>{n(O.id),h(!1)},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-danger hover:bg-danger/5 transition-colors cursor-pointer flex items-center gap-2",children:[t.jsx(qt,{size:10})," Delete"]})]})]})]})]}),b.length>0&&t.jsxs("div",{className:"px-4 pb-2 flex items-center gap-1.5 flex-wrap",children:[b.map((E,q)=>t.jsxs(ke,{variant:"default",className:"text-2xs",children:[E.role,E.phase?` P${E.phase}`:""]},q)),((se=O.integrationIds)==null?void 0:se.length)>0&&t.jsxs("span",{className:"text-2xs text-text-4 font-sans ml-1",children:["+",O.integrationIds.length," integrations"]})]}),(v||w)&&t.jsx("div",{className:"px-4 pb-2",children:w?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(Pi,{size:10,className:"text-text-4 flex-shrink-0"}),t.jsx("span",{className:"text-2xs font-mono text-text-3 truncate",children:w})]}):t.jsxs("p",{className:"text-2xs text-text-3 font-sans truncate",children:[t.jsx(Bn,{size:10,className:"inline mr-1 text-text-4"}),v.slice(0,100),v.length>100?"...":""]})}),t.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle bg-surface-0 flex items-center gap-3 flex-wrap",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(va,{size:10,className:"text-text-4"}),t.jsx("span",{className:"text-2xs font-mono text-text-2",children:_te(O.cron)})]}),O.nextRunAt&&t.jsxs("span",{className:"text-2xs font-mono text-text-3",children:["Next: ",ls(O.nextRunAt)]}),O.lastRunAt&&t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsxs("span",{className:"text-2xs font-mono text-text-3",children:["Last: ",ls(O.lastRunAt)]}),t.jsx(ss,{status:Q==="error"?"crashed":Q==="running"?"running":"completed",size:"sm"})]}),!O.lastRunAt&&t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Never run"})]}),(N.length>0||((H=O.outputConfig)==null?void 0:H.filePath)||((ne=O.outputConfig)==null?void 0:ne.customInstructions))&&t.jsxs("div",{className:"px-4 py-1.5 border-t border-border-subtle bg-surface-0 space-y-1",children:[N.length>0&&t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Gateways:"}),t.jsx("span",{className:"text-2xs font-sans text-text-3",children:N.join(", ")})]}),((K=O.outputConfig)==null?void 0:K.filePath)&&t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"File:"}),t.jsx("span",{className:"text-2xs font-mono text-text-3 truncate",children:O.outputConfig.filePath})]}),((L=O.outputConfig)==null?void 0:L.customInstructions)&&t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Custom:"}),t.jsxs("span",{className:"text-2xs font-sans text-text-3 truncate",children:[O.outputConfig.customInstructions.slice(0,80),O.outputConfig.customInstructions.length>80?"...":""]})]})]}),S.length>0&&t.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle bg-surface-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx(ss,{status:"running",size:"sm"}),t.jsx("span",{className:"text-2xs font-sans text-text-2 font-medium",children:"Running"})]}),t.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:S.map(E=>t.jsxs("button",{onClick:()=>F(E.id),className:"flex items-center gap-1.5 px-2 py-1 rounded bg-surface-4 hover:bg-surface-5 transition-colors cursor-pointer group",children:[t.jsx(ss,{status:E.status,size:"sm"}),t.jsx("span",{className:"text-2xs font-sans text-text-1 group-hover:text-text-0",children:E.name||E.role}),t.jsx(Gs,{size:9,className:"text-text-4 group-hover:text-accent"})]},E.id))})]}),!O.isRunning&&k.length>0&&t.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle bg-surface-0",children:[t.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:t.jsx("span",{className:"text-2xs font-sans text-text-3",children:"Last run agents"})}),t.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:k.map(E=>t.jsxs("button",{onClick:()=>F(E.id),className:"flex items-center gap-1.5 px-2 py-1 rounded bg-surface-4 hover:bg-surface-5 transition-colors cursor-pointer group",children:[t.jsx(ss,{status:E.status,size:"sm"}),t.jsx("span",{className:"text-2xs font-sans text-text-2 group-hover:text-text-0",children:E.name||E.role}),t.jsx(Gs,{size:9,className:"text-text-4 group-hover:text-accent"})]},E.id))})]}),t.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle flex items-center gap-3",children:[t.jsxs(ge,{variant:"ghost",size:"sm",onClick:()=>r(O.id),className:"h-6 px-2 text-2xs gap-1",children:[t.jsx(bo,{size:10})," Run Now"]}),t.jsx("div",{className:"flex-1"}),O.lastRunDuration!=null&&t.jsx("span",{className:"text-2xs font-mono text-text-4",children:Ro(O.lastRunDuration/1e3)}),O.lastRunCost!=null&&O.lastRunCost>0&&t.jsx("span",{className:"text-2xs font-mono text-text-4",children:$o(O.lastRunCost)})]})]})}function yx({title:e,icon:s,defaultOpen:n=!1,badge:a,children:r,className:l}){const[c,A]=p.useState(n);return t.jsxs("div",{className:V("border-t border-border-subtle",l),children:[t.jsxs("button",{onClick:()=>A(!c),className:"w-full flex items-center gap-2 px-5 py-3 text-left cursor-pointer hover:bg-surface-5/30 transition-colors group",children:[t.jsx(Ct,{size:12,className:V("text-text-4 transition-transform duration-200 flex-shrink-0",c&&"rotate-90")}),s&&t.jsx(s,{size:13,className:"text-text-3 flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:e}),a&&t.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1.5 py-0.5 rounded",children:a})]}),c&&t.jsx("div",{className:"px-5 pb-4",children:r})]})}const Xte=[{id:"solo",label:"Solo Agent",icon:CN,description:"Single agent for focused tasks"},{id:"dev",label:"Dev Team",icon:eR,description:"Frontend + Backend + QC"},{id:"business",label:"Business Team",icon:N$,description:"CMO + CFO + Analyst"},{id:"custom",label:"Custom",icon:Yl,description:"Build your own team"}],Sv=[{role:"frontend",phase:1},{role:"backend",phase:1},{role:"fullstack",phase:2}],Nv=[{role:"CMO",phase:1},{role:"CFO",phase:1},{role:"analyst",phase:2}],jQ=["chat","planner","backend","frontend","fullstack","testing","devops","docs","security","database","cmo","cfo","ea","support","analyst","creative","slides","ambassador"],Zte={chat:"Chat",planner:"Planner",backend:"Backend",frontend:"Frontend",fullstack:"Fullstack",testing:"Testing",devops:"DevOps",docs:"Docs",security:"Security",database:"Database",cmo:"CMO",cfo:"CFO",ea:"EA",support:"Support",analyst:"Analyst",creative:"Writer",slides:"Slides",ambassador:"Ambassador"};function gf(e){return Zte[e]||e}const Gte=/\[read\]\s*#[\w/.-]+/g;function Vte(e){return e?[...e.matchAll(Gte)].map(s=>s[0]):[]}function S4({text:e}){const s=Vte(e);return s.length===0?null:t.jsx("div",{className:"flex items-center gap-1.5 flex-wrap px-1",children:s.map((n,a)=>t.jsx("span",{className:"text-2xs font-mono text-teal-400",children:n},a))})}const Kte=[{value:"min",label:"minutes"},{value:"hour",label:"hours"},{value:"day",label:"days"},{value:"week",label:"weeks"}],Ug={name:"",description:"",teamType:null,soloRole:"planner",customRoles:[{role:"fullstack",phase:1}],provider:"",model:"",runtimeId:"",instructionMode:"write",instructions:"",filePath:"",cronPreset:null,scheduleMode:"preset",scheduleCount:1,scheduleUnit:"hour",enabledOnCreate:!0,gatewayIds:[],notifyOn:"complete",integrationIds:[],outputFilePath:"",outputCustom:""};function ZO(e,s){const n=parseInt(e,10);if(!n||n<1)return null;switch(s){case"min":return`*/${n} * * * *`;case"hour":return n===1?"0 * * * *":`0 */${n} * * *`;case"day":return n===1?"0 9 * * *":`0 9 */${n} * *`;case"week":return"0 9 * * 1";default:return null}}function qte(e,s){const n=parseInt(e,10);if(!n||n<1)return"";const a={min:"minute",hour:"hour",day:"day",week:"week"};return`Every ${n===1?"":n+" "}${a[s]}${n!==1?"s":""}`}function Wte(e){if(!e)return null;const s=e.trim().split(/\s+/);if(s.length!==5)return null;const[n,a,r,l,c]=s;return n.startsWith("*/")&&a==="*"&&r==="*"&&l==="*"&&c==="*"?{count:parseInt(n.slice(2)),unit:"min"}:n==="0"&&a==="*"&&r==="*"&&l==="*"&&c==="*"?{count:1,unit:"hour"}:n==="0"&&a.startsWith("*/")&&r==="*"&&l==="*"&&c==="*"?{count:parseInt(a.slice(2)),unit:"hour"}:n==="0"&&/^\d+$/.test(a)&&r==="*"&&l==="*"&&c==="*"?{count:1,unit:"day"}:n==="0"&&/^\d+$/.test(a)&&r.startsWith("*/")&&l==="*"&&c==="*"?{count:parseInt(r.slice(2)),unit:"day"}:n==="0"&&/^\d+$/.test(a)&&r==="*"&&l==="*"&&/^\d$/.test(c)?{count:1,unit:"week"}:null}function QQ(e,s){return e.length===s.length&&e.every((n,a)=>{var r,l;return((r=s[a])==null?void 0:r.role)===n.role&&(((l=s[a])==null?void 0:l.phase)||1)===n.phase})}function Yte(e){var g,O,b,v,w,N,Q,S,C,k,F,B,T,$;let s="custom",n="planner",a=[{role:"fullstack",phase:1}];e.agentConfig&&!e.teamConfig?(s="solo",n=e.agentConfig.role||"planner"):e.teamConfig&&(QQ(Sv,e.teamConfig)?s="dev":QQ(Nv,e.teamConfig)?s="business":a=e.teamConfig.map(M=>({role:M.role,phase:M.phase||1})));const r=((g=Qv.find(M=>M.cron===e.cron))==null?void 0:g.cron)||null;let l="preset",c=1,A="hour";if(!r){const M=Wte(e.cron);M&&(l="simple",c=M.count,A=M.unit)}let f=((O=e.agentConfig)==null?void 0:O.provider)||((v=(b=e.teamConfig)==null?void 0:b[0])==null?void 0:v.provider)||"",m=((w=e.agentConfig)==null?void 0:w.model)||((Q=(N=e.teamConfig)==null?void 0:N[0])==null?void 0:Q.model)||"",h="";if(f==="local"&&(m!=null&&m.startsWith("runtime:"))){const M=m.split(":");h=M[1],m=M.slice(2).join(":")}return{name:e.name||"",description:e.description||"",teamType:s,soloRole:n,customRoles:a,provider:f,model:m==="auto"?"":m,runtimeId:h,instructionMode:((S=e.instructionSource)==null?void 0:S.type)==="file"?"file":"write",instructions:((C=e.instructionSource)==null?void 0:C.type)==="inline"&&e.instructionSource.content||"",filePath:((k=e.instructionSource)==null?void 0:k.type)==="file"&&e.instructionSource.filePath||"",cronPreset:r,scheduleMode:l,scheduleCount:c,scheduleUnit:A,enabledOnCreate:e.enabled!==!1,gatewayIds:((F=e.outputConfig)==null?void 0:F.gatewayIds)||[],notifyOn:((B=e.outputConfig)==null?void 0:B.notifyOn)||"complete",integrationIds:e.integrationIds||[],outputFilePath:((T=e.outputConfig)==null?void 0:T.filePath)||"",outputCustom:(($=e.outputConfig)==null?void 0:$.customInstructions)||""}}function Jte(){const e=U(I=>I.automationWizardOpen),s=U(I=>I.closeAutomationWizard),n=U(I=>I.createAutomation),a=U(I=>I.updateAutomation),r=U(I=>I.editingAutomationId),l=U(I=>I.automations),c=U(I=>I.availableGateways),A=U(I=>I.availableIntegrations),f=U(I=>I.fetchGateways),m=U(I=>I.fetchInstalledIntegrations),h=!!r,[g,O]=p.useState(1),[b,v]=p.useState(Ug),[w,N]=p.useState([]),[Q,S]=p.useState([]),C=U(I=>I.labRuntimes),k=U(I=>I.fetchLabRuntimes);p.useEffect(()=>{if(e){if(O(1),r){const I=l.find(se=>se.id===r);v(I?Yte(I):Ug)}else v(Ug);f(),m(),k(),G.get("/providers").then(I=>{var ne;const se=Array.isArray(I)?I:I.providers||[];N(se);const H=se.find(K=>K.id==="local");(ne=H==null?void 0:H.models)!=null&&ne.length&&S(H.models)}).catch(()=>N([])),G.get("/providers/ollama/models").then(I=>{const se=I.installed||[],H=I.catalog||[];(se.length||H.length)&&S(ne=>{const K=new Set(ne.map(E=>E.id)),L=[...ne];for(const E of se)K.has(E.id)||(L.push(E),K.add(E.id));for(const E of H)K.has(E.id)||L.push({id:E.id,name:E.name||E.id});return L})}).catch(()=>{})}},[e]);function F(I){v(se=>({...se,...I}))}function B(){return b.cronPreset?b.cronPreset:ZO(b.scheduleCount,b.scheduleUnit)}function T(){let I=b.provider||void 0,se=b.model||void 0;switch(I==="local"&&b.runtimeId&&se&&(se=`runtime:${b.runtimeId}:${se}`),b.teamType){case"solo":return{agentConfig:{role:b.soloRole,provider:I,model:se}};case"dev":return{teamConfig:Sv.map(H=>({...H,provider:I,model:se}))};case"business":return{teamConfig:Nv.map(H=>({...H,provider:I,model:se}))};case"custom":return{teamConfig:b.customRoles.filter(H=>H.role).map(H=>({...H,provider:I,model:se}))};default:return{}}}function $(){switch(g){case 1:return b.name.trim()&&b.teamType;case 2:return b.instructionMode==="write"?b.instructions.trim():b.filePath.trim();case 3:{if(b.cronPreset)return!0;const I=ZO(b.scheduleCount,b.scheduleUnit);return I&&Dte(I).valid}case 4:return!0;default:return!1}}function M(){const I=B(),se={name:b.name.trim(),description:b.description.trim()||void 0,cron:I,...T(),instructionSource:b.instructionMode==="write"?{type:"inline",content:b.instructions}:{type:"file",filePath:b.filePath},outputConfig:{gatewayIds:b.gatewayIds,notifyOn:b.notifyOn,filePath:b.outputFilePath||void 0,customInstructions:b.outputCustom||void 0},integrationIds:b.integrationIds.length>0?b.integrationIds:void 0,enabled:b.enabledOnCreate};h?(a(r,se),s()):n(se)}return t.jsx(_t,{open:e,onOpenChange:I=>!I&&s(),children:t.jsxs(zt,{title:h?"Edit Automation":"New Automation",description:h?"Update this automation":"Create a scheduled automation",className:"max-w-xl",children:[t.jsx("div",{className:"px-5 py-3 border-b border-border-subtle flex items-center justify-center gap-2",children:[1,2,3,4].map(I=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:V("w-2 h-2 rounded-full transition-colors",I===g?"bg-accent":I<g?"bg-accent/40":"bg-surface-5")}),I<4&&t.jsx("div",{className:V("w-6 h-px",I<g?"bg-accent/40":"bg-surface-5")})]},I))}),t.jsxs("div",{className:"px-5 py-4 min-h-[300px]",children:[g===1&&t.jsx(ese,{form:b,update:F,providers:w,labRuntimes:C||[],localModels:Q}),g===2&&t.jsx(tse,{form:b,update:F}),g===3&&t.jsx(sse,{form:b,update:F}),g===4&&t.jsx(nse,{form:b,update:F,gateways:c,integrations:A})]}),t.jsxs("div",{className:"px-5 py-3 border-t border-border-subtle flex items-center justify-between",children:[t.jsx("div",{children:g>1&&t.jsxs(ge,{variant:"ghost",size:"sm",onClick:()=>O(g-1),className:"gap-1",children:[t.jsx(Ei,{size:12})," Back"]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ge,{variant:"ghost",size:"sm",onClick:s,children:"Cancel"}),g<4?t.jsxs(ge,{variant:"primary",size:"sm",disabled:!$(),onClick:()=>O(g+1),className:"gap-1",children:["Next ",t.jsx(Ct,{size:12})]}):t.jsx(ge,{variant:"primary",size:"sm",disabled:!$(),onClick:M,children:h?"Save":"Create"})]})]})]})})}const SQ={ollama:"Ollama",vllm:"vLLM","llama-cpp":"llama.cpp",mlx:"MLX",tgi:"TGI","openai-compatible":"OpenAI Compatible"};function ese({form:e,update:s,providers:n,labRuntimes:a,localModels:r}){const l=e.provider==="local",c=n.find(m=>m.id===e.provider),A=l?r||[]:(c==null?void 0:c.models)||[],f=l?a.find(m=>m.id===e.runtimeId):null;return t.jsxs("div",{className:"space-y-4",children:[t.jsx(Kt,{label:"Name",placeholder:"Morning briefing",value:e.name,onChange:m=>s({name:m.target.value})}),t.jsx(Kt,{label:"Description (optional)",placeholder:"Check email, calendar, and write a daily summary",value:e.description,onChange:m=>s({description:m.target.value})}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Team Type"}),t.jsx("div",{className:"grid grid-cols-2 gap-2",children:Xte.map(m=>t.jsxs("button",{onClick:()=>s({teamType:m.id}),className:V("flex items-center gap-3 p-3 rounded-md border text-left transition-colors cursor-pointer",e.teamType===m.id?"border-accent bg-accent/5":"border-border-subtle bg-surface-0 hover:border-border hover:bg-surface-2"),children:[t.jsx(m.icon,{size:16,className:V(e.teamType===m.id?"text-accent":"text-text-3")}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans",children:m.label}),t.jsx("div",{className:"text-2xs text-text-3 font-sans",children:m.description})]})]},m.id))})]}),e.teamType==="solo"&&t.jsxs(Cn,{value:e.soloRole,onValueChange:m=>s({soloRole:m}),children:[t.jsx(kn,{placeholder:"Select role"}),t.jsx(Tn,{children:jQ.map(m=>t.jsx(is,{value:m,children:gf(m)},m))})]}),e.teamType==="dev"&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Roles"}),Sv.map((m,h)=>t.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md bg-surface-0 border border-border-subtle",children:[t.jsx(ke,{variant:"default",className:"text-2xs",children:gf(m.role)}),t.jsx("div",{className:"flex-1"}),t.jsxs("span",{className:"text-2xs font-mono text-text-4",children:["Phase ",m.phase]})]},h))]}),e.teamType==="business"&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Roles"}),Nv.map((m,h)=>t.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md bg-surface-0 border border-border-subtle",children:[t.jsx(ke,{variant:"default",className:"text-2xs",children:gf(m.role)}),t.jsx("div",{className:"flex-1"}),t.jsxs("span",{className:"text-2xs font-mono text-text-4",children:["Phase ",m.phase]})]},h))]}),e.teamType==="custom"&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Roles"}),e.customRoles.map((m,h)=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(Cn,{value:m.role,onValueChange:g=>NQ(e,s,h,{role:g}),children:[t.jsx(kn,{placeholder:"Role",className:"flex-1"}),t.jsx(Tn,{children:jQ.map(g=>t.jsx(is,{value:g,children:gf(g)},g))})]}),t.jsxs("button",{onClick:()=>NQ(e,s,h,{phase:m.phase===1?2:1}),className:V("h-8 px-2.5 rounded-md text-2xs font-mono border transition-colors cursor-pointer",m.phase===1?"border-accent/30 text-accent bg-accent/5":"border-border text-text-3 bg-surface-0"),children:["P",m.phase]}),t.jsx("button",{onClick:()=>{const g=e.customRoles.filter((O,b)=>b!==h);s({customRoles:g.length>0?g:[{role:"fullstack",phase:1}]})},className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",children:t.jsx(Ze,{size:12})})]},h)),t.jsxs(ge,{variant:"ghost",size:"sm",onClick:()=>s({customRoles:[...e.customRoles,{role:"fullstack",phase:1}]}),className:"gap-1 text-2xs",children:[t.jsx(At,{size:10})," Add Role"]})]}),e.teamType&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Provider & Model"}),t.jsxs("div",{className:V("grid gap-3",l?"grid-cols-3":"grid-cols-2"),children:[t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:e.provider,onChange:m=>s({provider:m.target.value,model:"",runtimeId:""}),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[t.jsx("option",{value:"",children:"Auto"}),n.filter(m=>m.authType!=="local").map(m=>t.jsxs("option",{value:m.id,disabled:m.authType==="api-key"?!(m.installed&&m.hasKey):!m.installed,children:[m.name,m.installed?m.authType==="api-key"&&!m.hasKey?" (No API key)":"":" (Not installed)"]},m.id)),t.jsx("option",{value:"local",children:"Local Model"})]}),t.jsx(dt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:e.model,onChange:m=>s({model:m.target.value}),disabled:!e.provider,className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent disabled:opacity-40",children:[t.jsx("option",{value:"",children:"Auto"}),A.map(m=>t.jsx("option",{value:m.id,children:m.name||m.id},m.id))]}),t.jsx(dt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),l&&t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:e.runtimeId,onChange:m=>s({runtimeId:m.target.value}),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[t.jsx("option",{value:"",children:"Select runtime"}),a.map(m=>t.jsxs("option",{value:m.id,children:[m.name||SQ[m.type]||m.type,m.status==="connected"?"":" (offline)"]},m.id))]}),t.jsx(dt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),l&&t.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-md bg-warning/8 border border-warning/20",children:[t.jsx(sa,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),t.jsxs("span",{className:"text-2xs font-sans text-text-2",children:["Make sure your runtime",f?` (${f.name||SQ[f.type]||f.type})`:""," is running when this automation fires."]})]}),l&&a.length===0&&t.jsx("div",{className:"flex items-start gap-2 px-3 py-2 rounded-md bg-surface-4 border border-border-subtle",children:t.jsx("span",{className:"text-2xs font-sans text-text-3",children:"No runtimes configured. Set one up in the Model Lab tab first."})})]})]})}function NQ(e,s,n,a){s({customRoles:e.customRoles.map((r,l)=>l===n?{...r,...a}:r)})}function tse({form:e,update:s}){const[n,a]=p.useState(!1);return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"flex gap-1",children:[t.jsx("button",{onClick:()=>s({instructionMode:"write"}),className:V("px-3 py-1.5 text-xs font-sans rounded-md transition-colors cursor-pointer",e.instructionMode==="write"?"bg-accent/10 text-accent border border-accent/30":"text-text-3 border border-border-subtle hover:text-text-1"),children:"Write instructions"}),t.jsx("button",{onClick:()=>s({instructionMode:"file"}),className:V("px-3 py-1.5 text-xs font-sans rounded-md transition-colors cursor-pointer",e.instructionMode==="file"?"bg-accent/10 text-accent border border-accent/30":"text-text-3 border border-border-subtle hover:text-text-1"),children:"Reference a document"})]}),e.instructionMode==="write"?t.jsxs("div",{className:"space-y-2",children:[t.jsx(jv,{mono:!0,value:e.instructions,onChange:r=>s({instructions:r.target.value}),placeholder:`Describe what this team should do...
|