groove-dev 0.10.8 → 0.10.9

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@groove-dev/cli",
3
- "version": "0.10.8",
3
+ "version": "0.10.9",
4
4
  "description": "GROOVE CLI — manage AI coding agents from your terminal",
5
5
  "license": "FSL-1.1-Apache-2.0",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@groove-dev/daemon",
3
- "version": "0.10.8",
3
+ "version": "0.10.9",
4
4
  "description": "GROOVE daemon — agent orchestration engine",
5
5
  "license": "FSL-1.1-Apache-2.0",
6
6
  "type": "module",
@@ -70,4 +70,4 @@ Error generating stack: `+i.message+`
70
70
  `)),x=m.reduce((p,b)=>p.concat(...b),[]);return[m,x]}return[[],[]]},[n]);return X.useEffect(()=>{const g=(a==null?void 0:a.target)??Fm,m=(a==null?void 0:a.actInsideInputWithModifier)??!0;if(n!==null){const x=S=>{var C,T;if(u.current=S.ctrlKey||S.metaKey||S.shiftKey||S.altKey,(!u.current||u.current&&!m)&&sp(S))return!1;const M=Pm(S.code,h);if(f.current.add(S[M]),Im(d,f.current,!1)){const N=((T=(C=S.composedPath)==null?void 0:C.call(S))==null?void 0:T[0])||S.target,_=(N==null?void 0:N.nodeName)==="BUTTON"||(N==null?void 0:N.nodeName)==="A";a.preventDefault!==!1&&(u.current||!_)&&S.preventDefault(),r(!0)}},p=S=>{const w=Pm(S.code,h);Im(d,f.current,!0)?(r(!1),f.current.clear()):f.current.delete(S[w]),S.key==="Meta"&&f.current.clear(),u.current=!1},b=()=>{f.current.clear(),r(!1)};return g==null||g.addEventListener("keydown",x),g==null||g.addEventListener("keyup",p),window.addEventListener("blur",b),window.addEventListener("contextmenu",b),()=>{g==null||g.removeEventListener("keydown",x),g==null||g.removeEventListener("keyup",p),window.removeEventListener("blur",b),window.removeEventListener("contextmenu",b)}}},[n,r]),o}function Im(n,a,o){return n.filter(r=>o||r.length===a.size).some(r=>r.every(u=>a.has(u)))}function Pm(n,a){return a.includes(n)?"code":"key"}const RE=()=>{const n=Wt();return X.useMemo(()=>({zoomIn:a=>{const{panZoom:o}=n.getState();return o?o.scaleBy(1.2,a):Promise.resolve(!1)},zoomOut:a=>{const{panZoom:o}=n.getState();return o?o.scaleBy(1/1.2,a):Promise.resolve(!1)},zoomTo:(a,o)=>{const{panZoom:r}=n.getState();return r?r.scaleTo(a,o):Promise.resolve(!1)},getZoom:()=>n.getState().transform[2],setViewport:async(a,o)=>{const{transform:[r,u,f],panZoom:d}=n.getState();return d?(await d.setViewport({x:a.x??r,y:a.y??u,zoom:a.zoom??f},o),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[a,o,r]=n.getState().transform;return{x:a,y:o,zoom:r}},setCenter:async(a,o,r)=>n.getState().setCenter(a,o,r),fitBounds:async(a,o)=>{const{width:r,height:u,minZoom:f,maxZoom:d,panZoom:h}=n.getState(),g=id(a,r,u,f,d,(o==null?void 0:o.padding)??.1);return h?(await h.setViewport(g,{duration:o==null?void 0:o.duration,ease:o==null?void 0:o.ease,interpolate:o==null?void 0:o.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(a,o={})=>{const{transform:r,snapGrid:u,snapToGrid:f,domNode:d}=n.getState();if(!d)return a;const{x:h,y:g}=d.getBoundingClientRect(),m={x:a.x-h,y:a.y-g},x=o.snapGrid??u,p=o.snapToGrid??f;return Lo(m,r,p,x)},flowToScreenPosition:a=>{const{transform:o,domNode:r}=n.getState();if(!r)return a;const{x:u,y:f}=r.getBoundingClientRect(),d=Hs(a,o);return{x:d.x+u,y:d.y+f}}}),[])};function jp(n,a){const o=[],r=new Map,u=[];for(const f of n)if(f.type==="add"){u.push(f);continue}else if(f.type==="remove"||f.type==="replace")r.set(f.id,[f]);else{const d=r.get(f.id);d?d.push(f):r.set(f.id,[f])}for(const f of a){const d=r.get(f.id);if(!d){o.push(f);continue}if(d[0].type==="remove")continue;if(d[0].type==="replace"){o.push({...d[0].item});continue}const h={...f};for(const g of d)OE(g,h);o.push(h)}return u.length&&u.forEach(f=>{f.index!==void 0?o.splice(f.index,0,{...f.item}):o.push({...f.item})}),o}function OE(n,a){switch(n.type){case"select":{a.selected=n.selected;break}case"position":{typeof n.position<"u"&&(a.position=n.position),typeof n.dragging<"u"&&(a.dragging=n.dragging);break}case"dimensions":{typeof n.dimensions<"u"&&(a.measured={...n.dimensions},n.setAttributes&&((n.setAttributes===!0||n.setAttributes==="width")&&(a.width=n.dimensions.width),(n.setAttributes===!0||n.setAttributes==="height")&&(a.height=n.dimensions.height))),typeof n.resizing=="boolean"&&(a.resizing=n.resizing);break}}}function HE(n,a){return jp(n,a)}function BE(n,a){return jp(n,a)}function ii(n,a){return{id:n,type:"select",selected:a}}function aa(n,a=new Set,o=!1){const r=[];for(const[u,f]of n){const d=a.has(u);!(f.selected===void 0&&!d)&&f.selected!==d&&(o&&(f.selected=d),r.push(ii(f.id,d)))}return r}function ty({items:n=[],lookup:a}){var u;const o=[],r=new Map(n.map(f=>[f.id,f]));for(const[f,d]of n.entries()){const h=a.get(d.id),g=((u=h==null?void 0:h.internals)==null?void 0:u.userNode)??h;g!==void 0&&g!==d&&o.push({id:d.id,item:d,type:"replace"}),g===void 0&&o.push({item:d,type:"add",index:f})}for(const[f]of a)r.get(f)===void 0&&o.push({id:f,type:"remove"});return o}function ey(n){return{id:n.id,type:"remove"}}const ny=n=>iw(n),LE=n=>tp(n);function Np(n){return X.forwardRef(n)}function ly(n){const[a,o]=X.useState(BigInt(0)),[r]=X.useState(()=>UE(()=>o(u=>u+BigInt(1))));return Zf(()=>{const u=r.get();u.length&&(n(u),r.reset())},[a]),r}function UE(n){let a=[];return{get:()=>a,reset:()=>{a=[]},push:o=>{a.push(o),n()}}}const Dp=X.createContext(null);function kE({children:n}){const a=Wt(),o=X.useCallback(h=>{const{nodes:g=[],setNodes:m,hasDefaultNodes:x,onNodesChange:p,nodeLookup:b,fitViewQueued:S,onNodesChangeMiddlewareMap:w}=a.getState();let M=g;for(const T of h)M=typeof T=="function"?T(M):T;let C=ty({items:M,lookup:b});for(const T of w.values())C=T(C);x&&m(M),C.length>0?p==null||p(C):S&&window.requestAnimationFrame(()=>{const{fitViewQueued:T,nodes:N,setNodes:_}=a.getState();T&&_(N)})},[]),r=ly(o),u=X.useCallback(h=>{const{edges:g=[],setEdges:m,hasDefaultEdges:x,onEdgesChange:p,edgeLookup:b}=a.getState();let S=g;for(const w of h)S=typeof w=="function"?w(S):w;x?m(S):p&&p(ty({items:S,lookup:b}))},[]),f=ly(u),d=X.useMemo(()=>({nodeQueue:r,edgeQueue:f}),[]);return y.jsx(Dp.Provider,{value:d,children:n})}function YE(){const n=X.useContext(Dp);if(!n)throw new Error("useBatchContext must be used within a BatchProvider");return n}const qE=n=>!!n.panZoom;function Zs(){const n=RE(),a=Wt(),o=YE(),r=Rt(qE),u=X.useMemo(()=>{const f=p=>a.getState().nodeLookup.get(p),d=p=>{o.nodeQueue.push(p)},h=p=>{o.edgeQueue.push(p)},g=p=>{var T,N;const{nodeLookup:b,nodeOrigin:S}=a.getState(),w=ny(p)?p:b.get(p.id),M=w.parentId?op(w.position,w.measured,w.parentId,b,S):w.position,C={...w,position:M,width:((T=w.measured)==null?void 0:T.width)??w.width,height:((N=w.measured)==null?void 0:N.height)??w.height};return ha(C)},m=(p,b,S={replace:!1})=>{d(w=>w.map(M=>{if(M.id===p){const C=typeof b=="function"?b(M):b;return S.replace&&ny(C)?C:{...M,...C}}return M}))},x=(p,b,S={replace:!1})=>{h(w=>w.map(M=>{if(M.id===p){const C=typeof b=="function"?b(M):b;return S.replace&&LE(C)?C:{...M,...C}}return M}))};return{getNodes:()=>a.getState().nodes.map(p=>({...p})),getNode:p=>{var b;return(b=f(p))==null?void 0:b.internals.userNode},getInternalNode:f,getEdges:()=>{const{edges:p=[]}=a.getState();return p.map(b=>({...b}))},getEdge:p=>a.getState().edgeLookup.get(p),setNodes:d,setEdges:h,addNodes:p=>{const b=Array.isArray(p)?p:[p];o.nodeQueue.push(S=>[...S,...b])},addEdges:p=>{const b=Array.isArray(p)?p:[p];o.edgeQueue.push(S=>[...S,...b])},toObject:()=>{const{nodes:p=[],edges:b=[],transform:S}=a.getState(),[w,M,C]=S;return{nodes:p.map(T=>({...T})),edges:b.map(T=>({...T})),viewport:{x:w,y:M,zoom:C}}},deleteElements:async({nodes:p=[],edges:b=[]})=>{const{nodes:S,edges:w,onNodesDelete:M,onEdgesDelete:C,triggerNodeChanges:T,triggerEdgeChanges:N,onDelete:_,onBeforeDelete:j}=a.getState(),{nodes:V,edges:D}=await uw({nodesToRemove:p,edgesToRemove:b,nodes:S,edges:w,onBeforeDelete:j}),B=D.length>0,Q=V.length>0;if(B){const J=D.map(ey);C==null||C(D),N(J)}if(Q){const J=V.map(ey);M==null||M(V),T(J)}return(Q||B)&&(_==null||_({nodes:V,edges:D})),{deletedNodes:V,deletedEdges:D}},getIntersectingNodes:(p,b=!0,S)=>{const w=Mm(p),M=w?p:g(p),C=S!==void 0;return M?(S||a.getState().nodes).filter(T=>{const N=a.getState().nodeLookup.get(T.id);if(N&&!w&&(T.id===p.id||!N.internals.positionAbsolute))return!1;const _=ha(C?T:N),j=Mo(_,M);return b&&j>0||j>=_.width*_.height||j>=M.width*M.height}):[]},isNodeIntersecting:(p,b,S=!0)=>{const M=Mm(p)?p:g(p);if(!M)return!1;const C=Mo(M,b);return S&&C>0||C>=b.width*b.height||C>=M.width*M.height},updateNode:m,updateNodeData:(p,b,S={replace:!1})=>{m(p,w=>{const M=typeof b=="function"?b(w):b;return S.replace?{...w,data:M}:{...w,data:{...w.data,...M}}},S)},updateEdge:x,updateEdgeData:(p,b,S={replace:!1})=>{x(p,w=>{const M=typeof b=="function"?b(w):b;return S.replace?{...w,data:M}:{...w,data:{...w.data,...M}}},S)},getNodesBounds:p=>{const{nodeLookup:b,nodeOrigin:S}=a.getState();return aw(p,{nodeLookup:b,nodeOrigin:S})},getHandleConnections:({type:p,id:b,nodeId:S})=>{var w;return Array.from(((w=a.getState().connectionLookup.get(`${S}-${p}${b?`-${b}`:""}`))==null?void 0:w.values())??[])},getNodeConnections:({type:p,handleId:b,nodeId:S})=>{var w;return Array.from(((w=a.getState().connectionLookup.get(`${S}${p?b?`-${p}-${b}`:`-${p}`:""}`))==null?void 0:w.values())??[])},fitView:async p=>{const b=a.getState().fitViewResolver??hw();return a.setState({fitViewQueued:!0,fitViewOptions:p,fitViewResolver:b}),o.nodeQueue.push(S=>[...S]),b.promise}}},[]);return X.useMemo(()=>({...u,...n,viewportInitialized:r}),[r])}const iy=n=>n.selected,VE=typeof window<"u"?window:void 0;function XE({deleteKeyCode:n,multiSelectionKeyCode:a}){const o=Wt(),{deleteElements:r}=Zs(),u=jo(n,{actInsideInputWithModifier:!1}),f=jo(a,{target:VE});X.useEffect(()=>{if(u){const{edges:d,nodes:h}=o.getState();r({nodes:h.filter(iy),edges:d.filter(iy)}),o.setState({nodesSelectionActive:!1})}},[u]),X.useEffect(()=>{o.setState({multiSelectionActive:f})},[f])}function GE(n){const a=Wt();X.useEffect(()=>{const o=()=>{var u,f,d,h;if(!n.current||!(((f=(u=n.current).checkVisibility)==null?void 0:f.call(u))??!0))return!1;const r=ad(n.current);(r.height===0||r.width===0)&&((h=(d=a.getState()).onError)==null||h.call(d,"004",Sn.error004())),a.setState({width:r.width||500,height:r.height||500})};if(n.current){o(),window.addEventListener("resize",o);const r=new ResizeObserver(()=>o());return r.observe(n.current),()=>{window.removeEventListener("resize",o),r&&n.current&&r.unobserve(n.current)}}},[])}const Ks={position:"absolute",width:"100%",height:"100%",top:0,left:0},$E=n=>({userSelectionActive:n.userSelectionActive,lib:n.lib,connectionInProgress:n.connection.inProgress});function QE({onPaneContextMenu:n,zoomOnScroll:a=!0,zoomOnPinch:o=!0,panOnScroll:r=!1,panOnScrollSpeed:u=.5,panOnScrollMode:f=si.Free,zoomOnDoubleClick:d=!0,panOnDrag:h=!0,defaultViewport:g,translateExtent:m,minZoom:x,maxZoom:p,zoomActivationKeyCode:b,preventScrolling:S=!0,children:w,noWheelClassName:M,noPanClassName:C,onViewportChange:T,isControlledViewport:N,paneClickDistance:_,selectionOnDrag:j}){const V=Wt(),D=X.useRef(null),{userSelectionActive:B,lib:Q,connectionInProgress:J}=Rt($E,Jt),at=jo(b),$=X.useRef();GE(D);const I=X.useCallback(K=>{T==null||T({x:K[0],y:K[1],zoom:K[2]}),N||V.setState({transform:K})},[T,N]);return X.useEffect(()=>{if(D.current){$.current=Ww({domNode:D.current,minZoom:x,maxZoom:p,translateExtent:m,viewport:g,onDraggingChange:z=>V.setState(L=>L.paneDragging===z?L:{paneDragging:z}),onPanZoomStart:(z,L)=>{const{onViewportChangeStart:k,onMoveStart:q}=V.getState();q==null||q(z,L),k==null||k(L)},onPanZoom:(z,L)=>{const{onViewportChange:k,onMove:q}=V.getState();q==null||q(z,L),k==null||k(L)},onPanZoomEnd:(z,L)=>{const{onViewportChangeEnd:k,onMoveEnd:q}=V.getState();q==null||q(z,L),k==null||k(L)}});const{x:K,y:R,zoom:Z}=$.current.getViewport();return V.setState({panZoom:$.current,transform:[K,R,Z],domNode:D.current.closest(".react-flow")}),()=>{var z;(z=$.current)==null||z.destroy()}}},[]),X.useEffect(()=>{var K;(K=$.current)==null||K.update({onPaneContextMenu:n,zoomOnScroll:a,zoomOnPinch:o,panOnScroll:r,panOnScrollSpeed:u,panOnScrollMode:f,zoomOnDoubleClick:d,panOnDrag:h,zoomActivationKeyPressed:at,preventScrolling:S,noPanClassName:C,userSelectionActive:B,noWheelClassName:M,lib:Q,onTransformChange:I,connectionInProgress:J,selectionOnDrag:j,paneClickDistance:_})},[n,a,o,r,u,f,d,h,at,S,C,B,M,Q,I,J,j,_]),y.jsx("div",{className:"react-flow__renderer",ref:D,style:Ks,children:w})}const ZE=n=>({userSelectionActive:n.userSelectionActive,userSelectionRect:n.userSelectionRect});function KE(){const{userSelectionActive:n,userSelectionRect:a}=Rt(ZE,Jt);return n&&a?y.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:a.width,height:a.height,transform:`translate(${a.x}px, ${a.y}px)`}}):null}const Nf=(n,a)=>o=>{o.target===a.current&&(n==null||n(o))},JE=n=>({userSelectionActive:n.userSelectionActive,elementsSelectable:n.elementsSelectable,connectionInProgress:n.connection.inProgress,dragging:n.paneDragging});function WE({isSelecting:n,selectionKeyPressed:a,selectionMode:o=zo.Full,panOnDrag:r,paneClickDistance:u,selectionOnDrag:f,onSelectionStart:d,onSelectionEnd:h,onPaneClick:g,onPaneContextMenu:m,onPaneScroll:x,onPaneMouseEnter:p,onPaneMouseMove:b,onPaneMouseLeave:S,children:w}){const M=Wt(),{userSelectionActive:C,elementsSelectable:T,dragging:N,connectionInProgress:_}=Rt(JE,Jt),j=T&&(n||C),V=X.useRef(null),D=X.useRef(),B=X.useRef(new Set),Q=X.useRef(new Set),J=X.useRef(!1),at=k=>{if(J.current||_){J.current=!1;return}g==null||g(k),M.getState().resetSelectedElements(),M.setState({nodesSelectionActive:!1})},$=k=>{if(Array.isArray(r)&&(r!=null&&r.includes(2))){k.preventDefault();return}m==null||m(k)},I=x?k=>x(k):void 0,K=k=>{J.current&&(k.stopPropagation(),J.current=!1)},R=k=>{var rt,ut;const{domNode:q}=M.getState();if(D.current=q==null?void 0:q.getBoundingClientRect(),!D.current)return;const tt=k.target===V.current;if(!tt&&!!k.target.closest(".nokey")||!n||!(f&&tt||a)||k.button!==0||!k.isPrimary)return;(ut=(rt=k.target)==null?void 0:rt.setPointerCapture)==null||ut.call(rt,k.pointerId),J.current=!1;const{x:U,y:nt}=fn(k.nativeEvent,D.current);M.setState({userSelectionRect:{width:0,height:0,startX:U,startY:nt,x:U,y:nt}}),tt||(k.stopPropagation(),k.preventDefault())},Z=k=>{const{userSelectionRect:q,transform:tt,nodeLookup:A,edgeLookup:H,connectionLookup:U,triggerNodeChanges:nt,triggerEdgeChanges:rt,defaultEdgeOptions:ut,resetSelectedElements:ct}=M.getState();if(!D.current||!q)return;const{x:st,y:ft}=fn(k.nativeEvent,D.current),{startX:St,startY:xt}=q;if(!J.current){const Ct=a?0:u;if(Math.hypot(st-St,ft-xt)<=Ct)return;ct(),d==null||d(k)}J.current=!0;const pt={startX:St,startY:xt,x:st<St?st:St,y:ft<xt?ft:xt,width:Math.abs(st-St),height:Math.abs(ft-xt)},yt=B.current,Tt=Q.current;B.current=new Set(ld(A,pt,tt,o===zo.Partial,!0).map(Ct=>Ct.id)),Q.current=new Set;const Ut=(ut==null?void 0:ut.selectable)??!0;for(const Ct of B.current){const de=U.get(Ct);if(de)for(const{edgeId:tn}of de.values()){const Be=H.get(tn);Be&&(Be.selectable??Ut)&&Q.current.add(tn)}}if(!Cm(yt,B.current)){const Ct=aa(A,B.current,!0);nt(Ct)}if(!Cm(Tt,Q.current)){const Ct=aa(H,Q.current);rt(Ct)}M.setState({userSelectionRect:pt,userSelectionActive:!0,nodesSelectionActive:!1})},z=k=>{var q,tt;k.button===0&&((tt=(q=k.target)==null?void 0:q.releasePointerCapture)==null||tt.call(q,k.pointerId),!C&&k.target===V.current&&M.getState().userSelectionRect&&(at==null||at(k)),M.setState({userSelectionActive:!1,userSelectionRect:null}),J.current&&(h==null||h(k),M.setState({nodesSelectionActive:B.current.size>0})))},L=r===!0||Array.isArray(r)&&r.includes(0);return y.jsxs("div",{className:se(["react-flow__pane",{draggable:L,dragging:N,selection:n}]),onClick:j?void 0:Nf(at,V),onContextMenu:Nf($,V),onWheel:Nf(I,V),onPointerEnter:j?void 0:p,onPointerMove:j?Z:b,onPointerUp:j?z:void 0,onPointerDownCapture:j?R:void 0,onClickCapture:j?K:void 0,onPointerLeave:S,ref:V,style:Ks,children:[w,y.jsx(KE,{})]})}function Kf({id:n,store:a,unselect:o=!1,nodeRef:r}){const{addSelectedNodes:u,unselectNodesAndEdges:f,multiSelectionActive:d,nodeLookup:h,onError:g}=a.getState(),m=h.get(n);if(!m){g==null||g("012",Sn.error012(n));return}a.setState({nodesSelectionActive:!1}),m.selected?(o||m.selected&&d)&&(f({nodes:[m],edges:[]}),requestAnimationFrame(()=>{var x;return(x=r==null?void 0:r.current)==null?void 0:x.blur()})):u([n])}function Rp({nodeRef:n,disabled:a=!1,noDragClassName:o,handleSelector:r,nodeId:u,isSelectable:f,nodeClickDistance:d}){const h=Wt(),[g,m]=X.useState(!1),x=X.useRef();return X.useEffect(()=>{x.current=Bw({getStoreItems:()=>h.getState(),onNodeMouseDown:p=>{Kf({id:p,store:h,nodeRef:n})},onDragStart:()=>{m(!0)},onDragStop:()=>{m(!1)}})},[]),X.useEffect(()=>{if(!(a||!n.current||!x.current))return x.current.update({noDragClassName:o,handleSelector:r,domNode:n.current,isSelectable:f,nodeId:u,nodeClickDistance:d}),()=>{var p;(p=x.current)==null||p.destroy()}},[o,r,a,f,n,u,d]),g}const FE=n=>a=>a.selected&&(a.draggable||n&&typeof a.draggable>"u");function Op(){const n=Wt();return X.useCallback(o=>{const{nodeExtent:r,snapToGrid:u,snapGrid:f,nodesDraggable:d,onError:h,updateNodePositions:g,nodeLookup:m,nodeOrigin:x}=n.getState(),p=new Map,b=FE(d),S=u?f[0]:5,w=u?f[1]:5,M=o.direction.x*S*o.factor,C=o.direction.y*w*o.factor;for(const[,T]of m){if(!b(T))continue;let N={x:T.internals.positionAbsolute.x+M,y:T.internals.positionAbsolute.y+C};u&&(N=Bo(N,f));const{position:_,positionAbsolute:j}=ep({nodeId:T.id,nextPosition:N,nodeLookup:m,nodeExtent:r,nodeOrigin:x,onError:h});T.position=_,T.internals.positionAbsolute=j,p.set(T.id,T)}g(p)},[])}const fd=X.createContext(null),IE=fd.Provider;fd.Consumer;const Hp=()=>X.useContext(fd),PE=n=>({connectOnClick:n.connectOnClick,noPanClassName:n.noPanClassName,rfId:n.rfId}),t_=(n,a,o)=>r=>{const{connectionClickStartHandle:u,connectionMode:f,connection:d}=r,{fromHandle:h,toHandle:g,isValid:m}=d,x=(g==null?void 0:g.nodeId)===n&&(g==null?void 0:g.id)===a&&(g==null?void 0:g.type)===o;return{connectingFrom:(h==null?void 0:h.nodeId)===n&&(h==null?void 0:h.id)===a&&(h==null?void 0:h.type)===o,connectingTo:x,clickConnecting:(u==null?void 0:u.nodeId)===n&&(u==null?void 0:u.id)===a&&(u==null?void 0:u.type)===o,isPossibleEndHandle:f===fa.Strict?(h==null?void 0:h.type)!==o:n!==(h==null?void 0:h.nodeId)||a!==(h==null?void 0:h.id),connectionInProcess:!!h,clickConnectionInProcess:!!u,valid:x&&m}};function e_({type:n="source",position:a=gt.Top,isValidConnection:o,isConnectable:r=!0,isConnectableStart:u=!0,isConnectableEnd:f=!0,id:d,onConnect:h,children:g,className:m,onMouseDown:x,onTouchStart:p,...b},S){var Z,z;const w=d||null,M=n==="target",C=Wt(),T=Hp(),{connectOnClick:N,noPanClassName:_,rfId:j}=Rt(PE,Jt),{connectingFrom:V,connectingTo:D,clickConnecting:B,isPossibleEndHandle:Q,connectionInProcess:J,clickConnectionInProcess:at,valid:$}=Rt(t_(T,w,n),Jt);T||(z=(Z=C.getState()).onError)==null||z.call(Z,"010",Sn.error010());const I=L=>{const{defaultEdgeOptions:k,onConnect:q,hasDefaultEdges:tt}=C.getState(),A={...k,...L};if(tt){const{edges:H,setEdges:U}=C.getState();U(bw(A,H))}q==null||q(A),h==null||h(A)},K=L=>{if(!T)return;const k=up(L.nativeEvent);if(u&&(k&&L.button===0||!k)){const q=C.getState();Qf.onPointerDown(L.nativeEvent,{handleDomNode:L.currentTarget,autoPanOnConnect:q.autoPanOnConnect,connectionMode:q.connectionMode,connectionRadius:q.connectionRadius,domNode:q.domNode,nodeLookup:q.nodeLookup,lib:q.lib,isTarget:M,handleId:w,nodeId:T,flowId:q.rfId,panBy:q.panBy,cancelConnection:q.cancelConnection,onConnectStart:q.onConnectStart,onConnectEnd:(...tt)=>{var A,H;return(H=(A=C.getState()).onConnectEnd)==null?void 0:H.call(A,...tt)},updateConnection:q.updateConnection,onConnect:I,isValidConnection:o||((...tt)=>{var A,H;return((H=(A=C.getState()).isValidConnection)==null?void 0:H.call(A,...tt))??!0}),getTransform:()=>C.getState().transform,getFromHandle:()=>C.getState().connection.fromHandle,autoPanSpeed:q.autoPanSpeed,dragThreshold:q.connectionDragThreshold})}k?x==null||x(L):p==null||p(L)},R=L=>{const{onClickConnectStart:k,onClickConnectEnd:q,connectionClickStartHandle:tt,connectionMode:A,isValidConnection:H,lib:U,rfId:nt,nodeLookup:rt,connection:ut}=C.getState();if(!T||!tt&&!u)return;if(!tt){k==null||k(L.nativeEvent,{nodeId:T,handleId:w,handleType:n}),C.setState({connectionClickStartHandle:{nodeId:T,type:n,id:w}});return}const ct=rp(L.target),st=o||H,{connection:ft,isValid:St}=Qf.isValid(L.nativeEvent,{handle:{nodeId:T,id:w,type:n},connectionMode:A,fromNodeId:tt.nodeId,fromHandleId:tt.id||null,fromType:tt.type,isValidConnection:st,flowId:nt,doc:ct,lib:U,nodeLookup:rt});St&&ft&&I(ft);const xt=structuredClone(ut);delete xt.inProgress,xt.toPosition=xt.toHandle?xt.toHandle.position:null,q==null||q(L,xt),C.setState({connectionClickStartHandle:null})};return y.jsx("div",{"data-handleid":w,"data-nodeid":T,"data-handlepos":a,"data-id":`${j}-${T}-${w}-${n}`,className:se(["react-flow__handle",`react-flow__handle-${a}`,"nodrag",_,m,{source:!M,target:M,connectable:r,connectablestart:u,connectableend:f,clickconnecting:B,connectingfrom:V,connectingto:D,valid:$,connectionindicator:r&&(!J||Q)&&(J||at?f:u)}]),onMouseDown:K,onTouchStart:K,onClick:N?R:void 0,ref:S,...b,children:g})}const ya=X.memo(Np(e_));function n_({data:n,isConnectable:a,sourcePosition:o=gt.Bottom}){return y.jsxs(y.Fragment,{children:[n==null?void 0:n.label,y.jsx(ya,{type:"source",position:o,isConnectable:a})]})}function l_({data:n,isConnectable:a,targetPosition:o=gt.Top,sourcePosition:r=gt.Bottom}){return y.jsxs(y.Fragment,{children:[y.jsx(ya,{type:"target",position:o,isConnectable:a}),n==null?void 0:n.label,y.jsx(ya,{type:"source",position:r,isConnectable:a})]})}function i_(){return null}function a_({data:n,isConnectable:a,targetPosition:o=gt.Top}){return y.jsxs(y.Fragment,{children:[y.jsx(ya,{type:"target",position:o,isConnectable:a}),n==null?void 0:n.label]})}const Bs={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},ay={input:n_,default:l_,output:a_,group:i_};function o_(n){var a,o,r,u;return n.internals.handleBounds===void 0?{width:n.width??n.initialWidth??((a=n.style)==null?void 0:a.width),height:n.height??n.initialHeight??((o=n.style)==null?void 0:o.height)}:{width:n.width??((r=n.style)==null?void 0:r.width),height:n.height??((u=n.style)==null?void 0:u.height)}}const r_=n=>{const{width:a,height:o,x:r,y:u}=Ho(n.nodeLookup,{filter:f=>!!f.selected});return{width:cn(a)?a:null,height:cn(o)?o:null,userSelectionActive:n.userSelectionActive,transformString:`translate(${n.transform[0]}px,${n.transform[1]}px) scale(${n.transform[2]}) translate(${r}px,${u}px)`}};function s_({onSelectionContextMenu:n,noPanClassName:a,disableKeyboardA11y:o}){const r=Wt(),{width:u,height:f,transformString:d,userSelectionActive:h}=Rt(r_,Jt),g=Op(),m=X.useRef(null);X.useEffect(()=>{var S;o||(S=m.current)==null||S.focus({preventScroll:!0})},[o]);const x=!h&&u!==null&&f!==null;if(Rp({nodeRef:m,disabled:!x}),!x)return null;const p=n?S=>{const w=r.getState().nodes.filter(M=>M.selected);n(S,w)}:void 0,b=S=>{Object.prototype.hasOwnProperty.call(Bs,S.key)&&(S.preventDefault(),g({direction:Bs[S.key],factor:S.shiftKey?4:1}))};return y.jsx("div",{className:se(["react-flow__nodesselection","react-flow__container",a]),style:{transform:d},children:y.jsx("div",{ref:m,className:"react-flow__nodesselection-rect",onContextMenu:p,tabIndex:o?void 0:-1,onKeyDown:o?void 0:b,style:{width:u,height:f}})})}const oy=typeof window<"u"?window:void 0,u_=n=>({nodesSelectionActive:n.nodesSelectionActive,userSelectionActive:n.userSelectionActive});function Bp({children:n,onPaneClick:a,onPaneMouseEnter:o,onPaneMouseMove:r,onPaneMouseLeave:u,onPaneContextMenu:f,onPaneScroll:d,paneClickDistance:h,deleteKeyCode:g,selectionKeyCode:m,selectionOnDrag:x,selectionMode:p,onSelectionStart:b,onSelectionEnd:S,multiSelectionKeyCode:w,panActivationKeyCode:M,zoomActivationKeyCode:C,elementsSelectable:T,zoomOnScroll:N,zoomOnPinch:_,panOnScroll:j,panOnScrollSpeed:V,panOnScrollMode:D,zoomOnDoubleClick:B,panOnDrag:Q,defaultViewport:J,translateExtent:at,minZoom:$,maxZoom:I,preventScrolling:K,onSelectionContextMenu:R,noWheelClassName:Z,noPanClassName:z,disableKeyboardA11y:L,onViewportChange:k,isControlledViewport:q}){const{nodesSelectionActive:tt,userSelectionActive:A}=Rt(u_,Jt),H=jo(m,{target:oy}),U=jo(M,{target:oy}),nt=U||Q,rt=U||j,ut=x&&nt!==!0,ct=H||A||ut;return XE({deleteKeyCode:g,multiSelectionKeyCode:w}),y.jsx(QE,{onPaneContextMenu:f,elementsSelectable:T,zoomOnScroll:N,zoomOnPinch:_,panOnScroll:rt,panOnScrollSpeed:V,panOnScrollMode:D,zoomOnDoubleClick:B,panOnDrag:!H&&nt,defaultViewport:J,translateExtent:at,minZoom:$,maxZoom:I,zoomActivationKeyCode:C,preventScrolling:K,noWheelClassName:Z,noPanClassName:z,onViewportChange:k,isControlledViewport:q,paneClickDistance:h,selectionOnDrag:ut,children:y.jsxs(WE,{onSelectionStart:b,onSelectionEnd:S,onPaneClick:a,onPaneMouseEnter:o,onPaneMouseMove:r,onPaneMouseLeave:u,onPaneContextMenu:f,onPaneScroll:d,panOnDrag:nt,isSelecting:!!ct,selectionMode:p,selectionKeyPressed:H,paneClickDistance:h,selectionOnDrag:ut,children:[n,tt&&y.jsx(s_,{onSelectionContextMenu:R,noPanClassName:z,disableKeyboardA11y:L})]})})}Bp.displayName="FlowRenderer";const c_=X.memo(Bp),f_=n=>a=>n?ld(a.nodeLookup,{x:0,y:0,width:a.width,height:a.height},a.transform,!0).map(o=>o.id):Array.from(a.nodeLookup.keys());function d_(n){return Rt(X.useCallback(f_(n),[n]),Jt)}const h_=n=>n.updateNodeInternals;function g_(){const n=Rt(h_),[a]=X.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(o=>{const r=new Map;o.forEach(u=>{const f=u.target.getAttribute("data-id");r.set(f,{id:f,nodeElement:u.target,force:!0})}),n(r)}));return X.useEffect(()=>()=>{a==null||a.disconnect()},[a]),a}function m_({node:n,nodeType:a,hasDimensions:o,resizeObserver:r}){const u=Wt(),f=X.useRef(null),d=X.useRef(null),h=X.useRef(n.sourcePosition),g=X.useRef(n.targetPosition),m=X.useRef(a),x=o&&!!n.internals.handleBounds;return X.useEffect(()=>{f.current&&!n.hidden&&(!x||d.current!==f.current)&&(d.current&&(r==null||r.unobserve(d.current)),r==null||r.observe(f.current),d.current=f.current)},[x,n.hidden]),X.useEffect(()=>()=>{d.current&&(r==null||r.unobserve(d.current),d.current=null)},[]),X.useEffect(()=>{if(f.current){const p=m.current!==a,b=h.current!==n.sourcePosition,S=g.current!==n.targetPosition;(p||b||S)&&(m.current=a,h.current=n.sourcePosition,g.current=n.targetPosition,u.getState().updateNodeInternals(new Map([[n.id,{id:n.id,nodeElement:f.current,force:!0}]])))}},[n.id,a,n.sourcePosition,n.targetPosition]),f}function y_({id:n,onClick:a,onMouseEnter:o,onMouseMove:r,onMouseLeave:u,onContextMenu:f,onDoubleClick:d,nodesDraggable:h,elementsSelectable:g,nodesConnectable:m,nodesFocusable:x,resizeObserver:p,noDragClassName:b,noPanClassName:S,disableKeyboardA11y:w,rfId:M,nodeTypes:C,nodeClickDistance:T,onError:N}){const{node:_,internals:j,isParent:V}=Rt(st=>{const ft=st.nodeLookup.get(n),St=st.parentLookup.has(n);return{node:ft,internals:ft.internals,isParent:St}},Jt);let D=_.type||"default",B=(C==null?void 0:C[D])||ay[D];B===void 0&&(N==null||N("003",Sn.error003(D)),D="default",B=(C==null?void 0:C.default)||ay.default);const Q=!!(_.draggable||h&&typeof _.draggable>"u"),J=!!(_.selectable||g&&typeof _.selectable>"u"),at=!!(_.connectable||m&&typeof _.connectable>"u"),$=!!(_.focusable||x&&typeof _.focusable>"u"),I=Wt(),K=ap(_),R=m_({node:_,nodeType:D,hasDimensions:K,resizeObserver:p}),Z=Rp({nodeRef:R,disabled:_.hidden||!Q,noDragClassName:b,handleSelector:_.dragHandle,nodeId:n,isSelectable:J,nodeClickDistance:T}),z=Op();if(_.hidden)return null;const L=Jn(_),k=o_(_),q=J||Q||a||o||r||u,tt=o?st=>o(st,{...j.userNode}):void 0,A=r?st=>r(st,{...j.userNode}):void 0,H=u?st=>u(st,{...j.userNode}):void 0,U=f?st=>f(st,{...j.userNode}):void 0,nt=d?st=>d(st,{...j.userNode}):void 0,rt=st=>{const{selectNodesOnDrag:ft,nodeDragThreshold:St}=I.getState();J&&(!ft||!Q||St>0)&&Kf({id:n,store:I,nodeRef:R}),a&&a(st,{...j.userNode})},ut=st=>{if(!(sp(st.nativeEvent)||w)){if(Wy.includes(st.key)&&J){const ft=st.key==="Escape";Kf({id:n,store:I,unselect:ft,nodeRef:R})}else if(Q&&_.selected&&Object.prototype.hasOwnProperty.call(Bs,st.key)){st.preventDefault();const{ariaLabelConfig:ft}=I.getState();I.setState({ariaLiveMessage:ft["node.a11yDescription.ariaLiveMessage"]({direction:st.key.replace("Arrow","").toLowerCase(),x:~~j.positionAbsolute.x,y:~~j.positionAbsolute.y})}),z({direction:Bs[st.key],factor:st.shiftKey?4:1})}}},ct=()=>{var Tt;if(w||!((Tt=R.current)!=null&&Tt.matches(":focus-visible")))return;const{transform:st,width:ft,height:St,autoPanOnNodeFocus:xt,setCenter:pt}=I.getState();if(!xt)return;ld(new Map([[n,_]]),{x:0,y:0,width:ft,height:St},st,!0).length>0||pt(_.position.x+L.width/2,_.position.y+L.height/2,{zoom:st[2]})};return y.jsx("div",{className:se(["react-flow__node",`react-flow__node-${D}`,{[S]:Q},_.className,{selected:_.selected,selectable:J,parent:V,draggable:Q,dragging:Z}]),ref:R,style:{zIndex:j.z,transform:`translate(${j.positionAbsolute.x}px,${j.positionAbsolute.y}px)`,pointerEvents:q?"all":"none",visibility:K?"visible":"hidden",..._.style,...k},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:tt,onMouseMove:A,onMouseLeave:H,onContextMenu:U,onClick:rt,onDoubleClick:nt,onKeyDown:$?ut:void 0,tabIndex:$?0:void 0,onFocus:$?ct:void 0,role:_.ariaRole??($?"group":void 0),"aria-roledescription":"node","aria-describedby":w?void 0:`${zp}-${M}`,"aria-label":_.ariaLabel,..._.domAttributes,children:y.jsx(IE,{value:n,children:y.jsx(B,{id:n,data:_.data,type:D,positionAbsoluteX:j.positionAbsolute.x,positionAbsoluteY:j.positionAbsolute.y,selected:_.selected??!1,selectable:J,draggable:Q,deletable:_.deletable??!0,isConnectable:at,sourcePosition:_.sourcePosition,targetPosition:_.targetPosition,dragging:Z,dragHandle:_.dragHandle,zIndex:j.z,parentId:_.parentId,...L})})})}var p_=X.memo(y_);const v_=n=>({nodesDraggable:n.nodesDraggable,nodesConnectable:n.nodesConnectable,nodesFocusable:n.nodesFocusable,elementsSelectable:n.elementsSelectable,onError:n.onError});function Lp(n){const{nodesDraggable:a,nodesConnectable:o,nodesFocusable:r,elementsSelectable:u,onError:f}=Rt(v_,Jt),d=d_(n.onlyRenderVisibleElements),h=g_();return y.jsx("div",{className:"react-flow__nodes",style:Ks,children:d.map(g=>y.jsx(p_,{id:g,nodeTypes:n.nodeTypes,nodeExtent:n.nodeExtent,onClick:n.onNodeClick,onMouseEnter:n.onNodeMouseEnter,onMouseMove:n.onNodeMouseMove,onMouseLeave:n.onNodeMouseLeave,onContextMenu:n.onNodeContextMenu,onDoubleClick:n.onNodeDoubleClick,noDragClassName:n.noDragClassName,noPanClassName:n.noPanClassName,rfId:n.rfId,disableKeyboardA11y:n.disableKeyboardA11y,resizeObserver:h,nodesDraggable:a,nodesConnectable:o,nodesFocusable:r,elementsSelectable:u,nodeClickDistance:n.nodeClickDistance,onError:f},g))})}Lp.displayName="NodeRenderer";const x_=X.memo(Lp);function b_(n){return Rt(X.useCallback(o=>{if(!n)return o.edges.map(u=>u.id);const r=[];if(o.width&&o.height)for(const u of o.edges){const f=o.nodeLookup.get(u.source),d=o.nodeLookup.get(u.target);f&&d&&pw({sourceNode:f,targetNode:d,width:o.width,height:o.height,transform:o.transform})&&r.push(u.id)}return r},[n]),Jt)}const S_=({color:n="none",strokeWidth:a=1})=>{const o={strokeWidth:a,...n&&{stroke:n}};return y.jsx("polyline",{className:"arrow",style:o,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},w_=({color:n="none",strokeWidth:a=1})=>{const o={strokeWidth:a,...n&&{stroke:n,fill:n}};return y.jsx("polyline",{className:"arrowclosed",style:o,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},ry={[Rs.Arrow]:S_,[Rs.ArrowClosed]:w_};function E_(n){const a=Wt();return X.useMemo(()=>{var u,f;return Object.prototype.hasOwnProperty.call(ry,n)?ry[n]:((f=(u=a.getState()).onError)==null||f.call(u,"009",Sn.error009(n)),null)},[n])}const __=({id:n,type:a,color:o,width:r=12.5,height:u=12.5,markerUnits:f="strokeWidth",strokeWidth:d,orient:h="auto-start-reverse"})=>{const g=E_(a);return g?y.jsx("marker",{className:"react-flow__arrowhead",id:n,markerWidth:`${r}`,markerHeight:`${u}`,viewBox:"-10 -10 20 20",markerUnits:f,orient:h,refX:"0",refY:"0",children:y.jsx(g,{color:o,strokeWidth:d})}):null},Up=({defaultColor:n,rfId:a})=>{const o=Rt(f=>f.edges),r=Rt(f=>f.defaultEdgeOptions),u=X.useMemo(()=>Tw(o,{id:a,defaultColor:n,defaultMarkerStart:r==null?void 0:r.markerStart,defaultMarkerEnd:r==null?void 0:r.markerEnd}),[o,r,a,n]);return u.length?y.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:y.jsx("defs",{children:u.map(f=>y.jsx(__,{id:f.id,type:f.type,color:f.color,width:f.width,height:f.height,markerUnits:f.markerUnits,strokeWidth:f.strokeWidth,orient:f.orient},f.id))})}):null};Up.displayName="MarkerDefinitions";var T_=X.memo(Up);function kp({x:n,y:a,label:o,labelStyle:r,labelShowBg:u=!0,labelBgStyle:f,labelBgPadding:d=[2,4],labelBgBorderRadius:h=2,children:g,className:m,...x}){const[p,b]=X.useState({x:1,y:0,width:0,height:0}),S=se(["react-flow__edge-textwrapper",m]),w=X.useRef(null);return X.useEffect(()=>{if(w.current){const M=w.current.getBBox();b({x:M.x,y:M.y,width:M.width,height:M.height})}},[o]),o?y.jsxs("g",{transform:`translate(${n-p.width/2} ${a-p.height/2})`,className:S,visibility:p.width?"visible":"hidden",...x,children:[u&&y.jsx("rect",{width:p.width+2*d[0],x:-d[0],y:-d[1],height:p.height+2*d[1],className:"react-flow__edge-textbg",style:f,rx:h,ry:h}),y.jsx("text",{className:"react-flow__edge-text",y:p.height/2,dy:"0.3em",ref:w,style:r,children:o}),g]}):null}kp.displayName="EdgeText";const A_=X.memo(kp);function Js({path:n,labelX:a,labelY:o,label:r,labelStyle:u,labelShowBg:f,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:g,interactionWidth:m=20,...x}){return y.jsxs(y.Fragment,{children:[y.jsx("path",{...x,d:n,fill:"none",className:se(["react-flow__edge-path",x.className])}),m?y.jsx("path",{d:n,fill:"none",strokeOpacity:0,strokeWidth:m,className:"react-flow__edge-interaction"}):null,r&&cn(a)&&cn(o)?y.jsx(A_,{x:a,y:o,label:r,labelStyle:u,labelShowBg:f,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:g}):null]})}function sy({pos:n,x1:a,y1:o,x2:r,y2:u}){return n===gt.Left||n===gt.Right?[.5*(a+r),o]:[a,.5*(o+u)]}function Yp({sourceX:n,sourceY:a,sourcePosition:o=gt.Bottom,targetX:r,targetY:u,targetPosition:f=gt.Top}){const[d,h]=sy({pos:o,x1:n,y1:a,x2:r,y2:u}),[g,m]=sy({pos:f,x1:r,y1:u,x2:n,y2:a}),[x,p,b,S]=cp({sourceX:n,sourceY:a,targetX:r,targetY:u,sourceControlX:d,sourceControlY:h,targetControlX:g,targetControlY:m});return[`M${n},${a} C${d},${h} ${g},${m} ${r},${u}`,x,p,b,S]}function qp(n){return X.memo(({id:a,sourceX:o,sourceY:r,targetX:u,targetY:f,sourcePosition:d,targetPosition:h,label:g,labelStyle:m,labelShowBg:x,labelBgStyle:p,labelBgPadding:b,labelBgBorderRadius:S,style:w,markerEnd:M,markerStart:C,interactionWidth:T})=>{const[N,_,j]=Yp({sourceX:o,sourceY:r,sourcePosition:d,targetX:u,targetY:f,targetPosition:h}),V=n.isInternal?void 0:a;return y.jsx(Js,{id:V,path:N,labelX:_,labelY:j,label:g,labelStyle:m,labelShowBg:x,labelBgStyle:p,labelBgPadding:b,labelBgBorderRadius:S,style:w,markerEnd:M,markerStart:C,interactionWidth:T})})}const z_=qp({isInternal:!1}),Vp=qp({isInternal:!0});z_.displayName="SimpleBezierEdge";Vp.displayName="SimpleBezierEdgeInternal";function Xp(n){return X.memo(({id:a,sourceX:o,sourceY:r,targetX:u,targetY:f,label:d,labelStyle:h,labelShowBg:g,labelBgStyle:m,labelBgPadding:x,labelBgBorderRadius:p,style:b,sourcePosition:S=gt.Bottom,targetPosition:w=gt.Top,markerEnd:M,markerStart:C,pathOptions:T,interactionWidth:N})=>{const[_,j,V]=Xf({sourceX:o,sourceY:r,sourcePosition:S,targetX:u,targetY:f,targetPosition:w,borderRadius:T==null?void 0:T.borderRadius,offset:T==null?void 0:T.offset,stepPosition:T==null?void 0:T.stepPosition}),D=n.isInternal?void 0:a;return y.jsx(Js,{id:D,path:_,labelX:j,labelY:V,label:d,labelStyle:h,labelShowBg:g,labelBgStyle:m,labelBgPadding:x,labelBgBorderRadius:p,style:b,markerEnd:M,markerStart:C,interactionWidth:N})})}const Gp=Xp({isInternal:!1}),$p=Xp({isInternal:!0});Gp.displayName="SmoothStepEdge";$p.displayName="SmoothStepEdgeInternal";function Qp(n){return X.memo(({id:a,...o})=>{var u;const r=n.isInternal?void 0:a;return y.jsx(Gp,{...o,id:r,pathOptions:X.useMemo(()=>{var f;return{borderRadius:0,offset:(f=o.pathOptions)==null?void 0:f.offset}},[(u=o.pathOptions)==null?void 0:u.offset])})})}const M_=Qp({isInternal:!1}),Zp=Qp({isInternal:!0});M_.displayName="StepEdge";Zp.displayName="StepEdgeInternal";function Kp(n){return X.memo(({id:a,sourceX:o,sourceY:r,targetX:u,targetY:f,label:d,labelStyle:h,labelShowBg:g,labelBgStyle:m,labelBgPadding:x,labelBgBorderRadius:p,style:b,markerEnd:S,markerStart:w,interactionWidth:M})=>{const[C,T,N]=hp({sourceX:o,sourceY:r,targetX:u,targetY:f}),_=n.isInternal?void 0:a;return y.jsx(Js,{id:_,path:C,labelX:T,labelY:N,label:d,labelStyle:h,labelShowBg:g,labelBgStyle:m,labelBgPadding:x,labelBgBorderRadius:p,style:b,markerEnd:S,markerStart:w,interactionWidth:M})})}const C_=Kp({isInternal:!1}),Jp=Kp({isInternal:!0});C_.displayName="StraightEdge";Jp.displayName="StraightEdgeInternal";function Wp(n){return X.memo(({id:a,sourceX:o,sourceY:r,targetX:u,targetY:f,sourcePosition:d=gt.Bottom,targetPosition:h=gt.Top,label:g,labelStyle:m,labelShowBg:x,labelBgStyle:p,labelBgPadding:b,labelBgBorderRadius:S,style:w,markerEnd:M,markerStart:C,pathOptions:T,interactionWidth:N})=>{const[_,j,V]=fp({sourceX:o,sourceY:r,sourcePosition:d,targetX:u,targetY:f,targetPosition:h,curvature:T==null?void 0:T.curvature}),D=n.isInternal?void 0:a;return y.jsx(Js,{id:D,path:_,labelX:j,labelY:V,label:g,labelStyle:m,labelShowBg:x,labelBgStyle:p,labelBgPadding:b,labelBgBorderRadius:S,style:w,markerEnd:M,markerStart:C,interactionWidth:N})})}const j_=Wp({isInternal:!1}),Fp=Wp({isInternal:!0});j_.displayName="BezierEdge";Fp.displayName="BezierEdgeInternal";const uy={default:Fp,straight:Jp,step:Zp,smoothstep:$p,simplebezier:Vp},cy={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},N_=(n,a,o)=>o===gt.Left?n-a:o===gt.Right?n+a:n,D_=(n,a,o)=>o===gt.Top?n-a:o===gt.Bottom?n+a:n,fy="react-flow__edgeupdater";function dy({position:n,centerX:a,centerY:o,radius:r=10,onMouseDown:u,onMouseEnter:f,onMouseOut:d,type:h}){return y.jsx("circle",{onMouseDown:u,onMouseEnter:f,onMouseOut:d,className:se([fy,`${fy}-${h}`]),cx:N_(a,r,n),cy:D_(o,r,n),r,stroke:"transparent",fill:"transparent"})}function R_({isReconnectable:n,reconnectRadius:a,edge:o,sourceX:r,sourceY:u,targetX:f,targetY:d,sourcePosition:h,targetPosition:g,onReconnect:m,onReconnectStart:x,onReconnectEnd:p,setReconnecting:b,setUpdateHover:S}){const w=Wt(),M=(j,V)=>{if(j.button!==0)return;const{autoPanOnConnect:D,domNode:B,connectionMode:Q,connectionRadius:J,lib:at,onConnectStart:$,cancelConnection:I,nodeLookup:K,rfId:R,panBy:Z,updateConnection:z}=w.getState(),L=V.type==="target",k=(A,H)=>{b(!1),p==null||p(A,o,V.type,H)},q=A=>m==null?void 0:m(o,A),tt=(A,H)=>{b(!0),x==null||x(j,o,V.type),$==null||$(A,H)};Qf.onPointerDown(j.nativeEvent,{autoPanOnConnect:D,connectionMode:Q,connectionRadius:J,domNode:B,handleId:V.id,nodeId:V.nodeId,nodeLookup:K,isTarget:L,edgeUpdaterType:V.type,lib:at,flowId:R,cancelConnection:I,panBy:Z,isValidConnection:(...A)=>{var H,U;return((U=(H=w.getState()).isValidConnection)==null?void 0:U.call(H,...A))??!0},onConnect:q,onConnectStart:tt,onConnectEnd:(...A)=>{var H,U;return(U=(H=w.getState()).onConnectEnd)==null?void 0:U.call(H,...A)},onReconnectEnd:k,updateConnection:z,getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,dragThreshold:w.getState().connectionDragThreshold,handleDomNode:j.currentTarget})},C=j=>M(j,{nodeId:o.target,id:o.targetHandle??null,type:"target"}),T=j=>M(j,{nodeId:o.source,id:o.sourceHandle??null,type:"source"}),N=()=>S(!0),_=()=>S(!1);return y.jsxs(y.Fragment,{children:[(n===!0||n==="source")&&y.jsx(dy,{position:h,centerX:r,centerY:u,radius:a,onMouseDown:C,onMouseEnter:N,onMouseOut:_,type:"source"}),(n===!0||n==="target")&&y.jsx(dy,{position:g,centerX:f,centerY:d,radius:a,onMouseDown:T,onMouseEnter:N,onMouseOut:_,type:"target"})]})}function O_({id:n,edgesFocusable:a,edgesReconnectable:o,elementsSelectable:r,onClick:u,onDoubleClick:f,onContextMenu:d,onMouseEnter:h,onMouseMove:g,onMouseLeave:m,reconnectRadius:x,onReconnect:p,onReconnectStart:b,onReconnectEnd:S,rfId:w,edgeTypes:M,noPanClassName:C,onError:T,disableKeyboardA11y:N}){let _=Rt(pt=>pt.edgeLookup.get(n));const j=Rt(pt=>pt.defaultEdgeOptions);_=j?{...j,..._}:_;let V=_.type||"default",D=(M==null?void 0:M[V])||uy[V];D===void 0&&(T==null||T("011",Sn.error011(V)),V="default",D=(M==null?void 0:M.default)||uy.default);const B=!!(_.focusable||a&&typeof _.focusable>"u"),Q=typeof p<"u"&&(_.reconnectable||o&&typeof _.reconnectable>"u"),J=!!(_.selectable||r&&typeof _.selectable>"u"),at=X.useRef(null),[$,I]=X.useState(!1),[K,R]=X.useState(!1),Z=Wt(),{zIndex:z,sourceX:L,sourceY:k,targetX:q,targetY:tt,sourcePosition:A,targetPosition:H}=Rt(X.useCallback(pt=>{const yt=pt.nodeLookup.get(_.source),Tt=pt.nodeLookup.get(_.target);if(!yt||!Tt)return{zIndex:_.zIndex,...cy};const Ut=_w({id:n,sourceNode:yt,targetNode:Tt,sourceHandle:_.sourceHandle||null,targetHandle:_.targetHandle||null,connectionMode:pt.connectionMode,onError:T});return{zIndex:yw({selected:_.selected,zIndex:_.zIndex,sourceNode:yt,targetNode:Tt,elevateOnSelect:pt.elevateEdgesOnSelect,zIndexMode:pt.zIndexMode}),...Ut||cy}},[_.source,_.target,_.sourceHandle,_.targetHandle,_.selected,_.zIndex]),Jt),U=X.useMemo(()=>_.markerStart?`url('#${Gf(_.markerStart,w)}')`:void 0,[_.markerStart,w]),nt=X.useMemo(()=>_.markerEnd?`url('#${Gf(_.markerEnd,w)}')`:void 0,[_.markerEnd,w]);if(_.hidden||L===null||k===null||q===null||tt===null)return null;const rt=pt=>{var Ct;const{addSelectedEdges:yt,unselectNodesAndEdges:Tt,multiSelectionActive:Ut}=Z.getState();J&&(Z.setState({nodesSelectionActive:!1}),_.selected&&Ut?(Tt({nodes:[],edges:[_]}),(Ct=at.current)==null||Ct.blur()):yt([n])),u&&u(pt,_)},ut=f?pt=>{f(pt,{..._})}:void 0,ct=d?pt=>{d(pt,{..._})}:void 0,st=h?pt=>{h(pt,{..._})}:void 0,ft=g?pt=>{g(pt,{..._})}:void 0,St=m?pt=>{m(pt,{..._})}:void 0,xt=pt=>{var yt;if(!N&&Wy.includes(pt.key)&&J){const{unselectNodesAndEdges:Tt,addSelectedEdges:Ut}=Z.getState();pt.key==="Escape"?((yt=at.current)==null||yt.blur(),Tt({edges:[_]})):Ut([n])}};return y.jsx("svg",{style:{zIndex:z},children:y.jsxs("g",{className:se(["react-flow__edge",`react-flow__edge-${V}`,_.className,C,{selected:_.selected,animated:_.animated,inactive:!J&&!u,updating:$,selectable:J}]),onClick:rt,onDoubleClick:ut,onContextMenu:ct,onMouseEnter:st,onMouseMove:ft,onMouseLeave:St,onKeyDown:B?xt:void 0,tabIndex:B?0:void 0,role:_.ariaRole??(B?"group":"img"),"aria-roledescription":"edge","data-id":n,"data-testid":`rf__edge-${n}`,"aria-label":_.ariaLabel===null?void 0:_.ariaLabel||`Edge from ${_.source} to ${_.target}`,"aria-describedby":B?`${Mp}-${w}`:void 0,ref:at,..._.domAttributes,children:[!K&&y.jsx(D,{id:n,source:_.source,target:_.target,type:_.type,selected:_.selected,animated:_.animated,selectable:J,deletable:_.deletable??!0,label:_.label,labelStyle:_.labelStyle,labelShowBg:_.labelShowBg,labelBgStyle:_.labelBgStyle,labelBgPadding:_.labelBgPadding,labelBgBorderRadius:_.labelBgBorderRadius,sourceX:L,sourceY:k,targetX:q,targetY:tt,sourcePosition:A,targetPosition:H,data:_.data,style:_.style,sourceHandleId:_.sourceHandle,targetHandleId:_.targetHandle,markerStart:U,markerEnd:nt,pathOptions:"pathOptions"in _?_.pathOptions:void 0,interactionWidth:_.interactionWidth}),Q&&y.jsx(R_,{edge:_,isReconnectable:Q,reconnectRadius:x,onReconnect:p,onReconnectStart:b,onReconnectEnd:S,sourceX:L,sourceY:k,targetX:q,targetY:tt,sourcePosition:A,targetPosition:H,setUpdateHover:I,setReconnecting:R})]})})}var H_=X.memo(O_);const B_=n=>({edgesFocusable:n.edgesFocusable,edgesReconnectable:n.edgesReconnectable,elementsSelectable:n.elementsSelectable,connectionMode:n.connectionMode,onError:n.onError});function Ip({defaultMarkerColor:n,onlyRenderVisibleElements:a,rfId:o,edgeTypes:r,noPanClassName:u,onReconnect:f,onEdgeContextMenu:d,onEdgeMouseEnter:h,onEdgeMouseMove:g,onEdgeMouseLeave:m,onEdgeClick:x,reconnectRadius:p,onEdgeDoubleClick:b,onReconnectStart:S,onReconnectEnd:w,disableKeyboardA11y:M}){const{edgesFocusable:C,edgesReconnectable:T,elementsSelectable:N,onError:_}=Rt(B_,Jt),j=b_(a);return y.jsxs("div",{className:"react-flow__edges",children:[y.jsx(T_,{defaultColor:n,rfId:o}),j.map(V=>y.jsx(H_,{id:V,edgesFocusable:C,edgesReconnectable:T,elementsSelectable:N,noPanClassName:u,onReconnect:f,onContextMenu:d,onMouseEnter:h,onMouseMove:g,onMouseLeave:m,onClick:x,reconnectRadius:p,onDoubleClick:b,onReconnectStart:S,onReconnectEnd:w,rfId:o,onError:_,edgeTypes:r,disableKeyboardA11y:M},V))]})}Ip.displayName="EdgeRenderer";const L_=X.memo(Ip),U_=n=>`translate(${n.transform[0]}px,${n.transform[1]}px) scale(${n.transform[2]})`;function k_({children:n}){const a=Rt(U_);return y.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:a},children:n})}function Y_(n){const a=Zs(),o=X.useRef(!1);X.useEffect(()=>{!o.current&&a.viewportInitialized&&n&&(setTimeout(()=>n(a),1),o.current=!0)},[n,a.viewportInitialized])}const q_=n=>{var a;return(a=n.panZoom)==null?void 0:a.syncViewport};function V_(n){const a=Rt(q_),o=Wt();return X.useEffect(()=>{n&&(a==null||a(n),o.setState({transform:[n.x,n.y,n.zoom]}))},[n,a]),null}function X_(n){return n.connection.inProgress?{...n.connection,to:Lo(n.connection.to,n.transform)}:{...n.connection}}function G_(n){return X_}function $_(n){const a=G_();return Rt(a,Jt)}const Q_=n=>({nodesConnectable:n.nodesConnectable,isValid:n.connection.isValid,inProgress:n.connection.inProgress,width:n.width,height:n.height});function Z_({containerStyle:n,style:a,type:o,component:r}){const{nodesConnectable:u,width:f,height:d,isValid:h,inProgress:g}=Rt(Q_,Jt);return!(f&&u&&g)?null:y.jsx("svg",{style:n,width:f,height:d,className:"react-flow__connectionline react-flow__container",children:y.jsx("g",{className:se(["react-flow__connection",Py(h)]),children:y.jsx(Pp,{style:a,type:o,CustomComponent:r,isValid:h})})})}const Pp=({style:n,type:a=jl.Bezier,CustomComponent:o,isValid:r})=>{const{inProgress:u,from:f,fromNode:d,fromHandle:h,fromPosition:g,to:m,toNode:x,toHandle:p,toPosition:b,pointer:S}=$_();if(!u)return;if(o)return y.jsx(o,{connectionLineType:a,connectionLineStyle:n,fromNode:d,fromHandle:h,fromX:f.x,fromY:f.y,toX:m.x,toY:m.y,fromPosition:g,toPosition:b,connectionStatus:Py(r),toNode:x,toHandle:p,pointer:S});let w="";const M={sourceX:f.x,sourceY:f.y,sourcePosition:g,targetX:m.x,targetY:m.y,targetPosition:b};switch(a){case jl.Bezier:[w]=fp(M);break;case jl.SimpleBezier:[w]=Yp(M);break;case jl.Step:[w]=Xf({...M,borderRadius:0});break;case jl.SmoothStep:[w]=Xf(M);break;default:[w]=hp(M)}return y.jsx("path",{d:w,fill:"none",className:"react-flow__connection-path",style:n})};Pp.displayName="ConnectionLine";const K_={};function hy(n=K_){X.useRef(n),Wt(),X.useEffect(()=>{},[n])}function J_(){Wt(),X.useRef(!1),X.useEffect(()=>{},[])}function tv({nodeTypes:n,edgeTypes:a,onInit:o,onNodeClick:r,onEdgeClick:u,onNodeDoubleClick:f,onEdgeDoubleClick:d,onNodeMouseEnter:h,onNodeMouseMove:g,onNodeMouseLeave:m,onNodeContextMenu:x,onSelectionContextMenu:p,onSelectionStart:b,onSelectionEnd:S,connectionLineType:w,connectionLineStyle:M,connectionLineComponent:C,connectionLineContainerStyle:T,selectionKeyCode:N,selectionOnDrag:_,selectionMode:j,multiSelectionKeyCode:V,panActivationKeyCode:D,zoomActivationKeyCode:B,deleteKeyCode:Q,onlyRenderVisibleElements:J,elementsSelectable:at,defaultViewport:$,translateExtent:I,minZoom:K,maxZoom:R,preventScrolling:Z,defaultMarkerColor:z,zoomOnScroll:L,zoomOnPinch:k,panOnScroll:q,panOnScrollSpeed:tt,panOnScrollMode:A,zoomOnDoubleClick:H,panOnDrag:U,onPaneClick:nt,onPaneMouseEnter:rt,onPaneMouseMove:ut,onPaneMouseLeave:ct,onPaneScroll:st,onPaneContextMenu:ft,paneClickDistance:St,nodeClickDistance:xt,onEdgeContextMenu:pt,onEdgeMouseEnter:yt,onEdgeMouseMove:Tt,onEdgeMouseLeave:Ut,reconnectRadius:Ct,onReconnect:de,onReconnectStart:tn,onReconnectEnd:Be,noDragClassName:en,noWheelClassName:En,noPanClassName:Dl,disableKeyboardA11y:Rl,nodeExtent:ge,rfId:hi,viewport:_n,onViewportChange:Wn}){return hy(n),hy(a),J_(),Y_(o),V_(_n),y.jsx(c_,{onPaneClick:nt,onPaneMouseEnter:rt,onPaneMouseMove:ut,onPaneMouseLeave:ct,onPaneContextMenu:ft,onPaneScroll:st,paneClickDistance:St,deleteKeyCode:Q,selectionKeyCode:N,selectionOnDrag:_,selectionMode:j,onSelectionStart:b,onSelectionEnd:S,multiSelectionKeyCode:V,panActivationKeyCode:D,zoomActivationKeyCode:B,elementsSelectable:at,zoomOnScroll:L,zoomOnPinch:k,zoomOnDoubleClick:H,panOnScroll:q,panOnScrollSpeed:tt,panOnScrollMode:A,panOnDrag:U,defaultViewport:$,translateExtent:I,minZoom:K,maxZoom:R,onSelectionContextMenu:p,preventScrolling:Z,noDragClassName:en,noWheelClassName:En,noPanClassName:Dl,disableKeyboardA11y:Rl,onViewportChange:Wn,isControlledViewport:!!_n,children:y.jsxs(k_,{children:[y.jsx(L_,{edgeTypes:a,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:de,onReconnectStart:tn,onReconnectEnd:Be,onlyRenderVisibleElements:J,onEdgeContextMenu:pt,onEdgeMouseEnter:yt,onEdgeMouseMove:Tt,onEdgeMouseLeave:Ut,reconnectRadius:Ct,defaultMarkerColor:z,noPanClassName:Dl,disableKeyboardA11y:Rl,rfId:hi}),y.jsx(Z_,{style:M,type:w,component:C,containerStyle:T}),y.jsx("div",{className:"react-flow__edgelabel-renderer"}),y.jsx(x_,{nodeTypes:n,onNodeClick:r,onNodeDoubleClick:f,onNodeMouseEnter:h,onNodeMouseMove:g,onNodeMouseLeave:m,onNodeContextMenu:x,nodeClickDistance:xt,onlyRenderVisibleElements:J,noPanClassName:Dl,noDragClassName:en,disableKeyboardA11y:Rl,nodeExtent:ge,rfId:hi}),y.jsx("div",{className:"react-flow__viewport-portal"})]})})}tv.displayName="GraphView";const W_=X.memo(tv),gy=({nodes:n,edges:a,defaultNodes:o,defaultEdges:r,width:u,height:f,fitView:d,fitViewOptions:h,minZoom:g=.5,maxZoom:m=2,nodeOrigin:x,nodeExtent:p,zIndexMode:b="basic"}={})=>{const S=new Map,w=new Map,M=new Map,C=new Map,T=r??a??[],N=o??n??[],_=x??[0,0],j=p??Ao;yp(M,C,T);const{nodesInitialized:V}=$f(N,S,w,{nodeOrigin:_,nodeExtent:j,zIndexMode:b});let D=[0,0,1];if(d&&u&&f){const B=Ho(S,{filter:$=>!!(($.width||$.initialWidth)&&($.height||$.initialHeight))}),{x:Q,y:J,zoom:at}=id(B,u,f,g,m,(h==null?void 0:h.padding)??.1);D=[Q,J,at]}return{rfId:"1",width:u??0,height:f??0,transform:D,nodes:N,nodesInitialized:V,nodeLookup:S,parentLookup:w,edges:T,edgeLookup:C,connectionLookup:M,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:o!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:g,maxZoom:m,translateExtent:Ao,nodeExtent:j,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:fa.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:_,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:d??!1,fitViewOptions:h,fitViewResolver:null,connection:{...Iy},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:cw,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:Fy,zIndexMode:b,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},F_=({nodes:n,edges:a,defaultNodes:o,defaultEdges:r,width:u,height:f,fitView:d,fitViewOptions:h,minZoom:g,maxZoom:m,nodeOrigin:x,nodeExtent:p,zIndexMode:b})=>gE((S,w)=>{async function M(){const{nodeLookup:C,panZoom:T,fitViewOptions:N,fitViewResolver:_,width:j,height:V,minZoom:D,maxZoom:B}=w();T&&(await sw({nodes:C,width:j,height:V,panZoom:T,minZoom:D,maxZoom:B},N),_==null||_.resolve(!0),S({fitViewResolver:null}))}return{...gy({nodes:n,edges:a,width:u,height:f,fitView:d,fitViewOptions:h,minZoom:g,maxZoom:m,nodeOrigin:x,nodeExtent:p,defaultNodes:o,defaultEdges:r,zIndexMode:b}),setNodes:C=>{const{nodeLookup:T,parentLookup:N,nodeOrigin:_,elevateNodesOnSelect:j,fitViewQueued:V,zIndexMode:D,nodesSelectionActive:B}=w(),{nodesInitialized:Q,hasSelectedNodes:J}=$f(C,T,N,{nodeOrigin:_,nodeExtent:p,elevateNodesOnSelect:j,checkEquality:!0,zIndexMode:D}),at=B&&J;V&&Q?(M(),S({nodes:C,nodesInitialized:Q,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:at})):S({nodes:C,nodesInitialized:Q,nodesSelectionActive:at})},setEdges:C=>{const{connectionLookup:T,edgeLookup:N}=w();yp(T,N,C),S({edges:C})},setDefaultNodesAndEdges:(C,T)=>{if(C){const{setNodes:N}=w();N(C),S({hasDefaultNodes:!0})}if(T){const{setEdges:N}=w();N(T),S({hasDefaultEdges:!0})}},updateNodeInternals:C=>{const{triggerNodeChanges:T,nodeLookup:N,parentLookup:_,domNode:j,nodeOrigin:V,nodeExtent:D,debug:B,fitViewQueued:Q,zIndexMode:J}=w(),{changes:at,updatedInternals:$}=Dw(C,N,_,j,V,D,J);$&&(Mw(N,_,{nodeOrigin:V,nodeExtent:D,zIndexMode:J}),Q?(M(),S({fitViewQueued:!1,fitViewOptions:void 0})):S({}),(at==null?void 0:at.length)>0&&(B&&console.log("React Flow: trigger node changes",at),T==null||T(at)))},updateNodePositions:(C,T=!1)=>{const N=[];let _=[];const{nodeLookup:j,triggerNodeChanges:V,connection:D,updateConnection:B,onNodesChangeMiddlewareMap:Q}=w();for(const[J,at]of C){const $=j.get(J),I=!!($!=null&&$.expandParent&&($!=null&&$.parentId)&&(at!=null&&at.position)),K={id:J,type:"position",position:I?{x:Math.max(0,at.position.x),y:Math.max(0,at.position.y)}:at.position,dragging:T};if($&&D.inProgress&&D.fromNode.id===$.id){const R=di($,D.fromHandle,gt.Left,!0);B({...D,from:R})}I&&$.parentId&&N.push({id:J,parentId:$.parentId,rect:{...at.internals.positionAbsolute,width:at.measured.width??0,height:at.measured.height??0}}),_.push(K)}if(N.length>0){const{parentLookup:J,nodeOrigin:at}=w(),$=cd(N,j,J,at);_.push(...$)}for(const J of Q.values())_=J(_);V(_)},triggerNodeChanges:C=>{const{onNodesChange:T,setNodes:N,nodes:_,hasDefaultNodes:j,debug:V}=w();if(C!=null&&C.length){if(j){const D=HE(C,_);N(D)}V&&console.log("React Flow: trigger node changes",C),T==null||T(C)}},triggerEdgeChanges:C=>{const{onEdgesChange:T,setEdges:N,edges:_,hasDefaultEdges:j,debug:V}=w();if(C!=null&&C.length){if(j){const D=BE(C,_);N(D)}V&&console.log("React Flow: trigger edge changes",C),T==null||T(C)}},addSelectedNodes:C=>{const{multiSelectionActive:T,edgeLookup:N,nodeLookup:_,triggerNodeChanges:j,triggerEdgeChanges:V}=w();if(T){const D=C.map(B=>ii(B,!0));j(D);return}j(aa(_,new Set([...C]),!0)),V(aa(N))},addSelectedEdges:C=>{const{multiSelectionActive:T,edgeLookup:N,nodeLookup:_,triggerNodeChanges:j,triggerEdgeChanges:V}=w();if(T){const D=C.map(B=>ii(B,!0));V(D);return}V(aa(N,new Set([...C]))),j(aa(_,new Set,!0))},unselectNodesAndEdges:({nodes:C,edges:T}={})=>{const{edges:N,nodes:_,nodeLookup:j,triggerNodeChanges:V,triggerEdgeChanges:D}=w(),B=C||_,Q=T||N,J=[];for(const $ of B){if(!$.selected)continue;const I=j.get($.id);I&&(I.selected=!1),J.push(ii($.id,!1))}const at=[];for(const $ of Q)$.selected&&at.push(ii($.id,!1));V(J),D(at)},setMinZoom:C=>{const{panZoom:T,maxZoom:N}=w();T==null||T.setScaleExtent([C,N]),S({minZoom:C})},setMaxZoom:C=>{const{panZoom:T,minZoom:N}=w();T==null||T.setScaleExtent([N,C]),S({maxZoom:C})},setTranslateExtent:C=>{var T;(T=w().panZoom)==null||T.setTranslateExtent(C),S({translateExtent:C})},resetSelectedElements:()=>{const{edges:C,nodes:T,triggerNodeChanges:N,triggerEdgeChanges:_,elementsSelectable:j}=w();if(!j)return;const V=T.reduce((B,Q)=>Q.selected?[...B,ii(Q.id,!1)]:B,[]),D=C.reduce((B,Q)=>Q.selected?[...B,ii(Q.id,!1)]:B,[]);N(V),_(D)},setNodeExtent:C=>{const{nodes:T,nodeLookup:N,parentLookup:_,nodeOrigin:j,elevateNodesOnSelect:V,nodeExtent:D,zIndexMode:B}=w();C[0][0]===D[0][0]&&C[0][1]===D[0][1]&&C[1][0]===D[1][0]&&C[1][1]===D[1][1]||($f(T,N,_,{nodeOrigin:j,nodeExtent:C,elevateNodesOnSelect:V,checkEquality:!1,zIndexMode:B}),S({nodeExtent:C}))},panBy:C=>{const{transform:T,width:N,height:_,panZoom:j,translateExtent:V}=w();return Rw({delta:C,panZoom:j,transform:T,translateExtent:V,width:N,height:_})},setCenter:async(C,T,N)=>{const{width:_,height:j,maxZoom:V,panZoom:D}=w();if(!D)return Promise.resolve(!1);const B=typeof(N==null?void 0:N.zoom)<"u"?N.zoom:V;return await D.setViewport({x:_/2-C*B,y:j/2-T*B,zoom:B},{duration:N==null?void 0:N.duration,ease:N==null?void 0:N.ease,interpolate:N==null?void 0:N.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{S({connection:{...Iy}})},updateConnection:C=>{S({connection:C})},reset:()=>S({...gy()})}},Object.is);function ev({initialNodes:n,initialEdges:a,defaultNodes:o,defaultEdges:r,initialWidth:u,initialHeight:f,initialMinZoom:d,initialMaxZoom:h,initialFitViewOptions:g,fitView:m,nodeOrigin:x,nodeExtent:p,zIndexMode:b,children:S}){const[w]=X.useState(()=>F_({nodes:n,edges:a,defaultNodes:o,defaultEdges:r,width:u,height:f,fitView:m,minZoom:d,maxZoom:h,fitViewOptions:g,nodeOrigin:x,nodeExtent:p,zIndexMode:b}));return y.jsx(mE,{value:w,children:y.jsx(kE,{children:S})})}function I_({children:n,nodes:a,edges:o,defaultNodes:r,defaultEdges:u,width:f,height:d,fitView:h,fitViewOptions:g,minZoom:m,maxZoom:x,nodeOrigin:p,nodeExtent:b,zIndexMode:S}){return X.useContext($s)?y.jsx(y.Fragment,{children:n}):y.jsx(ev,{initialNodes:a,initialEdges:o,defaultNodes:r,defaultEdges:u,initialWidth:f,initialHeight:d,fitView:h,initialFitViewOptions:g,initialMinZoom:m,initialMaxZoom:x,nodeOrigin:p,nodeExtent:b,zIndexMode:S,children:n})}const P_={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function tT({nodes:n,edges:a,defaultNodes:o,defaultEdges:r,className:u,nodeTypes:f,edgeTypes:d,onNodeClick:h,onEdgeClick:g,onInit:m,onMove:x,onMoveStart:p,onMoveEnd:b,onConnect:S,onConnectStart:w,onConnectEnd:M,onClickConnectStart:C,onClickConnectEnd:T,onNodeMouseEnter:N,onNodeMouseMove:_,onNodeMouseLeave:j,onNodeContextMenu:V,onNodeDoubleClick:D,onNodeDragStart:B,onNodeDrag:Q,onNodeDragStop:J,onNodesDelete:at,onEdgesDelete:$,onDelete:I,onSelectionChange:K,onSelectionDragStart:R,onSelectionDrag:Z,onSelectionDragStop:z,onSelectionContextMenu:L,onSelectionStart:k,onSelectionEnd:q,onBeforeDelete:tt,connectionMode:A,connectionLineType:H=jl.Bezier,connectionLineStyle:U,connectionLineComponent:nt,connectionLineContainerStyle:rt,deleteKeyCode:ut="Backspace",selectionKeyCode:ct="Shift",selectionOnDrag:st=!1,selectionMode:ft=zo.Full,panActivationKeyCode:St="Space",multiSelectionKeyCode:xt=Co()?"Meta":"Control",zoomActivationKeyCode:pt=Co()?"Meta":"Control",snapToGrid:yt,snapGrid:Tt,onlyRenderVisibleElements:Ut=!1,selectNodesOnDrag:Ct,nodesDraggable:de,autoPanOnNodeFocus:tn,nodesConnectable:Be,nodesFocusable:en,nodeOrigin:En=Cp,edgesFocusable:Dl,edgesReconnectable:Rl,elementsSelectable:ge=!0,defaultViewport:hi=ME,minZoom:_n=.5,maxZoom:Wn=2,translateExtent:Ol=Ao,preventScrolling:Ws=!0,nodeExtent:gi,defaultMarkerColor:Fs="#b1b1b7",zoomOnScroll:Is=!0,zoomOnPinch:Hl=!0,panOnScroll:we=!1,panOnScrollSpeed:hn=.5,panOnScrollMode:Ee=si.Free,zoomOnDoubleClick:Ps=!0,panOnDrag:tu=!0,onPaneClick:eu,onPaneMouseEnter:mi,onPaneMouseMove:yi,onPaneMouseLeave:pi,onPaneScroll:Tn,onPaneContextMenu:vi,paneClickDistance:Bl=1,nodeClickDistance:nu=0,children:Uo,onReconnect:pa,onReconnectStart:Ll,onReconnectEnd:lu,onEdgeContextMenu:ko,onEdgeDoubleClick:Yo,onEdgeMouseEnter:qo,onEdgeMouseMove:va,onEdgeMouseLeave:xa,reconnectRadius:Vo=10,onNodesChange:Xo,onEdgesChange:gn,noDragClassName:ue="nodrag",noWheelClassName:xe="nowheel",noPanClassName:An="nopan",fitView:xi,fitViewOptions:Go,connectOnClick:iu,attributionPosition:$o,proOptions:Ul,defaultEdgeOptions:ba,elevateNodesOnSelect:Fn=!0,elevateEdgesOnSelect:In=!1,disableKeyboardA11y:Pn=!1,autoPanOnConnect:tl,autoPanOnNodeDrag:ee,autoPanSpeed:Qo,connectionRadius:Zo,isValidConnection:zn,onError:el,style:au,id:Sa,nodeDragThreshold:Ko,connectionDragThreshold:ou,viewport:bi,onViewportChange:Si,width:nn,height:Te,colorMode:Jo="light",debug:ru,onScroll:nl,ariaLabelConfig:Wo,zIndexMode:kl="basic",...su},Ae){const Yl=Sa||"1",Fo=DE(Jo),wa=X.useCallback(Mn=>{Mn.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),nl==null||nl(Mn)},[nl]);return y.jsx("div",{"data-testid":"rf__wrapper",...su,onScroll:wa,style:{...au,...P_},ref:Ae,className:se(["react-flow",u,Fo]),id:Sa,role:"application",children:y.jsxs(I_,{nodes:n,edges:a,width:nn,height:Te,fitView:xi,fitViewOptions:Go,minZoom:_n,maxZoom:Wn,nodeOrigin:En,nodeExtent:gi,zIndexMode:kl,children:[y.jsx(NE,{nodes:n,edges:a,defaultNodes:o,defaultEdges:r,onConnect:S,onConnectStart:w,onConnectEnd:M,onClickConnectStart:C,onClickConnectEnd:T,nodesDraggable:de,autoPanOnNodeFocus:tn,nodesConnectable:Be,nodesFocusable:en,edgesFocusable:Dl,edgesReconnectable:Rl,elementsSelectable:ge,elevateNodesOnSelect:Fn,elevateEdgesOnSelect:In,minZoom:_n,maxZoom:Wn,nodeExtent:gi,onNodesChange:Xo,onEdgesChange:gn,snapToGrid:yt,snapGrid:Tt,connectionMode:A,translateExtent:Ol,connectOnClick:iu,defaultEdgeOptions:ba,fitView:xi,fitViewOptions:Go,onNodesDelete:at,onEdgesDelete:$,onDelete:I,onNodeDragStart:B,onNodeDrag:Q,onNodeDragStop:J,onSelectionDrag:Z,onSelectionDragStart:R,onSelectionDragStop:z,onMove:x,onMoveStart:p,onMoveEnd:b,noPanClassName:An,nodeOrigin:En,rfId:Yl,autoPanOnConnect:tl,autoPanOnNodeDrag:ee,autoPanSpeed:Qo,onError:el,connectionRadius:Zo,isValidConnection:zn,selectNodesOnDrag:Ct,nodeDragThreshold:Ko,connectionDragThreshold:ou,onBeforeDelete:tt,debug:ru,ariaLabelConfig:Wo,zIndexMode:kl}),y.jsx(W_,{onInit:m,onNodeClick:h,onEdgeClick:g,onNodeMouseEnter:N,onNodeMouseMove:_,onNodeMouseLeave:j,onNodeContextMenu:V,onNodeDoubleClick:D,nodeTypes:f,edgeTypes:d,connectionLineType:H,connectionLineStyle:U,connectionLineComponent:nt,connectionLineContainerStyle:rt,selectionKeyCode:ct,selectionOnDrag:st,selectionMode:ft,deleteKeyCode:ut,multiSelectionKeyCode:xt,panActivationKeyCode:St,zoomActivationKeyCode:pt,onlyRenderVisibleElements:Ut,defaultViewport:hi,translateExtent:Ol,minZoom:_n,maxZoom:Wn,preventScrolling:Ws,zoomOnScroll:Is,zoomOnPinch:Hl,zoomOnDoubleClick:Ps,panOnScroll:we,panOnScrollSpeed:hn,panOnScrollMode:Ee,panOnDrag:tu,onPaneClick:eu,onPaneMouseEnter:mi,onPaneMouseMove:yi,onPaneMouseLeave:pi,onPaneScroll:Tn,onPaneContextMenu:vi,paneClickDistance:Bl,nodeClickDistance:nu,onSelectionContextMenu:L,onSelectionStart:k,onSelectionEnd:q,onReconnect:pa,onReconnectStart:Ll,onReconnectEnd:lu,onEdgeContextMenu:ko,onEdgeDoubleClick:Yo,onEdgeMouseEnter:qo,onEdgeMouseMove:va,onEdgeMouseLeave:xa,reconnectRadius:Vo,defaultMarkerColor:Fs,noDragClassName:ue,noWheelClassName:xe,noPanClassName:An,rfId:Yl,disableKeyboardA11y:Pn,nodeExtent:gi,viewport:bi,onViewportChange:Si}),y.jsx(zE,{onSelectionChange:K}),Uo,y.jsx(wE,{proOptions:Ul,position:$o}),y.jsx(SE,{rfId:Yl,disableKeyboardA11y:Pn})]})})}var eT=Np(tT);function nT({dimensions:n,lineWidth:a,variant:o,className:r}){return y.jsx("path",{strokeWidth:a,d:`M${n[0]/2} 0 V${n[1]} M0 ${n[1]/2} H${n[0]}`,className:se(["react-flow__background-pattern",o,r])})}function lT({radius:n,className:a}){return y.jsx("circle",{cx:n,cy:n,r:n,className:se(["react-flow__background-pattern","dots",a])})}var Nl;(function(n){n.Lines="lines",n.Dots="dots",n.Cross="cross"})(Nl||(Nl={}));const iT={[Nl.Dots]:1,[Nl.Lines]:1,[Nl.Cross]:6},aT=n=>({transform:n.transform,patternId:`pattern-${n.rfId}`});function nv({id:n,variant:a=Nl.Dots,gap:o=20,size:r,lineWidth:u=1,offset:f=0,color:d,bgColor:h,style:g,className:m,patternClassName:x}){const p=X.useRef(null),{transform:b,patternId:S}=Rt(aT,Jt),w=r||iT[a],M=a===Nl.Dots,C=a===Nl.Cross,T=Array.isArray(o)?o:[o,o],N=[T[0]*b[2]||1,T[1]*b[2]||1],_=w*b[2],j=Array.isArray(f)?f:[f,f],V=C?[_,_]:N,D=[j[0]*b[2]||1+V[0]/2,j[1]*b[2]||1+V[1]/2],B=`${S}${n||""}`;return y.jsxs("svg",{className:se(["react-flow__background",m]),style:{...g,...Ks,"--xy-background-color-props":h,"--xy-background-pattern-color-props":d},ref:p,"data-testid":"rf__background",children:[y.jsx("pattern",{id:B,x:b[0]%N[0],y:b[1]%N[1],width:N[0],height:N[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${D[0]},-${D[1]})`,children:M?y.jsx(lT,{radius:_/2,className:x}):y.jsx(nT,{dimensions:V,lineWidth:u,variant:a,className:x})}),y.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${B})`})]})}nv.displayName="Background";const oT=X.memo(nv);function rT(){return y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:y.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function sT(){return y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:y.jsx("path",{d:"M0 0h32v4.2H0z"})})}function uT(){return y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:y.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function cT(){return y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:y.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function fT(){return y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:y.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function ms({children:n,className:a,...o}){return y.jsx("button",{type:"button",className:se(["react-flow__controls-button",a]),...o,children:n})}const dT=n=>({isInteractive:n.nodesDraggable||n.nodesConnectable||n.elementsSelectable,minZoomReached:n.transform[2]<=n.minZoom,maxZoomReached:n.transform[2]>=n.maxZoom,ariaLabelConfig:n.ariaLabelConfig});function lv({style:n,showZoom:a=!0,showFitView:o=!0,showInteractive:r=!0,fitViewOptions:u,onZoomIn:f,onZoomOut:d,onFitView:h,onInteractiveChange:g,className:m,children:x,position:p="bottom-left",orientation:b="vertical","aria-label":S}){const w=Wt(),{isInteractive:M,minZoomReached:C,maxZoomReached:T,ariaLabelConfig:N}=Rt(dT,Jt),{zoomIn:_,zoomOut:j,fitView:V}=Zs(),D=()=>{_(),f==null||f()},B=()=>{j(),d==null||d()},Q=()=>{V(u),h==null||h()},J=()=>{w.setState({nodesDraggable:!M,nodesConnectable:!M,elementsSelectable:!M}),g==null||g(!M)},at=b==="horizontal"?"horizontal":"vertical";return y.jsxs(Qs,{className:se(["react-flow__controls",at,m]),position:p,style:n,"data-testid":"rf__controls","aria-label":S??N["controls.ariaLabel"],children:[a&&y.jsxs(y.Fragment,{children:[y.jsx(ms,{onClick:D,className:"react-flow__controls-zoomin",title:N["controls.zoomIn.ariaLabel"],"aria-label":N["controls.zoomIn.ariaLabel"],disabled:T,children:y.jsx(rT,{})}),y.jsx(ms,{onClick:B,className:"react-flow__controls-zoomout",title:N["controls.zoomOut.ariaLabel"],"aria-label":N["controls.zoomOut.ariaLabel"],disabled:C,children:y.jsx(sT,{})})]}),o&&y.jsx(ms,{className:"react-flow__controls-fitview",onClick:Q,title:N["controls.fitView.ariaLabel"],"aria-label":N["controls.fitView.ariaLabel"],children:y.jsx(uT,{})}),r&&y.jsx(ms,{className:"react-flow__controls-interactive",onClick:J,title:N["controls.interactive.ariaLabel"],"aria-label":N["controls.interactive.ariaLabel"],children:M?y.jsx(fT,{}):y.jsx(cT,{})}),x]})}lv.displayName="Controls";X.memo(lv);function hT({id:n,x:a,y:o,width:r,height:u,style:f,color:d,strokeColor:h,strokeWidth:g,className:m,borderRadius:x,shapeRendering:p,selected:b,onClick:S}){const{background:w,backgroundColor:M}=f||{},C=d||w||M;return y.jsx("rect",{className:se(["react-flow__minimap-node",{selected:b},m]),x:a,y:o,rx:x,ry:x,width:r,height:u,style:{fill:C,stroke:h,strokeWidth:g},shapeRendering:p,onClick:S?T=>S(T,n):void 0})}const gT=X.memo(hT),mT=n=>n.nodes.map(a=>a.id),Df=n=>n instanceof Function?n:()=>n;function yT({nodeStrokeColor:n,nodeColor:a,nodeClassName:o="",nodeBorderRadius:r=5,nodeStrokeWidth:u,nodeComponent:f=gT,onClick:d}){const h=Rt(mT,Jt),g=Df(a),m=Df(n),x=Df(o),p=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return y.jsx(y.Fragment,{children:h.map(b=>y.jsx(vT,{id:b,nodeColorFunc:g,nodeStrokeColorFunc:m,nodeClassNameFunc:x,nodeBorderRadius:r,nodeStrokeWidth:u,NodeComponent:f,onClick:d,shapeRendering:p},b))})}function pT({id:n,nodeColorFunc:a,nodeStrokeColorFunc:o,nodeClassNameFunc:r,nodeBorderRadius:u,nodeStrokeWidth:f,shapeRendering:d,NodeComponent:h,onClick:g}){const{node:m,x,y:p,width:b,height:S}=Rt(w=>{const M=w.nodeLookup.get(n);if(!M)return{node:void 0,x:0,y:0,width:0,height:0};const C=M.internals.userNode,{x:T,y:N}=M.internals.positionAbsolute,{width:_,height:j}=Jn(C);return{node:C,x:T,y:N,width:_,height:j}},Jt);return!m||m.hidden||!ap(m)?null:y.jsx(h,{x,y:p,width:b,height:S,style:m.style,selected:!!m.selected,className:r(m),color:a(m),borderRadius:u,strokeColor:o(m),strokeWidth:f,shapeRendering:d,onClick:g,id:m.id})}const vT=X.memo(pT);var xT=X.memo(yT);const bT=200,ST=150,wT=n=>!n.hidden,ET=n=>{const a={x:-n.transform[0]/n.transform[2],y:-n.transform[1]/n.transform[2],width:n.width/n.transform[2],height:n.height/n.transform[2]};return{viewBB:a,boundingRect:n.nodeLookup.size>0?ip(Ho(n.nodeLookup,{filter:wT}),a):a,rfId:n.rfId,panZoom:n.panZoom,translateExtent:n.translateExtent,flowWidth:n.width,flowHeight:n.height,ariaLabelConfig:n.ariaLabelConfig}},_T="react-flow__minimap-desc";function iv({style:n,className:a,nodeStrokeColor:o,nodeColor:r,nodeClassName:u="",nodeBorderRadius:f=5,nodeStrokeWidth:d,nodeComponent:h,bgColor:g,maskColor:m,maskStrokeColor:x,maskStrokeWidth:p,position:b="bottom-right",onClick:S,onNodeClick:w,pannable:M=!1,zoomable:C=!1,ariaLabel:T,inversePan:N,zoomStep:_=1,offsetScale:j=5}){const V=Wt(),D=X.useRef(null),{boundingRect:B,viewBB:Q,rfId:J,panZoom:at,translateExtent:$,flowWidth:I,flowHeight:K,ariaLabelConfig:R}=Rt(ET,Jt),Z=(n==null?void 0:n.width)??bT,z=(n==null?void 0:n.height)??ST,L=B.width/Z,k=B.height/z,q=Math.max(L,k),tt=q*Z,A=q*z,H=j*q,U=B.x-(tt-B.width)/2-H,nt=B.y-(A-B.height)/2-H,rt=tt+H*2,ut=A+H*2,ct=`${_T}-${J}`,st=X.useRef(0),ft=X.useRef();st.current=q,X.useEffect(()=>{if(D.current&&at)return ft.current=Vw({domNode:D.current,panZoom:at,getTransform:()=>V.getState().transform,getViewScale:()=>st.current}),()=>{var yt;(yt=ft.current)==null||yt.destroy()}},[at]),X.useEffect(()=>{var yt;(yt=ft.current)==null||yt.update({translateExtent:$,width:I,height:K,inversePan:N,pannable:M,zoomStep:_,zoomable:C})},[M,C,N,_,$,I,K]);const St=S?yt=>{var Ct;const[Tt,Ut]=((Ct=ft.current)==null?void 0:Ct.pointer(yt))||[0,0];S(yt,{x:Tt,y:Ut})}:void 0,xt=w?X.useCallback((yt,Tt)=>{const Ut=V.getState().nodeLookup.get(Tt).internals.userNode;w(yt,Ut)},[]):void 0,pt=T??R["minimap.ariaLabel"];return y.jsx(Qs,{position:b,style:{...n,"--xy-minimap-background-color-props":typeof g=="string"?g:void 0,"--xy-minimap-mask-background-color-props":typeof m=="string"?m:void 0,"--xy-minimap-mask-stroke-color-props":typeof x=="string"?x:void 0,"--xy-minimap-mask-stroke-width-props":typeof p=="number"?p*q:void 0,"--xy-minimap-node-background-color-props":typeof r=="string"?r:void 0,"--xy-minimap-node-stroke-color-props":typeof o=="string"?o:void 0,"--xy-minimap-node-stroke-width-props":typeof d=="number"?d:void 0},className:se(["react-flow__minimap",a]),"data-testid":"rf__minimap",children:y.jsxs("svg",{width:Z,height:z,viewBox:`${U} ${nt} ${rt} ${ut}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":ct,ref:D,onClick:St,children:[pt&&y.jsx("title",{id:ct,children:pt}),y.jsx(xT,{onClick:xt,nodeColor:r,nodeStrokeColor:o,nodeBorderRadius:f,nodeClassName:u,nodeStrokeWidth:d,nodeComponent:h}),y.jsx("path",{className:"react-flow__minimap-mask",d:`M${U-H},${nt-H}h${rt+H*2}v${ut+H*2}h${-rt-H*2}z
71
71
  M${Q.x},${Q.y}h${Q.width}v${Q.height}h${-Q.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}iv.displayName="MiniMap";X.memo(iv);const TT=n=>a=>n?`${Math.max(1/a.transform[2],1)}`:void 0,AT={[ma.Line]:"right",[ma.Handle]:"bottom-right"};function zT({nodeId:n,position:a,variant:o=ma.Handle,className:r,style:u=void 0,children:f,color:d,minWidth:h=10,minHeight:g=10,maxWidth:m=Number.MAX_VALUE,maxHeight:x=Number.MAX_VALUE,keepAspectRatio:p=!1,resizeDirection:b,autoScale:S=!0,shouldResize:w,onResizeStart:M,onResize:C,onResizeEnd:T}){const N=Hp(),_=typeof n=="string"?n:N,j=Wt(),V=X.useRef(null),D=o===ma.Handle,B=Rt(X.useCallback(TT(D&&S),[D,S]),Jt),Q=X.useRef(null),J=a??AT[o];X.useEffect(()=>{if(!(!V.current||!_))return Q.current||(Q.current=nE({domNode:V.current,nodeId:_,getStoreItems:()=>{const{nodeLookup:$,transform:I,snapGrid:K,snapToGrid:R,nodeOrigin:Z,domNode:z}=j.getState();return{nodeLookup:$,transform:I,snapGrid:K,snapToGrid:R,nodeOrigin:Z,paneDomNode:z}},onChange:($,I)=>{const{triggerNodeChanges:K,nodeLookup:R,parentLookup:Z,nodeOrigin:z}=j.getState(),L=[],k={x:$.x,y:$.y},q=R.get(_);if(q&&q.expandParent&&q.parentId){const tt=q.origin??z,A=$.width??q.measured.width??0,H=$.height??q.measured.height??0,U={id:q.id,parentId:q.parentId,rect:{width:A,height:H,...op({x:$.x??q.position.x,y:$.y??q.position.y},{width:A,height:H},q.parentId,R,tt)}},nt=cd([U],R,Z,z);L.push(...nt),k.x=$.x?Math.max(tt[0]*A,$.x):void 0,k.y=$.y?Math.max(tt[1]*H,$.y):void 0}if(k.x!==void 0&&k.y!==void 0){const tt={id:_,type:"position",position:{...k}};L.push(tt)}if($.width!==void 0&&$.height!==void 0){const A={id:_,type:"dimensions",resizing:!0,setAttributes:b?b==="horizontal"?"width":"height":!0,dimensions:{width:$.width,height:$.height}};L.push(A)}for(const tt of I){const A={...tt,type:"position"};L.push(A)}K(L)},onEnd:({width:$,height:I})=>{const K={id:_,type:"dimensions",resizing:!1,dimensions:{width:$,height:I}};j.getState().triggerNodeChanges([K])}})),Q.current.update({controlPosition:J,boundaries:{minWidth:h,minHeight:g,maxWidth:m,maxHeight:x},keepAspectRatio:p,resizeDirection:b,onResizeStart:M,onResize:C,onResizeEnd:T,shouldResize:w}),()=>{var $;($=Q.current)==null||$.destroy()}},[J,h,g,m,x,p,M,C,T,w]);const at=J.split("-");return y.jsx("div",{className:se(["react-flow__resize-control","nodrag",...at,o,r]),ref:V,style:{...u,scale:B,...d&&{[D?"backgroundColor":"borderColor"]:d}},children:f})}X.memo(zT);const my={running:"#4ae168",starting:"#e5c07b",stopped:"#5c6370",crashed:"#e06c75",completed:"#33afbc",killed:"#5c6370"},yy={planner:{bg:"#4ae16820",color:"#4ae168"},backend:{bg:"#33afbc20",color:"#33afbc"},frontend:{bg:"#e5c07b20",color:"#e5c07b"},fullstack:{bg:"#4ae16820",color:"#4ae168"},testing:{bg:"#61afef20",color:"#61afef"},devops:{bg:"#d19a6620",color:"#d19a66"},docs:{bg:"#5c637020",color:"#8b929e"}};function MT({data:n}){var g;const a=my[n.status]||my.stopped,o=yy[n.role]||yy.docs,r=n.status==="running"||n.status==="starting",u=n.selected,f=Math.round((n.contextUsage||0)*100),d=n.tokensUsed>0?n.tokensUsed>999?`${(n.tokensUsed/1e3).toFixed(1)}k`:`${n.tokensUsed}`:"0",h=((g=n.scope)==null?void 0:g.length)>0?n.scope[0].replace(/\/\*\*$/,"").replace(/^src\//,""):n.role;return y.jsxs("div",{style:{background:"#282c34",border:u?"1px solid #33afbc":"1px solid #3e4451",borderRadius:10,width:210,padding:0,cursor:"pointer",fontFamily:"'JetBrains Mono', 'SF Mono', 'Fira Code', Consolas, monospace",fontSize:10,overflow:"hidden"},children:[y.jsx(ya,{type:"target",position:gt.Top,style:{background:"#282c34",border:"2px solid #3e4451",width:8,height:8,borderRadius:"50%",top:-4}}),y.jsxs("div",{style:{padding:"10px 12px 8px"},children:[y.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,marginBottom:6},children:[y.jsx("div",{style:{width:7,height:7,borderRadius:"50%",background:a,flexShrink:0,...r?{animation:"pulse 2s infinite"}:{}}}),y.jsx("span",{style:{color:"#e6e6e6",fontWeight:700,fontSize:12,flex:1},children:n.name})]}),y.jsx("div",{style:{marginBottom:10},children:y.jsx("span",{style:{fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:1,color:o.color,background:o.bg,padding:"3px 8px",borderRadius:4,display:"inline-block"},children:n.role})}),y.jsxs("div",{style:{display:"flex",justifyContent:"space-between",color:"#5c6370",fontSize:10,marginBottom:4},children:[y.jsxs("span",{children:[d," tok"]}),y.jsxs("span",{children:[f,"% ctx"]})]}),y.jsx("div",{style:{color:"#3e4451",fontSize:9,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h})]}),r&&y.jsx(CT,{agentId:n.id,color:a}),y.jsx(ya,{type:"source",position:gt.Bottom,style:{background:"#282c34",border:"2px solid #3e4451",width:8,height:8,borderRadius:"50%",bottom:-4}})]})}function CT({agentId:n,color:a}){const o=X.useRef(),r=Mt(u=>u.tokenTimeline);return X.useEffect(()=>{const u=o.current;if(!u)return;const f=window.devicePixelRatio||1,d=210,h=24;u.width=d*f,u.height=h*f;const g=u.getContext("2d");g.scale(f,f),g.clearRect(0,0,d,h);const m=r[n]||[];if(m.length<2){g.strokeStyle="#2c313a",g.lineWidth=.5,g.beginPath(),g.moveTo(0,h/2),g.lineTo(d,h/2),g.stroke();return}const x=m.slice(-40),p=x.map(j=>j.v),b=Math.min(...p),w=Math.max(...p)-b||1,M=4,C=h-M*2,T=d/(x.length-1);g.beginPath(),x.forEach((j,V)=>{const D=V*T,B=M+C-(j.v-b)/w*C;V===0?g.moveTo(D,B):g.lineTo(D,B)}),g.strokeStyle=a,g.lineWidth=1,g.stroke();const N=(x.length-1)*T,_=M+C-(x[x.length-1].v-b)/w*C;g.beginPath(),g.arc(N,_,2,0,Math.PI*2),g.fillStyle=a,g.fill()},[r,n,a]),y.jsx("div",{style:{borderTop:"1px solid #2c313a",background:"#1e222a"},children:y.jsx("canvas",{ref:o,style:{display:"block",width:210,height:24}})})}const jT={agent:MT},na=4,ys=250,Rf=140;function NT(){const n=Mt(p=>p.agents),a=Mt(p=>p.detailPanel),o=Mt(p=>p.selectAgent),r=Mt(p=>p.clearSelection),{fitView:u}=Zs(),f=(a==null?void 0:a.type)==="agent"?a.agentId:null,d=X.useRef(0),{nodes:h,edges:g}=X.useMemo(()=>{const p=n.filter(D=>D.status==="running"||D.status==="starting"),b=n.filter(D=>D.status!=="running"&&D.status!=="starting"),S=p.map((D,B)=>({id:D.id,type:"agent",position:{x:B%na*ys,y:80+Math.floor(B/na)*Rf},data:{...D,selected:D.id===f},draggable:!0})),M=80+(Math.ceil(p.length/na)||1)*Rf+50,C=b.map((D,B)=>({id:D.id,type:"agent",position:{x:B%na*ys,y:M+Math.floor(B/na)*Rf},data:{...D,selected:D.id===f},draggable:!0})),T=[...S,...C],j={id:"groove-root",type:"default",position:{x:(Math.min(Math.max(p.length,b.length,1),na)*ys-ys)/2+25,y:0},data:{label:"GROOVE"},selectable:!1,draggable:!1,style:{background:"#282c34",color:"#e6e6e6",border:"1px solid #3e4451",borderRadius:24,fontWeight:600,fontSize:11,letterSpacing:6,padding:"10px 36px 9px",fontFamily:"'JetBrains Mono', 'SF Mono', Consolas, monospace"}},V=T.map(D=>{const B=n.find(J=>J.id===D.id),Q=(B==null?void 0:B.status)==="running";return{id:`groove-${D.id}`,source:"groove-root",target:D.id,type:"default",style:{stroke:Q?"#5c6370":"#2c313a",strokeWidth:1},animated:Q}});return{nodes:[j,...T],edges:V}},[n,f]);X.useEffect(()=>{const p=n.length;p!==d.current&&setTimeout(()=>u({padding:.3,maxZoom:1.4,duration:200}),50),d.current=p},[n.length,u]),X.useEffect(()=>{setTimeout(()=>u({padding:.3,maxZoom:1.4,duration:0}),100)},[]);const m=X.useCallback((p,b)=>{b.id!=="groove-root"&&o(b.id)},[o]),x=X.useCallback(()=>{r()},[r]);return y.jsx(eT,{nodes:h,edges:g,nodeTypes:jT,onNodeClick:m,onPaneClick:x,proOptions:{hideAttribution:!0},nodesConnectable:!1,elementsSelectable:!0,minZoom:.3,maxZoom:2,fitView:!0,fitViewOptions:{padding:.3,maxZoom:1.4},children:y.jsx(oT,{color:"#3e4451",gap:20,size:1})})}function DT(){return y.jsx(ev,{children:y.jsx(NT,{})})}function RT({agent:n}){const[a,o]=X.useState(""),[r,u]=X.useState(null),f=X.useRef(),d=Mt(T=>T.activityLog),h=Mt(T=>T.instructAgent),g=Mt(T=>T.queryAgent),m=Mt(T=>T.showStatus),x=Mt(T=>T.chatHistory),p=d[n.id]||[],b=x[n.id]||[],S=LT(b,p),w=n.status==="running"||n.status==="starting";X.useEffect(()=>{f.current&&(f.current.scrollTop=f.current.scrollHeight)},[S.length]);async function M(){const T=a.trim();if(!T||r)return;const N=T.startsWith("?"),_=N?T.slice(1).trim():T;if(_)if(o(""),N&&w){u("querying...");try{await g(n.id,_)}catch{}u(null)}else{u(w?"sending...":"continuing...");try{await h(n.id,_)}catch(j){m(`failed: ${j.message}`)}u(null)}}function C(T){T.key==="Enter"&&!T.shiftKey&&(T.preventDefault(),T.stopPropagation(),M())}return y.jsxs("div",{style:Kt.container,children:[y.jsxs("div",{ref:f,style:Kt.timeline,children:[S.length===0&&y.jsx("div",{style:Kt.hint,children:w?"Type a message to instruct this agent. Prefix with ? to query without disrupting.":"Agent finished. Reply to continue the conversation."}),S.map((T,N)=>y.jsxs("div",{style:Kt.entry,children:[T.from==="user"&&y.jsxs("div",{style:Kt.userMsg,children:[y.jsx("span",{style:Kt.userLabel,children:T.isQuery?"? you":"> you"}),y.jsx("div",{style:Kt.userText,children:T.text})]}),T.from==="agent"&&y.jsxs("div",{style:Kt.agentMsg,children:[y.jsx("span",{style:Kt.agentLabel,children:n.name}),y.jsx("div",{style:Kt.agentText,children:N===S.length-1&&T.from==="agent"&&Date.now()-T.timestamp<5e3?y.jsx(OT,{text:T.text}):y.jsx(av,{text:T.text})})]}),T.from==="system"&&y.jsx("div",{style:Kt.systemMsg,children:T.text}),y.jsx("span",{style:Kt.time,children:new Date(T.timestamp).toLocaleTimeString()})]},N)),r&&y.jsx("div",{style:Kt.statusMsg,children:r})]}),n.role==="planner"&&n.status==="completed"&&y.jsx(HT,{showStatus:m}),y.jsxs("div",{style:Kt.inputRow,children:[y.jsx("input",{style:Kt.input,value:a,onChange:T=>o(T.target.value),onKeyDown:C,placeholder:w?"message or ?query...":"reply to continue...",disabled:!!r,spellCheck:!1}),y.jsx("button",{type:"button",onClick:M,disabled:!!r||!a.trim(),style:{...Kt.sendBtn,opacity:r||!a.trim()?.3:1},children:"Send"})]})]})}function OT({text:n}){const[a,o]=X.useState(0),r=X.useRef(n);X.useEffect(()=>{r.current=n,o(0)},[n]),X.useEffect(()=>{if(a>=n.length)return;const d=Math.random()>.7?4:2,h=setTimeout(()=>{o(g=>Math.min(g+d,n.length))},12);return()=>clearTimeout(h)},[a,n.length]);const u=n.slice(0,a),f=a>=n.length;return y.jsxs(y.Fragment,{children:[y.jsx(av,{text:u}),!f&&y.jsx("span",{style:Kt.cursor,children:"|"})]})}function HT({showStatus:n}){const[a,o]=X.useState(null),[r,u]=X.useState(!1),[f,d]=X.useState(!1);X.useEffect(()=>{fetch("/api/recommended-team").then(g=>g.json()).then(g=>{g.exists&&g.agents.length>0&&o(g.agents)}).catch(()=>{})},[]);async function h(){u(!0);try{const m=await(await fetch("/api/recommended-team/launch",{method:"POST"})).json();m.launched?(n(`Launched ${m.launched} agents`),d(!0)):n(`Launch failed: ${m.error||"unknown"}`)}catch(g){n(`Launch failed: ${g.message}`)}u(!1)}return!a||f?null:y.jsxs("div",{style:Kt.launchBox,children:[y.jsxs("div",{style:Kt.launchHeader,children:["Recommended Team (",a.length," agents)"]}),y.jsx("div",{style:Kt.launchList,children:a.map((g,m)=>y.jsxs("div",{style:Kt.launchAgent,children:[y.jsx("span",{style:Kt.launchRole,children:g.role}),y.jsxs("span",{style:Kt.launchPrompt,children:[(g.prompt||"").slice(0,80),(g.prompt||"").length>80?"...":""]})]},m))}),y.jsx("button",{type:"button",onClick:h,disabled:r,style:{...Kt.launchBtn,opacity:r?.5:1},children:r?"Launching...":"Launch Team"})]})}function av({text:n}){return n?n.split(`
72
72
  `).map((o,r)=>{if(/^#{1,3}\s/.test(o)){const u=o.replace(/^#{1,3}\s+/,"");return y.jsx("div",{style:{fontWeight:700,color:"var(--text-bright)",marginTop:r>0?6:0,marginBottom:2,fontSize:11},children:ps(u)},r)}if(/^[-*_]{3,}\s*$/.test(o))return y.jsx("div",{style:{borderTop:"1px solid var(--border)",margin:"4px 0"}},r);if(/^\s*[-*]\s/.test(o)){const u=o.match(/^(\s*)/)[1].length,f=o.replace(/^\s*[-*]\s+/,"");return y.jsxs("div",{style:{paddingLeft:8+u*6,position:"relative"},children:[y.jsx("span",{style:{position:"absolute",left:u*6,color:"var(--text-dim)"},children:"-"}),ps(f)]},r)}if(/^\s*\d+\.\s/.test(o)){const u=o.match(/^(\s*)/)[1].length,f=o.match(/(\d+)\./)[1],d=o.replace(/^\s*\d+\.\s+/,"");return y.jsxs("div",{style:{paddingLeft:12+u*6,position:"relative"},children:[y.jsxs("span",{style:{position:"absolute",left:u*6,color:"var(--text-dim)"},children:[f,"."]}),ps(d)]},r)}return o.trim()?y.jsx("div",{children:ps(o)},r):y.jsx("div",{style:{height:4}},r)}):null}function ps(n){const a=[];let o=n,r=0;for(;o.length>0;){const u=o.match(/^(.*?)\*\*(.+?)\*\*(.*)/s);if(u){u[1]&&a.push(y.jsx("span",{children:u[1]},r++)),a.push(y.jsx("span",{style:{fontWeight:700,color:"var(--text-bright)"},children:u[2]},r++)),o=u[3];continue}const f=o.match(/^(.*?)`(.+?)`(.*)/s);if(f){f[1]&&a.push(y.jsx("span",{children:f[1]},r++)),a.push(y.jsx("span",{style:{background:"var(--bg-base)",padding:"0 3px",borderRadius:2,color:"var(--accent)",fontSize:"0.95em"},children:f[2]},r++)),o=f[3];continue}a.push(y.jsx("span",{children:o},r++));break}return a.length>0?a:n}function BT(n){if(!n)return"";try{const a=JSON.parse(n);return Array.isArray(a)?a.map(o=>o.type==="text"&&o.text?o.text:(o.type==="thinking"&&o.thinking||o.type==="tool_use",null)).filter(Boolean).join(`
73
- `)||null:a.type==="text"&&a.text?a.text:a.type==="result"&&a.result?a.result:null}catch{return n.length>5?n:null}}function LT(n,a){const o=[];for(const r of n)o.push({timestamp:r.timestamp,from:r.from,text:r.text,isQuery:r.isQuery});for(const r of a.slice(-30)){const u=BT(r.text);if(!u)continue;o.some(d=>Math.abs(d.timestamp-r.timestamp)<2e3&&d.from==="agent")||o.push({timestamp:r.timestamp,from:"agent",text:u.slice(0,500)})}return o.sort((r,u)=>r.timestamp-u.timestamp),o}const Kt={container:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},timeline:{flex:1,overflowY:"auto",padding:"10px 0"},hint:{color:"var(--text-dim)",fontSize:11,padding:"20px 4px",textAlign:"center",lineHeight:1.6},entry:{padding:"4px 0",position:"relative"},userMsg:{display:"flex",flexDirection:"column",gap:2},userLabel:{fontSize:10,fontWeight:600,color:"var(--accent)",textTransform:"uppercase",letterSpacing:.5},userText:{fontSize:12,color:"var(--text-bright)",lineHeight:1.5,padding:"4px 8px",background:"var(--bg-surface)",borderRadius:2,border:"1px solid var(--border)",whiteSpace:"pre-wrap",wordBreak:"break-word"},agentMsg:{display:"flex",flexDirection:"column",gap:2},agentLabel:{fontSize:10,fontWeight:600,color:"var(--green)",textTransform:"uppercase",letterSpacing:.5},agentText:{fontSize:12,color:"var(--text-primary)",lineHeight:1.5,padding:"4px 8px",background:"var(--bg-base)",borderRadius:2,whiteSpace:"pre-wrap",wordBreak:"break-word"},systemMsg:{fontSize:10,color:"var(--text-dim)",fontStyle:"italic",padding:"2px 0"},time:{position:"absolute",top:4,right:0,fontSize:9,color:"var(--text-muted)"},statusMsg:{fontSize:11,color:"var(--text-dim)",fontStyle:"italic",padding:"6px 0"},inputRow:{display:"flex",gap:6,padding:"8px 0 0",borderTop:"1px solid var(--border)"},input:{flex:1,background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"8px 10px",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font)",outline:"none"},sendBtn:{padding:"8px 14px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:11,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"},cursor:{color:"var(--accent)",fontWeight:400,animation:"pulse 1s infinite",marginLeft:1},launchBox:{padding:"8px 0",borderTop:"1px solid var(--border)",flexShrink:0},launchHeader:{fontSize:10,fontWeight:700,color:"var(--text-bright)",marginBottom:6},launchList:{display:"flex",flexDirection:"column",gap:3,marginBottom:8},launchAgent:{display:"flex",alignItems:"baseline",gap:6,fontSize:10,padding:"2px 0"},launchRole:{fontWeight:600,color:"var(--accent)",minWidth:60},launchPrompt:{color:"var(--text-dim)",fontSize:9,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},launchBtn:{width:"100%",padding:"8px",background:"rgba(51, 175, 188, 0.1)",border:"1px solid var(--accent)",color:"var(--accent)",fontSize:11,fontWeight:700,fontFamily:"var(--font)",cursor:"pointer",letterSpacing:.5}};function UT({agent:n}){var g;const a=Mt(m=>m.activityLog),o=Mt(m=>m.tokenTimeline),r=a[n.id]||[],u=o[n.id]||[],f=Math.round((n.contextUsage||0)*100),d=n.spawnedAt?qT(Date.now()-new Date(n.spawnedAt).getTime()):"-",h=n.spawnedAt&&n.tokensUsed>0?Math.round(n.tokensUsed/((Date.now()-new Date(n.spawnedAt).getTime())/6e4)):0;return y.jsxs("div",{style:oe.container,children:[y.jsxs("div",{style:oe.metricsGrid,children:[y.jsx(vs,{label:"Tokens",value:((g=n.tokensUsed)==null?void 0:g.toLocaleString())||"0"}),y.jsx(vs,{label:"Burn Rate",value:`${h}/min`}),y.jsx(vs,{label:"Uptime",value:d}),y.jsx(vs,{label:"Activity",value:`${r.length} events`})]}),y.jsxs("div",{style:{marginTop:16},children:[y.jsx("div",{style:oe.sectionLabel,children:"TOKEN HEARTBEAT"}),y.jsx(kT,{data:u,isAlive:n.status==="running"})]}),y.jsxs("div",{style:{marginTop:16},children:[y.jsx("div",{style:oe.sectionLabel,children:"CONTEXT USAGE"}),y.jsxs("div",{style:oe.gaugeRow,children:[y.jsx("div",{style:oe.gaugeTrack,children:y.jsx("div",{style:{height:"100%",width:`${f}%`,borderRadius:1,background:f>80?"var(--red)":f>60?"var(--amber)":"var(--green)",transition:"width 0.3s"}})}),y.jsxs("span",{style:oe.gaugeLabel,children:[f,"%"]})]})]}),y.jsxs("div",{style:{marginTop:16},children:[y.jsx("div",{style:oe.sectionLabel,children:"ACTIVITY PULSE"}),y.jsx(YT,{activity:r})]}),y.jsxs("div",{style:{marginTop:16},children:[y.jsx("div",{style:oe.sectionLabel,children:"DETAILS"}),y.jsxs("div",{style:oe.infoList,children:[y.jsx(li,{label:"ID",value:n.id}),y.jsx(li,{label:"Role",value:n.role}),y.jsx(li,{label:"Provider",value:n.provider}),y.jsx(li,{label:"Model",value:n.model||"default"}),y.jsx(li,{label:"Scope",value:(n.scope||[]).join(", ")||"unrestricted"}),y.jsx(li,{label:"Spawned",value:n.spawnedAt?new Date(n.spawnedAt).toLocaleTimeString():"-"}),y.jsx(li,{label:"Last Active",value:n.lastActivity?new Date(n.lastActivity).toLocaleTimeString():"-"})]})]}),n.prompt&&y.jsxs("div",{style:{marginTop:16},children:[y.jsx("div",{style:oe.sectionLabel,children:"ORIGINAL PROMPT"}),y.jsx("div",{style:oe.promptBox,children:n.prompt})]}),y.jsxs("div",{style:{marginTop:16},children:[y.jsxs("div",{style:oe.sectionLabel,children:["RECENT LOG (",r.length,")"]}),y.jsxs("div",{style:oe.logScroll,children:[r.length===0&&y.jsx("div",{style:{color:"var(--text-dim)",fontSize:11,padding:8},children:"No activity yet..."}),r.slice(-30).reverse().map((m,x)=>{var p;return y.jsxs("div",{style:oe.logEntry,children:[y.jsx("span",{style:oe.logTime,children:new Date(m.timestamp).toLocaleTimeString()}),y.jsx("span",{style:oe.logText,children:(p=m.text)==null?void 0:p.slice(0,200)})]},x)})]})]})]})}function kT({data:n,isAlive:a}){const o=X.useRef();return X.useEffect(()=>{const r=o.current;if(!r)return;const u=r.getContext("2d"),f=r.width,d=r.height;u.clearRect(0,0,f,d),u.strokeStyle="#3e4451",u.lineWidth=.5;for(let S=0;S<d;S+=d/4)u.beginPath(),u.moveTo(0,S),u.lineTo(f,S),u.stroke();if(n.length<2){u.strokeStyle=a?"#5c6370":"#3e4451",u.lineWidth=1,u.beginPath(),u.moveTo(0,d/2),u.lineTo(f,d/2),u.stroke(),a&&(u.fillStyle="#5c6370",u.font="10px monospace",u.fillText("waiting for data...",8,d/2-6));return}const h=n.map(S=>S.v),g=Math.min(...h),m=Math.max(...h),x=m-g||1,p=[];for(let S=1;S<h.length;S++){const w=h[S]-h[S-1];w>x*.2&&w>0&&p.push(S)}const b=u.createLinearGradient(0,0,0,d);b.addColorStop(0,a?"rgba(51, 175, 188, 0.15)":"rgba(92, 99, 112, 0.1)"),b.addColorStop(1,"transparent"),u.beginPath(),u.moveTo(0,d);for(let S=0;S<n.length;S++){const w=S/(n.length-1)*f,M=d-4-(h[S]-g)/x*(d-8);u.lineTo(w,M)}u.lineTo(f,d),u.closePath(),u.fillStyle=b,u.fill(),u.strokeStyle=a?"#33afbc":"#5c6370",u.lineWidth=1.5,u.beginPath();for(let S=0;S<n.length;S++){const w=S/(n.length-1)*f,M=d-4-(h[S]-g)/x*(d-8);S===0?u.moveTo(w,M):u.lineTo(w,M)}u.stroke();for(const S of p){const w=S/(n.length-1)*f,M=d-4-(h[S]-g)/x*(d-8);u.fillStyle="#e5c07b",u.beginPath(),u.arc(w,M,3,0,Math.PI*2),u.fill()}if(a&&n.length>0){const S=f,w=d-4-(h[h.length-1]-g)/x*(d-8);u.fillStyle="#33afbc",u.beginPath(),u.arc(S-2,w,3,0,Math.PI*2),u.fill()}u.fillStyle="#5c6370",u.font="9px monospace",u.fillText(m.toLocaleString(),4,10),u.fillText(g.toLocaleString(),4,d-2)},[n,a]),y.jsx("div",{style:oe.chartContainer,children:y.jsx("canvas",{ref:o,width:400,height:60,style:{width:"100%",height:60,display:"block"}})})}function YT({activity:n}){const o=Date.now(),r=300*1e3,u=r/40,f=new Array(40).fill(0);for(const g of n){const m=o-g.timestamp;if(m>r)continue;const x=Math.min(Math.floor((r-m)/u),39);f[x]++}const d=Math.max(...f,1),h=f.map((g,m)=>{const x=m/39*300,p=28-g/d*24;return`${x},${p}`}).join(" ");return y.jsx("div",{style:oe.chartContainer,children:y.jsxs("svg",{width:"100%",height:"32",viewBox:"0 0 300 32",preserveAspectRatio:"none",style:{display:"block"},children:[y.jsx("polyline",{points:h,fill:"none",stroke:"var(--green)",strokeWidth:"1",opacity:"0.6"}),y.jsx("line",{x1:"0",y1:"31",x2:"300",y2:"31",stroke:"var(--text-muted)",strokeWidth:"0.5"})]})})}function vs({label:n,value:a}){return y.jsxs("div",{style:oe.metric,children:[y.jsx("div",{style:{fontSize:14,fontWeight:700,color:"var(--text-bright)"},children:a}),y.jsx("div",{style:{fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1},children:n})]})}function li({label:n,value:a}){return y.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"3px 0"},children:[y.jsx("span",{style:{color:"var(--text-dim)",fontSize:11},children:n}),y.jsx("span",{style:{color:"var(--text-primary)",fontSize:11,maxWidth:"65%",textAlign:"right",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a})]})}function qT(n){const a=Math.floor(n/1e3),o=Math.floor(a/60),r=Math.floor(o/60);return r>0?`${r}h ${o%60}m`:o>0?`${o}m ${a%60}s`:`${a}s`}const oe={container:{flex:1,overflowY:"auto",padding:"10px 0"},metricsGrid:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:6},metric:{background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:10,textAlign:"center"},sectionLabel:{fontSize:11,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5,marginBottom:6,fontWeight:600},gaugeRow:{display:"flex",alignItems:"center",gap:8},gaugeTrack:{flex:1,height:4,background:"var(--text-muted)",borderRadius:2,overflow:"hidden"},gaugeLabel:{fontSize:12,color:"var(--text-primary)",fontWeight:600,minWidth:36,textAlign:"right"},chartContainer:{background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",overflow:"hidden"},infoList:{borderTop:"1px solid var(--border)",paddingTop:6},promptBox:{background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2,padding:8,fontSize:12,color:"var(--text-primary)",lineHeight:1.5,whiteSpace:"pre-wrap"},logScroll:{maxHeight:160,overflowY:"auto",background:"var(--bg-base)",borderRadius:2,border:"1px solid var(--border)"},logEntry:{padding:"3px 8px",borderBottom:"1px solid var(--bg-surface)",fontSize:10,display:"flex",gap:6},logTime:{color:"var(--text-dim)",whiteSpace:"nowrap"},logText:{color:"var(--text-primary)",wordBreak:"break-word"}};function VT({agent:n}){const a=Mt(K=>K.killAgent),o=Mt(K=>K.rotateAgent),r=Mt(K=>K.spawnAgent),u=Mt(K=>K.instructAgent),f=Mt(K=>K.showStatus),d=Mt(K=>K.closeDetail),[h,g]=X.useState(!1),[m,x]=X.useState(!1),[p,b]=X.useState(""),[S,w]=X.useState(!1),[M,C]=X.useState(n.model||""),[T,N]=X.useState([]),_=n.status==="running"||n.status==="starting";X.useEffect(()=>{fetch("/api/providers").then(K=>K.json()).then(N).catch(()=>{})},[]);const j=T.find(K=>K.id===n.provider),V=(j==null?void 0:j.models)||[];async function D(){try{await o(n.id)}catch(K){f(`rotate failed: ${K.message}`)}}async function B(){if(!h){g(!0),setTimeout(()=>g(!1),3e3);return}try{await a(n.id),f(`${n.name} killed`)}catch(K){f(`kill failed: ${K.message}`)}g(!1)}async function Q(){if(!m){x(!0),setTimeout(()=>x(!1),3e3);return}try{await a(n.id,!0),d(),f(`${n.name} deleted`)}catch(K){f(`delete failed: ${K.message}`)}x(!1)}async function J(){try{const K=await r({role:n.role,scope:n.scope,prompt:n.prompt,provider:n.provider,model:n.model});f(`cloned as ${K.name}`)}catch(K){f(`clone failed: ${K.message}`)}}async function at(K){C(K);try{await fetch(`/api/agents/${n.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:K||null})}),f(`model set to ${K||"default"} (takes effect on next rotation)`)}catch(R){f(`model change failed: ${R.message}`)}}async function $(){if(p.trim())try{await u(n.id,p.trim()),w(!1),b("")}catch(K){f(`prompt update failed: ${K.message}`)}}async function I(){try{await a(n.id,!0);const K=await r({role:n.role,scope:n.scope,prompt:n.prompt,provider:n.provider,model:n.model});f(`restarted as ${K.name}`)}catch(K){f(`restart failed: ${K.message}`)}}return y.jsxs("div",{style:re.container,children:[y.jsx("div",{style:re.sectionLabel,children:"LIFECYCLE"}),y.jsxs("div",{style:re.btnGrid,children:[_&&y.jsxs(y.Fragment,{children:[y.jsx(mo,{icon:"~",label:"Rotate",desc:"Fresh context + handoff brief",onClick:D,color:"var(--accent)"}),y.jsx(mo,{icon:"||",label:h?"Confirm Kill":"Stop",desc:"Stop the agent process",onClick:B,color:h?"var(--red)":"var(--amber)"})]}),!_&&y.jsx(mo,{icon:">",label:"Restart",desc:"Spawn fresh with same config",onClick:I,color:"var(--green)"}),y.jsx(mo,{icon:"+",label:"Clone",desc:"Spawn duplicate agent",onClick:J,color:"var(--accent)"}),y.jsx(mo,{icon:"x",label:m?"Confirm Delete":"Delete",desc:"Kill and remove permanently",onClick:Q,color:m?"var(--red)":"var(--text-dim)"})]}),y.jsxs("div",{style:{...re.sectionLabel,marginTop:20},children:["MODEL ",n.routingMode==="auto"&&y.jsx("span",{style:{color:"var(--accent)",fontWeight:400,textTransform:"none"},children:" — auto-routed"})]}),y.jsxs("select",{style:re.select,value:M,onChange:K=>at(K.target.value),children:[y.jsx("option",{value:"",children:"Default"}),V.map(K=>y.jsxs("option",{value:K.id,children:[K.name," (",K.tier,")"]},K.id))]}),y.jsx("div",{style:re.fieldHint,children:"Changes take effect on next rotation"}),y.jsx("div",{style:{...re.sectionLabel,marginTop:20},children:"PROMPT"}),n.prompt&&!S&&y.jsxs("div",{style:re.currentPrompt,children:[y.jsx("div",{style:re.promptText,children:n.prompt}),_&&y.jsx("button",{onClick:()=>{w(!0),b("")},style:re.editBtn,children:"Send New Instruction"})]}),!n.prompt&&!S&&y.jsx("div",{style:re.noPrompt,children:"No prompt set"}),S&&y.jsxs("div",{children:[y.jsx("textarea",{style:re.textarea,value:p,onChange:K=>b(K.target.value),placeholder:"New instruction for this agent...",rows:4,autoFocus:!0}),y.jsxs("div",{style:{display:"flex",gap:6,marginTop:6},children:[y.jsx("button",{onClick:$,style:re.saveBtn,disabled:!p.trim(),children:"Send (rotates agent)"}),y.jsx("button",{onClick:()=>w(!1),style:re.cancelBtn,children:"Cancel"})]})]}),y.jsx("div",{style:{...re.sectionLabel,marginTop:20},children:"CONFIGURATION"}),y.jsx(la,{label:"ID",value:n.id}),y.jsx(la,{label:"Role",value:n.role}),y.jsx(la,{label:"Provider",value:n.provider}),y.jsx(la,{label:"Model",value:n.routingMode==="auto"?`auto (${n.model||"pending"})`:n.model||"default"}),y.jsx(la,{label:"Scope",value:(n.scope||[]).join(", ")||"unrestricted"}),y.jsx(la,{label:"Status",value:n.status})]})}function mo({icon:n,label:a,desc:o,onClick:r,color:u}){return y.jsxs("button",{onClick:r,style:{...re.actionBtn,borderColor:u},children:[y.jsx("span",{style:{...re.actionIcon,color:u},children:n}),y.jsxs("div",{children:[y.jsx("div",{style:re.actionTitle,children:a}),y.jsx("div",{style:re.actionDesc,children:o})]})]})}function la({label:n,value:a}){return y.jsxs("div",{style:re.configRow,children:[y.jsx("span",{style:{color:"var(--text-dim)",fontSize:11,minWidth:60},children:n}),y.jsx("span",{style:{color:"var(--text-primary)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a})]})}const re={container:{flex:1,overflowY:"auto",padding:"10px 0"},sectionLabel:{fontSize:11,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5,marginBottom:8,fontWeight:600},btnGrid:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},actionBtn:{display:"flex",alignItems:"center",gap:8,padding:"8px 10px",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,cursor:"pointer",textAlign:"left",fontFamily:"var(--font)"},actionIcon:{fontSize:14,fontWeight:700,width:18,textAlign:"center",flexShrink:0},actionTitle:{fontSize:11,color:"var(--text-primary)",fontWeight:600},actionDesc:{fontSize:9,color:"var(--text-dim)",marginTop:1},select:{width:"100%",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font)",outline:"none"},fieldHint:{fontSize:10,color:"var(--text-muted)",marginTop:4},currentPrompt:{},promptText:{background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2,padding:8,fontSize:12,color:"var(--text-primary)",lineHeight:1.5,whiteSpace:"pre-wrap",maxHeight:100,overflowY:"auto"},noPrompt:{fontSize:12,color:"var(--text-dim)",fontStyle:"italic"},editBtn:{marginTop:6,padding:"4px 10px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:11,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"},textarea:{width:"100%",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font)",outline:"none",resize:"vertical"},saveBtn:{flex:1,padding:"6px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:11,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"},cancelBtn:{padding:"6px 12px",background:"transparent",border:"1px solid var(--border)",borderRadius:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font)",cursor:"pointer"},configRow:{display:"flex",gap:8,padding:"3px 0",borderBottom:"1px solid var(--bg-surface)"}},XT=[{id:"chat",label:"Chat"},{id:"stats",label:"Stats"},{id:"actions",label:"Actions"}],GT={running:"var(--green)",starting:"var(--amber)",stopped:"var(--text-dim)",crashed:"var(--red)",completed:"var(--accent)",killed:"var(--text-dim)"};function $T(){const[n,a]=X.useState("chat"),o=Mt(h=>h.detailPanel),u=Mt(h=>h.agents).find(h=>h.id===(o==null?void 0:o.agentId));if(!u)return y.jsx("div",{style:Ml.empty,children:"Agent not found"});const f=GT[u.status]||"var(--text-dim)",d=u.status==="running"||u.status==="starting";return y.jsxs("div",{style:Ml.container,children:[y.jsxs("div",{style:Ml.agentHeader,children:[y.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[y.jsx("div",{style:{width:6,height:6,borderRadius:"50%",background:f,animation:d?"pulse 2s infinite":"none"}}),y.jsx("span",{style:Ml.agentName,children:u.name}),y.jsx("span",{style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:.5,color:f,padding:"1px 6px",borderRadius:2,background:`color-mix(in srgb, ${f} 12%, transparent)`},children:u.status})]}),y.jsxs("span",{style:Ml.agentMeta,children:[u.role," / ",u.provider]})]}),y.jsx("div",{style:Ml.tabBar,children:XT.map(h=>y.jsx("button",{onClick:()=>a(h.id),style:{...Ml.tab,color:n===h.id?"var(--text-bright)":"var(--text-dim)",borderBottom:n===h.id?"2px solid var(--accent)":"2px solid transparent"},children:h.label},h.id))}),y.jsxs("div",{style:Ml.tabContent,children:[n==="chat"&&y.jsx(RT,{agent:u}),n==="stats"&&y.jsx(UT,{agent:u}),n==="actions"&&y.jsx(VT,{agent:u})]})]})}const Ml={container:{display:"flex",flexDirection:"column",height:"100%"},agentHeader:{padding:"12px 0 8px",display:"flex",justifyContent:"space-between",alignItems:"center",borderBottom:"1px solid var(--border)"},agentName:{fontSize:14,fontWeight:600,color:"var(--text-bright)"},agentMeta:{fontSize:11,color:"var(--text-dim)"},tabBar:{display:"flex",gap:0,borderBottom:"1px solid var(--border)"},tab:{padding:"8px 16px",background:"transparent",border:"none",borderBottom:"2px solid transparent",fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:1,fontFamily:"var(--font)",cursor:"pointer"},tabContent:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column"},empty:{color:"var(--text-dim)",fontSize:12,padding:16}};function QT(){const n=Mt(o=>o.openDetail),a=Mt(o=>o.connected);return y.jsx("div",{style:rn.container,children:y.jsx("div",{style:rn.inner,children:a?y.jsxs(y.Fragment,{children:[y.jsx("div",{style:rn.readyIcon,children:y.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 40 40",children:[y.jsx("circle",{cx:"20",cy:"20",r:"18",fill:"none",stroke:"#2c313a",strokeWidth:"1"}),y.jsx("circle",{cx:"20",cy:"20",r:"18",fill:"none",stroke:"#33afbc",strokeWidth:"1",strokeDasharray:"113",strokeDashoffset:"28",strokeLinecap:"round",children:y.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 20 20",to:"360 20 20",dur:"3s",repeatCount:"indefinite"})}),y.jsx("text",{x:"20",y:"24",textAnchor:"middle",fill:"#33afbc",fontSize:"14",fontWeight:"700",fontFamily:"JetBrains Mono, monospace",children:"+"})]})}),y.jsx("div",{style:rn.title,children:"Ready to orchestrate"}),y.jsx("div",{style:rn.hint,children:"Spawn your first agent to start building"}),y.jsx("button",{onClick:()=>n({type:"spawn"}),style:rn.spawnBtn,children:"Spawn Agent"})]}):y.jsxs(y.Fragment,{children:[y.jsx("div",{style:rn.pulseRing,children:y.jsx("div",{style:rn.pulseCore})}),y.jsx("div",{style:rn.title,children:"Connecting to daemon..."}),y.jsx("div",{style:rn.hint,children:"Make sure the GROOVE daemon is running"}),y.jsx("code",{style:rn.code,children:"groove start"})]})})})}const rn={container:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",background:"#1a1e25"},inner:{display:"flex",flexDirection:"column",alignItems:"center",gap:12,padding:40},pulseRing:{width:40,height:40,borderRadius:"50%",border:"1px solid #33afbc",display:"flex",alignItems:"center",justifyContent:"center",animation:"pulse 2s infinite"},pulseCore:{width:8,height:8,borderRadius:"50%",background:"#33afbc",boxShadow:"0 0 12px rgba(51, 175, 188, 0.5)"},readyIcon:{marginBottom:4},title:{fontSize:14,color:"#e6e6e6",fontWeight:600,letterSpacing:.5},hint:{fontSize:12,color:"#6b7280",textAlign:"center",lineHeight:1.6,maxWidth:360},spawnBtn:{padding:"8px 24px",background:"rgba(51, 175, 188, 0.1)",border:"1px solid #33afbc",color:"#33afbc",fontSize:12,fontWeight:600,fontFamily:"'JetBrains Mono', monospace",cursor:"pointer",marginTop:4,transition:"background 0.2s"},code:{background:"#252a33",padding:"8px 16px",fontSize:11,color:"#33afbc",border:"1px solid #2c313a"}},py=[{id:"backend",label:"Backend",desc:"APIs, server logic, database",scope:["src/api/**","src/server/**","src/lib/**","src/db/**"]},{id:"frontend",label:"Frontend",desc:"UI components, views, styles",scope:["src/components/**","src/views/**","src/pages/**","src/styles/**"]},{id:"fullstack",label:"Fullstack",desc:"Full codebase access",scope:[]},{id:"planner",label:"Planner",desc:"Architecture, research, planning",scope:[]},{id:"testing",label:"Testing",desc:"Tests, specs, coverage",scope:["tests/**","test/**","**/*.test.*","**/*.spec.*"]},{id:"devops",label:"DevOps",desc:"Docker, CI/CD, infra",scope:["Dockerfile*","docker-compose*",".github/**","infra/**"]},{id:"docs",label:"Docs",desc:"Documentation, READMEs",scope:["docs/**","*.md"]}],ZT=[{id:"auto",label:"Auto",desc:"AI PM reviews risky operations before they happen",icon:"~"},{id:"full",label:"Full Send",desc:"No reviews, maximum speed",icon:">"}];function KT(){const n=Mt(U=>U.spawnAgent),a=Mt(U=>U.closeDetail),[o,r]=X.useState(""),[u,f]=X.useState(""),[d,h]=X.useState(""),[g,m]=X.useState(""),[x,p]=X.useState("auto"),[b,S]=X.useState("claude-code"),[w,M]=X.useState("auto"),[C,T]=X.useState([]),[N,_]=X.useState(!1),[j,V]=X.useState(""),[D,B]=X.useState(!1),[Q,J]=X.useState(null),[at,$]=X.useState(""),[I,K]=X.useState(!1);X.useEffect(()=>{R()},[]);async function R(){try{const U=await fetch("/api/providers");T(await U.json())}catch{}}const Z=py.find(U=>U.id===o),z=o==="custom"?d:(Z==null?void 0:Z.scope.join(", "))||"",L=o==="planner";function k(U){if(U.installed&&(U.authType==="subscription"||U.authType==="local"||U.hasKey)){S(U.id),M("auto"),J(null);return}J(U.id),$("")}async function q(){if(!(!at.trim()||!Q)){K(!0);try{await fetch(`/api/credentials/${Q}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:at.trim()})}),$(""),J(null),S(Q),M("auto"),await R()}catch{}K(!1)}}async function tt(U){U.preventDefault();const nt=o==="custom"?u:o;if(!nt){V("Select a role");return}_(!0),V("");try{const rt=z?z.split(",").map(ct=>ct.trim()).filter(Boolean):[];await n({role:nt,scope:rt,prompt:g||null,model:w||"auto",provider:b,permission:x}),a()}catch(rt){V(rt.message)}finally{_(!1)}}function A(U){return U.installed?U.authType==="api-key"&&!U.hasKey?"needs key":U.authType==="subscription"?"subscription":U.authType==="local"?"local":"ready":"not installed"}function H(U){return!(!U.installed||U.authType==="api-key"&&!U.hasKey)}return y.jsxs("div",{style:{paddingTop:4},children:[y.jsx("div",{style:Et.title,children:"SPAWN AGENT"}),y.jsxs("form",{onSubmit:tt,children:[y.jsx("div",{style:Et.label,children:"ROLE"}),y.jsxs("div",{style:Et.roleGrid,children:[py.map(U=>y.jsx("button",{type:"button",onClick:()=>r(U.id),style:{...Et.roleBtn,...o===U.id?Et.roleBtnActive:{}},title:U.desc,children:U.label},U.id)),y.jsx("button",{type:"button",onClick:()=>r("custom"),style:{...Et.roleBtn,...o==="custom"?Et.roleBtnActive:{}},children:"Custom"})]}),Z&&y.jsx("div",{style:Et.roleDesc,children:Z.desc}),o==="custom"&&y.jsx("input",{style:{...Et.input,marginTop:6},placeholder:"Custom role name...",value:u,onChange:U=>f(U.target.value),autoFocus:!0}),y.jsx("div",{style:Et.label,children:L?"WHAT TO PLAN":"TASK PROMPT"}),y.jsx("textarea",{style:Et.textarea,placeholder:L?"What should this agent research or plan?":"What should this agent work on?",value:g,onChange:U=>m(U.target.value),rows:3}),y.jsx("div",{style:Et.label,children:"PERMISSIONS"}),y.jsx("div",{style:Et.permGrid,children:ZT.map(U=>y.jsxs("button",{type:"button",onClick:()=>p(U.id),style:{...Et.permBtn,...x===U.id?Et.permBtnActive:{}},children:[y.jsx("span",{style:Et.permIcon,children:U.icon}),y.jsxs("div",{children:[y.jsx("div",{style:Et.permLabel,children:U.label}),y.jsx("div",{style:Et.permDesc,children:U.desc})]})]},U.id))}),y.jsx("button",{type:"button",onClick:()=>B(!D),style:Et.advancedToggle,children:D?"- hide advanced":"+ advanced options"}),D&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Et.label,children:"PROVIDER"}),C.map(U=>{const nt=H(U),rt=A(U),ut=b===U.id,ct=Q===U.id;return y.jsxs("div",{style:{marginBottom:2},children:[y.jsxs("button",{type:"button",onClick:()=>k(U),style:{...Et.providerBtn,borderColor:ut?"var(--accent)":"var(--border)",opacity:nt||ct?1:.6},children:[y.jsxs("div",{style:{flex:1},children:[y.jsx("span",{style:{fontSize:12,fontWeight:600,color:ut?"var(--text-bright)":"var(--text-primary)"},children:U.name}),y.jsx("span",{style:Et.providerModels,children:U.models.map(st=>st.name).join(", ")})]}),y.jsx("span",{style:{fontSize:10,color:nt?"var(--green)":rt==="not installed"?"var(--text-muted)":"var(--amber)"},children:nt?ut?"active":"ready":rt})]}),ct&&y.jsxs("div",{style:Et.connectBox,children:[!U.installed&&y.jsxs("div",{children:[y.jsx("div",{style:Et.connectLabel,children:"Install first:"}),y.jsx("code",{style:Et.connectCode,children:U.installCommand}),y.jsx("div",{style:Et.connectHint,children:"Run this in your terminal, then click the provider again"})]}),U.installed&&U.authType==="api-key"&&!U.hasKey&&y.jsxs("div",{children:[y.jsxs("div",{style:Et.connectLabel,children:["API Key ",U.envKey?`(${U.envKey})`:""]}),y.jsxs("div",{style:{display:"flex",gap:4},children:[y.jsx("input",{type:"password",style:Et.input,placeholder:"sk-...",value:at,onChange:st=>$(st.target.value),onKeyDown:st=>st.key==="Enter"&&(st.preventDefault(),q())}),y.jsx("button",{type:"button",onClick:q,disabled:I||!at.trim(),style:Et.connectSaveBtn,children:I?"...":"Save"})]}),y.jsx("div",{style:Et.connectHint,children:"Encrypted locally. Never sent to GROOVE servers."})]}),U.installed&&U.authType==="subscription"&&y.jsxs("div",{children:[y.jsx("div",{style:Et.connectLabel,children:"Subscription auth"}),y.jsxs("div",{style:Et.connectHint,children:[U.name," uses your existing subscription. Make sure you're logged in via the CLI."]})]}),U.installed&&U.authType==="local"&&y.jsxs("div",{children:[y.jsx("div",{style:Et.connectLabel,children:"Local model"}),y.jsxs("div",{style:Et.connectHint,children:["Make sure ",U.name," is running locally. No API key needed."]})]}),y.jsx("button",{type:"button",onClick:()=>J(null),style:Et.connectCancel,children:"cancel"})]})]},U.id)}),(()=>{const U=C.find(rt=>rt.id===b),nt=(U==null?void 0:U.models)||[];return nt.length===0?null:y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Et.label,children:"MODEL"}),y.jsxs("select",{style:Et.input,value:w,onChange:rt=>M(rt.target.value),children:[y.jsx("option",{value:"auto",children:"Auto (recommended)"}),nt.map(rt=>y.jsxs("option",{value:rt.id,children:[rt.name," (",rt.tier,")"]},rt.id))]})]})})(),y.jsx("div",{style:Et.label,children:"FILE SCOPE"}),y.jsx("input",{style:Et.input,placeholder:"e.g. src/api/**, src/lib/**",value:o==="custom"?d:z,onChange:U=>{o==="custom"&&h(U.target.value)},readOnly:o!=="custom"}),y.jsx("div",{style:Et.hint,children:o==="custom"?"Comma-separated glob patterns":"Auto-set by role preset"})]}),j&&y.jsx("div",{style:Et.error,children:j}),y.jsx("button",{type:"submit",disabled:N,style:{...Et.submitBtn,opacity:N?.5:1},children:N?"spawning...":L?"Start Planning":"Spawn Agent"})]})]})}const Et={title:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5,marginBottom:14},label:{fontSize:11,color:"var(--text-dim)",marginBottom:4,marginTop:12,textTransform:"uppercase",letterSpacing:1.5,fontWeight:600},roleGrid:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},roleBtn:{background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 4px",color:"var(--text-primary)",fontSize:11,cursor:"pointer",fontFamily:"var(--font)",transition:"color 0.1s, border-color 0.1s"},roleBtnActive:{borderColor:"var(--accent)",color:"var(--text-bright)"},roleDesc:{fontSize:10,color:"var(--text-dim)",marginTop:4,fontStyle:"italic"},permGrid:{display:"flex",flexDirection:"column",gap:4},permBtn:{display:"flex",alignItems:"center",gap:10,padding:"8px 10px",width:"100%",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,cursor:"pointer",textAlign:"left",fontFamily:"var(--font)"},permBtnActive:{borderColor:"var(--accent)"},permIcon:{fontSize:14,fontWeight:700,color:"var(--accent)",width:18,textAlign:"center",flexShrink:0},permLabel:{fontSize:11,color:"var(--text-bright)",fontWeight:600},permDesc:{fontSize:10,color:"var(--text-dim)"},advancedToggle:{background:"none",border:"none",color:"var(--text-dim)",fontSize:10,cursor:"pointer",fontFamily:"var(--font)",padding:"8px 0",marginTop:8},providerBtn:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"8px 10px",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,cursor:"pointer",textAlign:"left",fontFamily:"var(--font)"},providerModels:{fontSize:10,color:"var(--text-dim)",marginLeft:6},connectBox:{padding:"8px 10px",margin:"2px 0 4px",background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2},connectLabel:{fontSize:11,color:"var(--text-primary)",fontWeight:600,marginBottom:4},connectCode:{display:"block",padding:"6px 8px",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,fontSize:11,color:"var(--accent)",wordBreak:"break-all"},connectHint:{fontSize:10,color:"var(--text-dim)",marginTop:4},connectSaveBtn:{padding:"6px 12px",flexShrink:0,background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:11,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"},connectCancel:{background:"none",border:"none",color:"var(--text-dim)",fontSize:10,cursor:"pointer",fontFamily:"var(--font)",padding:"4px 0",marginTop:4},input:{width:"100%",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",color:"var(--text-primary)",fontSize:12,outline:"none",fontFamily:"var(--font)"},textarea:{width:"100%",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",color:"var(--text-primary)",fontSize:12,outline:"none",fontFamily:"var(--font)",resize:"vertical"},hint:{fontSize:10,color:"var(--text-muted)",marginTop:3},error:{color:"var(--red)",fontSize:11,marginTop:8},submitBtn:{width:"100%",marginTop:14,padding:"8px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:12,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"}};function JT(){var d;const[n,a]=X.useState(null),[o,r]=X.useState(!0);X.useEffect(()=>{u();const h=setInterval(u,1e4);return()=>clearInterval(h)},[]);async function u(){try{const h=await fetch("/api/journalist");a(await h.json())}catch{}r(!1)}async function f(){r(!0);try{await fetch("/api/journalist/cycle",{method:"POST"}),await u()}catch{}r(!1)}return y.jsxs("div",{style:{paddingTop:4},children:[y.jsxs("div",{style:Se.header,children:[y.jsx("span",{style:Se.title,children:"THE JOURNALIST"}),y.jsx("button",{onClick:f,disabled:o,style:Se.btn,children:o?"synthesizing...":"Run Cycle"})]}),y.jsxs("div",{style:Se.statusRow,children:[y.jsxs("span",{children:["Status: ",n!=null&&n.running?"active":"stopped"]}),y.jsxs("span",{children:["Cycles: ",(n==null?void 0:n.cycleCount)||0]}),(n==null?void 0:n.lastCycleAt)&&y.jsxs("span",{children:["Last: ",new Date(n.lastCycleAt).toLocaleTimeString()]})]}),n!=null&&n.lastSynthesis?y.jsxs("div",{children:[y.jsx("div",{style:Se.sectionLabel,children:"SUMMARY"}),y.jsx("div",{style:Se.textBox,children:n.lastSynthesis.summary}),n.lastSynthesis.projectMap&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Se.sectionLabel,children:"PROJECT MAP"}),y.jsx("pre",{style:Se.codeBox,children:n.lastSynthesis.projectMap})]}),n.lastSynthesis.decisions&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Se.sectionLabel,children:"DECISIONS"}),y.jsx("pre",{style:Se.codeBox,children:n.lastSynthesis.decisions})]})]}):y.jsx("div",{style:Se.empty,children:"No synthesis yet. The Journalist runs every 2 minutes when agents are active."}),((d=n==null?void 0:n.history)==null?void 0:d.length)>0&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Se.sectionLabel,children:"HISTORY"}),y.jsx("div",{style:Se.historyList,children:n.history.slice().reverse().map((h,g)=>{var m;return y.jsxs("div",{style:Se.historyEntry,children:[y.jsx("span",{style:Se.historyTime,children:new Date(h.timestamp).toLocaleTimeString()}),y.jsxs("span",{style:Se.historyText,children:["Cycle ",h.cycle,": ",h.agentCount," agent",h.agentCount!==1?"s":""," — ",(m=h.summary)==null?void 0:m.slice(0,80)]})]},g)})})]})]})}const Se={header:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},title:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5},btn:{padding:"3px 10px",background:"transparent",border:"1px solid var(--purple)",borderRadius:2,color:"var(--purple)",fontSize:11,cursor:"pointer",fontFamily:"var(--font)"},statusRow:{display:"flex",gap:12,fontSize:11,color:"var(--text-dim)",marginBottom:12,padding:"6px 0",borderBottom:"1px solid var(--border)",flexWrap:"wrap"},sectionLabel:{fontSize:11,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5,marginBottom:4,marginTop:12,fontWeight:600},textBox:{background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2,padding:8,fontSize:12,color:"var(--text-primary)",lineHeight:1.5},codeBox:{background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2,padding:8,fontSize:11,color:"var(--text-dim)",lineHeight:1.5,whiteSpace:"pre-wrap",maxHeight:200,overflowY:"auto",margin:0},empty:{color:"var(--text-dim)",fontSize:12,padding:16,textAlign:"center"},historyList:{maxHeight:160,overflowY:"auto",background:"var(--bg-base)",borderRadius:2,border:"1px solid var(--border)"},historyEntry:{padding:"4px 8px",borderBottom:"1px solid var(--bg-surface)",fontSize:10,display:"flex",gap:6},historyTime:{color:"var(--text-dim)",whiteSpace:"nowrap"},historyText:{color:"var(--text-primary)"}};function WT(){const[n,a]=X.useState([]),[o,r]=X.useState(null),[u,f]=X.useState(!1),[d,h]=X.useState(""),g=Mt(S=>S.showStatus);X.useEffect(()=>{m();const S=setInterval(m,5e3);return()=>clearInterval(S)},[]);async function m(){try{const w=await(await fetch("/api/teams")).json();a(w.teams),r(w.activeTeam)}catch{}}async function x(S){try{await fetch(`/api/teams/${encodeURIComponent(S)}/load`,{method:"POST"}),g(`loaded team "${S}"`),m()}catch{g("failed to load team")}}async function p(){if(d.trim())try{await fetch("/api/teams",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:d.trim()})}),g(`saved team "${d}"`),h(""),f(!1),m()}catch{g("failed to save team")}}async function b(S){await fetch(`/api/teams/${encodeURIComponent(S)}`,{method:"DELETE"}),g(`deleted "${S}"`),m()}return y.jsxs("div",{style:Re.container,children:[y.jsx("div",{style:Re.title,children:"SAVED TEAMS"}),n.length===0?y.jsx("div",{style:Re.empty,children:"No saved teams"}):n.map(S=>y.jsxs("div",{style:{...Re.item,background:S.name===o?"var(--bg-hover)":"transparent"},children:[y.jsxs("div",{style:{flex:1},children:[y.jsxs("div",{style:Re.teamName,children:[">"," ",S.name]}),y.jsxs("div",{style:Re.teamMeta,children:[S.agents," agents"]})]}),y.jsxs("div",{style:{display:"flex",gap:8},children:[y.jsx("button",{onClick:()=>x(S.name),style:Re.loadBtn,children:"Load"}),y.jsx("button",{onClick:()=>b(S.name),style:Re.deleteBtn,children:"x"})]})]},S.name)),y.jsx("div",{style:Re.divider}),u?y.jsxs("div",{style:Re.saveRow,children:[y.jsx("input",{style:Re.saveInput,placeholder:"Team name...",value:d,onChange:S=>h(S.target.value),onKeyDown:S=>S.key==="Enter"&&p(),autoFocus:!0}),y.jsx("button",{onClick:p,style:Re.saveBtn,children:"Save"}),y.jsx("button",{onClick:()=>f(!1),style:Re.cancelBtn,children:"x"})]}):y.jsx("button",{onClick:()=>f(!0),style:Re.saveTeamBtn,children:"Save Current as Team"})]})}const Re={container:{padding:24,maxWidth:600,margin:"0 auto"},title:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5,marginBottom:16},item:{padding:"10px 12px",display:"flex",justifyContent:"space-between",alignItems:"center",borderBottom:"1px solid var(--border)"},teamName:{fontSize:12,color:"var(--text-bright)",fontWeight:600},teamMeta:{fontSize:11,color:"var(--text-dim)",marginTop:2},loadBtn:{background:"transparent",border:"none",color:"var(--accent)",fontSize:11,cursor:"pointer",fontFamily:"var(--font)",fontWeight:600},deleteBtn:{background:"none",border:"none",color:"var(--text-dim)",fontSize:12,cursor:"pointer",fontFamily:"var(--font)"},empty:{padding:20,color:"var(--text-dim)",fontSize:12,textAlign:"center"},divider:{borderTop:"1px solid var(--border)",margin:"12px 0"},saveTeamBtn:{background:"transparent",border:"1px solid var(--accent)",borderRadius:2,padding:"6px 14px",color:"var(--accent)",fontSize:12,cursor:"pointer",fontFamily:"var(--font)",fontWeight:600},saveRow:{display:"flex",gap:6,alignItems:"center"},saveInput:{flex:1,background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font)",outline:"none"},saveBtn:{padding:"6px 12px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:12,cursor:"pointer",fontFamily:"var(--font)"},cancelBtn:{background:"none",border:"none",color:"var(--text-dim)",fontSize:12,cursor:"pointer",fontFamily:"var(--font)"}},ai="#4ae168",dd="#33afbc",hd="#e5c07b",gd="#e06c75",FT="#c678dd",IT="#61afef",oa=[dd,hd,ai,FT,gd,IT,"#d19a66"],PT={medium:.009};function t3(){const[n,a]=X.useState(null),o=Mt(S=>S.agents),r=Mt(S=>S.dashTelemetry);X.useEffect(()=>{u();const S=setInterval(u,4e3);return()=>clearInterval(S)},[]);async function u(){try{const w=await(await fetch("/api/dashboard")).json();a(w),Mt.setState(M=>{const C={...M.dashTelemetry},T=Date.now();for(const N of w.agents.breakdown){C[N.id]||(C[N.id]=[]);const _=C[N.id],j=_[_.length-1];(!j||N.tokens!==j.v||T-j.t>1e4)&&(_.push({t:T,v:N.tokens||0,name:N.name}),_.length>200&&(C[N.id]=_.slice(-200)))}return{dashTelemetry:C}})}catch{}}if(!n)return y.jsxs("div",{style:Lt.loadingRoot,children:[y.jsx("div",{style:Lt.loadingText,children:"COMMAND CENTER"}),y.jsx("div",{style:Lt.loadingBar,children:y.jsx("div",{style:Lt.loadingFill})})]});const{tokens:f,routing:d,rotation:h,adaptive:g,journalist:m,uptime:x}=n,p=n.agents.breakdown,b=f.savings.total/1e3*PT.medium;return y.jsxs("div",{style:Lt.root,children:[y.jsxs("div",{style:Lt.statBar,children:[y.jsx(yo,{label:"Total Tokens",value:Cl(f.totalTokens),sub:`${n.agents.total} agent${n.agents.total!==1?"s":""}`}),y.jsx(yo,{label:"Tokens Saved",value:Cl(f.savings.total),sub:`${f.savings.percentage||0}% efficiency`,color:ai}),y.jsx(yo,{label:"Est. Savings",value:b>0?`$${b.toFixed(2)}`:"$0.00",sub:"based on token costs",color:ai}),y.jsx(yo,{label:"Rotations",value:h.totalRotations,sub:`${Cl(h.totalTokensSaved)} tok recovered`}),y.jsx(yo,{label:"Uptime",value:l3(x),sub:`${n.agents.running} running`})]}),y.jsxs("div",{style:Lt.midRow,children:[y.jsxs("div",{style:Lt.chartPanel,children:[y.jsxs("div",{style:Lt.panelHead,children:[y.jsx("span",{children:"Token Usage"}),y.jsx("span",{style:Lt.panelHeadRight,children:p.filter(S=>S.tokens>0).map((S,w)=>y.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,marginLeft:12},children:[y.jsx("span",{style:{width:6,height:2,background:oa[w%oa.length],display:"inline-block",borderRadius:1}}),y.jsx("span",{style:{fontSize:9},children:S.name})]},S.id))})]}),y.jsx(n3,{tokenTimeline:r,agents:o})]}),y.jsxs("div",{style:Lt.donutPanel,children:[y.jsx("div",{style:Lt.panelHead,children:"Model Routing"}),y.jsx(e3,{routing:d})]})]}),y.jsxs("div",{style:Lt.bottomRow,children:[y.jsxs("div",{style:Lt.panel,children:[y.jsx("div",{style:Lt.panelHead,children:"Savings Breakdown"}),y.jsxs("div",{style:Lt.scrollInner,children:[y.jsx(xs,{label:"Rotation",value:f.savings.fromRotation,max:f.savings.total||1,color:dd}),y.jsx(xs,{label:"Conflict Prevention",value:f.savings.fromConflictPrevention,max:f.savings.total||1,color:hd}),y.jsx(xs,{label:"Cold-Start Skip",value:f.savings.fromColdStartSkip,max:f.savings.total||1,color:ai}),y.jsx("div",{style:Lt.divider}),y.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:10,color:"#8b929e",padding:"4px 0"},children:[y.jsx("span",{children:"Without Groove"}),y.jsx("span",{style:{color:gd,fontWeight:600},children:Cl(f.savings.estimatedWithoutGroove)})]}),y.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:10,color:"#8b929e",padding:"4px 0"},children:[y.jsx("span",{children:"With Groove"}),y.jsx("span",{style:{color:ai,fontWeight:600},children:Cl(f.totalTokens)})]}),y.jsx("div",{style:{fontSize:8,color:"#5c6370",marginTop:4,lineHeight:1.4},children:"Calculated from: rotation recovery (30% of degraded context), cold-start prevention (2K tokens/skip), conflict avoidance (500 tokens/conflict)."}),m.lastSummary&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Lt.divider}),y.jsx("div",{style:Lt.panelHead,children:"Journalist"}),y.jsx("div",{style:Lt.journSummary,children:m.lastSummary})]})]})]}),y.jsxs("div",{style:Lt.panel,children:[y.jsx("div",{style:Lt.panelHead,children:"Agent Fleet"}),y.jsxs("div",{style:Lt.scrollInner,children:[p.length===0?y.jsx("div",{style:Lt.empty,children:"No agents spawned"}):p.map((S,w)=>y.jsx(xs,{label:S.name,value:S.tokens,max:Math.max(...p.map(M=>M.tokens),1),color:oa[w%oa.length],sub:`${S.role} · ${S.model||"auto"}`},S.id)),h.history.length>0&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Lt.divider}),y.jsx("div",{style:Lt.panelHead,children:"Rotation History"}),h.history.slice().reverse().slice(0,8).map((S,w)=>y.jsxs("div",{style:Lt.rotEntry,children:[y.jsx("span",{style:Lt.rotName,children:S.agentName}),y.jsxs("span",{style:{color:ai,fontSize:9},children:[Cl(S.oldTokens)," saved"]}),y.jsx("span",{style:Lt.rotTime,children:i3(S.timestamp)})]},w))]})]})]})]})]})}function yo({label:n,value:a,sub:o,color:r}){return y.jsxs("div",{style:Lt.statCard,children:[y.jsx("div",{style:{fontSize:10,color:"#8b929e",textTransform:"uppercase",letterSpacing:1,marginBottom:6},children:n}),y.jsx("div",{style:{fontSize:20,fontWeight:700,color:r||"#e6e6e6",lineHeight:1},children:a}),o&&y.jsx("div",{style:{fontSize:9,color:"#6b7280",marginTop:4},children:o})]})}function xs({label:n,value:a,max:o,color:r,sub:u}){const f=o>0?a/o*100:0;return y.jsxs("div",{style:{padding:"6px 0"},children:[y.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:4},children:[y.jsx("span",{style:{fontSize:11,color:"#abb2bf"},children:n}),y.jsx("span",{style:{fontSize:11,color:"#e6e6e6",fontWeight:600},children:Cl(a)})]}),y.jsx("div",{style:{height:4,background:"#1e222a",borderRadius:2},children:y.jsx("div",{style:{width:`${Math.max(f,a>0?1:0)}%`,height:"100%",background:r,borderRadius:2,transition:"width 0.3s"}})}),u&&y.jsx("div",{style:{fontSize:8,color:"#3e4451",marginTop:2},children:u})]})}function e3({routing:n}){const a=[{label:"Heavy",color:gd,count:n.byTier.heavy,cost:"$0.045/1k"},{label:"Medium",color:hd,count:n.byTier.medium,cost:"$0.009/1k"},{label:"Light",color:ai,count:n.byTier.light,cost:"$0.002/1k"}],o=a.reduce((g,m)=>g+m.count,0)||1,r=50,u=60,f=60,d=2*Math.PI*r;let h=0;return y.jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,alignItems:"center",justifyContent:"center",gap:12,minHeight:0},children:[y.jsxs("svg",{width:"120",height:"120",viewBox:"0 0 120 120",children:[y.jsx("circle",{cx:u,cy:f,r,fill:"none",stroke:"#1e222a",strokeWidth:"10"}),a.map(g=>{if(g.count===0)return null;const x=g.count/o*d,p=y.jsx("circle",{cx:u,cy:f,r,fill:"none",stroke:g.color,strokeWidth:"10",strokeDasharray:`${x} ${d-x}`,strokeDashoffset:-h,strokeLinecap:"butt",transform:`rotate(-90 ${u} ${f})`,style:{transition:"stroke-dasharray 0.5s"}},g.label);return h+=x,p}),y.jsx("text",{x:u,y:f-4,textAnchor:"middle",fill:"#e6e6e6",fontSize:"16",fontWeight:"700",fontFamily:"JetBrains Mono, monospace",children:o>1?o:n.totalDecisions}),y.jsx("text",{x:u,y:f+10,textAnchor:"middle",fill:"#5c6370",fontSize:"8",fontFamily:"JetBrains Mono, monospace",children:"decisions"})]}),y.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6,width:"100%",padding:"0 8px"},children:a.map(g=>y.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:10},children:[y.jsx("span",{style:{width:8,height:8,borderRadius:2,background:g.color,flexShrink:0}}),y.jsx("span",{style:{color:"#abb2bf",flex:1},children:g.label}),y.jsx("span",{style:{color:"#5c6370",fontSize:9},children:g.cost}),y.jsx("span",{style:{color:"#e6e6e6",fontWeight:600,minWidth:20,textAlign:"right"},children:g.count})]},g.label))}),y.jsxs("div",{style:{fontSize:9,color:"#3e4451"},children:[n.autoRoutedCount," auto-routed"]})]})}function n3({tokenTimeline:n,agents:a}){const o=X.useRef(),r=X.useRef(),u=X.useCallback(()=>{const f=o.current,d=r.current;if(!f||!d)return;const h=window.devicePixelRatio||1,g=f.clientWidth,m=f.clientHeight;if(g===0||m===0)return;d.width=g*h,d.height=m*h,d.style.width=g+"px",d.style.height=m+"px";const x=d.getContext("2d");x.scale(h,h),x.clearRect(0,0,g,m);const p=40,b=10,S=10,w=20,M=g-p-b,C=m-S-w;x.strokeStyle="#1e222a",x.lineWidth=.5;for(let D=0;D<=4;D++){const B=S+D/4*C;x.beginPath(),x.moveTo(p,B),x.lineTo(g-b,B),x.stroke()}const T=Object.keys(n);if(T.length===0){x.fillStyle="#3e4451",x.font="10px monospace",x.textAlign="center",x.fillText("Waiting for agent telemetry...",g/2,m/2);return}let N=1/0,_=0,j=0;for(const D of T)for(const B of n[D]||[])B.t<N&&(N=B.t),B.t>_&&(_=B.t),B.v>j&&(j=B.v);_===N&&(_=N+6e4),j===0&&(j=100);const V=_-N;x.fillStyle="#3e4451",x.font="8px monospace",x.textAlign="right";for(let D=0;D<=4;D++){const B=j*(1-D/4);x.fillText(Cl(Math.round(B)),p-4,S+D/4*C+3)}x.textAlign="center";for(let D=0;D<=4;D++){const B=N+D/4*V,Q=new Date(B);x.fillText(`${Q.getHours()}:${String(Q.getMinutes()).padStart(2,"0")}`,p+D/4*M,m-4)}T.forEach((D,B)=>{const Q=n[D]||[];if(Q.length<2)return;const J=oa[B%oa.length],at=Q.map(K=>({x:p+(K.t-N)/V*M,y:S+(1-K.v/j)*C}));x.beginPath(),x.moveTo(at[0].x,S+C);for(const K of at)x.lineTo(K.x,K.y);x.lineTo(at[at.length-1].x,S+C),x.closePath();const $=x.createLinearGradient(0,S,0,S+C);$.addColorStop(0,J+"20"),$.addColorStop(1,J+"03"),x.fillStyle=$,x.fill(),x.beginPath();for(let K=0;K<at.length;K++)K===0?x.moveTo(at[K].x,at[K].y):x.lineTo(at[K].x,at[K].y);x.strokeStyle=J,x.lineWidth=1,x.stroke();const I=at[at.length-1];x.beginPath(),x.arc(I.x,I.y,2,0,Math.PI*2),x.fillStyle=J,x.fill()})},[n,a]);return X.useEffect(()=>{u()},[u]),X.useEffect(()=>{const f=new ResizeObserver(u);return o.current&&f.observe(o.current),()=>f.disconnect()},[u]),y.jsx("div",{ref:o,style:{flex:1,minHeight:0,position:"relative"},children:y.jsx("canvas",{ref:r,style:{display:"block",position:"absolute",top:0,left:0}})})}function Cl(n){return n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}k`:String(n||0)}function l3(n){const a=Math.floor(n/3600),o=Math.floor(n%3600/60);return a>0?`${a}h ${o}m`:`${o}m ${Math.floor(n%60)}s`}function i3(n){const a=Math.floor((Date.now()-new Date(n).getTime())/6e4);return a>=60?`${Math.floor(a/60)}h ago`:a>0?`${a}m ago`:"now"}const Lt={root:{width:"100%",height:"100%",display:"flex",flexDirection:"column",overflow:"hidden",padding:14,gap:12,background:"var(--bg-base)"},loadingRoot:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:12},loadingText:{fontSize:11,fontWeight:700,color:"var(--text-dim)",letterSpacing:3,textTransform:"uppercase"},loadingBar:{width:120,height:2,background:"#282c34",borderRadius:1,overflow:"hidden"},loadingFill:{width:"40%",height:"100%",background:dd,animation:"pulse 1.5s infinite"},statBar:{display:"flex",flexShrink:0,background:"#282c34",borderRadius:12,overflow:"hidden"},statCard:{flex:1,padding:"14px 16px",borderRight:"1px solid #1e222a",display:"flex",flexDirection:"column"},midRow:{display:"grid",gridTemplateColumns:"2fr 1fr",gap:12,flex:2,minHeight:0},chartPanel:{background:"#282c34",borderRadius:12,padding:"12px 14px",display:"flex",flexDirection:"column",minHeight:0},donutPanel:{background:"#282c34",borderRadius:12,padding:"12px 14px",display:"flex",flexDirection:"column",minHeight:0},bottomRow:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,flex:3,minHeight:0},panel:{background:"#282c34",borderRadius:12,padding:"12px 14px",display:"flex",flexDirection:"column",minHeight:0,overflow:"hidden"},panelHead:{fontSize:10,fontWeight:600,color:"#5c6370",textTransform:"uppercase",letterSpacing:1,marginBottom:8,flexShrink:0,display:"flex",justifyContent:"space-between",alignItems:"center"},panelHeadRight:{display:"flex",alignItems:"center",color:"#3e4451"},scrollInner:{flex:1,minHeight:0,overflowY:"auto"},empty:{color:"#3e4451",fontSize:10,textAlign:"center",padding:20},divider:{height:1,background:"#1e222a",margin:"8px 0",flexShrink:0},journSummary:{fontSize:10,color:"#8b929e",lineHeight:1.5,padding:"4px 0",whiteSpace:"pre-wrap",maxHeight:80,overflowY:"auto"},rotEntry:{display:"flex",alignItems:"center",gap:8,padding:"4px 0",fontSize:10},rotName:{color:"#abb2bf",flex:1},rotTime:{color:"#3e4451",fontSize:9}};function a3(){const[n,a]=X.useState(null);X.useEffect(()=>{o();const f=setInterval(o,4e3);return()=>clearInterval(f)},[]);async function o(){try{const f=await fetch("/api/pm/history");a(await f.json())}catch{}}const r=(n==null?void 0:n.history)||[],u=(n==null?void 0:n.stats)||{};return y.jsxs("div",{style:fe.container,children:[y.jsxs("div",{style:fe.header,children:[y.jsx("div",{style:fe.title,children:"PM REVIEW LOG"}),y.jsx("div",{style:fe.subtitle,children:"AI Project Manager reviews risky agent operations in Auto mode"})]}),y.jsxs("div",{style:fe.statsBar,children:[y.jsx(bs,{label:"REVIEWS",value:u.totalReviews||0}),y.jsx(bs,{label:"APPROVED",value:u.approved||0,color:"var(--green)"}),y.jsx(bs,{label:"REJECTED",value:u.rejected||0,color:"var(--red)"}),y.jsx(bs,{label:"AVG TIME",value:u.avgDurationMs?`${(u.avgDurationMs/1e3).toFixed(1)}s`:"-"})]}),r.length===0?y.jsxs("div",{style:fe.empty,children:[y.jsx("div",{style:fe.emptyTitle,children:"No reviews yet"}),y.jsx("div",{style:fe.emptyDesc,children:"Spawn agents with Auto permission mode. The AI PM will review risky operations (new files, deletions, config changes) before they happen."})]}):y.jsx("div",{style:fe.list,children:r.slice().reverse().map((f,d)=>y.jsxs("div",{style:fe.entry,children:[y.jsxs("div",{style:fe.entryTop,children:[y.jsx("span",{style:{...fe.verdict,color:f.approved?"var(--green)":"var(--red)",borderColor:f.approved?"rgba(74,225,104,0.3)":"rgba(224,108,117,0.3)",background:f.approved?"rgba(74,225,104,0.08)":"rgba(224,108,117,0.08)"},children:f.approved?"APPROVED":"REJECTED"}),y.jsx("span",{style:fe.entryAgent,children:f.agent}),y.jsx("span",{style:fe.entryAction,children:f.action}),y.jsx("span",{style:fe.entryTime,children:o3(f.timestamp)})]}),y.jsx("div",{style:fe.entryFile,children:f.file}),f.description&&y.jsx("div",{style:fe.entryDesc,children:f.description}),y.jsx("div",{style:fe.entryReason,children:f.reason})]},d))})]})}function bs({label:n,value:a,color:o}){return y.jsxs("div",{style:fe.stat,children:[y.jsx("div",{style:{fontSize:16,fontWeight:700,color:o||"var(--text-bright)"},children:a}),y.jsx("div",{style:{fontSize:7,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1},children:n})]})}function o3(n){const a=Math.floor((Date.now()-new Date(n).getTime())/6e4);return a>=60?`${Math.floor(a/60)}h ago`:a>0?`${a}m ago`:"just now"}const fe={container:{padding:24,maxWidth:700,margin:"0 auto"},header:{marginBottom:16},title:{fontSize:11,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5},subtitle:{fontSize:10,color:"var(--text-dim)",marginTop:4},statsBar:{display:"flex",gap:8,marginBottom:16},stat:{flex:1,background:"var(--bg-surface)",border:"1px solid var(--border)",padding:"8px 10px",textAlign:"center"},empty:{textAlign:"center",padding:"40px 20px",background:"var(--bg-surface)",border:"1px solid var(--border)"},emptyTitle:{fontSize:12,color:"var(--text-primary)",fontWeight:600,marginBottom:8},emptyDesc:{fontSize:10,color:"var(--text-dim)",lineHeight:1.6,maxWidth:400,margin:"0 auto"},list:{display:"flex",flexDirection:"column",gap:4},entry:{background:"var(--bg-surface)",border:"1px solid var(--border)",padding:"8px 10px"},entryTop:{display:"flex",alignItems:"center",gap:8,marginBottom:4},verdict:{fontSize:8,fontWeight:700,letterSpacing:.5,padding:"1px 5px",border:"1px solid"},entryAgent:{fontSize:11,fontWeight:600,color:"var(--text-bright)"},entryAction:{fontSize:10,color:"var(--text-dim)"},entryTime:{fontSize:9,color:"var(--text-dim)",marginLeft:"auto"},entryFile:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font)"},entryDesc:{fontSize:10,color:"var(--text-primary)",marginTop:2},entryReason:{fontSize:10,color:"var(--text-dim)",marginTop:3,fontStyle:"italic"}},r3=[{id:"agents",label:"Agents"},{id:"stats",label:"Stats"},{id:"teams",label:"Teams"},{id:"approvals",label:"Approvals"}];function s3(){const n=Mt(p=>p.agents),a=Mt(p=>p.connected),o=Mt(p=>p.activeTab),r=Mt(p=>p.detailPanel),u=Mt(p=>p.statusMessage),f=Mt(p=>p.connect),d=Mt(p=>p.setActiveTab),h=Mt(p=>p.openDetail),g=Mt(p=>p.closeDetail);X.useEffect(()=>{f()},[f]);const m=n.filter(p=>p.status==="running").length,x=n.length>0;return y.jsxs("div",{style:Oe.root,children:[y.jsxs("header",{style:Oe.header,children:[y.jsx("div",{style:Oe.headerLeft,children:y.jsx("img",{src:"/groove-logo-short.png",alt:"GROOVE",style:{height:18,marginTop:3,opacity:.85}})}),y.jsx("div",{style:Oe.headerCenter,children:a&&r3.map(p=>y.jsx("button",{onClick:()=>d(p.id),style:{...Oe.tabBtn,color:o===p.id?"var(--text-bright)":"var(--text-primary)",borderBottom:o===p.id?"2px solid var(--accent)":"2px solid transparent",background:o===p.id?"var(--bg-active)":"transparent"},children:p.label},p.id))}),y.jsxs("div",{style:Oe.headerRight,children:[u&&y.jsx("span",{style:Oe.statusText,children:u}),y.jsx("span",{style:Oe.agentCount,children:m>0?`${m} running`:n.length>0?`${n.length} agent${n.length!==1?"s":""}`:""}),a&&y.jsxs(y.Fragment,{children:[y.jsx("button",{onClick:()=>(r==null?void 0:r.type)==="journalist"?g():h({type:"journalist"}),style:{...Oe.tabBtn,color:(r==null?void 0:r.type)==="journalist"?"var(--text-bright)":"var(--text-primary)",borderBottom:(r==null?void 0:r.type)==="journalist"?"2px solid var(--purple)":"2px solid transparent"},children:"Journalist"}),y.jsx("button",{onClick:()=>h({type:"spawn"}),style:Oe.spawnBtn,children:"+ Spawn"})]})]})]}),y.jsxs("div",{style:{position:"fixed",bottom:10,left:12,zIndex:50,display:"flex",alignItems:"center",gap:5},children:[y.jsx("div",{style:{width:5,height:5,borderRadius:"50%",background:a?"var(--green)":"var(--red)",animation:"pulse 2s infinite"}}),y.jsx("span",{style:{fontSize:9,fontWeight:600,letterSpacing:.8,color:a?"var(--green)":"var(--red)",textTransform:"uppercase",fontFamily:"var(--font)",animation:"pulse 3s infinite"},children:a?"connected":"offline"})]}),y.jsxs("div",{style:Oe.mainRow,children:[y.jsxs("main",{style:Oe.content,children:[o==="agents"&&(x?y.jsx(DT,{}):y.jsx(QT,{})),o==="stats"&&y.jsx(t3,{}),o==="teams"&&y.jsx(WT,{}),o==="approvals"&&y.jsx(a3,{})]}),r&&y.jsxs("aside",{style:{...Oe.detailPanel,width:r.type==="agent"?"45%":320},children:[y.jsx("button",{onClick:g,style:Oe.closeBtn,children:"x"}),r.type==="agent"&&y.jsx($T,{}),r.type==="spawn"&&y.jsx(KT,{}),r.type==="journalist"&&y.jsx(JT,{})]})]})]})}const Oe={root:{width:"100%",height:"100%",display:"flex",flexDirection:"column",background:"var(--bg-base)",color:"var(--text-primary)"},header:{height:40,padding:"0 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",background:"var(--bg-chrome)",flexShrink:0,position:"relative"},headerLeft:{display:"flex",alignItems:"center",gap:8},headerCenter:{display:"flex",alignItems:"center",gap:0},headerRight:{display:"flex",alignItems:"center",gap:10},tabBtn:{padding:"10px 14px",background:"transparent",border:"none",borderBottom:"2px solid transparent",fontSize:12,fontWeight:500,fontFamily:"var(--font)",cursor:"pointer",transition:"color 0.1s"},spawnBtn:{padding:"4px 12px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:12,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"},agentCount:{fontSize:11,color:"var(--text-dim)"},statusText:{fontSize:11,color:"var(--text-dim)",fontStyle:"italic"},mainRow:{flex:1,display:"flex",overflow:"hidden"},content:{flex:1,overflow:"hidden",position:"relative"},detailPanel:{width:320,flexShrink:0,background:"var(--bg-chrome)",borderLeft:"1px solid var(--border)",padding:16,overflowY:"auto",position:"relative"},closeBtn:{position:"absolute",top:8,right:10,background:"none",border:"none",color:"var(--text-dim)",fontSize:14,cursor:"pointer",fontFamily:"var(--font)",padding:"2px 6px"}};x1.createRoot(document.getElementById("root")).render(y.jsx(s3,{}));
73
+ `)||null:a.type==="text"&&a.text?a.text:a.type==="result"&&a.result?a.result:null}catch{return n.length>5?n:null}}function LT(n,a){const o=[];for(const r of n)o.push({timestamp:r.timestamp,from:r.from,text:r.text,isQuery:r.isQuery});for(const r of a.slice(-30)){const u=BT(r.text);if(!u||u.trimStart().startsWith("[")||u.trimStart().startsWith("{"))continue;o.some(d=>Math.abs(d.timestamp-r.timestamp)<2e3&&d.from==="agent")||o.push({timestamp:r.timestamp,from:"agent",text:u.slice(0,2e3)})}return o.sort((r,u)=>r.timestamp-u.timestamp),o}const Kt={container:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},timeline:{flex:1,overflowY:"auto",padding:"10px 0"},hint:{color:"var(--text-dim)",fontSize:11,padding:"20px 4px",textAlign:"center",lineHeight:1.6},entry:{padding:"4px 0",position:"relative"},userMsg:{display:"flex",flexDirection:"column",gap:2},userLabel:{fontSize:10,fontWeight:600,color:"var(--accent)",textTransform:"uppercase",letterSpacing:.5},userText:{fontSize:12,color:"var(--text-bright)",lineHeight:1.5,padding:"4px 8px",background:"var(--bg-surface)",borderRadius:2,border:"1px solid var(--border)",whiteSpace:"pre-wrap",wordBreak:"break-word"},agentMsg:{display:"flex",flexDirection:"column",gap:2},agentLabel:{fontSize:10,fontWeight:600,color:"var(--green)",textTransform:"uppercase",letterSpacing:.5},agentText:{fontSize:12,color:"var(--text-primary)",lineHeight:1.5,padding:"4px 8px",background:"var(--bg-base)",borderRadius:2,whiteSpace:"pre-wrap",wordBreak:"break-word"},systemMsg:{fontSize:10,color:"var(--text-dim)",fontStyle:"italic",padding:"2px 0"},time:{position:"absolute",top:4,right:0,fontSize:9,color:"var(--text-muted)"},statusMsg:{fontSize:11,color:"var(--text-dim)",fontStyle:"italic",padding:"6px 0"},inputRow:{display:"flex",gap:6,padding:"8px 0 0",borderTop:"1px solid var(--border)"},input:{flex:1,background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"8px 10px",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font)",outline:"none"},sendBtn:{padding:"8px 14px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:11,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"},cursor:{color:"var(--accent)",fontWeight:400,animation:"pulse 1s infinite",marginLeft:1},launchBox:{padding:"8px 0",borderTop:"1px solid var(--border)",flexShrink:0},launchHeader:{fontSize:10,fontWeight:700,color:"var(--text-bright)",marginBottom:6},launchList:{display:"flex",flexDirection:"column",gap:3,marginBottom:8},launchAgent:{display:"flex",alignItems:"baseline",gap:6,fontSize:10,padding:"2px 0"},launchRole:{fontWeight:600,color:"var(--accent)",minWidth:60},launchPrompt:{color:"var(--text-dim)",fontSize:9,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},launchBtn:{width:"100%",padding:"8px",background:"rgba(51, 175, 188, 0.1)",border:"1px solid var(--accent)",color:"var(--accent)",fontSize:11,fontWeight:700,fontFamily:"var(--font)",cursor:"pointer",letterSpacing:.5}};function UT({agent:n}){var g;const a=Mt(m=>m.activityLog),o=Mt(m=>m.tokenTimeline),r=a[n.id]||[],u=o[n.id]||[],f=Math.round((n.contextUsage||0)*100),d=n.spawnedAt?qT(Date.now()-new Date(n.spawnedAt).getTime()):"-",h=n.spawnedAt&&n.tokensUsed>0?Math.round(n.tokensUsed/((Date.now()-new Date(n.spawnedAt).getTime())/6e4)):0;return y.jsxs("div",{style:oe.container,children:[y.jsxs("div",{style:oe.metricsGrid,children:[y.jsx(vs,{label:"Tokens",value:((g=n.tokensUsed)==null?void 0:g.toLocaleString())||"0"}),y.jsx(vs,{label:"Burn Rate",value:`${h}/min`}),y.jsx(vs,{label:"Uptime",value:d}),y.jsx(vs,{label:"Activity",value:`${r.length} events`})]}),y.jsxs("div",{style:{marginTop:16},children:[y.jsx("div",{style:oe.sectionLabel,children:"TOKEN HEARTBEAT"}),y.jsx(kT,{data:u,isAlive:n.status==="running"})]}),y.jsxs("div",{style:{marginTop:16},children:[y.jsx("div",{style:oe.sectionLabel,children:"CONTEXT USAGE"}),y.jsxs("div",{style:oe.gaugeRow,children:[y.jsx("div",{style:oe.gaugeTrack,children:y.jsx("div",{style:{height:"100%",width:`${f}%`,borderRadius:1,background:f>80?"var(--red)":f>60?"var(--amber)":"var(--green)",transition:"width 0.3s"}})}),y.jsxs("span",{style:oe.gaugeLabel,children:[f,"%"]})]})]}),y.jsxs("div",{style:{marginTop:16},children:[y.jsx("div",{style:oe.sectionLabel,children:"ACTIVITY PULSE"}),y.jsx(YT,{activity:r})]}),y.jsxs("div",{style:{marginTop:16},children:[y.jsx("div",{style:oe.sectionLabel,children:"DETAILS"}),y.jsxs("div",{style:oe.infoList,children:[y.jsx(li,{label:"ID",value:n.id}),y.jsx(li,{label:"Role",value:n.role}),y.jsx(li,{label:"Provider",value:n.provider}),y.jsx(li,{label:"Model",value:n.model||"default"}),y.jsx(li,{label:"Scope",value:(n.scope||[]).join(", ")||"unrestricted"}),y.jsx(li,{label:"Spawned",value:n.spawnedAt?new Date(n.spawnedAt).toLocaleTimeString():"-"}),y.jsx(li,{label:"Last Active",value:n.lastActivity?new Date(n.lastActivity).toLocaleTimeString():"-"})]})]}),n.prompt&&y.jsxs("div",{style:{marginTop:16},children:[y.jsx("div",{style:oe.sectionLabel,children:"ORIGINAL PROMPT"}),y.jsx("div",{style:oe.promptBox,children:n.prompt})]}),y.jsxs("div",{style:{marginTop:16},children:[y.jsxs("div",{style:oe.sectionLabel,children:["RECENT LOG (",r.length,")"]}),y.jsxs("div",{style:oe.logScroll,children:[r.length===0&&y.jsx("div",{style:{color:"var(--text-dim)",fontSize:11,padding:8},children:"No activity yet..."}),r.slice(-30).reverse().map((m,x)=>{var p;return y.jsxs("div",{style:oe.logEntry,children:[y.jsx("span",{style:oe.logTime,children:new Date(m.timestamp).toLocaleTimeString()}),y.jsx("span",{style:oe.logText,children:(p=m.text)==null?void 0:p.slice(0,200)})]},x)})]})]})]})}function kT({data:n,isAlive:a}){const o=X.useRef();return X.useEffect(()=>{const r=o.current;if(!r)return;const u=r.getContext("2d"),f=r.width,d=r.height;u.clearRect(0,0,f,d),u.strokeStyle="#3e4451",u.lineWidth=.5;for(let S=0;S<d;S+=d/4)u.beginPath(),u.moveTo(0,S),u.lineTo(f,S),u.stroke();if(n.length<2){u.strokeStyle=a?"#5c6370":"#3e4451",u.lineWidth=1,u.beginPath(),u.moveTo(0,d/2),u.lineTo(f,d/2),u.stroke(),a&&(u.fillStyle="#5c6370",u.font="10px monospace",u.fillText("waiting for data...",8,d/2-6));return}const h=n.map(S=>S.v),g=Math.min(...h),m=Math.max(...h),x=m-g||1,p=[];for(let S=1;S<h.length;S++){const w=h[S]-h[S-1];w>x*.2&&w>0&&p.push(S)}const b=u.createLinearGradient(0,0,0,d);b.addColorStop(0,a?"rgba(51, 175, 188, 0.15)":"rgba(92, 99, 112, 0.1)"),b.addColorStop(1,"transparent"),u.beginPath(),u.moveTo(0,d);for(let S=0;S<n.length;S++){const w=S/(n.length-1)*f,M=d-4-(h[S]-g)/x*(d-8);u.lineTo(w,M)}u.lineTo(f,d),u.closePath(),u.fillStyle=b,u.fill(),u.strokeStyle=a?"#33afbc":"#5c6370",u.lineWidth=1.5,u.beginPath();for(let S=0;S<n.length;S++){const w=S/(n.length-1)*f,M=d-4-(h[S]-g)/x*(d-8);S===0?u.moveTo(w,M):u.lineTo(w,M)}u.stroke();for(const S of p){const w=S/(n.length-1)*f,M=d-4-(h[S]-g)/x*(d-8);u.fillStyle="#e5c07b",u.beginPath(),u.arc(w,M,3,0,Math.PI*2),u.fill()}if(a&&n.length>0){const S=f,w=d-4-(h[h.length-1]-g)/x*(d-8);u.fillStyle="#33afbc",u.beginPath(),u.arc(S-2,w,3,0,Math.PI*2),u.fill()}u.fillStyle="#5c6370",u.font="9px monospace",u.fillText(m.toLocaleString(),4,10),u.fillText(g.toLocaleString(),4,d-2)},[n,a]),y.jsx("div",{style:oe.chartContainer,children:y.jsx("canvas",{ref:o,width:400,height:60,style:{width:"100%",height:60,display:"block"}})})}function YT({activity:n}){const o=Date.now(),r=300*1e3,u=r/40,f=new Array(40).fill(0);for(const g of n){const m=o-g.timestamp;if(m>r)continue;const x=Math.min(Math.floor((r-m)/u),39);f[x]++}const d=Math.max(...f,1),h=f.map((g,m)=>{const x=m/39*300,p=28-g/d*24;return`${x},${p}`}).join(" ");return y.jsx("div",{style:oe.chartContainer,children:y.jsxs("svg",{width:"100%",height:"32",viewBox:"0 0 300 32",preserveAspectRatio:"none",style:{display:"block"},children:[y.jsx("polyline",{points:h,fill:"none",stroke:"var(--green)",strokeWidth:"1",opacity:"0.6"}),y.jsx("line",{x1:"0",y1:"31",x2:"300",y2:"31",stroke:"var(--text-muted)",strokeWidth:"0.5"})]})})}function vs({label:n,value:a}){return y.jsxs("div",{style:oe.metric,children:[y.jsx("div",{style:{fontSize:14,fontWeight:700,color:"var(--text-bright)"},children:a}),y.jsx("div",{style:{fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1},children:n})]})}function li({label:n,value:a}){return y.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"3px 0"},children:[y.jsx("span",{style:{color:"var(--text-dim)",fontSize:11},children:n}),y.jsx("span",{style:{color:"var(--text-primary)",fontSize:11,maxWidth:"65%",textAlign:"right",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a})]})}function qT(n){const a=Math.floor(n/1e3),o=Math.floor(a/60),r=Math.floor(o/60);return r>0?`${r}h ${o%60}m`:o>0?`${o}m ${a%60}s`:`${a}s`}const oe={container:{flex:1,overflowY:"auto",padding:"10px 0"},metricsGrid:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:6},metric:{background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:10,textAlign:"center"},sectionLabel:{fontSize:11,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5,marginBottom:6,fontWeight:600},gaugeRow:{display:"flex",alignItems:"center",gap:8},gaugeTrack:{flex:1,height:4,background:"var(--text-muted)",borderRadius:2,overflow:"hidden"},gaugeLabel:{fontSize:12,color:"var(--text-primary)",fontWeight:600,minWidth:36,textAlign:"right"},chartContainer:{background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",overflow:"hidden"},infoList:{borderTop:"1px solid var(--border)",paddingTop:6},promptBox:{background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2,padding:8,fontSize:12,color:"var(--text-primary)",lineHeight:1.5,whiteSpace:"pre-wrap"},logScroll:{maxHeight:160,overflowY:"auto",background:"var(--bg-base)",borderRadius:2,border:"1px solid var(--border)"},logEntry:{padding:"3px 8px",borderBottom:"1px solid var(--bg-surface)",fontSize:10,display:"flex",gap:6},logTime:{color:"var(--text-dim)",whiteSpace:"nowrap"},logText:{color:"var(--text-primary)",wordBreak:"break-word"}};function VT({agent:n}){const a=Mt(K=>K.killAgent),o=Mt(K=>K.rotateAgent),r=Mt(K=>K.spawnAgent),u=Mt(K=>K.instructAgent),f=Mt(K=>K.showStatus),d=Mt(K=>K.closeDetail),[h,g]=X.useState(!1),[m,x]=X.useState(!1),[p,b]=X.useState(""),[S,w]=X.useState(!1),[M,C]=X.useState(n.model||""),[T,N]=X.useState([]),_=n.status==="running"||n.status==="starting";X.useEffect(()=>{fetch("/api/providers").then(K=>K.json()).then(N).catch(()=>{})},[]);const j=T.find(K=>K.id===n.provider),V=(j==null?void 0:j.models)||[];async function D(){try{await o(n.id)}catch(K){f(`rotate failed: ${K.message}`)}}async function B(){if(!h){g(!0),setTimeout(()=>g(!1),3e3);return}try{await a(n.id),f(`${n.name} killed`)}catch(K){f(`kill failed: ${K.message}`)}g(!1)}async function Q(){if(!m){x(!0),setTimeout(()=>x(!1),3e3);return}try{await a(n.id,!0),d(),f(`${n.name} deleted`)}catch(K){f(`delete failed: ${K.message}`)}x(!1)}async function J(){try{const K=await r({role:n.role,scope:n.scope,prompt:n.prompt,provider:n.provider,model:n.model});f(`cloned as ${K.name}`)}catch(K){f(`clone failed: ${K.message}`)}}async function at(K){C(K);try{await fetch(`/api/agents/${n.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:K||null})}),f(`model set to ${K||"default"} (takes effect on next rotation)`)}catch(R){f(`model change failed: ${R.message}`)}}async function $(){if(p.trim())try{await u(n.id,p.trim()),w(!1),b("")}catch(K){f(`prompt update failed: ${K.message}`)}}async function I(){try{await a(n.id,!0);const K=await r({role:n.role,scope:n.scope,prompt:n.prompt,provider:n.provider,model:n.model});f(`restarted as ${K.name}`)}catch(K){f(`restart failed: ${K.message}`)}}return y.jsxs("div",{style:re.container,children:[y.jsx("div",{style:re.sectionLabel,children:"LIFECYCLE"}),y.jsxs("div",{style:re.btnGrid,children:[_&&y.jsxs(y.Fragment,{children:[y.jsx(mo,{icon:"~",label:"Rotate",desc:"Fresh context + handoff brief",onClick:D,color:"var(--accent)"}),y.jsx(mo,{icon:"||",label:h?"Confirm Kill":"Stop",desc:"Stop the agent process",onClick:B,color:h?"var(--red)":"var(--amber)"})]}),!_&&y.jsx(mo,{icon:">",label:"Restart",desc:"Spawn fresh with same config",onClick:I,color:"var(--green)"}),y.jsx(mo,{icon:"+",label:"Clone",desc:"Spawn duplicate agent",onClick:J,color:"var(--accent)"}),y.jsx(mo,{icon:"x",label:m?"Confirm Delete":"Delete",desc:"Kill and remove permanently",onClick:Q,color:m?"var(--red)":"var(--text-dim)"})]}),y.jsxs("div",{style:{...re.sectionLabel,marginTop:20},children:["MODEL ",n.routingMode==="auto"&&y.jsx("span",{style:{color:"var(--accent)",fontWeight:400,textTransform:"none"},children:" — auto-routed"})]}),y.jsxs("select",{style:re.select,value:M,onChange:K=>at(K.target.value),children:[y.jsx("option",{value:"",children:"Default"}),V.map(K=>y.jsxs("option",{value:K.id,children:[K.name," (",K.tier,")"]},K.id))]}),y.jsx("div",{style:re.fieldHint,children:"Changes take effect on next rotation"}),y.jsx("div",{style:{...re.sectionLabel,marginTop:20},children:"PROMPT"}),n.prompt&&!S&&y.jsxs("div",{style:re.currentPrompt,children:[y.jsx("div",{style:re.promptText,children:n.prompt}),_&&y.jsx("button",{onClick:()=>{w(!0),b("")},style:re.editBtn,children:"Send New Instruction"})]}),!n.prompt&&!S&&y.jsx("div",{style:re.noPrompt,children:"No prompt set"}),S&&y.jsxs("div",{children:[y.jsx("textarea",{style:re.textarea,value:p,onChange:K=>b(K.target.value),placeholder:"New instruction for this agent...",rows:4,autoFocus:!0}),y.jsxs("div",{style:{display:"flex",gap:6,marginTop:6},children:[y.jsx("button",{onClick:$,style:re.saveBtn,disabled:!p.trim(),children:"Send (rotates agent)"}),y.jsx("button",{onClick:()=>w(!1),style:re.cancelBtn,children:"Cancel"})]})]}),y.jsx("div",{style:{...re.sectionLabel,marginTop:20},children:"CONFIGURATION"}),y.jsx(la,{label:"ID",value:n.id}),y.jsx(la,{label:"Role",value:n.role}),y.jsx(la,{label:"Provider",value:n.provider}),y.jsx(la,{label:"Model",value:n.routingMode==="auto"?`auto (${n.model||"pending"})`:n.model||"default"}),y.jsx(la,{label:"Scope",value:(n.scope||[]).join(", ")||"unrestricted"}),y.jsx(la,{label:"Status",value:n.status})]})}function mo({icon:n,label:a,desc:o,onClick:r,color:u}){return y.jsxs("button",{onClick:r,style:{...re.actionBtn,borderColor:u},children:[y.jsx("span",{style:{...re.actionIcon,color:u},children:n}),y.jsxs("div",{children:[y.jsx("div",{style:re.actionTitle,children:a}),y.jsx("div",{style:re.actionDesc,children:o})]})]})}function la({label:n,value:a}){return y.jsxs("div",{style:re.configRow,children:[y.jsx("span",{style:{color:"var(--text-dim)",fontSize:11,minWidth:60},children:n}),y.jsx("span",{style:{color:"var(--text-primary)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a})]})}const re={container:{flex:1,overflowY:"auto",padding:"10px 0"},sectionLabel:{fontSize:11,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5,marginBottom:8,fontWeight:600},btnGrid:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},actionBtn:{display:"flex",alignItems:"center",gap:8,padding:"8px 10px",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,cursor:"pointer",textAlign:"left",fontFamily:"var(--font)"},actionIcon:{fontSize:14,fontWeight:700,width:18,textAlign:"center",flexShrink:0},actionTitle:{fontSize:11,color:"var(--text-primary)",fontWeight:600},actionDesc:{fontSize:9,color:"var(--text-dim)",marginTop:1},select:{width:"100%",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font)",outline:"none"},fieldHint:{fontSize:10,color:"var(--text-muted)",marginTop:4},currentPrompt:{},promptText:{background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2,padding:8,fontSize:12,color:"var(--text-primary)",lineHeight:1.5,whiteSpace:"pre-wrap",maxHeight:100,overflowY:"auto"},noPrompt:{fontSize:12,color:"var(--text-dim)",fontStyle:"italic"},editBtn:{marginTop:6,padding:"4px 10px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:11,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"},textarea:{width:"100%",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font)",outline:"none",resize:"vertical"},saveBtn:{flex:1,padding:"6px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:11,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"},cancelBtn:{padding:"6px 12px",background:"transparent",border:"1px solid var(--border)",borderRadius:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font)",cursor:"pointer"},configRow:{display:"flex",gap:8,padding:"3px 0",borderBottom:"1px solid var(--bg-surface)"}},XT=[{id:"chat",label:"Chat"},{id:"stats",label:"Stats"},{id:"actions",label:"Actions"}],GT={running:"var(--green)",starting:"var(--amber)",stopped:"var(--text-dim)",crashed:"var(--red)",completed:"var(--accent)",killed:"var(--text-dim)"};function $T(){const[n,a]=X.useState("chat"),o=Mt(h=>h.detailPanel),u=Mt(h=>h.agents).find(h=>h.id===(o==null?void 0:o.agentId));if(!u)return y.jsx("div",{style:Ml.empty,children:"Agent not found"});const f=GT[u.status]||"var(--text-dim)",d=u.status==="running"||u.status==="starting";return y.jsxs("div",{style:Ml.container,children:[y.jsxs("div",{style:Ml.agentHeader,children:[y.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[y.jsx("div",{style:{width:6,height:6,borderRadius:"50%",background:f,animation:d?"pulse 2s infinite":"none"}}),y.jsx("span",{style:Ml.agentName,children:u.name}),y.jsx("span",{style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:.5,color:f,padding:"1px 6px",borderRadius:2,background:`color-mix(in srgb, ${f} 12%, transparent)`},children:u.status})]}),y.jsxs("span",{style:Ml.agentMeta,children:[u.role," / ",u.provider]})]}),y.jsx("div",{style:Ml.tabBar,children:XT.map(h=>y.jsx("button",{onClick:()=>a(h.id),style:{...Ml.tab,color:n===h.id?"var(--text-bright)":"var(--text-dim)",borderBottom:n===h.id?"2px solid var(--accent)":"2px solid transparent"},children:h.label},h.id))}),y.jsxs("div",{style:Ml.tabContent,children:[n==="chat"&&y.jsx(RT,{agent:u}),n==="stats"&&y.jsx(UT,{agent:u}),n==="actions"&&y.jsx(VT,{agent:u})]})]})}const Ml={container:{display:"flex",flexDirection:"column",height:"100%"},agentHeader:{padding:"12px 0 8px",display:"flex",justifyContent:"space-between",alignItems:"center",borderBottom:"1px solid var(--border)"},agentName:{fontSize:14,fontWeight:600,color:"var(--text-bright)"},agentMeta:{fontSize:11,color:"var(--text-dim)"},tabBar:{display:"flex",gap:0,borderBottom:"1px solid var(--border)"},tab:{padding:"8px 16px",background:"transparent",border:"none",borderBottom:"2px solid transparent",fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:1,fontFamily:"var(--font)",cursor:"pointer"},tabContent:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column"},empty:{color:"var(--text-dim)",fontSize:12,padding:16}};function QT(){const n=Mt(o=>o.openDetail),a=Mt(o=>o.connected);return y.jsx("div",{style:rn.container,children:y.jsx("div",{style:rn.inner,children:a?y.jsxs(y.Fragment,{children:[y.jsx("div",{style:rn.readyIcon,children:y.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 40 40",children:[y.jsx("circle",{cx:"20",cy:"20",r:"18",fill:"none",stroke:"#2c313a",strokeWidth:"1"}),y.jsx("circle",{cx:"20",cy:"20",r:"18",fill:"none",stroke:"#33afbc",strokeWidth:"1",strokeDasharray:"113",strokeDashoffset:"28",strokeLinecap:"round",children:y.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 20 20",to:"360 20 20",dur:"3s",repeatCount:"indefinite"})}),y.jsx("text",{x:"20",y:"24",textAnchor:"middle",fill:"#33afbc",fontSize:"14",fontWeight:"700",fontFamily:"JetBrains Mono, monospace",children:"+"})]})}),y.jsx("div",{style:rn.title,children:"Ready to orchestrate"}),y.jsx("div",{style:rn.hint,children:"Spawn your first agent to start building"}),y.jsx("button",{onClick:()=>n({type:"spawn"}),style:rn.spawnBtn,children:"Spawn Agent"})]}):y.jsxs(y.Fragment,{children:[y.jsx("div",{style:rn.pulseRing,children:y.jsx("div",{style:rn.pulseCore})}),y.jsx("div",{style:rn.title,children:"Connecting to daemon..."}),y.jsx("div",{style:rn.hint,children:"Make sure the GROOVE daemon is running"}),y.jsx("code",{style:rn.code,children:"groove start"})]})})})}const rn={container:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",background:"#1a1e25"},inner:{display:"flex",flexDirection:"column",alignItems:"center",gap:12,padding:40},pulseRing:{width:40,height:40,borderRadius:"50%",border:"1px solid #33afbc",display:"flex",alignItems:"center",justifyContent:"center",animation:"pulse 2s infinite"},pulseCore:{width:8,height:8,borderRadius:"50%",background:"#33afbc",boxShadow:"0 0 12px rgba(51, 175, 188, 0.5)"},readyIcon:{marginBottom:4},title:{fontSize:14,color:"#e6e6e6",fontWeight:600,letterSpacing:.5},hint:{fontSize:12,color:"#6b7280",textAlign:"center",lineHeight:1.6,maxWidth:360},spawnBtn:{padding:"8px 24px",background:"rgba(51, 175, 188, 0.1)",border:"1px solid #33afbc",color:"#33afbc",fontSize:12,fontWeight:600,fontFamily:"'JetBrains Mono', monospace",cursor:"pointer",marginTop:4,transition:"background 0.2s"},code:{background:"#252a33",padding:"8px 16px",fontSize:11,color:"#33afbc",border:"1px solid #2c313a"}},py=[{id:"backend",label:"Backend",desc:"APIs, server logic, database",scope:["src/api/**","src/server/**","src/lib/**","src/db/**"]},{id:"frontend",label:"Frontend",desc:"UI components, views, styles",scope:["src/components/**","src/views/**","src/pages/**","src/styles/**"]},{id:"fullstack",label:"Fullstack",desc:"Full codebase access",scope:[]},{id:"planner",label:"Planner",desc:"Architecture, research, planning",scope:[]},{id:"testing",label:"Testing",desc:"Tests, specs, coverage",scope:["tests/**","test/**","**/*.test.*","**/*.spec.*"]},{id:"devops",label:"DevOps",desc:"Docker, CI/CD, infra",scope:["Dockerfile*","docker-compose*",".github/**","infra/**"]},{id:"docs",label:"Docs",desc:"Documentation, READMEs",scope:["docs/**","*.md"]}],ZT=[{id:"auto",label:"Auto",desc:"AI PM reviews risky operations before they happen",icon:"~"},{id:"full",label:"Full Send",desc:"No reviews, maximum speed",icon:">"}];function KT(){const n=Mt(U=>U.spawnAgent),a=Mt(U=>U.closeDetail),[o,r]=X.useState(""),[u,f]=X.useState(""),[d,h]=X.useState(""),[g,m]=X.useState(""),[x,p]=X.useState("auto"),[b,S]=X.useState("claude-code"),[w,M]=X.useState("auto"),[C,T]=X.useState([]),[N,_]=X.useState(!1),[j,V]=X.useState(""),[D,B]=X.useState(!1),[Q,J]=X.useState(null),[at,$]=X.useState(""),[I,K]=X.useState(!1);X.useEffect(()=>{R()},[]);async function R(){try{const U=await fetch("/api/providers");T(await U.json())}catch{}}const Z=py.find(U=>U.id===o),z=o==="custom"?d:(Z==null?void 0:Z.scope.join(", "))||"",L=o==="planner";function k(U){if(U.installed&&(U.authType==="subscription"||U.authType==="local"||U.hasKey)){S(U.id),M("auto"),J(null);return}J(U.id),$("")}async function q(){if(!(!at.trim()||!Q)){K(!0);try{await fetch(`/api/credentials/${Q}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:at.trim()})}),$(""),J(null),S(Q),M("auto"),await R()}catch{}K(!1)}}async function tt(U){U.preventDefault();const nt=o==="custom"?u:o;if(!nt){V("Select a role");return}_(!0),V("");try{const rt=z?z.split(",").map(ct=>ct.trim()).filter(Boolean):[];await n({role:nt,scope:rt,prompt:g||null,model:w||"auto",provider:b,permission:x}),a()}catch(rt){V(rt.message)}finally{_(!1)}}function A(U){return U.installed?U.authType==="api-key"&&!U.hasKey?"needs key":U.authType==="subscription"?"subscription":U.authType==="local"?"local":"ready":"not installed"}function H(U){return!(!U.installed||U.authType==="api-key"&&!U.hasKey)}return y.jsxs("div",{style:{paddingTop:4},children:[y.jsx("div",{style:Et.title,children:"SPAWN AGENT"}),y.jsxs("form",{onSubmit:tt,children:[y.jsx("div",{style:Et.label,children:"ROLE"}),y.jsxs("div",{style:Et.roleGrid,children:[py.map(U=>y.jsx("button",{type:"button",onClick:()=>r(U.id),style:{...Et.roleBtn,...o===U.id?Et.roleBtnActive:{}},title:U.desc,children:U.label},U.id)),y.jsx("button",{type:"button",onClick:()=>r("custom"),style:{...Et.roleBtn,...o==="custom"?Et.roleBtnActive:{}},children:"Custom"})]}),Z&&y.jsx("div",{style:Et.roleDesc,children:Z.desc}),o==="custom"&&y.jsx("input",{style:{...Et.input,marginTop:6},placeholder:"Custom role name...",value:u,onChange:U=>f(U.target.value),autoFocus:!0}),y.jsx("div",{style:Et.label,children:L?"WHAT TO PLAN":"TASK PROMPT"}),y.jsx("textarea",{style:Et.textarea,placeholder:L?"What should this agent research or plan?":"What should this agent work on?",value:g,onChange:U=>m(U.target.value),rows:3}),y.jsx("div",{style:Et.label,children:"PERMISSIONS"}),y.jsx("div",{style:Et.permGrid,children:ZT.map(U=>y.jsxs("button",{type:"button",onClick:()=>p(U.id),style:{...Et.permBtn,...x===U.id?Et.permBtnActive:{}},children:[y.jsx("span",{style:Et.permIcon,children:U.icon}),y.jsxs("div",{children:[y.jsx("div",{style:Et.permLabel,children:U.label}),y.jsx("div",{style:Et.permDesc,children:U.desc})]})]},U.id))}),y.jsx("button",{type:"button",onClick:()=>B(!D),style:Et.advancedToggle,children:D?"- hide advanced":"+ advanced options"}),D&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Et.label,children:"PROVIDER"}),C.map(U=>{const nt=H(U),rt=A(U),ut=b===U.id,ct=Q===U.id;return y.jsxs("div",{style:{marginBottom:2},children:[y.jsxs("button",{type:"button",onClick:()=>k(U),style:{...Et.providerBtn,borderColor:ut?"var(--accent)":"var(--border)",opacity:nt||ct?1:.6},children:[y.jsxs("div",{style:{flex:1},children:[y.jsx("span",{style:{fontSize:12,fontWeight:600,color:ut?"var(--text-bright)":"var(--text-primary)"},children:U.name}),y.jsx("span",{style:Et.providerModels,children:U.models.map(st=>st.name).join(", ")})]}),y.jsx("span",{style:{fontSize:10,color:nt?"var(--green)":rt==="not installed"?"var(--text-muted)":"var(--amber)"},children:nt?ut?"active":"ready":rt})]}),ct&&y.jsxs("div",{style:Et.connectBox,children:[!U.installed&&y.jsxs("div",{children:[y.jsx("div",{style:Et.connectLabel,children:"Install first:"}),y.jsx("code",{style:Et.connectCode,children:U.installCommand}),y.jsx("div",{style:Et.connectHint,children:"Run this in your terminal, then click the provider again"})]}),U.installed&&U.authType==="api-key"&&!U.hasKey&&y.jsxs("div",{children:[y.jsxs("div",{style:Et.connectLabel,children:["API Key ",U.envKey?`(${U.envKey})`:""]}),y.jsxs("div",{style:{display:"flex",gap:4},children:[y.jsx("input",{type:"password",style:Et.input,placeholder:"sk-...",value:at,onChange:st=>$(st.target.value),onKeyDown:st=>st.key==="Enter"&&(st.preventDefault(),q())}),y.jsx("button",{type:"button",onClick:q,disabled:I||!at.trim(),style:Et.connectSaveBtn,children:I?"...":"Save"})]}),y.jsx("div",{style:Et.connectHint,children:"Encrypted locally. Never sent to GROOVE servers."})]}),U.installed&&U.authType==="subscription"&&y.jsxs("div",{children:[y.jsx("div",{style:Et.connectLabel,children:"Subscription auth"}),y.jsxs("div",{style:Et.connectHint,children:[U.name," uses your existing subscription. Make sure you're logged in via the CLI."]})]}),U.installed&&U.authType==="local"&&y.jsxs("div",{children:[y.jsx("div",{style:Et.connectLabel,children:"Local model"}),y.jsxs("div",{style:Et.connectHint,children:["Make sure ",U.name," is running locally. No API key needed."]})]}),y.jsx("button",{type:"button",onClick:()=>J(null),style:Et.connectCancel,children:"cancel"})]})]},U.id)}),(()=>{const U=C.find(rt=>rt.id===b),nt=(U==null?void 0:U.models)||[];return nt.length===0?null:y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Et.label,children:"MODEL"}),y.jsxs("select",{style:Et.input,value:w,onChange:rt=>M(rt.target.value),children:[y.jsx("option",{value:"auto",children:"Auto (recommended)"}),nt.map(rt=>y.jsxs("option",{value:rt.id,children:[rt.name," (",rt.tier,")"]},rt.id))]})]})})(),y.jsx("div",{style:Et.label,children:"FILE SCOPE"}),y.jsx("input",{style:Et.input,placeholder:"e.g. src/api/**, src/lib/**",value:o==="custom"?d:z,onChange:U=>{o==="custom"&&h(U.target.value)},readOnly:o!=="custom"}),y.jsx("div",{style:Et.hint,children:o==="custom"?"Comma-separated glob patterns":"Auto-set by role preset"})]}),j&&y.jsx("div",{style:Et.error,children:j}),y.jsx("button",{type:"submit",disabled:N,style:{...Et.submitBtn,opacity:N?.5:1},children:N?"spawning...":L?"Start Planning":"Spawn Agent"})]})]})}const Et={title:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5,marginBottom:14},label:{fontSize:11,color:"var(--text-dim)",marginBottom:4,marginTop:12,textTransform:"uppercase",letterSpacing:1.5,fontWeight:600},roleGrid:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},roleBtn:{background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 4px",color:"var(--text-primary)",fontSize:11,cursor:"pointer",fontFamily:"var(--font)",transition:"color 0.1s, border-color 0.1s"},roleBtnActive:{borderColor:"var(--accent)",color:"var(--text-bright)"},roleDesc:{fontSize:10,color:"var(--text-dim)",marginTop:4,fontStyle:"italic"},permGrid:{display:"flex",flexDirection:"column",gap:4},permBtn:{display:"flex",alignItems:"center",gap:10,padding:"8px 10px",width:"100%",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,cursor:"pointer",textAlign:"left",fontFamily:"var(--font)"},permBtnActive:{borderColor:"var(--accent)"},permIcon:{fontSize:14,fontWeight:700,color:"var(--accent)",width:18,textAlign:"center",flexShrink:0},permLabel:{fontSize:11,color:"var(--text-bright)",fontWeight:600},permDesc:{fontSize:10,color:"var(--text-dim)"},advancedToggle:{background:"none",border:"none",color:"var(--text-dim)",fontSize:10,cursor:"pointer",fontFamily:"var(--font)",padding:"8px 0",marginTop:8},providerBtn:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"8px 10px",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,cursor:"pointer",textAlign:"left",fontFamily:"var(--font)"},providerModels:{fontSize:10,color:"var(--text-dim)",marginLeft:6},connectBox:{padding:"8px 10px",margin:"2px 0 4px",background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2},connectLabel:{fontSize:11,color:"var(--text-primary)",fontWeight:600,marginBottom:4},connectCode:{display:"block",padding:"6px 8px",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,fontSize:11,color:"var(--accent)",wordBreak:"break-all"},connectHint:{fontSize:10,color:"var(--text-dim)",marginTop:4},connectSaveBtn:{padding:"6px 12px",flexShrink:0,background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:11,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"},connectCancel:{background:"none",border:"none",color:"var(--text-dim)",fontSize:10,cursor:"pointer",fontFamily:"var(--font)",padding:"4px 0",marginTop:4},input:{width:"100%",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",color:"var(--text-primary)",fontSize:12,outline:"none",fontFamily:"var(--font)"},textarea:{width:"100%",background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",color:"var(--text-primary)",fontSize:12,outline:"none",fontFamily:"var(--font)",resize:"vertical"},hint:{fontSize:10,color:"var(--text-muted)",marginTop:3},error:{color:"var(--red)",fontSize:11,marginTop:8},submitBtn:{width:"100%",marginTop:14,padding:"8px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:12,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"}};function JT(){var d;const[n,a]=X.useState(null),[o,r]=X.useState(!0);X.useEffect(()=>{u();const h=setInterval(u,1e4);return()=>clearInterval(h)},[]);async function u(){try{const h=await fetch("/api/journalist");a(await h.json())}catch{}r(!1)}async function f(){r(!0);try{await fetch("/api/journalist/cycle",{method:"POST"}),await u()}catch{}r(!1)}return y.jsxs("div",{style:{paddingTop:4},children:[y.jsxs("div",{style:Se.header,children:[y.jsx("span",{style:Se.title,children:"THE JOURNALIST"}),y.jsx("button",{onClick:f,disabled:o,style:Se.btn,children:o?"synthesizing...":"Run Cycle"})]}),y.jsxs("div",{style:Se.statusRow,children:[y.jsxs("span",{children:["Status: ",n!=null&&n.running?"active":"stopped"]}),y.jsxs("span",{children:["Cycles: ",(n==null?void 0:n.cycleCount)||0]}),(n==null?void 0:n.lastCycleAt)&&y.jsxs("span",{children:["Last: ",new Date(n.lastCycleAt).toLocaleTimeString()]})]}),n!=null&&n.lastSynthesis?y.jsxs("div",{children:[y.jsx("div",{style:Se.sectionLabel,children:"SUMMARY"}),y.jsx("div",{style:Se.textBox,children:n.lastSynthesis.summary}),n.lastSynthesis.projectMap&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Se.sectionLabel,children:"PROJECT MAP"}),y.jsx("pre",{style:Se.codeBox,children:n.lastSynthesis.projectMap})]}),n.lastSynthesis.decisions&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Se.sectionLabel,children:"DECISIONS"}),y.jsx("pre",{style:Se.codeBox,children:n.lastSynthesis.decisions})]})]}):y.jsx("div",{style:Se.empty,children:"No synthesis yet. The Journalist runs every 2 minutes when agents are active."}),((d=n==null?void 0:n.history)==null?void 0:d.length)>0&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Se.sectionLabel,children:"HISTORY"}),y.jsx("div",{style:Se.historyList,children:n.history.slice().reverse().map((h,g)=>{var m;return y.jsxs("div",{style:Se.historyEntry,children:[y.jsx("span",{style:Se.historyTime,children:new Date(h.timestamp).toLocaleTimeString()}),y.jsxs("span",{style:Se.historyText,children:["Cycle ",h.cycle,": ",h.agentCount," agent",h.agentCount!==1?"s":""," — ",(m=h.summary)==null?void 0:m.slice(0,80)]})]},g)})})]})]})}const Se={header:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},title:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5},btn:{padding:"3px 10px",background:"transparent",border:"1px solid var(--purple)",borderRadius:2,color:"var(--purple)",fontSize:11,cursor:"pointer",fontFamily:"var(--font)"},statusRow:{display:"flex",gap:12,fontSize:11,color:"var(--text-dim)",marginBottom:12,padding:"6px 0",borderBottom:"1px solid var(--border)",flexWrap:"wrap"},sectionLabel:{fontSize:11,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5,marginBottom:4,marginTop:12,fontWeight:600},textBox:{background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2,padding:8,fontSize:12,color:"var(--text-primary)",lineHeight:1.5},codeBox:{background:"var(--bg-base)",border:"1px solid var(--border)",borderRadius:2,padding:8,fontSize:11,color:"var(--text-dim)",lineHeight:1.5,whiteSpace:"pre-wrap",maxHeight:200,overflowY:"auto",margin:0},empty:{color:"var(--text-dim)",fontSize:12,padding:16,textAlign:"center"},historyList:{maxHeight:160,overflowY:"auto",background:"var(--bg-base)",borderRadius:2,border:"1px solid var(--border)"},historyEntry:{padding:"4px 8px",borderBottom:"1px solid var(--bg-surface)",fontSize:10,display:"flex",gap:6},historyTime:{color:"var(--text-dim)",whiteSpace:"nowrap"},historyText:{color:"var(--text-primary)"}};function WT(){const[n,a]=X.useState([]),[o,r]=X.useState(null),[u,f]=X.useState(!1),[d,h]=X.useState(""),g=Mt(S=>S.showStatus);X.useEffect(()=>{m();const S=setInterval(m,5e3);return()=>clearInterval(S)},[]);async function m(){try{const w=await(await fetch("/api/teams")).json();a(w.teams),r(w.activeTeam)}catch{}}async function x(S){try{await fetch(`/api/teams/${encodeURIComponent(S)}/load`,{method:"POST"}),g(`loaded team "${S}"`),m()}catch{g("failed to load team")}}async function p(){if(d.trim())try{await fetch("/api/teams",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:d.trim()})}),g(`saved team "${d}"`),h(""),f(!1),m()}catch{g("failed to save team")}}async function b(S){await fetch(`/api/teams/${encodeURIComponent(S)}`,{method:"DELETE"}),g(`deleted "${S}"`),m()}return y.jsxs("div",{style:Re.container,children:[y.jsx("div",{style:Re.title,children:"SAVED TEAMS"}),n.length===0?y.jsx("div",{style:Re.empty,children:"No saved teams"}):n.map(S=>y.jsxs("div",{style:{...Re.item,background:S.name===o?"var(--bg-hover)":"transparent"},children:[y.jsxs("div",{style:{flex:1},children:[y.jsxs("div",{style:Re.teamName,children:[">"," ",S.name]}),y.jsxs("div",{style:Re.teamMeta,children:[S.agents," agents"]})]}),y.jsxs("div",{style:{display:"flex",gap:8},children:[y.jsx("button",{onClick:()=>x(S.name),style:Re.loadBtn,children:"Load"}),y.jsx("button",{onClick:()=>b(S.name),style:Re.deleteBtn,children:"x"})]})]},S.name)),y.jsx("div",{style:Re.divider}),u?y.jsxs("div",{style:Re.saveRow,children:[y.jsx("input",{style:Re.saveInput,placeholder:"Team name...",value:d,onChange:S=>h(S.target.value),onKeyDown:S=>S.key==="Enter"&&p(),autoFocus:!0}),y.jsx("button",{onClick:p,style:Re.saveBtn,children:"Save"}),y.jsx("button",{onClick:()=>f(!1),style:Re.cancelBtn,children:"x"})]}):y.jsx("button",{onClick:()=>f(!0),style:Re.saveTeamBtn,children:"Save Current as Team"})]})}const Re={container:{padding:24,maxWidth:600,margin:"0 auto"},title:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5,marginBottom:16},item:{padding:"10px 12px",display:"flex",justifyContent:"space-between",alignItems:"center",borderBottom:"1px solid var(--border)"},teamName:{fontSize:12,color:"var(--text-bright)",fontWeight:600},teamMeta:{fontSize:11,color:"var(--text-dim)",marginTop:2},loadBtn:{background:"transparent",border:"none",color:"var(--accent)",fontSize:11,cursor:"pointer",fontFamily:"var(--font)",fontWeight:600},deleteBtn:{background:"none",border:"none",color:"var(--text-dim)",fontSize:12,cursor:"pointer",fontFamily:"var(--font)"},empty:{padding:20,color:"var(--text-dim)",fontSize:12,textAlign:"center"},divider:{borderTop:"1px solid var(--border)",margin:"12px 0"},saveTeamBtn:{background:"transparent",border:"1px solid var(--accent)",borderRadius:2,padding:"6px 14px",color:"var(--accent)",fontSize:12,cursor:"pointer",fontFamily:"var(--font)",fontWeight:600},saveRow:{display:"flex",gap:6,alignItems:"center"},saveInput:{flex:1,background:"var(--bg-surface)",border:"1px solid var(--border)",borderRadius:2,padding:"6px 8px",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font)",outline:"none"},saveBtn:{padding:"6px 12px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:12,cursor:"pointer",fontFamily:"var(--font)"},cancelBtn:{background:"none",border:"none",color:"var(--text-dim)",fontSize:12,cursor:"pointer",fontFamily:"var(--font)"}},ai="#4ae168",dd="#33afbc",hd="#e5c07b",gd="#e06c75",FT="#c678dd",IT="#61afef",oa=[dd,hd,ai,FT,gd,IT,"#d19a66"],PT={medium:.009};function t3(){const[n,a]=X.useState(null),o=Mt(S=>S.agents),r=Mt(S=>S.dashTelemetry);X.useEffect(()=>{u();const S=setInterval(u,4e3);return()=>clearInterval(S)},[]);async function u(){try{const w=await(await fetch("/api/dashboard")).json();a(w),Mt.setState(M=>{const C={...M.dashTelemetry},T=Date.now();for(const N of w.agents.breakdown){C[N.id]||(C[N.id]=[]);const _=C[N.id],j=_[_.length-1];(!j||N.tokens!==j.v||T-j.t>1e4)&&(_.push({t:T,v:N.tokens||0,name:N.name}),_.length>200&&(C[N.id]=_.slice(-200)))}return{dashTelemetry:C}})}catch{}}if(!n)return y.jsxs("div",{style:Lt.loadingRoot,children:[y.jsx("div",{style:Lt.loadingText,children:"COMMAND CENTER"}),y.jsx("div",{style:Lt.loadingBar,children:y.jsx("div",{style:Lt.loadingFill})})]});const{tokens:f,routing:d,rotation:h,adaptive:g,journalist:m,uptime:x}=n,p=n.agents.breakdown,b=f.savings.total/1e3*PT.medium;return y.jsxs("div",{style:Lt.root,children:[y.jsxs("div",{style:Lt.statBar,children:[y.jsx(yo,{label:"Total Tokens",value:Cl(f.totalTokens),sub:`${n.agents.total} agent${n.agents.total!==1?"s":""}`}),y.jsx(yo,{label:"Tokens Saved",value:Cl(f.savings.total),sub:`${f.savings.percentage||0}% efficiency`,color:ai}),y.jsx(yo,{label:"Est. Savings",value:b>0?`$${b.toFixed(2)}`:"$0.00",sub:"based on token costs",color:ai}),y.jsx(yo,{label:"Rotations",value:h.totalRotations,sub:`${Cl(h.totalTokensSaved)} tok recovered`}),y.jsx(yo,{label:"Uptime",value:l3(x),sub:`${n.agents.running} running`})]}),y.jsxs("div",{style:Lt.midRow,children:[y.jsxs("div",{style:Lt.chartPanel,children:[y.jsxs("div",{style:Lt.panelHead,children:[y.jsx("span",{children:"Token Usage"}),y.jsx("span",{style:Lt.panelHeadRight,children:p.filter(S=>S.tokens>0).map((S,w)=>y.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,marginLeft:12},children:[y.jsx("span",{style:{width:6,height:2,background:oa[w%oa.length],display:"inline-block",borderRadius:1}}),y.jsx("span",{style:{fontSize:9},children:S.name})]},S.id))})]}),y.jsx(n3,{tokenTimeline:r,agents:o})]}),y.jsxs("div",{style:Lt.donutPanel,children:[y.jsx("div",{style:Lt.panelHead,children:"Model Routing"}),y.jsx(e3,{routing:d})]})]}),y.jsxs("div",{style:Lt.bottomRow,children:[y.jsxs("div",{style:Lt.panel,children:[y.jsx("div",{style:Lt.panelHead,children:"Savings Breakdown"}),y.jsxs("div",{style:Lt.scrollInner,children:[y.jsx(xs,{label:"Rotation",value:f.savings.fromRotation,max:f.savings.total||1,color:dd}),y.jsx(xs,{label:"Conflict Prevention",value:f.savings.fromConflictPrevention,max:f.savings.total||1,color:hd}),y.jsx(xs,{label:"Cold-Start Skip",value:f.savings.fromColdStartSkip,max:f.savings.total||1,color:ai}),y.jsx("div",{style:Lt.divider}),y.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:10,color:"#8b929e",padding:"4px 0"},children:[y.jsx("span",{children:"Without Groove"}),y.jsx("span",{style:{color:gd,fontWeight:600},children:Cl(f.savings.estimatedWithoutGroove)})]}),y.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:10,color:"#8b929e",padding:"4px 0"},children:[y.jsx("span",{children:"With Groove"}),y.jsx("span",{style:{color:ai,fontWeight:600},children:Cl(f.totalTokens)})]}),y.jsx("div",{style:{fontSize:8,color:"#5c6370",marginTop:4,lineHeight:1.4},children:"Calculated from: rotation recovery (30% of degraded context), cold-start prevention (2K tokens/skip), conflict avoidance (500 tokens/conflict)."}),m.lastSummary&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Lt.divider}),y.jsx("div",{style:Lt.panelHead,children:"Journalist"}),y.jsx("div",{style:Lt.journSummary,children:m.lastSummary})]})]})]}),y.jsxs("div",{style:Lt.panel,children:[y.jsx("div",{style:Lt.panelHead,children:"Agent Fleet"}),y.jsxs("div",{style:Lt.scrollInner,children:[p.length===0?y.jsx("div",{style:Lt.empty,children:"No agents spawned"}):p.map((S,w)=>y.jsx(xs,{label:S.name,value:S.tokens,max:Math.max(...p.map(M=>M.tokens),1),color:oa[w%oa.length],sub:`${S.role} · ${S.model||"auto"}`},S.id)),h.history.length>0&&y.jsxs(y.Fragment,{children:[y.jsx("div",{style:Lt.divider}),y.jsx("div",{style:Lt.panelHead,children:"Rotation History"}),h.history.slice().reverse().slice(0,8).map((S,w)=>y.jsxs("div",{style:Lt.rotEntry,children:[y.jsx("span",{style:Lt.rotName,children:S.agentName}),y.jsxs("span",{style:{color:ai,fontSize:9},children:[Cl(S.oldTokens)," saved"]}),y.jsx("span",{style:Lt.rotTime,children:i3(S.timestamp)})]},w))]})]})]})]})]})}function yo({label:n,value:a,sub:o,color:r}){return y.jsxs("div",{style:Lt.statCard,children:[y.jsx("div",{style:{fontSize:10,color:"#8b929e",textTransform:"uppercase",letterSpacing:1,marginBottom:6},children:n}),y.jsx("div",{style:{fontSize:20,fontWeight:700,color:r||"#e6e6e6",lineHeight:1},children:a}),o&&y.jsx("div",{style:{fontSize:9,color:"#6b7280",marginTop:4},children:o})]})}function xs({label:n,value:a,max:o,color:r,sub:u}){const f=o>0?a/o*100:0;return y.jsxs("div",{style:{padding:"6px 0"},children:[y.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:4},children:[y.jsx("span",{style:{fontSize:11,color:"#abb2bf"},children:n}),y.jsx("span",{style:{fontSize:11,color:"#e6e6e6",fontWeight:600},children:Cl(a)})]}),y.jsx("div",{style:{height:4,background:"#1e222a",borderRadius:2},children:y.jsx("div",{style:{width:`${Math.max(f,a>0?1:0)}%`,height:"100%",background:r,borderRadius:2,transition:"width 0.3s"}})}),u&&y.jsx("div",{style:{fontSize:8,color:"#3e4451",marginTop:2},children:u})]})}function e3({routing:n}){const a=[{label:"Heavy",color:gd,count:n.byTier.heavy,cost:"$0.045/1k"},{label:"Medium",color:hd,count:n.byTier.medium,cost:"$0.009/1k"},{label:"Light",color:ai,count:n.byTier.light,cost:"$0.002/1k"}],o=a.reduce((g,m)=>g+m.count,0)||1,r=50,u=60,f=60,d=2*Math.PI*r;let h=0;return y.jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,alignItems:"center",justifyContent:"center",gap:12,minHeight:0},children:[y.jsxs("svg",{width:"120",height:"120",viewBox:"0 0 120 120",children:[y.jsx("circle",{cx:u,cy:f,r,fill:"none",stroke:"#1e222a",strokeWidth:"10"}),a.map(g=>{if(g.count===0)return null;const x=g.count/o*d,p=y.jsx("circle",{cx:u,cy:f,r,fill:"none",stroke:g.color,strokeWidth:"10",strokeDasharray:`${x} ${d-x}`,strokeDashoffset:-h,strokeLinecap:"butt",transform:`rotate(-90 ${u} ${f})`,style:{transition:"stroke-dasharray 0.5s"}},g.label);return h+=x,p}),y.jsx("text",{x:u,y:f-4,textAnchor:"middle",fill:"#e6e6e6",fontSize:"16",fontWeight:"700",fontFamily:"JetBrains Mono, monospace",children:o>1?o:n.totalDecisions}),y.jsx("text",{x:u,y:f+10,textAnchor:"middle",fill:"#5c6370",fontSize:"8",fontFamily:"JetBrains Mono, monospace",children:"decisions"})]}),y.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6,width:"100%",padding:"0 8px"},children:a.map(g=>y.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:10},children:[y.jsx("span",{style:{width:8,height:8,borderRadius:2,background:g.color,flexShrink:0}}),y.jsx("span",{style:{color:"#abb2bf",flex:1},children:g.label}),y.jsx("span",{style:{color:"#5c6370",fontSize:9},children:g.cost}),y.jsx("span",{style:{color:"#e6e6e6",fontWeight:600,minWidth:20,textAlign:"right"},children:g.count})]},g.label))}),y.jsxs("div",{style:{fontSize:9,color:"#3e4451"},children:[n.autoRoutedCount," auto-routed"]})]})}function n3({tokenTimeline:n,agents:a}){const o=X.useRef(),r=X.useRef(),u=X.useCallback(()=>{const f=o.current,d=r.current;if(!f||!d)return;const h=window.devicePixelRatio||1,g=f.clientWidth,m=f.clientHeight;if(g===0||m===0)return;d.width=g*h,d.height=m*h,d.style.width=g+"px",d.style.height=m+"px";const x=d.getContext("2d");x.scale(h,h),x.clearRect(0,0,g,m);const p=40,b=10,S=10,w=20,M=g-p-b,C=m-S-w;x.strokeStyle="#1e222a",x.lineWidth=.5;for(let D=0;D<=4;D++){const B=S+D/4*C;x.beginPath(),x.moveTo(p,B),x.lineTo(g-b,B),x.stroke()}const T=Object.keys(n);if(T.length===0){x.fillStyle="#3e4451",x.font="10px monospace",x.textAlign="center",x.fillText("Waiting for agent telemetry...",g/2,m/2);return}let N=1/0,_=0,j=0;for(const D of T)for(const B of n[D]||[])B.t<N&&(N=B.t),B.t>_&&(_=B.t),B.v>j&&(j=B.v);_===N&&(_=N+6e4),j===0&&(j=100);const V=_-N;x.fillStyle="#3e4451",x.font="8px monospace",x.textAlign="right";for(let D=0;D<=4;D++){const B=j*(1-D/4);x.fillText(Cl(Math.round(B)),p-4,S+D/4*C+3)}x.textAlign="center";for(let D=0;D<=4;D++){const B=N+D/4*V,Q=new Date(B);x.fillText(`${Q.getHours()}:${String(Q.getMinutes()).padStart(2,"0")}`,p+D/4*M,m-4)}T.forEach((D,B)=>{const Q=n[D]||[];if(Q.length<2)return;const J=oa[B%oa.length],at=Q.map(K=>({x:p+(K.t-N)/V*M,y:S+(1-K.v/j)*C}));x.beginPath(),x.moveTo(at[0].x,S+C);for(const K of at)x.lineTo(K.x,K.y);x.lineTo(at[at.length-1].x,S+C),x.closePath();const $=x.createLinearGradient(0,S,0,S+C);$.addColorStop(0,J+"20"),$.addColorStop(1,J+"03"),x.fillStyle=$,x.fill(),x.beginPath();for(let K=0;K<at.length;K++)K===0?x.moveTo(at[K].x,at[K].y):x.lineTo(at[K].x,at[K].y);x.strokeStyle=J,x.lineWidth=1,x.stroke();const I=at[at.length-1];x.beginPath(),x.arc(I.x,I.y,2,0,Math.PI*2),x.fillStyle=J,x.fill()})},[n,a]);return X.useEffect(()=>{u()},[u]),X.useEffect(()=>{const f=new ResizeObserver(u);return o.current&&f.observe(o.current),()=>f.disconnect()},[u]),y.jsx("div",{ref:o,style:{flex:1,minHeight:0,position:"relative"},children:y.jsx("canvas",{ref:r,style:{display:"block",position:"absolute",top:0,left:0}})})}function Cl(n){return n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}k`:String(n||0)}function l3(n){const a=Math.floor(n/3600),o=Math.floor(n%3600/60);return a>0?`${a}h ${o}m`:`${o}m ${Math.floor(n%60)}s`}function i3(n){const a=Math.floor((Date.now()-new Date(n).getTime())/6e4);return a>=60?`${Math.floor(a/60)}h ago`:a>0?`${a}m ago`:"now"}const Lt={root:{width:"100%",height:"100%",display:"flex",flexDirection:"column",overflow:"hidden",padding:14,gap:12,background:"var(--bg-base)"},loadingRoot:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:12},loadingText:{fontSize:11,fontWeight:700,color:"var(--text-dim)",letterSpacing:3,textTransform:"uppercase"},loadingBar:{width:120,height:2,background:"#282c34",borderRadius:1,overflow:"hidden"},loadingFill:{width:"40%",height:"100%",background:dd,animation:"pulse 1.5s infinite"},statBar:{display:"flex",flexShrink:0,background:"#282c34",borderRadius:12,overflow:"hidden"},statCard:{flex:1,padding:"14px 16px",borderRight:"1px solid #1e222a",display:"flex",flexDirection:"column"},midRow:{display:"grid",gridTemplateColumns:"2fr 1fr",gap:12,flex:2,minHeight:0},chartPanel:{background:"#282c34",borderRadius:12,padding:"12px 14px",display:"flex",flexDirection:"column",minHeight:0},donutPanel:{background:"#282c34",borderRadius:12,padding:"12px 14px",display:"flex",flexDirection:"column",minHeight:0},bottomRow:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,flex:3,minHeight:0},panel:{background:"#282c34",borderRadius:12,padding:"12px 14px",display:"flex",flexDirection:"column",minHeight:0,overflow:"hidden"},panelHead:{fontSize:10,fontWeight:600,color:"#5c6370",textTransform:"uppercase",letterSpacing:1,marginBottom:8,flexShrink:0,display:"flex",justifyContent:"space-between",alignItems:"center"},panelHeadRight:{display:"flex",alignItems:"center",color:"#3e4451"},scrollInner:{flex:1,minHeight:0,overflowY:"auto"},empty:{color:"#3e4451",fontSize:10,textAlign:"center",padding:20},divider:{height:1,background:"#1e222a",margin:"8px 0",flexShrink:0},journSummary:{fontSize:10,color:"#8b929e",lineHeight:1.5,padding:"4px 0",whiteSpace:"pre-wrap",maxHeight:80,overflowY:"auto"},rotEntry:{display:"flex",alignItems:"center",gap:8,padding:"4px 0",fontSize:10},rotName:{color:"#abb2bf",flex:1},rotTime:{color:"#3e4451",fontSize:9}};function a3(){const[n,a]=X.useState(null);X.useEffect(()=>{o();const f=setInterval(o,4e3);return()=>clearInterval(f)},[]);async function o(){try{const f=await fetch("/api/pm/history");a(await f.json())}catch{}}const r=(n==null?void 0:n.history)||[],u=(n==null?void 0:n.stats)||{};return y.jsxs("div",{style:fe.container,children:[y.jsxs("div",{style:fe.header,children:[y.jsx("div",{style:fe.title,children:"PM REVIEW LOG"}),y.jsx("div",{style:fe.subtitle,children:"AI Project Manager reviews risky agent operations in Auto mode"})]}),y.jsxs("div",{style:fe.statsBar,children:[y.jsx(bs,{label:"REVIEWS",value:u.totalReviews||0}),y.jsx(bs,{label:"APPROVED",value:u.approved||0,color:"var(--green)"}),y.jsx(bs,{label:"REJECTED",value:u.rejected||0,color:"var(--red)"}),y.jsx(bs,{label:"AVG TIME",value:u.avgDurationMs?`${(u.avgDurationMs/1e3).toFixed(1)}s`:"-"})]}),r.length===0?y.jsxs("div",{style:fe.empty,children:[y.jsx("div",{style:fe.emptyTitle,children:"No reviews yet"}),y.jsx("div",{style:fe.emptyDesc,children:"Spawn agents with Auto permission mode. The AI PM will review risky operations (new files, deletions, config changes) before they happen."})]}):y.jsx("div",{style:fe.list,children:r.slice().reverse().map((f,d)=>y.jsxs("div",{style:fe.entry,children:[y.jsxs("div",{style:fe.entryTop,children:[y.jsx("span",{style:{...fe.verdict,color:f.approved?"var(--green)":"var(--red)",borderColor:f.approved?"rgba(74,225,104,0.3)":"rgba(224,108,117,0.3)",background:f.approved?"rgba(74,225,104,0.08)":"rgba(224,108,117,0.08)"},children:f.approved?"APPROVED":"REJECTED"}),y.jsx("span",{style:fe.entryAgent,children:f.agent}),y.jsx("span",{style:fe.entryAction,children:f.action}),y.jsx("span",{style:fe.entryTime,children:o3(f.timestamp)})]}),y.jsx("div",{style:fe.entryFile,children:f.file}),f.description&&y.jsx("div",{style:fe.entryDesc,children:f.description}),y.jsx("div",{style:fe.entryReason,children:f.reason})]},d))})]})}function bs({label:n,value:a,color:o}){return y.jsxs("div",{style:fe.stat,children:[y.jsx("div",{style:{fontSize:16,fontWeight:700,color:o||"var(--text-bright)"},children:a}),y.jsx("div",{style:{fontSize:7,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1},children:n})]})}function o3(n){const a=Math.floor((Date.now()-new Date(n).getTime())/6e4);return a>=60?`${Math.floor(a/60)}h ago`:a>0?`${a}m ago`:"just now"}const fe={container:{padding:24,maxWidth:700,margin:"0 auto"},header:{marginBottom:16},title:{fontSize:11,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:1.5},subtitle:{fontSize:10,color:"var(--text-dim)",marginTop:4},statsBar:{display:"flex",gap:8,marginBottom:16},stat:{flex:1,background:"var(--bg-surface)",border:"1px solid var(--border)",padding:"8px 10px",textAlign:"center"},empty:{textAlign:"center",padding:"40px 20px",background:"var(--bg-surface)",border:"1px solid var(--border)"},emptyTitle:{fontSize:12,color:"var(--text-primary)",fontWeight:600,marginBottom:8},emptyDesc:{fontSize:10,color:"var(--text-dim)",lineHeight:1.6,maxWidth:400,margin:"0 auto"},list:{display:"flex",flexDirection:"column",gap:4},entry:{background:"var(--bg-surface)",border:"1px solid var(--border)",padding:"8px 10px"},entryTop:{display:"flex",alignItems:"center",gap:8,marginBottom:4},verdict:{fontSize:8,fontWeight:700,letterSpacing:.5,padding:"1px 5px",border:"1px solid"},entryAgent:{fontSize:11,fontWeight:600,color:"var(--text-bright)"},entryAction:{fontSize:10,color:"var(--text-dim)"},entryTime:{fontSize:9,color:"var(--text-dim)",marginLeft:"auto"},entryFile:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font)"},entryDesc:{fontSize:10,color:"var(--text-primary)",marginTop:2},entryReason:{fontSize:10,color:"var(--text-dim)",marginTop:3,fontStyle:"italic"}},r3=[{id:"agents",label:"Agents"},{id:"stats",label:"Stats"},{id:"teams",label:"Teams"},{id:"approvals",label:"Approvals"}];function s3(){const n=Mt(p=>p.agents),a=Mt(p=>p.connected),o=Mt(p=>p.activeTab),r=Mt(p=>p.detailPanel),u=Mt(p=>p.statusMessage),f=Mt(p=>p.connect),d=Mt(p=>p.setActiveTab),h=Mt(p=>p.openDetail),g=Mt(p=>p.closeDetail);X.useEffect(()=>{f()},[f]);const m=n.filter(p=>p.status==="running").length,x=n.length>0;return y.jsxs("div",{style:Oe.root,children:[y.jsxs("header",{style:Oe.header,children:[y.jsx("div",{style:Oe.headerLeft,children:y.jsx("img",{src:"/groove-logo-short.png",alt:"GROOVE",style:{height:18,marginTop:3,opacity:.85}})}),y.jsx("div",{style:Oe.headerCenter,children:a&&r3.map(p=>y.jsx("button",{onClick:()=>d(p.id),style:{...Oe.tabBtn,color:o===p.id?"var(--text-bright)":"var(--text-primary)",borderBottom:o===p.id?"2px solid var(--accent)":"2px solid transparent",background:o===p.id?"var(--bg-active)":"transparent"},children:p.label},p.id))}),y.jsxs("div",{style:Oe.headerRight,children:[u&&y.jsx("span",{style:Oe.statusText,children:u}),y.jsx("span",{style:Oe.agentCount,children:m>0?`${m} running`:n.length>0?`${n.length} agent${n.length!==1?"s":""}`:""}),a&&y.jsxs(y.Fragment,{children:[y.jsx("button",{onClick:()=>(r==null?void 0:r.type)==="journalist"?g():h({type:"journalist"}),style:{...Oe.tabBtn,color:(r==null?void 0:r.type)==="journalist"?"var(--text-bright)":"var(--text-primary)",borderBottom:(r==null?void 0:r.type)==="journalist"?"2px solid var(--purple)":"2px solid transparent"},children:"Journalist"}),y.jsx("button",{onClick:()=>h({type:"spawn"}),style:Oe.spawnBtn,children:"+ Spawn"})]})]})]}),y.jsxs("div",{style:{position:"fixed",bottom:10,left:12,zIndex:50,display:"flex",alignItems:"center",gap:5},children:[y.jsx("div",{style:{width:5,height:5,borderRadius:"50%",background:a?"var(--green)":"var(--red)",animation:"pulse 2s infinite"}}),y.jsx("span",{style:{fontSize:9,fontWeight:600,letterSpacing:.8,color:a?"var(--green)":"var(--red)",textTransform:"uppercase",fontFamily:"var(--font)",animation:"pulse 3s infinite"},children:a?"connected":"offline"})]}),y.jsxs("div",{style:Oe.mainRow,children:[y.jsxs("main",{style:Oe.content,children:[o==="agents"&&(x?y.jsx(DT,{}):y.jsx(QT,{})),o==="stats"&&y.jsx(t3,{}),o==="teams"&&y.jsx(WT,{}),o==="approvals"&&y.jsx(a3,{})]}),r&&y.jsxs("aside",{style:{...Oe.detailPanel,width:r.type==="agent"?"45%":320},children:[y.jsx("button",{onClick:g,style:Oe.closeBtn,children:"x"}),r.type==="agent"&&y.jsx($T,{}),r.type==="spawn"&&y.jsx(KT,{}),r.type==="journalist"&&y.jsx(JT,{})]})]})]})}const Oe={root:{width:"100%",height:"100%",display:"flex",flexDirection:"column",background:"var(--bg-base)",color:"var(--text-primary)"},header:{height:40,padding:"0 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",background:"var(--bg-chrome)",flexShrink:0,position:"relative"},headerLeft:{display:"flex",alignItems:"center",gap:8},headerCenter:{display:"flex",alignItems:"center",gap:0},headerRight:{display:"flex",alignItems:"center",gap:10},tabBtn:{padding:"10px 14px",background:"transparent",border:"none",borderBottom:"2px solid transparent",fontSize:12,fontWeight:500,fontFamily:"var(--font)",cursor:"pointer",transition:"color 0.1s"},spawnBtn:{padding:"4px 12px",background:"transparent",border:"1px solid var(--accent)",borderRadius:2,color:"var(--accent)",fontSize:12,fontWeight:600,fontFamily:"var(--font)",cursor:"pointer"},agentCount:{fontSize:11,color:"var(--text-dim)"},statusText:{fontSize:11,color:"var(--text-dim)",fontStyle:"italic"},mainRow:{flex:1,display:"flex",overflow:"hidden"},content:{flex:1,overflow:"hidden",position:"relative"},detailPanel:{width:320,flexShrink:0,background:"var(--bg-chrome)",borderLeft:"1px solid var(--border)",padding:16,overflowY:"auto",position:"relative"},closeBtn:{position:"absolute",top:8,right:10,background:"none",border:"none",color:"var(--text-dim)",fontSize:14,cursor:"pointer",fontFamily:"var(--font)",padding:"2px 6px"}};x1.createRoot(document.getElementById("root")).render(y.jsx(s3,{}));
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>GROOVE</title>
7
- <script type="module" crossorigin src="/assets/index-C9USf6W_.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-BPVh7Oqk.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-CPzm9ZE9.css">
9
9
  </head>
10
10
  <body>