1import{r as h,p as T,j as e,bA as $,d as j,ab as D,g as i,h as d,E as G,b5 as S,a9 as F,w as R,aj as B,ak as q,al as p,an as N,bq as _,B as g,br as b,s as v,bs as k}from"./index-hWVpbWs7.js";const w=c=>{const o=c.toLowerCase();return["completed","success","sent","ok"].includes(o)?"bg-emerald-500/10 text-emerald-600 border-emerald-500/30":["failed","error"].includes(o)?"bg-red-500/10 text-red-600 border-red-500/30":["running","in_progress","pending"].includes(o)?"bg-amber-500/10 text-amber-600 border-amber-500/30":"bg-muted text-muted-foreground border-border"};function I(){const[c,o]=h.useState("all"),{data:t,isLoading:x,refetch:C,isFetching:f}=T({queryKey:["agents-admin"],refetchInterval:3e4,queryFn:async()=>{const s=new Date(Date.now()-6048e5).toISOString(),[r,n]=await Promise.all([v.from("admin_agent_runs").select("id,agent,trigger,status,model,cost_credits,duration_ms,input_tokens,output_tokens,error_message,started_at,finished_at,related_task").gte("started_at",s).order("started_at",{ascending:!1}).limit(200),v.from("agent_runs").select("id,status,outcome_reason,channel,brand_label,confidence,risk_level,steps_taken,model,duration_ms,error,created_at,completed_at").gte("created_at",s).order("created_at",{ascending:!1}).limit(200)]);return{admin:r.data??[],comm:n.data??[]}}}),m=h.useMemo(()=>{const s=[...((t==null?void 0:t.admin)??[]).map(a=>({status:a.status,err:!!a.error_message,cost:Number(a.cost_credits??0),dur:a.duration_ms??0})),...((t==null?void 0:t.comm)??[]).map(a=>({status:a.status,err:!!a.error,cost:0,dur:a.duration_ms??0}))],r=s.filter(a=>{var l;return a.err||["failed","error"].includes(((l=a.status)==null?void 0:l.toLowerCase())??"")}).length,n=s.filter(a=>{var l;return["running","in_progress","pending"].includes(((l=a.status)==null?void 0:l.toLowerCase())??"")}).length,y=s.filter(a=>{var l;return["completed","success","sent","ok"].includes(((l=a.status)==null?void 0:l.toLowerCase())??"")}).length,A=s.reduce((a,l)=>a+l.cost,0),L=s.length?Math.round(s.reduce((a,l)=>a+l.dur,0)/s.length):0;return{total:s.length,failed:r,running:n,ok:y,totalCost:A,avgDur:L}},[t]),u=s=>c==="all"?s:c==="failed"?s.filter(r=>{var n;return["failed","error"].includes(((n=r.status)==null?void 0:n.toLowerCase())??"")}):c==="running"?s.filter(r=>{var n;return["running","in_progress","pending"].includes(((n=r.status)==null?void 0:n.toLowerCase())??"")}):c==="ok"?s.filter(r=>{var n;return["completed","success","sent","ok"].includes(((n=r.status)==null?void 0:n.toLowerCase())??"")}):s;return e.jsxs("div",{className:"container mx-auto p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center gap-2",children:[e.jsx($,{className:"h-8 w-8 text-primary"})," Agents"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Alle agent-runs van de afgelopen 7 dagen â admin-agents en communicatie-agents."})]}),e.jsxs(j,{variant:"outline",size:"sm",onClick:()=>C(),disabled:f,children:[e.jsx(D,{className:`h-4 w-4 mr-2 ${f?"animate-spin":""}`})," Ververs"]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:[e.jsx(i,{children:e.jsxs(d,{className:"p-4",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Totaal runs"}),e.jsx("div",{className:"text-2xl font-bold",children:m.total})]})}),e.jsx(i,{children:e.jsxs(d,{className:"p-4",children:[e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(G,{className:"h-3 w-3 text-emerald-600"})," Geslaagd"]}),e.jsx("div",{className:"text-2xl font-bold text-emerald-600",children:m.ok})]})}),e.jsx(i,{children:e.jsxs(d,{className:"p-4",children:[e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(S,{className:"h-3 w-3 text-amber-600"})," Loopt"]}),e.jsx("div",{className:"text-2xl font-bold text-amber-600",children:m.running})]})}),e.jsx(i,{children:e.jsxs(d,{className:"p-4",children:[e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(F,{className:"h-3 w-3 text-red-600"})," Gefaald"]}),e.jsx("div",{className:"text-2xl font-bold text-red-600",children:m.failed})]})}),e.jsx(i,{children:e.jsxs(d,{className:"p-4",children:[e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(R,{className:"h-3 w-3"})," Gem. duur"]}),e.jsxs("div",{className:"text-2xl font-bold",children:[m.avgDur,"ms"]})]})})]}),e.jsx("div",{className:"flex gap-2",children:["all","failed","running","ok"].map(s=>e.jsx(j,{size:"sm",variant:c===s?"default":"outline",onClick:()=>o(s),children:s==="all"?"Alles":s==="failed"?"Gefaald":s==="running"?"Actief":"Geslaagd"},s))}),e.jsxs(B,{defaultValue:"admin",children:[e.jsxs(q,{children:[e.jsxs(p,{value:"admin",children:["Admin-agents (",(t==null?void 0:t.admin.length)??0,")"]}),e.jsxs(p,{value:"comm",children:["Communicatie-agents (",(t==null?void 0:t.comm.length)??0,")"]})]}),e.jsxs(N,{value:"admin",className:"space-y-2",children:[x&&e.jsx(_,{className:"h-40 w-full"}),!x&&u((t==null?void 0:t.admin)??[]).length===0&&e.jsx(i,{children:e.jsx(d,{className:"p-8 text-center text-muted-foreground",children:"Geen runs gevonden."})}),u((t==null?void 0:t.admin)??[]).map(s=>e.jsx(i,{children:e.jsx(d,{className:"p-4 flex items-start justify-between gap-4",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-semibold",children:s.agent}),e.jsx(g,{variant:"outline",className:w(s.status),children:s.status}),s.trigger&&e.jsx(g,{variant:"secondary",className:"text-xs",children:s.trigger}),s.model&&e.jsx("span",{className:"text-xs text-muted-foreground",children:s.model})]}),s.error_message&&e.jsx("div",{className:"text-xs text-red-600 mt-1 line-clamp-2",children:s.error_message}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[b(new Date(s.started_at),{addSuffix:!0,locale:k}),s.duration_ms!=null&&` · ${s.duration_ms}ms`,s.cost_credits!=null&&Number(s.cost_credits)>0&&` · ${Number(s.cost_credits).toFixed(4)} credits`,(s.input_tokens||s.output_tokens)&&` · ${s.input_tokens??0}/${s.output_tokens??0} tokens`]})]})})},s.id))]}),e.jsxs(N,{value:"comm",className:"space-y-2",children:[x&&e.jsx(_,{className:"h-40 w-full"}),!x&&u((t==null?void 0:t.comm)??[]).length===0&&e.jsx(i,{children:e.jsx(d,{className:"p-8 text-center text-muted-foreground",children:"Geen runs gevonden."})}),u((t==null?void 0:t.comm)??[]).map(s=>e.jsx(i,{children:e.jsx(d,{className:"p-4 flex items-start justify-between gap-4",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-semibold",children:s.channel??"agent"}),e.jsx(g,{variant:"outline",className:w(s.status),children:s.status}),s.risk_level&&e.jsxs(g,{variant:"secondary",className:"text-xs",children:["risk: ",s.risk_level]}),s.brand_label&&e.jsx("span",{className:"text-xs text-muted-foreground",children:s.brand_label}),s.confidence!=null&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["conf: ",Number(s.confidence).toFixed(2)]})]}),s.outcome_reason&&e.jsx("div",{className:"text-xs text-muted-foreground mt-1",children:s.outcome_reason}),s.error&&e.jsx("div",{className:"text-xs text-red-600 mt-1 line-clamp-2",children:s.error}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[b(new Date(s.created_at),{addSuffix:!0,locale:k}),s.duration_ms!=null&&` · ${s.duration_ms}ms`,s.steps_taken!=null&&` · ${s.steps_taken} steps`,s.model&&` · ${s.model}`]})]})})},s.id))]})]})]})}export{I as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.