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

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