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

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