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,5 +1,5 @@
1
- import { W as WorkflowStatus, B as BaseNotifierOptions, P as ProviderOptions, N as Notifier } from '../types-CgO2me2s.cjs';
2
- import { W as WorkflowIR } from '../url-BskfOf3W.cjs';
1
+ import { W as WorkflowStatus, B as BaseNotifierOptions, P as ProviderOptions, N as Notifier } from '../types-BmktN16n.cjs';
2
+ import { W as WorkflowIR } from '../url-CxqaR2K3.cjs';
3
3
  import 'awaitly';
4
4
  import 'awaitly/workflow';
5
5
  import 'awaitly/core';
@@ -1,5 +1,5 @@
1
- import { W as WorkflowStatus, B as BaseNotifierOptions, P as ProviderOptions, N as Notifier } from '../types-fuxEig2j.js';
2
- import { W as WorkflowIR } from '../url-BskfOf3W.js';
1
+ import { W as WorkflowStatus, B as BaseNotifierOptions, P as ProviderOptions, N as Notifier } from '../types-Bmb5LpD-.js';
2
+ import { W as WorkflowIR } from '../url-CxqaR2K3.js';
3
3
  import 'awaitly';
4
4
  import 'awaitly/workflow';
5
5
  import 'awaitly/core';
@@ -1,3 +1,3 @@
1
- import{ok as at,err as ct}from"awaitly";function V(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 s of u.branches)s.taken&&(c+=r(s.children));else"children"in u&&u.children&&(c+=r(u.children));return c}return r(e.root.children)}import{ok as St,err as $t}from"awaitly";function q(e){return e.type==="step"}function J(e){return e.type==="parallel"}function Y(e){return e.type==="race"}function Z(e){return e.type==="decision"}function X(e){return e.type==="stream"}function W(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 A(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}var Re="\x1B[2m",Ie="\x1B[31m",Ne="\x1B[32m",Me="\x1B[33m",Ee="\x1B[34m",Q="\x1B[90m",Te="\x1B[37m";var _={pending:Te,running:Me,success:Ne,error:Ie,aborted:Q,cached:Ee,skipped:Re+Q};import{ok as Oe,err as De}from"awaitly";function ee(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function ve(){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 We(){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 _e(e){return`heat_${e}`}function Ce(){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 Pe(e){try{return Oe(JSON.stringify(e,(n,c)=>{if(typeof c!="bigint")return c;let u=Number(c);return Number.isSafeInteger(u)?u:c.toString()}))}catch{return De("STRINGIFY_ERROR")}}function te(e){let r=Pe(e);return r.ok?r.value:"[unserializable]"}function Le(e,r,n){let c;if(e.shouldRun){let u="hook_shouldRun",s=e.shouldRun.state==="success"?"hook_success":"hook_error",h=e.shouldRun.state==="success"?"\u2699":"\u26A0",m=n.showTimings&&e.shouldRun.durationMs!==void 0?` ${W(e.shouldRun.durationMs)}`:"",g=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";r.push(` ${u}[["${h} shouldRun${g}${m}"]]:::${s}`),c=u}if(e.onBeforeStart){let u="hook_beforeStart",s=e.onBeforeStart.state==="success"?"hook_success":"hook_error",h=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",m=n.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${W(e.onBeforeStart.durationMs)}`:"",g=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";r.push(` ${u}[["${h} onBeforeStart${g}${m}"]]:::${s}`),c&&r.push(` ${c} --> ${u}`),c=u}return{lastHookId:c}}var re=0,F=new Set,B=new Set;function P(e="node"){return`${e}_${++re}`}function Ue(){re=0,F.clear(),B.clear()}function O(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function ne(e){return O(e).replace(/[{}[\]()]/g,"")}function C(){return{name:"mermaid",supportsLive:!1,render(e,r){Ue();let n=[],c=r;n.push("flowchart TD");let u;e.hooks&&(u=Le(e.hooks,n,r).lastHookId);let s="start";n.push(` ${s}(("\u25B6 Start"))`),u&&n.push(` ${u} --> ${s}`);let h=s;for(let g of e.root.children){let i=H(g,r,n,c,e.hooks);n.push(` ${h} --> ${i.entryId}`),h=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",b=`(("${i} ${d}"))`,l=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";n.push(` ${g}${b}${l}`),n.push(` ${h} --> ${g}`)}return n.push(""),n.push(...ve()),c.showHeatmap&&n.push(...We()),e.hooks&&n.push(...Ce()),n.join(`
2
- `)}}}function H(e,r,n,c,u){if(q(e))return Ae(e,r,n,c,u);if(J(e))return Fe(e,r,n,c,u);if(Y(e))return Be(e,r,n,c,u);if(Z(e))return He(e,r,n,c,u);if(X(e))return Ke(e,r,n);let s=P("unknown");return n.push(` ${s}["Unknown Node"]`),{entryId:s,exitId:s}}function Ae(e,r,n,c,u){let s=r,h=s.showRetryEdges??!0,m=s.showErrorEdges??!0,g=s.showTimeoutEdges??!0,i=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:P("step");if(B.has(i)){let y=2;for(;B.has(`${i}_${y}`);)y++;i=`${i}_${y}`}B.add(i);let d=e.name??e.key??"Step",b=r.showKeys&&e.key&&e.name?`${d} [${e.key}]`:d,l=O(b),p=r.showTimings&&e.durationMs!==void 0?` ${W(e.durationMs)}`:"",f="";switch(e.state){case"success":f="\u2713 ";break;case"error":f="\u2717 ";break;case"cached":f="\u{1F4BE} ";break;case"running":f="\u23F3 ";break;case"skipped":f="\u2298 ";break}let w="";if(e.input!==void 0){let y=typeof e.input=="string"?O(e.input):O(te(e.input).slice(0,20));w+=`\\nin: ${y}`}if(e.output!==void 0&&e.state==="success"){let y=typeof e.output=="string"?O(e.output):O(te(e.output).slice(0,20));w+=`\\nout: ${y}`}let S="",R=e.key??e.id;if(u&&R&&u.onAfterStep.has(R)){let y=u.onAfterStep.get(R),N=y.state==="success"?"\u2699":"\u26A0",M=r.showTimings&&y.durationMs!==void 0?` ${W(y.durationMs)}`:"";S=`\\n${N} hook${M}`}let x=(f+l+w+S+p).trim(),k,I=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(I!==void 0){let y=ee(I);k=_e(y)}else k=e.state;let T;switch(e.state){case"error":T=`{{"${x}"}}`;break;case"cached":T=`[("${x}")]`;break;case"skipped":T=`["${x}"]`;break;default:T=`["${x}"]`}if(n.push(` ${i}${T}:::${k}`),h&&e.retryCount!==void 0&&e.retryCount>0){let y=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;n.push(` ${i} -.->|"${y}"| ${i}`)}if(m&&e.state==="error"&&e.error!==void 0){let y=`ERR_${i}`,N=O(String(e.error)).slice(0,30);n.push(` ${y}{{"${N}"}}`),n.push(` ${i} -->|error| ${y}`),n.push(` style ${y} fill:#fee2e2,stroke:#dc2626`)}if(g&&e.timedOut){let y=`TO_${i}`,N=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";n.push(` ${y}{{"\u23F1 Timeout ${N}"}}`),n.push(` ${i} -.->|timeout| ${y}`),n.push(` style ${y} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:i,exitId:i}}function Fe(e,r,n,c,u){let s=P("parallel"),h=`${s}_fork`,m=`${s}_join`,g=ne(e.name??"Parallel"),i=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let l=s,p=O(`${g}${i}`),f="operations not individually tracked",w=r.showTimings&&e.durationMs!==void 0?` ${W(e.durationMs)}`:"";return n.push(` ${l}["${p}${w}\\n${f}"]:::${e.state}`),{entryId:l,exitId:l}}n.push(` subgraph ${s}["${g}${i}"]`),n.push(" direction TB"),n.push(` ${h}{"\u26A1 Fork"}`);let d=[];for(let l of e.children){let p=H(l,r,n,c,u);n.push(` ${h} --> ${p.entryId}`),d.push(p.exitId)}n.push(` ${m}{"\u2713 Join"}`);for(let l of d)n.push(` ${l} --> ${m}`);n.push(" end");let b=e.state;return n.push(` class ${s} ${b}`),{entryId:h,exitId:m}}function Be(e,r,n,c,u){let s=P("race"),h=`${s}_start`,m=`${s}_end`,g=ne(e.name??"Race");if(e.children.length===0){let l=s,p=O(g),f="operations not individually tracked",w=r.showTimings&&e.durationMs!==void 0?` ${W(e.durationMs)}`:"";return n.push(` ${l}["\u26A1 ${p}${w}\\n${f}"]:::${e.state}`),{entryId:l,exitId:l}}n.push(` subgraph ${s}["\u26A1 ${g}"]`),n.push(" direction TB"),n.push(` ${h}(("\u{1F3C1} Start"))`);let i=[],d;for(let l of e.children){let p=H(l,r,n,c,u),f=e.winnerId===l.id;n.push(` ${h} --> ${p.entryId}`),f&&(d=p.exitId),i.push({exitId:p.exitId,isWinner:f})}n.push(` ${m}(("\u2713 First"))`);for(let{exitId:l,isWinner:p}of i)p&&d?n.push(` ${l} ==>|\u{1F3C6} Winner| ${m}`):e.winnerId?n.push(` ${l} -. cancelled .-> ${m}`):n.push(` ${l} --> ${m}`);n.push(" end");let b=e.state;return n.push(` class ${s} ${b}`),{entryId:h,exitId:m}}function He(e,r,n,c,u){let s=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:P("decision");if(F.has(s)){let l=2;for(;F.has(`${s}_${l}`);)l++;s=`${s}_${l}`}F.add(s);let h=O(e.condition??"condition"),m=e.decisionValue!==void 0?` = ${O(String(e.decisionValue)).slice(0,30)}`:"",g=`${h}${m}`.trim();n.push(` ${s}{"${g}"}`);let i=[],d,b=new Set;for(let l of e.branches){let p=`${s}_${l.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(b.has(p)){let x=2;for(;b.has(`${p}_${x}`);)x++;p=`${p}_${x}`}b.add(p);let f=O(l.label),w=l.taken?`${f} \u2713`:`${f} skipped`,S=l.taken?":::success":":::skipped";n.push(` ${p}["${w}"]${S}`);let R=l.condition?`|${O(l.condition).replace(/\|/g,"")}|`:"";if(n.push(` ${s} -->${R} ${p}`),l.children.length>0){let x=p;for(let k of l.children){let I=H(k,r,n,c,u);n.push(` ${x} --> ${I.entryId}`),x=I.exitId}i.push(x),l.taken&&(d=x)}else i.push(p),l.taken&&(d=p)}return d?{entryId:s,exitId:d}:{entryId:s,exitId:s}}function Ke(e,r,n){let c=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${P("")}`,u=`W:${e.writeCount} R:${e.readCount}`,s="";switch(e.streamState){case"active":s="\u27F3 ";break;case"closed":s="\u2713 ";break;case"error":s="\u2717 ";break}let h=r.showTimings&&e.durationMs!==void 0?` ${W(e.durationMs)}`:"",m=e.backpressureOccurred?"\\nbackpressure":"",g=`${s}stream:${O(e.namespace)}\\n${u}${m}${h}`,i;return e.streamState==="error"?i="streamError":e.streamState==="active"?i="streamActive":i="stream",n.push(` ${c}{{"${g}"}}:::${i}`),{entryId:c,exitId:c}}import ze from"pako";var Ge=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function je(e){let r;if(Ge)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 K(e){let n=new TextEncoder().encode(e),c=ze.deflate(n);return je(c)}var Ve="https://kroki.io";function qe(e,r,n,c={}){let u=c.baseUrl??Ve,s=K(n);return`${u}/${e}/${r}/${s}`}function Je(e,r="svg",n={}){let c=C(),u={showTimings:!0,showKeys:!1,terminalWidth:80,colors:_},s=c.render(e,u);return qe("mermaid",r,s,n)}function oe(e,r={}){return Je(e,"svg",r)}var Ye="https://mermaid.ink";function Ze(e){return`pako:${K(e)}`}function Xe(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 Qe(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 et(e,r,n={}){let c=Xe(n),u=c.baseUrl??Ye,s=Ze(r),h=Qe(e,c);return`${u}/${e}/${s}${h}`}function tt(e,r="svg",n={}){let c=C(),u={showTimings:!0,showKeys:!1,terminalWidth:80,colors:_},s=c.render(e,u);return et(r,s,n)}function se(e,r={}){return tt(e,"svg",r)}function ie(e){return{getDiagramUrl(r){if(e.provider==="mermaid-ink"){let{provider:n,...c}=e;return se(r,c)}return oe(r,{baseUrl:e.baseUrl})},countSteps(r){return V(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"}}}import{ok as z,err as ot}from"awaitly";function rt(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 ae(e,r={}){if(rt(e))return e;let{minOverlapMs:n=0,maxGapMs:c=5}=r,u=[],s=[];for(let i=0;i<e.length;i++){let d=e[i];d.type==="step"&&d.startTs!==void 0?u.push({node:d,startTs:d.startTs,endTs:d.endTs??d.startTs+(d.durationMs??0),originalIndex:i}):s.push({node:d,originalIndex:i})}if(u.length<=1)return e;u.sort((i,d)=>i.startTs-d.startTs);let h=[],m=[u[0]];for(let i=1;i<u.length;i++){let d=u[i],b=Math.min(...m.map(S=>S.startTs)),l=Math.max(...m.map(S=>S.endTs)),p=d.startTs<=b+c,f=d.startTs<l;if(!p&&!f){h.push(m),m=[d];continue}let w=f?Math.min(d.endTs,l)-d.startTs:0;p||w>=n?m.push(d):(h.push(m),m=[d])}h.push(m);let g=[];for(let i of h){let d=Math.min(...i.map(b=>b.originalIndex));if(i.length===1)g.push({node:i[0].node,position:d});else{let b=i.map(w=>w.node),l=Math.min(...i.map(w=>w.startTs)),p=Math.max(...i.map(w=>w.endTs)),f={type:"parallel",id:`detected_parallel_${l}`,name:`${b.length} parallel steps`,state:nt(b),mode:"all",children:b,startTs:l,endTs:p,durationMs:p-l};g.push({node:f,position:d})}}for(let{node:i,originalIndex:d}of s)g.push({node:i,position:d});return g.sort((i,d)=>i.position-d.position),g.map(i=>i.node)}function nt(e){return e.some(s=>s.state==="error")?"error":e.some(s=>s.state==="running")?"running":e.some(s=>s.state==="pending")?"pending":(e.every(s=>s.state==="success"||s.state==="cached"),"success")}function ce(e={}){let{detectParallel:r=!0,parallelDetection:n,enableSnapshots:c=!1,maxSnapshots:u=1e3}=e,s=c,h=A(),m,g,i,d="pending",b,l,p=new Map,f=[],w=[],S=new Map,R=[],x=Date.now(),k=x,I={onAfterStep:new Map},T,y=[],N=0;function M(t){return t.stepId??t.stepKey??t.name??A()}function D(t){if(f.length>0){f[f.length-1].children.push(t),k=Date.now();return}if(w.length>0){let a=w[w.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}R.push(t),k=Date.now()}function fe(t){if(!s)return;let a=j(),o=new Map;for(let[$,v]of p)o.set($,{id:v.id,name:v.name,key:v.key,startTs:v.startTs,retryCount:v.retryCount,timedOut:v.timedOut,timeoutMs:v.timeoutMs});let E={id:`snapshot_${N}`,eventIndex:N,event:structuredClone(t),ir:structuredClone(a),timestamp:Date.now(),activeSteps:o};y.push(E),y.length>u&&y.shift(),N++}function me(t){switch(t.type){case"workflow_start":{R=[],i=void 0,l=void 0,b=void 0,p.clear(),f.length=0,w.length=0,S.clear(),m=t.workflowId,g=t.ts,d="running",x=Date.now(),k=x,T!==void 0&&T!==t.workflowId&&(I.shouldRun=void 0,I.onBeforeStart=void 0),T=t.workflowId,I.onAfterStep=new Map;break}case"workflow_success":d="success",i=t.ts,l=t.durationMs,k=Date.now();break;case"workflow_error":d="error",i=t.ts,b=t.error,l=t.durationMs,k=Date.now();break;case"workflow_cancelled":d="aborted",i=t.ts,l=t.durationMs,k=Date.now();break;case"step_start":{let a=M(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=M(t),o=p.get(a);if(o){let E={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}};D(E),p.delete(a)}break}case"step_error":{let a=M(t),o=p.get(a);if(o){let E={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}};D(E),p.delete(a)}break}case"step_aborted":{let a=M(t),o=p.get(a);if(o){let E={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}};D(E),p.delete(a)}break}case"step_cache_hit":{let o={type:"step",id:M(t),name:t.name,key:t.stepKey,state:"cached",startTs:t.ts,endTs:t.ts,durationMs:0};D(o);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let a=M(t),o=p.get(a);o&&(o.timedOut=!0,o.timeoutMs=t.timeoutMs),k=Date.now();break}case"step_retry":{let a=M(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:M(t),name:t.name,key:t.stepKey,state:"skipped",startTs:t.ts,endTs:t.ts,durationMs:0};D(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}};I.shouldRun=a,T=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};I.shouldRun=a,T=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}};I.onBeforeStart=a,T=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};I.onBeforeStart=a,T=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}};I.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}};I.onAfterStep.set(t.stepKey,a),k=Date.now();break}case"stream_created":{let a=`${t.workflowId}:${t.namespace}`;S.set(a,{id:A(),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=S.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=S.get(a);o&&o.readCount++,k=Date.now();break}case"stream_close":{let a=`${t.workflowId}:${t.namespace}`,o=S.get(a);if(o){o.streamState="closed",o.finalPosition=t.finalPosition;let E={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};D(E),S.delete(a)}k=Date.now();break}case"stream_error":{let a=`${t.workflowId}:${t.namespace}`,o=S.get(a);if(o){o.streamState="error";let E={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};D(E),S.delete(a)}k=Date.now();break}case"stream_backpressure":{let a=`${t.workflowId}:${t.namespace}`,o=S.get(a);o&&(o.backpressureOccurred=!0),k=Date.now();break}}fe(t)}function ge(t){if(t.type==="scope_start")f.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=f.findIndex($=>$.id===t.scopeId);if(a===-1)return;for(;f.length>a+1;){let $=f.pop(),v=$.type==="race"?{type:"race",id:$.id,name:$.name,state:L($.children),startTs:$.startTs,endTs:t.ts,children:$.children}:{type:"parallel",id:$.id,name:$.name,state:L($.children),startTs:$.startTs,endTs:t.ts,children:$.children,mode:$.type==="allSettled"?"allSettled":"all"};f[f.length-1].children.push(v)}let[o]=f.splice(a,1),E=o.type==="race"?{type:"race",id:o.id,name:o.name,state:L(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:L(o.children),startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,children:o.children,mode:o.type==="allSettled"?"allSettled":"all"};D(E)}}function he(t){if(t.type==="decision_start")w.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=w.find(o=>o.id===t.decisionId);if(a){let o=t.branchLabel,E=a.branches.get(o);if(E)E.taken=t.taken,t.taken&&a.pendingChildren.length>0&&(E.children.unshift(...a.pendingChildren),a.pendingChildren=[]);else{let $=t.taken?[...a.pendingChildren]:[];t.taken&&(a.pendingChildren=[]),a.branches.set(o,{label:t.branchLabel,condition:t.condition,taken:t.taken,children:$})}k=Date.now()}}else if(t.type==="decision_end"){let a=w.findIndex(o=>o.id===t.decisionId);if(a!==-1){let[o]=w.splice(a,1),E=w.splice(a),$=Array.from(o.branches.values());$.length===0&&o.pendingChildren.length>0&&($=[{label:"default",taken:!0,children:[...o.pendingChildren]}]);let v=$.find(U=>U.taken)?.label,xe={type:"decision",id:o.id,name:o.name,state:L($.flatMap(U=>U.taken?U.children:[])),startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,condition:o.condition,decisionValue:o.decisionValue,branchTaken:t.branchTaken??v,branches:$};D(xe),w.push(...E),k=Date.now()}}}function L(t){return t.length===0?"success":t.some($=>$.state==="error")?"error":t.every($=>$.state==="success"||$.state==="cached")?"success":t.some($=>$.state==="running")?"running":"pending"}function ke(){let t=[...R];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 S)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=ke();r&&(t=ae(t,n));let a={type:"workflow",id:m??h,workflowId:m??h,state:d,startTs:g,endTs:i,durationMs:l,children:t,error:b},o=I.shouldRun!==void 0||I.onBeforeStart!==void 0||I.onAfterStep.size>0;return{root:a,metadata:{createdAt:x,lastUpdatedAt:k},...o&&{hooks:I}}}function we(){m=void 0,g=void 0,i=void 0,d="pending",b=void 0,l=void 0,p.clear(),f.length=0,w.length=0,S.clear(),R=[],x=Date.now(),k=x,I={onAfterStep:new Map},T=void 0,y.length=0,N=0}function be(){return[...y]}function ye(t){return y[t]}function Se(t){return y[t]?.ir}function $e(){y.length=0,N=0}return{handleEvent:me,handleScopeEvent:ge,handleDecisionEvent:he,getIR:j,reset:we,getSnapshots:be,getSnapshotAt:ye,getIRAt:Se,clearSnapshots:$e,get hasActiveSteps(){return p.size>0},get state(){return d},get snapshotCount(){return y.length},get snapshotsEnabled(){return s},setSnapshotsEnabled(t){s=t}}}var st=500,it=5e3;function de(e,r){let{title:n,debounceMs:c=st,maxWaitMs:u=it}=e,s,h=!0,m,g,i,d,b,l,p=z(void 0),f=ce({detectParallel:!0});function w(){i&&(clearTimeout(i),i=void 0),d&&(clearTimeout(d),d=void 0)}async function S(){if(!m||!h)return z(void 0);let N=m;g=N,m=void 0,w();try{return s?await r.updateExisting(s,N,n):s=await r.postNew(N,n),b=Date.now(),p=z(void 0),p}catch{return p=ot("CALLBACK_ERROR"),p}}function R(){i&&clearTimeout(i),i=setTimeout(()=>{S()},c);let N=b??l;if(!d&&N!==void 0){let M=Date.now()-N,D=Math.max(0,u-M);d=setTimeout(()=>{d=void 0,S()},D)}}function x(N){if(h){if(l===void 0&&(l=Date.now()),"root"in N)m=N,g=N;else{let M=N;M.type==="scope_start"||M.type==="scope_end"?f.handleScopeEvent(M):M.type==="decision_start"||M.type==="decision_branch"||M.type==="decision_end"?f.handleDecisionEvent(M):f.handleEvent(M),m=f.getIR(),g=m}R()}}async function k(N="completed"){if(!h)return;h=!1,w();let M=m??g??f.getIR();await r.finalize(s,M,n,N)}function I(){h&&(h=!1,w(),s&&r.cancel&&r.cancel(s))}function T(){return s}function y(){return h}return{update:x,finalize:k,cancel:I,getSessionId:T,isActive:y}}function dt(e){switch(e.root.state){case"success":return"completed";case"error":return"failed";case"aborted":return"cancelled";default:return"running"}}function le(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 s=ie(n);async function h(g,i={}){let d=i.title??"Workflow",b=dt(g);try{let l=r.buildMessage({ir:g,title:d,status:b},s),p=await r.sendNew(l);return at(p?.toString())}catch{return ct("SEND_FAILED")}}function m(g){return de({...g,debounceMs:g.debounceMs??c,maxWaitMs:g.maxWaitMs??u},{async postNew(i,d){let b=r.buildMessage({ir:i,title:d,status:"running"},s);return(await r.sendNew(b))?.toString()},async updateExisting(i,d,b){let l=r.buildMessage({ir:d,title:b,status:"running"},s);await r.sendUpdate(i,l)},async finalize(i,d,b,l){let p=r.buildMessage({ir:d,title:b,status:l},s);i?await r.sendUpdate(i,p):await r.sendNew(p)},async cancel(i){r.sendCancel&&i&&await r.sendCancel(i)}})}return{notify:h,createLive:m,getType:()=>r.name.toLowerCase()}}import{ok as ue,err as G}from"awaitly";function pe(e){let{url:r,headers:n={},timeout:c=3e4,includeMermaid:u=!1,includeKrokiUrl:s,includeDiagramUrl:h=s??!0,providerName:m="kroki",metadata:g}=e,i=C(),d={showTimings:!0,showKeys:!1,terminalWidth:80,colors:_},b=0;async function l(f){let w=new AbortController,S=setTimeout(()=>w.abort(),c);try{let R=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",...n},body:JSON.stringify(f),signal:w.signal});if(!R.ok)return G("SEND_FAILED");try{let x=await R.json();return ue(x.messageId??x.id??f.messageId??"")}catch{return ue(f.messageId??"")}}catch(R){return R instanceof Error&&R.name==="AbortError"?G("TIMEOUT"):G("SEND_FAILED")}finally{clearTimeout(S)}}function p(){return`webhook-${++b}-${Date.now()}`}return{name:"Webhook",buildMessage({ir:f,title:w,status:S},R){let x;S==="running"?x="workflow.update":x="workflow.complete";let k={event:x,timestamp:new Date().toISOString(),title:w,status:S,ir:f,metadata:g};if(h){let I=R.getDiagramUrl(f);k.diagramUrl=I,k.diagramProvider=m,k.krokiUrl=I}return u&&(k.mermaid=i.render(f,d)),{payload:k}},async sendNew(f){let{payload:w}=f,S=p();w.messageId=S;let R=await l(w);if(!R.ok)throw new Error(`Webhook send failed: ${R.error}`);return S},async sendUpdate(f,w){let{payload:S}=w;S.messageId=f;let R=await l(S);if(!R.ok)throw new Error(`Webhook update failed: ${R.error}`)}}}function lr(e){let{url:r,headers:n,timeout:c,includeMermaid:u,includeKrokiUrl:s,includeDiagramUrl:h,diagramProvider:m,...g}=e,i=pe({url:r,headers:n,timeout:c,includeMermaid:u,includeKrokiUrl:s,includeDiagramUrl:h,providerName:m?.provider??"kroki"});return le({...g,diagramProvider:m},i)}export{lr as createWebhookNotifier};
1
+ import{ok as at,err as ct}from"awaitly";function V(e){function r(o){let c=0;for(let u of o)if(u.type==="step")c++;else if(u.type==="decision"&&u.branches)for(let s of u.branches)s.taken&&(c+=r(s.children));else"children"in u&&u.children&&(c+=r(u.children));return c}return r(e.root.children)}import{ok as St,err as $t}from"awaitly";function q(e){return e.type==="step"}function J(e){return e.type==="parallel"}function Y(e){return e.type==="race"}function Z(e){return e.type==="decision"}function X(e){return e.type==="stream"}function W(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),o=Math.round(e%6e4/1e3);return o>=60&&(r+=1,o=0),o===0?`${r}m`:`${r}m ${o}s`}function A(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}var Re="\x1B[2m",Ie="\x1B[31m",Ne="\x1B[32m",Me="\x1B[33m",Ee="\x1B[34m",Q="\x1B[90m",Te="\x1B[37m";var _={pending:Te,running:Me,success:Ne,error:Ie,aborted:Q,cached:Ee,skipped:Re+Q};import{ok as Oe,err as De}from"awaitly";function ee(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function ve(){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 We(){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 _e(e){return`heat_${e}`}function Ce(){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 Pe(e){try{return Oe(JSON.stringify(e,(o,c)=>{if(typeof c!="bigint")return c;let u=Number(c);return Number.isSafeInteger(u)?u:c.toString()}))}catch{return De("STRINGIFY_ERROR")}}function te(e){let r=Pe(e);return r.ok?r.value:"[unserializable]"}function Le(e,r,o){let c;if(e.shouldRun){let u="hook_shouldRun",s=e.shouldRun.state==="success"?"hook_success":"hook_error",h=e.shouldRun.state==="success"?"\u2699":"\u26A0",m=o.showTimings&&e.shouldRun.durationMs!==void 0?` ${W(e.shouldRun.durationMs)}`:"",g=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";r.push(` ${u}[["${h} shouldRun${g}${m}"]]:::${s}`),c=u}if(e.onBeforeStart){let u="hook_beforeStart",s=e.onBeforeStart.state==="success"?"hook_success":"hook_error",h=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",m=o.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${W(e.onBeforeStart.durationMs)}`:"",g=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";r.push(` ${u}[["${h} onBeforeStart${g}${m}"]]:::${s}`),c&&r.push(` ${c} --> ${u}`),c=u}return{lastHookId:c}}var re=0,F=new Set,B=new Set;function P(e="node"){return`${e}_${++re}`}function Ue(){re=0,F.clear(),B.clear()}function O(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function ne(e){return O(e).replace(/[{}[\]()]/g,"")}function C(){return{name:"mermaid",supportsLive:!1,render(e,r){Ue();let o=[],c=r;o.push("flowchart TD");let u;e.hooks&&(u=Le(e.hooks,o,r).lastHookId);let s="start";o.push(` ${s}(("\u25B6 Start"))`),u&&o.push(` ${u} --> ${s}`);let h=s;for(let g of e.root.children){let i=H(g,r,o,c,e.hooks);o.push(` ${h} --> ${i.entryId}`),h=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",b=`(("${i} ${d}"))`,l=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";o.push(` ${g}${b}${l}`),o.push(` ${h} --> ${g}`)}return o.push(""),o.push(...ve()),c.showHeatmap&&o.push(...We()),e.hooks&&o.push(...Ce()),o.join(`
2
+ `)}}}function H(e,r,o,c,u){if(q(e))return Ae(e,r,o,c,u);if(J(e))return Fe(e,r,o,c,u);if(Y(e))return Be(e,r,o,c,u);if(Z(e))return He(e,r,o,c,u);if(X(e))return Ke(e,r,o);let s=P("unknown");return o.push(` ${s}["Unknown Node"]`),{entryId:s,exitId:s}}function Ae(e,r,o,c,u){let s=r,h=s.showRetryEdges??!0,m=s.showErrorEdges??!0,g=s.showTimeoutEdges??!0,i=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:P("step");if(B.has(i)){let y=2;for(;B.has(`${i}_${y}`);)y++;i=`${i}_${y}`}B.add(i);let d=e.name??e.key??"Step",b=r.showKeys&&e.key&&e.name?`${d} [${e.key}]`:d,l=O(b),p=r.showTimings&&e.durationMs!==void 0?` ${W(e.durationMs)}`:"",f="";switch(e.state){case"success":f="\u2713 ";break;case"error":f="\u2717 ";break;case"cached":f="\u{1F4BE} ";break;case"running":f="\u23F3 ";break;case"skipped":f="\u2298 ";break}let w="";if(e.input!==void 0){let y=typeof e.input=="string"?O(e.input):O(te(e.input).slice(0,20));w+=`\\nin: ${y}`}if(e.output!==void 0&&e.state==="success"){let y=typeof e.output=="string"?O(e.output):O(te(e.output).slice(0,20));w+=`\\nout: ${y}`}let S="",R=e.key??e.id;if(u&&R&&u.onAfterStep.has(R)){let y=u.onAfterStep.get(R),N=y.state==="success"?"\u2699":"\u26A0",M=r.showTimings&&y.durationMs!==void 0?` ${W(y.durationMs)}`:"";S=`\\n${N} hook${M}`}let x=(f+l+w+S+p).trim(),k,I=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(I!==void 0){let y=ee(I);k=_e(y)}else k=e.state;let T;switch(e.state){case"error":T=`{{"${x}"}}`;break;case"cached":T=`[("${x}")]`;break;case"skipped":T=`["${x}"]`;break;default:T=`["${x}"]`}if(o.push(` ${i}${T}:::${k}`),h&&e.retryCount!==void 0&&e.retryCount>0){let y=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;o.push(` ${i} -.->|"${y}"| ${i}`)}if(m&&e.state==="error"&&e.error!==void 0){let y=`ERR_${i}`,N=O(String(e.error)).slice(0,30);o.push(` ${y}{{"${N}"}}`),o.push(` ${i} -->|error| ${y}`),o.push(` style ${y} fill:#fee2e2,stroke:#dc2626`)}if(g&&e.timedOut){let y=`TO_${i}`,N=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";o.push(` ${y}{{"\u23F1 Timeout ${N}"}}`),o.push(` ${i} -.->|timeout| ${y}`),o.push(` style ${y} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:i,exitId:i}}function Fe(e,r,o,c,u){let s=P("parallel"),h=`${s}_fork`,m=`${s}_join`,g=ne(e.name??"Parallel"),i=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let l=s,p=O(`${g}${i}`),f="operations not individually tracked",w=r.showTimings&&e.durationMs!==void 0?` ${W(e.durationMs)}`:"";return o.push(` ${l}["${p}${w}\\n${f}"]:::${e.state}`),{entryId:l,exitId:l}}o.push(` subgraph ${s}["${g}${i}"]`),o.push(" direction TB"),o.push(` ${h}{"\u26A1 Fork"}`);let d=[];for(let l of e.children){let p=H(l,r,o,c,u);o.push(` ${h} --> ${p.entryId}`),d.push(p.exitId)}o.push(` ${m}{"\u2713 Join"}`);for(let l of d)o.push(` ${l} --> ${m}`);o.push(" end");let b=e.state;return o.push(` class ${s} ${b}`),{entryId:h,exitId:m}}function Be(e,r,o,c,u){let s=P("race"),h=`${s}_start`,m=`${s}_end`,g=ne(e.name??"Race");if(e.children.length===0){let l=s,p=O(g),f="operations not individually tracked",w=r.showTimings&&e.durationMs!==void 0?` ${W(e.durationMs)}`:"";return o.push(` ${l}["\u26A1 ${p}${w}\\n${f}"]:::${e.state}`),{entryId:l,exitId:l}}o.push(` subgraph ${s}["\u26A1 ${g}"]`),o.push(" direction TB"),o.push(` ${h}(("\u{1F3C1} Start"))`);let i=[],d;for(let l of e.children){let p=H(l,r,o,c,u),f=e.winnerId===l.id;o.push(` ${h} --> ${p.entryId}`),f&&(d=p.exitId),i.push({exitId:p.exitId,isWinner:f})}o.push(` ${m}(("\u2713 First"))`);for(let{exitId:l,isWinner:p}of i)p&&d?o.push(` ${l} ==>|\u{1F3C6} Winner| ${m}`):e.winnerId?o.push(` ${l} -. cancelled .-> ${m}`):o.push(` ${l} --> ${m}`);o.push(" end");let b=e.state;return o.push(` class ${s} ${b}`),{entryId:h,exitId:m}}function He(e,r,o,c,u){let s=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:P("decision");if(F.has(s)){let l=2;for(;F.has(`${s}_${l}`);)l++;s=`${s}_${l}`}F.add(s);let h=O(e.condition??"condition"),m=e.decisionValue!==void 0?` = ${O(String(e.decisionValue)).slice(0,30)}`:"",g=`${h}${m}`.trim();o.push(` ${s}{"${g}"}`);let i=[],d,b=new Set;for(let l of e.branches){let p=`${s}_${l.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(b.has(p)){let x=2;for(;b.has(`${p}_${x}`);)x++;p=`${p}_${x}`}b.add(p);let f=O(l.label),w=l.taken?`${f} \u2713`:`${f} skipped`,S=l.taken?":::success":":::skipped";o.push(` ${p}["${w}"]${S}`);let R=l.condition?`|${O(l.condition).replace(/\|/g,"")}|`:"";if(o.push(` ${s} -->${R} ${p}`),l.children.length>0){let x=p;for(let k of l.children){let I=H(k,r,o,c,u);o.push(` ${x} --> ${I.entryId}`),x=I.exitId}i.push(x),l.taken&&(d=x)}else i.push(p),l.taken&&(d=p)}return d?{entryId:s,exitId:d}:{entryId:s,exitId:s}}function Ke(e,r,o){let c=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${P("")}`,u=`W:${e.writeCount} R:${e.readCount}`,s="";switch(e.streamState){case"active":s="\u27F3 ";break;case"closed":s="\u2713 ";break;case"error":s="\u2717 ";break}let h=r.showTimings&&e.durationMs!==void 0?` ${W(e.durationMs)}`:"",m=e.backpressureOccurred?"\\nbackpressure":"",g=`${s}stream:${O(e.namespace)}\\n${u}${m}${h}`,i;return e.streamState==="error"?i="streamError":e.streamState==="active"?i="streamActive":i="stream",o.push(` ${c}{{"${g}"}}:::${i}`),{entryId:c,exitId:c}}import ze from"pako";var Ge=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function je(e){let r;if(Ge)r=globalThis.Buffer.from(e).toString("base64");else{let o="";for(let c=0;c<e.length;c++)o+=String.fromCharCode(e[c]);r=btoa(o)}return r.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function K(e){let o=new TextEncoder().encode(e),c=ze.deflate(o);return je(c)}var Ve="https://kroki.io";function qe(e,r,o,c={}){let u=c.baseUrl??Ve,s=K(o);return`${u}/${e}/${r}/${s}`}function Je(e,r="svg",o={}){let c=C(),u={showTimings:!0,showKeys:!1,terminalWidth:80,colors:_},s=c.render(e,u);return qe("mermaid",r,s,o)}function oe(e,r={}){return Je(e,"svg",r)}var Ye="https://mermaid.ink";function Ze(e){return`pako:${K(e)}`}function Xe(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 Qe(e,r){let o=[];return r.bgColor&&o.push(`bgColor=${encodeURIComponent(r.bgColor)}`),r.theme&&o.push(`theme=${r.theme}`),r.width!==void 0&&o.push(`width=${r.width}`),r.height!==void 0&&o.push(`height=${r.height}`),r.scale!==void 0&&(r.width!==void 0||r.height!==void 0)&&o.push(`scale=${r.scale}`),e==="img"&&r.imageType&&r.imageType!=="jpeg"&&o.push(`type=${r.imageType}`),e==="pdf"&&(r.fit&&o.push("fit"),r.paper&&!r.fit&&o.push(`paper=${r.paper}`),r.landscape&&!r.fit&&o.push("landscape")),o.length>0?`?${o.join("&")}`:""}function et(e,r,o={}){let c=Xe(o),u=c.baseUrl??Ye,s=Ze(r),h=Qe(e,c);return`${u}/${e}/${s}${h}`}function tt(e,r="svg",o={}){let c=C(),u={showTimings:!0,showKeys:!1,terminalWidth:80,colors:_},s=c.render(e,u);return et(r,s,o)}function se(e,r={}){return tt(e,"svg",r)}function ie(e){return{getDiagramUrl(r){if(e.provider==="mermaid-ink"){let{provider:o,...c}=e;return se(r,c)}return oe(r,{baseUrl:e.baseUrl})},countSteps(r){return V(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"}}}import{ok as z,err as ot}from"awaitly";function rt(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 ae(e,r={}){if(rt(e))return e;let{minOverlapMs:o=0,maxGapMs:c=5}=r,u=[],s=[];for(let i=0;i<e.length;i++){let d=e[i];d.type==="step"&&d.startTs!==void 0?u.push({node:d,startTs:d.startTs,endTs:d.endTs??d.startTs+(d.durationMs??0),originalIndex:i}):s.push({node:d,originalIndex:i})}if(u.length<=1)return e;u.sort((i,d)=>i.startTs-d.startTs);let h=[],m=[u[0]];for(let i=1;i<u.length;i++){let d=u[i],b=Math.min(...m.map(S=>S.startTs)),l=Math.max(...m.map(S=>S.endTs)),p=d.startTs<=b+c,f=d.startTs<l;if(!p&&!f){h.push(m),m=[d];continue}let w=f?Math.min(d.endTs,l)-d.startTs:0;p||w>=o?m.push(d):(h.push(m),m=[d])}h.push(m);let g=[];for(let i of h){let d=Math.min(...i.map(b=>b.originalIndex));if(i.length===1)g.push({node:i[0].node,position:d});else{let b=i.map(w=>w.node),l=Math.min(...i.map(w=>w.startTs)),p=Math.max(...i.map(w=>w.endTs)),f={type:"parallel",id:`detected_parallel_${l}`,name:`${b.length} parallel steps`,state:nt(b),mode:"all",children:b,startTs:l,endTs:p,durationMs:p-l};g.push({node:f,position:d})}}for(let{node:i,originalIndex:d}of s)g.push({node:i,position:d});return g.sort((i,d)=>i.position-d.position),g.map(i=>i.node)}function nt(e){return e.some(s=>s.state==="error")?"error":e.some(s=>s.state==="running")?"running":e.some(s=>s.state==="pending")?"pending":(e.every(s=>s.state==="success"||s.state==="cached"),"success")}function ce(e={}){let{detectParallel:r=!0,parallelDetection:o,enableSnapshots:c=!1,maxSnapshots:u=1e3}=e,s=c,h=A(),m,g,i,d="pending",b,l,p=new Map,f=[],w=[],S=new Map,R=[],x=Date.now(),k=x,I={onAfterStep:new Map},T,y=[],N=0;function M(t){return t.stepId??t.stepKey??t.name??A()}function D(t){if(f.length>0){f[f.length-1].children.push(t),k=Date.now();return}if(w.length>0){let a=w[w.length-1];for(let n of a.branches.values())if(n.taken){n.children.push(t),k=Date.now();return}a.pendingChildren.push(t),k=Date.now();return}R.push(t),k=Date.now()}function fe(t){if(!s)return;let a=j(),n=new Map;for(let[$,v]of p)n.set($,{id:v.id,name:v.name,key:v.key,startTs:v.startTs,retryCount:v.retryCount,timedOut:v.timedOut,timeoutMs:v.timeoutMs});let E={id:`snapshot_${N}`,eventIndex:N,event:structuredClone(t),ir:structuredClone(a),timestamp:Date.now(),activeSteps:n};y.push(E),y.length>u&&y.shift(),N++}function me(t){switch(t.type){case"workflow_start":{R=[],i=void 0,l=void 0,b=void 0,p.clear(),f.length=0,w.length=0,S.clear(),m=t.workflowId,g=t.ts,d="running",x=Date.now(),k=x,T!==void 0&&T!==t.workflowId&&(I.shouldRun=void 0,I.onBeforeStart=void 0),T=t.workflowId,I.onAfterStep=new Map;break}case"workflow_success":d="success",i=t.ts,l=t.durationMs,k=Date.now();break;case"workflow_error":d="error",i=t.ts,b=t.error,l=t.durationMs,k=Date.now();break;case"workflow_cancelled":d="aborted",i=t.ts,l=t.durationMs,k=Date.now();break;case"step_start":{let a=M(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=M(t),n=p.get(a);if(n){let E={type:"step",id:n.id,name:n.name,key:n.key,state:"success",startTs:n.startTs,endTs:t.ts,durationMs:t.durationMs,...n.retryCount>0&&{retryCount:n.retryCount},...n.timedOut&&{timedOut:!0,timeoutMs:n.timeoutMs},...n.metadata&&{metadata:n.metadata}};D(E),p.delete(a)}break}case"step_error":{let a=M(t),n=p.get(a);if(n){let E={type:"step",id:n.id,name:n.name,key:n.key,state:"error",startTs:n.startTs,endTs:t.ts,durationMs:t.durationMs,error:t.error,...n.retryCount>0&&{retryCount:n.retryCount},...n.timedOut&&{timedOut:!0,timeoutMs:n.timeoutMs},...n.metadata&&{metadata:n.metadata},...t.diagnostics&&{errorDiagnostics:t.diagnostics}};D(E),p.delete(a)}break}case"step_aborted":{let a=M(t),n=p.get(a);if(n){let E={type:"step",id:n.id,name:n.name,key:n.key,state:"aborted",startTs:n.startTs,endTs:t.ts,durationMs:t.durationMs,...n.retryCount>0&&{retryCount:n.retryCount},...n.timedOut&&{timedOut:!0,timeoutMs:n.timeoutMs},...n.metadata&&{metadata:n.metadata}};D(E),p.delete(a)}break}case"step_cache_hit":{let n={type:"step",id:M(t),name:t.name,key:t.stepKey,state:"cached",startTs:t.ts,endTs:t.ts,durationMs:0};D(n);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let a=M(t),n=p.get(a);n&&(n.timedOut=!0,n.timeoutMs=t.timeoutMs),k=Date.now();break}case"step_retry":{let a=M(t),n=p.get(a);n&&(n.retryCount=(t.attempt??1)-1),k=Date.now();break}case"step_retries_exhausted":k=Date.now();break;case"step_skipped":{let n={type:"step",id:M(t),name:t.name,key:t.stepKey,state:"skipped",startTs:t.ts,endTs:t.ts,durationMs:0,...t.metadata&&{metadata:t.metadata}};D(n);break}case"hook_should_run":{let a={type:"shouldRun",state:"success",ts:t.ts,durationMs:t.durationMs,context:{result:t.result,skipped:t.skipped}};I.shouldRun=a,T=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};I.shouldRun=a,T=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}};I.onBeforeStart=a,T=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};I.onBeforeStart=a,T=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}};I.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}};I.onAfterStep.set(t.stepKey,a),k=Date.now();break}case"stream_created":{let a=`${t.workflowId}:${t.namespace}`;S.set(a,{id:A(),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}`,n=S.get(a);n&&(n.writeCount++,n.finalPosition=Math.max(n.finalPosition,t.position)),k=Date.now();break}case"stream_read":{let a=`${t.workflowId}:${t.namespace}`,n=S.get(a);n&&n.readCount++,k=Date.now();break}case"stream_close":{let a=`${t.workflowId}:${t.namespace}`,n=S.get(a);if(n){n.streamState="closed",n.finalPosition=t.finalPosition;let E={type:"stream",id:n.id,namespace:n.namespace,state:"success",startTs:n.startTs,endTs:t.ts,durationMs:t.ts-n.startTs,writeCount:n.writeCount,readCount:n.readCount,finalPosition:t.finalPosition,streamState:"closed",backpressureOccurred:n.backpressureOccurred};D(E),S.delete(a)}k=Date.now();break}case"stream_error":{let a=`${t.workflowId}:${t.namespace}`,n=S.get(a);if(n){n.streamState="error";let E={type:"stream",id:n.id,namespace:n.namespace,state:"error",error:t.error,startTs:n.startTs,endTs:t.ts,durationMs:t.ts-n.startTs,writeCount:n.writeCount,readCount:n.readCount,finalPosition:t.position,streamState:"error",backpressureOccurred:n.backpressureOccurred};D(E),S.delete(a)}k=Date.now();break}case"stream_backpressure":{let a=`${t.workflowId}:${t.namespace}`,n=S.get(a);n&&(n.backpressureOccurred=!0),k=Date.now();break}}fe(t)}function ge(t){if(t.type==="scope_start")f.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=f.findIndex($=>$.id===t.scopeId);if(a===-1)return;for(;f.length>a+1;){let $=f.pop(),v=$.type==="race"?{type:"race",id:$.id,name:$.name,state:L($.children),startTs:$.startTs,endTs:t.ts,children:$.children}:{type:"parallel",id:$.id,name:$.name,state:L($.children),startTs:$.startTs,endTs:t.ts,children:$.children,mode:$.type==="allSettled"?"allSettled":"all"};f[f.length-1].children.push(v)}let[n]=f.splice(a,1),E=n.type==="race"?{type:"race",id:n.id,name:n.name,state:L(n.children),startTs:n.startTs,endTs:t.ts,durationMs:t.durationMs,children:n.children,winnerId:t.winnerId}:{type:"parallel",id:n.id,name:n.name,state:L(n.children),startTs:n.startTs,endTs:t.ts,durationMs:t.durationMs,children:n.children,mode:n.type==="allSettled"?"allSettled":"all"};D(E)}}function he(t){if(t.type==="decision_start")w.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=w.find(n=>n.id===t.decisionId);if(a){let n=t.branchLabel,E=a.branches.get(n);if(E)E.taken=t.taken,t.taken&&a.pendingChildren.length>0&&(E.children.unshift(...a.pendingChildren),a.pendingChildren=[]);else{let $=t.taken?[...a.pendingChildren]:[];t.taken&&(a.pendingChildren=[]),a.branches.set(n,{label:t.branchLabel,condition:t.condition,taken:t.taken,children:$})}k=Date.now()}}else if(t.type==="decision_end"){let a=w.findIndex(n=>n.id===t.decisionId);if(a!==-1){let[n]=w.splice(a,1),E=w.splice(a),$=Array.from(n.branches.values());$.length===0&&n.pendingChildren.length>0&&($=[{label:"default",taken:!0,children:[...n.pendingChildren]}]);let v=$.find(U=>U.taken)?.label,xe={type:"decision",id:n.id,name:n.name,state:L($.flatMap(U=>U.taken?U.children:[])),startTs:n.startTs,endTs:t.ts,durationMs:t.durationMs,condition:n.condition,decisionValue:n.decisionValue,branchTaken:t.branchTaken??v,branches:$};D(xe),w.push(...E),k=Date.now()}}}function L(t){return t.length===0?"success":t.some($=>$.state==="error")?"error":t.every($=>$.state==="success"||$.state==="cached")?"success":t.some($=>$.state==="running")?"running":"pending"}function ke(){let t=[...R];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 S)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=ke();r&&(t=ae(t,o));let a={type:"workflow",id:m??h,workflowId:m??h,state:d,startTs:g,endTs:i,durationMs:l,children:t,error:b},n=I.shouldRun!==void 0||I.onBeforeStart!==void 0||I.onAfterStep.size>0;return{root:a,metadata:{createdAt:x,lastUpdatedAt:k},...n&&{hooks:I}}}function we(){m=void 0,g=void 0,i=void 0,d="pending",b=void 0,l=void 0,p.clear(),f.length=0,w.length=0,S.clear(),R=[],x=Date.now(),k=x,I={onAfterStep:new Map},T=void 0,y.length=0,N=0}function be(){return[...y]}function ye(t){return y[t]}function Se(t){return y[t]?.ir}function $e(){y.length=0,N=0}return{handleEvent:me,handleScopeEvent:ge,handleDecisionEvent:he,getIR:j,reset:we,getSnapshots:be,getSnapshotAt:ye,getIRAt:Se,clearSnapshots:$e,get hasActiveSteps(){return p.size>0},get state(){return d},get snapshotCount(){return y.length},get snapshotsEnabled(){return s},setSnapshotsEnabled(t){s=t}}}var st=500,it=5e3;function de(e,r){let{title:o,debounceMs:c=st,maxWaitMs:u=it}=e,s,h=!0,m,g,i,d,b,l,p=z(void 0),f=ce({detectParallel:!0});function w(){i&&(clearTimeout(i),i=void 0),d&&(clearTimeout(d),d=void 0)}async function S(){if(!m||!h)return z(void 0);let N=m;g=N,m=void 0,w();try{return s?await r.updateExisting(s,N,o):s=await r.postNew(N,o),b=Date.now(),p=z(void 0),p}catch{return p=ot("CALLBACK_ERROR"),p}}function R(){i&&clearTimeout(i),i=setTimeout(()=>{S()},c);let N=b??l;if(!d&&N!==void 0){let M=Date.now()-N,D=Math.max(0,u-M);d=setTimeout(()=>{d=void 0,S()},D)}}function x(N){if(h){if(l===void 0&&(l=Date.now()),"root"in N)m=N,g=N;else{let M=N;M.type==="scope_start"||M.type==="scope_end"?f.handleScopeEvent(M):M.type==="decision_start"||M.type==="decision_branch"||M.type==="decision_end"?f.handleDecisionEvent(M):f.handleEvent(M),m=f.getIR(),g=m}R()}}async function k(N="completed"){if(!h)return;h=!1,w();let M=m??g??f.getIR();await r.finalize(s,M,o,N)}function I(){h&&(h=!1,w(),s&&r.cancel&&r.cancel(s))}function T(){return s}function y(){return h}return{update:x,finalize:k,cancel:I,getSessionId:T,isActive:y}}function dt(e){switch(e.root.state){case"success":return"completed";case"error":return"failed";case"aborted":return"cancelled";default:return"running"}}function le(e,r){let{diagramProvider:o,debounceMs:c=500,maxWaitMs:u=5e3}=e;if(!o)throw new Error(`${r.name}Notifier: diagramProvider is required. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }.`);let s=ie(o);async function h(g,i={}){let d=i.title??"Workflow",b=dt(g);try{let l=r.buildMessage({ir:g,title:d,status:b},s),p=await r.sendNew(l);return at(p?.toString())}catch{return ct("SEND_FAILED")}}function m(g){return de({...g,debounceMs:g.debounceMs??c,maxWaitMs:g.maxWaitMs??u},{async postNew(i,d){let b=r.buildMessage({ir:i,title:d,status:"running"},s);return(await r.sendNew(b))?.toString()},async updateExisting(i,d,b){let l=r.buildMessage({ir:d,title:b,status:"running"},s);await r.sendUpdate(i,l)},async finalize(i,d,b,l){let p=r.buildMessage({ir:d,title:b,status:l},s);i?await r.sendUpdate(i,p):await r.sendNew(p)},async cancel(i){r.sendCancel&&i&&await r.sendCancel(i)}})}return{notify:h,createLive:m,getType:()=>r.name.toLowerCase()}}import{ok as ue,err as G}from"awaitly";function pe(e){let{url:r,headers:o={},timeout:c=3e4,includeMermaid:u=!1,includeKrokiUrl:s,includeDiagramUrl:h=s??!0,providerName:m="kroki",metadata:g}=e,i=C(),d={showTimings:!0,showKeys:!1,terminalWidth:80,colors:_},b=0;async function l(f){let w=new AbortController,S=setTimeout(()=>w.abort(),c);try{let R=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",...o},body:JSON.stringify(f),signal:w.signal});if(!R.ok)return G("SEND_FAILED");try{let x=await R.json();return ue(x.messageId??x.id??f.messageId??"")}catch{return ue(f.messageId??"")}}catch(R){return R instanceof Error&&R.name==="AbortError"?G("TIMEOUT"):G("SEND_FAILED")}finally{clearTimeout(S)}}function p(){return`webhook-${++b}-${Date.now()}`}return{name:"Webhook",buildMessage({ir:f,title:w,status:S},R){let x;S==="running"?x="workflow.update":x="workflow.complete";let k={event:x,timestamp:new Date().toISOString(),title:w,status:S,ir:f,metadata:g};if(h){let I=R.getDiagramUrl(f);k.diagramUrl=I,k.diagramProvider=m,k.krokiUrl=I}return u&&(k.mermaid=i.render(f,d)),{payload:k}},async sendNew(f){let{payload:w}=f,S=p();w.messageId=S;let R=await l(w);if(!R.ok)throw new Error(`Webhook send failed: ${R.error}`);return S},async sendUpdate(f,w){let{payload:S}=w;S.messageId=f;let R=await l(S);if(!R.ok)throw new Error(`Webhook update failed: ${R.error}`)}}}function lr(e){let{url:r,headers:o,timeout:c,includeMermaid:u,includeKrokiUrl:s,includeDiagramUrl:h,diagramProvider:m,...g}=e,i=pe({url:r,headers:o,timeout:c,includeMermaid:u,includeKrokiUrl:s,includeDiagramUrl:h,providerName:m?.provider??"kroki"});return le({...g,diagramProvider:m},i)}export{lr as createWebhookNotifier};
3
3
  //# sourceMappingURL=webhook.js.map