groove-dev 0.27.204 → 0.27.206
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@groove-dev/cli/package.json +1 -1
- package/node_modules/@groove-dev/daemon/package.json +1 -1
- package/node_modules/@groove-dev/daemon/src/axom-connector.js +8 -0
- package/node_modules/@groove-dev/daemon/test/axom-connector.test.js +12 -0
- package/node_modules/@groove-dev/gui/dist/assets/{index-BFlf13cA.js → index-BYQ4qIHh.js} +1 -1
- package/node_modules/@groove-dev/gui/dist/index.html +1 -1
- package/node_modules/@groove-dev/gui/package.json +1 -1
- package/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/daemon/package.json +1 -1
- package/packages/daemon/src/axom-connector.js +8 -0
- package/packages/gui/dist/assets/{index-BFlf13cA.js → index-BYQ4qIHh.js} +1 -1
- package/packages/gui/dist/index.html +1 -1
- package/packages/gui/package.json +1 -1
|
@@ -1084,6 +1084,6 @@ After gathering enough info, generate a JSON config block wrapped in \`\`\`json
|
|
|
1084
1084
|
Make the prompt comprehensive — include identity, philosophy, available tools, failure handling, and the never-park directive.
|
|
1085
1085
|
Make the roadmap have 2-4 stages with clear graduation criteria.
|
|
1086
1086
|
Keep the conversation friendly and efficient. Ask one question at a time.`;function hoe({msg:t}){const s=t.role==="user";return e.jsxs("div",{className:X("flex gap-2",s?"justify-end":"justify-start"),children:[!s&&e.jsx("div",{className:"w-6 h-6 rounded-full bg-accent/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(dn,{size:12,className:"text-accent"})}),e.jsx("div",{className:X("max-w-[85%] rounded-lg px-3 py-2 text-xs font-sans",s?"bg-accent text-surface-0 rounded-br-sm":"bg-surface-2 text-text-1 rounded-bl-sm"),children:e.jsx("p",{className:"whitespace-pre-wrap",children:t.content})})]})}function poe({config:t,onDeploy:s,onEdit:n,deploying:a}){var c,A;const[r,i]=p.useState(!1);return e.jsxs("div",{className:"rounded-lg border border-accent/30 bg-accent/5 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Io,{size:16,className:"text-accent"}),e.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans",children:"Ready to Deploy"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs font-sans",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-text-4 text-2xs",children:"Name"}),e.jsx("p",{className:"text-text-0",children:t.name})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-4 text-2xs",children:"Cadence"}),e.jsx("p",{className:"text-text-0",children:((c=xoe.find(u=>u.value===t.cadence))==null?void 0:c.label)||t.cadence})]})]}),t.description&&e.jsx("p",{className:"text-xs text-text-2 font-sans",children:t.description}),((A=t.guardrails)==null?void 0:A.length)>0&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-2xs text-text-4 font-sans flex items-center gap-1",children:[e.jsx(Qn,{size:10})," Guardrails"]}),e.jsx("ul",{className:"text-2xs text-text-2 font-sans mt-1 space-y-0.5",children:t.guardrails.map((u,x)=>e.jsxs("li",{children:["• ",u]},x))})]}),e.jsxs("button",{onClick:()=>i(!r),className:"text-2xs text-accent font-sans flex items-center gap-1 cursor-pointer hover:underline",children:[r?e.jsx(_b,{size:10}):e.jsx(rt,{size:10}),r?"Hide":"Show"," full config"]}),r&&e.jsx("pre",{className:"text-2xs font-mono text-text-3 bg-surface-0 rounded p-2 overflow-x-auto max-h-48 overflow-y-auto border border-border-subtle",children:JSON.stringify(t,null,2)}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(xe,{variant:"primary",size:"sm",onClick:s,disabled:a,className:"flex-1 gap-1.5",children:a?"Deploying...":e.jsxs(e.Fragment,{children:[e.jsx(Ye,{size:12})," Deploy Agent"]})}),e.jsxs(xe,{variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[e.jsx(GS,{size:12})," Edit"]})]})]})}function AQ(){const t=k(B=>B.autoAgentWizardOpen),s=k(B=>B.closeAutoAgentWizard),n=k(B=>B.createAutoAgent),a=k(B=>B.setActiveView),[r,i]=p.useState([]),[c,A]=p.useState(""),[u,x]=p.useState(!1),[h,O]=p.useState(null),[g,b]=p.useState(!1),y=p.useRef(null),v=p.useRef(null);p.useEffect(()=>{t&&r.length===0&&(i([{role:"assistant",content:"Hey! I'll help you set up an autonomous agent. What task do you want it to handle? Tell me what you're trying to accomplish and I'll help configure everything."}]),O(null))},[t]),p.useEffect(()=>{y.current&&(y.current.scrollTop=y.current.scrollHeight)},[r]);const S=p.useCallback(async()=>{if(!c.trim()||u)return;const B={role:"user",content:c.trim()},C=[...r,B];i(C),A(""),x(!0);try{const P=C.map(R=>({role:R.role,content:R.content})),U=await H.post("/auto-agents/setup-chat",{messages:P,systemPrompt:moe}),T={role:"assistant",content:U.response};i(R=>[...R,T]),U.config&&O(U.config)}catch(P){i(U=>[...U,{role:"assistant",content:`Sorry, I hit an error: ${P.message}. Let me try again — could you rephrase that?`}])}finally{x(!1)}},[c,r,u]),j=p.useCallback(async()=>{if(h){b(!0);try{await n(h)&&a("auto-agents")}finally{b(!1)}}},[h]),N=()=>{s(),i([]),O(null),A("")};return e.jsx(V0,{open:t,onOpenChange:B=>{B||N()},children:e.jsx(K0,{title:"New Auto Agent",width:520,onClose:N,children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{ref:y,className:"flex-1 overflow-y-auto px-4 py-4 space-y-3",children:[r.map((B,C)=>e.jsx(hoe,{msg:B},C)),u&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-accent/10 flex items-center justify-center flex-shrink-0",children:e.jsx(dn,{size:12,className:"text-accent animate-pulse"})}),e.jsx("div",{className:"bg-surface-2 rounded-lg px-3 py-2 rounded-bl-sm",children:e.jsx("span",{className:"text-xs text-text-3 font-sans animate-pulse",children:"Thinking..."})})]}),h&&e.jsx(poe,{config:h,onDeploy:j,onEdit:()=>O(null),deploying:g})]}),e.jsxs("div",{className:"border-t border-border-subtle px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{ref:v,type:"text",value:c,onChange:B=>A(B.target.value),onKeyDown:B=>{B.key==="Enter"&&!B.shiftKey&&(B.preventDefault(),S())},placeholder:h?"Ask to adjust the config...":"Describe what you want the agent to do...",className:"flex-1 bg-surface-0 border border-border-subtle rounded-md px-3 py-2 text-xs text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:border-accent",disabled:u}),e.jsx(xe,{variant:"primary",size:"icon-sm",onClick:S,disabled:!c.trim()||u,children:e.jsx(Kn,{size:14})})]}),!h&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:["ML training pipeline","Content generation","Data monitoring","Code review"].map(B=>e.jsx("button",{onClick:()=>{var C;A(B),(C=v.current)==null||C.focus()},className:"px-2 py-0.5 text-2xs font-sans text-text-3 bg-surface-2 rounded-full hover:bg-surface-3 cursor-pointer transition-colors",children:B},B))})]})]})})})}function goe(){const t=k(i=>i.autoAgents),s=k(i=>i.fetchAutoAgents),n=k(i=>i.openAutoAgentWizard),a=k(i=>i.selectedAutoAgentId),r=k(i=>i.selectAutoAgent);return p.useEffect(()=>{s();const i=setInterval(s,1e4);return()=>clearInterval(i)},[]),a?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(foe,{agentId:a,onBack:()=>r(null)}),e.jsx(AQ,{})]}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border-subtle bg-surface-1",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-0 font-sans uppercase tracking-wide",children:"Auto Agents"}),e.jsxs(xe,{variant:"primary",size:"sm",onClick:n,className:"gap-1.5",children:[e.jsx(ot,{size:12})," New Auto Agent"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:t.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:e.jsxs("div",{className:"text-center space-y-3 py-20",children:[e.jsx(Io,{size:28,className:"mx-auto text-text-4"}),e.jsx("p",{className:"text-xs font-sans text-text-3",children:"No auto agents yet"}),e.jsx("p",{className:"text-2xs font-sans text-text-4 max-w-xs mx-auto",children:"Auto agents run autonomously on a schedule — iterating, learning, and making progress on complex tasks 24/7."}),e.jsxs(xe,{variant:"primary",size:"sm",onClick:n,className:"gap-1.5 mt-2",children:[e.jsx(ot,{size:12})," Create Auto Agent"]})]})}):e.jsx("div",{className:"p-4 space-y-3",children:t.map(i=>e.jsx(loe,{agent:i},i.id))})}),e.jsx(AQ,{})]})}function dQ(t){return t?t>1e9?`${(t/1e9).toFixed(2)} GB`:`${Math.round(t/1e6)} MB`:"0 MB"}function Df({icon:t,label:s,value:n,unit:a,sub:r,tone:i="text-text-0",meter:c}){return e.jsxs("div",{className:"relative rounded-lg bg-surface-1 border border-border-subtle px-3.5 py-3 flex flex-col gap-1.5 min-w-0",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-2xs uppercase tracking-[0.12em] text-text-4 font-semibold",children:[e.jsx(t,{size:11,strokeWidth:1.75})," ",s]}),e.jsxs("span",{className:"flex items-baseline gap-1 min-w-0",children:[e.jsx("span",{className:X("font-mono text-xl font-semibold leading-none tabular-nums truncate",i),children:n}),a&&e.jsx("span",{className:"text-xs text-text-3 font-medium flex-shrink-0",children:a})]}),r&&e.jsx("span",{className:"text-2xs text-text-4 truncate",children:r}),c&&e.jsx("div",{className:"h-[3px] mt-0.5 rounded-full bg-surface-4 overflow-hidden",children:e.jsx("div",{className:X("h-full rounded-full transition-[width] duration-700 ease-out",c.tone),style:{width:`${c.pct}%`}})})]})}const Ooe={ready:{icon:To,pill:"Ready for local Axom",tone:"text-success border-success/30 bg-success/10",meterTone:"bg-success",detail:"Meets the recommended spec — expect a comfortable ride."},marginal:{icon:fc,pill:"Meets the minimum",tone:"text-warning border-warning/30 bg-warning/10",meterTone:"bg-warning",detail:"Local Axom will run, but expect slower turns and tight memory. Close heavy apps first."},insufficient:{icon:Ss,pill:"Not enough memory",tone:"text-danger border-danger/30 bg-danger/10",meterTone:"bg-danger",detail:"Loading the 4 GB chassis here risks freezing the whole machine — so GROOVE won’t. Connect to an Axom on a capable machine instead; same tab, same experience."}},boe=[{icon:rm,label:"Hot-swap skill leaves"},{icon:jt,label:"Steer it mid-thought"},{icon:ZA,label:"Answers that crystallize"},{icon:Zi,label:"Memory that stays yours"}];function uQ(t){const s=(t||"").trim();if(!s)return null;let n;try{n=new URL(/^[a-z]+:\/\//i.test(s)?s:`http://${s}`)}catch{return{invalid:!0}}const a=n.hostname;return{invalid:!1,host:a,port:n.port||(n.protocol==="https:"?"443":"80"),local:a==="127.0.0.1"||a==="localhost"||a==="::1"||a==="0.0.0.0"}}function voe(t){return`ssh -N -L ${t.port}:127.0.0.1:${t.port} ${t.host}`}function yoe(t,s){const n=(t||"").toLowerCase();return s&&!s.local?{cause:`Axom binds 127.0.0.1 only, so ${s.host} can't be reached from this machine directly — this address cannot work without a tunnel.`,tunnel:!0}:n.includes("econnrefused")||n.includes("refused")?{cause:"Nothing is listening on that port — the runtime is probably not started."}:n.includes("enotfound")||n.includes("eai_again")||n.includes("dns")?{cause:"That hostname doesn't resolve from this machine."}:n.includes("timeout")||n.includes("abort")?{cause:"No answer in time — wrong host, or something between here and there is dropping it."}:n.includes("404")||n.includes("about")||n.includes("json")||n.includes("parse")?{cause:"Something answered, but it didn't serve /about — that address isn't an Axom runtime."}:{cause:"The runtime didn't answer /about."}}function fQ({parsed:t,onCopy:s}){const n=voe(t);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed",children:["Run this on this machine first, then connect to"," ",e.jsxs("code",{className:"font-mono text-text-2",children:["http://127.0.0.1:",t.port]})," instead:"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("code",{className:"flex-1 px-2 py-1 bg-surface-0 border border-border-subtle rounded font-mono text-2xs text-text-2 truncate select-all",children:n}),e.jsx("button",{onClick:()=>s(n),className:"p-1 rounded text-text-4 hover:text-accent hover:bg-surface-3 transition-colors cursor-pointer",title:"Copy tunnel command",children:e.jsx(Nn,{size:11})})]})]})}function woe({onBack:t}){var Z;const s=k($=>$.axomStatus),n=k($=>$.saveAxomEndpoints),a=k($=>$.startAxomInstall),r=k($=>$.startAxomInstance),i=k($=>$.fetchAxomHardware),c=k($=>$.axomHardware),A=k($=>$.axomMyEndpoint),u=k($=>$.axomInstall),x=k($=>$.addToast),[h,O]=p.useState(""),[g,b]=p.useState(!1);p.useEffect(()=>{i()},[i]);const y=u.phase==="manifest"||u.phase==="runtime"||u.phase==="models",v=c==null?void 0:c.requirements,S=c?Ooe[c.verdict]:null,j=c?c.verdict!=="insufficient"&&c.diskOk!==!1:!0;async function N(){try{await a()}catch($){x("error","Install could not start",$.message)}}async function B(){try{await r("default")}catch($){x("error","Instance failed to start",$.message)}}async function C(){b(!0);try{await n([{name:"local",url:h.trim()}]),t==null||t()}catch($){x("error","Could not save endpoint",$.message)}finally{b(!1)}}async function P(){b(!0);try{await n([]),x("success","Endpoint removed")}catch($){x("error","Could not remove endpoint",$.message)}finally{b(!1)}}const U=((Z=s==null?void 0:s.endpoints)==null?void 0:Z[0])||null;function T($){navigator.clipboard.writeText($),x("success","Copied")}const R=p.useMemo(()=>uQ(h),[h]),M=p.useMemo(()=>uQ(U==null?void 0:U.url),[U==null?void 0:U.url]),I=(U==null?void 0:U.status)==="error"?yoe(U.error,M):null,J=(c==null?void 0:c.verdict)==="insufficient",W=u.runtimeInstalled===!0,ee=instances.find($=>$.status==="running")||null,V=!W&&u.available===!1,z=!W&&u.available===void 0,E=!W&&(V||J),q=c&&v?Math.min(100,c.totalRamGb/v.recommendedRamGb*100):0;return e.jsxs("div",{className:"h-full axom-hero-bg overflow-y-auto lg:overflow-hidden relative",children:[(t||U)&&e.jsxs("div",{className:"absolute top-0 inset-x-0 z-10 flex items-center gap-3 px-6 xl:px-12 py-2.5 border-b border-border-subtle bg-surface-1/70 backdrop-blur",children:[t&&e.jsxs("button",{onClick:t,className:"flex items-center gap-1.5 text-xs text-text-3 hover:text-accent cursor-pointer transition-colors",children:[e.jsx(tm,{size:13})," Back to workspace"]}),U&&e.jsxs("div",{className:"ml-auto flex items-center gap-2 min-w-0",children:[e.jsx(ht,{status:U.status==="connected"?"running":U.status==="error"?"crashed":"starting",size:"sm"}),e.jsx("span",{className:"text-xs text-text-3 font-mono truncate max-w-[22rem]",title:U.error||U.url,children:U.url}),U.status==="error"&&e.jsx("span",{className:"text-xs text-danger truncate",children:U.error||"unreachable"}),e.jsx(xe,{size:"sm",variant:"ghost",onClick:P,disabled:g,children:"Disconnect"})]})]}),e.jsxs("div",{className:X("min-h-full lg:h-full w-full max-w-[1600px] mx-auto px-6 xl:px-12 py-6 grid grid-cols-1 lg:grid-cols-[minmax(0,0.92fr)_minmax(0,1.08fr)] gap-8 xl:gap-14 items-center",(t||U)&&"pt-16"),children:[e.jsxs(Hs.div,{initial:{opacity:0,x:-14},animate:{opacity:1,x:0},transition:{duration:.5,ease:"easeOut"},className:"flex flex-col gap-6 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-5 min-w-0",children:[e.jsxs("div",{className:"relative h-24 w-24 flex-shrink-0 flex items-center justify-center",children:[e.jsx("span",{"aria-hidden":!0,className:"absolute h-20 w-20 rounded-full bg-accent/20 blur-2xl animate-axom-breathe"}),e.jsx("span",{"aria-hidden":!0,className:"absolute inset-0 animate-axom-orbit",children:e.jsx("span",{className:"axom-ring absolute inset-0 scale-y-[0.42]"})}),e.jsx("span",{"aria-hidden":!0,className:"absolute inset-1 animate-axom-orbit-slow",children:e.jsx("span",{className:"axom-ring absolute inset-0 scale-x-[0.42]"})}),e.jsx("span",{"aria-hidden":!0,className:"absolute inset-2 rounded-full border border-accent/10"}),e.jsx(tc,{size:46,strokeWidth:.9,className:"relative text-accent"})]}),e.jsxs("div",{className:"flex flex-col gap-2 min-w-0",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 text-2xs uppercase tracking-[0.22em] text-text-4 font-semibold",children:["Sovereign runtime",e.jsx("span",{"aria-hidden":!0,className:"h-px w-8 axom-edge-muted"})]}),e.jsx("h2",{className:"axom-display text-[2.75rem] xl:text-5xl font-semibold tracking-[-0.025em] leading-[1.05]",children:"Your own Axom"})]})]}),e.jsx("p",{className:"text-[0.9375rem] text-text-2 leading-relaxed max-w-xl",children:"A sovereign AI runtime that lives on your hardware, remembers per project, and shows its work — every claim on screen traces to a real event underneath."}),e.jsx("div",{className:"max-w-xl rounded-lg border border-border-subtle bg-surface-1/50 divide-y divide-border-subtle overflow-hidden",children:boe.map(({icon:$,label:D})=>e.jsxs("span",{className:"flex items-center gap-3 px-4 py-2.5",children:[e.jsx("span",{className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded border border-accent/20 bg-accent/10 text-accent",children:e.jsx($,{size:12,strokeWidth:1.75})}),e.jsx("span",{className:"text-xs text-text-2 leading-snug",children:D})]},D))}),e.jsx("p",{className:"text-xs text-text-4 leading-relaxed max-w-md",children:"Axom speaks an open provider protocol — local today, your rack tomorrow, the mesh after that. One socket, every tier."})]}),e.jsxs("div",{className:"flex flex-col gap-4 min-w-0",children:[c&&e.jsxs(Hs.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.4,delay:.1,ease:"easeOut"},className:"relative rounded-xl axom-panel border border-border overflow-hidden",children:[e.jsx("span",{"aria-hidden":!0,className:"absolute inset-x-0 top-0 h-px axom-edge-muted"}),e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("span",{className:"flex items-center gap-2 text-2xs uppercase tracking-[0.16em] text-text-3 font-semibold",children:[e.jsx(fc,{size:12,strokeWidth:1.75,className:"text-text-4"}),"This machine"]}),S&&e.jsxs("span",{className:X("inline-flex items-center gap-1.5 px-3 py-1 rounded-full border text-xs font-semibold",S.tone),children:[e.jsx(S.icon,{size:13,strokeWidth:2})," ",S.pill]})]}),e.jsxs("div",{className:"grid grid-cols-2 xl:grid-cols-4 gap-2.5",children:[e.jsx(Df,{icon:YM,label:"Memory",value:c.totalRamGb,unit:"GB",sub:v&&`of ${v.recommendedRamGb} GB recommended`,tone:J?"text-danger":c.verdict==="marginal"?"text-warning":"text-success",meter:S&&{pct:q,tone:S.meterTone}}),e.jsx(Df,{icon:Zi,label:"Free disk",value:c.freeDiskGb==null?"—":Math.round(c.freeDiskGb),unit:c.freeDiskGb==null?null:"GB",sub:v&&`${v.minDiskGb} GB needed`,tone:c.diskOk===!1?"text-danger":"text-text-0"}),e.jsx(Df,{icon:ha,label:"Processor",value:c.cpuCores,unit:"cores",sub:c.appleSilicon?"Apple Silicon":c.arch}),e.jsx(Df,{icon:jt,label:"Accelerator",value:c.gpu?"Metal":"—",sub:c.gpu?"unified memory":"none detected"})]}),S&&e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed max-w-3xl",children:[S.detail,c.diskOk===!1&&` Also low on disk: ${Math.round(c.freeDiskGb)} GB free, ${v==null?void 0:v.minDiskGb} GB needed.`]})]})]}),e.jsxs(Hs.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.4,delay:.18,ease:"easeOut"},className:"grid md:grid-cols-2 lg:grid-cols-1 xl:grid-cols-2 gap-4 items-stretch",children:[e.jsxs("section",{className:X("relative rounded-xl border p-5 flex flex-col gap-3.5 overflow-hidden transition-colors",E?"bg-surface-1/60 border-border-subtle":"axom-panel border-accent/25"),children:[e.jsx("span",{"aria-hidden":!0,className:X("absolute inset-x-0 top-0 h-px",E?"axom-edge-muted":"axom-edge-accent")}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:X("flex h-7 w-7 items-center justify-center rounded-md border",E?"bg-surface-2 border-border-subtle text-text-4":"bg-accent/10 border-accent/25 text-accent"),children:e.jsx(Js,{size:14,strokeWidth:1.75})}),e.jsx("span",{className:X("text-sm font-semibold tracking-tight",E?"text-text-3":"text-text-0"),children:"Run it here"})]}),!E&&c&&e.jsx(ke,{variant:"accent",children:"recommended here"})]}),e.jsx("p",{className:"text-xs text-text-3 leading-relaxed flex-1",children:W?e.jsx(e.Fragment,{children:"Axom is installed on this machine — start it and chat locally, no other machine involved."}):e.jsxs(e.Fragment,{children:["One verified download — runtime and models (~",(v==null?void 0:v.downloadGb)??4.4," GB) — then your Axom lives on this machine, fully self-contained."]})}),W?e.jsxs("div",{className:"flex flex-col gap-2",children:[ee?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-2",children:[e.jsx(ht,{status:"running",size:"sm"}),"Running on this machine",e.jsxs("span",{className:"font-mono text-2xs text-text-4 ml-auto",children:[ee.id,":",ee.port]})]}),t&&e.jsxs(xe,{variant:"primary",size:"lg",onClick:t,className:"w-full",children:[e.jsx(tc,{size:15,className:"mr-1.5"})," Open workspace"]})]}):e.jsxs(xe,{variant:"primary",size:"lg",onClick:B,disabled:g,className:"w-full",children:[e.jsx(jn,{size:15,className:"mr-1.5"})," Start runtime"]}),u.runtimeCommand&&e.jsx("span",{className:"font-mono text-2xs text-text-4 truncate",title:u.runtimeCommand,children:u.runtimeCommand})]}):V?e.jsxs("div",{className:"rounded-md border border-border-subtle bg-surface-2/50 px-3 py-3 flex flex-col items-center gap-1.5 text-center",children:[e.jsx("span",{className:"font-mono text-2xs uppercase tracking-[0.2em] text-text-2",children:u.unavailableReason||"Coming soon"}),e.jsx("span",{className:"text-xs text-text-4 leading-relaxed",children:"Running Axom on your own machine arrives in a future release."})]}):J?e.jsxs("div",{className:"rounded-md bg-surface-2/60 border border-border-subtle px-3 py-2.5 flex items-start gap-2 text-xs text-text-3 leading-relaxed",children:[e.jsx(Ss,{size:13,className:"flex-shrink-0 mt-0.5 text-text-4"}),"Locked below the ",v==null?void 0:v.minRamGb," GB memory floor — this machine stays comfortable."]}):u.phase==="done"?e.jsxs(xe,{variant:"primary",size:"lg",onClick:B,className:"w-full",children:[e.jsx(tc,{size:15,className:"mr-1.5"})," Start your Axom"]}):y?e.jsxs("div",{className:"rounded-md bg-surface-1 border border-border-subtle px-3 py-2.5 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs text-text-2",children:[e.jsx("span",{className:"truncate",children:u.phase==="models"?`Downloading ${u.file}`:u.phase==="runtime"?"Installing runtime…":"Fetching manifest…"}),u.totalBytes>0&&e.jsxs("span",{className:"font-mono text-2xs text-text-4 tabular-nums flex-shrink-0",children:[dQ(u.receivedBytes)," / ",dQ(u.totalBytes)]})]}),u.totalBytes>0&&e.jsx("div",{className:"h-[3px] rounded-full bg-surface-4 overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent rounded-full transition-[width] duration-500 ease-out",style:{width:`${Math.min(100,u.receivedBytes/u.totalBytes*100)}%`}})})]}):e.jsxs(xe,{variant:"primary",size:"lg",onClick:N,disabled:!j||z,className:"w-full",children:[e.jsx(Js,{size:15,className:"mr-1.5"})," Install Axom locally"]}),u.phase==="error"&&e.jsxs("p",{className:"flex items-start gap-1.5 text-xs text-danger leading-relaxed",children:[e.jsx(Ss,{size:13,className:"flex-shrink-0 mt-0.5"})," ",u.error]})]}),e.jsxs("section",{className:X("relative rounded-xl border p-5 flex flex-col gap-3.5 overflow-hidden transition-colors",E?"axom-panel border-accent/25":"bg-surface-1/60 border-border-subtle"),children:[e.jsx("span",{"aria-hidden":!0,className:X("absolute inset-x-0 top-0 h-px",E?"axom-edge-accent":"axom-edge-muted")}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:X("flex h-7 w-7 items-center justify-center rounded-md border",E?"bg-accent/10 border-accent/25 text-accent":"bg-surface-2 border-border-subtle text-text-3"),children:e.jsx(Vn,{size:14,strokeWidth:1.75})}),e.jsx("span",{className:"text-sm font-semibold tracking-tight text-text-0",children:"Connect to an Axom"})]}),E&&e.jsx(ke,{variant:"accent",children:"recommended here"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-2xs uppercase tracking-[0.12em] text-text-4 font-semibold",children:"Enter endpoint"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Jt,{value:h,onChange:$=>O($.target.value),placeholder:"Paste an Axom endpoint…",className:"flex-1 font-mono text-xs"}),e.jsxs(xe,{variant:E?"primary":"secondary",onClick:C,disabled:g||!h.trim(),children:[e.jsx(Ls,{size:14,className:"mr-1.5"}),g?"Connecting…":"Connect"]})]}),(R==null?void 0:R.invalid)&&e.jsx("p",{className:"text-xs text-danger leading-relaxed",children:"That isn't a URL GROOVE can parse."}),R&&!R.invalid&&!R.local&&e.jsxs("div",{className:"rounded-md border border-warning/25 bg-warning/[0.06] px-3 py-2.5 flex flex-col gap-1.5",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-xs font-semibold text-warning",children:[e.jsx(Ss,{size:12})," ",R.host," can't be reached directly"]}),e.jsx(fQ,{parsed:R,onCopy:T})]}),I&&e.jsxs("div",{className:"rounded-md border border-danger/25 bg-danger/[0.06] px-3 py-2.5 flex flex-col gap-1.5",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-xs font-semibold text-danger",children:[e.jsx(Ss,{size:12})," Can't reach ",U.url]}),e.jsx("p",{className:"text-xs text-text-2 leading-relaxed",children:I.cause}),U.error&&e.jsx("code",{className:"font-mono text-2xs text-text-4 break-all",children:U.error}),I.tunnel&&M&&e.jsx(fQ,{parsed:M,onCopy:T})]}),e.jsx("p",{className:"text-xs text-text-4 leading-relaxed",children:`Copied from another GROOVE's "My endpoint", over your own secure channel.`})]}),A&&e.jsxs("div",{className:"flex flex-col gap-2 mt-auto pt-3.5 border-t border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"text-2xs uppercase tracking-[0.12em] text-text-4 font-semibold",children:"My endpoint"}),e.jsx(ht,{status:A.running?"running":"completed",size:"sm"}),e.jsx("span",{className:"text-2xs text-text-4",children:A.running?"live":"idle"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("code",{className:"flex-1 px-2 py-1.5 bg-surface-0 border border-border-subtle rounded font-mono text-xs text-text-1 truncate select-all",children:A.url}),e.jsxs(xe,{size:"sm",onClick:()=>{navigator.clipboard.writeText(A.url),x("success","Endpoint copied")},children:[e.jsx(Nn,{size:12,className:"mr-1"})," Copy"]})]}),e.jsxs("p",{className:"text-xs text-text-4 leading-relaxed",children:[A.running?"Your Axom is live here.":"Where your Axom listens once started."," ","Binds to this machine only — from another machine, tunnel it:"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("code",{className:"flex-1 px-2 py-1 bg-surface-0 border border-border-subtle rounded font-mono text-2xs text-text-3 truncate select-all",children:A.tunnelCommand}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(A.tunnelCommand),x("success","Tunnel command copied")},className:"p-1 rounded text-text-4 hover:text-accent hover:bg-surface-3 transition-colors cursor-pointer",title:"Copy tunnel command",children:e.jsx(Nn,{size:11})})]})]})]})]})]})]})]})}const joe={idle:null,confirm:"Confirm",force:"Force stop",busy:"Working…"};function Noe({endpoint:t,remote:s}){const n=k(C=>C.startAxomRuntime),a=k(C=>C.stopAxomRuntime),r=k(C=>C.healAxomTunnel),i=k(C=>C.fetchAxomRemote),c=k(C=>C.stopAxomInstance),A=k(C=>C.saveAxomEndpoints),u=k(C=>C.addToast),[x,h]=p.useState("idle"),[O,g]=p.useState(null);p.useEffect(()=>{i==null||i()},[i]),p.useEffect(()=>{if(x!=="confirm"&&x!=="force")return;const C=setTimeout(()=>h("idle"),5e3);return()=>clearTimeout(C)},[x]);const b=!!(t!=null&&t.managed)&&!!(t!=null&&t.instanceId),y=(s==null?void 0:s.configured)&&s.running==null;async function v(C,P,U){h("busy");try{const T=await C();if(T!=null&&T.turnInFlight){g("turn in flight"),h("force"),u("warning","A turn is in flight","Force stop to end it anyway — that turn will not finish.");return}if(T!=null&&T.unsupported){g("no remote shutdown"),h("idle"),u("error","This runtime is still running","It predates remote shutdown, so GROOVE can't stop it from here — stop it on the machine it runs on.");return}g(null),h("idle"),u("success",P,U)}catch(T){h("idle"),u("error","That did not work",T.message)}}const S=x==="busy",j=x==="confirm"||x==="force";let N;s!=null&&s.configured?y?N={dot:"starting",word:"host unreachable",detail:s.error||`${s.host} did not answer — we can't tell whether the runtime is up`,action:r&&{label:"Heal tunnel",icon:Ls,confirm:!1,run:()=>r()}}:s.running?N={dot:"running",word:"runtime active",detail:`${s.host} is answering`,action:a&&{label:"Stop runtime",icon:bj,confirm:!0,run:C=>a({force:C})}}:N={dot:"completed",word:"runtime inactive",detail:`${s.host} is reachable, the runtime is not running`,action:n&&{label:"Start runtime",icon:jn,confirm:!1,run:()=>n()}}:b?N={dot:t.status==="connected"?"running":"completed",word:t.status==="connected"?"runtime active":"runtime idle",action:{label:"Stop runtime",icon:bj,confirm:!0,danger:!0,run:()=>c(t.instanceId)}}:N={dot:null,word:null,action:null};function B(){const C=N.action;if(C){if(C.confirm&&x==="idle"){h("confirm");return}return x==="force"?v(()=>C.run(!0),"Runtime force-stopped"):v(()=>C.run(!1),C.label==="Start runtime"?"Runtime started":C.label==="Heal tunnel"?"Tunnel re-established":"Runtime stopping")}}return e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[N.word&&e.jsxs("span",{className:"flex items-center gap-1.5",title:N.detail,children:[e.jsx(ht,{status:N.dot,size:"sm"}),e.jsx("span",{className:"text-2xs text-text-3 font-medium whitespace-nowrap",children:N.word})]}),O&&e.jsx("span",{className:X("font-mono text-2xs whitespace-nowrap",x==="force"?"text-warning":"text-text-4"),children:O}),N.action&&e.jsxs("button",{onClick:B,disabled:S,className:X("flex items-center gap-1.5 h-7 px-2 rounded-md text-2xs font-medium transition-colors cursor-pointer whitespace-nowrap","disabled:opacity-40 disabled:pointer-events-none",j?"bg-danger/10 text-danger":"text-text-3 hover:text-text-0 hover:bg-surface-2"),title:N.detail||N.action.label,children:[e.jsx(N.action.icon,{size:12}),j||S?joe[x]:N.action.label]}),!b&&e.jsx("button",{onClick:()=>A([]).then(()=>u("success","Disconnected","The runtime keeps running — GROOVE just stopped pointing at it."),C=>u("error","Disconnect failed",C.message)),className:"flex items-center gap-1.5 h-7 px-2 rounded-md text-2xs font-medium text-text-4 hover:text-text-1 hover:bg-surface-2 transition-colors cursor-pointer",title:"Stop pointing at this endpoint. The runtime keeps running.",children:e.jsx(Bd,{size:12})})]})}function Qoe({endpoint:t,remote:s,anomalies:n,onSetup:a}){var x,h,O,g,b;const r=k(y=>y.addToast),i=t.about,c=t.status==="connected"?"running":t.status==="connecting"?"starting":"crashed",A=t.remoteHost||t.name,u=t.status==="connected"?"connected":t.status==="connecting"?"connecting":"not connected";return e.jsxs("div",{className:"flex-shrink-0 h-10 border-b border-border-subtle bg-surface-1 px-3 flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-shrink-0",children:[e.jsx(ht,{status:c,size:"sm"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 truncate",children:A}),e.jsx("span",{className:"text-2xs text-text-3 whitespace-nowrap",children:u}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(t.url),r("success","Endpoint copied")},className:"font-mono text-2xs text-text-4 hover:text-accent truncate max-w-[13rem] cursor-pointer transition-colors",title:t.viaRemote?`Tunnelled to ${t.remoteHost} — click to copy`:"Copy endpoint URL",children:t.viaRemote?`via tunnel · ${t.url}`:t.url})]}),((x=i==null?void 0:i.chassis)==null?void 0:x.loaded)===!1&&e.jsx("span",{className:"font-mono text-2xs text-text-4 flex-shrink-0 hidden lg:inline",title:"The chassis unloaded after an idle timeout — the session and its ledger are intact",children:"chassis idle · reloads on next message"}),t.status==="error"&&e.jsxs("span",{className:"flex items-center gap-1.5 text-2xs text-danger min-w-0",title:t.error,children:[e.jsx(Ss,{size:11,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t.error||"unreachable"})]}),(((O=(h=t.drift)==null?void 0:h.novel)==null?void 0:O.length)>0||((b=(g=t.drift)==null?void 0:g.missing)==null?void 0:b.length)>0)&&e.jsxs("span",{className:"text-2xs text-warning font-mono flex-shrink-0",title:`novel: ${t.drift.novel.join(", ")||"—"} · missing: ${t.drift.missing.join(", ")||"—"}`,children:["drift +",t.drift.novel.length,"/−",t.drift.missing.length]}),(n==null?void 0:n.length)>0&&e.jsxs("span",{className:"flex items-center gap-1 text-2xs text-warning flex-shrink-0",title:n.slice(-3).map(y=>`${y.eventId}: ${y.message}`).join(`
|
|
1087
|
-
`),children:[e.jsx(Ss,{size:11})," ",n.length," contract ",n.length===1?"anomaly":"anomalies"]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[e.jsx(Noe,{endpoint:t,remote:s}),e.jsx("span",{"aria-hidden":!0,className:"h-4 w-px bg-border"}),a&&e.jsxs("button",{onClick:a,className:X("flex items-center gap-1.5 h-7 px-2 rounded-md text-2xs font-medium transition-colors cursor-pointer",t.status==="error"?"text-danger hover:bg-danger/10":"text-text-4 hover:text-text-1 hover:bg-surface-2"),title:"Change endpoint or set up a runtime",children:[e.jsx(e0,{size:12}),t.status==="error"?"Fix connection":"Setup"]})]})]})}function Soe({endpoint:t}){const s=k(a=>a.axomSelected),n=k(a=>a.selectAxomSession);return t.sessions.length===0?null:e.jsxs("div",{className:"flex-shrink-0 h-8 border-b border-border-subtle bg-surface-1 px-2 flex items-center gap-1 overflow-x-auto",children:[t.sessions.map(a=>{const r=(s==null?void 0:s.session)===a.session;return e.jsxs("button",{onClick:()=>n(t.name,a.session),className:X("flex items-center gap-1.5 h-6 px-2 rounded font-mono text-2xs whitespace-nowrap transition-colors cursor-pointer",r?"bg-surface-3 text-text-0":"text-text-4 hover:text-text-2 hover:bg-surface-2"),title:a.overflow>0?`${a.overflow} events evicted from the buffer`:void 0,children:[e.jsx(ht,{status:a.live?"running":"completed",size:"sm"}),a.session,a.overflow>0&&e.jsxs("span",{className:"text-warning",children:["−",a.overflow]})]},a.session)}),e.jsx("button",{onClick:()=>n(t.name,`s-${Math.random().toString(36).slice(2,10)}`),className:"h-6 w-6 flex items-center justify-center rounded text-text-4 hover:text-text-1 hover:bg-surface-2 transition-colors cursor-pointer flex-shrink-0",title:"New session — created on your first message",children:e.jsx(ot,{size:12})})]})}function Boe(){const t=k(r=>r.axomInstances),s=k(r=>r.startAxomInstance),n=k(r=>r.stopAxomInstance),a=k(r=>r.addToast);return t.length===0?null:e.jsxs("div",{className:"flex-shrink-0 border-t border-border-subtle px-3 py-2 flex flex-col gap-1",children:[e.jsx("div",{className:"text-2xs uppercase tracking-[0.12em] text-text-4 font-semibold",children:"Local instances"}),t.map(r=>e.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-3",children:[e.jsx(ht,{status:r.status==="running"?"running":r.status==="error"?"crashed":"completed",size:"sm"}),e.jsxs("span",{className:"font-mono truncate",title:r.error||r.dataDir,children:[r.id,":",r.port]}),e.jsx("button",{onClick:()=>(r.status==="running"?n(r.id):s(r.id)).catch(i=>a("error","Instance action failed",i.message)),className:"ml-auto text-text-4 hover:text-text-1 cursor-pointer transition-colors",title:r.status==="running"?"Stop instance":"Start instance",children:r.status==="running"?e.jsx(Qd,{size:11}):e.jsx(jn,{size:11})})]},r.id))]})}function Ur(t){if(t==null)return"";if(typeof t=="string")return t;const s=t.text||t.thought||t.content;if(typeof s=="string")return s;try{return JSON.stringify(t)}catch{return String(t)}}function Coe(t){const s=t==null?void 0:t.cites;return Array.isArray(s)?s.filter(n=>typeof n=="string"):[]}function Xx(t){return typeof(t==null?void 0:t.to)=="string"?t.to:null}function koe(t){for(const s of["text","prompt","message","query","input"])if(typeof(t==null?void 0:t[s])=="string"&&t[s].trim())return t[s];return null}function pb(t,s){const n=(t==null?void 0:t.tool)||(t==null?void 0:t.name)||(t==null?void 0:t.tool_name);let a=(t==null?void 0:t.arg)??(t==null?void 0:t.args)??(t==null?void 0:t.input)??(t==null?void 0:t.query);return a&&typeof a=="object"&&(a=Object.values(a).find(i=>typeof i=="string"&&i.length<120)),typeof n!="string"||!n.trim()?null:[`${s==="tool_end"?"finished":"running"} ${n.trim()}`,typeof a=="string"?a:null].filter(Boolean).join(" · ")}const qs=t=>typeof t=="string"&&t.trim()?t.trim():null,bo=(...t)=>t.filter(Boolean).join(" · "),Zl=t=>typeof t=="string"?qs(t):qs(t==null?void 0:t.text)||qs(t==null?void 0:t.thought)||qs(t==null?void 0:t.content),Toe={pipeline_start:{icon:jn,text:t=>bo("turn started",qs(t.mode))},firing_start:{icon:jt,text:t=>bo("firing",qs(t.leaf_id),qs(t.agent_type))},step_start:{icon:Nt,text:(t,s)=>{const n=t.step??s.step;return n==null?"step":`step ${n}`}},leaf_swap:{icon:rm,text:t=>Xx(t)?`wearing ${Xx(t)}`:"leaf swap · leaf not named"},thought:{icon:kS,text:t=>Zl(t)},tool_start:{icon:Ri,text:t=>qs(pb(t,"tool_start"))},tool_end:{icon:Ri,text:t=>qs(pb(t,"tool_end"))},narration:{icon:HS,text:t=>Zl(t)},text:{icon:w_,text:t=>Zl(t)},resolution:{icon:To,text:t=>Zl(t)},candidate_arrived:{icon:ZA,text:t=>bo("candidate",qs(t.leaf_id),t.banked?"banked":null)},champion_changed:{icon:ZA,text:t=>qs(t.to)?bo(`champion → ${qs(t.to)}`,qs(t.rule)&&`rule ${qs(t.rule)}`):"champion changed · winner not named"},candidate_banked:{icon:ZA,text:()=>"candidate banked"},confidence_updated:{icon:fc,text:t=>bo("confidence",t.candidates!=null&&`${t.candidates} candidates`,t.n_fused!=null&&t.n_agents!=null&&`${t.n_fused}/${t.n_agents} fused`,t.n_facts!=null&&`${t.n_facts} facts`)},evidence_scored:{icon:fc,text:t=>bo("evidence",qs(t.source))},firing_end:{icon:To,text:t=>bo("firing done",t.tokens_generated!=null&&`${t.tokens_generated} tok`)},pipeline_done:{icon:To,text:t=>t.stopped_early===!0?"turn stopped early":"turn complete"},interrupt:{icon:jt,text:t=>Zl(t)?`steer · ${Zl(t)}`:"steer"},interrupt_ack:{icon:jt,text:()=>"steer acknowledged"},stop_requested:{icon:mc,text:()=>"stop requested",tone:"text-danger"},stop_effected:{icon:mc,text:()=>"stopped",tone:"text-danger"}};function Uoe(t){const s=Toe[t.kind],n=s?s.text(t.payload||{},t):null;return n?{icon:s.icon,text:n,tone:s.tone,raw:!1}:{icon:(s==null?void 0:s.icon)||An,text:bo(t.kind,qs(Ur(t.payload)))||t.kind,tone:s==null?void 0:s.tone,raw:!0}}function Eoe({events:t,highlight:s,onHighlight:n,live:a}){const r=p.useRef(null),i=p.useRef(!0),[c,A]=p.useState(!1);p.useEffect(()=>{const h=r.current;h&&i.current&&!s&&(h.scrollTop=h.scrollHeight)},[t.length,s,c]),p.useEffect(()=>{var g;if(!((g=s==null?void 0:s.ids)!=null&&g.length))return;const h=r.current,O=h==null?void 0:h.querySelector(`[data-ev="${s.ids[0]}"]`);O&&h.scrollTo({top:O.offsetTop-h.clientHeight/2+O.offsetHeight/2,behavior:"smooth"})},[s]);function u(){const h=r.current;i.current=h.scrollHeight-h.scrollTop-h.clientHeight<40}const x=new Set((s==null?void 0:s.ids)||[]);return e.jsxs("div",{className:"w-64 xl:w-72 flex-shrink-0 border-r border-border-subtle bg-surface-1 flex flex-col min-h-0",children:[e.jsxs("div",{className:"flex-shrink-0 h-10 px-3 flex items-center gap-2 border-b border-border-subtle",children:[a?e.jsxs("span",{className:"relative flex items-center justify-center w-3 h-3 flex-shrink-0",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-accent/25 animate-ping [animation-duration:2s]"}),e.jsx("span",{className:"relative w-1.5 h-1.5 rounded-full bg-accent"})]}):e.jsx(_o,{size:11,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs uppercase tracking-[0.12em] text-text-4 font-semibold",children:"Activity"}),e.jsx("span",{className:"font-mono text-2xs text-text-4",children:t.length}),e.jsx("button",{onClick:()=>A(h=>!h),className:X("ml-auto h-6 px-1.5 rounded font-mono text-2xs transition-colors cursor-pointer",c?"bg-surface-3 text-text-1":"text-text-4 hover:text-text-1 hover:bg-surface-2"),title:c?"Show readable lines":"Show the raw envelopes",children:"raw"})]}),e.jsxs("div",{ref:r,onScroll:u,className:"flex-1 overflow-y-auto px-2 py-2",children:[t.length===0&&e.jsx("p",{className:"px-1 text-xs text-text-4 leading-relaxed",children:"Nothing yet. Every step the runtime takes shows up here as it happens."}),c?e.jsx("div",{className:"font-mono text-2xs leading-5",children:t.map(h=>e.jsxs("div",{"data-ev":h.id,className:X("flex gap-1.5 items-baseline rounded px-1 transition-colors",x.has(h.id)?"bg-accent/10 ring-1 ring-accent/30":"hover:bg-surface-2"),children:[e.jsx("span",{className:"text-text-4/70 flex-shrink-0",children:h.id.replace(/^ev-0*/,"")}),e.jsx("span",{className:"text-text-2 flex-shrink-0",children:h.kind}),e.jsx("span",{className:"text-text-4 truncate",children:Ur(h.payload)})]},h.id))}):e.jsx("div",{className:"flex flex-col",children:t.map(h=>{const O=Uoe(h),g=O.icon,b=x.has(h.id);return e.jsxs("button",{"data-ev":h.id,onClick:()=>n(b?null:{narrationId:`ev:${h.id}`,ids:[h.id]}),className:X("group flex items-start gap-2 py-1 px-1 rounded text-left transition-colors cursor-pointer",b?"bg-accent/10":"hover:bg-surface-2"),title:`${h.id} · ${h.kind}${O.raw?" — shown verbatim: no summary this build can vouch for":""}`,children:[e.jsx(g,{size:10,className:X("mt-[3px] flex-shrink-0",O.tone||(b?"text-accent":"text-text-4"))}),e.jsx("span",{className:X("text-[11px] leading-snug line-clamp-2 min-w-0 flex-1",O.raw?"font-mono text-text-4":"font-sans",O.tone||(O.raw?"":"text-text-3")),children:O.text})]},h.id)})})]}),e.jsx(Boe,{})]})}const Poe=new Set(["firing_start","firing_end","step_start","step_end"]),Foe=25;function $oe(t){const s=[];let n=null;function a(c){return n||(n={id:c,prompt:null,promptId:null,blocks:[],done:!1,stopped:!1},s.push(n)),n}function r(c){a(c.id).blocks.push(c)}function i(c){const A=n==null?void 0:n.blocks[n.blocks.length-1];return A&&A.type===c?A:null}for(const c of t){const A=c.payload||{};switch(c.kind){case"pipeline_start":n={id:c.id,prompt:koe(A),promptId:c.id,blocks:[],done:!1,stopped:!1},s.push(n);break;case"thought":{const u=Ur(A);if(!u)break;const x=i("thought");x?x.items.push({id:c.id,text:u}):r({type:"thought",id:c.id,items:[{id:c.id,text:u}]});break}case"tool_start":case"tool_end":{const u={id:c.id,text:pb(A,c.kind)||`${c.kind} ${Ur(A)}`.trim(),done:c.kind==="tool_end"},x=i("activity");x?x.items.push(u):r({type:"activity",id:c.id,items:[u]});break}case"narration":{const u=Coe(A);if(!u.length)break;r({type:"narration",id:c.id,text:Ur(A),cites:u});break}case"text":{const u=Ur(A);if(!u)break;const x=i("answer");if(x&&!x.final){const h=/\s$/.test(x.text)||/^\s/.test(u)?"":" ";x.text.endsWith(u)||(x.text+=h+u),x.ids.push(c.id)}else r({type:"answer",id:c.id,text:u,final:!1,ids:[c.id]});break}case"resolution":{const u=Ur(A);if(!u)break;r({type:"answer",id:c.id,text:u,final:!0,ids:[c.id]});break}case"leaf_swap":r({type:"leaf",id:c.id,leaf:Xx(A)??"UNKNOWN"});break;case"interrupt":r({type:"steer",id:c.id,steerId:A.interrupt_id??A.id??null,text:Ur(A),acked:!1});break;case"interrupt_ack":{const u=A.interrupt_id??A.id??null;for(let x=s.length-1;x>=0;x--){const h=s[x].blocks.find(O=>O.type==="steer"&&!O.acked&&(u?O.steerId===u||O.id===u:!0));if(h){h.acked=!0;break}}break}case"stop_requested":r({type:"note",id:c.id,text:"stop requested",state:"stop"});break;case"stop_effected":r({type:"note",id:c.id,text:"stopped",state:"stop"});break;case"pipeline_done":n&&(n.done=!0,n.stopped=A.stopped_early===!0),n=null;break;default:if(Poe.has(c.kind))break;break}}return s}function bT({text:t,status:s}){return e.jsx("div",{className:"flex justify-end pl-8",children:e.jsxs("div",{className:"max-w-[90%]",children:[e.jsx("div",{className:"px-3.5 py-2.5 rounded-lg border border-accent/25 bg-accent/10",children:e.jsx("div",{className:"text-[12px] font-sans whitespace-pre-wrap break-words leading-relaxed text-text-0",children:t})}),s&&e.jsx("div",{className:X("text-[10px] font-mono mt-1 text-right",s.stale?"text-warning":"text-text-4"),children:s.label})]})})}function Roe({block:t}){return e.jsx("div",{className:"flex justify-end pl-8",children:e.jsxs("div",{className:"max-w-[90%]",children:[e.jsx("div",{className:"px-3 py-1.5 rounded-lg border border-border bg-surface-2",children:e.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] font-sans text-text-1 leading-relaxed",children:[e.jsx(jt,{size:11,className:"text-accent flex-shrink-0"}),t.text]})}),e.jsx("div",{className:"text-[10px] font-mono text-text-4 mt-1 text-right",children:t.acked?"acked":"heard"})]})})}function Moe({block:t}){const[s,n]=p.useState(!1),a=s?t.items:t.items.slice(-1);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>n(r=>!r),className:"flex items-center gap-1.5 mb-1 text-2xs text-text-4 hover:text-text-2 font-sans transition-colors cursor-pointer",children:[e.jsx(kS,{size:11}),t.items.length===1?"thought":`${t.items.length} thoughts`,t.items.length>1&&e.jsx(rt,{size:10,className:X("transition-transform",s&&"rotate-180")})]}),e.jsx("div",{className:"pl-3.5 border-l border-border flex flex-col gap-1",children:a.map(r=>e.jsx("p",{className:"text-[11px] font-sans text-text-3 leading-relaxed italic",children:r.text},r.id))})]})}function Ioe({block:t,live:s}){var u;const[n,a]=p.useState(!1),[r,i]=p.useState(0),c=t.items,A=s&&!((u=c[c.length-1])!=null&&u.done);if(p.useEffect(()=>{if(!A||c.length<=1)return;const x=setInterval(()=>i(h=>(h+1)%c.length),1500);return()=>clearInterval(x)},[A,c.length]),A){const x=c[Math.min(r,c.length-1)];return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 w-full rounded-md bg-surface-3/50 border border-border-subtle/30",children:[e.jsx(ze,{size:11,className:"text-accent animate-spin flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-text-2 font-mono truncate min-w-0 flex-1 transition-opacity duration-300",children:x.text}),c.length>1&&e.jsx("span",{className:"text-[10px] text-text-4 font-mono flex-shrink-0",children:c.length})]})}return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>a(x=>!x),className:"inline-flex items-center gap-2 px-3 py-1 text-[10px] text-text-4 hover:text-text-2 font-mono transition-colors cursor-pointer",children:[e.jsx(Ri,{size:10,className:"opacity-50"}),c.length," tool call",c.length!==1?"s":"",e.jsx(rt,{size:10,className:X("transition-transform",n&&"rotate-180")})]}),n&&e.jsx("div",{className:"ml-3.5 pl-3.5 border-l border-border flex flex-col",children:c.map(x=>e.jsxs("div",{className:"flex items-center gap-2 py-0.5 group",children:[e.jsx(Ri,{size:10,className:"text-text-4 opacity-70 flex-shrink-0"}),e.jsx("p",{className:"text-[11px] text-text-3 font-sans truncate flex-1 min-w-0",children:x.text}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:x.id})]},x.id))})]})}function _oe({block:t,eventsById:s,highlight:n,onHighlight:a}){const r=(n==null?void 0:n.narrationId)===t.id;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>a(r?null:{narrationId:t.id,ids:t.cites}),className:X("group w-full flex items-start gap-2 text-left rounded-md px-2 py-1 -mx-2 transition-colors cursor-pointer",r?"bg-surface-2":"hover:bg-surface-2/60"),title:"Show the events behind this line",children:[e.jsx(HS,{size:12,className:X("mt-0.5 flex-shrink-0",r?"text-accent":"text-text-4")}),e.jsx("span",{className:"text-[12px] font-sans text-text-2 leading-relaxed",children:t.text}),e.jsxs("span",{className:X("ml-auto flex-shrink-0 font-mono text-[10px] transition-colors",r?"text-accent":"text-text-4 opacity-0 group-hover:opacity-100"),children:[t.cites.length," cited"]})]}),r&&e.jsx("div",{className:"ml-5 mt-1 rounded-md border border-border-subtle bg-surface-0 px-2 py-1.5 font-mono text-[10px] leading-5",children:t.cites.map(i=>{const c=s[i];return e.jsxs("div",{className:"flex gap-2 items-baseline",children:[e.jsx("span",{className:"text-text-4/70 flex-shrink-0",children:i}),e.jsx("span",{className:X("flex-shrink-0",c?"text-text-2":"text-warning"),children:c?c.kind:"evicted from buffer"}),e.jsx("span",{className:"text-text-4 truncate",children:c?Ur(c.payload):""})]},i)})})]})}function zoe({block:t,endpointName:s}){const[n,a]=p.useState(t.text.length>600),r=t.text.length>600;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-1 font-sans",children:"Axom"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:s}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono ml-auto",children:t.final?"resolution":"text"})]}),e.jsx("div",{className:"pl-3.5 py-1 border-l border-accent",children:e.jsx(Y0,{text:n?`${t.text.slice(0,600)}...`:t.text})}),r&&e.jsxs("button",{onClick:()=>a(i=>!i),className:"ml-3.5 mt-1.5 flex items-center gap-1.5 text-[11px] text-accent/70 hover:text-accent font-sans font-medium cursor-pointer transition-colors",children:[e.jsx(rt,{size:11,className:X(!n&&"rotate-180")}),n?"Show full response":"Collapse"]})]})}function Hf({icon:t,text:s,tone:n}){return e.jsxs("div",{className:"flex items-center gap-3 py-2",children:[e.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),e.jsxs("span",{className:X("flex items-center gap-1.5 text-[10px] font-sans flex-shrink-0 uppercase tracking-wide",n||"text-text-4"),children:[t&&e.jsx(t,{size:10})," ",s]}),e.jsx("div",{className:"flex-1 h-px bg-border-subtle"})]})}function Loe({turn:t,live:s,endpointName:n,eventsById:a,highlight:r,onHighlight:i,prompt:c,ambiguous:A}){const u=!c&&!!t.promptId;return e.jsxs(e.Fragment,{children:[c&&e.jsx(bT,{text:c}),u&&e.jsx(Hf,{text:A?"prompt not identified":"started elsewhere"}),t.blocks.map(x=>{switch(x.type){case"thought":return e.jsx(Moe,{block:x},x.id);case"activity":return e.jsx(Ioe,{block:x,live:s},x.id);case"narration":return e.jsx(_oe,{block:x,eventsById:a,highlight:r,onHighlight:i},x.id);case"answer":return e.jsx(zoe,{block:x,endpointName:n},x.id);case"steer":return e.jsx(Roe,{block:x},x.id);case"leaf":return e.jsx(Hf,{icon:rm,text:`wearing ${x.leaf}`},x.id);case"note":return e.jsx(Hf,{icon:mc,text:x.text,tone:"text-danger"},x.id);default:return null}}),t.stopped&&e.jsx(Hf,{icon:mc,text:"stopped early",tone:"text-danger"})]})}function Doe({events:t,prompts:s,sessionLive:n,endpointName:a,highlight:r,onHighlight:i}){const c=p.useRef(null),A=p.useRef(!0),u=p.useMemo(()=>$oe(t),[t]),x=p.useMemo(()=>Object.fromEntries(t.map(j=>[j.id,j])),[t]);p.useEffect(()=>{const j=c.current;j&&A.current&&(j.scrollTop=j.scrollHeight)},[t.length]);function h(){const j=c.current;A.current=j.scrollHeight-j.scrollTop-j.clientHeight<60}const O=s.filter(j=>!j.attachedTo),[g,b]=p.useState(()=>Date.now()/1e3);p.useEffect(()=>{if(!O.length)return;const j=setInterval(()=>b(Date.now()/1e3),3e3);return()=>clearInterval(j)},[O.length]);const y=u[u.length-1],v=y==null?void 0:y.blocks[y.blocks.length-1],S=n&&y&&!y.done&&(!v||v.type!=="activity"&&v.type!=="answer");return e.jsxs("div",{ref:c,onScroll:h,className:"flex-1 overflow-y-auto px-4 py-4 space-y-4 min-h-0",children:[u.length===0&&O.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center py-8",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-surface-3 flex items-center justify-center mb-3",children:e.jsx(tc,{size:18,className:"text-text-4"})}),e.jsx("p",{className:"text-sm font-semibold text-text-0 font-sans",children:a}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Send a message — every step it takes appears here, and every line cites the events behind it"})]}),u.map((j,N)=>{var B;return e.jsx(Loe,{turn:j,prompt:j.prompt||((B=s.find(C=>C.attachedTo&&C.attachedTo===j.promptId))==null?void 0:B.text)||null,ambiguous:O.length>0,live:n&&N===u.length-1&&!j.done,endpointName:a,eventsById:x,highlight:r,onHighlight:i},j.id)}),O.map(j=>e.jsx(bT,{text:j.text,status:g-j.ts>Foe?{label:"sent · no turn opened for it",stale:!0}:{label:"sent · awaiting turn"}},j.ts)),e.jsx(Ho,{children:S&&e.jsx(Hs.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.25,ease:"easeOut"},children:e.jsx(hT,{agent:{name:"Axom"}})},"thinking")})]})}function Hoe({about:t,events:s}){const n=p.useMemo(()=>s.filter(i=>i.kind==="leaf_swap").map(i=>({id:i.id,leaf:Xx(i.payload)})),[s]),a=(t==null?void 0:t.leaves)||[],r=n.length?n[n.length-1].leaf??"UNKNOWN":"UNKNOWN";return e.jsxs("div",{className:"flex-shrink-0 h-7 border-b border-border-subtle px-4 flex items-center gap-2 overflow-x-auto",children:[e.jsx(rm,{size:11,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"font-mono text-2xs flex-shrink-0",children:e.jsx("span",{className:r==="UNKNOWN"?"text-text-4":"text-text-1",children:r})}),n.length>1&&e.jsxs("span",{className:"font-mono text-2xs text-text-4 whitespace-nowrap",title:"Leaf swap history — each entry is a leaf_swap event",children:["← ",n.slice(-6,-1).reverse().map(i=>i.leaf??"?").join(" ← ")]}),e.jsxs("span",{className:"ml-auto font-mono text-2xs text-text-4 whitespace-nowrap flex-shrink-0",children:["roster ",a.length?a.map(i=>i.name).join(" · "):"—"]})]})}function Xoe(t){let s=null;const n=()=>({watermark:"PROVISIONAL",candidates:[],byFiring:{},champion:null,confidence:null,evidence:[],banked:0});for(const a of t){const r=a.payload||{};if(a.kind==="pipeline_start")s=null;else if(a.kind==="candidate_arrived"){s=s||n();const i={firingId:r.firing_id,leafId:r.leaf_id,text:r.text,banked:!!r.banked,basis:Array.isArray(r.basis)?r.basis:[]};s.candidates.push(i),i.firingId&&(s.byFiring[i.firingId]=i)}else s&&a.kind==="champion_changed"?s.champion={to:r.to,from:r.from??null,rule:r.rule,basis:Array.isArray(r.basis)?r.basis:[]}:s&&a.kind==="confidence_updated"?s.confidence=r:s&&a.kind==="evidence_scored"?s.evidence.push({source:r.source,values:r.values,basis:Array.isArray(r.basis)?r.basis:[]}):s&&a.kind==="candidate_banked"?s.banked+=1:s&&a.kind==="pipeline_done"&&(s.watermark=r.stopped_early===!0?"STOPPED":"SETTLED")}return s}const Goe={PROVISIONAL:"text-warning",SETTLED:"text-text-1",STOPPED:"text-danger"};function lO({basis:t,highlightKey:s,highlight:n,onHighlight:a,className:r,children:i,title:c}){const A=(n==null?void 0:n.narrationId)===s;return e.jsx("button",{title:c,onClick:()=>t.length&&a(A?null:{narrationId:s,ids:t}),className:X("text-left rounded transition-colors",t.length?"cursor-pointer":"cursor-default",A?"bg-surface-3":"hover:bg-surface-2",r),children:i})}function Zoe({answer:t,onStop:s,stopState:n,highlight:a,onHighlight:r}){const[i,c]=p.useState(!1),A=t.champion?t.byFiring[t.champion.to]:null,u=t.confidence,x=t.watermark==="PROVISIONAL";return e.jsxs("div",{className:"flex-shrink-0 border-t border-border-subtle bg-surface-1 px-4",children:[e.jsxs("div",{className:"h-8 flex items-center gap-2.5",children:[e.jsx(ZA,{size:11,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs uppercase tracking-[0.12em] text-text-4 font-semibold flex-shrink-0",children:"Living answer"}),e.jsx("span",{className:X("font-mono text-2xs font-semibold flex-shrink-0",Goe[t.watermark]),children:t.watermark}),e.jsxs("span",{className:"font-mono text-2xs text-text-4 truncate",children:[t.candidates.length," candidate",t.candidates.length===1?"":"s",t.banked>0&&` · ${t.banked} banked`]}),x&&e.jsxs("button",{onClick:s,disabled:n==="pending",className:"flex items-center gap-1.5 h-6 px-2 rounded text-2xs font-medium text-text-3 hover:text-danger hover:bg-danger/10 disabled:opacity-40 disabled:pointer-events-none transition-colors cursor-pointer flex-shrink-0",title:"Settle the tournament on the current champion",children:[e.jsx(mc,{size:11})," Good enough"]}),e.jsx("button",{onClick:()=>c(h=>!h),className:"ml-auto h-6 w-6 flex items-center justify-center rounded text-text-4 hover:text-text-1 hover:bg-surface-2 transition-colors cursor-pointer flex-shrink-0",title:i?"Collapse":"Show champion and confidence",children:e.jsx(rt,{size:12,className:X("transition-transform",i&&"rotate-180")})})]}),i&&e.jsxs("div",{className:"pb-2 flex flex-col gap-1.5 max-h-48 overflow-y-auto",children:[t.champion&&e.jsxs(lO,{basis:t.champion.basis,highlightKey:"champion",highlight:a,onHighlight:r,className:"px-2 py-1.5 border border-border-subtle",title:t.champion.basis.length?"Click to highlight the events behind this champion":void 0,children:[e.jsxs("span",{className:"flex items-center gap-2 mb-0.5 font-mono text-2xs text-text-4",children:[(A==null?void 0:A.leafId)&&e.jsx("span",{className:"text-text-2",children:A.leafId}),t.champion.rule&&e.jsxs("span",{children:["rule ",t.champion.rule]})]}),typeof(A==null?void 0:A.text)=="string"&&e.jsx("span",{className:"block text-[12px] text-text-2 leading-relaxed whitespace-pre-wrap",children:A.text.length>400?`${A.text.slice(0,400)}…`:A.text})]}),u&&e.jsxs(lO,{basis:Array.isArray(u.basis)?u.basis:[],highlightKey:"confidence",highlight:a,onHighlight:r,className:"px-2 py-1 font-mono text-2xs text-text-4",children:[[u.candidates!=null&&`${u.candidates} candidates`,u.n_fused!=null&&u.n_agents!=null&&`${u.n_fused}/${u.n_agents} fused`,u.n_facts!=null&&`${u.n_facts} facts`,u.tools_grounded!=null&&`tools ${String(u.tools_grounded)}`].filter(Boolean).join(" · "),e.jsxs("span",{className:"opacity-60",children:[" · verifier: ",u.verifier==null?"awaiting integration":String(u.verifier)]})]}),t.evidence.length>0&&e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:t.evidence.slice(-3).map((h,O)=>e.jsx(lO,{basis:h.basis,highlightKey:`evidence-${t.evidence.length-3+O}`,highlight:a,onHighlight:r,className:"px-1.5 py-0.5 border border-border-subtle font-mono text-2xs text-text-4",title:h.values?JSON.stringify(h.values):void 0,children:h.source??"evidence"},`${h.source}-${O}`))})]})]})}const Voe={pending:"stop pending…",effected:"stopped","resolved-before-stop":"resolved before stop"};function Koe(t){var s;for(let n=t.length-1;n>=0;n--){if(t[n].kind!=="pipeline_done")continue;const a=(s=t[n].payload)==null?void 0:s.interrupts;if(!a||typeof a!="object")return null;const r=["acked","unanswered","unconsumed"].filter(i=>Array.isArray(a[i]));return r.length===0?null:Object.fromEntries(r.map(i=>[i,a[i].length]))}return null}function qoe({sessionLive:t,rollup:s}){const n=k(C=>C.axomSelected),a=k(C=>C.axomInterrupts),r=k(C=>C.axomStops),i=k(C=>C.sendAxomInterrupt),c=k(C=>C.sendAxomMessage),A=k(C=>C.sendAxomStop),u=k(C=>C.addToast),[x,h]=p.useState(""),[O,g]=p.useState(!1),b=p.useRef(null),y=n?vi(n.endpoint,n.session):null,v=y&&a[y]||{},S=y&&r[y]||null;async function j(){var P;const C=x.trim();if(C){h(""),g(!0);try{if(t)(await i(C)).truncated&&u("warning","Interrupt truncated","The runtime capped it at 2000 chars");else{const U=await c(C);U.busy?(u("warning","Turn already in flight","Not sent — type again to steer the running turn instead"),h(C)):U.tooLong&&(u("error","Message too long",`The runtime's max is ${U.max||32768} chars — nothing was truncated`),h(C))}}catch(U){U.status===503?u("error","This runtime is shutting down","Nothing was sent — that endpoint is going away."):u("error",t?"Interrupt failed":"Message failed",U.message),h(C)}finally{g(!1),(P=b.current)==null||P.focus()}}}async function N(){try{await A()}catch(C){u("error","Stop failed",C.message)}}const B=Object.entries(v).filter(([,C])=>C.state==="sent").slice(-3);return e.jsx("div",{className:"bg-surface-1/50 flex-shrink-0 border-t border-border",children:e.jsxs("div",{className:"px-4 py-3 flex flex-col gap-1.5",children:[(B.length>0||S||s)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap font-mono text-[10px] text-text-4",children:[B.map(([C,P])=>e.jsxs("span",{title:P.text,className:"max-w-56 truncate",children:["sent · ",P.text]},C)),S&&e.jsx("span",{className:X(S==="effected"||S==="pending"?"text-danger":"text-text-3"),children:Voe[S]}),s&&e.jsxs("span",{title:"Interrupt accounting from the last pipeline_done rollup — every interrupt ends in exactly one state",children:["rollup"," ",Object.entries(s).map(([C,P],U)=>e.jsxs("span",{className:C==="unconsumed"&&P>0?"text-warning":void 0,children:[U>0&&" · ",P," ",C]},C))]})]}),e.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-0 transition-colors overflow-hidden focus-within:border-text-4/40",children:[e.jsx("textarea",{ref:b,value:x,onChange:C=>h(C.target.value),onKeyDown:C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),j())},placeholder:t?"Steer Axom mid-flight...":"Message your Axom — starts a turn",rows:2,className:"w-full resize-none field-sizing-content min-h-[72px] max-h-60 px-3 py-2.5 text-[13px] leading-[20px] bg-transparent font-sans text-text-0 placeholder:text-text-4 focus:outline-none"}),e.jsxs("div",{className:"flex items-center gap-1 px-1.5 pb-1.5 pt-0.5",children:[t&&e.jsxs("span",{className:"flex items-center gap-2 pl-1.5 mr-auto",children:[e.jsxs("span",{className:"relative flex items-center justify-center w-3 h-3",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-accent/30 animate-ping [animation-duration:2s]"}),e.jsx("span",{className:"relative w-2 h-2 rounded-full bg-accent"})]}),e.jsx("span",{className:"text-[10px] text-text-4 font-sans",children:"turn in flight"})]}),e.jsx("div",{className:"flex-1"}),t&&e.jsxs("button",{onClick:N,disabled:!n||S==="pending",className:"flex items-center gap-1.5 h-7 px-2 rounded-md text-[11px] font-medium text-text-3 hover:text-danger hover:bg-danger/10 disabled:opacity-40 disabled:pointer-events-none transition-colors cursor-pointer",title:"Stop this turn",children:[e.jsx(mc,{size:13})," Stop"]}),e.jsx("button",{onClick:j,disabled:!n||!x.trim()||O,className:X("w-7 h-7 flex items-center justify-center rounded-md transition-colors cursor-pointer","disabled:opacity-15 disabled:cursor-not-allowed",x.trim()?"text-text-0 hover:text-text-1":"text-text-4"),title:t?"Steer (Enter)":"Send (Enter)",children:O?e.jsx(ze,{size:15,className:"animate-spin"}):t?e.jsx(jt,{size:15}):e.jsx(Jb,{size:15})})]})]})]})})}function Woe(){const t=k(J=>J.axomStatus),s=k(J=>J.axomStatusLoaded),n=k(J=>J.fetchAxomStatus),[a,r]=p.useState(!1),i=k(J=>J.axomSelected),c=k(J=>J.axomEvents),A=k(J=>J.axomPrompts),u=k(J=>J.axomAnomalies),x=k(J=>J.axomStops),h=k(J=>J.axomRemote),O=k(J=>J.selectAxomSession),g=k(J=>J.sendAxomStop),[b,y]=p.useState(null),[v,S]=p.useState(!1),N=((t==null?void 0:t.endpoints)||[])[0],B=h||(t==null?void 0:t.remote)||null;p.useEffect(()=>{if(!N||i)return;const J=N.sessions.find(W=>W.live)||N.sessions[0];J&&O(N.name,J.session)},[N,i,O]);const C=i?vi(i.endpoint,i.session):null,P=p.useMemo(()=>C?c[C]||[]:[],[C,c]),U=p.useMemo(()=>C?A[C]||[]:[],[C,A]);p.useEffect(()=>{s||n()},[s,n]),p.useEffect(()=>{if(s)return;const J=setTimeout(()=>r(!0),3e3);return()=>clearTimeout(J)},[s]),p.useEffect(()=>{y(null)},[C]);const T=p.useMemo(()=>Xoe(P),[P]);if(!s&&!a&&!v)return e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("span",{className:"flex items-center gap-2 text-xs text-text-4",children:[e.jsx(tc,{size:14,className:"animate-pulse text-accent"})," Checking for your Axom…"]})});if(!N||v)return e.jsx(woe,{onBack:N?()=>S(!1):null});const R=i&&N.sessions.find(J=>J.session===i.session),M=!!(R!=null&&R.live),I=N.remoteHost||N.name;return e.jsxs("div",{className:"h-full flex flex-col bg-surface-1",children:[e.jsx(Qoe,{endpoint:N,remote:B,anomalies:C&&u[C]||[],onSetup:()=>S(!0)}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsx(Eoe,{events:P,live:M,highlight:b,onHighlight:y}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[e.jsx(Soe,{endpoint:N}),e.jsx(Hoe,{about:N.about,events:P}),e.jsx(Doe,{events:P,prompts:U,sessionLive:M,endpointName:I,highlight:b,onHighlight:y}),T&&e.jsx(Zoe,{answer:T,onStop:()=>g().catch(()=>{}),stopState:C&&x[C]||null,highlight:b,onHighlight:y}),e.jsx(qoe,{sessionLive:M,rollup:Koe(P)})]})]})]})}const Yoe={code:"Code",general:"General"},Joe={light:"text-success",medium:"text-accent",heavy:"text-warning"};function eie(t){return t<1?`${Math.round(t*1024)} MB`:`${t} GB`}function vT({hardware:t}){if(!t)return null;const{totalRamGb:s,gpu:n,isAppleSilicon:a}=t;return e.jsxs("div",{className:"flex items-center gap-3 bg-surface-0 rounded-lg border border-border-subtle px-3 py-2.5",children:[e.jsx(jd,{size:14,className:"text-text-3 flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs font-sans",children:[e.jsxs("span",{className:"text-text-0 font-semibold",children:[s," GB RAM"]}),n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{className:"text-text-2",children:n.name})]}),a&&e.jsx(ke,{variant:"accent",className:"text-2xs",children:"Unified Memory"})]})})]})}function tie({onRecheck:t}){const[s,n]=p.useState(null),[a,r]=p.useState(!1),[i,c]=p.useState(!1),[A,u]=p.useState(!1),x=k(C=>C.addToast);p.useEffect(()=>{H.post("/providers/ollama/check").then(n).catch(()=>{})},[]);async function h(){r(!0);try{const C=await H.post("/providers/ollama/check");n(C),C.installed&&C.serverRunning?(x("success","Ollama is ready!"),t()):C.installed?x("info","Ollama installed — server needs to start"):x("info","Ollama not found — install and try again")}catch{}r(!1)}async function O(){c(!0);try{if((await H.post("/providers/ollama/serve")).ok){x("success","Ollama server started!");let P=!1;for(let U=0;U<5;U++){await new Promise(R=>setTimeout(R,2e3));const T=await H.post("/providers/ollama/check");if(n(T),T.serverRunning){P=!0;break}}P&&t()}}catch(C){x("error","Could not start server",C.message)}c(!1)}function g(C){navigator.clipboard.writeText(C),u(!0),setTimeout(()=>u(!1),2e3)}if(!s)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{hardware:b,install:y,requirements:v,installed:S,serverRunning:j}=s,N=b.totalRamGb>=v.minRAM,B=b.recommended;return e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsx(vT,{hardware:b}),N?e.jsxs("div",{className:"flex items-start gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2.5",children:[e.jsx(Ye,{size:14,className:"text-success flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans",children:[e.jsx("span",{className:"text-success font-semibold",children:"Your system is ready."}),e.jsx("span",{className:"text-text-2 ml-1",children:B.code?`Recommended: ${B.code}`:`${b.totalRamGb} GB RAM available`})]})]}):e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Gs,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsxs("span",{className:"text-warning font-semibold",children:[b.totalRamGb," GB RAM detected."]})," ","Minimum ",v.minRAM," GB needed. Smallest models may still work."]})]}),S&&!j&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Gs,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama installed but server not running."})," ","The server needs to be running to pull and use models."]})]}),e.jsxs(xe,{variant:"primary",size:"md",onClick:O,disabled:i,className:"w-full gap-1.5",children:[e.jsx(jt,{size:12}),i?"Starting...":"Start Ollama Server"]})]}),!S&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold text-text-1 font-sans",children:"Install Ollama"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 bg-surface-0 border border-border-subtle rounded-md px-3 py-2 text-xs font-mono text-text-1 truncate",children:y.command}),e.jsxs(xe,{variant:"secondary",size:"sm",onClick:()=>g(y.command),className:"h-8 px-2.5 gap-1 flex-shrink-0",children:[A?e.jsx(Ye,{size:12}):e.jsx(Nn,{size:12}),A?"Copied":"Copy"]})]}),y.alt&&e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:y.alt})]}),e.jsxs(xe,{variant:"secondary",size:"md",onClick:h,disabled:a,className:"w-full gap-1.5",children:[e.jsx(sn,{size:12,className:a?"animate-spin":""}),a?"Checking...":S?"Check again":"I installed it — check again"]})]})}function sie({model:t,isInstalled:s,isRecommended:n,canRun:a,onPull:r,onDelete:i,pulling:c}){const A=c===t.id;return e.jsxs("div",{className:X("flex items-center gap-2 px-3 py-2 border-t border-border-subtle transition-colors",!a&&"opacity-40"),children:[s?e.jsx(Ye,{size:12,className:"text-success flex-shrink-0"}):e.jsx("div",{className:"w-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 truncate",children:t.name}),n&&e.jsx(s0,{size:10,className:"text-warning flex-shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:X("text-2xs font-semibold font-sans",Joe[t.tier]),children:t.tier}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:eie(t.sizeGb)}),e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["· ",t.ramGb," GB RAM"]})]})]}),s?e.jsx("button",{onClick:()=>i(t.id),className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Remove model",children:e.jsx(Vt,{size:12})}):a?e.jsx(xe,{variant:"secondary",size:"sm",onClick:()=>r(t.id),disabled:!!c,className:"h-7 px-2 text-2xs gap-1",children:A?e.jsxs(e.Fragment,{children:[e.jsx(sn,{size:10,className:"animate-spin"})," Pulling..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Js,{size:10})," Pull"]})}):e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["Needs ",t.ramGb," GB"]})]})}function nie({onStopped:t}){const[s,n]=p.useState(null),a=k(c=>c.addToast);async function r(){n("stopping");try{(await H.post("/providers/ollama/stop")).ok?(a("info","Ollama server stopped"),t&&t()):a("error","Could not stop server")}catch(c){a("error","Stop failed",c.message)}n(null)}async function i(){n("restarting");try{(await H.post("/providers/ollama/restart")).ok?a("success","Ollama server restarted"):a("error","Restart failed")}catch(c){a("error","Restart failed",c.message)}n(null)}return e.jsxs("div",{className:"flex items-center gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-success"}),e.jsx("span",{className:"absolute inset-[-2px] rounded-full bg-success opacity-20 animate-pulse"})]}),e.jsx("span",{className:"text-xs font-sans text-success font-semibold",children:"Server Running"}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:":11434"}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:i,disabled:!!s,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-accent cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(sn,{size:10,className:s==="restarting"?"animate-spin":""}),s==="restarting"?"Restarting...":"Restart"]}),e.jsxs("button",{onClick:r,disabled:!!s,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-danger cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(Gs,{size:10}),s==="stopping"?"Stopping...":"Stop"]})]})}function aie({onModelChange:t}){var R,M;const[s,n]=p.useState(null),[a,r]=p.useState(null),[i,c]=p.useState("code"),[A,u]=p.useState(!1),[x,h]=p.useState(!1),O=k(I=>I.addToast),g=p.useRef(!1);function b(){H.get("/providers/ollama/models").then(I=>{var J;n(I),!g.current&&((J=I.installed)==null?void 0:J.length)===0&&(g.current=!0,setTimeout(b,2e3))}).catch(()=>{})}p.useEffect(()=>{b()},[]);async function y(I){r(I);try{await H.post("/providers/ollama/pull",{model:I}),O("success",`Pulled ${I}`),b(),t&&t()}catch(J){O("error",`Pull failed: ${J.message}`)}r(null)}async function v(I){try{await H.delete(`/providers/ollama/models/${encodeURIComponent(I)}`),O("info",`Removed ${I}`),b(),t&&t()}catch(J){O("error",`Delete failed: ${J.message}`)}}if(!s)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{installed:S,catalog:j,hardware:N}=s,B=new Set(S.map(I=>I.id)),C=N.totalRamGb,P=[(R=N.recommended)==null?void 0:R.code,(M=N.recommended)==null?void 0:M.general].filter(Boolean),U=j.filter(I=>I.category===i),T=A?U:U.filter(I=>I.ramGb<=C);return x?e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Gs,{size:14,className:"text-warning flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama server stopped."})," ","Start it again to pull and use models."]})]}),e.jsxs(xe,{variant:"primary",size:"md",onClick:async()=>{try{(await H.post("/providers/ollama/serve")).ok&&(O("success","Ollama server started!"),h(!1),g.current=!1,setTimeout(b,2e3))}catch(I){O("error","Could not start server",I.message)}},className:"w-full gap-1.5",children:[e.jsx(jt,{size:12}),"Start Ollama Server"]})]}):e.jsxs("div",{className:"space-y-2 p-3",children:[e.jsx(nie,{onStopped:()=>h(!0)}),e.jsx(vT,{hardware:N}),S.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-sans text-text-2",children:[e.jsx(Zi,{size:12,className:"text-text-3"}),e.jsx("span",{className:"font-semibold",children:S.length})," model",S.length!==1?"s":""," installed"]}),e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:Object.entries(Yoe).map(([I,J])=>e.jsx("button",{onClick:()=>c(I),className:X("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",i===I?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:J},I))}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[T.map(I=>e.jsx(sie,{model:I,isInstalled:B.has(I.id),isRecommended:P.includes(I.id),canRun:I.ramGb<=C,onPull:y,onDelete:v,pulling:a},I.id)),T.length===0&&e.jsxs("div",{className:"px-3 py-4 text-center text-xs text-text-4 font-sans",children:["No ",i," models available for your hardware"]})]}),!A&&U.length>T.length&&e.jsxs("button",{onClick:()=>u(!0),className:"flex items-center gap-1 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(rt,{size:10}),"Show ",U.length-T.length," more (exceed your RAM)"]})]})}function rie({isInstalled:t,onModelChange:s}){const[n,a]=p.useState(!1),[r,i]=p.useState(!1);return p.useEffect(()=>{t?H.post("/providers/ollama/check").then(c=>{a(c.installed&&c.serverRunning),i(!0)}).catch(()=>i(!0)):i(!0)},[t]),r?n?e.jsx(aie,{onModelChange:s}):e.jsx(tie,{onRecheck:()=>{a(!0),s&&s()}}):e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Checking Ollama..."})}function Xf({options:t,value:s,onChange:n}){return e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:t.map(a=>e.jsx("button",{onClick:()=>n(a.value),className:X("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",s===a.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:a.label},a.value))})}function Aa({label:t,icon:s,children:n,description:a}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs font-semibold text-text-1 font-sans",children:[s&&e.jsx(s,{size:13,className:"text-text-3"}),t]}),a&&e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:a})]}),n]})}function oie({agent:t}){const s=k(y=>y.killAgent),n=k(y=>y.rotateAgent),a=k(y=>y.spawnAgent),r=k(y=>y.closeDetail),i=k(y=>y.addToast),[c,A]=p.useState(null),[u,x]=p.useState(!1),h=t.status==="running"||t.status==="starting";async function O(){A("rotate");try{await n(t.id)}catch{}A(null)}async function g(){if(!u){x(!0),setTimeout(()=>x(!1),3e3);return}A("kill");try{await s(t.id,!h),r()}catch{}A(null),x(!1)}async function b(){A("clone");try{await a({role:t.role,provider:t.provider,model:t.model,name:`${t.name}-clone`,scope:t.scope,workingDir:t.workingDir}),i("success",`Cloned ${t.name}`)}catch{}A(null)}return h?e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs(xe,{variant:"primary",size:"md",onClick:O,disabled:c==="rotate",className:"gap-1.5",children:[e.jsx(Nd,{size:12,className:c==="rotate"?"animate-spin":""}),"Rotate"]}),e.jsxs(xe,{variant:"info",size:"md",onClick:b,disabled:!!c,className:"gap-1.5",children:[e.jsx(Nn,{size:12})," Clone"]}),e.jsxs(xe,{variant:"danger",size:"md",onClick:g,disabled:c==="kill",className:"gap-1.5",children:[e.jsx(t0,{size:12}),u?"Confirm":"Kill"]})]})}):e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs(xe,{variant:"info",size:"md",onClick:b,disabled:!!c,className:"gap-1.5",children:[e.jsx(Nn,{size:12})," Clone"]}),e.jsxs(xe,{variant:"danger",size:"md",onClick:g,disabled:c==="kill",className:"gap-1.5",children:[e.jsx(Vt,{size:12}),u?"Confirm":"Remove"]})]})}function iie({agent:t}){var Fe;const s=k(ie=>ie.addToast),n=k(ie=>ie.remoteHomedir),[a,r]=p.useState([]),[i,c]=p.useState(t.model||""),[A,u]=p.useState(""),[x,h]=p.useState(t.effort||"default"),[O,g]=p.useState(!1),[b,y]=p.useState(""),[v,S]=p.useState(null),[j,N]=p.useState(!1),[B,C]=p.useState(null),[P,U]=p.useState(t.routingMode||"auto"),[T,R]=p.useState([]),[M,I]=p.useState(""),[J,W]=p.useState(!1),[ee,V]=p.useState([]),[z,E]=p.useState(!1),[q,Z]=p.useState([]),[$,D]=p.useState(null),[Y,L]=p.useState(t.authMode||"subscription"),[te,pe]=p.useState(!1),K=t.status==="running"||t.status==="starting";p.useEffect(()=>{ce(),H.get("/integrations/installed").then(Be=>Z(Array.isArray(Be)?Be:[])).catch(()=>{}),H.get("/repos/imported").then(Be=>R((Array.isArray(Be)?Be:[]).filter(Re=>Re.status==="active"))).catch(()=>{}),t.provider==="claude-code"&&(H.get("/providers/claude-code/auth").then(Be=>D(Be)).catch(()=>D(null)),H.get("/credentials").then(Be=>pe(Array.isArray(Be)&&Be.some(Re=>Re.provider==="claude-code"))).catch(()=>pe(!1)));function ie(){ce()}return window.addEventListener("groove:providers-changed",ie),()=>window.removeEventListener("groove:providers-changed",ie)},[]);function ce(){H.get("/providers").then(ie=>r(Array.isArray(ie)?ie:[])).catch(()=>{})}p.useEffect(()=>{L(t.authMode||"subscription")},[t.id,t.authMode]),p.useEffect(()=>{c(t.model||""),H.get(`/agents/${t.id}/routing/recommend`).then(ie=>{U((ie==null?void 0:ie.mode)||"fixed")}).catch(()=>{})},[t.id,t.model]),p.useEffect(()=>{W(!1),t.personality?H.get(`/personalities/${t.name}`).then(ie=>{I((ie==null?void 0:ie.content)||""),W(!0)}).catch(()=>{I(""),W(!0)}):(I(""),W(!0)),H.get("/personalities").then(ie=>{V(Array.isArray(ie)?ie:ie.personalities||[])}).catch(()=>{})},[t.id,t.name]);const le=a.find(ie=>ie.id===t.provider);async function je(ie){const Be=Y;L(ie);try{await H.patch(`/agents/${t.id}`,{authMode:ie}),s("success",`Billing → ${ie==="usage"?"usage credits":"subscription"}`)}catch(Re){L(Be),s("error","Failed to change billing mode",Re.message)}}async function _(ie,Be){c(Be);try{const Re={model:Be};ie&&ie!==t.provider&&(Re.provider=ie),await H.patch(`/agents/${t.id}`,Re),s("success",`Model → ${Be}${Re.provider?` (${ie})`:""}`)}catch(Re){s("error","Model swap failed",Re.message)}}async function re(ie){try{await H.patch(`/agents/${t.id}`,{workingDir:ie}),s("success",`Working dir → ${ie.split("/").pop()||ie}`)}catch(Be){s("error","Update failed",Be.message)}}async function fe(ie){h(ie);try{await H.patch(`/agents/${t.id}`,{effort:ie}),s("success",`Effort → ${ie}`)}catch(Be){s("error","Update failed",Be.message)}}async function ve(ie){if(!ie.trim())return;const Be=[...t.scope||[],ie.trim()];try{await H.patch(`/agents/${t.id}`,{scope:Be}),u("")}catch(Re){s("error","Scope update failed",Re.message)}}async function Ce(ie){const Be=(t.scope||[]).filter((Re,St)=>St!==ie);try{await H.patch(`/agents/${t.id}`,{scope:Be})}catch(Re){s("error","Scope update failed",Re.message)}}async function Te(ie){if(b.trim())try{await H.post(`/credentials/${ie}`,{key:b.trim()}),s("success",`API key set for ${ie}`),y(""),S(null),ce(),window.dispatchEvent(new CustomEvent("groove:providers-changed"))}catch(Be){s("error","Failed to set key",Be.message)}}const Ze=t.spawnedAt||t.createdAt;return e.jsxs("div",{className:"px-5 py-5 space-y-6 overflow-y-auto h-full",children:[e.jsx(Aa,{label:"Active Model",icon:ha,children:e.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold font-mono text-text-0",children:t.model||"auto"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:(le==null?void 0:le.name)||t.provider})]}),(le==null?void 0:le.canHotSwap)&&K&&e.jsxs(ke,{variant:"accent",className:"text-2xs gap-1",children:[e.jsx(jt,{size:8})," Hot-swap"]})]}),((Fe=le==null?void 0:le.models)==null?void 0:Fe.length)>1&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3 pt-3 border-t border-border-subtle",children:le.models.filter(ie=>!ie.disabled).map(ie=>{const Be=ie.id===t.model;return e.jsx("button",{onClick:()=>_(t.provider,ie.id),disabled:!1,className:X("px-2.5 py-1 rounded-md text-xs font-mono transition-all","cursor-pointer",Be?"bg-accent/15 text-accent font-semibold":"bg-surface-4 text-text-2 hover:bg-surface-5 hover:text-text-0"),children:ie.name||ie.id},ie.id)})}),t.provider==="claude-code"&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-2xs font-medium text-text-2 font-sans",children:"Billing"}),e.jsx("div",{className:"flex gap-1 p-0.5 rounded-md bg-surface-3",children:[{id:"subscription",label:"Subscription"},{id:"usage",label:"Usage credits"}].map(ie=>e.jsx("button",{onClick:()=>je(ie.id),disabled:ie.id==="usage"&&!te,className:X("px-2 py-1 rounded text-2xs font-semibold font-sans transition-colors",ie.id==="usage"&&!te&&"opacity-40 cursor-not-allowed",Y===ie.id?"bg-accent text-white":"text-text-2 hover:text-text-0"),children:ie.label},ie.id))})]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans mt-1.5",children:te?"Applies on next rotation or restart — the running process keeps its current billing.":"Add an Anthropic API key in Settings → Providers to enable usage credits."})]})]})}),e.jsx(oie,{agent:t}),e.jsxs(Aa,{label:"Providers",icon:xc,description:"Click a provider to see its models and connection status.",children:[e.jsx("div",{className:"space-y-1.5",children:a.map(ie=>{var er;const Be=ie.id===t.provider,Re=ie.authType==="subscription"?ie.installed||((er=ie.authStatus)==null?void 0:er.authenticated):ie.authType==="local"?ie.installed:ie.installed&&ie.hasKey,St=B===ie.id,Bs=ie.models||[];return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[e.jsxs("button",{onClick:()=>C(St?null:ie.id),className:"w-full flex items-center gap-2.5 px-3 py-2 cursor-pointer hover:bg-surface-4/50 transition-colors",children:[e.jsx("div",{className:X("w-2 h-2 rounded-full flex-shrink-0",Re?"bg-success":"bg-text-4")}),e.jsx("span",{className:X("text-xs font-semibold font-sans flex-1 text-left",Re?"text-text-0":"text-text-3"),children:ie.name||ie.id}),Be&&e.jsx(ke,{variant:"accent",className:"text-2xs",children:"Active"}),!Re&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:ie.installed?"No key":"Not installed"}),e.jsx(rt,{size:12,className:X("text-text-4 transition-transform",St&&"rotate-180")})]}),St&&ie.authType==="local"&&e.jsx("div",{className:"border-t border-border-subtle",children:e.jsx(rie,{isInstalled:Re,onModelChange:ce})}),St&&ie.authType!=="local"&&e.jsxs("div",{className:"border-t border-border-subtle",children:[(!Re||ie.hasKey)&&e.jsx("div",{className:"px-3 py-2 bg-surface-1/50",children:v===ie.id?e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("input",{value:b,onChange:es=>y(es.target.value),onKeyDown:es=>es.key==="Enter"&&Te(ie.id),type:j?"text":"password",placeholder:`${ie.name||ie.id} API key...`,className:"w-full h-7 px-2.5 pr-7 text-2xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),e.jsx("button",{onClick:()=>N(!j),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:j?e.jsx(Uo,{size:10}):e.jsx(Ys,{size:10})})]}),e.jsx(xe,{variant:"primary",size:"sm",onClick:()=>Te(ie.id),disabled:!b.trim(),className:"h-7 px-2 text-2xs",children:"Save"}),e.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>{S(null),y("")},className:"h-7 px-2 text-2xs",children:"Cancel"})]}):e.jsxs("button",{onClick:()=>{S(ie.id),y(""),N(!1)},className:"flex items-center gap-1.5 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(Fi,{size:10}),Re?"Update API key":"Add API key to enable"]})}),Re&&Bs.filter(es=>!es.disabled).length>0&&Bs.filter(es=>!es.disabled).map(es=>{const rs=ie.id===t.provider&&es.id===t.model;return e.jsxs("button",{onClick:()=>_(ie.id,es.id),disabled:!1,className:X("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",rs?"text-accent":"text-text-2"),children:[rs?e.jsx(Ye,{size:11,className:"text-accent flex-shrink-0"}):e.jsx("div",{className:"w-[11px]"}),e.jsx("span",{className:"font-mono flex-1 truncate",children:es.name||es.id}),e.jsx(ke,{variant:rs?"accent":"default",className:"text-2xs",children:es.tier})]},es.id)})]})]},ie.id)})}),K&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans mt-1.5",children:[e.jsx(Gs,{size:10}),e.jsx("span",{children:"Model changes apply on next rotation or respawn."})]})]}),t.provider==="claude-code"&&$&&!$.authenticated&&e.jsxs("div",{className:"rounded-lg border border-warning/30 bg-warning/5 px-4 py-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gs,{size:13,className:"text-warning flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Claude Code is not signed in"})]}),e.jsxs("p",{className:"text-2xs text-text-2 font-sans",children:["Open the terminal and run: ",e.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"claude"})]})]}),t.provider==="claude-code"&&($==null?void 0:$.authenticated)&&e.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-success flex-shrink-0"}),"Signed in as ",$.email||"Claude user"," (",$.subscriptionType||"subscription",")"]}),e.jsx(Aa,{label:"Working Directory",icon:tn,description:"The root directory this agent operates in.",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 bg-surface-0 rounded-lg px-3 py-2.5 text-sm font-mono text-text-1 border border-border-subtle truncate min-w-0",children:t.workingDir||"Project root"}),e.jsxs(xe,{variant:"secondary",size:"md",onClick:()=>g(!0),className:"gap-1.5 flex-shrink-0",children:[e.jsx(Gb,{size:14})," Browse"]})]})}),e.jsx(Aa,{label:"Permission Mode",icon:Qn,description:"Full Send = no approvals. Agent Approve = Fullstack Manager reviews risky operations.",children:e.jsx(Xf,{options:[{value:"full",label:"Full Send"},{value:"auto",label:"Agent Approve"}],value:t.permission||"full",onChange:async ie=>{try{await H.patch(`/agents/${t.id}`,{permission:ie}),s("success",`Permission → ${ie==="full"?"Full Send":"Agent Approve"}`)}catch(Be){s("error","Update failed",Be.message)}}})}),e.jsxs(Aa,{label:"Model Routing",icon:Mo,description:"How Groove selects models for this agent's tasks.",children:[e.jsx(Xf,{options:[{value:"fixed",label:"Fixed"},{value:"auto",label:"Auto"},{value:"auto-floor",label:"Auto + Floor"}],value:P,onChange:async ie=>{U(ie);try{await H.post(`/agents/${t.id}/routing`,{mode:ie}),s("success",`Routing → ${ie}`)}catch(Be){s("error","Update failed",Be.message)}}}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans mt-1",children:[P==="fixed"&&"Uses the selected model for all tasks.",P==="auto"&&"Groove picks Opus/Sonnet/Haiku based on task complexity.",P==="auto-floor"&&"Auto-routes but never drops below Sonnet."]})]}),e.jsx(Aa,{label:"File Scope",icon:Qn,description:"Restrict which files this agent can access. Empty = unrestricted.",children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(t.scope||[]).map((ie,Be)=>e.jsxs(ke,{variant:"default",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[ie,e.jsx("button",{onClick:()=>Ce(Be),className:"hover:text-danger cursor-pointer",children:e.jsx(qe,{size:10})})]},Be)),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{value:A,onChange:ie=>u(ie.target.value),onKeyDown:ie=>ie.key==="Enter"&&ve(A),placeholder:"e.g. src/**",className:"w-28 h-7 px-2.5 text-xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsx("button",{onClick:()=>ve(A),disabled:!A.trim(),className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:e.jsx(ot,{size:12})})]})]})}),e.jsx(Aa,{label:"Effort Level",icon:fc,description:"Controls how deep the agent reasons. Higher = more tokens but better results.",children:e.jsx(Xf,{options:[{value:"min",label:"Min"},{value:"low",label:"Low"},{value:"default",label:"Default"},{value:"high",label:"High"},{value:"max",label:"Max"},{value:"ultra",label:"Ultra"}],value:x,onChange:fe})}),e.jsx(Aa,{label:"Agent Details",icon:xc,children:e.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle divide-y divide-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"ID"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.id})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Role"}),e.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:t.role})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Provider"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.provider})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Model"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.model||"auto"})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Status"}),e.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:t.status})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Spawned"}),e.jsx("span",{className:"text-xs text-text-1 font-sans",children:Ze?cs(Ze):"—"})]}),t.sessionId&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Session"}),e.jsxs("span",{className:"text-xs text-text-1 font-mono",children:[t.sessionId.slice(0,16),"..."]})]})]})}),e.jsxs(Aa,{label:"Integrations",icon:Ls,description:"Attach MCP integrations for external services.",children:[e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(t.integrations||[]).map(ie=>{const Be=Ci[ie],Re=q.find(St=>St.id===ie);return e.jsxs(ke,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[Be?e.jsx("img",{src:Be,alt:"",className:"w-2.5 h-2.5"}):e.jsx(Ls,{size:9}),(Re==null?void 0:Re.name)||ie,e.jsx("button",{onClick:async()=>{try{await H.delete(`/agents/${t.id}/integrations/${ie}`),s("success",`Detached ${(Re==null?void 0:Re.name)||ie}`)}catch(St){s("error","Detach failed",St.message)}},className:"hover:text-danger cursor-pointer",children:e.jsx(qe,{size:10})})]},ie)}),q.filter(ie=>ie.configured!==!1&&!(t.integrations||[]).includes(ie.id)).length>0&&e.jsxs("div",{className:"relative group",children:[e.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer transition-colors",children:e.jsx(ot,{size:12})}),e.jsx("div",{className:"absolute top-full left-0 mt-1 z-20 hidden group-hover:block bg-surface-2 border border-border-subtle rounded-lg shadow-xl py-1 min-w-[200px]",children:q.filter(ie=>ie.configured!==!1&&!(t.integrations||[]).includes(ie.id)).map(ie=>{const Be=Ci[ie.id];return e.jsxs("button",{onClick:async()=>{try{await H.post(`/agents/${t.id}/integrations/${ie.id}`),s("success",`Attached ${ie.name||ie.id}`)}catch(Re){s("error","Attach failed",Re.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:[Be?e.jsx("img",{src:Be,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(Ls,{size:12,className:"text-text-3 flex-shrink-0"}),ie.name||ie.id]},ie.id)})})]}),(t.integrations||[]).length===0&&q.length===0&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No integrations installed — browse the Integrations tab"})]}),(t.integrations||[]).length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"text-2xs font-medium text-text-3 font-sans block mb-1.5",children:"Integration Approvals"}),e.jsx(Xf,{options:[{value:"auto",label:"Auto"},{value:"manual",label:"Manual"}],value:t.integrationApproval||"manual",onChange:async ie=>{try{await H.patch(`/agents/${t.id}`,{integrationApproval:ie}),s("success",`Integration approvals → ${ie==="auto"?"Auto":"Manual"}`)}catch(Be){s("error","Update failed",Be.message)}}})]})]}),T.length>0&&e.jsx(Aa,{label:"Repos",icon:nc,description:"Attach imported repos so this agent knows where they are.",children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(t.repos||[]).map(ie=>{const Be=T.find(Re=>Re.id===ie);return e.jsxs(ke,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[(Be==null?void 0:Be.name)||ie,e.jsx("button",{onClick:async()=>{try{await H.delete(`/agents/${t.id}/repos/${ie}`),s("success",`Detached ${(Be==null?void 0:Be.name)||ie}`)}catch(Re){s("error","Detach failed",Re.message)}},className:"hover:text-danger cursor-pointer",children:e.jsx(qe,{size:10})})]},ie)}),T.filter(ie=>!(t.repos||[]).includes(ie.id)).length>0&&e.jsxs("div",{className:"relative group",children:[e.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer transition-colors",children:e.jsx(ot,{size:12})}),e.jsx("div",{className:"absolute top-full left-0 mt-1 z-20 hidden group-hover:block bg-surface-2 border border-border-subtle rounded-lg shadow-xl py-1 min-w-[200px]",children:T.filter(ie=>!(t.repos||[]).includes(ie.id)).map(ie=>e.jsxs("button",{onClick:async()=>{try{await H.post(`/agents/${t.id}/repos/${ie.id}`),s("success",`Attached ${ie.name||ie.id}`)}catch(Be){s("error","Attach failed",Be.message)}},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-4 cursor-pointer transition-colors",children:[e.jsx("div",{className:"font-semibold",children:ie.name||ie.repo}),e.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:ie.clonedTo})]},ie.id))})]}),(t.repos||[]).length===0&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No repos attached — import one from the Integrations tab"})]})}),e.jsxs(Aa,{label:"Personality",icon:Vi,description:"Injected into every prompt. Changes apply on next spawn or rotation.",children:[e.jsx("textarea",{value:M,onChange:ie=>I(ie.target.value),placeholder:J?"Describe this agent's personality, tone, and behavior...":"Loading...",rows:4,className:"w-full min-h-[4rem] max-h-[10rem] resize-y bg-surface-0 border border-border-subtle rounded-md p-2 text-xs font-mono text-text-1 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(xe,{variant:"primary",size:"sm",disabled:z,onClick:async()=>{E(!0);try{await H.put(`/personalities/${t.name}`,{content:M}),s("success","Personality saved")}catch(ie){s("error","Save failed",ie.message)}E(!1)},className:"h-7 px-3 text-2xs gap-1",children:[e.jsx(Mr,{size:10}),z?"Saving...":"Save"]}),ee.length>0&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:"",onChange:ie=>{if(!ie.target.value)return;const Be=ee.find(Re=>(Re.name||Re)===ie.target.value);Be&&H.get(`/personalities/${Be.name||Be}`).then(Re=>{Re!=null&&Re.content&&I(Re.content)}).catch(()=>{})},className:"h-7 px-2 pr-7 text-2xs rounded-md bg-surface-1 border border-border-subtle text-text-2 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Clone from..."}),ee.filter(ie=>(ie.name||ie)!==t.name).map(ie=>e.jsx("option",{value:ie.name||ie,children:ie.name||ie},ie.name||ie))]}),e.jsx(rt,{size:10,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]})]})]}),t.prompt&&e.jsx(Aa,{label:"Original Prompt",icon:Mo,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3 py-3 text-xs text-text-2 font-sans leading-relaxed max-h-40 overflow-y-auto",children:t.prompt})}),e.jsx(Cc,{open:O,onOpenChange:g,currentPath:t.workingDir||n||"/",homePath:n,onSelect:re})]})}const xQ=[];function lie({data:t,isAlive:s,height:n=48}){const a=p.useRef(null);return p.useEffect(()=>{const r=a.current;if(!r||!t.length)return;const i=r.getContext("2d"),c=window.devicePixelRatio||1,A=r.clientWidth,u=r.clientHeight;r.width=A*c,r.height=u*c,i.scale(c,c),i.clearRect(0,0,A,u);const x=t.map(y=>y.v),h=Math.min(...x),g=Math.max(...x,1)-h||1;i.beginPath(),i.moveTo(0,u),t.forEach((y,v)=>{const S=v/(t.length-1)*A,j=u-(y.v-h)/g*(u-4)-2;i.lineTo(S,j)}),i.lineTo(A,u),i.closePath();const b=i.createLinearGradient(0,0,0,u);if(b.addColorStop(0,s?"rgba(51,175,188,0.15)":"rgba(110,118,129,0.08)"),b.addColorStop(1,"rgba(0,0,0,0)"),i.fillStyle=b,i.fill(),i.beginPath(),i.strokeStyle=s?oe.accent:oe.text3,i.lineWidth=1.5,t.forEach((y,v)=>{const S=v/(t.length-1)*A,j=u-(y.v-h)/g*(u-4)-2;v===0?i.moveTo(S,j):i.lineTo(S,j)}),i.stroke(),t.length>1&&s){const y=t[t.length-1],v=A-1,S=u-(y.v-h)/g*(u-4)-2;i.beginPath(),i.arc(v,S,5,0,Math.PI*2),i.fillStyle="rgba(51,175,188,0.3)",i.fill(),i.beginPath(),i.arc(v,S,2.5,0,Math.PI*2),i.fillStyle=oe.accent,i.fill()}},[t,s]),e.jsx("div",{className:"w-full rounded-lg bg-surface-0 overflow-hidden border border-border-subtle",style:{height:n},children:e.jsx("canvas",{ref:a,className:"w-full h-full"})})}function Gf({icon:t,label:s,value:n,color:a,sub:r}){return e.jsxs("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(t,{size:12,className:a||"text-text-3"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans uppercase tracking-wider",children:s})]}),e.jsx("div",{className:X("text-lg font-bold font-mono tabular-nums",a||"text-text-0"),children:n}),r&&e.jsx("div",{className:"text-2xs text-text-4 font-sans mt-0.5",children:r})]})}function cie({score:t}){const s=Math.min(Math.max(t,0),100);let n=oe.success,a="Healthy";return s<40?(n=oe.danger,a="Degraded"):s<70&&(n=oe.warning,a="Fair"),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("span",{className:"text-2xs text-text-3 font-sans flex items-center gap-1.5",children:[e.jsx(QM,{size:11}),"Session Health"]}),e.jsxs("span",{className:"text-xs font-bold font-mono",style:{color:n},children:[s,"/100"]})]}),e.jsx("div",{className:"h-2 bg-surface-0 rounded-full overflow-hidden border border-border-subtle",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700",style:{width:`${s}%`,background:n}})}),e.jsx("span",{className:"text-2xs font-sans mt-1 block",style:{color:n},children:a})]})}function Aie(t){const s=(t||"").toLowerCase();return s.includes("edit")||s.includes("writ")?{icon:rd,color:"text-warning"}:s.includes("read")||s.includes("view")?{icon:Ys,color:"text-info"}:s.includes("search")||s.includes("grep")||s.includes("glob")?{icon:ls,color:"text-purple"}:s.includes("bash")||s.includes("command")||s.includes("terminal")?{icon:Za,color:"text-orange"}:s.includes("error")||s.includes("fail")?{icon:Gs,color:"text-danger"}:s.includes("spawn")||s.includes("start")?{icon:jt,color:"text-success"}:s.includes("complet")||s.includes("done")?{icon:To,color:"text-success"}:{icon:Zn,color:"text-text-4"}}function die({agent:t}){const s=k(c=>c.tokenTimeline[t.id])||xQ,n=k(c=>c.activityLog[t.id])||xQ,a=t.status==="running"||t.status==="starting",r=p.useMemo(()=>{if(s.length<2)return 0;const c=s.slice(-10),A=(c[c.length-1].t-c[0].t)/6e4,u=c[c.length-1].v-c[0].v;return A>0?Math.round(u/A):0},[s]),i=p.useMemo(()=>{const c=t.contextUsage||0;let A=100;return c>90?A-=50:c>70?A-=25:c>50&&(A-=10),r>5e3?A-=15:r>3e3&&(A-=8),t.status==="crashed"&&(A=10),t.status==="completed"&&(A=95),Math.max(0,Math.min(100,A))},[t.contextUsage,t.status,r]);return e.jsxs("div",{className:"px-5 py-5 space-y-5 overflow-y-auto h-full",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Token Burn"}),a&&e.jsx("span",{className:"text-2xs text-accent font-mono animate-pulse",children:"LIVE"})]}),e.jsx(lie,{data:s,isAlive:a,height:56})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(Gf,{icon:rM,label:"Burn Rate",value:r>0?`${Ut(r)}/m`:"—",color:r>5e3?"text-danger":r>2e3?"text-warning":"text-text-0"}),e.jsx(Gf,{icon:FS,label:"Cost",value:qa(t.costUsd||0),color:"text-text-0"}),e.jsx(Gf,{icon:Nd,label:"Rotations",value:t.rotations||"0",color:"text-text-0"}),e.jsx(Gf,{icon:jt,label:"Turns",value:t.turns||"0",color:"text-text-0"})]}),e.jsx(cie,{score:i}),t.prompt&&e.jsxs("div",{children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-1.5",children:"Task"}),e.jsx("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 text-xs text-text-2 font-sans leading-relaxed max-h-28 overflow-y-auto border border-border-subtle",children:t.prompt})]}),n.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-2",children:"Activity"}),e.jsxs("div",{className:"space-y-0 relative",children:[e.jsx("div",{className:"absolute left-[9px] top-2 bottom-2 w-px bg-border-subtle"}),n.slice(-12).reverse().map((c,A)=>{const u=Aie(c.text),x=u.icon;return e.jsxs("div",{className:"flex items-start gap-3 py-1.5 relative",children:[e.jsx("div",{className:X("w-[18px] h-[18px] rounded-full flex items-center justify-center flex-shrink-0 z-10","bg-surface-1 border border-border-subtle"),children:e.jsx(x,{size:9,className:u.color})}),e.jsx("span",{className:"text-2xs text-text-2 font-sans flex-1 line-clamp-1 pt-0.5",children:c.text}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0 pt-0.5",children:cs(c.timestamp)})]},A)})]})]})]})}function uie({agent:t}){const s=k(T=>T.addToast),[n,a]=p.useState([]),[r,i]=p.useState(""),[c,A]=p.useState(null),[u,x]=p.useState(""),[h,O]=p.useState(""),[g,b]=p.useState(!1),[y,v]=p.useState(!1),[S,j]=p.useState("");async function N(){try{const T=await H.get(`/agents/${t.id}/mdfiles`);a(T.files||[]),i(T.workingDir||"")}catch{}}p.useEffect(()=>{N()},[t.id]);async function B(T){try{const R=await H.get(`/agents/${t.id}/mdfiles/read?path=${encodeURIComponent(T)}`);x(R.content||""),O(R.content||""),A(T)}catch(R){s("error","Failed to read file",R.message)}}async function C(){if(c){b(!0);try{await H.put(`/agents/${t.id}/mdfiles/write`,{path:c,content:u}),O(u),s("success",`Saved ${c}`)}catch(T){s("error","Save failed",T.message)}b(!1)}}async function P(){const T=S.trim();if(T)try{await H.post(`/agents/${t.id}/mdfiles/create`,{name:T}),j(""),v(!1),s("success",`Created ${T}.md`),N()}catch(R){s("error","Create failed",R.message)}}const U=u!==h;return c?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border-subtle",children:[e.jsx("button",{onClick:()=>{A(null),x(""),O("")},className:"p-1 text-text-3 hover:text-text-0 cursor-pointer",children:e.jsx(Xi,{size:14})}),e.jsx(wn,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs text-text-0 font-sans font-medium flex-1 truncate",children:c}),U&&e.jsx("span",{className:"text-[10px] text-warning font-sans",children:"unsaved"}),e.jsxs("button",{onClick:C,disabled:!U||g,className:X("flex items-center gap-1 px-2.5 py-1 rounded text-2xs font-sans font-medium cursor-pointer transition-colors",U?"bg-accent/15 text-accent hover:bg-accent/25":"text-text-4 opacity-50 cursor-not-allowed"),children:[e.jsx(Mr,{size:10}),g?"Saving...":"Save"]})]}),e.jsx("textarea",{value:u,onChange:T=>x(T.target.value),className:"flex-1 w-full px-4 py-3 bg-surface-0 text-[12px] font-mono text-text-1 leading-relaxed resize-none focus:outline-none",spellCheck:!1})]}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 border-b border-border-subtle",children:[e.jsx(wn,{size:12,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:"Markdown Files"}),e.jsx("button",{onClick:()=>v(!0),className:"p-1 text-text-4 hover:text-accent cursor-pointer",title:"Create file",children:e.jsx(ot,{size:12})}),e.jsx("button",{onClick:N,className:"p-1 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(sn,{size:11})})]}),r&&e.jsx("div",{className:"px-4 py-1.5 text-[10px] text-text-4 font-mono truncate border-b border-border-subtle/50",children:r}),y&&e.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-b border-border-subtle bg-surface-0",children:[e.jsx(wn,{size:11,className:"text-accent flex-shrink-0"}),e.jsx("input",{autoFocus:!0,value:S,onChange:T=>j(T.target.value),onKeyDown:T=>{T.key==="Enter"&&P(),T.key==="Escape"&&(v(!1),j(""))},placeholder:"filename",className:"flex-1 bg-transparent text-xs text-text-0 font-mono outline-none placeholder:text-text-4"}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:".md"}),e.jsx("button",{onClick:P,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:e.jsx(Mr,{size:11})}),e.jsx("button",{onClick:()=>{v(!1),j("")},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:11})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center px-4",children:[e.jsx(wn,{size:20,className:"text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No markdown files found"}),e.jsx("p",{className:"text-[10px] text-text-4 font-sans mt-1",children:"MD files in the agent's working directory will appear here"})]}):e.jsx("div",{className:"py-1",children:n.map(T=>e.jsxs("button",{onClick:()=>B(T.path),className:"w-full flex items-center gap-2.5 px-4 py-2 text-left hover:bg-surface-5 transition-colors cursor-pointer",children:[e.jsx(wn,{size:13,className:"text-accent flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-xs text-text-0 font-sans block truncate",children:T.name}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:T.path})]}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono flex-shrink-0",children:T.size>1024?`${(T.size/1024).toFixed(1)}K`:`${T.size}B`}),T.source==="personality"&&e.jsx("span",{className:"text-[9px] font-mono text-purple bg-purple/10 px-1 py-px rounded flex-shrink-0",children:"personality"}),T.source==="user"&&e.jsx("span",{className:"text-[9px] font-mono text-accent bg-accent/10 px-1 py-px rounded flex-shrink-0",children:"custom"})]},T.path))})})]})}const fie={running:"bg-accent",starting:"bg-warning",completed:"bg-info",crashed:"bg-danger",stopped:"bg-text-4",killed:"bg-text-4",rotating:"bg-accent"},xie={running:"success",starting:"warning",stopped:"default",crashed:"danger",completed:"accent",killed:"default",rotating:"purple"},mie={running:"Running",starting:"Starting",stopped:"Stopped",crashed:"Crashed",completed:"Done",killed:"Killed",rotating:"Rotating"},hie=[{id:"command",label:"Chat",icon:Ga},{id:"config",label:"Config",icon:hc},{id:"telemetry",label:"Monitor",icon:Mo},{id:"mdfiles",label:"Files",icon:wn}];function pie({agent:t}){const s=k(j=>j.addToast),n=k(j=>j.agents),a=k(j=>j.teams),r=k(j=>j.switchAgentPanel),[i,c]=p.useState(!1),[A,u]=p.useState(t.name),[x,h]=p.useState(!1),[O,g]=p.useState(""),b=p.useRef(null);p.useEffect(()=>{if(!x)return;const j=B=>{b.current&&!b.current.contains(B.target)&&h(!1)},N=B=>{B.key==="Escape"&&h(!1)};return document.addEventListener("mousedown",j),document.addEventListener("keydown",N),()=>{document.removeEventListener("mousedown",j),document.removeEventListener("keydown",N)}},[x]);const y=p.useMemo(()=>{const j=O.trim().toLowerCase(),N=new Map;for(const B of n){if(j&&!B.name.toLowerCase().includes(j)&&!B.role.toLowerCase().includes(j))continue;const C=B.teamId||"_none";N.has(C)||N.set(C,[]),N.get(C).push(B)}return Array.from(N.entries()).map(([B,C])=>{var P;return{teamId:B,name:((P=a.find(U=>U.id===B))==null?void 0:P.name)||"No team",agents:C.sort((U,T)=>U.name.localeCompare(T.name))}}).sort((B,C)=>B.name.localeCompare(C.name))},[n,a,O]);async function v(){const j=A.trim();if(!j||j===t.name){c(!1);return}try{await H.patch(`/agents/${t.id}`,{name:j.replace(/\s+/g,"-")}),s("success",`Renamed → ${j}`)}catch(N){s("error","Rename failed",N.message),u(t.name)}c(!1)}function S(j){h(!1),g(""),j!==t.id&&r(j)}return i?e.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-0",children:[e.jsx("input",{value:A,onChange:j=>u(j.target.value),onKeyDown:j=>{j.key==="Enter"&&v(),j.key==="Escape"&&(u(t.name),c(!1))},className:"flex-1 min-w-0 h-6 px-1.5 text-sm font-bold bg-surface-0 border border-accent/30 rounded text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent/40",autoFocus:!0}),e.jsx("button",{onClick:v,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:e.jsx(Ye,{size:12})}),e.jsx("button",{onClick:()=>{u(t.name),c(!1)},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:12})})]}):e.jsxs("div",{ref:b,className:"relative flex items-center gap-1.5 flex-1 min-w-0 group",children:[e.jsxs("button",{onClick:()=>h(j=>!j),className:"flex items-center gap-1 min-w-0 cursor-pointer rounded px-1 -mx-1 py-0.5 hover:bg-surface-3 transition-colors",title:"Switch agent",children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans truncate",children:t.name}),e.jsx(rt,{size:13,className:X("text-text-4 flex-shrink-0 transition-transform",x&&"rotate-180")})]}),e.jsx("button",{onClick:()=>{u(t.name),c(!0)},className:"p-0.5 text-text-4 opacity-0 group-hover:opacity-100 hover:text-text-1 cursor-pointer transition-opacity flex-shrink-0",title:"Rename agent",children:e.jsx(zr,{size:10})}),x&&e.jsxs("div",{className:"absolute top-full left-0 mt-1.5 w-72 max-h-[70vh] flex flex-col bg-surface-1 border border-border rounded-lg shadow-xl z-50 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-2 border-b border-border-subtle",children:[e.jsx(ls,{size:12,className:"text-text-4 flex-shrink-0"}),e.jsx("input",{value:O,onChange:j=>g(j.target.value),placeholder:"Switch to agent…",autoFocus:!0,className:"flex-1 min-w-0 bg-transparent text-xs text-text-0 font-sans placeholder:text-text-4 focus:outline-none"})]}),e.jsxs("div",{className:"overflow-y-auto py-1",children:[y.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-text-4 font-sans text-center",children:"No agents match"}),y.map(j=>e.jsxs("div",{children:[e.jsx("div",{className:"px-2.5 pt-1.5 pb-0.5 text-2xs font-semibold text-text-4 font-sans uppercase tracking-wide",children:j.name}),j.agents.map(N=>e.jsxs("button",{onClick:()=>S(N.id),className:X("w-full flex items-center gap-2 px-2.5 py-1.5 text-left cursor-pointer transition-colors",N.id===t.id?"bg-accent/10":"hover:bg-surface-3"),children:[e.jsx("span",{className:X("w-1.5 h-1.5 rounded-full flex-shrink-0",fie[N.status]||"bg-text-4")}),e.jsx("span",{className:X("text-xs font-sans truncate",N.id===t.id?"text-accent font-medium":"text-text-1"),children:N.name}),e.jsx("span",{className:"text-2xs text-text-4 font-sans ml-auto flex-shrink-0 capitalize",children:N.role})]},N.id))]},j.teamId))]})]})]})}function gie(){const t=k(y=>y.detailPanel),s=k(y=>y.agents),n=k(y=>y.activeTeamId),a=k(y=>y.activeView);k(y=>y.addToast);const[r,i]=p.useState("command"),c=p.useRef(null),A=(t==null?void 0:t.type)==="agent"?t.agentId:null,u=A?s.find(y=>y.id===A):null;u?c.current=u:c.current&&A&&c.current.id!==A&&(c.current=null);const x=u||c.current,h=(u==null?void 0:u.status)==="running"||(u==null?void 0:u.status)==="starting";if(!x||a!=="fleet"&&n&&x.teamId&&x.teamId!==n)return null;const O=Math.round((x.contextUsage||0)*100),g=x.spawnedAt||x.createdAt,b=g?Math.floor((Date.now()-new Date(g).getTime())/1e3):0;return Sc(x.role),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex-shrink-0",children:[e.jsxs("div",{className:"pl-4 pr-10 pt-3 pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pie,{agent:x}),e.jsx(ke,{variant:xie[x.status]||"default",dot:h?"pulse":void 0,className:"text-2xs flex-shrink-0",children:mie[x.status]||x.status})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-2xs text-text-3 font-mono",children:[e.jsx("span",{className:"capitalize",children:x.role}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{children:[x.provider,":",x.model||"auto"]}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{children:[Ut(x.tokensUsed||0)," tok"]}),O>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{className:X(O>80?"text-danger":O>60?"text-warning":"text-text-3"),children:[O,"% ctx"]})]}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{children:Zo(b)})]})]}),e.jsx("div",{className:"flex items-center px-4 border-b border-border-subtle",children:hie.map(y=>{const v=y.icon,S=r===y.id;return e.jsxs("button",{onClick:()=>i(y.id),className:X("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",S?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"),children:[e.jsx(v,{size:11}),y.label]},y.id)})})]}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[r==="command"&&e.jsx(OT,{agent:x}),r==="config"&&e.jsx(iie,{agent:x}),r==="telemetry"&&e.jsx(die,{agent:x}),r==="mdfiles"&&e.jsx(uie,{agent:x})]})]})}const Oie=[{id:"chat",label:"Chat",desc:"Companion, assistant, conversation",icon:Vi,tier:"Medium"},{id:"planner",label:"Planner",desc:"Plans the team and tasks",icon:$i,tier:"Heavy"},{id:"backend",label:"Backend",desc:"APIs, services, databases",icon:Qs,tier:"Medium"},{id:"frontend",label:"Frontend",desc:"UI, components, styling",icon:jd,tier:"Medium"},{id:"fullstack",label:"Fullstack",desc:"End-to-end implementation",icon:An,tier:"Heavy"},{id:"testing",label:"Testing",desc:"Tests, coverage, QA",icon:Sd,tier:"Medium"},{id:"devops",label:"DevOps",desc:"CI/CD, infra, deployment",icon:zb,tier:"Medium"},{id:"docs",label:"Docs",desc:"Documentation, guides",icon:wn,tier:"Light"},{id:"security",label:"Security",desc:"Audits, vulnerabilities",icon:Qn,tier:"Medium"},{id:"database",label:"Database",desc:"Schema, migrations, queries",icon:Lb,tier:"Medium"},{id:"cmo",label:"CMO",desc:"Marketing, content, growth",icon:Kb,tier:"Medium"},{id:"cfo",label:"CFO",desc:"Finance, metrics, forecasting",icon:TS,tier:"Medium"},{id:"ea",label:"EA",desc:"Executive assistant, scheduling",icon:WS,tier:"Light"},{id:"support",label:"Support",desc:"Customer support, FAQs",icon:IS,tier:"Medium"},{id:"analyst",label:"Analyst",desc:"Data analysis, insights",icon:sm,tier:"Medium"},{id:"creative",label:"Writer",desc:"Copy, articles, proposals",icon:ZS,tier:"Heavy",skillHint:!0},{id:"slides",label:"Slides",desc:"Pitch decks, presentations",icon:VS,tier:"Heavy",skillHint:!0},{id:"ambassador",label:"Ambassador",desc:"Bridge to federated server",icon:Vn,tier:"Light"}];function mQ(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"text-accent flex-shrink-0",children:[e.jsx("circle",{cx:"7",cy:"7",r:"6",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1"}),e.jsx("path",{d:"M4.5 7 L6.5 9 L9.5 5.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}function bie(){var $d;const t=k(ne=>ne.detailPanel),s=k(ne=>ne.closeDetail),n=k(ne=>ne.spawnAgent),a=qn(),r=k(ne=>ne.fetchProviders),i=k(ne=>ne.teams),c=k(ne=>ne.activeTeamId),A=k(ne=>ne.createTeam),u=(t==null?void 0:t.type)==="spawn",[x,h]=p.useState(""),[O,g]=p.useState(""),[b,y]=p.useState(""),[v,S]=p.useState(""),[j,N]=p.useState(""),[B,C]=p.useState(""),[P,U]=p.useState([]),[T,R]=p.useState([]),[M,I]=p.useState([]),[J,W]=p.useState(!1),[ee,V]=p.useState(""),[z,E]=p.useState("manual"),[q,Z]=p.useState([]),[$,D]=p.useState([]),[Y,L]=p.useState(!1),[te,pe]=p.useState(""),[K,ce]=p.useState([]),[le,je]=p.useState(""),[_,re]=p.useState(!1),[fe,ve]=p.useState(!1),[Ce,Te]=p.useState(""),[Ze,Fe]=p.useState([]),[ie,Be]=p.useState(null),[Re,St]=p.useState([]),[Bs,er]=p.useState(!1),[es,rs]=p.useState(!1),[tr,qo]=p.useState("subscription"),[Wo,sr]=p.useState(!1),[Ps,nr]=p.useState("new"),[Oa,Bn]=p.useState(""),[nn,bs]=p.useState(""),Wn=k(ne=>ne.federation),Ot=k(ne=>ne.ollamaRunningModels),Ae=x||O,He=P.find(ne=>ne.id===v),Qe=(He==null?void 0:He.models)||[],Xe=P.filter(ne=>ne.authType==="api-key"?ne.installed&&ne.hasKey:ne.installed),ts=!!(t!=null&&t.presetProvider||t!=null&&t.presetModel),vs=(t==null?void 0:t.presetTeamId)||null,an=!vs&&(ts||!c);p.useEffect(()=>{if(u){const ne=(t==null?void 0:t.presetProvider)||"",Se=(t==null?void 0:t.presetModel)||"";r().then(Ve=>{const Ke=Array.isArray(Ve)?Ve:Ve.providers||[];U(Ke);const Ea=Ke.filter(rn=>rn.authType==="api-key"?rn.installed&&rn.hasKey:rn.installed);if(Ea.length>0&&!ne){const ar=["claude-code","gemini","codex","ollama"].find(Wi=>Ea.some(xn=>xn.id===Wi))||Ea[0].id;S(ar)}if(ne&&S(ne),Se){const rn=Ke.find(xn=>xn.id===(ne||v)),ar=(rn==null?void 0:rn.models)||[];if(ar.find(xn=>xn.id===Se))N(Se);else{const xn=Se.split(":"),Yi=xn.length>=3?xn.slice(2).join(":"):xn[xn.length-1],Ji=ar.find(Cn=>Cn.id===Se||Cn.id===`gguf:${Yi}`||Cn.id.endsWith(`:${Yi}`)||Cn.name===Yi);N((Ji==null?void 0:Ji.id)||Se)}}}).catch(()=>{}),H.get("/integrations/installed").then(Ve=>{R(Array.isArray(Ve)?Ve:[])}).catch(()=>{}),H.get("/repos/imported").then(Ve=>{Z((Array.isArray(Ve)?Ve:[]).filter(Ke=>Ke.status==="active"))}).catch(()=>{}),H.get("/personalities").then(Ve=>{ce(Array.isArray(Ve)?Ve:Ve.personalities||[])}).catch(()=>{}),h(""),g(""),y(""),S(ne),N(Se),rs(!1),qo("subscription"),nr("new"),bs(""),Bn(Se?Se.split(":").pop().replace(/[-_]/g," "):""),C(""),I([]),E("manual"),D([]),je(""),Te(""),re(!1),Fe([]),Be(null)}},[u,r]),p.useEffect(()=>{if(!Ae||!u){Fe([]);return}H.get(`/roles/integrations?role=${encodeURIComponent(Ae)}`).then(ne=>{const Se=Array.isArray(ne)?ne:(ne==null?void 0:ne.recommendations)||[];Fe(Se);const Ve=Se.filter(Ke=>Ke.installed&&Ke.configured&&Ke.authenticated).map(Ke=>Ke.id);Ve.length>0&&I(Ke=>[...new Set([...Ke,...Ve])])}).catch(()=>Fe([]))},[Ae,u]),p.useEffect(()=>{u&&H.get("/credentials").then(ne=>sr(Array.isArray(ne)&&ne.some(Se=>Se.provider==="claude-code"))).catch(()=>sr(!1))},[u]),p.useEffect(()=>{if(!u||v!=="ollama"){St([]);return}H.get("/providers/ollama/models").then(ne=>{St(ne.installed||[])}).catch(()=>St([])),H.post("/providers/ollama/check").then(ne=>{er(ne.serverRunning)}).catch(()=>er(!1))},[u,v]);async function Yo(){ve(!0);try{let ne;if(vs)ne=vs;else if(!an)ne=c;else if(Ps==="new"){const Ve=Oa.trim()||Ae||"New Team";ne=(await A(Ve)).id}else Ps==="existing"&&nn&&(ne=nn);const Se={role:Ae,...b&&{name:b.replace(/\s+/g,"-")},...v&&{provider:v},...j&&{model:j},...B&&{prompt:B},...M.length>0&&{integrations:M},...M.length>0&&{integrationApproval:z},...$.length>0&&{repos:$},...es&&{fast:!0},...v==="claude-code"&&{authMode:tr},...le&&{personality:le},...Ae==="ambassador"&&Ce&&{peerId:Ce},...ne&&{teamId:ne}};await n(Se),s()}catch{}ve(!1)}async function Jo(){var ne;if(Ae){if(v==="claude-code"&&tr==="usage"&&!Wo){a.error("Add an Anthropic API key in Settings → Providers to spawn with usage credits.");return}try{const Se=await H.post("/agents/preflight",{role:Ae,integrations:M});if(((ne=Se==null?void 0:Se.issues)==null?void 0:ne.length)>0){Be(Se.issues);return}}catch{}Yo()}}return e.jsxs(V0,{open:u,onOpenChange:ne=>{ne||s()},children:[e.jsx(K0,{title:"Spawn Agent",width:480,onClose:()=>s(),children:e.jsxs("div",{className:"flex flex-col h-[calc(100%-57px)]",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-3",children:"Choose Role"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Oie.map(ne=>{const Se=Sc(ne.id),Ve=x===ne.id;return e.jsxs("button",{onClick:()=>{h(ne.id),g("")},className:X("flex items-center gap-2.5 p-3 rounded-md border text-left transition-all cursor-pointer",Ve?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-2"),children:[e.jsx("div",{className:"w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0",style:{background:Se.bg},children:e.jsx(ne.icon,{size:16,style:{color:Se.text}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ne.label}),ne.skillHint&&e.jsx("span",{className:"text-2xs font-mono text-warning/70 bg-warning/8 px-1 py-px rounded",children:"skill"})]}),e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:ne.desc})]})]},ne.id)})}),e.jsx("div",{className:"mt-3",children:e.jsx(Jt,{placeholder:"or type a custom role (e.g. chat-agent)...",value:O,onChange:ne=>{g(ne.target.value.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,50)),h("")},className:"text-xs"})})]}),Ae&&Ze.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Recommended Integrations"}),e.jsx("div",{className:"space-y-1.5",children:Ze.map(ne=>{const Se=Ci[ne.id];return ne.installed&&ne.configured&&ne.authenticated?e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-success/5 border border-success/20",children:[e.jsx(Ye,{size:13,className:"text-success flex-shrink-0"}),Se?e.jsx("img",{src:Se,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(Ls,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ne.name||ne.id}),e.jsx(ke,{variant:"success",className:"text-2xs ml-auto",children:"Ready"})]},ne.id):ne.installed?e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-warning/5 border border-warning/20",children:[e.jsx(Ss,{size:13,className:"text-warning flex-shrink-0"}),Se?e.jsx("img",{src:Se,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(Ls,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ne.name||ne.id}),e.jsx(xe,{variant:"ghost",size:"sm",className:"ml-auto text-2xs text-warning h-6 px-2",onClick:()=>{s(),k.getState().setActiveView("marketplace")},children:"Configure"})]},ne.id):e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-surface-1 border border-border-subtle",children:[Se?e.jsx("img",{src:Se,alt:"",className:"w-3.5 h-3.5 flex-shrink-0 opacity-40"}):e.jsx(Ls,{size:12,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-text-3 font-sans",children:ne.name||ne.id}),e.jsx("button",{onClick:()=>{s(),k.getState().setActiveView("marketplace")},className:"ml-auto text-2xs text-accent hover:underline font-sans cursor-pointer",children:"Install in Integrations"})]},ne.id)})})]}),Ae==="ambassador"&&(()=>{const ne=Wn.whitelist.filter(Se=>typeof Se=="object"&&(Se.status==="mutual"||Se.status==="connected"));return ne.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-4 text-center",children:[e.jsx(Vn,{size:18,className:"text-text-4 mx-auto mb-1.5"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans mb-2",children:"No federated servers connected. Add one in the Federation view."}),e.jsx(xe,{variant:"ghost",size:"sm",className:"text-2xs text-accent",onClick:()=>{s(),k.getState().setActiveView("federation")},children:"Go to Federation"})]}):e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Target Server"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:Ce,onChange:Se=>Te(Se.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Select a server..."}),ne.map(Se=>e.jsx("option",{value:Se.ip,children:Se.name||`${Se.ip}:${Se.port||31415}`},Se.ip))]}),e.jsx(rt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})})(),Ae&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block",children:"Configuration"}),e.jsx(Jt,{label:"Name (optional)",value:b,onChange:ne=>y(ne.target.value),placeholder:`${Ae}-1`}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Provider"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:v,onChange:ne=>{S(ne.target.value),N("")},className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Auto"}),P.map(ne=>e.jsxs("option",{value:ne.id,disabled:ne.authType==="api-key"?!(ne.installed&&ne.hasKey):!ne.installed,children:[ne.name,ne.installed?ne.authType==="api-key"&&!ne.hasKey?" (No API key)":"":" (Not installed)"]},ne.id))]}),e.jsx(rt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Model"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:j,onChange:ne=>N(ne.target.value),disabled:!v,className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent disabled:opacity-40",children:[e.jsx("option",{value:"",children:"Auto"}),v==="ollama"&&Re.length>0?e.jsxs(e.Fragment,{children:[e.jsx("optgroup",{label:"Installed Models",children:Re.map(ne=>{const Se=Ot.some(Ve=>Ve.name===ne.id);return e.jsxs("option",{value:ne.id,children:[ne.name||ne.id," (",ne.size,")",Se?" ● Running":""]},ne.id)})}),e.jsx("optgroup",{label:"Catalog",children:Qe.filter(ne=>!Re.some(Se=>Se.id===ne.id)).map(ne=>e.jsxs("option",{value:ne.id,children:[ne.name," (not installed)"]},ne.id))})]}):v==="local"?(()=>{const ne=Qe.filter(Ke=>Ke.source==="runtime"),Se=Qe.filter(Ke=>Ke.source==="gguf"),Ve=Qe.filter(Ke=>Ke.source==="ollama"||!Ke.source);return e.jsxs(e.Fragment,{children:[ne.length>0&&e.jsx("optgroup",{label:"Lab Runtimes",children:ne.map(Ke=>e.jsxs("option",{value:Ke.id,children:[Ke.name,Ke.runtimeType?` (${Ke.runtimeType})`:""]},Ke.id))}),Se.length>0&&e.jsx("optgroup",{label:"GGUF Models",children:Se.map(Ke=>e.jsxs("option",{value:Ke.id,children:[Ke.name,Ke.hasRuntime?"":" (no runtime)"]},Ke.id))}),Ve.length>0&&e.jsx("optgroup",{label:"Ollama",children:Ve.map(Ke=>e.jsx("option",{value:Ke.id,children:Ke.name},Ke.id))})]})})():Qe.map(ne=>e.jsx("option",{value:ne.id,children:ne.name},ne.id))]}),e.jsx(rt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})]}),v&&He&&e.jsx("div",{className:"text-2xs text-text-3 font-sans flex items-center gap-2 flex-wrap",children:He.authType==="local"?e.jsx(ke,{variant:"success",children:"Local"}):He.authType==="subscription"?e.jsx(ke,{variant:"accent",children:"Subscription"}):He.hasKey?e.jsx(ke,{variant:"success",children:"API key set"}):e.jsxs(ke,{variant:"warning",children:["No API key — set with: groove set-key ",v," YOUR_KEY"]})}),v==="claude-code"&&j&&j.includes("opus")&&e.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":es,onClick:()=>rs(!es),className:X("relative w-8 h-[18px] rounded-full transition-colors flex-shrink-0",es?"bg-accent":"bg-surface-5"),children:e.jsx("span",{className:X("absolute top-[2px] left-[2px] w-[14px] h-[14px] rounded-full bg-white transition-transform",es&&"translate-x-[14px]")})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Fast mode"}),e.jsx("span",{className:"text-2xs text-text-3 font-sans ml-1.5",children:"Faster output, same model"})]})]}),v==="claude-code"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Billing"}),e.jsx("div",{className:"flex gap-1 p-0.5 rounded-md bg-surface-3 w-fit",children:[{id:"subscription",label:"Subscription"},{id:"usage",label:"Usage credits"}].map(ne=>e.jsx("button",{type:"button",onClick:()=>qo(ne.id),className:X("px-2.5 py-1 rounded text-2xs font-semibold font-sans transition-colors",tr===ne.id?"bg-accent text-white":"text-text-2 hover:text-text-0"),children:ne.label},ne.id))}),tr==="usage"&&!Wo&&e.jsx("p",{className:"text-2xs text-warning font-sans",children:"No Anthropic API key stored — add one in Settings → Providers before spawning."}),tr==="subscription"&&e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Uses your Claude Code login (Pro/Max)."})]}),v==="ollama"&&j&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap text-2xs font-sans",children:[Ot.some(ne=>ne.name===j)?e.jsxs(ke,{variant:"success",className:"text-2xs gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-success"}),"Ready — running in memory"]}):Re.some(ne=>ne.id===j)?e.jsx(ke,{variant:"subtle",className:"text-2xs",children:"Will auto-start when agent spawns"}):e.jsx(ke,{variant:"warning",className:"text-2xs",children:"Not installed — will pull first"}),!Bs&&e.jsx("span",{className:"text-warning",children:"Server not running — will auto-start"})]}),an&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Team"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("button",{onClick:()=>nr("new"),className:X("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",Ps==="new"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(ot,{size:13,className:Ps==="new"?"text-accent":"text-text-3"}),e.jsx("div",{children:e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"New Team"})})]}),e.jsxs("button",{onClick:()=>nr("existing"),className:X("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",Ps==="existing"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(Sn,{size:13,className:Ps==="existing"?"text-accent":"text-text-3"}),e.jsx("div",{children:e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Existing"})})]})]}),Ps==="new"&&e.jsx(Jt,{value:Oa,onChange:ne=>Bn(ne.target.value),placeholder:"Team name...",className:"text-xs"}),Ps==="existing"&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:nn,onChange:ne=>bs(ne.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Select team..."}),i.filter(ne=>!ne.archived).map(ne=>e.jsx("option",{value:ne.id,children:ne.name},ne.id))]}),e.jsx(rt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integrations"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[M.map(ne=>{const Se=T.find(Ke=>Ke.id===ne),Ve=Ci[ne];return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded bg-accent/12 text-accent border border-accent/25 text-2xs font-sans",children:[Ve?e.jsx("img",{src:Ve,alt:"",className:"w-2.5 h-2.5"}):e.jsx(Ls,{size:9}),(Se==null?void 0:Se.name)||ne,e.jsx("button",{onClick:()=>I(Ke=>Ke.filter(Ea=>Ea!==ne)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:e.jsx(qe,{size:9})})]},ne)}),e.jsxs("button",{onClick:()=>{W(!0),V("")},className:X("inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-2xs font-sans transition-colors cursor-pointer","bg-surface-0 text-text-2 border border-border-subtle hover:border-border hover:text-text-0"),children:[e.jsx(Ls,{size:10}),M.length>0?"Add integration":"Attach integration"]})]})]}),e.jsx(Gt,{open:J,onOpenChange:W,children:e.jsx(Zt,{title:"Select Integration",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ls,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:ee,onChange:ne=>V(ne.target.value),placeholder:"Search integrations...",autoFocus:!0,className:"w-full h-8 pl-8 pr-3 text-xs rounded-md bg-surface-0 border border-border text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsxs("div",{className:"max-h-64 overflow-y-auto space-y-1",children:[T.filter(ne=>{if(!ee)return!0;const Se=ee.toLowerCase();return(ne.name||ne.id).toLowerCase().includes(Se)||(ne.description||"").toLowerCase().includes(Se)}).map(ne=>{const Se=M.includes(ne.id),Ve=ne.configured!==!1,Ke=Ci[ne.id],Ea=Ae&&Array.isArray(ne.roles)&&ne.roles.includes(Ae);return e.jsxs("button",{onClick:()=>{Ve&&I(rn=>Se?rn.filter(ar=>ar!==ne.id):[...rn,ne.id])},disabled:!Ve,className:X("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors",Ve?"cursor-pointer":"opacity-40 cursor-not-allowed",Se?"bg-accent/10 border border-accent/25":Ve?"hover:bg-surface-3 border border-transparent":"border border-transparent"),children:[Ke?e.jsx("img",{src:Ke,alt:"",className:"w-4 h-4 flex-shrink-0"}):e.jsx(Ls,{size:12,className:Se?"text-accent":"text-text-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:ne.name||ne.id}),!Ve&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"(not configured)"}),Ve&&Ea&&e.jsx("span",{className:"text-2xs font-mono text-accent/70 bg-accent/8 px-1 py-px rounded",children:"rec"})]}),ne.description&&e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:ne.description}),!Ve&&e.jsx("div",{className:"text-2xs text-text-4 font-sans",children:"Configure in Integrations"})]}),Se&&e.jsx(mQ,{})]},ne.id)}),T.length===0&&e.jsx("div",{className:"text-center py-6 text-xs text-text-3 font-sans",children:"No integrations installed. Visit the Integrations tab to install some."})]})]})})}),M.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integration Approvals"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("button",{onClick:()=>E("manual"),className:X("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:[e.jsx(Qn,{size:13,className:z==="manual"?"text-accent":"text-text-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Manual"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"You approve each action"})]})]}),e.jsxs("button",{onClick:()=>E("auto"),className:X("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:[e.jsx(dn,{size:13,className:z==="auto"?"text-warning":"text-text-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Auto"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"Agent acts without asking"})]})]})]})]}),q.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Repos"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[$.map(ne=>{const Se=q.find(Ve=>Ve.id===ne);return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded bg-accent/12 text-accent border border-accent/25 text-2xs font-sans",children:[e.jsx(nc,{size:9}),(Se==null?void 0:Se.name)||ne,e.jsx("button",{onClick:()=>D(Ve=>Ve.filter(Ke=>Ke!==ne)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:e.jsx(qe,{size:9})})]},ne)}),e.jsxs("button",{onClick:()=>{L(!0),pe("")},className:X("inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-2xs font-sans transition-colors cursor-pointer","bg-surface-0 text-text-2 border border-border-subtle hover:border-border hover:text-text-0"),children:[e.jsx(nc,{size:10}),$.length>0?"Add repo":"Attach repo"]})]})]}),e.jsx(Gt,{open:Y,onOpenChange:L,children:e.jsx(Zt,{title:"Select Repository",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-3 p-4",children:[q.length>1&&e.jsxs("div",{className:"relative",children:[e.jsx(ls,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:te,onChange:ne=>pe(ne.target.value),placeholder:"Search repos...",autoFocus:!0,className:"w-full h-8 pl-8 pr-3 text-xs rounded-md bg-surface-0 border border-border text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:q.filter(ne=>{if(!te)return!0;const Se=te.toLowerCase();return(ne.name||ne.repo||ne.id).toLowerCase().includes(Se)}).map(ne=>{const Se=$.includes(ne.id);return e.jsxs("button",{onClick:()=>{D(Ve=>Se?Ve.filter(Ke=>Ke!==ne.id):[...Ve,ne.id])},className:X("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors cursor-pointer",Se?"bg-accent/10 border border-accent/25":"hover:bg-surface-3 border border-transparent"),children:[e.jsx(nc,{size:12,className:Se?"text-accent":"text-text-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:ne.name||ne.repo}),e.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:ne.clonedTo})]}),Se&&e.jsx(mQ,{})]},ne.id)})})]})})}),(x==="chat"||_)&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Personality"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:le,onChange:ne=>je(ne.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"None (blank)"}),K.map(ne=>e.jsx("option",{value:ne.name||ne,children:ne.name||ne},ne.name||ne))]}),e.jsx(rt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:"Personality is injected into every prompt for this agent."})]}),x!=="chat"&&!_&&e.jsx("button",{onClick:()=>re(!0),className:"text-2xs text-text-3 hover:text-accent font-sans transition-colors cursor-pointer",children:"+ Advanced options"})]})]}),e.jsxs("div",{className:"border-t border-border-subtle px-5 py-4 bg-surface-1",children:[Xe.length===0&&P.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 px-3 py-2 rounded-md bg-warning/8 border border-warning/20",children:[e.jsx(Ss,{size:13,className:"text-warning flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-sans text-text-2",children:"No AI providers installed. Install Claude Code, Gemini CLI, Codex, or Ollama to spawn agents."})]}),Ae&&Xe.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 text-xs text-text-3 font-sans flex-wrap",children:[e.jsx("span",{children:"Spawning"}),e.jsx(ke,{variant:"accent",children:Ae}),v&&e.jsxs("span",{children:["on ",(He==null?void 0:He.name)||v]}),b&&e.jsxs("span",{children:["as ",b.replace(/\s+/g,"-")]}),Ps==="new"&&e.jsxs("span",{children:["in new team",Oa?` "${Oa}"`:""]}),Ps==="existing"&&nn&&e.jsxs("span",{children:["in ",(($d=i.find(ne=>ne.id===nn))==null?void 0:$d.name)||"team"]})]}),e.jsx(xe,{variant:"primary",size:"lg",onClick:Jo,disabled:!Ae||fe||Xe.length===0||Ps==="existing"&&!nn,className:"w-full",children:fe?"Spawning...":"Spawn Agent"})]})]})}),e.jsx(Gt,{open:!!ie,onOpenChange:ne=>{ne||Be(null)},children:e.jsx(Zt,{title:"Integration Warning",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsx("div",{className:"space-y-2",children:(ie||[]).map((ne,Se)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs text-text-1 font-sans",children:[e.jsx(Ss,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsx("span",{children:ne.name?`${ne.name}: ${ne.problem==="not_installed"?"not installed":ne.problem==="not_configured"?"not configured":"not authenticated"}`:ne.message||String(ne)})]},Se))}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Continue anyway?"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(xe,{variant:"ghost",size:"md",onClick:()=>Be(null),className:"flex-1",children:"Cancel"}),e.jsx(xe,{variant:"warning",size:"md",onClick:()=>{Be(null),Yo()},className:"flex-1",children:"Spawn Anyway"})]})]})})})]})}function vie(){const t=k(O=>O.journalistStatus),s=k(O=>O.fetchJournalist),n=k(O=>O.triggerJournalistCycle),[a,r]=p.useState(!0),[i,c]=p.useState(!1);p.useEffect(()=>{s().then(()=>r(!1));const O=setInterval(s,1e4);return()=>clearInterval(O)},[s]);async function A(){c(!0);try{await n()}catch{}c(!1)}if(a)return e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx(Ln,{className:"h-6 w-32 rounded"}),e.jsx(Ln,{className:"h-20 rounded-md"}),e.jsx(Ln,{className:"h-20 rounded-md"})]});const u=t||{},x=u.lastSynthesis,h=u.history||[];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"pl-5 pr-10 py-4 border-b border-border-subtle flex items-center gap-2",children:[e.jsx(px,{size:16,className:"text-accent"}),e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Journalist"}),e.jsxs(xe,{variant:"secondary",size:"sm",onClick:A,disabled:i,className:"gap-1.5 text-2xs",children:[e.jsx(sn,{size:11,className:i?"animate-spin":""}),i?"Running...":"Run Synthesis"]})]}),e.jsx(Qt,{className:"flex-1",children:e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Mo,{size:10}),e.jsxs("span",{children:[u.cycleCount||0," cycles"]})]}),u.lastCycleTime&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Zn,{size:10}),e.jsxs("span",{children:["Last: ",cs(u.lastCycleTime)]})]}),e.jsx(ke,{variant:u.cycleCount>0?"success":"default",className:"text-2xs",children:u.cycleCount>0?"Active":"Idle"})]}),(x==null?void 0:x.summary)&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[e.jsx(wn,{size:12,className:"text-text-3"}),"Latest Summary"]}),e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-sans leading-relaxed",children:x.summary})]}),(x==null?void 0:x.projectMap)&&e.jsx(Hx,{title:"Project Map",icon:VM,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-mono leading-relaxed max-h-64 overflow-y-auto whitespace-pre-wrap",children:x.projectMap})}),(x==null?void 0:x.decisions)&&e.jsx(Hx,{title:"Decisions Log",icon:wn,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-mono leading-relaxed max-h-64 overflow-y-auto whitespace-pre-wrap",children:x.decisions})}),h.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[e.jsx(Zn,{size:12,className:"text-text-3"}),"History (",h.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:h.slice().reverse().slice(0,20).map((O,g)=>e.jsxs("div",{className:"bg-surface-0 rounded-md border border-border-subtle px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xs",children:[e.jsxs(ke,{variant:"default",className:"text-2xs",children:["Cycle ",O.cycle]}),e.jsxs("span",{className:"text-text-4 font-sans",children:[O.agentCount," agent",O.agentCount!==1?"s":""]}),e.jsx("span",{className:"text-text-4 font-sans ml-auto",children:cs(O.timestamp)})]}),O.summary&&e.jsx("p",{className:"text-xs text-text-2 font-sans mt-1 leading-relaxed",children:O.summary})]},g))})]}),!x&&h.length===0&&e.jsxs("div",{className:"text-center py-8 text-text-4 font-sans",children:[e.jsx(px,{size:28,className:"mx-auto mb-2"}),e.jsx("p",{className:"text-sm",children:"No synthesis data yet"}),e.jsx("p",{className:"text-2xs mt-1",children:"The journalist runs automatically when agents are active, or trigger manually above"})]})]})})]})}const yie=[{cmd:"save",args:"#tag",desc:"Save the message and send it to the agent"},{cmd:"append",args:"#tag",desc:"Add to an existing memory and send to agent"},{cmd:"update",args:"#tag",desc:"Open the editor to modify a memory in place"},{cmd:"delete",args:"#tag",desc:"Remove a memory permanently"},{cmd:"view",args:"#tag",desc:"Read a memory in the viewer"},{cmd:"read",args:"#tag1 #tag2 ...",desc:"Send memory content to the agent — chat stays clean"},{cmd:"doc",args:"#tag",desc:"AI synthesizes the full conversation into a document"},{cmd:"link",args:"#tag path/to/doc",desc:"Link a memory to a NORTHSTAR or external document"},{cmd:"[instruct]",args:"",desc:"Show this command reference"}];function wie(){var j;const t=k(N=>N.keeperEditing),s=k(N=>N.setKeeperEditing),n=k(N=>N.saveKeeperItem),a=k(N=>N.updateKeeperItem),r=k(N=>N.activeView),[i,c]=p.useState(""),[A,u]=p.useState(""),x=p.useRef(null),h=!!t&&r!=="memory";p.useEffect(()=>{t&&(c(t.tag||""),u(t.content||""))},[t]),p.useEffect(()=>{h&&x.current&&setTimeout(()=>{var N;return(N=x.current)==null?void 0:N.focus()},100)},[h]);const O=N=>{N||s(null)},g=async()=>{!i.trim()||t!=null&&t.readOnly||(t!=null&&t.isNew?await n(i.trim(),A):await a(i.trim(),A),s(null))},b=N=>{N.key==="s"&&(N.metaKey||N.ctrlKey)&&(N.preventDefault(),g())};if(!t)return null;const y=t.readOnly,v=t.isNew,S=y?`#${t.tag}`:v?"New Memory":`Edit #${t.tag}`;return e.jsx(Gt,{open:h,onOpenChange:O,children:e.jsx(Zt,{title:S,description:"Memory content",className:"max-w-2xl",children:e.jsxs("div",{className:"p-5 space-y-4",onKeyDown:b,children:[v&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-text-2 mb-1.5",children:"Tag"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-sm text-text-3",children:"#"}),e.jsx("input",{type:"text",value:i,onChange:N=>c(N.target.value.replace(/[^a-zA-Z0-9/_-]/g,"").toLowerCase()),placeholder:"project/feature-name",className:"flex-1 px-2 py-1.5 text-sm font-mono rounded-md bg-surface-0 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"})]})]}),e.jsx("textarea",{ref:x,value:A,onChange:N=>!y&&u(N.target.value),readOnly:y,rows:16,className:"w-full px-3 py-2 text-sm font-mono leading-relaxed rounded-md bg-surface-0 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent resize-y",placeholder:"Write your thoughts, ideas, context..."}),e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[y?e.jsx("p",{className:"text-2xs text-text-4",children:"Read-only view"}):e.jsxs("p",{className:"text-2xs text-text-4",children:[(j=navigator.platform)!=null&&j.includes("Mac")?"Cmd":"Ctrl","+S to save"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>s(null),children:y?"Close":"Cancel"}),!y&&e.jsxs(xe,{variant:"primary",size:"sm",onClick:g,disabled:!i.trim(),children:[e.jsx(Mr,{size:14})," Save"]})]})]})]})})})}function jie(){const t=k(n=>n.keeperInstructOpen);return k(n=>n.activeView)==="memory"?null:e.jsx(Gt,{open:t,onOpenChange:n=>k.setState({keeperInstructOpen:n}),children:e.jsx(Zt,{title:"Keeper Commands",description:"Memory system command reference",className:"max-w-lg",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx("p",{className:"text-xs text-text-2 leading-relaxed",children:"Type these commands in any agent chat to manage your tagged memories. Commands are intercepted by Keeper — the agent never sees them."}),e.jsx("div",{className:"space-y-1.5",children:yie.map(n=>e.jsxs("div",{className:"flex items-start gap-3 py-1.5 border-b border-border-subtle last:border-0",children:[e.jsxs("div",{className:"flex-shrink-0 flex items-center gap-1",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-accent/15 text-accent font-mono text-xs font-semibold",children:n.cmd}),n.args&&e.jsx("span",{className:"text-xs text-text-3 font-mono",children:n.args})]}),e.jsx("span",{className:"text-xs text-text-3 pt-0.5",children:n.desc})]},n.cmd))}),e.jsxs("div",{className:"pt-2 space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold text-text-1",children:"Tag Hierarchy"}),e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed",children:["Use ",e.jsx("span",{className:"font-mono text-accent",children:"/"})," for nesting: ",e.jsx("span",{className:"font-mono text-accent",children:"#groove/memory-system"}),". Pull a parent to get all children."]}),e.jsx("h3",{className:"text-xs font-semibold text-text-1",children:"Memory Types"}),e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed",children:[e.jsx("span",{className:"font-semibold",children:"Manual"})," — you write via [save]/[append]/[update]. ",e.jsx("span",{className:"font-semibold",children:"Doc"})," — AI writes via [doc]. Both editable."]})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>k.setState({keeperInstructOpen:!1}),children:"Close"})})]})})})}function Nie(){return e.jsxs(e.Fragment,{children:[e.jsx(wie,{}),e.jsx(jie,{})]})}function Qie({onSelect:t,onClose:s}){const n=p.useRef(null),a=k(u=>u.agents),r=k(u=>u.teams);p.useEffect(()=>{function u(h){n.current&&!n.current.contains(h.target)&&s()}function x(h){h.key==="Escape"&&s()}return document.addEventListener("mousedown",u),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",x)}},[s]);const i=a.filter(u=>u.status==="running"||u.status==="starting"),c=a.filter(u=>u.status!=="running"&&u.status!=="starting");function A(u){const x=r.find(h=>h.id===u);return(x==null?void 0:x.name)||"Default"}return e.jsxs("div",{ref:n,className:"absolute bottom-full right-0 mb-1 z-50 min-w-[220px] max-h-[300px] overflow-y-auto py-1 bg-surface-2 border border-border rounded-lg shadow-xl",children:[i.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-1 text-2xs text-text-4 font-sans font-medium uppercase tracking-wider",children:"Active"}),i.map(u=>e.jsxs("button",{onClick:()=>t(u.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-5 cursor-pointer transition-colors text-left",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-success flex-shrink-0"}),e.jsx("span",{className:"truncate flex-1",children:u.name}),e.jsx("span",{className:"text-2xs text-text-4",children:A(u.teamId)})]},u.id))]}),c.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-1 text-2xs text-text-4 font-sans font-medium uppercase tracking-wider",children:i.length>0?"Other":"Agents"}),c.slice(0,10).map(u=>e.jsxs("button",{onClick:()=>t(u.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs font-sans text-text-2 hover:bg-surface-5 cursor-pointer transition-colors text-left",children:[e.jsx("span",{className:X("w-1.5 h-1.5 rounded-full flex-shrink-0",u.status==="completed"?"bg-accent":u.status==="crashed"?"bg-danger":"bg-text-4")}),e.jsx("span",{className:"truncate flex-1",children:u.name}),e.jsx("span",{className:"text-2xs text-text-4",children:A(u.teamId)})]},u.id))]}),a.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-text-4 font-sans text-center",children:"No agents available"})]})}function Sie({children:t,height:s,onHeightChange:n,visible:a,fullHeight:r,tabs:i,activeTab:c,onSelectTab:A,onAddTab:u,onCloseTab:x,onToggleFullHeight:h,onMinimize:O,onClose:g,onRenameTab:b,selectedText:y}){const v=p.useRef(!1),[S,j]=p.useState(null),[N,B]=p.useState(""),[C,P]=p.useState(!1),U=p.useRef(0),T=p.useRef(0),R=k($=>$.detailPanel),M=k($=>$.workspaceAgentId),I=(R==null?void 0:R.type)==="agent"?R.agentId:M||null,J=k($=>$.agents),W=k($=>$.attachSnippet),ee=J.find($=>$.id===I),V=y&&y.trim().length>0,z=p.useCallback($=>{if(r)return;$.preventDefault(),v.current=!0,U.current=$.clientY,T.current=s;function D(L){if(!v.current)return;const te=U.current-L.clientY,pe=Math.min(Math.max(T.current+te,120),600);n(pe)}function Y(){v.current=!1,document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",Y)}document.addEventListener("mousemove",D),document.addEventListener("mouseup",Y)},[s,n,r]);function E($){!$||!(y!=null&&y.trim())||(P(!1),W({type:"terminal",code:y.trim()}),k.getState().selectAgent($))}function q(){I?E(I):P(!0)}const Z=i||[{id:"default",label:"Terminal"}];return e.jsxs("div",{className:X("flex flex-col border-t border-border bg-surface-0 relative",!a&&"hidden"),style:a?r?{flex:1,minHeight:0}:{height:s,flexShrink:0}:{height:0},children:[!r&&e.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 cursor-row-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:z}),e.jsxs("div",{className:"flex items-center h-9 bg-surface-1 border-b border-border flex-shrink-0 pl-0 pr-3",children:[e.jsxs("div",{className:"flex items-center gap-0 flex-1 min-w-0 overflow-x-auto scrollbar-none h-full",children:[Z.map($=>e.jsxs("button",{onClick:()=>A==null?void 0:A($.id),onDoubleClick:()=>{j($.id),B($.label)},className:X("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",$.id===c?"text-text-0 bg-surface-3":"text-text-2 hover:text-text-0 hover:bg-surface-5/50"),children:[e.jsx(Za,{size:11}),S===$.id?e.jsx("input",{className:"bg-transparent border border-border rounded px-1 text-[11px] text-text-0 outline-none w-20 font-sans",value:N,onChange:D=>B(D.target.value),onBlur:()=>{N.trim()&&(b==null||b($.id,N.trim())),j(null)},onKeyDown:D=>{D.key==="Enter"&&(N.trim()&&(b==null||b($.id,N.trim())),j(null)),D.key==="Escape"&&j(null)},autoFocus:!0,onClick:D=>D.stopPropagation()}):e.jsx("span",{className:"truncate max-w-[100px]",children:$.label}),Z.length>1&&e.jsx("button",{onClick:D=>{D.stopPropagation(),x==null||x($.id)},className:"ml-1 p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:9})})]},$.id)),e.jsx("button",{onClick:u,className:"flex items-center justify-center w-6 h-6 text-text-3 hover:text-text-0 hover:bg-surface-5/50 rounded cursor-pointer transition-colors flex-shrink-0 ml-1",title:"New terminal",children:e.jsx(ot,{size:11})})]}),e.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0 ml-2",children:[V&&e.jsxs("div",{className:"relative flex items-center",children:[e.jsx(ut,{content:I?`Send to ${(ee==null?void 0:ee.name)||"agent"}`:"Send to agent",side:"top",children:e.jsx("button",{onClick:q,className:X("flex items-center gap-1.5 px-2 py-1 rounded text-xs font-sans cursor-pointer transition-colors mr-1","bg-accent/15 text-accent hover:bg-accent/25 disabled:opacity-50"),children:I?e.jsxs(e.Fragment,{children:[e.jsx(Kn,{size:11}),e.jsx("span",{className:"text-2xs max-w-[80px] truncate",children:(ee==null?void 0:ee.name)||"Agent"})]}):e.jsxs(e.Fragment,{children:[e.jsx(dn,{size:11}),e.jsx("span",{className:"text-2xs",children:"Agent"}),e.jsx(rt,{size:9})]})})}),!I&&V&&e.jsx(ut,{content:"Pick agent",side:"top",children:e.jsx("button",{onClick:()=>P(!C),className:"p-1 rounded text-text-3 hover:text-accent hover:bg-accent/10 cursor-pointer transition-colors mr-1",children:e.jsx(rt,{size:10})})}),C&&e.jsx(Qie,{onSelect:$=>E($),onClose:()=>P(!1)})]}),r?e.jsx("button",{onClick:O,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Restore",children:e.jsx(rI,{size:12})}):e.jsx("button",{onClick:h,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Maximize",children:e.jsx(DS,{size:12})}),e.jsx("button",{onClick:g,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Close terminal",children:e.jsx(qe,{size:12})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 pl-2 pt-1",children:t})]})}const Bie={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 cO=0,Cie=0;function kie({tabId:t,visible:s,registerKill:n,onSelectionChange:a}){const r=p.useRef(null),i=p.useRef(null),c=p.useRef(null),A=p.useRef(null),u=p.useRef(null),x=p.useRef(!1),h=p.useRef(s),O=p.useRef({cols:0,rows:0}),g=p.useRef(!1);p.useEffect(()=>{n==null||n(t,()=>{const y=k.getState().ws;(y==null?void 0:y.readyState)===WebSocket.OPEN&&A.current&&y.send(JSON.stringify({type:"terminal:kill",id:A.current}))})},[t,n]);const b=k(y=>y.terminalPendingCommand);return p.useEffect(()=>{if(!b||!s)return;let y=0,v=null;const S=()=>{const j=k.getState().ws;if((j==null?void 0:j.readyState)===WebSocket.OPEN&&A.current&&g.current){j.send(JSON.stringify({type:"terminal:input",id:A.current,data:b.command+"\r"})),k.getState().clearTerminalPendingCommand();return}y++<40&&(v=setTimeout(S,150))};return S(),()=>clearTimeout(v)},[b,s]),p.useEffect(()=>{if(!r.current||x.current)return;x.current=!0;const y=new lE({theme:Bie,fontFamily:"'SF Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace",fontSize:12,lineHeight:1.1,letterSpacing:0,cursorBlink:!0,cursorStyle:"bar",cursorWidth:1,scrollback:1e4,allowProposedApi:!0,minimumContrastRatio:1,drawBoldTextInBrightColors:!0,fontWeight:"400",fontWeightBold:"600",overviewRulerWidth:0}),v=new cE;y.loadAddon(v),y.loadAddon(new AE),y.open(r.current),i.current=y,c.current=v,y.onSelectionChange(()=>{const R=y.getSelection();a==null||a(R||"")});let S=0,j=!1;function N(){S++;const R=k.getState().ws;if(!R||R.readyState!==WebSocket.OPEN){S<20&&setTimeout(N,500);return}const M=`spawn-${++Cie}`;R.send(JSON.stringify({type:"terminal:spawn",cols:y.cols,rows:y.rows,requestId:M}));function I(W){let ee;try{ee=JSON.parse(W.data)}catch{return}ee.type==="terminal:spawned"&&ee.requestId===M&&!A.current?(A.current=ee.id,setTimeout(()=>{try{v.fit()}catch{}const V=y.cols,z=y.rows;if(V>1&&z>1&&A.current){const q=k.getState().ws;(q==null?void 0:q.readyState)===WebSocket.OPEN&&(q.send(JSON.stringify({type:"terminal:resize",id:A.current,rows:z,cols:V})),O.current={cols:V,rows:z})}y.reset(),j=!0,g.current=!0;const E=k.getState().ws;(E==null?void 0:E.readyState)===WebSocket.OPEN&&A.current&&E.send(JSON.stringify({type:"terminal:input",id:A.current,data:"\f"}))},300)):ee.type==="terminal:output"&&ee.id===A.current?j&&y.write(ee.data):ee.type==="terminal:exit"&&ee.id===A.current&&(j=!0,g.current=!1,y.write(`\r
|
|
1087
|
+
`),children:[e.jsx(Ss,{size:11})," ",n.length," contract ",n.length===1?"anomaly":"anomalies"]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[e.jsx(Noe,{endpoint:t,remote:s}),e.jsx("span",{"aria-hidden":!0,className:"h-4 w-px bg-border"}),a&&e.jsxs("button",{onClick:a,className:X("flex items-center gap-1.5 h-7 px-2 rounded-md text-2xs font-medium transition-colors cursor-pointer",t.status==="error"?"text-danger hover:bg-danger/10":"text-text-4 hover:text-text-1 hover:bg-surface-2"),title:"Change endpoint or set up a runtime",children:[e.jsx(e0,{size:12}),t.status==="error"?"Fix connection":"Setup"]})]})]})}function Soe({endpoint:t}){const s=k(a=>a.axomSelected),n=k(a=>a.selectAxomSession);return t.sessions.length===0?null:e.jsxs("div",{className:"flex-shrink-0 h-8 border-b border-border-subtle bg-surface-1 px-2 flex items-center gap-1 overflow-x-auto",children:[t.sessions.map(a=>{const r=(s==null?void 0:s.session)===a.session;return e.jsxs("button",{onClick:()=>n(t.name,a.session),className:X("flex items-center gap-1.5 h-6 px-2 rounded font-mono text-2xs whitespace-nowrap transition-colors cursor-pointer",r?"bg-surface-3 text-text-0":"text-text-4 hover:text-text-2 hover:bg-surface-2"),title:a.overflow>0?`${a.overflow} events evicted from the buffer`:void 0,children:[e.jsx(ht,{status:a.live?"running":"completed",size:"sm"}),a.session,a.overflow>0&&e.jsxs("span",{className:"text-warning",children:["−",a.overflow]})]},a.session)}),e.jsx("button",{onClick:()=>n(t.name,`s-${Math.random().toString(36).slice(2,10)}`),className:"h-6 w-6 flex items-center justify-center rounded text-text-4 hover:text-text-1 hover:bg-surface-2 transition-colors cursor-pointer flex-shrink-0",title:"New session — created on your first message",children:e.jsx(ot,{size:12})})]})}function Boe(){const t=k(r=>r.axomInstances),s=k(r=>r.startAxomInstance),n=k(r=>r.stopAxomInstance),a=k(r=>r.addToast);return t.length===0?null:e.jsxs("div",{className:"flex-shrink-0 border-t border-border-subtle px-3 py-2 flex flex-col gap-1",children:[e.jsx("div",{className:"text-2xs uppercase tracking-[0.12em] text-text-4 font-semibold",children:"Local instances"}),t.map(r=>e.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-3",children:[e.jsx(ht,{status:r.status==="running"?"running":r.status==="error"?"crashed":"completed",size:"sm"}),e.jsxs("span",{className:"font-mono truncate",title:r.error||r.dataDir,children:[r.id,":",r.port]}),e.jsx("button",{onClick:()=>(r.status==="running"?n(r.id):s(r.id)).catch(i=>a("error","Instance action failed",i.message)),className:"ml-auto text-text-4 hover:text-text-1 cursor-pointer transition-colors",title:r.status==="running"?"Stop instance":"Start instance",children:r.status==="running"?e.jsx(Qd,{size:11}):e.jsx(jn,{size:11})})]},r.id))]})}function Ur(t){if(t==null)return"";if(typeof t=="string")return t;const s=t.text||t.thought||t.content;if(typeof s=="string")return s;try{return JSON.stringify(t)}catch{return String(t)}}function Coe(t){const s=t==null?void 0:t.cites;return Array.isArray(s)?s.filter(n=>typeof n=="string"):[]}function Xx(t){return typeof(t==null?void 0:t.to)=="string"?t.to:null}function koe(t){for(const s of["text","prompt","message","query","input"])if(typeof(t==null?void 0:t[s])=="string"&&t[s].trim())return t[s];return null}function pb(t,s){const n=(t==null?void 0:t.tool)||(t==null?void 0:t.name)||(t==null?void 0:t.tool_name);let a=(t==null?void 0:t.arg)??(t==null?void 0:t.args)??(t==null?void 0:t.input)??(t==null?void 0:t.query);return a&&typeof a=="object"&&(a=Object.values(a).find(i=>typeof i=="string"&&i.length<120)),typeof n!="string"||!n.trim()?null:[`${s==="tool_end"?"finished":"running"} ${n.trim()}`,typeof a=="string"?a:null].filter(Boolean).join(" · ")}const qs=t=>typeof t=="string"&&t.trim()?t.trim():null,bo=(...t)=>t.filter(Boolean).join(" · "),Zl=t=>typeof t=="string"?qs(t):qs(t==null?void 0:t.text)||qs(t==null?void 0:t.thought)||qs(t==null?void 0:t.content),Toe={pipeline_start:{icon:jn,text:t=>bo("turn started",qs(t.mode))},firing_start:{icon:jt,text:t=>bo("firing",qs(t.leaf_id),qs(t.agent_type))},step_start:{icon:Nt,text:(t,s)=>{const n=t.step??s.step;return n==null?"step":`step ${n}`}},leaf_swap:{icon:rm,text:t=>Xx(t)?`wearing ${Xx(t)}`:"leaf swap · leaf not named"},thought:{icon:kS,text:t=>Zl(t)},tool_start:{icon:Ri,text:t=>qs(pb(t,"tool_start"))},tool_end:{icon:Ri,text:t=>qs(pb(t,"tool_end"))},narration:{icon:HS,text:t=>Zl(t)},text:{icon:w_,text:t=>Zl(t)},resolution:{icon:To,text:t=>Zl(t)},candidate_arrived:{icon:ZA,text:t=>bo("candidate",qs(t.leaf_id),t.banked?"banked":null)},champion_changed:{icon:ZA,text:t=>qs(t.to)?bo(`champion → ${qs(t.to)}`,qs(t.rule)&&`rule ${qs(t.rule)}`):"champion changed · winner not named"},candidate_banked:{icon:ZA,text:()=>"candidate banked"},confidence_updated:{icon:fc,text:t=>bo("confidence",t.candidates!=null&&`${t.candidates} candidates`,t.n_fused!=null&&t.n_agents!=null&&`${t.n_fused}/${t.n_agents} fused`,t.n_facts!=null&&`${t.n_facts} facts`)},evidence_scored:{icon:fc,text:t=>bo("evidence",qs(t.source))},firing_end:{icon:To,text:t=>bo("firing done",t.tokens_generated!=null&&`${t.tokens_generated} tok`)},pipeline_done:{icon:To,text:t=>t.stopped_early===!0?"turn stopped early":"turn complete"},interrupt:{icon:jt,text:t=>Zl(t)?`steer · ${Zl(t)}`:"steer"},interrupt_ack:{icon:jt,text:()=>"steer acknowledged"},stop_requested:{icon:mc,text:()=>"stop requested",tone:"text-danger"},stop_effected:{icon:mc,text:()=>"stopped",tone:"text-danger"}};function Uoe(t){const s=Toe[t.kind],n=s?s.text(t.payload||{},t):null;return n?{icon:s.icon,text:n,tone:s.tone,raw:!1}:{icon:(s==null?void 0:s.icon)||An,text:bo(t.kind,qs(Ur(t.payload)))||t.kind,tone:s==null?void 0:s.tone,raw:!0}}function Eoe({events:t,highlight:s,onHighlight:n,live:a}){const r=p.useRef(null),i=p.useRef(!0),[c,A]=p.useState(!1);p.useEffect(()=>{const h=r.current;h&&i.current&&!s&&(h.scrollTop=h.scrollHeight)},[t.length,s,c]),p.useEffect(()=>{var g;if(!((g=s==null?void 0:s.ids)!=null&&g.length))return;const h=r.current,O=h==null?void 0:h.querySelector(`[data-ev="${s.ids[0]}"]`);O&&h.scrollTo({top:O.offsetTop-h.clientHeight/2+O.offsetHeight/2,behavior:"smooth"})},[s]);function u(){const h=r.current;i.current=h.scrollHeight-h.scrollTop-h.clientHeight<40}const x=new Set((s==null?void 0:s.ids)||[]);return e.jsxs("div",{className:"w-64 xl:w-72 flex-shrink-0 border-r border-border-subtle bg-surface-1 flex flex-col min-h-0",children:[e.jsxs("div",{className:"flex-shrink-0 h-10 px-3 flex items-center gap-2 border-b border-border-subtle",children:[a?e.jsxs("span",{className:"relative flex items-center justify-center w-3 h-3 flex-shrink-0",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-accent/25 animate-ping [animation-duration:2s]"}),e.jsx("span",{className:"relative w-1.5 h-1.5 rounded-full bg-accent"})]}):e.jsx(_o,{size:11,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs uppercase tracking-[0.12em] text-text-4 font-semibold",children:"Activity"}),e.jsx("span",{className:"font-mono text-2xs text-text-4",children:t.length}),e.jsx("button",{onClick:()=>A(h=>!h),className:X("ml-auto h-6 px-1.5 rounded font-mono text-2xs transition-colors cursor-pointer",c?"bg-surface-3 text-text-1":"text-text-4 hover:text-text-1 hover:bg-surface-2"),title:c?"Show readable lines":"Show the raw envelopes",children:"raw"})]}),e.jsxs("div",{ref:r,onScroll:u,className:"flex-1 overflow-y-auto px-2 py-2",children:[t.length===0&&e.jsx("p",{className:"px-1 text-xs text-text-4 leading-relaxed",children:"Nothing yet. Every step the runtime takes shows up here as it happens."}),c?e.jsx("div",{className:"font-mono text-2xs leading-5",children:t.map(h=>e.jsxs("div",{"data-ev":h.id,className:X("flex gap-1.5 items-baseline rounded px-1 transition-colors",x.has(h.id)?"bg-accent/10 ring-1 ring-accent/30":"hover:bg-surface-2"),children:[e.jsx("span",{className:"text-text-4/70 flex-shrink-0",children:h.id.replace(/^ev-0*/,"")}),e.jsx("span",{className:"text-text-2 flex-shrink-0",children:h.kind}),e.jsx("span",{className:"text-text-4 truncate",children:Ur(h.payload)})]},h.id))}):e.jsx("div",{className:"flex flex-col",children:t.map(h=>{const O=Uoe(h),g=O.icon,b=x.has(h.id);return e.jsxs("button",{"data-ev":h.id,onClick:()=>n(b?null:{narrationId:`ev:${h.id}`,ids:[h.id]}),className:X("group flex items-start gap-2 py-1 px-1 rounded text-left transition-colors cursor-pointer",b?"bg-accent/10":"hover:bg-surface-2"),title:`${h.id} · ${h.kind}${O.raw?" — shown verbatim: no summary this build can vouch for":""}`,children:[e.jsx(g,{size:10,className:X("mt-[3px] flex-shrink-0",O.tone||(b?"text-accent":"text-text-4"))}),e.jsx("span",{className:X("text-[11px] leading-snug line-clamp-2 min-w-0 flex-1",O.raw?"font-mono text-text-4":"font-sans",O.tone||(O.raw?"":"text-text-3")),children:O.text})]},h.id)})})]}),e.jsx(Boe,{})]})}const Poe=new Set(["firing_start","firing_end","step_start","step_end"]),Foe=25;function $oe(t){const s=[];let n=null;function a(c){return n||(n={id:c,prompt:null,promptId:null,blocks:[],done:!1,stopped:!1},s.push(n)),n}function r(c){a(c.id).blocks.push(c)}function i(c){const A=n==null?void 0:n.blocks[n.blocks.length-1];return A&&A.type===c?A:null}for(const c of t){const A=c.payload||{};switch(c.kind){case"pipeline_start":n={id:c.id,prompt:koe(A),promptId:c.id,blocks:[],done:!1,stopped:!1},s.push(n);break;case"thought":{const u=Ur(A);if(!u)break;const x=i("thought");x?x.items.push({id:c.id,text:u}):r({type:"thought",id:c.id,items:[{id:c.id,text:u}]});break}case"tool_start":case"tool_end":{const u={id:c.id,text:pb(A,c.kind)||`${c.kind} ${Ur(A)}`.trim(),done:c.kind==="tool_end"},x=i("activity");x?x.items.push(u):r({type:"activity",id:c.id,items:[u]});break}case"narration":{const u=Coe(A);if(!u.length)break;r({type:"narration",id:c.id,text:Ur(A),cites:u});break}case"text":{const u=Ur(A);if(!u)break;const x=i("answer");if(x&&!x.final){const h=/\s$/.test(x.text)||/^\s/.test(u)?"":" ";x.text.endsWith(u)||(x.text+=h+u),x.ids.push(c.id)}else r({type:"answer",id:c.id,text:u,final:!1,ids:[c.id]});break}case"resolution":{const u=Ur(A);if(!u)break;r({type:"answer",id:c.id,text:u,final:!0,ids:[c.id]});break}case"leaf_swap":r({type:"leaf",id:c.id,leaf:Xx(A)??"UNKNOWN"});break;case"interrupt":r({type:"steer",id:c.id,steerId:A.interrupt_id??A.id??null,text:Ur(A),acked:!1});break;case"interrupt_ack":{const u=A.interrupt_id??A.id??null;for(let x=s.length-1;x>=0;x--){const h=s[x].blocks.find(O=>O.type==="steer"&&!O.acked&&(u?O.steerId===u||O.id===u:!0));if(h){h.acked=!0;break}}break}case"stop_requested":r({type:"note",id:c.id,text:"stop requested",state:"stop"});break;case"stop_effected":r({type:"note",id:c.id,text:"stopped",state:"stop"});break;case"pipeline_done":n&&(n.done=!0,n.stopped=A.stopped_early===!0),n=null;break;default:if(Poe.has(c.kind))break;break}}return s}function bT({text:t,status:s}){return e.jsx("div",{className:"flex justify-end pl-8",children:e.jsxs("div",{className:"max-w-[90%]",children:[e.jsx("div",{className:"px-3.5 py-2.5 rounded-lg border border-accent/25 bg-accent/10",children:e.jsx("div",{className:"text-[12px] font-sans whitespace-pre-wrap break-words leading-relaxed text-text-0",children:t})}),s&&e.jsx("div",{className:X("text-[10px] font-mono mt-1 text-right",s.stale?"text-warning":"text-text-4"),children:s.label})]})})}function Roe({block:t}){return e.jsx("div",{className:"flex justify-end pl-8",children:e.jsxs("div",{className:"max-w-[90%]",children:[e.jsx("div",{className:"px-3 py-1.5 rounded-lg border border-border bg-surface-2",children:e.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] font-sans text-text-1 leading-relaxed",children:[e.jsx(jt,{size:11,className:"text-accent flex-shrink-0"}),t.text]})}),e.jsx("div",{className:"text-[10px] font-mono text-text-4 mt-1 text-right",children:t.acked?"acked":"heard"})]})})}function Moe({block:t}){const[s,n]=p.useState(!1),a=s?t.items:t.items.slice(-1);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>n(r=>!r),className:"flex items-center gap-1.5 mb-1 text-2xs text-text-4 hover:text-text-2 font-sans transition-colors cursor-pointer",children:[e.jsx(kS,{size:11}),t.items.length===1?"thought":`${t.items.length} thoughts`,t.items.length>1&&e.jsx(rt,{size:10,className:X("transition-transform",s&&"rotate-180")})]}),e.jsx("div",{className:"pl-3.5 border-l border-border flex flex-col gap-1",children:a.map(r=>e.jsx("p",{className:"text-[11px] font-sans text-text-3 leading-relaxed italic",children:r.text},r.id))})]})}function Ioe({block:t,live:s}){var u;const[n,a]=p.useState(!1),[r,i]=p.useState(0),c=t.items,A=s&&!((u=c[c.length-1])!=null&&u.done);if(p.useEffect(()=>{if(!A||c.length<=1)return;const x=setInterval(()=>i(h=>(h+1)%c.length),1500);return()=>clearInterval(x)},[A,c.length]),A){const x=c[Math.min(r,c.length-1)];return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 w-full rounded-md bg-surface-3/50 border border-border-subtle/30",children:[e.jsx(ze,{size:11,className:"text-accent animate-spin flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-text-2 font-mono truncate min-w-0 flex-1 transition-opacity duration-300",children:x.text}),c.length>1&&e.jsx("span",{className:"text-[10px] text-text-4 font-mono flex-shrink-0",children:c.length})]})}return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>a(x=>!x),className:"inline-flex items-center gap-2 px-3 py-1 text-[10px] text-text-4 hover:text-text-2 font-mono transition-colors cursor-pointer",children:[e.jsx(Ri,{size:10,className:"opacity-50"}),c.length," tool call",c.length!==1?"s":"",e.jsx(rt,{size:10,className:X("transition-transform",n&&"rotate-180")})]}),n&&e.jsx("div",{className:"ml-3.5 pl-3.5 border-l border-border flex flex-col",children:c.map(x=>e.jsxs("div",{className:"flex items-center gap-2 py-0.5 group",children:[e.jsx(Ri,{size:10,className:"text-text-4 opacity-70 flex-shrink-0"}),e.jsx("p",{className:"text-[11px] text-text-3 font-sans truncate flex-1 min-w-0",children:x.text}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:x.id})]},x.id))})]})}function _oe({block:t,eventsById:s,highlight:n,onHighlight:a}){const r=(n==null?void 0:n.narrationId)===t.id;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>a(r?null:{narrationId:t.id,ids:t.cites}),className:X("group w-full flex items-start gap-2 text-left rounded-md px-2 py-1 -mx-2 transition-colors cursor-pointer",r?"bg-surface-2":"hover:bg-surface-2/60"),title:"Show the events behind this line",children:[e.jsx(HS,{size:12,className:X("mt-0.5 flex-shrink-0",r?"text-accent":"text-text-4")}),e.jsx("span",{className:"text-[12px] font-sans text-text-2 leading-relaxed",children:t.text}),e.jsxs("span",{className:X("ml-auto flex-shrink-0 font-mono text-[10px] transition-colors",r?"text-accent":"text-text-4 opacity-0 group-hover:opacity-100"),children:[t.cites.length," cited"]})]}),r&&e.jsx("div",{className:"ml-5 mt-1 rounded-md border border-border-subtle bg-surface-0 px-2 py-1.5 font-mono text-[10px] leading-5",children:t.cites.map(i=>{const c=s[i];return e.jsxs("div",{className:"flex gap-2 items-baseline",children:[e.jsx("span",{className:"text-text-4/70 flex-shrink-0",children:i}),e.jsx("span",{className:X("flex-shrink-0",c?"text-text-2":"text-warning"),children:c?c.kind:"evicted from buffer"}),e.jsx("span",{className:"text-text-4 truncate",children:c?Ur(c.payload):""})]},i)})})]})}function zoe({block:t,endpointName:s}){const[n,a]=p.useState(t.text.length>600),r=t.text.length>600;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-1 font-sans",children:"Axom"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:s}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono ml-auto",children:t.final?"resolution":"text"})]}),e.jsx("div",{className:"pl-3.5 py-1 border-l border-accent",children:e.jsx(Y0,{text:n?`${t.text.slice(0,600)}...`:t.text})}),r&&e.jsxs("button",{onClick:()=>a(i=>!i),className:"ml-3.5 mt-1.5 flex items-center gap-1.5 text-[11px] text-accent/70 hover:text-accent font-sans font-medium cursor-pointer transition-colors",children:[e.jsx(rt,{size:11,className:X(!n&&"rotate-180")}),n?"Show full response":"Collapse"]})]})}function Hf({icon:t,text:s,tone:n}){return e.jsxs("div",{className:"flex items-center gap-3 py-2",children:[e.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),e.jsxs("span",{className:X("flex items-center gap-1.5 text-[10px] font-sans flex-shrink-0 uppercase tracking-wide",n||"text-text-4"),children:[t&&e.jsx(t,{size:10})," ",s]}),e.jsx("div",{className:"flex-1 h-px bg-border-subtle"})]})}function Loe({turn:t,live:s,endpointName:n,eventsById:a,highlight:r,onHighlight:i,prompt:c,ambiguous:A}){const u=!c&&!!t.promptId;return e.jsxs(e.Fragment,{children:[c&&e.jsx(bT,{text:c}),u&&e.jsx(Hf,{text:A?"prompt not identified":"started elsewhere"}),t.blocks.map(x=>{switch(x.type){case"thought":return e.jsx(Moe,{block:x},x.id);case"activity":return e.jsx(Ioe,{block:x,live:s},x.id);case"narration":return e.jsx(_oe,{block:x,eventsById:a,highlight:r,onHighlight:i},x.id);case"answer":return e.jsx(zoe,{block:x,endpointName:n},x.id);case"steer":return e.jsx(Roe,{block:x},x.id);case"leaf":return e.jsx(Hf,{icon:rm,text:`wearing ${x.leaf}`},x.id);case"note":return e.jsx(Hf,{icon:mc,text:x.text,tone:"text-danger"},x.id);default:return null}}),t.stopped&&e.jsx(Hf,{icon:mc,text:"stopped early",tone:"text-danger"})]})}function Doe({events:t,prompts:s,sessionLive:n,endpointName:a,highlight:r,onHighlight:i}){const c=p.useRef(null),A=p.useRef(!0),u=p.useMemo(()=>$oe(t),[t]),x=p.useMemo(()=>Object.fromEntries(t.map(j=>[j.id,j])),[t]);p.useEffect(()=>{const j=c.current;j&&A.current&&(j.scrollTop=j.scrollHeight)},[t.length]);function h(){const j=c.current;A.current=j.scrollHeight-j.scrollTop-j.clientHeight<60}const O=s.filter(j=>!j.attachedTo),[g,b]=p.useState(()=>Date.now()/1e3);p.useEffect(()=>{if(!O.length)return;const j=setInterval(()=>b(Date.now()/1e3),3e3);return()=>clearInterval(j)},[O.length]);const y=u[u.length-1],v=y==null?void 0:y.blocks[y.blocks.length-1],S=n&&y&&!y.done&&(!v||v.type!=="activity"&&v.type!=="answer");return e.jsxs("div",{ref:c,onScroll:h,className:"flex-1 overflow-y-auto px-4 py-4 space-y-4 min-h-0",children:[u.length===0&&O.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center py-8",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-surface-3 flex items-center justify-center mb-3",children:e.jsx(tc,{size:18,className:"text-text-4"})}),e.jsx("p",{className:"text-sm font-semibold text-text-0 font-sans",children:a}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Send a message — every step it takes appears here, and every line cites the events behind it"})]}),u.map((j,N)=>{var B;return e.jsx(Loe,{turn:j,prompt:j.prompt||((B=s.find(C=>C.attachedTo&&C.attachedTo===j.promptId))==null?void 0:B.text)||null,ambiguous:O.length>0,live:n&&N===u.length-1&&!j.done,endpointName:a,eventsById:x,highlight:r,onHighlight:i},j.id)}),O.map(j=>e.jsx(bT,{text:j.text,status:g-j.ts>Foe?{label:"sent · no turn opened for it",stale:!0}:{label:"sent · awaiting turn"}},j.ts)),e.jsx(Ho,{children:S&&e.jsx(Hs.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.25,ease:"easeOut"},children:e.jsx(hT,{agent:{name:"Axom"}})},"thinking")})]})}function Hoe({about:t,events:s}){const n=p.useMemo(()=>s.filter(i=>i.kind==="leaf_swap").map(i=>({id:i.id,leaf:Xx(i.payload)})),[s]),a=(t==null?void 0:t.leaves)||[],r=n.length?n[n.length-1].leaf??"UNKNOWN":"UNKNOWN";return e.jsxs("div",{className:"flex-shrink-0 h-7 border-b border-border-subtle px-4 flex items-center gap-2 overflow-x-auto",children:[e.jsx(rm,{size:11,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"font-mono text-2xs flex-shrink-0",children:e.jsx("span",{className:r==="UNKNOWN"?"text-text-4":"text-text-1",children:r})}),n.length>1&&e.jsxs("span",{className:"font-mono text-2xs text-text-4 whitespace-nowrap",title:"Leaf swap history — each entry is a leaf_swap event",children:["← ",n.slice(-6,-1).reverse().map(i=>i.leaf??"?").join(" ← ")]}),e.jsxs("span",{className:"ml-auto font-mono text-2xs text-text-4 whitespace-nowrap flex-shrink-0",children:["roster ",a.length?a.map(i=>i.name).join(" · "):"—"]})]})}function Xoe(t){let s=null;const n=()=>({watermark:"PROVISIONAL",candidates:[],byFiring:{},champion:null,confidence:null,evidence:[],banked:0});for(const a of t){const r=a.payload||{};if(a.kind==="pipeline_start")s=null;else if(a.kind==="candidate_arrived"){s=s||n();const i={firingId:r.firing_id,leafId:r.leaf_id,text:r.text,banked:!!r.banked,basis:Array.isArray(r.basis)?r.basis:[]};s.candidates.push(i),i.firingId&&(s.byFiring[i.firingId]=i)}else s&&a.kind==="champion_changed"?s.champion={to:r.to,from:r.from??null,rule:r.rule,basis:Array.isArray(r.basis)?r.basis:[]}:s&&a.kind==="confidence_updated"?s.confidence=r:s&&a.kind==="evidence_scored"?s.evidence.push({source:r.source,values:r.values,basis:Array.isArray(r.basis)?r.basis:[]}):s&&a.kind==="candidate_banked"?s.banked+=1:s&&a.kind==="pipeline_done"&&(s.watermark=r.stopped_early===!0?"STOPPED":"SETTLED")}return s}const Goe={PROVISIONAL:"text-warning",SETTLED:"text-text-1",STOPPED:"text-danger"};function lO({basis:t,highlightKey:s,highlight:n,onHighlight:a,className:r,children:i,title:c}){const A=(n==null?void 0:n.narrationId)===s;return e.jsx("button",{title:c,onClick:()=>t.length&&a(A?null:{narrationId:s,ids:t}),className:X("text-left rounded transition-colors",t.length?"cursor-pointer":"cursor-default",A?"bg-surface-3":"hover:bg-surface-2",r),children:i})}function Zoe({answer:t,onStop:s,stopState:n,highlight:a,onHighlight:r}){const[i,c]=p.useState(!1),A=t.champion?t.byFiring[t.champion.to]:null,u=t.confidence,x=t.watermark==="PROVISIONAL";return e.jsxs("div",{className:"flex-shrink-0 border-t border-border-subtle bg-surface-1 px-4",children:[e.jsxs("div",{className:"h-8 flex items-center gap-2.5",children:[e.jsx(ZA,{size:11,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs uppercase tracking-[0.12em] text-text-4 font-semibold flex-shrink-0",children:"Living answer"}),e.jsx("span",{className:X("font-mono text-2xs font-semibold flex-shrink-0",Goe[t.watermark]),children:t.watermark}),e.jsxs("span",{className:"font-mono text-2xs text-text-4 truncate",children:[t.candidates.length," candidate",t.candidates.length===1?"":"s",t.banked>0&&` · ${t.banked} banked`]}),x&&e.jsxs("button",{onClick:s,disabled:n==="pending",className:"flex items-center gap-1.5 h-6 px-2 rounded text-2xs font-medium text-text-3 hover:text-danger hover:bg-danger/10 disabled:opacity-40 disabled:pointer-events-none transition-colors cursor-pointer flex-shrink-0",title:"Settle the tournament on the current champion",children:[e.jsx(mc,{size:11})," Good enough"]}),e.jsx("button",{onClick:()=>c(h=>!h),className:"ml-auto h-6 w-6 flex items-center justify-center rounded text-text-4 hover:text-text-1 hover:bg-surface-2 transition-colors cursor-pointer flex-shrink-0",title:i?"Collapse":"Show champion and confidence",children:e.jsx(rt,{size:12,className:X("transition-transform",i&&"rotate-180")})})]}),i&&e.jsxs("div",{className:"pb-2 flex flex-col gap-1.5 max-h-48 overflow-y-auto",children:[t.champion&&e.jsxs(lO,{basis:t.champion.basis,highlightKey:"champion",highlight:a,onHighlight:r,className:"px-2 py-1.5 border border-border-subtle",title:t.champion.basis.length?"Click to highlight the events behind this champion":void 0,children:[e.jsxs("span",{className:"flex items-center gap-2 mb-0.5 font-mono text-2xs text-text-4",children:[(A==null?void 0:A.leafId)&&e.jsx("span",{className:"text-text-2",children:A.leafId}),t.champion.rule&&e.jsxs("span",{children:["rule ",t.champion.rule]})]}),typeof(A==null?void 0:A.text)=="string"&&e.jsx("span",{className:"block text-[12px] text-text-2 leading-relaxed whitespace-pre-wrap",children:A.text.length>400?`${A.text.slice(0,400)}…`:A.text})]}),u&&e.jsxs(lO,{basis:Array.isArray(u.basis)?u.basis:[],highlightKey:"confidence",highlight:a,onHighlight:r,className:"px-2 py-1 font-mono text-2xs text-text-4",children:[[u.candidates!=null&&`${u.candidates} candidates`,u.n_fused!=null&&u.n_agents!=null&&`${u.n_fused}/${u.n_agents} fused`,u.n_facts!=null&&`${u.n_facts} facts`,u.tools_grounded!=null&&`tools ${String(u.tools_grounded)}`].filter(Boolean).join(" · "),e.jsxs("span",{className:"opacity-60",children:[" · verifier: ",u.verifier==null?"awaiting integration":String(u.verifier)]})]}),t.evidence.length>0&&e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:t.evidence.slice(-3).map((h,O)=>e.jsx(lO,{basis:h.basis,highlightKey:`evidence-${t.evidence.length-3+O}`,highlight:a,onHighlight:r,className:"px-1.5 py-0.5 border border-border-subtle font-mono text-2xs text-text-4",title:h.values?JSON.stringify(h.values):void 0,children:h.source??"evidence"},`${h.source}-${O}`))})]})]})}const Voe={pending:"stop pending…",effected:"stopped","resolved-before-stop":"resolved before stop"};function Koe(t){var s;for(let n=t.length-1;n>=0;n--){if(t[n].kind!=="pipeline_done")continue;const a=(s=t[n].payload)==null?void 0:s.interrupts;if(!a||typeof a!="object")return null;const r=["acked","unanswered","unconsumed"].filter(i=>Array.isArray(a[i]));return r.length===0?null:Object.fromEntries(r.map(i=>[i,a[i].length]))}return null}function qoe({sessionLive:t,rollup:s}){const n=k(C=>C.axomSelected),a=k(C=>C.axomInterrupts),r=k(C=>C.axomStops),i=k(C=>C.sendAxomInterrupt),c=k(C=>C.sendAxomMessage),A=k(C=>C.sendAxomStop),u=k(C=>C.addToast),[x,h]=p.useState(""),[O,g]=p.useState(!1),b=p.useRef(null),y=n?vi(n.endpoint,n.session):null,v=y&&a[y]||{},S=y&&r[y]||null;async function j(){var P;const C=x.trim();if(C){h(""),g(!0);try{if(t)(await i(C)).truncated&&u("warning","Interrupt truncated","The runtime capped it at 2000 chars");else{const U=await c(C);U.busy?(u("warning","Turn already in flight","Not sent — type again to steer the running turn instead"),h(C)):U.tooLong&&(u("error","Message too long",`The runtime's max is ${U.max||32768} chars — nothing was truncated`),h(C))}}catch(U){U.status===503?u("error","This runtime is shutting down","Nothing was sent — that endpoint is going away."):u("error",t?"Interrupt failed":"Message failed",U.message),h(C)}finally{g(!1),(P=b.current)==null||P.focus()}}}async function N(){try{await A()}catch(C){u("error","Stop failed",C.message)}}const B=Object.entries(v).filter(([,C])=>C.state==="sent").slice(-3);return e.jsx("div",{className:"bg-surface-1/50 flex-shrink-0 border-t border-border",children:e.jsxs("div",{className:"px-4 py-3 flex flex-col gap-1.5",children:[(B.length>0||S||s)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap font-mono text-[10px] text-text-4",children:[B.map(([C,P])=>e.jsxs("span",{title:P.text,className:"max-w-56 truncate",children:["sent · ",P.text]},C)),S&&e.jsx("span",{className:X(S==="effected"||S==="pending"?"text-danger":"text-text-3"),children:Voe[S]}),s&&e.jsxs("span",{title:"Interrupt accounting from the last pipeline_done rollup — every interrupt ends in exactly one state",children:["rollup"," ",Object.entries(s).map(([C,P],U)=>e.jsxs("span",{className:C==="unconsumed"&&P>0?"text-warning":void 0,children:[U>0&&" · ",P," ",C]},C))]})]}),e.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-0 transition-colors overflow-hidden focus-within:border-text-4/40",children:[e.jsx("textarea",{ref:b,value:x,onChange:C=>h(C.target.value),onKeyDown:C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),j())},placeholder:t?"Steer Axom mid-flight...":"Message your Axom — starts a turn",rows:2,className:"w-full resize-none field-sizing-content min-h-[72px] max-h-60 px-3 py-2.5 text-[13px] leading-[20px] bg-transparent font-sans text-text-0 placeholder:text-text-4 focus:outline-none"}),e.jsxs("div",{className:"flex items-center gap-1 px-1.5 pb-1.5 pt-0.5",children:[t&&e.jsxs("span",{className:"flex items-center gap-2 pl-1.5 mr-auto",children:[e.jsxs("span",{className:"relative flex items-center justify-center w-3 h-3",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-accent/30 animate-ping [animation-duration:2s]"}),e.jsx("span",{className:"relative w-2 h-2 rounded-full bg-accent"})]}),e.jsx("span",{className:"text-[10px] text-text-4 font-sans",children:"turn in flight"})]}),e.jsx("div",{className:"flex-1"}),t&&e.jsxs("button",{onClick:N,disabled:!n||S==="pending",className:"flex items-center gap-1.5 h-7 px-2 rounded-md text-[11px] font-medium text-text-3 hover:text-danger hover:bg-danger/10 disabled:opacity-40 disabled:pointer-events-none transition-colors cursor-pointer",title:"Stop this turn",children:[e.jsx(mc,{size:13})," Stop"]}),e.jsx("button",{onClick:j,disabled:!n||!x.trim()||O,className:X("w-7 h-7 flex items-center justify-center rounded-md transition-colors cursor-pointer","disabled:opacity-15 disabled:cursor-not-allowed",x.trim()?"text-text-0 hover:text-text-1":"text-text-4"),title:t?"Steer (Enter)":"Send (Enter)",children:O?e.jsx(ze,{size:15,className:"animate-spin"}):t?e.jsx(jt,{size:15}):e.jsx(Jb,{size:15})})]})]})]})})}function Woe(){const t=k(J=>J.axomStatus),s=k(J=>J.axomStatusLoaded),n=k(J=>J.fetchAxomStatus),[a,r]=p.useState(!1),i=k(J=>J.axomSelected),c=k(J=>J.axomEvents),A=k(J=>J.axomPrompts),u=k(J=>J.axomAnomalies),x=k(J=>J.axomStops),h=k(J=>J.axomRemote),O=k(J=>J.selectAxomSession),g=k(J=>J.sendAxomStop),[b,y]=p.useState(null),[v,S]=p.useState(!1),N=((t==null?void 0:t.endpoints)||[])[0],B=h||(t==null?void 0:t.remote)||null;p.useEffect(()=>{if(!N||i)return;const J=N.sessions.find(W=>W.live)||N.sessions[0];J&&O(N.name,J.session)},[N,i,O]);const C=i?vi(i.endpoint,i.session):null,P=p.useMemo(()=>C?c[C]||[]:[],[C,c]),U=p.useMemo(()=>C?A[C]||[]:[],[C,A]);p.useEffect(()=>{s||n()},[s,n]),p.useEffect(()=>{if(s)return;const J=setTimeout(()=>r(!0),3e3);return()=>clearTimeout(J)},[s]),p.useEffect(()=>{y(null)},[C]);const T=p.useMemo(()=>Xoe(P),[P]);if(!s&&!a&&!v)return e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("span",{className:"flex items-center gap-2 text-xs text-text-4",children:[e.jsx(tc,{size:14,className:"animate-pulse text-accent"})," Checking for your Axom…"]})});if(!N||v)return e.jsx(woe,{onBack:N?()=>S(!1):null});const R=i&&N.sessions.find(J=>J.session===i.session);let M=!!(R!=null&&R.live);for(let J=P.length-1;J>=0;J--){if(P[J].kind==="pipeline_done"){M=!1;break}if(P[J].kind==="pipeline_start"){M=!0;break}}const I=N.remoteHost||N.name;return e.jsxs("div",{className:"h-full flex flex-col bg-surface-1",children:[e.jsx(Qoe,{endpoint:N,remote:B,anomalies:C&&u[C]||[],onSetup:()=>S(!0)}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsx(Eoe,{events:P,live:M,highlight:b,onHighlight:y}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[e.jsx(Soe,{endpoint:N}),e.jsx(Hoe,{about:N.about,events:P}),e.jsx(Doe,{events:P,prompts:U,sessionLive:M,endpointName:I,highlight:b,onHighlight:y}),T&&e.jsx(Zoe,{answer:T,onStop:()=>g().catch(()=>{}),stopState:C&&x[C]||null,highlight:b,onHighlight:y}),e.jsx(qoe,{sessionLive:M,rollup:Koe(P)})]})]})]})}const Yoe={code:"Code",general:"General"},Joe={light:"text-success",medium:"text-accent",heavy:"text-warning"};function eie(t){return t<1?`${Math.round(t*1024)} MB`:`${t} GB`}function vT({hardware:t}){if(!t)return null;const{totalRamGb:s,gpu:n,isAppleSilicon:a}=t;return e.jsxs("div",{className:"flex items-center gap-3 bg-surface-0 rounded-lg border border-border-subtle px-3 py-2.5",children:[e.jsx(jd,{size:14,className:"text-text-3 flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs font-sans",children:[e.jsxs("span",{className:"text-text-0 font-semibold",children:[s," GB RAM"]}),n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{className:"text-text-2",children:n.name})]}),a&&e.jsx(ke,{variant:"accent",className:"text-2xs",children:"Unified Memory"})]})})]})}function tie({onRecheck:t}){const[s,n]=p.useState(null),[a,r]=p.useState(!1),[i,c]=p.useState(!1),[A,u]=p.useState(!1),x=k(C=>C.addToast);p.useEffect(()=>{H.post("/providers/ollama/check").then(n).catch(()=>{})},[]);async function h(){r(!0);try{const C=await H.post("/providers/ollama/check");n(C),C.installed&&C.serverRunning?(x("success","Ollama is ready!"),t()):C.installed?x("info","Ollama installed — server needs to start"):x("info","Ollama not found — install and try again")}catch{}r(!1)}async function O(){c(!0);try{if((await H.post("/providers/ollama/serve")).ok){x("success","Ollama server started!");let P=!1;for(let U=0;U<5;U++){await new Promise(R=>setTimeout(R,2e3));const T=await H.post("/providers/ollama/check");if(n(T),T.serverRunning){P=!0;break}}P&&t()}}catch(C){x("error","Could not start server",C.message)}c(!1)}function g(C){navigator.clipboard.writeText(C),u(!0),setTimeout(()=>u(!1),2e3)}if(!s)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{hardware:b,install:y,requirements:v,installed:S,serverRunning:j}=s,N=b.totalRamGb>=v.minRAM,B=b.recommended;return e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsx(vT,{hardware:b}),N?e.jsxs("div",{className:"flex items-start gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2.5",children:[e.jsx(Ye,{size:14,className:"text-success flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans",children:[e.jsx("span",{className:"text-success font-semibold",children:"Your system is ready."}),e.jsx("span",{className:"text-text-2 ml-1",children:B.code?`Recommended: ${B.code}`:`${b.totalRamGb} GB RAM available`})]})]}):e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Gs,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsxs("span",{className:"text-warning font-semibold",children:[b.totalRamGb," GB RAM detected."]})," ","Minimum ",v.minRAM," GB needed. Smallest models may still work."]})]}),S&&!j&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Gs,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama installed but server not running."})," ","The server needs to be running to pull and use models."]})]}),e.jsxs(xe,{variant:"primary",size:"md",onClick:O,disabled:i,className:"w-full gap-1.5",children:[e.jsx(jt,{size:12}),i?"Starting...":"Start Ollama Server"]})]}),!S&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold text-text-1 font-sans",children:"Install Ollama"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 bg-surface-0 border border-border-subtle rounded-md px-3 py-2 text-xs font-mono text-text-1 truncate",children:y.command}),e.jsxs(xe,{variant:"secondary",size:"sm",onClick:()=>g(y.command),className:"h-8 px-2.5 gap-1 flex-shrink-0",children:[A?e.jsx(Ye,{size:12}):e.jsx(Nn,{size:12}),A?"Copied":"Copy"]})]}),y.alt&&e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:y.alt})]}),e.jsxs(xe,{variant:"secondary",size:"md",onClick:h,disabled:a,className:"w-full gap-1.5",children:[e.jsx(sn,{size:12,className:a?"animate-spin":""}),a?"Checking...":S?"Check again":"I installed it — check again"]})]})}function sie({model:t,isInstalled:s,isRecommended:n,canRun:a,onPull:r,onDelete:i,pulling:c}){const A=c===t.id;return e.jsxs("div",{className:X("flex items-center gap-2 px-3 py-2 border-t border-border-subtle transition-colors",!a&&"opacity-40"),children:[s?e.jsx(Ye,{size:12,className:"text-success flex-shrink-0"}):e.jsx("div",{className:"w-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 truncate",children:t.name}),n&&e.jsx(s0,{size:10,className:"text-warning flex-shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:X("text-2xs font-semibold font-sans",Joe[t.tier]),children:t.tier}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:eie(t.sizeGb)}),e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["· ",t.ramGb," GB RAM"]})]})]}),s?e.jsx("button",{onClick:()=>i(t.id),className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Remove model",children:e.jsx(Vt,{size:12})}):a?e.jsx(xe,{variant:"secondary",size:"sm",onClick:()=>r(t.id),disabled:!!c,className:"h-7 px-2 text-2xs gap-1",children:A?e.jsxs(e.Fragment,{children:[e.jsx(sn,{size:10,className:"animate-spin"})," Pulling..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Js,{size:10})," Pull"]})}):e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["Needs ",t.ramGb," GB"]})]})}function nie({onStopped:t}){const[s,n]=p.useState(null),a=k(c=>c.addToast);async function r(){n("stopping");try{(await H.post("/providers/ollama/stop")).ok?(a("info","Ollama server stopped"),t&&t()):a("error","Could not stop server")}catch(c){a("error","Stop failed",c.message)}n(null)}async function i(){n("restarting");try{(await H.post("/providers/ollama/restart")).ok?a("success","Ollama server restarted"):a("error","Restart failed")}catch(c){a("error","Restart failed",c.message)}n(null)}return e.jsxs("div",{className:"flex items-center gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-success"}),e.jsx("span",{className:"absolute inset-[-2px] rounded-full bg-success opacity-20 animate-pulse"})]}),e.jsx("span",{className:"text-xs font-sans text-success font-semibold",children:"Server Running"}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:":11434"}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:i,disabled:!!s,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-accent cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(sn,{size:10,className:s==="restarting"?"animate-spin":""}),s==="restarting"?"Restarting...":"Restart"]}),e.jsxs("button",{onClick:r,disabled:!!s,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-danger cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(Gs,{size:10}),s==="stopping"?"Stopping...":"Stop"]})]})}function aie({onModelChange:t}){var R,M;const[s,n]=p.useState(null),[a,r]=p.useState(null),[i,c]=p.useState("code"),[A,u]=p.useState(!1),[x,h]=p.useState(!1),O=k(I=>I.addToast),g=p.useRef(!1);function b(){H.get("/providers/ollama/models").then(I=>{var J;n(I),!g.current&&((J=I.installed)==null?void 0:J.length)===0&&(g.current=!0,setTimeout(b,2e3))}).catch(()=>{})}p.useEffect(()=>{b()},[]);async function y(I){r(I);try{await H.post("/providers/ollama/pull",{model:I}),O("success",`Pulled ${I}`),b(),t&&t()}catch(J){O("error",`Pull failed: ${J.message}`)}r(null)}async function v(I){try{await H.delete(`/providers/ollama/models/${encodeURIComponent(I)}`),O("info",`Removed ${I}`),b(),t&&t()}catch(J){O("error",`Delete failed: ${J.message}`)}}if(!s)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{installed:S,catalog:j,hardware:N}=s,B=new Set(S.map(I=>I.id)),C=N.totalRamGb,P=[(R=N.recommended)==null?void 0:R.code,(M=N.recommended)==null?void 0:M.general].filter(Boolean),U=j.filter(I=>I.category===i),T=A?U:U.filter(I=>I.ramGb<=C);return x?e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Gs,{size:14,className:"text-warning flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama server stopped."})," ","Start it again to pull and use models."]})]}),e.jsxs(xe,{variant:"primary",size:"md",onClick:async()=>{try{(await H.post("/providers/ollama/serve")).ok&&(O("success","Ollama server started!"),h(!1),g.current=!1,setTimeout(b,2e3))}catch(I){O("error","Could not start server",I.message)}},className:"w-full gap-1.5",children:[e.jsx(jt,{size:12}),"Start Ollama Server"]})]}):e.jsxs("div",{className:"space-y-2 p-3",children:[e.jsx(nie,{onStopped:()=>h(!0)}),e.jsx(vT,{hardware:N}),S.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-sans text-text-2",children:[e.jsx(Zi,{size:12,className:"text-text-3"}),e.jsx("span",{className:"font-semibold",children:S.length})," model",S.length!==1?"s":""," installed"]}),e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:Object.entries(Yoe).map(([I,J])=>e.jsx("button",{onClick:()=>c(I),className:X("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",i===I?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:J},I))}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[T.map(I=>e.jsx(sie,{model:I,isInstalled:B.has(I.id),isRecommended:P.includes(I.id),canRun:I.ramGb<=C,onPull:y,onDelete:v,pulling:a},I.id)),T.length===0&&e.jsxs("div",{className:"px-3 py-4 text-center text-xs text-text-4 font-sans",children:["No ",i," models available for your hardware"]})]}),!A&&U.length>T.length&&e.jsxs("button",{onClick:()=>u(!0),className:"flex items-center gap-1 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(rt,{size:10}),"Show ",U.length-T.length," more (exceed your RAM)"]})]})}function rie({isInstalled:t,onModelChange:s}){const[n,a]=p.useState(!1),[r,i]=p.useState(!1);return p.useEffect(()=>{t?H.post("/providers/ollama/check").then(c=>{a(c.installed&&c.serverRunning),i(!0)}).catch(()=>i(!0)):i(!0)},[t]),r?n?e.jsx(aie,{onModelChange:s}):e.jsx(tie,{onRecheck:()=>{a(!0),s&&s()}}):e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Checking Ollama..."})}function Xf({options:t,value:s,onChange:n}){return e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:t.map(a=>e.jsx("button",{onClick:()=>n(a.value),className:X("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",s===a.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:a.label},a.value))})}function Aa({label:t,icon:s,children:n,description:a}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs font-semibold text-text-1 font-sans",children:[s&&e.jsx(s,{size:13,className:"text-text-3"}),t]}),a&&e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:a})]}),n]})}function oie({agent:t}){const s=k(y=>y.killAgent),n=k(y=>y.rotateAgent),a=k(y=>y.spawnAgent),r=k(y=>y.closeDetail),i=k(y=>y.addToast),[c,A]=p.useState(null),[u,x]=p.useState(!1),h=t.status==="running"||t.status==="starting";async function O(){A("rotate");try{await n(t.id)}catch{}A(null)}async function g(){if(!u){x(!0),setTimeout(()=>x(!1),3e3);return}A("kill");try{await s(t.id,!h),r()}catch{}A(null),x(!1)}async function b(){A("clone");try{await a({role:t.role,provider:t.provider,model:t.model,name:`${t.name}-clone`,scope:t.scope,workingDir:t.workingDir}),i("success",`Cloned ${t.name}`)}catch{}A(null)}return h?e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs(xe,{variant:"primary",size:"md",onClick:O,disabled:c==="rotate",className:"gap-1.5",children:[e.jsx(Nd,{size:12,className:c==="rotate"?"animate-spin":""}),"Rotate"]}),e.jsxs(xe,{variant:"info",size:"md",onClick:b,disabled:!!c,className:"gap-1.5",children:[e.jsx(Nn,{size:12})," Clone"]}),e.jsxs(xe,{variant:"danger",size:"md",onClick:g,disabled:c==="kill",className:"gap-1.5",children:[e.jsx(t0,{size:12}),u?"Confirm":"Kill"]})]})}):e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs(xe,{variant:"info",size:"md",onClick:b,disabled:!!c,className:"gap-1.5",children:[e.jsx(Nn,{size:12})," Clone"]}),e.jsxs(xe,{variant:"danger",size:"md",onClick:g,disabled:c==="kill",className:"gap-1.5",children:[e.jsx(Vt,{size:12}),u?"Confirm":"Remove"]})]})}function iie({agent:t}){var Fe;const s=k(ie=>ie.addToast),n=k(ie=>ie.remoteHomedir),[a,r]=p.useState([]),[i,c]=p.useState(t.model||""),[A,u]=p.useState(""),[x,h]=p.useState(t.effort||"default"),[O,g]=p.useState(!1),[b,y]=p.useState(""),[v,S]=p.useState(null),[j,N]=p.useState(!1),[B,C]=p.useState(null),[P,U]=p.useState(t.routingMode||"auto"),[T,R]=p.useState([]),[M,I]=p.useState(""),[J,W]=p.useState(!1),[ee,V]=p.useState([]),[z,E]=p.useState(!1),[q,Z]=p.useState([]),[$,D]=p.useState(null),[Y,L]=p.useState(t.authMode||"subscription"),[te,pe]=p.useState(!1),K=t.status==="running"||t.status==="starting";p.useEffect(()=>{ce(),H.get("/integrations/installed").then(Be=>Z(Array.isArray(Be)?Be:[])).catch(()=>{}),H.get("/repos/imported").then(Be=>R((Array.isArray(Be)?Be:[]).filter(Re=>Re.status==="active"))).catch(()=>{}),t.provider==="claude-code"&&(H.get("/providers/claude-code/auth").then(Be=>D(Be)).catch(()=>D(null)),H.get("/credentials").then(Be=>pe(Array.isArray(Be)&&Be.some(Re=>Re.provider==="claude-code"))).catch(()=>pe(!1)));function ie(){ce()}return window.addEventListener("groove:providers-changed",ie),()=>window.removeEventListener("groove:providers-changed",ie)},[]);function ce(){H.get("/providers").then(ie=>r(Array.isArray(ie)?ie:[])).catch(()=>{})}p.useEffect(()=>{L(t.authMode||"subscription")},[t.id,t.authMode]),p.useEffect(()=>{c(t.model||""),H.get(`/agents/${t.id}/routing/recommend`).then(ie=>{U((ie==null?void 0:ie.mode)||"fixed")}).catch(()=>{})},[t.id,t.model]),p.useEffect(()=>{W(!1),t.personality?H.get(`/personalities/${t.name}`).then(ie=>{I((ie==null?void 0:ie.content)||""),W(!0)}).catch(()=>{I(""),W(!0)}):(I(""),W(!0)),H.get("/personalities").then(ie=>{V(Array.isArray(ie)?ie:ie.personalities||[])}).catch(()=>{})},[t.id,t.name]);const le=a.find(ie=>ie.id===t.provider);async function je(ie){const Be=Y;L(ie);try{await H.patch(`/agents/${t.id}`,{authMode:ie}),s("success",`Billing → ${ie==="usage"?"usage credits":"subscription"}`)}catch(Re){L(Be),s("error","Failed to change billing mode",Re.message)}}async function _(ie,Be){c(Be);try{const Re={model:Be};ie&&ie!==t.provider&&(Re.provider=ie),await H.patch(`/agents/${t.id}`,Re),s("success",`Model → ${Be}${Re.provider?` (${ie})`:""}`)}catch(Re){s("error","Model swap failed",Re.message)}}async function re(ie){try{await H.patch(`/agents/${t.id}`,{workingDir:ie}),s("success",`Working dir → ${ie.split("/").pop()||ie}`)}catch(Be){s("error","Update failed",Be.message)}}async function fe(ie){h(ie);try{await H.patch(`/agents/${t.id}`,{effort:ie}),s("success",`Effort → ${ie}`)}catch(Be){s("error","Update failed",Be.message)}}async function ve(ie){if(!ie.trim())return;const Be=[...t.scope||[],ie.trim()];try{await H.patch(`/agents/${t.id}`,{scope:Be}),u("")}catch(Re){s("error","Scope update failed",Re.message)}}async function Ce(ie){const Be=(t.scope||[]).filter((Re,St)=>St!==ie);try{await H.patch(`/agents/${t.id}`,{scope:Be})}catch(Re){s("error","Scope update failed",Re.message)}}async function Te(ie){if(b.trim())try{await H.post(`/credentials/${ie}`,{key:b.trim()}),s("success",`API key set for ${ie}`),y(""),S(null),ce(),window.dispatchEvent(new CustomEvent("groove:providers-changed"))}catch(Be){s("error","Failed to set key",Be.message)}}const Ze=t.spawnedAt||t.createdAt;return e.jsxs("div",{className:"px-5 py-5 space-y-6 overflow-y-auto h-full",children:[e.jsx(Aa,{label:"Active Model",icon:ha,children:e.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold font-mono text-text-0",children:t.model||"auto"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:(le==null?void 0:le.name)||t.provider})]}),(le==null?void 0:le.canHotSwap)&&K&&e.jsxs(ke,{variant:"accent",className:"text-2xs gap-1",children:[e.jsx(jt,{size:8})," Hot-swap"]})]}),((Fe=le==null?void 0:le.models)==null?void 0:Fe.length)>1&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3 pt-3 border-t border-border-subtle",children:le.models.filter(ie=>!ie.disabled).map(ie=>{const Be=ie.id===t.model;return e.jsx("button",{onClick:()=>_(t.provider,ie.id),disabled:!1,className:X("px-2.5 py-1 rounded-md text-xs font-mono transition-all","cursor-pointer",Be?"bg-accent/15 text-accent font-semibold":"bg-surface-4 text-text-2 hover:bg-surface-5 hover:text-text-0"),children:ie.name||ie.id},ie.id)})}),t.provider==="claude-code"&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-2xs font-medium text-text-2 font-sans",children:"Billing"}),e.jsx("div",{className:"flex gap-1 p-0.5 rounded-md bg-surface-3",children:[{id:"subscription",label:"Subscription"},{id:"usage",label:"Usage credits"}].map(ie=>e.jsx("button",{onClick:()=>je(ie.id),disabled:ie.id==="usage"&&!te,className:X("px-2 py-1 rounded text-2xs font-semibold font-sans transition-colors",ie.id==="usage"&&!te&&"opacity-40 cursor-not-allowed",Y===ie.id?"bg-accent text-white":"text-text-2 hover:text-text-0"),children:ie.label},ie.id))})]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans mt-1.5",children:te?"Applies on next rotation or restart — the running process keeps its current billing.":"Add an Anthropic API key in Settings → Providers to enable usage credits."})]})]})}),e.jsx(oie,{agent:t}),e.jsxs(Aa,{label:"Providers",icon:xc,description:"Click a provider to see its models and connection status.",children:[e.jsx("div",{className:"space-y-1.5",children:a.map(ie=>{var er;const Be=ie.id===t.provider,Re=ie.authType==="subscription"?ie.installed||((er=ie.authStatus)==null?void 0:er.authenticated):ie.authType==="local"?ie.installed:ie.installed&&ie.hasKey,St=B===ie.id,Bs=ie.models||[];return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[e.jsxs("button",{onClick:()=>C(St?null:ie.id),className:"w-full flex items-center gap-2.5 px-3 py-2 cursor-pointer hover:bg-surface-4/50 transition-colors",children:[e.jsx("div",{className:X("w-2 h-2 rounded-full flex-shrink-0",Re?"bg-success":"bg-text-4")}),e.jsx("span",{className:X("text-xs font-semibold font-sans flex-1 text-left",Re?"text-text-0":"text-text-3"),children:ie.name||ie.id}),Be&&e.jsx(ke,{variant:"accent",className:"text-2xs",children:"Active"}),!Re&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:ie.installed?"No key":"Not installed"}),e.jsx(rt,{size:12,className:X("text-text-4 transition-transform",St&&"rotate-180")})]}),St&&ie.authType==="local"&&e.jsx("div",{className:"border-t border-border-subtle",children:e.jsx(rie,{isInstalled:Re,onModelChange:ce})}),St&&ie.authType!=="local"&&e.jsxs("div",{className:"border-t border-border-subtle",children:[(!Re||ie.hasKey)&&e.jsx("div",{className:"px-3 py-2 bg-surface-1/50",children:v===ie.id?e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("input",{value:b,onChange:es=>y(es.target.value),onKeyDown:es=>es.key==="Enter"&&Te(ie.id),type:j?"text":"password",placeholder:`${ie.name||ie.id} API key...`,className:"w-full h-7 px-2.5 pr-7 text-2xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),e.jsx("button",{onClick:()=>N(!j),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:j?e.jsx(Uo,{size:10}):e.jsx(Ys,{size:10})})]}),e.jsx(xe,{variant:"primary",size:"sm",onClick:()=>Te(ie.id),disabled:!b.trim(),className:"h-7 px-2 text-2xs",children:"Save"}),e.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>{S(null),y("")},className:"h-7 px-2 text-2xs",children:"Cancel"})]}):e.jsxs("button",{onClick:()=>{S(ie.id),y(""),N(!1)},className:"flex items-center gap-1.5 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(Fi,{size:10}),Re?"Update API key":"Add API key to enable"]})}),Re&&Bs.filter(es=>!es.disabled).length>0&&Bs.filter(es=>!es.disabled).map(es=>{const rs=ie.id===t.provider&&es.id===t.model;return e.jsxs("button",{onClick:()=>_(ie.id,es.id),disabled:!1,className:X("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",rs?"text-accent":"text-text-2"),children:[rs?e.jsx(Ye,{size:11,className:"text-accent flex-shrink-0"}):e.jsx("div",{className:"w-[11px]"}),e.jsx("span",{className:"font-mono flex-1 truncate",children:es.name||es.id}),e.jsx(ke,{variant:rs?"accent":"default",className:"text-2xs",children:es.tier})]},es.id)})]})]},ie.id)})}),K&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans mt-1.5",children:[e.jsx(Gs,{size:10}),e.jsx("span",{children:"Model changes apply on next rotation or respawn."})]})]}),t.provider==="claude-code"&&$&&!$.authenticated&&e.jsxs("div",{className:"rounded-lg border border-warning/30 bg-warning/5 px-4 py-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gs,{size:13,className:"text-warning flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Claude Code is not signed in"})]}),e.jsxs("p",{className:"text-2xs text-text-2 font-sans",children:["Open the terminal and run: ",e.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"claude"})]})]}),t.provider==="claude-code"&&($==null?void 0:$.authenticated)&&e.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-success flex-shrink-0"}),"Signed in as ",$.email||"Claude user"," (",$.subscriptionType||"subscription",")"]}),e.jsx(Aa,{label:"Working Directory",icon:tn,description:"The root directory this agent operates in.",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 bg-surface-0 rounded-lg px-3 py-2.5 text-sm font-mono text-text-1 border border-border-subtle truncate min-w-0",children:t.workingDir||"Project root"}),e.jsxs(xe,{variant:"secondary",size:"md",onClick:()=>g(!0),className:"gap-1.5 flex-shrink-0",children:[e.jsx(Gb,{size:14})," Browse"]})]})}),e.jsx(Aa,{label:"Permission Mode",icon:Qn,description:"Full Send = no approvals. Agent Approve = Fullstack Manager reviews risky operations.",children:e.jsx(Xf,{options:[{value:"full",label:"Full Send"},{value:"auto",label:"Agent Approve"}],value:t.permission||"full",onChange:async ie=>{try{await H.patch(`/agents/${t.id}`,{permission:ie}),s("success",`Permission → ${ie==="full"?"Full Send":"Agent Approve"}`)}catch(Be){s("error","Update failed",Be.message)}}})}),e.jsxs(Aa,{label:"Model Routing",icon:Mo,description:"How Groove selects models for this agent's tasks.",children:[e.jsx(Xf,{options:[{value:"fixed",label:"Fixed"},{value:"auto",label:"Auto"},{value:"auto-floor",label:"Auto + Floor"}],value:P,onChange:async ie=>{U(ie);try{await H.post(`/agents/${t.id}/routing`,{mode:ie}),s("success",`Routing → ${ie}`)}catch(Be){s("error","Update failed",Be.message)}}}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans mt-1",children:[P==="fixed"&&"Uses the selected model for all tasks.",P==="auto"&&"Groove picks Opus/Sonnet/Haiku based on task complexity.",P==="auto-floor"&&"Auto-routes but never drops below Sonnet."]})]}),e.jsx(Aa,{label:"File Scope",icon:Qn,description:"Restrict which files this agent can access. Empty = unrestricted.",children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(t.scope||[]).map((ie,Be)=>e.jsxs(ke,{variant:"default",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[ie,e.jsx("button",{onClick:()=>Ce(Be),className:"hover:text-danger cursor-pointer",children:e.jsx(qe,{size:10})})]},Be)),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{value:A,onChange:ie=>u(ie.target.value),onKeyDown:ie=>ie.key==="Enter"&&ve(A),placeholder:"e.g. src/**",className:"w-28 h-7 px-2.5 text-xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsx("button",{onClick:()=>ve(A),disabled:!A.trim(),className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:e.jsx(ot,{size:12})})]})]})}),e.jsx(Aa,{label:"Effort Level",icon:fc,description:"Controls how deep the agent reasons. Higher = more tokens but better results.",children:e.jsx(Xf,{options:[{value:"min",label:"Min"},{value:"low",label:"Low"},{value:"default",label:"Default"},{value:"high",label:"High"},{value:"max",label:"Max"},{value:"ultra",label:"Ultra"}],value:x,onChange:fe})}),e.jsx(Aa,{label:"Agent Details",icon:xc,children:e.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle divide-y divide-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"ID"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.id})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Role"}),e.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:t.role})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Provider"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.provider})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Model"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.model||"auto"})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Status"}),e.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:t.status})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Spawned"}),e.jsx("span",{className:"text-xs text-text-1 font-sans",children:Ze?cs(Ze):"—"})]}),t.sessionId&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Session"}),e.jsxs("span",{className:"text-xs text-text-1 font-mono",children:[t.sessionId.slice(0,16),"..."]})]})]})}),e.jsxs(Aa,{label:"Integrations",icon:Ls,description:"Attach MCP integrations for external services.",children:[e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(t.integrations||[]).map(ie=>{const Be=Ci[ie],Re=q.find(St=>St.id===ie);return e.jsxs(ke,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[Be?e.jsx("img",{src:Be,alt:"",className:"w-2.5 h-2.5"}):e.jsx(Ls,{size:9}),(Re==null?void 0:Re.name)||ie,e.jsx("button",{onClick:async()=>{try{await H.delete(`/agents/${t.id}/integrations/${ie}`),s("success",`Detached ${(Re==null?void 0:Re.name)||ie}`)}catch(St){s("error","Detach failed",St.message)}},className:"hover:text-danger cursor-pointer",children:e.jsx(qe,{size:10})})]},ie)}),q.filter(ie=>ie.configured!==!1&&!(t.integrations||[]).includes(ie.id)).length>0&&e.jsxs("div",{className:"relative group",children:[e.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer transition-colors",children:e.jsx(ot,{size:12})}),e.jsx("div",{className:"absolute top-full left-0 mt-1 z-20 hidden group-hover:block bg-surface-2 border border-border-subtle rounded-lg shadow-xl py-1 min-w-[200px]",children:q.filter(ie=>ie.configured!==!1&&!(t.integrations||[]).includes(ie.id)).map(ie=>{const Be=Ci[ie.id];return e.jsxs("button",{onClick:async()=>{try{await H.post(`/agents/${t.id}/integrations/${ie.id}`),s("success",`Attached ${ie.name||ie.id}`)}catch(Re){s("error","Attach failed",Re.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:[Be?e.jsx("img",{src:Be,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(Ls,{size:12,className:"text-text-3 flex-shrink-0"}),ie.name||ie.id]},ie.id)})})]}),(t.integrations||[]).length===0&&q.length===0&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No integrations installed — browse the Integrations tab"})]}),(t.integrations||[]).length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"text-2xs font-medium text-text-3 font-sans block mb-1.5",children:"Integration Approvals"}),e.jsx(Xf,{options:[{value:"auto",label:"Auto"},{value:"manual",label:"Manual"}],value:t.integrationApproval||"manual",onChange:async ie=>{try{await H.patch(`/agents/${t.id}`,{integrationApproval:ie}),s("success",`Integration approvals → ${ie==="auto"?"Auto":"Manual"}`)}catch(Be){s("error","Update failed",Be.message)}}})]})]}),T.length>0&&e.jsx(Aa,{label:"Repos",icon:nc,description:"Attach imported repos so this agent knows where they are.",children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(t.repos||[]).map(ie=>{const Be=T.find(Re=>Re.id===ie);return e.jsxs(ke,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[(Be==null?void 0:Be.name)||ie,e.jsx("button",{onClick:async()=>{try{await H.delete(`/agents/${t.id}/repos/${ie}`),s("success",`Detached ${(Be==null?void 0:Be.name)||ie}`)}catch(Re){s("error","Detach failed",Re.message)}},className:"hover:text-danger cursor-pointer",children:e.jsx(qe,{size:10})})]},ie)}),T.filter(ie=>!(t.repos||[]).includes(ie.id)).length>0&&e.jsxs("div",{className:"relative group",children:[e.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer transition-colors",children:e.jsx(ot,{size:12})}),e.jsx("div",{className:"absolute top-full left-0 mt-1 z-20 hidden group-hover:block bg-surface-2 border border-border-subtle rounded-lg shadow-xl py-1 min-w-[200px]",children:T.filter(ie=>!(t.repos||[]).includes(ie.id)).map(ie=>e.jsxs("button",{onClick:async()=>{try{await H.post(`/agents/${t.id}/repos/${ie.id}`),s("success",`Attached ${ie.name||ie.id}`)}catch(Be){s("error","Attach failed",Be.message)}},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-4 cursor-pointer transition-colors",children:[e.jsx("div",{className:"font-semibold",children:ie.name||ie.repo}),e.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:ie.clonedTo})]},ie.id))})]}),(t.repos||[]).length===0&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No repos attached — import one from the Integrations tab"})]})}),e.jsxs(Aa,{label:"Personality",icon:Vi,description:"Injected into every prompt. Changes apply on next spawn or rotation.",children:[e.jsx("textarea",{value:M,onChange:ie=>I(ie.target.value),placeholder:J?"Describe this agent's personality, tone, and behavior...":"Loading...",rows:4,className:"w-full min-h-[4rem] max-h-[10rem] resize-y bg-surface-0 border border-border-subtle rounded-md p-2 text-xs font-mono text-text-1 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(xe,{variant:"primary",size:"sm",disabled:z,onClick:async()=>{E(!0);try{await H.put(`/personalities/${t.name}`,{content:M}),s("success","Personality saved")}catch(ie){s("error","Save failed",ie.message)}E(!1)},className:"h-7 px-3 text-2xs gap-1",children:[e.jsx(Mr,{size:10}),z?"Saving...":"Save"]}),ee.length>0&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:"",onChange:ie=>{if(!ie.target.value)return;const Be=ee.find(Re=>(Re.name||Re)===ie.target.value);Be&&H.get(`/personalities/${Be.name||Be}`).then(Re=>{Re!=null&&Re.content&&I(Re.content)}).catch(()=>{})},className:"h-7 px-2 pr-7 text-2xs rounded-md bg-surface-1 border border-border-subtle text-text-2 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Clone from..."}),ee.filter(ie=>(ie.name||ie)!==t.name).map(ie=>e.jsx("option",{value:ie.name||ie,children:ie.name||ie},ie.name||ie))]}),e.jsx(rt,{size:10,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]})]})]}),t.prompt&&e.jsx(Aa,{label:"Original Prompt",icon:Mo,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3 py-3 text-xs text-text-2 font-sans leading-relaxed max-h-40 overflow-y-auto",children:t.prompt})}),e.jsx(Cc,{open:O,onOpenChange:g,currentPath:t.workingDir||n||"/",homePath:n,onSelect:re})]})}const xQ=[];function lie({data:t,isAlive:s,height:n=48}){const a=p.useRef(null);return p.useEffect(()=>{const r=a.current;if(!r||!t.length)return;const i=r.getContext("2d"),c=window.devicePixelRatio||1,A=r.clientWidth,u=r.clientHeight;r.width=A*c,r.height=u*c,i.scale(c,c),i.clearRect(0,0,A,u);const x=t.map(y=>y.v),h=Math.min(...x),g=Math.max(...x,1)-h||1;i.beginPath(),i.moveTo(0,u),t.forEach((y,v)=>{const S=v/(t.length-1)*A,j=u-(y.v-h)/g*(u-4)-2;i.lineTo(S,j)}),i.lineTo(A,u),i.closePath();const b=i.createLinearGradient(0,0,0,u);if(b.addColorStop(0,s?"rgba(51,175,188,0.15)":"rgba(110,118,129,0.08)"),b.addColorStop(1,"rgba(0,0,0,0)"),i.fillStyle=b,i.fill(),i.beginPath(),i.strokeStyle=s?oe.accent:oe.text3,i.lineWidth=1.5,t.forEach((y,v)=>{const S=v/(t.length-1)*A,j=u-(y.v-h)/g*(u-4)-2;v===0?i.moveTo(S,j):i.lineTo(S,j)}),i.stroke(),t.length>1&&s){const y=t[t.length-1],v=A-1,S=u-(y.v-h)/g*(u-4)-2;i.beginPath(),i.arc(v,S,5,0,Math.PI*2),i.fillStyle="rgba(51,175,188,0.3)",i.fill(),i.beginPath(),i.arc(v,S,2.5,0,Math.PI*2),i.fillStyle=oe.accent,i.fill()}},[t,s]),e.jsx("div",{className:"w-full rounded-lg bg-surface-0 overflow-hidden border border-border-subtle",style:{height:n},children:e.jsx("canvas",{ref:a,className:"w-full h-full"})})}function Gf({icon:t,label:s,value:n,color:a,sub:r}){return e.jsxs("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(t,{size:12,className:a||"text-text-3"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans uppercase tracking-wider",children:s})]}),e.jsx("div",{className:X("text-lg font-bold font-mono tabular-nums",a||"text-text-0"),children:n}),r&&e.jsx("div",{className:"text-2xs text-text-4 font-sans mt-0.5",children:r})]})}function cie({score:t}){const s=Math.min(Math.max(t,0),100);let n=oe.success,a="Healthy";return s<40?(n=oe.danger,a="Degraded"):s<70&&(n=oe.warning,a="Fair"),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("span",{className:"text-2xs text-text-3 font-sans flex items-center gap-1.5",children:[e.jsx(QM,{size:11}),"Session Health"]}),e.jsxs("span",{className:"text-xs font-bold font-mono",style:{color:n},children:[s,"/100"]})]}),e.jsx("div",{className:"h-2 bg-surface-0 rounded-full overflow-hidden border border-border-subtle",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700",style:{width:`${s}%`,background:n}})}),e.jsx("span",{className:"text-2xs font-sans mt-1 block",style:{color:n},children:a})]})}function Aie(t){const s=(t||"").toLowerCase();return s.includes("edit")||s.includes("writ")?{icon:rd,color:"text-warning"}:s.includes("read")||s.includes("view")?{icon:Ys,color:"text-info"}:s.includes("search")||s.includes("grep")||s.includes("glob")?{icon:ls,color:"text-purple"}:s.includes("bash")||s.includes("command")||s.includes("terminal")?{icon:Za,color:"text-orange"}:s.includes("error")||s.includes("fail")?{icon:Gs,color:"text-danger"}:s.includes("spawn")||s.includes("start")?{icon:jt,color:"text-success"}:s.includes("complet")||s.includes("done")?{icon:To,color:"text-success"}:{icon:Zn,color:"text-text-4"}}function die({agent:t}){const s=k(c=>c.tokenTimeline[t.id])||xQ,n=k(c=>c.activityLog[t.id])||xQ,a=t.status==="running"||t.status==="starting",r=p.useMemo(()=>{if(s.length<2)return 0;const c=s.slice(-10),A=(c[c.length-1].t-c[0].t)/6e4,u=c[c.length-1].v-c[0].v;return A>0?Math.round(u/A):0},[s]),i=p.useMemo(()=>{const c=t.contextUsage||0;let A=100;return c>90?A-=50:c>70?A-=25:c>50&&(A-=10),r>5e3?A-=15:r>3e3&&(A-=8),t.status==="crashed"&&(A=10),t.status==="completed"&&(A=95),Math.max(0,Math.min(100,A))},[t.contextUsage,t.status,r]);return e.jsxs("div",{className:"px-5 py-5 space-y-5 overflow-y-auto h-full",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Token Burn"}),a&&e.jsx("span",{className:"text-2xs text-accent font-mono animate-pulse",children:"LIVE"})]}),e.jsx(lie,{data:s,isAlive:a,height:56})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(Gf,{icon:rM,label:"Burn Rate",value:r>0?`${Ut(r)}/m`:"—",color:r>5e3?"text-danger":r>2e3?"text-warning":"text-text-0"}),e.jsx(Gf,{icon:FS,label:"Cost",value:qa(t.costUsd||0),color:"text-text-0"}),e.jsx(Gf,{icon:Nd,label:"Rotations",value:t.rotations||"0",color:"text-text-0"}),e.jsx(Gf,{icon:jt,label:"Turns",value:t.turns||"0",color:"text-text-0"})]}),e.jsx(cie,{score:i}),t.prompt&&e.jsxs("div",{children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-1.5",children:"Task"}),e.jsx("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 text-xs text-text-2 font-sans leading-relaxed max-h-28 overflow-y-auto border border-border-subtle",children:t.prompt})]}),n.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-2",children:"Activity"}),e.jsxs("div",{className:"space-y-0 relative",children:[e.jsx("div",{className:"absolute left-[9px] top-2 bottom-2 w-px bg-border-subtle"}),n.slice(-12).reverse().map((c,A)=>{const u=Aie(c.text),x=u.icon;return e.jsxs("div",{className:"flex items-start gap-3 py-1.5 relative",children:[e.jsx("div",{className:X("w-[18px] h-[18px] rounded-full flex items-center justify-center flex-shrink-0 z-10","bg-surface-1 border border-border-subtle"),children:e.jsx(x,{size:9,className:u.color})}),e.jsx("span",{className:"text-2xs text-text-2 font-sans flex-1 line-clamp-1 pt-0.5",children:c.text}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0 pt-0.5",children:cs(c.timestamp)})]},A)})]})]})]})}function uie({agent:t}){const s=k(T=>T.addToast),[n,a]=p.useState([]),[r,i]=p.useState(""),[c,A]=p.useState(null),[u,x]=p.useState(""),[h,O]=p.useState(""),[g,b]=p.useState(!1),[y,v]=p.useState(!1),[S,j]=p.useState("");async function N(){try{const T=await H.get(`/agents/${t.id}/mdfiles`);a(T.files||[]),i(T.workingDir||"")}catch{}}p.useEffect(()=>{N()},[t.id]);async function B(T){try{const R=await H.get(`/agents/${t.id}/mdfiles/read?path=${encodeURIComponent(T)}`);x(R.content||""),O(R.content||""),A(T)}catch(R){s("error","Failed to read file",R.message)}}async function C(){if(c){b(!0);try{await H.put(`/agents/${t.id}/mdfiles/write`,{path:c,content:u}),O(u),s("success",`Saved ${c}`)}catch(T){s("error","Save failed",T.message)}b(!1)}}async function P(){const T=S.trim();if(T)try{await H.post(`/agents/${t.id}/mdfiles/create`,{name:T}),j(""),v(!1),s("success",`Created ${T}.md`),N()}catch(R){s("error","Create failed",R.message)}}const U=u!==h;return c?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border-subtle",children:[e.jsx("button",{onClick:()=>{A(null),x(""),O("")},className:"p-1 text-text-3 hover:text-text-0 cursor-pointer",children:e.jsx(Xi,{size:14})}),e.jsx(wn,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs text-text-0 font-sans font-medium flex-1 truncate",children:c}),U&&e.jsx("span",{className:"text-[10px] text-warning font-sans",children:"unsaved"}),e.jsxs("button",{onClick:C,disabled:!U||g,className:X("flex items-center gap-1 px-2.5 py-1 rounded text-2xs font-sans font-medium cursor-pointer transition-colors",U?"bg-accent/15 text-accent hover:bg-accent/25":"text-text-4 opacity-50 cursor-not-allowed"),children:[e.jsx(Mr,{size:10}),g?"Saving...":"Save"]})]}),e.jsx("textarea",{value:u,onChange:T=>x(T.target.value),className:"flex-1 w-full px-4 py-3 bg-surface-0 text-[12px] font-mono text-text-1 leading-relaxed resize-none focus:outline-none",spellCheck:!1})]}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 border-b border-border-subtle",children:[e.jsx(wn,{size:12,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:"Markdown Files"}),e.jsx("button",{onClick:()=>v(!0),className:"p-1 text-text-4 hover:text-accent cursor-pointer",title:"Create file",children:e.jsx(ot,{size:12})}),e.jsx("button",{onClick:N,className:"p-1 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(sn,{size:11})})]}),r&&e.jsx("div",{className:"px-4 py-1.5 text-[10px] text-text-4 font-mono truncate border-b border-border-subtle/50",children:r}),y&&e.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-b border-border-subtle bg-surface-0",children:[e.jsx(wn,{size:11,className:"text-accent flex-shrink-0"}),e.jsx("input",{autoFocus:!0,value:S,onChange:T=>j(T.target.value),onKeyDown:T=>{T.key==="Enter"&&P(),T.key==="Escape"&&(v(!1),j(""))},placeholder:"filename",className:"flex-1 bg-transparent text-xs text-text-0 font-mono outline-none placeholder:text-text-4"}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:".md"}),e.jsx("button",{onClick:P,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:e.jsx(Mr,{size:11})}),e.jsx("button",{onClick:()=>{v(!1),j("")},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:11})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center px-4",children:[e.jsx(wn,{size:20,className:"text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No markdown files found"}),e.jsx("p",{className:"text-[10px] text-text-4 font-sans mt-1",children:"MD files in the agent's working directory will appear here"})]}):e.jsx("div",{className:"py-1",children:n.map(T=>e.jsxs("button",{onClick:()=>B(T.path),className:"w-full flex items-center gap-2.5 px-4 py-2 text-left hover:bg-surface-5 transition-colors cursor-pointer",children:[e.jsx(wn,{size:13,className:"text-accent flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-xs text-text-0 font-sans block truncate",children:T.name}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:T.path})]}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono flex-shrink-0",children:T.size>1024?`${(T.size/1024).toFixed(1)}K`:`${T.size}B`}),T.source==="personality"&&e.jsx("span",{className:"text-[9px] font-mono text-purple bg-purple/10 px-1 py-px rounded flex-shrink-0",children:"personality"}),T.source==="user"&&e.jsx("span",{className:"text-[9px] font-mono text-accent bg-accent/10 px-1 py-px rounded flex-shrink-0",children:"custom"})]},T.path))})})]})}const fie={running:"bg-accent",starting:"bg-warning",completed:"bg-info",crashed:"bg-danger",stopped:"bg-text-4",killed:"bg-text-4",rotating:"bg-accent"},xie={running:"success",starting:"warning",stopped:"default",crashed:"danger",completed:"accent",killed:"default",rotating:"purple"},mie={running:"Running",starting:"Starting",stopped:"Stopped",crashed:"Crashed",completed:"Done",killed:"Killed",rotating:"Rotating"},hie=[{id:"command",label:"Chat",icon:Ga},{id:"config",label:"Config",icon:hc},{id:"telemetry",label:"Monitor",icon:Mo},{id:"mdfiles",label:"Files",icon:wn}];function pie({agent:t}){const s=k(j=>j.addToast),n=k(j=>j.agents),a=k(j=>j.teams),r=k(j=>j.switchAgentPanel),[i,c]=p.useState(!1),[A,u]=p.useState(t.name),[x,h]=p.useState(!1),[O,g]=p.useState(""),b=p.useRef(null);p.useEffect(()=>{if(!x)return;const j=B=>{b.current&&!b.current.contains(B.target)&&h(!1)},N=B=>{B.key==="Escape"&&h(!1)};return document.addEventListener("mousedown",j),document.addEventListener("keydown",N),()=>{document.removeEventListener("mousedown",j),document.removeEventListener("keydown",N)}},[x]);const y=p.useMemo(()=>{const j=O.trim().toLowerCase(),N=new Map;for(const B of n){if(j&&!B.name.toLowerCase().includes(j)&&!B.role.toLowerCase().includes(j))continue;const C=B.teamId||"_none";N.has(C)||N.set(C,[]),N.get(C).push(B)}return Array.from(N.entries()).map(([B,C])=>{var P;return{teamId:B,name:((P=a.find(U=>U.id===B))==null?void 0:P.name)||"No team",agents:C.sort((U,T)=>U.name.localeCompare(T.name))}}).sort((B,C)=>B.name.localeCompare(C.name))},[n,a,O]);async function v(){const j=A.trim();if(!j||j===t.name){c(!1);return}try{await H.patch(`/agents/${t.id}`,{name:j.replace(/\s+/g,"-")}),s("success",`Renamed → ${j}`)}catch(N){s("error","Rename failed",N.message),u(t.name)}c(!1)}function S(j){h(!1),g(""),j!==t.id&&r(j)}return i?e.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-0",children:[e.jsx("input",{value:A,onChange:j=>u(j.target.value),onKeyDown:j=>{j.key==="Enter"&&v(),j.key==="Escape"&&(u(t.name),c(!1))},className:"flex-1 min-w-0 h-6 px-1.5 text-sm font-bold bg-surface-0 border border-accent/30 rounded text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent/40",autoFocus:!0}),e.jsx("button",{onClick:v,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:e.jsx(Ye,{size:12})}),e.jsx("button",{onClick:()=>{u(t.name),c(!1)},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:12})})]}):e.jsxs("div",{ref:b,className:"relative flex items-center gap-1.5 flex-1 min-w-0 group",children:[e.jsxs("button",{onClick:()=>h(j=>!j),className:"flex items-center gap-1 min-w-0 cursor-pointer rounded px-1 -mx-1 py-0.5 hover:bg-surface-3 transition-colors",title:"Switch agent",children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans truncate",children:t.name}),e.jsx(rt,{size:13,className:X("text-text-4 flex-shrink-0 transition-transform",x&&"rotate-180")})]}),e.jsx("button",{onClick:()=>{u(t.name),c(!0)},className:"p-0.5 text-text-4 opacity-0 group-hover:opacity-100 hover:text-text-1 cursor-pointer transition-opacity flex-shrink-0",title:"Rename agent",children:e.jsx(zr,{size:10})}),x&&e.jsxs("div",{className:"absolute top-full left-0 mt-1.5 w-72 max-h-[70vh] flex flex-col bg-surface-1 border border-border rounded-lg shadow-xl z-50 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-2 border-b border-border-subtle",children:[e.jsx(ls,{size:12,className:"text-text-4 flex-shrink-0"}),e.jsx("input",{value:O,onChange:j=>g(j.target.value),placeholder:"Switch to agent…",autoFocus:!0,className:"flex-1 min-w-0 bg-transparent text-xs text-text-0 font-sans placeholder:text-text-4 focus:outline-none"})]}),e.jsxs("div",{className:"overflow-y-auto py-1",children:[y.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-text-4 font-sans text-center",children:"No agents match"}),y.map(j=>e.jsxs("div",{children:[e.jsx("div",{className:"px-2.5 pt-1.5 pb-0.5 text-2xs font-semibold text-text-4 font-sans uppercase tracking-wide",children:j.name}),j.agents.map(N=>e.jsxs("button",{onClick:()=>S(N.id),className:X("w-full flex items-center gap-2 px-2.5 py-1.5 text-left cursor-pointer transition-colors",N.id===t.id?"bg-accent/10":"hover:bg-surface-3"),children:[e.jsx("span",{className:X("w-1.5 h-1.5 rounded-full flex-shrink-0",fie[N.status]||"bg-text-4")}),e.jsx("span",{className:X("text-xs font-sans truncate",N.id===t.id?"text-accent font-medium":"text-text-1"),children:N.name}),e.jsx("span",{className:"text-2xs text-text-4 font-sans ml-auto flex-shrink-0 capitalize",children:N.role})]},N.id))]},j.teamId))]})]})]})}function gie(){const t=k(y=>y.detailPanel),s=k(y=>y.agents),n=k(y=>y.activeTeamId),a=k(y=>y.activeView);k(y=>y.addToast);const[r,i]=p.useState("command"),c=p.useRef(null),A=(t==null?void 0:t.type)==="agent"?t.agentId:null,u=A?s.find(y=>y.id===A):null;u?c.current=u:c.current&&A&&c.current.id!==A&&(c.current=null);const x=u||c.current,h=(u==null?void 0:u.status)==="running"||(u==null?void 0:u.status)==="starting";if(!x||a!=="fleet"&&n&&x.teamId&&x.teamId!==n)return null;const O=Math.round((x.contextUsage||0)*100),g=x.spawnedAt||x.createdAt,b=g?Math.floor((Date.now()-new Date(g).getTime())/1e3):0;return Sc(x.role),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex-shrink-0",children:[e.jsxs("div",{className:"pl-4 pr-10 pt-3 pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pie,{agent:x}),e.jsx(ke,{variant:xie[x.status]||"default",dot:h?"pulse":void 0,className:"text-2xs flex-shrink-0",children:mie[x.status]||x.status})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-2xs text-text-3 font-mono",children:[e.jsx("span",{className:"capitalize",children:x.role}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{children:[x.provider,":",x.model||"auto"]}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{children:[Ut(x.tokensUsed||0)," tok"]}),O>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{className:X(O>80?"text-danger":O>60?"text-warning":"text-text-3"),children:[O,"% ctx"]})]}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{children:Zo(b)})]})]}),e.jsx("div",{className:"flex items-center px-4 border-b border-border-subtle",children:hie.map(y=>{const v=y.icon,S=r===y.id;return e.jsxs("button",{onClick:()=>i(y.id),className:X("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",S?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"),children:[e.jsx(v,{size:11}),y.label]},y.id)})})]}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[r==="command"&&e.jsx(OT,{agent:x}),r==="config"&&e.jsx(iie,{agent:x}),r==="telemetry"&&e.jsx(die,{agent:x}),r==="mdfiles"&&e.jsx(uie,{agent:x})]})]})}const Oie=[{id:"chat",label:"Chat",desc:"Companion, assistant, conversation",icon:Vi,tier:"Medium"},{id:"planner",label:"Planner",desc:"Plans the team and tasks",icon:$i,tier:"Heavy"},{id:"backend",label:"Backend",desc:"APIs, services, databases",icon:Qs,tier:"Medium"},{id:"frontend",label:"Frontend",desc:"UI, components, styling",icon:jd,tier:"Medium"},{id:"fullstack",label:"Fullstack",desc:"End-to-end implementation",icon:An,tier:"Heavy"},{id:"testing",label:"Testing",desc:"Tests, coverage, QA",icon:Sd,tier:"Medium"},{id:"devops",label:"DevOps",desc:"CI/CD, infra, deployment",icon:zb,tier:"Medium"},{id:"docs",label:"Docs",desc:"Documentation, guides",icon:wn,tier:"Light"},{id:"security",label:"Security",desc:"Audits, vulnerabilities",icon:Qn,tier:"Medium"},{id:"database",label:"Database",desc:"Schema, migrations, queries",icon:Lb,tier:"Medium"},{id:"cmo",label:"CMO",desc:"Marketing, content, growth",icon:Kb,tier:"Medium"},{id:"cfo",label:"CFO",desc:"Finance, metrics, forecasting",icon:TS,tier:"Medium"},{id:"ea",label:"EA",desc:"Executive assistant, scheduling",icon:WS,tier:"Light"},{id:"support",label:"Support",desc:"Customer support, FAQs",icon:IS,tier:"Medium"},{id:"analyst",label:"Analyst",desc:"Data analysis, insights",icon:sm,tier:"Medium"},{id:"creative",label:"Writer",desc:"Copy, articles, proposals",icon:ZS,tier:"Heavy",skillHint:!0},{id:"slides",label:"Slides",desc:"Pitch decks, presentations",icon:VS,tier:"Heavy",skillHint:!0},{id:"ambassador",label:"Ambassador",desc:"Bridge to federated server",icon:Vn,tier:"Light"}];function mQ(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"text-accent flex-shrink-0",children:[e.jsx("circle",{cx:"7",cy:"7",r:"6",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1"}),e.jsx("path",{d:"M4.5 7 L6.5 9 L9.5 5.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}function bie(){var $d;const t=k(ne=>ne.detailPanel),s=k(ne=>ne.closeDetail),n=k(ne=>ne.spawnAgent),a=qn(),r=k(ne=>ne.fetchProviders),i=k(ne=>ne.teams),c=k(ne=>ne.activeTeamId),A=k(ne=>ne.createTeam),u=(t==null?void 0:t.type)==="spawn",[x,h]=p.useState(""),[O,g]=p.useState(""),[b,y]=p.useState(""),[v,S]=p.useState(""),[j,N]=p.useState(""),[B,C]=p.useState(""),[P,U]=p.useState([]),[T,R]=p.useState([]),[M,I]=p.useState([]),[J,W]=p.useState(!1),[ee,V]=p.useState(""),[z,E]=p.useState("manual"),[q,Z]=p.useState([]),[$,D]=p.useState([]),[Y,L]=p.useState(!1),[te,pe]=p.useState(""),[K,ce]=p.useState([]),[le,je]=p.useState(""),[_,re]=p.useState(!1),[fe,ve]=p.useState(!1),[Ce,Te]=p.useState(""),[Ze,Fe]=p.useState([]),[ie,Be]=p.useState(null),[Re,St]=p.useState([]),[Bs,er]=p.useState(!1),[es,rs]=p.useState(!1),[tr,qo]=p.useState("subscription"),[Wo,sr]=p.useState(!1),[Ps,nr]=p.useState("new"),[Oa,Bn]=p.useState(""),[nn,bs]=p.useState(""),Wn=k(ne=>ne.federation),Ot=k(ne=>ne.ollamaRunningModels),Ae=x||O,He=P.find(ne=>ne.id===v),Qe=(He==null?void 0:He.models)||[],Xe=P.filter(ne=>ne.authType==="api-key"?ne.installed&&ne.hasKey:ne.installed),ts=!!(t!=null&&t.presetProvider||t!=null&&t.presetModel),vs=(t==null?void 0:t.presetTeamId)||null,an=!vs&&(ts||!c);p.useEffect(()=>{if(u){const ne=(t==null?void 0:t.presetProvider)||"",Se=(t==null?void 0:t.presetModel)||"";r().then(Ve=>{const Ke=Array.isArray(Ve)?Ve:Ve.providers||[];U(Ke);const Ea=Ke.filter(rn=>rn.authType==="api-key"?rn.installed&&rn.hasKey:rn.installed);if(Ea.length>0&&!ne){const ar=["claude-code","gemini","codex","ollama"].find(Wi=>Ea.some(xn=>xn.id===Wi))||Ea[0].id;S(ar)}if(ne&&S(ne),Se){const rn=Ke.find(xn=>xn.id===(ne||v)),ar=(rn==null?void 0:rn.models)||[];if(ar.find(xn=>xn.id===Se))N(Se);else{const xn=Se.split(":"),Yi=xn.length>=3?xn.slice(2).join(":"):xn[xn.length-1],Ji=ar.find(Cn=>Cn.id===Se||Cn.id===`gguf:${Yi}`||Cn.id.endsWith(`:${Yi}`)||Cn.name===Yi);N((Ji==null?void 0:Ji.id)||Se)}}}).catch(()=>{}),H.get("/integrations/installed").then(Ve=>{R(Array.isArray(Ve)?Ve:[])}).catch(()=>{}),H.get("/repos/imported").then(Ve=>{Z((Array.isArray(Ve)?Ve:[]).filter(Ke=>Ke.status==="active"))}).catch(()=>{}),H.get("/personalities").then(Ve=>{ce(Array.isArray(Ve)?Ve:Ve.personalities||[])}).catch(()=>{}),h(""),g(""),y(""),S(ne),N(Se),rs(!1),qo("subscription"),nr("new"),bs(""),Bn(Se?Se.split(":").pop().replace(/[-_]/g," "):""),C(""),I([]),E("manual"),D([]),je(""),Te(""),re(!1),Fe([]),Be(null)}},[u,r]),p.useEffect(()=>{if(!Ae||!u){Fe([]);return}H.get(`/roles/integrations?role=${encodeURIComponent(Ae)}`).then(ne=>{const Se=Array.isArray(ne)?ne:(ne==null?void 0:ne.recommendations)||[];Fe(Se);const Ve=Se.filter(Ke=>Ke.installed&&Ke.configured&&Ke.authenticated).map(Ke=>Ke.id);Ve.length>0&&I(Ke=>[...new Set([...Ke,...Ve])])}).catch(()=>Fe([]))},[Ae,u]),p.useEffect(()=>{u&&H.get("/credentials").then(ne=>sr(Array.isArray(ne)&&ne.some(Se=>Se.provider==="claude-code"))).catch(()=>sr(!1))},[u]),p.useEffect(()=>{if(!u||v!=="ollama"){St([]);return}H.get("/providers/ollama/models").then(ne=>{St(ne.installed||[])}).catch(()=>St([])),H.post("/providers/ollama/check").then(ne=>{er(ne.serverRunning)}).catch(()=>er(!1))},[u,v]);async function Yo(){ve(!0);try{let ne;if(vs)ne=vs;else if(!an)ne=c;else if(Ps==="new"){const Ve=Oa.trim()||Ae||"New Team";ne=(await A(Ve)).id}else Ps==="existing"&&nn&&(ne=nn);const Se={role:Ae,...b&&{name:b.replace(/\s+/g,"-")},...v&&{provider:v},...j&&{model:j},...B&&{prompt:B},...M.length>0&&{integrations:M},...M.length>0&&{integrationApproval:z},...$.length>0&&{repos:$},...es&&{fast:!0},...v==="claude-code"&&{authMode:tr},...le&&{personality:le},...Ae==="ambassador"&&Ce&&{peerId:Ce},...ne&&{teamId:ne}};await n(Se),s()}catch{}ve(!1)}async function Jo(){var ne;if(Ae){if(v==="claude-code"&&tr==="usage"&&!Wo){a.error("Add an Anthropic API key in Settings → Providers to spawn with usage credits.");return}try{const Se=await H.post("/agents/preflight",{role:Ae,integrations:M});if(((ne=Se==null?void 0:Se.issues)==null?void 0:ne.length)>0){Be(Se.issues);return}}catch{}Yo()}}return e.jsxs(V0,{open:u,onOpenChange:ne=>{ne||s()},children:[e.jsx(K0,{title:"Spawn Agent",width:480,onClose:()=>s(),children:e.jsxs("div",{className:"flex flex-col h-[calc(100%-57px)]",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-3",children:"Choose Role"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Oie.map(ne=>{const Se=Sc(ne.id),Ve=x===ne.id;return e.jsxs("button",{onClick:()=>{h(ne.id),g("")},className:X("flex items-center gap-2.5 p-3 rounded-md border text-left transition-all cursor-pointer",Ve?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-2"),children:[e.jsx("div",{className:"w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0",style:{background:Se.bg},children:e.jsx(ne.icon,{size:16,style:{color:Se.text}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ne.label}),ne.skillHint&&e.jsx("span",{className:"text-2xs font-mono text-warning/70 bg-warning/8 px-1 py-px rounded",children:"skill"})]}),e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:ne.desc})]})]},ne.id)})}),e.jsx("div",{className:"mt-3",children:e.jsx(Jt,{placeholder:"or type a custom role (e.g. chat-agent)...",value:O,onChange:ne=>{g(ne.target.value.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,50)),h("")},className:"text-xs"})})]}),Ae&&Ze.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Recommended Integrations"}),e.jsx("div",{className:"space-y-1.5",children:Ze.map(ne=>{const Se=Ci[ne.id];return ne.installed&&ne.configured&&ne.authenticated?e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-success/5 border border-success/20",children:[e.jsx(Ye,{size:13,className:"text-success flex-shrink-0"}),Se?e.jsx("img",{src:Se,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(Ls,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ne.name||ne.id}),e.jsx(ke,{variant:"success",className:"text-2xs ml-auto",children:"Ready"})]},ne.id):ne.installed?e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-warning/5 border border-warning/20",children:[e.jsx(Ss,{size:13,className:"text-warning flex-shrink-0"}),Se?e.jsx("img",{src:Se,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(Ls,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:ne.name||ne.id}),e.jsx(xe,{variant:"ghost",size:"sm",className:"ml-auto text-2xs text-warning h-6 px-2",onClick:()=>{s(),k.getState().setActiveView("marketplace")},children:"Configure"})]},ne.id):e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-surface-1 border border-border-subtle",children:[Se?e.jsx("img",{src:Se,alt:"",className:"w-3.5 h-3.5 flex-shrink-0 opacity-40"}):e.jsx(Ls,{size:12,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-text-3 font-sans",children:ne.name||ne.id}),e.jsx("button",{onClick:()=>{s(),k.getState().setActiveView("marketplace")},className:"ml-auto text-2xs text-accent hover:underline font-sans cursor-pointer",children:"Install in Integrations"})]},ne.id)})})]}),Ae==="ambassador"&&(()=>{const ne=Wn.whitelist.filter(Se=>typeof Se=="object"&&(Se.status==="mutual"||Se.status==="connected"));return ne.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-4 text-center",children:[e.jsx(Vn,{size:18,className:"text-text-4 mx-auto mb-1.5"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans mb-2",children:"No federated servers connected. Add one in the Federation view."}),e.jsx(xe,{variant:"ghost",size:"sm",className:"text-2xs text-accent",onClick:()=>{s(),k.getState().setActiveView("federation")},children:"Go to Federation"})]}):e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Target Server"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:Ce,onChange:Se=>Te(Se.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Select a server..."}),ne.map(Se=>e.jsx("option",{value:Se.ip,children:Se.name||`${Se.ip}:${Se.port||31415}`},Se.ip))]}),e.jsx(rt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})})(),Ae&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block",children:"Configuration"}),e.jsx(Jt,{label:"Name (optional)",value:b,onChange:ne=>y(ne.target.value),placeholder:`${Ae}-1`}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Provider"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:v,onChange:ne=>{S(ne.target.value),N("")},className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Auto"}),P.map(ne=>e.jsxs("option",{value:ne.id,disabled:ne.authType==="api-key"?!(ne.installed&&ne.hasKey):!ne.installed,children:[ne.name,ne.installed?ne.authType==="api-key"&&!ne.hasKey?" (No API key)":"":" (Not installed)"]},ne.id))]}),e.jsx(rt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Model"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:j,onChange:ne=>N(ne.target.value),disabled:!v,className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent disabled:opacity-40",children:[e.jsx("option",{value:"",children:"Auto"}),v==="ollama"&&Re.length>0?e.jsxs(e.Fragment,{children:[e.jsx("optgroup",{label:"Installed Models",children:Re.map(ne=>{const Se=Ot.some(Ve=>Ve.name===ne.id);return e.jsxs("option",{value:ne.id,children:[ne.name||ne.id," (",ne.size,")",Se?" ● Running":""]},ne.id)})}),e.jsx("optgroup",{label:"Catalog",children:Qe.filter(ne=>!Re.some(Se=>Se.id===ne.id)).map(ne=>e.jsxs("option",{value:ne.id,children:[ne.name," (not installed)"]},ne.id))})]}):v==="local"?(()=>{const ne=Qe.filter(Ke=>Ke.source==="runtime"),Se=Qe.filter(Ke=>Ke.source==="gguf"),Ve=Qe.filter(Ke=>Ke.source==="ollama"||!Ke.source);return e.jsxs(e.Fragment,{children:[ne.length>0&&e.jsx("optgroup",{label:"Lab Runtimes",children:ne.map(Ke=>e.jsxs("option",{value:Ke.id,children:[Ke.name,Ke.runtimeType?` (${Ke.runtimeType})`:""]},Ke.id))}),Se.length>0&&e.jsx("optgroup",{label:"GGUF Models",children:Se.map(Ke=>e.jsxs("option",{value:Ke.id,children:[Ke.name,Ke.hasRuntime?"":" (no runtime)"]},Ke.id))}),Ve.length>0&&e.jsx("optgroup",{label:"Ollama",children:Ve.map(Ke=>e.jsx("option",{value:Ke.id,children:Ke.name},Ke.id))})]})})():Qe.map(ne=>e.jsx("option",{value:ne.id,children:ne.name},ne.id))]}),e.jsx(rt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})]}),v&&He&&e.jsx("div",{className:"text-2xs text-text-3 font-sans flex items-center gap-2 flex-wrap",children:He.authType==="local"?e.jsx(ke,{variant:"success",children:"Local"}):He.authType==="subscription"?e.jsx(ke,{variant:"accent",children:"Subscription"}):He.hasKey?e.jsx(ke,{variant:"success",children:"API key set"}):e.jsxs(ke,{variant:"warning",children:["No API key — set with: groove set-key ",v," YOUR_KEY"]})}),v==="claude-code"&&j&&j.includes("opus")&&e.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":es,onClick:()=>rs(!es),className:X("relative w-8 h-[18px] rounded-full transition-colors flex-shrink-0",es?"bg-accent":"bg-surface-5"),children:e.jsx("span",{className:X("absolute top-[2px] left-[2px] w-[14px] h-[14px] rounded-full bg-white transition-transform",es&&"translate-x-[14px]")})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Fast mode"}),e.jsx("span",{className:"text-2xs text-text-3 font-sans ml-1.5",children:"Faster output, same model"})]})]}),v==="claude-code"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Billing"}),e.jsx("div",{className:"flex gap-1 p-0.5 rounded-md bg-surface-3 w-fit",children:[{id:"subscription",label:"Subscription"},{id:"usage",label:"Usage credits"}].map(ne=>e.jsx("button",{type:"button",onClick:()=>qo(ne.id),className:X("px-2.5 py-1 rounded text-2xs font-semibold font-sans transition-colors",tr===ne.id?"bg-accent text-white":"text-text-2 hover:text-text-0"),children:ne.label},ne.id))}),tr==="usage"&&!Wo&&e.jsx("p",{className:"text-2xs text-warning font-sans",children:"No Anthropic API key stored — add one in Settings → Providers before spawning."}),tr==="subscription"&&e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Uses your Claude Code login (Pro/Max)."})]}),v==="ollama"&&j&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap text-2xs font-sans",children:[Ot.some(ne=>ne.name===j)?e.jsxs(ke,{variant:"success",className:"text-2xs gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-success"}),"Ready — running in memory"]}):Re.some(ne=>ne.id===j)?e.jsx(ke,{variant:"subtle",className:"text-2xs",children:"Will auto-start when agent spawns"}):e.jsx(ke,{variant:"warning",className:"text-2xs",children:"Not installed — will pull first"}),!Bs&&e.jsx("span",{className:"text-warning",children:"Server not running — will auto-start"})]}),an&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Team"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("button",{onClick:()=>nr("new"),className:X("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",Ps==="new"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(ot,{size:13,className:Ps==="new"?"text-accent":"text-text-3"}),e.jsx("div",{children:e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"New Team"})})]}),e.jsxs("button",{onClick:()=>nr("existing"),className:X("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",Ps==="existing"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(Sn,{size:13,className:Ps==="existing"?"text-accent":"text-text-3"}),e.jsx("div",{children:e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Existing"})})]})]}),Ps==="new"&&e.jsx(Jt,{value:Oa,onChange:ne=>Bn(ne.target.value),placeholder:"Team name...",className:"text-xs"}),Ps==="existing"&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:nn,onChange:ne=>bs(ne.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Select team..."}),i.filter(ne=>!ne.archived).map(ne=>e.jsx("option",{value:ne.id,children:ne.name},ne.id))]}),e.jsx(rt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integrations"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[M.map(ne=>{const Se=T.find(Ke=>Ke.id===ne),Ve=Ci[ne];return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded bg-accent/12 text-accent border border-accent/25 text-2xs font-sans",children:[Ve?e.jsx("img",{src:Ve,alt:"",className:"w-2.5 h-2.5"}):e.jsx(Ls,{size:9}),(Se==null?void 0:Se.name)||ne,e.jsx("button",{onClick:()=>I(Ke=>Ke.filter(Ea=>Ea!==ne)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:e.jsx(qe,{size:9})})]},ne)}),e.jsxs("button",{onClick:()=>{W(!0),V("")},className:X("inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-2xs font-sans transition-colors cursor-pointer","bg-surface-0 text-text-2 border border-border-subtle hover:border-border hover:text-text-0"),children:[e.jsx(Ls,{size:10}),M.length>0?"Add integration":"Attach integration"]})]})]}),e.jsx(Gt,{open:J,onOpenChange:W,children:e.jsx(Zt,{title:"Select Integration",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ls,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:ee,onChange:ne=>V(ne.target.value),placeholder:"Search integrations...",autoFocus:!0,className:"w-full h-8 pl-8 pr-3 text-xs rounded-md bg-surface-0 border border-border text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsxs("div",{className:"max-h-64 overflow-y-auto space-y-1",children:[T.filter(ne=>{if(!ee)return!0;const Se=ee.toLowerCase();return(ne.name||ne.id).toLowerCase().includes(Se)||(ne.description||"").toLowerCase().includes(Se)}).map(ne=>{const Se=M.includes(ne.id),Ve=ne.configured!==!1,Ke=Ci[ne.id],Ea=Ae&&Array.isArray(ne.roles)&&ne.roles.includes(Ae);return e.jsxs("button",{onClick:()=>{Ve&&I(rn=>Se?rn.filter(ar=>ar!==ne.id):[...rn,ne.id])},disabled:!Ve,className:X("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors",Ve?"cursor-pointer":"opacity-40 cursor-not-allowed",Se?"bg-accent/10 border border-accent/25":Ve?"hover:bg-surface-3 border border-transparent":"border border-transparent"),children:[Ke?e.jsx("img",{src:Ke,alt:"",className:"w-4 h-4 flex-shrink-0"}):e.jsx(Ls,{size:12,className:Se?"text-accent":"text-text-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:ne.name||ne.id}),!Ve&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"(not configured)"}),Ve&&Ea&&e.jsx("span",{className:"text-2xs font-mono text-accent/70 bg-accent/8 px-1 py-px rounded",children:"rec"})]}),ne.description&&e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:ne.description}),!Ve&&e.jsx("div",{className:"text-2xs text-text-4 font-sans",children:"Configure in Integrations"})]}),Se&&e.jsx(mQ,{})]},ne.id)}),T.length===0&&e.jsx("div",{className:"text-center py-6 text-xs text-text-3 font-sans",children:"No integrations installed. Visit the Integrations tab to install some."})]})]})})}),M.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integration Approvals"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("button",{onClick:()=>E("manual"),className:X("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:[e.jsx(Qn,{size:13,className:z==="manual"?"text-accent":"text-text-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Manual"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"You approve each action"})]})]}),e.jsxs("button",{onClick:()=>E("auto"),className:X("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:[e.jsx(dn,{size:13,className:z==="auto"?"text-warning":"text-text-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Auto"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"Agent acts without asking"})]})]})]})]}),q.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Repos"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[$.map(ne=>{const Se=q.find(Ve=>Ve.id===ne);return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded bg-accent/12 text-accent border border-accent/25 text-2xs font-sans",children:[e.jsx(nc,{size:9}),(Se==null?void 0:Se.name)||ne,e.jsx("button",{onClick:()=>D(Ve=>Ve.filter(Ke=>Ke!==ne)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:e.jsx(qe,{size:9})})]},ne)}),e.jsxs("button",{onClick:()=>{L(!0),pe("")},className:X("inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-2xs font-sans transition-colors cursor-pointer","bg-surface-0 text-text-2 border border-border-subtle hover:border-border hover:text-text-0"),children:[e.jsx(nc,{size:10}),$.length>0?"Add repo":"Attach repo"]})]})]}),e.jsx(Gt,{open:Y,onOpenChange:L,children:e.jsx(Zt,{title:"Select Repository",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-3 p-4",children:[q.length>1&&e.jsxs("div",{className:"relative",children:[e.jsx(ls,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:te,onChange:ne=>pe(ne.target.value),placeholder:"Search repos...",autoFocus:!0,className:"w-full h-8 pl-8 pr-3 text-xs rounded-md bg-surface-0 border border-border text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:q.filter(ne=>{if(!te)return!0;const Se=te.toLowerCase();return(ne.name||ne.repo||ne.id).toLowerCase().includes(Se)}).map(ne=>{const Se=$.includes(ne.id);return e.jsxs("button",{onClick:()=>{D(Ve=>Se?Ve.filter(Ke=>Ke!==ne.id):[...Ve,ne.id])},className:X("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors cursor-pointer",Se?"bg-accent/10 border border-accent/25":"hover:bg-surface-3 border border-transparent"),children:[e.jsx(nc,{size:12,className:Se?"text-accent":"text-text-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:ne.name||ne.repo}),e.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:ne.clonedTo})]}),Se&&e.jsx(mQ,{})]},ne.id)})})]})})}),(x==="chat"||_)&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Personality"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:le,onChange:ne=>je(ne.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"None (blank)"}),K.map(ne=>e.jsx("option",{value:ne.name||ne,children:ne.name||ne},ne.name||ne))]}),e.jsx(rt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:"Personality is injected into every prompt for this agent."})]}),x!=="chat"&&!_&&e.jsx("button",{onClick:()=>re(!0),className:"text-2xs text-text-3 hover:text-accent font-sans transition-colors cursor-pointer",children:"+ Advanced options"})]})]}),e.jsxs("div",{className:"border-t border-border-subtle px-5 py-4 bg-surface-1",children:[Xe.length===0&&P.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 px-3 py-2 rounded-md bg-warning/8 border border-warning/20",children:[e.jsx(Ss,{size:13,className:"text-warning flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-sans text-text-2",children:"No AI providers installed. Install Claude Code, Gemini CLI, Codex, or Ollama to spawn agents."})]}),Ae&&Xe.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 text-xs text-text-3 font-sans flex-wrap",children:[e.jsx("span",{children:"Spawning"}),e.jsx(ke,{variant:"accent",children:Ae}),v&&e.jsxs("span",{children:["on ",(He==null?void 0:He.name)||v]}),b&&e.jsxs("span",{children:["as ",b.replace(/\s+/g,"-")]}),Ps==="new"&&e.jsxs("span",{children:["in new team",Oa?` "${Oa}"`:""]}),Ps==="existing"&&nn&&e.jsxs("span",{children:["in ",(($d=i.find(ne=>ne.id===nn))==null?void 0:$d.name)||"team"]})]}),e.jsx(xe,{variant:"primary",size:"lg",onClick:Jo,disabled:!Ae||fe||Xe.length===0||Ps==="existing"&&!nn,className:"w-full",children:fe?"Spawning...":"Spawn Agent"})]})]})}),e.jsx(Gt,{open:!!ie,onOpenChange:ne=>{ne||Be(null)},children:e.jsx(Zt,{title:"Integration Warning",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsx("div",{className:"space-y-2",children:(ie||[]).map((ne,Se)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs text-text-1 font-sans",children:[e.jsx(Ss,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsx("span",{children:ne.name?`${ne.name}: ${ne.problem==="not_installed"?"not installed":ne.problem==="not_configured"?"not configured":"not authenticated"}`:ne.message||String(ne)})]},Se))}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Continue anyway?"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(xe,{variant:"ghost",size:"md",onClick:()=>Be(null),className:"flex-1",children:"Cancel"}),e.jsx(xe,{variant:"warning",size:"md",onClick:()=>{Be(null),Yo()},className:"flex-1",children:"Spawn Anyway"})]})]})})})]})}function vie(){const t=k(O=>O.journalistStatus),s=k(O=>O.fetchJournalist),n=k(O=>O.triggerJournalistCycle),[a,r]=p.useState(!0),[i,c]=p.useState(!1);p.useEffect(()=>{s().then(()=>r(!1));const O=setInterval(s,1e4);return()=>clearInterval(O)},[s]);async function A(){c(!0);try{await n()}catch{}c(!1)}if(a)return e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx(Ln,{className:"h-6 w-32 rounded"}),e.jsx(Ln,{className:"h-20 rounded-md"}),e.jsx(Ln,{className:"h-20 rounded-md"})]});const u=t||{},x=u.lastSynthesis,h=u.history||[];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"pl-5 pr-10 py-4 border-b border-border-subtle flex items-center gap-2",children:[e.jsx(px,{size:16,className:"text-accent"}),e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Journalist"}),e.jsxs(xe,{variant:"secondary",size:"sm",onClick:A,disabled:i,className:"gap-1.5 text-2xs",children:[e.jsx(sn,{size:11,className:i?"animate-spin":""}),i?"Running...":"Run Synthesis"]})]}),e.jsx(Qt,{className:"flex-1",children:e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Mo,{size:10}),e.jsxs("span",{children:[u.cycleCount||0," cycles"]})]}),u.lastCycleTime&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Zn,{size:10}),e.jsxs("span",{children:["Last: ",cs(u.lastCycleTime)]})]}),e.jsx(ke,{variant:u.cycleCount>0?"success":"default",className:"text-2xs",children:u.cycleCount>0?"Active":"Idle"})]}),(x==null?void 0:x.summary)&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[e.jsx(wn,{size:12,className:"text-text-3"}),"Latest Summary"]}),e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-sans leading-relaxed",children:x.summary})]}),(x==null?void 0:x.projectMap)&&e.jsx(Hx,{title:"Project Map",icon:VM,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-mono leading-relaxed max-h-64 overflow-y-auto whitespace-pre-wrap",children:x.projectMap})}),(x==null?void 0:x.decisions)&&e.jsx(Hx,{title:"Decisions Log",icon:wn,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-mono leading-relaxed max-h-64 overflow-y-auto whitespace-pre-wrap",children:x.decisions})}),h.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[e.jsx(Zn,{size:12,className:"text-text-3"}),"History (",h.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:h.slice().reverse().slice(0,20).map((O,g)=>e.jsxs("div",{className:"bg-surface-0 rounded-md border border-border-subtle px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xs",children:[e.jsxs(ke,{variant:"default",className:"text-2xs",children:["Cycle ",O.cycle]}),e.jsxs("span",{className:"text-text-4 font-sans",children:[O.agentCount," agent",O.agentCount!==1?"s":""]}),e.jsx("span",{className:"text-text-4 font-sans ml-auto",children:cs(O.timestamp)})]}),O.summary&&e.jsx("p",{className:"text-xs text-text-2 font-sans mt-1 leading-relaxed",children:O.summary})]},g))})]}),!x&&h.length===0&&e.jsxs("div",{className:"text-center py-8 text-text-4 font-sans",children:[e.jsx(px,{size:28,className:"mx-auto mb-2"}),e.jsx("p",{className:"text-sm",children:"No synthesis data yet"}),e.jsx("p",{className:"text-2xs mt-1",children:"The journalist runs automatically when agents are active, or trigger manually above"})]})]})})]})}const yie=[{cmd:"save",args:"#tag",desc:"Save the message and send it to the agent"},{cmd:"append",args:"#tag",desc:"Add to an existing memory and send to agent"},{cmd:"update",args:"#tag",desc:"Open the editor to modify a memory in place"},{cmd:"delete",args:"#tag",desc:"Remove a memory permanently"},{cmd:"view",args:"#tag",desc:"Read a memory in the viewer"},{cmd:"read",args:"#tag1 #tag2 ...",desc:"Send memory content to the agent — chat stays clean"},{cmd:"doc",args:"#tag",desc:"AI synthesizes the full conversation into a document"},{cmd:"link",args:"#tag path/to/doc",desc:"Link a memory to a NORTHSTAR or external document"},{cmd:"[instruct]",args:"",desc:"Show this command reference"}];function wie(){var j;const t=k(N=>N.keeperEditing),s=k(N=>N.setKeeperEditing),n=k(N=>N.saveKeeperItem),a=k(N=>N.updateKeeperItem),r=k(N=>N.activeView),[i,c]=p.useState(""),[A,u]=p.useState(""),x=p.useRef(null),h=!!t&&r!=="memory";p.useEffect(()=>{t&&(c(t.tag||""),u(t.content||""))},[t]),p.useEffect(()=>{h&&x.current&&setTimeout(()=>{var N;return(N=x.current)==null?void 0:N.focus()},100)},[h]);const O=N=>{N||s(null)},g=async()=>{!i.trim()||t!=null&&t.readOnly||(t!=null&&t.isNew?await n(i.trim(),A):await a(i.trim(),A),s(null))},b=N=>{N.key==="s"&&(N.metaKey||N.ctrlKey)&&(N.preventDefault(),g())};if(!t)return null;const y=t.readOnly,v=t.isNew,S=y?`#${t.tag}`:v?"New Memory":`Edit #${t.tag}`;return e.jsx(Gt,{open:h,onOpenChange:O,children:e.jsx(Zt,{title:S,description:"Memory content",className:"max-w-2xl",children:e.jsxs("div",{className:"p-5 space-y-4",onKeyDown:b,children:[v&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-text-2 mb-1.5",children:"Tag"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-sm text-text-3",children:"#"}),e.jsx("input",{type:"text",value:i,onChange:N=>c(N.target.value.replace(/[^a-zA-Z0-9/_-]/g,"").toLowerCase()),placeholder:"project/feature-name",className:"flex-1 px-2 py-1.5 text-sm font-mono rounded-md bg-surface-0 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"})]})]}),e.jsx("textarea",{ref:x,value:A,onChange:N=>!y&&u(N.target.value),readOnly:y,rows:16,className:"w-full px-3 py-2 text-sm font-mono leading-relaxed rounded-md bg-surface-0 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent resize-y",placeholder:"Write your thoughts, ideas, context..."}),e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[y?e.jsx("p",{className:"text-2xs text-text-4",children:"Read-only view"}):e.jsxs("p",{className:"text-2xs text-text-4",children:[(j=navigator.platform)!=null&&j.includes("Mac")?"Cmd":"Ctrl","+S to save"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>s(null),children:y?"Close":"Cancel"}),!y&&e.jsxs(xe,{variant:"primary",size:"sm",onClick:g,disabled:!i.trim(),children:[e.jsx(Mr,{size:14})," Save"]})]})]})]})})})}function jie(){const t=k(n=>n.keeperInstructOpen);return k(n=>n.activeView)==="memory"?null:e.jsx(Gt,{open:t,onOpenChange:n=>k.setState({keeperInstructOpen:n}),children:e.jsx(Zt,{title:"Keeper Commands",description:"Memory system command reference",className:"max-w-lg",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx("p",{className:"text-xs text-text-2 leading-relaxed",children:"Type these commands in any agent chat to manage your tagged memories. Commands are intercepted by Keeper — the agent never sees them."}),e.jsx("div",{className:"space-y-1.5",children:yie.map(n=>e.jsxs("div",{className:"flex items-start gap-3 py-1.5 border-b border-border-subtle last:border-0",children:[e.jsxs("div",{className:"flex-shrink-0 flex items-center gap-1",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-accent/15 text-accent font-mono text-xs font-semibold",children:n.cmd}),n.args&&e.jsx("span",{className:"text-xs text-text-3 font-mono",children:n.args})]}),e.jsx("span",{className:"text-xs text-text-3 pt-0.5",children:n.desc})]},n.cmd))}),e.jsxs("div",{className:"pt-2 space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold text-text-1",children:"Tag Hierarchy"}),e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed",children:["Use ",e.jsx("span",{className:"font-mono text-accent",children:"/"})," for nesting: ",e.jsx("span",{className:"font-mono text-accent",children:"#groove/memory-system"}),". Pull a parent to get all children."]}),e.jsx("h3",{className:"text-xs font-semibold text-text-1",children:"Memory Types"}),e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed",children:[e.jsx("span",{className:"font-semibold",children:"Manual"})," — you write via [save]/[append]/[update]. ",e.jsx("span",{className:"font-semibold",children:"Doc"})," — AI writes via [doc]. Both editable."]})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>k.setState({keeperInstructOpen:!1}),children:"Close"})})]})})})}function Nie(){return e.jsxs(e.Fragment,{children:[e.jsx(wie,{}),e.jsx(jie,{})]})}function Qie({onSelect:t,onClose:s}){const n=p.useRef(null),a=k(u=>u.agents),r=k(u=>u.teams);p.useEffect(()=>{function u(h){n.current&&!n.current.contains(h.target)&&s()}function x(h){h.key==="Escape"&&s()}return document.addEventListener("mousedown",u),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",x)}},[s]);const i=a.filter(u=>u.status==="running"||u.status==="starting"),c=a.filter(u=>u.status!=="running"&&u.status!=="starting");function A(u){const x=r.find(h=>h.id===u);return(x==null?void 0:x.name)||"Default"}return e.jsxs("div",{ref:n,className:"absolute bottom-full right-0 mb-1 z-50 min-w-[220px] max-h-[300px] overflow-y-auto py-1 bg-surface-2 border border-border rounded-lg shadow-xl",children:[i.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-1 text-2xs text-text-4 font-sans font-medium uppercase tracking-wider",children:"Active"}),i.map(u=>e.jsxs("button",{onClick:()=>t(u.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-5 cursor-pointer transition-colors text-left",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-success flex-shrink-0"}),e.jsx("span",{className:"truncate flex-1",children:u.name}),e.jsx("span",{className:"text-2xs text-text-4",children:A(u.teamId)})]},u.id))]}),c.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-1 text-2xs text-text-4 font-sans font-medium uppercase tracking-wider",children:i.length>0?"Other":"Agents"}),c.slice(0,10).map(u=>e.jsxs("button",{onClick:()=>t(u.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs font-sans text-text-2 hover:bg-surface-5 cursor-pointer transition-colors text-left",children:[e.jsx("span",{className:X("w-1.5 h-1.5 rounded-full flex-shrink-0",u.status==="completed"?"bg-accent":u.status==="crashed"?"bg-danger":"bg-text-4")}),e.jsx("span",{className:"truncate flex-1",children:u.name}),e.jsx("span",{className:"text-2xs text-text-4",children:A(u.teamId)})]},u.id))]}),a.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-text-4 font-sans text-center",children:"No agents available"})]})}function Sie({children:t,height:s,onHeightChange:n,visible:a,fullHeight:r,tabs:i,activeTab:c,onSelectTab:A,onAddTab:u,onCloseTab:x,onToggleFullHeight:h,onMinimize:O,onClose:g,onRenameTab:b,selectedText:y}){const v=p.useRef(!1),[S,j]=p.useState(null),[N,B]=p.useState(""),[C,P]=p.useState(!1),U=p.useRef(0),T=p.useRef(0),R=k($=>$.detailPanel),M=k($=>$.workspaceAgentId),I=(R==null?void 0:R.type)==="agent"?R.agentId:M||null,J=k($=>$.agents),W=k($=>$.attachSnippet),ee=J.find($=>$.id===I),V=y&&y.trim().length>0,z=p.useCallback($=>{if(r)return;$.preventDefault(),v.current=!0,U.current=$.clientY,T.current=s;function D(L){if(!v.current)return;const te=U.current-L.clientY,pe=Math.min(Math.max(T.current+te,120),600);n(pe)}function Y(){v.current=!1,document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",Y)}document.addEventListener("mousemove",D),document.addEventListener("mouseup",Y)},[s,n,r]);function E($){!$||!(y!=null&&y.trim())||(P(!1),W({type:"terminal",code:y.trim()}),k.getState().selectAgent($))}function q(){I?E(I):P(!0)}const Z=i||[{id:"default",label:"Terminal"}];return e.jsxs("div",{className:X("flex flex-col border-t border-border bg-surface-0 relative",!a&&"hidden"),style:a?r?{flex:1,minHeight:0}:{height:s,flexShrink:0}:{height:0},children:[!r&&e.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 cursor-row-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:z}),e.jsxs("div",{className:"flex items-center h-9 bg-surface-1 border-b border-border flex-shrink-0 pl-0 pr-3",children:[e.jsxs("div",{className:"flex items-center gap-0 flex-1 min-w-0 overflow-x-auto scrollbar-none h-full",children:[Z.map($=>e.jsxs("button",{onClick:()=>A==null?void 0:A($.id),onDoubleClick:()=>{j($.id),B($.label)},className:X("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",$.id===c?"text-text-0 bg-surface-3":"text-text-2 hover:text-text-0 hover:bg-surface-5/50"),children:[e.jsx(Za,{size:11}),S===$.id?e.jsx("input",{className:"bg-transparent border border-border rounded px-1 text-[11px] text-text-0 outline-none w-20 font-sans",value:N,onChange:D=>B(D.target.value),onBlur:()=>{N.trim()&&(b==null||b($.id,N.trim())),j(null)},onKeyDown:D=>{D.key==="Enter"&&(N.trim()&&(b==null||b($.id,N.trim())),j(null)),D.key==="Escape"&&j(null)},autoFocus:!0,onClick:D=>D.stopPropagation()}):e.jsx("span",{className:"truncate max-w-[100px]",children:$.label}),Z.length>1&&e.jsx("button",{onClick:D=>{D.stopPropagation(),x==null||x($.id)},className:"ml-1 p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:9})})]},$.id)),e.jsx("button",{onClick:u,className:"flex items-center justify-center w-6 h-6 text-text-3 hover:text-text-0 hover:bg-surface-5/50 rounded cursor-pointer transition-colors flex-shrink-0 ml-1",title:"New terminal",children:e.jsx(ot,{size:11})})]}),e.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0 ml-2",children:[V&&e.jsxs("div",{className:"relative flex items-center",children:[e.jsx(ut,{content:I?`Send to ${(ee==null?void 0:ee.name)||"agent"}`:"Send to agent",side:"top",children:e.jsx("button",{onClick:q,className:X("flex items-center gap-1.5 px-2 py-1 rounded text-xs font-sans cursor-pointer transition-colors mr-1","bg-accent/15 text-accent hover:bg-accent/25 disabled:opacity-50"),children:I?e.jsxs(e.Fragment,{children:[e.jsx(Kn,{size:11}),e.jsx("span",{className:"text-2xs max-w-[80px] truncate",children:(ee==null?void 0:ee.name)||"Agent"})]}):e.jsxs(e.Fragment,{children:[e.jsx(dn,{size:11}),e.jsx("span",{className:"text-2xs",children:"Agent"}),e.jsx(rt,{size:9})]})})}),!I&&V&&e.jsx(ut,{content:"Pick agent",side:"top",children:e.jsx("button",{onClick:()=>P(!C),className:"p-1 rounded text-text-3 hover:text-accent hover:bg-accent/10 cursor-pointer transition-colors mr-1",children:e.jsx(rt,{size:10})})}),C&&e.jsx(Qie,{onSelect:$=>E($),onClose:()=>P(!1)})]}),r?e.jsx("button",{onClick:O,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Restore",children:e.jsx(rI,{size:12})}):e.jsx("button",{onClick:h,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Maximize",children:e.jsx(DS,{size:12})}),e.jsx("button",{onClick:g,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Close terminal",children:e.jsx(qe,{size:12})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 pl-2 pt-1",children:t})]})}const Bie={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 cO=0,Cie=0;function kie({tabId:t,visible:s,registerKill:n,onSelectionChange:a}){const r=p.useRef(null),i=p.useRef(null),c=p.useRef(null),A=p.useRef(null),u=p.useRef(null),x=p.useRef(!1),h=p.useRef(s),O=p.useRef({cols:0,rows:0}),g=p.useRef(!1);p.useEffect(()=>{n==null||n(t,()=>{const y=k.getState().ws;(y==null?void 0:y.readyState)===WebSocket.OPEN&&A.current&&y.send(JSON.stringify({type:"terminal:kill",id:A.current}))})},[t,n]);const b=k(y=>y.terminalPendingCommand);return p.useEffect(()=>{if(!b||!s)return;let y=0,v=null;const S=()=>{const j=k.getState().ws;if((j==null?void 0:j.readyState)===WebSocket.OPEN&&A.current&&g.current){j.send(JSON.stringify({type:"terminal:input",id:A.current,data:b.command+"\r"})),k.getState().clearTerminalPendingCommand();return}y++<40&&(v=setTimeout(S,150))};return S(),()=>clearTimeout(v)},[b,s]),p.useEffect(()=>{if(!r.current||x.current)return;x.current=!0;const y=new lE({theme:Bie,fontFamily:"'SF Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace",fontSize:12,lineHeight:1.1,letterSpacing:0,cursorBlink:!0,cursorStyle:"bar",cursorWidth:1,scrollback:1e4,allowProposedApi:!0,minimumContrastRatio:1,drawBoldTextInBrightColors:!0,fontWeight:"400",fontWeightBold:"600",overviewRulerWidth:0}),v=new cE;y.loadAddon(v),y.loadAddon(new AE),y.open(r.current),i.current=y,c.current=v,y.onSelectionChange(()=>{const R=y.getSelection();a==null||a(R||"")});let S=0,j=!1;function N(){S++;const R=k.getState().ws;if(!R||R.readyState!==WebSocket.OPEN){S<20&&setTimeout(N,500);return}const M=`spawn-${++Cie}`;R.send(JSON.stringify({type:"terminal:spawn",cols:y.cols,rows:y.rows,requestId:M}));function I(W){let ee;try{ee=JSON.parse(W.data)}catch{return}ee.type==="terminal:spawned"&&ee.requestId===M&&!A.current?(A.current=ee.id,setTimeout(()=>{try{v.fit()}catch{}const V=y.cols,z=y.rows;if(V>1&&z>1&&A.current){const q=k.getState().ws;(q==null?void 0:q.readyState)===WebSocket.OPEN&&(q.send(JSON.stringify({type:"terminal:resize",id:A.current,rows:z,cols:V})),O.current={cols:V,rows:z})}y.reset(),j=!0,g.current=!0;const E=k.getState().ws;(E==null?void 0:E.readyState)===WebSocket.OPEN&&A.current&&E.send(JSON.stringify({type:"terminal:input",id:A.current,data:"\f"}))},300)):ee.type==="terminal:output"&&ee.id===A.current?j&&y.write(ee.data):ee.type==="terminal:exit"&&ee.id===A.current&&(j=!0,g.current=!1,y.write(`\r
|
|
1088
1088
|
\x1B[90m[session ended]\x1B[0m\r
|
|
1089
1089
|
`),A.current=null)}R.addEventListener("message",I),u.current={ws:R,handler:I},y.onData(W=>{const ee=k.getState().ws;(ee==null?void 0:ee.readyState)===WebSocket.OPEN&&A.current&&ee.send(JSON.stringify({type:"terminal:input",id:A.current,data:W}))});let J=null;y.onResize(({cols:W,rows:ee})=>{W===O.current.cols&&ee===O.current.rows||W<2||ee<2||(O.current={cols:W,rows:ee},clearTimeout(J),J=setTimeout(()=>{const{cols:V,rows:z}=O.current,E=k.getState().ws;(E==null?void 0:E.readyState)===WebSocket.OPEN&&A.current&&E.send(JSON.stringify({type:"terminal:resize",id:A.current,rows:z,cols:V}))},150))})}let B=!1,C=null;function P(){if(B)return;const R=r.current;if(!R||R.offsetWidth<200||R.offsetHeight<50){clearTimeout(C),C=null;return}C||(C=setTimeout(()=>{if(B)return;const M=r.current;if(!M||M.offsetWidth<200||M.offsetHeight<50){C=null;return}B=!0;try{v.fit()}catch{}N()},200))}requestAnimationFrame(P);const U=setTimeout(()=>{if(!B){B=!0;try{v.fit()}catch{}N()}},5e3),T=new ResizeObserver(()=>{h.current&&requestAnimationFrame(()=>{if(!B)P();else try{v.fit()}catch{}})});return T.observe(r.current),()=>{clearTimeout(C),clearTimeout(U),T.disconnect(),u.current&&u.current.ws.removeEventListener("message",u.current.handler),y.dispose(),c.current=null,i.current=null,x.current=!1}},[]),p.useEffect(()=>{h.current=s,s&&c.current&&requestAnimationFrame(()=>{try{c.current.fit()}catch{}})},[s]),e.jsx("div",{ref:r,className:"w-full h-full overflow-hidden",style:{display:s?"block":"none"}})}function Tie(){const t=k(j=>j.terminalVisible),s=k(j=>j.terminalHeight),n=k(j=>j.setTerminalVisible),a=k(j=>j.setTerminalHeight),r=k(j=>j.terminalFullHeight),i=k(j=>j.setTerminalFullHeight),[c,A]=p.useState([{id:"term-0",label:"Terminal"}]),[u,x]=p.useState("term-0"),[h,O]=p.useState(""),g=p.useRef({}),b=p.useCallback((j,N)=>{g.current[j]=N},[]),y=p.useCallback(()=>{cO++;const j=`term-${cO}`;A(N=>[...N,{id:j,label:`Terminal ${cO+1}`}]),x(j)},[]),v=p.useCallback((j,N)=>{A(B=>B.map(C=>C.id===j?{...C,label:N}:C))},[]),S=p.useCallback(j=>{var N,B;(B=(N=g.current)[j])==null||B.call(N),delete g.current[j],A(C=>{const P=C.filter(U=>U.id!==j);if(P.length===0)return n(!1),C;if(u===j){const U=C.findIndex(R=>R.id===j),T=P[Math.min(U,P.length-1)];x(T.id)}return P})},[u,n]);return e.jsx(Sie,{visible:t,height:s,onHeightChange:a,fullHeight:r,tabs:c,activeTab:u,onSelectTab:x,onAddTab:y,onCloseTab:S,onRenameTab:v,onToggleFullHeight:()=>i(!0),onMinimize:()=>i(!1),onClose:()=>n(!1),selectedText:h,children:c.map(j=>e.jsx(kie,{tabId:j.id,visible:j.id===u,registerKill:b,onSelectionChange:j.id===u?O:void 0},j.id))})}class Zf extends ho.Component{constructor(s){super(s),this.state={error:null}}static getDerivedStateFromError(s){return{error:s}}render(){return this.state.error?e.jsxs("div",{className:"h-screen bg-surface-0 p-10 font-sans",children:[e.jsx("h2",{className:"text-lg font-semibold text-text-0 mb-4",children:"Groove — Render Error"}),e.jsx("pre",{className:"text-sm text-danger whitespace-pre-wrap mb-4",children:this.state.error.message}),e.jsx("pre",{className:"text-xs text-text-3 whitespace-pre-wrap",children:this.state.error.stack}),e.jsx("button",{onClick:()=>this.setState({error:null}),className:"mt-6 px-4 py-2 bg-accent text-surface-0 rounded-md font-medium text-sm cursor-pointer",children:"Try Again"})]}):this.props.children}}function Uie(){const t=k(c=>c.activeView),s=k(c=>c.detailPanel),n=k(c=>c.agents),a=k(c=>c.networkUnlocked);let r;switch(t){case"agents":r=e.jsx(Vg,{});break;case"editor":r=e.jsx(jte,{});break;case"dashboard":r=e.jsx(rse,{});break;case"marketplace":r=e.jsx(kse,{});break;case"teams":r=e.jsx(qse,{});break;case"auto-agents":r=e.jsx(goe,{});break;case"models":r=e.jsx(One,{});break;case"model-lab":r=e.jsx(Qae,{});break;case"federation":r=e.jsx(Mne,{});break;case"settings":r=e.jsx(fne,{});break;case"fleet":r=e.jsx(ooe,{});break;case"axom":r=e.jsx(Woe,{});break;case"memory":r=e.jsx(Sre,{});break;case"network":r=a?e.jsx(bre,{}):e.jsx(Vg,{});break;default:r=e.jsx(Vg,{})}let i=null;if(s)switch(s.type){case"agent":{n.some(c=>c.id===s.agentId)&&(i=e.jsx(gie,{}));break}case"journalist":i=e.jsx(vie,{});break;case"spawn":i=null;break}return e.jsxs(Gee,{detailContent:i,terminalContent:e.jsx(Tie,{}),children:[r,e.jsx(bie,{})]})}function Eie(){const t=k(n=>n.remoteHomedir),s=k(n=>n.setProjectDir);return e.jsxs("div",{className:"fixed inset-0 z-40 bg-surface-0 flex flex-col items-center justify-center gap-3",children:[e.jsx("img",{src:"/favicon.png",alt:"",className:"w-10 h-10 opacity-60"}),e.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Connected — choose a project directory to continue"}),e.jsx(Cc,{open:!0,onOpenChange:()=>{},currentPath:t||"/home",homePath:t,onSelect:n=>s(n),mandatory:!0})]})}function Pie(){const t=k(c=>c.connected),[s,n]=p.useState(!1),[a,r]=p.useState(!1);p.useEffect(()=>{const c=setTimeout(()=>n(!0),12e3);return()=>clearTimeout(c)},[]);async function i(){var c;if((c=window.groove)!=null&&c.reconnect){r(!0);try{await window.groove.reconnect()}catch{}r(!1)}window.location.reload()}return e.jsxs("div",{className:"h-screen bg-surface-0 flex flex-col items-center justify-center gap-4",children:[e.jsx("img",{src:"/favicon.png",alt:"",className:"w-10 h-10 opacity-60 animate-pulse"}),e.jsx("p",{className:"text-sm text-text-3 font-sans",children:a?"Re-establishing connection…":t?"Loading…":"Connecting to daemon…"}),s&&e.jsxs("div",{className:"flex flex-col items-center gap-2 mt-1",children:[e.jsx("p",{className:"text-xs text-text-4 font-sans max-w-xs text-center",children:"Still trying to reach the daemon. If you just woke your machine, the connection is re-establishing."}),e.jsx("button",{onClick:i,disabled:a,className:"px-3 py-1.5 rounded-md text-xs font-medium font-sans border border-accent/40 bg-accent/10 text-accent hover:bg-accent/20 disabled:opacity-50 transition-colors cursor-pointer",children:a?"Reconnecting…":"Reconnect"})]})]})}function Fie(){const t=k(c=>c.connect),s=k(c=>c.hydrated),n=k(c=>c.tunneled),a=k(c=>c.onboardingComplete),r=k(c=>c.showProjectPicker);p.useEffect(()=>{t()},[t]),p.useEffect(()=>{async function c(){var x;if((x=window.groove)!=null&&x.getInstanceInfo){const h=await window.groove.getInstanceInfo();if(h!=null&&h.name){document.title=`${h.name} — Groove`;return}}const u=new URLSearchParams(window.location.search).get("instance");if(u){const h=u.replace(/[\x00-\x1F]/g,"").slice(0,50);document.title=`${h} — Groove`}else n?document.title="Remote — Groove":document.title="Groove"}c()},[n]);const i=p.useMemo(()=>{var c;return(c=window.groove)!=null&&c.openFolder?[{key:"o",meta:!0,handler:()=>window.groove.openFolder()}]:[]},[]);return SQ(i),s?a?r&&n?e.jsx(Zf,{children:e.jsx(Eie,{})}):r?e.jsxs(Zf,{children:[e.jsx(ite,{}),e.jsx(RN,{})]}):e.jsxs(Zf,{children:[e.jsx(Uie,{}),e.jsx(RN,{}),e.jsx(ote,{}),e.jsx(Nie,{})]}):e.jsx(Zf,{children:e.jsx(ate,{})}):e.jsx(Pie,{})}mE.createRoot(document.getElementById("root")).render(e.jsx(p.StrictMode,{children:e.jsx(Fie,{})}));
|