1import{j as e,r as j}from"./react-vendor-BKgfKFZH.js";import{b as re,c as ae}from"./adminControls-BcRTrq2z.js";import{A as le}from"./adminLayout-BbJWN0b2.js";import{u as ne,g as ie}from"./graphql-C1dYKLT3.js";import{l as oe}from"./lindy-avatar-BCVLbp0J.js";import{k as ce,x as M}from"./entry-C8wUDEw9.js";import"./icons-BfNt_9T9.js";import"./graphql-WBhJzdnw.js";import"./makePostHogHeaders-DBJS6Pqp.js";import"./pacedPoll-Ci7sm2Uo.js";const J=[{hours:24,label:"24h"},{hours:96,label:"4d",unavailableReason:"Too slow to summarize from retained attempts. Returns with rollups."}],q=[{label:"Now",description:"Run outcomes",durationMs:18e3},{label:"Trend",description:"Period comparison",durationMs:24e3},{label:"Timeline",description:"Success, duration, failures",durationMs:24e3},{label:"Focus",description:"Failures by type",durationMs:2e4},{label:"Examples",description:"Task failures and flags",durationMs:24e3}],de=q.map(t=>t.durationMs);function ue({data:t}){const a=Math.max(1,...t.timeBuckets.map(s=>s.attempts));return e.jsxs("div",{className:"rr-activity",children:[e.jsxs("div",{children:[e.jsx("span",{className:"rr-eyebrow",children:"Run volume by start time"}),e.jsxs("p",{children:["Each column is ",t.bucketSizeHours,"h. Height is run volume."]})]}),e.jsx("div",{className:"rr-activity-bars",role:"img","aria-label":"Routine activity by start time; column height shows attempts, color shows current outcomes",children:t.timeBuckets.map((s,o)=>{const x=Math.max(0,s.attempts-s.completed-s.failed-s.inProgress-s.noTaskProduced-s.skipped),i=[{outcome:"completed",value:s.completed,color:"var(--rr-success)"},{outcome:"in_progress",value:s.inProgress,color:"var(--rr-running)"},{outcome:"failed",value:s.failed,color:"var(--rr-failure)"},{outcome:"no_task",value:s.noTaskProduced,color:"var(--rr-attention)"},{outcome:"skipped",value:s.skipped,color:"var(--rr-neutral)"},{outcome:"other",value:x,color:"var(--rr-unknown)"}];return e.jsx("div",{className:"rr-activity-column",style:{"--rr-order":o},title:`${new Date(s.bucketStart).toLocaleString()}: ${s.attempts} attempts, ${s.completed} completed, ${s.failed} failed`,children:e.jsx("div",{style:{height:`${s.attempts/a*100}%`},children:i.map(n=>e.jsx("span",{style:{flex:n.value,background:n.color}},n.outcome))})},s.bucketStart)})}),e.jsxs("div",{className:"rr-activity-legend",children:[e.jsx("span",{children:"Earlier"}),e.jsx("span",{children:"Completed · active · failed · no task · skipped"}),e.jsx("span",{children:"Latest"})]})]})}function V(t){const a=t*100;return`${a.toFixed(a<10?2:1)}%`}function pe(t){const a=new Date(t);return Number.isNaN(a.getTime())?"":a.toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function O(t){return t==null||!Number.isFinite(t)?"â":t<6e4?`${Math.max(1,Math.round(t/1e3))}s`:t<36e5?`${Math.round(t/6e4)}m`:`${(t/36e5).toFixed(t<36e6?1:0)}h`}function Z(t){return t.replace(/([a-z\d])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replaceAll("_"," ").replace(/\b\w/g,a=>a.toUpperCase())}function me(t){return t==="team"?"Team":t==="personal"?"Personal":"Unknown"}const S=t=>t.toLocaleString(),_=t=>t.replace(/([a-z\d])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replaceAll("_"," "),E=t=>t===null?"â":t<6e4?`${Math.round(t/1e3)}s`:`${Math.round(t/6e4)}m`,X=t=>({"--rr-tint":t});function ee(t,a){const s=j.useRef(null),[o,x]=j.useState({width:t,height:a});return j.useEffect(()=>{const i=s.current;if(!i||typeof ResizeObserver>"u")return;const n=new ResizeObserver(([m])=>{!m||m.contentRect.width<=0||m.contentRect.height<=0||x({width:m.contentRect.width,height:m.contentRect.height})});return n.observe(i),()=>n.disconnect()},[]),{ref:s,...o}}function xe({data:t}){const a=j.useId(),{ref:s,width:o,height:x}=ee(760,360),i=70,n=o-52,m=40,l=x-64,d=n-i,f=l-m,[h,g]=he(),c=[...t.triggerTypes].sort((r,b)=>b.failed-r.failed||b.stuck-r.stuck||b.attempts-r.attempts),v=c.filter(r=>r.averageCompletedDurationMs!==null&&r.completed+r.failed>0),C=Math.max(6e4,...v.map(r=>r.averageCompletedDurationMs??0)),p=Math.max(1,...v.map(r=>r.attempts)),$=Math.max(.05,Math.ceil(Math.max(0,...v.map(r=>r.failed/(r.completed+r.failed)))*20)/20),k=c.find(r=>`${r.triggerType}-${r.scope}`===h)??c[0],w=[{key:"trigger_processing",name:"Trigger processing",observable:!1},{key:"task_creation",name:"Task creation",observable:!1},{key:"task_execution",name:"Task execution",observable:!0}
1,{key:"awaiting_approval",name:"Awaiting approval",observable:!0}].map(r=>({...r,...t.stuckStages.find(b=>b.stage===r.key)})),y=Math.max(1,...w.map(r=>r.count??0));return e.jsxs("div",{className:"rr-pressure",children:[e.jsxs("div",{className:"rr-scene-heading",children:[e.jsxs("div",{children:[e.jsx("span",{className:"rr-eyebrow",children:"04 / Failure breakdown"}),e.jsx("h2",{children:"Failures and duration by routine type"})]}),e.jsxs("p",{children:["Failure rate vs average completion time",e.jsx("br",{}),"Stuck runs grouped by stage below"]})]}),e.jsxs("div",{className:"rr-pressure-layout",children:[e.jsxs("div",{className:"rr-risk-chart",children:[e.jsxs("div",{className:"rr-chart-caption",children:[e.jsx("strong",{children:"Completion time vs failure rate"}),e.jsx("span",{children:"Circle area = attempts · select a routine type"})]}),e.jsx("div",{className:"rr-risk-plot",ref:s,children:e.jsxs("svg",{viewBox:`0 0 ${o} ${x}`,role:"img","aria-labelledby":a,children:[e.jsx("title",{id:a,children:"Routine types by average completion time and failed share of completed or failed tasks. Circle area shows attempts."}),e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:`${a}-risk`,x1:"0",y1:"1",x2:"1",y2:"0",children:[e.jsx("stop",{stopColor:"var(--rr-success)",stopOpacity:".03"}),e.jsx("stop",{offset:"1",stopColor:"var(--rr-failure)",stopOpacity:".12"})]}),["failure","success"].map(r=>e.jsxs("radialGradient",{id:`${a}-marble-${r}`,cx:"30%",cy:"25%",r:"75%",children:[e.jsx("stop",{stopColor:"var(--rr-card)"}),e.jsx("stop",{offset:".38",stopColor:`var(--rr-${r})`,stopOpacity:".32"}),e.jsx("stop",{offset:"1",stopColor:`var(--rr-${r})`,stopOpacity:".85"})]},r))]}),e.jsx("rect",{x:i,y:m,width:d,height:f,rx:"18",fill:`url(#${a}-risk)`}),[0,.25,.5,.75,1].map(r=>e.jsxs("g",{children:[e.jsx("line",{x1:i,x2:n,y1:l-r*f,y2:l-r*f,stroke:"var(--rr-muted)",strokeOpacity:".13",strokeDasharray:"2 6"}),e.jsxs("text",{x:i-14,y:l+5-r*f,fill:"var(--rr-muted)",fontSize:"14",textAnchor:"end",children:[Number((r*$*100).toFixed(1)),"%"]})]},r)),[0,.25,.5,.75,1].map(r=>e.jsxs("g",{children:[e.jsx("line",{x1:i+r*d,x2:i+r*d,y1:m,y2:l,stroke:"var(--rr-muted)",strokeOpacity:".1",strokeDasharray:"2 6"}),e.jsx("text",{x:i+r*d,y:l+28,fill:"var(--rr-muted)",fontSize:"14",textAnchor:"middle",children:E(r*C)})]},r)),e.jsx("text",{x:i,y:"25",fill:"var(--rr-failure)",fontSize:"14",children:"Failed / (completed + failed)"}),e.jsx("text",{x:n,y:x-6,fill:"var(--rr-muted)",fontSize:"14",textAnchor:"end",children:"Average completed duration â"}),[...v].sort((r,b)=>b.attempts-r.attempts).map((r,b)=>{const u=i+(r.averageCompletedDurationMs??0)/C*d,N=r.failed/(r.completed+r.failed),R=l-N/$*f,U=35*Math.sqrt(r.attempts/p),A=r.failed?"var(--rr-failure)":"var(--rr-success)",F=r===k;return e.jsxs("g",{className:"rr-risk-point",style:{"--rr-order":Math.min(b,12)},children:[e.jsxs("title",{children:[_(r.triggerType),", ",r.scope,":"," ",Math.round(N*100),"% failed,"," ",E(r.averageCompletedDurationMs)," average,"," ",r.attempts," attempts"]}),F?e.jsxs(e.Fragment,{children:[e.jsx("line",{x1:i,x2:u,y1:R,y2:R,stroke:A,strokeOpacity:".45",strokeDasharray:"4 5"}),e.jsx("line",{x1:u,x2:u,y1:R,y2:l,stroke:A,strokeOpacity:".45",strokeDasharray:"4 5"}),e.jsx("circle",{cx:u,cy:R,r:U+8,fill:"none",stroke:A,strokeOpacity:".4"})]}):null,e.jsx("circle",{cx:u,cy:R,r:U,fill:`url(#${a}-marble-${r.failed?"failure":"success"})`,fillOpacity:F?1:.75,stroke:A,strokeOpacity:F?1:.6}),e.jsx("circle",{cx:u,cy:R,r:"2.5",fill:A})]},`${r.triggerType}-${r.scope}`)}),v.length===0?e.jsx("text",{x:(i+n)/2,y:(m+l)/2,fill:"var(--rr-muted)",textAnchor:"middle",fontSize:"18",children:"No comparable completed durations yet"}):null]})}),e.jsxs("p",{className:"rr-plot-caption",children:[c.length-v.length," types without comparable durations are unplotted. Rates exclude unfinished tasks."]})]}),e.jsxs("div",{className:"rr-spotlight",children:[e.jsx("span",{className:"rr-eyebrow",children:"Selected routine type"}),k?e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:_(k.triggerType)}),e.jsxs("p",{children:[k.scope," routines"]}),e.jsxs("div",{className:"rr-spotlight-value","data-tone":k.failed>0?"failure":k.completed>0?"success":"neutral",children:[e.jsx("strong",{children:S(k.failed)}
1),e.jsxs("span",{children:["failed tasks",e.jsx("br",{}),"of ",S(k.completed+k.failed)," finalized"]})]}),e.jsxs("dl",{children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Attempts"}),e.jsx("dd",{children:S(k.attempts)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Average duration"}),e.jsx("dd",{children:E(k.averageCompletedDurationMs)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Stuck / approval"}),e.jsx("dd",{children:S(k.stuck)})]})]})]}):e.jsx("p",{children:"No routine types in this window."}),e.jsx("div",{className:"rr-type-picker","aria-label":"Select a routine type",children:c.map(r=>{const b=`${r.triggerType}-${r.scope}`;return e.jsxs("button",{type:"button","data-routine-key":b,onClick:g,"aria-pressed":r===k,children:[e.jsxs("span",{children:[_(r.triggerType)," ",e.jsx("small",{children:r.scope})]}),e.jsx("b",{"data-tone":r.failed>0?"failure":"neutral",children:S(r.failed)})]},b)})})]})]}),e.jsxs("div",{className:"rr-stage-heading",children:[e.jsx("strong",{children:"Stuck runs and approval waits by stage"}),e.jsxs("span",{children:["Inactivity threshold: ",t.stuckAfterMinutes,"m · approval is a separate wait state"]})]}),e.jsx("div",{className:"rr-stage-grid",children:w.map((r,b)=>e.jsxs("div",{className:"rr-stage",style:{...X(r.observable?"var(--rr-attention)":"var(--rr-neutral)"),"--rr-order":b},children:[e.jsxs("div",{children:[e.jsx("span",{children:r.name}),e.jsx("strong",{children:r.observable?S(r.count??0):"â"})]}),r.observable?e.jsx("div",{className:"rr-stage-track",children:e.jsx("span",{style:{width:`${(r.count??0)/y*100}%`}})}):null,e.jsx("small",{children:r.observable?r.count?`${E(r.oldestAgeMs??0)} since oldest progress`:"No runs waiting here":"Not recorded · outcome unknown"})]},r.key))})]})}function he(){const[t,a]=j.useState(null),s=j.useCallback(o=>{a(o.currentTarget.dataset.routineKey??null)},[]);return[t,s]}function T(t,a,s){if(s<=0)return"";const o=l=>{const d=l*Math.PI/180;return[t*Math.cos(d),t*Math.sin(d)]},[x,i]=o(a),[n,m]=o(a+s);return`M ${x} ${i} A ${t} ${t} 0 ${s>180?1:0} 1 ${n} ${m}`}const fe="M 0 -66 C -39 -84 -78 -142 -49 -177 C -23 -209 23 -209 49 -177 C 78 -142 39 -84 0 -66 Z";function ge({data:t}){const a=j.useId(),{totals:s}=t,o=s.attempts,x=s.completed+s.failed,i=x>0?s.completed/x:null,n=[{label:"Completed tasks",short:"Completed",value:s.completed,tone:"success"},{label:"In-progress runs",short:"In progress",value:s.inProgress,tone:"running"},{label:"Failed tasks",short:"Failed",value:s.failed,tone:"failure"},{label:"No-task outcomes",short:"No task",value:s.noTaskProduced,tone:"attention"},{label:"Skipped runs",short:"Skipped",value:s.skipped,tone:"neutral"},{label:"Other / unresolved",short:"Other",value:Math.max(0,o-s.completed-s.inProgress-s.failed-s.noTaskProduced-s.skipped),tone:"unknown"}],m=[{label:"Observed attempts",value:o},{label:"Qualified attempts",value:s.qualified},{label:"Tasks created",value:s.tasksCreated}];return e.jsxs("div",{className:"rr-currents",children:[e.jsxs("div",{className:"rr-scene-heading",children:[e.jsxs("div",{children:[e.jsx("span",{className:"rr-eyebrow",children:"01 / Run outcomes"}),e.jsxs("h2",{children:["Routine runs · last ",t.windowHours,"h"]})]}),e.jsxs("p",{children:[S(s.failed)," failed · ",S(s.inProgress)," in progress",e.jsx("br",{}),"Counts from retained attempts"]})]}),e.jsxs("div",{className:"rr-bloom-layout",children:[e.jsx("div",{className:"rr-bloom",children:e.jsxs("svg",{className:"rr-flower",viewBox:"-242 -242 484 484",role:"img","aria-label":`Routine outcome breakdown. ${n.map(l=>`${l.label}: ${l.value}`).join(". ")}. Each outer arc shows that outcome's share of all attempts on its own zero to 100 percent track. Petal size is decorative.`,children:[e.jsx("defs",{children:n.map(l=>e.jsxs("linearGradient",{id:`${a}-${l.tone}`,x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{stopColor:`var(--rr-${l.tone})`,stopOpacity:".08"}),e.jsx("stop",{offset:".65",stopColor:`var(--rr-${l.tone})`,stopOpacity:".26"}),e.jsx("stop",{offset:"1",stopColor:`var(--rr-${l.tone})`,stopOpacity:".48"})]},l.tone))}),e.jsx("circle",{r:"231",fill:"none",stroke:"var(--rr-grid)",strokeDasharray:"1 8"}),n.map((l,d)=>{const f=d*60,h=(f-90)*Math.PI/180,g=Math.cos(h)*142,c=Math.sin(h)*142,v=o>0?l.value/o:null;return e.jsxs("g",{className:"rr-outcome-petal","data-outcome":l.tone,style:{"--rr-tint":`var(--rr-${l.tone})`,"--rr-order":d},children:[e.jsxs("title",{children:[l.label,": ",S(l.value)," (",v===null?"no samples":`${(v*100).toFixed(1)}% of attempts`,")"]}),e.jsx("g",{transform:`rotate(${f})`,children:e.jsxs("g",{className:"rr-petal-reveal",children:[e.jsx("path",{d:fe,fill:`url(#${a}-${l.tone})`,stroke:"var(--rr-tint)",strokeOpacity:".2"}),e.jsx("path",{d:"M 0 -74 Q -19 -123 -8 -179",fill:"none",stroke:"var(--rr-card)",strokeWidth:"2",strokeOpacity:".5"})]})}),e.jsx("path",{d:T(214,f-116,52),fill:"none",stroke:"var(--rr-tint)",strokeOpacity:".12",strokeWidth:"5",strokeLinecap:"round"}),v!==null&&v>0?e.jsx("path",{className:"rr-outcome-arc rr-draw",d:T(214,f-116,52*v),pathLength:"1",fill:"none",stroke:"var(--rr-tint)",strokeWidth:"5"}):null,e.jsxs("g",{className:"rr-petal-label",textAnchor:"middle",children:[e.jsx("text",{x:g,y:c-5,className:"rr-petal-count",children:S(l.value)}),e.jsx("text",{x:g,y:c+16,className:"rr-petal-name",children:l.short}),e.jsx("text",{x:g,y:c+33,className:"rr-petal-share",children:v===null?"â":`${(v*100).toFixed(1)}%`})]})]},l.tone)}),e.jsxs("g",{className:"rr-bloom-center",children:[e.jsx("circle",{r:"68",fill:"var(--rr-card)",stroke:"var(--rr-border)"}),e.jsx("image",{href:oe,x:"-22",y:"-53",width:"44",height:"44"}),e.jsx("text",{y:"18",textAnchor:"middle",className:"rr-bloom-total",children:S(o)}),e.jsx("text",{y:"39",textAnchor:"middle",className:"rr-petal-share",children:"observed attempts"})]})]})}),e.jsxs("div",{className:"rr-bloom-summary",children:[e.jsxs("div",{className:"rr-success-summary",children:[e.jsx("span",{className:"rr-eyebrow",children:"Finalized task success"}),e.jsxs("div",{className:"rr-success-number",role:"img","aria-label":i===null?"No finalized tasks to measure":`${(i*100).toFixed(1)}% of finalized tasks completed successfully`,children:[e.jsxs("strong",{children:[i===null?"â":(i*100).toFixed(1),i===null?null:e.jsx("small",{children:"%"})]}
1),e.jsxs("svg",{viewBox:"-100 -100 200 160","aria-hidden":!0,className:"rr-success-arc",children:[e.jsx("path",{d:T(80,150,240),fill:"none",stroke:"var(--rr-grid)",strokeWidth:"12",strokeLinecap:"round"}),i!==null&&i>0?e.jsx("path",{className:"rr-draw",d:T(80,150,240*i),pathLength:"1",fill:"none",stroke:"var(--rr-success)",strokeWidth:"12",strokeLinecap:"round"}):null]})]}),e.jsxs("p",{children:[S(s.completed)," completed / ",S(x)," finalized tasks"]}),e.jsx("span",{className:"rr-summary-note",children:"Completed + failed tasks only · unfinished tasks excluded"})]}),e.jsx("div",{className:"rr-checkpoint-line","aria-label":"Routine qualification and task creation",children:m.map((l,d)=>e.jsxs("div",{className:"rr-checkpoint",style:{"--rr-order":d},children:[e.jsx("span",{className:"rr-checkpoint-step",children:String(d+1).padStart(2,"0")}),e.jsx("strong",{children:S(l.value)}),e.jsx("span",{children:l.label})]},l.label))})]})]}),e.jsxs("div",{className:"rr-bloom-caption",children:[e.jsx("span",{children:"Petals group outcomes · each arc = share of all attempts, 0â100% · petal size is decorative"}),e.jsx("span",{children:"Completion â confirmed delivery"})]})]})}const L=t=>`${(t*100).toFixed(1)}%`,z=t=>new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});function je(t){const a=Date.parse(t.generatedAt),s=a-t.windowHours*36e5,o=t.bucketSizeHours*36e5,x=t.timeBuckets.filter(l=>Date.parse(l.bucketStart)>=s&&Date.parse(l.bucketStart)+o<=a).toSorted((l,d)=>Date.parse(l.bucketStart)-Date.parse(d.bucketStart)),i=x.slice(x.length%2);if(i.length<2||i.some((l,d)=>d>0&&Date.parse(l.bucketStart)-Date.parse(i[d-1].bucketStart)!==o))return null;const n=i.length/2,m=l=>l.reduce((d,f)=>({completed:d.completed+f.completed,failed:d.failed+f.failed,qualified:d.qualified+f.qualified,tasksCreated:d.tasksCreated+f.tasksCreated,noTaskProduced:d.noTaskProduced+f.noTaskProduced}),{completed:0,failed:0,qualified:0,tasksCreated:0,noTaskProduced:0});return{earlier:m(i.slice(0,n)),recent:m(i.slice(n)),start:Date.parse(i[0].bucketStart),middle:Date.parse(i[n].bucketStart),end:Date.parse(i.at(-1).bucketStart)+o,hours:n*t.bucketSizeHours}}const ve=[{title:"Task success",numerator:"completed",denominator:"finalized",description:"Completed / (completed + failed)",higherIsBetter:!0},{title:"Task creation",numerator:"tasksCreated",denominator:"qualified",description:"Tasks created / qualified attempts",higherIsBetter:!0},{title:"No-task outcomes",numerator:"noTaskProduced",denominator:"qualified",description:"Ended without a task / qualified attempts",higherIsBetter:!1}];function be({data:t}){const a=je(t);return e.jsxs("section",{className:"rr-progress","aria-label":"Change between comparable periods",children:[e.jsxs("div",{className:"rr-chart-caption",children:[e.jsx("strong",{children:"Rate changes"}),e.jsx("span",{children:a?`Previous ${a.hours}h â recent ${a.hours}h · complete buckets only`:"Not enough complete time buckets to compare"})]}),e.jsx("div",{className:"rr-progress-grid",children:ve.map((s,o)=>{const x=h=>s.denominator==="finalized"?h.completed+h.failed:h.qualified,i=a?x(a.earlier):0,n=a?x(a.recent):0,m=a&&i>0?a.earlier[s.numerator]/i:null,l=a&&n>0?a.recent[s.numerator]/n:null,d=m!==null&&l!==null?(l-m)*100:null,f=d===null?"unknown":Math.abs(d)<.05?"steady":d>0===s.higherIsBetter?"better":"worse";return e.jsxs("article",{"data-direction":f,style:{"--rr-order":o},children:[e.jsx("h3",{children:s.title}),e.jsx("strong",{children:d===null?"â":`${d>0?"+":""}${d.toFixed(1)} pp`}),e.jsx("span",{children:f==="unknown"?"Insufficient samples":f==="steady"?"Unchanged":f==="better"?"Improved":"Worsened"}),e.jsxs("p",{children:[m===null?"â":L(m)," â"," ",l===null?"â":L(l)]}),e.jsxs("svg",{className:"rr-comparison-chart",viewBox:"-150 -122 300 205",role:"img","aria-label":`${s.title}: previous ${m===null?"unavailable":L(m)}, recent ${l===null?"unavailable":L(l)}. Scale zero to 100 percent.`,children:[e.jsx("path",{d:T(108,150,240),fill:"none",stroke:"var(--rr-grid)",strokeWidth:"12",strokeLinecap:"round"}),m!==null?e.jsx("path",{className:"rr-draw",d:T(108,150,240*m),pathLength:"1",fill:"none",stroke:"var(--rr-muted)",strokeOpacity:".4",strokeWidth:"12",strokeLinecap:"round"}):null,l!==null?e.jsx("path",{className:"rr-draw",d:T(108,150,240*l),pathLength:"1",fill:"none",stroke:"currentColor",strokeWidth:"5",strokeLinecap:"round"}):null,m!==null?e.jsx("circle",{cx:108*Math.cos((150+240*m)*Math.PI/180),cy:108*Math.sin((150+240*m)*Math.PI/180),r:"7",fill:"var(--rr-card)",stroke:"var(--rr-muted)",strokeWidth:"2"}):null,l!==null?e.jsx("circle",{cx:108*Math.cos((150+240*l)*Math.PI/180),cy:108*Math.sin((150+240*l)*Math.PI/180),r:"5",fill:"currentColor",stroke:"var(--rr-card)",strokeWidth:"1.5"}):null,e.jsx("text",{x:"-95",y:"80",textAnchor:"middle",fill:"var(--rr-muted)",fontSize:"13",children:"0%"}),e.jsx("text",{x:"95",y:"80",textAnchor:"middle",fill:"var(--rr-muted)",fontSize:"13",children:"100%"}),e.jsx("text",{x:"0",y:"-8",textAnchor:"middle",fill:"var(--rr-ink)",fontSize:"28",children:l===null?"â":L(l)}),e.jsx("text",{x:"0",y:"14",textAnchor:"middle",fill:"var(--rr-muted)",fontSize:"12",children:"recent period"})]}),e.jsxs("small",{children:[s.description,e.jsx("br",{}
1),i.toLocaleString()," â ",n.toLocaleString()," ","eligible samples"]})]},s.title)})}),e.jsxs("p",{className:"rr-method-note",children:["Hollow dot = previous · filled dot = recent."," ",a?`${z(a.start)}â${z(a.middle)} vs ${z(a.middle)}â${z(a.end)} (local). `:"","pp = percentage points, rounded to 0.1 pp. Directional comparison, not proof of a fix; recent attempts can still finish. Bucket medians and p95s are not averaged together."]})]})}function ye(t,a,s){return t.reduce((o,x,i)=>(x===null?o.at(-1)?.length&&o.push([]):(o.length||o.push([]),o.at(-1)?.push([58+i/Math.max(t.length-1,1)*(s-76),a(x)])),o),[]).filter(o=>o.length>0)}function H({title:t,subtitle:a,signals:s,ceiling:o,format:x}){const i=j.useId(),{ref:n,width:m,height:l}=ee(1e3,160),d=58,f=m-18,h=l*.8,g=c=>h-c/Math.max(o,1)*l*.6;return e.jsxs("div",{className:"rr-signal-track",children:[e.jsxs("div",{className:"rr-signal-info",children:[e.jsx("h3",{children:t}),e.jsx("p",{children:a}),e.jsx("div",{className:"rr-signal-legend",children:s.map(c=>{const v=c.values.at(-1)??null;return e.jsxs("span",{style:X(c.color),children:[e.jsx("i",{"aria-hidden":!0}),e.jsx("span",{children:c.name}),e.jsx("b",{children:x(v)})]},c.name)})})]}),e.jsx("div",{className:"rr-signal-plot",ref:n,children:e.jsxs("svg",{viewBox:`0 0 ${m} ${l}`,role:"img","aria-label":`${t}. ${a}`,children:[e.jsx("defs",{children:s.map((c,v)=>e.jsxs("linearGradient",{id:`${i}-${v}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{stopColor:c.color,stopOpacity:".24"}),e.jsx("stop",{offset:"1",stopColor:c.color,stopOpacity:"0"})]},c.name))}),[0,.5,1].map(c=>e.jsxs("g",{children:[e.jsx("line",{x1:d,x2:f,y1:g(o*c),y2:g(o*c),stroke:"var(--rr-muted)",strokeOpacity:".13",strokeDasharray:"2 6"}),e.jsx("text",{x:d-14,y:g(o*c)+5,fontSize:"14",textAnchor:"end",fill:"var(--rr-muted)",children:x(o*c)})]},c)),[0,.25,.5,.75,1].map(c=>e.jsx("line",{x1:d+c*(f-d),x2:d+c*(f-d),y1:l*.1,y2:l*.90625,stroke:"var(--rr-muted)",strokeOpacity:".07"},c)),e.jsx("g",{className:"rr-signal-reveal",children:s.map((c,v)=>{const C=ye(c.values,g,m);return e.jsxs("g",{children:[C.map((p,$)=>{const k=p[0],w=p.at(-1),y=p.map(([r,b],u)=>`${u?"L":"M"} ${r} ${b}`).join(" ");return e.jsxs("g",{children:[e.jsx("path",{d:`${y} L ${w[0]} ${h} L ${k[0]} ${h} Z`,fill:`url(#${i}-${v})`}),e.jsx("path",{d:y,fill:"none",stroke:c.color,strokeOpacity:".08",strokeWidth:"14"}),e.jsx("path",{d:y,fill:"none",stroke:c.color,strokeWidth:"2.4",strokeLinejoin:"round",strokeLinecap:"round",className:"rr-signal-line"}),p.map(([r,b],u)=>e.jsx("circle",{cx:r,cy:b,r:p.length===1?3:1.5,fill:c.color,children:e.jsxs("title",{children:[c.name,":"," ",x(c.values[Math.round((r-d)/(f-d)*Math.max(c.values.length-1,1))]??null)]})},u))]},$)}),c.values.at(-1)!==null&&c.values.at(-1)!==void 0?e.jsx("circle",{cx:c.values.length===1?d:f,cy:g(c.values.at(-1)),r:"4.5",fill:c.color}):null]},c.name)})}),s.every(c=>c.values.every(v=>v===null))?e.jsx("text",{x:(d+f)/2,y:l/2+3,fontSize:"16",fill:"var(--rr-muted)",textAnchor:"middle",children:"No measured samples in this window"}):null]})})]})}const ke=t=>t===null?"â":`${Number(t.toFixed(1))}%`,Ne=t=>t===null?"â":S(Math.round(t));function Se({data:t}){const a=t.timeBuckets,s=j.useMemo(()=>[{name:"Success",color:"var(--rr-success)",values:a.map(n=>n.completed+n.failed>0?n.completed/(n.completed+n.failed)*100:null)},{name:"Task creation",color:"var(--rr-running)",values:a.map(n=>n.qualified>0?n.tasksCreated/n.qualified*100:null)}],[a]),o=j.useMemo(()=>[{name:"Median",color:"var(--rr-running)",values:a.map(n=>n.p50CompletedDurationMs)},{name:"p95",color:"var(--rr-comparison)",values:a.map(n=>n.p95CompletedDurationMs)}],[a]),x=j.useMemo(()=>[{name:"Failed",color:"var(--rr-failure)",values:a.map(n=>n.failed)},{name:"No task",color:"var(--rr-attention)",values:a.map(n=>n.noTaskProduced)},{name:"Active",color:"var(--rr-running)",values:a.map(n=>n.inProgress)}],[a]),i=[...new Set([0,Math.floor((a.length-1)/2),a.length-1])].filter(n=>n>=0&&n<a.length);return e.jsxs("div",{className:"rr-signal-loom",children:[e.jsx("span",{className:"rr-eyebrow",children:"Reliability over time"}),e.jsx(H,{title:"Task success & creation",subtitle:"Success = completed / (completed + failed). Creation = tasks / qualified attempts.",signals:s,ceiling:100,format:ke}),e.jsx(H,{title:"Time to finish",subtitle:"Completed tasks only. Median = halfway point; 95% finish within p95. Lower is faster.",signals:o,ceiling:Math.max(6e4,...o.flatMap(n=>n.values).filter(n=>n!==null)),format:E}),e.jsx(H,{title:"Failed, no task & active",subtitle:"Current outcomes grouped by the attempt's start time.",signals:x,ceiling:Math.max(1,...x.flatMap(n=>n.values).filter(n=>n!==null)),format:Ne}),e.jsxs("div",{className:"rr-signal-axis",children:[e.jsx("span",{children:"Start time · local"}),e.jsx("div",{children:i.map(n=>
1e.jsx("span",{children:new Date(a[n].bucketStart).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})},n))})]}),e.jsxs("p",{className:"rr-plot-caption",children:[t.bucketSizeHours,"h buckets · edge buckets are partial · missing measurements stay gaps · legend values are the latest bucket, not the whole window"]})]})}const Q="(prefers-reduced-motion: reduce)";function te(t,a,s=!0){const[o,x]=j.useState(0),[i,n]=j.useState(()=>!(window.matchMedia?.(Q).matches??!1)),[m,l]=j.useState(!1),[d,f]=j.useState(()=>!document.hidden),h=t>0?o%t:0,g=typeof a=="number"?a:a[h]??18e3,c=i&&s&&d&&!m&&t>1;j.useEffect(()=>{const y=window.matchMedia?.(Q),r=()=>{y?.matches&&n(!1)},b=()=>f(!document.hidden);return y?.addEventListener?.("change",r),document.addEventListener("visibilitychange",b),()=>{y?.removeEventListener?.("change",r),document.removeEventListener("visibilitychange",b)}},[]),j.useEffect(()=>{if(!c)return;const y=window.setTimeout(()=>x(r=>(r+1)%t),g);return()=>window.clearTimeout(y)},[h,c,t,g]);const v=j.useCallback((y,r=!0)=>{x(y),r&&n(!1)},[]),C=j.useCallback(()=>n(y=>!y),[]),p=j.useCallback(()=>l(!0),[]),$=j.useCallback(y=>{y.currentTarget.contains(y.relatedTarget)||l(!1)},[]),k=j.useMemo(()=>({onFocusCapture:p,onBlurCapture:$}),[$,p]),w=j.useMemo(()=>({animationDuration:`${g}ms`,animationPlayState:c?"running":"paused"}),[c,g]);return{activeIndex:h,playing:i,advancing:c,select:v,toggle:C,interactionProps:k,progressStyle:w}}const G=t=>t.replace(/([a-z\d])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replaceAll("_"," "),se=t=>new Date(t).toLocaleString(),$e={completed:"Task completed",failed:"Task failed",no_task:"Ended without a task",in_progress:"Task in progress"},K={completed:"success",failed:"failure",no_task:"attention",in_progress:"running"},B=t=>t.userReaction==="negative"?4:t.qualityStatus==="failed"?3:t.outcome==="failed"?2:t.outcome==="no_task"?1:0;function we({item:t}){return e.jsxs("article",{className:"rr-evidence-card","data-tone":t.userReaction==="negative"||t.qualityStatus==="failed"?"failure":K[t.outcome],children:[e.jsxs("h3",{children:[G(t.triggerType),e.jsxs("small",{children:[G(t.scope)," routine"]})]}),e.jsx("span",{"data-tone":K[t.outcome],children:$e[t.outcome]}),e.jsx("span",{"data-tone":t.qualityStatus==="not_scored"?"neutral":t.qualityStatus==="failed"?"failure":"success",title:"Stored quality check",children:t.qualityStatus==="not_scored"?"Not scored":t.qualityStatus==="failed"?"Failed":"Passed"}),e.jsx("span",{"data-tone":t.userReaction==="negative"?"failure":"neutral",title:t.userReaction==="negative"?"Stored bad-reaction rescore flag, not a customer quote or satisfaction score":"No reaction signal available",children:t.userReaction==="negative"?"Bad-reaction flag":"â"}),e.jsx("time",{dateTime:t.occurredAt,title:se(t.occurredAt),children:new Date(t.occurredAt).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}),t.taskId?e.jsx("a",{href:`/admin/subtask/${t.taskId}`,"aria-label":`Open routine task ${t.taskId}`,children:"Inspect task"}):e.jsx("span",{title:"No task was created; no task transcript exists.",children:"No task"})]})}function Y({data:t,playing:a,compact:s=!1}){const o=j.useMemo(()=>t.pulseItems.filter(h=>B(h)>0).toSorted((h,g)=>B(g)-B(h)||Date.parse(g.occurredAt)-Date.parse(h.occurredAt)),[t.pulseItems]),x=s?1:4,i=Math.ceil(o.length/x),n=te(i,8e3,a),{activeIndex:m,select:l}=n,d=j.useCallback(()=>l((m+1)%i,!1),[m,i,l]),f=o.slice(m*x,(m+1)*x);return e.jsxs("section",{className:s?"rr-evidence-rail":"rr-evidence","aria-label":"Recent routine task and user signals","data-compact":s,...n.interactionProps,children:[s?null:e.jsxs("div",{className:"rr-scene-heading",children:[e.jsxs("div",{children:[e.jsx("span",{className:"rr-eyebrow",children:"05 / Task examples"}),e.jsx("h2",{children:"Task failures and quality checks"})]}),e.jsxs("p",{children:[o.length," flagged examples · latest snapshot"]})]}),e.jsxs("div",{className:"rr-chart-caption",children:[e.jsx("strong",{children:s?"Recent task failures and flags":"Recorded outcomes"}),e.jsxs("span",{children:["Snapshot · ",se(t.generatedAt)," · not live"]})]}),f.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rr-evidence-transition",children:[e.jsxs("div",{className:"rr-evidence-columns","aria-hidden":!0,
1children:[e.jsx("span",{children:"Routine"}),e.jsx("span",{children:"Outcome"}),e.jsx("span",{children:"Quality"}),e.jsx("span",{children:"Reaction"}),e.jsx("span",{children:"Updated"}),e.jsx("span",{})]}),f.map((h,g)=>e.jsx(we,{item:h},`${h.taskId}-${h.occurredAt}-${g}`))]},`${n.activeIndex}-${t.generatedAt}`),e.jsxs("div",{className:"rr-evidence-controls",children:[e.jsxs("span",{children:[m*x+1,"â",Math.min((m+1)*x,o.length)," of ",o.length," ","examples"]}),i>1?e.jsx("button",{type:"button",onClick:d,children:s?"Next example":"Next examples"}):null]})]}):e.jsx("p",{className:"rr-method-note",children:"No problem examples in the loaded sample. This does not prove every routine is healthy."}),s?null:e.jsx("p",{className:"rr-method-note",children:"Up to 12 examples · â = unknown · refresh for new events"})]})}const W="text-[13px] font-semibold tracking-tight text-slate-11",Ce="flex h-full min-h-[260px] flex-col gap-5 rounded-2xl border border-slate-5 bg-slate-2 p-6 shadow-[0_4px_24px_rgba(0,0,0,0.28)] ring-1 ring-inset ring-white/[0.03] transition-all duration-200 hover:border-slate-6";function D({label:t,value:a,context:s,warning:o=!1}){return e.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5 border-l border-slate-4 px-3 first:border-l-0",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-[0.12em] text-slate-9",children:t}),e.jsx("span",{className:M("text-2xl font-semibold tabular-nums text-slate-12 sm:text-3xl",o&&"text-amber-11"),children:a}),e.jsx("span",{className:"text-xs leading-4 text-slate-9",children:s})]})}function I({label:t,value:a,denominator:s,barClassName:o}){const x=s===0?0:a/s;return e.jsxs("div",{className:"grid grid-cols-[92px_minmax(0,1fr)_64px] items-center gap-3",children:[e.jsx("span",{className:"text-xs font-medium text-slate-10",children:t}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-slate-3/80",children:e.jsx("div",{className:M("h-full min-w-0 rounded-full",o),style:{width:`${Math.max(0,Math.min(1,x))*100}%`}})}),e.jsx("span",{className:"text-right text-xs font-semibold tabular-nums text-slate-12",children:a.toLocaleString()})]})}function P({active:t,children:a}){return t?e.jsx("div",{className:"routine-reliability-tv-scene-enter flex min-w-0 flex-col gap-5",children:a}):e.jsx(e.Fragment,{})}function Me({data:t,windowHours:a,isUpdatingWindow:s=!1,onSelectWindow:o,onRefresh:x}){const i=j.useRef(null),[n,m]=j.useState(!1),[l,d]=j.useState(null);j.useEffect(()=>{const u=()=>m(document.fullscreenElement===i.current);return document.addEventListener("fullscreenchange",u),()=>document.removeEventListener("fullscreenchange",u)},[]);const f=j.useCallback(async()=>{d(null);try{document.fullscreenElement?await document.exitFullscreen():i.current?.requestFullscreen?await i.current.requestFullscreen():d("Full-screen is unavailable in this browser. Use the browserâs full-screen control.")}catch(u){ce(u,{tags:{source:"reliability-tv-fullscreen"}}),d("Could not open the TV screen. Use the browserâs full-screen control.")}},[]),h=te(q.length,de,!s),g=h.activeIndex,c=h.playing,v=h.select,C=j.useCallback(u=>{const N=Number(u.currentTarget.dataset.scene);N>=0&&N<q.length&&v(N)},[v]),{totals:p,completedDuration:$}=t,k=t.stuckStages.find(u=>u.stage==="awaiting_approval")?.count??0,w=Math.max(0,p.stuck-k),y=p.tasksCreated===0?null:p.completed/p.tasksCreated,r=p.qualified===0?null:p.tasksCreated/p.qualified,b=p.stuck===0&&p.failed===0&&p.noTaskProduced===0?"No active runs are stuck":p.stuck>0?`${p.stuck.toLocaleString()} runs need attention`:`${p.failed.toLocaleString()} failed · ${p.noTaskProduced.toLocaleString()} no-task outcomes`;return e.jsxs("div",{className:M(Ce,"gap-5 routine-reliability-panel-shell rr-story"),ref:i,"data-paused":!h.advancing,children:[e.jsx("div",{className:"routine-reliability-tv-galaxy absolute inset-0 pointer-events-none"}),e.jsx("div",{className:"routine-reliability-ambient-orbit routine-reliability-tv-orbit"}),e.jsx("div",{className:"routine-reliability-ambient-flare pointer-events-none"}),e.jsxs("div",{className:"routine-reliability-scene-panel relative z-10 flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[e.jsx("span",{className:"text-[15px] font-semibold tracking-tight text-slate-12",children:"Routine run health"}),e.jsx("span",{className:"text-xs text-slate-9",children:s?`Updating to ${a===96?"4d":"24h"}â¦`:`Stored events, read on load · updated ${pe(t.generatedAt)}`})]}),e.jsxs("div",{className:"routine-reliability-scene-panel relative z-10 flex flex-wrap items-center justify-end gap-2",children:[e.jsx("div",{className:"flex items-center gap-1 rounded-md border border-slate-4 bg-slate-1 p-0.5",children:J.map(u=>{const N="unavailableReason"in u?u.unavailableReason:null;return e.jsx("button",{type:"button","data-hours":u.hours,onClick:o,disabled:N!=null,title:N??void 0,"aria-pressed":t.windowHours===u.hours,className:M("rounded px-2.5 py-1 text-xs font-medium transition-colors",N!=null?"curs
1or-not-allowed text-slate-8":t.windowHours===u.hours?"bg-slate-3 text-slate-12":"text-slate-10 hover:text-slate-12"),children:u.label},u.hours)})}),e.jsx("button",{type:"button",onClick:x,className:"rounded-md border border-slate-4 px-2.5 py-1 text-xs font-medium text-slate-10 transition-colors hover:border-slate-6 hover:text-slate-12",children:"Refresh"})]})]}),e.jsxs("div",{className:"routine-reliability-scene-panel relative z-10 grid gap-3 border-y border-slate-4/70 py-3 sm:grid-cols-[minmax(0,1fr)_auto_auto] sm:items-center",children:[e.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-5","aria-label":"TV story scenes",children:q.map((u,N)=>e.jsxs("button",{type:"button","data-scene":N,onClick:C,"aria-current":g===N?"step":void 0,className:"group relative z-10 flex min-w-0 flex-col gap-1.5 rounded-lg border border-slate-5/60 bg-slate-2/70 px-2.5 py-2 transition-colors duration-200 hover:border-slate-6 hover:bg-slate-2/90",children:[e.jsxs("span",{className:M("text-xs font-semibold uppercase tracking-[0.12em] transition-colors",g===N?"text-slate-12":"text-slate-8"),children:["0",N+1," · ",u.label]}),e.jsx("span",{className:"truncate text-xs text-slate-9",children:u.description}),e.jsxs("span",{className:"h-0.5 overflow-hidden rounded-full bg-slate-4",children:[N<g?e.jsx("span",{className:"block h-full w-full bg-slate-9"}):null,N===g?c?e.jsx("span",{className:"routine-reliability-tv-progress block h-full origin-left bg-blue-9",style:h.progressStyle},`${g}-${h.advancing}`):e.jsx("span",{className:"block h-full w-1/3 bg-blue-9"}):null]})]},u.label))}),e.jsx("button",{type:"button",onClick:h.toggle,className:"justify-self-start rounded-md border border-slate-4 px-3 py-1.5 text-xs font-medium text-slate-10 transition-colors hover:border-slate-6 hover:text-slate-12 sm:justify-self-end",children:c?"Pause TV story":"Play TV story"}),e.jsx("button",{type:"button",onClick:f,className:"rr-tv-screen-button",children:n?"Exit TV screen":"Open TV screen"})]}),l?e.jsx("p",{role:"alert",children:l}):null,e.jsxs("div",{className:"rr-canvas routine-reliability-scene-panel relative z-10 min-h-[360px]","data-paused":!h.advancing,...h.interactionProps,children:[e.jsxs(P,{active:g===0,children:[e.jsx(ge,{data:t}),e.jsxs("div",{className:"rr-stats grid grid-cols-2 gap-y-4 sm:grid-cols-4",children:[e.jsx(D,{label:"Tasks completed",value:y===null?"â":V(y),context:`${p.completed.toLocaleString()} of ${p.tasksCreated.toLocaleString()} tasks`}),e.jsx(D,{label:"Stuck runs",value:w.toLocaleString(),context:`${t.stuckAfterMinutes}m without progress · ${k.toLocaleString()} approval waits counted separately`,warning:w>0}),e.jsx(D,{label:"Task creation",value:r===null?"â":V(r),context:`${p.tasksCreated.toLocaleString()} of ${p.qualified.toLocaleString()} qualified runs`}),e.jsx(D,{label:"Time to finish",value:O($.p50Ms),context:`median · p95 ${O($.p95Ms)} · completed tasks only`})]}),e.jsxs("div",{className:M("routine-reliability-scene-panel flex flex-wrap items-center justify-between gap-3 rounded-lg border px-4 py-3",p.attempts===0?"border-slate-5 bg-slate-2/40":p.failed>0?"border-red-6 bg-red-2/50":p.stuck>0||p.noTaskProduced>0?"border-amber-6 bg-amber-2/50":"border-green-6 bg-green-2/50"),children:[e.jsx("span",{className:"text-sm font-medium text-slate-12",children:p.attempts===0?"No routine attempts in this window":b}),e.jsxs("span",{className:"text-xs text-slate-10",children:[p.failed.toLocaleString()," failed ·"," ",p.noTaskProduced.toLocaleString()," ended without a task ·"," ",p.inProgress.toLocaleString()," active"]})]})]}),e.jsxs(P,{active:g===1,children:[e.jsxs("div",{className:"rr-scene-heading",children:[e.jsxs("div",{children:[e.jsx("span",{className:"rr-eyebrow",children:"02 / Period comparison"}),e.jsx("h2",{children:"Change vs previous period"})]}),e.jsxs("p",{children:["Task success · task creation · no-task rate",e.jsx("br",{}),"Equal-length periods, complete buckets only"]})]}),e.jsx(be,{data:t}),e.jsx(ue,{data:t})]}),e.jsxs(P,{active:g===2,children:[e.jsxs("div",{className:"rr-scene-heading",children:[e.jsxs("div",{children:[e.jsx("span",{className:"rr-eyebrow",children:"03 / Time series"}),e.jsx("h2",{children:"Task success, duration, and failures"})]}),e.jsxs("p",{children:["Each point groups attempts by start time.",e.jsx("br",{}),"The latest bucket is still filling."]})]}),e.jsx(Se,{data:t})]}),e.jsxs(P,{active:g===3,children:[e.jsx(xe,{data:t}),e.jsxs("details",{className:"rr-detail",children:[e.jsx("summary",{children:"Explore the full funnel and routine breakdown"}),e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-12",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:col-span-7",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("span",{className:W,children:"Run funnel"}),e.jsx("span",{className:"text-xs text-slate-9",children:"dry runs excluded"})]}),e.jsx(I,{label:"Trigger attempts",value:p.attempts,denominator:p.attempts,barClassName:"bg-slate-8"}),e.jsx(I,{label:"Qualified runs",value:p.qualified,denominator:p.attempts,barClassName:"bg-indigo-9"}),e.jsx(I,{label:"Tasks created",value:p.tasksCreated,denominator:p.attempts,barClassName:"bg-blue-9"}),e.jsx(I,{label:"Tasks completed",value:p.completed,denominator:p.attempts,barClassName:"bg-green-9"}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 border-t border-slate-4/70 pt-3 text-xs text-slate-9",children:[e.jsxs("span",{children:[p.skipped.toLocaleStr
1ing()," skipped by conditions"]}),e.jsxs("span",{children:[p.inProgress.toLocaleString()," in progress"]}),e.jsxs("span",{children:[p.noTaskProduced.toLocaleString()," ended without a task"]}),e.jsxs("span",{children:[$.sampleCount.toLocaleString()," completed durations"]})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 lg:col-span-5",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("span",{className:W,children:"Stalls and approval waits"}),e.jsx("span",{className:"text-xs text-slate-9",children:`No progress for ${t.stuckAfterMinutes}m, or approval needed`})]}),t.stuckStages.length===0?e.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-xl border border-dashed border-slate-5 text-sm text-slate-9",children:"No stalls or approval waits in this window"}):e.jsx("div",{className:"flex flex-col divide-y divide-slate-4/70",children:t.stuckStages.map(u=>e.jsxs("div",{className:"flex items-center justify-between gap-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium text-slate-11",children:Z(u.stage)}),e.jsxs("span",{className:"flex items-baseline gap-3 text-xs text-slate-9",children:[e.jsxs("span",{children:[O(u.oldestAgeMs)," oldest"]}),e.jsx("span",{className:"min-w-8 text-right font-semibold tabular-nums text-slate-12",children:u.count.toLocaleString()})]})]},u.stage))})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 border-t border-slate-4/70 pt-5",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[e.jsx("span",{className:W,children:"By routine trigger"}),e.jsx("span",{className:"text-xs text-slate-9",children:"Average time covers completed tasks only"})]}),t.triggerTypes.length===0?e.jsx("div",{className:"py-6 text-center text-sm text-slate-9",children:"No production routine attempts in this window."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[900px] border-collapse text-left text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-5 text-slate-9",children:[e.jsx("th",{className:"py-2 pr-4 font-medium",children:"Trigger"}),e.jsx("th",{className:"px-3 py-2 font-medium",children:"Scope"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"Runs"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"Tasks"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"Completed"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"In progress"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"Failed"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"No task"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"Stuck / approval"}),e.jsx("th",{className:"py-2 pl-3 text-right font-medium",children:"Avg time"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-4/60",children:t.triggerTypes.map(u=>e.jsxs("tr",{children:[e.jsx("td",{className:"py-2.5 pr-4 font-medium text-slate-12",children:Z(u.triggerType)}),e.jsx("td",{className:"px-3 py-2.5 text-slate-10",children:me(u.scope)}),e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums text-slate-11",children:u.attempts.toLocaleString()}),e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums text-slate-11",children:u.tasksCreated.toLocaleString()}),e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums text-slate-11",children:u.completed.toLocaleString()}),e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums text-slate-11",children:u.inProgress.toLocaleString()}),e.jsx("td",{className:M("px-3 py-2.5 text-right tabular-nums text-slate-11",u.failed>0&&"text-red-11"),children:u.failed.toLocaleString()}),e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums text-slate-11",children:u.noTaskProduced.toLocaleString()}),e.jsx("td",{className:M("px-3 py-2.5 text-right tabular-nums text-slate-11",u.stuck>0&&"text-amber-11"),children:u.stuck.toLocaleString()}),e.jsx("td",{className:"py-2.5 pl-3 text-right tabular-nums text-slate-11",children:O(u.averageCompletedDurationMs)})]},`${u.triggerType}-${u.scope}`))})]})})]})]})]}),e.jsx(P,{active:g===4,children:e.jsx(Y,{data:t,playing:h.advancing})})]}),g!==4?e.jsx("div",{...h.interactionProps,children:e.jsx(Y,{data:t,playing:h.advancing,compact:!0})}):null,e.jsxs("details",{className:"rr-methodology border-t border-slate-4/70 pt-3 text-xs leading-relaxed text-slate-9",children:[e.jsx("summary",{children:"Data & definitions · read on refresh"}),e.jsxs("p",{children:["Derived from retained trigger attempts, task states, and approval events. Attempt history lasts ",t.retentionHours/24," days. Examples expose only categorical stored score and reaction signals plus opaque task IDs; it never displays customer text and makes no scoring or LLM calls. Completed means the task ended successfully; it does not confirm external delivery."]}
1),e.jsx("p",{children:"Other / unresolved includes attempts with no task record and cancelled tasks. Missing records do not prove a stall. Buckets use attempt creation time and current task state, so recent results can still change. Duration runs from task creation to its latest completed status, including queue and approval waits."})]})]})}const Te=ie` 2 query OperationsRoutineReliabilityQuery($windowHours: Int!) { 3 admin { 4 routineReliability(windowHours: $windowHours) { 5 generatedAt 6 windowHours 7 bucketSizeHours 8 retentionHours 9 stuckAfterMinutes 10 totals { 11 attempts 12 qualified 13 skipped 14 tasksCreated 15 completed 16 failed 17 noTaskProduced 18 inProgress 19 stuck 20 } 21 completedDuration { 22 sampleCount 23 p50Ms 24 p95Ms 25 } 26 stuckStages { 27 stage 28 count 29 oldestAgeMs 30 } 31 triggerTypes { 32 triggerType 33 scope 34 attempts 35 qualified 36 skipped 37 tasksCreated 38 completed 39 failed 40 noTaskProduced 41 inProgress 42 stuck 43 averageCompletedDurationMs 44 } 45 timeBuckets { 46 bucketStart 47 attempts 48 qualified 49 skipped 50 tasksCreated 51 completed 52 failed 53 noTaskProduced 54 inProgress 55 p50CompletedDurationMs 56 p95CompletedDurationMs 57 } 58 pulseItems { 59 taskId 60 occurredAt 61 triggerType 62 scope 63 outcome 64 qualityStatus 65 userReaction 66 } 67 } 68 } 69 } 70`;function Re(){const[t,a]=j.useState(24),s=ne(Te,{windowHours:t}),o=s.data?.admin.routineReliability,x=s.loading&&o?.windowHours!==t,i=j.useCallback(n=>{const m=Number(n.currentTarget.dataset.hours),l=J.find(d=>d.hours===m);!l||"unavailableReason"in l||a(m)},[]);return s.loading&&!o?e.jsx("div",{className:"rounded-2xl border border-slate-4 bg-slate-1 p-6",children:e.jsx(re,{})}):s.error?e.jsx("div",{className:"rounded-2xl border border-slate-4 bg-slate-1 p-6",children:e.jsx(ae,{message:s.error,onRetry:s.refetch})}):o?e.jsx(Me,{data:o,windowHours:t,isUpdatingWindow:x,onSelectWindow:i,onRefresh:s.refetch}):e.jsx("div",{className:"rounded-2xl border border-slate-4 bg-slate-1 p-6",children:"No routine data returned."})}function _e(){return e.jsx(le,{title:"Routine reliability",hideTitle:!0,children:e.jsxs("div",{className:"mx-auto flex w-full max-w-[1680px] flex-col gap-4 pb-8",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h1",{className:"text-[26px] font-semibold tracking-tight text-slate-12",children:"Routine reliability"}),e.jsx("a",{href:"/admin/reliability",className:"inline-flex min-h-10 items-center rounded-md px-3 text-sm text-slate-11 hover:bg-slate-3 hover:text-slate-12 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-slate-8",children:"Back to reliability"})]}),e.jsx(Re,{})]})})}export{_e as View};
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.