UNPKG

decocms

Version:

Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools

2 lines (1 loc) • 15.2 kB
import{s as ye}from"./session-runtime-CZKHty5X.js";import{c as w,K as ie,i as ae,b as se,j as f,h as xe,r as H,m as re,I as le,a_ as be,w as je,x as Pe,B as ke,v as ve,D as Ce}from"./index-DoEtSiIe.js";import{b as Se}from"./UserCheck01-CA8kXGn8.js";import{C as we}from"./agent-icon-DoabtHNW.js";import{aT as Ne}from"./site-editor-toast-B-FDGvtN.js";const De="https://placeholder.invalid";function We(s,e){const t=(s??"").trim();if(!t)return"";const o=ye((e??"").trim());if(!o)return"";try{const i=new URL(t,De),a=new URL(o);return a.pathname=i.pathname,a.search=i.search,a.hash=i.hash,a.href}catch{return""}}const fe="vtex/loaders/intelligentSearch/productList.ts",Te="vtex/loaders/categories/tree.ts",Ee=24;function Q(s){return s&&typeof s=="object"&&!Array.isArray(s)?s:null}function Le(s){return s.split("/").filter(Boolean).map((t,o)=>`category-${o+1}/${t}`).join("/")}function $e(s,e){const t=e.trim(),o=fe,i=Ee;if(s==="cluster")return t?[{resolveType:o,props:{collection:t,count:i}}]:[];if(s==="category"){if(!t)return[];const d=Le(t);return d?[{resolveType:o,props:{facets:d,count:i}}]:[]}if(!t)return[{resolveType:o,props:{query:"",count:i}}];const a=[];/^\d+$/.test(t)&&a.push({resolveType:o,props:{ids:[t]}});const l=t.includes("-")&&!/\s/.test(t)?t.replace(/-+/g," "):t;return a.push({resolveType:o,props:{query:l,count:i}}),a}function _e(){return{resolveType:Te,props:{}}}function Ie(s){return{resolveType:fe,props:{ids:s}}}function de(s){return typeof s=="string"||typeof s=="number"?String(s):""}function pe(s){const e=Q(s),t=Array.isArray(s)?s:Array.isArray(e?.products)?e.products:[],o=[],i=new Set;for(const a of t){const r=Q(a);if(!r)continue;const l=de(r.productID)||de(r.sku);if(!l||i.has(l))continue;i.add(l);const d=Q(r.isVariantOf),u=typeof d?.name=="string"&&d.name||typeof r.name=="string"&&r.name||l,n=qe(r.image),c=n[0],m=typeof r.url=="string"&&r.url||typeof d?.url=="string"&&d.url||void 0;o.push({id:l,label:u,image:c,images:n,url:m,category:Ae(r.category),description:Fe(r,d)})}return o}function qe(s){if(!Array.isArray(s))return[];const e=[];for(const t of s){const o=Q(t),i=typeof o?.url=="string"?o.url:"";i&&!e.includes(i)&&e.push(i)}return e}function Ae(s){return typeof s!="string"||!s.trim()?void 0:s.split(/[>/]/).map(t=>t.trim()).filter(Boolean).pop()||void 0}function Fe(s,e){const o=(typeof s.description=="string"&&s.description||typeof e?.description=="string"&&e.description||"").replace(/<[^>]*>/g," ").replace(/\s+/g," ").trim();if(o)return o.length>400?`${o.slice(0,400).trimEnd()}…`:o}function Oe(s){if(typeof s!="string"||!s)return null;let e;try{e=new URL(s,"https://placeholder.invalid").pathname}catch{return null}return e.replace(/^\/+|\/+$/g,"")||null}function Re(s){const e=[],t=new Set,o=(i,a)=>{const r=Q(i);if(!r)return;const l=typeof r.name=="string"&&r.name?r.name:"",d=l?[...a,l]:a,u=Oe(r.url);if(u&&!t.has(u)&&(t.add(u),e.push({path:u,label:d.join(" › ")||u,url:typeof r.url=="string"?r.url:`/${u}`})),Array.isArray(r.children))for(const n of r.children)o(n,d)};if(Array.isArray(s))for(const i of s)o(i,[]);return e}function Ke(s,e,t=50){const o=e.trim().toLowerCase();return(o?s.filter(a=>a.label.toLowerCase().includes(o)||a.path.toLowerCase().includes(o)):s).slice(0,t)}const ze=1e4;async function ce(s,{resolveType:e,props:t}){const o=await fetch(Ne(s),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({__resolveType:e,...t}),signal:AbortSignal.timeout(ze)});if(!o.ok)throw new Error(`Failed to fetch (${o.status})`);return o.json()}function Ze(s,e){const t=w.c(20);let o;t[0]!==e?(o=new Set(e.filter(Boolean)),t[0]=e,t[1]=o):o=t[1];let i;t[2]!==o?(i=[...o],t[2]=o,t[3]=i):i=t[3];const a=i;let r;t[4]!==a||t[5]!==s?(r=ie.sandboxInvoke(s?`${s.orgSlug}/${s.virtualMcpId}/${s.branch}`:"none",`blog-products-by-ids:${a.join(",")}`),t[4]=a,t[5]=s,t[6]=r):r=t[6];let l;t[7]!==a||t[8]!==s?(l=()=>ce(s,Ie(a)).then(pe),t[7]=a,t[8]=s,t[9]=l):l=t[9];const d=!!s&&a.length>0;let u;t[10]!==r||t[11]!==l||t[12]!==d?(u={queryKey:r,queryFn:l,enabled:d,staleTime:6e4,retry:1},t[10]=r,t[11]=l,t[12]=d,t[13]=u):u=t[13];const n=ae(u);let c;if(t[14]!==n.data){c=new Map;for(const p of n.data??[])c.set(p.id,p);t[14]=n.data,t[15]=c}else c=t[15];let m;return t[16]!==c||t[17]!==n.isError||t[18]!==n.isLoading?(m={byId:c,isLoading:n.isLoading,isError:n.isError},t[16]=c,t[17]=n.isError,t[18]=n.isLoading,t[19]=m):m=t[19],m}function me(s){return`${s.orgSlug}/${s.virtualMcpId}/${s.branch}`}function ge(s){const e=w.c(9),{query:t,emptyLabel:o,loadingLabel:i}=s,a=se();if(t.isLoading){let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=f.jsx(xe,{size:"xs"}),e[0]=l):l=e[0];let d;return e[1]!==i?(d=f.jsxs("div",{className:"flex items-center gap-2 px-2 py-6 text-sm text-muted-foreground",children:[l,i]}),e[1]=i,e[2]=d):d=e[2],d}if(t.isError){let l;e[3]!==a?(l=a("sandbox.productPickerDialog.couldNotLoad"),e[3]=a,e[4]=l):l=e[4];let d;return e[5]!==l?(d=f.jsx("p",{className:"px-2 py-6 text-sm text-muted-foreground",children:l}),e[5]=l,e[6]=d):d=e[6],d}let r;return e[7]!==o?(r=f.jsx("p",{className:"px-2 py-6 text-center text-sm text-muted-foreground",children:o}),e[7]=o,e[8]=r):r=e[8],r}function Be(s){const e=w.c(32),{sandboxRef:t,enabled:o,onSelect:i,className:a}=s,r=se(),[l,d]=H.useState("");let u;e[0]!==t?(u=ie.sandboxInvoke(me(t),"blog-category-tree"),e[0]=t,e[1]=u):u=e[1];let n;e[2]!==t?(n=()=>ce(t,_e()).then(Re),e[2]=t,e[3]=n):n=e[3];let c;e[4]!==o||e[5]!==u||e[6]!==n?(c={queryKey:u,queryFn:n,enabled:o,staleTime:6e4,retry:1},e[4]=o,e[5]=u,e[6]=n,e[7]=c):c=e[7];const m=ae(c);let p,g,h,P;if(e[8]!==a||e[9]!==l||e[10]!==i||e[11]!==m||e[12]!==r){const S=Ke(m.data??[],l);h="space-y-2";let j;e[17]===Symbol.for("react.memo_cache_sentinel")?(j=C=>d(C.target.value),e[17]=j):j=e[17];let b;e[18]!==r?(b=r("sandbox.productPickerDialog.filterCategoriesPlaceholder"),e[18]=r,e[19]=b):b=e[19],e[20]!==l||e[21]!==b?(P=f.jsx(le,{value:l,onChange:j,placeholder:b,className:"h-9"}),e[20]=l,e[21]=b,e[22]=P):P=e[22],e[23]!==a?(p=re("overflow-y-auto rounded-md border",a),e[23]=a,e[24]=p):p=e[24],g=S.length===0?f.jsx(ge,{query:m,loadingLabel:r("sandbox.productPickerDialog.loadingCategories"),emptyLabel:r("sandbox.productPickerDialog.noCategories")}):f.jsx("div",{className:"p-1",children:S.map(C=>f.jsx("button",{type:"button",onClick:()=>i(C),className:"block w-full truncate px-2 py-1.5 text-left text-sm hover:bg-accent rounded-lg",children:C.label},C.path))}),e[8]=a,e[9]=l,e[10]=i,e[11]=m,e[12]=r,e[13]=p,e[14]=g,e[15]=h,e[16]=P}else p=e[13],g=e[14],h=e[15],P=e[16];let x;e[25]!==p||e[26]!==g?(x=f.jsx("div",{className:p,children:g}),e[25]=p,e[26]=g,e[27]=x):x=e[27];let v;return e[28]!==h||e[29]!==P||e[30]!==x?(v=f.jsxs("div",{className:h,children:[P,x]}),e[28]=h,e[29]=P,e[30]=x,e[31]=v):v=e[31],v}const Ue=[{id:"search",labelKey:"sandbox.productPickerDialog.modeSearch"},{id:"category",labelKey:"sandbox.productPickerDialog.modeCategory"},{id:"cluster",labelKey:"sandbox.productPickerDialog.modeClusterId"}];async function Me(s,e){if(e.length===0)return[];const t=await Promise.allSettled(e.map(r=>ce(s,r))),o=t.filter(r=>r.status==="fulfilled").map(r=>r.value);if(o.length===0){const r=t.find(l=>l.status==="rejected");throw r?r.reason:new Error("Failed to fetch products")}const i=[],a=new Set;for(const r of o)for(const l of pe(r))a.has(l.id)||(a.add(l.id),i.push(l));return i}function ue(s){const e=w.c(6),[t,o]=H.useState(""),[i,a]=H.useState(""),r=H.useRef(null);let l;e[0]!==s?(l=n=>{o(n),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>a(n),s)},e[0]=s,e[1]=l):l=e[1];const d=l;let u;return e[2]!==i||e[3]!==d||e[4]!==t?(u={value:t,debounced:i,onChange:d},e[2]=i,e[3]=d,e[4]=t,e[5]=u):u=e[5],u}function Ve(s){const e=w.c(23),{option:t,selected:o,onToggle:i}=s,a=o?"border-primary/40 bg-primary/5":"border-transparent hover:bg-accent";let r;e[0]!==a?(r=re("flex w-full items-center gap-3 rounded-lg border px-2 py-2 text-left transition-colors",a),e[0]=a,e[1]=r):r=e[1];let l;e[2]!==t.image?(l=f.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-md border border-border bg-muted",children:t.image?f.jsx("img",{src:t.image,alt:"",referrerPolicy:"no-referrer",className:"h-full w-full object-cover"}):f.jsx(we,{size:14,className:"text-muted-foreground"})}),e[2]=t.image,e[3]=l):l=e[3];let d;e[4]!==t.label?(d=f.jsx("span",{className:"line-clamp-2 text-sm",children:t.label}),e[4]=t.label,e[5]=d):d=e[5];let u;e[6]!==t.id?(u=f.jsxs("span",{className:"block truncate text-xs text-muted-foreground",children:["ID ",t.id]}),e[6]=t.id,e[7]=u):u=e[7];let n;e[8]!==d||e[9]!==u?(n=f.jsxs("span",{className:"min-w-0 flex-1",children:[d,u]}),e[8]=d,e[9]=u,e[10]=n):n=e[10];const c=o?"border-primary bg-primary text-primary-foreground":"border-border text-transparent";let m;e[11]!==c?(m=re("flex h-5 w-5 shrink-0 items-center justify-center rounded-full border",c),e[11]=c,e[12]=m):m=e[12];let p;e[13]===Symbol.for("react.memo_cache_sentinel")?(p=f.jsx(be,{size:12}),e[13]=p):p=e[13];let g;e[14]!==m?(g=f.jsx("span",{className:m,children:p}),e[14]=m,e[15]=g):g=e[15];let h;return e[16]!==i||e[17]!==o||e[18]!==g||e[19]!==r||e[20]!==l||e[21]!==n?(h=f.jsxs("button",{type:"button",onClick:i,"aria-pressed":o,className:r,children:[l,n,g]}),e[16]=i,e[17]=o,e[18]=g,e[19]=r,e[20]=l,e[21]=n,e[22]=h):h=e[22],h}function Ye(s){const e=w.c(20),{sandboxRef:t,open:o,selected:i,onSelect:a}=s,r=se();if(i){let d;e[0]!==a?(d=()=>a(null),e[0]=a,e[1]=d):d=e[1];let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=f.jsx(Se,{size:14}),e[2]=u):u=e[2];let n;e[3]!==r?(n=r("sandbox.productPickerDialog.categoryLabel"),e[3]=r,e[4]=n):n=e[4];let c;e[5]!==i.label?(c=f.jsx("span",{className:"text-foreground",children:i.label}),e[5]=i.label,e[6]=c):c=e[6];let m;e[7]!==r?(m=r("sandbox.productPickerDialog.change"),e[7]=r,e[8]=m):m=e[8];let p;e[9]!==n||e[10]!==c||e[11]!==m?(p=f.jsxs("span",{className:"truncate",children:[n,c," —",m]}),e[9]=n,e[10]=c,e[11]=m,e[12]=p):p=e[12];let g;return e[13]!==d||e[14]!==p?(g=f.jsxs("button",{type:"button",onClick:d,className:"flex items-center gap-1.5 rounded-lg px-2 py-1.5 text-sm text-muted-foreground hover:bg-accent hover:text-foreground",children:[u,p]}),e[13]=d,e[14]=p,e[15]=g):g=e[15],g}let l;return e[16]!==a||e[17]!==o||e[18]!==t?(l=f.jsx(Be,{sandboxRef:t,enabled:o,onSelect:a,className:"h-48"}),e[16]=a,e[17]=o,e[18]=t,e[19]=l):l=e[19],l}function et(s){const e=w.c(90),{open:t,onOpenChange:o,sandboxRef:i,selectedIds:a,onChange:r,onPicked:l,multiple:d}=s,u=d===void 0?!0:d,n=se(),[c,m]=H.useState("search"),p=ue(300),g=ue(300),[h,P]=H.useState(null),x=c==="search"?p.debounced:c==="cluster"?g.debounced:h?.path??"";let v;e[0]!==c||e[1]!==x?(v=$e(c,x),e[0]=c,e[1]=x,e[2]=v):v=e[2];const S=v;let j;e[3]!==c||e[4]!==i||e[5]!==x?(j=ie.sandboxInvoke(me(i),`blog-product:${c}:${x}`),e[3]=c,e[4]=i,e[5]=x,e[6]=j):j=e[6];let b;e[7]!==S||e[8]!==i?(b=()=>Me(i,S),e[7]=S,e[8]=i,e[9]=b):b=e[9];const C=t&&S.length>0;let X;e[10]!==j||e[11]!==b||e[12]!==C?(X={queryKey:j,queryFn:b,enabled:C,staleTime:6e4,retry:1},e[10]=j,e[11]=b,e[12]=C,e[13]=X):X=e[13];const N=ae(X);let G;e[14]!==a?(G=new Set(a.filter(Boolean)),e[14]=a,e[15]=G):G=e[15];const k=G;let J;e[16]!==u||e[17]!==r||e[18]!==l||e[19]!==k||e[20]!==a?(J=y=>{const te=y.id,ne=k.has(te);if(l){l(y,!ne);return}r(u?ne?a.filter(he=>he!==te):[...a.filter(Boolean),te]:ne?[]:[te])},e[16]=u,e[17]=r,e[18]=l,e[19]=k,e[20]=a,e[21]=J):J=e[21];const oe=J;let W;e[22]!==N.data?(W=N.data??[],e[22]=N.data,e[23]=W):W=e[23];const Z=W,D=S.length===0;let T;e[24]!==u||e[25]!==n?(T=n(u?"sandbox.productPickerDialog.addProducts":"sandbox.productPickerDialog.chooseProduct"),e[24]=u,e[25]=n,e[26]=T):T=e[26];let E;e[27]!==T?(E=f.jsx(je,{className:"border-b border-border px-4 py-3",children:f.jsx(Pe,{className:"text-sm font-medium",children:T})}),e[27]=T,e[28]=E):E=e[28];let L;e[29]!==c||e[30]!==n?(L=Ue.map(y=>f.jsx("button",{type:"button",onClick:()=>m(y.id),className:re("rounded-lg px-2.5 py-1 text-sm transition-colors",c===y.id?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),children:n(y.labelKey)},y.id)),e[29]=c,e[30]=n,e[31]=L):L=e[31];let $;e[32]!==L?($=f.jsx("div",{className:"flex shrink-0 items-center gap-1 border-b border-border px-4 py-2",children:L}),e[32]=L,e[33]=$):$=e[33];let _;e[34]!==c||e[35]!==p||e[36]!==n?(_=c==="search"&&f.jsx(le,{autoFocus:!0,value:p.value,onChange:y=>p.onChange(y.target.value),placeholder:n("sandbox.productPickerDialog.searchProductsPlaceholder"),className:"h-9"}),e[34]=c,e[35]=p,e[36]=n,e[37]=_):_=e[37];let I;e[38]!==g||e[39]!==c||e[40]!==n?(I=c==="cluster"&&f.jsx(le,{autoFocus:!0,value:g.value,onChange:y=>g.onChange(y.target.value),placeholder:n("sandbox.productPickerDialog.clusterIdPlaceholder"),className:"h-9"}),e[38]=g,e[39]=c,e[40]=n,e[41]=I):I=e[41];let q;e[42]!==h||e[43]!==c||e[44]!==t||e[45]!==i?(q=c==="category"&&f.jsx(Ye,{sandboxRef:i,open:t,selected:h,onSelect:P}),e[42]=h,e[43]=c,e[44]=t,e[45]=i,e[46]=q):q=e[46];let A;e[47]!==_||e[48]!==I||e[49]!==q?(A=f.jsxs("div",{className:"shrink-0 space-y-2 px-4 py-3",children:[_,I,q]}),e[47]=_,e[48]=I,e[49]=q,e[50]=A):A=e[50];let F;e[51]!==Z||e[52]!==N||e[53]!==k||e[54]!==D||e[55]!==n||e[56]!==oe?(F=Z.length>0?Z.map(y=>f.jsx(Ve,{option:y,selected:k.has(y.id),onToggle:()=>oe(y)},y.id)):!D&&f.jsx(ge,{query:N,loadingLabel:n("sandbox.productPickerDialog.loadingProducts"),emptyLabel:n("sandbox.productPickerDialog.noProductsFound")}),e[51]=Z,e[52]=N,e[53]=k,e[54]=D,e[55]=n,e[56]=oe,e[57]=F):F=e[57];let O;e[58]!==c||e[59]!==D||e[60]!==n?(O=D&&f.jsx("p",{className:"px-2 py-6 text-center text-sm text-muted-foreground",children:n(c==="category"?"sandbox.productPickerDialog.pickCategoryPrompt":"sandbox.productPickerDialog.enterClusterPrompt")}),e[58]=c,e[59]=D,e[60]=n,e[61]=O):O=e[61];let R;e[62]!==F||e[63]!==O?(R=f.jsxs("div",{className:"min-h-0 flex-1 space-y-1 overflow-y-auto border-t border-border px-3 py-2",children:[F,O]}),e[62]=F,e[63]=O,e[64]=R):R=e[64];let K;e[65]!==k.size||e[66]!==n?(K=k.size===0?n("sandbox.productPickerDialog.noneSelected"):n("sandbox.productPickerDialog.selectedCount",{count:String(k.size)}),e[65]=k.size,e[66]=n,e[67]=K):K=e[67];let z;e[68]!==K?(z=f.jsx("span",{className:"text-xs text-muted-foreground",children:K}),e[68]=K,e[69]=z):z=e[69];let B;e[70]!==o?(B=()=>o(!1),e[70]=o,e[71]=B):B=e[71];let U;e[72]!==n?(U=n("sandbox.productPickerDialog.done"),e[72]=n,e[73]=U):U=e[73];let M;e[74]!==B||e[75]!==U?(M=f.jsx(ke,{size:"sm",onClick:B,children:U}),e[74]=B,e[75]=U,e[76]=M):M=e[76];let V;e[77]!==z||e[78]!==M?(V=f.jsxs("div",{className:"flex shrink-0 items-center justify-between border-t border-border px-4 py-3",children:[z,M]}),e[77]=z,e[78]=M,e[79]=V):V=e[79];let Y;e[80]!==E||e[81]!==$||e[82]!==A||e[83]!==R||e[84]!==V?(Y=f.jsxs(ve,{className:"flex h-[85svh] flex-col gap-0 overflow-hidden p-0 sm:h-[560px] sm:max-w-[560px]",children:[E,$,A,R,V]}),e[80]=E,e[81]=$,e[82]=A,e[83]=R,e[84]=V,e[85]=Y):Y=e[85];let ee;return e[86]!==o||e[87]!==t||e[88]!==Y?(ee=f.jsx(Ce,{open:t,onOpenChange:o,children:Y}),e[86]=o,e[87]=t,e[88]=Y,e[89]=ee):ee=e[89],ee}export{Be as C,et as P,$e as b,ce as i,pe as p,We as r,Ze as u};