groove-dev 0.26.35 → 0.26.36

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.
@@ -629,7 +629,7 @@ Error generating stack: `+c.message+`
629
629
 
630
630
  If you want to hide the \`${n.titleName}\`, you can wrap it with our VisuallyHidden component.
631
631
 
632
- For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return v.useEffect(()=>{t&&(document.getElementById(t)||console.error(s))},[s,t]),null},CX="DialogDescriptionWarning",_X=({contentRef:t,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${AS(CX).contentName}}.`;return v.useEffect(()=>{var u;const o=(u=t.current)==null?void 0:u.getAttribute("aria-describedby");n&&o&&(document.getElementById(n)||console.warn(r))},[r,t,n]),null},ZS=QS,ES=kS,qS=$S,MS=TS,YS=PS,US=RS,VS=_S;function Ch({children:t,...n}){return l.jsx(ZS,{...n,children:t})}function _h({children:t,className:n,title:s,description:r,...o}){return l.jsxs(ES,{children:[l.jsx(qS,{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"}),l.jsxs(MS,{className:re("fixed left-1/2 top-1/2 z-50 -translate-x-1/2 -translate-y-1/2","w-full max-w-lg max-h-[85vh] overflow-y-auto","bg-surface-1 border border-border rounded-lg shadow-2xl","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",n),...o,children:[s&&l.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border-subtle",children:[l.jsx(YS,{className:"text-base font-semibold text-text-0 font-sans",children:s}),l.jsx(VS,{className:"p-1 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-5 transition-colors",children:l.jsx(jt,{size:16})})]}),r&&l.jsx(US,{className:"sr-only",children:r}),t]})]})}const _c=v.forwardRef(({className:t,label:n,error:s,mono:r,...o},u)=>l.jsxs("div",{className:"flex flex-col gap-1",children:[n&&l.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:n}),l.jsx("input",{ref:u,className:re("h-8 w-full rounded-md px-3 text-sm","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",r?"font-mono":"font-sans",s&&"border-danger focus:ring-danger",t),...o}),s&&l.jsx("span",{className:"text-2xs text-danger font-sans",children:s})]}));_c.displayName="Input";const XX=v.forwardRef(({className:t,label:n,error:s,mono:r,...o},u)=>l.jsxs("div",{className:"flex flex-col gap-1",children:[n&&l.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:n}),l.jsx("textarea",{ref:u,className:re("w-full rounded-md px-3 py-2 text-sm resize-none","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",r?"font-mono":"font-sans",s&&"border-danger focus:ring-danger",t),...o}),s&&l.jsx("span",{className:"text-2xs text-danger font-sans",children:s})]}));XX.displayName="Textarea";const AX={slack:"https://cdn.simpleicons.org/slack/E01E5A",github:"https://cdn.simpleicons.org/github/white",stripe:"https://cdn.simpleicons.org/stripe/635BFF",gmail:"https://cdn.simpleicons.org/gmail/EA4335","google-calendar":"https://cdn.simpleicons.org/googlecalendar/4285F4","google-drive":"https://cdn.simpleicons.org/googledrive/4285F4","google-maps":"https://cdn.simpleicons.org/googlemaps/4285F4",postgres:"https://cdn.simpleicons.org/postgresql/4169E1",notion:"https://cdn.simpleicons.org/notion/white",discord:"https://cdn.simpleicons.org/discord/5865F2",linear:"https://cdn.simpleicons.org/linear/5E6AD2","brave-search":"https://cdn.simpleicons.org/brave/FB542B","home-assistant":"https://cdn.simpleicons.org/homeassistant/18BCF2"};function GS({item:t,size:n=48}){const s=AX[t.id];if(s)return l.jsx("div",{className:"rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:n,height:n},children:l.jsx("img",{src:s,alt:t.name,className:"w-6 h-6",onError:u=>{u.target.style.display="none"}})});const r=(t.name||"?")[0].toUpperCase(),o=t.name?t.name.charCodeAt(0)*37%360:200;return l.jsx("div",{className:"rounded-lg flex items-center justify-center flex-shrink-0 text-xl font-bold font-sans",style:{width:n,height:n,background:`hsl(${o}, 40%, 18%)`,color:`hsl(${o}, 60%, 65%)`},children:r})}function ZX({value:t,onChange:n,placeholder:s,disabled:r}){const[o,u]=v.useState(!1);return l.jsxs("div",{className:"relative",children:[l.jsx(_c,{type:o?"text":"password",value:t,onChange:d=>n(d.target.value),placeholder:s,disabled:r,mono:!0,className:"pr-9"}),l.jsx("button",{type:"button",onClick:()=>u(d=>!d),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded text-text-4 hover:text-text-1 transition-colors cursor-pointer",tabIndex:-1,children:o?l.jsx(Dc,{size:14}):l.jsx(Es,{size:14})})]})}function EX({integrationId:t,envKey:n,onSaved:s}){const r=ls(),[o,u]=v.useState(""),[d,O]=v.useState(!1),[h,p]=v.useState(n.set),[x,g]=v.useState(!1);async function b(){if(o.trim()){O(!0);try{await K.post(`/integrations/${t}/credentials`,{key:n.key,value:o.trim()}),p(!0),u(""),r.success(`${n.label} saved`),s==null||s()}catch(Q){r.error("Failed to save",Q.message)}O(!1)}}async function y(){g(!0);try{await K.delete(`/integrations/${t}/credentials/${n.key}`),p(!1),r.success(`${n.label} removed`),s==null||s()}catch(Q){r.error("Failed to remove",Q.message)}g(!1)}return l.jsxs("div",{className:"space-y-1.5",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[l.jsx(ri,{size:11,className:"text-text-4"}),n.label,n.required&&l.jsx("span",{className:"text-danger",children:"*"})]}),h&&l.jsxs("span",{className:"flex items-center gap-1 text-2xs text-success font-sans",children:[l.jsx(Qt,{size:10})," Set"]})]}),h?l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("div",{className:"flex-1 h-8 rounded-md px-3 bg-surface-2 border border-border-subtle flex items-center",children:l.jsx("span",{className:"text-xs text-text-4 font-mono tracking-widest",children:"*".repeat(16)})}),l.jsx(ge,{variant:"ghost",size:"sm",onClick:y,disabled:x,className:"text-text-3 hover:text-danger",children:x?l.jsx(Ct,{size:12,className:"animate-spin"}):l.jsx(_n,{size:12})})]}):l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("div",{className:"flex-1",children:l.jsx(ZX,{value:o,onChange:u,placeholder:n.placeholder||`Enter ${n.label.toLowerCase()}...`,disabled:d})}),l.jsx(ge,{variant:"primary",size:"sm",onClick:b,disabled:d||!o.trim(),children:d?l.jsx(Ct,{size:12,className:"animate-spin"}):"Save"})]})]})}function qX({item:t,status:n,installing:s,onInstall:r,onUninstall:o,onNext:u}){var O;const d=n==null?void 0:n.installed;return l.jsxs("div",{className:"px-5 py-5 space-y-5",children:[l.jsxs("div",{className:"flex items-start gap-4",children:[l.jsx(GS,{item:t,size:52}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:t.name}),(t.verified==="mcp-official"||t.verified==="verified")&&l.jsxs(ze,{variant:"accent",className:"text-2xs gap-1",children:[l.jsx(Yl,{size:9})," Verified"]})]}),l.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:t.author||"Community"}),t.category&&l.jsx(ze,{variant:"default",className:"text-2xs mt-2",children:t.category})]})]}),l.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((O=t.tags)==null?void 0:O.length)>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map(h=>l.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:h},h))}),l.jsx("div",{className:"h-px bg-border-subtle"}),d?l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[l.jsx(Ps,{size:16,className:"text-success"}),l.jsx("span",{className:"text-sm font-medium text-success font-sans",children:"Installed"})]}),l.jsxs(ge,{variant:"ghost",size:"sm",onClick:o,className:"text-text-3 hover:text-danger gap-1.5",children:[l.jsx(_n,{size:12})," Uninstall"]}),l.jsxs(ge,{variant:"primary",size:"sm",onClick:u,className:"gap-1",children:["Configure ",l.jsx(as,{size:12})]})]}):l.jsx(ge,{variant:"primary",size:"lg",onClick:r,disabled:s,className:"w-full gap-2",children:s?l.jsxs(l.Fragment,{children:[l.jsx(Ct,{size:14,className:"animate-spin"}),"Installing..."]}):"Install"}),s&&l.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"This may take up to 30 seconds..."})]})}function MX({item:t,status:n,onDone:s,onRefreshStatus:r}){var y;const o=ls(),[u,d]=v.useState(!1),O=t.authType;async function h(){d(!0);try{await K.post(`/integrations/${t.id}/authenticate`),o.success("Browser opened — complete sign-in there")}catch(Q){o.error("Auth failed",Q.message)}d(!1)}async function p(){d(!0);try{const Q=await K.post(`/integrations/${t.id}/oauth/start`);Q.url&&(window.open(Q.url,"_blank","noopener"),o.success("Browser opened — complete sign-in there"))}catch(Q){o.error("OAuth failed",Q.message)}d(!1)}const x=(n==null?void 0:n.envKeys)||[],g=x.filter(Q=>Q.required&&!Q.hidden),b=g.length===0||g.every(Q=>Q.set);return l.jsxs("div",{className:"px-5 py-5 space-y-5",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx(GS,{item:t,size:36}),l.jsxs("div",{children:[l.jsxs("h2",{className:"text-sm font-bold text-text-0 font-sans",children:["Configure ",t.name]}),l.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Set up credentials to connect"})]})]}),((y=t.setupSteps)==null?void 0:y.length)>0&&l.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[l.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Setup guide"}),l.jsx("ol",{className:"space-y-1.5",children:t.setupSteps.map((Q,w)=>l.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[l.jsxs("span",{className:"text-text-4 font-mono flex-shrink-0 w-4 text-right",children:[w+1,"."]}),l.jsx("span",{children:Q})]},w))}),t.setupUrl&&l.jsxs("a",{href:t.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-accent font-sans hover:underline mt-1",children:[l.jsx(si,{size:11}),new URL(t.setupUrl).hostname]})]}),l.jsx("div",{className:"h-px bg-border-subtle"}),O==="api-key"&&l.jsx("div",{className:"space-y-4",children:x.filter(Q=>!Q.hidden).map(Q=>l.jsx(EX,{integrationId:t.id,envKey:Q,onSaved:r},Q.key))}),O==="google-autoauth"&&l.jsxs("div",{className:"space-y-3",children:[l.jsx(ge,{variant:"primary",size:"lg",onClick:h,disabled:u,className:"w-full gap-2",children:u?l.jsxs(l.Fragment,{children:[l.jsx(Ct,{size:14,className:"animate-spin"}),"Opening browser..."]}):l.jsxs(l.Fragment,{children:[l.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),l.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"A browser window will open for Google authorization"})]}),O==="oauth-google"&&l.jsxs("div",{className:"space-y-3",children:[l.jsx(ge,{variant:"primary",size:"lg",onClick:p,disabled:u,className:"w-full gap-2",children:u?l.jsxs(l.Fragment,{children:[l.jsx(Ct,{size:14,className:"animate-spin"}),"Connecting..."]}):l.jsxs(l.Fragment,{children:[l.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Connect with Google"]})}),l.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["Authorize Groove to access your ",t.name]})]}),l.jsx(ge,{variant:b?"primary":"secondary",size:"lg",onClick:s,className:"w-full gap-1.5",children:b?l.jsxs(l.Fragment,{children:[l.jsx(Qt,{size:14}),"Done"]}):"Skip for now"})]})}function YX({item:t,onClose:n}){return l.jsxs("div",{className:"px-5 py-10 flex flex-col items-center text-center space-y-4",children:[l.jsx("div",{className:"w-14 h-14 rounded-full bg-success/15 flex items-center justify-center",children:l.jsx(Ps,{size:28,className:"text-success"})}),l.jsxs("div",{children:[l.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:"Integration ready"}),l.jsxs("p",{className:"text-sm text-text-3 font-sans mt-1",children:[t.name," is installed and configured. Agents can now use it."]})]}),l.jsx(ge,{variant:"primary",size:"lg",onClick:n,className:"mt-2",children:"Close"})]})}function UX({integration:t,open:n,onClose:s}){const r=ls(),[o,u]=v.useState("overview"),[d,O]=v.useState(null),[h,p]=v.useState(!1),[x,g]=v.useState(!0),b=v.useCallback(async()=>{try{const j=await K.get(`/integrations/${t.id}/status`);O(j)}catch{O(null)}g(!1)},[t.id]);v.useEffect(()=>{n&&t&&(u("overview"),g(!0),b())},[n,t,b]);async function y(){p(!0);try{await K.post(`/integrations/${t.id}/install`),r.success(`${t.name} installed`),await b(),u("configure")}catch(j){r.error("Install failed",j.message)}p(!1)}async function Q(){try{await K.delete(`/integrations/${t.id}`),r.success(`${t.name} uninstalled`),await b()}catch(j){r.error("Uninstall failed",j.message)}}function w(){u("configure")}function k(){u("done")}return t?l.jsx(Ch,{open:n,onOpenChange:j=>{j||s()},children:l.jsx(_h,{title:o==="overview"?t.name:o==="configure"?"Configure":"Complete",description:`Setup wizard for ${t.name}`,className:"max-w-md",children:x?l.jsx("div",{className:"px-5 py-10 flex items-center justify-center",children:l.jsx(Ct,{size:20,className:"animate-spin text-text-4"})}):o==="overview"?l.jsx(qX,{item:t,status:d,installing:h,onInstall:y,onUninstall:Q,onNext:w}):o==="configure"?l.jsx(MX,{item:t,status:d,onDone:k,onRefreshStatus:b}):l.jsx(YX,{item:t,onClose:s})})}):null}function VX({skill:t,onBack:n}){var G,R,_;const s=ls(),[r,o]=v.useState(""),[u,d]=v.useState(!1),[O,h]=v.useState(!1),[p,x]=v.useState(!1),[g,b]=v.useState(!1),[y,Q]=v.useState(t.installed),[w,k]=v.useState(!0);v.useEffect(()=>{k(!0),K.get(`/skills/${t.id}/content`).then(T=>{o(T.content||""),d(T.requiresPurchase||!1)}).catch(()=>{}).finally(()=>k(!1))},[t.id]);async function j(){h(!0);try{await K.post(`/skills/${t.id}/install`),Q(!0),s.success(`${t.name} installed`)}catch(T){s.error("Install failed",T.message)}h(!1)}async function z(){x(!0);try{await K.post(`/skills/${t.id}/update`),s.success(`${t.name} updated to latest`);const T=await K.get(`/skills/${t.id}/content`);T.content&&o(T.content)}catch(T){s.error("Update failed",T.message)}x(!1)}async function N(){b(!0);try{await K.delete(`/skills/${t.id}`),Q(!1),s.success(`${t.name} uninstalled`)}catch(T){s.error("Uninstall failed",T.message)}b(!1)}async function X(){const{marketplaceAuthenticated:T,marketplaceLogin:Y,marketplaceCheckout:M}=D.getState();if(!T){Y();return}try{await M(t.id)}catch{}}return l.jsx(ma,{className:"h-full",children:l.jsxs("div",{className:"px-6 py-5",children:[l.jsxs("button",{onClick:n,className:"flex items-center gap-1 text-xs text-text-3 font-sans hover:text-text-0 cursor-pointer bg-transparent border-0 mb-4",children:[l.jsx(Ab,{size:14})," Back"]}),l.jsxs("div",{className:"flex gap-8",children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"w-11 h-11 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-[22px]",children:t.icon||((R=(G=t.name)==null?void 0:G[0])==null?void 0:R.toUpperCase())}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:t.name}),l.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-text-3 font-sans",children:[l.jsx("span",{children:t.author||"Community"}),(t.source==="claude-official"||t.verified)&&l.jsx(iS,{type:t.source,size:13})]})]})]}),l.jsx("p",{className:"mt-3 text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((_=t.tags)==null?void 0:_.length)>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:t.tags.map(T=>l.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:T},T))}),l.jsx("div",{className:"h-px bg-border-subtle my-5"}),w?l.jsxs("div",{className:"space-y-2",children:[l.jsx("div",{className:"h-3 w-48 bg-surface-4 rounded animate-pulse"}),l.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),l.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}):r?l.jsxs("div",{className:"text-sm text-text-2 font-sans leading-relaxed",children:[l.jsx("h2",{className:"text-sm font-semibold text-text-0 mb-2",children:"About"}),l.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:r})]}):u?l.jsxs("div",{className:"bg-warning/5 border border-warning/15 rounded-lg px-4 py-3",children:[l.jsx("p",{className:"text-sm text-text-1 font-sans font-medium",children:"Paid skill — purchase to view content"}),l.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Sign in and purchase this skill to access its full instructions."})]}):l.jsx("p",{className:"text-xs text-text-4 font-sans",children:"Content loading failed — check your connection."})]}),l.jsx("div",{className:"w-[240px] flex-shrink-0",children:l.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-lg p-4 sticky top-4",children:[l.jsx(rS,{price:t.price||0,size:"md"}),u&&!y?l.jsxs("button",{onClick:X,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 flex items-center justify-center gap-2 border bg-warning/15 text-warning border-warning/20 hover:bg-warning/25",children:["Buy $",(t.price||0).toFixed(2)]}):y?l.jsxs("div",{className:"mt-3 flex flex-col gap-1.5",children:[l.jsxs("button",{onClick:z,disabled:p,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:[l.jsx(Cn,{size:12,className:p?"animate-spin":""}),p?"Updating...":"Pull Latest"]}),l.jsxs("button",{onClick:N,disabled:g,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-error/10 text-error border-error/20 hover:bg-error/15",children:[l.jsx(_n,{size:12}),g?"Removing...":"Uninstall"]})]}):l.jsx("button",{onClick:j,disabled:O,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:O?"Installing...":"Install"}),l.jsx("div",{className:"mt-4 flex flex-col gap-2.5",children:[["Downloads",l.jsx("span",{className:"font-mono text-text-0",children:Ke(t.downloads||0)},"d")],["Rating",l.jsx(sS,{rating:t.rating||0,count:t.rating_count||t.ratingCount,size:"sm"},"r")],["Version",l.jsx("span",{className:"font-mono text-text-0",children:t.version||"1.0.0"},"v")],["Category",l.jsx(lS,{label:t.category||"general",variant:t.category||"draft"},"c")],["Source",l.jsx("span",{className:"text-text-0",children:t.source==="claude-official"?"Anthropic":"Community"},"s")]].map(([T,Y])=>l.jsxs("div",{className:"flex justify-between items-center text-xs font-sans",children:[l.jsx("span",{className:"text-text-3",children:T}),Y]},T))})]})})]})]})})}function GX(){const[t,n]=v.useState([]),[s,r]=v.useState(!0),[o,u]=v.useState(""),[d,O]=v.useState(""),[h,p]=v.useState("popular"),[x,g]=v.useState(null);return v.useEffect(()=>{r(!0);const b=new URLSearchParams;o&&b.set("search",o),d&&b.set("category",d),h&&b.set("sort",h),K.get(`/skills/registry?${b}`).then(y=>n(S_(y.skills||y.items||(Array.isArray(y)?y:[])))).catch(()=>n([])).finally(()=>r(!1))},[o,d,h]),x?l.jsx(VX,{skill:x,onBack:()=>g(null)}):l.jsx(ma,{className:"h-full",children:l.jsxs("div",{className:"px-5 py-4",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("div",{className:"w-72",children:l.jsx(uS,{value:o,onChange:u})}),l.jsx(P_,{selected:d,onSelect:O}),l.jsx("div",{className:"flex-1"}),l.jsxs("div",{className:"relative flex-shrink-0",children:[l.jsxs("select",{value:h,onChange:b=>p(b.target.value),className:"appearance-none font-sans cursor-pointer pr-7 py-2 pl-3 text-xs bg-surface-0 border border-border-subtle rounded text-text-1 focus:outline-none",children:[l.jsx("option",{value:"popular",children:"Popular"}),l.jsx("option",{value:"rating",children:"Top Rated"}),l.jsx("option",{value:"newest",children:"Newest"}),l.jsx("option",{value:"name",children:"A-Z"})]}),l.jsx(zn,{size:12,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]}),l.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:t.length})]}),l.jsx("div",{className:"mt-4 grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:s?Array.from({length:8}).map((b,y)=>l.jsx(cS,{},y)):t.map(b=>l.jsx(w_,{skill:b,onClick:g},b.id))}),!s&&t.length===0&&l.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No skills found."})]})})}function LX(){const[t,n]=v.useState([]),[s,r]=v.useState(!0),[o,u]=v.useState(""),[d,O]=v.useState(null),[h,p]=v.useState(!1),x=()=>{r(!0),K.get(`/integrations/registry?search=${encodeURIComponent(o)}`).then(y=>n(y.integrations||y.items||(Array.isArray(y)?y:[]))).catch(()=>n([])).finally(()=>r(!1))};v.useEffect(()=>{x()},[o]);function g(y){O(y),p(!0)}function b(){p(!1),O(null),x()}return l.jsxs(ma,{className:"h-full",children:[l.jsxs("div",{className:"px-5 py-4",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("div",{className:"w-72",children:l.jsx(uS,{value:o,onChange:u,placeholder:"Search integrations..."})}),l.jsx("div",{className:"flex-1"}),l.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:t.length})]}),l.jsx("div",{className:"mt-4 grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:s?Array.from({length:6}).map((y,Q)=>l.jsx(cS,{},Q)):t.map(y=>l.jsx(T_,{item:y,onClick:()=>g(y)},y.id))}),!s&&t.length===0&&l.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No integrations found."})]}),l.jsx(UX,{integration:d,open:h,onClose:b})]})}function DX(){const t=D(k=>k.marketplaceAuthenticated),n=D(k=>k.marketplaceLogin),[s,r]=v.useState([]),[o,u]=v.useState([]),[d,O]=v.useState(!0),[h,p]=v.useState(null),x=ls(),g=v.useRef(null),b=async()=>{const k=await K.get("/skills/installed");u(Array.isArray(k)?k:k.skills||[])};v.useEffect(()=>{O(!0),Promise.all([t?K.get("/auth/purchases").then(k=>k.purchases||[]).catch(()=>[]):Promise.resolve([]),K.get("/skills/installed").then(k=>Array.isArray(k)?k:k.skills||[]).catch(()=>[])]).then(([k,j])=>{r(k),u(j)}).finally(()=>O(!1))},[t]);async function y(k){p(k.id);try{await K.post(`/skills/${k.id}/update`),x.success(`${k.name||k.id} updated`),await b()}catch(j){x.error("Update failed",j.message)}p(null)}async function Q(k){p(k.id);try{await K.delete(`/skills/${k.id}`),x.success(`${k.name||k.id} uninstalled`),await b()}catch(j){x.error("Uninstall failed",j.message)}p(null)}async function w(k){var z;const j=(z=k.target.files)==null?void 0:z[0];if(j){try{const N=await j.text(),X=j.name.replace(/\.md$/i,"");await K.post("/skills/import",{name:X,content:N}),x.success(`Imported "${X}"`),await b()}catch(N){x.error("Import failed",N.message)}k.target.value=""}}return d?l.jsx("div",{className:"p-5 space-y-3",children:[...Array(4)].map((k,j)=>l.jsx(on,{className:"h-14 rounded-md"},j))}):l.jsx(ma,{className:"h-full",children:l.jsxs("div",{className:"px-5 py-4 space-y-6",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("input",{ref:g,type:"file",accept:".md",onChange:w,className:"hidden"}),l.jsxs(ge,{variant:"secondary",size:"md",onClick:()=>{var k;return(k=g.current)==null?void 0:k.click()},className:"gap-1.5",children:[l.jsx(AN,{size:13}),"Import .md Skill"]}),l.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Drop a markdown skill file to install locally"})]}),t&&s.length>0&&l.jsxs("div",{children:[l.jsxs("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[l.jsx(TO,{size:12}),"Purchases (",s.length,")"]}),l.jsx("div",{className:"space-y-1.5",children:s.map(k=>{var j,z;return l.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-1 border border-border-subtle",children:[l.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center text-sm flex-shrink-0",children:k.skill_icon||((z=(j=k.skill_name)==null?void 0:j[0])==null?void 0:z.toUpperCase())||"?"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:k.skill_name||k.skill_id}),l.jsxs("div",{className:"text-2xs text-text-4 font-sans",children:["$",(k.amount||0).toFixed(2)," · ",vt(k.created_at)]})]}),l.jsx(ze,{variant:"success",className:"text-2xs flex-shrink-0",children:"Owned"})]},k.id||k.skill_id)})})]}),t&&s.length===0&&l.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[l.jsx(TO,{size:20,className:"mx-auto text-text-4 mb-2"}),l.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No purchases yet"})]}),!t&&l.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[l.jsx(TO,{size:20,className:"mx-auto text-text-4 mb-2"}),l.jsx("p",{className:"text-xs text-text-2 font-sans mb-3",children:"Sign in to see your purchases"}),l.jsxs(ge,{variant:"primary",size:"sm",onClick:n,className:"gap-1.5 mx-auto",children:[l.jsx(ah,{size:12})," Sign in"]})]}),l.jsxs("div",{children:[l.jsxs("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[l.jsx(Db,{size:12}),"Installed (",o.length,")"]}),o.length===0?l.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[l.jsx(xi,{size:20,className:"mx-auto text-text-4 mb-2"}),l.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No skills installed — browse the Skills tab or import a .md file"})]}):l.jsx("div",{className:"space-y-1.5",children:o.map(k=>{var j,z;return l.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-1 border border-border-subtle group",children:[l.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center text-sm flex-shrink-0",children:k.icon||((z=(j=k.name)==null?void 0:j[0])==null?void 0:z.toUpperCase())||"?"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:k.name||k.id}),l.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:k.description||k.category||"local skill"})]}),l.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[l.jsx("button",{onClick:()=>y(k),disabled:h===k.id,title:"Pull latest version",className:"p-1.5 rounded text-text-3 hover:text-accent hover:bg-accent/10 cursor-pointer transition-colors disabled:opacity-50",children:l.jsx(Cn,{size:12,className:h===k.id?"animate-spin":""})}),l.jsx("button",{onClick:()=>Q(k),disabled:h===k.id,title:"Uninstall",className:"p-1.5 rounded text-text-3 hover:text-error hover:bg-error/10 cursor-pointer transition-colors disabled:opacity-50",children:l.jsx(_n,{size:12})})]}),l.jsx(ze,{variant:"accent",className:"text-2xs flex-shrink-0",children:"Installed"})]},k.id)})})]})]})})}function WX(){const t=D(o=>o.marketplaceAuthenticated),n=D(o=>o.marketplaceUser),s=D(o=>o.marketplaceLogin),r=D(o=>o.marketplaceLogout);return t?l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded bg-surface-3 border border-border-subtle",children:[l.jsx("div",{className:"w-4 h-4 rounded-full bg-accent/20 flex items-center justify-center",children:l.jsx(ev,{size:9,className:"text-accent"})}),l.jsx("span",{className:"text-xs text-text-0 font-sans font-medium max-w-[120px] truncate",children:(n==null?void 0:n.displayName)||(n==null?void 0:n.id)||"Account"})]}),l.jsx("button",{onClick:r,className:"flex items-center gap-1 px-2 py-1.5 rounded text-xs text-text-3 hover:text-text-0 hover:bg-surface-3 font-sans cursor-pointer transition-colors",children:l.jsx(Vb,{size:11})})]}):l.jsxs("button",{onClick:s,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold font-sans text-text-0 bg-accent/15 border border-accent/25 rounded hover:bg-accent/25 cursor-pointer transition-colors",children:[l.jsx(ah,{size:12}),"Sign in"]})}function BX(){const[t,n]=v.useState("skills"),s=[{id:"skills",label:"Skills",icon:Kr},{id:"integrations",label:"Integrations",icon:Wb},{id:"library",label:"My Library",icon:Db}];return l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-b border-border-subtle",children:l.jsxs("div",{className:"flex items-center px-5 h-11",children:[l.jsx("div",{className:"flex items-center",children:s.map(r=>{const o=r.icon;return l.jsxs("button",{onClick:()=>n(r.id),className:`flex items-center gap-1.5 px-3 py-2.5 text-xs font-semibold font-sans cursor-pointer select-none border-b-2 -mb-px transition-colors ${t===r.id?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"}`,children:[l.jsx(o,{size:12}),r.label]},r.id)})}),l.jsx("div",{className:"flex-1"}),l.jsx(WX,{})]})}),l.jsxs("div",{className:"flex-1 min-h-0",children:[t==="skills"&&l.jsx(GX,{}),t==="integrations"&&l.jsx(LX,{}),t==="library"&&l.jsx(DX,{})]})]})}function HX(){const t=D(u=>u.teams),n=D(u=>u.agents),s=D(u=>u.activeTeamId),r=D(u=>u.deleteTeam),o=D(u=>u.addToast);return t.length===0?l.jsx("div",{className:"flex-1 flex items-center justify-center",children:l.jsxs("div",{className:"text-center space-y-2",children:[l.jsx(yi,{size:28,className:"mx-auto text-text-4"}),l.jsx("p",{className:"text-xs font-sans text-text-3",children:"No teams yet"}),l.jsx("p",{className:"text-2xs font-sans text-text-4",children:"Teams are created when you spawn agents or launch a planner"})]})}):l.jsx("div",{className:"flex-1 overflow-y-auto",children:l.jsx("div",{className:"p-4 space-y-3",children:t.map(u=>{const d=n.filter(y=>y.teamId===u.id),O=d.filter(y=>y.status==="running"||y.status==="starting"),h=d.filter(y=>y.status==="completed"),p=d.filter(y=>y.status==="crashed"),x=d.reduce((y,Q)=>y+(Q.tokensUsed||0),0),g=d.reduce((y,Q)=>y+(Q.costUsd||0),0),b=u.id===s;return l.jsxs("div",{className:re("rounded-md border bg-surface-1 overflow-hidden transition-colors",b?"border-accent/30":"border-border-subtle"),children:[l.jsxs("div",{className:"px-4 py-3 flex items-center gap-3",children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans",children:u.name}),b&&l.jsx(ze,{variant:"accent",className:"text-2xs",children:"Active"})]}),u.workingDir&&l.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[l.jsx(Mb,{size:10,className:"text-text-4"}),l.jsx("span",{className:"text-2xs font-mono text-text-3 truncate",children:u.workingDir})]})]}),l.jsx("button",{onClick:()=>{if(d.some(y=>y.status==="running")){o("error","Stop running agents first");return}r(u.id)},className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Delete team",children:l.jsx(_n,{size:13})})]}),l.jsxs("div",{className:"px-4 py-2.5 border-t border-border-subtle bg-surface-0 flex items-center gap-4",children:[l.jsx(kl,{label:"Agents",value:d.length}),l.jsx(kl,{label:"Running",value:O.length,color:O.length>0?"text-success":void 0}),l.jsx(kl,{label:"Done",value:h.length}),l.jsx(kl,{label:"Crashed",value:p.length,color:p.length>0?"text-danger":void 0}),l.jsx("div",{className:"flex-1"}),l.jsx(kl,{label:"Tokens",value:Ke(x)}),g>0&&l.jsx(kl,{label:"Cost",value:Si(g)})]}),d.length>0&&l.jsx("div",{className:"border-t border-border-subtle",children:d.map(y=>l.jsxs("div",{className:"flex items-center gap-2 px-4 py-1.5 border-b border-border-subtle last:border-b-0",children:[l.jsx(zs,{status:y.status,size:"sm"}),l.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:y.name}),l.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase",children:y.role}),l.jsx("div",{className:"flex-1"}),l.jsx("span",{className:"text-2xs font-mono text-text-2 tabular-nums",children:Ke(y.tokensUsed||0)})]},y.id))})]},u.id)})})})}function kl({label:t,value:n,color:s}){return l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:re("text-xs font-mono tabular-nums",s||"text-text-1"),children:n}),l.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider",children:t})]})}function IX(){const t=D(r=>r.pendingApprovals),n=D(r=>r.approveRequest),s=D(r=>r.rejectRequest);return t.length===0?null:l.jsxs("div",{className:"px-4 pt-4 space-y-2",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx(vi,{size:12,className:"text-warning"}),l.jsxs("span",{className:"text-2xs font-mono text-warning uppercase tracking-wider",children:["Pending (",t.length,")"]})]}),t.map(r=>{var o,u,d;return l.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-md bg-warning/5 border border-warning/20",children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"text-xs text-text-0 font-sans font-medium truncate",children:[r.agentName,": ",((o=r.action)==null?void 0:o.description)||((u=r.action)==null?void 0:u.type)||"action"]}),((d=r.action)==null?void 0:d.filePath)&&l.jsx("div",{className:"text-2xs font-mono text-text-3 truncate mt-0.5",children:r.action.filePath}),l.jsx("div",{className:"text-2xs text-text-4 font-mono mt-0.5",children:vt(r.requestedAt)})]}),l.jsxs("div",{className:"flex gap-1.5 flex-shrink-0",children:[l.jsxs(ge,{variant:"primary",size:"sm",onClick:()=>n(r.id),className:"h-7 px-2.5 gap-1 text-2xs",children:[l.jsx(Kb,{size:10})," Approve"]}),l.jsxs(ge,{variant:"danger",size:"sm",onClick:()=>s(r.id),className:"h-7 px-2.5 gap-1 text-2xs",children:[l.jsx(wN,{size:10})," Reject"]})]})]},r.id)})]})}function FX(){const t=D(h=>h.resolvedApprovals),[n,s]=v.useState([]),[r,o]=v.useState(!0);v.useEffect(()=>{const h=setInterval(u,4e3);return u(),()=>clearInterval(h)},[]);async function u(){try{const h=await K.get("/pm/history");s(h.history||h||[])}catch{}o(!1)}const d=new Set,O=[...t,...n].filter(h=>{const p=h.id||`${h.agentName}-${h.timestamp}`;return d.has(p)?!1:(d.add(p),!0)});return l.jsxs("div",{className:"flex-1 overflow-y-auto",children:[l.jsx(IX,{}),l.jsxs("div",{className:"p-4 space-y-1.5",children:[r&&O.length===0&&l.jsx("div",{className:"text-center py-12 text-text-4 font-mono text-xs",children:"Loading..."}),!r&&O.length===0&&l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Ps,{size:24,className:"mx-auto mb-2 text-text-4"}),l.jsx("p",{className:"text-xs font-sans text-text-3",children:"No approval history"}),l.jsx("p",{className:"text-2xs text-text-4 font-sans mt-1",children:"Approvals appear when agents use Auto permission mode"})]}),O.map((h,p)=>{var g;const x=h.status==="approved"||h.verdict==="approved";return l.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-surface-0 border border-border-subtle",children:[x?l.jsx(Ps,{size:12,className:"text-success flex-shrink-0"}):l.jsx(Zb,{size:12,className:"text-danger flex-shrink-0"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"text-xs text-text-1 font-sans truncate",children:[l.jsx("span",{className:"font-medium text-text-0",children:h.agentName}),l.jsx("span",{className:"text-text-3 mx-1",children:"·"}),l.jsx("span",{children:((g=h.action)==null?void 0:g.description)||h.action||"action"})]}),h.reason&&l.jsx("div",{className:"text-2xs text-text-3 font-sans truncate mt-0.5",children:h.reason})]}),l.jsx("span",{className:"text-2xs font-mono text-text-4 flex-shrink-0",children:vt(h.resolvedAt||h.timestamp)})]},h.id||p)})]})]})}function KX(){const[t,n]=v.useState([]),[s,r]=v.useState(!0),o=ls();v.useEffect(()=>{const O=setInterval(u,1e4);return u(),()=>clearInterval(O)},[]);async function u(){try{const O=await K.get("/schedules");n(O.schedules||O||[])}catch{}r(!1)}async function d(O,h){try{await K.post(`/schedules/${O}/${h?"disable":"enable"}`),u()}catch(p){o.error("Failed to toggle schedule",p.message)}}return l.jsx("div",{className:"flex-1 overflow-y-auto",children:l.jsxs("div",{className:"p-4 space-y-2",children:[s&&t.length===0&&l.jsx("div",{className:"text-center py-12 text-text-4 font-mono text-xs",children:"Loading..."}),!s&&t.length===0&&l.jsxs("div",{className:"text-center py-12",children:[l.jsx(vc,{size:24,className:"mx-auto mb-2 text-text-4"}),l.jsx("p",{className:"text-xs font-sans text-text-3",children:"No schedules configured"}),l.jsx("p",{className:"text-2xs text-text-4 font-sans mt-1",children:"Use the CLI to create agent schedules"})]}),t.map(O=>l.jsxs("div",{className:"rounded-md border border-border-subtle bg-surface-0 overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:O.name}),l.jsx(ze,{variant:O.enabled?"success":"default",className:"text-2xs",children:O.enabled?"Active":"Paused"})]}),l.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[l.jsx("span",{className:"text-2xs font-mono text-text-2",children:O.cron}),l.jsx("span",{className:"text-2xs text-text-4",children:"·"}),l.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase",children:O.role}),O.teamId&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"text-2xs text-text-4",children:"·"}),l.jsx("span",{className:"text-2xs font-sans text-text-3",children:O.teamName||O.teamId})]})]}),O.prompt&&l.jsx("div",{className:"text-2xs font-sans text-text-4 mt-1 truncate",children:O.prompt})]}),l.jsx(ge,{variant:"secondary",size:"sm",onClick:()=>d(O.id,O.enabled),className:"h-7 px-2.5 gap-1 text-2xs",children:O.enabled?l.jsxs(l.Fragment,{children:[l.jsx(tN,{size:10})," Pause"]}):l.jsxs(l.Fragment,{children:[l.jsx(rN,{size:10})," Enable"]})})]}),O.lastRunAt&&l.jsxs("div",{className:"px-4 py-1.5 border-t border-border-subtle bg-surface-1 text-2xs font-mono text-text-4",children:["Last run: ",vt(O.lastRunAt),O.nextRunAt&&l.jsxs("span",{className:"ml-3",children:["Next: ",vt(O.nextRunAt)]})]})]},O.id))]})})}function JX(){return l.jsxs(nS,{defaultValue:"dashboard",className:"flex flex-col h-full",children:[l.jsxs("div",{className:"px-4 pt-3 bg-surface-1 border-b border-border",children:[l.jsx("div",{className:"flex items-center gap-4 mb-0",children:l.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Management"})}),l.jsxs(aS,{className:"border-b-0",children:[l.jsxs(_l,{value:"dashboard",className:"inline-flex items-center gap-1.5",children:[l.jsx(PT,{size:12}),"Teams"]}),l.jsxs(_l,{value:"approvals",className:"inline-flex items-center gap-1.5",children:[l.jsx(RT,{size:12}),"Approvals"]}),l.jsxs(_l,{value:"schedules",className:"inline-flex items-center gap-1.5",children:[l.jsx(vc,{size:12}),"Schedules"]})]})]}),l.jsx(Xl,{value:"dashboard",className:"flex-1 min-h-0",children:l.jsx(HX,{})}),l.jsx(Xl,{value:"approvals",className:"flex-1 min-h-0",children:l.jsx(FX,{})}),l.jsx(Xl,{value:"schedules",className:"flex-1 min-h-0",children:l.jsx(KX,{})})]})}const eA={code:"Code",general:"General"},tA={light:"text-success",medium:"text-accent",heavy:"text-warning"};function nA(t){return t<1?`${Math.round(t*1024)} MB`:`${t} GB`}function LS({hardware:t}){if(!t)return null;const{totalRamGb:n,gpu:s,isAppleSilicon:r}=t;return l.jsxs("div",{className:"flex items-center gap-3 bg-surface-0 rounded-lg border border-border-subtle px-3 py-2.5",children:[l.jsx(sh,{size:14,className:"text-text-3 flex-shrink-0"}),l.jsx("div",{className:"flex-1 min-w-0",children:l.jsxs("div",{className:"flex items-center gap-2 text-xs font-sans",children:[l.jsxs("span",{className:"text-text-0 font-semibold",children:[n," GB RAM"]}),s&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"text-text-4",children:"·"}),l.jsx("span",{className:"text-text-2",children:s.name})]}),r&&l.jsx(ze,{variant:"accent",className:"text-2xs",children:"Unified Memory"})]})})]})}function aA({onRecheck:t}){const[n,s]=v.useState(null),[r,o]=v.useState(!1),[u,d]=v.useState(!1),[O,h]=v.useState(!1),p=D(X=>X.addToast);v.useEffect(()=>{K.post("/providers/ollama/check").then(s).catch(()=>{})},[]);async function x(){o(!0);try{const X=await K.post("/providers/ollama/check");s(X),X.installed&&X.serverRunning?(p("success","Ollama is ready!"),t()):X.installed?p("info","Ollama installed — server needs to start"):p("info","Ollama not found — install and try again")}catch{}o(!1)}async function g(){d(!0);try{if((await K.post("/providers/ollama/serve")).ok){p("success","Ollama server started!");let G=!1;for(let R=0;R<5;R++){await new Promise(T=>setTimeout(T,2e3));const _=await K.post("/providers/ollama/check");if(s(_),_.serverRunning){G=!0;break}}G&&t()}}catch(X){p("error","Could not start server",X.message)}d(!1)}function b(X){navigator.clipboard.writeText(X),h(!0),setTimeout(()=>h(!1),2e3)}if(!n)return l.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{hardware:y,install:Q,requirements:w,installed:k,serverRunning:j}=n,z=y.totalRamGb>=w.minRAM,N=y.recommended;return l.jsxs("div",{className:"space-y-3 p-3",children:[l.jsx(LS,{hardware:y}),z?l.jsxs("div",{className:"flex items-start gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2.5",children:[l.jsx(Qt,{size:14,className:"text-success flex-shrink-0 mt-0.5"}),l.jsxs("div",{className:"text-xs font-sans",children:[l.jsx("span",{className:"text-success font-semibold",children:"Your system is ready."}),l.jsx("span",{className:"text-text-2 ml-1",children:N.code?`Recommended: ${N.code}`:`${y.totalRamGb} GB RAM available`})]})]}):l.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[l.jsx(Oa,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),l.jsxs("div",{className:"text-xs font-sans text-text-2",children:[l.jsxs("span",{className:"text-warning font-semibold",children:[y.totalRamGb," GB RAM detected."]})," ","Minimum ",w.minRAM," GB needed. Smallest models may still work."]})]}),k&&!j&&l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[l.jsx(Oa,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),l.jsxs("div",{className:"text-xs font-sans text-text-2",children:[l.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."]})]}),l.jsxs(ge,{variant:"primary",size:"md",onClick:g,disabled:u,className:"w-full gap-1.5",children:[l.jsx(Xn,{size:12}),u?"Starting...":"Start Ollama Server"]})]}),!k&&l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("p",{className:"text-xs font-semibold text-text-1 font-sans",children:"Install Ollama"}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.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:Q.command}),l.jsxs(ge,{variant:"secondary",size:"sm",onClick:()=>b(Q.command),className:"h-8 px-2.5 gap-1 flex-shrink-0",children:[O?l.jsx(Qt,{size:12}):l.jsx(Sf,{size:12}),O?"Copied":"Copy"]})]}),Q.alt&&l.jsx("p",{className:"text-2xs text-text-4 font-sans",children:Q.alt})]}),l.jsxs(ge,{variant:"secondary",size:"md",onClick:x,disabled:r,className:"w-full gap-1.5",children:[l.jsx(Cn,{size:12,className:r?"animate-spin":""}),r?"Checking...":k?"Check again":"I installed it — check again"]})]})}function sA({model:t,isInstalled:n,isRecommended:s,canRun:r,onPull:o,onDelete:u,pulling:d}){const O=d===t.id;return l.jsxs("div",{className:re("flex items-center gap-2 px-3 py-2 border-t border-border-subtle transition-colors",!r&&"opacity-40"),children:[n?l.jsx(Qt,{size:12,className:"text-success flex-shrink-0"}):l.jsx("div",{className:"w-3"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("span",{className:"text-xs font-mono text-text-1 truncate",children:t.name}),s&&l.jsx(Jb,{size:10,className:"text-warning flex-shrink-0"})]}),l.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[l.jsx("span",{className:re("text-2xs font-semibold font-sans",tA[t.tier]),children:t.tier}),l.jsx("span",{className:"text-2xs text-text-4 font-sans",children:nA(t.sizeGb)}),l.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["· ",t.ramGb," GB RAM"]})]})]}),n?l.jsx("button",{onClick:()=>u(t.id),className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Remove model",children:l.jsx(_n,{size:12})}):r?l.jsx(ge,{variant:"secondary",size:"sm",onClick:()=>o(t.id),disabled:!!d,className:"h-7 px-2 text-2xs gap-1",children:O?l.jsxs(l.Fragment,{children:[l.jsx(Cn,{size:10,className:"animate-spin"})," Pulling..."]}):l.jsxs(l.Fragment,{children:[l.jsx(xi,{size:10})," Pull"]})}):l.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["Needs ",t.ramGb," GB"]})]})}function lA({onStopped:t}){const[n,s]=v.useState(null),r=D(d=>d.addToast);async function o(){s("stopping");try{(await K.post("/providers/ollama/stop")).ok?(r("info","Ollama server stopped"),t&&t()):r("error","Could not stop server")}catch(d){r("error","Stop failed",d.message)}s(null)}async function u(){s("restarting");try{(await K.post("/providers/ollama/restart")).ok?r("success","Ollama server restarted"):r("error","Restart failed")}catch(d){r("error","Restart failed",d.message)}s(null)}return l.jsxs("div",{className:"flex items-center gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2",children:[l.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[l.jsx("span",{className:"absolute inset-0 rounded-full bg-success"}),l.jsx("span",{className:"absolute inset-[-2px] rounded-full bg-success opacity-20 animate-pulse"})]}),l.jsx("span",{className:"text-xs font-sans text-success font-semibold",children:"Server Running"}),l.jsx("span",{className:"text-2xs font-mono text-text-4",children:":11434"}),l.jsx("div",{className:"flex-1"}),l.jsxs("button",{onClick:u,disabled:!!n,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-accent cursor-pointer transition-colors disabled:opacity-40",children:[l.jsx(Cn,{size:10,className:n==="restarting"?"animate-spin":""}),n==="restarting"?"Restarting...":"Restart"]}),l.jsxs("button",{onClick:o,disabled:!!n,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-danger cursor-pointer transition-colors disabled:opacity-40",children:[l.jsx(Oa,{size:10}),n==="stopping"?"Stopping...":"Stop"]})]})}function rA({onModelChange:t}){var T,Y;const[n,s]=v.useState(null),[r,o]=v.useState(null),[u,d]=v.useState("code"),[O,h]=v.useState(!1),[p,x]=v.useState(!1),g=D(M=>M.addToast),b=v.useRef(!1);function y(){K.get("/providers/ollama/models").then(M=>{var ae;s(M),!b.current&&((ae=M.installed)==null?void 0:ae.length)===0&&(b.current=!0,setTimeout(y,2e3))}).catch(()=>{})}v.useEffect(()=>{y()},[]);async function Q(M){o(M);try{await K.post("/providers/ollama/pull",{model:M}),g("success",`Pulled ${M}`),y(),t&&t()}catch(ae){g("error",`Pull failed: ${ae.message}`)}o(null)}async function w(M){try{await K.delete(`/providers/ollama/models/${encodeURIComponent(M)}`),g("info",`Removed ${M}`),y(),t&&t()}catch(ae){g("error",`Delete failed: ${ae.message}`)}}if(!n)return l.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{installed:k,catalog:j,hardware:z}=n,N=new Set(k.map(M=>M.id)),X=z.totalRamGb,G=[(T=z.recommended)==null?void 0:T.code,(Y=z.recommended)==null?void 0:Y.general].filter(Boolean),R=j.filter(M=>M.category===u),_=O?R:R.filter(M=>M.ramGb<=X);return p?l.jsxs("div",{className:"space-y-3 p-3",children:[l.jsxs("div",{className:"flex items-center gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[l.jsx(Oa,{size:14,className:"text-warning flex-shrink-0"}),l.jsxs("span",{className:"text-xs font-sans text-text-2",children:[l.jsx("span",{className:"text-warning font-semibold",children:"Ollama server stopped."})," ","Start it again to pull and use models."]})]}),l.jsxs(ge,{variant:"primary",size:"md",onClick:async()=>{try{(await K.post("/providers/ollama/serve")).ok&&(g("success","Ollama server started!"),x(!1),b.current=!1,setTimeout(y,2e3))}catch(M){g("error","Could not start server",M.message)}},className:"w-full gap-1.5",children:[l.jsx(Xn,{size:12}),"Start Ollama Server"]})]}):l.jsxs("div",{className:"space-y-2 p-3",children:[l.jsx(lA,{onStopped:()=>x(!0)}),l.jsx(LS,{hardware:z}),k.length>0&&l.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-sans text-text-2",children:[l.jsx(nh,{size:12,className:"text-text-3"}),l.jsx("span",{className:"font-semibold",children:k.length})," model",k.length!==1?"s":""," installed"]}),l.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:Object.entries(eA).map(([M,ae])=>l.jsx("button",{onClick:()=>d(M),className:re("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",u===M?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:ae},M))}),l.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[_.map(M=>l.jsx(sA,{model:M,isInstalled:N.has(M.id),isRecommended:G.includes(M.id),canRun:M.ramGb<=X,onPull:Q,onDelete:w,pulling:r},M.id)),_.length===0&&l.jsxs("div",{className:"px-3 py-4 text-center text-xs text-text-4 font-sans",children:["No ",u," models available for your hardware"]})]}),!O&&R.length>_.length&&l.jsxs("button",{onClick:()=>h(!0),className:"flex items-center gap-1 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[l.jsx(zn,{size:10}),"Show ",R.length-_.length," more (exceed your RAM)"]})]})}function DS({isInstalled:t,onModelChange:n}){const[s,r]=v.useState(!1),[o,u]=v.useState(!1);return v.useEffect(()=>{t?K.post("/providers/ollama/check").then(d=>{r(d.installed&&d.serverRunning),u(!0)}).catch(()=>u(!0)):u(!0)},[t]),o?s?l.jsx(rA,{onModelChange:n}):l.jsx(aA,{onRecheck:()=>{r(!0),n&&n()}}):l.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Checking Ollama..."})}var w0={};function iA({path:t,onNavigate:n}){const s=t.split("/").filter(Boolean);return l.jsxs("div",{className:"flex items-center gap-0.5 min-w-0 overflow-x-auto py-1.5 scrollbar-none",children:[l.jsx("button",{onClick:()=>n("/"),className:"flex-shrink-0 p-1 rounded hover:bg-surface-5 cursor-pointer text-text-3 hover:text-text-0 transition-colors",children:l.jsx(nh,{size:13})}),s.map((r,o)=>{const u="/"+s.slice(0,o+1).join("/"),d=o===s.length-1;return l.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[l.jsx(as,{size:11,className:"text-text-4"}),l.jsx("button",{onClick:()=>n(u),className:re("px-1.5 py-0.5 rounded text-xs font-mono cursor-pointer transition-colors",d?"text-text-0 bg-surface-4 font-medium":"text-text-3 hover:text-text-0 hover:bg-surface-5"),children:r})]},o)})]})}function WS({open:t,onOpenChange:n,currentPath:s,onSelect:r}){const[o,u]=v.useState(s||w0.HOME||"/"),[d,O]=v.useState([]),[h,p]=v.useState(!1),[x,g]=v.useState(null);v.useEffect(()=>{t&&b(s||"/")},[t]);async function b(k){p(!0),g(null);try{const j=await K.get(`/browse-system?path=${encodeURIComponent(k)}`);u(j.current||k),O(j.dirs||[])}catch(j){g(j.message),O([])}p(!1)}function y(){const k=o==="/"?"/":o.split("/").slice(0,-1).join("/")||"/";b(k)}function Q(){b(w0.HOME||"/Users")}function w(){r(o),n(!1)}return l.jsx(Ch,{open:t,onOpenChange:n,children:l.jsx(_h,{title:"Select Working Directory",description:"Choose a directory for this agent to work in",className:"max-w-[520px]",children:l.jsxs("div",{className:"px-5 py-4 space-y-3",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("button",{onClick:y,disabled:o==="/",className:"p-1.5 rounded-md bg-surface-4 border border-border text-text-2 hover:text-text-0 hover:bg-surface-5 transition-colors cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",children:l.jsx(j$,{size:14})}),l.jsx("button",{onClick:Q,className:"p-1.5 rounded-md bg-surface-4 border border-border text-text-2 hover:text-text-0 hover:bg-surface-5 transition-colors cursor-pointer",children:l.jsx(wT,{size:14})}),l.jsx("div",{className:"flex-1 min-w-0 bg-surface-0 rounded-md border border-border-subtle px-2",children:l.jsx(iA,{path:o,onNavigate:b})})]}),l.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle overflow-hidden",children:l.jsxs("div",{className:"max-h-[340px] overflow-y-auto",children:[h&&l.jsx("div",{className:"flex items-center justify-center py-8",children:l.jsx(Ct,{size:18,className:"text-text-3 animate-spin"})}),x&&l.jsx("div",{className:"px-4 py-6 text-center",children:l.jsx("p",{className:"text-xs text-danger font-sans",children:x})}),!h&&!x&&d.length===0&&l.jsx("div",{className:"px-4 py-6 text-center",children:l.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No subdirectories"})}),!h&&!x&&d.map(k=>l.jsxs("button",{onClick:()=>b(k.path),className:re("w-full flex items-center gap-2.5 px-3.5 py-2 text-left cursor-pointer","hover:bg-surface-4 transition-colors border-b border-border-subtle last:border-0"),children:[k.hasChildren?l.jsx(fT,{size:15,className:"text-warning flex-shrink-0"}):l.jsx(li,{size:15,className:"text-text-3 flex-shrink-0"}),l.jsx("span",{className:"text-sm text-text-0 font-sans truncate flex-1",children:k.name}),k.hasChildren&&l.jsx(as,{size:12,className:"text-text-4 flex-shrink-0"})]},k.path))]})}),l.jsxs("div",{className:"flex items-center gap-3 bg-surface-4/50 rounded-lg px-3.5 py-2.5 border border-border-subtle",children:[l.jsx(li,{size:16,className:"text-accent flex-shrink-0"}),l.jsx("span",{className:"text-xs font-mono text-text-1 truncate flex-1",children:o})]}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsx(ge,{variant:"ghost",size:"md",onClick:()=>n(!1),children:"Cancel"}),l.jsxs(ge,{variant:"primary",size:"md",onClick:w,className:"gap-1.5",children:[l.jsx(Qt,{size:14})," Select Folder"]})]})]})})})}function BS({children:t,...n}){return l.jsx(ZS,{...n,children:t})}function HS({children:t,className:n,title:s,side:r="right",width:o=400,...u}){return l.jsxs(ES,{children:[l.jsx(qS,{className:"fixed inset-0 z-40 bg-black/30"}),l.jsxs(MS,{className:re("fixed top-0 z-50 h-full overflow-y-auto","bg-surface-1 border-l border-border shadow-2xl","data-[state=open]:animate-in data-[state=closed]:animate-out",r==="right"&&"right-0 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right",r==="left"&&"left-0 data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left",n),style:{width:o},...u,children:[s&&l.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border-subtle sticky top-0 bg-surface-1 z-10",children:[l.jsx(YS,{className:"text-base font-semibold text-text-0 font-sans",children:s}),l.jsx(VS,{className:"p-1 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-5 transition-colors cursor-pointer",children:l.jsx(jt,{size:16})})]}),l.jsx(US,{className:"sr-only",children:"Panel"}),t]})]})}function oA({value:t,onChange:n}){return l.jsx("button",{onClick:()=>n(!t),className:re("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer",t?"bg-accent":"bg-surface-5"),children:l.jsx("div",{className:re("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",t?"translate-x-4":"translate-x-0")})})}function cA({user:t}){const[n,s]=v.useState(!1),r=(t==null?void 0:t.avatar)||(t==null?void 0:t.picture)||(t==null?void 0:t.photoURL)||(t==null?void 0:t.photo);return r&&!n?l.jsx("img",{src:r,alt:"",className:"w-6 h-6 rounded-full",referrerPolicy:"no-referrer",crossOrigin:"anonymous",onError:()=>s(!0)}):l.jsx("div",{className:"w-6 h-6 rounded-full bg-accent/10 flex items-center justify-center",children:l.jsx(ev,{size:12,className:"text-accent"})})}function uA({provider:t,onKeyChange:n}){var k,j,z;const[s,r]=v.useState(!1),[o,u]=v.useState(""),[d,O]=v.useState(!1),[h,p]=v.useState(!1),x=D(N=>N.addToast),g=t.authType==="local",b=t.authType==="subscription",y=g||b?t.installed:t.hasKey;async function Q(){if(o.trim())try{await K.post(`/credentials/${t.id}`,{key:o.trim()}),x("success",`API key set for ${t.name}`),u(""),r(!1),n&&n()}catch(N){x("error","Failed to set key",N.message)}}async function w(){try{await K.delete(`/credentials/${t.id}`),x("info",`Removed ${t.name} key`),n&&n()}catch(N){x("error","Remove failed",N.message)}}if(g){const N=((j=(k=t.models)==null?void 0:k.filter(G=>!G.disabled))==null?void 0:j.length)||0,X=()=>D.getState().setActiveView("models");return l.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[l.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[l.jsx(zs,{status:y&&N>0?"running":"crashed",size:"sm"}),l.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:t.name}),l.jsx("div",{className:"flex-1"}),y&&N>0?l.jsxs(ze,{variant:"success",className:"text-2xs gap-1",children:[l.jsx(Qt,{size:8})," ",N," models"]}):y?l.jsx(ze,{variant:"warning",className:"text-2xs",children:"No models pulled"}):l.jsx(ze,{variant:"default",className:"text-2xs",children:"Not set up"})]}),l.jsx("div",{className:"flex-1",children:h?l.jsxs(l.Fragment,{children:[l.jsx(DS,{isInstalled:y,onModelChange:n}),l.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle flex gap-2",children:[l.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>p(!1),className:"flex-1 h-7 text-2xs",children:"Back"}),l.jsx(ge,{variant:"secondary",size:"sm",onClick:()=>{p(!1),X()},className:"flex-1 h-7 text-2xs gap-1",children:"Models Tab"})]})]}):l.jsxs("div",{className:"px-4 py-3 flex flex-col h-full",children:[l.jsx("div",{className:"text-xs text-text-3 font-sans flex-1",children:y&&N>0?"Full agentic runtime — tool calling, context rotation, zero cloud cost":y?"Ollama is running. Pull a model to start using local agents.":"Run any open-source model locally — free, private, fully offline. Requires Ollama."}),l.jsxs("div",{className:"flex gap-2 mt-3",children:[y?l.jsxs(ge,{variant:"primary",size:"sm",onClick:()=>p(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[l.jsx(Ml,{size:11})," ",N>0?"Manage":"Pull Models"]}):l.jsxs(ge,{variant:"primary",size:"sm",onClick:()=>p(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[l.jsx(Ml,{size:11})," Set Up Ollama"]}),l.jsx(ge,{variant:"secondary",size:"sm",onClick:X,className:"flex-1 h-7 text-2xs gap-1.5",children:"Models Tab"})]})]})})]})}return l.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[l.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[l.jsx(zs,{status:y?"running":"crashed",size:"sm"}),l.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:t.name}),l.jsx("div",{className:"flex-1"}),y?l.jsxs(ze,{variant:"success",className:"text-2xs gap-1",children:[l.jsx(Qt,{size:8})," Ready"]}):l.jsx(ze,{variant:"default",className:"text-2xs",children:b?"Not installed":"No key"})]}),l.jsxs("div",{className:"flex-1 flex flex-col px-4 py-3 min-h-[120px]",children:[((z=t.models)==null?void 0:z.length)>0&&l.jsx("div",{className:"flex flex-wrap gap-1 mb-3",children:t.models.map(N=>l.jsx("span",{className:"px-1.5 py-0.5 rounded bg-surface-4 text-2xs font-mono text-text-3",children:N.name||N.id},N.id))}),b&&y&&!t.hasKey&&!s&&l.jsxs("div",{className:"flex items-center gap-1.5 h-8 px-2.5 bg-accent/8 border border-accent/20 rounded-md text-2xs font-sans text-accent mb-3",children:[l.jsx(Qt,{size:10})," Subscription active"]}),t.hasKey&&!s&&l.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[l.jsxs("div",{className:"flex-1 flex items-center gap-1.5 h-8 px-2.5 bg-success/8 border border-success/20 rounded-md text-2xs font-sans text-success",children:[l.jsx(Qt,{size:10})," API Connected"]}),l.jsx("button",{onClick:()=>{r(!0),O(!1),u("")},className:"text-2xs text-text-4 hover:text-accent cursor-pointer font-sans",children:"Edit"}),l.jsx("button",{onClick:w,className:"text-2xs text-text-4 hover:text-danger cursor-pointer font-sans",children:"Remove"})]}),l.jsx("div",{className:"flex-1"}),s&&l.jsxs("div",{className:"space-y-2.5 pt-1",children:[l.jsxs("div",{children:[l.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:t.hasKey?"Update API Key":`${t.name} API Key`}),l.jsxs("div",{className:"relative",children:[l.jsx("input",{value:o,onChange:N=>u(N.target.value),onKeyDown:N=>N.key==="Enter"&&Q(),type:d?"text":"password",placeholder:"sk-...",className:"w-full h-9 px-3 pr-9 text-xs 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}),l.jsx("button",{onClick:()=>O(!d),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:d?l.jsx(Dc,{size:12}):l.jsx(Es,{size:12})})]})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ge,{variant:"primary",size:"sm",onClick:Q,disabled:!o.trim(),className:"flex-1 h-8 text-xs",children:"Save Key"}),l.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>{r(!1),u("")},className:"h-8 text-xs px-3",children:"Cancel"})]})]}),!s&&!t.hasKey&&l.jsxs(ge,{variant:b?"secondary":"primary",size:"sm",onClick:()=>{r(!0),O(!1),u("")},className:"w-full h-8 text-2xs gap-1.5 mt-2",children:[l.jsx(ri,{size:11}),b?"Add API key for headless mode":"Add API Key"]})]})]})}function $l({icon:t,label:n,description:s,children:r}){return l.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-4 py-3.5 flex flex-col gap-2",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("div",{className:"w-6 h-6 rounded bg-accent/8 flex items-center justify-center flex-shrink-0",children:l.jsx(t,{size:12,className:"text-accent"})}),l.jsx("div",{className:"text-[13px] font-medium text-text-0 font-sans leading-tight",children:n})]}),l.jsx("div",{className:"text-2xs text-text-4 font-sans leading-relaxed",children:s}),l.jsx("div",{className:"mt-auto pt-1",children:r})]})}const IS={telegram:rh,discord:gi,slack:Gb},$s={telegram:"Telegram",discord:"Discord",slack:"Slack"},dA={telegram:"Bot token from @BotFather",discord:"Bot token from Developer Portal",slack:"Bot token (xoxb-...)"},OA=["critical","lifecycle","all"];function fA({type:t,open:n,onOpenChange:s}){if(!t)return null;const o={telegram:{title:"Set Up Telegram",icon:rh,intro:"Create a Telegram bot and connect it to Groove in under 2 minutes. No dependencies required.",sections:[{title:"Create Your Bot",steps:[{text:"Open Telegram on any device and search for",link:"https://t.me/BotFather",linkText:"@BotFather"},{text:"Send /newbot to start the setup"},{text:"Choose a display name — we suggest GroovePilot"},{text:'Choose a username (must end in "bot") — e.g. GroovePilot_bot'},{text:"BotFather will reply with your bot token — copy it"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Telegram card"},{text:"Paste your bot token and click Save"},{text:"The gateway will connect automatically"}]},{title:"Link a Chat",steps:[{text:"Open a chat with your new bot in Telegram"},{text:'Send any message (e.g. "hello") — Groove captures the chat ID automatically'},{text:"Click Test in the gateway card to verify"}]},{title:"Commands",note:"All commands use / prefix in Telegram:",commands:["/instruct <team> <msg>","/query <team> <question>","/plan <description>","/log <team>","/brief","/tokens","/status","/agents","/help"]}]},discord:{title:"Set Up Discord",icon:gi,intro:"Create a Discord bot and add it to your server. Requires discord.js (installed automatically with Groove).",sections:[{title:"Create the Application",steps:[{text:"Go to the",link:"https://discord.com/developers/applications",linkText:"Discord Developer Portal"},{text:"Click New Application and name it GroovePilot"},{text:"Go to the Bot tab in the left sidebar"},{text:"Click Reset Token and copy the bot token"}]},{title:"Set Permissions & Invite",steps:[{text:"Go to OAuth2 > URL Generator"},{text:"Under Scopes, check bot"},{text:"Under Bot Permissions, check:"}],scopes:["Send Messages","Read Message History","Embed Links","Use External Emojis"],after:[{text:"Copy the generated URL at the bottom and open it in your browser"},{text:"Select your server and click Authorize"}]},{title:"Enable Message Content Intent",steps:[{text:"Go back to the Bot tab in the Developer Portal"},{text:"Scroll to Privileged Gateway Intents"},{text:"Enable Message Content Intent — required for the bot to read commands"},{text:"Click Save Changes"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Discord card"},{text:"Paste your bot token and click Save"},{text:"Send a message in any channel where the bot is — Groove captures the channel automatically"}]},{title:"Commands",note:"All commands use / prefix in Discord:",commands:["/instruct <team> <msg>","/query <team> <question>","/plan <description>","/log <team>","/brief","/tokens","/status","/agents","/help"]}]},slack:{title:"Set Up Slack",icon:Gb,intro:"Create a Slack app with Socket Mode — no public URL needed. Requires @slack/bolt (installed automatically with Groove).",sections:[{title:"Create the App",steps:[{text:"Go to",link:"https://api.slack.com/apps",linkText:"api.slack.com/apps"},{text:"Click Create New App > From scratch"},{text:"Name it GroovePilot and select your workspace"}]},{title:"Enable Socket Mode",steps:[{text:"In the left sidebar, go to Settings > Socket Mode"},{text:"Toggle Enable Socket Mode to on"},{text:"It will ask you to create an App-Level Token"},{text:'Name it "groove", add the connections:write scope'},{text:"Click Generate — copy the xapp-... token (this is your App Token)"}],important:"Save this token now — you can't view it again after closing the dialog."},{title:"Set Bot Token Scopes",steps:[{text:"Go to Features > OAuth & Permissions"},{text:"Scroll to Bot Token Scopes and add all of these:"}],scopes:["chat:write","channels:read","channels:history","groups:read","groups:history","im:history","app_mentions:read"],after:[{text:"Scroll up and click Install to Workspace"},{text:"Click Allow to grant permissions"},{text:"Copy the Bot User OAuth Token (xoxb-...) — this is your Bot Token"}]},{title:"Enable Events",steps:[{text:"Go to Features > Event Subscriptions"},{text:"Toggle Enable Events to on"},{text:"Under Subscribe to bot events, add:"}],scopes:["message.channels","message.im","app_mention"],after:[{text:"Click Save Changes at the bottom"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Slack card"},{text:"Paste your Bot Token (xoxb-...) in the first field"},{text:"Paste your App Token (xapp-...) in the second field"},{text:"Click Save — Groove will auto-connect"}]},{title:"Link a Channel",steps:[{text:"Invite the bot to a channel: /invite @GroovePilot"},{text:"Select the channel from the dropdown in the gateway card"},{text:"Or @mention the bot — it will auto-capture the channel"},{text:"Click Test to verify"}],important:"For private channels, make sure you added the groups:read scope."},{title:"Commands",note:"In Slack, use plain text commands (no / prefix) or @mention the bot:",commands:["instruct <team> <msg>","query <team> <question>","plan <description>","log <team>","brief","tokens","status","agents","help","@GroovePilot status"]}]}}[t];if(!o)return null;const u=o.icon;return l.jsx(BS,{open:n,onOpenChange:s,children:l.jsx(HS,{title:o.title,width:480,children:l.jsxs("div",{className:"px-5 py-4 space-y-5",children:[l.jsxs("div",{className:"flex items-start gap-3 p-3 bg-accent/5 border border-accent/15 rounded-lg",children:[l.jsx("div",{className:"w-8 h-8 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:l.jsx(u,{size:16,className:"text-accent"})}),l.jsx("p",{className:"text-xs text-text-2 font-sans leading-relaxed",children:o.intro})]}),o.sections.map((d,O)=>{var h;return l.jsxs("div",{children:[l.jsxs("h3",{className:"text-xs font-semibold text-text-0 font-sans mb-2.5 flex items-center gap-2",children:[l.jsx("span",{className:"w-5 h-5 rounded-full bg-accent/10 flex items-center justify-center text-2xs font-bold text-accent",children:O+1}),d.title]}),d.note&&l.jsx("p",{className:"text-2xs text-text-3 font-sans mb-2",children:d.note}),d.steps&&l.jsx("ol",{className:"space-y-2 mb-2",children:d.steps.map((p,x)=>l.jsxs("li",{className:"flex gap-2 text-2xs text-text-2 font-sans leading-relaxed",children:[l.jsxs("span",{className:"text-text-4 font-mono w-4 flex-shrink-0 pt-px",children:[x+1,"."]}),l.jsxs("span",{children:[p.text,p.link&&l.jsxs(l.Fragment,{children:[" ",l.jsxs("a",{href:p.link,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline inline-flex items-center gap-0.5 font-medium",children:[p.linkText,l.jsx(si,{size:9})]})]})]})]},x))}),d.scopes&&l.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2 ml-6",children:d.scopes.map(p=>l.jsx("code",{className:"px-2 py-0.5 rounded bg-surface-4 text-2xs font-mono text-accent",children:p},p))}),d.after&&l.jsx("ol",{className:"space-y-2 mb-2",start:(((h=d.steps)==null?void 0:h.length)||0)+1,children:d.after.map((p,x)=>{var g;return l.jsxs("li",{className:"flex gap-2 text-2xs text-text-2 font-sans leading-relaxed",children:[l.jsxs("span",{className:"text-text-4 font-mono w-4 flex-shrink-0 pt-px",children:[(((g=d.steps)==null?void 0:g.length)||0)+x+1,"."]}),l.jsx("span",{children:p.text})]},x)})}),d.important&&l.jsx("div",{className:"ml-6 p-2 bg-warning/8 border border-warning/20 rounded-md text-2xs text-warning font-sans",children:d.important}),d.commands&&l.jsx("div",{className:"ml-6 p-2.5 bg-surface-0 border border-border-subtle rounded-md space-y-1",children:d.commands.map(p=>l.jsx("code",{className:"block text-2xs font-mono text-text-1",children:p},p))})]},O)}),l.jsxs("a",{href:"https://docs.groovedev.ai/guide/gateways",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium mt-2",children:[l.jsx(si,{size:10}),"Full documentation at docs.groovedev.ai"]})]})})})}function hA({gateway:t,onRefresh:n}){var se,ie;const[s,r]=v.useState(!1),[o,u]=v.useState(""),[d,O]=v.useState(""),[h,p]=v.useState(!1),[x,g]=v.useState(!1),[b,y]=v.useState(!1),[Q,w]=v.useState([]),[k,j]=v.useState(!1),z=D(W=>W.addToast);v.useEffect(()=>{t.connected&&!t.chatId&&t.type==="slack"&&K.get(`/gateways/${t.id}/channels`).then(W=>w(Array.isArray(W)?W:[])).catch(()=>{})},[t.connected,t.chatId,t.id,t.type]);const N=IS[t.type]||lh,X=t.type==="slack";async function G(){if(o.trim())try{await K.post(`/gateways/${t.id}/credentials`,{key:"bot_token",value:o.trim()}),X&&d.trim()&&await K.post(`/gateways/${t.id}/credentials`,{key:"app_token",value:d.trim()}),z("success","Token saved — connecting..."),u(""),O(""),r(!1);try{await K.post(`/gateways/${t.id}/connect`),z("success",`${$s[t.type]} connected!`)}catch(W){z("error","Token saved but connect failed",W.message)}n()}catch(W){z("error","Failed to save token",W.message)}}async function R(){g(!0);try{await K.post(`/gateways/${t.id}/test`),z("success","Test message sent!")}catch(W){z("error","Test failed",W.message)}g(!1)}async function _(){y(!0);try{t.connected?(await K.post(`/gateways/${t.id}/disconnect`),z("info",`${$s[t.type]} disconnected`)):(await K.post(`/gateways/${t.id}/connect`),z("success",`${$s[t.type]} connected!`)),n()}catch(W){z("error",t.connected?"Disconnect failed":"Connect failed",W.message)}y(!1)}async function T(W){try{await K.patch(`/gateways/${t.id}`,{enabled:W}),n()}catch(P){z("error","Update failed",P.message)}}async function Y(W){try{await K.patch(`/gateways/${t.id}`,{notifications:{preset:W}}),n()}catch(P){z("error","Update failed",P.message)}}async function M(W){try{await K.patch(`/gateways/${t.id}`,{commandPermission:W}),n()}catch(P){z("error","Update failed",P.message)}}async function ae(){try{await K.delete(`/gateways/${t.id}`),z("info",`${$s[t.type]} gateway removed`),n()}catch(W){z("error","Delete failed",W.message)}}const F=((se=t.notifications)==null?void 0:se.preset)||"critical";return l.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[l.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[l.jsx(zs,{status:t.connected?"running":"crashed",size:"sm"}),l.jsx(N,{size:13,className:"text-text-2"}),l.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:$s[t.type]}),l.jsx("div",{className:"flex-1"}),t.connected?l.jsxs(ze,{variant:"success",className:"text-2xs gap-1",children:[l.jsx(c1,{size:8})," Connected"]}):t.enabled?l.jsx(ze,{variant:"warning",className:"text-2xs",children:"Disconnected"}):l.jsx(ze,{variant:"default",className:"text-2xs",children:"Disabled"})]}),l.jsxs("div",{className:"flex-1 flex flex-col px-4 py-3 min-h-[140px]",children:[t.connected&&!s&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"flex items-center gap-1.5 h-8 px-2.5 bg-success/8 border border-success/20 rounded-md text-2xs font-sans text-success mb-3",children:[l.jsx(Qt,{size:10})," Gateway active",t.botUsername&&l.jsxs("span",{className:"text-text-4 ml-1",children:["@",t.botUsername]}),t.botTag&&l.jsx("span",{className:"text-text-4 ml-1",children:t.botTag})]}),l.jsxs("div",{className:"mb-3",children:[l.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:t.type==="slack"?"Channel":"Chat ID"}),t.chatId?l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("code",{className:"flex-1 flex items-center h-7 px-2 bg-surface-0 border border-border-subtle rounded-md text-2xs font-mono text-text-2",children:t.type==="slack"&&Q.length>0?`#${((ie=Q.find(W=>W.id===t.chatId))==null?void 0:ie.name)||t.chatId}`:t.chatId}),l.jsx("button",{onClick:async()=>{try{await K.patch(`/gateways/${t.id}`,{chatId:null}),n()}catch(W){z("error","Failed",W.message)}},className:"text-2xs text-text-4 hover:text-text-1 cursor-pointer font-sans",children:"Change"})]}):t.type==="slack"&&Q.length>0?l.jsxs("select",{onChange:async W=>{if(W.target.value)try{await K.patch(`/gateways/${t.id}`,{chatId:W.target.value}),n()}catch(P){z("error","Failed to set channel",P.message)}},className:"w-full h-7 px-2 text-2xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer",defaultValue:"",children:[l.jsx("option",{value:"",disabled:!0,children:"Select a channel..."}),Q.map(W=>l.jsxs("option",{value:W.id,children:["#",W.name]},W.id))]}):l.jsxs("div",{className:"text-2xs text-warning font-sans",children:[t.type==="slack"?"No channels found — invite the bot to a channel first.":"Send a message to the bot to auto-capture, or enter manually:",l.jsx("input",{placeholder:t.type==="slack"?"C0123456789":"Chat ID",className:"mt-1 w-full h-7 px-2 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",onKeyDown:async W=>{if(W.key==="Enter"&&W.target.value.trim())try{await K.patch(`/gateways/${t.id}`,{chatId:W.target.value.trim()}),n()}catch(P){z("error","Failed to set channel",P.message)}}})]})]}),l.jsxs("div",{className:"mb-3",children:[l.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:"Notifications"}),l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:OA.map(W=>l.jsx("button",{onClick:()=>Y(W),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer capitalize",F===W?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:W},W))})]}),l.jsxs("div",{className:"mb-3",children:[l.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:"Commands"}),l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:["full","read-only"].map(W=>l.jsx("button",{onClick:()=>M(W),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer capitalize",(t.commandPermission||"full")===W?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:W==="full"?"Full Access":"Read Only"},W))})]})]}),!t.connected&&!s&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"text-xs text-text-3 font-sans mb-2",children:t.enabled?t.hasCredentials?"Tokens saved — click Connect.":"Configure bot token to connect.":"Gateway is disabled."}),!t.hasCredentials&&l.jsxs("button",{onClick:()=>j(!0),className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer mb-2",children:[l.jsx(yc,{size:11}),"How to set up",l.jsx(si,{size:9})]})]}),l.jsx(fA,{type:t.type,open:k,onOpenChange:j}),l.jsx("div",{className:"flex-1"}),s&&l.jsxs("div",{className:"space-y-2.5 pt-1",children:[l.jsxs("button",{onClick:()=>j(!0),className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer",children:[l.jsx(yc,{size:11}),"Where do I get these?"]}),l.jsxs("div",{children:[l.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:"Bot Token"}),l.jsxs("div",{className:"relative",children:[l.jsx("input",{value:o,onChange:W=>u(W.target.value),onKeyDown:W=>W.key==="Enter"&&!X&&G(),type:h?"text":"password",placeholder:dA[t.type],className:"w-full h-9 px-3 pr-9 text-xs 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}),l.jsx("button",{onClick:()=>p(!h),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:h?l.jsx(Dc,{size:12}):l.jsx(Es,{size:12})})]})]}),X&&l.jsxs("div",{children:[l.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:"App Token (Socket Mode)"}),l.jsx("input",{value:d,onChange:W=>O(W.target.value),onKeyDown:W=>W.key==="Enter"&&G(),type:h?"text":"password",placeholder:"xapp-...",className:"w-full h-9 px-3 text-xs 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"})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ge,{variant:"primary",size:"sm",onClick:G,disabled:!o.trim(),className:"flex-1 h-8 text-xs",children:"Save Token"}),l.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>{r(!1),u(""),O("")},className:"h-8 text-xs px-3",children:"Cancel"})]})]}),!s&&l.jsxs("div",{className:"flex gap-2 mt-2",children:[!t.connected&&l.jsxs(ge,{variant:"primary",size:"sm",onClick:()=>r(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[l.jsx(ri,{size:11}),t.enabled?"Set Token":"Configure"]}),t.connected&&l.jsxs(l.Fragment,{children:[l.jsxs(ge,{variant:"secondary",size:"sm",onClick:R,disabled:x,className:"flex-1 h-7 text-2xs gap-1.5",children:[l.jsx(oh,{size:11}),x?"Sending...":"Test"]}),l.jsx(ge,{variant:"secondary",size:"sm",onClick:()=>r(!0),className:"h-7 text-2xs px-2.5",children:l.jsx(ri,{size:11})})]}),l.jsx(ge,{variant:"ghost",size:"sm",onClick:_,disabled:b,className:"h-7 text-2xs px-2.5",title:t.connected?"Disconnect":"Connect",children:t.connected?l.jsx(Wb,{size:11}):l.jsx(c1,{size:11})}),l.jsx(oA,{value:t.enabled,onChange:T}),l.jsx("button",{onClick:ae,className:"text-text-4 hover:text-danger cursor-pointer p-1",title:"Remove gateway",children:l.jsx(_n,{size:11})})]})]})]})}function mA({existingTypes:t,onAdd:n}){const[s,r]=v.useState(!1),o=["telegram","discord","slack"].filter(u=>!t.includes(u));return o.length===0?null:s?l.jsxs("div",{className:"flex flex-col rounded-lg border border-accent/30 bg-surface-1 overflow-hidden min-w-[220px]",children:[l.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[l.jsx(lh,{size:13,className:"text-accent"}),l.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:"Add Gateway"}),l.jsx("div",{className:"flex-1"}),l.jsx("button",{onClick:()=>r(!1),className:"text-text-4 hover:text-text-1 cursor-pointer",children:l.jsx(jt,{size:12})})]}),l.jsx("div",{className:"p-3 space-y-2",children:o.map(u=>{const d=IS[u];return l.jsxs("button",{onClick:()=>{n(u),r(!1)},className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-0 hover:bg-accent/8 border border-border-subtle hover:border-accent/20 cursor-pointer transition-all group",children:[l.jsx(d,{size:14,className:"text-text-3 group-hover:text-accent"}),l.jsx("span",{className:"text-xs font-medium text-text-1 group-hover:text-accent font-sans",children:$s[u]})]},u)})})]}):l.jsxs("button",{onClick:()=>r(!0),className:"flex flex-col items-center justify-center rounded-lg border border-dashed border-border-subtle bg-surface-1/50 hover:bg-surface-1 hover:border-accent/30 min-h-[140px] min-w-[220px] cursor-pointer transition-all group",children:[l.jsx("div",{className:"w-8 h-8 rounded-full bg-accent/8 group-hover:bg-accent/15 flex items-center justify-center mb-2 transition-colors",children:l.jsx(es,{size:14,className:"text-accent"})}),l.jsx("span",{className:"text-2xs font-semibold text-text-3 group-hover:text-text-1 font-sans transition-colors",children:"Add Gateway"})]})}function pA(){const[t,n]=v.useState([]),[s,r]=v.useState(null),[o,u]=v.useState(null),[d,O]=v.useState([]),[h,p]=v.useState(!0),[x,g]=v.useState(!1),b=D(_=>_.addToast),y=D(_=>_.marketplaceUser),Q=D(_=>_.marketplaceAuthenticated),w=D(_=>_.marketplaceLogin),k=D(_=>_.marketplaceLogout);function j(){K.get("/providers").then(_=>n(Array.isArray(_)?_:[])).catch(()=>{})}function z(){K.get("/gateways").then(_=>O(Array.isArray(_)?_:[])).catch(()=>{})}v.useEffect(()=>{Promise.all([K.get("/providers"),K.get("/config"),K.get("/status"),K.get("/gateways")]).then(([_,T,Y,M])=>{n(Array.isArray(_)?_:[]),r(T),u(Y),O(Array.isArray(M)?M:[]),p(!1)}).catch(()=>p(!1))},[]);async function N(_){try{await K.post("/gateways",{type:_}),b("success",`${$s[_]} gateway added`),z()}catch(T){b("error","Failed to add gateway",T.message)}}async function X(_,T){try{const Y=await K.patch("/config",{[_]:T});r(Y)}catch(Y){b("error","Update failed",Y.message)}}if(h)return l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsx("div",{className:"h-12 bg-surface-1 border-b border-border"}),l.jsxs("div",{className:"flex-1 p-4 space-y-4",children:[l.jsx("div",{className:"grid grid-cols-4 gap-3",children:[...Array(4)].map((_,T)=>l.jsx(on,{className:"h-40 rounded-lg"},T))}),l.jsx("div",{className:"grid grid-cols-3 gap-3",children:[...Array(6)].map((_,T)=>l.jsx(on,{className:"h-28 rounded-lg"},T))})]})]});const G=t.filter(_=>_.authType==="local"||_.authType==="subscription"?_.installed:_.hasKey).length,R=(s==null?void 0:s.rotationThreshold)||0;return l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsxs("div",{className:"flex items-center gap-4 px-4 py-2.5 bg-surface-1 border-b border-border flex-shrink-0",children:[l.jsx("h2",{className:"text-sm font-semibold text-text-0 font-sans",children:"Settings"}),l.jsx("div",{className:"flex-1"}),l.jsxs("div",{className:"flex items-center gap-4 text-2xs text-text-3 font-sans",children:[(o==null?void 0:o.version)&&l.jsxs("span",{children:["v",o.version]}),(o==null?void 0:o.port)&&l.jsxs("span",{children:[":",o.port]}),(o==null?void 0:o.uptime)>0&&l.jsxs("span",{children:["Up ",Hc(o.uptime)]})]}),l.jsx("div",{className:"w-px h-4 bg-border-subtle"}),Q?l.jsxs("div",{className:"flex items-center gap-2.5",children:[l.jsx(cA,{user:y}),l.jsx("span",{className:"text-xs font-medium text-text-0 font-sans",children:(y==null?void 0:y.displayName)||"User"}),l.jsxs("button",{onClick:k,className:"text-2xs text-text-4 hover:text-text-1 cursor-pointer font-sans flex items-center gap-1",children:[l.jsx(Vb,{size:10})," Sign out"]})]}):l.jsxs(ge,{variant:"ghost",size:"sm",onClick:w,className:"h-7 text-2xs gap-1.5 text-text-3",children:[l.jsx(ah,{size:11})," Sign in"]}),l.jsx(zs,{status:"running",size:"sm"})]}),l.jsx(ma,{className:"flex-1",children:l.jsxs("div",{className:"p-4 space-y-4",children:[l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[l.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Providers"}),l.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),l.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:[G,"/",t.length," connected"]})]}),l.jsx("div",{className:"grid grid-cols-4 gap-3",children:t.map(_=>l.jsx(uA,{provider:_,onKeyChange:j},_.id))})]}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[l.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Gateways"}),l.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),l.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:[d.filter(_=>_.connected).length,"/",d.length," connected"]})]}),l.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[d.map(_=>l.jsx(hA,{gateway:_,onRefresh:z},_.id)),l.jsx(mA,{existingTypes:d.map(_=>_.type),onAdd:N})]})]}),s&&l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[l.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Configuration"}),l.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),l.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Auto-saves"})]}),l.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[l.jsx($l,{icon:Ml,label:"Default Provider",description:"Provider used when spawning new agents.",children:l.jsx("select",{value:s.defaultProvider||"claude-code",onChange:_=>X("defaultProvider",_.target.value),className:"w-full h-8 px-2.5 text-xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer",children:t.filter(_=>_.installed||_.hasKey).map(_=>l.jsx("option",{value:_.id,children:_.name},_.id))})}),l.jsx($l,{icon:li,label:"Working Directory",description:"Default root directory for new agents.",children:l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("code",{className:"flex-1 h-8 px-2 flex items-center bg-surface-0 border border-border-subtle rounded-md text-2xs font-mono text-text-2 truncate min-w-0",children:s.defaultWorkingDir||"Project root"}),l.jsx(ge,{variant:"secondary",size:"sm",onClick:()=>g(!0),className:"h-8 px-2 flex-shrink-0",children:l.jsx(qb,{size:12})})]})}),l.jsx($l,{icon:Yb,label:"Rotation Threshold",description:"Context usage that triggers auto-rotation.",children:l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:["auto","50%","65%","75%","85%"].map(_=>{const T=_==="auto"?0:parseInt(_,10)/100,Y=R===T;return l.jsx("button",{onClick:()=>X("rotationThreshold",T),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",Y?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:_==="auto"?"Auto":_},_)})})}),l.jsx($l,{icon:Kb,label:"QC Threshold",description:"Running agents count that triggers auto-QC.",children:l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[2,3,4,6,8].map(_=>{const T=(s.qcThreshold||2)===_;return l.jsx("button",{onClick:()=>X("qcThreshold",_),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",T?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:_},_)})})}),l.jsx($l,{icon:yi,label:"Max Agents",description:"Concurrent agent limit. 0 = unlimited.",children:l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[0,4,8,12,20].map(_=>{const T=(s.maxAgents||0)===_;return l.jsx("button",{onClick:()=>X("maxAgents",_),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",T?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:_===0?"∞":_},_)})})}),l.jsx($l,{icon:ii,label:"Journalist Interval",description:"Seconds between synthesis cycles.",children:l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[60,120,300,600].map(_=>{const T=(s.journalistInterval||120)===_,Y=_<60?`${_}s`:`${_/60}m`;return l.jsx("button",{onClick:()=>X("journalistInterval",_),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",T?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:Y},_)})})})]})]})]})}),l.jsx(WS,{open:x,onOpenChange:g,currentPath:(s==null?void 0:s.defaultWorkingDir)||"/",onSelect:_=>X("defaultWorkingDir",_)})]})}function Xc(t){return t?t<1024*1024?`${(t/1024).toFixed(0)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(2)} GB`:"—"}function xA(t){return t?t<1024*1024?`${(t/1024).toFixed(0)} KB/s`:`${(t/(1024*1024)).toFixed(1)} MB/s`:""}function gA({hardware:t}){var n;return t?l.jsxs("div",{className:"flex items-center gap-4 px-4 py-2.5 bg-surface-1 border border-border-subtle rounded-lg text-xs font-sans text-text-2",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(YT,{size:14,className:"text-text-3"}),l.jsxs("span",{children:[t.totalRamGb," GB RAM"]})]}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(Ml,{size:14,className:"text-text-3"}),l.jsxs("span",{children:[t.cores," cores"]})]}),t.gpu&&l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(nh,{size:14,className:"text-text-3"}),l.jsxs("span",{children:[t.gpu.name,t.gpu.vram?` (${t.gpu.vram} GB)`:""]})]}),((n=t.recommended)==null?void 0:n.code)&&l.jsxs("div",{className:"ml-auto text-accent",children:["Recommended: ",t.recommended.code]})]}):null}function bA({download:t}){const n=Math.round((t.percent||0)*100);return l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex items-center justify-between text-2xs font-sans text-text-3",children:[l.jsx("span",{children:t.filename}),l.jsxs("span",{children:[n,"% ",xA(t.speed)]})]}),l.jsx("div",{className:"h-1.5 bg-surface-3 rounded-full overflow-hidden",children:l.jsx("div",{className:"h-full bg-accent rounded-full transition-all",style:{width:`${n}%`}})}),l.jsxs("div",{className:"text-2xs text-text-4",children:[Xc(t.downloaded)," / ",Xc(t.totalBytes)]})]})}function vA({model:t,onDelete:n}){const[s,r]=v.useState(!1),o={light:"text-green-400",medium:"text-blue-400",heavy:"text-orange-400"};return l.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-surface-1 border border-border-subtle rounded-lg",children:[l.jsx(th,{size:18,className:"text-accent flex-shrink-0"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate",children:t.id}),t.quantization&&l.jsx(ze,{variant:"subtle",className:"text-2xs",children:t.quantization}),t.parameters&&l.jsx(ze,{variant:"subtle",className:"text-2xs",children:t.parameters}),l.jsx("span",{className:re("text-2xs font-medium capitalize",o[t.tier]||"text-text-3"),children:t.tier})]}),l.jsxs("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:[Xc(t.sizeBytes)," · ctx ",(t.contextWindow||0).toLocaleString()," · ",t.category,t.repoId&&l.jsxs("span",{className:"text-text-4",children:[" · ",t.repoId]})]})]}),l.jsx("button",{onClick:async()=>{r(!0),await n(t.id),r(!1)},disabled:s,className:"p-1.5 rounded-md text-text-4 hover:text-red-400 hover:bg-red-400/10 transition-colors",children:s?l.jsx(Ct,{size:14,className:"animate-spin"}):l.jsx(_n,{size:14})})]})}function yA({result:t,onExpand:n,expanded:s}){var r;return l.jsxs("button",{onClick:()=>n(s?null:t.id),className:"w-full text-left px-4 py-3 bg-surface-1 border border-border-subtle rounded-lg hover:border-accent/30 transition-colors cursor-pointer",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate flex-1",children:t.name}),l.jsx("span",{className:"text-2xs text-text-4 font-sans",children:t.author}),s?l.jsx(zn,{size:14,className:"text-text-3"}):l.jsx(as,{size:14,className:"text-text-3"})]}),l.jsxs("div",{className:"text-2xs text-text-3 font-sans mt-0.5 flex gap-3",children:[l.jsxs("span",{children:[(r=t.downloads)==null?void 0:r.toLocaleString()," downloads"]}),l.jsxs("span",{children:[t.likes," likes"]})]})]})}function SA({repoId:t,onDownload:n,systemRamGb:s}){const[r,o]=v.useState(null),[u,d]=v.useState(!0),[O,h]=v.useState(null),p=ls();v.useEffect(()=>{d(!0),K.get(`/models/${t}/files`).then(g=>o(g.files||[])).catch(()=>p.error("Failed to load model files")).finally(()=>d(!1))},[t]);async function x(g){h(g.filename);try{await K.post("/models/download",{repoId:t,filename:g.filename}),p.success(`Downloading ${g.filename}`),n==null||n(g.filename)}catch(b){p.error(b.message)}h(null)}return u?l.jsx("div",{className:"py-3 px-4 text-2xs text-text-4 font-sans",children:"Loading quantization variants..."}):r!=null&&r.length?l.jsx("div",{className:"pl-6 pr-4 pb-2 space-y-1.5",children:r.map(g=>{const b=!g.estimatedRamGb||!s||g.estimatedRamGb<=s,y=g.estimatedRamGb&&s&&g.estimatedRamGb>s*.8&&b;return l.jsxs("div",{className:re("flex items-center gap-2 py-1.5 px-3 rounded-md text-xs font-sans",b?"bg-surface-2":"bg-red-500/5 border border-red-500/15"),children:[l.jsx("span",{className:"font-mono text-text-1 truncate flex-1",children:g.filename}),g.quantization&&l.jsx(ze,{variant:"subtle",className:"text-2xs",children:g.quantization}),l.jsx("span",{className:"text-text-2 text-2xs w-16 text-right",children:Xc(g.size)}),g.estimatedRamGb&&l.jsxs("span",{className:re("text-2xs w-20 text-right font-medium",b?y?"text-yellow-400":"text-green-400":"text-red-400"),children:["~",g.estimatedRamGb," GB RAM"]}),!b&&l.jsx("span",{className:"text-2xs text-red-400 font-medium",children:"too large"}),l.jsx("button",{onClick:()=>x(g),disabled:O===g.filename||!b,className:re("p-1 rounded transition-colors",b?"text-accent hover:bg-accent/10":"text-text-4 cursor-not-allowed","disabled:opacity-40"),children:O===g.filename?l.jsx(Ct,{size:13,className:"animate-spin"}):l.jsx(xi,{size:13})})]},g.filename)})}):l.jsx("div",{className:"py-3 px-4 text-2xs text-text-4 font-sans",children:"No GGUF files found in this repo."})}function QA({model:t,systemRamGb:n,onPull:s,pulling:r,isInstalled:o}){const u={light:"text-green-400",medium:"text-blue-400",heavy:"text-orange-400"},d={code:"{}",general:"AI"},O=n?Math.round((1-t.ramGb/n)*100):null;return l.jsxs("div",{className:re("flex items-center gap-3 px-4 py-3 border rounded-lg transition-colors",o?"bg-success/5 border-success/20":"bg-surface-1 border-border-subtle hover:border-accent/20"),children:[l.jsx("div",{className:"w-9 h-9 rounded-lg bg-surface-3 flex items-center justify-center text-xs font-mono text-text-2 flex-shrink-0",children:d[t.category]||"AI"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate",children:t.name}),l.jsx("span",{className:re("text-2xs font-semibold capitalize",u[t.tier]),children:t.tier}),o&&l.jsxs(ze,{variant:"success",className:"text-2xs gap-1",children:[l.jsx(Qt,{size:8})," Installed"]})]}),l.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:t.description}),l.jsxs("div",{className:"flex items-center gap-3 mt-1 text-2xs font-sans",children:[l.jsxs("span",{className:"text-text-2",children:[t.sizeGb," GB download"]}),l.jsxs("span",{className:"text-green-400 font-medium",children:[t.ramGb," GB RAM"]}),O!==null&&l.jsxs("span",{className:"text-text-4",children:[O,"% headroom"]})]})]}),o?l.jsx("span",{className:"text-xs text-success font-sans font-medium px-3 py-1.5",children:"Ready"}):l.jsxs("button",{onClick:()=>s(t.id),disabled:r===t.id,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-sans font-medium bg-accent/10 text-accent hover:bg-accent/20 transition-colors cursor-pointer disabled:opacity-40",children:[r===t.id?l.jsx(Ct,{size:12,className:"animate-spin"}):l.jsx(xi,{size:12}),"Pull"]})]})}function jA(){const[t,n]=v.useState("recommended"),[s,r]=v.useState(""),[o,u]=v.useState([]),[d,O]=v.useState(!1),[h,p]=v.useState([]),[x,g]=v.useState([]),[b,y]=v.useState([]),[Q,w]=v.useState(null),[k,j]=v.useState(null),[z,N]=v.useState(null),[X,G]=v.useState([]),R=ls(),_=v.useCallback(()=>{K.get("/models/installed").then(F=>{p(F.models||[])}).catch(()=>{})},[]),T=v.useCallback(()=>{K.get("/providers/ollama/models").then(F=>{G((F.installed||[]).map(se=>se.id))}).catch(()=>{})},[]);v.useEffect(()=>{K.get("/providers/ollama/hardware").then(w).catch(()=>{}),K.get("/models/recommended").then(F=>{g(F.models||[]),!Q&&F.hardware&&w(F.hardware)}).catch(()=>{}),_(),T()},[_,T]);async function Y(F){N(F);try{await K.post("/providers/ollama/pull",{model:F}),R.success(`${F} ready to use`),_(),T(),G(se=>[...se,F])}catch(se){R.error(`Pull failed: ${se.message}`)}N(null)}v.useEffect(()=>{const F=D.subscribe((ie,W)=>{}),se=setInterval(()=>{K.get("/models/downloads").then(y).catch(()=>{})},2e3);return()=>{F(),clearInterval(se)}},[]),v.useEffect(()=>{function F(ie){try{const W=JSON.parse(ie.data);W.type==="model:download:progress"&&y(P=>{const B=P.findIndex(E=>E.filename===W.data.filename);if(B>=0){const E=[...P];return E[B]=W.data,E}return[...P,W.data]}),W.type==="model:download:complete"&&(y(P=>P.filter(B=>B.filename!==W.data.filename)),_(),R.success(`${W.data.filename} downloaded`)),W.type==="model:download:error"&&(y(P=>P.filter(B=>B.filename!==W.data.filename)),R.error(`Download failed: ${W.data.error}`))}catch{}}const se=D.getState()._ws;return se&&se.addEventListener("message",F),()=>{se&&se.removeEventListener("message",F)}},[_,R]);async function M(){if(s.trim()){O(!0),n("search");try{const F=await K.get(`/models/search?q=${encodeURIComponent(s.trim())}`);u(F)}catch(F){R.error(F.message)}O(!1)}}async function ae(F){try{await K.delete(`/models/${F}`),p(se=>se.filter(ie=>ie.id!==F)),R.success("Model deleted")}catch(se){R.error(se.message)}}return l.jsxs("div",{className:"h-full flex flex-col bg-surface-0",children:[l.jsxs("div",{className:"flex-shrink-0 px-5 pt-4 pb-3 border-b border-border space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("h1",{className:"text-base font-bold font-sans text-text-0",children:"Local Models"}),l.jsxs(ze,{variant:"subtle",className:"text-2xs",children:[h.length," installed"]})]}),l.jsx(gA,{hardware:Q}),l.jsxs("div",{className:"flex gap-2",children:[l.jsxs("div",{className:"relative flex-1",children:[l.jsx(fa,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4"}),l.jsx("input",{value:s,onChange:F=>r(F.target.value),onKeyDown:F=>F.key==="Enter"&&M(),placeholder:"Search HuggingFace for GGUF models...",className:"w-full h-8 pl-9 pr-3 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"})]}),l.jsx(ge,{onClick:M,disabled:d,size:"sm",variant:"accent",children:d?l.jsx(Ct,{size:14,className:"animate-spin"}):"Search"})]}),l.jsx("div",{className:"flex gap-1",children:[{id:"recommended",label:`Recommended (${x.length})`},{id:"installed",label:`Installed (${h.length})`},{id:"search",label:`Search (${o.length})`}].map(F=>l.jsx("button",{onClick:()=>n(F.id),className:re("px-3 py-1 rounded-md text-xs font-sans font-medium transition-colors cursor-pointer",t===F.id?"bg-accent/12 text-accent":"text-text-3 hover:text-text-1 hover:bg-surface-3"),children:F.label},F.id))})]}),b.length>0&&l.jsxs("div",{className:"px-5 py-3 border-b border-border space-y-2",children:[l.jsx("div",{className:"text-xs font-sans font-semibold text-text-2",children:"Downloading"}),b.map(F=>l.jsx(bA,{download:F},F.filename))]}),l.jsx(ma,{className:"flex-1",children:l.jsxs("div",{className:"px-5 py-4 space-y-2",children:[t==="recommended"&&l.jsx(l.Fragment,{children:x.length===0?l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Ml,{size:40,className:"mx-auto text-text-4 mb-3"}),l.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"Detecting hardware..."}),l.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Make sure Ollama is installed so we can check your system."})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"text-xs text-text-3 font-sans mb-2",children:["Top models for your system (",(Q==null?void 0:Q.totalRamGb)||"?"," GB RAM). Click Pull to download via Ollama."]}),x.map(F=>{const se=F.id.split(":")[0],ie=X.some(W=>W===F.id||W.startsWith(se+":")||W===se);return l.jsx(QA,{model:F,systemRamGb:Q==null?void 0:Q.totalRamGb,onPull:Y,pulling:z,isInstalled:ie},F.id)})]})}),t==="installed"&&l.jsx(l.Fragment,{children:h.length===0?l.jsxs("div",{className:"text-center py-12",children:[l.jsx(th,{size:40,className:"mx-auto text-text-4 mb-3"}),l.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"No local models yet"}),l.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Search HuggingFace to download GGUF models, or pull models via Ollama."})]}):h.map(F=>l.jsx(vA,{model:F,onDelete:ae},F.id))}),t==="search"&&l.jsx(l.Fragment,{children:d?l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Ct,{size:24,className:"mx-auto text-accent animate-spin mb-3"}),l.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Searching HuggingFace..."})]}):o.length===0?l.jsxs("div",{className:"text-center py-12",children:[l.jsx(fa,{size:40,className:"mx-auto text-text-4 mb-3"}),l.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"Search for GGUF models"}),l.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:'Try "qwen coder", "deepseek", "codestral", "llama"'})]}):o.map(F=>l.jsxs("div",{className:"space-y-1",children:[l.jsx(yA,{result:F,expanded:k===F.id,onExpand:j}),k===F.id&&l.jsx(SA,{repoId:F.id,onDownload:()=>_(),systemRamGb:Q==null?void 0:Q.totalRamGb})]},F.id))})]})})]})}const k0=["Reading through the codebase...","Thinking through your request...","Planning the approach...","Running tool calls...","Working through the problem...","Reasoning step by step...","Reviewing context...","Considering options...","Analyzing the code...","Making progress..."];function wA({agent:t,className:n}){const[s,r]=v.useState(0),[o,u]=v.useState(!0);return v.useEffect(()=>{const d=setInterval(()=>{u(!1),setTimeout(()=>{r(O=>(O+1)%k0.length),u(!0)},250)},2800);return()=>clearInterval(d)},[]),l.jsxs("div",{className:`${n||""}`,children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx("span",{className:"text-2xs font-semibold text-text-1 font-sans",children:(t==null?void 0:t.name)||"Agent"}),l.jsx("span",{className:"text-2xs text-accent font-mono",children:"thinking"})]}),l.jsxs("div",{className:"border-l border-accent/40 pl-3.5 py-1 flex items-center gap-2.5",children:[l.jsx("div",{className:"relative w-3.5 h-3.5 flex-shrink-0",children:l.jsx("span",{className:"absolute inset-0 rounded-full border border-transparent border-t-accent animate-spin",style:{animationDuration:"0.9s"}})}),l.jsx("span",{className:"text-[12px] font-sans text-text-3 transition-opacity duration-[250ms]",style:{opacity:o?1:0},children:k0[s]})]})]})}const Af=[];function FS(t){const n=(t||"").toLowerCase();return n.includes("reading")||n.includes("read ")?{icon:Es,color:"text-info",label:"Reading"}:n.includes("editing")||n.includes("wrote")||n.includes("writing")||n.includes("edit ")?{icon:Eb,color:"text-warning",label:"Editing"}:n.includes("searching")||n.includes("search")||n.includes("grep")||n.includes("glob")?{icon:fa,color:"text-purple",label:"Searching"}:n.includes("running")||n.includes("bash")||n.includes("command")||n.includes("exec")?{icon:bi,color:"text-orange",label:"Running"}:n.includes("test")||n.includes("pass")?{icon:vf,color:"text-success",label:"Testing"}:n.includes("error")||n.includes("fail")||n.includes("crash")?{icon:Oa,color:"text-danger",label:"Error"}:n.includes("rotat")?{icon:Il,color:"text-accent",label:"Rotating"}:n.includes("spawn")||n.includes("start")?{icon:Xn,color:"text-success",label:"Spawned"}:n.includes("tool")||n.includes("function")?{icon:GN,color:"text-text-2",label:"Tool"}:n.includes("complet")||n.includes("done")||n.includes("finish")?{icon:vf,color:"text-success",label:"Done"}:{icon:ss,color:"text-text-3",label:"Activity"}}function Nl({text:t}){return t?t.split(/(\*\*[^*]+\*\*|`[^`]+`)/g).map((n,s)=>n.startsWith("**")&&n.endsWith("**")?l.jsx("strong",{className:"font-semibold text-text-0",children:n.slice(2,-2)},s):n.startsWith("`")&&n.endsWith("`")?l.jsx("code",{className:"px-1 py-px rounded bg-accent/8 text-[11px] font-mono text-accent",children:n.slice(1,-1)},s):l.jsx("span",{children:n},s)):null}function kA({text:t}){if(!t)return null;const n=[],s=t.split(`
632
+ For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return v.useEffect(()=>{t&&(document.getElementById(t)||console.error(s))},[s,t]),null},CX="DialogDescriptionWarning",_X=({contentRef:t,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${AS(CX).contentName}}.`;return v.useEffect(()=>{var u;const o=(u=t.current)==null?void 0:u.getAttribute("aria-describedby");n&&o&&(document.getElementById(n)||console.warn(r))},[r,t,n]),null},ZS=QS,ES=kS,qS=$S,MS=TS,YS=PS,US=RS,VS=_S;function Ch({children:t,...n}){return l.jsx(ZS,{...n,children:t})}function _h({children:t,className:n,title:s,description:r,...o}){return l.jsxs(ES,{children:[l.jsx(qS,{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"}),l.jsxs(MS,{className:re("fixed left-1/2 top-1/2 z-50 -translate-x-1/2 -translate-y-1/2","w-full max-w-lg max-h-[85vh] overflow-y-auto","bg-surface-1 border border-border rounded-lg shadow-2xl","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",n),...o,children:[s&&l.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border-subtle",children:[l.jsx(YS,{className:"text-base font-semibold text-text-0 font-sans",children:s}),l.jsx(VS,{className:"p-1 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-5 transition-colors",children:l.jsx(jt,{size:16})})]}),r&&l.jsx(US,{className:"sr-only",children:r}),t]})]})}const _c=v.forwardRef(({className:t,label:n,error:s,mono:r,...o},u)=>l.jsxs("div",{className:"flex flex-col gap-1",children:[n&&l.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:n}),l.jsx("input",{ref:u,className:re("h-8 w-full rounded-md px-3 text-sm","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",r?"font-mono":"font-sans",s&&"border-danger focus:ring-danger",t),...o}),s&&l.jsx("span",{className:"text-2xs text-danger font-sans",children:s})]}));_c.displayName="Input";const XX=v.forwardRef(({className:t,label:n,error:s,mono:r,...o},u)=>l.jsxs("div",{className:"flex flex-col gap-1",children:[n&&l.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:n}),l.jsx("textarea",{ref:u,className:re("w-full rounded-md px-3 py-2 text-sm resize-none","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",r?"font-mono":"font-sans",s&&"border-danger focus:ring-danger",t),...o}),s&&l.jsx("span",{className:"text-2xs text-danger font-sans",children:s})]}));XX.displayName="Textarea";const AX={slack:"https://cdn.simpleicons.org/slack/E01E5A",github:"https://cdn.simpleicons.org/github/white",stripe:"https://cdn.simpleicons.org/stripe/635BFF",gmail:"https://cdn.simpleicons.org/gmail/EA4335","google-calendar":"https://cdn.simpleicons.org/googlecalendar/4285F4","google-drive":"https://cdn.simpleicons.org/googledrive/4285F4","google-maps":"https://cdn.simpleicons.org/googlemaps/4285F4",postgres:"https://cdn.simpleicons.org/postgresql/4169E1",notion:"https://cdn.simpleicons.org/notion/white",discord:"https://cdn.simpleicons.org/discord/5865F2",linear:"https://cdn.simpleicons.org/linear/5E6AD2","brave-search":"https://cdn.simpleicons.org/brave/FB542B","home-assistant":"https://cdn.simpleicons.org/homeassistant/18BCF2"};function GS({item:t,size:n=48}){const s=AX[t.id];if(s)return l.jsx("div",{className:"rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:n,height:n},children:l.jsx("img",{src:s,alt:t.name,className:"w-6 h-6",onError:u=>{u.target.style.display="none"}})});const r=(t.name||"?")[0].toUpperCase(),o=t.name?t.name.charCodeAt(0)*37%360:200;return l.jsx("div",{className:"rounded-lg flex items-center justify-center flex-shrink-0 text-xl font-bold font-sans",style:{width:n,height:n,background:`hsl(${o}, 40%, 18%)`,color:`hsl(${o}, 60%, 65%)`},children:r})}function ZX({value:t,onChange:n,placeholder:s,disabled:r}){const[o,u]=v.useState(!1);return l.jsxs("div",{className:"relative",children:[l.jsx(_c,{type:o?"text":"password",value:t,onChange:d=>n(d.target.value),placeholder:s,disabled:r,mono:!0,className:"pr-9"}),l.jsx("button",{type:"button",onClick:()=>u(d=>!d),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded text-text-4 hover:text-text-1 transition-colors cursor-pointer",tabIndex:-1,children:o?l.jsx(Dc,{size:14}):l.jsx(Es,{size:14})})]})}function EX({integrationId:t,envKey:n,onSaved:s}){const r=ls(),[o,u]=v.useState(""),[d,O]=v.useState(!1),[h,p]=v.useState(n.set),[x,g]=v.useState(!1);async function b(){if(o.trim()){O(!0);try{await K.post(`/integrations/${t}/credentials`,{key:n.key,value:o.trim()}),p(!0),u(""),r.success(`${n.label} saved`),s==null||s()}catch(Q){r.error("Failed to save",Q.message)}O(!1)}}async function y(){g(!0);try{await K.delete(`/integrations/${t}/credentials/${n.key}`),p(!1),r.success(`${n.label} removed`),s==null||s()}catch(Q){r.error("Failed to remove",Q.message)}g(!1)}return l.jsxs("div",{className:"space-y-1.5",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[l.jsx(ri,{size:11,className:"text-text-4"}),n.label,n.required&&l.jsx("span",{className:"text-danger",children:"*"})]}),h&&l.jsxs("span",{className:"flex items-center gap-1 text-2xs text-success font-sans",children:[l.jsx(Qt,{size:10})," Set"]})]}),h?l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("div",{className:"flex-1 h-8 rounded-md px-3 bg-surface-2 border border-border-subtle flex items-center",children:l.jsx("span",{className:"text-xs text-text-4 font-mono tracking-widest",children:"*".repeat(16)})}),l.jsx(ge,{variant:"ghost",size:"sm",onClick:y,disabled:x,className:"text-text-3 hover:text-danger",children:x?l.jsx(Ct,{size:12,className:"animate-spin"}):l.jsx(_n,{size:12})})]}):l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("div",{className:"flex-1",children:l.jsx(ZX,{value:o,onChange:u,placeholder:n.placeholder||`Enter ${n.label.toLowerCase()}...`,disabled:d})}),l.jsx(ge,{variant:"primary",size:"sm",onClick:b,disabled:d||!o.trim(),children:d?l.jsx(Ct,{size:12,className:"animate-spin"}):"Save"})]})]})}function qX({item:t,status:n,installing:s,onInstall:r,onUninstall:o,onNext:u}){var O;const d=n==null?void 0:n.installed;return l.jsxs("div",{className:"px-5 py-5 space-y-5",children:[l.jsxs("div",{className:"flex items-start gap-4",children:[l.jsx(GS,{item:t,size:52}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:t.name}),(t.verified==="mcp-official"||t.verified==="verified")&&l.jsxs(ze,{variant:"accent",className:"text-2xs gap-1",children:[l.jsx(Yl,{size:9})," Verified"]})]}),l.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:t.author||"Community"}),t.category&&l.jsx(ze,{variant:"default",className:"text-2xs mt-2",children:t.category})]})]}),l.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((O=t.tags)==null?void 0:O.length)>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map(h=>l.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:h},h))}),l.jsx("div",{className:"h-px bg-border-subtle"}),d?l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[l.jsx(Ps,{size:16,className:"text-success"}),l.jsx("span",{className:"text-sm font-medium text-success font-sans",children:"Installed"})]}),l.jsxs(ge,{variant:"ghost",size:"sm",onClick:o,className:"text-text-3 hover:text-danger gap-1.5",children:[l.jsx(_n,{size:12})," Uninstall"]}),l.jsxs(ge,{variant:"primary",size:"sm",onClick:u,className:"gap-1",children:["Configure ",l.jsx(as,{size:12})]})]}):l.jsx(ge,{variant:"primary",size:"lg",onClick:r,disabled:s,className:"w-full gap-2",children:s?l.jsxs(l.Fragment,{children:[l.jsx(Ct,{size:14,className:"animate-spin"}),"Installing..."]}):"Install"}),s&&l.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"This may take up to 30 seconds..."})]})}function MX({item:t,status:n,onDone:s,onRefreshStatus:r}){var y;const o=ls(),[u,d]=v.useState(!1),O=t.authType;async function h(){d(!0);try{await K.post(`/integrations/${t.id}/authenticate`),o.success("Browser opened — complete sign-in there")}catch(Q){o.error("Auth failed",Q.message)}d(!1)}async function p(){d(!0);try{const Q=await K.post(`/integrations/${t.id}/oauth/start`);Q.url&&(window.open(Q.url,"_blank","noopener"),o.success("Browser opened — complete sign-in there"))}catch(Q){o.error("OAuth failed",Q.message)}d(!1)}const x=(n==null?void 0:n.envKeys)||[],g=x.filter(Q=>Q.required&&!Q.hidden),b=g.length===0||g.every(Q=>Q.set);return l.jsxs("div",{className:"px-5 py-5 space-y-5",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx(GS,{item:t,size:36}),l.jsxs("div",{children:[l.jsxs("h2",{className:"text-sm font-bold text-text-0 font-sans",children:["Configure ",t.name]}),l.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Set up credentials to connect"})]})]}),((y=t.setupSteps)==null?void 0:y.length)>0&&l.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[l.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Setup guide"}),l.jsx("ol",{className:"space-y-1.5",children:t.setupSteps.map((Q,w)=>l.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[l.jsxs("span",{className:"text-text-4 font-mono flex-shrink-0 w-4 text-right",children:[w+1,"."]}),l.jsx("span",{children:Q})]},w))}),t.setupUrl&&l.jsxs("a",{href:t.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-accent font-sans hover:underline mt-1",children:[l.jsx(si,{size:11}),new URL(t.setupUrl).hostname]})]}),l.jsx("div",{className:"h-px bg-border-subtle"}),O==="api-key"&&l.jsx("div",{className:"space-y-4",children:x.filter(Q=>!Q.hidden).map(Q=>l.jsx(EX,{integrationId:t.id,envKey:Q,onSaved:r},Q.key))}),O==="google-autoauth"&&l.jsxs("div",{className:"space-y-3",children:[l.jsx(ge,{variant:"primary",size:"lg",onClick:h,disabled:u,className:"w-full gap-2",children:u?l.jsxs(l.Fragment,{children:[l.jsx(Ct,{size:14,className:"animate-spin"}),"Opening browser..."]}):l.jsxs(l.Fragment,{children:[l.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),l.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"A browser window will open for Google authorization"})]}),O==="oauth-google"&&l.jsxs("div",{className:"space-y-3",children:[l.jsx(ge,{variant:"primary",size:"lg",onClick:p,disabled:u,className:"w-full gap-2",children:u?l.jsxs(l.Fragment,{children:[l.jsx(Ct,{size:14,className:"animate-spin"}),"Connecting..."]}):l.jsxs(l.Fragment,{children:[l.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Connect with Google"]})}),l.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["Authorize Groove to access your ",t.name]})]}),l.jsx(ge,{variant:b?"primary":"secondary",size:"lg",onClick:s,className:"w-full gap-1.5",children:b?l.jsxs(l.Fragment,{children:[l.jsx(Qt,{size:14}),"Done"]}):"Skip for now"})]})}function YX({item:t,onClose:n}){return l.jsxs("div",{className:"px-5 py-10 flex flex-col items-center text-center space-y-4",children:[l.jsx("div",{className:"w-14 h-14 rounded-full bg-success/15 flex items-center justify-center",children:l.jsx(Ps,{size:28,className:"text-success"})}),l.jsxs("div",{children:[l.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:"Integration ready"}),l.jsxs("p",{className:"text-sm text-text-3 font-sans mt-1",children:[t.name," is installed and configured. Agents can now use it."]})]}),l.jsx(ge,{variant:"primary",size:"lg",onClick:n,className:"mt-2",children:"Close"})]})}function UX({integration:t,open:n,onClose:s}){const r=ls(),[o,u]=v.useState("overview"),[d,O]=v.useState(null),[h,p]=v.useState(!1),[x,g]=v.useState(!0),b=t==null?void 0:t.id,y=v.useCallback(async()=>{if(b){try{const z=await K.get(`/integrations/${b}/status`);O(z)}catch{O(null)}g(!1)}},[b]);v.useEffect(()=>{n&&t&&(u("overview"),g(!0),y())},[n,t,y]);async function Q(){p(!0);try{await K.post(`/integrations/${t.id}/install`),r.success(`${t.name} installed`),await y(),u("configure")}catch(z){r.error("Install failed",z.message)}p(!1)}async function w(){try{await K.delete(`/integrations/${t.id}`),r.success(`${t.name} uninstalled`),await y()}catch(z){r.error("Uninstall failed",z.message)}}function k(){u("configure")}function j(){u("done")}return t?l.jsx(Ch,{open:n,onOpenChange:z=>{z||s()},children:l.jsx(_h,{title:o==="overview"?t.name:o==="configure"?"Configure":"Complete",description:`Setup wizard for ${t.name}`,className:"max-w-md",children:x?l.jsx("div",{className:"px-5 py-10 flex items-center justify-center",children:l.jsx(Ct,{size:20,className:"animate-spin text-text-4"})}):o==="overview"?l.jsx(qX,{item:t,status:d,installing:h,onInstall:Q,onUninstall:w,onNext:k}):o==="configure"?l.jsx(MX,{item:t,status:d,onDone:j,onRefreshStatus:y}):l.jsx(YX,{item:t,onClose:s})})}):null}function VX({skill:t,onBack:n}){var G,R,_;const s=ls(),[r,o]=v.useState(""),[u,d]=v.useState(!1),[O,h]=v.useState(!1),[p,x]=v.useState(!1),[g,b]=v.useState(!1),[y,Q]=v.useState(t.installed),[w,k]=v.useState(!0);v.useEffect(()=>{k(!0),K.get(`/skills/${t.id}/content`).then(T=>{o(T.content||""),d(T.requiresPurchase||!1)}).catch(()=>{}).finally(()=>k(!1))},[t.id]);async function j(){h(!0);try{await K.post(`/skills/${t.id}/install`),Q(!0),s.success(`${t.name} installed`)}catch(T){s.error("Install failed",T.message)}h(!1)}async function z(){x(!0);try{await K.post(`/skills/${t.id}/update`),s.success(`${t.name} updated to latest`);const T=await K.get(`/skills/${t.id}/content`);T.content&&o(T.content)}catch(T){s.error("Update failed",T.message)}x(!1)}async function N(){b(!0);try{await K.delete(`/skills/${t.id}`),Q(!1),s.success(`${t.name} uninstalled`)}catch(T){s.error("Uninstall failed",T.message)}b(!1)}async function X(){const{marketplaceAuthenticated:T,marketplaceLogin:Y,marketplaceCheckout:M}=D.getState();if(!T){Y();return}try{await M(t.id)}catch{}}return l.jsx(ma,{className:"h-full",children:l.jsxs("div",{className:"px-6 py-5",children:[l.jsxs("button",{onClick:n,className:"flex items-center gap-1 text-xs text-text-3 font-sans hover:text-text-0 cursor-pointer bg-transparent border-0 mb-4",children:[l.jsx(Ab,{size:14})," Back"]}),l.jsxs("div",{className:"flex gap-8",children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"w-11 h-11 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-[22px]",children:t.icon||((R=(G=t.name)==null?void 0:G[0])==null?void 0:R.toUpperCase())}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:t.name}),l.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-text-3 font-sans",children:[l.jsx("span",{children:t.author||"Community"}),(t.source==="claude-official"||t.verified)&&l.jsx(iS,{type:t.source,size:13})]})]})]}),l.jsx("p",{className:"mt-3 text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((_=t.tags)==null?void 0:_.length)>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:t.tags.map(T=>l.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:T},T))}),l.jsx("div",{className:"h-px bg-border-subtle my-5"}),w?l.jsxs("div",{className:"space-y-2",children:[l.jsx("div",{className:"h-3 w-48 bg-surface-4 rounded animate-pulse"}),l.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),l.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}):r?l.jsxs("div",{className:"text-sm text-text-2 font-sans leading-relaxed",children:[l.jsx("h2",{className:"text-sm font-semibold text-text-0 mb-2",children:"About"}),l.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:r})]}):u?l.jsxs("div",{className:"bg-warning/5 border border-warning/15 rounded-lg px-4 py-3",children:[l.jsx("p",{className:"text-sm text-text-1 font-sans font-medium",children:"Paid skill — purchase to view content"}),l.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Sign in and purchase this skill to access its full instructions."})]}):l.jsx("p",{className:"text-xs text-text-4 font-sans",children:"Content loading failed — check your connection."})]}),l.jsx("div",{className:"w-[240px] flex-shrink-0",children:l.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-lg p-4 sticky top-4",children:[l.jsx(rS,{price:t.price||0,size:"md"}),u&&!y?l.jsxs("button",{onClick:X,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 flex items-center justify-center gap-2 border bg-warning/15 text-warning border-warning/20 hover:bg-warning/25",children:["Buy $",(t.price||0).toFixed(2)]}):y?l.jsxs("div",{className:"mt-3 flex flex-col gap-1.5",children:[l.jsxs("button",{onClick:z,disabled:p,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:[l.jsx(Cn,{size:12,className:p?"animate-spin":""}),p?"Updating...":"Pull Latest"]}),l.jsxs("button",{onClick:N,disabled:g,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-error/10 text-error border-error/20 hover:bg-error/15",children:[l.jsx(_n,{size:12}),g?"Removing...":"Uninstall"]})]}):l.jsx("button",{onClick:j,disabled:O,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:O?"Installing...":"Install"}),l.jsx("div",{className:"mt-4 flex flex-col gap-2.5",children:[["Downloads",l.jsx("span",{className:"font-mono text-text-0",children:Ke(t.downloads||0)},"d")],["Rating",l.jsx(sS,{rating:t.rating||0,count:t.rating_count||t.ratingCount,size:"sm"},"r")],["Version",l.jsx("span",{className:"font-mono text-text-0",children:t.version||"1.0.0"},"v")],["Category",l.jsx(lS,{label:t.category||"general",variant:t.category||"draft"},"c")],["Source",l.jsx("span",{className:"text-text-0",children:t.source==="claude-official"?"Anthropic":"Community"},"s")]].map(([T,Y])=>l.jsxs("div",{className:"flex justify-between items-center text-xs font-sans",children:[l.jsx("span",{className:"text-text-3",children:T}),Y]},T))})]})})]})]})})}function GX(){const[t,n]=v.useState([]),[s,r]=v.useState(!0),[o,u]=v.useState(""),[d,O]=v.useState(""),[h,p]=v.useState("popular"),[x,g]=v.useState(null);return v.useEffect(()=>{r(!0);const b=new URLSearchParams;o&&b.set("search",o),d&&b.set("category",d),h&&b.set("sort",h),K.get(`/skills/registry?${b}`).then(y=>n(S_(y.skills||y.items||(Array.isArray(y)?y:[])))).catch(()=>n([])).finally(()=>r(!1))},[o,d,h]),x?l.jsx(VX,{skill:x,onBack:()=>g(null)}):l.jsx(ma,{className:"h-full",children:l.jsxs("div",{className:"px-5 py-4",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("div",{className:"w-72",children:l.jsx(uS,{value:o,onChange:u})}),l.jsx(P_,{selected:d,onSelect:O}),l.jsx("div",{className:"flex-1"}),l.jsxs("div",{className:"relative flex-shrink-0",children:[l.jsxs("select",{value:h,onChange:b=>p(b.target.value),className:"appearance-none font-sans cursor-pointer pr-7 py-2 pl-3 text-xs bg-surface-0 border border-border-subtle rounded text-text-1 focus:outline-none",children:[l.jsx("option",{value:"popular",children:"Popular"}),l.jsx("option",{value:"rating",children:"Top Rated"}),l.jsx("option",{value:"newest",children:"Newest"}),l.jsx("option",{value:"name",children:"A-Z"})]}),l.jsx(zn,{size:12,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]}),l.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:t.length})]}),l.jsx("div",{className:"mt-4 grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:s?Array.from({length:8}).map((b,y)=>l.jsx(cS,{},y)):t.map(b=>l.jsx(w_,{skill:b,onClick:g},b.id))}),!s&&t.length===0&&l.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No skills found."})]})})}function LX(){const[t,n]=v.useState([]),[s,r]=v.useState(!0),[o,u]=v.useState(""),[d,O]=v.useState(null),[h,p]=v.useState(!1),x=()=>{r(!0),K.get(`/integrations/registry?search=${encodeURIComponent(o)}`).then(y=>n(y.integrations||y.items||(Array.isArray(y)?y:[]))).catch(()=>n([])).finally(()=>r(!1))};v.useEffect(()=>{x()},[o]);function g(y){O(y),p(!0)}function b(){p(!1),O(null),x()}return l.jsxs(ma,{className:"h-full",children:[l.jsxs("div",{className:"px-5 py-4",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("div",{className:"w-72",children:l.jsx(uS,{value:o,onChange:u,placeholder:"Search integrations..."})}),l.jsx("div",{className:"flex-1"}),l.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:t.length})]}),l.jsx("div",{className:"mt-4 grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:s?Array.from({length:6}).map((y,Q)=>l.jsx(cS,{},Q)):t.map(y=>l.jsx(T_,{item:y,onClick:()=>g(y)},y.id))}),!s&&t.length===0&&l.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No integrations found."})]}),l.jsx(UX,{integration:d,open:h,onClose:b})]})}function DX(){const t=D(k=>k.marketplaceAuthenticated),n=D(k=>k.marketplaceLogin),[s,r]=v.useState([]),[o,u]=v.useState([]),[d,O]=v.useState(!0),[h,p]=v.useState(null),x=ls(),g=v.useRef(null),b=async()=>{const k=await K.get("/skills/installed");u(Array.isArray(k)?k:k.skills||[])};v.useEffect(()=>{O(!0),Promise.all([t?K.get("/auth/purchases").then(k=>k.purchases||[]).catch(()=>[]):Promise.resolve([]),K.get("/skills/installed").then(k=>Array.isArray(k)?k:k.skills||[]).catch(()=>[])]).then(([k,j])=>{r(k),u(j)}).finally(()=>O(!1))},[t]);async function y(k){p(k.id);try{await K.post(`/skills/${k.id}/update`),x.success(`${k.name||k.id} updated`),await b()}catch(j){x.error("Update failed",j.message)}p(null)}async function Q(k){p(k.id);try{await K.delete(`/skills/${k.id}`),x.success(`${k.name||k.id} uninstalled`),await b()}catch(j){x.error("Uninstall failed",j.message)}p(null)}async function w(k){var z;const j=(z=k.target.files)==null?void 0:z[0];if(j){try{const N=await j.text(),X=j.name.replace(/\.md$/i,"");await K.post("/skills/import",{name:X,content:N}),x.success(`Imported "${X}"`),await b()}catch(N){x.error("Import failed",N.message)}k.target.value=""}}return d?l.jsx("div",{className:"p-5 space-y-3",children:[...Array(4)].map((k,j)=>l.jsx(on,{className:"h-14 rounded-md"},j))}):l.jsx(ma,{className:"h-full",children:l.jsxs("div",{className:"px-5 py-4 space-y-6",children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("input",{ref:g,type:"file",accept:".md",onChange:w,className:"hidden"}),l.jsxs(ge,{variant:"secondary",size:"md",onClick:()=>{var k;return(k=g.current)==null?void 0:k.click()},className:"gap-1.5",children:[l.jsx(AN,{size:13}),"Import .md Skill"]}),l.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Drop a markdown skill file to install locally"})]}),t&&s.length>0&&l.jsxs("div",{children:[l.jsxs("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[l.jsx(TO,{size:12}),"Purchases (",s.length,")"]}),l.jsx("div",{className:"space-y-1.5",children:s.map(k=>{var j,z;return l.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-1 border border-border-subtle",children:[l.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center text-sm flex-shrink-0",children:k.skill_icon||((z=(j=k.skill_name)==null?void 0:j[0])==null?void 0:z.toUpperCase())||"?"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:k.skill_name||k.skill_id}),l.jsxs("div",{className:"text-2xs text-text-4 font-sans",children:["$",(k.amount||0).toFixed(2)," · ",vt(k.created_at)]})]}),l.jsx(ze,{variant:"success",className:"text-2xs flex-shrink-0",children:"Owned"})]},k.id||k.skill_id)})})]}),t&&s.length===0&&l.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[l.jsx(TO,{size:20,className:"mx-auto text-text-4 mb-2"}),l.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No purchases yet"})]}),!t&&l.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[l.jsx(TO,{size:20,className:"mx-auto text-text-4 mb-2"}),l.jsx("p",{className:"text-xs text-text-2 font-sans mb-3",children:"Sign in to see your purchases"}),l.jsxs(ge,{variant:"primary",size:"sm",onClick:n,className:"gap-1.5 mx-auto",children:[l.jsx(ah,{size:12})," Sign in"]})]}),l.jsxs("div",{children:[l.jsxs("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[l.jsx(Db,{size:12}),"Installed (",o.length,")"]}),o.length===0?l.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[l.jsx(xi,{size:20,className:"mx-auto text-text-4 mb-2"}),l.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No skills installed — browse the Skills tab or import a .md file"})]}):l.jsx("div",{className:"space-y-1.5",children:o.map(k=>{var j,z;return l.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-1 border border-border-subtle group",children:[l.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center text-sm flex-shrink-0",children:k.icon||((z=(j=k.name)==null?void 0:j[0])==null?void 0:z.toUpperCase())||"?"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:k.name||k.id}),l.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:k.description||k.category||"local skill"})]}),l.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[l.jsx("button",{onClick:()=>y(k),disabled:h===k.id,title:"Pull latest version",className:"p-1.5 rounded text-text-3 hover:text-accent hover:bg-accent/10 cursor-pointer transition-colors disabled:opacity-50",children:l.jsx(Cn,{size:12,className:h===k.id?"animate-spin":""})}),l.jsx("button",{onClick:()=>Q(k),disabled:h===k.id,title:"Uninstall",className:"p-1.5 rounded text-text-3 hover:text-error hover:bg-error/10 cursor-pointer transition-colors disabled:opacity-50",children:l.jsx(_n,{size:12})})]}),l.jsx(ze,{variant:"accent",className:"text-2xs flex-shrink-0",children:"Installed"})]},k.id)})})]})]})})}function WX(){const t=D(o=>o.marketplaceAuthenticated),n=D(o=>o.marketplaceUser),s=D(o=>o.marketplaceLogin),r=D(o=>o.marketplaceLogout);return t?l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded bg-surface-3 border border-border-subtle",children:[l.jsx("div",{className:"w-4 h-4 rounded-full bg-accent/20 flex items-center justify-center",children:l.jsx(ev,{size:9,className:"text-accent"})}),l.jsx("span",{className:"text-xs text-text-0 font-sans font-medium max-w-[120px] truncate",children:(n==null?void 0:n.displayName)||(n==null?void 0:n.id)||"Account"})]}),l.jsx("button",{onClick:r,className:"flex items-center gap-1 px-2 py-1.5 rounded text-xs text-text-3 hover:text-text-0 hover:bg-surface-3 font-sans cursor-pointer transition-colors",children:l.jsx(Vb,{size:11})})]}):l.jsxs("button",{onClick:s,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold font-sans text-text-0 bg-accent/15 border border-accent/25 rounded hover:bg-accent/25 cursor-pointer transition-colors",children:[l.jsx(ah,{size:12}),"Sign in"]})}function BX(){const[t,n]=v.useState("skills"),s=[{id:"skills",label:"Skills",icon:Kr},{id:"integrations",label:"Integrations",icon:Wb},{id:"library",label:"My Library",icon:Db}];return l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-b border-border-subtle",children:l.jsxs("div",{className:"flex items-center px-5 h-11",children:[l.jsx("div",{className:"flex items-center",children:s.map(r=>{const o=r.icon;return l.jsxs("button",{onClick:()=>n(r.id),className:`flex items-center gap-1.5 px-3 py-2.5 text-xs font-semibold font-sans cursor-pointer select-none border-b-2 -mb-px transition-colors ${t===r.id?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"}`,children:[l.jsx(o,{size:12}),r.label]},r.id)})}),l.jsx("div",{className:"flex-1"}),l.jsx(WX,{})]})}),l.jsxs("div",{className:"flex-1 min-h-0",children:[t==="skills"&&l.jsx(GX,{}),t==="integrations"&&l.jsx(LX,{}),t==="library"&&l.jsx(DX,{})]})]})}function HX(){const t=D(u=>u.teams),n=D(u=>u.agents),s=D(u=>u.activeTeamId),r=D(u=>u.deleteTeam),o=D(u=>u.addToast);return t.length===0?l.jsx("div",{className:"flex-1 flex items-center justify-center",children:l.jsxs("div",{className:"text-center space-y-2",children:[l.jsx(yi,{size:28,className:"mx-auto text-text-4"}),l.jsx("p",{className:"text-xs font-sans text-text-3",children:"No teams yet"}),l.jsx("p",{className:"text-2xs font-sans text-text-4",children:"Teams are created when you spawn agents or launch a planner"})]})}):l.jsx("div",{className:"flex-1 overflow-y-auto",children:l.jsx("div",{className:"p-4 space-y-3",children:t.map(u=>{const d=n.filter(y=>y.teamId===u.id),O=d.filter(y=>y.status==="running"||y.status==="starting"),h=d.filter(y=>y.status==="completed"),p=d.filter(y=>y.status==="crashed"),x=d.reduce((y,Q)=>y+(Q.tokensUsed||0),0),g=d.reduce((y,Q)=>y+(Q.costUsd||0),0),b=u.id===s;return l.jsxs("div",{className:re("rounded-md border bg-surface-1 overflow-hidden transition-colors",b?"border-accent/30":"border-border-subtle"),children:[l.jsxs("div",{className:"px-4 py-3 flex items-center gap-3",children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans",children:u.name}),b&&l.jsx(ze,{variant:"accent",className:"text-2xs",children:"Active"})]}),u.workingDir&&l.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[l.jsx(Mb,{size:10,className:"text-text-4"}),l.jsx("span",{className:"text-2xs font-mono text-text-3 truncate",children:u.workingDir})]})]}),l.jsx("button",{onClick:()=>{if(d.some(y=>y.status==="running")){o("error","Stop running agents first");return}r(u.id)},className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Delete team",children:l.jsx(_n,{size:13})})]}),l.jsxs("div",{className:"px-4 py-2.5 border-t border-border-subtle bg-surface-0 flex items-center gap-4",children:[l.jsx(kl,{label:"Agents",value:d.length}),l.jsx(kl,{label:"Running",value:O.length,color:O.length>0?"text-success":void 0}),l.jsx(kl,{label:"Done",value:h.length}),l.jsx(kl,{label:"Crashed",value:p.length,color:p.length>0?"text-danger":void 0}),l.jsx("div",{className:"flex-1"}),l.jsx(kl,{label:"Tokens",value:Ke(x)}),g>0&&l.jsx(kl,{label:"Cost",value:Si(g)})]}),d.length>0&&l.jsx("div",{className:"border-t border-border-subtle",children:d.map(y=>l.jsxs("div",{className:"flex items-center gap-2 px-4 py-1.5 border-b border-border-subtle last:border-b-0",children:[l.jsx(zs,{status:y.status,size:"sm"}),l.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:y.name}),l.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase",children:y.role}),l.jsx("div",{className:"flex-1"}),l.jsx("span",{className:"text-2xs font-mono text-text-2 tabular-nums",children:Ke(y.tokensUsed||0)})]},y.id))})]},u.id)})})})}function kl({label:t,value:n,color:s}){return l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:re("text-xs font-mono tabular-nums",s||"text-text-1"),children:n}),l.jsx("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider",children:t})]})}function IX(){const t=D(r=>r.pendingApprovals),n=D(r=>r.approveRequest),s=D(r=>r.rejectRequest);return t.length===0?null:l.jsxs("div",{className:"px-4 pt-4 space-y-2",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx(vi,{size:12,className:"text-warning"}),l.jsxs("span",{className:"text-2xs font-mono text-warning uppercase tracking-wider",children:["Pending (",t.length,")"]})]}),t.map(r=>{var o,u,d;return l.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-md bg-warning/5 border border-warning/20",children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"text-xs text-text-0 font-sans font-medium truncate",children:[r.agentName,": ",((o=r.action)==null?void 0:o.description)||((u=r.action)==null?void 0:u.type)||"action"]}),((d=r.action)==null?void 0:d.filePath)&&l.jsx("div",{className:"text-2xs font-mono text-text-3 truncate mt-0.5",children:r.action.filePath}),l.jsx("div",{className:"text-2xs text-text-4 font-mono mt-0.5",children:vt(r.requestedAt)})]}),l.jsxs("div",{className:"flex gap-1.5 flex-shrink-0",children:[l.jsxs(ge,{variant:"primary",size:"sm",onClick:()=>n(r.id),className:"h-7 px-2.5 gap-1 text-2xs",children:[l.jsx(Kb,{size:10})," Approve"]}),l.jsxs(ge,{variant:"danger",size:"sm",onClick:()=>s(r.id),className:"h-7 px-2.5 gap-1 text-2xs",children:[l.jsx(wN,{size:10})," Reject"]})]})]},r.id)})]})}function FX(){const t=D(h=>h.resolvedApprovals),[n,s]=v.useState([]),[r,o]=v.useState(!0);v.useEffect(()=>{const h=setInterval(u,4e3);return u(),()=>clearInterval(h)},[]);async function u(){try{const h=await K.get("/pm/history");s(h.history||h||[])}catch{}o(!1)}const d=new Set,O=[...t,...n].filter(h=>{const p=h.id||`${h.agentName}-${h.timestamp}`;return d.has(p)?!1:(d.add(p),!0)});return l.jsxs("div",{className:"flex-1 overflow-y-auto",children:[l.jsx(IX,{}),l.jsxs("div",{className:"p-4 space-y-1.5",children:[r&&O.length===0&&l.jsx("div",{className:"text-center py-12 text-text-4 font-mono text-xs",children:"Loading..."}),!r&&O.length===0&&l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Ps,{size:24,className:"mx-auto mb-2 text-text-4"}),l.jsx("p",{className:"text-xs font-sans text-text-3",children:"No approval history"}),l.jsx("p",{className:"text-2xs text-text-4 font-sans mt-1",children:"Approvals appear when agents use Auto permission mode"})]}),O.map((h,p)=>{var g;const x=h.status==="approved"||h.verdict==="approved";return l.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-surface-0 border border-border-subtle",children:[x?l.jsx(Ps,{size:12,className:"text-success flex-shrink-0"}):l.jsx(Zb,{size:12,className:"text-danger flex-shrink-0"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"text-xs text-text-1 font-sans truncate",children:[l.jsx("span",{className:"font-medium text-text-0",children:h.agentName}),l.jsx("span",{className:"text-text-3 mx-1",children:"·"}),l.jsx("span",{children:((g=h.action)==null?void 0:g.description)||h.action||"action"})]}),h.reason&&l.jsx("div",{className:"text-2xs text-text-3 font-sans truncate mt-0.5",children:h.reason})]}),l.jsx("span",{className:"text-2xs font-mono text-text-4 flex-shrink-0",children:vt(h.resolvedAt||h.timestamp)})]},h.id||p)})]})]})}function KX(){const[t,n]=v.useState([]),[s,r]=v.useState(!0),o=ls();v.useEffect(()=>{const O=setInterval(u,1e4);return u(),()=>clearInterval(O)},[]);async function u(){try{const O=await K.get("/schedules");n(O.schedules||O||[])}catch{}r(!1)}async function d(O,h){try{await K.post(`/schedules/${O}/${h?"disable":"enable"}`),u()}catch(p){o.error("Failed to toggle schedule",p.message)}}return l.jsx("div",{className:"flex-1 overflow-y-auto",children:l.jsxs("div",{className:"p-4 space-y-2",children:[s&&t.length===0&&l.jsx("div",{className:"text-center py-12 text-text-4 font-mono text-xs",children:"Loading..."}),!s&&t.length===0&&l.jsxs("div",{className:"text-center py-12",children:[l.jsx(vc,{size:24,className:"mx-auto mb-2 text-text-4"}),l.jsx("p",{className:"text-xs font-sans text-text-3",children:"No schedules configured"}),l.jsx("p",{className:"text-2xs text-text-4 font-sans mt-1",children:"Use the CLI to create agent schedules"})]}),t.map(O=>l.jsxs("div",{className:"rounded-md border border-border-subtle bg-surface-0 overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:O.name}),l.jsx(ze,{variant:O.enabled?"success":"default",className:"text-2xs",children:O.enabled?"Active":"Paused"})]}),l.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[l.jsx("span",{className:"text-2xs font-mono text-text-2",children:O.cron}),l.jsx("span",{className:"text-2xs text-text-4",children:"·"}),l.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase",children:O.role}),O.teamId&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"text-2xs text-text-4",children:"·"}),l.jsx("span",{className:"text-2xs font-sans text-text-3",children:O.teamName||O.teamId})]})]}),O.prompt&&l.jsx("div",{className:"text-2xs font-sans text-text-4 mt-1 truncate",children:O.prompt})]}),l.jsx(ge,{variant:"secondary",size:"sm",onClick:()=>d(O.id,O.enabled),className:"h-7 px-2.5 gap-1 text-2xs",children:O.enabled?l.jsxs(l.Fragment,{children:[l.jsx(tN,{size:10})," Pause"]}):l.jsxs(l.Fragment,{children:[l.jsx(rN,{size:10})," Enable"]})})]}),O.lastRunAt&&l.jsxs("div",{className:"px-4 py-1.5 border-t border-border-subtle bg-surface-1 text-2xs font-mono text-text-4",children:["Last run: ",vt(O.lastRunAt),O.nextRunAt&&l.jsxs("span",{className:"ml-3",children:["Next: ",vt(O.nextRunAt)]})]})]},O.id))]})})}function JX(){return l.jsxs(nS,{defaultValue:"dashboard",className:"flex flex-col h-full",children:[l.jsxs("div",{className:"px-4 pt-3 bg-surface-1 border-b border-border",children:[l.jsx("div",{className:"flex items-center gap-4 mb-0",children:l.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Management"})}),l.jsxs(aS,{className:"border-b-0",children:[l.jsxs(_l,{value:"dashboard",className:"inline-flex items-center gap-1.5",children:[l.jsx(PT,{size:12}),"Teams"]}),l.jsxs(_l,{value:"approvals",className:"inline-flex items-center gap-1.5",children:[l.jsx(RT,{size:12}),"Approvals"]}),l.jsxs(_l,{value:"schedules",className:"inline-flex items-center gap-1.5",children:[l.jsx(vc,{size:12}),"Schedules"]})]})]}),l.jsx(Xl,{value:"dashboard",className:"flex-1 min-h-0",children:l.jsx(HX,{})}),l.jsx(Xl,{value:"approvals",className:"flex-1 min-h-0",children:l.jsx(FX,{})}),l.jsx(Xl,{value:"schedules",className:"flex-1 min-h-0",children:l.jsx(KX,{})})]})}const eA={code:"Code",general:"General"},tA={light:"text-success",medium:"text-accent",heavy:"text-warning"};function nA(t){return t<1?`${Math.round(t*1024)} MB`:`${t} GB`}function LS({hardware:t}){if(!t)return null;const{totalRamGb:n,gpu:s,isAppleSilicon:r}=t;return l.jsxs("div",{className:"flex items-center gap-3 bg-surface-0 rounded-lg border border-border-subtle px-3 py-2.5",children:[l.jsx(sh,{size:14,className:"text-text-3 flex-shrink-0"}),l.jsx("div",{className:"flex-1 min-w-0",children:l.jsxs("div",{className:"flex items-center gap-2 text-xs font-sans",children:[l.jsxs("span",{className:"text-text-0 font-semibold",children:[n," GB RAM"]}),s&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"text-text-4",children:"·"}),l.jsx("span",{className:"text-text-2",children:s.name})]}),r&&l.jsx(ze,{variant:"accent",className:"text-2xs",children:"Unified Memory"})]})})]})}function aA({onRecheck:t}){const[n,s]=v.useState(null),[r,o]=v.useState(!1),[u,d]=v.useState(!1),[O,h]=v.useState(!1),p=D(X=>X.addToast);v.useEffect(()=>{K.post("/providers/ollama/check").then(s).catch(()=>{})},[]);async function x(){o(!0);try{const X=await K.post("/providers/ollama/check");s(X),X.installed&&X.serverRunning?(p("success","Ollama is ready!"),t()):X.installed?p("info","Ollama installed — server needs to start"):p("info","Ollama not found — install and try again")}catch{}o(!1)}async function g(){d(!0);try{if((await K.post("/providers/ollama/serve")).ok){p("success","Ollama server started!");let G=!1;for(let R=0;R<5;R++){await new Promise(T=>setTimeout(T,2e3));const _=await K.post("/providers/ollama/check");if(s(_),_.serverRunning){G=!0;break}}G&&t()}}catch(X){p("error","Could not start server",X.message)}d(!1)}function b(X){navigator.clipboard.writeText(X),h(!0),setTimeout(()=>h(!1),2e3)}if(!n)return l.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{hardware:y,install:Q,requirements:w,installed:k,serverRunning:j}=n,z=y.totalRamGb>=w.minRAM,N=y.recommended;return l.jsxs("div",{className:"space-y-3 p-3",children:[l.jsx(LS,{hardware:y}),z?l.jsxs("div",{className:"flex items-start gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2.5",children:[l.jsx(Qt,{size:14,className:"text-success flex-shrink-0 mt-0.5"}),l.jsxs("div",{className:"text-xs font-sans",children:[l.jsx("span",{className:"text-success font-semibold",children:"Your system is ready."}),l.jsx("span",{className:"text-text-2 ml-1",children:N.code?`Recommended: ${N.code}`:`${y.totalRamGb} GB RAM available`})]})]}):l.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[l.jsx(Oa,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),l.jsxs("div",{className:"text-xs font-sans text-text-2",children:[l.jsxs("span",{className:"text-warning font-semibold",children:[y.totalRamGb," GB RAM detected."]})," ","Minimum ",w.minRAM," GB needed. Smallest models may still work."]})]}),k&&!j&&l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[l.jsx(Oa,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),l.jsxs("div",{className:"text-xs font-sans text-text-2",children:[l.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."]})]}),l.jsxs(ge,{variant:"primary",size:"md",onClick:g,disabled:u,className:"w-full gap-1.5",children:[l.jsx(Xn,{size:12}),u?"Starting...":"Start Ollama Server"]})]}),!k&&l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("p",{className:"text-xs font-semibold text-text-1 font-sans",children:"Install Ollama"}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.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:Q.command}),l.jsxs(ge,{variant:"secondary",size:"sm",onClick:()=>b(Q.command),className:"h-8 px-2.5 gap-1 flex-shrink-0",children:[O?l.jsx(Qt,{size:12}):l.jsx(Sf,{size:12}),O?"Copied":"Copy"]})]}),Q.alt&&l.jsx("p",{className:"text-2xs text-text-4 font-sans",children:Q.alt})]}),l.jsxs(ge,{variant:"secondary",size:"md",onClick:x,disabled:r,className:"w-full gap-1.5",children:[l.jsx(Cn,{size:12,className:r?"animate-spin":""}),r?"Checking...":k?"Check again":"I installed it — check again"]})]})}function sA({model:t,isInstalled:n,isRecommended:s,canRun:r,onPull:o,onDelete:u,pulling:d}){const O=d===t.id;return l.jsxs("div",{className:re("flex items-center gap-2 px-3 py-2 border-t border-border-subtle transition-colors",!r&&"opacity-40"),children:[n?l.jsx(Qt,{size:12,className:"text-success flex-shrink-0"}):l.jsx("div",{className:"w-3"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("span",{className:"text-xs font-mono text-text-1 truncate",children:t.name}),s&&l.jsx(Jb,{size:10,className:"text-warning flex-shrink-0"})]}),l.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[l.jsx("span",{className:re("text-2xs font-semibold font-sans",tA[t.tier]),children:t.tier}),l.jsx("span",{className:"text-2xs text-text-4 font-sans",children:nA(t.sizeGb)}),l.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["· ",t.ramGb," GB RAM"]})]})]}),n?l.jsx("button",{onClick:()=>u(t.id),className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Remove model",children:l.jsx(_n,{size:12})}):r?l.jsx(ge,{variant:"secondary",size:"sm",onClick:()=>o(t.id),disabled:!!d,className:"h-7 px-2 text-2xs gap-1",children:O?l.jsxs(l.Fragment,{children:[l.jsx(Cn,{size:10,className:"animate-spin"})," Pulling..."]}):l.jsxs(l.Fragment,{children:[l.jsx(xi,{size:10})," Pull"]})}):l.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["Needs ",t.ramGb," GB"]})]})}function lA({onStopped:t}){const[n,s]=v.useState(null),r=D(d=>d.addToast);async function o(){s("stopping");try{(await K.post("/providers/ollama/stop")).ok?(r("info","Ollama server stopped"),t&&t()):r("error","Could not stop server")}catch(d){r("error","Stop failed",d.message)}s(null)}async function u(){s("restarting");try{(await K.post("/providers/ollama/restart")).ok?r("success","Ollama server restarted"):r("error","Restart failed")}catch(d){r("error","Restart failed",d.message)}s(null)}return l.jsxs("div",{className:"flex items-center gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2",children:[l.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[l.jsx("span",{className:"absolute inset-0 rounded-full bg-success"}),l.jsx("span",{className:"absolute inset-[-2px] rounded-full bg-success opacity-20 animate-pulse"})]}),l.jsx("span",{className:"text-xs font-sans text-success font-semibold",children:"Server Running"}),l.jsx("span",{className:"text-2xs font-mono text-text-4",children:":11434"}),l.jsx("div",{className:"flex-1"}),l.jsxs("button",{onClick:u,disabled:!!n,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-accent cursor-pointer transition-colors disabled:opacity-40",children:[l.jsx(Cn,{size:10,className:n==="restarting"?"animate-spin":""}),n==="restarting"?"Restarting...":"Restart"]}),l.jsxs("button",{onClick:o,disabled:!!n,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-danger cursor-pointer transition-colors disabled:opacity-40",children:[l.jsx(Oa,{size:10}),n==="stopping"?"Stopping...":"Stop"]})]})}function rA({onModelChange:t}){var T,Y;const[n,s]=v.useState(null),[r,o]=v.useState(null),[u,d]=v.useState("code"),[O,h]=v.useState(!1),[p,x]=v.useState(!1),g=D(M=>M.addToast),b=v.useRef(!1);function y(){K.get("/providers/ollama/models").then(M=>{var ae;s(M),!b.current&&((ae=M.installed)==null?void 0:ae.length)===0&&(b.current=!0,setTimeout(y,2e3))}).catch(()=>{})}v.useEffect(()=>{y()},[]);async function Q(M){o(M);try{await K.post("/providers/ollama/pull",{model:M}),g("success",`Pulled ${M}`),y(),t&&t()}catch(ae){g("error",`Pull failed: ${ae.message}`)}o(null)}async function w(M){try{await K.delete(`/providers/ollama/models/${encodeURIComponent(M)}`),g("info",`Removed ${M}`),y(),t&&t()}catch(ae){g("error",`Delete failed: ${ae.message}`)}}if(!n)return l.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{installed:k,catalog:j,hardware:z}=n,N=new Set(k.map(M=>M.id)),X=z.totalRamGb,G=[(T=z.recommended)==null?void 0:T.code,(Y=z.recommended)==null?void 0:Y.general].filter(Boolean),R=j.filter(M=>M.category===u),_=O?R:R.filter(M=>M.ramGb<=X);return p?l.jsxs("div",{className:"space-y-3 p-3",children:[l.jsxs("div",{className:"flex items-center gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[l.jsx(Oa,{size:14,className:"text-warning flex-shrink-0"}),l.jsxs("span",{className:"text-xs font-sans text-text-2",children:[l.jsx("span",{className:"text-warning font-semibold",children:"Ollama server stopped."})," ","Start it again to pull and use models."]})]}),l.jsxs(ge,{variant:"primary",size:"md",onClick:async()=>{try{(await K.post("/providers/ollama/serve")).ok&&(g("success","Ollama server started!"),x(!1),b.current=!1,setTimeout(y,2e3))}catch(M){g("error","Could not start server",M.message)}},className:"w-full gap-1.5",children:[l.jsx(Xn,{size:12}),"Start Ollama Server"]})]}):l.jsxs("div",{className:"space-y-2 p-3",children:[l.jsx(lA,{onStopped:()=>x(!0)}),l.jsx(LS,{hardware:z}),k.length>0&&l.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-sans text-text-2",children:[l.jsx(nh,{size:12,className:"text-text-3"}),l.jsx("span",{className:"font-semibold",children:k.length})," model",k.length!==1?"s":""," installed"]}),l.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:Object.entries(eA).map(([M,ae])=>l.jsx("button",{onClick:()=>d(M),className:re("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",u===M?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:ae},M))}),l.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[_.map(M=>l.jsx(sA,{model:M,isInstalled:N.has(M.id),isRecommended:G.includes(M.id),canRun:M.ramGb<=X,onPull:Q,onDelete:w,pulling:r},M.id)),_.length===0&&l.jsxs("div",{className:"px-3 py-4 text-center text-xs text-text-4 font-sans",children:["No ",u," models available for your hardware"]})]}),!O&&R.length>_.length&&l.jsxs("button",{onClick:()=>h(!0),className:"flex items-center gap-1 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[l.jsx(zn,{size:10}),"Show ",R.length-_.length," more (exceed your RAM)"]})]})}function DS({isInstalled:t,onModelChange:n}){const[s,r]=v.useState(!1),[o,u]=v.useState(!1);return v.useEffect(()=>{t?K.post("/providers/ollama/check").then(d=>{r(d.installed&&d.serverRunning),u(!0)}).catch(()=>u(!0)):u(!0)},[t]),o?s?l.jsx(rA,{onModelChange:n}):l.jsx(aA,{onRecheck:()=>{r(!0),n&&n()}}):l.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Checking Ollama..."})}var w0={};function iA({path:t,onNavigate:n}){const s=t.split("/").filter(Boolean);return l.jsxs("div",{className:"flex items-center gap-0.5 min-w-0 overflow-x-auto py-1.5 scrollbar-none",children:[l.jsx("button",{onClick:()=>n("/"),className:"flex-shrink-0 p-1 rounded hover:bg-surface-5 cursor-pointer text-text-3 hover:text-text-0 transition-colors",children:l.jsx(nh,{size:13})}),s.map((r,o)=>{const u="/"+s.slice(0,o+1).join("/"),d=o===s.length-1;return l.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[l.jsx(as,{size:11,className:"text-text-4"}),l.jsx("button",{onClick:()=>n(u),className:re("px-1.5 py-0.5 rounded text-xs font-mono cursor-pointer transition-colors",d?"text-text-0 bg-surface-4 font-medium":"text-text-3 hover:text-text-0 hover:bg-surface-5"),children:r})]},o)})]})}function WS({open:t,onOpenChange:n,currentPath:s,onSelect:r}){const[o,u]=v.useState(s||w0.HOME||"/"),[d,O]=v.useState([]),[h,p]=v.useState(!1),[x,g]=v.useState(null);v.useEffect(()=>{t&&b(s||"/")},[t]);async function b(k){p(!0),g(null);try{const j=await K.get(`/browse-system?path=${encodeURIComponent(k)}`);u(j.current||k),O(j.dirs||[])}catch(j){g(j.message),O([])}p(!1)}function y(){const k=o==="/"?"/":o.split("/").slice(0,-1).join("/")||"/";b(k)}function Q(){b(w0.HOME||"/Users")}function w(){r(o),n(!1)}return l.jsx(Ch,{open:t,onOpenChange:n,children:l.jsx(_h,{title:"Select Working Directory",description:"Choose a directory for this agent to work in",className:"max-w-[520px]",children:l.jsxs("div",{className:"px-5 py-4 space-y-3",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("button",{onClick:y,disabled:o==="/",className:"p-1.5 rounded-md bg-surface-4 border border-border text-text-2 hover:text-text-0 hover:bg-surface-5 transition-colors cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",children:l.jsx(j$,{size:14})}),l.jsx("button",{onClick:Q,className:"p-1.5 rounded-md bg-surface-4 border border-border text-text-2 hover:text-text-0 hover:bg-surface-5 transition-colors cursor-pointer",children:l.jsx(wT,{size:14})}),l.jsx("div",{className:"flex-1 min-w-0 bg-surface-0 rounded-md border border-border-subtle px-2",children:l.jsx(iA,{path:o,onNavigate:b})})]}),l.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle overflow-hidden",children:l.jsxs("div",{className:"max-h-[340px] overflow-y-auto",children:[h&&l.jsx("div",{className:"flex items-center justify-center py-8",children:l.jsx(Ct,{size:18,className:"text-text-3 animate-spin"})}),x&&l.jsx("div",{className:"px-4 py-6 text-center",children:l.jsx("p",{className:"text-xs text-danger font-sans",children:x})}),!h&&!x&&d.length===0&&l.jsx("div",{className:"px-4 py-6 text-center",children:l.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No subdirectories"})}),!h&&!x&&d.map(k=>l.jsxs("button",{onClick:()=>b(k.path),className:re("w-full flex items-center gap-2.5 px-3.5 py-2 text-left cursor-pointer","hover:bg-surface-4 transition-colors border-b border-border-subtle last:border-0"),children:[k.hasChildren?l.jsx(fT,{size:15,className:"text-warning flex-shrink-0"}):l.jsx(li,{size:15,className:"text-text-3 flex-shrink-0"}),l.jsx("span",{className:"text-sm text-text-0 font-sans truncate flex-1",children:k.name}),k.hasChildren&&l.jsx(as,{size:12,className:"text-text-4 flex-shrink-0"})]},k.path))]})}),l.jsxs("div",{className:"flex items-center gap-3 bg-surface-4/50 rounded-lg px-3.5 py-2.5 border border-border-subtle",children:[l.jsx(li,{size:16,className:"text-accent flex-shrink-0"}),l.jsx("span",{className:"text-xs font-mono text-text-1 truncate flex-1",children:o})]}),l.jsxs("div",{className:"flex justify-end gap-2",children:[l.jsx(ge,{variant:"ghost",size:"md",onClick:()=>n(!1),children:"Cancel"}),l.jsxs(ge,{variant:"primary",size:"md",onClick:w,className:"gap-1.5",children:[l.jsx(Qt,{size:14})," Select Folder"]})]})]})})})}function BS({children:t,...n}){return l.jsx(ZS,{...n,children:t})}function HS({children:t,className:n,title:s,side:r="right",width:o=400,...u}){return l.jsxs(ES,{children:[l.jsx(qS,{className:"fixed inset-0 z-40 bg-black/30"}),l.jsxs(MS,{className:re("fixed top-0 z-50 h-full overflow-y-auto","bg-surface-1 border-l border-border shadow-2xl","data-[state=open]:animate-in data-[state=closed]:animate-out",r==="right"&&"right-0 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right",r==="left"&&"left-0 data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left",n),style:{width:o},...u,children:[s&&l.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border-subtle sticky top-0 bg-surface-1 z-10",children:[l.jsx(YS,{className:"text-base font-semibold text-text-0 font-sans",children:s}),l.jsx(VS,{className:"p-1 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-5 transition-colors cursor-pointer",children:l.jsx(jt,{size:16})})]}),l.jsx(US,{className:"sr-only",children:"Panel"}),t]})]})}function oA({value:t,onChange:n}){return l.jsx("button",{onClick:()=>n(!t),className:re("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer",t?"bg-accent":"bg-surface-5"),children:l.jsx("div",{className:re("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",t?"translate-x-4":"translate-x-0")})})}function cA({user:t}){const[n,s]=v.useState(!1),r=(t==null?void 0:t.avatar)||(t==null?void 0:t.picture)||(t==null?void 0:t.photoURL)||(t==null?void 0:t.photo);return r&&!n?l.jsx("img",{src:r,alt:"",className:"w-6 h-6 rounded-full",referrerPolicy:"no-referrer",crossOrigin:"anonymous",onError:()=>s(!0)}):l.jsx("div",{className:"w-6 h-6 rounded-full bg-accent/10 flex items-center justify-center",children:l.jsx(ev,{size:12,className:"text-accent"})})}function uA({provider:t,onKeyChange:n}){var k,j,z;const[s,r]=v.useState(!1),[o,u]=v.useState(""),[d,O]=v.useState(!1),[h,p]=v.useState(!1),x=D(N=>N.addToast),g=t.authType==="local",b=t.authType==="subscription",y=g||b?t.installed:t.hasKey;async function Q(){if(o.trim())try{await K.post(`/credentials/${t.id}`,{key:o.trim()}),x("success",`API key set for ${t.name}`),u(""),r(!1),n&&n()}catch(N){x("error","Failed to set key",N.message)}}async function w(){try{await K.delete(`/credentials/${t.id}`),x("info",`Removed ${t.name} key`),n&&n()}catch(N){x("error","Remove failed",N.message)}}if(g){const N=((j=(k=t.models)==null?void 0:k.filter(G=>!G.disabled))==null?void 0:j.length)||0,X=()=>D.getState().setActiveView("models");return l.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[l.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[l.jsx(zs,{status:y&&N>0?"running":"crashed",size:"sm"}),l.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:t.name}),l.jsx("div",{className:"flex-1"}),y&&N>0?l.jsxs(ze,{variant:"success",className:"text-2xs gap-1",children:[l.jsx(Qt,{size:8})," ",N," models"]}):y?l.jsx(ze,{variant:"warning",className:"text-2xs",children:"No models pulled"}):l.jsx(ze,{variant:"default",className:"text-2xs",children:"Not set up"})]}),l.jsx("div",{className:"flex-1",children:h?l.jsxs(l.Fragment,{children:[l.jsx(DS,{isInstalled:y,onModelChange:n}),l.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle flex gap-2",children:[l.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>p(!1),className:"flex-1 h-7 text-2xs",children:"Back"}),l.jsx(ge,{variant:"secondary",size:"sm",onClick:()=>{p(!1),X()},className:"flex-1 h-7 text-2xs gap-1",children:"Models Tab"})]})]}):l.jsxs("div",{className:"px-4 py-3 flex flex-col h-full",children:[l.jsx("div",{className:"text-xs text-text-3 font-sans flex-1",children:y&&N>0?"Full agentic runtime — tool calling, context rotation, zero cloud cost":y?"Ollama is running. Pull a model to start using local agents.":"Run any open-source model locally — free, private, fully offline. Requires Ollama."}),l.jsxs("div",{className:"flex gap-2 mt-3",children:[y?l.jsxs(ge,{variant:"primary",size:"sm",onClick:()=>p(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[l.jsx(Ml,{size:11})," ",N>0?"Manage":"Pull Models"]}):l.jsxs(ge,{variant:"primary",size:"sm",onClick:()=>p(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[l.jsx(Ml,{size:11})," Set Up Ollama"]}),l.jsx(ge,{variant:"secondary",size:"sm",onClick:X,className:"flex-1 h-7 text-2xs gap-1.5",children:"Models Tab"})]})]})})]})}return l.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[l.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[l.jsx(zs,{status:y?"running":"crashed",size:"sm"}),l.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:t.name}),l.jsx("div",{className:"flex-1"}),y?l.jsxs(ze,{variant:"success",className:"text-2xs gap-1",children:[l.jsx(Qt,{size:8})," Ready"]}):l.jsx(ze,{variant:"default",className:"text-2xs",children:b?"Not installed":"No key"})]}),l.jsxs("div",{className:"flex-1 flex flex-col px-4 py-3 min-h-[120px]",children:[((z=t.models)==null?void 0:z.length)>0&&l.jsx("div",{className:"flex flex-wrap gap-1 mb-3",children:t.models.map(N=>l.jsx("span",{className:"px-1.5 py-0.5 rounded bg-surface-4 text-2xs font-mono text-text-3",children:N.name||N.id},N.id))}),b&&y&&!t.hasKey&&!s&&l.jsxs("div",{className:"flex items-center gap-1.5 h-8 px-2.5 bg-accent/8 border border-accent/20 rounded-md text-2xs font-sans text-accent mb-3",children:[l.jsx(Qt,{size:10})," Subscription active"]}),t.hasKey&&!s&&l.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[l.jsxs("div",{className:"flex-1 flex items-center gap-1.5 h-8 px-2.5 bg-success/8 border border-success/20 rounded-md text-2xs font-sans text-success",children:[l.jsx(Qt,{size:10})," API Connected"]}),l.jsx("button",{onClick:()=>{r(!0),O(!1),u("")},className:"text-2xs text-text-4 hover:text-accent cursor-pointer font-sans",children:"Edit"}),l.jsx("button",{onClick:w,className:"text-2xs text-text-4 hover:text-danger cursor-pointer font-sans",children:"Remove"})]}),l.jsx("div",{className:"flex-1"}),s&&l.jsxs("div",{className:"space-y-2.5 pt-1",children:[l.jsxs("div",{children:[l.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:t.hasKey?"Update API Key":`${t.name} API Key`}),l.jsxs("div",{className:"relative",children:[l.jsx("input",{value:o,onChange:N=>u(N.target.value),onKeyDown:N=>N.key==="Enter"&&Q(),type:d?"text":"password",placeholder:"sk-...",className:"w-full h-9 px-3 pr-9 text-xs 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}),l.jsx("button",{onClick:()=>O(!d),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:d?l.jsx(Dc,{size:12}):l.jsx(Es,{size:12})})]})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ge,{variant:"primary",size:"sm",onClick:Q,disabled:!o.trim(),className:"flex-1 h-8 text-xs",children:"Save Key"}),l.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>{r(!1),u("")},className:"h-8 text-xs px-3",children:"Cancel"})]})]}),!s&&!t.hasKey&&l.jsxs(ge,{variant:b?"secondary":"primary",size:"sm",onClick:()=>{r(!0),O(!1),u("")},className:"w-full h-8 text-2xs gap-1.5 mt-2",children:[l.jsx(ri,{size:11}),b?"Add API key for headless mode":"Add API Key"]})]})]})}function $l({icon:t,label:n,description:s,children:r}){return l.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-4 py-3.5 flex flex-col gap-2",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("div",{className:"w-6 h-6 rounded bg-accent/8 flex items-center justify-center flex-shrink-0",children:l.jsx(t,{size:12,className:"text-accent"})}),l.jsx("div",{className:"text-[13px] font-medium text-text-0 font-sans leading-tight",children:n})]}),l.jsx("div",{className:"text-2xs text-text-4 font-sans leading-relaxed",children:s}),l.jsx("div",{className:"mt-auto pt-1",children:r})]})}const IS={telegram:rh,discord:gi,slack:Gb},$s={telegram:"Telegram",discord:"Discord",slack:"Slack"},dA={telegram:"Bot token from @BotFather",discord:"Bot token from Developer Portal",slack:"Bot token (xoxb-...)"},OA=["critical","lifecycle","all"];function fA({type:t,open:n,onOpenChange:s}){if(!t)return null;const o={telegram:{title:"Set Up Telegram",icon:rh,intro:"Create a Telegram bot and connect it to Groove in under 2 minutes. No dependencies required.",sections:[{title:"Create Your Bot",steps:[{text:"Open Telegram on any device and search for",link:"https://t.me/BotFather",linkText:"@BotFather"},{text:"Send /newbot to start the setup"},{text:"Choose a display name — we suggest GroovePilot"},{text:'Choose a username (must end in "bot") — e.g. GroovePilot_bot'},{text:"BotFather will reply with your bot token — copy it"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Telegram card"},{text:"Paste your bot token and click Save"},{text:"The gateway will connect automatically"}]},{title:"Link a Chat",steps:[{text:"Open a chat with your new bot in Telegram"},{text:'Send any message (e.g. "hello") — Groove captures the chat ID automatically'},{text:"Click Test in the gateway card to verify"}]},{title:"Commands",note:"All commands use / prefix in Telegram:",commands:["/instruct <team> <msg>","/query <team> <question>","/plan <description>","/log <team>","/brief","/tokens","/status","/agents","/help"]}]},discord:{title:"Set Up Discord",icon:gi,intro:"Create a Discord bot and add it to your server. Requires discord.js (installed automatically with Groove).",sections:[{title:"Create the Application",steps:[{text:"Go to the",link:"https://discord.com/developers/applications",linkText:"Discord Developer Portal"},{text:"Click New Application and name it GroovePilot"},{text:"Go to the Bot tab in the left sidebar"},{text:"Click Reset Token and copy the bot token"}]},{title:"Set Permissions & Invite",steps:[{text:"Go to OAuth2 > URL Generator"},{text:"Under Scopes, check bot"},{text:"Under Bot Permissions, check:"}],scopes:["Send Messages","Read Message History","Embed Links","Use External Emojis"],after:[{text:"Copy the generated URL at the bottom and open it in your browser"},{text:"Select your server and click Authorize"}]},{title:"Enable Message Content Intent",steps:[{text:"Go back to the Bot tab in the Developer Portal"},{text:"Scroll to Privileged Gateway Intents"},{text:"Enable Message Content Intent — required for the bot to read commands"},{text:"Click Save Changes"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Discord card"},{text:"Paste your bot token and click Save"},{text:"Send a message in any channel where the bot is — Groove captures the channel automatically"}]},{title:"Commands",note:"All commands use / prefix in Discord:",commands:["/instruct <team> <msg>","/query <team> <question>","/plan <description>","/log <team>","/brief","/tokens","/status","/agents","/help"]}]},slack:{title:"Set Up Slack",icon:Gb,intro:"Create a Slack app with Socket Mode — no public URL needed. Requires @slack/bolt (installed automatically with Groove).",sections:[{title:"Create the App",steps:[{text:"Go to",link:"https://api.slack.com/apps",linkText:"api.slack.com/apps"},{text:"Click Create New App > From scratch"},{text:"Name it GroovePilot and select your workspace"}]},{title:"Enable Socket Mode",steps:[{text:"In the left sidebar, go to Settings > Socket Mode"},{text:"Toggle Enable Socket Mode to on"},{text:"It will ask you to create an App-Level Token"},{text:'Name it "groove", add the connections:write scope'},{text:"Click Generate — copy the xapp-... token (this is your App Token)"}],important:"Save this token now — you can't view it again after closing the dialog."},{title:"Set Bot Token Scopes",steps:[{text:"Go to Features > OAuth & Permissions"},{text:"Scroll to Bot Token Scopes and add all of these:"}],scopes:["chat:write","channels:read","channels:history","groups:read","groups:history","im:history","app_mentions:read"],after:[{text:"Scroll up and click Install to Workspace"},{text:"Click Allow to grant permissions"},{text:"Copy the Bot User OAuth Token (xoxb-...) — this is your Bot Token"}]},{title:"Enable Events",steps:[{text:"Go to Features > Event Subscriptions"},{text:"Toggle Enable Events to on"},{text:"Under Subscribe to bot events, add:"}],scopes:["message.channels","message.im","app_mention"],after:[{text:"Click Save Changes at the bottom"}]},{title:"Connect to Groove",steps:[{text:"In Groove Settings > Gateways, click Set Token on the Slack card"},{text:"Paste your Bot Token (xoxb-...) in the first field"},{text:"Paste your App Token (xapp-...) in the second field"},{text:"Click Save — Groove will auto-connect"}]},{title:"Link a Channel",steps:[{text:"Invite the bot to a channel: /invite @GroovePilot"},{text:"Select the channel from the dropdown in the gateway card"},{text:"Or @mention the bot — it will auto-capture the channel"},{text:"Click Test to verify"}],important:"For private channels, make sure you added the groups:read scope."},{title:"Commands",note:"In Slack, use plain text commands (no / prefix) or @mention the bot:",commands:["instruct <team> <msg>","query <team> <question>","plan <description>","log <team>","brief","tokens","status","agents","help","@GroovePilot status"]}]}}[t];if(!o)return null;const u=o.icon;return l.jsx(BS,{open:n,onOpenChange:s,children:l.jsx(HS,{title:o.title,width:480,children:l.jsxs("div",{className:"px-5 py-4 space-y-5",children:[l.jsxs("div",{className:"flex items-start gap-3 p-3 bg-accent/5 border border-accent/15 rounded-lg",children:[l.jsx("div",{className:"w-8 h-8 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:l.jsx(u,{size:16,className:"text-accent"})}),l.jsx("p",{className:"text-xs text-text-2 font-sans leading-relaxed",children:o.intro})]}),o.sections.map((d,O)=>{var h;return l.jsxs("div",{children:[l.jsxs("h3",{className:"text-xs font-semibold text-text-0 font-sans mb-2.5 flex items-center gap-2",children:[l.jsx("span",{className:"w-5 h-5 rounded-full bg-accent/10 flex items-center justify-center text-2xs font-bold text-accent",children:O+1}),d.title]}),d.note&&l.jsx("p",{className:"text-2xs text-text-3 font-sans mb-2",children:d.note}),d.steps&&l.jsx("ol",{className:"space-y-2 mb-2",children:d.steps.map((p,x)=>l.jsxs("li",{className:"flex gap-2 text-2xs text-text-2 font-sans leading-relaxed",children:[l.jsxs("span",{className:"text-text-4 font-mono w-4 flex-shrink-0 pt-px",children:[x+1,"."]}),l.jsxs("span",{children:[p.text,p.link&&l.jsxs(l.Fragment,{children:[" ",l.jsxs("a",{href:p.link,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline inline-flex items-center gap-0.5 font-medium",children:[p.linkText,l.jsx(si,{size:9})]})]})]})]},x))}),d.scopes&&l.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2 ml-6",children:d.scopes.map(p=>l.jsx("code",{className:"px-2 py-0.5 rounded bg-surface-4 text-2xs font-mono text-accent",children:p},p))}),d.after&&l.jsx("ol",{className:"space-y-2 mb-2",start:(((h=d.steps)==null?void 0:h.length)||0)+1,children:d.after.map((p,x)=>{var g;return l.jsxs("li",{className:"flex gap-2 text-2xs text-text-2 font-sans leading-relaxed",children:[l.jsxs("span",{className:"text-text-4 font-mono w-4 flex-shrink-0 pt-px",children:[(((g=d.steps)==null?void 0:g.length)||0)+x+1,"."]}),l.jsx("span",{children:p.text})]},x)})}),d.important&&l.jsx("div",{className:"ml-6 p-2 bg-warning/8 border border-warning/20 rounded-md text-2xs text-warning font-sans",children:d.important}),d.commands&&l.jsx("div",{className:"ml-6 p-2.5 bg-surface-0 border border-border-subtle rounded-md space-y-1",children:d.commands.map(p=>l.jsx("code",{className:"block text-2xs font-mono text-text-1",children:p},p))})]},O)}),l.jsxs("a",{href:"https://docs.groovedev.ai/guide/gateways",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium mt-2",children:[l.jsx(si,{size:10}),"Full documentation at docs.groovedev.ai"]})]})})})}function hA({gateway:t,onRefresh:n}){var se,ie;const[s,r]=v.useState(!1),[o,u]=v.useState(""),[d,O]=v.useState(""),[h,p]=v.useState(!1),[x,g]=v.useState(!1),[b,y]=v.useState(!1),[Q,w]=v.useState([]),[k,j]=v.useState(!1),z=D(W=>W.addToast);v.useEffect(()=>{t.connected&&!t.chatId&&t.type==="slack"&&K.get(`/gateways/${t.id}/channels`).then(W=>w(Array.isArray(W)?W:[])).catch(()=>{})},[t.connected,t.chatId,t.id,t.type]);const N=IS[t.type]||lh,X=t.type==="slack";async function G(){if(o.trim())try{await K.post(`/gateways/${t.id}/credentials`,{key:"bot_token",value:o.trim()}),X&&d.trim()&&await K.post(`/gateways/${t.id}/credentials`,{key:"app_token",value:d.trim()}),z("success","Token saved — connecting..."),u(""),O(""),r(!1);try{await K.post(`/gateways/${t.id}/connect`),z("success",`${$s[t.type]} connected!`)}catch(W){z("error","Token saved but connect failed",W.message)}n()}catch(W){z("error","Failed to save token",W.message)}}async function R(){g(!0);try{await K.post(`/gateways/${t.id}/test`),z("success","Test message sent!")}catch(W){z("error","Test failed",W.message)}g(!1)}async function _(){y(!0);try{t.connected?(await K.post(`/gateways/${t.id}/disconnect`),z("info",`${$s[t.type]} disconnected`)):(await K.post(`/gateways/${t.id}/connect`),z("success",`${$s[t.type]} connected!`)),n()}catch(W){z("error",t.connected?"Disconnect failed":"Connect failed",W.message)}y(!1)}async function T(W){try{await K.patch(`/gateways/${t.id}`,{enabled:W}),n()}catch(P){z("error","Update failed",P.message)}}async function Y(W){try{await K.patch(`/gateways/${t.id}`,{notifications:{preset:W}}),n()}catch(P){z("error","Update failed",P.message)}}async function M(W){try{await K.patch(`/gateways/${t.id}`,{commandPermission:W}),n()}catch(P){z("error","Update failed",P.message)}}async function ae(){try{await K.delete(`/gateways/${t.id}`),z("info",`${$s[t.type]} gateway removed`),n()}catch(W){z("error","Delete failed",W.message)}}const F=((se=t.notifications)==null?void 0:se.preset)||"critical";return l.jsxs("div",{className:"flex flex-col rounded-lg border border-border-subtle bg-surface-1 overflow-hidden min-w-[220px]",children:[l.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[l.jsx(zs,{status:t.connected?"running":"crashed",size:"sm"}),l.jsx(N,{size:13,className:"text-text-2"}),l.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:$s[t.type]}),l.jsx("div",{className:"flex-1"}),t.connected?l.jsxs(ze,{variant:"success",className:"text-2xs gap-1",children:[l.jsx(c1,{size:8})," Connected"]}):t.enabled?l.jsx(ze,{variant:"warning",className:"text-2xs",children:"Disconnected"}):l.jsx(ze,{variant:"default",className:"text-2xs",children:"Disabled"})]}),l.jsxs("div",{className:"flex-1 flex flex-col px-4 py-3 min-h-[140px]",children:[t.connected&&!s&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"flex items-center gap-1.5 h-8 px-2.5 bg-success/8 border border-success/20 rounded-md text-2xs font-sans text-success mb-3",children:[l.jsx(Qt,{size:10})," Gateway active",t.botUsername&&l.jsxs("span",{className:"text-text-4 ml-1",children:["@",t.botUsername]}),t.botTag&&l.jsx("span",{className:"text-text-4 ml-1",children:t.botTag})]}),l.jsxs("div",{className:"mb-3",children:[l.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:t.type==="slack"?"Channel":"Chat ID"}),t.chatId?l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("code",{className:"flex-1 flex items-center h-7 px-2 bg-surface-0 border border-border-subtle rounded-md text-2xs font-mono text-text-2",children:t.type==="slack"&&Q.length>0?`#${((ie=Q.find(W=>W.id===t.chatId))==null?void 0:ie.name)||t.chatId}`:t.chatId}),l.jsx("button",{onClick:async()=>{try{await K.patch(`/gateways/${t.id}`,{chatId:null}),n()}catch(W){z("error","Failed",W.message)}},className:"text-2xs text-text-4 hover:text-text-1 cursor-pointer font-sans",children:"Change"})]}):t.type==="slack"&&Q.length>0?l.jsxs("select",{onChange:async W=>{if(W.target.value)try{await K.patch(`/gateways/${t.id}`,{chatId:W.target.value}),n()}catch(P){z("error","Failed to set channel",P.message)}},className:"w-full h-7 px-2 text-2xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer",defaultValue:"",children:[l.jsx("option",{value:"",disabled:!0,children:"Select a channel..."}),Q.map(W=>l.jsxs("option",{value:W.id,children:["#",W.name]},W.id))]}):l.jsxs("div",{className:"text-2xs text-warning font-sans",children:[t.type==="slack"?"No channels found — invite the bot to a channel first.":"Send a message to the bot to auto-capture, or enter manually:",l.jsx("input",{placeholder:t.type==="slack"?"C0123456789":"Chat ID",className:"mt-1 w-full h-7 px-2 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",onKeyDown:async W=>{if(W.key==="Enter"&&W.target.value.trim())try{await K.patch(`/gateways/${t.id}`,{chatId:W.target.value.trim()}),n()}catch(P){z("error","Failed to set channel",P.message)}}})]})]}),l.jsxs("div",{className:"mb-3",children:[l.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:"Notifications"}),l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:OA.map(W=>l.jsx("button",{onClick:()=>Y(W),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer capitalize",F===W?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:W},W))})]}),l.jsxs("div",{className:"mb-3",children:[l.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans mb-1.5 block",children:"Commands"}),l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:["full","read-only"].map(W=>l.jsx("button",{onClick:()=>M(W),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer capitalize",(t.commandPermission||"full")===W?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:W==="full"?"Full Access":"Read Only"},W))})]})]}),!t.connected&&!s&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"text-xs text-text-3 font-sans mb-2",children:t.enabled?t.hasCredentials?"Tokens saved — click Connect.":"Configure bot token to connect.":"Gateway is disabled."}),!t.hasCredentials&&l.jsxs("button",{onClick:()=>j(!0),className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer mb-2",children:[l.jsx(yc,{size:11}),"How to set up",l.jsx(si,{size:9})]})]}),l.jsx(fA,{type:t.type,open:k,onOpenChange:j}),l.jsx("div",{className:"flex-1"}),s&&l.jsxs("div",{className:"space-y-2.5 pt-1",children:[l.jsxs("button",{onClick:()=>j(!0),className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer",children:[l.jsx(yc,{size:11}),"Where do I get these?"]}),l.jsxs("div",{children:[l.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:"Bot Token"}),l.jsxs("div",{className:"relative",children:[l.jsx("input",{value:o,onChange:W=>u(W.target.value),onKeyDown:W=>W.key==="Enter"&&!X&&G(),type:h?"text":"password",placeholder:dA[t.type],className:"w-full h-9 px-3 pr-9 text-xs 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}),l.jsx("button",{onClick:()=>p(!h),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:h?l.jsx(Dc,{size:12}):l.jsx(Es,{size:12})})]})]}),X&&l.jsxs("div",{children:[l.jsx("label",{className:"text-2xs font-semibold text-text-2 font-sans mb-1.5 block",children:"App Token (Socket Mode)"}),l.jsx("input",{value:d,onChange:W=>O(W.target.value),onKeyDown:W=>W.key==="Enter"&&G(),type:h?"text":"password",placeholder:"xapp-...",className:"w-full h-9 px-3 text-xs 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"})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(ge,{variant:"primary",size:"sm",onClick:G,disabled:!o.trim(),className:"flex-1 h-8 text-xs",children:"Save Token"}),l.jsx(ge,{variant:"ghost",size:"sm",onClick:()=>{r(!1),u(""),O("")},className:"h-8 text-xs px-3",children:"Cancel"})]})]}),!s&&l.jsxs("div",{className:"flex gap-2 mt-2",children:[!t.connected&&l.jsxs(ge,{variant:"primary",size:"sm",onClick:()=>r(!0),className:"flex-1 h-7 text-2xs gap-1.5",children:[l.jsx(ri,{size:11}),t.enabled?"Set Token":"Configure"]}),t.connected&&l.jsxs(l.Fragment,{children:[l.jsxs(ge,{variant:"secondary",size:"sm",onClick:R,disabled:x,className:"flex-1 h-7 text-2xs gap-1.5",children:[l.jsx(oh,{size:11}),x?"Sending...":"Test"]}),l.jsx(ge,{variant:"secondary",size:"sm",onClick:()=>r(!0),className:"h-7 text-2xs px-2.5",children:l.jsx(ri,{size:11})})]}),l.jsx(ge,{variant:"ghost",size:"sm",onClick:_,disabled:b,className:"h-7 text-2xs px-2.5",title:t.connected?"Disconnect":"Connect",children:t.connected?l.jsx(Wb,{size:11}):l.jsx(c1,{size:11})}),l.jsx(oA,{value:t.enabled,onChange:T}),l.jsx("button",{onClick:ae,className:"text-text-4 hover:text-danger cursor-pointer p-1",title:"Remove gateway",children:l.jsx(_n,{size:11})})]})]})]})}function mA({existingTypes:t,onAdd:n}){const[s,r]=v.useState(!1),o=["telegram","discord","slack"].filter(u=>!t.includes(u));return o.length===0?null:s?l.jsxs("div",{className:"flex flex-col rounded-lg border border-accent/30 bg-surface-1 overflow-hidden min-w-[220px]",children:[l.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border-subtle",children:[l.jsx(lh,{size:13,className:"text-accent"}),l.jsx("span",{className:"text-[13px] font-semibold text-text-0 font-sans",children:"Add Gateway"}),l.jsx("div",{className:"flex-1"}),l.jsx("button",{onClick:()=>r(!1),className:"text-text-4 hover:text-text-1 cursor-pointer",children:l.jsx(jt,{size:12})})]}),l.jsx("div",{className:"p-3 space-y-2",children:o.map(u=>{const d=IS[u];return l.jsxs("button",{onClick:()=>{n(u),r(!1)},className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-0 hover:bg-accent/8 border border-border-subtle hover:border-accent/20 cursor-pointer transition-all group",children:[l.jsx(d,{size:14,className:"text-text-3 group-hover:text-accent"}),l.jsx("span",{className:"text-xs font-medium text-text-1 group-hover:text-accent font-sans",children:$s[u]})]},u)})})]}):l.jsxs("button",{onClick:()=>r(!0),className:"flex flex-col items-center justify-center rounded-lg border border-dashed border-border-subtle bg-surface-1/50 hover:bg-surface-1 hover:border-accent/30 min-h-[140px] min-w-[220px] cursor-pointer transition-all group",children:[l.jsx("div",{className:"w-8 h-8 rounded-full bg-accent/8 group-hover:bg-accent/15 flex items-center justify-center mb-2 transition-colors",children:l.jsx(es,{size:14,className:"text-accent"})}),l.jsx("span",{className:"text-2xs font-semibold text-text-3 group-hover:text-text-1 font-sans transition-colors",children:"Add Gateway"})]})}function pA(){const[t,n]=v.useState([]),[s,r]=v.useState(null),[o,u]=v.useState(null),[d,O]=v.useState([]),[h,p]=v.useState(!0),[x,g]=v.useState(!1),b=D(_=>_.addToast),y=D(_=>_.marketplaceUser),Q=D(_=>_.marketplaceAuthenticated),w=D(_=>_.marketplaceLogin),k=D(_=>_.marketplaceLogout);function j(){K.get("/providers").then(_=>n(Array.isArray(_)?_:[])).catch(()=>{})}function z(){K.get("/gateways").then(_=>O(Array.isArray(_)?_:[])).catch(()=>{})}v.useEffect(()=>{Promise.all([K.get("/providers"),K.get("/config"),K.get("/status"),K.get("/gateways")]).then(([_,T,Y,M])=>{n(Array.isArray(_)?_:[]),r(T),u(Y),O(Array.isArray(M)?M:[]),p(!1)}).catch(()=>p(!1))},[]);async function N(_){try{await K.post("/gateways",{type:_}),b("success",`${$s[_]} gateway added`),z()}catch(T){b("error","Failed to add gateway",T.message)}}async function X(_,T){try{const Y=await K.patch("/config",{[_]:T});r(Y)}catch(Y){b("error","Update failed",Y.message)}}if(h)return l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsx("div",{className:"h-12 bg-surface-1 border-b border-border"}),l.jsxs("div",{className:"flex-1 p-4 space-y-4",children:[l.jsx("div",{className:"grid grid-cols-4 gap-3",children:[...Array(4)].map((_,T)=>l.jsx(on,{className:"h-40 rounded-lg"},T))}),l.jsx("div",{className:"grid grid-cols-3 gap-3",children:[...Array(6)].map((_,T)=>l.jsx(on,{className:"h-28 rounded-lg"},T))})]})]});const G=t.filter(_=>_.authType==="local"||_.authType==="subscription"?_.installed:_.hasKey).length,R=(s==null?void 0:s.rotationThreshold)||0;return l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsxs("div",{className:"flex items-center gap-4 px-4 py-2.5 bg-surface-1 border-b border-border flex-shrink-0",children:[l.jsx("h2",{className:"text-sm font-semibold text-text-0 font-sans",children:"Settings"}),l.jsx("div",{className:"flex-1"}),l.jsxs("div",{className:"flex items-center gap-4 text-2xs text-text-3 font-sans",children:[(o==null?void 0:o.version)&&l.jsxs("span",{children:["v",o.version]}),(o==null?void 0:o.port)&&l.jsxs("span",{children:[":",o.port]}),(o==null?void 0:o.uptime)>0&&l.jsxs("span",{children:["Up ",Hc(o.uptime)]})]}),l.jsx("div",{className:"w-px h-4 bg-border-subtle"}),Q?l.jsxs("div",{className:"flex items-center gap-2.5",children:[l.jsx(cA,{user:y}),l.jsx("span",{className:"text-xs font-medium text-text-0 font-sans",children:(y==null?void 0:y.displayName)||"User"}),l.jsxs("button",{onClick:k,className:"text-2xs text-text-4 hover:text-text-1 cursor-pointer font-sans flex items-center gap-1",children:[l.jsx(Vb,{size:10})," Sign out"]})]}):l.jsxs(ge,{variant:"ghost",size:"sm",onClick:w,className:"h-7 text-2xs gap-1.5 text-text-3",children:[l.jsx(ah,{size:11})," Sign in"]}),l.jsx(zs,{status:"running",size:"sm"})]}),l.jsx(ma,{className:"flex-1",children:l.jsxs("div",{className:"p-4 space-y-4",children:[l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[l.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Providers"}),l.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),l.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:[G,"/",t.length," connected"]})]}),l.jsx("div",{className:"grid grid-cols-4 gap-3",children:t.map(_=>l.jsx(uA,{provider:_,onKeyChange:j},_.id))})]}),l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[l.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Gateways"}),l.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),l.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:[d.filter(_=>_.connected).length,"/",d.length," connected"]})]}),l.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[d.map(_=>l.jsx(hA,{gateway:_,onRefresh:z},_.id)),l.jsx(mA,{existingTypes:d.map(_=>_.type),onAdd:N})]})]}),s&&l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 mb-2.5 px-0.5",children:[l.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Configuration"}),l.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),l.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Auto-saves"})]}),l.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[l.jsx($l,{icon:Ml,label:"Default Provider",description:"Provider used when spawning new agents.",children:l.jsx("select",{value:s.defaultProvider||"claude-code",onChange:_=>X("defaultProvider",_.target.value),className:"w-full h-8 px-2.5 text-xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer",children:t.filter(_=>_.installed||_.hasKey).map(_=>l.jsx("option",{value:_.id,children:_.name},_.id))})}),l.jsx($l,{icon:li,label:"Working Directory",description:"Default root directory for new agents.",children:l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("code",{className:"flex-1 h-8 px-2 flex items-center bg-surface-0 border border-border-subtle rounded-md text-2xs font-mono text-text-2 truncate min-w-0",children:s.defaultWorkingDir||"Project root"}),l.jsx(ge,{variant:"secondary",size:"sm",onClick:()=>g(!0),className:"h-8 px-2 flex-shrink-0",children:l.jsx(qb,{size:12})})]})}),l.jsx($l,{icon:Yb,label:"Rotation Threshold",description:"Context usage that triggers auto-rotation.",children:l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:["auto","50%","65%","75%","85%"].map(_=>{const T=_==="auto"?0:parseInt(_,10)/100,Y=R===T;return l.jsx("button",{onClick:()=>X("rotationThreshold",T),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",Y?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:_==="auto"?"Auto":_},_)})})}),l.jsx($l,{icon:Kb,label:"QC Threshold",description:"Running agents count that triggers auto-QC.",children:l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[2,3,4,6,8].map(_=>{const T=(s.qcThreshold||2)===_;return l.jsx("button",{onClick:()=>X("qcThreshold",_),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",T?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:_},_)})})}),l.jsx($l,{icon:yi,label:"Max Agents",description:"Concurrent agent limit. 0 = unlimited.",children:l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[0,4,8,12,20].map(_=>{const T=(s.maxAgents||0)===_;return l.jsx("button",{onClick:()=>X("maxAgents",_),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",T?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:_===0?"∞":_},_)})})}),l.jsx($l,{icon:ii,label:"Journalist Interval",description:"Seconds between synthesis cycles.",children:l.jsx("div",{className:"flex bg-surface-0 rounded-md p-0.5 border border-border-subtle",children:[60,120,300,600].map(_=>{const T=(s.journalistInterval||120)===_,Y=_<60?`${_}s`:`${_/60}m`;return l.jsx("button",{onClick:()=>X("journalistInterval",_),className:re("flex-1 px-2 py-1.5 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",T?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:Y},_)})})})]})]})]})}),l.jsx(WS,{open:x,onOpenChange:g,currentPath:(s==null?void 0:s.defaultWorkingDir)||"/",onSelect:_=>X("defaultWorkingDir",_)})]})}function Xc(t){return t?t<1024*1024?`${(t/1024).toFixed(0)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(2)} GB`:"—"}function xA(t){return t?t<1024*1024?`${(t/1024).toFixed(0)} KB/s`:`${(t/(1024*1024)).toFixed(1)} MB/s`:""}function gA({hardware:t}){var n;return t?l.jsxs("div",{className:"flex items-center gap-4 px-4 py-2.5 bg-surface-1 border border-border-subtle rounded-lg text-xs font-sans text-text-2",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(YT,{size:14,className:"text-text-3"}),l.jsxs("span",{children:[t.totalRamGb," GB RAM"]})]}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(Ml,{size:14,className:"text-text-3"}),l.jsxs("span",{children:[t.cores," cores"]})]}),t.gpu&&l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(nh,{size:14,className:"text-text-3"}),l.jsxs("span",{children:[t.gpu.name,t.gpu.vram?` (${t.gpu.vram} GB)`:""]})]}),((n=t.recommended)==null?void 0:n.code)&&l.jsxs("div",{className:"ml-auto text-accent",children:["Recommended: ",t.recommended.code]})]}):null}function bA({download:t}){const n=Math.round((t.percent||0)*100);return l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex items-center justify-between text-2xs font-sans text-text-3",children:[l.jsx("span",{children:t.filename}),l.jsxs("span",{children:[n,"% ",xA(t.speed)]})]}),l.jsx("div",{className:"h-1.5 bg-surface-3 rounded-full overflow-hidden",children:l.jsx("div",{className:"h-full bg-accent rounded-full transition-all",style:{width:`${n}%`}})}),l.jsxs("div",{className:"text-2xs text-text-4",children:[Xc(t.downloaded)," / ",Xc(t.totalBytes)]})]})}function vA({model:t,onDelete:n}){const[s,r]=v.useState(!1),o={light:"text-green-400",medium:"text-blue-400",heavy:"text-orange-400"};return l.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-surface-1 border border-border-subtle rounded-lg",children:[l.jsx(th,{size:18,className:"text-accent flex-shrink-0"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate",children:t.id}),t.quantization&&l.jsx(ze,{variant:"subtle",className:"text-2xs",children:t.quantization}),t.parameters&&l.jsx(ze,{variant:"subtle",className:"text-2xs",children:t.parameters}),l.jsx("span",{className:re("text-2xs font-medium capitalize",o[t.tier]||"text-text-3"),children:t.tier})]}),l.jsxs("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:[Xc(t.sizeBytes)," · ctx ",(t.contextWindow||0).toLocaleString()," · ",t.category,t.repoId&&l.jsxs("span",{className:"text-text-4",children:[" · ",t.repoId]})]})]}),l.jsx("button",{onClick:async()=>{r(!0),await n(t.id),r(!1)},disabled:s,className:"p-1.5 rounded-md text-text-4 hover:text-red-400 hover:bg-red-400/10 transition-colors",children:s?l.jsx(Ct,{size:14,className:"animate-spin"}):l.jsx(_n,{size:14})})]})}function yA({result:t,onExpand:n,expanded:s}){var r;return l.jsxs("button",{onClick:()=>n(s?null:t.id),className:"w-full text-left px-4 py-3 bg-surface-1 border border-border-subtle rounded-lg hover:border-accent/30 transition-colors cursor-pointer",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate flex-1",children:t.name}),l.jsx("span",{className:"text-2xs text-text-4 font-sans",children:t.author}),s?l.jsx(zn,{size:14,className:"text-text-3"}):l.jsx(as,{size:14,className:"text-text-3"})]}),l.jsxs("div",{className:"text-2xs text-text-3 font-sans mt-0.5 flex gap-3",children:[l.jsxs("span",{children:[(r=t.downloads)==null?void 0:r.toLocaleString()," downloads"]}),l.jsxs("span",{children:[t.likes," likes"]})]})]})}function SA({repoId:t,onDownload:n,systemRamGb:s}){const[r,o]=v.useState(null),[u,d]=v.useState(!0),[O,h]=v.useState(null),p=ls();v.useEffect(()=>{d(!0),K.get(`/models/${t}/files`).then(g=>o(g.files||[])).catch(()=>p.error("Failed to load model files")).finally(()=>d(!1))},[t]);async function x(g){h(g.filename);try{await K.post("/models/download",{repoId:t,filename:g.filename}),p.success(`Downloading ${g.filename}`),n==null||n(g.filename)}catch(b){p.error(b.message)}h(null)}return u?l.jsx("div",{className:"py-3 px-4 text-2xs text-text-4 font-sans",children:"Loading quantization variants..."}):r!=null&&r.length?l.jsx("div",{className:"pl-6 pr-4 pb-2 space-y-1.5",children:r.map(g=>{const b=!g.estimatedRamGb||!s||g.estimatedRamGb<=s,y=g.estimatedRamGb&&s&&g.estimatedRamGb>s*.8&&b;return l.jsxs("div",{className:re("flex items-center gap-2 py-1.5 px-3 rounded-md text-xs font-sans",b?"bg-surface-2":"bg-red-500/5 border border-red-500/15"),children:[l.jsx("span",{className:"font-mono text-text-1 truncate flex-1",children:g.filename}),g.quantization&&l.jsx(ze,{variant:"subtle",className:"text-2xs",children:g.quantization}),l.jsx("span",{className:"text-text-2 text-2xs w-16 text-right",children:Xc(g.size)}),g.estimatedRamGb&&l.jsxs("span",{className:re("text-2xs w-20 text-right font-medium",b?y?"text-yellow-400":"text-green-400":"text-red-400"),children:["~",g.estimatedRamGb," GB RAM"]}),!b&&l.jsx("span",{className:"text-2xs text-red-400 font-medium",children:"too large"}),l.jsx("button",{onClick:()=>x(g),disabled:O===g.filename||!b,className:re("p-1 rounded transition-colors",b?"text-accent hover:bg-accent/10":"text-text-4 cursor-not-allowed","disabled:opacity-40"),children:O===g.filename?l.jsx(Ct,{size:13,className:"animate-spin"}):l.jsx(xi,{size:13})})]},g.filename)})}):l.jsx("div",{className:"py-3 px-4 text-2xs text-text-4 font-sans",children:"No GGUF files found in this repo."})}function QA({model:t,systemRamGb:n,onPull:s,pulling:r,isInstalled:o}){const u={light:"text-green-400",medium:"text-blue-400",heavy:"text-orange-400"},d={code:"{}",general:"AI"},O=n?Math.round((1-t.ramGb/n)*100):null;return l.jsxs("div",{className:re("flex items-center gap-3 px-4 py-3 border rounded-lg transition-colors",o?"bg-success/5 border-success/20":"bg-surface-1 border-border-subtle hover:border-accent/20"),children:[l.jsx("div",{className:"w-9 h-9 rounded-lg bg-surface-3 flex items-center justify-center text-xs font-mono text-text-2 flex-shrink-0",children:d[t.category]||"AI"}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm font-mono font-bold text-text-0 truncate",children:t.name}),l.jsx("span",{className:re("text-2xs font-semibold capitalize",u[t.tier]),children:t.tier}),o&&l.jsxs(ze,{variant:"success",className:"text-2xs gap-1",children:[l.jsx(Qt,{size:8})," Installed"]})]}),l.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:t.description}),l.jsxs("div",{className:"flex items-center gap-3 mt-1 text-2xs font-sans",children:[l.jsxs("span",{className:"text-text-2",children:[t.sizeGb," GB download"]}),l.jsxs("span",{className:"text-green-400 font-medium",children:[t.ramGb," GB RAM"]}),O!==null&&l.jsxs("span",{className:"text-text-4",children:[O,"% headroom"]})]})]}),o?l.jsx("span",{className:"text-xs text-success font-sans font-medium px-3 py-1.5",children:"Ready"}):l.jsxs("button",{onClick:()=>s(t.id),disabled:r===t.id,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-sans font-medium bg-accent/10 text-accent hover:bg-accent/20 transition-colors cursor-pointer disabled:opacity-40",children:[r===t.id?l.jsx(Ct,{size:12,className:"animate-spin"}):l.jsx(xi,{size:12}),"Pull"]})]})}function jA(){const[t,n]=v.useState("recommended"),[s,r]=v.useState(""),[o,u]=v.useState([]),[d,O]=v.useState(!1),[h,p]=v.useState([]),[x,g]=v.useState([]),[b,y]=v.useState([]),[Q,w]=v.useState(null),[k,j]=v.useState(null),[z,N]=v.useState(null),[X,G]=v.useState([]),R=ls(),_=v.useCallback(()=>{K.get("/models/installed").then(F=>{p(F.models||[])}).catch(()=>{})},[]),T=v.useCallback(()=>{K.get("/providers/ollama/models").then(F=>{G((F.installed||[]).map(se=>se.id))}).catch(()=>{})},[]);v.useEffect(()=>{K.get("/providers/ollama/hardware").then(w).catch(()=>{}),K.get("/models/recommended").then(F=>{g(F.models||[]),!Q&&F.hardware&&w(F.hardware)}).catch(()=>{}),_(),T()},[_,T]);async function Y(F){N(F);try{await K.post("/providers/ollama/pull",{model:F}),R.success(`${F} ready to use`),_(),T(),G(se=>[...se,F])}catch(se){R.error(`Pull failed: ${se.message}`)}N(null)}v.useEffect(()=>{const F=D.subscribe((ie,W)=>{}),se=setInterval(()=>{K.get("/models/downloads").then(y).catch(()=>{})},2e3);return()=>{F(),clearInterval(se)}},[]),v.useEffect(()=>{function F(ie){try{const W=JSON.parse(ie.data);W.type==="model:download:progress"&&y(P=>{const B=P.findIndex(E=>E.filename===W.data.filename);if(B>=0){const E=[...P];return E[B]=W.data,E}return[...P,W.data]}),W.type==="model:download:complete"&&(y(P=>P.filter(B=>B.filename!==W.data.filename)),_(),R.success(`${W.data.filename} downloaded`)),W.type==="model:download:error"&&(y(P=>P.filter(B=>B.filename!==W.data.filename)),R.error(`Download failed: ${W.data.error}`))}catch{}}const se=D.getState()._ws;return se&&se.addEventListener("message",F),()=>{se&&se.removeEventListener("message",F)}},[_,R]);async function M(){if(s.trim()){O(!0),n("search");try{const F=await K.get(`/models/search?q=${encodeURIComponent(s.trim())}`);u(F)}catch(F){R.error(F.message)}O(!1)}}async function ae(F){try{await K.delete(`/models/${F}`),p(se=>se.filter(ie=>ie.id!==F)),R.success("Model deleted")}catch(se){R.error(se.message)}}return l.jsxs("div",{className:"h-full flex flex-col bg-surface-0",children:[l.jsxs("div",{className:"flex-shrink-0 px-5 pt-4 pb-3 border-b border-border space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("h1",{className:"text-base font-bold font-sans text-text-0",children:"Local Models"}),l.jsxs(ze,{variant:"subtle",className:"text-2xs",children:[h.length," installed"]})]}),l.jsx(gA,{hardware:Q}),l.jsxs("div",{className:"flex gap-2",children:[l.jsxs("div",{className:"relative flex-1",children:[l.jsx(fa,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4"}),l.jsx("input",{value:s,onChange:F=>r(F.target.value),onKeyDown:F=>F.key==="Enter"&&M(),placeholder:"Search HuggingFace for GGUF models...",className:"w-full h-8 pl-9 pr-3 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"})]}),l.jsx(ge,{onClick:M,disabled:d,size:"sm",variant:"accent",children:d?l.jsx(Ct,{size:14,className:"animate-spin"}):"Search"})]}),l.jsx("div",{className:"flex gap-1",children:[{id:"recommended",label:`Recommended (${x.length})`},{id:"installed",label:`Installed (${h.length})`},{id:"search",label:`Search (${o.length})`}].map(F=>l.jsx("button",{onClick:()=>n(F.id),className:re("px-3 py-1 rounded-md text-xs font-sans font-medium transition-colors cursor-pointer",t===F.id?"bg-accent/12 text-accent":"text-text-3 hover:text-text-1 hover:bg-surface-3"),children:F.label},F.id))})]}),b.length>0&&l.jsxs("div",{className:"px-5 py-3 border-b border-border space-y-2",children:[l.jsx("div",{className:"text-xs font-sans font-semibold text-text-2",children:"Downloading"}),b.map(F=>l.jsx(bA,{download:F},F.filename))]}),l.jsx(ma,{className:"flex-1",children:l.jsxs("div",{className:"px-5 py-4 space-y-2",children:[t==="recommended"&&l.jsx(l.Fragment,{children:x.length===0?l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Ml,{size:40,className:"mx-auto text-text-4 mb-3"}),l.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"Detecting hardware..."}),l.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Make sure Ollama is installed so we can check your system."})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"text-xs text-text-3 font-sans mb-2",children:["Top models for your system (",(Q==null?void 0:Q.totalRamGb)||"?"," GB RAM). Click Pull to download via Ollama."]}),x.map(F=>{const se=F.id.split(":")[0],ie=X.some(W=>W===F.id||W.startsWith(se+":")||W===se);return l.jsx(QA,{model:F,systemRamGb:Q==null?void 0:Q.totalRamGb,onPull:Y,pulling:z,isInstalled:ie},F.id)})]})}),t==="installed"&&l.jsx(l.Fragment,{children:h.length===0?l.jsxs("div",{className:"text-center py-12",children:[l.jsx(th,{size:40,className:"mx-auto text-text-4 mb-3"}),l.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"No local models yet"}),l.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Search HuggingFace to download GGUF models, or pull models via Ollama."})]}):h.map(F=>l.jsx(vA,{model:F,onDelete:ae},F.id))}),t==="search"&&l.jsx(l.Fragment,{children:d?l.jsxs("div",{className:"text-center py-12",children:[l.jsx(Ct,{size:24,className:"mx-auto text-accent animate-spin mb-3"}),l.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Searching HuggingFace..."})]}):o.length===0?l.jsxs("div",{className:"text-center py-12",children:[l.jsx(fa,{size:40,className:"mx-auto text-text-4 mb-3"}),l.jsx("p",{className:"text-sm text-text-2 font-sans font-medium",children:"Search for GGUF models"}),l.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:'Try "qwen coder", "deepseek", "codestral", "llama"'})]}):o.map(F=>l.jsxs("div",{className:"space-y-1",children:[l.jsx(yA,{result:F,expanded:k===F.id,onExpand:j}),k===F.id&&l.jsx(SA,{repoId:F.id,onDownload:()=>_(),systemRamGb:Q==null?void 0:Q.totalRamGb})]},F.id))})]})})]})}const k0=["Reading through the codebase...","Thinking through your request...","Planning the approach...","Running tool calls...","Working through the problem...","Reasoning step by step...","Reviewing context...","Considering options...","Analyzing the code...","Making progress..."];function wA({agent:t,className:n}){const[s,r]=v.useState(0),[o,u]=v.useState(!0);return v.useEffect(()=>{const d=setInterval(()=>{u(!1),setTimeout(()=>{r(O=>(O+1)%k0.length),u(!0)},250)},2800);return()=>clearInterval(d)},[]),l.jsxs("div",{className:`${n||""}`,children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx("span",{className:"text-2xs font-semibold text-text-1 font-sans",children:(t==null?void 0:t.name)||"Agent"}),l.jsx("span",{className:"text-2xs text-accent font-mono",children:"thinking"})]}),l.jsxs("div",{className:"border-l border-accent/40 pl-3.5 py-1 flex items-center gap-2.5",children:[l.jsx("div",{className:"relative w-3.5 h-3.5 flex-shrink-0",children:l.jsx("span",{className:"absolute inset-0 rounded-full border border-transparent border-t-accent animate-spin",style:{animationDuration:"0.9s"}})}),l.jsx("span",{className:"text-[12px] font-sans text-text-3 transition-opacity duration-[250ms]",style:{opacity:o?1:0},children:k0[s]})]})]})}const Af=[];function FS(t){const n=(t||"").toLowerCase();return n.includes("reading")||n.includes("read ")?{icon:Es,color:"text-info",label:"Reading"}:n.includes("editing")||n.includes("wrote")||n.includes("writing")||n.includes("edit ")?{icon:Eb,color:"text-warning",label:"Editing"}:n.includes("searching")||n.includes("search")||n.includes("grep")||n.includes("glob")?{icon:fa,color:"text-purple",label:"Searching"}:n.includes("running")||n.includes("bash")||n.includes("command")||n.includes("exec")?{icon:bi,color:"text-orange",label:"Running"}:n.includes("test")||n.includes("pass")?{icon:vf,color:"text-success",label:"Testing"}:n.includes("error")||n.includes("fail")||n.includes("crash")?{icon:Oa,color:"text-danger",label:"Error"}:n.includes("rotat")?{icon:Il,color:"text-accent",label:"Rotating"}:n.includes("spawn")||n.includes("start")?{icon:Xn,color:"text-success",label:"Spawned"}:n.includes("tool")||n.includes("function")?{icon:GN,color:"text-text-2",label:"Tool"}:n.includes("complet")||n.includes("done")||n.includes("finish")?{icon:vf,color:"text-success",label:"Done"}:{icon:ss,color:"text-text-3",label:"Activity"}}function Nl({text:t}){return t?t.split(/(\*\*[^*]+\*\*|`[^`]+`)/g).map((n,s)=>n.startsWith("**")&&n.endsWith("**")?l.jsx("strong",{className:"font-semibold text-text-0",children:n.slice(2,-2)},s):n.startsWith("`")&&n.endsWith("`")?l.jsx("code",{className:"px-1 py-px rounded bg-accent/8 text-[11px] font-mono text-accent",children:n.slice(1,-1)},s):l.jsx("span",{children:n},s)):null}function kA({text:t}){if(!t)return null;const n=[],s=t.split(`
633
633
  `);let r=0;for(;r<s.length;){const o=s[r];if(o.trimStart().startsWith("```")){const d=[],O=o.trim().slice(3);for(r++;r<s.length&&!s[r].trimStart().startsWith("```");)d.push(s[r]),r++;r++,n.push({type:"code",content:d.join(`
634
634
  `),lang:O});continue}if(/^#{1,3}\s/.test(o)||/^\*\*[^*]+:\*\*\s*$/.test(o.trim())){const d=o.replace(/^#+\s*/,"").replace(/^\*\*/,"").replace(/:\*\*\s*$/,":").trim();n.push({type:"heading",content:d}),r++;continue}if(/^\s*[-*]\s/.test(o)){const d=[];for(;r<s.length&&/^\s*[-*]\s/.test(s[r]);)d.push(s[r].replace(/^\s*[-*]\s+/,"").trim()),r++;n.push({type:"list",items:d});continue}if(/^\s*\d+[\.)]\s/.test(o)){const d=[];for(;r<s.length&&/^\s*\d+[\.)]\s/.test(s[r]);)d.push(s[r].replace(/^\s*\d+[\.)]\s+/,"").trim()),r++;n.push({type:"numbered",items:d});continue}if(!o.trim()){r++;continue}if(/^(Note|Warning|Important|IMPORTANT|TODO):/i.test(o.trim())){n.push({type:"note",content:o.trim()}),r++;continue}const u=[];for(;r<s.length&&s[r].trim()&&!/^#{1,3}\s/.test(s[r])&&!/^\s*[-*]\s/.test(s[r])&&!/^\s*\d+[\.)]\s/.test(s[r])&&!s[r].trimStart().startsWith("```");)u.push(s[r].trim()),r++;u.length>0&&n.push({type:"para",content:u.join(" ")})}return l.jsx("div",{className:"space-y-2",children:n.map((o,u)=>{switch(o.type){case"heading":return l.jsxs("div",{className:"flex items-center gap-1.5 pt-1.5 first:pt-0",children:[l.jsx("div",{className:"w-1 h-3.5 rounded-full bg-accent/40 flex-shrink-0"}),l.jsx("span",{className:"text-[12px] font-semibold text-text-0 font-sans",children:l.jsx(Nl,{text:o.content})})]},u);case"list":return l.jsx("div",{className:"space-y-1 pl-2",children:o.items.map((d,O)=>l.jsxs("div",{className:"flex gap-2 text-[12px] text-text-0 font-sans leading-relaxed",children:[l.jsx("span",{className:"text-accent/50 mt-0.5 flex-shrink-0",children:"-"}),l.jsx("span",{className:"min-w-0",children:l.jsx(Nl,{text:d})})]},O))},u);case"numbered":return l.jsx("div",{className:"space-y-1 pl-2",children:o.items.map((d,O)=>l.jsxs("div",{className:"flex gap-2 text-[12px] text-text-0 font-sans leading-relaxed",children:[l.jsxs("span",{className:"text-text-4 font-mono w-4 text-right flex-shrink-0",children:[O+1,"."]}),l.jsx("span",{className:"min-w-0",children:l.jsx(Nl,{text:d})})]},O))},u);case"code":return l.jsx("pre",{className:"p-2.5 rounded-md bg-[#0d1117] text-[11px] font-mono text-[#c9d1d9] overflow-x-auto whitespace-pre-wrap border border-white/[0.06] leading-relaxed",children:o.content},u);case"note":return l.jsxs("div",{className:"flex items-start gap-1.5 px-2.5 py-1.5 rounded-md bg-warning/6 border border-warning/12",children:[l.jsx(Oa,{size:10,className:"text-warning mt-0.5 flex-shrink-0"}),l.jsx("span",{className:"text-[11px] text-warning/80 font-sans",children:l.jsx(Nl,{text:o.content})})]},u);case"para":default:return l.jsx("p",{className:"text-[12px] text-text-0 font-sans leading-relaxed",children:l.jsx(Nl,{text:o.content})},u)}})})}function $A({text:t}){if(!t)return null;const n=t.split(/(```[\s\S]*?```)/g);return l.jsx("span",{children:n.map((s,r)=>{if(s.startsWith("```")&&s.endsWith("```")){const o=s.slice(3,-3).replace(/^\w+\n/,"");return l.jsx("pre",{className:"my-1.5 p-2 rounded-md bg-[#0d1117] text-[11px] font-mono text-[#c9d1d9] overflow-x-auto whitespace-pre-wrap border border-white/[0.06]",children:o},r)}return l.jsx("span",{children:l.jsx(Nl,{text:s})},r)})})}function TA({msg:t}){const n=t.isQuery;return l.jsx("div",{className:"flex justify-end pl-8",children:l.jsxs("div",{className:"max-w-[90%]",children:[n&&l.jsxs("div",{className:"flex items-center justify-end gap-1 mb-1",children:[l.jsx(yc,{size:9,className:"text-info"}),l.jsx("span",{className:"text-2xs text-info font-sans font-medium",children:"Query"})]}),l.jsx("div",{className:re("px-3.5 py-2.5 rounded-lg border","bg-info/10 border-info/25"),children:l.jsx("div",{className:"text-[12px] font-sans whitespace-pre-wrap break-words leading-relaxed text-text-0",children:l.jsx($A,{text:t.text})})}),l.jsx("div",{className:"text-[10px] text-text-4 font-sans mt-1 text-right",children:vt(t.timestamp)})]})})}function NA({msg:t,agent:n}){var u,d;const[s,r]=v.useState(((u=t.text)==null?void 0:u.length)>600),o=((d=t.text)==null?void 0:d.length)>600;return l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsx("span",{className:"text-2xs font-semibold text-text-1 font-sans",children:(n==null?void 0:n.name)||"Agent"}),l.jsx("span",{className:"text-2xs text-text-4 font-sans",children:n==null?void 0:n.role}),l.jsx("span",{className:"text-[10px] text-text-4 font-sans ml-auto",children:vt(t.timestamp)})]}),l.jsx("div",{className:"border-l border-accent pl-3.5 py-1",children:l.jsx(kA,{text:s?t.text.slice(0,600)+"...":t.text})}),s&&l.jsxs("button",{onClick:()=>r(!1),className:"ml-3.5 mt-1.5 flex items-center gap-1.5 text-[11px] text-accent/70 hover:text-accent font-sans font-medium cursor-pointer transition-colors",children:[l.jsx(zn,{size:11}),"Show full response"]}),o&&!s&&l.jsxs("button",{onClick:()=>r(!0),className:"ml-3.5 mt-1.5 flex items-center gap-1.5 text-[11px] text-accent/70 hover:text-accent font-sans font-medium cursor-pointer transition-colors",children:[l.jsx(zn,{size:11,className:"rotate-180"}),"Collapse"]})]})}function PA({msg:t}){return l.jsxs("div",{className:"flex items-center gap-3 py-2",children:[l.jsx("div",{className:"flex-1 h-px bg-border-subtle"}),l.jsx("span",{className:"text-[10px] text-text-4 font-sans flex-shrink-0 uppercase tracking-wide",children:t.text}),l.jsx("div",{className:"flex-1 h-px bg-border-subtle"})]})}function zA({entries:t,isLive:n}){var d;const[s,r]=v.useState(0);if(v.useEffect(()=>{if(!n||t.length<=1)return;const O=setInterval(()=>r(h=>(h+1)%t.length),1500);return()=>clearInterval(O)},[t.length,n]),!n){const O=t[t.length-1],p=FS(O.text).icon;return l.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-1 text-[10px] text-text-4 font-mono",children:[l.jsx(p,{size:10,className:"opacity-50"}),l.jsxs("span",{children:[t.length," tool call",t.length!==1?"s":""]})]})}const o=t[Math.min(s,t.length-1)],u=((d=o.text)==null?void 0:d.length)>60?o.text.slice(0,60)+"...":o.text;return l.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-2 max-w-[280px] rounded-md bg-surface-3/50 border border-border-subtle/30",children:[l.jsx(Ct,{size:11,className:"text-accent animate-spin flex-shrink-0"}),l.jsx("span",{className:"text-[11px] text-text-2 font-mono truncate transition-opacity duration-300",children:u}),t.length>1&&l.jsx("span",{className:"text-[10px] text-text-4 font-mono flex-shrink-0",children:t.length})]})}function RA({agent:t}){const n=D(h=>h.activityLog[t.id])||Af,s=n[n.length-1],r=s?FS(s.text):null,o=(r==null?void 0:r.icon)||ss,u=s&&Date.now()-s.timestamp<1e4,d=u&&s.text?s.text.length>60?s.text.slice(0,60)+"...":s.text:null,O=Math.round((t.contextUsage||0)*100);return l.jsxs("div",{className:"flex items-center gap-3 px-4 h-8 border-b border-border-subtle bg-surface-1/80 flex-shrink-0",children:[l.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[l.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[l.jsx("span",{className:"absolute inset-0 rounded-full bg-accent/15 animate-ping",style:{animationDuration:"2s"}}),l.jsx("span",{className:"relative w-1.5 h-1.5 rounded-full bg-accent"})]}),u?l.jsxs(l.Fragment,{children:[l.jsx(o,{size:10,className:re(r.color,"flex-shrink-0")}),l.jsx("span",{className:"text-[11px] text-text-2 font-sans truncate",children:d})]}):l.jsx("span",{className:"text-[11px] text-text-3 font-sans",children:"Working..."})]}),l.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[l.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:CA(t.tokensUsed)}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("div",{className:"w-14 h-1 rounded-full bg-surface-4 overflow-hidden",children:l.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${O}%`,background:O>=75?"var(--color-danger)":O>=50?"var(--color-warning)":"var(--color-accent)"}})}),l.jsxs("span",{className:"text-[10px] text-text-4 font-mono w-7 text-right",children:[O,"%"]})]})]})]})}function CA(t){return t?t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"K":String(t):"0"}function _A({agent:t}){const[n,s]=v.useState([]),r=[{text:`Initializing ${t.name}`,delay:0},{text:`Role: ${t.role}`,delay:400},{text:`Provider: ${t.provider||"claude-code"}`,delay:700},{text:"Loading workspace context",delay:1e3},{text:"Scanning project structure",delay:1400},{text:"Session active",delay:1900}];return v.useEffect(()=>{const o=r.map((u,d)=>setTimeout(()=>s(O=>[...O,d]),u.delay));return()=>o.forEach(clearTimeout)},[]),l.jsxs("div",{className:"flex flex-col px-4 pt-6",children:[l.jsxs("div",{className:"flex items-center gap-3 mb-5",children:[l.jsxs("div",{className:"relative w-9 h-9",children:[l.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-accent/20 animate-ping",style:{animationDuration:"2s"}}),l.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent animate-spin",style:{animationDuration:"1s"}}),l.jsx("span",{className:"absolute inset-[5px] rounded-full bg-accent/8"})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-sm font-bold text-text-0 font-sans",children:t.name}),l.jsx("p",{className:"text-2xs text-accent font-mono",children:"starting up"})]})]}),l.jsx("div",{className:"space-y-2 pl-3 border-l border-accent/15",children:r.map((o,u)=>{const d=n.includes(u),O=u===r.length-1;return l.jsxs("div",{className:re("flex items-center gap-2.5 transition-all duration-300",d?"opacity-100 translate-x-0":"opacity-0 -translate-x-2"),children:[l.jsx("span",{className:re("w-1 h-1 rounded-full flex-shrink-0",O&&d?"bg-accent":d?"bg-text-3":"bg-transparent")}),l.jsx("span",{className:re("text-[11px] font-mono",O&&d?"text-accent":"text-text-3"),children:o.text}),O&&d&&l.jsxs("span",{className:"flex gap-0.5 ml-1",children:[l.jsx("span",{className:"w-1 h-1 rounded-full bg-accent animate-pulse",style:{animationDelay:"0ms"}}),l.jsx("span",{className:"w-1 h-1 rounded-full bg-accent animate-pulse",style:{animationDelay:"200ms"}}),l.jsx("span",{className:"w-1 h-1 rounded-full bg-accent animate-pulse",style:{animationDelay:"400ms"}})]})]},u)})})]})}function XA({agent:t}){const n=D(R=>R.chatHistory[t.id])||Af,s=D(R=>R.activityLog[t.id])||Af,r=D(R=>R.instructAgent),o=D(R=>R.queryAgent),u=D(R=>{var _;return(_=R.thinkingAgents)==null?void 0:_.has(t.id)}),d=D(R=>R.chatInputs[t.id]||""),O=R=>D.setState(_=>({chatInputs:{..._.chatInputs,[t.id]:R}})),h=d,p=O,[x,g]=v.useState("instruct"),[b,y]=v.useState(!1),Q=v.useRef(null),w=v.useRef(null),k=v.useRef(null),j=v.useMemo(()=>{var F;const R=[],_=new Set;for(const se of n){const ie=`${se.from}:${(F=se.text)==null?void 0:F.slice(0,100)}`;R.find(P=>{var B;return P.kind==="chat"&&`${P.from}:${(B=P.text)==null?void 0:B.slice(0,100)}`===ie&&Math.abs(P.ts-se.timestamp)<5e3})||(R.push({...se,kind:"chat",ts:se.timestamp}),_.add(se.text))}const T=_,Y=s.slice(-30);for(const se of Y)(se.text||"").trim()&&!T.has(se.text)&&R.push({...se,kind:"activity",ts:se.timestamp});R.sort((se,ie)=>se.ts-ie.ts);const M=[];let ae=[];for(const se of R)se.kind==="activity"?ae.push(se):(ae.length>0&&(M.push({kind:"activity-group",entries:ae}),ae=[]),M.push(se));return ae.length>0&&M.push({kind:"activity-group",entries:ae}),M},[n,s]);v.useEffect(()=>{Q.current&&requestAnimationFrame(()=>{Q.current&&(Q.current.scrollTop=Q.current.scrollHeight)})},[j.length]);async function z(R){var M;const _=Array.from(R.target.files||[]);if(_.length===0)return;const T=D.getState().addToast,Y=[];for(const ae of _)try{const F=await new Promise((se,ie)=>{const W=new FileReader;W.onload=()=>se(W.result.split(",")[1]),W.onerror=ie,W.readAsDataURL(ae)});await K.post(`/agents/${t.id}/upload`,{filename:ae.name,content:F}),Y.push(ae.name)}catch(F){T("error",`Upload failed: ${ae.name}`,F.message)}if(Y.length>0){const ae=Y.join(", ");p(F=>(F?F+`
635
635
  `:"")+`[Uploaded: ${ae}] — I've uploaded these files to your working directory. Read them and use their content.`),T("success",`Uploaded ${Y.length} file${Y.length>1?"s":""}`)}R.target.value="",(M=w.current)==null||M.focus()}async function N(){var _;const R=h.trim();if(!(!R||b)){if(R==="/rotate"){const T=D.getState().rotateAgent;p("");try{await T(t.id)}catch{}return}p(""),y(!0);try{x==="query"?await o(t.id,R):await r(t.id,R)}catch{}y(!1),(_=w.current)==null||_.focus()}}function X(R){R.key==="Enter"&&!R.shiftKey&&(R.preventDefault(),N())}const G=t.status==="running"||t.status==="starting";return l.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[G&&l.jsx(RA,{agent:t}),l.jsxs("div",{ref:Q,className:"flex-1 overflow-y-auto px-4 py-4 space-y-4",children:[!j.some(R=>R.from==="agent"||R.kind==="activity-group")&&(G?l.jsx(_A,{agent:t}):l.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center py-8",children:[l.jsx("div",{className:"w-10 h-10 rounded-xl bg-surface-3 flex items-center justify-center mb-3",children:l.jsx(gi,{size:18,className:"text-text-4"})}),l.jsx("p",{className:"text-sm font-semibold text-text-0 font-sans",children:t.name}),l.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Session complete — send a message to continue"})]})),j.map((R,_)=>{if(R.kind==="activity-group"){const T=!j.slice(_+1).some(Y=>Y.kind==="activity-group"||Y.from==="agent");return l.jsx("div",{children:l.jsx(zA,{entries:R.entries,isLive:G&&T})},`grp-${_}`)}return R.from==="user"?l.jsx(TA,{msg:R},`msg-${_}`):R.from==="system"?l.jsx(PA,{msg:R},`msg-${_}`):l.jsx(NA,{msg:R,agent:t},`msg-${_}`)}),l.jsx(Zf,{children:(b||u)&&l.jsx(Ef.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.25,ease:"easeOut"},children:l.jsx(wA,{agent:t})},"thinking")})]}),l.jsxs("div",{className:"border-t border-border px-4 py-3 bg-surface-1/50 flex-shrink-0",children:[l.jsxs("div",{className:"flex items-center gap-1 mb-2",children:[l.jsxs("button",{onClick:()=>g("instruct"),className:re("flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] font-sans font-medium transition-colors cursor-pointer",x==="instruct"?"bg-accent/12 text-accent border border-accent/20":"text-text-3 hover:text-text-1 hover:bg-surface-3"),children:[l.jsx(Wc,{size:10}),"Instruct"]}),l.jsxs("button",{onClick:()=>g("query"),className:re("flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] font-sans font-medium transition-colors cursor-pointer",x==="query"?"bg-info/12 text-info border border-info/20":"text-text-3 hover:text-text-1 hover:bg-surface-3"),children:[l.jsx(yc,{size:10}),"Query"]}),l.jsx("span",{className:"text-[10px] text-text-4 font-sans ml-auto",children:x==="query"?"Read-only — agent keeps working":G?"Directs the agent":"Continues the session"})]}),l.jsxs("div",{className:re("flex items-end gap-1 rounded-xl border bg-surface-0 p-1 transition-colors",x==="query"?"border-info/20 focus-within:border-info/40":"border-border-subtle focus-within:border-accent/30"),children:[l.jsx("input",{ref:k,type:"file",multiple:!0,accept:".pdf,.png,.jpg,.jpeg,.gif,.svg,.csv,.txt,.md,.json,.yaml,.yml,.docx,.pptx,.xlsx",onChange:z,className:"hidden"}),l.jsx("button",{onClick:()=>{var R;return(R=k.current)==null?void 0:R.click()},className:"w-9 h-9 flex items-center justify-center rounded-lg text-text-4 hover:text-text-1 hover:bg-surface-3 transition-colors cursor-pointer flex-shrink-0 mb-px",title:"Attach file",children:l.jsx(JT,{size:14})}),l.jsx("textarea",{ref:w,value:h,onChange:R=>p(R.target.value),onKeyDown:X,placeholder:x==="query"?"Ask about this agent's work...":G?"Send an instruction...":"Continue this session...",rows:1,className:re("flex-1 resize-none px-3 py-2 text-[13px]","bg-transparent text-text-0 font-sans","placeholder:text-text-4","focus:outline-none","max-h-[120px] min-h-[36px]"),style:{height:Math.min(Math.max(36,h.split(`