decocms
Version:
Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools
2 lines (1 loc) • 4.89 kB
JavaScript
import{c as Z,b as ee,r as B,i as te,e as se,j as i,n as M,m as ie,K as le,t as Q,h as ne,B as Y,I as oe}from"./index-ztdGKvBm.js";import{E as re}from"./empty-state-I_cTbW85.js";import{L as $}from"./label-8UxgpYiA.js";import{T as ae}from"./textarea-viSdm6BE.js";import{a as G}from"./admin-fetch-BhTJlAsX.js";function xe(){const e=Z.c(66),s=ee();let _;e[0]===Symbol.for("react.memo_cache_sentinel")?(_={},e[0]=_):_=e[0];const[r,D]=B.useState(_),[H,U]=B.useState(null),[m,J]=B.useState("");let k;e[1]===Symbol.for("react.memo_cache_sentinel")?(k={queryKey:le.deploymentAdminPrompts(),queryFn:de},e[1]=k):k=e[1];const{data:a,isLoading:V,isError:W,error:C,refetch:c}=te(k),w=a?.prompts??[],l=w.find(t=>t.id===H)??w[0],n=Object.keys(r).filter(t=>r[t]!==w.find(o=>o.id===t)?.content);let p;e[2]!==a?.baseSha||e[3]!==n||e[4]!==r||e[5]!==m?(p=()=>G("/api/_admin/prompts/pull-request",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:m.trim()||void 0,baseSha:a?.baseSha,edits:n.map(t=>({id:t,content:r[t]}))})}),e[2]=a?.baseSha,e[3]=n,e[4]=r,e[5]=m,e[6]=p):p=e[6];let f;e[7]!==c||e[8]!==s?(f=t=>{Q.success(s("admin.prompts.prOpened",{number:String(t.number)}),{action:{label:s("admin.prompts.viewPr"),onClick:()=>window.open(t.url,"_blank")}}),D({}),J(""),c()},e[7]=c,e[8]=s,e[9]=f):f=e[9];let u;e[10]!==s?(u=t=>{Q.error(t instanceof Error?t.message:s("admin.prompts.prFailed"))},e[10]=s,e[11]=u):u=e[11];let F;e[12]!==p||e[13]!==f||e[14]!==u?(F={mutationFn:p,onSuccess:f,onError:u},e[12]=p,e[13]=f,e[14]=u,e[15]=F):F=e[15];const d=se(F);if(V){let t;return e[16]===Symbol.for("react.memo_cache_sentinel")?(t=i.jsx("div",{className:"flex h-full items-center justify-center",children:i.jsx(ne,{className:"size-5 text-muted-foreground"})}),e[16]=t):t=e[16],t}if(W||!l){let t;e[17]!==s?(t=s("admin.prompts.failedToLoadTitle"),e[17]=s,e[18]=t):t=e[18];let o;e[19]!==C||e[20]!==s?(o=C instanceof Error&&C.message?C.message:s("admin.prompts.failedToLoadDescription"),e[19]=C,e[20]=s,e[21]=o):o=e[21];let P;e[22]!==c?(P=()=>c(),e[22]=c,e[23]=P):P=e[23];let E;e[24]!==s?(E=s("admin.prompts.retry"),e[24]=s,e[25]=E):E=e[25];let T;e[26]!==P||e[27]!==E?(T=i.jsx(Y,{variant:"outline",size:"sm",onClick:P,children:E}),e[26]=P,e[27]=E,e[28]=T):T=e[28];let O;return e[29]!==T||e[30]!==t||e[31]!==o?(O=i.jsx(re,{title:t,description:o,actions:T}),e[29]=T,e[30]=t,e[31]=o,e[32]=O):O=e[32],O}const X=r[l.id]??l.content??"",K=a?.repo??"",R=a?.branch??"",z=a?.org??"";let x;e[33]!==s||e[34]!==K||e[35]!==R||e[36]!==z?(x=s("admin.prompts.description",{repo:K,branch:R,org:z}),e[33]=s,e[34]=K,e[35]=R,e[36]=z,e[37]=x):x=e[37];let L;e[38]!==x?(L=i.jsx("p",{className:"text-sm text-muted-foreground",children:x}),e[38]=x,e[39]=L):L=e[39];let h;e[40]!==s?(h=s("admin.prompts.prTitleLabel"),e[40]=s,e[41]=h):h=e[41];let g;e[42]!==h?(g=i.jsx($,{htmlFor:"pr-title",children:h}),e[42]=h,e[43]=g):g=e[43];let I;e[44]===Symbol.for("react.memo_cache_sentinel")?(I=t=>J(t.target.value),e[44]=I):I=e[44];let b;e[45]!==s?(b=s("admin.prompts.prTitlePlaceholder"),e[45]=s,e[46]=b):b=e[46];let j;e[47]!==b||e[48]!==m?(j=i.jsx(oe,{id:"pr-title",value:m,onChange:I,placeholder:b}),e[47]=b,e[48]=m,e[49]=j):j=e[49];let S;e[50]!==g||e[51]!==j?(S=i.jsxs("div",{className:"flex w-full flex-col gap-2 md:max-w-md",children:[g,j]}),e[50]=g,e[51]=j,e[52]=S):S=e[52];const A=n.length===0||d.isPending;let y;e[53]!==d?(y=()=>d.mutate(),e[53]=d,e[54]=y):y=e[54];let v;e[55]!==n.length||e[56]!==d.isPending||e[57]!==s?(v=d.isPending?s("admin.prompts.opening"):s("admin.prompts.openPr",{count:String(n.length)}),e[55]=n.length,e[56]=d.isPending,e[57]=s,e[58]=v):v=e[58];let N;e[59]!==A||e[60]!==y||e[61]!==v?(N=i.jsx(Y,{disabled:A,onClick:y,children:v}),e[59]=A,e[60]=y,e[61]=v,e[62]=N):N=e[62];let q;return e[63]!==S||e[64]!==N?(q=i.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-end md:justify-between",children:[S,N]}),e[63]=S,e[64]=N,e[65]=q):q=e[65],i.jsx(M,{children:i.jsx(M.Content,{children:i.jsx(M.Container,{children:i.jsxs("div",{className:"flex flex-col gap-4",children:[L,i.jsx("div",{className:"flex flex-wrap gap-1",children:w.map(t=>i.jsxs("button",{type:"button",onClick:()=>U(t.id),className:ie("rounded-lg px-3 py-1.5 text-sm font-medium transition-colors",t.id===l.id?"bg-muted text-foreground":"text-muted-foreground hover:text-foreground"),children:[t.label,n.includes(t.id)?" •":""]},t.id))}),i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx($,{htmlFor:"prompt-source",children:l.path}),i.jsx(ae,{id:"prompt-source",className:"min-h-[420px] font-mono text-xs",spellCheck:!1,value:X,disabled:l.content===null,onChange:t=>D({...r,[l.id]:t.target.value})}),l.content===null?i.jsx("p",{className:"text-sm text-destructive",children:s("admin.prompts.markerMissing",{id:l.id})}):null]}),q]})})})})}function de(){return G("/api/_admin/prompts")}export{xe as default};