decocms
Version:
Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools
2 lines (1 loc) • 2.67 kB
JavaScript
import{q as Q,b as q,e as v,K as l}from"./index-DoEtSiIe.js";import{u as E}from"./use-voice-input-DJjQBO4e.js";import{x as T,c as x,u as B,v as H,aq as U,as as j,au as A,aF as F,aj as O,ax as R,Z as V,X as W,Y as L,aE as Y,aD as G,y as J,$ as N}from"./site-editor-toast-B-FDGvtN.js";import{s as X}from"./sandbox-git-api-DiUyKbJU.js";import{u as Z}from"./chat-context-vJ6R-Clt.js";import{i as $,H as z}from"./hosted-reconcile-CTronLZo.js";import{k as S}from"./use-never-published-C4cAqdmZ.js";import{b}from"./sandbox-url-D3mC8qhT.js";import{d as g}from"./utils-CzRFs-0R.js";function re({orgSlug:i,virtualMcpId:s,branch:o}){const n=Q(),p=Z()?.taskId??null,w=T(s),K=E(s).runtime==="cms",{url:P}=x(s),u=B(s,o),c=u.kind==="protocol"?u:null,f=H({orgSlug:i,virtualMcpId:s,branch:o}),C=async e=>{if(P)return{ok:!0,existed:!0};if(K){const r=await Y({orgSlug:i,virtualMcpId:s,branch:o},{delete:[e]});return G(n,{orgSlug:i,virtualMcpId:s,branch:o},r),await n.invalidateQueries({queryKey:X({orgSlug:i,virtualMcpId:s,branch:o,threadId:p})}),{ok:!0,existed:!0}}const t=J(w,g(e)),a=await fetch(b({orgSlug:i,virtualMcpId:s,branch:o,threadId:p},"unlink"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:t})});return a.ok?a.json():N(a,"Delete")},h=q(),y=v({mutationKey:L(i,s,o),scope:W(i,s,o),mutationFn:async({blockKey:e,base:t,shown:a})=>{if(u.kind==="pending"||u.kind==="unavailable")throw O("CMS storage");if(c?.source==="github"){const r=a?.();try{await $({queryClient:n,backend:c,params:{orgSlug:i,virtualMcpId:s,branch:o},cacheKey:f},{writes:{},deletes:[e]},t&&t.value!==void 0?{[e]:t.value}:void 0,r&&r.value!==void 0?{[e]:r}:void 0)}catch(d){if(d instanceof z)return{keptTheirs:!0,deleted:!1};throw d}return{ok:!0,existed:!0}}return c?(await R(n,c,{orgSlug:i,virtualMcpId:s,branch:o},f,{delete:[e]}),{ok:!0,existed:!0}):V({queryClient:n,orgSlug:i,virtualMcpId:s,branch:o,backend:u,cacheKey:f},{kind:"edit",write:()=>C(e)})},onMutate:async({blockKey:e})=>{const t=l.decofile(f);await n.cancelQueries({queryKey:t});const a=n.getQueryData(t),r=!!a&&e in a,d=a?.[e];return n.setQueryData(t,m=>{if(!m)return m;const{[e]:_,...D}=m;return D}),{queryKey:t,blockKey:e,hadKey:r,previousValue:d}},onError:(e,t,a)=>{j(h,e),a&&(c?.source==="github"&&(A(e)||e instanceof F)||n.setQueryData(a.queryKey,r=>a.hadKey?{...r??{},[a.blockKey]:a.previousValue}:r))},onSuccess:e=>{if(S(e)){U(h,!1);return}n.invalidateQueries({queryKey:l.liveMeta(i,s,o)})}}),k=e=>{if(e.base)return e;const t=n.getQueryData(l.decofile(f));return t?{...e,base:{value:t[e.blockKey]}}:e};return{...y,mutate:(e,t)=>y.mutate(k(e),t),mutateAsync:(e,t)=>y.mutateAsync(k(e),t)}}export{re as u};