decocms
Version:
Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools
2 lines (1 loc) • 5.37 kB
JavaScript
import{b as F,q as L,e as q,f$ as W,fR as z,K as S,t as K,fQ as J,fP as v,eh as U,fS as X,hN as Y,fX as G,hO as $,fI as Z}from"./index-DoEtSiIe.js";import{C as I,E as ee}from"./content-changes-DXqxs3Wb.js";import{u as te,v as ne,aA as D,ax as oe,X as se,Y as re,av as ae,aP as ce,aQ as B,aR as ie,aO as P,au as le,az as ue,aJ as fe,ay as de}from"./site-editor-toast-B-FDGvtN.js";import{c as pe,b as ye,p as he,j as me,k as ke,l as be,f as Oe,m as we,d as Ce}from"./hosted-reconcile-CTronLZo.js";import{k as Ee,a7 as je}from"./blocks-tab-states-CTy1iAF5.js";import{a as ve}from"./use-move-blocks-CCDsEu9Z.js";function ge(n,u){const d=(n.deletes??[]).filter(i=>!Object.hasOwn(n.writes,i)),p=[...Object.keys(n.writes),...d],o={},k=[];for(const i of p){const O=u(i);O===void 0?k.push(i):o[i]=O}return k.length>0?{kind:"unread",blockKeys:k}:{kind:"apply",patch:{set:n.writes,...d.length>0?{delete:d}:{}},ifMatch:o}}function Re(n,u){const d=u.pointer.split("/").slice(1).map(k=>k.replaceAll("~1","/").replaceAll("~0","~")),p=je(d[0]),o=d[1];return!p||o===void 0?u:p==="experiments"?{...u,label:n("sectionsEditor.formConflict.ruleExperiment",{name:o}),phrase:n("sectionsEditor.formConflict.ruleExperimentPhrase",{name:o})}:{...u,label:n("sectionsEditor.formConflict.ruleCampaign",{name:o}),phrase:n("sectionsEditor.formConflict.ruleCampaignPhrase",{name:o}),mine:Q(u.mine,d.length),theirs:Q(u.theirs,d.length)}}function Q(n,u){return u===3?$(n)??n:u===2&&n&&typeof n=="object"?Z(n)??n:n}function Ke(n){return{type:"object",properties:{experiments:{type:"object",title:n("thread.publishPopover.abTests")},campaigns:{type:"object",title:n("thread.publishPopover.campaignDates")}}}}function De(n){return new I(ee.Conflict,"not read yet",{entries:Object.fromEntries(n.map(u=>[u,{expected:null,actual:null}]))})}function Te({orgSlug:n,virtualMcpId:u,branch:d}){const p=F(),o=L(),k=te(u,d),i=k.kind==="protocol"?k:null,O=i?.source==="github",m=ne({orgSlug:n,virtualMcpId:u,branch:d}),w={orgSlug:n,virtualMcpId:u,branch:d},C=S.decofile(m),x=q({mutationKey:re(n,u,d),scope:se(n,u,d),mutationFn:async e=>{const r=[...Object.keys(e.writes),...e.deletes.filter(t=>!Object.hasOwn(e.writes,t))],a={};for(const t of r){const s=Object.hasOwn(e.pinned,t)?e.pinned[t]:D(o,m,t,i);a[t]=await _(s,t,e.copies)}const c=ge(e,t=>a[t]);if(c.kind==="unread")throw De(c.blockKeys);return oe(o,i,w,m,c.patch,c.ifMatch)}}),T=async(e,r)=>{for(const a of e)await de(o,i,w,m,a,r);return K.info(p("sectionsEditor.namedRules.changedMeanwhile"),{...P,description:p("sectionsEditor.namedRules.changedMeanwhileHint")}),{ok:!1,reason:"changed"}},g=async(e,r,a,c)=>{const t=await H(e,r,a,c);if(O&&!(!t.ok&&t.reason==="unavailable")){const s=pe(w),l=[...Object.keys(e.writes),...e.deletes];U.schedule(()=>{for(const y of l)ye(s,y)})}return t},H=async(e,r,a,c)=>{const t=[...Object.keys(e.writes),...e.deletes];if(a>=Ce||!X())return T(t,c);const s=i&&fe(o,i,m,c)?o.getQueryData(C)??{}:await R({blocks:t});if(!s)return K.info(p("sectionsEditor.namedRules.unavailable"),{...P,description:p("sectionsEditor.namedRules.unavailableHint")}),{ok:!1,reason:"unavailable"};const l=he(t,r,e,s),y=l.pointers.length===0?{}:await me(l,Ke(p),{author:(()=>{const h=i?Y(i,w):null,E=ke(l.pointers[0]??"");return h&&E?{draft:h,blockKey:E}:null})()},h=>Re(p,h)),b=l.pointers.length===0?l.merged:G(l,y),f=be(t,b,s);return Oe(y)&&we(f,s)?{ok:!0,keptTheirs:!0}:A(f,a+1)},M=e=>A(e,0),A=async(e,r)=>{if(!i)return K.info(p("sectionsEditor.namedRules.unavailable"),{...P,description:p("sectionsEditor.namedRules.unavailableHint")}),{ok:!1,reason:"unavailable"};const a=i.source==="github"?e.writes:J(e.writes),c=(e.deletes??[]).filter(f=>!Object.hasOwn(a,f)),t=[...Object.keys(a),...c];if(t.length===0)return{ok:!0};const s=o.getQueryData(C),l=O?N(e.basis,s):null;if(l)return g({writes:a,deletes:c},l,r);const y=await V(t,s);if(!y)return g({writes:a,deletes:c},s,r);const b=new Map;for(const f of t)s&&Object.hasOwn(s,f)&&b.set(f,s[f]);o.setQueryData(C,f=>ve(f,{writes:a,deletes:c})),o.cancelQueries({queryKey:C});try{const f={};for(const h of t)s&&Object.hasOwn(s,h)&&(f[h]=s[h]);return await x.mutateAsync({writes:a,deletes:c,pinned:y,copies:f}),{ok:!0}}catch(f){return o.setQueryData(C,h=>{if(!h)return h;const E={...h};for(const j of t)b.has(j)?E[j]=b.get(j):delete E[j];return E}),le(f)?g({writes:a,deletes:c},s,r,f):(ue(p,f instanceof Error?f:new Error(String(f)),i.source),{ok:!1,reason:"failed"})}},N=(e,r)=>{if(!e||!Object.keys(e).some(t=>v(e[t]??null)!==v(r?.[t]??null)))return null;const c={...r};for(const[t,s]of Object.entries(e))s===void 0?delete c[t]:c[t]=s;return c},_=async(e,r,a)=>!O||!Object.hasOwn(a,r)?e:W(e,a[r],z(o,m,r)),V=async(e,r)=>{const a=B(o,w),c={},t=[];for(const l of e){if(a.has(l))continue;const y=D(o,m,l,i);y===void 0?t.push(l):c[l]=y}if(t.length===0)return c;const s=await R({blocks:t});if(!s)return null;for(const l of t){const y=!!r&&Object.hasOwn(r,l);if(y!==Object.hasOwn(s,l)||y&&v(s[l])!==v(r[l]))return null;const b=D(o,m,l,i);if(b===void 0)return null;c[l]=b}return c},R=async(e={})=>{if(!i)return null;try{const r=await ae(o,i,w,m);if(!i.hosted)return r.blocks;const a=o.getQueryData(S.contentIndex(m));return await ce(o,i.hosted,m,[...Ee,...e.blocks??[]],B(o,w)),ie(a,o.getQueryData(C)??r.blocks)}catch{return null}};return{apply:M,reread:R,isPending:x.isPending,holdsCopy:O}}export{Te as u};