@octo-cyber/workflow 0.5.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 (297) hide show
  1. package/dist/controllers/ai-workflow-session.controller.d.ts +19 -0
  2. package/dist/controllers/ai-workflow-session.controller.d.ts.map +1 -0
  3. package/dist/controllers/ai-workflow-session.controller.js +135 -0
  4. package/dist/controllers/ai-workflow-session.controller.js.map +1 -0
  5. package/dist/controllers/credential.controller.d.ts +68 -0
  6. package/dist/controllers/credential.controller.d.ts.map +1 -0
  7. package/dist/controllers/credential.controller.js +303 -0
  8. package/dist/controllers/credential.controller.js.map +1 -0
  9. package/dist/controllers/index.d.ts +3 -0
  10. package/dist/controllers/index.d.ts.map +1 -0
  11. package/dist/controllers/index.js +8 -0
  12. package/dist/controllers/index.js.map +1 -0
  13. package/dist/controllers/workflow-ai.controller.d.ts +23 -0
  14. package/dist/controllers/workflow-ai.controller.d.ts.map +1 -0
  15. package/dist/controllers/workflow-ai.controller.js +164 -0
  16. package/dist/controllers/workflow-ai.controller.js.map +1 -0
  17. package/dist/controllers/workflow.controller.d.ts +66 -0
  18. package/dist/controllers/workflow.controller.d.ts.map +1 -0
  19. package/dist/controllers/workflow.controller.js +239 -0
  20. package/dist/controllers/workflow.controller.js.map +1 -0
  21. package/dist/core/expression-resolver.d.ts +49 -0
  22. package/dist/core/expression-resolver.d.ts.map +1 -0
  23. package/dist/core/expression-resolver.js +113 -0
  24. package/dist/core/expression-resolver.js.map +1 -0
  25. package/dist/core/node-registry.d.ts +24 -0
  26. package/dist/core/node-registry.d.ts.map +1 -0
  27. package/dist/core/node-registry.js +62 -0
  28. package/dist/core/node-registry.js.map +1 -0
  29. package/dist/core/workflow-executor.d.ts +50 -0
  30. package/dist/core/workflow-executor.d.ts.map +1 -0
  31. package/dist/core/workflow-executor.js +458 -0
  32. package/dist/core/workflow-executor.js.map +1 -0
  33. package/dist/entities/ai-workflow-session.entity.d.ts +17 -0
  34. package/dist/entities/ai-workflow-session.entity.d.ts.map +1 -0
  35. package/dist/entities/ai-workflow-session.entity.js +70 -0
  36. package/dist/entities/ai-workflow-session.entity.js.map +1 -0
  37. package/dist/entities/ai-workflow-version.entity.d.ts +18 -0
  38. package/dist/entities/ai-workflow-version.entity.d.ts.map +1 -0
  39. package/dist/entities/ai-workflow-version.entity.js +71 -0
  40. package/dist/entities/ai-workflow-version.entity.js.map +1 -0
  41. package/dist/entities/credential-definition.entity.d.ts +17 -0
  42. package/dist/entities/credential-definition.entity.d.ts.map +1 -0
  43. package/dist/entities/credential-definition.entity.js +66 -0
  44. package/dist/entities/credential-definition.entity.js.map +1 -0
  45. package/dist/entities/index.d.ts +9 -0
  46. package/dist/entities/index.d.ts.map +1 -0
  47. package/dist/entities/index.js +22 -0
  48. package/dist/entities/index.js.map +1 -0
  49. package/dist/entities/workflow-definition.entity.d.ts +20 -0
  50. package/dist/entities/workflow-definition.entity.d.ts.map +1 -0
  51. package/dist/entities/workflow-definition.entity.js +85 -0
  52. package/dist/entities/workflow-definition.entity.js.map +1 -0
  53. package/dist/entities/workflow-execution.entity.d.ts +26 -0
  54. package/dist/entities/workflow-execution.entity.d.ts.map +1 -0
  55. package/dist/entities/workflow-execution.entity.js +99 -0
  56. package/dist/entities/workflow-execution.entity.js.map +1 -0
  57. package/dist/index.d.ts +52 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +96 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/n8n/cipher/cipher.d.ts +11 -0
  62. package/dist/n8n/cipher/cipher.d.ts.map +1 -0
  63. package/dist/n8n/cipher/cipher.js +54 -0
  64. package/dist/n8n/cipher/cipher.js.map +1 -0
  65. package/dist/n8n/controllers/n8n-session.controller.d.ts +20 -0
  66. package/dist/n8n/controllers/n8n-session.controller.d.ts.map +1 -0
  67. package/dist/n8n/controllers/n8n-session.controller.js +84 -0
  68. package/dist/n8n/controllers/n8n-session.controller.js.map +1 -0
  69. package/dist/n8n/index.d.ts +8 -0
  70. package/dist/n8n/index.d.ts.map +1 -0
  71. package/dist/n8n/index.js +14 -0
  72. package/dist/n8n/index.js.map +1 -0
  73. package/dist/n8n/launcher/n8n-launcher.d.ts +41 -0
  74. package/dist/n8n/launcher/n8n-launcher.d.ts.map +1 -0
  75. package/dist/n8n/launcher/n8n-launcher.js +186 -0
  76. package/dist/n8n/launcher/n8n-launcher.js.map +1 -0
  77. package/dist/n8n/nodes/OctoClaudeCliTool.node.d.ts +13 -0
  78. package/dist/n8n/nodes/OctoClaudeCliTool.node.d.ts.map +1 -0
  79. package/dist/n8n/nodes/OctoClaudeCliTool.node.js +103 -0
  80. package/dist/n8n/nodes/OctoClaudeCliTool.node.js.map +1 -0
  81. package/dist/n8n/nodes/OctoCliChatModel.node.d.ts +14 -0
  82. package/dist/n8n/nodes/OctoCliChatModel.node.d.ts.map +1 -0
  83. package/dist/n8n/nodes/OctoCliChatModel.node.js +431 -0
  84. package/dist/n8n/nodes/OctoCliChatModel.node.js.map +1 -0
  85. package/dist/n8n/nodes/OctoCodexCliTool.node.d.ts +13 -0
  86. package/dist/n8n/nodes/OctoCodexCliTool.node.d.ts.map +1 -0
  87. package/dist/n8n/nodes/OctoCodexCliTool.node.js +100 -0
  88. package/dist/n8n/nodes/OctoCodexCliTool.node.js.map +1 -0
  89. package/dist/n8n/nodes/OctoGeminiCliTool.node.d.ts +13 -0
  90. package/dist/n8n/nodes/OctoGeminiCliTool.node.d.ts.map +1 -0
  91. package/dist/n8n/nodes/OctoGeminiCliTool.node.js +91 -0
  92. package/dist/n8n/nodes/OctoGeminiCliTool.node.js.map +1 -0
  93. package/dist/n8n/nodes/OctoKnowledge.node.d.ts +6 -0
  94. package/dist/n8n/nodes/OctoKnowledge.node.d.ts.map +1 -0
  95. package/dist/n8n/nodes/OctoKnowledge.node.js +95 -0
  96. package/dist/n8n/nodes/OctoKnowledge.node.js.map +1 -0
  97. package/dist/n8n/nodes/OctoNotification.node.d.ts +6 -0
  98. package/dist/n8n/nodes/OctoNotification.node.d.ts.map +1 -0
  99. package/dist/n8n/nodes/OctoNotification.node.js +72 -0
  100. package/dist/n8n/nodes/OctoNotification.node.js.map +1 -0
  101. package/dist/n8n/nodes/OctoSyncBridge.node.d.ts +6 -0
  102. package/dist/n8n/nodes/OctoSyncBridge.node.d.ts.map +1 -0
  103. package/dist/n8n/nodes/OctoSyncBridge.node.js +60 -0
  104. package/dist/n8n/nodes/OctoSyncBridge.node.js.map +1 -0
  105. package/dist/n8n/nodes/n8n-node-types.d.ts +111 -0
  106. package/dist/n8n/nodes/n8n-node-types.d.ts.map +1 -0
  107. package/dist/n8n/nodes/n8n-node-types.js +30 -0
  108. package/dist/n8n/nodes/n8n-node-types.js.map +1 -0
  109. package/dist/n8n/nodes/octo-cli-chat-model.svg +23 -0
  110. package/dist/n8n/nodes/package.json +16 -0
  111. package/dist/n8n/proxy/css-injector.d.ts +3 -0
  112. package/dist/n8n/proxy/css-injector.d.ts.map +1 -0
  113. package/dist/n8n/proxy/css-injector.js +62 -0
  114. package/dist/n8n/proxy/css-injector.js.map +1 -0
  115. package/dist/n8n/proxy/n8n-proxy.middleware.d.ts +12 -0
  116. package/dist/n8n/proxy/n8n-proxy.middleware.d.ts.map +1 -0
  117. package/dist/n8n/proxy/n8n-proxy.middleware.js +131 -0
  118. package/dist/n8n/proxy/n8n-proxy.middleware.js.map +1 -0
  119. package/dist/n8n/proxy/n8n-theme.css +45 -0
  120. package/dist/n8n/sync/n8n-user-sync.service.d.ts +75 -0
  121. package/dist/n8n/sync/n8n-user-sync.service.d.ts.map +1 -0
  122. package/dist/n8n/sync/n8n-user-sync.service.js +286 -0
  123. package/dist/n8n/sync/n8n-user-sync.service.js.map +1 -0
  124. package/dist/n8n/watcher/n8n-execution-watcher.d.ts +39 -0
  125. package/dist/n8n/watcher/n8n-execution-watcher.d.ts.map +1 -0
  126. package/dist/n8n/watcher/n8n-execution-watcher.js +110 -0
  127. package/dist/n8n/watcher/n8n-execution-watcher.js.map +1 -0
  128. package/dist/nodes/code.node.d.ts +24 -0
  129. package/dist/nodes/code.node.d.ts.map +1 -0
  130. package/dist/nodes/code.node.js +150 -0
  131. package/dist/nodes/code.node.js.map +1 -0
  132. package/dist/nodes/error-trigger.node.d.ts +15 -0
  133. package/dist/nodes/error-trigger.node.d.ts.map +1 -0
  134. package/dist/nodes/error-trigger.node.js +53 -0
  135. package/dist/nodes/error-trigger.node.js.map +1 -0
  136. package/dist/nodes/execute-command.node.d.ts +9 -0
  137. package/dist/nodes/execute-command.node.d.ts.map +1 -0
  138. package/dist/nodes/execute-command.node.js +81 -0
  139. package/dist/nodes/execute-command.node.js.map +1 -0
  140. package/dist/nodes/filter.node.d.ts +10 -0
  141. package/dist/nodes/filter.node.d.ts.map +1 -0
  142. package/dist/nodes/filter.node.js +95 -0
  143. package/dist/nodes/filter.node.js.map +1 -0
  144. package/dist/nodes/http-request.node.d.ts +11 -0
  145. package/dist/nodes/http-request.node.d.ts.map +1 -0
  146. package/dist/nodes/http-request.node.js +139 -0
  147. package/dist/nodes/http-request.node.js.map +1 -0
  148. package/dist/nodes/if.node.d.ts +13 -0
  149. package/dist/nodes/if.node.d.ts.map +1 -0
  150. package/dist/nodes/if.node.js +137 -0
  151. package/dist/nodes/if.node.js.map +1 -0
  152. package/dist/nodes/index.d.ts +12 -0
  153. package/dist/nodes/index.d.ts.map +1 -0
  154. package/dist/nodes/index.js +26 -0
  155. package/dist/nodes/index.js.map +1 -0
  156. package/dist/nodes/manual-trigger.node.d.ts +10 -0
  157. package/dist/nodes/manual-trigger.node.d.ts.map +1 -0
  158. package/dist/nodes/manual-trigger.node.js +36 -0
  159. package/dist/nodes/manual-trigger.node.js.map +1 -0
  160. package/dist/nodes/merge.node.d.ts +15 -0
  161. package/dist/nodes/merge.node.d.ts.map +1 -0
  162. package/dist/nodes/merge.node.js +99 -0
  163. package/dist/nodes/merge.node.js.map +1 -0
  164. package/dist/nodes/noop.node.d.ts +12 -0
  165. package/dist/nodes/noop.node.d.ts.map +1 -0
  166. package/dist/nodes/noop.node.js +32 -0
  167. package/dist/nodes/noop.node.js.map +1 -0
  168. package/dist/nodes/placeholder.node.d.ts +10 -0
  169. package/dist/nodes/placeholder.node.d.ts.map +1 -0
  170. package/dist/nodes/placeholder.node.js +50 -0
  171. package/dist/nodes/placeholder.node.js.map +1 -0
  172. package/dist/nodes/remove-duplicates.node.d.ts +9 -0
  173. package/dist/nodes/remove-duplicates.node.d.ts.map +1 -0
  174. package/dist/nodes/remove-duplicates.node.js +68 -0
  175. package/dist/nodes/remove-duplicates.node.js.map +1 -0
  176. package/dist/nodes/respond-to-webhook.node.d.ts +14 -0
  177. package/dist/nodes/respond-to-webhook.node.d.ts.map +1 -0
  178. package/dist/nodes/respond-to-webhook.node.js +116 -0
  179. package/dist/nodes/respond-to-webhook.node.js.map +1 -0
  180. package/dist/nodes/schedule-trigger.node.d.ts +9 -0
  181. package/dist/nodes/schedule-trigger.node.d.ts.map +1 -0
  182. package/dist/nodes/schedule-trigger.node.js +67 -0
  183. package/dist/nodes/schedule-trigger.node.js.map +1 -0
  184. package/dist/nodes/set.node.d.ts +12 -0
  185. package/dist/nodes/set.node.d.ts.map +1 -0
  186. package/dist/nodes/set.node.js +81 -0
  187. package/dist/nodes/set.node.js.map +1 -0
  188. package/dist/nodes/sort.node.d.ts +9 -0
  189. package/dist/nodes/sort.node.d.ts.map +1 -0
  190. package/dist/nodes/sort.node.js +61 -0
  191. package/dist/nodes/sort.node.js.map +1 -0
  192. package/dist/nodes/split-in-batches.node.d.ts +9 -0
  193. package/dist/nodes/split-in-batches.node.d.ts.map +1 -0
  194. package/dist/nodes/split-in-batches.node.js +53 -0
  195. package/dist/nodes/split-in-batches.node.js.map +1 -0
  196. package/dist/nodes/split-out.node.d.ts +9 -0
  197. package/dist/nodes/split-out.node.d.ts.map +1 -0
  198. package/dist/nodes/split-out.node.js +76 -0
  199. package/dist/nodes/split-out.node.js.map +1 -0
  200. package/dist/nodes/switch.node.d.ts +16 -0
  201. package/dist/nodes/switch.node.d.ts.map +1 -0
  202. package/dist/nodes/switch.node.js +156 -0
  203. package/dist/nodes/switch.node.js.map +1 -0
  204. package/dist/nodes/wait.node.d.ts +12 -0
  205. package/dist/nodes/wait.node.d.ts.map +1 -0
  206. package/dist/nodes/wait.node.js +81 -0
  207. package/dist/nodes/wait.node.js.map +1 -0
  208. package/dist/nodes/webhook.node.d.ts +9 -0
  209. package/dist/nodes/webhook.node.d.ts.map +1 -0
  210. package/dist/nodes/webhook.node.js +69 -0
  211. package/dist/nodes/webhook.node.js.map +1 -0
  212. package/dist/services/ai-workflow-session.service.d.ts +31 -0
  213. package/dist/services/ai-workflow-session.service.d.ts.map +1 -0
  214. package/dist/services/ai-workflow-session.service.js +118 -0
  215. package/dist/services/ai-workflow-session.service.js.map +1 -0
  216. package/dist/services/credential.service.d.ts +57 -0
  217. package/dist/services/credential.service.d.ts.map +1 -0
  218. package/dist/services/credential.service.js +155 -0
  219. package/dist/services/credential.service.js.map +1 -0
  220. package/dist/services/index.d.ts +10 -0
  221. package/dist/services/index.d.ts.map +1 -0
  222. package/dist/services/index.js +14 -0
  223. package/dist/services/index.js.map +1 -0
  224. package/dist/services/push.service.d.ts +60 -0
  225. package/dist/services/push.service.d.ts.map +1 -0
  226. package/dist/services/push.service.js +121 -0
  227. package/dist/services/push.service.js.map +1 -0
  228. package/dist/services/workflow-ai.service.d.ts +61 -0
  229. package/dist/services/workflow-ai.service.d.ts.map +1 -0
  230. package/dist/services/workflow-ai.service.js +219 -0
  231. package/dist/services/workflow-ai.service.js.map +1 -0
  232. package/dist/services/workflow-context.service.d.ts +32 -0
  233. package/dist/services/workflow-context.service.d.ts.map +1 -0
  234. package/dist/services/workflow-context.service.js +155 -0
  235. package/dist/services/workflow-context.service.js.map +1 -0
  236. package/dist/services/workflow-engine.service.d.ts +90 -0
  237. package/dist/services/workflow-engine.service.d.ts.map +1 -0
  238. package/dist/services/workflow-engine.service.js +305 -0
  239. package/dist/services/workflow-engine.service.js.map +1 -0
  240. package/dist/services/workflow.service.d.ts +84 -0
  241. package/dist/services/workflow.service.d.ts.map +1 -0
  242. package/dist/services/workflow.service.js +241 -0
  243. package/dist/services/workflow.service.js.map +1 -0
  244. package/dist/triggers/cron-trigger.d.ts +39 -0
  245. package/dist/triggers/cron-trigger.d.ts.map +1 -0
  246. package/dist/triggers/cron-trigger.js +137 -0
  247. package/dist/triggers/cron-trigger.js.map +1 -0
  248. package/dist/triggers/index.d.ts +3 -0
  249. package/dist/triggers/index.d.ts.map +1 -0
  250. package/dist/triggers/index.js +8 -0
  251. package/dist/triggers/index.js.map +1 -0
  252. package/dist/triggers/webhook-trigger.d.ts +51 -0
  253. package/dist/triggers/webhook-trigger.d.ts.map +1 -0
  254. package/dist/triggers/webhook-trigger.js +122 -0
  255. package/dist/triggers/webhook-trigger.js.map +1 -0
  256. package/dist/types/index.d.ts +5 -0
  257. package/dist/types/index.d.ts.map +1 -0
  258. package/dist/types/index.js +8 -0
  259. package/dist/types/index.js.map +1 -0
  260. package/dist/types/node.types.d.ts +313 -0
  261. package/dist/types/node.types.d.ts.map +1 -0
  262. package/dist/types/node.types.js +23 -0
  263. package/dist/types/node.types.js.map +1 -0
  264. package/dist/types/workflow.types.d.ts +153 -0
  265. package/dist/types/workflow.types.d.ts.map +1 -0
  266. package/dist/types/workflow.types.js +44 -0
  267. package/dist/types/workflow.types.js.map +1 -0
  268. package/dist/utils/n8n-converter.d.ts +52 -0
  269. package/dist/utils/n8n-converter.d.ts.map +1 -0
  270. package/dist/utils/n8n-converter.js +107 -0
  271. package/dist/utils/n8n-converter.js.map +1 -0
  272. package/dist/utils/n8n-node-map.d.ts +6 -0
  273. package/dist/utils/n8n-node-map.d.ts.map +1 -0
  274. package/dist/utils/n8n-node-map.js +59 -0
  275. package/dist/utils/n8n-node-map.js.map +1 -0
  276. package/dist/workflow.module.d.ts +40 -0
  277. package/dist/workflow.module.d.ts.map +1 -0
  278. package/dist/workflow.module.js +240 -0
  279. package/dist/workflow.module.js.map +1 -0
  280. package/package.json +97 -0
  281. package/web/components/ChatPanel.tsx +344 -0
  282. package/web/components/N8nIframe.tsx +119 -0
  283. package/web/components/SessionPanel.tsx +301 -0
  284. package/web/components/ToolPanel.tsx +404 -0
  285. package/web/components/WorkflowDiff.tsx +161 -0
  286. package/web/components/WorkflowGraph.tsx +158 -0
  287. package/web/components/WorkflowPreviewPanel.tsx +186 -0
  288. package/web/hooks/use-n8n-session.ts +46 -0
  289. package/web/index.ts +29 -0
  290. package/web/manifest.ts +16 -0
  291. package/web/messages/en-US.json +94 -0
  292. package/web/messages/zh-CN.json +94 -0
  293. package/web/pages/AiDesignPage.tsx +215 -0
  294. package/web/pages/CredentialsPage.tsx +7 -0
  295. package/web/pages/ExecutionsPage.tsx +7 -0
  296. package/web/pages/WorkflowsPage.tsx +7 -0
  297. package/web/services/workflow-ai-service.ts +173 -0
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.WorkflowContextService = void 0;
10
+ const promises_1 = require("node:fs/promises");
11
+ const node_path_1 = require("node:path");
12
+ const core_1 = require("@octo/core");
13
+ const ai_1 = require("@octo/ai");
14
+ const n8n_user_sync_service_js_1 = require("../n8n/sync/n8n-user-sync.service.js");
15
+ let WorkflowContextService = class WorkflowContextService {
16
+ logger = core_1.Container.get(core_1.LoggerService).child('WorkflowContext');
17
+ packagesDir = (0, node_path_1.resolve)(process.cwd(), '../../packages');
18
+ async listAiTools() {
19
+ const registry = core_1.Container.get(ai_1.CliRegistryService);
20
+ const toolInfos = await registry.getAvailableTools();
21
+ const tools = [];
22
+ for (const info of toolInfos) {
23
+ const models = await registry.getModels(info.name);
24
+ tools.push({
25
+ name: info.name,
26
+ displayName: info.displayName,
27
+ isAvailable: info.isAvailable,
28
+ models,
29
+ });
30
+ }
31
+ return tools;
32
+ }
33
+ async listApiDocs() {
34
+ const result = [];
35
+ try {
36
+ const entries = await (0, promises_1.readdir)(this.packagesDir);
37
+ for (const entry of entries) {
38
+ const docPath = (0, node_path_1.join)(this.packagesDir, entry, 'docs', 'api', 'rest-api.md');
39
+ try {
40
+ const s = await (0, promises_1.stat)(docPath);
41
+ if (s.isFile()) {
42
+ result.push({
43
+ moduleId: entry,
44
+ moduleName: `@octo/${entry}`,
45
+ docPath,
46
+ contentLength: s.size,
47
+ });
48
+ }
49
+ }
50
+ catch {
51
+ // doc file doesn't exist for this module
52
+ }
53
+ }
54
+ }
55
+ catch (err) {
56
+ this.logger.warn(`Failed to scan packages dir: ${err}`);
57
+ }
58
+ return result;
59
+ }
60
+ async getApiDocContent(moduleId) {
61
+ const docPath = (0, node_path_1.join)(this.packagesDir, moduleId, 'docs', 'api', 'rest-api.md');
62
+ try {
63
+ return await (0, promises_1.readFile)(docPath, 'utf-8');
64
+ }
65
+ catch {
66
+ throw core_1.AppError.notFound(`API doc not found for module: ${moduleId}`);
67
+ }
68
+ }
69
+ async listN8nWorkflows() {
70
+ const userSync = core_1.Container.get(n8n_user_sync_service_js_1.N8nUserSyncService);
71
+ const apiUrl = this.getN8nApiUrl();
72
+ try {
73
+ const response = await fetch(`${apiUrl}/rest/workflows`, {
74
+ headers: this.getN8nHeaders(userSync),
75
+ });
76
+ if (!response.ok) {
77
+ this.logger.warn(`Failed to list n8n workflows: ${response.status}`);
78
+ return [];
79
+ }
80
+ const body = (await response.json());
81
+ const data = body.data;
82
+ if (!Array.isArray(data))
83
+ return [];
84
+ return data.map((w) => ({
85
+ id: String(w.id),
86
+ name: String(w.name ?? ''),
87
+ active: Boolean(w.active),
88
+ createdAt: String(w.createdAt ?? ''),
89
+ updatedAt: String(w.updatedAt ?? ''),
90
+ }));
91
+ }
92
+ catch (err) {
93
+ this.logger.warn(`Failed to fetch n8n workflows: ${err}`);
94
+ return [];
95
+ }
96
+ }
97
+ async getN8nWorkflow(workflowId) {
98
+ const userSync = core_1.Container.get(n8n_user_sync_service_js_1.N8nUserSyncService);
99
+ const apiUrl = this.getN8nApiUrl();
100
+ const response = await fetch(`${apiUrl}/rest/workflows/${workflowId}`, { headers: this.getN8nHeaders(userSync) });
101
+ if (!response.ok) {
102
+ throw core_1.AppError.notFound(`n8n workflow ${workflowId} not found`);
103
+ }
104
+ const body = (await response.json());
105
+ return (body.data ?? body);
106
+ }
107
+ async updateN8nWorkflow(workflowId, workflowJson) {
108
+ const userSync = core_1.Container.get(n8n_user_sync_service_js_1.N8nUserSyncService);
109
+ const apiUrl = this.getN8nApiUrl();
110
+ // First deactivate the workflow
111
+ await fetch(`${apiUrl}/rest/workflows/${workflowId}`, {
112
+ method: 'PATCH',
113
+ headers: this.getN8nHeaders(userSync),
114
+ body: JSON.stringify({ active: false }),
115
+ });
116
+ // Parse and apply the new JSON
117
+ const parsed = JSON.parse(workflowJson);
118
+ const updatePayload = {
119
+ nodes: parsed.nodes,
120
+ connections: parsed.connections,
121
+ settings: parsed.settings,
122
+ name: parsed.name,
123
+ };
124
+ const response = await fetch(`${apiUrl}/rest/workflows/${workflowId}`, {
125
+ method: 'PUT',
126
+ headers: this.getN8nHeaders(userSync),
127
+ body: JSON.stringify(updatePayload),
128
+ });
129
+ if (!response.ok) {
130
+ const errBody = await response.text();
131
+ throw core_1.AppError.badRequest(`Failed to update n8n workflow: ${response.status} ${errBody}`);
132
+ }
133
+ this.logger.info(`Applied workflow JSON to n8n workflow ${workflowId}`);
134
+ }
135
+ getN8nApiUrl() {
136
+ const port = Number(process.env.N8N_PORT) || 5678;
137
+ return `http://127.0.0.1:${port}`;
138
+ }
139
+ getN8nHeaders(userSync) {
140
+ const headers = {
141
+ 'Content-Type': 'application/json',
142
+ };
143
+ // Access ownerCookie via runtime cast (same pattern as N8nExecutionWatcher)
144
+ const sync = userSync;
145
+ if (sync.ownerCookie) {
146
+ headers['Cookie'] = sync.ownerCookie;
147
+ }
148
+ return headers;
149
+ }
150
+ };
151
+ exports.WorkflowContextService = WorkflowContextService;
152
+ exports.WorkflowContextService = WorkflowContextService = __decorate([
153
+ (0, core_1.Service)()
154
+ ], WorkflowContextService);
155
+ //# sourceMappingURL=workflow-context.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-context.service.js","sourceRoot":"","sources":["../../src/services/workflow-context.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+CAA2D;AAC3D,yCAA0C;AAC1C,qCAAyE;AACzE,iCAA8C;AAC9C,mFAA0E;AAyBnE,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAChB,MAAM,GAAG,gBAAS,CAAC,GAAG,CAAC,oBAAa,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC/D,WAAW,GAAG,IAAA,mBAAO,EACpC,OAAO,CAAC,GAAG,EAAE,EACb,gBAAgB,CACjB,CAAC;IAEF,KAAK,CAAC,WAAW;QACf,MAAM,QAAQ,GAAG,gBAAS,CAAC,GAAG,CAAC,uBAAkB,CAAC,CAAC;QACnD,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,iBAAiB,EAAE,CAAC;QACrD,MAAM,KAAK,GAAiB,EAAE,CAAC;QAE/B,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnD,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,WAAW,EA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cAAO,GAAE;GACG,sBAAsB,CAyLlC"}
@@ -0,0 +1,90 @@
1
+ import { WorkflowDefinitionEntity } from '../entities/workflow-definition.entity.js';
2
+ import { WorkflowExecutionEntity } from '../entities/workflow-execution.entity.js';
3
+ import { NodeRegistry } from '../core/node-registry.js';
4
+ import type { INodeTypeDescription } from '../types/index.js';
5
+ /**
6
+ * WorkflowEngineService — bridges the n8n execution engine with Octo's
7
+ * module system.
8
+ *
9
+ * Responsibilities:
10
+ * - Wraps Octo's WorkflowExecutor and provides a clean high-level API
11
+ * - Manages the node registry (built-in + n8n nodes)
12
+ * - Persists execution results to the database
13
+ * - Pushes real-time execution events via PushService
14
+ * - Tracks running executions for cancellation
15
+ *
16
+ * Future: When the n8n WorkflowExecute class is fully integrated (all TODOs
17
+ * resolved), this service can swap to use it instead of the simpler
18
+ * Octo WorkflowExecutor. The external API remains the same.
19
+ */
20
+ export declare class WorkflowEngineService {
21
+ private workflowRepo;
22
+ private executionRepo;
23
+ private logger;
24
+ private executor;
25
+ private nodeRegistry;
26
+ private pushService;
27
+ /** Track running executions so we can cancel them. */
28
+ private runningExecutions;
29
+ /**
30
+ * Initialize the engine. Must be called after DataSource is ready.
31
+ *
32
+ * - Obtains TypeORM repositories
33
+ * - Built-in Octo nodes are registered separately in WorkflowModule.initialize()
34
+ * - n8n nodes will be registered here once fully integrated
35
+ */
36
+ initialize(): void;
37
+ /**
38
+ * Return all registered node type descriptions.
39
+ * Used by the editor to populate the node panel.
40
+ */
41
+ getNodeTypes(): INodeTypeDescription[];
42
+ /**
43
+ * Get the underlying NodeRegistry for direct access.
44
+ */
45
+ getNodeRegistry(): NodeRegistry;
46
+ /**
47
+ * Execute a workflow by ID.
48
+ *
49
+ * @param workflowId - The workflow definition UUID
50
+ * @param mode - Execution mode (manual | trigger | webhook | retry)
51
+ * @param triggerData - Optional data from the trigger/manual input
52
+ * @param retryOf - If this is a retry, the original execution ID
53
+ * @returns The completed (or failed) WorkflowExecutionEntity
54
+ */
55
+ executeWorkflow(workflowId: string, mode?: string, triggerData?: Record<string, unknown>, retryOf?: string): Promise<WorkflowExecutionEntity>;
56
+ /**
57
+ * Stop a running execution by ID.
58
+ *
59
+ * Currently marks the execution as canceled in the database.
60
+ * Once the n8n WorkflowExecute (PCancelable) is integrated,
61
+ * this will actually abort the running Promise.
62
+ */
63
+ stopExecution(executionId: string): Promise<WorkflowExecutionEntity>;
64
+ /**
65
+ * Activate a workflow's triggers.
66
+ * Sets the `active` flag to true and restarts cron/webhook triggers.
67
+ */
68
+ activateWorkflow(workflowId: string): Promise<WorkflowDefinitionEntity>;
69
+ /**
70
+ * Deactivate a workflow's triggers.
71
+ * Sets the `active` flag to false and stops cron/webhook triggers.
72
+ */
73
+ deactivateWorkflow(workflowId: string): Promise<WorkflowDefinitionEntity>;
74
+ /**
75
+ * Get execution history for a workflow (paginated).
76
+ */
77
+ getExecutions(workflowId: string, page?: number, pageSize?: number): Promise<{
78
+ items: WorkflowExecutionEntity[];
79
+ total: number;
80
+ }>;
81
+ /**
82
+ * Get a single execution by ID.
83
+ */
84
+ getExecution(executionId: string): Promise<WorkflowExecutionEntity>;
85
+ /**
86
+ * Get the count of currently running executions.
87
+ */
88
+ get runningCount(): number;
89
+ }
90
+ //# sourceMappingURL=workflow-engine.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-engine.service.d.ts","sourceRoot":"","sources":["../../src/services/workflow-engine.service.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AAEnF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,KAAK,EAIV,oBAAoB,EAErB,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;;GAcG;AACH,qBACa,qBAAqB;IAChC,OAAO,CAAC,YAAY,CAAwC;IAC5D,OAAO,CAAC,aAAa,CAAuC;IAC5D,OAAO,CAAC,MAAM,CAA+D;IAC7E,OAAO,CAAC,QAAQ,CAA0B;IAC1C,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,WAAW,CAA8B;IAEjD,sDAAsD;IACtD,OAAO,CAAC,iBAAiB,CAAsC;IAI/D;;;;;;OAMG;IACH,UAAU,IAAI,IAAI;IASlB;;;OAGG;IACH,YAAY,IAAI,oBAAoB,EAAE;IAItC;;OAEG;IACH,eAAe,IAAI,YAAY;IAM/B;;;;;;;;OAQG;IACG,eAAe,CACnB,UAAU,EAAE,MAAM,EAClB,IAAI,SAAW,EACf,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,uBAAuB,CAAC;IAiJnC;;;;;;OAMG;IACG,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAqC1E;;;OAGG;IACG,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAkB7E;;;OAGG;IACG,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAmB/E;;OAEG;IACG,aAAa,CACjB,UAAU,EAAE,MAAM,EAClB,IAAI,SAAI,EACR,QAAQ,SAAK,GACZ,OAAO,CAAC;QAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAU/D;;OAEG;IACG,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAQzE;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;CACF"}
@@ -0,0 +1,305 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.WorkflowEngineService = void 0;
10
+ const core_1 = require("@octo/core");
11
+ const workflow_definition_entity_js_1 = require("../entities/workflow-definition.entity.js");
12
+ const workflow_execution_entity_js_1 = require("../entities/workflow-execution.entity.js");
13
+ const workflow_executor_js_1 = require("../core/workflow-executor.js");
14
+ const node_registry_js_1 = require("../core/node-registry.js");
15
+ const push_service_js_1 = require("./push.service.js");
16
+ /**
17
+ * WorkflowEngineService — bridges the n8n execution engine with Octo's
18
+ * module system.
19
+ *
20
+ * Responsibilities:
21
+ * - Wraps Octo's WorkflowExecutor and provides a clean high-level API
22
+ * - Manages the node registry (built-in + n8n nodes)
23
+ * - Persists execution results to the database
24
+ * - Pushes real-time execution events via PushService
25
+ * - Tracks running executions for cancellation
26
+ *
27
+ * Future: When the n8n WorkflowExecute class is fully integrated (all TODOs
28
+ * resolved), this service can swap to use it instead of the simpler
29
+ * Octo WorkflowExecutor. The external API remains the same.
30
+ */
31
+ let WorkflowEngineService = class WorkflowEngineService {
32
+ workflowRepo;
33
+ executionRepo;
34
+ logger = core_1.Container.get(core_1.LoggerService).child('WorkflowEngineService');
35
+ executor = new workflow_executor_js_1.WorkflowExecutor();
36
+ nodeRegistry = core_1.Container.get(node_registry_js_1.NodeRegistry);
37
+ pushService = core_1.Container.get(push_service_js_1.PushService);
38
+ /** Track running executions so we can cancel them. */
39
+ runningExecutions = new Map();
40
+ // ── Lifecycle ────────────────────────────────────────────────
41
+ /**
42
+ * Initialize the engine. Must be called after DataSource is ready.
43
+ *
44
+ * - Obtains TypeORM repositories
45
+ * - Built-in Octo nodes are registered separately in WorkflowModule.initialize()
46
+ * - n8n nodes will be registered here once fully integrated
47
+ */
48
+ initialize() {
49
+ const db = core_1.Container.get(core_1.DatabaseService);
50
+ this.workflowRepo = db.getRepository(workflow_definition_entity_js_1.WorkflowDefinitionEntity);
51
+ this.executionRepo = db.getRepository(workflow_execution_entity_js_1.WorkflowExecutionEntity);
52
+ this.logger.info('WorkflowEngineService initialized');
53
+ }
54
+ // ── Node Registry ────────────────────────────────────────────
55
+ /**
56
+ * Return all registered node type descriptions.
57
+ * Used by the editor to populate the node panel.
58
+ */
59
+ getNodeTypes() {
60
+ return this.nodeRegistry.getAllDescriptions();
61
+ }
62
+ /**
63
+ * Get the underlying NodeRegistry for direct access.
64
+ */
65
+ getNodeRegistry() {
66
+ return this.nodeRegistry;
67
+ }
68
+ // ── Execution ────────────────────────────────────────────────
69
+ /**
70
+ * Execute a workflow by ID.
71
+ *
72
+ * @param workflowId - The workflow definition UUID
73
+ * @param mode - Execution mode (manual | trigger | webhook | retry)
74
+ * @param triggerData - Optional data from the trigger/manual input
75
+ * @param retryOf - If this is a retry, the original execution ID
76
+ * @returns The completed (or failed) WorkflowExecutionEntity
77
+ */
78
+ async executeWorkflow(workflowId, mode = 'manual', triggerData, retryOf) {
79
+ // 1. Load the workflow definition
80
+ const workflow = await this.workflowRepo.findOneBy({ id: workflowId });
81
+ if (!workflow) {
82
+ throw core_1.AppError.notFound(`Workflow not found: ${workflowId}`);
83
+ }
84
+ // Parse the stored JSON definition
85
+ let definition;
86
+ try {
87
+ definition = JSON.parse(workflow.definition);
88
+ }
89
+ catch {
90
+ throw core_1.AppError.badRequest(`Invalid workflow definition JSON for workflow: ${workflowId}`);
91
+ }
92
+ // 2. Create the execution record
93
+ const execution = this.executionRepo.create({
94
+ workflowId,
95
+ status: 'running',
96
+ finished: false,
97
+ mode,
98
+ triggerData: triggerData ? JSON.stringify(triggerData) : null,
99
+ retryOf: retryOf ?? null,
100
+ startedAt: new Date(),
101
+ });
102
+ const savedExecution = await this.executionRepo.save(execution);
103
+ const executionId = savedExecution.id;
104
+ this.logger.info(`Executing workflow: ${workflowId} (execution: ${executionId}, mode: ${mode})`);
105
+ // 3. Push executionStarted event
106
+ this.pushService.broadcast('executionStarted', {
107
+ executionId,
108
+ workflowId,
109
+ mode,
110
+ });
111
+ // 4. Set up abort controller for cancellation
112
+ const abortController = new AbortController();
113
+ this.runningExecutions.set(executionId, abortController);
114
+ try {
115
+ // Prepare trigger data as INodeExecutionData[]
116
+ const triggerItems = triggerData
117
+ ? [{ json: triggerData }]
118
+ : undefined;
119
+ // 5. Run the executor
120
+ const result = await this.executor.execute(definition, triggerItems);
121
+ // 6. Serialize the result — Map must be converted to a plain object
122
+ const serializedNodeResults = {};
123
+ for (const [key, value] of result.nodeResults) {
124
+ serializedNodeResults[key] = value;
125
+ // Push per-node events
126
+ this.pushService.broadcast('nodeExecuteAfter', {
127
+ executionId,
128
+ nodeName: value.nodeName,
129
+ data: {
130
+ status: value.status,
131
+ error: value.error,
132
+ startTime: value.startTime,
133
+ endTime: value.endTime,
134
+ },
135
+ });
136
+ }
137
+ const serializedResult = {
138
+ status: result.status,
139
+ startedAt: result.startedAt,
140
+ completedAt: result.completedAt,
141
+ nodeResults: serializedNodeResults,
142
+ error: result.error,
143
+ };
144
+ // 7. Persist
145
+ savedExecution.status = result.status === 'completed' ? 'completed' : 'failed';
146
+ savedExecution.finished = true;
147
+ savedExecution.result = JSON.stringify(serializedResult);
148
+ savedExecution.error = result.error ?? null;
149
+ savedExecution.completedAt = new Date();
150
+ await this.executionRepo.save(savedExecution);
151
+ this.logger.info(`Workflow execution ${executionId} finished: ${savedExecution.status}`);
152
+ // 8. Push executionFinished event
153
+ this.pushService.broadcast('executionFinished', {
154
+ executionId,
155
+ workflowId,
156
+ status: savedExecution.status,
157
+ data: serializedResult,
158
+ });
159
+ // 9. Emit EventBus event for notification integration
160
+ core_1.EventBus.emit('n8n:executionFinished', {
161
+ executionId,
162
+ workflowId,
163
+ workflowName: workflow.name,
164
+ status: savedExecution.status === 'completed' ? 'success' : 'error',
165
+ startedAt: savedExecution.startedAt.toISOString(),
166
+ stoppedAt: savedExecution.completedAt?.toISOString() ?? null,
167
+ error: savedExecution.error ?? undefined,
168
+ });
169
+ return savedExecution;
170
+ }
171
+ catch (error) {
172
+ const errorMsg = error instanceof Error ? error.message : String(error);
173
+ savedExecution.status = 'failed';
174
+ savedExecution.finished = true;
175
+ savedExecution.error = errorMsg;
176
+ savedExecution.completedAt = new Date();
177
+ await this.executionRepo.save(savedExecution);
178
+ this.logger.error(`Workflow execution ${executionId} failed: ${errorMsg}`);
179
+ // Push failure event
180
+ this.pushService.broadcast('executionFinished', {
181
+ executionId,
182
+ workflowId,
183
+ status: 'failed',
184
+ error: errorMsg,
185
+ });
186
+ // Emit EventBus event for notification integration
187
+ core_1.EventBus.emit('n8n:executionFinished', {
188
+ executionId,
189
+ workflowId,
190
+ workflowName: workflow.name,
191
+ status: 'error',
192
+ startedAt: savedExecution.startedAt.toISOString(),
193
+ stoppedAt: savedExecution.completedAt?.toISOString() ?? null,
194
+ error: errorMsg,
195
+ });
196
+ return savedExecution;
197
+ }
198
+ finally {
199
+ this.runningExecutions.delete(executionId);
200
+ }
201
+ }
202
+ /**
203
+ * Stop a running execution by ID.
204
+ *
205
+ * Currently marks the execution as canceled in the database.
206
+ * Once the n8n WorkflowExecute (PCancelable) is integrated,
207
+ * this will actually abort the running Promise.
208
+ */
209
+ async stopExecution(executionId) {
210
+ const execution = await this.executionRepo.findOneBy({ id: executionId });
211
+ if (!execution) {
212
+ throw core_1.AppError.notFound(`Execution not found: ${executionId}`);
213
+ }
214
+ if (execution.finished) {
215
+ throw core_1.AppError.badRequest(`Execution ${executionId} is already finished`);
216
+ }
217
+ // Abort if still running
218
+ const abortController = this.runningExecutions.get(executionId);
219
+ if (abortController) {
220
+ abortController.abort();
221
+ this.runningExecutions.delete(executionId);
222
+ }
223
+ // Update database
224
+ execution.status = 'canceled';
225
+ execution.finished = true;
226
+ execution.completedAt = new Date();
227
+ await this.executionRepo.save(execution);
228
+ this.logger.info(`Execution ${executionId} canceled`);
229
+ // Push cancellation event
230
+ this.pushService.broadcast('executionFinished', {
231
+ executionId,
232
+ workflowId: execution.workflowId,
233
+ status: 'canceled',
234
+ });
235
+ return execution;
236
+ }
237
+ // ── Activation / Deactivation ────────────────────────────────
238
+ /**
239
+ * Activate a workflow's triggers.
240
+ * Sets the `active` flag to true and restarts cron/webhook triggers.
241
+ */
242
+ async activateWorkflow(workflowId) {
243
+ const workflow = await this.workflowRepo.findOneBy({ id: workflowId });
244
+ if (!workflow) {
245
+ throw core_1.AppError.notFound(`Workflow not found: ${workflowId}`);
246
+ }
247
+ workflow.active = true;
248
+ workflow.status = 'active';
249
+ const saved = await this.workflowRepo.save(workflow);
250
+ this.logger.info(`Workflow ${workflowId} activated`);
251
+ // TODO: [Octo] Re-register cron/webhook triggers via CronTriggerService / WebhookTriggerService
252
+ // This will be wired up when the trigger services are refactored to use WorkflowEngineService.
253
+ return saved;
254
+ }
255
+ /**
256
+ * Deactivate a workflow's triggers.
257
+ * Sets the `active` flag to false and stops cron/webhook triggers.
258
+ */
259
+ async deactivateWorkflow(workflowId) {
260
+ const workflow = await this.workflowRepo.findOneBy({ id: workflowId });
261
+ if (!workflow) {
262
+ throw core_1.AppError.notFound(`Workflow not found: ${workflowId}`);
263
+ }
264
+ workflow.active = false;
265
+ workflow.status = 'inactive';
266
+ const saved = await this.workflowRepo.save(workflow);
267
+ this.logger.info(`Workflow ${workflowId} deactivated`);
268
+ // TODO: [Octo] Unregister cron/webhook triggers via CronTriggerService / WebhookTriggerService
269
+ return saved;
270
+ }
271
+ // ── Queries ──────────────────────────────────────────────────
272
+ /**
273
+ * Get execution history for a workflow (paginated).
274
+ */
275
+ async getExecutions(workflowId, page = 1, pageSize = 20) {
276
+ const [items, total] = await this.executionRepo.findAndCount({
277
+ where: { workflowId },
278
+ order: { startedAt: 'DESC' },
279
+ skip: (page - 1) * pageSize,
280
+ take: pageSize,
281
+ });
282
+ return { items, total };
283
+ }
284
+ /**
285
+ * Get a single execution by ID.
286
+ */
287
+ async getExecution(executionId) {
288
+ const execution = await this.executionRepo.findOneBy({ id: executionId });
289
+ if (!execution) {
290
+ throw core_1.AppError.notFound(`Execution not found: ${executionId}`);
291
+ }
292
+ return execution;
293
+ }
294
+ /**
295
+ * Get the count of currently running executions.
296
+ */
297
+ get runningCount() {
298
+ return this.runningExecutions.size;
299
+ }
300
+ };
301
+ exports.WorkflowEngineService = WorkflowEngineService;
302
+ exports.WorkflowEngineService = WorkflowEngineService = __decorate([
303
+ (0, core_1.Service)()
304
+ ], WorkflowEngineService);
305
+ //# sourceMappingURL=workflow-engine.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-engine.service.js","sourceRoot":"","sources":["../../src/services/workflow-engine.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,qCAOoB;AAEpB,6FAAqF;AACrF,2FAAmF;AACnF,uEAAgE;AAChE,+DAAwD;AACxD,uDAAgD;AAShD;;;;;;;;;;;;;;GAcG;AAEI,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACxB,YAAY,CAAwC;IACpD,aAAa,CAAuC;IACpD,MAAM,GAAG,gBAAS,CAAC,GAAG,CAAC,oBAAa,CAAC,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACrE,QAAQ,GAAG,IAAI,uCAAgB,EAAE,CAAC;IAClC,YAAY,GAAG,gBAAS,CAAC,GAAG,CAAC,+BAAY,CAAC,CAAC;IAC3C,WAAW,GAAG,gBAAS,CAAC,GAAG,CAAC,6BAAW,CAAC,CAAC;IAEjD,sDAAsD;IAC9C,iBAAiB,GAAG,IAAI,GAAG,EAA2B,CAAC;IAE/D,gEAAgE;IAEhE;;;;;;OAMG;IACH,UAAU;QACR,MAAM,EAAE,GAAG,gBAAS,CAAC,GAAG,CAAC,sBAAe,CAAC,CAAC;QAC1C,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC,aAAa,CAAC,wDA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ACf,CAAC;IAED,gEAAgE;IAEhE;;OAEG;IACH,KAAK,CAAC,aAAa,CACjB,UAAkB,EAClB,IAAI,GAAG,CAAC,EACR,QAAQ,GAAG,EAAE;QAEb,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC;YAC3D,KAAK,EAAE,EAAE,UAAU,EAAE;YACrB,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE;YAC5B,IAAI,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ;YAC3B,IAAI,EAAE,QAAQ;SACf,CAAC,CAAC;QACH,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,WAAmB;QACpC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;QAC1E,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,eAAQ,CAAC,QAAQ,CAAC,wBAAwB,WAAW,EAAE,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;IACrC,CAAC;CACF,CAAA;AAxUY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,cAAO,GAAE;GACG,qBAAqB,CAwUjC"}
@@ -0,0 +1,84 @@
1
+ import { WorkflowDefinitionEntity } from '../entities/workflow-definition.entity.js';
2
+ import { WorkflowExecutionEntity } from '../entities/workflow-execution.entity.js';
3
+ import { NodeRegistry } from '../core/node-registry.js';
4
+ import type { IWorkflowDefinition } from '../types/index.js';
5
+ export interface CreateWorkflowDto {
6
+ name: string;
7
+ description?: string;
8
+ definition: IWorkflowDefinition;
9
+ triggerType?: string;
10
+ triggerConfig?: Record<string, unknown>;
11
+ createdBy?: number;
12
+ }
13
+ export interface UpdateWorkflowDto {
14
+ name?: string;
15
+ description?: string;
16
+ definition?: IWorkflowDefinition;
17
+ status?: 'active' | 'inactive';
18
+ triggerType?: string;
19
+ triggerConfig?: Record<string, unknown>;
20
+ }
21
+ export declare class WorkflowService {
22
+ private repo;
23
+ private executionRepo;
24
+ private logger;
25
+ private executor;
26
+ private nodeRegistry;
27
+ /** Must be called after DataSource is initialized. */
28
+ initialize(): void;
29
+ /**
30
+ * Create a new workflow definition.
31
+ */
32
+ create(dto: CreateWorkflowDto): Promise<WorkflowDefinitionEntity>;
33
+ /**
34
+ * List all workflow definitions with pagination.
35
+ */
36
+ findAll(page?: number, pageSize?: number): Promise<{
37
+ items: WorkflowDefinitionEntity[];
38
+ total: number;
39
+ }>;
40
+ /**
41
+ * Find a workflow by ID.
42
+ */
43
+ findById(id: string): Promise<WorkflowDefinitionEntity>;
44
+ /**
45
+ * Update a workflow definition.
46
+ */
47
+ update(id: string, dto: UpdateWorkflowDto): Promise<WorkflowDefinitionEntity>;
48
+ /**
49
+ * Delete a workflow definition and its executions.
50
+ */
51
+ delete(id: string): Promise<void>;
52
+ /**
53
+ * Execute a workflow by ID.
54
+ */
55
+ execute(id: string, triggerData?: Record<string, unknown>): Promise<WorkflowExecutionEntity>;
56
+ /**
57
+ * Get execution history for a workflow.
58
+ */
59
+ getExecutions(workflowId: string, page?: number, pageSize?: number): Promise<{
60
+ items: WorkflowExecutionEntity[];
61
+ total: number;
62
+ }>;
63
+ /**
64
+ * Get a single execution by ID.
65
+ */
66
+ getExecution(executionId: string): Promise<WorkflowExecutionEntity>;
67
+ /**
68
+ * Delete a single execution record.
69
+ */
70
+ deleteExecution(executionId: string): Promise<void>;
71
+ /**
72
+ * Export a workflow definition as a portable JSON object.
73
+ */
74
+ exportWorkflow(id: string): Promise<Record<string, unknown>>;
75
+ /**
76
+ * Import a workflow from a portable JSON object.
77
+ */
78
+ importWorkflow(data: Record<string, unknown>): Promise<WorkflowDefinitionEntity>;
79
+ /**
80
+ * Get the node registry for external access (e.g., editor node panel).
81
+ */
82
+ getNodeRegistry(): NodeRegistry;
83
+ }
84
+ //# sourceMappingURL=workflow.service.d.ts.map