groove-dev 0.27.190 → 0.27.191
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/providers/claude-code.js +1 -0
- package/node_modules/@groove-dev/gui/dist/assets/{index-DXup-n8w.js → index-L8xSnvHj.js} +1 -1
- 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/onboarding/setup-wizard.jsx +1 -1
- package/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/daemon/package.json +1 -1
- package/packages/daemon/src/providers/claude-code.js +1 -0
- package/packages/gui/dist/assets/{index-DXup-n8w.js → index-L8xSnvHj.js} +1 -1
- package/packages/gui/dist/index.html +1 -1
- package/packages/gui/package.json +1 -1
- package/packages/gui/src/components/onboarding/setup-wizard.jsx +1 -1
|
@@ -1009,7 +1009,7 @@ ${I.join(`
|
|
|
1009
1009
|
[&::-moz-range-thumb]:bg-accent [&::-moz-range-thumb]:border-none
|
|
1010
1010
|
[&::-moz-range-thumb]:shadow-[0_0_0_2px_var(--color-surface-1)]
|
|
1011
1011
|
[&::-moz-range-track]:bg-transparent
|
|
1012
|
-
disabled:cursor-not-allowed`})]}),e.jsx("span",{className:"text-[11px] text-accent font-mono font-medium w-9 text-right shrink-0 tabular-nums",children:O})]})}const xee={backend:Ns,frontend:md,fullstack:bn,testing:Wx,security:vn},mee=new Set(["codex","grok","local"]),hee=/^[a-zA-Z0-9_-]{1,64}$/;function pee(t){return t.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,64)}function qf(){var H;const t=k(I=>I.recommendedTeam),s=k(I=>I.launchRecommendedTeam),n=k(I=>I.teamLaunchConfig),a=k(I=>I.fetchProviders),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState([]),[O,b]=p.useState((n==null?void 0:n.provider)||""),[v,y]=p.useState((n==null?void 0:n.model)||""),[S,j]=p.useState((n==null?void 0:n.reasoningEffort)??50),[N,C]=p.useState((n==null?void 0:n.temperature)??.5),[U,P]=p.useState(null);if(p.useEffect(()=>{a().then(I=>{Array.isArray(I)&&g(I.filter(L=>L.installed))}).catch(()=>{})},[]),!((H=t==null?void 0:t.agents)!=null&&H.length))return null;const T=t.agents,B=T.filter(I=>!I.phase||I.phase===1),F=T.filter(I=>I.phase===2),M=c??B.map(I=>({...I,name:I.name||""})),R=h.find(I=>I.id===O),Y=((R==null?void 0:R.models)||[]).filter(I=>I.type!=="image"&&!I.disabled),W=mee.has(O);function ee(I,L){const J=M.map((D,se)=>se===I?{...D,name:pee(L)}:D);A(J)}function K(I,L){if(typeof L=="string"){const[J,D]=[L,arguments[2]];A(se=>(se??M).map((le,V)=>V===I?{...le,[J]:D}:le))}else A(J=>(J??M).map((D,se)=>se===I?{...D,...L}:D))}function _(I){var D;b(I);const L=h.find(se=>se.id===I),J=((L==null?void 0:L.models)||[]).filter(se=>se.type!=="image"&&!se.disabled);y(((D=J[0])==null?void 0:D.id)||"")}async function E(){l(!0),k.setState({teamLaunchConfig:{...O&&{provider:O,model:v},reasoningEffort:S,...W&&{temperature:N}}});try{const I=[...M,...F];await s(I)}catch{}l(!1)}function q(){k.setState({recommendedTeam:null})}return e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 z-50 w-full max-w-lg",children:e.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:[e.jsxs("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center gap-2",children:[e.jsx(Ei,{size:16,className:"text-accent"}),e.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Planner Recommends a Team"}),e.jsx("button",{onClick:q,className:"text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:14})})]}),e.jsxs("div",{className:"border-b border-border-subtle",children:[e.jsxs("button",{onClick:()=>x(!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:[e.jsx(xt,{size:12,className:Z("text-text-4 transition-transform duration-200",!f&&"-rotate-90")}),e.jsx(DS,{size:12,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider",children:"Team Settings"}),O&&e.jsxs("span",{className:"ml-auto text-2xs text-accent font-mono",children:[O,v?` / ${v}`:""]})]}),f&&e.jsxs("div",{className:"px-4 pb-3 space-y-3",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:O,onValueChange:_,children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-4 h-7 text-xs"}),e.jsx(In,{children:h.map(I=>e.jsx(ms,{value:I.id,children:I.displayName||I.name||I.id},I.id))})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:v,onValueChange:y,children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-4 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"auto",children:"Auto"}),Y.map(I=>e.jsx(ms,{value:I.id,children:I.name||I.id},I.id))]})]})]})]}),e.jsx(Ka,{label:"Reasoning",value:S,onChange:j,min:0,max:100,step:1}),W&&e.jsx(Ka,{label:"Temperature",value:N,onChange:C,min:0,max:1,step:.01,formatValue:I=>I.toFixed(2)})]})]}),e.jsxs("div",{className:"px-4 py-3 space-y-1.5",children:[M.map((I,L)=>{var te;const J=xee[I.role]||bn,D=!I.name||hee.test(I.name),se=U===L,le=h.find(ae=>ae.id===(I.provider||O)),V=((le==null?void 0:le.models)||[]).filter(ae=>ae.type!=="image"&&!ae.disabled);return e.jsxs("div",{className:"rounded-md bg-surface-4 border border-border-subtle overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 cursor-pointer hover:bg-surface-5/50 transition-colors",onClick:()=>P(se?null:L),children:[e.jsx(J,{size:12,className:"text-text-2 shrink-0"}),e.jsx("input",{type:"text",value:I.name,onChange:ae=>ee(L,ae.target.value),onClick:ae=>ae.stopPropagation(),placeholder:I.role,className:Z("flex-1 min-w-0 bg-transparent text-xs font-mono text-text-0 outline-none placeholder:text-text-4",!D&&"text-red-400"),maxLength:64,spellCheck:!1}),I.provider&&I.provider!==O&&e.jsx("span",{className:"text-2xs text-accent font-mono shrink-0",children:I.provider}),((te=I.scope)==null?void 0:te.length)>0&&e.jsxs("span",{className:"text-2xs text-text-4 font-mono shrink-0 truncate max-w-[120px]",children:[I.scope[0],I.scope.length>1?` +${I.scope.length-1}`:""]}),e.jsx(xt,{size:10,className:Z("text-text-4 shrink-0 transition-transform duration-200",!se&&"-rotate-90")})]}),se&&e.jsxs("div",{className:"px-2.5 pb-2.5 pt-1 space-y-2.5 border-t border-border-subtle",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(ka,{size:10}),"Provider"]}),e.jsxs(Rn,{value:I.provider||"",onValueChange:ae=>{var oe;const be=h.find(ue=>ue.id===ae),z=((be==null?void 0:be.models)||[]).filter(ue=>ue.type!=="image"&&!ue.disabled);K(L,{provider:ae,model:((oe=z[0])==null?void 0:oe.id)||""})},children:[e.jsx(Mn,{placeholder:"Team default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"",children:"Team default"}),h.map(ae=>e.jsx(ms,{value:ae.id,children:ae.displayName||ae.name||ae.id},ae.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:I.model||"",onValueChange:ae=>K(L,"model",ae),children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"",children:"Auto"}),V.map(ae=>e.jsx(ms,{value:ae.id,children:ae.name||ae.id},ae.id))]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(Ro,{size:10}),"Model Routing"]}),e.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(ae=>e.jsx("button",{onClick:()=>K(L,"routingMode",ae.value),className:Z("flex-1 px-2 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(I.routingMode||"auto")===ae.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:ae.label},ae.value))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(SS,{size:10}),"Effort Level"]}),e.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"},{value:"ultra",label:"Ultra"}].map(ae=>e.jsx("button",{onClick:()=>K(L,"effort",ae.value),className:Z("flex-1 px-1.5 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(I.effort||"default")===ae.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:ae.label},ae.value))})]})]})]},L)}),t.projectDir&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-2 font-mono pt-0.5",children:[e.jsx("span",{className:"text-text-4",children:"Project:"}),e.jsxs("span",{className:"text-accent",children:[t.projectDir,"/"]})]}),F.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans",children:[e.jsx(vn,{size:10}),e.jsxs("span",{children:[F.length," QC agent",F.length>1?"s":""," will auto-spawn after builders complete"]})]})]}),e.jsx("div",{className:"px-4 py-3 border-t border-border-subtle",children:e.jsxs(pe,{variant:"primary",size:"md",onClick:E,disabled:r,className:"w-full gap-2",children:[e.jsx(qt,{size:14}),r?"Launching...":`Launch ${B.length} Agent${B.length>1?"s":""}`]})})]})})}const gee={agentNode:SC,rootNode:CC},Ig=220,zg=82,wf=260,jf=130,po=4,Xs="__groove_root__";function FA(t){if(!t)return{};try{return JSON.parse(localStorage.getItem(`groove:nodePositions:${t}`)||"{}")}catch{return{}}}function B4(){let t=!1;for(const s of["groove:chatHistory","groove:activityLog"])localStorage.getItem(s)!==null&&(localStorage.removeItem(s),t=!0);return t}function QQ(t,s){if(!t)return;const n=`groove:nodePositions:${t}`,a=JSON.stringify(s);try{localStorage.setItem(n,a);return}catch{}if(B4())try{localStorage.setItem(n,a)}catch{}}function k4(){try{return JSON.parse(localStorage.getItem("groove:roleLayout")||"{}")}catch{return{}}}function Oee(t){const s="groove:roleLayout",n=JSON.stringify(t);try{localStorage.setItem(s,n);return}catch{}if(B4())try{localStorage.setItem(s,n)}catch{}}function T4(){try{return JSON.parse(localStorage.getItem("groove:teamViewports")||"{}")}catch{return{}}}function bee(t,s){try{const n=T4();n[t]=s,localStorage.setItem("groove:teamViewports",JSON.stringify(n))}catch{}}function vee(t,s){const n=t.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 yee(){const t=k(E=>E.teams),s=k(E=>E.activeTeamId),n=k(E=>E.agents),a=k(E=>E.switchTeam),r=k(E=>E.createTeam),l=k(E=>E.deleteTeamPermanently),c=k(E=>E.renameTeam),A=k(E=>E.cloneTeam),f=k(E=>E.reorderTeams),x=k(E=>E.addToast),[h,g]=p.useState(!1),[O,b]=p.useState(""),[v,y]=p.useState(null),[S,j]=p.useState(""),N=p.useRef(!1),[C,U]=p.useState(null),[P,T]=p.useState(null),B=p.useRef(null),[F,M]=p.useState(!1),[R,Y]=p.useState(!1),W=p.useCallback(()=>{const E=B.current;E&&(M(E.scrollLeft>0),Y(E.scrollLeft+E.clientWidth<E.scrollWidth-1))},[]);p.useEffect(()=>{const E=B.current;if(!E)return;W(),E.addEventListener("scroll",W);const q=new ResizeObserver(W);return q.observe(E),()=>{E.removeEventListener("scroll",W),q.disconnect()}},[W,t.length]);function ee(){const E=O.trim();!E||N.current||(N.current=!0,b(""),g(!1),r(E).finally(()=>{N.current=!1,setTimeout(()=>{B.current&&B.current.scrollTo({left:B.current.scrollWidth,behavior:"smooth"})},100)}))}function K(E){y(E.id),j(E.name)}function _(){const E=S.trim();if(!E||!v){y(null);return}c(v,E),y(null)}return e.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:[F&&e.jsx("button",{onClick:()=>{var E;return(E=B.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:e.jsx(Di,{size:14})}),e.jsxs("div",{ref:B,className:"flex items-end flex-1 min-w-0 overflow-x-auto gap-0",style:{scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch"},children:[t.map(E=>{const q=n.filter(J=>{var D;return J.teamId===E.id&&!((D=J.metadata)!=null&&D.scheduled)}).length,H=E.id===s,I=v===E.id,L=n.filter(J=>{var D;return J.teamId===E.id&&!((D=J.metadata)!=null&&D.scheduled)&&(J.status==="running"||J.status==="starting")}).length;return e.jsxs(Uv,{children:[e.jsx(Ev,{asChild:!0,children:e.jsxs("div",{draggable:!I,onDragStart:J=>{U(E.id),J.dataTransfer.effectAllowed="move",J.dataTransfer.setData("text/plain","")},onDragEnd:()=>{U(null),T(null)},onDragOver:J=>{J.preventDefault(),J.dataTransfer.dropEffect="move",C&&C!==E.id&&T(E.id)},onDragLeave:()=>{P===E.id&&T(null)},onDrop:J=>{if(J.preventDefault(),!C||C===E.id)return;const D=t.findIndex(le=>le.id===C),se=t.findIndex(le=>le.id===E.id);D!==-1&&se!==-1&&f(D,se),U(null),T(null)},onClick:()=>!I&&a(E.id),onDoubleClick:()=>K(E),className:Z("relative flex items-center gap-2 px-3 h-9 text-xs font-sans cursor-pointer select-none transition-colors flex-shrink-0",H?"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",P===E.id&&C!==E.id&&"border-l-2 !border-l-accent"),children:[H&&e.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-accent",style:{height:"0.5px"}}),(()=>{const J=vee(n,E.id),D=J==="working"||J==="completed"?"text-green-400":J==="crashed"?"text-red-400":H?"text-accent":"text-text-4";return e.jsxs("span",{className:"relative flex-shrink-0",children:[e.jsx(yn,{size:13,className:Z(D,J==="working"&&"animate-pulse")}),J==="working"&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 w-1.5 h-1.5 rounded-full bg-green-400 animate-pulse"})]})})(),I?e.jsx("input",{value:S,onChange:J=>j(J.target.value),onKeyDown:J=>{J.key==="Enter"&&_(),J.key==="Escape"&&y(null)},onBlur:_,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:J=>J.stopPropagation()}):e.jsx("span",{className:"truncate max-w-[120px]",children:E.name}),q>0&&!I&&e.jsx("span",{className:Z("flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full text-2xs font-mono font-semibold",L>0?"bg-accent/15 text-accent":"bg-surface-4 text-text-3"),children:q}),H&&e.jsx("div",{className:"absolute bottom-[-1px] left-0 right-0 h-px bg-[#242830]"})]})}),e.jsxs(Pv,{children:[e.jsxs(ya,{onSelect:()=>K(E),children:[e.jsx(Ua,{size:12})," Rename"]}),e.jsxs(ya,{onSelect:()=>A(E.id),children:[e.jsx(Ba,{size:12})," Clone"]}),e.jsx(Fv,{}),e.jsxs(ya,{danger:!0,onSelect:()=>{if(n.filter(D=>D.teamId===E.id).some(D=>D.status==="running"||D.status==="starting")){x("error","Stop running agents first");return}l(E.id)},children:[e.jsx(Ft,{size:12})," Delete"]})]})]},E.id)}),h?e.jsxs("div",{className:"flex items-center gap-1.5 px-3 h-9 flex-shrink-0",children:[e.jsx("input",{value:O,onChange:E=>b(E.target.value),onKeyDown:E=>{E.key==="Enter"&&ee(),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}),e.jsx("button",{onClick:ee,disabled:!O.trim(),className:"p-1 rounded text-accent hover:bg-accent/10 cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",children:e.jsx(Je,{size:12})}),e.jsx("button",{onClick:()=>{g(!1),b("")},className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:12})})]}):e.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:e.jsx(it,{size:12})})]}),R&&e.jsx("button",{onClick:()=>{var E;return(E=B.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:e.jsx(Tt,{size:14})})]})}function wee(){const t=k(K=>K.agents),s=k(K=>K.activeTeamId),n=k(K=>K.tokenTimeline),a=k(K=>K.selectAgent),r=k(K=>K.closeDetail),l=p.useRef([]),c=p.useMemo(()=>{const K=t.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.current;return _.length===K.length&&_.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.current=K,K)},[t,s]),A=p.useRef(FA(s)),f=p.useRef(s);f.current!==s&&(f.current=s,A.current=FA(s));const{fitView:x,setViewport:h}=BU(),[g,O]=p.useState(0),b=p.useRef(s),v=p.useMemo(()=>{const K=A.current,_=k4(),E=c.filter(se=>se.status==="running").length,q=K[Xs]||_[Xs]||{x:0,y:0},H=[{id:Xs,type:"rootNode",position:q,data:{agentCount:c.length,runningCount:E},draggable:!0,selectable:!1}],I=new Set,L=(se,le)=>`${Math.round(se/100)},${Math.round(le/100)}`;I.add(L(q.x,q.y));const J=[];c.forEach(se=>{const le=se.name||se.id;if(K[le]){const V=K[le];I.add(L(V.x,V.y)),H.push({id:se.id,type:"agentNode",position:V,data:{agent:se,timeline:n[se.id]||[]},draggable:!0,selectable:!0})}else J.push(se)});const D=new Map;return J.forEach((se,le)=>{const V=se.role||"agent",te=D.get(V)||0;D.set(V,te+1);const ae=te===0?V:`${V}-${te}`;let be;if(_[ae])be={..._[ae]};else{const z=Math.floor(le/po),oe=le%po;be={x:-((Math.min(J.length-z*po,po)-1)*wf)/2+oe*wf,y:jf+z*jf}}for(;I.has(L(be.x,be.y));)be={x:be.x,y:be.y+jf};I.add(L(be.x,be.y)),se.name||se.id,H.push({id:se.id,type:"agentNode",position:be,data:{agent:se,timeline:n[se.id]||[]},draggable:!0,selectable:!0})}),H},[c,n,s]);p.useEffect(()=>{const K={};v.forEach(_=>{var q,H;const E=_.id===Xs?Xs:((H=(q=_.data)==null?void 0:q.agent)==null?void 0:H.name)||_.id;A.current[E]||(K[E]=_.position)}),Object.keys(K).length>0&&(Object.assign(A.current,K),QQ(s,A.current))},[v,s]);const y=p.useMemo(()=>{const K=FA(s),_=K[Xs]||{x:0,y:0};return c.map((E,q)=>{const H=E.name||E.id,I=Math.floor(q/po),L=q%po,D=-((Math.min(c.length-I*po,po)-1)*wf)/2,se=K[H]||{x:D+L*wf,y:140+I*jf},le=se.x+Ig/2-_.x,V=se.y+zg/2-_.y;let te,ae;return Math.abs(V)>Math.abs(le)?(te=V>0?"bottom":"top",ae=V>0?"top":"bottom"):(te=le>0?"right":"left",ae=le>0?"left":"right"),{id:`e-${Xs}-${E.id}`,source:Xs,target:E.id,sourceHandle:te,targetHandle:ae,type:"default",animated:E.status==="running"}})},[c,s]),[S,j,N]=kU(v),[C,U,P]=TU(y),T=p.useRef(new Set);p.useEffect(()=>{j(K=>{const _=new Map(K.map(E=>[E.id,E]));return v.map(E=>{const q=_.get(E.id);return q?{...q,data:E.data}:E})})},[v,j]),p.useEffect(()=>{U(()=>{const K=S.find(E=>E.id===Xs);if(!K)return y;const _=K.position;return y.map(E=>{const q=S.find(D=>D.id===E.target);if(!q)return E;const H=q.position.x+Ig/2-_.x,I=q.position.y+zg/2-_.y;let L,J;return Math.abs(I)>Math.abs(H)?(L=I>0?"bottom":"top",J=I>0?"top":"bottom"):(L=H>0?"right":"left",J=H>0?"left":"right"),{...E,sourceHandle:L,targetHandle:J}})})},[y,S,U]);const B=c.map(K=>K.id).join(","),F=p.useRef(null);p.useEffect(()=>{if(b.current!==s){b.current=s,T.current=new Set(c.map(q=>q.id)),O(c.length);const E=T4()[s];E?h(E,{duration:200}):c.length>0&&x({padding:.3,maxZoom:1.2,duration:200});return}const K=new Set(c.map(E=>E.id)),_=c.length>0&&[...K].some(E=>!T.current.has(E));T.current=K,g===0&&c.length>0?x({padding:.3,maxZoom:1.2,duration:0}):_&&(clearTimeout(F.current),F.current=setTimeout(()=>x({padding:.3,maxZoom:1.2,duration:300}),500)),O(c.length)},[B,g,x,s,h]);const M=p.useCallback((K,_)=>{bee(s,_)},[s]),R=p.useCallback((K,_)=>{_.id!==Xs&&a(_.id)},[a]),Y=p.useCallback(()=>{r()},[r]),W=p.useCallback((K,_)=>{const E=S.find(H=>H.id===Xs);if(!E)return;const q=E.position;U(H=>H.map(I=>{const L=I.source===_.id,J=I.target===_.id;if(!L&&!J)return I;const D=_.position,se=D.x+Ig/2-q.x,le=D.y+zg/2-q.y;let V,te;return Math.abs(le)>Math.abs(se)?(V=le>0?"bottom":"top",te=le>0?"top":"bottom"):(V=se>0?"right":"left",te=se>0?"left":"right"),{...I,sourceHandle:V,targetHandle:te}}))},[S,U]),ee=p.useCallback((K,_)=>{var H,I;const E=_.id===Xs?Xs:((I=(H=_.data)==null?void 0:H.agent)==null?void 0:I.name)||_.id;A.current[E]=_.position;const q=FA(s);q[E]=_.position,QQ(s,q)},[s]);return e.jsx(UU,{nodes:S,edges:C,nodeTypes:gee,onNodesChange:N,onEdgesChange:P,onNodeClick:R,onPaneClick:Y,onNodeDrag:W,onNodeDragStop:ee,onMoveEnd:M,defaultViewport:{x:0,y:0,zoom:1.2},proOptions:{hideAttribution:!0},minZoom:.2,maxZoom:1.5,className:"bg-surface-2",children:e.jsx(EU,{color:"rgba(97,175,239,0.03)",gap:24,size:1})})}const U4=new Set(["codex","grok","local"]),jee=new Set(["codex"]);function Qee({open:t,onOpenChange:s,onLaunch:n}){const a=k(T=>T.fetchProviders),[r,l]=p.useState([]),[c,A]=p.useState(""),[f,x]=p.useState(""),[h,g]=p.useState(50),[O,b]=p.useState(.5),[v,y]=p.useState(50);p.useEffect(()=>{t&&a().then(T=>{var F;if(!Array.isArray(T))return;const B=T.filter(M=>M.installed);if(l(B),!c&&B.length>0){const M=B.find(Y=>Y.isDefault)||B[0];A(M.id);const R=((F=M.models)==null?void 0:F.filter(Y=>Y.type!=="image"))||[];R.length>0&&x(R[0].id)}}).catch(()=>{})},[t]);const S=r.find(T=>T.id===c),j=((S==null?void 0:S.models)||[]).filter(T=>T.type!=="image"&&!T.disabled),N=U4.has(c),C=jee.has(c);function U(T){var M;A(T);const B=r.find(R=>R.id===T),F=((B==null?void 0:B.models)||[]).filter(R=>R.type!=="image"&&!R.disabled);x(((M=F[0])==null?void 0:M.id)||"")}function P(){const T={provider:c,model:f,reasoningEffort:h,...N&&{temperature:O},...C&&{verbosity:v}};k.setState({teamLaunchConfig:T}),n(T)}return e.jsx(Vt,{open:t,onOpenChange:s,children:e.jsxs(Kt,{title:"Configure Planner",description:"Set provider, model, and tuning before launching the planner",children:[e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Provider"}),e.jsxs(Rn,{value:c,onValueChange:U,children:[e.jsx(Mn,{placeholder:"Select provider",className:"bg-surface-3"}),e.jsx(In,{children:r.map(T=>e.jsx(ms,{value:T.id,children:T.displayName||T.name||T.id},T.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Model"}),e.jsxs(Rn,{value:f,onValueChange:x,children:[e.jsx(Mn,{placeholder:"Select model",className:"bg-surface-3"}),e.jsxs(In,{children:[e.jsx(ms,{value:"auto",children:"Auto"}),j.map(T=>e.jsx(ms,{value:T.id,children:T.name||T.id},T.id))]})]})]}),e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(Ka,{label:"Reasoning Effort",value:h,onChange:g,min:0,max:100,step:1}),N&&e.jsx(Ka,{label:"Temperature",value:O,onChange:b,min:0,max:1,step:.01,formatValue:T=>T.toFixed(2)}),C&&e.jsx(Ka,{label:"Verbosity",value:v,onChange:y,min:0,max:100,step:1})]})]}),e.jsx("div",{className:"px-5 py-4 border-t border-border-subtle",children:e.jsxs(pe,{variant:"primary",size:"md",onClick:P,className:"w-full gap-2",children:[e.jsx(qt,{size:14}),"Launch Planner"]})})]})})}const NQ={chat:Ho,planner:Ei,backend:Ns,frontend:md,fullstack:bn,testing:Wx,devops:Eb,docs:On,security:vn,database:Pb,cmo:Ib,cfo:bS,ea:LS,support:kS,analyst:Lx,creative:MS,slides:zS,ambassador:ua},_g=[{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"}],Nee=[{name:"Dev Team",icon:bn,roles:["frontend","backend","testing"],desc:"3 agents"},{name:"Full Stack",icon:rc,roles:["frontend","backend","fullstack","testing","devops"],desc:"5 agents"},{name:"Marketing",icon:Ib,roles:["cmo","creative","analyst"],desc:"3 agents"},{name:"Business",icon:Lx,roles:["cfo","analyst","ea"],desc:"3 agents"},{name:"Security Audit",icon:vn,roles:["security","testing","devops"],desc:"3 agents"},{name:"Docs",icon:On,roles:["docs","frontend","analyst"],desc:"3 agents"}];function See(){const t=k(D=>D.teamBuilderOpen),s=k(D=>D.teamBuilderRoles),n=k(D=>D.teamBuilderSettings),a=k(D=>D.teamBuilderTask),r=k(D=>D.teamTemplates),l=k(D=>D.closeTeamBuilder),c=k(D=>D.addTeamBuilderRole),A=k(D=>D.removeTeamBuilderRole),f=k(D=>D.updateTeamBuilderRole),x=k(D=>D.applyTemplate),h=k(D=>D.setTeamBuilderSettings),g=k(D=>D.setTeamBuilderTask),O=k(D=>D.launchTeamBuilder),b=k(D=>D.saveTeamTemplate),v=k(D=>D.fetchTeamTemplates),y=k(D=>D.fetchProviders),[S,j]=p.useState([]),[N,C]=p.useState(""),[U,P]=p.useState(null),[T,B]=p.useState(!1),[F,M]=p.useState(null),[R,Y]=p.useState(!1),[W,ee]=p.useState("");if(p.useEffect(()=>{t&&(y().then(D=>{Array.isArray(D)&&j(D.filter(se=>se.installed))}).catch(()=>{}),v())},[t]),!t)return null;const K=N?_g.filter(D=>D.label.toLowerCase().includes(N.toLowerCase())||D.desc.toLowerCase().includes(N.toLowerCase())):_g,_=S.find(D=>D.id===n.provider),E=((_==null?void 0:_.models)||[]).filter(D=>D.type!=="image"&&!D.disabled);function q(D){var V;h({provider:D});const se=S.find(te=>te.id===D),le=((se==null?void 0:se.models)||[]).filter(te=>te.type!=="image"&&!te.disabled);h({provider:D,model:((V=le[0])==null?void 0:V.id)||""})}function H(D){x(D),M(D.name)}async function I(){B(!0);try{await O()}catch{}B(!1)}function L(){const D=W.trim();D&&(b(D),Y(!1),ee(""))}const J=[...Nee,...(r.custom||[]).map(D=>{var se;return{...D,icon:rc,desc:`${((se=D.roles)==null?void 0:se.length)||0} agents`,custom:!0}})];return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:[e.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:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-info/15 flex items-center justify-center",children:e.jsx(yn,{size:16,className:"text-info"})}),e.jsx("h2",{className:"text-lg font-bold text-text-0 font-sans",children:"Team Builder"})]}),e.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:e.jsx(qe,{size:18})})]}),e.jsx("div",{className:"px-6 py-3 border-b border-border-subtle",children:e.jsxs("div",{className:"flex items-center gap-2 overflow-x-auto pb-1",style:{scrollbarWidth:"none"},children:[J.map(D=>{const se=D.icon||rc,le=F===D.name;return e.jsxs("button",{onClick:()=>H(D),className:Z("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:[e.jsx(se,{size:16,className:le?"text-accent":"text-text-2"}),e.jsx("span",{className:"text-2xs font-semibold text-text-0 font-sans",children:D.name}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:D.desc})]},D.name)}),e.jsx(dt,{content:"Save current roster as template",children:e.jsxs("button",{onClick:()=>{Y(!0),ee("")},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:[e.jsx(_r,{size:16,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans",children:"Save"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Template"})]})})]})}),e.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"w-[40%] border-r border-border-subtle flex flex-col",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border-subtle",children:e.jsxs("div",{className:"relative",children:[e.jsx(As,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{type:"text",value:N,onChange:D=>C(D.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"})]})}),e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"p-3 grid grid-cols-2 gap-2",children:K.map(D=>{const se=NQ[D.id]||bn;return e.jsxs("button",{onClick:()=>c(D.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:[e.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:e.jsx(se,{size:14,className:"text-text-2 group-hover:text-accent transition-colors"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:D.label}),e.jsx(it,{size:12,className:"text-text-4 group-hover:text-accent transition-colors flex-shrink-0"})]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans leading-tight mt-0.5",children:D.desc})]})]},D.id)})})})]}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center justify-between",children:e.jsxs("span",{className:"text-xs font-semibold text-text-1 font-sans uppercase tracking-wider",children:["Your Team (",s.length,")"]})}),e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"p-3 space-y-1.5",children:s.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx(yn,{size:32,className:"text-text-4 mb-3"}),e.jsx("p",{className:"text-sm text-text-2 font-sans",children:"Add roles from the left or pick a template above"})]}):s.map((D,se)=>{var be;const le=NQ[D.role]||bn,V=U===se,te=D.provider?S.find(z=>z.id===D.provider):null,ae=((te==null?void 0:te.models)||[]).filter(z=>z.type!=="image"&&!z.disabled);return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(BS,{size:12,className:"text-text-4 flex-shrink-0 cursor-grab"}),e.jsx("div",{className:"w-6 h-6 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx(le,{size:12,className:"text-text-1"})}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans flex-1",children:((be=_g.find(z=>z.id===D.role))==null?void 0:be.label)||D.role}),e.jsx("button",{onClick:()=>P(V?null:se),className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(xt,{size:12,className:Z("transition-transform duration-200",V&&"rotate-180")})}),e.jsx("button",{onClick:()=>{A(se),U===se?P(null):U>se&&P(U-1)},className:"p-1 rounded text-text-4 hover:text-danger cursor-pointer",children:e.jsx(qe,{size:12})})]}),V&&e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-3 border-t border-border-subtle bg-surface-1",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Name Override"}),e.jsx("input",{type:"text",value:D.name,onChange:z=>f(se,{name:sanitizeName(z.target.value)}),placeholder:D.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})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:D.provider||"__default__",onValueChange:z=>{var Ce;const oe=z==="__default__"?null:z,ue=S.find(Ne=>Ne.id===oe),ve=((ue==null?void 0:ue.models)||[]).filter(Ne=>Ne.type!=="image"&&!Ne.disabled);f(se,{provider:oe,model:((Ce=ve[0])==null?void 0:Ce.id)||null})},children:[e.jsx(Mn,{placeholder:"Team Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Team Default"}),S.map(z=>e.jsx(ms,{value:z.id,children:z.displayName||z.name||z.id},z.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:D.model||"__default__",onValueChange:z=>f(se,{model:z==="__default__"?null:z}),children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Default"}),ae.map(z=>e.jsx(ms,{value:z.id,children:z.name||z.id},z.id))]})]})]})]}),e.jsx(Ka,{label:"Reasoning",value:D.reasoningEffort??n.reasoningEffort,onChange:z=>f(se,{reasoningEffort:z}),min:0,max:100,step:1}),U4.has(D.provider||n.provider)&&e.jsx(Ka,{label:"Temperature",value:D.temperature??n.temperature,onChange:z=>f(se,{temperature:z}),min:0,max:1,step:.01,formatValue:z=>z.toFixed(2)})]})]},se)})})})]})]}),e.jsx("div",{className:"border-t border-border-subtle px-6 py-4",children:e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("textarea",{value:a,onChange:D=>g(D.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"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans italic",children:"Leave empty to spawn agents awaiting instructions"})]}),e.jsxs("div",{className:"w-64 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-0.5",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:n.provider||"__default__",onValueChange:D=>q(D==="__default__"?"":D),children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Default"}),S.map(D=>e.jsx(ms,{value:D.id,children:D.displayName||D.name||D.id},D.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-0.5",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:n.model||"__default__",onValueChange:D=>h({model:D==="__default__"?"":D}),children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Auto"}),E.map(D=>e.jsx(ms,{value:D.id,children:D.name||D.id},D.id))]})]})]})]}),e.jsxs(pe,{variant:"primary",size:"md",onClick:I,disabled:T||s.length===0,className:"w-full gap-2 mt-1",children:[e.jsx(qt,{size:14}),T?"Launching...":`Plan & Launch (${s.length})`]})]})]})})]}),R&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40",children:e.jsxs("div",{className:"w-full max-w-sm bg-surface-2 border border-border rounded-lg shadow-2xl p-5 space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:"Save as Template"}),e.jsx("input",{type:"text",value:W,onChange:D=>ee(D.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:D=>{D.key==="Enter"&&L(),D.key==="Escape"&&Y(!1)}}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(pe,{variant:"ghost",size:"sm",onClick:()=>Y(!1),children:"Cancel"}),e.jsx(pe,{variant:"primary",size:"sm",onClick:L,disabled:!W.trim(),children:"Save"})]})]})})]})}function Cee({onPlanner:t,onSpawn:s,onTeamBuilder:n}){var a;return e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsxs("div",{className:"max-w-2xl w-full text-center space-y-10 px-8",children:[e.jsxs("div",{className:"relative mx-auto w-20 h-20",children:[e.jsx("div",{className:"absolute inset-0 rounded-full bg-accent/8 animate-pulse"}),e.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:e.jsx("img",{src:"/favicon.png",alt:"Groove",className:"h-10 w-10 rounded-full"})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h1",{className:"text-3xl font-bold text-text-0 font-sans tracking-tight",children:"Welcome to Groove"}),e.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."})]}),e.jsxs("div",{className:"space-y-3 max-w-xl mx-auto",children:[e.jsxs("button",{onClick:t,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:[e.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:e.jsx(qt,{size:24,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-base font-semibold text-text-0 font-sans",children:"Start with a Planner"}),e.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"})]}),e.jsx("div",{className:"text-accent text-xs font-semibold font-sans flex-shrink-0 opacity-60 group-hover:opacity-100 transition-opacity",children:"Recommended"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.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:[e.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:e.jsx(HS,{size:20,className:"text-info"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Build a Team"}),e.jsx("div",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Pick roles and configure"})]})]}),e.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:[e.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:e.jsx(it,{size:20,className:"text-text-1"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn Agent"}),e.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)&&e.jsxs("div",{className:"max-w-sm mx-auto",children:[e.jsx("p",{className:"text-xs text-text-3 mb-2",children:"Or open a different project"}),e.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:[e.jsx(Ys,{size:16,className:"text-accent"}),"Open Folder"]})]}),e.jsxs("p",{className:"text-xs text-text-4 font-sans",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+K"}),e.jsx("span",{className:"mx-1.5",children:"command palette"}),e.jsx("span",{className:"text-text-4 mx-1",children:"·"}),e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+N"}),e.jsx("span",{className:"mx-1.5",children:"spawn"}),e.jsx("span",{className:"text-text-4 mx-1",children:"·"}),e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+J"}),e.jsx("span",{className:"mx-1.5",children:"terminal"})]})]})})}function Dg(){var M;const t=k(R=>R.agents),s=k(R=>R.activeTeamId),n=k(R=>R.openDetail),a=k(R=>R.spawnAgent),r=k(R=>R.selectAgent);k(R=>R.recommendedTeam);const l=k(R=>R.checkRecommendedTeam),c=k(R=>R.addToast),A=k(R=>R.showPreviewInAgents),f=k(R=>R.previewState),x=k(R=>R.togglePreviewInAgents),h=k(R=>R.teamPreviews),g=k(R=>R.relaunchPreview),O=k(R=>R.openPreview),b=k(R=>R.workspaceMode),v=k(R=>R.setWorkspaceMode),y=k(R=>R.openTeamBuilder),[S,j]=p.useState(!1);p.useEffect(()=>{if(!t.some(W=>W.role==="planner"&&(W.status==="running"||W.status==="starting")))return;const Y=setInterval(()=>l(),5e3);return()=>clearInterval(Y)},[t,l]);function N(){j(!0)}async function C(R){j(!1);try{const Y=await a({role:"planner",provider:R.provider,model:R.model,reasoningEffort:R.reasoningEffort,temperature:R.temperature,verbosity:R.verbosity});Y!=null&&Y.id&&r(Y.id)}catch{}}const U=t.filter(R=>{var Y;return R.teamId===s&&!((Y=R.metadata)!=null&&Y.scheduled)}),P=k(R=>R.hydrated),[T,B]=p.useState(!0);p.useEffect(()=>{const R=setTimeout(()=>B(!1),1200);return()=>clearTimeout(R)},[]);const F=T||!P;return e.jsxs("div",{className:"flex flex-col h-full relative",children:[e.jsx("div",{className:"flex-1 min-h-0",children:F?e.jsxs("div",{className:Z("flex flex-col items-center justify-center h-full transition-opacity duration-500",!T&&P?"opacity-0":"opacity-100"),children:[e.jsxs("div",{className:"relative w-12 h-12 mb-5",children:[e.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-accent/20 animate-ping",style:{animationDuration:"2s"}}),e.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent animate-spin",style:{animationDuration:"1s"}}),e.jsx("span",{className:"absolute inset-[6px] rounded-full bg-accent/8 flex items-center justify-center",children:e.jsx(qt,{size:16,className:"text-accent animate-pulse"})})]}),e.jsx("p",{className:"text-sm font-medium text-text-1 font-sans animate-pulse",children:"Connecting to agents"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Syncing with daemon..."})]}):U.length===0?e.jsx(Cee,{onPlanner:N,onSpawn:()=>n({type:"spawn"}),onTeamBuilder:y}):b?e.jsx(nY,{}):A&&f.url&&f.teamId===s&&((M=h[s])!=null&&M.active)?e.jsx(RX,{embedded:!0}):e.jsx(CU,{children:e.jsx(wee,{})},s)}),!b&&e.jsx(qf,{}),!F&&U.length>0&&!b&&e.jsxs("div",{className:"absolute bottom-3 left-3 z-40 flex items-center gap-1.5",children:[e.jsx(dt,{content:"Spawn agent",side:"top",children:e.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:e.jsx(it,{size:15})})}),e.jsx(dt,{content:Object.keys(k4()).length>0?"Update layout":"Save layout",side:"top",children:e.jsx("button",{onClick:()=>{const R=FA(s),Y={},W=new Map;[...U].sort((ee,K)=>(ee.name||ee.id).localeCompare(K.name||K.id)).forEach(ee=>{const K=ee.name||ee.id,_=R[K];if(!_)return;const E=ee.role||"agent",q=W.get(E)||0;W.set(E,q+1);const H=q===0?E:`${E}-${q}`;Y[H]=_}),R[Xs]&&(Y[Xs]=R[Xs]),Oee(Y),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:e.jsx(yM,{size:15})})}),e.jsx(dt,{content:"Workspace",side:"top",children:e.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:e.jsx(bn,{size:15})})}),(()=>{const R=h[s];if(!R)return null;const Y=R.active&&f.url&&f.teamId===s,W=Y&&A,ee=W?"Show team":Y?"Show preview":"Relaunch preview";return e.jsx(dt,{content:ee,side:"top",children:e.jsx("button",{onClick:()=>{Y?A?x():O(R.url,s,R.kind):g(s)},className:Z("flex items-center justify-center w-8 h-8 rounded border bg-surface-2/50 transition-colors cursor-pointer",Y?"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:W?e.jsx(yn,{size:15}):e.jsx(Vs,{size:15})})})})()]}),e.jsx(Qee,{open:S,onOpenChange:j,onLaunch:C}),e.jsx(See,{})]})}function Bee({children:t,detailContent:s,terminalContent:n}){const a=k(T=>T.activeView),r=k(T=>T.detailPanel),l=k(T=>T.connected),c=k(T=>T.tunneled),A=k(T=>T.daemonHost),f=k(T=>T.agents),x=k(T=>T.editorActiveFile),h=k(T=>T.detailPanelWidth),g=k(T=>T.terminalVisible),O=k(T=>T.terminalFullHeight),b=k(T=>T.setActiveView),v=k(T=>T.openDetail),y=k(T=>T.closeDetail),S=k(T=>T.setDetailPanelWidth),j=k(T=>T.setTerminalVisible),N=k(T=>T.toggleCommandPalette),C=p.useMemo(()=>f.filter(T=>T.status==="running").length,[f]),U=p.useMemo(()=>[{key:"k",meta:!0,handler:()=>k.getState().toggleCommandPalette()},{key:"p",meta:!0,shift:!0,handler:()=>k.getState().toggleCommandPalette()},{key:"j",meta:!0,handler:()=>{const T=k.getState();T.setTerminalVisible(!T.terminalVisible)}},{key:"n",meta:!0,handler:()=>k.getState().openDetail({type:"spawn"})},{key:"1",meta:!0,handler:()=>k.getState().setActiveView("agents")},{key:"2",meta:!0,handler:()=>k.getState().setActiveView("editor")},{key:"3",meta:!0,handler:()=>k.getState().setActiveView("dashboard")},{key:"4",meta:!0,handler:()=>k.getState().setActiveView("marketplace")},{key:"5",meta:!0,handler:()=>k.getState().setActiveView("teams")},{key:"Escape",handler:()=>{const T=k.getState();T.commandPaletteOpen?T.toggleCommandPalette():T.detailPanel&&T.closeDetail()}}],[]);pN(U);const P=r&&r.type!=="spawn";return e.jsx(v$,{children:e.jsxs("div",{className:Z("w-full h-full flex flex-col bg-surface-2 text-text-1 font-sans",cd()&&"electron-app"),children:[e.jsx(Uz,{activeView:a,connected:l,tunneled:c,daemonHost:A,editorActiveFile:x,onOpenCommandPalette:N}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsx(Cz,{activeView:a,detailPanel:r,onNavigate:b,onTogglePanel:T=>{(r==null?void 0:r.type)===T?y():v({type:T})}}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[a==="agents"&&e.jsx(yee,{}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[!(g&&O)&&e.jsx("main",{className:"flex-1 min-h-0 overflow-hidden relative",children:t}),n]}),P&&e.jsx(D_,{width:h,onWidthChange:S,onClose:y,children:s})]})]})]}),e.jsx(__,{connected:l,agentCount:f.length,runningCount:C,terminalVisible:g,onToggleTerminal:()=>j(!g)}),e.jsx(H_,{}),e.jsx(NC,{}),e.jsx(X_,{}),e.jsx(G_,{}),e.jsx(ZS,{})]})})}function kee({id:t,name:s,subtitle:n,models:a,authType:r,recommended:l,installed:c,installing:A,failed:f,selected:x,onInstall:h,gradientFrom:g,letter:O,statusChecking:b}){return e.jsxs(_n.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.25},className:Z("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",x?"border-accent ring-1 ring-accent/30 shadow-md shadow-accent/10":"border-border-subtle",A&&"pointer-events-none opacity-70"),children:[x&&e.jsx("div",{className:"absolute top-3 left-3 w-5 h-5 rounded-full bg-accent flex items-center justify-center",children:e.jsx(Je,{className:"w-3 h-3 text-surface-0",strokeWidth:3})}),e.jsxs("div",{className:"flex items-start gap-4 mb-5",children:[e.jsx("div",{className:Z("w-14 h-14 rounded-md flex items-center justify-center text-lg font-bold font-mono shrink-0",g),children:O}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:s}),l&&e.jsx(Te,{variant:"purple",className:"text-2xs",children:"Recommended"})]}),e.jsx("p",{className:"text-xs text-text-2 mt-0.5",children:n})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",children:a.map(v=>e.jsx("span",{className:"text-xs text-text-2 bg-surface-4 px-2 py-0.5 rounded font-mono",children:v},v))}),e.jsx("p",{className:"text-2xs text-text-3 mb-4",children:r}),e.jsx("div",{className:"mt-auto pt-4 border-t border-border-subtle",children:A?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4 text-accent animate-spin"}),e.jsx("span",{className:"text-xs text-accent font-medium",children:"Installing..."})]}),e.jsx("div",{className:"h-1 bg-surface-4 rounded-full overflow-hidden",children:e.jsx(_n.div,{className:"h-full bg-accent rounded-full",initial:{width:"0%"},animate:{width:"90%"},transition:{duration:15,ease:"easeOut"}})})]}):c?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rx,{className:"w-4 h-4 text-success"}),e.jsx("span",{className:"text-xs text-success font-medium",children:"Ready"})]}):f?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"w-4 h-4 text-danger"}),e.jsx("span",{className:"text-xs text-danger font-medium",children:"Failed"})]}),e.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(t)},children:[e.jsx(Io,{className:"w-3 h-3"}),"Retry"]})]}):b?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-3.5 h-3.5 text-text-4 animate-spin"}),e.jsx("span",{className:"text-xs text-text-4",children:"Checking..."})]}):e.jsx("div",{className:"flex items-center justify-end",children:e.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(t)},children:[e.jsx(qs,{className:"w-3.5 h-3.5"}),"Install"]})})})]})}const ja=[{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"}],Tee={enter:t=>({x:t>0?80:-80,opacity:0}),center:{x:0,opacity:1},exit:t=>({x:t<0?80:-80,opacity:0})},Uee={duration:.25,ease:[.4,0,.2,1]};function Eee({current:t,total:s}){return e.jsx("div",{className:"flex items-center gap-2.5",children:Array.from({length:s},(n,a)=>e.jsx("div",{className:Z("h-2 rounded-full transition-all duration-300",a===t?"w-7 bg-accent":a<t?"w-2 bg-accent/50":"w-2 bg-surface-5")},a))})}function Pee({onNext:t,onSkip:s}){return e.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[e.jsx(_n.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"}}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"Welcome to Groove"}),e.jsx("p",{className:"text-sm text-text-2",children:"Your AI coding team, ready in minutes"})]}),e.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."}),e.jsxs("button",{type:"button",onClick:t,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",e.jsx(Mo,{className:"w-4 h-4"})]}),e.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 Fee({selectedDir:t,onSelectDir:s}){const n=k(A=>A.remoteHomedir),[a,r]=p.useState(!1),l=new URLSearchParams(window.location.search).has("instance");async function c(){var f,x;if(l){r(!0);return}const A=await wE({title:"Choose your project folder",defaultPath:t||void 0});A?s(A):(x=(f=window.groove)==null?void 0:f.folders)!=null&&x.select||r(!0)}return e.jsxs("div",{className:"flex flex-col items-center max-w-lg mx-auto w-full text-center",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your project folder"}),e.jsx("p",{className:"text-sm text-text-2",children:"Pick the root directory where your code lives. Groove will manage agents from here."})]}),e.jsx("div",{className:"w-full bg-surface-2 border border-border-subtle rounded-lg p-5 mb-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-lg bg-accent/10 flex items-center justify-center",children:e.jsx(Ys,{className:"w-6 h-6 text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[e.jsx("p",{className:"text-xs text-text-3 mb-0.5",children:"Working directory"}),e.jsx("p",{className:"text-sm font-mono text-text-0 truncate",children:t||"No folder selected"})]})]})}),e.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:[e.jsx(Ys,{className:"w-4 h-4"}),t?"Change Folder":"Select Folder"]}),e.jsx("p",{className:"mt-4 text-2xs text-text-4",children:"You can change this anytime in Settings."}),a&&e.jsx(gc,{open:a,onOpenChange:r,currentPath:t||n||"/",homePath:n,onSelect:A=>{s(A),r(!1)}})]})}function $ee({providerStatus:t,selected:s,onInstall:n,installing:a,statusChecking:r}){const l=ja.filter(A=>{var f;return(f=t[A.id])==null?void 0:f.installed}).length,c=l===ja.length;return e.jsxs("div",{className:"flex flex-col items-center max-w-4xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your AI providers"}),e.jsx("p",{className:"text-sm text-text-2",children:"Install the coding tools you want to use. You can always add more later."})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 w-full mb-8",children:ja.map(A=>{var f,x;return e.jsx(kee,{...A,installed:(f=t[A.id])==null?void 0:f.installed,installing:a[A.id],failed:(x=t[A.id])==null?void 0:x.failed,selected:s.includes(A.id),onInstall:n,statusChecking:r},A.id)})}),e.jsx("p",{className:Z("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 ${ja.length} providers installed`:"Click Install to set up a provider"})]})}function Ree({provider:t,providerStatus:s,onSaveKey:n}){const[a,r]=p.useState(t.authModes.includes("subscription")?"subscription":"apikey"),[l,c]=p.useState(""),[A,f]=p.useState(!1),[x,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(t.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 e.jsxs(_n.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:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:Z("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono",t.gradientFrom),children:t.letter}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:t.name}),e.jsx("p",{className:"text-2xs text-text-3",children:t.subtitle})]}),(g||(s==null?void 0:s.authenticated))&&e.jsx(Te,{variant:"success",className:"ml-auto",children:"Connected"})]}),t.authModes.length>1&&e.jsx("div",{className:"flex gap-1 mb-4 bg-surface-3 p-0.5 rounded-md",children:t.authModes.map(y=>e.jsx("button",{type:"button",onClick:()=>r(y),className:Z("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===y?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:y==="subscription"?"Subscription":y==="chatgpt-plus"?"ChatGPT Plus":"API Key"},y))}),a==="subscription"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-text-2",children:"Sign in via the terminal with your Claude subscription."}),e.jsx("div",{className:"space-y-1.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans",children:["Open a terminal and run: ",e.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)&&e.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[e.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="chatgpt-plus"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-xs text-text-2",children:["Run ",e.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)&&e.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[e.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="apikey"&&e.jsx("div",{className:"space-y-3",children:g||s!=null&&s.authenticated?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-8 rounded-md bg-surface-1 border border-border px-3 flex items-center",children:e.jsx("span",{className:"text-xs text-text-3 font-mono truncate",children:v||"••••••••••••••"})}),e.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"})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{type:A?"text":"password",value:l,onChange:y=>c(y.target.value),placeholder:t.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:y=>y.key==="Enter"&&b(),"aria-label":t.keyLabel}),e.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?e.jsx(To,{className:"w-3.5 h-3.5"}):e.jsx(Vs,{className:"w-3.5 h-3.5"})})]}),e.jsx("button",{type:"button",onClick:b,disabled:!l.trim()||x,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:x?"Saving...":"Save"})]})})]})}function Mee({providerStatus:t,installedIds:s,onSaveKey:n}){const a=ja.filter(r=>{var l;return s.includes(r.id)||((l=t[r.id])==null?void 0:l.installed)});return a.some(r=>{var l;return(l=t[r.id])==null?void 0:l.authenticated}),e.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Connect your accounts"}),e.jsx("p",{className:"text-sm text-text-2",children:"Add credentials for your installed providers."})]}),e.jsx("div",{className:"flex flex-col gap-4 w-full mb-6",children:a.map(r=>e.jsx(Ree,{provider:r,providerStatus:t[r.id]||{},onSaveKey:n},r.id))}),a.length===0&&e.jsx("p",{className:"text-sm text-text-3 text-center",children:"No providers installed yet. Go back to install one."})]})}function Iee({providerStatus:t,installedIds:s,defaultProvider:n,defaultModel:a,onSetDefault:r}){var c;const l=ja.filter(A=>{var f,x;return(s.includes(A.id)||((f=t[A.id])==null?void 0:f.installed))&&((x=t[A.id])==null?void 0:x.authenticated)});return e.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Set your default"}),e.jsx("p",{className:"text-sm text-text-2",children:"Choose which provider and model to use by default. You can switch per-agent anytime."})]}),e.jsxs("div",{className:"flex flex-col gap-3 w-full max-w-md mb-6",children:[l.map(A=>e.jsxs("button",{type:"button",onClick:()=>r(A.id,A.models[0]),className:Z("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:[e.jsx("div",{className:Z("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono shrink-0",A.gradientFrom),children:A.letter}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:A.name}),e.jsx("p",{className:"text-2xs text-text-3",children:A.subtitle})]}),e.jsx("div",{className:Z("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&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-surface-0"})})]},A.id)),l.length===0&&e.jsx("p",{className:"text-sm text-text-3 text-center",children:"No authenticated providers. Go back to connect one."})]}),n&&e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 mb-2 block",children:"Model"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(c=ja.find(A=>A.id===n))==null?void 0:c.models.map(A=>e.jsx("button",{type:"button",onClick:()=>r(n,A),className:Z("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 zee({providerStatus:t,defaultProvider:s,defaultModel:n,onFinish:a}){var c;const r=ja.filter(A=>{var f;return(f=t[A.id])==null?void 0:f.installed}).length,l=(c=ja.find(A=>A.id===s))==null?void 0:c.name;return e.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[e.jsx(_n.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:e.jsx(Je,{className:"w-10 h-10 text-success",strokeWidth:2.5})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"You're all set!"}),e.jsxs("p",{className:"text-sm text-text-2",children:[r," provider",r!==1?"s":""," installed",l?`, default: ${l}`:"",n?` (${n})`:""]})]}),e.jsx(_n.div,{className:"flex gap-3 mt-4",initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.3},children:e.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:[e.jsx(Js,{className:"w-4 h-4"}),"Start Building"]})})]})}const yA=6;function _ee(){const t=k(H=>H.dismissOnboarding),s=k(H=>H.installProvider),n=k(H=>H.setDefaultProvider),a=k(H=>H.addToast),[r,l]=p.useState(0),[c,A]=p.useState(1),[f,x]=p.useState(["claude-code"]),[h,g]=p.useState({}),[O,b]=p.useState({}),[v,y]=p.useState(null),[S,j]=p.useState(null),[N,C]=p.useState(!0),[U,P]=p.useState(null),T=p.useRef(null);p.useEffect(()=>{let H=!1;async function I(){var J;try{const D=await fetch("/api/onboarding/status").then(se=>se.ok?se.json():null);if(D!=null&&D.providers){const se={},le=[];for(const V of D.providers){const te=V.authStatus==="authenticated"||V.authStatus==="key-set";se[V.id]={installed:V.installed,authenticated:te},V.installed&&le.push(V.id)}return{status:se,installedIds:le,workingDir:((J=D.config)==null?void 0:J.defaultWorkingDir)||null}}}catch{}try{const D=await fetch("/api/providers").then(se=>se.ok?se.json():null);if(D){const se={},le=[],V=Array.isArray(D)?D:D.providers||[];for(const te of V){const ae=te.installed||te.authStatus==="authenticated"||te.authStatus==="key-set"||!1;se[te.id]={installed:ae,authenticated:te.authenticated||!1},ae&&le.push(te.id)}return{status:se,installedIds:le}}}catch{}return null}async function L(){C(!0);let J=await I();if(!H&&J&&J.installedIds.length===0)for(let D=0;D<2;D++){if(await new Promise(se=>setTimeout(se,2e3)),H)return;if(J=await I(),J&&J.installedIds.length>0)break}!H&&J&&(b(J.status),J.installedIds.length>0&&x(D=>[...new Set([...D,...J.installedIds])]),J.workingDir&&!U&&P(J.workingDir)),H||C(!1)}return L(),()=>{H=!0}},[r]);const B=p.useCallback(()=>{r<yA-1&&(A(1),l(H=>H+1))},[r]),F=p.useCallback(()=>{r>0&&(A(-1),l(H=>H-1))},[r]),M=p.useCallback(()=>{t()},[t]),R=p.useCallback(async()=>{if(U)try{await P(U)}catch{a("error","Failed to set project directory")}t()},[t,U,a]),Y=p.useCallback(async H=>{g(I=>({...I,[H]:!0}));try{await s(H),b(I=>({...I,[H]:{...I[H],installed:!0}})),x(I=>I.includes(H)?I:[...I,H])}catch{b(I=>({...I,[H]:{...I[H],failed:!0}}))}finally{g(I=>({...I,[H]:!1}))}},[s]),W=p.useCallback(async(H,I)=>{try{if(!(await fetch(`/api/credentials/${encodeURIComponent(H)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:I})})).ok)throw new Error("Failed to save key");b(J=>({...J,[H]:{...J[H],authenticated:!0,maskedKey:`${I.slice(0,6)}${"•".repeat(20)}`}})),a("success","API key saved")}catch(L){throw a("error","Failed to save key",L.message),L}},[a]),ee=p.useCallback(async(H,I)=>{y(H),j(I);try{await n(H,I)}catch{}},[n]),K=ja.some(H=>{var I;return(I=O[H.id])==null?void 0:I.installed}),_=ja.some(H=>{var I;return(I=O[H.id])==null?void 0:I.authenticated}),E=r===0||r===1?!0:r===2?K:r===3?_:r===4?!!v:!1;p.useEffect(()=>{const H=I=>{I.key==="Enter"&&r<yA-1&&E&&B(),I.key==="Escape"&&M()};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[r,E,B,M]);const q=[e.jsx(Pee,{onNext:B,onSkip:M},"welcome"),e.jsx(Fee,{selectedDir:U,onSelectDir:P},"folder"),e.jsx($ee,{providerStatus:O,selected:f,onInstall:Y,installing:h,statusChecking:N},"install"),e.jsx(Mee,{providerStatus:O,installedIds:f,onSaveKey:W},"auth"),e.jsx(Iee,{providerStatus:O,installedIds:f,defaultProvider:v,defaultModel:S,onSetDefault:ee},"default"),e.jsx(zee,{providerStatus:O,defaultProvider:v,defaultModel:S,onFinish:R},"done")];return e.jsxs("div",{ref:T,className:"fixed inset-0 z-50 bg-gradient-to-b from-surface-0 to-surface-1 flex flex-col font-sans overflow-hidden",children:[cd()&&e.jsx("div",{className:"h-8 w-full electron-drag shrink-0"}),e.jsxs("div",{className:"flex items-center justify-between px-8 py-4 shrink-0",children:[e.jsx(Eee,{current:r,total:yA}),r>0&&r<yA-1&&e.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"})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center px-8 py-4 overflow-y-auto",children:e.jsx(Mi,{mode:"wait",custom:c,children:e.jsx(_n.div,{custom:c,variants:Tee,initial:"enter",animate:"center",exit:"exit",transition:Uee,className:"w-full",children:q[r]},r)})}),r>0&&r<yA-1&&e.jsxs("div",{className:"flex items-center justify-between px-8 py-8 shrink-0",children:[e.jsxs("button",{type:"button",onClick:F,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:[e.jsx(Di,{className:"w-4 h-4"}),"Back"]}),e.jsxs("button",{type:"button",onClick:B,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",e.jsx(Tt,{className:"w-4 h-4"})]})]})]})}const Dee=[{icon:Ns,label:"Federation",desc:"Multi-machine daemon pairing"},{icon:Eb,label:"Cloud Teams",desc:"Coming soon"}];function SQ(){var y;const t=k(S=>S.upgradeModalOpen),s=k(S=>S.setUpgradeModalOpen),n=k(S=>S.marketplaceAuthenticated),a=k(S=>S.marketplaceLogin),r=k(S=>S.startCheckout),l=k(S=>S.addToast),[c,A]=p.useState(null),[f,x]=p.useState("monthly"),[h,g]=p.useState(!1);p.useEffect(()=>{t&&!c&&k.getState().fetchSubscriptionPlans().then(S=>A(S)).catch(()=>{})},[t,c]);const O=(y=c==null?void 0:c.pro)==null?void 0:y[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 S;if(!n){a();return}if(!(O!=null&&O.priceId)){sO("https://groovedev.ai/pro"),s(!1);return}g(!0);try{await r(O.priceId),s(!1)}catch(j){j.status===401||(S=j.message)!=null&&S.includes("Not authenticated")?(l("info","Please sign in first"),a()):j.status===409&&(l("info","You already have a subscription"),s(!1))}finally{g(!1)}}return e.jsx(Vt,{open:t,onOpenChange:s,children:e.jsx(Kt,{title:"Upgrade to Pro",className:"max-w-[440px]",children:e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx("div",{className:"mx-auto mb-3 w-12 h-12 rounded-full bg-accent/10 flex items-center justify-center",children:e.jsx(Js,{size:22,className:"text-accent"})}),e.jsx("h2",{className:"text-lg font-bold text-text-0",children:"Upgrade to Groove Pro"}),e.jsx("p",{className:"text-sm text-text-2 mt-1",children:"Unlock powerful features for your AI workflow"})]}),e.jsx("div",{className:"space-y-3 mb-6",children:Dee.map(S=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx(S.icon,{size:15,className:"text-accent"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-text-0",children:S.label}),e.jsx("p",{className:"text-2xs text-text-3",children:S.desc})]}),e.jsx(Je,{size:14,className:"text-success ml-auto flex-shrink-0"})]},S.label))}),e.jsxs("div",{className:"flex gap-1 mb-5 bg-surface-3 p-0.5 rounded-md",children:[e.jsx("button",{type:"button",onClick:()=>x("monthly"),className:Z("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"}),e.jsxs("button",{type:"button",onClick:()=>x("annual"),className:Z("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",e.jsx("span",{className:"ml-1 text-success text-2xs",children:"Save 20%"})]})]}),e.jsxs("div",{className:"text-center mb-5",children:[e.jsx("span",{className:"text-3xl font-bold text-text-0",children:b}),f==="annual"&&e.jsxs("p",{className:"text-2xs text-text-3 mt-1",children:["Billed $",(O==null?void 0:O.price)||96,"/year"]})]}),e.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?e.jsxs(e.Fragment,{children:[e.jsx(Js,{size:15})," Subscribe — ",b]}):e.jsxs(e.Fragment,{children:[e.jsx(PS,{size:15})," Sign in to subscribe"]})}),e.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 Lee(){const t=k(l=>l.dataSharingModalOpen),s=k(l=>l.setTrainingOptIn),n=k(l=>l.dismissDataSharingModal),[a,r]=p.useState(!1);return e.jsx(Vt,{open:t,children:e.jsxs(Kt,{className:"max-w-md",description:"Help improve Groove by sharing usage data",onInteractOutside:l=>l.preventDefault(),onEscapeKeyDown:l=>l.preventDefault(),children:[e.jsxs("div",{className:"relative bg-gradient-to-br from-accent/5 to-transparent px-6 pt-8 pb-6 text-center",children:[e.jsx("div",{className:"flex justify-center mb-3",children:e.jsx("div",{className:"w-14 h-14 rounded-xl bg-accent/10 flex items-center justify-center",children:e.jsx(Js,{size:32,className:"text-accent"})})}),e.jsx(nm,{className:"text-xl font-bold text-text-0 font-sans",children:"Help Build a Better Groove"}),e.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."})]}),e.jsx("div",{className:"px-6 pt-4",children:e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2/30 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx(vn,{size:14,className:"text-text-2"}),e.jsx("span",{className:"text-xs font-semibold uppercase text-text-3 tracking-wider font-sans",children:"What We Never Collect"})]}),e.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=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qe,{size:12,className:"text-danger flex-shrink-0"}),e.jsx("span",{className:"text-xs text-text-1 font-sans",children:l})]},l))}),e.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."})]})}),e.jsxs("div",{className:"border-t border-border-subtle mt-5 pt-4 pb-1 px-6",children:[e.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:[e.jsx(Js,{size:15}),"Turn On Sharing"]}),e.jsx("div",{className:"text-center mt-2.5",children:e.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"})}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-3",children:[e.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"}),e.jsx("label",{htmlFor:"data-sharing-dismiss",className:"text-2xs text-text-3 font-sans cursor-pointer select-none",children:"Don't show this again"})]}),e.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 Hee(){const t=k(P=>P.recentProjects),s=k(P=>P.setProjectDir),n=k(P=>P.removeRecentProject),a=k(P=>P.remoteHomedir),r=k(P=>P.savedTunnels),l=k(P=>P.fetchTunnels),c=k(P=>P.deleteTunnel),A=k(P=>P.connectTunnel),f=k(P=>P.disconnectTunnel),x=k(P=>P.toggleQuickConnect),h=k(P=>P.addToast),g=k(P=>P.tunnelConnectStep),[O,b]=p.useState(!1),[v,y]=p.useState(null);p.useEffect(()=>{l()},[l]);const S=(t||[]).slice(0,8),j=S.length>0,N=r.length>0,C=j||N;async function U(P){var T,B;if(P.active){(B=(T=window.groove)==null?void 0:T.remote)!=null&&B.openWindow?window.groove.remote.openWindow(P.localPort,P.name):window.open(`http://localhost:${P.localPort}?instance=${encodeURIComponent(P.name)}`,"_blank");return}y(P.id);try{await A(P.id)}catch(F){const M=(F==null?void 0:F.message)||"Unknown error";/permission|EACCES|sudo|Node\.js is not installed|npm install failed|write access/i.test(M)?(x(),h("warning","Remote setup needed","Follow the instructions to set up the remote server.")):h("error","Connection failed",M)}y(null)}return e.jsxs("div",{className:"fixed inset-0 z-50 overflow-y-auto welcome-bg",children:[e.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]"}),e.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:[e.jsxs("div",{className:"flex flex-col items-center text-center mb-14",children:[e.jsxs("div",{className:"relative mb-8",children:[e.jsx("div",{className:"absolute -inset-10 rounded-full bg-accent/[0.06] blur-3xl animate-welcome-breathe"}),e.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/25 animate-welcome-ring"}),e.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/15 animate-welcome-ring-delayed"}),e.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:e.jsx("img",{src:"/favicon.png",className:"w-12 h-12 rounded-full",alt:"Groove"})})]}),e.jsx("h1",{className:"text-4xl font-bold text-text-0 tracking-tight mb-3 font-sans max-sm:text-3xl",children:"Welcome to Groove"}),e.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.",e.jsx("br",{className:"max-sm:hidden"}),e.jsx("span",{className:"max-sm:hidden",children:" "}),"Spawn fast. Stay aware. Never lose context."]})]}),e.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:[e.jsxs("button",{onClick:()=>b(!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:[e.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:e.jsx(Ys,{size:24,className:"text-accent"})}),e.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Open Project"}),e.jsx("div",{className:"text-sm text-text-2 font-sans",children:"Browse the filesystem to pick a project"}),e.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 ",e.jsx(Mo,{size:12})]})]}),e.jsxs("button",{onClick:x,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:[e.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:e.jsx(Ui,{size:24,className:"text-text-2 group-hover:text-accent transition-colors duration-300"})}),e.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Connect to Remote"}),e.jsx("div",{className:"text-sm text-text-2 font-sans",children:"SSH tunnel to a server running Groove"}),e.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 ",e.jsx(Mo,{size:12})]})]})]}),C&&e.jsxs("div",{className:Z("w-full max-w-4xl gap-6 mb-14 max-sm:flex max-sm:flex-col max-sm:gap-6",j&&N?"grid grid-cols-2":"flex justify-center"),children:[j&&e.jsxs("div",{className:Z(!N&&"w-full max-w-lg"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Dn,{size:13,className:"text-text-3"}),e.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Recent Projects"})]}),e.jsx("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:S.map(P=>e.jsxs("div",{className:"group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",children:[e.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:e.jsx(Ys,{size:14,className:"text-text-3 group-hover:text-accent transition-colors"})}),e.jsxs("button",{onClick:()=>s(P.path),className:"flex-1 min-w-0 text-left cursor-pointer",children:[e.jsx("div",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:P.name}),e.jsx("div",{className:"text-2xs font-mono text-text-4 truncate",children:P.path})]}),e.jsx("button",{onClick:T=>{T.stopPropagation(),n(P.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:e.jsx(qe,{size:14})})]},P.path))})]}),N&&e.jsxs("div",{className:Z(!j&&"w-full max-w-lg"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ns,{size:13,className:"text-text-3"}),e.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"SSH Connections"})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:[r.map(P=>e.jsxs("div",{className:Z("group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",v===P.id&&"opacity-60 pointer-events-none"),children:[e.jsx("div",{className:Z("w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0 transition-colors",P.active?"bg-success/10":"bg-surface-3 group-hover:bg-accent/10"),children:e.jsx(Ns,{size:14,className:Z("transition-colors",P.active?"text-success":"text-text-3 group-hover:text-accent")})}),e.jsxs("button",{onClick:()=>U(P),disabled:v===P.id,className:"flex-1 min-w-0 text-left cursor-pointer",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:P.name}),P.active&&e.jsx(Gt,{status:"running",size:"sm"})]}),e.jsxs("div",{className:"text-2xs font-mono text-text-4 truncate",children:[P.user,"@",P.host]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[v===P.id?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(De,{size:14,className:"text-text-3 animate-spin"}),(g==null?void 0:g.id)===P.id&&(g==null?void 0:g.step)&&e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:{testing:"Testing…",installing:"Installing…",checking:"Checking for updates…",upgrading:"Updating remote…",starting:"Starting daemon…",connecting:"Connecting…",forwarding:"Establishing tunnel…"}[g.step]||g.step})]}):P.active?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>U(P),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:[e.jsx(Ws,{size:11})," Open"]}),e.jsx("button",{onClick:async()=>{await f(P.id),h("info","Disconnected",P.name)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all",title:"Disconnect",children:e.jsx(Yx,{size:12})})]}):null,e.jsx("button",{onClick:T=>{T.stopPropagation(),c(P.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:e.jsx(qe,{size:14})})]})]},P.id)),e.jsxs("button",{onClick:x,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:[e.jsx(it,{size:11})," Add Connection"]})]})]})]}),e.jsx("div",{className:"mt-auto pt-8 flex flex-col items-center gap-4",children:e.jsxs("div",{className:"flex items-center gap-5 text-xs text-text-4 font-sans",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘K"}),e.jsx("span",{children:"palette"})]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘N"}),e.jsx("span",{children:"spawn"})]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘J"}),e.jsx("span",{children:"terminal"})]})]})})]}),e.jsx(gc,{open:O,onOpenChange:b,currentPath:a||"/home",homePath:a,onSelect:P=>{b(!1),s(P)}}),e.jsx(NC,{}),e.jsx(ZS,{})]})}const Xee={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 Gee(t){var n;const s=(n=t.split(".").pop())==null?void 0:n.toLowerCase();return Xee[s]||"text-text-3"}function Zee({x:t,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]),e.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:t,top:s},children:n.map((l,c)=>l.separator?e.jsx("div",{className:"h-px bg-border-subtle my-1"},c):e.jsxs("button",{onClick:()=>{l.action(),a()},className:Z("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&&e.jsx(l.icon,{size:12,className:l.danger?"text-danger":"text-text-3"}),l.label]},c))})}function Tx({defaultValue:t="",placeholder:s,onSubmit:n,onCancel:a,depth:r=0}){const[l,c]=p.useState(t),A=p.useRef(null);p.useEffect(()=>{var x,h;(x=A.current)==null||x.focus(),t&&((h=A.current)==null||h.select())},[t]);function f(x){if(x.key==="Enter"){const h=l.trim();h&&n(h)}x.key==="Escape"&&a()}return e.jsx("div",{className:"flex items-center py-0.5",style:{paddingLeft:r*16+8},children:e.jsx("input",{ref:A,value:l,onChange:x=>c(x.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 Vee({status:t}){if(!t)return null;const s=t==="A"||t==="?"?"bg-success":t==="D"?"bg-danger":"bg-warning";return e.jsx("span",{className:Z("w-1.5 h-1.5 rounded-full flex-shrink-0",s)})}function Kee(t,s){const n=document.createElement("a");n.href=`/api/files/download?path=${encodeURIComponent(t)}`,n.download=s?`${t.split("/").pop()}.zip`:t.split("/").pop(),document.body.appendChild(n),n.click(),n.remove()}function E4({entry:t,depth:s=0,activePath:n,onFileClick:a,onDirToggle:r,expanded:l,onContextMenu:c,dragState:A,onDragStartEntry:f,onDragEndEntry:x,onSetDragOver:h,onDropOnDir:g,gitStatusMap:O}){const b=t.type==="dir",v=n===t.path,y=l.has(t.path),S=s*16+8,j=(A==null?void 0:A.draggingPath)===t.path,N=b&&(A==null?void 0:A.dragOverPath)===t.path,C=b?null:O==null?void 0:O[t.path];function U(P){P.preventDefault(),P.stopPropagation(),c(P,t)}return e.jsxs("button",{draggable:!0,onDragStart:P=>{P.dataTransfer.setData("application/json",JSON.stringify({path:t.path,name:t.name,type:t.type})),P.dataTransfer.effectAllowed="move",f(t.path)},onDragEnd:x,onDragOver:P=>{P.preventDefault(),b&&(P.stopPropagation(),h(t.path))},onDrop:P=>g(b?t.path:t.path.includes("/")?t.path.split("/").slice(0,-1).join("/"):"",P),onClick:()=>b?r(t.path):a(t.path),onDoubleClick:U,onContextMenu:U,className:Z("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",j&&"opacity-50",N&&"bg-accent/15 ring-1 ring-accent/50 rounded"),style:{paddingLeft:S},children:[b?e.jsxs(e.Fragment,{children:[y?e.jsx(xt,{size:12,className:"text-text-4 flex-shrink-0"}):e.jsx(Tt,{size:12,className:"text-text-4 flex-shrink-0"}),y?e.jsx(Ys,{size:14,className:"text-accent flex-shrink-0"}):e.jsx(Li,{size:14,className:"text-text-3 flex-shrink-0"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-3"}),e.jsx(Lo,{size:14,className:Z("flex-shrink-0",Gee(t.name))})]}),e.jsx("span",{className:"truncate flex-1",children:t.name}),C&&e.jsx(Vee,{status:C})]})}function P4({dirPath:t,depth:s,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:x,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y}){const S=c[t]||[];return p.useEffect(()=>{r.has(t)&&!c[t]&&A(t)},[r,t,c,A]),r.has(t)?e.jsxs(e.Fragment,{children:[(x==null?void 0:x.parentPath)===t&&e.jsx(Tx,{placeholder:x.type==="file"?"filename.ext":"folder-name",onSubmit:x.onSubmit,onCancel:x.onCancel,depth:s}),S.map(j=>e.jsxs("div",{children:[(x==null?void 0:x.renamePath)===j.path?e.jsx(Tx,{defaultValue:j.name,onSubmit:x.onSubmit,onCancel:x.onCancel,depth:s}):e.jsx(E4,{entry:j,depth:s,activePath:n,onFileClick:a,onDirToggle:l,expanded:r,onContextMenu:f,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y}),j.type==="dir"&&e.jsx(P4,{dirPath:j.path,depth:s+1,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:x,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y})]},j.path))]}):null}function qee({rootDir:t,onCollapse:s}){const n=k(L=>L.editorTreeCache),a=k(L=>L.editorActiveFile),r=k(L=>L.openFile),l=k(L=>L.fetchTreeDir),c=k(L=>L.addToast),[A,f]=p.useState(new Set([""])),[x,h]=p.useState(""),[g,O]=p.useState(null),[b,v]=p.useState(null),[y,S]=p.useState({draggingPath:null,dragOverPath:null}),[j,N]=p.useState([]);p.useEffect(()=>{l("")},[l,t]),p.useEffect(()=>{G.get("/files/git-status").then(L=>{N(L.entries||[])}).catch(()=>N([]))},[t]);const C={};for(const L of j)C[L.path]=L.status;function U(L){f(J=>{const D=new Set(J);return D.has(L)?D.delete(L):D.add(L),D})}function P(){f(new Set([""]))}function T(L){S({draggingPath:L,dragOverPath:null})}function B(){S({draggingPath:null,dragOverPath:null})}function F(L){S(J=>J.dragOverPath===L?J:{...J,dragOverPath:L})}async function M(L,J){var V,te;if(J.preventDefault(),J.stopPropagation(),S({draggingPath:null,dragOverPath:null}),((te=(V=J.dataTransfer)==null?void 0:V.files)==null?void 0:te.length)>0){q(L,Array.from(J.dataTransfer.files));return}let D;try{D=JSON.parse(J.dataTransfer.getData("application/json"))}catch{return}if(!(D!=null&&D.path))return;if(D.type==="dir"&&(L===D.path||L.startsWith(D.path+"/"))){c("error","Cannot move a folder into itself");return}const se=W(D.path);if(se===L)return;const le=L?`${L}/${D.name}`:D.name;try{await G.post("/files/rename",{oldPath:D.path,newPath:le}),l(se),l(L),c("success",`Moved ${D.name} to ${L||"/"}`)}catch(ae){c("error","Move failed",ae.message)}}function R(L,J){O({x:L.clientX,y:L.clientY,entry:J})}function Y(L){L.preventDefault(),O({x:L.clientX,y:L.clientY,entry:{type:"dir",path:"",name:"root"}})}function W(L){const J=L.split("/");return J.pop(),J.join("/")}async function ee(L){f(J=>new Set([...J,L])),v({type:"file",parentPath:L,onSubmit:async J=>{const D=L?`${L}/${J}`:J;try{await G.post("/files/create",{path:D,content:""}),l(L),r(D),c("success",`Created ${J}`)}catch(se){c("error","Create failed",se.message)}v(null)},onCancel:()=>v(null)})}async function K(L){f(J=>new Set([...J,L])),v({type:"folder",parentPath:L,onSubmit:async J=>{const D=L?`${L}/${J}`:J;try{await G.post("/files/mkdir",{path:D}),l(L),f(se=>new Set([...se,D])),c("success",`Created ${J}/`)}catch(se){c("error","Create folder failed",se.message)}v(null)},onCancel:()=>v(null)})}async function _(L){v({type:"rename",renamePath:L.path,onSubmit:async J=>{const D=W(L.path),se=D?`${D}/${J}`:J;try{await G.post("/files/rename",{oldPath:L.path,newPath:se}),l(D),c("success",`Renamed to ${J}`)}catch(le){c("error","Rename failed",le.message)}v(null)},onCancel:()=>v(null)})}async function E(L){const J=L.type==="dir"?`folder "${L.name}" and all contents`:`"${L.name}"`;if(window.confirm(`Delete ${J}?`))try{await G.delete(`/files/delete?path=${encodeURIComponent(L.path)}`),l(W(L.path)),c("success",`Deleted ${L.name}`)}catch(D){c("error","Delete failed",D.message)}}async function q(L,J){const D=[];for(const se of J){const le=await new Promise((V,te)=>{const ae=new FileReader;ae.onload=()=>V(ae.result.split(",")[1]),ae.onerror=te,ae.readAsDataURL(se)});D.push({name:se.name,content:le})}try{const se=await G.post("/files/upload",{dir:L,files:D});c("success",`Uploaded ${se.total} file${se.total!==1?"s":""}`),l(L)}catch(se){c("error","Upload failed",se.message)}}function H(L){const J=L.type==="dir",D=[];return J&&(D.push({icon:Vl,label:"New File",action:()=>ee(L.path)}),D.push({icon:RA,label:"New Folder",action:()=>K(L.path)})),L.name!=="root"?(D.push({icon:qs,label:J?"Download as ZIP":"Download",action:()=>Kee(L.path,J)}),D.length>0&&D.push({separator:!0}),D.push({icon:Ua,label:"Rename",action:()=>_(L)}),D.push({icon:Ft,label:"Delete",danger:!0,action:()=>E(L)})):(D.length=0,D.push({icon:Vl,label:"New File",action:()=>ee("")}),D.push({icon:RA,label:"New Folder",action:()=>K("")})),D}const I=n[""]||[];return e.jsxs("div",{className:"flex flex-col h-full bg-surface-1",onContextMenu:Y,children:[e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border-subtle",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(As,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:x,onChange:L=>h(L.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"})]}),e.jsx("button",{onClick:()=>ee(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New file",children:e.jsx(Vl,{size:12})}),e.jsx("button",{onClick:()=>K(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New folder",children:e.jsx(RA,{size:12})}),e.jsx("button",{onClick:()=>l(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Refresh",children:e.jsx(Ls,{size:12})}),e.jsx("button",{onClick:P,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse all",children:e.jsx(wS,{size:12})}),s&&e.jsx("button",{onClick:s,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse sidebar",children:e.jsx(Vx,{size:12})})]}),e.jsx(Qt,{className:"flex-1",children:e.jsxs("div",{className:"py-1 min-h-full",onDragOver:L=>{L.preventDefault(),y.draggingPath&&F(null)},onDrop:L=>M("",L),children:[(b==null?void 0:b.parentPath)===""&&e.jsx(Tx,{placeholder:b.type==="file"?"filename.ext":"folder-name",onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}),I.filter(L=>!x||L.name.toLowerCase().includes(x.toLowerCase())).map(L=>e.jsxs("div",{children:[(b==null?void 0:b.renamePath)===L.path?e.jsx(Tx,{defaultValue:L.name,onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}):e.jsx(E4,{entry:L,depth:0,activePath:a,onFileClick:r,onDirToggle:U,expanded:A,onContextMenu:R,dragState:y,onDragStartEntry:T,onDragEndEntry:B,onSetDragOver:F,onDropOnDir:M,gitStatusMap:C}),L.type==="dir"&&e.jsx(P4,{dirPath:L.path,depth:1,activePath:a,onFileClick:r,expanded:A,onDirToggle:U,treeCache:n,fetchTreeDir:l,onContextMenu:R,inlineInput:b,dragState:y,onDragStartEntry:T,onDragEndEntry:B,onSetDragOver:F,onDropOnDir:M,gitStatusMap:C})]},L.path)),I.length===0&&!x&&e.jsxs("div",{className:"px-3 py-6 text-center",children:[e.jsx("p",{className:"text-xs text-text-4",children:"No files found"}),e.jsx("button",{onClick:()=>l(""),className:"mt-2 text-xs text-accent hover:underline cursor-pointer",children:"Retry"})]})]})}),g&&e.jsx(Zee,{x:g.x,y:g.y,items:H(g.entry),onClose:()=>O(null)})]})}function Wee(){const t=k(y=>y.editorOpenTabs),s=k(y=>y.editorActiveFile),n=k(y=>y.editorFiles),a=k(y=>y.setActiveFile),r=k(y=>y.closeFile),l=p.useRef(null),[c,A]=p.useState(!1),f=p.useCallback(()=>{const y=l.current;y&&A(y.scrollWidth>y.clientWidth)},[]);p.useEffect(()=>{f();const y=l.current;if(!y)return;const S=new ResizeObserver(f);return S.observe(y),()=>S.disconnect()},[f,t.length]);function x(){var y;(y=l.current)==null||y.scrollBy({left:-120,behavior:"smooth"})}function h(){var y;(y=l.current)==null||y.scrollBy({left:120,behavior:"smooth"})}function g(y){t.filter(S=>S!==y).forEach(S=>r(S))}function O(){[...t].forEach(y=>r(y))}function b(y){const S=t.indexOf(y);t.slice(S+1).forEach(j=>r(j))}function v(y){var S;(S=navigator.clipboard)==null||S.writeText(y)}return t.length===0?null:e.jsxs("div",{className:"flex items-stretch h-9 bg-surface-3 border-b border-border-subtle flex-shrink-0",children:[c&&e.jsx("button",{onClick:x,className:"flex-shrink-0 px-1 h-full text-text-4 hover:text-text-1 hover:bg-surface-4 transition-colors cursor-pointer",children:e.jsx(Di,{size:14})}),e.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:t.map(y=>{const S=y===s,j=n[y],N=j&&j.content!==j.originalContent,C=y.split("/").pop();return e.jsxs(Uv,{children:[e.jsx(Ev,{asChild:!0,children:e.jsxs("div",{className:Z("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",S?"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(y),onAuxClick:U=>{U.button===1&&(U.preventDefault(),r(y))},children:[e.jsx("span",{className:"truncate max-w-[120px]",children:C}),N&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-warning flex-shrink-0"}),e.jsx("button",{onClick:U=>{U.stopPropagation(),r(y)},className:"p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 transition-colors cursor-pointer ml-0.5",children:e.jsx(qe,{size:12})})]})}),e.jsxs(Pv,{children:[e.jsxs(ya,{onSelect:()=>r(y),children:[e.jsx(qe,{size:12,className:"text-text-3"})," Close"]}),e.jsxs(ya,{onSelect:()=>g(y),children:[e.jsx(AO,{size:12,className:"text-text-3"})," Close Others"]}),e.jsxs(ya,{onSelect:()=>O(),children:[e.jsx(AO,{size:12,className:"text-text-3"})," Close All"]}),e.jsxs(ya,{onSelect:()=>b(y),children:[e.jsx(Tt,{size:12,className:"text-text-3"})," Close to the Right"]}),e.jsx(Fv,{}),e.jsxs(ya,{onSelect:()=>v(y),children:[e.jsx(Ba,{size:12,className:"text-text-3"})," Copy Path"]})]})]},y)})}),c&&e.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:e.jsx(Tt,{size:14})})]})}const Yee={javascript:"JavaScript",typescript:"TypeScript",css:"CSS",html:"HTML",json:"JSON",markdown:"Markdown",python:"Python"},F4=Object.keys(Po),$4=F4.filter(t=>!["githubLight","vscodeLight","eclipse","xcodeLight","solarizedLight","gruvboxLight","materialLight","duotoneLight","quietlight","bbedit","tokyoNightDay","basicLight"].includes(t)),Jee=F4.filter(t=>!$4.includes(t));function ete({cursorPos:t,language:s}){var A;const n=k(f=>f.editorTheme),a=k(f=>f.setEditorTheme),[r,l]=p.useState(!1),c=p.useRef(null);return p.useEffect(()=>{if(!r)return;function f(x){c.current&&!c.current.contains(x.target)&&l(!1)}return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[r]),e.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:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("span",{children:["Ln ",t.line,", Col ",t.col]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",ref:c,children:[e.jsxs("button",{onClick:()=>l(!r),className:"flex items-center gap-1.5 hover:text-text-0 transition-colors cursor-pointer",children:[e.jsx(YM,{size:10}),e.jsx("span",{children:((A=Po[n])==null?void 0:A.label)||n})]}),r&&e.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:[e.jsx("div",{className:"px-2 py-1 text-2xs text-text-4 font-semibold uppercase tracking-wider",children:"Dark"}),$4.map(f=>e.jsx("button",{onClick:()=>{a(f),l(!1)},className:Z("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:Po[f].label},f)),e.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=>e.jsx("button",{onClick:()=>{a(f),l(!1)},className:Z("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:Po[f].label},f))]})]}),e.jsx("span",{className:"cursor-default",children:Yee[s]||s||"Plain Text"}),e.jsx("span",{children:"Spaces: 2"}),e.jsx("span",{children:"UTF-8"})]})]})}function tte({currentLine:t,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 e.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:[e.jsx("label",{className:"text-2xs font-sans text-text-3 whitespace-nowrap",children:"Go to Line:"}),e.jsx("input",{ref:l,value:a,onChange:A=>r(A.target.value),onKeyDown:c,onBlur:n,placeholder:String(t),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 ste({path:t}){if(!t)return null;const s=t.split("/").filter(Boolean);return e.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 e.jsxs("span",{className:"flex items-center min-w-0",children:[a>0&&e.jsx(Tt,{size:10,className:"mx-0.5 flex-shrink-0 text-text-4"}),e.jsx("span",{className:r?"text-text-1 font-medium truncate":"hover:text-text-1 cursor-pointer truncate transition-colors",children:n})]},a)})})}function nte(t){var n;const s=(n=t==null?void 0:t.split(".").pop())==null?void 0:n.toLowerCase();return s==="html"||s==="htm"}const ate=240,rte=160,ote=400;function ite(){const t=k(J=>J.editorActiveFile),s=k(J=>J.editorFiles),n=k(J=>J.updateFileContent),a=k(J=>J.saveFile),r=k(J=>J.editorSidebarWidth),l=k(J=>J.setEditorSidebarWidth),c=k(J=>J.projectDir),[A,f]=p.useState(""),[x,h]=p.useState(!1),[g,O]=p.useState(0),[b,v]=p.useState({line:1,col:1}),[y,S]=p.useState(!1),[j,N]=p.useState(!1),[C,U]=p.useState(!1),P=p.useRef(0),T=k(J=>J.addToast),B=k(J=>J.fetchTreeDir),F=p.useRef(null),M=p.useRef(!1),R=p.useRef(0),Y=p.useRef(0);p.useEffect(()=>{G.get("/files/root").then(J=>f(J.root||"")).catch(()=>{})},[c]),p.useEffect(()=>{h(!1)},[t]),p.useEffect(()=>{function J(D){(D.metaKey||D.ctrlKey)&&D.key==="g"&&(D.preventDefault(),S(!0))}return document.addEventListener("keydown",J),()=>document.removeEventListener("keydown",J)},[]);function W(J){var D,se;J.preventDefault(),P.current++,(se=(D=J.dataTransfer)==null?void 0:D.types)!=null&&se.includes("Files")&&U(!0)}function ee(J){J.preventDefault(),P.current--,P.current<=0&&(P.current=0,U(!1))}function K(J){J.preventDefault(),J.dataTransfer.dropEffect="copy"}async function _(J){var le;J.preventDefault(),P.current=0,U(!1);const D=(le=J.dataTransfer)==null?void 0:le.files;if(!(D!=null&&D.length))return;const se=[];for(const V of Array.from(D)){const te=await new Promise((ae,be)=>{const z=new FileReader;z.onload=()=>ae(z.result.split(",")[1]),z.onerror=be,z.readAsDataURL(V)});se.push({name:V.name,content:te})}try{const V=await G.post("/files/upload",{dir:"",files:se});T("success",`Uploaded ${V.total} file${V.total!==1?"s":""}`),B("")}catch(V){T("error","Upload failed",V.message)}}const E=p.useCallback(J=>{J.preventDefault(),M.current=!0,R.current=J.clientX,Y.current=r;function D(le){if(!M.current)return;const V=le.clientX-R.current,te=Math.min(Math.max(Y.current+V,rte),ote);l(te)}function se(){M.current=!1,document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",se)}document.addEventListener("mousemove",D),document.addEventListener("mouseup",se)},[r,l]);function q(J){const D=F.current;if(!D)return;const se=D.state.doc.line(Math.min(J,D.state.doc.lines));D.dispatch({selection:{anchor:se.from},scrollIntoView:!0}),D.focus()}const H=t?s[t]:null,I=t&&g5(t),L=t&&nte(t);return e.jsxs("div",{className:"flex h-full",children:[e.jsxs("div",{className:Z("relative flex-shrink-0 border-r border-border transition-all duration-200 overflow-hidden",j&&"w-0 border-r-0"),style:j?void 0:{width:r},children:[e.jsx(qee,{rootDir:A,onCollapse:()=>N(!0)}),e.jsx("div",{className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:E,onDoubleClick:()=>l(ate)})]}),j&&e.jsx("button",{onClick:()=>N(!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:e.jsx(Kx,{size:14})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-surface-1 relative",onDragEnter:W,onDragLeave:ee,onDragOver:K,onDrop:_,children:[C&&e.jsx("div",{className:"absolute inset-0 z-50 bg-accent/8 border-2 border-dashed border-accent/40 rounded-lg flex items-center justify-center pointer-events-none",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 text-accent",children:[e.jsx(Hb,{size:32}),e.jsx("span",{className:"text-sm font-semibold font-sans",children:"Drop files to upload"})]})}),e.jsx(Wee,{}),t&&!I&&e.jsx(ste,{path:t}),e.jsxs("div",{className:"flex-1 relative min-h-0",children:[y&&e.jsx(tte,{currentLine:b.line,onGoto:q,onClose:()=>S(!1)}),!t&&e.jsx("div",{className:"w-full h-full flex items-center justify-center text-text-4 font-sans",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(bn,{size:32,className:"mx-auto"}),e.jsx("p",{className:"text-sm",children:"Open a file from the tree"})]})}),t&&I&&e.jsx(O5,{path:t}),t&&!I&&L&&e.jsxs(e.Fragment,{children:[e.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:[e.jsxs("button",{onClick:()=>h(!1),className:Z("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",x?"text-text-3 hover:text-text-1":"bg-surface-4 text-text-0 font-medium"),children:[e.jsx(Fb,{size:12})," Code"]}),e.jsxs("button",{onClick:()=>{h(!0),O(J=>J+1)},className:Z("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",x?"bg-surface-4 text-text-0 font-medium":"text-text-3 hover:text-text-1"),children:[e.jsx(Vs,{size:12})," Preview"]})]}),x?e.jsx("iframe",{src:`/api/files/raw?path=${encodeURIComponent(t)}`,className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin",title:"HTML Preview"},g):H&&e.jsx(KO,{content:H.content,language:H.language,onChange:J=>n(t,J),onSave:()=>a(t),onCursorChange:v,viewRef:F})]}),t&&!I&&!L&&H&&e.jsx(KO,{content:H.content,language:H.language,onChange:J=>n(t,J),onSave:()=>a(t),onCursorChange:v,viewRef:F})]}),t&&!I&&e.jsx(ete,{cursorPos:b,language:H==null?void 0:H.language})]})]})}function lte(){var C;const t=k(U=>U.connected),s=k(U=>U.agents),[n,a]=p.useState(null),[r,l]=p.useState([]),[c,A]=p.useState({constraints:[],discoveries:[],roles:[],specializations:null}),[f,x]=p.useState(!0),[h,g]=p.useState({tokens:[],cost:[],saved:[],efficiency:[],cache:[],inputOutput:[],agents:[],turns:[]}),O=p.useRef(0);p.useEffect(()=>{if(!t)return;let U=!0;async function P(){try{const[B,F,M,R,Y,W]=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(!U)return;a(B),l((F==null?void 0:F.teams)||[]),A({constraints:(M==null?void 0:M.constraints)||[],discoveries:(R==null?void 0:R.discoveries)||[],roles:(Y==null?void 0:Y.roles)||[],specializations:W||{perAgent:{},perProjectRole:{}}}),x(!1),O.current=Date.now(),g(ee=>{var D,se,le,V,te,ae,be,z,oe;const K=Date.now(),_=(ue,ve)=>[...ue.slice(-59),{t:K,v:ve||0}],E=((D=B.tokens)==null?void 0:D.totalTokens)||0,q=((se=B.tokens)==null?void 0:se.totalInputTokens)||0,H=((le=B.tokens)==null?void 0:le.totalOutputTokens)||0,L=(((V=B.agents)==null?void 0:V.breakdown)||[]).filter(ue=>{var ve;return((ve=ue.quality)==null?void 0:ve.score)!=null}),J=L.length>0?L.reduce((ue,ve)=>ue+ve.quality.score,0)/L.length:0;return{tokens:_(ee.tokens,E),cost:_(ee.cost,(te=B.tokens)==null?void 0:te.totalCostUsd),saved:_(ee.saved,J),efficiency:_(ee.efficiency,((ae=B.rotation)==null?void 0:ae.totalRotations)||0),cache:_(ee.cache,(be=B.tokens)==null?void 0:be.cacheHitRate),inputOutput:_(ee.inputOutput,H>0?q/H:0),agents:_(ee.agents,((z=B.agents)==null?void 0:z.running)||0),turns:_(ee.turns,(oe=B.tokens)==null?void 0:oe.totalTurns)}})}catch{U&&x(!1)}}P();const T=setInterval(P,4e3);return()=>{U=!1,clearInterval(T)}},[t]);const b=((C=n==null?void 0:n.agents)==null?void 0:C.breakdown)||[],v=(n==null?void 0:n.routing)||null,y=(n==null?void 0:n.rotation)||null,S=(n==null?void 0:n.adaptive)||[],j=(n==null?void 0:n.journalist)||null,N=(y==null?void 0:y.rotating)||[];return{data:n,loading:f,agents:s,connected:t,kpiHistory:h,lastFetch:O.current,agentBreakdown:b,routing:v,rotation:y,adaptive:S,journalist:j,rotating:N,teamBurn:r,memory:c}}const CQ=p.memo(function({connected:s,runningCount:n,totalCount:a,uptime:r,lastFetch:l,activeTeam:c}){return e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 bg-surface-1 border-b border-border",children:[e.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Command Center"}),c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-xs font-mono text-text-2",children:c.name})]}),e.jsx("div",{className:"flex-1"}),s&&e.jsxs("div",{className:"flex items-center gap-3.5 text-xs font-mono text-text-2",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-text-1",children:n}),e.jsxs("span",{className:"text-text-3",children:["/",a]}),e.jsx("span",{className:"ml-1 text-text-3",children:"agents"})]}),r>0&&e.jsxs("span",{className:"text-text-3",children:["Up ",Xo(r)]}),l>0&&e.jsxs("span",{className:"flex items-center gap-1 text-text-4",children:[e.jsx(Ls,{size:9}),e.jsx("span",{children:$t(l)})]})]}),e.jsx(Gt,{status:s?"running":"crashed",size:"sm"})]})});function nt(t,s){const n=parseInt(t.slice(1,3),16),a=parseInt(t.slice(3,5),16),r=parseInt(t.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 cte({data:t,color:s=ce.text3,width:n=72,height:a=22}){if(!t||t.length<2)return e.jsx("div",{style:{width:n,height:a}});const r=t.map(h=>h.v),l=Math.min(...r),A=Math.max(...r)-l||1,f=t.map((h,g)=>{const O=g/(t.length-1)*n,b=a-(h.v-l)/A*(a-2)-1;return`${O},${b}`}).join(" "),x=`kpi-${s.replace("#","")}`;return e.jsxs("svg",{width:n,height:a,className:"flex-shrink-0",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:x,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:s,stopOpacity:"0.2"}),e.jsx("stop",{offset:"100%",stopColor:s,stopOpacity:"0"})]})}),e.jsx("polygon",{points:`0,${a} ${f} ${n},${a}`,fill:`url(#${x})`}),e.jsx("polyline",{points:f,fill:"none",stroke:s,strokeWidth:"1.5",strokeLinejoin:"round",strokeOpacity:"0.8"})]})}const Ate=p.memo(function({label:s,value:n,sparkData:a,color:r=ce.text3,hint:l,className:c}){return e.jsxs("div",{className:Z("flex items-center gap-2.5 px-3 py-2.5 min-w-0","bg-surface-1",c),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.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&&e.jsx(dt,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:l}),side:"bottom",children:e.jsx(ki,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors"})})]}),e.jsx("div",{className:"text-base font-semibold font-mono text-text-0 tabular-nums leading-none",children:n})]}),e.jsx(cte,{data:a,color:r})]})});function dte({kpis:t}){return e.jsx("div",{className:"flex flex-wrap border-b border-border bg-surface-0",children:t.map(s=>e.jsx(Ate,{label:s.label,value:s.value,sparkData:s.sparkData,color:s.color,hint:s.hint,className:Z("flex-1 basis-[12.5%] min-w-[140px]","border-b border-r border-border")},s.label))})}const ute={actual:"ACT",estimated:"EST",local:"LOC"};function fte(t){if(!t||t==="auto"||t==="default")return"default";const s=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gem ").replace("-preview",""):t.length>12?t.slice(0,12)+"...":t}const xte=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:Gb(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,x=Ha(s.role),h=ce.text1;return e.jsxs("div",{className:"px-3 pl-6 py-2 hover:bg-surface-4 transition-colors space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:l}}),a&&e.jsx("span",{className:"absolute inset-[-2px] rounded-sm",style:{background:l,opacity:.15,animation:"node-pulse-bar 2s ease-in-out infinite"}})]}),e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate leading-none flex-shrink-0 max-w-[80px]",children:s.name}),e.jsx("span",{className:"text-2xs font-mono font-semibold px-1.5 py-px rounded-sm flex-shrink-0 capitalize",style:{background:x.bg,color:x.text},children:(s.role||"").toLowerCase()}),e.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:fte(s.model)}),e.jsx("div",{className:"flex-1"}),A!=null&&e.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"&&e.jsx("span",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex-shrink-0",children:ute[s.costSource]||""}),e.jsxs("div",{className:"text-right flex-shrink-0",children:[e.jsx("div",{className:"text-xs font-mono text-text-1 tabular-nums leading-none",children:jt(s.tokens||0)}),(s.costUsd||0)>0&&e.jsx("div",{className:"text-2xs font-mono text-text-3 mt-0.5",children:er(s.costUsd)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 h-0.5 rounded-sm overflow-visible",style:{background:nt(ce.text4,.2)},children:[e.jsx("div",{className:"absolute inset-y-0 left-0 rounded-sm transition-all duration-700",style:{width:`${Math.max(r,1)}%`,background:h}}),f&&e.jsx("div",{className:"absolute top-[-1px] w-px h-[4px]",style:{left:`${f}%`,background:ce.text3},title:`Rotation at ${f}%`})]}),e.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums flex-shrink-0 w-7 text-right",children:[r,"%"]})]})]})});function mte({team:t,members:s,rotatingSet:n}){const[a,r]=p.useState(!0),l=s.filter(x=>x.status==="running"||x.status==="starting").length,c=l>0,A=s.reduce((x,h)=>x+(h.tokens||0),0),f=s.reduce((x,h)=>x+(h.costUsd||0),0);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>r(x=>!x),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?e.jsx(xt,{size:10,className:"text-text-4 flex-shrink-0"}):e.jsx(Tt,{size:10,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-mono font-semibold text-text-2 uppercase tracking-widest flex-1 truncate",children:t}),e.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:jt(A)}),f>0&&e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums ml-1",children:er(f)}),e.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(x=>e.jsx(xte,{agent:x,isRotating:n.has(x.id)},x.id))]})}const hte=p.memo(function({agentBreakdown:s,rotating:n=[],teams:a=[]}){if(!(s!=null&&s.length))return e.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 e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"py-1",children:Object.entries(l).map(([A,f])=>e.jsx(mte,{team:r[A]||(A==="ungrouped"?"Ungrouped":A),members:f,rotatingSet:c},A))})})}),Is=36,nb=3,Wf=(Is-nb)/2,Qf=2*Math.PI*Wf,BQ=-90;function pte(){return ce.text1}function gte({name:t,pct:s,threshold:n}){const a=pte(),r=s/100*Qf;return e.jsxs("div",{className:"flex flex-col items-center gap-0.5",title:`${t}: ${s}% context used`,children:[e.jsxs("svg",{width:Is,height:Is,viewBox:`0 0 ${Is} ${Is}`,children:[e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:nb,className:"stroke-surface-4"}),e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:nb,strokeLinecap:"round",style:{stroke:a,strokeDasharray:`${r} ${Qf-r}`,strokeDashoffset:0,transition:"stroke-dasharray 0.5s ease"},transform:`rotate(${BQ} ${Is/2} ${Is/2})`}),n&&e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:1,strokeLinecap:"butt",style:{stroke:ce.text3,strokeDasharray:`1 ${Qf-1}`,strokeDashoffset:-(n/100)*Qf},transform:`rotate(${BQ} ${Is/2} ${Is/2})`}),e.jsx("text",{x:Is/2,y:Is/2+1,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-1 font-mono font-semibold",style:{fontSize:9},children:s})]}),e.jsx("span",{className:"text-2xs font-mono text-text-3 truncate max-w-[40px] leading-none",children:t})]})}function Ote({zones:t}){return e.jsxs("div",{className:"flex items-center gap-2 text-2xs font-mono",children:[e.jsx("span",{className:"text-text-2",children:t.healthy}),e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-text-2",children:t.warning}),e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-text-2",children:t.critical})]})}const bte=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 e.jsxs("div",{className:"px-3 py-2 flex-shrink-0 border-b border-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Context Health"}),e.jsx(Ote,{zones:a})]}),e.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 e.jsx(gte,{name:r.name,pct:l,threshold:c},r.id)})})]})}),vte=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:x}=r,h={top:28,right:12,bottom:8,left:12},g=Math.max(f-h.left-h.right,0),O=Math.max(x-h.top-h.bottom,0),b=p.useMemo(()=>!s||s.length<2?[]:s.slice(1).map((S,j)=>{const N=s[j],C=(S.t-N.t)/6e4,U=Math.max((S.tokens||0)-(N.tokens||0),0);return{burnRate:C>0?Math.round(U/C):0,cacheHitRate:S.cacheHitRate||0,running:S.running||0,agents:S.agents||0,t:S.t}}),[s]);p.useEffect(()=>{const S=n.current;if(!S)return;const j=new ResizeObserver(N=>{const{width:C,height:U}=N[0].contentRect;C>0&&U>0&&l({width:Math.floor(C),height:Math.floor(U)})});return j.observe(S),()=>j.disconnect()},[]);const v=p.useCallback(S=>{const j=a.current;if(!j||!b.length||g<=0)return;const N=j.getBoundingClientRect(),C=S.clientX-N.left-h.left;if(C<0||C>g){A(null);return}const U=Math.round(C/g*(b.length-1));A({x:h.left+U/Math.max(b.length-1,1)*g,index:U})},[b,g,h.left]),y=p.useCallback(()=>A(null),[]);return p.useEffect(()=>{const S=a.current;if(!S||!b.length||f<=0||x<=0||g<=0||O<=0)return;const j=S.getContext("2d"),N=window.devicePixelRatio||1;S.width=f*N,S.height=x*N,j.scale(N,N),j.clearRect(0,0,f,x);const C=b.map(E=>E.burnRate),U=b.map(E=>E.cacheHitRate),P=b.map(E=>E.running),T=Math.max(...C,100),B=Math.max(...P,1),F=E=>h.left+E/Math.max(b.length-1,1)*g,M=E=>h.top+O-E/T*O,R=E=>h.top+O-E*O,Y=Math.max(g/b.length-1,2);for(let E=0;E<b.length;E++){const q=P[E];if(q<=0)continue;const H=q/B*O*.3,I=F(E)-Y/2,L=h.top+O-H;j.fillStyle=nt(ce.surface5,.5),j.fillRect(I,L,Y,H)}j.setLineDash([2,4]),j.strokeStyle=nt(ce.text4,.2),j.lineWidth=1;for(let E=1;E<=3;E++){const q=h.top+O/4*E;j.beginPath(),j.moveTo(h.left,q),j.lineTo(h.left+g,q),j.stroke()}j.setLineDash([]),j.font="9px 'SF Mono', ui-monospace, Menlo, Consolas, monospace",j.textAlign="left",j.fillStyle=nt(ce.text3,.5),j.fillText(`${jt(T)}/m`,h.left+4,h.top+10),j.fillText(`${jt(Math.round(T/2))}/m`,h.left+4,h.top+O/2+4),j.beginPath(),j.moveTo(h.left,h.top+O);for(let E=0;E<b.length;E++)j.lineTo(F(E),M(C[E]));j.lineTo(F(b.length-1),h.top+O),j.closePath();const W=j.createLinearGradient(0,h.top,0,h.top+O);W.addColorStop(0,nt(ce.accent,.2)),W.addColorStop(.7,nt(ce.accent,.04)),W.addColorStop(1,nt(ce.accent,0)),j.fillStyle=W,j.fill(),j.beginPath(),j.strokeStyle=ce.accent,j.lineWidth=1.5,j.lineJoin="round";for(let E=0;E<b.length;E++){const q=F(E),H=M(C[E]);E===0?j.moveTo(q,H):j.lineTo(q,H)}j.stroke();const ee=U.some(E=>E>0);if(ee){j.beginPath(),j.strokeStyle=nt(ce.text2,.5),j.lineWidth=1,j.lineJoin="round",j.setLineDash([2,3]);for(let E=0;E<b.length;E++){const q=F(E),H=R(U[E]);E===0?j.moveTo(q,H):j.lineTo(q,H)}j.stroke(),j.setLineDash([])}j.font="9px 'Inter Variable', sans-serif",j.textAlign="right";let K=f-h.right-4;const _=14;if(ee&&(j.fillStyle=nt(ce.text2,.5),j.fillText("Cache %",K,_),K-=j.measureText("Cache %").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),K-=14),j.fillStyle=nt(ce.surface5,.7),j.fillText("Agents",K,_),K-=j.measureText("Agents").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),K-=14,j.fillStyle=ce.accent,j.fillText("Burn Rate",K,_),K-=j.measureText("Burn Rate").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),c&&c.index>=0&&c.index<b.length){const E=c.x,q=b[c.index];j.beginPath(),j.moveTo(E,h.top),j.lineTo(E,h.top+O),j.strokeStyle=nt(ce.text1,.15),j.lineWidth=1,j.stroke();const H=M(q.burnRate);j.beginPath(),j.arc(E,H,3,0,Math.PI*2),j.fillStyle=ce.accent,j.fill();const I=[{label:"Burn",value:`${jt(q.burnRate)}/m`,color:ce.accent},{label:"Cache",value:pc(q.cacheHitRate*100),color:ce.text2},{label:"Agents",value:`${q.running}/${q.agents}`,color:ce.text3}],L=104,J=I.length*16+12;let D=E+12;D+L>f-8&&(D=E-L-12);const se=Math.max(h.top,H-J/2);j.fillStyle=nt(ce.surface0,.92),j.beginPath(),j.roundRect(D,se,L,J,4),j.fill(),j.strokeStyle=nt(ce.text4,.2),j.lineWidth=1,j.stroke(),j.textAlign="left",I.forEach((le,V)=>{const te=se+14+V*16;j.beginPath(),j.arc(D+8,te-3,2,0,Math.PI*2),j.fillStyle=le.color,j.fill(),j.font="8px 'Inter Variable', sans-serif",j.fillStyle=ce.text3,j.fillText(le.label,D+14,te),j.font="9px 'SF Mono', ui-monospace, Menlo, Consolas, monospace",j.fillStyle=ce.text0,j.textAlign="right",j.fillText(le.value,D+L-8,te),j.textAlign="left"})}},[b,f,x,c,g,O,h]),e.jsx("div",{ref:n,className:"absolute inset-0",children:f>0&&x>0&&e.jsx("canvas",{ref:a,style:{width:f,height:x},className:"block cursor-crosshair",onMouseMove:v,onMouseLeave:y})})}),yte=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 x=l.current;if(!x)return;const h=window.devicePixelRatio||1;x.width=r*h,x.height=r*h;const g=x.getContext("2d");g.scale(h,h),g.clearRect(0,0,r,r);const O=r/2,b=r/2,v=(r-12)/2,y=5,S=135*Math.PI/180,j=405*Math.PI/180,N=j-S;if(g.beginPath(),g.arc(O,b,v,S,j),g.strokeStyle=ce.surface4,g.lineWidth=y,g.lineCap="round",g.stroke(),A>0){const C=s/A,U=n/A;if(C>0){const P=S+N*C;g.beginPath(),g.arc(O,b,v,S,P),g.strokeStyle=ce.text0,g.lineWidth=y,g.lineCap="round",g.stroke()}if(U>0){const P=S+N*C,T=P+N*U;g.beginPath(),g.arc(O,b,v,P,T),g.strokeStyle=ce.text3,g.lineWidth=y,g.lineCap="butt",g.stroke()}}g.textAlign="center",g.textBaseline="middle",g.font=`600 ${r*.2}px 'SF Mono', ui-monospace, Menlo, Consolas, monospace`,g.fillStyle=ce.text0,g.fillText(`${Math.round(f)}%`,O,b-3),g.font=`500 ${r*.08}px 'SF Mono', ui-monospace, Menlo, Consolas, monospace`,g.fillStyle=ce.text3,g.fillText("CACHE",O,b+r*.13)},[s,n,a,r,A,f]),e.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-3 py-3",children:[e.jsx("canvas",{ref:l,className:"flex-shrink-0",style:{width:r,height:r}}),e.jsxs("div",{className:"w-full mt-3 space-y-1.5 max-w-[160px]",children:[e.jsx(Lg,{color:ce.text0,label:"Read",value:jt(s)}),e.jsx(Lg,{color:ce.text3,label:"Create",value:jt(n)}),e.jsx(Lg,{color:ce.surface5,label:"Miss",value:jt(Math.max(a-s-n,0))})]})]})});function Lg({color:t,label:s,value:n}){return e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:t}}),e.jsx("span",{className:"text-text-3 uppercase tracking-wider flex-1",children:s}),e.jsx("span",{className:"text-text-1 tabular-nums",children:n})]})}const R4={heavy:ce.text0,medium:ce.text2,light:ce.text4},wte={heavy:"Heavy",medium:"Medium",light:"Light"},an=80,ab=6,rb=(an-ab)/2,kQ=2*Math.PI*rb;function jte({byTier:t,total:s,tiers:n}){let a=0;const r=[];for(const l of n){const c=t[l]||0;if(c===0)continue;const f=c/s*kQ;r.push({tier:l,dashLen:f,offset:a}),a+=f}return s>0&&Math.round((t.heavy||0)/s*100),e.jsxs("svg",{width:an,height:an,viewBox:`0 0 ${an} ${an}`,className:"flex-shrink-0",children:[e.jsx("circle",{cx:an/2,cy:an/2,r:rb,fill:"none",strokeWidth:ab,className:"stroke-surface-4"}),r.map(l=>e.jsx("circle",{cx:an/2,cy:an/2,r:rb,fill:"none",strokeWidth:ab,strokeLinecap:"butt",style:{stroke:R4[l.tier],strokeDasharray:`${l.dashLen} ${kQ-l.dashLen}`,strokeDashoffset:-l.offset},transform:`rotate(-90 ${an/2} ${an/2})`},l.tier)),e.jsx("text",{x:an/2,y:an/2-2,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-0 text-sm font-mono font-semibold",children:jt(s)}),e.jsx("text",{x:an/2,y:an/2+11,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-3 font-mono",style:{fontSize:7},children:"decisions"})]})}const Qte=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 x=Object.entries(f).sort((g,O)=>O[1].tokens-g[1].tokens),h=x.length>0?x[0][1].tokens:0;return e.jsxs("div",{className:"flex flex-col h-full px-3 py-3 overflow-y-auto",children:[A>0&&e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(jte,{byTier:a,total:A,tiers:c}),e.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 e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:R4[g]}}),e.jsx("span",{className:"text-2xs font-mono text-text-2 flex-1",children:wte[g]}),e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums",children:O}),e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums w-8 text-right",children:pc(b)})]},g)}),l>0&&e.jsxs("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:[l," auto-routed"]})]})]}),x.length>0&&e.jsxs("div",{className:"space-y-1.5 flex-1",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Models in Use"}),e.jsx("div",{className:"space-y-1.5",children:x.map(([g,O])=>{const b=h>0?O.tokens/h*100:0;return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 flex-1 truncate",children:Nte(g)}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[O.agents," agent",O.agents!==1?"s":""]}),e.jsx("span",{className:"text-xs font-mono text-text-1 tabular-nums",children:jt(O.tokens)})]}),e.jsx("div",{className:"h-0.5 bg-surface-4 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-500",style:{width:`${Math.max(b,2)}%`,background:ce.text2}})})]},g)})})]}),A===0&&x.length===0&&e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono",children:"No routing data"})]})});function Nte(t){if(!t||t==="auto"||t==="default")return"Default";const s=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gemini ").replace("-preview",""):t}function M4({text:t}){return e.jsx(dt,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:t}),side:"bottom",children:e.jsx(ki,{size:9,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors ml-0.5"})})}function Ste({children:t,tip:s}){return e.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex items-center gap-0.5",children:[t,s&&e.jsx(M4,{text:s})]})}function Nf({label:t,value:s,tip:n}){return e.jsxs("div",{children:[e.jsx(Ste,{tip:n,children:t}),e.jsx("div",{className:"text-sm font-mono font-semibold text-text-1 tabular-nums leading-snug",children:s})]})}function jd({title:t,children:s,tip:n}){return e.jsxs("div",{className:"px-3 py-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider mb-2 flex items-center gap-0.5",children:[t,n&&e.jsx(M4,{text:n})]}),s]})}function vc(){return e.jsx("div",{className:"h-px bg-border mx-3"})}function Cte({tokens:t,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 e.jsxs("div",{className:"px-3 py-3 flex items-start gap-5",children:[e.jsx(Nf,{label:"Quality",value:l??"—",tip:"Average session quality (0-100). Below 40 triggers auto-rotation."}),e.jsx(Nf,{label:"Cache",value:pc(((t==null?void 0:t.cacheHitRate)||0)*100),tip:"Prompt cache hit rate. Higher = faster + cheaper."}),e.jsx(Nf,{label:"Rotations",value:(s==null?void 0:s.totalRotations)||0,tip:"Total context rotations this session."}),((t==null?void 0:t.totalCostUsd)||0)>0&&e.jsx(Nf,{label:"Cost",value:er(t.totalCostUsd),tip:"Total cost reported by providers."})]})}function Bte({agentBreakdown:t,rotation:s}){const n=(s==null?void 0:s.liveScores)||{},a=(t||[]).filter(r=>r.status==="running");return a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Live agents",children:e.jsx("div",{className:"space-y-0",children:a.map(r=>{var x;const l=r.quality||{},c=((x=n[r.id])==null?void 0:x.score)??l.score,A=Ha(r.role),f=[l.errorCount>0&&`${l.errorCount} err`,l.repetitions>0&&`${l.repetitions} rep`,l.fileChurn>0&&`${l.fileChurn} churn`].filter(Boolean);return e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[e.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}),e.jsx("span",{className:"text-text-2 truncate flex-1",children:r.name}),f.length>0&&e.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:f.join(" · ")}),e.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0 w-6 text-right",children:c??"—"})]},r.id)})})})]})}function kte({rotation:t}){const s=((t==null?void 0:t.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":pc((a.contextUsage||0)*100)}return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Recent rotations",children:e.jsx("div",{className:"space-y-0",children:s.map((a,r)=>e.jsxs("div",{className:"flex items-center gap-2 py-0.5 text-xs font-mono",children:[e.jsx("span",{className:"text-text-2 truncate flex-1",children:a.agentName||a.role}),e.jsx("span",{className:"text-text-3 flex-shrink-0",children:n(a)}),e.jsx("span",{className:"text-text-4 flex-shrink-0 w-10 text-right",children:$t(a.timestamp)})]},r))})})]})}function Tte({adaptive:t}){if(!(t!=null&&t.length))return null;function s(n){const a=n.split(":");return{provider:a[0]||n,role:a[1]||""}}return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Adaptive thresholds",tip:"Per-role rotation thresholds. GROOVE learns when each role benefits from rotation and adjusts automatically.",children:e.jsx("div",{className:"space-y-0",children:t.map(n=>{const{provider:a,role:r}=s(n.key),l=r||a,c=Ha(l);return e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[e.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&&e.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:a}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0",children:pc(n.threshold*100)}),n.converged?e.jsx("span",{className:"text-2xs font-semibold flex-shrink-0",style:{color:ce.accent},children:"Converged"}):e.jsxs("span",{className:"text-2xs text-text-3 flex-shrink-0 flex items-center gap-1",children:[e.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 Ute({journalist:t}){return!t||!((t.cycleCount||0)>0)&&!t.synthesizing?null:e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs(jd,{title:"Journalist",children:[e.jsxs("div",{className:"flex items-center gap-3 text-xs font-mono",children:[e.jsxs("span",{className:"text-text-2",children:[t.cycleCount||0," cycles"]}),t.lastCycleAt&&e.jsx("span",{className:"text-text-4",children:$t(t.lastCycleAt)}),t.synthesizing&&e.jsx("span",{className:"font-semibold text-accent animate-pulse",children:"Synthesizing"})]}),t.lastSummary&&e.jsx("div",{className:"text-xs text-text-3 leading-relaxed mt-1.5 line-clamp-3",children:t.lastSummary})]})]})}function Ete({memory:t}){var f,x;const s=(t==null?void 0:t.constraints)||[],n=(t==null?void 0:t.discoveries)||[],a=(t==null?void 0:t.roles)||[],r=((f=t==null?void 0:t.specializations)==null?void 0:f.perProjectRole)||{},l=Object.keys(((x=t==null?void 0:t.specializations)==null?void 0:x.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 e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs(jd,{title:"Memory",tip:"Persistent knowledge across agent rotations. Constraints, error→fix discoveries, and handoff chains.",children:[e.jsx("div",{className:"text-xs font-mono text-text-3 mb-1.5",children:A.join(" · ")}),s.length>0&&e.jsxs("div",{className:"mt-2 space-y-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Constraints"}),s.slice(0,3).map(h=>e.jsx("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:h.text},h.hash)),s.length>3&&e.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",s.length-3," more"]})]}),n.length>0&&e.jsxs("div",{className:"mt-2 space-y-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Discoveries"}),n.slice(0,3).map((h,g)=>e.jsxs("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:[e.jsx("span",{className:"text-text-4",children:h.trigger})," → ",h.fix]},g)),n.length>3&&e.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",n.length-3," more"]})]}),Object.keys(r).length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Role quality"}),e.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-0.5",children:Object.entries(r).map(([h,g])=>e.jsxs("span",{className:"text-xs font-mono text-text-3",children:[e.jsx("span",{className:"text-text-2 capitalize",children:h})," Q:",g.avgQualityScore," ",e.jsxs("span",{className:"text-text-4",children:["(",g.sessionCount,"s)"]})]},h))})]})]})]})}function Pte({tokens:t}){var r,l;if(!((r=t==null?void 0:t.internalOverhead)!=null&&r.tokens)||!((l=t==null?void 0:t.savings)!=null&&l.total))return null;const s=t.internalOverhead,n=t.savings,a=t.totalTokens>0?Math.round(s.tokens/t.totalTokens*100):0;return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs("div",{className:"px-3 py-2.5 flex items-center gap-3 text-xs font-mono",children:[e.jsx("span",{className:"text-text-4",children:"Overhead"}),e.jsxs("span",{className:"text-text-3 tabular-nums",children:[jt(s.tokens)," (",a,"%)"]}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-text-4",children:"Saved"}),e.jsx("span",{className:"text-text-3 tabular-nums",children:jt(n.total)})]})]})}const Fte=p.memo(function({tokens:s,rotation:n,adaptive:a,journalist:r,agentBreakdown:l,memory:c}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-shrink-0 px-3 pt-2.5 pb-1.5",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Intel"})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[e.jsx(Cte,{tokens:s,rotation:n,agentBreakdown:l}),e.jsx(Bte,{agentBreakdown:l,rotation:n}),e.jsx(kte,{rotation:n}),e.jsx(Tte,{adaptive:a}),e.jsx(Ute,{journalist:r}),e.jsx(Ete,{memory:c}),e.jsx(Pte,{tokens:s}),e.jsx("div",{className:"h-3"})]})]})}),$te=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 e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0 flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Team Burn"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3",children:[jt(n)," total"]})]}),e.jsx(Qt,{className:"flex-1 min-h-0",children:s.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-text-3 font-mono",children:"No team activity yet"}):e.jsx("div",{className:"px-3 py-3 space-y-3",children:s.map(r=>{const l=a>0?r.totalTokens/a*100:0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:r.teamName}),r.isDefault&&e.jsx("span",{className:"text-[9px] font-mono text-text-3 uppercase tracking-wider",children:"default"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 flex-shrink-0",children:[r.agentCount," ",r.agentCount===1?"agent":"agents"]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 font-mono text-2xs",children:[e.jsx("span",{className:"text-text-1",children:jt(r.totalTokens)}),e.jsx("span",{className:"text-text-3",children:er(r.totalCostUsd)})]})]}),e.jsx("div",{className:"h-0.5 bg-surface-2 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all",style:{width:`${l}%`,background:ce.text3}})})]},r.teamId)})})})]})}),Rte={spawn:HS,complete:Ga,crash:Aa,kill:AO,rotate:hd,error:Db},Mte={spawn:"text-text-2",complete:"text-text-2",crash:"text-danger",kill:"text-text-3",rotate:"text-text-2",error:"text-danger"};function Ite(t){const s=t.agentName||t.role||"";switch(t.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 t.text||t.type||"event"}}const zte=p.memo(function({events:s=[]}){return s.length?e.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=Rte[n.type]||qt,l=Mte[n.type]||"text-text-3",c=Ite(n);return e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx(r,{size:11,className:l}),e.jsx("span",{className:"text-xs font-sans text-text-2 whitespace-nowrap",children:c}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:$t(n.t||n.timestamp)})]},a)})}):e.jsx("div",{className:"text-xs text-text-3 font-mono py-2.5 text-center",children:"No recent activity"})});function ia({className:t,...s}){return e.jsx("div",{className:Z("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]",t),...s})}function _te(){return e.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:[e.jsx("div",{className:"col-span-3",children:e.jsx(ia,{className:"h-[72px] rounded-none"})}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx("div",{className:"col-span-2",children:e.jsx(ia,{className:"h-full rounded-none"})})]})}function Dte(){const{data:t,loading:s,agents:n,connected:a,kpiHistory:r,lastFetch:l,agentBreakdown:c,routing:A,rotation:f,adaptive:x,journalist:h,rotating:g,teamBurn:O,memory:b}=lte(),v=k(R=>R.teams),y=n.filter(R=>R.status==="running").length;if(!a)return e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2 text-text-3 font-mono",children:[e.jsx(Lx,{size:28,className:"mx-auto"}),e.jsx("p",{className:"text-xs",children:"Connecting to daemon..."})]})});if(s||!t)return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(CQ,{connected:a,runningCount:0,totalCount:0,uptime:0,lastFetch:0}),e.jsx(_te,{})]});const S=t.tokens||{},j={totalTokens:S.totalTokens||0,totalCostUsd:S.totalCostUsd||0,totalInputTokens:S.totalInputTokens||0,totalOutputTokens:S.totalOutputTokens||0,cacheReadTokens:S.cacheReadTokens||0,cacheCreationTokens:S.cacheCreationTokens||0,cacheHitRate:S.cacheHitRate||0,totalTurns:S.totalTurns||0,agentCount:S.agentCount||0,savings:S.savings||{},internalOverhead:S.internalOverhead||{tokens:0,costUsd:0,components:{}}},N=j.totalOutputTokens>0?(j.totalInputTokens/j.totalOutputTokens).toFixed(1):"—",C=(f==null?void 0:f.totalRotations)||0,U=(c||[]).filter(R=>{var Y;return((Y=R.quality)==null?void 0:Y.score)!=null}),P=U.length>0?Math.round(U.reduce((R,Y)=>R+Y.quality.score,0)/U.length):null,T=t.timeline||{},B=T.snapshots||[],F=T.events||t.events||[],M=[{label:"Tokens Used",value:jt(j.totalTokens),sparkData:r.tokens,color:ce.text3,hint:"Total tokens consumed across all agents — input, output, and cache tokens combined."},{label:"Total Cost",value:er(j.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:P!=null?`${P}`:"—",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:pc(j.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:`${N}: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:`${y}/${n.length}`,sparkData:r.agents,color:ce.text3,hint:"Running agents out of total spawned this session (including completed and crashed)."},{label:"Turns",value:jt(j.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 e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(CQ,{connected:a,runningCount:y,totalCount:n.length,uptime:t.uptime||0,lastFetch:l,activeTeam:t.activeTeam}),e.jsx(dte,{kpis:M}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col bg-surface-3 gap-px",children:[e.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"3fr 1.5fr 1.5fr"},children:[e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 relative",children:e.jsx(vte,{data:B})}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Cache Performance"})}),e.jsx(yte,{cacheRead:j.cacheReadTokens,cacheCreation:j.cacheCreationTokens,totalInput:j.totalInputTokens})]}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Model Routing"})}),e.jsx(Qte,{routing:A,agentBreakdown:c})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"2fr 2.5fr 1.5fr"},children:[e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Agent Fleet"})}),e.jsx(bte,{agentBreakdown:c}),e.jsx(hte,{agentBreakdown:c,rotating:g,teams:v})]}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx(Fte,{tokens:j,rotation:f,adaptive:x,journalist:h,agentBreakdown:c,memory:b})}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx($te,{teams:O})})]})]}),e.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-t border-border",children:e.jsx(zte,{events:F})})]})}const TQ={sm:12,md:16,lg:20};function Lte({fill:t="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 e.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",children:[t==="half"&&e.jsx("defs",{children:e.jsxs("linearGradient",{id:r,children:[e.jsx("stop",{offset:"50%",stopColor:n}),e.jsx("stop",{offset:"50%",stopColor:a})]})}),e.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:t==="full"?n:t==="half"?`url(#${r})`:a})]})}function Hte({rating:t=0,count:s,size:n="sm"}){const a=TQ[n]||TQ.sm,r=[];for(let l=1;l<=5;l++)t>=l?r.push("full"):t>=l-.5?r.push("half"):r.push("empty");return e.jsxs("span",{className:"inline-flex items-center",style:{gap:1},children:[r.map((l,c)=>e.jsx(Lte,{fill:l,size:a},c)),s!=null&&e.jsxs("span",{className:"ml-1 text-[11px] text-[var(--text-dim,#6b7f95)] font-sans",children:["(",s,")"]})]})}const UQ={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 Xte({label:t,variant:s,className:n}){const a=UQ[s]||UQ.draft;return e.jsx("span",{className:Z("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:t})}function Gte({price:t=0,size:s="sm"}){const n=!t||t===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 e.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":`$${t.toFixed(2)}`})}function Zte({type:t="verified",size:s=12}){const n=t==="claude-official"||t==="anthropic"?"#f59e0b":"#4ade80";return e.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",className:"inline-block flex-shrink-0",children:[e.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}),e.jsx("path",{d:"M7 10.5l2 2 4-4.5",fill:"none",stroke:"#24282f",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Vte(){return e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md animate-pulse",style:{padding:20,minHeight:280},children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-surface-4"}),e.jsx("div",{className:"mt-3 h-4 w-[70%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-2 h-3 w-[40%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-3 w-full rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[90%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[60%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-5 w-[50px] rounded bg-surface-4"}),e.jsx("div",{className:"h-px bg-surface-4 my-3"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("div",{className:"h-3 w-16 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-12 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-10 rounded bg-surface-4"})]})]})}const Ni={"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 Kte({item:t,size:s=40}){const n=Ni[t.id];if(n)return e.jsxs("div",{className:"rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:[e.jsx("img",{src:n,alt:t.name,className:"w-5 h-5",onError:l=>{l.target.style.display="none",l.target.nextSibling.style.display="flex"}}),e.jsx("div",{className:"hidden items-center justify-center w-full h-full text-lg font-bold font-sans text-text-1",children:(t.name||"?")[0]})]});const a=(t.name||"?")[0].toUpperCase(),r=t.name?t.name.charCodeAt(0)*37%360:200;return e.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 Ux({item:t,onClick:s,className:n,statusBadge:a}){var l;const r=t.installed;return e.jsxs("button",{onClick:()=>s(t),className:Z("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:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(Kte,{item:t,size:36}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[14px] font-semibold text-text-0 font-sans truncate",children:t.name}),(t.verified||t.verified==="mcp-official")&&e.jsx(Ga,{size:11,className:"text-accent flex-shrink-0"})]}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.author||"Community"})]})]}),e.jsx("p",{className:"text-xs text-text-2 font-sans line-clamp-3 mb-3 flex-1 leading-relaxed",children:t.description}),e.jsx("div",{className:"h-px bg-border-subtle my-2"}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(qs,{size:10}),jt(t.downloads||0)]}),(t.rating||0)>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lb,{size:10,className:"text-warning",fill:"currentColor"}),(l=t.rating)==null?void 0:l.toFixed(1)]}),e.jsx("span",{className:"flex-1"}),a||r&&e.jsx(Te,{variant:"accent",className:"text-2xs",children:t._installedCount?`${t._installedCount} active`:"Installed"})]})]})}function I4({value:t,onChange:s,placeholder:n="Search skills, tags, authors...",large:a}){const[r,l]=p.useState(t||""),c=p.useRef(null);p.useEffect(()=>{l(t||"")},[t]);function A(f){const x=f.target.value;l(x),clearTimeout(c.current),c.current=setTimeout(()=>s(x),300)}return e.jsxs("div",{className:"relative w-full",children:[e.jsx(As,{size:16,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{value:r,onChange:A,placeholder:n,className:Z("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&&e.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 Hn(){const t=k(s=>s.addToast);return{success:(s,n)=>t("success",s,n),error:(s,n)=>t("error",s,n),info:(s,n)=>t("info",s,n),warning:(s,n)=>t("warning",s,n)}}const rs=p.forwardRef(({className:t,label:s,error:n,mono:a,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[s&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),e.jsx("input",{ref:l,className:Z("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",t),...r}),n&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));rs.displayName="Input";const Rv=p.forwardRef(({className:t,label:s,error:n,mono:a,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[s&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),e.jsx("textarea",{ref:l,className:Z("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",t),...r}),n&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));Rv.displayName="Textarea";const EQ=["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 Jl({item:t,size:s=48}){const n=Ni[t.id];if(n)return e.jsx("div",{className:"rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:e.jsx("img",{src:n,alt:t.name,className:"w-6 h-6",onError:l=>{l.target.classList.add("hidden")}})});const a=(t.name||"?")[0].toUpperCase(),r=EQ[(t.name||"").charCodeAt(0)%EQ.length];return e.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 ob({value:t,onChange:s,placeholder:n,disabled:a}){const[r,l]=p.useState(!1);return e.jsxs("div",{className:"relative",children:[e.jsx(rs,{type:r?"text":"password",value:t,onChange:c=>s(c.target.value),placeholder:n,disabled:a,mono:!0,className:"pr-9"}),e.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?e.jsx(To,{size:14}):e.jsx(Vs,{size:14})})]})}function qte({integrationId:t,envKey:s,onSaved:n}){const a=Hn(),[r,l]=p.useState(""),[c,A]=p.useState(!1),[f,x]=p.useState(s.set),[h,g]=p.useState(!1);async function O(){if(r.trim()){A(!0);try{await G.post(`/integrations/${t}/credentials`,{key:s.key,value:r.trim()}),x(!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/${t}/credentials/${s.key}`),x(!1),a.success(`${s.label} removed`),n==null||n()}catch(v){a.error("Failed to remove",v.message)}g(!1)}return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),s.label,s.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),f&&e.jsxs("span",{className:"flex items-center gap-1 text-2xs text-success font-sans",children:[e.jsx(Je,{size:10})," Set"]})]}),f?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-8 rounded-md px-3 bg-surface-2 border border-border-subtle flex items-center",children:e.jsx("span",{className:"text-xs text-text-4 font-mono tracking-widest",children:"*".repeat(16)})}),e.jsx(pe,{variant:"ghost",size:"sm",onClick:b,disabled:h,className:"text-text-3 hover:text-danger",children:h?e.jsx(De,{size:12,className:"animate-spin"}):e.jsx(Ft,{size:12})})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1",children:e.jsx(ob,{value:r,onChange:l,placeholder:s.placeholder||`Enter ${s.label.toLowerCase()}...`,disabled:c})}),e.jsx(pe,{variant:"primary",size:"sm",onClick:O,disabled:c||!r.trim(),children:c?e.jsx(De,{size:12,className:"animate-spin"}):"Save"})]})]})}function Wte({item:t,status:s,installing:n,onInstall:a,onUninstall:r,onNext:l}){var A;const c=s==null?void 0:s.installed;return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Jl,{item:t,size:52}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:t.name}),(t.verified==="mcp-official"||t.verified==="verified")&&e.jsxs(Te,{variant:"accent",className:"text-2xs gap-1",children:[e.jsx(vn,{size:9})," Verified"]})]}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:t.author||"Community"}),t.category&&e.jsx(Te,{variant:"default",className:"text-2xs mt-2",children:t.category})]})]}),e.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((A=t.tags)==null?void 0:A.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map(f=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:f},f))}),e.jsx("div",{className:"h-px bg-border-subtle"}),c?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[e.jsx(Ga,{size:16,className:"text-success"}),e.jsx("span",{className:"text-sm font-medium text-success font-sans",children:"Installed"})]}),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:r,className:"text-text-3 hover:text-danger gap-1.5",children:[e.jsx(Ft,{size:12})," Uninstall"]}),e.jsxs(pe,{variant:"primary",size:"sm",onClick:l,className:"gap-1",children:["Configure ",e.jsx(Tt,{size:12})]})]}):e.jsx(pe,{variant:"primary",size:"lg",onClick:a,disabled:n,className:"w-full gap-2",children:n?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"}),"Installing..."]}):"Install"}),n&&e.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"This may take up to 30 seconds..."})]})}function Yte({item:t,onClose:s}){const n=k(j=>j.agents),a=k(j=>j.teams),r=k(j=>j.installViaExistingAgent),l=k(j=>j.spawnIntegrationTeam),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState(null),O=n.filter(j=>j.status==="running"||j.status==="idle"),b={};for(const j of O){const N=j.teamId||"_none";b[N]||(b[N]=[]),b[N].push(j)}const v={};for(const j of a)v[j.id]=j.name;async function y(){h&&(await r(t,h),s())}async function S(){x(!0);try{await l(t),s()}catch{x(!1)}}return c?c==="spawn"?e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Spawn Integration Agent"}),e.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Creates a team and planner for ",t.name]})]})]}),e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"What happens next"}),e.jsx("ol",{className:"space-y-1.5",children:[`A new team "${t.name}" will be created`,"A planner agent will spawn with full integration context","The agent will handle installation and configuration"].map((j,N)=>e.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-accent font-mono flex-shrink-0 w-4 text-right",children:[N+1,"."]}),e.jsx("span",{children:j})]},N))})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(pe,{variant:"secondary",size:"lg",onClick:()=>A(null),className:"flex-1",disabled:f,children:"Back"}),e.jsx(pe,{variant:"primary",size:"lg",onClick:S,disabled:f,className:"flex-1 gap-2",children:f?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Spawning..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ei,{size:14})," Spawn Agent"]})})]})]}):e.jsxs("div",{className:"px-5 py-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Choose an Agent"}),e.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Send ",t.name," setup instructions to a running agent"]})]})]}),e.jsx(Qt,{className:"max-h-64",children:e.jsx("div",{className:"space-y-3",children:Object.entries(b).map(([j,N])=>e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5 px-1",children:v[j]||"Unassigned"}),e.jsx("div",{className:"space-y-1",children:N.map(C=>e.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:[e.jsx(qa,{size:14,className:h===C.id?"text-accent":"text-text-4"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:C.name||C.id}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:C.role})]}),h===C.id&&e.jsx(Je,{size:14,className:"text-accent flex-shrink-0"})]},C.id))})]},j))})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(pe,{variant:"secondary",size:"lg",onClick:()=>{A(null),g(null)},className:"flex-1",children:"Back"}),e.jsxs(pe,{variant:"primary",size:"lg",onClick:y,disabled:!h,className:"flex-1 gap-2",children:[e.jsx(qa,{size:14})," Send Instructions"]})]})]}):e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Jl,{item:t,size:52}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("h2",{className:"text-base font-bold text-text-0 font-sans",children:["Install ",t.name]}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Choose how to set up this integration"})]})]}),e.jsx("div",{className:"h-px bg-border-subtle"}),e.jsxs("div",{className:"space-y-2.5",children:[e.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:e.jsxs("div",{className:"flex items-center gap-3",children:[e.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:e.jsx(yn,{size:18,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Use Existing Agent"}),e.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&&e.jsx(Tt,{size:14,className:"text-text-4 group-hover:text-accent transition-colors"})]})}),e.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:e.jsxs("div",{className:"flex items-center gap-3",children:[e.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:e.jsx(Ei,{size:18,className:"text-purple"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn New Agent"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:"Create a dedicated team and planner for this integration"})]}),e.jsx(Tt,{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 z4({integrationId:t,onConfigured:s}){const n=Hn(),[a,r]=p.useState(""),[l,c]=p.useState(""),[A,f]=p.useState(!1),x=Jte[t]||"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:e.jsxs(e.Fragment,{children:["Enable the ",e.jsx("strong",{children:x})," — search for it in the API Library and click ",e.jsx("strong",{children:"Enable"})]}),link:{url:"https://console.cloud.google.com/apis/library",label:"Open API Library"}},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Credentials"})," and click ",e.jsx("strong",{children:"Create Credentials"})," → ",e.jsx("strong",{children:"OAuth client ID"})]}),link:{url:"https://console.cloud.google.com/apis/credentials",label:"Open Credentials page"}},{text:e.jsxs(e.Fragment,{children:["If prompted to configure the consent screen, choose ",e.jsx("strong",{children:"External"}),', fill in an app name (e.g. "Groove"), your email, and save. You can skip optional fields.']})},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Audience"})," and click ",e.jsx("strong",{children:"Publish App"}),". Then scroll down to ",e.jsx("strong",{children:"Test users"}),", click ",e.jsx("strong",{children:"Add Users"}),", enter your Google email address, and save."]})},{text:e.jsxs(e.Fragment,{children:["For Application type, choose ",e.jsx("strong",{children:"Desktop app"})," (not Web application). Give it any name."]})},{text:e.jsxs(e.Fragment,{children:["Click ",e.jsx("strong",{children:"Create"}),", then copy the ",e.jsx("strong",{children:"Client ID"})," and ",e.jsx("strong",{children:"Client Secret"})," and paste them below."]})}];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-3",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"How to get your Google credentials"}),e.jsx("ol",{className:"space-y-2.5",children:g.map((O,b)=>e.jsxs("li",{className:"flex gap-2.5 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-accent font-mono font-bold flex-shrink-0 w-4 text-right",children:[b+1,"."]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{children:O.text}),O.link&&e.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:[e.jsx(Ws,{size:9}),O.link.label]}),O.copyable&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.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}),e.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:e.jsx(Ba,{size:12})})]})]})]},b))})]}),e.jsx("div",{className:"bg-accent/8 border border-accent/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.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."]})}),e.jsx("div",{className:"bg-warning/8 border border-warning/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.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 ",e.jsx("strong",{children:"Advanced"}),", then ",e.jsx("strong",{children:"Go to [your app name] (unsafe)"})," to continue. Your credentials stay local and are never sent to Groove servers."]})}),e.jsx("div",{className:"h-px bg-border-subtle"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),"Client ID ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(ob,{value:a,onChange:r,placeholder:"123456789.apps.googleusercontent.com",disabled:A})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),"Client Secret ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(ob,{value:l,onChange:c,placeholder:"GOCSPX-...",disabled:A})]})]}),e.jsx(pe,{variant:"primary",size:"lg",onClick:h,disabled:A||!a.trim()||!l.trim(),className:"w-full gap-2",children:A?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Saving..."]}):"Save Credentials"})]})}function ese({item:t,status:s,onDone:n,onRefreshStatus:a}){var S;const r=Hn(),[l,c]=p.useState(!1),[A,f]=p.useState(null),x=t.authType,h=x==="google-autoauth"||x==="oauth-google";p.useEffect(()=>{h&&G.get("/integrations/google-oauth/status").then(j=>f(j.configured)).catch(()=>f(!1))},[h]);const g=p.useRef(null);p.useEffect(()=>()=>{g.current&&clearInterval(g.current)},[]);async function O(){c(!0);try{const j=await G.post(`/integrations/${t.id}/oauth/start`);if(j.url){const N=await ON(j.url);if(N!=null&&N.error){r.error("Sign-in failed",N.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 U=await G.get(`/integrations/${t.id}/status`);((U==null?void 0:U.envKeys)||[]).some(B=>B.key==="GOOGLE_REFRESH_TOKEN"&&B.set)&&(clearInterval(g.current),g.current=null,r.success("Connected!",`${t.name} is now authenticated`),a(),c(!1))}catch{}},2e3)}}catch(j){r.error("Sign-in failed",j.message),c(!1)}}const b=(s==null?void 0:s.envKeys)||[],v=b.filter(j=>j.required&&!j.hidden),y=v.length===0||v.every(j=>j.set);return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm font-bold text-text-0 font-sans",children:["Configure ",t.name]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Set up credentials to connect"})]})]}),((S=t.setupSteps)==null?void 0:S.length)>0&&!(h&&A===!1)&&e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Setup guide"}),e.jsx("ol",{className:"space-y-1.5",children:t.setupSteps.map((j,N)=>e.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 font-mono flex-shrink-0 w-4 text-right",children:[N+1,"."]}),e.jsx("span",{children:j})]},N))}),t.setupUrl&&e.jsxs("a",{href:t.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-accent font-sans hover:underline mt-1",children:[e.jsx(Ws,{size:11}),new URL(t.setupUrl).hostname]})]}),!(h&&A===!1)&&e.jsx("div",{className:"h-px bg-border-subtle"}),x==="api-key"&&e.jsx("div",{className:"space-y-4",children:b.filter(j=>!j.hidden).map(j=>e.jsx(qte,{integrationId:t.id,envKey:j,onSaved:a},j.key))}),h&&A===!1&&e.jsx(z4,{integrationId:t.id,onConfigured:()=>f(!0)}),h&&A&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(pe,{variant:"primary",size:"lg",onClick:O,disabled:l,className:"w-full gap-2",children:l?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"}),"Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.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 ",t.name]}),e.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&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(De,{size:16,className:"animate-spin text-text-4"})}),e.jsx(pe,{variant:y?"primary":"secondary",size:"lg",onClick:n,className:"w-full gap-1.5",children:y?e.jsxs(e.Fragment,{children:[e.jsx(Je,{size:14}),"Done"]}):"Skip for now"})]})}function tse({item:t,onClose:s}){return e.jsxs("div",{className:"px-5 py-10 flex flex-col items-center text-center space-y-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(Ga,{size:28,className:"text-success"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:"Integration ready"}),e.jsxs("p",{className:"text-sm text-text-3 font-sans mt-1",children:[t.name," is installed and configured. Agents can now use it."]})]}),e.jsx(pe,{variant:"primary",size:"lg",onClick:s,className:"mt-2",children:"Close"})]})}function _4({integration:t,open:s,onClose:n}){const a=Hn(),[r,l]=p.useState("overview"),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState(!0),O=t==null?void 0:t.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&&t&&(l("overview"),g(!0),b())},[s,t,b]);function v(){l("agent-setup")}async function y(){try{await G.delete(`/integrations/${t.id}`),a.success(`${t.name} uninstalled`),await b()}catch(C){a.error("Uninstall failed",C.message)}}function S(){l("configure")}function j(){l("done")}if(!t)return null;const N={overview:t.name,"agent-setup":"Install",configure:"Configure",done:"Complete"};return e.jsx(Vt,{open:s,onOpenChange:C=>{C||n()},children:e.jsx(Kt,{title:N[r]||t.name,description:`Setup wizard for ${t.name}`,className:"max-w-md",children:h?e.jsx("div",{className:"px-5 py-10 flex items-center justify-center",children:e.jsx(De,{size:20,className:"animate-spin text-text-4"})}):r==="overview"?e.jsx(Wte,{item:t,status:c,installing:f,onInstall:v,onUninstall:y,onNext:S}):r==="agent-setup"?e.jsx(Yte,{item:t,onClose:n}):r==="configure"?e.jsx(ese,{item:t,status:c,onDone:j,onRefreshStatus:b}):e.jsx(tse,{item:t,onClose:n})})})}const sse=["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"];function nse({item:t,status:s,onInstall:n,onUninstall:a,busy:r}){const l=s==null?void 0:s.installed,c=s==null?void 0:s.authenticated;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-2 border border-border-subtle",children:[e.jsx(Jl,{item:t,size:32}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans",children:t.name}),e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:t.description})]}),l&&c&&!(s!=null&&s.needsReauth)&&e.jsxs(Te,{variant:"success",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(Je,{size:8})," Ready"]}),l&&c&&(s==null?void 0:s.needsReauth)&&e.jsxs(Te,{variant:"warning",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(Ls,{size:8})," Update"]}),l&&!c&&e.jsx(Te,{variant:"warning",className:"text-2xs flex-shrink-0",children:"Needs sign-in"}),e.jsx(pe,{variant:l?"ghost":"primary",size:"sm",onClick:()=>l?a(t.id):n(t.id),disabled:r===t.id,className:l?"text-text-3 hover:text-danger":"",children:r===t.id?e.jsx(De,{size:12,className:"animate-spin"}):l?e.jsx(Ft,{size:12}):"Install"})]})}function ase({integrations:t,open:s,onClose:n}){const a=Hn(),[r,l]=p.useState(null),[c,A]=p.useState({}),[f,x]=p.useState(null),[h,g]=p.useState(!1),[O,b]=p.useState(!0),v=p.useRef(null),y=t.filter(B=>sse.includes(B.id)),S=p.useCallback(async()=>{const B={};await Promise.all(y.map(async F=>{try{B[F.id]=await G.get(`/integrations/${F.id}/status`)}catch{B[F.id]=null}})),A(B),b(!1)},[y.map(B=>B.id).join(",")]);p.useEffect(()=>(s&&(b(!0),G.get("/integrations/google-oauth/status").then(B=>l(B.configured)).catch(()=>l(!1)),S()),()=>{v.current&&clearInterval(v.current)}),[s]);const j=Object.entries(c).filter(([,B])=>B==null?void 0:B.installed).map(([B])=>B),N=j.length>0&&j.every(B=>{var F;return(F=c[B])==null?void 0:F.authenticated});j.some(B=>{var F;return!((F=c[B])!=null&&F.authenticated)});const C=N&&j.some(B=>{var F;return(F=c[B])==null?void 0:F.needsReauth});async function U(B){var F;x(B);try{await G.post(`/integrations/${B}/install`),a.success(`${(F=y.find(M=>M.id===B))==null?void 0:F.name} installed`),await S()}catch(M){a.error("Install failed",M.message)}x(null)}async function P(B){var F;x(B);try{await G.delete(`/integrations/${B}`),a.success(`${(F=y.find(M=>M.id===B))==null?void 0:F.name} removed`),await S()}catch(M){a.error("Uninstall failed",M.message)}x(null)}async function T(){if(!j.length){a.error("Install at least one service first");return}g(!0);try{const B=await G.post("/integrations/google-workspace/oauth/start",{integrationIds:j});if(B.url){const F=await ON(B.url);if(F!=null&&F.error){a.error("Sign-in failed",F.error),g(!1);return}a.success("Browser opened — complete sign-in there"),v.current&&clearInterval(v.current),v.current=setInterval(async()=>{await S()},3e3),setTimeout(()=>{v.current&&clearInterval(v.current)},18e4)}}catch(B){a.error("Sign-in failed",B.message)}g(!1)}return p.useEffect(()=>{N&&v.current&&(clearInterval(v.current),v.current=null)},[N]),s?e.jsx(Vt,{open:s,onOpenChange:B=>{B||n()},children:e.jsx(Kt,{title:"Google Workspace",description:"Connect your Google services",className:"max-w-md",children:e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"Google",className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Google Workspace"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"One set of credentials for all Google services"})]})]}),r===!1&&e.jsx(z4,{integrationId:"gmail",onConfigured:()=>l(!0)}),r===null&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(De,{size:16,className:"animate-spin text-text-4"})}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans",children:"Services"}),e.jsx("div",{className:"space-y-1.5",children:O?Array.from({length:4}).map((B,F)=>e.jsx("div",{className:"h-14 rounded-md bg-surface-2 animate-pulse"},F)):y.map(B=>e.jsx(nse,{item:B,status:c[B.id],onInstall:U,onUninstall:P,busy:f},B.id))})]}),e.jsx("div",{className:"h-px bg-border-subtle"}),j.length>0&&!N&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(pe,{variant:"primary",size:"lg",onClick:T,disabled:h,className:"w-full gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["Connects ",j.length," service",j.length!==1?"s":""," with one sign-in"]})]}),N&&j.length>0&&e.jsxs("div",{className:"flex flex-col items-center text-center gap-2 py-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(Ga,{size:20,className:"text-success"})}),e.jsx("p",{className:"text-sm font-medium text-success font-sans",children:"All services connected"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Your agents can now use these Google integrations."}),C?e.jsxs("div",{className:"w-full space-y-2 pt-2",children:[e.jsx("p",{className:"text-2xs text-warning font-sans",children:"New permissions available — re-authenticate to enable all features."}),e.jsx(pe,{variant:"secondary",size:"sm",onClick:T,disabled:h,className:"w-full gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:12,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ls,{size:12})," Re-authenticate"]})})]}):e.jsx("button",{onClick:T,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"})]}),j.length===0&&!O&&e.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."})]}),e.jsx(pe,{variant:"secondary",size:"lg",onClick:n,className:"w-full",children:N&&j.length>0?"Done":"Close"})]})})}):null}const Hg=/github\.com\/([^/]+)\/([^/\s#?]+)/;function rse(){const[t,s]=p.useState("input"),[n,a]=p.useState(""),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,x]=p.useState("standalone"),[h,g]=p.useState(""),[O,b]=p.useState(!0),[v,y]=p.useState(""),S=k(B=>B.previewRepo),j=k(B=>B.importRepo),N=k(B=>B.importInProgress),C=Hn(),U=p.useCallback(async B=>{const F=B.match(Hg);if(F){l(!0);try{const M=await S(B);A(M),y(M.name||F[2]),s("preview")}catch(M){C.error("Preview failed",M.message)}finally{l(!1)}}},[S,C]),P=p.useCallback(B=>{const F=B.target.value;a(F),Hg.test(F)&&t==="input"&&U(F)},[t,U]),T=p.useCallback(async()=>{if(!c)return;let B;f==="standalone"?B=`~/Projects/${c.name}`:f==="subdirectory"?B=`./packages/${c.name}`:B=h;try{await j(n,B,O,v),C.success(`Importing ${c.name}`,"Setup agent will handle the rest"),s("input"),a(""),A(null)}catch(F){C.error("Import failed",F.message)}},[c,f,h,n,O,v,j,C]);if(t==="input")return e.jsxs("div",{className:"relative",children:[e.jsx(As,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{type:"text",value:n,onChange:P,placeholder:"Paste a GitHub URL...",className:Z("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")}),e.jsx(pe,{variant:"primary",size:"sm",className:"absolute right-1.5 top-1/2 -translate-y-1/2",onClick:()=>U(n),disabled:!Hg.test(n)||r,children:r?e.jsx(De,{size:12,className:"animate-spin"}):"Preview"})]});if(t==="preview"&&c)return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(Kl,{size:22,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[e.jsx("span",{className:"text-lg font-bold text-text-0 font-sans",children:c.name}),e.jsx("span",{className:"text-xs text-text-4 font-sans",children:c.owner})]}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[c.language&&e.jsx(Te,{variant:"outline",className:"text-2xs",children:c.language}),c.stars!=null&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lb,{size:10,className:"text-warning",fill:"currentColor"}),jt(c.stars)]}),c.license&&e.jsx("span",{children:c.license})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(pe,{variant:"primary",size:"sm",onClick:()=>s("configure"),className:"h-8 text-xs gap-1.5 px-4",children:[e.jsx(Ys,{size:13}),"Clone & Setup"]}),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>{try{const B=n.startsWith("http")?n:`https://${n}`,F=new URL(B);(F.protocol==="https:"||F.protocol==="http:")&&window.open(B,"_blank")}catch{}},className:"h-8 text-xs gap-1.5",children:[e.jsx(Ws,{size:12}),"GitHub"]}),e.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&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2",children:"About"}),e.jsx("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:c.description})]}),c.readmePreview&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-3",children:"README"}),e.jsx("div",{className:"text-sm text-text-2 font-sans leading-relaxed whitespace-pre-wrap",children:c.readmePreview})]})]});if(t==="configure"&&c){const B=[{id:"standalone",icon:xd,title:"Standalone project",description:"Clone to its own directory, separate from this workspace",path:`~/Projects/${c.name}`},{id:"subdirectory",icon:zb,title:"Workspace package",description:"Add as a package inside this project's monorepo",path:`./packages/${c.name}`},{id:"custom",icon:RS,title:"Custom location",description:"Choose your own path",path:null}];return e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-2 overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 border-b border-border-subtle bg-surface-3/50",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0",children:e.jsx(qs,{size:16,className:"text-accent"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:["Clone ",c.name]}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:[c.owner,"/",c.name," — configure where to install"]})]})]})}),e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2.5 block",children:"Install location"}),e.jsx("div",{className:"space-y-2",children:B.map(F=>{const M=F.icon,R=f===F.id;return e.jsx("button",{onClick:()=>x(F.id),className:Z("w-full text-left rounded-lg border p-3.5 transition-all duration-150 cursor-pointer",R?"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:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:Z("w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0 mt-0.5",R?"bg-accent/15 text-accent":"bg-surface-3 text-text-4"),children:e.jsx(M,{size:15})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:Z("text-xs font-semibold font-sans",R?"text-text-0":"text-text-2"),children:F.title}),R&&e.jsx("div",{className:"w-4 h-4 rounded-full bg-accent flex items-center justify-center",children:e.jsx(Je,{size:10,className:"text-white"})})]}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5 leading-relaxed",children:F.description}),F.path&&R&&e.jsx("code",{className:"text-2xs text-accent/80 font-mono mt-1.5 block truncate",children:F.path})]})]})},F.id)})}),f==="custom"&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:h,onChange:F=>g(F.target.value),placeholder:"/path/to/clone",autoFocus:!0,className:Z("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")})})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-3 flex items-center justify-center",children:e.jsx(yn,{size:14,className:"text-text-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans block",children:"Create a team"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Organize agents working on this repo into their own team"})]})]}),e.jsx("button",{onClick:()=>b(!O),className:Z("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer flex-shrink-0",O?"bg-accent":"bg-surface-5"),children:e.jsx("div",{className:Z("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",O?"translate-x-4":"translate-x-0")})})]}),O&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:v,onChange:F=>y(F.target.value),placeholder:"Team name",className:Z("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")})})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle bg-surface-3/30 flex items-center justify-between",children:[e.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:[e.jsx(kb,{size:11}),"Back"]}),e.jsx(pe,{variant:"primary",size:"sm",onClick:T,disabled:N||f==="custom"&&!h.trim(),className:"h-8 text-xs gap-1.5 px-5",children:N?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:12,className:"animate-spin"})," Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(qs,{size:12})," Clone & Setup"]})})]})]})}return null}function ose({repo:t,onRemove:s,onNuke:n,onOpen:a}){return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-3 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:t.repoName||t.name}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.repoOwner||t.owner})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.language&&e.jsx(Te,{variant:"outline",className:"text-2xs",children:t.language}),e.jsx("span",{className:"text-2xs text-text-4 font-mono truncate max-w-[180px]",children:t.clonedTo||t.path})]}),e.jsx("span",{className:"text-2xs text-text-4 font-sans mt-0.5 block",children:t.clonedAt?`Imported ${$t(t.clonedAt)}`:t.status||""})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a&&e.jsxs("button",{onClick:()=>a(t),className:Z("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:[e.jsx(Ys,{size:11}),"Open"]}),s&&e.jsxs("button",{onClick:()=>s(t),className:Z("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:[e.jsx(Ft,{size:11}),"Remove"]}),n&&e.jsxs("button",{onClick:()=>n(t),className:Z("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:[e.jsx(_$,{size:11}),"Nuke"]})]})]})}function ise({repo:t,open:s,onClose:n,onConfirm:a}){var h,g,O;const[r,l]=p.useState(!0);if(!t)return null;const c=((h=t.agents)==null?void 0:h.length)||0,A=((g=t.processes)==null?void 0:g.length)||0,f=((O=t.credentialKeys)==null?void 0:O.length)||0,x=t.fileCount||0;return e.jsx(Vt,{open:s,onOpenChange:b=>{b||n()},children:e.jsx(Kt,{title:`Nuke ${t.repoName||t.name}?`,description:"Confirm destructive removal of imported repo",children:e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Aa,{size:16,className:"text-danger flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-text-1 font-sans",children:"This cannot be undone."})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-text-2 font-sans",children:[c>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Kill ",c," agent",c!==1?"s":""]}),A>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Stop ",A," process",A!==1?"es":""]}),f>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Remove ",f," credential",f!==1?"s":""]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"}),' Delete team "',t.teamId||t.repoName||t.name,'"']}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Clean all .groove state"]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:b=>l(b.target.checked),className:"accent-[var(--color-danger)]"}),e.jsxs("span",{className:"text-xs text-text-1 font-sans",children:["Delete repo files",x>0?` (${x} files)`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(pe,{variant:"danger",size:"sm",onClick:()=>a(r),children:"Nuke Everything"}),e.jsx(pe,{variant:"ghost",size:"sm",onClick:n,children:"Cancel"})]})]})})})}function lse({skill:t,onBack:s}){var P,T,B;const n=Hn(),[a,r]=p.useState(""),[l,c]=p.useState(!1),[A,f]=p.useState(!1),[x,h]=p.useState(!1),[g,O]=p.useState(!1),[b,v]=p.useState(t.installed),[y,S]=p.useState(!0);p.useEffect(()=>{S(!0),G.get(`/skills/${t.id}/content`).then(F=>{r(F.content||""),c(F.requiresPurchase||!1)}).catch(()=>{}).finally(()=>S(!1))},[t.id]);async function j(){f(!0);try{await G.post(`/skills/${t.id}/install`),v(!0),n.success(`${t.name} installed`)}catch(F){n.error("Install failed",F.message)}f(!1)}async function N(){h(!0);try{await G.post(`/skills/${t.id}/update`),n.success(`${t.name} updated to latest`);const F=await G.get(`/skills/${t.id}/content`);F.content&&r(F.content)}catch(F){n.error("Update failed",F.message)}h(!1)}async function C(){O(!0);try{await G.delete(`/skills/${t.id}`),v(!1),n.success(`${t.name} uninstalled`)}catch(F){n.error("Uninstall failed",F.message)}O(!1)}async function U(){const{marketplaceAuthenticated:F,marketplaceLogin:M,marketplaceCheckout:R}=k.getState();if(!F){M();return}try{await R(t.id)}catch{}}return e.jsx(Qt,{className:"h-full",children:e.jsxs("div",{className:"px-6 py-5",children:[e.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:[e.jsx(Di,{size:14})," Back"]}),e.jsxs("div",{className:"flex gap-8",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.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:t.icon||((T=(P=t.name)==null?void 0:P[0])==null?void 0:T.toUpperCase())}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-text-3 font-sans",children:[e.jsx("span",{children:t.author||"Community"}),(t.source==="claude-official"||t.verified)&&e.jsx(Zte,{type:t.source,size:13})]})]})]}),e.jsx("p",{className:"mt-3 text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((B=t.tags)==null?void 0:B.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:t.tags.map(F=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:F},F))}),e.jsx("div",{className:"h-px bg-border-subtle my-5"}),y?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-3 w-48 bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}):a?e.jsxs("div",{className:"text-sm text-text-2 font-sans leading-relaxed",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-0 mb-2",children:"About"}),e.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:a})]}):l?e.jsxs("div",{className:"bg-warning/5 border border-warning/15 rounded-lg px-4 py-3",children:[e.jsx("p",{className:"text-sm text-text-1 font-sans font-medium",children:"Paid skill — purchase to view content"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Sign in and purchase this skill to access its full instructions."})]}):e.jsx("p",{className:"text-xs text-text-4 font-sans",children:"Content loading failed — check your connection."})]}),e.jsx("div",{className:"w-[240px] flex-shrink-0",children:e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-lg p-4 sticky top-4",children:[e.jsx(Gte,{price:t.price||0,size:"md"}),l&&!b?e.jsxs("button",{onClick:U,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 $",(t.price||0).toFixed(2)]}):b?e.jsxs("div",{className:"mt-3 flex flex-col gap-1.5",children:[e.jsxs("button",{onClick:N,disabled:x,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:[e.jsx(Ls,{size:12,className:x?"animate-spin":""}),x?"Updating...":"Pull Latest"]}),e.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:[e.jsx(Ft,{size:12}),g?"Removing...":"Uninstall"]})]}):e.jsx("button",{onClick:j,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"}),e.jsx("div",{className:"mt-4 flex flex-col gap-2.5",children:[["Downloads",e.jsx("span",{className:"font-mono text-text-0",children:jt(t.downloads||0)},"d")],["Rating",e.jsx(Hte,{rating:t.rating||0,count:t.rating_count||t.ratingCount,size:"sm"},"r")],["Version",e.jsx("span",{className:"font-mono text-text-0",children:t.version||"1.0.0"},"v")],["Category",e.jsx(Xte,{label:t.category||"general",variant:t.category||"draft"},"c")],["Source",e.jsx("span",{className:"text-text-0",children:t.source==="claude-official"?"Anthropic":"Community"},"s")]].map(([F,M])=>e.jsxs("div",{className:"flex justify-between items-center text-xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:F}),M]},F))})]})})]})]})})}function cse({open:t,onClose:s}){const[n,a]=p.useState("new"),[r,l]=p.useState(""),[c,A]=p.useState(""),[f,x]=p.useState(""),[h,g]=p.useState(""),[O,b]=p.useState(""),[v,y]=p.useState(!1),S=k(M=>M.teams),j=k(M=>M.activeTeamId),N=k(M=>M.createTeam),C=k(M=>M.spawnAgent),U=k(M=>M.setActiveView),P=k(M=>M.selectAgent),T=Hn();p.useEffect(()=>{t&&(a("new"),l(""),A(j||""),x(""),g(""),b(""),y(!1))},[t,j]);async function B(){if(f.trim()){y(!0);try{let M;n==="new"?M=(await N(r.trim()||f.trim())).id:M=c;const R=[`The user wants to integrate the **${f.trim()}** API into their project.`,""];h.trim()&&R.push(`**API Documentation:** ${h.trim()}`),O.trim()&&R.push("**API Key:** The user has provided an API key. Store it securely using environment variables — never hardcode it."),R.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 Y=R.join(`
|
|
1012
|
+
disabled:cursor-not-allowed`})]}),e.jsx("span",{className:"text-[11px] text-accent font-mono font-medium w-9 text-right shrink-0 tabular-nums",children:O})]})}const xee={backend:Ns,frontend:md,fullstack:bn,testing:Wx,security:vn},mee=new Set(["codex","grok","local"]),hee=/^[a-zA-Z0-9_-]{1,64}$/;function pee(t){return t.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,64)}function qf(){var H;const t=k(I=>I.recommendedTeam),s=k(I=>I.launchRecommendedTeam),n=k(I=>I.teamLaunchConfig),a=k(I=>I.fetchProviders),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState([]),[O,b]=p.useState((n==null?void 0:n.provider)||""),[v,y]=p.useState((n==null?void 0:n.model)||""),[S,j]=p.useState((n==null?void 0:n.reasoningEffort)??50),[N,C]=p.useState((n==null?void 0:n.temperature)??.5),[U,P]=p.useState(null);if(p.useEffect(()=>{a().then(I=>{Array.isArray(I)&&g(I.filter(L=>L.installed))}).catch(()=>{})},[]),!((H=t==null?void 0:t.agents)!=null&&H.length))return null;const T=t.agents,B=T.filter(I=>!I.phase||I.phase===1),F=T.filter(I=>I.phase===2),M=c??B.map(I=>({...I,name:I.name||""})),R=h.find(I=>I.id===O),Y=((R==null?void 0:R.models)||[]).filter(I=>I.type!=="image"&&!I.disabled),W=mee.has(O);function ee(I,L){const J=M.map((D,se)=>se===I?{...D,name:pee(L)}:D);A(J)}function K(I,L){if(typeof L=="string"){const[J,D]=[L,arguments[2]];A(se=>(se??M).map((le,V)=>V===I?{...le,[J]:D}:le))}else A(J=>(J??M).map((D,se)=>se===I?{...D,...L}:D))}function _(I){var D;b(I);const L=h.find(se=>se.id===I),J=((L==null?void 0:L.models)||[]).filter(se=>se.type!=="image"&&!se.disabled);y(((D=J[0])==null?void 0:D.id)||"")}async function E(){l(!0),k.setState({teamLaunchConfig:{...O&&{provider:O,model:v},reasoningEffort:S,...W&&{temperature:N}}});try{const I=[...M,...F];await s(I)}catch{}l(!1)}function q(){k.setState({recommendedTeam:null})}return e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 z-50 w-full max-w-lg",children:e.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:[e.jsxs("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center gap-2",children:[e.jsx(Ei,{size:16,className:"text-accent"}),e.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Planner Recommends a Team"}),e.jsx("button",{onClick:q,className:"text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:14})})]}),e.jsxs("div",{className:"border-b border-border-subtle",children:[e.jsxs("button",{onClick:()=>x(!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:[e.jsx(xt,{size:12,className:Z("text-text-4 transition-transform duration-200",!f&&"-rotate-90")}),e.jsx(DS,{size:12,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider",children:"Team Settings"}),O&&e.jsxs("span",{className:"ml-auto text-2xs text-accent font-mono",children:[O,v?` / ${v}`:""]})]}),f&&e.jsxs("div",{className:"px-4 pb-3 space-y-3",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:O,onValueChange:_,children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-4 h-7 text-xs"}),e.jsx(In,{children:h.map(I=>e.jsx(ms,{value:I.id,children:I.displayName||I.name||I.id},I.id))})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:v,onValueChange:y,children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-4 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"auto",children:"Auto"}),Y.map(I=>e.jsx(ms,{value:I.id,children:I.name||I.id},I.id))]})]})]})]}),e.jsx(Ka,{label:"Reasoning",value:S,onChange:j,min:0,max:100,step:1}),W&&e.jsx(Ka,{label:"Temperature",value:N,onChange:C,min:0,max:1,step:.01,formatValue:I=>I.toFixed(2)})]})]}),e.jsxs("div",{className:"px-4 py-3 space-y-1.5",children:[M.map((I,L)=>{var te;const J=xee[I.role]||bn,D=!I.name||hee.test(I.name),se=U===L,le=h.find(ae=>ae.id===(I.provider||O)),V=((le==null?void 0:le.models)||[]).filter(ae=>ae.type!=="image"&&!ae.disabled);return e.jsxs("div",{className:"rounded-md bg-surface-4 border border-border-subtle overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 cursor-pointer hover:bg-surface-5/50 transition-colors",onClick:()=>P(se?null:L),children:[e.jsx(J,{size:12,className:"text-text-2 shrink-0"}),e.jsx("input",{type:"text",value:I.name,onChange:ae=>ee(L,ae.target.value),onClick:ae=>ae.stopPropagation(),placeholder:I.role,className:Z("flex-1 min-w-0 bg-transparent text-xs font-mono text-text-0 outline-none placeholder:text-text-4",!D&&"text-red-400"),maxLength:64,spellCheck:!1}),I.provider&&I.provider!==O&&e.jsx("span",{className:"text-2xs text-accent font-mono shrink-0",children:I.provider}),((te=I.scope)==null?void 0:te.length)>0&&e.jsxs("span",{className:"text-2xs text-text-4 font-mono shrink-0 truncate max-w-[120px]",children:[I.scope[0],I.scope.length>1?` +${I.scope.length-1}`:""]}),e.jsx(xt,{size:10,className:Z("text-text-4 shrink-0 transition-transform duration-200",!se&&"-rotate-90")})]}),se&&e.jsxs("div",{className:"px-2.5 pb-2.5 pt-1 space-y-2.5 border-t border-border-subtle",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(ka,{size:10}),"Provider"]}),e.jsxs(Rn,{value:I.provider||"",onValueChange:ae=>{var oe;const be=h.find(ue=>ue.id===ae),z=((be==null?void 0:be.models)||[]).filter(ue=>ue.type!=="image"&&!ue.disabled);K(L,{provider:ae,model:((oe=z[0])==null?void 0:oe.id)||""})},children:[e.jsx(Mn,{placeholder:"Team default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"",children:"Team default"}),h.map(ae=>e.jsx(ms,{value:ae.id,children:ae.displayName||ae.name||ae.id},ae.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:I.model||"",onValueChange:ae=>K(L,"model",ae),children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"",children:"Auto"}),V.map(ae=>e.jsx(ms,{value:ae.id,children:ae.name||ae.id},ae.id))]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(Ro,{size:10}),"Model Routing"]}),e.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(ae=>e.jsx("button",{onClick:()=>K(L,"routingMode",ae.value),className:Z("flex-1 px-2 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(I.routingMode||"auto")===ae.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:ae.label},ae.value))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(SS,{size:10}),"Effort Level"]}),e.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"},{value:"ultra",label:"Ultra"}].map(ae=>e.jsx("button",{onClick:()=>K(L,"effort",ae.value),className:Z("flex-1 px-1.5 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(I.effort||"default")===ae.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:ae.label},ae.value))})]})]})]},L)}),t.projectDir&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-2 font-mono pt-0.5",children:[e.jsx("span",{className:"text-text-4",children:"Project:"}),e.jsxs("span",{className:"text-accent",children:[t.projectDir,"/"]})]}),F.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans",children:[e.jsx(vn,{size:10}),e.jsxs("span",{children:[F.length," QC agent",F.length>1?"s":""," will auto-spawn after builders complete"]})]})]}),e.jsx("div",{className:"px-4 py-3 border-t border-border-subtle",children:e.jsxs(pe,{variant:"primary",size:"md",onClick:E,disabled:r,className:"w-full gap-2",children:[e.jsx(qt,{size:14}),r?"Launching...":`Launch ${B.length} Agent${B.length>1?"s":""}`]})})]})})}const gee={agentNode:SC,rootNode:CC},Ig=220,zg=82,wf=260,jf=130,po=4,Xs="__groove_root__";function FA(t){if(!t)return{};try{return JSON.parse(localStorage.getItem(`groove:nodePositions:${t}`)||"{}")}catch{return{}}}function B4(){let t=!1;for(const s of["groove:chatHistory","groove:activityLog"])localStorage.getItem(s)!==null&&(localStorage.removeItem(s),t=!0);return t}function QQ(t,s){if(!t)return;const n=`groove:nodePositions:${t}`,a=JSON.stringify(s);try{localStorage.setItem(n,a);return}catch{}if(B4())try{localStorage.setItem(n,a)}catch{}}function k4(){try{return JSON.parse(localStorage.getItem("groove:roleLayout")||"{}")}catch{return{}}}function Oee(t){const s="groove:roleLayout",n=JSON.stringify(t);try{localStorage.setItem(s,n);return}catch{}if(B4())try{localStorage.setItem(s,n)}catch{}}function T4(){try{return JSON.parse(localStorage.getItem("groove:teamViewports")||"{}")}catch{return{}}}function bee(t,s){try{const n=T4();n[t]=s,localStorage.setItem("groove:teamViewports",JSON.stringify(n))}catch{}}function vee(t,s){const n=t.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 yee(){const t=k(E=>E.teams),s=k(E=>E.activeTeamId),n=k(E=>E.agents),a=k(E=>E.switchTeam),r=k(E=>E.createTeam),l=k(E=>E.deleteTeamPermanently),c=k(E=>E.renameTeam),A=k(E=>E.cloneTeam),f=k(E=>E.reorderTeams),x=k(E=>E.addToast),[h,g]=p.useState(!1),[O,b]=p.useState(""),[v,y]=p.useState(null),[S,j]=p.useState(""),N=p.useRef(!1),[C,U]=p.useState(null),[P,T]=p.useState(null),B=p.useRef(null),[F,M]=p.useState(!1),[R,Y]=p.useState(!1),W=p.useCallback(()=>{const E=B.current;E&&(M(E.scrollLeft>0),Y(E.scrollLeft+E.clientWidth<E.scrollWidth-1))},[]);p.useEffect(()=>{const E=B.current;if(!E)return;W(),E.addEventListener("scroll",W);const q=new ResizeObserver(W);return q.observe(E),()=>{E.removeEventListener("scroll",W),q.disconnect()}},[W,t.length]);function ee(){const E=O.trim();!E||N.current||(N.current=!0,b(""),g(!1),r(E).finally(()=>{N.current=!1,setTimeout(()=>{B.current&&B.current.scrollTo({left:B.current.scrollWidth,behavior:"smooth"})},100)}))}function K(E){y(E.id),j(E.name)}function _(){const E=S.trim();if(!E||!v){y(null);return}c(v,E),y(null)}return e.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:[F&&e.jsx("button",{onClick:()=>{var E;return(E=B.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:e.jsx(Di,{size:14})}),e.jsxs("div",{ref:B,className:"flex items-end flex-1 min-w-0 overflow-x-auto gap-0",style:{scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch"},children:[t.map(E=>{const q=n.filter(J=>{var D;return J.teamId===E.id&&!((D=J.metadata)!=null&&D.scheduled)}).length,H=E.id===s,I=v===E.id,L=n.filter(J=>{var D;return J.teamId===E.id&&!((D=J.metadata)!=null&&D.scheduled)&&(J.status==="running"||J.status==="starting")}).length;return e.jsxs(Uv,{children:[e.jsx(Ev,{asChild:!0,children:e.jsxs("div",{draggable:!I,onDragStart:J=>{U(E.id),J.dataTransfer.effectAllowed="move",J.dataTransfer.setData("text/plain","")},onDragEnd:()=>{U(null),T(null)},onDragOver:J=>{J.preventDefault(),J.dataTransfer.dropEffect="move",C&&C!==E.id&&T(E.id)},onDragLeave:()=>{P===E.id&&T(null)},onDrop:J=>{if(J.preventDefault(),!C||C===E.id)return;const D=t.findIndex(le=>le.id===C),se=t.findIndex(le=>le.id===E.id);D!==-1&&se!==-1&&f(D,se),U(null),T(null)},onClick:()=>!I&&a(E.id),onDoubleClick:()=>K(E),className:Z("relative flex items-center gap-2 px-3 h-9 text-xs font-sans cursor-pointer select-none transition-colors flex-shrink-0",H?"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",P===E.id&&C!==E.id&&"border-l-2 !border-l-accent"),children:[H&&e.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-accent",style:{height:"0.5px"}}),(()=>{const J=vee(n,E.id),D=J==="working"||J==="completed"?"text-green-400":J==="crashed"?"text-red-400":H?"text-accent":"text-text-4";return e.jsxs("span",{className:"relative flex-shrink-0",children:[e.jsx(yn,{size:13,className:Z(D,J==="working"&&"animate-pulse")}),J==="working"&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 w-1.5 h-1.5 rounded-full bg-green-400 animate-pulse"})]})})(),I?e.jsx("input",{value:S,onChange:J=>j(J.target.value),onKeyDown:J=>{J.key==="Enter"&&_(),J.key==="Escape"&&y(null)},onBlur:_,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:J=>J.stopPropagation()}):e.jsx("span",{className:"truncate max-w-[120px]",children:E.name}),q>0&&!I&&e.jsx("span",{className:Z("flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full text-2xs font-mono font-semibold",L>0?"bg-accent/15 text-accent":"bg-surface-4 text-text-3"),children:q}),H&&e.jsx("div",{className:"absolute bottom-[-1px] left-0 right-0 h-px bg-[#242830]"})]})}),e.jsxs(Pv,{children:[e.jsxs(ya,{onSelect:()=>K(E),children:[e.jsx(Ua,{size:12})," Rename"]}),e.jsxs(ya,{onSelect:()=>A(E.id),children:[e.jsx(Ba,{size:12})," Clone"]}),e.jsx(Fv,{}),e.jsxs(ya,{danger:!0,onSelect:()=>{if(n.filter(D=>D.teamId===E.id).some(D=>D.status==="running"||D.status==="starting")){x("error","Stop running agents first");return}l(E.id)},children:[e.jsx(Ft,{size:12})," Delete"]})]})]},E.id)}),h?e.jsxs("div",{className:"flex items-center gap-1.5 px-3 h-9 flex-shrink-0",children:[e.jsx("input",{value:O,onChange:E=>b(E.target.value),onKeyDown:E=>{E.key==="Enter"&&ee(),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}),e.jsx("button",{onClick:ee,disabled:!O.trim(),className:"p-1 rounded text-accent hover:bg-accent/10 cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",children:e.jsx(Je,{size:12})}),e.jsx("button",{onClick:()=>{g(!1),b("")},className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:12})})]}):e.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:e.jsx(it,{size:12})})]}),R&&e.jsx("button",{onClick:()=>{var E;return(E=B.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:e.jsx(Tt,{size:14})})]})}function wee(){const t=k(K=>K.agents),s=k(K=>K.activeTeamId),n=k(K=>K.tokenTimeline),a=k(K=>K.selectAgent),r=k(K=>K.closeDetail),l=p.useRef([]),c=p.useMemo(()=>{const K=t.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.current;return _.length===K.length&&_.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.current=K,K)},[t,s]),A=p.useRef(FA(s)),f=p.useRef(s);f.current!==s&&(f.current=s,A.current=FA(s));const{fitView:x,setViewport:h}=BU(),[g,O]=p.useState(0),b=p.useRef(s),v=p.useMemo(()=>{const K=A.current,_=k4(),E=c.filter(se=>se.status==="running").length,q=K[Xs]||_[Xs]||{x:0,y:0},H=[{id:Xs,type:"rootNode",position:q,data:{agentCount:c.length,runningCount:E},draggable:!0,selectable:!1}],I=new Set,L=(se,le)=>`${Math.round(se/100)},${Math.round(le/100)}`;I.add(L(q.x,q.y));const J=[];c.forEach(se=>{const le=se.name||se.id;if(K[le]){const V=K[le];I.add(L(V.x,V.y)),H.push({id:se.id,type:"agentNode",position:V,data:{agent:se,timeline:n[se.id]||[]},draggable:!0,selectable:!0})}else J.push(se)});const D=new Map;return J.forEach((se,le)=>{const V=se.role||"agent",te=D.get(V)||0;D.set(V,te+1);const ae=te===0?V:`${V}-${te}`;let be;if(_[ae])be={..._[ae]};else{const z=Math.floor(le/po),oe=le%po;be={x:-((Math.min(J.length-z*po,po)-1)*wf)/2+oe*wf,y:jf+z*jf}}for(;I.has(L(be.x,be.y));)be={x:be.x,y:be.y+jf};I.add(L(be.x,be.y)),se.name||se.id,H.push({id:se.id,type:"agentNode",position:be,data:{agent:se,timeline:n[se.id]||[]},draggable:!0,selectable:!0})}),H},[c,n,s]);p.useEffect(()=>{const K={};v.forEach(_=>{var q,H;const E=_.id===Xs?Xs:((H=(q=_.data)==null?void 0:q.agent)==null?void 0:H.name)||_.id;A.current[E]||(K[E]=_.position)}),Object.keys(K).length>0&&(Object.assign(A.current,K),QQ(s,A.current))},[v,s]);const y=p.useMemo(()=>{const K=FA(s),_=K[Xs]||{x:0,y:0};return c.map((E,q)=>{const H=E.name||E.id,I=Math.floor(q/po),L=q%po,D=-((Math.min(c.length-I*po,po)-1)*wf)/2,se=K[H]||{x:D+L*wf,y:140+I*jf},le=se.x+Ig/2-_.x,V=se.y+zg/2-_.y;let te,ae;return Math.abs(V)>Math.abs(le)?(te=V>0?"bottom":"top",ae=V>0?"top":"bottom"):(te=le>0?"right":"left",ae=le>0?"left":"right"),{id:`e-${Xs}-${E.id}`,source:Xs,target:E.id,sourceHandle:te,targetHandle:ae,type:"default",animated:E.status==="running"}})},[c,s]),[S,j,N]=kU(v),[C,U,P]=TU(y),T=p.useRef(new Set);p.useEffect(()=>{j(K=>{const _=new Map(K.map(E=>[E.id,E]));return v.map(E=>{const q=_.get(E.id);return q?{...q,data:E.data}:E})})},[v,j]),p.useEffect(()=>{U(()=>{const K=S.find(E=>E.id===Xs);if(!K)return y;const _=K.position;return y.map(E=>{const q=S.find(D=>D.id===E.target);if(!q)return E;const H=q.position.x+Ig/2-_.x,I=q.position.y+zg/2-_.y;let L,J;return Math.abs(I)>Math.abs(H)?(L=I>0?"bottom":"top",J=I>0?"top":"bottom"):(L=H>0?"right":"left",J=H>0?"left":"right"),{...E,sourceHandle:L,targetHandle:J}})})},[y,S,U]);const B=c.map(K=>K.id).join(","),F=p.useRef(null);p.useEffect(()=>{if(b.current!==s){b.current=s,T.current=new Set(c.map(q=>q.id)),O(c.length);const E=T4()[s];E?h(E,{duration:200}):c.length>0&&x({padding:.3,maxZoom:1.2,duration:200});return}const K=new Set(c.map(E=>E.id)),_=c.length>0&&[...K].some(E=>!T.current.has(E));T.current=K,g===0&&c.length>0?x({padding:.3,maxZoom:1.2,duration:0}):_&&(clearTimeout(F.current),F.current=setTimeout(()=>x({padding:.3,maxZoom:1.2,duration:300}),500)),O(c.length)},[B,g,x,s,h]);const M=p.useCallback((K,_)=>{bee(s,_)},[s]),R=p.useCallback((K,_)=>{_.id!==Xs&&a(_.id)},[a]),Y=p.useCallback(()=>{r()},[r]),W=p.useCallback((K,_)=>{const E=S.find(H=>H.id===Xs);if(!E)return;const q=E.position;U(H=>H.map(I=>{const L=I.source===_.id,J=I.target===_.id;if(!L&&!J)return I;const D=_.position,se=D.x+Ig/2-q.x,le=D.y+zg/2-q.y;let V,te;return Math.abs(le)>Math.abs(se)?(V=le>0?"bottom":"top",te=le>0?"top":"bottom"):(V=se>0?"right":"left",te=se>0?"left":"right"),{...I,sourceHandle:V,targetHandle:te}}))},[S,U]),ee=p.useCallback((K,_)=>{var H,I;const E=_.id===Xs?Xs:((I=(H=_.data)==null?void 0:H.agent)==null?void 0:I.name)||_.id;A.current[E]=_.position;const q=FA(s);q[E]=_.position,QQ(s,q)},[s]);return e.jsx(UU,{nodes:S,edges:C,nodeTypes:gee,onNodesChange:N,onEdgesChange:P,onNodeClick:R,onPaneClick:Y,onNodeDrag:W,onNodeDragStop:ee,onMoveEnd:M,defaultViewport:{x:0,y:0,zoom:1.2},proOptions:{hideAttribution:!0},minZoom:.2,maxZoom:1.5,className:"bg-surface-2",children:e.jsx(EU,{color:"rgba(97,175,239,0.03)",gap:24,size:1})})}const U4=new Set(["codex","grok","local"]),jee=new Set(["codex"]);function Qee({open:t,onOpenChange:s,onLaunch:n}){const a=k(T=>T.fetchProviders),[r,l]=p.useState([]),[c,A]=p.useState(""),[f,x]=p.useState(""),[h,g]=p.useState(50),[O,b]=p.useState(.5),[v,y]=p.useState(50);p.useEffect(()=>{t&&a().then(T=>{var F;if(!Array.isArray(T))return;const B=T.filter(M=>M.installed);if(l(B),!c&&B.length>0){const M=B.find(Y=>Y.isDefault)||B[0];A(M.id);const R=((F=M.models)==null?void 0:F.filter(Y=>Y.type!=="image"))||[];R.length>0&&x(R[0].id)}}).catch(()=>{})},[t]);const S=r.find(T=>T.id===c),j=((S==null?void 0:S.models)||[]).filter(T=>T.type!=="image"&&!T.disabled),N=U4.has(c),C=jee.has(c);function U(T){var M;A(T);const B=r.find(R=>R.id===T),F=((B==null?void 0:B.models)||[]).filter(R=>R.type!=="image"&&!R.disabled);x(((M=F[0])==null?void 0:M.id)||"")}function P(){const T={provider:c,model:f,reasoningEffort:h,...N&&{temperature:O},...C&&{verbosity:v}};k.setState({teamLaunchConfig:T}),n(T)}return e.jsx(Vt,{open:t,onOpenChange:s,children:e.jsxs(Kt,{title:"Configure Planner",description:"Set provider, model, and tuning before launching the planner",children:[e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Provider"}),e.jsxs(Rn,{value:c,onValueChange:U,children:[e.jsx(Mn,{placeholder:"Select provider",className:"bg-surface-3"}),e.jsx(In,{children:r.map(T=>e.jsx(ms,{value:T.id,children:T.displayName||T.name||T.id},T.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Model"}),e.jsxs(Rn,{value:f,onValueChange:x,children:[e.jsx(Mn,{placeholder:"Select model",className:"bg-surface-3"}),e.jsxs(In,{children:[e.jsx(ms,{value:"auto",children:"Auto"}),j.map(T=>e.jsx(ms,{value:T.id,children:T.name||T.id},T.id))]})]})]}),e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(Ka,{label:"Reasoning Effort",value:h,onChange:g,min:0,max:100,step:1}),N&&e.jsx(Ka,{label:"Temperature",value:O,onChange:b,min:0,max:1,step:.01,formatValue:T=>T.toFixed(2)}),C&&e.jsx(Ka,{label:"Verbosity",value:v,onChange:y,min:0,max:100,step:1})]})]}),e.jsx("div",{className:"px-5 py-4 border-t border-border-subtle",children:e.jsxs(pe,{variant:"primary",size:"md",onClick:P,className:"w-full gap-2",children:[e.jsx(qt,{size:14}),"Launch Planner"]})})]})})}const NQ={chat:Ho,planner:Ei,backend:Ns,frontend:md,fullstack:bn,testing:Wx,devops:Eb,docs:On,security:vn,database:Pb,cmo:Ib,cfo:bS,ea:LS,support:kS,analyst:Lx,creative:MS,slides:zS,ambassador:ua},_g=[{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"}],Nee=[{name:"Dev Team",icon:bn,roles:["frontend","backend","testing"],desc:"3 agents"},{name:"Full Stack",icon:rc,roles:["frontend","backend","fullstack","testing","devops"],desc:"5 agents"},{name:"Marketing",icon:Ib,roles:["cmo","creative","analyst"],desc:"3 agents"},{name:"Business",icon:Lx,roles:["cfo","analyst","ea"],desc:"3 agents"},{name:"Security Audit",icon:vn,roles:["security","testing","devops"],desc:"3 agents"},{name:"Docs",icon:On,roles:["docs","frontend","analyst"],desc:"3 agents"}];function See(){const t=k(D=>D.teamBuilderOpen),s=k(D=>D.teamBuilderRoles),n=k(D=>D.teamBuilderSettings),a=k(D=>D.teamBuilderTask),r=k(D=>D.teamTemplates),l=k(D=>D.closeTeamBuilder),c=k(D=>D.addTeamBuilderRole),A=k(D=>D.removeTeamBuilderRole),f=k(D=>D.updateTeamBuilderRole),x=k(D=>D.applyTemplate),h=k(D=>D.setTeamBuilderSettings),g=k(D=>D.setTeamBuilderTask),O=k(D=>D.launchTeamBuilder),b=k(D=>D.saveTeamTemplate),v=k(D=>D.fetchTeamTemplates),y=k(D=>D.fetchProviders),[S,j]=p.useState([]),[N,C]=p.useState(""),[U,P]=p.useState(null),[T,B]=p.useState(!1),[F,M]=p.useState(null),[R,Y]=p.useState(!1),[W,ee]=p.useState("");if(p.useEffect(()=>{t&&(y().then(D=>{Array.isArray(D)&&j(D.filter(se=>se.installed))}).catch(()=>{}),v())},[t]),!t)return null;const K=N?_g.filter(D=>D.label.toLowerCase().includes(N.toLowerCase())||D.desc.toLowerCase().includes(N.toLowerCase())):_g,_=S.find(D=>D.id===n.provider),E=((_==null?void 0:_.models)||[]).filter(D=>D.type!=="image"&&!D.disabled);function q(D){var V;h({provider:D});const se=S.find(te=>te.id===D),le=((se==null?void 0:se.models)||[]).filter(te=>te.type!=="image"&&!te.disabled);h({provider:D,model:((V=le[0])==null?void 0:V.id)||""})}function H(D){x(D),M(D.name)}async function I(){B(!0);try{await O()}catch{}B(!1)}function L(){const D=W.trim();D&&(b(D),Y(!1),ee(""))}const J=[...Nee,...(r.custom||[]).map(D=>{var se;return{...D,icon:rc,desc:`${((se=D.roles)==null?void 0:se.length)||0} agents`,custom:!0}})];return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:[e.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:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-info/15 flex items-center justify-center",children:e.jsx(yn,{size:16,className:"text-info"})}),e.jsx("h2",{className:"text-lg font-bold text-text-0 font-sans",children:"Team Builder"})]}),e.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:e.jsx(qe,{size:18})})]}),e.jsx("div",{className:"px-6 py-3 border-b border-border-subtle",children:e.jsxs("div",{className:"flex items-center gap-2 overflow-x-auto pb-1",style:{scrollbarWidth:"none"},children:[J.map(D=>{const se=D.icon||rc,le=F===D.name;return e.jsxs("button",{onClick:()=>H(D),className:Z("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:[e.jsx(se,{size:16,className:le?"text-accent":"text-text-2"}),e.jsx("span",{className:"text-2xs font-semibold text-text-0 font-sans",children:D.name}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:D.desc})]},D.name)}),e.jsx(dt,{content:"Save current roster as template",children:e.jsxs("button",{onClick:()=>{Y(!0),ee("")},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:[e.jsx(_r,{size:16,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans",children:"Save"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Template"})]})})]})}),e.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"w-[40%] border-r border-border-subtle flex flex-col",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border-subtle",children:e.jsxs("div",{className:"relative",children:[e.jsx(As,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{type:"text",value:N,onChange:D=>C(D.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"})]})}),e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"p-3 grid grid-cols-2 gap-2",children:K.map(D=>{const se=NQ[D.id]||bn;return e.jsxs("button",{onClick:()=>c(D.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:[e.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:e.jsx(se,{size:14,className:"text-text-2 group-hover:text-accent transition-colors"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:D.label}),e.jsx(it,{size:12,className:"text-text-4 group-hover:text-accent transition-colors flex-shrink-0"})]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans leading-tight mt-0.5",children:D.desc})]})]},D.id)})})})]}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center justify-between",children:e.jsxs("span",{className:"text-xs font-semibold text-text-1 font-sans uppercase tracking-wider",children:["Your Team (",s.length,")"]})}),e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"p-3 space-y-1.5",children:s.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx(yn,{size:32,className:"text-text-4 mb-3"}),e.jsx("p",{className:"text-sm text-text-2 font-sans",children:"Add roles from the left or pick a template above"})]}):s.map((D,se)=>{var be;const le=NQ[D.role]||bn,V=U===se,te=D.provider?S.find(z=>z.id===D.provider):null,ae=((te==null?void 0:te.models)||[]).filter(z=>z.type!=="image"&&!z.disabled);return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(BS,{size:12,className:"text-text-4 flex-shrink-0 cursor-grab"}),e.jsx("div",{className:"w-6 h-6 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx(le,{size:12,className:"text-text-1"})}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans flex-1",children:((be=_g.find(z=>z.id===D.role))==null?void 0:be.label)||D.role}),e.jsx("button",{onClick:()=>P(V?null:se),className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(xt,{size:12,className:Z("transition-transform duration-200",V&&"rotate-180")})}),e.jsx("button",{onClick:()=>{A(se),U===se?P(null):U>se&&P(U-1)},className:"p-1 rounded text-text-4 hover:text-danger cursor-pointer",children:e.jsx(qe,{size:12})})]}),V&&e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-3 border-t border-border-subtle bg-surface-1",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Name Override"}),e.jsx("input",{type:"text",value:D.name,onChange:z=>f(se,{name:sanitizeName(z.target.value)}),placeholder:D.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})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:D.provider||"__default__",onValueChange:z=>{var Ce;const oe=z==="__default__"?null:z,ue=S.find(Ne=>Ne.id===oe),ve=((ue==null?void 0:ue.models)||[]).filter(Ne=>Ne.type!=="image"&&!Ne.disabled);f(se,{provider:oe,model:((Ce=ve[0])==null?void 0:Ce.id)||null})},children:[e.jsx(Mn,{placeholder:"Team Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Team Default"}),S.map(z=>e.jsx(ms,{value:z.id,children:z.displayName||z.name||z.id},z.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:D.model||"__default__",onValueChange:z=>f(se,{model:z==="__default__"?null:z}),children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Default"}),ae.map(z=>e.jsx(ms,{value:z.id,children:z.name||z.id},z.id))]})]})]})]}),e.jsx(Ka,{label:"Reasoning",value:D.reasoningEffort??n.reasoningEffort,onChange:z=>f(se,{reasoningEffort:z}),min:0,max:100,step:1}),U4.has(D.provider||n.provider)&&e.jsx(Ka,{label:"Temperature",value:D.temperature??n.temperature,onChange:z=>f(se,{temperature:z}),min:0,max:1,step:.01,formatValue:z=>z.toFixed(2)})]})]},se)})})})]})]}),e.jsx("div",{className:"border-t border-border-subtle px-6 py-4",children:e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("textarea",{value:a,onChange:D=>g(D.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"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans italic",children:"Leave empty to spawn agents awaiting instructions"})]}),e.jsxs("div",{className:"w-64 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-0.5",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:n.provider||"__default__",onValueChange:D=>q(D==="__default__"?"":D),children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Default"}),S.map(D=>e.jsx(ms,{value:D.id,children:D.displayName||D.name||D.id},D.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-0.5",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:n.model||"__default__",onValueChange:D=>h({model:D==="__default__"?"":D}),children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Auto"}),E.map(D=>e.jsx(ms,{value:D.id,children:D.name||D.id},D.id))]})]})]})]}),e.jsxs(pe,{variant:"primary",size:"md",onClick:I,disabled:T||s.length===0,className:"w-full gap-2 mt-1",children:[e.jsx(qt,{size:14}),T?"Launching...":`Plan & Launch (${s.length})`]})]})]})})]}),R&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40",children:e.jsxs("div",{className:"w-full max-w-sm bg-surface-2 border border-border rounded-lg shadow-2xl p-5 space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:"Save as Template"}),e.jsx("input",{type:"text",value:W,onChange:D=>ee(D.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:D=>{D.key==="Enter"&&L(),D.key==="Escape"&&Y(!1)}}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(pe,{variant:"ghost",size:"sm",onClick:()=>Y(!1),children:"Cancel"}),e.jsx(pe,{variant:"primary",size:"sm",onClick:L,disabled:!W.trim(),children:"Save"})]})]})})]})}function Cee({onPlanner:t,onSpawn:s,onTeamBuilder:n}){var a;return e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsxs("div",{className:"max-w-2xl w-full text-center space-y-10 px-8",children:[e.jsxs("div",{className:"relative mx-auto w-20 h-20",children:[e.jsx("div",{className:"absolute inset-0 rounded-full bg-accent/8 animate-pulse"}),e.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:e.jsx("img",{src:"/favicon.png",alt:"Groove",className:"h-10 w-10 rounded-full"})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h1",{className:"text-3xl font-bold text-text-0 font-sans tracking-tight",children:"Welcome to Groove"}),e.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."})]}),e.jsxs("div",{className:"space-y-3 max-w-xl mx-auto",children:[e.jsxs("button",{onClick:t,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:[e.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:e.jsx(qt,{size:24,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-base font-semibold text-text-0 font-sans",children:"Start with a Planner"}),e.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"})]}),e.jsx("div",{className:"text-accent text-xs font-semibold font-sans flex-shrink-0 opacity-60 group-hover:opacity-100 transition-opacity",children:"Recommended"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.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:[e.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:e.jsx(HS,{size:20,className:"text-info"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Build a Team"}),e.jsx("div",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Pick roles and configure"})]})]}),e.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:[e.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:e.jsx(it,{size:20,className:"text-text-1"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn Agent"}),e.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)&&e.jsxs("div",{className:"max-w-sm mx-auto",children:[e.jsx("p",{className:"text-xs text-text-3 mb-2",children:"Or open a different project"}),e.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:[e.jsx(Ys,{size:16,className:"text-accent"}),"Open Folder"]})]}),e.jsxs("p",{className:"text-xs text-text-4 font-sans",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+K"}),e.jsx("span",{className:"mx-1.5",children:"command palette"}),e.jsx("span",{className:"text-text-4 mx-1",children:"·"}),e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+N"}),e.jsx("span",{className:"mx-1.5",children:"spawn"}),e.jsx("span",{className:"text-text-4 mx-1",children:"·"}),e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+J"}),e.jsx("span",{className:"mx-1.5",children:"terminal"})]})]})})}function Dg(){var M;const t=k(R=>R.agents),s=k(R=>R.activeTeamId),n=k(R=>R.openDetail),a=k(R=>R.spawnAgent),r=k(R=>R.selectAgent);k(R=>R.recommendedTeam);const l=k(R=>R.checkRecommendedTeam),c=k(R=>R.addToast),A=k(R=>R.showPreviewInAgents),f=k(R=>R.previewState),x=k(R=>R.togglePreviewInAgents),h=k(R=>R.teamPreviews),g=k(R=>R.relaunchPreview),O=k(R=>R.openPreview),b=k(R=>R.workspaceMode),v=k(R=>R.setWorkspaceMode),y=k(R=>R.openTeamBuilder),[S,j]=p.useState(!1);p.useEffect(()=>{if(!t.some(W=>W.role==="planner"&&(W.status==="running"||W.status==="starting")))return;const Y=setInterval(()=>l(),5e3);return()=>clearInterval(Y)},[t,l]);function N(){j(!0)}async function C(R){j(!1);try{const Y=await a({role:"planner",provider:R.provider,model:R.model,reasoningEffort:R.reasoningEffort,temperature:R.temperature,verbosity:R.verbosity});Y!=null&&Y.id&&r(Y.id)}catch{}}const U=t.filter(R=>{var Y;return R.teamId===s&&!((Y=R.metadata)!=null&&Y.scheduled)}),P=k(R=>R.hydrated),[T,B]=p.useState(!0);p.useEffect(()=>{const R=setTimeout(()=>B(!1),1200);return()=>clearTimeout(R)},[]);const F=T||!P;return e.jsxs("div",{className:"flex flex-col h-full relative",children:[e.jsx("div",{className:"flex-1 min-h-0",children:F?e.jsxs("div",{className:Z("flex flex-col items-center justify-center h-full transition-opacity duration-500",!T&&P?"opacity-0":"opacity-100"),children:[e.jsxs("div",{className:"relative w-12 h-12 mb-5",children:[e.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-accent/20 animate-ping",style:{animationDuration:"2s"}}),e.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent animate-spin",style:{animationDuration:"1s"}}),e.jsx("span",{className:"absolute inset-[6px] rounded-full bg-accent/8 flex items-center justify-center",children:e.jsx(qt,{size:16,className:"text-accent animate-pulse"})})]}),e.jsx("p",{className:"text-sm font-medium text-text-1 font-sans animate-pulse",children:"Connecting to agents"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Syncing with daemon..."})]}):U.length===0?e.jsx(Cee,{onPlanner:N,onSpawn:()=>n({type:"spawn"}),onTeamBuilder:y}):b?e.jsx(nY,{}):A&&f.url&&f.teamId===s&&((M=h[s])!=null&&M.active)?e.jsx(RX,{embedded:!0}):e.jsx(CU,{children:e.jsx(wee,{})},s)}),!b&&e.jsx(qf,{}),!F&&U.length>0&&!b&&e.jsxs("div",{className:"absolute bottom-3 left-3 z-40 flex items-center gap-1.5",children:[e.jsx(dt,{content:"Spawn agent",side:"top",children:e.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:e.jsx(it,{size:15})})}),e.jsx(dt,{content:Object.keys(k4()).length>0?"Update layout":"Save layout",side:"top",children:e.jsx("button",{onClick:()=>{const R=FA(s),Y={},W=new Map;[...U].sort((ee,K)=>(ee.name||ee.id).localeCompare(K.name||K.id)).forEach(ee=>{const K=ee.name||ee.id,_=R[K];if(!_)return;const E=ee.role||"agent",q=W.get(E)||0;W.set(E,q+1);const H=q===0?E:`${E}-${q}`;Y[H]=_}),R[Xs]&&(Y[Xs]=R[Xs]),Oee(Y),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:e.jsx(yM,{size:15})})}),e.jsx(dt,{content:"Workspace",side:"top",children:e.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:e.jsx(bn,{size:15})})}),(()=>{const R=h[s];if(!R)return null;const Y=R.active&&f.url&&f.teamId===s,W=Y&&A,ee=W?"Show team":Y?"Show preview":"Relaunch preview";return e.jsx(dt,{content:ee,side:"top",children:e.jsx("button",{onClick:()=>{Y?A?x():O(R.url,s,R.kind):g(s)},className:Z("flex items-center justify-center w-8 h-8 rounded border bg-surface-2/50 transition-colors cursor-pointer",Y?"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:W?e.jsx(yn,{size:15}):e.jsx(Vs,{size:15})})})})()]}),e.jsx(Qee,{open:S,onOpenChange:j,onLaunch:C}),e.jsx(See,{})]})}function Bee({children:t,detailContent:s,terminalContent:n}){const a=k(T=>T.activeView),r=k(T=>T.detailPanel),l=k(T=>T.connected),c=k(T=>T.tunneled),A=k(T=>T.daemonHost),f=k(T=>T.agents),x=k(T=>T.editorActiveFile),h=k(T=>T.detailPanelWidth),g=k(T=>T.terminalVisible),O=k(T=>T.terminalFullHeight),b=k(T=>T.setActiveView),v=k(T=>T.openDetail),y=k(T=>T.closeDetail),S=k(T=>T.setDetailPanelWidth),j=k(T=>T.setTerminalVisible),N=k(T=>T.toggleCommandPalette),C=p.useMemo(()=>f.filter(T=>T.status==="running").length,[f]),U=p.useMemo(()=>[{key:"k",meta:!0,handler:()=>k.getState().toggleCommandPalette()},{key:"p",meta:!0,shift:!0,handler:()=>k.getState().toggleCommandPalette()},{key:"j",meta:!0,handler:()=>{const T=k.getState();T.setTerminalVisible(!T.terminalVisible)}},{key:"n",meta:!0,handler:()=>k.getState().openDetail({type:"spawn"})},{key:"1",meta:!0,handler:()=>k.getState().setActiveView("agents")},{key:"2",meta:!0,handler:()=>k.getState().setActiveView("editor")},{key:"3",meta:!0,handler:()=>k.getState().setActiveView("dashboard")},{key:"4",meta:!0,handler:()=>k.getState().setActiveView("marketplace")},{key:"5",meta:!0,handler:()=>k.getState().setActiveView("teams")},{key:"Escape",handler:()=>{const T=k.getState();T.commandPaletteOpen?T.toggleCommandPalette():T.detailPanel&&T.closeDetail()}}],[]);pN(U);const P=r&&r.type!=="spawn";return e.jsx(v$,{children:e.jsxs("div",{className:Z("w-full h-full flex flex-col bg-surface-2 text-text-1 font-sans",cd()&&"electron-app"),children:[e.jsx(Uz,{activeView:a,connected:l,tunneled:c,daemonHost:A,editorActiveFile:x,onOpenCommandPalette:N}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsx(Cz,{activeView:a,detailPanel:r,onNavigate:b,onTogglePanel:T=>{(r==null?void 0:r.type)===T?y():v({type:T})}}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[a==="agents"&&e.jsx(yee,{}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[!(g&&O)&&e.jsx("main",{className:"flex-1 min-h-0 overflow-hidden relative",children:t}),n]}),P&&e.jsx(D_,{width:h,onWidthChange:S,onClose:y,children:s})]})]})]}),e.jsx(__,{connected:l,agentCount:f.length,runningCount:C,terminalVisible:g,onToggleTerminal:()=>j(!g)}),e.jsx(H_,{}),e.jsx(NC,{}),e.jsx(X_,{}),e.jsx(G_,{}),e.jsx(ZS,{})]})})}function kee({id:t,name:s,subtitle:n,models:a,authType:r,recommended:l,installed:c,installing:A,failed:f,selected:x,onInstall:h,gradientFrom:g,letter:O,statusChecking:b}){return e.jsxs(_n.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.25},className:Z("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",x?"border-accent ring-1 ring-accent/30 shadow-md shadow-accent/10":"border-border-subtle",A&&"pointer-events-none opacity-70"),children:[x&&e.jsx("div",{className:"absolute top-3 left-3 w-5 h-5 rounded-full bg-accent flex items-center justify-center",children:e.jsx(Je,{className:"w-3 h-3 text-surface-0",strokeWidth:3})}),e.jsxs("div",{className:"flex items-start gap-4 mb-5",children:[e.jsx("div",{className:Z("w-14 h-14 rounded-md flex items-center justify-center text-lg font-bold font-mono shrink-0",g),children:O}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:s}),l&&e.jsx(Te,{variant:"purple",className:"text-2xs",children:"Recommended"})]}),e.jsx("p",{className:"text-xs text-text-2 mt-0.5",children:n})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",children:a.map(v=>e.jsx("span",{className:"text-xs text-text-2 bg-surface-4 px-2 py-0.5 rounded font-mono",children:v},v))}),e.jsx("p",{className:"text-2xs text-text-3 mb-4",children:r}),e.jsx("div",{className:"mt-auto pt-4 border-t border-border-subtle",children:A?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4 text-accent animate-spin"}),e.jsx("span",{className:"text-xs text-accent font-medium",children:"Installing..."})]}),e.jsx("div",{className:"h-1 bg-surface-4 rounded-full overflow-hidden",children:e.jsx(_n.div,{className:"h-full bg-accent rounded-full",initial:{width:"0%"},animate:{width:"90%"},transition:{duration:15,ease:"easeOut"}})})]}):c?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rx,{className:"w-4 h-4 text-success"}),e.jsx("span",{className:"text-xs text-success font-medium",children:"Ready"})]}):f?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"w-4 h-4 text-danger"}),e.jsx("span",{className:"text-xs text-danger font-medium",children:"Failed"})]}),e.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(t)},children:[e.jsx(Io,{className:"w-3 h-3"}),"Retry"]})]}):b?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-3.5 h-3.5 text-text-4 animate-spin"}),e.jsx("span",{className:"text-xs text-text-4",children:"Checking..."})]}):e.jsx("div",{className:"flex items-center justify-end",children:e.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(t)},children:[e.jsx(qs,{className:"w-3.5 h-3.5"}),"Install"]})})})]})}const ja=[{id:"claude-code",name:"Claude Code",subtitle:"by Anthropic",models:["Opus 5","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"}],Tee={enter:t=>({x:t>0?80:-80,opacity:0}),center:{x:0,opacity:1},exit:t=>({x:t<0?80:-80,opacity:0})},Uee={duration:.25,ease:[.4,0,.2,1]};function Eee({current:t,total:s}){return e.jsx("div",{className:"flex items-center gap-2.5",children:Array.from({length:s},(n,a)=>e.jsx("div",{className:Z("h-2 rounded-full transition-all duration-300",a===t?"w-7 bg-accent":a<t?"w-2 bg-accent/50":"w-2 bg-surface-5")},a))})}function Pee({onNext:t,onSkip:s}){return e.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[e.jsx(_n.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"}}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"Welcome to Groove"}),e.jsx("p",{className:"text-sm text-text-2",children:"Your AI coding team, ready in minutes"})]}),e.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."}),e.jsxs("button",{type:"button",onClick:t,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",e.jsx(Mo,{className:"w-4 h-4"})]}),e.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 Fee({selectedDir:t,onSelectDir:s}){const n=k(A=>A.remoteHomedir),[a,r]=p.useState(!1),l=new URLSearchParams(window.location.search).has("instance");async function c(){var f,x;if(l){r(!0);return}const A=await wE({title:"Choose your project folder",defaultPath:t||void 0});A?s(A):(x=(f=window.groove)==null?void 0:f.folders)!=null&&x.select||r(!0)}return e.jsxs("div",{className:"flex flex-col items-center max-w-lg mx-auto w-full text-center",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your project folder"}),e.jsx("p",{className:"text-sm text-text-2",children:"Pick the root directory where your code lives. Groove will manage agents from here."})]}),e.jsx("div",{className:"w-full bg-surface-2 border border-border-subtle rounded-lg p-5 mb-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-lg bg-accent/10 flex items-center justify-center",children:e.jsx(Ys,{className:"w-6 h-6 text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[e.jsx("p",{className:"text-xs text-text-3 mb-0.5",children:"Working directory"}),e.jsx("p",{className:"text-sm font-mono text-text-0 truncate",children:t||"No folder selected"})]})]})}),e.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:[e.jsx(Ys,{className:"w-4 h-4"}),t?"Change Folder":"Select Folder"]}),e.jsx("p",{className:"mt-4 text-2xs text-text-4",children:"You can change this anytime in Settings."}),a&&e.jsx(gc,{open:a,onOpenChange:r,currentPath:t||n||"/",homePath:n,onSelect:A=>{s(A),r(!1)}})]})}function $ee({providerStatus:t,selected:s,onInstall:n,installing:a,statusChecking:r}){const l=ja.filter(A=>{var f;return(f=t[A.id])==null?void 0:f.installed}).length,c=l===ja.length;return e.jsxs("div",{className:"flex flex-col items-center max-w-4xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your AI providers"}),e.jsx("p",{className:"text-sm text-text-2",children:"Install the coding tools you want to use. You can always add more later."})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 w-full mb-8",children:ja.map(A=>{var f,x;return e.jsx(kee,{...A,installed:(f=t[A.id])==null?void 0:f.installed,installing:a[A.id],failed:(x=t[A.id])==null?void 0:x.failed,selected:s.includes(A.id),onInstall:n,statusChecking:r},A.id)})}),e.jsx("p",{className:Z("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 ${ja.length} providers installed`:"Click Install to set up a provider"})]})}function Ree({provider:t,providerStatus:s,onSaveKey:n}){const[a,r]=p.useState(t.authModes.includes("subscription")?"subscription":"apikey"),[l,c]=p.useState(""),[A,f]=p.useState(!1),[x,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(t.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 e.jsxs(_n.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:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:Z("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono",t.gradientFrom),children:t.letter}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:t.name}),e.jsx("p",{className:"text-2xs text-text-3",children:t.subtitle})]}),(g||(s==null?void 0:s.authenticated))&&e.jsx(Te,{variant:"success",className:"ml-auto",children:"Connected"})]}),t.authModes.length>1&&e.jsx("div",{className:"flex gap-1 mb-4 bg-surface-3 p-0.5 rounded-md",children:t.authModes.map(y=>e.jsx("button",{type:"button",onClick:()=>r(y),className:Z("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===y?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:y==="subscription"?"Subscription":y==="chatgpt-plus"?"ChatGPT Plus":"API Key"},y))}),a==="subscription"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-text-2",children:"Sign in via the terminal with your Claude subscription."}),e.jsx("div",{className:"space-y-1.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans",children:["Open a terminal and run: ",e.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)&&e.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[e.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="chatgpt-plus"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-xs text-text-2",children:["Run ",e.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)&&e.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[e.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="apikey"&&e.jsx("div",{className:"space-y-3",children:g||s!=null&&s.authenticated?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-8 rounded-md bg-surface-1 border border-border px-3 flex items-center",children:e.jsx("span",{className:"text-xs text-text-3 font-mono truncate",children:v||"••••••••••••••"})}),e.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"})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{type:A?"text":"password",value:l,onChange:y=>c(y.target.value),placeholder:t.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:y=>y.key==="Enter"&&b(),"aria-label":t.keyLabel}),e.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?e.jsx(To,{className:"w-3.5 h-3.5"}):e.jsx(Vs,{className:"w-3.5 h-3.5"})})]}),e.jsx("button",{type:"button",onClick:b,disabled:!l.trim()||x,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:x?"Saving...":"Save"})]})})]})}function Mee({providerStatus:t,installedIds:s,onSaveKey:n}){const a=ja.filter(r=>{var l;return s.includes(r.id)||((l=t[r.id])==null?void 0:l.installed)});return a.some(r=>{var l;return(l=t[r.id])==null?void 0:l.authenticated}),e.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Connect your accounts"}),e.jsx("p",{className:"text-sm text-text-2",children:"Add credentials for your installed providers."})]}),e.jsx("div",{className:"flex flex-col gap-4 w-full mb-6",children:a.map(r=>e.jsx(Ree,{provider:r,providerStatus:t[r.id]||{},onSaveKey:n},r.id))}),a.length===0&&e.jsx("p",{className:"text-sm text-text-3 text-center",children:"No providers installed yet. Go back to install one."})]})}function Iee({providerStatus:t,installedIds:s,defaultProvider:n,defaultModel:a,onSetDefault:r}){var c;const l=ja.filter(A=>{var f,x;return(s.includes(A.id)||((f=t[A.id])==null?void 0:f.installed))&&((x=t[A.id])==null?void 0:x.authenticated)});return e.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Set your default"}),e.jsx("p",{className:"text-sm text-text-2",children:"Choose which provider and model to use by default. You can switch per-agent anytime."})]}),e.jsxs("div",{className:"flex flex-col gap-3 w-full max-w-md mb-6",children:[l.map(A=>e.jsxs("button",{type:"button",onClick:()=>r(A.id,A.models[0]),className:Z("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:[e.jsx("div",{className:Z("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono shrink-0",A.gradientFrom),children:A.letter}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:A.name}),e.jsx("p",{className:"text-2xs text-text-3",children:A.subtitle})]}),e.jsx("div",{className:Z("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&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-surface-0"})})]},A.id)),l.length===0&&e.jsx("p",{className:"text-sm text-text-3 text-center",children:"No authenticated providers. Go back to connect one."})]}),n&&e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 mb-2 block",children:"Model"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(c=ja.find(A=>A.id===n))==null?void 0:c.models.map(A=>e.jsx("button",{type:"button",onClick:()=>r(n,A),className:Z("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 zee({providerStatus:t,defaultProvider:s,defaultModel:n,onFinish:a}){var c;const r=ja.filter(A=>{var f;return(f=t[A.id])==null?void 0:f.installed}).length,l=(c=ja.find(A=>A.id===s))==null?void 0:c.name;return e.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[e.jsx(_n.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:e.jsx(Je,{className:"w-10 h-10 text-success",strokeWidth:2.5})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"You're all set!"}),e.jsxs("p",{className:"text-sm text-text-2",children:[r," provider",r!==1?"s":""," installed",l?`, default: ${l}`:"",n?` (${n})`:""]})]}),e.jsx(_n.div,{className:"flex gap-3 mt-4",initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.3},children:e.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:[e.jsx(Js,{className:"w-4 h-4"}),"Start Building"]})})]})}const yA=6;function _ee(){const t=k(H=>H.dismissOnboarding),s=k(H=>H.installProvider),n=k(H=>H.setDefaultProvider),a=k(H=>H.addToast),[r,l]=p.useState(0),[c,A]=p.useState(1),[f,x]=p.useState(["claude-code"]),[h,g]=p.useState({}),[O,b]=p.useState({}),[v,y]=p.useState(null),[S,j]=p.useState(null),[N,C]=p.useState(!0),[U,P]=p.useState(null),T=p.useRef(null);p.useEffect(()=>{let H=!1;async function I(){var J;try{const D=await fetch("/api/onboarding/status").then(se=>se.ok?se.json():null);if(D!=null&&D.providers){const se={},le=[];for(const V of D.providers){const te=V.authStatus==="authenticated"||V.authStatus==="key-set";se[V.id]={installed:V.installed,authenticated:te},V.installed&&le.push(V.id)}return{status:se,installedIds:le,workingDir:((J=D.config)==null?void 0:J.defaultWorkingDir)||null}}}catch{}try{const D=await fetch("/api/providers").then(se=>se.ok?se.json():null);if(D){const se={},le=[],V=Array.isArray(D)?D:D.providers||[];for(const te of V){const ae=te.installed||te.authStatus==="authenticated"||te.authStatus==="key-set"||!1;se[te.id]={installed:ae,authenticated:te.authenticated||!1},ae&&le.push(te.id)}return{status:se,installedIds:le}}}catch{}return null}async function L(){C(!0);let J=await I();if(!H&&J&&J.installedIds.length===0)for(let D=0;D<2;D++){if(await new Promise(se=>setTimeout(se,2e3)),H)return;if(J=await I(),J&&J.installedIds.length>0)break}!H&&J&&(b(J.status),J.installedIds.length>0&&x(D=>[...new Set([...D,...J.installedIds])]),J.workingDir&&!U&&P(J.workingDir)),H||C(!1)}return L(),()=>{H=!0}},[r]);const B=p.useCallback(()=>{r<yA-1&&(A(1),l(H=>H+1))},[r]),F=p.useCallback(()=>{r>0&&(A(-1),l(H=>H-1))},[r]),M=p.useCallback(()=>{t()},[t]),R=p.useCallback(async()=>{if(U)try{await P(U)}catch{a("error","Failed to set project directory")}t()},[t,U,a]),Y=p.useCallback(async H=>{g(I=>({...I,[H]:!0}));try{await s(H),b(I=>({...I,[H]:{...I[H],installed:!0}})),x(I=>I.includes(H)?I:[...I,H])}catch{b(I=>({...I,[H]:{...I[H],failed:!0}}))}finally{g(I=>({...I,[H]:!1}))}},[s]),W=p.useCallback(async(H,I)=>{try{if(!(await fetch(`/api/credentials/${encodeURIComponent(H)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:I})})).ok)throw new Error("Failed to save key");b(J=>({...J,[H]:{...J[H],authenticated:!0,maskedKey:`${I.slice(0,6)}${"•".repeat(20)}`}})),a("success","API key saved")}catch(L){throw a("error","Failed to save key",L.message),L}},[a]),ee=p.useCallback(async(H,I)=>{y(H),j(I);try{await n(H,I)}catch{}},[n]),K=ja.some(H=>{var I;return(I=O[H.id])==null?void 0:I.installed}),_=ja.some(H=>{var I;return(I=O[H.id])==null?void 0:I.authenticated}),E=r===0||r===1?!0:r===2?K:r===3?_:r===4?!!v:!1;p.useEffect(()=>{const H=I=>{I.key==="Enter"&&r<yA-1&&E&&B(),I.key==="Escape"&&M()};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[r,E,B,M]);const q=[e.jsx(Pee,{onNext:B,onSkip:M},"welcome"),e.jsx(Fee,{selectedDir:U,onSelectDir:P},"folder"),e.jsx($ee,{providerStatus:O,selected:f,onInstall:Y,installing:h,statusChecking:N},"install"),e.jsx(Mee,{providerStatus:O,installedIds:f,onSaveKey:W},"auth"),e.jsx(Iee,{providerStatus:O,installedIds:f,defaultProvider:v,defaultModel:S,onSetDefault:ee},"default"),e.jsx(zee,{providerStatus:O,defaultProvider:v,defaultModel:S,onFinish:R},"done")];return e.jsxs("div",{ref:T,className:"fixed inset-0 z-50 bg-gradient-to-b from-surface-0 to-surface-1 flex flex-col font-sans overflow-hidden",children:[cd()&&e.jsx("div",{className:"h-8 w-full electron-drag shrink-0"}),e.jsxs("div",{className:"flex items-center justify-between px-8 py-4 shrink-0",children:[e.jsx(Eee,{current:r,total:yA}),r>0&&r<yA-1&&e.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"})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center px-8 py-4 overflow-y-auto",children:e.jsx(Mi,{mode:"wait",custom:c,children:e.jsx(_n.div,{custom:c,variants:Tee,initial:"enter",animate:"center",exit:"exit",transition:Uee,className:"w-full",children:q[r]},r)})}),r>0&&r<yA-1&&e.jsxs("div",{className:"flex items-center justify-between px-8 py-8 shrink-0",children:[e.jsxs("button",{type:"button",onClick:F,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:[e.jsx(Di,{className:"w-4 h-4"}),"Back"]}),e.jsxs("button",{type:"button",onClick:B,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",e.jsx(Tt,{className:"w-4 h-4"})]})]})]})}const Dee=[{icon:Ns,label:"Federation",desc:"Multi-machine daemon pairing"},{icon:Eb,label:"Cloud Teams",desc:"Coming soon"}];function SQ(){var y;const t=k(S=>S.upgradeModalOpen),s=k(S=>S.setUpgradeModalOpen),n=k(S=>S.marketplaceAuthenticated),a=k(S=>S.marketplaceLogin),r=k(S=>S.startCheckout),l=k(S=>S.addToast),[c,A]=p.useState(null),[f,x]=p.useState("monthly"),[h,g]=p.useState(!1);p.useEffect(()=>{t&&!c&&k.getState().fetchSubscriptionPlans().then(S=>A(S)).catch(()=>{})},[t,c]);const O=(y=c==null?void 0:c.pro)==null?void 0:y[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 S;if(!n){a();return}if(!(O!=null&&O.priceId)){sO("https://groovedev.ai/pro"),s(!1);return}g(!0);try{await r(O.priceId),s(!1)}catch(j){j.status===401||(S=j.message)!=null&&S.includes("Not authenticated")?(l("info","Please sign in first"),a()):j.status===409&&(l("info","You already have a subscription"),s(!1))}finally{g(!1)}}return e.jsx(Vt,{open:t,onOpenChange:s,children:e.jsx(Kt,{title:"Upgrade to Pro",className:"max-w-[440px]",children:e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx("div",{className:"mx-auto mb-3 w-12 h-12 rounded-full bg-accent/10 flex items-center justify-center",children:e.jsx(Js,{size:22,className:"text-accent"})}),e.jsx("h2",{className:"text-lg font-bold text-text-0",children:"Upgrade to Groove Pro"}),e.jsx("p",{className:"text-sm text-text-2 mt-1",children:"Unlock powerful features for your AI workflow"})]}),e.jsx("div",{className:"space-y-3 mb-6",children:Dee.map(S=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx(S.icon,{size:15,className:"text-accent"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-text-0",children:S.label}),e.jsx("p",{className:"text-2xs text-text-3",children:S.desc})]}),e.jsx(Je,{size:14,className:"text-success ml-auto flex-shrink-0"})]},S.label))}),e.jsxs("div",{className:"flex gap-1 mb-5 bg-surface-3 p-0.5 rounded-md",children:[e.jsx("button",{type:"button",onClick:()=>x("monthly"),className:Z("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"}),e.jsxs("button",{type:"button",onClick:()=>x("annual"),className:Z("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",e.jsx("span",{className:"ml-1 text-success text-2xs",children:"Save 20%"})]})]}),e.jsxs("div",{className:"text-center mb-5",children:[e.jsx("span",{className:"text-3xl font-bold text-text-0",children:b}),f==="annual"&&e.jsxs("p",{className:"text-2xs text-text-3 mt-1",children:["Billed $",(O==null?void 0:O.price)||96,"/year"]})]}),e.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?e.jsxs(e.Fragment,{children:[e.jsx(Js,{size:15})," Subscribe — ",b]}):e.jsxs(e.Fragment,{children:[e.jsx(PS,{size:15})," Sign in to subscribe"]})}),e.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 Lee(){const t=k(l=>l.dataSharingModalOpen),s=k(l=>l.setTrainingOptIn),n=k(l=>l.dismissDataSharingModal),[a,r]=p.useState(!1);return e.jsx(Vt,{open:t,children:e.jsxs(Kt,{className:"max-w-md",description:"Help improve Groove by sharing usage data",onInteractOutside:l=>l.preventDefault(),onEscapeKeyDown:l=>l.preventDefault(),children:[e.jsxs("div",{className:"relative bg-gradient-to-br from-accent/5 to-transparent px-6 pt-8 pb-6 text-center",children:[e.jsx("div",{className:"flex justify-center mb-3",children:e.jsx("div",{className:"w-14 h-14 rounded-xl bg-accent/10 flex items-center justify-center",children:e.jsx(Js,{size:32,className:"text-accent"})})}),e.jsx(nm,{className:"text-xl font-bold text-text-0 font-sans",children:"Help Build a Better Groove"}),e.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."})]}),e.jsx("div",{className:"px-6 pt-4",children:e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2/30 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx(vn,{size:14,className:"text-text-2"}),e.jsx("span",{className:"text-xs font-semibold uppercase text-text-3 tracking-wider font-sans",children:"What We Never Collect"})]}),e.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=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qe,{size:12,className:"text-danger flex-shrink-0"}),e.jsx("span",{className:"text-xs text-text-1 font-sans",children:l})]},l))}),e.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."})]})}),e.jsxs("div",{className:"border-t border-border-subtle mt-5 pt-4 pb-1 px-6",children:[e.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:[e.jsx(Js,{size:15}),"Turn On Sharing"]}),e.jsx("div",{className:"text-center mt-2.5",children:e.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"})}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-3",children:[e.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"}),e.jsx("label",{htmlFor:"data-sharing-dismiss",className:"text-2xs text-text-3 font-sans cursor-pointer select-none",children:"Don't show this again"})]}),e.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 Hee(){const t=k(P=>P.recentProjects),s=k(P=>P.setProjectDir),n=k(P=>P.removeRecentProject),a=k(P=>P.remoteHomedir),r=k(P=>P.savedTunnels),l=k(P=>P.fetchTunnels),c=k(P=>P.deleteTunnel),A=k(P=>P.connectTunnel),f=k(P=>P.disconnectTunnel),x=k(P=>P.toggleQuickConnect),h=k(P=>P.addToast),g=k(P=>P.tunnelConnectStep),[O,b]=p.useState(!1),[v,y]=p.useState(null);p.useEffect(()=>{l()},[l]);const S=(t||[]).slice(0,8),j=S.length>0,N=r.length>0,C=j||N;async function U(P){var T,B;if(P.active){(B=(T=window.groove)==null?void 0:T.remote)!=null&&B.openWindow?window.groove.remote.openWindow(P.localPort,P.name):window.open(`http://localhost:${P.localPort}?instance=${encodeURIComponent(P.name)}`,"_blank");return}y(P.id);try{await A(P.id)}catch(F){const M=(F==null?void 0:F.message)||"Unknown error";/permission|EACCES|sudo|Node\.js is not installed|npm install failed|write access/i.test(M)?(x(),h("warning","Remote setup needed","Follow the instructions to set up the remote server.")):h("error","Connection failed",M)}y(null)}return e.jsxs("div",{className:"fixed inset-0 z-50 overflow-y-auto welcome-bg",children:[e.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]"}),e.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:[e.jsxs("div",{className:"flex flex-col items-center text-center mb-14",children:[e.jsxs("div",{className:"relative mb-8",children:[e.jsx("div",{className:"absolute -inset-10 rounded-full bg-accent/[0.06] blur-3xl animate-welcome-breathe"}),e.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/25 animate-welcome-ring"}),e.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/15 animate-welcome-ring-delayed"}),e.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:e.jsx("img",{src:"/favicon.png",className:"w-12 h-12 rounded-full",alt:"Groove"})})]}),e.jsx("h1",{className:"text-4xl font-bold text-text-0 tracking-tight mb-3 font-sans max-sm:text-3xl",children:"Welcome to Groove"}),e.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.",e.jsx("br",{className:"max-sm:hidden"}),e.jsx("span",{className:"max-sm:hidden",children:" "}),"Spawn fast. Stay aware. Never lose context."]})]}),e.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:[e.jsxs("button",{onClick:()=>b(!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:[e.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:e.jsx(Ys,{size:24,className:"text-accent"})}),e.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Open Project"}),e.jsx("div",{className:"text-sm text-text-2 font-sans",children:"Browse the filesystem to pick a project"}),e.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 ",e.jsx(Mo,{size:12})]})]}),e.jsxs("button",{onClick:x,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:[e.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:e.jsx(Ui,{size:24,className:"text-text-2 group-hover:text-accent transition-colors duration-300"})}),e.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Connect to Remote"}),e.jsx("div",{className:"text-sm text-text-2 font-sans",children:"SSH tunnel to a server running Groove"}),e.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 ",e.jsx(Mo,{size:12})]})]})]}),C&&e.jsxs("div",{className:Z("w-full max-w-4xl gap-6 mb-14 max-sm:flex max-sm:flex-col max-sm:gap-6",j&&N?"grid grid-cols-2":"flex justify-center"),children:[j&&e.jsxs("div",{className:Z(!N&&"w-full max-w-lg"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Dn,{size:13,className:"text-text-3"}),e.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Recent Projects"})]}),e.jsx("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:S.map(P=>e.jsxs("div",{className:"group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",children:[e.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:e.jsx(Ys,{size:14,className:"text-text-3 group-hover:text-accent transition-colors"})}),e.jsxs("button",{onClick:()=>s(P.path),className:"flex-1 min-w-0 text-left cursor-pointer",children:[e.jsx("div",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:P.name}),e.jsx("div",{className:"text-2xs font-mono text-text-4 truncate",children:P.path})]}),e.jsx("button",{onClick:T=>{T.stopPropagation(),n(P.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:e.jsx(qe,{size:14})})]},P.path))})]}),N&&e.jsxs("div",{className:Z(!j&&"w-full max-w-lg"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ns,{size:13,className:"text-text-3"}),e.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"SSH Connections"})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:[r.map(P=>e.jsxs("div",{className:Z("group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",v===P.id&&"opacity-60 pointer-events-none"),children:[e.jsx("div",{className:Z("w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0 transition-colors",P.active?"bg-success/10":"bg-surface-3 group-hover:bg-accent/10"),children:e.jsx(Ns,{size:14,className:Z("transition-colors",P.active?"text-success":"text-text-3 group-hover:text-accent")})}),e.jsxs("button",{onClick:()=>U(P),disabled:v===P.id,className:"flex-1 min-w-0 text-left cursor-pointer",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:P.name}),P.active&&e.jsx(Gt,{status:"running",size:"sm"})]}),e.jsxs("div",{className:"text-2xs font-mono text-text-4 truncate",children:[P.user,"@",P.host]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[v===P.id?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(De,{size:14,className:"text-text-3 animate-spin"}),(g==null?void 0:g.id)===P.id&&(g==null?void 0:g.step)&&e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:{testing:"Testing…",installing:"Installing…",checking:"Checking for updates…",upgrading:"Updating remote…",starting:"Starting daemon…",connecting:"Connecting…",forwarding:"Establishing tunnel…"}[g.step]||g.step})]}):P.active?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>U(P),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:[e.jsx(Ws,{size:11})," Open"]}),e.jsx("button",{onClick:async()=>{await f(P.id),h("info","Disconnected",P.name)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all",title:"Disconnect",children:e.jsx(Yx,{size:12})})]}):null,e.jsx("button",{onClick:T=>{T.stopPropagation(),c(P.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:e.jsx(qe,{size:14})})]})]},P.id)),e.jsxs("button",{onClick:x,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:[e.jsx(it,{size:11})," Add Connection"]})]})]})]}),e.jsx("div",{className:"mt-auto pt-8 flex flex-col items-center gap-4",children:e.jsxs("div",{className:"flex items-center gap-5 text-xs text-text-4 font-sans",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘K"}),e.jsx("span",{children:"palette"})]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘N"}),e.jsx("span",{children:"spawn"})]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘J"}),e.jsx("span",{children:"terminal"})]})]})})]}),e.jsx(gc,{open:O,onOpenChange:b,currentPath:a||"/home",homePath:a,onSelect:P=>{b(!1),s(P)}}),e.jsx(NC,{}),e.jsx(ZS,{})]})}const Xee={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 Gee(t){var n;const s=(n=t.split(".").pop())==null?void 0:n.toLowerCase();return Xee[s]||"text-text-3"}function Zee({x:t,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]),e.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:t,top:s},children:n.map((l,c)=>l.separator?e.jsx("div",{className:"h-px bg-border-subtle my-1"},c):e.jsxs("button",{onClick:()=>{l.action(),a()},className:Z("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&&e.jsx(l.icon,{size:12,className:l.danger?"text-danger":"text-text-3"}),l.label]},c))})}function Tx({defaultValue:t="",placeholder:s,onSubmit:n,onCancel:a,depth:r=0}){const[l,c]=p.useState(t),A=p.useRef(null);p.useEffect(()=>{var x,h;(x=A.current)==null||x.focus(),t&&((h=A.current)==null||h.select())},[t]);function f(x){if(x.key==="Enter"){const h=l.trim();h&&n(h)}x.key==="Escape"&&a()}return e.jsx("div",{className:"flex items-center py-0.5",style:{paddingLeft:r*16+8},children:e.jsx("input",{ref:A,value:l,onChange:x=>c(x.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 Vee({status:t}){if(!t)return null;const s=t==="A"||t==="?"?"bg-success":t==="D"?"bg-danger":"bg-warning";return e.jsx("span",{className:Z("w-1.5 h-1.5 rounded-full flex-shrink-0",s)})}function Kee(t,s){const n=document.createElement("a");n.href=`/api/files/download?path=${encodeURIComponent(t)}`,n.download=s?`${t.split("/").pop()}.zip`:t.split("/").pop(),document.body.appendChild(n),n.click(),n.remove()}function E4({entry:t,depth:s=0,activePath:n,onFileClick:a,onDirToggle:r,expanded:l,onContextMenu:c,dragState:A,onDragStartEntry:f,onDragEndEntry:x,onSetDragOver:h,onDropOnDir:g,gitStatusMap:O}){const b=t.type==="dir",v=n===t.path,y=l.has(t.path),S=s*16+8,j=(A==null?void 0:A.draggingPath)===t.path,N=b&&(A==null?void 0:A.dragOverPath)===t.path,C=b?null:O==null?void 0:O[t.path];function U(P){P.preventDefault(),P.stopPropagation(),c(P,t)}return e.jsxs("button",{draggable:!0,onDragStart:P=>{P.dataTransfer.setData("application/json",JSON.stringify({path:t.path,name:t.name,type:t.type})),P.dataTransfer.effectAllowed="move",f(t.path)},onDragEnd:x,onDragOver:P=>{P.preventDefault(),b&&(P.stopPropagation(),h(t.path))},onDrop:P=>g(b?t.path:t.path.includes("/")?t.path.split("/").slice(0,-1).join("/"):"",P),onClick:()=>b?r(t.path):a(t.path),onDoubleClick:U,onContextMenu:U,className:Z("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",j&&"opacity-50",N&&"bg-accent/15 ring-1 ring-accent/50 rounded"),style:{paddingLeft:S},children:[b?e.jsxs(e.Fragment,{children:[y?e.jsx(xt,{size:12,className:"text-text-4 flex-shrink-0"}):e.jsx(Tt,{size:12,className:"text-text-4 flex-shrink-0"}),y?e.jsx(Ys,{size:14,className:"text-accent flex-shrink-0"}):e.jsx(Li,{size:14,className:"text-text-3 flex-shrink-0"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-3"}),e.jsx(Lo,{size:14,className:Z("flex-shrink-0",Gee(t.name))})]}),e.jsx("span",{className:"truncate flex-1",children:t.name}),C&&e.jsx(Vee,{status:C})]})}function P4({dirPath:t,depth:s,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:x,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y}){const S=c[t]||[];return p.useEffect(()=>{r.has(t)&&!c[t]&&A(t)},[r,t,c,A]),r.has(t)?e.jsxs(e.Fragment,{children:[(x==null?void 0:x.parentPath)===t&&e.jsx(Tx,{placeholder:x.type==="file"?"filename.ext":"folder-name",onSubmit:x.onSubmit,onCancel:x.onCancel,depth:s}),S.map(j=>e.jsxs("div",{children:[(x==null?void 0:x.renamePath)===j.path?e.jsx(Tx,{defaultValue:j.name,onSubmit:x.onSubmit,onCancel:x.onCancel,depth:s}):e.jsx(E4,{entry:j,depth:s,activePath:n,onFileClick:a,onDirToggle:l,expanded:r,onContextMenu:f,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y}),j.type==="dir"&&e.jsx(P4,{dirPath:j.path,depth:s+1,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:x,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y})]},j.path))]}):null}function qee({rootDir:t,onCollapse:s}){const n=k(L=>L.editorTreeCache),a=k(L=>L.editorActiveFile),r=k(L=>L.openFile),l=k(L=>L.fetchTreeDir),c=k(L=>L.addToast),[A,f]=p.useState(new Set([""])),[x,h]=p.useState(""),[g,O]=p.useState(null),[b,v]=p.useState(null),[y,S]=p.useState({draggingPath:null,dragOverPath:null}),[j,N]=p.useState([]);p.useEffect(()=>{l("")},[l,t]),p.useEffect(()=>{G.get("/files/git-status").then(L=>{N(L.entries||[])}).catch(()=>N([]))},[t]);const C={};for(const L of j)C[L.path]=L.status;function U(L){f(J=>{const D=new Set(J);return D.has(L)?D.delete(L):D.add(L),D})}function P(){f(new Set([""]))}function T(L){S({draggingPath:L,dragOverPath:null})}function B(){S({draggingPath:null,dragOverPath:null})}function F(L){S(J=>J.dragOverPath===L?J:{...J,dragOverPath:L})}async function M(L,J){var V,te;if(J.preventDefault(),J.stopPropagation(),S({draggingPath:null,dragOverPath:null}),((te=(V=J.dataTransfer)==null?void 0:V.files)==null?void 0:te.length)>0){q(L,Array.from(J.dataTransfer.files));return}let D;try{D=JSON.parse(J.dataTransfer.getData("application/json"))}catch{return}if(!(D!=null&&D.path))return;if(D.type==="dir"&&(L===D.path||L.startsWith(D.path+"/"))){c("error","Cannot move a folder into itself");return}const se=W(D.path);if(se===L)return;const le=L?`${L}/${D.name}`:D.name;try{await G.post("/files/rename",{oldPath:D.path,newPath:le}),l(se),l(L),c("success",`Moved ${D.name} to ${L||"/"}`)}catch(ae){c("error","Move failed",ae.message)}}function R(L,J){O({x:L.clientX,y:L.clientY,entry:J})}function Y(L){L.preventDefault(),O({x:L.clientX,y:L.clientY,entry:{type:"dir",path:"",name:"root"}})}function W(L){const J=L.split("/");return J.pop(),J.join("/")}async function ee(L){f(J=>new Set([...J,L])),v({type:"file",parentPath:L,onSubmit:async J=>{const D=L?`${L}/${J}`:J;try{await G.post("/files/create",{path:D,content:""}),l(L),r(D),c("success",`Created ${J}`)}catch(se){c("error","Create failed",se.message)}v(null)},onCancel:()=>v(null)})}async function K(L){f(J=>new Set([...J,L])),v({type:"folder",parentPath:L,onSubmit:async J=>{const D=L?`${L}/${J}`:J;try{await G.post("/files/mkdir",{path:D}),l(L),f(se=>new Set([...se,D])),c("success",`Created ${J}/`)}catch(se){c("error","Create folder failed",se.message)}v(null)},onCancel:()=>v(null)})}async function _(L){v({type:"rename",renamePath:L.path,onSubmit:async J=>{const D=W(L.path),se=D?`${D}/${J}`:J;try{await G.post("/files/rename",{oldPath:L.path,newPath:se}),l(D),c("success",`Renamed to ${J}`)}catch(le){c("error","Rename failed",le.message)}v(null)},onCancel:()=>v(null)})}async function E(L){const J=L.type==="dir"?`folder "${L.name}" and all contents`:`"${L.name}"`;if(window.confirm(`Delete ${J}?`))try{await G.delete(`/files/delete?path=${encodeURIComponent(L.path)}`),l(W(L.path)),c("success",`Deleted ${L.name}`)}catch(D){c("error","Delete failed",D.message)}}async function q(L,J){const D=[];for(const se of J){const le=await new Promise((V,te)=>{const ae=new FileReader;ae.onload=()=>V(ae.result.split(",")[1]),ae.onerror=te,ae.readAsDataURL(se)});D.push({name:se.name,content:le})}try{const se=await G.post("/files/upload",{dir:L,files:D});c("success",`Uploaded ${se.total} file${se.total!==1?"s":""}`),l(L)}catch(se){c("error","Upload failed",se.message)}}function H(L){const J=L.type==="dir",D=[];return J&&(D.push({icon:Vl,label:"New File",action:()=>ee(L.path)}),D.push({icon:RA,label:"New Folder",action:()=>K(L.path)})),L.name!=="root"?(D.push({icon:qs,label:J?"Download as ZIP":"Download",action:()=>Kee(L.path,J)}),D.length>0&&D.push({separator:!0}),D.push({icon:Ua,label:"Rename",action:()=>_(L)}),D.push({icon:Ft,label:"Delete",danger:!0,action:()=>E(L)})):(D.length=0,D.push({icon:Vl,label:"New File",action:()=>ee("")}),D.push({icon:RA,label:"New Folder",action:()=>K("")})),D}const I=n[""]||[];return e.jsxs("div",{className:"flex flex-col h-full bg-surface-1",onContextMenu:Y,children:[e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border-subtle",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(As,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:x,onChange:L=>h(L.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"})]}),e.jsx("button",{onClick:()=>ee(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New file",children:e.jsx(Vl,{size:12})}),e.jsx("button",{onClick:()=>K(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New folder",children:e.jsx(RA,{size:12})}),e.jsx("button",{onClick:()=>l(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Refresh",children:e.jsx(Ls,{size:12})}),e.jsx("button",{onClick:P,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse all",children:e.jsx(wS,{size:12})}),s&&e.jsx("button",{onClick:s,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse sidebar",children:e.jsx(Vx,{size:12})})]}),e.jsx(Qt,{className:"flex-1",children:e.jsxs("div",{className:"py-1 min-h-full",onDragOver:L=>{L.preventDefault(),y.draggingPath&&F(null)},onDrop:L=>M("",L),children:[(b==null?void 0:b.parentPath)===""&&e.jsx(Tx,{placeholder:b.type==="file"?"filename.ext":"folder-name",onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}),I.filter(L=>!x||L.name.toLowerCase().includes(x.toLowerCase())).map(L=>e.jsxs("div",{children:[(b==null?void 0:b.renamePath)===L.path?e.jsx(Tx,{defaultValue:L.name,onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}):e.jsx(E4,{entry:L,depth:0,activePath:a,onFileClick:r,onDirToggle:U,expanded:A,onContextMenu:R,dragState:y,onDragStartEntry:T,onDragEndEntry:B,onSetDragOver:F,onDropOnDir:M,gitStatusMap:C}),L.type==="dir"&&e.jsx(P4,{dirPath:L.path,depth:1,activePath:a,onFileClick:r,expanded:A,onDirToggle:U,treeCache:n,fetchTreeDir:l,onContextMenu:R,inlineInput:b,dragState:y,onDragStartEntry:T,onDragEndEntry:B,onSetDragOver:F,onDropOnDir:M,gitStatusMap:C})]},L.path)),I.length===0&&!x&&e.jsxs("div",{className:"px-3 py-6 text-center",children:[e.jsx("p",{className:"text-xs text-text-4",children:"No files found"}),e.jsx("button",{onClick:()=>l(""),className:"mt-2 text-xs text-accent hover:underline cursor-pointer",children:"Retry"})]})]})}),g&&e.jsx(Zee,{x:g.x,y:g.y,items:H(g.entry),onClose:()=>O(null)})]})}function Wee(){const t=k(y=>y.editorOpenTabs),s=k(y=>y.editorActiveFile),n=k(y=>y.editorFiles),a=k(y=>y.setActiveFile),r=k(y=>y.closeFile),l=p.useRef(null),[c,A]=p.useState(!1),f=p.useCallback(()=>{const y=l.current;y&&A(y.scrollWidth>y.clientWidth)},[]);p.useEffect(()=>{f();const y=l.current;if(!y)return;const S=new ResizeObserver(f);return S.observe(y),()=>S.disconnect()},[f,t.length]);function x(){var y;(y=l.current)==null||y.scrollBy({left:-120,behavior:"smooth"})}function h(){var y;(y=l.current)==null||y.scrollBy({left:120,behavior:"smooth"})}function g(y){t.filter(S=>S!==y).forEach(S=>r(S))}function O(){[...t].forEach(y=>r(y))}function b(y){const S=t.indexOf(y);t.slice(S+1).forEach(j=>r(j))}function v(y){var S;(S=navigator.clipboard)==null||S.writeText(y)}return t.length===0?null:e.jsxs("div",{className:"flex items-stretch h-9 bg-surface-3 border-b border-border-subtle flex-shrink-0",children:[c&&e.jsx("button",{onClick:x,className:"flex-shrink-0 px-1 h-full text-text-4 hover:text-text-1 hover:bg-surface-4 transition-colors cursor-pointer",children:e.jsx(Di,{size:14})}),e.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:t.map(y=>{const S=y===s,j=n[y],N=j&&j.content!==j.originalContent,C=y.split("/").pop();return e.jsxs(Uv,{children:[e.jsx(Ev,{asChild:!0,children:e.jsxs("div",{className:Z("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",S?"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(y),onAuxClick:U=>{U.button===1&&(U.preventDefault(),r(y))},children:[e.jsx("span",{className:"truncate max-w-[120px]",children:C}),N&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-warning flex-shrink-0"}),e.jsx("button",{onClick:U=>{U.stopPropagation(),r(y)},className:"p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 transition-colors cursor-pointer ml-0.5",children:e.jsx(qe,{size:12})})]})}),e.jsxs(Pv,{children:[e.jsxs(ya,{onSelect:()=>r(y),children:[e.jsx(qe,{size:12,className:"text-text-3"})," Close"]}),e.jsxs(ya,{onSelect:()=>g(y),children:[e.jsx(AO,{size:12,className:"text-text-3"})," Close Others"]}),e.jsxs(ya,{onSelect:()=>O(),children:[e.jsx(AO,{size:12,className:"text-text-3"})," Close All"]}),e.jsxs(ya,{onSelect:()=>b(y),children:[e.jsx(Tt,{size:12,className:"text-text-3"})," Close to the Right"]}),e.jsx(Fv,{}),e.jsxs(ya,{onSelect:()=>v(y),children:[e.jsx(Ba,{size:12,className:"text-text-3"})," Copy Path"]})]})]},y)})}),c&&e.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:e.jsx(Tt,{size:14})})]})}const Yee={javascript:"JavaScript",typescript:"TypeScript",css:"CSS",html:"HTML",json:"JSON",markdown:"Markdown",python:"Python"},F4=Object.keys(Po),$4=F4.filter(t=>!["githubLight","vscodeLight","eclipse","xcodeLight","solarizedLight","gruvboxLight","materialLight","duotoneLight","quietlight","bbedit","tokyoNightDay","basicLight"].includes(t)),Jee=F4.filter(t=>!$4.includes(t));function ete({cursorPos:t,language:s}){var A;const n=k(f=>f.editorTheme),a=k(f=>f.setEditorTheme),[r,l]=p.useState(!1),c=p.useRef(null);return p.useEffect(()=>{if(!r)return;function f(x){c.current&&!c.current.contains(x.target)&&l(!1)}return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[r]),e.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:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("span",{children:["Ln ",t.line,", Col ",t.col]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",ref:c,children:[e.jsxs("button",{onClick:()=>l(!r),className:"flex items-center gap-1.5 hover:text-text-0 transition-colors cursor-pointer",children:[e.jsx(YM,{size:10}),e.jsx("span",{children:((A=Po[n])==null?void 0:A.label)||n})]}),r&&e.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:[e.jsx("div",{className:"px-2 py-1 text-2xs text-text-4 font-semibold uppercase tracking-wider",children:"Dark"}),$4.map(f=>e.jsx("button",{onClick:()=>{a(f),l(!1)},className:Z("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:Po[f].label},f)),e.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=>e.jsx("button",{onClick:()=>{a(f),l(!1)},className:Z("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:Po[f].label},f))]})]}),e.jsx("span",{className:"cursor-default",children:Yee[s]||s||"Plain Text"}),e.jsx("span",{children:"Spaces: 2"}),e.jsx("span",{children:"UTF-8"})]})]})}function tte({currentLine:t,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 e.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:[e.jsx("label",{className:"text-2xs font-sans text-text-3 whitespace-nowrap",children:"Go to Line:"}),e.jsx("input",{ref:l,value:a,onChange:A=>r(A.target.value),onKeyDown:c,onBlur:n,placeholder:String(t),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 ste({path:t}){if(!t)return null;const s=t.split("/").filter(Boolean);return e.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 e.jsxs("span",{className:"flex items-center min-w-0",children:[a>0&&e.jsx(Tt,{size:10,className:"mx-0.5 flex-shrink-0 text-text-4"}),e.jsx("span",{className:r?"text-text-1 font-medium truncate":"hover:text-text-1 cursor-pointer truncate transition-colors",children:n})]},a)})})}function nte(t){var n;const s=(n=t==null?void 0:t.split(".").pop())==null?void 0:n.toLowerCase();return s==="html"||s==="htm"}const ate=240,rte=160,ote=400;function ite(){const t=k(J=>J.editorActiveFile),s=k(J=>J.editorFiles),n=k(J=>J.updateFileContent),a=k(J=>J.saveFile),r=k(J=>J.editorSidebarWidth),l=k(J=>J.setEditorSidebarWidth),c=k(J=>J.projectDir),[A,f]=p.useState(""),[x,h]=p.useState(!1),[g,O]=p.useState(0),[b,v]=p.useState({line:1,col:1}),[y,S]=p.useState(!1),[j,N]=p.useState(!1),[C,U]=p.useState(!1),P=p.useRef(0),T=k(J=>J.addToast),B=k(J=>J.fetchTreeDir),F=p.useRef(null),M=p.useRef(!1),R=p.useRef(0),Y=p.useRef(0);p.useEffect(()=>{G.get("/files/root").then(J=>f(J.root||"")).catch(()=>{})},[c]),p.useEffect(()=>{h(!1)},[t]),p.useEffect(()=>{function J(D){(D.metaKey||D.ctrlKey)&&D.key==="g"&&(D.preventDefault(),S(!0))}return document.addEventListener("keydown",J),()=>document.removeEventListener("keydown",J)},[]);function W(J){var D,se;J.preventDefault(),P.current++,(se=(D=J.dataTransfer)==null?void 0:D.types)!=null&&se.includes("Files")&&U(!0)}function ee(J){J.preventDefault(),P.current--,P.current<=0&&(P.current=0,U(!1))}function K(J){J.preventDefault(),J.dataTransfer.dropEffect="copy"}async function _(J){var le;J.preventDefault(),P.current=0,U(!1);const D=(le=J.dataTransfer)==null?void 0:le.files;if(!(D!=null&&D.length))return;const se=[];for(const V of Array.from(D)){const te=await new Promise((ae,be)=>{const z=new FileReader;z.onload=()=>ae(z.result.split(",")[1]),z.onerror=be,z.readAsDataURL(V)});se.push({name:V.name,content:te})}try{const V=await G.post("/files/upload",{dir:"",files:se});T("success",`Uploaded ${V.total} file${V.total!==1?"s":""}`),B("")}catch(V){T("error","Upload failed",V.message)}}const E=p.useCallback(J=>{J.preventDefault(),M.current=!0,R.current=J.clientX,Y.current=r;function D(le){if(!M.current)return;const V=le.clientX-R.current,te=Math.min(Math.max(Y.current+V,rte),ote);l(te)}function se(){M.current=!1,document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",se)}document.addEventListener("mousemove",D),document.addEventListener("mouseup",se)},[r,l]);function q(J){const D=F.current;if(!D)return;const se=D.state.doc.line(Math.min(J,D.state.doc.lines));D.dispatch({selection:{anchor:se.from},scrollIntoView:!0}),D.focus()}const H=t?s[t]:null,I=t&&g5(t),L=t&&nte(t);return e.jsxs("div",{className:"flex h-full",children:[e.jsxs("div",{className:Z("relative flex-shrink-0 border-r border-border transition-all duration-200 overflow-hidden",j&&"w-0 border-r-0"),style:j?void 0:{width:r},children:[e.jsx(qee,{rootDir:A,onCollapse:()=>N(!0)}),e.jsx("div",{className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:E,onDoubleClick:()=>l(ate)})]}),j&&e.jsx("button",{onClick:()=>N(!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:e.jsx(Kx,{size:14})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-surface-1 relative",onDragEnter:W,onDragLeave:ee,onDragOver:K,onDrop:_,children:[C&&e.jsx("div",{className:"absolute inset-0 z-50 bg-accent/8 border-2 border-dashed border-accent/40 rounded-lg flex items-center justify-center pointer-events-none",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 text-accent",children:[e.jsx(Hb,{size:32}),e.jsx("span",{className:"text-sm font-semibold font-sans",children:"Drop files to upload"})]})}),e.jsx(Wee,{}),t&&!I&&e.jsx(ste,{path:t}),e.jsxs("div",{className:"flex-1 relative min-h-0",children:[y&&e.jsx(tte,{currentLine:b.line,onGoto:q,onClose:()=>S(!1)}),!t&&e.jsx("div",{className:"w-full h-full flex items-center justify-center text-text-4 font-sans",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(bn,{size:32,className:"mx-auto"}),e.jsx("p",{className:"text-sm",children:"Open a file from the tree"})]})}),t&&I&&e.jsx(O5,{path:t}),t&&!I&&L&&e.jsxs(e.Fragment,{children:[e.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:[e.jsxs("button",{onClick:()=>h(!1),className:Z("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",x?"text-text-3 hover:text-text-1":"bg-surface-4 text-text-0 font-medium"),children:[e.jsx(Fb,{size:12})," Code"]}),e.jsxs("button",{onClick:()=>{h(!0),O(J=>J+1)},className:Z("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",x?"bg-surface-4 text-text-0 font-medium":"text-text-3 hover:text-text-1"),children:[e.jsx(Vs,{size:12})," Preview"]})]}),x?e.jsx("iframe",{src:`/api/files/raw?path=${encodeURIComponent(t)}`,className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin",title:"HTML Preview"},g):H&&e.jsx(KO,{content:H.content,language:H.language,onChange:J=>n(t,J),onSave:()=>a(t),onCursorChange:v,viewRef:F})]}),t&&!I&&!L&&H&&e.jsx(KO,{content:H.content,language:H.language,onChange:J=>n(t,J),onSave:()=>a(t),onCursorChange:v,viewRef:F})]}),t&&!I&&e.jsx(ete,{cursorPos:b,language:H==null?void 0:H.language})]})]})}function lte(){var C;const t=k(U=>U.connected),s=k(U=>U.agents),[n,a]=p.useState(null),[r,l]=p.useState([]),[c,A]=p.useState({constraints:[],discoveries:[],roles:[],specializations:null}),[f,x]=p.useState(!0),[h,g]=p.useState({tokens:[],cost:[],saved:[],efficiency:[],cache:[],inputOutput:[],agents:[],turns:[]}),O=p.useRef(0);p.useEffect(()=>{if(!t)return;let U=!0;async function P(){try{const[B,F,M,R,Y,W]=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(!U)return;a(B),l((F==null?void 0:F.teams)||[]),A({constraints:(M==null?void 0:M.constraints)||[],discoveries:(R==null?void 0:R.discoveries)||[],roles:(Y==null?void 0:Y.roles)||[],specializations:W||{perAgent:{},perProjectRole:{}}}),x(!1),O.current=Date.now(),g(ee=>{var D,se,le,V,te,ae,be,z,oe;const K=Date.now(),_=(ue,ve)=>[...ue.slice(-59),{t:K,v:ve||0}],E=((D=B.tokens)==null?void 0:D.totalTokens)||0,q=((se=B.tokens)==null?void 0:se.totalInputTokens)||0,H=((le=B.tokens)==null?void 0:le.totalOutputTokens)||0,L=(((V=B.agents)==null?void 0:V.breakdown)||[]).filter(ue=>{var ve;return((ve=ue.quality)==null?void 0:ve.score)!=null}),J=L.length>0?L.reduce((ue,ve)=>ue+ve.quality.score,0)/L.length:0;return{tokens:_(ee.tokens,E),cost:_(ee.cost,(te=B.tokens)==null?void 0:te.totalCostUsd),saved:_(ee.saved,J),efficiency:_(ee.efficiency,((ae=B.rotation)==null?void 0:ae.totalRotations)||0),cache:_(ee.cache,(be=B.tokens)==null?void 0:be.cacheHitRate),inputOutput:_(ee.inputOutput,H>0?q/H:0),agents:_(ee.agents,((z=B.agents)==null?void 0:z.running)||0),turns:_(ee.turns,(oe=B.tokens)==null?void 0:oe.totalTurns)}})}catch{U&&x(!1)}}P();const T=setInterval(P,4e3);return()=>{U=!1,clearInterval(T)}},[t]);const b=((C=n==null?void 0:n.agents)==null?void 0:C.breakdown)||[],v=(n==null?void 0:n.routing)||null,y=(n==null?void 0:n.rotation)||null,S=(n==null?void 0:n.adaptive)||[],j=(n==null?void 0:n.journalist)||null,N=(y==null?void 0:y.rotating)||[];return{data:n,loading:f,agents:s,connected:t,kpiHistory:h,lastFetch:O.current,agentBreakdown:b,routing:v,rotation:y,adaptive:S,journalist:j,rotating:N,teamBurn:r,memory:c}}const CQ=p.memo(function({connected:s,runningCount:n,totalCount:a,uptime:r,lastFetch:l,activeTeam:c}){return e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 bg-surface-1 border-b border-border",children:[e.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Command Center"}),c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-xs font-mono text-text-2",children:c.name})]}),e.jsx("div",{className:"flex-1"}),s&&e.jsxs("div",{className:"flex items-center gap-3.5 text-xs font-mono text-text-2",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-text-1",children:n}),e.jsxs("span",{className:"text-text-3",children:["/",a]}),e.jsx("span",{className:"ml-1 text-text-3",children:"agents"})]}),r>0&&e.jsxs("span",{className:"text-text-3",children:["Up ",Xo(r)]}),l>0&&e.jsxs("span",{className:"flex items-center gap-1 text-text-4",children:[e.jsx(Ls,{size:9}),e.jsx("span",{children:$t(l)})]})]}),e.jsx(Gt,{status:s?"running":"crashed",size:"sm"})]})});function nt(t,s){const n=parseInt(t.slice(1,3),16),a=parseInt(t.slice(3,5),16),r=parseInt(t.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 cte({data:t,color:s=ce.text3,width:n=72,height:a=22}){if(!t||t.length<2)return e.jsx("div",{style:{width:n,height:a}});const r=t.map(h=>h.v),l=Math.min(...r),A=Math.max(...r)-l||1,f=t.map((h,g)=>{const O=g/(t.length-1)*n,b=a-(h.v-l)/A*(a-2)-1;return`${O},${b}`}).join(" "),x=`kpi-${s.replace("#","")}`;return e.jsxs("svg",{width:n,height:a,className:"flex-shrink-0",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:x,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:s,stopOpacity:"0.2"}),e.jsx("stop",{offset:"100%",stopColor:s,stopOpacity:"0"})]})}),e.jsx("polygon",{points:`0,${a} ${f} ${n},${a}`,fill:`url(#${x})`}),e.jsx("polyline",{points:f,fill:"none",stroke:s,strokeWidth:"1.5",strokeLinejoin:"round",strokeOpacity:"0.8"})]})}const Ate=p.memo(function({label:s,value:n,sparkData:a,color:r=ce.text3,hint:l,className:c}){return e.jsxs("div",{className:Z("flex items-center gap-2.5 px-3 py-2.5 min-w-0","bg-surface-1",c),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.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&&e.jsx(dt,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:l}),side:"bottom",children:e.jsx(ki,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors"})})]}),e.jsx("div",{className:"text-base font-semibold font-mono text-text-0 tabular-nums leading-none",children:n})]}),e.jsx(cte,{data:a,color:r})]})});function dte({kpis:t}){return e.jsx("div",{className:"flex flex-wrap border-b border-border bg-surface-0",children:t.map(s=>e.jsx(Ate,{label:s.label,value:s.value,sparkData:s.sparkData,color:s.color,hint:s.hint,className:Z("flex-1 basis-[12.5%] min-w-[140px]","border-b border-r border-border")},s.label))})}const ute={actual:"ACT",estimated:"EST",local:"LOC"};function fte(t){if(!t||t==="auto"||t==="default")return"default";const s=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gem ").replace("-preview",""):t.length>12?t.slice(0,12)+"...":t}const xte=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:Gb(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,x=Ha(s.role),h=ce.text1;return e.jsxs("div",{className:"px-3 pl-6 py-2 hover:bg-surface-4 transition-colors space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:l}}),a&&e.jsx("span",{className:"absolute inset-[-2px] rounded-sm",style:{background:l,opacity:.15,animation:"node-pulse-bar 2s ease-in-out infinite"}})]}),e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate leading-none flex-shrink-0 max-w-[80px]",children:s.name}),e.jsx("span",{className:"text-2xs font-mono font-semibold px-1.5 py-px rounded-sm flex-shrink-0 capitalize",style:{background:x.bg,color:x.text},children:(s.role||"").toLowerCase()}),e.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:fte(s.model)}),e.jsx("div",{className:"flex-1"}),A!=null&&e.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"&&e.jsx("span",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex-shrink-0",children:ute[s.costSource]||""}),e.jsxs("div",{className:"text-right flex-shrink-0",children:[e.jsx("div",{className:"text-xs font-mono text-text-1 tabular-nums leading-none",children:jt(s.tokens||0)}),(s.costUsd||0)>0&&e.jsx("div",{className:"text-2xs font-mono text-text-3 mt-0.5",children:er(s.costUsd)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 h-0.5 rounded-sm overflow-visible",style:{background:nt(ce.text4,.2)},children:[e.jsx("div",{className:"absolute inset-y-0 left-0 rounded-sm transition-all duration-700",style:{width:`${Math.max(r,1)}%`,background:h}}),f&&e.jsx("div",{className:"absolute top-[-1px] w-px h-[4px]",style:{left:`${f}%`,background:ce.text3},title:`Rotation at ${f}%`})]}),e.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums flex-shrink-0 w-7 text-right",children:[r,"%"]})]})]})});function mte({team:t,members:s,rotatingSet:n}){const[a,r]=p.useState(!0),l=s.filter(x=>x.status==="running"||x.status==="starting").length,c=l>0,A=s.reduce((x,h)=>x+(h.tokens||0),0),f=s.reduce((x,h)=>x+(h.costUsd||0),0);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>r(x=>!x),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?e.jsx(xt,{size:10,className:"text-text-4 flex-shrink-0"}):e.jsx(Tt,{size:10,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-mono font-semibold text-text-2 uppercase tracking-widest flex-1 truncate",children:t}),e.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:jt(A)}),f>0&&e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums ml-1",children:er(f)}),e.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(x=>e.jsx(xte,{agent:x,isRotating:n.has(x.id)},x.id))]})}const hte=p.memo(function({agentBreakdown:s,rotating:n=[],teams:a=[]}){if(!(s!=null&&s.length))return e.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 e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"py-1",children:Object.entries(l).map(([A,f])=>e.jsx(mte,{team:r[A]||(A==="ungrouped"?"Ungrouped":A),members:f,rotatingSet:c},A))})})}),Is=36,nb=3,Wf=(Is-nb)/2,Qf=2*Math.PI*Wf,BQ=-90;function pte(){return ce.text1}function gte({name:t,pct:s,threshold:n}){const a=pte(),r=s/100*Qf;return e.jsxs("div",{className:"flex flex-col items-center gap-0.5",title:`${t}: ${s}% context used`,children:[e.jsxs("svg",{width:Is,height:Is,viewBox:`0 0 ${Is} ${Is}`,children:[e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:nb,className:"stroke-surface-4"}),e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:nb,strokeLinecap:"round",style:{stroke:a,strokeDasharray:`${r} ${Qf-r}`,strokeDashoffset:0,transition:"stroke-dasharray 0.5s ease"},transform:`rotate(${BQ} ${Is/2} ${Is/2})`}),n&&e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:1,strokeLinecap:"butt",style:{stroke:ce.text3,strokeDasharray:`1 ${Qf-1}`,strokeDashoffset:-(n/100)*Qf},transform:`rotate(${BQ} ${Is/2} ${Is/2})`}),e.jsx("text",{x:Is/2,y:Is/2+1,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-1 font-mono font-semibold",style:{fontSize:9},children:s})]}),e.jsx("span",{className:"text-2xs font-mono text-text-3 truncate max-w-[40px] leading-none",children:t})]})}function Ote({zones:t}){return e.jsxs("div",{className:"flex items-center gap-2 text-2xs font-mono",children:[e.jsx("span",{className:"text-text-2",children:t.healthy}),e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-text-2",children:t.warning}),e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-text-2",children:t.critical})]})}const bte=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 e.jsxs("div",{className:"px-3 py-2 flex-shrink-0 border-b border-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Context Health"}),e.jsx(Ote,{zones:a})]}),e.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 e.jsx(gte,{name:r.name,pct:l,threshold:c},r.id)})})]})}),vte=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:x}=r,h={top:28,right:12,bottom:8,left:12},g=Math.max(f-h.left-h.right,0),O=Math.max(x-h.top-h.bottom,0),b=p.useMemo(()=>!s||s.length<2?[]:s.slice(1).map((S,j)=>{const N=s[j],C=(S.t-N.t)/6e4,U=Math.max((S.tokens||0)-(N.tokens||0),0);return{burnRate:C>0?Math.round(U/C):0,cacheHitRate:S.cacheHitRate||0,running:S.running||0,agents:S.agents||0,t:S.t}}),[s]);p.useEffect(()=>{const S=n.current;if(!S)return;const j=new ResizeObserver(N=>{const{width:C,height:U}=N[0].contentRect;C>0&&U>0&&l({width:Math.floor(C),height:Math.floor(U)})});return j.observe(S),()=>j.disconnect()},[]);const v=p.useCallback(S=>{const j=a.current;if(!j||!b.length||g<=0)return;const N=j.getBoundingClientRect(),C=S.clientX-N.left-h.left;if(C<0||C>g){A(null);return}const U=Math.round(C/g*(b.length-1));A({x:h.left+U/Math.max(b.length-1,1)*g,index:U})},[b,g,h.left]),y=p.useCallback(()=>A(null),[]);return p.useEffect(()=>{const S=a.current;if(!S||!b.length||f<=0||x<=0||g<=0||O<=0)return;const j=S.getContext("2d"),N=window.devicePixelRatio||1;S.width=f*N,S.height=x*N,j.scale(N,N),j.clearRect(0,0,f,x);const C=b.map(E=>E.burnRate),U=b.map(E=>E.cacheHitRate),P=b.map(E=>E.running),T=Math.max(...C,100),B=Math.max(...P,1),F=E=>h.left+E/Math.max(b.length-1,1)*g,M=E=>h.top+O-E/T*O,R=E=>h.top+O-E*O,Y=Math.max(g/b.length-1,2);for(let E=0;E<b.length;E++){const q=P[E];if(q<=0)continue;const H=q/B*O*.3,I=F(E)-Y/2,L=h.top+O-H;j.fillStyle=nt(ce.surface5,.5),j.fillRect(I,L,Y,H)}j.setLineDash([2,4]),j.strokeStyle=nt(ce.text4,.2),j.lineWidth=1;for(let E=1;E<=3;E++){const q=h.top+O/4*E;j.beginPath(),j.moveTo(h.left,q),j.lineTo(h.left+g,q),j.stroke()}j.setLineDash([]),j.font="9px 'SF Mono', ui-monospace, Menlo, Consolas, monospace",j.textAlign="left",j.fillStyle=nt(ce.text3,.5),j.fillText(`${jt(T)}/m`,h.left+4,h.top+10),j.fillText(`${jt(Math.round(T/2))}/m`,h.left+4,h.top+O/2+4),j.beginPath(),j.moveTo(h.left,h.top+O);for(let E=0;E<b.length;E++)j.lineTo(F(E),M(C[E]));j.lineTo(F(b.length-1),h.top+O),j.closePath();const W=j.createLinearGradient(0,h.top,0,h.top+O);W.addColorStop(0,nt(ce.accent,.2)),W.addColorStop(.7,nt(ce.accent,.04)),W.addColorStop(1,nt(ce.accent,0)),j.fillStyle=W,j.fill(),j.beginPath(),j.strokeStyle=ce.accent,j.lineWidth=1.5,j.lineJoin="round";for(let E=0;E<b.length;E++){const q=F(E),H=M(C[E]);E===0?j.moveTo(q,H):j.lineTo(q,H)}j.stroke();const ee=U.some(E=>E>0);if(ee){j.beginPath(),j.strokeStyle=nt(ce.text2,.5),j.lineWidth=1,j.lineJoin="round",j.setLineDash([2,3]);for(let E=0;E<b.length;E++){const q=F(E),H=R(U[E]);E===0?j.moveTo(q,H):j.lineTo(q,H)}j.stroke(),j.setLineDash([])}j.font="9px 'Inter Variable', sans-serif",j.textAlign="right";let K=f-h.right-4;const _=14;if(ee&&(j.fillStyle=nt(ce.text2,.5),j.fillText("Cache %",K,_),K-=j.measureText("Cache %").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),K-=14),j.fillStyle=nt(ce.surface5,.7),j.fillText("Agents",K,_),K-=j.measureText("Agents").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),K-=14,j.fillStyle=ce.accent,j.fillText("Burn Rate",K,_),K-=j.measureText("Burn Rate").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),c&&c.index>=0&&c.index<b.length){const E=c.x,q=b[c.index];j.beginPath(),j.moveTo(E,h.top),j.lineTo(E,h.top+O),j.strokeStyle=nt(ce.text1,.15),j.lineWidth=1,j.stroke();const H=M(q.burnRate);j.beginPath(),j.arc(E,H,3,0,Math.PI*2),j.fillStyle=ce.accent,j.fill();const I=[{label:"Burn",value:`${jt(q.burnRate)}/m`,color:ce.accent},{label:"Cache",value:pc(q.cacheHitRate*100),color:ce.text2},{label:"Agents",value:`${q.running}/${q.agents}`,color:ce.text3}],L=104,J=I.length*16+12;let D=E+12;D+L>f-8&&(D=E-L-12);const se=Math.max(h.top,H-J/2);j.fillStyle=nt(ce.surface0,.92),j.beginPath(),j.roundRect(D,se,L,J,4),j.fill(),j.strokeStyle=nt(ce.text4,.2),j.lineWidth=1,j.stroke(),j.textAlign="left",I.forEach((le,V)=>{const te=se+14+V*16;j.beginPath(),j.arc(D+8,te-3,2,0,Math.PI*2),j.fillStyle=le.color,j.fill(),j.font="8px 'Inter Variable', sans-serif",j.fillStyle=ce.text3,j.fillText(le.label,D+14,te),j.font="9px 'SF Mono', ui-monospace, Menlo, Consolas, monospace",j.fillStyle=ce.text0,j.textAlign="right",j.fillText(le.value,D+L-8,te),j.textAlign="left"})}},[b,f,x,c,g,O,h]),e.jsx("div",{ref:n,className:"absolute inset-0",children:f>0&&x>0&&e.jsx("canvas",{ref:a,style:{width:f,height:x},className:"block cursor-crosshair",onMouseMove:v,onMouseLeave:y})})}),yte=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 x=l.current;if(!x)return;const h=window.devicePixelRatio||1;x.width=r*h,x.height=r*h;const g=x.getContext("2d");g.scale(h,h),g.clearRect(0,0,r,r);const O=r/2,b=r/2,v=(r-12)/2,y=5,S=135*Math.PI/180,j=405*Math.PI/180,N=j-S;if(g.beginPath(),g.arc(O,b,v,S,j),g.strokeStyle=ce.surface4,g.lineWidth=y,g.lineCap="round",g.stroke(),A>0){const C=s/A,U=n/A;if(C>0){const P=S+N*C;g.beginPath(),g.arc(O,b,v,S,P),g.strokeStyle=ce.text0,g.lineWidth=y,g.lineCap="round",g.stroke()}if(U>0){const P=S+N*C,T=P+N*U;g.beginPath(),g.arc(O,b,v,P,T),g.strokeStyle=ce.text3,g.lineWidth=y,g.lineCap="butt",g.stroke()}}g.textAlign="center",g.textBaseline="middle",g.font=`600 ${r*.2}px 'SF Mono', ui-monospace, Menlo, Consolas, monospace`,g.fillStyle=ce.text0,g.fillText(`${Math.round(f)}%`,O,b-3),g.font=`500 ${r*.08}px 'SF Mono', ui-monospace, Menlo, Consolas, monospace`,g.fillStyle=ce.text3,g.fillText("CACHE",O,b+r*.13)},[s,n,a,r,A,f]),e.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-3 py-3",children:[e.jsx("canvas",{ref:l,className:"flex-shrink-0",style:{width:r,height:r}}),e.jsxs("div",{className:"w-full mt-3 space-y-1.5 max-w-[160px]",children:[e.jsx(Lg,{color:ce.text0,label:"Read",value:jt(s)}),e.jsx(Lg,{color:ce.text3,label:"Create",value:jt(n)}),e.jsx(Lg,{color:ce.surface5,label:"Miss",value:jt(Math.max(a-s-n,0))})]})]})});function Lg({color:t,label:s,value:n}){return e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:t}}),e.jsx("span",{className:"text-text-3 uppercase tracking-wider flex-1",children:s}),e.jsx("span",{className:"text-text-1 tabular-nums",children:n})]})}const R4={heavy:ce.text0,medium:ce.text2,light:ce.text4},wte={heavy:"Heavy",medium:"Medium",light:"Light"},an=80,ab=6,rb=(an-ab)/2,kQ=2*Math.PI*rb;function jte({byTier:t,total:s,tiers:n}){let a=0;const r=[];for(const l of n){const c=t[l]||0;if(c===0)continue;const f=c/s*kQ;r.push({tier:l,dashLen:f,offset:a}),a+=f}return s>0&&Math.round((t.heavy||0)/s*100),e.jsxs("svg",{width:an,height:an,viewBox:`0 0 ${an} ${an}`,className:"flex-shrink-0",children:[e.jsx("circle",{cx:an/2,cy:an/2,r:rb,fill:"none",strokeWidth:ab,className:"stroke-surface-4"}),r.map(l=>e.jsx("circle",{cx:an/2,cy:an/2,r:rb,fill:"none",strokeWidth:ab,strokeLinecap:"butt",style:{stroke:R4[l.tier],strokeDasharray:`${l.dashLen} ${kQ-l.dashLen}`,strokeDashoffset:-l.offset},transform:`rotate(-90 ${an/2} ${an/2})`},l.tier)),e.jsx("text",{x:an/2,y:an/2-2,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-0 text-sm font-mono font-semibold",children:jt(s)}),e.jsx("text",{x:an/2,y:an/2+11,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-3 font-mono",style:{fontSize:7},children:"decisions"})]})}const Qte=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 x=Object.entries(f).sort((g,O)=>O[1].tokens-g[1].tokens),h=x.length>0?x[0][1].tokens:0;return e.jsxs("div",{className:"flex flex-col h-full px-3 py-3 overflow-y-auto",children:[A>0&&e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(jte,{byTier:a,total:A,tiers:c}),e.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 e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:R4[g]}}),e.jsx("span",{className:"text-2xs font-mono text-text-2 flex-1",children:wte[g]}),e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums",children:O}),e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums w-8 text-right",children:pc(b)})]},g)}),l>0&&e.jsxs("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:[l," auto-routed"]})]})]}),x.length>0&&e.jsxs("div",{className:"space-y-1.5 flex-1",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Models in Use"}),e.jsx("div",{className:"space-y-1.5",children:x.map(([g,O])=>{const b=h>0?O.tokens/h*100:0;return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 flex-1 truncate",children:Nte(g)}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[O.agents," agent",O.agents!==1?"s":""]}),e.jsx("span",{className:"text-xs font-mono text-text-1 tabular-nums",children:jt(O.tokens)})]}),e.jsx("div",{className:"h-0.5 bg-surface-4 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-500",style:{width:`${Math.max(b,2)}%`,background:ce.text2}})})]},g)})})]}),A===0&&x.length===0&&e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono",children:"No routing data"})]})});function Nte(t){if(!t||t==="auto"||t==="default")return"Default";const s=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gemini ").replace("-preview",""):t}function M4({text:t}){return e.jsx(dt,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:t}),side:"bottom",children:e.jsx(ki,{size:9,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors ml-0.5"})})}function Ste({children:t,tip:s}){return e.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex items-center gap-0.5",children:[t,s&&e.jsx(M4,{text:s})]})}function Nf({label:t,value:s,tip:n}){return e.jsxs("div",{children:[e.jsx(Ste,{tip:n,children:t}),e.jsx("div",{className:"text-sm font-mono font-semibold text-text-1 tabular-nums leading-snug",children:s})]})}function jd({title:t,children:s,tip:n}){return e.jsxs("div",{className:"px-3 py-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider mb-2 flex items-center gap-0.5",children:[t,n&&e.jsx(M4,{text:n})]}),s]})}function vc(){return e.jsx("div",{className:"h-px bg-border mx-3"})}function Cte({tokens:t,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 e.jsxs("div",{className:"px-3 py-3 flex items-start gap-5",children:[e.jsx(Nf,{label:"Quality",value:l??"—",tip:"Average session quality (0-100). Below 40 triggers auto-rotation."}),e.jsx(Nf,{label:"Cache",value:pc(((t==null?void 0:t.cacheHitRate)||0)*100),tip:"Prompt cache hit rate. Higher = faster + cheaper."}),e.jsx(Nf,{label:"Rotations",value:(s==null?void 0:s.totalRotations)||0,tip:"Total context rotations this session."}),((t==null?void 0:t.totalCostUsd)||0)>0&&e.jsx(Nf,{label:"Cost",value:er(t.totalCostUsd),tip:"Total cost reported by providers."})]})}function Bte({agentBreakdown:t,rotation:s}){const n=(s==null?void 0:s.liveScores)||{},a=(t||[]).filter(r=>r.status==="running");return a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Live agents",children:e.jsx("div",{className:"space-y-0",children:a.map(r=>{var x;const l=r.quality||{},c=((x=n[r.id])==null?void 0:x.score)??l.score,A=Ha(r.role),f=[l.errorCount>0&&`${l.errorCount} err`,l.repetitions>0&&`${l.repetitions} rep`,l.fileChurn>0&&`${l.fileChurn} churn`].filter(Boolean);return e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[e.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}),e.jsx("span",{className:"text-text-2 truncate flex-1",children:r.name}),f.length>0&&e.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:f.join(" · ")}),e.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0 w-6 text-right",children:c??"—"})]},r.id)})})})]})}function kte({rotation:t}){const s=((t==null?void 0:t.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":pc((a.contextUsage||0)*100)}return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Recent rotations",children:e.jsx("div",{className:"space-y-0",children:s.map((a,r)=>e.jsxs("div",{className:"flex items-center gap-2 py-0.5 text-xs font-mono",children:[e.jsx("span",{className:"text-text-2 truncate flex-1",children:a.agentName||a.role}),e.jsx("span",{className:"text-text-3 flex-shrink-0",children:n(a)}),e.jsx("span",{className:"text-text-4 flex-shrink-0 w-10 text-right",children:$t(a.timestamp)})]},r))})})]})}function Tte({adaptive:t}){if(!(t!=null&&t.length))return null;function s(n){const a=n.split(":");return{provider:a[0]||n,role:a[1]||""}}return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Adaptive thresholds",tip:"Per-role rotation thresholds. GROOVE learns when each role benefits from rotation and adjusts automatically.",children:e.jsx("div",{className:"space-y-0",children:t.map(n=>{const{provider:a,role:r}=s(n.key),l=r||a,c=Ha(l);return e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[e.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&&e.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:a}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0",children:pc(n.threshold*100)}),n.converged?e.jsx("span",{className:"text-2xs font-semibold flex-shrink-0",style:{color:ce.accent},children:"Converged"}):e.jsxs("span",{className:"text-2xs text-text-3 flex-shrink-0 flex items-center gap-1",children:[e.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 Ute({journalist:t}){return!t||!((t.cycleCount||0)>0)&&!t.synthesizing?null:e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs(jd,{title:"Journalist",children:[e.jsxs("div",{className:"flex items-center gap-3 text-xs font-mono",children:[e.jsxs("span",{className:"text-text-2",children:[t.cycleCount||0," cycles"]}),t.lastCycleAt&&e.jsx("span",{className:"text-text-4",children:$t(t.lastCycleAt)}),t.synthesizing&&e.jsx("span",{className:"font-semibold text-accent animate-pulse",children:"Synthesizing"})]}),t.lastSummary&&e.jsx("div",{className:"text-xs text-text-3 leading-relaxed mt-1.5 line-clamp-3",children:t.lastSummary})]})]})}function Ete({memory:t}){var f,x;const s=(t==null?void 0:t.constraints)||[],n=(t==null?void 0:t.discoveries)||[],a=(t==null?void 0:t.roles)||[],r=((f=t==null?void 0:t.specializations)==null?void 0:f.perProjectRole)||{},l=Object.keys(((x=t==null?void 0:t.specializations)==null?void 0:x.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 e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs(jd,{title:"Memory",tip:"Persistent knowledge across agent rotations. Constraints, error→fix discoveries, and handoff chains.",children:[e.jsx("div",{className:"text-xs font-mono text-text-3 mb-1.5",children:A.join(" · ")}),s.length>0&&e.jsxs("div",{className:"mt-2 space-y-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Constraints"}),s.slice(0,3).map(h=>e.jsx("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:h.text},h.hash)),s.length>3&&e.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",s.length-3," more"]})]}),n.length>0&&e.jsxs("div",{className:"mt-2 space-y-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Discoveries"}),n.slice(0,3).map((h,g)=>e.jsxs("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:[e.jsx("span",{className:"text-text-4",children:h.trigger})," → ",h.fix]},g)),n.length>3&&e.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",n.length-3," more"]})]}),Object.keys(r).length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Role quality"}),e.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-0.5",children:Object.entries(r).map(([h,g])=>e.jsxs("span",{className:"text-xs font-mono text-text-3",children:[e.jsx("span",{className:"text-text-2 capitalize",children:h})," Q:",g.avgQualityScore," ",e.jsxs("span",{className:"text-text-4",children:["(",g.sessionCount,"s)"]})]},h))})]})]})]})}function Pte({tokens:t}){var r,l;if(!((r=t==null?void 0:t.internalOverhead)!=null&&r.tokens)||!((l=t==null?void 0:t.savings)!=null&&l.total))return null;const s=t.internalOverhead,n=t.savings,a=t.totalTokens>0?Math.round(s.tokens/t.totalTokens*100):0;return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs("div",{className:"px-3 py-2.5 flex items-center gap-3 text-xs font-mono",children:[e.jsx("span",{className:"text-text-4",children:"Overhead"}),e.jsxs("span",{className:"text-text-3 tabular-nums",children:[jt(s.tokens)," (",a,"%)"]}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-text-4",children:"Saved"}),e.jsx("span",{className:"text-text-3 tabular-nums",children:jt(n.total)})]})]})}const Fte=p.memo(function({tokens:s,rotation:n,adaptive:a,journalist:r,agentBreakdown:l,memory:c}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-shrink-0 px-3 pt-2.5 pb-1.5",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Intel"})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[e.jsx(Cte,{tokens:s,rotation:n,agentBreakdown:l}),e.jsx(Bte,{agentBreakdown:l,rotation:n}),e.jsx(kte,{rotation:n}),e.jsx(Tte,{adaptive:a}),e.jsx(Ute,{journalist:r}),e.jsx(Ete,{memory:c}),e.jsx(Pte,{tokens:s}),e.jsx("div",{className:"h-3"})]})]})}),$te=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 e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0 flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Team Burn"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3",children:[jt(n)," total"]})]}),e.jsx(Qt,{className:"flex-1 min-h-0",children:s.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-text-3 font-mono",children:"No team activity yet"}):e.jsx("div",{className:"px-3 py-3 space-y-3",children:s.map(r=>{const l=a>0?r.totalTokens/a*100:0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:r.teamName}),r.isDefault&&e.jsx("span",{className:"text-[9px] font-mono text-text-3 uppercase tracking-wider",children:"default"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 flex-shrink-0",children:[r.agentCount," ",r.agentCount===1?"agent":"agents"]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 font-mono text-2xs",children:[e.jsx("span",{className:"text-text-1",children:jt(r.totalTokens)}),e.jsx("span",{className:"text-text-3",children:er(r.totalCostUsd)})]})]}),e.jsx("div",{className:"h-0.5 bg-surface-2 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all",style:{width:`${l}%`,background:ce.text3}})})]},r.teamId)})})})]})}),Rte={spawn:HS,complete:Ga,crash:Aa,kill:AO,rotate:hd,error:Db},Mte={spawn:"text-text-2",complete:"text-text-2",crash:"text-danger",kill:"text-text-3",rotate:"text-text-2",error:"text-danger"};function Ite(t){const s=t.agentName||t.role||"";switch(t.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 t.text||t.type||"event"}}const zte=p.memo(function({events:s=[]}){return s.length?e.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=Rte[n.type]||qt,l=Mte[n.type]||"text-text-3",c=Ite(n);return e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx(r,{size:11,className:l}),e.jsx("span",{className:"text-xs font-sans text-text-2 whitespace-nowrap",children:c}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:$t(n.t||n.timestamp)})]},a)})}):e.jsx("div",{className:"text-xs text-text-3 font-mono py-2.5 text-center",children:"No recent activity"})});function ia({className:t,...s}){return e.jsx("div",{className:Z("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]",t),...s})}function _te(){return e.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:[e.jsx("div",{className:"col-span-3",children:e.jsx(ia,{className:"h-[72px] rounded-none"})}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx("div",{className:"col-span-2",children:e.jsx(ia,{className:"h-full rounded-none"})})]})}function Dte(){const{data:t,loading:s,agents:n,connected:a,kpiHistory:r,lastFetch:l,agentBreakdown:c,routing:A,rotation:f,adaptive:x,journalist:h,rotating:g,teamBurn:O,memory:b}=lte(),v=k(R=>R.teams),y=n.filter(R=>R.status==="running").length;if(!a)return e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2 text-text-3 font-mono",children:[e.jsx(Lx,{size:28,className:"mx-auto"}),e.jsx("p",{className:"text-xs",children:"Connecting to daemon..."})]})});if(s||!t)return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(CQ,{connected:a,runningCount:0,totalCount:0,uptime:0,lastFetch:0}),e.jsx(_te,{})]});const S=t.tokens||{},j={totalTokens:S.totalTokens||0,totalCostUsd:S.totalCostUsd||0,totalInputTokens:S.totalInputTokens||0,totalOutputTokens:S.totalOutputTokens||0,cacheReadTokens:S.cacheReadTokens||0,cacheCreationTokens:S.cacheCreationTokens||0,cacheHitRate:S.cacheHitRate||0,totalTurns:S.totalTurns||0,agentCount:S.agentCount||0,savings:S.savings||{},internalOverhead:S.internalOverhead||{tokens:0,costUsd:0,components:{}}},N=j.totalOutputTokens>0?(j.totalInputTokens/j.totalOutputTokens).toFixed(1):"—",C=(f==null?void 0:f.totalRotations)||0,U=(c||[]).filter(R=>{var Y;return((Y=R.quality)==null?void 0:Y.score)!=null}),P=U.length>0?Math.round(U.reduce((R,Y)=>R+Y.quality.score,0)/U.length):null,T=t.timeline||{},B=T.snapshots||[],F=T.events||t.events||[],M=[{label:"Tokens Used",value:jt(j.totalTokens),sparkData:r.tokens,color:ce.text3,hint:"Total tokens consumed across all agents — input, output, and cache tokens combined."},{label:"Total Cost",value:er(j.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:P!=null?`${P}`:"—",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:pc(j.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:`${N}: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:`${y}/${n.length}`,sparkData:r.agents,color:ce.text3,hint:"Running agents out of total spawned this session (including completed and crashed)."},{label:"Turns",value:jt(j.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 e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(CQ,{connected:a,runningCount:y,totalCount:n.length,uptime:t.uptime||0,lastFetch:l,activeTeam:t.activeTeam}),e.jsx(dte,{kpis:M}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col bg-surface-3 gap-px",children:[e.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"3fr 1.5fr 1.5fr"},children:[e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 relative",children:e.jsx(vte,{data:B})}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Cache Performance"})}),e.jsx(yte,{cacheRead:j.cacheReadTokens,cacheCreation:j.cacheCreationTokens,totalInput:j.totalInputTokens})]}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Model Routing"})}),e.jsx(Qte,{routing:A,agentBreakdown:c})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"2fr 2.5fr 1.5fr"},children:[e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Agent Fleet"})}),e.jsx(bte,{agentBreakdown:c}),e.jsx(hte,{agentBreakdown:c,rotating:g,teams:v})]}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx(Fte,{tokens:j,rotation:f,adaptive:x,journalist:h,agentBreakdown:c,memory:b})}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx($te,{teams:O})})]})]}),e.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-t border-border",children:e.jsx(zte,{events:F})})]})}const TQ={sm:12,md:16,lg:20};function Lte({fill:t="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 e.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",children:[t==="half"&&e.jsx("defs",{children:e.jsxs("linearGradient",{id:r,children:[e.jsx("stop",{offset:"50%",stopColor:n}),e.jsx("stop",{offset:"50%",stopColor:a})]})}),e.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:t==="full"?n:t==="half"?`url(#${r})`:a})]})}function Hte({rating:t=0,count:s,size:n="sm"}){const a=TQ[n]||TQ.sm,r=[];for(let l=1;l<=5;l++)t>=l?r.push("full"):t>=l-.5?r.push("half"):r.push("empty");return e.jsxs("span",{className:"inline-flex items-center",style:{gap:1},children:[r.map((l,c)=>e.jsx(Lte,{fill:l,size:a},c)),s!=null&&e.jsxs("span",{className:"ml-1 text-[11px] text-[var(--text-dim,#6b7f95)] font-sans",children:["(",s,")"]})]})}const UQ={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 Xte({label:t,variant:s,className:n}){const a=UQ[s]||UQ.draft;return e.jsx("span",{className:Z("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:t})}function Gte({price:t=0,size:s="sm"}){const n=!t||t===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 e.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":`$${t.toFixed(2)}`})}function Zte({type:t="verified",size:s=12}){const n=t==="claude-official"||t==="anthropic"?"#f59e0b":"#4ade80";return e.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",className:"inline-block flex-shrink-0",children:[e.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}),e.jsx("path",{d:"M7 10.5l2 2 4-4.5",fill:"none",stroke:"#24282f",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Vte(){return e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md animate-pulse",style:{padding:20,minHeight:280},children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-surface-4"}),e.jsx("div",{className:"mt-3 h-4 w-[70%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-2 h-3 w-[40%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-3 w-full rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[90%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[60%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-5 w-[50px] rounded bg-surface-4"}),e.jsx("div",{className:"h-px bg-surface-4 my-3"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("div",{className:"h-3 w-16 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-12 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-10 rounded bg-surface-4"})]})]})}const Ni={"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 Kte({item:t,size:s=40}){const n=Ni[t.id];if(n)return e.jsxs("div",{className:"rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:[e.jsx("img",{src:n,alt:t.name,className:"w-5 h-5",onError:l=>{l.target.style.display="none",l.target.nextSibling.style.display="flex"}}),e.jsx("div",{className:"hidden items-center justify-center w-full h-full text-lg font-bold font-sans text-text-1",children:(t.name||"?")[0]})]});const a=(t.name||"?")[0].toUpperCase(),r=t.name?t.name.charCodeAt(0)*37%360:200;return e.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 Ux({item:t,onClick:s,className:n,statusBadge:a}){var l;const r=t.installed;return e.jsxs("button",{onClick:()=>s(t),className:Z("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:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(Kte,{item:t,size:36}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[14px] font-semibold text-text-0 font-sans truncate",children:t.name}),(t.verified||t.verified==="mcp-official")&&e.jsx(Ga,{size:11,className:"text-accent flex-shrink-0"})]}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.author||"Community"})]})]}),e.jsx("p",{className:"text-xs text-text-2 font-sans line-clamp-3 mb-3 flex-1 leading-relaxed",children:t.description}),e.jsx("div",{className:"h-px bg-border-subtle my-2"}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(qs,{size:10}),jt(t.downloads||0)]}),(t.rating||0)>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lb,{size:10,className:"text-warning",fill:"currentColor"}),(l=t.rating)==null?void 0:l.toFixed(1)]}),e.jsx("span",{className:"flex-1"}),a||r&&e.jsx(Te,{variant:"accent",className:"text-2xs",children:t._installedCount?`${t._installedCount} active`:"Installed"})]})]})}function I4({value:t,onChange:s,placeholder:n="Search skills, tags, authors...",large:a}){const[r,l]=p.useState(t||""),c=p.useRef(null);p.useEffect(()=>{l(t||"")},[t]);function A(f){const x=f.target.value;l(x),clearTimeout(c.current),c.current=setTimeout(()=>s(x),300)}return e.jsxs("div",{className:"relative w-full",children:[e.jsx(As,{size:16,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{value:r,onChange:A,placeholder:n,className:Z("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&&e.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 Hn(){const t=k(s=>s.addToast);return{success:(s,n)=>t("success",s,n),error:(s,n)=>t("error",s,n),info:(s,n)=>t("info",s,n),warning:(s,n)=>t("warning",s,n)}}const rs=p.forwardRef(({className:t,label:s,error:n,mono:a,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[s&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),e.jsx("input",{ref:l,className:Z("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",t),...r}),n&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));rs.displayName="Input";const Rv=p.forwardRef(({className:t,label:s,error:n,mono:a,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[s&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),e.jsx("textarea",{ref:l,className:Z("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",t),...r}),n&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));Rv.displayName="Textarea";const EQ=["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 Jl({item:t,size:s=48}){const n=Ni[t.id];if(n)return e.jsx("div",{className:"rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:e.jsx("img",{src:n,alt:t.name,className:"w-6 h-6",onError:l=>{l.target.classList.add("hidden")}})});const a=(t.name||"?")[0].toUpperCase(),r=EQ[(t.name||"").charCodeAt(0)%EQ.length];return e.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 ob({value:t,onChange:s,placeholder:n,disabled:a}){const[r,l]=p.useState(!1);return e.jsxs("div",{className:"relative",children:[e.jsx(rs,{type:r?"text":"password",value:t,onChange:c=>s(c.target.value),placeholder:n,disabled:a,mono:!0,className:"pr-9"}),e.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?e.jsx(To,{size:14}):e.jsx(Vs,{size:14})})]})}function qte({integrationId:t,envKey:s,onSaved:n}){const a=Hn(),[r,l]=p.useState(""),[c,A]=p.useState(!1),[f,x]=p.useState(s.set),[h,g]=p.useState(!1);async function O(){if(r.trim()){A(!0);try{await G.post(`/integrations/${t}/credentials`,{key:s.key,value:r.trim()}),x(!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/${t}/credentials/${s.key}`),x(!1),a.success(`${s.label} removed`),n==null||n()}catch(v){a.error("Failed to remove",v.message)}g(!1)}return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),s.label,s.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),f&&e.jsxs("span",{className:"flex items-center gap-1 text-2xs text-success font-sans",children:[e.jsx(Je,{size:10})," Set"]})]}),f?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-8 rounded-md px-3 bg-surface-2 border border-border-subtle flex items-center",children:e.jsx("span",{className:"text-xs text-text-4 font-mono tracking-widest",children:"*".repeat(16)})}),e.jsx(pe,{variant:"ghost",size:"sm",onClick:b,disabled:h,className:"text-text-3 hover:text-danger",children:h?e.jsx(De,{size:12,className:"animate-spin"}):e.jsx(Ft,{size:12})})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1",children:e.jsx(ob,{value:r,onChange:l,placeholder:s.placeholder||`Enter ${s.label.toLowerCase()}...`,disabled:c})}),e.jsx(pe,{variant:"primary",size:"sm",onClick:O,disabled:c||!r.trim(),children:c?e.jsx(De,{size:12,className:"animate-spin"}):"Save"})]})]})}function Wte({item:t,status:s,installing:n,onInstall:a,onUninstall:r,onNext:l}){var A;const c=s==null?void 0:s.installed;return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Jl,{item:t,size:52}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:t.name}),(t.verified==="mcp-official"||t.verified==="verified")&&e.jsxs(Te,{variant:"accent",className:"text-2xs gap-1",children:[e.jsx(vn,{size:9})," Verified"]})]}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:t.author||"Community"}),t.category&&e.jsx(Te,{variant:"default",className:"text-2xs mt-2",children:t.category})]})]}),e.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((A=t.tags)==null?void 0:A.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map(f=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:f},f))}),e.jsx("div",{className:"h-px bg-border-subtle"}),c?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[e.jsx(Ga,{size:16,className:"text-success"}),e.jsx("span",{className:"text-sm font-medium text-success font-sans",children:"Installed"})]}),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:r,className:"text-text-3 hover:text-danger gap-1.5",children:[e.jsx(Ft,{size:12})," Uninstall"]}),e.jsxs(pe,{variant:"primary",size:"sm",onClick:l,className:"gap-1",children:["Configure ",e.jsx(Tt,{size:12})]})]}):e.jsx(pe,{variant:"primary",size:"lg",onClick:a,disabled:n,className:"w-full gap-2",children:n?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"}),"Installing..."]}):"Install"}),n&&e.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"This may take up to 30 seconds..."})]})}function Yte({item:t,onClose:s}){const n=k(j=>j.agents),a=k(j=>j.teams),r=k(j=>j.installViaExistingAgent),l=k(j=>j.spawnIntegrationTeam),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState(null),O=n.filter(j=>j.status==="running"||j.status==="idle"),b={};for(const j of O){const N=j.teamId||"_none";b[N]||(b[N]=[]),b[N].push(j)}const v={};for(const j of a)v[j.id]=j.name;async function y(){h&&(await r(t,h),s())}async function S(){x(!0);try{await l(t),s()}catch{x(!1)}}return c?c==="spawn"?e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Spawn Integration Agent"}),e.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Creates a team and planner for ",t.name]})]})]}),e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"What happens next"}),e.jsx("ol",{className:"space-y-1.5",children:[`A new team "${t.name}" will be created`,"A planner agent will spawn with full integration context","The agent will handle installation and configuration"].map((j,N)=>e.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-accent font-mono flex-shrink-0 w-4 text-right",children:[N+1,"."]}),e.jsx("span",{children:j})]},N))})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(pe,{variant:"secondary",size:"lg",onClick:()=>A(null),className:"flex-1",disabled:f,children:"Back"}),e.jsx(pe,{variant:"primary",size:"lg",onClick:S,disabled:f,className:"flex-1 gap-2",children:f?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Spawning..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ei,{size:14})," Spawn Agent"]})})]})]}):e.jsxs("div",{className:"px-5 py-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Choose an Agent"}),e.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Send ",t.name," setup instructions to a running agent"]})]})]}),e.jsx(Qt,{className:"max-h-64",children:e.jsx("div",{className:"space-y-3",children:Object.entries(b).map(([j,N])=>e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5 px-1",children:v[j]||"Unassigned"}),e.jsx("div",{className:"space-y-1",children:N.map(C=>e.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:[e.jsx(qa,{size:14,className:h===C.id?"text-accent":"text-text-4"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:C.name||C.id}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:C.role})]}),h===C.id&&e.jsx(Je,{size:14,className:"text-accent flex-shrink-0"})]},C.id))})]},j))})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(pe,{variant:"secondary",size:"lg",onClick:()=>{A(null),g(null)},className:"flex-1",children:"Back"}),e.jsxs(pe,{variant:"primary",size:"lg",onClick:y,disabled:!h,className:"flex-1 gap-2",children:[e.jsx(qa,{size:14})," Send Instructions"]})]})]}):e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Jl,{item:t,size:52}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("h2",{className:"text-base font-bold text-text-0 font-sans",children:["Install ",t.name]}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Choose how to set up this integration"})]})]}),e.jsx("div",{className:"h-px bg-border-subtle"}),e.jsxs("div",{className:"space-y-2.5",children:[e.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:e.jsxs("div",{className:"flex items-center gap-3",children:[e.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:e.jsx(yn,{size:18,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Use Existing Agent"}),e.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&&e.jsx(Tt,{size:14,className:"text-text-4 group-hover:text-accent transition-colors"})]})}),e.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:e.jsxs("div",{className:"flex items-center gap-3",children:[e.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:e.jsx(Ei,{size:18,className:"text-purple"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn New Agent"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:"Create a dedicated team and planner for this integration"})]}),e.jsx(Tt,{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 z4({integrationId:t,onConfigured:s}){const n=Hn(),[a,r]=p.useState(""),[l,c]=p.useState(""),[A,f]=p.useState(!1),x=Jte[t]||"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:e.jsxs(e.Fragment,{children:["Enable the ",e.jsx("strong",{children:x})," — search for it in the API Library and click ",e.jsx("strong",{children:"Enable"})]}),link:{url:"https://console.cloud.google.com/apis/library",label:"Open API Library"}},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Credentials"})," and click ",e.jsx("strong",{children:"Create Credentials"})," → ",e.jsx("strong",{children:"OAuth client ID"})]}),link:{url:"https://console.cloud.google.com/apis/credentials",label:"Open Credentials page"}},{text:e.jsxs(e.Fragment,{children:["If prompted to configure the consent screen, choose ",e.jsx("strong",{children:"External"}),', fill in an app name (e.g. "Groove"), your email, and save. You can skip optional fields.']})},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Audience"})," and click ",e.jsx("strong",{children:"Publish App"}),". Then scroll down to ",e.jsx("strong",{children:"Test users"}),", click ",e.jsx("strong",{children:"Add Users"}),", enter your Google email address, and save."]})},{text:e.jsxs(e.Fragment,{children:["For Application type, choose ",e.jsx("strong",{children:"Desktop app"})," (not Web application). Give it any name."]})},{text:e.jsxs(e.Fragment,{children:["Click ",e.jsx("strong",{children:"Create"}),", then copy the ",e.jsx("strong",{children:"Client ID"})," and ",e.jsx("strong",{children:"Client Secret"})," and paste them below."]})}];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-3",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"How to get your Google credentials"}),e.jsx("ol",{className:"space-y-2.5",children:g.map((O,b)=>e.jsxs("li",{className:"flex gap-2.5 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-accent font-mono font-bold flex-shrink-0 w-4 text-right",children:[b+1,"."]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{children:O.text}),O.link&&e.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:[e.jsx(Ws,{size:9}),O.link.label]}),O.copyable&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.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}),e.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:e.jsx(Ba,{size:12})})]})]})]},b))})]}),e.jsx("div",{className:"bg-accent/8 border border-accent/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.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."]})}),e.jsx("div",{className:"bg-warning/8 border border-warning/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.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 ",e.jsx("strong",{children:"Advanced"}),", then ",e.jsx("strong",{children:"Go to [your app name] (unsafe)"})," to continue. Your credentials stay local and are never sent to Groove servers."]})}),e.jsx("div",{className:"h-px bg-border-subtle"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),"Client ID ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(ob,{value:a,onChange:r,placeholder:"123456789.apps.googleusercontent.com",disabled:A})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),"Client Secret ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(ob,{value:l,onChange:c,placeholder:"GOCSPX-...",disabled:A})]})]}),e.jsx(pe,{variant:"primary",size:"lg",onClick:h,disabled:A||!a.trim()||!l.trim(),className:"w-full gap-2",children:A?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Saving..."]}):"Save Credentials"})]})}function ese({item:t,status:s,onDone:n,onRefreshStatus:a}){var S;const r=Hn(),[l,c]=p.useState(!1),[A,f]=p.useState(null),x=t.authType,h=x==="google-autoauth"||x==="oauth-google";p.useEffect(()=>{h&&G.get("/integrations/google-oauth/status").then(j=>f(j.configured)).catch(()=>f(!1))},[h]);const g=p.useRef(null);p.useEffect(()=>()=>{g.current&&clearInterval(g.current)},[]);async function O(){c(!0);try{const j=await G.post(`/integrations/${t.id}/oauth/start`);if(j.url){const N=await ON(j.url);if(N!=null&&N.error){r.error("Sign-in failed",N.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 U=await G.get(`/integrations/${t.id}/status`);((U==null?void 0:U.envKeys)||[]).some(B=>B.key==="GOOGLE_REFRESH_TOKEN"&&B.set)&&(clearInterval(g.current),g.current=null,r.success("Connected!",`${t.name} is now authenticated`),a(),c(!1))}catch{}},2e3)}}catch(j){r.error("Sign-in failed",j.message),c(!1)}}const b=(s==null?void 0:s.envKeys)||[],v=b.filter(j=>j.required&&!j.hidden),y=v.length===0||v.every(j=>j.set);return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm font-bold text-text-0 font-sans",children:["Configure ",t.name]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Set up credentials to connect"})]})]}),((S=t.setupSteps)==null?void 0:S.length)>0&&!(h&&A===!1)&&e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Setup guide"}),e.jsx("ol",{className:"space-y-1.5",children:t.setupSteps.map((j,N)=>e.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 font-mono flex-shrink-0 w-4 text-right",children:[N+1,"."]}),e.jsx("span",{children:j})]},N))}),t.setupUrl&&e.jsxs("a",{href:t.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-accent font-sans hover:underline mt-1",children:[e.jsx(Ws,{size:11}),new URL(t.setupUrl).hostname]})]}),!(h&&A===!1)&&e.jsx("div",{className:"h-px bg-border-subtle"}),x==="api-key"&&e.jsx("div",{className:"space-y-4",children:b.filter(j=>!j.hidden).map(j=>e.jsx(qte,{integrationId:t.id,envKey:j,onSaved:a},j.key))}),h&&A===!1&&e.jsx(z4,{integrationId:t.id,onConfigured:()=>f(!0)}),h&&A&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(pe,{variant:"primary",size:"lg",onClick:O,disabled:l,className:"w-full gap-2",children:l?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"}),"Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.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 ",t.name]}),e.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&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(De,{size:16,className:"animate-spin text-text-4"})}),e.jsx(pe,{variant:y?"primary":"secondary",size:"lg",onClick:n,className:"w-full gap-1.5",children:y?e.jsxs(e.Fragment,{children:[e.jsx(Je,{size:14}),"Done"]}):"Skip for now"})]})}function tse({item:t,onClose:s}){return e.jsxs("div",{className:"px-5 py-10 flex flex-col items-center text-center space-y-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(Ga,{size:28,className:"text-success"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:"Integration ready"}),e.jsxs("p",{className:"text-sm text-text-3 font-sans mt-1",children:[t.name," is installed and configured. Agents can now use it."]})]}),e.jsx(pe,{variant:"primary",size:"lg",onClick:s,className:"mt-2",children:"Close"})]})}function _4({integration:t,open:s,onClose:n}){const a=Hn(),[r,l]=p.useState("overview"),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState(!0),O=t==null?void 0:t.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&&t&&(l("overview"),g(!0),b())},[s,t,b]);function v(){l("agent-setup")}async function y(){try{await G.delete(`/integrations/${t.id}`),a.success(`${t.name} uninstalled`),await b()}catch(C){a.error("Uninstall failed",C.message)}}function S(){l("configure")}function j(){l("done")}if(!t)return null;const N={overview:t.name,"agent-setup":"Install",configure:"Configure",done:"Complete"};return e.jsx(Vt,{open:s,onOpenChange:C=>{C||n()},children:e.jsx(Kt,{title:N[r]||t.name,description:`Setup wizard for ${t.name}`,className:"max-w-md",children:h?e.jsx("div",{className:"px-5 py-10 flex items-center justify-center",children:e.jsx(De,{size:20,className:"animate-spin text-text-4"})}):r==="overview"?e.jsx(Wte,{item:t,status:c,installing:f,onInstall:v,onUninstall:y,onNext:S}):r==="agent-setup"?e.jsx(Yte,{item:t,onClose:n}):r==="configure"?e.jsx(ese,{item:t,status:c,onDone:j,onRefreshStatus:b}):e.jsx(tse,{item:t,onClose:n})})})}const sse=["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"];function nse({item:t,status:s,onInstall:n,onUninstall:a,busy:r}){const l=s==null?void 0:s.installed,c=s==null?void 0:s.authenticated;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-2 border border-border-subtle",children:[e.jsx(Jl,{item:t,size:32}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans",children:t.name}),e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:t.description})]}),l&&c&&!(s!=null&&s.needsReauth)&&e.jsxs(Te,{variant:"success",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(Je,{size:8})," Ready"]}),l&&c&&(s==null?void 0:s.needsReauth)&&e.jsxs(Te,{variant:"warning",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(Ls,{size:8})," Update"]}),l&&!c&&e.jsx(Te,{variant:"warning",className:"text-2xs flex-shrink-0",children:"Needs sign-in"}),e.jsx(pe,{variant:l?"ghost":"primary",size:"sm",onClick:()=>l?a(t.id):n(t.id),disabled:r===t.id,className:l?"text-text-3 hover:text-danger":"",children:r===t.id?e.jsx(De,{size:12,className:"animate-spin"}):l?e.jsx(Ft,{size:12}):"Install"})]})}function ase({integrations:t,open:s,onClose:n}){const a=Hn(),[r,l]=p.useState(null),[c,A]=p.useState({}),[f,x]=p.useState(null),[h,g]=p.useState(!1),[O,b]=p.useState(!0),v=p.useRef(null),y=t.filter(B=>sse.includes(B.id)),S=p.useCallback(async()=>{const B={};await Promise.all(y.map(async F=>{try{B[F.id]=await G.get(`/integrations/${F.id}/status`)}catch{B[F.id]=null}})),A(B),b(!1)},[y.map(B=>B.id).join(",")]);p.useEffect(()=>(s&&(b(!0),G.get("/integrations/google-oauth/status").then(B=>l(B.configured)).catch(()=>l(!1)),S()),()=>{v.current&&clearInterval(v.current)}),[s]);const j=Object.entries(c).filter(([,B])=>B==null?void 0:B.installed).map(([B])=>B),N=j.length>0&&j.every(B=>{var F;return(F=c[B])==null?void 0:F.authenticated});j.some(B=>{var F;return!((F=c[B])!=null&&F.authenticated)});const C=N&&j.some(B=>{var F;return(F=c[B])==null?void 0:F.needsReauth});async function U(B){var F;x(B);try{await G.post(`/integrations/${B}/install`),a.success(`${(F=y.find(M=>M.id===B))==null?void 0:F.name} installed`),await S()}catch(M){a.error("Install failed",M.message)}x(null)}async function P(B){var F;x(B);try{await G.delete(`/integrations/${B}`),a.success(`${(F=y.find(M=>M.id===B))==null?void 0:F.name} removed`),await S()}catch(M){a.error("Uninstall failed",M.message)}x(null)}async function T(){if(!j.length){a.error("Install at least one service first");return}g(!0);try{const B=await G.post("/integrations/google-workspace/oauth/start",{integrationIds:j});if(B.url){const F=await ON(B.url);if(F!=null&&F.error){a.error("Sign-in failed",F.error),g(!1);return}a.success("Browser opened — complete sign-in there"),v.current&&clearInterval(v.current),v.current=setInterval(async()=>{await S()},3e3),setTimeout(()=>{v.current&&clearInterval(v.current)},18e4)}}catch(B){a.error("Sign-in failed",B.message)}g(!1)}return p.useEffect(()=>{N&&v.current&&(clearInterval(v.current),v.current=null)},[N]),s?e.jsx(Vt,{open:s,onOpenChange:B=>{B||n()},children:e.jsx(Kt,{title:"Google Workspace",description:"Connect your Google services",className:"max-w-md",children:e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"Google",className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Google Workspace"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"One set of credentials for all Google services"})]})]}),r===!1&&e.jsx(z4,{integrationId:"gmail",onConfigured:()=>l(!0)}),r===null&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(De,{size:16,className:"animate-spin text-text-4"})}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans",children:"Services"}),e.jsx("div",{className:"space-y-1.5",children:O?Array.from({length:4}).map((B,F)=>e.jsx("div",{className:"h-14 rounded-md bg-surface-2 animate-pulse"},F)):y.map(B=>e.jsx(nse,{item:B,status:c[B.id],onInstall:U,onUninstall:P,busy:f},B.id))})]}),e.jsx("div",{className:"h-px bg-border-subtle"}),j.length>0&&!N&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(pe,{variant:"primary",size:"lg",onClick:T,disabled:h,className:"w-full gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["Connects ",j.length," service",j.length!==1?"s":""," with one sign-in"]})]}),N&&j.length>0&&e.jsxs("div",{className:"flex flex-col items-center text-center gap-2 py-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(Ga,{size:20,className:"text-success"})}),e.jsx("p",{className:"text-sm font-medium text-success font-sans",children:"All services connected"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Your agents can now use these Google integrations."}),C?e.jsxs("div",{className:"w-full space-y-2 pt-2",children:[e.jsx("p",{className:"text-2xs text-warning font-sans",children:"New permissions available — re-authenticate to enable all features."}),e.jsx(pe,{variant:"secondary",size:"sm",onClick:T,disabled:h,className:"w-full gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:12,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ls,{size:12})," Re-authenticate"]})})]}):e.jsx("button",{onClick:T,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"})]}),j.length===0&&!O&&e.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."})]}),e.jsx(pe,{variant:"secondary",size:"lg",onClick:n,className:"w-full",children:N&&j.length>0?"Done":"Close"})]})})}):null}const Hg=/github\.com\/([^/]+)\/([^/\s#?]+)/;function rse(){const[t,s]=p.useState("input"),[n,a]=p.useState(""),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,x]=p.useState("standalone"),[h,g]=p.useState(""),[O,b]=p.useState(!0),[v,y]=p.useState(""),S=k(B=>B.previewRepo),j=k(B=>B.importRepo),N=k(B=>B.importInProgress),C=Hn(),U=p.useCallback(async B=>{const F=B.match(Hg);if(F){l(!0);try{const M=await S(B);A(M),y(M.name||F[2]),s("preview")}catch(M){C.error("Preview failed",M.message)}finally{l(!1)}}},[S,C]),P=p.useCallback(B=>{const F=B.target.value;a(F),Hg.test(F)&&t==="input"&&U(F)},[t,U]),T=p.useCallback(async()=>{if(!c)return;let B;f==="standalone"?B=`~/Projects/${c.name}`:f==="subdirectory"?B=`./packages/${c.name}`:B=h;try{await j(n,B,O,v),C.success(`Importing ${c.name}`,"Setup agent will handle the rest"),s("input"),a(""),A(null)}catch(F){C.error("Import failed",F.message)}},[c,f,h,n,O,v,j,C]);if(t==="input")return e.jsxs("div",{className:"relative",children:[e.jsx(As,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{type:"text",value:n,onChange:P,placeholder:"Paste a GitHub URL...",className:Z("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")}),e.jsx(pe,{variant:"primary",size:"sm",className:"absolute right-1.5 top-1/2 -translate-y-1/2",onClick:()=>U(n),disabled:!Hg.test(n)||r,children:r?e.jsx(De,{size:12,className:"animate-spin"}):"Preview"})]});if(t==="preview"&&c)return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(Kl,{size:22,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[e.jsx("span",{className:"text-lg font-bold text-text-0 font-sans",children:c.name}),e.jsx("span",{className:"text-xs text-text-4 font-sans",children:c.owner})]}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[c.language&&e.jsx(Te,{variant:"outline",className:"text-2xs",children:c.language}),c.stars!=null&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lb,{size:10,className:"text-warning",fill:"currentColor"}),jt(c.stars)]}),c.license&&e.jsx("span",{children:c.license})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(pe,{variant:"primary",size:"sm",onClick:()=>s("configure"),className:"h-8 text-xs gap-1.5 px-4",children:[e.jsx(Ys,{size:13}),"Clone & Setup"]}),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>{try{const B=n.startsWith("http")?n:`https://${n}`,F=new URL(B);(F.protocol==="https:"||F.protocol==="http:")&&window.open(B,"_blank")}catch{}},className:"h-8 text-xs gap-1.5",children:[e.jsx(Ws,{size:12}),"GitHub"]}),e.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&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2",children:"About"}),e.jsx("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:c.description})]}),c.readmePreview&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-3",children:"README"}),e.jsx("div",{className:"text-sm text-text-2 font-sans leading-relaxed whitespace-pre-wrap",children:c.readmePreview})]})]});if(t==="configure"&&c){const B=[{id:"standalone",icon:xd,title:"Standalone project",description:"Clone to its own directory, separate from this workspace",path:`~/Projects/${c.name}`},{id:"subdirectory",icon:zb,title:"Workspace package",description:"Add as a package inside this project's monorepo",path:`./packages/${c.name}`},{id:"custom",icon:RS,title:"Custom location",description:"Choose your own path",path:null}];return e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-2 overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 border-b border-border-subtle bg-surface-3/50",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0",children:e.jsx(qs,{size:16,className:"text-accent"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:["Clone ",c.name]}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:[c.owner,"/",c.name," — configure where to install"]})]})]})}),e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2.5 block",children:"Install location"}),e.jsx("div",{className:"space-y-2",children:B.map(F=>{const M=F.icon,R=f===F.id;return e.jsx("button",{onClick:()=>x(F.id),className:Z("w-full text-left rounded-lg border p-3.5 transition-all duration-150 cursor-pointer",R?"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:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:Z("w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0 mt-0.5",R?"bg-accent/15 text-accent":"bg-surface-3 text-text-4"),children:e.jsx(M,{size:15})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:Z("text-xs font-semibold font-sans",R?"text-text-0":"text-text-2"),children:F.title}),R&&e.jsx("div",{className:"w-4 h-4 rounded-full bg-accent flex items-center justify-center",children:e.jsx(Je,{size:10,className:"text-white"})})]}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5 leading-relaxed",children:F.description}),F.path&&R&&e.jsx("code",{className:"text-2xs text-accent/80 font-mono mt-1.5 block truncate",children:F.path})]})]})},F.id)})}),f==="custom"&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:h,onChange:F=>g(F.target.value),placeholder:"/path/to/clone",autoFocus:!0,className:Z("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")})})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-3 flex items-center justify-center",children:e.jsx(yn,{size:14,className:"text-text-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans block",children:"Create a team"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Organize agents working on this repo into their own team"})]})]}),e.jsx("button",{onClick:()=>b(!O),className:Z("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer flex-shrink-0",O?"bg-accent":"bg-surface-5"),children:e.jsx("div",{className:Z("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",O?"translate-x-4":"translate-x-0")})})]}),O&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:v,onChange:F=>y(F.target.value),placeholder:"Team name",className:Z("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")})})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle bg-surface-3/30 flex items-center justify-between",children:[e.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:[e.jsx(kb,{size:11}),"Back"]}),e.jsx(pe,{variant:"primary",size:"sm",onClick:T,disabled:N||f==="custom"&&!h.trim(),className:"h-8 text-xs gap-1.5 px-5",children:N?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:12,className:"animate-spin"})," Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(qs,{size:12})," Clone & Setup"]})})]})]})}return null}function ose({repo:t,onRemove:s,onNuke:n,onOpen:a}){return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-3 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:t.repoName||t.name}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.repoOwner||t.owner})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.language&&e.jsx(Te,{variant:"outline",className:"text-2xs",children:t.language}),e.jsx("span",{className:"text-2xs text-text-4 font-mono truncate max-w-[180px]",children:t.clonedTo||t.path})]}),e.jsx("span",{className:"text-2xs text-text-4 font-sans mt-0.5 block",children:t.clonedAt?`Imported ${$t(t.clonedAt)}`:t.status||""})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a&&e.jsxs("button",{onClick:()=>a(t),className:Z("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:[e.jsx(Ys,{size:11}),"Open"]}),s&&e.jsxs("button",{onClick:()=>s(t),className:Z("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:[e.jsx(Ft,{size:11}),"Remove"]}),n&&e.jsxs("button",{onClick:()=>n(t),className:Z("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:[e.jsx(_$,{size:11}),"Nuke"]})]})]})}function ise({repo:t,open:s,onClose:n,onConfirm:a}){var h,g,O;const[r,l]=p.useState(!0);if(!t)return null;const c=((h=t.agents)==null?void 0:h.length)||0,A=((g=t.processes)==null?void 0:g.length)||0,f=((O=t.credentialKeys)==null?void 0:O.length)||0,x=t.fileCount||0;return e.jsx(Vt,{open:s,onOpenChange:b=>{b||n()},children:e.jsx(Kt,{title:`Nuke ${t.repoName||t.name}?`,description:"Confirm destructive removal of imported repo",children:e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Aa,{size:16,className:"text-danger flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-text-1 font-sans",children:"This cannot be undone."})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-text-2 font-sans",children:[c>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Kill ",c," agent",c!==1?"s":""]}),A>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Stop ",A," process",A!==1?"es":""]}),f>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Remove ",f," credential",f!==1?"s":""]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"}),' Delete team "',t.teamId||t.repoName||t.name,'"']}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Clean all .groove state"]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:b=>l(b.target.checked),className:"accent-[var(--color-danger)]"}),e.jsxs("span",{className:"text-xs text-text-1 font-sans",children:["Delete repo files",x>0?` (${x} files)`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(pe,{variant:"danger",size:"sm",onClick:()=>a(r),children:"Nuke Everything"}),e.jsx(pe,{variant:"ghost",size:"sm",onClick:n,children:"Cancel"})]})]})})})}function lse({skill:t,onBack:s}){var P,T,B;const n=Hn(),[a,r]=p.useState(""),[l,c]=p.useState(!1),[A,f]=p.useState(!1),[x,h]=p.useState(!1),[g,O]=p.useState(!1),[b,v]=p.useState(t.installed),[y,S]=p.useState(!0);p.useEffect(()=>{S(!0),G.get(`/skills/${t.id}/content`).then(F=>{r(F.content||""),c(F.requiresPurchase||!1)}).catch(()=>{}).finally(()=>S(!1))},[t.id]);async function j(){f(!0);try{await G.post(`/skills/${t.id}/install`),v(!0),n.success(`${t.name} installed`)}catch(F){n.error("Install failed",F.message)}f(!1)}async function N(){h(!0);try{await G.post(`/skills/${t.id}/update`),n.success(`${t.name} updated to latest`);const F=await G.get(`/skills/${t.id}/content`);F.content&&r(F.content)}catch(F){n.error("Update failed",F.message)}h(!1)}async function C(){O(!0);try{await G.delete(`/skills/${t.id}`),v(!1),n.success(`${t.name} uninstalled`)}catch(F){n.error("Uninstall failed",F.message)}O(!1)}async function U(){const{marketplaceAuthenticated:F,marketplaceLogin:M,marketplaceCheckout:R}=k.getState();if(!F){M();return}try{await R(t.id)}catch{}}return e.jsx(Qt,{className:"h-full",children:e.jsxs("div",{className:"px-6 py-5",children:[e.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:[e.jsx(Di,{size:14})," Back"]}),e.jsxs("div",{className:"flex gap-8",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.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:t.icon||((T=(P=t.name)==null?void 0:P[0])==null?void 0:T.toUpperCase())}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-text-3 font-sans",children:[e.jsx("span",{children:t.author||"Community"}),(t.source==="claude-official"||t.verified)&&e.jsx(Zte,{type:t.source,size:13})]})]})]}),e.jsx("p",{className:"mt-3 text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((B=t.tags)==null?void 0:B.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:t.tags.map(F=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:F},F))}),e.jsx("div",{className:"h-px bg-border-subtle my-5"}),y?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-3 w-48 bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}):a?e.jsxs("div",{className:"text-sm text-text-2 font-sans leading-relaxed",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-0 mb-2",children:"About"}),e.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:a})]}):l?e.jsxs("div",{className:"bg-warning/5 border border-warning/15 rounded-lg px-4 py-3",children:[e.jsx("p",{className:"text-sm text-text-1 font-sans font-medium",children:"Paid skill — purchase to view content"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Sign in and purchase this skill to access its full instructions."})]}):e.jsx("p",{className:"text-xs text-text-4 font-sans",children:"Content loading failed — check your connection."})]}),e.jsx("div",{className:"w-[240px] flex-shrink-0",children:e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-lg p-4 sticky top-4",children:[e.jsx(Gte,{price:t.price||0,size:"md"}),l&&!b?e.jsxs("button",{onClick:U,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 $",(t.price||0).toFixed(2)]}):b?e.jsxs("div",{className:"mt-3 flex flex-col gap-1.5",children:[e.jsxs("button",{onClick:N,disabled:x,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:[e.jsx(Ls,{size:12,className:x?"animate-spin":""}),x?"Updating...":"Pull Latest"]}),e.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:[e.jsx(Ft,{size:12}),g?"Removing...":"Uninstall"]})]}):e.jsx("button",{onClick:j,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"}),e.jsx("div",{className:"mt-4 flex flex-col gap-2.5",children:[["Downloads",e.jsx("span",{className:"font-mono text-text-0",children:jt(t.downloads||0)},"d")],["Rating",e.jsx(Hte,{rating:t.rating||0,count:t.rating_count||t.ratingCount,size:"sm"},"r")],["Version",e.jsx("span",{className:"font-mono text-text-0",children:t.version||"1.0.0"},"v")],["Category",e.jsx(Xte,{label:t.category||"general",variant:t.category||"draft"},"c")],["Source",e.jsx("span",{className:"text-text-0",children:t.source==="claude-official"?"Anthropic":"Community"},"s")]].map(([F,M])=>e.jsxs("div",{className:"flex justify-between items-center text-xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:F}),M]},F))})]})})]})]})})}function cse({open:t,onClose:s}){const[n,a]=p.useState("new"),[r,l]=p.useState(""),[c,A]=p.useState(""),[f,x]=p.useState(""),[h,g]=p.useState(""),[O,b]=p.useState(""),[v,y]=p.useState(!1),S=k(M=>M.teams),j=k(M=>M.activeTeamId),N=k(M=>M.createTeam),C=k(M=>M.spawnAgent),U=k(M=>M.setActiveView),P=k(M=>M.selectAgent),T=Hn();p.useEffect(()=>{t&&(a("new"),l(""),A(j||""),x(""),g(""),b(""),y(!1))},[t,j]);async function B(){if(f.trim()){y(!0);try{let M;n==="new"?M=(await N(r.trim()||f.trim())).id:M=c;const R=[`The user wants to integrate the **${f.trim()}** API into their project.`,""];h.trim()&&R.push(`**API Documentation:** ${h.trim()}`),O.trim()&&R.push("**API Key:** The user has provided an API key. Store it securely using environment variables — never hardcode it."),R.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 Y=R.join(`
|
|
1013
1013
|
`),W=await C({role:"fullstack",prompt:Y,teamId:M});O.trim()&&await G.post(`/agents/${W.id}/instruct`,{message:`Here is the API key for ${f.trim()}: \`${O.trim()}\`
|
|
1014
1014
|
|
|
1015
1015
|
Store this in a .env file as an environment variable. Do not commit it to git.`}).catch(()=>{}),U("agents"),P(W.id),s()}catch(M){T("error","Failed to start integration",M.message),y(!1)}}}const F=f.trim()&&(n==="new"||c);return e.jsx(Vt,{open:t,onOpenChange:M=>!M&&s(),children:e.jsx(Kt,{title:"New Integration",description:"Set up a custom API integration",children:e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[e.jsx(rs,{label:"Integration name",placeholder:"e.g. NASA APOD, Stripe, Twilio…",value:f,onChange:M=>x(M.target.value),autoFocus:!0}),e.jsx(rs,{label:"Documentation URL",placeholder:"https://api.example.com/docs",value:h,onChange:M=>g(M.target.value)}),e.jsx(rs,{label:"API key (optional)",placeholder:"sk-...",value:O,onChange:M=>b(M.target.value),mono:!0,type:"password"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-text-2 font-sans",children:"Team"}),e.jsxs("div",{className:"flex gap-2",children:[e.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:[e.jsx(it,{size:12}),"New team"]}),e.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:[e.jsx(yn,{size:12}),"Existing team"]})]}),n==="new"?e.jsx(rs,{placeholder:f?f.trim():"Team name (defaults to integration name)",value:r,onChange:M=>l(M.target.value)}):e.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:[e.jsx("option",{value:"",children:"Select a team…"}),S.map(M=>e.jsx("option",{value:M.id,children:M.name},M.id))]})]}),e.jsx(pe,{onClick:B,disabled:!F||v,className:"w-full mt-1",children:v?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Setting up…"]}):"Go"})]})})})}const PQ=new Set(["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"]);function Ase(){const[t,s]=p.useState([]),[n,a]=p.useState(!0),[r,l]=p.useState(""),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState(!1),[O,b]=p.useState(!1),v=()=>{a(!0),G.get(`/integrations/registry?search=${encodeURIComponent(r)}`).then(P=>s(P.integrations||P.items||(Array.isArray(P)?P:[]))).catch(()=>s([])).finally(()=>a(!1))};p.useEffect(()=>{v()},[r]);const y=t.filter(P=>PQ.has(P.id)),S=t.filter(P=>!PQ.has(P.id)),j=y.filter(P=>P.installed).length;function N(P){A(P),x(!0)}function C(){x(!1),A(null),v()}const U=!r||"google workspace gmail calendar drive docs sheets slides".includes(r.toLowerCase());return e.jsxs(Qt,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-72",children:e.jsx(I4,{value:r,onChange:l,placeholder:"Search integrations..."})}),e.jsx("div",{className:"flex-1"}),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>b(!0),className:"gap-1 text-xs",children:[e.jsx(it,{size:13}),"New"]}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:S.length+(y.length>0?1:0)})]}),e.jsx("div",{className:"mt-4 grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:n?Array.from({length:6}).map((P,T)=>e.jsx(Vte,{},T)):e.jsxs(e.Fragment,{children:[y.length>0&&U&&e.jsx(Ux,{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:j>0,_installedCount:j},onClick:()=>g(!0)},"google-workspace"),S.map(P=>e.jsx(Ux,{item:P,onClick:()=>N(P)},P.id))]})}),!n&&S.length===0&&y.length===0&&e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No integrations found."})]}),e.jsx(_4,{integration:c,open:f,onClose:C}),e.jsx(ase,{integrations:t,open:h,onClose:()=>{g(!1),v()}}),e.jsx(cse,{open:O,onClose:()=>b(!1)})]})}function dse(){const t=k(K=>K.marketplaceAuthenticated),s=k(K=>K.marketplaceLogin),[n,a]=p.useState([]),[r,l]=p.useState([]),[c,A]=p.useState([]),[f,x]=p.useState(!0),[h,g]=p.useState("all"),[O,b]=p.useState(""),[v,y]=p.useState(null),[S,j]=p.useState(null),[N,C]=p.useState(!1),U=Hn(),P=p.useRef(null),T=async()=>{const[K,_]=await Promise.all([G.get("/skills/installed").catch(()=>[]),G.get("/integrations/installed").catch(()=>[])]);l(Array.isArray(K)?K:K.skills||[]),A(Array.isArray(_)?_:_.integrations||[])};p.useEffect(()=>{x(!0),Promise.all([t?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,_,E])=>{a(K),l(_),A(E)}).finally(()=>x(!1))},[t]);async function B(K){var E;const _=(E=K.target.files)==null?void 0:E[0];if(_){try{const q=await _.text(),H=_.name.replace(/\.md$/i,"");await G.post("/skills/import",{name:H,content:q}),U.success(`Imported "${H}"`),await T()}catch(q){U.error("Import failed",q.message)}K.target.value=""}}if(v)return e.jsx(lse,{skill:v,onBack:()=>y(null)});const F=O.toLowerCase(),M=h==="all"||h==="skills"?r.filter(K=>!F||(K.name||K.id||"").toLowerCase().includes(F)||(K.description||"").toLowerCase().includes(F)):[],R=h==="all"||h==="integrations"?c.filter(K=>!F||(K.name||K.id||"").toLowerCase().includes(F)||(K.description||"").toLowerCase().includes(F)):[],Y=[...M.map(K=>({...K,_type:"skill"})),...R.map(K=>({...K,_type:"integration"}))],W=[{id:"all",label:"All"},{id:"skills",label:"Skills"},{id:"integrations",label:"Integrations"}],ee={all:"No skills or integrations installed yet. Visit the Marketplace to get started.",skills:"No skills installed.",integrations:"No integrations installed."};return f?e.jsx("div",{className:"p-5 space-y-3",children:[...Array(4)].map((K,_)=>e.jsx(ia,{className:"h-14 rounded-md"},_))}):e.jsxs(Qt,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("div",{className:"w-72",children:e.jsx(I4,{value:O,onChange:b,placeholder:"Search library..."})}),e.jsx("div",{className:"flex items-center gap-1",children:W.map(K=>e.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))}),e.jsx("div",{className:"flex-1"}),e.jsx("input",{ref:P,type:"file",accept:".md",onChange:B,className:"hidden"}),e.jsxs(pe,{variant:"secondary",size:"md",onClick:()=>{var K;return(K=P.current)==null?void 0:K.click()},className:"gap-1.5",children:[e.jsx(Hb,{size:13}),"Import .md"]}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:Y.length})]}),t&&n.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[e.jsx(Lp,{size:12}),"Purchases (",n.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:n.map(K=>{var _,E;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-1 border border-border-subtle",children:[e.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=(_=K.skill_name)==null?void 0:_[0])==null?void 0:E.toUpperCase())||"?"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:K.skill_name||K.skill_id}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans",children:["$",(K.amount||0).toFixed(2)," · ",$t(K.created_at)]})]}),e.jsx(Te,{variant:"success",className:"text-2xs flex-shrink-0",children:"Owned"})]},K.id||K.skill_id)})})]}),t&&n.length===0&&e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[e.jsx(Lp,{size:20,className:"mx-auto text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No purchases yet"})]}),!t&&e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[e.jsx(Lp,{size:20,className:"mx-auto text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-2 font-sans mb-3",children:"Sign in to see your purchases"}),e.jsxs(pe,{variant:"primary",size:"sm",onClick:s,className:"gap-1.5 mx-auto",children:[e.jsx(PS,{size:12})," Sign in"]})]}),Y.length>0?e.jsx("div",{className:"grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:Y.map(K=>K._type==="skill"?e.jsx(Ux,{item:{...K,installed:!0},onClick:()=>y(K)},`skill-${K.id}`):e.jsx(Ux,{item:{...K,installed:!0},onClick:()=>{j(K),C(!0)},statusBadge:e.jsx(Te,{variant:K.configured?"success":"warning",className:"text-2xs",children:K.configured?"Active":"Not configured"})},`int-${K.id}`))}):e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:ee[h]})]}),e.jsx(_4,{integration:S,open:N,onClose:()=>{C(!1),j(null),T()}})]})}function use(){const t=k(x=>x.importedRepos),s=k(x=>x.fetchImportedRepos),n=k(x=>x.softRemoveRepo),a=k(x=>x.hardNukeRepo),r=Hn(),[l,c]=p.useState(null);p.useEffect(()=>{s()},[]);async function A(x){try{await n(x.id),r.success(`Removed ${x.repoName||x.name}`)}catch(h){r.error("Remove failed",h.message)}}async function f(x){if(l){try{x?await a(l.id):await n(l.id),r.success(`${x?"Nuked":"Removed"} ${l.name||l.repo}`)}catch(h){r.error("Nuke failed",h.message)}c(null)}}return e.jsxs(Qt,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsx(rse,{}),t.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3",children:"Recently Imported"}),e.jsx("div",{className:"space-y-2",children:(Array.isArray(t)?t:[]).map(x=>e.jsx(ose,{repo:x,onRemove:()=>A(x),onNuke:()=>c(x)},x.id))})]}),t.length===0&&e.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."})]}),e.jsx(ise,{repo:l,open:!!l,onClose:()=>c(null),onConfirm:f})]})}function fse(){const[t,s]=p.useState("integrations"),n=[{id:"integrations",label:"Integrations",icon:on},{id:"github",label:"GitHub",icon:Kl},{id:"library",label:"My Library",icon:zb}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-b border-border-subtle",children:e.jsxs("div",{className:"flex items-center px-5 h-11",children:[e.jsx("div",{className:"flex items-center",children:n.map(a=>{const r=a.icon;return e.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 ${t===a.id?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"}`,children:[e.jsx(r,{size:12}),a.label]},a.id)})}),e.jsx("div",{className:"flex-1"})]})}),e.jsxs("div",{className:"flex-1 min-h-0",children:[t==="integrations"&&e.jsx(Ase,{}),t==="github"&&e.jsx(use,{}),t==="library"&&e.jsx(dse,{})]})]})}const Mv=[{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"}],xse=new Map(Mv.map(t=>[t.cron,t.description]));function mse(t){if(!t)return"";const s=t.trim(),n=xse.get(s);return n||s}const hse=[{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 pse(t,s){if(t==="*")return null;if(/^\*\/\d+$/.test(t)){const a=parseInt(t.slice(2),10);return a<1||a>s.max?`Invalid step ${a} for ${s.name}`:null}const n=t.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 gse(t){if(!t||typeof t!="string")return{valid:!1,error:"Expression is required"};const s=t.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=pse(s[n],hse[n]);if(a)return{valid:!1,error:a}}return{valid:!0}}function Ose({automation:t}){var T,B,F,M,R,Y,W,ee,K,_;const s=k(E=>E.toggleAutomation),n=k(E=>E.deleteAutomation),a=k(E=>E.duplicateAutomation),r=k(E=>E.runAutomation),l=k(E=>E.setEditingAutomation),c=k(E=>E.openAutomationWizard),A=k(E=>E.openDetail),f=k(E=>E.agents),[x,h]=p.useState(!1),g=p.useRef(null);p.useEffect(()=>{if(!x)return;function E(q){g.current&&!g.current.contains(q.target)&&h(!1)}return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[x]);const O=t,b=O.teamConfig||(O.agentConfig?[O.agentConfig]:O.role?[{role:O.role}]:[]),v=((T=O.instructionSource)==null?void 0:T.type)==="inline"?O.instructionSource.content:((B=O.instructionSource)==null?void 0:B.type)==="file"?null:O.prompt||null,y=((F=O.instructionSource)==null?void 0:F.type)==="file"?O.instructionSource.filePath:null,S=((M=O.outputConfig)==null?void 0:M.gatewayIds)||[],j=O.lastRunStatus||(O.lastRunAt?"completed":null),N=(O.activeAgentIds||[]).map(E=>f.find(q=>q.id===E)).filter(Boolean),C=(R=O.lastRun)!=null&&R.agentId?O.lastRun.agentId.split(",").filter(Boolean):[],U=O.isRunning?[]:C.map(E=>f.find(q=>q.id===E)).filter(Boolean);function P(E){A({type:"agent",agentId:E})}return e.jsxs("div",{className:Z("rounded-md border bg-surface-1 overflow-hidden transition-colors",O.enabled?"border-border-subtle":"border-border-subtle/50 opacity-75"),children:[e.jsxs("div",{className:"px-4 py-3 flex items-start gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans truncate",children:O.name}),e.jsx(Te,{variant:O.enabled?"success":"default",className:"text-2xs flex-shrink-0",children:O.enabled?"Active":"Paused"})]}),O.description&&e.jsx("p",{className:"text-2xs text-text-3 font-sans truncate mt-0.5",children:O.description})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("button",{onClick:()=>s(O.id,O.enabled),className:Z("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?e.jsx(qx,{size:13}):e.jsx(Za,{size:13})}),e.jsxs("div",{ref:g,className:"relative",children:[e.jsx("button",{onClick:()=>h(!x),className:"p-1.5 rounded text-text-4 hover:text-text-2 transition-colors cursor-pointer",children:e.jsx(Xx,{size:13})}),x&&e.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:[e.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:[e.jsx(Ua,{size:10})," Edit"]}),e.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:[e.jsx(Ba,{size:10})," Duplicate"]}),e.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:[e.jsx(Za,{size:10})," Run Now"]}),e.jsx("div",{className:"h-px my-1 bg-border-subtle"}),e.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:[e.jsx(Ft,{size:10})," Delete"]})]})]})]})]}),b.length>0&&e.jsxs("div",{className:"px-4 pb-2 flex items-center gap-1.5 flex-wrap",children:[b.map((E,q)=>e.jsxs(Te,{variant:"default",className:"text-2xs",children:[E.role,E.phase?` P${E.phase}`:""]},q)),((Y=O.integrationIds)==null?void 0:Y.length)>0&&e.jsxs("span",{className:"text-2xs text-text-4 font-sans ml-1",children:["+",O.integrationIds.length," integrations"]})]}),(v||y)&&e.jsx("div",{className:"px-4 pb-2",children:y?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Li,{size:10,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-mono text-text-3 truncate",children:y})]}):e.jsxs("p",{className:"text-2xs text-text-3 font-sans truncate",children:[e.jsx(On,{size:10,className:"inline mr-1 text-text-4"}),v.slice(0,100),v.length>100?"...":""]})}),e.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle bg-surface-0 flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Dn,{size:10,className:"text-text-4"}),e.jsx("span",{className:"text-2xs font-mono text-text-2",children:mse(O.cron)})]}),O.nextRunAt&&e.jsxs("span",{className:"text-2xs font-mono text-text-3",children:["Next: ",$t(O.nextRunAt)]}),O.lastRunAt&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-2xs font-mono text-text-3",children:["Last: ",$t(O.lastRunAt)]}),e.jsx(Gt,{status:j==="error"?"crashed":j==="running"?"running":"completed",size:"sm"})]}),!O.lastRunAt&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Never run"})]}),(S.length>0||((W=O.outputConfig)==null?void 0:W.filePath)||((ee=O.outputConfig)==null?void 0:ee.customInstructions))&&e.jsxs("div",{className:"px-4 py-1.5 border-t border-border-subtle bg-surface-0 space-y-1",children:[S.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Gateways:"}),e.jsx("span",{className:"text-2xs font-sans text-text-3",children:S.join(", ")})]}),((K=O.outputConfig)==null?void 0:K.filePath)&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"File:"}),e.jsx("span",{className:"text-2xs font-mono text-text-3 truncate",children:O.outputConfig.filePath})]}),((_=O.outputConfig)==null?void 0:_.customInstructions)&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Custom:"}),e.jsxs("span",{className:"text-2xs font-sans text-text-3 truncate",children:[O.outputConfig.customInstructions.slice(0,80),O.outputConfig.customInstructions.length>80?"...":""]})]})]}),N.length>0&&e.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle bg-surface-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx(Gt,{status:"running",size:"sm"}),e.jsx("span",{className:"text-2xs font-sans text-text-2 font-medium",children:"Running"})]}),e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:N.map(E=>e.jsxs("button",{onClick:()=>P(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:[e.jsx(Gt,{status:E.status,size:"sm"}),e.jsx("span",{className:"text-2xs font-sans text-text-1 group-hover:text-text-0",children:E.name||E.role}),e.jsx(Ws,{size:9,className:"text-text-4 group-hover:text-accent"})]},E.id))})]}),!O.isRunning&&U.length>0&&e.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle bg-surface-0",children:[e.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:e.jsx("span",{className:"text-2xs font-sans text-text-3",children:"Last run agents"})}),e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:U.map(E=>e.jsxs("button",{onClick:()=>P(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:[e.jsx(Gt,{status:E.status,size:"sm"}),e.jsx("span",{className:"text-2xs font-sans text-text-2 group-hover:text-text-0",children:E.name||E.role}),e.jsx(Ws,{size:9,className:"text-text-4 group-hover:text-accent"})]},E.id))})]}),e.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle flex items-center gap-3",children:[e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>r(O.id),className:"h-6 px-2 text-2xs gap-1",children:[e.jsx(Za,{size:10})," Run Now"]}),e.jsx("div",{className:"flex-1"}),O.lastRunDuration!=null&&e.jsx("span",{className:"text-2xs font-mono text-text-4",children:Xo(O.lastRunDuration/1e3)}),O.lastRunCost!=null&&O.lastRunCost>0&&e.jsx("span",{className:"text-2xs font-mono text-text-4",children:er(O.lastRunCost)})]})]})}function Ex({title:t,icon:s,defaultOpen:n=!1,badge:a,children:r,className:l}){const[c,A]=p.useState(n);return e.jsxs("div",{className:Z("border-t border-border-subtle",l),children:[e.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:[e.jsx(Tt,{size:12,className:Z("text-text-4 transition-transform duration-200 flex-shrink-0",c&&"rotate-90")}),s&&e.jsx(s,{size:13,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:t}),a&&e.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1.5 py-0.5 rounded",children:a})]}),c&&e.jsx("div",{className:"px-5 pb-4",children:r})]})}const bse=[{id:"solo",label:"Solo Agent",icon:XS,description:"Single agent for focused tasks"},{id:"dev",label:"Dev Team",icon:vR,description:"Frontend + Backend + QC"},{id:"business",label:"Business Team",icon:V$,description:"CMO + CFO + Analyst"},{id:"custom",label:"Custom",icon:oc,description:"Build your own team"}],Iv=[{role:"frontend",phase:1},{role:"backend",phase:1},{role:"fullstack",phase:2}],zv=[{role:"CMO",phase:1},{role:"CFO",phase:1},{role:"analyst",phase:2}],FQ=["chat","planner","backend","frontend","fullstack","testing","devops","docs","security","database","cmo","cfo","ea","support","analyst","creative","slides","ambassador"],vse={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 Sf(t){return vse[t]||t}const yse=/\[read\]\s*#[\w/.-]+/g;function wse(t){return t?[...t.matchAll(yse)].map(s=>s[0]):[]}function D4({text:t}){const s=wse(t);return s.length===0?null:e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap px-1",children:s.map((n,a)=>e.jsx("span",{className:"text-2xs font-mono text-teal-400",children:n},a))})}const jse=[{value:"min",label:"minutes"},{value:"hour",label:"hours"},{value:"day",label:"days"},{value:"week",label:"weeks"}],Xg={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 ib(t,s){const n=parseInt(t,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 Qse(t,s){const n=parseInt(t,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 Nse(t){if(!t)return null;const s=t.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 $Q(t,s){return t.length===s.length&&t.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 Sse(t){var g,O,b,v,y,S,j,N,C,U,P,T,B,F;let s="custom",n="planner",a=[{role:"fullstack",phase:1}];t.agentConfig&&!t.teamConfig?(s="solo",n=t.agentConfig.role||"planner"):t.teamConfig&&($Q(Iv,t.teamConfig)?s="dev":$Q(zv,t.teamConfig)?s="business":a=t.teamConfig.map(M=>({role:M.role,phase:M.phase||1})));const r=((g=Mv.find(M=>M.cron===t.cron))==null?void 0:g.cron)||null;let l="preset",c=1,A="hour";if(!r){const M=Nse(t.cron);M&&(l="simple",c=M.count,A=M.unit)}let f=((O=t.agentConfig)==null?void 0:O.provider)||((v=(b=t.teamConfig)==null?void 0:b[0])==null?void 0:v.provider)||"",x=((y=t.agentConfig)==null?void 0:y.model)||((j=(S=t.teamConfig)==null?void 0:S[0])==null?void 0:j.model)||"",h="";if(f==="local"&&(x!=null&&x.startsWith("runtime:"))){const M=x.split(":");h=M[1],x=M.slice(2).join(":")}return{name:t.name||"",description:t.description||"",teamType:s,soloRole:n,customRoles:a,provider:f,model:x==="auto"?"":x,runtimeId:h,instructionMode:((N=t.instructionSource)==null?void 0:N.type)==="file"?"file":"write",instructions:((C=t.instructionSource)==null?void 0:C.type)==="inline"&&t.instructionSource.content||"",filePath:((U=t.instructionSource)==null?void 0:U.type)==="file"&&t.instructionSource.filePath||"",cronPreset:r,scheduleMode:l,scheduleCount:c,scheduleUnit:A,enabledOnCreate:t.enabled!==!1,gatewayIds:((P=t.outputConfig)==null?void 0:P.gatewayIds)||[],notifyOn:((T=t.outputConfig)==null?void 0:T.notifyOn)||"complete",integrationIds:t.integrationIds||[],outputFilePath:((B=t.outputConfig)==null?void 0:B.filePath)||"",outputCustom:((F=t.outputConfig)==null?void 0:F.customInstructions)||""}}function Cse(){const t=k(R=>R.automationWizardOpen),s=k(R=>R.closeAutomationWizard),n=k(R=>R.createAutomation),a=k(R=>R.updateAutomation),r=k(R=>R.editingAutomationId),l=k(R=>R.automations),c=k(R=>R.availableGateways),A=k(R=>R.availableIntegrations),f=k(R=>R.fetchGateways),x=k(R=>R.fetchInstalledIntegrations),h=!!r,[g,O]=p.useState(1),[b,v]=p.useState(Xg),[y,S]=p.useState([]),[j,N]=p.useState([]),C=k(R=>R.labRuntimes),U=k(R=>R.fetchLabRuntimes);p.useEffect(()=>{if(t){if(O(1),r){const R=l.find(Y=>Y.id===r);v(R?Sse(R):Xg)}else v(Xg);f(),x(),U(),G.get("/providers").then(R=>{var ee;const Y=Array.isArray(R)?R:R.providers||[];S(Y);const W=Y.find(K=>K.id==="local");(ee=W==null?void 0:W.models)!=null&&ee.length&&N(W.models)}).catch(()=>S([])),G.get("/providers/ollama/models").then(R=>{const Y=R.installed||[],W=R.catalog||[];(Y.length||W.length)&&N(ee=>{const K=new Set(ee.map(E=>E.id)),_=[...ee];for(const E of Y)K.has(E.id)||(_.push(E),K.add(E.id));for(const E of W)K.has(E.id)||_.push({id:E.id,name:E.name||E.id});return _})}).catch(()=>{})}},[t]);function P(R){v(Y=>({...Y,...R}))}function T(){return b.cronPreset?b.cronPreset:ib(b.scheduleCount,b.scheduleUnit)}function B(){let R=b.provider||void 0,Y=b.model||void 0;switch(R==="local"&&b.runtimeId&&Y&&(Y=`runtime:${b.runtimeId}:${Y}`),b.teamType){case"solo":return{agentConfig:{role:b.soloRole,provider:R,model:Y}};case"dev":return{teamConfig:Iv.map(W=>({...W,provider:R,model:Y}))};case"business":return{teamConfig:zv.map(W=>({...W,provider:R,model:Y}))};case"custom":return{teamConfig:b.customRoles.filter(W=>W.role).map(W=>({...W,provider:R,model:Y}))};default:return{}}}function F(){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 R=ib(b.scheduleCount,b.scheduleUnit);return R&&gse(R).valid}case 4:return!0;default:return!1}}function M(){const R=T(),Y={name:b.name.trim(),description:b.description.trim()||void 0,cron:R,...B(),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,Y),s()):n(Y)}return e.jsx(Vt,{open:t,onOpenChange:R=>!R&&s(),children:e.jsxs(Kt,{title:h?"Edit Automation":"New Automation",description:h?"Update this automation":"Create a scheduled automation",className:"max-w-xl",children:[e.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(R=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:Z("w-2 h-2 rounded-full transition-colors",R===g?"bg-accent":R<g?"bg-accent/40":"bg-surface-5")}),R<4&&e.jsx("div",{className:Z("w-6 h-px",R<g?"bg-accent/40":"bg-surface-5")})]},R))}),e.jsxs("div",{className:"px-5 py-4 min-h-[300px]",children:[g===1&&e.jsx(Bse,{form:b,update:P,providers:y,labRuntimes:C||[],localModels:j}),g===2&&e.jsx(kse,{form:b,update:P}),g===3&&e.jsx(Tse,{form:b,update:P}),g===4&&e.jsx(Use,{form:b,update:P,gateways:c,integrations:A})]}),e.jsxs("div",{className:"px-5 py-3 border-t border-border-subtle flex items-center justify-between",children:[e.jsx("div",{children:g>1&&e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>O(g-1),className:"gap-1",children:[e.jsx(Di,{size:12})," Back"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{variant:"ghost",size:"sm",onClick:s,children:"Cancel"}),g<4?e.jsxs(pe,{variant:"primary",size:"sm",disabled:!F(),onClick:()=>O(g+1),className:"gap-1",children:["Next ",e.jsx(Tt,{size:12})]}):e.jsx(pe,{variant:"primary",size:"sm",disabled:!F(),onClick:M,children:h?"Save":"Create"})]})]})]})})}const RQ={ollama:"Ollama",vllm:"vLLM","llama-cpp":"llama.cpp",mlx:"MLX",tgi:"TGI","openai-compatible":"OpenAI Compatible"};function Bse({form:t,update:s,providers:n,labRuntimes:a,localModels:r}){const l=t.provider==="local",c=n.find(x=>x.id===t.provider),A=l?r||[]:(c==null?void 0:c.models)||[],f=l?a.find(x=>x.id===t.runtimeId):null;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(rs,{label:"Name",placeholder:"Morning briefing",value:t.name,onChange:x=>s({name:x.target.value})}),e.jsx(rs,{label:"Description (optional)",placeholder:"Check email, calendar, and write a daily summary",value:t.description,onChange:x=>s({description:x.target.value})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Team Type"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:bse.map(x=>e.jsxs("button",{onClick:()=>s({teamType:x.id}),className:Z("flex items-center gap-3 p-3 rounded-md border text-left transition-colors cursor-pointer",t.teamType===x.id?"border-accent bg-accent/5":"border-border-subtle bg-surface-0 hover:border-border hover:bg-surface-2"),children:[e.jsx(x.icon,{size:16,className:Z(t.teamType===x.id?"text-accent":"text-text-3")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans",children:x.label}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:x.description})]})]},x.id))})]}),t.teamType==="solo"&&e.jsxs(Rn,{value:t.soloRole,onValueChange:x=>s({soloRole:x}),children:[e.jsx(Mn,{placeholder:"Select role"}),e.jsx(In,{children:FQ.map(x=>e.jsx(ms,{value:x,children:Sf(x)},x))})]}),t.teamType==="dev"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Roles"}),Iv.map((x,h)=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md bg-surface-0 border border-border-subtle",children:[e.jsx(Te,{variant:"default",className:"text-2xs",children:Sf(x.role)}),e.jsx("div",{className:"flex-1"}),e.jsxs("span",{className:"text-2xs font-mono text-text-4",children:["Phase ",x.phase]})]},h))]}),t.teamType==="business"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Roles"}),zv.map((x,h)=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md bg-surface-0 border border-border-subtle",children:[e.jsx(Te,{variant:"default",className:"text-2xs",children:Sf(x.role)}),e.jsx("div",{className:"flex-1"}),e.jsxs("span",{className:"text-2xs font-mono text-text-4",children:["Phase ",x.phase]})]},h))]}),t.teamType==="custom"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Roles"}),t.customRoles.map((x,h)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Rn,{value:x.role,onValueChange:g=>MQ(t,s,h,{role:g}),children:[e.jsx(Mn,{placeholder:"Role",className:"flex-1"}),e.jsx(In,{children:FQ.map(g=>e.jsx(ms,{value:g,children:Sf(g)},g))})]}),e.jsxs("button",{onClick:()=>MQ(t,s,h,{phase:x.phase===1?2:1}),className:Z("h-8 px-2.5 rounded-md text-2xs font-mono border transition-colors cursor-pointer",x.phase===1?"border-accent/30 text-accent bg-accent/5":"border-border text-text-3 bg-surface-0"),children:["P",x.phase]}),e.jsx("button",{onClick:()=>{const g=t.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:e.jsx(qe,{size:12})})]},h)),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>s({customRoles:[...t.customRoles,{role:"fullstack",phase:1}]}),className:"gap-1 text-2xs",children:[e.jsx(it,{size:10})," Add Role"]})]}),t.teamType&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Provider & Model"}),e.jsxs("div",{className:Z("grid gap-3",l?"grid-cols-3":"grid-cols-2"),children:[e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:t.provider,onChange:x=>s({provider:x.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:[e.jsx("option",{value:"",children:"Auto"}),n.filter(x=>x.authType!=="local").map(x=>e.jsxs("option",{value:x.id,disabled:x.authType==="api-key"?!(x.installed&&x.hasKey):!x.installed,children:[x.name,x.installed?x.authType==="api-key"&&!x.hasKey?" (No API key)":"":" (Not installed)"]},x.id)),e.jsx("option",{value:"local",children:"Local Model"})]}),e.jsx(xt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:t.model,onChange:x=>s({model:x.target.value}),disabled:!t.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:[e.jsx("option",{value:"",children:"Auto"}),A.map(x=>e.jsx("option",{value:x.id,children:x.name||x.id},x.id))]}),e.jsx(xt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),l&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:t.runtimeId,onChange:x=>s({runtimeId:x.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:[e.jsx("option",{value:"",children:"Select runtime"}),a.map(x=>e.jsxs("option",{value:x.id,children:[x.name||RQ[x.type]||x.type,x.status==="connected"?"":" (offline)"]},x.id))]}),e.jsx(xt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),l&&e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-md bg-warning/8 border border-warning/20",children:[e.jsx(Aa,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("span",{className:"text-2xs font-sans text-text-2",children:["Make sure your runtime",f?` (${f.name||RQ[f.type]||f.type})`:""," is running when this automation fires."]})]}),l&&a.length===0&&e.jsx("div",{className:"flex items-start gap-2 px-3 py-2 rounded-md bg-surface-4 border border-border-subtle",children:e.jsx("span",{className:"text-2xs font-sans text-text-3",children:"No runtimes configured. Set one up in the Model Lab tab first."})})]})]})}function MQ(t,s,n,a){s({customRoles:t.customRoles.map((r,l)=>l===n?{...r,...a}:r)})}function kse({form:t,update:s}){const[n,a]=p.useState(!1);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>s({instructionMode:"write"}),className:Z("px-3 py-1.5 text-xs font-sans rounded-md transition-colors cursor-pointer",t.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"}),e.jsx("button",{onClick:()=>s({instructionMode:"file"}),className:Z("px-3 py-1.5 text-xs font-sans rounded-md transition-colors cursor-pointer",t.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"})]}),t.instructionMode==="write"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Rv,{mono:!0,value:t.instructions,onChange:r=>s({instructions:r.target.value}),placeholder:`Describe what this team should do...
|