@isaacwasserman/remora 0.1.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 (73) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +99 -0
  3. package/dist/compiler/index.d.ts +8 -0
  4. package/dist/compiler/index.d.ts.map +1 -0
  5. package/dist/compiler/passes/apply-best-practices.d.ts +19 -0
  6. package/dist/compiler/passes/apply-best-practices.d.ts.map +1 -0
  7. package/dist/compiler/passes/build-graph.d.ts +7 -0
  8. package/dist/compiler/passes/build-graph.d.ts.map +1 -0
  9. package/dist/compiler/passes/generate-constrained-tool-schemas.d.ts +4 -0
  10. package/dist/compiler/passes/generate-constrained-tool-schemas.d.ts.map +1 -0
  11. package/dist/compiler/passes/validate-control-flow.d.ts +4 -0
  12. package/dist/compiler/passes/validate-control-flow.d.ts.map +1 -0
  13. package/dist/compiler/passes/validate-foreach-target.d.ts +6 -0
  14. package/dist/compiler/passes/validate-foreach-target.d.ts.map +1 -0
  15. package/dist/compiler/passes/validate-jmespath.d.ts +4 -0
  16. package/dist/compiler/passes/validate-jmespath.d.ts.map +1 -0
  17. package/dist/compiler/passes/validate-references.d.ts +4 -0
  18. package/dist/compiler/passes/validate-references.d.ts.map +1 -0
  19. package/dist/compiler/passes/validate-tools.d.ts +4 -0
  20. package/dist/compiler/passes/validate-tools.d.ts.map +1 -0
  21. package/dist/compiler/types.d.ts +49 -0
  22. package/dist/compiler/types.d.ts.map +1 -0
  23. package/dist/compiler/utils/graph.d.ts +35 -0
  24. package/dist/compiler/utils/graph.d.ts.map +1 -0
  25. package/dist/compiler/utils/jmespath-helpers.d.ts +34 -0
  26. package/dist/compiler/utils/jmespath-helpers.d.ts.map +1 -0
  27. package/dist/executor/errors.d.ts +32 -0
  28. package/dist/executor/errors.d.ts.map +1 -0
  29. package/dist/executor/index.d.ts +20 -0
  30. package/dist/executor/index.d.ts.map +1 -0
  31. package/dist/generator/index.d.ts +24 -0
  32. package/dist/generator/index.d.ts.map +1 -0
  33. package/dist/generator/prompt.d.ts +6 -0
  34. package/dist/generator/prompt.d.ts.map +1 -0
  35. package/dist/lib.d.ts +11 -0
  36. package/dist/lib.d.ts.map +1 -0
  37. package/dist/lib.js +1973 -0
  38. package/dist/lib.js.map +25 -0
  39. package/dist/types.d.ts +234 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/viewer/edges/workflow-edge.d.ts +3 -0
  42. package/dist/viewer/edges/workflow-edge.d.ts.map +1 -0
  43. package/dist/viewer/graph-layout.d.ts +13 -0
  44. package/dist/viewer/graph-layout.d.ts.map +1 -0
  45. package/dist/viewer/index.d.ts +5 -0
  46. package/dist/viewer/index.d.ts.map +1 -0
  47. package/dist/viewer/index.js +1554 -0
  48. package/dist/viewer/index.js.map +23 -0
  49. package/dist/viewer/nodes/base-node.d.ts +17 -0
  50. package/dist/viewer/nodes/base-node.d.ts.map +1 -0
  51. package/dist/viewer/nodes/end-node.d.ts +3 -0
  52. package/dist/viewer/nodes/end-node.d.ts.map +1 -0
  53. package/dist/viewer/nodes/extract-data-node.d.ts +3 -0
  54. package/dist/viewer/nodes/extract-data-node.d.ts.map +1 -0
  55. package/dist/viewer/nodes/for-each-node.d.ts +3 -0
  56. package/dist/viewer/nodes/for-each-node.d.ts.map +1 -0
  57. package/dist/viewer/nodes/group-header-node.d.ts +3 -0
  58. package/dist/viewer/nodes/group-header-node.d.ts.map +1 -0
  59. package/dist/viewer/nodes/llm-prompt-node.d.ts +3 -0
  60. package/dist/viewer/nodes/llm-prompt-node.d.ts.map +1 -0
  61. package/dist/viewer/nodes/start-node.d.ts +3 -0
  62. package/dist/viewer/nodes/start-node.d.ts.map +1 -0
  63. package/dist/viewer/nodes/start-step-node.d.ts +3 -0
  64. package/dist/viewer/nodes/start-step-node.d.ts.map +1 -0
  65. package/dist/viewer/nodes/switch-case-node.d.ts +3 -0
  66. package/dist/viewer/nodes/switch-case-node.d.ts.map +1 -0
  67. package/dist/viewer/nodes/tool-call-node.d.ts +3 -0
  68. package/dist/viewer/nodes/tool-call-node.d.ts.map +1 -0
  69. package/dist/viewer/panels/step-detail-panel.d.ts +10 -0
  70. package/dist/viewer/panels/step-detail-panel.d.ts.map +1 -0
  71. package/dist/viewer/workflow-viewer.d.ts +9 -0
  72. package/dist/viewer/workflow-viewer.d.ts.map +1 -0
  73. package/package.json +78 -0
@@ -0,0 +1,25 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/compiler/index.ts", "../src/compiler/passes/apply-best-practices.ts", "../src/compiler/utils/graph.ts", "../src/compiler/passes/build-graph.ts", "../src/compiler/passes/generate-constrained-tool-schemas.ts", "../src/compiler/passes/validate-control-flow.ts", "../src/compiler/passes/validate-foreach-target.ts", "../src/compiler/utils/jmespath-helpers.ts", "../src/compiler/passes/validate-jmespath.ts", "../src/compiler/passes/validate-references.ts", "../src/compiler/passes/validate-tools.ts", "../src/executor/index.ts", "../src/executor/errors.ts", "../src/generator/index.ts", "../src/types.ts", "../src/generator/prompt.ts"],
4
+ "sourcesContent": [
5
+ "import type { ToolSet } from \"ai\";\nimport { asSchema } from \"ai\";\nimport type { WorkflowDefinition } from \"../types\";\nimport { applyBestPractices } from \"./passes/apply-best-practices\";\nimport { buildGraph } from \"./passes/build-graph\";\nimport { generateConstrainedToolSchemas } from \"./passes/generate-constrained-tool-schemas\";\nimport { validateControlFlow } from \"./passes/validate-control-flow\";\nimport { validateForeachTarget } from \"./passes/validate-foreach-target\";\nimport { validateJmespath } from \"./passes/validate-jmespath\";\nimport { validateReferences } from \"./passes/validate-references\";\nimport { validateTools } from \"./passes/validate-tools\";\nimport type {\n\tCompilerResult,\n\tConstrainedToolSchemaMap,\n\tDiagnostic,\n\tToolDefinitionMap,\n} from \"./types\";\n\nexport async function compileWorkflow(\n\tworkflow: WorkflowDefinition,\n\toptions?: {\n\t\ttools?: ToolSet;\n\t},\n): Promise<CompilerResult> {\n\tconst diagnostics: Diagnostic[] = [];\n\n\t// Pass 1: Build execution graph\n\tconst graphResult = buildGraph(workflow);\n\tdiagnostics.push(...graphResult.diagnostics);\n\n\t// Pass 2: Validate step references\n\tconst refDiagnostics = validateReferences(workflow);\n\t// Deduplicate MISSING_INITIAL_STEP (emitted by both build-graph and validate-references)\n\tfor (const d of refDiagnostics) {\n\t\tif (\n\t\t\td.code === \"MISSING_INITIAL_STEP\" &&\n\t\t\tdiagnostics.some((e) => e.code === \"MISSING_INITIAL_STEP\")\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tdiagnostics.push(d);\n\t}\n\n\t// Pass 3+: Only proceed with graph-dependent passes if we have a valid graph\n\tif (graphResult.graph) {\n\t\tdiagnostics.push(...validateControlFlow(workflow, graphResult.graph));\n\n\t\tdiagnostics.push(...validateJmespath(workflow, graphResult.graph));\n\t}\n\n\t// Pass 5: Tool validation + constrained schema generation (doesn't require graph)\n\tlet constrainedToolSchemas: ConstrainedToolSchemaMap | null = null;\n\tif (options?.tools) {\n\t\tconst toolSchemas = await extractToolSchemas(options.tools);\n\t\tdiagnostics.push(...validateTools(workflow, toolSchemas));\n\t\tconstrainedToolSchemas = generateConstrainedToolSchemas(\n\t\t\tworkflow,\n\t\t\ttoolSchemas,\n\t\t);\n\n\t\t// Pass 6: Validate for-each targets resolve to array types\n\t\tif (graphResult.graph) {\n\t\t\tdiagnostics.push(\n\t\t\t\t...validateForeachTarget(workflow, graphResult.graph, toolSchemas),\n\t\t\t);\n\t\t}\n\t}\n\n\t// Final pass: apply best-practice transformations (non-destructive)\n\tconst hasErrors = diagnostics.some((d) => d.severity === \"error\");\n\tlet optimizedWorkflow: WorkflowDefinition | null = null;\n\tif (graphResult.graph && !hasErrors) {\n\t\tconst bpResult = applyBestPractices(workflow, graphResult.graph);\n\t\toptimizedWorkflow = bpResult.workflow;\n\t\tdiagnostics.push(...bpResult.diagnostics);\n\t}\n\n\treturn {\n\t\tdiagnostics,\n\t\tgraph: graphResult.graph,\n\t\tworkflow: optimizedWorkflow,\n\t\tconstrainedToolSchemas,\n\t};\n}\n\nasync function extractToolSchemas(tools: ToolSet): Promise<ToolDefinitionMap> {\n\tconst schemas: ToolDefinitionMap = {};\n\tfor (const [name, toolDef] of Object.entries(tools)) {\n\t\tconst jsonSchema = await asSchema(toolDef.inputSchema).jsonSchema;\n\t\tschemas[name] = {\n\t\t\tinputSchema: jsonSchema as ToolDefinitionMap[string][\"inputSchema\"],\n\t\t};\n\t\tif (toolDef.outputSchema) {\n\t\t\tschemas[name].outputSchema = (await asSchema(toolDef.outputSchema)\n\t\t\t\t.jsonSchema) as Record<string, unknown>;\n\t\t}\n\t}\n\treturn schemas;\n}\n\nexport type {\n\tCompilerResult,\n\tConstrainedToolSchema,\n\tConstrainedToolSchemaMap,\n\tDiagnostic,\n\tDiagnosticCode,\n\tDiagnosticLocation,\n\tDiagnosticSeverity,\n\tExecutionGraph,\n} from \"./types\";\n",
6
+ "import type { WorkflowDefinition, WorkflowStep } from \"../../types\";\nimport type { Diagnostic, ExecutionGraph } from \"../types\";\n\ninterface BestPracticeRuleResult {\n\tworkflow: WorkflowDefinition;\n\tdiagnostics: Diagnostic[];\n}\n\n/**\n * A best-practice rule that can non-destructively modify a workflow.\n * Each rule receives a deep-cloned workflow and the execution graph,\n * and returns the (possibly modified) workflow along with any diagnostics.\n */\nexport type BestPracticeRule = (\n\tworkflow: WorkflowDefinition,\n\tgraph: ExecutionGraph,\n) => BestPracticeRuleResult;\n\n/**\n * Registry of best-practice rules applied in order.\n * Add new rules here to have them run automatically.\n */\nconst rules: BestPracticeRule[] = [addMissingStartStep, addMissingEndSteps];\n\n/**\n * Applies all registered best-practice rules to a deep copy of the workflow.\n * The original workflow is never mutated.\n */\nexport function applyBestPractices(\n\tworkflow: WorkflowDefinition,\n\tgraph: ExecutionGraph,\n): BestPracticeRuleResult {\n\tlet result = structuredClone(workflow);\n\tconst allDiagnostics: Diagnostic[] = [];\n\n\tfor (const rule of rules) {\n\t\tconst ruleResult = rule(result, graph);\n\t\tresult = ruleResult.workflow;\n\t\tallDiagnostics.push(...ruleResult.diagnostics);\n\t}\n\n\treturn { workflow: result, diagnostics: allDiagnostics };\n}\n\n/**\n * Ensures the workflow has a start step. If none exists, one is\n * auto-inserted with an empty input schema.\n */\nfunction addMissingStartStep(\n\tworkflow: WorkflowDefinition,\n\t_graph: ExecutionGraph,\n): BestPracticeRuleResult {\n\tconst diagnostics: Diagnostic[] = [];\n\n\tconst hasStartStep = workflow.steps.some((s) => s.type === \"start\");\n\tif (hasStartStep) {\n\t\treturn { workflow, diagnostics };\n\t}\n\n\tconst startStepId = \"__start\";\n\tconst oldInitialStepId = workflow.initialStepId;\n\n\tconst startStep: WorkflowStep = {\n\t\tid: startStepId,\n\t\tname: \"Start\",\n\t\tdescription: \"Auto-generated start step\",\n\t\ttype: \"start\",\n\t\tparams: {\n\t\t\tinputSchema: {},\n\t\t},\n\t\tnextStepId: oldInitialStepId,\n\t};\n\n\tworkflow.steps.unshift(startStep);\n\tworkflow.initialStepId = startStepId;\n\n\tdiagnostics.push({\n\t\tseverity: \"warning\",\n\t\tlocation: { stepId: null, field: \"initialStepId\" },\n\t\tmessage:\n\t\t\t\"Workflow has no start step; one was automatically added with an empty input schema\",\n\t\tcode: \"MISSING_START_STEP\",\n\t});\n\n\treturn { workflow, diagnostics };\n}\n\n/**\n * Ensures every terminal step (a step with no nextStepId that isn't\n * already an \"end\" step) gets an explicit \"end\" step appended.\n */\nfunction addMissingEndSteps(\n\tworkflow: WorkflowDefinition,\n\t_graph: ExecutionGraph,\n): BestPracticeRuleResult {\n\tconst newEndSteps: WorkflowStep[] = [];\n\n\tfor (const step of workflow.steps) {\n\t\tif (step.type === \"end\") continue;\n\t\tif (step.nextStepId) continue;\n\n\t\tconst endStepId = `${step.id}_end`;\n\t\tstep.nextStepId = endStepId;\n\t\tnewEndSteps.push({\n\t\t\tid: endStepId,\n\t\t\tname: \"End\",\n\t\t\tdescription: `End of chain after ${step.id}`,\n\t\t\ttype: \"end\",\n\t\t});\n\t}\n\n\tworkflow.steps.push(...newEndSteps);\n\treturn { workflow, diagnostics: [] };\n}\n",
7
+ "import type { WorkflowStep } from \"../../types\";\n\nexport function buildStepIndex(steps: WorkflowStep[]): {\n\tindex: Map<string, WorkflowStep>;\n\tduplicates: string[];\n} {\n\tconst index = new Map<string, WorkflowStep>();\n\tconst duplicates: string[] = [];\n\n\tfor (const step of steps) {\n\t\tif (index.has(step.id)) {\n\t\t\tduplicates.push(step.id);\n\t\t} else {\n\t\t\tindex.set(step.id, step);\n\t\t}\n\t}\n\n\treturn { index, duplicates };\n}\n\nexport function computeSuccessors(\n\tstepIndex: Map<string, WorkflowStep>,\n): Map<string, Set<string>> {\n\tconst successors = new Map<string, Set<string>>();\n\n\tfor (const [id, step] of stepIndex) {\n\t\tconst succs = new Set<string>();\n\n\t\tif (step.nextStepId) {\n\t\t\tsuccs.add(step.nextStepId);\n\t\t}\n\n\t\tif (step.type === \"switch-case\") {\n\t\t\tfor (const c of step.params.cases) {\n\t\t\t\tsuccs.add(c.branchBodyStepId);\n\t\t\t}\n\t\t}\n\n\t\tif (step.type === \"for-each\") {\n\t\t\tsuccs.add(step.params.loopBodyStepId);\n\t\t}\n\n\t\tsuccessors.set(id, succs);\n\t}\n\n\treturn successors;\n}\n\nexport function computeReachability(\n\tinitialStepId: string,\n\tsuccessors: Map<string, Set<string>>,\n): Set<string> {\n\tconst reachable = new Set<string>();\n\tconst queue = [initialStepId];\n\n\twhile (queue.length > 0) {\n\t\tconst current = queue.shift();\n\t\tif (current === undefined) break;\n\t\tif (reachable.has(current)) continue;\n\t\treachable.add(current);\n\n\t\tconst succs = successors.get(current);\n\t\tif (succs) {\n\t\t\tfor (const s of succs) {\n\t\t\t\tif (!reachable.has(s)) {\n\t\t\t\t\tqueue.push(s);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn reachable;\n}\n\n/**\n * Detect cycles using DFS with white/gray/black coloring.\n * Returns arrays of step IDs forming each detected cycle.\n */\nexport function detectCycles(\n\tstepIndex: Map<string, WorkflowStep>,\n\tsuccessors: Map<string, Set<string>>,\n): string[][] {\n\tconst WHITE = 0;\n\tconst GRAY = 1;\n\tconst BLACK = 2;\n\n\tconst color = new Map<string, number>();\n\tfor (const id of stepIndex.keys()) {\n\t\tcolor.set(id, WHITE);\n\t}\n\n\tconst cycles: string[][] = [];\n\tconst path: string[] = [];\n\n\tfunction dfs(node: string) {\n\t\tif (!stepIndex.has(node)) return;\n\n\t\tcolor.set(node, GRAY);\n\t\tpath.push(node);\n\n\t\tconst succs = successors.get(node);\n\t\tif (succs) {\n\t\t\tfor (const next of succs) {\n\t\t\t\tif (!stepIndex.has(next)) continue;\n\n\t\t\t\tconst c = color.get(next);\n\t\t\t\tif (c === undefined) continue;\n\t\t\t\tif (c === GRAY) {\n\t\t\t\t\t// Found a cycle — extract the cycle from the path\n\t\t\t\t\tconst cycleStart = path.indexOf(next);\n\t\t\t\t\tcycles.push(path.slice(cycleStart));\n\t\t\t\t} else if (c === WHITE) {\n\t\t\t\t\tdfs(next);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpath.pop();\n\t\tcolor.set(node, BLACK);\n\t}\n\n\tfor (const id of stepIndex.keys()) {\n\t\tif (color.get(id) === WHITE) {\n\t\t\tdfs(id);\n\t\t}\n\t}\n\n\treturn cycles;\n}\n\n/**\n * Compute the set of predecessor step IDs for each step.\n * A predecessor of step X is any step that must have executed before X\n * in the execution order.\n *\n * This uses topological order: for each step, its predecessors are the\n * union of all steps that can reach it via successor edges.\n */\nexport function computePredecessors(\n\ttopologicalOrder: string[],\n\tsuccessors: Map<string, Set<string>>,\n): Map<string, Set<string>> {\n\tconst predecessors = new Map<string, Set<string>>();\n\n\tfor (const id of topologicalOrder) {\n\t\tpredecessors.set(id, new Set());\n\t}\n\n\tfor (const id of topologicalOrder) {\n\t\tconst succs = successors.get(id);\n\t\tif (!succs) continue;\n\n\t\tfor (const succ of succs) {\n\t\t\tconst predSet = predecessors.get(succ);\n\t\t\tif (!predSet) continue;\n\n\t\t\t// succ's predecessors include id and all of id's predecessors\n\t\t\tpredSet.add(id);\n\t\t\tconst idPreds = predecessors.get(id);\n\t\t\tif (idPreds) {\n\t\t\t\tfor (const p of idPreds) {\n\t\t\t\t\tpredSet.add(p);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn predecessors;\n}\n\n/**\n * Compute topological order using Kahn's algorithm.\n * Returns null if cycles exist.\n */\nexport function topologicalSort(\n\tstepIds: string[],\n\tsuccessors: Map<string, Set<string>>,\n): string[] | null {\n\tconst inDegree = new Map<string, number>();\n\tconst stepIdSet = new Set(stepIds);\n\n\tfor (const id of stepIds) {\n\t\tinDegree.set(id, 0);\n\t}\n\n\tfor (const id of stepIds) {\n\t\tconst succs = successors.get(id);\n\t\tif (!succs) continue;\n\t\tfor (const s of succs) {\n\t\t\tif (stepIdSet.has(s)) {\n\t\t\t\tinDegree.set(s, (inDegree.get(s) ?? 0) + 1);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst queue: string[] = [];\n\tfor (const [id, deg] of inDegree) {\n\t\tif (deg === 0) queue.push(id);\n\t}\n\n\tconst order: string[] = [];\n\twhile (queue.length > 0) {\n\t\tconst node = queue.shift();\n\t\tif (node === undefined) break;\n\t\torder.push(node);\n\n\t\tconst succs = successors.get(node);\n\t\tif (!succs) continue;\n\t\tfor (const s of succs) {\n\t\t\tif (!stepIdSet.has(s)) continue;\n\t\t\tconst currentDeg = inDegree.get(s);\n\t\t\tif (currentDeg === undefined) continue;\n\t\t\tconst newDeg = currentDeg - 1;\n\t\t\tinDegree.set(s, newDeg);\n\t\t\tif (newDeg === 0) {\n\t\t\t\tqueue.push(s);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn order.length === stepIds.length ? order : null;\n}\n\n/**\n * Walk the execution graph to determine which loop variables (itemName)\n * are in scope at each step, and which steps belong to a body (loop or branch).\n */\nexport function computeLoopScopesAndOwnership(\n\tinitialStepId: string,\n\tstepIndex: Map<string, WorkflowStep>,\n): {\n\tloopVariablesInScope: Map<string, Set<string>>;\n\tbodyOwnership: Map<string, string>;\n} {\n\tconst loopVariablesInScope = new Map<string, Set<string>>();\n\tconst bodyOwnership = new Map<string, string>();\n\n\tfunction walkChain(\n\t\tstartId: string,\n\t\tloopVars: Set<string>,\n\t\townerStepId: string | null,\n\t) {\n\t\t// First pass: claim all steps on this chain (following nextStepId only)\n\t\t// This ensures the main chain is claimed before body sub-chains,\n\t\t// so body chains can't accidentally claim main-chain steps.\n\t\tlet currentId: string | undefined = startId;\n\t\tconst chainSteps: import(\"../../types\").WorkflowStep[] = [];\n\n\t\twhile (currentId) {\n\t\t\tif (loopVariablesInScope.has(currentId)) break;\n\n\t\t\tconst step = stepIndex.get(currentId);\n\t\t\tif (!step) break;\n\n\t\t\tloopVariablesInScope.set(currentId, new Set(loopVars));\n\t\t\tif (ownerStepId !== null) {\n\t\t\t\tbodyOwnership.set(currentId, ownerStepId);\n\t\t\t}\n\n\t\t\tchainSteps.push(step);\n\t\t\tcurrentId = step.nextStepId;\n\t\t}\n\n\t\t// Second pass: recurse into control flow sub-chains (bodies)\n\t\tfor (const step of chainSteps) {\n\t\t\tif (step.type === \"for-each\") {\n\t\t\t\tconst innerVars = new Set(loopVars);\n\t\t\t\tinnerVars.add(step.params.itemName);\n\t\t\t\twalkChain(step.params.loopBodyStepId, innerVars, step.id);\n\t\t\t}\n\n\t\t\tif (step.type === \"switch-case\") {\n\t\t\t\tfor (const c of step.params.cases) {\n\t\t\t\t\twalkChain(c.branchBodyStepId, loopVars, step.id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\twalkChain(initialStepId, new Set(), null);\n\n\treturn { loopVariablesInScope, bodyOwnership };\n}\n",
8
+ "import type { WorkflowDefinition } from \"../../types\";\nimport type { Diagnostic, ExecutionGraph } from \"../types\";\nimport {\n\tbuildStepIndex,\n\tcomputeLoopScopesAndOwnership,\n\tcomputePredecessors,\n\tcomputeReachability,\n\tcomputeSuccessors,\n\tdetectCycles,\n\ttopologicalSort,\n} from \"../utils/graph\";\n\nexport function buildGraph(workflow: WorkflowDefinition): {\n\tgraph: ExecutionGraph | null;\n\tdiagnostics: Diagnostic[];\n} {\n\tconst diagnostics: Diagnostic[] = [];\n\n\t// Validate step ID format\n\tconst VALID_STEP_ID = /^[a-zA-Z_][a-zA-Z0-9_]*$/;\n\tfor (const step of workflow.steps) {\n\t\tif (!VALID_STEP_ID.test(step.id)) {\n\t\t\tdiagnostics.push({\n\t\t\t\tseverity: \"error\",\n\t\t\t\tlocation: { stepId: step.id, field: \"id\" },\n\t\t\t\tmessage: `Step ID '${step.id}' is invalid — must match [a-zA-Z_][a-zA-Z0-9_]* (use underscores, not hyphens)`,\n\t\t\t\tcode: \"INVALID_STEP_ID\",\n\t\t\t});\n\t\t}\n\t}\n\n\t// Validate itemName format and shadowing\n\tconst stepIdSet = new Set(workflow.steps.map((s) => s.id));\n\tfor (const step of workflow.steps) {\n\t\tif (step.type === \"for-each\") {\n\t\t\tconst { itemName } = step.params;\n\t\t\tif (!VALID_STEP_ID.test(itemName)) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tseverity: \"error\",\n\t\t\t\t\tlocation: { stepId: step.id, field: \"params.itemName\" },\n\t\t\t\t\tmessage: `Item name '${itemName}' is invalid — must match [a-zA-Z_][a-zA-Z0-9_]*`,\n\t\t\t\t\tcode: \"INVALID_ITEM_NAME\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (stepIdSet.has(itemName)) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tseverity: \"warning\",\n\t\t\t\t\tlocation: { stepId: step.id, field: \"params.itemName\" },\n\t\t\t\t\tmessage: `Item name '${itemName}' shadows step ID '${itemName}' — references to '${itemName}' inside the loop body will resolve to the loop variable, not the step output`,\n\t\t\t\t\tcode: \"ITEM_NAME_SHADOWS_STEP_ID\",\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t// Build step index, detect duplicates\n\tconst { index: stepIndex, duplicates } = buildStepIndex(workflow.steps);\n\tfor (const dupId of duplicates) {\n\t\tdiagnostics.push({\n\t\t\tseverity: \"error\",\n\t\t\tlocation: { stepId: dupId, field: \"id\" },\n\t\t\tmessage: `Duplicate step ID '${dupId}'`,\n\t\t\tcode: \"DUPLICATE_STEP_ID\",\n\t\t});\n\t}\n\n\t// Check initialStepId exists\n\tif (!stepIndex.has(workflow.initialStepId)) {\n\t\tdiagnostics.push({\n\t\t\tseverity: \"error\",\n\t\t\tlocation: { stepId: null, field: \"initialStepId\" },\n\t\t\tmessage: `Initial step '${workflow.initialStepId}' does not exist`,\n\t\t\tcode: \"MISSING_INITIAL_STEP\",\n\t\t});\n\t\t// Can't build a graph without a valid initial step\n\t\treturn { graph: null, diagnostics };\n\t}\n\n\t// If there are duplicate IDs, the step index is unreliable\n\tif (duplicates.length > 0) {\n\t\treturn { graph: null, diagnostics };\n\t}\n\n\tconst successors = computeSuccessors(stepIndex);\n\n\t// Detect cycles\n\tconst cycles = detectCycles(stepIndex, successors);\n\tfor (const cycle of cycles) {\n\t\tconst firstStep = cycle[0];\n\t\tif (!firstStep) continue;\n\t\tdiagnostics.push({\n\t\t\tseverity: \"error\",\n\t\t\tlocation: { stepId: firstStep, field: \"nextStepId\" },\n\t\t\tmessage: `Cycle detected: ${cycle.join(\" → \")} → ${firstStep}`,\n\t\t\tcode: \"CYCLE_DETECTED\",\n\t\t});\n\t}\n\n\t// Compute reachability\n\tconst reachableSteps = computeReachability(\n\t\tworkflow.initialStepId,\n\t\tsuccessors,\n\t);\n\n\t// Warn about unreachable steps\n\tfor (const [id] of stepIndex) {\n\t\tif (!reachableSteps.has(id)) {\n\t\t\tdiagnostics.push({\n\t\t\t\tseverity: \"warning\",\n\t\t\t\tlocation: { stepId: id, field: \"id\" },\n\t\t\t\tmessage: `Step '${id}' is not reachable from initial step '${workflow.initialStepId}'`,\n\t\t\t\tcode: \"UNREACHABLE_STEP\",\n\t\t\t});\n\t\t}\n\t}\n\n\t// If cycles exist, we can't compute topological order or predecessors\n\tif (cycles.length > 0) {\n\t\treturn { graph: null, diagnostics };\n\t}\n\n\t// Compute topological order\n\tconst reachableIds = [...reachableSteps];\n\tconst topologicalOrder = topologicalSort(reachableIds, successors);\n\tif (!topologicalOrder) {\n\t\t// Shouldn't happen since we already checked for cycles\n\t\treturn { graph: null, diagnostics };\n\t}\n\n\t// Compute predecessors\n\tconst predecessors = computePredecessors(topologicalOrder, successors);\n\n\t// Compute loop variable scopes and body ownership\n\tconst { loopVariablesInScope, bodyOwnership } = computeLoopScopesAndOwnership(\n\t\tworkflow.initialStepId,\n\t\tstepIndex,\n\t);\n\n\treturn {\n\t\tgraph: {\n\t\t\tstepIndex,\n\t\t\tsuccessors,\n\t\t\tpredecessors,\n\t\t\ttopologicalOrder,\n\t\t\treachableSteps,\n\t\t\tloopVariablesInScope,\n\t\t\tbodyOwnership,\n\t\t},\n\t\tdiagnostics,\n\t};\n}\n",
9
+ "import type { WorkflowDefinition } from \"../../types\";\nimport type {\n\tConstrainedToolSchema,\n\tConstrainedToolSchemaMap,\n\tToolDefinitionMap,\n} from \"../types\";\n\n// ─── Internal Types ──────────────────────────────────────────────\n\ninterface CallSiteKeyInfo {\n\ttype: \"literal\";\n\tvalue: unknown;\n}\n\ninterface CallSiteKeyDynamic {\n\ttype: \"jmespath\";\n}\n\ninterface CallSiteInfo {\n\tstepId: string;\n\tkeys: Map<string, CallSiteKeyInfo | CallSiteKeyDynamic>;\n}\n\n// ─── Phase 1: Collect Call Sites ─────────────────────────────────\n\nfunction collectCallSites(\n\tworkflow: WorkflowDefinition,\n): Map<string, CallSiteInfo[]> {\n\tconst callSitesByTool = new Map<string, CallSiteInfo[]>();\n\n\tfor (const step of workflow.steps) {\n\t\tif (step.type !== \"tool-call\") continue;\n\n\t\tconst { toolName, toolInput } = step.params;\n\t\tconst keys = new Map<string, CallSiteKeyInfo | CallSiteKeyDynamic>();\n\n\t\tfor (const [key, expr] of Object.entries(toolInput)) {\n\t\t\tconst expression = expr as { type: string; value?: unknown };\n\t\t\tif (expression.type === \"literal\") {\n\t\t\t\tkeys.set(key, { type: \"literal\", value: expression.value });\n\t\t\t} else {\n\t\t\t\tkeys.set(key, { type: \"jmespath\" });\n\t\t\t}\n\t\t}\n\n\t\tlet sites = callSitesByTool.get(toolName);\n\t\tif (!sites) {\n\t\t\tsites = [];\n\t\t\tcallSitesByTool.set(toolName, sites);\n\t\t}\n\t\tsites.push({ stepId: step.id, keys });\n\t}\n\n\treturn callSitesByTool;\n}\n\n// ─── Phase 2–3: Analyze and Constrain Properties ─────────────────\n\nfunction constrainProperty(\n\tcallSites: CallSiteInfo[],\n\tkey: string,\n\toriginalPropertySchema: unknown,\n): { schema: unknown; allLiteral: boolean; providedInAll: boolean } {\n\tlet providedCount = 0;\n\tlet allLiteral = true;\n\tconst literalValues: unknown[] = [];\n\tconst seen = new Set<string>();\n\n\tfor (const site of callSites) {\n\t\tconst entry = site.keys.get(key);\n\t\tif (!entry) continue;\n\n\t\tprovidedCount++;\n\n\t\tif (entry.type === \"jmespath\") {\n\t\t\tallLiteral = false;\n\t\t} else {\n\t\t\tconst serialized = JSON.stringify(entry.value);\n\t\t\tif (!seen.has(serialized)) {\n\t\t\t\tseen.add(serialized);\n\t\t\t\tliteralValues.push(entry.value);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst providedInAll = providedCount === callSites.length;\n\n\tif (!allLiteral) {\n\t\treturn { schema: originalPropertySchema, allLiteral: false, providedInAll };\n\t}\n\n\tconst original =\n\t\toriginalPropertySchema && typeof originalPropertySchema === \"object\"\n\t\t\t? (originalPropertySchema as Record<string, unknown>)\n\t\t\t: {};\n\n\tif (literalValues.length === 1) {\n\t\treturn {\n\t\t\tschema: { ...original, const: literalValues[0] },\n\t\t\tallLiteral: true,\n\t\t\tprovidedInAll,\n\t\t};\n\t}\n\n\treturn {\n\t\tschema: { ...original, enum: literalValues },\n\t\tallLiteral: true,\n\t\tprovidedInAll,\n\t};\n}\n\n// ─── Phase 4: Assemble Constrained Schemas ───────────────────────\n\nexport function generateConstrainedToolSchemas(\n\tworkflow: WorkflowDefinition,\n\ttools: ToolDefinitionMap,\n): ConstrainedToolSchemaMap {\n\tconst callSitesByTool = collectCallSites(workflow);\n\tconst result: ConstrainedToolSchemaMap = {};\n\n\tfor (const [toolName, callSites] of callSitesByTool) {\n\t\tconst toolDef = tools[toolName];\n\t\tif (!toolDef) continue; // Unknown tool — already reported by validate-tools\n\n\t\tconst originalProperties = toolDef.inputSchema.properties ?? {};\n\n\t\t// Collect all keys used across any call site\n\t\tconst allUsedKeys = new Set<string>();\n\t\tfor (const site of callSites) {\n\t\t\tfor (const key of site.keys.keys()) {\n\t\t\t\tallUsedKeys.add(key);\n\t\t\t}\n\t\t}\n\n\t\tconst constrainedProperties: Record<string, unknown> = {};\n\t\tconst requiredKeys: string[] = [];\n\t\tlet fullyStatic = true;\n\n\t\tfor (const key of allUsedKeys) {\n\t\t\tconst originalProp = originalProperties[key];\n\t\t\tif (originalProp === undefined) continue; // Extra key not in schema — skip\n\n\t\t\tconst { schema, allLiteral, providedInAll } = constrainProperty(\n\t\t\t\tcallSites,\n\t\t\t\tkey,\n\t\t\t\toriginalProp,\n\t\t\t);\n\n\t\t\tconstrainedProperties[key] = schema;\n\n\t\t\tif (providedInAll) {\n\t\t\t\trequiredKeys.push(key);\n\t\t\t}\n\n\t\t\tif (!allLiteral) {\n\t\t\t\tfullyStatic = false;\n\t\t\t}\n\t\t}\n\n\t\tconst constrained: ConstrainedToolSchema = {\n\t\t\tinputSchema: {\n\t\t\t\trequired: requiredKeys.sort(),\n\t\t\t\tproperties: constrainedProperties,\n\t\t\t},\n\t\t\tfullyStatic,\n\t\t\tcallSites: callSites.map((s) => s.stepId).sort(),\n\t\t};\n\n\t\tif (toolDef.outputSchema) {\n\t\t\tconstrained.outputSchema = toolDef.outputSchema;\n\t\t}\n\n\t\tresult[toolName] = constrained;\n\t}\n\n\treturn result;\n}\n",
10
+ "import type { WorkflowDefinition } from \"../../types\";\nimport type { Diagnostic, ExecutionGraph } from \"../types\";\n\nexport function validateControlFlow(\n\tworkflow: WorkflowDefinition,\n\tgraph: ExecutionGraph,\n): Diagnostic[] {\n\tconst diagnostics: Diagnostic[] = [];\n\n\tfor (const step of workflow.steps) {\n\t\t// End steps should not have nextStepId\n\t\tif (step.type === \"end\" && step.nextStepId) {\n\t\t\tdiagnostics.push({\n\t\t\t\tseverity: \"error\",\n\t\t\t\tlocation: { stepId: step.id, field: \"nextStepId\" },\n\t\t\t\tmessage: `End step '${step.id}' should not have a nextStepId`,\n\t\t\t\tcode: \"END_STEP_HAS_NEXT\",\n\t\t\t});\n\t\t}\n\n\t\t// Switch-case: at most one default case\n\t\tif (step.type === \"switch-case\") {\n\t\t\tconst defaultCount = step.params.cases.filter(\n\t\t\t\t(c) => c.value.type === \"default\",\n\t\t\t).length;\n\t\t\tif (defaultCount > 1) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tseverity: \"error\",\n\t\t\t\t\tlocation: { stepId: step.id, field: \"params.cases\" },\n\t\t\t\t\tmessage: `Switch-case step '${step.id}' has ${defaultCount} default cases (expected at most 1)`,\n\t\t\t\t\tcode: \"MULTIPLE_DEFAULT_CASES\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Validate branch bodies don't escape\n\t\t\tfor (const [i, c] of step.params.cases.entries()) {\n\t\t\t\tconst escapes = checkBodyEscapes(c.branchBodyStepId, step.id, graph);\n\t\t\t\tif (escapes) {\n\t\t\t\t\tdiagnostics.push({\n\t\t\t\t\t\tseverity: \"warning\",\n\t\t\t\t\t\tlocation: {\n\t\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\t\tfield: `params.cases[${i}].branchBodyStepId`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tmessage: `Branch body starting at '${c.branchBodyStepId}' in step '${step.id}' has a step ('${escapes.escapingStep}') whose nextStepId points outside the branch body to '${escapes.target}'`,\n\t\t\t\t\t\tcode: \"BRANCH_BODY_ESCAPES\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// For-each: validate loop body doesn't escape\n\t\tif (step.type === \"for-each\") {\n\t\t\tconst escapes = checkBodyEscapes(\n\t\t\t\tstep.params.loopBodyStepId,\n\t\t\t\tstep.id,\n\t\t\t\tgraph,\n\t\t\t);\n\t\t\tif (escapes) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tseverity: \"warning\",\n\t\t\t\t\tlocation: {\n\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\tfield: \"params.loopBodyStepId\",\n\t\t\t\t\t},\n\t\t\t\t\tmessage: `Loop body starting at '${step.params.loopBodyStepId}' in step '${step.id}' has a step ('${escapes.escapingStep}') whose nextStepId points outside the loop body to '${escapes.target}'`,\n\t\t\t\t\tcode: \"LOOP_BODY_ESCAPES\",\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t// Output consistency checks\n\tif (workflow.outputSchema) {\n\t\tfor (const step of workflow.steps) {\n\t\t\tif (step.type === \"end\" && !step.params?.output) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tseverity: \"warning\",\n\t\t\t\t\tlocation: { stepId: step.id, field: \"params\" },\n\t\t\t\t\tmessage: `End step '${step.id}' has no output expression, but the workflow declares an outputSchema`,\n\t\t\t\t\tcode: \"END_STEP_MISSING_OUTPUT\",\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor (const step of workflow.steps) {\n\t\t\tif (step.type === \"end\" && step.params?.output) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tseverity: \"warning\",\n\t\t\t\t\tlocation: { stepId: step.id, field: \"params.output\" },\n\t\t\t\t\tmessage: `End step '${step.id}' has an output expression, but the workflow does not declare an outputSchema`,\n\t\t\t\t\tcode: \"END_STEP_UNEXPECTED_OUTPUT\",\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn diagnostics;\n}\n\n/**\n * Check if a body chain (loop body or branch body) has a step whose\n * nextStepId points outside the body. Follow the chain from startId\n * through nextStepId links; all steps in this chain should be owned\n * by parentStepId.\n */\nfunction checkBodyEscapes(\n\tstartId: string,\n\tparentStepId: string,\n\tgraph: ExecutionGraph,\n): { escapingStep: string; target: string } | null {\n\tlet currentId: string | undefined = startId;\n\tconst visited = new Set<string>();\n\n\twhile (currentId) {\n\t\tif (visited.has(currentId)) break;\n\t\tvisited.add(currentId);\n\n\t\tconst step = graph.stepIndex.get(currentId);\n\t\tif (!step) break;\n\n\t\tif (step.nextStepId) {\n\t\t\t// Check if the next step is still owned by the same parent\n\t\t\tconst nextOwner = graph.bodyOwnership.get(step.nextStepId);\n\t\t\tconst currentOwner = graph.bodyOwnership.get(currentId);\n\n\t\t\t// The next step is escaping if:\n\t\t\t// 1. The current step is in the body (owned by parentStepId)\n\t\t\t// 2. The next step is NOT in the body (not owned by parentStepId)\n\t\t\tif (\n\t\t\t\t(currentOwner === parentStepId || currentId === startId) &&\n\t\t\t\tnextOwner !== parentStepId\n\t\t\t) {\n\t\t\t\treturn { escapingStep: currentId, target: step.nextStepId };\n\t\t\t}\n\t\t}\n\n\t\tcurrentId = step.nextStepId;\n\t}\n\n\treturn null;\n}\n",
11
+ "import type { WorkflowStep } from \"../../types\";\nimport type { Diagnostic, ExecutionGraph, ToolDefinitionMap } from \"../types\";\n\nexport function validateForeachTarget(\n\tworkflow: { steps: WorkflowStep[] },\n\tgraph: ExecutionGraph,\n\ttools: ToolDefinitionMap,\n): Diagnostic[] {\n\tconst diagnostics: Diagnostic[] = [];\n\n\tfor (const step of workflow.steps) {\n\t\tif (step.type !== \"for-each\") continue;\n\t\tif (step.params.target.type !== \"jmespath\") continue;\n\n\t\tconst expression = step.params.target.expression;\n\n\t\t// Only handle simple dotted paths (e.g. \"step_id\" or \"step_id.field\")\n\t\tconst segments = parseSimplePath(expression);\n\t\tif (!segments) continue;\n\n\t\tconst [rootId, ...fieldPath] = segments;\n\t\tif (!rootId) continue;\n\n\t\tconst referencedStep = graph.stepIndex.get(rootId);\n\t\tif (!referencedStep) continue; // Handled by jmespath validation\n\n\t\tconst outputSchema = getStepOutputSchema(referencedStep, tools);\n\t\tif (!outputSchema) continue;\n\n\t\tconst resolvedSchema = resolvePath(outputSchema, fieldPath);\n\t\tif (!resolvedSchema) continue;\n\n\t\tconst resolvedType = getSchemaType(resolvedSchema);\n\t\tif (resolvedType === \"array\") continue;\n\n\t\tif (resolvedType === \"object\") {\n\t\t\tconst suggestions = findArrayProperties(resolvedSchema);\n\t\t\tconst hint =\n\t\t\t\tsuggestions.length > 0\n\t\t\t\t\t? ` Did you mean ${suggestions.map((s) => `'${rootId}.${s}'`).join(\" or \")}?`\n\t\t\t\t\t: \"\";\n\n\t\t\tdiagnostics.push({\n\t\t\t\tseverity: \"error\",\n\t\t\t\tlocation: { stepId: step.id, field: \"params.target\" },\n\t\t\t\tmessage: `for-each target '${expression}' resolves to an object, not an array.${hint}`,\n\t\t\t\tcode: \"FOREACH_TARGET_NOT_ARRAY\",\n\t\t\t});\n\t\t} else if (resolvedType !== null) {\n\t\t\tdiagnostics.push({\n\t\t\t\tseverity: \"error\",\n\t\t\t\tlocation: { stepId: step.id, field: \"params.target\" },\n\t\t\t\tmessage: `for-each target '${expression}' resolves to type '${resolvedType}', not an array.`,\n\t\t\t\tcode: \"FOREACH_TARGET_NOT_ARRAY\",\n\t\t\t});\n\t\t}\n\t}\n\n\treturn diagnostics;\n}\n\nfunction parseSimplePath(expression: string): string[] | null {\n\tif (!/^[a-zA-Z_][a-zA-Z0-9_]*(\\.[a-zA-Z_][a-zA-Z0-9_]*)*$/.test(expression)) {\n\t\treturn null;\n\t}\n\treturn expression.split(\".\");\n}\n\nfunction getStepOutputSchema(\n\tstep: WorkflowStep,\n\ttools: ToolDefinitionMap,\n): Record<string, unknown> | null {\n\tif (step.type === \"tool-call\") {\n\t\tconst toolDef = tools[step.params.toolName];\n\t\treturn toolDef?.outputSchema ?? null;\n\t}\n\tif (step.type === \"start\" && step.params.inputSchema) {\n\t\treturn step.params.inputSchema as Record<string, unknown>;\n\t}\n\treturn null;\n}\n\nfunction resolvePath(\n\tschema: Record<string, unknown>,\n\tpath: string[],\n): Record<string, unknown> | null {\n\tlet current = schema;\n\tfor (const segment of path) {\n\t\tconst properties = current.properties as\n\t\t\t| Record<string, Record<string, unknown>>\n\t\t\t| undefined;\n\t\tif (!properties?.[segment]) return null;\n\t\tcurrent = properties[segment];\n\t}\n\treturn current;\n}\n\nfunction getSchemaType(schema: Record<string, unknown>): string | null {\n\tif (typeof schema.type === \"string\") return schema.type;\n\treturn null;\n}\n\nfunction findArrayProperties(schema: Record<string, unknown>): string[] {\n\tconst properties = schema.properties as\n\t\t| Record<string, Record<string, unknown>>\n\t\t| undefined;\n\tif (!properties) return [];\n\treturn Object.entries(properties)\n\t\t.filter(([_, propSchema]) => propSchema.type === \"array\")\n\t\t.map(([name]) => name);\n}\n",
12
+ "import { compile } from \"@jmespath-community/jmespath\";\n\n/**\n * Validate that a JMESPath expression is syntactically valid.\n */\nexport function validateJmespathSyntax(\n\texpression: string,\n): { valid: true } | { valid: false; error: string } {\n\ttry {\n\t\tcompile(expression);\n\t\treturn { valid: true };\n\t} catch (e) {\n\t\treturn { valid: false, error: (e as Error).message };\n\t}\n}\n\ninterface ASTNode {\n\ttype: string;\n\tname?: string;\n\tleft?: ASTNode;\n\tright?: ASTNode;\n\tchildren?: ASTNode[];\n\tcondition?: ASTNode;\n\t[key: string]: unknown;\n}\n\n/**\n * Extract root identifiers from a JMESPath AST.\n * A \"root identifier\" is a Field node that represents a top-level\n * reference (e.g., `stepId` in `stepId.field`, `foo` in `length(foo.bar)`).\n *\n * We walk the AST and collect Field nodes that appear in \"root position\" —\n * meaning they are the leftmost leaf in a chain of Subexpressions,\n * or standalone fields, or the first field in a function argument.\n */\nexport function extractRootIdentifiers(expression: string): string[] {\n\tlet ast: ASTNode;\n\ttry {\n\t\tast = compile(expression) as unknown as ASTNode;\n\t} catch {\n\t\treturn [];\n\t}\n\n\tconst roots = new Set<string>();\n\tcollectRoots(ast, roots);\n\treturn [...roots];\n}\n\nfunction collectRoots(node: ASTNode, roots: Set<string>): void {\n\tif (!node || typeof node !== \"object\") return;\n\n\tswitch (node.type) {\n\t\tcase \"Field\":\n\t\t\t// Standalone field — this IS a root reference\n\t\t\tif (node.name) roots.add(node.name);\n\t\t\tbreak;\n\n\t\tcase \"Subexpression\":\n\t\t\t// Only the leftmost field in the chain is a root\n\t\t\tif (node.left) collectLeftmostRoot(node.left, roots);\n\t\t\tbreak;\n\n\t\tcase \"FilterProjection\":\n\t\t\t// Only the left side contains root references.\n\t\t\t// The condition and right are relative to the filtered items,\n\t\t\t// NOT root-level references.\n\t\t\tif (node.left) collectLeftmostRoot(node.left, roots);\n\t\t\tbreak;\n\n\t\tcase \"Projection\":\n\t\tcase \"Flatten\":\n\t\t\t// The left side contains the root; right is relative\n\t\t\tif (node.left) collectLeftmostRoot(node.left, roots);\n\t\t\tbreak;\n\n\t\tcase \"Function\":\n\t\t\t// Recurse into function arguments\n\t\t\tif (node.children) {\n\t\t\t\tfor (const child of node.children) {\n\t\t\t\t\tcollectRoots(child, roots);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"MultiSelectList\":\n\t\tcase \"MultiSelectHash\":\n\t\t\tif (node.children) {\n\t\t\t\tfor (const child of node.children) {\n\t\t\t\t\tcollectRoots(child, roots);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"Comparator\":\n\t\tcase \"And\":\n\t\tcase \"Or\":\n\t\tcase \"Arithmetic\":\n\t\t\tif (node.left) collectRoots(node.left, roots);\n\t\t\tif (node.right) collectRoots(node.right, roots);\n\t\t\tbreak;\n\n\t\tcase \"Not\":\n\t\tcase \"Negate\":\n\t\t\tif (node.children?.[0]) collectRoots(node.children[0], roots);\n\t\t\tbreak;\n\n\t\tcase \"Pipe\":\n\t\t\t// Only the left side of a pipe has root references from the data\n\t\t\tif (node.left) collectRoots(node.left, roots);\n\t\t\tbreak;\n\n\t\tcase \"IndexExpression\":\n\t\t\tif (node.left) collectLeftmostRoot(node.left, roots);\n\t\t\tbreak;\n\n\t\tcase \"ValueProjection\":\n\t\tcase \"Slice\":\n\t\t\tif (node.left) collectLeftmostRoot(node.left, roots);\n\t\t\tbreak;\n\n\t\tcase \"Literal\":\n\t\tcase \"Current\":\n\t\tcase \"Identity\":\n\t\tcase \"Expref\":\n\t\t\t// No root references\n\t\t\tbreak;\n\n\t\tcase \"KeyValuePair\": {\n\t\t\tconst kvValue = (node as Record<string, ASTNode>).value;\n\t\t\tif (kvValue) {\n\t\t\t\tcollectRoots(kvValue, roots);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault:\n\t\t\t// Unknown node type — try to recurse into known fields\n\t\t\tif (node.left) collectRoots(node.left, roots);\n\t\t\tif (node.right) collectRoots(node.right, roots);\n\t\t\tif (node.children) {\n\t\t\t\tfor (const child of node.children) {\n\t\t\t\t\tcollectRoots(child, roots);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\n/**\n * Follow the left side of subexpressions/projections to find the\n * leftmost root field.\n */\nfunction collectLeftmostRoot(node: ASTNode, roots: Set<string>): void {\n\tif (!node) return;\n\n\tswitch (node.type) {\n\t\tcase \"Field\":\n\t\t\tif (node.name) roots.add(node.name);\n\t\t\tbreak;\n\t\tcase \"Subexpression\":\n\t\t\tif (node.left) collectLeftmostRoot(node.left, roots);\n\t\t\tbreak;\n\t\tcase \"FilterProjection\":\n\t\tcase \"Projection\":\n\t\tcase \"Flatten\":\n\t\tcase \"IndexExpression\":\n\t\tcase \"ValueProjection\":\n\t\tcase \"Slice\":\n\t\t\tif (node.left) collectLeftmostRoot(node.left, roots);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t// For other types (like Arithmetic for hyphenated IDs), fall through\n\t\t\tcollectRoots(node, roots);\n\t\t\tbreak;\n\t}\n}\n\nexport interface TemplateExpression {\n\texpression: string;\n\tstart: number;\n\tend: number;\n}\n\nexport interface TemplateExtractionResult {\n\texpressions: TemplateExpression[];\n\tunclosed: number[]; // start positions of unclosed ${\n}\n\n/**\n * Extract all ${...} template expressions from an llm-prompt template string.\n * Also reports positions of unclosed ${ sequences.\n */\nexport function extractTemplateExpressions(\n\ttemplate: string,\n): TemplateExtractionResult {\n\tconst expressions: TemplateExpression[] = [];\n\tconst unclosed: number[] = [];\n\tlet i = 0;\n\n\twhile (i < template.length) {\n\t\tif (template[i] === \"$\" && template[i + 1] === \"{\") {\n\t\t\tconst start = i;\n\t\t\ti += 2; // Skip ${\n\t\t\tlet depth = 1;\n\t\t\tconst exprStart = i;\n\n\t\t\twhile (i < template.length && depth > 0) {\n\t\t\t\tif (template[i] === \"{\") depth++;\n\t\t\t\telse if (template[i] === \"}\") depth--;\n\t\t\t\tif (depth > 0) i++;\n\t\t\t}\n\n\t\t\tif (depth === 0) {\n\t\t\t\tconst expression = template.slice(exprStart, i);\n\t\t\t\texpressions.push({ expression, start, end: i + 1 });\n\t\t\t\ti++; // Skip closing }\n\t\t\t} else {\n\t\t\t\tunclosed.push(start);\n\t\t\t}\n\t\t} else {\n\t\t\ti++;\n\t\t}\n\t}\n\n\treturn { expressions, unclosed };\n}\n",
13
+ "import type { WorkflowDefinition } from \"../../types\";\nimport type { Diagnostic, ExecutionGraph } from \"../types\";\nimport {\n\textractRootIdentifiers,\n\textractTemplateExpressions,\n\tvalidateJmespathSyntax,\n} from \"../utils/jmespath-helpers\";\n\ninterface ExpressionInfo {\n\texpression: string;\n\tstepId: string;\n\tfield: string;\n}\n\nexport function validateJmespath(\n\tworkflow: WorkflowDefinition,\n\tgraph: ExecutionGraph,\n): Diagnostic[] {\n\tconst diagnostics: Diagnostic[] = [];\n\n\t// Collect all JMESPath expressions with location info\n\tconst { expressions, templateDiagnostics } = collectExpressions(workflow);\n\tdiagnostics.push(...templateDiagnostics);\n\n\tfor (const expr of expressions) {\n\t\t// Syntax validation\n\t\tconst syntaxResult = validateJmespathSyntax(expr.expression);\n\t\tif (!syntaxResult.valid) {\n\t\t\tdiagnostics.push({\n\t\t\t\tseverity: \"error\",\n\t\t\t\tlocation: { stepId: expr.stepId, field: expr.field },\n\t\t\t\tmessage: `Invalid JMESPath syntax in '${expr.expression}': ${syntaxResult.error}`,\n\t\t\t\tcode: \"JMESPATH_SYNTAX_ERROR\",\n\t\t\t});\n\t\t\tcontinue; // Can't do scope validation on invalid syntax\n\t\t}\n\n\t\t// Scope/reference validation\n\t\tvalidateExpressionScope(expr, graph, diagnostics);\n\t}\n\n\treturn diagnostics;\n}\n\nfunction collectExpressions(workflow: WorkflowDefinition): {\n\texpressions: ExpressionInfo[];\n\ttemplateDiagnostics: Diagnostic[];\n} {\n\tconst expressions: ExpressionInfo[] = [];\n\tconst templateDiagnostics: Diagnostic[] = [];\n\n\tfor (const step of workflow.steps) {\n\t\tswitch (step.type) {\n\t\t\tcase \"tool-call\":\n\t\t\t\tfor (const [key, val] of Object.entries(step.params.toolInput)) {\n\t\t\t\t\tif (val.type === \"jmespath\") {\n\t\t\t\t\t\texpressions.push({\n\t\t\t\t\t\t\texpression: val.expression,\n\t\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\t\tfield: `params.toolInput.${key}.expression`,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase \"switch-case\":\n\t\t\t\tif (step.params.switchOn.type === \"jmespath\") {\n\t\t\t\t\texpressions.push({\n\t\t\t\t\t\texpression: step.params.switchOn.expression,\n\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\tfield: \"params.switchOn.expression\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tfor (const [i, c] of step.params.cases.entries()) {\n\t\t\t\t\tif (c.value.type === \"jmespath\") {\n\t\t\t\t\t\texpressions.push({\n\t\t\t\t\t\t\texpression: c.value.expression,\n\t\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\t\tfield: `params.cases[${i}].value.expression`,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase \"for-each\":\n\t\t\t\tif (step.params.target.type === \"jmespath\") {\n\t\t\t\t\texpressions.push({\n\t\t\t\t\t\texpression: step.params.target.expression,\n\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\tfield: \"params.target.expression\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase \"extract-data\":\n\t\t\t\tif (step.params.sourceData.type === \"jmespath\") {\n\t\t\t\t\texpressions.push({\n\t\t\t\t\t\texpression: step.params.sourceData.expression,\n\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\tfield: \"params.sourceData.expression\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase \"start\":\n\t\t\t\tbreak;\n\n\t\t\tcase \"end\":\n\t\t\t\tif (step.params?.output && step.params.output.type === \"jmespath\") {\n\t\t\t\t\texpressions.push({\n\t\t\t\t\t\texpression: step.params.output.expression,\n\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\tfield: \"params.output.expression\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase \"llm-prompt\": {\n\t\t\t\tconst { expressions: templateExprs, unclosed } =\n\t\t\t\t\textractTemplateExpressions(step.params.prompt);\n\t\t\t\tfor (const te of templateExprs) {\n\t\t\t\t\texpressions.push({\n\t\t\t\t\t\texpression: te.expression,\n\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\tfield: `params.prompt[${te.start}:${te.end}]`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tfor (const pos of unclosed) {\n\t\t\t\t\ttemplateDiagnostics.push({\n\t\t\t\t\t\tseverity: \"error\",\n\t\t\t\t\t\tlocation: {\n\t\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\t\tfield: `params.prompt[${pos}]`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tmessage: `Unclosed template expression at position ${pos} in prompt`,\n\t\t\t\t\t\tcode: \"UNCLOSED_TEMPLATE_EXPRESSION\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { expressions, templateDiagnostics };\n}\n\nfunction validateExpressionScope(\n\texpr: ExpressionInfo,\n\tgraph: ExecutionGraph,\n\tdiagnostics: Diagnostic[],\n): void {\n\tconst astRoots = extractRootIdentifiers(expr.expression);\n\tconst loopVars = graph.loopVariablesInScope.get(expr.stepId);\n\tconst predecessors = graph.predecessors.get(expr.stepId);\n\n\tfor (const root of astRoots) {\n\t\t// Skip if it's a loop variable in scope\n\t\tif (loopVars?.has(root)) continue;\n\n\t\t// Check if it's a step ID\n\t\tif (graph.stepIndex.has(root)) {\n\t\t\t// Check if the step is a predecessor (has executed before this step)\n\t\t\tif (predecessors && !predecessors.has(root)) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tseverity: \"warning\",\n\t\t\t\t\tlocation: { stepId: expr.stepId, field: expr.field },\n\t\t\t\t\tmessage: `Expression '${expr.expression}' references step '${root}' which may not have executed before step '${expr.stepId}'`,\n\t\t\t\t\tcode: \"JMESPATH_FORWARD_REFERENCE\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tdiagnostics.push({\n\t\t\tseverity: \"error\",\n\t\t\tlocation: { stepId: expr.stepId, field: expr.field },\n\t\t\tmessage: `Expression '${expr.expression}' references '${root}' which is not a known step ID or loop variable in scope`,\n\t\t\tcode: \"JMESPATH_INVALID_ROOT_REFERENCE\",\n\t\t});\n\t}\n}\n",
14
+ "import type { WorkflowDefinition } from \"../../types\";\nimport type { Diagnostic } from \"../types\";\n\nexport function validateReferences(workflow: WorkflowDefinition): Diagnostic[] {\n\tconst diagnostics: Diagnostic[] = [];\n\tconst stepIds = new Set(workflow.steps.map((s) => s.id));\n\n\t// Check initialStepId\n\tif (!stepIds.has(workflow.initialStepId)) {\n\t\tdiagnostics.push({\n\t\t\tseverity: \"error\",\n\t\t\tlocation: { stepId: null, field: \"initialStepId\" },\n\t\t\tmessage: `Initial step '${workflow.initialStepId}' does not exist`,\n\t\t\tcode: \"MISSING_INITIAL_STEP\",\n\t\t});\n\t}\n\n\tfor (const step of workflow.steps) {\n\t\t// Check nextStepId\n\t\tif (step.nextStepId && !stepIds.has(step.nextStepId)) {\n\t\t\tdiagnostics.push({\n\t\t\t\tseverity: \"error\",\n\t\t\t\tlocation: { stepId: step.id, field: \"nextStepId\" },\n\t\t\t\tmessage: `Step '${step.id}' references non-existent next step '${step.nextStepId}'`,\n\t\t\t\tcode: \"MISSING_NEXT_STEP\",\n\t\t\t});\n\t\t}\n\n\t\t// Check branchBodyStepId in switch-case\n\t\tif (step.type === \"switch-case\") {\n\t\t\tfor (const [i, c] of step.params.cases.entries()) {\n\t\t\t\tif (!stepIds.has(c.branchBodyStepId)) {\n\t\t\t\t\tdiagnostics.push({\n\t\t\t\t\t\tseverity: \"error\",\n\t\t\t\t\t\tlocation: {\n\t\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\t\tfield: `params.cases[${i}].branchBodyStepId`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tmessage: `Step '${step.id}' case ${i} references non-existent branch body step '${c.branchBodyStepId}'`,\n\t\t\t\t\t\tcode: \"MISSING_BRANCH_BODY_STEP\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Check loopBodyStepId in for-each\n\t\tif (step.type === \"for-each\") {\n\t\t\tif (!stepIds.has(step.params.loopBodyStepId)) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tseverity: \"error\",\n\t\t\t\t\tlocation: {\n\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\tfield: \"params.loopBodyStepId\",\n\t\t\t\t\t},\n\t\t\t\t\tmessage: `Step '${step.id}' references non-existent loop body step '${step.params.loopBodyStepId}'`,\n\t\t\t\t\tcode: \"MISSING_LOOP_BODY_STEP\",\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn diagnostics;\n}\n",
15
+ "import type { WorkflowDefinition } from \"../../types\";\nimport type { Diagnostic, ToolDefinitionMap } from \"../types\";\n\nexport function validateTools(\n\tworkflow: WorkflowDefinition,\n\ttools: ToolDefinitionMap,\n): Diagnostic[] {\n\tconst diagnostics: Diagnostic[] = [];\n\n\tfor (const step of workflow.steps) {\n\t\tif (step.type !== \"tool-call\") continue;\n\n\t\tconst { toolName, toolInput } = step.params;\n\n\t\t// Check tool exists\n\t\tconst toolDef = tools[toolName];\n\t\tif (!toolDef) {\n\t\t\tdiagnostics.push({\n\t\t\t\tseverity: \"error\",\n\t\t\t\tlocation: { stepId: step.id, field: \"params.toolName\" },\n\t\t\t\tmessage: `Step '${step.id}' references unknown tool '${toolName}'`,\n\t\t\t\tcode: \"UNKNOWN_TOOL\",\n\t\t\t});\n\t\t\tcontinue; // Can't validate inputs for unknown tool\n\t\t}\n\n\t\tconst schemaProperties = toolDef.inputSchema.properties ?? {};\n\t\tconst requiredKeys = new Set(toolDef.inputSchema.required ?? []);\n\t\tconst definedKeys = new Set(Object.keys(schemaProperties));\n\t\tconst providedKeys = new Set(Object.keys(toolInput));\n\n\t\t// Check for extra keys (provided but not in schema)\n\t\tfor (const key of providedKeys) {\n\t\t\tif (!definedKeys.has(key)) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tseverity: \"warning\",\n\t\t\t\t\tlocation: {\n\t\t\t\t\t\tstepId: step.id,\n\t\t\t\t\t\tfield: `params.toolInput.${key}`,\n\t\t\t\t\t},\n\t\t\t\t\tmessage: `Step '${step.id}' provides input key '${key}' which is not defined in tool '${toolName}' schema`,\n\t\t\t\t\tcode: \"EXTRA_TOOL_INPUT_KEY\",\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Check for missing required keys\n\t\tfor (const key of requiredKeys) {\n\t\t\tif (!providedKeys.has(key)) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tseverity: \"error\",\n\t\t\t\t\tlocation: { stepId: step.id, field: \"params.toolInput\" },\n\t\t\t\t\tmessage: `Step '${step.id}' is missing required input key '${key}' for tool '${toolName}'`,\n\t\t\t\t\tcode: \"MISSING_TOOL_INPUT_KEY\",\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn diagnostics;\n}\n",
16
+ "import { safeValidateTypes } from \"@ai-sdk/provider-utils\";\nimport { search } from \"@jmespath-community/jmespath\";\nimport type { Agent, LanguageModel, ToolSet } from \"ai\";\nimport {\n\tAPICallError,\n\tJSONParseError,\n\tNoContentGeneratedError,\n\tRetryError,\n\tstepCountIs,\n\tToolLoopAgent,\n\tTypeValidationError,\n} from \"ai\";\nimport { extractTemplateExpressions } from \"../compiler/utils/jmespath-helpers\";\nimport type { WorkflowDefinition, WorkflowStep } from \"../types\";\nimport type { ErrorCode } from \"./errors\";\nimport {\n\tConfigurationError,\n\tExpressionError,\n\tExternalServiceError,\n\tOutputQualityError,\n\tStepExecutionError,\n\tValidationError,\n} from \"./errors\";\n\n// ─── Helpers ─────────────────────────────────────────────────────\n\nfunction stripCodeFence(text: string): string {\n\tconst match = text.match(/^```(?:\\w*)\\s*\\n?([\\s\\S]*?)\\n?\\s*```\\s*$/);\n\treturn match?.[1] ?? text;\n}\n\n// ─── Types ───────────────────────────────────────────────────────\n\nexport interface ExecutionResult {\n\tsuccess: boolean;\n\tstepOutputs: Record<string, unknown>;\n\toutput?: unknown;\n\terror?: StepExecutionError;\n}\n\nexport interface ExecuteWorkflowOptions {\n\ttools: ToolSet;\n\tagent?: Agent | LanguageModel;\n\tinputs?: Record<string, unknown>;\n\tmaxRetries?: number;\n\tretryDelayMs?: number;\n\tonStepStart?: (stepId: string, step: WorkflowStep) => void;\n\tonStepComplete?: (stepId: string, output: unknown) => void;\n}\n\nfunction isAgent(value: Agent | LanguageModel): value is Agent {\n\treturn typeof value === \"object\" && value !== null && \"generate\" in value;\n}\n\n// ─── Expression Evaluation ───────────────────────────────────────\n\ntype Expression =\n\t| { type: \"literal\"; value: unknown }\n\t| { type: \"jmespath\"; expression: string };\n\nfunction evaluateExpression(\n\texpr: Expression,\n\tscope: Record<string, unknown>,\n\tstepId: string,\n): unknown {\n\tif (expr.type === \"literal\") {\n\t\treturn expr.value;\n\t}\n\ttry {\n\t\treturn search(scope as Parameters<typeof search>[0], expr.expression);\n\t} catch (e) {\n\t\tthrow new ExpressionError(\n\t\t\tstepId,\n\t\t\t\"JMESPATH_EVALUATION_ERROR\",\n\t\t\t`JMESPath expression '${expr.expression}' failed: ${e instanceof Error ? e.message : String(e)}`,\n\t\t\texpr.expression,\n\t\t\te,\n\t\t);\n\t}\n}\n\nfunction stringifyValue(value: unknown): string {\n\tif (value === null || value === undefined) return \"\";\n\tif (typeof value === \"object\") return JSON.stringify(value);\n\treturn String(value);\n}\n\nfunction interpolateTemplate(\n\ttemplate: string,\n\tscope: Record<string, unknown>,\n\tstepId: string,\n): string {\n\tconst { expressions } = extractTemplateExpressions(template);\n\tif (expressions.length === 0) return template;\n\n\tlet result = \"\";\n\tlet lastEnd = 0;\n\tfor (const expr of expressions) {\n\t\tresult += template.slice(lastEnd, expr.start);\n\t\ttry {\n\t\t\tconst value = search(\n\t\t\t\tscope as Parameters<typeof search>[0],\n\t\t\t\texpr.expression,\n\t\t\t);\n\t\t\tresult += stringifyValue(value);\n\t\t} catch (e) {\n\t\t\tthrow new ExpressionError(\n\t\t\t\tstepId,\n\t\t\t\t\"TEMPLATE_INTERPOLATION_ERROR\",\n\t\t\t\t`Template expression '${expr.expression}' failed: ${e instanceof Error ? e.message : String(e)}`,\n\t\t\t\texpr.expression,\n\t\t\t\te,\n\t\t\t);\n\t\t}\n\t\tlastEnd = expr.end;\n\t}\n\tresult += template.slice(lastEnd);\n\treturn result;\n}\n\n// ─── LLM Error Classification ───────────────────────────────────\n\nfunction classifyLlmError(stepId: string, e: unknown): StepExecutionError {\n\tif (APICallError.isInstance(e)) {\n\t\tconst code: ErrorCode =\n\t\t\te.statusCode === 429 ? \"LLM_RATE_LIMITED\" : \"LLM_API_ERROR\";\n\t\treturn new ExternalServiceError(\n\t\t\tstepId,\n\t\t\tcode,\n\t\t\te.message,\n\t\t\te,\n\t\t\te.statusCode,\n\t\t\te.isRetryable ?? true,\n\t\t);\n\t}\n\tif (RetryError.isInstance(e)) {\n\t\treturn new ExternalServiceError(\n\t\t\tstepId,\n\t\t\t\"LLM_API_ERROR\",\n\t\t\te.message,\n\t\t\te,\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t);\n\t}\n\tif (NoContentGeneratedError.isInstance(e)) {\n\t\treturn new ExternalServiceError(\n\t\t\tstepId,\n\t\t\t\"LLM_NO_CONTENT\",\n\t\t\te.message,\n\t\t\te,\n\t\t\tundefined,\n\t\t\ttrue,\n\t\t);\n\t}\n\tif (TypeValidationError.isInstance(e)) {\n\t\treturn new OutputQualityError(\n\t\t\tstepId,\n\t\t\t\"LLM_OUTPUT_PARSE_ERROR\",\n\t\t\t`LLM output could not be parsed: ${e.message}`,\n\t\t\te.value,\n\t\t\te,\n\t\t);\n\t}\n\tif (JSONParseError.isInstance(e)) {\n\t\treturn new OutputQualityError(\n\t\t\tstepId,\n\t\t\t\"LLM_OUTPUT_PARSE_ERROR\",\n\t\t\t`LLM output could not be parsed: ${e.message}`,\n\t\t\te.text,\n\t\t\te,\n\t\t);\n\t}\n\treturn new ExternalServiceError(\n\t\tstepId,\n\t\t\"LLM_NETWORK_ERROR\",\n\t\te instanceof Error ? e.message : String(e),\n\t\te,\n\t\tundefined,\n\t\ttrue,\n\t);\n}\n\n// ─── Input Validation ────────────────────────────────────────────\n\nfunction validateWorkflowInputs(\n\tstep: WorkflowStep & { type: \"start\" },\n\tinputs: Record<string, unknown>,\n): void {\n\tconst schema = step.params.inputSchema as Record<string, unknown>;\n\tif (!schema || typeof schema !== \"object\") return;\n\n\tconst required = schema.required;\n\tif (Array.isArray(required)) {\n\t\tconst missing = required.filter(\n\t\t\t(key: unknown) => typeof key === \"string\" && !(key in inputs),\n\t\t);\n\t\tif (missing.length > 0) {\n\t\t\tthrow new ValidationError(\n\t\t\t\tstep.id,\n\t\t\t\t\"TOOL_INPUT_VALIDATION_FAILED\",\n\t\t\t\t`Workflow input validation failed: missing required input(s): ${missing.join(\", \")}`,\n\t\t\t\tinputs,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst properties = schema.properties;\n\tif (properties && typeof properties === \"object\") {\n\t\tfor (const [key, value] of Object.entries(inputs)) {\n\t\t\tconst propSchema = (properties as Record<string, unknown>)[key];\n\t\t\tif (\n\t\t\t\tpropSchema &&\n\t\t\t\ttypeof propSchema === \"object\" &&\n\t\t\t\t\"type\" in propSchema\n\t\t\t) {\n\t\t\t\tconst expectedType = (propSchema as { type: string }).type;\n\t\t\t\tconst actualType = typeof value;\n\t\t\t\tif (expectedType === \"integer\" || expectedType === \"number\") {\n\t\t\t\t\tif (actualType !== \"number\") {\n\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\tstep.id,\n\t\t\t\t\t\t\t\"TOOL_INPUT_VALIDATION_FAILED\",\n\t\t\t\t\t\t\t`Workflow input validation failed: input '${key}' expected type '${expectedType}' but got '${actualType}'`,\n\t\t\t\t\t\t\tinputs,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (expectedType === \"array\") {\n\t\t\t\t\tif (!Array.isArray(value)) {\n\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\tstep.id,\n\t\t\t\t\t\t\t\"TOOL_INPUT_VALIDATION_FAILED\",\n\t\t\t\t\t\t\t`Workflow input validation failed: input '${key}' expected type 'array' but got '${actualType}'`,\n\t\t\t\t\t\t\tinputs,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (actualType !== expectedType) {\n\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\tstep.id,\n\t\t\t\t\t\t\"TOOL_INPUT_VALIDATION_FAILED\",\n\t\t\t\t\t\t`Workflow input validation failed: input '${key}' expected type '${expectedType}' but got '${actualType}'`,\n\t\t\t\t\t\tinputs,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n// ─── Output Validation ──────────────────────────────────────────\n\nfunction validateWorkflowOutput(\n\toutputSchema: Record<string, unknown>,\n\toutput: unknown,\n\tendStepId: string,\n): void {\n\tconst expectedType = outputSchema.type;\n\tif (typeof expectedType === \"string\") {\n\t\tif (\n\t\t\texpectedType === \"object\" &&\n\t\t\t(typeof output !== \"object\" || output === null)\n\t\t) {\n\t\t\tthrow new ValidationError(\n\t\t\t\tendStepId,\n\t\t\t\t\"WORKFLOW_OUTPUT_VALIDATION_FAILED\",\n\t\t\t\t`Workflow output validation failed: expected type 'object' but got '${output === null ? \"null\" : typeof output}'`,\n\t\t\t\toutput,\n\t\t\t);\n\t\t}\n\t\tif (expectedType === \"array\" && !Array.isArray(output)) {\n\t\t\tthrow new ValidationError(\n\t\t\t\tendStepId,\n\t\t\t\t\"WORKFLOW_OUTPUT_VALIDATION_FAILED\",\n\t\t\t\t`Workflow output validation failed: expected type 'array' but got '${typeof output}'`,\n\t\t\t\toutput,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\t(expectedType === \"string\" || expectedType === \"boolean\") &&\n\t\t\ttypeof output !== expectedType\n\t\t) {\n\t\t\tthrow new ValidationError(\n\t\t\t\tendStepId,\n\t\t\t\t\"WORKFLOW_OUTPUT_VALIDATION_FAILED\",\n\t\t\t\t`Workflow output validation failed: expected type '${expectedType}' but got '${typeof output}'`,\n\t\t\t\toutput,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\t(expectedType === \"number\" || expectedType === \"integer\") &&\n\t\t\ttypeof output !== \"number\"\n\t\t) {\n\t\t\tthrow new ValidationError(\n\t\t\t\tendStepId,\n\t\t\t\t\"WORKFLOW_OUTPUT_VALIDATION_FAILED\",\n\t\t\t\t`Workflow output validation failed: expected type '${expectedType}' but got '${typeof output}'`,\n\t\t\t\toutput,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (typeof output === \"object\" && output !== null && !Array.isArray(output)) {\n\t\tconst required = outputSchema.required;\n\t\tif (Array.isArray(required)) {\n\t\t\tconst missing = required.filter(\n\t\t\t\t(key: unknown) =>\n\t\t\t\t\ttypeof key === \"string\" &&\n\t\t\t\t\t!(key in (output as Record<string, unknown>)),\n\t\t\t);\n\t\t\tif (missing.length > 0) {\n\t\t\t\tthrow new ValidationError(\n\t\t\t\t\tendStepId,\n\t\t\t\t\t\"WORKFLOW_OUTPUT_VALIDATION_FAILED\",\n\t\t\t\t\t`Workflow output validation failed: missing required field(s): ${missing.join(\", \")}`,\n\t\t\t\t\toutput,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst properties = outputSchema.properties;\n\t\tif (properties && typeof properties === \"object\") {\n\t\t\tfor (const [key, value] of Object.entries(\n\t\t\t\toutput as Record<string, unknown>,\n\t\t\t)) {\n\t\t\t\tconst propSchema = (properties as Record<string, unknown>)[key];\n\t\t\t\tif (\n\t\t\t\t\tpropSchema &&\n\t\t\t\t\ttypeof propSchema === \"object\" &&\n\t\t\t\t\t\"type\" in propSchema\n\t\t\t\t) {\n\t\t\t\t\tconst propExpectedType = (propSchema as { type: string }).type;\n\t\t\t\t\tconst actualType = typeof value;\n\t\t\t\t\tif (propExpectedType === \"integer\" || propExpectedType === \"number\") {\n\t\t\t\t\t\tif (actualType !== \"number\") {\n\t\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\t\tendStepId,\n\t\t\t\t\t\t\t\t\"WORKFLOW_OUTPUT_VALIDATION_FAILED\",\n\t\t\t\t\t\t\t\t`Workflow output validation failed: field '${key}' expected type '${propExpectedType}' but got '${actualType}'`,\n\t\t\t\t\t\t\t\toutput,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (propExpectedType === \"array\") {\n\t\t\t\t\t\tif (!Array.isArray(value)) {\n\t\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\t\tendStepId,\n\t\t\t\t\t\t\t\t\"WORKFLOW_OUTPUT_VALIDATION_FAILED\",\n\t\t\t\t\t\t\t\t`Workflow output validation failed: field '${key}' expected type 'array' but got '${actualType}'`,\n\t\t\t\t\t\t\t\toutput,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (actualType !== propExpectedType) {\n\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\tendStepId,\n\t\t\t\t\t\t\t\"WORKFLOW_OUTPUT_VALIDATION_FAILED\",\n\t\t\t\t\t\t\t`Workflow output validation failed: field '${key}' expected type '${propExpectedType}' but got '${actualType}'`,\n\t\t\t\t\t\t\toutput,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n// ─── Step Handlers ───────────────────────────────────────────────\n\nasync function executeToolCall(\n\tstep: WorkflowStep & { type: \"tool-call\" },\n\tscope: Record<string, unknown>,\n\ttools: ToolSet,\n): Promise<unknown> {\n\t// Tool existence and executability are validated in pre-flight checks\n\tconst toolDef = tools[step.params.toolName];\n\tif (!toolDef?.execute) {\n\t\tthrow new ConfigurationError(\n\t\t\tstep.id,\n\t\t\t\"TOOL_NOT_FOUND\",\n\t\t\t`Tool '${step.params.toolName}' not found or has no execute function`,\n\t\t);\n\t}\n\n\tconst resolvedInput: Record<string, unknown> = {};\n\tfor (const [key, expr] of Object.entries(step.params.toolInput)) {\n\t\tresolvedInput[key] = evaluateExpression(expr as Expression, scope, step.id);\n\t}\n\n\tif (toolDef.inputSchema) {\n\t\tconst validation = await safeValidateTypes({\n\t\t\tvalue: resolvedInput,\n\t\t\tschema: toolDef.inputSchema,\n\t\t});\n\t\tif (!validation.success) {\n\t\t\tthrow new ValidationError(\n\t\t\t\tstep.id,\n\t\t\t\t\"TOOL_INPUT_VALIDATION_FAILED\",\n\t\t\t\t`Tool '${step.params.toolName}' input validation failed: ${validation.error.message}`,\n\t\t\t\tresolvedInput,\n\t\t\t\tvalidation.error,\n\t\t\t);\n\t\t}\n\t}\n\n\ttry {\n\t\treturn await toolDef.execute(resolvedInput, {\n\t\t\ttoolCallId: step.id,\n\t\t\tmessages: [],\n\t\t});\n\t} catch (e) {\n\t\tthrow new ExternalServiceError(\n\t\t\tstep.id,\n\t\t\t\"TOOL_EXECUTION_FAILED\",\n\t\t\te instanceof Error ? e.message : String(e),\n\t\t\te,\n\t\t);\n\t}\n}\n\nasync function executeLlmPrompt(\n\tstep: WorkflowStep & { type: \"llm-prompt\" },\n\tscope: Record<string, unknown>,\n\tagent: Agent,\n): Promise<unknown> {\n\tconst interpolatedPrompt = interpolateTemplate(\n\t\tstep.params.prompt,\n\t\tscope,\n\t\tstep.id,\n\t);\n\tconst schemaStr = JSON.stringify(step.params.outputFormat, null, 2);\n\tconst prompt = `${interpolatedPrompt}\\n\\nYou must respond with valid JSON matching this JSON Schema:\\n${schemaStr}\\n\\nRespond ONLY with the JSON object, no other text.`;\n\ttry {\n\t\tconst result = await agent.generate({ prompt });\n\t\treturn JSON.parse(stripCodeFence(result.text));\n\t} catch (e) {\n\t\tif (e instanceof StepExecutionError) throw e;\n\t\tif (e instanceof SyntaxError) {\n\t\t\tthrow new OutputQualityError(\n\t\t\t\tstep.id,\n\t\t\t\t\"LLM_OUTPUT_PARSE_ERROR\",\n\t\t\t\t`LLM output is not valid JSON: ${e.message}`,\n\t\t\t\tundefined,\n\t\t\t\te,\n\t\t\t);\n\t\t}\n\t\tthrow classifyLlmError(step.id, e);\n\t}\n}\n\nasync function executeExtractData(\n\tstep: WorkflowStep & { type: \"extract-data\" },\n\tscope: Record<string, unknown>,\n\tagent: Agent,\n): Promise<unknown> {\n\tconst sourceData = evaluateExpression(\n\t\tstep.params.sourceData as Expression,\n\t\tscope,\n\t\tstep.id,\n\t);\n\tconst sourceStr =\n\t\ttypeof sourceData === \"string\"\n\t\t\t? sourceData\n\t\t\t: JSON.stringify(sourceData, null, 2);\n\n\tconst schemaStr = JSON.stringify(step.params.outputFormat, null, 2);\n\tconst prompt = `Extract the following structured data from the provided source data.\\n\\nSource data:\\n${sourceStr}\\n\\nYou must respond with valid JSON matching this JSON Schema:\\n${schemaStr}\\n\\nRespond ONLY with the JSON object, no other text.`;\n\ttry {\n\t\tconst result = await agent.generate({ prompt });\n\t\treturn JSON.parse(stripCodeFence(result.text));\n\t} catch (e) {\n\t\tif (e instanceof StepExecutionError) throw e;\n\t\tif (e instanceof SyntaxError) {\n\t\t\tthrow new OutputQualityError(\n\t\t\t\tstep.id,\n\t\t\t\t\"LLM_OUTPUT_PARSE_ERROR\",\n\t\t\t\t`LLM output is not valid JSON: ${e.message}`,\n\t\t\t\tundefined,\n\t\t\t\te,\n\t\t\t);\n\t\t}\n\t\tthrow classifyLlmError(step.id, e);\n\t}\n}\n\nasync function executeSwitchCase(\n\tstep: WorkflowStep & { type: \"switch-case\" },\n\tscope: Record<string, unknown>,\n\tstepIndex: Map<string, WorkflowStep>,\n\tstepOutputs: Record<string, unknown>,\n\tloopVars: Record<string, unknown>,\n\toptions: ExecuteWorkflowOptions,\n): Promise<unknown> {\n\tconst switchValue = evaluateExpression(\n\t\tstep.params.switchOn as Expression,\n\t\tscope,\n\t\tstep.id,\n\t);\n\n\tlet matchedBranchId: string | undefined;\n\tlet defaultBranchId: string | undefined;\n\n\tfor (const c of step.params.cases) {\n\t\tif (c.value.type === \"default\") {\n\t\t\tdefaultBranchId = c.branchBodyStepId;\n\t\t} else {\n\t\t\tconst caseValue = evaluateExpression(\n\t\t\t\tc.value as Expression,\n\t\t\t\tscope,\n\t\t\t\tstep.id,\n\t\t\t);\n\t\t\tif (caseValue === switchValue) {\n\t\t\t\tmatchedBranchId = c.branchBodyStepId;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst selectedBranchId = matchedBranchId ?? defaultBranchId;\n\tif (!selectedBranchId) {\n\t\treturn undefined;\n\t}\n\n\treturn await executeChain(\n\t\tselectedBranchId,\n\t\tstepIndex,\n\t\tstepOutputs,\n\t\tloopVars,\n\t\toptions,\n\t);\n}\n\nasync function executeForEach(\n\tstep: WorkflowStep & { type: \"for-each\" },\n\tscope: Record<string, unknown>,\n\tstepIndex: Map<string, WorkflowStep>,\n\tstepOutputs: Record<string, unknown>,\n\tloopVars: Record<string, unknown>,\n\toptions: ExecuteWorkflowOptions,\n): Promise<unknown[]> {\n\tconst target = evaluateExpression(\n\t\tstep.params.target as Expression,\n\t\tscope,\n\t\tstep.id,\n\t);\n\n\tif (!Array.isArray(target)) {\n\t\tthrow new ValidationError(\n\t\t\tstep.id,\n\t\t\t\"FOREACH_TARGET_NOT_ARRAY\",\n\t\t\t`for-each target must be an array, got ${typeof target}`,\n\t\t\ttarget,\n\t\t);\n\t}\n\n\tconst results: unknown[] = [];\n\tfor (const item of target) {\n\t\tconst innerLoopVars = { ...loopVars, [step.params.itemName]: item };\n\t\tconst lastOutput = await executeChain(\n\t\t\tstep.params.loopBodyStepId,\n\t\t\tstepIndex,\n\t\t\tstepOutputs,\n\t\t\tinnerLoopVars,\n\t\t\toptions,\n\t\t);\n\t\tresults.push(lastOutput);\n\t}\n\treturn results;\n}\n\n// ─── Step Dispatch ───────────────────────────────────────────────\n\nasync function executeStep(\n\tstep: WorkflowStep,\n\tscope: Record<string, unknown>,\n\tstepIndex: Map<string, WorkflowStep>,\n\tstepOutputs: Record<string, unknown>,\n\tloopVars: Record<string, unknown>,\n\toptions: ExecuteWorkflowOptions,\n): Promise<unknown> {\n\tswitch (step.type) {\n\t\tcase \"tool-call\":\n\t\t\treturn executeToolCall(step, scope, options.tools);\n\t\tcase \"llm-prompt\": {\n\t\t\tif (!options.agent)\n\t\t\t\tthrow new ConfigurationError(\n\t\t\t\t\tstep.id,\n\t\t\t\t\t\"AGENT_NOT_PROVIDED\",\n\t\t\t\t\t\"No agent provided\",\n\t\t\t\t);\n\t\t\treturn executeLlmPrompt(step, scope, options.agent as Agent);\n\t\t}\n\t\tcase \"extract-data\": {\n\t\t\tif (!options.agent)\n\t\t\t\tthrow new ConfigurationError(\n\t\t\t\t\tstep.id,\n\t\t\t\t\t\"AGENT_NOT_PROVIDED\",\n\t\t\t\t\t\"No agent provided\",\n\t\t\t\t);\n\t\t\treturn executeExtractData(step, scope, options.agent as Agent);\n\t\t}\n\t\tcase \"switch-case\":\n\t\t\treturn executeSwitchCase(\n\t\t\t\tstep,\n\t\t\t\tscope,\n\t\t\t\tstepIndex,\n\t\t\t\tstepOutputs,\n\t\t\t\tloopVars,\n\t\t\t\toptions,\n\t\t\t);\n\t\tcase \"for-each\":\n\t\t\treturn executeForEach(\n\t\t\t\tstep,\n\t\t\t\tscope,\n\t\t\t\tstepIndex,\n\t\t\t\tstepOutputs,\n\t\t\t\tloopVars,\n\t\t\t\toptions,\n\t\t\t);\n\t\tcase \"start\": {\n\t\t\tconst inputs = options.inputs ?? {};\n\t\t\tconst startStep = step as WorkflowStep & { type: \"start\" };\n\t\t\tvalidateWorkflowInputs(startStep, inputs);\n\t\t\treturn inputs;\n\t\t}\n\t\tcase \"end\": {\n\t\t\tconst endStep = step as WorkflowStep & { type: \"end\" };\n\t\t\tif (endStep.params?.output) {\n\t\t\t\treturn evaluateExpression(\n\t\t\t\t\tendStep.params.output as Expression,\n\t\t\t\t\tscope,\n\t\t\t\t\tstep.id,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t}\n}\n\n// ─── Error Recovery ──────────────────────────────────────────────\n\nconst DEFAULT_MAX_RETRIES = 3;\nconst DEFAULT_BASE_DELAY_MS = 1000;\n\nconst sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));\n\nasync function retryStep(\n\tstep: WorkflowStep,\n\tstepIndex: Map<string, WorkflowStep>,\n\tstepOutputs: Record<string, unknown>,\n\tloopVars: Record<string, unknown>,\n\toptions: ExecuteWorkflowOptions,\n\toriginalError: StepExecutionError,\n): Promise<unknown> {\n\tconst maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;\n\tconst baseDelay = options.retryDelayMs ?? DEFAULT_BASE_DELAY_MS;\n\tconst scope = { ...stepOutputs, ...loopVars };\n\tfor (let attempt = 1; attempt <= maxRetries; attempt++) {\n\t\tawait sleep(baseDelay * 2 ** (attempt - 1));\n\t\ttry {\n\t\t\treturn await executeStep(\n\t\t\t\tstep,\n\t\t\t\tscope,\n\t\t\t\tstepIndex,\n\t\t\t\tstepOutputs,\n\t\t\t\tloopVars,\n\t\t\t\toptions,\n\t\t\t);\n\t\t} catch {\n\t\t\tif (attempt === maxRetries) throw originalError;\n\t\t}\n\t}\n\tthrow originalError;\n}\n\nasync function recoverFromError(\n\terror: StepExecutionError,\n\tstep: WorkflowStep,\n\tstepIndex: Map<string, WorkflowStep>,\n\tstepOutputs: Record<string, unknown>,\n\tloopVars: Record<string, unknown>,\n\toptions: ExecuteWorkflowOptions,\n): Promise<unknown> {\n\tswitch (error.code) {\n\t\tcase \"LLM_RATE_LIMITED\":\n\t\tcase \"LLM_NETWORK_ERROR\":\n\t\tcase \"LLM_NO_CONTENT\":\n\t\tcase \"LLM_OUTPUT_PARSE_ERROR\":\n\t\t\treturn retryStep(step, stepIndex, stepOutputs, loopVars, options, error);\n\n\t\tcase \"LLM_API_ERROR\":\n\t\t\tif (error instanceof ExternalServiceError && error.isRetryable) {\n\t\t\t\treturn retryStep(\n\t\t\t\t\tstep,\n\t\t\t\t\tstepIndex,\n\t\t\t\t\tstepOutputs,\n\t\t\t\t\tloopVars,\n\t\t\t\t\toptions,\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow error;\n\n\t\tdefault:\n\t\t\tthrow error;\n\t}\n}\n\n// ─── Chain Execution ─────────────────────────────────────────────\n\nasync function executeChain(\n\tstartStepId: string,\n\tstepIndex: Map<string, WorkflowStep>,\n\tstepOutputs: Record<string, unknown>,\n\tloopVars: Record<string, unknown>,\n\toptions: ExecuteWorkflowOptions,\n): Promise<unknown> {\n\tlet currentStepId: string | undefined = startStepId;\n\tlet lastOutput: unknown;\n\n\twhile (currentStepId) {\n\t\tconst step = stepIndex.get(currentStepId);\n\t\tif (!step) {\n\t\t\t// Defensive: the compiler and pre-flight checks should prevent this\n\t\t\tthrow new Error(`Step '${currentStepId}' not found`);\n\t\t}\n\n\t\toptions.onStepStart?.(step.id, step);\n\n\t\tconst scope = { ...stepOutputs, ...loopVars };\n\t\tlet stepOutput: unknown;\n\n\t\ttry {\n\t\t\tstepOutput = await executeStep(\n\t\t\t\tstep,\n\t\t\t\tscope,\n\t\t\t\tstepIndex,\n\t\t\t\tstepOutputs,\n\t\t\t\tloopVars,\n\t\t\t\toptions,\n\t\t\t);\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof StepExecutionError)) throw e;\n\t\t\tstepOutput = await recoverFromError(\n\t\t\t\te,\n\t\t\t\tstep,\n\t\t\t\tstepIndex,\n\t\t\t\tstepOutputs,\n\t\t\t\tloopVars,\n\t\t\t\toptions,\n\t\t\t);\n\t\t}\n\n\t\tstepOutputs[step.id] = stepOutput;\n\t\tlastOutput = stepOutput;\n\t\toptions.onStepComplete?.(step.id, stepOutput);\n\n\t\tcurrentStepId = step.nextStepId;\n\t}\n\n\treturn lastOutput;\n}\n\n// ─── Pre-flight Validation ───────────────────────────────────────\n\nfunction validateWorkflowConfig(\n\tworkflow: WorkflowDefinition,\n\toptions: ExecuteWorkflowOptions,\n): void {\n\tconst needsAgent = workflow.steps.some(\n\t\t(s) => s.type === \"llm-prompt\" || s.type === \"extract-data\",\n\t);\n\tif (needsAgent && !options.agent) {\n\t\tconst llmStep = workflow.steps.find(\n\t\t\t(s) => s.type === \"llm-prompt\" || s.type === \"extract-data\",\n\t\t);\n\t\tthrow new ConfigurationError(\n\t\t\tllmStep?.id ?? \"unknown\",\n\t\t\t\"AGENT_NOT_PROVIDED\",\n\t\t\t\"Workflow contains LLM steps but no agent was provided\",\n\t\t);\n\t}\n\n\tfor (const step of workflow.steps) {\n\t\tif (step.type !== \"tool-call\") continue;\n\t\tconst toolDef = options.tools[step.params.toolName];\n\t\tif (!toolDef) {\n\t\t\tthrow new ConfigurationError(\n\t\t\t\tstep.id,\n\t\t\t\t\"TOOL_NOT_FOUND\",\n\t\t\t\t`Tool '${step.params.toolName}' not found`,\n\t\t\t);\n\t\t}\n\t\tif (!toolDef.execute) {\n\t\t\tthrow new ConfigurationError(\n\t\t\t\tstep.id,\n\t\t\t\t\"TOOL_MISSING_EXECUTE\",\n\t\t\t\t`Tool '${step.params.toolName}' has no execute function`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n// ─── Public API ──────────────────────────────────────────────────\n\nexport async function executeWorkflow(\n\tworkflow: WorkflowDefinition,\n\toptions: ExecuteWorkflowOptions,\n): Promise<ExecutionResult> {\n\tconst stepIndex = new Map<string, WorkflowStep>();\n\tfor (const step of workflow.steps) {\n\t\tstepIndex.set(step.id, step);\n\t}\n\n\tconst stepOutputs: Record<string, unknown> = {};\n\n\tconst resolvedAgent = options.agent\n\t\t? isAgent(options.agent)\n\t\t\t? options.agent\n\t\t\t: new ToolLoopAgent({\n\t\t\t\t\tmodel: options.agent,\n\t\t\t\t\tstopWhen: stepCountIs(1),\n\t\t\t\t})\n\t\t: undefined;\n\tconst resolvedOptions = { ...options, agent: resolvedAgent };\n\n\ttry {\n\t\tvalidateWorkflowConfig(workflow, resolvedOptions);\n\t\tconst chainOutput = await executeChain(\n\t\t\tworkflow.initialStepId,\n\t\t\tstepIndex,\n\t\t\tstepOutputs,\n\t\t\t{},\n\t\t\tresolvedOptions,\n\t\t);\n\n\t\tif (workflow.outputSchema) {\n\t\t\t// Find the terminating end step for error reporting\n\t\t\tlet endStepId = \"unknown\";\n\t\t\tfor (const step of workflow.steps) {\n\t\t\t\tif (step.type === \"end\" && step.id in stepOutputs) {\n\t\t\t\t\tendStepId = step.id;\n\t\t\t\t}\n\t\t\t}\n\t\t\tvalidateWorkflowOutput(\n\t\t\t\tworkflow.outputSchema as Record<string, unknown>,\n\t\t\t\tchainOutput,\n\t\t\t\tendStepId,\n\t\t\t);\n\t\t}\n\n\t\treturn { success: true, stepOutputs, output: chainOutput };\n\t} catch (e) {\n\t\tconst error =\n\t\t\te instanceof StepExecutionError\n\t\t\t\t? e\n\t\t\t\t: new ExternalServiceError(\n\t\t\t\t\t\t\"unknown\",\n\t\t\t\t\t\t\"TOOL_EXECUTION_FAILED\",\n\t\t\t\t\t\te instanceof Error ? e.message : String(e),\n\t\t\t\t\t\te,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t);\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tstepOutputs,\n\t\t\terror,\n\t\t};\n\t}\n}\n",
17
+ "// ─── Recovery & Classification Types ────────────────────────────\n\nexport type RecoveryStrategy =\n\t| \"none\"\n\t| \"retry\"\n\t| \"llm-transform\"\n\t| \"llm-reprompt\";\n\nexport type ErrorCategory =\n\t| \"configuration\"\n\t| \"validation\"\n\t| \"external-service\"\n\t| \"expression\"\n\t| \"output-quality\";\n\nexport type ErrorCode =\n\t// configuration — workflow is misconfigured\n\t| \"TOOL_NOT_FOUND\"\n\t| \"TOOL_MISSING_EXECUTE\"\n\t| \"AGENT_NOT_PROVIDED\"\n\t// validation — input/output data doesn't match expected schema/type\n\t| \"TOOL_INPUT_VALIDATION_FAILED\"\n\t| \"FOREACH_TARGET_NOT_ARRAY\"\n\t| \"WORKFLOW_OUTPUT_VALIDATION_FAILED\"\n\t// external-service — external service failure\n\t| \"TOOL_EXECUTION_FAILED\"\n\t| \"LLM_API_ERROR\"\n\t| \"LLM_RATE_LIMITED\"\n\t| \"LLM_NETWORK_ERROR\"\n\t| \"LLM_NO_CONTENT\"\n\t// expression — JMESPath or template evaluation failure\n\t| \"JMESPATH_EVALUATION_ERROR\"\n\t| \"TEMPLATE_INTERPOLATION_ERROR\"\n\t// output-quality — LLM produced unparseable/unusable output\n\t| \"LLM_OUTPUT_PARSE_ERROR\";\n\n// ─── Base Error Class ───────────────────────────────────────────\n\nexport class StepExecutionError extends Error {\n\toverride readonly name = \"StepExecutionError\";\n\n\tconstructor(\n\t\tpublic readonly stepId: string,\n\t\tpublic readonly code: ErrorCode,\n\t\tpublic readonly category: ErrorCategory,\n\t\tmessage: string,\n\t\tpublic override readonly cause?: unknown,\n\t) {\n\t\tsuper(message);\n\t}\n}\n\n// ─── Category Subclasses ────────────────────────────────────────\n\nexport class ConfigurationError extends StepExecutionError {\n\tconstructor(stepId: string, code: ErrorCode, message: string) {\n\t\tsuper(stepId, code, \"configuration\", message);\n\t}\n}\n\nexport class ValidationError extends StepExecutionError {\n\tconstructor(\n\t\tstepId: string,\n\t\tcode: ErrorCode,\n\t\tmessage: string,\n\t\tpublic readonly input: unknown,\n\t\tcause?: unknown,\n\t) {\n\t\tsuper(stepId, code, \"validation\", message, cause);\n\t}\n}\n\nexport class ExternalServiceError extends StepExecutionError {\n\tconstructor(\n\t\tstepId: string,\n\t\tcode: ErrorCode,\n\t\tmessage: string,\n\t\tcause?: unknown,\n\t\tpublic readonly statusCode?: number,\n\t\tpublic readonly isRetryable: boolean = true,\n\t) {\n\t\tsuper(stepId, code, \"external-service\", message, cause);\n\t}\n}\n\nexport class ExpressionError extends StepExecutionError {\n\tconstructor(\n\t\tstepId: string,\n\t\tcode: ErrorCode,\n\t\tmessage: string,\n\t\tpublic readonly expression: string,\n\t\tcause?: unknown,\n\t) {\n\t\tsuper(stepId, code, \"expression\", message, cause);\n\t}\n}\n\nexport class OutputQualityError extends StepExecutionError {\n\tconstructor(\n\t\tstepId: string,\n\t\tcode: ErrorCode,\n\t\tmessage: string,\n\t\tpublic readonly rawOutput: unknown,\n\t\tcause?: unknown,\n\t) {\n\t\tsuper(stepId, code, \"output-quality\", message, cause);\n\t}\n}\n",
18
+ "import type { LanguageModel, ToolSet } from \"ai\";\nimport { generateText, stepCountIs, tool } from \"ai\";\nimport { type as arktype } from \"arktype\";\nimport { compileWorkflow } from \"../compiler\";\nimport type { Diagnostic } from \"../compiler/types\";\nimport type { WorkflowDefinition } from \"../types\";\nimport { workflowDefinitionSchema } from \"../types\";\nimport {\n\tbuildWorkflowGenerationPrompt,\n\tformatDiagnostics,\n\tserializeToolsForPrompt,\n} from \"./prompt\";\n\n// ─── Types ───────────────────────────────────────────────────────\n\nexport interface GenerateWorkflowOptions {\n\tmodel: LanguageModel;\n\ttools: ToolSet;\n\ttask: string;\n\tmaxRetries?: number;\n}\n\nexport interface GenerateWorkflowResult {\n\tworkflow: WorkflowDefinition | null;\n\tdiagnostics: Diagnostic[];\n\tattempts: number;\n}\n\nexport interface WorkflowGeneratorToolOptions {\n\tmodel: LanguageModel;\n\ttools?: ToolSet;\n\tmaxRetries?: number;\n}\n\n// ─── generateWorkflow ────────────────────────────────────────────\n\nexport async function generateWorkflow(\n\toptions: GenerateWorkflowOptions,\n): Promise<GenerateWorkflowResult> {\n\tconst { model, tools, task, maxRetries = 3 } = options;\n\n\tconst missingOutputSchema = Object.entries(tools)\n\t\t.filter(([_, t]) => !t.outputSchema)\n\t\t.map(([name]) => name);\n\tif (missingOutputSchema.length > 0) {\n\t\tthrow new Error(\n\t\t\t`All tools must have an outputSchema. Missing: ${missingOutputSchema.join(\", \")}`,\n\t\t);\n\t}\n\n\tconst serializedTools = await serializeToolsForPrompt(tools);\n\tconst systemPrompt = buildWorkflowGenerationPrompt(serializedTools);\n\n\tlet successWorkflow: WorkflowDefinition | null = null;\n\tlet lastDiagnostics: Diagnostic[] = [];\n\tlet attempts = 0;\n\n\tconst createWorkflowTool = tool({\n\t\tdescription: \"Create a workflow definition\",\n\t\tinputSchema: workflowDefinitionSchema,\n\t\texecute: async (workflowDef) => {\n\t\t\tattempts++;\n\t\t\tconst result = await compileWorkflow(workflowDef, { tools });\n\t\t\tlastDiagnostics = result.diagnostics;\n\n\t\t\tconst errors = result.diagnostics.filter((d) => d.severity === \"error\");\n\t\t\tif (errors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terrors: formatDiagnostics(result.diagnostics),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tsuccessWorkflow = result.workflow ?? workflowDef;\n\t\t\treturn { success: true };\n\t\t},\n\t});\n\n\tawait generateText({\n\t\tmodel,\n\t\tsystem: systemPrompt,\n\t\tprompt: `Create a workflow to accomplish the following task:\\n\\n${task}`,\n\t\ttools: { createWorkflow: createWorkflowTool },\n\t\ttoolChoice: { type: \"tool\", toolName: \"createWorkflow\" },\n\t\tstopWhen: [stepCountIs(maxRetries + 1), () => successWorkflow !== null],\n\t});\n\n\treturn {\n\t\tworkflow: successWorkflow,\n\t\tdiagnostics: lastDiagnostics,\n\t\tattempts,\n\t};\n}\n\n// ─── createWorkflowGeneratorTool ─────────────────────────────────\n\nexport function createWorkflowGeneratorTool(\n\toptions: WorkflowGeneratorToolOptions,\n) {\n\tconst { model, tools: baseTools, maxRetries } = options;\n\n\treturn tool({\n\t\tdescription:\n\t\t\t\"Generate a validated workflow definition from a natural language task description\",\n\t\tinputSchema: arktype({ task: \"string\" }),\n\t\texecute: async ({ task }) => {\n\t\t\treturn generateWorkflow({\n\t\t\t\tmodel,\n\t\t\t\ttools: baseTools ?? {},\n\t\t\t\ttask,\n\t\t\t\tmaxRetries,\n\t\t\t});\n\t\t},\n\t});\n}\n",
19
+ "import { type } from \"arktype\";\n\nconst expressionSchema = type({\n\ttype: \"'literal'\",\n\tvalue: \"unknown\",\n})\n\t.or({\n\t\ttype: \"'jmespath'\",\n\t\texpression: \"string\",\n\t})\n\t.describe(\n\t\t\"a value that must always be wrapped as an expression object — use { type: 'literal', value: ... } for any static value (strings, numbers, booleans, etc.), or { type: 'jmespath', expression: '...' } for dynamic data extracted from previous steps' outputs (via their step ids, e.g. `stepId.someKey`) or loop variables (e.g. `itemName.someKey` within a for-each loop body)\",\n\t);\n\nconst toolCallParamsSchema = type({\n\ttype: \"'tool-call'\",\n\tparams: {\n\t\ttoolName: \"string\",\n\t\ttoolInput: [\n\t\t\t{\n\t\t\t\t\"[string]\": expressionSchema,\n\t\t\t},\n\t\t\t\"@\",\n\t\t\t\"a map of input parameter names to their values; ALL values must be wrapped as expression objects — even static strings like email addresses must use { type: 'literal', value: '...' }, never plain primitives\",\n\t\t],\n\t},\n}).describe(\n\t\"a step that calls a tool with specified input parameters (which can be static values or expressions)\",\n);\n\nconst switchCaseParamsSchema = type({\n\ttype: \"'switch-case'\",\n\tparams: {\n\t\tswitchOn: expressionSchema,\n\t\tcases: [\n\t\t\t{\n\t\t\t\tvalue: expressionSchema.or({ type: \"'default'\" }),\n\t\t\t\tbranchBodyStepId: [\n\t\t\t\t\t\"string\",\n\t\t\t\t\t\"@\",\n\t\t\t\t\t\"the id of the first step in the branch body chain to execute if this case matches\",\n\t\t\t\t],\n\t\t\t},\n\t\t\t\"[]\",\n\t\t],\n\t},\n}).describe(\n\t\"a step that branches to different step chains based on the value of an expression; each case's chain runs until a step with no nextStepId, at which point execution continues with this step's nextStepId; a case with type 'default' serves as the fallback if no other case matches\",\n);\n\nconst forEachParamsSchema = type({\n\ttype: \"'for-each'\",\n\tparams: {\n\t\ttarget: expressionSchema,\n\t\titemName: [\n\t\t\t\"string\",\n\t\t\t\"@\",\n\t\t\t\"the name to refer to the current item in the list within expressions in the loop body\",\n\t\t],\n\t\tloopBodyStepId: [\n\t\t\t\"string\",\n\t\t\t\"@\",\n\t\t\t\"the id of the first step in the loop body chain to execute for each item in the list\",\n\t\t],\n\t},\n}).describe(\n\t\"a step that iterates over a list and executes a chain of steps for each item; the loop body chain runs until a step with no nextStepId, at which point the next iteration begins; once all items are exhausted, execution continues with this step's nextStepId\",\n);\n\nconst llmPromptSchema = type({\n\ttype: \"'llm-prompt'\",\n\tparams: {\n\t\tprompt: [\n\t\t\t\"string\",\n\t\t\t\"@\",\n\t\t\t\"a template string where JMESPath expressions can be embedded using ${...} syntax (e.g. 'Hello ${user.name}, you have ${length(user.messages)} messages'). All data from previous steps is available via their step ids (e.g. ${stepId.someKey}), and loop variables are available within for-each loop bodies (e.g. ${itemName.someKey})\",\n\t\t],\n\t\toutputFormat: [\n\t\t\t\"object\",\n\t\t\t\"@\",\n\t\t\t\"JSON schema specifying the output format expected from the LLM\",\n\t\t],\n\t},\n}).describe(\n\t\"a step that prompts an LLM with a text prompt to produce an output in a specified format\",\n);\n\nconst extractDataParamsSchema = type({\n\ttype: \"'extract-data'\",\n\tparams: {\n\t\tsourceData: [expressionSchema, \"@\", \"the data to extract information from\"],\n\t\toutputFormat: [\n\t\t\t\"object\",\n\t\t\t\"@\",\n\t\t\t\"JSON schema specifying the output format expected from the data extraction\",\n\t\t],\n\t},\n}).describe(\n\t\"a step that uses an LLM to extract structured data from a larger blob of source data (e.g. llm responses or tool outputs with unknown output formats) based on a specified output format\",\n);\n\nconst startParamsSchema = type({\n\ttype: \"'start'\",\n\tparams: {\n\t\tinputSchema: [\n\t\t\t\"object\",\n\t\t\t\"@\",\n\t\t\t\"a JSON Schema object defining the inputs required to run the workflow; the workflow executor will validate provided inputs against this schema, and the validated inputs become available in JMESPath scope via this step's id\",\n\t\t],\n\t},\n}).describe(\n\t\"a step that marks the entry point of a workflow and declares the input schema; its output is the validated input data, accessible by subsequent steps via its step id\",\n);\n\nconst endSchema = type({\n\ttype: \"'end'\",\n\t\"params?\": {\n\t\toutput: expressionSchema,\n\t},\n}).describe(\n\t\"a step that indicates the end of a branch; optionally specify an output expression whose evaluated value becomes the workflow's output\",\n);\n\nconst workflowStepSchema = type({\n\tid: /^[a-zA-Z_][a-zA-Z0-9_]+$/,\n\tname: \"string\",\n\tdescription: \"string\",\n\t\"nextStepId?\": \"string\",\n}).and(\n\ttoolCallParamsSchema\n\t\t.or(llmPromptSchema)\n\t\t.or(extractDataParamsSchema)\n\t\t.or(switchCaseParamsSchema)\n\t\t.or(forEachParamsSchema)\n\t\t.or(startParamsSchema)\n\t\t.or(endSchema),\n);\n\nexport const workflowDefinitionSchema = type({\n\tinitialStepId: \"string\",\n\t\"outputSchema?\": [\n\t\t\"object\",\n\t\t\"@\",\n\t\t\"an optional JSON Schema object declaring the shape of the workflow's output; when present, the value produced by the end step's output expression will be validated against this schema\",\n\t],\n\tsteps: [\n\t\t[workflowStepSchema, \"[]\"],\n\t\t\"@\",\n\t\t\"a list of steps to execute in the workflow; these should be in no particular order as execution flow is determined by the nextStepId fields and branching logic within the steps\",\n\t],\n});\n\nexport type WorkflowStep = typeof workflowStepSchema.infer;\nexport type WorkflowDefinition = typeof workflowDefinitionSchema.infer;\n",
20
+ "import { asSchema, type ToolSet } from \"ai\";\nimport type { Diagnostic } from \"../compiler/types\";\n\nexport async function serializeToolsForPrompt(tools: ToolSet): Promise<string> {\n\treturn JSON.stringify(\n\t\tawait Promise.all(\n\t\t\tObject.entries(tools).map(async ([toolName, toolDef]) => ({\n\t\t\t\tname: toolName,\n\t\t\t\tdescription: toolDef.description,\n\t\t\t\tinputSchema: await asSchema(toolDef.inputSchema).jsonSchema,\n\t\t\t\toutputSchema: toolDef.outputSchema\n\t\t\t\t\t? await asSchema(toolDef.outputSchema).jsonSchema\n\t\t\t\t\t: undefined,\n\t\t\t})),\n\t\t),\n\t);\n}\n\nexport function buildWorkflowGenerationPrompt(serializedTools: string): string {\n\treturn `You are a workflow architect. Your job is to design a workflow definition in the remora DSL that accomplishes a given task using the provided tools. You MUST call the createWorkflow tool with a valid workflow definition.\n\n## Workflow Structure\n\nA workflow has:\n- \\`initialStepId\\`: the id of the first step to execute\n- \\`steps\\`: an array of step objects (order does not matter — execution flow is determined by nextStepId links)\n- \\`outputSchema\\` (optional): a JSON Schema object declaring the shape of the workflow's output. When present, every \\`end\\` step should have an \\`output\\` expression that evaluates to a value matching this schema.\n\n## Step Common Fields\n\nEvery step has:\n- \\`id\\`: unique identifier matching /^[a-zA-Z_][a-zA-Z0-9_]+$/ (letters, digits, underscores; at least 2 characters)\n- \\`name\\`: human-readable name\n- \\`description\\`: what this step does\n- \\`type\\`: one of the step types below\n- \\`nextStepId\\` (optional): id of the next step to execute after this one\n\n## Step Types\n\n### start\nEntry point that declares and validates workflow inputs. Its output (the validated inputs) is accessible by subsequent steps via its step id.\n\\`\\`\\`json\n{\n \"type\": \"start\",\n \"params\": {\n \"inputSchema\": { \"type\": \"object\", \"properties\": { ... }, \"required\": [...] }\n }\n}\n\\`\\`\\`\n\n### tool-call\nCalls a tool with input parameters. All values in toolInput MUST be expression objects.\n\\`\\`\\`json\n{\n \"type\": \"tool-call\",\n \"params\": {\n \"toolName\": \"name-of-tool\",\n \"toolInput\": {\n \"paramName\": { \"type\": \"literal\", \"value\": \"static value\" },\n \"otherParam\": { \"type\": \"jmespath\", \"expression\": \"previous_step.someField\" }\n }\n }\n}\n\\`\\`\\`\n\n### llm-prompt\nPrompts an LLM with a template string to produce structured output. Use \\${...} syntax to embed JMESPath expressions in the prompt.\n\\`\\`\\`json\n{\n \"type\": \"llm-prompt\",\n \"params\": {\n \"prompt\": \"Classify this ticket: \\${get_tickets.tickets[0].subject}\",\n \"outputFormat\": { \"type\": \"object\", \"properties\": { \"category\": { \"type\": \"string\" } }, \"required\": [\"category\"] }\n }\n}\n\\`\\`\\`\n\n### extract-data\nUses an LLM to extract structured data from a source. Use when you need to parse unstructured or semi-structured data into a known shape.\n\\`\\`\\`json\n{\n \"type\": \"extract-data\",\n \"params\": {\n \"sourceData\": { \"type\": \"jmespath\", \"expression\": \"previous_step.rawContent\" },\n \"outputFormat\": { \"type\": \"object\", \"properties\": { ... }, \"required\": [...] }\n }\n}\n\\`\\`\\`\n\n### switch-case\nBranches execution based on a value. Each case's branch chain runs until a step with no nextStepId, then execution continues with this step's nextStepId. Use \\`{ \"type\": \"default\" }\\` for a fallback case.\n\\`\\`\\`json\n{\n \"type\": \"switch-case\",\n \"params\": {\n \"switchOn\": { \"type\": \"jmespath\", \"expression\": \"classify.category\" },\n \"cases\": [\n {\n \"value\": { \"type\": \"literal\", \"value\": \"critical\" },\n \"branchBodyStepId\": \"handle_critical\"\n },\n {\n \"value\": { \"type\": \"default\" },\n \"branchBodyStepId\": \"handle_other\"\n }\n ]\n }\n}\n\\`\\`\\`\n\n### for-each\nIterates over a list and executes a chain of steps for each item. The loop body chain runs until a step with no nextStepId, then the next iteration begins. After all items, execution continues with this step's nextStepId. The \\`itemName\\` becomes a scoped variable accessible only within the loop body.\n\\`\\`\\`json\n{\n \"type\": \"for-each\",\n \"params\": {\n \"target\": { \"type\": \"jmespath\", \"expression\": \"get_items.items\" },\n \"itemName\": \"item\",\n \"loopBodyStepId\": \"process_item\"\n }\n}\n\\`\\`\\`\n\n### end\nMarks the end of a branch or the workflow. Must NOT have a nextStepId. Optionally, specify an output expression whose value becomes the workflow's return value.\n\\`\\`\\`json\n{\n \"type\": \"end\"\n}\n\\`\\`\\`\n\nWith output (when the workflow declares an outputSchema):\n\\`\\`\\`json\n{\n \"type\": \"end\",\n \"params\": {\n \"output\": { \"type\": \"jmespath\", \"expression\": \"summarize.result\" }\n }\n}\n\\`\\`\\`\n\n## Expression System\n\nEvery dynamic value must be an expression object:\n\n1. **Literal** — for static values known at design time:\n \\`{ \"type\": \"literal\", \"value\": <any value> }\\`\n\n2. **JMESPath** — for referencing data from previous steps or loop variables:\n \\`{ \"type\": \"jmespath\", \"expression\": \"<expression>\" }\\`\n The root of a JMESPath expression must be either a step id (e.g. \\`get_orders.orders\\`) or a loop variable name (e.g. \\`item.id\\` within a for-each body).\n\n3. **Template strings** (llm-prompt only) — embed JMESPath in the prompt string using \\${...}:\n \\`\"Summarize: \\${fetch_data.content}\"\\`\n These are NOT expression objects — they appear directly in the prompt string.\n\n## Structural Rules\n\n1. Step IDs must be unique and match /^[a-zA-Z_][a-zA-Z0-9_]+$/.\n2. Steps link via nextStepId. Omitting nextStepId ends the chain.\n3. Branch body chains (switch-case) and loop body chains (for-each) must terminate — their last step must NOT have a nextStepId. Do NOT point them back to the parent or outside the body.\n4. Only reference step IDs of steps that will have executed before the current step (no forward references).\n5. Do not create cycles (for-each handles iteration — you do not need to loop manually).\n6. end steps must NOT have a nextStepId.\n\n## Available Tools\n\nEach tool below includes an \\`outputSchema\\` describing the shape of its return value. Use the output schema to construct correct JMESPath expressions. For example, if a tool returns \\`{ \"type\": \"object\", \"properties\": { \"orders\": { \"type\": \"array\", ... } } }\\`, reference the array as \\`step_id.orders\\`, not \\`step_id\\` alone.\n\n${serializedTools}\n\n## Common Mistakes\n\n1. NEVER use bare primitives in toolInput. ALL values must be expression objects.\n WRONG: \\`{ \"email\": \"user@example.com\" }\\`\n RIGHT: \\`{ \"email\": { \"type\": \"literal\", \"value\": \"user@example.com\" } }\\`\n\n2. Do NOT give end steps a nextStepId.\n\n3. Branch/loop body chains must terminate (last step has no nextStepId). Do NOT point them outside their scope.\n\n4. JMESPath expressions reference step outputs by step ID as the root identifier. Example: \\`\"get_orders.orders[0].id\"\\` means step \"get_orders\" → its output → .orders[0].id\n\n5. For-each itemName is a scoped variable accessible ONLY within the loop body steps.\n\n6. Step IDs must be at least 2 characters long.\n\n7. for-each target must resolve to an ARRAY. Check the tool's outputSchema to determine the correct path.\n WRONG: \\`\"target\": { \"type\": \"jmespath\", \"expression\": \"get_orders\" }\\` (when get_orders returns an object with an \\`orders\\` array property)\n RIGHT: \\`\"target\": { \"type\": \"jmespath\", \"expression\": \"get_orders.orders\" }\\`\n\n8. If the workflow needs to return structured data, declare an \\`outputSchema\\` on the workflow and give every \\`end\\` step an \\`output\\` expression that evaluates to a value matching it.`;\n}\n\nexport function formatDiagnostics(diagnostics: Diagnostic[]): string {\n\tconst errors = diagnostics.filter((d) => d.severity === \"error\");\n\tif (errors.length === 0) return \"No errors.\";\n\treturn errors\n\t\t.map((d) => {\n\t\t\tconst loc = d.location\n\t\t\t\t? ` (at step ${d.location.stepId}${d.location.field ? `, field ${d.location.field}` : \"\"})`\n\t\t\t\t: \"\";\n\t\t\treturn `- [${d.code}] ${d.message}${loc}`;\n\t\t})\n\t\t.join(\"\\n\");\n}\n"
21
+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AAE,aAAa,OAAO;AAAA,MACtE,IAAI,OAAO,SAAS,GAAG;AAAA,QACtB,OAAO;AAAA,UACN,SAAS;AAAA,UACT,QAAQ,kBAAkB,OAAO,WAAW;AAAA,QAC7C;AAAA,MACD;AAAA,MAEA,kBAAkB,OAAO,YAAY;AAAA,MACrC,OAAO,EAAE,SAAS,KAAK;AAAA;AAAA,EAEzB,CAAC;AAAA,EAED,MAAM,aAAa;AAAA,IAClB;AAAA,IACA,QAAQ;AAAA,IACR,QAAQ;AAAA;AAAA,EAA0D;AAAA,IAClE,OAAO,EAAE,gBAAgB,mBAAmB;AAAA,IAC5C,YAAY,EAAE,MAAM,QAAQ,UAAU,iBAAiB;AAAA,IACvD,UAAU,CAAC,aAAY,aAAa,CAAC,GAAG,MAAM,oBAAoB,IAAI;AAAA,EACvE,CAAC;AAAA,EAED,OAAO;AAAA,IACN,UAAU;AAAA,IACV,aAAa;AAAA,IACb;AAAA,EACD;AAAA;AAKM,SAAS,2BAA2B,CAC1C,SACC;AAAA,EACD,QAAQ,OAAO,OAAO,WAAW,eAAe;AAAA,EAEhD,OAAO,KAAK;AAAA,IACX,aACC;AAAA,IACD,aAAa,QAAQ,EAAE,MAAM,SAAS,CAAC;AAAA,IACvC,SAAS,SAAS,WAAW;AAAA,MAC5B,OAAO,iBAAiB;AAAA,QACvB;AAAA,QACA,OAAO,aAAa,CAAC;AAAA,QACrB;AAAA,QACA;AAAA,MACD,CAAC;AAAA;AAAA,EAEH,CAAC;AAAA;",
23
+ "debugId": "DD448656596BC50E64756E2164756E21",
24
+ "names": []
25
+ }
@@ -0,0 +1,234 @@
1
+ declare const workflowStepSchema: import("arktype/internal/variants/object.ts").ObjectType<{
2
+ id: string;
3
+ name: string;
4
+ description: string;
5
+ nextStepId?: string | undefined;
6
+ type: "tool-call";
7
+ params: {
8
+ toolName: string;
9
+ toolInput: {
10
+ [x: string]: {
11
+ type: "literal";
12
+ value: unknown;
13
+ } | {
14
+ type: "jmespath";
15
+ expression: string;
16
+ };
17
+ };
18
+ };
19
+ } | {
20
+ id: string;
21
+ name: string;
22
+ description: string;
23
+ nextStepId?: string | undefined;
24
+ type: "switch-case";
25
+ params: {
26
+ switchOn: {
27
+ type: "literal";
28
+ value: unknown;
29
+ } | {
30
+ type: "jmespath";
31
+ expression: string;
32
+ };
33
+ cases: {
34
+ value: {
35
+ type: "literal";
36
+ value: unknown;
37
+ } | {
38
+ type: "jmespath";
39
+ expression: string;
40
+ } | {
41
+ type: "default";
42
+ };
43
+ branchBodyStepId: string;
44
+ }[];
45
+ };
46
+ } | {
47
+ id: string;
48
+ name: string;
49
+ description: string;
50
+ nextStepId?: string | undefined;
51
+ type: "for-each";
52
+ params: {
53
+ target: {
54
+ type: "literal";
55
+ value: unknown;
56
+ } | {
57
+ type: "jmespath";
58
+ expression: string;
59
+ };
60
+ itemName: string;
61
+ loopBodyStepId: string;
62
+ };
63
+ } | {
64
+ id: string;
65
+ name: string;
66
+ description: string;
67
+ nextStepId?: string | undefined;
68
+ type: "llm-prompt";
69
+ params: {
70
+ prompt: string;
71
+ outputFormat: object;
72
+ };
73
+ } | {
74
+ id: string;
75
+ name: string;
76
+ description: string;
77
+ nextStepId?: string | undefined;
78
+ type: "extract-data";
79
+ params: {
80
+ sourceData: {
81
+ type: "literal";
82
+ value: unknown;
83
+ } | {
84
+ type: "jmespath";
85
+ expression: string;
86
+ };
87
+ outputFormat: object;
88
+ };
89
+ } | {
90
+ id: string;
91
+ name: string;
92
+ description: string;
93
+ nextStepId?: string | undefined;
94
+ type: "start";
95
+ params: {
96
+ inputSchema: object;
97
+ };
98
+ } | {
99
+ id: string;
100
+ name: string;
101
+ description: string;
102
+ nextStepId?: string | undefined;
103
+ type: "end";
104
+ params?: {
105
+ output: {
106
+ type: "literal";
107
+ value: unknown;
108
+ } | {
109
+ type: "jmespath";
110
+ expression: string;
111
+ };
112
+ } | undefined;
113
+ }, {}>;
114
+ export declare const workflowDefinitionSchema: import("arktype/internal/variants/object.ts").ObjectType<{
115
+ initialStepId: string;
116
+ steps: ({
117
+ id: string;
118
+ name: string;
119
+ description: string;
120
+ nextStepId?: string | undefined;
121
+ type: "tool-call";
122
+ params: {
123
+ toolName: string;
124
+ toolInput: {
125
+ [x: string]: {
126
+ type: "literal";
127
+ value: unknown;
128
+ } | {
129
+ type: "jmespath";
130
+ expression: string;
131
+ };
132
+ };
133
+ };
134
+ } | {
135
+ id: string;
136
+ name: string;
137
+ description: string;
138
+ nextStepId?: string | undefined;
139
+ type: "switch-case";
140
+ params: {
141
+ switchOn: {
142
+ type: "literal";
143
+ value: unknown;
144
+ } | {
145
+ type: "jmespath";
146
+ expression: string;
147
+ };
148
+ cases: {
149
+ value: {
150
+ type: "literal";
151
+ value: unknown;
152
+ } | {
153
+ type: "jmespath";
154
+ expression: string;
155
+ } | {
156
+ type: "default";
157
+ };
158
+ branchBodyStepId: string;
159
+ }[];
160
+ };
161
+ } | {
162
+ id: string;
163
+ name: string;
164
+ description: string;
165
+ nextStepId?: string | undefined;
166
+ type: "for-each";
167
+ params: {
168
+ target: {
169
+ type: "literal";
170
+ value: unknown;
171
+ } | {
172
+ type: "jmespath";
173
+ expression: string;
174
+ };
175
+ itemName: string;
176
+ loopBodyStepId: string;
177
+ };
178
+ } | {
179
+ id: string;
180
+ name: string;
181
+ description: string;
182
+ nextStepId?: string | undefined;
183
+ type: "llm-prompt";
184
+ params: {
185
+ prompt: string;
186
+ outputFormat: object;
187
+ };
188
+ } | {
189
+ id: string;
190
+ name: string;
191
+ description: string;
192
+ nextStepId?: string | undefined;
193
+ type: "extract-data";
194
+ params: {
195
+ sourceData: {
196
+ type: "literal";
197
+ value: unknown;
198
+ } | {
199
+ type: "jmespath";
200
+ expression: string;
201
+ };
202
+ outputFormat: object;
203
+ };
204
+ } | {
205
+ id: string;
206
+ name: string;
207
+ description: string;
208
+ nextStepId?: string | undefined;
209
+ type: "start";
210
+ params: {
211
+ inputSchema: object;
212
+ };
213
+ } | {
214
+ id: string;
215
+ name: string;
216
+ description: string;
217
+ nextStepId?: string | undefined;
218
+ type: "end";
219
+ params?: {
220
+ output: {
221
+ type: "literal";
222
+ value: unknown;
223
+ } | {
224
+ type: "jmespath";
225
+ expression: string;
226
+ };
227
+ } | undefined;
228
+ })[];
229
+ outputSchema?: object | undefined;
230
+ }, {}>;
231
+ export type WorkflowStep = typeof workflowStepSchema.infer;
232
+ export type WorkflowDefinition = typeof workflowDefinitionSchema.infer;
233
+ export {};
234
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA2HA,QAAA,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAavB,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAYnC,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,OAAO,kBAAkB,CAAC,KAAK,CAAC;AAC3D,MAAM,MAAM,kBAAkB,GAAG,OAAO,wBAAwB,CAAC,KAAK,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type EdgeProps } from "@xyflow/react";
2
+ export declare function WorkflowEdge({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, label, data, markerEnd, style, }: EdgeProps): import("react/jsx-runtime").JSX.Element;
3
+ //# sourceMappingURL=workflow-edge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-edge.d.ts","sourceRoot":"","sources":["../../../src/viewer/edges/workflow-edge.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,SAAS,EAEd,MAAM,eAAe,CAAC;AAEvB,wBAAgB,YAAY,CAAC,EAC5B,EAAE,EACF,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,cAAc,EACd,cAAc,EACd,KAAK,EACL,IAAI,EACJ,SAAS,EACT,KAAK,GACL,EAAE,SAAS,2CA2CX"}
@@ -0,0 +1,13 @@
1
+ import type { Edge, Node } from "@xyflow/react";
2
+ import type { Diagnostic } from "../compiler/types";
3
+ import type { WorkflowDefinition, WorkflowStep } from "../types";
4
+ export interface StepNodeData {
5
+ step: WorkflowStep;
6
+ diagnostics: Diagnostic[];
7
+ hasSourceEdge?: boolean;
8
+ }
9
+ export declare function buildLayout(workflow: WorkflowDefinition, diagnostics?: Diagnostic[]): {
10
+ nodes: Node[];
11
+ edges: Edge[];
12
+ };
13
+ //# sourceMappingURL=graph-layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-layout.d.ts","sourceRoot":"","sources":["../../src/viewer/graph-layout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEjE,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AA2KD,wBAAgB,WAAW,CAC1B,QAAQ,EAAE,kBAAkB,EAC5B,WAAW,GAAE,UAAU,EAAO,GAC5B;IAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAAC,KAAK,EAAE,IAAI,EAAE,CAAA;CAAE,CAuZlC"}
@@ -0,0 +1,5 @@
1
+ export type { StepNodeData } from "./graph-layout";
2
+ export { buildLayout } from "./graph-layout";
3
+ export type { WorkflowViewerProps } from "./workflow-viewer";
4
+ export { WorkflowViewer } from "./workflow-viewer";
5
+ //# sourceMappingURL=index.d.ts.map