decocms
Version:
Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools
2 lines (1 loc) • 4.81 kB
JavaScript
import{b as S}from"./sandbox-url-D3mC8qhT.js";import{aJ as h,bF as g,aK as c,dH as O}from"./index-ztdGKvBm.js";function s(e,n){return S(e,`git/${n}`)}class l extends Error{constructor(n,t){super(n),this.status=t,this.name="SandboxGitError"}status}function F(e){return e instanceof l&&(e.status===503||e.status===410||e.status===404)}function P(e,n){return n instanceof l&&n.status===429?!1:e<1}const G=h({code:O("block-deleted-on-base"),error:c(),blocks:g(h({path:c(),key:c(),renamedTo:c().optional(),missingRefs:g(c())})).min(1)});class p extends Error{constructor(n,t){super(n),this.blocks=t,this.name="BlocksDeletedOnBaseError"}blocks}async function i(e){let n;try{n=await e.json()}catch{throw new l(`Request failed (${e.status})`,e.status)}const t=e.status===409?G.safeParse(n):null;if(t?.success)throw new p(t.data.error,t.data.blocks);if(!e.ok)throw new l(typeof n.error=="string"?n.error:`Request failed (${e.status})`,e.status);return n}function o(e,n){return fetch(e,{cache:"no-store",...n})}async function k(e){const n=await o(s(e,"status"),void 0);return i(n)}async function u(e,n){const t=await o(s(e,"diff"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...n?.base?{base:n.base}:{},...n?.headSha?{headSha:n.headSha}:{}})});return i(t)}function B(e){const n={};for(const[t,r]of Object.entries(e.diffs))d(t)||f(t)||(n[t]=r);return{...e,diffs:n}}async function N(e,n){const t=await o(s(e,"publish"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({message:n})});await i(t)}async function H(e,n,t){const r=await o(s(e,"rebase"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({base:n,...t?{resolutions:t}:{}})});await i(r)}function d(e){return e==="blocks.gen.json"||e.endsWith("/blocks.gen.json")}function f(e){return e==="static/tailwind.css"||e.endsWith("/static/tailwind.css")}function j(e){return d(e)||f(e)||e.endsWith("generate.digests.json")||e.endsWith("meta.gen.json")}function x(e){return e?e.conflicted.length>0||e.renamed.length>0?!0:[...e.modified,...e.created,...e.deleted,...e.not_added,...e.staged].some(n=>!j(n)):!1}function I(e){return e?!x(e)&&(e.aheadOfBase??0)===0&&(e.unpushed??0)===0:!1}function T(e){return e===".deco"||e.endsWith("/.deco")||e.startsWith(".deco/")||e.includes("/.deco/")}function b(e){return e.length===0?!1:e.every(n=>T(n)||d(n)||f(n))}function y(e){return e?b(Object.keys(e.diffs)):!1}const D="smart";function L(e){return e==="code-review"||e==="open"||e==="smart"?e:D}function U(e){let n=5381;const t=r=>{for(let a=0;a<r.length;a++)n=(n<<5)+n+r.charCodeAt(a)|0};for(const r of Object.keys(e.diffs).sort()){const a=e.diffs[r];t(r),t("\0from:"),t(a?.from??""),t("\0to:"),t(a?.to??""),t("\0\0")}return(n>>>0).toString(36)}async function K(e,n){const t=await o(s(e,"judge-review"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({status:n.status,diff:B(n.diff),...n.language?{language:n.language}:{}})});return i(t)}async function Q(e,n){const t=await o(s(e,"discard"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({filepaths:n})});await i(t)}const v="current";function $(e){return e?.[v]??null}function M(e,n,t){return["sandbox-git-status",e,n,t]}function E(e){return["sandbox-git-status",e.orgSlug,e.virtualMcpId,e.branch,e.threadId]}const R=5e3;function Y(e){return{queryKey:E(e),queryFn:()=>k(e),staleTime:R,retry:P}}function _(e){return e?e.modified.length+e.created.length+e.deleted.length+e.not_added.length+e.renamed.length:0}function J(e){return e?_(e)>0||e.staged.length>0||e.conflicted.length>0:!1}function W(e,n){return{diffs:{...e?.diffs??{},...n?.diffs??{}},...e?.mergeBaseSha?{mergeBaseSha:e.mergeBaseSha}:{}}}function q(e){return e.aheadOfBase===void 0||e.aheadOfBase>0||e.ahead>0||(e.unpushed??0)>0}async function z(e,n,t,r){if(r?.fastPreview)return u(e,{base:t});const a=n.headSha?{base:t,headSha:n.headSha}:{base:t},[m,w]=await Promise.all([q(n)?u(e,a):null,J(n)?u(e):null]);return W(m,w)}function V(e,n="code-review"){return n==="open"?{allowed:!0,reason:null}:y(e)?{allowed:!0,reason:null}:{allowed:!1,reason:null}}function X(e,n){return e.length===0?{allowed:!1,reason:null}:n==="open"?{allowed:!0,reason:null}:b(e)?{allowed:!0,reason:null}:n==="smart"?{allowed:!1,reason:null,pending:!0}:{allowed:!1,reason:null}}function Z(e,n){return n!=="smart"||!e||Object.keys(e.diffs).length===0?!1:!y(e)}function ee(e,n){if(n)return{allowed:!1,reason:null,pending:!0};if(!e)return{allowed:!0,reason:null};if(!e.requiresReview)return{allowed:!0,reason:null};const t=e.reason?.trim();return{allowed:!1,reason:t||null}}export{p as B,M as a,Y as b,F as c,z as d,K as e,k as f,X as g,J as h,j as i,V as j,ee as k,$ as l,q as m,Z as n,x as o,L as p,H as q,U as r,E as s,I as t,N as u,Q as v};