decocms
Version:
Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools
2 lines (1 loc) • 10.5 kB
JavaScript
import{c as Y,b as X,a6 as lt,T as it,an as rt,eR as ct,K as tt,j as s,m as ut,i as mt,gK as dt}from"./index-ztdGKvBm.js";import{u as ft}from"./useInfiniteQuery-Ypmdjx1e.js";import{b as xt}from"./use-connection-CcG4QE1K.js";import{u as pt}from"./use-mcp-client-2MG3LveS.js";import{u as gt}from"./repository-binding-D_Xc1yRH.js";import{b as ht,a as Rt}from"./sheet-C-umRrOH.js";import{e as jt,a as Nt,b as st,T as G,d as Tt,c as Q}from"./table-C3AdbrSy.js";import{E as et}from"./empty-state-I_cTbW85.js";import{u as bt}from"./use-id-selection-DNp_iXDg.js";import{u as St}from"./use-infinite-scroll-DdrDrAAo.js";import{g as vt}from"./task-status-DYgcNbkh.js";import{e as Ct}from"./use-automations-BF2lxi1L.js";import{T as wt,f as at,a as nt}from"./thread-sheet-body-CC8y_ZHb.js";const W=50;function J(m){const t=Y.c(10),{title:r,value:c,subtitle:e}=m;let o;t[0]!==r?(o=s.jsx("span",{className:"text-sm text-foreground/70",children:r}),t[0]=r,t[1]=o):o=t[1];let n;t[2]!==c?(n=s.jsx("span",{className:"text-3xl font-normal tabular-nums",children:c}),t[2]=c,t[3]=n):n=t[3];let a;t[4]!==e?(a=e&&s.jsx("span",{className:"text-xs text-muted-foreground",children:e}),t[4]=e,t[5]=a):a=t[5];let l;return t[6]!==o||t[7]!==n||t[8]!==a?(l=s.jsxs(dt,{className:"pt-4 px-4 pb-5 gap-1",children:[o,n,a]}),t[6]=o,t[7]=n,t[8]=a,t[9]=l):l=t[9],l}function yt(m){const t=Y.c(45),{automationId:r,range:c}=m,e=X(),{data:o,isLoading:n}=Ct(r,c),a=o?.runs,l=o?.usage;let P;t[0]!==a?(P=a&&a.total>0?`${Math.round(a.completed/a.total*100)}%`:"—",t[0]=a,t[1]=P):P=t[1];const C=P;let w;t[2]!==e||t[3]!==l?(w=l&&l.truncated?e("automations.automationRuns.lastRunsSubtitle",{count:l.sampledRuns}):void 0,t[2]=e,t[3]=l,t[4]=w):w=t[4];const h=w;let b;t[5]!==e?(b=e("automations.automationRuns.runsTitle"),t[5]=e,t[6]=b):b=t[6];let d;t[7]!==n||t[8]!==a?.total?(d=n?"…":a?.total.toLocaleString()??"0",t[7]=n,t[8]=a?.total,t[9]=d):d=t[9];let f;t[10]!==a||t[11]!==e?(f=a?`${a.completed} ${e("automations.automationRuns.ok")} · ${a.failed} ${e("automations.automationRuns.failed")}${a.inProgress>0?` · ${a.inProgress} ${e("automations.automationRuns.running")}`:""}`:void 0,t[10]=a,t[11]=e,t[12]=f):f=t[12];let x;t[13]!==b||t[14]!==d||t[15]!==f?(x=s.jsx(J,{title:b,value:d,subtitle:f}),t[13]=b,t[14]=d,t[15]=f,t[16]=x):x=t[16];let j;t[17]!==e?(j=e("automations.automationRuns.successRateTitle"),t[17]=e,t[18]=j):j=t[18];const y=n?"…":C;let S;t[19]!==j||t[20]!==y?(S=s.jsx(J,{title:j,value:y}),t[19]=j,t[20]=y,t[21]=S):S=t[21];let N;t[22]!==e?(N=e("automations.automationRuns.tokensTitle"),t[22]=e,t[23]=N):N=t[23];let u;t[24]!==n||t[25]!==l?.totalTokens?(u=n?"…":at(l?.totalTokens??0),t[24]=n,t[25]=l?.totalTokens,t[26]=u):u=t[26];let v;t[27]!==N||t[28]!==u||t[29]!==h?(v=s.jsx(J,{title:N,value:u,subtitle:h}),t[27]=N,t[28]=u,t[29]=h,t[30]=v):v=t[30];let i;t[31]!==e?(i=e("automations.automationRuns.costTitle"),t[31]=e,t[32]=i):i=t[32];let p;t[33]!==n||t[34]!==l?(p=n?"…":l&&l.costUsd>0?nt(l.costUsd):"—",t[33]=n,t[34]=l,t[35]=p):p=t[35];let T;t[36]!==i||t[37]!==p||t[38]!==h?(T=s.jsx(J,{title:i,value:p,subtitle:h}),t[36]=i,t[37]=p,t[38]=h,t[39]=T):T=t[39];let g;return t[40]!==v||t[41]!==T||t[42]!==x||t[43]!==S?(g=s.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[x,S,v,T]}),t[40]=v,t[41]=T,t[42]=x,t[43]=S,t[44]=g):g=t[44],g}function It(m){const t=Y.c(57),{run:r,usage:c,onClick:e,lastRowRef:o}=m,n=X();let a,l;if(t[0]!==r.created_at){const k=new Date(r.created_at);a=k.toLocaleDateString("en-US",{month:"short",day:"numeric"}),l=k.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit"}),t[0]=r.created_at,t[1]=a,t[2]=l}else a=t[1],l=t[2];const P=l;let C,w,h,b,d,f,x,j,y,S,N;if(t[3]!==o||t[4]!==e||t[5]!==r.status||t[6]!==r.title||t[7]!==n){const k=vt(r.status),$=k.icon;w=st,y=o,S="h-14 cursor-pointer hover:bg-accent transition-colors border-b-0",N=e,t[19]!==r.title?(h=s.jsx(Q,{className:"min-w-0 pr-2 pl-4 md:pr-4",children:s.jsx("div",{className:"font-medium text-foreground truncate",children:r.title})}),t[19]=r.title,t[20]=h):h=t[20],C=Q,j="w-28 px-3",f="flex items-center gap-1.5",x=s.jsx($,{size:14,className:k.iconClassName}),b=ut("text-sm",k.labelColor),d=n(k.labelKey),t[3]=o,t[4]=e,t[5]=r.status,t[6]=r.title,t[7]=n,t[8]=C,t[9]=w,t[10]=h,t[11]=b,t[12]=d,t[13]=f,t[14]=x,t[15]=j,t[16]=y,t[17]=S,t[18]=N}else C=t[8],w=t[9],h=t[10],b=t[11],d=t[12],f=t[13],x=t[14],j=t[15],y=t[16],S=t[17],N=t[18];let u;t[21]!==b||t[22]!==d?(u=s.jsx("span",{className:b,children:d}),t[21]=b,t[22]=d,t[23]=u):u=t[23];let v;t[24]!==u||t[25]!==f||t[26]!==x?(v=s.jsxs("div",{className:f,children:[x,u]}),t[24]=u,t[25]=f,t[26]=x,t[27]=v):v=t[27];let i;t[28]!==C||t[29]!==v||t[30]!==j?(i=s.jsx(C,{className:j,children:v}),t[28]=C,t[29]=v,t[30]=j,t[31]=i):i=t[31];let p;t[32]!==c?(p=c?at(c.totalTokens):"—",t[32]=c,t[33]=p):p=t[33];let T;t[34]!==p?(T=s.jsx(Q,{className:"w-24 px-3 text-right tabular-nums text-muted-foreground",children:p}),t[34]=p,t[35]=T):T=t[35];let g;t[36]!==c?(g=c&&c.costUsd>0?nt(c.costUsd):"—",t[36]=c,t[37]=g):g=t[37];let I;t[38]!==g?(I=s.jsx(Q,{className:"w-24 px-3 text-right tabular-nums text-muted-foreground",children:g}),t[38]=g,t[39]=I):I=t[39];let D;t[40]!==a?(D=s.jsx("div",{children:a}),t[40]=a,t[41]=D):D=t[41];let _;t[42]!==P?(_=s.jsx("div",{className:"text-xs text-muted-foreground/60",children:P}),t[42]=P,t[43]=_):_=t[43];let E;t[44]!==D||t[45]!==_?(E=s.jsxs(Q,{className:"w-32 px-3 pr-5 text-muted-foreground",children:[D,_]}),t[44]=D,t[45]=_,t[46]=E):E=t[46];let M;return t[47]!==w||t[48]!==h||t[49]!==i||t[50]!==T||t[51]!==I||t[52]!==E||t[53]!==y||t[54]!==S||t[55]!==N?(M=s.jsxs(w,{ref:y,className:S,onClick:N,children:[h,i,T,I,E]}),t[47]=w,t[48]=h,t[49]=i,t[50]=T,t[51]=I,t[52]=E,t[53]=y,t[54]=S,t[55]=N,t[56]=M):M=t[56],M}function Vt(m){const t=Y.c(73),{automationId:r,triggerIds:c,range:e}=m,o=X(),{org:n,locator:a}=lt();let l;t[0]!==n.id||t[1]!==n.slug?(l={connectionId:it,orgId:n.id,orgSlug:n.slug},t[0]=n.id,t[1]=n.slug,t[2]=l):l=t[2];const P=pt(l),C=rt(),w=xt(),h=gt(),{data:b}=ct(),d=c.length>0;let f;t[3]!==r||t[4]!==n.id||t[5]!==c?(f=tt.automationRuns(n.id,r,c),t[3]=r,t[4]=n.id,t[5]=c,t[6]=f):f=t[6];let x;t[7]!==C||t[8]!==c?(x=async U=>{const{pageParam:z}=U,ot=z===void 0?0:z;return await C.call("COLLECTION_THREADS_LIST",{limit:W,offset:ot,where:{trigger_ids:c}})},t[7]=C,t[8]=c,t[9]=x):x=t[9];let j;t[10]!==d||t[11]!==f||t[12]!==x?(j={queryKey:f,queryFn:x,initialPageParam:0,getNextPageParam:Dt,enabled:d,staleTime:3e4},t[10]=d,t[11]=f,t[12]=x,t[13]=j):j=t[13];const{data:y,fetchNextPage:S,hasNextPage:N,isFetchingNextPage:u,isLoading:v}=ft(j);let i,p,T,g;t[14]!==y?.pages||t[15]!==a||t[16]!==e?(i=(y?.pages??[]).flatMap(kt),g=i.map(_t),T=mt,p=tt.monitoringThreadUsage(a,JSON.stringify({ids:g,...e})),t[14]=y?.pages,t[15]=a,t[16]=e,t[17]=i,t[18]=p,t[19]=T,t[20]=g):(i=t[17],p=t[18],T=t[19],g=t[20]);let I;t[21]!==e||t[22]!==C||t[23]!==g?(I=async()=>await C.call("MONITORING_THREAD_USAGE",{threadIds:g,...e.startDate?{startDate:e.startDate}:{},...e.endDate?{endDate:e.endDate}:{}}),t[21]=e,t[22]=C,t[23]=g,t[24]=I):I=t[24];const D=g.length>0;let _;t[25]!==p||t[26]!==I||t[27]!==D?(_={queryKey:p,queryFn:I,enabled:D,staleTime:3e4},t[25]=p,t[26]=I,t[27]=D,t[28]=_):_=t[28];const{data:E}=T(_);let M;t[29]!==E?.items?(M=new Map((E?.items??[]).map(Pt)),t[29]=E?.items,t[30]=M):M=t[30];const k=M;let $;t[31]!==S||t[32]!==N||t[33]!==u?($=()=>{N&&!u&&S()},t[31]=S,t[32]=N,t[33]=u,t[34]=$):$=t[34];const Z=St($,N??!1,u),R=bt(i),V=R.selected;let L;t[35]!==r||t[36]!==e?(L=s.jsx(yt,{automationId:r,range:e}),t[35]=r,t[36]=e,t[37]=L):L=t[37];let A;t[38]!==d||t[39]!==v||t[40]!==Z||t[41]!==i||t[42]!==R||t[43]!==o||t[44]!==k?(A=d?v?s.jsx("div",{className:"py-16 text-center text-sm text-muted-foreground",children:o("automations.automationRuns.loadingRuns")}):i.length===0?s.jsx("div",{className:"py-16",children:s.jsx(et,{title:o("automations.automationRuns.noRunsTitle"),description:o("automations.automationRuns.noRunsDescription")})}):s.jsxs(jt,{className:"w-full border-collapse",children:[s.jsx(Nt,{className:"border-b-0",children:s.jsxs(st,{className:"h-9 hover:bg-transparent border-b border-border",children:[s.jsx(G,{className:"pl-4 font-normal text-meta",children:o("automations.automationRuns.runHeader")}),s.jsx(G,{className:"w-28 px-3 font-normal text-meta",children:o("automations.automationRuns.statusHeader")}),s.jsx(G,{className:"w-24 px-3 font-normal text-meta text-right",children:o("automations.automationRuns.tokensHeader")}),s.jsx(G,{className:"w-24 px-3 font-normal text-meta text-right",children:o("automations.automationRuns.costHeader")}),s.jsx(G,{className:"w-32 px-3 pr-5 font-normal text-meta",children:o("automations.automationRuns.startedHeader")})]})}),s.jsx(Tt,{children:i.map((U,z)=>s.jsx(It,{run:U,usage:k.get(U.id),onClick:()=>R.select(U.id),lastRowRef:z===i.length-1?Z:void 0},U.id))})]}):s.jsx("div",{className:"py-16",children:s.jsx(et,{title:o("automations.automationRuns.noStartersTitle"),description:o("automations.automationRuns.noStartersDescription")})}),t[38]=d,t[39]=v,t[40]=Z,t[41]=i,t[42]=R,t[43]=o,t[44]=k,t[45]=A):A=t[45];let H;t[46]!==u||t[47]!==o?(H=u&&s.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:o("automations.automationRuns.loadingMore")}),t[46]=u,t[47]=o,t[48]=H):H=t[48];let O;t[49]!==R?(O=U=>{U||R.close()},t[49]=R,t[50]=O):O=t[50];let K;t[51]!==w||t[52]!==h||t[53]!==P||t[54]!==a||t[55]!==b||t[56]!==i||t[57]!==V||t[58]!==R.index||t[59]!==R.next||t[60]!==R.prev?(K=V&&s.jsx(wt,{thread:V,client:P,locator:a,connections:w,virtualMcps:h,members:b,nav:{index:R.index,total:i.length,onPrev:R.prev,onNext:R.next}}),t[51]=w,t[52]=h,t[53]=P,t[54]=a,t[55]=b,t[56]=i,t[57]=V,t[58]=R.index,t[59]=R.next,t[60]=R.prev,t[61]=K):K=t[61];let q;t[62]!==K?(q=s.jsx(Rt,{className:"sm:max-w-2xl flex flex-col p-0 gap-0",children:K}),t[62]=K,t[63]=q):q=t[63];let F;t[64]!==R.isOpen||t[65]!==O||t[66]!==q?(F=s.jsx(ht,{open:R.isOpen,onOpenChange:O,children:q}),t[64]=R.isOpen,t[65]=O,t[66]=q,t[67]=F):F=t[67];let B;return t[68]!==L||t[69]!==A||t[70]!==H||t[71]!==F?(B=s.jsxs("div",{className:"flex flex-col gap-5",children:[L,A,H,F]}),t[68]=L,t[69]=A,t[70]=H,t[71]=F,t[72]=B):B=t[72],B}function Pt(m){return[m.threadId,{calls:m.calls,inputTokens:m.inputTokens,outputTokens:m.outputTokens,totalTokens:m.totalTokens,costUsd:m.costUsd}]}function _t(m){return m.id}function kt(m){return m.items??[]}function Dt(m,t){const r=m,c=t;if(!((r?.items?.length??0)<W))return c.length*W}export{Vt as A};