groove-dev 0.27.89 → 0.27.91

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.
Files changed (29) hide show
  1. package/moe-training/client/parsers/claude-code.js +0 -2
  2. package/moe-training/client/session-attestation.js +2 -1
  3. package/moe-training/client/trajectory-capture.js +6 -0
  4. package/moe-training/test/client/parsers/claude-code.test.js +2 -2
  5. package/node_modules/@groove-dev/cli/package.json +1 -1
  6. package/node_modules/@groove-dev/daemon/package.json +1 -1
  7. package/node_modules/@groove-dev/daemon/src/api.js +16 -9
  8. package/node_modules/@groove-dev/daemon/src/conversations.js +32 -6
  9. package/node_modules/@groove-dev/daemon/src/providers/claude-code.js +1 -1
  10. package/node_modules/@groove-dev/daemon/src/providers/codex.js +1 -1
  11. package/node_modules/@groove-dev/daemon/src/providers/gemini.js +1 -1
  12. package/node_modules/@groove-dev/daemon/src/providers/grok.js +2 -2
  13. package/node_modules/@groove-dev/gui/dist/assets/{index-BKD8JAsV.js → index-MLIZRMj1.js} +1 -1
  14. package/node_modules/@groove-dev/gui/dist/index.html +1 -1
  15. package/node_modules/@groove-dev/gui/package.json +1 -1
  16. package/node_modules/@groove-dev/gui/src/components/chat/chat-view.jsx +1 -3
  17. package/package.json +1 -1
  18. package/packages/cli/package.json +1 -1
  19. package/packages/daemon/package.json +1 -1
  20. package/packages/daemon/src/api.js +16 -9
  21. package/packages/daemon/src/conversations.js +32 -6
  22. package/packages/daemon/src/providers/claude-code.js +1 -1
  23. package/packages/daemon/src/providers/codex.js +1 -1
  24. package/packages/daemon/src/providers/gemini.js +1 -1
  25. package/packages/daemon/src/providers/grok.js +2 -2
  26. package/packages/gui/dist/assets/{index-BKD8JAsV.js → index-MLIZRMj1.js} +1 -1
  27. package/packages/gui/dist/index.html +1 -1
  28. package/packages/gui/package.json +1 -1
  29. package/packages/gui/src/components/chat/chat-view.jsx +1 -3
@@ -8637,6 +8637,6 @@ ${S.join(`
8637
8637
  `)});continue}const c=o.match(/^(#{1,6})\s+(.+)/);if(c){n.push({type:"heading",level:c[1].length,text:c[2]}),s++;continue}if(/^(-{3,}|_{3,}|\*{3,})$/.test(o.trim())){n.push({type:"hr"}),s++;continue}if(o.startsWith("> ")){const d=[o.slice(2)];for(s++;s<a.length&&a[s].startsWith("> ");)d.push(a[s].slice(2)),s++;n.push({type:"blockquote",text:d.join(`
8638
8638
  `)});continue}if(/^[-*+]\s/.test(o)){const d=[o.replace(/^[-*+]\s/,"")];for(s++;s<a.length&&/^[-*+]\s/.test(a[s]);)d.push(a[s].replace(/^[-*+]\s/,"")),s++;n.push({type:"ul",items:d});continue}if(/^\d+\.\s/.test(o)){const d=[o.replace(/^\d+\.\s/,"")];for(s++;s<a.length&&/^\d+\.\s/.test(a[s]);)d.push(a[s].replace(/^\d+\.\s/,"")),s++;n.push({type:"ol",items:d});continue}if(o.includes("|")&&s+1<a.length&&/^\|?\s*[-:]+/.test(a[s+1])){const d=o.split("|").map(f=>f.trim()).filter(Boolean);s+=2;const h=[];for(;s<a.length&&a[s].includes("|");)h.push(a[s].split("|").map(f=>f.trim()).filter(Boolean)),s++;n.push({type:"table",headers:d,rows:h});continue}if(o.trim()===""){s++;continue}const l=[o];for(s++;s<a.length&&a[s].trim()!==""&&!a[s].startsWith("```")&&!a[s].startsWith("#")&&!/^[-*+]\s/.test(a[s])&&!/^\d+\.\s/.test(a[s])&&!a[s].startsWith("> ")&&!/^(-{3,}|_{3,}|\*{3,})$/.test(a[s].trim());)l.push(a[s]),s++;n.push({type:"paragraph",text:l.join(`
8639
8639
  `)})}return n}function T1({text:e}){if(!e)return null;const a=e.split(/(```[\s\S]*?```|`[^`]+`|\*\*[^*]+\*\*|\*[^*]+\*|~~[^~]+~~|\[([^\]]+)\]\(([^)]+)\))/g);return t.jsx(t.Fragment,{children:a.map((n,s)=>{if(!n)return null;if(n.startsWith("`")&&n.endsWith("`")&&!n.startsWith("``"))return t.jsx("code",{className:"px-1.5 py-0.5 rounded bg-surface-0 text-xs font-mono text-accent",children:n.slice(1,-1)},s);if(n.startsWith("**")&&n.endsWith("**"))return t.jsx("strong",{className:"font-semibold text-text-0",children:n.slice(2,-2)},s);if(n.startsWith("*")&&n.endsWith("*")&&!n.startsWith("**"))return t.jsx("em",{className:"italic",children:n.slice(1,-1)},s);if(n.startsWith("~~")&&n.endsWith("~~"))return t.jsx("del",{className:"line-through text-text-3",children:n.slice(2,-2)},s);const o=n.match(/^\[([^\]]+)\]\(([^)]+)\)$/);return o?t.jsx("a",{href:o[2],target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline",children:o[1]},s):t.jsx("span",{children:n},s)})})}function Kqe({text:e}){const a=Wqe(e);return t.jsx("div",{className:"space-y-2",children:a.map((n,s)=>{switch(n.type){case"code":return t.jsx(Gqe,{language:n.language,code:n.code},s);case"heading":{const o=["text-lg font-bold","text-base font-bold","text-sm font-semibold","text-sm font-semibold","text-xs font-semibold","text-xs font-semibold"];return t.jsx("div",{className:q(o[n.level-1]||o[0],"text-text-0 font-sans mt-3 mb-1"),children:t.jsx(T1,{text:n.text})},s)}case"hr":return t.jsx("hr",{className:"border-border-subtle my-3"},s);case"blockquote":return t.jsx("div",{className:"border-l-2 border-accent/40 pl-3 py-1 text-sm text-text-2 italic font-sans",children:t.jsx(T1,{text:n.text})},s);case"ul":return t.jsx("ul",{className:"list-disc list-inside space-y-0.5 text-sm text-text-0 font-sans",children:n.items.map((o,c)=>t.jsx("li",{children:t.jsx(T1,{text:o})},c))},s);case"ol":return t.jsx("ol",{className:"list-decimal list-inside space-y-0.5 text-sm text-text-0 font-sans",children:n.items.map((o,c)=>t.jsx("li",{children:t.jsx(T1,{text:o})},c))},s);case"table":return t.jsx("div",{className:"overflow-x-auto my-2",children:t.jsxs("table",{className:"text-xs font-sans border-collapse w-full",children:[t.jsx("thead",{children:t.jsx("tr",{className:"border-b border-border",children:n.headers.map((o,c)=>t.jsx("th",{className:"px-3 py-1.5 text-left font-semibold text-text-0",children:o},c))})}),t.jsx("tbody",{children:n.rows.map((o,c)=>t.jsx("tr",{className:"border-b border-border-subtle",children:o.map((l,d)=>t.jsx("td",{className:"px-3 py-1.5 text-text-0",children:t.jsx(T1,{text:l})},d))},c))})]})},s);case"paragraph":return t.jsx("p",{className:"text-sm text-text-0 font-sans leading-relaxed whitespace-pre-wrap break-words",children:t.jsx(T1,{text:n.text})},s);default:return null}})})}function Yqe({msg:e}){return t.jsx("div",{className:"flex justify-end",children:t.jsxs("div",{className:"max-w-[85%]",children:[t.jsx("div",{className:"px-3.5 py-2.5 rounded-2xl rounded-br-md bg-info/10 border border-info/15",children:t.jsx("p",{className:"text-sm text-text-0 font-sans whitespace-pre-wrap break-words leading-relaxed",children:e.text})}),t.jsx("div",{className:"text-2xs text-text-4 font-sans mt-1 text-right",children:ht(e.timestamp)})]})})}function Jqe({msg:e,model:a,role:n}){const s=Zqe(e.text),o=a||"Assistant",c=n?n.charAt(0).toUpperCase()+n.slice(1):null;return t.jsxs("div",{className:"max-w-[85%]",children:[t.jsxs("div",{className:"text-2xs font-sans mb-1 font-medium",children:[t.jsx("span",{className:"text-text-1",children:o}),c&&t.jsx("span",{className:"text-text-3 ml-1",children:c})]}),t.jsx("div",{className:"border-l-2 border-accent pl-3.5 py-1",children:t.jsx("div",{className:"text-sm text-text-1 font-sans whitespace-pre-wrap break-words leading-relaxed",children:t.jsx(Kqe,{text:s})})}),t.jsx("div",{className:"text-2xs text-text-4 font-sans mt-1",children:ht(e.timestamp)})]})}function eDe({msg:e}){return t.jsx("div",{className:"max-w-[85%]",children:t.jsxs("div",{className:"rounded-2xl rounded-tl-md bg-surface-1/80 border border-border-subtle overflow-hidden",children:[t.jsx("div",{className:"w-80 h-80 image-loading-shimmer flex items-center justify-center",children:t.jsxs("div",{className:"flex flex-col items-center gap-3",children:[t.jsx("div",{className:"w-10 h-10 rounded-full bg-surface-3/80 flex items-center justify-center",children:t.jsx(Pn,{size:18,className:"text-accent animate-pulse"})}),t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Generating image..."})]})}),e.prompt&&t.jsx("div",{className:"px-4 py-2.5 border-t border-border-subtle",children:t.jsxs("p",{className:"text-2xs text-text-3 font-sans italic truncate",children:['"',e.prompt,'"']})})]})})}function tDe({msg:e,onReply:a}){const[n,s]=y.useState(!1),[o,c]=y.useState(!1),l=y.useCallback(()=>{if(!e.imageUrl)return;const d=document.createElement("a");d.href=e.imageUrl,d.download=`groove-${e.model||"image"}-${Date.now()}.png`,document.body.appendChild(d),d.click(),document.body.removeChild(d)},[e.imageUrl,e.model]);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"max-w-[85%]",children:[e.model&&t.jsxs("div",{className:"text-2xs text-text-3 font-mono mb-1.5 font-medium flex items-center gap-1.5",children:[t.jsx(Pn,{size:10})," ",e.model]}),t.jsxs("div",{className:"rounded-2xl rounded-tl-md bg-surface-1/80 border border-border-subtle overflow-hidden",children:[t.jsxs("div",{className:"relative group",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[t.jsx("img",{src:e.imageUrl,alt:e.prompt||"Generated image",className:"max-w-full max-h-[480px] object-contain cursor-pointer",onClick:()=>s(!0)}),o&&t.jsxs("div",{className:"absolute top-2 right-2 flex gap-1.5",children:[t.jsx("button",{onClick:l,className:"w-8 h-8 rounded-lg bg-surface-0/90 backdrop-blur-sm border border-border-subtle flex items-center justify-center text-text-2 hover:text-accent hover:border-accent/30 transition-colors cursor-pointer",title:"Download",children:t.jsx(Oa,{size:14})}),t.jsx("button",{onClick:()=>s(!0),className:"w-8 h-8 rounded-lg bg-surface-0/90 backdrop-blur-sm border border-border-subtle flex items-center justify-center text-text-2 hover:text-accent hover:border-accent/30 transition-colors cursor-pointer",title:"Fullscreen",children:t.jsx(md,{size:14})}),t.jsx(uJ,{text:e.prompt||"",className:"h-8 rounded-lg bg-surface-0/90 backdrop-blur-sm border border-border-subtle text-text-2 hover:text-accent"})]})]}),t.jsxs("div",{className:"px-4 py-2.5 border-t border-border-subtle flex items-center gap-2",children:[t.jsxs("p",{className:"flex-1 text-2xs text-text-3 font-sans italic truncate",children:['"',e.prompt,'"']}),a&&t.jsxs("button",{onClick:()=>a(e),className:"text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer flex items-center gap-1 flex-shrink-0",children:[t.jsx(Et,{size:10})," Iterate"]})]})]}),t.jsx("div",{className:"text-2xs text-text-4 font-sans mt-1",children:ht(e.timestamp)})]}),n&&t.jsxs("div",{className:"fixed inset-0 z-[200] bg-surface-0/95 backdrop-blur-md flex items-center justify-center",onClick:()=>s(!1),children:[t.jsx("button",{onClick:()=>s(!1),className:"absolute top-4 right-4 w-10 h-10 rounded-full bg-surface-3 border border-border flex items-center justify-center text-text-2 hover:text-text-0 transition-colors cursor-pointer z-10",children:t.jsx(He,{size:18})}),t.jsx("div",{className:"absolute bottom-4 right-4 flex gap-2 z-10",children:t.jsxs("button",{onClick:d=>{d.stopPropagation(),l()},className:"h-9 px-4 rounded-lg bg-surface-3 border border-border flex items-center gap-2 text-xs font-sans text-text-1 hover:text-accent hover:border-accent/30 transition-colors cursor-pointer",children:[t.jsx(Oa,{size:14})," Download"]})}),t.jsx("img",{src:e.imageUrl,alt:e.prompt||"Generated image",className:"max-w-[90vw] max-h-[90vh] object-contain rounded-lg shadow-2xl",onClick:d=>d.stopPropagation()}),e.prompt&&t.jsx("div",{className:"absolute bottom-4 left-4 max-w-md px-4 py-2 rounded-lg bg-surface-3/90 backdrop-blur-sm border border-border-subtle z-10",children:t.jsxs("p",{className:"text-xs text-text-2 font-sans italic",children:['"',e.prompt,'"']})})]})]})}function aDe({msg:e}){return t.jsx("div",{className:"flex justify-center py-1",children:t.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1 rounded-full bg-surface-4/50",children:[t.jsx(vr,{size:10,className:"text-text-4"}),t.jsx("span",{className:"text-2xs text-text-3 font-sans",children:e.text})]})})}function nDe(){return t.jsx("div",{className:"flex flex-col items-center justify-center h-full text-center py-16",children:t.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Send a message to start"})})}function sDe(){const[e,a]=y.useState(0),[n,s]=y.useState(!0);return y.useEffect(()=>{const o=setInterval(()=>{s(!1),setTimeout(()=>{a(c=>(c+1)%tX.length),s(!0)},250)},2800);return()=>clearInterval(o)},[]),t.jsxs("div",{className:"flex items-center gap-2.5 ml-8 py-1",children:[t.jsx("div",{className:"relative w-3.5 h-3.5 flex-shrink-0",children:t.jsx("span",{className:"absolute inset-0 rounded-full border border-transparent border-t-accent animate-spin",style:{animationDuration:"0.9s"}})}),t.jsx("span",{className:"text-2xs font-sans text-text-3 transition-opacity duration-[250ms]",style:{opacity:n?1:0},children:tX[e]})]})}function rDe({messages:e,isStreaming:a,model:n,mode:s,onImageReply:o,role:c}){const l=y.useRef(null),d=y.useRef(!0);return y.useEffect(()=>{const h=l.current;if(!h)return;function f(){d.current=h.scrollHeight-h.scrollTop-h.clientHeight<50}return h.addEventListener("scroll",f),()=>h.removeEventListener("scroll",f)},[]),y.useEffect(()=>{d.current&&l.current&&(l.current.scrollTop=l.current.scrollHeight)},[e==null?void 0:e.length,a]),!e||e.length===0?t.jsx("div",{ref:l,className:"flex-1 overflow-y-auto",children:t.jsx(nDe,{})}):t.jsxs("div",{ref:l,className:"flex-1 overflow-y-auto px-6 py-5 space-y-5",children:[e.map((h,f)=>h.type==="image-loading"?t.jsx(eDe,{msg:h},f):h.type==="image"?t.jsx(tDe,{msg:h,onReply:o},f):h.from==="user"?t.jsx(Yqe,{msg:h},f):h.from==="system"?t.jsx(aDe,{msg:h},f):t.jsx(Jqe,{msg:h,model:n,role:c},f)),a&&(s==="agent"?t.jsx(vz,{className:"py-1"}):t.jsx(sDe,{}))]})}const oDe=[{value:"none",label:"None"},{value:"low",label:"Low"},{value:"medium",label:"Med"},{value:"high",label:"High"},{value:"xhigh",label:"XHigh"}],iDe=[{value:"low",label:"Concise"},{value:"medium",label:"Normal"}];function aX({onSend:e,onStop:a,sending:n,streaming:s,disabled:o,isImageModel:c,currentModel:l,replyContext:d,onClearReply:h,role:f,isCodex:g,reasoningEffort:x,onReasoningEffortChange:m,verbosity:v,onVerbosityChange:b,mode:C,onModeChange:j}){const[w,Q]=y.useState(""),S=y.useRef(null),_=y.useRef(null),F=y.useCallback(()=>{const G=S.current;G&&(G.style.height="auto",G.style.height=Math.min(G.scrollHeight,400)+"px")},[]);y.useEffect(()=>{F()},[w,F]),y.useEffect(()=>{!o&&S.current&&S.current.focus()},[o]);function B(){const G=w.trim();!G||n||o||(e(G),Q(""),S.current&&(S.current.style.height="auto"))}function M(G){G.key==="Enter"&&!G.shiftKey&&(G.preventDefault(),B())}function L(G){const E=Array.from(G.target.files||[]);if(E.length===0)return;const P=E.map(I=>I.name).join(", ");Q(I=>I+(I?`
8640
- `:"")+`[Attached: ${P}]`),G.target.value=""}const T=s||n,U=w.trim()&&!n&&!o,Y=C||"api",J=o?"Select a model to start chatting...":c?"Describe the image you want to generate...":f?`Ask your ${f}...`:"Send a message...";return t.jsxs("div",{className:"border-t border-border-subtle px-4 py-3 bg-surface-1",children:[d&&t.jsxs("div",{className:"flex items-center gap-2 mb-2 px-3 py-2 rounded-lg bg-accent/5 border border-accent/15",children:[t.jsx(Pn,{size:12,className:"text-accent flex-shrink-0"}),t.jsxs("span",{className:"flex-1 text-2xs text-text-2 font-sans truncate",children:['Iterating: "',d.prompt,'"']}),t.jsx("button",{onClick:h,className:"text-text-4 hover:text-text-1 cursor-pointer flex-shrink-0",children:t.jsx(Fo,{size:10})})]}),t.jsx("textarea",{ref:S,value:w,onChange:G=>Q(G.target.value),onKeyDown:M,placeholder:J,disabled:o,rows:1,className:q("w-full resize-y rounded-xl px-4 py-2.5 text-sm","bg-surface-0 border text-text-0 font-sans","placeholder:text-text-4","focus:outline-none focus:ring-1","min-h-[40px]","border-border focus:ring-accent/40","disabled:opacity-50 disabled:cursor-not-allowed")}),t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx("input",{ref:_,type:"file",multiple:!0,accept:".pdf,.png,.jpg,.jpeg,.gif,.svg,.csv,.txt,.md,.json,.yaml,.yml,.docx,.pptx,.xlsx",onChange:L,className:"hidden"}),t.jsx("button",{onClick:()=>{var G;return(G=_.current)==null?void 0:G.click()},disabled:o,className:"w-8 h-8 flex items-center justify-center rounded-lg text-text-4 hover:text-text-1 hover:bg-surface-3 transition-colors cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed flex-shrink-0",title:"Attach file",children:t.jsx(gd,{size:14})}),t.jsxs("div",{className:"flex items-center h-7 rounded-lg bg-surface-3 border border-border-subtle p-0.5",children:[t.jsxs("button",{onClick:()=>j==null?void 0:j("api"),className:q("flex items-center gap-1 h-6 px-2 rounded-md text-2xs font-semibold font-sans transition-colors cursor-pointer",Y==="api"?"bg-accent/15 text-accent border border-accent/25":"text-text-3 hover:text-text-1"),title:"Lightweight — fast and cheap, no tools",children:[t.jsx(wt,{size:11})," Chat"]}),t.jsxs("button",{onClick:()=>j==null?void 0:j("agent"),className:q("flex items-center gap-1 h-6 px-2 rounded-md text-2xs font-semibold font-sans transition-colors cursor-pointer",Y==="agent"?"bg-purple/15 text-purple border border-purple/25":"text-text-3 hover:text-text-1"),title:"Full agent — tools, files, session resume",children:[t.jsx(ud,{size:11})," Agent"]})]}),l&&t.jsxs("div",{className:q("flex items-center gap-1 h-6 px-2 rounded-md text-2xs font-mono border",c?"bg-purple/8 border-purple/20 text-purple":"bg-surface-3 border-border-subtle text-text-3"),children:[c&&t.jsx(Pn,{size:9}),t.jsx("span",{className:"max-w-[80px] truncate",children:eF(l)})]}),g&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex items-center h-6 rounded-md bg-surface-3 border border-border-subtle p-0.5",children:oDe.map(G=>t.jsx("button",{onClick:()=>m==null?void 0:m(G.value),className:q("h-5 px-1.5 rounded text-2xs font-semibold font-sans transition-colors cursor-pointer",x===G.value?"bg-accent/15 text-accent":"text-text-4 hover:text-text-1"),title:`Reasoning: ${G.label}`,children:G.label},G.value))}),t.jsx("div",{className:"flex items-center h-6 rounded-md bg-surface-3 border border-border-subtle p-0.5",children:iDe.map(G=>t.jsx("button",{onClick:()=>b==null?void 0:b(G.value),className:q("h-5 px-1.5 rounded text-2xs font-semibold font-sans transition-colors cursor-pointer",v===G.value?"bg-accent/15 text-accent":"text-text-4 hover:text-text-1"),title:`Verbosity: ${G.label}`,children:G.label},G.value))})]}),t.jsx("div",{className:"flex-1"}),T?t.jsx("button",{onClick:a,className:"w-8 h-8 flex items-center justify-center rounded-lg bg-danger/80 text-white hover:bg-danger transition-all cursor-pointer shadow-lg shadow-danger/20 flex-shrink-0",title:"Stop generation",children:t.jsx(Fo,{size:14,fill:"currentColor"})}):t.jsx("button",{onClick:B,disabled:!U,className:q("w-8 h-8 flex items-center justify-center rounded-lg transition-all cursor-pointer flex-shrink-0","disabled:opacity-20 disabled:cursor-not-allowed",U?"bg-accent/15 text-accent hover:bg-accent/25 border border-accent/25":"bg-surface-4 text-text-4"),children:n?t.jsx(Le,{size:14,className:"animate-spin"}):t.jsx(Ga,{size:14})})]})]})}function cDe({onNewChat:e}){return t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"text-center space-y-4",children:[t.jsx("h1",{className:"text-lg font-semibold text-text-1 font-sans",children:"Groove Chat"}),t.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Every provider, every model, full project context."}),t.jsxs("button",{onClick:e,className:"inline-flex items-center gap-2 h-9 px-5 rounded-lg bg-accent/15 text-accent text-sm font-semibold font-sans hover:bg-accent/25 transition-colors cursor-pointer border border-accent/20",children:[t.jsx(ut,{size:14}),"New Chat"]})]})})}function lDe(){const e=$(ie=>ie.conversations),a=$(ie=>ie.activeConversationId),n=$(ie=>ie.conversationMessages),s=$(ie=>ie.sendingMessage),o=$(ie=>ie.streamingConversationId),c=$(ie=>ie.createConversation);$(ie=>ie.setActiveConversation);const l=$(ie=>ie.sendChatMessage),d=$(ie=>ie.sendImageMessage),h=$(ie=>ie.stopAgent),f=$(ie=>ie.stopChatStreaming),g=$(ie=>ie.setConversationMode),x=$(ie=>ie.setConversationModel),m=$(ie=>ie.conversationRoles),v=$(ie=>ie.setConversationRole),b=$(ie=>ie.conversationReasoningEffort),C=$(ie=>ie.setConversationReasoningEffort),j=$(ie=>ie.conversationVerbosity),w=$(ie=>ie.setConversationVerbosity),[Q,S]=y.useState(!1),[_,F]=y.useState(null),B=a&&(m==null?void 0:m[a])||null,M=a&&(b==null?void 0:b[a])||"medium",L=a&&(j==null?void 0:j[a])||"medium",T=e.find(ie=>ie.id===a)||null,U=(T==null?void 0:T.provider)==="codex",Y=a?n[a]||[]:[],J=o===a&&s,G=T?oL(T.model):!1,E=y.useCallback(async(ie,ge)=>{const de=ie||"claude-code",me=ge||"claude-sonnet-4-6";try{await c(de,me,"api")}catch{}},[c]),P=y.useCallback(ie=>{a&&g(a,ie)},[a,g]),I=y.useCallback(ie=>{a&&v(a,ie)},[a,v]),H=y.useCallback(ie=>{if(a)if(G){const ge=_?`${ie} (iterating on: "${_.prompt}")`:ie;d(a,ge,{model:T.model}),F(null)}else l(a,ie)},[a,T,G,_,l,d]),V=y.useCallback(()=>{T&&(T.mode==="agent"&&T.agentId?h(T.agentId):f(a))},[T,a,h,f]),Z=y.useCallback(async ie=>{a?await x(a,ie.provider,ie.model):await E(ie.provider,ie.model)},[a,x,E]),R=y.useCallback(ie=>{F(ie)},[]),pe=y.useCallback(ie=>{a&&C(a,ie)},[a,C]),xe=y.useCallback(ie=>{a&&w(a,ie)},[a,w]),se=T?{provider:T.provider,model:T.model}:null;return t.jsxs("div",{className:"flex h-full bg-surface-0",children:[t.jsx("div",{className:q("flex-shrink-0 border-r border-accent/12 bg-surface-1 transition-all duration-200 overflow-hidden",Q?"w-0":"w-64"),children:t.jsx(Vqe,{onNewChat:()=>E()})}),t.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:T?t.jsxs(t.Fragment,{children:[t.jsx(Xqe,{conversation:T,model:se,onModelChange:Z,onModeChange:P,role:B,onRoleChange:I}),t.jsx(rDe,{messages:Y,isStreaming:J,model:T.model,mode:T.mode||"api",onImageReply:R,role:B}),t.jsx(aX,{onSend:H,onStop:V,sending:s,streaming:J,disabled:!1,isImageModel:G,currentModel:T.model,replyContext:_,onClearReply:()=>F(null),role:B,isCodex:U,reasoningEffort:M,onReasoningEffortChange:pe,verbosity:L,onVerbosityChange:xe,mode:(T==null?void 0:T.mode)||"api",onModeChange:P})]}):t.jsxs(t.Fragment,{children:[t.jsx(cDe,{onNewChat:()=>E()}),t.jsx(aX,{onSend:ie=>{E().then(()=>{setTimeout(()=>{const ge=$.getState().activeConversationId;ge&&l(ge,ie)},500)})},onStop:()=>{},sending:!1,streaming:!1,disabled:!1,isImageModel:!1,currentModel:null})]})})]})}function ADe(){return t.jsx(lDe,{})}function dDe(){return t.jsx(iW,{})}function Kp({options:e,value:a,onChange:n}){return t.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:e.map(s=>t.jsx("button",{onClick:()=>n(s.value),className:q("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",a===s.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:s.label},s.value))})}function Va({label:e,icon:a,children:n,description:s}){return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsxs("label",{className:"flex items-center gap-1.5 text-xs font-semibold text-text-1 font-sans",children:[a&&t.jsx(a,{size:13,className:"text-text-3"}),e]}),s&&t.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:s})]}),n]})}function uDe({agent:e}){const a=$(b=>b.killAgent),n=$(b=>b.rotateAgent),s=$(b=>b.spawnAgent),o=$(b=>b.closeDetail),c=$(b=>b.addToast),[l,d]=y.useState(null),[h,f]=y.useState(!1),g=e.status==="running"||e.status==="starting";async function x(){d("rotate");try{await n(e.id)}catch{}d(null)}async function m(){if(!h){f(!0),setTimeout(()=>f(!1),3e3);return}d("kill");try{await a(e.id,!g),o()}catch{}d(null),f(!1)}async function v(){d("clone");try{await s({role:e.role,provider:e.provider,model:e.model,name:`${e.name}-clone`,scope:e.scope,workingDir:e.workingDir}),c("success",`Cloned ${e.name}`)}catch{}d(null)}return g?t.jsx("div",{className:"space-y-2",children:t.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[t.jsxs(Ae,{variant:"primary",size:"md",onClick:x,disabled:l==="rotate",className:"gap-1.5",children:[t.jsx(wr,{size:12,className:l==="rotate"?"animate-spin":""}),"Rotate"]}),t.jsxs(Ae,{variant:"info",size:"md",onClick:v,disabled:!!l,className:"gap-1.5",children:[t.jsx(pn,{size:12})," Clone"]}),t.jsxs(Ae,{variant:"danger",size:"md",onClick:m,disabled:l==="kill",className:"gap-1.5",children:[t.jsx(bd,{size:12}),h?"Confirm":"Kill"]})]})}):t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[t.jsxs(Ae,{variant:"info",size:"md",onClick:v,disabled:!!l,className:"gap-1.5",children:[t.jsx(pn,{size:12})," Clone"]}),t.jsxs(Ae,{variant:"danger",size:"md",onClick:m,disabled:l==="kill",className:"gap-1.5",children:[t.jsx($t,{size:12}),h?"Confirm":"Remove"]})]})}function hDe({agent:e}){var St;const a=$(te=>te.addToast),n=$(te=>te.remoteHomedir),[s,o]=y.useState([]),[c,l]=y.useState(e.model||""),[d,h]=y.useState(""),[f,g]=y.useState(e.effort||"default"),[x,m]=y.useState(!1),[v,b]=y.useState(""),[C,j]=y.useState(null),[w,Q]=y.useState(!1),[S,_]=y.useState(null),[F,B]=y.useState(e.routingMode||"auto"),[M,L]=y.useState([]),[T,U]=y.useState([]),[Y,J]=y.useState("hr"),[G,E]=y.useState("1"),[P,I]=y.useState(!1),[H,V]=y.useState(""),[Z,R]=y.useState(!1),[pe,xe]=y.useState([]),[se,ie]=y.useState(!1),[ge,de]=y.useState([]),[me,Ue]=y.useState(null),[Te,Tt]=y.useState(!1),[xt,mt]=y.useState(!1),oa=e.status==="running"||e.status==="starting";y.useEffect(()=>{jt(),D.get("/skills/installed").then(ve=>L(Array.isArray(ve)?ve:ve.skills||[])).catch(()=>{}),D.get("/integrations/installed").then(ve=>de(Array.isArray(ve)?ve:[])).catch(()=>{}),D.get("/repos/imported").then(ve=>U((Array.isArray(ve)?ve:[]).filter(_e=>_e.status==="active"))).catch(()=>{}),e.provider==="claude-code"&&D.get("/providers/claude-code/auth").then(ve=>Ue(ve)).catch(()=>Ue(null));function te(){jt()}return window.addEventListener("groove:providers-changed",te),()=>window.removeEventListener("groove:providers-changed",te)},[]);function jt(){D.get("/providers").then(te=>o(Array.isArray(te)?te:[])).catch(()=>{})}y.useEffect(()=>{l(e.model||""),D.get(`/agents/${e.id}/routing/recommend`).then(te=>{B((te==null?void 0:te.mode)||"fixed")}).catch(()=>{})},[e.id,e.model]),y.useEffect(()=>{R(!1),e.personality?D.get(`/personalities/${e.name}`).then(te=>{V((te==null?void 0:te.content)||""),R(!0)}).catch(()=>{V(""),R(!0)}):(V(""),R(!0)),D.get("/personalities").then(te=>{xe(Array.isArray(te)?te:te.personalities||[])}).catch(()=>{})},[e.id,e.name]),y.useEffect(()=>{if(!xt)return;const te=Date.now(),ve=setInterval(()=>{if(Date.now()-te>3e5){mt(!1),clearInterval(ve);return}D.get("/providers/claude-code/auth").then(_e=>{_e!=null&&_e.authenticated&&(Ue(_e),mt(!1),Tt(!1),clearInterval(ve))}).catch(()=>{})},2e3);return()=>clearInterval(ve)},[xt]);const Gt=s.find(te=>te.id===e.provider);async function Vn(te,ve){l(ve);try{const _e={model:ve};te&&te!==e.provider&&(_e.provider=te),await D.patch(`/agents/${e.id}`,_e),a("success",`Model → ${ve}${_e.provider?` (${te})`:""}`)}catch(_e){a("error","Model swap failed",_e.message)}}async function Ps(te){try{await D.patch(`/agents/${e.id}`,{workingDir:te}),a("success",`Working dir → ${te.split("/").pop()||te}`)}catch(ve){a("error","Update failed",ve.message)}}async function zs(te){g(te);try{await D.patch(`/agents/${e.id}`,{effort:te}),a("success",`Effort → ${te}`)}catch(ve){a("error","Update failed",ve.message)}}async function Pa(te){if(!te.trim())return;const ve=[...e.scope||[],te.trim()];try{await D.patch(`/agents/${e.id}`,{scope:ve}),h("")}catch(_e){a("error","Scope update failed",_e.message)}}async function ls(te){const ve=(e.scope||[]).filter((_e,Rt)=>Rt!==te);try{await D.patch(`/agents/${e.id}`,{scope:ve})}catch(_e){a("error","Scope update failed",_e.message)}}async function Fs(te){if(v.trim())try{await D.post(`/credentials/${te}`,{key:v.trim()}),a("success",`API key set for ${te}`),b(""),j(null),jt(),window.dispatchEvent(new CustomEvent("groove:providers-changed"))}catch(ve){a("error","Failed to set key",ve.message)}}async function Es(){Tt(!0);try{await D.post("/providers/claude-code/login"),mt(!0)}catch{Tt(!1)}}const yn=e.spawnedAt||e.createdAt;return t.jsxs("div",{className:"px-5 py-5 space-y-6 overflow-y-auto h-full",children:[t.jsx(Va,{label:"Active Model",icon:Qa,children:t.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-bold font-mono text-text-0",children:e.model||"auto"}),t.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:(Gt==null?void 0:Gt.name)||e.provider})]}),(Gt==null?void 0:Gt.canHotSwap)&&oa&&t.jsxs(ke,{variant:"accent",className:"text-2xs gap-1",children:[t.jsx(wt,{size:8})," Hot-swap"]})]}),((St=Gt==null?void 0:Gt.models)==null?void 0:St.length)>1&&t.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3 pt-3 border-t border-border-subtle",children:Gt.models.filter(te=>!te.disabled).map(te=>{const ve=te.id===e.model;return t.jsx("button",{onClick:()=>Vn(e.provider,te.id),disabled:!1,className:q("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:te.name||te.id},te.id)})})]})}),t.jsx(uDe,{agent:e}),t.jsxs(Va,{label:"Providers",icon:gr,description:"Click a provider to see its models and connection status.",children:[t.jsx("div",{className:"space-y-1.5",children:s.map(te=>{var Bt;const ve=te.id===e.provider,_e=te.authType==="subscription"?te.installed||((Bt=te.authStatus)==null?void 0:Bt.authenticated):te.authType==="local"?te.installed:te.installed&&te.hasKey,Rt=S===te.id,Fd=te.models||[];return t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[t.jsxs("button",{onClick:()=>_(Rt?null:te.id),className:"w-full flex items-center gap-2.5 px-3 py-2 cursor-pointer hover:bg-surface-4/50 transition-colors",children:[t.jsx("div",{className:q("w-2 h-2 rounded-full flex-shrink-0",_e?"bg-success":"bg-text-4")}),t.jsx("span",{className:q("text-xs font-semibold font-sans flex-1 text-left",_e?"text-text-0":"text-text-3"),children:te.name||te.id}),ve&&t.jsx(ke,{variant:"accent",className:"text-2xs",children:"Active"}),!_e&&t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:te.installed?"No key":"Not installed"}),t.jsx(Lt,{size:12,className:q("text-text-4 transition-transform",Rt&&"rotate-180")})]}),Rt&&te.authType==="local"&&t.jsx("div",{className:"border-t border-border-subtle",children:t.jsx(iJ,{isInstalled:_e,onModelChange:jt})}),Rt&&te.authType!=="local"&&t.jsxs("div",{className:"border-t border-border-subtle",children:[(!_e||te.hasKey)&&t.jsx("div",{className:"px-3 py-2 bg-surface-1/50",children:C===te.id?t.jsxs("div",{className:"flex gap-1.5",children:[t.jsxs("div",{className:"flex-1 relative",children:[t.jsx("input",{value:v,onChange:At=>b(At.target.value),onKeyDown:At=>At.key==="Enter"&&Fs(te.id),type:w?"text":"password",placeholder:`${te.name||te.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}),t.jsx("button",{onClick:()=>Q(!w),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:w?t.jsx(fn,{size:10}):t.jsx(na,{size:10})})]}),t.jsx(Ae,{variant:"primary",size:"sm",onClick:()=>Fs(te.id),disabled:!v.trim(),className:"h-7 px-2 text-2xs",children:"Save"}),t.jsx(Ae,{variant:"ghost",size:"sm",onClick:()=>{j(null),b("")},className:"h-7 px-2 text-2xs",children:"Cancel"})]}):t.jsxs("button",{onClick:()=>{j(te.id),b(""),Q(!1)},className:"flex items-center gap-1.5 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[t.jsx(ns,{size:10}),_e?"Update API key":"Add API key to enable"]})}),_e&&Fd.filter(At=>!At.disabled).length>0&&Fd.filter(At=>!At.disabled).map(At=>{const Ko=te.id===e.provider&&At.id===e.model;return t.jsxs("button",{onClick:()=>Vn(te.id,At.id),disabled:!1,className:q("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",Ko?"text-accent":"text-text-2"),children:[Ko?t.jsx(Ie,{size:11,className:"text-accent flex-shrink-0"}):t.jsx("div",{className:"w-[11px]"}),t.jsx("span",{className:"font-mono flex-1 truncate",children:At.name||At.id}),t.jsx(ke,{variant:Ko?"accent":"default",className:"text-2xs",children:At.tier})]},At.id)})]})]},te.id)})}),oa&&t.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans mt-1.5",children:[t.jsx(Ft,{size:10}),t.jsx("span",{children:"Model changes apply on next rotation or respawn."})]})]}),e.provider==="claude-code"&&me&&!me.authenticated&&t.jsxs("div",{className:"rounded-lg border border-warning/30 bg-warning/5 px-4 py-3 space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ft,{size:13,className:"text-warning flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Claude Code is not signed in"})]}),Te?t.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[t.jsx(Le,{size:12,className:"animate-spin text-accent"}),"Waiting for browser authentication..."]}):t.jsxs(Ae,{variant:"primary",size:"sm",onClick:Es,className:"text-2xs gap-1.5",children:[t.jsx(ft,{size:10}),"Sign in to Claude"]})]}),e.provider==="claude-code"&&(me==null?void 0:me.authenticated)&&t.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[t.jsx("div",{className:"w-2 h-2 rounded-full bg-success flex-shrink-0"}),"Signed in as ",me.email||"Claude user"," (",me.subscriptionType||"subscription",")"]}),t.jsx(Va,{label:"Working Directory",icon:da,description:"The root directory this agent operates in.",children:t.jsxs("div",{className:"flex gap-2",children:[t.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:e.workingDir||"Project root"}),t.jsxs(Ae,{variant:"secondary",size:"md",onClick:()=>m(!0),className:"gap-1.5 flex-shrink-0",children:[t.jsx(pd,{size:14})," Browse"]})]})}),t.jsx(Va,{label:"Permission Mode",icon:mn,description:"Full Send = no approvals. Agent Approve = Fullstack Manager reviews risky operations.",children:t.jsx(Kp,{options:[{value:"full",label:"Full Send"},{value:"auto",label:"Agent Approve"}],value:e.permission||"full",onChange:async te=>{try{await D.patch(`/agents/${e.id}`,{permission:te}),a("success",`Permission → ${te==="full"?"Full Send":"Agent Approve"}`)}catch(ve){a("error","Update failed",ve.message)}}})}),t.jsxs(Va,{label:"Model Routing",icon:ts,description:"How Groove selects models for this agent's tasks.",children:[t.jsx(Kp,{options:[{value:"fixed",label:"Fixed"},{value:"auto",label:"Auto"},{value:"auto-floor",label:"Auto + Floor"}],value:F,onChange:async te=>{B(te);try{await D.post(`/agents/${e.id}/routing`,{mode:te}),a("success",`Routing → ${te}`)}catch(ve){a("error","Update failed",ve.message)}}}),t.jsxs("div",{className:"text-2xs text-text-4 font-sans mt-1",children:[F==="fixed"&&"Uses the selected model for all tasks.",F==="auto"&&"Groove picks Opus/Sonnet/Haiku based on task complexity.",F==="auto-floor"&&"Auto-routes but never drops below Sonnet."]})]}),t.jsx(Va,{label:"File Scope",icon:mn,description:"Restrict which files this agent can access. Empty = unrestricted.",children:t.jsxs("div",{className:"flex flex-wrap gap-2",children:[(e.scope||[]).map((te,ve)=>t.jsxs(ke,{variant:"default",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[te,t.jsx("button",{onClick:()=>ls(ve),className:"hover:text-danger cursor-pointer",children:t.jsx(He,{size:10})})]},ve)),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{value:d,onChange:te=>h(te.target.value),onKeyDown:te=>te.key==="Enter"&&Pa(d),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"}),t.jsx("button",{onClick:()=>Pa(d),disabled:!d.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:t.jsx(ut,{size:12})})]})]})}),t.jsx(Va,{label:"Effort Level",icon:Dh,description:"Controls how deep the agent reasons. Higher = more tokens but better results.",children:t.jsx(Kp,{options:[{value:"min",label:"Min"},{value:"low",label:"Low"},{value:"default",label:"Default"},{value:"high",label:"High"},{value:"max",label:"Max"}],value:f,onChange:zs})}),t.jsx(Va,{label:"Agent Details",icon:gr,children:t.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle divide-y divide-border-subtle",children:[t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"ID"}),t.jsx("span",{className:"text-xs text-text-1 font-mono",children:e.id})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Role"}),t.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:e.role})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Provider"}),t.jsx("span",{className:"text-xs text-text-1 font-mono",children:e.provider})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Model"}),t.jsx("span",{className:"text-xs text-text-1 font-mono",children:e.model||"auto"})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Status"}),t.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:e.status})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Spawned"}),t.jsx("span",{className:"text-xs text-text-1 font-sans",children:yn?ht(yn):"—"})]}),e.sessionId&&t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Session"}),t.jsxs("span",{className:"text-xs text-text-1 font-mono",children:[e.sessionId.slice(0,16),"..."]})]})]})}),t.jsx(Va,{label:"Skills",icon:Qt,description:"Attach installed skills to this agent's context.",children:t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(e.skills||[]).map(te=>t.jsxs(ke,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[te,t.jsx("button",{onClick:async()=>{try{await D.delete(`/agents/${e.id}/skills/${te}`),a("success",`Detached ${te}`)}catch(ve){a("error","Detach failed",ve.message)}},className:"hover:text-danger cursor-pointer",children:t.jsx(He,{size:10})})]},te)),M.filter(te=>!(e.skills||[]).includes(te.id)).length>0&&t.jsxs("div",{className:"relative group",children:[t.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:t.jsx(ut,{size:12})}),t.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-[160px]",children:M.filter(te=>!(e.skills||[]).includes(te.id)).map(te=>t.jsx("button",{onClick:async()=>{try{await D.post(`/agents/${e.id}/skills/${te.id}`),a("success",`Attached ${te.name||te.id}`)}catch(ve){a("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:te.name||te.id},te.id))})]}),(e.skills||[]).length===0&&M.length===0&&t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No skills installed — browse the Marketplace"})]})}),t.jsxs(Va,{label:"Integrations",icon:Yt,description:"Attach MCP integrations for external services.",children:[t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(e.integrations||[]).map(te=>{const ve=Sd[te],_e=ge.find(Rt=>Rt.id===te);return t.jsxs(ke,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[ve?t.jsx("img",{src:ve,alt:"",className:"w-2.5 h-2.5"}):t.jsx(Yt,{size:9}),(_e==null?void 0:_e.name)||te,t.jsx("button",{onClick:async()=>{try{await D.delete(`/agents/${e.id}/integrations/${te}`),a("success",`Detached ${(_e==null?void 0:_e.name)||te}`)}catch(Rt){a("error","Detach failed",Rt.message)}},className:"hover:text-danger cursor-pointer",children:t.jsx(He,{size:10})})]},te)}),ge.filter(te=>te.configured!==!1&&!(e.integrations||[]).includes(te.id)).length>0&&t.jsxs("div",{className:"relative group",children:[t.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:t.jsx(ut,{size:12})}),t.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:ge.filter(te=>te.configured!==!1&&!(e.integrations||[]).includes(te.id)).map(te=>{const ve=Sd[te.id];return t.jsxs("button",{onClick:async()=>{try{await D.post(`/agents/${e.id}/integrations/${te.id}`),a("success",`Attached ${te.name||te.id}`)}catch(_e){a("error","Attach failed",_e.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?t.jsx("img",{src:ve,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):t.jsx(Yt,{size:12,className:"text-text-3 flex-shrink-0"}),te.name||te.id]},te.id)})})]}),(e.integrations||[]).length===0&&ge.length===0&&t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No integrations installed — browse the Marketplace"})]}),(e.integrations||[]).length>0&&t.jsxs("div",{className:"mt-3",children:[t.jsx("label",{className:"text-2xs font-medium text-text-3 font-sans block mb-1.5",children:"Integration Approvals"}),t.jsx(Kp,{options:[{value:"auto",label:"Auto"},{value:"manual",label:"Manual"}],value:e.integrationApproval||"manual",onChange:async te=>{try{await D.patch(`/agents/${e.id}`,{integrationApproval:te}),a("success",`Integration approvals → ${te==="auto"?"Auto":"Manual"}`)}catch(ve){a("error","Update failed",ve.message)}}})]})]}),T.length>0&&t.jsx(Va,{label:"Repos",icon:Bs,description:"Attach imported repos so this agent knows where they are.",children:t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(e.repos||[]).map(te=>{const ve=T.find(_e=>_e.id===te);return t.jsxs(ke,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[(ve==null?void 0:ve.name)||te,t.jsx("button",{onClick:async()=>{try{await D.delete(`/agents/${e.id}/repos/${te}`),a("success",`Detached ${(ve==null?void 0:ve.name)||te}`)}catch(_e){a("error","Detach failed",_e.message)}},className:"hover:text-danger cursor-pointer",children:t.jsx(He,{size:10})})]},te)}),T.filter(te=>!(e.repos||[]).includes(te.id)).length>0&&t.jsxs("div",{className:"relative group",children:[t.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:t.jsx(ut,{size:12})}),t.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:T.filter(te=>!(e.repos||[]).includes(te.id)).map(te=>t.jsxs("button",{onClick:async()=>{try{await D.post(`/agents/${e.id}/repos/${te.id}`),a("success",`Attached ${te.name||te.id}`)}catch(ve){a("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:[t.jsx("div",{className:"font-semibold",children:te.name||te.repo}),t.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:te.clonedTo})]},te.id))})]}),(e.repos||[]).length===0&&t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No repos attached — import one from the Marketplace"})]})}),t.jsx(Va,{label:"Schedule",icon:No,description:"Run this agent on a recurring schedule.",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs text-text-2 font-sans",children:"Every"}),t.jsx("input",{value:G,onChange:te=>E(te.target.value.replace(/\D/g,"").slice(0,3)),className:"w-12 h-7 px-2 text-xs text-center bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono focus:outline-none focus:ring-1 focus:ring-accent",placeholder:"1"}),t.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:[{value:"min",label:"Min"},{value:"hr",label:"Hr"},{value:"day",label:"Day"},{value:"wk",label:"Wk"},{value:"mo",label:"Mo"}].map(te=>t.jsx("button",{onClick:()=>J(te.value),className:q("px-2 py-1 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",Y===te.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:te.label},te.value))}),t.jsxs(Ae,{variant:"primary",size:"sm",disabled:P||!G||parseInt(G,10)<1,onClick:async()=>{const te=parseInt(G,10);if(!te||te<1)return;const ve={min:te===1?"* * * * *":`*/${te} * * * *`,hr:te===1?"0 * * * *":`0 */${te} * * *`,day:te===1?"0 0 * * *":`0 0 */${te} * *`,wk:`0 0 * * ${te===1?"1":"*"}`,mo:`0 0 ${te===1?"1":te} * *`};I(!0);try{await D.post("/schedules",{name:`${e.name} schedule`,cron:ve[Y],agentConfig:{role:e.role,provider:e.provider,model:e.model,scope:e.scope,workingDir:e.workingDir,prompt:e.prompt}}),a("success",`Scheduled every ${te} ${Y}`)}catch(_e){a("error","Schedule failed",_e.message)}I(!1)},className:"h-7 px-3 text-2xs gap-1",children:[t.jsx(No,{size:10}),P?"...":"Set"]})]})}),t.jsxs(Va,{label:"Personality",icon:En,description:"Injected into every prompt. Changes apply on next spawn or rotation.",children:[t.jsx("textarea",{value:H,onChange:te=>V(te.target.value),placeholder:Z?"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"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(Ae,{variant:"primary",size:"sm",disabled:se,onClick:async()=>{ie(!0);try{await D.put(`/personalities/${e.name}`,{content:H}),a("success","Personality saved")}catch(te){a("error","Save failed",te.message)}ie(!1)},className:"h-7 px-3 text-2xs gap-1",children:[t.jsx(Od,{size:10}),se?"Saving...":"Save"]}),pe.length>0&&t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:"",onChange:te=>{if(!te.target.value)return;const ve=pe.find(_e=>(_e.name||_e)===te.target.value);ve&&D.get(`/personalities/${ve.name||ve}`).then(_e=>{_e!=null&&_e.content&&V(_e.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:[t.jsx("option",{value:"",children:"Clone from..."}),pe.filter(te=>(te.name||te)!==e.name).map(te=>t.jsx("option",{value:te.name||te,children:te.name||te},te.name||te))]}),t.jsx(Lt,{size:10,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]})]})]}),e.prompt&&t.jsx(Va,{label:"Original Prompt",icon:ts,children:t.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:e.prompt})}),t.jsx(Ou,{open:x,onOpenChange:m,currentPath:e.workingDir||n||"/",homePath:n,onSelect:Ps})]})}const nX=[];function pDe({data:e,isAlive:a,height:n=48}){const s=y.useRef(null);return y.useEffect(()=>{const o=s.current;if(!o||!e.length)return;const c=o.getContext("2d"),l=window.devicePixelRatio||1,d=o.clientWidth,h=o.clientHeight;o.width=d*l,o.height=h*l,c.scale(l,l),c.clearRect(0,0,d,h);const f=e.map(b=>b.v),g=Math.min(...f),m=Math.max(...f,1)-g||1;c.beginPath(),c.moveTo(0,h),e.forEach((b,C)=>{const j=C/(e.length-1)*d,w=h-(b.v-g)/m*(h-4)-2;c.lineTo(j,w)}),c.lineTo(d,h),c.closePath();const v=c.createLinearGradient(0,0,0,h);if(v.addColorStop(0,a?"rgba(51,175,188,0.15)":"rgba(110,118,129,0.08)"),v.addColorStop(1,"rgba(0,0,0,0)"),c.fillStyle=v,c.fill(),c.beginPath(),c.strokeStyle=a?W.accent:W.text3,c.lineWidth=1.5,e.forEach((b,C)=>{const j=C/(e.length-1)*d,w=h-(b.v-g)/m*(h-4)-2;C===0?c.moveTo(j,w):c.lineTo(j,w)}),c.stroke(),e.length>1&&a){const b=e[e.length-1],C=d-1,j=h-(b.v-g)/m*(h-4)-2;c.beginPath(),c.arc(C,j,5,0,Math.PI*2),c.fillStyle="rgba(51,175,188,0.3)",c.fill(),c.beginPath(),c.arc(C,j,2.5,0,Math.PI*2),c.fillStyle=W.accent,c.fill()}},[e,a]),t.jsx("div",{className:"w-full rounded-lg bg-surface-0 overflow-hidden border border-border-subtle",style:{height:n},children:t.jsx("canvas",{ref:s,className:"w-full h-full"})})}function Yp({icon:e,label:a,value:n,color:s,sub:o}){return t.jsxs("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 border border-border-subtle",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx(e,{size:12,className:s||"text-text-3"}),t.jsx("span",{className:"text-2xs text-text-4 font-sans uppercase tracking-wider",children:a})]}),t.jsx("div",{className:q("text-lg font-bold font-mono tabular-nums",s||"text-text-0"),children:n}),o&&t.jsx("div",{className:"text-2xs text-text-4 font-sans mt-0.5",children:o})]})}function fDe({score:e}){const a=Math.min(Math.max(e,0),100);let n=W.success,s="Healthy";return a<40?(n=W.danger,s="Degraded"):a<70&&(n=W.warning,s="Fair"),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[t.jsxs("span",{className:"text-2xs text-text-3 font-sans flex items-center gap-1.5",children:[t.jsx(Kh,{size:11}),"Session Health"]}),t.jsxs("span",{className:"text-xs font-bold font-mono",style:{color:n},children:[a,"/100"]})]}),t.jsx("div",{className:"h-2 bg-surface-0 rounded-full overflow-hidden border border-border-subtle",children:t.jsx("div",{className:"h-full rounded-full transition-all duration-700",style:{width:`${a}%`,background:n}})}),t.jsx("span",{className:"text-2xs font-sans mt-1 block",style:{color:n},children:s})]})}function xDe(e){const a=(e||"").toLowerCase();return a.includes("edit")||a.includes("writ")?{icon:mr,color:"text-warning"}:a.includes("read")||a.includes("view")?{icon:na,color:"text-info"}:a.includes("search")||a.includes("grep")||a.includes("glob")?{icon:ra,color:"text-purple"}:a.includes("bash")||a.includes("command")||a.includes("terminal")?{icon:jr,color:"text-orange"}:a.includes("error")||a.includes("fail")?{icon:Ft,color:"text-danger"}:a.includes("spawn")||a.includes("start")?{icon:wt,color:"text-success"}:a.includes("complet")||a.includes("done")?{icon:$n,color:"text-success"}:{icon:br,color:"text-text-4"}}function mDe({agent:e}){const a=$(l=>l.tokenTimeline[e.id])||nX,n=$(l=>l.activityLog[e.id])||nX,s=e.status==="running"||e.status==="starting",o=y.useMemo(()=>{if(a.length<2)return 0;const l=a.slice(-10),d=(l[l.length-1].t-l[0].t)/6e4,h=l[l.length-1].v-l[0].v;return d>0?Math.round(h/d):0},[a]),c=y.useMemo(()=>{const l=e.contextUsage||0;let d=100;return l>90?d-=50:l>70?d-=25:l>50&&(d-=10),o>5e3?d-=15:o>3e3&&(d-=8),e.status==="crashed"&&(d=10),e.status==="completed"&&(d=95),Math.max(0,Math.min(100,d))},[e.contextUsage,e.status,o]);return t.jsxs("div",{className:"px-5 py-5 space-y-5 overflow-y-auto h-full",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Token Burn"}),s&&t.jsx("span",{className:"text-2xs text-accent font-mono animate-pulse",children:"LIVE"})]}),t.jsx(pDe,{data:a,isAlive:s,height:56})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[t.jsx(Yp,{icon:Hh,label:"Burn Rate",value:o>0?`${tt(o)}/m`:"—",color:o>5e3?"text-danger":o>2e3?"text-warning":"text-text-0"}),t.jsx(Yp,{icon:Rh,label:"Cost",value:Wo(e.costUsd||0),color:"text-text-0"}),t.jsx(Yp,{icon:wr,label:"Rotations",value:e.rotations||"0",color:"text-text-0"}),t.jsx(Yp,{icon:wt,label:"Turns",value:e.turns||"0",color:"text-text-0"})]}),t.jsx(fDe,{score:c}),e.prompt&&t.jsxs("div",{children:[t.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-1.5",children:"Task"}),t.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:e.prompt})]}),n.length>0&&t.jsxs("div",{children:[t.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-2",children:"Activity"}),t.jsxs("div",{className:"space-y-0 relative",children:[t.jsx("div",{className:"absolute left-[9px] top-2 bottom-2 w-px bg-border-subtle"}),n.slice(-12).reverse().map((l,d)=>{const h=xDe(l.text),f=h.icon;return t.jsxs("div",{className:"flex items-start gap-3 py-1.5 relative",children:[t.jsx("div",{className:q("w-[18px] h-[18px] rounded-full flex items-center justify-center flex-shrink-0 z-10","bg-surface-1 border border-border-subtle"),children:t.jsx(f,{size:9,className:h.color})}),t.jsx("span",{className:"text-2xs text-text-2 font-sans flex-1 line-clamp-1 pt-0.5",children:l.text}),t.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0 pt-0.5",children:ht(l.timestamp)})]},d)})]})]})]})}function gDe({agent:e}){const a=$(M=>M.addToast),[n,s]=y.useState([]),[o,c]=y.useState(""),[l,d]=y.useState(null),[h,f]=y.useState(""),[g,x]=y.useState(""),[m,v]=y.useState(!1),[b,C]=y.useState(!1),[j,w]=y.useState("");async function Q(){try{const M=await D.get(`/agents/${e.id}/mdfiles`);s(M.files||[]),c(M.workingDir||"")}catch{}}y.useEffect(()=>{Q()},[e.id]);async function S(M){try{const L=await D.get(`/agents/${e.id}/mdfiles/read?path=${encodeURIComponent(M)}`);f(L.content||""),x(L.content||""),d(M)}catch(L){a("error","Failed to read file",L.message)}}async function _(){if(l){v(!0);try{await D.put(`/agents/${e.id}/mdfiles/write`,{path:l,content:h}),x(h),a("success",`Saved ${l}`)}catch(M){a("error","Save failed",M.message)}v(!1)}}async function F(){const M=j.trim();if(M)try{await D.post(`/agents/${e.id}/mdfiles/create`,{name:M}),w(""),C(!1),a("success",`Created ${M}.md`),Q()}catch(L){a("error","Create failed",L.message)}}const B=h!==g;return l?t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border-subtle",children:[t.jsx("button",{onClick:()=>{d(null),f(""),x("")},className:"p-1 text-text-3 hover:text-text-0 cursor-pointer",children:t.jsx(Ss,{size:14})}),t.jsx(un,{size:12,className:"text-accent"}),t.jsx("span",{className:"text-xs text-text-0 font-sans font-medium flex-1 truncate",children:l}),B&&t.jsx("span",{className:"text-[10px] text-warning font-sans",children:"unsaved"}),t.jsxs("button",{onClick:_,disabled:!B||m,className:q("flex items-center gap-1 px-2.5 py-1 rounded text-2xs font-sans font-medium cursor-pointer transition-colors",B?"bg-accent/15 text-accent hover:bg-accent/25":"text-text-4 opacity-50 cursor-not-allowed"),children:[t.jsx(Od,{size:10}),m?"Saving...":"Save"]})]}),t.jsx("textarea",{value:h,onChange:M=>f(M.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})]}):t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 border-b border-border-subtle",children:[t.jsx(un,{size:12,className:"text-text-3"}),t.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:"Markdown Files"}),t.jsx("button",{onClick:()=>C(!0),className:"p-1 text-text-4 hover:text-accent cursor-pointer",title:"Create file",children:t.jsx(ut,{size:12})}),t.jsx("button",{onClick:Q,className:"p-1 text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(Et,{size:11})})]}),o&&t.jsx("div",{className:"px-4 py-1.5 text-[10px] text-text-4 font-mono truncate border-b border-border-subtle/50",children:o}),b&&t.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-b border-border-subtle bg-surface-0",children:[t.jsx(un,{size:11,className:"text-accent flex-shrink-0"}),t.jsx("input",{autoFocus:!0,value:j,onChange:M=>w(M.target.value),onKeyDown:M=>{M.key==="Enter"&&F(),M.key==="Escape"&&(C(!1),w(""))},placeholder:"filename",className:"flex-1 bg-transparent text-xs text-text-0 font-mono outline-none placeholder:text-text-4"}),t.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:".md"}),t.jsx("button",{onClick:F,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:t.jsx(Od,{size:11})}),t.jsx("button",{onClick:()=>{C(!1),w("")},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(He,{size:11})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:n.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center px-4",children:[t.jsx(un,{size:20,className:"text-text-4 mb-2"}),t.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No markdown files found"}),t.jsx("p",{className:"text-[10px] text-text-4 font-sans mt-1",children:"MD files in the agent's working directory will appear here"})]}):t.jsx("div",{className:"py-1",children:n.map(M=>t.jsxs("button",{onClick:()=>S(M.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:[t.jsx(un,{size:13,className:"text-accent flex-shrink-0"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("span",{className:"text-xs text-text-0 font-sans block truncate",children:M.name}),t.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:M.path})]}),t.jsx("span",{className:"text-[10px] text-text-4 font-mono flex-shrink-0",children:M.size>1024?`${(M.size/1024).toFixed(1)}K`:`${M.size}B`}),M.source==="personality"&&t.jsx("span",{className:"text-[9px] font-mono text-purple bg-purple/10 px-1 py-px rounded flex-shrink-0",children:"personality"}),M.source==="user"&&t.jsx("span",{className:"text-[9px] font-mono text-accent bg-accent/10 px-1 py-px rounded flex-shrink-0",children:"custom"})]},M.path))})})]})}const yDe={running:"success",starting:"warning",stopped:"default",crashed:"danger",completed:"accent",killed:"default",rotating:"purple"},kDe={running:"Running",starting:"Starting",stopped:"Stopped",crashed:"Crashed",completed:"Done",killed:"Killed",rotating:"Rotating"},ODe=[{id:"command",label:"Chat",icon:Ta},{id:"config",label:"Config",icon:Cr},{id:"telemetry",label:"Monitor",icon:ts},{id:"mdfiles",label:"Files",icon:un}];function vDe({agent:e}){const a=$(h=>h.addToast),[n,s]=y.useState(!1),[o,c]=y.useState(e.name),l=y.useRef(null);async function d(){const h=o.trim();if(!h||h===e.name){s(!1);return}try{await D.patch(`/agents/${e.id}`,{name:h.replace(/\s+/g,"-")}),a("success",`Renamed → ${h}`)}catch(f){a("error","Rename failed",f.message),c(e.name)}s(!1)}return n?t.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-0",children:[t.jsx("input",{ref:l,value:o,onChange:h=>c(h.target.value),onKeyDown:h=>{h.key==="Enter"&&d(),h.key==="Escape"&&(c(e.name),s(!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}),t.jsx("button",{onClick:d,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:t.jsx(Ie,{size:12})}),t.jsx("button",{onClick:()=>{c(e.name),s(!1)},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(He,{size:12})})]}):t.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0 group",children:[t.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans truncate",children:e.name}),t.jsx("button",{onClick:()=>{c(e.name),s(!0)},className:"p-0.5 text-text-4 opacity-0 group-hover:opacity-100 hover:text-text-1 cursor-pointer transition-opacity",children:t.jsx(Ns,{size:10})})]})}function bDe(){const e=$(f=>f.detailPanel),a=$(f=>f.agents),[n,s]=y.useState("command");if((e==null?void 0:e.type)!=="agent")return null;const o=a.find(f=>f.id===e.agentId);if(!o)return null;const c=o.status==="running"||o.status==="starting",l=Math.round((o.contextUsage||0)*100),d=o.spawnedAt||o.createdAt,h=d?Math.floor((Date.now()-new Date(d).getTime())/1e3):0;return Za(o.role),t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex-shrink-0",children:[t.jsxs("div",{className:"pl-4 pr-10 pt-3 pb-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(vDe,{agent:o}),t.jsx(ke,{variant:yDe[o.status]||"default",dot:c?"pulse":void 0,className:"text-2xs flex-shrink-0",children:kDe[o.status]||o.status})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1 text-2xs text-text-3 font-mono",children:[t.jsx("span",{className:"capitalize",children:o.role}),t.jsx("span",{className:"text-text-4",children:"·"}),t.jsxs("span",{children:[o.provider,":",o.model||"auto"]}),t.jsx("span",{className:"text-text-4",children:"·"}),t.jsxs("span",{children:[tt(o.tokensUsed||0)," tok"]}),l>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-text-4",children:"·"}),t.jsxs("span",{className:q(l>80?"text-danger":l>60?"text-warning":"text-text-3"),children:[l,"% ctx"]})]}),t.jsx("span",{className:"text-text-4",children:"·"}),t.jsx("span",{children:Ud(h)})]})]}),t.jsx("div",{className:"flex items-center px-4 border-b border-border-subtle",children:ODe.map(f=>{const g=f.icon,x=n===f.id;return t.jsxs("button",{onClick:()=>s(f.id),className:q("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",x?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"),children:[t.jsx(g,{size:11}),f.label]},f.id)})})]}),t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[n==="command"&&t.jsx(jW,{agent:o}),n==="config"&&t.jsx(hDe,{agent:o}),n==="telemetry"&&t.jsx(mDe,{agent:o}),n==="mdfiles"&&t.jsx(gDe,{agent:o})]})]})}const wDe=[{id:"chat",label:"Chat",desc:"Companion, assistant, conversation",icon:En,tier:"Medium"},{id:"planner",label:"Planner",desc:"Plans the team and tasks",icon:zo,tier:"Heavy"},{id:"backend",label:"Backend",desc:"APIs, services, databases",icon:ta,tier:"Medium"},{id:"frontend",label:"Frontend",desc:"UI, components, styling",icon:Uo,tier:"Medium"},{id:"fullstack",label:"Fullstack",desc:"End-to-end implementation",icon:ga,tier:"Heavy"},{id:"testing",label:"Testing",desc:"Tests, coverage, QA",icon:Cd,tier:"Medium"},{id:"devops",label:"DevOps",desc:"CI/CD, infra, deployment",icon:Z1,tier:"Medium"},{id:"docs",label:"Docs",desc:"Documentation, guides",icon:un,tier:"Light"},{id:"security",label:"Security",desc:"Audits, vulnerabilities",icon:mn,tier:"Medium"},{id:"database",label:"Database",desc:"Schema, migrations, queries",icon:G1,tier:"Medium"},{id:"cmo",label:"CMO",desc:"Marketing, content, growth",icon:n0,tier:"Medium"},{id:"cfo",label:"CFO",desc:"Finance, metrics, forecasting",icon:zh,tier:"Medium"},{id:"ea",label:"EA",desc:"Executive assistant, scheduling",icon:h0,tier:"Light"},{id:"support",label:"Support",desc:"Customer support, FAQs",icon:Wh,tier:"Medium"},{id:"analyst",label:"Analyst",desc:"Data analysis, insights",icon:xr,tier:"Medium"},{id:"creative",label:"Writer",desc:"Copy, articles, proposals",icon:ko,tier:"Heavy",skillHint:!0},{id:"slides",label:"Slides",desc:"Pitch decks, presentations",icon:c0,tier:"Heavy",skillHint:!0},{id:"ambassador",label:"Ambassador",desc:"Bridge to federated server",icon:sa,tier:"Light"}];function VU(){return t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"text-accent flex-shrink-0",children:[t.jsx("circle",{cx:"7",cy:"7",r:"6",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1"}),t.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 CDe(){const e=$(ae=>ae.detailPanel),a=$(ae=>ae.closeDetail),n=$(ae=>ae.spawnAgent),s=$(ae=>ae.fetchProviders),o=(e==null?void 0:e.type)==="spawn",[c,l]=y.useState(""),[d,h]=y.useState(""),[f,g]=y.useState(""),[x,m]=y.useState(""),[v,b]=y.useState(""),[C,j]=y.useState(""),[w,Q]=y.useState([]),[S,_]=y.useState([]),[F,B]=y.useState([]),[M,L]=y.useState(!1),[T,U]=y.useState(""),[Y,J]=y.useState([]),[G,E]=y.useState([]),[P,I]=y.useState(!1),[H,V]=y.useState(""),[Z,R]=y.useState("manual"),[pe,xe]=y.useState([]),[se,ie]=y.useState([]),[ge,de]=y.useState(!1),[me,Ue]=y.useState(""),[Te,Tt]=y.useState([]),[xt,mt]=y.useState(""),[oa,jt]=y.useState(!1),[Gt,Vn]=y.useState(!1),[Ps,zs]=y.useState(""),[Pa,ls]=y.useState([]),[Fs,Es]=y.useState(null),[yn,St]=y.useState(null),[te,ve]=y.useState(!1),[_e,Rt]=y.useState(!1),Fd=$(ae=>ae.federation),Bt=c||d,At=w.find(ae=>ae.id===x),Ko=(At==null?void 0:At.models)||[],Rs=w.filter(ae=>ae.authType==="api-key"?ae.installed&&ae.hasKey:ae.installed);y.useEffect(()=>{o&&(s().then(ae=>{const Oe=Array.isArray(ae)?ae:ae.providers||[];Q(Oe);const ze=Oe.filter(Ke=>Ke.authType==="api-key"?Ke.installed&&Ke.hasKey:Ke.installed);if(ze.length>0&&!x){const ds=["claude-code","gemini","codex","ollama"].find(kn=>ze.some(Ir=>Ir.id===kn))||ze[0].id;m(ds)}}).catch(()=>{}),D.get("/skills/installed").then(ae=>{_(Array.isArray(ae)?ae:[])}).catch(()=>{}),D.get("/integrations/installed").then(ae=>{J(Array.isArray(ae)?ae:[])}).catch(()=>{}),D.get("/repos/imported").then(ae=>{xe((Array.isArray(ae)?ae:[]).filter(Oe=>Oe.status==="active"))}).catch(()=>{}),D.get("/personalities").then(ae=>{Tt(Array.isArray(ae)?ae:ae.personalities||[])}).catch(()=>{}),l(""),h(""),g(""),m(""),b(""),j(""),B([]),E([]),R("manual"),ie([]),mt(""),zs(""),jt(!1),ls([]),Es(null),St(null),ve(!1),Rt(!1))},[o,s]),y.useEffect(()=>{if(!Bt||!o){ls([]);return}D.get(`/roles/integrations?role=${encodeURIComponent(Bt)}`).then(ae=>{const Oe=Array.isArray(ae)?ae:(ae==null?void 0:ae.recommendations)||[];ls(Oe);const ze=Oe.filter(Ke=>Ke.installed&&Ke.configured&&Ke.authenticated).map(Ke=>Ke.id);ze.length>0&&E(Ke=>[...new Set([...Ke,...ze])])}).catch(()=>ls([]))},[Bt,o]),y.useEffect(()=>{if(!o||x!=="claude-code"){St(null);return}D.get("/providers/claude-code/auth").then(ae=>{St(ae)}).catch(()=>St(null))},[o,x]),y.useEffect(()=>{if(!_e)return;const ae=Date.now(),Oe=setInterval(()=>{if(Date.now()-ae>3e5){Rt(!1),clearInterval(Oe);return}D.get("/providers/claude-code/auth").then(ze=>{ze!=null&&ze.authenticated&&(St(ze),Rt(!1),ve(!1),clearInterval(Oe))}).catch(()=>{})},2e3);return()=>clearInterval(Oe)},[_e]);async function ba(){Vn(!0);try{const ae={role:Bt,...f&&{name:f.replace(/\s+/g,"-")},...x&&{provider:x},...v&&{model:v},...C&&{prompt:C},...F.length>0&&{skills:F},...G.length>0&&{integrations:G},...G.length>0&&{integrationApproval:Z},...se.length>0&&{repos:se},...xt&&{personality:xt},...Bt==="ambassador"&&Ps&&{peerId:Ps}};await n(ae),a()}catch{}Vn(!1)}async function As(){var ae;if(Bt){try{const Oe=await D.post("/agents/preflight",{role:Bt,integrations:G});if(((ae=Oe==null?void 0:Oe.issues)==null?void 0:ae.length)>0){Es(Oe.issues);return}}catch{}ba()}}async function Sa(){ve(!0);try{await D.post("/providers/claude-code/login"),Rt(!0)}catch{ve(!1)}}const X0=x==="claude-code"&&yn&&!yn.authenticated;return t.jsxs(O$,{open:o,onOpenChange:ae=>{ae||a()},children:[t.jsx(v$,{title:"Spawn Agent",width:480,children:t.jsxs("div",{className:"flex flex-col h-[calc(100%-57px)]",children:[t.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-6",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-3",children:"Choose Role"}),t.jsx("div",{className:"grid grid-cols-2 gap-2",children:wDe.map(ae=>{const Oe=Za(ae.id),ze=c===ae.id;return t.jsxs("button",{onClick:()=>{l(ae.id),h("")},className:q("flex items-center gap-2.5 p-3 rounded-md border text-left transition-all cursor-pointer",ze?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-2"),children:[t.jsx("div",{className:"w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0",style:{background:Oe.bg},children:t.jsx(ae.icon,{size:16,style:{color:Oe.text}})}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ae.label}),ae.skillHint&&t.jsx("span",{className:"text-2xs font-mono text-warning/70 bg-warning/8 px-1 py-px rounded",children:"skill"})]}),t.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:ae.desc})]})]},ae.id)})}),t.jsx("div",{className:"mt-3",children:t.jsx(Ls,{placeholder:"or type a custom role (e.g. chat-agent)...",value:d,onChange:ae=>{h(ae.target.value.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,50)),l("")},className:"text-xs"})})]}),Bt&&Pa.length>0&&t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Recommended Integrations"}),t.jsx("div",{className:"space-y-1.5",children:Pa.map(ae=>{const Oe=Sd[ae.id];return ae.installed&&ae.configured&&ae.authenticated?t.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-success/5 border border-success/20",children:[t.jsx(Ie,{size:13,className:"text-success flex-shrink-0"}),Oe?t.jsx("img",{src:Oe,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):t.jsx(Yt,{size:12,className:"text-text-3 flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ae.name||ae.id}),t.jsx(ke,{variant:"success",className:"text-2xs ml-auto",children:"Ready"})]},ae.id):ae.installed?t.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-warning/5 border border-warning/20",children:[t.jsx(Jt,{size:13,className:"text-warning flex-shrink-0"}),Oe?t.jsx("img",{src:Oe,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):t.jsx(Yt,{size:12,className:"text-text-3 flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ae.name||ae.id}),t.jsx(Ae,{variant:"ghost",size:"sm",className:"ml-auto text-2xs text-warning h-6 px-2",onClick:()=>{a(),$.getState().setActiveView("marketplace")},children:"Configure"})]},ae.id):t.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-surface-1 border border-border-subtle",children:[Oe?t.jsx("img",{src:Oe,alt:"",className:"w-3.5 h-3.5 flex-shrink-0 opacity-40"}):t.jsx(Yt,{size:12,className:"text-text-4 flex-shrink-0"}),t.jsx("span",{className:"text-xs text-text-3 font-sans",children:ae.name||ae.id}),t.jsx("button",{onClick:()=>{a(),$.getState().setActiveView("marketplace")},className:"ml-auto text-2xs text-accent hover:underline font-sans cursor-pointer",children:"Install in Marketplace"})]},ae.id)})})]}),Bt==="ambassador"&&(()=>{const ae=Fd.whitelist.filter(Oe=>typeof Oe=="object"&&(Oe.status==="mutual"||Oe.status==="connected"));return ae.length===0?t.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-4 text-center",children:[t.jsx(sa,{size:18,className:"text-text-4 mx-auto mb-1.5"}),t.jsx("p",{className:"text-2xs text-text-3 font-sans mb-2",children:"No federated servers connected. Add one in the Federation view."}),t.jsx(Ae,{variant:"ghost",size:"sm",className:"text-2xs text-accent",onClick:()=>{a(),$.getState().setActiveView("federation")},children:"Go to Federation"})]}):t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Target Server"}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:Ps,onChange:Oe=>zs(Oe.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[t.jsx("option",{value:"",children:"Select a server..."}),ae.map(Oe=>t.jsx("option",{value:Oe.ip,children:Oe.name||`${Oe.ip}:${Oe.port||31415}`},Oe.ip))]}),t.jsx(Lt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})})(),Bt&&t.jsxs("div",{className:"space-y-4",children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block",children:"Configuration"}),t.jsx(Ls,{label:"Name (optional)",value:f,onChange:ae=>g(ae.target.value),placeholder:`${Bt}-1`}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Provider"}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:x,onChange:ae=>{m(ae.target.value),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",children:[t.jsx("option",{value:"",children:"Auto"}),w.map(ae=>t.jsxs("option",{value:ae.id,disabled:ae.authType==="api-key"?!(ae.installed&&ae.hasKey):!ae.installed,children:[ae.name,ae.installed?ae.authType==="api-key"&&!ae.hasKey?" (No API key)":"":" (Not installed)"]},ae.id))]}),t.jsx(Lt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Model"}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:v,onChange:ae=>b(ae.target.value),disabled:!x,className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent disabled:opacity-40",children:[t.jsx("option",{value:"",children:"Auto"}),Ko.map(ae=>t.jsx("option",{value:ae.id,children:ae.name},ae.id))]}),t.jsx(Lt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})]}),x&&At&&t.jsx("div",{className:"text-2xs text-text-3 font-sans flex items-center gap-2",children:At.authType==="local"?t.jsx(ke,{variant:"success",children:"Local"}):At.authType==="subscription"?t.jsx(ke,{variant:"accent",children:"Subscription"}):At.hasKey?t.jsx(ke,{variant:"success",children:"API key set"}):t.jsxs(ke,{variant:"warning",children:["No API key — set with: groove set-key ",x," YOUR_KEY"]})}),X0&&t.jsxs("div",{className:"rounded-lg border border-warning/30 bg-warning/5 px-4 py-3",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx(Jt,{size:13,className:"text-warning flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Claude Code is not signed in"})]}),te?t.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[t.jsx(Le,{size:12,className:"animate-spin text-accent"}),"Waiting for browser authentication..."]}):t.jsxs(Ae,{variant:"primary",size:"sm",onClick:Sa,className:"text-2xs gap-1.5",children:[t.jsx(ft,{size:10}),"Sign in to Claude"]})]}),x==="claude-code"&&(yn==null?void 0:yn.authenticated)&&t.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[t.jsx("div",{className:"w-2 h-2 rounded-full bg-success flex-shrink-0"}),"Signed in as ",yn.email||"Claude user"," (",yn.subscriptionType||"subscription",")"]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Skills"}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[F.map(ae=>{const Oe=S.find(ze=>ze.id===ae);return t.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:[t.jsx(Qt,{size:9}),(Oe==null?void 0:Oe.name)||ae,t.jsx("button",{onClick:()=>B(ze=>ze.filter(Ke=>Ke!==ae)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:t.jsx(He,{size:9})})]},ae)}),t.jsxs("button",{onClick:()=>{L(!0),U("")},className:q("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:[t.jsx(Qt,{size:10}),F.length>0?"Add skill":"Attach skill"]})]})]}),t.jsx(ja,{open:M,onOpenChange:L,children:t.jsx(Ma,{title:"Select Skill",className:"max-w-sm",children:t.jsxs("div",{className:"space-y-3 p-4",children:[t.jsxs("div",{className:"relative",children:[t.jsx(ra,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),t.jsx("input",{value:T,onChange:ae=>U(ae.target.value),placeholder:"Search skills...",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"})]}),t.jsxs("div",{className:"max-h-64 overflow-y-auto space-y-1",children:[S.filter(ae=>{if(!T)return!0;const Oe=T.toLowerCase();return(ae.name||ae.id).toLowerCase().includes(Oe)||(ae.description||"").toLowerCase().includes(Oe)}).map(ae=>{const Oe=F.includes(ae.id);return t.jsxs("button",{onClick:()=>{B(ze=>Oe?ze.filter(Ke=>Ke!==ae.id):[...ze,ae.id])},className:q("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors cursor-pointer",Oe?"bg-accent/10 border border-accent/25":"hover:bg-surface-3 border border-transparent"),children:[t.jsx(Qt,{size:12,className:Oe?"text-accent":"text-text-3"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:ae.name||ae.id}),ae.description&&t.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:ae.description})]}),Oe&&t.jsx(VU,{})]},ae.id)}),S.length===0&&t.jsx("div",{className:"text-center py-6 text-xs text-text-3 font-sans",children:"No skills installed. Visit the Marketplace to install skills."})]})]})})}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integrations"}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[G.map(ae=>{const Oe=Y.find(Ke=>Ke.id===ae),ze=Sd[ae];return t.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:[ze?t.jsx("img",{src:ze,alt:"",className:"w-2.5 h-2.5"}):t.jsx(Yt,{size:9}),(Oe==null?void 0:Oe.name)||ae,t.jsx("button",{onClick:()=>E(Ke=>Ke.filter(ds=>ds!==ae)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:t.jsx(He,{size:9})})]},ae)}),t.jsxs("button",{onClick:()=>{I(!0),V("")},className:q("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:[t.jsx(Yt,{size:10}),G.length>0?"Add integration":"Attach integration"]})]})]}),t.jsx(ja,{open:P,onOpenChange:I,children:t.jsx(Ma,{title:"Select Integration",className:"max-w-sm",children:t.jsxs("div",{className:"space-y-3 p-4",children:[t.jsxs("div",{className:"relative",children:[t.jsx(ra,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),t.jsx("input",{value:H,onChange:ae=>V(ae.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"})]}),t.jsxs("div",{className:"max-h-64 overflow-y-auto space-y-1",children:[Y.filter(ae=>{if(!H)return!0;const Oe=H.toLowerCase();return(ae.name||ae.id).toLowerCase().includes(Oe)||(ae.description||"").toLowerCase().includes(Oe)}).map(ae=>{const Oe=G.includes(ae.id),ze=ae.configured!==!1,Ke=Sd[ae.id],ds=Bt&&Array.isArray(ae.roles)&&ae.roles.includes(Bt);return t.jsxs("button",{onClick:()=>{ze&&E(kn=>Oe?kn.filter(Ir=>Ir!==ae.id):[...kn,ae.id])},disabled:!ze,className:q("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors",ze?"cursor-pointer":"opacity-40 cursor-not-allowed",Oe?"bg-accent/10 border border-accent/25":ze?"hover:bg-surface-3 border border-transparent":"border border-transparent"),children:[Ke?t.jsx("img",{src:Ke,alt:"",className:"w-4 h-4 flex-shrink-0"}):t.jsx(Yt,{size:12,className:Oe?"text-accent":"text-text-3"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:ae.name||ae.id}),!ze&&t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"(not configured)"}),ze&&ds&&t.jsx("span",{className:"text-2xs font-mono text-accent/70 bg-accent/8 px-1 py-px rounded",children:"rec"})]}),ae.description&&t.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:ae.description}),!ze&&t.jsx("div",{className:"text-2xs text-text-4 font-sans",children:"Configure in Marketplace"})]}),Oe&&t.jsx(VU,{})]},ae.id)}),Y.length===0&&t.jsx("div",{className:"text-center py-6 text-xs text-text-3 font-sans",children:"No integrations installed. Visit the Marketplace to install integrations."})]})]})})}),G.length>0&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integration Approvals"}),t.jsxs("div",{className:"flex gap-1.5",children:[t.jsxs("button",{onClick:()=>R("manual"),className:q("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",Z==="manual"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[t.jsx(mn,{size:13,className:Z==="manual"?"text-accent":"text-text-3"}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Manual"}),t.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"You approve each action"})]})]}),t.jsxs("button",{onClick:()=>R("auto"),className:q("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",Z==="auto"?"border-warning bg-warning/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[t.jsx(Qt,{size:13,className:Z==="auto"?"text-warning":"text-text-3"}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Auto"}),t.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"Agent acts without asking"})]})]})]})]}),pe.length>0&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Repos"}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[se.map(ae=>{const Oe=pe.find(ze=>ze.id===ae);return t.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:[t.jsx(Bs,{size:9}),(Oe==null?void 0:Oe.name)||ae,t.jsx("button",{onClick:()=>ie(ze=>ze.filter(Ke=>Ke!==ae)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:t.jsx(He,{size:9})})]},ae)}),t.jsxs("button",{onClick:()=>{de(!0),Ue("")},className:q("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:[t.jsx(Bs,{size:10}),se.length>0?"Add repo":"Attach repo"]})]})]}),t.jsx(ja,{open:ge,onOpenChange:de,children:t.jsx(Ma,{title:"Select Repository",className:"max-w-sm",children:t.jsxs("div",{className:"space-y-3 p-4",children:[pe.length>1&&t.jsxs("div",{className:"relative",children:[t.jsx(ra,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),t.jsx("input",{value:me,onChange:ae=>Ue(ae.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"})]}),t.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:pe.filter(ae=>{if(!me)return!0;const Oe=me.toLowerCase();return(ae.name||ae.repo||ae.id).toLowerCase().includes(Oe)}).map(ae=>{const Oe=se.includes(ae.id);return t.jsxs("button",{onClick:()=>{ie(ze=>Oe?ze.filter(Ke=>Ke!==ae.id):[...ze,ae.id])},className:q("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors cursor-pointer",Oe?"bg-accent/10 border border-accent/25":"hover:bg-surface-3 border border-transparent"),children:[t.jsx(Bs,{size:12,className:Oe?"text-accent":"text-text-3"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:ae.name||ae.repo}),t.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:ae.clonedTo})]}),Oe&&t.jsx(VU,{})]},ae.id)})})]})})}),(c==="chat"||oa)&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Personality"}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:xt,onChange:ae=>mt(ae.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[t.jsx("option",{value:"",children:"None (blank)"}),Te.map(ae=>t.jsx("option",{value:ae.name||ae,children:ae.name||ae},ae.name||ae))]}),t.jsx(Lt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),t.jsx("p",{className:"text-2xs text-text-4 font-sans",children:"Personality is injected into every prompt for this agent."})]}),c!=="chat"&&!oa&&t.jsx("button",{onClick:()=>jt(!0),className:"text-2xs text-text-3 hover:text-accent font-sans transition-colors cursor-pointer",children:"+ Advanced options"})]})]}),t.jsxs("div",{className:"border-t border-border-subtle px-5 py-4 bg-surface-1",children:[Rs.length===0&&w.length>0&&t.jsxs("div",{className:"flex items-center gap-2 mb-3 px-3 py-2 rounded-md bg-warning/8 border border-warning/20",children:[t.jsx(Jt,{size:13,className:"text-warning flex-shrink-0"}),t.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."})]}),Bt&&Rs.length>0&&t.jsxs("div",{className:"flex items-center gap-2 mb-3 text-xs text-text-3 font-sans",children:[t.jsx("span",{children:"Spawning"}),t.jsx(ke,{variant:"accent",children:Bt}),x&&t.jsxs("span",{children:["on ",(At==null?void 0:At.name)||x]}),f&&t.jsxs("span",{children:["as ",f.replace(/\s+/g,"-")]})]}),t.jsx(Ae,{variant:"primary",size:"lg",onClick:As,disabled:!Bt||Gt||Rs.length===0||X0,className:"w-full",children:Gt?"Spawning...":"Spawn Agent"})]})]})}),t.jsx(ja,{open:!!Fs,onOpenChange:ae=>{ae||Es(null)},children:t.jsx(Ma,{title:"Integration Warning",className:"max-w-sm",children:t.jsxs("div",{className:"space-y-4 p-4",children:[t.jsx("div",{className:"space-y-2",children:(Fs||[]).map((ae,Oe)=>t.jsxs("div",{className:"flex items-start gap-2 text-xs text-text-1 font-sans",children:[t.jsx(Jt,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),t.jsx("span",{children:ae.name?`${ae.name}: ${ae.problem==="not_installed"?"not installed":ae.problem==="not_configured"?"not configured":"not authenticated"}`:ae.message||String(ae)})]},Oe))}),t.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Continue anyway?"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(Ae,{variant:"ghost",size:"md",onClick:()=>Es(null),className:"flex-1",children:"Cancel"}),t.jsx(Ae,{variant:"warning",size:"md",onClick:()=>{Es(null),ba()},className:"flex-1",children:"Spawn Anyway"})]})]})})})]})}function sX({title:e,icon:a,defaultOpen:n=!1,badge:s,children:o,className:c}){const[l,d]=y.useState(n);return t.jsxs("div",{className:q("border-t border-border-subtle",c),children:[t.jsxs("button",{onClick:()=>d(!l),className:"w-full flex items-center gap-2 px-5 py-3 text-left cursor-pointer hover:bg-surface-5/30 transition-colors group",children:[t.jsx(aa,{size:12,className:q("text-text-4 transition-transform duration-200 flex-shrink-0",l&&"rotate-90")}),a&&t.jsx(a,{size:13,className:"text-text-3 flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:e}),s&&t.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1.5 py-0.5 rounded",children:s})]}),l&&t.jsx("div",{className:"px-5 pb-4",children:o})]})}function jDe(){const e=$(x=>x.journalistStatus),a=$(x=>x.fetchJournalist),n=$(x=>x.triggerJournalistCycle),[s,o]=y.useState(!0),[c,l]=y.useState(!1);y.useEffect(()=>{a().then(()=>o(!1));const x=setInterval(a,1e4);return()=>clearInterval(x)},[a]);async function d(){l(!0);try{await n()}catch{}l(!1)}if(s)return t.jsxs("div",{className:"p-5 space-y-4",children:[t.jsx(Un,{className:"h-6 w-32 rounded"}),t.jsx(Un,{className:"h-20 rounded-md"}),t.jsx(Un,{className:"h-20 rounded-md"})]});const h=e||{},f=h.lastSynthesis,g=h.history||[];return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center gap-2",children:[t.jsx(Po,{size:16,className:"text-accent"}),t.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Journalist"}),t.jsxs(Ae,{variant:"secondary",size:"sm",onClick:d,disabled:c,className:"gap-1.5 text-2xs",children:[t.jsx(Et,{size:11,className:c?"animate-spin":""}),c?"Running...":"Run Synthesis"]})]}),t.jsx(Ct,{className:"flex-1",children:t.jsxs("div",{className:"px-5 py-4 space-y-5",children:[t.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(ts,{size:10}),t.jsxs("span",{children:[h.cycleCount||0," cycles"]})]}),h.lastCycleTime&&t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(br,{size:10}),t.jsxs("span",{children:["Last: ",ht(h.lastCycleTime)]})]}),t.jsx(ke,{variant:h.cycleCount>0?"success":"default",className:"text-2xs",children:h.cycleCount>0?"Active":"Idle"})]}),(f==null?void 0:f.summary)&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[t.jsx(un,{size:12,className:"text-text-3"}),"Latest Summary"]}),t.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:f.summary})]}),(f==null?void 0:f.projectMap)&&t.jsx(sX,{title:"Project Map",icon:t0,children:t.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:f.projectMap})}),(f==null?void 0:f.decisions)&&t.jsx(sX,{title:"Decisions Log",icon:un,children:t.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:f.decisions})}),g.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[t.jsx(br,{size:12,className:"text-text-3"}),"History (",g.length,")"]}),t.jsx("div",{className:"space-y-1.5",children:g.slice().reverse().slice(0,20).map((x,m)=>t.jsxs("div",{className:"bg-surface-0 rounded-md border border-border-subtle px-3 py-2",children:[t.jsxs("div",{className:"flex items-center gap-2 text-2xs",children:[t.jsxs(ke,{variant:"default",className:"text-2xs",children:["Cycle ",x.cycle]}),t.jsxs("span",{className:"text-text-4 font-sans",children:[x.agentCount," agent",x.agentCount!==1?"s":""]}),t.jsx("span",{className:"text-text-4 font-sans ml-auto",children:ht(x.timestamp)})]}),x.summary&&t.jsx("p",{className:"text-xs text-text-2 font-sans mt-1 leading-relaxed",children:x.summary})]},m))})]}),!f&&g.length===0&&t.jsxs("div",{className:"text-center py-8 text-text-4 font-sans",children:[t.jsx(Po,{size:28,className:"mx-auto mb-2"}),t.jsx("p",{className:"text-sm",children:"No synthesis data yet"}),t.jsx("p",{className:"text-2xs mt-1",children:"The journalist runs automatically when agents are active, or trigger manually above"})]})]})})]})}function MDe({children:e,height:a,onHeightChange:n,visible:s,fullHeight:o,tabs:c,activeTab:l,onSelectTab:d,onAddTab:h,onCloseTab:f,onToggleFullHeight:g,onMinimize:x,onRenameTab:m}){const v=y.useRef(!1),[b,C]=y.useState(null),[j,w]=y.useState(""),Q=y.useRef(0),S=y.useRef(0),_=y.useCallback(B=>{if(o)return;B.preventDefault(),v.current=!0,Q.current=B.clientY,S.current=a;function M(T){if(!v.current)return;const U=Q.current-T.clientY,Y=Math.min(Math.max(S.current+U,120),600);n(Y)}function L(){v.current=!1,document.removeEventListener("mousemove",M),document.removeEventListener("mouseup",L)}document.addEventListener("mousemove",M),document.addEventListener("mouseup",L)},[a,n,o]);if(!s)return null;const F=c||[{id:"default",label:"Terminal"}];return t.jsxs("div",{className:"flex flex-col border-t border-border bg-surface-0 relative",style:o?{flex:1,minHeight:0}:{height:a,flexShrink:0},children:[!o&&t.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 cursor-row-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:_}),t.jsxs("div",{className:"flex items-center h-9 bg-surface-1 border-b border-border flex-shrink-0 pl-0 pr-3",children:[t.jsxs("div",{className:"flex items-center gap-0 flex-1 min-w-0 overflow-x-auto scrollbar-none h-full",children:[F.map(B=>t.jsxs("button",{onClick:()=>d==null?void 0:d(B.id),onDoubleClick:()=>{C(B.id),w(B.label)},className:q("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",B.id===l?"text-text-0 bg-surface-3":"text-text-2 hover:text-text-0 hover:bg-surface-5/50"),children:[t.jsx(jr,{size:11}),b===B.id?t.jsx("input",{className:"bg-transparent border border-border rounded px-1 text-[11px] text-text-0 outline-none w-20 font-sans",value:j,onChange:M=>w(M.target.value),onBlur:()=>{j.trim()&&(m==null||m(B.id,j.trim())),C(null)},onKeyDown:M=>{M.key==="Enter"&&(j.trim()&&(m==null||m(B.id,j.trim())),C(null)),M.key==="Escape"&&C(null)},autoFocus:!0,onClick:M=>M.stopPropagation()}):t.jsx("span",{className:"truncate max-w-[100px]",children:B.label}),F.length>1&&t.jsx("button",{onClick:M=>{M.stopPropagation(),f==null||f(B.id)},className:"ml-1 p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(He,{size:9})})]},B.id)),t.jsx("button",{onClick:h,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:t.jsx(ut,{size:11})})]}),t.jsx("div",{className:"flex items-center gap-0.5 flex-shrink-0 ml-2",children:o?t.jsx("button",{onClick:x,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Restore",children:t.jsx(s0,{size:12})}):t.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:"Maximize",children:t.jsx(md,{size:12})})})]}),t.jsx("div",{className:"flex-1 min-h-0 pl-2 pt-1",children:e})]})}const QDe={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 XU=0;function SDe({tabId:e,visible:a}){const n=y.useRef(null),s=y.useRef(null),o=y.useRef(null),c=y.useRef(null),l=y.useRef(null),d=y.useRef(!1);return y.useEffect(()=>{if(!n.current||d.current)return;d.current=!0;const h=new rae({theme:QDe,fontFamily:"'JetBrains Mono Variable', 'SF 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}),f=new oae;h.loadAddon(f),h.loadAddon(new iae),h.open(n.current),s.current=h,o.current=f;let g=0;function x(){g++;const v=$.getState().ws;if(!v||v.readyState!==WebSocket.OPEN){g<20&&setTimeout(x,500);return}v.send(JSON.stringify({type:"terminal:spawn",cols:h.cols,rows:h.rows}));function b(C){let j;try{j=JSON.parse(C.data)}catch{return}j.type==="terminal:spawned"&&!c.current?c.current=j.id:j.type==="terminal:output"&&j.id===c.current?h.write(j.data):j.type==="terminal:exit"&&j.id===c.current&&(h.write(`\r
8640
+ `:"")+`[Attached: ${P}]`),G.target.value=""}const T=s||n,U=w.trim()&&!n&&!o,Y=C||"api",J=o?"Select a model to start chatting...":c?"Describe the image you want to generate...":f?`Ask your ${f}...`:"Send a message...";return t.jsxs("div",{className:"border-t border-border-subtle px-4 py-3 bg-surface-1",children:[d&&t.jsxs("div",{className:"flex items-center gap-2 mb-2 px-3 py-2 rounded-lg bg-accent/5 border border-accent/15",children:[t.jsx(Pn,{size:12,className:"text-accent flex-shrink-0"}),t.jsxs("span",{className:"flex-1 text-2xs text-text-2 font-sans truncate",children:['Iterating: "',d.prompt,'"']}),t.jsx("button",{onClick:h,className:"text-text-4 hover:text-text-1 cursor-pointer flex-shrink-0",children:t.jsx(Fo,{size:10})})]}),t.jsx("textarea",{ref:S,value:w,onChange:G=>Q(G.target.value),onKeyDown:M,placeholder:J,disabled:o,rows:1,className:q("w-full resize-y rounded-xl px-4 py-2.5 text-sm","bg-surface-0 border text-text-0 font-sans","placeholder:text-text-4","focus:outline-none focus:ring-1","min-h-[40px]","border-border focus:ring-accent/40","disabled:opacity-50 disabled:cursor-not-allowed")}),t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx("input",{ref:_,type:"file",multiple:!0,accept:".pdf,.png,.jpg,.jpeg,.gif,.svg,.csv,.txt,.md,.json,.yaml,.yml,.docx,.pptx,.xlsx",onChange:L,className:"hidden"}),t.jsx("button",{onClick:()=>{var G;return(G=_.current)==null?void 0:G.click()},disabled:o,className:"w-8 h-8 flex items-center justify-center rounded-lg text-text-4 hover:text-text-1 hover:bg-surface-3 transition-colors cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed flex-shrink-0",title:"Attach file",children:t.jsx(gd,{size:14})}),t.jsxs("div",{className:"flex items-center h-7 rounded-lg bg-surface-3 border border-border-subtle p-0.5",children:[t.jsxs("button",{onClick:()=>j==null?void 0:j("api"),className:q("flex items-center gap-1 h-6 px-2 rounded-md text-2xs font-semibold font-sans transition-colors cursor-pointer",Y==="api"?"bg-accent/15 text-accent border border-accent/25":"text-text-3 hover:text-text-1"),title:"Lightweight — fast and cheap, no tools",children:[t.jsx(wt,{size:11})," Chat"]}),t.jsxs("button",{onClick:()=>j==null?void 0:j("agent"),className:q("flex items-center gap-1 h-6 px-2 rounded-md text-2xs font-semibold font-sans transition-colors cursor-pointer",Y==="agent"?"bg-purple/15 text-purple border border-purple/25":"text-text-3 hover:text-text-1"),title:"Full agent — tools, files, session resume",children:[t.jsx(ud,{size:11})," Agent"]})]}),l&&t.jsxs("div",{className:q("flex items-center gap-1 h-6 px-2 rounded-md text-2xs font-mono border",c?"bg-purple/8 border-purple/20 text-purple":"bg-surface-3 border-border-subtle text-text-3"),children:[c&&t.jsx(Pn,{size:9}),t.jsx("span",{className:"max-w-[80px] truncate",children:eF(l)})]}),g&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex items-center h-6 rounded-md bg-surface-3 border border-border-subtle p-0.5",children:oDe.map(G=>t.jsx("button",{onClick:()=>m==null?void 0:m(G.value),className:q("h-5 px-1.5 rounded text-2xs font-semibold font-sans transition-colors cursor-pointer",x===G.value?"bg-accent/15 text-accent":"text-text-4 hover:text-text-1"),title:`Reasoning: ${G.label}`,children:G.label},G.value))}),t.jsx("div",{className:"flex items-center h-6 rounded-md bg-surface-3 border border-border-subtle p-0.5",children:iDe.map(G=>t.jsx("button",{onClick:()=>b==null?void 0:b(G.value),className:q("h-5 px-1.5 rounded text-2xs font-semibold font-sans transition-colors cursor-pointer",v===G.value?"bg-accent/15 text-accent":"text-text-4 hover:text-text-1"),title:`Verbosity: ${G.label}`,children:G.label},G.value))})]}),t.jsx("div",{className:"flex-1"}),T?t.jsx("button",{onClick:a,className:"w-8 h-8 flex items-center justify-center rounded-lg bg-danger/80 text-white hover:bg-danger transition-all cursor-pointer shadow-lg shadow-danger/20 flex-shrink-0",title:"Stop generation",children:t.jsx(Fo,{size:14,fill:"currentColor"})}):t.jsx("button",{onClick:B,disabled:!U,className:q("w-8 h-8 flex items-center justify-center rounded-lg transition-all cursor-pointer flex-shrink-0","disabled:opacity-20 disabled:cursor-not-allowed",U?"bg-accent/15 text-accent hover:bg-accent/25 border border-accent/25":"bg-surface-4 text-text-4"),children:n?t.jsx(Le,{size:14,className:"animate-spin"}):t.jsx(Ga,{size:14})})]})]})}function cDe({onNewChat:e}){return t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"text-center space-y-4",children:[t.jsx("h1",{className:"text-lg font-semibold text-text-1 font-sans",children:"Groove Chat"}),t.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Every provider, every model, full project context."}),t.jsxs("button",{onClick:e,className:"inline-flex items-center gap-2 h-9 px-5 rounded-lg bg-accent/15 text-accent text-sm font-semibold font-sans hover:bg-accent/25 transition-colors cursor-pointer border border-accent/20",children:[t.jsx(ut,{size:14}),"New Chat"]})]})})}function lDe(){const e=$(ie=>ie.conversations),a=$(ie=>ie.activeConversationId),n=$(ie=>ie.conversationMessages),s=$(ie=>ie.sendingMessage),o=$(ie=>ie.streamingConversationId),c=$(ie=>ie.createConversation);$(ie=>ie.setActiveConversation);const l=$(ie=>ie.sendChatMessage),d=$(ie=>ie.sendImageMessage),h=$(ie=>ie.stopAgent),f=$(ie=>ie.stopChatStreaming),g=$(ie=>ie.setConversationMode),x=$(ie=>ie.setConversationModel),m=$(ie=>ie.conversationRoles),v=$(ie=>ie.setConversationRole),b=$(ie=>ie.conversationReasoningEffort),C=$(ie=>ie.setConversationReasoningEffort),j=$(ie=>ie.conversationVerbosity),w=$(ie=>ie.setConversationVerbosity),[Q,S]=y.useState(!1),[_,F]=y.useState(null),B=a&&(m==null?void 0:m[a])||null,M=a&&(b==null?void 0:b[a])||"medium",L=a&&(j==null?void 0:j[a])||"medium",T=e.find(ie=>ie.id===a)||null,U=(T==null?void 0:T.provider)==="codex",Y=a?n[a]||[]:[],J=o===a&&s,G=T?oL(T.model):!1,E=y.useCallback(async(ie,ge)=>{try{await c(ie||null,ge||null,"api")}catch{}},[c]),P=y.useCallback(ie=>{a&&g(a,ie)},[a,g]),I=y.useCallback(ie=>{a&&v(a,ie)},[a,v]),H=y.useCallback(ie=>{if(a)if(G){const ge=_?`${ie} (iterating on: "${_.prompt}")`:ie;d(a,ge,{model:T.model}),F(null)}else l(a,ie)},[a,T,G,_,l,d]),V=y.useCallback(()=>{T&&(T.mode==="agent"&&T.agentId?h(T.agentId):f(a))},[T,a,h,f]),Z=y.useCallback(async ie=>{a?await x(a,ie.provider,ie.model):await E(ie.provider,ie.model)},[a,x,E]),R=y.useCallback(ie=>{F(ie)},[]),pe=y.useCallback(ie=>{a&&C(a,ie)},[a,C]),xe=y.useCallback(ie=>{a&&w(a,ie)},[a,w]),se=T?{provider:T.provider,model:T.model}:null;return t.jsxs("div",{className:"flex h-full bg-surface-0",children:[t.jsx("div",{className:q("flex-shrink-0 border-r border-accent/12 bg-surface-1 transition-all duration-200 overflow-hidden",Q?"w-0":"w-64"),children:t.jsx(Vqe,{onNewChat:()=>E()})}),t.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:T?t.jsxs(t.Fragment,{children:[t.jsx(Xqe,{conversation:T,model:se,onModelChange:Z,onModeChange:P,role:B,onRoleChange:I}),t.jsx(rDe,{messages:Y,isStreaming:J,model:T.model,mode:T.mode||"api",onImageReply:R,role:B}),t.jsx(aX,{onSend:H,onStop:V,sending:s,streaming:J,disabled:!1,isImageModel:G,currentModel:T.model,replyContext:_,onClearReply:()=>F(null),role:B,isCodex:U,reasoningEffort:M,onReasoningEffortChange:pe,verbosity:L,onVerbosityChange:xe,mode:(T==null?void 0:T.mode)||"api",onModeChange:P})]}):t.jsxs(t.Fragment,{children:[t.jsx(cDe,{onNewChat:()=>E()}),t.jsx(aX,{onSend:ie=>{E().then(()=>{setTimeout(()=>{const ge=$.getState().activeConversationId;ge&&l(ge,ie)},500)})},onStop:()=>{},sending:!1,streaming:!1,disabled:!1,isImageModel:!1,currentModel:null})]})})]})}function ADe(){return t.jsx(lDe,{})}function dDe(){return t.jsx(iW,{})}function Kp({options:e,value:a,onChange:n}){return t.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:e.map(s=>t.jsx("button",{onClick:()=>n(s.value),className:q("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",a===s.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:s.label},s.value))})}function Va({label:e,icon:a,children:n,description:s}){return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsxs("label",{className:"flex items-center gap-1.5 text-xs font-semibold text-text-1 font-sans",children:[a&&t.jsx(a,{size:13,className:"text-text-3"}),e]}),s&&t.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:s})]}),n]})}function uDe({agent:e}){const a=$(b=>b.killAgent),n=$(b=>b.rotateAgent),s=$(b=>b.spawnAgent),o=$(b=>b.closeDetail),c=$(b=>b.addToast),[l,d]=y.useState(null),[h,f]=y.useState(!1),g=e.status==="running"||e.status==="starting";async function x(){d("rotate");try{await n(e.id)}catch{}d(null)}async function m(){if(!h){f(!0),setTimeout(()=>f(!1),3e3);return}d("kill");try{await a(e.id,!g),o()}catch{}d(null),f(!1)}async function v(){d("clone");try{await s({role:e.role,provider:e.provider,model:e.model,name:`${e.name}-clone`,scope:e.scope,workingDir:e.workingDir}),c("success",`Cloned ${e.name}`)}catch{}d(null)}return g?t.jsx("div",{className:"space-y-2",children:t.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[t.jsxs(Ae,{variant:"primary",size:"md",onClick:x,disabled:l==="rotate",className:"gap-1.5",children:[t.jsx(wr,{size:12,className:l==="rotate"?"animate-spin":""}),"Rotate"]}),t.jsxs(Ae,{variant:"info",size:"md",onClick:v,disabled:!!l,className:"gap-1.5",children:[t.jsx(pn,{size:12})," Clone"]}),t.jsxs(Ae,{variant:"danger",size:"md",onClick:m,disabled:l==="kill",className:"gap-1.5",children:[t.jsx(bd,{size:12}),h?"Confirm":"Kill"]})]})}):t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[t.jsxs(Ae,{variant:"info",size:"md",onClick:v,disabled:!!l,className:"gap-1.5",children:[t.jsx(pn,{size:12})," Clone"]}),t.jsxs(Ae,{variant:"danger",size:"md",onClick:m,disabled:l==="kill",className:"gap-1.5",children:[t.jsx($t,{size:12}),h?"Confirm":"Remove"]})]})}function hDe({agent:e}){var St;const a=$(te=>te.addToast),n=$(te=>te.remoteHomedir),[s,o]=y.useState([]),[c,l]=y.useState(e.model||""),[d,h]=y.useState(""),[f,g]=y.useState(e.effort||"default"),[x,m]=y.useState(!1),[v,b]=y.useState(""),[C,j]=y.useState(null),[w,Q]=y.useState(!1),[S,_]=y.useState(null),[F,B]=y.useState(e.routingMode||"auto"),[M,L]=y.useState([]),[T,U]=y.useState([]),[Y,J]=y.useState("hr"),[G,E]=y.useState("1"),[P,I]=y.useState(!1),[H,V]=y.useState(""),[Z,R]=y.useState(!1),[pe,xe]=y.useState([]),[se,ie]=y.useState(!1),[ge,de]=y.useState([]),[me,Ue]=y.useState(null),[Te,Tt]=y.useState(!1),[xt,mt]=y.useState(!1),oa=e.status==="running"||e.status==="starting";y.useEffect(()=>{jt(),D.get("/skills/installed").then(ve=>L(Array.isArray(ve)?ve:ve.skills||[])).catch(()=>{}),D.get("/integrations/installed").then(ve=>de(Array.isArray(ve)?ve:[])).catch(()=>{}),D.get("/repos/imported").then(ve=>U((Array.isArray(ve)?ve:[]).filter(_e=>_e.status==="active"))).catch(()=>{}),e.provider==="claude-code"&&D.get("/providers/claude-code/auth").then(ve=>Ue(ve)).catch(()=>Ue(null));function te(){jt()}return window.addEventListener("groove:providers-changed",te),()=>window.removeEventListener("groove:providers-changed",te)},[]);function jt(){D.get("/providers").then(te=>o(Array.isArray(te)?te:[])).catch(()=>{})}y.useEffect(()=>{l(e.model||""),D.get(`/agents/${e.id}/routing/recommend`).then(te=>{B((te==null?void 0:te.mode)||"fixed")}).catch(()=>{})},[e.id,e.model]),y.useEffect(()=>{R(!1),e.personality?D.get(`/personalities/${e.name}`).then(te=>{V((te==null?void 0:te.content)||""),R(!0)}).catch(()=>{V(""),R(!0)}):(V(""),R(!0)),D.get("/personalities").then(te=>{xe(Array.isArray(te)?te:te.personalities||[])}).catch(()=>{})},[e.id,e.name]),y.useEffect(()=>{if(!xt)return;const te=Date.now(),ve=setInterval(()=>{if(Date.now()-te>3e5){mt(!1),clearInterval(ve);return}D.get("/providers/claude-code/auth").then(_e=>{_e!=null&&_e.authenticated&&(Ue(_e),mt(!1),Tt(!1),clearInterval(ve))}).catch(()=>{})},2e3);return()=>clearInterval(ve)},[xt]);const Gt=s.find(te=>te.id===e.provider);async function Vn(te,ve){l(ve);try{const _e={model:ve};te&&te!==e.provider&&(_e.provider=te),await D.patch(`/agents/${e.id}`,_e),a("success",`Model → ${ve}${_e.provider?` (${te})`:""}`)}catch(_e){a("error","Model swap failed",_e.message)}}async function Ps(te){try{await D.patch(`/agents/${e.id}`,{workingDir:te}),a("success",`Working dir → ${te.split("/").pop()||te}`)}catch(ve){a("error","Update failed",ve.message)}}async function zs(te){g(te);try{await D.patch(`/agents/${e.id}`,{effort:te}),a("success",`Effort → ${te}`)}catch(ve){a("error","Update failed",ve.message)}}async function Pa(te){if(!te.trim())return;const ve=[...e.scope||[],te.trim()];try{await D.patch(`/agents/${e.id}`,{scope:ve}),h("")}catch(_e){a("error","Scope update failed",_e.message)}}async function ls(te){const ve=(e.scope||[]).filter((_e,Rt)=>Rt!==te);try{await D.patch(`/agents/${e.id}`,{scope:ve})}catch(_e){a("error","Scope update failed",_e.message)}}async function Fs(te){if(v.trim())try{await D.post(`/credentials/${te}`,{key:v.trim()}),a("success",`API key set for ${te}`),b(""),j(null),jt(),window.dispatchEvent(new CustomEvent("groove:providers-changed"))}catch(ve){a("error","Failed to set key",ve.message)}}async function Es(){Tt(!0);try{await D.post("/providers/claude-code/login"),mt(!0)}catch{Tt(!1)}}const yn=e.spawnedAt||e.createdAt;return t.jsxs("div",{className:"px-5 py-5 space-y-6 overflow-y-auto h-full",children:[t.jsx(Va,{label:"Active Model",icon:Qa,children:t.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-bold font-mono text-text-0",children:e.model||"auto"}),t.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:(Gt==null?void 0:Gt.name)||e.provider})]}),(Gt==null?void 0:Gt.canHotSwap)&&oa&&t.jsxs(ke,{variant:"accent",className:"text-2xs gap-1",children:[t.jsx(wt,{size:8})," Hot-swap"]})]}),((St=Gt==null?void 0:Gt.models)==null?void 0:St.length)>1&&t.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3 pt-3 border-t border-border-subtle",children:Gt.models.filter(te=>!te.disabled).map(te=>{const ve=te.id===e.model;return t.jsx("button",{onClick:()=>Vn(e.provider,te.id),disabled:!1,className:q("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:te.name||te.id},te.id)})})]})}),t.jsx(uDe,{agent:e}),t.jsxs(Va,{label:"Providers",icon:gr,description:"Click a provider to see its models and connection status.",children:[t.jsx("div",{className:"space-y-1.5",children:s.map(te=>{var Bt;const ve=te.id===e.provider,_e=te.authType==="subscription"?te.installed||((Bt=te.authStatus)==null?void 0:Bt.authenticated):te.authType==="local"?te.installed:te.installed&&te.hasKey,Rt=S===te.id,Fd=te.models||[];return t.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[t.jsxs("button",{onClick:()=>_(Rt?null:te.id),className:"w-full flex items-center gap-2.5 px-3 py-2 cursor-pointer hover:bg-surface-4/50 transition-colors",children:[t.jsx("div",{className:q("w-2 h-2 rounded-full flex-shrink-0",_e?"bg-success":"bg-text-4")}),t.jsx("span",{className:q("text-xs font-semibold font-sans flex-1 text-left",_e?"text-text-0":"text-text-3"),children:te.name||te.id}),ve&&t.jsx(ke,{variant:"accent",className:"text-2xs",children:"Active"}),!_e&&t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:te.installed?"No key":"Not installed"}),t.jsx(Lt,{size:12,className:q("text-text-4 transition-transform",Rt&&"rotate-180")})]}),Rt&&te.authType==="local"&&t.jsx("div",{className:"border-t border-border-subtle",children:t.jsx(iJ,{isInstalled:_e,onModelChange:jt})}),Rt&&te.authType!=="local"&&t.jsxs("div",{className:"border-t border-border-subtle",children:[(!_e||te.hasKey)&&t.jsx("div",{className:"px-3 py-2 bg-surface-1/50",children:C===te.id?t.jsxs("div",{className:"flex gap-1.5",children:[t.jsxs("div",{className:"flex-1 relative",children:[t.jsx("input",{value:v,onChange:At=>b(At.target.value),onKeyDown:At=>At.key==="Enter"&&Fs(te.id),type:w?"text":"password",placeholder:`${te.name||te.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}),t.jsx("button",{onClick:()=>Q(!w),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:w?t.jsx(fn,{size:10}):t.jsx(na,{size:10})})]}),t.jsx(Ae,{variant:"primary",size:"sm",onClick:()=>Fs(te.id),disabled:!v.trim(),className:"h-7 px-2 text-2xs",children:"Save"}),t.jsx(Ae,{variant:"ghost",size:"sm",onClick:()=>{j(null),b("")},className:"h-7 px-2 text-2xs",children:"Cancel"})]}):t.jsxs("button",{onClick:()=>{j(te.id),b(""),Q(!1)},className:"flex items-center gap-1.5 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[t.jsx(ns,{size:10}),_e?"Update API key":"Add API key to enable"]})}),_e&&Fd.filter(At=>!At.disabled).length>0&&Fd.filter(At=>!At.disabled).map(At=>{const Ko=te.id===e.provider&&At.id===e.model;return t.jsxs("button",{onClick:()=>Vn(te.id,At.id),disabled:!1,className:q("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",Ko?"text-accent":"text-text-2"),children:[Ko?t.jsx(Ie,{size:11,className:"text-accent flex-shrink-0"}):t.jsx("div",{className:"w-[11px]"}),t.jsx("span",{className:"font-mono flex-1 truncate",children:At.name||At.id}),t.jsx(ke,{variant:Ko?"accent":"default",className:"text-2xs",children:At.tier})]},At.id)})]})]},te.id)})}),oa&&t.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans mt-1.5",children:[t.jsx(Ft,{size:10}),t.jsx("span",{children:"Model changes apply on next rotation or respawn."})]})]}),e.provider==="claude-code"&&me&&!me.authenticated&&t.jsxs("div",{className:"rounded-lg border border-warning/30 bg-warning/5 px-4 py-3 space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ft,{size:13,className:"text-warning flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Claude Code is not signed in"})]}),Te?t.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[t.jsx(Le,{size:12,className:"animate-spin text-accent"}),"Waiting for browser authentication..."]}):t.jsxs(Ae,{variant:"primary",size:"sm",onClick:Es,className:"text-2xs gap-1.5",children:[t.jsx(ft,{size:10}),"Sign in to Claude"]})]}),e.provider==="claude-code"&&(me==null?void 0:me.authenticated)&&t.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[t.jsx("div",{className:"w-2 h-2 rounded-full bg-success flex-shrink-0"}),"Signed in as ",me.email||"Claude user"," (",me.subscriptionType||"subscription",")"]}),t.jsx(Va,{label:"Working Directory",icon:da,description:"The root directory this agent operates in.",children:t.jsxs("div",{className:"flex gap-2",children:[t.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:e.workingDir||"Project root"}),t.jsxs(Ae,{variant:"secondary",size:"md",onClick:()=>m(!0),className:"gap-1.5 flex-shrink-0",children:[t.jsx(pd,{size:14})," Browse"]})]})}),t.jsx(Va,{label:"Permission Mode",icon:mn,description:"Full Send = no approvals. Agent Approve = Fullstack Manager reviews risky operations.",children:t.jsx(Kp,{options:[{value:"full",label:"Full Send"},{value:"auto",label:"Agent Approve"}],value:e.permission||"full",onChange:async te=>{try{await D.patch(`/agents/${e.id}`,{permission:te}),a("success",`Permission → ${te==="full"?"Full Send":"Agent Approve"}`)}catch(ve){a("error","Update failed",ve.message)}}})}),t.jsxs(Va,{label:"Model Routing",icon:ts,description:"How Groove selects models for this agent's tasks.",children:[t.jsx(Kp,{options:[{value:"fixed",label:"Fixed"},{value:"auto",label:"Auto"},{value:"auto-floor",label:"Auto + Floor"}],value:F,onChange:async te=>{B(te);try{await D.post(`/agents/${e.id}/routing`,{mode:te}),a("success",`Routing → ${te}`)}catch(ve){a("error","Update failed",ve.message)}}}),t.jsxs("div",{className:"text-2xs text-text-4 font-sans mt-1",children:[F==="fixed"&&"Uses the selected model for all tasks.",F==="auto"&&"Groove picks Opus/Sonnet/Haiku based on task complexity.",F==="auto-floor"&&"Auto-routes but never drops below Sonnet."]})]}),t.jsx(Va,{label:"File Scope",icon:mn,description:"Restrict which files this agent can access. Empty = unrestricted.",children:t.jsxs("div",{className:"flex flex-wrap gap-2",children:[(e.scope||[]).map((te,ve)=>t.jsxs(ke,{variant:"default",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[te,t.jsx("button",{onClick:()=>ls(ve),className:"hover:text-danger cursor-pointer",children:t.jsx(He,{size:10})})]},ve)),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{value:d,onChange:te=>h(te.target.value),onKeyDown:te=>te.key==="Enter"&&Pa(d),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"}),t.jsx("button",{onClick:()=>Pa(d),disabled:!d.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:t.jsx(ut,{size:12})})]})]})}),t.jsx(Va,{label:"Effort Level",icon:Dh,description:"Controls how deep the agent reasons. Higher = more tokens but better results.",children:t.jsx(Kp,{options:[{value:"min",label:"Min"},{value:"low",label:"Low"},{value:"default",label:"Default"},{value:"high",label:"High"},{value:"max",label:"Max"}],value:f,onChange:zs})}),t.jsx(Va,{label:"Agent Details",icon:gr,children:t.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle divide-y divide-border-subtle",children:[t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"ID"}),t.jsx("span",{className:"text-xs text-text-1 font-mono",children:e.id})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Role"}),t.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:e.role})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Provider"}),t.jsx("span",{className:"text-xs text-text-1 font-mono",children:e.provider})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Model"}),t.jsx("span",{className:"text-xs text-text-1 font-mono",children:e.model||"auto"})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Status"}),t.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:e.status})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Spawned"}),t.jsx("span",{className:"text-xs text-text-1 font-sans",children:yn?ht(yn):"—"})]}),e.sessionId&&t.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[t.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Session"}),t.jsxs("span",{className:"text-xs text-text-1 font-mono",children:[e.sessionId.slice(0,16),"..."]})]})]})}),t.jsx(Va,{label:"Skills",icon:Qt,description:"Attach installed skills to this agent's context.",children:t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(e.skills||[]).map(te=>t.jsxs(ke,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[te,t.jsx("button",{onClick:async()=>{try{await D.delete(`/agents/${e.id}/skills/${te}`),a("success",`Detached ${te}`)}catch(ve){a("error","Detach failed",ve.message)}},className:"hover:text-danger cursor-pointer",children:t.jsx(He,{size:10})})]},te)),M.filter(te=>!(e.skills||[]).includes(te.id)).length>0&&t.jsxs("div",{className:"relative group",children:[t.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:t.jsx(ut,{size:12})}),t.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-[160px]",children:M.filter(te=>!(e.skills||[]).includes(te.id)).map(te=>t.jsx("button",{onClick:async()=>{try{await D.post(`/agents/${e.id}/skills/${te.id}`),a("success",`Attached ${te.name||te.id}`)}catch(ve){a("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:te.name||te.id},te.id))})]}),(e.skills||[]).length===0&&M.length===0&&t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No skills installed — browse the Marketplace"})]})}),t.jsxs(Va,{label:"Integrations",icon:Yt,description:"Attach MCP integrations for external services.",children:[t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(e.integrations||[]).map(te=>{const ve=Sd[te],_e=ge.find(Rt=>Rt.id===te);return t.jsxs(ke,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[ve?t.jsx("img",{src:ve,alt:"",className:"w-2.5 h-2.5"}):t.jsx(Yt,{size:9}),(_e==null?void 0:_e.name)||te,t.jsx("button",{onClick:async()=>{try{await D.delete(`/agents/${e.id}/integrations/${te}`),a("success",`Detached ${(_e==null?void 0:_e.name)||te}`)}catch(Rt){a("error","Detach failed",Rt.message)}},className:"hover:text-danger cursor-pointer",children:t.jsx(He,{size:10})})]},te)}),ge.filter(te=>te.configured!==!1&&!(e.integrations||[]).includes(te.id)).length>0&&t.jsxs("div",{className:"relative group",children:[t.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:t.jsx(ut,{size:12})}),t.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:ge.filter(te=>te.configured!==!1&&!(e.integrations||[]).includes(te.id)).map(te=>{const ve=Sd[te.id];return t.jsxs("button",{onClick:async()=>{try{await D.post(`/agents/${e.id}/integrations/${te.id}`),a("success",`Attached ${te.name||te.id}`)}catch(_e){a("error","Attach failed",_e.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?t.jsx("img",{src:ve,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):t.jsx(Yt,{size:12,className:"text-text-3 flex-shrink-0"}),te.name||te.id]},te.id)})})]}),(e.integrations||[]).length===0&&ge.length===0&&t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No integrations installed — browse the Marketplace"})]}),(e.integrations||[]).length>0&&t.jsxs("div",{className:"mt-3",children:[t.jsx("label",{className:"text-2xs font-medium text-text-3 font-sans block mb-1.5",children:"Integration Approvals"}),t.jsx(Kp,{options:[{value:"auto",label:"Auto"},{value:"manual",label:"Manual"}],value:e.integrationApproval||"manual",onChange:async te=>{try{await D.patch(`/agents/${e.id}`,{integrationApproval:te}),a("success",`Integration approvals → ${te==="auto"?"Auto":"Manual"}`)}catch(ve){a("error","Update failed",ve.message)}}})]})]}),T.length>0&&t.jsx(Va,{label:"Repos",icon:Bs,description:"Attach imported repos so this agent knows where they are.",children:t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(e.repos||[]).map(te=>{const ve=T.find(_e=>_e.id===te);return t.jsxs(ke,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[(ve==null?void 0:ve.name)||te,t.jsx("button",{onClick:async()=>{try{await D.delete(`/agents/${e.id}/repos/${te}`),a("success",`Detached ${(ve==null?void 0:ve.name)||te}`)}catch(_e){a("error","Detach failed",_e.message)}},className:"hover:text-danger cursor-pointer",children:t.jsx(He,{size:10})})]},te)}),T.filter(te=>!(e.repos||[]).includes(te.id)).length>0&&t.jsxs("div",{className:"relative group",children:[t.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:t.jsx(ut,{size:12})}),t.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:T.filter(te=>!(e.repos||[]).includes(te.id)).map(te=>t.jsxs("button",{onClick:async()=>{try{await D.post(`/agents/${e.id}/repos/${te.id}`),a("success",`Attached ${te.name||te.id}`)}catch(ve){a("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:[t.jsx("div",{className:"font-semibold",children:te.name||te.repo}),t.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:te.clonedTo})]},te.id))})]}),(e.repos||[]).length===0&&t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No repos attached — import one from the Marketplace"})]})}),t.jsx(Va,{label:"Schedule",icon:No,description:"Run this agent on a recurring schedule.",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs text-text-2 font-sans",children:"Every"}),t.jsx("input",{value:G,onChange:te=>E(te.target.value.replace(/\D/g,"").slice(0,3)),className:"w-12 h-7 px-2 text-xs text-center bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono focus:outline-none focus:ring-1 focus:ring-accent",placeholder:"1"}),t.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:[{value:"min",label:"Min"},{value:"hr",label:"Hr"},{value:"day",label:"Day"},{value:"wk",label:"Wk"},{value:"mo",label:"Mo"}].map(te=>t.jsx("button",{onClick:()=>J(te.value),className:q("px-2 py-1 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",Y===te.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:te.label},te.value))}),t.jsxs(Ae,{variant:"primary",size:"sm",disabled:P||!G||parseInt(G,10)<1,onClick:async()=>{const te=parseInt(G,10);if(!te||te<1)return;const ve={min:te===1?"* * * * *":`*/${te} * * * *`,hr:te===1?"0 * * * *":`0 */${te} * * *`,day:te===1?"0 0 * * *":`0 0 */${te} * *`,wk:`0 0 * * ${te===1?"1":"*"}`,mo:`0 0 ${te===1?"1":te} * *`};I(!0);try{await D.post("/schedules",{name:`${e.name} schedule`,cron:ve[Y],agentConfig:{role:e.role,provider:e.provider,model:e.model,scope:e.scope,workingDir:e.workingDir,prompt:e.prompt}}),a("success",`Scheduled every ${te} ${Y}`)}catch(_e){a("error","Schedule failed",_e.message)}I(!1)},className:"h-7 px-3 text-2xs gap-1",children:[t.jsx(No,{size:10}),P?"...":"Set"]})]})}),t.jsxs(Va,{label:"Personality",icon:En,description:"Injected into every prompt. Changes apply on next spawn or rotation.",children:[t.jsx("textarea",{value:H,onChange:te=>V(te.target.value),placeholder:Z?"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"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(Ae,{variant:"primary",size:"sm",disabled:se,onClick:async()=>{ie(!0);try{await D.put(`/personalities/${e.name}`,{content:H}),a("success","Personality saved")}catch(te){a("error","Save failed",te.message)}ie(!1)},className:"h-7 px-3 text-2xs gap-1",children:[t.jsx(Od,{size:10}),se?"Saving...":"Save"]}),pe.length>0&&t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:"",onChange:te=>{if(!te.target.value)return;const ve=pe.find(_e=>(_e.name||_e)===te.target.value);ve&&D.get(`/personalities/${ve.name||ve}`).then(_e=>{_e!=null&&_e.content&&V(_e.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:[t.jsx("option",{value:"",children:"Clone from..."}),pe.filter(te=>(te.name||te)!==e.name).map(te=>t.jsx("option",{value:te.name||te,children:te.name||te},te.name||te))]}),t.jsx(Lt,{size:10,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]})]})]}),e.prompt&&t.jsx(Va,{label:"Original Prompt",icon:ts,children:t.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:e.prompt})}),t.jsx(Ou,{open:x,onOpenChange:m,currentPath:e.workingDir||n||"/",homePath:n,onSelect:Ps})]})}const nX=[];function pDe({data:e,isAlive:a,height:n=48}){const s=y.useRef(null);return y.useEffect(()=>{const o=s.current;if(!o||!e.length)return;const c=o.getContext("2d"),l=window.devicePixelRatio||1,d=o.clientWidth,h=o.clientHeight;o.width=d*l,o.height=h*l,c.scale(l,l),c.clearRect(0,0,d,h);const f=e.map(b=>b.v),g=Math.min(...f),m=Math.max(...f,1)-g||1;c.beginPath(),c.moveTo(0,h),e.forEach((b,C)=>{const j=C/(e.length-1)*d,w=h-(b.v-g)/m*(h-4)-2;c.lineTo(j,w)}),c.lineTo(d,h),c.closePath();const v=c.createLinearGradient(0,0,0,h);if(v.addColorStop(0,a?"rgba(51,175,188,0.15)":"rgba(110,118,129,0.08)"),v.addColorStop(1,"rgba(0,0,0,0)"),c.fillStyle=v,c.fill(),c.beginPath(),c.strokeStyle=a?W.accent:W.text3,c.lineWidth=1.5,e.forEach((b,C)=>{const j=C/(e.length-1)*d,w=h-(b.v-g)/m*(h-4)-2;C===0?c.moveTo(j,w):c.lineTo(j,w)}),c.stroke(),e.length>1&&a){const b=e[e.length-1],C=d-1,j=h-(b.v-g)/m*(h-4)-2;c.beginPath(),c.arc(C,j,5,0,Math.PI*2),c.fillStyle="rgba(51,175,188,0.3)",c.fill(),c.beginPath(),c.arc(C,j,2.5,0,Math.PI*2),c.fillStyle=W.accent,c.fill()}},[e,a]),t.jsx("div",{className:"w-full rounded-lg bg-surface-0 overflow-hidden border border-border-subtle",style:{height:n},children:t.jsx("canvas",{ref:s,className:"w-full h-full"})})}function Yp({icon:e,label:a,value:n,color:s,sub:o}){return t.jsxs("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 border border-border-subtle",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx(e,{size:12,className:s||"text-text-3"}),t.jsx("span",{className:"text-2xs text-text-4 font-sans uppercase tracking-wider",children:a})]}),t.jsx("div",{className:q("text-lg font-bold font-mono tabular-nums",s||"text-text-0"),children:n}),o&&t.jsx("div",{className:"text-2xs text-text-4 font-sans mt-0.5",children:o})]})}function fDe({score:e}){const a=Math.min(Math.max(e,0),100);let n=W.success,s="Healthy";return a<40?(n=W.danger,s="Degraded"):a<70&&(n=W.warning,s="Fair"),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[t.jsxs("span",{className:"text-2xs text-text-3 font-sans flex items-center gap-1.5",children:[t.jsx(Kh,{size:11}),"Session Health"]}),t.jsxs("span",{className:"text-xs font-bold font-mono",style:{color:n},children:[a,"/100"]})]}),t.jsx("div",{className:"h-2 bg-surface-0 rounded-full overflow-hidden border border-border-subtle",children:t.jsx("div",{className:"h-full rounded-full transition-all duration-700",style:{width:`${a}%`,background:n}})}),t.jsx("span",{className:"text-2xs font-sans mt-1 block",style:{color:n},children:s})]})}function xDe(e){const a=(e||"").toLowerCase();return a.includes("edit")||a.includes("writ")?{icon:mr,color:"text-warning"}:a.includes("read")||a.includes("view")?{icon:na,color:"text-info"}:a.includes("search")||a.includes("grep")||a.includes("glob")?{icon:ra,color:"text-purple"}:a.includes("bash")||a.includes("command")||a.includes("terminal")?{icon:jr,color:"text-orange"}:a.includes("error")||a.includes("fail")?{icon:Ft,color:"text-danger"}:a.includes("spawn")||a.includes("start")?{icon:wt,color:"text-success"}:a.includes("complet")||a.includes("done")?{icon:$n,color:"text-success"}:{icon:br,color:"text-text-4"}}function mDe({agent:e}){const a=$(l=>l.tokenTimeline[e.id])||nX,n=$(l=>l.activityLog[e.id])||nX,s=e.status==="running"||e.status==="starting",o=y.useMemo(()=>{if(a.length<2)return 0;const l=a.slice(-10),d=(l[l.length-1].t-l[0].t)/6e4,h=l[l.length-1].v-l[0].v;return d>0?Math.round(h/d):0},[a]),c=y.useMemo(()=>{const l=e.contextUsage||0;let d=100;return l>90?d-=50:l>70?d-=25:l>50&&(d-=10),o>5e3?d-=15:o>3e3&&(d-=8),e.status==="crashed"&&(d=10),e.status==="completed"&&(d=95),Math.max(0,Math.min(100,d))},[e.contextUsage,e.status,o]);return t.jsxs("div",{className:"px-5 py-5 space-y-5 overflow-y-auto h-full",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Token Burn"}),s&&t.jsx("span",{className:"text-2xs text-accent font-mono animate-pulse",children:"LIVE"})]}),t.jsx(pDe,{data:a,isAlive:s,height:56})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[t.jsx(Yp,{icon:Hh,label:"Burn Rate",value:o>0?`${tt(o)}/m`:"—",color:o>5e3?"text-danger":o>2e3?"text-warning":"text-text-0"}),t.jsx(Yp,{icon:Rh,label:"Cost",value:Wo(e.costUsd||0),color:"text-text-0"}),t.jsx(Yp,{icon:wr,label:"Rotations",value:e.rotations||"0",color:"text-text-0"}),t.jsx(Yp,{icon:wt,label:"Turns",value:e.turns||"0",color:"text-text-0"})]}),t.jsx(fDe,{score:c}),e.prompt&&t.jsxs("div",{children:[t.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-1.5",children:"Task"}),t.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:e.prompt})]}),n.length>0&&t.jsxs("div",{children:[t.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-2",children:"Activity"}),t.jsxs("div",{className:"space-y-0 relative",children:[t.jsx("div",{className:"absolute left-[9px] top-2 bottom-2 w-px bg-border-subtle"}),n.slice(-12).reverse().map((l,d)=>{const h=xDe(l.text),f=h.icon;return t.jsxs("div",{className:"flex items-start gap-3 py-1.5 relative",children:[t.jsx("div",{className:q("w-[18px] h-[18px] rounded-full flex items-center justify-center flex-shrink-0 z-10","bg-surface-1 border border-border-subtle"),children:t.jsx(f,{size:9,className:h.color})}),t.jsx("span",{className:"text-2xs text-text-2 font-sans flex-1 line-clamp-1 pt-0.5",children:l.text}),t.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0 pt-0.5",children:ht(l.timestamp)})]},d)})]})]})]})}function gDe({agent:e}){const a=$(M=>M.addToast),[n,s]=y.useState([]),[o,c]=y.useState(""),[l,d]=y.useState(null),[h,f]=y.useState(""),[g,x]=y.useState(""),[m,v]=y.useState(!1),[b,C]=y.useState(!1),[j,w]=y.useState("");async function Q(){try{const M=await D.get(`/agents/${e.id}/mdfiles`);s(M.files||[]),c(M.workingDir||"")}catch{}}y.useEffect(()=>{Q()},[e.id]);async function S(M){try{const L=await D.get(`/agents/${e.id}/mdfiles/read?path=${encodeURIComponent(M)}`);f(L.content||""),x(L.content||""),d(M)}catch(L){a("error","Failed to read file",L.message)}}async function _(){if(l){v(!0);try{await D.put(`/agents/${e.id}/mdfiles/write`,{path:l,content:h}),x(h),a("success",`Saved ${l}`)}catch(M){a("error","Save failed",M.message)}v(!1)}}async function F(){const M=j.trim();if(M)try{await D.post(`/agents/${e.id}/mdfiles/create`,{name:M}),w(""),C(!1),a("success",`Created ${M}.md`),Q()}catch(L){a("error","Create failed",L.message)}}const B=h!==g;return l?t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border-subtle",children:[t.jsx("button",{onClick:()=>{d(null),f(""),x("")},className:"p-1 text-text-3 hover:text-text-0 cursor-pointer",children:t.jsx(Ss,{size:14})}),t.jsx(un,{size:12,className:"text-accent"}),t.jsx("span",{className:"text-xs text-text-0 font-sans font-medium flex-1 truncate",children:l}),B&&t.jsx("span",{className:"text-[10px] text-warning font-sans",children:"unsaved"}),t.jsxs("button",{onClick:_,disabled:!B||m,className:q("flex items-center gap-1 px-2.5 py-1 rounded text-2xs font-sans font-medium cursor-pointer transition-colors",B?"bg-accent/15 text-accent hover:bg-accent/25":"text-text-4 opacity-50 cursor-not-allowed"),children:[t.jsx(Od,{size:10}),m?"Saving...":"Save"]})]}),t.jsx("textarea",{value:h,onChange:M=>f(M.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})]}):t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 border-b border-border-subtle",children:[t.jsx(un,{size:12,className:"text-text-3"}),t.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:"Markdown Files"}),t.jsx("button",{onClick:()=>C(!0),className:"p-1 text-text-4 hover:text-accent cursor-pointer",title:"Create file",children:t.jsx(ut,{size:12})}),t.jsx("button",{onClick:Q,className:"p-1 text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(Et,{size:11})})]}),o&&t.jsx("div",{className:"px-4 py-1.5 text-[10px] text-text-4 font-mono truncate border-b border-border-subtle/50",children:o}),b&&t.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-b border-border-subtle bg-surface-0",children:[t.jsx(un,{size:11,className:"text-accent flex-shrink-0"}),t.jsx("input",{autoFocus:!0,value:j,onChange:M=>w(M.target.value),onKeyDown:M=>{M.key==="Enter"&&F(),M.key==="Escape"&&(C(!1),w(""))},placeholder:"filename",className:"flex-1 bg-transparent text-xs text-text-0 font-mono outline-none placeholder:text-text-4"}),t.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:".md"}),t.jsx("button",{onClick:F,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:t.jsx(Od,{size:11})}),t.jsx("button",{onClick:()=>{C(!1),w("")},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(He,{size:11})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:n.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center px-4",children:[t.jsx(un,{size:20,className:"text-text-4 mb-2"}),t.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No markdown files found"}),t.jsx("p",{className:"text-[10px] text-text-4 font-sans mt-1",children:"MD files in the agent's working directory will appear here"})]}):t.jsx("div",{className:"py-1",children:n.map(M=>t.jsxs("button",{onClick:()=>S(M.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:[t.jsx(un,{size:13,className:"text-accent flex-shrink-0"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("span",{className:"text-xs text-text-0 font-sans block truncate",children:M.name}),t.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:M.path})]}),t.jsx("span",{className:"text-[10px] text-text-4 font-mono flex-shrink-0",children:M.size>1024?`${(M.size/1024).toFixed(1)}K`:`${M.size}B`}),M.source==="personality"&&t.jsx("span",{className:"text-[9px] font-mono text-purple bg-purple/10 px-1 py-px rounded flex-shrink-0",children:"personality"}),M.source==="user"&&t.jsx("span",{className:"text-[9px] font-mono text-accent bg-accent/10 px-1 py-px rounded flex-shrink-0",children:"custom"})]},M.path))})})]})}const yDe={running:"success",starting:"warning",stopped:"default",crashed:"danger",completed:"accent",killed:"default",rotating:"purple"},kDe={running:"Running",starting:"Starting",stopped:"Stopped",crashed:"Crashed",completed:"Done",killed:"Killed",rotating:"Rotating"},ODe=[{id:"command",label:"Chat",icon:Ta},{id:"config",label:"Config",icon:Cr},{id:"telemetry",label:"Monitor",icon:ts},{id:"mdfiles",label:"Files",icon:un}];function vDe({agent:e}){const a=$(h=>h.addToast),[n,s]=y.useState(!1),[o,c]=y.useState(e.name),l=y.useRef(null);async function d(){const h=o.trim();if(!h||h===e.name){s(!1);return}try{await D.patch(`/agents/${e.id}`,{name:h.replace(/\s+/g,"-")}),a("success",`Renamed → ${h}`)}catch(f){a("error","Rename failed",f.message),c(e.name)}s(!1)}return n?t.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-0",children:[t.jsx("input",{ref:l,value:o,onChange:h=>c(h.target.value),onKeyDown:h=>{h.key==="Enter"&&d(),h.key==="Escape"&&(c(e.name),s(!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}),t.jsx("button",{onClick:d,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:t.jsx(Ie,{size:12})}),t.jsx("button",{onClick:()=>{c(e.name),s(!1)},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(He,{size:12})})]}):t.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0 group",children:[t.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans truncate",children:e.name}),t.jsx("button",{onClick:()=>{c(e.name),s(!0)},className:"p-0.5 text-text-4 opacity-0 group-hover:opacity-100 hover:text-text-1 cursor-pointer transition-opacity",children:t.jsx(Ns,{size:10})})]})}function bDe(){const e=$(f=>f.detailPanel),a=$(f=>f.agents),[n,s]=y.useState("command");if((e==null?void 0:e.type)!=="agent")return null;const o=a.find(f=>f.id===e.agentId);if(!o)return null;const c=o.status==="running"||o.status==="starting",l=Math.round((o.contextUsage||0)*100),d=o.spawnedAt||o.createdAt,h=d?Math.floor((Date.now()-new Date(d).getTime())/1e3):0;return Za(o.role),t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex-shrink-0",children:[t.jsxs("div",{className:"pl-4 pr-10 pt-3 pb-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(vDe,{agent:o}),t.jsx(ke,{variant:yDe[o.status]||"default",dot:c?"pulse":void 0,className:"text-2xs flex-shrink-0",children:kDe[o.status]||o.status})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1 text-2xs text-text-3 font-mono",children:[t.jsx("span",{className:"capitalize",children:o.role}),t.jsx("span",{className:"text-text-4",children:"·"}),t.jsxs("span",{children:[o.provider,":",o.model||"auto"]}),t.jsx("span",{className:"text-text-4",children:"·"}),t.jsxs("span",{children:[tt(o.tokensUsed||0)," tok"]}),l>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-text-4",children:"·"}),t.jsxs("span",{className:q(l>80?"text-danger":l>60?"text-warning":"text-text-3"),children:[l,"% ctx"]})]}),t.jsx("span",{className:"text-text-4",children:"·"}),t.jsx("span",{children:Ud(h)})]})]}),t.jsx("div",{className:"flex items-center px-4 border-b border-border-subtle",children:ODe.map(f=>{const g=f.icon,x=n===f.id;return t.jsxs("button",{onClick:()=>s(f.id),className:q("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",x?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"),children:[t.jsx(g,{size:11}),f.label]},f.id)})})]}),t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[n==="command"&&t.jsx(jW,{agent:o}),n==="config"&&t.jsx(hDe,{agent:o}),n==="telemetry"&&t.jsx(mDe,{agent:o}),n==="mdfiles"&&t.jsx(gDe,{agent:o})]})]})}const wDe=[{id:"chat",label:"Chat",desc:"Companion, assistant, conversation",icon:En,tier:"Medium"},{id:"planner",label:"Planner",desc:"Plans the team and tasks",icon:zo,tier:"Heavy"},{id:"backend",label:"Backend",desc:"APIs, services, databases",icon:ta,tier:"Medium"},{id:"frontend",label:"Frontend",desc:"UI, components, styling",icon:Uo,tier:"Medium"},{id:"fullstack",label:"Fullstack",desc:"End-to-end implementation",icon:ga,tier:"Heavy"},{id:"testing",label:"Testing",desc:"Tests, coverage, QA",icon:Cd,tier:"Medium"},{id:"devops",label:"DevOps",desc:"CI/CD, infra, deployment",icon:Z1,tier:"Medium"},{id:"docs",label:"Docs",desc:"Documentation, guides",icon:un,tier:"Light"},{id:"security",label:"Security",desc:"Audits, vulnerabilities",icon:mn,tier:"Medium"},{id:"database",label:"Database",desc:"Schema, migrations, queries",icon:G1,tier:"Medium"},{id:"cmo",label:"CMO",desc:"Marketing, content, growth",icon:n0,tier:"Medium"},{id:"cfo",label:"CFO",desc:"Finance, metrics, forecasting",icon:zh,tier:"Medium"},{id:"ea",label:"EA",desc:"Executive assistant, scheduling",icon:h0,tier:"Light"},{id:"support",label:"Support",desc:"Customer support, FAQs",icon:Wh,tier:"Medium"},{id:"analyst",label:"Analyst",desc:"Data analysis, insights",icon:xr,tier:"Medium"},{id:"creative",label:"Writer",desc:"Copy, articles, proposals",icon:ko,tier:"Heavy",skillHint:!0},{id:"slides",label:"Slides",desc:"Pitch decks, presentations",icon:c0,tier:"Heavy",skillHint:!0},{id:"ambassador",label:"Ambassador",desc:"Bridge to federated server",icon:sa,tier:"Light"}];function VU(){return t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"text-accent flex-shrink-0",children:[t.jsx("circle",{cx:"7",cy:"7",r:"6",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1"}),t.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 CDe(){const e=$(ae=>ae.detailPanel),a=$(ae=>ae.closeDetail),n=$(ae=>ae.spawnAgent),s=$(ae=>ae.fetchProviders),o=(e==null?void 0:e.type)==="spawn",[c,l]=y.useState(""),[d,h]=y.useState(""),[f,g]=y.useState(""),[x,m]=y.useState(""),[v,b]=y.useState(""),[C,j]=y.useState(""),[w,Q]=y.useState([]),[S,_]=y.useState([]),[F,B]=y.useState([]),[M,L]=y.useState(!1),[T,U]=y.useState(""),[Y,J]=y.useState([]),[G,E]=y.useState([]),[P,I]=y.useState(!1),[H,V]=y.useState(""),[Z,R]=y.useState("manual"),[pe,xe]=y.useState([]),[se,ie]=y.useState([]),[ge,de]=y.useState(!1),[me,Ue]=y.useState(""),[Te,Tt]=y.useState([]),[xt,mt]=y.useState(""),[oa,jt]=y.useState(!1),[Gt,Vn]=y.useState(!1),[Ps,zs]=y.useState(""),[Pa,ls]=y.useState([]),[Fs,Es]=y.useState(null),[yn,St]=y.useState(null),[te,ve]=y.useState(!1),[_e,Rt]=y.useState(!1),Fd=$(ae=>ae.federation),Bt=c||d,At=w.find(ae=>ae.id===x),Ko=(At==null?void 0:At.models)||[],Rs=w.filter(ae=>ae.authType==="api-key"?ae.installed&&ae.hasKey:ae.installed);y.useEffect(()=>{o&&(s().then(ae=>{const Oe=Array.isArray(ae)?ae:ae.providers||[];Q(Oe);const ze=Oe.filter(Ke=>Ke.authType==="api-key"?Ke.installed&&Ke.hasKey:Ke.installed);if(ze.length>0&&!x){const ds=["claude-code","gemini","codex","ollama"].find(kn=>ze.some(Ir=>Ir.id===kn))||ze[0].id;m(ds)}}).catch(()=>{}),D.get("/skills/installed").then(ae=>{_(Array.isArray(ae)?ae:[])}).catch(()=>{}),D.get("/integrations/installed").then(ae=>{J(Array.isArray(ae)?ae:[])}).catch(()=>{}),D.get("/repos/imported").then(ae=>{xe((Array.isArray(ae)?ae:[]).filter(Oe=>Oe.status==="active"))}).catch(()=>{}),D.get("/personalities").then(ae=>{Tt(Array.isArray(ae)?ae:ae.personalities||[])}).catch(()=>{}),l(""),h(""),g(""),m(""),b(""),j(""),B([]),E([]),R("manual"),ie([]),mt(""),zs(""),jt(!1),ls([]),Es(null),St(null),ve(!1),Rt(!1))},[o,s]),y.useEffect(()=>{if(!Bt||!o){ls([]);return}D.get(`/roles/integrations?role=${encodeURIComponent(Bt)}`).then(ae=>{const Oe=Array.isArray(ae)?ae:(ae==null?void 0:ae.recommendations)||[];ls(Oe);const ze=Oe.filter(Ke=>Ke.installed&&Ke.configured&&Ke.authenticated).map(Ke=>Ke.id);ze.length>0&&E(Ke=>[...new Set([...Ke,...ze])])}).catch(()=>ls([]))},[Bt,o]),y.useEffect(()=>{if(!o||x!=="claude-code"){St(null);return}D.get("/providers/claude-code/auth").then(ae=>{St(ae)}).catch(()=>St(null))},[o,x]),y.useEffect(()=>{if(!_e)return;const ae=Date.now(),Oe=setInterval(()=>{if(Date.now()-ae>3e5){Rt(!1),clearInterval(Oe);return}D.get("/providers/claude-code/auth").then(ze=>{ze!=null&&ze.authenticated&&(St(ze),Rt(!1),ve(!1),clearInterval(Oe))}).catch(()=>{})},2e3);return()=>clearInterval(Oe)},[_e]);async function ba(){Vn(!0);try{const ae={role:Bt,...f&&{name:f.replace(/\s+/g,"-")},...x&&{provider:x},...v&&{model:v},...C&&{prompt:C},...F.length>0&&{skills:F},...G.length>0&&{integrations:G},...G.length>0&&{integrationApproval:Z},...se.length>0&&{repos:se},...xt&&{personality:xt},...Bt==="ambassador"&&Ps&&{peerId:Ps}};await n(ae),a()}catch{}Vn(!1)}async function As(){var ae;if(Bt){try{const Oe=await D.post("/agents/preflight",{role:Bt,integrations:G});if(((ae=Oe==null?void 0:Oe.issues)==null?void 0:ae.length)>0){Es(Oe.issues);return}}catch{}ba()}}async function Sa(){ve(!0);try{await D.post("/providers/claude-code/login"),Rt(!0)}catch{ve(!1)}}const X0=x==="claude-code"&&yn&&!yn.authenticated;return t.jsxs(O$,{open:o,onOpenChange:ae=>{ae||a()},children:[t.jsx(v$,{title:"Spawn Agent",width:480,children:t.jsxs("div",{className:"flex flex-col h-[calc(100%-57px)]",children:[t.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-6",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-3",children:"Choose Role"}),t.jsx("div",{className:"grid grid-cols-2 gap-2",children:wDe.map(ae=>{const Oe=Za(ae.id),ze=c===ae.id;return t.jsxs("button",{onClick:()=>{l(ae.id),h("")},className:q("flex items-center gap-2.5 p-3 rounded-md border text-left transition-all cursor-pointer",ze?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-2"),children:[t.jsx("div",{className:"w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0",style:{background:Oe.bg},children:t.jsx(ae.icon,{size:16,style:{color:Oe.text}})}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ae.label}),ae.skillHint&&t.jsx("span",{className:"text-2xs font-mono text-warning/70 bg-warning/8 px-1 py-px rounded",children:"skill"})]}),t.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:ae.desc})]})]},ae.id)})}),t.jsx("div",{className:"mt-3",children:t.jsx(Ls,{placeholder:"or type a custom role (e.g. chat-agent)...",value:d,onChange:ae=>{h(ae.target.value.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,50)),l("")},className:"text-xs"})})]}),Bt&&Pa.length>0&&t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Recommended Integrations"}),t.jsx("div",{className:"space-y-1.5",children:Pa.map(ae=>{const Oe=Sd[ae.id];return ae.installed&&ae.configured&&ae.authenticated?t.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-success/5 border border-success/20",children:[t.jsx(Ie,{size:13,className:"text-success flex-shrink-0"}),Oe?t.jsx("img",{src:Oe,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):t.jsx(Yt,{size:12,className:"text-text-3 flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ae.name||ae.id}),t.jsx(ke,{variant:"success",className:"text-2xs ml-auto",children:"Ready"})]},ae.id):ae.installed?t.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-warning/5 border border-warning/20",children:[t.jsx(Jt,{size:13,className:"text-warning flex-shrink-0"}),Oe?t.jsx("img",{src:Oe,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):t.jsx(Yt,{size:12,className:"text-text-3 flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ae.name||ae.id}),t.jsx(Ae,{variant:"ghost",size:"sm",className:"ml-auto text-2xs text-warning h-6 px-2",onClick:()=>{a(),$.getState().setActiveView("marketplace")},children:"Configure"})]},ae.id):t.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-surface-1 border border-border-subtle",children:[Oe?t.jsx("img",{src:Oe,alt:"",className:"w-3.5 h-3.5 flex-shrink-0 opacity-40"}):t.jsx(Yt,{size:12,className:"text-text-4 flex-shrink-0"}),t.jsx("span",{className:"text-xs text-text-3 font-sans",children:ae.name||ae.id}),t.jsx("button",{onClick:()=>{a(),$.getState().setActiveView("marketplace")},className:"ml-auto text-2xs text-accent hover:underline font-sans cursor-pointer",children:"Install in Marketplace"})]},ae.id)})})]}),Bt==="ambassador"&&(()=>{const ae=Fd.whitelist.filter(Oe=>typeof Oe=="object"&&(Oe.status==="mutual"||Oe.status==="connected"));return ae.length===0?t.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-4 text-center",children:[t.jsx(sa,{size:18,className:"text-text-4 mx-auto mb-1.5"}),t.jsx("p",{className:"text-2xs text-text-3 font-sans mb-2",children:"No federated servers connected. Add one in the Federation view."}),t.jsx(Ae,{variant:"ghost",size:"sm",className:"text-2xs text-accent",onClick:()=>{a(),$.getState().setActiveView("federation")},children:"Go to Federation"})]}):t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Target Server"}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:Ps,onChange:Oe=>zs(Oe.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[t.jsx("option",{value:"",children:"Select a server..."}),ae.map(Oe=>t.jsx("option",{value:Oe.ip,children:Oe.name||`${Oe.ip}:${Oe.port||31415}`},Oe.ip))]}),t.jsx(Lt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})})(),Bt&&t.jsxs("div",{className:"space-y-4",children:[t.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block",children:"Configuration"}),t.jsx(Ls,{label:"Name (optional)",value:f,onChange:ae=>g(ae.target.value),placeholder:`${Bt}-1`}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Provider"}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:x,onChange:ae=>{m(ae.target.value),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",children:[t.jsx("option",{value:"",children:"Auto"}),w.map(ae=>t.jsxs("option",{value:ae.id,disabled:ae.authType==="api-key"?!(ae.installed&&ae.hasKey):!ae.installed,children:[ae.name,ae.installed?ae.authType==="api-key"&&!ae.hasKey?" (No API key)":"":" (Not installed)"]},ae.id))]}),t.jsx(Lt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Model"}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:v,onChange:ae=>b(ae.target.value),disabled:!x,className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent disabled:opacity-40",children:[t.jsx("option",{value:"",children:"Auto"}),Ko.map(ae=>t.jsx("option",{value:ae.id,children:ae.name},ae.id))]}),t.jsx(Lt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})]}),x&&At&&t.jsx("div",{className:"text-2xs text-text-3 font-sans flex items-center gap-2",children:At.authType==="local"?t.jsx(ke,{variant:"success",children:"Local"}):At.authType==="subscription"?t.jsx(ke,{variant:"accent",children:"Subscription"}):At.hasKey?t.jsx(ke,{variant:"success",children:"API key set"}):t.jsxs(ke,{variant:"warning",children:["No API key — set with: groove set-key ",x," YOUR_KEY"]})}),X0&&t.jsxs("div",{className:"rounded-lg border border-warning/30 bg-warning/5 px-4 py-3",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx(Jt,{size:13,className:"text-warning flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Claude Code is not signed in"})]}),te?t.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[t.jsx(Le,{size:12,className:"animate-spin text-accent"}),"Waiting for browser authentication..."]}):t.jsxs(Ae,{variant:"primary",size:"sm",onClick:Sa,className:"text-2xs gap-1.5",children:[t.jsx(ft,{size:10}),"Sign in to Claude"]})]}),x==="claude-code"&&(yn==null?void 0:yn.authenticated)&&t.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[t.jsx("div",{className:"w-2 h-2 rounded-full bg-success flex-shrink-0"}),"Signed in as ",yn.email||"Claude user"," (",yn.subscriptionType||"subscription",")"]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Skills"}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[F.map(ae=>{const Oe=S.find(ze=>ze.id===ae);return t.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:[t.jsx(Qt,{size:9}),(Oe==null?void 0:Oe.name)||ae,t.jsx("button",{onClick:()=>B(ze=>ze.filter(Ke=>Ke!==ae)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:t.jsx(He,{size:9})})]},ae)}),t.jsxs("button",{onClick:()=>{L(!0),U("")},className:q("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:[t.jsx(Qt,{size:10}),F.length>0?"Add skill":"Attach skill"]})]})]}),t.jsx(ja,{open:M,onOpenChange:L,children:t.jsx(Ma,{title:"Select Skill",className:"max-w-sm",children:t.jsxs("div",{className:"space-y-3 p-4",children:[t.jsxs("div",{className:"relative",children:[t.jsx(ra,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),t.jsx("input",{value:T,onChange:ae=>U(ae.target.value),placeholder:"Search skills...",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"})]}),t.jsxs("div",{className:"max-h-64 overflow-y-auto space-y-1",children:[S.filter(ae=>{if(!T)return!0;const Oe=T.toLowerCase();return(ae.name||ae.id).toLowerCase().includes(Oe)||(ae.description||"").toLowerCase().includes(Oe)}).map(ae=>{const Oe=F.includes(ae.id);return t.jsxs("button",{onClick:()=>{B(ze=>Oe?ze.filter(Ke=>Ke!==ae.id):[...ze,ae.id])},className:q("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors cursor-pointer",Oe?"bg-accent/10 border border-accent/25":"hover:bg-surface-3 border border-transparent"),children:[t.jsx(Qt,{size:12,className:Oe?"text-accent":"text-text-3"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:ae.name||ae.id}),ae.description&&t.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:ae.description})]}),Oe&&t.jsx(VU,{})]},ae.id)}),S.length===0&&t.jsx("div",{className:"text-center py-6 text-xs text-text-3 font-sans",children:"No skills installed. Visit the Marketplace to install skills."})]})]})})}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integrations"}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[G.map(ae=>{const Oe=Y.find(Ke=>Ke.id===ae),ze=Sd[ae];return t.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:[ze?t.jsx("img",{src:ze,alt:"",className:"w-2.5 h-2.5"}):t.jsx(Yt,{size:9}),(Oe==null?void 0:Oe.name)||ae,t.jsx("button",{onClick:()=>E(Ke=>Ke.filter(ds=>ds!==ae)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:t.jsx(He,{size:9})})]},ae)}),t.jsxs("button",{onClick:()=>{I(!0),V("")},className:q("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:[t.jsx(Yt,{size:10}),G.length>0?"Add integration":"Attach integration"]})]})]}),t.jsx(ja,{open:P,onOpenChange:I,children:t.jsx(Ma,{title:"Select Integration",className:"max-w-sm",children:t.jsxs("div",{className:"space-y-3 p-4",children:[t.jsxs("div",{className:"relative",children:[t.jsx(ra,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),t.jsx("input",{value:H,onChange:ae=>V(ae.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"})]}),t.jsxs("div",{className:"max-h-64 overflow-y-auto space-y-1",children:[Y.filter(ae=>{if(!H)return!0;const Oe=H.toLowerCase();return(ae.name||ae.id).toLowerCase().includes(Oe)||(ae.description||"").toLowerCase().includes(Oe)}).map(ae=>{const Oe=G.includes(ae.id),ze=ae.configured!==!1,Ke=Sd[ae.id],ds=Bt&&Array.isArray(ae.roles)&&ae.roles.includes(Bt);return t.jsxs("button",{onClick:()=>{ze&&E(kn=>Oe?kn.filter(Ir=>Ir!==ae.id):[...kn,ae.id])},disabled:!ze,className:q("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors",ze?"cursor-pointer":"opacity-40 cursor-not-allowed",Oe?"bg-accent/10 border border-accent/25":ze?"hover:bg-surface-3 border border-transparent":"border border-transparent"),children:[Ke?t.jsx("img",{src:Ke,alt:"",className:"w-4 h-4 flex-shrink-0"}):t.jsx(Yt,{size:12,className:Oe?"text-accent":"text-text-3"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:ae.name||ae.id}),!ze&&t.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"(not configured)"}),ze&&ds&&t.jsx("span",{className:"text-2xs font-mono text-accent/70 bg-accent/8 px-1 py-px rounded",children:"rec"})]}),ae.description&&t.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:ae.description}),!ze&&t.jsx("div",{className:"text-2xs text-text-4 font-sans",children:"Configure in Marketplace"})]}),Oe&&t.jsx(VU,{})]},ae.id)}),Y.length===0&&t.jsx("div",{className:"text-center py-6 text-xs text-text-3 font-sans",children:"No integrations installed. Visit the Marketplace to install integrations."})]})]})})}),G.length>0&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integration Approvals"}),t.jsxs("div",{className:"flex gap-1.5",children:[t.jsxs("button",{onClick:()=>R("manual"),className:q("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",Z==="manual"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[t.jsx(mn,{size:13,className:Z==="manual"?"text-accent":"text-text-3"}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Manual"}),t.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"You approve each action"})]})]}),t.jsxs("button",{onClick:()=>R("auto"),className:q("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",Z==="auto"?"border-warning bg-warning/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[t.jsx(Qt,{size:13,className:Z==="auto"?"text-warning":"text-text-3"}),t.jsxs("div",{children:[t.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Auto"}),t.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"Agent acts without asking"})]})]})]})]}),pe.length>0&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Repos"}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[se.map(ae=>{const Oe=pe.find(ze=>ze.id===ae);return t.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:[t.jsx(Bs,{size:9}),(Oe==null?void 0:Oe.name)||ae,t.jsx("button",{onClick:()=>ie(ze=>ze.filter(Ke=>Ke!==ae)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:t.jsx(He,{size:9})})]},ae)}),t.jsxs("button",{onClick:()=>{de(!0),Ue("")},className:q("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:[t.jsx(Bs,{size:10}),se.length>0?"Add repo":"Attach repo"]})]})]}),t.jsx(ja,{open:ge,onOpenChange:de,children:t.jsx(Ma,{title:"Select Repository",className:"max-w-sm",children:t.jsxs("div",{className:"space-y-3 p-4",children:[pe.length>1&&t.jsxs("div",{className:"relative",children:[t.jsx(ra,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),t.jsx("input",{value:me,onChange:ae=>Ue(ae.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"})]}),t.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:pe.filter(ae=>{if(!me)return!0;const Oe=me.toLowerCase();return(ae.name||ae.repo||ae.id).toLowerCase().includes(Oe)}).map(ae=>{const Oe=se.includes(ae.id);return t.jsxs("button",{onClick:()=>{ie(ze=>Oe?ze.filter(Ke=>Ke!==ae.id):[...ze,ae.id])},className:q("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors cursor-pointer",Oe?"bg-accent/10 border border-accent/25":"hover:bg-surface-3 border border-transparent"),children:[t.jsx(Bs,{size:12,className:Oe?"text-accent":"text-text-3"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:ae.name||ae.repo}),t.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:ae.clonedTo})]}),Oe&&t.jsx(VU,{})]},ae.id)})})]})})}),(c==="chat"||oa)&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Personality"}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:xt,onChange:ae=>mt(ae.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[t.jsx("option",{value:"",children:"None (blank)"}),Te.map(ae=>t.jsx("option",{value:ae.name||ae,children:ae.name||ae},ae.name||ae))]}),t.jsx(Lt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),t.jsx("p",{className:"text-2xs text-text-4 font-sans",children:"Personality is injected into every prompt for this agent."})]}),c!=="chat"&&!oa&&t.jsx("button",{onClick:()=>jt(!0),className:"text-2xs text-text-3 hover:text-accent font-sans transition-colors cursor-pointer",children:"+ Advanced options"})]})]}),t.jsxs("div",{className:"border-t border-border-subtle px-5 py-4 bg-surface-1",children:[Rs.length===0&&w.length>0&&t.jsxs("div",{className:"flex items-center gap-2 mb-3 px-3 py-2 rounded-md bg-warning/8 border border-warning/20",children:[t.jsx(Jt,{size:13,className:"text-warning flex-shrink-0"}),t.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."})]}),Bt&&Rs.length>0&&t.jsxs("div",{className:"flex items-center gap-2 mb-3 text-xs text-text-3 font-sans",children:[t.jsx("span",{children:"Spawning"}),t.jsx(ke,{variant:"accent",children:Bt}),x&&t.jsxs("span",{children:["on ",(At==null?void 0:At.name)||x]}),f&&t.jsxs("span",{children:["as ",f.replace(/\s+/g,"-")]})]}),t.jsx(Ae,{variant:"primary",size:"lg",onClick:As,disabled:!Bt||Gt||Rs.length===0||X0,className:"w-full",children:Gt?"Spawning...":"Spawn Agent"})]})]})}),t.jsx(ja,{open:!!Fs,onOpenChange:ae=>{ae||Es(null)},children:t.jsx(Ma,{title:"Integration Warning",className:"max-w-sm",children:t.jsxs("div",{className:"space-y-4 p-4",children:[t.jsx("div",{className:"space-y-2",children:(Fs||[]).map((ae,Oe)=>t.jsxs("div",{className:"flex items-start gap-2 text-xs text-text-1 font-sans",children:[t.jsx(Jt,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),t.jsx("span",{children:ae.name?`${ae.name}: ${ae.problem==="not_installed"?"not installed":ae.problem==="not_configured"?"not configured":"not authenticated"}`:ae.message||String(ae)})]},Oe))}),t.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Continue anyway?"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(Ae,{variant:"ghost",size:"md",onClick:()=>Es(null),className:"flex-1",children:"Cancel"}),t.jsx(Ae,{variant:"warning",size:"md",onClick:()=>{Es(null),ba()},className:"flex-1",children:"Spawn Anyway"})]})]})})})]})}function sX({title:e,icon:a,defaultOpen:n=!1,badge:s,children:o,className:c}){const[l,d]=y.useState(n);return t.jsxs("div",{className:q("border-t border-border-subtle",c),children:[t.jsxs("button",{onClick:()=>d(!l),className:"w-full flex items-center gap-2 px-5 py-3 text-left cursor-pointer hover:bg-surface-5/30 transition-colors group",children:[t.jsx(aa,{size:12,className:q("text-text-4 transition-transform duration-200 flex-shrink-0",l&&"rotate-90")}),a&&t.jsx(a,{size:13,className:"text-text-3 flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:e}),s&&t.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1.5 py-0.5 rounded",children:s})]}),l&&t.jsx("div",{className:"px-5 pb-4",children:o})]})}function jDe(){const e=$(x=>x.journalistStatus),a=$(x=>x.fetchJournalist),n=$(x=>x.triggerJournalistCycle),[s,o]=y.useState(!0),[c,l]=y.useState(!1);y.useEffect(()=>{a().then(()=>o(!1));const x=setInterval(a,1e4);return()=>clearInterval(x)},[a]);async function d(){l(!0);try{await n()}catch{}l(!1)}if(s)return t.jsxs("div",{className:"p-5 space-y-4",children:[t.jsx(Un,{className:"h-6 w-32 rounded"}),t.jsx(Un,{className:"h-20 rounded-md"}),t.jsx(Un,{className:"h-20 rounded-md"})]});const h=e||{},f=h.lastSynthesis,g=h.history||[];return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center gap-2",children:[t.jsx(Po,{size:16,className:"text-accent"}),t.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Journalist"}),t.jsxs(Ae,{variant:"secondary",size:"sm",onClick:d,disabled:c,className:"gap-1.5 text-2xs",children:[t.jsx(Et,{size:11,className:c?"animate-spin":""}),c?"Running...":"Run Synthesis"]})]}),t.jsx(Ct,{className:"flex-1",children:t.jsxs("div",{className:"px-5 py-4 space-y-5",children:[t.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(ts,{size:10}),t.jsxs("span",{children:[h.cycleCount||0," cycles"]})]}),h.lastCycleTime&&t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(br,{size:10}),t.jsxs("span",{children:["Last: ",ht(h.lastCycleTime)]})]}),t.jsx(ke,{variant:h.cycleCount>0?"success":"default",className:"text-2xs",children:h.cycleCount>0?"Active":"Idle"})]}),(f==null?void 0:f.summary)&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[t.jsx(un,{size:12,className:"text-text-3"}),"Latest Summary"]}),t.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:f.summary})]}),(f==null?void 0:f.projectMap)&&t.jsx(sX,{title:"Project Map",icon:t0,children:t.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:f.projectMap})}),(f==null?void 0:f.decisions)&&t.jsx(sX,{title:"Decisions Log",icon:un,children:t.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:f.decisions})}),g.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[t.jsx(br,{size:12,className:"text-text-3"}),"History (",g.length,")"]}),t.jsx("div",{className:"space-y-1.5",children:g.slice().reverse().slice(0,20).map((x,m)=>t.jsxs("div",{className:"bg-surface-0 rounded-md border border-border-subtle px-3 py-2",children:[t.jsxs("div",{className:"flex items-center gap-2 text-2xs",children:[t.jsxs(ke,{variant:"default",className:"text-2xs",children:["Cycle ",x.cycle]}),t.jsxs("span",{className:"text-text-4 font-sans",children:[x.agentCount," agent",x.agentCount!==1?"s":""]}),t.jsx("span",{className:"text-text-4 font-sans ml-auto",children:ht(x.timestamp)})]}),x.summary&&t.jsx("p",{className:"text-xs text-text-2 font-sans mt-1 leading-relaxed",children:x.summary})]},m))})]}),!f&&g.length===0&&t.jsxs("div",{className:"text-center py-8 text-text-4 font-sans",children:[t.jsx(Po,{size:28,className:"mx-auto mb-2"}),t.jsx("p",{className:"text-sm",children:"No synthesis data yet"}),t.jsx("p",{className:"text-2xs mt-1",children:"The journalist runs automatically when agents are active, or trigger manually above"})]})]})})]})}function MDe({children:e,height:a,onHeightChange:n,visible:s,fullHeight:o,tabs:c,activeTab:l,onSelectTab:d,onAddTab:h,onCloseTab:f,onToggleFullHeight:g,onMinimize:x,onRenameTab:m}){const v=y.useRef(!1),[b,C]=y.useState(null),[j,w]=y.useState(""),Q=y.useRef(0),S=y.useRef(0),_=y.useCallback(B=>{if(o)return;B.preventDefault(),v.current=!0,Q.current=B.clientY,S.current=a;function M(T){if(!v.current)return;const U=Q.current-T.clientY,Y=Math.min(Math.max(S.current+U,120),600);n(Y)}function L(){v.current=!1,document.removeEventListener("mousemove",M),document.removeEventListener("mouseup",L)}document.addEventListener("mousemove",M),document.addEventListener("mouseup",L)},[a,n,o]);if(!s)return null;const F=c||[{id:"default",label:"Terminal"}];return t.jsxs("div",{className:"flex flex-col border-t border-border bg-surface-0 relative",style:o?{flex:1,minHeight:0}:{height:a,flexShrink:0},children:[!o&&t.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 cursor-row-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:_}),t.jsxs("div",{className:"flex items-center h-9 bg-surface-1 border-b border-border flex-shrink-0 pl-0 pr-3",children:[t.jsxs("div",{className:"flex items-center gap-0 flex-1 min-w-0 overflow-x-auto scrollbar-none h-full",children:[F.map(B=>t.jsxs("button",{onClick:()=>d==null?void 0:d(B.id),onDoubleClick:()=>{C(B.id),w(B.label)},className:q("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",B.id===l?"text-text-0 bg-surface-3":"text-text-2 hover:text-text-0 hover:bg-surface-5/50"),children:[t.jsx(jr,{size:11}),b===B.id?t.jsx("input",{className:"bg-transparent border border-border rounded px-1 text-[11px] text-text-0 outline-none w-20 font-sans",value:j,onChange:M=>w(M.target.value),onBlur:()=>{j.trim()&&(m==null||m(B.id,j.trim())),C(null)},onKeyDown:M=>{M.key==="Enter"&&(j.trim()&&(m==null||m(B.id,j.trim())),C(null)),M.key==="Escape"&&C(null)},autoFocus:!0,onClick:M=>M.stopPropagation()}):t.jsx("span",{className:"truncate max-w-[100px]",children:B.label}),F.length>1&&t.jsx("button",{onClick:M=>{M.stopPropagation(),f==null||f(B.id)},className:"ml-1 p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 cursor-pointer",children:t.jsx(He,{size:9})})]},B.id)),t.jsx("button",{onClick:h,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:t.jsx(ut,{size:11})})]}),t.jsx("div",{className:"flex items-center gap-0.5 flex-shrink-0 ml-2",children:o?t.jsx("button",{onClick:x,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Restore",children:t.jsx(s0,{size:12})}):t.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:"Maximize",children:t.jsx(md,{size:12})})})]}),t.jsx("div",{className:"flex-1 min-h-0 pl-2 pt-1",children:e})]})}const QDe={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 XU=0;function SDe({tabId:e,visible:a}){const n=y.useRef(null),s=y.useRef(null),o=y.useRef(null),c=y.useRef(null),l=y.useRef(null),d=y.useRef(!1);return y.useEffect(()=>{if(!n.current||d.current)return;d.current=!0;const h=new rae({theme:QDe,fontFamily:"'JetBrains Mono Variable', 'SF 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}),f=new oae;h.loadAddon(f),h.loadAddon(new iae),h.open(n.current),s.current=h,o.current=f;let g=0;function x(){g++;const v=$.getState().ws;if(!v||v.readyState!==WebSocket.OPEN){g<20&&setTimeout(x,500);return}v.send(JSON.stringify({type:"terminal:spawn",cols:h.cols,rows:h.rows}));function b(C){let j;try{j=JSON.parse(C.data)}catch{return}j.type==="terminal:spawned"&&!c.current?c.current=j.id:j.type==="terminal:output"&&j.id===c.current?h.write(j.data):j.type==="terminal:exit"&&j.id===c.current&&(h.write(`\r
8641
8641
  \x1B[90m[session ended]\x1B[0m\r
8642
8642
  `),c.current=null)}v.addEventListener("message",b),l.current={ws:v,handler:b},h.onData(C=>{const j=$.getState().ws;(j==null?void 0:j.readyState)===WebSocket.OPEN&&c.current&&j.send(JSON.stringify({type:"terminal:input",id:c.current,data:C}))}),h.onResize(({cols:C,rows:j})=>{const w=$.getState().ws;(w==null?void 0:w.readyState)===WebSocket.OPEN&&c.current&&w.send(JSON.stringify({type:"terminal:resize",id:c.current,rows:j,cols:C}))})}requestAnimationFrame(()=>{try{f.fit()}catch{}x()});const m=new ResizeObserver(()=>{requestAnimationFrame(()=>{try{f.fit()}catch{}})});return m.observe(n.current),()=>{m.disconnect();const v=$.getState().ws;(v==null?void 0:v.readyState)===WebSocket.OPEN&&c.current&&v.send(JSON.stringify({type:"terminal:kill",id:c.current})),l.current&&l.current.ws.removeEventListener("message",l.current.handler),h.dispose(),o.current=null,d.current=!1}},[]),y.useEffect(()=>{a&&o.current&&requestAnimationFrame(()=>{try{o.current.fit()}catch{}})},[a]),t.jsx("div",{ref:n,className:"w-full h-full overflow-hidden",style:{display:a?"block":"none"}})}function BDe(){const e=$(v=>v.terminalVisible),a=$(v=>v.terminalHeight),n=$(v=>v.setTerminalVisible),s=$(v=>v.setTerminalHeight),o=$(v=>v.terminalFullHeight),c=$(v=>v.setTerminalFullHeight),[l,d]=y.useState([{id:"term-0",label:"Terminal"}]),[h,f]=y.useState("term-0"),g=y.useCallback(()=>{XU++;const v=`term-${XU}`;d(b=>[...b,{id:v,label:`Terminal ${XU+1}`}]),f(v)},[]),x=y.useCallback((v,b)=>{d(C=>C.map(j=>j.id===v?{...j,label:b}:j))},[]),m=y.useCallback(v=>{d(b=>{const C=b.filter(j=>j.id!==v);if(C.length===0)return n(!1),b;if(h===v){const j=b.findIndex(Q=>Q.id===v),w=C[Math.min(j,C.length-1)];f(w.id)}return C})},[h,n]);return t.jsx(MDe,{visible:e,height:a,onHeightChange:s,fullHeight:o,tabs:l,activeTab:h,onSelectTab:f,onAddTab:g,onCloseTab:m,onRenameTab:x,onToggleFullHeight:()=>c(!0),onMinimize:()=>c(!1),children:l.map(v=>t.jsx(SDe,{tabId:v.id,visible:v.id===h},v.id))})}class Jp extends uo.Component{constructor(a){super(a),this.state={error:null}}static getDerivedStateFromError(a){return{error:a}}render(){return this.state.error?t.jsxs("div",{className:"h-screen bg-surface-0 p-10 font-sans",children:[t.jsx("h2",{className:"text-lg font-semibold text-text-0 mb-4",children:"Groove — Render Error"}),t.jsx("pre",{className:"text-sm text-danger whitespace-pre-wrap mb-4",children:this.state.error.message}),t.jsx("pre",{className:"text-xs text-text-3 whitespace-pre-wrap",children:this.state.error.stack}),t.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 NDe(){const e=$(c=>c.activeView),a=$(c=>c.detailPanel);$(c=>c.agents);const n=$(c=>c.networkUnlocked);let s;switch(e){case"agents":s=t.jsx(FU,{});break;case"editor":s=t.jsx(TEe,{});break;case"dashboard":s=t.jsx(hRe,{});break;case"marketplace":s=t.jsx(FRe,{});break;case"toys":s=t.jsx(qHe,{});break;case"teams":s=t.jsx(DRe,{});break;case"models":s=t.jsx(vHe,{});break;case"federation":s=t.jsx(THe,{});break;case"settings":s=t.jsx(pHe,{});break;case"chat":s=t.jsx(ADe,{});break;case"preview":s=t.jsx(dDe,{});break;case"network":s=n?t.jsx(Pqe,{}):t.jsx(FU,{});break;default:s=t.jsx(FU,{})}let o=null;if(a)switch(a.type){case"agent":{o=t.jsx(bDe,{});break}case"journalist":o=t.jsx(jDe,{});break;case"spawn":o=null;break}return t.jsxs(iEe,{detailContent:o,terminalContent:t.jsx(BDe,{}),children:[s,t.jsx(CDe,{})]})}function _De(){const e=$(n=>n.remoteHomedir),a=$(n=>n.setProjectDir);return t.jsxs("div",{className:"fixed inset-0 z-40 bg-surface-0 flex flex-col items-center justify-center gap-3",children:[t.jsx("img",{src:"/favicon.png",alt:"",className:"w-10 h-10 opacity-60"}),t.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Connected — choose a project directory to continue"}),t.jsx(Ou,{open:!0,onOpenChange:()=>{},currentPath:e||"/home",homePath:e,onSelect:n=>a(n),mandatory:!0})]})}function LDe(){return t.jsxs("div",{className:"h-screen bg-surface-0 flex flex-col items-center justify-center gap-4",children:[t.jsx("img",{src:"/favicon.png",alt:"",className:"w-10 h-10 opacity-60 animate-pulse"}),t.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Connecting..."})]})}function $De(){const e=$(l=>l.connect),a=$(l=>l.hydrated),n=$(l=>l.tunneled),s=$(l=>l.onboardingComplete),o=$(l=>l.showProjectPicker);y.useEffect(()=>{e()},[e]),y.useEffect(()=>{async function l(){var f;if((f=window.groove)!=null&&f.getInstanceInfo){const g=await window.groove.getInstanceInfo();if(g!=null&&g.name){document.title=`${g.name} — Groove`;return}}const h=new URLSearchParams(window.location.search).get("instance");if(h){const g=h.replace(/[\x00-\x1F]/g,"").slice(0,50);document.title=`${g} — Groove`}else n?document.title="Remote — Groove":document.title="Groove"}l()},[n]);const c=y.useMemo(()=>{var l;return(l=window.groove)!=null&&l.openFolder?[{key:"o",meta:!0,handler:()=>window.groove.openFolder()}]:[]},[]);return pX(c),a?s?o&&n?t.jsx(Jp,{children:t.jsx(_De,{})}):o?t.jsxs(Jp,{children:[t.jsx(OEe,{}),t.jsx(FV,{})]}):t.jsxs(Jp,{children:[t.jsx(NDe,{}),t.jsx(FV,{})]}):t.jsx(Jp,{children:t.jsx(yEe,{})}):t.jsx(LDe,{})}uae.createRoot(document.getElementById("root")).render(t.jsx(y.StrictMode,{children:t.jsx($De,{})}));
@@ -6,7 +6,7 @@
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <link rel="icon" type="image/png" href="/favicon.png" />
8
8
  <title>Groove GUI</title>
9
- <script type="module" crossorigin src="/assets/index-BKD8JAsV.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-MLIZRMj1.js"></script>
10
10
  <link rel="modulepreload" crossorigin href="/assets/vendor-C0HXlhrU.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/reactflow-BQPfi37R.js">
12
12
  <link rel="modulepreload" crossorigin href="/assets/codemirror-BBL3i_JW.js">
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@groove-dev/gui",
3
- "version": "0.27.89",
3
+ "version": "0.27.91",
4
4
  "description": "GROOVE GUI — visual agent control plane",
5
5
  "license": "FSL-1.1-Apache-2.0",
6
6
  "type": "module",
@@ -64,10 +64,8 @@ export function ChatView() {
64
64
  const currentModelIsImage = activeConversation ? isImageModel(activeConversation.model) : false;
65
65
 
66
66
  const handleNewChat = useCallback(async (provider, model) => {
67
- const p = provider || 'claude-code';
68
- const m = model || 'claude-sonnet-4-6';
69
67
  try {
70
- await createConversation(p, m, 'api');
68
+ await createConversation(provider || null, model || null, 'api');
71
69
  } catch { /* toast handles */ }
72
70
  }, [createConversation]);
73
71
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "groove-dev",
3
- "version": "0.27.89",
3
+ "version": "0.27.91",
4
4
  "description": "Open-source agent orchestration layer — the AI company OS. Local model agent engine (GGUF/Ollama/llama-server), HuggingFace model browser, MCP integrations (Slack, Gmail, Stripe, 15+), agent scheduling (cron), business roles (CMO, CFO, EA). GUI dashboard, multi-agent coordination, zero cold-start, infinite sessions. Works with Claude Code, Codex, Gemini CLI, Ollama, any local model.",
5
5
  "license": "FSL-1.1-Apache-2.0",
6
6
  "author": "Groove Dev <hello@groovedev.ai> (https://groovedev.ai)",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@groove-dev/cli",
3
- "version": "0.27.89",
3
+ "version": "0.27.91",
4
4
  "description": "GROOVE CLI — manage AI coding agents from your terminal",
5
5
  "license": "FSL-1.1-Apache-2.0",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@groove-dev/daemon",
3
- "version": "0.27.89",
3
+ "version": "0.27.91",
4
4
  "description": "GROOVE daemon — agent orchestration engine",
5
5
  "license": "FSL-1.1-Apache-2.0",
6
6
  "type": "module",