awaitly-visualizer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/index.browser.cjs +1677 -0
  2. package/dist/index.browser.cjs.map +1 -0
  3. package/dist/index.browser.d.cts +166 -0
  4. package/dist/index.browser.d.ts +166 -0
  5. package/dist/index.browser.js +1677 -0
  6. package/dist/index.browser.js.map +1 -0
  7. package/dist/index.cjs +1680 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.d.cts +242 -0
  10. package/dist/index.d.ts +242 -0
  11. package/dist/index.js +1680 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/kroki/fetch.cjs +3 -0
  14. package/dist/kroki/fetch.cjs.map +1 -0
  15. package/dist/kroki/fetch.d.cts +86 -0
  16. package/dist/kroki/fetch.d.ts +86 -0
  17. package/dist/kroki/fetch.js +3 -0
  18. package/dist/kroki/fetch.js.map +1 -0
  19. package/dist/notifiers/discord.cjs +3 -0
  20. package/dist/notifiers/discord.cjs.map +1 -0
  21. package/dist/notifiers/discord.d.cts +70 -0
  22. package/dist/notifiers/discord.d.ts +70 -0
  23. package/dist/notifiers/discord.js +3 -0
  24. package/dist/notifiers/discord.js.map +1 -0
  25. package/dist/notifiers/slack.cjs +38 -0
  26. package/dist/notifiers/slack.cjs.map +1 -0
  27. package/dist/notifiers/slack.d.cts +95 -0
  28. package/dist/notifiers/slack.d.ts +95 -0
  29. package/dist/notifiers/slack.js +38 -0
  30. package/dist/notifiers/slack.js.map +1 -0
  31. package/dist/notifiers/webhook.cjs +3 -0
  32. package/dist/notifiers/webhook.cjs.map +1 -0
  33. package/dist/notifiers/webhook.d.cts +115 -0
  34. package/dist/notifiers/webhook.d.ts +115 -0
  35. package/dist/notifiers/webhook.js +3 -0
  36. package/dist/notifiers/webhook.js.map +1 -0
  37. package/dist/performance-analyzer-B5VF5b1F.d.ts +663 -0
  38. package/dist/performance-analyzer-BNwE4AiO.d.cts +663 -0
  39. package/dist/types-BIZSmXif.d.ts +350 -0
  40. package/dist/types-BnWc9Wlr.d.cts +350 -0
  41. package/dist/url-PkfQz4V5.d.cts +750 -0
  42. package/dist/url-PkfQz4V5.d.ts +750 -0
  43. package/package.json +105 -0
@@ -0,0 +1,3 @@
1
+ "use strict";var Q=Object.create;var E=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var oe=(e,r)=>{for(var t in r)E(e,t,{get:r[t],enumerable:!0})},H=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of te(r))!ne.call(e,s)&&s!==t&&E(e,s,{get:()=>r[s],enumerable:!(n=ee(r,s))||n.enumerable});return e};var se=(e,r,t)=>(t=e!=null?Q(re(e)):{},H(r||!e||!e.__esModule?E(t,"default",{value:e,enumerable:!0}):t,e)),ie=e=>H(E({},"__esModule",{value:!0}),e);var _e={};oe(_e,{fetchKrokiPdf:()=>Te,fetchKrokiPng:()=>De,fetchKrokiSvg:()=>Oe});module.exports=ie(_e);var h=require("awaitly");var K=require("awaitly");function C(e){return e.type==="step"}function P(e){return e.type==="parallel"}function B(e){return e.type==="race"}function U(e){return e.type==="decision"}function F(e){return e.type==="stream"}function y(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),t=Math.round(e%6e4/1e3);return t>=60&&(r+=1,t=0),t===0?`${r}m`:`${r}m ${t}s`}var ae="\x1B[2m",ce="\x1B[31m",le="\x1B[32m",ue="\x1B[33m",de="\x1B[34m",A="\x1B[90m",pe="\x1B[37m";var O={pending:pe,running:ue,success:le,error:ce,aborted:A,cached:de,skipped:ae+A};var _=require("awaitly");function z(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function fe(){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 me(){return[" classDef heat_cold fill:#dbeafe,stroke:#3b82f6,stroke-width:2px,color:#1e40af"," classDef heat_cool fill:#ccfbf1,stroke:#14b8a6,stroke-width:2px,color:#0f766e"," classDef heat_neutral fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#374151"," classDef heat_warm fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#92400e"," classDef heat_hot fill:#fed7aa,stroke:#f97316,stroke-width:3px,color:#c2410c"," classDef heat_critical fill:#fecaca,stroke:#ef4444,stroke-width:3px,color:#b91c1c"]}function ge(e){return`heat_${e}`}function he(){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 be(e){try{return(0,_.ok)(JSON.stringify(e,(t,n)=>{if(typeof n!="bigint")return n;let s=Number(n);return Number.isSafeInteger(s)?s:n.toString()}))}catch{return(0,_.err)("STRINGIFY_ERROR")}}function G(e){let r=be(e);return r.ok?r.value:"[unserializable]"}function $e(e,r,t){let n;if(e.shouldRun){let s="hook_shouldRun",o=e.shouldRun.state==="success"?"hook_success":"hook_error",l=e.shouldRun.state==="success"?"\u2699":"\u26A0",u=t.showTimings&&e.shouldRun.durationMs!==void 0?` ${y(e.shouldRun.durationMs)}`:"",i=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";r.push(` ${s}[["${l} shouldRun${i}${u}"]]:::${o}`),n=s}if(e.onBeforeStart){let s="hook_beforeStart",o=e.onBeforeStart.state==="success"?"hook_success":"hook_error",l=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",u=t.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${y(e.onBeforeStart.durationMs)}`:"",i=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";r.push(` ${s}[["${l} onBeforeStart${i}${u}"]]:::${o}`),n&&r.push(` ${n} --> ${s}`),n=s}return{lastHookId:n}}var j=0,D=new Set,T=new Set;function w(e="node"){return`${e}_${++j}`}function ke(){j=0,D.clear(),T.clear()}function g(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function V(e){return g(e).replace(/[{}[\]()]/g,"")}function W(){return{name:"mermaid",supportsLive:!1,render(e,r){ke();let t=[],n=r;t.push("flowchart TD");let s;e.hooks&&(s=$e(e.hooks,t,r).lastHookId);let o="start";t.push(` ${o}(("\u25B6 Start"))`),s&&t.push(` ${s} --> ${o}`);let l=o;for(let i of e.root.children){let a=M(i,r,t,n,e.hooks);t.push(` ${l} --> ${a.entryId}`),l=a.exitId}if(["success","error","aborted"].includes(e.root.state)){let i="finish",a=e.root.state==="success"?"\u2713":e.root.state==="error"?"\u2717":"\u2298",m=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",$=`(("${a} ${m}"))`,c=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";t.push(` ${i}${$}${c}`),t.push(` ${l} --> ${i}`)}return t.push(""),t.push(...fe()),n.showHeatmap&&t.push(...me()),e.hooks&&t.push(...he()),t.join(`
2
+ `)}}}function M(e,r,t,n,s){if(C(e))return ye(e,r,t,n,s);if(P(e))return we(e,r,t,n,s);if(B(e))return xe(e,r,t,n,s);if(U(e))return Re(e,r,t,n,s);if(F(e))return Se(e,r,t);let o=w("unknown");return t.push(` ${o}["Unknown Node"]`),{entryId:o,exitId:o}}function ye(e,r,t,n,s){let o=r,l=o.showRetryEdges??!0,u=o.showErrorEdges??!0,i=o.showTimeoutEdges??!0,a=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:w("step");if(T.has(a)){let p=2;for(;T.has(`${a}_${p}`);)p++;a=`${a}_${p}`}T.add(a);let m=e.name??e.key??"Step",$=r.showKeys&&e.key&&e.name?`${m} [${e.key}]`:m,c=g($),d=r.showTimings&&e.durationMs!==void 0?` ${y(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 k="";if(e.input!==void 0){let p=typeof e.input=="string"?g(e.input):g(G(e.input).slice(0,20));k+=`\\nin: ${p}`}if(e.output!==void 0&&e.state==="success"){let p=typeof e.output=="string"?g(e.output):g(G(e.output).slice(0,20));k+=`\\nout: ${p}`}let v="",x=e.key??e.id;if(s&&x&&s.onAfterStep.has(x)){let p=s.onAfterStep.get(x),I=p.state==="success"?"\u2699":"\u26A0",X=r.showTimings&&p.durationMs!==void 0?` ${y(p.durationMs)}`:"";v=`\\n${I} hook${X}`}let b=(f+c+k+v+d).trim(),R,S=n?.showHeatmap&&n.heatmapData?n.heatmapData.heat.get(e.key??"")??n.heatmapData.heat.get(e.name??"")??n.heatmapData.heat.get(e.id):void 0;if(S!==void 0){let p=z(S);R=ge(p)}else R=e.state;let N;switch(e.state){case"error":N=`{{"${b}"}}`;break;case"cached":N=`[("${b}")]`;break;case"skipped":N=`["${b}"]`;break;default:N=`["${b}"]`}if(t.push(` ${a}${N}:::${R}`),l&&e.retryCount!==void 0&&e.retryCount>0){let p=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;t.push(` ${a} -.->|"${p}"| ${a}`)}if(u&&e.state==="error"&&e.error!==void 0){let p=`ERR_${a}`,I=g(String(e.error)).slice(0,30);t.push(` ${p}{{"${I}"}}`),t.push(` ${a} -->|error| ${p}`),t.push(` style ${p} fill:#fee2e2,stroke:#dc2626`)}if(i&&e.timedOut){let p=`TO_${a}`,I=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";t.push(` ${p}{{"\u23F1 Timeout ${I}"}}`),t.push(` ${a} -.->|timeout| ${p}`),t.push(` style ${p} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:a,exitId:a}}function we(e,r,t,n,s){let o=w("parallel"),l=`${o}_fork`,u=`${o}_join`,i=V(e.name??"Parallel"),a=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let c=o,d=g(`${i}${a}`),f="operations not individually tracked",k=r.showTimings&&e.durationMs!==void 0?` ${y(e.durationMs)}`:"";return t.push(` ${c}["${d}${k}\\n${f}"]:::${e.state}`),{entryId:c,exitId:c}}t.push(` subgraph ${o}["${i}${a}"]`),t.push(" direction TB"),t.push(` ${l}{"\u26A1 Fork"}`);let m=[];for(let c of e.children){let d=M(c,r,t,n,s);t.push(` ${l} --> ${d.entryId}`),m.push(d.exitId)}t.push(` ${u}{"\u2713 Join"}`);for(let c of m)t.push(` ${c} --> ${u}`);t.push(" end");let $=e.state;return t.push(` class ${o} ${$}`),{entryId:l,exitId:u}}function xe(e,r,t,n,s){let o=w("race"),l=`${o}_start`,u=`${o}_end`,i=V(e.name??"Race");if(e.children.length===0){let c=o,d=g(i),f="operations not individually tracked",k=r.showTimings&&e.durationMs!==void 0?` ${y(e.durationMs)}`:"";return t.push(` ${c}["\u26A1 ${d}${k}\\n${f}"]:::${e.state}`),{entryId:c,exitId:c}}t.push(` subgraph ${o}["\u26A1 ${i}"]`),t.push(" direction TB"),t.push(` ${l}(("\u{1F3C1} Start"))`);let a=[],m;for(let c of e.children){let d=M(c,r,t,n,s),f=e.winnerId===c.id;t.push(` ${l} --> ${d.entryId}`),f&&(m=d.exitId),a.push({exitId:d.exitId,isWinner:f})}t.push(` ${u}(("\u2713 First"))`);for(let{exitId:c,isWinner:d}of a)d&&m?t.push(` ${c} ==>|\u{1F3C6} Winner| ${u}`):e.winnerId?t.push(` ${c} -. cancelled .-> ${u}`):t.push(` ${c} --> ${u}`);t.push(" end");let $=e.state;return t.push(` class ${o} ${$}`),{entryId:l,exitId:u}}function Re(e,r,t,n,s){let o=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:w("decision");if(D.has(o)){let c=2;for(;D.has(`${o}_${c}`);)c++;o=`${o}_${c}`}D.add(o);let l=g(e.condition??"condition"),u=e.decisionValue!==void 0?` = ${g(String(e.decisionValue)).slice(0,30)}`:"",i=`${l}${u}`.trim();t.push(` ${o}{"${i}"}`);let a=[],m,$=new Set;for(let c of e.branches){let d=`${o}_${c.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if($.has(d)){let b=2;for(;$.has(`${d}_${b}`);)b++;d=`${d}_${b}`}$.add(d);let f=g(c.label),k=c.taken?`${f} \u2713`:`${f} skipped`,v=c.taken?":::success":":::skipped";t.push(` ${d}["${k}"]${v}`);let x=c.condition?`|${g(c.condition).replace(/\|/g,"")}|`:"";if(t.push(` ${o} -->${x} ${d}`),c.children.length>0){let b=d;for(let R of c.children){let S=M(R,r,t,n,s);t.push(` ${b} --> ${S.entryId}`),b=S.exitId}a.push(b),c.taken&&(m=b)}else a.push(d),c.taken&&(m=d)}return m?{entryId:o,exitId:m}:{entryId:o,exitId:o}}function Se(e,r,t){let n=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${w("")}`,s=`W:${e.writeCount} R:${e.readCount}`,o="";switch(e.streamState){case"active":o="\u27F3 ";break;case"closed":o="\u2713 ";break;case"error":o="\u2717 ";break}let l=r.showTimings&&e.durationMs!==void 0?` ${y(e.durationMs)}`:"",u=e.backpressureOccurred?"\\nbackpressure":"",i=`${o}stream:${g(e.namespace)}\\n${s}${u}${l}`,a;return e.streamState==="error"?a="streamError":e.streamState==="active"?a="streamActive":a="stream",t.push(` ${n}{{"${i}"}}:::${a}`),{entryId:n,exitId:n}}var q=se(require("pako"),1),Ne=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function Ie(e){let r;if(Ne)r=globalThis.Buffer.from(e).toString("base64");else{let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);r=btoa(t)}return r.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function J(e){let t=new TextEncoder().encode(e),n=q.default.deflate(t);return Ie(n)}var ve="https://kroki.io";function Ee(e,r,t,n={}){let s=n.baseUrl??ve,o=J(t);return`${s}/${e}/${r}/${o}`}function Y(e,r="svg",t={}){let n=W(),s={showTimings:!0,showKeys:!1,terminalWidth:80,colors:O},o=n.render(e,s);return Ee("mermaid",r,o,t)}function Z(e,r={}){return Y(e,"svg",r)}function L(e,r={}){return Y(e,"png",r)}async function Oe(e,r={}){let{generator:t,timeout:n=3e4,...s}=r,o=t?t.toSvgUrl(e):Z(e,s),l=new AbortController,u=setTimeout(()=>l.abort(),n);try{let i=await fetch(o,{signal:l.signal,headers:{Accept:"image/svg+xml"}});if(!i.ok)return(0,h.err)("INVALID_RESPONSE");let a=await i.text();return(0,h.ok)(a)}catch(i){return i instanceof Error&&i.name==="AbortError"?(0,h.err)("TIMEOUT"):(0,h.err)("FETCH_ERROR")}finally{clearTimeout(u)}}async function De(e,r={}){let{generator:t,timeout:n=3e4,...s}=r,o=t?t.toPngUrl(e):L(e,s),l=new AbortController,u=setTimeout(()=>l.abort(),n);try{let i=await fetch(o,{signal:l.signal,headers:{Accept:"image/png"}});if(!i.ok)return(0,h.err)("INVALID_RESPONSE");let a=await i.arrayBuffer();return(0,h.ok)(Buffer.from(a))}catch(i){return i instanceof Error&&i.name==="AbortError"?(0,h.err)("TIMEOUT"):(0,h.err)("FETCH_ERROR")}finally{clearTimeout(u)}}async function Te(e,r={}){let{generator:t,timeout:n=3e4,...s}=r,o=t?t.toPdfUrl(e):L(e,s).replace("/png/","/pdf/"),l=new AbortController,u=setTimeout(()=>l.abort(),n);try{let i=await fetch(o,{signal:l.signal,headers:{Accept:"application/pdf"}});if(!i.ok)return(0,h.err)("INVALID_RESPONSE");let a=await i.arrayBuffer();return(0,h.ok)(Buffer.from(a))}catch(i){return i instanceof Error&&i.name==="AbortError"?(0,h.err)("TIMEOUT"):(0,h.err)("FETCH_ERROR")}finally{clearTimeout(u)}}0&&(module.exports={fetchKrokiPdf,fetchKrokiPng,fetchKrokiSvg});
3
+ //# sourceMappingURL=fetch.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/kroki/fetch.ts","../../src/renderers/ascii.ts","../../src/types.ts","../../src/utils/timing.ts","../../src/renderers/colors.ts","../../src/renderers/mermaid.ts","../../src/performance-analyzer.ts","../../src/kroki/encoder.ts","../../src/kroki/url.ts"],"sourcesContent":["/**\n * Kroki Fetch (Node-only)\n *\n * Downloads rendered diagrams from Kroki as SVG or PNG.\n * This is a separate subpath entry to avoid bundling Node-only code in browser builds.\n */\n\nimport { ok, err, type AsyncResult } from \"awaitly\";\nimport type { WorkflowIR } from \"../types\";\nimport { toKrokiSvgUrl, toKrokiPngUrl, type UrlGeneratorOptions, type UrlGenerator } from \"./url\";\n\n/**\n * Error types for Kroki fetch operations.\n */\nexport type KrokiError = \"FETCH_ERROR\" | \"TIMEOUT\" | \"INVALID_RESPONSE\";\n\n/**\n * Options for fetching from Kroki.\n */\nexport interface FetchKrokiOptions extends UrlGeneratorOptions {\n /** Optional custom URL generator */\n generator?: UrlGenerator;\n /** Request timeout in milliseconds (default: 30000) */\n timeout?: number;\n}\n\n/**\n * Fetch SVG content from Kroki.\n *\n * @param ir - Workflow intermediate representation\n * @param options - Fetch options\n * @returns Result with SVG content or KrokiError\n *\n * @example\n * ```typescript\n * import { fetchKrokiSvg } from 'awaitly-visualizer/kroki-fetch';\n *\n * const result = await fetchKrokiSvg(workflowIR);\n * if (result.ok) {\n * // Write to file or embed in HTML\n * console.log(result.value);\n * } else {\n * console.error('Failed:', result.error);\n * }\n * ```\n */\nexport async function fetchKrokiSvg(\n ir: WorkflowIR,\n options: FetchKrokiOptions = {}\n): AsyncResult<string, KrokiError> {\n const { generator, timeout = 30000, ...urlOptions } = options;\n\n const url = generator\n ? generator.toSvgUrl(ir)\n : toKrokiSvgUrl(ir, urlOptions);\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n\n try {\n const response = await fetch(url, {\n signal: controller.signal,\n headers: {\n Accept: \"image/svg+xml\",\n },\n });\n\n if (!response.ok) {\n return err(\"INVALID_RESPONSE\");\n }\n\n const text = await response.text();\n return ok(text);\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") {\n return err(\"TIMEOUT\");\n }\n return err(\"FETCH_ERROR\");\n } finally {\n clearTimeout(timeoutId);\n }\n}\n\n/**\n * Fetch PNG content from Kroki.\n *\n * @param ir - Workflow intermediate representation\n * @param options - Fetch options\n * @returns Result with PNG content as Buffer or KrokiError\n *\n * @example\n * ```typescript\n * import { fetchKrokiPng } from 'awaitly-visualizer/kroki-fetch';\n * import fs from 'node:fs';\n *\n * const result = await fetchKrokiPng(workflowIR);\n * if (result.ok) {\n * fs.writeFileSync('workflow.png', result.value);\n * }\n * ```\n */\nexport async function fetchKrokiPng(\n ir: WorkflowIR,\n options: FetchKrokiOptions = {}\n): AsyncResult<Buffer, KrokiError> {\n const { generator, timeout = 30000, ...urlOptions } = options;\n\n const url = generator\n ? generator.toPngUrl(ir)\n : toKrokiPngUrl(ir, urlOptions);\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n\n try {\n const response = await fetch(url, {\n signal: controller.signal,\n headers: {\n Accept: \"image/png\",\n },\n });\n\n if (!response.ok) {\n return err(\"INVALID_RESPONSE\");\n }\n\n const arrayBuffer = await response.arrayBuffer();\n return ok(Buffer.from(arrayBuffer));\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") {\n return err(\"TIMEOUT\");\n }\n return err(\"FETCH_ERROR\");\n } finally {\n clearTimeout(timeoutId);\n }\n}\n\n/**\n * Fetch PDF content from Kroki.\n *\n * @param ir - Workflow intermediate representation\n * @param options - Fetch options\n * @returns Result with PDF content as Buffer or KrokiError\n *\n * @example\n * ```typescript\n * import { fetchKrokiPdf } from 'awaitly-visualizer/kroki-fetch';\n * import fs from 'node:fs';\n *\n * const result = await fetchKrokiPdf(workflowIR);\n * if (result.ok) {\n * fs.writeFileSync('workflow.pdf', result.value);\n * }\n * ```\n */\nexport async function fetchKrokiPdf(\n ir: WorkflowIR,\n options: FetchKrokiOptions = {}\n): AsyncResult<Buffer, KrokiError> {\n const { generator, timeout = 30000, ...urlOptions } = options;\n\n // When generator is provided, use its toPdfUrl directly\n // Otherwise, build PDF URL by modifying the PNG URL path\n const pdfUrl = generator\n ? generator.toPdfUrl(ir)\n : toKrokiPngUrl(ir, urlOptions).replace(\"/png/\", \"/pdf/\");\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n\n try {\n const response = await fetch(pdfUrl, {\n signal: controller.signal,\n headers: {\n Accept: \"application/pdf\",\n },\n });\n\n if (!response.ok) {\n return err(\"INVALID_RESPONSE\");\n }\n\n const arrayBuffer = await response.arrayBuffer();\n return ok(Buffer.from(arrayBuffer));\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") {\n return err(\"TIMEOUT\");\n }\n return err(\"FETCH_ERROR\");\n } finally {\n clearTimeout(timeoutId);\n }\n}\n","/**\n * ASCII Terminal Renderer\n *\n * Renders the workflow IR as ASCII art with box-drawing characters\n * and ANSI colors for terminal display.\n */\n\nimport { ok, err, type Result } from \"awaitly\";\nimport type {\n FlowNode,\n ParallelNode,\n RaceNode,\n DecisionNode,\n StreamNode,\n Renderer,\n RenderOptions,\n StepNode,\n WorkflowIR,\n EnhancedRenderOptions,\n HeatLevel,\n WorkflowHooks,\n HookExecution,\n} from \"../types\";\nimport { isParallelNode, isRaceNode, isStepNode, isDecisionNode, isStreamNode } from \"../types\";\nimport { formatDuration } from \"../utils/timing\";\nimport {\n bold,\n colorByState,\n colorize,\n defaultColorScheme,\n dim,\n getColoredSymbol,\n stripAnsi,\n} from \"./colors\";\n\n/**\n * Error types for stringify operations.\n */\nexport type StringifyError = \"STRINGIFY_ERROR\";\n\n// =============================================================================\n// Box Drawing Characters\n// =============================================================================\n\nconst BOX = {\n topLeft: \"┌\",\n topRight: \"┐\",\n bottomLeft: \"└\",\n bottomRight: \"┘\",\n horizontal: \"─\",\n vertical: \"│\",\n teeRight: \"├\",\n teeLeft: \"┤\",\n teeDown: \"┬\",\n teeUp: \"┴\",\n cross: \"┼\",\n} as const;\n\n// =============================================================================\n// Heatmap Colors (ANSI)\n// =============================================================================\n\n/**\n * ANSI color codes for heatmap visualization.\n */\nconst HEAT_COLORS: Record<HeatLevel, string> = {\n cold: \"\\x1b[34m\", // Blue\n cool: \"\\x1b[36m\", // Cyan\n neutral: \"\", // Default (no color)\n warm: \"\\x1b[33m\", // Yellow\n hot: \"\\x1b[31m\", // Red\n critical: \"\\x1b[41m\", // Red background\n};\n\nconst RESET = \"\\x1b[0m\";\n\n/**\n * Get ANSI color code for a heat level.\n */\nfunction getHeatColor(heat: number): string {\n if (heat < 0.2) return HEAT_COLORS.cold;\n if (heat < 0.4) return HEAT_COLORS.cool;\n if (heat < 0.6) return HEAT_COLORS.neutral;\n if (heat < 0.8) return HEAT_COLORS.warm;\n if (heat < 0.95) return HEAT_COLORS.hot;\n return HEAT_COLORS.critical;\n}\n\n/**\n * Apply heat coloring to a string.\n */\nfunction applyHeatColor(text: string, heat: number): string {\n const color = getHeatColor(heat);\n if (!color) return text;\n return `${color}${text}${RESET}`;\n}\n\n/**\n * Safely stringify a value, handling circular references and BigInt.\n * Returns Result with either the stringified value or an error.\n */\nfunction safeStringify(value: unknown): Result<string, StringifyError> {\n try {\n const replacer = (_key: string, v: unknown): unknown => {\n if (typeof v !== \"bigint\") return v;\n const n = Number(v);\n return Number.isSafeInteger(n) ? n : v.toString();\n };\n return ok(JSON.stringify(value, replacer));\n } catch {\n return err(\"STRINGIFY_ERROR\");\n }\n}\n\n/**\n * Get stringified value or fallback for unserializable values.\n */\nfunction getStringified(value: unknown): string {\n const result = safeStringify(value);\n return result.ok ? result.value : \"[unserializable]\";\n}\n\n// =============================================================================\n// Sparkline Characters\n// =============================================================================\n\nconst SPARK_CHARS = \"▁▂▃▄▅▆▇█\";\n\n/**\n * Render a sparkline from an array of values.\n *\n * @param values Array of numeric values\n * @param width Maximum characters to use (default: 10)\n * @returns Sparkline string\n */\nexport function renderSparkline(values: number[], width = 10): string {\n if (values.length === 0) return \"\";\n\n // Take last N values\n const subset = values.slice(-width);\n const min = Math.min(...subset);\n const max = Math.max(...subset);\n const range = max - min || 1;\n\n return subset\n .map((v) => {\n const normalized = (v - min) / range;\n const index = Math.floor(normalized * (SPARK_CHARS.length - 1));\n return SPARK_CHARS[index];\n })\n .join(\"\");\n}\n\n// =============================================================================\n// Helper Functions\n// =============================================================================\n\n/**\n * Pad a string to a fixed width, accounting for ANSI codes.\n */\nfunction padEnd(str: string, width: number): string {\n const visibleLen = stripAnsi(str).length;\n const padding = Math.max(0, width - visibleLen);\n return str + \" \".repeat(padding);\n}\n\n/**\n * Create a horizontal line with optional title.\n */\nfunction horizontalLine(width: number, title?: string): string {\n if (!title) {\n return BOX.horizontal.repeat(width);\n }\n\n const titleText = ` ${title} `;\n // Use visible length (strip ANSI codes) for width calculation\n const visibleTitleLen = stripAnsi(titleText).length;\n const remainingWidth = width - visibleTitleLen;\n if (remainingWidth < 4) {\n return BOX.horizontal.repeat(width);\n }\n\n const leftPad = 2;\n const rightPad = remainingWidth - leftPad;\n\n return (\n BOX.horizontal.repeat(leftPad) + titleText + BOX.horizontal.repeat(rightPad)\n );\n}\n\n// =============================================================================\n// Hook Rendering\n// =============================================================================\n\n/**\n * Render a single hook execution.\n */\nfunction renderHookExecution(\n hook: HookExecution,\n label: string,\n colors: ReturnType<typeof Object.assign>\n): string {\n const symbol = hook.state === \"success\"\n ? colorize(\"⚙\", colors.success)\n : colorize(\"⚠\", colors.error);\n\n const timing = hook.durationMs !== undefined\n ? dim(` [${formatDuration(hook.durationMs)}]`)\n : \"\";\n\n let context = \"\";\n if (hook.type === \"shouldRun\" && hook.context?.skipped) {\n context = dim(\" → workflow skipped\");\n } else if (hook.type === \"shouldRun\" && hook.context?.result === true) {\n context = dim(\" → proceed\");\n } else if (hook.type === \"onBeforeStart\" && hook.context?.skipped) {\n context = dim(\" → workflow skipped\");\n } else if (hook.type === \"onAfterStep\" && hook.context?.stepKey) {\n context = dim(` (${hook.context.stepKey})`);\n }\n\n const error = hook.state === \"error\" && hook.error\n ? dim(` error: ${String(hook.error)}`)\n : \"\";\n\n return `${symbol} ${dim(label)}${context}${timing}${error}`;\n}\n\n/**\n * Render workflow hooks section.\n */\nfunction renderHooks(\n hooks: WorkflowHooks,\n colors: ReturnType<typeof Object.assign>\n): string[] {\n const lines: string[] = [];\n\n // Render shouldRun hook\n if (hooks.shouldRun) {\n lines.push(renderHookExecution(hooks.shouldRun, \"shouldRun\", colors));\n }\n\n // Render onBeforeStart hook\n if (hooks.onBeforeStart) {\n lines.push(renderHookExecution(hooks.onBeforeStart, \"onBeforeStart\", colors));\n }\n\n // We don't render onAfterStep hooks here - they're shown inline with steps\n // But if there are any, add a separator\n if (lines.length > 0) {\n lines.push(dim(\"────────────────────\")); // Separator between hooks and steps\n }\n\n return lines;\n}\n\n// =============================================================================\n// ASCII Renderer\n// =============================================================================\n\n/**\n * Create the ASCII terminal renderer.\n */\nexport function asciiRenderer(): Renderer {\n return {\n name: \"ascii\",\n supportsLive: true,\n\n render(ir: WorkflowIR, options: RenderOptions): string {\n const colors = { ...defaultColorScheme, ...options.colors };\n // Ensure minimum width to prevent negative repeat counts\n const width = Math.max(options.terminalWidth ?? 60, 5);\n const innerWidth = width - 4; // Account for borders\n\n const lines: string[] = [];\n\n // Header\n const workflowName = ir.root.name ?? \"workflow\";\n const headerTitle = bold(workflowName);\n lines.push(\n `${BOX.topLeft}${horizontalLine(width - 2, headerTitle)}${BOX.topRight}`\n );\n lines.push(`${BOX.vertical}${\" \".repeat(width - 2)}${BOX.vertical}`);\n\n // Render hooks (if any)\n if (ir.hooks) {\n const hookLines = renderHooks(ir.hooks, colors);\n for (const line of hookLines) {\n lines.push(\n `${BOX.vertical} ${padEnd(line, innerWidth)}${BOX.vertical}`\n );\n }\n }\n\n // Render children\n const childLines = renderNodes(ir.root.children, options, colors, 0, ir.hooks);\n for (const line of childLines) {\n lines.push(\n `${BOX.vertical} ${padEnd(line, innerWidth)}${BOX.vertical}`\n );\n }\n\n // Footer with timing\n lines.push(`${BOX.vertical}${\" \".repeat(width - 2)}${BOX.vertical}`);\n\n if (ir.root.durationMs !== undefined && options.showTimings) {\n const status =\n ir.root.state === \"success\"\n ? \"Completed\"\n : ir.root.state === \"aborted\"\n ? \"Cancelled\"\n : \"Failed\";\n const statusColored = colorByState(status, ir.root.state, colors);\n const footer = `${statusColored} in ${formatDuration(ir.root.durationMs)}`;\n lines.push(\n `${BOX.vertical} ${padEnd(footer, innerWidth)}${BOX.vertical}`\n );\n lines.push(`${BOX.vertical}${\" \".repeat(width - 2)}${BOX.vertical}`);\n }\n\n lines.push(\n `${BOX.bottomLeft}${BOX.horizontal.repeat(width - 2)}${BOX.bottomRight}`\n );\n\n return lines.join(\"\\n\");\n },\n };\n}\n\n/**\n * Render a list of nodes.\n */\nfunction renderNodes(\n nodes: FlowNode[],\n options: RenderOptions,\n colors: ReturnType<typeof Object.assign>,\n depth: number,\n hooks?: WorkflowHooks\n): string[] {\n const lines: string[] = [];\n\n for (const node of nodes) {\n if (isStepNode(node)) {\n lines.push(renderStepNode(node, options, colors, hooks));\n } else if (isParallelNode(node)) {\n lines.push(...renderParallelNode(node, options, colors, depth, hooks));\n } else if (isRaceNode(node)) {\n lines.push(...renderRaceNode(node, options, colors, depth, hooks));\n } else if (isDecisionNode(node)) {\n lines.push(...renderDecisionNode(node, options, colors, depth, hooks));\n } else if (isStreamNode(node)) {\n lines.push(renderStreamNode(node, options, colors));\n }\n }\n\n return lines;\n}\n\n/**\n * Render a single step node.\n */\nfunction renderStepNode(\n node: StepNode,\n options: RenderOptions,\n colors: ReturnType<typeof Object.assign>,\n hooks?: WorkflowHooks\n): string {\n const symbol = getColoredSymbol(node.state, colors);\n const name = node.name ?? node.key ?? \"step\";\n\n // Check for enhanced options\n const enhanced = options as EnhancedRenderOptions;\n // Heatmap lookup order matches PerformanceAnalyzer: key ?? name ?? id\n const heat = enhanced.showHeatmap && enhanced.heatmapData\n ? enhanced.heatmapData.heat.get(node.key ?? \"\") ??\n enhanced.heatmapData.heat.get(node.name ?? \"\") ??\n enhanced.heatmapData.heat.get(node.id)\n : undefined;\n\n // Apply heat coloring or default state coloring\n let nameColored: string;\n if (heat !== undefined) {\n nameColored = applyHeatColor(name, heat);\n } else {\n nameColored = colorByState(name, node.state, colors);\n }\n\n let line = `${symbol} ${nameColored}`;\n\n // Add key if requested (only when step has a name, so key is not already the label)\n if (options.showKeys && node.key && node.name) {\n line += dim(` [key: ${node.key}]`);\n }\n\n // Add input/output if available (for decision understanding)\n if (node.input !== undefined) {\n const inputStr = typeof node.input === \"string\"\n ? node.input\n : getStringified(node.input).slice(0, 30);\n line += dim(` [in: ${inputStr}${inputStr.length >= 30 ? \"...\" : \"\"}]`);\n }\n if (node.output !== undefined && node.state === \"success\") {\n const outputStr = typeof node.output === \"string\"\n ? node.output\n : getStringified(node.output).slice(0, 30);\n line += dim(` [out: ${outputStr}${outputStr.length >= 30 ? \"...\" : \"\"}]`);\n }\n\n // Add timing if available and requested\n if (options.showTimings && node.durationMs !== undefined) {\n // Apply heat coloring to timing if enabled\n const timingStr = formatDuration(node.durationMs);\n const timingDisplay = heat !== undefined\n ? applyHeatColor(`[${timingStr}]`, heat)\n : dim(`[${timingStr}]`);\n line += ` ${timingDisplay}`;\n }\n\n // Add sparkline if enabled and history available (lookup order: key ?? name ?? id, like analyzer)\n if (enhanced.showSparklines && enhanced.timingHistory) {\n const history =\n enhanced.timingHistory.get(node.key ?? \"\") ??\n enhanced.timingHistory.get(node.name ?? \"\") ??\n enhanced.timingHistory.get(node.id);\n if (history && history.length > 1) {\n line += ` ${dim(renderSparkline(history))}`;\n }\n }\n\n // Add retry indicator if retries occurred\n if (node.retryCount !== undefined && node.retryCount > 0) {\n line += dim(` [${node.retryCount} ${node.retryCount === 1 ? \"retry\" : \"retries\"}]`);\n }\n\n // Add timeout indicator if step timed out\n if (node.timedOut) {\n const timeoutInfo = node.timeoutMs !== undefined ? ` ${node.timeoutMs}ms` : \"\";\n line += dim(` [timeout${timeoutInfo}]`);\n }\n\n // Add onAfterStep hook indicator if present (check by key first, then by id)\n const hookKey = node.key ?? node.id;\n if (hooks && hookKey && hooks.onAfterStep.has(hookKey)) {\n const hookExec = hooks.onAfterStep.get(hookKey)!;\n const hookSymbol = hookExec.state === \"success\"\n ? colorize(\"⚙\", colors.success)\n : colorize(\"⚠\", colors.error);\n const hookTiming = hookExec.durationMs !== undefined\n ? dim(` ${formatDuration(hookExec.durationMs)}`)\n : \"\";\n line += ` ${hookSymbol}${hookTiming}`;\n }\n\n return line;\n}\n\n/**\n * Render a stream node.\n */\nfunction renderStreamNode(\n node: StreamNode,\n options: RenderOptions,\n colors: ReturnType<typeof Object.assign>\n): string {\n // Use stream-specific symbol\n const stateSymbol = node.streamState === \"active\"\n ? colorize(\"⟳\", colors.running)\n : node.streamState === \"closed\"\n ? colorize(\"✓\", colors.success)\n : colorize(\"✗\", colors.error);\n\n const name = `stream:${node.namespace}`;\n const nameColored = colorByState(name, node.state, colors);\n\n // Show write/read counts\n const counts = dim(`[W:${node.writeCount} R:${node.readCount}]`);\n\n let line = `${stateSymbol} ${nameColored} ${counts}`;\n\n // Add timing if available and requested\n if (options.showTimings && node.durationMs !== undefined) {\n line += ` ${dim(`[${formatDuration(node.durationMs)}]`)}`;\n }\n\n // Add backpressure indicator if occurred\n if (node.backpressureOccurred) {\n line += dim(\" [backpressure]\");\n }\n\n // Add final position\n if (node.streamState === \"closed\") {\n line += dim(` pos:${node.finalPosition}`);\n }\n\n return line;\n}\n\n/**\n * Render a parallel node (allAsync).\n */\nfunction renderParallelNode(\n node: ParallelNode,\n options: RenderOptions,\n colors: ReturnType<typeof Object.assign>,\n depth: number,\n hooks?: WorkflowHooks\n): string[] {\n const lines: string[] = [];\n const indent = \" \".repeat(depth);\n\n // Header\n const symbol = getColoredSymbol(node.state, colors);\n const name = node.name ?? \"parallel\";\n const mode = node.mode === \"allSettled\" ? \" (allSettled)\" : \"\";\n lines.push(`${indent}${BOX.teeRight}${BOX.teeDown}${BOX.horizontal} ${symbol} ${bold(name)}${mode}`);\n\n // Children\n if (node.children.length === 0) {\n // Empty parallel scope - operations inside allAsync/anyAsync weren't tracked as steps\n lines.push(`${indent}${BOX.vertical} ${dim(\"(operations not individually tracked)\")}`);\n lines.push(`${indent}${BOX.vertical} ${dim(\"(wrap each operation with step() to see individual steps)\")}`);\n } else {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n const isLast = i === node.children.length - 1;\n const prefix = isLast ? `${indent}${BOX.vertical} ${BOX.bottomLeft}` : `${indent}${BOX.vertical} ${BOX.teeRight}`;\n\n if (isStepNode(child)) {\n lines.push(`${prefix} ${renderStepNode(child, options, colors, hooks)}`);\n } else {\n // Nested structure - recurse\n const nestedLines = renderNodes([child], options, colors, depth + 1, hooks);\n for (const line of nestedLines) {\n lines.push(`${indent}${BOX.vertical} ${line}`);\n }\n }\n }\n }\n\n // Timing footer\n if (options.showTimings && node.durationMs !== undefined) {\n lines.push(`${indent}${BOX.bottomLeft}${BOX.horizontal}${BOX.horizontal} ${dim(`[${formatDuration(node.durationMs)}]`)}`);\n }\n\n return lines;\n}\n\n/**\n * Render a race node (anyAsync).\n */\nfunction renderRaceNode(\n node: RaceNode,\n options: RenderOptions,\n colors: ReturnType<typeof Object.assign>,\n depth: number,\n hooks?: WorkflowHooks\n): string[] {\n const lines: string[] = [];\n const indent = \" \".repeat(depth);\n\n // Header with lightning bolt for race\n const symbol = getColoredSymbol(node.state, colors);\n const name = node.name ?? \"race\";\n lines.push(`${indent}${BOX.teeRight}⚡ ${symbol} ${bold(name)}`);\n\n // Children\n if (node.children.length === 0) {\n // Empty race scope - operations inside anyAsync weren't tracked as steps\n lines.push(`${indent}${BOX.vertical} ${dim(\"(operations not individually tracked)\")}`);\n lines.push(`${indent}${BOX.vertical} ${dim(\"(wrap each operation with step() to see individual steps)\")}`);\n } else {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n const isLast = i === node.children.length - 1;\n const prefix = isLast ? `${indent}${BOX.vertical} ${BOX.bottomLeft}` : `${indent}${BOX.vertical} ${BOX.teeRight}`;\n\n // Mark winner\n const isWinner = node.winnerId && child.id === node.winnerId;\n const winnerSuffix = isWinner ? dim(\" (winner)\") : \"\";\n\n if (isStepNode(child)) {\n lines.push(`${prefix} ${renderStepNode(child, options, colors, hooks)}${winnerSuffix}`);\n } else {\n const nestedLines = renderNodes([child], options, colors, depth + 1, hooks);\n for (const line of nestedLines) {\n lines.push(`${indent}${BOX.vertical} ${line}`);\n }\n }\n }\n }\n\n // Timing footer\n if (options.showTimings && node.durationMs !== undefined) {\n lines.push(`${indent}${BOX.bottomLeft}${BOX.horizontal}${BOX.horizontal} ${dim(`[${formatDuration(node.durationMs)}]`)}`);\n }\n\n return lines;\n}\n\n/**\n * Render a decision node (conditional branch).\n */\nfunction renderDecisionNode(\n node: DecisionNode,\n options: RenderOptions,\n colors: ReturnType<typeof Object.assign>,\n depth: number,\n hooks?: WorkflowHooks\n): string[] {\n const lines: string[] = [];\n const indent = \" \".repeat(depth);\n\n // Header with decision info\n const symbol = getColoredSymbol(node.state, colors);\n const name = node.name ?? \"decision\";\n const condition = node.condition\n ? dim(` (${node.condition})`)\n : \"\";\n const decisionValue = node.decisionValue !== undefined\n ? dim(` = ${String(node.decisionValue)}`)\n : \"\";\n const branchTaken = node.branchTaken !== undefined\n ? dim(` → ${String(node.branchTaken)}`)\n : \"\";\n\n lines.push(\n `${indent}${BOX.teeRight}${BOX.teeDown}${BOX.horizontal} ${symbol} ${bold(name)}${condition}${decisionValue}${branchTaken}`\n );\n\n // Render branches\n for (let i = 0; i < node.branches.length; i++) {\n const branch = node.branches[i];\n const isLast = i === node.branches.length - 1;\n const prefix = isLast\n ? `${indent}${BOX.vertical} ${BOX.bottomLeft}`\n : `${indent}${BOX.vertical} ${BOX.teeRight}`;\n\n // Branch label with taken/skipped indicator\n const branchSymbol = branch.taken ? \"✓\" : \"⊘\";\n const branchColor = branch.taken ? colors.success : colors.skipped;\n const branchLabel = colorize(\n `${branchSymbol} ${branch.label}`,\n branchColor\n );\n const branchCondition = branch.condition\n ? dim(` (${branch.condition})`)\n : \"\";\n\n lines.push(`${prefix} ${branchLabel}${branchCondition}`);\n\n // Render children of this branch\n if (branch.children.length > 0) {\n const childLines = renderNodes(branch.children, options, colors, depth + 1, hooks);\n for (const line of childLines) {\n lines.push(`${indent}${BOX.vertical} ${line}`);\n }\n } else if (!branch.taken) {\n // Show that this branch was skipped\n lines.push(\n `${indent}${BOX.vertical} ${dim(\"(skipped)\")}`\n );\n }\n }\n\n // Timing footer\n if (options.showTimings && node.durationMs !== undefined) {\n lines.push(\n `${indent}${BOX.bottomLeft}${BOX.horizontal}${BOX.horizontal} ${dim(`[${formatDuration(node.durationMs)}]`)}`\n );\n }\n\n return lines;\n}\n\nexport { defaultColorScheme };\n","/**\n * Workflow Visualization - Intermediate Representation Types\n *\n * The IR (Intermediate Representation) is a DSL that represents workflow\n * execution structure. Events are converted to IR, which can then be\n * rendered to various output formats (ASCII, Mermaid, JSON, etc.).\n */\n\n// =============================================================================\n// Step States\n// =============================================================================\n\n/**\n * Execution state of a step with semantic meaning for visualization.\n *\n * Color mapping:\n * - pending → white/clear (not started)\n * - running → yellow (currently executing)\n * - success → green (completed successfully)\n * - error → red (failed with error)\n * - aborted → gray (cancelled, e.g., in race)\n * - cached → blue (served from cache)\n * - skipped → dim gray (not executed due to conditional logic)\n */\nexport type StepState =\n | \"pending\"\n | \"running\"\n | \"success\"\n | \"error\"\n | \"aborted\"\n | \"cached\"\n | \"skipped\";\n\n// =============================================================================\n// Node Types\n// =============================================================================\n\n/**\n * Base properties shared by all IR nodes.\n */\nexport interface BaseNode {\n /** Unique identifier for this node */\n id: string;\n /** Human-readable name (from step options or inferred) */\n name?: string;\n /** Cache key if this is a keyed step */\n key?: string;\n /** Current execution state */\n state: StepState;\n /** Timestamp when execution started */\n startTs?: number;\n /** Timestamp when execution ended */\n endTs?: number;\n /** Duration in milliseconds */\n durationMs?: number;\n /** Error value if state is 'error' */\n error?: unknown;\n /** Input value that triggered this step (for decision understanding) */\n input?: unknown;\n /** Output value from this step (for decision understanding) */\n output?: unknown;\n /** Number of retry attempts made (0 = no retries, 1 = one retry, etc.) */\n retryCount?: number;\n /** Whether this step experienced a timeout (may have retried after) */\n timedOut?: boolean;\n /** Timeout duration in ms (if timed out) */\n timeoutMs?: number;\n}\n\n/**\n * A single step execution node.\n */\nexport interface StepNode extends BaseNode {\n type: \"step\";\n}\n\n/**\n * Sequential execution - steps run one after another.\n * This is the implicit structure when steps are awaited in sequence.\n */\nexport interface SequenceNode extends BaseNode {\n type: \"sequence\";\n children: FlowNode[];\n}\n\n/**\n * Parallel execution - all branches run simultaneously.\n * Created by allAsync() or allSettledAsync().\n */\nexport interface ParallelNode extends BaseNode {\n type: \"parallel\";\n children: FlowNode[];\n /**\n * Execution mode:\n * - 'all': Fails on first error (allAsync)\n * - 'allSettled': Collects all results (allSettledAsync)\n */\n mode: \"all\" | \"allSettled\";\n}\n\n/**\n * Race execution - first to complete wins.\n * Created by anyAsync().\n */\nexport interface RaceNode extends BaseNode {\n type: \"race\";\n children: FlowNode[];\n /** ID of the winning branch (first to succeed) */\n winnerId?: string;\n}\n\n/**\n * Stream operation node.\n * Tracks streaming events (write, read, close, error, backpressure).\n */\nexport interface StreamNode extends BaseNode {\n type: \"stream\";\n /** Stream namespace identifier */\n namespace: string;\n /** Total number of write operations */\n writeCount: number;\n /** Total number of read operations */\n readCount: number;\n /** Final position when stream closed */\n finalPosition: number;\n /** Current stream state */\n streamState: \"active\" | \"closed\" | \"error\";\n /** Whether backpressure was encountered during streaming */\n backpressureOccurred: boolean;\n}\n\n/**\n * Decision point - conditional branch (if/switch).\n * Shows which branch was taken and why.\n */\nexport interface DecisionNode extends BaseNode {\n type: \"decision\";\n /** Condition that was evaluated (e.g., \"user.role === 'admin'\") */\n condition?: string;\n /** Value that was evaluated (the input to the decision) */\n decisionValue?: unknown;\n /** Which branch was taken (true/false, or the matched case) */\n branchTaken?: string | boolean;\n /** All possible branches (including skipped ones) */\n branches: DecisionBranch[];\n}\n\n/**\n * A branch in a decision node.\n */\nexport interface DecisionBranch {\n /** Label for this branch (e.g., \"if\", \"else\", \"case 'admin'\") */\n label: string;\n /** Condition that would trigger this branch */\n condition?: string;\n /** Whether this branch was taken */\n taken: boolean;\n /** Steps in this branch */\n children: FlowNode[];\n}\n\n/**\n * Union of all flow node types.\n */\nexport type FlowNode = StepNode | SequenceNode | ParallelNode | RaceNode | DecisionNode | StreamNode;\n\n/**\n * Root node representing the entire workflow.\n */\nexport interface WorkflowNode extends BaseNode {\n type: \"workflow\";\n /** Correlation ID from the workflow execution */\n workflowId: string;\n /** Child nodes (steps, parallel blocks, etc.) */\n children: FlowNode[];\n}\n\n// =============================================================================\n// Workflow IR\n// =============================================================================\n\n/**\n * Complete workflow intermediate representation.\n * This is the main data structure produced by the IR builder.\n */\nexport interface WorkflowIR {\n /** Root workflow node */\n root: WorkflowNode;\n /** Metadata about the IR */\n metadata: {\n /** When the IR was first created */\n createdAt: number;\n /** When the IR was last updated */\n lastUpdatedAt: number;\n };\n /** Hook executions (if any hooks are configured) */\n hooks?: WorkflowHooks;\n}\n\n// =============================================================================\n// Scope Events (for parallel/race detection)\n// =============================================================================\n\n// Re-export ScopeType from awaitly for consistency\nexport type { ScopeType } from \"awaitly/workflow\";\nimport type { ScopeType, WorkflowEvent, WorkflowOptions } from \"awaitly/workflow\";\nimport type { UnexpectedError } from \"awaitly/core\";\n\n/**\n * Event emitted when entering a parallel/race scope.\n * This matches the scope_start event in WorkflowEvent.\n */\nexport interface ScopeStartEvent {\n type: \"scope_start\";\n workflowId: string;\n scopeId: string;\n scopeType: ScopeType;\n name?: string;\n ts: number;\n}\n\n/**\n * Event emitted when exiting a parallel/race scope.\n */\nexport interface ScopeEndEvent {\n type: \"scope_end\";\n workflowId: string;\n scopeId: string;\n ts: number;\n durationMs: number;\n /** For race scopes, the ID of the winning branch */\n winnerId?: string;\n}\n\n/**\n * Event emitted when a decision point is encountered.\n * Use this to track conditional logic (if/switch).\n */\nexport interface DecisionStartEvent {\n type: \"decision_start\";\n workflowId: string;\n decisionId: string;\n /** Condition being evaluated (e.g., \"user.role === 'admin'\") */\n condition?: string;\n /** Value being evaluated */\n decisionValue?: unknown;\n /** Name/label for this decision point */\n name?: string;\n ts: number;\n}\n\n/**\n * Event emitted when a decision branch is taken.\n */\nexport interface DecisionBranchEvent {\n type: \"decision_branch\";\n workflowId: string;\n decisionId: string;\n /** Label for this branch (e.g., \"if\", \"else\", \"case 'admin'\") */\n branchLabel: string;\n /** Condition for this branch */\n condition?: string;\n /** Whether this branch was taken */\n taken: boolean;\n ts: number;\n}\n\n/**\n * Event emitted when a decision point completes.\n */\nexport interface DecisionEndEvent {\n type: \"decision_end\";\n workflowId: string;\n decisionId: string;\n /** Which branch was taken */\n branchTaken?: string | boolean;\n ts: number;\n durationMs: number;\n}\n\n/**\n * Event emitted when a step is skipped due to conditional logic.\n */\nexport interface StepSkippedEvent {\n type: \"step_skipped\";\n workflowId: string;\n stepKey?: string;\n name?: string;\n /** Reason why this step was skipped (e.g., \"condition was false\") */\n reason?: string;\n /** The decision that caused this skip */\n decisionId?: string;\n ts: number;\n}\n\n/**\n * Union of scope-related events.\n */\nexport type ScopeEvent = ScopeStartEvent | ScopeEndEvent;\n\n/**\n * Union of decision-related events.\n */\nexport type DecisionEvent = DecisionStartEvent | DecisionBranchEvent | DecisionEndEvent;\n\n// =============================================================================\n// Renderer Types\n// =============================================================================\n\n/**\n * Color scheme for rendering step states.\n */\nexport interface ColorScheme {\n pending: string;\n running: string;\n success: string;\n error: string;\n aborted: string;\n cached: string;\n skipped: string;\n}\n\n/**\n * Options passed to renderers.\n */\nexport interface RenderOptions {\n /** Show timing information (duration) */\n showTimings: boolean;\n /** Show step cache keys */\n showKeys: boolean;\n /** Terminal width for ASCII renderer */\n terminalWidth?: number;\n /** Color scheme */\n colors: ColorScheme;\n}\n\n/**\n * Extended options for Mermaid renderer.\n * Controls how edges are displayed for retries, errors, and timeouts.\n */\nexport interface MermaidRenderOptions extends RenderOptions {\n /** Show retry as self-loop edge (default: true) */\n showRetryEdges?: boolean;\n /** Show error flow to error node (default: true) */\n showErrorEdges?: boolean;\n /** Show timeout as alternative path (default: true) */\n showTimeoutEdges?: boolean;\n}\n\n/**\n * Renderer interface - transforms IR to output format.\n */\nexport interface Renderer {\n /** Unique identifier for this renderer */\n readonly name: string;\n /** Render IR to string output */\n render(ir: WorkflowIR, options: RenderOptions): string;\n /** Whether this renderer supports live (incremental) updates */\n supportsLive?: boolean;\n /** Render incremental update (optional) */\n renderUpdate?(\n ir: WorkflowIR,\n changedNodes: FlowNode[],\n options: RenderOptions\n ): string;\n}\n\n// =============================================================================\n// Visualizer Types\n// =============================================================================\n\n/**\n * Output format for rendering.\n */\nexport type OutputFormat = \"ascii\" | \"mermaid\" | \"json\" | \"logger\" | \"flowchart\";\n\n/**\n * Options for creating a visualizer.\n */\nexport interface VisualizerOptions {\n /** Name for the workflow in visualizations */\n workflowName?: string;\n /** Enable parallel detection heuristics (default: true) */\n detectParallel?: boolean;\n /** Show timing information (default: true) */\n showTimings?: boolean;\n /** Show step keys (default: false) */\n showKeys?: boolean;\n /** Custom color scheme */\n colors?: Partial<ColorScheme>;\n /**\n * Export configuration for URL generation methods.\n * Note: Treated as immutable after creation - do not mutate.\n */\n export?: {\n /** Default export provider (opt-in). If not set, export methods require explicit provider. */\n default?: ExportOptions;\n };\n}\n\n/**\n * Options for createVisualizingWorkflow convenience factory.\n * Combines WorkflowOptions with VisualizerOptions.\n *\n * @example\n * ```typescript\n * const { workflow, visualizer } = createVisualizingWorkflow(deps, {\n * workflowName: 'checkout',\n * showTimings: true,\n * forwardTo: (event) => console.log(event.type),\n * });\n * ```\n */\nexport interface VisualizingWorkflowOptions<E, C = void>\n extends Omit<WorkflowOptions<E, C>, \"onEvent\">,\n VisualizerOptions {\n /** Forward events to additional handler (runs after visualization) */\n forwardTo?: (event: WorkflowEvent<E | UnexpectedError, C>, ctx: C) => void;\n}\n\n/**\n * Options for live visualization.\n */\nexport interface LiveVisualizerOptions extends VisualizerOptions {\n /** Output stream (default: process.stdout) */\n stream?: NodeJS.WriteStream;\n /** Update interval in ms (default: 100) */\n updateInterval?: number;\n}\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Check if a node is a StepNode.\n */\nexport function isStepNode(node: FlowNode): node is StepNode {\n return node.type === \"step\";\n}\n\n/**\n * Check if a node is a SequenceNode.\n */\nexport function isSequenceNode(node: FlowNode): node is SequenceNode {\n return node.type === \"sequence\";\n}\n\n/**\n * Check if a node is a ParallelNode.\n */\nexport function isParallelNode(node: FlowNode): node is ParallelNode {\n return node.type === \"parallel\";\n}\n\n/**\n * Check if a node is a RaceNode.\n */\nexport function isRaceNode(node: FlowNode): node is RaceNode {\n return node.type === \"race\";\n}\n\n/**\n * Check if a node is a DecisionNode.\n */\nexport function isDecisionNode(node: FlowNode): node is DecisionNode {\n return node.type === \"decision\";\n}\n\n/**\n * Check if a node is a StreamNode.\n */\nexport function isStreamNode(node: FlowNode): node is StreamNode {\n return node.type === \"stream\";\n}\n\n/**\n * Check if a node has children.\n */\nexport function hasChildren(\n node: FlowNode\n): node is SequenceNode | ParallelNode | RaceNode | DecisionNode {\n return \"children\" in node || (node.type === \"decision\" && \"branches\" in node);\n}\n\n// =============================================================================\n// Time Travel Types\n// =============================================================================\n\n/**\n * Snapshot of an active step's state at a point in time.\n */\nexport interface ActiveStepSnapshot {\n id: string;\n name?: string;\n key?: string;\n startTs: number;\n retryCount: number;\n timedOut: boolean;\n timeoutMs?: number;\n}\n\n/**\n * A snapshot of the complete IR state at a specific point in time.\n * Used for time-travel debugging - each event creates a snapshot.\n */\nexport interface IRSnapshot {\n /** Unique identifier for this snapshot */\n id: string;\n /** Index in the event sequence (0-based) */\n eventIndex: number;\n /** The event that triggered this snapshot */\n event: unknown; // WorkflowEvent - avoid circular import\n /** Complete IR state at this moment */\n ir: WorkflowIR;\n /** Timestamp when snapshot was taken */\n timestamp: number;\n /** Active step states at this moment (for debugging) */\n activeSteps: Map<string, ActiveStepSnapshot>;\n}\n\n/**\n * State of the time-travel controller.\n */\nexport interface TimeTravelState {\n /** All recorded snapshots */\n snapshots: IRSnapshot[];\n /** Current snapshot index (for playback position) */\n currentIndex: number;\n /** Whether playback is active */\n isPlaying: boolean;\n /** Playback speed multiplier (1.0 = realtime, 2.0 = 2x speed) */\n playbackSpeed: number;\n /** Whether recording is active */\n isRecording: boolean;\n}\n\n// =============================================================================\n// Performance Analysis Types\n// =============================================================================\n\n/**\n * Performance metrics for a single node across multiple runs.\n */\nexport interface NodePerformance {\n /** Node identifier (name or step ID) */\n nodeId: string;\n /** Average duration across all samples */\n avgDurationMs: number;\n /** Minimum duration observed */\n minDurationMs: number;\n /** Maximum duration observed */\n maxDurationMs: number;\n /** Standard deviation of durations */\n stdDevMs: number;\n /** Number of timing samples collected */\n samples: number;\n /** Retry frequency (0-1, where 1 = always retries) */\n retryRate: number;\n /** Timeout frequency (0-1) */\n timeoutRate: number;\n /** Error rate (0-1) */\n errorRate: number;\n /** Percentile data for distribution analysis */\n percentiles: {\n p50: number;\n p90: number;\n p95: number;\n p99: number;\n };\n}\n\n/**\n * Heatmap data for visualizing performance across nodes.\n */\nexport interface HeatmapData {\n /** Map of node ID to heat level (0-1, where 1 is hottest/slowest) */\n heat: Map<string, number>;\n /** The metric used for heat calculation */\n metric: \"duration\" | \"retryRate\" | \"errorRate\";\n /** Statistics used to compute heat values */\n stats: {\n /** Minimum value in the dataset */\n min: number;\n /** Maximum value in the dataset */\n max: number;\n /** Mean value */\n mean: number;\n /** Threshold above which a node is considered \"hot\" */\n threshold: number;\n };\n}\n\n/**\n * Heat level for visual styling.\n */\nexport type HeatLevel = \"cold\" | \"cool\" | \"neutral\" | \"warm\" | \"hot\" | \"critical\";\n\n// =============================================================================\n// HTML Renderer Types\n// =============================================================================\n\n/**\n * Theme for the HTML visualizer.\n */\nexport type HTMLTheme = \"light\" | \"dark\" | \"auto\";\n\n/**\n * Layout direction for the workflow diagram.\n */\nexport type LayoutDirection = \"TB\" | \"LR\" | \"BT\" | \"RL\";\n\n/**\n * Options for the HTML renderer.\n */\nexport interface HTMLRenderOptions extends RenderOptions {\n /** Enable interactive features (click to inspect, zoom/pan) */\n interactive: boolean;\n /** Include time-travel controls */\n timeTravel: boolean;\n /** Include performance heatmap overlay */\n heatmap: boolean;\n /** Animation duration for transitions (ms) */\n animationDuration: number;\n /** Color theme */\n theme: HTMLTheme;\n /** Diagram layout direction */\n layout: LayoutDirection;\n /** Heatmap data (if heatmap is enabled) */\n heatmapData?: HeatmapData;\n /** WebSocket URL for live updates (if streaming) */\n wsUrl?: string;\n}\n\n/**\n * Message sent from the web visualizer to the dev server.\n */\nexport interface WebVisualizerMessage {\n type:\n | \"time_travel_seek\"\n | \"time_travel_play\"\n | \"time_travel_pause\"\n | \"time_travel_step_forward\"\n | \"time_travel_step_backward\"\n | \"request_snapshots\"\n | \"toggle_heatmap\"\n | \"set_heatmap_metric\";\n payload?: unknown;\n}\n\n/**\n * Message sent from the dev server to the web visualizer.\n */\nexport interface ServerMessage {\n type:\n | \"ir_update\"\n | \"snapshot\"\n | \"snapshots_list\"\n | \"performance_data\"\n | \"workflow_complete\"\n | \"time_travel_state\";\n payload: unknown;\n}\n\n// =============================================================================\n// Enhanced ASCII Renderer Types\n// =============================================================================\n\n/**\n * Extended render options for the enhanced ASCII renderer.\n */\nexport interface EnhancedRenderOptions extends RenderOptions {\n /** Show performance heatmap coloring */\n showHeatmap?: boolean;\n /** Heatmap data for coloring nodes */\n heatmapData?: HeatmapData;\n /** Show timing sparklines (requires historical data) */\n showSparklines?: boolean;\n /** Historical timing data for sparklines: nodeId → array of durations */\n timingHistory?: Map<string, number[]>;\n}\n\n/**\n * Options for the flowchart ASCII renderer.\n * Renders workflow as a proper flowchart with boxes and arrows.\n */\nexport interface FlowchartRenderOptions extends EnhancedRenderOptions {\n /** Show start and end nodes (default: true) */\n showStartEnd?: boolean;\n /** Reduce vertical spacing between nodes (default: false) */\n compact?: boolean;\n /** Box border style (default: 'single') */\n boxStyle?: \"single\" | \"double\" | \"rounded\";\n}\n\n// =============================================================================\n// Hook Execution Types\n// =============================================================================\n\n/**\n * State of a hook execution.\n */\nexport type HookState = \"pending\" | \"running\" | \"success\" | \"error\";\n\n/**\n * Execution record for a workflow hook.\n */\nexport interface HookExecution {\n /** Hook type identifier */\n type: \"shouldRun\" | \"onBeforeStart\" | \"onAfterStep\";\n /** Execution state */\n state: HookState;\n /** Timestamp when hook started */\n ts: number;\n /** Duration in milliseconds */\n durationMs?: number;\n /** Error if hook failed */\n error?: unknown;\n /** Additional context (e.g., stepKey for onAfterStep) */\n context?: {\n /** Step key for onAfterStep hooks */\n stepKey?: string;\n /** Result of shouldRun hook */\n result?: boolean;\n /** Whether workflow was skipped due to shouldRun returning false */\n skipped?: boolean;\n };\n}\n\n/**\n * Hook execution summary for the workflow.\n */\nexport interface WorkflowHooks {\n /** shouldRun hook execution (if configured) */\n shouldRun?: HookExecution;\n /** onBeforeStart hook execution (if configured) */\n onBeforeStart?: HookExecution;\n /** onAfterStep hook executions (keyed by stepKey) */\n onAfterStep: Map<string, HookExecution>;\n}\n\n// =============================================================================\n// Export Types\n// =============================================================================\n\n/**\n * Export format for diagram URLs.\n */\nexport type ExportFormat = \"svg\" | \"png\" | \"pdf\";\n\n/**\n * Diagram source - future-proof union for multiple diagram types.\n * Uses \"kind\" internally, maps to \"diagramType\" for Kroki API.\n */\nexport type DiagramSource =\n | { kind: \"mermaid\"; source: string }\n | { kind: \"graphviz\"; source: string }\n | { kind: \"plantuml\"; source: string };\n\n/**\n * Kroki-specific export options.\n * Note: No background/scale - Kroki doesn't support them for mermaid diagrams.\n */\nexport interface KrokiExportOptions {\n /** Provider identifier */\n provider: \"kroki\";\n /** Base URL for self-hosted Kroki (default: https://kroki.io) */\n baseUrl?: string;\n}\n\n/**\n * Mermaid.ink-specific export options.\n * Supports additional styling options like background, scale, and theme.\n */\nexport interface MermaidInkExportOptions {\n /** Provider identifier */\n provider: \"mermaid-ink\";\n /** Mermaid theme */\n mermaidTheme?: \"default\" | \"dark\" | \"forest\" | \"neutral\";\n /** Background color: \"transparent\" or hex color (e.g., \"1b1b1f\") */\n background?: \"transparent\" | string;\n /** Image scale (1-3) */\n scale?: number;\n /** Fit PDF to diagram size */\n fit?: boolean;\n /** Image width in pixels */\n width?: number;\n /** Image height in pixels */\n height?: number;\n /** Paper size for PDF */\n paper?: \"a4\" | \"letter\";\n}\n\n/**\n * Discriminated union of export options.\n * Provider is the discriminant - no implicit defaults.\n */\nexport type ExportOptions = KrokiExportOptions | MermaidInkExportOptions;\n","/**\n * Timing utilities for workflow visualization.\n */\n\n/**\n * Format duration in milliseconds to a human-readable string.\n *\n * @example\n * formatDuration(23) // \"23ms\"\n * formatDuration(1500) // \"1.5s\"\n * formatDuration(65000) // \"1m 5s\"\n */\nexport function formatDuration(ms: number): string {\n if (ms < 1000) {\n return `${Math.round(ms)}ms`;\n }\n\n if (ms < 60000) {\n const seconds = ms / 1000;\n // Show one decimal for seconds\n return `${seconds.toFixed(1).replace(/\\.0$/, \"\")}s`;\n }\n\n let minutes = Math.floor(ms / 60000);\n let seconds = Math.round((ms % 60000) / 1000);\n if (seconds >= 60) {\n minutes += 1;\n seconds = 0;\n }\n\n if (seconds === 0) {\n return `${minutes}m`;\n }\n\n return `${minutes}m ${seconds}s`;\n}\n\n/**\n * Generate a unique ID for nodes.\n */\nexport function generateId(): string {\n return `node_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;\n}\n","/**\n * ANSI color utilities for terminal output.\n */\n\nimport type { ColorScheme, StepState } from \"../types\";\n\n// =============================================================================\n// ANSI Escape Codes\n// =============================================================================\n\nconst RESET = \"\\x1b[0m\";\nconst BOLD = \"\\x1b[1m\";\nconst DIM = \"\\x1b[2m\";\n\n// Foreground colors\nconst FG_RED = \"\\x1b[31m\";\nconst FG_GREEN = \"\\x1b[32m\";\nconst FG_YELLOW = \"\\x1b[33m\";\nconst FG_BLUE = \"\\x1b[34m\";\nconst FG_GRAY = \"\\x1b[90m\";\nconst FG_WHITE = \"\\x1b[37m\";\n\n// =============================================================================\n// Color Functions\n// =============================================================================\n\n/**\n * Apply ANSI color to text.\n */\nexport function colorize(text: string, color: string): string {\n if (!color) return text;\n return `${color}${text}${RESET}`;\n}\n\n/**\n * Make text bold.\n */\nexport function bold(text: string): string {\n return `${BOLD}${text}${RESET}`;\n}\n\n/**\n * Make text dim.\n */\nexport function dim(text: string): string {\n return `${DIM}${text}${RESET}`;\n}\n\n// =============================================================================\n// Default Color Scheme\n// =============================================================================\n\n/**\n * Default ANSI color scheme for step states.\n */\nexport const defaultColorScheme: ColorScheme = {\n pending: FG_WHITE,\n running: FG_YELLOW,\n success: FG_GREEN,\n error: FG_RED,\n aborted: FG_GRAY,\n cached: FG_BLUE,\n skipped: DIM + FG_GRAY, // Dim gray for skipped steps\n};\n\n// =============================================================================\n// State Symbols\n// =============================================================================\n\n/**\n * Get the symbol for a step state.\n */\nexport function getStateSymbol(state: StepState): string {\n switch (state) {\n case \"pending\":\n return \"○\"; // Empty circle\n case \"running\":\n return \"⟳\"; // Rotating arrows\n case \"success\":\n return \"✓\"; // Check mark\n case \"error\":\n return \"✗\"; // X mark\n case \"aborted\":\n return \"⊘\"; // Circled slash\n case \"cached\":\n return \"↺\"; // Cached/replay\n case \"skipped\":\n return \"⊘\"; // Circled slash (same as aborted, but different color)\n }\n}\n\n/**\n * Get the colored symbol for a step state.\n */\nexport function getColoredSymbol(state: StepState, colors: ColorScheme): string {\n const symbol = getStateSymbol(state);\n return colorize(symbol, colors[state]);\n}\n\n/**\n * Get colored text based on step state.\n */\nexport function colorByState(\n text: string,\n state: StepState,\n colors: ColorScheme\n): string {\n return colorize(text, colors[state]);\n}\n\n// =============================================================================\n// Strip ANSI\n// =============================================================================\n\n/**\n * Strip ANSI escape codes from a string.\n * Useful for calculating visible string length.\n */\nexport function stripAnsi(str: string): string {\n // eslint-disable-next-line no-control-regex\n return str.replace(/\\x1b\\[[0-9;]*m/g, \"\");\n}\n\n/**\n * Get the visible length of a string (without ANSI codes).\n */\nexport function visibleLength(str: string): string {\n return stripAnsi(str);\n}\n","/**\n * Mermaid Diagram Renderer\n *\n * Renders the workflow IR as a Mermaid flowchart diagram.\n * Supports sequential flows, parallel (subgraph), and race patterns.\n */\n\nimport { ok, err, type Result } from \"awaitly\";\nimport type {\n FlowNode,\n ParallelNode,\n RaceNode,\n DecisionNode,\n StreamNode,\n Renderer,\n RenderOptions,\n MermaidRenderOptions,\n StepNode,\n StepState,\n WorkflowIR,\n EnhancedRenderOptions,\n HeatLevel,\n WorkflowHooks,\n} from \"../types\";\nimport { isParallelNode, isRaceNode, isStepNode, isDecisionNode, isStreamNode } from \"../types\";\nimport { formatDuration } from \"../utils/timing\";\nimport { getHeatLevel } from \"../performance-analyzer\";\n\n/**\n * Error types for stringify operations.\n */\nexport type StringifyError = \"STRINGIFY_ERROR\";\n\n// =============================================================================\n// Mermaid Style Definitions\n// =============================================================================\n\n/**\n * Get Mermaid class definition for step states.\n * Colors inspired by AWS Step Functions and XState visualizers for professional appearance.\n */\nfunction getStyleDefinitions(): string[] {\n return [\n // Pending - light gray, subtle\n \" classDef pending fill:#f3f4f6,stroke:#9ca3af,stroke-width:2px,color:#374151\",\n // Running - amber/yellow, indicates active execution\n \" classDef running fill:#fef3c7,stroke:#f59e0b,stroke-width:3px,color:#92400e\",\n // Success - green, clear positive indicator\n \" classDef success fill:#d1fae5,stroke:#10b981,stroke-width:3px,color:#065f46\",\n // Error - red, clear negative indicator\n \" classDef error fill:#fee2e2,stroke:#ef4444,stroke-width:3px,color:#991b1b\",\n // Aborted - gray, indicates cancellation\n \" classDef aborted fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#4b5563,stroke-dasharray: 5 5\",\n // Cached - blue, indicates cache hit\n \" classDef cached fill:#dbeafe,stroke:#3b82f6,stroke-width:3px,color:#1e40af\",\n // Skipped - light gray with dashed border\n \" classDef skipped fill:#f9fafb,stroke:#d1d5db,stroke-width:2px,color:#6b7280,stroke-dasharray: 5 5\",\n // Stream - purple/violet, indicates streaming operation\n \" classDef stream fill:#ede9fe,stroke:#8b5cf6,stroke-width:3px,color:#5b21b6\",\n // Stream active - purple with animation indicator\n \" classDef streamActive fill:#ddd6fe,stroke:#7c3aed,stroke-width:3px,color:#4c1d95\",\n // Stream error - purple-red for stream errors\n \" classDef streamError fill:#fce7f3,stroke:#db2777,stroke-width:3px,color:#9d174d\",\n ];\n}\n\n/**\n * Get Mermaid class definitions for heatmap visualization.\n */\nfunction getHeatmapStyleDefinitions(): string[] {\n return [\n // Heatmap colors - cold to hot\n \" classDef heat_cold fill:#dbeafe,stroke:#3b82f6,stroke-width:2px,color:#1e40af\",\n \" classDef heat_cool fill:#ccfbf1,stroke:#14b8a6,stroke-width:2px,color:#0f766e\",\n \" classDef heat_neutral fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#374151\",\n \" classDef heat_warm fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#92400e\",\n \" classDef heat_hot fill:#fed7aa,stroke:#f97316,stroke-width:3px,color:#c2410c\",\n \" classDef heat_critical fill:#fecaca,stroke:#ef4444,stroke-width:3px,color:#b91c1c\",\n ];\n}\n\n/**\n * Get the Mermaid class name for a heat level.\n */\nfunction getHeatClass(level: HeatLevel): string {\n return `heat_${level}`;\n}\n\n/**\n * Get the Mermaid class name for a step state.\n */\nfunction getStateClass(state: StepState): string {\n return state;\n}\n\n/**\n * Get Mermaid class definitions for hook visualization.\n */\nfunction getHookStyleDefinitions(): string[] {\n return [\n // Hook styles - gear icon aesthetic\n \" classDef hook_success fill:#e0f2fe,stroke:#0284c7,stroke-width:2px,color:#0c4a6e\",\n \" classDef hook_error fill:#fef2f2,stroke:#dc2626,stroke-width:2px,color:#7f1d1d\",\n ];\n}\n\n/**\n * Safely stringify a value, handling circular references and BigInt.\n * Returns Result with either the stringified value or an error.\n */\nfunction safeStringify(value: unknown): Result<string, StringifyError> {\n try {\n const replacer = (_key: string, v: unknown): unknown => {\n if (typeof v !== \"bigint\") return v;\n const n = Number(v);\n return Number.isSafeInteger(n) ? n : v.toString();\n };\n return ok(JSON.stringify(value, replacer));\n } catch {\n return err(\"STRINGIFY_ERROR\");\n }\n}\n\n/**\n * Get stringified value or fallback for unserializable values.\n */\nfunction getStringified(value: unknown): string {\n const result = safeStringify(value);\n return result.ok ? result.value : \"[unserializable]\";\n}\n\n/**\n * Render hooks as nodes before the workflow starts.\n * Returns the ID of the last hook node (to connect to workflow start).\n */\nfunction renderHooks(\n hooks: WorkflowHooks,\n lines: string[],\n options: RenderOptions\n): { lastHookId: string | undefined } {\n let lastHookId: string | undefined;\n\n // Render shouldRun hook\n if (hooks.shouldRun) {\n const hookId = \"hook_shouldRun\";\n const state = hooks.shouldRun.state === \"success\" ? \"hook_success\" : \"hook_error\";\n const icon = hooks.shouldRun.state === \"success\" ? \"⚙\" : \"⚠\";\n const timing = options.showTimings && hooks.shouldRun.durationMs !== undefined\n ? ` ${formatDuration(hooks.shouldRun.durationMs)}`\n : \"\";\n const context = hooks.shouldRun.context?.skipped\n ? \"\\\\nskipped workflow\"\n : hooks.shouldRun.context?.result === true\n ? \"\\\\nproceed\"\n : \"\";\n\n lines.push(` ${hookId}[[\"${icon} shouldRun${context}${timing}\"]]:::${state}`);\n lastHookId = hookId;\n }\n\n // Render onBeforeStart hook\n if (hooks.onBeforeStart) {\n const hookId = \"hook_beforeStart\";\n const state = hooks.onBeforeStart.state === \"success\" ? \"hook_success\" : \"hook_error\";\n const icon = hooks.onBeforeStart.state === \"success\" ? \"⚙\" : \"⚠\";\n const timing = options.showTimings && hooks.onBeforeStart.durationMs !== undefined\n ? ` ${formatDuration(hooks.onBeforeStart.durationMs)}`\n : \"\";\n const context = hooks.onBeforeStart.context?.skipped\n ? \"\\\\nskipped workflow\"\n : \"\";\n\n lines.push(` ${hookId}[[\"${icon} onBeforeStart${context}${timing}\"]]:::${state}`);\n\n // Connect from previous hook if exists\n if (lastHookId) {\n lines.push(` ${lastHookId} --> ${hookId}`);\n }\n lastHookId = hookId;\n }\n\n return { lastHookId };\n}\n\n// =============================================================================\n// Node ID Generation\n// =============================================================================\n\nlet nodeCounter = 0;\nconst usedDecisionIds = new Set<string>();\nconst usedStepIds = new Set<string>();\n\nfunction generateNodeId(prefix: string = \"node\"): string {\n return `${prefix}_${++nodeCounter}`;\n}\n\nfunction resetNodeCounter(): void {\n nodeCounter = 0;\n usedDecisionIds.clear();\n usedStepIds.clear();\n}\n\n// =============================================================================\n// Mermaid Text Escaping\n// =============================================================================\n\n/**\n * Escape text for use in Mermaid diagrams.\n * Only escapes characters that break quoted strings in Mermaid.\n *\n * With bracket-quote syntax (e.g., `nodeId[\"label\"]`), special characters\n * like {}[]() are allowed inside the quoted label.\n *\n * @param text - Text to escape\n * @returns Escaped text safe for Mermaid quoted labels\n */\nfunction escapeMermaidText(text: string): string {\n return text\n .replace(/\"/g, \"#quot;\") // Escape double quotes for Mermaid\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .trim();\n}\n\n/**\n * Escape text for use in Mermaid subgraph names.\n * Subgraph names need special handling - brackets and braces must be removed.\n *\n * @param text - Text to escape for subgraph name\n * @returns Escaped text safe for subgraph names\n */\nfunction escapeSubgraphName(text: string): string {\n return escapeMermaidText(text)\n .replace(/[{}[\\]()]/g, \"\"); // Remove brackets, braces, and parentheses from subgraph names\n}\n\n// =============================================================================\n// Mermaid Renderer\n// =============================================================================\n\n/**\n * Create the Mermaid diagram renderer.\n */\nexport function mermaidRenderer(): Renderer {\n return {\n name: \"mermaid\",\n supportsLive: false,\n\n render(ir: WorkflowIR, options: RenderOptions): string {\n resetNodeCounter();\n const lines: string[] = [];\n\n // Check for enhanced options (heatmap)\n const enhanced = options as EnhancedRenderOptions;\n\n // Diagram header\n lines.push(\"flowchart TD\");\n\n // Render hooks first (if any)\n let hookExitId: string | undefined;\n if (ir.hooks) {\n const hookResult = renderHooks(ir.hooks, lines, options);\n hookExitId = hookResult.lastHookId;\n }\n\n // Start node - more visually distinctive\n const startId = \"start\";\n lines.push(` ${startId}((\"▶ Start\"))`);\n\n // Connect hooks to start node\n if (hookExitId) {\n lines.push(` ${hookExitId} --> ${startId}`);\n }\n\n // Track the last node for connections\n let prevNodeId = startId;\n\n // Render children (passing hooks for onAfterStep annotations)\n for (const child of ir.root.children) {\n const result = renderNode(child, options, lines, enhanced, ir.hooks);\n lines.push(` ${prevNodeId} --> ${result.entryId}`);\n prevNodeId = result.exitId;\n }\n\n // End node (if workflow reached a terminal state) - more visually distinctive\n const terminalStates = [\"success\", \"error\", \"aborted\"] as const;\n if (terminalStates.includes(ir.root.state as (typeof terminalStates)[number])) {\n const endId = \"finish\";\n const endIcon =\n ir.root.state === \"success\" ? \"✓\"\n : ir.root.state === \"error\" ? \"✗\"\n : \"⊘\";\n const endLabel =\n ir.root.state === \"success\" ? \"Done\"\n : ir.root.state === \"error\" ? \"Failed\"\n : \"Cancelled\";\n const endShape = `((\"${endIcon} ${endLabel}\"))`;\n const endClass =\n ir.root.state === \"success\" ? \":::success\"\n : ir.root.state === \"error\" ? \":::error\"\n : \":::aborted\";\n lines.push(` ${endId}${endShape}${endClass}`);\n lines.push(` ${prevNodeId} --> ${endId}`);\n }\n\n // Add style definitions\n lines.push(\"\");\n lines.push(...getStyleDefinitions());\n\n // Add heatmap styles if enabled\n if (enhanced.showHeatmap) {\n lines.push(...getHeatmapStyleDefinitions());\n }\n\n // Add hook styles if hooks were rendered\n if (ir.hooks) {\n lines.push(...getHookStyleDefinitions());\n }\n\n return lines.join(\"\\n\");\n },\n };\n}\n\n/**\n * Render result with entry and exit node IDs.\n */\ninterface RenderResult {\n entryId: string;\n exitId: string;\n}\n\n/**\n * Render a node and return its entry/exit IDs.\n */\nfunction renderNode(\n node: FlowNode,\n options: RenderOptions,\n lines: string[],\n enhanced?: EnhancedRenderOptions,\n hooks?: WorkflowHooks\n): RenderResult {\n if (isStepNode(node)) {\n return renderStepNode(node, options, lines, enhanced, hooks);\n } else if (isParallelNode(node)) {\n return renderParallelNode(node, options, lines, enhanced, hooks);\n } else if (isRaceNode(node)) {\n return renderRaceNode(node, options, lines, enhanced, hooks);\n } else if (isDecisionNode(node)) {\n return renderDecisionNode(node, options, lines, enhanced, hooks);\n } else if (isStreamNode(node)) {\n return renderStreamNode(node, options, lines);\n }\n\n // Fallback for sequence or unknown nodes\n const id = generateNodeId(\"unknown\");\n lines.push(` ${id}[\"Unknown Node\"]`);\n return { entryId: id, exitId: id };\n}\n\n/**\n * Render a step node.\n */\nfunction renderStepNode(\n node: StepNode,\n options: RenderOptions,\n lines: string[],\n enhanced?: EnhancedRenderOptions,\n hooks?: WorkflowHooks\n): RenderResult {\n // Cast to MermaidRenderOptions to access extended options\n const mermaidOpts = options as MermaidRenderOptions;\n const showRetryEdges = mermaidOpts.showRetryEdges ?? true;\n const showErrorEdges = mermaidOpts.showErrorEdges ?? true;\n const showTimeoutEdges = mermaidOpts.showTimeoutEdges ?? true;\n\n // Generate step ID, ensuring uniqueness even with duplicate keys\n let id = node.key\n ? `step_${node.key.replace(/[^a-zA-Z0-9]/g, \"_\")}`\n : generateNodeId(\"step\");\n\n // Ensure uniqueness by appending suffix if collision\n if (usedStepIds.has(id)) {\n let suffix = 2;\n while (usedStepIds.has(`${id}_${suffix}`)) {\n suffix++;\n }\n id = `${id}_${suffix}`;\n }\n usedStepIds.add(id);\n\n const baseLabel = node.name ?? node.key ?? \"Step\";\n const labelText = options.showKeys && node.key && node.name\n ? `${baseLabel} [${node.key}]`\n : baseLabel;\n const label = escapeMermaidText(labelText);\n\n // Format timing - use space instead of parentheses to avoid Mermaid parse errors\n const timing =\n options.showTimings && node.durationMs !== undefined\n ? ` ${formatDuration(node.durationMs)}`\n : \"\";\n\n // Add visual indicators based on state (like XState/AWS Step Functions)\n let stateIcon = \"\";\n switch (node.state) {\n case \"success\":\n stateIcon = \"✓ \";\n break;\n case \"error\":\n stateIcon = \"✗ \";\n break;\n case \"cached\":\n stateIcon = \"💾 \";\n break;\n case \"running\":\n stateIcon = \"⏳ \";\n break;\n case \"skipped\":\n stateIcon = \"⊘ \";\n break;\n }\n\n // Add input/output info if available\n // Use newlines for multi-line labels, but escape special characters\n let ioInfo = \"\";\n if (node.input !== undefined) {\n const inputStr = typeof node.input === \"string\"\n ? escapeMermaidText(node.input)\n : escapeMermaidText(getStringified(node.input).slice(0, 20));\n ioInfo += `\\\\nin: ${inputStr}`;\n }\n if (node.output !== undefined && node.state === \"success\") {\n const outputStr = typeof node.output === \"string\"\n ? escapeMermaidText(node.output)\n : escapeMermaidText(getStringified(node.output).slice(0, 20));\n ioInfo += `\\\\nout: ${outputStr}`;\n }\n\n // Add onAfterStep hook info if present (check by key first, then by id)\n let hookInfo = \"\";\n const hookKey = node.key ?? node.id;\n if (hooks && hookKey && hooks.onAfterStep.has(hookKey)) {\n const hookExec = hooks.onAfterStep.get(hookKey)!;\n const hookIcon = hookExec.state === \"success\" ? \"⚙\" : \"⚠\";\n const hookTiming = options.showTimings && hookExec.durationMs !== undefined\n ? ` ${formatDuration(hookExec.durationMs)}`\n : \"\";\n hookInfo = `\\\\n${hookIcon} hook${hookTiming}`;\n }\n\n // Combine all label parts with icon (retry/timeout info moved to edges)\n const escapedLabel = (stateIcon + label + ioInfo + hookInfo + timing).trim();\n\n // Determine class: use heatmap if enabled and data available, otherwise use state\n // Lookup order matches PerformanceAnalyzer: key ?? name ?? id\n let nodeClass: string;\n const heat = enhanced?.showHeatmap && enhanced.heatmapData\n ? enhanced.heatmapData.heat.get(node.key ?? \"\") ??\n enhanced.heatmapData.heat.get(node.name ?? \"\") ??\n enhanced.heatmapData.heat.get(node.id)\n : undefined;\n\n if (heat !== undefined) {\n const level = getHeatLevel(heat);\n nodeClass = getHeatClass(level);\n } else {\n nodeClass = getStateClass(node.state);\n }\n\n // Use different shapes based on state (like AWS Step Functions)\n let shape: string;\n switch (node.state) {\n case \"error\":\n // Hexagon for errors (more distinctive)\n shape = `{{\"${escapedLabel}\"}}`;\n break;\n case \"cached\":\n // Rounded rectangle with double border for cached\n shape = `[(\"${escapedLabel}\")]`;\n break;\n case \"skipped\":\n // Dashed border via class (applied once in lines.push below)\n shape = `[\"${escapedLabel}\"]`;\n break;\n default:\n // Standard rectangle for normal steps\n shape = `[\"${escapedLabel}\"]`;\n }\n\n lines.push(` ${id}${shape}:::${nodeClass}`);\n\n // NEW: Add retry loop edge (self-loop showing retries)\n if (showRetryEdges && node.retryCount !== undefined && node.retryCount > 0) {\n const retryLabel = `↻ ${node.retryCount} retr${node.retryCount === 1 ? \"y\" : \"ies\"}`;\n lines.push(` ${id} -.->|\"${retryLabel}\"| ${id}`);\n }\n\n // NEW: Add error path edge (flow to error node)\n if (showErrorEdges && node.state === \"error\" && node.error !== undefined) {\n const errorNodeId = `ERR_${id}`;\n const errorLabel = escapeMermaidText(String(node.error)).slice(0, 30);\n lines.push(` ${errorNodeId}{{\"${errorLabel}\"}}`);\n lines.push(` ${id} -->|error| ${errorNodeId}`);\n lines.push(` style ${errorNodeId} fill:#fee2e2,stroke:#dc2626`);\n }\n\n // NEW: Add timeout edge (alternative timeout path)\n if (showTimeoutEdges && node.timedOut) {\n const timeoutNodeId = `TO_${id}`;\n const timeoutMs = node.timeoutMs !== undefined ? `${node.timeoutMs}ms` : \"\";\n lines.push(` ${timeoutNodeId}{{\"⏱ Timeout ${timeoutMs}\"}}`);\n lines.push(` ${id} -.->|timeout| ${timeoutNodeId}`);\n lines.push(` style ${timeoutNodeId} fill:#fef3c7,stroke:#f59e0b`);\n }\n\n return { entryId: id, exitId: id };\n}\n\n/**\n * Render a parallel node as a subgraph with fork/join.\n */\nfunction renderParallelNode(\n node: ParallelNode,\n options: RenderOptions,\n lines: string[],\n enhanced?: EnhancedRenderOptions,\n hooks?: WorkflowHooks\n): RenderResult {\n const subgraphId = generateNodeId(\"parallel\");\n const forkId = `${subgraphId}_fork`;\n const joinId = `${subgraphId}_join`;\n const name = escapeSubgraphName(node.name ?? \"Parallel\");\n const modeLabel = node.mode === \"allSettled\" ? \" (allSettled)\" : \"\";\n\n // If no children, render as a simple step-like node with note\n if (node.children.length === 0) {\n const id = subgraphId;\n const label = escapeMermaidText(`${name}${modeLabel}`);\n const note = \"operations not individually tracked\";\n const timing = options.showTimings && node.durationMs !== undefined\n ? ` ${formatDuration(node.durationMs)}`\n : \"\";\n\n // Use a rounded rectangle to indicate it's a parallel operation\n lines.push(` ${id}[\"${label}${timing}\\\\n${note}\"]:::${getStateClass(node.state)}`);\n return { entryId: id, exitId: id };\n }\n\n // Subgraph for parallel block with proper visual hierarchy\n lines.push(` subgraph ${subgraphId}[\"${name}${modeLabel}\"]`);\n lines.push(` direction TB`);\n\n // Fork node (diamond) - more visually distinct\n lines.push(` ${forkId}{\"⚡ Fork\"}`);\n\n // Child branches - render in parallel columns\n const childExitIds: string[] = [];\n for (const child of node.children) {\n const result = renderNode(child, options, lines, enhanced, hooks);\n lines.push(` ${forkId} --> ${result.entryId}`);\n childExitIds.push(result.exitId);\n }\n\n // Join node (diamond) - visually distinct\n lines.push(` ${joinId}{\"✓ Join\"}`);\n for (const exitId of childExitIds) {\n lines.push(` ${exitId} --> ${joinId}`);\n }\n\n lines.push(` end`);\n\n // Apply state styling to subgraph\n const stateClass = getStateClass(node.state);\n lines.push(` class ${subgraphId} ${stateClass}`);\n\n return { entryId: forkId, exitId: joinId };\n}\n\n/**\n * Render a race node as a subgraph with racing indicator.\n */\nfunction renderRaceNode(\n node: RaceNode,\n options: RenderOptions,\n lines: string[],\n enhanced?: EnhancedRenderOptions,\n hooks?: WorkflowHooks\n): RenderResult {\n const subgraphId = generateNodeId(\"race\");\n const startId = `${subgraphId}_start`;\n const endId = `${subgraphId}_end`;\n const name = escapeSubgraphName(node.name ?? \"Race\");\n\n // If no children, render as a simple step-like node with note\n if (node.children.length === 0) {\n const id = subgraphId;\n const label = escapeMermaidText(name);\n const note = \"operations not individually tracked\";\n const timing = options.showTimings && node.durationMs !== undefined\n ? ` ${formatDuration(node.durationMs)}`\n : \"\";\n\n lines.push(` ${id}[\"⚡ ${label}${timing}\\\\n${note}\"]:::${getStateClass(node.state)}`);\n return { entryId: id, exitId: id };\n }\n\n // Subgraph for race block - escape name and emoji is safe in quoted strings\n lines.push(` subgraph ${subgraphId}[\"⚡ ${name}\"]`);\n lines.push(` direction TB`);\n\n // Start node - use a more distinctive shape\n lines.push(` ${startId}((\"🏁 Start\"))`);\n\n // Child branches\n const childExitIds: Array<{ exitId: string; isWinner: boolean }> = [];\n let winnerExitId: string | undefined;\n\n for (const child of node.children) {\n const result = renderNode(child, options, lines, enhanced, hooks);\n const isWinner = node.winnerId === child.id;\n lines.push(` ${startId} --> ${result.entryId}`);\n\n if (isWinner) {\n winnerExitId = result.exitId;\n }\n childExitIds.push({ exitId: result.exitId, isWinner });\n }\n\n // End node - more distinctive\n lines.push(` ${endId}((\"✓ First\"))`);\n\n // Connect winner with thick line, others with dashed (cancelled)\n for (const { exitId, isWinner } of childExitIds) {\n if (isWinner && winnerExitId) {\n lines.push(` ${exitId} ==>|🏆 Winner| ${endId}`);\n } else if (node.winnerId) {\n // Non-winner: show as cancelled\n lines.push(` ${exitId} -. cancelled .-> ${endId}`);\n } else {\n // No winner determined, normal connection\n lines.push(` ${exitId} --> ${endId}`);\n }\n }\n\n lines.push(` end`);\n\n const stateClass = getStateClass(node.state);\n lines.push(` class ${subgraphId} ${stateClass}`);\n\n return { entryId: startId, exitId: endId };\n}\n\n/**\n * Render a decision node as a diamond with branches.\n */\nfunction renderDecisionNode(\n node: DecisionNode,\n options: RenderOptions,\n lines: string[],\n enhanced?: EnhancedRenderOptions,\n hooks?: WorkflowHooks\n): RenderResult {\n // Generate decision ID, ensuring uniqueness even with duplicate keys\n let decisionId = node.key\n ? `decision_${node.key.replace(/[^a-zA-Z0-9]/g, \"_\")}`\n : generateNodeId(\"decision\");\n\n // Ensure uniqueness by appending suffix if collision\n if (usedDecisionIds.has(decisionId)) {\n let suffix = 2;\n while (usedDecisionIds.has(`${decisionId}_${suffix}`)) {\n suffix++;\n }\n decisionId = `${decisionId}_${suffix}`;\n }\n usedDecisionIds.add(decisionId);\n\n // Escape condition and decision value - remove characters that break Mermaid\n const condition = escapeMermaidText(node.condition ?? \"condition\");\n const decisionValue = node.decisionValue !== undefined\n ? ` = ${escapeMermaidText(String(node.decisionValue)).slice(0, 30)}`\n : \"\";\n\n // Decision diamond - ensure no invalid characters\n const decisionLabel = `${condition}${decisionValue}`.trim();\n lines.push(` ${decisionId}{\"${decisionLabel}\"}`);\n\n // Render branches\n const branchExitIds: string[] = [];\n let takenBranchExitId: string | undefined;\n const usedBranchIds = new Set<string>();\n\n for (const branch of node.branches) {\n // Generate base branch ID from sanitized label\n let branchId = `${decisionId}_${branch.label.replace(/[^a-zA-Z0-9]/g, \"_\")}`;\n // Ensure uniqueness by appending index if collision\n if (usedBranchIds.has(branchId)) {\n let suffix = 2;\n while (usedBranchIds.has(`${branchId}_${suffix}`)) {\n suffix++;\n }\n branchId = `${branchId}_${suffix}`;\n }\n usedBranchIds.add(branchId);\n // Escape branch label - remove parentheses and other special chars\n const branchLabelText = escapeMermaidText(branch.label);\n const branchLabel = branch.taken\n ? `${branchLabelText} ✓`\n : `${branchLabelText} skipped`;\n const branchClass = branch.taken ? \":::success\" : \":::skipped\";\n\n // Branch label node\n lines.push(` ${branchId}[\"${branchLabel}\"]${branchClass}`);\n\n // Connect decision to branch\n // Mermaid edge labels must be simple text - escape special characters\n // Also remove pipe character as it's used for edge label syntax\n const edgeLabel = branch.condition\n ? `|${escapeMermaidText(branch.condition).replace(/\\|/g, \"\")}|`\n : \"\";\n lines.push(` ${decisionId} -->${edgeLabel} ${branchId}`);\n\n // Render children of this branch\n if (branch.children.length > 0) {\n let prevId = branchId;\n for (const child of branch.children) {\n const result = renderNode(child, options, lines, enhanced, hooks);\n lines.push(` ${prevId} --> ${result.entryId}`);\n prevId = result.exitId;\n }\n branchExitIds.push(prevId);\n if (branch.taken) {\n takenBranchExitId = prevId;\n }\n } else {\n branchExitIds.push(branchId);\n if (branch.taken) {\n takenBranchExitId = branchId;\n }\n }\n }\n\n // Join point (if we have a taken branch)\n if (takenBranchExitId) {\n return { entryId: decisionId, exitId: takenBranchExitId };\n }\n\n // If no branch was taken, return decision as exit\n return { entryId: decisionId, exitId: decisionId };\n}\n\n/**\n * Render a stream node.\n * Uses hexagonal shape to distinguish from regular steps.\n */\nfunction renderStreamNode(\n node: StreamNode,\n options: RenderOptions,\n lines: string[]\n): RenderResult {\n const id = `stream_${node.namespace.replace(/[^a-zA-Z0-9]/g, \"_\")}_${generateNodeId(\"\")}`;\n\n // Format counts\n const counts = `W:${node.writeCount} R:${node.readCount}`;\n\n // Add state icon\n let stateIcon = \"\";\n switch (node.streamState) {\n case \"active\":\n stateIcon = \"⟳ \";\n break;\n case \"closed\":\n stateIcon = \"✓ \";\n break;\n case \"error\":\n stateIcon = \"✗ \";\n break;\n }\n\n // Format timing\n const timing =\n options.showTimings && node.durationMs !== undefined\n ? ` ${formatDuration(node.durationMs)}`\n : \"\";\n\n // Backpressure indicator\n const backpressure = node.backpressureOccurred ? \"\\\\nbackpressure\" : \"\";\n\n // Combine label parts - use hexagon shape for streams\n const label = `${stateIcon}stream:${escapeMermaidText(node.namespace)}\\\\n${counts}${backpressure}${timing}`;\n\n // Determine class based on stream state\n let nodeClass: string;\n if (node.streamState === \"error\") {\n nodeClass = \"streamError\";\n } else if (node.streamState === \"active\") {\n nodeClass = \"streamActive\";\n } else {\n nodeClass = \"stream\";\n }\n\n // Hexagonal shape for streams: {{\"label\"}}\n lines.push(` ${id}{{\"${label}\"}}:::${nodeClass}`);\n\n return { entryId: id, exitId: id };\n}\n\nexport { mermaidRenderer as default };\n","/**\n * Performance Analyzer\n *\n * Analyzes workflow execution data to identify:\n * - Slow steps (bottlenecks)\n * - Retry patterns\n * - Error-prone steps\n * - Timing anomalies\n *\n * Aggregates metrics across multiple workflow runs to provide\n * statistical insights and heatmap visualization data.\n */\n\nimport type { WorkflowEvent } from \"awaitly/workflow\";\nimport type {\n NodePerformance,\n HeatmapData,\n WorkflowIR,\n FlowNode,\n HeatLevel,\n} from \"./types\";\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * A recorded workflow run for analysis.\n */\nexport interface WorkflowRun {\n /** Unique identifier for this run */\n id: string;\n /** Workflow start timestamp */\n startTime: number;\n /** All events from the workflow execution */\n events: WorkflowEvent<unknown>[];\n}\n\n/**\n * Performance analyzer interface.\n */\nexport interface PerformanceAnalyzer {\n /** Add a completed workflow run for analysis */\n addRun: (run: WorkflowRun) => void;\n\n /** Add events incrementally (alternative to addRun) */\n addEvent: (event: WorkflowEvent<unknown>) => void;\n\n /** Finalize current run (when using addEvent) */\n finalizeRun: (runId: string) => void;\n\n /** Get performance stats for a specific node */\n getNodePerformance: (nodeId: string) => NodePerformance | undefined;\n\n /** Get heatmap data for an IR */\n getHeatmap: (\n ir: WorkflowIR,\n metric?: \"duration\" | \"retryRate\" | \"errorRate\"\n ) => HeatmapData;\n\n /** Get slowest nodes */\n getSlowestNodes: (limit?: number) => NodePerformance[];\n\n /** Get error-prone nodes */\n getErrorProneNodes: (limit?: number) => NodePerformance[];\n\n /** Get retry-prone nodes */\n getRetryProneNodes: (limit?: number) => NodePerformance[];\n\n /** Get all performance data */\n getAllPerformance: () => Map<string, NodePerformance>;\n\n /** Export performance data as JSON */\n exportData: () => string;\n\n /** Import performance data from JSON */\n importData: (json: string) => void;\n\n /** Clear all collected data */\n clear: () => void;\n}\n\n// =============================================================================\n// Helper Functions\n// =============================================================================\n\n/**\n * Flatten all nodes from an IR tree.\n */\nfunction flattenNodes(nodes: FlowNode[]): FlowNode[] {\n const result: FlowNode[] = [];\n for (const node of nodes) {\n result.push(node);\n if (\"children\" in node && Array.isArray(node.children)) {\n result.push(...flattenNodes(node.children));\n }\n if (\"branches\" in node) {\n for (const branch of node.branches) {\n result.push(...flattenNodes(branch.children));\n }\n }\n }\n return result;\n}\n\n/**\n * Calculate percentile value from sorted array.\n */\nfunction percentile(sortedValues: number[], p: number): number {\n if (sortedValues.length === 0) return 0;\n const index = Math.floor(sortedValues.length * p);\n return sortedValues[Math.min(index, sortedValues.length - 1)];\n}\n\n/**\n * Get heat level from normalized value (0-1).\n */\nexport function getHeatLevel(heat: number): HeatLevel {\n if (heat < 0.2) return \"cold\";\n if (heat < 0.4) return \"cool\";\n if (heat < 0.6) return \"neutral\";\n if (heat < 0.8) return \"warm\";\n if (heat < 0.95) return \"hot\";\n return \"critical\";\n}\n\n// =============================================================================\n// Implementation\n// =============================================================================\n\n/**\n * Create a performance analyzer for workflow metrics.\n *\n * @example\n * ```typescript\n * const analyzer = createPerformanceAnalyzer();\n *\n * // Add completed runs\n * analyzer.addRun({ id: 'run-1', startTime: Date.now(), events });\n *\n * // Get insights\n * const slowest = analyzer.getSlowestNodes(5);\n * const heatmap = analyzer.getHeatmap(ir, 'duration');\n * ```\n */\nexport function createPerformanceAnalyzer(): PerformanceAnalyzer {\n // Timing data: nodeId → array of durations (ms)\n const timingData = new Map<string, number[]>();\n\n // Retry data: nodeId → { retried runs, total runs }\n const retryData = new Map<string, { retried: number; total: number }>();\n\n // Error data: nodeId → { error runs, total runs }\n const errorData = new Map<string, { errors: number; total: number }>();\n\n // Timeout data: nodeId → { timed out, total }\n const timeoutData = new Map<string, { timedOut: number; total: number }>();\n\n // Current run state (for incremental event adding)\n let currentRunEvents: WorkflowEvent<unknown>[] = [];\n\n /**\n * Get node ID from event.\n * Prioritizes stepKey, then stepId, then name so distinct steps (same name, no key)\n * are not merged.\n */\n function getNodeId(event: {\n stepId?: string;\n stepKey?: string;\n name?: string;\n }): string {\n return event.stepKey ?? event.stepId ?? event.name ?? \"unknown\";\n }\n\n /**\n * Process events from a workflow run.\n */\n function processEvents(events: WorkflowEvent<unknown>[]): void {\n // Track step state during processing\n const stepState = new Map<\n string,\n {\n retried: boolean;\n timedOut: boolean;\n }\n >();\n\n for (const event of events) {\n switch (event.type) {\n case \"step_start\": {\n const id = getNodeId(event);\n stepState.set(id, { retried: false, timedOut: false });\n break;\n }\n\n case \"step_retry\": {\n const id = getNodeId(event);\n const state = stepState.get(id);\n if (state) {\n state.retried = true;\n }\n break;\n }\n\n case \"step_timeout\": {\n const id = getNodeId(event);\n const state = stepState.get(id);\n if (state) {\n state.timedOut = true;\n }\n // Don't update counts here - wait for step completion\n // to get accurate total count across all runs\n break;\n }\n\n case \"step_success\": {\n const id = getNodeId(event);\n const state = stepState.get(id);\n\n // Record timing\n const timings = timingData.get(id) ?? [];\n timings.push(event.durationMs);\n timingData.set(id, timings);\n\n // Record retry status\n const retry = retryData.get(id) ?? { retried: 0, total: 0 };\n retry.total++;\n if (state?.retried) retry.retried++;\n retryData.set(id, retry);\n\n // Record timeout status\n const timeout = timeoutData.get(id) ?? { timedOut: 0, total: 0 };\n timeout.total++;\n if (state?.timedOut) timeout.timedOut++;\n timeoutData.set(id, timeout);\n\n // Record success (no error)\n const error = errorData.get(id) ?? { errors: 0, total: 0 };\n error.total++;\n errorData.set(id, error);\n\n stepState.delete(id);\n break;\n }\n\n case \"step_error\": {\n const id = getNodeId(event);\n const state = stepState.get(id);\n\n // Record timing\n const timings = timingData.get(id) ?? [];\n timings.push(event.durationMs);\n timingData.set(id, timings);\n\n // Record retry status\n const retry = retryData.get(id) ?? { retried: 0, total: 0 };\n retry.total++;\n if (state?.retried) retry.retried++;\n retryData.set(id, retry);\n\n // Record timeout status\n const timeout = timeoutData.get(id) ?? { timedOut: 0, total: 0 };\n timeout.total++;\n if (state?.timedOut) timeout.timedOut++;\n timeoutData.set(id, timeout);\n\n // Record error\n const error = errorData.get(id) ?? { errors: 0, total: 0 };\n error.total++;\n error.errors++;\n errorData.set(id, error);\n\n stepState.delete(id);\n break;\n }\n }\n }\n }\n\n /**\n * Add a completed workflow run.\n */\n function addRun(run: WorkflowRun): void {\n processEvents(run.events);\n }\n\n /**\n * Add an event incrementally.\n */\n function addEvent(event: WorkflowEvent<unknown>): void {\n currentRunEvents.push(event);\n }\n\n /**\n * Finalize current run (process accumulated events).\n */\n function finalizeRun(_runId: string): void {\n if (currentRunEvents.length > 0) {\n processEvents(currentRunEvents);\n currentRunEvents = [];\n }\n }\n\n /**\n * Compute performance metrics for a node.\n */\n function computePerformance(nodeId: string): NodePerformance | undefined {\n const timings = timingData.get(nodeId);\n if (!timings || timings.length === 0) return undefined;\n\n const sorted = [...timings].sort((a, b) => a - b);\n const sum = sorted.reduce((a, b) => a + b, 0);\n const mean = sum / sorted.length;\n const variance =\n sorted.reduce((acc, t) => acc + (t - mean) ** 2, 0) / sorted.length;\n\n const retry = retryData.get(nodeId) ?? { retried: 0, total: 1 };\n const error = errorData.get(nodeId) ?? { errors: 0, total: 1 };\n const timeout = timeoutData.get(nodeId) ?? { timedOut: 0, total: 1 };\n\n return {\n nodeId,\n avgDurationMs: mean,\n minDurationMs: sorted[0],\n maxDurationMs: sorted[sorted.length - 1],\n stdDevMs: Math.sqrt(variance),\n samples: sorted.length,\n retryRate: retry.total > 0 ? retry.retried / retry.total : 0,\n timeoutRate: timeout.total > 0 ? timeout.timedOut / timeout.total : 0,\n errorRate: error.total > 0 ? error.errors / error.total : 0,\n percentiles: {\n p50: percentile(sorted, 0.5),\n p90: percentile(sorted, 0.9),\n p95: percentile(sorted, 0.95),\n p99: percentile(sorted, 0.99),\n },\n };\n }\n\n /**\n * Get performance stats for a specific node.\n */\n function getNodePerformance(nodeId: string): NodePerformance | undefined {\n return computePerformance(nodeId);\n }\n\n /**\n * Get heatmap data for an IR.\n */\n function getHeatmap(\n ir: WorkflowIR,\n metric: \"duration\" | \"retryRate\" | \"errorRate\" = \"duration\"\n ): HeatmapData {\n const heat = new Map<string, number>();\n const allNodes = flattenNodes(ir.root.children);\n\n // Compute values for all nodes\n const values: Array<{ id: string; value: number }> = [];\n for (const node of allNodes) {\n // Use same lookup order as getNodeId: stepKey ?? stepId ?? name (IR has key, id, name)\n const lookupKey =\n (\"key\" in node ? node.key : undefined) ?? node.id ?? node.name;\n const perf = computePerformance(lookupKey);\n if (perf) {\n let value: number;\n switch (metric) {\n case \"duration\":\n value = perf.avgDurationMs;\n break;\n case \"retryRate\":\n value = perf.retryRate;\n break;\n case \"errorRate\":\n value = perf.errorRate;\n break;\n }\n values.push({ id: node.id, value });\n }\n }\n\n if (values.length === 0) {\n return {\n heat,\n metric,\n stats: { min: 0, max: 0, mean: 0, threshold: 0 },\n };\n }\n\n // Compute statistics\n const vals = values.map((v) => v.value);\n const min = Math.min(...vals);\n const max = Math.max(...vals);\n const mean = vals.reduce((a, b) => a + b, 0) / vals.length;\n const range = max - min || 1;\n\n // Normalize to 0-1 heat values\n for (const { id, value } of values) {\n heat.set(id, (value - min) / range);\n }\n\n return {\n heat,\n metric,\n stats: {\n min,\n max,\n mean,\n threshold: mean + (max - mean) * 0.5, // 50% above mean is \"hot\"\n },\n };\n }\n\n /**\n * Get all performance data.\n */\n function getAllPerformance(): Map<string, NodePerformance> {\n const result = new Map<string, NodePerformance>();\n for (const nodeId of timingData.keys()) {\n const perf = computePerformance(nodeId);\n if (perf) result.set(nodeId, perf);\n }\n return result;\n }\n\n /**\n * Get slowest nodes by average duration.\n */\n function getSlowestNodes(limit = 10): NodePerformance[] {\n const all = getAllPerformance();\n return [...all.values()]\n .sort((a, b) => b.avgDurationMs - a.avgDurationMs)\n .slice(0, limit);\n }\n\n /**\n * Get error-prone nodes by error rate.\n */\n function getErrorProneNodes(limit = 10): NodePerformance[] {\n const all = getAllPerformance();\n return [...all.values()]\n .filter((p) => p.errorRate > 0)\n .sort((a, b) => b.errorRate - a.errorRate)\n .slice(0, limit);\n }\n\n /**\n * Get retry-prone nodes by retry rate.\n */\n function getRetryProneNodes(limit = 10): NodePerformance[] {\n const all = getAllPerformance();\n return [...all.values()]\n .filter((p) => p.retryRate > 0)\n .sort((a, b) => b.retryRate - a.retryRate)\n .slice(0, limit);\n }\n\n /**\n * Export performance data as JSON.\n */\n function exportData(): string {\n return JSON.stringify({\n timingData: Object.fromEntries(timingData),\n retryData: Object.fromEntries(retryData),\n errorData: Object.fromEntries(errorData),\n timeoutData: Object.fromEntries(timeoutData),\n });\n }\n\n /**\n * Import performance data from JSON.\n */\n function importData(json: string): void {\n const data = JSON.parse(json) as {\n timingData?: Record<string, number[]>;\n retryData?: Record<string, { retried: number; total: number }>;\n errorData?: Record<string, { errors: number; total: number }>;\n timeoutData?: Record<string, { timedOut: number; total: number }>;\n };\n\n // Clear existing data\n timingData.clear();\n retryData.clear();\n errorData.clear();\n timeoutData.clear();\n\n // Import timing data\n for (const [k, v] of Object.entries(data.timingData ?? {})) {\n timingData.set(k, v);\n }\n\n // Import retry data\n for (const [k, v] of Object.entries(data.retryData ?? {})) {\n retryData.set(k, v);\n }\n\n // Import error data\n for (const [k, v] of Object.entries(data.errorData ?? {})) {\n errorData.set(k, v);\n }\n\n // Import timeout data\n for (const [k, v] of Object.entries(data.timeoutData ?? {})) {\n timeoutData.set(k, v);\n }\n }\n\n /**\n * Clear all collected data.\n */\n function clear(): void {\n timingData.clear();\n retryData.clear();\n errorData.clear();\n timeoutData.clear();\n currentRunEvents = [];\n }\n\n return {\n addRun,\n addEvent,\n finalizeRun,\n getNodePerformance,\n getHeatmap,\n getSlowestNodes,\n getErrorProneNodes,\n getRetryProneNodes,\n getAllPerformance,\n exportData,\n importData,\n clear,\n };\n}\n","/**\n * Kroki Encoder\n *\n * Encodes Mermaid diagram text for Kroki URLs using pako deflate + base64url.\n * Uses Buffer in Node (btoa/atob not available) and btoa/atob in browsers.\n */\n\nimport pako from \"pako\";\n\n/** True when Buffer is available (Node). */\nconst hasBuffer = typeof globalThis !== \"undefined\" && \"Buffer\" in globalThis && typeof (globalThis as { Buffer?: unknown }).Buffer === \"function\";\n\n/**\n * Base64URL encode bytes (URL-safe base64).\n * Uses `-` and `_` instead of `+` and `/`, and omits padding.\n * Node-safe: uses Buffer when available, otherwise btoa.\n */\nfunction base64UrlEncode(bytes: Uint8Array): string {\n let base64: string;\n if (hasBuffer) {\n const B = (globalThis as unknown as { Buffer: { from: (u: Uint8Array) => { toString: (enc: string) => string } } }).Buffer;\n base64 = B.from(bytes).toString(\"base64\");\n } else {\n let binary = \"\";\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n base64 = btoa(binary);\n }\n return base64\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/, \"\"); // Remove padding\n}\n\n/**\n * Decode standard base64 to bytes.\n * Node-safe: uses Buffer when available, otherwise atob.\n */\nfunction base64ToBytes(base64: string): Uint8Array {\n if (hasBuffer) {\n const B = (globalThis as unknown as { Buffer: { from: (s: string, enc: string) => Uint8Array } }).Buffer;\n return B.from(base64, \"base64\");\n }\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n}\n\n/**\n * Encode text for Kroki URL.\n * Uses pako deflate compression + base64url encoding.\n *\n * @param text - The text to encode (e.g., Mermaid diagram)\n * @returns URL-safe encoded string\n *\n * @example\n * ```typescript\n * const encoded = encodeForKroki('flowchart TD\\n A-->B');\n * // => \"eNpLzs8tyc9NTgQADsMDmA\"\n * ```\n */\nexport function encodeForKroki(text: string): string {\n // Convert string to UTF-8 bytes\n const textEncoder = new TextEncoder();\n const textBytes = textEncoder.encode(text);\n\n // Compress with deflate\n const compressed = pako.deflate(textBytes);\n\n // Base64URL encode\n return base64UrlEncode(compressed);\n}\n\n/**\n * Decode Kroki URL payload back to text.\n * Uses base64url decoding + pako inflate.\n *\n * @param encoded - The encoded string from a Kroki URL\n * @returns The original text\n *\n * @example\n * ```typescript\n * const text = decodeFromKroki('eNpLzs8tyc9NTgQADsMDmA');\n * // => \"flowchart TD\\n A-->B\"\n * ```\n */\nexport function decodeFromKroki(encoded: string): string {\n // Convert URL-safe base64 to standard base64\n let base64 = encoded.replace(/-/g, \"+\").replace(/_/g, \"/\");\n\n // Add padding if needed\n const padding = 4 - (base64.length % 4);\n if (padding !== 4) {\n base64 += \"=\".repeat(padding);\n }\n\n const bytes = base64ToBytes(base64);\n const decompressed = pako.inflate(bytes);\n const textDecoder = new TextDecoder();\n return textDecoder.decode(decompressed);\n}\n","/**\n * Kroki URL Generation\n *\n * Generates shareable URLs for Kroki diagram rendering service.\n * Works in both browser and Node.js environments.\n */\n\nimport type { WorkflowIR, RenderOptions, KrokiExportOptions } from \"../types\";\nimport { mermaidRenderer, defaultColorScheme } from \"../renderers\";\nimport { encodeForKroki } from \"./encoder\";\n\n/**\n * Supported Kroki output formats.\n */\nexport type KrokiFormat = \"svg\" | \"png\" | \"pdf\" | \"jpeg\";\n\n/**\n * Options for URL generator.\n */\nexport interface UrlGeneratorOptions {\n /** Base URL for Kroki service (default: https://kroki.io) */\n baseUrl?: string;\n}\n\n/**\n * Default Kroki base URL.\n */\nconst DEFAULT_KROKI_URL = \"https://kroki.io\";\n\n/**\n * Build a Kroki URL for the given diagram.\n *\n * @param diagramType - Diagram type (e.g., \"mermaid\", \"plantuml\", \"graphviz\")\n * @param format - Output format (svg, png, pdf, jpeg)\n * @param text - The diagram text\n * @param options - URL generator options (KrokiExportOptions or legacy UrlGeneratorOptions)\n * @returns The Kroki URL\n *\n * @example\n * ```typescript\n * const url = buildKrokiUrl('mermaid', 'svg', 'flowchart TD\\n A-->B');\n * // => \"https://kroki.io/mermaid/svg/eNpLzs8tyc9NTgQADsMDmA\"\n *\n * // With explicit KrokiExportOptions\n * const url2 = buildKrokiUrl('mermaid', 'svg', 'flowchart TD\\n A-->B', {\n * provider: 'kroki',\n * baseUrl: 'https://kroki.internal'\n * });\n * ```\n */\nexport function buildKrokiUrl(\n diagramType: string,\n format: KrokiFormat,\n text: string,\n options: KrokiExportOptions | UrlGeneratorOptions = {}\n): string {\n const baseUrl = options.baseUrl ?? DEFAULT_KROKI_URL;\n const encoded = encodeForKroki(text);\n return `${baseUrl}/${diagramType}/${format}/${encoded}`;\n}\n\n/**\n * Generate a Kroki URL from workflow IR.\n *\n * @param ir - Workflow intermediate representation\n * @param format - Output format (default: 'svg')\n * @param options - Optional URL generator options\n * @returns The Kroki URL\n *\n * @example\n * ```typescript\n * const url = toKrokiUrl(workflowIR, 'svg');\n * // Share this URL - image renders when viewed\n * ```\n */\nexport function toKrokiUrl(\n ir: WorkflowIR,\n format: KrokiFormat = \"svg\",\n options: UrlGeneratorOptions = {}\n): string {\n const renderer = mermaidRenderer();\n const renderOptions: RenderOptions = {\n showTimings: true,\n showKeys: false,\n terminalWidth: 80,\n colors: defaultColorScheme,\n };\n\n const mermaidText = renderer.render(ir, renderOptions);\n return buildKrokiUrl(\"mermaid\", format, mermaidText, options);\n}\n\n/**\n * Generate a Kroki SVG URL from workflow IR.\n *\n * @param ir - Workflow intermediate representation\n * @param options - Optional URL generator options\n * @returns The Kroki SVG URL\n *\n * @example\n * ```typescript\n * const svgUrl = toKrokiSvgUrl(workflowIR);\n * // => \"https://kroki.io/mermaid/svg/eNp...\"\n * ```\n */\nexport function toKrokiSvgUrl(\n ir: WorkflowIR,\n options: UrlGeneratorOptions = {}\n): string {\n return toKrokiUrl(ir, \"svg\", options);\n}\n\n/**\n * Generate a Kroki PNG URL from workflow IR.\n *\n * @param ir - Workflow intermediate representation\n * @param options - Optional URL generator options\n * @returns The Kroki PNG URL\n *\n * @example\n * ```typescript\n * const pngUrl = toKrokiPngUrl(workflowIR);\n * // => \"https://kroki.io/mermaid/png/eNp...\"\n * ```\n */\nexport function toKrokiPngUrl(\n ir: WorkflowIR,\n options: UrlGeneratorOptions = {}\n): string {\n return toKrokiUrl(ir, \"png\", options);\n}\n\n/**\n * URL Generator with configured base URL.\n */\nexport interface UrlGenerator {\n /** Generate URL with specified format */\n toUrl(ir: WorkflowIR, format: KrokiFormat): string;\n /** Generate SVG URL */\n toSvgUrl(ir: WorkflowIR): string;\n /** Generate PNG URL */\n toPngUrl(ir: WorkflowIR): string;\n /** Generate PDF URL */\n toPdfUrl(ir: WorkflowIR): string;\n /** Get the configured base URL */\n getBaseUrl(): string;\n}\n\n/**\n * Create a URL generator with a custom base URL.\n * Useful for self-hosted Kroki instances.\n *\n * @param options - URL generator options\n * @returns A URL generator instance\n *\n * @example\n * ```typescript\n * // Use self-hosted Kroki\n * const generator = createUrlGenerator({ baseUrl: 'https://my-kroki.internal' });\n * const url = generator.toSvgUrl(workflowIR);\n *\n * // Default public Kroki\n * const defaultGenerator = createUrlGenerator();\n * const publicUrl = defaultGenerator.toSvgUrl(workflowIR);\n * ```\n */\nexport function createUrlGenerator(options: UrlGeneratorOptions = {}): UrlGenerator {\n const baseUrl = options.baseUrl ?? DEFAULT_KROKI_URL;\n\n return {\n toUrl(ir: WorkflowIR, format: KrokiFormat): string {\n return toKrokiUrl(ir, format, { baseUrl });\n },\n\n toSvgUrl(ir: WorkflowIR): string {\n return toKrokiUrl(ir, \"svg\", { baseUrl });\n },\n\n toPngUrl(ir: WorkflowIR): string {\n return toKrokiUrl(ir, \"png\", { baseUrl });\n },\n\n toPdfUrl(ir: WorkflowIR): string {\n return toKrokiUrl(ir, \"pdf\", { baseUrl });\n },\n\n getBaseUrl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AM,EAAGJ,CAAO,EAE9D,GAAI,CACF,IAAMM,EAAW,MAAM,MAAMJ,EAAK,CAChC,OAAQE,EAAW,OACnB,QAAS,CACP,OAAQ,WACV,CACF,CAAC,EAED,GAAI,CAACE,EAAS,GACZ,SAAO,OAAI,kBAAkB,EAG/B,IAAMK,EAAc,MAAML,EAAS,YAAY,EAC/C,SAAO,MAAG,OAAO,KAAKK,CAAW,CAAC,CACpC,OAASH,EAAO,CACd,OAAIA,aAAiB,OAASA,EAAM,OAAS,gBACpC,OAAI,SAAS,KAEf,OAAI,aAAa,CAC1B,QAAE,CACA,aAAaH,CAAS,CACxB,CACF,CAoBA,eAAsBO,GACpBf,EACAC,EAA6B,CAAC,EACG,CACjC,GAAM,CAAE,UAAAC,EAAW,QAAAC,EAAU,IAAO,GAAGC,CAAW,EAAIH,EAIhDe,EAASd,EACXA,EAAU,SAASF,CAAE,EACrBa,EAAcb,EAAII,CAAU,EAAE,QAAQ,QAAS,OAAO,EAEpDG,EAAa,IAAI,gBACjBC,EAAY,WAAW,IAAMD,EAAW,MAAM,EAAGJ,CAAO,EAE9D,GAAI,CACF,IAAMM,EAAW,MAAM,MAAMO,EAAQ,CACnC,OAAQT,EAAW,OACnB,QAAS,CACP,OAAQ,iBACV,CACF,CAAC,EAED,GAAI,CAACE,EAAS,GACZ,SAAO,OAAI,kBAAkB,EAG/B,IAAMK,EAAc,MAAML,EAAS,YAAY,EAC/C,SAAO,MAAG,OAAO,KAAKK,CAAW,CAAC,CACpC,OAASH,EAAO,CACd,OAAIA,aAAiB,OAASA,EAAM,OAAS,gBACpC,OAAI,SAAS,KAEf,OAAI,aAAa,CAC1B,QAAE,CACA,aAAaH,CAAS,CACxB,CACF","names":["fetch_exports","__export","fetchKrokiPdf","fetchKrokiPng","fetchKrokiSvg","__toCommonJS","import_awaitly","import_awaitly","isStepNode","node","isParallelNode","node","isRaceNode","isDecisionNode","isStreamNode","formatDuration","ms","minutes","seconds","DIM","FG_RED","FG_GREEN","FG_YELLOW","FG_BLUE","FG_GRAY","FG_WHITE","defaultColorScheme","FG_WHITE","FG_YELLOW","FG_GREEN","FG_RED","FG_GRAY","FG_BLUE","DIM","import_awaitly","getHeatLevel","heat","getStyleDefinitions","getHeatmapStyleDefinitions","getHeatClass","level","getHookStyleDefinitions","safeStringify","value","_key","v","n","getStringified","result","renderHooks","hooks","lines","options","lastHookId","hookId","state","icon","timing","formatDuration","context","nodeCounter","usedDecisionIds","usedStepIds","generateNodeId","prefix","resetNodeCounter","escapeMermaidText","text","escapeSubgraphName","mermaidRenderer","ir","enhanced","hookExitId","startId","prevNodeId","child","renderNode","endId","endIcon","endLabel","endShape","endClass","getStyleDefinitions","getHeatmapStyleDefinitions","node","isStepNode","renderStepNode","isParallelNode","renderParallelNode","isRaceNode","renderRaceNode","isDecisionNode","renderDecisionNode","isStreamNode","renderStreamNode","id","mermaidOpts","showRetryEdges","showErrorEdges","showTimeoutEdges","suffix","baseLabel","labelText","label","stateIcon","ioInfo","inputStr","outputStr","hookInfo","hookKey","hookExec","hookIcon","hookTiming","escapedLabel","nodeClass","heat","level","getHeatLevel","getHeatClass","shape","retryLabel","errorNodeId","errorLabel","timeoutNodeId","timeoutMs","subgraphId","forkId","joinId","name","modeLabel","note","childExitIds","exitId","stateClass","winnerExitId","isWinner","decisionId","condition","decisionValue","decisionLabel","branchExitIds","takenBranchExitId","usedBranchIds","branch","branchId","branchLabelText","branchLabel","branchClass","edgeLabel","prevId","counts","backpressure","import_pako","hasBuffer","base64UrlEncode","bytes","base64","binary","i","encodeForKroki","text","textBytes","compressed","pako","base64UrlEncode","DEFAULT_KROKI_URL","buildKrokiUrl","diagramType","format","text","options","baseUrl","encoded","encodeForKroki","toKrokiUrl","ir","renderer","mermaidRenderer","renderOptions","defaultColorScheme","mermaidText","toKrokiSvgUrl","toKrokiPngUrl","fetchKrokiSvg","ir","options","generator","timeout","urlOptions","url","toKrokiSvgUrl","controller","timeoutId","response","text","error","fetchKrokiPng","toKrokiPngUrl","arrayBuffer","fetchKrokiPdf","pdfUrl"]}
@@ -0,0 +1,86 @@
1
+ import { AsyncResult } from 'awaitly';
2
+ import { U as UrlGeneratorOptions, a8 as UrlGenerator, W as WorkflowIR } from '../url-PkfQz4V5.cjs';
3
+ import 'awaitly/workflow';
4
+ import 'awaitly/core';
5
+
6
+ /**
7
+ * Kroki Fetch (Node-only)
8
+ *
9
+ * Downloads rendered diagrams from Kroki as SVG or PNG.
10
+ * This is a separate subpath entry to avoid bundling Node-only code in browser builds.
11
+ */
12
+
13
+ /**
14
+ * Error types for Kroki fetch operations.
15
+ */
16
+ type KrokiError = "FETCH_ERROR" | "TIMEOUT" | "INVALID_RESPONSE";
17
+ /**
18
+ * Options for fetching from Kroki.
19
+ */
20
+ interface FetchKrokiOptions extends UrlGeneratorOptions {
21
+ /** Optional custom URL generator */
22
+ generator?: UrlGenerator;
23
+ /** Request timeout in milliseconds (default: 30000) */
24
+ timeout?: number;
25
+ }
26
+ /**
27
+ * Fetch SVG content from Kroki.
28
+ *
29
+ * @param ir - Workflow intermediate representation
30
+ * @param options - Fetch options
31
+ * @returns Result with SVG content or KrokiError
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { fetchKrokiSvg } from 'awaitly-visualizer/kroki-fetch';
36
+ *
37
+ * const result = await fetchKrokiSvg(workflowIR);
38
+ * if (result.ok) {
39
+ * // Write to file or embed in HTML
40
+ * console.log(result.value);
41
+ * } else {
42
+ * console.error('Failed:', result.error);
43
+ * }
44
+ * ```
45
+ */
46
+ declare function fetchKrokiSvg(ir: WorkflowIR, options?: FetchKrokiOptions): AsyncResult<string, KrokiError>;
47
+ /**
48
+ * Fetch PNG content from Kroki.
49
+ *
50
+ * @param ir - Workflow intermediate representation
51
+ * @param options - Fetch options
52
+ * @returns Result with PNG content as Buffer or KrokiError
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { fetchKrokiPng } from 'awaitly-visualizer/kroki-fetch';
57
+ * import fs from 'node:fs';
58
+ *
59
+ * const result = await fetchKrokiPng(workflowIR);
60
+ * if (result.ok) {
61
+ * fs.writeFileSync('workflow.png', result.value);
62
+ * }
63
+ * ```
64
+ */
65
+ declare function fetchKrokiPng(ir: WorkflowIR, options?: FetchKrokiOptions): AsyncResult<Buffer, KrokiError>;
66
+ /**
67
+ * Fetch PDF content from Kroki.
68
+ *
69
+ * @param ir - Workflow intermediate representation
70
+ * @param options - Fetch options
71
+ * @returns Result with PDF content as Buffer or KrokiError
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import { fetchKrokiPdf } from 'awaitly-visualizer/kroki-fetch';
76
+ * import fs from 'node:fs';
77
+ *
78
+ * const result = await fetchKrokiPdf(workflowIR);
79
+ * if (result.ok) {
80
+ * fs.writeFileSync('workflow.pdf', result.value);
81
+ * }
82
+ * ```
83
+ */
84
+ declare function fetchKrokiPdf(ir: WorkflowIR, options?: FetchKrokiOptions): AsyncResult<Buffer, KrokiError>;
85
+
86
+ export { type FetchKrokiOptions, type KrokiError, fetchKrokiPdf, fetchKrokiPng, fetchKrokiSvg };
@@ -0,0 +1,86 @@
1
+ import { AsyncResult } from 'awaitly';
2
+ import { U as UrlGeneratorOptions, a8 as UrlGenerator, W as WorkflowIR } from '../url-PkfQz4V5.js';
3
+ import 'awaitly/workflow';
4
+ import 'awaitly/core';
5
+
6
+ /**
7
+ * Kroki Fetch (Node-only)
8
+ *
9
+ * Downloads rendered diagrams from Kroki as SVG or PNG.
10
+ * This is a separate subpath entry to avoid bundling Node-only code in browser builds.
11
+ */
12
+
13
+ /**
14
+ * Error types for Kroki fetch operations.
15
+ */
16
+ type KrokiError = "FETCH_ERROR" | "TIMEOUT" | "INVALID_RESPONSE";
17
+ /**
18
+ * Options for fetching from Kroki.
19
+ */
20
+ interface FetchKrokiOptions extends UrlGeneratorOptions {
21
+ /** Optional custom URL generator */
22
+ generator?: UrlGenerator;
23
+ /** Request timeout in milliseconds (default: 30000) */
24
+ timeout?: number;
25
+ }
26
+ /**
27
+ * Fetch SVG content from Kroki.
28
+ *
29
+ * @param ir - Workflow intermediate representation
30
+ * @param options - Fetch options
31
+ * @returns Result with SVG content or KrokiError
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { fetchKrokiSvg } from 'awaitly-visualizer/kroki-fetch';
36
+ *
37
+ * const result = await fetchKrokiSvg(workflowIR);
38
+ * if (result.ok) {
39
+ * // Write to file or embed in HTML
40
+ * console.log(result.value);
41
+ * } else {
42
+ * console.error('Failed:', result.error);
43
+ * }
44
+ * ```
45
+ */
46
+ declare function fetchKrokiSvg(ir: WorkflowIR, options?: FetchKrokiOptions): AsyncResult<string, KrokiError>;
47
+ /**
48
+ * Fetch PNG content from Kroki.
49
+ *
50
+ * @param ir - Workflow intermediate representation
51
+ * @param options - Fetch options
52
+ * @returns Result with PNG content as Buffer or KrokiError
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { fetchKrokiPng } from 'awaitly-visualizer/kroki-fetch';
57
+ * import fs from 'node:fs';
58
+ *
59
+ * const result = await fetchKrokiPng(workflowIR);
60
+ * if (result.ok) {
61
+ * fs.writeFileSync('workflow.png', result.value);
62
+ * }
63
+ * ```
64
+ */
65
+ declare function fetchKrokiPng(ir: WorkflowIR, options?: FetchKrokiOptions): AsyncResult<Buffer, KrokiError>;
66
+ /**
67
+ * Fetch PDF content from Kroki.
68
+ *
69
+ * @param ir - Workflow intermediate representation
70
+ * @param options - Fetch options
71
+ * @returns Result with PDF content as Buffer or KrokiError
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import { fetchKrokiPdf } from 'awaitly-visualizer/kroki-fetch';
76
+ * import fs from 'node:fs';
77
+ *
78
+ * const result = await fetchKrokiPdf(workflowIR);
79
+ * if (result.ok) {
80
+ * fs.writeFileSync('workflow.pdf', result.value);
81
+ * }
82
+ * ```
83
+ */
84
+ declare function fetchKrokiPdf(ir: WorkflowIR, options?: FetchKrokiOptions): AsyncResult<Buffer, KrokiError>;
85
+
86
+ export { type FetchKrokiOptions, type KrokiError, fetchKrokiPdf, fetchKrokiPng, fetchKrokiSvg };
@@ -0,0 +1,3 @@
1
+ import{ok as W,err as k}from"awaitly";import{ok as De,err as Te}from"awaitly";function L(e){return e.type==="step"}function H(e){return e.type==="parallel"}function C(e){return e.type==="race"}function P(e){return e.type==="decision"}function B(e){return e.type==="stream"}function y(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),t=Math.round(e%6e4/1e3);return t>=60&&(r+=1,t=0),t===0?`${r}m`:`${r}m ${t}s`}var J="\x1B[2m",Y="\x1B[31m",Z="\x1B[32m",X="\x1B[33m",Q="\x1B[34m",U="\x1B[90m",ee="\x1B[37m";var E={pending:ee,running:X,success:Z,error:Y,aborted:U,cached:Q,skipped:J+U};import{ok as te,err as re}from"awaitly";function F(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function ne(){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 oe(){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 se(e){return`heat_${e}`}function ie(){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 ae(e){try{return te(JSON.stringify(e,(t,o)=>{if(typeof o!="bigint")return o;let s=Number(o);return Number.isSafeInteger(s)?s:o.toString()}))}catch{return re("STRINGIFY_ERROR")}}function A(e){let r=ae(e);return r.ok?r.value:"[unserializable]"}function ce(e,r,t){let o;if(e.shouldRun){let s="hook_shouldRun",n=e.shouldRun.state==="success"?"hook_success":"hook_error",l=e.shouldRun.state==="success"?"\u2699":"\u26A0",u=t.showTimings&&e.shouldRun.durationMs!==void 0?` ${y(e.shouldRun.durationMs)}`:"",i=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";r.push(` ${s}[["${l} shouldRun${i}${u}"]]:::${n}`),o=s}if(e.onBeforeStart){let s="hook_beforeStart",n=e.onBeforeStart.state==="success"?"hook_success":"hook_error",l=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",u=t.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${y(e.onBeforeStart.durationMs)}`:"",i=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";r.push(` ${s}[["${l} onBeforeStart${i}${u}"]]:::${n}`),o&&r.push(` ${o} --> ${s}`),o=s}return{lastHookId:o}}var K=0,O=new Set,D=new Set;function w(e="node"){return`${e}_${++K}`}function le(){K=0,O.clear(),D.clear()}function g(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function z(e){return g(e).replace(/[{}[\]()]/g,"")}function _(){return{name:"mermaid",supportsLive:!1,render(e,r){le();let t=[],o=r;t.push("flowchart TD");let s;e.hooks&&(s=ce(e.hooks,t,r).lastHookId);let n="start";t.push(` ${n}(("\u25B6 Start"))`),s&&t.push(` ${s} --> ${n}`);let l=n;for(let i of e.root.children){let a=T(i,r,t,o,e.hooks);t.push(` ${l} --> ${a.entryId}`),l=a.exitId}if(["success","error","aborted"].includes(e.root.state)){let i="finish",a=e.root.state==="success"?"\u2713":e.root.state==="error"?"\u2717":"\u2298",m=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",b=`(("${a} ${m}"))`,c=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";t.push(` ${i}${b}${c}`),t.push(` ${l} --> ${i}`)}return t.push(""),t.push(...ne()),o.showHeatmap&&t.push(...oe()),e.hooks&&t.push(...ie()),t.join(`
2
+ `)}}}function T(e,r,t,o,s){if(L(e))return ue(e,r,t,o,s);if(H(e))return de(e,r,t,o,s);if(C(e))return pe(e,r,t,o,s);if(P(e))return fe(e,r,t,o,s);if(B(e))return me(e,r,t);let n=w("unknown");return t.push(` ${n}["Unknown Node"]`),{entryId:n,exitId:n}}function ue(e,r,t,o,s){let n=r,l=n.showRetryEdges??!0,u=n.showErrorEdges??!0,i=n.showTimeoutEdges??!0,a=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:w("step");if(D.has(a)){let p=2;for(;D.has(`${a}_${p}`);)p++;a=`${a}_${p}`}D.add(a);let m=e.name??e.key??"Step",b=r.showKeys&&e.key&&e.name?`${m} [${e.key}]`:m,c=g(b),d=r.showTimings&&e.durationMs!==void 0?` ${y(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 $="";if(e.input!==void 0){let p=typeof e.input=="string"?g(e.input):g(A(e.input).slice(0,20));$+=`\\nin: ${p}`}if(e.output!==void 0&&e.state==="success"){let p=typeof e.output=="string"?g(e.output):g(A(e.output).slice(0,20));$+=`\\nout: ${p}`}let v="",x=e.key??e.id;if(s&&x&&s.onAfterStep.has(x)){let p=s.onAfterStep.get(x),I=p.state==="success"?"\u2699":"\u26A0",q=r.showTimings&&p.durationMs!==void 0?` ${y(p.durationMs)}`:"";v=`\\n${I} hook${q}`}let h=(f+c+$+v+d).trim(),R,S=o?.showHeatmap&&o.heatmapData?o.heatmapData.heat.get(e.key??"")??o.heatmapData.heat.get(e.name??"")??o.heatmapData.heat.get(e.id):void 0;if(S!==void 0){let p=F(S);R=se(p)}else R=e.state;let N;switch(e.state){case"error":N=`{{"${h}"}}`;break;case"cached":N=`[("${h}")]`;break;case"skipped":N=`["${h}"]`;break;default:N=`["${h}"]`}if(t.push(` ${a}${N}:::${R}`),l&&e.retryCount!==void 0&&e.retryCount>0){let p=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;t.push(` ${a} -.->|"${p}"| ${a}`)}if(u&&e.state==="error"&&e.error!==void 0){let p=`ERR_${a}`,I=g(String(e.error)).slice(0,30);t.push(` ${p}{{"${I}"}}`),t.push(` ${a} -->|error| ${p}`),t.push(` style ${p} fill:#fee2e2,stroke:#dc2626`)}if(i&&e.timedOut){let p=`TO_${a}`,I=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";t.push(` ${p}{{"\u23F1 Timeout ${I}"}}`),t.push(` ${a} -.->|timeout| ${p}`),t.push(` style ${p} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:a,exitId:a}}function de(e,r,t,o,s){let n=w("parallel"),l=`${n}_fork`,u=`${n}_join`,i=z(e.name??"Parallel"),a=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let c=n,d=g(`${i}${a}`),f="operations not individually tracked",$=r.showTimings&&e.durationMs!==void 0?` ${y(e.durationMs)}`:"";return t.push(` ${c}["${d}${$}\\n${f}"]:::${e.state}`),{entryId:c,exitId:c}}t.push(` subgraph ${n}["${i}${a}"]`),t.push(" direction TB"),t.push(` ${l}{"\u26A1 Fork"}`);let m=[];for(let c of e.children){let d=T(c,r,t,o,s);t.push(` ${l} --> ${d.entryId}`),m.push(d.exitId)}t.push(` ${u}{"\u2713 Join"}`);for(let c of m)t.push(` ${c} --> ${u}`);t.push(" end");let b=e.state;return t.push(` class ${n} ${b}`),{entryId:l,exitId:u}}function pe(e,r,t,o,s){let n=w("race"),l=`${n}_start`,u=`${n}_end`,i=z(e.name??"Race");if(e.children.length===0){let c=n,d=g(i),f="operations not individually tracked",$=r.showTimings&&e.durationMs!==void 0?` ${y(e.durationMs)}`:"";return t.push(` ${c}["\u26A1 ${d}${$}\\n${f}"]:::${e.state}`),{entryId:c,exitId:c}}t.push(` subgraph ${n}["\u26A1 ${i}"]`),t.push(" direction TB"),t.push(` ${l}(("\u{1F3C1} Start"))`);let a=[],m;for(let c of e.children){let d=T(c,r,t,o,s),f=e.winnerId===c.id;t.push(` ${l} --> ${d.entryId}`),f&&(m=d.exitId),a.push({exitId:d.exitId,isWinner:f})}t.push(` ${u}(("\u2713 First"))`);for(let{exitId:c,isWinner:d}of a)d&&m?t.push(` ${c} ==>|\u{1F3C6} Winner| ${u}`):e.winnerId?t.push(` ${c} -. cancelled .-> ${u}`):t.push(` ${c} --> ${u}`);t.push(" end");let b=e.state;return t.push(` class ${n} ${b}`),{entryId:l,exitId:u}}function fe(e,r,t,o,s){let n=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:w("decision");if(O.has(n)){let c=2;for(;O.has(`${n}_${c}`);)c++;n=`${n}_${c}`}O.add(n);let l=g(e.condition??"condition"),u=e.decisionValue!==void 0?` = ${g(String(e.decisionValue)).slice(0,30)}`:"",i=`${l}${u}`.trim();t.push(` ${n}{"${i}"}`);let a=[],m,b=new Set;for(let c of e.branches){let d=`${n}_${c.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(b.has(d)){let h=2;for(;b.has(`${d}_${h}`);)h++;d=`${d}_${h}`}b.add(d);let f=g(c.label),$=c.taken?`${f} \u2713`:`${f} skipped`,v=c.taken?":::success":":::skipped";t.push(` ${d}["${$}"]${v}`);let x=c.condition?`|${g(c.condition).replace(/\|/g,"")}|`:"";if(t.push(` ${n} -->${x} ${d}`),c.children.length>0){let h=d;for(let R of c.children){let S=T(R,r,t,o,s);t.push(` ${h} --> ${S.entryId}`),h=S.exitId}a.push(h),c.taken&&(m=h)}else a.push(d),c.taken&&(m=d)}return m?{entryId:n,exitId:m}:{entryId:n,exitId:n}}function me(e,r,t){let o=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${w("")}`,s=`W:${e.writeCount} R:${e.readCount}`,n="";switch(e.streamState){case"active":n="\u27F3 ";break;case"closed":n="\u2713 ";break;case"error":n="\u2717 ";break}let l=r.showTimings&&e.durationMs!==void 0?` ${y(e.durationMs)}`:"",u=e.backpressureOccurred?"\\nbackpressure":"",i=`${n}stream:${g(e.namespace)}\\n${s}${u}${l}`,a;return e.streamState==="error"?a="streamError":e.streamState==="active"?a="streamActive":a="stream",t.push(` ${o}{{"${i}"}}:::${a}`),{entryId:o,exitId:o}}import ge from"pako";var he=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function be(e){let r;if(he)r=globalThis.Buffer.from(e).toString("base64");else{let t="";for(let o=0;o<e.length;o++)t+=String.fromCharCode(e[o]);r=btoa(t)}return r.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function G(e){let t=new TextEncoder().encode(e),o=ge.deflate(t);return be(o)}var $e="https://kroki.io";function ke(e,r,t,o={}){let s=o.baseUrl??$e,n=G(t);return`${s}/${e}/${r}/${n}`}function j(e,r="svg",t={}){let o=_(),s={showTimings:!0,showKeys:!1,terminalWidth:80,colors:E},n=o.render(e,s);return ke("mermaid",r,n,t)}function V(e,r={}){return j(e,"svg",r)}function M(e,r={}){return j(e,"png",r)}async function Xe(e,r={}){let{generator:t,timeout:o=3e4,...s}=r,n=t?t.toSvgUrl(e):V(e,s),l=new AbortController,u=setTimeout(()=>l.abort(),o);try{let i=await fetch(n,{signal:l.signal,headers:{Accept:"image/svg+xml"}});if(!i.ok)return k("INVALID_RESPONSE");let a=await i.text();return W(a)}catch(i){return i instanceof Error&&i.name==="AbortError"?k("TIMEOUT"):k("FETCH_ERROR")}finally{clearTimeout(u)}}async function Qe(e,r={}){let{generator:t,timeout:o=3e4,...s}=r,n=t?t.toPngUrl(e):M(e,s),l=new AbortController,u=setTimeout(()=>l.abort(),o);try{let i=await fetch(n,{signal:l.signal,headers:{Accept:"image/png"}});if(!i.ok)return k("INVALID_RESPONSE");let a=await i.arrayBuffer();return W(Buffer.from(a))}catch(i){return i instanceof Error&&i.name==="AbortError"?k("TIMEOUT"):k("FETCH_ERROR")}finally{clearTimeout(u)}}async function et(e,r={}){let{generator:t,timeout:o=3e4,...s}=r,n=t?t.toPdfUrl(e):M(e,s).replace("/png/","/pdf/"),l=new AbortController,u=setTimeout(()=>l.abort(),o);try{let i=await fetch(n,{signal:l.signal,headers:{Accept:"application/pdf"}});if(!i.ok)return k("INVALID_RESPONSE");let a=await i.arrayBuffer();return W(Buffer.from(a))}catch(i){return i instanceof Error&&i.name==="AbortError"?k("TIMEOUT"):k("FETCH_ERROR")}finally{clearTimeout(u)}}export{et as fetchKrokiPdf,Qe as fetchKrokiPng,Xe as fetchKrokiSvg};
3
+ //# sourceMappingURL=fetch.js.map