1import{j as e,g as b,X as xe,e as pe}from"./index-BDkOycpI.js";import{r as d}from"./vendor-syncfusion-aSHKQ61y.js";import{B as se,a as y}from"./button-CVt88oIN.js";import{aq as q,ar as he,a4 as fe,r as Ae,v as je,O as we,w as be,y as W,P as ve,x as Ne,T as ye,z as ke,A as Ce,a5 as De,q as Se,ah as Ee,ae as Fe,af as Be,a2 as Pe,ag as Ie,S as Me,I as Oe,as as Le,at as Re}from"./heicToJpeg-BWVEChr-.js";import{g as Te,e as ze,A as _e,a as Ue,b as Ke}from"./AgentPresetDialog-BQAsaeYI.js";import{g as Ve,E as X}from"./useSkills-DouKfDom.js";import{f as te,u as qe,e as We,g as $e,a as Xe,b as Ye,c as Ge,l as He}from"./useAgentPresets-AvcYr1FH.js";import{u as Je}from"./useSupabaseAuth-PXYCFvw2.js";import{L as Qe}from"./loader-circle-BrIeJJsZ.js";import{P as I}from"./switch-CxebYeZv.js";import"./vendor-monaco-CXmyaYlk.js";import"./index-BIrHiGfp.js";import"./FilePreviewPanel-BXHQ0H9u.js";import"./upload-IBgQ44aU.js";import"./index.dom-BzuiG5hi.js";import"./chevron-down-CvQoQoeG.js";import"./folder-D303bfEi.js";import"./IntegrationIcons-CNWladvc.js";import"./TelegramConnectDialog-BUQqkYTe.js";import"./oauth-popup-AdeWZCT1.js";import"./useWhatsAppBusiness-Ch6hhlxO.js";function ee({children:a,size:t}){return e.jsx("span",{className:b("inline-flex shrink-0 items-center justify-center overflow-hidden rounded-md",t==="sm"?"h-4 w-4":"h-[18px] w-[18px]","[&>*]:h-full [&>*]:w-full [&_img]:h-full [&_img]:w-full [&_img]:object-contain [&_svg]:h-full [&_svg]:w-full"),children:a})}function Ze({mcpServers:a,skills:t,className:x,size:u="md",maxEach:l=8}){const{data:p=[]}=te(),r=a.filter(n=>!q(n)),g=[...t.filter(n=>!!n.name).map(n=>n.name),...a.filter(q)],h=[...t.filter(n=>!!n.name).map(n=>he(n)),...a.filter(q)];if(r.length===0&&g.length===0)return null;const f=u==="sm"?"gap-2":"gap-2.5",j=r.length>0&&g.length>0;return e.jsxs("div",{className:b("flex flex-wrap items-center",f,x),role:"list",children:[r.length>0?e.jsxs("div",{className:b("flex items-center",f),children:[r.slice(0,l).map(n=>e.jsx(ee,{size:u,children:Te(n)},`mcp-${n}`)),r.length>l?e.jsxs("span",{className:"text-[10px] font-medium leading-none text-[#9A9A9A]",children:["+",r.length-l]}):null]}):null,j?e.jsx("span",{className:"h-4 w-px shrink-0 bg-[#E0DBD3]","aria-hidden":!0}):null,g.length>0?e.jsxs("div",{className:b("flex items-center",f),children:[g.slice(0,l).map((n,v)=>e.jsx(ee,{size:u,children:Ve(n,p)},`skill-${h[v]??n}`)),g.length>l?e.jsxs("span",{className:"text-[10px] font-medium leading-none text-[#9A9A9A]",children:["+",g.length-l]}):null]}):null]})}function es({agent:a,onView:t,onEdit:x,onDelete:u,onStartChat:l,isLast:p=!1}){const r=!!t,g=!!x,h=!!u,f=!!(r||g||h),j=a.description?.trim()??"",n=()=>{l?l():x?x():t&&t()},v=m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),n())},A=!!(l||x||t);return e.jsxs("div",{className:b("group flex items-center gap-4 px-4 py-3.5 transition-colors",!p&&"border-b border-[#F0ECE4]",A&&"cursor-pointer hover:bg-[#FAF8F4]"),onClick:A?n:void 0,onKeyDown:A?v:void 0,role:A?"button":void 0,tabIndex:A?0:void 0,children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-xl border border-[#E8E4DC] bg-[#F8F5EF]",children:e.jsx(se,{className:"h-5 w-5 text-[#1A1A1A]",strokeWidth:1.75})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"truncate text-[14px] font-semibold tracking-tight text-[#1A1A1A]",children:a.name}),a.isDefault?e.jsx("span",{className:"inline-flex items-center rounded-md border border-[#DCE6F7] bg-[#F6F9FF] px-0.5 py-[3px] text-[9px] font-semibold leading-none uppercase tracking-[0.04em] text-[#45618A]",children:"default"}):null]}),j?e.jsx("p",{className:"mt-0.5 line-clamp-1 text-[12px] leading-snug text-[#6B6B6B]",children:j}):null,e.jsx(Ze,{mcpServers:a.mcp_servers,skills:a.skills,size:"sm",maxEach:5,className:"mt-2 min-h-[18px]"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[l?e.jsxs("span",{className:"hidden items-center gap-0.5 text-[12px] font-medium text-[#2B5EA7] opacity-0 transition-opacity group-hover:opacity-100 sm:inline-flex",children:["Start chat",e.jsx(fe,{className:"h-3.5 w-3.5"})]}):null,f?e.jsxs(Ae,{children:[e.jsx(je,{asChild:!0,children:e.jsx("button",{type:"button",className:"flex h-8 w-8 items-center justify-center rounded-full text-[#9A9A9A] transition-colors hover:bg-[#F4F1EB] hover:text-[#1A1A1A] data-[state=open]:bg-[#F4F1EB] data-[state=open]:text-[#1A1A1A]","aria-label":"Agent options",onClick:m=>m.stopPropagation(),children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(be,{align:"end",className:"min-w-[9rem]",children:[r?e.jsxs(W,{onClick:m=>{m.stopPropagation(),t?.()},children:[e.jsx(X,{className:"mr-2 h-4 w-4"}),"View"]}
1):null,g?e.jsxs(W,{onClick:m=>{m.stopPropagation(),x?.()},children:[e.jsx(ve,{className:"mr-2 h-4 w-4"}),"Edit"]}):null,(r||g)&&h?e.jsx(Ne,{}):null,h?e.jsxs(W,{className:"text-destructive focus:text-destructive",onClick:m=>{m.stopPropagation(),u?.()},children:[e.jsx(ye,{className:"mr-2 h-4 w-4"}),"Delete"]}):null]})]}):null]})]})}function ss({open:a,onOpenChange:t}){return e.jsx(ke,{open:a,onOpenChange:t,children:e.jsx(Ce,{hideClose:!0,className:b("gap-0 overflow-hidden border-[#EAE6DE] bg-[#FCFBF9] p-0","max-h-[min(92vh,860px)] w-[min(1120px,96vw)] max-w-none sm:rounded-2xl"),children:e.jsxs("div",{className:"flex max-h-[min(92vh,860px)] min-h-0 flex-col",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-3 border-b border-[#EAE6DE] bg-white px-6 py-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border border-[#E8E4DC] bg-[#F8F5EF]",children:e.jsx(X,{className:"h-5 w-5 text-[#1A1A1A]",strokeWidth:1.75})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("h2",{className:"truncate text-[17px] font-semibold tracking-tight text-[#1A1A1A]",children:"Skills & apps"})}),e.jsx("button",{type:"button",onClick:()=>t(!1),className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg text-[#9A9A9A] transition-colors hover:bg-[#F4F1EB] hover:text-[#1A1A1A]","aria-label":"Close",children:e.jsx(xe,{className:"h-5 w-5"})})]}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden p-6",children:e.jsx(ze,{enabledSkills:[],enabledMcpServers:[],onSkillToggle:()=>{},onMcpToggle:()=>{},allowSkillManagement:!1,allowSkillDelete:!0,hideToggles:!0,className:"min-h-[380px] lg:h-[min(70vh,640px)]"})}),e.jsx("div",{className:"flex shrink-0 items-center justify-end gap-2 border-t border-[#EAE6DE] bg-white px-6 py-4",children:e.jsx(y,{type:"button",variant:"outline",onClick:()=>t(!1),children:"Close"})})]})})})}function $({active:a,onClick:t,children:x}){return e.jsx("button",{type:"button",onClick:t,className:b("whitespace-nowrap rounded-full px-4 py-1.5 text-[13px] font-medium transition-all duration-150",a?"bg-white text-[#1A1A1A] shadow-[0_1px_3px_rgba(26,26,26,0.08)]":"text-[#6B6B6B] hover:text-[#1A1A1A]"),children:x})}const Ns=({onStartChat:a})=>{const{data:t=[],isLoading:x}=qe(),{userId:u}=Je(),{orgId:l,isOrgAdmin:p}=De(),{agents:r,isLoading:g}=Se(),{data:h=[],isSuccess:f}=We(),{data:j=[],isSuccess:n}=te(),v=$e(),A=Xe(),m=Ye(),ne=Ge(),[o,k]=d.useState("shapeai"),[w,D]=d.useState(""),[ae,C]=d.useState(!1),[N,M]=d.useState("edit"),[Y,S]=d.useState(null),[G,E]=d.useState(null),[ie,F]=d.useState(!1),[le,H]=d.useState(!1),[O,J]=d.useState(null),[B,L]=d.useState(null),Q=d.useMemo(()=>f&&n?{mcpOptions:h,skillOptions:j}:void 0,[h,j,f,n]),R=d.useMemo(()=>Ee(t,r,Q),[t,r,Q]),T=d.useMemo(()=>{const s=R?[R]:[],i=Fe(r).filter(c=>!c.isDefault).map(c=>Be(c.id,t,r)).filter(c=>c!=null);return[...s,...i]},[t,r,R]),z=d.useMemo(()=>Pe(t),[t]),_=d.useMemo(()=>u?Ie(t,u):[],[t,u]),U=o==="shapeai"?T:o==="org"?z:_,K=d.useMemo(()=>{const s=w.trim().toLowerCase();return s?U.filter(i=>i.name.toLowerCase().includes(s)||(i.description??"").toLowerCase().includes(s)):U},[U,w]),V=()=>{C(!1),S(null),E(null),F(!1)},P=(s=!1)=>{M("create"),S(null),E(null),F(s),C(!0)},re=s=>{M("view"),S(s),E(null),F(!1),C(!0)},oe=s=>{M("edit"),S(s),F(!1),E(t.find(i=>i.id===s.id)??null),C(!0)},ce=s=>{a&&a(s)},de=async s=>{const i=t.find(c=>c.id===s);if(i&&!(i.source==="user"&&(!u||!Le(i,u)))&&!(i.source==="org"&&(!Re(i)||!p))){try{const c=await He(s);if(c.length>0){J({agentName:i.name,dependents:c});return}}catch(c){pe.error(c instanceof Error?c.message:"Failed to check where this agent is used");return}L({id:i.id,name:i.name})}},me=async()=>{if(!B)return;const{id:s}=B;L(null),await ne.mutateAsync(s),Y?.id===s&&V()},ue=async s=>{if(N==="create")if(ie){if(!l)throw new Error("No organization");await A.mutateAsync({orgId:l,values:s}),k("org")}else await v.mutateAsync(s),k("you");else N==="edit"&&G&&await m.mutateAsync({id:G.id,values:s});V()},ge=o==="shapeai"?"Specialized agents built by ShapeAI for common workflows.":o==="org"?p?"Shared agents for everyone in your organization.":"Shared agents from your organization. Ask an admin to create or edit them.":"Create and manage your own custom agents.";return x||g?e.jsx("div",{className:"flex flex-1 items-center justify-center bg-[#F8F5EF]",children:e.jsx(Qe,{className:"h-6 w-6 animate-spin text-[#9A9A9A]"})}):e.jsxs("div",{className:"flex flex-1 flex-col overflow-y-auto bg-[#F8F5EF]",children:[e.jsxs("div",{className:"mx-auto w-full max-w-[720px] px-4 pt-6 pb-16 md:px-6 md:pt-8",children:[e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"mb-5",children:[e.jsx("h1",{className:"text-[20px] font-semibold tracking-tight text-[#1A1A1A] md:text-[22px]",children:"Agents"}),e.jsx("p",{className:"mt-1.5 text-[13px] leading-relaxed text-[#6B6B6B]",children:ge})]}),e.jsxs("div",{className:"mb-5 flex flex-wrap items-center justify-between gap-3 md:flex-nowrap md:gap-4",children:[e.jsxs("div",{className:"inline-flex shrink-0 overflow-x-auto rounded-full bg-[#EDE9E0] p-1",children:[e.jsxs($,{active:o==="shapeai",onClick:()=>{k("shapeai"),D("")},children:["By ShapeAI",T.length>0?e.jsx("span",{className:"ml-1.5 text-[#9A9A9A]",children:T.length}):null]}),e.jsxs($,{active:o==="org",onClick:()=>{k("org"),D("")},children:["By Org",z.length>0?e.jsx("span",{className:"ml-1.5 text-[#9A9A9A]",children:z.length}):null]}),e.jsxs($,{active:o==="you",onClick:()=>{k("you"),D("")},children:["By You",_.length>0?e.jsx("span",{className:"ml-1.5 text-[#9A9A9A]",children:_.length}):null]})]}),e.jsxs("div",{className:"flex min-w-0 shrink-0 items-center gap-2 md:gap-3",children:[e.jsxs("div",{className:"relative w-[140px] sm:w-[160px] md:w-[180px]",children:[e.jsx(Me,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-[#9A9A9A]"}),e.jsx(Oe,{value:w,onChange:s=>D(s.target.value),placeholder:"Search agents",className:"h-9 rounded-full border-[#
1EAE6DE] bg-white/80 pl-9 text-[13px] shadow-none focus-visible:ring-1 focus-visible:ring-[#1A1A1A]/10"})]}),o!=="shapeai"?e.jsxs(y,{variant:"outline",onClick:()=>H(!0),size:"sm",className:"shrink-0 rounded-full px-3",children:[e.jsx(X,{className:"mr-1.5 h-4 w-4"}),"View"]}):null,o==="you"?e.jsxs(y,{onClick:()=>P(!1),size:"sm",className:"shrink-0 rounded-full px-4",children:[e.jsx(I,{className:"mr-1.5 h-4 w-4"}),"Create"]}):null,o==="org"&&p&&l?e.jsxs(y,{onClick:()=>P(!0),size:"sm",className:"shrink-0 rounded-full px-4",children:[e.jsx(I,{className:"mr-1.5 h-4 w-4"}),"Create"]}):null]})]})]}),K.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center rounded-2xl border border-dashed border-[#E0DBD2] bg-white/50 px-8 py-14 text-center",children:[e.jsx("div",{className:"mb-4 flex h-12 w-12 items-center justify-center rounded-2xl bg-[#F4F1EB]",children:e.jsx(se,{className:"h-6 w-6 text-[#1A1A1A]",strokeWidth:1.75})}),e.jsx("p",{className:"text-[15px] font-medium text-[#1A1A1A]",children:w.trim()?"No agents match your search":o==="shapeai"?"No ShapeAI agents available":o==="org"?"No org agents yet":"No agents yet"}),e.jsx("p",{className:"mt-1 max-w-[280px] text-[13px] text-[#6B6B6B]",children:w.trim()?"Try a different search term.":o==="shapeai"?"Check back later for new specialized agents from ShapeAI.":o==="org"?p?"Create a shared agent for your organization.":"Org admins can create shared agents for everyone.":"Create a custom agent with its own skills and instructions."}),!w.trim()&&o==="you"?e.jsxs(y,{variant:"outline",className:"mt-5 rounded-full",onClick:()=>P(!1),children:[e.jsx(I,{className:"mr-1.5 h-4 w-4"}),"Create agent"]}):null,!w.trim()&&o==="org"&&p&&l?e.jsxs(y,{variant:"outline",className:"mt-5 rounded-full",onClick:()=>P(!0),children:[e.jsx(I,{className:"mr-1.5 h-4 w-4"}),"Create org agent"]}):null]}):e.jsx("div",{className:"overflow-hidden rounded-2xl border border-[#EAE6DE] bg-white",children:K.map((s,i)=>{const c=s.source==="org"&&p,Z=s.source==="user";return e.jsx(es,{agent:s,onView:()=>re(s),onEdit:c||Z?()=>oe(s):void 0,onDelete:c||Z?()=>{de(s.id)}:void 0,onStartChat:a?()=>ce(s.id):void 0,isLast:i===K.length-1},s.id)})})]}),e.jsx(_e,{open:ae,onOpenChange:s=>{s?C(!0):V()},mode:N,agent:N==="create"?null:Y,onSubmit:N==="create"||N==="edit"?ue:void 0,isSubmitting:v.isPending||A.isPending||m.isPending}),e.jsx(ss,{open:le,onOpenChange:H}),e.jsx(Ue,{open:O!=null,onOpenChange:s=>{s||J(null)},agentName:O?.agentName??"",dependents:O?.dependents??[]}),e.jsx(Ke,{open:B!=null,onOpenChange:s=>{s||L(null)},agentName:B?.name??"",onConfirm:()=>{me()}})]})};export{Ns as AgentsPage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.