awaitly-visualizer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/index.browser.cjs +1677 -0
  2. package/dist/index.browser.cjs.map +1 -0
  3. package/dist/index.browser.d.cts +166 -0
  4. package/dist/index.browser.d.ts +166 -0
  5. package/dist/index.browser.js +1677 -0
  6. package/dist/index.browser.js.map +1 -0
  7. package/dist/index.cjs +1680 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.d.cts +242 -0
  10. package/dist/index.d.ts +242 -0
  11. package/dist/index.js +1680 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/kroki/fetch.cjs +3 -0
  14. package/dist/kroki/fetch.cjs.map +1 -0
  15. package/dist/kroki/fetch.d.cts +86 -0
  16. package/dist/kroki/fetch.d.ts +86 -0
  17. package/dist/kroki/fetch.js +3 -0
  18. package/dist/kroki/fetch.js.map +1 -0
  19. package/dist/notifiers/discord.cjs +3 -0
  20. package/dist/notifiers/discord.cjs.map +1 -0
  21. package/dist/notifiers/discord.d.cts +70 -0
  22. package/dist/notifiers/discord.d.ts +70 -0
  23. package/dist/notifiers/discord.js +3 -0
  24. package/dist/notifiers/discord.js.map +1 -0
  25. package/dist/notifiers/slack.cjs +38 -0
  26. package/dist/notifiers/slack.cjs.map +1 -0
  27. package/dist/notifiers/slack.d.cts +95 -0
  28. package/dist/notifiers/slack.d.ts +95 -0
  29. package/dist/notifiers/slack.js +38 -0
  30. package/dist/notifiers/slack.js.map +1 -0
  31. package/dist/notifiers/webhook.cjs +3 -0
  32. package/dist/notifiers/webhook.cjs.map +1 -0
  33. package/dist/notifiers/webhook.d.cts +115 -0
  34. package/dist/notifiers/webhook.d.ts +115 -0
  35. package/dist/notifiers/webhook.js +3 -0
  36. package/dist/notifiers/webhook.js.map +1 -0
  37. package/dist/performance-analyzer-B5VF5b1F.d.ts +663 -0
  38. package/dist/performance-analyzer-BNwE4AiO.d.cts +663 -0
  39. package/dist/types-BIZSmXif.d.ts +350 -0
  40. package/dist/types-BnWc9Wlr.d.cts +350 -0
  41. package/dist/url-PkfQz4V5.d.cts +750 -0
  42. package/dist/url-PkfQz4V5.d.ts +750 -0
  43. package/package.json +105 -0
@@ -0,0 +1,70 @@
1
+ import { B as BaseNotifierOptions, P as ProviderOptions, N as Notifier } from '../types-BnWc9Wlr.cjs';
2
+ import 'awaitly';
3
+ import 'awaitly/workflow';
4
+ import '../url-PkfQz4V5.cjs';
5
+ import 'awaitly/core';
6
+
7
+ /**
8
+ * Discord Notifier
9
+ *
10
+ * Discord webhook notifier for pushing workflow visualizations.
11
+ * Uses plain HTTP webhooks - no Discord SDK required.
12
+ */
13
+
14
+ /**
15
+ * Options for Discord notifier.
16
+ */
17
+ interface DiscordNotifierOptions extends BaseNotifierOptions {
18
+ /** Discord webhook URL */
19
+ webhookUrl: string;
20
+ /** Bot username to display (optional) */
21
+ username?: string;
22
+ /** Bot avatar URL (optional) */
23
+ avatarUrl?: string;
24
+ /** Request timeout in milliseconds (default: 30000) */
25
+ timeout?: number;
26
+ /**
27
+ * Diagram rendering provider configuration.
28
+ * REQUIRED - no silent default to prevent surprise network calls.
29
+ */
30
+ diagramProvider: ProviderOptions;
31
+ }
32
+ /**
33
+ * Create a Discord notifier.
34
+ *
35
+ * @param options - Discord configuration
36
+ * @returns A Notifier instance
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { createDiscordNotifier } from 'awaitly-visualizer/notifiers/discord';
41
+ *
42
+ * // Using Kroki (default)
43
+ * const discord = createDiscordNotifier({
44
+ * webhookUrl: process.env.DISCORD_WEBHOOK!,
45
+ * username: 'Workflow Bot',
46
+ * diagramProvider: { provider: 'kroki' },
47
+ * });
48
+ *
49
+ * // Using mermaid.ink with dark theme
50
+ * const discordDark = createDiscordNotifier({
51
+ * webhookUrl: process.env.DISCORD_WEBHOOK!,
52
+ * diagramProvider: {
53
+ * provider: 'mermaid-ink',
54
+ * theme: 'dark',
55
+ * bgColor: '1b1b1f',
56
+ * },
57
+ * });
58
+ *
59
+ * // One-time notification
60
+ * await discord.notify(workflowIR, { title: 'Order Processing' });
61
+ *
62
+ * // Live updates
63
+ * const live = discord.createLive({ title: 'Order #123' });
64
+ * workflow.on('event', (e) => live.update(e));
65
+ * await live.finalize();
66
+ * ```
67
+ */
68
+ declare function createDiscordNotifier(options: DiscordNotifierOptions): Notifier;
69
+
70
+ export { type DiscordNotifierOptions, createDiscordNotifier };
@@ -0,0 +1,70 @@
1
+ import { B as BaseNotifierOptions, P as ProviderOptions, N as Notifier } from '../types-BIZSmXif.js';
2
+ import 'awaitly';
3
+ import 'awaitly/workflow';
4
+ import '../url-PkfQz4V5.js';
5
+ import 'awaitly/core';
6
+
7
+ /**
8
+ * Discord Notifier
9
+ *
10
+ * Discord webhook notifier for pushing workflow visualizations.
11
+ * Uses plain HTTP webhooks - no Discord SDK required.
12
+ */
13
+
14
+ /**
15
+ * Options for Discord notifier.
16
+ */
17
+ interface DiscordNotifierOptions extends BaseNotifierOptions {
18
+ /** Discord webhook URL */
19
+ webhookUrl: string;
20
+ /** Bot username to display (optional) */
21
+ username?: string;
22
+ /** Bot avatar URL (optional) */
23
+ avatarUrl?: string;
24
+ /** Request timeout in milliseconds (default: 30000) */
25
+ timeout?: number;
26
+ /**
27
+ * Diagram rendering provider configuration.
28
+ * REQUIRED - no silent default to prevent surprise network calls.
29
+ */
30
+ diagramProvider: ProviderOptions;
31
+ }
32
+ /**
33
+ * Create a Discord notifier.
34
+ *
35
+ * @param options - Discord configuration
36
+ * @returns A Notifier instance
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { createDiscordNotifier } from 'awaitly-visualizer/notifiers/discord';
41
+ *
42
+ * // Using Kroki (default)
43
+ * const discord = createDiscordNotifier({
44
+ * webhookUrl: process.env.DISCORD_WEBHOOK!,
45
+ * username: 'Workflow Bot',
46
+ * diagramProvider: { provider: 'kroki' },
47
+ * });
48
+ *
49
+ * // Using mermaid.ink with dark theme
50
+ * const discordDark = createDiscordNotifier({
51
+ * webhookUrl: process.env.DISCORD_WEBHOOK!,
52
+ * diagramProvider: {
53
+ * provider: 'mermaid-ink',
54
+ * theme: 'dark',
55
+ * bgColor: '1b1b1f',
56
+ * },
57
+ * });
58
+ *
59
+ * // One-time notification
60
+ * await discord.notify(workflowIR, { title: 'Order Processing' });
61
+ *
62
+ * // Live updates
63
+ * const live = discord.createLive({ title: 'Order #123' });
64
+ * workflow.on('event', (e) => live.update(e));
65
+ * await live.finalize();
66
+ * ```
67
+ */
68
+ declare function createDiscordNotifier(options: DiscordNotifierOptions): Notifier;
69
+
70
+ export { type DiscordNotifierOptions, createDiscordNotifier };
@@ -0,0 +1,3 @@
1
+ import{ok as it,err as at}from"awaitly";function V(e){function r(n){let d=0;for(let l of n)if(l.type==="step")d++;else if(l.type==="decision"&&l.branches)for(let i of l.branches)i.taken&&(d+=r(i.children));else"children"in l&&l.children&&(d+=r(l.children));return d}return r(e.root.children)}import{ok as $t,err as xt}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 _(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 xe="\x1B[2m",Re="\x1B[31m",Ie="\x1B[32m",Ee="\x1B[33m",Ne="\x1B[34m",Q="\x1B[90m",Me="\x1B[37m";var W={pending:Me,running:Ee,success:Ie,error:Re,aborted:Q,cached:Ne,skipped:xe+Q};import{ok as Te,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 Oe(){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 ve(){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 We(){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 Ce(e){try{return Te(JSON.stringify(e,(n,d)=>{if(typeof d!="bigint")return d;let l=Number(d);return Number.isSafeInteger(l)?l:d.toString()}))}catch{return De("STRINGIFY_ERROR")}}function te(e){let r=Ce(e);return r.ok?r.value:"[unserializable]"}function Pe(e,r,n){let d;if(e.shouldRun){let l="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(` ${l}[["${m} shouldRun${g}${f}"]]:::${i}`),d=l}if(e.onBeforeStart){let l="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(` ${l}[["${m} onBeforeStart${g}${f}"]]:::${i}`),d&&r.push(` ${d} --> ${l}`),d=l}return{lastHookId:d}}var re=0,F=new Set,B=new Set;function C(e="node"){return`${e}_${++re}`}function Le(){re=0,F.clear(),B.clear()}function T(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function ne(e){return T(e).replace(/[{}[\]()]/g,"")}function L(){return{name:"mermaid",supportsLive:!1,render(e,r){Le();let n=[],d=r;n.push("flowchart TD");let l;e.hooks&&(l=Pe(e.hooks,n,r).lastHookId);let i="start";n.push(` ${i}(("\u25B6 Start"))`),l&&n.push(` ${l} --> ${i}`);let m=i;for(let g of e.root.children){let s=H(g,r,n,d,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",c=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",w=`(("${s} ${c}"))`,u=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";n.push(` ${g}${w}${u}`),n.push(` ${m} --> ${g}`)}return n.push(""),n.push(...Oe()),d.showHeatmap&&n.push(...ve()),e.hooks&&n.push(...We()),n.join(`
2
+ `)}}}function H(e,r,n,d,l){if(q(e))return Ue(e,r,n,d,l);if(J(e))return Ae(e,r,n,d,l);if(Y(e))return Fe(e,r,n,d,l);if(Z(e))return Be(e,r,n,d,l);if(X(e))return He(e,r,n);let i=C("unknown");return n.push(` ${i}["Unknown Node"]`),{entryId:i,exitId:i}}function Ue(e,r,n,d,l){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(B.has(s)){let b=2;for(;B.has(`${s}_${b}`);)b++;s=`${s}_${b}`}B.add(s);let c=e.name??e.key??"Step",w=r.showKeys&&e.key&&e.name?`${c} [${e.key}]`:c,u=T(w),p=r.showTimings&&e.durationMs!==void 0?` ${_(e.durationMs)}`:"",h="";switch(e.state){case"success":h="\u2713 ";break;case"error":h="\u2717 ";break;case"cached":h="\u{1F4BE} ";break;case"running":h="\u23F3 ";break;case"skipped":h="\u2298 ";break}let y="";if(e.input!==void 0){let b=typeof e.input=="string"?T(e.input):T(te(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(te(e.output).slice(0,20));y+=`\\nout: ${b}`}let x="",D=e.key??e.id;if(l&&D&&l.onAfterStep.has(D)){let b=l.onAfterStep.get(D),$=b.state==="success"?"\u2699":"\u26A0",R=r.showTimings&&b.durationMs!==void 0?` ${_(b.durationMs)}`:"";x=`\\n${$} hook${R}`}let I=(h+u+y+x+p).trim(),k,E=d?.showHeatmap&&d.heatmapData?d.heatmapData.heat.get(e.key??"")??d.heatmapData.heat.get(e.name??"")??d.heatmapData.heat.get(e.id):void 0;if(E!==void 0){let b=ee(E);k=_e(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 Ae(e,r,n,d,l){let i=C("parallel"),m=`${i}_fork`,f=`${i}_join`,g=ne(e.name??"Parallel"),s=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let u=i,p=T(`${g}${s}`),h="operations not individually tracked",y=r.showTimings&&e.durationMs!==void 0?` ${_(e.durationMs)}`:"";return n.push(` ${u}["${p}${y}\\n${h}"]:::${e.state}`),{entryId:u,exitId:u}}n.push(` subgraph ${i}["${g}${s}"]`),n.push(" direction TB"),n.push(` ${m}{"\u26A1 Fork"}`);let c=[];for(let u of e.children){let p=H(u,r,n,d,l);n.push(` ${m} --> ${p.entryId}`),c.push(p.exitId)}n.push(` ${f}{"\u2713 Join"}`);for(let u of c)n.push(` ${u} --> ${f}`);n.push(" end");let w=e.state;return n.push(` class ${i} ${w}`),{entryId:m,exitId:f}}function Fe(e,r,n,d,l){let i=C("race"),m=`${i}_start`,f=`${i}_end`,g=ne(e.name??"Race");if(e.children.length===0){let u=i,p=T(g),h="operations not individually tracked",y=r.showTimings&&e.durationMs!==void 0?` ${_(e.durationMs)}`:"";return n.push(` ${u}["\u26A1 ${p}${y}\\n${h}"]:::${e.state}`),{entryId:u,exitId:u}}n.push(` subgraph ${i}["\u26A1 ${g}"]`),n.push(" direction TB"),n.push(` ${m}(("\u{1F3C1} Start"))`);let s=[],c;for(let u of e.children){let p=H(u,r,n,d,l),h=e.winnerId===u.id;n.push(` ${m} --> ${p.entryId}`),h&&(c=p.exitId),s.push({exitId:p.exitId,isWinner:h})}n.push(` ${f}(("\u2713 First"))`);for(let{exitId:u,isWinner:p}of s)p&&c?n.push(` ${u} ==>|\u{1F3C6} Winner| ${f}`):e.winnerId?n.push(` ${u} -. cancelled .-> ${f}`):n.push(` ${u} --> ${f}`);n.push(" end");let w=e.state;return n.push(` class ${i} ${w}`),{entryId:m,exitId:f}}function Be(e,r,n,d,l){let i=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:C("decision");if(F.has(i)){let u=2;for(;F.has(`${i}_${u}`);)u++;i=`${i}_${u}`}F.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=[],c,w=new Set;for(let u of e.branches){let p=`${i}_${u.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(u.label),y=u.taken?`${h} \u2713`:`${h} skipped`,x=u.taken?":::success":":::skipped";n.push(` ${p}["${y}"]${x}`);let D=u.condition?`|${T(u.condition).replace(/\|/g,"")}|`:"";if(n.push(` ${i} -->${D} ${p}`),u.children.length>0){let I=p;for(let k of u.children){let E=H(k,r,n,d,l);n.push(` ${I} --> ${E.entryId}`),I=E.exitId}s.push(I),u.taken&&(c=I)}else s.push(p),u.taken&&(c=p)}return c?{entryId:i,exitId:c}:{entryId:i,exitId:i}}function He(e,r,n){let d=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${C("")}`,l=`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${l}${f}${m}`,s;return e.streamState==="error"?s="streamError":e.streamState==="active"?s="streamActive":s="stream",n.push(` ${d}{{"${g}"}}:::${s}`),{entryId:d,exitId:d}}import Ke from"pako";var ze=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function Ge(e){let r;if(ze)r=globalThis.Buffer.from(e).toString("base64");else{let n="";for(let d=0;d<e.length;d++)n+=String.fromCharCode(e[d]);r=btoa(n)}return r.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function K(e){let n=new TextEncoder().encode(e),d=Ke.deflate(n);return Ge(d)}var je="https://kroki.io";function Ve(e,r,n,d={}){let l=d.baseUrl??je,i=K(n);return`${l}/${e}/${r}/${i}`}function qe(e,r="svg",n={}){let d=L(),l={showTimings:!0,showKeys:!1,terminalWidth:80,colors:W},i=d.render(e,l);return Ve("mermaid",r,i,n)}function oe(e,r={}){return qe(e,"svg",r)}var Je="https://mermaid.ink";function Ye(e){return`pako:${K(e)}`}function Ze(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 Xe(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 Qe(e,r,n={}){let d=Ze(n),l=d.baseUrl??Je,i=Ye(r),m=Xe(e,d);return`${l}/${e}/${i}${m}`}function et(e,r="svg",n={}){let d=L(),l={showTimings:!0,showKeys:!1,terminalWidth:80,colors:W},i=d.render(e,l);return Qe(r,i,n)}function se(e,r={}){return et(e,"svg",r)}function ie(e){return{getDiagramUrl(r){if(e.provider==="mermaid-ink"){let{provider:n,...d}=e;return se(r,d)}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 nt}from"awaitly";function tt(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(tt(e))return e;let{minOverlapMs:n=0,maxGapMs:d=5}=r,l=[],i=[];for(let s=0;s<e.length;s++){let c=e[s];c.type==="step"&&c.startTs!==void 0?l.push({node:c,startTs:c.startTs,endTs:c.endTs??c.startTs+(c.durationMs??0),originalIndex:s}):i.push({node:c,originalIndex:s})}if(l.length<=1)return e;l.sort((s,c)=>s.startTs-c.startTs);let m=[],f=[l[0]];for(let s=1;s<l.length;s++){let c=l[s],w=Math.min(...f.map(x=>x.startTs)),u=Math.max(...f.map(x=>x.endTs)),p=c.startTs<=w+d,h=c.startTs<u;if(!p&&!h){m.push(f),f=[c];continue}let y=h?Math.min(c.endTs,u)-c.startTs:0;p||y>=n?f.push(c):(m.push(f),f=[c])}m.push(f);let g=[];for(let s of m){let c=Math.min(...s.map(w=>w.originalIndex));if(s.length===1)g.push({node:s[0].node,position:c});else{let w=s.map(y=>y.node),u=Math.min(...s.map(y=>y.startTs)),p=Math.max(...s.map(y=>y.endTs)),h={type:"parallel",id:`detected_parallel_${u}`,name:`${w.length} parallel steps`,state:rt(w),mode:"all",children:w,startTs:u,endTs:p,durationMs:p-u};g.push({node:h,position:c})}}for(let{node:s,originalIndex:c}of i)g.push({node:s,position:c});return g.sort((s,c)=>s.position-c.position),g.map(s=>s.node)}function rt(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 ce(e={}){let{detectParallel:r=!0,parallelDetection:n,enableSnapshots:d=!1,maxSnapshots:l=1e3}=e,i=d,m=A(),f,g,s,c="pending",w,u,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??A()}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 pe(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>l&&b.shift(),$++}function fe(t){switch(t.type){case"workflow_start":{D=[],s=void 0,u=void 0,w=void 0,p.clear(),h.length=0,y.length=0,x.clear(),f=t.workflowId,g=t.ts,c="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":c="success",s=t.ts,u=t.durationMs,k=Date.now();break;case"workflow_error":c="error",s=t.ts,w=t.error,u=t.durationMs,k=Date.now();break;case"workflow_cancelled":c="aborted",s=t.ts,u=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: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=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}}pe(t)}function me(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:P(S.children),startTs:S.startTs,endTs:t.ts,children:S.children}:{type:"parallel",id:S.id,name:S.name,state:P(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:P(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:P(o.children),startTs:o.startTs,endTs:t.ts,durationMs:t.durationMs,children:o.children,mode:o.type==="allSettled"?"allSettled":"all"};O(N)}}function ge(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(U=>U.taken)?.label,$e={type:"decision",id:o.id,name:o.name,state:P(S.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:S};O($e),y.push(...N),k=Date.now()}}}function P(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 he(){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=he();r&&(t=ae(t,n));let a={type:"workflow",id:f??m,workflowId:f??m,state:c,startTs:g,endTs:s,durationMs:u,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 ke(){f=void 0,g=void 0,s=void 0,c="pending",w=void 0,u=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 we(){return[...b]}function be(t){return b[t]}function ye(t){return b[t]?.ir}function Se(){b.length=0,$=0}return{handleEvent:fe,handleScopeEvent:me,handleDecisionEvent:ge,getIR:j,reset:ke,getSnapshots:we,getSnapshotAt:be,getIRAt:ye,clearSnapshots:Se,get hasActiveSteps(){return p.size>0},get state(){return c},get snapshotCount(){return b.length},get snapshotsEnabled(){return i},setSnapshotsEnabled(t){i=t}}}var ot=500,st=5e3;function de(e,r){let{title:n,debounceMs:d=ot,maxWaitMs:l=st}=e,i,m=!0,f,g,s,c,w,u,p=z(void 0),h=ce({detectParallel:!0});function y(){s&&(clearTimeout(s),s=void 0),c&&(clearTimeout(c),c=void 0)}async function x(){if(!f||!m)return z(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=z(void 0),p}catch{return p=nt("CALLBACK_ERROR"),p}}function D(){s&&clearTimeout(s),s=setTimeout(()=>{x()},d);let $=w??u;if(!c&&$!==void 0){let R=Date.now()-$,O=Math.max(0,l-R);c=setTimeout(()=>{c=void 0,x()},O)}}function I($){if(m){if(u===void 0&&(u=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 ct(e){switch(e.root.state){case"success":return"completed";case"error":return"failed";case"aborted":return"cancelled";default:return"running"}}function ue(e,r){let{diagramProvider:n,debounceMs:d=500,maxWaitMs:l=5e3}=e;if(!n)throw new Error(`${r.name}Notifier: diagramProvider is required. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }.`);let i=ie(n);async function m(g,s={}){let c=s.title??"Workflow",w=ct(g);try{let u=r.buildMessage({ir:g,title:c,status:w},i),p=await r.sendNew(u);return it(p?.toString())}catch{return at("SEND_FAILED")}}function f(g){return de({...g,debounceMs:g.debounceMs??d,maxWaitMs:g.maxWaitMs??l},{async postNew(s,c){let w=r.buildMessage({ir:s,title:c,status:"running"},i);return(await r.sendNew(w))?.toString()},async updateExisting(s,c,w){let u=r.buildMessage({ir:c,title:w,status:"running"},i);await r.sendUpdate(s,u)},async finalize(s,c,w,u){let p=r.buildMessage({ir:c,title:w,status:u},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()}}import{ok as dt,err as G}from"awaitly";var ut={running:3447003,completed:3066993,failed:15158332,cancelled:9807270};function le(e){let{webhookUrl:r,username:n,avatarUrl:d,timeout:l=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(),l);try{let c=f?`${r}/messages/${f}`:`${r}?wait=true`,u=await fetch(c,{method:f?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m),signal:g.signal});if(!u.ok)return G("SEND_FAILED");let p=await u.json();return dt(p.id)}catch(c){return c instanceof Error&&c.name==="AbortError"?G("TIMEOUT"):G("SEND_FAILED")}finally{clearTimeout(s)}}return{name:"Discord",buildMessage({ir:m,title:f,status:g},s){let c={title:f,color:ut[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:d,embeds:[c]}},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 ur(e){let{webhookUrl:r,username:n,avatarUrl:d,timeout:l,...i}=e,m=le({webhookUrl:r,username:n,avatarUrl:d,timeout:l});return ue(i,m)}export{ur as createDiscordNotifier};
3
+ //# sourceMappingURL=discord.js.map