@workflow/web 4.1.0-beta.42 → 4.1.0-beta.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/build/client/assets/{highlighted-body-B3W2YXNL-Zd0qPYE7.js → highlighted-body-B3W2YXNL-BdpKyd6t.js} +1 -1
  2. package/build/client/assets/home-C884R8Ik.js +35 -0
  3. package/build/client/assets/{manifest-41615f41.js → manifest-14123a0c.js} +1 -1
  4. package/build/client/assets/{mermaid-3ZIDBTTL-BMFG0Hnn.js → mermaid-3ZIDBTTL-D6v4WgFl.js} +61 -61
  5. package/build/client/assets/{root-EzkmXyJV.js → root-CxkGJJO9.js} +1 -1
  6. package/build/client/assets/root-DUJPWGN3.css +1 -0
  7. package/build/client/assets/run-detail-D_eXHYm3.js +36 -0
  8. package/build/client/assets/server-build-BFalDDpv.css +1 -0
  9. package/build/client/assets/{use-workflow-graph-DXipnqlR.js → use-workflow-graph-WEp5s5k_.js} +1 -1
  10. package/build/server/assets/{app-BIqik-91.js → app-KW-1KXCl.js} +1 -1
  11. package/build/server/assets/{highlighted-body-B3W2YXNL-WkqeTqm-.js → highlighted-body-B3W2YXNL-DapKdL2n.js} +3 -3
  12. package/build/server/assets/index-93Io7SSr.js +76 -0
  13. package/build/server/assets/{mermaid-3ZIDBTTL-ClaETQoK.js → mermaid-3ZIDBTTL-BdsOvyTU.js} +3 -3
  14. package/build/server/assets/{server-build-Cyb0dncG.js → server-build-D9d_jMLb.js} +3773 -1454
  15. package/build/server/assets/{token-CTJIoJEi.js → token-Bf2BqxEG.js} +2 -2
  16. package/build/server/assets/{token-util-Dp_pg92C.js → token-util-C8FlMBAQ.js} +2 -2
  17. package/build/server/index.js +1 -1
  18. package/package.json +5 -5
  19. package/build/client/assets/home-C-j1J39E.js +0 -35
  20. package/build/client/assets/root-SL7uvdv2.css +0 -1
  21. package/build/client/assets/run-detail-C0ZpSKc-.js +0 -36
  22. package/build/client/assets/server-build-d6BKG46c.css +0 -1
  23. package/build/server/assets/token-Bjyd4X_e.js +0 -86
  24. package/build/server/assets/token-util-D-4jXUkD.js +0 -30
  25. package/build/server/assets/token-util-DoGNqK5w.js +0 -256
@@ -0,0 +1,36 @@
1
+ import{j as t,r as c,f as Qt,A as Jr,x as Qr,y as Us,z as en,w as tn,C as sn}from"./index-DklpUtP3.js";import{U as rt,C as bt,V as nt,B as Te,j as es,q as Gs,Y as qs,Z as rn,S as Zs,R as Ys,p as nn,o as on,X as Xs,Q as Be,_ as an,G as ln,$ as ue,u as vt,W as Oe,a0 as cn,v as je,a1 as wt,a2 as dn,t as Js,a3 as un,s as fn,a4 as _t,w as ts,l as pn,m as mn,a5 as hn,a6 as xn,a7 as gn,a8 as vn,a9 as yn,aa as bn,ab as wn,ac as jn,ad as fs,J as jt,ae as Qs,af as Nn,ag as kn,ah as ps,ai as ve,aj as ye,F as zt,ak as Sn,al as Cn,am as In,an as En,r as Tn,A as Kt,c as Ut,d as Gt,a as Me,ao as An,e as Dn,b as ft,T as Rn,M as Mn,N as pt,K as _n,O as mt,y as Ln,ap as On,I as Fn}from"./use-workflow-graph-WEp5s5k_.js";import{c as At,h as Ge,I as Q,Y as Pn,J as ge,M as Fe,N as Nt,_ as Wn,O as $n,U as Hn,W as Bn,X as er,Z as Pe,$ as be,a0 as K,a1 as Vn,a2 as zn,a3 as Lt,a4 as ce,a5 as ht,a6 as kt,a7 as Ve,a8 as Ee,a9 as tr,aa as Qe,ab as Ot,ac as Kn,ad as Un,ae as Gn,af as qn,ag as Zn,ah as Yn,ai as Xn,aj as ze,ak as pe,al as sr,l as Ke,F as qt,am as Jn,an as Qn,ao as ss,E as Ae,ap as eo,d as de,aq as rr,ar as to,as as so,at as ro,au as no,T as nr,a as or,b as ar,av as oo,L as rs,u as ao,aw as ms,ax as io,t as _e,ay as lo}from"./mermaid-3ZIDBTTL-D6v4WgFl.js";import{importKey as co,decrypt as uo}from"./encryption-8OvC6eoJ.js";/**
2
+ * @license lucide-react v0.575.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const fo=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],po=At("circle-question-mark",fo);/**
7
+ * @license lucide-react v0.575.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const mo=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],ho=At("info",mo);/**
12
+ * @license lucide-react v0.575.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const xo=[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]],Ft=At("list",xo);/**
17
+ * @license lucide-react v0.575.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const go=[["path",{d:"M12 4v16",key:"1654pz"}],["path",{d:"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2",key:"e0r10z"}],["path",{d:"M9 20h6",key:"s66wpe"}]],vo=At("type",go),yo="@keyframes wf-spinner-fade{0%{opacity:1}100%{opacity:.15}}";function ns({size:e=14,color:s}){const r=e<=12?{angle:45,delays:[-875,-750,-625,-500,-375,-250,-125,0],duration:1e3,lineW:3,lineH:1.5}:e<=16?{angle:36,delays:[-900,-800,-700,-600,-500,-400,-300,-200,-100,0],duration:1e3,lineW:4,lineH:1.5}:{angle:30,delays:[-1100,-1e3,-900,-800,-700,-600,-500,-400,-300,-200,-100,0],duration:1200,lineW:e*.24,lineH:e*.08};return t.jsxs("span",{style:{display:"inline-flex",position:"relative",width:e,height:e},children:[t.jsx("style",{dangerouslySetInnerHTML:{__html:yo}}),r.delays.map((n,o)=>t.jsx("span",{style:{position:"absolute",left:"50%",top:"50%",width:r.lineW,height:r.lineH,marginLeft:-r.lineW/2,marginTop:-r.lineH/2,borderRadius:1,backgroundColor:s??"var(--ds-gray-700)",transform:`rotate(${o*r.angle}deg) translate(${e*.36}px)`,animation:`wf-spinner-fade ${r.duration}ms linear infinite`,animationDelay:`${n}ms`}},n))]})}const bo=".wf-decrypt-btn{appearance:none;-webkit-appearance:none;border:none;display:inline-flex;align-items:center;justify-content:center;height:40px;padding:0 12px;border-radius:6px;font-size:14px;font-weight:500;line-height:20px;cursor:pointer;white-space:nowrap;gap:6px;transition:background 150ms}.wf-decrypt-idle{color:var(--ds-gray-1000);background:var(--ds-background-100);box-shadow:0 0 0 1px var(--ds-gray-400)}.wf-decrypt-idle:hover{background:var(--ds-gray-alpha-200)}.wf-decrypt-done{color:var(--ds-green-900);background:var(--ds-green-100);box-shadow:0 0 0 1px var(--ds-green-400);cursor:default}";function os({decrypted:e=!1,loading:s=!1,onClick:r}){return t.jsxs(t.Fragment,{children:[t.jsx("style",{dangerouslySetInnerHTML:{__html:bo}}),t.jsxs("button",{type:"button",onClick:e?void 0:r,disabled:e||s,className:`wf-decrypt-btn ${e?"wf-decrypt-done":"wf-decrypt-idle"}`,children:[s?t.jsx(ns,{size:14}):e?t.jsxs("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]}):t.jsxs("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),s?"Decrypting…":e?"Decrypted":"Decrypt"]})]})}function tt(e){return e!=null&&typeof e=="object"&&"stack"in e&&typeof e.stack=="string"}function St({value:e}){const s=Ge(),r=e.stack,n=typeof e.message=="string"?e.message:void 0,o=n?`${n}
22
+
23
+ ${r}`:r;return t.jsxs("div",{className:"relative overflow-hidden rounded-md border",style:{borderColor:"var(--ds-red-400)",background:"var(--ds-red-100)"},children:[t.jsx("button",{type:"button","aria-label":"Copy error",title:"Copy",className:"!absolute !right-2 !top-2 !flex !h-6 !w-6 !items-center !justify-center !rounded-md !border transition-transform transition-colors duration-100 hover:!bg-[var(--ds-red-200)] active:!scale-95",style:{borderColor:"var(--ds-red-400)",background:"var(--ds-red-100)",color:"var(--ds-red-900)"},onClick:()=>{navigator.clipboard.writeText(o).then(()=>{s.success("Copied to clipboard")}).catch(()=>{s.error("Failed to copy")})},children:t.jsx(rt,{size:12})}),n&&t.jsxs("div",{className:"flex items-start gap-2 px-3 py-2.5 pr-10",style:{color:"var(--ds-red-900)",borderBottom:"1px solid var(--ds-red-400)"},children:[t.jsx(bt,{className:"h-4 w-4 shrink-0",style:{marginTop:1}}),t.jsx("p",{className:"text-xs font-semibold m-0 break-words",children:n})]}),t.jsx("pre",{className:"px-3 py-2.5 text-xs font-mono whitespace-pre-wrap break-words overflow-auto m-0",style:{color:"var(--ds-red-900)",background:"var(--ds-red-200)"},children:r})]})}const wo=".wf-load-more{appearance:none;-webkit-appearance:none;border:none;display:inline-flex;align-items:center;justify-content:center;height:32px;padding:0 12px;border-radius:6px;font-size:13px;font-weight:500;line-height:20px;color:var(--ds-gray-1000);background:var(--ds-background-100);box-shadow:0 0 0 1px var(--ds-gray-400);cursor:pointer;white-space:nowrap;gap:6px;transition:background 150ms}.wf-load-more:hover{background:var(--ds-gray-alpha-200)}.wf-load-more:disabled{opacity:.6;cursor:default}.wf-load-more:disabled:hover{background:var(--ds-background-100)}";function jo({loading:e=!1,onClick:s,label:r="Load more",loadingLabel:n="Loading..."}){return t.jsxs(t.Fragment,{children:[t.jsx("style",{dangerouslySetInnerHTML:{__html:wo}}),t.jsxs("button",{type:"button",onClick:s,disabled:e,className:"wf-load-more",children:[e&&t.jsx(ns,{size:14}),e?n:r]})]})}const No=".wf-menu-btn{appearance:none;-webkit-appearance:none;border:none;display:inline-flex;align-items:center;justify-content:center;height:40px;padding:0 12px;border-radius:6px;font-size:14px;font-weight:500;line-height:20px;color:var(--ds-gray-1000);background:var(--ds-background-100);box-shadow:0 0 0 1px var(--ds-gray-400);cursor:pointer;white-space:nowrap;transition:background 150ms}.wf-menu-btn:hover{background:var(--ds-gray-alpha-200)}.wf-menu-item{appearance:none;-webkit-appearance:none;border:none;display:flex;align-items:center;width:100%;height:40px;padding:0 8px;border-radius:6px;font-size:14px;color:var(--ds-gray-1000);background:transparent;cursor:pointer;transition:background 150ms}.wf-menu-item:hover{background:var(--ds-gray-alpha-100)}";function ko({options:e,value:s,onChange:r}){var l,p;const[n,o]=c.useState(!1),a=c.useRef(null),i=((l=e.find(d=>d.value===s))==null?void 0:l.label)??((p=e[0])==null?void 0:p.label)??"";return c.useEffect(()=>{if(!n)return;function d(h){a.current&&!a.current.contains(h.target)&&o(!1)}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[n]),t.jsxs("div",{ref:a,style:{position:"relative",flexShrink:0},children:[t.jsx("style",{dangerouslySetInnerHTML:{__html:No}}),t.jsxs("button",{type:"button",className:"wf-menu-btn",onClick:()=>o(!n),children:[t.jsx("span",{children:i}),t.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none",style:{marginLeft:16,marginRight:-4,color:"var(--ds-gray-900)"},children:t.jsx("path",{d:"M4.5 6L8 9.5L11.5 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),n&&t.jsx("div",{style:{position:"absolute",right:0,top:"100%",marginTop:4,minWidth:140,padding:4,borderRadius:12,background:"var(--ds-background-100)",boxShadow:"var(--ds-shadow-menu, var(--ds-shadow-medium))",zIndex:2001},role:"menu",children:e.map(d=>t.jsx("button",{type:"button",role:"menuitem",className:"wf-menu-item",style:{fontWeight:d.value===s?500:400},onClick:()=>{r(d.value),o(!1)},children:d.label},d.value))})]})}const So=[{unit:"year",ms:31536e6},{unit:"month",ms:2628e6},{unit:"day",ms:864e5},{unit:"hour",ms:36e5},{unit:"minute",ms:6e4},{unit:"second",ms:1e3}];function Co(e){let s=Math.abs(e);const r=[];for(const{unit:n,ms:o}of So){const a=Math.floor(s/o);if((a>0||r.length>0)&&(r.push(`${a} ${n}${a!==1?"s":""}`),s%=o),r.length===3)break}return r.join(", ")}function Io(e){const[s,r]=c.useState("");return c.useEffect(()=>{const n=()=>{const a=Date.now()-e,i=Co(a);r(i?`${i} ago`:"Just now")};n();const o=setInterval(n,1e3);return()=>clearInterval(o)},[e]),s}function hs({date:e,zone:s}){var i;const r=new Date(e),n=((i=new Intl.DateTimeFormat("en-US",{timeZone:s,timeZoneName:"short"}).formatToParts(r).find(l=>l.type==="timeZoneName"))==null?void 0:i.value)||s,o=r.toLocaleString("en-US",{timeZone:s,year:"numeric",month:"long",day:"numeric"}),a=r.toLocaleTimeString("en-US",{timeZone:s,hour:"2-digit",minute:"2-digit",second:"2-digit"});return t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("div",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",height:16,padding:"0 6px",backgroundColor:"var(--ds-gray-200)",borderRadius:3,fontSize:11,fontFamily:"var(--font-mono, monospace)",fontWeight:500,color:"var(--ds-gray-900)",whiteSpace:"nowrap"},children:n}),t.jsx("span",{style:{fontSize:13,color:"var(--ds-gray-1000)",whiteSpace:"nowrap"},children:o})]}),t.jsx("span",{style:{fontSize:11,fontFamily:"var(--font-mono, monospace)",fontVariantNumeric:"tabular-nums",color:"var(--ds-gray-900)",whiteSpace:"nowrap"},children:a})]})}function Eo({date:e}){const s=Intl.DateTimeFormat().resolvedOptions().timeZone,r=Io(e);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12,minWidth:300,padding:"12px 14px"},children:[t.jsx("span",{style:{fontSize:13,fontVariantNumeric:"tabular-nums",color:"var(--ds-gray-900)"},children:r}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.jsx(hs,{date:e,zone:"UTC"}),t.jsx(hs,{date:e,zone:s})]})]})}const To=330,xt=8;function Ao({triggerRect:e,onMouseEnter:s,onMouseLeave:r,date:n}){const o=c.useRef(null),[a,i]=c.useState({position:"fixed",zIndex:9999,visibility:"hidden"});return c.useEffect(()=>{const l=e.top>240?"above":"below",p=e.left+e.width/2,d=o.current,h=d?d.offsetWidth:To,u=d?d.offsetHeight:100;let f=p-h/2;f=Math.max(xt,Math.min(f,window.innerWidth-h-xt));let m;l==="above"?(m=e.top-u-6,m<xt&&(m=e.bottom+6)):(m=e.bottom+6,m+u>window.innerHeight-xt&&(m=e.top-u-6)),i({position:"fixed",left:f,top:m,zIndex:9999,borderRadius:10,border:"1px solid var(--ds-gray-alpha-200)",backgroundColor:"var(--ds-background-100)",boxShadow:"0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06)",visibility:"visible"})},[e]),Qt.createPortal(t.jsx("div",{ref:o,onMouseEnter:s,onMouseLeave:r,style:a,children:t.jsx(Eo,{date:n})}),document.body)}function ir({date:e,children:s}){const[r,n]=c.useState(!1),[o,a]=c.useState(null),i=c.useRef(null),l=c.useRef(null);c.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]);const p=e==null?null:typeof e=="number"?e:new Date(e).getTime();if(p==null||Number.isNaN(p))return t.jsx(t.Fragment,{children:s});const d=()=>{l.current&&(clearTimeout(l.current),l.current=null)},h=()=>{d(),l.current=setTimeout(()=>n(!1),120)},u=()=>{d(),i.current&&a(i.current.getBoundingClientRect()),n(!0)};return t.jsxs("span",{ref:i,onMouseEnter:u,onMouseLeave:h,style:{display:"inline-flex"},children:[s,r&&o&&t.jsx(Ao,{triggerRect:o,onMouseEnter:d,onMouseLeave:h,date:p})]})}const Do=new Set(["step_failed","step_retrying","run_failed","workflow_failed"]),lr={appearance:"none",WebkitAppearance:"none",border:"none",background:"transparent"},cr="workflow-dot-pulse 1.25s cubic-bezier(0, 0, 0.2, 1) infinite";function Ro(e){return e.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1})+"."+e.getMilliseconds().toString().padStart(3,"0")}function dr(e){return e.split("_").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}function Mo(e){return e==="step_failed"||e==="run_failed"||e==="workflow_failed"?"var(--ds-red-700)":e==="run_cancelled"||e==="step_retrying"?"var(--ds-amber-700)":e==="step_completed"||e==="run_completed"||e==="workflow_completed"||e==="hook_disposed"||e==="wait_completed"?"var(--ds-green-700)":e==="step_started"||e==="run_started"||e==="workflow_started"||e==="hook_received"?"var(--ds-blue-700)":"var(--ds-gray-600)"}function _o(e,s){var o,a;const r=new Map;if(e){for(const i of e)if(i.eventType==="step_created"&&i.correlationId){const l=((o=i.eventData)==null?void 0:o.stepName)??"",p=nt(String(l));r.set(i.correlationId,(p==null?void 0:p.shortName)??l)}}const n=s!=null&&s.workflowName?((a=Te(s.workflowName))==null?void 0:a.shortName)??s.workflowName:null;return{correlationNameMap:r,workflowName:n}}function Lo(e){const s=new Map,r=new Map,n=new Map;for(const o of e){const a=new Date(o.createdAt).getTime(),i=o.correlationId??"__run__",l=o.eventType;if((l==="step_created"||l==="run_created")&&s.set(i,a),l==="step_started"||l==="run_started"||l==="workflow_started"){r.set(i,a),s.has(i)||s.set(i,a);const p=s.get(i),d=n.get(i)??{};p!==void 0&&(d.queued=a-p),n.set(i,d)}if(l==="step_completed"||l==="step_failed"||l==="run_completed"||l==="run_failed"||l==="run_cancelled"||l==="workflow_completed"||l==="workflow_failed"||l==="wait_completed"||l==="hook_disposed"){const p=r.get(i),d=n.get(i)??{};p!==void 0&&(d.ran=a-p),n.set(i,d)}}return n}function Zt(e){if(!e||typeof e!="object")return!1;for(const s of Object.values(e))if(ge(s))return!0;return!1}function Ct(e){return e==="run_created"||e==="run_started"||e==="run_completed"||e==="run_failed"||e==="run_cancelled"||e==="workflow_started"||e==="workflow_completed"||e==="workflow_failed"}const st=36,Oo=20,Pt="var(--ds-gray-500)";function xs({isFirst:e,isLast:s,isRunLevel:r,statusDotColor:n,pulse:o=!1,hasSelection:a,showBranch:i,showLaneLine:l,isLaneStart:p,isLaneEnd:d,continuationOnly:h=!1}){const u=r?8:6,f=r?5:6,m=a&&!i&&!r?.3:1;return t.jsxs("div",{className:"relative flex-shrink-0 self-stretch",style:{width:st,minHeight:h?0:void 0},children:[t.jsx("div",{style:{position:"absolute",left:8,top:h?0:e?"50%":0,bottom:h?0:s?"50%":0,width:2,backgroundColor:Pt,zIndex:0}}),!h&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{position:"absolute",left:f,top:"50%",transform:"translateY(-50%)",width:u,height:u,zIndex:2},children:[t.jsx("div",{style:{position:"absolute",inset:0,borderRadius:"50%",backgroundColor:"var(--ds-background-100)",zIndex:0}}),o&&t.jsx("div",{style:{position:"absolute",inset:0,borderRadius:"50%",backgroundColor:n,opacity:.75*m,animation:cr,zIndex:1}}),t.jsx("div",{style:{position:"relative",width:"100%",height:"100%",borderRadius:"50%",backgroundColor:n,opacity:m,transition:"opacity 150ms",zIndex:2}})]}),i&&t.jsx("div",{style:{position:"absolute",left:9,top:"50%",width:st-9,height:2,backgroundColor:Pt,zIndex:0}})]}),l&&t.jsx("div",{style:{position:"absolute",left:Oo,top:h?0:p?"50%":0,bottom:h?0:d?"50%":0,width:2,backgroundColor:Pt,zIndex:0}})]})}function gs({value:e,className:s,style:r}){const[n,o]=c.useState(!1),a=c.useRef(null);c.useEffect(()=>()=>{a.current!==null&&window.clearTimeout(a.current)},[]);const i=c.useCallback(l=>{l.stopPropagation(),navigator.clipboard.writeText(e).then(()=>{o(!0),a.current!==null&&window.clearTimeout(a.current),a.current=window.setTimeout(()=>{o(!1),a.current=null},1500)})},[e]);return t.jsxs("div",{className:`group/copy flex items-center gap-1 min-w-0 px-4 ${s??""}`,style:r,children:[t.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap",children:e||"-"}),e?t.jsx("button",{type:"button",onClick:i,className:"flex-shrink-0 opacity-0 group-hover/copy:opacity-100 transition-opacity p-0.5 rounded hover:bg-[var(--ds-gray-alpha-200)]",style:lr,"aria-label":`Copy ${e}`,children:n?t.jsx(Gs,{className:"h-3 w-3",style:{color:"var(--ds-green-700)"}}):t.jsx(rt,{className:"h-3 w-3",style:{color:"var(--ds-gray-700)"}})}):null]})}function yt(e){if(typeof e=="string"){const s=e.trim();if(s.startsWith("{")&&s.endsWith("}")||s.startsWith("[")&&s.endsWith("]")||s.startsWith('"')&&s.endsWith('"'))try{return yt(JSON.parse(s))}catch{return e}return e}if(Array.isArray(e))return e.map(yt);if(e!==null&&typeof e=="object"){if(e.constructor!==Object)return e;const s={};for(const[r,n]of Object.entries(e))s[r]=yt(n);return s}return e}function Fo(e,s){if(!s||!Do.has(s)||e==null||typeof e!="object")return null;const r=e;return tt(r.error)?r.error:tt(r)?r:null}function Po({data:e,eventType:s}){const r=c.useMemo(()=>Fo(e,s),[e,s]),[n,o]=c.useState(!1),a=c.useRef(null),i=c.useMemo(()=>yt(e),[e]);c.useEffect(()=>()=>{a.current!==null&&window.clearTimeout(a.current)},[]);const l=c.useMemo(()=>{try{return JSON.stringify(i,null,2)}catch{return String(i)}},[i]),p=c.useCallback(d=>{d.stopPropagation(),navigator.clipboard.writeText(l).then(()=>{o(!0),a.current!==null&&window.clearTimeout(a.current),a.current=window.setTimeout(()=>{o(!1),a.current=null},1500)})},[l]);return r?t.jsx("div",{className:"p-2",children:t.jsx(St,{value:r})}):t.jsxs("div",{className:"relative group/payload",children:[t.jsx("div",{className:"overflow-x-auto p-2 text-[11px]",style:{color:"var(--ds-gray-1000)"},children:t.jsx(Nt,{data:i,expandLevel:2})}),t.jsx("button",{type:"button",onClick:p,className:"absolute bottom-2 right-2 opacity-0 group-hover/payload:opacity-100 transition-opacity flex items-center gap-1 px-2 py-1 rounded-md text-xs hover:bg-[var(--ds-gray-alpha-200)]",style:{...lr,color:"var(--ds-gray-700)"},"aria-label":"Copy payload",children:n?t.jsxs(t.Fragment,{children:[t.jsx(Gs,{className:"h-3 w-3",style:{color:"var(--ds-green-700)"}}),t.jsx("span",{style:{color:"var(--ds-green-700)"},children:"Copied"})]}):t.jsxs(t.Fragment,{children:[t.jsx(rt,{className:"h-3 w-3"}),t.jsx("span",{children:"Copy"})]})})]})}const Wo=[{value:"desc",label:"Newest"},{value:"asc",label:"Oldest"}];function vs(){return t.jsx("div",{className:"flex-1 overflow-hidden",children:Array.from({length:16},(e,s)=>t.jsxs("div",{className:"flex items-center gap-0",style:{height:40},children:[t.jsxs("div",{className:"relative flex-shrink-0 self-stretch flex items-center",style:{width:st},children:[t.jsx("div",{style:{position:"absolute",left:8,top:s===0?"50%":0,bottom:0,width:2},children:t.jsx(Q,{className:"w-full h-full",style:{borderRadius:1}})}),t.jsx(Q,{className:"flex-shrink-0",style:{width:s%4===0?8:6,height:s%4===0?8:6,borderRadius:"50%",marginLeft:s%4===0?5:6}})]}),t.jsx("div",{className:"w-5 flex-shrink-0 flex items-center justify-center",children:t.jsx(Q,{className:"w-5 h-5",style:{borderRadius:4}})}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"2 1 0%"},children:t.jsx(Q,{className:"h-3",style:{width:"70%"}})}),t.jsxs("div",{className:"min-w-0 px-4 flex items-center gap-1.5",style:{flex:"2 1 0%"},children:[t.jsx(Q,{className:"flex-shrink-0",style:{width:6,height:6,borderRadius:"50%"}}),t.jsx(Q,{className:"h-3",style:{width:"60%"}})]}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"2 1 0%"},children:t.jsx(Q,{className:"h-3",style:{width:"50%"}})}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"3 1 0%"},children:t.jsx(Q,{className:"h-3",style:{width:"75%"}})}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"3 1 0%"},children:t.jsx(Q,{className:"h-3",style:{width:"75%"}})})]},s))})}function $o({event:e,index:s,isFirst:r,isLast:n,isExpanded:o,onToggleExpand:a,activeGroupKey:i,selectedGroupKey:l,selectedGroupRange:p,correlationNameMap:d,workflowName:h,durationMap:u,onSelectGroup:f,onHoverGroup:m,onLoadEventData:w,cachedEventData:b,onCacheEventData:x,encryptionKey:y,onEncryptedDataDetected:v}){const[N,g]=c.useState(!1),[k,C]=c.useState(b),[I,S]=c.useState(null),[j,E]=c.useState(b!==null);c.useEffect(()=>{b!==null&&!y&&Zt(b)&&(v==null||v())},[]);const M=Ct(e.eventType)?"__run__":e.correlationId??void 0,D=Mo(e.eventType),A=new Date(e.createdAt),P="eventData"in e&&e.eventData!=null,U=Ct(e.eventType),O=U?h??"-":e.correlationId?d.get(e.correlationId)??"-":"-",L=e.correlationId??(U?"__run__":""),T=L?u.get(L):void 0,F=i!==void 0,G=M!==void 0&&M===i,B=F&&!G,q=F&&G,X=F&&G&&!U,J=p!==null&&s>=p.first&&s<=p.last,R=p!==null&&s===p.first,_=p!==null&&s===p.last,H=c.useCallback(async()=>{if(!(k!==null||P)){g(!0),S(null);try{if(!w){S("Event details unavailable");return}const W=await w(e);W!=null&&(C(W),x(e.eventId,W),!y&&Zt(W)&&(v==null||v()))}catch(W){S(W instanceof Error?W.message:"Failed to load event details")}finally{g(!1),E(!0)}}},[e,k,P,w,x,y,v]);c.useEffect(()=>{o&&k===null&&!P&&!N&&!j&&H()},[]),c.useEffect(()=>{y&&j&&w&&(C(null),E(!1),w(e).then(W=>{W!=null&&(C(W),x(e.eventId,W)),E(!0)}).catch(()=>{E(!0)}))},[y]);const V=c.useCallback(()=>{f(M===l?void 0:M),a(e.eventId),!o&&k===null&&!P&&H()},[l,M,f,a,e.eventId,o,k,P,H]),ee=P?e.eventData:k,$=B?.3:1;return t.jsxs("div",{"data-event-id":e.eventId,onMouseEnter:()=>m(M),onMouseLeave:()=>m(void 0),children:[t.jsxs("div",{role:"button",tabIndex:0,onClick:V,onKeyDown:W=>{(W.key==="Enter"||W.key===" ")&&V()},className:"w-full text-left flex items-center gap-0 text-[13px] hover:bg-[var(--ds-gray-alpha-100)] transition-colors cursor-pointer",style:{minHeight:40},children:[t.jsx(xs,{isFirst:r,isLast:n&&!o,isRunLevel:U,statusDotColor:D,pulse:q,hasSelection:F,showBranch:X,showLaneLine:J,isLaneStart:R,isLaneEnd:_}),t.jsxs("div",{className:"flex items-center flex-1 min-w-0",style:{opacity:$,transition:"opacity 150ms"},children:[t.jsx("div",{className:"flex items-center justify-center w-5 h-5 flex-shrink-0 rounded",style:{border:"1px solid var(--ds-gray-400)"},children:t.jsx(es,{className:"h-3 w-3 transition-transform",style:{color:"var(--ds-gray-900)",transform:o?"rotate(90deg)":"rotate(0deg)"}})}),t.jsx("div",{className:"tabular-nums min-w-0 px-4",style:{color:"var(--ds-gray-900)",flex:"2 1 0%"},children:t.jsx(ir,{date:A,children:t.jsx("span",{children:Ro(A)})})}),t.jsx("div",{className:"font-medium min-w-0 px-4",style:{flex:"2 1 0%"},children:t.jsxs("span",{className:"inline-flex items-center gap-1.5",style:{color:"var(--ds-gray-900)"},children:[t.jsxs("span",{style:{position:"relative",display:"inline-flex",width:6,height:6,flexShrink:0},children:[q&&t.jsx("span",{style:{position:"absolute",inset:0,borderRadius:"50%",backgroundColor:D,opacity:.75,animation:cr}}),t.jsx("span",{style:{position:"relative",width:6,height:6,borderRadius:"50%",backgroundColor:D}})]}),dr(e.eventType)]})}),t.jsx("div",{className:"min-w-0 px-4 overflow-hidden text-ellipsis whitespace-nowrap",style:{flex:"2 1 0%"},title:O!=="-"?O:void 0,children:O}),t.jsx(gs,{value:e.correlationId||"",className:"font-mono",style:{flex:"3 1 0%"}}),t.jsx(gs,{value:e.eventId,className:"font-mono",style:{flex:"3 1 0%"}})]})]}),o&&t.jsxs("div",{className:"flex",children:[t.jsx(xs,{isFirst:!1,isLast:n,isRunLevel:U,hasSelection:F,showBranch:!1,showLaneLine:J&&!_,isLaneStart:!1,isLaneEnd:!1,continuationOnly:!0}),t.jsx("div",{className:"w-5 flex-shrink-0"}),t.jsxs("div",{className:"flex-1 my-1.5 mr-3 ml-2 py-2 rounded-md border overflow-hidden",style:{borderColor:"var(--ds-gray-alpha-200)",opacity:$,transition:"opacity 150ms"},children:[((T==null?void 0:T.queued)!==void 0||(T==null?void 0:T.ran)!==void 0)&&t.jsxs("div",{className:"px-2 pb-1.5 text-xs flex gap-3",style:{color:"var(--ds-gray-900)"},children:[T.queued!==void 0&&T.queued>0&&t.jsxs("span",{children:["Queued for"," ",t.jsx("span",{className:"font-mono tabular-nums",children:Fe(T.queued)})]}),T.ran!==void 0&&t.jsxs("span",{children:["Ran for"," ",t.jsx("span",{className:"font-mono tabular-nums",children:Fe(T.ran)})]})]}),ee!=null?t.jsx(Po,{data:ee,eventType:e.eventType}):I?t.jsx("div",{className:"rounded-md border p-3 text-xs",style:{borderColor:"var(--ds-red-400)",backgroundColor:"var(--ds-red-100)",color:"var(--ds-red-900)"},children:I}):N||!P&&!j&&e.correlationId?t.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[t.jsx(Q,{className:"h-3",style:{width:"75%"}}),t.jsx(Q,{className:"h-3",style:{width:"50%"}}),t.jsx(Q,{className:"h-3",style:{width:"60%"}})]}):t.jsx("div",{className:"p-2 text-xs",style:{color:"var(--ds-gray-900)"},children:"No data"})]})]})]})}function Ho({events:e,run:s,onLoadEventData:r,hasMoreEvents:n=!1,isLoadingMoreEvents:o=!1,onLoadMoreEvents:a,encryptionKey:i,isLoading:l=!1,sortOrder:p,onSortOrderChange:d,onDecrypt:h,isDecrypting:u=!1}){const[f,m]=c.useState("asc"),w=p??f,b=c.useCallback($=>{d?d($):m($)},[d]),x=c.useMemo(()=>{if(!e||e.length===0)return[];const $=w==="desc"?-1:1;return[...e].sort((W,Y)=>$*(new Date(W.createdAt).getTime()-new Date(Y.createdAt).getTime()))},[e,w]),y=c.useMemo(()=>{if(!e)return!1;for(const $ of e){const W=$.eventData;if(Zt(W))return!0}return!1},[e]),[v,N]=c.useState(!1),g=c.useCallback(()=>{N(!0)},[]),k=y||v,{correlationNameMap:C,workflowName:I}=c.useMemo(()=>_o(e??null,s??null),[e,s]),S=c.useMemo(()=>Lo(x),[x]),[j,E]=c.useState(void 0),[M,D]=c.useState(void 0),A=c.useCallback($=>{E($)},[]),P=c.useCallback($=>{D($)},[]),U=j??M,[O,L]=c.useState(()=>new Set),T=c.useCallback($=>{L(W=>{const Y=new Set(W);return Y.has($)?Y.delete($):Y.add($),Y})},[]),F=c.useRef(new Map),G=c.useCallback(($,W)=>{F.current.set($,W)},[]),B=c.useMemo(()=>{const $=new Map;for(const W of x){const Y=Ct(W.eventType)?"__run__":W.correlationId??"";Y&&$.set(W.eventId,Y)}return $},[x]);c.useEffect(()=>{j!==void 0&&L($=>{if($.size===0)return $;let W=!1;const Y=new Set;for(const Z of $)B.get(Z)===j?Y.add(Z):W=!0;return W?Y:$})},[j,B]);const q=c.useMemo(()=>{if(!U||U==="__run__")return null;let $=-1,W=-1;for(let Y=0;Y<x.length;Y++)x[Y].correlationId===U&&($===-1&&($=Y),W=Y);return $>=0?{first:$,last:W}:null},[U,x]),[X,J]=c.useState(""),R=c.useRef(null),_=c.useMemo(()=>{const $=[];for(let W=0;W<x.length;W++){const Y=x[W],Z=Ct(Y.eventType),re=Z?I??"":Y.correlationId?C.get(Y.correlationId)??"":"";$.push({fields:[Y.eventId,Y.correlationId??"",Y.eventType,dr(Y.eventType),re].map(oe=>oe.toLowerCase()),groupKey:Y.correlationId??(Z?"__run__":void 0),eventId:Y.eventId,index:W})}return $},[x,C,I]);c.useEffect(()=>{var Z;const $=X.trim().toLowerCase();if(!$){E(void 0);return}let W=null,Y=0;for(const re of _)for(const oe of re.fields)if(oe&&oe.includes($)){const fe=$.length/oe.length;fe>Y&&(Y=fe,W=re)}W&&(E(W.groupKey),(Z=R.current)==null||Z.scrollToIndex({index:W.index,align:"center",behavior:"smooth"}))},[X,_]);const H=c.useRef(!1);x.length>0&&(H.current=!0);const V=l&&!H.current,ee=l&&H.current&&x.length===0;return V?t.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[t.jsx("div",{style:{padding:6},children:t.jsx(Q,{style:{height:40,borderRadius:6}})}),t.jsxs("div",{className:"flex items-center gap-0 h-10 border-b flex-shrink-0",style:{borderColor:"var(--ds-gray-alpha-200)"},children:[t.jsx("div",{className:"flex-shrink-0",style:{width:st}}),t.jsx("div",{className:"w-5 flex-shrink-0"}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"2 1 0%"},children:t.jsx(Q,{className:"h-3",style:{width:40}})}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"2 1 0%"},children:t.jsx(Q,{className:"h-3",style:{width:72}})}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"2 1 0%"},children:t.jsx(Q,{className:"h-3",style:{width:44}})}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"3 1 0%"},children:t.jsx(Q,{className:"h-3",style:{width:92}})}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"3 1 0%"},children:t.jsx(Q,{className:"h-3",style:{width:60}})})]}),t.jsx(vs,{})]}):!l&&(!e||e.length===0)?t.jsx("div",{className:"flex items-center justify-center h-full text-sm",style:{color:"var(--ds-gray-700)"},children:"No events found"}):t.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[t.jsx("style",{children:"@keyframes workflow-dot-pulse{0%{transform:scale(1);opacity:.7}70%,100%{transform:scale(2.2);opacity:0}}"}),t.jsxs("div",{style:{padding:6,backgroundColor:"var(--ds-background-100)",display:"flex",gap:6},children:[t.jsxs("label",{style:{display:"flex",alignItems:"center",justifyContent:"center",borderRadius:6,boxShadow:"0 0 0 1px var(--ds-gray-alpha-400)",background:"var(--ds-background-100)",height:40,flex:1,minWidth:0},children:[t.jsx("div",{style:{width:40,height:40,display:"flex",alignItems:"center",justifyContent:"center",color:"var(--ds-gray-800)",flexShrink:0},children:t.jsxs("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",focusable:"false",children:[t.jsx("circle",{cx:"7",cy:"7",r:"4.5",stroke:"currentColor",strokeWidth:"1.5"}),t.jsx("path",{d:"M11.5 11.5L14 14",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}),t.jsx("input",{type:"search",placeholder:"Search by name, event type, or ID…",value:X,onChange:$=>J($.target.value),style:{marginLeft:-16,paddingInline:12,fontFamily:"inherit",fontSize:14,background:"transparent",border:"none",outline:"none",height:40,width:"100%"}})]}),t.jsx(ko,{options:Wo,value:w,onChange:b}),(k||i)&&h&&t.jsx(os,{decrypted:!!i,loading:u,onClick:h})]}),t.jsxs("div",{className:"flex items-center gap-0 text-[13px] font-medium h-10 border-b flex-shrink-0",style:{borderColor:"var(--ds-gray-alpha-200)",color:"var(--ds-gray-900)",backgroundColor:"var(--ds-background-100)"},children:[t.jsx("div",{className:"flex-shrink-0",style:{width:st}}),t.jsx("div",{className:"w-5 flex-shrink-0"}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"2 1 0%"},children:"Time"}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"2 1 0%"},children:"Event Type"}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"2 1 0%"},children:"Name"}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"3 1 0%"},children:"Correlation ID"}),t.jsx("div",{className:"min-w-0 px-4",style:{flex:"3 1 0%"},children:"Event ID"})]}),ee?t.jsx(vs,{}):t.jsx(Pn,{ref:R,totalCount:x.length,overscan:20,defaultItemHeight:40,endReached:()=>{!n||o||a==null||a()},itemContent:$=>{const W=x[$];return t.jsx($o,{event:W,index:$,isFirst:$===0,isLast:$===x.length-1,isExpanded:O.has(W.eventId),onToggleExpand:T,activeGroupKey:U,selectedGroupKey:j,selectedGroupRange:q,correlationNameMap:C,workflowName:I,durationMap:S,onSelectGroup:A,onHoverGroup:P,onLoadEventData:r,cachedEventData:F.current.get(W.eventId)??null,onCacheEventData:G,encryptionKey:i,onEncryptedDataDetected:g})},style:{flex:1,minHeight:0}}),t.jsxs("div",{className:"relative flex-shrink-0 flex items-center h-10 border-t px-4 text-xs",style:{borderColor:"var(--ds-gray-alpha-200)",color:"var(--ds-gray-900)",backgroundColor:"var(--ds-background-100)"},children:[t.jsxs("span",{children:[x.length," event",x.length!==1?"s":""," loaded"]}),n&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:t.jsx("div",{className:"pointer-events-auto",children:t.jsx(jo,{loading:o,onClick:()=>void(a==null?void 0:a())})})})]})]})}function Bo({messages:e}){return e.length===0?t.jsx("div",{className:"text-center py-8 text-[11px]",style:{color:"var(--ds-gray-600)"},children:"No messages"}):t.jsx("div",{className:"flex flex-col gap-3 p-3",children:e.map((s,r)=>t.jsx(Vo,{message:s},r))})}function Vo({message:e}){const s=e.role,r=Uo(e.content),n=Ko(s);return t.jsxs("div",{className:"rounded-md border text-[11px]",style:{backgroundColor:n.bg,borderColor:n.border},children:[t.jsx("div",{className:"px-2.5 py-1 border-b text-[10px] font-medium uppercase tracking-wide",style:{borderColor:n.border,color:n.label},children:s}),t.jsx("div",{className:"px-2.5 py-2 space-y-2",children:r.map((o,a)=>t.jsx(zo,{part:o,role:s},a))})]})}function zo({part:e,role:s}){return e.type==="text"?e.text?s==="assistant"?t.jsx("div",{className:"prose prose-sm max-w-none text-[11px] [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",style:{color:"var(--ds-gray-1000)"},children:t.jsx(Wn,{children:e.text})}):t.jsx("div",{className:"whitespace-pre-wrap break-words",style:{color:"var(--ds-gray-1000)"},children:e.text}):null:e.type==="tool-call"?t.jsxs("div",{className:"rounded border px-2 py-1.5",style:{backgroundColor:"var(--ds-purple-100)",borderColor:"var(--ds-purple-300)"},children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium",children:[t.jsx("span",{children:"🔧"}),t.jsx("span",{style:{color:"var(--ds-purple-900)"},children:e.toolName})]}),e.input!=null&&t.jsx("div",{className:"mt-1.5 overflow-x-auto p-1.5 rounded",style:{backgroundColor:"var(--ds-gray-100)"},children:typeof e.input=="string"?t.jsx("pre",{className:"text-[10px]",style:{color:"var(--ds-gray-800)"},children:e.input}):t.jsx(Nt,{data:e.input})})]}):e.type==="tool-result"?t.jsxs("div",{className:"rounded border px-2 py-1.5",style:{backgroundColor:"var(--ds-green-100)",borderColor:"var(--ds-green-300)"},children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium",children:[t.jsx("span",{children:"✓"}),t.jsxs("span",{style:{color:"var(--ds-green-900)"},children:[e.toolName," result"]})]}),e.output!=null&&t.jsx("div",{className:"mt-1.5 overflow-x-auto max-h-[200px] overflow-y-auto p-1.5 rounded",style:{backgroundColor:"var(--ds-gray-100)"},children:typeof e.output=="string"?t.jsx("pre",{className:"text-[10px]",style:{color:"var(--ds-gray-800)"},children:e.output}):t.jsx(Nt,{data:e.output,expandLevel:1})})]}):null}function Ko(e){switch(e){case"user":return{bg:"var(--ds-blue-100)",border:"var(--ds-blue-300)",label:"var(--ds-blue-700)"};case"assistant":return{bg:"var(--ds-gray-100)",border:"var(--ds-gray-300)",label:"var(--ds-gray-700)"};case"system":return{bg:"var(--ds-amber-100)",border:"var(--ds-amber-300)",label:"var(--ds-amber-700)"};case"tool":return{bg:"var(--ds-green-50)",border:"var(--ds-green-300)",label:"var(--ds-green-700)"};default:return{bg:"var(--ds-gray-100)",border:"var(--ds-gray-300)",label:"var(--ds-gray-700)"}}}function Uo(e){return typeof e=="string"?[{type:"text",text:e}]:Array.isArray(e)?e.map(s=>typeof s=="string"?{type:"text",text:s}:(s==null?void 0:s.type)==="text"?{type:"text",text:String(s.text??"")}:(s==null?void 0:s.type)==="tool-call"?{type:"tool-call",toolName:s.toolName,input:s.input}:(s==null?void 0:s.type)==="tool-result"?{type:"tool-result",toolName:s.toolName,output:s.output}:{type:"text",text:""}):[]}const Go=e=>{if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean"||e===null)return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}};function ur({data:e}){const s=Ge();return t.jsxs("div",{className:"relative overflow-x-auto rounded-md border p-3 pt-9",style:{borderColor:"var(--ds-gray-300)"},children:[t.jsx("button",{type:"button","aria-label":"Copy data",title:"Copy",className:"!absolute !right-2 !top-2 !flex !h-6 !w-6 !items-center !justify-center !rounded-md !border !bg-[var(--ds-background-100)] !text-[var(--ds-gray-800)] transition-transform transition-colors duration-100 hover:!bg-[var(--ds-gray-alpha-200)] active:!scale-95 active:!bg-[var(--ds-gray-alpha-300)]",style:{borderColor:"var(--ds-gray-300)"},onClick:()=>{navigator.clipboard.writeText(Go(e)).then(()=>{s.success("Copied to clipboard")}).catch(()=>{s.error("Failed to copy")})},children:t.jsx(rt,{size:12})}),t.jsx(Nt,{data:e})]})}function ie({summary:e,children:s,onToggle:r,disabled:n=!1,summaryClassName:o,contentClassName:a}){return n?t.jsx("div",{className:`rounded-md border px-2.5 py-1.5 text-xs ${o??""}`,style:{borderColor:"var(--ds-gray-300)",backgroundColor:"var(--ds-gray-100)",color:"var(--ds-gray-700)",cursor:"not-allowed",opacity:.8},children:e}):t.jsxs("details",{className:"group",onToggle:i=>r==null?void 0:r(i.target.open),children:[t.jsx("summary",{className:`cursor-pointer rounded-md border px-2.5 py-1.5 text-xs hover:brightness-95 [&::-webkit-details-marker]:hidden ${o??""}`,style:{borderColor:"var(--ds-gray-300)",backgroundColor:"var(--ds-gray-100)",color:"var(--ds-gray-900)",listStyle:"none"},children:t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(es,{size:14,className:"shrink-0 transition-transform group-open:rotate-90"}),e]})}),t.jsxs("div",{className:`relative pl-6 mt-3 ${a??""}`,children:[t.jsx("div",{className:"absolute left-3 -top-3 w-px h-3",style:{backgroundColor:"var(--ds-gray-400)"}}),t.jsx("div",{className:"absolute left-3 top-0 w-3 h-3 border-l border-b rounded-bl-lg",style:{borderColor:"var(--ds-gray-400)"}}),t.jsx("div",{className:"absolute left-6 top-3 w-0 h-px -translate-y-px",style:{backgroundColor:"var(--ds-gray-400)"}}),t.jsx("div",{children:s})]})]})}function qo({active:e,onClick:s,children:r}){return t.jsx("button",{type:"button",role:"tab","aria-selected":e,tabIndex:e?0:-1,onClick:s,className:"px-3 py-1.5 text-[11px] font-medium transition-colors -mb-px",style:{backgroundColor:"transparent",borderTop:"none",borderLeft:"none",borderRight:"none",borderBottom:`2px solid ${e?"var(--ds-blue-600)":"transparent"}`,borderRadius:0,outline:"none",boxShadow:"none",cursor:"pointer",color:e?"var(--ds-gray-1000)":"var(--ds-gray-600)"},children:r})}function Zo({tabs:e,activeTab:s,onTabChange:r,ariaLabel:n,children:o}){const a=c.useCallback(i=>{if(i.key!=="ArrowRight"&&i.key!=="ArrowLeft")return;i.preventDefault();const l=e.findIndex(d=>d.id===s),p=i.key==="ArrowRight"?(l+1)%e.length:(l-1+e.length)%e.length;r(e[p].id)},[e,s,r]);return t.jsxs("div",{className:"rounded-md border",style:{borderColor:"var(--ds-gray-300)",backgroundColor:"transparent"},children:[t.jsx("div",{className:"flex gap-1 border-b",role:"tablist","aria-label":n,onKeyDown:a,style:{borderColor:"var(--ds-gray-300)",backgroundColor:"transparent"},children:e.map(i=>t.jsx(qo,{active:s===i.id,onClick:()=>r(i.id),children:i.label},i.id))}),t.jsx("div",{role:"tabpanel",children:o})]})}const Yo=[{id:"conversation",label:"Conversation"},{id:"json",label:"Raw JSON"}];function Xo({conversation:e,args:s}){const[r,n]=c.useState("conversation");return t.jsx(ie,{summary:`Input (${e.length} messages)`,children:t.jsx(Zo,{tabs:Yo,activeTab:r,onTabChange:n,ariaLabel:"Conversation view",children:r==="conversation"?t.jsx(Bo,{messages:e}):t.jsx("div",{className:"p-3",children:Array.isArray(s)?s.map((o,a)=>t.jsx("div",{className:"mt-2 first:mt-0",children:le(o)},a)):le(s)})})})}function Xe(){return t.jsxs("div",{className:"flex items-center gap-1.5 rounded-md border px-3 py-2 text-xs",style:{borderColor:"var(--ds-gray-300)",backgroundColor:"var(--ds-gray-100)",color:"var(--ds-gray-700)"},children:[t.jsx(er,{className:"h-3 w-3"}),t.jsx("span",{className:"font-medium",children:"Encrypted"})]})}function le(e){return t.jsx(ur,{data:e})}const Ce=e=>e==null?!1:typeof e=="string"?e.trim().length>0:Array.isArray(e)?e.length>0:typeof e=="object"?Object.keys(e).length>0:!0,ys=["workflowName","moduleSpecifier","stepName","status","stepId","hookId","eventId","runId","attempt","token","receivedCount","lastReceivedAt","disposedAt","correlationId","eventType","deploymentId","specVersion","workflowCoreVersion","ownerId","projectId","environment","executionContext","createdAt","startedAt","updatedAt","completedAt","expiredAt","retryAfter","error","metadata","eventData","input","output","resumeAt"],Wt=(e,s)=>{const r=ys.indexOf(e)||0,n=ys.indexOf(s)||0;return r-n},Jo={workflowCoreVersion:"@workflow/core version",receivedCount:"times resolved"},Qo=e=>Jo[e]??e,ea=e=>{const s=String(e),r=nt(s);if(r)return r.moduleSpecifier;const n=Te(s);return n?n.moduleSpecifier:s},as=e=>{if(e==null)return null;if(e instanceof Date)return Number.isNaN(e.getTime())?null:e;if(typeof e=="string"&&e.trim().length===0)return null;const s=typeof e=="number"?new Date(e):new Date(String(e));return Number.isNaN(s.getTime())?null:s},is=e=>e.toLocaleString(void 0,{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",fractionalSecondDigits:3}),ta=e=>{const s=as(e);return s?is(s):"-"},bs=e=>{const s=as(e);return s?is(s):null},Le=e=>{const s=as(e);return s?t.jsx(ir,{date:s,children:t.jsx("span",{children:is(s)})}):null},et={workflowName:e=>{var s;return((s=Te(String(e)))==null?void 0:s.shortName)??"?"},moduleSpecifier:e=>ea(e),stepName:e=>{var s;return((s=nt(String(e)))==null?void 0:s.shortName)??"?"},runId:e=>String(e),stepId:e=>String(e),hookId:e=>String(e),eventId:e=>String(e),status:e=>String(e),attempt:e=>String(e),token:e=>String(e),isWebhook:e=>String(e),receivedCount:e=>String(e),lastReceivedAt:bs,disposedAt:bs,eventType:e=>String(e),correlationId:e=>String(e),deploymentId:e=>String(e),specVersion:e=>String(e),workflowCoreVersion:e=>String(e),ownerId:e=>null,projectId:e=>null,environment:e=>null,executionContext:e=>null,createdAt:Le,startedAt:Le,updatedAt:Le,completedAt:Le,expiredAt:Le,retryAfter:Le,resumeAt:Le,metadata:e=>Ce(e)?ge(e)?t.jsx(Xe,{}):le(e):null,input:(e,s)=>{if(ge(e))return t.jsx(Xe,{});if(e&&typeof e=="object"&&"args"in e){const{args:o,closureVars:a,thisVal:i}=e,l=Array.isArray(o)?o.length:0,p=l===1?"argument":"arguments",d=Ce(a),h=Ce(i),u=Ce(o);if(s!=null&&s.stepName&&Hn(s.stepName)){const f=Bn(o);if(f&&f.length>0)return t.jsxs(t.Fragment,{children:[t.jsx(Xo,{conversation:f,args:o}),d&&t.jsx(ie,{summary:"Closure Variables",children:le(a)}),h&&t.jsx(ie,{summary:"This Value",children:le(i)})]})}return!u&&!d&&!h?t.jsx(ie,{summary:"Input (no data)",disabled:!0,summaryClassName:"text-base py-2"}):t.jsxs(t.Fragment,{children:[t.jsx(ie,{summary:`Input (${l} ${p})`,summaryClassName:"text-base py-2",contentClassName:"mt-0",children:Array.isArray(o)?o.map((f,m)=>t.jsx("div",{className:"mt-2 first:mt-0",children:le(f)},m)):le(o)}),d&&t.jsx(ie,{summary:"Closure Variables",children:le(a)}),h&&t.jsx(ie,{summary:"this",children:le(i)})]})}const r=Array.isArray(e)?e.length:0,n=r===1?"argument":"arguments";return Ce(e)?t.jsx(ie,{summary:`Input (${r} ${n})`,summaryClassName:"text-base py-2",contentClassName:"mt-0",children:Array.isArray(e)?e.map((o,a)=>t.jsx("div",{className:"mt-2 first:mt-0",children:le(o)},a)):le(e)}):t.jsx(ie,{summary:"Input (no data)",disabled:!0,summaryClassName:"text-base py-2"})},output:e=>Ce(e)?ge(e)?t.jsx(Xe,{}):t.jsx(ie,{summary:"Output",summaryClassName:"text-base py-2",contentClassName:"mt-0",children:le(e)}):null,error:e=>ge(e)?t.jsx(Xe,{}):Ce(e)?tt(e)?t.jsx(ie,{summary:"Error",summaryClassName:"text-base py-2",contentClassName:"mt-0",children:t.jsx(St,{value:e})}):t.jsx(ie,{summary:"Error",summaryClassName:"text-base py-2",contentClassName:"mt-0",children:le(e)}):null,eventData:e=>ge(e)?t.jsx(Xe,{}):Ce(e)?t.jsx(ie,{summary:"Event Data",children:le(e)}):null},ws=["input","output","error","metadata","eventData"],sa=()=>t.jsx("div",{className:"text-copy-12 rounded-md border p-4 my-2",style:{borderColor:"var(--ds-gray-300)",backgroundColor:"var(--ds-gray-100)",color:"var(--ds-gray-700)"},children:t.jsx("span",{children:"The data for this run has expired and is no longer available."})}),ra=({attribute:e,value:s,isLoading:r,inline:n=!1,context:o})=>{if(r&&(e==="input"||e==="output"||e==="eventData"))return t.jsxs("div",{className:`my-2 flex flex-col ${e==="input"||e==="output"?"gap-2 my-3.5":"gap-0"}`,children:[t.jsx("span",{className:`${e==="input"||e==="output"?"text-base":"text-xs"} font-medium first-letter:uppercase`,style:{color:"var(--ds-gray-700)"},children:e}),t.jsx(Q,{className:"h-9 w-full rounded-md"})]});const i=et[e];if(!i)return null;const l=i(s,o);return l?n?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-[11px] font-medium",style:{color:"var(--ds-gray-700)"},children:e}),t.jsx("span",{className:"text-[11px]",style:{color:"var(--ds-gray-1000)"},children:l})]}):t.jsxs("div",{className:"relative",children:[typeof r=="boolean"&&r&&t.jsx("div",{className:"absolute top-9 right-4",children:t.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2",style:{borderColor:"var(--ds-gray-900)"}})}),t.jsxs("div",{className:`my-2 flex flex-col ${e==="input"||e==="output"||e==="error"?"gap-2 my-3.5":"gap-0"}`,children:[t.jsx("span",{className:`${e==="input"||e==="output"||e==="error"?"text-base":"text-xs"} font-medium first-letter:uppercase`,style:{color:"var(--ds-gray-700)"},children:e}),t.jsx("span",{className:"text-xs",style:{color:"var(--ds-gray-1000)"},children:l})]},e)]}):null},na=({data:e,moduleSpecifier:s,isLoading:r,error:n,expiredAt:o,onStreamClick:a,resource:i})=>{const l=Ge(),p=c.useMemo(()=>{const x={...e},y=e.executionContext;return y!=null&&y.workflowCoreVersion&&(x.workflowCoreVersion=y.workflowCoreVersion),s?x.moduleSpecifier=s:typeof e.stepName=="string"?x.moduleSpecifier=e.stepName:typeof e.workflowName=="string"&&(x.moduleSpecifier=e.workflowName),x},[e,s]),d=o!=null&&new Date(o)<new Date,h=Object.keys(p).filter(x=>!ws.includes(x)).sort(Wt),u=c.useMemo(()=>{const x=Object.keys(p).filter(v=>ws.includes(v)).sort(Wt);if(!r)return x;const y=["input","output"];for(const v of y)x.includes(v)||x.push(v);return x.sort(Wt)},[p,r]),f=h.filter(x=>{const y=et[x];return y?y(p[x])!==null:!1}),m=c.useMemo(()=>{const x=[...f],y=x.indexOf("moduleSpecifier");if(y===-1)return x;x.splice(y,1);const v=x.indexOf("workflowName");if(v!==-1)return x.splice(v+1,0,"moduleSpecifier"),x;const N=x.indexOf("stepName");return N!==-1?(x.splice(N+1,0,"moduleSpecifier"),x):(x.unshift("moduleSpecifier"),x)},[f]),w=c.useMemo(()=>({stepName:p.stepName}),[p.stepName]),b=c.useCallback(x=>{navigator.clipboard.writeText(x).then(()=>{l.success("moduleSpecifier copied")}).catch(()=>{l.error("Failed to copy moduleSpecifier")})},[]);return t.jsx($n.Provider,{value:a,children:t.jsxs("div",{children:[f.length>0&&t.jsxs("div",{className:"mb-3 flex flex-col overflow-hidden rounded-lg border",style:{borderColor:"var(--ds-gray-300)"},children:[m.map((x,y)=>{var S;const v=(S=et[x])==null?void 0:S.call(et,p[x]),N=x==="moduleSpecifier",g=typeof v=="string"?v:String(v??p.moduleSpecifier??""),k=x!=="workflowCoreVersion",C=r&&i==="sleep"&&!p.resumeAt,I=y<m.length-1||C;return t.jsxs("div",{className:"py-1",children:[t.jsxs("div",{className:"flex min-h-[32px] items-center justify-between gap-4 rounded-sm px-2.5 py-1",children:[t.jsx("span",{className:k?"text-[14px] first-letter:uppercase":"text-[14px]",style:{color:"var(--ds-gray-700)"},children:Qo(x)}),N?t.jsx("button",{type:"button",className:"min-w-0 max-w-[70%] truncate text-right text-[13px] font-mono",style:{color:"var(--ds-gray-1000)",background:"transparent",border:"none",padding:0},title:g,onClick:()=>b(g),children:g}):t.jsx("span",{className:"min-w-0 max-w-[70%] truncate text-right text-[13px] font-mono",style:{color:"var(--ds-gray-1000)"},children:v})]}),I?t.jsx("div",{className:"mx-2.5 border-b",style:{borderColor:"var(--ds-gray-300)"}}):null]},x)}),r&&i==="sleep"&&!p.resumeAt&&t.jsx("div",{className:"py-1",children:t.jsxs("div",{className:"flex min-h-[32px] items-center justify-between gap-4 rounded-sm px-2.5 py-1",children:[t.jsx("span",{className:"text-[14px] first-letter:uppercase",style:{color:"var(--ds-gray-700)"},children:"resumeAt"}),t.jsx(Q,{className:"h-4 w-[55%]"})]})})]}),n?t.jsx(qs,{title:"Failed to load resource details",details:n.message,className:"my-4"}):d?t.jsx(sa,{}):t.jsx(t.Fragment,{children:u.map(x=>t.jsx(ra,{isLoading:r,attribute:x,value:p[x],context:w},x))})]})})},oa=new Set(["step_failed","step_retrying"]),aa=new Set(["step_created","step_completed","step_failed","step_retrying","hook_created","hook_received","run_created","run_completed","run_failed","wait_created","wait_completed"]);function ia({event:e,onLoadEventData:s,encryptionKey:r}){const[n,o]=c.useState(null),[a,i]=c.useState(!1),[l,p]=c.useState(null),d=c.useRef(!1),h="eventData"in e&&e.eventData!=null?e.eventData:null,u=h??n,f=aa.has(e.eventType),m=c.useCallback(async()=>{if(!(!s||!e.correlationId||!e.eventId))try{i(!0),p(null);const x=await s(e.correlationId,e.eventId);o(x)}catch(x){p(x instanceof Error?x.message:String(x))}finally{i(!1)}},[s,e.correlationId,e.eventId]),w=c.useCallback(async()=>{h||n!==null||a||(d.current=!0,await m())},[h,n,a,m]);c.useEffect(()=>{r&&d.current&&n!==null&&(o(null),m())},[r]);const b=new Date(e.createdAt);return t.jsxs(ie,{summaryClassName:"text-base py-2",summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"font-medium",style:{color:"var(--ds-gray-1000)"},children:e.eventType})," ","-"," ",t.jsx("span",{style:{color:"var(--ds-gray-700)"},children:ta(b.getTime())})]}),onToggle:f?x=>{x&&w()}:void 0,children:[t.jsxs("div",{className:"flex flex-col divide-y rounded-md border overflow-hidden",style:{borderColor:"var(--ds-gray-300)",backgroundColor:"var(--ds-gray-100)"},children:[t.jsxs("div",{className:"flex min-h-[32px] items-center justify-between gap-4 px-2.5 py-1.5",style:{borderColor:"var(--ds-gray-300)"},children:[t.jsx("span",{className:"text-[14px]",style:{color:"var(--ds-gray-700)"},children:"eventId"}),t.jsx("span",{className:"max-w-[70%] truncate text-right text-[13px] font-mono",style:{color:"var(--ds-gray-1000)"},title:e.eventId,children:e.eventId})]}),e.correlationId&&t.jsxs("div",{className:"flex min-h-[32px] items-center justify-between gap-4 px-2.5 py-1.5",style:{borderColor:"var(--ds-gray-300)"},children:[t.jsx("span",{className:"text-[14px]",style:{color:"var(--ds-gray-700)"},children:"correlationId"}),t.jsx("span",{className:"max-w-[70%] truncate text-right text-[13px] font-mono",style:{color:"var(--ds-gray-1000)"},title:e.correlationId,children:e.correlationId})]})]}),a&&t.jsxs("div",{className:"mt-2 rounded-md border p-3",style:{borderColor:"var(--ds-gray-300)"},children:[t.jsx(Q,{className:"h-4 w-[35%]"}),t.jsx(Q,{className:"mt-2 h-4 w-[90%]"}),t.jsx(Q,{className:"mt-2 h-4 w-[75%]"})]}),l&&t.jsx(qs,{title:"Failed to load event data",details:l,className:"mt-2"}),u!=null&&t.jsx("div",{className:"mt-2",children:t.jsx(la,{eventType:e.eventType,data:u})})]})}function la({eventType:e,data:s}){if(oa.has(e)&&s!=null&&typeof s=="object"){const r=s;if(tt(r.error))return t.jsx(St,{value:r.error});if(tt(r))return t.jsx(St,{value:r})}return t.jsx(ur,{data:s})}function ca({events:e,isLoading:s=!1,error:r,onLoadEventData:n,encryptionKey:o}){const a=c.useMemo(()=>[...e].sort((i,l)=>new Date(i.createdAt).getTime()-new Date(l.createdAt).getTime()),[e]);return t.jsxs("div",{className:"mt-2",style:{color:"var(--ds-gray-1000)"},children:[t.jsxs("h3",{className:"text-heading-16 font-medium mt-4 mb-2",style:{color:"var(--ds-gray-1000)"},children:["Events ",!s&&`(${a.length})`]}),s?t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx(Q,{className:"h-9 w-full rounded-md"}),t.jsx(Q,{className:"h-9 w-full rounded-md"}),t.jsx(Q,{className:"h-9 w-full rounded-md"})]}):null,!s&&!r&&a.length===0&&t.jsx("div",{className:"text-sm",children:"No events found"}),a.length>0&&!r?t.jsx("div",{className:"flex flex-col gap-4",children:a.map(i=>t.jsx(ia,{event:i,onLoadEventData:n,encryptionKey:o},i.eventId))}):null]})}function da(e){return e!==null&&typeof e=="object"&&"stepId"in e}function ua(e){return e!==null&&typeof e=="object"&&"runId"in e}function gt(e){return e!==null&&typeof e=="object"&&"hookId"in e}function fa({run:e,onStreamClick:s,spanDetailData:r,spanDetailError:n,spanDetailLoading:o,onSpanSelect:a,onWakeUpSleep:i,onLoadEventData:l,onResolveHook:p,encryptionKey:d,onDecrypt:h,isDecrypting:u=!1,selectedSpan:f}){const m=Ge(),[w,b]=c.useState(!1),[x,y]=c.useState(!1),[v,N]=c.useState(!1),[g,k]=c.useState(new Set),C=f==null?void 0:f.data,I=f==null?void 0:f.rawEvents,S=(I==null?void 0:I.length)??0,{resource:j,resourceId:E,runId:M}=c.useMemo(()=>{if(!f)return{resource:void 0,resourceId:void 0,runId:void 0};const _=f.resource;if(_==="step"&&da(C))return{resource:"step",resourceId:C.stepId,runId:C.runId};if(_==="run"&&ua(C))return{resource:"run",resourceId:C.runId,runId:void 0};if(_==="hook"&&gt(C))return{resource:"hook",resourceId:C.hookId,runId:void 0};if(_==="sleep"){const H=C;return{resource:"sleep",resourceId:f.spanId,runId:H==null?void 0:H.runId}}return{resource:void 0,resourceId:void 0,runId:void 0}},[f,C]),D=c.useRef(a);D.current=a,c.useEffect(()=>{j&&E&&["run","step","hook","sleep"].includes(j)&&D.current({resource:j,resourceId:E,runId:M})},[j,E,M]);const A=c.useMemo(()=>j!=="sleep"||!I||["completed","failed","cancelled"].includes(e.status)||!I.some(ee=>ee.eventType==="wait_created")?!1:!I.some(ee=>ee.eventType==="wait_completed"),[j,I,S,e.status]),P=c.useMemo(()=>!(j!=="hook"||!I||!E||g.has(E)||["completed","failed","cancelled"].includes(e.status)||I.some(V=>V.eventType==="hook_disposed")),[j,E,I,S,e.status,g]),U=n??void 0,O=o??!1,L=c.useMemo(()=>{if(!r)return!1;const _=r;return ge(_.input)||ge(_.output)||ge(_.error)||ge(_.metadata)},[r]),T=c.useMemo(()=>{if(!(j!=="hook"||!E)){if(gt(r)&&r.token)return r.token;if(gt(C)&&C.token)return C.token}},[j,E,r,C]);c.useEffect(()=>{U&&f&&j&&m.error(`Failed to load ${j} details`,{description:U.message})},[U,j,f]);const F=async()=>{if(!(w||!E)){if(!i){m.error("Unable to wake up sleep",{description:"No wake-up handler provided."});return}try{b(!0),(await i(e.runId,E)).stoppedCount>0?m.success("Run woken up",{description:"The sleep call has been interrupted and the run woken up."}):m.info("Sleep already completed",{description:"This sleep call has already finished."})}catch(_){console.error("Failed to wake up run:",_),m.error("Failed to wake up run",{description:_ instanceof Error?_.message:"An unknown error occurred"})}finally{b(!1)}}},G=c.useCallback(async _=>{if(!v){if(!p){m.error("Unable to resolve hook",{description:"No resolve handler provided."});return}if(!T){m.error("Unable to resolve hook",{description:"Missing hook token. Try refreshing the run data and retry."});return}try{N(!0);const H=r??C,V=gt(H)?H:void 0;await p(T,_,V),m.success("Hook resolved",{description:"The payload has been sent and the hook resolved."}),y(!1),E&&k(ee=>new Set(ee).add(E))}catch(H){console.error("Failed to resolve hook:",H),m.error("Failed to resolve hook",{description:H instanceof Error?H.message:"An unknown error occurred"})}finally{N(!1)}}},[p,T,v,r,C]),B=r??C,q=c.useMemo(()=>{const _=B,H=_.stepName,V=_.workflowName;if(typeof H=="string")return H;if(typeof V=="string")return V;if(typeof e.workflowName=="string")return e.workflowName},[B,e.workflowName]);if(!f||!j||!E)return null;const X=j.charAt(0).toUpperCase()+j.slice(1),J=j==="sleep"&&A||j==="hook"&&P,R=e.completedAt?"Completed":"Live";return t.jsxs("div",{className:"flex h-full flex-col",children:[t.jsx("div",{className:"border-b px-3 py-3",style:{borderColor:"var(--ds-gray-200)"},children:t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"inline-flex items-center rounded-full border px-2 py-0.5 text-[13px] font-medium",style:{borderColor:"var(--ds-gray-300)",color:"var(--ds-gray-900)",backgroundColor:"var(--ds-background-100)"},children:X}),t.jsx("span",{className:"text-[13px]",style:{color:e.completedAt?"var(--ds-gray-700)":"var(--ds-green-800)"},children:R})]}),t.jsx("p",{className:"mt-1 truncate font-mono text-[13px]",style:{color:"var(--ds-gray-700)"},title:E,children:E})]}),(L||d)&&h&&t.jsx(os,{decrypted:!!d,loading:u,onClick:h})]})}),t.jsxs("div",{className:"flex-1 overflow-y-auto px-3 pt-3 pb-8",children:[J&&t.jsxs("div",{className:"mb-4 rounded-lg border p-2",style:{borderColor:"var(--ds-gray-300)",backgroundColor:"var(--ds-gray-100)"},children:[t.jsx("p",{className:"mb-2 px-1 text-[13px] font-medium uppercase tracking-wide",style:{color:"var(--ds-gray-700)"},children:"Actions"}),t.jsxs("div",{className:"flex flex-col gap-2",children:[j==="sleep"&&A&&t.jsxs("button",{type:"button",onClick:F,disabled:w,className:Pe("flex items-center justify-center gap-2 rounded-md px-3 py-2 text-sm font-medium","disabled:opacity-50 disabled:cursor-not-allowed transition-colors",w?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{background:"var(--ds-amber-200)",color:"var(--ds-amber-900)"},children:[t.jsx(rn,{className:"h-4 w-4"}),w?"Waking up...":"Wake Up Sleep"]}),j==="hook"&&P&&t.jsxs("button",{type:"button",onClick:()=>y(!0),disabled:v,className:Pe("flex items-center justify-center gap-2 rounded-md px-3 py-2 text-sm font-medium","disabled:opacity-50 disabled:cursor-not-allowed transition-colors",v?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{background:"var(--ds-gray-1000)",color:"var(--ds-background-100)"},children:[t.jsx(Zs,{className:"h-4 w-4"}),"Resolve Hook"]})]})]}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("section",{children:[t.jsx("h3",{className:"mb-2 text-[13px] font-medium uppercase tracking-wide",style:{color:"var(--ds-gray-700)"},children:"Details"}),t.jsx(na,{data:B,moduleSpecifier:q,expiredAt:e.expiredAt,isLoading:O,error:U??void 0,onStreamClick:s,resource:j})]}),j!=="run"&&I&&t.jsx("section",{children:t.jsx(ca,{events:I,onLoadEventData:l,encryptionKey:d})})]})]}),t.jsx(Ys,{isOpen:x,onClose:()=>y(!1),onSubmit:G,isSubmitting:v})]})}function pa(e){const s=c.useRef(e);s.current=e,c.useEffect(()=>{let r=0,n=0;const o=()=>{s.current(r),r=0},a=i=>{if(!i.ctrlKey&&!i.metaKey)return;i.preventDefault();let l=-i.deltaY;switch(i.deltaMode){case WheelEvent.DOM_DELTA_PAGE:l*=window.innerHeight;break;case WheelEvent.DOM_DELTA_LINE:l*=20;break}r+=l,cancelAnimationFrame(n),n=requestAnimationFrame(o)};return window.addEventListener("wheel",a,{passive:!1}),()=>{window.removeEventListener("wheel",a),cancelAnimationFrame(n)}},[])}function js(e){if(e<=0)return 1;const r=10**Math.floor(Math.log10(e)),n=e/r;return n<=1.5?r:n<=3.5?2*r:n<=7.5?5*r:10*r}function ma({scale:e,isLive:s=!1}){const{state:{root:r}}=be(),[,n]=c.useState(0);c.useEffect(()=>{if(!s)return;const f=setInterval(()=>n(m=>m+1),1e3);return()=>clearInterval(f)},[s]);const o=r.duration,a=e>0?e:o>0?1/o:1;let l=js(50/a);l=Math.max(1,l);let p=l*a;const d=1e3;o/l>d&&(l=js(o/d),p=l*a);const h=Math.ceil(o/l),u=Math.ceil(100/p)||1;return t.jsx("div",{className:K.markersContainer,children:t.jsx("div",{"aria-hidden":!0,className:K.markers,style:{width:Math.floor(r.duration*e+15),visibility:e!==-1?"visible":"hidden","--marker-width":`${p}px`},children:new Array(h).fill(null).map((f,m)=>{const w=m%u===0;return t.jsx("span",{className:Pe(K.marker,!w&&K.notch),children:w?t.jsxs("span",{className:K.markerLabel,children:[Vn(l*m),t.jsx("span",{className:K.markerClockTime,children:zn(r.startTime+l*m)})]}):null},String(m))})})})}function ha({events:e,root:s,scale:r}){const n=c.useMemo(()=>e.filter(o=>o.event.showVerticalLine!==!1),[e]);return t.jsx("div",{className:K.eventMarkersContainer,children:t.jsx("div",{"aria-hidden":!0,className:K.eventMarkers,style:{width:Math.floor(s.duration*r)},children:n.map(o=>t.jsx("span",{className:Pe(K.eventMarker),style:{left:Math.floor((o.timestamp-s.startTime)*r),...o.event.color&&{borderLeftColor:o.event.color}}},o.key))})})}const Ns=2;function xa({memoCacheRef:e,timelineRef:s,root:r,spans:n,events:o,scale:a,dispatch:i,scrollSnapshotRef:l}){const p=c.useRef(!1),d=c.useRef(n);d.current=n;const h=c.useRef(o);h.current=o;const u=c.useRef(null),{style:f,setStyle:m}=Lt(u),w=c.useRef(null),b=c.useRef(null),{style:x,setStyle:y}=Lt(b),v=c.useRef(void 0),N=c.useRef(null),{style:g,setStyle:k}=Lt(N),C=c.useRef(0);c.useEffect(()=>{const S=s.current;if(!S)return;let j=C.current,E=0,M=!1,D=!1,A=!1,P=!1,U=0,O=0;const L=Date.now()+500,T=()=>{v.current||(v.current=S.getBoundingClientRect())},F=Z=>v.current?(Z-kt-ce)/(Ve+Ee):0,G=()=>{const Z=e.current;for(const re of d.current)re.isHovered&&(re.isHovered=!1,Z.set(re.span.spanId,{}));i({type:"forceRender"})};let B=0;const q=()=>{var qe,at,it,xe,lt,ct,dt,ut;if(!p.current)return;v.current||T();const Z=v.current;if(!Z)return;const{scrollLeft:re,scrollTop:oe}=S,fe=Math.max(0,Math.min(j+re-Z.left-ce,r.duration*a)),$e=`${fe-re+ce}px`;y("left",$e),m("left",$e);const we=r.startTime+fe/a,Se=we-r.startTime;if(Se<0||Se>r.duration?(qe=w.current)==null||qe.removeAttribute("data-text"):(at=w.current)==null||at.setAttribute("data-text",ht(Se)),M){const De=j-E,Ze=Math.abs(De);if(!A){if(Ze<4)return;A=!0,k("display","flex"),G()}De>0?(k("left",""),k("right","0")):(k("left","0"),k("right","")),k("width",`${Ze}px`);const Re=Math.max(0,Math.min(E+re-Z.left-ce,r.duration*a))/a;let z,te;Re<Se?(z=Re,te=Se):(z=Se,te=Re),(it=N.current)==null||it.setAttribute("data-range",`${ht(z)} — ${ht(te)}`),(xe=N.current)==null||xe.setAttribute("data-duration",`${ht(te-z)} selected`)}if(Date.now()<L){B=requestAnimationFrame(q);return}if(re!==U||oe!==O){U=re,O=oe,B=requestAnimationFrame(q);return}if(j-Z.left<128?(lt=w.current)==null||lt.setAttribute("data-align","left"):j-Z.left>Z.width-128?(ct=w.current)==null||ct.setAttribute("data-align","right"):(dt=w.current)==null||dt.removeAttribute("data-align"),!A&&!D){const De=e.current,Ze=F(oe)-Ns,Mt=F(oe+Z.height)+Ns;for(const se of d.current){const ae=se.row>=Ze&&se.row<=Mt&&we>=se.startTime&&we<=se.endTime;se.isHovered!==ae&&(se.isHovered=ae,De.set(se.span.spanId,{}))}const z=12/a;let te=null,ne=1/0;for(const se of h.current){const ae=Math.abs(se.timestamp-we);ae<=z&&ae<ne&&(ne=ae,te=se)}for(const se of h.current){const ae=se===te;if(se.isHovered===ae)continue;se.isHovered=ae;const Ye=(ut=se.ref)==null?void 0:ut.current;Ye&&Ye.setAttribute("data-hovered",String(ae))}i({type:"forceRender"})}};B=requestAnimationFrame(q);const X=Z=>{Z.pointerType==="mouse"&&(p.current=!0)},J=()=>{p.current&&(p.current=!1,G())},R=({clientX:Z})=>{j=Z,C.current=j,cancelAnimationFrame(B),B=requestAnimationFrame(q)},_=Z=>{Z.preventDefault()},H=Z=>{var re;if(Z.button===2)P=!0,Z.preventDefault();else{if(Z.button!==0)return;P=!1}(re=s.current)!=null&&re.contains(Z.target)?(E=j,M=!0):(D=!0,requestAnimationFrame(G))},V=Z=>{if(D=!1,!M||(M=!1,!A))return;if(A=!1,k("display",""),k("left",""),k("right",""),k("width",""),Z.preventDefault(),Z.stopImmediatePropagation(),P){P=!1;return}v.current||T();const re=v.current;if(!re)return;const{scrollLeft:oe}=S,fe=Math.max(0,Math.min((E+oe-re.left-ce)/a,r.duration)),$e=Math.max(0,Math.min((j+oe-re.left-ce)/a,r.duration));i({type:"scaleToRange",t1:fe+r.startTime,t2:$e+r.startTime})},ee=Z=>{M&&Z.key==="Escape"&&(P=!0,V(Z))},$=()=>{v.current=void 0,I.current=void 0,cancelAnimationFrame(B),B=requestAnimationFrame(q)},W=()=>{cancelAnimationFrame(B),B=requestAnimationFrame(q)},Y=new ResizeObserver(()=>{v.current=void 0});return Y.observe(S),window.addEventListener("mousemove",R),S.addEventListener("contextmenu",_),window.addEventListener("mousedown",H),window.addEventListener("mouseup",V),window.addEventListener("blur",V),window.addEventListener("keydown",ee,!0),window.addEventListener("scroll",$),S.addEventListener("scroll",W),S.addEventListener("pointerenter",X),S.addEventListener("pointerleave",J),()=>{Y.disconnect(),window.removeEventListener("mousemove",R),S.removeEventListener("contextmenu",_),window.removeEventListener("mousedown",H),window.removeEventListener("mouseup",V),window.removeEventListener("blur",V),window.removeEventListener("keydown",ee,!0),window.removeEventListener("scroll",$),S.removeEventListener("scroll",W),S.removeEventListener("pointerenter",X),S.removeEventListener("pointerleave",J),cancelAnimationFrame(B),C.current=j,G()}},[i,r,a,y,m,k,e,s,l]);const I=c.useRef(void 0);return pa(S=>{const j=s.current;if(!j)return;v.current??(v.current=j.getBoundingClientRect());const E=v.current,M=Math.max(0,Math.min(C.current-E.left-ce,E.width-2*ce));let D=0,A=I.current;(A==null?void 0:A.anchorX)===M?D=A.anchorT:(D=(j.scrollLeft+M)/a,A={anchorT:D,anchorX:M},I.current=A),i({type:"trackpadScale",delta:S/64,anchorT:D,anchorX:M})}),t.jsxs(t.Fragment,{children:[t.jsx("div",{className:K.cursorMarkerStickyParent,children:t.jsx("div",{className:K.cursorMarkerLabelContainer,ref:u,style:f,children:t.jsx("div",{className:K.cursorMarkerLabel,ref:w})})}),t.jsx("div",{className:K.cursorMarkerStickyParent,children:t.jsx("div",{className:K.cursorMarkerContainer,ref:b,style:x,children:t.jsx("div",{className:K.cursorMarker,children:t.jsx("div",{className:K.cursorSelection,ref:N,style:g})})})})]})}function ga({height:e,width:s,value:r,placeholder:n,onChange:o}){return t.jsxs("label",{className:K.searchInputLabel,children:[t.jsx("div",{className:K.searchInputPrefix,children:t.jsx(va,{})}),t.jsx("input",{type:"search",value:r,placeholder:n,onChange:o,style:{height:e,width:s}})]})}function va(){return t.jsxs("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",focusable:"false",children:[t.jsx("circle",{cx:"7",cy:"7",r:"4.5",stroke:"currentColor",strokeWidth:"1.5"}),t.jsx("path",{d:"M11.5 11.5L14 14",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}function ya(){return t.jsx("nav",{className:K.searchBar,children:t.jsx(ba,{})})}function ba(){const{dispatch:e}=be(),[s,r]=c.useState("");return c.useEffect(()=>{const n=setTimeout(()=>e({type:"setFilter",filter:s}),100);return()=>{clearTimeout(n)}},[e,s]),t.jsx("div",{className:K.searchInput,children:t.jsx(ga,{height:tr,onChange:n=>r(n.target.value),placeholder:"Search spans…",value:s,width:"100%"})})}function wa({size:e=16}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none","aria-hidden":!0,children:[t.jsx("title",{children:"Zoom In"}),t.jsx("path",{d:"M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16Z",stroke:"currentColor",strokeWidth:"2"}),t.jsx("path",{d:"M11 8v6M8 11h6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),t.jsx("path",{d:"M20 20l-3.5-3.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}function ja({size:e=16}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none","aria-hidden":!0,children:[t.jsx("title",{children:"Zoom Out"}),t.jsx("path",{d:"M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16Z",stroke:"currentColor",strokeWidth:"2"}),t.jsx("path",{d:"M8 11h6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),t.jsx("path",{d:"M20 20l-3.5-3.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}function Na({size:e=16}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none","aria-hidden":!0,children:[t.jsx("title",{children:"Minus"}),t.jsx("path",{d:"M6 12h12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}function ka(){const{dispatch:e}=be(),s=c.useCallback(()=>{e({type:"adjustScaleRatio",direction:1})},[e]),r=c.useCallback(()=>{e({type:"adjustScaleRatio",direction:-1})},[e]),n=c.useCallback(()=>{e({type:"adjustScaleRatio",direction:0})},[e]);return t.jsxs("div",{className:K.zoomButtonGroup,children:[t.jsx("button",{"aria-label":"Zoom Out",className:K.zoomButton,onClick:r,type:"button",children:t.jsx(ja,{size:18})}),t.jsx("div",{className:K.divider}),t.jsx("button",{"aria-label":"Reset Zoom",className:K.zoomButton,onClick:n,type:"button",children:t.jsx(Na,{size:18})}),t.jsx("div",{className:K.divider}),t.jsx("button",{"aria-label":"Zoom In",className:K.zoomButton,onClick:s,type:"button",children:t.jsx(wa,{size:18})})]})}const Sa=e=>{const{spans:s}=e,r={startTime:0,endTime:0,duration:0,depth:0,children:[]},n={},o=new Map,a=u=>{const f=o.get(u);if(f)return f;const m=o.size+1;return o.set(u,m),m};let i=!1;for(const u of s){const f=Qe(u.startTime),m=Qe(u.endTime),w=Qe(u.duration);m>r.endTime&&(r.endTime=m,r.duration=m-r.startTime),(r.startTime===0||f<r.startTime)&&(r.startTime=f,r.duration=r.endTime-f);const b=u.resource.startsWith("vercel.");b||(i=!0);const x=b&&(u.resource!=="vercel.serverless-runtime"||!("http.method"in u.attributes)),y=x?0:a(u.resource);let v;x&&(v=`▲ ${u.name}`),n[u.spanId]={parent:null,startTime:f,endTime:m,duration:w,span:u,depth:0,label:v,events:Ca(u),isVercel:x,children:[],resourceIndex:y,activeStartTime:u.activeStartTime?Qe(u.activeStartTime):void 0}}const l=(u,f)=>{let m;f?(m=n[f],m||(m=r)):m=r,u.parent=m,m.children.push(u)},p=u=>{"parent"in u&&(u.depth=u.parent.depth+1);for(const f of u.children)p(f)};let d=1;const h=(u,f)=>{if("parent"in u&&u.span.name===f){let m=u.endTime;const w=C=>C.children.length?C.children.map(w).sort((I,S)=>I.duration-S.duration)[0]||C:C.span.name==="waitUntil"?(m=C.startTime,C.parent):C,b=w(u),x=`instrumentation-hint-${d++}`,y=u.duration*.05,v=u.startTime+y,N=Math.max(v+y,Math.min(m-u.duration*.01,u.endTime-y)),g=N-v,k={parent:b,startTime:v,endTime:N,duration:g,span:{spanId:x,name:"Add your spans here",resource:"",kind:0,library:{name:""},status:{code:200},traceFlags:0,attributes:{},links:[],events:[],startTime:Ot(v),endTime:Ot(N),duration:Ot(g)},depth:u.depth+1,isVercel:!1,isInstrumentationHint:!0,children:[],resourceIndex:1};return b.children.push(k),n[x]=k,!0}for(const m of u.children)if(h(m,f))return!0;return!1};for(const u of Object.values(n))l(u,u.span.parentSpanId);if(p(r),!i){for(const u of["Invoke Function","Invoke Middleware","Vercel Runtime"])if(h(r,u))break}return{root:r,map:n}},Ca=e=>{if(!e.events.length)return;const s=`${e.spanId}:ev`;return e.events.map((r,n)=>({key:`${s}${n}`,timestamp:Qe(r.timestamp),event:r})).sort((r,n)=>r.timestamp-n.timestamp)},ks=(e,s)=>(e.isVisible=!0,e.isHovered=!1,e.isVisible);function $t(){return[]}const Ia=(e,s=!1)=>{const{state:r,dispatch:n}=be(),{root:o,filter:a,scale:i,timelineRef:l,timelineWidth:p,spanMap:d,scrollSnapshotRef:h,selected:u,memoCacheRef:f}=r,m=Ea(r.timelineHeight),w=c.useRef(0),[b,x]=c.useState($t),[y,v]=c.useState($t),[N,g]=c.useState($t),[k,C]=c.useState(-1),I=c.useRef(void 0);return c.useEffect(()=>{var S;return(S=I.current)==null?void 0:S.call(I,a)},[a]),c.useEffect(()=>{if(e!=null&&e.length){for(const S of b)for(const j of S){const E=e.includes(j.span.spanId);j.isHighlighted!==E&&(j.isHighlighted=E,f.current.set(j.span.spanId,{}))}n({type:"forceRender"})}},[b,e,n,f]),c.useEffect(()=>{if(!o.startTime)return;const S=new Worker(new URL("/assets/worker-D-HfgUMl.js",import.meta.url),{type:"module"});let j=++w.current;const E=D=>{var P;const A=D.data;switch(A.type){case"setRowsResult":{if((A==null?void 0:A.requestId)!==j)return;if(A.isEnd)for(const U of A.rows)for(const O of U)O.span=((P=d[O.span.spanId])==null?void 0:P.span)??O.span;x(A.rows);break}case"updateHighlight":{if((A==null?void 0:A.requestId)!==j)return;const{matches:U}=A;x(O=>{for(const L of O)for(const T of L){const F=U.has(T.span.spanId);T.isHighlighted!==F&&(T.isHighlighted=F,f.current.set(T.span.spanId,{}))}return O}),n({type:"forceRender"});break}}};S.addEventListener("message",E);const M={requestId:j,type:"calculateSpanPositions",root:o};return S.postMessage(M),I.current=D=>{const A=D.trim().toLocaleLowerCase();if(!A){x(U=>U.map(O=>O.map(L=>(L.isHighlighted=void 0,{...L}))));return}j=++w.current;const P={type:"filterSpans",requestId:j,root:o,filter:A};S.postMessage(P)},()=>{S.terminate()}},[o,d,n,f]),c.useEffect(()=>{if(!b.length)return;if(s){const R=[],_=[];for(const H of b)for(const V of H)ks(V)&&(R.push(V),V.events&&_.push(...V.events));v(R),g(_),C(i);return}const S=l.current;let j=h.current,E=!1,M=!1,D=0,A=0;const P=Math.max(500,p*.5),U=new Array(b.length).fill(null),O=()=>{M=!0;const R=Math.min(1+A+Math.ceil((j==null?void 0:j.endRow)??Number.POSITIVE_INFINITY),b.length);for(let _=R;_--;){if(U[_])continue;const H=L(_);if(Math.abs(H)>A){if(M=!1,H>0)continue;break}const V=[],ee=b[_];if(ee){for(const $ of ee){if(!ks($))continue;const W=T($);D=Math.max(W,D),V.push({d:W,span:$})}U[_]=V}}},L=R=>j?R<j.startRow?R-j.startRow:R>j.endRow?R-j.endRow:0:0,T=R=>{if(!j)return 0;let _=0;R.endTime<j.startTime?_=j.startTime-R.endTime:R.startTime>j.endTime&&(_=R.startTime-j.endTime);const H=Math.abs(L(R.row));return!_&&!H?0:Math.sqrt((_/i)**2+(H*Ve+Ee)**2)},F=()=>{if(!S)return;const{scrollLeft:R,scrollTop:_}=S,H=0,V=R/i,ee=(_-kt-ce)/(Ve+Ee),$=ee+Math.ceil(m/(Ve+Ee));j={anchorT:V,anchorX:H,scrollLeft:R,scrollTop:_,startTime:o.startTime+R/i,endTime:o.startTime+(R+p)/i,startRow:ee,endRow:$,scale:i},h.current=j;for(let W=U.length;W--;)U[W]=null};let G=0;const B=()=>{(E||!j)&&(E=!1,F()),O();const R=[],_=[];for(const H of U)if(H)for(const{d:V,span:ee}of H)V>A||(R.push(ee),ee.events&&_.push(...ee.events));A<P&&(!M||A<D)&&(A=Math.min(P,A+100),G=requestAnimationFrame(B)),v(R),g(_),C(i)};B();let q=Date.now();const X=R=>{(R.ctrlKey||R.metaKey)&&(q=Date.now())};S==null||S.addEventListener("wheel",X);const J=()=>{Date.now()-q<=50||(E=!0,cancelAnimationFrame(G),G=requestAnimationFrame(B))};return S==null||S.addEventListener("scroll",J),()=>{cancelAnimationFrame(G),S==null||S.removeEventListener("wheel",X),S==null||S.removeEventListener("scroll",J)}},[b,o,i,h,l,p,m,s]),c.useEffect(()=>{var E;if(!u)return;let S;for(const M of y)if(M.span.spanId===u.span.spanId){S=M;break}const j=(E=S==null?void 0:S.ref)==null?void 0:E.current;if(!(!S||!j))return S.isSelected=!0,j.setAttribute("data-selected",""),()=>{S.isSelected=!1,j.removeAttribute("data-selected")}},[y,u]),{rows:b,spans:y,events:N,scale:k}};function Ea(e){const[s,r]=c.useState(e);return c.useEffect(()=>{if(s===e)return;let n=0,o=0;const a=()=>{if(++n<=3){o=requestAnimationFrame(a);return}r(e)};return a(),()=>{cancelAnimationFrame(o)}},[s,e]),s}const Ss={traceId:"skeleton",spans:[{parentSpanId:"",spanId:"root",name:"root span",kind:1,resource:"vercel.runtime",startTime:[5e3,0],endTime:[6e3,0],duration:[1e3,0],library:{name:"vercel-site"},status:{code:1},attributes:{"vercel.ownerId":"team_abc"},traceFlags:1,events:[],links:[]}],resources:[{name:"vercel.runtime",attributes:{}}],rootSpanId:"root"};function Ta({trace:e=Ss,className:s="",scrollLock:r=!1,height:n,withPanel:o=!1,highlightedSpans:a,eagerRender:i=!1,isLive:l=!1,footer:p,knownDurationMs:d,hasMoreData:h=!1}){const u=e===Ss,{state:f,dispatch:m}=be(),{timelineRef:w,scrollSnapshotRef:b}=f,x=f.memoCacheRef.current,y=((a==null?void 0:a.length)??0)>0,v=c.useRef(!1),N=c.useRef(""),g=c.useRef(null),k=c.useRef({}),C=c.useRef(null);c.useEffect(()=>{const{root:O,map:L}=Sa(e),T=!v.current;v.current=!0;const F=Object.keys(L).sort().map(G=>{const B=L[G].events,q=(B==null?void 0:B.length)??0,X=q?B==null?void 0:B[0]:void 0,J=q?B==null?void 0:B[q-1]:void 0,R=`${(X==null?void 0:X.event.name)??"none"}@${(X==null?void 0:X.timestamp)??0}|${(J==null?void 0:J.event.name)??"none"}@${(J==null?void 0:J.timestamp)??0}`;return`${G}:${q}:${R}`}).join(",");if(!T&&F===N.current&&g.current){const G=g.current,B=k.current;let q=!1;(G.endTime!==O.endTime||G.duration!==O.duration)&&(G.endTime=O.endTime,G.duration=O.duration,q=!0);for(const[X,J]of Object.entries(L)){const R=B[X];R&&((R.endTime!==J.endTime||R.duration!==J.duration)&&(R.endTime=J.endTime,R.duration=J.duration,q=!0),Object.assign(R.span,J.span))}if(!q)return;m({type:"forceRender"});return}N.current=F,g.current=O,k.current=L,m({type:T?"setRoot":"updateRoot",root:O,spanMap:L,resources:e.resources||[]})},[m,e]);const{rows:I,spans:S,events:j,scale:E}=Ia(a,i),M=c.useRef(null);c.useLayoutEffect(()=>{const O=M.current;if(!O)return;const L=()=>{const F=2*ce,G=O.getBoundingClientRect(),B=G.width-F,q=G.height,X=C.current;X&&X.width===B&&X.height===q||(C.current={width:B,height:q},m({type:"setSize",width:B,height:q}))};L();const T=new ResizeObserver(L);return T.observe(O),window.addEventListener("resize",L),()=>{T.disconnect(),window.removeEventListener("resize",L)}},[m]);const D=c.useRef({t:0,x:-1,y:-1,spanId:""}),A=c.useCallback(O=>{const L=D.current,T=Date.now(),{clientX:F,clientY:G}=O,B=Math.sqrt((F-L.x)**2+(G-L.y)**2);if(T-L.t<=500&&B<=8){if(O.stopPropagation(),O.preventDefault(),!L.spanId){m({type:"resetScale"});return}m({type:"select",id:L.spanId}),m({type:"scaleToNode",id:L.spanId});return}const q=O.target;if(!q.closest(`.${String(K.timeline)}`))return;const X=q.closest("[data-span-id]"),J=(X==null?void 0:X.dataset.spanId)||"";D.current={x:F,y:G,t:T,spanId:J},J&&(m({type:"toggleSelection",id:J}),O.stopPropagation())},[m]);c.useLayoutEffect(()=>{const O=w.current;if(!O)return;const L=b.current;L&&(O.scrollLeft=L.anchorT*E-L.anchorX,b.current=void 0)},[b,w,E]),c.useEffect(()=>{var T;const O=(T=f.selected)==null?void 0:T.span.spanId;if(!O)return;const L=setTimeout(()=>{const F=f.timelineRef.current,G=F==null?void 0:F.querySelector(`[data-span-id="${O}"]`);if(!F||!G)return;const B=F.getBoundingClientRect(),q=G.getBoundingClientRect();q.width<B.width&&(q.left<B.left||q.right>B.right||q.top<B.top||q.bottom>B.bottom)&&G.scrollIntoView({block:"nearest",inline:"center",behavior:"smooth"})},500);return()=>{clearTimeout(L)}},[f.selected,f.timelineRef]),c.useEffect(()=>{const O=L=>{L.key==="Escape"&&m({type:"escape"})};return window.addEventListener("keydown",O),()=>{window.removeEventListener("keydown",O)}},[m]),c.useEffect(()=>{if(!r)return;const O=document.documentElement,L=document.body;O.style.overflow="clip",L.style.overflow="clip";const T=F=>{F!=null&&F.cancelable?F.preventDefault():window.scrollTo({left:0,top:0,behavior:"instant"})};return T(),window.addEventListener("scroll",T,{passive:!1}),()=>{O.style.overflow="",L.style.overflow="",window.removeEventListener("scroll",T)}},[r]);const P=Math.max(f.timelineHeight-f.scrollbarWidth,kt+Ee+I.length*(Ve+Ee)-Ee+84),U=!!(f.isMobile&&f.selected);return t.jsxs("div",{className:Pe(K.traceViewer,u&&K.skeleton,s),onClickCapture:A,ref:M,style:{height:n,"--timeline-padding":`${ce}px`,"--row-height":`${Ve}px`,"--row-padding":`${Ee}px`,"--search-height":`${y?0:tr}px`,"--search-gap":`${y?2:Gn}px`,"--map-height":`${Un}px`,"--timeline-width":`${f.timelineWidth}px`,"--timeline-height":`${f.timelineHeight}px`,"--timeline-scroll-width":`${Math.round(f.root.duration*f.scale)}px`,"--panel-width":`${f.panelWidth}px`,"--panel-height":`${f.panelHeight}px`,"--height":`${f.height}px`,"--scrollbar-width":`${f.scrollbarWidth}px`,"--marker-height":`${kt}px`,"--marker-notch-height":`${Kn}px`},children:[y?null:t.jsx(ya,{}),t.jsx(qn,{rows:I,scale:E,timelineRef:w}),t.jsxs("div",{className:Pe(K.traceViewerContent,U&&K.inert),children:[t.jsxs("div",{className:K.timeline,ref:w,children:[t.jsx("div",{style:{position:"relative",width:f.timelineWidth,minHeight:f.timelineHeight-ce*2,padding:ce,paddingBottom:0},children:t.jsxs("div",{className:K.traceNode,style:{width:f.root.duration*E||void 0,height:P-ce*2},children:[t.jsx(ma,{scale:E,isLive:l}),t.jsx(ha,{events:j,root:f.root,scale:E}),t.jsx(xa,{dispatch:m,events:j,memoCacheRef:f.memoCacheRef,root:f.root,scale:E,scrollSnapshotRef:b,spans:S,timelineRef:w}),t.jsx(Zn,{cacheKey:x.get(""),cache:x,customSpanClassNameFunc:f.customSpanClassNameFunc,customSpanEventClassNameFunc:f.customSpanEventClassNameFunc,isLive:l,root:f.root,scale:E,scrollSnapshotRef:b,spans:S}),d!=null&&d>0&&(h||l)&&f.root.duration>0&&(()=>{const O=d*E,T=f.root.duration*E-O;if(T<4)return null;const F=Math.min(T*.05,20);return t.jsx("div",{style:{position:"absolute",top:0,left:O+F,width:T-F,height:"100%",pointerEvents:"none",zIndex:1,maskImage:"linear-gradient(to right, transparent 1%, black 3%)",WebkitMaskImage:"linear-gradient(to right, transparent 1%, black 3%)",background:"repeating-linear-gradient(-45deg, var(--ds-background-200) 0, var(--ds-background-200) 11px, var(--ds-gray-200) 11px, var(--ds-gray-200) 12px)"}})})()]})}),p]}),t.jsx("div",{className:K.zoomButtonTraceViewer,children:t.jsx(ka,{})})]}),o?t.jsx("div",{className:Pe(K.spanDetailPanelTraceViewer,!f.selected&&K.hidden,f.isMobile&&K.mobile),children:t.jsx(Yn,{attached:!0})}):null]})}function Cs(e,s=!1){if(s&&e==="pending")return K.spanPendingStriped;switch(e){case"running":return K.spanRunning;case"pending":return K.spanPending;case"completed":return K.spanCompleted;case"cancelled":return K.spanCancelled;case"failed":return K.spanFailed;default:return""}}function Aa(e){return String(e).toLowerCase().endsWith("sleep")}const Da=e=>{const s=e.span.attributes,r=s==null?void 0:s.resource;if(r==="step"){const n=s.data,o=n==null?void 0:n.stepName;if(o&&Aa(o))return K.spanSleep;const a=(n==null?void 0:n.status)==="pending";return Cs(n==null?void 0:n.status,a)}if(r==="run"){const n=s.data;return Cs(n==null?void 0:n.status,!1)}return r==="hook"?K.spanHook:r==="sleep"?K.spanSleep:""},Ra=e=>{const s=e.event.name;return s==="step_failed"||s==="run_failed"?K.eventFailed:s==="step_retrying"?K.eventRetrying:s==="hook_created"||s==="hook_received"||s==="hook_disposed"?K.eventHook:K.eventDefault};function Ma(e){return e==="hook_created"||e==="hook_received"||e==="hook_disposed"}function me(e){if(typeof e=="string"&&(e=new Date(e)),!e||!(e instanceof Date))return[0,0];const s=e.getTime(),r=Math.floor(s/1e3),n=s%1e3*1e6;return[r,n]}function Yt(e){const s=e[0]*1e3,r=e[1]/1e6;return s+r}function Dt(e,s){if(typeof e=="string"&&(e=new Date(e)),typeof s=="string"&&(s=new Date(s)),!e||!(e instanceof Date))return[0,0];const n=(s&&s instanceof Date?s:new Date).getTime()-e.getTime(),o=Math.floor(n/1e3),a=n%1e3*1e6;return[o,a]}const ot={name:"workflow-development-kit",version:"4.0.0"},_a=new Set(["hook_created","hook_received","hook_disposed","step_started","step_retrying","step_failed","run_failed","wait_created","wait_completed"]);function Rt(e,s=!0){return e.filter(r=>s?_a.has(r.eventType):!0).map(r=>({name:r.eventType,timestamp:me(r.createdAt),attributes:{eventId:r.eventId,correlationId:r.correlationId,eventData:"eventData"in r?r.eventData:void 0},showVerticalLine:Ma(r.eventType)}))}const fr=e=>{var n;const s=e.find(o=>o.eventType==="wait_created");if(!s)return null;const r=e.find(o=>o.eventType==="wait_completed");return{waitId:s.correlationId,runId:s.runId,createdAt:s.createdAt,resumeAt:(n=s.eventData)==null?void 0:n.resumeAt,completedAt:r==null?void 0:r.createdAt}};function La(e,s){const r=fr(e);if(!r)return null;const n=r.createdAt,o=r.completedAt??s,a=me(n),i=me(o),l=Dt(n,o),p=Rt(e,!1);return{spanId:r.waitId,name:"sleep",kind:1,resource:"sleep",library:ot,status:{code:0},traceFlags:1,attributes:{resource:"sleep",data:r},links:[],events:p,duration:l,startTime:a,endTime:i}}const pr=e=>{var p;const s=e.find(d=>d.eventType==="step_created"),r=s??e[0];if(!r)return null;let n="pending",o=0,a,i;for(const d of e)switch(d.eventType){case"step_started":n="running",o+=1,a||(a=d.createdAt),i=void 0;break;case"step_completed":n="completed",i=d.createdAt;break;case"step_failed":n="failed",i=d.createdAt;break;case"step_retrying":n="pending",i=void 0;break}o===0&&(o=1);const l=e[e.length-1];return{stepId:r.correlationId??"",runId:r.runId,stepName:((p=s==null?void 0:s.eventData)==null?void 0:p.stepName)??"",status:n,attempt:o,createdAt:r.createdAt,updatedAt:(l==null?void 0:l.createdAt)??r.createdAt,startedAt:a,completedAt:i,specVersion:r.specVersion}};function Oa(e,s){const r=pr(e);if(!r)return null;const n=nt(String(r.stepName)),o={resource:"step",data:r},a="step",i=new Date(r.completedAt??s),l=Rt(e,!1),p=new Date(r.createdAt);let d=r.startedAt?new Date(r.startedAt):void 0;const h=e.find(u=>u.eventType==="step_started");return h&&(d=new Date(h.createdAt)),{spanId:String(r.stepId),name:(n==null?void 0:n.shortName)??"",kind:1,resource:a,library:ot,status:{code:0},traceFlags:1,attributes:o,links:[],events:l,startTime:me(p),endTime:me(i),duration:Dt(p,i),activeStartTime:d&&d.getTime()>p.getTime()?me(d):void 0}}const Fa=e=>{var a,i;const s=e.find(l=>l.eventType==="hook_created");if(!s)return null;const r=e.filter(l=>l.eventType==="hook_received"),n=e.filter(l=>l.eventType==="hook_disposed"),o=r.at(-1);return{hookId:s.correlationId,runId:s.runId,token:(a=s.eventData)==null?void 0:a.token,createdAt:s.createdAt,receivedCount:r.length,lastReceivedAt:(o==null?void 0:o.createdAt)||void 0,disposedAt:((i=n.at(-1))==null?void 0:i.createdAt)||void 0}};function Pa(e,s){const r=Fa(e);if(!r)return null;const n=Rt(e,!1),o=r.disposedAt||s;return{spanId:String(r.hookId),name:String(r.hookId),kind:1,resource:"hook",library:ot,status:{code:1},traceFlags:1,attributes:{resource:"hook",data:r},links:[],events:n,startTime:me(r.createdAt),endTime:me(o),duration:Dt(r.createdAt,o)}}function Wa(e,s,r){var m;const n=r??new Date,{input:o,output:a,error:i,...l}=e,p={resource:"run",data:l},d=new Date(e.createdAt),h=e.startedAt?new Date(e.startedAt):void 0,u=e.completedAt??n,f=Rt(s,!1);return{spanId:String(e.runId),name:String(((m=Te(e.workflowName))==null?void 0:m.shortName)??"?"),kind:1,resource:"run",library:ot,status:{code:0},traceFlags:1,attributes:p,links:[],events:f,startTime:me(d),endTime:me(u),duration:Dt(d,u),activeStartTime:h&&h.getTime()>d.getTime()?me(h):void 0}}const $a=e=>e.startsWith("step_"),Ha=e=>e==="wait_created"||e==="wait_completed",Ba=e=>e==="hook_received"||e==="hook_created"||e==="hook_disposed";function Ht(e,s,r){const n=e.get(s);if(n){n.push(r);return}e.set(s,[r])}function Va(e){const s=new Map,r=[],n=new Map,o=new Map;for(const a of e){const i=a.correlationId;if(!i){r.push(a);continue}if(Ha(a.eventType)){Ht(n,i,a);continue}if(Ba(a.eventType)){Ht(o,i,a);continue}if($a(a.eventType)){Ht(s,i,a);continue}r.push(a)}return{eventsByStepId:s,runLevelEvents:r,timerEvents:n,hookEvents:o}}function za(e,s){let r=new Date(s.createdAt).getTime();for(const n of e){const o=new Date(n.createdAt).getTime();o>r&&(r=o)}return new Date(r)}function Ka(e,s,r,n){const o=n,a=Array.from(s.eventsByStepId.values()).map(p=>Oa(p,o)).filter(p=>p!==null),i=Array.from(s.hookEvents.values()).map(p=>Pa(p,o)).filter(p=>p!==null),l=Array.from(s.timerEvents.values()).map(p=>La(p,o)).filter(p=>p!==null);return{runSpan:Wa(e,s.runLevelEvents,r),spans:[...a,...i,...l]}}function Ua(e,s){const r=[e,...s.slice().sort((n,o)=>{const a=Yt(n.startTime),i=Yt(o.startTime);return a-i})];return r.map((n,o)=>{const a=o===0?void 0:String(r[o-1].spanId);return{...n,parentSpanId:a}})}function Ga(e,s,r){const n=Va(s),o=za(s,e),{runSpan:a,spans:i}=Ka(e,n,r,o),l=Ua(a,i),p=Yt(a.startTime),d=o.getTime()-p;return{traceId:e.runId,rootSpanId:e.runId,spans:l,resources:[{name:"workflow",attributes:{"service.name":ot.name}}],knownDurationMs:Math.max(0,d)}}function qa(e){const{state:s,dispatch:r}=be(),n=c.useRef(s);n.current=s,c.useEffect(()=>{if(!e)return;let o=0;const a=()=>{const{root:d}=n.current;if(d.startTime){const h=Date.now();h>d.endTime&&(d.endTime=h,d.duration=d.endTime-d.startTime)}o=requestAnimationFrame(a)};o=requestAnimationFrame(a);let i=0,l=0;const p=()=>{const d=n.current;if(d.root.duration>0){const h=(d.width-d.scrollbarWidth)/d.root.duration;(Math.abs(h-l)>l*.001||l===0)&&(l=h,r({type:"detectBaseScale"}))}i=requestAnimationFrame(p)};return i=requestAnimationFrame(p),()=>{cancelAnimationFrame(o),cancelAnimationFrame(i)}},[e,r])}const Za=450,Ya=240;function Xa({menu:e,items:s,onClose:r}){const n=c.useRef(null);c.useEffect(()=>{const i=h=>{n.current&&!n.current.contains(h.target)&&r()},l=h=>{h.key==="Escape"&&r()},p=()=>{r()},d=setTimeout(()=>{window.addEventListener("mousedown",i),window.addEventListener("keydown",l),window.addEventListener("scroll",p,!0)},0);return()=>{clearTimeout(d),window.removeEventListener("mousedown",i),window.removeEventListener("keydown",l),window.removeEventListener("scroll",p,!0)}},[r]);const[o,a]=c.useState({x:e.x,y:e.y});return c.useEffect(()=>{const i=n.current;if(!i)return;const l=i.getBoundingClientRect();let{x:p,y:d}=e;l.right>window.innerWidth&&(p=window.innerWidth-l.width-8),l.bottom>window.innerHeight&&(d=window.innerHeight-l.height-8),(p!==e.x||d!==e.y)&&a({x:p,y:d})},[e]),s.length===0?null:Qt.createPortal(t.jsxs("div",{ref:n,style:{position:"fixed",left:o.x,top:o.y,zIndex:99999,boxShadow:"var(--ds-shadow-menu)",borderRadius:12,background:"var(--ds-background-100)",padding:"var(--geist-space-gap-quarter, 4px)",fontSize:14,minWidth:180,overflowX:"hidden",overflowY:"auto"},children:[t.jsx("div",{style:{display:"block",color:"var(--ds-gray-900)",fontSize:"0.75rem",padding:"var(--geist-gap-quarter, 4px) var(--geist-space-2x, 8px)",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:240,borderBottom:"1px solid var(--ds-gray-alpha-400)",marginBottom:4},children:e.spanName}),s.map(i=>t.jsxs("button",{type:"button",style:{outline:"none",cursor:i.disabled?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:8,padding:"0 var(--geist-space-2x, 8px)",height:40,textDecoration:"none",borderRadius:6,color:i.destructive?"var(--ds-red-900)":"var(--ds-gray-1000)",width:"100%",background:"transparent",border:"none",fontSize:14,textAlign:"left",opacity:i.disabled?.4:1,transition:"background 0.15s"},disabled:i.disabled,onMouseEnter:l=>{l.currentTarget.style.background="var(--ds-gray-alpha-100)"},onMouseLeave:l=>{l.currentTarget.style.background="transparent"},onClick:()=>{i.action(),r()},children:[i.icon??null,i.label]},i.label))]}),document.body)}function Ja({trace:e,run:s,isLive:r,onWakeUpSleep:n,onCancelRun:o,onResolveHook:a,onLoadMoreSpans:i,hasMoreSpans:l=!1,isLoadingMoreSpans:p=!1,children:d}){const h=Ge(),{state:u,dispatch:f}=be();qa(r);const[m,w]=c.useState(null),[b,x]=c.useState(null),[y,v]=c.useState(!1),[N,g]=c.useState(new Set),k=c.useMemo(()=>{const D=new Map;for(const A of e.spans)D.set(A.spanId,A);return D},[e.spans]),C=c.useCallback(async D=>{if(!(y||!b||!a)){if(!b.token){h.error("Unable to resolve hook",{description:"Missing hook token. Try refreshing the run data and retry."});return}try{v(!0),await a(b.token,D),h.success("Hook resolved",{description:"The payload has been sent and the hook resolved."}),g(A=>new Set(A).add(b.hookId)),x(null)}catch(A){console.error("Failed to resolve hook:",A),h.error("Failed to resolve hook",{description:A instanceof Error?A.message:"An unknown error occurred"})}finally{v(!1)}}},[a,b,y]),I=c.useCallback(D=>{const P=D.target.closest("[data-span-id]");if(!P)return;const U=P.dataset.spanId;if(!U)return;D.preventDefault(),D.stopPropagation();const O=k.get(U);if(!O)return;const L=O.attributes.resource??"unknown",T=O.attributes.data,F=!(T!=null&&T.completedAt)&&!(T!=null&&T.disposedAt);w({x:D.clientX,y:D.clientY,spanId:U,spanName:O.name,resourceType:L,isActive:F})},[k]),S=c.useRef(null);c.useEffect(()=>{const D=S.current;if(!D)return;const A=P=>{I(P)};return D.addEventListener("contextmenu",A),()=>{D.removeEventListener("contextmenu",A)}},[I]);const j=c.useRef(!1);c.useEffect(()=>{const D=u.timelineRef.current;if(!D||!i||!l)return;const A=200,P=()=>{j.current||p||!l||D.scrollHeight-D.scrollTop-D.clientHeight>A||(j.current=!0,Promise.resolve(i()).finally(()=>{j.current=!1}))};return D.addEventListener("scroll",P),P(),()=>{D.removeEventListener("scroll",P)}},[u.timelineRef,i,l,p]);const E=c.useCallback(()=>{w(null)},[]),M=c.useCallback(D=>{var U,O;const A=[],P=!s.completedAt;if(D.resourceType==="sleep"&&D.isActive&&P&&n&&A.push({label:"Wake Up Sleep",icon:t.jsx(an,{className:"h-3.5 w-3.5"}),action:()=>{n(s.runId,D.spanId).then(L=>{L.stoppedCount>0?h.success("Sleep woken up",{description:`Woke up ${String(L.stoppedCount)} sleep${L.stoppedCount>1?"s":""}`}):h.info("No active sleeps found",{description:"The sleep may have already completed."})}).catch(L=>{h.error("Failed to wake up sleep",{description:L instanceof Error?L.message:"An unknown error occurred"})})}}),D.resourceType==="hook"&&P&&a){const L=k.get(D.spanId),T=(U=L==null?void 0:L.attributes)==null?void 0:U.data,F=!!(T!=null&&T.disposedAt)||!!((O=L==null?void 0:L.events)!=null&&O.some(G=>G.name==="hook_disposed"))||N.has(D.spanId);T!=null&&T.token&&!F&&A.push({label:"Resolve Hook",icon:t.jsx(Zs,{className:"h-3.5 w-3.5"}),action:()=>{x({hookId:D.spanId,token:T.token})}})}return D.resourceType==="run"&&P&&o&&A.push({label:"Cancel Run",icon:t.jsx(ln,{className:"h-3.5 w-3.5"}),destructive:!0,action:()=>{o(s.runId).catch(L=>{h.error("Failed to cancel run",{description:L instanceof Error?L.message:"An unknown error occurred"})})}}),A.push({label:"View Details",icon:t.jsx(ho,{className:"h-3.5 w-3.5"}),action:()=>{f({type:"select",id:D.spanId})}}),A.push({label:"Copy Name",icon:t.jsx(vo,{className:"h-3.5 w-3.5"}),action:()=>{navigator.clipboard.writeText(D.spanName).then(()=>{h.success("Name copied to clipboard")}).catch(()=>{h.error("Failed to copy name")})}}),A.push({label:"Copy ID",icon:t.jsx(rt,{className:"h-3.5 w-3.5"}),action:()=>{navigator.clipboard.writeText(D.spanId).then(()=>{h.success("ID copied to clipboard")}).catch(()=>{h.error("Failed to copy ID")})}}),A},[f,n,o,a,k,N,s.runId,s.completedAt]);return t.jsxs("div",{className:"relative w-full h-full",ref:S,children:[d,m?t.jsx(Xa,{menu:m,items:M(m),onClose:E}):null,t.jsx(Ys,{isOpen:b!==null,onClose:()=>x(null),onSubmit:C,isSubmitting:y})]})}function Qa({onSelectionChange:e}){const{state:s}=be(),{selected:r}=s,n=c.useRef(e);n.current=e;const o=c.useRef(void 0);return c.useEffect(()=>{var i,l;const a=r==null?void 0:r.span.spanId;a!==o.current&&(o.current=a,r?n.current({data:(i=r.span.attributes)==null?void 0:i.data,resource:(l=r.span.attributes)==null?void 0:l.resource,spanId:r.span.spanId}):n.current(null))},[r]),null}function ei({triggerDeselect:e}){const{dispatch:s}=be();return c.useEffect(()=>{e>0&&s({type:"deselect"})},[e,s]),null}function ti({selectRequest:e}){const{dispatch:s}=be();return c.useEffect(()=>{e!=null&&e.id&&s({type:"select",id:e.id})},[s,e]),null}function si({onResize:e}){const s=c.useCallback(r=>{r.preventDefault();let n=r.clientX;const o=i=>{const l=n-i.clientX;n=i.clientX,e(l)},a=()=>{document.removeEventListener("pointermove",o),document.removeEventListener("pointerup",a)};document.addEventListener("pointermove",o),document.addEventListener("pointerup",a)},[e]);return t.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-blue-400/50 z-10",onPointerDown:s})}function ri({hasMore:e,isLive:s,isInitialLoading:r}){const n={color:"var(--ds-gray-900)"};return e||r?t.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-xs",style:n,children:[t.jsx(ns,{size:14}),"Loading more events…"]}):s?t.jsx("div",{className:"flex items-center justify-center py-3 text-xs",style:n,children:"Waiting for more events…"}):t.jsx("div",{className:"flex items-center justify-center py-3 text-xs",style:n,children:"End of run"})}const ni=({run:e,events:s,isLoading:r,error:n,spanDetailData:o,spanDetailLoading:a,spanDetailError:i,onWakeUpSleep:l,onResolveHook:p,onCancelRun:d,onStreamClick:h,onSpanSelect:u,onLoadEventData:f,onLoadMoreSpans:m,hasMoreSpans:w=!1,isLoadingMoreSpans:b=!1,encryptionKey:x,onDecrypt:y,isDecrypting:v=!1})=>{const N=Ge(),[g,k]=c.useState(null),[C,I]=c.useState(Za),[S,j]=c.useState(0),[E,M]=c.useState(null),D=!!(e&&!e.completedAt),A=c.useMemo(()=>{if(e!=null&&e.runId)return Ga(e,s,new Date)},[e,s]),P=A;c.useEffect(()=>{n&&!r&&(console.error(n),N.error("Error loading workflow trace data",{description:n.message}))},[n,r]);const U=c.useCallback(R=>{u==null||u(R)},[u]),O=c.useCallback(R=>{if(R){const _=R.spanId,H=_?s.filter(V=>V.correlationId===_):[];k({...R,rawEvents:H})}else k(null)},[s]);c.useEffect(()=>{const R=g==null?void 0:g.spanId;if(!R)return;const _=s.filter(H=>H.correlationId===R);k(H=>{if(!H||H.spanId!==R)return H;const V=H.rawEvents??[];return V.length===_.length&&V.every(($,W)=>{var Y;return $.eventId===((Y=_[W])==null?void 0:Y.eventId)})?H:{...H,rawEvents:_}})},[s,g==null?void 0:g.spanId]);const L=c.useCallback(()=>{k(null),j(R=>R+1)},[]),T=c.useCallback(R=>{I(_=>Math.max(Ya,_+R))},[]),F=c.useMemo(()=>!(g!=null&&g.spanId)||!P?-1:P.spans.findIndex(R=>R.spanId===g.spanId),[g==null?void 0:g.spanId,P]),G=F>0,B=F>=0&&P!=null&&F<P.spans.length-1,q=c.useCallback(()=>{var _;if(!P||F<=0)return;const R=(_=P.spans[F-1])==null?void 0:_.spanId;R&&M({id:R,token:Date.now()})},[F,P]),X=c.useCallback(()=>{var _;if(!P||F<0)return;const R=(_=P.spans[F+1])==null?void 0:_.spanId;R&&M({id:R,token:Date.now()})},[F,P]),J=c.useMemo(()=>{var V,ee;if(!(g!=null&&g.data))return;const R=g.data,_=R.stepName,H=R.workflowName;return(_?(V=nt(_))==null?void 0:V.shortName:void 0)??(H?(ee=Te(H))==null?void 0:ee.shortName:void 0)??_??H??R.hookId??"Details"},[g==null?void 0:g.data]);return P?t.jsxs("div",{className:"relative w-full h-full flex",children:[t.jsx("div",{className:"flex-1 min-w-0 relative",children:t.jsxs(Xn,{customSpanClassNameFunc:Da,customSpanEventClassNameFunc:Ra,children:[t.jsx(Qa,{onSelectionChange:O}),t.jsx(ei,{triggerDeselect:S}),t.jsx(ti,{selectRequest:E}),t.jsx(Ja,{trace:P,run:e,isLive:D,onWakeUpSleep:l,onCancelRun:d,onResolveHook:p,onLoadMoreSpans:m,hasMoreSpans:w,isLoadingMoreSpans:b,children:t.jsx(Ta,{eagerRender:!0,height:"100%",isLive:D,trace:P,knownDurationMs:A==null?void 0:A.knownDurationMs,hasMoreData:w||!!r,footer:t.jsx(ri,{hasMore:w,isLive:D,isInitialLoading:!!r})})})]})}),g&&t.jsxs("div",{className:"relative border-l flex-shrink-0 flex flex-col",style:{width:C,borderColor:"var(--ds-gray-200)",backgroundColor:"var(--ds-background-100)"},children:[t.jsx(si,{onResize:T}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-y flex-shrink-0",style:{borderColor:"var(--ds-gray-200)"},children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("div",{className:"text-sm font-medium truncate",style:{color:"var(--ds-gray-1000)"},title:J,children:J})}),t.jsxs("div",{className:"flex items-center",children:[t.jsx("button",{type:"button","aria-label":"Previous span",onClick:q,disabled:!G,style:{display:"flex",alignItems:"center",justifyContent:"center",marginLeft:6,width:24,height:24,padding:0,borderRadius:6,border:"none",background:"transparent",color:"var(--ds-gray-700)",cursor:G?"pointer":"not-allowed",opacity:G?1:.45,flexShrink:0,transition:"background 0.15s"},onMouseEnter:R=>{G&&(R.currentTarget.style.background="var(--ds-gray-alpha-100)")},onMouseLeave:R=>{R.currentTarget.style.background="transparent"},children:t.jsx(nn,{size:16})}),t.jsx("button",{type:"button","aria-label":"Next span",onClick:X,disabled:!B,style:{display:"flex",alignItems:"center",justifyContent:"center",marginLeft:2,width:24,height:24,padding:0,borderRadius:6,border:"none",background:"transparent",color:"var(--ds-gray-700)",cursor:B?"pointer":"not-allowed",opacity:B?1:.45,flexShrink:0,transition:"background 0.15s"},onMouseEnter:R=>{B&&(R.currentTarget.style.background="var(--ds-gray-alpha-100)")},onMouseLeave:R=>{R.currentTarget.style.background="transparent"},children:t.jsx(on,{size:16})})]}),t.jsx("div",{className:"flex items-center",style:{borderLeft:"1px solid var(--ds-gray-300)",marginLeft:6},children:t.jsx("button",{type:"button","aria-label":"Close panel",onClick:L,style:{display:"flex",alignItems:"center",justifyContent:"center",marginLeft:6,width:24,height:24,padding:0,borderRadius:6,border:"none",background:"transparent",color:"var(--ds-gray-700)",cursor:"pointer",flexShrink:0,transition:"background 0.15s"},onMouseEnter:R=>{R.currentTarget.style.background="var(--ds-gray-alpha-100)"},onMouseLeave:R=>{R.currentTarget.style.background="transparent"},children:t.jsx(Xs,{size:16})})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsx(Be,{title:"Failed to load entity details",children:t.jsx(fa,{run:e,onStreamClick:h,spanDetailData:o??null,spanDetailError:i,spanDetailLoading:a,onSpanSelect:U,onWakeUpSleep:l,onLoadEventData:f,onResolveHook:p,encryptionKey:x,onDecrypt:y,isDecrypting:v,selectedSpan:g})})})]})]}):t.jsxs("div",{className:"relative w-full h-full",children:[t.jsx("div",{className:"border-b border-gray-alpha-400 w-full"}),t.jsx(Q,{className:"w-full ml-2 mt-1 mb-1 h-[56px]"}),t.jsxs("div",{className:"p-2 relative w-full",children:[t.jsx(Q,{className:"w-full mt-6 h-[20px]"}),t.jsx(Q,{className:"w-[10%] mt-2 ml-6 h-[20px]"}),t.jsx(Q,{className:"w-[10%] mt-2 ml-12 h-[20px]"}),t.jsx(Q,{className:"w-[20%] mt-2 ml-16 h-[20px]"})]})]})};async function oi(e,s,r,n={}){const o=n.resolveData??"all";let a,i;if(s==="run")a=await vt(qt(e,r,o)),i=a.runId;else if(s==="step"){const{runId:l}=n;if(!l)throw new Oe("runId is required for step resource",{layer:"client"});a=await vt(Jn(e,l,r,o)),i=a.stepId}else if(s==="hook")a=await vt(sr(e,r,o)),i=a.hookId;else throw new Oe(`Unknown resource type: ${s}`,{layer:"client"});return{data:a,correlationId:i}}function mr(e,s,r,n={}){const{refreshInterval:o=0,runId:a,enabled:i=!0,encryptionKey:l}=n,[p,d]=c.useState(null),[h,u]=c.useState(i),[f,m]=c.useState(null),w=c.useCallback(async x=>l?ze(x,l):pe(x),[l]),b=c.useCallback(async()=>{if(!i){u(!1);return}if(d(null),m(null),u(!0),s==="hook"){try{const{error:x,result:y}=await ue(sr(e,r,"all"));if(x){m(x);return}try{d(await w(y))}catch(v){m(v instanceof Error?v:new Error(String(v)))}}finally{u(!1)}return}if(s==="sleep"){try{if(!a){m(new Error("runId is required for loading sleep details"));return}const{error:x,result:y}=await ue(Ke(e,a,{sortOrder:"asc",limit:1e3,withData:!0}));if(x){m(x);return}try{const v=y.data.map(pe),N=await Promise.all(v.filter(k=>k.correlationId===r).map(w)),g=fr(N);if(g===null){m(new Error(`Failed to load ${s} details: missing required event data`));return}d(g)}catch(v){m(v instanceof Error?v:new Error(String(v)))}}finally{u(!1)}return}try{const{data:x}=await oi(e,s,r,{runId:a});d(await w(x))}catch(x){x instanceof Error?m(x):m(new Error(String(x)));return}finally{u(!1)}},[e,s,r,a,i,w]);return c.useEffect(()=>{b()},[b]),c.useEffect(()=>{if(!o||o<=0)return;const x=setInterval(b,o);return()=>clearInterval(x)},[o,b]),{data:p,loading:h,error:f,refresh:b}}function Xt(e,s,r){const n=[...e,...s],o=new Map(n.map(a=>[a[r],a]));return Array.from(o.values())}async function ai(e){const{fetchFn:s,setItems:r,setCursor:n,setError:o,idKey:a,cursorStrategy:i="always",transform:l}=e,{error:p,result:d}=await s();if(p)return o(p),!1;if(d.data.length>0){const h=l?d.data.map(l):d.data;return r(f=>Xt(f,h,a)),(i==="onHasMore"?!!(d.cursor&&d.hasMore):!!d.cursor)&&n(d.cursor),!0}return!1}const ii=100,li=500,ci=100,di=5e3;function ui(e,s,r={}){const{live:n=!1}=r,[o,a]=c.useState(null),[i,l]=c.useState([]),[p,d]=c.useState(!0),[h,u]=c.useState(null),[f,m]=c.useState(),[w,b]=c.useState(!1),[x,y]=c.useState(!1),v=c.useRef(!1),[N,g]=c.useState(!1),k=c.useCallback(async()=>{if(v.current)return;v.current=!0,d(!0),u(null);const[E,M]=await Promise.all([ue(qt(e,s,"none")),ue(Ke(e,s,{sortOrder:"asc",limit:li,withData:!1}))]);E.error?u(E.error):a(pe(E.result));const D=M.error?[]:M.result.data.map(pe);l(Xt([],D,"eventId")),m(M.error||!M.result.hasMore?void 0:M.result.cursor),b(!!(!M.error&&M.result.hasMore)),d(!1),g(!0),v.current=!1,!E.error&&M.error&&u(M.error)},[e,s]),C=c.useCallback(async()=>{if(!(v.current||!N||x||!w)){y(!0);try{const E=await ue(Ke(e,s,{cursor:f,sortOrder:"asc",limit:ci,withData:!1}));if(E.error)u(E.error);else{const M=E.result.data.map(pe);M.length>0&&l(D=>Xt(D,M,"eventId")),b(!!E.result.hasMore),m(E.result.hasMore?E.result.cursor:void 0)}}finally{y(!1)}}},[e,s,N,x,w,f]),I=c.useCallback(async()=>{if(o!=null&&o.completedAt)return!1;const{error:E,result:M}=await ue(qt(e,s,"none"));return E?(u(E),!1):(u(null),a(pe(M)),!0)},[e,s,o==null?void 0:o.completedAt]),S=c.useCallback(()=>ai({fetchFn:()=>ue(Ke(e,s,{cursor:f,sortOrder:"asc",limit:ii,withData:!1})),setItems:l,setCursor:m,setError:u,idKey:"eventId",transform:pe}),[e,s,f]),j=c.useCallback(async()=>{if(v.current||!N)return{foundNewItems:!1};let E=!1;try{const[M,D]=await Promise.all([I(),S()]);E=D}catch(M){console.error("Update error:",M)}return{foundNewItems:E}},[S,N,I]);return c.useEffect(()=>{k()},[k]),c.useEffect(()=>{if(!n||!N||o!=null&&o.completedAt)return;const E=setInterval(()=>{j()},di);return()=>{clearInterval(E)}},[n,N,j,o==null?void 0:o.completedAt]),{run:o??{},events:i,loading:p,error:h,update:j,loadMoreTraceData:C,hasMoreTraceData:w,isLoadingMoreTraceData:x}}function fi(e){return typeof e=="object"&&e!==null&&"message"in e&&"layer"in e&&"cause"in e&&"request"in e}async function pi(e,s,r,n){try{const o=`/api/stream/${encodeURIComponent(s)}${r!=null?`?startIndex=${r}`:""}`,a=await fetch(o,{signal:n});if(!a.ok){const i=await a.json().catch(()=>null);throw i&&fi(i)?new Oe(i.message,{layer:"client",cause:i.cause,request:i.request}):new Oe(`Failed to read stream: ${a.status}`,{layer:"client"})}if(!a.body)throw new Oe("Failed to read stream: no body",{layer:"client"});return a.body}catch(o){throw o instanceof Oe?o:new Oe("Failed to read stream",{layer:"client",cause:o})}}async function mi(e,s){return vt(Qn(e,s))}const hi=1e4;function xi(e,s,r=hi){const[n,o]=c.useState([]),[a,i]=c.useState(!0),[l,p]=c.useState(null),d=c.useCallback(async()=>{i(!0),p(null);try{const h=await mi(e,s);o(h)}catch(h){p(h instanceof Error?h:new Error(String(h)))}finally{i(!1)}},[e,s]);return c.useEffect(()=>{d()},[d]),c.useEffect(()=>{if(!r||r<=0)return;const h=setInterval(d,r);return()=>clearInterval(h)},[r,d]),{streams:n,loading:a,error:l,refresh:d}}var gi=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],Ne=gi.reduce((e,s)=>{const r=c.forwardRef((n,o)=>{const{asChild:a,...i}=n,l=a?ss:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),t.jsx(l,{...i,ref:o})});return r.displayName=`Primitive.${s}`,{...e,[s]:r}},{});function vi(e,s){e&&Qt.flushSync(()=>e.dispatchEvent(s))}var yi="DismissableLayer",Jt="dismissableLayer.update",bi="dismissableLayer.pointerDownOutside",wi="dismissableLayer.focusOutside",Is,hr=c.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),xr=c.forwardRef((e,s)=>{const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:n,onPointerDownOutside:o,onFocusOutside:a,onInteractOutside:i,onDismiss:l,...p}=e,d=c.useContext(hr),[h,u]=c.useState(null),f=(h==null?void 0:h.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,m]=c.useState({}),w=Ae(s,I=>u(I)),b=Array.from(d.layers),[x]=[...d.layersWithOutsidePointerEventsDisabled].slice(-1),y=b.indexOf(x),v=h?b.indexOf(h):-1,N=d.layersWithOutsidePointerEventsDisabled.size>0,g=v>=y,k=ki(I=>{const S=I.target,j=[...d.branches].some(E=>E.contains(S));!g||j||(o==null||o(I),i==null||i(I),I.defaultPrevented||l==null||l())},f),C=Si(I=>{const S=I.target;[...d.branches].some(E=>E.contains(S))||(a==null||a(I),i==null||i(I),I.defaultPrevented||l==null||l())},f);return cn(I=>{v===d.layers.size-1&&(n==null||n(I),!I.defaultPrevented&&l&&(I.preventDefault(),l()))},f),c.useEffect(()=>{if(h)return r&&(d.layersWithOutsidePointerEventsDisabled.size===0&&(Is=f.body.style.pointerEvents,f.body.style.pointerEvents="none"),d.layersWithOutsidePointerEventsDisabled.add(h)),d.layers.add(h),Es(),()=>{r&&d.layersWithOutsidePointerEventsDisabled.size===1&&(f.body.style.pointerEvents=Is)}},[h,f,r,d]),c.useEffect(()=>()=>{h&&(d.layers.delete(h),d.layersWithOutsidePointerEventsDisabled.delete(h),Es())},[h,d]),c.useEffect(()=>{const I=()=>m({});return document.addEventListener(Jt,I),()=>document.removeEventListener(Jt,I)},[]),t.jsx(Ne.div,{...p,ref:w,style:{pointerEvents:N?g?"auto":"none":void 0,...e.style},onFocusCapture:je(e.onFocusCapture,C.onFocusCapture),onBlurCapture:je(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:je(e.onPointerDownCapture,k.onPointerDownCapture)})});xr.displayName=yi;var ji="DismissableLayerBranch",Ni=c.forwardRef((e,s)=>{const r=c.useContext(hr),n=c.useRef(null),o=Ae(s,n);return c.useEffect(()=>{const a=n.current;if(a)return r.branches.add(a),()=>{r.branches.delete(a)}},[r.branches]),t.jsx(Ne.div,{...e,ref:o})});Ni.displayName=ji;function ki(e,s=globalThis==null?void 0:globalThis.document){const r=wt(e),n=c.useRef(!1),o=c.useRef(()=>{});return c.useEffect(()=>{const a=l=>{if(l.target&&!n.current){let p=function(){gr(bi,r,d,{discrete:!0})};const d={originalEvent:l};l.pointerType==="touch"?(s.removeEventListener("click",o.current),o.current=p,s.addEventListener("click",o.current,{once:!0})):p()}else s.removeEventListener("click",o.current);n.current=!1},i=window.setTimeout(()=>{s.addEventListener("pointerdown",a)},0);return()=>{window.clearTimeout(i),s.removeEventListener("pointerdown",a),s.removeEventListener("click",o.current)}},[s,r]),{onPointerDownCapture:()=>n.current=!0}}function Si(e,s=globalThis==null?void 0:globalThis.document){const r=wt(e),n=c.useRef(!1);return c.useEffect(()=>{const o=a=>{a.target&&!n.current&&gr(wi,r,{originalEvent:a},{discrete:!1})};return s.addEventListener("focusin",o),()=>s.removeEventListener("focusin",o)},[s,r]),{onFocusCapture:()=>n.current=!0,onBlurCapture:()=>n.current=!1}}function Es(){const e=new CustomEvent(Jt);document.dispatchEvent(e)}function gr(e,s,r,{discrete:n}){const o=r.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:r});s&&o.addEventListener(e,s,{once:!0}),n?vi(o,a):o.dispatchEvent(a)}var Bt="focusScope.autoFocusOnMount",Vt="focusScope.autoFocusOnUnmount",Ts={bubbles:!1,cancelable:!0},Ci="FocusScope",vr=c.forwardRef((e,s)=>{const{loop:r=!1,trapped:n=!1,onMountAutoFocus:o,onUnmountAutoFocus:a,...i}=e,[l,p]=c.useState(null),d=wt(o),h=wt(a),u=c.useRef(null),f=Ae(s,b=>p(b)),m=c.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;c.useEffect(()=>{if(n){let b=function(N){if(m.paused||!l)return;const g=N.target;l.contains(g)?u.current=g:Ie(u.current,{select:!0})},x=function(N){if(m.paused||!l)return;const g=N.relatedTarget;g!==null&&(l.contains(g)||Ie(u.current,{select:!0}))},y=function(N){if(document.activeElement===document.body)for(const k of N)k.removedNodes.length>0&&Ie(l)};document.addEventListener("focusin",b),document.addEventListener("focusout",x);const v=new MutationObserver(y);return l&&v.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",x),v.disconnect()}}},[n,l,m.paused]),c.useEffect(()=>{if(l){Ds.add(m);const b=document.activeElement;if(!l.contains(b)){const y=new CustomEvent(Bt,Ts);l.addEventListener(Bt,d),l.dispatchEvent(y),y.defaultPrevented||(Ii(Ri(yr(l)),{select:!0}),document.activeElement===b&&Ie(l))}return()=>{l.removeEventListener(Bt,d),setTimeout(()=>{const y=new CustomEvent(Vt,Ts);l.addEventListener(Vt,h),l.dispatchEvent(y),y.defaultPrevented||Ie(b??document.body,{select:!0}),l.removeEventListener(Vt,h),Ds.remove(m)},0)}}},[l,d,h,m]);const w=c.useCallback(b=>{if(!r&&!n||m.paused)return;const x=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,y=document.activeElement;if(x&&y){const v=b.currentTarget,[N,g]=Ei(v);N&&g?!b.shiftKey&&y===g?(b.preventDefault(),r&&Ie(N,{select:!0})):b.shiftKey&&y===N&&(b.preventDefault(),r&&Ie(g,{select:!0})):y===v&&b.preventDefault()}},[r,n,m.paused]);return t.jsx(Ne.div,{tabIndex:-1,...i,ref:f,onKeyDown:w})});vr.displayName=Ci;function Ii(e,{select:s=!1}={}){const r=document.activeElement;for(const n of e)if(Ie(n,{select:s}),document.activeElement!==r)return}function Ei(e){const s=yr(e),r=As(s,e),n=As(s.reverse(),e);return[r,n]}function yr(e){const s=[],r=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:n=>{const o=n.tagName==="INPUT"&&n.type==="hidden";return n.disabled||n.hidden||o?NodeFilter.FILTER_SKIP:n.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;r.nextNode();)s.push(r.currentNode);return s}function As(e,s){for(const r of e)if(!Ti(r,{upTo:s}))return r}function Ti(e,{upTo:s}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(s!==void 0&&e===s)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Ai(e){return e instanceof HTMLInputElement&&"select"in e}function Ie(e,{select:s=!1}={}){if(e&&e.focus){const r=document.activeElement;e.focus({preventScroll:!0}),e!==r&&Ai(e)&&s&&e.select()}}var Ds=Di();function Di(){let e=[];return{add(s){const r=e[0];s!==r&&(r==null||r.pause()),e=Rs(e,s),e.unshift(s)},remove(s){var r;e=Rs(e,s),(r=e[0])==null||r.resume()}}}function Rs(e,s){const r=[...e],n=r.indexOf(s);return n!==-1&&r.splice(n,1),r}function Ri(e){return e.filter(s=>s.tagName!=="A")}var Mi="Portal",br=c.forwardRef((e,s)=>{var l;const{container:r,...n}=e,[o,a]=c.useState(!1);dn(()=>a(!0),[]);const i=r||o&&((l=globalThis==null?void 0:globalThis.document)==null?void 0:l.body);return i?Jr.createPortal(t.jsx(Ne.div,{...n,ref:s}),i):null});br.displayName=Mi;var ls="Dialog",[wr,jr]=Js(ls),[_i,he]=wr(ls),Nr=e=>{const{__scopeDialog:s,children:r,open:n,defaultOpen:o,onOpenChange:a,modal:i=!0}=e,l=c.useRef(null),p=c.useRef(null),[d=!1,h]=fn({prop:n,defaultProp:o,onChange:a});return t.jsx(_i,{scope:s,triggerRef:l,contentRef:p,contentId:_t(),titleId:_t(),descriptionId:_t(),open:d,onOpenChange:h,onOpenToggle:c.useCallback(()=>h(u=>!u),[h]),modal:i,children:r})};Nr.displayName=ls;var kr="DialogTrigger",Sr=c.forwardRef((e,s)=>{const{__scopeDialog:r,...n}=e,o=he(kr,r),a=Ae(s,o.triggerRef);return t.jsx(Ne.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":us(o.open),...n,ref:a,onClick:je(e.onClick,o.onOpenToggle)})});Sr.displayName=kr;var cs="DialogPortal",[Li,Cr]=wr(cs,{forceMount:void 0}),Ir=e=>{const{__scopeDialog:s,forceMount:r,children:n,container:o}=e,a=he(cs,s);return t.jsx(Li,{scope:s,forceMount:r,children:c.Children.map(n,i=>t.jsx(ts,{present:r||a.open,children:t.jsx(br,{asChild:!0,container:o,children:i})}))})};Ir.displayName=cs;var It="DialogOverlay",Er=c.forwardRef((e,s)=>{const r=Cr(It,e.__scopeDialog),{forceMount:n=r.forceMount,...o}=e,a=he(It,e.__scopeDialog);return a.modal?t.jsx(ts,{present:n||a.open,children:t.jsx(Oi,{...o,ref:s})}):null});Er.displayName=It;var Oi=c.forwardRef((e,s)=>{const{__scopeDialog:r,...n}=e,o=he(It,r);return t.jsx(mn,{as:ss,allowPinchZoom:!0,shards:[o.contentRef],children:t.jsx(Ne.div,{"data-state":us(o.open),...n,ref:s,style:{pointerEvents:"auto",...n.style}})})}),We="DialogContent",Tr=c.forwardRef((e,s)=>{const r=Cr(We,e.__scopeDialog),{forceMount:n=r.forceMount,...o}=e,a=he(We,e.__scopeDialog);return t.jsx(ts,{present:n||a.open,children:a.modal?t.jsx(Fi,{...o,ref:s}):t.jsx(Pi,{...o,ref:s})})});Tr.displayName=We;var Fi=c.forwardRef((e,s)=>{const r=he(We,e.__scopeDialog),n=c.useRef(null),o=Ae(s,r.contentRef,n);return c.useEffect(()=>{const a=n.current;if(a)return pn(a)},[]),t.jsx(Ar,{...e,ref:o,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:je(e.onCloseAutoFocus,a=>{var i;a.preventDefault(),(i=r.triggerRef.current)==null||i.focus()}),onPointerDownOutside:je(e.onPointerDownOutside,a=>{const i=a.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&a.preventDefault()}),onFocusOutside:je(e.onFocusOutside,a=>a.preventDefault())})}),Pi=c.forwardRef((e,s)=>{const r=he(We,e.__scopeDialog),n=c.useRef(!1),o=c.useRef(!1);return t.jsx(Ar,{...e,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var i,l;(i=e.onCloseAutoFocus)==null||i.call(e,a),a.defaultPrevented||(n.current||(l=r.triggerRef.current)==null||l.focus(),a.preventDefault()),n.current=!1,o.current=!1},onInteractOutside:a=>{var p,d;(p=e.onInteractOutside)==null||p.call(e,a),a.defaultPrevented||(n.current=!0,a.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=a.target;((d=r.triggerRef.current)==null?void 0:d.contains(i))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&o.current&&a.preventDefault()}})}),Ar=c.forwardRef((e,s)=>{const{__scopeDialog:r,trapFocus:n,onOpenAutoFocus:o,onCloseAutoFocus:a,...i}=e,l=he(We,r),p=c.useRef(null),d=Ae(s,p);return hn(),t.jsxs(t.Fragment,{children:[t.jsx(vr,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:o,onUnmountAutoFocus:a,children:t.jsx(xr,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":us(l.open),...i,ref:d,onDismiss:()=>l.onOpenChange(!1)})}),t.jsxs(t.Fragment,{children:[t.jsx($i,{titleId:l.titleId}),t.jsx(Bi,{contentRef:p,descriptionId:l.descriptionId})]})]})}),ds="DialogTitle",Dr=c.forwardRef((e,s)=>{const{__scopeDialog:r,...n}=e,o=he(ds,r);return t.jsx(Ne.h2,{id:o.titleId,...n,ref:s})});Dr.displayName=ds;var Rr="DialogDescription",Mr=c.forwardRef((e,s)=>{const{__scopeDialog:r,...n}=e,o=he(Rr,r);return t.jsx(Ne.p,{id:o.descriptionId,...n,ref:s})});Mr.displayName=Rr;var _r="DialogClose",Lr=c.forwardRef((e,s)=>{const{__scopeDialog:r,...n}=e,o=he(_r,r);return t.jsx(Ne.button,{type:"button",...n,ref:s,onClick:je(e.onClick,()=>o.onOpenChange(!1))})});Lr.displayName=_r;function us(e){return e?"open":"closed"}var Or="DialogTitleWarning",[Wi,Fr]=un(Or,{contentName:We,titleName:ds,docsSlug:"dialog"}),$i=({titleId:e})=>{const s=Fr(Or),r=`\`${s.contentName}\` requires a \`${s.titleName}\` for the component to be accessible for screen reader users.
24
+
25
+ If you want to hide the \`${s.titleName}\`, you can wrap it with our VisuallyHidden component.
26
+
27
+ For more information, see https://radix-ui.com/primitives/docs/components/${s.docsSlug}`;return c.useEffect(()=>{e&&(document.getElementById(e)||console.error(r))},[r,e]),null},Hi="DialogDescriptionWarning",Bi=({contentRef:e,descriptionId:s})=>{const n=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Fr(Hi).contentName}}.`;return c.useEffect(()=>{var a;const o=(a=e.current)==null?void 0:a.getAttribute("aria-describedby");s&&o&&(document.getElementById(s)||console.warn(n))},[n,e,s]),null},Vi=Nr,zi=Sr,Ki=Ir,Ui=Er,Gi=Tr,qi=Dr,Zi=Mr,Pr=Lr,Wr="AlertDialog",[Yi]=Js(Wr,[jr]),ke=jr(),$r=e=>{const{__scopeAlertDialog:s,...r}=e,n=ke(s);return t.jsx(Vi,{...n,...r,modal:!0})};$r.displayName=Wr;var Xi="AlertDialogTrigger",Ji=c.forwardRef((e,s)=>{const{__scopeAlertDialog:r,...n}=e,o=ke(r);return t.jsx(zi,{...o,...n,ref:s})});Ji.displayName=Xi;var Qi="AlertDialogPortal",Hr=e=>{const{__scopeAlertDialog:s,...r}=e,n=ke(s);return t.jsx(Ki,{...n,...r})};Hr.displayName=Qi;var el="AlertDialogOverlay",Br=c.forwardRef((e,s)=>{const{__scopeAlertDialog:r,...n}=e,o=ke(r);return t.jsx(Ui,{...o,...n,ref:s})});Br.displayName=el;var Ue="AlertDialogContent",[tl,sl]=Yi(Ue),Vr=c.forwardRef((e,s)=>{const{__scopeAlertDialog:r,children:n,...o}=e,a=ke(r),i=c.useRef(null),l=Ae(s,i),p=c.useRef(null);return t.jsx(Wi,{contentName:Ue,titleName:zr,docsSlug:"alert-dialog",children:t.jsx(tl,{scope:r,cancelRef:p,children:t.jsxs(Gi,{role:"alertdialog",...a,...o,ref:l,onOpenAutoFocus:je(o.onOpenAutoFocus,d=>{var h;d.preventDefault(),(h=p.current)==null||h.focus({preventScroll:!0})}),onPointerDownOutside:d=>d.preventDefault(),onInteractOutside:d=>d.preventDefault(),children:[t.jsx(eo,{children:n}),t.jsx(nl,{contentRef:i})]})})})});Vr.displayName=Ue;var zr="AlertDialogTitle",Kr=c.forwardRef((e,s)=>{const{__scopeAlertDialog:r,...n}=e,o=ke(r);return t.jsx(qi,{...o,...n,ref:s})});Kr.displayName=zr;var Ur="AlertDialogDescription",Gr=c.forwardRef((e,s)=>{const{__scopeAlertDialog:r,...n}=e,o=ke(r);return t.jsx(Zi,{...o,...n,ref:s})});Gr.displayName=Ur;var rl="AlertDialogAction",qr=c.forwardRef((e,s)=>{const{__scopeAlertDialog:r,...n}=e,o=ke(r);return t.jsx(Pr,{...o,...n,ref:s})});qr.displayName=rl;var Zr="AlertDialogCancel",Yr=c.forwardRef((e,s)=>{const{__scopeAlertDialog:r,...n}=e,{cancelRef:o}=sl(Zr,r),a=ke(r),i=Ae(s,o);return t.jsx(Pr,{...a,...n,ref:i})});Yr.displayName=Zr;var nl=({contentRef:e})=>{const s=`\`${Ue}\` requires a description for the component to be accessible for screen reader users.
28
+
29
+ You can add a description to the \`${Ue}\` by passing a \`${Ur}\` component as a child, which also benefits sighted users by adding visible context to the dialog.
30
+
31
+ Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${Ue}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component.
32
+
33
+ For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return c.useEffect(()=>{var n;document.getElementById((n=e.current)==null?void 0:n.getAttribute("aria-describedby"))||console.warn(s)},[s,e]),null},ol=$r,al=Hr,il=Br,ll=Vr,cl=qr,dl=Yr,ul=Kr,fl=Gr;function Ms({...e}){return t.jsx(ol,{"data-slot":"alert-dialog",...e})}function pl({...e}){return t.jsx(al,{"data-slot":"alert-dialog-portal",...e})}function ml({className:e,...s}){return t.jsx(il,{"data-slot":"alert-dialog-overlay",className:de("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...s})}function _s({className:e,onSubmit:s,...r}){return t.jsxs(pl,{children:[t.jsx(ml,{}),t.jsx(ll,{"data-slot":"alert-dialog-content",className:de("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",e),onSubmit:n=>{n.preventDefault(),s==null||s(n)},...r})]})}function Ls({className:e,...s}){return t.jsx("div",{"data-slot":"alert-dialog-header",className:de("flex flex-col gap-2 text-center sm:text-left",e),...s})}function Os({className:e,...s}){return t.jsx("div",{"data-slot":"alert-dialog-footer",className:de("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",e),...s})}function Fs({className:e,...s}){return t.jsx(ul,{"data-slot":"alert-dialog-title",className:de("text-lg font-semibold",e),...s})}function Ps({className:e,...s}){return t.jsx(fl,{"data-slot":"alert-dialog-description",className:de("text-muted-foreground text-sm",e),...s})}function Ws({className:e,...s}){return t.jsx(cl,{className:de(rr(),e),...s})}function $s({className:e,...s}){return t.jsx(dl,{className:de(rr({variant:"outline"}),e),...s})}function hl({...e}){return t.jsx("nav",{"aria-label":"breadcrumb","data-slot":"breadcrumb",...e})}function xl({className:e,...s}){return t.jsx("ol",{"data-slot":"breadcrumb-list",className:de("text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5",e),...s})}function Hs({className:e,...s}){return t.jsx("li",{"data-slot":"breadcrumb-item",className:de("inline-flex items-center gap-1.5",e),...s})}function gl({asChild:e,className:s,...r}){const n=e?ss:"a";return t.jsx(n,{"data-slot":"breadcrumb-link",className:de("hover:text-foreground transition-colors",s),...r})}function vl({className:e,...s}){return t.jsx("span",{"data-slot":"breadcrumb-page",role:"link","aria-disabled":"true","aria-current":"page",className:de("text-foreground font-normal",e),...s})}function yl({children:e,className:s,...r}){return t.jsx("li",{"data-slot":"breadcrumb-separator",role:"presentation","aria-hidden":"true",className:de("[&>svg]:size-3.5",s),...r,children:e??t.jsx(es,{})})}const He={sleep:"sleep",createHook:"createHook",createWebhook:"createWebhook",awaitWebhook:"awaitWebhook"};function Et(e){return e.replace(/\/\/\.\.\//g,"//")}function bl(e,s,r,n){let o;switch(e.status){case"completed":o="completed";break;case"failed":o=r<n-1?"retrying":"failed";break;case"running":o="running";break;case"cancelled":o="cancelled";break;case"pending":default:o="pending";break}const a=e.completedAt&&e.startedAt?new Date(e.completedAt).getTime()-new Date(e.startedAt).getTime():void 0;return{nodeId:s,stepId:e.stepId,attemptNumber:e.attempt,status:o,startedAt:e.startedAt?new Date(e.startedAt).toISOString():void 0,completedAt:e.completedAt?new Date(e.completedAt).toISOString():void 0,duration:a,input:e.input,output:e.output,error:e.error?{message:e.error.message,stack:e.error.stack||""}:void 0}}function Tt(e){const s=e.split("//");return s.length>=3?s[s.length-1]:null}function wl(e){const s=new Map,r=new Map,n=new Map,o=[],a=new Map;for(const i of e){if(i.data.stepId){const l=Et(i.data.stepId),p=s.get(l)||[];p.push(i),s.set(l,p);const d=Tt(l);if(d){const h=r.get(d)||[];h.push(i),r.set(d,h)}}if(i.data.nodeKind==="primitive"){const l=i.data.label,p=n.get(l)||[];p.push(i),n.set(l,p)}if(i.data.nodeKind==="agent"&&o.push(i),i.data.nodeKind==="tool"){const p=i.data.label.replace(/ \(tool\)$/,""),d=a.get(p)||[];if(d.push(i),a.set(p,d),i.data.stepId){const h=Tt(Et(i.data.stepId));if(h){const u=a.get(h)||[];u.includes(i)||(u.push(i),a.set(h,u))}}}}return{byStepId:s,byFunctionName:r,primitivesByLabel:n,agentNodes:o,toolNodes:a}}function jl(e,s,r){var p,d,h,u;const n=new Map,o=new Set(e),a=new Map;for(const f of s.nodes){const m=(p=f.metadata)==null?void 0:p.parallelGroupId;if(m){const w=a.get(m)||{nodes:[]};w.nodes.push(f),w.method=(d=f.metadata)==null?void 0:d.parallelMethod,a.set(m,w)}}const i=new Map;for(const[f,m]of a)if(m.method==="race"){let w,b;for(const x of m.nodes){const y=r.get(x.id);if(y){for(const v of y)if(v.status==="completed"&&v.completedAt){const N=new Date(v.completedAt);(!b||N<b)&&(b=N,w=x.id)}}}w&&i.set(f,w)}const l=f=>{const m=n.get(f.id);m?m.traversalCount++:n.set(f.id,{edgeId:f.id,traversalCount:1,timings:[]})};for(const f of s.edges){const m=s.nodes.find(N=>N.id===f.source),w=s.nodes.find(N=>N.id===f.target);if(!m||!w)continue;const b=o.has(f.source),x=o.has(f.target);if(!b&&!x)continue;if(f.type==="conditional"){b&&x&&l(f);continue}const y=(h=m.metadata)==null?void 0:h.parallelGroupId,v=(u=m.metadata)==null?void 0:u.parallelMethod;y&&v==="race"?i.get(y)===f.source&&x&&l(f):(b&&x||b&&f.type==="parallel"&&x)&&l(f)}return n}function Nl(e,s,r,n){const o=s.nodes.find(a=>a.data.nodeKind==="workflow_start");o&&(r.push(o.id),n.set(o.id,[{nodeId:o.id,attemptNumber:1,status:"completed",startedAt:e.startedAt?new Date(e.startedAt).toISOString():void 0,completedAt:e.startedAt?new Date(e.startedAt).toISOString():void 0}]))}function kl(e,s,r,n){const o=s.nodes.find(i=>i.data.nodeKind==="workflow_end");if(!o||r.includes(o.id))return;let a;switch(e.status){case"completed":a="completed";break;case"failed":a="failed";break;case"cancelled":a="cancelled";break;case"running":a="running";break;case"pending":default:return}r.push(o.id),n.set(o.id,[{nodeId:o.id,attemptNumber:1,status:a,startedAt:e.completedAt?new Date(e.completedAt).toISOString():void 0,completedAt:e.completedAt?new Date(e.completedAt).toISOString():void 0}])}function Sl(e,s,r,n,o,a,i){const l=Et(s),p=o.get(l)||0;o.set(l,p+1);let d=r.get(l)||[],h="step-id";if(d.length===0){const w=Tt(l);w&&(d=n.get(w)||[],h="function-name")}const u=d.length===1?d[0]:d[p];if(console.log("[Graph Mapper] Processing step group:",{stepName:s,normalizedStepName:l,attempts:e.length,occurrenceIndex:p,totalNodesWithStepId:d.length,selectedNode:u==null?void 0:u.id,allNodesWithStepId:d.map(w=>w.id),matchStrategy:h,strategy:d.length===1?"single-node-multiple-invocations":"occurrence-based"}),!u)return;const f=e.map((w,b)=>bl(w,u.id,b,e.length));if(d.length===1){const w=a.get(u.id)||[];a.set(u.id,[...w,...f])}else a.set(u.id,f);return i.includes(u.id)||i.push(u.id),f[f.length-1].status==="running"?u.id:void 0}function Cl(e,s,r,n){const o=new Map,a=new Map;for(const y of e){if(!y.correlationId)continue;const v=a.get(y.correlationId)||[];v.push(y),a.set(y.correlationId,v)}let i;const l=s.get(He.sleep)||[],p=new Set;for(const y of e)y.eventType==="wait_created"&&y.correlationId&&p.add(y.correlationId);const d=Array.from(p).sort((y,v)=>{var I,S;const N=a.get(y)||[],g=a.get(v)||[],k=(I=N.find(j=>j.eventType==="wait_created"))==null?void 0:I.createdAt,C=(S=g.find(j=>j.eventType==="wait_created"))==null?void 0:S.createdAt;return!k||!C?0:new Date(k).getTime()-new Date(C).getTime()});for(const y of d){const v=a.get(y)||[],N=v.find(A=>A.eventType==="wait_created"),g=v.find(A=>A.eventType==="wait_completed");if(!N)continue;const k=o.get(He.sleep)||0;o.set(He.sleep,k+1);const C=l.length===1?l[0]:l[k];if(!C)continue;let I="running";g&&(I="completed");const S=new Date(N.createdAt).toISOString(),j=g?new Date(g.createdAt).toISOString():void 0,E=g?new Date(g.createdAt).getTime()-new Date(N.createdAt).getTime():void 0,M={nodeId:C.id,attemptNumber:1,status:I,startedAt:S,completedAt:j,duration:E},D=r.get(C.id)||[];r.set(C.id,[...D,M]),n.includes(C.id)||n.push(C.id),I==="running"&&(i=C.id)}const h=[...s.get(He.createHook)||[],...s.get(He.createWebhook)||[]],u=new Set;for(const y of e)y.eventType==="hook_created"&&y.correlationId&&u.add(y.correlationId);const f=Array.from(u).sort((y,v)=>{var I,S;const N=a.get(y)||[],g=a.get(v)||[],k=(I=N.find(j=>j.eventType==="hook_created"))==null?void 0:I.createdAt,C=(S=g.find(j=>j.eventType==="hook_created"))==null?void 0:S.createdAt;return!k||!C?0:new Date(k).getTime()-new Date(C).getTime()});let m=0;for(const y of f){const N=(a.get(y)||[]).find(E=>E.eventType==="hook_created");if(!N)continue;const g=h.length===1?h[0]:h[m];if(m++,!g)continue;const k="completed",C=new Date(N.createdAt).toISOString(),I=new Date(N.createdAt).toISOString(),S={nodeId:g.id,attemptNumber:1,status:k,startedAt:C,completedAt:I,duration:0},j=r.get(g.id)||[];r.set(g.id,[...j,S]),n.includes(g.id)||n.push(g.id)}const w=s.get(He.awaitWebhook)||[],b=new Set;for(const y of e)y.eventType==="hook_received"&&y.correlationId&&b.add(y.correlationId);let x=0;for(const y of f){const v=w.length===1?w[0]:w[x];if(x++,!v)continue;const N=a.get(y)||[],g=N.find(D=>D.eventType==="hook_created"),k=N.find(D=>D.eventType==="hook_received");let C,I,S,j=0;k?(C="completed",I=g?new Date(g.createdAt).toISOString():new Date(k.createdAt).toISOString(),S=new Date(k.createdAt).toISOString(),j=new Date(S).getTime()-new Date(I).getTime()):g?(C="running",I=new Date(g.createdAt).toISOString()):C="pending";const E={nodeId:v.id,attemptNumber:1,status:C,startedAt:I,completedAt:S,duration:j},M=r.get(v.id)||[];r.set(v.id,[...M,E]),n.includes(v.id)||n.push(v.id)}return i}function Il(e,s,r,n,o,a,i){var p;let l="pending";e.status==="completed"?l="completed":e.status==="failed"?l="failed":e.status==="running"&&(l="running");for(const d of r){const h={nodeId:d.id,attemptNumber:1,status:l,startedAt:e.startedAt?new Date(e.startedAt).toISOString():void 0,completedAt:e.completedAt&&(l==="completed"||l==="failed")?new Date(e.completedAt).toISOString():void 0};o.set(d.id,[h]),a.includes(d.id)||a.push(d.id)}for(const d of s){const h=Tt(d.stepName);if(!h)continue;const u=n.get(h);if(!u||u.length===0)continue;const f=u[0];let m;switch(d.status){case"completed":m="completed";break;case"failed":m="failed";break;case"running":m="running";break;case"cancelled":m="cancelled";break;case"pending":default:m="pending";break}const w=d.completedAt&&d.startedAt?new Date(d.completedAt).getTime()-new Date(d.startedAt).getTime():void 0,b={nodeId:f.id,stepId:d.stepId,attemptNumber:d.attempt,status:m,startedAt:d.startedAt?new Date(d.startedAt).toISOString():void 0,completedAt:d.completedAt?new Date(d.completedAt).toISOString():void 0,duration:w,input:d.input,output:d.output,error:d.error},x=o.get(f.id)||[];o.set(f.id,[...x,b]),a.includes(f.id)||a.push(f.id)}for(const d of i){const h=((p=d.metadata)==null?void 0:p.isToolsCollection)===!0;if(d.data.nodeKind==="tool"&&h&&!o.has(d.id)){const u={nodeId:d.id,attemptNumber:1,status:l,startedAt:e.startedAt?new Date(e.startedAt).toISOString():void 0,completedAt:e.completedAt&&(l==="completed"||l==="failed")?new Date(e.completedAt).toISOString():void 0};o.set(d.id,[u]),a.includes(d.id)||a.push(d.id)}}}function El(e,s,r,n){var i,l,p;const o=e.nodes.filter(d=>d.data.nodeKind==="conditional"),a=new Map;for(const d of e.nodes){const h=(i=d.metadata)==null?void 0:i.conditionalId;if(h){const u=a.get(h)||{thenNodes:[],elseNodes:[]};((l=d.metadata)==null?void 0:l.conditionalBranch)==="Then"?u.thenNodes.push(d):((p=d.metadata)==null?void 0:p.conditionalBranch)==="Else"&&u.elseNodes.push(d),a.set(h,u)}}for(const d of o){const h=d.id.match(/^(cond_\d+)_node$/);if(!h)continue;const u=h[1],f=a.get(u);if(!f)continue;const m=f.thenNodes.some(b=>s.has(b.id)),w=f.elseNodes.some(b=>s.has(b.id));if(m||w){const b=[...f.thenNodes,...f.elseNodes];if(!s.has(d.id)){let x;for(const N of b){const g=s.get(N.id);if(g&&g.length>0){const k=g[0];k.startedAt&&(!x||k.startedAt<x)&&(x=k.startedAt)}}const y=n.startedAt?new Date(n.startedAt).toISOString():void 0,v={nodeId:d.id,attemptNumber:1,status:"completed",startedAt:x||y,completedAt:x||y};s.set(d.id,[v])}if(!r.includes(d.id)){const x=b.map(y=>r.indexOf(y.id)).filter(y=>y>=0);if(x.length>0){const y=Math.min(...x);y>=0&&y<r.length?r.splice(y,0,d.id):r.push(d.id)}else r.push(d.id)}}}}function Tl(e,s,r,n){const o=new Map,a=[];let i;console.log("[Graph Mapper] Mapping run to execution:",{runId:e.runId,workflowName:e.workflowName,graphNodes:n.nodes.length,stepsCount:s.length}),Nl(e,n,a,o);const l=[...s].sort((g,k)=>new Date(g.createdAt).getTime()-new Date(k.createdAt).getTime());console.log("[Graph Mapper] Sorted steps:",l.map(g=>({stepId:g.stepId,stepName:g.stepName,attempt:g.attempt,status:g.status,createdAt:g.createdAt})));const{byStepId:p,byFunctionName:d,primitivesByLabel:h,agentNodes:u,toolNodes:f}=wl(n.nodes);console.log("[Graph Mapper] Graph nodes by stepId:",{allGraphNodes:n.nodes.map(g=>({id:g.id,stepId:g.data.stepId,normalizedStepId:g.data.stepId?Et(g.data.stepId):void 0,nodeKind:g.data.nodeKind})),nodesByStepId:Array.from(p.entries()).map(([g,k])=>({stepId:g,nodeIds:k.map(C=>C.id)}))});const m=new Map;let w=[],b=null,x=null;for(let g=0;g<=l.length;g++){const k=l[g];if(!k||k.stepId!==b){if(w.length>0&&x){const I=Sl(w,x,p,d,m,o,a);I&&(i=I)}k&&(w=[k],b=k.stepId,x=k.stepName)}else w.push(k)}const y=Cl(r,h,o,a);y&&(i=y),Il(e,l,u,f,o,a,n.nodes),El(n,o,a,e),kl(e,n,a,o);const v=jl(a,n,o),N={runId:e.runId,status:e.status,nodeExecutions:o,edgeTraversals:v,currentNode:i,executionPath:a};return console.log("[Graph Mapper] Mapping complete:",{executionPath:a,nodeExecutionsCount:o.size,nodeExecutions:Array.from(o.entries()).map(([g,k])=>{var C;return{nodeId:g,executionCount:k.length,latestStatus:(C=k[k.length-1])==null?void 0:C.status}})}),N}const Je=4;function Al(e,s,r,n){const[o,a]=c.useState([]),[i,l]=c.useState(!1),[p,d]=c.useState(null),h=c.useRef(null),u=c.useRef(0);return c.useEffect(()=>{if(a([]),d(null),u.current=0,!s){l(!1);return}let f=!0;const m=new AbortController;h.current=m,l(!0);const w=no();return(async()=>{try{const x=await pi(e,s,void 0,m.signal),y=n?await co(n):void 0,v=x.getReader();let N=new Uint8Array(0);const g=k=>{const C=new Uint8Array(N.length+k.length);C.set(N,0),C.set(k,N.length),N=C};for(;!m.signal.aborted;){const{value:k,done:C}=await v.read();if(C){f&&l(!1);break}for(g(k);N.length>=Je;){const S=new DataView(N.buffer,N.byteOffset,N.byteLength).getUint32(0,!1);if(N.length<Je+S)break;const j=N.slice(Je,Je+S);N=N.slice(Je+S);try{const{format:E,payload:M}=to(j);let D;if(E===so.ENCRYPTED){if(!y){f&&(d("This stream is encrypted. Click Decrypt to view."),l(!1)),v.cancel().catch(()=>{});return}D=await uo(y,M)}else D=j;const A=ro(D,w);if(f&&A!==void 0&&A!==null){const P=u.current++,U=typeof A=="string"?A:JSON.stringify(A,null,2);a(O=>[...O,{id:P,text:U}])}}catch(E){console.error("Failed to process stream frame:",E)}}}}catch(x){if(m.signal.aborted)return;f&&(d(x instanceof Error?x.message:String(x)),l(!1))}})(),()=>{f=!1,h.current&&h.current.abort()}},[e,s,r,n]),{chunks:o,isLive:i,error:p}}const Dl=100,Rl=100;function Ml(e,s,r={}){const{sortOrder:n="asc",encryptionKey:o,enabled:a=!0}=r,[i,l]=c.useState([]),[p,d]=c.useState(!0),[h,u]=c.useState(null),[f,m]=c.useState(),[w,b]=c.useState(!1),[x,y]=c.useState(!1),v=c.useRef(!1),N=c.useRef(o);N.current=o;const g=c.useCallback(async()=>{if(!v.current){v.current=!0,d(!0),u(null),l([]),m(void 0),b(!1);try{const{error:C,result:I}=await ue(Ke(e,s,{sortOrder:n,limit:Dl,withData:!1}));if(C)u(C);else{const S=I.data.map(pe),j=N.current;if(j){const E=await Promise.all(S.map(M=>ze(M,j)));l(E)}else l(S);m(I.hasMore?I.cursor:void 0),b(!!I.hasMore)}}catch(C){u(C)}finally{d(!1),v.current=!1}}},[e,s,n]);c.useEffect(()=>{a&&g()},[g,a]),c.useEffect(()=>{if(!o||i.length===0)return;let C=!1;return Promise.all(i.map(I=>ze(I,o))).then(I=>{C||l(I)}).catch(()=>{}),()=>{C=!0}},[o]);const k=c.useCallback(async()=>{if(!(x||!f)){y(!0);try{const{error:C,result:I}=await ue(Ke(e,s,{cursor:f,sortOrder:n,limit:Rl,withData:!1}));if(C)u(C);else{if(I.data.length>0){const S=I.data.map(pe),j=N.current;if(j){const E=await Promise.all(S.map(M=>ze(M,j)));l(M=>[...M,...E])}else l(E=>[...E,...S])}m(I.hasMore?I.cursor:void 0),b(!!I.hasMore)}}catch(C){u(C)}finally{y(!1)}}},[e,s,n,f,x]);return{events:i,loading:p,error:h,hasMore:w,loadingMore:x,loadMore:k}}function _l({hasError:e,errorMessage:s}){return t.jsx("div",{className:"flex items-center gap-2",children:t.jsxs(nr,{children:[t.jsx(or,{asChild:!0,children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:`w-2 h-2 rounded-full ${e?"bg-red-500":"bg-green-500 animate-pulse"}`}),t.jsx("span",{className:`text-xs $
34
+ hasError
35
+ ? 'text-red-600 dark:text-red-400'
36
+ : 'text-muted-foreground'`,children:e?"Error":"Live"})]})}),t.jsx(ar,{children:t.jsx("p",{children:e?`Error updating data: ${s}`:`Content updates every ${oo/1e3} seconds`})})]})})}function Bs(e){return e==="retrying"?"running":e}function Ll({data:e,selected:s}){var n,o,a,i;const r=e;return t.jsxs("div",{className:`relative ${r.className||""}`,style:{borderWidth:((n=r.nodeStyle)==null?void 0:n.borderWidth)??2,borderRadius:8,padding:12,width:220,borderStyle:"solid",backgroundColor:(o=r.nodeStyle)==null?void 0:o.backgroundColor,borderColor:((a=r.nodeStyle)==null?void 0:a.borderColor)??"#9ca3af",opacity:(i=r.nodeStyle)==null?void 0:i.opacity,boxShadow:s?"0 0 0 2px rgba(168, 85, 247, 0.5)":void 0},children:[r.label,t.jsx(ve,{type:"target",position:ye.Top,className:"!bg-purple-500"}),t.jsx(ve,{type:"source",position:ye.Bottom,className:"!bg-purple-500"}),t.jsx(ve,{type:"source",position:ye.Left,id:"loop-out",className:"!bg-purple-500 !-left-1 !w-[6px] !h-[6px] !min-w-0 !min-h-0",style:{top:"30%"}}),t.jsx(ve,{type:"target",position:ye.Left,id:"loop-in",className:"!bg-purple-500 !-left-1 !w-[6px] !h-[6px] !min-w-0 !min-h-0",style:{top:"70%"}})]})}function Ol({data:e,selected:s}){var a,i,l,p;const r=e,n=r.nodeKind==="workflow_start",o=r.nodeKind==="workflow_end";return t.jsxs("div",{className:`relative ${r.className||""}`,style:{borderWidth:((a=r.nodeStyle)==null?void 0:a.borderWidth)??2,borderRadius:8,padding:12,width:220,borderStyle:"solid",backgroundColor:(i=r.nodeStyle)==null?void 0:i.backgroundColor,borderColor:((l=r.nodeStyle)==null?void 0:l.borderColor)??"#9ca3af",opacity:(p=r.nodeStyle)==null?void 0:p.opacity,boxShadow:s?"0 0 0 2px rgba(59, 130, 246, 0.35)":void 0},children:[r.label,!n&&t.jsx(ve,{type:"target",position:ye.Top,className:"!bg-muted"}),!o&&t.jsx(ve,{type:"source",position:ye.Bottom,className:"!bg-muted"})]})}function Fl({data:e,selected:s}){var o,a,i;const r=e,n=160;return t.jsxs("div",{className:`relative flex items-center justify-center ${r.className||""}`,style:{width:n,height:n},children:[t.jsx("div",{style:{width:n*.7,height:n*.7,transform:"rotate(45deg)",borderWidth:2,borderStyle:"solid",borderRadius:4,backgroundColor:(o=r.nodeStyle)==null?void 0:o.backgroundColor,borderColor:((a=r.nodeStyle)==null?void 0:a.borderColor)??"#ef4444",opacity:(i=r.nodeStyle)==null?void 0:i.opacity,boxShadow:s?"0 0 0 2px rgba(239, 68, 68, 0.5)":void 0}}),t.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-auto",style:{fontSize:11,fontWeight:600,padding:n*.25},title:typeof r.label=="string"?r.label:void 0,children:t.jsx("span",{className:"text-center line-clamp-3 overflow-hidden",children:r.label})}),t.jsx(ve,{type:"target",position:ye.Top,className:"!bg-red-500"}),t.jsx(ve,{type:"source",position:ye.Bottom,id:"bottom",className:"!bg-red-500"}),t.jsx(ve,{type:"source",position:ye.Left,id:"left",className:"!bg-red-500"}),t.jsx(ve,{type:"source",position:ye.Right,id:"right",className:"!bg-red-500"})]})}const Pl={loopNode:Ll,parallelGroup:bn,executionNode:Ol,diamondNode:Fl},Wl=yn(In);function $l(e,s){const r=Sn(e);if(!s||s.length===0)return{color:"hsl(var(--card-foreground))",backgroundColor:r,borderColor:"#9ca3af",opacity:.4};const n=s[s.length-1];let o="#9ca3af",a=2;switch(n.status){case"completed":o="#22c55e";break;case"failed":o="#ef4444",a=3;break;case"running":o="#3b82f6",a=2;break;case"retrying":o="#f97316";break;case"cancelled":o="#eab308";break;case"pending":o="#9ca3af";break}return{color:"hsl(var(--card-foreground))",backgroundColor:r,borderColor:o,borderWidth:a}}function Vs(e,s,r){const n=t.jsxs("div",{className:"flex items-start gap-2 w-full overflow-hidden",children:[t.jsx("div",{className:"flex-shrink-0",children:Cn(e.nodeKind,e.label)}),t.jsx("span",{className:"text-sm font-medium break-words whitespace-normal leading-tight flex-1 min-w-0",children:e.label})]});if(!r||r.length===0)return n;const o=r[r.length-1],a=r.length,i=a>1;return i||o.duration&&o.duration>0?t.jsxs("div",{className:"flex flex-col gap-1.5 w-full",children:[n,t.jsxs("div",{className:"flex flex-wrap gap-1 text-xs",children:[i&&t.jsxs(jt,{variant:"outline",className:"text-xs px-1.5 py-0 border-orange-500 text-orange-700 dark:text-orange-300",children:["↻ ",a,"x"]}),o.duration&&o.duration>0&&t.jsxs(jt,{variant:"secondary",className:"text-xs px-1.5 py-0 bg-black/10 dark:bg-white/15 border-0",children:["⏱ ",Fe(o.duration,!0)]})]})]}):n}const Xr={...Nn};function zs(e,s){var p,d,h;const{nodes:r,groupNodes:n}=Qs(e,Xr),o=new Map,a=new Map;for(const u of n)u.id.startsWith("group_")&&a.set(u.id,u.position);for(const u of r){const f=(p=u.metadata)!=null&&p.parallelGroupId?`group_${u.metadata.parallelGroupId}`:null;f&&a.has(f)&&o.set(u.id,f)}const i=[],l=n.filter(u=>u.id.startsWith("group_"));for(const u of l)i.push({id:u.id,type:"parallelGroup",position:u.position,style:{...u.style,cursor:"grab",zIndex:-1},data:u.data,selectable:!0,draggable:!0});for(const u of r){const f=s==null?void 0:s.nodeExecutions.get(u.id),m=$l(u.data.nodeKind,f),w=(s==null?void 0:s.currentNode)===u.id,b=!!((d=u.metadata)!=null&&d.loopId),x=!!((h=u.metadata)!=null&&h.loopIsAwait),y=u.data.nodeKind==="conditional",v=y?"diamondNode":b?"loopNode":"executionNode",N=o.get(u.id);let g=u.position;if(N){const C=a.get(N);C&&(g={x:u.position.x-C.x,y:u.position.y-C.y})}const k=w?"animate-pulse-subtle":"";b?i.push({id:u.id,type:v,position:g,parentId:N,extent:N?"parent":void 0,expandParent:!0,data:{...u.data,label:Vs(u.data,u.metadata,f),executions:f,isLoopNode:!0,isAwaitLoop:x,nodeStyle:m,className:k}}):y?i.push({id:u.id,type:v,position:g,parentId:N,extent:N?"parent":void 0,expandParent:!0,data:{...u.data,label:u.data.label,executions:f,nodeStyle:m,className:k}}):i.push({id:u.id,type:v,position:g,parentId:N,extent:N?"parent":void 0,expandParent:!0,data:{...u.data,label:Vs(u.data,u.metadata,f),executions:f,nodeStyle:m,className:k},style:{width:220}})}return i}function Ks(e,s){const{additionalEdges:r}=Qs(e,Xr),o=[...e.edges.map(i=>i.type==="loop"?{...i,id:`loop_back_${i.source}_${i.target}`,isOriginal:!0}:{...i,isOriginal:!0}),...r.map(i=>({...i,isOriginal:!1}))];return kn(o,e.nodes).map(i=>{if(i.type==="selfLoop")return{id:i.id,source:i.source,target:i.target,sourceHandle:i.sourceHandle,targetHandle:i.targetHandle,type:"selfLoop",label:i.label,markerEnd:{type:ps.ArrowClosed,width:12,height:12,color:"#a855f7"}};let l=s==null?void 0:s.edgeTraversals.get(i.id);if(!l&&i.isConsolidated&&i.originalEdgeIds)for(const I of i.originalEdgeIds){const S=s==null?void 0:s.edgeTraversals.get(I);if(S&&S.traversalCount>0){l=S;break}}const p=l&&l.traversalCount>0,d=!!s,h=l!=null&&l.timings.length?l.timings.reduce((I,S)=>I+S,0)/l.timings.length:void 0;let u="bezier",f,m=i.label,w=!1;switch(i.type){case"parallel":u="smoothstep",f="4,4",m=void 0;break;case"loop":u="step",f="8,4";break;case"conditional":u="smoothstep",f="8,4",w=!0;break;default:u="bezier"}const x=p?"#22c55e":"#6b7280",y=p?void 0:f,v=d&&!p?.35:1,N=p?2.5:1,g=w?"#ffffff":"#6b7280",k=w?"#374151":"#f3f4f6",C=w?"#4b5563":"#d1d5db";return{id:i.id,source:i.source,target:i.target,type:u,animated:p&&(s==null?void 0:s.status)==="running",label:l&&l.traversalCount>1?t.jsxs("div",{className:"flex flex-col items-center gap-0.5",children:[t.jsxs(jt,{variant:"secondary",className:"text-xs px-1.5 py-0",children:[l.traversalCount,"×"]}),h&&h>0&&t.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["~",Fe(h,!0)]})]}):m,labelStyle:{fill:g,fontWeight:500,fontSize:"11px"},labelBgStyle:{fill:k,fillOpacity:.95,stroke:C,strokeWidth:1},labelBgPadding:[4,6],labelBgBorderRadius:4,markerEnd:{type:ps.ArrowClosed,width:p?14:10,height:p?14:10,color:x},style:{strokeWidth:N,stroke:x,opacity:v,strokeDasharray:y}}})}function Hl({selectedNode:e,env:s,onClose:r}){const{node:n,executions:o,stepId:a,runId:i}=e,l=o[o.length-1],p=o.length>1,{data:d,loading:h}=mr(s??{},"step",a??"",{runId:i}),u=(d==null?void 0:d.input)??(l==null?void 0:l.input),f=(d==null?void 0:d.output)??(l==null?void 0:l.output),m=(d==null?void 0:d.error)??(l==null?void 0:l.error);return t.jsxs("div",{className:"h-full flex flex-col bg-background border-l",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b flex-none",children:[t.jsx("span",{className:"text-xs font-medium truncate flex-1",title:n.data.label,children:n.data.label}),t.jsxs("div",{className:"flex items-center gap-2 flex-none",children:[(l==null?void 0:l.duration)!==void 0&&l.duration>0&&t.jsx("span",{className:"text-[10px] font-mono text-muted-foreground bg-muted px-1.5 py-0.5 rounded",children:Fe(l.duration)}),t.jsx("div",{className:"w-px h-4 bg-border"}),t.jsx("button",{type:"button",onClick:r,className:"p-1 rounded hover:bg-muted transition-colors","aria-label":"Close panel",children:t.jsx(Xs,{className:"h-4 w-4 text-muted-foreground"})})]})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto p-3 min-h-0",children:[t.jsxs("div",{className:"flex flex-col divide-y rounded-lg border overflow-hidden mb-3",children:[t.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1.5",children:[t.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:"type"}),t.jsx("span",{className:"text-[11px] font-mono",children:n.data.nodeKind})]}),l&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1.5",children:[t.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:"status"}),t.jsx(zt,{status:Bs(l.status)})]}),l.duration!==void 0&&l.duration>0&&t.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1.5",children:[t.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:"duration"}),t.jsx("span",{className:"text-[11px] font-mono",children:Fe(l.duration)})]}),p&&t.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1.5",children:[t.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:"attempts"}),t.jsx("span",{className:"text-[11px] font-mono",children:o.length})]}),l.startedAt&&t.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1.5",children:[t.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:"startedAt"}),t.jsx("span",{className:"text-[11px] font-mono",children:new Date(l.startedAt).toLocaleString()})]}),l.completedAt&&t.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1.5",children:[t.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:"completedAt"}),t.jsx("span",{className:"text-[11px] font-mono",children:new Date(l.completedAt).toLocaleString()})]})]})]}),h&&a&&t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground mb-3",children:[t.jsx(rs,{className:"h-3 w-3 animate-spin"}),t.jsx("span",{children:"Loading step data..."})]}),u!==void 0&&t.jsxs("details",{className:"group mb-3",children:[t.jsxs("summary",{className:"cursor-pointer rounded-md border px-2.5 py-1.5 text-xs hover:brightness-95 bg-muted/50",children:[t.jsx("span",{className:"font-medium",children:"Input"}),t.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",Array.isArray(u)?u.length:1," args)"]})]}),t.jsxs("div",{className:"relative pl-6 mt-3",children:[t.jsx("div",{className:"absolute left-3 -top-3 w-px h-3 bg-border"}),t.jsx("div",{className:"absolute left-3 top-0 w-3 h-3 border-l border-b rounded-bl-lg border-border"}),t.jsx("pre",{className:"text-[11px] overflow-x-auto rounded-md border p-2.5 bg-muted/30 max-h-64 overflow-y-auto",children:t.jsx("code",{children:JSON.stringify(u,null,2)})})]})]}),f!==void 0&&t.jsxs("details",{className:"group mb-3",children:[t.jsx("summary",{className:"cursor-pointer rounded-md border px-2.5 py-1.5 text-xs hover:brightness-95 bg-muted/50",children:t.jsx("span",{className:"font-medium",children:"Output"})}),t.jsxs("div",{className:"relative pl-6 mt-3",children:[t.jsx("div",{className:"absolute left-3 -top-3 w-px h-3 bg-border"}),t.jsx("div",{className:"absolute left-3 top-0 w-3 h-3 border-l border-b rounded-bl-lg border-border"}),t.jsx("pre",{className:"text-[11px] overflow-x-auto rounded-md border p-2.5 bg-muted/30 max-h-64 overflow-y-auto",children:t.jsx("code",{children:JSON.stringify(f,null,2)})})]})]}),m&&t.jsxs("details",{className:"group mb-3",open:!0,children:[t.jsx("summary",{className:"cursor-pointer rounded-md border border-red-300 bg-red-50 dark:bg-red-950/20 px-2.5 py-1.5 text-xs hover:brightness-95",children:t.jsx("span",{className:"font-medium text-red-600 dark:text-red-400",children:"Error"})}),t.jsxs("div",{className:"relative pl-6 mt-3",children:[t.jsx("div",{className:"absolute left-3 -top-3 w-px h-3 bg-red-300"}),t.jsx("div",{className:"absolute left-3 top-0 w-3 h-3 border-l border-b rounded-bl-lg border-red-300"}),t.jsx("pre",{className:"text-[11px] overflow-x-auto rounded-md border border-red-200 p-2.5 bg-red-50 dark:bg-red-950/20 text-red-700 dark:text-red-300 whitespace-pre-wrap max-h-64 overflow-y-auto",children:t.jsx("code",{children:typeof m=="object"?JSON.stringify(m,null,2):String(m)})})]})]}),p&&t.jsxs("details",{className:"group",children:[t.jsxs("summary",{className:"cursor-pointer rounded-md border px-2.5 py-1.5 text-xs hover:brightness-95 bg-muted/50",children:[t.jsx("span",{className:"font-medium",children:"Attempt History"}),t.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",o.length," attempts)"]})]}),t.jsxs("div",{className:"relative pl-6 mt-3",children:[t.jsx("div",{className:"absolute left-3 -top-3 w-px h-3 bg-border"}),t.jsx("div",{className:"absolute left-3 top-0 w-3 h-3 border-l border-b rounded-bl-lg border-border"}),t.jsx("div",{className:"flex flex-col divide-y rounded-md border overflow-hidden",children:o.map(w=>t.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1.5 text-[11px]",children:[t.jsxs("span",{className:"text-muted-foreground",children:["Attempt ",w.attemptNumber]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(zt,{status:Bs(w.status)}),w.duration!==void 0&&w.duration>0&&t.jsx("span",{className:"font-mono text-muted-foreground",children:Fe(w.duration)})]})]},w.attemptNumber))})]})]})]})]})}function Bl({workflow:e,execution:s,env:r,onNodeClick:n}){const[o,a]=c.useState(null),i=320,l=c.useMemo(()=>zs(e,s),[e,s]),p=c.useMemo(()=>Ks(e,s),[e,s]),[d,h,u]=xn(l),[f,m,w]=gn(p);c.useEffect(()=>{h(y=>{const v=zs(e,s),N=new Map(y.map(g=>[g.id,g.position]));return v.map(g=>({...g,position:N.get(g.id)??g.position}))}),m(Ks(e,s))},[e,s,h,m]);const b=c.useCallback((y,v)=>{const N=e.nodes.find(g=>g.id===v.id);if(N){const g=v.data.executions||[],k=g[g.length-1];a({nodeId:v.id,node:N,executions:g,stepId:k==null?void 0:k.stepId,runId:s==null?void 0:s.runId}),n&&g.length>0&&n(v.id,g)}},[e.nodes,s==null?void 0:s.runId,n]),x=c.useCallback(()=>{a(null)},[]);return t.jsxs("div",{className:"h-full w-full border rounded-lg bg-background relative overflow-hidden flex",children:[t.jsx("div",{className:"h-full flex-1 min-w-0",style:{width:o?`calc(100% - ${i}px)`:"100%"},children:t.jsxs(vn,{nodes:d,edges:f,onNodesChange:u,onEdgesChange:w,onNodeClick:b,nodeTypes:Pl,edgeTypes:Wl,fitView:!0,minZoom:.1,maxZoom:2,defaultViewport:{x:0,y:0,zoom:1},proOptions:{hideAttribution:!0},children:[t.jsx(wn,{}),t.jsx(jn,{}),t.jsx(fs,{position:"top-left",className:"bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 border rounded-lg p-2 text-xs",children:t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("div",{className:"font-semibold text-[10px] text-muted-foreground mb-1",children:"Status"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-6 h-4 rounded border-2 border-green-500 bg-background"}),t.jsx("span",{children:"Completed"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-6 h-4 rounded border-2 border-red-500 bg-background"}),t.jsx("span",{children:"Failed"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-6 h-4 rounded border-2 border-blue-500 bg-background"}),t.jsx("span",{children:"Running"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-6 h-4 rounded border-2 border-yellow-500 bg-background"}),t.jsx("span",{children:"Cancelled"})]}),t.jsxs("div",{className:"flex items-center gap-2 opacity-50",children:[t.jsx("div",{className:"w-6 h-4 rounded border-2 border-gray-400 bg-background"}),t.jsx("span",{children:"Pending"})]})]})}),s&&t.jsxs(fs,{position:"top-right",className:"bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 border rounded-lg p-3 text-xs space-y-1.5",children:[t.jsx("div",{className:"font-semibold text-sm",children:"Execution"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-muted-foreground",children:"Status:"}),t.jsx(jt,{variant:s.status==="completed"?"default":s.status==="failed"?"destructive":s.status==="cancelled"?"outline":"secondary",className:"text-xs",children:s.status})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-muted-foreground",children:"Progress:"}),t.jsxs("span",{className:"font-mono",children:[s.executionPath.length," / ",e.nodes.length]})]})]})]})}),o&&t.jsx("div",{className:"h-full flex-none",style:{width:i},children:t.jsx(Hl,{selectedNode:o,env:r,onClose:x})})]})}function Vl({run:e,allEvents:s,env:r}){const{manifest:n,loading:o,error:a}=Fn(),i=c.useMemo(()=>{var m;if(!n||!e.workflowName)return null;const d=String(e.workflowName).trim(),h=n.workflows[d];if(h)return h;const u=(m=Te(d))==null?void 0:m.shortName;return Object.values(n.workflows).find(w=>{var b;return w.workflowId===d||w.workflowName===d?!0:u?((b=Te(w.workflowName))==null?void 0:b.shortName)===u:!1})??null},[n,e.workflowName]),l=c.useMemo(()=>{if(!s)return[];const d=new Map;for(const h of s)if(h.eventType.startsWith("step_")&&h.correlationId){const u=d.get(h.correlationId);u?u.push(h):d.set(h.correlationId,[h])}return Array.from(d.values()).map(pr).filter(h=>h!==null)},[s]),p=c.useMemo(()=>!i||!e.runId?null:Tl(e,l,s||[],i),[i,e,l,s]);return o?t.jsxs("div",{className:"flex items-center justify-center w-full h-full",children:[t.jsx(rs,{className:"h-8 w-8 animate-spin text-muted-foreground"}),t.jsx("span",{className:"ml-4 text-muted-foreground",children:"Loading workflow graph..."})]}):a?t.jsx("div",{className:"flex items-center justify-center w-full h-full p-4",children:t.jsxs(Kt,{variant:"destructive",className:"max-w-lg",children:[t.jsx(bt,{className:"h-4 w-4"}),t.jsx(Ut,{children:"Error Loading Workflow Graph"}),t.jsx(Gt,{children:a.message})]})}):i?t.jsx(Bl,{workflow:i,execution:p||void 0,env:r}):t.jsx("div",{className:"flex items-center justify-center w-full h-full",children:t.jsxs(Kt,{className:"max-w-lg",children:[t.jsx(bt,{className:"h-4 w-4"}),t.jsx(Ut,{children:"Workflow Graph Not Found"}),t.jsx(Gt,{children:"Could not find the workflow graph for this run. The workflow may have been deleted or the graph manifest may need to be regenerated."})]})})}function zl({runId:e,selectedId:s}){var Re;const r=Qr(),[n]=Us(),{serverConfig:o}=ao(),[a,i]=c.useState(!1),[l,p]=c.useState(!1),[d,h]=c.useState(!1),[u,f]=c.useState(!1),m=c.useMemo(()=>({}),[]),w=n.get("tab")||"trace",b=n.get("streamId"),x=c.useCallback(z=>{const te=new URLSearchParams(n.toString());for(const[ne,se]of Object.entries(z))se===null?te.delete(ne):te.set(ne,se);r(`?${te.toString()}`,{preventScrollReset:!0})},[r,n]),y=c.useCallback(z=>{x(z==="trace"||z==="graph"?{tab:z,streamId:null}:{tab:z})},[x]),v=c.useCallback(z=>{x({streamId:z})},[x]),N=c.useCallback(z=>{x({tab:"streams",streamId:z})},[x]),g=c.useCallback(async(z,te)=>En(m,z,{correlationIds:[te]}),[m]),k=c.useRef(null),C=c.useCallback(async(z,te)=>{await Tn(m,z,te)},[m]),I=c.useCallback(async z=>{const{error:te,result:ne}=await ue(ms(m,z.runId,z.eventId,"all"));if(te)throw te;const se=k.current?await ze(ne,k.current):pe(ne);return"eventData"in se?se.eventData:null},[m]),S=c.useCallback(async(z,te)=>{const{error:ne,result:se}=await ue(ms(m,e,te,"all"));if(ne)throw ne;const ae=k.current?await ze(se,k.current):pe(se);return"eventData"in ae?ae.eventData:null},[m,e]),j=o.backendId==="local"||o.backendId==="@workflow/world-local",{run:E,events:M,loading:D,error:A,update:P,loadMoreTraceData:U,hasMoreTraceData:O,isLoadingMoreTraceData:L}=ui(m,e,{live:!0}),T=E??{},[F,G]=c.useState(null);k.current=F;const[B,q]=c.useState("asc"),{events:X,loading:J,hasMore:R,loadingMore:_,loadMore:H}=Ml(m,e,{sortOrder:B,encryptionKey:F??void 0,enabled:w==="events"}),[V,ee]=c.useState(null),{data:$,loading:W,error:Y,refresh:Z}=mr(m,(V==null?void 0:V.resource)??"run",(V==null?void 0:V.resourceId)??"",{runId:V==null?void 0:V.runId,enabled:!!(V!=null&&V.resource&&(V!=null&&V.resourceId)&&V.resource!=="hook"),encryptionKey:F??void 0}),[re,oe]=c.useState(!1),fe=c.useCallback(async()=>{if(F){Z();return}oe(!0);try{const{error:z,result:te}=await ue(io(m,e));if(z){_e.error(`Failed to fetch encryption key: ${z.message}`);return}if(!te){_e.error("Encryption is not configured for this deployment.");return}G(te),_e.success("Run data decrypted successfully")}finally{oe(!1)}},[F,m,e,Z]),$e=c.useCallback(z=>{ee(z)},[]),{streams:we,loading:Se,error:qe}=xi(m,e),{chunks:at,isLive:it,error:xe}=Al(m,b,e,F),lt=()=>{h(!0)},ct=async()=>{if(!a)try{i(!0),h(!1),await Ln(m,e),await P(),_e.success("Run cancelled successfully")}catch(z){console.error("Failed to cancel run:",z),_e.error("Failed to cancel run",{description:z instanceof Error?z.message:"An unknown error occurred"})}finally{i(!1)}},dt=()=>{f(!0)},ut=async()=>{if(!l)try{p(!0),f(!1);const z=await On(m,T.runId);_e.success("New run started successfully",{description:`Run ID: ${z}`}),r(`/run/${z}`)}catch(z){console.error("Failed to re-run workflow:",z),_e.error("Failed to start new run",{description:z instanceof Error?z.message:"An unknown error occurred"})}finally{p(!1),f(!1)}};if(A&&!E)return t.jsxs(Kt,{variant:"destructive",className:"m-4",children:[t.jsx(bt,{className:"h-4 w-4"}),t.jsx(Ut,{children:"Error loading workflow run"}),t.jsx(Gt,{children:A.message})]});const De=(Re=Te(T.workflowName))==null?void 0:Re.shortName;return t.jsxs(t.Fragment,{children:[t.jsx(Ms,{open:d,onOpenChange:h,children:t.jsxs(_s,{children:[t.jsxs(Ls,{children:[t.jsx(Fs,{children:"Cancel Workflow Run?"}),t.jsx(Ps,{children:"This will stop the workflow execution immediately, and no further steps will be executed. Partial workflow execution may occur. Are you sure you want to cancel the run?"})]}),t.jsxs(Os,{children:[t.jsx($s,{children:"Keep Running"}),t.jsx(Ws,{onClick:ct,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Cancel Run"})]})]})}),t.jsx(Ms,{open:u,onOpenChange:f,children:t.jsxs(_s,{children:[t.jsxs(Ls,{children:[t.jsx(Fs,{children:"Replay Run?"}),t.jsx(Ps,{children:"This can potentially re-run code that is meant to only execute once. Are you sure you want to replay the workflow run?"})]}),t.jsxs(Os,{children:[t.jsx($s,{children:"Cancel"}),t.jsx(Ws,{onClick:ut,children:"Replay Run"})]})]})}),t.jsxs("div",{className:"flex flex-col h-[calc(100vh-97px)]",children:[t.jsxs("div",{className:"flex-none space-y-4",children:[t.jsx(hl,{children:t.jsxs(xl,{children:[t.jsx(Hs,{children:t.jsx(gl,{asChild:!0,children:t.jsx(en,{to:"/",children:"Runs"})})}),t.jsx(yl,{}),t.jsx(Hs,{children:t.jsx(vl,{className:"font-mono text-xs",children:e})})]})}),t.jsxs("div",{className:"space-y-4 p-6 border rounded-lg",children:[t.jsxs("div",{className:"flex items-start justify-between",children:[t.jsx("div",{className:"mb-4",children:t.jsx("h1",{className:"text-xl font-semibold",children:De||t.jsx(Me,{className:"w-[260px] h-[28px]"})})}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx(_l,{hasError:!1,errorMessage:""}),t.jsx(An,{env:m,runId:e,runStatus:T.status,events:M,eventsLoading:D,loading:D,onRerunClick:dt,onCancelClick:lt,callbacks:{onSuccess:P}})]})]}),t.jsxs("div",{className:"flex items-start gap-8",children:[t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("div",{className:"text-xs text-muted-foreground",children:"Status"}),T.status?t.jsx(zt,{status:T.status,context:T}):t.jsx(Me,{className:"w-[55px] h-[24px]"})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("div",{className:"text-xs text-muted-foreground",children:"Duration"}),t.jsx("div",{className:"text-xs",children:T.runId?T.startedAt?(()=>{const z=(T.completedAt?new Date(T.completedAt).getTime():Date.now())-new Date(T.startedAt).getTime(),te=Math.floor(z/1e3);if(te<60)return`${te}s`;const ne=Math.floor(te/60),se=te%60;if(ne<60)return se>0?`${ne}m ${se}s`:`${ne}m`;const ae=Math.floor(ne/60),Ye=ne%60;return Ye>0?`${ae}h ${Ye}m`:`${ae}h`})():"-":t.jsx(Me,{className:"w-[60px] h-[20px]"})})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("div",{className:"text-xs text-muted-foreground",children:"Run ID"}),T.runId?t.jsx(Dn,{text:T.runId,children:t.jsx("div",{className:"text-xs mt-0.5 font-mono",children:T.runId})}):t.jsx(Me,{className:"w-[280px] h-[20px]"})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("div",{className:"text-xs text-muted-foreground",children:"Queued"}),T.createdAt?t.jsx("div",{className:"text-xs",children:t.jsx(ft,{date:T.createdAt})}):t.jsx(Me,{className:"w-[110px] h-[20px]"})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("div",{className:"text-xs text-muted-foreground",children:"Started"}),t.jsx("div",{className:"text-xs",children:T.runId?T.startedAt?t.jsx(ft,{date:T.startedAt}):"-":t.jsx(Me,{className:"w-[110px] h-[20px]"})})]}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("div",{className:"text-xs text-muted-foreground",children:"Completed"}),t.jsx("div",{className:"text-xs",children:T.runId?T.completedAt?t.jsx(ft,{date:T.completedAt}):"-":t.jsx(Me,{className:"w-[110px] h-[20px]"})})]}),T.expiredAt!=null&&t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs(nr,{children:[t.jsx(or,{asChild:!0,children:t.jsxs("div",{className:"text-xs text-muted-foreground cursor-help flex items-center gap-1",children:["Expired",t.jsx(po,{className:"w-3 h-3"})]})}),t.jsx(ar,{children:t.jsx("p",{children:"The storage data for this run has expired and is no longer available."})})]}),t.jsx("div",{className:"text-xs",children:t.jsx(ft,{date:T.expiredAt})})]})]})]})]}),t.jsx("div",{className:"mt-4 flex-1 flex flex-col min-h-0",children:t.jsxs(Rn,{value:w,onValueChange:z=>y(z),className:"flex-1 flex flex-col min-h-0",children:[t.jsxs(Mn,{className:"mb-4 flex-none",children:[t.jsxs(pt,{value:"trace",className:"gap-2",children:[t.jsx(Ft,{className:"h-4 w-4"}),"Trace"]}),j&&t.jsxs(pt,{value:"graph",className:"gap-2",children:[t.jsx(_n,{className:"h-4 w-4"}),"Graph"]}),t.jsxs(pt,{value:"events",className:"gap-2",children:[t.jsx(Ft,{className:"h-4 w-4"}),"Events"]}),t.jsxs(pt,{value:"streams",className:"gap-2",children:[t.jsx(Ft,{className:"h-4 w-4"}),"Streams"]})]}),t.jsx(mt,{value:"trace",className:"mt-0 flex-1 min-h-0",children:t.jsx(Be,{title:"Failed to load trace viewer",children:t.jsx("div",{className:"h-full",children:t.jsx(ni,{error:A,events:M,run:T,isLoading:D,spanDetailData:$,spanDetailLoading:W,spanDetailError:Y,onSpanSelect:$e,onStreamClick:N,onWakeUpSleep:g,onResolveHook:C,onLoadEventData:S,onLoadMoreSpans:U,hasMoreSpans:O,isLoadingMoreSpans:L,encryptionKey:F??void 0,onDecrypt:fe,isDecrypting:re})})})}),t.jsx(mt,{value:"events",className:"mt-0 flex-1 min-h-0",children:t.jsx(Be,{title:"Failed to load events list",children:t.jsx("div",{className:"h-full",children:t.jsx(Ho,{events:X,run:T,onLoadEventData:I,hasMoreEvents:R,isLoadingMoreEvents:_,onLoadMoreEvents:H,encryptionKey:F??void 0,isLoading:J,sortOrder:B,onSortOrderChange:q,onDecrypt:fe,isDecrypting:re})})})}),t.jsx(mt,{value:"streams",className:"mt-0 flex-1 min-h-0",children:t.jsx(Be,{title:"Failed to load stream data",children:t.jsxs("div",{className:"h-full flex gap-4",children:[t.jsxs("div",{className:"w-64 flex-shrink-0 border rounded-lg overflow-hidden",style:{borderColor:"var(--ds-gray-300)",backgroundColor:"var(--ds-background-100)"},children:[t.jsxs("div",{className:"px-3 py-2 border-b text-xs font-medium",style:{borderColor:"var(--ds-gray-300)",color:"var(--ds-gray-900)"},children:["Streams (",we.length,")"]}),t.jsx("div",{className:"overflow-auto max-h-[calc(100vh-400px)]",children:Se?t.jsx("div",{className:"p-4 flex items-center justify-center",children:t.jsx(rs,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):qe?t.jsx("div",{className:"p-4 text-xs text-destructive",children:qe.message}):we.length===0?t.jsx("div",{className:"p-4 text-xs",style:{color:"var(--ds-gray-600)"},children:"No streams found for this run"}):we.map(z=>t.jsx("button",{type:"button",onClick:()=>v(z),className:"w-full text-left px-3 py-2 text-xs font-mono truncate hover:bg-accent transition-colors",style:{backgroundColor:b===z?"var(--ds-gray-200)":"transparent",color:"var(--ds-gray-1000)"},title:z,children:z},z))})]}),t.jsx("div",{className:"flex-1 min-w-0",children:b?xe!=null&&xe.includes("encrypted")&&!F?t.jsxs("div",{className:"h-full flex flex-col items-center justify-center gap-3 rounded-lg border p-4",style:{borderColor:"var(--ds-gray-300)",backgroundColor:"var(--ds-gray-100)"},children:[t.jsx(er,{className:"h-6 w-6",style:{color:"var(--ds-gray-700)"}}),t.jsx("div",{className:"text-sm",style:{color:"var(--ds-gray-900)"},children:"This stream is encrypted."}),t.jsx(os,{onClick:fe,loading:re})]}):t.jsx(lo,{streamId:b,chunks:at,isLive:it,error:xe!=null&&xe.includes("encrypted")?null:xe}):t.jsx("div",{className:"h-full flex items-center justify-center rounded-lg border",style:{borderColor:"var(--ds-gray-300)",backgroundColor:"var(--ds-gray-100)"},children:t.jsx("div",{className:"text-sm",style:{color:"var(--ds-gray-600)"},children:we.length>0?"Select a stream to view its data":"No streams available"})})})]})})}),j&&t.jsx(mt,{value:"graph",className:"mt-0 flex-1 min-h-0",children:t.jsx(Be,{title:"Failed to load execution graph",children:t.jsx("div",{className:"h-full min-h-[500px]",children:t.jsx(Vl,{run:T,allEvents:M,env:m})})})})]})})]})]})}const Zl=tn(function(){const s=sn(),[r]=Us(),n=s.runId,o=r.get("stepId"),a=r.get("eventId"),i=r.get("hookId"),l=o||a||i||void 0;return t.jsx(Be,{title:"Failed to load run details",children:t.jsx(zl,{runId:n,selectedId:l})})});export{Zl as default};