@synergenius/flow-weaver 0.2.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 (466) hide show
  1. package/LICENSE +122 -0
  2. package/README.md +315 -0
  3. package/dist/annotation-generator.d.ts +45 -0
  4. package/dist/annotation-generator.js +557 -0
  5. package/dist/api/builder.d.ts +223 -0
  6. package/dist/api/builder.js +345 -0
  7. package/dist/api/compile.d.ts +92 -0
  8. package/dist/api/compile.js +149 -0
  9. package/dist/api/extract-types.d.ts +29 -0
  10. package/dist/api/extract-types.js +57 -0
  11. package/dist/api/generate-in-place.d.ts +73 -0
  12. package/dist/api/generate-in-place.js +1353 -0
  13. package/dist/api/generate.d.ts +83 -0
  14. package/dist/api/generate.js +510 -0
  15. package/dist/api/helpers.d.ts +248 -0
  16. package/dist/api/helpers.js +285 -0
  17. package/dist/api/index.d.ts +46 -0
  18. package/dist/api/index.js +45 -0
  19. package/dist/api/inline-runtime.d.ts +27 -0
  20. package/dist/api/inline-runtime.js +551 -0
  21. package/dist/api/manipulation/connections.d.ts +79 -0
  22. package/dist/api/manipulation/connections.js +151 -0
  23. package/dist/api/manipulation/index.d.ts +34 -0
  24. package/dist/api/manipulation/index.js +41 -0
  25. package/dist/api/manipulation/node-types.d.ts +123 -0
  26. package/dist/api/manipulation/node-types.js +200 -0
  27. package/dist/api/manipulation/nodes.d.ts +144 -0
  28. package/dist/api/manipulation/nodes.js +333 -0
  29. package/dist/api/manipulation/ports.d.ts +59 -0
  30. package/dist/api/manipulation/ports.js +228 -0
  31. package/dist/api/manipulation/scopes.d.ts +52 -0
  32. package/dist/api/manipulation/scopes.js +156 -0
  33. package/dist/api/manipulation/validation.d.ts +6 -0
  34. package/dist/api/manipulation/validation.js +6 -0
  35. package/dist/api/manipulation/workflow.d.ts +81 -0
  36. package/dist/api/manipulation/workflow.js +116 -0
  37. package/dist/api/manipulation.d.ts +8 -0
  38. package/dist/api/manipulation.js +8 -0
  39. package/dist/api/parse.d.ts +48 -0
  40. package/dist/api/parse.js +110 -0
  41. package/dist/api/patterns.d.ts +112 -0
  42. package/dist/api/patterns.js +306 -0
  43. package/dist/api/query.d.ts +429 -0
  44. package/dist/api/query.js +816 -0
  45. package/dist/api/templates.d.ts +98 -0
  46. package/dist/api/templates.js +117 -0
  47. package/dist/api/transform.d.ts +31 -0
  48. package/dist/api/transform.js +40 -0
  49. package/dist/api/validate.d.ts +25 -0
  50. package/dist/api/validate.js +39 -0
  51. package/dist/api/workflow-file-operations.d.ts +29 -0
  52. package/dist/api/workflow-file-operations.js +180 -0
  53. package/dist/ast/builder.d.ts +210 -0
  54. package/dist/ast/builder.js +395 -0
  55. package/dist/ast/index.d.ts +5 -0
  56. package/dist/ast/index.js +5 -0
  57. package/dist/ast/serialization-node.d.ts +6 -0
  58. package/dist/ast/serialization-node.js +30 -0
  59. package/dist/ast/serialization.d.ts +43 -0
  60. package/dist/ast/serialization.js +134 -0
  61. package/dist/ast/types.d.ts +852 -0
  62. package/dist/ast/types.js +2 -0
  63. package/dist/ast/workflow-utils.d.ts +54 -0
  64. package/dist/ast/workflow-utils.js +114 -0
  65. package/dist/body-generator.d.ts +31 -0
  66. package/dist/body-generator.js +35 -0
  67. package/dist/built-in-nodes/delay.d.ts +11 -0
  68. package/dist/built-in-nodes/delay.js +29 -0
  69. package/dist/built-in-nodes/index.d.ts +5 -0
  70. package/dist/built-in-nodes/index.js +4 -0
  71. package/dist/built-in-nodes/invoke-workflow.d.ts +13 -0
  72. package/dist/built-in-nodes/invoke-workflow.js +25 -0
  73. package/dist/built-in-nodes/mock-types.d.ts +18 -0
  74. package/dist/built-in-nodes/mock-types.js +12 -0
  75. package/dist/built-in-nodes/wait-for-event.d.ts +13 -0
  76. package/dist/built-in-nodes/wait-for-event.js +25 -0
  77. package/dist/chevrotain-parser/connect-parser.d.ts +24 -0
  78. package/dist/chevrotain-parser/connect-parser.js +98 -0
  79. package/dist/chevrotain-parser/grammar-diagrams.d.ts +29 -0
  80. package/dist/chevrotain-parser/grammar-diagrams.js +264 -0
  81. package/dist/chevrotain-parser/index.d.ts +25 -0
  82. package/dist/chevrotain-parser/index.js +27 -0
  83. package/dist/chevrotain-parser/map-parser.d.ts +33 -0
  84. package/dist/chevrotain-parser/map-parser.js +130 -0
  85. package/dist/chevrotain-parser/node-parser.d.ts +36 -0
  86. package/dist/chevrotain-parser/node-parser.js +466 -0
  87. package/dist/chevrotain-parser/path-parser.d.ts +28 -0
  88. package/dist/chevrotain-parser/path-parser.js +118 -0
  89. package/dist/chevrotain-parser/port-parser.d.ts +36 -0
  90. package/dist/chevrotain-parser/port-parser.js +442 -0
  91. package/dist/chevrotain-parser/position-parser.d.ts +20 -0
  92. package/dist/chevrotain-parser/position-parser.js +83 -0
  93. package/dist/chevrotain-parser/scope-parser.d.ts +19 -0
  94. package/dist/chevrotain-parser/scope-parser.js +104 -0
  95. package/dist/chevrotain-parser/tokens.d.ts +78 -0
  96. package/dist/chevrotain-parser/tokens.js +384 -0
  97. package/dist/chevrotain-parser/trigger-cancel-parser.d.ts +50 -0
  98. package/dist/chevrotain-parser/trigger-cancel-parser.js +282 -0
  99. package/dist/cli/commands/changelog.d.ts +13 -0
  100. package/dist/cli/commands/changelog.js +135 -0
  101. package/dist/cli/commands/compile.d.ts +64 -0
  102. package/dist/cli/commands/compile.js +278 -0
  103. package/dist/cli/commands/create.d.ts +33 -0
  104. package/dist/cli/commands/create.js +147 -0
  105. package/dist/cli/commands/describe.d.ts +68 -0
  106. package/dist/cli/commands/describe.js +377 -0
  107. package/dist/cli/commands/dev.d.ts +32 -0
  108. package/dist/cli/commands/dev.js +384 -0
  109. package/dist/cli/commands/diagram.d.ts +13 -0
  110. package/dist/cli/commands/diagram.js +33 -0
  111. package/dist/cli/commands/diff.d.ts +11 -0
  112. package/dist/cli/commands/diff.js +59 -0
  113. package/dist/cli/commands/doctor.d.ts +57 -0
  114. package/dist/cli/commands/doctor.js +719 -0
  115. package/dist/cli/commands/export.d.ts +57 -0
  116. package/dist/cli/commands/export.js +163 -0
  117. package/dist/cli/commands/grammar.d.ts +9 -0
  118. package/dist/cli/commands/grammar.js +39 -0
  119. package/dist/cli/commands/init.d.ts +59 -0
  120. package/dist/cli/commands/init.js +435 -0
  121. package/dist/cli/commands/listen.d.ts +16 -0
  122. package/dist/cli/commands/listen.js +39 -0
  123. package/dist/cli/commands/market.d.ts +52 -0
  124. package/dist/cli/commands/market.js +436 -0
  125. package/dist/cli/commands/migrate.d.ts +13 -0
  126. package/dist/cli/commands/migrate.js +89 -0
  127. package/dist/cli/commands/openapi.d.ts +37 -0
  128. package/dist/cli/commands/openapi.js +67 -0
  129. package/dist/cli/commands/pattern.d.ts +34 -0
  130. package/dist/cli/commands/pattern.js +185 -0
  131. package/dist/cli/commands/plugin.d.ts +16 -0
  132. package/dist/cli/commands/plugin.js +176 -0
  133. package/dist/cli/commands/run.d.ts +49 -0
  134. package/dist/cli/commands/run.js +191 -0
  135. package/dist/cli/commands/serve.d.ts +45 -0
  136. package/dist/cli/commands/serve.js +81 -0
  137. package/dist/cli/commands/templates.d.ts +8 -0
  138. package/dist/cli/commands/templates.js +54 -0
  139. package/dist/cli/commands/ui.d.ts +16 -0
  140. package/dist/cli/commands/ui.js +130 -0
  141. package/dist/cli/commands/validate.d.ts +12 -0
  142. package/dist/cli/commands/validate.js +247 -0
  143. package/dist/cli/commands/watch.d.ts +9 -0
  144. package/dist/cli/commands/watch.js +70 -0
  145. package/dist/cli/flow-weaver.mjs +92924 -0
  146. package/dist/cli/index.d.ts +9 -0
  147. package/dist/cli/index.js +742 -0
  148. package/dist/cli/templates/ai/mock-provider.d.ts +7 -0
  149. package/dist/cli/templates/ai/mock-provider.js +64 -0
  150. package/dist/cli/templates/ai/types.d.ts +47 -0
  151. package/dist/cli/templates/ai/types.js +5 -0
  152. package/dist/cli/templates/approvals/index.d.ts +15 -0
  153. package/dist/cli/templates/approvals/index.js +241 -0
  154. package/dist/cli/templates/index.d.ts +102 -0
  155. package/dist/cli/templates/index.js +101 -0
  156. package/dist/cli/templates/nodes/agent-router.d.ts +3 -0
  157. package/dist/cli/templates/nodes/agent-router.js +114 -0
  158. package/dist/cli/templates/nodes/aggregator.d.ts +7 -0
  159. package/dist/cli/templates/nodes/aggregator.js +63 -0
  160. package/dist/cli/templates/nodes/conversation-memory.d.ts +3 -0
  161. package/dist/cli/templates/nodes/conversation-memory.js +85 -0
  162. package/dist/cli/templates/nodes/http.d.ts +7 -0
  163. package/dist/cli/templates/nodes/http.js +80 -0
  164. package/dist/cli/templates/nodes/human-approval.d.ts +3 -0
  165. package/dist/cli/templates/nodes/human-approval.js +110 -0
  166. package/dist/cli/templates/nodes/json-extractor.d.ts +3 -0
  167. package/dist/cli/templates/nodes/json-extractor.js +119 -0
  168. package/dist/cli/templates/nodes/llm-call.d.ts +3 -0
  169. package/dist/cli/templates/nodes/llm-call.js +106 -0
  170. package/dist/cli/templates/nodes/prompt-template.d.ts +3 -0
  171. package/dist/cli/templates/nodes/prompt-template.js +52 -0
  172. package/dist/cli/templates/nodes/rag-retriever.d.ts +3 -0
  173. package/dist/cli/templates/nodes/rag-retriever.js +128 -0
  174. package/dist/cli/templates/nodes/tool-executor.d.ts +3 -0
  175. package/dist/cli/templates/nodes/tool-executor.js +108 -0
  176. package/dist/cli/templates/nodes/transformer.d.ts +7 -0
  177. package/dist/cli/templates/nodes/transformer.js +68 -0
  178. package/dist/cli/templates/nodes/validator.d.ts +7 -0
  179. package/dist/cli/templates/nodes/validator.js +62 -0
  180. package/dist/cli/templates/providers/index.d.ts +14 -0
  181. package/dist/cli/templates/providers/index.js +239 -0
  182. package/dist/cli/templates/shared/approval-types.d.ts +9 -0
  183. package/dist/cli/templates/shared/approval-types.js +31 -0
  184. package/dist/cli/templates/shared/llm-types.d.ts +15 -0
  185. package/dist/cli/templates/shared/llm-types.js +104 -0
  186. package/dist/cli/templates/workflows/aggregator.d.ts +7 -0
  187. package/dist/cli/templates/workflows/aggregator.js +104 -0
  188. package/dist/cli/templates/workflows/ai-agent-durable.d.ts +8 -0
  189. package/dist/cli/templates/workflows/ai-agent-durable.js +338 -0
  190. package/dist/cli/templates/workflows/ai-agent.d.ts +31 -0
  191. package/dist/cli/templates/workflows/ai-agent.js +326 -0
  192. package/dist/cli/templates/workflows/ai-chat.d.ts +7 -0
  193. package/dist/cli/templates/workflows/ai-chat.js +169 -0
  194. package/dist/cli/templates/workflows/ai-pipeline-durable.d.ts +8 -0
  195. package/dist/cli/templates/workflows/ai-pipeline-durable.js +330 -0
  196. package/dist/cli/templates/workflows/ai-rag.d.ts +7 -0
  197. package/dist/cli/templates/workflows/ai-rag.js +186 -0
  198. package/dist/cli/templates/workflows/ai-react.d.ts +7 -0
  199. package/dist/cli/templates/workflows/ai-react.js +294 -0
  200. package/dist/cli/templates/workflows/conditional.d.ts +12 -0
  201. package/dist/cli/templates/workflows/conditional.js +142 -0
  202. package/dist/cli/templates/workflows/error-handler.d.ts +7 -0
  203. package/dist/cli/templates/workflows/error-handler.js +147 -0
  204. package/dist/cli/templates/workflows/foreach.d.ts +7 -0
  205. package/dist/cli/templates/workflows/foreach.js +143 -0
  206. package/dist/cli/templates/workflows/sequential.d.ts +7 -0
  207. package/dist/cli/templates/workflows/sequential.js +198 -0
  208. package/dist/cli/templates/workflows/webhook.d.ts +7 -0
  209. package/dist/cli/templates/workflows/webhook.js +161 -0
  210. package/dist/cli/utils/logger.d.ts +15 -0
  211. package/dist/cli/utils/logger.js +46 -0
  212. package/dist/constants.d.ts +100 -0
  213. package/dist/constants.js +125 -0
  214. package/dist/defaults.d.ts +3 -0
  215. package/dist/defaults.js +3 -0
  216. package/dist/deployment/config/defaults.d.ts +29 -0
  217. package/dist/deployment/config/defaults.js +98 -0
  218. package/dist/deployment/config/loader.d.ts +24 -0
  219. package/dist/deployment/config/loader.js +236 -0
  220. package/dist/deployment/config/types.d.ts +117 -0
  221. package/dist/deployment/config/types.js +5 -0
  222. package/dist/deployment/core/adapters.d.ts +90 -0
  223. package/dist/deployment/core/adapters.js +251 -0
  224. package/dist/deployment/core/executor.d.ts +62 -0
  225. package/dist/deployment/core/executor.js +197 -0
  226. package/dist/deployment/core/formatters.d.ts +57 -0
  227. package/dist/deployment/core/formatters.js +170 -0
  228. package/dist/deployment/index.d.ts +31 -0
  229. package/dist/deployment/index.js +48 -0
  230. package/dist/deployment/openapi/generator.d.ts +146 -0
  231. package/dist/deployment/openapi/generator.js +347 -0
  232. package/dist/deployment/openapi/schema-converter.d.ts +49 -0
  233. package/dist/deployment/openapi/schema-converter.js +192 -0
  234. package/dist/deployment/targets/base.d.ts +316 -0
  235. package/dist/deployment/targets/base.js +823 -0
  236. package/dist/deployment/targets/cloudflare.d.ts +23 -0
  237. package/dist/deployment/targets/cloudflare.js +1125 -0
  238. package/dist/deployment/targets/inngest.d.ts +38 -0
  239. package/dist/deployment/targets/inngest.js +926 -0
  240. package/dist/deployment/targets/lambda.d.ts +23 -0
  241. package/dist/deployment/targets/lambda.js +1289 -0
  242. package/dist/deployment/targets/vercel.d.ts +23 -0
  243. package/dist/deployment/targets/vercel.js +886 -0
  244. package/dist/deployment/types.d.ts +183 -0
  245. package/dist/deployment/types.js +8 -0
  246. package/dist/diagram/geometry.d.ts +26 -0
  247. package/dist/diagram/geometry.js +850 -0
  248. package/dist/diagram/index.d.ts +16 -0
  249. package/dist/diagram/index.js +42 -0
  250. package/dist/diagram/layout.d.ts +11 -0
  251. package/dist/diagram/layout.js +143 -0
  252. package/dist/diagram/orthogonal-router.d.ts +79 -0
  253. package/dist/diagram/orthogonal-router.js +568 -0
  254. package/dist/diagram/renderer.d.ts +3 -0
  255. package/dist/diagram/renderer.js +207 -0
  256. package/dist/diagram/theme.d.ts +20 -0
  257. package/dist/diagram/theme.js +189 -0
  258. package/dist/diagram/types.d.ts +70 -0
  259. package/dist/diagram/types.js +2 -0
  260. package/dist/diff/WorkflowDiffer.d.ts +13 -0
  261. package/dist/diff/WorkflowDiffer.js +429 -0
  262. package/dist/diff/formatDiff.d.ts +10 -0
  263. package/dist/diff/formatDiff.js +220 -0
  264. package/dist/diff/impact.d.ts +29 -0
  265. package/dist/diff/impact.js +119 -0
  266. package/dist/diff/index.d.ts +10 -0
  267. package/dist/diff/index.js +9 -0
  268. package/dist/diff/types.d.ts +138 -0
  269. package/dist/diff/types.js +35 -0
  270. package/dist/doc-metadata/extractors/annotations.d.ts +56 -0
  271. package/dist/doc-metadata/extractors/annotations.js +337 -0
  272. package/dist/doc-metadata/extractors/cli-commands.d.ts +17 -0
  273. package/dist/doc-metadata/extractors/cli-commands.js +355 -0
  274. package/dist/doc-metadata/extractors/mcp-tools.d.ts +16 -0
  275. package/dist/doc-metadata/extractors/mcp-tools.js +689 -0
  276. package/dist/doc-metadata/extractors/plugin-api.d.ts +19 -0
  277. package/dist/doc-metadata/extractors/plugin-api.js +279 -0
  278. package/dist/doc-metadata/index.d.ts +5 -0
  279. package/dist/doc-metadata/index.js +4 -0
  280. package/dist/doc-metadata/types.d.ts +120 -0
  281. package/dist/doc-metadata/types.js +5 -0
  282. package/dist/editor-completions/annotationValues.d.ts +12 -0
  283. package/dist/editor-completions/annotationValues.js +138 -0
  284. package/dist/editor-completions/contextParser.d.ts +40 -0
  285. package/dist/editor-completions/contextParser.js +410 -0
  286. package/dist/editor-completions/dataTypes.d.ts +16 -0
  287. package/dist/editor-completions/dataTypes.js +95 -0
  288. package/dist/editor-completions/goToDefinition.d.ts +27 -0
  289. package/dist/editor-completions/goToDefinition.js +112 -0
  290. package/dist/editor-completions/index.d.ts +39 -0
  291. package/dist/editor-completions/index.js +181 -0
  292. package/dist/editor-completions/jsDocAnnotations.d.ts +29 -0
  293. package/dist/editor-completions/jsDocAnnotations.js +357 -0
  294. package/dist/editor-completions/modifierCompletions.d.ts +17 -0
  295. package/dist/editor-completions/modifierCompletions.js +197 -0
  296. package/dist/editor-completions/types.d.ts +119 -0
  297. package/dist/editor-completions/types.js +8 -0
  298. package/dist/export/index.d.ts +68 -0
  299. package/dist/export/index.js +1074 -0
  300. package/dist/export/templates.d.ts +24 -0
  301. package/dist/export/templates.js +186 -0
  302. package/dist/friendly-errors.d.ts +35 -0
  303. package/dist/friendly-errors.js +375 -0
  304. package/dist/function-like.d.ts +38 -0
  305. package/dist/function-like.js +83 -0
  306. package/dist/generated-branding.d.ts +16 -0
  307. package/dist/generated-branding.js +22 -0
  308. package/dist/generator/async-detection.d.ts +27 -0
  309. package/dist/generator/async-detection.js +56 -0
  310. package/dist/generator/code-utils.d.ts +76 -0
  311. package/dist/generator/code-utils.js +410 -0
  312. package/dist/generator/control-flow.d.ts +54 -0
  313. package/dist/generator/control-flow.js +284 -0
  314. package/dist/generator/inngest.d.ts +53 -0
  315. package/dist/generator/inngest.js +1126 -0
  316. package/dist/generator/scope-function-generator.d.ts +78 -0
  317. package/dist/generator/scope-function-generator.js +360 -0
  318. package/dist/generator/unified.d.ts +42 -0
  319. package/dist/generator/unified.js +1504 -0
  320. package/dist/generator.d.ts +54 -0
  321. package/dist/generator.js +100 -0
  322. package/dist/index.d.ts +85 -0
  323. package/dist/index.js +89 -0
  324. package/dist/jsdoc-parser.d.ts +308 -0
  325. package/dist/jsdoc-parser.js +923 -0
  326. package/dist/jsdoc-port-sync/constants.d.ts +41 -0
  327. package/dist/jsdoc-port-sync/constants.js +103 -0
  328. package/dist/jsdoc-port-sync/diff.d.ts +76 -0
  329. package/dist/jsdoc-port-sync/diff.js +319 -0
  330. package/dist/jsdoc-port-sync/index.d.ts +42 -0
  331. package/dist/jsdoc-port-sync/index.js +45 -0
  332. package/dist/jsdoc-port-sync/port-parser.d.ts +68 -0
  333. package/dist/jsdoc-port-sync/port-parser.js +579 -0
  334. package/dist/jsdoc-port-sync/rename.d.ts +21 -0
  335. package/dist/jsdoc-port-sync/rename.js +256 -0
  336. package/dist/jsdoc-port-sync/signature-parser.d.ts +104 -0
  337. package/dist/jsdoc-port-sync/signature-parser.js +559 -0
  338. package/dist/jsdoc-port-sync/sync.d.ts +36 -0
  339. package/dist/jsdoc-port-sync/sync.js +644 -0
  340. package/dist/jsdoc-port-sync.d.ts +10 -0
  341. package/dist/jsdoc-port-sync.js +10 -0
  342. package/dist/marketplace/index.d.ts +11 -0
  343. package/dist/marketplace/index.js +10 -0
  344. package/dist/marketplace/manifest.d.ts +32 -0
  345. package/dist/marketplace/manifest.js +176 -0
  346. package/dist/marketplace/registry.d.ts +30 -0
  347. package/dist/marketplace/registry.js +100 -0
  348. package/dist/marketplace/types.d.ts +154 -0
  349. package/dist/marketplace/types.js +9 -0
  350. package/dist/marketplace/validator.d.ts +13 -0
  351. package/dist/marketplace/validator.js +131 -0
  352. package/dist/mcp/auto-registration.d.ts +3 -0
  353. package/dist/mcp/auto-registration.js +62 -0
  354. package/dist/mcp/editor-connection.d.ts +50 -0
  355. package/dist/mcp/editor-connection.js +125 -0
  356. package/dist/mcp/event-buffer.d.ts +62 -0
  357. package/dist/mcp/event-buffer.js +150 -0
  358. package/dist/mcp/index.d.ts +12 -0
  359. package/dist/mcp/index.js +11 -0
  360. package/dist/mcp/resources.d.ts +14 -0
  361. package/dist/mcp/resources.js +55 -0
  362. package/dist/mcp/response-utils.d.ts +63 -0
  363. package/dist/mcp/response-utils.js +89 -0
  364. package/dist/mcp/server.d.ts +4 -0
  365. package/dist/mcp/server.js +99 -0
  366. package/dist/mcp/tools-diagram.d.ts +8 -0
  367. package/dist/mcp/tools-diagram.js +53 -0
  368. package/dist/mcp/tools-editor.d.ts +5 -0
  369. package/dist/mcp/tools-editor.js +190 -0
  370. package/dist/mcp/tools-export.d.ts +9 -0
  371. package/dist/mcp/tools-export.js +180 -0
  372. package/dist/mcp/tools-marketplace.d.ts +9 -0
  373. package/dist/mcp/tools-marketplace.js +132 -0
  374. package/dist/mcp/tools-pattern.d.ts +3 -0
  375. package/dist/mcp/tools-pattern.js +783 -0
  376. package/dist/mcp/tools-query.d.ts +3 -0
  377. package/dist/mcp/tools-query.js +364 -0
  378. package/dist/mcp/tools-template.d.ts +10 -0
  379. package/dist/mcp/tools-template.js +119 -0
  380. package/dist/mcp/types.d.ts +70 -0
  381. package/dist/mcp/types.js +8 -0
  382. package/dist/mcp/workflow-executor.d.ts +47 -0
  383. package/dist/mcp/workflow-executor.js +133 -0
  384. package/dist/migration/registry.d.ts +30 -0
  385. package/dist/migration/registry.js +29 -0
  386. package/dist/node-types-generator.d.ts +49 -0
  387. package/dist/node-types-generator.js +139 -0
  388. package/dist/npm-packages.d.ts +56 -0
  389. package/dist/npm-packages.js +255 -0
  390. package/dist/parser.d.ts +204 -0
  391. package/dist/parser.js +2100 -0
  392. package/dist/plugin/PluginPanel.d.ts +12 -0
  393. package/dist/plugin/PluginPanel.js +5 -0
  394. package/dist/plugin/index.d.ts +13 -0
  395. package/dist/plugin/index.js +14 -0
  396. package/dist/plugin/types.d.ts +75 -0
  397. package/dist/plugin/types.js +8 -0
  398. package/dist/resolve-package-types.d.ts +17 -0
  399. package/dist/resolve-package-types.js +123 -0
  400. package/dist/runtime/CancellationError.d.ts +11 -0
  401. package/dist/runtime/CancellationError.js +20 -0
  402. package/dist/runtime/ExecutionContext.d.ts +146 -0
  403. package/dist/runtime/ExecutionContext.js +235 -0
  404. package/dist/runtime/builtin-functions.d.ts +8 -0
  405. package/dist/runtime/builtin-functions.js +549 -0
  406. package/dist/runtime/events.d.ts +50 -0
  407. package/dist/runtime/events.js +2 -0
  408. package/dist/runtime/function-registry.d.ts +59 -0
  409. package/dist/runtime/function-registry.js +66 -0
  410. package/dist/runtime/index.d.ts +7 -0
  411. package/dist/runtime/index.js +7 -0
  412. package/dist/runtime/parameter-resolver.d.ts +62 -0
  413. package/dist/runtime/parameter-resolver.js +113 -0
  414. package/dist/server/index.d.ts +7 -0
  415. package/dist/server/index.js +6 -0
  416. package/dist/server/types.d.ts +93 -0
  417. package/dist/server/types.js +5 -0
  418. package/dist/server/webhook-server.d.ts +50 -0
  419. package/dist/server/webhook-server.js +269 -0
  420. package/dist/server/workflow-registry.d.ts +61 -0
  421. package/dist/server/workflow-registry.js +202 -0
  422. package/dist/shared-project.d.ts +9 -0
  423. package/dist/shared-project.js +28 -0
  424. package/dist/sugar-optimizer.d.ts +40 -0
  425. package/dist/sugar-optimizer.js +387 -0
  426. package/dist/testing/assertions.d.ts +51 -0
  427. package/dist/testing/assertions.js +127 -0
  428. package/dist/testing/index.d.ts +30 -0
  429. package/dist/testing/index.js +24 -0
  430. package/dist/testing/mock-approval.d.ts +81 -0
  431. package/dist/testing/mock-approval.js +98 -0
  432. package/dist/testing/mock-llm.d.ts +124 -0
  433. package/dist/testing/mock-llm.js +119 -0
  434. package/dist/testing/recorder.d.ts +72 -0
  435. package/dist/testing/recorder.js +70 -0
  436. package/dist/testing/replayer.d.ts +56 -0
  437. package/dist/testing/replayer.js +143 -0
  438. package/dist/testing/token-tracker.d.ts +71 -0
  439. package/dist/testing/token-tracker.js +94 -0
  440. package/dist/type-checker.d.ts +42 -0
  441. package/dist/type-checker.js +190 -0
  442. package/dist/type-mappings.d.ts +29 -0
  443. package/dist/type-mappings.js +125 -0
  444. package/dist/types/branded-ports.d.ts +151 -0
  445. package/dist/types/branded-ports.js +121 -0
  446. package/dist/types/index.d.ts +5 -0
  447. package/dist/types/index.js +5 -0
  448. package/dist/types.d.ts +139 -0
  449. package/dist/types.js +15 -0
  450. package/dist/utils/error-utils.d.ts +15 -0
  451. package/dist/utils/error-utils.js +27 -0
  452. package/dist/utils/lru-cache.d.ts +15 -0
  453. package/dist/utils/lru-cache.js +40 -0
  454. package/dist/utils/port-ordering.d.ts +26 -0
  455. package/dist/utils/port-ordering.js +88 -0
  456. package/dist/utils/port-tag-utils.d.ts +23 -0
  457. package/dist/utils/port-tag-utils.js +41 -0
  458. package/dist/utils/string-distance.d.ts +14 -0
  459. package/dist/utils/string-distance.js +56 -0
  460. package/dist/validation/agent-detection.d.ts +33 -0
  461. package/dist/validation/agent-detection.js +115 -0
  462. package/dist/validation/agent-rules.d.ts +48 -0
  463. package/dist/validation/agent-rules.js +262 -0
  464. package/dist/validator.d.ts +92 -0
  465. package/dist/validator.js +970 -0
  466. package/package.json +109 -0
@@ -0,0 +1,387 @@
1
+ /**
2
+ * Sugar Optimizer - Auto-detect @path routes from connections.
3
+ *
4
+ * Analyzes control-flow connections and identifies routes through the graph
5
+ * that can be expressed as @path macros. @connect is the escape hatch for
6
+ * connections that @path can't cover.
7
+ */
8
+ import { isControlFlowPort } from './constants.js';
9
+ // =============================================================================
10
+ // Path Validation (for stale macro detection during round-trip)
11
+ // =============================================================================
12
+ /**
13
+ * Validate that a @path macro's control-flow connections still exist
14
+ * in the actual connection set. Also checks that all step nodes exist
15
+ * as instances (or are Start/Exit).
16
+ *
17
+ * Returns true if the path is still valid, false if it should be dropped.
18
+ */
19
+ export function validatePathMacro(path, connections, instances) {
20
+ const instanceIds = new Set(instances.map(inst => inst.id));
21
+ // Check all step nodes exist as instances (or are Start/Exit)
22
+ for (const step of path.steps) {
23
+ if (step.node === 'Start' || step.node === 'Exit')
24
+ continue;
25
+ if (!instanceIds.has(step.node))
26
+ return false;
27
+ }
28
+ // Build a quick lookup set for unscoped connections
29
+ const connKeys = new Set();
30
+ for (const conn of connections) {
31
+ if (!conn.from.scope && !conn.to.scope) {
32
+ connKeys.add(`${conn.from.node}.${conn.from.port}->${conn.to.node}.${conn.to.port}`);
33
+ }
34
+ }
35
+ // For each consecutive pair, compute expected control-flow connection
36
+ for (let i = 0; i < path.steps.length - 1; i++) {
37
+ const current = path.steps[i];
38
+ const next = path.steps[i + 1];
39
+ const route = current.route || 'ok';
40
+ let expectedKey;
41
+ if (current.node === 'Start') {
42
+ expectedKey = `Start.execute->${next.node}.execute`;
43
+ }
44
+ else if (next.node === 'Exit') {
45
+ if (route === 'fail') {
46
+ expectedKey = `${current.node}.onFailure->Exit.onFailure`;
47
+ }
48
+ else {
49
+ expectedKey = `${current.node}.onSuccess->Exit.onSuccess`;
50
+ }
51
+ }
52
+ else {
53
+ if (route === 'fail') {
54
+ expectedKey = `${current.node}.onFailure->${next.node}.execute`;
55
+ }
56
+ else {
57
+ expectedKey = `${current.node}.onSuccess->${next.node}.execute`;
58
+ }
59
+ }
60
+ if (!connKeys.has(expectedKey)) {
61
+ return false;
62
+ }
63
+ }
64
+ return true;
65
+ }
66
+ /**
67
+ * Filter existing macros, removing any @path macros whose control-flow
68
+ * connections no longer exist in the connection set.
69
+ * Non-path macros are passed through unchanged.
70
+ */
71
+ export function filterStaleMacros(macros, connections, instances) {
72
+ return macros.filter(macro => {
73
+ if (macro.type !== 'path')
74
+ return true;
75
+ return validatePathMacro(macro, connections, instances);
76
+ });
77
+ }
78
+ /**
79
+ * Detect @path routes from a set of connections.
80
+ *
81
+ * Algorithm:
82
+ * 1. Build control-flow adjacency from unscoped connections
83
+ * 2. DFS from Start to enumerate all Start-to-Exit routes
84
+ * 3. Validate data connections for each candidate (scope walking safety)
85
+ * 4. Greedy route selection to cover all control-flow edges
86
+ */
87
+ export function detectSugarPatterns(connections, instances, existingMacros, nodeTypes, startPorts, exitPorts) {
88
+ const coveredByExistingMacro = buildExistingMacroCoverage(existingMacros);
89
+ // Filter out scoped connections — never optimize those
90
+ const unscopedConns = connections.filter((c) => !c.from.scope && !c.to.scope);
91
+ // Build lookup helpers
92
+ const instanceMap = new Map(instances.map((inst) => [inst.id, inst]));
93
+ const nodeTypeMap = new Map();
94
+ for (const nt of nodeTypes) {
95
+ nodeTypeMap.set(nt.name, nt);
96
+ if (nt.functionName !== nt.name) {
97
+ nodeTypeMap.set(nt.functionName, nt);
98
+ }
99
+ }
100
+ const getNodeType = (nodeId) => {
101
+ const inst = instanceMap.get(nodeId);
102
+ if (!inst)
103
+ return undefined;
104
+ return nodeTypeMap.get(inst.nodeType);
105
+ };
106
+ const getOutputPorts = (nodeId) => {
107
+ if (nodeId === 'Start')
108
+ return startPorts;
109
+ const nt = getNodeType(nodeId);
110
+ return nt?.outputs || {};
111
+ };
112
+ const getInputPorts = (nodeId) => {
113
+ if (nodeId === 'Exit')
114
+ return exitPorts;
115
+ const nt = getNodeType(nodeId);
116
+ return nt?.inputs || {};
117
+ };
118
+ // ---- Step 1: Build control-flow adjacency ----
119
+ // adj[node] = { ok?: targetNode, fail?: targetNode }
120
+ // Only single-target edges are pathable (multi-target needs @connect)
121
+ const adj = new Map();
122
+ const multiTargetPorts = new Set(); // "node.port" keys with multiple targets
123
+ for (const conn of unscopedConns) {
124
+ const { from, to } = conn;
125
+ let edgeNode;
126
+ let edgeRoute;
127
+ // Start.execute -> X.execute
128
+ if (from.node === 'Start' && from.port === 'execute' && to.port === 'execute') {
129
+ edgeNode = 'Start';
130
+ edgeRoute = 'ok';
131
+ }
132
+ // X.onSuccess -> Exit.onSuccess
133
+ else if (to.node === 'Exit' && from.port === 'onSuccess' && to.port === 'onSuccess') {
134
+ edgeNode = from.node;
135
+ edgeRoute = 'ok';
136
+ }
137
+ // X.onFailure -> Exit.onFailure
138
+ else if (to.node === 'Exit' && from.port === 'onFailure' && to.port === 'onFailure') {
139
+ edgeNode = from.node;
140
+ edgeRoute = 'fail';
141
+ }
142
+ // X.onSuccess -> Y.execute
143
+ else if (from.port === 'onSuccess' && to.port === 'execute') {
144
+ edgeNode = from.node;
145
+ edgeRoute = 'ok';
146
+ }
147
+ // X.onFailure -> Y.execute
148
+ else if (from.port === 'onFailure' && to.port === 'execute') {
149
+ edgeNode = from.node;
150
+ edgeRoute = 'fail';
151
+ }
152
+ if (edgeNode === undefined || edgeRoute === undefined)
153
+ continue;
154
+ const portKey = `${edgeNode}.${edgeRoute}`;
155
+ if (!adj.has(edgeNode)) {
156
+ adj.set(edgeNode, {});
157
+ }
158
+ const entry = adj.get(edgeNode);
159
+ if (entry[edgeRoute] !== undefined && entry[edgeRoute] !== to.node) {
160
+ // Multiple targets for same port — not pathable
161
+ multiTargetPorts.add(portKey);
162
+ delete entry[edgeRoute];
163
+ }
164
+ else if (!multiTargetPorts.has(portKey)) {
165
+ entry[edgeRoute] = to.node;
166
+ }
167
+ }
168
+ // ---- Step 2: DFS to enumerate Start-to-Exit routes ----
169
+ const candidateRoutes = [];
170
+ const MAX_ROUTES = 20; // Sanity limit for complex graphs
171
+ function dfs(node, path, visited) {
172
+ if (candidateRoutes.length >= MAX_ROUTES)
173
+ return;
174
+ if (node === 'Exit') {
175
+ path.push({ node: 'Exit' });
176
+ candidateRoutes.push([...path]);
177
+ path.pop();
178
+ return;
179
+ }
180
+ if (visited.has(node))
181
+ return; // Cycle protection
182
+ visited.add(node);
183
+ const edges = adj.get(node);
184
+ if (!edges) {
185
+ visited.delete(node);
186
+ return;
187
+ }
188
+ // Try ok edge
189
+ if (edges.ok && !coveredByExistingMacro.has(edges.ok === 'Exit' ? '' : edges.ok)) {
190
+ const step = node === 'Start' ? { node: 'Start' } : { node };
191
+ path.push(step);
192
+ dfs(edges.ok, path, visited);
193
+ path.pop();
194
+ }
195
+ // Try fail edge
196
+ if (edges.fail && !coveredByExistingMacro.has(edges.fail === 'Exit' ? '' : edges.fail)) {
197
+ const step = { node, route: 'fail' };
198
+ path.push(step);
199
+ dfs(edges.fail, path, visited);
200
+ path.pop();
201
+ }
202
+ visited.delete(node);
203
+ }
204
+ // Only start DFS if Start is not covered by existing macros
205
+ if (!coveredByExistingMacro.has('Start')) {
206
+ dfs('Start', [], new Set());
207
+ }
208
+ // ---- Step 3: Validate data connections for each candidate ----
209
+ // Simulate scope walking and verify expected data connections exist
210
+ const connKeySet = new Set();
211
+ for (const conn of unscopedConns) {
212
+ connKeySet.add(`${conn.from.node}.${conn.from.port}->${conn.to.node}.${conn.to.port}`);
213
+ }
214
+ const validRoutes = candidateRoutes.filter(route => {
215
+ // Path needs at least 2 steps
216
+ if (route.length < 2)
217
+ return false;
218
+ // Simulate scope walking for data ports
219
+ for (let i = 0; i < route.length - 1; i++) {
220
+ const nextId = route[i + 1].node;
221
+ if (nextId === 'Exit')
222
+ continue;
223
+ const nextInputs = getInputPorts(nextId);
224
+ for (const [inputName] of Object.entries(nextInputs)) {
225
+ if (isControlFlowPort(inputName))
226
+ continue;
227
+ // Walk backward through route steps to find nearest ancestor with same-name output
228
+ for (let j = i; j >= 0; j--) {
229
+ const ancestorId = route[j].node;
230
+ const ancestorOutputs = getOutputPorts(ancestorId);
231
+ if (inputName in ancestorOutputs && !isControlFlowPort(inputName)) {
232
+ // Scope walking would create this connection — verify it exists
233
+ const key = `${ancestorId}.${inputName}->${nextId}.${inputName}`;
234
+ if (!connKeySet.has(key)) {
235
+ return false; // Path would create a connection that doesn't exist
236
+ }
237
+ break;
238
+ }
239
+ }
240
+ }
241
+ }
242
+ return true;
243
+ });
244
+ const allCFEdges = new Set();
245
+ for (const conn of unscopedConns) {
246
+ if (isControlFlowPort(conn.from.port) || conn.from.port === 'execute') {
247
+ if (isControlFlowPort(conn.to.port) || conn.to.port === 'execute') {
248
+ // Only include edges that are pathable (single target)
249
+ const portKey = conn.from.node === 'Start' ? 'Start.ok'
250
+ : conn.from.port === 'onSuccess' ? `${conn.from.node}.ok`
251
+ : conn.from.port === 'onFailure' ? `${conn.from.node}.fail`
252
+ : null;
253
+ if (portKey && !multiTargetPorts.has(portKey)) {
254
+ allCFEdges.add(`${conn.from.node}.${conn.from.port}->${conn.to.node}.${conn.to.port}`);
255
+ }
256
+ }
257
+ }
258
+ }
259
+ // Remove edges already covered by existing macros
260
+ for (const macro of existingMacros) {
261
+ if (macro.type === 'path') {
262
+ for (let i = 0; i < macro.steps.length - 1; i++) {
263
+ const current = macro.steps[i];
264
+ const next = macro.steps[i + 1];
265
+ const route = current.route || 'ok';
266
+ let key;
267
+ if (current.node === 'Start') {
268
+ key = `Start.execute->${next.node}.execute`;
269
+ }
270
+ else if (next.node === 'Exit') {
271
+ const fromPort = route === 'fail' ? 'onFailure' : 'onSuccess';
272
+ const toPort = route === 'fail' ? 'onFailure' : 'onSuccess';
273
+ key = `${current.node}.${fromPort}->Exit.${toPort}`;
274
+ }
275
+ else {
276
+ const fromPort = route === 'fail' ? 'onFailure' : 'onSuccess';
277
+ key = `${current.node}.${fromPort}->${next.node}.execute`;
278
+ }
279
+ allCFEdges.delete(key);
280
+ }
281
+ }
282
+ }
283
+ // Compute edges covered by each candidate route
284
+ function getRouteEdges(route) {
285
+ const edges = [];
286
+ for (let i = 0; i < route.length - 1; i++) {
287
+ const current = route[i];
288
+ const next = route[i + 1];
289
+ const routeVal = current.route || 'ok';
290
+ let key;
291
+ if (current.node === 'Start') {
292
+ key = `Start.execute->${next.node}.execute`;
293
+ }
294
+ else if (next.node === 'Exit') {
295
+ const fromPort = routeVal === 'fail' ? 'onFailure' : 'onSuccess';
296
+ const toPort = routeVal === 'fail' ? 'onFailure' : 'onSuccess';
297
+ key = `${current.node}.${fromPort}->Exit.${toPort}`;
298
+ }
299
+ else {
300
+ const fromPort = routeVal === 'fail' ? 'onFailure' : 'onSuccess';
301
+ key = `${current.node}.${fromPort}->${next.node}.execute`;
302
+ }
303
+ edges.push(key);
304
+ }
305
+ return edges;
306
+ }
307
+ // Sort by length (longest first) for greedy selection
308
+ const sortedRoutes = [...validRoutes].sort((a, b) => b.length - a.length);
309
+ const selectedPaths = [];
310
+ const coveredEdges = new Set();
311
+ for (const route of sortedRoutes) {
312
+ const routeEdges = getRouteEdges(route);
313
+ const newEdges = routeEdges.filter(e => allCFEdges.has(e) && !coveredEdges.has(e));
314
+ if (newEdges.length > 0) {
315
+ selectedPaths.push({
316
+ type: 'path',
317
+ steps: route.map(s => s.route ? { node: s.node, route: s.route } : { node: s.node }),
318
+ });
319
+ for (const e of routeEdges) {
320
+ coveredEdges.add(e);
321
+ }
322
+ }
323
+ }
324
+ return { paths: selectedPaths };
325
+ }
326
+ /**
327
+ * Check if a connection is covered by detected sugar and should be omitted from @connect output.
328
+ */
329
+ export function isConnectionCoveredBySugar(conn, sugar) {
330
+ // Scoped connections are never covered
331
+ if (conn.from.scope || conn.to.scope)
332
+ return false;
333
+ for (const path of sugar.paths) {
334
+ const steps = path.steps;
335
+ const fromIdx = steps.findIndex(s => s.node === conn.from.node);
336
+ const toIdx = steps.findIndex(s => s.node === conn.to.node);
337
+ if (fromIdx === -1 || toIdx === -1 || fromIdx >= toIdx)
338
+ continue;
339
+ // Control flow: check consecutive pairs
340
+ if (toIdx === fromIdx + 1) {
341
+ const route = steps[fromIdx].route || 'ok';
342
+ // Start.execute -> next.execute
343
+ if (conn.from.node === 'Start' && conn.from.port === 'execute' && conn.to.port === 'execute')
344
+ return true;
345
+ // To Exit: route determines which Exit port
346
+ if (conn.to.node === 'Exit') {
347
+ if (route === 'fail' && conn.from.port === 'onFailure' && conn.to.port === 'onFailure')
348
+ return true;
349
+ if (route === 'ok' && conn.from.port === 'onSuccess' && conn.to.port === 'onSuccess')
350
+ return true;
351
+ }
352
+ // Normal: onSuccess/onFailure -> execute
353
+ if (route === 'fail' && conn.from.port === 'onFailure' && conn.to.port === 'execute')
354
+ return true;
355
+ if (route === 'ok' && conn.from.port === 'onSuccess' && conn.to.port === 'execute')
356
+ return true;
357
+ }
358
+ // Data: same-name non-control-flow, from before to, to is not Exit
359
+ if (conn.to.node !== 'Exit' &&
360
+ !isControlFlowPort(conn.from.port) &&
361
+ !isControlFlowPort(conn.to.port) &&
362
+ conn.from.port === conn.to.port) {
363
+ return true;
364
+ }
365
+ }
366
+ return false;
367
+ }
368
+ /**
369
+ * Build a set of node IDs that are already covered by user-written macros.
370
+ * These nodes should not be included in auto-detected patterns.
371
+ */
372
+ function buildExistingMacroCoverage(macros) {
373
+ const covered = new Set();
374
+ for (const macro of macros) {
375
+ if (macro.type === 'map') {
376
+ covered.add(macro.instanceId);
377
+ covered.add(macro.childId);
378
+ }
379
+ else if (macro.type === 'path') {
380
+ for (const step of macro.steps) {
381
+ covered.add(step.node);
382
+ }
383
+ }
384
+ }
385
+ return covered;
386
+ }
387
+ //# sourceMappingURL=sugar-optimizer.js.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Fluent assertion helpers for agent workflow test results.
3
+ *
4
+ * Usage:
5
+ * ```typescript
6
+ * import { expectAgentResult } from 'flow-weaver/testing';
7
+ *
8
+ * const result = await myAgentWorkflow(true, { query: 'hello' });
9
+ *
10
+ * expectAgentResult(result)
11
+ * .toHaveSucceeded()
12
+ * .toHaveOutput('answer', 'hello world')
13
+ * .toNotHaveOutput('error');
14
+ * ```
15
+ */
16
+ import type { MockLlmProvider } from './mock-llm.js';
17
+ export interface AgentResultAssertions {
18
+ /** Assert the workflow completed successfully (onSuccess === true) */
19
+ toHaveSucceeded(): AgentResultAssertions;
20
+ /** Assert the workflow failed (onFailure === true) */
21
+ toHaveFailed(): AgentResultAssertions;
22
+ /** Assert a specific output port has a value */
23
+ toHaveOutput(portName: string, expectedValue?: unknown): AgentResultAssertions;
24
+ /** Assert a specific output port is absent, null, or undefined */
25
+ toNotHaveOutput(portName: string): AgentResultAssertions;
26
+ }
27
+ /**
28
+ * Create fluent assertions for an agent workflow result.
29
+ *
30
+ * @param result - The workflow result object (record of output port values)
31
+ */
32
+ export declare function expectAgentResult(result: Record<string, unknown>): AgentResultAssertions;
33
+ export interface MockLlmAssertions {
34
+ /** Assert the LLM was called exactly N times */
35
+ toHaveBeenCalledTimes(n: number): MockLlmAssertions;
36
+ /** Assert at least one call included a tool call with the given name */
37
+ toHaveUsedTool(toolName: string): MockLlmAssertions;
38
+ /** Assert no call included a tool call with the given name */
39
+ toNotHaveUsedTool(toolName: string): MockLlmAssertions;
40
+ /** Assert total tokens are below a budget */
41
+ toHaveTokenUsageBelow(maxTokens: number): MockLlmAssertions;
42
+ /** Assert a specific call's messages contain a message matching a pattern */
43
+ toHaveReceivedMessage(pattern: string | RegExp, callIndex?: number): MockLlmAssertions;
44
+ }
45
+ /**
46
+ * Create fluent assertions for a mock LLM provider's recorded calls.
47
+ *
48
+ * @param mockLlm - The mock provider to assert against
49
+ */
50
+ export declare function expectMockLlm(mockLlm: MockLlmProvider): MockLlmAssertions;
51
+ //# sourceMappingURL=assertions.d.ts.map
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Fluent assertion helpers for agent workflow test results.
3
+ *
4
+ * Usage:
5
+ * ```typescript
6
+ * import { expectAgentResult } from 'flow-weaver/testing';
7
+ *
8
+ * const result = await myAgentWorkflow(true, { query: 'hello' });
9
+ *
10
+ * expectAgentResult(result)
11
+ * .toHaveSucceeded()
12
+ * .toHaveOutput('answer', 'hello world')
13
+ * .toNotHaveOutput('error');
14
+ * ```
15
+ */
16
+ /**
17
+ * Create fluent assertions for an agent workflow result.
18
+ *
19
+ * @param result - The workflow result object (record of output port values)
20
+ */
21
+ export function expectAgentResult(result) {
22
+ const assertions = {
23
+ toHaveSucceeded() {
24
+ if (result.onSuccess !== true) {
25
+ throw new Error(`Expected workflow to succeed (onSuccess === true), but got onSuccess=${result.onSuccess}, onFailure=${result.onFailure}`);
26
+ }
27
+ return assertions;
28
+ },
29
+ toHaveFailed() {
30
+ if (result.onFailure !== true) {
31
+ throw new Error(`Expected workflow to fail (onFailure === true), but got onSuccess=${result.onSuccess}, onFailure=${result.onFailure}`);
32
+ }
33
+ return assertions;
34
+ },
35
+ toHaveOutput(portName, expectedValue) {
36
+ if (!(portName in result)) {
37
+ throw new Error(`Expected output port '${portName}' to exist, but result only has: ${Object.keys(result).join(', ')}`);
38
+ }
39
+ if (result[portName] === null || result[portName] === undefined) {
40
+ throw new Error(`Expected output port '${portName}' to have a value, but got ${result[portName]}`);
41
+ }
42
+ if (expectedValue !== undefined) {
43
+ const actual = result[portName];
44
+ const expected = expectedValue;
45
+ if (typeof expected === 'object' && expected !== null) {
46
+ // Deep comparison for objects
47
+ if (JSON.stringify(actual) !== JSON.stringify(expected)) {
48
+ throw new Error(`Expected output '${portName}' to equal ${JSON.stringify(expected)}, but got ${JSON.stringify(actual)}`);
49
+ }
50
+ }
51
+ else if (actual !== expected) {
52
+ throw new Error(`Expected output '${portName}' to equal ${JSON.stringify(expected)}, but got ${JSON.stringify(actual)}`);
53
+ }
54
+ }
55
+ return assertions;
56
+ },
57
+ toNotHaveOutput(portName) {
58
+ if (portName in result && result[portName] !== null && result[portName] !== undefined) {
59
+ throw new Error(`Expected output port '${portName}' to be absent or null, but got ${JSON.stringify(result[portName])}`);
60
+ }
61
+ return assertions;
62
+ },
63
+ };
64
+ return assertions;
65
+ }
66
+ /**
67
+ * Create fluent assertions for a mock LLM provider's recorded calls.
68
+ *
69
+ * @param mockLlm - The mock provider to assert against
70
+ */
71
+ export function expectMockLlm(mockLlm) {
72
+ const assertions = {
73
+ toHaveBeenCalledTimes(n) {
74
+ const actual = mockLlm.getCallCount();
75
+ if (actual !== n) {
76
+ throw new Error(`Expected LLM to be called ${n} time(s), but was called ${actual} time(s)`);
77
+ }
78
+ return assertions;
79
+ },
80
+ toHaveUsedTool(toolName) {
81
+ const calls = mockLlm.getCalls();
82
+ const found = calls.some((call) => call.response.toolCalls.some((tc) => tc.name === toolName));
83
+ if (!found) {
84
+ const usedTools = [
85
+ ...new Set(calls.flatMap((c) => c.response.toolCalls.map((tc) => tc.name))),
86
+ ];
87
+ throw new Error(`Expected tool '${toolName}' to have been used, but only these tools were used: ${usedTools.length > 0 ? usedTools.join(', ') : '(none)'}`);
88
+ }
89
+ return assertions;
90
+ },
91
+ toNotHaveUsedTool(toolName) {
92
+ const calls = mockLlm.getCalls();
93
+ const found = calls.some((call) => call.response.toolCalls.some((tc) => tc.name === toolName));
94
+ if (found) {
95
+ throw new Error(`Expected tool '${toolName}' to NOT have been used, but it was`);
96
+ }
97
+ return assertions;
98
+ },
99
+ toHaveTokenUsageBelow(maxTokens) {
100
+ const total = mockLlm.getTotalTokens();
101
+ if (total > maxTokens) {
102
+ throw new Error(`Expected token usage below ${maxTokens}, but total was ${total}`);
103
+ }
104
+ return assertions;
105
+ },
106
+ toHaveReceivedMessage(pattern, callIndex) {
107
+ const calls = mockLlm.getCalls();
108
+ const targetCalls = callIndex !== undefined ? [calls[callIndex]] : calls;
109
+ if (callIndex !== undefined && !calls[callIndex]) {
110
+ throw new Error(`Expected call at index ${callIndex}, but only ${calls.length} calls were recorded`);
111
+ }
112
+ const found = targetCalls.some((call) => call?.messages.some((msg) => {
113
+ if (typeof pattern === 'string') {
114
+ return msg.content.includes(pattern);
115
+ }
116
+ return pattern.test(msg.content);
117
+ }));
118
+ if (!found) {
119
+ const scope = callIndex !== undefined ? `call #${callIndex}` : 'any call';
120
+ throw new Error(`Expected ${scope} to contain a message matching ${pattern}, but none matched`);
121
+ }
122
+ return assertions;
123
+ },
124
+ };
125
+ return assertions;
126
+ }
127
+ //# sourceMappingURL=assertions.js.map
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Flow Weaver Testing Utilities
3
+ *
4
+ * Deterministic testing for agent workflows.
5
+ *
6
+ * ```typescript
7
+ * import {
8
+ * createMockLlmProvider,
9
+ * createRecordingProvider,
10
+ * createReplayProvider,
11
+ * loadRecording,
12
+ * expectAgentResult,
13
+ * expectMockLlm,
14
+ * TokenTracker,
15
+ * } from 'flow-weaver/testing';
16
+ * ```
17
+ */
18
+ export { createMockLlmProvider } from './mock-llm.js';
19
+ export type { MockLlmProvider, MockLlmResponse, MockLlmCall, LLMProvider, LLMMessage, LLMResponse, LLMToolCall, LLMTool, LLMTokenUsage, } from './mock-llm.js';
20
+ export { expectAgentResult, expectMockLlm } from './assertions.js';
21
+ export type { AgentResultAssertions, MockLlmAssertions } from './assertions.js';
22
+ export { TokenTracker } from './token-tracker.js';
23
+ export type { TrackedStep } from './token-tracker.js';
24
+ export { createRecordingProvider } from './recorder.js';
25
+ export type { RecordingLlmProvider, LlmRecording, LlmRecordingStep } from './recorder.js';
26
+ export { createReplayProvider, loadRecording } from './replayer.js';
27
+ export type { ReplayOptions } from './replayer.js';
28
+ export { createMockApprovalProvider } from './mock-approval.js';
29
+ export type { MockApprovalProvider, MockApprovalResponse, MockApprovalCall, ApprovalProvider, ApprovalRequest, ApprovalResult, } from './mock-approval.js';
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Flow Weaver Testing Utilities
3
+ *
4
+ * Deterministic testing for agent workflows.
5
+ *
6
+ * ```typescript
7
+ * import {
8
+ * createMockLlmProvider,
9
+ * createRecordingProvider,
10
+ * createReplayProvider,
11
+ * loadRecording,
12
+ * expectAgentResult,
13
+ * expectMockLlm,
14
+ * TokenTracker,
15
+ * } from 'flow-weaver/testing';
16
+ * ```
17
+ */
18
+ export { createMockLlmProvider } from './mock-llm.js';
19
+ export { expectAgentResult, expectMockLlm } from './assertions.js';
20
+ export { TokenTracker } from './token-tracker.js';
21
+ export { createRecordingProvider } from './recorder.js';
22
+ export { createReplayProvider, loadRecording } from './replayer.js';
23
+ export { createMockApprovalProvider } from './mock-approval.js';
24
+ //# sourceMappingURL=index.js.map