1import{j as e,aa as te,ab as se,ac as re,ad as ae,aU as ne,o as B,u as ie,E as oe,r as o,b as f,m as w,B as G,Z as le}from"./index-OSRUV3rL.js";import{B as de}from"./badge-CrTI-_kU.js";import{T as ce,a as ue,b as $,c,d as me,e as u}from"./table-3qZ4dBul.js";import{S as E,a as T,b as R,c as D,d as h}from"./select-BOvmBYxB.js";import{A as xe}from"./AdminPageLayout-Cic8X1bp.js";import{P as ge}from"./play-Dza17SUs.js";import"./index-DdyG-fhH.js";import"./chevron-up-DQ-M4Aed.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"production-14e047243da27d5e7b44b6ceda42aa9249abf9c8"};var a=new t.Error().stack;a&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[a]="f844fca2-6bb2-41b5-8277-41fcf3c2a114",t._sentryDebugIdIdentifier="sentry-dbid-f844fca2-6bb2-41b5-8277-41fcf3c2a114")}catch{}})();const pe={success:"bg-success/10 text-success border-success/30",warning:"bg-warning/10 text-warning border-warning/30",destructive:"bg-destructive/10 text-destructive border-destructive/30",info:"bg-primary/10 text-primary border-primary/30",muted:"bg-muted text-muted-foreground border-border",accent:"bg-accent text-accent-foreground border-accent"},fe={BRIEFING_EMITTED:{nl:"Briefing aangemaakt",tone:"success"},URL_FLAGGED:{nl:"URL gemarkeerd voor refresh",tone:"warning"},STRATEGIST_RUN_TRIGGERED:{nl:"Strategist getriggerd",tone:"info"},ANOMALY_DETECTED:{nl:"Anomaly gedetecteerd",tone:"destructive"},DATA_SYNCED:{nl:"Data gesynchroniseerd",tone:"info"},NO_SIGNAL:{nl:"Geen signaal",tone:"muted"},TOOL_ERRORED:{nl:"Tool-fout",tone:"destructive"}},he={RUNNING:"Bezig",COMPLETED:"Voltooid",FAILED:"Mislukt",SKIPPED:"Overgeslagen"},je={RUNNING:"info",COMPLETED:"success",FAILED:"destructive",SKIPPED:"muted"};function be(t){return t===null?"â":t<1e3?`${t} ms`:`${(t/1e3).toFixed(1)}s`}function ye(t){return new Date(t).toLocaleString("nl-NL",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})}function V(t){return new Date(t).toLocaleTimeString("nl-NL",{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function Ne(t){if(!t||typeof t!="object")return{};const a=t;return{signal:typeof a.signal=="string"?a.signal:void 0,summary:typeof a.summary=="string"?a.summary:void 0,reasoning:typeof a.reasoning=="string"?a.reasoning:void 0,decisionsCount:typeof a.decisionsCount=="number"?a.decisionsCount:void 0}}function A({tone:t,size:a="sm",children:r,title:i}){return e.jsx("span",{title:i,className:B("inline-flex items-center rounded-full border font-medium",a==="sm"?"px-2 py-0.5 text-xs":"px-2 py-0.5 text-[11px]",pe[t]),children:r})}function ve({status:t}){return e.jsx(A,{tone:je[t],children:he[t]})}function Se({run:t}){const a=[{label:"Duur",value:be(t.durationMs)},{label:"Beslissingen",value:String(t.decisionsCount)}];return t.costUsd!==null&&a.push({label:"Kosten",value:`$${Number(t.costUsd).toFixed(4)}`}),t.turnsUsed!==null&&a.push({label:"Agent-turns",value:String(t.turnsUsed)}),t.modelUsed&&a.push({label:"Model",value:t.modelUsed.replace("claude-","").replace(/-\d{8}$/,"")}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:a.map(r=>e.jsxs("div",{className:"rounded-lg border border-border/60 bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:r.label}),e.jsx("div",{className:"text-sm font-medium text-foreground mt-0.5 truncate",title:r.value,children:r.value})]},r.label))})}function we({run:t}){const a=Ne(t.outputSummary);if(t.status==="FAILED"&&t.errorMessage)return e.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-destructive font-semibold mb-1",children:"Mislukt"}),e.jsx("p",{className:"text-sm text-foreground leading-relaxed",children:t.errorMessage}),t.errorStack&&e.jsxs("details",{className:"mt-2",children:[e.jsx("summary",{className:"cursor-pointer text-xs text-destructive hover:opacity-80",children:"Stacktrace"}
1),e.jsx("pre",{className:"mt-1 text-[11px] text-foreground/80 whitespace-pre-wrap break-all overflow-auto max-h-40",children:t.errorStack})]})]});if(!a.summary&&!a.reasoning)return e.jsx(j,{value:t.outputSummary});const r={rest:"Rust",emitted:"Acties uitgevoerd",detected:"Signaal gedetecteerd"};return e.jsxs("div",{className:"rounded-lg border border-border/60 bg-card p-4 space-y-3",children:[a.signal&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Resultaat:"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:r[a.signal]??a.signal})]}),a.summary&&e.jsx("p",{className:"text-base text-foreground leading-snug",children:a.summary}),a.reasoning&&e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"cursor-pointer text-xs text-muted-foreground hover:text-foreground select-none flex items-center gap-1",children:[e.jsx("span",{className:"group-open:hidden",children:"Toon redenering"}),e.jsx("span",{className:"hidden group-open:inline",children:"Verberg redenering"})]}),e.jsx("p",{className:"mt-2 text-sm text-foreground/80 leading-relaxed whitespace-pre-line",children:a.reasoning})]})]})}function Ee({action:t}){const a=fe[t.type]??{nl:t.type,tone:"muted"},r=t.payload,i=[];if(t.type==="BRIEFING_EMITTED"&&r)typeof r.type=="string"&&i.push({label:"Type",value:r.type}),typeof r.clusterId=="string"&&i.push({label:"Cluster",value:r.clusterId}),typeof r.primaryKeyword=="string"&&i.push({label:"Keyword",value:r.primaryKeyword});else if(t.type==="URL_FLAGGED"&&r){if(typeof r.url=="string"&&i.push({label:"URL",value:r.url}),r.gscMetrics&&typeof r.gscMetrics=="object"){const n=r.gscMetrics;typeof n.position=="number"&&i.push({label:"Positie",value:n.position.toFixed(1)}),typeof n.impressions=="number"&&i.push({label:"Impr.",value:String(n.impressions)})}}else t.type==="ANOMALY_DETECTED"&&r?(typeof r.pctChange=="number"&&i.push({label:"Verandering",value:`${r.pctChange.toFixed(1)}%`}),typeof r.significance=="string"&&i.push({label:"Significantie",value:r.significance})):t.type==="STRATEGIST_RUN_TRIGGERED"&&r?typeof r.reason=="string"&&i.push({label:"Reden",value:r.reason}):t.type==="DATA_SYNCED"&&r&&typeof r.rowsImported=="number"&&i.push({label:"Rijen",value:String(r.rowsImported)});return e.jsxs("div",{className:"rounded-lg border border-border/60 bg-card px-4 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(A,{tone:a.tone,children:a.nl}),t.shadowed&&e.jsx(A,{tone:"accent",size:"xs",title:"Simulatie - geen echte actie uitgevoerd",children:"simulatie"})]}),e.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:V(t.createdAt)})]}),e.jsx("p",{className:"text-sm text-foreground leading-snug",children:t.label}),i.length>0&&e.jsx("dl",{className:"mt-2 grid grid-cols-2 gap-x-4 gap-y-1 text-xs",children:i.map(n=>e.jsxs(ne.Fragment,{children:[e.jsx("dt",{className:"text-muted-foreground",children:n.label}),e.jsx("dd",{className:"text-foreground/90 truncate",title:n.value,children:n.value})]},n.label))}),r&&Object.keys(r).length>0&&e.jsxs("details",{className:"mt-2",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground/70 hover:text-muted-foreground select-none",children:"Ruwe data"}),e.jsx(j,{value:t.payload,className:"mt-1"})]})]})}function j({value:t,className:a=""}){return e.jsx("pre",{className:B("bg-muted/50 border border-border/60 rounded p-2 text-[11px] leading-snug overflow-auto max-h-48 whitespace-pre-wrap break-all text-foreground/80",a),children:JSON.stringify(t,null,2)})}function Te({run:t,open:a,onClose:r}){if(!t)return null;const i=t.actions??[];return e.jsx(te,{open:a,onOpenChange:n=>!n&&r(),children:e.jsxs(se,{className:"max-w-2xl max-h-[90vh] overflow-y-auto p-0",children:[e.jsxs(re,{className:"px-6 pt-6 pb-4 border-b border-border/60",children:[e.jsxs(ae,{className:"flex items-center gap-3 text-xl",children:[e.jsx("span",{className:"text-foreground",children:t.rout
1ineName}),e.jsx(ve,{status:t.status})]}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[ye(t.startedAt),t.completedAt&&` â ${V(t.completedAt)}`]})]}),e.jsxs("div",{className:"px-6 py-5 space-y-6",children:[e.jsx(Se,{run:t}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs uppercase tracking-wide text-muted-foreground font-semibold",children:"Wat de routine deed"}),e.jsx(we,{run:t})]}),i.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-xs uppercase tracking-wide text-muted-foreground font-semibold",children:["Acties (",i.length,")"]}),e.jsx("div",{className:"space-y-2",children:i.map(n=>e.jsx(Ee,{action:n},n.id))})]}),e.jsxs("details",{className:"rounded-lg border border-border/60",children:[e.jsx("summary",{className:"cursor-pointer px-4 py-2 text-xs text-muted-foreground hover:text-foreground select-none",children:"Technische details"}),e.jsxs("div",{className:"px-4 pb-4 pt-2 space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground mb-1",children:"Run ID"}),e.jsx("code",{className:"text-[11px] text-foreground font-mono",children:t.id})]}),t.templateVersion!==null&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground mb-1",children:"Template versie"}),e.jsxs("code",{className:"text-[11px] text-foreground font-mono",children:["v",t.templateVersion]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground mb-1",children:"Input"}),e.jsx(j,{value:t.input})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground mb-1",children:"Output Summary (raw)"}),e.jsx(j,{value:t.outputSummary})]})]})]})]})]})})}const I=["Foundation","ContentRefresh","PerformanceSync","AnomalyDetection","OpportunityScan"],Re={RUNNING:"default",COMPLETED:"success",FAILED:"destructive",SKIPPED:"secondary"};function Ue(){const[t,a]=ie(),r=t.get("projectId")??"",{toast:i}=oe(),[n,_]=o.useState(r),[b,K]=o.useState([]),[L,k]=o.useState(!1),[C,P]=o.useState([]),[y,U]=o.useState(!1),[M,O]=o.useState(!1),[d,Y]=o.useState("__all__"),[x,z]=o.useState(I[0]),[H,N]=o.useState(null),[J,v]=o.useState(!1),[W,F]=o.useState(!1);o.useEffect(()=>{let s=!1;async function l(){k(!0);try{const p=await f.get("/admin/projects");if(s)return;const m=p.data.data??[];m.sort((X,ee)=>X.domain.localeCompare(ee.domain)),K(m),!n&&m.length>0&&(_(m[0].id),a({projectId:m[0].id},{replace:!0}))}catch(p){i({title:"Error loading projects",description:p instanceof Error?p.message:"Unknown error",variant:"destructive"})}finally{s||k(!1)}}return l(),()=>{s=!0}},[]);const Z=s=>{_(s),a({projectId:s},{replace:!0}),P([])},g=o.useCallback(async()=>{if(n){U(!0);try{const s={limit:"50"};d!=="__all__"&&(s.routineName=d);const l=await f.get(`/admin/projects/${n}/routine-runs`,{params:s});P(l.data.items)}catch(s){i({title:"Error loading routine runs",description:s instanceof Error?s.message:"Unknown error",variant:"destructive"})}finally{U(!1)}}},[n,d,i]);o.useEffect(()=>{g()},[g]);const q=async s=>{if(n){F(!0),v(!0),N(null);try{const l=await f.get(`/admin/projects/${n}/routine-runs/${s}`);N(l.data)}catch(l){i({title:"Failed to load routine run detail",description:l instanceof Error?l.message:"Unknown error",variant:"destructive"}),v(!1)}finally{F(!1)}}},Q=async()=>{if(!(!n||!x)){O(!0);try{const s=await f.post(`/admin/projects/${n}/routine-runs`,{routineName:x});i({title:"Routine run triggered",description:`${x} · Job ID: ${s.data.jobId}`}),setTimeout(()=>void g(),2e3)}catch(s){i({title:"Error triggering routine run",description:s instanceof Error?s.message:"Unknown error",variant:"destructive"})}finally{O(!1)}}},S=b.find(s=>s.id===n);return e.jsxs(xe,{title:"Routine Runs",description:S?`${S.name} (${S.domain})`:"Pick a project to inspect its routine-run history.",action:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(G,{variant:"outline",size:"sm",onClick:()=>void g(),disabled:y||!n,children:[e.jsx(le,{className:`h-4 w-4 mr-1 ${y?"animate-spin":""}`}),"Refresh"]}),e.jsxs(E,{value:x,onValueChange:z,children:[e.jsx(T,{className:"w-44 h-9 text-sm",disabled:!n,children:e.jsx(R,{})}),e.jsx(D,{children:I.map(s=>e.jsx(h,{value:s,children:s},s))})]}),e.jsxs(G,{size:"sm",onClick:()=>void Q(),disabled:M||!n,children:[M?e.jsx(w,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(ge,{className:"h-4 w-4 mr-1"}),"Run Routine"]})]}),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4","data-testid":"project-picker",children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Project:"}),e.jsxs(E,{value:n,onValueChange:Z,children:[e.jsx(T,{className:"w-80 h-9 text-sm","data-testid":"project-picker-trigger",children:e.jsx(R,{placeholder:L?"Loadingâ¦":"Pick a project"})}),e.jsx(D,{children:b.map(s=>e.jsxs(h,{value:s.id,children:[s.domain," ",e.jsx("span",{className:"text-xs text-gray-500 ml-2",children:s.name})]},s.id))})]}),b.length===0&&!L&&e.jsx("span",{className:"text-xs text-gray-500 italic",children:"No active projects."})]}),!n&&e.jsx("div",{className:"text-sm text-gray-500 bg-gray-50 border border-gray-200 rounded p-4",children:"Pick a project from the dropdown above to see its routine-run history."}),n&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Filter by routine:"}),e.jsxs(E,{value:d,onValueChange:Y,children:[e.jsx(T,{className:"w-48 h-8 text-sm",children:e.jsx(R,{})}),e.jsxs(D,{children:[e.jsx(h,{value:"__all__",children:"All routines"}),I.map(s=>e.jsx(h,{value:s,children:s},s))]})]})]}),n&&(y?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(w,{className:"h-6 w-6 animate-spin text-gray-400"})}):C.length===0?e.jsxs("div",{className:"text-sm text-gray-500 bg-gray-50 border border-gray-200 rounded p-4",children:["No routine runs found",d!=="__all__"?` for routine "${d}"`:"","."]}):e.jsx("div",{className:"rounded-md border border-gray-200 overflow-hidden",children:e.jsxs(ce,{children:[e.jsx(ue,{children:e.jsxs($,{children:[e.jsx(c,{children:"Routine Name"}),e.jsx(c,{className:"w-28",children:"Status"}),e.jsx(c,{className:"w-24",children:"Decisions"}),e.jsx(c,{className:"w-24",children:"Duration"}),e.jsx(c,{children:"Error"}),e.jsx(c,{className:"w-36",children:"Started At"})]})}),e.jsx(me,{children:C.map(s=>e.jsxs($,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>void q(s.id),children:[e.jsx(u,{className:"font-mono text-sm",children:s.routineName}),e.jsx(u,{children:e.jsx(de,{variant:Re[s.status],className:"text-xs",children:s.status})}),e.jsx(u,{className:"text-sm text-gray-600",children:s.decisionsCount}),e.jsx(u,{className:"text-sm text-gray-500",children:s.durationMs?`${s.durationMs}ms`:"â"}),e.jsx(u,{className:"text-sm text-red-600 max-w-xs truncate",children:s.errorMessage??"â"}),e.jsx(u,{className:"text-sm text-gray-500",children:new Date(s.startedAt).toLocaleStr
1ing("nl-NL",{day:"2-digit",month:"2-digit",year:"2-digit",hour:"2-digit",minute:"2-digit"})})]},s.id))})]})})),W&&e.jsx("div",{className:"fixed inset-0 bg-black/20 flex items-center justify-center z-50",children:e.jsx(w,{className:"h-8 w-8 animate-spin text-white"})}),e.jsx(Te,{run:H,open:J,onClose:()=>{v(!1),N(null)}})]})}export{Ue as AdminRoutineRunsPage}; 2//# sourceMappingURL=AdminRoutineRunsPage-DX02T2r_.js.map
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.