awaitly-analyze 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.cjs CHANGED
@@ -1,8 +1,9 @@
1
- "use strict";var se=Object.create;var R=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var fe=(t,e)=>{for(var n in e)R(t,n,{get:e[n],enumerable:!0})},q=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of le(e))!ce.call(t,r)&&r!==n&&R(t,r,{get:()=>e[r],enumerable:!(o=ie(e,r))||o.enumerable});return t};var ue=(t,e,n)=>(n=t!=null?se(de(t)):{},q(e||!t||!t.__esModule?R(n,"default",{value:t,enumerable:!0}):n,t)),pe=t=>q(R({},"__esModule",{value:!0}),t);var Ye={};fe(Ye,{analyzeWorkflowSource:()=>Ae,clearTreeSitterBrowserCache:()=>V,getWasmBasePath:()=>U,renderMultipleStaticJSON:()=>x,renderPathsMermaid:()=>L,renderStaticJSON:()=>T,renderStaticMermaid:()=>O,resetIdCounter:()=>be,setWasmBasePath:()=>J});module.exports=pe(Ye);var z="/wasm/";function J(t){z=t.endsWith("/")?t:`${t}/`}function U(){return z}var I=null;async function ye(){let t=`${z}tree-sitter-typescript.wasm`,e=await fetch(t);if(!e.ok)throw new Error(`Failed to load TypeScript grammar WASM from: ${t}
1
+ "use strict";var se=Object.create;var $=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var fe=(t,e)=>{for(var n in e)$(t,n,{get:e[n],enumerable:!0})},J=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of le(e))!ce.call(t,r)&&r!==n&&$(t,r,{get:()=>e[r],enumerable:!(o=ie(e,r))||o.enumerable});return t};var ue=(t,e,n)=>(n=t!=null?se(de(t)):{},J(e||!t||!t.__esModule?$(n,"default",{value:t,enumerable:!0}):n,t)),pe=t=>J($({},"__esModule",{value:!0}),t);var Ye={};fe(Ye,{analyzeWorkflowSource:()=>Ae,clearTreeSitterBrowserCache:()=>H,getWasmBasePath:()=>K,renderMultipleStaticJSON:()=>M,renderPathsMermaid:()=>T,renderStaticJSON:()=>x,renderStaticMermaid:()=>O,resetIdCounter:()=>be,setWasmBasePath:()=>U});module.exports=pe(Ye);var R="/wasm/";function U(t){R=t.endsWith("/")?t:`${t}/`}function K(){return R}var I=null;async function ye(){let t=`${R}tree-sitter-typescript.wasm`,e=await fetch(t);if(!e.ok)throw new Error(`Failed to load TypeScript grammar WASM from: ${t}
2
2
  HTTP ${e.status}: ${e.statusText}
3
3
 
4
- Make sure the WASM file is available at this path. You can configure the path using setWasmBasePath().`);let n=await e.arrayBuffer();return new Uint8Array(n)}async function K(){if(I)return I;let{Parser:t,Language:e}=await import("web-tree-sitter");await t.init({locateFile:s=>`${z}${s}`});let n=await ye(),o=await e.load(n),r=new t;return r.setLanguage(o),I={parser:r,language:o},I}function V(){I=null}var H={direction:"TB",showKeys:!1,showConditions:!0,useSubgraphs:!0,styles:{step:"fill:#e1f5fe,stroke:#01579b,color:#01579b",parallel:"fill:#e8f5e9,stroke:#1b5e20,color:#1b5e20",race:"fill:#fff3e0,stroke:#e65100,color:#bf360c",conditional:"fill:#fce4ec,stroke:#880e4f,color:#880e4f",loop:"fill:#f3e5f5,stroke:#4a148c,color:#4a148c",workflowRef:"fill:#e0f2f1,stroke:#004d40,color:#004d40",start:"fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20",end:"fill:#ffcdd2,stroke:#c62828,color:#b71c1c"},maxMarkdownLines:10,includeMarkdown:!0};function O(t,e={}){let n={...H,...e},o={opts:n,nodeCounter:0,edges:[],subgraphs:[],styleClasses:new Map},r=[];if(r.push(`flowchart ${n.direction}`),r.push(""),r.push(` %% Workflow: ${t.root.workflowName}`),t.root.description&&r.push(` %% ${t.root.description}`),n.includeMarkdown&&t.root.markdown){r.push(" %%");let d=t.root.markdown.trim().split(`
4
+ Make sure the WASM file is available at this path. You can configure the path using setWasmBasePath().`);let n=await e.arrayBuffer();return new Uint8Array(n)}async function V(){if(I)return I;let{Parser:t,Language:e}=await import("web-tree-sitter");await t.init({locateFile:s=>`${R}${s}`});let n=await ye(),o=await e.load(n),r=new t;return r.setLanguage(o),I={parser:r,language:o},I}function H(){I=null}var G={direction:"TB",showKeys:!1,showStepDescriptions:!1,includeStepMarkdown:!1,showConditions:!0,useSubgraphs:!0,styles:{step:"fill:#e1f5fe,stroke:#01579b,color:#01579b",parallel:"fill:#e8f5e9,stroke:#1b5e20,color:#1b5e20",race:"fill:#fff3e0,stroke:#e65100,color:#bf360c",conditional:"fill:#fce4ec,stroke:#880e4f,color:#880e4f",loop:"fill:#f3e5f5,stroke:#4a148c,color:#4a148c",workflowRef:"fill:#e0f2f1,stroke:#004d40,color:#004d40",start:"fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20",end:"fill:#ffcdd2,stroke:#c62828,color:#b71c1c"},maxMarkdownLines:10,includeMarkdown:!0};function O(t,e={}){let n={...G,...e},o={opts:n,nodeCounter:0,edges:[],subgraphs:[],styleClasses:new Map},r=[];if(r.push(`flowchart ${n.direction}`),r.push(""),r.push(` %% Workflow: ${t.root.workflowName}`),t.root.description&&r.push(` %% ${t.root.description}`),n.includeMarkdown&&t.root.markdown){r.push(" %%");let d=t.root.markdown.trim().split(`
5
5
  `),f=n.maxMarkdownLines,m=d.slice(0,f);for(let y of m)r.push(` %% ${y}`);d.length>f&&r.push(` %% ... (${d.length-f} more lines)`)}r.push("");let s="start";r.push(` ${s}((Start))`);let{firstNodeId:a,lastNodeIds:i}=_(t.root.children,o,r);a&&o.edges.push({from:s,to:a});let l="end_node";r.push(` ${l}((End))`);for(let d of i)o.edges.push({from:d,to:l});for(let d of o.subgraphs){r.push(""),r.push(` subgraph ${d.id}[${d.label}]`);for(let f of d.content)r.push(` ${f}`);r.push(" end")}r.push(""),r.push(" %% Edges");for(let d of o.edges)d.label&&n.showConditions?r.push(` ${d.from} -->|${g(d.label)}| ${d.to}`):r.push(` ${d.from} --> ${d.to}`);r.push(""),r.push(" %% Styles"),r.push(` classDef stepStyle ${n.styles.step}`),r.push(` classDef parallelStyle ${n.styles.parallel}`),r.push(` classDef raceStyle ${n.styles.race}`),r.push(` classDef conditionalStyle ${n.styles.conditional}`),r.push(` classDef loopStyle ${n.styles.loop}`),r.push(` classDef workflowRefStyle ${n.styles.workflowRef}`),r.push(` classDef startStyle ${n.styles.start}`),r.push(` classDef endStyle ${n.styles.end}`),r.push(` class ${s} startStyle`),r.push(` class ${l} endStyle`);for(let[d,f]of o.styleClasses)r.push(` class ${d} ${f}`);return r.join(`
6
- `)}function _(t,e,n){if(t.length===0)return{firstNodeId:null,lastNodeIds:[]};let o=null,r=[];for(let s of t){let a=P(s,e,n);if(o===null&&a.firstNodeId&&(o=a.firstNodeId),a.firstNodeId)for(let i of r)e.edges.push({from:i,to:a.firstNodeId});r=a.lastNodeIds}return{firstNodeId:o,lastNodeIds:r}}function P(t,e,n){switch(t.type){case"step":return me(t,e,n);case"sequence":return Ne(t,e,n);case"parallel":return he(t,e,n);case"race":return Se(t,e,n);case"conditional":return ge(t,e,n);case"loop":return we(t,e,n);case"workflow-ref":return Ce(t,e,n);case"unknown":return Fe(t,e,n);default:return{firstNodeId:null,lastNodeIds:[]}}}function me(t,e,n){let o=`step_${++e.nodeCounter}`,r=t.name??t.callee??"step";return e.opts.showKeys&&t.key&&(r=`${r}\\n[${t.key}]`),t.retry&&(r+="\\n(retry)"),t.timeout&&(r+="\\n(timeout)"),n.push(` ${o}[${g(r)}]`),e.styleClasses.set(o,"stepStyle"),{firstNodeId:o,lastNodeIds:[o]}}function Ne(t,e,n){return _(t.children,e,n)}function he(t,e,n){let o=`parallel_fork_${++e.nodeCounter}`,r=`parallel_join_${++e.nodeCounter}`,s=t.name?`${t.name} (${t.mode})`:`Parallel (${t.mode})`;n.push(` ${o}{{"${s}"}}`),e.styleClasses.set(o,"parallelStyle"),n.push(` ${r}{{"Join"}}`),e.styleClasses.set(r,"parallelStyle");for(let a=0;a<t.children.length;a++){let i=t.children[a],l=P(i,e,n);l.firstNodeId&&e.edges.push({from:o,to:l.firstNodeId,label:`branch ${a+1}`});for(let d of l.lastNodeIds)e.edges.push({from:d,to:r})}return{firstNodeId:o,lastNodeIds:[r]}}function Se(t,e,n){let o=`race_fork_${++e.nodeCounter}`,r=`race_join_${++e.nodeCounter}`,s=t.name?t.name:"Race";n.push(` ${o}{{{"${s}"}}}`),e.styleClasses.set(o,"raceStyle"),n.push(` ${r}{{{"Winner"}}}`),e.styleClasses.set(r,"raceStyle");for(let a=0;a<t.children.length;a++){let i=t.children[a],l=P(i,e,n);l.firstNodeId&&e.edges.push({from:o,to:l.firstNodeId,label:`racer ${a+1}`});for(let d of l.lastNodeIds)e.edges.push({from:d,to:r})}return{firstNodeId:o,lastNodeIds:[r]}}function ge(t,e,n){let o=`decision_${++e.nodeCounter}`,r=G(t.condition,30);n.push(` ${o}{${g(r)}}`),e.styleClasses.set(o,"conditionalStyle");let s=[],a=_(t.consequent,e,n);if(a.firstNodeId){let i=t.helper==="unless"||t.helper==="unlessOr"?"false":"true";e.edges.push({from:o,to:a.firstNodeId,label:i}),s.push(...a.lastNodeIds)}if(t.alternate&&t.alternate.length>0){let i=_(t.alternate,e,n);if(i.firstNodeId){let l=t.helper==="unless"||t.helper==="unlessOr"?"true":"false";e.edges.push({from:o,to:i.firstNodeId,label:l}),s.push(...i.lastNodeIds)}}else s.push(o);return{firstNodeId:o,lastNodeIds:s}}function we(t,e,n){let o=`loop_start_${++e.nodeCounter}`,r=`loop_end_${++e.nodeCounter}`,s=t.iterSource?`${t.loopType}: ${G(t.iterSource,20)}`:t.loopType;n.push(` ${o}([${g(s)}])`),e.styleClasses.set(o,"loopStyle");let a=_(t.body,e,n);a.firstNodeId&&e.edges.push({from:o,to:a.firstNodeId,label:"iterate"}),n.push(` ${r}([Continue?])`),e.styleClasses.set(r,"loopStyle");for(let i of a.lastNodeIds)e.edges.push({from:i,to:r});return e.edges.push({from:r,to:o,label:"next"}),{firstNodeId:o,lastNodeIds:[r]}}function Ce(t,e,n){let o=`workflow_ref_${++e.nodeCounter}`,r=`[[${t.workflowName}]]`;return n.push(` ${o}${r}`),e.styleClasses.set(o,"workflowRefStyle"),{firstNodeId:o,lastNodeIds:[o]}}function Fe(t,e,n){let o=`unknown_${++e.nodeCounter}`;return n.push(` ${o}[/"Unknown: ${g(t.reason)}"/]`),{firstNodeId:o,lastNodeIds:[o]}}function g(t){return t.replace(/"/g,"'").replace(/\[/g,"(").replace(/\]/g,")").replace(/\{/g,"(").replace(/\}/g,")").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function G(t,e){return t.length<=e?t:t.slice(0,e-3)+"..."}function L(t,e={}){let n={...H,...e},o=[];o.push(`flowchart ${n.direction}`),o.push("");let r=new Map,s=0;for(let i of t)for(let l of i.steps)r.has(l.nodeId)||r.set(l.nodeId,{id:`step_${++s}`,label:l.name??l.nodeId});o.push(" start((Start))"),o.push(" end_node((End))"),o.push("");for(let[,{id:i,label:l}]of r)o.push(` ${i}[${g(l)}]`);o.push("");let a=new Set;for(let i of t){if(i.steps.length===0)continue;let l=i.steps[0],d=r.get(l.nodeId).id;a.add(`start --> ${d}`);for(let y=0;y<i.steps.length-1;y++){let b=i.steps[y],S=i.steps[y+1],N=r.get(b.nodeId).id,A=r.get(S.nodeId).id;a.add(`${N} --> ${A}`)}let f=i.steps[i.steps.length-1],m=r.get(f.nodeId).id;a.add(`${m} --> end_node`)}o.push(" %% Edges");for(let i of a)o.push(` ${i}`);return o.join(`
7
- `)}function T(t,e={}){let{pretty:n=!0,includeMetadata:o=!0}=e,r={root:t.root,metadata:o?t.metadata:void 0,references:t.references.size>0?Object.fromEntries(Array.from(t.references.entries()).map(([s,a])=>[s,{root:a.root,metadata:o?a.metadata:void 0}])):void 0};return n?JSON.stringify(r,null,2):JSON.stringify(r)}function x(t,e,n={}){let{pretty:o=!0,includeMetadata:r=!0}=n,s={file:e,analyzedAt:Date.now(),workflowCount:t.length,workflows:t.map(a=>({root:a.root,metadata:r?a.metadata:void 0,references:a.references.size>0?Object.fromEntries(Array.from(a.references.entries()).map(([i,l])=>[i,{root:l.root,metadata:r?l.metadata:void 0}])):void 0}))};return o?JSON.stringify(s,null,2):JSON.stringify(s)}var ke={tsConfigPath:"./tsconfig.json",resolveReferences:!1,maxReferenceDepth:5,includeLocations:!0,detect:"all",assumeImported:!1},Q=0;function be(){Q=0}function p(){return`ts-${++Q}`}async function Ae(t,e={}){let n={...ke,...e},{parser:o}=await K(),r=o.parse(t);if(!r)throw new Error("Failed to parse source code");let s={sourceCode:t,filePath:"<source>",opts:n,warnings:[],stats:j(),workflowNames:new Set};M(r.rootNode,s).forEach(l=>s.workflowNames.add(l.name));let i=[];if(n.detect==="all"||n.detect==="createWorkflow"){let l=_e(r.rootNode,s);for(let d of l){let f=Pe(d,s);f&&i.push(f)}}if(n.detect==="all"||n.detect==="run"){let l=$e(r.rootNode,s);for(let d of l){let f=Oe(d,s);f&&i.push(f)}}return i}function Ie(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s){let a=c(r,e);if(a==="description"){let i=C(s,e);i&&(n.description=i)}else if(a==="markdown"){let i=C(s,e);i&&(n.markdown=i)}}}return n}function M(t,e){let n=[];return k(t,o=>{if(o.type==="call_expression"){let r=o.childForFieldName("function");if(r&&c(r,e)==="createWorkflow"){let a=Le(o,e);if(a){let l=o.childForFieldName("arguments")?.namedChildren[1],d=l?Ie(l,e):{};n.push({name:a,createWorkflowCall:o,description:d.description,markdown:d.markdown})}}}}),n}function _e(t,e){let n=M(t,e),o=new Set(n.map(s=>s.name)),r=[];return k(t,s=>{if(s.type==="call_expression"){let a=s.childForFieldName("function");if(a){let i=c(a,e);if(o.has(i)){let l=s.childForFieldName("arguments");if(l){let d=l.namedChildren[0];(d?.type==="arrow_function"||d?.type==="function_expression")&&r.push(s)}}}}}),r}function Re(t,e,n){let o=new Set;return k(t,r=>{if(r.type==="import_statement"){let s=!1;for(let i=0;i<r.childCount;i++){let l=r.children[i];if(l&&l.type==="type"){s=!0;break}}if(s)return;let a=r.childForFieldName("source");if(a){let l=c(a,n).slice(1,-1);if(l==="awaitly"||l.startsWith("@awaitly/")){for(let d of r.namedChildren)if(d.type==="import_clause"){for(let f of d.namedChildren)if(f.type==="named_imports"){for(let m of f.namedChildren)if(m.type==="import_specifier"){let y=!1;for(let N of m.children)if(N.type==="type"){y=!0;break}if(y)continue;let b=m.childForFieldName("name"),S=m.childForFieldName("alias");if(b){let N=c(b,n);if(N===e){let A=S?c(S,n):N;o.add(A)}}}}}}}}}),o}function ze(t,e,n){let o=t.parent;for(;o;){if(o.type==="statement_block"||o.type==="program")for(let r of o.namedChildren){if(r.startIndex>=t.startIndex)break;if(r.type==="lexical_declaration"||r.type==="variable_declaration"){for(let s of r.namedChildren)if(s.type==="variable_declarator"){let a=s.childForFieldName("name");if(a&&c(a,n)===e)return!0}}else if(r.type==="function_declaration"){let s=r.childForFieldName("name");if(s&&c(s,n)===e)return!0}}if(o.type==="arrow_function"||o.type==="function_expression"||o.type==="function_declaration"||o.type==="method_definition"){let r=o.childForFieldName("parameters");if(r)for(let s of r.namedChildren){if(s.type==="identifier"&&c(s,n)===e)return!0;if(s.type==="object_pattern"||s.type==="array_pattern"){let a=!1;if(k(s,i=>{i.type==="identifier"&&c(i,n)===e&&(a=!0)}),a)return!0}if(s.type==="assignment_pattern"){let a=s.childForFieldName("left");if(a?.type==="identifier"&&c(a,n)===e)return!0}}}if(o.type==="program")break;o=o.parent}return!1}function $e(t,e){let n=Re(t,"run",e);if(e.opts.assumeImported&&n.add("run"),n.size===0)return[];let o=[];return k(t,r=>{if(r.type==="call_expression"){let s=r.childForFieldName("function");if(s&&s.type==="identifier"){let a=c(s,e);if(n.has(a)){if(ze(r,a,e))return;let l=r.childForFieldName("arguments")?.namedChildren[0];(l?.type==="arrow_function"||l?.type==="function_expression")&&o.push(r)}}}}),o}function We(t,e){let n=t.startPosition.row+1,o=e.filePath;return`run@${o.includes("/")?o.split("/").pop()||o:o.includes("\\")&&o.split("\\").pop()||o}:${n}`}function Oe(t,e){let o=t.childForFieldName("arguments")?.namedChildren[0],r=[],s=j(),a={...e,warnings:r,stats:s};if(!o||o.type!=="arrow_function"&&o.type!=="function_expression")return r.push({code:"CALLBACK_NOT_FOUND",message:"Could not find callback for run()",location:u(t,a)}),null;let i=We(t,a),l=X(o,a),d=a.stepParameterName;a.stepParameterName=l;let f=Z(o,a);a.stepParameterName=d;let m={id:p(),type:"workflow",workflowName:i,source:"run",dependencies:[],errorTypes:[],children:F(f),location:a.opts.includeLocations?u(t,a):void 0},y={analyzedAt:Date.now(),filePath:a.filePath,warnings:r,stats:s};return{root:m,metadata:y,references:new Map}}function Pe(t,e){let n=t.childForFieldName("function"),o=n?c(n,e):"<unknown>",s=t.childForFieldName("arguments")?.namedChildren[0],a=[],i=j(),l={...e,warnings:a,stats:i};if(!s||s.type!=="arrow_function"&&s.type!=="function_expression")return a.push({code:"CALLBACK_NOT_FOUND",message:`Could not find callback for workflow ${o}`,location:u(t,l)}),null;let d=l.currentWorkflow;l.currentWorkflow=o;let f=X(s,l),m=l.stepParameterName;l.stepParameterName=f;let y=Z(s,l);l.currentWorkflow=d,l.stepParameterName=m;let S=M(t.tree?.rootNode||t,e).find(ae=>ae.name===o),N={id:p(),type:"workflow",workflowName:o,source:"createWorkflow",dependencies:[],errorTypes:[],children:F(y),description:S?.description,markdown:S?.markdown},A={analyzedAt:Date.now(),filePath:l.filePath,warnings:a,stats:i};return{root:N,metadata:A,references:new Map}}function Le(t,e){let n=t;for(;n;){if(n.type==="variable_declarator"){let o=n.childForFieldName("name");if(o)return c(o,e)}n=n.parent}return null}function X(t,e){let n=t.childForFieldName("parameters");if(!n)return;let o=n.namedChildren[0];if(o){if(o.type==="identifier")return c(o,e);if(o.type==="required_parameter"){let r=o.childForFieldName("pattern");if(r)return r.type==="object_pattern"?Y(r,e):c(r,e)}if(o.type==="object_pattern")return Y(o,e)}}function Y(t,e){for(let n of t.namedChildren){if(n.type==="pair_pattern"){let o=n.childForFieldName("key"),r=n.childForFieldName("value");if(o&&r&&c(o,e)==="step"){if(r.type==="assignment_pattern"){let a=r.childForFieldName("left");if(a)return c(a,e)}return c(r,e)}}if(n.type==="shorthand_property_identifier_pattern"&&c(n,e)==="step")return"step";if(n.type==="assignment_pattern"){let o=n.childForFieldName("left");if(o&&c(o,e)==="step")return"step"}}}function Z(t,e){let n=t.childForFieldName("body");return n?n.type==="statement_block"?D(n.namedChildren,e):h(n,e):[]}function D(t,e){let n=[];for(let o of t){let r=ee(o,e);n.push(...r)}return n}function ee(t,e){switch(t.type){case"expression_statement":{let n=t.namedChildren[0];return n?h(n,e):[]}case"variable_declaration":case"lexical_declaration":return Te(t,e);case"return_statement":{let n=t.childForFieldName("value");return n?h(n,e):[]}case"if_statement":return qe(t,e);case"for_statement":return Ve(t,e);case"for_in_statement":return He(t,e);case"while_statement":return Ge(t,e);default:return[]}}function h(t,e){if(t.type==="await_expression"){let n=t.namedChildren[0];return n?h(n,e):[]}if(t.type==="parenthesized_expression"){let n=t.namedChildren[0];return n?h(n,e):[]}return t.type==="call_expression"?E(t,e):[]}function Te(t,e){let n=[];for(let o of t.namedChildren)if(o.type==="variable_declarator"){let r=o.childForFieldName("value");r&&n.push(...h(r,e))}return n}function E(t,e){let n=t.childForFieldName("function");if(!n)return[];let o=c(n,e),r=e.stepParameterName||"step";return o===r?[Me(t,e)]:o===`${r}.retry`?[De(t,e)]:o===`${r}.withTimeout`?[Ee(t,e)]:o===`${r}.parallel`?Be(t,e):o===`${r}.race`?je(t,e):["when","unless","whenOr","unlessOr"].includes(o)?Je(t,o,e):o==="allAsync"||o==="allSettledAsync"?Ue(t,o==="allAsync"?"all":"allSettled",e):o==="anyAsync"?Ke(t,e):xe(t,o,e)?ve(t,o,e):[]}function xe(t,e,n){if(e===n.currentWorkflow)return!1;let r=t.childForFieldName("arguments")?.namedChildren[0];if(!r)return!1;if(r.type==="arrow_function"||r.type==="function_expression"){if(n.workflowNames.has(e))return!0;let s=r.childForFieldName("parameters");if(s){let a=c(s,n);if(a.includes("step")||a.includes("deps"))return!0}}return!1}function ve(t,e,n){return n.stats.workflowRefCount++,[{id:p(),type:"workflow-ref",workflowName:e,resolved:!1,location:n.opts.includeLocations?u(t,n):void 0}]}function B(t,e){if(t.type==="call_expression"){let n=t.childForFieldName("function");if(n)return c(n,e)}if(t.type==="statement_block"){for(let n of t.namedChildren)if(n.type==="return_statement"){let o=n.namedChildren[0];if(o?.type==="call_expression"){let r=o.childForFieldName("function");if(r)return c(r,e)}else if(o)return c(o,e)}}return c(t,e)}function Me(t,e){e.stats.totalSteps++;let n=t.childForFieldName("arguments"),o=n?.namedChildren[0],r=n?.namedChildren[1],s="<unknown>";if(o)if(o.type==="arrow_function"||o.type==="function_expression"){let l=o.childForFieldName("body");l&&(s=B(l,e))}else s=c(o,e);let a=r?$(r,e):{};return{id:p(),type:"step",callee:s,key:a.key,name:a.name,retry:a.retry,timeout:a.timeout,location:e.opts.includeLocations?u(t,e):void 0}}function De(t,e){e.stats.totalSteps++;let o=t.childForFieldName("arguments")?.namedChildren||[],r=o[0],s="<unknown>";if(r)if(r.type==="arrow_function"||r.type==="function_expression"){let d=r.childForFieldName("body");d&&(s=B(d,e))}else s=c(r,e);let a=o[1],i=a?$(a,e):{},l=a?te(a,e):void 0;return{id:p(),type:"step",callee:s,key:i.key,name:i.name,retry:l,timeout:i.timeout,location:e.opts.includeLocations?u(t,e):void 0}}function Ee(t,e){e.stats.totalSteps++;let o=t.childForFieldName("arguments")?.namedChildren||[],r=o[0],s="<unknown>";if(r)if(r.type==="arrow_function"||r.type==="function_expression"){let d=r.childForFieldName("body");d&&(s=B(d,e))}else s=c(r,e);let a=o[1],i=a?$(a,e):{},l=a?ne(a,e):void 0;return{id:p(),type:"step",callee:s,key:i.key,name:i.name,retry:i.retry,timeout:l,location:e.opts.includeLocations?u(t,e):void 0}}function $(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s){let a=c(r,e);if(a==="key"){let i=C(s,e);i&&(n.key=i)}else if(a==="name"){let i=C(s,e);i&&(n.name=i)}else a==="retry"?n.retry=te(s,e):a==="timeout"&&(n.timeout=ne(s,e))}}return n}function te(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s){let a=c(r,e);if(a==="attempts"){let i=v(s,e);n.attempts=i}else if(a==="backoff"){let i=C(s,e);i==="fixed"||i==="linear"||i==="exponential"?n.backoff=i:n.backoff="<dynamic>"}else if(a==="baseDelay"){let i=v(s,e);n.baseDelay=i}else a==="retryOn"&&(n.retryOn=c(s,e))}}return n}function ne(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s&&c(r,e)==="ms"){let i=v(s,e);n.ms=i}}return n}function v(t,e){let n=c(t,e);if(t.type==="number"){let o=parseFloat(n);return isNaN(o)?"<dynamic>":o}return"<dynamic>"}function Be(t,e){let n=t.childForFieldName("arguments"),o=n?.namedChildren[0];if(!o)return[];if(o.type==="string"||o.type==="identifier"||o.type==="member_expression"){let i=o.type==="string"?C(o,e):c(o,e),l=n?.namedChildren[1];if(l&&(l.type==="arrow_function"||l.type==="function_expression")){let d=W(l,e);if(d.length>0){for(let f of d)f.type==="parallel"&&i&&(f.name=i);return d}}return[]}if(o.type!=="object")return[];e.stats.parallelCount++;let r=[];for(let i of o.namedChildren)if(i.type==="pair"){let l=i.childForFieldName("key"),d=i.childForFieldName("value");if(l&&d){let f=oe(l,d,e);f&&r.push(f)}}let s=n?.namedChildren[1],a=s?$(s,e):{};return[{id:p(),type:"parallel",mode:"all",name:a.name,children:r,callee:"step.parallel",location:e.opts.includeLocations?u(t,e):void 0}]}function oe(t,e,n){n.stats.totalSteps++;let o=c(t,n),r="<unknown>";if(e.type==="arrow_function"||e.type==="function_expression"){let s=e.childForFieldName("body");if(s?.type==="call_expression"){let a=s.childForFieldName("function");a&&(r=c(a,n))}}return{id:p(),type:"step",callee:r,name:o,location:n.opts.includeLocations?u(e,n):void 0}}function je(t,e){e.stats.raceCount++;let o=t.childForFieldName("arguments")?.namedChildren[0];if(!o||o.type!=="object")return[];let r=[];for(let s of o.namedChildren)if(s.type==="pair"){let a=s.childForFieldName("key"),i=s.childForFieldName("value");if(a&&i){let l=oe(a,i,e);l&&r.push(l)}}return[{id:p(),type:"race",children:r,callee:"step.race",location:e.opts.includeLocations?u(t,e):void 0}]}function qe(t,e){e.stats.conditionalCount++;let n=t.childForFieldName("condition"),o=t.childForFieldName("consequence"),r=t.childForFieldName("alternative"),s=n?c(n,e).replace(/^\(|\)$/g,""):"<unknown>",a=o?w(o,e):[],i;if(r)if(r.type==="else_clause"){let l=r.namedChildren[0];l&&(i=w(l,e))}else i=w(r,e);return[{id:p(),type:"conditional",condition:s,helper:null,consequent:a,alternate:i?.length?i:void 0,location:e.opts.includeLocations?u(t,e):void 0}]}function w(t,e){return t.type==="statement_block"?D(t.namedChildren,e):ee(t,e)}function Je(t,e,n){n.stats.conditionalCount++;let r=t.childForFieldName("arguments")?.namedChildren||[],s=r[0],a=s?c(s,n):"<unknown>",i=r[1],l=i?W(i,n):[],d;return(e==="whenOr"||e==="unlessOr")&&r[2]&&(d=c(r[2],n)),[{id:p(),type:"conditional",condition:a,helper:e,consequent:l,defaultValue:d,location:n.opts.includeLocations?u(t,n):void 0}]}function W(t,e){if(t.type==="arrow_function"||t.type==="function_expression"){let n=t.childForFieldName("body");if(n)return n.type==="statement_block"?D(n.namedChildren,e):h(n,e)}return h(t,e)}function Ue(t,e,n){n.stats.parallelCount++;let r=t.childForFieldName("arguments")?.namedChildren[0];if(!r||r.type!=="array")return[];let s=[];for(let a of r.namedChildren)if(a.type==="call_expression"){let i=E(a,n);if(i.length>0)s.push(...F(i));else{let l=re(a,n);l&&s.push(l)}}else{let i=W(a,n);s.push(...F(i))}return[{id:p(),type:"parallel",mode:e,children:s,callee:e==="all"?"allAsync":"allSettledAsync",location:n.opts.includeLocations?u(t,n):void 0}]}function Ke(t,e){e.stats.raceCount++;let o=t.childForFieldName("arguments")?.namedChildren[0];if(!o||o.type!=="array")return[];let r=[];for(let a of o.namedChildren)if(a.type==="call_expression"){let i=E(a,e);if(i.length>0)r.push(...F(i));else{let l=re(a,e);l&&r.push(l)}}else{let i=W(a,e);r.push(...F(i))}return[{id:p(),type:"race",children:r,callee:"anyAsync",location:e.opts.includeLocations?u(t,e):void 0}]}function re(t,e){e.stats.totalSteps++;let n=t.childForFieldName("function"),o=n?c(n,e):"<unknown>",r=o.includes(".")?o.split(".").pop():o;return{id:p(),type:"step",name:r,callee:o,location:e.opts.includeLocations?u(t,e):void 0}}function Ve(t,e){let n=t.childForFieldName("body");if(!n)return[];let o=w(n,e);return o.length===0?[]:(e.stats.loopCount++,[{id:p(),type:"loop",loopType:"for",body:o,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}])}function He(t,e){let n=t.childForFieldName("body");if(!n)return[];let o=w(n,e);if(o.length===0)return[];e.stats.loopCount++;let s=c(t,e).includes(" of "),a=t.childForFieldName("right"),i=a?c(a,e):void 0;return[{id:p(),type:"loop",loopType:s?"for-of":"for-in",iterSource:i,body:o,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}]}function Ge(t,e){let n=t.childForFieldName("body");if(!n)return[];let o=w(n,e);return o.length===0?[]:(e.stats.loopCount++,[{id:p(),type:"loop",loopType:"while",body:o,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}])}function c(t,e){return e.sourceCode.slice(t.startIndex,t.endIndex)}function C(t,e){let n=c(t,e);return t.type==="string"?n.slice(1,-1):t.type==="template_string"?"<dynamic>":n}function u(t,e){return{filePath:e.filePath,line:t.startPosition.row+1,column:t.startPosition.column,endLine:t.endPosition.row+1,endColumn:t.endPosition.column}}function k(t,e){e(t);for(let n of t.namedChildren)k(n,e)}function F(t){return t.length<=1?t:[{id:p(),type:"sequence",children:t}]}function j(){return{totalSteps:0,conditionalCount:0,parallelCount:0,raceCount:0,loopCount:0,workflowRefCount:0,unknownCount:0}}0&&(module.exports={analyzeWorkflowSource,clearTreeSitterBrowserCache,getWasmBasePath,renderMultipleStaticJSON,renderPathsMermaid,renderStaticJSON,renderStaticMermaid,resetIdCounter,setWasmBasePath});
6
+ `)}function _(t,e,n){if(t.length===0)return{firstNodeId:null,lastNodeIds:[]};let o=null,r=[];for(let s of t){let a=L(s,e,n);if(o===null&&a.firstNodeId&&(o=a.firstNodeId),a.firstNodeId)for(let i of r)e.edges.push({from:i,to:a.firstNodeId});r=a.lastNodeIds}return{firstNodeId:o,lastNodeIds:r}}function L(t,e,n){switch(t.type){case"step":return me(t,e,n);case"sequence":return Ne(t,e,n);case"parallel":return he(t,e,n);case"race":return Se(t,e,n);case"conditional":return ge(t,e,n);case"loop":return we(t,e,n);case"workflow-ref":return Ce(t,e,n);case"unknown":return ke(t,e,n);default:return{firstNodeId:null,lastNodeIds:[]}}}function me(t,e,n){let o=`step_${++e.nodeCounter}`,r=t.name??t.callee??"step";if(e.opts.showKeys&&t.key&&(r=`${r}\\n[${t.key}]`),e.opts.showStepDescriptions&&t.description&&(r=`${r}\\n${P(t.description,40)}`),t.retry&&(r+="\\n(retry)"),t.timeout&&(r+="\\n(timeout)"),e.opts.includeStepMarkdown&&t.markdown){let s=t.markdown.trim().split(`
7
+ `),a=e.opts.maxMarkdownLines,i=s.slice(0,a);n.push(` %% Step: ${t.name??t.callee??"step"}`);for(let l of i)n.push(` %% ${l}`);s.length>a&&n.push(` %% ... (${s.length-a} more lines)`)}return n.push(` ${o}[${g(r)}]`),e.styleClasses.set(o,"stepStyle"),{firstNodeId:o,lastNodeIds:[o]}}function Ne(t,e,n){return _(t.children,e,n)}function he(t,e,n){let o=`parallel_fork_${++e.nodeCounter}`,r=`parallel_join_${++e.nodeCounter}`,s=t.name?`${t.name} (${t.mode})`:`Parallel (${t.mode})`;n.push(` ${o}{{"${s}"}}`),e.styleClasses.set(o,"parallelStyle"),n.push(` ${r}{{"Join"}}`),e.styleClasses.set(r,"parallelStyle");for(let a=0;a<t.children.length;a++){let i=t.children[a],l=L(i,e,n);l.firstNodeId&&e.edges.push({from:o,to:l.firstNodeId,label:`branch ${a+1}`});for(let d of l.lastNodeIds)e.edges.push({from:d,to:r})}return{firstNodeId:o,lastNodeIds:[r]}}function Se(t,e,n){let o=`race_fork_${++e.nodeCounter}`,r=`race_join_${++e.nodeCounter}`,s=t.name?t.name:"Race";n.push(` ${o}{{{"${s}"}}}`),e.styleClasses.set(o,"raceStyle"),n.push(` ${r}{{{"Winner"}}}`),e.styleClasses.set(r,"raceStyle");for(let a=0;a<t.children.length;a++){let i=t.children[a],l=L(i,e,n);l.firstNodeId&&e.edges.push({from:o,to:l.firstNodeId,label:`racer ${a+1}`});for(let d of l.lastNodeIds)e.edges.push({from:d,to:r})}return{firstNodeId:o,lastNodeIds:[r]}}function ge(t,e,n){let o=`decision_${++e.nodeCounter}`,r=P(t.condition,30);n.push(` ${o}{${g(r)}}`),e.styleClasses.set(o,"conditionalStyle");let s=[],a=_(t.consequent,e,n);if(a.firstNodeId){let i=t.helper==="unless"||t.helper==="unlessOr"?"false":"true";e.edges.push({from:o,to:a.firstNodeId,label:i}),s.push(...a.lastNodeIds)}if(t.alternate&&t.alternate.length>0){let i=_(t.alternate,e,n);if(i.firstNodeId){let l=t.helper==="unless"||t.helper==="unlessOr"?"true":"false";e.edges.push({from:o,to:i.firstNodeId,label:l}),s.push(...i.lastNodeIds)}}else s.push(o);return{firstNodeId:o,lastNodeIds:s}}function we(t,e,n){let o=`loop_start_${++e.nodeCounter}`,r=`loop_end_${++e.nodeCounter}`,s=t.iterSource?`${t.loopType}: ${P(t.iterSource,20)}`:t.loopType;n.push(` ${o}([${g(s)}])`),e.styleClasses.set(o,"loopStyle");let a=_(t.body,e,n);a.firstNodeId&&e.edges.push({from:o,to:a.firstNodeId,label:"iterate"}),n.push(` ${r}([Continue?])`),e.styleClasses.set(r,"loopStyle");for(let i of a.lastNodeIds)e.edges.push({from:i,to:r});return e.edges.push({from:r,to:o,label:"next"}),{firstNodeId:o,lastNodeIds:[r]}}function Ce(t,e,n){let o=`workflow_ref_${++e.nodeCounter}`,r=`[[${t.workflowName}]]`;return n.push(` ${o}${r}`),e.styleClasses.set(o,"workflowRefStyle"),{firstNodeId:o,lastNodeIds:[o]}}function ke(t,e,n){let o=`unknown_${++e.nodeCounter}`;return n.push(` ${o}[/"Unknown: ${g(t.reason)}"/]`),{firstNodeId:o,lastNodeIds:[o]}}function g(t){return t.replace(/"/g,"'").replace(/\[/g,"(").replace(/\]/g,")").replace(/\{/g,"(").replace(/\}/g,")").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function P(t,e){return t.length<=e?t:t.slice(0,e-3)+"..."}function T(t,e={}){let n={...G,...e},o=[];o.push(`flowchart ${n.direction}`),o.push("");let r=new Map,s=0;for(let i of t)for(let l of i.steps)r.has(l.nodeId)||r.set(l.nodeId,{id:`step_${++s}`,label:l.name??l.nodeId});o.push(" start((Start))"),o.push(" end_node((End))"),o.push("");for(let[,{id:i,label:l}]of r)o.push(` ${i}[${g(l)}]`);o.push("");let a=new Set;for(let i of t){if(i.steps.length===0)continue;let l=i.steps[0],d=r.get(l.nodeId).id;a.add(`start --> ${d}`);for(let y=0;y<i.steps.length-1;y++){let b=i.steps[y],S=i.steps[y+1],N=r.get(b.nodeId).id,A=r.get(S.nodeId).id;a.add(`${N} --> ${A}`)}let f=i.steps[i.steps.length-1],m=r.get(f.nodeId).id;a.add(`${m} --> end_node`)}o.push(" %% Edges");for(let i of a)o.push(` ${i}`);return o.join(`
8
+ `)}function x(t,e={}){let{pretty:n=!0,includeMetadata:o=!0}=e,r={root:t.root,metadata:o?t.metadata:void 0,references:t.references.size>0?Object.fromEntries(Array.from(t.references.entries()).map(([s,a])=>[s,{root:a.root,metadata:o?a.metadata:void 0}])):void 0};return n?JSON.stringify(r,null,2):JSON.stringify(r)}function M(t,e,n={}){let{pretty:o=!0,includeMetadata:r=!0}=n,s={file:e,analyzedAt:Date.now(),workflowCount:t.length,workflows:t.map(a=>({root:a.root,metadata:r?a.metadata:void 0,references:a.references.size>0?Object.fromEntries(Array.from(a.references.entries()).map(([i,l])=>[i,{root:l.root,metadata:r?l.metadata:void 0}])):void 0}))};return o?JSON.stringify(s,null,2):JSON.stringify(s)}var Fe={tsConfigPath:"./tsconfig.json",resolveReferences:!1,maxReferenceDepth:5,includeLocations:!0,detect:"all",assumeImported:!1},Q=0;function be(){Q=0}function p(){return`ts-${++Q}`}async function Ae(t,e={}){let n={...Fe,...e},{parser:o}=await V(),r=o.parse(t);if(!r)throw new Error("Failed to parse source code");let s={sourceCode:t,filePath:"<source>",opts:n,warnings:[],stats:q(),workflowNames:new Set};D(r.rootNode,s).forEach(l=>s.workflowNames.add(l.name));let i=[];if(n.detect==="all"||n.detect==="createWorkflow"){let l=_e(r.rootNode,s);for(let d of l){let f=Le(d,s);f&&i.push(f)}}if(n.detect==="all"||n.detect==="run"){let l=ze(r.rootNode,s);for(let d of l){let f=Oe(d,s);f&&i.push(f)}}return i}function Ie(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s){let a=c(r,e);if(a==="description"){let i=C(s,e);i&&(n.description=i)}else if(a==="markdown"){let i=C(s,e);i&&(n.markdown=i)}}}return n}function D(t,e){let n=[];return F(t,o=>{if(o.type==="call_expression"){let r=o.childForFieldName("function");if(r&&c(r,e)==="createWorkflow"){let a=Pe(o,e);if(a){let l=o.childForFieldName("arguments")?.namedChildren[1],d=l?Ie(l,e):{};n.push({name:a,createWorkflowCall:o,description:d.description,markdown:d.markdown})}}}}),n}function _e(t,e){let n=D(t,e),o=new Set(n.map(s=>s.name)),r=[];return F(t,s=>{if(s.type==="call_expression"){let a=s.childForFieldName("function");if(a){let i=c(a,e);if(o.has(i)){let l=s.childForFieldName("arguments");if(l){let d=l.namedChildren[0];(d?.type==="arrow_function"||d?.type==="function_expression")&&r.push(s)}}}}}),r}function $e(t,e,n){let o=new Set;return F(t,r=>{if(r.type==="import_statement"){let s=!1;for(let i=0;i<r.childCount;i++){let l=r.children[i];if(l&&l.type==="type"){s=!0;break}}if(s)return;let a=r.childForFieldName("source");if(a){let l=c(a,n).slice(1,-1);if(l==="awaitly"||l.startsWith("@awaitly/")){for(let d of r.namedChildren)if(d.type==="import_clause"){for(let f of d.namedChildren)if(f.type==="named_imports"){for(let m of f.namedChildren)if(m.type==="import_specifier"){let y=!1;for(let N of m.children)if(N.type==="type"){y=!0;break}if(y)continue;let b=m.childForFieldName("name"),S=m.childForFieldName("alias");if(b){let N=c(b,n);if(N===e){let A=S?c(S,n):N;o.add(A)}}}}}}}}}),o}function Re(t,e,n){let o=t.parent;for(;o;){if(o.type==="statement_block"||o.type==="program")for(let r of o.namedChildren){if(r.startIndex>=t.startIndex)break;if(r.type==="lexical_declaration"||r.type==="variable_declaration"){for(let s of r.namedChildren)if(s.type==="variable_declarator"){let a=s.childForFieldName("name");if(a&&c(a,n)===e)return!0}}else if(r.type==="function_declaration"){let s=r.childForFieldName("name");if(s&&c(s,n)===e)return!0}}if(o.type==="arrow_function"||o.type==="function_expression"||o.type==="function_declaration"||o.type==="method_definition"){let r=o.childForFieldName("parameters");if(r)for(let s of r.namedChildren){if(s.type==="identifier"&&c(s,n)===e)return!0;if(s.type==="object_pattern"||s.type==="array_pattern"){let a=!1;if(F(s,i=>{i.type==="identifier"&&c(i,n)===e&&(a=!0)}),a)return!0}if(s.type==="assignment_pattern"){let a=s.childForFieldName("left");if(a?.type==="identifier"&&c(a,n)===e)return!0}}}if(o.type==="program")break;o=o.parent}return!1}function ze(t,e){let n=$e(t,"run",e);if(e.opts.assumeImported&&n.add("run"),n.size===0)return[];let o=[];return F(t,r=>{if(r.type==="call_expression"){let s=r.childForFieldName("function");if(s&&s.type==="identifier"){let a=c(s,e);if(n.has(a)){if(Re(r,a,e))return;let l=r.childForFieldName("arguments")?.namedChildren[0];(l?.type==="arrow_function"||l?.type==="function_expression")&&o.push(r)}}}}),o}function We(t,e){let n=t.startPosition.row+1,o=e.filePath;return`run@${o.includes("/")?o.split("/").pop()||o:o.includes("\\")&&o.split("\\").pop()||o}:${n}`}function Oe(t,e){let o=t.childForFieldName("arguments")?.namedChildren[0],r=[],s=q(),a={...e,warnings:r,stats:s};if(!o||o.type!=="arrow_function"&&o.type!=="function_expression")return r.push({code:"CALLBACK_NOT_FOUND",message:"Could not find callback for run()",location:u(t,a)}),null;let i=We(t,a),l=X(o,a),d=a.stepParameterName;a.stepParameterName=l;let f=Z(o,a);a.stepParameterName=d;let m={id:p(),type:"workflow",workflowName:i,source:"run",dependencies:[],errorTypes:[],children:k(f),location:a.opts.includeLocations?u(t,a):void 0},y={analyzedAt:Date.now(),filePath:a.filePath,warnings:r,stats:s};return{root:m,metadata:y,references:new Map}}function Le(t,e){let n=t.childForFieldName("function"),o=n?c(n,e):"<unknown>",s=t.childForFieldName("arguments")?.namedChildren[0],a=[],i=q(),l={...e,warnings:a,stats:i};if(!s||s.type!=="arrow_function"&&s.type!=="function_expression")return a.push({code:"CALLBACK_NOT_FOUND",message:`Could not find callback for workflow ${o}`,location:u(t,l)}),null;let d=l.currentWorkflow;l.currentWorkflow=o;let f=X(s,l),m=l.stepParameterName;l.stepParameterName=f;let y=Z(s,l);l.currentWorkflow=d,l.stepParameterName=m;let S=D(t.tree?.rootNode||t,e).find(ae=>ae.name===o),N={id:p(),type:"workflow",workflowName:o,source:"createWorkflow",dependencies:[],errorTypes:[],children:k(y),description:S?.description,markdown:S?.markdown},A={analyzedAt:Date.now(),filePath:l.filePath,warnings:a,stats:i};return{root:N,metadata:A,references:new Map}}function Pe(t,e){let n=t;for(;n;){if(n.type==="variable_declarator"){let o=n.childForFieldName("name");if(o)return c(o,e)}n=n.parent}return null}function X(t,e){let n=t.childForFieldName("parameters");if(!n)return;let o=n.namedChildren[0];if(o){if(o.type==="identifier")return c(o,e);if(o.type==="required_parameter"){let r=o.childForFieldName("pattern");if(r)return r.type==="object_pattern"?Y(r,e):c(r,e)}if(o.type==="object_pattern")return Y(o,e)}}function Y(t,e){for(let n of t.namedChildren){if(n.type==="pair_pattern"){let o=n.childForFieldName("key"),r=n.childForFieldName("value");if(o&&r&&c(o,e)==="step"){if(r.type==="assignment_pattern"){let a=r.childForFieldName("left");if(a)return c(a,e)}return c(r,e)}}if(n.type==="shorthand_property_identifier_pattern"&&c(n,e)==="step")return"step";if(n.type==="assignment_pattern"){let o=n.childForFieldName("left");if(o&&c(o,e)==="step")return"step"}}}function Z(t,e){let n=t.childForFieldName("body");return n?n.type==="statement_block"?E(n.namedChildren,e):h(n,e):[]}function E(t,e){let n=[];for(let o of t){let r=ee(o,e);n.push(...r)}return n}function ee(t,e){switch(t.type){case"expression_statement":{let n=t.namedChildren[0];return n?h(n,e):[]}case"variable_declaration":case"lexical_declaration":return Te(t,e);case"return_statement":{let n=t.childForFieldName("value");return n?h(n,e):[]}case"if_statement":return qe(t,e);case"for_statement":return Ve(t,e);case"for_in_statement":return He(t,e);case"while_statement":return Ge(t,e);default:return[]}}function h(t,e){if(t.type==="await_expression"){let n=t.namedChildren[0];return n?h(n,e):[]}if(t.type==="parenthesized_expression"){let n=t.namedChildren[0];return n?h(n,e):[]}return t.type==="call_expression"?B(t,e):[]}function Te(t,e){let n=[];for(let o of t.namedChildren)if(o.type==="variable_declarator"){let r=o.childForFieldName("value");r&&n.push(...h(r,e))}return n}function B(t,e){let n=t.childForFieldName("function");if(!n)return[];let o=c(n,e),r=e.stepParameterName||"step";return o===r?[ve(t,e)]:o===`${r}.retry`?[De(t,e)]:o===`${r}.withTimeout`?[Ee(t,e)]:o===`${r}.parallel`?Be(t,e):o===`${r}.race`?je(t,e):["when","unless","whenOr","unlessOr"].includes(o)?Je(t,o,e):o==="allAsync"||o==="allSettledAsync"?Ue(t,o==="allAsync"?"all":"allSettled",e):o==="anyAsync"?Ke(t,e):xe(t,o,e)?Me(t,o,e):[]}function xe(t,e,n){if(e===n.currentWorkflow)return!1;let r=t.childForFieldName("arguments")?.namedChildren[0];if(!r)return!1;if(r.type==="arrow_function"||r.type==="function_expression"){if(n.workflowNames.has(e))return!0;let s=r.childForFieldName("parameters");if(s){let a=c(s,n);if(a.includes("step")||a.includes("deps"))return!0}}return!1}function Me(t,e,n){return n.stats.workflowRefCount++,[{id:p(),type:"workflow-ref",workflowName:e,resolved:!1,location:n.opts.includeLocations?u(t,n):void 0}]}function j(t,e){if(t.type==="call_expression"){let n=t.childForFieldName("function");if(n)return c(n,e)}if(t.type==="statement_block"){for(let n of t.namedChildren)if(n.type==="return_statement"){let o=n.namedChildren[0];if(o?.type==="call_expression"){let r=o.childForFieldName("function");if(r)return c(r,e)}else if(o)return c(o,e)}}return c(t,e)}function ve(t,e){e.stats.totalSteps++;let n=t.childForFieldName("arguments"),o=n?.namedChildren[0],r=n?.namedChildren[1],s="<unknown>";if(o)if(o.type==="arrow_function"||o.type==="function_expression"){let l=o.childForFieldName("body");l&&(s=j(l,e))}else s=c(o,e);let a=r?z(r,e):{};return{id:p(),type:"step",callee:s,key:a.key,name:a.name,retry:a.retry,timeout:a.timeout,location:e.opts.includeLocations?u(t,e):void 0}}function De(t,e){e.stats.totalSteps++;let o=t.childForFieldName("arguments")?.namedChildren||[],r=o[0],s="<unknown>";if(r)if(r.type==="arrow_function"||r.type==="function_expression"){let d=r.childForFieldName("body");d&&(s=j(d,e))}else s=c(r,e);let a=o[1],i=a?z(a,e):{},l=a?te(a,e):void 0;return{id:p(),type:"step",callee:s,key:i.key,name:i.name,retry:l,timeout:i.timeout,location:e.opts.includeLocations?u(t,e):void 0}}function Ee(t,e){e.stats.totalSteps++;let o=t.childForFieldName("arguments")?.namedChildren||[],r=o[0],s="<unknown>";if(r)if(r.type==="arrow_function"||r.type==="function_expression"){let d=r.childForFieldName("body");d&&(s=j(d,e))}else s=c(r,e);let a=o[1],i=a?z(a,e):{},l=a?ne(a,e):void 0;return{id:p(),type:"step",callee:s,key:i.key,name:i.name,retry:i.retry,timeout:l,location:e.opts.includeLocations?u(t,e):void 0}}function z(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s){let a=c(r,e);if(a==="key"){let i=C(s,e);i&&(n.key=i)}else if(a==="name"){let i=C(s,e);i&&(n.name=i)}else a==="retry"?n.retry=te(s,e):a==="timeout"&&(n.timeout=ne(s,e))}}return n}function te(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s){let a=c(r,e);if(a==="attempts"){let i=v(s,e);n.attempts=i}else if(a==="backoff"){let i=C(s,e);i==="fixed"||i==="linear"||i==="exponential"?n.backoff=i:n.backoff="<dynamic>"}else if(a==="baseDelay"){let i=v(s,e);n.baseDelay=i}else a==="retryOn"&&(n.retryOn=c(s,e))}}return n}function ne(t,e){let n={};if(t.type!=="object")return n;for(let o of t.namedChildren)if(o.type==="pair"){let r=o.childForFieldName("key"),s=o.childForFieldName("value");if(r&&s&&c(r,e)==="ms"){let i=v(s,e);n.ms=i}}return n}function v(t,e){let n=c(t,e);if(t.type==="number"){let o=parseFloat(n);return isNaN(o)?"<dynamic>":o}return"<dynamic>"}function Be(t,e){let n=t.childForFieldName("arguments"),o=n?.namedChildren[0];if(!o)return[];if(o.type==="string"||o.type==="identifier"||o.type==="member_expression"){let i=o.type==="string"?C(o,e):c(o,e),l=n?.namedChildren[1];if(l&&(l.type==="arrow_function"||l.type==="function_expression")){let d=W(l,e);if(d.length>0){for(let f of d)f.type==="parallel"&&i&&(f.name=i);return d}}return[]}if(o.type!=="object")return[];e.stats.parallelCount++;let r=[];for(let i of o.namedChildren)if(i.type==="pair"){let l=i.childForFieldName("key"),d=i.childForFieldName("value");if(l&&d){let f=oe(l,d,e);f&&r.push(f)}}let s=n?.namedChildren[1],a=s?z(s,e):{};return[{id:p(),type:"parallel",mode:"all",name:a.name,children:r,callee:"step.parallel",location:e.opts.includeLocations?u(t,e):void 0}]}function oe(t,e,n){n.stats.totalSteps++;let o=c(t,n),r="<unknown>";if(e.type==="arrow_function"||e.type==="function_expression"){let s=e.childForFieldName("body");if(s?.type==="call_expression"){let a=s.childForFieldName("function");a&&(r=c(a,n))}}return{id:p(),type:"step",callee:r,name:o,location:n.opts.includeLocations?u(e,n):void 0}}function je(t,e){e.stats.raceCount++;let o=t.childForFieldName("arguments")?.namedChildren[0];if(!o||o.type!=="object")return[];let r=[];for(let s of o.namedChildren)if(s.type==="pair"){let a=s.childForFieldName("key"),i=s.childForFieldName("value");if(a&&i){let l=oe(a,i,e);l&&r.push(l)}}return[{id:p(),type:"race",children:r,callee:"step.race",location:e.opts.includeLocations?u(t,e):void 0}]}function qe(t,e){e.stats.conditionalCount++;let n=t.childForFieldName("condition"),o=t.childForFieldName("consequence"),r=t.childForFieldName("alternative"),s=n?c(n,e).replace(/^\(|\)$/g,""):"<unknown>",a=o?w(o,e):[],i;if(r)if(r.type==="else_clause"){let l=r.namedChildren[0];l&&(i=w(l,e))}else i=w(r,e);return[{id:p(),type:"conditional",condition:s,helper:null,consequent:a,alternate:i?.length?i:void 0,location:e.opts.includeLocations?u(t,e):void 0}]}function w(t,e){return t.type==="statement_block"?E(t.namedChildren,e):ee(t,e)}function Je(t,e,n){n.stats.conditionalCount++;let r=t.childForFieldName("arguments")?.namedChildren||[],s=r[0],a=s?c(s,n):"<unknown>",i=r[1],l=i?W(i,n):[],d;return(e==="whenOr"||e==="unlessOr")&&r[2]&&(d=c(r[2],n)),[{id:p(),type:"conditional",condition:a,helper:e,consequent:l,defaultValue:d,location:n.opts.includeLocations?u(t,n):void 0}]}function W(t,e){if(t.type==="arrow_function"||t.type==="function_expression"){let n=t.childForFieldName("body");if(n)return n.type==="statement_block"?E(n.namedChildren,e):h(n,e)}return h(t,e)}function Ue(t,e,n){n.stats.parallelCount++;let r=t.childForFieldName("arguments")?.namedChildren[0];if(!r||r.type!=="array")return[];let s=[];for(let a of r.namedChildren)if(a.type==="call_expression"){let i=B(a,n);if(i.length>0)s.push(...k(i));else{let l=re(a,n);l&&s.push(l)}}else{let i=W(a,n);s.push(...k(i))}return[{id:p(),type:"parallel",mode:e,children:s,callee:e==="all"?"allAsync":"allSettledAsync",location:n.opts.includeLocations?u(t,n):void 0}]}function Ke(t,e){e.stats.raceCount++;let o=t.childForFieldName("arguments")?.namedChildren[0];if(!o||o.type!=="array")return[];let r=[];for(let a of o.namedChildren)if(a.type==="call_expression"){let i=B(a,e);if(i.length>0)r.push(...k(i));else{let l=re(a,e);l&&r.push(l)}}else{let i=W(a,e);r.push(...k(i))}return[{id:p(),type:"race",children:r,callee:"anyAsync",location:e.opts.includeLocations?u(t,e):void 0}]}function re(t,e){e.stats.totalSteps++;let n=t.childForFieldName("function"),o=n?c(n,e):"<unknown>",r=o.includes(".")?o.split(".").pop():o;return{id:p(),type:"step",name:r,callee:o,location:e.opts.includeLocations?u(t,e):void 0}}function Ve(t,e){let n=t.childForFieldName("body");if(!n)return[];let o=w(n,e);return o.length===0?[]:(e.stats.loopCount++,[{id:p(),type:"loop",loopType:"for",body:o,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}])}function He(t,e){let n=t.childForFieldName("body");if(!n)return[];let o=w(n,e);if(o.length===0)return[];e.stats.loopCount++;let s=c(t,e).includes(" of "),a=t.childForFieldName("right"),i=a?c(a,e):void 0;return[{id:p(),type:"loop",loopType:s?"for-of":"for-in",iterSource:i,body:o,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}]}function Ge(t,e){let n=t.childForFieldName("body");if(!n)return[];let o=w(n,e);return o.length===0?[]:(e.stats.loopCount++,[{id:p(),type:"loop",loopType:"while",body:o,boundKnown:!1,location:e.opts.includeLocations?u(t,e):void 0}])}function c(t,e){return e.sourceCode.slice(t.startIndex,t.endIndex)}function C(t,e){let n=c(t,e);return t.type==="string"?n.slice(1,-1):t.type==="template_string"?"<dynamic>":n}function u(t,e){return{filePath:e.filePath,line:t.startPosition.row+1,column:t.startPosition.column,endLine:t.endPosition.row+1,endColumn:t.endPosition.column}}function F(t,e){e(t);for(let n of t.namedChildren)F(n,e)}function k(t){return t.length<=1?t:[{id:p(),type:"sequence",children:t}]}function q(){return{totalSteps:0,conditionalCount:0,parallelCount:0,raceCount:0,loopCount:0,workflowRefCount:0,unknownCount:0}}0&&(module.exports={analyzeWorkflowSource,clearTreeSitterBrowserCache,getWasmBasePath,renderMultipleStaticJSON,renderPathsMermaid,renderStaticJSON,renderStaticMermaid,resetIdCounter,setWasmBasePath});
8
9
  //# sourceMappingURL=browser.cjs.map