awaitly-visualizer 24.0.0 → 26.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 { W as WorkflowStatus, B as BaseNotifierOptions, P as ProviderOptions, N as Notifier } from '../types-
|
|
2
|
-
import { W as WorkflowIR } from '../url-
|
|
1
|
+
import { W as WorkflowStatus, B as BaseNotifierOptions, P as ProviderOptions, N as Notifier } from '../types-Cxa5QZ0j.cjs';
|
|
2
|
+
import { W as WorkflowIR } from '../url-DD8-D8H4.cjs';
|
|
3
3
|
import 'awaitly';
|
|
4
4
|
import 'awaitly/workflow';
|
|
5
|
-
import 'awaitly/core';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Webhook Adapter
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { W as WorkflowStatus, B as BaseNotifierOptions, P as ProviderOptions, N as Notifier } from '../types-
|
|
2
|
-
import { W as WorkflowIR } from '../url-
|
|
1
|
+
import { W as WorkflowStatus, B as BaseNotifierOptions, P as ProviderOptions, N as Notifier } from '../types-J_mgQ3lz.js';
|
|
2
|
+
import { W as WorkflowIR } from '../url-DD8-D8H4.js';
|
|
3
3
|
import 'awaitly';
|
|
4
4
|
import 'awaitly/workflow';
|
|
5
|
-
import 'awaitly/core';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Webhook Adapter
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{ok as at,err as ct}from"awaitly";function
|
|
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};
|
|
1
|
+
import{ok as at,err as ct}from"awaitly";function q(e){function r(s){let c=0;for(let u of s)if(u.type==="step")c++;else if(u.type==="decision"&&u.branches)for(let i of u.branches)i.taken&&(c+=r(i.children));else"children"in u&&u.children&&(c+=r(u.children));return c}return r(e.root.children)}import{ok as St,err as $t}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 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),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 Ie="\x1B[2m",Re="\x1B[31m",Me="\x1B[32m",Ne="\x1B[33m",Ee="\x1B[34m",ee="\x1B[90m",Te="\x1B[37m";var _={pending:Te,running:Ne,success:Me,error:Re,aborted:ee,cached:Ee,skipped:Ie+ee};import{ok as Oe,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 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,(s,c)=>{if(typeof c!="bigint")return c;let u=Number(c);return Number.isSafeInteger(u)?u:c.toString()}))}catch{return De("STRINGIFY_ERROR")}}function re(e){let r=Pe(e);return r.ok?r.value:"[unserializable]"}function Le(e,r,s){let c;if(e.shouldRun){let u="hook_shouldRun",i=e.shouldRun.state==="success"?"hook_success":"hook_error",h=e.shouldRun.state==="success"?"\u2699":"\u26A0",m=s.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}"]]:::${i}`),c=u}if(e.onBeforeStart){let u="hook_beforeStart",i=e.onBeforeStart.state==="success"?"hook_success":"hook_error",h=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",m=s.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${W(e.onBeforeStart.durationMs)}`:"",g=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";r.push(` ${u}[["${h} onBeforeStart${g}${m}"]]:::${i}`),c&&r.push(` ${c} --> ${u}`),c=u}return{lastHookId:c}}var ne=0,B=new Set,H=new Set;function P(e="node"){return`${e}_${++ne}`}function Ue(){ne=0,B.clear(),H.clear()}function O(e){return e.replace(/"/g,"#quot;").replace(/</g,"<").replace(/>/g,">").trim()}function oe(e){return O(e).replace(/[{}[\]()]/g,"")}function C(){return{name:"mermaid",supportsLive:!1,render(e,r){Ue();let s=[],c=r;s.push("flowchart TD");let u;e.hooks&&(u=Le(e.hooks,s,r).lastHookId);let i="start";s.push(` ${i}(("\u25B6 Start"))`),u&&s.push(` ${u} --> ${i}`);let h=i;for(let g of e.root.children){let a=K(g,r,s,c,e.hooks);s.push(` ${h} --> ${a.entryId}`),h=a.exitId}if(["success","error","aborted"].includes(e.root.state)){let g="finish",a=e.root.state==="success"?"\u2713":e.root.state==="error"?"\u2717":"\u2298",d=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",b=`(("${a} ${d}"))`,l=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";s.push(` ${g}${b}${l}`),s.push(` ${h} --> ${g}`)}return s.push(""),s.push(...ve()),c.showHeatmap&&s.push(...We()),e.hooks&&s.push(...Ce()),s.join(`
|
|
2
|
+
`)}}}function K(e,r,s,c,u){if(J(e))return Ae(e,r,s,c,u);if(Y(e))return Fe(e,r,s,c,u);if(Z(e))return Be(e,r,s,c,u);if(X(e))return He(e,r,s,c,u);if(Q(e))return Ke(e,r,s);let i=P("unknown");return s.push(` ${i}["Unknown Node"]`),{entryId:i,exitId:i}}function Ae(e,r,s,c,u){let i=r,h=i.showRetryEdges??!0,m=i.showErrorEdges??!0,g=i.showTimeoutEdges??!0,a=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:P("step");if(H.has(a)){let y=2;for(;H.has(`${a}_${y}`);)y++;a=`${a}_${y}`}H.add(a);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(re(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(re(e.output).slice(0,20));w+=`\\nout: ${y}`}let S="",I=e.key??e.id;if(u&&I&&u.onAfterStep.has(I)){let y=u.onAfterStep.get(I),M=y.state==="success"?"\u2699":"\u26A0",N=r.showTimings&&y.durationMs!==void 0?` ${W(y.durationMs)}`:"";S=`\\n${M} hook${N}`}let x=(f+l+w+S+p).trim(),k,R=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(R!==void 0){let y=te(R);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(s.push(` ${a}${T}:::${k}`),h&&e.retryCount!==void 0&&e.retryCount>0){let y=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;s.push(` ${a} -.->|"${y}"| ${a}`)}if(m&&e.state==="error"&&e.error!==void 0){let y=`ERR_${a}`,M=O(String(e.error)).slice(0,30);s.push(` ${y}{{"${M}"}}`),s.push(` ${a} -->|error| ${y}`),s.push(` style ${y} fill:#fee2e2,stroke:#dc2626`)}if(g&&e.timedOut){let y=`TO_${a}`,M=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";s.push(` ${y}{{"\u23F1 Timeout ${M}"}}`),s.push(` ${a} -.->|timeout| ${y}`),s.push(` style ${y} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:a,exitId:a}}function Fe(e,r,s,c,u){let i=P("parallel"),h=`${i}_fork`,m=`${i}_join`,g=oe(e.name??"Parallel"),a=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let l=i,p=O(`${g}${a}`),f="operations not individually tracked",w=r.showTimings&&e.durationMs!==void 0?` ${W(e.durationMs)}`:"";return s.push(` ${l}["${p}${w}\\n${f}"]:::${e.state}`),{entryId:l,exitId:l}}s.push(` subgraph ${i}["${g}${a}"]`),s.push(" direction TB"),s.push(` ${h}{"\u26A1 Fork"}`);let d=[];for(let l of e.children){let p=K(l,r,s,c,u);s.push(` ${h} --> ${p.entryId}`),d.push(p.exitId)}s.push(` ${m}{"\u2713 Join"}`);for(let l of d)s.push(` ${l} --> ${m}`);s.push(" end");let b=e.state;return s.push(` class ${i} ${b}`),{entryId:h,exitId:m}}function Be(e,r,s,c,u){let i=P("race"),h=`${i}_start`,m=`${i}_end`,g=oe(e.name??"Race");if(e.children.length===0){let l=i,p=O(g),f="operations not individually tracked",w=r.showTimings&&e.durationMs!==void 0?` ${W(e.durationMs)}`:"";return s.push(` ${l}["\u26A1 ${p}${w}\\n${f}"]:::${e.state}`),{entryId:l,exitId:l}}s.push(` subgraph ${i}["\u26A1 ${g}"]`),s.push(" direction TB"),s.push(` ${h}(("\u{1F3C1} Start"))`);let a=[],d;for(let l of e.children){let p=K(l,r,s,c,u),f=e.winnerId===l.id;s.push(` ${h} --> ${p.entryId}`),f&&(d=p.exitId),a.push({exitId:p.exitId,isWinner:f})}s.push(` ${m}(("\u2713 First"))`);for(let{exitId:l,isWinner:p}of a)p&&d?s.push(` ${l} ==>|\u{1F3C6} Winner| ${m}`):e.winnerId?s.push(` ${l} -. cancelled .-> ${m}`):s.push(` ${l} --> ${m}`);s.push(" end");let b=e.state;return s.push(` class ${i} ${b}`),{entryId:h,exitId:m}}function He(e,r,s,c,u){let i=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:P("decision");if(B.has(i)){let l=2;for(;B.has(`${i}_${l}`);)l++;i=`${i}_${l}`}B.add(i);let h=O(e.condition??"condition"),m=e.decisionValue!==void 0?` = ${O(String(e.decisionValue)).slice(0,30)}`:"",g=`${h}${m}`.trim();s.push(` ${i}{"${g}"}`);let a=[],d,b=new Set;for(let l of e.branches){let p=`${i}_${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";s.push(` ${p}["${w}"]${S}`);let I=l.condition?`|${O(l.condition).replace(/\|/g,"")}|`:"";if(s.push(` ${i} -->${I} ${p}`),l.children.length>0){let x=p;for(let k of l.children){let R=K(k,r,s,c,u);s.push(` ${x} --> ${R.entryId}`),x=R.exitId}a.push(x),l.taken&&(d=x)}else a.push(p),l.taken&&(d=p)}return d?{entryId:i,exitId:d}:{entryId:i,exitId:i}}function Ke(e,r,s){let c=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${P("")}`,u=`W:${e.writeCount} R:${e.readCount}`,i="";switch(e.streamState){case"active":i="\u27F3 ";break;case"closed":i="\u2713 ";break;case"error":i="\u2717 ";break}let h=r.showTimings&&e.durationMs!==void 0?` ${W(e.durationMs)}`:"",m=e.backpressureOccurred?"\\nbackpressure":"",g=`${i}stream:${O(e.namespace)}\\n${u}${m}${h}`,a;return e.streamState==="error"?a="streamError":e.streamState==="active"?a="streamActive":a="stream",s.push(` ${c}{{"${g}"}}:::${a}`),{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 s="";for(let c=0;c<e.length;c++)s+=String.fromCharCode(e[c]);r=btoa(s)}return r.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function z(e){let s=new TextEncoder().encode(e),c=ze.deflate(s);return je(c)}var Ve="https://kroki.io";function qe(e,r,s,c={}){let u=c.baseUrl??Ve,i=z(s);return`${u}/${e}/${r}/${i}`}function Je(e,r="svg",s={}){let c=C(),u={showTimings:!0,showKeys:!1,terminalWidth:80,colors:_},i=c.render(e,u);return qe("mermaid",r,i,s)}function se(e,r={}){return Je(e,"svg",r)}var Ye="https://mermaid.ink";function Ze(e){return`pako:${z(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 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 et(e,r,s={}){let c=Xe(s),u=c.baseUrl??Ye,i=Ze(r),h=Qe(e,c);return`${u}/${e}/${i}${h}`}function tt(e,r="svg",s={}){let c=C(),u={showTimings:!0,showKeys:!1,terminalWidth:80,colors:_},i=c.render(e,u);return et(r,i,s)}function ie(e,r={}){return tt(e,"svg",r)}function ae(e){return{getDiagramUrl(r){if(e.provider==="mermaid-ink"){let{provider:s,...c}=e;return ie(r,c)}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 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 ce(e,r={}){if(rt(e))return e;let{minOverlapMs:s=0,maxGapMs:c=5}=r,u=[],i=[];for(let a=0;a<e.length;a++){let d=e[a];d.type==="step"&&d.startTs!==void 0?u.push({node:d,startTs:d.startTs,endTs:d.endTs??d.startTs+(d.durationMs??0),originalIndex:a}):i.push({node:d,originalIndex:a})}if(u.length<=1)return e;u.sort((a,d)=>a.startTs-d.startTs);let h=[],m=[u[0]];for(let a=1;a<u.length;a++){let d=u[a],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>=s?m.push(d):(h.push(m),m=[d])}h.push(m);let g=[];for(let a of h){let d=Math.min(...a.map(b=>b.originalIndex));if(a.length===1)g.push({node:a[0].node,position:d});else{let b=a.map(w=>w.node),l=Math.min(...a.map(w=>w.startTs)),p=Math.max(...a.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:a,originalIndex:d}of i)g.push({node:a,position:d});return g.sort((a,d)=>a.position-d.position),g.map(a=>a.node)}function nt(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 de(e={}){let{detectParallel:r=!0,parallelDetection:s,enableSnapshots:c=!1,maxSnapshots:u=1e3}=e,i=c,h=F(),m,g,a,d="pending",b,l,p=new Map,f=[],w=[],S=new Map,I=[],x=Date.now(),k=x,R={onAfterStep:new Map},T,y=[],M=0;function N(t){return t.stepId??t.stepKey??t.name??F()}function D(t){if(f.length>0){f[f.length-1].children.push(t),k=Date.now();return}if(w.length>0){let o=w[w.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}I.push(t),k=Date.now()}function me(t){if(!i)return;let o=V(),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_${M}`,eventIndex:M,event:structuredClone(t),ir:structuredClone(o),timestamp:Date.now(),activeSteps:n};y.push(E),y.length>u&&y.shift(),M++}function ge(t){switch(t.type){case"workflow_start":{I=[],a=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&&(R.shouldRun=void 0,R.onBeforeStart=void 0),T=t.workflowId,R.onAfterStep=new Map;break}case"workflow_success":d="success",a=t.ts,l=t.durationMs,k=Date.now();break;case"workflow_error":d="error",a=t.ts,b=t.error,l=t.durationMs,k=Date.now();break;case"workflow_cancelled":d="aborted",a=t.ts,l=t.durationMs,k=Date.now();break;case"step_start":{let o=N(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=N(t),n=p.get(o);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(o)}break}case"step_error":{let o=N(t),n=p.get(o);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(o)}break}case"step_aborted":{let o=N(t),n=p.get(o);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(o)}break}case"step_cache_hit":{let n={type:"step",id:N(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 o=N(t),n=p.get(o);n&&(n.timedOut=!0,n.timeoutMs=t.timeoutMs),k=Date.now();break}case"step_retry":{let o=N(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:N(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"decision":{let o=t;if(o.phase==="start"){L({type:"decision_start",workflowId:t.workflowId,decisionId:o.decisionId,name:o.label??o.decisionId,condition:o.label,decisionValue:o.value,ts:o.ts}),L({type:"decision_branch",workflowId:t.workflowId,decisionId:o.decisionId,branchLabel:"then",condition:o.label,taken:o.branch==="then",ts:o.ts}),L({type:"decision_branch",workflowId:t.workflowId,decisionId:o.decisionId,branchLabel:"else",taken:o.branch==="else",ts:o.ts});break}if(o.phase==="end"){L({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:[]}]};D(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}};R.shouldRun=o,T=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};R.shouldRun=o,T=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}};R.onBeforeStart=o,T=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};R.onBeforeStart=o,T=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}};R.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}};R.onAfterStep.set(t.stepKey,o),k=Date.now();break}case"stream_created":{let o=`${t.workflowId}:${t.namespace}`;S.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=S.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=S.get(o);n&&n.readCount++,k=Date.now();break}case"stream_close":{let o=`${t.workflowId}:${t.namespace}`,n=S.get(o);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(o)}k=Date.now();break}case"stream_error":{let o=`${t.workflowId}:${t.namespace}`,n=S.get(o);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(o)}k=Date.now();break}case"stream_backpressure":{let o=`${t.workflowId}:${t.namespace}`,n=S.get(o);n&&(n.backpressureOccurred=!0),k=Date.now();break}}me(t)}function he(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 o=f.findIndex($=>$.id===t.scopeId);if(o===-1)return;for(;f.length>o+1;){let $=f.pop(),v=$.type==="race"?{type:"race",id:$.id,name:$.name,state:U($.children),startTs:$.startTs,endTs:t.ts,children:$.children}:{type:"parallel",id:$.id,name:$.name,state:U($.children),startTs:$.startTs,endTs:t.ts,children:$.children,mode:$.type==="allSettled"?"allSettled":"all"};f[f.length-1].children.push(v)}let[n]=f.splice(o,1),E=n.type==="race"?{type:"race",id:n.id,name:n.name,state:U(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:U(n.children),startTs:n.startTs,endTs:t.ts,durationMs:t.durationMs,children:n.children,mode:n.type==="allSettled"?"allSettled":"all"};D(E)}}function L(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 o=w.find(n=>n.id===t.decisionId);if(o){let n=t.branchLabel,E=o.branches.get(n);if(E)E.taken=t.taken,t.taken&&o.pendingChildren.length>0&&(E.children.unshift(...o.pendingChildren),o.pendingChildren=[]);else{let $=t.taken?[...o.pendingChildren]:[];t.taken&&(o.pendingChildren=[]),o.branches.set(n,{label:t.branchLabel,condition:t.condition,taken:t.taken,children:$})}k=Date.now()}}else if(t.type==="decision_end"){let o=w.findIndex(n=>n.id===t.decisionId);if(o!==-1){let[n]=w.splice(o,1),E=w.splice(o),$=Array.from(n.branches.values());$.length===0&&n.pendingChildren.length>0&&($=[{label:"default",taken:!0,children:[...n.pendingChildren]}]);let v=$.find(A=>A.taken)?.label,xe={type:"decision",id:n.id,name:n.name,state:U($.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:$};D(xe),w.push(...E),k=Date.now()}}}function U(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=[...I];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 S)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=ke();r&&(t=ce(t,s));let o={type:"workflow",id:m??h,workflowId:m??h,state:d,startTs:g,endTs:a,durationMs:l,children:t,error:b},n=R.shouldRun!==void 0||R.onBeforeStart!==void 0||R.onAfterStep.size>0;return{root:o,metadata:{createdAt:x,lastUpdatedAt:k},...n&&{hooks:R}}}function we(){m=void 0,g=void 0,a=void 0,d="pending",b=void 0,l=void 0,p.clear(),f.length=0,w.length=0,S.clear(),I=[],x=Date.now(),k=x,R={onAfterStep:new Map},T=void 0,y.length=0,M=0}function be(){return[...y]}function ye(t){return y[t]}function Se(t){return y[t]?.ir}function $e(){y.length=0,M=0}return{handleEvent:ge,handleScopeEvent:he,handleDecisionEvent:L,getIR:V,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 i},setSnapshotsEnabled(t){i=t}}}var st=500,it=5e3;function le(e,r){let{title:s,debounceMs:c=st,maxWaitMs:u=it}=e,i,h=!0,m,g,a,d,b,l,p=G(void 0),f=de({detectParallel:!0});function w(){a&&(clearTimeout(a),a=void 0),d&&(clearTimeout(d),d=void 0)}async function S(){if(!m||!h)return G(void 0);let M=m;g=M,m=void 0,w();try{return i?await r.updateExisting(i,M,s):i=await r.postNew(M,s),b=Date.now(),p=G(void 0),p}catch{return p=ot("CALLBACK_ERROR"),p}}function I(){a&&clearTimeout(a),a=setTimeout(()=>{S()},c);let M=b??l;if(!d&&M!==void 0){let N=Date.now()-M,D=Math.max(0,u-N);d=setTimeout(()=>{d=void 0,S()},D)}}function x(M){if(h){if(l===void 0&&(l=Date.now()),"root"in M)m=M,g=M;else{let N=M;N.type==="scope_start"||N.type==="scope_end"?f.handleScopeEvent(N):N.type==="decision_start"||N.type==="decision_branch"||N.type==="decision_end"?f.handleDecisionEvent(N):f.handleEvent(N),m=f.getIR(),g=m}I()}}async function k(M="completed"){if(!h)return;h=!1,w();let N=m??g??f.getIR();await r.finalize(i,N,s,M)}function R(){h&&(h=!1,w(),i&&r.cancel&&r.cancel(i))}function T(){return i}function y(){return h}return{update:x,finalize:k,cancel:R,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 ue(e,r){let{diagramProvider:s,debounceMs:c=500,maxWaitMs:u=5e3}=e;if(!s)throw new Error(`${r.name}Notifier: diagramProvider is required. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }.`);let i=ae(s);async function h(g,a={}){let d=a.title??"Workflow",b=dt(g);try{let l=r.buildMessage({ir:g,title:d,status:b},i),p=await r.sendNew(l);return at(p?.toString())}catch{return ct("SEND_FAILED")}}function m(g){return le({...g,debounceMs:g.debounceMs??c,maxWaitMs:g.maxWaitMs??u},{async postNew(a,d){let b=r.buildMessage({ir:a,title:d,status:"running"},i);return(await r.sendNew(b))?.toString()},async updateExisting(a,d,b){let l=r.buildMessage({ir:d,title:b,status:"running"},i);await r.sendUpdate(a,l)},async finalize(a,d,b,l){let p=r.buildMessage({ir:d,title:b,status:l},i);a?await r.sendUpdate(a,p):await r.sendNew(p)},async cancel(a){r.sendCancel&&a&&await r.sendCancel(a)}})}return{notify:h,createLive:m,getType:()=>r.name.toLowerCase()}}import{ok as pe,err as j}from"awaitly";function fe(e){let{url:r,headers:s={},timeout:c=3e4,includeMermaid:u=!1,includeKrokiUrl:i,includeDiagramUrl:h=i??!0,providerName:m="kroki",metadata:g}=e,a=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 I=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",...s},body:JSON.stringify(f),signal:w.signal});if(!I.ok)return j("SEND_FAILED");try{let x=await I.json();return pe(x.messageId??x.id??f.messageId??"")}catch{return pe(f.messageId??"")}}catch(I){return I instanceof Error&&I.name==="AbortError"?j("TIMEOUT"):j("SEND_FAILED")}finally{clearTimeout(S)}}function p(){return`webhook-${++b}-${Date.now()}`}return{name:"Webhook",buildMessage({ir:f,title:w,status:S},I){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 R=I.getDiagramUrl(f);k.diagramUrl=R,k.diagramProvider=m,k.krokiUrl=R}return u&&(k.mermaid=a.render(f,d)),{payload:k}},async sendNew(f){let{payload:w}=f,S=p();w.messageId=S;let I=await l(w);if(!I.ok)throw new Error(`Webhook send failed: ${I.error}`);return S},async sendUpdate(f,w){let{payload:S}=w;S.messageId=f;let I=await l(S);if(!I.ok)throw new Error(`Webhook update failed: ${I.error}`)}}}function lr(e){let{url:r,headers:s,timeout:c,includeMermaid:u,includeKrokiUrl:i,includeDiagramUrl:h,diagramProvider:m,...g}=e,a=fe({url:r,headers:s,timeout:c,includeMermaid:u,includeKrokiUrl:i,includeDiagramUrl:h,providerName:m?.provider??"kroki"});return ue({...g,diagramProvider:m},a)}export{lr as createWebhookNotifier};
|
|
3
3
|
//# sourceMappingURL=webhook.js.map
|