awaitly-visualizer 24.0.0 → 26.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/devtools.cjs +6 -6
  2. package/dist/devtools.cjs.map +1 -1
  3. package/dist/devtools.d.cts +3 -4
  4. package/dist/devtools.d.ts +3 -4
  5. package/dist/devtools.js +4 -4
  6. package/dist/devtools.js.map +1 -1
  7. package/dist/index.browser.cjs +14 -14
  8. package/dist/index.browser.cjs.map +1 -1
  9. package/dist/index.browser.d.cts +4 -5
  10. package/dist/index.browser.d.ts +4 -5
  11. package/dist/index.browser.js +14 -14
  12. package/dist/index.browser.js.map +1 -1
  13. package/dist/index.cjs +24 -24
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +25 -6
  16. package/dist/index.d.ts +25 -6
  17. package/dist/index.js +24 -24
  18. package/dist/index.js.map +1 -1
  19. package/dist/kroki/fetch.cjs +2 -2
  20. package/dist/kroki/fetch.cjs.map +1 -1
  21. package/dist/kroki/fetch.d.cts +1 -2
  22. package/dist/kroki/fetch.d.ts +1 -2
  23. package/dist/kroki/fetch.js +2 -2
  24. package/dist/kroki/fetch.js.map +1 -1
  25. package/dist/notifiers/discord.cjs +2 -2
  26. package/dist/notifiers/discord.cjs.map +1 -1
  27. package/dist/notifiers/discord.d.cts +2 -3
  28. package/dist/notifiers/discord.d.ts +2 -3
  29. package/dist/notifiers/discord.js +2 -2
  30. package/dist/notifiers/discord.js.map +1 -1
  31. package/dist/notifiers/slack.cjs +12 -12
  32. package/dist/notifiers/slack.cjs.map +1 -1
  33. package/dist/notifiers/slack.d.cts +2 -3
  34. package/dist/notifiers/slack.d.ts +2 -3
  35. package/dist/notifiers/slack.js +13 -13
  36. package/dist/notifiers/slack.js.map +1 -1
  37. package/dist/notifiers/webhook.cjs +2 -2
  38. package/dist/notifiers/webhook.cjs.map +1 -1
  39. package/dist/notifiers/webhook.d.cts +2 -3
  40. package/dist/notifiers/webhook.d.ts +2 -3
  41. package/dist/notifiers/webhook.js +2 -2
  42. package/dist/notifiers/webhook.js.map +1 -1
  43. package/dist/{performance-analyzer-ffmMicjZ.d.ts → performance-analyzer-BCzSirud.d.ts} +1 -1
  44. package/dist/{performance-analyzer-C9WFkUSa.d.cts → performance-analyzer-dTsqap8v.d.cts} +1 -1
  45. package/dist/{types-BmktN16n.d.cts → types-Cxa5QZ0j.d.cts} +1 -1
  46. package/dist/{types-Bmb5LpD-.d.ts → types-J_mgQ3lz.d.ts} +1 -1
  47. package/dist/{url-CxqaR2K3.d.cts → url-DD8-D8H4.d.cts} +4 -4
  48. package/dist/{url-CxqaR2K3.d.ts → url-DD8-D8H4.d.ts} +4 -4
  49. package/package.json +4 -4
@@ -1,3 +1,3 @@
1
- "use strict";var De=Object.create;var B=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var ve=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty;var We=(e,r)=>{for(var n in r)B(e,n,{get:r[n],enumerable:!0})},Y=(e,r,n,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let u of Oe(r))!_e.call(e,u)&&u!==n&&B(e,u,{get:()=>r[u],enumerable:!(c=Te(r,u))||c.enumerable});return e};var Ce=(e,r,n)=>(n=e!=null?De(ve(e)):{},Y(r||!e||!e.__esModule?B(n,"default",{value:e,enumerable:!0}):n,e)),Pe=e=>Y(B({},"__esModule",{value:!0}),e);var bt={};We(bt,{createDiscordNotifier:()=>wt});module.exports=Pe(bt);var q=require("awaitly");function Z(e){function r(n){let c=0;for(let u of n)if(u.type==="step")c++;else if(u.type==="decision"&&u.branches)for(let i of u.branches)i.taken&&(c+=r(i.children));else"children"in u&&u.children&&(c+=r(u.children));return c}return r(e.root.children)}var oe=require("awaitly");function X(e){return e.type==="step"}function Q(e){return e.type==="parallel"}function ee(e){return e.type==="race"}function te(e){return e.type==="decision"}function re(e){return e.type==="stream"}function _(e){if(e<1e3)return`${Math.round(e)}ms`;if(e<6e4)return`${(e/1e3).toFixed(1).replace(/\.0$/,"")}s`;let r=Math.floor(e/6e4),n=Math.round(e%6e4/1e3);return n>=60&&(r+=1,n=0),n===0?`${r}m`:`${r}m ${n}s`}function H(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}var Le="\x1B[2m",Ue="\x1B[31m",Ae="\x1B[32m",Fe="\x1B[33m",Be="\x1B[34m",ne="\x1B[90m",He="\x1B[37m";var W={pending:He,running:Fe,success:Ae,error:Ue,aborted:ne,cached:Be,skipped:Le+ne};var G=require("awaitly");function se(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function Ke(){return[" classDef pending fill:#f3f4f6,stroke:#9ca3af,stroke-width:2px,color:#374151"," classDef running fill:#fef3c7,stroke:#f59e0b,stroke-width:3px,color:#92400e"," classDef success fill:#d1fae5,stroke:#10b981,stroke-width:3px,color:#065f46"," classDef error fill:#fee2e2,stroke:#ef4444,stroke-width:3px,color:#991b1b"," classDef aborted fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#4b5563,stroke-dasharray: 5 5"," classDef cached fill:#dbeafe,stroke:#3b82f6,stroke-width:3px,color:#1e40af"," classDef skipped fill:#f9fafb,stroke:#d1d5db,stroke-width:2px,color:#6b7280,stroke-dasharray: 5 5"," classDef stream fill:#ede9fe,stroke:#8b5cf6,stroke-width:3px,color:#5b21b6"," classDef streamActive fill:#ddd6fe,stroke:#7c3aed,stroke-width:3px,color:#4c1d95"," classDef streamError fill:#fce7f3,stroke:#db2777,stroke-width:3px,color:#9d174d"]}function ze(){return[" classDef heat_cold fill:#dbeafe,stroke:#3b82f6,stroke-width:2px,color:#1e40af"," classDef heat_cool fill:#ccfbf1,stroke:#14b8a6,stroke-width:2px,color:#0f766e"," classDef heat_neutral fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#374151"," classDef heat_warm fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#92400e"," classDef heat_hot fill:#fed7aa,stroke:#f97316,stroke-width:3px,color:#c2410c"," classDef heat_critical fill:#fecaca,stroke:#ef4444,stroke-width:3px,color:#b91c1c"]}function Ge(e){return`heat_${e}`}function je(){return[" classDef hook_success fill:#e0f2fe,stroke:#0284c7,stroke-width:2px,color:#0c4a6e"," classDef hook_error fill:#fef2f2,stroke:#dc2626,stroke-width:2px,color:#7f1d1d"]}function Ve(e){try{return(0,G.ok)(JSON.stringify(e,(n,c)=>{if(typeof c!="bigint")return c;let u=Number(c);return Number.isSafeInteger(u)?u:c.toString()}))}catch{return(0,G.err)("STRINGIFY_ERROR")}}function ie(e){let r=Ve(e);return r.ok?r.value:"[unserializable]"}function qe(e,r,n){let c;if(e.shouldRun){let u="hook_shouldRun",i=e.shouldRun.state==="success"?"hook_success":"hook_error",m=e.shouldRun.state==="success"?"\u2699":"\u26A0",f=n.showTimings&&e.shouldRun.durationMs!==void 0?` ${_(e.shouldRun.durationMs)}`:"",g=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";r.push(` ${u}[["${m} shouldRun${g}${f}"]]:::${i}`),c=u}if(e.onBeforeStart){let u="hook_beforeStart",i=e.onBeforeStart.state==="success"?"hook_success":"hook_error",m=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",f=n.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${_(e.onBeforeStart.durationMs)}`:"",g=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";r.push(` ${u}[["${m} onBeforeStart${g}${f}"]]:::${i}`),c&&r.push(` ${c} --> ${u}`),c=u}return{lastHookId:c}}var ae=0,K=new Set,z=new Set;function C(e="node"){return`${e}_${++ae}`}function Je(){ae=0,K.clear(),z.clear()}function D(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function ce(e){return D(e).replace(/[{}[\]()]/g,"")}function A(){return{name:"mermaid",supportsLive:!1,render(e,r){Je();let n=[],c=r;n.push("flowchart TD");let u;e.hooks&&(u=qe(e.hooks,n,r).lastHookId);let i="start";n.push(` ${i}(("\u25B6 Start"))`),u&&n.push(` ${u} --> ${i}`);let m=i;for(let g of e.root.children){let s=j(g,r,n,c,e.hooks);n.push(` ${m} --> ${s.entryId}`),m=s.exitId}if(["success","error","aborted"].includes(e.root.state)){let g="finish",s=e.root.state==="success"?"\u2713":e.root.state==="error"?"\u2717":"\u2298",d=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",w=`(("${s} ${d}"))`,l=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";n.push(` ${g}${w}${l}`),n.push(` ${m} --> ${g}`)}return n.push(""),n.push(...Ke()),c.showHeatmap&&n.push(...ze()),e.hooks&&n.push(...je()),n.join(`
2
- `)}}}function j(e,r,n,c,u){if(X(e))return Ye(e,r,n,c,u);if(Q(e))return Ze(e,r,n,c,u);if(ee(e))return Xe(e,r,n,c,u);if(te(e))return Qe(e,r,n,c,u);if(re(e))return et(e,r,n);let i=C("unknown");return n.push(` ${i}["Unknown Node"]`),{entryId:i,exitId:i}}function Ye(e,r,n,c,u){let i=r,m=i.showRetryEdges??!0,f=i.showErrorEdges??!0,g=i.showTimeoutEdges??!0,s=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:C("step");if(z.has(s)){let b=2;for(;z.has(`${s}_${b}`);)b++;s=`${s}_${b}`}z.add(s);let d=e.name??e.key??"Step",w=r.showKeys&&e.key&&e.name?`${d} [${e.key}]`:d,l=D(w),p=r.showTimings&&e.durationMs!==void 0?` ${_(e.durationMs)}`:"",h="";switch(e.state){case"success":h="\u2713 ";break;case"error":h="\u2717 ";break;case"cached":h="\u{1F4BE} ";break;case"running":h="\u23F3 ";break;case"skipped":h="\u2298 ";break}let y="";if(e.input!==void 0){let b=typeof e.input=="string"?D(e.input):D(ie(e.input).slice(0,20));y+=`\\nin: ${b}`}if(e.output!==void 0&&e.state==="success"){let b=typeof e.output=="string"?D(e.output):D(ie(e.output).slice(0,20));y+=`\\nout: ${b}`}let x="",T=e.key??e.id;if(u&&T&&u.onAfterStep.has(T)){let b=u.onAfterStep.get(T),$=b.state==="success"?"\u2699":"\u26A0",R=r.showTimings&&b.durationMs!==void 0?` ${_(b.durationMs)}`:"";x=`\\n${$} hook${R}`}let I=(h+l+y+x+p).trim(),k,E=c?.showHeatmap&&c.heatmapData?c.heatmapData.heat.get(e.key??"")??c.heatmapData.heat.get(e.name??"")??c.heatmapData.heat.get(e.id):void 0;if(E!==void 0){let b=se(E);k=Ge(b)}else k=e.state;let M;switch(e.state){case"error":M=`{{"${I}"}}`;break;case"cached":M=`[("${I}")]`;break;case"skipped":M=`["${I}"]`;break;default:M=`["${I}"]`}if(n.push(` ${s}${M}:::${k}`),m&&e.retryCount!==void 0&&e.retryCount>0){let b=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;n.push(` ${s} -.->|"${b}"| ${s}`)}if(f&&e.state==="error"&&e.error!==void 0){let b=`ERR_${s}`,$=D(String(e.error)).slice(0,30);n.push(` ${b}{{"${$}"}}`),n.push(` ${s} -->|error| ${b}`),n.push(` style ${b} fill:#fee2e2,stroke:#dc2626`)}if(g&&e.timedOut){let b=`TO_${s}`,$=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";n.push(` ${b}{{"\u23F1 Timeout ${$}"}}`),n.push(` ${s} -.->|timeout| ${b}`),n.push(` style ${b} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:s,exitId:s}}function Ze(e,r,n,c,u){let i=C("parallel"),m=`${i}_fork`,f=`${i}_join`,g=ce(e.name??"Parallel"),s=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let l=i,p=D(`${g}${s}`),h="operations not individually tracked",y=r.showTimings&&e.durationMs!==void 0?` ${_(e.durationMs)}`:"";return n.push(` ${l}["${p}${y}\\n${h}"]:::${e.state}`),{entryId:l,exitId:l}}n.push(` subgraph ${i}["${g}${s}"]`),n.push(" direction TB"),n.push(` ${m}{"\u26A1 Fork"}`);let d=[];for(let l of e.children){let p=j(l,r,n,c,u);n.push(` ${m} --> ${p.entryId}`),d.push(p.exitId)}n.push(` ${f}{"\u2713 Join"}`);for(let l of d)n.push(` ${l} --> ${f}`);n.push(" end");let w=e.state;return n.push(` class ${i} ${w}`),{entryId:m,exitId:f}}function Xe(e,r,n,c,u){let i=C("race"),m=`${i}_start`,f=`${i}_end`,g=ce(e.name??"Race");if(e.children.length===0){let l=i,p=D(g),h="operations not individually tracked",y=r.showTimings&&e.durationMs!==void 0?` ${_(e.durationMs)}`:"";return n.push(` ${l}["\u26A1 ${p}${y}\\n${h}"]:::${e.state}`),{entryId:l,exitId:l}}n.push(` subgraph ${i}["\u26A1 ${g}"]`),n.push(" direction TB"),n.push(` ${m}(("\u{1F3C1} Start"))`);let s=[],d;for(let l of e.children){let p=j(l,r,n,c,u),h=e.winnerId===l.id;n.push(` ${m} --> ${p.entryId}`),h&&(d=p.exitId),s.push({exitId:p.exitId,isWinner:h})}n.push(` ${f}(("\u2713 First"))`);for(let{exitId:l,isWinner:p}of s)p&&d?n.push(` ${l} ==>|\u{1F3C6} Winner| ${f}`):e.winnerId?n.push(` ${l} -. cancelled .-> ${f}`):n.push(` ${l} --> ${f}`);n.push(" end");let w=e.state;return n.push(` class ${i} ${w}`),{entryId:m,exitId:f}}function Qe(e,r,n,c,u){let i=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:C("decision");if(K.has(i)){let l=2;for(;K.has(`${i}_${l}`);)l++;i=`${i}_${l}`}K.add(i);let m=D(e.condition??"condition"),f=e.decisionValue!==void 0?` = ${D(String(e.decisionValue)).slice(0,30)}`:"",g=`${m}${f}`.trim();n.push(` ${i}{"${g}"}`);let s=[],d,w=new Set;for(let l of e.branches){let p=`${i}_${l.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(w.has(p)){let I=2;for(;w.has(`${p}_${I}`);)I++;p=`${p}_${I}`}w.add(p);let h=D(l.label),y=l.taken?`${h} \u2713`:`${h} skipped`,x=l.taken?":::success":":::skipped";n.push(` ${p}["${y}"]${x}`);let T=l.condition?`|${D(l.condition).replace(/\|/g,"")}|`:"";if(n.push(` ${i} -->${T} ${p}`),l.children.length>0){let I=p;for(let k of l.children){let E=j(k,r,n,c,u);n.push(` ${I} --> ${E.entryId}`),I=E.exitId}s.push(I),l.taken&&(d=I)}else s.push(p),l.taken&&(d=p)}return d?{entryId:i,exitId:d}:{entryId:i,exitId:i}}function et(e,r,n){let c=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${C("")}`,u=`W:${e.writeCount} R:${e.readCount}`,i="";switch(e.streamState){case"active":i="\u27F3 ";break;case"closed":i="\u2713 ";break;case"error":i="\u2717 ";break}let m=r.showTimings&&e.durationMs!==void 0?` ${_(e.durationMs)}`:"",f=e.backpressureOccurred?"\\nbackpressure":"",g=`${i}stream:${D(e.namespace)}\\n${u}${f}${m}`,s;return e.streamState==="error"?s="streamError":e.streamState==="active"?s="streamActive":s="stream",n.push(` ${c}{{"${g}"}}:::${s}`),{entryId:c,exitId:c}}var de=Ce(require("pako"),1),tt=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function rt(e){let r;if(tt)r=globalThis.Buffer.from(e).toString("base64");else{let n="";for(let c=0;c<e.length;c++)n+=String.fromCharCode(e[c]);r=btoa(n)}return r.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function V(e){let n=new TextEncoder().encode(e),c=de.default.deflate(n);return rt(c)}var nt="https://kroki.io";function ot(e,r,n,c={}){let u=c.baseUrl??nt,i=V(n);return`${u}/${e}/${r}/${i}`}function st(e,r="svg",n={}){let c=A(),u={showTimings:!0,showKeys:!1,terminalWidth:80,colors:W},i=c.render(e,u);return ot("mermaid",r,i,n)}function ue(e,r={}){return st(e,"svg",r)}var it="https://mermaid.ink";function at(e){return`pako:${V(e)}`}function ct(e){if("provider"in e){let r=e;return{theme:r.mermaidTheme,bgColor:r.background,scale:r.scale,fit:r.fit,width:r.width,height:r.height,paper:r.paper,imageType:"png"}}return e}function dt(e,r){let n=[];return r.bgColor&&n.push(`bgColor=${encodeURIComponent(r.bgColor)}`),r.theme&&n.push(`theme=${r.theme}`),r.width!==void 0&&n.push(`width=${r.width}`),r.height!==void 0&&n.push(`height=${r.height}`),r.scale!==void 0&&(r.width!==void 0||r.height!==void 0)&&n.push(`scale=${r.scale}`),e==="img"&&r.imageType&&r.imageType!=="jpeg"&&n.push(`type=${r.imageType}`),e==="pdf"&&(r.fit&&n.push("fit"),r.paper&&!r.fit&&n.push(`paper=${r.paper}`),r.landscape&&!r.fit&&n.push("landscape")),n.length>0?`?${n.join("&")}`:""}function ut(e,r,n={}){let c=ct(n),u=c.baseUrl??it,i=at(r),m=dt(e,c);return`${u}/${e}/${i}${m}`}function lt(e,r="svg",n={}){let c=A(),u={showTimings:!0,showKeys:!1,terminalWidth:80,colors:W},i=c.render(e,u);return ut(r,i,n)}function le(e,r={}){return lt(e,"svg",r)}function pe(e){return{getDiagramUrl(r){if(e.provider==="mermaid-ink"){let{provider:n,...c}=e;return le(r,c)}return ue(r,{baseUrl:e.baseUrl})},countSteps(r){return Z(r)},formatDuration(r){return r.root.endTs!==void 0&&r.root.startTs!==void 0?`${r.root.endTs-r.root.startTs}ms`:r.root.durationMs!==void 0?`${r.root.durationMs}ms`:"In progress"}}}var P=require("awaitly");function pt(e){for(let r of e)if((r.type==="parallel"||r.type==="race"||r.type==="sequence")&&!r.id.startsWith("detected_")||r.type==="decision")return!0;return!1}function fe(e,r={}){if(pt(e))return e;let{minOverlapMs:n=0,maxGapMs:c=5}=r,u=[],i=[];for(let s=0;s<e.length;s++){let d=e[s];d.type==="step"&&d.startTs!==void 0?u.push({node:d,startTs:d.startTs,endTs:d.endTs??d.startTs+(d.durationMs??0),originalIndex:s}):i.push({node:d,originalIndex:s})}if(u.length<=1)return e;u.sort((s,d)=>s.startTs-d.startTs);let m=[],f=[u[0]];for(let s=1;s<u.length;s++){let d=u[s],w=Math.min(...f.map(x=>x.startTs)),l=Math.max(...f.map(x=>x.endTs)),p=d.startTs<=w+c,h=d.startTs<l;if(!p&&!h){m.push(f),f=[d];continue}let y=h?Math.min(d.endTs,l)-d.startTs:0;p||y>=n?f.push(d):(m.push(f),f=[d])}m.push(f);let g=[];for(let s of m){let d=Math.min(...s.map(w=>w.originalIndex));if(s.length===1)g.push({node:s[0].node,position:d});else{let w=s.map(y=>y.node),l=Math.min(...s.map(y=>y.startTs)),p=Math.max(...s.map(y=>y.endTs)),h={type:"parallel",id:`detected_parallel_${l}`,name:`${w.length} parallel steps`,state:ft(w),mode:"all",children:w,startTs:l,endTs:p,durationMs:p-l};g.push({node:h,position:d})}}for(let{node:s,originalIndex:d}of i)g.push({node:s,position:d});return g.sort((s,d)=>s.position-d.position),g.map(s=>s.node)}function ft(e){return e.some(i=>i.state==="error")?"error":e.some(i=>i.state==="running")?"running":e.some(i=>i.state==="pending")?"pending":(e.every(i=>i.state==="success"||i.state==="cached"),"success")}function me(e={}){let{detectParallel:r=!0,parallelDetection:n,enableSnapshots:c=!1,maxSnapshots:u=1e3}=e,i=c,m=H(),f,g,s,d="pending",w,l,p=new Map,h=[],y=[],x=new Map,T=[],I=Date.now(),k=I,E={onAfterStep:new Map},M,b=[],$=0;function R(t){return t.stepId??t.stepKey??t.name??H()}function O(t){if(h.length>0){h[h.length-1].children.push(t),k=Date.now();return}if(y.length>0){let a=y[y.length-1];for(let o of a.branches.values())if(o.taken){o.children.push(t),k=Date.now();return}a.pendingChildren.push(t),k=Date.now();return}T.push(t),k=Date.now()}function we(t){if(!i)return;let a=J(),o=new Map;for(let[S,v]of p)o.set(S,{id:v.id,name:v.name,key:v.key,startTs:v.startTs,retryCount:v.retryCount,timedOut:v.timedOut,timeoutMs:v.timeoutMs});let N={id:`snapshot_${$}`,eventIndex:$,event:structuredClone(t),ir:structuredClone(a),timestamp:Date.now(),activeSteps:o};b.push(N),b.length>u&&b.shift(),$++}function be(t){switch(t.type){case"workflow_start":{T=[],s=void 0,l=void 0,w=void 0,p.clear(),h.length=0,y.length=0,x.clear(),f=t.workflowId,g=t.ts,d="running",I=Date.now(),k=I,M!==void 0&&M!==t.workflowId&&(E.shouldRun=void 0,E.onBeforeStart=void 0),M=t.workflowId,E.onAfterStep=new Map;break}case"workflow_success":d="success",s=t.ts,l=t.durationMs,k=Date.now();break;case"workflow_error":d="error",s=t.ts,w=t.error,l=t.durationMs,k=Date.now();break;case"workflow_cancelled":d="aborted",s=t.ts,l=t.durationMs,k=Date.now();break;case"step_start":{let a=R(t);p.set(a,{id:a,name:t.name,key:t.stepKey,startTs:t.ts,retryCount:0,timedOut:!1,metadata:t.metadata}),k=Date.now();break}case"step_success":{let a=R(t),o=p.get(a);if(o){let N={type:"step",id:o.id,name:o.name,key:o.key,state:"success",startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,...o.retryCount>0&&{retryCount:o.retryCount},...o.timedOut&&{timedOut:!0,timeoutMs:o.timeoutMs},...o.metadata&&{metadata:o.metadata}};O(N),p.delete(a)}break}case"step_error":{let a=R(t),o=p.get(a);if(o){let N={type:"step",id:o.id,name:o.name,key:o.key,state:"error",startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,error:t.error,...o.retryCount>0&&{retryCount:o.retryCount},...o.timedOut&&{timedOut:!0,timeoutMs:o.timeoutMs},...o.metadata&&{metadata:o.metadata},...t.diagnostics&&{errorDiagnostics:t.diagnostics}};O(N),p.delete(a)}break}case"step_aborted":{let a=R(t),o=p.get(a);if(o){let N={type:"step",id:o.id,name:o.name,key:o.key,state:"aborted",startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,...o.retryCount>0&&{retryCount:o.retryCount},...o.timedOut&&{timedOut:!0,timeoutMs:o.timeoutMs},...o.metadata&&{metadata:o.metadata}};O(N),p.delete(a)}break}case"step_cache_hit":{let o={type:"step",id:R(t),name:t.name,key:t.stepKey,state:"cached",startTs:t.ts,endTs:t.ts,durationMs:0};O(o);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let a=R(t),o=p.get(a);o&&(o.timedOut=!0,o.timeoutMs=t.timeoutMs),k=Date.now();break}case"step_retry":{let a=R(t),o=p.get(a);o&&(o.retryCount=(t.attempt??1)-1),k=Date.now();break}case"step_retries_exhausted":k=Date.now();break;case"step_skipped":{let o={type:"step",id:R(t),name:t.name,key:t.stepKey,state:"skipped",startTs:t.ts,endTs:t.ts,durationMs:0,...t.metadata&&{metadata:t.metadata}};O(o);break}case"hook_should_run":{let a={type:"shouldRun",state:"success",ts:t.ts,durationMs:t.durationMs,context:{result:t.result,skipped:t.skipped}};E.shouldRun=a,M=t.workflowId,k=Date.now();break}case"hook_should_run_error":{let a={type:"shouldRun",state:"error",ts:t.ts,durationMs:t.durationMs,error:t.error};E.shouldRun=a,M=t.workflowId,k=Date.now();break}case"hook_before_start":{let a={type:"onBeforeStart",state:"success",ts:t.ts,durationMs:t.durationMs,context:{result:t.result,skipped:t.skipped}};E.onBeforeStart=a,M=t.workflowId,k=Date.now();break}case"hook_before_start_error":{let a={type:"onBeforeStart",state:"error",ts:t.ts,durationMs:t.durationMs,error:t.error};E.onBeforeStart=a,M=t.workflowId,k=Date.now();break}case"hook_after_step":{let a={type:"onAfterStep",state:"success",ts:t.ts,durationMs:t.durationMs,context:{stepKey:t.stepKey}};E.onAfterStep.set(t.stepKey,a),k=Date.now();break}case"hook_after_step_error":{let a={type:"onAfterStep",state:"error",ts:t.ts,durationMs:t.durationMs,error:t.error,context:{stepKey:t.stepKey}};E.onAfterStep.set(t.stepKey,a),k=Date.now();break}case"stream_created":{let a=`${t.workflowId}:${t.namespace}`;x.set(a,{id:H(),namespace:t.namespace,startTs:t.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),k=Date.now();break}case"stream_write":{let a=`${t.workflowId}:${t.namespace}`,o=x.get(a);o&&(o.writeCount++,o.finalPosition=Math.max(o.finalPosition,t.position)),k=Date.now();break}case"stream_read":{let a=`${t.workflowId}:${t.namespace}`,o=x.get(a);o&&o.readCount++,k=Date.now();break}case"stream_close":{let a=`${t.workflowId}:${t.namespace}`,o=x.get(a);if(o){o.streamState="closed",o.finalPosition=t.finalPosition;let N={type:"stream",id:o.id,namespace:o.namespace,state:"success",startTs:o.startTs,endTs:t.ts,durationMs:t.ts-o.startTs,writeCount:o.writeCount,readCount:o.readCount,finalPosition:t.finalPosition,streamState:"closed",backpressureOccurred:o.backpressureOccurred};O(N),x.delete(a)}k=Date.now();break}case"stream_error":{let a=`${t.workflowId}:${t.namespace}`,o=x.get(a);if(o){o.streamState="error";let N={type:"stream",id:o.id,namespace:o.namespace,state:"error",error:t.error,startTs:o.startTs,endTs:t.ts,durationMs:t.ts-o.startTs,writeCount:o.writeCount,readCount:o.readCount,finalPosition:t.position,streamState:"error",backpressureOccurred:o.backpressureOccurred};O(N),x.delete(a)}k=Date.now();break}case"stream_backpressure":{let a=`${t.workflowId}:${t.namespace}`,o=x.get(a);o&&(o.backpressureOccurred=!0),k=Date.now();break}}we(t)}function ye(t){if(t.type==="scope_start")h.push({id:t.scopeId,name:t.name,type:t.scopeType,startTs:t.ts,children:[]}),k=Date.now();else if(t.type==="scope_end"){let a=h.findIndex(S=>S.id===t.scopeId);if(a===-1)return;for(;h.length>a+1;){let S=h.pop(),v=S.type==="race"?{type:"race",id:S.id,name:S.name,state:U(S.children),startTs:S.startTs,endTs:t.ts,children:S.children}:{type:"parallel",id:S.id,name:S.name,state:U(S.children),startTs:S.startTs,endTs:t.ts,children:S.children,mode:S.type==="allSettled"?"allSettled":"all"};h[h.length-1].children.push(v)}let[o]=h.splice(a,1),N=o.type==="race"?{type:"race",id:o.id,name:o.name,state:U(o.children),startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,children:o.children,winnerId:t.winnerId}:{type:"parallel",id:o.id,name:o.name,state:U(o.children),startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,children:o.children,mode:o.type==="allSettled"?"allSettled":"all"};O(N)}}function Se(t){if(t.type==="decision_start")y.push({id:t.decisionId,name:t.name,condition:t.condition,decisionValue:t.decisionValue,startTs:t.ts,branches:new Map,pendingChildren:[]}),k=Date.now();else if(t.type==="decision_branch"){let a=y.find(o=>o.id===t.decisionId);if(a){let o=t.branchLabel,N=a.branches.get(o);if(N)N.taken=t.taken,t.taken&&a.pendingChildren.length>0&&(N.children.unshift(...a.pendingChildren),a.pendingChildren=[]);else{let S=t.taken?[...a.pendingChildren]:[];t.taken&&(a.pendingChildren=[]),a.branches.set(o,{label:t.branchLabel,condition:t.condition,taken:t.taken,children:S})}k=Date.now()}}else if(t.type==="decision_end"){let a=y.findIndex(o=>o.id===t.decisionId);if(a!==-1){let[o]=y.splice(a,1),N=y.splice(a),S=Array.from(o.branches.values());S.length===0&&o.pendingChildren.length>0&&(S=[{label:"default",taken:!0,children:[...o.pendingChildren]}]);let v=S.find(F=>F.taken)?.label,Me={type:"decision",id:o.id,name:o.name,state:U(S.flatMap(F=>F.taken?F.children:[])),startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,condition:o.condition,decisionValue:o.decisionValue,branchTaken:t.branchTaken??v,branches:S};O(Me),y.push(...N),k=Date.now()}}}function U(t){return t.length===0?"success":t.some(S=>S.state==="error")?"error":t.every(S=>S.state==="success"||S.state==="cached")?"success":t.some(S=>S.state==="running")?"running":"pending"}function $e(){let t=[...T];for(let[,a]of p)t.push({type:"step",id:a.id,name:a.name,key:a.key,state:"running",startTs:a.startTs,...a.retryCount>0&&{retryCount:a.retryCount},...a.timedOut&&{timedOut:!0,timeoutMs:a.timeoutMs}});for(let[,a]of x)t.push({type:"stream",id:a.id,namespace:a.namespace,state:"running",startTs:a.startTs,writeCount:a.writeCount,readCount:a.readCount,finalPosition:a.finalPosition,streamState:a.streamState,backpressureOccurred:a.backpressureOccurred});return t}function J(){let t=$e();r&&(t=fe(t,n));let a={type:"workflow",id:f??m,workflowId:f??m,state:d,startTs:g,endTs:s,durationMs:l,children:t,error:w},o=E.shouldRun!==void 0||E.onBeforeStart!==void 0||E.onAfterStep.size>0;return{root:a,metadata:{createdAt:I,lastUpdatedAt:k},...o&&{hooks:E}}}function xe(){f=void 0,g=void 0,s=void 0,d="pending",w=void 0,l=void 0,p.clear(),h.length=0,y.length=0,x.clear(),T=[],I=Date.now(),k=I,E={onAfterStep:new Map},M=void 0,b.length=0,$=0}function Re(){return[...b]}function Ie(t){return b[t]}function Ee(t){return b[t]?.ir}function Ne(){b.length=0,$=0}return{handleEvent:be,handleScopeEvent:ye,handleDecisionEvent:Se,getIR:J,reset:xe,getSnapshots:Re,getSnapshotAt:Ie,getIRAt:Ee,clearSnapshots:Ne,get hasActiveSteps(){return p.size>0},get state(){return d},get snapshotCount(){return b.length},get snapshotsEnabled(){return i},setSnapshotsEnabled(t){i=t}}}var mt=500,gt=5e3;function ge(e,r){let{title:n,debounceMs:c=mt,maxWaitMs:u=gt}=e,i,m=!0,f,g,s,d,w,l,p=(0,P.ok)(void 0),h=me({detectParallel:!0});function y(){s&&(clearTimeout(s),s=void 0),d&&(clearTimeout(d),d=void 0)}async function x(){if(!f||!m)return(0,P.ok)(void 0);let $=f;g=$,f=void 0,y();try{return i?await r.updateExisting(i,$,n):i=await r.postNew($,n),w=Date.now(),p=(0,P.ok)(void 0),p}catch{return p=(0,P.err)("CALLBACK_ERROR"),p}}function T(){s&&clearTimeout(s),s=setTimeout(()=>{x()},c);let $=w??l;if(!d&&$!==void 0){let R=Date.now()-$,O=Math.max(0,u-R);d=setTimeout(()=>{d=void 0,x()},O)}}function I($){if(m){if(l===void 0&&(l=Date.now()),"root"in $)f=$,g=$;else{let R=$;R.type==="scope_start"||R.type==="scope_end"?h.handleScopeEvent(R):R.type==="decision_start"||R.type==="decision_branch"||R.type==="decision_end"?h.handleDecisionEvent(R):h.handleEvent(R),f=h.getIR(),g=f}T()}}async function k($="completed"){if(!m)return;m=!1,y();let R=f??g??h.getIR();await r.finalize(i,R,n,$)}function E(){m&&(m=!1,y(),i&&r.cancel&&r.cancel(i))}function M(){return i}function b(){return m}return{update:I,finalize:k,cancel:E,getSessionId:M,isActive:b}}function ht(e){switch(e.root.state){case"success":return"completed";case"error":return"failed";case"aborted":return"cancelled";default:return"running"}}function he(e,r){let{diagramProvider:n,debounceMs:c=500,maxWaitMs:u=5e3}=e;if(!n)throw new Error(`${r.name}Notifier: diagramProvider is required. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }.`);let i=pe(n);async function m(g,s={}){let d=s.title??"Workflow",w=ht(g);try{let l=r.buildMessage({ir:g,title:d,status:w},i),p=await r.sendNew(l);return(0,q.ok)(p?.toString())}catch{return(0,q.err)("SEND_FAILED")}}function f(g){return ge({...g,debounceMs:g.debounceMs??c,maxWaitMs:g.maxWaitMs??u},{async postNew(s,d){let w=r.buildMessage({ir:s,title:d,status:"running"},i);return(await r.sendNew(w))?.toString()},async updateExisting(s,d,w){let l=r.buildMessage({ir:d,title:w,status:"running"},i);await r.sendUpdate(s,l)},async finalize(s,d,w,l){let p=r.buildMessage({ir:d,title:w,status:l},i);s?await r.sendUpdate(s,p):await r.sendNew(p)},async cancel(s){r.sendCancel&&s&&await r.sendCancel(s)}})}return{notify:m,createLive:f,getType:()=>r.name.toLowerCase()}}var L=require("awaitly"),kt={running:3447003,completed:3066993,failed:15158332,cancelled:9807270};function ke(e){let{webhookUrl:r,username:n,avatarUrl:c,timeout:u=3e4}=e;if(!r.includes("discord.com/api/webhooks/"))throw new Error("Invalid Discord webhook URL");async function i(m,f){let g=new AbortController,s=setTimeout(()=>g.abort(),u);try{let d=f?`${r}/messages/${f}`:`${r}?wait=true`,l=await fetch(d,{method:f?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m),signal:g.signal});if(!l.ok)return(0,L.err)("SEND_FAILED");let p=await l.json();return(0,L.ok)(p.id)}catch(d){return d instanceof Error&&d.name==="AbortError"?(0,L.err)("TIMEOUT"):(0,L.err)("SEND_FAILED")}finally{clearTimeout(s)}}return{name:"Discord",buildMessage({ir:m,title:f,status:g},s){let d={title:f,color:kt[g],image:{url:s.getDiagramUrl(m)},fields:[{name:"Steps",value:String(s.countSteps(m)),inline:!0},{name:"Duration",value:s.formatDuration(m),inline:!0},{name:"Status",value:g.charAt(0).toUpperCase()+g.slice(1),inline:!0}],timestamp:new Date().toISOString()};return{username:n,avatar_url:c,embeds:[d]}},async sendNew(m){let f=await i(m);if(!f.ok)throw new Error(`Discord send failed: ${f.error}`);return f.value},async sendUpdate(m,f){let g=await i(f,m);if(!g.ok)throw new Error(`Discord update failed: ${g.error}`)}}}function wt(e){let{webhookUrl:r,username:n,avatarUrl:c,timeout:u,...i}=e,m=ke({webhookUrl:r,username:n,avatarUrl:c,timeout:u});return he(i,m)}0&&(module.exports={createDiscordNotifier});
1
+ "use strict";var Te=Object.create;var H=Object.defineProperty;var De=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var ve=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty;var We=(e,r)=>{for(var n in r)H(e,n,{get:r[n],enumerable:!0})},Z=(e,r,n,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of Oe(r))!_e.call(e,l)&&l!==n&&H(e,l,{get:()=>r[l],enumerable:!(c=De(r,l))||c.enumerable});return e};var Ce=(e,r,n)=>(n=e!=null?Te(ve(e)):{},Z(r||!e||!e.__esModule?H(n,"default",{value:e,enumerable:!0}):n,e)),Pe=e=>Z(H({},"__esModule",{value:!0}),e);var bt={};We(bt,{createDiscordNotifier:()=>wt});module.exports=Pe(bt);var J=require("awaitly");function X(e){function r(n){let c=0;for(let l of n)if(l.type==="step")c++;else if(l.type==="decision"&&l.branches)for(let a of l.branches)a.taken&&(c+=r(a.children));else"children"in l&&l.children&&(c+=r(l.children));return c}return r(e.root.children)}var se=require("awaitly");function Q(e){return e.type==="step"}function ee(e){return e.type==="parallel"}function te(e){return e.type==="race"}function re(e){return e.type==="decision"}function ne(e){return e.type==="stream"}function _(e){if(e<1e3)return`${Math.round(e)}ms`;if(e<6e4)return`${(e/1e3).toFixed(1).replace(/\.0$/,"")}s`;let r=Math.floor(e/6e4),n=Math.round(e%6e4/1e3);return n>=60&&(r+=1,n=0),n===0?`${r}m`:`${r}m ${n}s`}function K(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}var Le="\x1B[2m",Ue="\x1B[31m",Ae="\x1B[32m",Fe="\x1B[33m",Be="\x1B[34m",oe="\x1B[90m",He="\x1B[37m";var W={pending:He,running:Fe,success:Ae,error:Ue,aborted:oe,cached:Be,skipped:Le+oe};var j=require("awaitly");function ie(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function Ke(){return[" classDef pending fill:#f3f4f6,stroke:#9ca3af,stroke-width:2px,color:#374151"," classDef running fill:#fef3c7,stroke:#f59e0b,stroke-width:3px,color:#92400e"," classDef success fill:#d1fae5,stroke:#10b981,stroke-width:3px,color:#065f46"," classDef error fill:#fee2e2,stroke:#ef4444,stroke-width:3px,color:#991b1b"," classDef aborted fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#4b5563,stroke-dasharray: 5 5"," classDef cached fill:#dbeafe,stroke:#3b82f6,stroke-width:3px,color:#1e40af"," classDef skipped fill:#f9fafb,stroke:#d1d5db,stroke-width:2px,color:#6b7280,stroke-dasharray: 5 5"," classDef stream fill:#ede9fe,stroke:#8b5cf6,stroke-width:3px,color:#5b21b6"," classDef streamActive fill:#ddd6fe,stroke:#7c3aed,stroke-width:3px,color:#4c1d95"," classDef streamError fill:#fce7f3,stroke:#db2777,stroke-width:3px,color:#9d174d"]}function ze(){return[" classDef heat_cold fill:#dbeafe,stroke:#3b82f6,stroke-width:2px,color:#1e40af"," classDef heat_cool fill:#ccfbf1,stroke:#14b8a6,stroke-width:2px,color:#0f766e"," classDef heat_neutral fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#374151"," classDef heat_warm fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#92400e"," classDef heat_hot fill:#fed7aa,stroke:#f97316,stroke-width:3px,color:#c2410c"," classDef heat_critical fill:#fecaca,stroke:#ef4444,stroke-width:3px,color:#b91c1c"]}function Ge(e){return`heat_${e}`}function je(){return[" classDef hook_success fill:#e0f2fe,stroke:#0284c7,stroke-width:2px,color:#0c4a6e"," classDef hook_error fill:#fef2f2,stroke:#dc2626,stroke-width:2px,color:#7f1d1d"]}function Ve(e){try{return(0,j.ok)(JSON.stringify(e,(n,c)=>{if(typeof c!="bigint")return c;let l=Number(c);return Number.isSafeInteger(l)?l:c.toString()}))}catch{return(0,j.err)("STRINGIFY_ERROR")}}function ae(e){let r=Ve(e);return r.ok?r.value:"[unserializable]"}function qe(e,r,n){let c;if(e.shouldRun){let l="hook_shouldRun",a=e.shouldRun.state==="success"?"hook_success":"hook_error",m=e.shouldRun.state==="success"?"\u2699":"\u26A0",f=n.showTimings&&e.shouldRun.durationMs!==void 0?` ${_(e.shouldRun.durationMs)}`:"",g=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";r.push(` ${l}[["${m} shouldRun${g}${f}"]]:::${a}`),c=l}if(e.onBeforeStart){let l="hook_beforeStart",a=e.onBeforeStart.state==="success"?"hook_success":"hook_error",m=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",f=n.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${_(e.onBeforeStart.durationMs)}`:"",g=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";r.push(` ${l}[["${m} onBeforeStart${g}${f}"]]:::${a}`),c&&r.push(` ${c} --> ${l}`),c=l}return{lastHookId:c}}var ce=0,z=new Set,G=new Set;function C(e="node"){return`${e}_${++ce}`}function Je(){ce=0,z.clear(),G.clear()}function T(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function de(e){return T(e).replace(/[{}[\]()]/g,"")}function F(){return{name:"mermaid",supportsLive:!1,render(e,r){Je();let n=[],c=r;n.push("flowchart TD");let l;e.hooks&&(l=qe(e.hooks,n,r).lastHookId);let a="start";n.push(` ${a}(("\u25B6 Start"))`),l&&n.push(` ${l} --> ${a}`);let m=a;for(let g of e.root.children){let i=V(g,r,n,c,e.hooks);n.push(` ${m} --> ${i.entryId}`),m=i.exitId}if(["success","error","aborted"].includes(e.root.state)){let g="finish",i=e.root.state==="success"?"\u2713":e.root.state==="error"?"\u2717":"\u2298",d=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",w=`(("${i} ${d}"))`,u=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";n.push(` ${g}${w}${u}`),n.push(` ${m} --> ${g}`)}return n.push(""),n.push(...Ke()),c.showHeatmap&&n.push(...ze()),e.hooks&&n.push(...je()),n.join(`
2
+ `)}}}function V(e,r,n,c,l){if(Q(e))return Ye(e,r,n,c,l);if(ee(e))return Ze(e,r,n,c,l);if(te(e))return Xe(e,r,n,c,l);if(re(e))return Qe(e,r,n,c,l);if(ne(e))return et(e,r,n);let a=C("unknown");return n.push(` ${a}["Unknown Node"]`),{entryId:a,exitId:a}}function Ye(e,r,n,c,l){let a=r,m=a.showRetryEdges??!0,f=a.showErrorEdges??!0,g=a.showTimeoutEdges??!0,i=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:C("step");if(G.has(i)){let b=2;for(;G.has(`${i}_${b}`);)b++;i=`${i}_${b}`}G.add(i);let d=e.name??e.key??"Step",w=r.showKeys&&e.key&&e.name?`${d} [${e.key}]`:d,u=T(w),p=r.showTimings&&e.durationMs!==void 0?` ${_(e.durationMs)}`:"",h="";switch(e.state){case"success":h="\u2713 ";break;case"error":h="\u2717 ";break;case"cached":h="\u{1F4BE} ";break;case"running":h="\u23F3 ";break;case"skipped":h="\u2298 ";break}let y="";if(e.input!==void 0){let b=typeof e.input=="string"?T(e.input):T(ae(e.input).slice(0,20));y+=`\\nin: ${b}`}if(e.output!==void 0&&e.state==="success"){let b=typeof e.output=="string"?T(e.output):T(ae(e.output).slice(0,20));y+=`\\nout: ${b}`}let x="",D=e.key??e.id;if(l&&D&&l.onAfterStep.has(D)){let b=l.onAfterStep.get(D),$=b.state==="success"?"\u2699":"\u26A0",I=r.showTimings&&b.durationMs!==void 0?` ${_(b.durationMs)}`:"";x=`\\n${$} hook${I}`}let R=(h+u+y+x+p).trim(),k,E=c?.showHeatmap&&c.heatmapData?c.heatmapData.heat.get(e.key??"")??c.heatmapData.heat.get(e.name??"")??c.heatmapData.heat.get(e.id):void 0;if(E!==void 0){let b=ie(E);k=Ge(b)}else k=e.state;let M;switch(e.state){case"error":M=`{{"${R}"}}`;break;case"cached":M=`[("${R}")]`;break;case"skipped":M=`["${R}"]`;break;default:M=`["${R}"]`}if(n.push(` ${i}${M}:::${k}`),m&&e.retryCount!==void 0&&e.retryCount>0){let b=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;n.push(` ${i} -.->|"${b}"| ${i}`)}if(f&&e.state==="error"&&e.error!==void 0){let b=`ERR_${i}`,$=T(String(e.error)).slice(0,30);n.push(` ${b}{{"${$}"}}`),n.push(` ${i} -->|error| ${b}`),n.push(` style ${b} fill:#fee2e2,stroke:#dc2626`)}if(g&&e.timedOut){let b=`TO_${i}`,$=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";n.push(` ${b}{{"\u23F1 Timeout ${$}"}}`),n.push(` ${i} -.->|timeout| ${b}`),n.push(` style ${b} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:i,exitId:i}}function Ze(e,r,n,c,l){let a=C("parallel"),m=`${a}_fork`,f=`${a}_join`,g=de(e.name??"Parallel"),i=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let u=a,p=T(`${g}${i}`),h="operations not individually tracked",y=r.showTimings&&e.durationMs!==void 0?` ${_(e.durationMs)}`:"";return n.push(` ${u}["${p}${y}\\n${h}"]:::${e.state}`),{entryId:u,exitId:u}}n.push(` subgraph ${a}["${g}${i}"]`),n.push(" direction TB"),n.push(` ${m}{"\u26A1 Fork"}`);let d=[];for(let u of e.children){let p=V(u,r,n,c,l);n.push(` ${m} --> ${p.entryId}`),d.push(p.exitId)}n.push(` ${f}{"\u2713 Join"}`);for(let u of d)n.push(` ${u} --> ${f}`);n.push(" end");let w=e.state;return n.push(` class ${a} ${w}`),{entryId:m,exitId:f}}function Xe(e,r,n,c,l){let a=C("race"),m=`${a}_start`,f=`${a}_end`,g=de(e.name??"Race");if(e.children.length===0){let u=a,p=T(g),h="operations not individually tracked",y=r.showTimings&&e.durationMs!==void 0?` ${_(e.durationMs)}`:"";return n.push(` ${u}["\u26A1 ${p}${y}\\n${h}"]:::${e.state}`),{entryId:u,exitId:u}}n.push(` subgraph ${a}["\u26A1 ${g}"]`),n.push(" direction TB"),n.push(` ${m}(("\u{1F3C1} Start"))`);let i=[],d;for(let u of e.children){let p=V(u,r,n,c,l),h=e.winnerId===u.id;n.push(` ${m} --> ${p.entryId}`),h&&(d=p.exitId),i.push({exitId:p.exitId,isWinner:h})}n.push(` ${f}(("\u2713 First"))`);for(let{exitId:u,isWinner:p}of i)p&&d?n.push(` ${u} ==>|\u{1F3C6} Winner| ${f}`):e.winnerId?n.push(` ${u} -. cancelled .-> ${f}`):n.push(` ${u} --> ${f}`);n.push(" end");let w=e.state;return n.push(` class ${a} ${w}`),{entryId:m,exitId:f}}function Qe(e,r,n,c,l){let a=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:C("decision");if(z.has(a)){let u=2;for(;z.has(`${a}_${u}`);)u++;a=`${a}_${u}`}z.add(a);let m=T(e.condition??"condition"),f=e.decisionValue!==void 0?` = ${T(String(e.decisionValue)).slice(0,30)}`:"",g=`${m}${f}`.trim();n.push(` ${a}{"${g}"}`);let i=[],d,w=new Set;for(let u of e.branches){let p=`${a}_${u.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(w.has(p)){let R=2;for(;w.has(`${p}_${R}`);)R++;p=`${p}_${R}`}w.add(p);let h=T(u.label),y=u.taken?`${h} \u2713`:`${h} skipped`,x=u.taken?":::success":":::skipped";n.push(` ${p}["${y}"]${x}`);let D=u.condition?`|${T(u.condition).replace(/\|/g,"")}|`:"";if(n.push(` ${a} -->${D} ${p}`),u.children.length>0){let R=p;for(let k of u.children){let E=V(k,r,n,c,l);n.push(` ${R} --> ${E.entryId}`),R=E.exitId}i.push(R),u.taken&&(d=R)}else i.push(p),u.taken&&(d=p)}return d?{entryId:a,exitId:d}:{entryId:a,exitId:a}}function et(e,r,n){let c=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${C("")}`,l=`W:${e.writeCount} R:${e.readCount}`,a="";switch(e.streamState){case"active":a="\u27F3 ";break;case"closed":a="\u2713 ";break;case"error":a="\u2717 ";break}let m=r.showTimings&&e.durationMs!==void 0?` ${_(e.durationMs)}`:"",f=e.backpressureOccurred?"\\nbackpressure":"",g=`${a}stream:${T(e.namespace)}\\n${l}${f}${m}`,i;return e.streamState==="error"?i="streamError":e.streamState==="active"?i="streamActive":i="stream",n.push(` ${c}{{"${g}"}}:::${i}`),{entryId:c,exitId:c}}var le=Ce(require("pako"),1),tt=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function rt(e){let r;if(tt)r=globalThis.Buffer.from(e).toString("base64");else{let n="";for(let c=0;c<e.length;c++)n+=String.fromCharCode(e[c]);r=btoa(n)}return r.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function q(e){let n=new TextEncoder().encode(e),c=le.default.deflate(n);return rt(c)}var nt="https://kroki.io";function ot(e,r,n,c={}){let l=c.baseUrl??nt,a=q(n);return`${l}/${e}/${r}/${a}`}function st(e,r="svg",n={}){let c=F(),l={showTimings:!0,showKeys:!1,terminalWidth:80,colors:W},a=c.render(e,l);return ot("mermaid",r,a,n)}function ue(e,r={}){return st(e,"svg",r)}var it="https://mermaid.ink";function at(e){return`pako:${q(e)}`}function ct(e){if("provider"in e){let r=e;return{theme:r.mermaidTheme,bgColor:r.background,scale:r.scale,fit:r.fit,width:r.width,height:r.height,paper:r.paper,imageType:"png"}}return e}function dt(e,r){let n=[];return r.bgColor&&n.push(`bgColor=${encodeURIComponent(r.bgColor)}`),r.theme&&n.push(`theme=${r.theme}`),r.width!==void 0&&n.push(`width=${r.width}`),r.height!==void 0&&n.push(`height=${r.height}`),r.scale!==void 0&&(r.width!==void 0||r.height!==void 0)&&n.push(`scale=${r.scale}`),e==="img"&&r.imageType&&r.imageType!=="jpeg"&&n.push(`type=${r.imageType}`),e==="pdf"&&(r.fit&&n.push("fit"),r.paper&&!r.fit&&n.push(`paper=${r.paper}`),r.landscape&&!r.fit&&n.push("landscape")),n.length>0?`?${n.join("&")}`:""}function lt(e,r,n={}){let c=ct(n),l=c.baseUrl??it,a=at(r),m=dt(e,c);return`${l}/${e}/${a}${m}`}function ut(e,r="svg",n={}){let c=F(),l={showTimings:!0,showKeys:!1,terminalWidth:80,colors:W},a=c.render(e,l);return lt(r,a,n)}function pe(e,r={}){return ut(e,"svg",r)}function fe(e){return{getDiagramUrl(r){if(e.provider==="mermaid-ink"){let{provider:n,...c}=e;return pe(r,c)}return ue(r,{baseUrl:e.baseUrl})},countSteps(r){return X(r)},formatDuration(r){return r.root.endTs!==void 0&&r.root.startTs!==void 0?`${r.root.endTs-r.root.startTs}ms`:r.root.durationMs!==void 0?`${r.root.durationMs}ms`:"In progress"}}}var P=require("awaitly");function pt(e){for(let r of e)if((r.type==="parallel"||r.type==="race"||r.type==="sequence")&&!r.id.startsWith("detected_")||r.type==="decision")return!0;return!1}function me(e,r={}){if(pt(e))return e;let{minOverlapMs:n=0,maxGapMs:c=5}=r,l=[],a=[];for(let i=0;i<e.length;i++){let d=e[i];d.type==="step"&&d.startTs!==void 0?l.push({node:d,startTs:d.startTs,endTs:d.endTs??d.startTs+(d.durationMs??0),originalIndex:i}):a.push({node:d,originalIndex:i})}if(l.length<=1)return e;l.sort((i,d)=>i.startTs-d.startTs);let m=[],f=[l[0]];for(let i=1;i<l.length;i++){let d=l[i],w=Math.min(...f.map(x=>x.startTs)),u=Math.max(...f.map(x=>x.endTs)),p=d.startTs<=w+c,h=d.startTs<u;if(!p&&!h){m.push(f),f=[d];continue}let y=h?Math.min(d.endTs,u)-d.startTs:0;p||y>=n?f.push(d):(m.push(f),f=[d])}m.push(f);let g=[];for(let i of m){let d=Math.min(...i.map(w=>w.originalIndex));if(i.length===1)g.push({node:i[0].node,position:d});else{let w=i.map(y=>y.node),u=Math.min(...i.map(y=>y.startTs)),p=Math.max(...i.map(y=>y.endTs)),h={type:"parallel",id:`detected_parallel_${u}`,name:`${w.length} parallel steps`,state:ft(w),mode:"all",children:w,startTs:u,endTs:p,durationMs:p-u};g.push({node:h,position:d})}}for(let{node:i,originalIndex:d}of a)g.push({node:i,position:d});return g.sort((i,d)=>i.position-d.position),g.map(i=>i.node)}function ft(e){return e.some(a=>a.state==="error")?"error":e.some(a=>a.state==="running")?"running":e.some(a=>a.state==="pending")?"pending":(e.every(a=>a.state==="success"||a.state==="cached"),"success")}function ge(e={}){let{detectParallel:r=!0,parallelDetection:n,enableSnapshots:c=!1,maxSnapshots:l=1e3}=e,a=c,m=K(),f,g,i,d="pending",w,u,p=new Map,h=[],y=[],x=new Map,D=[],R=Date.now(),k=R,E={onAfterStep:new Map},M,b=[],$=0;function I(t){return t.stepId??t.stepKey??t.name??K()}function O(t){if(h.length>0){h[h.length-1].children.push(t),k=Date.now();return}if(y.length>0){let s=y[y.length-1];for(let o of s.branches.values())if(o.taken){o.children.push(t),k=Date.now();return}s.pendingChildren.push(t),k=Date.now();return}D.push(t),k=Date.now()}function be(t){if(!a)return;let s=Y(),o=new Map;for(let[S,v]of p)o.set(S,{id:v.id,name:v.name,key:v.key,startTs:v.startTs,retryCount:v.retryCount,timedOut:v.timedOut,timeoutMs:v.timeoutMs});let N={id:`snapshot_${$}`,eventIndex:$,event:structuredClone(t),ir:structuredClone(s),timestamp:Date.now(),activeSteps:o};b.push(N),b.length>l&&b.shift(),$++}function ye(t){switch(t.type){case"workflow_start":{D=[],i=void 0,u=void 0,w=void 0,p.clear(),h.length=0,y.length=0,x.clear(),f=t.workflowId,g=t.ts,d="running",R=Date.now(),k=R,M!==void 0&&M!==t.workflowId&&(E.shouldRun=void 0,E.onBeforeStart=void 0),M=t.workflowId,E.onAfterStep=new Map;break}case"workflow_success":d="success",i=t.ts,u=t.durationMs,k=Date.now();break;case"workflow_error":d="error",i=t.ts,w=t.error,u=t.durationMs,k=Date.now();break;case"workflow_cancelled":d="aborted",i=t.ts,u=t.durationMs,k=Date.now();break;case"step_start":{let s=I(t);p.set(s,{id:s,name:t.name,key:t.stepKey,startTs:t.ts,retryCount:0,timedOut:!1,metadata:t.metadata}),k=Date.now();break}case"step_success":{let s=I(t),o=p.get(s);if(o){let N={type:"step",id:o.id,name:o.name,key:o.key,state:"success",startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,...o.retryCount>0&&{retryCount:o.retryCount},...o.timedOut&&{timedOut:!0,timeoutMs:o.timeoutMs},...o.metadata&&{metadata:o.metadata}};O(N),p.delete(s)}break}case"step_error":{let s=I(t),o=p.get(s);if(o){let N={type:"step",id:o.id,name:o.name,key:o.key,state:"error",startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,error:t.error,...o.retryCount>0&&{retryCount:o.retryCount},...o.timedOut&&{timedOut:!0,timeoutMs:o.timeoutMs},...o.metadata&&{metadata:o.metadata},...t.diagnostics&&{errorDiagnostics:t.diagnostics}};O(N),p.delete(s)}break}case"step_aborted":{let s=I(t),o=p.get(s);if(o){let N={type:"step",id:o.id,name:o.name,key:o.key,state:"aborted",startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,...o.retryCount>0&&{retryCount:o.retryCount},...o.timedOut&&{timedOut:!0,timeoutMs:o.timeoutMs},...o.metadata&&{metadata:o.metadata}};O(N),p.delete(s)}break}case"step_cache_hit":{let o={type:"step",id:I(t),name:t.name,key:t.stepKey,state:"cached",startTs:t.ts,endTs:t.ts,durationMs:0};O(o);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let s=I(t),o=p.get(s);o&&(o.timedOut=!0,o.timeoutMs=t.timeoutMs),k=Date.now();break}case"step_retry":{let s=I(t),o=p.get(s);o&&(o.retryCount=(t.attempt??1)-1),k=Date.now();break}case"step_retries_exhausted":k=Date.now();break;case"step_skipped":{let o={type:"step",id:I(t),name:t.name,key:t.stepKey,state:"skipped",startTs:t.ts,endTs:t.ts,durationMs:0,...t.metadata&&{metadata:t.metadata}};O(o);break}case"decision":{let s=t;if(s.phase==="start"){U({type:"decision_start",workflowId:t.workflowId,decisionId:s.decisionId,name:s.label??s.decisionId,condition:s.label,decisionValue:s.value,ts:s.ts}),U({type:"decision_branch",workflowId:t.workflowId,decisionId:s.decisionId,branchLabel:"then",condition:s.label,taken:s.branch==="then",ts:s.ts}),U({type:"decision_branch",workflowId:t.workflowId,decisionId:s.decisionId,branchLabel:"else",taken:s.branch==="else",ts:s.ts});break}if(s.phase==="end"){U({type:"decision_end",workflowId:t.workflowId,decisionId:s.decisionId,branchTaken:s.branch,ts:s.ts,durationMs:s.durationMs??0});break}let o={type:"decision",id:s.decisionId,name:s.label??s.decisionId,state:"success",startTs:s.ts,endTs:s.ts,durationMs:0,condition:s.label,decisionValue:s.value,branchTaken:s.branch,branches:[{label:"then",condition:s.label,taken:s.branch==="then",children:[]},{label:"else",taken:s.branch==="else",children:[]}]};O(o),k=Date.now();break}case"hook_should_run":{let s={type:"shouldRun",state:"success",ts:t.ts,durationMs:t.durationMs,context:{result:t.result,skipped:t.skipped}};E.shouldRun=s,M=t.workflowId,k=Date.now();break}case"hook_should_run_error":{let s={type:"shouldRun",state:"error",ts:t.ts,durationMs:t.durationMs,error:t.error};E.shouldRun=s,M=t.workflowId,k=Date.now();break}case"hook_before_start":{let s={type:"onBeforeStart",state:"success",ts:t.ts,durationMs:t.durationMs,context:{result:t.result,skipped:t.skipped}};E.onBeforeStart=s,M=t.workflowId,k=Date.now();break}case"hook_before_start_error":{let s={type:"onBeforeStart",state:"error",ts:t.ts,durationMs:t.durationMs,error:t.error};E.onBeforeStart=s,M=t.workflowId,k=Date.now();break}case"hook_after_step":{let s={type:"onAfterStep",state:"success",ts:t.ts,durationMs:t.durationMs,context:{stepKey:t.stepKey}};E.onAfterStep.set(t.stepKey,s),k=Date.now();break}case"hook_after_step_error":{let s={type:"onAfterStep",state:"error",ts:t.ts,durationMs:t.durationMs,error:t.error,context:{stepKey:t.stepKey}};E.onAfterStep.set(t.stepKey,s),k=Date.now();break}case"stream_created":{let s=`${t.workflowId}:${t.namespace}`;x.set(s,{id:K(),namespace:t.namespace,startTs:t.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),k=Date.now();break}case"stream_write":{let s=`${t.workflowId}:${t.namespace}`,o=x.get(s);o&&(o.writeCount++,o.finalPosition=Math.max(o.finalPosition,t.position)),k=Date.now();break}case"stream_read":{let s=`${t.workflowId}:${t.namespace}`,o=x.get(s);o&&o.readCount++,k=Date.now();break}case"stream_close":{let s=`${t.workflowId}:${t.namespace}`,o=x.get(s);if(o){o.streamState="closed",o.finalPosition=t.finalPosition;let N={type:"stream",id:o.id,namespace:o.namespace,state:"success",startTs:o.startTs,endTs:t.ts,durationMs:t.ts-o.startTs,writeCount:o.writeCount,readCount:o.readCount,finalPosition:t.finalPosition,streamState:"closed",backpressureOccurred:o.backpressureOccurred};O(N),x.delete(s)}k=Date.now();break}case"stream_error":{let s=`${t.workflowId}:${t.namespace}`,o=x.get(s);if(o){o.streamState="error";let N={type:"stream",id:o.id,namespace:o.namespace,state:"error",error:t.error,startTs:o.startTs,endTs:t.ts,durationMs:t.ts-o.startTs,writeCount:o.writeCount,readCount:o.readCount,finalPosition:t.position,streamState:"error",backpressureOccurred:o.backpressureOccurred};O(N),x.delete(s)}k=Date.now();break}case"stream_backpressure":{let s=`${t.workflowId}:${t.namespace}`,o=x.get(s);o&&(o.backpressureOccurred=!0),k=Date.now();break}}be(t)}function Se(t){if(t.type==="scope_start")h.push({id:t.scopeId,name:t.name,type:t.scopeType,startTs:t.ts,children:[]}),k=Date.now();else if(t.type==="scope_end"){let s=h.findIndex(S=>S.id===t.scopeId);if(s===-1)return;for(;h.length>s+1;){let S=h.pop(),v=S.type==="race"?{type:"race",id:S.id,name:S.name,state:A(S.children),startTs:S.startTs,endTs:t.ts,children:S.children}:{type:"parallel",id:S.id,name:S.name,state:A(S.children),startTs:S.startTs,endTs:t.ts,children:S.children,mode:S.type==="allSettled"?"allSettled":"all"};h[h.length-1].children.push(v)}let[o]=h.splice(s,1),N=o.type==="race"?{type:"race",id:o.id,name:o.name,state:A(o.children),startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,children:o.children,winnerId:t.winnerId}:{type:"parallel",id:o.id,name:o.name,state:A(o.children),startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,children:o.children,mode:o.type==="allSettled"?"allSettled":"all"};O(N)}}function U(t){if(t.type==="decision_start")y.push({id:t.decisionId,name:t.name,condition:t.condition,decisionValue:t.decisionValue,startTs:t.ts,branches:new Map,pendingChildren:[]}),k=Date.now();else if(t.type==="decision_branch"){let s=y.find(o=>o.id===t.decisionId);if(s){let o=t.branchLabel,N=s.branches.get(o);if(N)N.taken=t.taken,t.taken&&s.pendingChildren.length>0&&(N.children.unshift(...s.pendingChildren),s.pendingChildren=[]);else{let S=t.taken?[...s.pendingChildren]:[];t.taken&&(s.pendingChildren=[]),s.branches.set(o,{label:t.branchLabel,condition:t.condition,taken:t.taken,children:S})}k=Date.now()}}else if(t.type==="decision_end"){let s=y.findIndex(o=>o.id===t.decisionId);if(s!==-1){let[o]=y.splice(s,1),N=y.splice(s),S=Array.from(o.branches.values());S.length===0&&o.pendingChildren.length>0&&(S=[{label:"default",taken:!0,children:[...o.pendingChildren]}]);let v=S.find(B=>B.taken)?.label,Me={type:"decision",id:o.id,name:o.name,state:A(S.flatMap(B=>B.taken?B.children:[])),startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,condition:o.condition,decisionValue:o.decisionValue,branchTaken:t.branchTaken??v,branches:S};O(Me),y.push(...N),k=Date.now()}}}function A(t){return t.length===0?"success":t.some(S=>S.state==="error")?"error":t.every(S=>S.state==="success"||S.state==="cached")?"success":t.some(S=>S.state==="running")?"running":"pending"}function $e(){let t=[...D];for(let[,s]of p)t.push({type:"step",id:s.id,name:s.name,key:s.key,state:"running",startTs:s.startTs,...s.retryCount>0&&{retryCount:s.retryCount},...s.timedOut&&{timedOut:!0,timeoutMs:s.timeoutMs}});for(let[,s]of x)t.push({type:"stream",id:s.id,namespace:s.namespace,state:"running",startTs:s.startTs,writeCount:s.writeCount,readCount:s.readCount,finalPosition:s.finalPosition,streamState:s.streamState,backpressureOccurred:s.backpressureOccurred});return t}function Y(){let t=$e();r&&(t=me(t,n));let s={type:"workflow",id:f??m,workflowId:f??m,state:d,startTs:g,endTs:i,durationMs:u,children:t,error:w},o=E.shouldRun!==void 0||E.onBeforeStart!==void 0||E.onAfterStep.size>0;return{root:s,metadata:{createdAt:R,lastUpdatedAt:k},...o&&{hooks:E}}}function xe(){f=void 0,g=void 0,i=void 0,d="pending",w=void 0,u=void 0,p.clear(),h.length=0,y.length=0,x.clear(),D=[],R=Date.now(),k=R,E={onAfterStep:new Map},M=void 0,b.length=0,$=0}function Ie(){return[...b]}function Re(t){return b[t]}function Ee(t){return b[t]?.ir}function Ne(){b.length=0,$=0}return{handleEvent:ye,handleScopeEvent:Se,handleDecisionEvent:U,getIR:Y,reset:xe,getSnapshots:Ie,getSnapshotAt:Re,getIRAt:Ee,clearSnapshots:Ne,get hasActiveSteps(){return p.size>0},get state(){return d},get snapshotCount(){return b.length},get snapshotsEnabled(){return a},setSnapshotsEnabled(t){a=t}}}var mt=500,gt=5e3;function he(e,r){let{title:n,debounceMs:c=mt,maxWaitMs:l=gt}=e,a,m=!0,f,g,i,d,w,u,p=(0,P.ok)(void 0),h=ge({detectParallel:!0});function y(){i&&(clearTimeout(i),i=void 0),d&&(clearTimeout(d),d=void 0)}async function x(){if(!f||!m)return(0,P.ok)(void 0);let $=f;g=$,f=void 0,y();try{return a?await r.updateExisting(a,$,n):a=await r.postNew($,n),w=Date.now(),p=(0,P.ok)(void 0),p}catch{return p=(0,P.err)("CALLBACK_ERROR"),p}}function D(){i&&clearTimeout(i),i=setTimeout(()=>{x()},c);let $=w??u;if(!d&&$!==void 0){let I=Date.now()-$,O=Math.max(0,l-I);d=setTimeout(()=>{d=void 0,x()},O)}}function R($){if(m){if(u===void 0&&(u=Date.now()),"root"in $)f=$,g=$;else{let I=$;I.type==="scope_start"||I.type==="scope_end"?h.handleScopeEvent(I):I.type==="decision_start"||I.type==="decision_branch"||I.type==="decision_end"?h.handleDecisionEvent(I):h.handleEvent(I),f=h.getIR(),g=f}D()}}async function k($="completed"){if(!m)return;m=!1,y();let I=f??g??h.getIR();await r.finalize(a,I,n,$)}function E(){m&&(m=!1,y(),a&&r.cancel&&r.cancel(a))}function M(){return a}function b(){return m}return{update:R,finalize:k,cancel:E,getSessionId:M,isActive:b}}function ht(e){switch(e.root.state){case"success":return"completed";case"error":return"failed";case"aborted":return"cancelled";default:return"running"}}function ke(e,r){let{diagramProvider:n,debounceMs:c=500,maxWaitMs:l=5e3}=e;if(!n)throw new Error(`${r.name}Notifier: diagramProvider is required. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }.`);let a=fe(n);async function m(g,i={}){let d=i.title??"Workflow",w=ht(g);try{let u=r.buildMessage({ir:g,title:d,status:w},a),p=await r.sendNew(u);return(0,J.ok)(p?.toString())}catch{return(0,J.err)("SEND_FAILED")}}function f(g){return he({...g,debounceMs:g.debounceMs??c,maxWaitMs:g.maxWaitMs??l},{async postNew(i,d){let w=r.buildMessage({ir:i,title:d,status:"running"},a);return(await r.sendNew(w))?.toString()},async updateExisting(i,d,w){let u=r.buildMessage({ir:d,title:w,status:"running"},a);await r.sendUpdate(i,u)},async finalize(i,d,w,u){let p=r.buildMessage({ir:d,title:w,status:u},a);i?await r.sendUpdate(i,p):await r.sendNew(p)},async cancel(i){r.sendCancel&&i&&await r.sendCancel(i)}})}return{notify:m,createLive:f,getType:()=>r.name.toLowerCase()}}var L=require("awaitly"),kt={running:3447003,completed:3066993,failed:15158332,cancelled:9807270};function we(e){let{webhookUrl:r,username:n,avatarUrl:c,timeout:l=3e4}=e;if(!r.includes("discord.com/api/webhooks/"))throw new Error("Invalid Discord webhook URL");async function a(m,f){let g=new AbortController,i=setTimeout(()=>g.abort(),l);try{let d=f?`${r}/messages/${f}`:`${r}?wait=true`,u=await fetch(d,{method:f?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m),signal:g.signal});if(!u.ok)return(0,L.err)("SEND_FAILED");let p=await u.json();return(0,L.ok)(p.id)}catch(d){return d instanceof Error&&d.name==="AbortError"?(0,L.err)("TIMEOUT"):(0,L.err)("SEND_FAILED")}finally{clearTimeout(i)}}return{name:"Discord",buildMessage({ir:m,title:f,status:g},i){let d={title:f,color:kt[g],image:{url:i.getDiagramUrl(m)},fields:[{name:"Steps",value:String(i.countSteps(m)),inline:!0},{name:"Duration",value:i.formatDuration(m),inline:!0},{name:"Status",value:g.charAt(0).toUpperCase()+g.slice(1),inline:!0}],timestamp:new Date().toISOString()};return{username:n,avatar_url:c,embeds:[d]}},async sendNew(m){let f=await a(m);if(!f.ok)throw new Error(`Discord send failed: ${f.error}`);return f.value},async sendUpdate(m,f){let g=await a(f,m);if(!g.ok)throw new Error(`Discord update failed: ${g.error}`)}}}function wt(e){let{webhookUrl:r,username:n,avatarUrl:c,timeout:l,...a}=e,m=we({webhookUrl:r,username:n,avatarUrl:c,timeout:l});return ke(a,m)}0&&(module.exports={createDiscordNotifier});
3
3
  //# sourceMappingURL=discord.cjs.map