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