decocms
Version:
Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools
2 lines (1 loc) • 8.54 kB
JavaScript
import{b as re,r as y,a6 as ie,T as ce,K as ae,i as de,dT as me,j as s,m as C,h as B,B as ue,c as R}from"./index-ztdGKvBm.js";import{I as K}from"./integration-icon-Bo-3z9o3.js";import{u as fe}from"./use-infinite-scroll-DdrDrAAo.js";import{C as U}from"./checkbox-QUuOza1H.js";import{i as xe}from"./ArrowLeft-B0PZnf1E.js";import{u as he}from"./useSuspenseInfiniteQuery-Pk4rU2Ft.js";import{u as pe}from"./use-mcp-client-2MG3LveS.js";import{C as ge}from"./collection-search-DkVgkcUC.js";import{p as Se}from"./connection-C8I8wKeO.js";function be(i){const e=R.c(21),{connection:n,isSelected:m,hasToolsEnabled:l,activeToolsCount:h,totalToolsCount:b,onSelect:p,onToggle:j}=i,r=m?"bg-accent/50":"hover:bg-accent";let c;e[0]!==r?(c=C("flex items-center gap-3 p-2 rounded-lg transition-colors will-change-auto",r),e[0]=r,e[1]=c):c=e[1];let a;e[2]!==n.icon||e[3]!==n.title?(a=s.jsx(K,{icon:n.icon,name:n.title,size:"xs"}),e[2]=n.icon,e[3]=n.title,e[4]=a):a=e[4];let d;e[5]!==n.title?(d=s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:n.title})}),e[5]=n.title,e[6]=d):d=e[6];let u;e[7]!==p||e[8]!==a||e[9]!==d?(u=s.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0 cursor-pointer",onClick:p,children:[a,d]}),e[7]=p,e[8]=a,e[9]=d,e[10]=u):u=e[10];let f;e[11]!==h||e[12]!==n.tools||e[13]!==l||e[14]!==j||e[15]!==b?(f=n.tools&&n.tools.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"text-xs text-muted-foreground shrink-0",children:[h,"/",b]}),s.jsx(U,{checked:l,onCheckedChange:j,onClick:je})]}),e[11]=h,e[12]=n.tools,e[13]=l,e[14]=j,e[15]=b,e[16]=f):f=e[16];let x;return e[17]!==c||e[18]!==u||e[19]!==f?(x=s.jsxs("div",{className:c,children:[u,f]}),e[17]=c,e[18]=u,e[19]=f,e[20]=x):x=e[20],x}function je(i){return i.stopPropagation()}function ve(i){const e=R.c(21),{connectionId:n,tool:m,isSelected:l,onToggle:h,badge:b}=i,p=`tool-${n}-${m.name}`,j=l?"text-foreground":"text-muted-foreground";let r;e[0]!==j?(r=C("text-sm font-medium",j),e[0]=j,e[1]=r):r=e[1];let c;e[2]!==r||e[3]!==m.name?(c=s.jsx("span",{className:r,children:m.name}),e[2]=r,e[3]=m.name,e[4]=c):c=e[4];let a;e[5]!==b||e[6]!==c?(a=s.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[c,b]}),e[5]=b,e[6]=c,e[7]=a):a=e[7];let d;e[8]!==m.description?(d=m.description&&s.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:m.description}),e[8]=m.description,e[9]=d):d=e[9];let u;e[10]!==a||e[11]!==d?(u=s.jsxs("div",{className:"flex-1 min-w-0",children:[a,d]}),e[10]=a,e[11]=d,e[12]=u):u=e[12];const f=`tool-${n}-${m.name}`;let x;e[13]!==l||e[14]!==h||e[15]!==f?(x=s.jsx("div",{className:"flex items-center shrink-0",children:s.jsx(U,{id:f,checked:l,onCheckedChange:h,onClick:Ne})}),e[13]=l,e[14]=h,e[15]=f,e[16]=x):x=e[16];let N;return e[17]!==p||e[18]!==u||e[19]!==x?(N=s.jsxs("label",{className:"flex items-center gap-3 p-3 rounded-lg hover:bg-accent cursor-pointer group will-change-auto",htmlFor:p,children:[u,x]}),e[17]=p,e[18]=u,e[19]=x,e[20]=N):N=e[20],N}function Ne(i){return i.stopPropagation()}function Fe({toolSet:i,onToolSetChange:e,excludeVirtualMcpId:n,searchQuery:m}){const l=re(),[h,b]=y.useState(""),p=m!==void 0?m:h,j=y.useDeferredValue(p),[r,c]=y.useState("all"),[a,d]=y.useState(!1),u=y.useRef(new Set(Object.keys(i))),{org:f}=ie(),x=pe({connectionId:ce,orgId:f.id,orgSlug:f.slug}),N=100,P=j.trim(),I=P?{operator:"or",conditions:[{field:["title"],operator:"contains",value:P},{field:["description"],operator:"contains",value:P}]}:void 0,O=!!n,q={...I&&{where:I},orderBy:[{field:["updated_at"],direction:"asc"}],limit:N,offset:0,...O&&{include_virtual:!0}},V=JSON.stringify(q),{data:_,fetchNextPage:G,hasNextPage:J,isFetchingNextPage:F}=he({queryKey:ae.collectionListInfinite(x,f.id,"","CONNECTIONS",V),queryFn:async({pageParam:t=0})=>(await x.callTool({name:"COLLECTION_CONNECTIONS_LIST",arguments:{...I&&{where:I},orderBy:[{field:["updated_at"],direction:"asc"}],limit:N,offset:t,...O&&{include_virtual:!0}}})).structuredContent,initialPageParam:0,getNextPageParam:(t,o)=>{if(t?.hasMore)return o.reduce((g,S)=>g+(S?.items?.length??0),0)},staleTime:3e4}),M=_?.pages.flatMap(t=>t?.items??[])??[],Y=fe(G,J??!1,F),A=n?M.filter(t=>t.connection_type!=="VIRTUAL"?!0:Se(t.connection_url)!==n):M,L=u.current,Z=[...L.values()].map(t=>A.find(o=>o.id===t)).filter(t=>t!==void 0),H=A.filter(t=>!L.has(t.id)),E=[...Z,...H],z=t=>{const o=i[t];return o!==void 0&&o.length>0},D=E.filter(t=>{if(r==="all")return!0;const o=z(t.id);return r==="selected"?o:r==="unselected"?!o:!0}),[T,Q]=y.useState(E[0]?.id??null),v=T?E.find(t=>t.id===T)??null:null,{data:W,isFetching:X}=de({...me(f.id,"CONNECTIONS",T??void 0,x),enabled:!!T}),w=W?.item?.tools??[],ee=(t,o)=>i[t]?.includes(o)??!1,te=(t,o)=>{const g=i[t]??[],S=g.includes(o),k={...i};if(S){const $=g.filter(le=>le!==o);$.length===0?delete k[t]:k[t]=$}else k[t]=[...g,o];e(k)},se=t=>{if((i[t]??[]).length>0){const S={...i};delete S[t],e(S);return}const g=t===T?w:[];if(!g.length){Q(t);return}e({...i,[t]:g.map(S=>S.name)})},oe=t=>{Q(t),d(!0)},ne=()=>{d(!1)};return s.jsxs("div",{className:"flex h-full",children:[s.jsxs("div",{className:C("w-full md:w-80 border-r border-border flex flex-col",a&&"hidden md:flex"),children:[m===void 0&&s.jsx(ge,{value:h,onChange:b,placeholder:l("common.toolSetSelector.searchPlaceholder")}),s.jsxs("div",{className:"flex gap-1 p-2 border-b border-border",children:[s.jsx("button",{type:"button",onClick:()=>c("all"),className:C("flex-1 px-3 py-1.5 text-xs font-medium rounded-lg transition-colors border cursor-pointer",r==="all"?"bg-muted border-border":"border-border opacity-75 hover:opacity-100"),children:l("common.toolSetSelector.filterAll")}),s.jsx("button",{type:"button",onClick:()=>c("selected"),className:C("flex-1 px-3 py-1.5 text-xs font-medium rounded-lg transition-colors border cursor-pointer",r==="selected"?"bg-muted border-border":"border-border opacity-75 hover:opacity-100"),children:l("common.toolSetSelector.filterSelected")}),s.jsx("button",{type:"button",onClick:()=>c("unselected"),className:C("flex-1 px-3 py-1.5 text-xs font-medium rounded-lg transition-colors border cursor-pointer",r==="unselected"?"bg-muted border-border":"border-border opacity-75 hover:opacity-100"),children:l("common.toolSetSelector.filterUnselected")})]}),s.jsx("div",{className:"flex-1 overflow-auto",children:D.length===0?s.jsx("div",{className:"p-4 text-sm text-muted-foreground text-center",children:l(p?"common.toolSetSelector.noConnectionsFound":r==="selected"?"common.toolSetSelector.noServersSelected":r==="unselected"?"common.toolSetSelector.noUnselectedServers":"common.toolSetSelector.noConnectionsAvailable")}):s.jsxs("div",{className:"p-2 space-y-1",children:[D.map(t=>{const o=T===t.id,g=o?w.length:0,S=i[t.id]?.length??0;return s.jsx(be,{connection:{...t,tools:o?w:t.tools},isSelected:o,hasToolsEnabled:z(t.id),activeToolsCount:S,totalToolsCount:g,onSelect:()=>oe(t.id),onToggle:()=>se(t.id)},t.id)}),s.jsx("div",{ref:Y,className:"h-4"}),F&&s.jsx("div",{className:"flex justify-center py-3",children:s.jsx(B,{className:"size-4.5 text-muted-foreground"})})]})})]}),s.jsx("div",{className:C("flex-1 flex-col",a?"flex":"hidden md:flex"),children:v?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"md:hidden border-b border-border p-4 flex items-center gap-3",children:[s.jsx(ue,{variant:"ghost",size:"icon",onClick:ne,className:"shrink-0",children:s.jsx(xe,{size:20})}),s.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[s.jsx(K,{icon:v.icon,name:v.title,size:"sm"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("h3",{className:"text-base font-medium text-foreground truncate",children:v.title}),v.description&&s.jsx("p",{className:"text-sm text-muted-foreground truncate",children:v.description})]})]})]}),s.jsx("div",{className:"flex-1 overflow-auto p-4",children:X?s.jsx("div",{className:"flex justify-center py-8",children:s.jsx(B,{className:"size-4.5 text-muted-foreground"})}):w.length===0?s.jsx("div",{className:"text-sm text-muted-foreground text-center py-8",children:l("common.toolSetSelector.noToolsAvailable")}):s.jsx("div",{className:"space-y-2",children:w.map(t=>s.jsx(ve,{connectionId:v.id,tool:t,isSelected:ee(v.id,t.name),onToggle:()=>te(v.id,t.name)},t.name))})})]}):s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsx("div",{className:"text-sm text-muted-foreground text-center",children:l("common.toolSetSelector.selectConnection")})})})]})}export{ve as T,Fe as a};