awaitly-visualizer 20.0.0 → 20.0.2

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/binding.gyp +9 -0
  2. package/dist/devtools.cjs +5 -5
  3. package/dist/devtools.cjs.map +1 -1
  4. package/dist/devtools.d.cts +3 -3
  5. package/dist/devtools.d.ts +3 -3
  6. package/dist/devtools.js +5 -5
  7. package/dist/devtools.js.map +1 -1
  8. package/dist/index.browser.cjs +17 -17
  9. package/dist/index.browser.cjs.map +1 -1
  10. package/dist/index.browser.d.cts +4 -4
  11. package/dist/index.browser.d.ts +4 -4
  12. package/dist/index.browser.js +19 -19
  13. package/dist/index.browser.js.map +1 -1
  14. package/dist/index.cjs +20 -20
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +4 -4
  17. package/dist/index.d.ts +4 -4
  18. package/dist/index.js +22 -22
  19. package/dist/index.js.map +1 -1
  20. package/dist/kroki/fetch.cjs.map +1 -1
  21. package/dist/kroki/fetch.d.cts +2 -2
  22. package/dist/kroki/fetch.d.ts +2 -2
  23. package/dist/kroki/fetch.js.map +1 -1
  24. package/dist/notifiers/discord.cjs +2 -2
  25. package/dist/notifiers/discord.cjs.map +1 -1
  26. package/dist/notifiers/discord.d.cts +2 -2
  27. package/dist/notifiers/discord.d.ts +2 -2
  28. package/dist/notifiers/discord.js +2 -2
  29. package/dist/notifiers/discord.js.map +1 -1
  30. package/dist/notifiers/slack.cjs +12 -12
  31. package/dist/notifiers/slack.cjs.map +1 -1
  32. package/dist/notifiers/slack.d.cts +2 -2
  33. package/dist/notifiers/slack.d.ts +2 -2
  34. package/dist/notifiers/slack.js +12 -12
  35. package/dist/notifiers/slack.js.map +1 -1
  36. package/dist/notifiers/webhook.cjs +1 -1
  37. package/dist/notifiers/webhook.cjs.map +1 -1
  38. package/dist/notifiers/webhook.d.cts +2 -2
  39. package/dist/notifiers/webhook.d.ts +2 -2
  40. package/dist/notifiers/webhook.js +2 -2
  41. package/dist/notifiers/webhook.js.map +1 -1
  42. package/dist/{performance-analyzer-MwxDr6ej.d.ts → performance-analyzer-C9WFkUSa.d.cts} +16 -1
  43. package/dist/{performance-analyzer-DyIZZ2rA.d.cts → performance-analyzer-ffmMicjZ.d.ts} +16 -1
  44. package/dist/{types-fuxEig2j.d.ts → types-Bmb5LpD-.d.ts} +1 -1
  45. package/dist/{types-CgO2me2s.d.cts → types-BmktN16n.d.cts} +1 -1
  46. package/dist/{url-BskfOf3W.d.cts → url-CxqaR2K3.d.cts} +6 -1
  47. package/dist/{url-BskfOf3W.d.ts → url-CxqaR2K3.d.ts} +6 -1
  48. package/index.js +1 -0
  49. package/package.json +4 -4
@@ -1,3 +1,3 @@
1
- "use strict";var Te=Object.create;var B=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)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=De(r,u))||c.enumerable});return e};var Ce=(e,r,n)=>(n=e!=null?Te(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 T(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function ce(e){return T(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=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(ie(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(ie(e.output).slice(0,20));y+=`\\nout: ${b}`}let x="",D=e.key??e.id;if(u&&D&&u.onAfterStep.has(D)){let b=u.onAfterStep.get(D),$=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}`,$=T(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=T(`${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=T(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=T(e.condition??"condition"),f=e.decisionValue!==void 0?` = ${T(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=T(l.label),y=l.taken?`${h} \u2713`:`${h} skipped`,x=l.taken?":::success":":::skipped";n.push(` ${p}["${y}"]${x}`);let D=l.condition?`|${T(l.condition).replace(/\|/g,"")}|`:"";if(n.push(` ${i} -->${D} ${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:${T(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,D=[],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}D.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":{D=[],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}),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(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(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(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};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=[...D];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(),D=[],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 D(){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}D()}}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 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});
3
3
  //# sourceMappingURL=discord.cjs.map