groove-dev 0.27.163 → 0.27.164

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.
@@ -1020,6 +1020,6 @@ State: ${v}`),children:[e.jsx(Xs,{size:10}),"Details"]}),e.jsxs(Oe,{size:"sm",va
1020
1020
  `),lang:A});continue}if(/^#{1,3}\s/.test(r)||/^\*\*[^*]+:\*\*\s*$/.test(r.trim())){const c=r.replace(/^#+\s*/,"").replace(/^\*\*/,"").replace(/:\*\*\s*$/,":").trim();s.push({type:"heading",content:c}),a++;continue}if(/^\s*[-*]\s/.test(r)){const c=[];for(;a<n.length&&/^\s*[-*]\s/.test(n[a]);)c.push(n[a].replace(/^\s*[-*]\s+/,"").trim()),a++;s.push({type:"list",items:c});continue}if(/^\s*\d+[\.)]\s/.test(r)){const c=[];for(;a<n.length&&/^\s*\d+[\.)]\s/.test(n[a]);)c.push(n[a].replace(/^\s*\d+[\.)]\s+/,"").trim()),a++;s.push({type:"numbered",items:c});continue}if(r.includes("|")&&a+1<n.length&&/^\|?\s*[-:]+/.test(n[a+1])){const c=r.split("|").map(f=>f.trim()).filter(Boolean);a+=2;const A=[];for(;a<n.length&&n[a].includes("|");)A.push(n[a].split("|").map(f=>f.trim()).filter(Boolean)),a++;s.push({type:"table",headers:c,rows:A});continue}if(!r.trim()){a++;continue}if(/^(Note|Warning|Important|IMPORTANT|TODO):/i.test(r.trim())){s.push({type:"note",content:r.trim()}),a++;continue}const l=[];for(;a<n.length&&n[a].trim()&&!/^#{1,3}\s/.test(n[a])&&!/^\s*[-*]\s/.test(n[a])&&!/^\s*\d+[\.)]\s/.test(n[a])&&!n[a].trimStart().startsWith("```");)l.push(n[a].trim()),a++;l.length>0&&s.push({type:"para",content:l.join(" ")})}return e.jsx("div",{className:"space-y-2",children:s.map((r,l)=>{switch(r.type){case"heading":return e.jsxs("div",{className:"flex items-center gap-1.5 pt-1.5 first:pt-0",children:[e.jsx("div",{className:"w-1 h-3.5 rounded-full bg-accent/40 flex-shrink-0"}),e.jsx("span",{className:"text-[12px] font-semibold text-text-0 font-sans",children:e.jsx(Pl,{text:r.content})})]},l);case"list":return e.jsx("div",{className:"space-y-1 pl-2",children:r.items.map((c,A)=>e.jsxs("div",{className:"flex gap-2 text-[12px] text-text-0 font-sans leading-relaxed",children:[e.jsx("span",{className:"text-accent/50 mt-0.5 flex-shrink-0",children:"-"}),e.jsx("span",{className:"min-w-0",children:e.jsx(Pl,{text:c})})]},A))},l);case"numbered":return e.jsx("div",{className:"space-y-1 pl-2",children:r.items.map((c,A)=>e.jsxs("div",{className:"flex gap-2 text-[12px] text-text-0 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 font-mono w-4 text-right flex-shrink-0",children:[A+1,"."]}),e.jsx("span",{className:"min-w-0",children:e.jsx(Pl,{text:c})})]},A))},l);case"code":return e.jsx("pre",{className:"p-2.5 rounded-md bg-[#0d1117] text-[11px] font-mono text-[#c9d1d9] overflow-x-auto whitespace-pre-wrap border border-white/[0.06] leading-relaxed",children:r.content},l);case"table":return e.jsx(Vb,{headers:r.headers,rows:r.rows},l);case"note":return e.jsxs("div",{className:"flex items-start gap-1.5 px-2.5 py-1.5 rounded-md bg-warning/6 border border-warning/12",children:[e.jsx(Zs,{size:10,className:"text-warning mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-warning/80 font-sans",children:e.jsx(Pl,{text:r.content})})]},l);case"para":default:return e.jsx("p",{className:"text-[12px] text-text-0 font-sans leading-relaxed",children:e.jsx(Pl,{text:r.content})},l)}})})}function Qre({text:t}){if(!t)return null;const s=t.split(/(```[\s\S]*?```)/g);return e.jsx("span",{children:s.map((n,a)=>{if(n.startsWith("```")&&n.endsWith("```")){const r=n.slice(3,-3).replace(/^\w+\n/,"");return e.jsx("pre",{className:"my-1.5 p-2 rounded-md bg-[#0d1117] text-[11px] font-mono text-[#c9d1d9] overflow-x-auto whitespace-pre-wrap border border-white/[0.06]",children:r},a)}return e.jsx("span",{children:e.jsx(Pl,{text:n})},a)})})}function Nre({src:t,type:s,onClose:n}){return p.useEffect(()=>{function a(r){r.key==="Escape"&&n()}return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[n]),e.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:n,children:[e.jsx("button",{onClick:n,className:"absolute top-4 right-4 p-2 text-white/70 hover:text-white cursor-pointer z-10",children:e.jsx(De,{size:20})}),e.jsx("div",{className:"max-w-[90vw] max-h-[90vh]",onClick:a=>a.stopPropagation(),children:s==="video"?e.jsx("video",{src:t,controls:!0,autoPlay:!0,className:"max-w-full max-h-[85vh] rounded-lg"}):e.jsx("img",{src:t,className:"max-w-full max-h-[85vh] rounded-lg object-contain",alt:""})})]})}function Sre({attachments:t}){const[s,n]=p.useState(null);if(!t||t.length===0)return null;const a=t.filter(c=>c.type==="image"),r=t.filter(c=>c.type==="video"),l=t.filter(c=>c.type==="file");return e.jsxs(e.Fragment,{children:[s&&e.jsx(Nre,{src:s.src,type:s.type,onClose:()=>n(null)}),(a.length>0||r.length>0)&&e.jsxs("div",{className:"flex flex-wrap gap-1.5 mt-2",children:[a.map((c,A)=>e.jsxs("button",{onClick:()=>n({src:c.dataUrl,type:"image"}),className:"relative group rounded-md overflow-hidden border border-border-subtle hover:border-accent/40 transition-colors cursor-pointer flex-shrink-0",children:[e.jsx("img",{src:c.dataUrl,className:"w-16 h-16 object-cover",alt:c.name}),e.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/20 transition-colors flex items-center justify-center",children:e.jsx(Xs,{size:14,className:"text-white opacity-0 group-hover:opacity-100 transition-opacity"})})]},A)),r.map((c,A)=>e.jsxs("button",{onClick:()=>n({src:c.dataUrl,type:"video"}),className:"relative group rounded-md overflow-hidden border border-border-subtle hover:border-accent/40 transition-colors cursor-pointer flex-shrink-0",children:[e.jsx("video",{src:c.dataUrl,className:"w-16 h-16 object-cover",muted:!0}),e.jsx("div",{className:"absolute inset-0 bg-black/30 group-hover:bg-black/40 transition-colors flex items-center justify-center",children:e.jsx(dS,{size:14,className:"text-white"})})]},A))]}),l.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:l.map((c,A)=>e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-md bg-surface-3 border border-border-subtle",children:[e.jsx(Fo,{size:11,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-sans text-text-1 truncate max-w-[140px]",children:c.name}),e.jsx("span",{className:"text-[10px] font-mono text-text-4",children:q4(c.size)})]},A))})]})}function q4(t){return t?t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(0)}KB`:`${(t/(1024*1024)).toFixed(1)}MB`:""}function Bre({msg:t}){return e.jsx("div",{className:"flex justify-end pl-8",children:e.jsxs("div",{className:"max-w-[90%]",children:[e.jsxs("div",{className:"px-3.5 py-2.5 rounded-lg border bg-info/10 border-info/25",children:[t.text&&e.jsx("div",{className:"text-[12px] font-sans whitespace-pre-wrap break-words leading-relaxed text-text-0",children:e.jsx(Qre,{text:t.text})}),e.jsx(Sre,{attachments:t.attachments})]}),e.jsx("div",{className:"text-[10px] text-text-4 font-sans mt-1 text-right",children:As(t.timestamp)})]})})}function Cre({msg:t,agent:s}){var l,c;const[n,a]=p.useState(((l=t.text)==null?void 0:l.length)>600),r=((c=t.text)==null?void 0:c.length)>600;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-1 font-sans",children:(s==null?void 0:s.name)||"Agent"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:s==null?void 0:s.role}),e.jsx("span",{className:"text-[10px] text-text-4 font-sans ml-auto",children:As(t.timestamp)})]}),e.jsx("div",{className:"border-l border-accent pl-3.5 py-1",children:e.jsx(jre,{text:n?t.text.slice(0,600)+"...":t.text})}),n&&e.jsxs("button",{onClick:()=>a(!1),className:"ml-3.5 mt-1.5 flex items-center gap-1.5 text-[11px] text-accent/70 hover:text-accent font-sans font-medium cursor-pointer transition-colors",children:[e.jsx(ft,{size:11}),"Show full response"]}),r&&!n&&e.jsxs("button",{onClick:()=>a(!0),className:"ml-3.5 mt-1.5 flex items-center gap-1.5 text-[11px] text-accent/70 hover:text-accent font-sans font-medium cursor-pointer transition-colors",children:[e.jsx(ft,{size:11,className:"rotate-180"}),"Collapse"]})]})}function kre({msg:t}){return e.jsxs("div",{className:"flex items-center gap-3 py-2",children:[e.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),e.jsx("span",{className:"text-[10px] text-text-4 font-sans flex-shrink-0 uppercase tracking-wide",children:t.text}),e.jsx("div",{className:"flex-1 h-px bg-border-subtle"})]})}function Tre({entries:t,isLive:s}){const[n,a]=p.useState(0);if(p.useEffect(()=>{if(!s||t.length<=1)return;const l=setInterval(()=>a(c=>(c+1)%t.length),1500);return()=>clearInterval(l)},[t.length,s]),!s){const l=t[t.length-1],A=K4(l.text).icon;return e.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-1 text-[10px] text-text-4 font-mono",children:[e.jsx(A,{size:10,className:"opacity-50"}),e.jsxs("span",{children:[t.length," tool call",t.length!==1?"s":""]})]})}const r=t[Math.min(n,t.length-1)];return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 w-full rounded-md bg-surface-3/50 border border-border-subtle/30",children:[e.jsx(_e,{size:11,className:"text-accent animate-spin flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-text-2 font-mono truncate min-w-0 flex-1 transition-opacity duration-300",children:r.text}),t.length>1&&e.jsx("span",{className:"text-[10px] text-text-4 font-mono flex-shrink-0",children:t.length})]})}function Ure({agent:t}){const s=k(f=>f.activityLog[t.id])||kA,n=s[s.length-1],a=n?K4(n.text):null,r=(a==null?void 0:a.icon)||xn,l=n&&Date.now()-n.timestamp<1e4,c=l&&n.text?n.text.length>60?n.text.slice(0,60)+"...":n.text:null,A=Math.round((t.contextUsage||0)*100);return e.jsxs("div",{className:"flex items-center gap-3 px-4 h-8 border-b border-border-subtle bg-surface-1/80 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-accent/15 animate-ping [animation-duration:2s]"}),e.jsx("span",{className:"relative w-1.5 h-1.5 rounded-full bg-accent"})]}),l?e.jsxs(e.Fragment,{children:[e.jsx(r,{size:10,className:G(a.color,"flex-shrink-0")}),e.jsx("span",{className:"text-[11px] text-text-2 font-sans truncate",children:c})]}):e.jsx("span",{className:"text-[11px] text-text-3 font-sans",children:"Working..."})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[e.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:Ere(t.tokensUsed)}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-14 h-0.5 rounded-sm bg-surface-4 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-500",style:{width:`${A}%`,background:A>=75?"var(--color-danger)":A>=50?"var(--color-warning)":"var(--color-accent)"}})}),e.jsxs("span",{className:"text-[10px] text-text-4 font-mono w-7 text-right",children:[A,"%"]})]})]})]})}function Ere(t){return t?t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"K":String(t):"0"}function Pre({agent:t}){const[s,n]=p.useState([]),a=[{text:`Initializing ${t.name}`,delay:0},{text:`Role: ${t.role}`,delay:400},{text:`Provider: ${t.provider||"claude-code"}`,delay:700},{text:"Loading workspace context",delay:1e3},{text:"Scanning project structure",delay:1400},{text:"Session active",delay:1900}];return p.useEffect(()=>{const r=a.map((l,c)=>setTimeout(()=>n(A=>[...A,c]),l.delay));return()=>r.forEach(clearTimeout)},[]),e.jsxs("div",{className:"flex flex-col px-4 pt-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5",children:[e.jsxs("div",{className:"relative w-9 h-9",children:[e.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-accent/20 animate-ping [animation-duration:2s]"}),e.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent animate-spin [animation-duration:1s]"}),e.jsx("span",{className:"absolute inset-[5px] rounded-full bg-accent/8"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-text-0 font-sans",children:t.name}),e.jsx("p",{className:"text-2xs text-accent font-mono",children:"starting up"})]})]}),e.jsx("div",{className:"space-y-2 pl-3 border-l border-accent/15",children:a.map((r,l)=>{const c=s.includes(l),A=l===a.length-1;return e.jsxs("div",{className:G("flex items-center gap-2.5 transition-all duration-300",c?"opacity-100 translate-x-0":"opacity-0 -translate-x-2"),children:[e.jsx("span",{className:G("w-1 h-1 rounded-full flex-shrink-0",A&&c?"bg-accent":c?"bg-text-3":"bg-transparent")}),e.jsx("span",{className:G("text-[11px] font-mono",A&&c?"text-accent":"text-text-3"),children:r.text}),A&&c&&e.jsxs("span",{className:"flex gap-0.5 ml-1",children:[e.jsx("span",{className:"w-1 h-1 rounded-full bg-accent animate-pulse [animation-delay:0ms]"}),e.jsx("span",{className:"w-1 h-1 rounded-full bg-accent animate-pulse [animation-delay:200ms]"}),e.jsx("span",{className:"w-1 h-1 rounded-full bg-accent animate-pulse [animation-delay:400ms]"})]})]},l)})})]})}function Fre({snippet:t,onRemove:s}){const n=t.type==="code",a=n?jb:Nr,r=t.code.split(`
1021
1021
  `).length;let l;return n&&t.filePath?l=`${t.filePath.split("/").pop()}:${t.lineStart}-${t.lineEnd}`:l=`${n?"":"Terminal · "}${r} line${r!==1?"s":""}`,e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-md bg-accent/10 border border-accent/20 text-accent",children:[e.jsx(a,{size:11,className:"flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-sans font-medium truncate max-w-[160px]",children:l}),t.instruction&&e.jsxs("span",{className:"text-2xs text-accent/60 truncate max-w-[100px]",children:["· ",t.instruction]}),e.jsx("button",{onClick:s,className:"p-0.5 rounded hover:bg-accent/20 cursor-pointer flex-shrink-0",children:e.jsx(De,{size:9})})]})}function W4({agent:t}){const s=k(X=>X.chatHistory[t.id])||kA,n=k(X=>X.activityLog[t.id])||kA,a=k(X=>X.instructAgent),r=k(X=>{var ee;return(ee=X.thinkingAgents)==null?void 0:ee.has(t.id)}),l=p.useRef(kA),c=p.useRef(kA);s.length>0&&(l.current=s),n.length>0&&(c.current=n);const A=s.length>0?s:l.current,f=n.length>0?n:c.current,x=k(X=>X.editorPendingSnippet),h=k(X=>X.clearSnippet),g=k(X=>X.chatInputs[t.id]||""),O=X=>k.setState(ee=>{const pe=ee.chatInputs[t.id]||"",q=typeof X=="function"?X(pe):X;return{chatInputs:{...ee.chatInputs,[t.id]:q}}}),v=g,b=O,[y,B]=p.useState(!1),[j,N]=p.useState(88),[T,U]=p.useState([]),[E,S]=p.useState([]),[C,F]=p.useState(!1),[R,I]=p.useState(!1),Y=p.useRef(null),W=p.useRef(null),te=p.useRef(null),V=p.useRef(null),_=p.useRef(null),P=p.useRef(!0);p.useEffect(()=>{var X;x&&((X=te.current)==null||X.focus())},[x]),p.useEffect(()=>{t.provider&&Z.get("/providers").then(X=>{const ee=(Array.isArray(X)?X:[]).find(pe=>pe.id===t.provider);U(((ee==null?void 0:ee.models)||[]).filter(pe=>!pe.disabled))}).catch(()=>{})},[t.provider]),p.useEffect(()=>{const X=W.current;if(!X)return;function ee(){P.current=X.scrollHeight-X.scrollTop-X.clientHeight<60}return X.addEventListener("scroll",ee),()=>X.removeEventListener("scroll",ee)},[]);const K=p.useCallback(X=>{X.preventDefault();const ee=X.clientY,pe=j,q=me=>N(Math.min(Math.max(56,pe-(me.clientY-ee)),280)),ge=()=>{window.removeEventListener("mousemove",q),window.removeEventListener("mouseup",ge)};window.addEventListener("mousemove",q),window.addEventListener("mouseup",ge)},[j]),H=p.useMemo(()=>{var J;const X=[],ee=new Set;for(let ve=0;ve<A.length;ve++){const Qe=A[ve],Xe=`${Qe.from}:${(J=Qe.text)==null?void 0:J.slice(0,100)}`;X.find(Tt=>{var lt;return Tt.kind==="chat"&&`${Tt.from}:${(lt=Tt.text)==null?void 0:lt.slice(0,100)}`===Xe&&Math.abs(Tt.ts-Qe.timestamp)<5e3})||(X.push({...Qe,kind:"chat",ts:Qe.timestamp,_chatIdx:ve}),ee.add(Qe.text))}const pe=ee,q=f.slice(-30);for(const ve of q)(ve.text||"").trim()&&!pe.has(ve.text)&&X.push({...ve,kind:"activity",ts:ve.timestamp});X.sort((ve,Qe)=>ve.ts-Qe.ts);const ge=[];let me=[];for(const ve of X)ve.kind==="activity"?me.push(ve):(me.length>0&&(ge.push({kind:"activity-group",entries:me}),me=[]),ge.push(ve));return me.length>0&&ge.push({kind:"activity-group",entries:me}),ge},[A,f]);p.useEffect(()=>{P.current&&W.current&&requestAnimationFrame(()=>{W.current&&(W.current.scrollTop=W.current.scrollHeight)})},[H.length,y]);function M(X){return X.type.startsWith("image/")?"image":X.type.startsWith("video/")?"video":"file"}async function L(X){var q,ge,me;const ee=Array.from(X.target.files||((q=X.dataTransfer)==null?void 0:q.files)||[]);if(ee.length===0)return;const pe=[];for(const J of ee){const ve=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,Qe=M(J),Xe={id:ve,name:J.name,size:J.size,type:Qe,status:"reading",file:J};if(Qe==="image"||Qe==="video"){const nt=await new Promise(Tt=>{const lt=new FileReader;lt.onload=()=>Tt(lt.result),lt.onerror=()=>Tt(null),lt.readAsDataURL(J)});Xe.dataUrl=nt}Xe.status="pending",pe.push(Xe)}S(J=>[...J,...pe]),((ge=X.target)==null?void 0:ge.value)!=null&&(X.target.value=""),(me=te.current)==null||me.focus()}function oe(X){S(ee=>ee.filter(pe=>pe.id!==X))}async function z(){if(E.length===0)return[];F(!0);const X=k.getState().addToast,ee=[];for(const pe of E){S(q=>q.map(ge=>ge.id===pe.id?{...ge,status:"uploading"}:ge));try{const q=await new Promise((ge,me)=>{const J=new FileReader;J.onload=()=>ge(J.result.split(",")[1]),J.onerror=me,J.readAsDataURL(pe.file)});await Z.post(`/agents/${t.id}/upload`,{filename:pe.name,content:q}),S(ge=>ge.map(me=>me.id===pe.id?{...me,status:"done"}:me)),ee.push({name:pe.name,size:pe.size,type:pe.type,dataUrl:pe.dataUrl||null})}catch(q){S(ge=>ge.map(me=>me.id===pe.id?{...me,status:"error"}:me)),X("error",`Upload failed: ${pe.name}`,q.message)}}return F(!1),ee}async function ae(){var J;const X=v.trim(),ee=E.length>0;if(!X&&!x&&!ee||y)return;if(X==="/rotate"){const ve=k.getState().rotateAgent;b("");try{await ve(t.id)}catch{}return}B(!0),P.current=!0;let pe=[];ee&&(pe=await z());const q=[];if(X&&q.push(X),x){const ve=x;ve.type==="code"&&ve.filePath?(ve.instruction&&!X&&q.push(ve.instruction),q.push(`File: ${ve.filePath} (lines ${ve.lineStart}-${ve.lineEnd})`),q.push("```\n"+ve.code+"\n```")):ve.code&&q.push("```\n"+ve.code+"\n```")}if(pe.length>0){const ve=pe.map(Qe=>Qe.name).join(", ");q.push(`[Uploaded: ${ve}] — I've uploaded these files to your working directory. Read them and use their content.`)}const ge=q.join(`
1022
1022
 
1023
- `),me=pe.length>0?pe:void 0;b(""),h(),S([]),requestAnimationFrame(()=>{W.current&&(W.current.scrollTop=W.current.scrollHeight)});try{await a(t.id,ge,me)}catch{}B(!1),(J=te.current)==null||J.focus()}function ce(X){X.key==="Enter"&&!X.shiftKey&&(X.preventDefault(),ae())}const re=t.status==="running"||t.status==="starting";return e.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[re&&e.jsx(Ure,{agent:t}),e.jsxs("div",{ref:W,className:"flex-1 overflow-y-auto px-4 py-4 space-y-4",children:[!H.some(X=>X.from==="agent"||X.kind==="activity-group")&&(re?e.jsx(Pre,{agent:t}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center py-8",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-surface-3 flex items-center justify-center mb-3",children:e.jsx(ja,{size:18,className:"text-text-4"})}),e.jsx("p",{className:"text-sm font-semibold text-text-0 font-sans",children:t.name}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Session complete — send a message to continue"})]})),H.map((X,ee)=>{var pe;if(X.kind==="activity-group"){const q=!H.slice(ee+1).some(ge=>ge.kind==="activity-group"||ge.from==="agent");return e.jsx("div",{children:e.jsx(Tre,{entries:X.entries,isLive:re&&q})},`grp-${((pe=X.entries[0])==null?void 0:pe.ts)||ee}`)}return X.from==="user"?e.jsx(Bre,{msg:X},`user-${X._chatIdx}`):X.from==="system"?e.jsx(kre,{msg:X},`sys-${X._chatIdx}`):e.jsx(Cre,{msg:X,agent:t},`agent-${X._chatIdx}`)}),e.jsx(ki,{children:(y||r)&&e.jsx(En.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.25,ease:"easeOut"},children:e.jsx(G4,{agent:t})},"thinking")})]}),e.jsxs("div",{className:"bg-surface-1/50 flex-shrink-0",children:[e.jsx("div",{ref:Y,onMouseDown:K,className:"flex items-center justify-center h-5 cursor-row-resize border-t border-border hover:bg-surface-3/50 transition-colors group",children:e.jsx(xS,{size:12,className:"text-text-4 group-hover:text-text-2 transition-colors"})}),e.jsxs("div",{className:"px-4 pb-3",children:[x&&e.jsx("div",{className:"mb-2",children:e.jsx(Fre,{snippet:x,onRemove:h})}),v&&/\[(?:save|append|update|delete|view|doc|link|read|instruct)\]/i.test(v)&&(()=>{const X=v.match(/\[(save|append|update|delete|view|doc|link|read|instruct)\]/i),ee=v.match(/#[\w/.-]+/g)||[];return e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1 mb-2 rounded-lg bg-accent/5 border border-accent/10",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-accent/15 text-accent font-semibold font-mono text-[10px]",children:X[0]}),ee.map((pe,q)=>e.jsx("span",{className:"text-accent font-medium text-[10px]",children:pe},q)),e.jsx("span",{className:"text-[10px] text-text-4 ml-auto",children:"memory command"})]})})(),e.jsxs("div",{className:G("flex flex-col rounded-lg border bg-surface-0 transition-colors overflow-hidden focus-within:border-text-4/40",R?"border-accent border-dashed bg-accent/[0.03]":"border-border-subtle"),onDragOver:X=>{X.preventDefault(),I(!0)},onDragLeave:()=>I(!1),onDrop:X=>{var ee,pe;X.preventDefault(),I(!1),(pe=(ee=X.dataTransfer)==null?void 0:ee.files)!=null&&pe.length&&L(X)},children:[e.jsx("input",{ref:V,type:"file",multiple:!0,accept:"image/*,video/*,.pdf,.csv,.txt,.md,.json,.yaml,.yml,.docx,.pptx,.xlsx,.xml,.html,.py,.js,.ts,.jsx,.tsx,.go,.rs,.c,.cpp,.h,.java,.rb,.sh,.sql,.log",onChange:L,className:"hidden"}),R&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-accent",children:[e.jsx(CS,{size:16}),e.jsx("span",{className:"text-xs font-sans font-medium",children:"Drop files here"})]}),E.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 px-3 pt-2.5 pb-1",children:E.map(X=>e.jsxs("div",{className:G("relative group flex items-center gap-1.5 rounded-md border overflow-hidden",X.status==="error"?"border-danger/30 bg-danger/5":"border-border-subtle bg-surface-2",X.status==="uploading"&&"opacity-70"),children:[X.type==="image"&&X.dataUrl?e.jsx("img",{src:X.dataUrl,className:"w-12 h-12 object-cover",alt:X.name}):X.type==="video"&&X.dataUrl?e.jsxs("div",{className:"relative w-12 h-12",children:[e.jsx("video",{src:X.dataUrl,className:"w-12 h-12 object-cover",muted:!0}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20",children:e.jsx(dS,{size:12,className:"text-white"})})]}):e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5",children:[e.jsx(Fo,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-sans text-text-1 truncate max-w-[100px]",children:X.name}),e.jsx("span",{className:"text-[10px] font-mono text-text-4",children:q4(X.size)})]}),X.status==="uploading"&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-surface-0/60",children:e.jsx(_e,{size:14,className:"text-accent animate-spin"})}),X.status==="error"&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-danger/10",children:e.jsx(Zs,{size:14,className:"text-danger"})}),e.jsx("button",{onClick:()=>oe(X.id),className:"absolute top-0.5 right-0.5 w-4 h-4 flex items-center justify-center rounded-full bg-surface-0/80 text-text-4 hover:text-danger opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:e.jsx(De,{size:9})})]},X.id))}),e.jsxs("div",{className:"relative px-1",children:[v&&HQ.test(v)&&e.jsx("div",{ref:_,"aria-hidden":!0,className:"absolute inset-y-0 left-1 right-1 px-3 py-2.5 text-[13px] leading-[20px] font-sans pointer-events-none whitespace-pre-wrap break-words overflow-hidden",style:{height:j},children:wre(v)}),e.jsx("textarea",{ref:te,value:v,onChange:X=>b(X.target.value),onKeyDown:ce,onScroll:X=>{_.current&&(_.current.scrollTop=X.target.scrollTop)},placeholder:E.length>0||x?"Add a message (optional)...":re?"Send an instruction...":"Continue this session...",rows:1,className:G("w-full resize-none px-3 py-2.5 text-[13px] leading-[20px]","bg-transparent font-sans relative z-10 whitespace-pre-wrap break-words","placeholder:text-text-4","focus:outline-none",v&&HQ.test(v)?"text-transparent caret-text-0":"text-text-0"),style:{height:j}})]}),e.jsxs("div",{className:"flex items-center gap-1 px-1.5 pb-1.5 pt-0.5",children:[e.jsx("button",{onClick:()=>{var X;return(X=V.current)==null?void 0:X.click()},className:G("w-7 h-7 flex items-center justify-center rounded-md transition-colors cursor-pointer",E.length>0?"text-accent hover:text-accent/80":"text-text-4 hover:text-text-1"),title:"Attach file",children:e.jsx(yS,{size:14})}),E.length>0&&e.jsxs("span",{className:"text-[10px] font-mono text-accent",children:[E.length," file",E.length>1?"s":""]}),T.length>1&&e.jsxs("div",{className:"relative flex items-center",children:[e.jsx("select",{value:t.model||"",onChange:X=>{X.target.value&&Z.patch(`/agents/${t.id}`,{model:X.target.value}).catch(()=>{})},className:"h-7 pl-2 pr-5 text-[11px] font-mono bg-transparent text-text-3 hover:text-text-1 rounded-md cursor-pointer focus:outline-none appearance-none border-none",title:"Switch model",children:T.map(X=>e.jsx("option",{value:X.id,children:X.name||X.id},X.id))}),e.jsx(ft,{size:10,className:"absolute right-1.5 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]}),re&&e.jsxs("span",{className:"relative flex items-center justify-center w-3 h-3 mr-auto",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-accent/30 animate-ping [animation-duration:2s]"}),e.jsx("span",{className:"relative w-2 h-2 rounded-full bg-accent"})]}),e.jsx("div",{className:"flex-1"}),re?e.jsxs("button",{onClick:()=>k.getState().stopAgent(t.id),className:"flex items-center gap-1.5 h-7 px-2 rounded-md text-text-0 hover:text-text-1 hover:bg-surface-3 transition-colors cursor-pointer",children:[e.jsx(wS,{size:13}),e.jsx("span",{className:"text-[11px] font-sans font-medium",children:"Pause"})]}):e.jsx("button",{onClick:ae,disabled:!v.trim()&&!x&&E.length===0||y,className:G("w-7 h-7 flex items-center justify-center rounded-md transition-colors cursor-pointer","disabled:opacity-15 disabled:cursor-not-allowed",v.trim()||x||E.length>0?"text-text-0 hover:text-text-1":"text-text-4"),children:y?e.jsx(_e,{size:15,className:"animate-spin"}):e.jsx(Tb,{size:15})})]})]})]})]})]})}const $re={running:"success",starting:"warning",stopped:"default",crashed:"danger",completed:"accent",killed:"default",rotating:"purple"},Rre={running:"Running",starting:"Starting",stopped:"Stopped",crashed:"Crashed",completed:"Done",killed:"Killed",rotating:"Rotating"};function zg({agentId:t,paneIndex:s}){const n=k(c=>c.agents.find(A=>A.id===t)),a=k(c=>c.fleetSelectAgent),r=k(c=>c.fleetMarkRead);if(p.useEffect(()=>{t&&r(t)},[t,r]),!n)return e.jsx("div",{className:"h-full flex items-center justify-center text-text-4",children:e.jsx("p",{className:"text-xs font-sans",children:"Agent not found"})});const l=Math.round((n.contextUsage||0)*100);return e.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[e.jsxs("div",{className:"h-10 bg-surface-1 border-b border-border px-3 flex items-center gap-2 flex-shrink-0",children:[e.jsx("span",{className:"text-sm font-medium text-text-0 font-sans truncate",children:n.name}),e.jsx(Te,{variant:"default",children:n.role}),n.provider&&e.jsxs("span",{className:"text-xs text-text-3 font-mono truncate",children:[n.provider,n.model?`:${n.model}`:""]}),e.jsx(Te,{variant:$re[n.status]||"default",dot:n.status==="running"?"pulse":void 0,children:Rre[n.status]||n.status}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-xs text-text-3 font-mono",children:vt(n.tokensUsed)}),e.jsxs("span",{className:G("text-xs font-mono",l>=75?"text-danger":l>=50?"text-warning":"text-text-3"),children:[l,"%"]}),e.jsx("button",{onClick:()=>a(null,s),className:"p-1 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-3 transition-colors cursor-pointer",title:"Close pane",children:e.jsx(De,{size:14})})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(W4,{agent:n})})]})}function Mre(){const t=k(v=>v.fleetSelectedAgents),s=k(v=>v.fleetSplitMode),n=k(v=>v.fleetSelectAgent),[a,r]=p.useState(null),l=p.useRef(!1),c=p.useRef(null),A=p.useRef(null),f=p.useRef(null),x=p.useCallback(v=>{var j;v.preventDefault(),l.current=!0;const b=(j=c.current)==null?void 0:j.parentElement;if(!b)return;function y(N){if(!l.current||!b||!A.current||!f.current)return;const T=b.getBoundingClientRect(),U=(N.clientX-T.left)/T.width*100,E=Math.max(25,Math.min(75,U));A.current.style.flex=`0 0 ${E}%`,f.current.style.flex=`0 0 ${100-E}%`}function B(){l.current=!1,document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",B)}document.addEventListener("mousemove",y),document.addEventListener("mouseup",B)},[]);function h(v,b){v.dataTransfer.types.includes("application/x-fleet-agent")&&(v.preventDefault(),v.dataTransfer.dropEffect="link",r(b))}function g(v,b){v.preventDefault(),r(null);const y=v.dataTransfer.getData("application/x-fleet-agent");y&&n(y,b)}function O(){r(null)}return!t[0]&&!t[1]?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 text-text-3",onDragOver:v=>h(v,"left"),onDragLeave:O,onDrop:v=>g(v,0),children:[e.jsx(OS,{size:32,strokeWidth:1,className:"text-text-4"}),e.jsx("p",{className:"text-sm font-sans",children:"Select an agent or drag one here"}),e.jsx("p",{className:"text-xs font-sans text-text-4",children:"Cmd+Click or drag to open side-by-side"})]}):!s||!t[1]?e.jsxs("div",{className:"flex-1 flex min-w-0 min-h-0",children:[e.jsx("div",{className:"flex-1 min-w-0 min-h-0",children:e.jsx(zg,{agentId:t[0],paneIndex:0})}),e.jsx("div",{className:`w-1 flex-shrink-0 transition-all ${a==="right"?"w-1 bg-accent/40":""}`,onDragOver:v=>h(v,"right"),onDragLeave:O,onDrop:v=>g(v,1)}),a==="right"&&e.jsx("div",{className:"w-48 flex-shrink-0 flex items-center justify-center border-2 border-dashed border-accent/30 bg-accent/5 rounded-lg m-1 transition-all",onDragOver:v=>h(v,"right"),onDragLeave:O,onDrop:v=>g(v,1),children:e.jsx("p",{className:"text-xs text-accent font-sans",children:"Drop to open"})})]}):e.jsxs("div",{className:"flex-1 flex min-w-0 min-h-0",children:[e.jsx("div",{ref:A,className:`min-w-0 min-h-0 ${a==="left"?"ring-2 ring-inset ring-accent/30":""}`,style:{flex:"0 0 50%"},onDragOver:v=>h(v,"left"),onDragLeave:O,onDrop:v=>g(v,0),children:e.jsx(zg,{agentId:t[0],paneIndex:0})}),e.jsx("div",{ref:c,className:"w-1 bg-border hover:bg-accent/30 cursor-col-resize transition-colors flex-shrink-0",onMouseDown:x}),e.jsx("div",{ref:f,className:`min-w-0 min-h-0 ${a==="right"?"ring-2 ring-inset ring-accent/30":""}`,style:{flex:"0 0 calc(50% - 4px)"},onDragOver:v=>h(v,"right"),onDragLeave:O,onDrop:v=>g(v,1),children:e.jsx(zg,{agentId:t[1],paneIndex:1})})]})}function Ire(){const t=k(s=>s.fleetSidebarWidth);return e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsx(Ore,{width:t}),e.jsx(Mre,{})]})}const _re={code:"Code",general:"General"},zre={light:"text-success",medium:"text-accent",heavy:"text-warning"};function Lre(t){return t<1?`${Math.round(t*1024)} MB`:`${t} GB`}function Y4({hardware:t}){if(!t)return null;const{totalRamGb:s,gpu:n,isAppleSilicon:a}=t;return e.jsxs("div",{className:"flex items-center gap-3 bg-surface-0 rounded-lg border border-border-subtle px-3 py-2.5",children:[e.jsx(ld,{size:14,className:"text-text-3 flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs font-sans",children:[e.jsxs("span",{className:"text-text-0 font-semibold",children:[s," GB RAM"]}),n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{className:"text-text-2",children:n.name})]}),a&&e.jsx(Te,{variant:"accent",className:"text-2xs",children:"Unified Memory"})]})})]})}function Dre({onRecheck:t}){const[s,n]=p.useState(null),[a,r]=p.useState(!1),[l,c]=p.useState(!1),[A,f]=p.useState(!1),x=k(U=>U.addToast);p.useEffect(()=>{Z.post("/providers/ollama/check").then(n).catch(()=>{})},[]);async function h(){r(!0);try{const U=await Z.post("/providers/ollama/check");n(U),U.installed&&U.serverRunning?(x("success","Ollama is ready!"),t()):U.installed?x("info","Ollama installed — server needs to start"):x("info","Ollama not found — install and try again")}catch{}r(!1)}async function g(){c(!0);try{if((await Z.post("/providers/ollama/serve")).ok){x("success","Ollama server started!");let E=!1;for(let S=0;S<5;S++){await new Promise(F=>setTimeout(F,2e3));const C=await Z.post("/providers/ollama/check");if(n(C),C.serverRunning){E=!0;break}}E&&t()}}catch(U){x("error","Could not start server",U.message)}c(!1)}function O(U){navigator.clipboard.writeText(U),f(!0),setTimeout(()=>f(!1),2e3)}if(!s)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{hardware:v,install:b,requirements:y,installed:B,serverRunning:j}=s,N=v.totalRamGb>=y.minRAM,T=v.recommended;return e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsx(Y4,{hardware:v}),N?e.jsxs("div",{className:"flex items-start gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2.5",children:[e.jsx(Ye,{size:14,className:"text-success flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans",children:[e.jsx("span",{className:"text-success font-semibold",children:"Your system is ready."}),e.jsx("span",{className:"text-text-2 ml-1",children:T.code?`Recommended: ${T.code}`:`${v.totalRamGb} GB RAM available`})]})]}):e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Zs,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsxs("span",{className:"text-warning font-semibold",children:[v.totalRamGb," GB RAM detected."]})," ","Minimum ",y.minRAM," GB needed. Smallest models may still work."]})]}),B&&!j&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Zs,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama installed but server not running."})," ","The server needs to be running to pull and use models."]})]}),e.jsxs(Oe,{variant:"primary",size:"md",onClick:g,disabled:l,className:"w-full gap-1.5",children:[e.jsx(Jt,{size:12}),l?"Starting...":"Start Ollama Server"]})]}),!B&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold text-text-1 font-sans",children:"Install Ollama"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 bg-surface-0 border border-border-subtle rounded-md px-3 py-2 text-xs font-mono text-text-1 truncate",children:b.command}),e.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>O(b.command),className:"h-8 px-2.5 gap-1 flex-shrink-0",children:[A?e.jsx(Ye,{size:12}):e.jsx(ya,{size:12}),A?"Copied":"Copy"]})]}),b.alt&&e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:b.alt})]}),e.jsxs(Oe,{variant:"secondary",size:"md",onClick:h,disabled:a,className:"w-full gap-1.5",children:[e.jsx(Is,{size:12,className:a?"animate-spin":""}),a?"Checking...":B?"Check again":"I installed it — check again"]})]})}function Hre({model:t,isInstalled:s,isRecommended:n,canRun:a,onPull:r,onDelete:l,pulling:c}){const A=c===t.id;return e.jsxs("div",{className:G("flex items-center gap-2 px-3 py-2 border-t border-border-subtle transition-colors",!a&&"opacity-40"),children:[s?e.jsx(Ye,{size:12,className:"text-success flex-shrink-0"}):e.jsx("div",{className:"w-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 truncate",children:t.name}),n&&e.jsx(Eb,{size:10,className:"text-warning flex-shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:G("text-2xs font-semibold font-sans",zre[t.tier]),children:t.tier}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:Lre(t.sizeGb)}),e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["· ",t.ramGb," GB RAM"]})]})]}),s?e.jsx("button",{onClick:()=>l(t.id),className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Remove model",children:e.jsx(Xt,{size:12})}):a?e.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>r(t.id),disabled:!!c,className:"h-7 px-2 text-2xs gap-1",children:A?e.jsxs(e.Fragment,{children:[e.jsx(Is,{size:10,className:"animate-spin"})," Pulling..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Gs,{size:10})," Pull"]})}):e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["Needs ",t.ramGb," GB"]})]})}function Xre({onStopped:t}){const[s,n]=p.useState(null),a=k(c=>c.addToast);async function r(){n("stopping");try{(await Z.post("/providers/ollama/stop")).ok?(a("info","Ollama server stopped"),t&&t()):a("error","Could not stop server")}catch(c){a("error","Stop failed",c.message)}n(null)}async function l(){n("restarting");try{(await Z.post("/providers/ollama/restart")).ok?a("success","Ollama server restarted"):a("error","Restart failed")}catch(c){a("error","Restart failed",c.message)}n(null)}return e.jsxs("div",{className:"flex items-center gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-success"}),e.jsx("span",{className:"absolute inset-[-2px] rounded-full bg-success opacity-20 animate-pulse"})]}),e.jsx("span",{className:"text-xs font-sans text-success font-semibold",children:"Server Running"}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:":11434"}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:l,disabled:!!s,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-accent cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(Is,{size:10,className:s==="restarting"?"animate-spin":""}),s==="restarting"?"Restarting...":"Restart"]}),e.jsxs("button",{onClick:r,disabled:!!s,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-danger cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(Zs,{size:10}),s==="stopping"?"Stopping...":"Stop"]})]})}function Zre({onModelChange:t}){var F,R;const[s,n]=p.useState(null),[a,r]=p.useState(null),[l,c]=p.useState("code"),[A,f]=p.useState(!1),[x,h]=p.useState(!1),g=k(I=>I.addToast),O=p.useRef(!1);function v(){Z.get("/providers/ollama/models").then(I=>{var Y;n(I),!O.current&&((Y=I.installed)==null?void 0:Y.length)===0&&(O.current=!0,setTimeout(v,2e3))}).catch(()=>{})}p.useEffect(()=>{v()},[]);async function b(I){r(I);try{await Z.post("/providers/ollama/pull",{model:I}),g("success",`Pulled ${I}`),v(),t&&t()}catch(Y){g("error",`Pull failed: ${Y.message}`)}r(null)}async function y(I){try{await Z.delete(`/providers/ollama/models/${encodeURIComponent(I)}`),g("info",`Removed ${I}`),v(),t&&t()}catch(Y){g("error",`Delete failed: ${Y.message}`)}}if(!s)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{installed:B,catalog:j,hardware:N}=s,T=new Set(B.map(I=>I.id)),U=N.totalRamGb,E=[(F=N.recommended)==null?void 0:F.code,(R=N.recommended)==null?void 0:R.general].filter(Boolean),S=j.filter(I=>I.category===l),C=A?S:S.filter(I=>I.ramGb<=U);return x?e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Zs,{size:14,className:"text-warning flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama server stopped."})," ","Start it again to pull and use models."]})]}),e.jsxs(Oe,{variant:"primary",size:"md",onClick:async()=>{try{(await Z.post("/providers/ollama/serve")).ok&&(g("success","Ollama server started!"),h(!1),O.current=!1,setTimeout(v,2e3))}catch(I){g("error","Could not start server",I.message)}},className:"w-full gap-1.5",children:[e.jsx(Jt,{size:12}),"Start Ollama Server"]})]}):e.jsxs("div",{className:"space-y-2 p-3",children:[e.jsx(Xre,{onStopped:()=>h(!0)}),e.jsx(Y4,{hardware:N}),B.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-sans text-text-2",children:[e.jsx(id,{size:12,className:"text-text-3"}),e.jsx("span",{className:"font-semibold",children:B.length})," model",B.length!==1?"s":""," installed"]}),e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:Object.entries(_re).map(([I,Y])=>e.jsx("button",{onClick:()=>c(I),className:G("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",l===I?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:Y},I))}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[C.map(I=>e.jsx(Hre,{model:I,isInstalled:T.has(I.id),isRecommended:E.includes(I.id),canRun:I.ramGb<=U,onPull:b,onDelete:y,pulling:a},I.id)),C.length===0&&e.jsxs("div",{className:"px-3 py-4 text-center text-xs text-text-4 font-sans",children:["No ",l," models available for your hardware"]})]}),!A&&S.length>C.length&&e.jsxs("button",{onClick:()=>f(!0),className:"flex items-center gap-1 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(ft,{size:10}),"Show ",S.length-C.length," more (exceed your RAM)"]})]})}function Gre({isInstalled:t,onModelChange:s}){const[n,a]=p.useState(!1),[r,l]=p.useState(!1);return p.useEffect(()=>{t?Z.post("/providers/ollama/check").then(c=>{a(c.installed&&c.serverRunning),l(!0)}).catch(()=>l(!0)):l(!0)},[t]),r?n?e.jsx(Zre,{onModelChange:s}):e.jsx(Dre,{onRecheck:()=>{a(!0),s&&s()}}):e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Checking Ollama..."})}function Qf({options:t,value:s,onChange:n}){return e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:t.map(a=>e.jsx("button",{onClick:()=>n(a.value),className:G("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",s===a.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:a.label},a.value))})}function qn({label:t,icon:s,children:n,description:a}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs font-semibold text-text-1 font-sans",children:[s&&e.jsx(s,{size:13,className:"text-text-3"}),t]}),a&&e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:a})]}),n]})}function Vre({agent:t}){const s=k(b=>b.killAgent),n=k(b=>b.rotateAgent),a=k(b=>b.spawnAgent),r=k(b=>b.closeDetail),l=k(b=>b.addToast),[c,A]=p.useState(null),[f,x]=p.useState(!1),h=t.status==="running"||t.status==="starting";async function g(){A("rotate");try{await n(t.id)}catch{}A(null)}async function O(){if(!f){x(!0),setTimeout(()=>x(!1),3e3);return}A("kill");try{await s(t.id,!h),r()}catch{}A(null),x(!1)}async function v(){A("clone");try{await a({role:t.role,provider:t.provider,model:t.model,name:`${t.name}-clone`,scope:t.scope,workingDir:t.workingDir}),l("success",`Cloned ${t.name}`)}catch{}A(null)}return h?e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs(Oe,{variant:"primary",size:"md",onClick:g,disabled:c==="rotate",className:"gap-1.5",children:[e.jsx(cd,{size:12,className:c==="rotate"?"animate-spin":""}),"Rotate"]}),e.jsxs(Oe,{variant:"info",size:"md",onClick:v,disabled:!!c,className:"gap-1.5",children:[e.jsx(ya,{size:12})," Clone"]}),e.jsxs(Oe,{variant:"danger",size:"md",onClick:O,disabled:c==="kill",className:"gap-1.5",children:[e.jsx(Ub,{size:12}),f?"Confirm":"Kill"]})]})}):e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs(Oe,{variant:"info",size:"md",onClick:v,disabled:!!c,className:"gap-1.5",children:[e.jsx(ya,{size:12})," Clone"]}),e.jsxs(Oe,{variant:"danger",size:"md",onClick:O,disabled:c==="kill",className:"gap-1.5",children:[e.jsx(Xt,{size:12}),f?"Confirm":"Remove"]})]})}function Kre({agent:t}){var me;const s=k(J=>J.addToast),n=k(J=>J.remoteHomedir),[a,r]=p.useState([]),[l,c]=p.useState(t.model||""),[A,f]=p.useState(""),[x,h]=p.useState(t.effort||"default"),[g,O]=p.useState(!1),[v,b]=p.useState(""),[y,B]=p.useState(null),[j,N]=p.useState(!1),[T,U]=p.useState(null),[E,S]=p.useState(t.routingMode||"auto"),[C,F]=p.useState([]),[R,I]=p.useState(""),[Y,W]=p.useState(!1),[te,V]=p.useState([]),[_,P]=p.useState(!1),[K,H]=p.useState([]),[M,L]=p.useState(null),oe=t.status==="running"||t.status==="starting";p.useEffect(()=>{z(),Z.get("/integrations/installed").then(ve=>H(Array.isArray(ve)?ve:[])).catch(()=>{}),Z.get("/repos/imported").then(ve=>F((Array.isArray(ve)?ve:[]).filter(Qe=>Qe.status==="active"))).catch(()=>{}),t.provider==="claude-code"&&Z.get("/providers/claude-code/auth").then(ve=>L(ve)).catch(()=>L(null));function J(){z()}return window.addEventListener("groove:providers-changed",J),()=>window.removeEventListener("groove:providers-changed",J)},[]);function z(){Z.get("/providers").then(J=>r(Array.isArray(J)?J:[])).catch(()=>{})}p.useEffect(()=>{c(t.model||""),Z.get(`/agents/${t.id}/routing/recommend`).then(J=>{S((J==null?void 0:J.mode)||"fixed")}).catch(()=>{})},[t.id,t.model]),p.useEffect(()=>{W(!1),t.personality?Z.get(`/personalities/${t.name}`).then(J=>{I((J==null?void 0:J.content)||""),W(!0)}).catch(()=>{I(""),W(!0)}):(I(""),W(!0)),Z.get("/personalities").then(J=>{V(Array.isArray(J)?J:J.personalities||[])}).catch(()=>{})},[t.id,t.name]);const ae=a.find(J=>J.id===t.provider);async function ce(J,ve){c(ve);try{const Qe={model:ve};J&&J!==t.provider&&(Qe.provider=J),await Z.patch(`/agents/${t.id}`,Qe),s("success",`Model → ${ve}${Qe.provider?` (${J})`:""}`)}catch(Qe){s("error","Model swap failed",Qe.message)}}async function re(J){try{await Z.patch(`/agents/${t.id}`,{workingDir:J}),s("success",`Working dir → ${J.split("/").pop()||J}`)}catch(ve){s("error","Update failed",ve.message)}}async function X(J){h(J);try{await Z.patch(`/agents/${t.id}`,{effort:J}),s("success",`Effort → ${J}`)}catch(ve){s("error","Update failed",ve.message)}}async function ee(J){if(!J.trim())return;const ve=[...t.scope||[],J.trim()];try{await Z.patch(`/agents/${t.id}`,{scope:ve}),f("")}catch(Qe){s("error","Scope update failed",Qe.message)}}async function pe(J){const ve=(t.scope||[]).filter((Qe,Xe)=>Xe!==J);try{await Z.patch(`/agents/${t.id}`,{scope:ve})}catch(Qe){s("error","Scope update failed",Qe.message)}}async function q(J){if(v.trim())try{await Z.post(`/credentials/${J}`,{key:v.trim()}),s("success",`API key set for ${J}`),b(""),B(null),z(),window.dispatchEvent(new CustomEvent("groove:providers-changed"))}catch(ve){s("error","Failed to set key",ve.message)}}const ge=t.spawnedAt||t.createdAt;return e.jsxs("div",{className:"px-5 py-5 space-y-6 overflow-y-auto h-full",children:[e.jsx(qn,{label:"Active Model",icon:wa,children:e.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold font-mono text-text-0",children:t.model||"auto"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:(ae==null?void 0:ae.name)||t.provider})]}),(ae==null?void 0:ae.canHotSwap)&&oe&&e.jsxs(Te,{variant:"accent",className:"text-2xs gap-1",children:[e.jsx(Jt,{size:8})," Hot-swap"]})]}),((me=ae==null?void 0:ae.models)==null?void 0:me.length)>1&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3 pt-3 border-t border-border-subtle",children:ae.models.filter(J=>!J.disabled).map(J=>{const ve=J.id===t.model;return e.jsx("button",{onClick:()=>ce(t.provider,J.id),disabled:!1,className:G("px-2.5 py-1 rounded-md text-xs font-mono transition-all","cursor-pointer",ve?"bg-accent/15 text-accent font-semibold":"bg-surface-4 text-text-2 hover:bg-surface-5 hover:text-text-0"),children:J.name||J.id},J.id)})})]})}),e.jsx(Vre,{agent:t}),e.jsxs(qn,{label:"Providers",icon:Wl,description:"Click a provider to see its models and connection status.",children:[e.jsx("div",{className:"space-y-1.5",children:a.map(J=>{var Tt;const ve=J.id===t.provider,Qe=J.authType==="subscription"?J.installed||((Tt=J.authStatus)==null?void 0:Tt.authenticated):J.authType==="local"?J.installed:J.installed&&J.hasKey,Xe=T===J.id,nt=J.models||[];return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[e.jsxs("button",{onClick:()=>U(Xe?null:J.id),className:"w-full flex items-center gap-2.5 px-3 py-2 cursor-pointer hover:bg-surface-4/50 transition-colors",children:[e.jsx("div",{className:G("w-2 h-2 rounded-full flex-shrink-0",Qe?"bg-success":"bg-text-4")}),e.jsx("span",{className:G("text-xs font-semibold font-sans flex-1 text-left",Qe?"text-text-0":"text-text-3"),children:J.name||J.id}),ve&&e.jsx(Te,{variant:"accent",className:"text-2xs",children:"Active"}),!Qe&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:J.installed?"No key":"Not installed"}),e.jsx(ft,{size:12,className:G("text-text-4 transition-transform",Xe&&"rotate-180")})]}),Xe&&J.authType==="local"&&e.jsx("div",{className:"border-t border-border-subtle",children:e.jsx(Gre,{isInstalled:Qe,onModelChange:z})}),Xe&&J.authType!=="local"&&e.jsxs("div",{className:"border-t border-border-subtle",children:[(!Qe||J.hasKey)&&e.jsx("div",{className:"px-3 py-2 bg-surface-1/50",children:y===J.id?e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("input",{value:v,onChange:lt=>b(lt.target.value),onKeyDown:lt=>lt.key==="Enter"&&q(J.id),type:j?"text":"password",placeholder:`${J.name||J.id} API key...`,className:"w-full h-7 px-2.5 pr-7 text-2xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),e.jsx("button",{onClick:()=>N(!j),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:j?e.jsx(yo,{size:10}):e.jsx(Xs,{size:10})})]}),e.jsx(Oe,{variant:"primary",size:"sm",onClick:()=>q(J.id),disabled:!v.trim(),className:"h-7 px-2 text-2xs",children:"Save"}),e.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{B(null),b("")},className:"h-7 px-2 text-2xs",children:"Cancel"})]}):e.jsxs("button",{onClick:()=>{B(J.id),b(""),N(!1)},className:"flex items-center gap-1.5 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(wi,{size:10}),Qe?"Update API key":"Add API key to enable"]})}),Qe&&nt.filter(lt=>!lt.disabled).length>0&&nt.filter(lt=>!lt.disabled).map(lt=>{const bs=J.id===t.provider&&lt.id===t.model;return e.jsxs("button",{onClick:()=>ce(J.id,lt.id),disabled:!1,className:G("w-full flex items-center gap-2 px-3 py-2 text-left text-xs font-sans transition-colors","border-t border-border-subtle","cursor-pointer hover:bg-surface-4/50",bs?"text-accent":"text-text-2"),children:[bs?e.jsx(Ye,{size:11,className:"text-accent flex-shrink-0"}):e.jsx("div",{className:"w-[11px]"}),e.jsx("span",{className:"font-mono flex-1 truncate",children:lt.name||lt.id}),e.jsx(Te,{variant:bs?"accent":"default",className:"text-2xs",children:lt.tier})]},lt.id)})]})]},J.id)})}),oe&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans mt-1.5",children:[e.jsx(Zs,{size:10}),e.jsx("span",{children:"Model changes apply on next rotation or respawn."})]})]}),t.provider==="claude-code"&&M&&!M.authenticated&&e.jsxs("div",{className:"rounded-lg border border-warning/30 bg-warning/5 px-4 py-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Zs,{size:13,className:"text-warning flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Claude Code is not signed in"})]}),e.jsxs("p",{className:"text-2xs text-text-2 font-sans",children:["Open the terminal and run: ",e.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"claude"})]})]}),t.provider==="claude-code"&&(M==null?void 0:M.authenticated)&&e.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-success flex-shrink-0"}),"Signed in as ",M.email||"Claude user"," (",M.subscriptionType||"subscription",")"]}),e.jsx(qn,{label:"Working Directory",icon:Ks,description:"The root directory this agent operates in.",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 bg-surface-0 rounded-lg px-3 py-2.5 text-sm font-mono text-text-1 border border-border-subtle truncate min-w-0",children:t.workingDir||"Project root"}),e.jsxs(Oe,{variant:"secondary",size:"md",onClick:()=>O(!0),className:"gap-1.5 flex-shrink-0",children:[e.jsx(Nb,{size:14})," Browse"]})]})}),e.jsx(qn,{label:"Permission Mode",icon:Pn,description:"Full Send = no approvals. Agent Approve = Fullstack Manager reviews risky operations.",children:e.jsx(Qf,{options:[{value:"full",label:"Full Send"},{value:"auto",label:"Agent Approve"}],value:t.permission||"full",onChange:async J=>{try{await Z.patch(`/agents/${t.id}`,{permission:J}),s("success",`Permission → ${J==="full"?"Full Send":"Agent Approve"}`)}catch(ve){s("error","Update failed",ve.message)}}})}),e.jsxs(qn,{label:"Model Routing",icon:Vl,description:"How Groove selects models for this agent's tasks.",children:[e.jsx(Qf,{options:[{value:"fixed",label:"Fixed"},{value:"auto",label:"Auto"},{value:"auto-floor",label:"Auto + Floor"}],value:E,onChange:async J=>{S(J);try{await Z.post(`/agents/${t.id}/routing`,{mode:J}),s("success",`Routing → ${J}`)}catch(ve){s("error","Update failed",ve.message)}}}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans mt-1",children:[E==="fixed"&&"Uses the selected model for all tasks.",E==="auto"&&"Groove picks Opus/Sonnet/Haiku based on task complexity.",E==="auto-floor"&&"Auto-routes but never drops below Sonnet."]})]}),e.jsx(qn,{label:"File Scope",icon:Pn,description:"Restrict which files this agent can access. Empty = unrestricted.",children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(t.scope||[]).map((J,ve)=>e.jsxs(Te,{variant:"default",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[J,e.jsx("button",{onClick:()=>pe(ve),className:"hover:text-danger cursor-pointer",children:e.jsx(De,{size:10})})]},ve)),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{value:A,onChange:J=>f(J.target.value),onKeyDown:J=>J.key==="Enter"&&ee(A),placeholder:"e.g. src/**",className:"w-28 h-7 px-2.5 text-xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsx("button",{onClick:()=>ee(A),disabled:!A.trim(),className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:e.jsx(At,{size:12})})]})]})}),e.jsx(qn,{label:"Effort Level",icon:fS,description:"Controls how deep the agent reasons. Higher = more tokens but better results.",children:e.jsx(Qf,{options:[{value:"min",label:"Min"},{value:"low",label:"Low"},{value:"default",label:"Default"},{value:"high",label:"High"},{value:"max",label:"Max"}],value:x,onChange:X})}),e.jsx(qn,{label:"Agent Details",icon:Wl,children:e.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle divide-y divide-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"ID"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.id})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Role"}),e.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:t.role})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Provider"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.provider})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Model"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.model||"auto"})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Status"}),e.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:t.status})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Spawned"}),e.jsx("span",{className:"text-xs text-text-1 font-sans",children:ge?As(ge):"—"})]}),t.sessionId&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Session"}),e.jsxs("span",{className:"text-xs text-text-1 font-mono",children:[t.sessionId.slice(0,16),"..."]})]})]})}),e.jsxs(qn,{label:"Integrations",icon:en,description:"Attach MCP integrations for external services.",children:[e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(t.integrations||[]).map(J=>{const ve=gi[J],Qe=K.find(Xe=>Xe.id===J);return e.jsxs(Te,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[ve?e.jsx("img",{src:ve,alt:"",className:"w-2.5 h-2.5"}):e.jsx(en,{size:9}),(Qe==null?void 0:Qe.name)||J,e.jsx("button",{onClick:async()=>{try{await Z.delete(`/agents/${t.id}/integrations/${J}`),s("success",`Detached ${(Qe==null?void 0:Qe.name)||J}`)}catch(Xe){s("error","Detach failed",Xe.message)}},className:"hover:text-danger cursor-pointer",children:e.jsx(De,{size:10})})]},J)}),K.filter(J=>J.configured!==!1&&!(t.integrations||[]).includes(J.id)).length>0&&e.jsxs("div",{className:"relative group",children:[e.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer transition-colors",children:e.jsx(At,{size:12})}),e.jsx("div",{className:"absolute top-full left-0 mt-1 z-20 hidden group-hover:block bg-surface-2 border border-border-subtle rounded-lg shadow-xl py-1 min-w-[200px]",children:K.filter(J=>J.configured!==!1&&!(t.integrations||[]).includes(J.id)).map(J=>{const ve=gi[J.id];return e.jsxs("button",{onClick:async()=>{try{await Z.post(`/agents/${t.id}/integrations/${J.id}`),s("success",`Attached ${J.name||J.id}`)}catch(Qe){s("error","Attach failed",Qe.message)}},className:"w-full flex items-center gap-2 text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-4 cursor-pointer transition-colors",children:[ve?e.jsx("img",{src:ve,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(en,{size:12,className:"text-text-3 flex-shrink-0"}),J.name||J.id]},J.id)})})]}),(t.integrations||[]).length===0&&K.length===0&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No integrations installed — browse the Marketplace"})]}),(t.integrations||[]).length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"text-2xs font-medium text-text-3 font-sans block mb-1.5",children:"Integration Approvals"}),e.jsx(Qf,{options:[{value:"auto",label:"Auto"},{value:"manual",label:"Manual"}],value:t.integrationApproval||"manual",onChange:async J=>{try{await Z.patch(`/agents/${t.id}`,{integrationApproval:J}),s("success",`Integration approvals → ${J==="auto"?"Auto":"Manual"}`)}catch(ve){s("error","Update failed",ve.message)}}})]})]}),C.length>0&&e.jsx(qn,{label:"Repos",icon:Il,description:"Attach imported repos so this agent knows where they are.",children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(t.repos||[]).map(J=>{const ve=C.find(Qe=>Qe.id===J);return e.jsxs(Te,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[(ve==null?void 0:ve.name)||J,e.jsx("button",{onClick:async()=>{try{await Z.delete(`/agents/${t.id}/repos/${J}`),s("success",`Detached ${(ve==null?void 0:ve.name)||J}`)}catch(Qe){s("error","Detach failed",Qe.message)}},className:"hover:text-danger cursor-pointer",children:e.jsx(De,{size:10})})]},J)}),C.filter(J=>!(t.repos||[]).includes(J.id)).length>0&&e.jsxs("div",{className:"relative group",children:[e.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer transition-colors",children:e.jsx(At,{size:12})}),e.jsx("div",{className:"absolute top-full left-0 mt-1 z-20 hidden group-hover:block bg-surface-2 border border-border-subtle rounded-lg shadow-xl py-1 min-w-[200px]",children:C.filter(J=>!(t.repos||[]).includes(J.id)).map(J=>e.jsxs("button",{onClick:async()=>{try{await Z.post(`/agents/${t.id}/repos/${J.id}`),s("success",`Attached ${J.name||J.id}`)}catch(ve){s("error","Attach failed",ve.message)}},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-4 cursor-pointer transition-colors",children:[e.jsx("div",{className:"font-semibold",children:J.name||J.repo}),e.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:J.clonedTo})]},J.id))})]}),(t.repos||[]).length===0&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No repos attached — import one from the Marketplace"})]})}),e.jsxs(qn,{label:"Personality",icon:$o,description:"Injected into every prompt. Changes apply on next spawn or rotation.",children:[e.jsx("textarea",{value:R,onChange:J=>I(J.target.value),placeholder:Y?"Describe this agent's personality, tone, and behavior...":"Loading...",rows:4,className:"w-full min-h-[4rem] max-h-[10rem] resize-y bg-surface-0 border border-border-subtle rounded-md p-2 text-xs font-mono text-text-1 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Oe,{variant:"primary",size:"sm",disabled:_,onClick:async()=>{P(!0);try{await Z.put(`/personalities/${t.name}`,{content:R}),s("success","Personality saved")}catch(J){s("error","Save failed",J.message)}P(!1)},className:"h-7 px-3 text-2xs gap-1",children:[e.jsx(To,{size:10}),_?"Saving...":"Save"]}),te.length>0&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:"",onChange:J=>{if(!J.target.value)return;const ve=te.find(Qe=>(Qe.name||Qe)===J.target.value);ve&&Z.get(`/personalities/${ve.name||ve}`).then(Qe=>{Qe!=null&&Qe.content&&I(Qe.content)}).catch(()=>{})},className:"h-7 px-2 pr-7 text-2xs rounded-md bg-surface-1 border border-border-subtle text-text-2 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Clone from..."}),te.filter(J=>(J.name||J)!==t.name).map(J=>e.jsx("option",{value:J.name||J,children:J.name||J},J.name||J))]}),e.jsx(ft,{size:10,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]})]})]}),t.prompt&&e.jsx(qn,{label:"Original Prompt",icon:Vl,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3 py-3 text-xs text-text-2 font-sans leading-relaxed max-h-40 overflow-y-auto",children:t.prompt})}),e.jsx(Ac,{open:g,onOpenChange:O,currentPath:t.workingDir||n||"/",homePath:n,onSelect:re})]})}const XQ=[];function qre({data:t,isAlive:s,height:n=48}){const a=p.useRef(null);return p.useEffect(()=>{const r=a.current;if(!r||!t.length)return;const l=r.getContext("2d"),c=window.devicePixelRatio||1,A=r.clientWidth,f=r.clientHeight;r.width=A*c,r.height=f*c,l.scale(c,c),l.clearRect(0,0,A,f);const x=t.map(b=>b.v),h=Math.min(...x),O=Math.max(...x,1)-h||1;l.beginPath(),l.moveTo(0,f),t.forEach((b,y)=>{const B=y/(t.length-1)*A,j=f-(b.v-h)/O*(f-4)-2;l.lineTo(B,j)}),l.lineTo(A,f),l.closePath();const v=l.createLinearGradient(0,0,0,f);if(v.addColorStop(0,s?"rgba(51,175,188,0.15)":"rgba(110,118,129,0.08)"),v.addColorStop(1,"rgba(0,0,0,0)"),l.fillStyle=v,l.fill(),l.beginPath(),l.strokeStyle=s?le.accent:le.text3,l.lineWidth=1.5,t.forEach((b,y)=>{const B=y/(t.length-1)*A,j=f-(b.v-h)/O*(f-4)-2;y===0?l.moveTo(B,j):l.lineTo(B,j)}),l.stroke(),t.length>1&&s){const b=t[t.length-1],y=A-1,B=f-(b.v-h)/O*(f-4)-2;l.beginPath(),l.arc(y,B,5,0,Math.PI*2),l.fillStyle="rgba(51,175,188,0.3)",l.fill(),l.beginPath(),l.arc(y,B,2.5,0,Math.PI*2),l.fillStyle=le.accent,l.fill()}},[t,s]),e.jsx("div",{className:"w-full rounded-lg bg-surface-0 overflow-hidden border border-border-subtle",style:{height:n},children:e.jsx("canvas",{ref:a,className:"w-full h-full"})})}function Nf({icon:t,label:s,value:n,color:a,sub:r}){return e.jsxs("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(t,{size:12,className:a||"text-text-3"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans uppercase tracking-wider",children:s})]}),e.jsx("div",{className:G("text-lg font-bold font-mono tabular-nums",a||"text-text-0"),children:n}),r&&e.jsx("div",{className:"text-2xs text-text-4 font-sans mt-0.5",children:r})]})}function Wre({score:t}){const s=Math.min(Math.max(t,0),100);let n=le.success,a="Healthy";return s<40?(n=le.danger,a="Degraded"):s<70&&(n=le.warning,a="Fair"),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("span",{className:"text-2xs text-text-3 font-sans flex items-center gap-1.5",children:[e.jsx(qR,{size:11}),"Session Health"]}),e.jsxs("span",{className:"text-xs font-bold font-mono",style:{color:n},children:[s,"/100"]})]}),e.jsx("div",{className:"h-2 bg-surface-0 rounded-full overflow-hidden border border-border-subtle",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700",style:{width:`${s}%`,background:n}})}),e.jsx("span",{className:"text-2xs font-sans mt-1 block",style:{color:n},children:a})]})}function Yre(t){const s=(t||"").toLowerCase();return s.includes("edit")||s.includes("writ")?{icon:LA,color:"text-warning"}:s.includes("read")||s.includes("view")?{icon:Xs,color:"text-info"}:s.includes("search")||s.includes("grep")||s.includes("glob")?{icon:cs,color:"text-purple"}:s.includes("bash")||s.includes("command")||s.includes("terminal")?{icon:Nr,color:"text-orange"}:s.includes("error")||s.includes("fail")?{icon:Zs,color:"text-danger"}:s.includes("spawn")||s.includes("start")?{icon:Jt,color:"text-success"}:s.includes("complet")||s.includes("done")?{icon:qf,color:"text-success"}:{icon:va,color:"text-text-4"}}function Jre({agent:t}){const s=k(c=>c.tokenTimeline[t.id])||XQ,n=k(c=>c.activityLog[t.id])||XQ,a=t.status==="running"||t.status==="starting",r=p.useMemo(()=>{if(s.length<2)return 0;const c=s.slice(-10),A=(c[c.length-1].t-c[0].t)/6e4,f=c[c.length-1].v-c[0].v;return A>0?Math.round(f/A):0},[s]),l=p.useMemo(()=>{const c=t.contextUsage||0;let A=100;return c>90?A-=50:c>70?A-=25:c>50&&(A-=10),r>5e3?A-=15:r>3e3&&(A-=8),t.status==="crashed"&&(A=10),t.status==="completed"&&(A=95),Math.max(0,Math.min(100,A))},[t.contextUsage,t.status,r]);return e.jsxs("div",{className:"px-5 py-5 space-y-5 overflow-y-auto h-full",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Token Burn"}),a&&e.jsx("span",{className:"text-2xs text-accent font-mono animate-pulse",children:"LIVE"})]}),e.jsx(qre,{data:s,isAlive:a,height:56})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(Nf,{icon:kR,label:"Burn Rate",value:r>0?`${vt(r)}/m`:"—",color:r>5e3?"text-danger":r>2e3?"text-warning":"text-text-0"}),e.jsx(Nf,{icon:mR,label:"Cost",value:Ro(t.costUsd||0),color:"text-text-0"}),e.jsx(Nf,{icon:cd,label:"Rotations",value:t.rotations||"0",color:"text-text-0"}),e.jsx(Nf,{icon:Jt,label:"Turns",value:t.turns||"0",color:"text-text-0"})]}),e.jsx(Wre,{score:l}),t.prompt&&e.jsxs("div",{children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-1.5",children:"Task"}),e.jsx("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 text-xs text-text-2 font-sans leading-relaxed max-h-28 overflow-y-auto border border-border-subtle",children:t.prompt})]}),n.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-2",children:"Activity"}),e.jsxs("div",{className:"space-y-0 relative",children:[e.jsx("div",{className:"absolute left-[9px] top-2 bottom-2 w-px bg-border-subtle"}),n.slice(-12).reverse().map((c,A)=>{const f=Yre(c.text),x=f.icon;return e.jsxs("div",{className:"flex items-start gap-3 py-1.5 relative",children:[e.jsx("div",{className:G("w-[18px] h-[18px] rounded-full flex items-center justify-center flex-shrink-0 z-10","bg-surface-1 border border-border-subtle"),children:e.jsx(x,{size:9,className:f.color})}),e.jsx("span",{className:"text-2xs text-text-2 font-sans flex-1 line-clamp-1 pt-0.5",children:c.text}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0 pt-0.5",children:As(c.timestamp)})]},A)})]})]})]})}function eoe({agent:t}){const s=k(C=>C.addToast),[n,a]=p.useState([]),[r,l]=p.useState(""),[c,A]=p.useState(null),[f,x]=p.useState(""),[h,g]=p.useState(""),[O,v]=p.useState(!1),[b,y]=p.useState(!1),[B,j]=p.useState("");async function N(){try{const C=await Z.get(`/agents/${t.id}/mdfiles`);a(C.files||[]),l(C.workingDir||"")}catch{}}p.useEffect(()=>{N()},[t.id]);async function T(C){try{const F=await Z.get(`/agents/${t.id}/mdfiles/read?path=${encodeURIComponent(C)}`);x(F.content||""),g(F.content||""),A(C)}catch(F){s("error","Failed to read file",F.message)}}async function U(){if(c){v(!0);try{await Z.put(`/agents/${t.id}/mdfiles/write`,{path:c,content:f}),g(f),s("success",`Saved ${c}`)}catch(C){s("error","Save failed",C.message)}v(!1)}}async function E(){const C=B.trim();if(C)try{await Z.post(`/agents/${t.id}/mdfiles/create`,{name:C}),j(""),y(!1),s("success",`Created ${C}.md`),N()}catch(F){s("error","Create failed",F.message)}}const S=f!==h;return c?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border-subtle",children:[e.jsx("button",{onClick:()=>{A(null),x(""),g("")},className:"p-1 text-text-3 hover:text-text-0 cursor-pointer",children:e.jsx(Pi,{size:14})}),e.jsx(Bn,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs text-text-0 font-sans font-medium flex-1 truncate",children:c}),S&&e.jsx("span",{className:"text-[10px] text-warning font-sans",children:"unsaved"}),e.jsxs("button",{onClick:U,disabled:!S||O,className:G("flex items-center gap-1 px-2.5 py-1 rounded text-2xs font-sans font-medium cursor-pointer transition-colors",S?"bg-accent/15 text-accent hover:bg-accent/25":"text-text-4 opacity-50 cursor-not-allowed"),children:[e.jsx(To,{size:10}),O?"Saving...":"Save"]})]}),e.jsx("textarea",{value:f,onChange:C=>x(C.target.value),className:"flex-1 w-full px-4 py-3 bg-surface-0 text-[12px] font-mono text-text-1 leading-relaxed resize-none focus:outline-none",spellCheck:!1})]}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 border-b border-border-subtle",children:[e.jsx(Bn,{size:12,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:"Markdown Files"}),e.jsx("button",{onClick:()=>y(!0),className:"p-1 text-text-4 hover:text-accent cursor-pointer",title:"Create file",children:e.jsx(At,{size:12})}),e.jsx("button",{onClick:N,className:"p-1 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(Is,{size:11})})]}),r&&e.jsx("div",{className:"px-4 py-1.5 text-[10px] text-text-4 font-mono truncate border-b border-border-subtle/50",children:r}),b&&e.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-b border-border-subtle bg-surface-0",children:[e.jsx(Bn,{size:11,className:"text-accent flex-shrink-0"}),e.jsx("input",{autoFocus:!0,value:B,onChange:C=>j(C.target.value),onKeyDown:C=>{C.key==="Enter"&&E(),C.key==="Escape"&&(y(!1),j(""))},placeholder:"filename",className:"flex-1 bg-transparent text-xs text-text-0 font-mono outline-none placeholder:text-text-4"}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:".md"}),e.jsx("button",{onClick:E,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:e.jsx(To,{size:11})}),e.jsx("button",{onClick:()=>{y(!1),j("")},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(De,{size:11})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center px-4",children:[e.jsx(Bn,{size:20,className:"text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No markdown files found"}),e.jsx("p",{className:"text-[10px] text-text-4 font-sans mt-1",children:"MD files in the agent's working directory will appear here"})]}):e.jsx("div",{className:"py-1",children:n.map(C=>e.jsxs("button",{onClick:()=>T(C.path),className:"w-full flex items-center gap-2.5 px-4 py-2 text-left hover:bg-surface-5 transition-colors cursor-pointer",children:[e.jsx(Bn,{size:13,className:"text-accent flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-xs text-text-0 font-sans block truncate",children:C.name}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:C.path})]}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono flex-shrink-0",children:C.size>1024?`${(C.size/1024).toFixed(1)}K`:`${C.size}B`}),C.source==="personality"&&e.jsx("span",{className:"text-[9px] font-mono text-purple bg-purple/10 px-1 py-px rounded flex-shrink-0",children:"personality"}),C.source==="user"&&e.jsx("span",{className:"text-[9px] font-mono text-accent bg-accent/10 px-1 py-px rounded flex-shrink-0",children:"custom"})]},C.path))})})]})}const toe={running:"success",starting:"warning",stopped:"default",crashed:"danger",completed:"accent",killed:"default",rotating:"purple"},soe={running:"Running",starting:"Starting",stopped:"Stopped",crashed:"Crashed",completed:"Done",killed:"Killed",rotating:"Rotating"},noe=[{id:"command",label:"Chat",icon:ja},{id:"config",label:"Config",icon:Yl},{id:"telemetry",label:"Monitor",icon:Vl},{id:"mdfiles",label:"Files",icon:Bn}];function aoe({agent:t}){const s=k(f=>f.addToast),[n,a]=p.useState(!1),[r,l]=p.useState(t.name),c=p.useRef(null);async function A(){const f=r.trim();if(!f||f===t.name){a(!1);return}try{await Z.patch(`/agents/${t.id}`,{name:f.replace(/\s+/g,"-")}),s("success",`Renamed → ${f}`)}catch(x){s("error","Rename failed",x.message),l(t.name)}a(!1)}return n?e.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-0",children:[e.jsx("input",{ref:c,value:r,onChange:f=>l(f.target.value),onKeyDown:f=>{f.key==="Enter"&&A(),f.key==="Escape"&&(l(t.name),a(!1))},className:"flex-1 min-w-0 h-6 px-1.5 text-sm font-bold bg-surface-0 border border-accent/30 rounded text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent/40",autoFocus:!0}),e.jsx("button",{onClick:A,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:e.jsx(Ye,{size:12})}),e.jsx("button",{onClick:()=>{l(t.name),a(!1)},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(De,{size:12})})]}):e.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0 group",children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans truncate",children:t.name}),e.jsx("button",{onClick:()=>{l(t.name),a(!0)},className:"p-0.5 text-text-4 opacity-0 group-hover:opacity-100 hover:text-text-1 cursor-pointer transition-opacity",children:e.jsx(Cr,{size:10})})]})}function roe(){const t=k(v=>v.detailPanel),s=k(v=>v.agents),n=k(v=>v.activeTeamId);k(v=>v.addToast);const[a,r]=p.useState("command"),l=p.useRef(null),c=(t==null?void 0:t.type)==="agent"?t.agentId:null,A=c?s.find(v=>v.id===c):null;A?l.current=A:l.current&&l.current.id!==c&&(l.current=null);const f=A||l.current,x=(A==null?void 0:A.status)==="running"||(A==null?void 0:A.status)==="starting";if(!f||n&&f.teamId&&f.teamId!==n)return null;const h=Math.round((f.contextUsage||0)*100),g=f.spawnedAt||f.createdAt,O=g?Math.floor((Date.now()-new Date(g).getTime())/1e3):0;return Ra(f.role),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex-shrink-0",children:[e.jsxs("div",{className:"pl-4 pr-10 pt-3 pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(aoe,{agent:f}),e.jsx(Te,{variant:toe[f.status]||"default",dot:x?"pulse":void 0,className:"text-2xs flex-shrink-0",children:soe[f.status]||f.status})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-2xs text-text-3 font-mono",children:[e.jsx("span",{className:"capitalize",children:f.role}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{children:[f.provider,":",f.model||"auto"]}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{children:[vt(f.tokensUsed||0)," tok"]}),h>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{className:G(h>80?"text-danger":h>60?"text-warning":"text-text-3"),children:[h,"% ctx"]})]}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{children:Mo(O)})]})]}),e.jsx("div",{className:"flex items-center px-4 border-b border-border-subtle",children:noe.map(v=>{const b=v.icon,y=a===v.id;return e.jsxs("button",{onClick:()=>r(v.id),className:G("flex items-center gap-1.5 px-3 py-2 text-2xs font-semibold font-sans transition-all cursor-pointer select-none border-b-2 -mb-px",y?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"),children:[e.jsx(b,{size:11}),v.label]},v.id)})})]}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[a==="command"&&e.jsx(W4,{agent:f}),a==="config"&&e.jsx(Kre,{agent:f}),a==="telemetry"&&e.jsx(Jre,{agent:f}),a==="mdfiles"&&e.jsx(eoe,{agent:f})]})]})}const ooe=[{id:"chat",label:"Chat",desc:"Companion, assistant, conversation",icon:$o,tier:"Medium"},{id:"planner",label:"Planner",desc:"Plans the team and tasks",icon:Qi,tier:"Heavy"},{id:"backend",label:"Backend",desc:"APIs, services, databases",icon:Bs,tier:"Medium"},{id:"frontend",label:"Frontend",desc:"UI, components, styling",icon:ld,tier:"Medium"},{id:"fullstack",label:"Fullstack",desc:"End-to-end implementation",icon:xn,tier:"Heavy"},{id:"testing",label:"Testing",desc:"Tests, coverage, QA",icon:Mx,tier:"Medium"},{id:"devops",label:"DevOps",desc:"CI/CD, infra, deployment",icon:vb,tier:"Medium"},{id:"docs",label:"Docs",desc:"Documentation, guides",icon:Bn,tier:"Light"},{id:"security",label:"Security",desc:"Audits, vulnerabilities",icon:Pn,tier:"Medium"},{id:"database",label:"Database",desc:"Schema, migrations, queries",icon:yb,tier:"Medium"},{id:"cmo",label:"CMO",desc:"Marketing, content, growth",icon:Cb,tier:"Medium"},{id:"cfo",label:"CFO",desc:"Finance, metrics, forecasting",icon:iS,tier:"Medium"},{id:"ea",label:"EA",desc:"Executive assistant, scheduling",icon:kS,tier:"Light"},{id:"support",label:"Support",desc:"Customer support, FAQs",icon:hS,tier:"Medium"},{id:"analyst",label:"Analyst",desc:"Data analysis, insights",icon:Px,tier:"Medium"},{id:"creative",label:"Writer",desc:"Copy, articles, proposals",icon:jS,tier:"Heavy",skillHint:!0},{id:"slides",label:"Slides",desc:"Pitch decks, presentations",icon:NS,tier:"Heavy",skillHint:!0},{id:"ambassador",label:"Ambassador",desc:"Bridge to federated server",icon:aa,tier:"Light"}];function ZQ(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"text-accent flex-shrink-0",children:[e.jsx("circle",{cx:"7",cy:"7",r:"6",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1"}),e.jsx("path",{d:"M4.5 7 L6.5 9 L9.5 5.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}function ioe(){var Be;const t=k(se=>se.detailPanel),s=k(se=>se.closeDetail),n=k(se=>se.spawnAgent),a=k(se=>se.fetchProviders),r=k(se=>se.teams),l=k(se=>se.activeTeamId),c=k(se=>se.createTeam),A=(t==null?void 0:t.type)==="spawn",[f,x]=p.useState(""),[h,g]=p.useState(""),[O,v]=p.useState(""),[b,y]=p.useState(""),[B,j]=p.useState(""),[N,T]=p.useState(""),[U,E]=p.useState([]),[S,C]=p.useState([]),[F,R]=p.useState([]),[I,Y]=p.useState(!1),[W,te]=p.useState(""),[V,_]=p.useState("manual"),[P,K]=p.useState([]),[H,M]=p.useState([]),[L,oe]=p.useState(!1),[z,ae]=p.useState(""),[ce,re]=p.useState([]),[X,ee]=p.useState(""),[pe,q]=p.useState(!1),[ge,me]=p.useState(!1),[J,ve]=p.useState(""),[Qe,Xe]=p.useState([]),[nt,Tt]=p.useState(null),[lt,bs]=p.useState([]),[zo,kr]=p.useState(!1),[qs,Lo]=p.useState("new"),[ds,Mi]=p.useState(""),[ca,Do]=p.useState(""),Tr=k(se=>se.federation),Ur=k(se=>se.ollamaRunningModels),es=f||h,Cs=U.find(se=>se.id===b),zs=(Cs==null?void 0:Cs.models)||[],$n=U.filter(se=>se.authType==="api-key"?se.installed&&se.hasKey:se.installed),vs=!!(t!=null&&t.presetProvider||t!=null&&t.presetModel),nn=(t==null?void 0:t.presetTeamId)||null,ht=!nn&&(vs||!l);p.useEffect(()=>{if(A){const se=(t==null?void 0:t.presetProvider)||"",Ne=(t==null?void 0:t.presetModel)||"";a().then(Me=>{const Re=Array.isArray(Me)?Me:Me.providers||[];E(Re);const Rn=Re.filter(ys=>ys.authType==="api-key"?ys.installed&&ys.hasKey:ys.installed);if(Rn.length>0&&!se){const Er=["claude-code","gemini","codex","ollama"].find(xc=>Rn.some(an=>an.id===xc))||Rn[0].id;y(Er)}if(se&&y(se),Ne){const ys=Re.find(an=>an.id===(se||b)),Er=(ys==null?void 0:ys.models)||[];if(Er.find(an=>an.id===Ne))j(Ne);else{const an=Ne.split(":"),Ga=an.length>=3?an.slice(2).join(":"):an[an.length-1],mc=Er.find(Ho=>Ho.id===Ne||Ho.id===`gguf:${Ga}`||Ho.id.endsWith(`:${Ga}`)||Ho.name===Ga);j((mc==null?void 0:mc.id)||Ne)}}}).catch(()=>{}),Z.get("/integrations/installed").then(Me=>{C(Array.isArray(Me)?Me:[])}).catch(()=>{}),Z.get("/repos/imported").then(Me=>{K((Array.isArray(Me)?Me:[]).filter(Re=>Re.status==="active"))}).catch(()=>{}),Z.get("/personalities").then(Me=>{re(Array.isArray(Me)?Me:Me.personalities||[])}).catch(()=>{}),x(""),g(""),v(""),y(se),j(Ne),Lo("new"),Do(""),Mi(Ne?Ne.split(":").pop().replace(/[-_]/g," "):""),T(""),R([]),_("manual"),M([]),ee(""),ve(""),q(!1),Xe([]),Tt(null)}},[A,a]),p.useEffect(()=>{if(!es||!A){Xe([]);return}Z.get(`/roles/integrations?role=${encodeURIComponent(es)}`).then(se=>{const Ne=Array.isArray(se)?se:(se==null?void 0:se.recommendations)||[];Xe(Ne);const Me=Ne.filter(Re=>Re.installed&&Re.configured&&Re.authenticated).map(Re=>Re.id);Me.length>0&&R(Re=>[...new Set([...Re,...Me])])}).catch(()=>Xe([]))},[es,A]),p.useEffect(()=>{if(!A||b!=="ollama"){bs([]);return}Z.get("/providers/ollama/models").then(se=>{bs(se.installed||[])}).catch(()=>bs([])),Z.post("/providers/ollama/check").then(se=>{kr(se.serverRunning)}).catch(()=>kr(!1))},[A,b]);async function de(){me(!0);try{let se;if(nn)se=nn;else if(!ht)se=l;else if(qs==="new"){const Me=ds.trim()||es||"New Team";se=(await c(Me)).id}else qs==="existing"&&ca&&(se=ca);const Ne={role:es,...O&&{name:O.replace(/\s+/g,"-")},...b&&{provider:b},...B&&{model:B},...N&&{prompt:N},...F.length>0&&{integrations:F},...F.length>0&&{integrationApproval:V},...H.length>0&&{repos:H},...X&&{personality:X},...es==="ambassador"&&J&&{peerId:J},...se&&{teamId:se}};await n(Ne),s()}catch{}me(!1)}async function Ze(){var se;if(es){try{const Ne=await Z.post("/agents/preflight",{role:es,integrations:F});if(((se=Ne==null?void 0:Ne.issues)==null?void 0:se.length)>0){Tt(Ne.issues);return}}catch{}de()}}return e.jsxs(T4,{open:A,onOpenChange:se=>{se||s()},children:[e.jsx(U4,{title:"Spawn Agent",width:480,onClose:()=>s(),children:e.jsxs("div",{className:"flex flex-col h-[calc(100%-57px)]",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-3",children:"Choose Role"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:ooe.map(se=>{const Ne=Ra(se.id),Me=f===se.id;return e.jsxs("button",{onClick:()=>{x(se.id),g("")},className:G("flex items-center gap-2.5 p-3 rounded-md border text-left transition-all cursor-pointer",Me?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-2"),children:[e.jsx("div",{className:"w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0",style:{background:Ne.bg},children:e.jsx(se.icon,{size:16,style:{color:Ne.text}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:se.label}),se.skillHint&&e.jsx("span",{className:"text-2xs font-mono text-warning/70 bg-warning/8 px-1 py-px rounded",children:"skill"})]}),e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:se.desc})]})]},se.id)})}),e.jsx("div",{className:"mt-3",children:e.jsx(Yt,{placeholder:"or type a custom role (e.g. chat-agent)...",value:h,onChange:se=>{g(se.target.value.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,50)),x("")},className:"text-xs"})})]}),es&&Qe.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Recommended Integrations"}),e.jsx("div",{className:"space-y-1.5",children:Qe.map(se=>{const Ne=gi[se.id];return se.installed&&se.configured&&se.authenticated?e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-success/5 border border-success/20",children:[e.jsx(Ye,{size:13,className:"text-success flex-shrink-0"}),Ne?e.jsx("img",{src:Ne,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(en,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:se.name||se.id}),e.jsx(Te,{variant:"success",className:"text-2xs ml-auto",children:"Ready"})]},se.id):se.installed?e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-warning/5 border border-warning/20",children:[e.jsx(sa,{size:13,className:"text-warning flex-shrink-0"}),Ne?e.jsx("img",{src:Ne,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(en,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:se.name||se.id}),e.jsx(Oe,{variant:"ghost",size:"sm",className:"ml-auto text-2xs text-warning h-6 px-2",onClick:()=>{s(),k.getState().setActiveView("marketplace")},children:"Configure"})]},se.id):e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-surface-1 border border-border-subtle",children:[Ne?e.jsx("img",{src:Ne,alt:"",className:"w-3.5 h-3.5 flex-shrink-0 opacity-40"}):e.jsx(en,{size:12,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-text-3 font-sans",children:se.name||se.id}),e.jsx("button",{onClick:()=>{s(),k.getState().setActiveView("marketplace")},className:"ml-auto text-2xs text-accent hover:underline font-sans cursor-pointer",children:"Install in Marketplace"})]},se.id)})})]}),es==="ambassador"&&(()=>{const se=Tr.whitelist.filter(Ne=>typeof Ne=="object"&&(Ne.status==="mutual"||Ne.status==="connected"));return se.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-4 text-center",children:[e.jsx(aa,{size:18,className:"text-text-4 mx-auto mb-1.5"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans mb-2",children:"No federated servers connected. Add one in the Federation view."}),e.jsx(Oe,{variant:"ghost",size:"sm",className:"text-2xs text-accent",onClick:()=>{s(),k.getState().setActiveView("federation")},children:"Go to Federation"})]}):e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Target Server"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:J,onChange:Ne=>ve(Ne.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Select a server..."}),se.map(Ne=>e.jsx("option",{value:Ne.ip,children:Ne.name||`${Ne.ip}:${Ne.port||31415}`},Ne.ip))]}),e.jsx(ft,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})})(),es&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block",children:"Configuration"}),e.jsx(Yt,{label:"Name (optional)",value:O,onChange:se=>v(se.target.value),placeholder:`${es}-1`}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Provider"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:b,onChange:se=>{y(se.target.value),j("")},className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Auto"}),U.map(se=>e.jsxs("option",{value:se.id,disabled:se.authType==="api-key"?!(se.installed&&se.hasKey):!se.installed,children:[se.name,se.installed?se.authType==="api-key"&&!se.hasKey?" (No API key)":"":" (Not installed)"]},se.id))]}),e.jsx(ft,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Model"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:B,onChange:se=>j(se.target.value),disabled:!b,className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent disabled:opacity-40",children:[e.jsx("option",{value:"",children:"Auto"}),b==="ollama"&&lt.length>0?e.jsxs(e.Fragment,{children:[e.jsx("optgroup",{label:"Installed Models",children:lt.map(se=>{const Ne=Ur.some(Me=>Me.name===se.id);return e.jsxs("option",{value:se.id,children:[se.name||se.id," (",se.size,")",Ne?" ● Running":""]},se.id)})}),e.jsx("optgroup",{label:"Catalog",children:zs.filter(se=>!lt.some(Ne=>Ne.id===se.id)).map(se=>e.jsxs("option",{value:se.id,children:[se.name," (not installed)"]},se.id))})]}):b==="local"?(()=>{const se=zs.filter(Re=>Re.source==="runtime"),Ne=zs.filter(Re=>Re.source==="gguf"),Me=zs.filter(Re=>Re.source==="ollama"||!Re.source);return e.jsxs(e.Fragment,{children:[se.length>0&&e.jsx("optgroup",{label:"Lab Runtimes",children:se.map(Re=>e.jsxs("option",{value:Re.id,children:[Re.name,Re.runtimeType?` (${Re.runtimeType})`:""]},Re.id))}),Ne.length>0&&e.jsx("optgroup",{label:"GGUF Models",children:Ne.map(Re=>e.jsxs("option",{value:Re.id,children:[Re.name,Re.hasRuntime?"":" (no runtime)"]},Re.id))}),Me.length>0&&e.jsx("optgroup",{label:"Ollama",children:Me.map(Re=>e.jsx("option",{value:Re.id,children:Re.name},Re.id))})]})})():zs.map(se=>e.jsx("option",{value:se.id,children:se.name},se.id))]}),e.jsx(ft,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})]}),b&&Cs&&e.jsx("div",{className:"text-2xs text-text-3 font-sans flex items-center gap-2 flex-wrap",children:Cs.authType==="local"?e.jsx(Te,{variant:"success",children:"Local"}):Cs.authType==="subscription"?e.jsx(Te,{variant:"accent",children:"Subscription"}):Cs.hasKey?e.jsx(Te,{variant:"success",children:"API key set"}):e.jsxs(Te,{variant:"warning",children:["No API key — set with: groove set-key ",b," YOUR_KEY"]})}),b==="ollama"&&B&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap text-2xs font-sans",children:[Ur.some(se=>se.name===B)?e.jsxs(Te,{variant:"success",className:"text-2xs gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-success"}),"Ready — running in memory"]}):lt.some(se=>se.id===B)?e.jsx(Te,{variant:"subtle",className:"text-2xs",children:"Will auto-start when agent spawns"}):e.jsx(Te,{variant:"warning",className:"text-2xs",children:"Not installed — will pull first"}),!zo&&e.jsx("span",{className:"text-warning",children:"Server not running — will auto-start"})]}),ht&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Team"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("button",{onClick:()=>Lo("new"),className:G("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",qs==="new"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(At,{size:13,className:qs==="new"?"text-accent":"text-text-3"}),e.jsx("div",{children:e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"New Team"})})]}),e.jsxs("button",{onClick:()=>Lo("existing"),className:G("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",qs==="existing"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(Fn,{size:13,className:qs==="existing"?"text-accent":"text-text-3"}),e.jsx("div",{children:e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Existing"})})]})]}),qs==="new"&&e.jsx(Yt,{value:ds,onChange:se=>Mi(se.target.value),placeholder:"Team name...",className:"text-xs"}),qs==="existing"&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:ca,onChange:se=>Do(se.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Select team..."}),r.filter(se=>!se.archived).map(se=>e.jsx("option",{value:se.id,children:se.name},se.id))]}),e.jsx(ft,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integrations"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[F.map(se=>{const Ne=S.find(Re=>Re.id===se),Me=gi[se];return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded bg-accent/12 text-accent border border-accent/25 text-2xs font-sans",children:[Me?e.jsx("img",{src:Me,alt:"",className:"w-2.5 h-2.5"}):e.jsx(en,{size:9}),(Ne==null?void 0:Ne.name)||se,e.jsx("button",{onClick:()=>R(Re=>Re.filter(Rn=>Rn!==se)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:e.jsx(De,{size:9})})]},se)}),e.jsxs("button",{onClick:()=>{Y(!0),te("")},className:G("inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-2xs font-sans transition-colors cursor-pointer","bg-surface-0 text-text-2 border border-border-subtle hover:border-border hover:text-text-0"),children:[e.jsx(en,{size:10}),F.length>0?"Add integration":"Attach integration"]})]})]}),e.jsx(Dt,{open:I,onOpenChange:Y,children:e.jsx(Ht,{title:"Select Integration",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(cs,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:W,onChange:se=>te(se.target.value),placeholder:"Search integrations...",autoFocus:!0,className:"w-full h-8 pl-8 pr-3 text-xs rounded-md bg-surface-0 border border-border text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsxs("div",{className:"max-h-64 overflow-y-auto space-y-1",children:[S.filter(se=>{if(!W)return!0;const Ne=W.toLowerCase();return(se.name||se.id).toLowerCase().includes(Ne)||(se.description||"").toLowerCase().includes(Ne)}).map(se=>{const Ne=F.includes(se.id),Me=se.configured!==!1,Re=gi[se.id],Rn=es&&Array.isArray(se.roles)&&se.roles.includes(es);return e.jsxs("button",{onClick:()=>{Me&&R(ys=>Ne?ys.filter(Er=>Er!==se.id):[...ys,se.id])},disabled:!Me,className:G("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors",Me?"cursor-pointer":"opacity-40 cursor-not-allowed",Ne?"bg-accent/10 border border-accent/25":Me?"hover:bg-surface-3 border border-transparent":"border border-transparent"),children:[Re?e.jsx("img",{src:Re,alt:"",className:"w-4 h-4 flex-shrink-0"}):e.jsx(en,{size:12,className:Ne?"text-accent":"text-text-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:se.name||se.id}),!Me&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"(not configured)"}),Me&&Rn&&e.jsx("span",{className:"text-2xs font-mono text-accent/70 bg-accent/8 px-1 py-px rounded",children:"rec"})]}),se.description&&e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:se.description}),!Me&&e.jsx("div",{className:"text-2xs text-text-4 font-sans",children:"Configure in Marketplace"})]}),Ne&&e.jsx(ZQ,{})]},se.id)}),S.length===0&&e.jsx("div",{className:"text-center py-6 text-xs text-text-3 font-sans",children:"No integrations installed. Visit the Marketplace to install integrations."})]})]})})}),F.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integration Approvals"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("button",{onClick:()=>_("manual"),className:G("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",V==="manual"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(Pn,{size:13,className:V==="manual"?"text-accent":"text-text-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Manual"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"You approve each action"})]})]}),e.jsxs("button",{onClick:()=>_("auto"),className:G("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",V==="auto"?"border-warning bg-warning/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(mn,{size:13,className:V==="auto"?"text-warning":"text-text-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Auto"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"Agent acts without asking"})]})]})]})]}),P.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Repos"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[H.map(se=>{const Ne=P.find(Me=>Me.id===se);return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded bg-accent/12 text-accent border border-accent/25 text-2xs font-sans",children:[e.jsx(Il,{size:9}),(Ne==null?void 0:Ne.name)||se,e.jsx("button",{onClick:()=>M(Me=>Me.filter(Re=>Re!==se)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:e.jsx(De,{size:9})})]},se)}),e.jsxs("button",{onClick:()=>{oe(!0),ae("")},className:G("inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-2xs font-sans transition-colors cursor-pointer","bg-surface-0 text-text-2 border border-border-subtle hover:border-border hover:text-text-0"),children:[e.jsx(Il,{size:10}),H.length>0?"Add repo":"Attach repo"]})]})]}),e.jsx(Dt,{open:L,onOpenChange:oe,children:e.jsx(Ht,{title:"Select Repository",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-3 p-4",children:[P.length>1&&e.jsxs("div",{className:"relative",children:[e.jsx(cs,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:z,onChange:se=>ae(se.target.value),placeholder:"Search repos...",autoFocus:!0,className:"w-full h-8 pl-8 pr-3 text-xs rounded-md bg-surface-0 border border-border text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:P.filter(se=>{if(!z)return!0;const Ne=z.toLowerCase();return(se.name||se.repo||se.id).toLowerCase().includes(Ne)}).map(se=>{const Ne=H.includes(se.id);return e.jsxs("button",{onClick:()=>{M(Me=>Ne?Me.filter(Re=>Re!==se.id):[...Me,se.id])},className:G("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors cursor-pointer",Ne?"bg-accent/10 border border-accent/25":"hover:bg-surface-3 border border-transparent"),children:[e.jsx(Il,{size:12,className:Ne?"text-accent":"text-text-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:se.name||se.repo}),e.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:se.clonedTo})]}),Ne&&e.jsx(ZQ,{})]},se.id)})})]})})}),(f==="chat"||pe)&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Personality"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:X,onChange:se=>ee(se.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"None (blank)"}),ce.map(se=>e.jsx("option",{value:se.name||se,children:se.name||se},se.name||se))]}),e.jsx(ft,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:"Personality is injected into every prompt for this agent."})]}),f!=="chat"&&!pe&&e.jsx("button",{onClick:()=>q(!0),className:"text-2xs text-text-3 hover:text-accent font-sans transition-colors cursor-pointer",children:"+ Advanced options"})]})]}),e.jsxs("div",{className:"border-t border-border-subtle px-5 py-4 bg-surface-1",children:[$n.length===0&&U.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 px-3 py-2 rounded-md bg-warning/8 border border-warning/20",children:[e.jsx(sa,{size:13,className:"text-warning flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-sans text-text-2",children:"No AI providers installed. Install Claude Code, Gemini CLI, Codex, or Ollama to spawn agents."})]}),es&&$n.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 text-xs text-text-3 font-sans flex-wrap",children:[e.jsx("span",{children:"Spawning"}),e.jsx(Te,{variant:"accent",children:es}),b&&e.jsxs("span",{children:["on ",(Cs==null?void 0:Cs.name)||b]}),O&&e.jsxs("span",{children:["as ",O.replace(/\s+/g,"-")]}),qs==="new"&&e.jsxs("span",{children:["in new team",ds?` "${ds}"`:""]}),qs==="existing"&&ca&&e.jsxs("span",{children:["in ",((Be=r.find(se=>se.id===ca))==null?void 0:Be.name)||"team"]})]}),e.jsx(Oe,{variant:"primary",size:"lg",onClick:Ze,disabled:!es||ge||$n.length===0||qs==="existing"&&!ca,className:"w-full",children:ge?"Spawning...":"Spawn Agent"})]})]})}),e.jsx(Dt,{open:!!nt,onOpenChange:se=>{se||Tt(null)},children:e.jsx(Ht,{title:"Integration Warning",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsx("div",{className:"space-y-2",children:(nt||[]).map((se,Ne)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs text-text-1 font-sans",children:[e.jsx(sa,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsx("span",{children:se.name?`${se.name}: ${se.problem==="not_installed"?"not installed":se.problem==="not_configured"?"not configured":"not authenticated"}`:se.message||String(se)})]},Ne))}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Continue anyway?"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Oe,{variant:"ghost",size:"md",onClick:()=>Tt(null),className:"flex-1",children:"Cancel"}),e.jsx(Oe,{variant:"warning",size:"md",onClick:()=>{Tt(null),de()},className:"flex-1",children:"Spawn Anyway"})]})]})})})]})}function loe(){const t=k(g=>g.journalistStatus),s=k(g=>g.fetchJournalist),n=k(g=>g.triggerJournalistCycle),[a,r]=p.useState(!0),[l,c]=p.useState(!1);p.useEffect(()=>{s().then(()=>r(!1));const g=setInterval(s,1e4);return()=>clearInterval(g)},[s]);async function A(){c(!0);try{await n()}catch{}c(!1)}if(a)return e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx(Jn,{className:"h-6 w-32 rounded"}),e.jsx(Jn,{className:"h-20 rounded-md"}),e.jsx(Jn,{className:"h-20 rounded-md"})]});const f=t||{},x=f.lastSynthesis,h=f.history||[];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"pl-5 pr-10 py-4 border-b border-border-subtle flex items-center gap-2",children:[e.jsx(Wf,{size:16,className:"text-accent"}),e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Journalist"}),e.jsxs(Oe,{variant:"secondary",size:"sm",onClick:A,disabled:l,className:"gap-1.5 text-2xs",children:[e.jsx(Is,{size:11,className:l?"animate-spin":""}),l?"Running...":"Run Synthesis"]})]}),e.jsx(yt,{className:"flex-1",children:e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Vl,{size:10}),e.jsxs("span",{children:[f.cycleCount||0," cycles"]})]}),f.lastCycleTime&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(va,{size:10}),e.jsxs("span",{children:["Last: ",As(f.lastCycleTime)]})]}),e.jsx(Te,{variant:f.cycleCount>0?"success":"default",className:"text-2xs",children:f.cycleCount>0?"Active":"Idle"})]}),(x==null?void 0:x.summary)&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[e.jsx(Bn,{size:12,className:"text-text-3"}),"Latest Summary"]}),e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-sans leading-relaxed",children:x.summary})]}),(x==null?void 0:x.projectMap)&&e.jsx(jx,{title:"Project Map",icon:pM,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-mono leading-relaxed max-h-64 overflow-y-auto whitespace-pre-wrap",children:x.projectMap})}),(x==null?void 0:x.decisions)&&e.jsx(jx,{title:"Decisions Log",icon:Bn,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-mono leading-relaxed max-h-64 overflow-y-auto whitespace-pre-wrap",children:x.decisions})}),h.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[e.jsx(va,{size:12,className:"text-text-3"}),"History (",h.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:h.slice().reverse().slice(0,20).map((g,O)=>e.jsxs("div",{className:"bg-surface-0 rounded-md border border-border-subtle px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xs",children:[e.jsxs(Te,{variant:"default",className:"text-2xs",children:["Cycle ",g.cycle]}),e.jsxs("span",{className:"text-text-4 font-sans",children:[g.agentCount," agent",g.agentCount!==1?"s":""]}),e.jsx("span",{className:"text-text-4 font-sans ml-auto",children:As(g.timestamp)})]}),g.summary&&e.jsx("p",{className:"text-xs text-text-2 font-sans mt-1 leading-relaxed",children:g.summary})]},O))})]}),!x&&h.length===0&&e.jsxs("div",{className:"text-center py-8 text-text-4 font-sans",children:[e.jsx(Wf,{size:28,className:"mx-auto mb-2"}),e.jsx("p",{className:"text-sm",children:"No synthesis data yet"}),e.jsx("p",{className:"text-2xs mt-1",children:"The journalist runs automatically when agents are active, or trigger manually above"})]})]})})]})}const coe=[{cmd:"save",args:"#tag",desc:"Save the message and send it to the agent"},{cmd:"append",args:"#tag",desc:"Add to an existing memory and send to agent"},{cmd:"update",args:"#tag",desc:"Open the editor to modify a memory in place"},{cmd:"delete",args:"#tag",desc:"Remove a memory permanently"},{cmd:"view",args:"#tag",desc:"Read a memory in the viewer"},{cmd:"read",args:"#tag1 #tag2 ...",desc:"Send memory content to the agent — chat stays clean"},{cmd:"doc",args:"#tag",desc:"AI synthesizes the full conversation into a document"},{cmd:"link",args:"#tag path/to/doc",desc:"Link a memory to a NORTHSTAR or external document"},{cmd:"[instruct]",args:"",desc:"Show this command reference"}];function Aoe(){var j;const t=k(N=>N.keeperEditing),s=k(N=>N.setKeeperEditing),n=k(N=>N.saveKeeperItem),a=k(N=>N.updateKeeperItem),r=k(N=>N.activeView),[l,c]=p.useState(""),[A,f]=p.useState(""),x=p.useRef(null),h=!!t&&r!=="memory";p.useEffect(()=>{t&&(c(t.tag||""),f(t.content||""))},[t]),p.useEffect(()=>{h&&x.current&&setTimeout(()=>{var N;return(N=x.current)==null?void 0:N.focus()},100)},[h]);const g=N=>{N||s(null)},O=async()=>{!l.trim()||t!=null&&t.readOnly||(t!=null&&t.isNew?await n(l.trim(),A):await a(l.trim(),A),s(null))},v=N=>{N.key==="s"&&(N.metaKey||N.ctrlKey)&&(N.preventDefault(),O())};if(!t)return null;const b=t.readOnly,y=t.isNew,B=b?`#${t.tag}`:y?"New Memory":`Edit #${t.tag}`;return e.jsx(Dt,{open:h,onOpenChange:g,children:e.jsx(Ht,{title:B,description:"Memory content",className:"max-w-2xl",children:e.jsxs("div",{className:"p-5 space-y-4",onKeyDown:v,children:[y&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-text-2 mb-1.5",children:"Tag"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-sm text-text-3",children:"#"}),e.jsx("input",{type:"text",value:l,onChange:N=>c(N.target.value.replace(/[^a-zA-Z0-9/_-]/g,"").toLowerCase()),placeholder:"project/feature-name",className:"flex-1 px-2 py-1.5 text-sm font-mono rounded-md bg-surface-0 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"})]})]}),e.jsx("textarea",{ref:x,value:A,onChange:N=>!b&&f(N.target.value),readOnly:b,rows:16,className:"w-full px-3 py-2 text-sm font-mono leading-relaxed rounded-md bg-surface-0 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent resize-y",placeholder:"Write your thoughts, ideas, context..."}),e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[b?e.jsx("p",{className:"text-2xs text-text-4",children:"Read-only view"}):e.jsxs("p",{className:"text-2xs text-text-4",children:[(j=navigator.platform)!=null&&j.includes("Mac")?"Cmd":"Ctrl","+S to save"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>s(null),children:b?"Close":"Cancel"}),!b&&e.jsxs(Oe,{variant:"primary",size:"sm",onClick:O,disabled:!l.trim(),children:[e.jsx(To,{size:14})," Save"]})]})]})]})})})}function doe(){const t=k(n=>n.keeperInstructOpen);return k(n=>n.activeView)==="memory"?null:e.jsx(Dt,{open:t,onOpenChange:n=>k.setState({keeperInstructOpen:n}),children:e.jsx(Ht,{title:"Keeper Commands",description:"Memory system command reference",className:"max-w-lg",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx("p",{className:"text-xs text-text-2 leading-relaxed",children:"Type these commands in any agent chat to manage your tagged memories. Commands are intercepted by Keeper — the agent never sees them."}),e.jsx("div",{className:"space-y-1.5",children:coe.map(n=>e.jsxs("div",{className:"flex items-start gap-3 py-1.5 border-b border-border-subtle last:border-0",children:[e.jsxs("div",{className:"flex-shrink-0 flex items-center gap-1",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-accent/15 text-accent font-mono text-xs font-semibold",children:n.cmd}),n.args&&e.jsx("span",{className:"text-xs text-text-3 font-mono",children:n.args})]}),e.jsx("span",{className:"text-xs text-text-3 pt-0.5",children:n.desc})]},n.cmd))}),e.jsxs("div",{className:"pt-2 space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold text-text-1",children:"Tag Hierarchy"}),e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed",children:["Use ",e.jsx("span",{className:"font-mono text-accent",children:"/"})," for nesting: ",e.jsx("span",{className:"font-mono text-accent",children:"#groove/memory-system"}),". Pull a parent to get all children."]}),e.jsx("h3",{className:"text-xs font-semibold text-text-1",children:"Memory Types"}),e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed",children:[e.jsx("span",{className:"font-semibold",children:"Manual"})," — you write via [save]/[append]/[update]. ",e.jsx("span",{className:"font-semibold",children:"Doc"})," — AI writes via [doc]. Both editable."]})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>k.setState({keeperInstructOpen:!1}),children:"Close"})})]})})})}function uoe(){return e.jsxs(e.Fragment,{children:[e.jsx(Aoe,{}),e.jsx(doe,{})]})}function foe({onSelect:t,onClose:s}){const n=p.useRef(null),a=k(f=>f.agents),r=k(f=>f.teams);p.useEffect(()=>{function f(h){n.current&&!n.current.contains(h.target)&&s()}function x(h){h.key==="Escape"&&s()}return document.addEventListener("mousedown",f),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",x)}},[s]);const l=a.filter(f=>f.status==="running"||f.status==="starting"),c=a.filter(f=>f.status!=="running"&&f.status!=="starting");function A(f){const x=r.find(h=>h.id===f);return(x==null?void 0:x.name)||"Default"}return e.jsxs("div",{ref:n,className:"absolute bottom-full right-0 mb-1 z-50 min-w-[220px] max-h-[300px] overflow-y-auto py-1 bg-surface-2 border border-border rounded-lg shadow-xl",children:[l.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-1 text-2xs text-text-4 font-sans font-medium uppercase tracking-wider",children:"Active"}),l.map(f=>e.jsxs("button",{onClick:()=>t(f.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-5 cursor-pointer transition-colors text-left",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-success flex-shrink-0"}),e.jsx("span",{className:"truncate flex-1",children:f.name}),e.jsx("span",{className:"text-2xs text-text-4",children:A(f.teamId)})]},f.id))]}),c.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-1 text-2xs text-text-4 font-sans font-medium uppercase tracking-wider",children:l.length>0?"Other":"Agents"}),c.slice(0,10).map(f=>e.jsxs("button",{onClick:()=>t(f.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs font-sans text-text-2 hover:bg-surface-5 cursor-pointer transition-colors text-left",children:[e.jsx("span",{className:G("w-1.5 h-1.5 rounded-full flex-shrink-0",f.status==="completed"?"bg-accent":f.status==="crashed"?"bg-danger":"bg-text-4")}),e.jsx("span",{className:"truncate flex-1",children:f.name}),e.jsx("span",{className:"text-2xs text-text-4",children:A(f.teamId)})]},f.id))]}),a.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-text-4 font-sans text-center",children:"No agents available"})]})}function xoe({children:t,height:s,onHeightChange:n,visible:a,fullHeight:r,tabs:l,activeTab:c,onSelectTab:A,onAddTab:f,onCloseTab:x,onToggleFullHeight:h,onMinimize:g,onClose:O,onRenameTab:v,selectedText:b}){const y=p.useRef(!1),[B,j]=p.useState(null),[N,T]=p.useState(""),[U,E]=p.useState(!1),S=p.useRef(0),C=p.useRef(0),F=k(M=>M.detailPanel),R=k(M=>M.workspaceAgentId),I=(F==null?void 0:F.type)==="agent"?F.agentId:R||null,Y=k(M=>M.agents),W=k(M=>M.attachSnippet),te=Y.find(M=>M.id===I),V=b&&b.trim().length>0,_=p.useCallback(M=>{if(r)return;M.preventDefault(),y.current=!0,S.current=M.clientY,C.current=s;function L(z){if(!y.current)return;const ae=S.current-z.clientY,ce=Math.min(Math.max(C.current+ae,120),600);n(ce)}function oe(){y.current=!1,document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",oe)}document.addEventListener("mousemove",L),document.addEventListener("mouseup",oe)},[s,n,r]);function P(M){!M||!(b!=null&&b.trim())||(E(!1),W({type:"terminal",code:b.trim()}),k.getState().selectAgent(M))}function K(){I?P(I):E(!0)}const H=l||[{id:"default",label:"Terminal"}];return e.jsxs("div",{className:G("flex flex-col border-t border-border bg-surface-0 relative",!a&&"hidden"),style:a?r?{flex:1,minHeight:0}:{height:s,flexShrink:0}:{height:0},children:[!r&&e.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 cursor-row-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:_}),e.jsxs("div",{className:"flex items-center h-9 bg-surface-1 border-b border-border flex-shrink-0 pl-0 pr-3",children:[e.jsxs("div",{className:"flex items-center gap-0 flex-1 min-w-0 overflow-x-auto scrollbar-none h-full",children:[H.map(M=>e.jsxs("button",{onClick:()=>A==null?void 0:A(M.id),onDoubleClick:()=>{j(M.id),T(M.label)},className:G("inline-flex items-center gap-1.5 px-3 h-full text-[11px] font-medium font-sans cursor-pointer select-none transition-colors duration-100 flex-shrink-0",M.id===c?"text-text-0 bg-surface-3":"text-text-2 hover:text-text-0 hover:bg-surface-5/50"),children:[e.jsx(Nr,{size:11}),B===M.id?e.jsx("input",{className:"bg-transparent border border-border rounded px-1 text-[11px] text-text-0 outline-none w-20 font-sans",value:N,onChange:L=>T(L.target.value),onBlur:()=>{N.trim()&&(v==null||v(M.id,N.trim())),j(null)},onKeyDown:L=>{L.key==="Enter"&&(N.trim()&&(v==null||v(M.id,N.trim())),j(null)),L.key==="Escape"&&j(null)},autoFocus:!0,onClick:L=>L.stopPropagation()}):e.jsx("span",{className:"truncate max-w-[100px]",children:M.label}),H.length>1&&e.jsx("button",{onClick:L=>{L.stopPropagation(),x==null||x(M.id)},className:"ml-1 p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(De,{size:9})})]},M.id)),e.jsx("button",{onClick:f,className:"flex items-center justify-center w-6 h-6 text-text-3 hover:text-text-0 hover:bg-surface-5/50 rounded cursor-pointer transition-colors flex-shrink-0 ml-1",title:"New terminal",children:e.jsx(At,{size:11})})]}),e.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0 ml-2",children:[V&&e.jsxs("div",{className:"relative flex items-center",children:[e.jsx(it,{content:I?`Send to ${(te==null?void 0:te.name)||"agent"}`:"Send to agent",side:"top",children:e.jsx("button",{onClick:K,className:G("flex items-center gap-1.5 px-2 py-1 rounded text-xs font-sans cursor-pointer transition-colors mr-1","bg-accent/15 text-accent hover:bg-accent/25 disabled:opacity-50"),children:I?e.jsxs(e.Fragment,{children:[e.jsx(ra,{size:11}),e.jsx("span",{className:"text-2xs max-w-[80px] truncate",children:(te==null?void 0:te.name)||"Agent"})]}):e.jsxs(e.Fragment,{children:[e.jsx(mn,{size:11}),e.jsx("span",{className:"text-2xs",children:"Agent"}),e.jsx(ft,{size:9})]})})}),!I&&V&&e.jsx(it,{content:"Pick agent",side:"top",children:e.jsx("button",{onClick:()=>E(!U),className:"p-1 rounded text-text-3 hover:text-accent hover:bg-accent/10 cursor-pointer transition-colors mr-1",children:e.jsx(ft,{size:10})})}),U&&e.jsx(foe,{onSelect:M=>P(M),onClose:()=>E(!1)})]}),r?e.jsx("button",{onClick:g,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Restore",children:e.jsx(QM,{size:12})}):e.jsx("button",{onClick:h,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Maximize",children:e.jsx(Bb,{size:12})}),e.jsx("button",{onClick:O,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Close terminal",children:e.jsx(De,{size:12})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 pl-2 pt-1",children:t})]})}const moe={background:"#1a1e25",foreground:"#c8ccd4",cursor:"#33afbc",cursorAccent:"#1a1e25",selectionBackground:"rgba(51, 175, 188, 0.3)",selectionForeground:"#ffffff",black:"#1a1e25",red:"#e06c75",green:"#4ae168",yellow:"#e5c07b",blue:"#61afef",magenta:"#c678dd",cyan:"#33afbc",white:"#abb2bf",brightBlack:"#5c6370",brightRed:"#f07178",brightGreen:"#4ae168",brightYellow:"#e5c07b",brightBlue:"#61afef",brightMagenta:"#c678dd",brightCyan:"#56b6c2",brightWhite:"#ffffff"};let Lg=0,hoe=0;function poe({tabId:t,visible:s,registerKill:n,onSelectionChange:a}){const r=p.useRef(null),l=p.useRef(null),c=p.useRef(null),A=p.useRef(null),f=p.useRef(null),x=p.useRef(!1),h=p.useRef(s),g=p.useRef({cols:0,rows:0});return p.useEffect(()=>{n==null||n(t,()=>{const O=k.getState().ws;(O==null?void 0:O.readyState)===WebSocket.OPEN&&A.current&&O.send(JSON.stringify({type:"terminal:kill",id:A.current}))})},[t,n]),p.useEffect(()=>{if(!r.current||x.current)return;x.current=!0;const O=new I3({theme:moe,fontFamily:"'SF Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace",fontSize:12,lineHeight:1.1,letterSpacing:0,cursorBlink:!0,cursorStyle:"bar",cursorWidth:1,scrollback:1e4,allowProposedApi:!0,minimumContrastRatio:1,drawBoldTextInBrightColors:!0,fontWeight:"400",fontWeightBold:"600",overviewRulerWidth:0}),v=new _3;O.loadAddon(v),O.loadAddon(new z3),O.open(r.current),l.current=O,c.current=v,O.onSelectionChange(()=>{const j=O.getSelection();a==null||a(j||"")});let b=0;function y(){b++;const j=k.getState().ws;if(!j||j.readyState!==WebSocket.OPEN){b<20&&setTimeout(y,500);return}const N=`spawn-${++hoe}`;j.send(JSON.stringify({type:"terminal:spawn",cols:O.cols,rows:O.rows,requestId:N}));function T(U){let E;try{E=JSON.parse(U.data)}catch{return}E.type==="terminal:spawned"&&E.requestId===N&&!A.current?A.current=E.id:E.type==="terminal:output"&&E.id===A.current?O.write(E.data):E.type==="terminal:exit"&&E.id===A.current&&(O.write(`\r
1023
+ `),me=pe.length>0?pe:void 0;b(""),h(),S([]),requestAnimationFrame(()=>{W.current&&(W.current.scrollTop=W.current.scrollHeight)});try{await a(t.id,ge,me)}catch{}B(!1),(J=te.current)==null||J.focus()}function ce(X){X.key==="Enter"&&!X.shiftKey&&(X.preventDefault(),ae())}const re=t.status==="running"||t.status==="starting";return e.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[re&&e.jsx(Ure,{agent:t}),e.jsxs("div",{ref:W,className:"flex-1 overflow-y-auto px-4 py-4 space-y-4",children:[!H.some(X=>X.from==="agent"||X.kind==="activity-group")&&(re?e.jsx(Pre,{agent:t}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center py-8",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-surface-3 flex items-center justify-center mb-3",children:e.jsx(ja,{size:18,className:"text-text-4"})}),e.jsx("p",{className:"text-sm font-semibold text-text-0 font-sans",children:t.name}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Session complete — send a message to continue"})]})),H.map((X,ee)=>{var pe;if(X.kind==="activity-group"){const q=!H.slice(ee+1).some(ge=>ge.kind==="activity-group"||ge.from==="agent");return e.jsx("div",{children:e.jsx(Tre,{entries:X.entries,isLive:re&&q})},`grp-${((pe=X.entries[0])==null?void 0:pe.ts)||ee}`)}return X.from==="user"?e.jsx(Bre,{msg:X},`user-${X._chatIdx}`):X.from==="system"?e.jsx(kre,{msg:X},`sys-${X._chatIdx}`):e.jsx(Cre,{msg:X,agent:t},`agent-${X._chatIdx}`)}),e.jsx(ki,{children:(y||r)&&e.jsx(En.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.25,ease:"easeOut"},children:e.jsx(G4,{agent:t})},"thinking")})]}),e.jsxs("div",{className:"bg-surface-1/50 flex-shrink-0",children:[e.jsx("div",{ref:Y,onMouseDown:K,className:"flex items-center justify-center h-5 cursor-row-resize border-t border-border hover:bg-surface-3/50 transition-colors group",children:e.jsx(xS,{size:12,className:"text-text-4 group-hover:text-text-2 transition-colors"})}),e.jsxs("div",{className:"px-4 pb-3",children:[x&&e.jsx("div",{className:"mb-2",children:e.jsx(Fre,{snippet:x,onRemove:h})}),v&&/\[(?:save|append|update|delete|view|doc|link|read|instruct)\]/i.test(v)&&(()=>{const X=v.match(/\[(save|append|update|delete|view|doc|link|read|instruct)\]/i),ee=v.match(/#[\w/.-]+/g)||[];return e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1 mb-2 rounded-lg bg-accent/5 border border-accent/10",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-accent/15 text-accent font-semibold font-mono text-[10px]",children:X[0]}),ee.map((pe,q)=>e.jsx("span",{className:"text-accent font-medium text-[10px]",children:pe},q)),e.jsx("span",{className:"text-[10px] text-text-4 ml-auto",children:"memory command"})]})})(),e.jsxs("div",{className:G("flex flex-col rounded-lg border bg-surface-0 transition-colors overflow-hidden focus-within:border-text-4/40",R?"border-accent border-dashed bg-accent/[0.03]":"border-border-subtle"),onDragOver:X=>{X.preventDefault(),I(!0)},onDragLeave:()=>I(!1),onDrop:X=>{var ee,pe;X.preventDefault(),I(!1),(pe=(ee=X.dataTransfer)==null?void 0:ee.files)!=null&&pe.length&&L(X)},children:[e.jsx("input",{ref:V,type:"file",multiple:!0,accept:"image/*,video/*,.pdf,.csv,.txt,.md,.json,.yaml,.yml,.docx,.pptx,.xlsx,.xml,.html,.py,.js,.ts,.jsx,.tsx,.go,.rs,.c,.cpp,.h,.java,.rb,.sh,.sql,.log",onChange:L,className:"hidden"}),R&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-accent",children:[e.jsx(CS,{size:16}),e.jsx("span",{className:"text-xs font-sans font-medium",children:"Drop files here"})]}),E.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 px-3 pt-2.5 pb-1",children:E.map(X=>e.jsxs("div",{className:G("relative group flex items-center gap-1.5 rounded-md border overflow-hidden",X.status==="error"?"border-danger/30 bg-danger/5":"border-border-subtle bg-surface-2",X.status==="uploading"&&"opacity-70"),children:[X.type==="image"&&X.dataUrl?e.jsx("img",{src:X.dataUrl,className:"w-12 h-12 object-cover",alt:X.name}):X.type==="video"&&X.dataUrl?e.jsxs("div",{className:"relative w-12 h-12",children:[e.jsx("video",{src:X.dataUrl,className:"w-12 h-12 object-cover",muted:!0}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20",children:e.jsx(dS,{size:12,className:"text-white"})})]}):e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5",children:[e.jsx(Fo,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-sans text-text-1 truncate max-w-[100px]",children:X.name}),e.jsx("span",{className:"text-[10px] font-mono text-text-4",children:q4(X.size)})]}),X.status==="uploading"&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-surface-0/60",children:e.jsx(_e,{size:14,className:"text-accent animate-spin"})}),X.status==="error"&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-danger/10",children:e.jsx(Zs,{size:14,className:"text-danger"})}),e.jsx("button",{onClick:()=>oe(X.id),className:"absolute top-0.5 right-0.5 w-4 h-4 flex items-center justify-center rounded-full bg-surface-0/80 text-text-4 hover:text-danger opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:e.jsx(De,{size:9})})]},X.id))}),e.jsxs("div",{className:"relative px-1",children:[v&&HQ.test(v)&&e.jsx("div",{ref:_,"aria-hidden":!0,className:"absolute inset-y-0 left-1 right-1 px-3 py-2.5 text-[13px] leading-[20px] font-sans pointer-events-none whitespace-pre-wrap break-words overflow-hidden",style:{height:j},children:wre(v)}),e.jsx("textarea",{ref:te,value:v,onChange:X=>b(X.target.value),onKeyDown:ce,onScroll:X=>{_.current&&(_.current.scrollTop=X.target.scrollTop)},placeholder:E.length>0||x?"Add a message (optional)...":re?"Send an instruction...":"Continue this session...",rows:1,className:G("w-full resize-none px-3 py-2.5 text-[13px] leading-[20px]","bg-transparent font-sans relative z-10 whitespace-pre-wrap break-words","placeholder:text-text-4","focus:outline-none",v&&HQ.test(v)?"text-transparent caret-text-0":"text-text-0"),style:{height:j}})]}),e.jsxs("div",{className:"flex items-center gap-1 px-1.5 pb-1.5 pt-0.5",children:[e.jsx("button",{onClick:()=>{var X;return(X=V.current)==null?void 0:X.click()},className:G("w-7 h-7 flex items-center justify-center rounded-md transition-colors cursor-pointer",E.length>0?"text-accent hover:text-accent/80":"text-text-4 hover:text-text-1"),title:"Attach file",children:e.jsx(yS,{size:14})}),E.length>0&&e.jsxs("span",{className:"text-[10px] font-mono text-accent",children:[E.length," file",E.length>1?"s":""]}),T.length>1&&e.jsxs("div",{className:"relative flex items-center",children:[e.jsx("select",{value:t.model||"",onChange:X=>{X.target.value&&Z.patch(`/agents/${t.id}`,{model:X.target.value}).catch(()=>{})},className:"h-7 pl-2 pr-5 text-[11px] font-mono bg-transparent text-text-3 hover:text-text-1 rounded-md cursor-pointer focus:outline-none appearance-none border-none",title:"Switch model",children:T.map(X=>e.jsx("option",{value:X.id,children:X.name||X.id},X.id))}),e.jsx(ft,{size:10,className:"absolute right-1.5 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]}),re&&e.jsxs("span",{className:"relative flex items-center justify-center w-3 h-3 mr-auto",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-accent/30 animate-ping [animation-duration:2s]"}),e.jsx("span",{className:"relative w-2 h-2 rounded-full bg-accent"})]}),e.jsx("div",{className:"flex-1"}),re?e.jsxs("button",{onClick:()=>k.getState().stopAgent(t.id),className:"flex items-center gap-1.5 h-7 px-2 rounded-md text-text-0 hover:text-text-1 hover:bg-surface-3 transition-colors cursor-pointer",children:[e.jsx(wS,{size:13}),e.jsx("span",{className:"text-[11px] font-sans font-medium",children:"Pause"})]}):e.jsx("button",{onClick:ae,disabled:!v.trim()&&!x&&E.length===0||y,className:G("w-7 h-7 flex items-center justify-center rounded-md transition-colors cursor-pointer","disabled:opacity-15 disabled:cursor-not-allowed",v.trim()||x||E.length>0?"text-text-0 hover:text-text-1":"text-text-4"),children:y?e.jsx(_e,{size:15,className:"animate-spin"}):e.jsx(Tb,{size:15})})]})]})]})]})]})}const $re={running:"success",starting:"warning",stopped:"default",crashed:"danger",completed:"accent",killed:"default",rotating:"purple"},Rre={running:"Running",starting:"Starting",stopped:"Stopped",crashed:"Crashed",completed:"Done",killed:"Killed",rotating:"Rotating"};function zg({agentId:t,paneIndex:s}){const n=k(g=>g.agents.find(O=>O.id===t)),a=k(g=>g.fleetSelectAgent),r=k(g=>g.fleetMarkRead),l=p.useRef(n),[c,A]=p.useState(!1),f=p.useRef(null);n&&(l.current=n,c&&A(!1),f.current&&(clearTimeout(f.current),f.current=null)),p.useEffect(()=>{if(!n&&t&&!c)return f.current=setTimeout(()=>A(!0),2e3),()=>{f.current&&clearTimeout(f.current)}},[n,t,c]),p.useEffect(()=>{t&&r(t)},[t,r]);const x=n||l.current;if(!x)return e.jsx("div",{className:"h-full flex items-center justify-center text-text-4",children:e.jsx("p",{className:"text-xs font-sans",children:"Select an agent"})});const h=Math.round((x.contextUsage||0)*100);return e.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[e.jsxs("div",{className:"h-10 bg-surface-1 border-b border-border px-3 flex items-center gap-2 flex-shrink-0",children:[e.jsx("span",{className:"text-sm font-medium text-text-0 font-sans truncate",children:x.name}),e.jsx(Te,{variant:"default",children:x.role}),x.provider&&e.jsxs("span",{className:"text-xs text-text-3 font-mono truncate",children:[x.provider,x.model?`:${x.model}`:""]}),e.jsx(Te,{variant:$re[x.status]||"default",dot:x.status==="running"?"pulse":void 0,children:Rre[x.status]||x.status}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-xs text-text-3 font-mono",children:vt(x.tokensUsed)}),e.jsxs("span",{className:G("text-xs font-mono",h>=75?"text-danger":h>=50?"text-warning":"text-text-3"),children:[h,"%"]}),e.jsx("button",{onClick:()=>a(null,s),className:"p-1 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-3 transition-colors cursor-pointer",title:"Close pane",children:e.jsx(De,{size:14})})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(W4,{agent:x})})]})}function Mre(){const t=k(v=>v.fleetSelectedAgents),s=k(v=>v.fleetSplitMode),n=k(v=>v.fleetSelectAgent),[a,r]=p.useState(null),l=p.useRef(!1),c=p.useRef(null),A=p.useRef(null),f=p.useRef(null),x=p.useCallback(v=>{var j;v.preventDefault(),l.current=!0;const b=(j=c.current)==null?void 0:j.parentElement;if(!b)return;function y(N){if(!l.current||!b||!A.current||!f.current)return;const T=b.getBoundingClientRect(),U=(N.clientX-T.left)/T.width*100,E=Math.max(25,Math.min(75,U));A.current.style.flex=`0 0 ${E}%`,f.current.style.flex=`0 0 ${100-E}%`}function B(){l.current=!1,document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",B)}document.addEventListener("mousemove",y),document.addEventListener("mouseup",B)},[]);function h(v,b){v.dataTransfer.types.includes("application/x-fleet-agent")&&(v.preventDefault(),v.dataTransfer.dropEffect="link",r(b))}function g(v,b){v.preventDefault(),r(null);const y=v.dataTransfer.getData("application/x-fleet-agent");y&&n(y,b)}function O(){r(null)}return!t[0]&&!t[1]?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 text-text-3",onDragOver:v=>h(v,"left"),onDragLeave:O,onDrop:v=>g(v,0),children:[e.jsx(OS,{size:32,strokeWidth:1,className:"text-text-4"}),e.jsx("p",{className:"text-sm font-sans",children:"Select an agent or drag one here"}),e.jsx("p",{className:"text-xs font-sans text-text-4",children:"Cmd+Click or drag to open side-by-side"})]}):!s||!t[1]?e.jsxs("div",{className:"flex-1 flex min-w-0 min-h-0",children:[e.jsx("div",{className:"flex-1 min-w-0 min-h-0",children:e.jsx(zg,{agentId:t[0],paneIndex:0})}),e.jsx("div",{className:`w-1 flex-shrink-0 transition-all ${a==="right"?"w-1 bg-accent/40":""}`,onDragOver:v=>h(v,"right"),onDragLeave:O,onDrop:v=>g(v,1)}),a==="right"&&e.jsx("div",{className:"w-48 flex-shrink-0 flex items-center justify-center border-2 border-dashed border-accent/30 bg-accent/5 rounded-lg m-1 transition-all",onDragOver:v=>h(v,"right"),onDragLeave:O,onDrop:v=>g(v,1),children:e.jsx("p",{className:"text-xs text-accent font-sans",children:"Drop to open"})})]}):e.jsxs("div",{className:"flex-1 flex min-w-0 min-h-0",children:[e.jsx("div",{ref:A,className:`min-w-0 min-h-0 ${a==="left"?"ring-2 ring-inset ring-accent/30":""}`,style:{flex:"0 0 50%"},onDragOver:v=>h(v,"left"),onDragLeave:O,onDrop:v=>g(v,0),children:e.jsx(zg,{agentId:t[0],paneIndex:0})}),e.jsx("div",{ref:c,className:"w-1 bg-border hover:bg-accent/30 cursor-col-resize transition-colors flex-shrink-0",onMouseDown:x}),e.jsx("div",{ref:f,className:`min-w-0 min-h-0 ${a==="right"?"ring-2 ring-inset ring-accent/30":""}`,style:{flex:"0 0 calc(50% - 4px)"},onDragOver:v=>h(v,"right"),onDragLeave:O,onDrop:v=>g(v,1),children:e.jsx(zg,{agentId:t[1],paneIndex:1})})]})}function Ire(){const t=k(s=>s.fleetSidebarWidth);return e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsx(Ore,{width:t}),e.jsx(Mre,{})]})}const _re={code:"Code",general:"General"},zre={light:"text-success",medium:"text-accent",heavy:"text-warning"};function Lre(t){return t<1?`${Math.round(t*1024)} MB`:`${t} GB`}function Y4({hardware:t}){if(!t)return null;const{totalRamGb:s,gpu:n,isAppleSilicon:a}=t;return e.jsxs("div",{className:"flex items-center gap-3 bg-surface-0 rounded-lg border border-border-subtle px-3 py-2.5",children:[e.jsx(ld,{size:14,className:"text-text-3 flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs font-sans",children:[e.jsxs("span",{className:"text-text-0 font-semibold",children:[s," GB RAM"]}),n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{className:"text-text-2",children:n.name})]}),a&&e.jsx(Te,{variant:"accent",className:"text-2xs",children:"Unified Memory"})]})})]})}function Dre({onRecheck:t}){const[s,n]=p.useState(null),[a,r]=p.useState(!1),[l,c]=p.useState(!1),[A,f]=p.useState(!1),x=k(U=>U.addToast);p.useEffect(()=>{Z.post("/providers/ollama/check").then(n).catch(()=>{})},[]);async function h(){r(!0);try{const U=await Z.post("/providers/ollama/check");n(U),U.installed&&U.serverRunning?(x("success","Ollama is ready!"),t()):U.installed?x("info","Ollama installed — server needs to start"):x("info","Ollama not found — install and try again")}catch{}r(!1)}async function g(){c(!0);try{if((await Z.post("/providers/ollama/serve")).ok){x("success","Ollama server started!");let E=!1;for(let S=0;S<5;S++){await new Promise(F=>setTimeout(F,2e3));const C=await Z.post("/providers/ollama/check");if(n(C),C.serverRunning){E=!0;break}}E&&t()}}catch(U){x("error","Could not start server",U.message)}c(!1)}function O(U){navigator.clipboard.writeText(U),f(!0),setTimeout(()=>f(!1),2e3)}if(!s)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{hardware:v,install:b,requirements:y,installed:B,serverRunning:j}=s,N=v.totalRamGb>=y.minRAM,T=v.recommended;return e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsx(Y4,{hardware:v}),N?e.jsxs("div",{className:"flex items-start gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2.5",children:[e.jsx(Ye,{size:14,className:"text-success flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans",children:[e.jsx("span",{className:"text-success font-semibold",children:"Your system is ready."}),e.jsx("span",{className:"text-text-2 ml-1",children:T.code?`Recommended: ${T.code}`:`${v.totalRamGb} GB RAM available`})]})]}):e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Zs,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsxs("span",{className:"text-warning font-semibold",children:[v.totalRamGb," GB RAM detected."]})," ","Minimum ",y.minRAM," GB needed. Smallest models may still work."]})]}),B&&!j&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Zs,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama installed but server not running."})," ","The server needs to be running to pull and use models."]})]}),e.jsxs(Oe,{variant:"primary",size:"md",onClick:g,disabled:l,className:"w-full gap-1.5",children:[e.jsx(Jt,{size:12}),l?"Starting...":"Start Ollama Server"]})]}),!B&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold text-text-1 font-sans",children:"Install Ollama"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 bg-surface-0 border border-border-subtle rounded-md px-3 py-2 text-xs font-mono text-text-1 truncate",children:b.command}),e.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>O(b.command),className:"h-8 px-2.5 gap-1 flex-shrink-0",children:[A?e.jsx(Ye,{size:12}):e.jsx(ya,{size:12}),A?"Copied":"Copy"]})]}),b.alt&&e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:b.alt})]}),e.jsxs(Oe,{variant:"secondary",size:"md",onClick:h,disabled:a,className:"w-full gap-1.5",children:[e.jsx(Is,{size:12,className:a?"animate-spin":""}),a?"Checking...":B?"Check again":"I installed it — check again"]})]})}function Hre({model:t,isInstalled:s,isRecommended:n,canRun:a,onPull:r,onDelete:l,pulling:c}){const A=c===t.id;return e.jsxs("div",{className:G("flex items-center gap-2 px-3 py-2 border-t border-border-subtle transition-colors",!a&&"opacity-40"),children:[s?e.jsx(Ye,{size:12,className:"text-success flex-shrink-0"}):e.jsx("div",{className:"w-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 truncate",children:t.name}),n&&e.jsx(Eb,{size:10,className:"text-warning flex-shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:G("text-2xs font-semibold font-sans",zre[t.tier]),children:t.tier}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:Lre(t.sizeGb)}),e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["· ",t.ramGb," GB RAM"]})]})]}),s?e.jsx("button",{onClick:()=>l(t.id),className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Remove model",children:e.jsx(Xt,{size:12})}):a?e.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>r(t.id),disabled:!!c,className:"h-7 px-2 text-2xs gap-1",children:A?e.jsxs(e.Fragment,{children:[e.jsx(Is,{size:10,className:"animate-spin"})," Pulling..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Gs,{size:10})," Pull"]})}):e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["Needs ",t.ramGb," GB"]})]})}function Xre({onStopped:t}){const[s,n]=p.useState(null),a=k(c=>c.addToast);async function r(){n("stopping");try{(await Z.post("/providers/ollama/stop")).ok?(a("info","Ollama server stopped"),t&&t()):a("error","Could not stop server")}catch(c){a("error","Stop failed",c.message)}n(null)}async function l(){n("restarting");try{(await Z.post("/providers/ollama/restart")).ok?a("success","Ollama server restarted"):a("error","Restart failed")}catch(c){a("error","Restart failed",c.message)}n(null)}return e.jsxs("div",{className:"flex items-center gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-success"}),e.jsx("span",{className:"absolute inset-[-2px] rounded-full bg-success opacity-20 animate-pulse"})]}),e.jsx("span",{className:"text-xs font-sans text-success font-semibold",children:"Server Running"}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:":11434"}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:l,disabled:!!s,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-accent cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(Is,{size:10,className:s==="restarting"?"animate-spin":""}),s==="restarting"?"Restarting...":"Restart"]}),e.jsxs("button",{onClick:r,disabled:!!s,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-danger cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(Zs,{size:10}),s==="stopping"?"Stopping...":"Stop"]})]})}function Zre({onModelChange:t}){var F,R;const[s,n]=p.useState(null),[a,r]=p.useState(null),[l,c]=p.useState("code"),[A,f]=p.useState(!1),[x,h]=p.useState(!1),g=k(I=>I.addToast),O=p.useRef(!1);function v(){Z.get("/providers/ollama/models").then(I=>{var Y;n(I),!O.current&&((Y=I.installed)==null?void 0:Y.length)===0&&(O.current=!0,setTimeout(v,2e3))}).catch(()=>{})}p.useEffect(()=>{v()},[]);async function b(I){r(I);try{await Z.post("/providers/ollama/pull",{model:I}),g("success",`Pulled ${I}`),v(),t&&t()}catch(Y){g("error",`Pull failed: ${Y.message}`)}r(null)}async function y(I){try{await Z.delete(`/providers/ollama/models/${encodeURIComponent(I)}`),g("info",`Removed ${I}`),v(),t&&t()}catch(Y){g("error",`Delete failed: ${Y.message}`)}}if(!s)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{installed:B,catalog:j,hardware:N}=s,T=new Set(B.map(I=>I.id)),U=N.totalRamGb,E=[(F=N.recommended)==null?void 0:F.code,(R=N.recommended)==null?void 0:R.general].filter(Boolean),S=j.filter(I=>I.category===l),C=A?S:S.filter(I=>I.ramGb<=U);return x?e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Zs,{size:14,className:"text-warning flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama server stopped."})," ","Start it again to pull and use models."]})]}),e.jsxs(Oe,{variant:"primary",size:"md",onClick:async()=>{try{(await Z.post("/providers/ollama/serve")).ok&&(g("success","Ollama server started!"),h(!1),O.current=!1,setTimeout(v,2e3))}catch(I){g("error","Could not start server",I.message)}},className:"w-full gap-1.5",children:[e.jsx(Jt,{size:12}),"Start Ollama Server"]})]}):e.jsxs("div",{className:"space-y-2 p-3",children:[e.jsx(Xre,{onStopped:()=>h(!0)}),e.jsx(Y4,{hardware:N}),B.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-sans text-text-2",children:[e.jsx(id,{size:12,className:"text-text-3"}),e.jsx("span",{className:"font-semibold",children:B.length})," model",B.length!==1?"s":""," installed"]}),e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:Object.entries(_re).map(([I,Y])=>e.jsx("button",{onClick:()=>c(I),className:G("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",l===I?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:Y},I))}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[C.map(I=>e.jsx(Hre,{model:I,isInstalled:T.has(I.id),isRecommended:E.includes(I.id),canRun:I.ramGb<=U,onPull:b,onDelete:y,pulling:a},I.id)),C.length===0&&e.jsxs("div",{className:"px-3 py-4 text-center text-xs text-text-4 font-sans",children:["No ",l," models available for your hardware"]})]}),!A&&S.length>C.length&&e.jsxs("button",{onClick:()=>f(!0),className:"flex items-center gap-1 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(ft,{size:10}),"Show ",S.length-C.length," more (exceed your RAM)"]})]})}function Gre({isInstalled:t,onModelChange:s}){const[n,a]=p.useState(!1),[r,l]=p.useState(!1);return p.useEffect(()=>{t?Z.post("/providers/ollama/check").then(c=>{a(c.installed&&c.serverRunning),l(!0)}).catch(()=>l(!0)):l(!0)},[t]),r?n?e.jsx(Zre,{onModelChange:s}):e.jsx(Dre,{onRecheck:()=>{a(!0),s&&s()}}):e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Checking Ollama..."})}function Qf({options:t,value:s,onChange:n}){return e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:t.map(a=>e.jsx("button",{onClick:()=>n(a.value),className:G("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",s===a.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:a.label},a.value))})}function qn({label:t,icon:s,children:n,description:a}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs font-semibold text-text-1 font-sans",children:[s&&e.jsx(s,{size:13,className:"text-text-3"}),t]}),a&&e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:a})]}),n]})}function Vre({agent:t}){const s=k(b=>b.killAgent),n=k(b=>b.rotateAgent),a=k(b=>b.spawnAgent),r=k(b=>b.closeDetail),l=k(b=>b.addToast),[c,A]=p.useState(null),[f,x]=p.useState(!1),h=t.status==="running"||t.status==="starting";async function g(){A("rotate");try{await n(t.id)}catch{}A(null)}async function O(){if(!f){x(!0),setTimeout(()=>x(!1),3e3);return}A("kill");try{await s(t.id,!h),r()}catch{}A(null),x(!1)}async function v(){A("clone");try{await a({role:t.role,provider:t.provider,model:t.model,name:`${t.name}-clone`,scope:t.scope,workingDir:t.workingDir}),l("success",`Cloned ${t.name}`)}catch{}A(null)}return h?e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs(Oe,{variant:"primary",size:"md",onClick:g,disabled:c==="rotate",className:"gap-1.5",children:[e.jsx(cd,{size:12,className:c==="rotate"?"animate-spin":""}),"Rotate"]}),e.jsxs(Oe,{variant:"info",size:"md",onClick:v,disabled:!!c,className:"gap-1.5",children:[e.jsx(ya,{size:12})," Clone"]}),e.jsxs(Oe,{variant:"danger",size:"md",onClick:O,disabled:c==="kill",className:"gap-1.5",children:[e.jsx(Ub,{size:12}),f?"Confirm":"Kill"]})]})}):e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs(Oe,{variant:"info",size:"md",onClick:v,disabled:!!c,className:"gap-1.5",children:[e.jsx(ya,{size:12})," Clone"]}),e.jsxs(Oe,{variant:"danger",size:"md",onClick:O,disabled:c==="kill",className:"gap-1.5",children:[e.jsx(Xt,{size:12}),f?"Confirm":"Remove"]})]})}function Kre({agent:t}){var me;const s=k(J=>J.addToast),n=k(J=>J.remoteHomedir),[a,r]=p.useState([]),[l,c]=p.useState(t.model||""),[A,f]=p.useState(""),[x,h]=p.useState(t.effort||"default"),[g,O]=p.useState(!1),[v,b]=p.useState(""),[y,B]=p.useState(null),[j,N]=p.useState(!1),[T,U]=p.useState(null),[E,S]=p.useState(t.routingMode||"auto"),[C,F]=p.useState([]),[R,I]=p.useState(""),[Y,W]=p.useState(!1),[te,V]=p.useState([]),[_,P]=p.useState(!1),[K,H]=p.useState([]),[M,L]=p.useState(null),oe=t.status==="running"||t.status==="starting";p.useEffect(()=>{z(),Z.get("/integrations/installed").then(ve=>H(Array.isArray(ve)?ve:[])).catch(()=>{}),Z.get("/repos/imported").then(ve=>F((Array.isArray(ve)?ve:[]).filter(Qe=>Qe.status==="active"))).catch(()=>{}),t.provider==="claude-code"&&Z.get("/providers/claude-code/auth").then(ve=>L(ve)).catch(()=>L(null));function J(){z()}return window.addEventListener("groove:providers-changed",J),()=>window.removeEventListener("groove:providers-changed",J)},[]);function z(){Z.get("/providers").then(J=>r(Array.isArray(J)?J:[])).catch(()=>{})}p.useEffect(()=>{c(t.model||""),Z.get(`/agents/${t.id}/routing/recommend`).then(J=>{S((J==null?void 0:J.mode)||"fixed")}).catch(()=>{})},[t.id,t.model]),p.useEffect(()=>{W(!1),t.personality?Z.get(`/personalities/${t.name}`).then(J=>{I((J==null?void 0:J.content)||""),W(!0)}).catch(()=>{I(""),W(!0)}):(I(""),W(!0)),Z.get("/personalities").then(J=>{V(Array.isArray(J)?J:J.personalities||[])}).catch(()=>{})},[t.id,t.name]);const ae=a.find(J=>J.id===t.provider);async function ce(J,ve){c(ve);try{const Qe={model:ve};J&&J!==t.provider&&(Qe.provider=J),await Z.patch(`/agents/${t.id}`,Qe),s("success",`Model → ${ve}${Qe.provider?` (${J})`:""}`)}catch(Qe){s("error","Model swap failed",Qe.message)}}async function re(J){try{await Z.patch(`/agents/${t.id}`,{workingDir:J}),s("success",`Working dir → ${J.split("/").pop()||J}`)}catch(ve){s("error","Update failed",ve.message)}}async function X(J){h(J);try{await Z.patch(`/agents/${t.id}`,{effort:J}),s("success",`Effort → ${J}`)}catch(ve){s("error","Update failed",ve.message)}}async function ee(J){if(!J.trim())return;const ve=[...t.scope||[],J.trim()];try{await Z.patch(`/agents/${t.id}`,{scope:ve}),f("")}catch(Qe){s("error","Scope update failed",Qe.message)}}async function pe(J){const ve=(t.scope||[]).filter((Qe,Xe)=>Xe!==J);try{await Z.patch(`/agents/${t.id}`,{scope:ve})}catch(Qe){s("error","Scope update failed",Qe.message)}}async function q(J){if(v.trim())try{await Z.post(`/credentials/${J}`,{key:v.trim()}),s("success",`API key set for ${J}`),b(""),B(null),z(),window.dispatchEvent(new CustomEvent("groove:providers-changed"))}catch(ve){s("error","Failed to set key",ve.message)}}const ge=t.spawnedAt||t.createdAt;return e.jsxs("div",{className:"px-5 py-5 space-y-6 overflow-y-auto h-full",children:[e.jsx(qn,{label:"Active Model",icon:wa,children:e.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold font-mono text-text-0",children:t.model||"auto"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:(ae==null?void 0:ae.name)||t.provider})]}),(ae==null?void 0:ae.canHotSwap)&&oe&&e.jsxs(Te,{variant:"accent",className:"text-2xs gap-1",children:[e.jsx(Jt,{size:8})," Hot-swap"]})]}),((me=ae==null?void 0:ae.models)==null?void 0:me.length)>1&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3 pt-3 border-t border-border-subtle",children:ae.models.filter(J=>!J.disabled).map(J=>{const ve=J.id===t.model;return e.jsx("button",{onClick:()=>ce(t.provider,J.id),disabled:!1,className:G("px-2.5 py-1 rounded-md text-xs font-mono transition-all","cursor-pointer",ve?"bg-accent/15 text-accent font-semibold":"bg-surface-4 text-text-2 hover:bg-surface-5 hover:text-text-0"),children:J.name||J.id},J.id)})})]})}),e.jsx(Vre,{agent:t}),e.jsxs(qn,{label:"Providers",icon:Wl,description:"Click a provider to see its models and connection status.",children:[e.jsx("div",{className:"space-y-1.5",children:a.map(J=>{var Tt;const ve=J.id===t.provider,Qe=J.authType==="subscription"?J.installed||((Tt=J.authStatus)==null?void 0:Tt.authenticated):J.authType==="local"?J.installed:J.installed&&J.hasKey,Xe=T===J.id,nt=J.models||[];return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[e.jsxs("button",{onClick:()=>U(Xe?null:J.id),className:"w-full flex items-center gap-2.5 px-3 py-2 cursor-pointer hover:bg-surface-4/50 transition-colors",children:[e.jsx("div",{className:G("w-2 h-2 rounded-full flex-shrink-0",Qe?"bg-success":"bg-text-4")}),e.jsx("span",{className:G("text-xs font-semibold font-sans flex-1 text-left",Qe?"text-text-0":"text-text-3"),children:J.name||J.id}),ve&&e.jsx(Te,{variant:"accent",className:"text-2xs",children:"Active"}),!Qe&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:J.installed?"No key":"Not installed"}),e.jsx(ft,{size:12,className:G("text-text-4 transition-transform",Xe&&"rotate-180")})]}),Xe&&J.authType==="local"&&e.jsx("div",{className:"border-t border-border-subtle",children:e.jsx(Gre,{isInstalled:Qe,onModelChange:z})}),Xe&&J.authType!=="local"&&e.jsxs("div",{className:"border-t border-border-subtle",children:[(!Qe||J.hasKey)&&e.jsx("div",{className:"px-3 py-2 bg-surface-1/50",children:y===J.id?e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("input",{value:v,onChange:lt=>b(lt.target.value),onKeyDown:lt=>lt.key==="Enter"&&q(J.id),type:j?"text":"password",placeholder:`${J.name||J.id} API key...`,className:"w-full h-7 px-2.5 pr-7 text-2xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),e.jsx("button",{onClick:()=>N(!j),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:j?e.jsx(yo,{size:10}):e.jsx(Xs,{size:10})})]}),e.jsx(Oe,{variant:"primary",size:"sm",onClick:()=>q(J.id),disabled:!v.trim(),className:"h-7 px-2 text-2xs",children:"Save"}),e.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{B(null),b("")},className:"h-7 px-2 text-2xs",children:"Cancel"})]}):e.jsxs("button",{onClick:()=>{B(J.id),b(""),N(!1)},className:"flex items-center gap-1.5 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(wi,{size:10}),Qe?"Update API key":"Add API key to enable"]})}),Qe&&nt.filter(lt=>!lt.disabled).length>0&&nt.filter(lt=>!lt.disabled).map(lt=>{const bs=J.id===t.provider&&lt.id===t.model;return e.jsxs("button",{onClick:()=>ce(J.id,lt.id),disabled:!1,className:G("w-full flex items-center gap-2 px-3 py-2 text-left text-xs font-sans transition-colors","border-t border-border-subtle","cursor-pointer hover:bg-surface-4/50",bs?"text-accent":"text-text-2"),children:[bs?e.jsx(Ye,{size:11,className:"text-accent flex-shrink-0"}):e.jsx("div",{className:"w-[11px]"}),e.jsx("span",{className:"font-mono flex-1 truncate",children:lt.name||lt.id}),e.jsx(Te,{variant:bs?"accent":"default",className:"text-2xs",children:lt.tier})]},lt.id)})]})]},J.id)})}),oe&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans mt-1.5",children:[e.jsx(Zs,{size:10}),e.jsx("span",{children:"Model changes apply on next rotation or respawn."})]})]}),t.provider==="claude-code"&&M&&!M.authenticated&&e.jsxs("div",{className:"rounded-lg border border-warning/30 bg-warning/5 px-4 py-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Zs,{size:13,className:"text-warning flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Claude Code is not signed in"})]}),e.jsxs("p",{className:"text-2xs text-text-2 font-sans",children:["Open the terminal and run: ",e.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"claude"})]})]}),t.provider==="claude-code"&&(M==null?void 0:M.authenticated)&&e.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-success flex-shrink-0"}),"Signed in as ",M.email||"Claude user"," (",M.subscriptionType||"subscription",")"]}),e.jsx(qn,{label:"Working Directory",icon:Ks,description:"The root directory this agent operates in.",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 bg-surface-0 rounded-lg px-3 py-2.5 text-sm font-mono text-text-1 border border-border-subtle truncate min-w-0",children:t.workingDir||"Project root"}),e.jsxs(Oe,{variant:"secondary",size:"md",onClick:()=>O(!0),className:"gap-1.5 flex-shrink-0",children:[e.jsx(Nb,{size:14})," Browse"]})]})}),e.jsx(qn,{label:"Permission Mode",icon:Pn,description:"Full Send = no approvals. Agent Approve = Fullstack Manager reviews risky operations.",children:e.jsx(Qf,{options:[{value:"full",label:"Full Send"},{value:"auto",label:"Agent Approve"}],value:t.permission||"full",onChange:async J=>{try{await Z.patch(`/agents/${t.id}`,{permission:J}),s("success",`Permission → ${J==="full"?"Full Send":"Agent Approve"}`)}catch(ve){s("error","Update failed",ve.message)}}})}),e.jsxs(qn,{label:"Model Routing",icon:Vl,description:"How Groove selects models for this agent's tasks.",children:[e.jsx(Qf,{options:[{value:"fixed",label:"Fixed"},{value:"auto",label:"Auto"},{value:"auto-floor",label:"Auto + Floor"}],value:E,onChange:async J=>{S(J);try{await Z.post(`/agents/${t.id}/routing`,{mode:J}),s("success",`Routing → ${J}`)}catch(ve){s("error","Update failed",ve.message)}}}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans mt-1",children:[E==="fixed"&&"Uses the selected model for all tasks.",E==="auto"&&"Groove picks Opus/Sonnet/Haiku based on task complexity.",E==="auto-floor"&&"Auto-routes but never drops below Sonnet."]})]}),e.jsx(qn,{label:"File Scope",icon:Pn,description:"Restrict which files this agent can access. Empty = unrestricted.",children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(t.scope||[]).map((J,ve)=>e.jsxs(Te,{variant:"default",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[J,e.jsx("button",{onClick:()=>pe(ve),className:"hover:text-danger cursor-pointer",children:e.jsx(De,{size:10})})]},ve)),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{value:A,onChange:J=>f(J.target.value),onKeyDown:J=>J.key==="Enter"&&ee(A),placeholder:"e.g. src/**",className:"w-28 h-7 px-2.5 text-xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsx("button",{onClick:()=>ee(A),disabled:!A.trim(),className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:e.jsx(At,{size:12})})]})]})}),e.jsx(qn,{label:"Effort Level",icon:fS,description:"Controls how deep the agent reasons. Higher = more tokens but better results.",children:e.jsx(Qf,{options:[{value:"min",label:"Min"},{value:"low",label:"Low"},{value:"default",label:"Default"},{value:"high",label:"High"},{value:"max",label:"Max"}],value:x,onChange:X})}),e.jsx(qn,{label:"Agent Details",icon:Wl,children:e.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle divide-y divide-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"ID"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.id})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Role"}),e.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:t.role})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Provider"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.provider})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Model"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.model||"auto"})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Status"}),e.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:t.status})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Spawned"}),e.jsx("span",{className:"text-xs text-text-1 font-sans",children:ge?As(ge):"—"})]}),t.sessionId&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Session"}),e.jsxs("span",{className:"text-xs text-text-1 font-mono",children:[t.sessionId.slice(0,16),"..."]})]})]})}),e.jsxs(qn,{label:"Integrations",icon:en,description:"Attach MCP integrations for external services.",children:[e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(t.integrations||[]).map(J=>{const ve=gi[J],Qe=K.find(Xe=>Xe.id===J);return e.jsxs(Te,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[ve?e.jsx("img",{src:ve,alt:"",className:"w-2.5 h-2.5"}):e.jsx(en,{size:9}),(Qe==null?void 0:Qe.name)||J,e.jsx("button",{onClick:async()=>{try{await Z.delete(`/agents/${t.id}/integrations/${J}`),s("success",`Detached ${(Qe==null?void 0:Qe.name)||J}`)}catch(Xe){s("error","Detach failed",Xe.message)}},className:"hover:text-danger cursor-pointer",children:e.jsx(De,{size:10})})]},J)}),K.filter(J=>J.configured!==!1&&!(t.integrations||[]).includes(J.id)).length>0&&e.jsxs("div",{className:"relative group",children:[e.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer transition-colors",children:e.jsx(At,{size:12})}),e.jsx("div",{className:"absolute top-full left-0 mt-1 z-20 hidden group-hover:block bg-surface-2 border border-border-subtle rounded-lg shadow-xl py-1 min-w-[200px]",children:K.filter(J=>J.configured!==!1&&!(t.integrations||[]).includes(J.id)).map(J=>{const ve=gi[J.id];return e.jsxs("button",{onClick:async()=>{try{await Z.post(`/agents/${t.id}/integrations/${J.id}`),s("success",`Attached ${J.name||J.id}`)}catch(Qe){s("error","Attach failed",Qe.message)}},className:"w-full flex items-center gap-2 text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-4 cursor-pointer transition-colors",children:[ve?e.jsx("img",{src:ve,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(en,{size:12,className:"text-text-3 flex-shrink-0"}),J.name||J.id]},J.id)})})]}),(t.integrations||[]).length===0&&K.length===0&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No integrations installed — browse the Marketplace"})]}),(t.integrations||[]).length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"text-2xs font-medium text-text-3 font-sans block mb-1.5",children:"Integration Approvals"}),e.jsx(Qf,{options:[{value:"auto",label:"Auto"},{value:"manual",label:"Manual"}],value:t.integrationApproval||"manual",onChange:async J=>{try{await Z.patch(`/agents/${t.id}`,{integrationApproval:J}),s("success",`Integration approvals → ${J==="auto"?"Auto":"Manual"}`)}catch(ve){s("error","Update failed",ve.message)}}})]})]}),C.length>0&&e.jsx(qn,{label:"Repos",icon:Il,description:"Attach imported repos so this agent knows where they are.",children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(t.repos||[]).map(J=>{const ve=C.find(Qe=>Qe.id===J);return e.jsxs(Te,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[(ve==null?void 0:ve.name)||J,e.jsx("button",{onClick:async()=>{try{await Z.delete(`/agents/${t.id}/repos/${J}`),s("success",`Detached ${(ve==null?void 0:ve.name)||J}`)}catch(Qe){s("error","Detach failed",Qe.message)}},className:"hover:text-danger cursor-pointer",children:e.jsx(De,{size:10})})]},J)}),C.filter(J=>!(t.repos||[]).includes(J.id)).length>0&&e.jsxs("div",{className:"relative group",children:[e.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer transition-colors",children:e.jsx(At,{size:12})}),e.jsx("div",{className:"absolute top-full left-0 mt-1 z-20 hidden group-hover:block bg-surface-2 border border-border-subtle rounded-lg shadow-xl py-1 min-w-[200px]",children:C.filter(J=>!(t.repos||[]).includes(J.id)).map(J=>e.jsxs("button",{onClick:async()=>{try{await Z.post(`/agents/${t.id}/repos/${J.id}`),s("success",`Attached ${J.name||J.id}`)}catch(ve){s("error","Attach failed",ve.message)}},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-4 cursor-pointer transition-colors",children:[e.jsx("div",{className:"font-semibold",children:J.name||J.repo}),e.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:J.clonedTo})]},J.id))})]}),(t.repos||[]).length===0&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No repos attached — import one from the Marketplace"})]})}),e.jsxs(qn,{label:"Personality",icon:$o,description:"Injected into every prompt. Changes apply on next spawn or rotation.",children:[e.jsx("textarea",{value:R,onChange:J=>I(J.target.value),placeholder:Y?"Describe this agent's personality, tone, and behavior...":"Loading...",rows:4,className:"w-full min-h-[4rem] max-h-[10rem] resize-y bg-surface-0 border border-border-subtle rounded-md p-2 text-xs font-mono text-text-1 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Oe,{variant:"primary",size:"sm",disabled:_,onClick:async()=>{P(!0);try{await Z.put(`/personalities/${t.name}`,{content:R}),s("success","Personality saved")}catch(J){s("error","Save failed",J.message)}P(!1)},className:"h-7 px-3 text-2xs gap-1",children:[e.jsx(To,{size:10}),_?"Saving...":"Save"]}),te.length>0&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:"",onChange:J=>{if(!J.target.value)return;const ve=te.find(Qe=>(Qe.name||Qe)===J.target.value);ve&&Z.get(`/personalities/${ve.name||ve}`).then(Qe=>{Qe!=null&&Qe.content&&I(Qe.content)}).catch(()=>{})},className:"h-7 px-2 pr-7 text-2xs rounded-md bg-surface-1 border border-border-subtle text-text-2 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Clone from..."}),te.filter(J=>(J.name||J)!==t.name).map(J=>e.jsx("option",{value:J.name||J,children:J.name||J},J.name||J))]}),e.jsx(ft,{size:10,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]})]})]}),t.prompt&&e.jsx(qn,{label:"Original Prompt",icon:Vl,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3 py-3 text-xs text-text-2 font-sans leading-relaxed max-h-40 overflow-y-auto",children:t.prompt})}),e.jsx(Ac,{open:g,onOpenChange:O,currentPath:t.workingDir||n||"/",homePath:n,onSelect:re})]})}const XQ=[];function qre({data:t,isAlive:s,height:n=48}){const a=p.useRef(null);return p.useEffect(()=>{const r=a.current;if(!r||!t.length)return;const l=r.getContext("2d"),c=window.devicePixelRatio||1,A=r.clientWidth,f=r.clientHeight;r.width=A*c,r.height=f*c,l.scale(c,c),l.clearRect(0,0,A,f);const x=t.map(b=>b.v),h=Math.min(...x),O=Math.max(...x,1)-h||1;l.beginPath(),l.moveTo(0,f),t.forEach((b,y)=>{const B=y/(t.length-1)*A,j=f-(b.v-h)/O*(f-4)-2;l.lineTo(B,j)}),l.lineTo(A,f),l.closePath();const v=l.createLinearGradient(0,0,0,f);if(v.addColorStop(0,s?"rgba(51,175,188,0.15)":"rgba(110,118,129,0.08)"),v.addColorStop(1,"rgba(0,0,0,0)"),l.fillStyle=v,l.fill(),l.beginPath(),l.strokeStyle=s?le.accent:le.text3,l.lineWidth=1.5,t.forEach((b,y)=>{const B=y/(t.length-1)*A,j=f-(b.v-h)/O*(f-4)-2;y===0?l.moveTo(B,j):l.lineTo(B,j)}),l.stroke(),t.length>1&&s){const b=t[t.length-1],y=A-1,B=f-(b.v-h)/O*(f-4)-2;l.beginPath(),l.arc(y,B,5,0,Math.PI*2),l.fillStyle="rgba(51,175,188,0.3)",l.fill(),l.beginPath(),l.arc(y,B,2.5,0,Math.PI*2),l.fillStyle=le.accent,l.fill()}},[t,s]),e.jsx("div",{className:"w-full rounded-lg bg-surface-0 overflow-hidden border border-border-subtle",style:{height:n},children:e.jsx("canvas",{ref:a,className:"w-full h-full"})})}function Nf({icon:t,label:s,value:n,color:a,sub:r}){return e.jsxs("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(t,{size:12,className:a||"text-text-3"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans uppercase tracking-wider",children:s})]}),e.jsx("div",{className:G("text-lg font-bold font-mono tabular-nums",a||"text-text-0"),children:n}),r&&e.jsx("div",{className:"text-2xs text-text-4 font-sans mt-0.5",children:r})]})}function Wre({score:t}){const s=Math.min(Math.max(t,0),100);let n=le.success,a="Healthy";return s<40?(n=le.danger,a="Degraded"):s<70&&(n=le.warning,a="Fair"),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("span",{className:"text-2xs text-text-3 font-sans flex items-center gap-1.5",children:[e.jsx(qR,{size:11}),"Session Health"]}),e.jsxs("span",{className:"text-xs font-bold font-mono",style:{color:n},children:[s,"/100"]})]}),e.jsx("div",{className:"h-2 bg-surface-0 rounded-full overflow-hidden border border-border-subtle",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700",style:{width:`${s}%`,background:n}})}),e.jsx("span",{className:"text-2xs font-sans mt-1 block",style:{color:n},children:a})]})}function Yre(t){const s=(t||"").toLowerCase();return s.includes("edit")||s.includes("writ")?{icon:LA,color:"text-warning"}:s.includes("read")||s.includes("view")?{icon:Xs,color:"text-info"}:s.includes("search")||s.includes("grep")||s.includes("glob")?{icon:cs,color:"text-purple"}:s.includes("bash")||s.includes("command")||s.includes("terminal")?{icon:Nr,color:"text-orange"}:s.includes("error")||s.includes("fail")?{icon:Zs,color:"text-danger"}:s.includes("spawn")||s.includes("start")?{icon:Jt,color:"text-success"}:s.includes("complet")||s.includes("done")?{icon:qf,color:"text-success"}:{icon:va,color:"text-text-4"}}function Jre({agent:t}){const s=k(c=>c.tokenTimeline[t.id])||XQ,n=k(c=>c.activityLog[t.id])||XQ,a=t.status==="running"||t.status==="starting",r=p.useMemo(()=>{if(s.length<2)return 0;const c=s.slice(-10),A=(c[c.length-1].t-c[0].t)/6e4,f=c[c.length-1].v-c[0].v;return A>0?Math.round(f/A):0},[s]),l=p.useMemo(()=>{const c=t.contextUsage||0;let A=100;return c>90?A-=50:c>70?A-=25:c>50&&(A-=10),r>5e3?A-=15:r>3e3&&(A-=8),t.status==="crashed"&&(A=10),t.status==="completed"&&(A=95),Math.max(0,Math.min(100,A))},[t.contextUsage,t.status,r]);return e.jsxs("div",{className:"px-5 py-5 space-y-5 overflow-y-auto h-full",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Token Burn"}),a&&e.jsx("span",{className:"text-2xs text-accent font-mono animate-pulse",children:"LIVE"})]}),e.jsx(qre,{data:s,isAlive:a,height:56})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(Nf,{icon:kR,label:"Burn Rate",value:r>0?`${vt(r)}/m`:"—",color:r>5e3?"text-danger":r>2e3?"text-warning":"text-text-0"}),e.jsx(Nf,{icon:mR,label:"Cost",value:Ro(t.costUsd||0),color:"text-text-0"}),e.jsx(Nf,{icon:cd,label:"Rotations",value:t.rotations||"0",color:"text-text-0"}),e.jsx(Nf,{icon:Jt,label:"Turns",value:t.turns||"0",color:"text-text-0"})]}),e.jsx(Wre,{score:l}),t.prompt&&e.jsxs("div",{children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-1.5",children:"Task"}),e.jsx("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 text-xs text-text-2 font-sans leading-relaxed max-h-28 overflow-y-auto border border-border-subtle",children:t.prompt})]}),n.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-2",children:"Activity"}),e.jsxs("div",{className:"space-y-0 relative",children:[e.jsx("div",{className:"absolute left-[9px] top-2 bottom-2 w-px bg-border-subtle"}),n.slice(-12).reverse().map((c,A)=>{const f=Yre(c.text),x=f.icon;return e.jsxs("div",{className:"flex items-start gap-3 py-1.5 relative",children:[e.jsx("div",{className:G("w-[18px] h-[18px] rounded-full flex items-center justify-center flex-shrink-0 z-10","bg-surface-1 border border-border-subtle"),children:e.jsx(x,{size:9,className:f.color})}),e.jsx("span",{className:"text-2xs text-text-2 font-sans flex-1 line-clamp-1 pt-0.5",children:c.text}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0 pt-0.5",children:As(c.timestamp)})]},A)})]})]})]})}function eoe({agent:t}){const s=k(C=>C.addToast),[n,a]=p.useState([]),[r,l]=p.useState(""),[c,A]=p.useState(null),[f,x]=p.useState(""),[h,g]=p.useState(""),[O,v]=p.useState(!1),[b,y]=p.useState(!1),[B,j]=p.useState("");async function N(){try{const C=await Z.get(`/agents/${t.id}/mdfiles`);a(C.files||[]),l(C.workingDir||"")}catch{}}p.useEffect(()=>{N()},[t.id]);async function T(C){try{const F=await Z.get(`/agents/${t.id}/mdfiles/read?path=${encodeURIComponent(C)}`);x(F.content||""),g(F.content||""),A(C)}catch(F){s("error","Failed to read file",F.message)}}async function U(){if(c){v(!0);try{await Z.put(`/agents/${t.id}/mdfiles/write`,{path:c,content:f}),g(f),s("success",`Saved ${c}`)}catch(C){s("error","Save failed",C.message)}v(!1)}}async function E(){const C=B.trim();if(C)try{await Z.post(`/agents/${t.id}/mdfiles/create`,{name:C}),j(""),y(!1),s("success",`Created ${C}.md`),N()}catch(F){s("error","Create failed",F.message)}}const S=f!==h;return c?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border-subtle",children:[e.jsx("button",{onClick:()=>{A(null),x(""),g("")},className:"p-1 text-text-3 hover:text-text-0 cursor-pointer",children:e.jsx(Pi,{size:14})}),e.jsx(Bn,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs text-text-0 font-sans font-medium flex-1 truncate",children:c}),S&&e.jsx("span",{className:"text-[10px] text-warning font-sans",children:"unsaved"}),e.jsxs("button",{onClick:U,disabled:!S||O,className:G("flex items-center gap-1 px-2.5 py-1 rounded text-2xs font-sans font-medium cursor-pointer transition-colors",S?"bg-accent/15 text-accent hover:bg-accent/25":"text-text-4 opacity-50 cursor-not-allowed"),children:[e.jsx(To,{size:10}),O?"Saving...":"Save"]})]}),e.jsx("textarea",{value:f,onChange:C=>x(C.target.value),className:"flex-1 w-full px-4 py-3 bg-surface-0 text-[12px] font-mono text-text-1 leading-relaxed resize-none focus:outline-none",spellCheck:!1})]}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 border-b border-border-subtle",children:[e.jsx(Bn,{size:12,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:"Markdown Files"}),e.jsx("button",{onClick:()=>y(!0),className:"p-1 text-text-4 hover:text-accent cursor-pointer",title:"Create file",children:e.jsx(At,{size:12})}),e.jsx("button",{onClick:N,className:"p-1 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(Is,{size:11})})]}),r&&e.jsx("div",{className:"px-4 py-1.5 text-[10px] text-text-4 font-mono truncate border-b border-border-subtle/50",children:r}),b&&e.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-b border-border-subtle bg-surface-0",children:[e.jsx(Bn,{size:11,className:"text-accent flex-shrink-0"}),e.jsx("input",{autoFocus:!0,value:B,onChange:C=>j(C.target.value),onKeyDown:C=>{C.key==="Enter"&&E(),C.key==="Escape"&&(y(!1),j(""))},placeholder:"filename",className:"flex-1 bg-transparent text-xs text-text-0 font-mono outline-none placeholder:text-text-4"}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:".md"}),e.jsx("button",{onClick:E,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:e.jsx(To,{size:11})}),e.jsx("button",{onClick:()=>{y(!1),j("")},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(De,{size:11})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center px-4",children:[e.jsx(Bn,{size:20,className:"text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No markdown files found"}),e.jsx("p",{className:"text-[10px] text-text-4 font-sans mt-1",children:"MD files in the agent's working directory will appear here"})]}):e.jsx("div",{className:"py-1",children:n.map(C=>e.jsxs("button",{onClick:()=>T(C.path),className:"w-full flex items-center gap-2.5 px-4 py-2 text-left hover:bg-surface-5 transition-colors cursor-pointer",children:[e.jsx(Bn,{size:13,className:"text-accent flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-xs text-text-0 font-sans block truncate",children:C.name}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:C.path})]}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono flex-shrink-0",children:C.size>1024?`${(C.size/1024).toFixed(1)}K`:`${C.size}B`}),C.source==="personality"&&e.jsx("span",{className:"text-[9px] font-mono text-purple bg-purple/10 px-1 py-px rounded flex-shrink-0",children:"personality"}),C.source==="user"&&e.jsx("span",{className:"text-[9px] font-mono text-accent bg-accent/10 px-1 py-px rounded flex-shrink-0",children:"custom"})]},C.path))})})]})}const toe={running:"success",starting:"warning",stopped:"default",crashed:"danger",completed:"accent",killed:"default",rotating:"purple"},soe={running:"Running",starting:"Starting",stopped:"Stopped",crashed:"Crashed",completed:"Done",killed:"Killed",rotating:"Rotating"},noe=[{id:"command",label:"Chat",icon:ja},{id:"config",label:"Config",icon:Yl},{id:"telemetry",label:"Monitor",icon:Vl},{id:"mdfiles",label:"Files",icon:Bn}];function aoe({agent:t}){const s=k(f=>f.addToast),[n,a]=p.useState(!1),[r,l]=p.useState(t.name),c=p.useRef(null);async function A(){const f=r.trim();if(!f||f===t.name){a(!1);return}try{await Z.patch(`/agents/${t.id}`,{name:f.replace(/\s+/g,"-")}),s("success",`Renamed → ${f}`)}catch(x){s("error","Rename failed",x.message),l(t.name)}a(!1)}return n?e.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-0",children:[e.jsx("input",{ref:c,value:r,onChange:f=>l(f.target.value),onKeyDown:f=>{f.key==="Enter"&&A(),f.key==="Escape"&&(l(t.name),a(!1))},className:"flex-1 min-w-0 h-6 px-1.5 text-sm font-bold bg-surface-0 border border-accent/30 rounded text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent/40",autoFocus:!0}),e.jsx("button",{onClick:A,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:e.jsx(Ye,{size:12})}),e.jsx("button",{onClick:()=>{l(t.name),a(!1)},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(De,{size:12})})]}):e.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0 group",children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans truncate",children:t.name}),e.jsx("button",{onClick:()=>{l(t.name),a(!0)},className:"p-0.5 text-text-4 opacity-0 group-hover:opacity-100 hover:text-text-1 cursor-pointer transition-opacity",children:e.jsx(Cr,{size:10})})]})}function roe(){const t=k(v=>v.detailPanel),s=k(v=>v.agents),n=k(v=>v.activeTeamId);k(v=>v.addToast);const[a,r]=p.useState("command"),l=p.useRef(null),c=(t==null?void 0:t.type)==="agent"?t.agentId:null,A=c?s.find(v=>v.id===c):null;A?l.current=A:l.current&&l.current.id!==c&&(l.current=null);const f=A||l.current,x=(A==null?void 0:A.status)==="running"||(A==null?void 0:A.status)==="starting";if(!f||n&&f.teamId&&f.teamId!==n)return null;const h=Math.round((f.contextUsage||0)*100),g=f.spawnedAt||f.createdAt,O=g?Math.floor((Date.now()-new Date(g).getTime())/1e3):0;return Ra(f.role),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex-shrink-0",children:[e.jsxs("div",{className:"pl-4 pr-10 pt-3 pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(aoe,{agent:f}),e.jsx(Te,{variant:toe[f.status]||"default",dot:x?"pulse":void 0,className:"text-2xs flex-shrink-0",children:soe[f.status]||f.status})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-2xs text-text-3 font-mono",children:[e.jsx("span",{className:"capitalize",children:f.role}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{children:[f.provider,":",f.model||"auto"]}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{children:[vt(f.tokensUsed||0)," tok"]}),h>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{className:G(h>80?"text-danger":h>60?"text-warning":"text-text-3"),children:[h,"% ctx"]})]}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{children:Mo(O)})]})]}),e.jsx("div",{className:"flex items-center px-4 border-b border-border-subtle",children:noe.map(v=>{const b=v.icon,y=a===v.id;return e.jsxs("button",{onClick:()=>r(v.id),className:G("flex items-center gap-1.5 px-3 py-2 text-2xs font-semibold font-sans transition-all cursor-pointer select-none border-b-2 -mb-px",y?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"),children:[e.jsx(b,{size:11}),v.label]},v.id)})})]}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[a==="command"&&e.jsx(W4,{agent:f}),a==="config"&&e.jsx(Kre,{agent:f}),a==="telemetry"&&e.jsx(Jre,{agent:f}),a==="mdfiles"&&e.jsx(eoe,{agent:f})]})]})}const ooe=[{id:"chat",label:"Chat",desc:"Companion, assistant, conversation",icon:$o,tier:"Medium"},{id:"planner",label:"Planner",desc:"Plans the team and tasks",icon:Qi,tier:"Heavy"},{id:"backend",label:"Backend",desc:"APIs, services, databases",icon:Bs,tier:"Medium"},{id:"frontend",label:"Frontend",desc:"UI, components, styling",icon:ld,tier:"Medium"},{id:"fullstack",label:"Fullstack",desc:"End-to-end implementation",icon:xn,tier:"Heavy"},{id:"testing",label:"Testing",desc:"Tests, coverage, QA",icon:Mx,tier:"Medium"},{id:"devops",label:"DevOps",desc:"CI/CD, infra, deployment",icon:vb,tier:"Medium"},{id:"docs",label:"Docs",desc:"Documentation, guides",icon:Bn,tier:"Light"},{id:"security",label:"Security",desc:"Audits, vulnerabilities",icon:Pn,tier:"Medium"},{id:"database",label:"Database",desc:"Schema, migrations, queries",icon:yb,tier:"Medium"},{id:"cmo",label:"CMO",desc:"Marketing, content, growth",icon:Cb,tier:"Medium"},{id:"cfo",label:"CFO",desc:"Finance, metrics, forecasting",icon:iS,tier:"Medium"},{id:"ea",label:"EA",desc:"Executive assistant, scheduling",icon:kS,tier:"Light"},{id:"support",label:"Support",desc:"Customer support, FAQs",icon:hS,tier:"Medium"},{id:"analyst",label:"Analyst",desc:"Data analysis, insights",icon:Px,tier:"Medium"},{id:"creative",label:"Writer",desc:"Copy, articles, proposals",icon:jS,tier:"Heavy",skillHint:!0},{id:"slides",label:"Slides",desc:"Pitch decks, presentations",icon:NS,tier:"Heavy",skillHint:!0},{id:"ambassador",label:"Ambassador",desc:"Bridge to federated server",icon:aa,tier:"Light"}];function ZQ(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"text-accent flex-shrink-0",children:[e.jsx("circle",{cx:"7",cy:"7",r:"6",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1"}),e.jsx("path",{d:"M4.5 7 L6.5 9 L9.5 5.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}function ioe(){var Be;const t=k(se=>se.detailPanel),s=k(se=>se.closeDetail),n=k(se=>se.spawnAgent),a=k(se=>se.fetchProviders),r=k(se=>se.teams),l=k(se=>se.activeTeamId),c=k(se=>se.createTeam),A=(t==null?void 0:t.type)==="spawn",[f,x]=p.useState(""),[h,g]=p.useState(""),[O,v]=p.useState(""),[b,y]=p.useState(""),[B,j]=p.useState(""),[N,T]=p.useState(""),[U,E]=p.useState([]),[S,C]=p.useState([]),[F,R]=p.useState([]),[I,Y]=p.useState(!1),[W,te]=p.useState(""),[V,_]=p.useState("manual"),[P,K]=p.useState([]),[H,M]=p.useState([]),[L,oe]=p.useState(!1),[z,ae]=p.useState(""),[ce,re]=p.useState([]),[X,ee]=p.useState(""),[pe,q]=p.useState(!1),[ge,me]=p.useState(!1),[J,ve]=p.useState(""),[Qe,Xe]=p.useState([]),[nt,Tt]=p.useState(null),[lt,bs]=p.useState([]),[zo,kr]=p.useState(!1),[qs,Lo]=p.useState("new"),[ds,Mi]=p.useState(""),[ca,Do]=p.useState(""),Tr=k(se=>se.federation),Ur=k(se=>se.ollamaRunningModels),es=f||h,Cs=U.find(se=>se.id===b),zs=(Cs==null?void 0:Cs.models)||[],$n=U.filter(se=>se.authType==="api-key"?se.installed&&se.hasKey:se.installed),vs=!!(t!=null&&t.presetProvider||t!=null&&t.presetModel),nn=(t==null?void 0:t.presetTeamId)||null,ht=!nn&&(vs||!l);p.useEffect(()=>{if(A){const se=(t==null?void 0:t.presetProvider)||"",Ne=(t==null?void 0:t.presetModel)||"";a().then(Me=>{const Re=Array.isArray(Me)?Me:Me.providers||[];E(Re);const Rn=Re.filter(ys=>ys.authType==="api-key"?ys.installed&&ys.hasKey:ys.installed);if(Rn.length>0&&!se){const Er=["claude-code","gemini","codex","ollama"].find(xc=>Rn.some(an=>an.id===xc))||Rn[0].id;y(Er)}if(se&&y(se),Ne){const ys=Re.find(an=>an.id===(se||b)),Er=(ys==null?void 0:ys.models)||[];if(Er.find(an=>an.id===Ne))j(Ne);else{const an=Ne.split(":"),Ga=an.length>=3?an.slice(2).join(":"):an[an.length-1],mc=Er.find(Ho=>Ho.id===Ne||Ho.id===`gguf:${Ga}`||Ho.id.endsWith(`:${Ga}`)||Ho.name===Ga);j((mc==null?void 0:mc.id)||Ne)}}}).catch(()=>{}),Z.get("/integrations/installed").then(Me=>{C(Array.isArray(Me)?Me:[])}).catch(()=>{}),Z.get("/repos/imported").then(Me=>{K((Array.isArray(Me)?Me:[]).filter(Re=>Re.status==="active"))}).catch(()=>{}),Z.get("/personalities").then(Me=>{re(Array.isArray(Me)?Me:Me.personalities||[])}).catch(()=>{}),x(""),g(""),v(""),y(se),j(Ne),Lo("new"),Do(""),Mi(Ne?Ne.split(":").pop().replace(/[-_]/g," "):""),T(""),R([]),_("manual"),M([]),ee(""),ve(""),q(!1),Xe([]),Tt(null)}},[A,a]),p.useEffect(()=>{if(!es||!A){Xe([]);return}Z.get(`/roles/integrations?role=${encodeURIComponent(es)}`).then(se=>{const Ne=Array.isArray(se)?se:(se==null?void 0:se.recommendations)||[];Xe(Ne);const Me=Ne.filter(Re=>Re.installed&&Re.configured&&Re.authenticated).map(Re=>Re.id);Me.length>0&&R(Re=>[...new Set([...Re,...Me])])}).catch(()=>Xe([]))},[es,A]),p.useEffect(()=>{if(!A||b!=="ollama"){bs([]);return}Z.get("/providers/ollama/models").then(se=>{bs(se.installed||[])}).catch(()=>bs([])),Z.post("/providers/ollama/check").then(se=>{kr(se.serverRunning)}).catch(()=>kr(!1))},[A,b]);async function de(){me(!0);try{let se;if(nn)se=nn;else if(!ht)se=l;else if(qs==="new"){const Me=ds.trim()||es||"New Team";se=(await c(Me)).id}else qs==="existing"&&ca&&(se=ca);const Ne={role:es,...O&&{name:O.replace(/\s+/g,"-")},...b&&{provider:b},...B&&{model:B},...N&&{prompt:N},...F.length>0&&{integrations:F},...F.length>0&&{integrationApproval:V},...H.length>0&&{repos:H},...X&&{personality:X},...es==="ambassador"&&J&&{peerId:J},...se&&{teamId:se}};await n(Ne),s()}catch{}me(!1)}async function Ze(){var se;if(es){try{const Ne=await Z.post("/agents/preflight",{role:es,integrations:F});if(((se=Ne==null?void 0:Ne.issues)==null?void 0:se.length)>0){Tt(Ne.issues);return}}catch{}de()}}return e.jsxs(T4,{open:A,onOpenChange:se=>{se||s()},children:[e.jsx(U4,{title:"Spawn Agent",width:480,onClose:()=>s(),children:e.jsxs("div",{className:"flex flex-col h-[calc(100%-57px)]",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-3",children:"Choose Role"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:ooe.map(se=>{const Ne=Ra(se.id),Me=f===se.id;return e.jsxs("button",{onClick:()=>{x(se.id),g("")},className:G("flex items-center gap-2.5 p-3 rounded-md border text-left transition-all cursor-pointer",Me?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-2"),children:[e.jsx("div",{className:"w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0",style:{background:Ne.bg},children:e.jsx(se.icon,{size:16,style:{color:Ne.text}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:se.label}),se.skillHint&&e.jsx("span",{className:"text-2xs font-mono text-warning/70 bg-warning/8 px-1 py-px rounded",children:"skill"})]}),e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:se.desc})]})]},se.id)})}),e.jsx("div",{className:"mt-3",children:e.jsx(Yt,{placeholder:"or type a custom role (e.g. chat-agent)...",value:h,onChange:se=>{g(se.target.value.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,50)),x("")},className:"text-xs"})})]}),es&&Qe.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Recommended Integrations"}),e.jsx("div",{className:"space-y-1.5",children:Qe.map(se=>{const Ne=gi[se.id];return se.installed&&se.configured&&se.authenticated?e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-success/5 border border-success/20",children:[e.jsx(Ye,{size:13,className:"text-success flex-shrink-0"}),Ne?e.jsx("img",{src:Ne,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(en,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:se.name||se.id}),e.jsx(Te,{variant:"success",className:"text-2xs ml-auto",children:"Ready"})]},se.id):se.installed?e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-warning/5 border border-warning/20",children:[e.jsx(sa,{size:13,className:"text-warning flex-shrink-0"}),Ne?e.jsx("img",{src:Ne,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(en,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:se.name||se.id}),e.jsx(Oe,{variant:"ghost",size:"sm",className:"ml-auto text-2xs text-warning h-6 px-2",onClick:()=>{s(),k.getState().setActiveView("marketplace")},children:"Configure"})]},se.id):e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-surface-1 border border-border-subtle",children:[Ne?e.jsx("img",{src:Ne,alt:"",className:"w-3.5 h-3.5 flex-shrink-0 opacity-40"}):e.jsx(en,{size:12,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-text-3 font-sans",children:se.name||se.id}),e.jsx("button",{onClick:()=>{s(),k.getState().setActiveView("marketplace")},className:"ml-auto text-2xs text-accent hover:underline font-sans cursor-pointer",children:"Install in Marketplace"})]},se.id)})})]}),es==="ambassador"&&(()=>{const se=Tr.whitelist.filter(Ne=>typeof Ne=="object"&&(Ne.status==="mutual"||Ne.status==="connected"));return se.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-4 text-center",children:[e.jsx(aa,{size:18,className:"text-text-4 mx-auto mb-1.5"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans mb-2",children:"No federated servers connected. Add one in the Federation view."}),e.jsx(Oe,{variant:"ghost",size:"sm",className:"text-2xs text-accent",onClick:()=>{s(),k.getState().setActiveView("federation")},children:"Go to Federation"})]}):e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Target Server"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:J,onChange:Ne=>ve(Ne.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Select a server..."}),se.map(Ne=>e.jsx("option",{value:Ne.ip,children:Ne.name||`${Ne.ip}:${Ne.port||31415}`},Ne.ip))]}),e.jsx(ft,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})})(),es&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block",children:"Configuration"}),e.jsx(Yt,{label:"Name (optional)",value:O,onChange:se=>v(se.target.value),placeholder:`${es}-1`}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Provider"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:b,onChange:se=>{y(se.target.value),j("")},className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Auto"}),U.map(se=>e.jsxs("option",{value:se.id,disabled:se.authType==="api-key"?!(se.installed&&se.hasKey):!se.installed,children:[se.name,se.installed?se.authType==="api-key"&&!se.hasKey?" (No API key)":"":" (Not installed)"]},se.id))]}),e.jsx(ft,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Model"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:B,onChange:se=>j(se.target.value),disabled:!b,className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent disabled:opacity-40",children:[e.jsx("option",{value:"",children:"Auto"}),b==="ollama"&&lt.length>0?e.jsxs(e.Fragment,{children:[e.jsx("optgroup",{label:"Installed Models",children:lt.map(se=>{const Ne=Ur.some(Me=>Me.name===se.id);return e.jsxs("option",{value:se.id,children:[se.name||se.id," (",se.size,")",Ne?" ● Running":""]},se.id)})}),e.jsx("optgroup",{label:"Catalog",children:zs.filter(se=>!lt.some(Ne=>Ne.id===se.id)).map(se=>e.jsxs("option",{value:se.id,children:[se.name," (not installed)"]},se.id))})]}):b==="local"?(()=>{const se=zs.filter(Re=>Re.source==="runtime"),Ne=zs.filter(Re=>Re.source==="gguf"),Me=zs.filter(Re=>Re.source==="ollama"||!Re.source);return e.jsxs(e.Fragment,{children:[se.length>0&&e.jsx("optgroup",{label:"Lab Runtimes",children:se.map(Re=>e.jsxs("option",{value:Re.id,children:[Re.name,Re.runtimeType?` (${Re.runtimeType})`:""]},Re.id))}),Ne.length>0&&e.jsx("optgroup",{label:"GGUF Models",children:Ne.map(Re=>e.jsxs("option",{value:Re.id,children:[Re.name,Re.hasRuntime?"":" (no runtime)"]},Re.id))}),Me.length>0&&e.jsx("optgroup",{label:"Ollama",children:Me.map(Re=>e.jsx("option",{value:Re.id,children:Re.name},Re.id))})]})})():zs.map(se=>e.jsx("option",{value:se.id,children:se.name},se.id))]}),e.jsx(ft,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})]}),b&&Cs&&e.jsx("div",{className:"text-2xs text-text-3 font-sans flex items-center gap-2 flex-wrap",children:Cs.authType==="local"?e.jsx(Te,{variant:"success",children:"Local"}):Cs.authType==="subscription"?e.jsx(Te,{variant:"accent",children:"Subscription"}):Cs.hasKey?e.jsx(Te,{variant:"success",children:"API key set"}):e.jsxs(Te,{variant:"warning",children:["No API key — set with: groove set-key ",b," YOUR_KEY"]})}),b==="ollama"&&B&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap text-2xs font-sans",children:[Ur.some(se=>se.name===B)?e.jsxs(Te,{variant:"success",className:"text-2xs gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-success"}),"Ready — running in memory"]}):lt.some(se=>se.id===B)?e.jsx(Te,{variant:"subtle",className:"text-2xs",children:"Will auto-start when agent spawns"}):e.jsx(Te,{variant:"warning",className:"text-2xs",children:"Not installed — will pull first"}),!zo&&e.jsx("span",{className:"text-warning",children:"Server not running — will auto-start"})]}),ht&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Team"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("button",{onClick:()=>Lo("new"),className:G("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",qs==="new"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(At,{size:13,className:qs==="new"?"text-accent":"text-text-3"}),e.jsx("div",{children:e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"New Team"})})]}),e.jsxs("button",{onClick:()=>Lo("existing"),className:G("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",qs==="existing"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(Fn,{size:13,className:qs==="existing"?"text-accent":"text-text-3"}),e.jsx("div",{children:e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Existing"})})]})]}),qs==="new"&&e.jsx(Yt,{value:ds,onChange:se=>Mi(se.target.value),placeholder:"Team name...",className:"text-xs"}),qs==="existing"&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:ca,onChange:se=>Do(se.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Select team..."}),r.filter(se=>!se.archived).map(se=>e.jsx("option",{value:se.id,children:se.name},se.id))]}),e.jsx(ft,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integrations"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[F.map(se=>{const Ne=S.find(Re=>Re.id===se),Me=gi[se];return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded bg-accent/12 text-accent border border-accent/25 text-2xs font-sans",children:[Me?e.jsx("img",{src:Me,alt:"",className:"w-2.5 h-2.5"}):e.jsx(en,{size:9}),(Ne==null?void 0:Ne.name)||se,e.jsx("button",{onClick:()=>R(Re=>Re.filter(Rn=>Rn!==se)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:e.jsx(De,{size:9})})]},se)}),e.jsxs("button",{onClick:()=>{Y(!0),te("")},className:G("inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-2xs font-sans transition-colors cursor-pointer","bg-surface-0 text-text-2 border border-border-subtle hover:border-border hover:text-text-0"),children:[e.jsx(en,{size:10}),F.length>0?"Add integration":"Attach integration"]})]})]}),e.jsx(Dt,{open:I,onOpenChange:Y,children:e.jsx(Ht,{title:"Select Integration",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(cs,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:W,onChange:se=>te(se.target.value),placeholder:"Search integrations...",autoFocus:!0,className:"w-full h-8 pl-8 pr-3 text-xs rounded-md bg-surface-0 border border-border text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsxs("div",{className:"max-h-64 overflow-y-auto space-y-1",children:[S.filter(se=>{if(!W)return!0;const Ne=W.toLowerCase();return(se.name||se.id).toLowerCase().includes(Ne)||(se.description||"").toLowerCase().includes(Ne)}).map(se=>{const Ne=F.includes(se.id),Me=se.configured!==!1,Re=gi[se.id],Rn=es&&Array.isArray(se.roles)&&se.roles.includes(es);return e.jsxs("button",{onClick:()=>{Me&&R(ys=>Ne?ys.filter(Er=>Er!==se.id):[...ys,se.id])},disabled:!Me,className:G("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors",Me?"cursor-pointer":"opacity-40 cursor-not-allowed",Ne?"bg-accent/10 border border-accent/25":Me?"hover:bg-surface-3 border border-transparent":"border border-transparent"),children:[Re?e.jsx("img",{src:Re,alt:"",className:"w-4 h-4 flex-shrink-0"}):e.jsx(en,{size:12,className:Ne?"text-accent":"text-text-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:se.name||se.id}),!Me&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"(not configured)"}),Me&&Rn&&e.jsx("span",{className:"text-2xs font-mono text-accent/70 bg-accent/8 px-1 py-px rounded",children:"rec"})]}),se.description&&e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:se.description}),!Me&&e.jsx("div",{className:"text-2xs text-text-4 font-sans",children:"Configure in Marketplace"})]}),Ne&&e.jsx(ZQ,{})]},se.id)}),S.length===0&&e.jsx("div",{className:"text-center py-6 text-xs text-text-3 font-sans",children:"No integrations installed. Visit the Marketplace to install integrations."})]})]})})}),F.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integration Approvals"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("button",{onClick:()=>_("manual"),className:G("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",V==="manual"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(Pn,{size:13,className:V==="manual"?"text-accent":"text-text-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Manual"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"You approve each action"})]})]}),e.jsxs("button",{onClick:()=>_("auto"),className:G("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",V==="auto"?"border-warning bg-warning/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(mn,{size:13,className:V==="auto"?"text-warning":"text-text-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Auto"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"Agent acts without asking"})]})]})]})]}),P.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Repos"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[H.map(se=>{const Ne=P.find(Me=>Me.id===se);return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded bg-accent/12 text-accent border border-accent/25 text-2xs font-sans",children:[e.jsx(Il,{size:9}),(Ne==null?void 0:Ne.name)||se,e.jsx("button",{onClick:()=>M(Me=>Me.filter(Re=>Re!==se)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:e.jsx(De,{size:9})})]},se)}),e.jsxs("button",{onClick:()=>{oe(!0),ae("")},className:G("inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-2xs font-sans transition-colors cursor-pointer","bg-surface-0 text-text-2 border border-border-subtle hover:border-border hover:text-text-0"),children:[e.jsx(Il,{size:10}),H.length>0?"Add repo":"Attach repo"]})]})]}),e.jsx(Dt,{open:L,onOpenChange:oe,children:e.jsx(Ht,{title:"Select Repository",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-3 p-4",children:[P.length>1&&e.jsxs("div",{className:"relative",children:[e.jsx(cs,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:z,onChange:se=>ae(se.target.value),placeholder:"Search repos...",autoFocus:!0,className:"w-full h-8 pl-8 pr-3 text-xs rounded-md bg-surface-0 border border-border text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:P.filter(se=>{if(!z)return!0;const Ne=z.toLowerCase();return(se.name||se.repo||se.id).toLowerCase().includes(Ne)}).map(se=>{const Ne=H.includes(se.id);return e.jsxs("button",{onClick:()=>{M(Me=>Ne?Me.filter(Re=>Re!==se.id):[...Me,se.id])},className:G("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors cursor-pointer",Ne?"bg-accent/10 border border-accent/25":"hover:bg-surface-3 border border-transparent"),children:[e.jsx(Il,{size:12,className:Ne?"text-accent":"text-text-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:se.name||se.repo}),e.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:se.clonedTo})]}),Ne&&e.jsx(ZQ,{})]},se.id)})})]})})}),(f==="chat"||pe)&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Personality"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:X,onChange:se=>ee(se.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"None (blank)"}),ce.map(se=>e.jsx("option",{value:se.name||se,children:se.name||se},se.name||se))]}),e.jsx(ft,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:"Personality is injected into every prompt for this agent."})]}),f!=="chat"&&!pe&&e.jsx("button",{onClick:()=>q(!0),className:"text-2xs text-text-3 hover:text-accent font-sans transition-colors cursor-pointer",children:"+ Advanced options"})]})]}),e.jsxs("div",{className:"border-t border-border-subtle px-5 py-4 bg-surface-1",children:[$n.length===0&&U.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 px-3 py-2 rounded-md bg-warning/8 border border-warning/20",children:[e.jsx(sa,{size:13,className:"text-warning flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-sans text-text-2",children:"No AI providers installed. Install Claude Code, Gemini CLI, Codex, or Ollama to spawn agents."})]}),es&&$n.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 text-xs text-text-3 font-sans flex-wrap",children:[e.jsx("span",{children:"Spawning"}),e.jsx(Te,{variant:"accent",children:es}),b&&e.jsxs("span",{children:["on ",(Cs==null?void 0:Cs.name)||b]}),O&&e.jsxs("span",{children:["as ",O.replace(/\s+/g,"-")]}),qs==="new"&&e.jsxs("span",{children:["in new team",ds?` "${ds}"`:""]}),qs==="existing"&&ca&&e.jsxs("span",{children:["in ",((Be=r.find(se=>se.id===ca))==null?void 0:Be.name)||"team"]})]}),e.jsx(Oe,{variant:"primary",size:"lg",onClick:Ze,disabled:!es||ge||$n.length===0||qs==="existing"&&!ca,className:"w-full",children:ge?"Spawning...":"Spawn Agent"})]})]})}),e.jsx(Dt,{open:!!nt,onOpenChange:se=>{se||Tt(null)},children:e.jsx(Ht,{title:"Integration Warning",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsx("div",{className:"space-y-2",children:(nt||[]).map((se,Ne)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs text-text-1 font-sans",children:[e.jsx(sa,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsx("span",{children:se.name?`${se.name}: ${se.problem==="not_installed"?"not installed":se.problem==="not_configured"?"not configured":"not authenticated"}`:se.message||String(se)})]},Ne))}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Continue anyway?"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Oe,{variant:"ghost",size:"md",onClick:()=>Tt(null),className:"flex-1",children:"Cancel"}),e.jsx(Oe,{variant:"warning",size:"md",onClick:()=>{Tt(null),de()},className:"flex-1",children:"Spawn Anyway"})]})]})})})]})}function loe(){const t=k(g=>g.journalistStatus),s=k(g=>g.fetchJournalist),n=k(g=>g.triggerJournalistCycle),[a,r]=p.useState(!0),[l,c]=p.useState(!1);p.useEffect(()=>{s().then(()=>r(!1));const g=setInterval(s,1e4);return()=>clearInterval(g)},[s]);async function A(){c(!0);try{await n()}catch{}c(!1)}if(a)return e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx(Jn,{className:"h-6 w-32 rounded"}),e.jsx(Jn,{className:"h-20 rounded-md"}),e.jsx(Jn,{className:"h-20 rounded-md"})]});const f=t||{},x=f.lastSynthesis,h=f.history||[];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"pl-5 pr-10 py-4 border-b border-border-subtle flex items-center gap-2",children:[e.jsx(Wf,{size:16,className:"text-accent"}),e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Journalist"}),e.jsxs(Oe,{variant:"secondary",size:"sm",onClick:A,disabled:l,className:"gap-1.5 text-2xs",children:[e.jsx(Is,{size:11,className:l?"animate-spin":""}),l?"Running...":"Run Synthesis"]})]}),e.jsx(yt,{className:"flex-1",children:e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Vl,{size:10}),e.jsxs("span",{children:[f.cycleCount||0," cycles"]})]}),f.lastCycleTime&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(va,{size:10}),e.jsxs("span",{children:["Last: ",As(f.lastCycleTime)]})]}),e.jsx(Te,{variant:f.cycleCount>0?"success":"default",className:"text-2xs",children:f.cycleCount>0?"Active":"Idle"})]}),(x==null?void 0:x.summary)&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[e.jsx(Bn,{size:12,className:"text-text-3"}),"Latest Summary"]}),e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-sans leading-relaxed",children:x.summary})]}),(x==null?void 0:x.projectMap)&&e.jsx(jx,{title:"Project Map",icon:pM,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-mono leading-relaxed max-h-64 overflow-y-auto whitespace-pre-wrap",children:x.projectMap})}),(x==null?void 0:x.decisions)&&e.jsx(jx,{title:"Decisions Log",icon:Bn,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-mono leading-relaxed max-h-64 overflow-y-auto whitespace-pre-wrap",children:x.decisions})}),h.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[e.jsx(va,{size:12,className:"text-text-3"}),"History (",h.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:h.slice().reverse().slice(0,20).map((g,O)=>e.jsxs("div",{className:"bg-surface-0 rounded-md border border-border-subtle px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xs",children:[e.jsxs(Te,{variant:"default",className:"text-2xs",children:["Cycle ",g.cycle]}),e.jsxs("span",{className:"text-text-4 font-sans",children:[g.agentCount," agent",g.agentCount!==1?"s":""]}),e.jsx("span",{className:"text-text-4 font-sans ml-auto",children:As(g.timestamp)})]}),g.summary&&e.jsx("p",{className:"text-xs text-text-2 font-sans mt-1 leading-relaxed",children:g.summary})]},O))})]}),!x&&h.length===0&&e.jsxs("div",{className:"text-center py-8 text-text-4 font-sans",children:[e.jsx(Wf,{size:28,className:"mx-auto mb-2"}),e.jsx("p",{className:"text-sm",children:"No synthesis data yet"}),e.jsx("p",{className:"text-2xs mt-1",children:"The journalist runs automatically when agents are active, or trigger manually above"})]})]})})]})}const coe=[{cmd:"save",args:"#tag",desc:"Save the message and send it to the agent"},{cmd:"append",args:"#tag",desc:"Add to an existing memory and send to agent"},{cmd:"update",args:"#tag",desc:"Open the editor to modify a memory in place"},{cmd:"delete",args:"#tag",desc:"Remove a memory permanently"},{cmd:"view",args:"#tag",desc:"Read a memory in the viewer"},{cmd:"read",args:"#tag1 #tag2 ...",desc:"Send memory content to the agent — chat stays clean"},{cmd:"doc",args:"#tag",desc:"AI synthesizes the full conversation into a document"},{cmd:"link",args:"#tag path/to/doc",desc:"Link a memory to a NORTHSTAR or external document"},{cmd:"[instruct]",args:"",desc:"Show this command reference"}];function Aoe(){var j;const t=k(N=>N.keeperEditing),s=k(N=>N.setKeeperEditing),n=k(N=>N.saveKeeperItem),a=k(N=>N.updateKeeperItem),r=k(N=>N.activeView),[l,c]=p.useState(""),[A,f]=p.useState(""),x=p.useRef(null),h=!!t&&r!=="memory";p.useEffect(()=>{t&&(c(t.tag||""),f(t.content||""))},[t]),p.useEffect(()=>{h&&x.current&&setTimeout(()=>{var N;return(N=x.current)==null?void 0:N.focus()},100)},[h]);const g=N=>{N||s(null)},O=async()=>{!l.trim()||t!=null&&t.readOnly||(t!=null&&t.isNew?await n(l.trim(),A):await a(l.trim(),A),s(null))},v=N=>{N.key==="s"&&(N.metaKey||N.ctrlKey)&&(N.preventDefault(),O())};if(!t)return null;const b=t.readOnly,y=t.isNew,B=b?`#${t.tag}`:y?"New Memory":`Edit #${t.tag}`;return e.jsx(Dt,{open:h,onOpenChange:g,children:e.jsx(Ht,{title:B,description:"Memory content",className:"max-w-2xl",children:e.jsxs("div",{className:"p-5 space-y-4",onKeyDown:v,children:[y&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-text-2 mb-1.5",children:"Tag"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-sm text-text-3",children:"#"}),e.jsx("input",{type:"text",value:l,onChange:N=>c(N.target.value.replace(/[^a-zA-Z0-9/_-]/g,"").toLowerCase()),placeholder:"project/feature-name",className:"flex-1 px-2 py-1.5 text-sm font-mono rounded-md bg-surface-0 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"})]})]}),e.jsx("textarea",{ref:x,value:A,onChange:N=>!b&&f(N.target.value),readOnly:b,rows:16,className:"w-full px-3 py-2 text-sm font-mono leading-relaxed rounded-md bg-surface-0 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent resize-y",placeholder:"Write your thoughts, ideas, context..."}),e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[b?e.jsx("p",{className:"text-2xs text-text-4",children:"Read-only view"}):e.jsxs("p",{className:"text-2xs text-text-4",children:[(j=navigator.platform)!=null&&j.includes("Mac")?"Cmd":"Ctrl","+S to save"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>s(null),children:b?"Close":"Cancel"}),!b&&e.jsxs(Oe,{variant:"primary",size:"sm",onClick:O,disabled:!l.trim(),children:[e.jsx(To,{size:14})," Save"]})]})]})]})})})}function doe(){const t=k(n=>n.keeperInstructOpen);return k(n=>n.activeView)==="memory"?null:e.jsx(Dt,{open:t,onOpenChange:n=>k.setState({keeperInstructOpen:n}),children:e.jsx(Ht,{title:"Keeper Commands",description:"Memory system command reference",className:"max-w-lg",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx("p",{className:"text-xs text-text-2 leading-relaxed",children:"Type these commands in any agent chat to manage your tagged memories. Commands are intercepted by Keeper — the agent never sees them."}),e.jsx("div",{className:"space-y-1.5",children:coe.map(n=>e.jsxs("div",{className:"flex items-start gap-3 py-1.5 border-b border-border-subtle last:border-0",children:[e.jsxs("div",{className:"flex-shrink-0 flex items-center gap-1",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-accent/15 text-accent font-mono text-xs font-semibold",children:n.cmd}),n.args&&e.jsx("span",{className:"text-xs text-text-3 font-mono",children:n.args})]}),e.jsx("span",{className:"text-xs text-text-3 pt-0.5",children:n.desc})]},n.cmd))}),e.jsxs("div",{className:"pt-2 space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold text-text-1",children:"Tag Hierarchy"}),e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed",children:["Use ",e.jsx("span",{className:"font-mono text-accent",children:"/"})," for nesting: ",e.jsx("span",{className:"font-mono text-accent",children:"#groove/memory-system"}),". Pull a parent to get all children."]}),e.jsx("h3",{className:"text-xs font-semibold text-text-1",children:"Memory Types"}),e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed",children:[e.jsx("span",{className:"font-semibold",children:"Manual"})," — you write via [save]/[append]/[update]. ",e.jsx("span",{className:"font-semibold",children:"Doc"})," — AI writes via [doc]. Both editable."]})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>k.setState({keeperInstructOpen:!1}),children:"Close"})})]})})})}function uoe(){return e.jsxs(e.Fragment,{children:[e.jsx(Aoe,{}),e.jsx(doe,{})]})}function foe({onSelect:t,onClose:s}){const n=p.useRef(null),a=k(f=>f.agents),r=k(f=>f.teams);p.useEffect(()=>{function f(h){n.current&&!n.current.contains(h.target)&&s()}function x(h){h.key==="Escape"&&s()}return document.addEventListener("mousedown",f),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",x)}},[s]);const l=a.filter(f=>f.status==="running"||f.status==="starting"),c=a.filter(f=>f.status!=="running"&&f.status!=="starting");function A(f){const x=r.find(h=>h.id===f);return(x==null?void 0:x.name)||"Default"}return e.jsxs("div",{ref:n,className:"absolute bottom-full right-0 mb-1 z-50 min-w-[220px] max-h-[300px] overflow-y-auto py-1 bg-surface-2 border border-border rounded-lg shadow-xl",children:[l.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-1 text-2xs text-text-4 font-sans font-medium uppercase tracking-wider",children:"Active"}),l.map(f=>e.jsxs("button",{onClick:()=>t(f.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-5 cursor-pointer transition-colors text-left",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-success flex-shrink-0"}),e.jsx("span",{className:"truncate flex-1",children:f.name}),e.jsx("span",{className:"text-2xs text-text-4",children:A(f.teamId)})]},f.id))]}),c.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-1 text-2xs text-text-4 font-sans font-medium uppercase tracking-wider",children:l.length>0?"Other":"Agents"}),c.slice(0,10).map(f=>e.jsxs("button",{onClick:()=>t(f.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs font-sans text-text-2 hover:bg-surface-5 cursor-pointer transition-colors text-left",children:[e.jsx("span",{className:G("w-1.5 h-1.5 rounded-full flex-shrink-0",f.status==="completed"?"bg-accent":f.status==="crashed"?"bg-danger":"bg-text-4")}),e.jsx("span",{className:"truncate flex-1",children:f.name}),e.jsx("span",{className:"text-2xs text-text-4",children:A(f.teamId)})]},f.id))]}),a.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-text-4 font-sans text-center",children:"No agents available"})]})}function xoe({children:t,height:s,onHeightChange:n,visible:a,fullHeight:r,tabs:l,activeTab:c,onSelectTab:A,onAddTab:f,onCloseTab:x,onToggleFullHeight:h,onMinimize:g,onClose:O,onRenameTab:v,selectedText:b}){const y=p.useRef(!1),[B,j]=p.useState(null),[N,T]=p.useState(""),[U,E]=p.useState(!1),S=p.useRef(0),C=p.useRef(0),F=k(M=>M.detailPanel),R=k(M=>M.workspaceAgentId),I=(F==null?void 0:F.type)==="agent"?F.agentId:R||null,Y=k(M=>M.agents),W=k(M=>M.attachSnippet),te=Y.find(M=>M.id===I),V=b&&b.trim().length>0,_=p.useCallback(M=>{if(r)return;M.preventDefault(),y.current=!0,S.current=M.clientY,C.current=s;function L(z){if(!y.current)return;const ae=S.current-z.clientY,ce=Math.min(Math.max(C.current+ae,120),600);n(ce)}function oe(){y.current=!1,document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",oe)}document.addEventListener("mousemove",L),document.addEventListener("mouseup",oe)},[s,n,r]);function P(M){!M||!(b!=null&&b.trim())||(E(!1),W({type:"terminal",code:b.trim()}),k.getState().selectAgent(M))}function K(){I?P(I):E(!0)}const H=l||[{id:"default",label:"Terminal"}];return e.jsxs("div",{className:G("flex flex-col border-t border-border bg-surface-0 relative",!a&&"hidden"),style:a?r?{flex:1,minHeight:0}:{height:s,flexShrink:0}:{height:0},children:[!r&&e.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 cursor-row-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:_}),e.jsxs("div",{className:"flex items-center h-9 bg-surface-1 border-b border-border flex-shrink-0 pl-0 pr-3",children:[e.jsxs("div",{className:"flex items-center gap-0 flex-1 min-w-0 overflow-x-auto scrollbar-none h-full",children:[H.map(M=>e.jsxs("button",{onClick:()=>A==null?void 0:A(M.id),onDoubleClick:()=>{j(M.id),T(M.label)},className:G("inline-flex items-center gap-1.5 px-3 h-full text-[11px] font-medium font-sans cursor-pointer select-none transition-colors duration-100 flex-shrink-0",M.id===c?"text-text-0 bg-surface-3":"text-text-2 hover:text-text-0 hover:bg-surface-5/50"),children:[e.jsx(Nr,{size:11}),B===M.id?e.jsx("input",{className:"bg-transparent border border-border rounded px-1 text-[11px] text-text-0 outline-none w-20 font-sans",value:N,onChange:L=>T(L.target.value),onBlur:()=>{N.trim()&&(v==null||v(M.id,N.trim())),j(null)},onKeyDown:L=>{L.key==="Enter"&&(N.trim()&&(v==null||v(M.id,N.trim())),j(null)),L.key==="Escape"&&j(null)},autoFocus:!0,onClick:L=>L.stopPropagation()}):e.jsx("span",{className:"truncate max-w-[100px]",children:M.label}),H.length>1&&e.jsx("button",{onClick:L=>{L.stopPropagation(),x==null||x(M.id)},className:"ml-1 p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(De,{size:9})})]},M.id)),e.jsx("button",{onClick:f,className:"flex items-center justify-center w-6 h-6 text-text-3 hover:text-text-0 hover:bg-surface-5/50 rounded cursor-pointer transition-colors flex-shrink-0 ml-1",title:"New terminal",children:e.jsx(At,{size:11})})]}),e.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0 ml-2",children:[V&&e.jsxs("div",{className:"relative flex items-center",children:[e.jsx(it,{content:I?`Send to ${(te==null?void 0:te.name)||"agent"}`:"Send to agent",side:"top",children:e.jsx("button",{onClick:K,className:G("flex items-center gap-1.5 px-2 py-1 rounded text-xs font-sans cursor-pointer transition-colors mr-1","bg-accent/15 text-accent hover:bg-accent/25 disabled:opacity-50"),children:I?e.jsxs(e.Fragment,{children:[e.jsx(ra,{size:11}),e.jsx("span",{className:"text-2xs max-w-[80px] truncate",children:(te==null?void 0:te.name)||"Agent"})]}):e.jsxs(e.Fragment,{children:[e.jsx(mn,{size:11}),e.jsx("span",{className:"text-2xs",children:"Agent"}),e.jsx(ft,{size:9})]})})}),!I&&V&&e.jsx(it,{content:"Pick agent",side:"top",children:e.jsx("button",{onClick:()=>E(!U),className:"p-1 rounded text-text-3 hover:text-accent hover:bg-accent/10 cursor-pointer transition-colors mr-1",children:e.jsx(ft,{size:10})})}),U&&e.jsx(foe,{onSelect:M=>P(M),onClose:()=>E(!1)})]}),r?e.jsx("button",{onClick:g,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Restore",children:e.jsx(QM,{size:12})}):e.jsx("button",{onClick:h,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Maximize",children:e.jsx(Bb,{size:12})}),e.jsx("button",{onClick:O,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Close terminal",children:e.jsx(De,{size:12})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 pl-2 pt-1",children:t})]})}const moe={background:"#1a1e25",foreground:"#c8ccd4",cursor:"#33afbc",cursorAccent:"#1a1e25",selectionBackground:"rgba(51, 175, 188, 0.3)",selectionForeground:"#ffffff",black:"#1a1e25",red:"#e06c75",green:"#4ae168",yellow:"#e5c07b",blue:"#61afef",magenta:"#c678dd",cyan:"#33afbc",white:"#abb2bf",brightBlack:"#5c6370",brightRed:"#f07178",brightGreen:"#4ae168",brightYellow:"#e5c07b",brightBlue:"#61afef",brightMagenta:"#c678dd",brightCyan:"#56b6c2",brightWhite:"#ffffff"};let Lg=0,hoe=0;function poe({tabId:t,visible:s,registerKill:n,onSelectionChange:a}){const r=p.useRef(null),l=p.useRef(null),c=p.useRef(null),A=p.useRef(null),f=p.useRef(null),x=p.useRef(!1),h=p.useRef(s),g=p.useRef({cols:0,rows:0});return p.useEffect(()=>{n==null||n(t,()=>{const O=k.getState().ws;(O==null?void 0:O.readyState)===WebSocket.OPEN&&A.current&&O.send(JSON.stringify({type:"terminal:kill",id:A.current}))})},[t,n]),p.useEffect(()=>{if(!r.current||x.current)return;x.current=!0;const O=new I3({theme:moe,fontFamily:"'SF Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace",fontSize:12,lineHeight:1.1,letterSpacing:0,cursorBlink:!0,cursorStyle:"bar",cursorWidth:1,scrollback:1e4,allowProposedApi:!0,minimumContrastRatio:1,drawBoldTextInBrightColors:!0,fontWeight:"400",fontWeightBold:"600",overviewRulerWidth:0}),v=new _3;O.loadAddon(v),O.loadAddon(new z3),O.open(r.current),l.current=O,c.current=v,O.onSelectionChange(()=>{const j=O.getSelection();a==null||a(j||"")});let b=0;function y(){b++;const j=k.getState().ws;if(!j||j.readyState!==WebSocket.OPEN){b<20&&setTimeout(y,500);return}const N=`spawn-${++hoe}`;j.send(JSON.stringify({type:"terminal:spawn",cols:O.cols,rows:O.rows,requestId:N}));function T(U){let E;try{E=JSON.parse(U.data)}catch{return}E.type==="terminal:spawned"&&E.requestId===N&&!A.current?A.current=E.id:E.type==="terminal:output"&&E.id===A.current?O.write(E.data):E.type==="terminal:exit"&&E.id===A.current&&(O.write(`\r
1024
1024
  \x1B[90m[session ended]\x1B[0m\r
1025
1025
  `),A.current=null)}j.addEventListener("message",T),f.current={ws:j,handler:T},O.onData(U=>{const E=k.getState().ws;(E==null?void 0:E.readyState)===WebSocket.OPEN&&A.current&&E.send(JSON.stringify({type:"terminal:input",id:A.current,data:U}))}),O.onResize(({cols:U,rows:E})=>{if(U===g.current.cols&&E===g.current.rows||U<2||E<2)return;g.current={cols:U,rows:E};const S=k.getState().ws;(S==null?void 0:S.readyState)===WebSocket.OPEN&&A.current&&S.send(JSON.stringify({type:"terminal:resize",id:A.current,rows:E,cols:U}))})}requestAnimationFrame(()=>{try{v.fit()}catch{}y()});const B=new ResizeObserver(()=>{h.current&&requestAnimationFrame(()=>{try{v.fit()}catch{}})});return B.observe(r.current),()=>{B.disconnect(),f.current&&f.current.ws.removeEventListener("message",f.current.handler),O.dispose(),c.current=null,x.current=!1}},[]),p.useEffect(()=>{h.current=s,s&&c.current&&requestAnimationFrame(()=>{try{c.current.fit()}catch{}})},[s]),e.jsx("div",{ref:r,className:"w-full h-full overflow-hidden",style:{display:s?"block":"none"}})}function goe(){const t=k(j=>j.terminalVisible),s=k(j=>j.terminalHeight),n=k(j=>j.setTerminalVisible),a=k(j=>j.setTerminalHeight),r=k(j=>j.terminalFullHeight),l=k(j=>j.setTerminalFullHeight),[c,A]=p.useState([{id:"term-0",label:"Terminal"}]),[f,x]=p.useState("term-0"),[h,g]=p.useState(""),O=p.useRef({}),v=p.useCallback((j,N)=>{O.current[j]=N},[]),b=p.useCallback(()=>{Lg++;const j=`term-${Lg}`;A(N=>[...N,{id:j,label:`Terminal ${Lg+1}`}]),x(j)},[]),y=p.useCallback((j,N)=>{A(T=>T.map(U=>U.id===j?{...U,label:N}:U))},[]),B=p.useCallback(j=>{var N,T;(T=(N=O.current)[j])==null||T.call(N),delete O.current[j],A(U=>{const E=U.filter(S=>S.id!==j);if(E.length===0)return n(!1),U;if(f===j){const S=U.findIndex(F=>F.id===j),C=E[Math.min(S,E.length-1)];x(C.id)}return E})},[f,n]);return e.jsx(xoe,{visible:t,height:s,onHeightChange:a,fullHeight:r,tabs:c,activeTab:f,onSelectTab:x,onAddTab:b,onCloseTab:B,onRenameTab:y,onToggleFullHeight:()=>l(!0),onMinimize:()=>l(!1),onClose:()=>n(!1),selectedText:h,children:c.map(j=>e.jsx(poe,{tabId:j.id,visible:j.id===f,registerKill:v,onSelectionChange:j.id===f?g:void 0},j.id))})}class Sf extends lo.Component{constructor(s){super(s),this.state={error:null}}static getDerivedStateFromError(s){return{error:s}}render(){return this.state.error?e.jsxs("div",{className:"h-screen bg-surface-0 p-10 font-sans",children:[e.jsx("h2",{className:"text-lg font-semibold text-text-0 mb-4",children:"Groove — Render Error"}),e.jsx("pre",{className:"text-sm text-danger whitespace-pre-wrap mb-4",children:this.state.error.message}),e.jsx("pre",{className:"text-xs text-text-3 whitespace-pre-wrap",children:this.state.error.stack}),e.jsx("button",{onClick:()=>this.setState({error:null}),className:"mt-6 px-4 py-2 bg-accent text-surface-0 rounded-md font-medium text-sm cursor-pointer",children:"Try Again"})]}):this.props.children}}function Ooe(){const t=k(l=>l.activeView),s=k(l=>l.detailPanel);k(l=>l.agents);const n=k(l=>l.networkUnlocked);let a;switch(t){case"agents":a=e.jsx(Tg,{});break;case"editor":a=e.jsx(_ee,{});break;case"dashboard":a=e.jsx(vte,{});break;case"marketplace":a=e.jsx(Zte,{});break;case"teams":a=e.jsx(use,{});break;case"models":a=e.jsx(Pse,{});break;case"model-lab":a=e.jsx(zne,{});break;case"federation":a=e.jsx(Jse,{});break;case"settings":a=e.jsx(Bse,{});break;case"chat":a=e.jsx(ire,{});break;case"fleet":a=e.jsx(Ire,{});break;case"memory":a=e.jsx(xre,{});break;case"network":a=n?e.jsx(Fae,{}):e.jsx(Tg,{});break;default:a=e.jsx(Tg,{})}let r=null;if(s)switch(s.type){case"agent":{r=e.jsx(roe,{});break}case"journalist":r=e.jsx(loe,{});break;case"spawn":r=null;break}return e.jsxs(lee,{detailContent:r,terminalContent:e.jsx(goe,{}),children:[a,e.jsx(ioe,{})]})}function boe(){const t=k(n=>n.remoteHomedir),s=k(n=>n.setProjectDir);return e.jsxs("div",{className:"fixed inset-0 z-40 bg-surface-0 flex flex-col items-center justify-center gap-3",children:[e.jsx("img",{src:"/favicon.png",alt:"",className:"w-10 h-10 opacity-60"}),e.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Connected — choose a project directory to continue"}),e.jsx(Ac,{open:!0,onOpenChange:()=>{},currentPath:t||"/home",homePath:t,onSelect:n=>s(n),mandatory:!0})]})}function voe(){return e.jsxs("div",{className:"h-screen bg-surface-0 flex flex-col items-center justify-center gap-4",children:[e.jsx("img",{src:"/favicon.png",alt:"",className:"w-10 h-10 opacity-60 animate-pulse"}),e.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Connecting..."})]})}function yoe(){const t=k(c=>c.connect),s=k(c=>c.hydrated),n=k(c=>c.tunneled),a=k(c=>c.onboardingComplete),r=k(c=>c.showProjectPicker);p.useEffect(()=>{t()},[t]),p.useEffect(()=>{async function c(){var x;if((x=window.groove)!=null&&x.getInstanceInfo){const h=await window.groove.getInstanceInfo();if(h!=null&&h.name){document.title=`${h.name} — Groove`;return}}const f=new URLSearchParams(window.location.search).get("instance");if(f){const h=f.replace(/[\x00-\x1F]/g,"").slice(0,50);document.title=`${h} — Groove`}else n?document.title="Remote — Groove":document.title="Groove"}c()},[n]);const l=p.useMemo(()=>{var c;return(c=window.groove)!=null&&c.openFolder?[{key:"o",meta:!0,handler:()=>window.groove.openFolder()}]:[]},[]);return aN(l),s?a?r&&n?e.jsx(Sf,{children:e.jsx(boe,{})}):r?e.jsxs(Sf,{children:[e.jsx(wee,{}),e.jsx(gQ,{})]}):e.jsxs(Sf,{children:[e.jsx(Ooe,{}),e.jsx(gQ,{}),e.jsx(yee,{}),e.jsx(uoe,{})]}):e.jsx(Sf,{children:e.jsx(bee,{})}):e.jsx(voe,{})}Z3.createRoot(document.getElementById("root")).render(e.jsx(p.StrictMode,{children:e.jsx(yoe,{})}));