@workflow/web 4.1.0-beta.45 → 4.1.0-beta.47
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.
- package/README.md +1 -1
- package/build/client/assets/{entry.client-BjpmGyLC.js → entry.client-BiVEcoV8.js} +1 -1
- package/build/client/assets/{highlighted-body-B3W2YXNL-DmGJDYCd.js → highlighted-body-B3W2YXNL-B2Qjtd6a.js} +1 -1
- package/build/client/assets/{home-Bg63MGns.js → home-3vHAnkef.js} +1 -1
- package/build/client/assets/{index-DklpUtP3.js → index-BmZS3y7B.js} +13 -13
- package/build/client/assets/manifest-54e6ae64.js +1 -0
- package/build/client/assets/{mermaid-3ZIDBTTL-ClWSYlBT.js → mermaid-3ZIDBTTL-BFtRJrXs.js} +4 -4
- package/build/client/assets/root-Qfp_mn5S.js +26 -0
- package/build/client/assets/root-aMfmV5uh.css +1 -0
- package/build/client/assets/run-detail-DTTdMaKq.js +37 -0
- package/build/client/assets/server-build-CiTtikBY.css +1 -0
- package/build/client/assets/{workflow-graph-viewer-RUyTSlHH.js → workflow-graph-viewer-kC8rw29h.js} +1 -1
- package/build/server/assets/{app-DMT28sgS.js → app-CnRXtjrV.js} +33 -8
- package/build/server/assets/{highlighted-body-B3W2YXNL-CKl1xXgz.js → highlighted-body-B3W2YXNL-Dbvlczoc.js} +2 -2
- package/build/server/assets/{index-BHIV6JOr.js → index-DymBv9ds.js} +10 -9
- package/build/server/assets/{mermaid-3ZIDBTTL-uTah_BkY.js → mermaid-3ZIDBTTL-DL0Nr5XO.js} +2 -2
- package/build/server/assets/{server-build-DiN0zpXF.js → server-build-VXKZr6Mi.js} +2614 -448
- package/build/server/assets/{token-fvUEOQRa.js → token-BV_eEV9j.js} +2 -2
- package/build/server/assets/{token-util-1mDJoKQG.js → token-util-ClsVcJbP.js} +2 -2
- package/build/server/index.js +2 -2
- package/package.json +6 -6
- package/build/client/assets/manifest-f52831b8.js +0 -1
- package/build/client/assets/root-CADywoAy.js +0 -26
- package/build/client/assets/root-DtrAdcW8.css +0 -1
- package/build/client/assets/run-detail-CX8hD4AT.js +0 -37
- package/build/client/assets/server-build-8B6V768r.css +0 -1
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import{j as t,r as a,f as Ut,A as _s,x as Ls,y as Dr,z as Ps,w as Fs,C as Os}from"./index-DklpUtP3.js";import{O as rt,C as Mr,Q as st,B as ze,j as Kt,q as _r,U as Lr,Z as $s,S as Pr,R as Fr,p as Ws,o as Hs,X as Bs,N as Qe,V as Vs,G as zs,I as ue,u as ht,W as _e,Y as Us,v as be,_ as yt,$ as Ks,t as Or,a0 as qs,s as Gs,a1 as It,w as qt,l as Zs,m as Ys,a2 as Xs,a3 as Js,a4 as Qs,r as en,A as tn,c as rn,d as sn,a as Ae,a5 as nn,F as on,e as an,b as ut,T as ln,K as cn,L as Tt,M as At,y as dn,a6 as un}from"./workflow-graph-viewer-RUyTSlHH.js";import{c as Nt,h as Ue,M as Q,Y as fn,N as ge,O as sr,U as vt,_ as mn,W as pn,X as Le,Z as hn,$ as xn,a0 as $r,a1 as Pe,a2 as ye,a3 as K,a4 as gn,a5 as yn,a6 as Rt,a7 as ce,a8 as ft,a9 as wt,aa as We,ab as Ee,ac as Wr,ad as Xe,ae as Dt,af as vn,ag as wn,ah as bn,ai as jn,aj as kn,ak as Nn,al as Cn,am as He,an as me,ao as Hr,l as Be,F as Wt,ap as En,aq as Sn,ar as Gt,E as Se,as as In,d as de,at as Br,au as Tn,av as An,aw as Rn,ax as Dn,T as Vr,a as zr,b as Ur,ay as Mn,u as _n,az as nr,aA as Ln,t as Re,L as Pn,aB as Fn}from"./mermaid-3ZIDBTTL-ClWSYlBT.js";import{importKey as On,decrypt as $n}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 Wn=[["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"}]],Hn=Nt("circle-question-mark",Wn);/**
|
|
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 Bn=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],Vn=Nt("info",Bn);/**
|
|
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 zn=[["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"}]],Mt=Nt("list",zn);/**
|
|
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 Un=[["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"}]],Kn=Nt("type",Un),qn="@keyframes wf-spinner-fade{0%{opacity:1}100%{opacity:.15}}";function Zt({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:qn}}),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 Gn=".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 Yt({decrypted:e=!1,loading:r=!1,onClick:s}){return t.jsxs(t.Fragment,{children:[t.jsx("style",{dangerouslySetInnerHTML:{__html:Gn}}),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(Zt,{size:14}):e?t.jsxs("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]}):t.jsxs("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),r?"Decrypting…":e?"Decrypted":"Decrypt"]})]})}function et(e){return e!=null&&typeof e=="object"&&"stack"in e&&typeof e.stack=="string"}function bt({value:e}){const r=Ue(),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(rt,{size:12})}),n&&t.jsxs("div",{className:"flex items-start gap-2 px-3 py-2.5 pr-10",style:{color:"var(--ds-red-900)",borderBottom:"1px solid var(--ds-red-400)"},children:[t.jsx(Mr,{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 Zn=".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 Yn({loading:e=!1,onClick:r,label:s="Load more",loadingLabel:n="Loading..."}){return t.jsxs(t.Fragment,{children:[t.jsx("style",{dangerouslySetInnerHTML:{__html:Zn}}),t.jsxs("button",{type:"button",onClick:r,disabled:e,className:"wf-load-more",children:[e&&t.jsx(Zt,{size:14}),e?n:s]})]})}const Xn=".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 Jn({options:e,value:r,onChange:s}){var c,u;const[n,o]=a.useState(!1),i=a.useRef(null),l=((c=e.find(d=>d.value===r))==null?void 0:c.label)??((u=e[0])==null?void 0:u.label)??"";return a.useEffect(()=>{if(!n)return;function d(p){i.current&&!i.current.contains(p.target)&&o(!1)}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[n]),t.jsxs("div",{ref:i,style:{position:"relative",flexShrink:0},children:[t.jsx("style",{dangerouslySetInnerHTML:{__html:Xn}}),t.jsxs("button",{type:"button",className:"wf-menu-btn",onClick:()=>o(!n),children:[t.jsx("span",{children:l}),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 Qn=[{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 Qn){const i=Math.floor(r/o);if((i>0||s.length>0)&&(s.push(`${i} ${n}${i!==1?"s":""}`),r%=o),s.length===3)break}return s.join(", ")}function to(e){const[r,s]=a.useState("");return a.useEffect(()=>{const n=()=>{const i=Date.now()-e,l=eo(i);s(l?`${l} ago`:"Just now")};n();const o=setInterval(n,1e3);return()=>clearInterval(o)},[e]),r}function or({date:e,zone:r}){var l;const s=new Date(e),n=((l=new Intl.DateTimeFormat("en-US",{timeZone:r,timeZoneName:"short"}).formatToParts(s).find(c=>c.type==="timeZoneName"))==null?void 0:l.value)||r,o=s.toLocaleString("en-US",{timeZone:r,year:"numeric",month:"long",day:"numeric"}),i=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:i})]})}function ro({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(or,{date:e,zone:"UTC"}),t.jsx(or,{date:e,zone:r})]})]})}const so=330,mt=8;function no({triggerRect:e,onMouseEnter:r,onMouseLeave:s,date:n}){const o=a.useRef(null),[i,l]=a.useState({position:"fixed",zIndex:9999,visibility:"hidden"});return a.useEffect(()=>{const c=e.top>240?"above":"below",u=e.left+e.width/2,d=o.current,p=d?d.offsetWidth:so,x=d?d.offsetHeight:100;let m=u-p/2;m=Math.max(mt,Math.min(m,window.innerWidth-p-mt));let f;c==="above"?(f=e.top-x-6,f<mt&&(f=e.bottom+6)):(f=e.bottom+6,f+x>window.innerHeight-mt&&(f=e.top-x-6)),l({position:"fixed",left:m,top:f,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]),Ut.createPortal(t.jsx("div",{ref:o,onMouseEnter:r,onMouseLeave:s,style:i,children:t.jsx(ro,{date:n})}),document.body)}function Kr({date:e,children:r}){const[s,n]=a.useState(!1),[o,i]=a.useState(null),l=a.useRef(null),c=a.useRef(null);a.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const u=e==null?null:typeof e=="number"?e:new Date(e).getTime();if(u==null||Number.isNaN(u))return t.jsx(t.Fragment,{children:r});const d=()=>{c.current&&(clearTimeout(c.current),c.current=null)},p=()=>{d(),c.current=setTimeout(()=>n(!1),120)},x=()=>{d(),l.current&&i(l.current.getBoundingClientRect()),n(!0)};return t.jsxs("span",{ref:l,onMouseEnter:x,onMouseLeave:p,style:{display:"inline-flex"},children:[r,s&&o&&t.jsx(no,{triggerRect:o,onMouseEnter:d,onMouseLeave:p,date:u})]})}const oo=new Set(["step_failed","step_retrying","run_failed","workflow_failed"]),qr={appearance:"none",WebkitAppearance:"none",border:"none",background:"transparent"},Gr="workflow-dot-pulse 1.25s cubic-bezier(0, 0, 0.2, 1) infinite";function ao(e){return e.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1})+"."+e.getMilliseconds().toString().padStart(3,"0")}function Zr(e){return e.split("_").map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}function io(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 lo(e,r){var o,i;const s=new Map;if(e){for(const l of e)if(l.eventType==="step_created"&&l.correlationId){const c=((o=l.eventData)==null?void 0:o.stepName)??"",u=st(String(c));s.set(l.correlationId,(u==null?void 0:u.shortName)??c)}}const n=r!=null&&r.workflowName?((i=ze(r.workflowName))==null?void 0:i.shortName)??r.workflowName:null;return{correlationNameMap:s,workflowName:n}}function co(e){const r=new Map,s=new Map,n=new Map;for(const o of e){const i=new Date(o.createdAt).getTime(),l=o.correlationId??"__run__",c=o.eventType;if((c==="step_created"||c==="run_created")&&r.set(l,i),c==="step_started"||c==="run_started"||c==="workflow_started"){s.set(l,i),r.has(l)||r.set(l,i);const u=r.get(l),d=n.get(l)??{};u!==void 0&&(d.queued=i-u),n.set(l,d)}if(c==="step_completed"||c==="step_failed"||c==="run_completed"||c==="run_failed"||c==="run_cancelled"||c==="workflow_completed"||c==="workflow_failed"||c==="wait_completed"||c==="hook_disposed"){const u=s.get(l),d=n.get(l)??{};u!==void 0&&(d.ran=i-u),n.set(l,d)}}return n}function Ht(e){if(!e||typeof e!="object")return!1;for(const r of Object.values(e))if(ge(r))return!0;return!1}function jt(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 tt=36,uo=20,_t="var(--ds-gray-500)";function ar({isFirst:e,isLast:r,isRunLevel:s,statusDotColor:n,pulse:o=!1,hasSelection:i,showBranch:l,showLaneLine:c,isLaneStart:u,isLaneEnd:d,continuationOnly:p=!1}){const x=s?8:6,m=s?5:6,f=i&&!l&&!s?.3:1;return t.jsxs("div",{className:"relative flex-shrink-0 self-stretch",style:{width:tt,minHeight:p?0:void 0},children:[t.jsx("div",{style:{position:"absolute",left:8,top:p?0:e?"50%":0,bottom:p?0:r?"50%":0,width:2,backgroundColor:_t,zIndex:0}}),!p&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{position:"absolute",left:m,top:"50%",transform:"translateY(-50%)",width:x,height:x,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*f,animation:Gr,zIndex:1}}),t.jsx("div",{style:{position:"relative",width:"100%",height:"100%",borderRadius:"50%",backgroundColor:n,opacity:f,transition:"opacity 150ms",zIndex:2}})]}),l&&t.jsx("div",{style:{position:"absolute",left:9,top:"50%",width:tt-9,height:2,backgroundColor:_t,zIndex:0}})]}),c&&t.jsx("div",{style:{position:"absolute",left:uo,top:p?0:u?"50%":0,bottom:p?0:d?"50%":0,width:2,backgroundColor:_t,zIndex:0}})]})}function ir({value:e,className:r,style:s}){const[n,o]=a.useState(!1),i=a.useRef(null);a.useEffect(()=>()=>{i.current!==null&&window.clearTimeout(i.current)},[]);const l=a.useCallback(c=>{c.stopPropagation(),navigator.clipboard.writeText(e).then(()=>{o(!0),i.current!==null&&window.clearTimeout(i.current),i.current=window.setTimeout(()=>{o(!1),i.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:l,className:"flex-shrink-0 opacity-0 group-hover/copy:opacity-100 transition-opacity p-0.5 rounded hover:bg-[var(--ds-gray-alpha-200)]",style:qr,"aria-label":`Copy ${e}`,children:n?t.jsx(_r,{className:"h-3 w-3",style:{color:"var(--ds-green-700)"}}):t.jsx(rt,{className:"h-3 w-3",style:{color:"var(--ds-gray-700)"}})}):null]})}function xt(e){if(typeof e=="string"){const r=e.trim();if(r.startsWith("{")&&r.endsWith("}")||r.startsWith("[")&&r.endsWith("]")||r.startsWith('"')&&r.endsWith('"'))try{return xt(JSON.parse(r))}catch{return e}return e}if(Array.isArray(e))return e.map(xt);if(e!==null&&typeof e=="object"){if(e.constructor!==Object)return e;const r={};for(const[s,n]of Object.entries(e))r[s]=xt(n);return r}return e}function fo(e,r){if(!r||!oo.has(r)||e==null||typeof e!="object")return null;const s=e;return et(s.error)?s.error:et(s)?s:null}function mo({data:e,eventType:r}){const s=a.useMemo(()=>fo(e,r),[e,r]),[n,o]=a.useState(!1),i=a.useRef(null),l=a.useMemo(()=>xt(e),[e]);a.useEffect(()=>()=>{i.current!==null&&window.clearTimeout(i.current)},[]);const c=a.useMemo(()=>{try{return JSON.stringify(l,null,2)}catch{return String(l)}},[l]),u=a.useCallback(d=>{d.stopPropagation(),navigator.clipboard.writeText(c).then(()=>{o(!0),i.current!==null&&window.clearTimeout(i.current),i.current=window.setTimeout(()=>{o(!1),i.current=null},1500)})},[c]);return s?t.jsx("div",{className:"p-2",children:t.jsx(bt,{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(vt,{data:l,expandLevel:2})}),t.jsx("button",{type:"button",onClick:u,className:"absolute bottom-2 right-2 opacity-0 group-hover/payload:opacity-100 transition-opacity flex items-center gap-1 px-2 py-1 rounded-md text-xs hover:bg-[var(--ds-gray-alpha-200)]",style:{...qr,color:"var(--ds-gray-700)"},"aria-label":"Copy payload",children:n?t.jsxs(t.Fragment,{children:[t.jsx(_r,{className:"h-3 w-3",style:{color:"var(--ds-green-700)"}}),t.jsx("span",{style:{color:"var(--ds-green-700)"},children:"Copied"})]}):t.jsxs(t.Fragment,{children:[t.jsx(rt,{className:"h-3 w-3"}),t.jsx("span",{children:"Copy"})]})})]})}const po=[{value:"desc",label:"Newest"},{value:"asc",label:"Oldest"}];function lr(){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:tt},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 ho({event:e,index:r,isFirst:s,isLast:n,isExpanded:o,onToggleExpand:i,activeGroupKey:l,selectedGroupKey:c,selectedGroupRange:u,correlationNameMap:d,workflowName:p,durationMap:x,onSelectGroup:m,onHoverGroup:f,onLoadEventData:_,cachedEventData:C,onCacheEventData:h,encryptionKey:j,onEncryptedDataDetected:v}){const[F,w]=a.useState(!1),[O,E]=a.useState(C),[S,k]=a.useState(null),[g,y]=a.useState(C!==null);a.useEffect(()=>{C!==null&&!j&&Ht(C)&&(v==null||v())},[]);const A=jt(e.eventType)?"__run__":e.correlationId??void 0,I=io(e.eventType),T=new Date(e.createdAt),P="eventData"in e&&e.eventData!=null,z=jt(e.eventType),L=z?p??"-":e.correlationId?d.get(e.correlationId)??"-":"-",R=e.correlationId??(z?"__run__":""),b=R?x.get(R):void 0,M=l!==void 0,q=A!==void 0&&A===l,W=M&&!q,G=M&&q,X=M&&q&&!z,J=u!==null&&r>=u.first&&r<=u.last,N=u!==null&&r===u.first,D=u!==null&&r===u.last,B=a.useCallback(async()=>{if(!(O!==null||P)){w(!0),k(null);try{if(!_){k("Event details unavailable");return}const $=await _(e);$!=null&&(E($),h(e.eventId,$),!j&&Ht($)&&(v==null||v()))}catch($){k($ instanceof Error?$.message:"Failed to load event details")}finally{w(!1),y(!0)}}},[e,O,P,_,h,j,v]);a.useEffect(()=>{o&&O===null&&!P&&!F&&!g&&B()},[]),a.useEffect(()=>{j&&g&&_&&(E(null),y(!1),_(e).then($=>{$!=null&&(E($),h(e.eventId,$)),y(!0)}).catch(()=>{y(!0)}))},[j]);const V=a.useCallback(()=>{m(A===c?void 0:A),i(e.eventId),!o&&O===null&&!P&&B()},[c,A,m,i,e.eventId,o,O,P,B]),ee=P?e.eventData:O,H=W?.3:1;return t.jsxs("div",{"data-event-id":e.eventId,onMouseEnter:()=>f(A),onMouseLeave:()=>f(void 0),children:[t.jsxs("div",{role:"button",tabIndex:0,onClick:V,onKeyDown:$=>{($.key==="Enter"||$.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(ar,{isFirst:s,isLast:n&&!o,isRunLevel:z,statusDotColor:I,pulse:G,hasSelection:M,showBranch:X,showLaneLine:J,isLaneStart:N,isLaneEnd:D}),t.jsxs("div",{className:"flex items-center flex-1 min-w-0",style:{opacity:H,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(Kt,{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(Kr,{date:T,children:t.jsx("span",{children:ao(T)})})}),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:[G&&t.jsx("span",{style:{position:"absolute",inset:0,borderRadius:"50%",backgroundColor:I,opacity:.75,animation:Gr}}),t.jsx("span",{style:{position:"relative",width:6,height:6,borderRadius:"50%",backgroundColor:I}})]}),Zr(e.eventType)]})}),t.jsx("div",{className:"min-w-0 px-4 overflow-hidden text-ellipsis whitespace-nowrap",style:{flex:"2 1 0%"},title:L!=="-"?L:void 0,children:L}),t.jsx(ir,{value:e.correlationId||"",className:"font-mono",style:{flex:"3 1 0%"}}),t.jsx(ir,{value:e.eventId,className:"font-mono",style:{flex:"3 1 0%"}})]})]}),o&&t.jsxs("div",{className:"flex",children:[t.jsx(ar,{isFirst:!1,isLast:n,isRunLevel:z,hasSelection:M,showBranch:!1,showLaneLine:J&&!D,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:H,transition:"opacity 150ms"},children:[((b==null?void 0:b.queued)!==void 0||(b==null?void 0:b.ran)!==void 0)&&t.jsxs("div",{className:"px-2 pb-1.5 text-xs flex gap-3",style:{color:"var(--ds-gray-900)"},children:[b.queued!==void 0&&b.queued>0&&t.jsxs("span",{children:["Queued for"," ",t.jsx("span",{className:"font-mono tabular-nums",children:sr(b.queued)})]}),b.ran!==void 0&&t.jsxs("span",{children:["Ran for"," ",t.jsx("span",{className:"font-mono tabular-nums",children:sr(b.ran)})]})]}),ee!=null?t.jsx(mo,{data:ee,eventType:e.eventType}):S?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:S}):F||!P&&!g&&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 xo({events:e,run:r,onLoadEventData:s,hasMoreEvents:n=!1,isLoadingMoreEvents:o=!1,onLoadMoreEvents:i,encryptionKey:l,isLoading:c=!1,sortOrder:u,onSortOrderChange:d,onDecrypt:p,isDecrypting:x=!1}){const[m,f]=a.useState("asc"),_=u??m,C=a.useCallback(H=>{d?d(H):f(H)},[d]),h=a.useMemo(()=>{if(!e||e.length===0)return[];const H=_==="desc"?-1:1;return[...e].sort(($,Y)=>H*(new Date($.createdAt).getTime()-new Date(Y.createdAt).getTime()))},[e,_]),j=a.useMemo(()=>{if(!e)return!1;for(const H of e){const $=H.eventData;if(Ht($))return!0}return!1},[e]),[v,F]=a.useState(!1),w=a.useCallback(()=>{F(!0)},[]),O=j||v,{correlationNameMap:E,workflowName:S}=a.useMemo(()=>lo(e??null,r??null),[e,r]),k=a.useMemo(()=>co(h),[h]),[g,y]=a.useState(void 0),[A,I]=a.useState(void 0),T=a.useCallback(H=>{y(H)},[]),P=a.useCallback(H=>{I(H)},[]),z=g??A,[L,R]=a.useState(()=>new Set),b=a.useCallback(H=>{R($=>{const Y=new Set($);return Y.has(H)?Y.delete(H):Y.add(H),Y})},[]),M=a.useRef(new Map),q=a.useCallback((H,$)=>{M.current.set(H,$)},[]),W=a.useMemo(()=>{const H=new Map;for(const $ of h){const Y=jt($.eventType)?"__run__":$.correlationId??"";Y&&H.set($.eventId,Y)}return H},[h]);a.useEffect(()=>{g!==void 0&&R(H=>{if(H.size===0)return H;let $=!1;const Y=new Set;for(const Z of H)W.get(Z)===g?Y.add(Z):$=!0;return $?Y:H})},[g,W]);const G=a.useMemo(()=>{if(!z||z==="__run__")return null;let H=-1,$=-1;for(let Y=0;Y<h.length;Y++)h[Y].correlationId===z&&(H===-1&&(H=Y),$=Y);return H>=0?{first:H,last:$}:null},[z,h]),[X,J]=a.useState(""),N=a.useRef(null),D=a.useMemo(()=>{const H=[];for(let $=0;$<h.length;$++){const Y=h[$],Z=jt(Y.eventType),se=Z?S??"":Y.correlationId?E.get(Y.correlationId)??"":"";H.push({fields:[Y.eventId,Y.correlationId??"",Y.eventType,Zr(Y.eventType),se].map(oe=>oe.toLowerCase()),groupKey:Y.correlationId??(Z?"__run__":void 0),eventId:Y.eventId,index:$})}return H},[h,E,S]);a.useEffect(()=>{var Z;const H=X.trim().toLowerCase();if(!H){y(void 0);return}let $=null,Y=0;for(const se of D)for(const oe of se.fields)if(oe&&oe.includes(H)){const fe=H.length/oe.length;fe>Y&&(Y=fe,$=se)}$&&(y($.groupKey),(Z=N.current)==null||Z.scrollToIndex({index:$.index,align:"center",behavior:"smooth"}))},[X,D]);const B=a.useRef(!1);h.length>0&&(B.current=!0);const V=c&&!B.current,ee=c&&B.current&&h.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:tt}}),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(lr,{})]}):!c&&(!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:H=>J(H.target.value),style:{marginLeft:-16,paddingInline:12,fontFamily:"inherit",fontSize:14,background:"transparent",border:"none",outline:"none",height:40,width:"100%"}})]}),t.jsx(Jn,{options:po,value:_,onChange:C}),(O||l)&&p&&t.jsx(Yt,{decrypted:!!l,loading:x,onClick:p})]}),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:tt}}),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(lr,{}):t.jsx(fn,{ref:N,totalCount:h.length,overscan:20,defaultItemHeight:40,endReached:()=>{!n||o||i==null||i()},itemContent:H=>{const $=h[H];return t.jsx(ho,{event:$,index:H,isFirst:H===0,isLast:H===h.length-1,isExpanded:L.has($.eventId),onToggleExpand:b,activeGroupKey:z,selectedGroupKey:g,selectedGroupRange:G,correlationNameMap:E,workflowName:S,durationMap:k,onSelectGroup:T,onHoverGroup:P,onLoadEventData:s,cachedEventData:M.current.get($.eventId)??null,onCacheEventData:q,encryptionKey:l,onEncryptedDataDetected:w})},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:[h.length," event",h.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(Yn,{loading:o,onClick:()=>void(i==null?void 0:i())})})})]})]})}function go({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(yo,{message:r},s))})}function yo({message:e}){const r=e.role,s=bo(e.content),n=wo(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,i)=>t.jsx(vo,{part:o,role:r},i))})]})}function vo({part:e,role:r}){return e.type==="text"?e.text?r==="assistant"?t.jsx("div",{className:"prose prose-sm max-w-none text-[11px] [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",style:{color:"var(--ds-gray-1000)"},children:t.jsx(mn,{children:e.text})}):t.jsx("div",{className:"whitespace-pre-wrap break-words",style:{color:"var(--ds-gray-1000)"},children:e.text}):null:e.type==="tool-call"?t.jsxs("div",{className:"rounded border px-2 py-1.5",style:{backgroundColor:"var(--ds-purple-100)",borderColor:"var(--ds-purple-300)"},children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium",children:[t.jsx("span",{children:"🔧"}),t.jsx("span",{style:{color:"var(--ds-purple-900)"},children:e.toolName})]}),e.input!=null&&t.jsx("div",{className:"mt-1.5 overflow-x-auto p-1.5 rounded",style:{backgroundColor:"var(--ds-gray-100)"},children:typeof e.input=="string"?t.jsx("pre",{className:"text-[10px]",style:{color:"var(--ds-gray-800)"},children:e.input}):t.jsx(vt,{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(vt,{data:e.output,expandLevel:1})})]}):null}function wo(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 bo(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 jo=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 Yr({data:e}){const r=Ue();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(jo(e)).then(()=>{r.success("Copied to clipboard")}).catch(()=>{r.error("Failed to copy")})},children:t.jsx(rt,{size:12})}),t.jsx(vt,{data:e})]})}function ie({summary:e,children:r,onToggle:s,disabled:n=!1,summaryClassName:o,contentClassName:i}){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:l=>s==null?void 0:s(l.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(Kt,{size:14,className:"shrink-0 transition-transform group-open:rotate-90"}),e]})}),t.jsxs("div",{className:`relative pl-6 mt-3 ${i??""}`,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 ko({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 No({tabs:e,activeTab:r,onTabChange:s,ariaLabel:n,children:o}){const i=a.useCallback(l=>{if(l.key!=="ArrowRight"&&l.key!=="ArrowLeft")return;l.preventDefault();const c=e.findIndex(d=>d.id===r),u=l.key==="ArrowRight"?(c+1)%e.length:(c-1+e.length)%e.length;s(e[u].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:i,style:{borderColor:"var(--ds-gray-300)",backgroundColor:"transparent"},children:e.map(l=>t.jsx(ko,{active:r===l.id,onClick:()=>s(l.id),children:l.label},l.id))}),t.jsx("div",{role:"tabpanel",children:o})]})}const Co=[{id:"conversation",label:"Conversation"},{id:"json",label:"Raw JSON"}];function Eo({conversation:e,args:r}){const[s,n]=a.useState("conversation");return t.jsx(ie,{summary:`Input (${e.length} messages)`,children:t.jsx(No,{tabs:Co,activeTab:s,onTabChange:n,ariaLabel:"Conversation view",children:s==="conversation"?t.jsx(go,{messages:e}):t.jsx("div",{className:"p-3",children:Array.isArray(r)?r.map((o,i)=>t.jsx("div",{className:"mt-2 first:mt-0",children:le(o)},i)):le(r)})})})}function Ze(){return t.jsxs("div",{className:"flex items-center gap-1.5 rounded-md border px-3 py-2 text-xs",style:{borderColor:"var(--ds-gray-300)",backgroundColor:"var(--ds-gray-100)",color:"var(--ds-gray-700)"},children:[t.jsx($r,{className:"h-3 w-3"}),t.jsx("span",{className:"font-medium",children:"Encrypted"})]})}function Ye(){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(Yr,{data:e})}const we=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,cr=["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"],Lt=(e,r)=>{const s=cr.indexOf(e)||0,n=cr.indexOf(r)||0;return s-n},So={workflowCoreVersion:"@workflow/core version",receivedCount:"times resolved"},Io=e=>So[e]??e,To=e=>{const r=String(e),s=st(r);if(s)return s.moduleSpecifier;const n=ze(r);return n?n.moduleSpecifier:r},Xt=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},Jt=e=>e.toLocaleString(void 0,{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",fractionalSecondDigits:3}),Ao=e=>{const r=Xt(e);return r?Jt(r):"-"},dr=e=>{const r=Xt(e);return r?Jt(r):null},De=e=>{const r=Xt(e);return r?t.jsx(Kr,{date:r,children:t.jsx("span",{children:Jt(r)})}):null},Je={workflowName:e=>{var r;return((r=ze(String(e)))==null?void 0:r.shortName)??"?"},moduleSpecifier:e=>To(e),stepName:e=>{var r;return((r=st(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:dr,disposedAt:dr,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:De,startedAt:De,updatedAt:De,completedAt:De,expiredAt:De,retryAfter:De,resumeAt:De,metadata:e=>we(e)?ge(e)?t.jsx(Ze,{}):Le(e)?t.jsx(Ye,{}):le(e):null,input:(e,r)=>{if(ge(e))return t.jsx(Ze,{});if(Le(e))return t.jsx(Ye,{});if(e&&typeof e=="object"&&"args"in e){const{args:o,closureVars:i,thisVal:l}=e,c=Array.isArray(o)?o.length:0,u=c===1?"argument":"arguments",d=we(i),p=we(l),x=we(o);if(r!=null&&r.stepName&&hn(r.stepName)){const m=xn(o);if(m&&m.length>0)return t.jsxs(t.Fragment,{children:[t.jsx(Eo,{conversation:m,args:o}),d&&t.jsx(ie,{summary:"Closure Variables",children:le(i)}),p&&t.jsx(ie,{summary:"This Value",children:le(l)})]})}return!x&&!d&&!p?t.jsx(ie,{summary:"Input (no data)",disabled:!0,summaryClassName:"text-base py-2"}):t.jsxs(t.Fragment,{children:[t.jsx(ie,{summary:`Input (${c} ${u})`,summaryClassName:"text-base py-2",contentClassName:"mt-0",children:Array.isArray(o)?o.map((m,f)=>t.jsx("div",{className:"mt-2 first:mt-0",children:le(m)},f)):le(o)}),d&&t.jsx(ie,{summary:"Closure Variables",children:le(i)}),p&&t.jsx(ie,{summary:"this",children:le(l)})]})}const s=Array.isArray(e)?e.length:0,n=s===1?"argument":"arguments";return we(e)?t.jsx(ie,{summary:`Input (${s} ${n})`,summaryClassName:"text-base py-2",contentClassName:"mt-0",children:Array.isArray(e)?e.map((o,i)=>t.jsx("div",{className:"mt-2 first:mt-0",children:le(o)},i)):le(e)}):t.jsx(ie,{summary:"Input (no data)",disabled:!0,summaryClassName:"text-base py-2"})},output:e=>we(e)?ge(e)?t.jsx(Ze,{}):Le(e)?t.jsx(Ye,{}):t.jsx(ie,{summary:"Output",summaryClassName:"text-base py-2",contentClassName:"mt-0",children:le(e)}):null,error:e=>ge(e)?t.jsx(Ze,{}):Le(e)?t.jsx(Ye,{}):we(e)?et(e)?t.jsx(ie,{summary:"Error",summaryClassName:"text-base py-2",contentClassName:"mt-0",children:t.jsx(bt,{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(Ze,{}):Le(e)?t.jsx(Ye,{}):we(e)?t.jsx(ie,{summary:"Event Data",children:le(e)}):null},ur=["input","output","error","metadata","eventData"],Ro=()=>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."})}),Do=({attribute:e,value:r,isLoading:s,inline:n=!1,context:o})=>{if(s&&(e==="input"||e==="output"||e==="eventData")&&!we(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 l=Je[e];if(!l)return null;const c=l(r,o);return c?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:c})]}):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:c})]},e)]}):null},Mo=({data:e,moduleSpecifier:r,isLoading:s,error:n,expiredAt:o,onStreamClick:i,resource:l})=>{const c=Ue(),u=a.useMemo(()=>{const h={...e},j=e.executionContext;return j!=null&&j.workflowCoreVersion&&(h.workflowCoreVersion=j.workflowCoreVersion),r?h.moduleSpecifier=r:typeof e.stepName=="string"?h.moduleSpecifier=e.stepName:typeof e.workflowName=="string"&&(h.moduleSpecifier=e.workflowName),h},[e,r]),d=o!=null&&new Date(o)<new Date,p=Object.keys(u).filter(h=>!ur.includes(h)).sort(Lt),x=a.useMemo(()=>{const h=Object.keys(u).filter(v=>ur.includes(v)).sort(Lt);if(!s)return h;const j=["input","output"];for(const v of j)h.includes(v)||h.push(v);return h.sort(Lt)},[u,s]),m=p.filter(h=>{const j=Je[h];return j?j(u[h])!==null:!1}),f=a.useMemo(()=>{const h=[...m],j=h.indexOf("moduleSpecifier");if(j===-1)return h;h.splice(j,1);const v=h.indexOf("workflowName");if(v!==-1)return h.splice(v+1,0,"moduleSpecifier"),h;const F=h.indexOf("stepName");return F!==-1?(h.splice(F+1,0,"moduleSpecifier"),h):(h.unshift("moduleSpecifier"),h)},[m]),_=a.useMemo(()=>({stepName:u.stepName}),[u.stepName]),C=a.useCallback(h=>{navigator.clipboard.writeText(h).then(()=>{c.success("moduleSpecifier copied")}).catch(()=>{c.error("Failed to copy moduleSpecifier")})},[]);return t.jsx(pn.Provider,{value:i,children:t.jsxs("div",{children:[m.length>0&&t.jsxs("div",{className:"mb-3 flex flex-col overflow-hidden rounded-lg border",style:{borderColor:"var(--ds-gray-300)"},children:[f.map((h,j)=>{var k;const v=(k=Je[h])==null?void 0:k.call(Je,u[h]),F=h==="moduleSpecifier",w=typeof v=="string"?v:String(v??u.moduleSpecifier??""),O=h!=="workflowCoreVersion",E=s&&l==="sleep"&&!u.resumeAt,S=j<f.length-1||E;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:O?"text-[14px] first-letter:uppercase":"text-[14px]",style:{color:"var(--ds-gray-700)"},children:Io(h)}),F?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:w,onClick:()=>C(w),children:w}):t.jsx("span",{className:"min-w-0 max-w-[70%] truncate text-right text-[13px] font-mono",style:{color:"var(--ds-gray-1000)"},children:v})]}),S?t.jsx("div",{className:"mx-2.5 border-b",style:{borderColor:"var(--ds-gray-300)"}}):null]},h)}),s&&l==="sleep"&&!u.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(Lr,{title:"Failed to load resource details",details:n.message,className:"my-4"}):d?t.jsx(Ro,{}):t.jsx(t.Fragment,{children:x.map(h=>t.jsx(Do,{isLoading:s,attribute:h,value:u[h],context:_},h))})]})})},_o=new Set(["step_failed","step_retrying"]),Lo=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 Po({event:e,onLoadEventData:r,encryptionKey:s}){const[n,o]=a.useState(null),[i,l]=a.useState(!1),[c,u]=a.useState(null),d=a.useRef(!1),p="eventData"in e&&e.eventData!=null?e.eventData:null,x=p??n,m=Lo.has(e.eventType),f=a.useCallback(async()=>{if(!(!r||!e.correlationId||!e.eventId))try{l(!0),u(null);const h=await r(e.correlationId,e.eventId);o(h)}catch(h){u(h instanceof Error?h.message:String(h))}finally{l(!1)}},[r,e.correlationId,e.eventId]),_=a.useCallback(async()=>{p||n!==null||i||(d.current=!0,await f())},[p,n,i,f]);a.useEffect(()=>{s&&d.current&&n!==null&&(o(null),f())},[s]);const C=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:Ao(C.getTime())})]}),onToggle:m?h=>{h&&_()}: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})]})]}),i&&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%]"})]}),c&&t.jsx(Lr,{title:"Failed to load event data",details:c,className:"mt-2"}),x!=null&&t.jsx("div",{className:"mt-2",children:t.jsx(Oo,{eventType:e.eventType,data:x})})]})}function Fo(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=>Le(r[o]))}function Oo({eventType:e,data:r}){if(Le(r)||Fo(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(_o.has(e)&&r!=null&&typeof r=="object"){const s=r;if(et(s.error))return t.jsx(bt,{value:s.error});if(et(s))return t.jsx(bt,{value:s})}return t.jsx(Yr,{data:r})}function $o({events:e,isLoading:r=!1,error:s,onLoadEventData:n,encryptionKey:o}){const i=a.useMemo(()=>[...e].sort((l,c)=>new Date(l.createdAt).getTime()-new Date(c.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&&`(${i.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&&i.length===0&&t.jsx("div",{className:"text-sm",children:"No events found"}),i.length>0&&!s?t.jsx("div",{className:"flex flex-col gap-4",children:i.map(l=>t.jsx(Po,{event:l,onLoadEventData:n,encryptionKey:o},l.eventId))}):null]})}function Wo(e){return e!==null&&typeof e=="object"&&"stepId"in e}function Ho(e){return e!==null&&typeof e=="object"&&"runId"in e}function pt(e){return e!==null&&typeof e=="object"&&"hookId"in e}function Bo({run:e,onStreamClick:r,spanDetailData:s,spanDetailError:n,spanDetailLoading:o,onSpanSelect:i,onWakeUpSleep:l,onLoadEventData:c,onResolveHook:u,encryptionKey:d,onDecrypt:p,isDecrypting:x=!1,selectedSpan:m}){const f=Ue(),[_,C]=a.useState(!1),[h,j]=a.useState(!1),[v,F]=a.useState(!1),[w,O]=a.useState(new Set),E=m==null?void 0:m.data,S=m==null?void 0:m.rawEvents,k=(S==null?void 0:S.length)??0,{resource:g,resourceId:y,runId:A}=a.useMemo(()=>{if(!m)return{resource:void 0,resourceId:void 0,runId:void 0};const D=m.resource;if(D==="step"&&Wo(E))return{resource:"step",resourceId:E.stepId,runId:E.runId};if(D==="run"&&Ho(E))return{resource:"run",resourceId:E.runId,runId:void 0};if(D==="hook"&&pt(E))return{resource:"hook",resourceId:E.hookId,runId:void 0};if(D==="sleep"){const B=E;return{resource:"sleep",resourceId:m.spanId,runId:B==null?void 0:B.runId}}return{resource:void 0,resourceId:void 0,runId:void 0}},[m,E]),I=a.useRef(i);I.current=i,a.useEffect(()=>{g&&y&&["run","step","hook","sleep"].includes(g)&&I.current({resource:g,resourceId:y,runId:A})},[g,y,A]);const T=a.useMemo(()=>g!=="sleep"||!S||["completed","failed","cancelled"].includes(e.status)||!S.some(ee=>ee.eventType==="wait_created")?!1:!S.some(ee=>ee.eventType==="wait_completed"),[g,S,k,e.status]),P=a.useMemo(()=>!(g!=="hook"||!S||!y||w.has(y)||["completed","failed","cancelled"].includes(e.status)||S.some(V=>V.eventType==="hook_disposed")),[g,y,S,k,e.status,w]),z=n??void 0,L=o??!1,R=a.useMemo(()=>{if(!s)return!1;const D=s;return ge(D.input)||ge(D.output)||ge(D.error)||ge(D.metadata)},[s]),b=a.useMemo(()=>{if(!(g!=="hook"||!y)){if(pt(s)&&s.token)return s.token;if(pt(E)&&E.token)return E.token}},[g,y,s,E]);a.useEffect(()=>{z&&m&&g&&f.error(`Failed to load ${g} details`,{description:z.message})},[z,g,m]);const M=async()=>{if(!(_||!y)){if(!l){f.error("Unable to wake up sleep",{description:"No wake-up handler provided."});return}try{C(!0),(await l(e.runId,y)).stoppedCount>0?f.success("Run woken up",{description:"The sleep call has been interrupted and the run woken up."}):f.info("Sleep already completed",{description:"This sleep call has already finished."})}catch(D){console.error("Failed to wake up run:",D),f.error("Failed to wake up run",{description:D instanceof Error?D.message:"An unknown error occurred"})}finally{C(!1)}}},q=a.useCallback(async D=>{if(!v){if(!u){f.error("Unable to resolve hook",{description:"No resolve handler provided."});return}if(!b){f.error("Unable to resolve hook",{description:"Missing hook token. Try refreshing the run data and retry."});return}try{F(!0);const B=s??E,V=pt(B)?B:void 0;await u(b,D,V),f.success("Hook resolved",{description:"The payload has been sent and the hook resolved."}),j(!1),y&&O(ee=>new Set(ee).add(y))}catch(B){console.error("Failed to resolve hook:",B),f.error("Failed to resolve hook",{description:B instanceof Error?B.message:"An unknown error occurred"})}finally{F(!1)}}},[u,b,v,s,E]),W=s??E,G=a.useMemo(()=>{const D=W,B=D.stepName,V=D.workflowName;if(typeof B=="string")return B;if(typeof V=="string")return V;if(typeof e.workflowName=="string")return e.workflowName},[W,e.workflowName]);if(!m||!g||!y)return null;const X=g.charAt(0).toUpperCase()+g.slice(1),J=g==="sleep"&&T||g==="hook"&&P,N=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:N})]}),t.jsx("p",{className:"mt-1 truncate font-mono text-[13px]",style:{color:"var(--ds-gray-700)"},title:y,children:y})]}),(R||d)&&p&&t.jsx(Yt,{decrypted:!!d,loading:x,onClick:p})]})}),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:[g==="sleep"&&T&&t.jsxs("button",{type:"button",onClick:M,disabled:_,className:Pe("flex items-center justify-center gap-2 rounded-md px-3 py-2 text-sm font-medium","disabled:opacity-50 disabled:cursor-not-allowed transition-colors",_?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{background:"var(--ds-amber-200)",color:"var(--ds-amber-900)"},children:[t.jsx($s,{className:"h-4 w-4"}),_?"Waking up...":"Wake Up Sleep"]}),g==="hook"&&P&&t.jsxs("button",{type:"button",onClick:()=>j(!0),disabled:v,className:Pe("flex items-center justify-center gap-2 rounded-md px-3 py-2 text-sm font-medium","disabled:opacity-50 disabled:cursor-not-allowed transition-colors",v?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{background:"var(--ds-gray-1000)",color:"var(--ds-background-100)"},children:[t.jsx(Pr,{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(Mo,{data:W,moduleSpecifier:G,expiredAt:e.expiredAt,isLoading:L,error:z??void 0,onStreamClick:r,resource:g})]}),g!=="run"&&S&&t.jsx("section",{children:t.jsx($o,{events:S,onLoadEventData:c,encryptionKey:d})})]})]}),t.jsx(Fr,{isOpen:h,onClose:()=>j(!1),onSubmit:q,isSubmitting:v})]})}function Vo(e){const r=a.useRef(e);r.current=e,a.useEffect(()=>{let s=0,n=0;const o=()=>{r.current(s),s=0},i=l=>{if(!l.ctrlKey&&!l.metaKey)return;l.preventDefault();let c=-l.deltaY;switch(l.deltaMode){case WheelEvent.DOM_DELTA_PAGE:c*=window.innerHeight;break;case WheelEvent.DOM_DELTA_LINE:c*=20;break}s+=c,cancelAnimationFrame(n),n=requestAnimationFrame(o)};return window.addEventListener("wheel",i,{passive:!1}),()=>{window.removeEventListener("wheel",i),cancelAnimationFrame(n)}},[])}function fr(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 zo({scale:e,isLive:r=!1}){const{state:{root:s}}=ye(),[,n]=a.useState(0);a.useEffect(()=>{if(!r)return;const m=setInterval(()=>n(f=>f+1),1e3);return()=>clearInterval(m)},[r]);const o=s.duration,i=e>0?e:o>0?1/o:1;let c=fr(50/i);c=Math.max(1,c);let u=c*i;const d=1e3;o/c>d&&(c=fr(o/d),u=c*i);const p=Math.ceil(o/c),x=Math.ceil(100/u)||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":`${u}px`},children:new Array(p).fill(null).map((m,f)=>{const _=f%x===0;return t.jsx("span",{className:Pe(K.marker,!_&&K.notch),children:_?t.jsxs("span",{className:K.markerLabel,children:[gn(c*f),t.jsx("span",{className:K.markerClockTime,children:yn(s.startTime+c*f)})]}):null},String(f))})})})}function Uo({events:e,root:r,scale:s}){const n=a.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:Pe(K.eventMarker),style:{left:Math.floor((o.timestamp-r.startTime)*s),...o.event.color&&{borderLeftColor:o.event.color}}},o.key))})})}const mr=2;function Ko({memoCacheRef:e,timelineRef:r,root:s,spans:n,events:o,scale:i,dispatch:l,scrollSnapshotRef:c}){const u=a.useRef(!1),d=a.useRef(n);d.current=n;const p=a.useRef(o);p.current=o;const x=a.useRef(null),{style:m,setStyle:f}=Rt(x),_=a.useRef(null),C=a.useRef(null),{style:h,setStyle:j}=Rt(C),v=a.useRef(void 0),F=a.useRef(null),{style:w,setStyle:O}=Rt(F),E=a.useRef(0);a.useEffect(()=>{const k=r.current;if(!k)return;let g=E.current,y=0,A=!1,I=!1,T=!1,P=!1,z=0,L=0;const R=Date.now()+500,b=()=>{v.current||(v.current=k.getBoundingClientRect())},M=Z=>v.current?(Z-wt-ce)/(We+Ee):0,q=()=>{const Z=e.current;for(const se of d.current)se.isHovered&&(se.isHovered=!1,Z.set(se.span.spanId,{}));l({type:"forceRender"})};let W=0;const G=()=>{var Ke,ot,at,xe,it,lt,ct,dt;if(!u.current)return;v.current||b();const Z=v.current;if(!Z)return;const{scrollLeft:se,scrollTop:oe}=k,fe=Math.max(0,Math.min(g+se-Z.left-ce,s.duration*i)),Oe=`${fe-se+ce}px`;j("left",Oe),f("left",Oe);const ve=s.startTime+fe/i,Ne=ve-s.startTime;if(Ne<0||Ne>s.duration?(Ke=_.current)==null||Ke.removeAttribute("data-text"):(ot=_.current)==null||ot.setAttribute("data-text",ft(Ne)),A){const Ie=g-y,qe=Math.abs(Ie);if(!T){if(qe<4)return;T=!0,O("display","flex"),q()}Ie>0?(O("left",""),O("right","0")):(O("left","0"),O("right","")),O("width",`${qe}px`);const Te=Math.max(0,Math.min(y+se-Z.left-ce,s.duration*i))/i;let U,te;Te<Ne?(U=Te,te=Ne):(U=Ne,te=Te),(at=F.current)==null||at.setAttribute("data-range",`${ft(U)} — ${ft(te)}`),(xe=F.current)==null||xe.setAttribute("data-duration",`${ft(te-U)} selected`)}if(Date.now()<R){W=requestAnimationFrame(G);return}if(se!==z||oe!==L){z=se,L=oe,W=requestAnimationFrame(G);return}if(g-Z.left<128?(it=_.current)==null||it.setAttribute("data-align","left"):g-Z.left>Z.width-128?(lt=_.current)==null||lt.setAttribute("data-align","right"):(ct=_.current)==null||ct.removeAttribute("data-align"),!T&&!I){const Ie=e.current,qe=M(oe)-mr,St=M(oe+Z.height)+mr;for(const re of d.current){const ae=re.row>=qe&&re.row<=St&&ve>=re.startTime&&ve<=re.endTime;re.isHovered!==ae&&(re.isHovered=ae,Ie.set(re.span.spanId,{}))}const U=12/i;let te=null,ne=1/0;for(const re of p.current){const ae=Math.abs(re.timestamp-ve);ae<=U&&ae<ne&&(ne=ae,te=re)}for(const re of p.current){const ae=re===te;if(re.isHovered===ae)continue;re.isHovered=ae;const Ge=(dt=re.ref)==null?void 0:dt.current;Ge&&Ge.setAttribute("data-hovered",String(ae))}l({type:"forceRender"})}};W=requestAnimationFrame(G);const X=Z=>{Z.pointerType==="mouse"&&(u.current=!0)},J=()=>{u.current&&(u.current=!1,q())},N=({clientX:Z})=>{g=Z,E.current=g,cancelAnimationFrame(W),W=requestAnimationFrame(G)},D=Z=>{Z.preventDefault()},B=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)?(y=g,A=!0):(I=!0,requestAnimationFrame(q))},V=Z=>{if(I=!1,!A||(A=!1,!T))return;if(T=!1,O("display",""),O("left",""),O("right",""),O("width",""),Z.preventDefault(),Z.stopImmediatePropagation(),P){P=!1;return}v.current||b();const se=v.current;if(!se)return;const{scrollLeft:oe}=k,fe=Math.max(0,Math.min((y+oe-se.left-ce)/i,s.duration)),Oe=Math.max(0,Math.min((g+oe-se.left-ce)/i,s.duration));l({type:"scaleToRange",t1:fe+s.startTime,t2:Oe+s.startTime})},ee=Z=>{A&&Z.key==="Escape"&&(P=!0,V(Z))},H=()=>{v.current=void 0,S.current=void 0,cancelAnimationFrame(W),W=requestAnimationFrame(G)},$=()=>{cancelAnimationFrame(W),W=requestAnimationFrame(G)},Y=new ResizeObserver(()=>{v.current=void 0});return Y.observe(k),window.addEventListener("mousemove",N),k.addEventListener("contextmenu",D),window.addEventListener("mousedown",B),window.addEventListener("mouseup",V),window.addEventListener("blur",V),window.addEventListener("keydown",ee,!0),window.addEventListener("scroll",H),k.addEventListener("scroll",$),k.addEventListener("pointerenter",X),k.addEventListener("pointerleave",J),()=>{Y.disconnect(),window.removeEventListener("mousemove",N),k.removeEventListener("contextmenu",D),window.removeEventListener("mousedown",B),window.removeEventListener("mouseup",V),window.removeEventListener("blur",V),window.removeEventListener("keydown",ee,!0),window.removeEventListener("scroll",H),k.removeEventListener("scroll",$),k.removeEventListener("pointerenter",X),k.removeEventListener("pointerleave",J),cancelAnimationFrame(W),E.current=g,q()}},[l,s,i,j,f,O,e,r,c]);const S=a.useRef(void 0);return Vo(k=>{const g=r.current;if(!g)return;v.current??(v.current=g.getBoundingClientRect());const y=v.current,A=Math.max(0,Math.min(E.current-y.left-ce,y.width-2*ce));let I=0,T=S.current;(T==null?void 0:T.anchorX)===A?I=T.anchorT:(I=(g.scrollLeft+A)/i,T={anchorT:I,anchorX:A},S.current=T),l({type:"trackpadScale",delta:k/64,anchorT:I,anchorX:A})}),t.jsxs(t.Fragment,{children:[t.jsx("div",{className:K.cursorMarkerStickyParent,children:t.jsx("div",{className:K.cursorMarkerLabelContainer,ref:x,style:m,children:t.jsx("div",{className:K.cursorMarkerLabel,ref:_})})}),t.jsx("div",{className:K.cursorMarkerStickyParent,children:t.jsx("div",{className:K.cursorMarkerContainer,ref:C,style:h,children:t.jsx("div",{className:K.cursorMarker,children:t.jsx("div",{className:K.cursorSelection,ref:F,style:w})})})})]})}function qo({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(Go,{})}),t.jsx("input",{type:"search",value:s,placeholder:n,onChange:o,style:{height:e,width:r}})]})}function Go(){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 Zo(){return t.jsx("nav",{className:K.searchBar,children:t.jsx(Yo,{})})}function Yo(){const{dispatch:e}=ye(),[r,s]=a.useState("");return a.useEffect(()=>{const n=setTimeout(()=>e({type:"setFilter",filter:r}),100);return()=>{clearTimeout(n)}},[e,r]),t.jsx("div",{className:K.searchInput,children:t.jsx(qo,{height:Wr,onChange:n=>s(n.target.value),placeholder:"Search spans…",value:r,width:"100%"})})}function Xo({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 Jo({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 Qo({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 ea(){const{dispatch:e}=ye(),r=a.useCallback(()=>{e({type:"adjustScaleRatio",direction:1})},[e]),s=a.useCallback(()=>{e({type:"adjustScaleRatio",direction:-1})},[e]),n=a.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(Jo,{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(Qo,{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(Xo,{size:18})})]})}const ta=e=>{const{spans:r}=e,s={startTime:0,endTime:0,duration:0,depth:0,children:[]},n={},o=new Map,i=x=>{const m=o.get(x);if(m)return m;const f=o.size+1;return o.set(x,f),f};let l=!1;for(const x of r){const m=Xe(x.startTime),f=Xe(x.endTime),_=Xe(x.duration);f>s.endTime&&(s.endTime=f,s.duration=f-s.startTime),(s.startTime===0||m<s.startTime)&&(s.startTime=m,s.duration=s.endTime-m);const C=x.resource.startsWith("vercel.");C||(l=!0);const h=C&&(x.resource!=="vercel.serverless-runtime"||!("http.method"in x.attributes)),j=h?0:i(x.resource);let v;h&&(v=`▲ ${x.name}`),n[x.spanId]={parent:null,startTime:m,endTime:f,duration:_,span:x,depth:0,label:v,events:ra(x),isVercel:h,children:[],resourceIndex:j,activeStartTime:x.activeStartTime?Xe(x.activeStartTime):void 0}}const c=(x,m)=>{let f;m?(f=n[m],f||(f=s)):f=s,x.parent=f,f.children.push(x)},u=x=>{"parent"in x&&(x.depth=x.parent.depth+1);for(const m of x.children)u(m)};let d=1;const p=(x,m)=>{if("parent"in x&&x.span.name===m){let f=x.endTime;const _=E=>E.children.length?E.children.map(_).sort((S,k)=>S.duration-k.duration)[0]||E:E.span.name==="waitUntil"?(f=E.startTime,E.parent):E,C=_(x),h=`instrumentation-hint-${d++}`,j=x.duration*.05,v=x.startTime+j,F=Math.max(v+j,Math.min(f-x.duration*.01,x.endTime-j)),w=F-v,O={parent:C,startTime:v,endTime:F,duration:w,span:{spanId:h,name:"Add your spans here",resource:"",kind:0,library:{name:""},status:{code:200},traceFlags:0,attributes:{},links:[],events:[],startTime:Dt(v),endTime:Dt(F),duration:Dt(w)},depth:x.depth+1,isVercel:!1,isInstrumentationHint:!0,children:[],resourceIndex:1};return C.children.push(O),n[h]=O,!0}for(const f of x.children)if(p(f,m))return!0;return!1};for(const x of Object.values(n))c(x,x.span.parentSpanId);if(u(s),!l){for(const x of["Invoke Function","Invoke Middleware","Vercel Runtime"])if(p(s,x))break}return{root:s,map:n}},ra=e=>{if(!e.events.length)return;const r=`${e.spanId}:ev`;return e.events.map((s,n)=>({key:`${r}${n}`,timestamp:Xe(s.timestamp),event:s})).sort((s,n)=>s.timestamp-n.timestamp)},pr=(e,r)=>(e.isVisible=!0,e.isHovered=!1,e.isVisible);function Pt(){return[]}const sa=(e,r=!1)=>{const{state:s,dispatch:n}=ye(),{root:o,filter:i,scale:l,timelineRef:c,timelineWidth:u,spanMap:d,scrollSnapshotRef:p,selected:x,memoCacheRef:m}=s,f=na(s.timelineHeight),_=a.useRef(0),[C,h]=a.useState(Pt),[j,v]=a.useState(Pt),[F,w]=a.useState(Pt),[O,E]=a.useState(-1),S=a.useRef(void 0);return a.useEffect(()=>{var k;return(k=S.current)==null?void 0:k.call(S,i)},[i]),a.useEffect(()=>{if(e!=null&&e.length){for(const k of C)for(const g of k){const y=e.includes(g.span.spanId);g.isHighlighted!==y&&(g.isHighlighted=y,m.current.set(g.span.spanId,{}))}n({type:"forceRender"})}},[C,e,n,m]),a.useEffect(()=>{if(!o.startTime)return;const k=new Worker(new URL("/assets/worker-D-HfgUMl.js",import.meta.url),{type:"module"});let g=++_.current;const y=I=>{var P;const T=I.data;switch(T.type){case"setRowsResult":{if((T==null?void 0:T.requestId)!==g)return;if(T.isEnd)for(const z of T.rows)for(const L of z)L.span=((P=d[L.span.spanId])==null?void 0:P.span)??L.span;h(T.rows);break}case"updateHighlight":{if((T==null?void 0:T.requestId)!==g)return;const{matches:z}=T;h(L=>{for(const R of L)for(const b of R){const M=z.has(b.span.spanId);b.isHighlighted!==M&&(b.isHighlighted=M,m.current.set(b.span.spanId,{}))}return L}),n({type:"forceRender"});break}}};k.addEventListener("message",y);const A={requestId:g,type:"calculateSpanPositions",root:o};return k.postMessage(A),S.current=I=>{const T=I.trim().toLocaleLowerCase();if(!T){h(z=>z.map(L=>L.map(R=>(R.isHighlighted=void 0,{...R}))));return}g=++_.current;const P={type:"filterSpans",requestId:g,root:o,filter:T};k.postMessage(P)},()=>{k.terminate()}},[o,d,n,m]),a.useEffect(()=>{if(!C.length)return;if(r){const N=[],D=[];for(const B of C)for(const V of B)pr(V)&&(N.push(V),V.events&&D.push(...V.events));v(N),w(D),E(l);return}const k=c.current;let g=p.current,y=!1,A=!1,I=0,T=0;const P=Math.max(500,u*.5),z=new Array(C.length).fill(null),L=()=>{A=!0;const N=Math.min(1+T+Math.ceil((g==null?void 0:g.endRow)??Number.POSITIVE_INFINITY),C.length);for(let D=N;D--;){if(z[D])continue;const B=R(D);if(Math.abs(B)>T){if(A=!1,B>0)continue;break}const V=[],ee=C[D];if(ee){for(const H of ee){if(!pr(H))continue;const $=b(H);I=Math.max($,I),V.push({d:$,span:H})}z[D]=V}}},R=N=>g?N<g.startRow?N-g.startRow:N>g.endRow?N-g.endRow:0:0,b=N=>{if(!g)return 0;let D=0;N.endTime<g.startTime?D=g.startTime-N.endTime:N.startTime>g.endTime&&(D=N.startTime-g.endTime);const B=Math.abs(R(N.row));return!D&&!B?0:Math.sqrt((D/l)**2+(B*We+Ee)**2)},M=()=>{if(!k)return;const{scrollLeft:N,scrollTop:D}=k,B=0,V=N/l,ee=(D-wt-ce)/(We+Ee),H=ee+Math.ceil(f/(We+Ee));g={anchorT:V,anchorX:B,scrollLeft:N,scrollTop:D,startTime:o.startTime+N/l,endTime:o.startTime+(N+u)/l,startRow:ee,endRow:H,scale:l},p.current=g;for(let $=z.length;$--;)z[$]=null};let q=0;const W=()=>{(y||!g)&&(y=!1,M()),L();const N=[],D=[];for(const B of z)if(B)for(const{d:V,span:ee}of B)V>T||(N.push(ee),ee.events&&D.push(...ee.events));T<P&&(!A||T<I)&&(T=Math.min(P,T+100),q=requestAnimationFrame(W)),v(N),w(D),E(l)};W();let G=Date.now();const X=N=>{(N.ctrlKey||N.metaKey)&&(G=Date.now())};k==null||k.addEventListener("wheel",X);const J=()=>{Date.now()-G<=50||(y=!0,cancelAnimationFrame(q),q=requestAnimationFrame(W))};return k==null||k.addEventListener("scroll",J),()=>{cancelAnimationFrame(q),k==null||k.removeEventListener("wheel",X),k==null||k.removeEventListener("scroll",J)}},[C,o,l,p,c,u,f,r]),a.useEffect(()=>{var y;if(!x)return;let k;for(const A of j)if(A.span.spanId===x.span.spanId){k=A;break}const g=(y=k==null?void 0:k.ref)==null?void 0:y.current;if(!(!k||!g))return k.isSelected=!0,g.setAttribute("data-selected",""),()=>{k.isSelected=!1,g.removeAttribute("data-selected")}},[j,x]),{rows:C,spans:j,events:F,scale:O}};function na(e){const[r,s]=a.useState(e);return a.useEffect(()=>{if(r===e)return;let n=0,o=0;const i=()=>{if(++n<=3){o=requestAnimationFrame(i);return}s(e)};return i(),()=>{cancelAnimationFrame(o)}},[r,e]),r}const hr={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 oa({trace:e=hr,className:r="",scrollLock:s=!1,height:n,withPanel:o=!1,highlightedSpans:i,eagerRender:l=!1,isLive:c=!1,footer:u,knownDurationMs:d,hasMoreData:p=!1}){const x=e===hr,{state:m,dispatch:f}=ye(),{timelineRef:_,scrollSnapshotRef:C}=m,h=m.memoCacheRef.current,j=((i==null?void 0:i.length)??0)>0,v=a.useRef(!1),F=a.useRef(""),w=a.useRef(null),O=a.useRef({}),E=a.useRef(null);a.useEffect(()=>{const{root:L,map:R}=ta(e),b=!v.current;v.current=!0;const M=Object.keys(R).sort().map(q=>{const W=R[q].events,G=(W==null?void 0:W.length)??0,X=G?W==null?void 0:W[0]:void 0,J=G?W==null?void 0:W[G-1]:void 0,N=`${(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`${q}:${G}:${N}`}).join(",");if(!b&&M===F.current&&w.current){const q=w.current,W=O.current;let G=!1;(q.endTime!==L.endTime||q.duration!==L.duration)&&(q.endTime=L.endTime,q.duration=L.duration,G=!0);for(const[X,J]of Object.entries(R)){const N=W[X];N&&((N.endTime!==J.endTime||N.duration!==J.duration)&&(N.endTime=J.endTime,N.duration=J.duration,G=!0),Object.assign(N.span,J.span))}if(!G)return;f({type:"forceRender"});return}F.current=M,w.current=L,O.current=R,f({type:b?"setRoot":"updateRoot",root:L,spanMap:R,resources:e.resources||[]})},[f,e]);const{rows:S,spans:k,events:g,scale:y}=sa(i,l),A=a.useRef(null);a.useLayoutEffect(()=>{const L=A.current;if(!L)return;const R=()=>{const M=2*ce,q=L.getBoundingClientRect(),W=q.width-M,G=q.height,X=E.current;X&&X.width===W&&X.height===G||(E.current={width:W,height:G},f({type:"setSize",width:W,height:G}))};R();const b=new ResizeObserver(R);return b.observe(L),window.addEventListener("resize",R),()=>{b.disconnect(),window.removeEventListener("resize",R)}},[f]);const I=a.useRef({t:0,x:-1,y:-1,spanId:""}),T=a.useCallback(L=>{const R=I.current,b=Date.now(),{clientX:M,clientY:q}=L,W=Math.sqrt((M-R.x)**2+(q-R.y)**2);if(b-R.t<=500&&W<=8){if(L.stopPropagation(),L.preventDefault(),!R.spanId){f({type:"resetScale"});return}f({type:"select",id:R.spanId}),f({type:"scaleToNode",id:R.spanId});return}const G=L.target;if(!G.closest(`.${String(K.timeline)}`))return;const X=G.closest("[data-span-id]"),J=(X==null?void 0:X.dataset.spanId)||"";I.current={x:M,y:q,t:b,spanId:J},J&&(f({type:"toggleSelection",id:J}),L.stopPropagation())},[f]);a.useLayoutEffect(()=>{const L=_.current;if(!L)return;const R=C.current;R&&(L.scrollLeft=R.anchorT*y-R.anchorX,C.current=void 0)},[C,_,y]),a.useEffect(()=>{var b;const L=(b=m.selected)==null?void 0:b.span.spanId;if(!L)return;const R=setTimeout(()=>{const M=m.timelineRef.current,q=M==null?void 0:M.querySelector(`[data-span-id="${L}"]`);if(!M||!q)return;const W=M.getBoundingClientRect(),G=q.getBoundingClientRect();G.width<W.width&&(G.left<W.left||G.right>W.right||G.top<W.top||G.bottom>W.bottom)&&q.scrollIntoView({block:"nearest",inline:"center",behavior:"smooth"})},500);return()=>{clearTimeout(R)}},[m.selected,m.timelineRef]),a.useEffect(()=>{const L=R=>{R.key==="Escape"&&f({type:"escape"})};return window.addEventListener("keydown",L),()=>{window.removeEventListener("keydown",L)}},[f]),a.useEffect(()=>{if(!s)return;const L=document.documentElement,R=document.body;L.style.overflow="clip",R.style.overflow="clip";const b=M=>{M!=null&&M.cancelable?M.preventDefault():window.scrollTo({left:0,top:0,behavior:"instant"})};return b(),window.addEventListener("scroll",b,{passive:!1}),()=>{L.style.overflow="",R.style.overflow="",window.removeEventListener("scroll",b)}},[s]);const P=Math.max(m.timelineHeight-m.scrollbarWidth,wt+Ee+S.length*(We+Ee)-Ee+84),z=!!(m.isMobile&&m.selected);return t.jsxs("div",{className:Pe(K.traceViewer,x&&K.skeleton,r),onClickCapture:T,ref:A,style:{height:n,"--timeline-padding":`${ce}px`,"--row-height":`${We}px`,"--row-padding":`${Ee}px`,"--search-height":`${j?0:Wr}px`,"--search-gap":`${j?2:bn}px`,"--map-height":`${wn}px`,"--timeline-width":`${m.timelineWidth}px`,"--timeline-height":`${m.timelineHeight}px`,"--timeline-scroll-width":`${Math.round(m.root.duration*m.scale)}px`,"--panel-width":`${m.panelWidth}px`,"--panel-height":`${m.panelHeight}px`,"--height":`${m.height}px`,"--scrollbar-width":`${m.scrollbarWidth}px`,"--marker-height":`${wt}px`,"--marker-notch-height":`${vn}px`},children:[j?null:t.jsx(Zo,{}),t.jsx(jn,{rows:S,scale:y,timelineRef:_}),t.jsxs("div",{className:Pe(K.traceViewerContent,z&&K.inert),children:[t.jsxs("div",{className:K.timeline,ref:_,children:[t.jsx("div",{style:{position:"relative",width:m.timelineWidth,minHeight:m.timelineHeight-ce*2,padding:ce,paddingBottom:0},children:t.jsxs("div",{className:K.traceNode,style:{width:m.root.duration*y||void 0,height:P-ce*2},children:[t.jsx(zo,{scale:y,isLive:c}),t.jsx(Uo,{events:g,root:m.root,scale:y}),t.jsx(Ko,{dispatch:f,events:g,memoCacheRef:m.memoCacheRef,root:m.root,scale:y,scrollSnapshotRef:C,spans:k,timelineRef:_}),t.jsx(kn,{cacheKey:h.get(""),cache:h,customSpanClassNameFunc:m.customSpanClassNameFunc,customSpanEventClassNameFunc:m.customSpanEventClassNameFunc,isLive:c,root:m.root,scale:y,scrollSnapshotRef:C,spans:k}),d!=null&&d>0&&(p||c)&&m.root.duration>0&&(()=>{const L=d*y,b=m.root.duration*y-L;if(b<4)return null;const M=Math.min(b*.05,20);return t.jsx("div",{style:{position:"absolute",top:0,left:L+M,width:b-M,height:"100%",pointerEvents:"none",zIndex:1,maskImage:"linear-gradient(to right, transparent 1%, black 3%)",WebkitMaskImage:"linear-gradient(to right, transparent 1%, black 3%)",background:"repeating-linear-gradient(-45deg, var(--ds-background-200) 0, var(--ds-background-200) 11px, var(--ds-gray-200) 11px, var(--ds-gray-200) 12px)"}})})()]})}),u]}),t.jsx("div",{className:K.zoomButtonTraceViewer,children:t.jsx(ea,{})})]}),o?t.jsx("div",{className:Pe(K.spanDetailPanelTraceViewer,!m.selected&&K.hidden,m.isMobile&&K.mobile),children:t.jsx(Nn,{attached:!0})}):null]})}function xr(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 aa(e){return String(e).toLowerCase().endsWith("sleep")}const ia=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&&aa(o))return K.spanSleep;const i=(n==null?void 0:n.status)==="pending";return xr(n==null?void 0:n.status,i)}if(s==="run"){const n=r.data;return xr(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 ca(e){return e==="hook_created"||e==="hook_received"||e==="hook_disposed"}function pe(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 Bt(e){const r=e[0]*1e3,s=e[1]/1e6;return r+s}function Ct(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),i=n%1e3*1e6;return[o,i]}const nt={name:"workflow-development-kit",version:"4.0.0"},da=new Set(["hook_created","hook_received","hook_disposed","step_started","step_retrying","step_failed","run_failed","wait_created","wait_completed"]);function Et(e,r=!0){return e.filter(s=>r?da.has(s.eventType):!0).map(s=>({name:s.eventType,timestamp:pe(s.createdAt),attributes:{eventId:s.eventId,correlationId:s.correlationId,eventData:"eventData"in s?s.eventData:void 0},showVerticalLine:ca(s.eventType)}))}const Xr=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 ua(e,r){const s=Xr(e);if(!s)return null;const n=s.createdAt,o=s.completedAt??r,i=pe(n),l=pe(o),c=Ct(n,o),u=Et(e,!1);return{spanId:s.waitId,name:"sleep",kind:1,resource:"sleep",library:nt,status:{code:0},traceFlags:1,attributes:{resource:"sleep",data:s},links:[],events:u,duration:c,startTime:i,endTime:l}}const fa=e=>{var u;const r=e.find(d=>d.eventType==="step_created"),s=r??e[0];if(!s)return null;let n="pending",o=0,i,l;for(const d of e)switch(d.eventType){case"step_started":n="running",o+=1,i||(i=d.createdAt),l=void 0;break;case"step_completed":n="completed",l=d.createdAt;break;case"step_failed":n="failed",l=d.createdAt;break;case"step_retrying":n="pending",l=void 0;break}o===0&&(o=1);const c=e[e.length-1];return{stepId:s.correlationId??"",runId:s.runId,stepName:((u=r==null?void 0:r.eventData)==null?void 0:u.stepName)??"",status:n,attempt:o,createdAt:s.createdAt,updatedAt:(c==null?void 0:c.createdAt)??s.createdAt,startedAt:i,completedAt:l,specVersion:s.specVersion}};function ma(e,r){const s=fa(e);if(!s)return null;const n=st(String(s.stepName)),o={resource:"step",data:s},i="step",l=new Date(s.completedAt??r),c=Et(e,!1),u=new Date(s.createdAt);let d=s.startedAt?new Date(s.startedAt):void 0;const p=e.find(x=>x.eventType==="step_started");return p&&(d=new Date(p.createdAt)),{spanId:String(s.stepId),name:(n==null?void 0:n.shortName)??"",kind:1,resource:i,library:nt,status:{code:0},traceFlags:1,attributes:o,links:[],events:c,startTime:pe(u),endTime:pe(l),duration:Ct(u,l),activeStartTime:d&&d.getTime()>u.getTime()?pe(d):void 0}}const pa=e=>{var i,l;const r=e.find(c=>c.eventType==="hook_created");if(!r)return null;const s=e.filter(c=>c.eventType==="hook_received"),n=e.filter(c=>c.eventType==="hook_disposed"),o=s.at(-1);return{hookId:r.correlationId,runId:r.runId,token:(i=r.eventData)==null?void 0:i.token,createdAt:r.createdAt,receivedCount:s.length,lastReceivedAt:(o==null?void 0:o.createdAt)||void 0,disposedAt:((l=n.at(-1))==null?void 0:l.createdAt)||void 0}};function ha(e,r){const s=pa(e);if(!s)return null;const n=Et(e,!1),o=s.disposedAt||r;return{spanId:String(s.hookId),name:String(s.hookId),kind:1,resource:"hook",library:nt,status:{code:1},traceFlags:1,attributes:{resource:"hook",data:s},links:[],events:n,startTime:pe(s.createdAt),endTime:pe(o),duration:Ct(s.createdAt,o)}}function xa(e,r,s){var f;const n=s??new Date,{input:o,output:i,error:l,...c}=e,u={resource:"run",data:c},d=new Date(e.createdAt),p=e.startedAt?new Date(e.startedAt):void 0,x=e.completedAt??n,m=Et(r,!1);return{spanId:String(e.runId),name:String(((f=ze(e.workflowName))==null?void 0:f.shortName)??"?"),kind:1,resource:"run",library:nt,status:{code:0},traceFlags:1,attributes:u,links:[],events:m,startTime:pe(d),endTime:pe(x),duration:Ct(d,x),activeStartTime:p&&p.getTime()>d.getTime()?pe(p):void 0}}const ga=e=>e.startsWith("step_"),ya=e=>e==="wait_created"||e==="wait_completed",va=e=>e==="hook_received"||e==="hook_created"||e==="hook_disposed";function Ft(e,r,s){const n=e.get(r);if(n){n.push(s);return}e.set(r,[s])}function wa(e){const r=new Map,s=[],n=new Map,o=new Map;for(const i of e){const l=i.correlationId;if(!l){s.push(i);continue}if(ya(i.eventType)){Ft(n,l,i);continue}if(va(i.eventType)){Ft(o,l,i);continue}if(ga(i.eventType)){Ft(r,l,i);continue}s.push(i)}return{eventsByStepId:r,runLevelEvents:s,timerEvents:n,hookEvents:o}}function ba(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 ja(e,r,s,n){const o=n,i=Array.from(r.eventsByStepId.values()).map(u=>ma(u,o)).filter(u=>u!==null),l=Array.from(r.hookEvents.values()).map(u=>ha(u,o)).filter(u=>u!==null),c=Array.from(r.timerEvents.values()).map(u=>ua(u,o)).filter(u=>u!==null);return{runSpan:xa(e,r.runLevelEvents,s),spans:[...i,...l,...c]}}function ka(e,r){const s=[e,...r.slice().sort((n,o)=>{const i=Bt(n.startTime),l=Bt(o.startTime);return i-l})];return s.map((n,o)=>{const i=o===0?void 0:String(s[o-1].spanId);return{...n,parentSpanId:i}})}function Na(e,r,s){const n=wa(r),o=ba(r,e),{runSpan:i,spans:l}=ja(e,n,s,o),c=ka(i,l),u=Bt(i.startTime),d=o.getTime()-u;return{traceId:e.runId,rootSpanId:e.runId,spans:c,resources:[{name:"workflow",attributes:{"service.name":nt.name}}],knownDurationMs:Math.max(0,d)}}function Ca(e){const{state:r,dispatch:s}=ye(),n=a.useRef(r);n.current=r,a.useEffect(()=>{if(!e)return;let o=0;const i=()=>{const{root:d}=n.current;if(d.startTime){const p=Date.now();p>d.endTime&&(d.endTime=p,d.duration=d.endTime-d.startTime)}o=requestAnimationFrame(i)};o=requestAnimationFrame(i);let l=0,c=0;const u=()=>{const d=n.current;if(d.root.duration>0){const p=(d.width-d.scrollbarWidth)/d.root.duration;(Math.abs(p-c)>c*.001||c===0)&&(c=p,s({type:"detectBaseScale"}))}l=requestAnimationFrame(u)};return l=requestAnimationFrame(u),()=>{cancelAnimationFrame(o),cancelAnimationFrame(l)}},[e,s])}const Ea=450,Sa=240;function Ia({menu:e,items:r,onClose:s}){const n=a.useRef(null);a.useEffect(()=>{const l=p=>{n.current&&!n.current.contains(p.target)&&s()},c=p=>{p.key==="Escape"&&s()},u=()=>{s()},d=setTimeout(()=>{window.addEventListener("mousedown",l),window.addEventListener("keydown",c),window.addEventListener("scroll",u,!0)},0);return()=>{clearTimeout(d),window.removeEventListener("mousedown",l),window.removeEventListener("keydown",c),window.removeEventListener("scroll",u,!0)}},[s]);const[o,i]=a.useState({x:e.x,y:e.y});return a.useEffect(()=>{const l=n.current;if(!l)return;const c=l.getBoundingClientRect();let{x:u,y:d}=e;c.right>window.innerWidth&&(u=window.innerWidth-c.width-8),c.bottom>window.innerHeight&&(d=window.innerHeight-c.height-8),(u!==e.x||d!==e.y)&&i({x:u,y:d})},[e]),r.length===0?null:Ut.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(l=>t.jsxs("button",{type:"button",style:{outline:"none",cursor:l.disabled?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:8,padding:"0 var(--geist-space-2x, 8px)",height:40,textDecoration:"none",borderRadius:6,color:l.destructive?"var(--ds-red-900)":"var(--ds-gray-1000)",width:"100%",background:"transparent",border:"none",fontSize:14,textAlign:"left",opacity:l.disabled?.4:1,transition:"background 0.15s"},disabled:l.disabled,onMouseEnter:c=>{c.currentTarget.style.background="var(--ds-gray-alpha-100)"},onMouseLeave:c=>{c.currentTarget.style.background="transparent"},onClick:()=>{l.action(),s()},children:[l.icon??null,l.label]},l.label))]}),document.body)}function Ta({trace:e,run:r,isLive:s,onWakeUpSleep:n,onCancelRun:o,onResolveHook:i,onLoadMoreSpans:l,hasMoreSpans:c=!1,isLoadingMoreSpans:u=!1,children:d}){const p=Ue(),{state:x,dispatch:m}=ye();Ca(s);const[f,_]=a.useState(null),[C,h]=a.useState(null),[j,v]=a.useState(!1),[F,w]=a.useState(new Set),O=a.useMemo(()=>{const I=new Map;for(const T of e.spans)I.set(T.spanId,T);return I},[e.spans]),E=a.useCallback(async I=>{if(!(j||!C||!i)){if(!C.token){p.error("Unable to resolve hook",{description:"Missing hook token. Try refreshing the run data and retry."});return}try{v(!0),await i(C.token,I),p.success("Hook resolved",{description:"The payload has been sent and the hook resolved."}),w(T=>new Set(T).add(C.hookId)),h(null)}catch(T){console.error("Failed to resolve hook:",T),p.error("Failed to resolve hook",{description:T instanceof Error?T.message:"An unknown error occurred"})}finally{v(!1)}}},[i,C,j]),S=a.useCallback(I=>{const P=I.target.closest("[data-span-id]");if(!P)return;const z=P.dataset.spanId;if(!z)return;I.preventDefault(),I.stopPropagation();const L=O.get(z);if(!L)return;const R=L.attributes.resource??"unknown",b=L.attributes.data,M=!(b!=null&&b.completedAt)&&!(b!=null&&b.disposedAt);_({x:I.clientX,y:I.clientY,spanId:z,spanName:L.name,resourceType:R,isActive:M})},[O]),k=a.useRef(null);a.useEffect(()=>{const I=k.current;if(!I)return;const T=P=>{S(P)};return I.addEventListener("contextmenu",T),()=>{I.removeEventListener("contextmenu",T)}},[S]);const g=a.useRef(!1);a.useEffect(()=>{const I=x.timelineRef.current;if(!I||!l||!c)return;const T=200,P=()=>{g.current||u||!c||I.scrollHeight-I.scrollTop-I.clientHeight>T||(g.current=!0,Promise.resolve(l()).finally(()=>{g.current=!1}))};return I.addEventListener("scroll",P),P(),()=>{I.removeEventListener("scroll",P)}},[x.timelineRef,l,c,u]);const y=a.useCallback(()=>{_(null)},[]),A=a.useCallback(I=>{var z,L;const T=[],P=!r.completedAt;if(I.resourceType==="sleep"&&I.isActive&&P&&n&&T.push({label:"Wake Up Sleep",icon:t.jsx(Vs,{className:"h-3.5 w-3.5"}),action:()=>{n(r.runId,I.spanId).then(R=>{R.stoppedCount>0?p.success("Sleep woken up",{description:`Woke up ${String(R.stoppedCount)} sleep${R.stoppedCount>1?"s":""}`}):p.info("No active sleeps found",{description:"The sleep may have already completed."})}).catch(R=>{p.error("Failed to wake up sleep",{description:R instanceof Error?R.message:"An unknown error occurred"})})}}),I.resourceType==="hook"&&P&&i){const R=O.get(I.spanId),b=(z=R==null?void 0:R.attributes)==null?void 0:z.data,M=!!(b!=null&&b.disposedAt)||!!((L=R==null?void 0:R.events)!=null&&L.some(q=>q.name==="hook_disposed"))||F.has(I.spanId);b!=null&&b.token&&!M&&T.push({label:"Resolve Hook",icon:t.jsx(Pr,{className:"h-3.5 w-3.5"}),action:()=>{h({hookId:I.spanId,token:b.token})}})}return I.resourceType==="run"&&P&&o&&T.push({label:"Cancel Run",icon:t.jsx(zs,{className:"h-3.5 w-3.5"}),destructive:!0,action:()=>{o(r.runId).catch(R=>{p.error("Failed to cancel run",{description:R instanceof Error?R.message:"An unknown error occurred"})})}}),T.push({label:"View Details",icon:t.jsx(Vn,{className:"h-3.5 w-3.5"}),action:()=>{m({type:"select",id:I.spanId})}}),T.push({label:"Copy Name",icon:t.jsx(Kn,{className:"h-3.5 w-3.5"}),action:()=>{navigator.clipboard.writeText(I.spanName).then(()=>{p.success("Name copied to clipboard")}).catch(()=>{p.error("Failed to copy name")})}}),T.push({label:"Copy ID",icon:t.jsx(rt,{className:"h-3.5 w-3.5"}),action:()=>{navigator.clipboard.writeText(I.spanId).then(()=>{p.success("ID copied to clipboard")}).catch(()=>{p.error("Failed to copy ID")})}}),T},[m,n,o,i,O,F,r.runId,r.completedAt]);return t.jsxs("div",{className:"relative w-full h-full",ref:k,children:[d,f?t.jsx(Ia,{menu:f,items:A(f),onClose:y}):null,t.jsx(Fr,{isOpen:C!==null,onClose:()=>h(null),onSubmit:E,isSubmitting:j})]})}function Aa({onSelectionChange:e}){const{state:r}=ye(),{selected:s}=r,n=a.useRef(e);n.current=e;const o=a.useRef(void 0);return a.useEffect(()=>{var l,c;const i=s==null?void 0:s.span.spanId;i!==o.current&&(o.current=i,s?n.current({data:(l=s.span.attributes)==null?void 0:l.data,resource:(c=s.span.attributes)==null?void 0:c.resource,spanId:s.span.spanId}):n.current(null))},[s]),null}function Ra({triggerDeselect:e}){const{dispatch:r}=ye();return a.useEffect(()=>{e>0&&r({type:"deselect"})},[e,r]),null}function Da({selectRequest:e}){const{dispatch:r}=ye();return a.useEffect(()=>{e!=null&&e.id&&r({type:"select",id:e.id})},[r,e]),null}function Ma({onResize:e}){const r=a.useCallback(s=>{s.preventDefault();let n=s.clientX;const o=l=>{const c=n-l.clientX;n=l.clientX,e(c)},i=()=>{document.removeEventListener("pointermove",o),document.removeEventListener("pointerup",i)};document.addEventListener("pointermove",o),document.addEventListener("pointerup",i)},[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 _a({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(Zt,{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 La=({run:e,events:r,isLoading:s,error:n,spanDetailData:o,spanDetailLoading:i,spanDetailError:l,onWakeUpSleep:c,onResolveHook:u,onCancelRun:d,onStreamClick:p,onSpanSelect:x,onLoadEventData:m,onLoadMoreSpans:f,hasMoreSpans:_=!1,isLoadingMoreSpans:C=!1,encryptionKey:h,onDecrypt:j,isDecrypting:v=!1})=>{const F=Ue(),[w,O]=a.useState(null),[E,S]=a.useState(Ea),[k,g]=a.useState(0),[y,A]=a.useState(null),I=!!(e&&!e.completedAt),T=a.useMemo(()=>{if(e!=null&&e.runId)return Na(e,r,new Date)},[e,r]),P=T;a.useEffect(()=>{n&&!s&&(console.error(n),F.error("Error loading workflow trace data",{description:n.message}))},[n,s]);const z=a.useCallback(N=>{x==null||x(N)},[x]),L=a.useCallback(N=>{if(N){const D=N.spanId,B=D?r.filter(V=>V.correlationId===D):[];O({...N,rawEvents:B})}else O(null)},[r]);a.useEffect(()=>{const N=w==null?void 0:w.spanId;if(!N)return;const D=r.filter(B=>B.correlationId===N);O(B=>{if(!B||B.spanId!==N)return B;const V=B.rawEvents??[];return V.length===D.length&&V.every((H,$)=>{var Y;return H.eventId===((Y=D[$])==null?void 0:Y.eventId)})?B:{...B,rawEvents:D}})},[r,w==null?void 0:w.spanId]);const R=a.useCallback(()=>{O(null),g(N=>N+1)},[]),b=a.useCallback(N=>{S(D=>Math.max(Sa,D+N))},[]),M=a.useMemo(()=>!(w!=null&&w.spanId)||!P?-1:P.spans.findIndex(N=>N.spanId===w.spanId),[w==null?void 0:w.spanId,P]),q=M>0,W=M>=0&&P!=null&&M<P.spans.length-1,G=a.useCallback(()=>{var D;if(!P||M<=0)return;const N=(D=P.spans[M-1])==null?void 0:D.spanId;N&&A({id:N,token:Date.now()})},[M,P]),X=a.useCallback(()=>{var D;if(!P||M<0)return;const N=(D=P.spans[M+1])==null?void 0:D.spanId;N&&A({id:N,token:Date.now()})},[M,P]),J=a.useMemo(()=>{var V,ee;if(!(w!=null&&w.data))return;const N=w.data,D=N.stepName,B=N.workflowName;return(D?(V=st(D))==null?void 0:V.shortName:void 0)??(B?(ee=ze(B))==null?void 0:ee.shortName:void 0)??D??B??N.hookId??"Details"},[w==null?void 0:w.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(Cn,{customSpanClassNameFunc:ia,customSpanEventClassNameFunc:la,children:[t.jsx(Aa,{onSelectionChange:L}),t.jsx(Ra,{triggerDeselect:k}),t.jsx(Da,{selectRequest:y}),t.jsx(Ta,{trace:P,run:e,isLive:I,onWakeUpSleep:c,onCancelRun:d,onResolveHook:u,onLoadMoreSpans:f,hasMoreSpans:_,isLoadingMoreSpans:C,children:t.jsx(oa,{eagerRender:!0,height:"100%",isLive:I,trace:P,knownDurationMs:T==null?void 0:T.knownDurationMs,hasMoreData:_||!!s,footer:t.jsx(_a,{hasMore:_,isLive:I,isInitialLoading:!!s})})})]})}),w&&t.jsxs("div",{className:"relative border-l flex-shrink-0 flex flex-col",style:{width:E,borderColor:"var(--ds-gray-200)",backgroundColor:"var(--ds-background-100)"},children:[t.jsx(Ma,{onResize:b}),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:G,disabled:!q,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:q?"pointer":"not-allowed",opacity:q?1:.45,flexShrink:0,transition:"background 0.15s"},onMouseEnter:N=>{q&&(N.currentTarget.style.background="var(--ds-gray-alpha-100)")},onMouseLeave:N=>{N.currentTarget.style.background="transparent"},children:t.jsx(Ws,{size:16})}),t.jsx("button",{type:"button","aria-label":"Next span",onClick:X,disabled:!W,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:W?"pointer":"not-allowed",opacity:W?1:.45,flexShrink:0,transition:"background 0.15s"},onMouseEnter:N=>{W&&(N.currentTarget.style.background="var(--ds-gray-alpha-100)")},onMouseLeave:N=>{N.currentTarget.style.background="transparent"},children:t.jsx(Hs,{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:R,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:N=>{N.currentTarget.style.background="var(--ds-gray-alpha-100)"},onMouseLeave:N=>{N.currentTarget.style.background="transparent"},children:t.jsx(Bs,{size:16})})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsx(Qe,{title:"Failed to load entity details",children:t.jsx(Bo,{run:e,onStreamClick:p,spanDetailData:o??null,spanDetailError:l,spanDetailLoading:i,onSpanSelect:z,onWakeUpSleep:c,onLoadEventData:m,onResolveHook:u,encryptionKey:h,onDecrypt:j,isDecrypting:v,selectedSpan:w})})})]})]}):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 Pa(e,r,s,n={}){const o=n.resolveData??"all";let i,l;if(r==="run")i=await ht(Wt(e,s,o)),l=i.runId;else if(r==="step"){const{runId:c}=n;if(!c)throw new _e("runId is required for step resource",{layer:"client"});i=await ht(En(e,c,s,o)),l=i.stepId}else if(r==="hook")i=await ht(Hr(e,s,o)),l=i.hookId;else throw new _e(`Unknown resource type: ${r}`,{layer:"client"});return{data:i,correlationId:l}}function Fa(e,r,s,n={}){const{refreshInterval:o=0,runId:i,enabled:l=!0,encryptionKey:c}=n,[u,d]=a.useState(null),[p,x]=a.useState(l),[m,f]=a.useState(null),_=a.useCallback(async j=>c?He(j,c):me(j),[c]),C=a.useRef(""),h=a.useCallback(async()=>{if(!l){x(!1);return}const j=`${r}:${s}`;if(j!==C.current&&(d(null),C.current=j),f(null),x(!0),r==="hook"){try{const{error:v,result:F}=await ue(Hr(e,s,"all"));if(v){f(v);return}try{d(await _(F))}catch(w){f(w instanceof Error?w:new Error(String(w)))}}finally{x(!1)}return}if(r==="sleep"){try{if(!i){f(new Error("runId is required for loading sleep details"));return}const{error:v,result:F}=await ue(Be(e,i,{sortOrder:"asc",limit:1e3,withData:!0}));if(v){f(v);return}try{const w=F.data.map(me),O=await Promise.all(w.filter(S=>S.correlationId===s).map(_)),E=Xr(O);if(E===null){f(new Error(`Failed to load ${r} details: missing required event data`));return}d(E)}catch(w){f(w instanceof Error?w:new Error(String(w)))}}finally{x(!1)}return}try{const{data:v}=await Pa(e,r,s,{runId:i});d(await _(v))}catch(v){v instanceof Error?f(v):f(new Error(String(v)));return}finally{x(!1)}},[e,r,s,i,l,_]);return a.useEffect(()=>{h()},[h]),a.useEffect(()=>{if(!o||o<=0)return;const j=setInterval(h,o);return()=>clearInterval(j)},[o,h]),{data:u,loading:p,error:m,refresh:h}}function Vt(e,r,s){const n=[...e,...r],o=new Map(n.map(i=>[i[s],i]));return Array.from(o.values())}async function Oa(e){const{fetchFn:r,setItems:s,setCursor:n,setError:o,idKey:i,cursorStrategy:l="always",transform:c}=e,{error:u,result:d}=await r();if(u)return o(u),!1;if(d.data.length>0){const p=c?d.data.map(c):d.data;return s(m=>Vt(m,p,i)),(l==="onHasMore"?!!(d.cursor&&d.hasMore):!!d.cursor)&&n(d.cursor),!0}return!1}const $a=100,Wa=500,Ha=100,Ba=5e3;function Va(e,r,s={}){const{live:n=!1}=s,[o,i]=a.useState(null),[l,c]=a.useState([]),[u,d]=a.useState(!0),[p,x]=a.useState(null),[m,f]=a.useState(),[_,C]=a.useState(!1),[h,j]=a.useState(!1),v=a.useRef(!1),[F,w]=a.useState(!1),O=a.useCallback(async()=>{if(v.current)return;v.current=!0,d(!0),x(null);const[y,A]=await Promise.all([ue(Wt(e,r,"none")),ue(Be(e,r,{sortOrder:"asc",limit:Wa,withData:!1}))]);y.error?x(y.error):i(me(y.result));const I=A.error?[]:A.result.data.map(me);c(Vt([],I,"eventId")),f(A.error||!A.result.hasMore?void 0:A.result.cursor),C(!!(!A.error&&A.result.hasMore)),d(!1),w(!0),v.current=!1,!y.error&&A.error&&x(A.error)},[e,r]),E=a.useCallback(async()=>{if(!(v.current||!F||h||!_)){j(!0);try{const y=await ue(Be(e,r,{cursor:m,sortOrder:"asc",limit:Ha,withData:!1}));if(y.error)x(y.error);else{const A=y.result.data.map(me);A.length>0&&c(I=>Vt(I,A,"eventId")),C(!!y.result.hasMore),f(y.result.hasMore?y.result.cursor:void 0)}}finally{j(!1)}}},[e,r,F,h,_,m]),S=a.useCallback(async()=>{if(o!=null&&o.completedAt)return!1;const{error:y,result:A}=await ue(Wt(e,r,"none"));return y?(x(y),!1):(x(null),i(me(A)),!0)},[e,r,o==null?void 0:o.completedAt]),k=a.useCallback(()=>Oa({fetchFn:()=>ue(Be(e,r,{cursor:m,sortOrder:"asc",limit:$a,withData:!1})),setItems:c,setCursor:f,setError:x,idKey:"eventId",transform:me}),[e,r,m]),g=a.useCallback(async()=>{if(v.current||!F)return{foundNewItems:!1};let y=!1;try{const[A,I]=await Promise.all([S(),k()]);y=I}catch(A){console.error("Update error:",A)}return{foundNewItems:y}},[k,F,S]);return a.useEffect(()=>{O()},[O]),a.useEffect(()=>{if(!n||!F||o!=null&&o.completedAt)return;const y=setInterval(()=>{g()},Ba);return()=>{clearInterval(y)}},[n,F,g,o==null?void 0:o.completedAt]),{run:o??{},events:l,loading:u,error:p,update:g,loadMoreTraceData:E,hasMoreTraceData:_,isLoadingMoreTraceData:h}}function za(e){return typeof e=="object"&&e!==null&&"message"in e&&"layer"in e&&"cause"in e&&"request"in e}async function Ua(e,r,s,n){try{const o=`/api/stream/${encodeURIComponent(r)}${s!=null?`?startIndex=${s}`:""}`,i=await fetch(o,{signal:n});if(!i.ok){const l=await i.json().catch(()=>null);throw l&&za(l)?new _e(l.message,{layer:"client",cause:l.cause,request:l.request}):new _e(`Failed to read stream: ${i.status}`,{layer:"client"})}if(!i.body)throw new _e("Failed to read stream: no body",{layer:"client"});return i.body}catch(o){throw o instanceof _e?o:new _e("Failed to read stream",{layer:"client",cause:o})}}async function Ka(e,r){return ht(Sn(e,r))}const qa=1e4;function Ga(e,r,s=qa){const[n,o]=a.useState([]),[i,l]=a.useState(!0),[c,u]=a.useState(null),d=a.useCallback(async()=>{l(!0),u(null);try{const p=await Ka(e,r);o(p)}catch(p){u(p instanceof Error?p:new Error(String(p)))}finally{l(!1)}},[e,r]);return a.useEffect(()=>{d()},[d]),a.useEffect(()=>{if(!s||s<=0)return;const p=setInterval(d,s);return()=>clearInterval(p)},[s,d]),{streams:n,loading:i,error:c,refresh:d}}var Za=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],je=Za.reduce((e,r)=>{const s=a.forwardRef((n,o)=>{const{asChild:i,...l}=n,c=i?Gt:r;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),t.jsx(c,{...l,ref:o})});return s.displayName=`Primitive.${r}`,{...e,[r]:s}},{});function Ya(e,r){e&&Ut.flushSync(()=>e.dispatchEvent(r))}var Xa="DismissableLayer",zt="dismissableLayer.update",Ja="dismissableLayer.pointerDownOutside",Qa="dismissableLayer.focusOutside",gr,Jr=a.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Qr=a.forwardRef((e,r)=>{const{disableOutsidePointerEvents:s=!1,onEscapeKeyDown:n,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:l,onDismiss:c,...u}=e,d=a.useContext(Jr),[p,x]=a.useState(null),m=(p==null?void 0:p.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=a.useState({}),_=Se(r,S=>x(S)),C=Array.from(d.layers),[h]=[...d.layersWithOutsidePointerEventsDisabled].slice(-1),j=C.indexOf(h),v=p?C.indexOf(p):-1,F=d.layersWithOutsidePointerEventsDisabled.size>0,w=v>=j,O=ri(S=>{const k=S.target,g=[...d.branches].some(y=>y.contains(k));!w||g||(o==null||o(S),l==null||l(S),S.defaultPrevented||c==null||c())},m),E=si(S=>{const k=S.target;[...d.branches].some(y=>y.contains(k))||(i==null||i(S),l==null||l(S),S.defaultPrevented||c==null||c())},m);return Us(S=>{v===d.layers.size-1&&(n==null||n(S),!S.defaultPrevented&&c&&(S.preventDefault(),c()))},m),a.useEffect(()=>{if(p)return s&&(d.layersWithOutsidePointerEventsDisabled.size===0&&(gr=m.body.style.pointerEvents,m.body.style.pointerEvents="none"),d.layersWithOutsidePointerEventsDisabled.add(p)),d.layers.add(p),yr(),()=>{s&&d.layersWithOutsidePointerEventsDisabled.size===1&&(m.body.style.pointerEvents=gr)}},[p,m,s,d]),a.useEffect(()=>()=>{p&&(d.layers.delete(p),d.layersWithOutsidePointerEventsDisabled.delete(p),yr())},[p,d]),a.useEffect(()=>{const S=()=>f({});return document.addEventListener(zt,S),()=>document.removeEventListener(zt,S)},[]),t.jsx(je.div,{...u,ref:_,style:{pointerEvents:F?w?"auto":"none":void 0,...e.style},onFocusCapture:be(e.onFocusCapture,E.onFocusCapture),onBlurCapture:be(e.onBlurCapture,E.onBlurCapture),onPointerDownCapture:be(e.onPointerDownCapture,O.onPointerDownCapture)})});Qr.displayName=Xa;var ei="DismissableLayerBranch",ti=a.forwardRef((e,r)=>{const s=a.useContext(Jr),n=a.useRef(null),o=Se(r,n);return a.useEffect(()=>{const i=n.current;if(i)return s.branches.add(i),()=>{s.branches.delete(i)}},[s.branches]),t.jsx(je.div,{...e,ref:o})});ti.displayName=ei;function ri(e,r=globalThis==null?void 0:globalThis.document){const s=yt(e),n=a.useRef(!1),o=a.useRef(()=>{});return a.useEffect(()=>{const i=c=>{if(c.target&&!n.current){let u=function(){es(Ja,s,d,{discrete:!0})};const d={originalEvent:c};c.pointerType==="touch"?(r.removeEventListener("click",o.current),o.current=u,r.addEventListener("click",o.current,{once:!0})):u()}else r.removeEventListener("click",o.current);n.current=!1},l=window.setTimeout(()=>{r.addEventListener("pointerdown",i)},0);return()=>{window.clearTimeout(l),r.removeEventListener("pointerdown",i),r.removeEventListener("click",o.current)}},[r,s]),{onPointerDownCapture:()=>n.current=!0}}function si(e,r=globalThis==null?void 0:globalThis.document){const s=yt(e),n=a.useRef(!1);return a.useEffect(()=>{const o=i=>{i.target&&!n.current&&es(Qa,s,{originalEvent:i},{discrete:!1})};return r.addEventListener("focusin",o),()=>r.removeEventListener("focusin",o)},[r,s]),{onFocusCapture:()=>n.current=!0,onBlurCapture:()=>n.current=!1}}function yr(){const e=new CustomEvent(zt);document.dispatchEvent(e)}function es(e,r,s,{discrete:n}){const o=s.originalEvent.target,i=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});r&&o.addEventListener(e,r,{once:!0}),n?Ya(o,i):o.dispatchEvent(i)}var Ot="focusScope.autoFocusOnMount",$t="focusScope.autoFocusOnUnmount",vr={bubbles:!1,cancelable:!0},ni="FocusScope",ts=a.forwardRef((e,r)=>{const{loop:s=!1,trapped:n=!1,onMountAutoFocus:o,onUnmountAutoFocus:i,...l}=e,[c,u]=a.useState(null),d=yt(o),p=yt(i),x=a.useRef(null),m=Se(r,C=>u(C)),f=a.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;a.useEffect(()=>{if(n){let C=function(F){if(f.paused||!c)return;const w=F.target;c.contains(w)?x.current=w:Ce(x.current,{select:!0})},h=function(F){if(f.paused||!c)return;const w=F.relatedTarget;w!==null&&(c.contains(w)||Ce(x.current,{select:!0}))},j=function(F){if(document.activeElement===document.body)for(const O of F)O.removedNodes.length>0&&Ce(c)};document.addEventListener("focusin",C),document.addEventListener("focusout",h);const v=new MutationObserver(j);return c&&v.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",C),document.removeEventListener("focusout",h),v.disconnect()}}},[n,c,f.paused]),a.useEffect(()=>{if(c){br.add(f);const C=document.activeElement;if(!c.contains(C)){const j=new CustomEvent(Ot,vr);c.addEventListener(Ot,d),c.dispatchEvent(j),j.defaultPrevented||(oi(di(rs(c)),{select:!0}),document.activeElement===C&&Ce(c))}return()=>{c.removeEventListener(Ot,d),setTimeout(()=>{const j=new CustomEvent($t,vr);c.addEventListener($t,p),c.dispatchEvent(j),j.defaultPrevented||Ce(C??document.body,{select:!0}),c.removeEventListener($t,p),br.remove(f)},0)}}},[c,d,p,f]);const _=a.useCallback(C=>{if(!s&&!n||f.paused)return;const h=C.key==="Tab"&&!C.altKey&&!C.ctrlKey&&!C.metaKey,j=document.activeElement;if(h&&j){const v=C.currentTarget,[F,w]=ai(v);F&&w?!C.shiftKey&&j===w?(C.preventDefault(),s&&Ce(F,{select:!0})):C.shiftKey&&j===F&&(C.preventDefault(),s&&Ce(w,{select:!0})):j===v&&C.preventDefault()}},[s,n,f.paused]);return t.jsx(je.div,{tabIndex:-1,...l,ref:m,onKeyDown:_})});ts.displayName=ni;function oi(e,{select:r=!1}={}){const s=document.activeElement;for(const n of e)if(Ce(n,{select:r}),document.activeElement!==s)return}function ai(e){const r=rs(e),s=wr(r,e),n=wr(r.reverse(),e);return[s,n]}function rs(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 wr(e,r){for(const s of e)if(!ii(s,{upTo:r}))return s}function ii(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 li(e){return e instanceof HTMLInputElement&&"select"in e}function Ce(e,{select:r=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&li(e)&&r&&e.select()}}var br=ci();function ci(){let e=[];return{add(r){const s=e[0];r!==s&&(s==null||s.pause()),e=jr(e,r),e.unshift(r)},remove(r){var s;e=jr(e,r),(s=e[0])==null||s.resume()}}}function jr(e,r){const s=[...e],n=s.indexOf(r);return n!==-1&&s.splice(n,1),s}function di(e){return e.filter(r=>r.tagName!=="A")}var ui="Portal",ss=a.forwardRef((e,r)=>{var c;const{container:s,...n}=e,[o,i]=a.useState(!1);Ks(()=>i(!0),[]);const l=s||o&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return l?_s.createPortal(t.jsx(je.div,{...n,ref:r}),l):null});ss.displayName=ui;var Qt="Dialog",[ns,os]=Or(Qt),[fi,he]=ns(Qt),as=e=>{const{__scopeDialog:r,children:s,open:n,defaultOpen:o,onOpenChange:i,modal:l=!0}=e,c=a.useRef(null),u=a.useRef(null),[d=!1,p]=Gs({prop:n,defaultProp:o,onChange:i});return t.jsx(fi,{scope:r,triggerRef:c,contentRef:u,contentId:It(),titleId:It(),descriptionId:It(),open:d,onOpenChange:p,onOpenToggle:a.useCallback(()=>p(x=>!x),[p]),modal:l,children:s})};as.displayName=Qt;var is="DialogTrigger",ls=a.forwardRef((e,r)=>{const{__scopeDialog:s,...n}=e,o=he(is,s),i=Se(r,o.triggerRef);return t.jsx(je.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":rr(o.open),...n,ref:i,onClick:be(e.onClick,o.onOpenToggle)})});ls.displayName=is;var er="DialogPortal",[mi,cs]=ns(er,{forceMount:void 0}),ds=e=>{const{__scopeDialog:r,forceMount:s,children:n,container:o}=e,i=he(er,r);return t.jsx(mi,{scope:r,forceMount:s,children:a.Children.map(n,l=>t.jsx(qt,{present:s||i.open,children:t.jsx(ss,{asChild:!0,container:o,children:l})}))})};ds.displayName=er;var kt="DialogOverlay",us=a.forwardRef((e,r)=>{const s=cs(kt,e.__scopeDialog),{forceMount:n=s.forceMount,...o}=e,i=he(kt,e.__scopeDialog);return i.modal?t.jsx(qt,{present:n||i.open,children:t.jsx(pi,{...o,ref:r})}):null});us.displayName=kt;var pi=a.forwardRef((e,r)=>{const{__scopeDialog:s,...n}=e,o=he(kt,s);return t.jsx(Ys,{as:Gt,allowPinchZoom:!0,shards:[o.contentRef],children:t.jsx(je.div,{"data-state":rr(o.open),...n,ref:r,style:{pointerEvents:"auto",...n.style}})})}),Fe="DialogContent",fs=a.forwardRef((e,r)=>{const s=cs(Fe,e.__scopeDialog),{forceMount:n=s.forceMount,...o}=e,i=he(Fe,e.__scopeDialog);return t.jsx(qt,{present:n||i.open,children:i.modal?t.jsx(hi,{...o,ref:r}):t.jsx(xi,{...o,ref:r})})});fs.displayName=Fe;var hi=a.forwardRef((e,r)=>{const s=he(Fe,e.__scopeDialog),n=a.useRef(null),o=Se(r,s.contentRef,n);return a.useEffect(()=>{const i=n.current;if(i)return Zs(i)},[]),t.jsx(ms,{...e,ref:o,trapFocus:s.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:be(e.onCloseAutoFocus,i=>{var l;i.preventDefault(),(l=s.triggerRef.current)==null||l.focus()}),onPointerDownOutside:be(e.onPointerDownOutside,i=>{const l=i.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0;(l.button===2||c)&&i.preventDefault()}),onFocusOutside:be(e.onFocusOutside,i=>i.preventDefault())})}),xi=a.forwardRef((e,r)=>{const s=he(Fe,e.__scopeDialog),n=a.useRef(!1),o=a.useRef(!1);return t.jsx(ms,{...e,ref:r,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{var l,c;(l=e.onCloseAutoFocus)==null||l.call(e,i),i.defaultPrevented||(n.current||(c=s.triggerRef.current)==null||c.focus(),i.preventDefault()),n.current=!1,o.current=!1},onInteractOutside:i=>{var u,d;(u=e.onInteractOutside)==null||u.call(e,i),i.defaultPrevented||(n.current=!0,i.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const l=i.target;((d=s.triggerRef.current)==null?void 0:d.contains(l))&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&o.current&&i.preventDefault()}})}),ms=a.forwardRef((e,r)=>{const{__scopeDialog:s,trapFocus:n,onOpenAutoFocus:o,onCloseAutoFocus:i,...l}=e,c=he(Fe,s),u=a.useRef(null),d=Se(r,u);return Xs(),t.jsxs(t.Fragment,{children:[t.jsx(ts,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:o,onUnmountAutoFocus:i,children:t.jsx(Qr,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":rr(c.open),...l,ref:d,onDismiss:()=>c.onOpenChange(!1)})}),t.jsxs(t.Fragment,{children:[t.jsx(yi,{titleId:c.titleId}),t.jsx(wi,{contentRef:u,descriptionId:c.descriptionId})]})]})}),tr="DialogTitle",ps=a.forwardRef((e,r)=>{const{__scopeDialog:s,...n}=e,o=he(tr,s);return t.jsx(je.h2,{id:o.titleId,...n,ref:r})});ps.displayName=tr;var hs="DialogDescription",xs=a.forwardRef((e,r)=>{const{__scopeDialog:s,...n}=e,o=he(hs,s);return t.jsx(je.p,{id:o.descriptionId,...n,ref:r})});xs.displayName=hs;var gs="DialogClose",ys=a.forwardRef((e,r)=>{const{__scopeDialog:s,...n}=e,o=he(gs,s);return t.jsx(je.button,{type:"button",...n,ref:r,onClick:be(e.onClick,()=>o.onOpenChange(!1))})});ys.displayName=gs;function rr(e){return e?"open":"closed"}var vs="DialogTitleWarning",[gi,ws]=qs(vs,{contentName:Fe,titleName:tr,docsSlug:"dialog"}),yi=({titleId:e})=>{const r=ws(vs),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 a.useEffect(()=>{e&&(document.getElementById(e)||console.error(s))},[s,e]),null},vi="DialogDescriptionWarning",wi=({contentRef:e,descriptionId:r})=>{const n=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${ws(vi).contentName}}.`;return a.useEffect(()=>{var i;const o=(i=e.current)==null?void 0:i.getAttribute("aria-describedby");r&&o&&(document.getElementById(r)||console.warn(n))},[n,e,r]),null},bi=as,ji=ls,ki=ds,Ni=us,Ci=fs,Ei=ps,Si=xs,bs=ys,js="AlertDialog",[Ii]=Or(js,[os]),ke=os(),ks=e=>{const{__scopeAlertDialog:r,...s}=e,n=ke(r);return t.jsx(bi,{...n,...s,modal:!0})};ks.displayName=js;var Ti="AlertDialogTrigger",Ai=a.forwardRef((e,r)=>{const{__scopeAlertDialog:s,...n}=e,o=ke(s);return t.jsx(ji,{...o,...n,ref:r})});Ai.displayName=Ti;var Ri="AlertDialogPortal",Ns=e=>{const{__scopeAlertDialog:r,...s}=e,n=ke(r);return t.jsx(ki,{...n,...s})};Ns.displayName=Ri;var Di="AlertDialogOverlay",Cs=a.forwardRef((e,r)=>{const{__scopeAlertDialog:s,...n}=e,o=ke(s);return t.jsx(Ni,{...o,...n,ref:r})});Cs.displayName=Di;var Ve="AlertDialogContent",[Mi,_i]=Ii(Ve),Es=a.forwardRef((e,r)=>{const{__scopeAlertDialog:s,children:n,...o}=e,i=ke(s),l=a.useRef(null),c=Se(r,l),u=a.useRef(null);return t.jsx(gi,{contentName:Ve,titleName:Ss,docsSlug:"alert-dialog",children:t.jsx(Mi,{scope:s,cancelRef:u,children:t.jsxs(Ci,{role:"alertdialog",...i,...o,ref:c,onOpenAutoFocus:be(o.onOpenAutoFocus,d=>{var p;d.preventDefault(),(p=u.current)==null||p.focus({preventScroll:!0})}),onPointerDownOutside:d=>d.preventDefault(),onInteractOutside:d=>d.preventDefault(),children:[t.jsx(In,{children:n}),t.jsx(Pi,{contentRef:l})]})})})});Es.displayName=Ve;var Ss="AlertDialogTitle",Is=a.forwardRef((e,r)=>{const{__scopeAlertDialog:s,...n}=e,o=ke(s);return t.jsx(Ei,{...o,...n,ref:r})});Is.displayName=Ss;var Ts="AlertDialogDescription",As=a.forwardRef((e,r)=>{const{__scopeAlertDialog:s,...n}=e,o=ke(s);return t.jsx(Si,{...o,...n,ref:r})});As.displayName=Ts;var Li="AlertDialogAction",Rs=a.forwardRef((e,r)=>{const{__scopeAlertDialog:s,...n}=e,o=ke(s);return t.jsx(bs,{...o,...n,ref:r})});Rs.displayName=Li;var Ds="AlertDialogCancel",Ms=a.forwardRef((e,r)=>{const{__scopeAlertDialog:s,...n}=e,{cancelRef:o}=_i(Ds,s),i=ke(s),l=Se(r,o);return t.jsx(bs,{...i,...n,ref:l})});Ms.displayName=Ds;var Pi=({contentRef:e})=>{const r=`\`${Ve}\` requires a description for the component to be accessible for screen reader users.
|
|
28
|
-
|
|
29
|
-
You can add a description to the \`${Ve}\` by passing a \`${Ts}\` 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 \`${Ve}\`. 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 a.useEffect(()=>{var n;document.getElementById((n=e.current)==null?void 0:n.getAttribute("aria-describedby"))||console.warn(r)},[r,e]),null},Fi=ks,Oi=Ns,$i=Cs,Wi=Es,Hi=Rs,Bi=Ms,Vi=Is,zi=As;function kr({...e}){return t.jsx(Fi,{"data-slot":"alert-dialog",...e})}function Ui({...e}){return t.jsx(Oi,{"data-slot":"alert-dialog-portal",...e})}function Ki({className:e,...r}){return t.jsx($i,{"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 Nr({className:e,onSubmit:r,...s}){return t.jsxs(Ui,{children:[t.jsx(Ki,{}),t.jsx(Wi,{"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 Cr({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 Er({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 Sr({className:e,...r}){return t.jsx(Vi,{"data-slot":"alert-dialog-title",className:de("text-lg font-semibold",e),...r})}function Ir({className:e,...r}){return t.jsx(zi,{"data-slot":"alert-dialog-description",className:de("text-muted-foreground text-sm",e),...r})}function Tr({className:e,...r}){return t.jsx(Hi,{className:de(Br(),e),...r})}function Ar({className:e,...r}){return t.jsx(Bi,{className:de(Br({variant:"outline"}),e),...r})}function qi({...e}){return t.jsx("nav",{"aria-label":"breadcrumb","data-slot":"breadcrumb",...e})}function Gi({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 Rr({className:e,...r}){return t.jsx("li",{"data-slot":"breadcrumb-item",className:de("inline-flex items-center gap-1.5",e),...r})}function Zi({asChild:e,className:r,...s}){const n=e?Gt:"a";return t.jsx(n,{"data-slot":"breadcrumb-link",className:de("hover:text-foreground transition-colors",r),...s})}function Yi({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 Xi({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(Kt,{})})}const Me=4,$e=200,Ji=6;function gt(e,r=0){if(e==null)return e;if(ArrayBuffer.isView(e)&&!(e instanceof DataView)){const s=e,n=s.constructor.name,o=Array.from({length:Math.min(s.length,8)},(l,c)=>s[c]),i=s.length>8?", …":"";return`${n}(${s.length}) [${o.join(", ")}${i}]`}if(e instanceof ArrayBuffer)return`ArrayBuffer(${e.byteLength})`;if(r>=Ji)return Array.isArray(e)?`Array(${e.length})`:typeof e=="object"?"{…}":e;if(Array.isArray(e)){if(e.length<=$e)return e.map(n=>gt(n,r+1));const s=e.slice(0,$e).map(n=>gt(n,r+1));return s.push(`… ${e.length-$e} more items`),s}if(typeof e=="object"){const s=Object.keys(e),n={},o=Math.min(s.length,$e);for(let i=0;i<o;i++)n[s[i]]=gt(e[s[i]],r+1);return s.length>$e&&(n[`… ${s.length-$e} more keys`]="…"),n}return e}const Qi=()=>new Promise(e=>setTimeout(e,0)),el=64;function tl(e){if(e.length<Me)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 rl(e,r,s,n){const[o,i]=a.useState([]),[l,c]=a.useState(!1),[u,d]=a.useState(null),p=a.useRef(null),x=a.useRef(0);return a.useEffect(()=>{if(i([]),d(null),x.current=0,!r){c(!1);return}let m=!0;const f=new AbortController;p.current=f,c(!0);const _=Dn();return(async()=>{try{const h=await Ua(e,r,void 0,f.signal),j=n?await On(n):void 0,v=h.getReader(),F=new TextDecoder;let w=new Uint8Array(0),O=null,E="";const S=g=>{const y=new Uint8Array(w.length+g.length);y.set(w,0),y.set(g,w.length),w=y},k=g=>{if(!m||!g)return;const y=x.current++;let A;try{const I=JSON.parse(g);A=JSON.stringify(I,null,2)}catch{A=g}i(I=>[...I,{id:y,text:A}])};for(;!f.signal.aborted;){const{value:g,done:y}=await v.read();if(y){O==="legacy"&&E.trim()&&(k(E.trim()),E=""),m&&c(!1);break}if(O===null?(S(g),w.length>=Me&&(O=tl(w)),O==="legacy"&&(E=F.decode(w,{stream:!0}),w=new Uint8Array(0))):O==="legacy"?E+=F.decode(g,{stream:!0}):S(g),O==="legacy"){const T=E.split(`
|
|
34
|
-
`);E=T.pop()??"";for(const P of T){const z=P.trim();z&&k(z)}continue}let A=0,I=0;for(;A+Me<=w.length;){const P=new DataView(w.buffer,w.byteOffset+A,w.byteLength-A).getUint32(0,!1);if(P===0||P>10*1024*1024||A+Me+P>w.length)break;const z=w.slice(A+Me,A+Me+P);A+=Me+P;try{const{format:L,payload:R}=Tn(z);let b;if(L===An.ENCRYPTED){if(!j){m&&(d("This stream is encrypted. Click Decrypt to view."),c(!1)),v.cancel().catch(()=>{});return}b=await $n(j,R)}else b=z;const M=Rn(b,_);if(m&&M!==void 0&&M!==null){const q=x.current++;let W;try{if(typeof M=="string")W=M;else{const G=gt(M);W=JSON.stringify(G,null,2)}}catch{W="[Serialization Error]"}i(G=>[...G,{id:q,text:W}])}}catch(L){console.error("Failed to process stream frame:",L)}if(I++,I%el===0&&(await Qi(),f.signal.aborted||!m))break}w=w.slice(A)}}catch(h){if(f.signal.aborted)return;m&&(d(h instanceof Error?h.message:String(h)),c(!1))}})(),()=>{m=!1,p.current&&p.current.abort()}},[e,r,s,n]),{chunks:o,isLive:l,error:u}}const sl=100,nl=100;function ol(e,r,s={}){const{sortOrder:n="asc",encryptionKey:o,enabled:i=!0}=s,[l,c]=a.useState([]),[u,d]=a.useState(!0),[p,x]=a.useState(null),[m,f]=a.useState(),[_,C]=a.useState(!1),[h,j]=a.useState(!1),v=a.useRef(!1),F=a.useRef(o);F.current=o;const w=a.useCallback(async()=>{if(!v.current){v.current=!0,d(!0),x(null),c([]),f(void 0),C(!1);try{const{error:E,result:S}=await ue(Be(e,r,{sortOrder:n,limit:sl,withData:!1}));if(E)x(E);else{const k=S.data.map(me),g=F.current;if(g){const y=await Promise.all(k.map(A=>He(A,g)));c(y)}else c(k);f(S.hasMore?S.cursor:void 0),C(!!S.hasMore)}}catch(E){x(E)}finally{d(!1),v.current=!1}}},[e,r,n]);a.useEffect(()=>{i&&w()},[w,i]),a.useEffect(()=>{if(!o||l.length===0)return;let E=!1;return Promise.all(l.map(S=>He(S,o))).then(S=>{E||c(S)}).catch(()=>{}),()=>{E=!0}},[o]);const O=a.useCallback(async()=>{if(!(h||!m)){j(!0);try{const{error:E,result:S}=await ue(Be(e,r,{cursor:m,sortOrder:n,limit:nl,withData:!1}));if(E)x(E);else{if(S.data.length>0){const k=S.data.map(me),g=F.current;if(g){const y=await Promise.all(k.map(A=>He(A,g)));c(A=>[...A,...y])}else c(y=>[...y,...k])}f(S.hasMore?S.cursor:void 0),C(!!S.hasMore)}}catch(E){x(E)}finally{j(!1)}}},[e,r,n,m,h]);return{events:l,loading:u,error:p,hasMore:_,loadingMore:h,loadMore:O}}function al({hasError:e,errorMessage:r}){return t.jsx("div",{className:"flex items-center gap-2",children:t.jsxs(Vr,{children:[t.jsx(zr,{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(Ur,{children:t.jsx("p",{children:e?`Error updating data: ${r}`:`Content updates every ${Mn/1e3} seconds`})})]})})}({...Js});function il({runId:e,selectedId:r}){var Te;const s=Ls(),[n]=Dr(),{serverConfig:o}=_n(),[i,l]=a.useState(!1),[c,u]=a.useState(!1),[d,p]=a.useState(!1),[x,m]=a.useState(!1),f=a.useMemo(()=>({}),[]),_=n.get("tab")||"trace",C=_==="graph"?"trace":_,h=n.get("streamId"),j=a.useCallback(U=>{const te=new URLSearchParams(n.toString());for(const[ne,re]of Object.entries(U))re===null?te.delete(ne):te.set(ne,re);s(`?${te.toString()}`,{preventScrollReset:!0})},[s,n]),v=a.useCallback(U=>{j(U==="trace"||U==="graph"?{tab:U,streamId:null}:{tab:U})},[j]),F=a.useCallback(U=>{j({streamId:U})},[j]),w=a.useCallback(U=>{j({tab:"streams",streamId:U})},[j]),O=a.useCallback(async(U,te)=>Qs(f,U,{correlationIds:[te]}),[f]),E=a.useRef(null),S=a.useCallback(async(U,te)=>{await en(f,U,te)},[f]),k=a.useCallback(async U=>{const{error:te,result:ne}=await ue(nr(f,U.runId,U.eventId,"all"));if(te)throw te;const re=E.current?await He(ne,E.current):me(ne);return"eventData"in re?re.eventData:null},[f]),g=a.useCallback(async(U,te)=>{const{error:ne,result:re}=await ue(nr(f,e,te,"all"));if(ne)throw ne;const ae=E.current?await He(re,E.current):me(re);return"eventData"in ae?ae.eventData:null},[f,e]);o.backendId==="local"||o.backendId;const{run:y,events:A,loading:I,error:T,update:P,loadMoreTraceData:z,hasMoreTraceData:L,isLoadingMoreTraceData:R}=Va(f,e,{live:!0}),b=y??{},[M,q]=a.useState(null);E.current=M;const[W,G]=a.useState("asc"),{events:X,loading:J,hasMore:N,loadingMore:D,loadMore:B}=ol(f,e,{sortOrder:W,encryptionKey:M??void 0,enabled:C==="events"}),[V,ee]=a.useState(null),{data:H,loading:$,error:Y,refresh:Z}=Fa(f,(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:M??void 0}),[se,oe]=a.useState(!1),fe=a.useCallback(async()=>{if(M){Z();return}oe(!0);try{const{error:U,result:te}=await ue(Ln(f,e));if(U){Re.error(`Failed to fetch encryption key: ${U.message}`);return}if(!te){Re.error("Encryption is not configured for this deployment.");return}q(te),Re.success("Run data decrypted successfully")}finally{oe(!1)}},[M,f,e,Z]),Oe=a.useCallback(U=>{ee(U)},[]),{streams:ve,loading:Ne,error:Ke}=Ga(f,e),{chunks:ot,isLive:at,error:xe}=rl(f,h,e,M),it=()=>{p(!0)},lt=async()=>{if(!i)try{l(!0),p(!1),await dn(f,e),await P(),Re.success("Run cancelled successfully")}catch(U){console.error("Failed to cancel run:",U),Re.error("Failed to cancel run",{description:U instanceof Error?U.message:"An unknown error occurred"})}finally{l(!1)}},ct=()=>{m(!0)},dt=async()=>{if(!c)try{u(!0),m(!1);const U=await un(f,b.runId);Re.success("New run started successfully",{description:`Run ID: ${U}`}),s(`/run/${U}`)}catch(U){console.error("Failed to re-run workflow:",U),Re.error("Failed to start new run",{description:U instanceof Error?U.message:"An unknown error occurred"})}finally{u(!1),m(!1)}};if(T&&!y)return t.jsxs(tn,{variant:"destructive",className:"m-4",children:[t.jsx(Mr,{className:"h-4 w-4"}),t.jsx(rn,{children:"Error loading workflow run"}),t.jsx(sn,{children:T.message})]});const Ie=(Te=ze(b.workflowName))==null?void 0:Te.shortName;return t.jsxs(t.Fragment,{children:[t.jsx(kr,{open:d,onOpenChange:p,children:t.jsxs(Nr,{children:[t.jsxs(Cr,{children:[t.jsx(Sr,{children:"Cancel Workflow Run?"}),t.jsx(Ir,{children:"This will stop the workflow execution immediately, and no further steps will be executed. Partial workflow execution may occur. Are you sure you want to cancel the run?"})]}),t.jsxs(Er,{children:[t.jsx(Ar,{children:"Keep Running"}),t.jsx(Tr,{onClick:lt,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Cancel Run"})]})]})}),t.jsx(kr,{open:x,onOpenChange:m,children:t.jsxs(Nr,{children:[t.jsxs(Cr,{children:[t.jsx(Sr,{children:"Replay Run?"}),t.jsx(Ir,{children:"This can potentially re-run code that is meant to only execute once. Are you sure you want to replay the workflow run?"})]}),t.jsxs(Er,{children:[t.jsx(Ar,{children:"Cancel"}),t.jsx(Tr,{onClick:dt,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(qi,{children:t.jsxs(Gi,{children:[t.jsx(Rr,{children:t.jsx(Zi,{asChild:!0,children:t.jsx(Ps,{to:"/",children:"Runs"})})}),t.jsx(Xi,{}),t.jsx(Rr,{children:t.jsx(Yi,{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:Ie||t.jsx(Ae,{className:"w-[260px] h-[28px]"})})}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx(al,{hasError:!1,errorMessage:""}),t.jsx(nn,{env:f,runId:e,runStatus:b.status,events:A,eventsLoading:I,loading:I,onRerunClick:ct,onCancelClick:it,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"}),b.status?t.jsx(on,{status:b.status,context:b}):t.jsx(Ae,{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:b.runId?b.startedAt?(()=>{const U=(b.completedAt?new Date(b.completedAt).getTime():Date.now())-new Date(b.startedAt).getTime(),te=Math.floor(U/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),Ge=ne%60;return Ge>0?`${ae}h ${Ge}m`:`${ae}h`})():"-":t.jsx(Ae,{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"}),b.runId?t.jsx(an,{text:b.runId,children:t.jsx("div",{className:"text-xs mt-0.5 font-mono",children:b.runId})}):t.jsx(Ae,{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"}),b.createdAt?t.jsx("div",{className:"text-xs",children:t.jsx(ut,{date:b.createdAt})}):t.jsx(Ae,{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:b.runId?b.startedAt?t.jsx(ut,{date:b.startedAt}):"-":t.jsx(Ae,{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:b.runId?b.completedAt?t.jsx(ut,{date:b.completedAt}):"-":t.jsx(Ae,{className:"w-[110px] h-[20px]"})})]}),b.expiredAt!=null&&t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs(Vr,{children:[t.jsx(zr,{asChild:!0,children:t.jsxs("div",{className:"text-xs text-muted-foreground cursor-help flex items-center gap-1",children:["Expired",t.jsx(Hn,{className:"w-3 h-3"})]})}),t.jsx(Ur,{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(ut,{date:b.expiredAt})})]})]})]})]}),t.jsx("div",{className:"mt-4 flex-1 flex flex-col min-h-0",children:t.jsxs(ln,{value:C,onValueChange:U=>v(U),className:"flex-1 flex flex-col min-h-0",children:[t.jsxs(cn,{className:"mb-4 flex-none",children:[t.jsxs(Tt,{value:"trace",className:"gap-2",children:[t.jsx(Mt,{className:"h-4 w-4"}),"Trace"]}),!1,t.jsxs(Tt,{value:"events",className:"gap-2",children:[t.jsx(Mt,{className:"h-4 w-4"}),"Events"]}),t.jsxs(Tt,{value:"streams",className:"gap-2",children:[t.jsx(Mt,{className:"h-4 w-4"}),"Streams"]})]}),t.jsx(At,{value:"trace",className:"mt-0 flex-1 min-h-0",children:t.jsx(Qe,{title:"Failed to load trace viewer",children:t.jsx("div",{className:"h-full",children:t.jsx(La,{error:T,events:A,run:b,isLoading:I,spanDetailData:H,spanDetailLoading:$,spanDetailError:Y,onSpanSelect:Oe,onStreamClick:w,onWakeUpSleep:O,onResolveHook:S,onLoadEventData:g,onLoadMoreSpans:z,hasMoreSpans:L,isLoadingMoreSpans:R,encryptionKey:M??void 0,onDecrypt:fe,isDecrypting:se})})})}),t.jsx(At,{value:"events",className:"mt-0 flex-1 min-h-0",children:t.jsx(Qe,{title:"Failed to load events list",children:t.jsx("div",{className:"h-full",children:t.jsx(xo,{events:X,run:b,onLoadEventData:k,hasMoreEvents:N,isLoadingMoreEvents:D,onLoadMoreEvents:B,encryptionKey:M??void 0,isLoading:J,sortOrder:W,onSortOrderChange:G,onDecrypt:fe,isDecrypting:se})})})}),t.jsx(At,{value:"streams",className:"mt-0 flex-1 min-h-0",children:t.jsx(Qe,{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 (",ve.length,")"]}),t.jsx("div",{className:"overflow-auto max-h-[calc(100vh-400px)]",children:Ne?t.jsx("div",{className:"p-4 flex items-center justify-center",children:t.jsx(Pn,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):Ke?t.jsx("div",{className:"p-4 text-xs text-destructive",children:Ke.message}):ve.length===0?t.jsx("div",{className:"p-4 text-xs",style:{color:"var(--ds-gray-600)"},children:"No streams found for this run"}):ve.map(U=>t.jsx("button",{type:"button",onClick:()=>F(U),className:"w-full text-left px-3 py-2 text-xs font-mono truncate hover:bg-accent transition-colors",style:{backgroundColor:h===U?"var(--ds-gray-200)":"transparent",color:"var(--ds-gray-1000)"},title:U,children:U},U))})]}),t.jsx("div",{className:"flex-1 min-w-0",children:h?xe!=null&&xe.includes("encrypted")&&!M?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($r,{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(Yt,{onClick:fe,loading:se})]}):t.jsx(Fn,{streamId:h,chunks:ot,isLive:at,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:ve.length>0?"Select a stream to view its data":"No streams available"})})})]})})}),!1]})})]})]})}const fl=Fs(function(){const r=Os(),[s]=Dr(),n=r.runId,o=s.get("stepId"),i=s.get("eventId"),l=s.get("hookId"),c=o||i||l||void 0;return t.jsx(Qe,{title:"Failed to load run details",children:t.jsx(il,{runId:n,selectedId:c})})});export{fl as default};
|