@n8n/instance-ai 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (504) hide show
  1. package/LICENSE.md +88 -0
  2. package/dist/agent/instance-agent.d.ts +3 -0
  3. package/dist/agent/instance-agent.js +215 -0
  4. package/dist/agent/instance-agent.js.map +1 -0
  5. package/dist/agent/register-with-mastra.d.ts +3 -0
  6. package/dist/agent/register-with-mastra.js +19 -0
  7. package/dist/agent/register-with-mastra.js.map +1 -0
  8. package/dist/agent/sanitize-mcp-schemas.d.ts +2 -0
  9. package/dist/agent/sanitize-mcp-schemas.js +91 -0
  10. package/dist/agent/sanitize-mcp-schemas.js.map +1 -0
  11. package/dist/agent/sub-agent-factory.d.ts +14 -0
  12. package/dist/agent/sub-agent-factory.js +48 -0
  13. package/dist/agent/sub-agent-factory.js.map +1 -0
  14. package/dist/agent/system-prompt.d.ts +13 -0
  15. package/dist/agent/system-prompt.js +226 -0
  16. package/dist/agent/system-prompt.js.map +1 -0
  17. package/dist/build.tsbuildinfo +1 -0
  18. package/dist/compaction/compaction-helper.d.ts +9 -0
  19. package/dist/compaction/compaction-helper.js +58 -0
  20. package/dist/compaction/compaction-helper.js.map +1 -0
  21. package/dist/compaction/index.d.ts +2 -0
  22. package/dist/compaction/index.js +6 -0
  23. package/dist/compaction/index.js.map +1 -0
  24. package/dist/domain-access/domain-access-tracker.d.ts +9 -0
  25. package/dist/domain-access/domain-access-tracker.js +46 -0
  26. package/dist/domain-access/domain-access-tracker.js.map +1 -0
  27. package/dist/domain-access/domain-gating.d.ts +65 -0
  28. package/dist/domain-access/domain-gating.js +68 -0
  29. package/dist/domain-access/domain-gating.js.map +1 -0
  30. package/dist/domain-access/index.d.ts +4 -0
  31. package/dist/domain-access/index.js +11 -0
  32. package/dist/domain-access/index.js.map +1 -0
  33. package/dist/event-bus/event-bus.interface.d.ts +15 -0
  34. package/dist/event-bus/event-bus.interface.js +3 -0
  35. package/dist/event-bus/event-bus.interface.js.map +1 -0
  36. package/dist/event-bus/index.d.ts +1 -0
  37. package/dist/event-bus/index.js +3 -0
  38. package/dist/event-bus/index.js.map +1 -0
  39. package/dist/index.d.ts +46 -0
  40. package/dist/index.js +89 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/mcp/mcp-client-manager.d.ts +6 -0
  43. package/dist/mcp/mcp-client-manager.js +34 -0
  44. package/dist/mcp/mcp-client-manager.js.map +1 -0
  45. package/dist/memory/memory-config.d.ts +3 -0
  46. package/dist/memory/memory-config.js +29 -0
  47. package/dist/memory/memory-config.js.map +1 -0
  48. package/dist/memory/title-utils.d.ts +3 -0
  49. package/dist/memory/title-utils.js +42 -0
  50. package/dist/memory/title-utils.js.map +1 -0
  51. package/dist/memory/working-memory-template.d.ts +1 -0
  52. package/dist/memory/working-memory-template.js +25 -0
  53. package/dist/memory/working-memory-template.js.map +1 -0
  54. package/dist/planned-tasks/planned-task-service.d.ts +33 -0
  55. package/dist/planned-tasks/planned-task-service.js +151 -0
  56. package/dist/planned-tasks/planned-task-service.js.map +1 -0
  57. package/dist/runtime/background-task-manager.d.ts +53 -0
  58. package/dist/runtime/background-task-manager.js +127 -0
  59. package/dist/runtime/background-task-manager.js.map +1 -0
  60. package/dist/runtime/resumable-stream-executor.d.ts +75 -0
  61. package/dist/runtime/resumable-stream-executor.js +1552 -0
  62. package/dist/runtime/resumable-stream-executor.js.map +1 -0
  63. package/dist/runtime/run-state-registry.d.ts +109 -0
  64. package/dist/runtime/run-state-registry.js +210 -0
  65. package/dist/runtime/run-state-registry.js.map +1 -0
  66. package/dist/runtime/stream-runner.d.ts +27 -0
  67. package/dist/runtime/stream-runner.js +87 -0
  68. package/dist/runtime/stream-runner.js.map +1 -0
  69. package/dist/runtime/working-memory-tracing.d.ts +19 -0
  70. package/dist/runtime/working-memory-tracing.js +111 -0
  71. package/dist/runtime/working-memory-tracing.js.map +1 -0
  72. package/dist/storage/agent-tree-snapshot.d.ts +7 -0
  73. package/dist/storage/agent-tree-snapshot.js +3 -0
  74. package/dist/storage/agent-tree-snapshot.js.map +1 -0
  75. package/dist/storage/index.d.ts +10 -0
  76. package/dist/storage/index.js +17 -0
  77. package/dist/storage/index.js.map +1 -0
  78. package/dist/storage/iteration-log.d.ts +30 -0
  79. package/dist/storage/iteration-log.js +31 -0
  80. package/dist/storage/iteration-log.js.map +1 -0
  81. package/dist/storage/mastra-iteration-log-storage.d.ts +10 -0
  82. package/dist/storage/mastra-iteration-log-storage.js +57 -0
  83. package/dist/storage/mastra-iteration-log-storage.js.map +1 -0
  84. package/dist/storage/mastra-task-storage.d.ts +9 -0
  85. package/dist/storage/mastra-task-storage.js +35 -0
  86. package/dist/storage/mastra-task-storage.js.map +1 -0
  87. package/dist/storage/planned-task-storage.d.ts +10 -0
  88. package/dist/storage/planned-task-storage.js +97 -0
  89. package/dist/storage/planned-task-storage.js.map +1 -0
  90. package/dist/storage/thread-patch.d.ts +16 -0
  91. package/dist/storage/thread-patch.js +50 -0
  92. package/dist/storage/thread-patch.js.map +1 -0
  93. package/dist/storage/workflow-loop-storage.d.ts +217 -0
  94. package/dist/storage/workflow-loop-storage.js +59 -0
  95. package/dist/storage/workflow-loop-storage.js.map +1 -0
  96. package/dist/stream/consume-with-hitl.d.ts +22 -0
  97. package/dist/stream/consume-with-hitl.js +29 -0
  98. package/dist/stream/consume-with-hitl.js.map +1 -0
  99. package/dist/stream/map-chunk.d.ts +2 -0
  100. package/dist/stream/map-chunk.js +224 -0
  101. package/dist/stream/map-chunk.js.map +1 -0
  102. package/dist/tools/best-practices/get-best-practices.tool.d.ts +12 -0
  103. package/dist/tools/best-practices/get-best-practices.tool.js +64 -0
  104. package/dist/tools/best-practices/get-best-practices.tool.js.map +1 -0
  105. package/dist/tools/best-practices/guides/chatbot.d.ts +1 -0
  106. package/dist/tools/best-practices/guides/chatbot.js +111 -0
  107. package/dist/tools/best-practices/guides/chatbot.js.map +1 -0
  108. package/dist/tools/best-practices/guides/content-generation.d.ts +1 -0
  109. package/dist/tools/best-practices/guides/content-generation.js +108 -0
  110. package/dist/tools/best-practices/guides/content-generation.js.map +1 -0
  111. package/dist/tools/best-practices/guides/data-extraction.d.ts +1 -0
  112. package/dist/tools/best-practices/guides/data-extraction.js +115 -0
  113. package/dist/tools/best-practices/guides/data-extraction.js.map +1 -0
  114. package/dist/tools/best-practices/guides/data-persistence.d.ts +1 -0
  115. package/dist/tools/best-practices/guides/data-persistence.js +198 -0
  116. package/dist/tools/best-practices/guides/data-persistence.js.map +1 -0
  117. package/dist/tools/best-practices/guides/data-transformation.d.ts +1 -0
  118. package/dist/tools/best-practices/guides/data-transformation.js +139 -0
  119. package/dist/tools/best-practices/guides/data-transformation.js.map +1 -0
  120. package/dist/tools/best-practices/guides/document-processing.d.ts +1 -0
  121. package/dist/tools/best-practices/guides/document-processing.js +326 -0
  122. package/dist/tools/best-practices/guides/document-processing.js.map +1 -0
  123. package/dist/tools/best-practices/guides/form-input.d.ts +1 -0
  124. package/dist/tools/best-practices/guides/form-input.js +166 -0
  125. package/dist/tools/best-practices/guides/form-input.js.map +1 -0
  126. package/dist/tools/best-practices/guides/notification.d.ts +1 -0
  127. package/dist/tools/best-practices/guides/notification.js +128 -0
  128. package/dist/tools/best-practices/guides/notification.js.map +1 -0
  129. package/dist/tools/best-practices/guides/scheduling.d.ts +1 -0
  130. package/dist/tools/best-practices/guides/scheduling.js +145 -0
  131. package/dist/tools/best-practices/guides/scheduling.js.map +1 -0
  132. package/dist/tools/best-practices/guides/scraping-and-research.d.ts +1 -0
  133. package/dist/tools/best-practices/guides/scraping-and-research.js +151 -0
  134. package/dist/tools/best-practices/guides/scraping-and-research.js.map +1 -0
  135. package/dist/tools/best-practices/guides/triage.d.ts +1 -0
  136. package/dist/tools/best-practices/guides/triage.js +142 -0
  137. package/dist/tools/best-practices/guides/triage.js.map +1 -0
  138. package/dist/tools/best-practices/index.d.ts +2 -0
  139. package/dist/tools/best-practices/index.js +34 -0
  140. package/dist/tools/best-practices/index.js.map +1 -0
  141. package/dist/tools/best-practices/techniques.d.ts +20 -0
  142. package/dist/tools/best-practices/techniques.js +40 -0
  143. package/dist/tools/best-practices/techniques.js.map +1 -0
  144. package/dist/tools/credentials/delete-credential.tool.d.ts +21 -0
  145. package/dist/tools/credentials/delete-credential.tool.js +51 -0
  146. package/dist/tools/credentials/delete-credential.tool.js.map +1 -0
  147. package/dist/tools/credentials/get-credential.tool.d.ts +4 -0
  148. package/dist/tools/credentials/get-credential.tool.js +26 -0
  149. package/dist/tools/credentials/get-credential.tool.js.map +1 -0
  150. package/dist/tools/credentials/list-credentials.tool.d.ts +6 -0
  151. package/dist/tools/credentials/list-credentials.tool.js +30 -0
  152. package/dist/tools/credentials/list-credentials.tool.js.map +1 -0
  153. package/dist/tools/credentials/search-credential-types.tool.d.ts +6 -0
  154. package/dist/tools/credentials/search-credential-types.tool.js +44 -0
  155. package/dist/tools/credentials/search-credential-types.tool.js.map +1 -0
  156. package/dist/tools/credentials/setup-credentials.tool.d.ts +73 -0
  157. package/dist/tools/credentials/setup-credentials.tool.js +134 -0
  158. package/dist/tools/credentials/setup-credentials.tool.js.map +1 -0
  159. package/dist/tools/credentials/test-credential.tool.d.ts +7 -0
  160. package/dist/tools/credentials/test-credential.tool.js +30 -0
  161. package/dist/tools/credentials/test-credential.tool.js.map +1 -0
  162. package/dist/tools/data-tables/add-data-table-column.tool.d.ts +27 -0
  163. package/dist/tools/data-tables/add-data-table-column.tool.js +60 -0
  164. package/dist/tools/data-tables/add-data-table-column.tool.js.map +1 -0
  165. package/dist/tools/data-tables/create-data-table.tool.d.ts +36 -0
  166. package/dist/tools/data-tables/create-data-table.tool.js +79 -0
  167. package/dist/tools/data-tables/create-data-table.tool.js.map +1 -0
  168. package/dist/tools/data-tables/delete-data-table-column.tool.d.ts +21 -0
  169. package/dist/tools/data-tables/delete-data-table-column.tool.js +48 -0
  170. package/dist/tools/data-tables/delete-data-table-column.tool.js.map +1 -0
  171. package/dist/tools/data-tables/delete-data-table-rows.tool.d.ts +29 -0
  172. package/dist/tools/data-tables/delete-data-table-rows.tool.js +63 -0
  173. package/dist/tools/data-tables/delete-data-table-rows.tool.js.map +1 -0
  174. package/dist/tools/data-tables/delete-data-table.tool.d.ts +20 -0
  175. package/dist/tools/data-tables/delete-data-table.tool.js +46 -0
  176. package/dist/tools/data-tables/delete-data-table.tool.js.map +1 -0
  177. package/dist/tools/data-tables/get-data-table-schema.tool.d.ts +11 -0
  178. package/dist/tools/data-tables/get-data-table-schema.tool.js +27 -0
  179. package/dist/tools/data-tables/get-data-table-schema.tool.js.map +1 -0
  180. package/dist/tools/data-tables/insert-data-table-rows.tool.d.ts +21 -0
  181. package/dist/tools/data-tables/insert-data-table-rows.tool.js +52 -0
  182. package/dist/tools/data-tables/insert-data-table-rows.tool.js.map +1 -0
  183. package/dist/tools/data-tables/list-data-tables.tool.d.ts +6 -0
  184. package/dist/tools/data-tables/list-data-tables.tool.js +32 -0
  185. package/dist/tools/data-tables/list-data-tables.tool.js.map +1 -0
  186. package/dist/tools/data-tables/query-data-table-rows.tool.d.ts +21 -0
  187. package/dist/tools/data-tables/query-data-table-rows.tool.js +54 -0
  188. package/dist/tools/data-tables/query-data-table-rows.tool.js.map +1 -0
  189. package/dist/tools/data-tables/rename-data-table-column.tool.d.ts +22 -0
  190. package/dist/tools/data-tables/rename-data-table-column.tool.js +49 -0
  191. package/dist/tools/data-tables/rename-data-table-column.tool.js.map +1 -0
  192. package/dist/tools/data-tables/update-data-table-rows.tool.d.ts +29 -0
  193. package/dist/tools/data-tables/update-data-table-rows.tool.js +57 -0
  194. package/dist/tools/data-tables/update-data-table-rows.tool.js.map +1 -0
  195. package/dist/tools/executions/debug-execution.tool.d.ts +4 -0
  196. package/dist/tools/executions/debug-execution.tool.js +41 -0
  197. package/dist/tools/executions/debug-execution.tool.js.map +1 -0
  198. package/dist/tools/executions/get-execution.tool.d.ts +4 -0
  199. package/dist/tools/executions/get-execution.tool.js +26 -0
  200. package/dist/tools/executions/get-execution.tool.js.map +1 -0
  201. package/dist/tools/executions/get-node-output.tool.d.ts +7 -0
  202. package/dist/tools/executions/get-node-output.tool.js +44 -0
  203. package/dist/tools/executions/get-node-output.tool.js.map +1 -0
  204. package/dist/tools/executions/list-executions.tool.d.ts +8 -0
  205. package/dist/tools/executions/list-executions.tool.js +45 -0
  206. package/dist/tools/executions/list-executions.tool.js.map +1 -0
  207. package/dist/tools/executions/run-workflow.tool.d.ts +24 -0
  208. package/dist/tools/executions/run-workflow.tool.js +82 -0
  209. package/dist/tools/executions/run-workflow.tool.js.map +1 -0
  210. package/dist/tools/executions/stop-execution.tool.d.ts +7 -0
  211. package/dist/tools/executions/stop-execution.tool.js +22 -0
  212. package/dist/tools/executions/stop-execution.tool.js.map +1 -0
  213. package/dist/tools/filesystem/create-tools-from-mcp-server.d.ts +3 -0
  214. package/dist/tools/filesystem/create-tools-from-mcp-server.js +61 -0
  215. package/dist/tools/filesystem/create-tools-from-mcp-server.js.map +1 -0
  216. package/dist/tools/filesystem/get-file-tree.tool.d.ts +22 -0
  217. package/dist/tools/filesystem/get-file-tree.tool.js +64 -0
  218. package/dist/tools/filesystem/get-file-tree.tool.js.map +1 -0
  219. package/dist/tools/filesystem/list-files.tool.d.ts +30 -0
  220. package/dist/tools/filesystem/list-files.tool.js +100 -0
  221. package/dist/tools/filesystem/list-files.tool.js.map +1 -0
  222. package/dist/tools/filesystem/read-file.tool.d.ts +25 -0
  223. package/dist/tools/filesystem/read-file.tool.js +83 -0
  224. package/dist/tools/filesystem/read-file.tool.js.map +1 -0
  225. package/dist/tools/filesystem/search-files.tool.d.ts +31 -0
  226. package/dist/tools/filesystem/search-files.tool.js +96 -0
  227. package/dist/tools/filesystem/search-files.tool.js.map +1 -0
  228. package/dist/tools/index.d.ts +2385 -0
  229. package/dist/tools/index.js +195 -0
  230. package/dist/tools/index.js.map +1 -0
  231. package/dist/tools/nodes/explore-node-resources.tool.d.ts +21 -0
  232. package/dist/tools/nodes/explore-node-resources.tool.js +71 -0
  233. package/dist/tools/nodes/explore-node-resources.tool.js.map +1 -0
  234. package/dist/tools/nodes/get-node-description.tool.d.ts +23 -0
  235. package/dist/tools/nodes/get-node-description.tool.js +52 -0
  236. package/dist/tools/nodes/get-node-description.tool.js.map +1 -0
  237. package/dist/tools/nodes/get-node-type-definition.tool.d.ts +17 -0
  238. package/dist/tools/nodes/get-node-type-definition.tool.js +73 -0
  239. package/dist/tools/nodes/get-node-type-definition.tool.js.map +1 -0
  240. package/dist/tools/nodes/get-suggested-nodes.tool.d.ts +14 -0
  241. package/dist/tools/nodes/get-suggested-nodes.tool.js +54 -0
  242. package/dist/tools/nodes/get-suggested-nodes.tool.js.map +1 -0
  243. package/dist/tools/nodes/list-nodes.tool.d.ts +6 -0
  244. package/dist/tools/nodes/list-nodes.tool.js +33 -0
  245. package/dist/tools/nodes/list-nodes.tool.js.map +1 -0
  246. package/dist/tools/nodes/node-search-engine.d.ts +18 -0
  247. package/dist/tools/nodes/node-search-engine.js +266 -0
  248. package/dist/tools/nodes/node-search-engine.js.map +1 -0
  249. package/dist/tools/nodes/node-search-engine.types.d.ts +38 -0
  250. package/dist/tools/nodes/node-search-engine.types.js +18 -0
  251. package/dist/tools/nodes/node-search-engine.types.js.map +1 -0
  252. package/dist/tools/nodes/search-nodes.tool.d.ts +28 -0
  253. package/dist/tools/nodes/search-nodes.tool.js +87 -0
  254. package/dist/tools/nodes/search-nodes.tool.js.map +1 -0
  255. package/dist/tools/nodes/suggested-nodes-data.d.ts +11 -0
  256. package/dist/tools/nodes/suggested-nodes-data.js +326 -0
  257. package/dist/tools/nodes/suggested-nodes-data.js.map +1 -0
  258. package/dist/tools/orchestration/browser-credential-setup.tool.d.ts +14 -0
  259. package/dist/tools/orchestration/browser-credential-setup.tool.js +429 -0
  260. package/dist/tools/orchestration/browser-credential-setup.tool.js.map +1 -0
  261. package/dist/tools/orchestration/build-workflow-agent.prompt.d.ts +2 -0
  262. package/dist/tools/orchestration/build-workflow-agent.prompt.js +836 -0
  263. package/dist/tools/orchestration/build-workflow-agent.prompt.js.map +1 -0
  264. package/dist/tools/orchestration/build-workflow-agent.tool.d.ts +23 -0
  265. package/dist/tools/orchestration/build-workflow-agent.tool.js +503 -0
  266. package/dist/tools/orchestration/build-workflow-agent.tool.js.map +1 -0
  267. package/dist/tools/orchestration/cancel-background-task.tool.d.ts +6 -0
  268. package/dist/tools/orchestration/cancel-background-task.tool.js +24 -0
  269. package/dist/tools/orchestration/cancel-background-task.tool.js.map +1 -0
  270. package/dist/tools/orchestration/correct-background-task.tool.d.ts +7 -0
  271. package/dist/tools/orchestration/correct-background-task.tool.js +41 -0
  272. package/dist/tools/orchestration/correct-background-task.tool.js.map +1 -0
  273. package/dist/tools/orchestration/data-table-agent.prompt.d.ts +1 -0
  274. package/dist/tools/orchestration/data-table-agent.prompt.js +29 -0
  275. package/dist/tools/orchestration/data-table-agent.prompt.js.map +1 -0
  276. package/dist/tools/orchestration/data-table-agent.tool.d.ts +21 -0
  277. package/dist/tools/orchestration/data-table-agent.tool.js +171 -0
  278. package/dist/tools/orchestration/data-table-agent.tool.js.map +1 -0
  279. package/dist/tools/orchestration/delegate.schemas.d.ts +32 -0
  280. package/dist/tools/orchestration/delegate.schemas.js +29 -0
  281. package/dist/tools/orchestration/delegate.schemas.js.map +1 -0
  282. package/dist/tools/orchestration/delegate.tool.d.ts +27 -0
  283. package/dist/tools/orchestration/delegate.tool.js +307 -0
  284. package/dist/tools/orchestration/delegate.tool.js.map +1 -0
  285. package/dist/tools/orchestration/display-utils.d.ts +1 -0
  286. package/dist/tools/orchestration/display-utils.js +8 -0
  287. package/dist/tools/orchestration/display-utils.js.map +1 -0
  288. package/dist/tools/orchestration/plan.tool.d.ts +45 -0
  289. package/dist/tools/orchestration/plan.tool.js +99 -0
  290. package/dist/tools/orchestration/plan.tool.js.map +1 -0
  291. package/dist/tools/orchestration/report-verification-verdict.tool.d.ts +14 -0
  292. package/dist/tools/orchestration/report-verification-verdict.tool.js +66 -0
  293. package/dist/tools/orchestration/report-verification-verdict.tool.js.map +1 -0
  294. package/dist/tools/orchestration/research-agent-prompt.d.ts +1 -0
  295. package/dist/tools/orchestration/research-agent-prompt.js +28 -0
  296. package/dist/tools/orchestration/research-agent-prompt.js.map +1 -0
  297. package/dist/tools/orchestration/research-with-agent.tool.d.ts +23 -0
  298. package/dist/tools/orchestration/research-with-agent.tool.js +160 -0
  299. package/dist/tools/orchestration/research-with-agent.tool.js.map +1 -0
  300. package/dist/tools/orchestration/tracing-utils.d.ts +20 -0
  301. package/dist/tools/orchestration/tracing-utils.js +102 -0
  302. package/dist/tools/orchestration/tracing-utils.js.map +1 -0
  303. package/dist/tools/orchestration/update-tasks.tool.d.ts +10 -0
  304. package/dist/tools/orchestration/update-tasks.tool.js +26 -0
  305. package/dist/tools/orchestration/update-tasks.tool.js.map +1 -0
  306. package/dist/tools/orchestration/verify-built-workflow.tool.d.ts +13 -0
  307. package/dist/tools/orchestration/verify-built-workflow.tool.js +58 -0
  308. package/dist/tools/orchestration/verify-built-workflow.tool.js.map +1 -0
  309. package/dist/tools/shared/ask-user.tool.d.ts +61 -0
  310. package/dist/tools/shared/ask-user.tool.js +98 -0
  311. package/dist/tools/shared/ask-user.tool.js.map +1 -0
  312. package/dist/tools/templates/search-template-parameters.tool.d.ts +11 -0
  313. package/dist/tools/templates/search-template-parameters.tool.js +55 -0
  314. package/dist/tools/templates/search-template-parameters.tool.js.map +1 -0
  315. package/dist/tools/templates/search-template-structures.tool.d.ts +12 -0
  316. package/dist/tools/templates/search-template-structures.tool.js +45 -0
  317. package/dist/tools/templates/search-template-structures.tool.js.map +1 -0
  318. package/dist/tools/templates/template-api.d.ts +21 -0
  319. package/dist/tools/templates/template-api.js +104 -0
  320. package/dist/tools/templates/template-api.js.map +1 -0
  321. package/dist/tools/templates/types.d.ts +52 -0
  322. package/dist/tools/templates/types.js +37 -0
  323. package/dist/tools/templates/types.js.map +1 -0
  324. package/dist/tools/utils/mermaid.utils.d.ts +15 -0
  325. package/dist/tools/utils/mermaid.utils.js +622 -0
  326. package/dist/tools/utils/mermaid.utils.js.map +1 -0
  327. package/dist/tools/utils/node-configuration.utils.d.ts +6 -0
  328. package/dist/tools/utils/node-configuration.utils.js +77 -0
  329. package/dist/tools/utils/node-configuration.utils.js.map +1 -0
  330. package/dist/tools/web-research/fetch-url.tool.d.ts +27 -0
  331. package/dist/tools/web-research/fetch-url.tool.js +116 -0
  332. package/dist/tools/web-research/fetch-url.tool.js.map +1 -0
  333. package/dist/tools/web-research/index.d.ts +1 -0
  334. package/dist/tools/web-research/index.js +6 -0
  335. package/dist/tools/web-research/index.js.map +1 -0
  336. package/dist/tools/web-research/sanitize-web-content.d.ts +3 -0
  337. package/dist/tools/web-research/sanitize-web-content.js +36 -0
  338. package/dist/tools/web-research/sanitize-web-content.js.map +1 -0
  339. package/dist/tools/web-research/web-search.tool.d.ts +6 -0
  340. package/dist/tools/web-research/web-search.tool.js +57 -0
  341. package/dist/tools/web-research/web-search.tool.js.map +1 -0
  342. package/dist/tools/workflows/apply-workflow-credentials.tool.d.ts +10 -0
  343. package/dist/tools/workflows/apply-workflow-credentials.tool.js +87 -0
  344. package/dist/tools/workflows/apply-workflow-credentials.tool.js.map +1 -0
  345. package/dist/tools/workflows/build-workflow.tool.d.ts +16 -0
  346. package/dist/tools/workflows/build-workflow.tool.js +163 -0
  347. package/dist/tools/workflows/build-workflow.tool.js.map +1 -0
  348. package/dist/tools/workflows/delete-workflow.tool.d.ts +21 -0
  349. package/dist/tools/workflows/delete-workflow.tool.js +51 -0
  350. package/dist/tools/workflows/delete-workflow.tool.js.map +1 -0
  351. package/dist/tools/workflows/get-workflow-as-code.tool.d.ts +14 -0
  352. package/dist/tools/workflows/get-workflow-as-code.tool.js +37 -0
  353. package/dist/tools/workflows/get-workflow-as-code.tool.js.map +1 -0
  354. package/dist/tools/workflows/get-workflow-version.tool.d.ts +21 -0
  355. package/dist/tools/workflows/get-workflow-version.tool.js +38 -0
  356. package/dist/tools/workflows/get-workflow-version.tool.js.map +1 -0
  357. package/dist/tools/workflows/get-workflow.tool.d.ts +18 -0
  358. package/dist/tools/workflows/get-workflow.tool.js +36 -0
  359. package/dist/tools/workflows/get-workflow.tool.js.map +1 -0
  360. package/dist/tools/workflows/list-workflow-versions.tool.d.ts +8 -0
  361. package/dist/tools/workflows/list-workflow-versions.tool.js +47 -0
  362. package/dist/tools/workflows/list-workflow-versions.tool.js.map +1 -0
  363. package/dist/tools/workflows/list-workflows.tool.d.ts +14 -0
  364. package/dist/tools/workflows/list-workflows.tool.js +42 -0
  365. package/dist/tools/workflows/list-workflows.tool.js.map +1 -0
  366. package/dist/tools/workflows/materialize-node-type.tool.d.ts +23 -0
  367. package/dist/tools/workflows/materialize-node-type.tool.js +105 -0
  368. package/dist/tools/workflows/materialize-node-type.tool.js.map +1 -0
  369. package/dist/tools/workflows/publish-workflow.tool.d.ts +24 -0
  370. package/dist/tools/workflows/publish-workflow.tool.js +92 -0
  371. package/dist/tools/workflows/publish-workflow.tool.js.map +1 -0
  372. package/dist/tools/workflows/resolve-credentials.d.ts +14 -0
  373. package/dist/tools/workflows/resolve-credentials.js +89 -0
  374. package/dist/tools/workflows/resolve-credentials.js.map +1 -0
  375. package/dist/tools/workflows/restore-workflow-version.tool.d.ts +22 -0
  376. package/dist/tools/workflows/restore-workflow-version.tool.js +65 -0
  377. package/dist/tools/workflows/restore-workflow-version.tool.js.map +1 -0
  378. package/dist/tools/workflows/setup-workflow.schema.d.ts +331 -0
  379. package/dist/tools/workflows/setup-workflow.schema.js +21 -0
  380. package/dist/tools/workflows/setup-workflow.schema.js.map +1 -0
  381. package/dist/tools/workflows/setup-workflow.service.d.ts +40 -0
  382. package/dist/tools/workflows/setup-workflow.service.js +470 -0
  383. package/dist/tools/workflows/setup-workflow.service.js.map +1 -0
  384. package/dist/tools/workflows/setup-workflow.tool.d.ts +150 -0
  385. package/dist/tools/workflows/setup-workflow.tool.js +219 -0
  386. package/dist/tools/workflows/setup-workflow.tool.js.map +1 -0
  387. package/dist/tools/workflows/submit-workflow.tool.d.ts +33 -0
  388. package/dist/tools/workflows/submit-workflow.tool.js +258 -0
  389. package/dist/tools/workflows/submit-workflow.tool.js.map +1 -0
  390. package/dist/tools/workflows/unpublish-workflow.tool.d.ts +22 -0
  391. package/dist/tools/workflows/unpublish-workflow.tool.js +61 -0
  392. package/dist/tools/workflows/unpublish-workflow.tool.js.map +1 -0
  393. package/dist/tools/workflows/update-workflow-version.tool.d.ts +9 -0
  394. package/dist/tools/workflows/update-workflow-version.tool.js +35 -0
  395. package/dist/tools/workflows/update-workflow-version.tool.js.map +1 -0
  396. package/dist/tools/workflows/write-sandbox-file.tool.d.ts +13 -0
  397. package/dist/tools/workflows/write-sandbox-file.tool.js +53 -0
  398. package/dist/tools/workflows/write-sandbox-file.tool.js.map +1 -0
  399. package/dist/tools/workspace/cleanup-test-executions.tool.d.ts +22 -0
  400. package/dist/tools/workspace/cleanup-test-executions.tool.js +58 -0
  401. package/dist/tools/workspace/cleanup-test-executions.tool.js.map +1 -0
  402. package/dist/tools/workspace/create-folder.tool.d.ts +24 -0
  403. package/dist/tools/workspace/create-folder.tool.js +59 -0
  404. package/dist/tools/workspace/create-folder.tool.js.map +1 -0
  405. package/dist/tools/workspace/delete-folder.tool.d.ts +24 -0
  406. package/dist/tools/workspace/delete-folder.tool.js +60 -0
  407. package/dist/tools/workspace/delete-folder.tool.js.map +1 -0
  408. package/dist/tools/workspace/list-folders.tool.d.ts +6 -0
  409. package/dist/tools/workspace/list-folders.tool.js +26 -0
  410. package/dist/tools/workspace/list-folders.tool.js.map +1 -0
  411. package/dist/tools/workspace/list-projects.tool.d.ts +4 -0
  412. package/dist/tools/workspace/list-projects.tool.js +24 -0
  413. package/dist/tools/workspace/list-projects.tool.js.map +1 -0
  414. package/dist/tools/workspace/list-tags.tool.d.ts +7 -0
  415. package/dist/tools/workspace/list-tags.tool.js +23 -0
  416. package/dist/tools/workspace/list-tags.tool.js.map +1 -0
  417. package/dist/tools/workspace/move-workflow-to-folder.tool.d.ts +23 -0
  418. package/dist/tools/workspace/move-workflow-to-folder.tool.js +56 -0
  419. package/dist/tools/workspace/move-workflow-to-folder.tool.js.map +1 -0
  420. package/dist/tools/workspace/tag-workflow.tool.d.ts +22 -0
  421. package/dist/tools/workspace/tag-workflow.tool.js +52 -0
  422. package/dist/tools/workspace/tag-workflow.tool.js.map +1 -0
  423. package/dist/tracing/langsmith-tracing.d.ts +56 -0
  424. package/dist/tracing/langsmith-tracing.js +810 -0
  425. package/dist/tracing/langsmith-tracing.js.map +1 -0
  426. package/dist/types.d.ts +709 -0
  427. package/dist/types.js +3 -0
  428. package/dist/types.js.map +1 -0
  429. package/dist/utils/agent-tree.d.ts +3 -0
  430. package/dist/utils/agent-tree.js +23 -0
  431. package/dist/utils/agent-tree.js.map +1 -0
  432. package/dist/utils/format-timestamp.d.ts +1 -0
  433. package/dist/utils/format-timestamp.js +19 -0
  434. package/dist/utils/format-timestamp.js.map +1 -0
  435. package/dist/utils/stream-helpers.d.ts +15 -0
  436. package/dist/utils/stream-helpers.js +26 -0
  437. package/dist/utils/stream-helpers.js.map +1 -0
  438. package/dist/workflow-builder/extract-code.d.ts +5 -0
  439. package/dist/workflow-builder/extract-code.js +105 -0
  440. package/dist/workflow-builder/extract-code.js.map +1 -0
  441. package/dist/workflow-builder/index.d.ts +5 -0
  442. package/dist/workflow-builder/index.js +19 -0
  443. package/dist/workflow-builder/index.js.map +1 -0
  444. package/dist/workflow-builder/parse-validate.d.ts +6 -0
  445. package/dist/workflow-builder/parse-validate.js +49 -0
  446. package/dist/workflow-builder/parse-validate.js.map +1 -0
  447. package/dist/workflow-builder/patch-code.d.ts +14 -0
  448. package/dist/workflow-builder/patch-code.js +117 -0
  449. package/dist/workflow-builder/patch-code.js.map +1 -0
  450. package/dist/workflow-builder/sdk-prompt-sections.d.ts +4 -0
  451. package/dist/workflow-builder/sdk-prompt-sections.js +517 -0
  452. package/dist/workflow-builder/sdk-prompt-sections.js.map +1 -0
  453. package/dist/workflow-builder/types.d.ts +11 -0
  454. package/dist/workflow-builder/types.js +3 -0
  455. package/dist/workflow-builder/types.js.map +1 -0
  456. package/dist/workflow-loop/guidance.d.ts +5 -0
  457. package/dist/workflow-loop/guidance.js +37 -0
  458. package/dist/workflow-loop/guidance.js.map +1 -0
  459. package/dist/workflow-loop/index.d.ts +5 -0
  460. package/dist/workflow-loop/index.js +25 -0
  461. package/dist/workflow-loop/index.js.map +1 -0
  462. package/dist/workflow-loop/runtime.d.ts +8 -0
  463. package/dist/workflow-loop/runtime.js +40 -0
  464. package/dist/workflow-loop/runtime.js.map +1 -0
  465. package/dist/workflow-loop/workflow-loop-controller.d.ts +11 -0
  466. package/dist/workflow-loop/workflow-loop-controller.js +212 -0
  467. package/dist/workflow-loop/workflow-loop-controller.js.map +1 -0
  468. package/dist/workflow-loop/workflow-loop-state.d.ts +189 -0
  469. package/dist/workflow-loop/workflow-loop-state.js +77 -0
  470. package/dist/workflow-loop/workflow-loop-state.js.map +1 -0
  471. package/dist/workflow-loop/workflow-task-service.d.ts +13 -0
  472. package/dist/workflow-loop/workflow-task-service.js +35 -0
  473. package/dist/workflow-loop/workflow-task-service.js.map +1 -0
  474. package/dist/workspace/builder-sandbox-factory.d.ts +25 -0
  475. package/dist/workspace/builder-sandbox-factory.js +199 -0
  476. package/dist/workspace/builder-sandbox-factory.js.map +1 -0
  477. package/dist/workspace/create-workspace.d.ts +33 -0
  478. package/dist/workspace/create-workspace.js +56 -0
  479. package/dist/workspace/create-workspace.js.map +1 -0
  480. package/dist/workspace/daytona-filesystem.d.ts +25 -0
  481. package/dist/workspace/daytona-filesystem.js +109 -0
  482. package/dist/workspace/daytona-filesystem.js.map +1 -0
  483. package/dist/workspace/n8n-sandbox-client.d.ts +105 -0
  484. package/dist/workspace/n8n-sandbox-client.js +335 -0
  485. package/dist/workspace/n8n-sandbox-client.js.map +1 -0
  486. package/dist/workspace/n8n-sandbox-filesystem.d.ts +25 -0
  487. package/dist/workspace/n8n-sandbox-filesystem.js +128 -0
  488. package/dist/workspace/n8n-sandbox-filesystem.js.map +1 -0
  489. package/dist/workspace/n8n-sandbox-image-manager.d.ts +5 -0
  490. package/dist/workspace/n8n-sandbox-image-manager.js +25 -0
  491. package/dist/workspace/n8n-sandbox-image-manager.js.map +1 -0
  492. package/dist/workspace/n8n-sandbox-sandbox.d.ts +27 -0
  493. package/dist/workspace/n8n-sandbox-sandbox.js +103 -0
  494. package/dist/workspace/n8n-sandbox-sandbox.js.map +1 -0
  495. package/dist/workspace/sandbox-fs.d.ts +9 -0
  496. package/dist/workspace/sandbox-fs.js +43 -0
  497. package/dist/workspace/sandbox-fs.js.map +1 -0
  498. package/dist/workspace/sandbox-setup.d.ts +11 -0
  499. package/dist/workspace/sandbox-setup.js +139 -0
  500. package/dist/workspace/sandbox-setup.js.map +1 -0
  501. package/dist/workspace/snapshot-manager.d.ts +8 -0
  502. package/dist/workspace/snapshot-manager.js +31 -0
  503. package/dist/workspace/snapshot-manager.js.map +1 -0
  504. package/package.json +54 -0
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.categories = void 0;
4
+ exports.categories = [
5
+ 'AI',
6
+ 'AI Chatbot',
7
+ 'AI RAG',
8
+ 'AI Summarization',
9
+ 'Content Creation',
10
+ 'CRM',
11
+ 'Crypto Trading',
12
+ 'DevOps',
13
+ 'Document Extraction',
14
+ 'Document Ops',
15
+ 'Engineering',
16
+ 'File Management',
17
+ 'HR',
18
+ 'Internal Wiki',
19
+ 'Invoice Processing',
20
+ 'IT Ops',
21
+ 'Lead Generation',
22
+ 'Lead Nurturing',
23
+ 'Marketing',
24
+ 'Market Research',
25
+ 'Miscellaneous',
26
+ 'Multimodal AI',
27
+ 'Other',
28
+ 'Personal Productivity',
29
+ 'Project Management',
30
+ 'Sales',
31
+ 'SecOps',
32
+ 'Social Media',
33
+ 'Support',
34
+ 'Support Chatbot',
35
+ 'Ticket Management',
36
+ ];
37
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/tools/templates/types.ts"],"names":[],"mappings":";;;AA0Ca,QAAA,UAAU,GAAG;IACzB,IAAI;IACJ,YAAY;IACZ,QAAQ;IACR,kBAAkB;IAClB,kBAAkB;IAClB,KAAK;IACL,gBAAgB;IAChB,QAAQ;IACR,qBAAqB;IACrB,cAAc;IACd,aAAa;IACb,iBAAiB;IACjB,IAAI;IACJ,eAAe;IACf,oBAAoB;IACpB,QAAQ;IACR,iBAAiB;IACjB,gBAAgB;IAChB,WAAW;IACX,iBAAiB;IACjB,eAAe;IACf,eAAe;IACf,OAAO;IACP,uBAAuB;IACvB,oBAAoB;IACpB,OAAO;IACP,QAAQ;IACR,cAAc;IACd,SAAS;IACT,iBAAiB;IACjB,mBAAmB;CACV,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { TemplateConnections, TemplateNode, WorkflowMetadata } from '../templates/types';
2
+ export interface MermaidWorkflowInput {
3
+ workflow: {
4
+ name?: string;
5
+ nodes: TemplateNode[];
6
+ connections: TemplateConnections;
7
+ };
8
+ }
9
+ export interface MermaidOptions {
10
+ includeNodeType?: boolean;
11
+ includeNodeParameters?: boolean;
12
+ includeNodeName?: boolean;
13
+ includeNodeId?: boolean;
14
+ }
15
+ export declare function mermaidStringify(input: WorkflowMetadata | MermaidWorkflowInput, options?: MermaidOptions): string;
@@ -0,0 +1,622 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mermaidStringify = mermaidStringify;
4
+ const DEFAULT_MERMAID_OPTIONS = {
5
+ includeNodeType: true,
6
+ includeNodeParameters: true,
7
+ includeNodeName: true,
8
+ includeNodeId: true,
9
+ };
10
+ const CONDITIONAL_NODE_TYPES = new Set([
11
+ 'n8n-nodes-base.if',
12
+ 'n8n-nodes-base.switch',
13
+ 'n8n-nodes-base.filter',
14
+ ]);
15
+ const AGENT_NODE_TYPE = '@n8n/n8n-nodes-langchain.agent';
16
+ const STICKY_NOTE_TYPE = 'n8n-nodes-base.stickyNote';
17
+ const DEFAULT_NODE_WIDTH = 100;
18
+ const DEFAULT_NODE_HEIGHT = 100;
19
+ const DEFAULT_STICKY_WIDTH = 150;
20
+ const DEFAULT_STICKY_HEIGHT = 80;
21
+ class MermaidBuilder {
22
+ nodes;
23
+ connections;
24
+ options;
25
+ nodeIdMap;
26
+ nodeByName;
27
+ stickyOverlaps;
28
+ agentSubgraphs;
29
+ nodesInSubgraphs;
30
+ definedNodes = new Set();
31
+ lines = [];
32
+ subgraphCounter = 0;
33
+ constructor(nodes, connections, options) {
34
+ const regularNodes = nodes.filter((n) => n.type !== STICKY_NOTE_TYPE);
35
+ const stickyNotes = nodes.filter((n) => n.type === STICKY_NOTE_TYPE);
36
+ this.nodes = regularNodes;
37
+ this.connections = connections;
38
+ this.options = options;
39
+ this.nodeIdMap = this.createNodeIdMap();
40
+ this.nodeByName = new Map(regularNodes.map((n) => [n.name, n]));
41
+ this.stickyOverlaps = this.categorizeStickyOverlaps(stickyNotes);
42
+ const nodesInStickySubgraphs = new Set();
43
+ for (const { nodeNames } of this.stickyOverlaps.multiNodeOverlap) {
44
+ for (const name of nodeNames) {
45
+ nodesInStickySubgraphs.add(name);
46
+ }
47
+ }
48
+ this.agentSubgraphs = this.findAgentSubgraphs(nodesInStickySubgraphs);
49
+ this.nodesInSubgraphs = new Set(nodesInStickySubgraphs);
50
+ for (const { agentNode, aiConnectedNodeNames } of this.agentSubgraphs) {
51
+ this.nodesInSubgraphs.add(agentNode.name);
52
+ for (const name of aiConnectedNodeNames) {
53
+ this.nodesInSubgraphs.add(name);
54
+ }
55
+ }
56
+ }
57
+ build() {
58
+ for (const sticky of this.stickyOverlaps.noOverlap) {
59
+ this.lines.push(this.formatStickyComment(sticky.content));
60
+ }
61
+ this.buildMainFlow();
62
+ this.buildStickySubgraphs();
63
+ this.buildAgentSubgraphs();
64
+ this.buildConnectionsToSubgraphs();
65
+ this.buildConnectionsFromSubgraphs();
66
+ this.buildInterSubgraphConnections();
67
+ return ['```mermaid', 'flowchart TD', ...this.lines, '```'];
68
+ }
69
+ createNodeIdMap() {
70
+ const map = new Map();
71
+ this.nodes.forEach((node, idx) => {
72
+ map.set(node.name, `n${idx + 1}`);
73
+ });
74
+ return map;
75
+ }
76
+ categorizeStickyOverlaps(stickyNotes) {
77
+ const result = {
78
+ noOverlap: [],
79
+ singleNodeOverlap: new Map(),
80
+ multiNodeOverlap: [],
81
+ };
82
+ for (const sticky of stickyNotes) {
83
+ const bounds = this.extractStickyBounds(sticky);
84
+ if (!bounds.content)
85
+ continue;
86
+ const overlappingNodes = this.nodes.filter((node) => this.isNodeWithinStickyBounds(node.position[0], node.position[1], bounds));
87
+ if (overlappingNodes.length === 0) {
88
+ result.noOverlap.push(bounds);
89
+ }
90
+ else if (overlappingNodes.length === 1) {
91
+ result.singleNodeOverlap.set(overlappingNodes[0].name, bounds);
92
+ }
93
+ else {
94
+ result.multiNodeOverlap.push({
95
+ sticky: bounds,
96
+ nodeNames: overlappingNodes.map((n) => n.name),
97
+ });
98
+ }
99
+ }
100
+ return result;
101
+ }
102
+ extractStickyBounds(node) {
103
+ return {
104
+ node,
105
+ x: node.position[0],
106
+ y: node.position[1],
107
+ width: typeof node.parameters.width === 'number' ? node.parameters.width : DEFAULT_STICKY_WIDTH,
108
+ height: typeof node.parameters.height === 'number' ? node.parameters.height : DEFAULT_STICKY_HEIGHT,
109
+ content: typeof node.parameters.content === 'string' ? node.parameters.content.trim() : '',
110
+ };
111
+ }
112
+ isNodeWithinStickyBounds(nodeX, nodeY, sticky) {
113
+ const nodeCenterX = nodeX + DEFAULT_NODE_WIDTH / 2;
114
+ const nodeCenterY = nodeY + DEFAULT_NODE_HEIGHT / 2;
115
+ return (nodeCenterX >= sticky.x &&
116
+ nodeCenterX <= sticky.x + sticky.width &&
117
+ nodeCenterY >= sticky.y &&
118
+ nodeCenterY <= sticky.y + sticky.height);
119
+ }
120
+ findAgentSubgraphs(nodesInStickySubgraphs) {
121
+ const agentSubgraphs = [];
122
+ const agentNodes = this.nodes.filter((n) => n.type === AGENT_NODE_TYPE && !nodesInStickySubgraphs.has(n.name));
123
+ const reverseConnections = this.buildReverseConnectionMap();
124
+ for (const agentNode of agentNodes) {
125
+ const incomingConns = reverseConnections.get(agentNode.name) ?? [];
126
+ const aiConnectedNodeNames = incomingConns
127
+ .filter(({ connType, sourceName }) => connType !== 'main' && !nodesInStickySubgraphs.has(sourceName))
128
+ .map(({ sourceName }) => sourceName);
129
+ const nestedStickySubgraphs = this.findNestedStickySubgraphs(incomingConns);
130
+ if (aiConnectedNodeNames.length > 0 || nestedStickySubgraphs.length > 0) {
131
+ agentSubgraphs.push({ agentNode, aiConnectedNodeNames, nestedStickySubgraphs });
132
+ }
133
+ }
134
+ return agentSubgraphs;
135
+ }
136
+ findNestedStickySubgraphs(incomingConns) {
137
+ const nested = [];
138
+ for (const stickySubgraph of this.stickyOverlaps.multiNodeOverlap) {
139
+ const allNodesConnectToAgent = stickySubgraph.nodeNames.every((nodeName) => incomingConns.some(({ sourceName, connType }) => sourceName === nodeName && connType !== 'main'));
140
+ if (allNodesConnectToAgent) {
141
+ nested.push(stickySubgraph);
142
+ }
143
+ }
144
+ return nested;
145
+ }
146
+ buildReverseConnectionMap() {
147
+ const reverseConnections = new Map();
148
+ for (const [sourceName, sourceConns] of Object.entries(this.connections)) {
149
+ for (const { nodeName: targetName, connType } of this.getConnectionTargets(sourceConns)) {
150
+ if (!reverseConnections.has(targetName)) {
151
+ reverseConnections.set(targetName, []);
152
+ }
153
+ reverseConnections.get(targetName).push({ sourceName, connType });
154
+ }
155
+ }
156
+ return reverseConnections;
157
+ }
158
+ getConnectionTargets(nodeConns) {
159
+ const targets = [];
160
+ for (const [connType, connList] of Object.entries(nodeConns)) {
161
+ for (const connArray of connList) {
162
+ if (!connArray)
163
+ continue;
164
+ for (const conn of connArray) {
165
+ targets.push({ nodeName: conn.node, connType });
166
+ }
167
+ }
168
+ }
169
+ return targets;
170
+ }
171
+ getMainConnectionTargets(nodeConns) {
172
+ if (!nodeConns.main)
173
+ return [];
174
+ return nodeConns.main
175
+ .filter((connArray) => connArray !== null)
176
+ .flatMap((connArray) => connArray.map((conn) => conn.node));
177
+ }
178
+ findStartNodes() {
179
+ const nodesWithIncoming = new Set();
180
+ Object.values(this.connections)
181
+ .filter((conn) => conn.main)
182
+ .forEach((sourceConnections) => {
183
+ for (const connArray of sourceConnections.main) {
184
+ if (!connArray)
185
+ continue;
186
+ for (const conn of connArray) {
187
+ nodesWithIncoming.add(conn.node);
188
+ }
189
+ }
190
+ });
191
+ return this.nodes.filter((n) => !nodesWithIncoming.has(n.name));
192
+ }
193
+ formatStickyComment(content) {
194
+ return `%% ${content.replace(/\n/g, ' ').replace(/\s+/g, ' ').trim()}`;
195
+ }
196
+ getNextSubgraphId() {
197
+ this.subgraphCounter++;
198
+ return `sg${this.subgraphCounter}`;
199
+ }
200
+ buildNodeDefinition(node, id) {
201
+ const isConditional = CONDITIONAL_NODE_TYPES.has(node.type);
202
+ if (this.options.includeNodeName) {
203
+ const escapedName = node.name.replace(/"/g, "'");
204
+ return isConditional ? `${id}{"${escapedName}"}` : `${id}["${escapedName}"]`;
205
+ }
206
+ return id;
207
+ }
208
+ buildNodeCommentLines(node) {
209
+ const lines = [];
210
+ if (this.options.includeNodeType ||
211
+ this.options.includeNodeParameters ||
212
+ this.options.includeNodeId) {
213
+ const idPart = this.options.includeNodeId && node.id ? `[${node.id}] ` : '';
214
+ const typePart = this.options.includeNodeType ? this.buildNodeTypePart(node) : '';
215
+ const paramsPart = this.options.includeNodeParameters && Object.keys(node.parameters).length > 0
216
+ ? ` | ${JSON.stringify(node.parameters)}`
217
+ : '';
218
+ if (idPart || typePart || paramsPart) {
219
+ lines.push(`%% ${idPart}${typePart}${paramsPart}`);
220
+ }
221
+ }
222
+ return lines;
223
+ }
224
+ buildNodeTypePart(node) {
225
+ const parts = [node.type];
226
+ if (typeof node.parameters.resource === 'string' && node.parameters.resource) {
227
+ parts.push(node.parameters.resource);
228
+ }
229
+ if (typeof node.parameters.operation === 'string' && node.parameters.operation) {
230
+ parts.push(node.parameters.operation);
231
+ }
232
+ return parts.join(':');
233
+ }
234
+ buildSingleNodeLines(node, id) {
235
+ const lines = this.buildNodeCommentLines(node);
236
+ lines.push(this.buildNodeDefinition(node, id));
237
+ return lines;
238
+ }
239
+ defineNodeIfNeeded(nodeName) {
240
+ const node = this.nodeByName.get(nodeName);
241
+ const id = this.nodeIdMap.get(nodeName);
242
+ if (!node || !id)
243
+ return id ?? '';
244
+ if (!this.definedNodes.has(nodeName)) {
245
+ this.definedNodes.add(nodeName);
246
+ const stickyForNode = this.stickyOverlaps.singleNodeOverlap.get(nodeName);
247
+ if (stickyForNode) {
248
+ this.lines.push(this.formatStickyComment(stickyForNode.content));
249
+ }
250
+ this.lines.push(...this.buildNodeCommentLines(node));
251
+ return this.buildNodeDefinition(node, id);
252
+ }
253
+ return id;
254
+ }
255
+ defineTargetAndConnect(sourceId, targetName, connType) {
256
+ const targetId = this.nodeIdMap.get(targetName);
257
+ if (!targetId)
258
+ return false;
259
+ if (!this.definedNodes.has(targetName)) {
260
+ const targetNode = this.nodeByName.get(targetName);
261
+ if (targetNode) {
262
+ const stickyForNode = this.stickyOverlaps.singleNodeOverlap.get(targetName);
263
+ if (stickyForNode) {
264
+ this.lines.push(this.formatStickyComment(stickyForNode.content));
265
+ }
266
+ this.lines.push(...this.buildNodeCommentLines(targetNode));
267
+ this.addConnection(sourceId, this.buildNodeDefinition(targetNode, targetId), connType);
268
+ this.definedNodes.add(targetName);
269
+ return connType === 'main';
270
+ }
271
+ }
272
+ else {
273
+ this.addConnection(sourceId, targetId, connType);
274
+ }
275
+ return false;
276
+ }
277
+ addConnection(sourceId, targetDef, connType) {
278
+ const arrow = connType === 'main' ? '-->' : `-.${connType}.->`;
279
+ this.lines.push(`${sourceId} ${arrow} ${targetDef}`);
280
+ }
281
+ buildMainFlow() {
282
+ const visited = new Set();
283
+ const startNodes = this.findStartNodes();
284
+ const traverse = (nodeName) => {
285
+ if (visited.has(nodeName))
286
+ return;
287
+ visited.add(nodeName);
288
+ const nodeConns = this.connections[nodeName];
289
+ const targets = nodeConns ? this.getConnectionTargets(nodeConns) : [];
290
+ for (const { nodeName: targetName, connType } of targets) {
291
+ if (this.nodesInSubgraphs.has(targetName) || this.nodesInSubgraphs.has(nodeName))
292
+ continue;
293
+ const sourceId = this.nodeIdMap.get(nodeName);
294
+ const targetDef = this.defineNodeIfNeeded(targetName);
295
+ if (sourceId) {
296
+ this.addConnection(sourceId, targetDef, connType);
297
+ }
298
+ }
299
+ if (nodeConns) {
300
+ this.getMainConnectionTargets(nodeConns)
301
+ .filter((target) => !this.nodesInSubgraphs.has(target))
302
+ .forEach((target) => traverse(target));
303
+ }
304
+ };
305
+ for (const startNode of startNodes) {
306
+ if (this.nodesInSubgraphs.has(startNode.name))
307
+ continue;
308
+ const id = this.nodeIdMap.get(startNode.name);
309
+ if (id && !this.definedNodes.has(startNode.name)) {
310
+ const stickyForNode = this.stickyOverlaps.singleNodeOverlap.get(startNode.name);
311
+ if (stickyForNode) {
312
+ this.lines.push(this.formatStickyComment(stickyForNode.content));
313
+ }
314
+ this.lines.push(...this.buildSingleNodeLines(startNode, id));
315
+ this.definedNodes.add(startNode.name);
316
+ }
317
+ traverse(startNode.name);
318
+ }
319
+ }
320
+ buildStickySubgraphs() {
321
+ const nestedStickyIds = this.getNestedStickyIds();
322
+ for (const { sticky, nodeNames } of this.stickyOverlaps.multiNodeOverlap) {
323
+ if (nestedStickyIds.has(sticky.node.id ?? ''))
324
+ continue;
325
+ this.buildSingleStickySubgraph(sticky, nodeNames);
326
+ }
327
+ }
328
+ getNestedStickyIds() {
329
+ const ids = new Set();
330
+ for (const { nestedStickySubgraphs } of this.agentSubgraphs) {
331
+ for (const { sticky } of nestedStickySubgraphs) {
332
+ ids.add(sticky.node.id ?? '');
333
+ }
334
+ }
335
+ return ids;
336
+ }
337
+ buildSingleStickySubgraph(sticky, nodeNames) {
338
+ const subgraphId = this.getNextSubgraphId();
339
+ const subgraphLabel = sticky.content.replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
340
+ this.lines.push(this.formatStickyComment(sticky.content));
341
+ this.lines.push(`subgraph ${subgraphId}["${subgraphLabel.replace(/"/g, "'")}"]`);
342
+ const subgraphNodeSet = new Set(nodeNames);
343
+ const subgraphDefinedNodes = new Set();
344
+ const startNodes = this.findSubgraphStartNodes(nodeNames, subgraphNodeSet);
345
+ for (const startNode of startNodes) {
346
+ const id = this.nodeIdMap.get(startNode.name);
347
+ if (id && !subgraphDefinedNodes.has(startNode.name)) {
348
+ this.lines.push(...this.buildSingleNodeLines(startNode, id));
349
+ subgraphDefinedNodes.add(startNode.name);
350
+ }
351
+ }
352
+ this.buildSubgraphInternalConnections(startNodes, subgraphNodeSet, subgraphDefinedNodes);
353
+ for (const name of nodeNames) {
354
+ this.definedNodes.add(name);
355
+ }
356
+ this.lines.push('end');
357
+ }
358
+ findSubgraphStartNodes(nodeNames, subgraphNodeSet) {
359
+ const nodesWithInternalIncoming = new Set();
360
+ for (const nodeName of nodeNames) {
361
+ const nodeConns = this.connections[nodeName];
362
+ if (!nodeConns)
363
+ continue;
364
+ for (const { nodeName: targetName } of this.getConnectionTargets(nodeConns)) {
365
+ if (subgraphNodeSet.has(targetName)) {
366
+ nodesWithInternalIncoming.add(targetName);
367
+ }
368
+ }
369
+ }
370
+ return nodeNames
371
+ .filter((name) => !nodesWithInternalIncoming.has(name))
372
+ .map((name) => this.nodeByName.get(name))
373
+ .filter((node) => node !== undefined);
374
+ }
375
+ buildSubgraphInternalConnections(startNodes, subgraphNodeSet, subgraphDefinedNodes) {
376
+ const visited = new Set();
377
+ const traverse = (nodeName) => {
378
+ if (visited.has(nodeName))
379
+ return;
380
+ visited.add(nodeName);
381
+ const nodeConns = this.connections[nodeName];
382
+ if (!nodeConns)
383
+ return;
384
+ const sourceId = this.nodeIdMap.get(nodeName);
385
+ if (!sourceId)
386
+ return;
387
+ for (const { nodeName: targetName, connType } of this.getConnectionTargets(nodeConns)) {
388
+ if (!subgraphNodeSet.has(targetName))
389
+ continue;
390
+ const targetId = this.nodeIdMap.get(targetName);
391
+ const targetNode = this.nodeByName.get(targetName);
392
+ if (!targetId || !targetNode)
393
+ continue;
394
+ const arrow = connType === 'main' ? '-->' : `-.${connType}.->`;
395
+ if (!subgraphDefinedNodes.has(targetName)) {
396
+ this.lines.push(...this.buildNodeCommentLines(targetNode));
397
+ this.lines.push(`${sourceId} ${arrow} ${this.buildNodeDefinition(targetNode, targetId)}`);
398
+ subgraphDefinedNodes.add(targetName);
399
+ }
400
+ else {
401
+ this.lines.push(`${sourceId} ${arrow} ${targetId}`);
402
+ }
403
+ }
404
+ this.getMainConnectionTargets(nodeConns)
405
+ .filter((t) => subgraphNodeSet.has(t))
406
+ .forEach((t) => traverse(t));
407
+ };
408
+ startNodes.forEach((n) => traverse(n.name));
409
+ }
410
+ buildAgentSubgraphs() {
411
+ for (const agentSubgraph of this.agentSubgraphs) {
412
+ this.buildSingleAgentSubgraph(agentSubgraph);
413
+ }
414
+ }
415
+ buildSingleAgentSubgraph(agentSubgraph) {
416
+ const { agentNode, aiConnectedNodeNames, nestedStickySubgraphs } = agentSubgraph;
417
+ const agentId = this.nodeIdMap.get(agentNode.name);
418
+ if (!agentId)
419
+ return;
420
+ const subgraphId = this.getNextSubgraphId();
421
+ this.lines.push(`subgraph ${subgraphId}["${agentNode.name.replace(/"/g, "'")}"]`);
422
+ for (const nodeName of aiConnectedNodeNames) {
423
+ this.defineAgentConnectedNode(nodeName);
424
+ }
425
+ for (const { sticky, nodeNames } of nestedStickySubgraphs) {
426
+ this.buildNestedStickySubgraph(sticky, nodeNames);
427
+ }
428
+ this.buildAgentNodeConnections(agentNode, agentId, aiConnectedNodeNames, nestedStickySubgraphs);
429
+ this.markAgentSubgraphNodesDefined(agentNode, aiConnectedNodeNames, nestedStickySubgraphs);
430
+ this.lines.push('end');
431
+ }
432
+ defineAgentConnectedNode(nodeName) {
433
+ const node = this.nodeByName.get(nodeName);
434
+ const id = this.nodeIdMap.get(nodeName);
435
+ if (!node || !id)
436
+ return;
437
+ const stickyForNode = this.stickyOverlaps.singleNodeOverlap.get(nodeName);
438
+ if (stickyForNode) {
439
+ this.lines.push(this.formatStickyComment(stickyForNode.content));
440
+ }
441
+ this.lines.push(...this.buildSingleNodeLines(node, id));
442
+ }
443
+ buildNestedStickySubgraph(sticky, nodeNames) {
444
+ const nestedSubgraphId = this.getNextSubgraphId();
445
+ const label = sticky.content.replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
446
+ this.lines.push(this.formatStickyComment(sticky.content));
447
+ this.lines.push(`subgraph ${nestedSubgraphId}["${label.replace(/"/g, "'")}"]`);
448
+ for (const nodeName of nodeNames) {
449
+ const node = this.nodeByName.get(nodeName);
450
+ const id = this.nodeIdMap.get(nodeName);
451
+ if (node && id) {
452
+ this.lines.push(...this.buildSingleNodeLines(node, id));
453
+ }
454
+ }
455
+ this.lines.push('end');
456
+ }
457
+ buildAgentNodeConnections(agentNode, agentId, aiConnectedNodeNames, nestedStickySubgraphs) {
458
+ const stickyForAgent = this.stickyOverlaps.singleNodeOverlap.get(agentNode.name);
459
+ if (stickyForAgent) {
460
+ this.lines.push(this.formatStickyComment(stickyForAgent.content));
461
+ }
462
+ this.lines.push(...this.buildNodeCommentLines(agentNode));
463
+ const allAiNodeNames = [
464
+ ...aiConnectedNodeNames,
465
+ ...nestedStickySubgraphs.flatMap(({ nodeNames }) => nodeNames),
466
+ ];
467
+ let agentDefined = false;
468
+ for (const nodeName of allAiNodeNames) {
469
+ const sourceId = this.nodeIdMap.get(nodeName);
470
+ const nodeConns = this.connections[nodeName];
471
+ if (!sourceId || !nodeConns)
472
+ continue;
473
+ for (const { nodeName: targetName, connType } of this.getConnectionTargets(nodeConns)) {
474
+ if (targetName !== agentNode.name || connType === 'main')
475
+ continue;
476
+ const arrow = `-.${connType}.->`;
477
+ if (!agentDefined) {
478
+ this.lines.push(`${sourceId} ${arrow} ${this.buildNodeDefinition(agentNode, agentId)}`);
479
+ agentDefined = true;
480
+ }
481
+ else {
482
+ this.lines.push(`${sourceId} ${arrow} ${agentId}`);
483
+ }
484
+ }
485
+ }
486
+ if (!agentDefined) {
487
+ this.lines.push(this.buildNodeDefinition(agentNode, agentId));
488
+ }
489
+ }
490
+ markAgentSubgraphNodesDefined(agentNode, aiConnectedNodeNames, nestedStickySubgraphs) {
491
+ for (const name of aiConnectedNodeNames) {
492
+ this.definedNodes.add(name);
493
+ }
494
+ for (const { nodeNames } of nestedStickySubgraphs) {
495
+ for (const name of nodeNames) {
496
+ this.definedNodes.add(name);
497
+ }
498
+ }
499
+ this.definedNodes.add(agentNode.name);
500
+ }
501
+ buildConnectionsToSubgraphs() {
502
+ for (const nodeName of this.definedNodes) {
503
+ if (this.nodesInSubgraphs.has(nodeName))
504
+ continue;
505
+ const nodeConns = this.connections[nodeName];
506
+ if (!nodeConns)
507
+ continue;
508
+ for (const { nodeName: targetName, connType } of this.getConnectionTargets(nodeConns)) {
509
+ if (this.nodesInSubgraphs.has(targetName)) {
510
+ const sourceId = this.nodeIdMap.get(nodeName);
511
+ const targetId = this.nodeIdMap.get(targetName);
512
+ if (sourceId && targetId) {
513
+ this.addConnection(sourceId, targetId, connType);
514
+ }
515
+ }
516
+ }
517
+ }
518
+ }
519
+ buildConnectionsFromSubgraphs() {
520
+ const nodesToProcess = [];
521
+ for (const nodeName of this.nodesInSubgraphs) {
522
+ const nodeConns = this.connections[nodeName];
523
+ if (!nodeConns)
524
+ continue;
525
+ const sourceId = this.nodeIdMap.get(nodeName);
526
+ if (!sourceId)
527
+ continue;
528
+ for (const { nodeName: targetName, connType } of this.getConnectionTargets(nodeConns)) {
529
+ if (this.nodesInSubgraphs.has(targetName))
530
+ continue;
531
+ const wasNewMainConnection = this.defineTargetAndConnect(sourceId, targetName, connType);
532
+ if (wasNewMainConnection) {
533
+ nodesToProcess.push(targetName);
534
+ }
535
+ }
536
+ }
537
+ this.continueTraversalFromNodes(nodesToProcess);
538
+ }
539
+ continueTraversalFromNodes(nodesToProcess) {
540
+ const visited = new Set();
541
+ const traverse = (nodeName) => {
542
+ if (visited.has(nodeName) || this.nodesInSubgraphs.has(nodeName))
543
+ return;
544
+ visited.add(nodeName);
545
+ const nodeConns = this.connections[nodeName];
546
+ if (!nodeConns)
547
+ return;
548
+ const sourceId = this.nodeIdMap.get(nodeName);
549
+ if (!sourceId)
550
+ return;
551
+ for (const { nodeName: targetName, connType } of this.getConnectionTargets(nodeConns)) {
552
+ if (this.nodesInSubgraphs.has(targetName)) {
553
+ const targetId = this.nodeIdMap.get(targetName);
554
+ if (targetId) {
555
+ this.addConnection(sourceId, targetId, connType);
556
+ }
557
+ continue;
558
+ }
559
+ this.defineTargetAndConnect(sourceId, targetName, connType);
560
+ }
561
+ this.getMainConnectionTargets(nodeConns)
562
+ .filter((t) => !this.nodesInSubgraphs.has(t))
563
+ .forEach((t) => traverse(t));
564
+ };
565
+ nodesToProcess.forEach((n) => traverse(n));
566
+ }
567
+ buildInterSubgraphConnections() {
568
+ const nestedStickyIds = this.getNestedStickyIds();
569
+ const outputConnections = new Set();
570
+ for (const nodeName of this.nodesInSubgraphs) {
571
+ const nodeConns = this.connections[nodeName];
572
+ if (!nodeConns)
573
+ continue;
574
+ for (const { nodeName: targetName, connType } of this.getConnectionTargets(nodeConns)) {
575
+ if (!this.nodesInSubgraphs.has(targetName))
576
+ continue;
577
+ if (this.isInNestedSticky(nodeName, nestedStickyIds))
578
+ continue;
579
+ if (this.isInNestedSticky(targetName, nestedStickyIds))
580
+ continue;
581
+ const sourceSubgraphId = this.getSubgraphId(nodeName, nestedStickyIds);
582
+ const targetSubgraphId = this.getSubgraphId(targetName, nestedStickyIds);
583
+ if (sourceSubgraphId === targetSubgraphId)
584
+ continue;
585
+ const sourceId = this.nodeIdMap.get(nodeName);
586
+ const targetId = this.nodeIdMap.get(targetName);
587
+ if (!sourceId || !targetId)
588
+ continue;
589
+ const connKey = `${sourceId}-${connType}-${targetId}`;
590
+ if (outputConnections.has(connKey))
591
+ continue;
592
+ outputConnections.add(connKey);
593
+ this.addConnection(sourceId, targetId, connType);
594
+ }
595
+ }
596
+ }
597
+ isInNestedSticky(nodeName, nestedStickyIds) {
598
+ return this.stickyOverlaps.multiNodeOverlap.some(({ sticky, nodeNames }) => nodeNames.includes(nodeName) && nestedStickyIds.has(sticky.node.id ?? ''));
599
+ }
600
+ getSubgraphId(nodeName, nestedStickyIds) {
601
+ const stickySubgraph = this.stickyOverlaps.multiNodeOverlap.find(({ sticky, nodeNames }) => nodeNames.includes(nodeName) && !nestedStickyIds.has(sticky.node.id ?? ''));
602
+ if (stickySubgraph) {
603
+ return `sticky:${stickySubgraph.sticky.node.id}`;
604
+ }
605
+ const agentSubgraph = this.agentSubgraphs.find(({ agentNode, aiConnectedNodeNames }) => agentNode.name === nodeName || aiConnectedNodeNames.includes(nodeName));
606
+ if (agentSubgraph) {
607
+ return `agent:${agentSubgraph.agentNode.id}`;
608
+ }
609
+ return 'none';
610
+ }
611
+ }
612
+ function mermaidStringify(input, options) {
613
+ const { workflow: wf } = input;
614
+ const mergedOptions = {
615
+ ...DEFAULT_MERMAID_OPTIONS,
616
+ ...options,
617
+ };
618
+ const builder = new MermaidBuilder(wf.nodes, wf.connections, mergedOptions);
619
+ const lines = builder.build();
620
+ return lines.join('\n');
621
+ }
622
+ //# sourceMappingURL=mermaid.utils.js.map