@elizaos/plugin-workflow 2.0.0-beta.1

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 (294) hide show
  1. package/README.md +71 -0
  2. package/auto-enable.ts +18 -0
  3. package/dist/actions/index.d.ts +2 -0
  4. package/dist/actions/index.d.ts.map +1 -0
  5. package/dist/actions/index.js +2 -0
  6. package/dist/actions/index.js.map +1 -0
  7. package/dist/actions/workflow.d.ts +23 -0
  8. package/dist/actions/workflow.d.ts.map +1 -0
  9. package/dist/actions/workflow.js +425 -0
  10. package/dist/actions/workflow.js.map +1 -0
  11. package/dist/data/defaultNodes.json +9887 -0
  12. package/dist/data/schemaIndex.json +1 -0
  13. package/dist/data/triggerSchemaIndex.json +1 -0
  14. package/dist/db/index.d.ts +2 -0
  15. package/dist/db/index.d.ts.map +1 -0
  16. package/dist/db/index.js +2 -0
  17. package/dist/db/index.js.map +1 -0
  18. package/dist/db/schema.d.ts +588 -0
  19. package/dist/db/schema.d.ts.map +1 -0
  20. package/dist/db/schema.js +59 -0
  21. package/dist/db/schema.js.map +1 -0
  22. package/dist/index.d.ts +34 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +126 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/lib/automations-builder.d.ts +21 -0
  27. package/dist/lib/automations-builder.d.ts.map +1 -0
  28. package/dist/lib/automations-builder.js +557 -0
  29. package/dist/lib/automations-builder.js.map +1 -0
  30. package/dist/lib/automations-types.d.ts +153 -0
  31. package/dist/lib/automations-types.d.ts.map +1 -0
  32. package/dist/lib/automations-types.js +191 -0
  33. package/dist/lib/automations-types.js.map +1 -0
  34. package/dist/lib/index.d.ts +3 -0
  35. package/dist/lib/index.d.ts.map +1 -0
  36. package/dist/lib/index.js +3 -0
  37. package/dist/lib/index.js.map +1 -0
  38. package/dist/lib/legacy-task-migration.d.ts +20 -0
  39. package/dist/lib/legacy-task-migration.d.ts.map +1 -0
  40. package/dist/lib/legacy-task-migration.js +110 -0
  41. package/dist/lib/legacy-task-migration.js.map +1 -0
  42. package/dist/lib/legacy-text-trigger-migration.d.ts +18 -0
  43. package/dist/lib/legacy-text-trigger-migration.d.ts.map +1 -0
  44. package/dist/lib/legacy-text-trigger-migration.js +131 -0
  45. package/dist/lib/legacy-text-trigger-migration.js.map +1 -0
  46. package/dist/lib/workflow-clarification.d.ts +113 -0
  47. package/dist/lib/workflow-clarification.d.ts.map +1 -0
  48. package/dist/lib/workflow-clarification.js +425 -0
  49. package/dist/lib/workflow-clarification.js.map +1 -0
  50. package/dist/plugin-routes.d.ts +9 -0
  51. package/dist/plugin-routes.d.ts.map +1 -0
  52. package/dist/plugin-routes.js +147 -0
  53. package/dist/plugin-routes.js.map +1 -0
  54. package/dist/providers/activeWorkflows.d.ts +11 -0
  55. package/dist/providers/activeWorkflows.d.ts.map +1 -0
  56. package/dist/providers/activeWorkflows.js +72 -0
  57. package/dist/providers/activeWorkflows.js.map +1 -0
  58. package/dist/providers/index.d.ts +4 -0
  59. package/dist/providers/index.d.ts.map +1 -0
  60. package/dist/providers/index.js +4 -0
  61. package/dist/providers/index.js.map +1 -0
  62. package/dist/providers/pendingDraft.d.ts +9 -0
  63. package/dist/providers/pendingDraft.d.ts.map +1 -0
  64. package/dist/providers/pendingDraft.js +48 -0
  65. package/dist/providers/pendingDraft.js.map +1 -0
  66. package/dist/providers/workflowStatus.d.ts +3 -0
  67. package/dist/providers/workflowStatus.d.ts.map +1 -0
  68. package/dist/providers/workflowStatus.js +69 -0
  69. package/dist/providers/workflowStatus.js.map +1 -0
  70. package/dist/register-routes.d.ts +2 -0
  71. package/dist/register-routes.d.ts.map +1 -0
  72. package/dist/register-routes.js +6 -0
  73. package/dist/register-routes.js.map +1 -0
  74. package/dist/routes/_helpers.d.ts +11 -0
  75. package/dist/routes/_helpers.d.ts.map +1 -0
  76. package/dist/routes/_helpers.js +22 -0
  77. package/dist/routes/_helpers.js.map +1 -0
  78. package/dist/routes/automations.d.ts +19 -0
  79. package/dist/routes/automations.d.ts.map +1 -0
  80. package/dist/routes/automations.js +32 -0
  81. package/dist/routes/automations.js.map +1 -0
  82. package/dist/routes/embedded-webhooks.d.ts +3 -0
  83. package/dist/routes/embedded-webhooks.d.ts.map +1 -0
  84. package/dist/routes/embedded-webhooks.js +47 -0
  85. package/dist/routes/embedded-webhooks.js.map +1 -0
  86. package/dist/routes/executions.d.ts +3 -0
  87. package/dist/routes/executions.d.ts.map +1 -0
  88. package/dist/routes/executions.js +58 -0
  89. package/dist/routes/executions.js.map +1 -0
  90. package/dist/routes/index.d.ts +4 -0
  91. package/dist/routes/index.d.ts.map +1 -0
  92. package/dist/routes/index.js +14 -0
  93. package/dist/routes/index.js.map +1 -0
  94. package/dist/routes/nodes.d.ts +3 -0
  95. package/dist/routes/nodes.d.ts.map +1 -0
  96. package/dist/routes/nodes.js +168 -0
  97. package/dist/routes/nodes.js.map +1 -0
  98. package/dist/routes/validation.d.ts +3 -0
  99. package/dist/routes/validation.d.ts.map +1 -0
  100. package/dist/routes/validation.js +41 -0
  101. package/dist/routes/validation.js.map +1 -0
  102. package/dist/routes/workflow-routes.d.ts +27 -0
  103. package/dist/routes/workflow-routes.d.ts.map +1 -0
  104. package/dist/routes/workflow-routes.js +326 -0
  105. package/dist/routes/workflow-routes.js.map +1 -0
  106. package/dist/routes/workflows.d.ts +3 -0
  107. package/dist/routes/workflows.d.ts.map +1 -0
  108. package/dist/routes/workflows.js +252 -0
  109. package/dist/routes/workflows.js.map +1 -0
  110. package/dist/schemas/draftIntent.d.ts +22 -0
  111. package/dist/schemas/draftIntent.d.ts.map +1 -0
  112. package/dist/schemas/draftIntent.js +22 -0
  113. package/dist/schemas/draftIntent.js.map +1 -0
  114. package/dist/schemas/feasibility.d.ts +13 -0
  115. package/dist/schemas/feasibility.d.ts.map +1 -0
  116. package/dist/schemas/feasibility.js +9 -0
  117. package/dist/schemas/feasibility.js.map +1 -0
  118. package/dist/schemas/index.d.ts +5 -0
  119. package/dist/schemas/index.d.ts.map +1 -0
  120. package/dist/schemas/index.js +5 -0
  121. package/dist/schemas/index.js.map +1 -0
  122. package/dist/schemas/keywordExtraction.d.ts +14 -0
  123. package/dist/schemas/keywordExtraction.d.ts.map +1 -0
  124. package/dist/schemas/keywordExtraction.js +12 -0
  125. package/dist/schemas/keywordExtraction.js.map +1 -0
  126. package/dist/schemas/workflowMatching.d.ts +36 -0
  127. package/dist/schemas/workflowMatching.d.ts.map +1 -0
  128. package/dist/schemas/workflowMatching.js +30 -0
  129. package/dist/schemas/workflowMatching.js.map +1 -0
  130. package/dist/services/embedded-workflow-service.d.ts +106 -0
  131. package/dist/services/embedded-workflow-service.d.ts.map +1 -0
  132. package/dist/services/embedded-workflow-service.js +1900 -0
  133. package/dist/services/embedded-workflow-service.js.map +1 -0
  134. package/dist/services/index.d.ts +5 -0
  135. package/dist/services/index.d.ts.map +1 -0
  136. package/dist/services/index.js +5 -0
  137. package/dist/services/index.js.map +1 -0
  138. package/dist/services/workflow-credential-store.d.ts +27 -0
  139. package/dist/services/workflow-credential-store.d.ts.map +1 -0
  140. package/dist/services/workflow-credential-store.js +92 -0
  141. package/dist/services/workflow-credential-store.js.map +1 -0
  142. package/dist/services/workflow-dispatch.d.ts +41 -0
  143. package/dist/services/workflow-dispatch.d.ts.map +1 -0
  144. package/dist/services/workflow-dispatch.js +86 -0
  145. package/dist/services/workflow-dispatch.js.map +1 -0
  146. package/dist/services/workflow-service.d.ts +63 -0
  147. package/dist/services/workflow-service.d.ts.map +1 -0
  148. package/dist/services/workflow-service.js +492 -0
  149. package/dist/services/workflow-service.js.map +1 -0
  150. package/dist/trigger-routes.d.ts +153 -0
  151. package/dist/trigger-routes.d.ts.map +1 -0
  152. package/dist/trigger-routes.js +424 -0
  153. package/dist/trigger-routes.js.map +1 -0
  154. package/dist/types/index.d.ts +457 -0
  155. package/dist/types/index.d.ts.map +1 -0
  156. package/dist/types/index.js +59 -0
  157. package/dist/types/index.js.map +1 -0
  158. package/dist/utils/catalog.d.ts +16 -0
  159. package/dist/utils/catalog.d.ts.map +1 -0
  160. package/dist/utils/catalog.js +211 -0
  161. package/dist/utils/catalog.js.map +1 -0
  162. package/dist/utils/clarification.d.ts +17 -0
  163. package/dist/utils/clarification.d.ts.map +1 -0
  164. package/dist/utils/clarification.js +46 -0
  165. package/dist/utils/clarification.js.map +1 -0
  166. package/dist/utils/context.d.ts +4 -0
  167. package/dist/utils/context.d.ts.map +1 -0
  168. package/dist/utils/context.js +18 -0
  169. package/dist/utils/context.js.map +1 -0
  170. package/dist/utils/credentialResolver.d.ts +22 -0
  171. package/dist/utils/credentialResolver.d.ts.map +1 -0
  172. package/dist/utils/credentialResolver.js +146 -0
  173. package/dist/utils/credentialResolver.js.map +1 -0
  174. package/dist/utils/generation.d.ts +36 -0
  175. package/dist/utils/generation.d.ts.map +1 -0
  176. package/dist/utils/generation.js +701 -0
  177. package/dist/utils/generation.js.map +1 -0
  178. package/dist/utils/host-capabilities.d.ts +27 -0
  179. package/dist/utils/host-capabilities.d.ts.map +1 -0
  180. package/dist/utils/host-capabilities.js +59 -0
  181. package/dist/utils/host-capabilities.js.map +1 -0
  182. package/dist/utils/inferSyntheticOutputSchema.d.ts +20 -0
  183. package/dist/utils/inferSyntheticOutputSchema.d.ts.map +1 -0
  184. package/dist/utils/inferSyntheticOutputSchema.js +151 -0
  185. package/dist/utils/inferSyntheticOutputSchema.js.map +1 -0
  186. package/dist/utils/outputSchema.d.ts +26 -0
  187. package/dist/utils/outputSchema.d.ts.map +1 -0
  188. package/dist/utils/outputSchema.js +297 -0
  189. package/dist/utils/outputSchema.js.map +1 -0
  190. package/dist/utils/validateAndRepair.d.ts +41 -0
  191. package/dist/utils/validateAndRepair.d.ts.map +1 -0
  192. package/dist/utils/validateAndRepair.js +483 -0
  193. package/dist/utils/validateAndRepair.js.map +1 -0
  194. package/dist/utils/workflow-prompts/actionResponse.d.ts +2 -0
  195. package/dist/utils/workflow-prompts/actionResponse.d.ts.map +1 -0
  196. package/dist/utils/workflow-prompts/actionResponse.js +17 -0
  197. package/dist/utils/workflow-prompts/actionResponse.js.map +1 -0
  198. package/dist/utils/workflow-prompts/draftIntent.d.ts +2 -0
  199. package/dist/utils/workflow-prompts/draftIntent.d.ts.map +1 -0
  200. package/dist/utils/workflow-prompts/draftIntent.js +23 -0
  201. package/dist/utils/workflow-prompts/draftIntent.js.map +1 -0
  202. package/dist/utils/workflow-prompts/feasibilityCheck.d.ts +2 -0
  203. package/dist/utils/workflow-prompts/feasibilityCheck.d.ts.map +1 -0
  204. package/dist/utils/workflow-prompts/feasibilityCheck.js +21 -0
  205. package/dist/utils/workflow-prompts/feasibilityCheck.js.map +1 -0
  206. package/dist/utils/workflow-prompts/fieldCorrection.d.ts +3 -0
  207. package/dist/utils/workflow-prompts/fieldCorrection.d.ts.map +1 -0
  208. package/dist/utils/workflow-prompts/fieldCorrection.js +20 -0
  209. package/dist/utils/workflow-prompts/fieldCorrection.js.map +1 -0
  210. package/dist/utils/workflow-prompts/index.d.ts +8 -0
  211. package/dist/utils/workflow-prompts/index.d.ts.map +1 -0
  212. package/dist/utils/workflow-prompts/index.js +8 -0
  213. package/dist/utils/workflow-prompts/index.js.map +1 -0
  214. package/dist/utils/workflow-prompts/keywordExtraction.d.ts +2 -0
  215. package/dist/utils/workflow-prompts/keywordExtraction.d.ts.map +1 -0
  216. package/dist/utils/workflow-prompts/keywordExtraction.js +21 -0
  217. package/dist/utils/workflow-prompts/keywordExtraction.js.map +1 -0
  218. package/dist/utils/workflow-prompts/parameterCorrection.d.ts +3 -0
  219. package/dist/utils/workflow-prompts/parameterCorrection.d.ts.map +1 -0
  220. package/dist/utils/workflow-prompts/parameterCorrection.js +29 -0
  221. package/dist/utils/workflow-prompts/parameterCorrection.js.map +1 -0
  222. package/dist/utils/workflow-prompts/workflowGeneration.d.ts +2 -0
  223. package/dist/utils/workflow-prompts/workflowGeneration.d.ts.map +1 -0
  224. package/dist/utils/workflow-prompts/workflowGeneration.js +529 -0
  225. package/dist/utils/workflow-prompts/workflowGeneration.js.map +1 -0
  226. package/dist/utils/workflow-prompts/workflowMatching.d.ts +2 -0
  227. package/dist/utils/workflow-prompts/workflowMatching.d.ts.map +1 -0
  228. package/dist/utils/workflow-prompts/workflowMatching.js +23 -0
  229. package/dist/utils/workflow-prompts/workflowMatching.js.map +1 -0
  230. package/dist/utils/workflow.d.ts +62 -0
  231. package/dist/utils/workflow.d.ts.map +1 -0
  232. package/dist/utils/workflow.js +712 -0
  233. package/dist/utils/workflow.js.map +1 -0
  234. package/package.json +87 -0
  235. package/src/actions/index.ts +1 -0
  236. package/src/actions/workflow.ts +494 -0
  237. package/src/data/defaultNodes.json +9887 -0
  238. package/src/data/schemaIndex.json +1 -0
  239. package/src/data/triggerSchemaIndex.json +1 -0
  240. package/src/db/index.ts +8 -0
  241. package/src/db/schema.ts +94 -0
  242. package/src/index.ts +179 -0
  243. package/src/lib/automations-builder.ts +679 -0
  244. package/src/lib/automations-types.ts +391 -0
  245. package/src/lib/index.ts +8 -0
  246. package/src/lib/legacy-task-migration.ts +143 -0
  247. package/src/lib/legacy-text-trigger-migration.ts +178 -0
  248. package/src/lib/workflow-clarification.ts +497 -0
  249. package/src/plugin-routes.ts +164 -0
  250. package/src/providers/activeWorkflows.ts +81 -0
  251. package/src/providers/index.ts +3 -0
  252. package/src/providers/pendingDraft.ts +55 -0
  253. package/src/providers/workflowStatus.ts +88 -0
  254. package/src/register-routes.ts +6 -0
  255. package/src/routes/_helpers.ts +27 -0
  256. package/src/routes/automations.ts +46 -0
  257. package/src/routes/embedded-webhooks.ts +64 -0
  258. package/src/routes/executions.ts +75 -0
  259. package/src/routes/index.ts +16 -0
  260. package/src/routes/nodes.ts +211 -0
  261. package/src/routes/validation.ts +51 -0
  262. package/src/routes/workflow-routes.ts +469 -0
  263. package/src/routes/workflows.ts +310 -0
  264. package/src/schemas/draftIntent.ts +21 -0
  265. package/src/schemas/feasibility.ts +8 -0
  266. package/src/schemas/index.ts +4 -0
  267. package/src/schemas/keywordExtraction.ts +11 -0
  268. package/src/schemas/workflowMatching.ts +29 -0
  269. package/src/services/embedded-workflow-service.ts +2224 -0
  270. package/src/services/index.ts +17 -0
  271. package/src/services/workflow-credential-store.ts +132 -0
  272. package/src/services/workflow-dispatch.ts +121 -0
  273. package/src/services/workflow-service.ts +839 -0
  274. package/src/trigger-routes.ts +714 -0
  275. package/src/types/index.ts +562 -0
  276. package/src/utils/catalog.ts +260 -0
  277. package/src/utils/clarification.ts +52 -0
  278. package/src/utils/context.ts +22 -0
  279. package/src/utils/credentialResolver.ts +234 -0
  280. package/src/utils/generation.ts +987 -0
  281. package/src/utils/host-capabilities.ts +81 -0
  282. package/src/utils/inferSyntheticOutputSchema.ts +163 -0
  283. package/src/utils/outputSchema.ts +372 -0
  284. package/src/utils/validateAndRepair.ts +610 -0
  285. package/src/utils/workflow-prompts/actionResponse.ts +16 -0
  286. package/src/utils/workflow-prompts/draftIntent.ts +22 -0
  287. package/src/utils/workflow-prompts/feasibilityCheck.ts +20 -0
  288. package/src/utils/workflow-prompts/fieldCorrection.ts +20 -0
  289. package/src/utils/workflow-prompts/index.ts +10 -0
  290. package/src/utils/workflow-prompts/keywordExtraction.ts +20 -0
  291. package/src/utils/workflow-prompts/parameterCorrection.ts +29 -0
  292. package/src/utils/workflow-prompts/workflowGeneration.ts +528 -0
  293. package/src/utils/workflow-prompts/workflowMatching.ts +22 -0
  294. package/src/utils/workflow.ts +895 -0
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Workflow route plugin — registers `/api/workflow/*` route handlers with the
3
+ * elizaOS runtime plugin route system. The handlers run in-process against
4
+ * plugin-workflow services; there is no external workflow server or sidecar.
5
+ */
6
+
7
+ import type http from 'node:http';
8
+ import type { Plugin, Route } from '@elizaos/core';
9
+ import { handleAutomationsRoutes } from './routes/automations';
10
+ import { handleWorkflowRoutes, type WorkflowRouteContext } from './routes/workflow-routes';
11
+
12
+ type AnyRuntime = WorkflowRouteContext['runtime'];
13
+
14
+ interface WorkflowCompatState {
15
+ current: AnyRuntime;
16
+ }
17
+
18
+ function buildState(runtime: unknown): WorkflowCompatState {
19
+ return { current: runtime as AnyRuntime } as WorkflowCompatState;
20
+ }
21
+
22
+ function jsonResponder(httpRes: http.ServerResponse) {
23
+ return (_res: http.ServerResponse, body: unknown, status = 200) => {
24
+ if (httpRes.headersSent) return;
25
+ httpRes.statusCode = status;
26
+ httpRes.setHeader('content-type', 'application/json; charset=utf-8');
27
+ httpRes.end(JSON.stringify(body));
28
+ };
29
+ }
30
+
31
+ function makeWorkflowHandler() {
32
+ return async (req: unknown, res: unknown, runtime: unknown): Promise<void> => {
33
+ const httpReq = req as http.IncomingMessage;
34
+ const httpRes = res as http.ServerResponse;
35
+ const url = new URL(httpReq.url ?? '/', 'http://localhost');
36
+ const method = (httpReq.method ?? 'GET').toUpperCase();
37
+ const state = buildState(runtime);
38
+
39
+ await handleWorkflowRoutes({
40
+ req: httpReq,
41
+ res: httpRes,
42
+ method,
43
+ pathname: url.pathname,
44
+ runtime: state.current,
45
+ json: jsonResponder(httpRes),
46
+ });
47
+ };
48
+ }
49
+
50
+ function makeAutomationsHandler() {
51
+ return async (req: unknown, res: unknown, runtime: unknown): Promise<void> => {
52
+ const httpReq = req as http.IncomingMessage;
53
+ const httpRes = res as http.ServerResponse;
54
+ const url = new URL(httpReq.url ?? '/', 'http://localhost');
55
+ const method = (httpReq.method ?? 'GET').toUpperCase();
56
+ const state = buildState(runtime);
57
+
58
+ await handleAutomationsRoutes({
59
+ req: httpReq,
60
+ res: httpRes,
61
+ method,
62
+ pathname: url.pathname,
63
+ runtime: state.current,
64
+ json: jsonResponder(httpRes),
65
+ });
66
+ };
67
+ }
68
+
69
+ const workflowHandler = makeWorkflowHandler();
70
+ const automationsHandler = makeAutomationsHandler();
71
+
72
+ const workflowRouteList: Route[] = [
73
+ // Status surface
74
+ {
75
+ type: 'GET',
76
+ path: '/api/workflow/status',
77
+ rawPath: true,
78
+ handler: workflowHandler,
79
+ },
80
+ // Runtime lifecycle/status compatibility
81
+ {
82
+ type: 'POST',
83
+ path: '/api/workflow/runtime/start',
84
+ rawPath: true,
85
+ handler: workflowHandler,
86
+ },
87
+ // Workflow CRUD
88
+ {
89
+ type: 'GET',
90
+ path: '/api/workflow/workflows',
91
+ rawPath: true,
92
+ handler: workflowHandler,
93
+ },
94
+ {
95
+ type: 'POST',
96
+ path: '/api/workflow/workflows',
97
+ rawPath: true,
98
+ handler: workflowHandler,
99
+ },
100
+ {
101
+ type: 'POST',
102
+ path: '/api/workflow/workflows/generate',
103
+ rawPath: true,
104
+ handler: workflowHandler,
105
+ },
106
+ {
107
+ type: 'POST',
108
+ path: '/api/workflow/workflows/resolve-clarification',
109
+ rawPath: true,
110
+ handler: workflowHandler,
111
+ },
112
+ {
113
+ type: 'GET',
114
+ path: '/api/workflow/workflows/:id',
115
+ rawPath: true,
116
+ handler: workflowHandler,
117
+ },
118
+ {
119
+ type: 'PUT',
120
+ path: '/api/workflow/workflows/:id',
121
+ rawPath: true,
122
+ handler: workflowHandler,
123
+ },
124
+ {
125
+ type: 'POST',
126
+ path: '/api/workflow/workflows/:id/activate',
127
+ rawPath: true,
128
+ handler: workflowHandler,
129
+ },
130
+ {
131
+ type: 'POST',
132
+ path: '/api/workflow/workflows/:id/deactivate',
133
+ rawPath: true,
134
+ handler: workflowHandler,
135
+ },
136
+ {
137
+ type: 'DELETE',
138
+ path: '/api/workflow/workflows/:id',
139
+ rawPath: true,
140
+ handler: workflowHandler,
141
+ },
142
+ {
143
+ type: 'GET',
144
+ path: '/api/workflow/workflows/:id/executions',
145
+ rawPath: true,
146
+ handler: workflowHandler,
147
+ },
148
+ // Cross-cutting `/api/automations` surface — combines workflows, triggers,
149
+ // workbench tasks, and draft conversations into a single list view.
150
+ {
151
+ type: 'GET',
152
+ path: '/api/automations',
153
+ rawPath: true,
154
+ handler: automationsHandler,
155
+ },
156
+ ];
157
+
158
+ export const workflowRoutePlugin: Plugin = {
159
+ name: '@elizaos/plugin-workflow:routes',
160
+ description: 'Workflow routes — in-process status, generation, CRUD, and lifecycle handlers.',
161
+ routes: workflowRouteList,
162
+ };
163
+
164
+ export default workflowRoutePlugin;
@@ -0,0 +1,81 @@
1
+ import { type IAgentRuntime, logger, type Memory, type Provider, type State } from '@elizaos/core';
2
+ import { WORKFLOW_SERVICE_TYPE, type WorkflowService } from '../services/index';
3
+
4
+ /**
5
+ * Provider that enriches state with user's active workflows
6
+ *
7
+ * This provider runs for every message and adds workflow information to the state,
8
+ * allowing the LLM to automatically extract workflow IDs and references from context.
9
+ *
10
+ * Example: User says "run my Stripe workflow" → LLM can see all workflows and extract the right ID
11
+ */
12
+ export const activeWorkflowsProvider: Provider = {
13
+ name: 'ACTIVE_WORKFLOWS',
14
+ description: "User's active workflows with IDs and descriptions",
15
+ contexts: ['automation', 'connectors'],
16
+ contextGate: { anyOf: ['automation', 'connectors'] },
17
+ cacheScope: 'agent',
18
+ roleGate: { minRole: 'ADMIN' },
19
+
20
+ get: async (runtime: IAgentRuntime, _message: Memory, _state: State) => {
21
+ try {
22
+ const service = runtime.getService<WorkflowService>(WORKFLOW_SERVICE_TYPE);
23
+
24
+ if (!service) {
25
+ return {
26
+ text: '',
27
+ data: {},
28
+ values: {},
29
+ };
30
+ }
31
+
32
+ const userId = _message.entityId;
33
+ const workflows = await service.listWorkflows(userId);
34
+
35
+ if (workflows.length === 0) {
36
+ return {
37
+ text: '',
38
+ data: { workflows: [] },
39
+ values: { hasWorkflows: false },
40
+ };
41
+ }
42
+
43
+ const workflowList = workflows
44
+ .slice(0, 20)
45
+ .map((wf) => {
46
+ const status = wf.active ? 'ACTIVE' : 'INACTIVE';
47
+ const nodeCount = wf.nodes?.length || 0;
48
+ return `- **${wf.name}** (ID: ${wf.id}, Status: ${status}, Nodes: ${nodeCount})`;
49
+ })
50
+ .join('\n');
51
+
52
+ const text = `# Available Workflows\n\n${workflowList}`;
53
+
54
+ return {
55
+ text,
56
+ data: {
57
+ workflows: workflows.map((wf) => ({
58
+ id: wf.id,
59
+ name: wf.name,
60
+ active: wf.active || false,
61
+ nodeCount: wf.nodes?.length || 0,
62
+ })),
63
+ },
64
+ values: {
65
+ hasWorkflows: true,
66
+ workflowCount: workflows.length,
67
+ },
68
+ };
69
+ } catch (error) {
70
+ logger.error(
71
+ { src: 'plugin:workflow:providers:active-workflows' },
72
+ `Failed to get active workflows: ${error instanceof Error ? error.message : String(error)}`
73
+ );
74
+ return {
75
+ text: '',
76
+ data: {},
77
+ values: {},
78
+ };
79
+ }
80
+ },
81
+ };
@@ -0,0 +1,3 @@
1
+ export { activeWorkflowsProvider } from './activeWorkflows';
2
+ export { pendingDraftProvider } from './pendingDraft';
3
+ export { workflowStatusProvider } from './workflowStatus';
@@ -0,0 +1,55 @@
1
+ import type { IAgentRuntime, Memory, Provider, State } from '@elizaos/core';
2
+ import type { WorkflowDraft } from '../types/index';
3
+
4
+ const DRAFT_TTL_MS = 30 * 60 * 1000;
5
+ const MAX_DRAFT_NODES = 12;
6
+
7
+ /**
8
+ * Provider that tells the LLM when a workflow draft is pending confirmation.
9
+ *
10
+ * Without this, the LLM has no context about pending drafts and will route
11
+ * confirmation messages (e.g. "yes, deploy it") to REPLY instead of WORKFLOW.
12
+ */
13
+ export const pendingDraftProvider: Provider = {
14
+ name: 'PENDING_WORKFLOW_DRAFT',
15
+ description: 'Pending workflow draft awaiting user confirmation, modification, or cancellation',
16
+ contexts: ['automation', 'connectors'],
17
+ contextGate: { anyOf: ['automation', 'connectors'] },
18
+ cacheScope: 'conversation',
19
+ roleGate: { minRole: 'ADMIN' },
20
+
21
+ get: async (runtime: IAgentRuntime, message: Memory, _state: State) => {
22
+ try {
23
+ const cacheKey = `workflow_draft:${message.entityId}`;
24
+ const draft = await runtime.getCache<WorkflowDraft>(cacheKey);
25
+
26
+ if (!draft || Date.now() - draft.createdAt > DRAFT_TTL_MS) {
27
+ return { text: '', data: {}, values: {} };
28
+ }
29
+
30
+ const nodeNames = draft.workflow.nodes
31
+ .slice(0, MAX_DRAFT_NODES)
32
+ .map((n) => n.name)
33
+ .join(' → ');
34
+
35
+ return {
36
+ text:
37
+ '# Pending Workflow Draft\n\n' +
38
+ `A workflow draft "${draft.workflow.name}" is pending.\n` +
39
+ `Nodes: ${nodeNames}\n\n` +
40
+ '**REQUIRED**: Any user message about this draft MUST trigger the WORKFLOW action.\n' +
41
+ 'This includes confirmations ("yes", "ok", "deploy it", "create it", "go ahead"),\n' +
42
+ 'cancellations ("cancel", "nevermind"), and modifications ("change X", "use Y instead").\n' +
43
+ 'The action handler manages all draft operations — do NOT handle them via text reply.\n' +
44
+ 'You MUST include WORKFLOW in your actions.',
45
+ data: {
46
+ hasPendingDraft: true,
47
+ truncated: draft.workflow.nodes.length > MAX_DRAFT_NODES,
48
+ },
49
+ values: { hasPendingDraft: true },
50
+ };
51
+ } catch {
52
+ return { text: '', data: {}, values: {} };
53
+ }
54
+ },
55
+ };
@@ -0,0 +1,88 @@
1
+ import { type IAgentRuntime, logger, type Memory, type Provider, type State } from '@elizaos/core';
2
+ import { WORKFLOW_SERVICE_TYPE, type WorkflowService } from '../services/index';
3
+
4
+ export const workflowStatusProvider: Provider = {
5
+ name: 'workflow_status',
6
+ contexts: ['automation', 'connectors'],
7
+ contextGate: { anyOf: ['automation', 'connectors'] },
8
+ cacheScope: 'turn',
9
+ roleGate: { minRole: 'ADMIN' },
10
+
11
+ get: async (runtime: IAgentRuntime, _message: Memory, _state: State) => {
12
+ try {
13
+ const service = runtime.getService<WorkflowService>(WORKFLOW_SERVICE_TYPE);
14
+
15
+ if (!service) {
16
+ logger.warn(
17
+ { src: 'plugin:workflow:provider:workflowStatus' },
18
+ 'Workflow service not available for provider'
19
+ );
20
+ return {
21
+ text: '',
22
+ data: {},
23
+ values: {},
24
+ };
25
+ }
26
+
27
+ // Get workflows for the user
28
+ const userId = _message.entityId;
29
+
30
+ const workflows = await service.listWorkflows(userId);
31
+
32
+ if (workflows.length === 0) {
33
+ return {
34
+ text: 'No workflows configured yet.',
35
+ data: {},
36
+ values: {},
37
+ };
38
+ }
39
+
40
+ let status = `Current workflows (${workflows.length}):\n\n`;
41
+
42
+ for (const workflow of workflows.slice(0, 10)) {
43
+ const statusEmoji = workflow.active ? '✅' : '⏸️';
44
+ status += `${statusEmoji} ${workflow.name} (ID: ${workflow.id})\n`;
45
+ status += ` Nodes: ${workflow.nodes?.length || 0}\n`;
46
+
47
+ // Try to get last execution (if possible)
48
+ try {
49
+ const executions = await service.getWorkflowExecutions(workflow.id, 1);
50
+ if (executions.length > 0) {
51
+ const lastExec = executions[0];
52
+ const execEmoji =
53
+ lastExec.status === 'success' ? '✅' : lastExec.status === 'error' ? '❌' : '⏳';
54
+ status += ` Last run: ${execEmoji} ${lastExec.status} at ${new Date(lastExec.startedAt).toLocaleString()}\n`;
55
+ }
56
+ } catch (_error) {
57
+ // Ignore execution fetch errors
58
+ logger.debug(
59
+ { src: 'plugin:workflow:provider:workflowStatus' },
60
+ `Could not fetch executions for workflow ${workflow.id}`
61
+ );
62
+ }
63
+
64
+ status += '\n';
65
+ }
66
+
67
+ if (workflows.length > 10) {
68
+ status += `\n... and ${workflows.length - 10} more workflows.`;
69
+ }
70
+
71
+ return {
72
+ text: status,
73
+ data: { workflows },
74
+ values: { workflowCount: workflows.length },
75
+ };
76
+ } catch (error) {
77
+ logger.error(
78
+ { src: 'plugin:workflow:provider:workflowStatus' },
79
+ `Failed to get workflow status: ${error instanceof Error ? error.message : String(error)}`
80
+ );
81
+ return {
82
+ text: '',
83
+ data: {},
84
+ values: {},
85
+ };
86
+ }
87
+ },
88
+ };
@@ -0,0 +1,6 @@
1
+ import { registerAppRoutePluginLoader } from '@elizaos/core';
2
+
3
+ registerAppRoutePluginLoader('@elizaos/plugin-workflow:routes', async () => {
4
+ const { workflowRoutePlugin } = await import('./plugin-routes');
5
+ return workflowRoutePlugin;
6
+ });
@@ -0,0 +1,27 @@
1
+ import type { IAgentRuntime } from '@elizaos/core';
2
+ import type { WorkflowService } from '../services/workflow-service';
3
+ import { WORKFLOW_SERVICE_TYPE } from '../services/workflow-service';
4
+
5
+ /**
6
+ * Extract WorkflowService from runtime services
7
+ */
8
+ export function getService(runtime: IAgentRuntime): WorkflowService {
9
+ const service = runtime.getService<WorkflowService>(WORKFLOW_SERVICE_TYPE);
10
+
11
+ if (!service) {
12
+ throw new Error('WorkflowService not available in runtime');
13
+ }
14
+
15
+ return service;
16
+ }
17
+
18
+ /**
19
+ * Validate and clamp limit parameter
20
+ */
21
+ export function validateLimit(limitParam: unknown, defaultLimit = 20, maxLimit = 100): number {
22
+ const limit = Number(limitParam);
23
+ if (!Number.isFinite(limit) || limit <= 0) {
24
+ return defaultLimit;
25
+ }
26
+ return Math.min(limit, maxLimit);
27
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * `/api/automations` route handler. Lives in plugin-workflow because the
3
+ * response is built directly from the in-process WorkflowService (no proxy)
4
+ * plus the runtime task and room APIs.
5
+ */
6
+
7
+ import type http from 'node:http';
8
+ import type { AgentRuntime } from '@elizaos/core';
9
+ import { buildAutomationListResponse } from '../lib/automations-builder';
10
+
11
+ type JsonResponder = (res: http.ServerResponse, body: unknown, status?: number) => void;
12
+
13
+ export interface AutomationsRouteContext {
14
+ req: http.IncomingMessage;
15
+ res: http.ServerResponse;
16
+ method: string;
17
+ pathname: string;
18
+ runtime: AgentRuntime | null;
19
+ json: JsonResponder;
20
+ }
21
+
22
+ function sendJson(ctx: AutomationsRouteContext, status: number, body: unknown): void {
23
+ ctx.json(ctx.res, body, status);
24
+ }
25
+
26
+ export async function handleAutomationsRoutes(ctx: AutomationsRouteContext): Promise<boolean> {
27
+ if (ctx.method.toUpperCase() !== 'GET') {
28
+ return false;
29
+ }
30
+ if (ctx.pathname !== '/api/automations') {
31
+ return false;
32
+ }
33
+ if (!ctx.runtime) {
34
+ sendJson(ctx, 503, { error: 'Agent runtime is not available' });
35
+ return true;
36
+ }
37
+ try {
38
+ const payload = await buildAutomationListResponse(ctx.runtime);
39
+ sendJson(ctx, 200, payload);
40
+ } catch (error) {
41
+ sendJson(ctx, 500, {
42
+ error: error instanceof Error ? error.message : String(error),
43
+ });
44
+ }
45
+ return true;
46
+ }
@@ -0,0 +1,64 @@
1
+ import type { IAgentRuntime, Route, RouteRequest, RouteResponse } from '@elizaos/core';
2
+ import {
3
+ EMBEDDED_WORKFLOW_SERVICE_TYPE,
4
+ type EmbeddedWorkflowService,
5
+ } from '../services/embedded-workflow-service';
6
+ import { WorkflowApiError } from '../types/index';
7
+
8
+ function getEmbeddedService(runtime: IAgentRuntime): EmbeddedWorkflowService {
9
+ const service = runtime.getService(
10
+ EMBEDDED_WORKFLOW_SERVICE_TYPE
11
+ ) as EmbeddedWorkflowService | null;
12
+ if (!service) {
13
+ throw new Error('EmbeddedWorkflowService not available in runtime');
14
+ }
15
+ return service;
16
+ }
17
+
18
+ function coerceBody(body: unknown): Record<string, unknown> {
19
+ return body && typeof body === 'object' && !Array.isArray(body)
20
+ ? (body as Record<string, unknown>)
21
+ : { body };
22
+ }
23
+
24
+ async function executeWebhook(
25
+ req: RouteRequest,
26
+ res: RouteResponse,
27
+ runtime: IAgentRuntime
28
+ ): Promise<void> {
29
+ try {
30
+ const path = req.params?.path;
31
+ if (!path) {
32
+ res.status(400).json({ success: false, error: 'webhook_path_required' });
33
+ return;
34
+ }
35
+
36
+ const service = getEmbeddedService(runtime);
37
+ const method = (req.method ?? 'POST').toUpperCase();
38
+ const execution = await service.executeWebhook(
39
+ path,
40
+ {
41
+ body: req.body ?? {},
42
+ query: req.query ?? {},
43
+ params: req.params ?? {},
44
+ ...coerceBody(req.body),
45
+ },
46
+ method
47
+ );
48
+ res.json({ success: true, data: execution });
49
+ } catch (error) {
50
+ res.status(error instanceof WorkflowApiError ? (error.statusCode ?? 500) : 500).json({
51
+ success: false,
52
+ error: 'failed_to_execute_webhook',
53
+ message: error instanceof Error ? error.message : 'Unknown error',
54
+ });
55
+ }
56
+ }
57
+
58
+ export const embeddedWebhookRoutes: Route[] = [
59
+ { type: 'GET', path: '/webhooks/:path', handler: executeWebhook },
60
+ { type: 'POST', path: '/webhooks/:path', handler: executeWebhook },
61
+ { type: 'PUT', path: '/webhooks/:path', handler: executeWebhook },
62
+ { type: 'PATCH', path: '/webhooks/:path', handler: executeWebhook },
63
+ { type: 'DELETE', path: '/webhooks/:path', handler: executeWebhook },
64
+ ];
@@ -0,0 +1,75 @@
1
+ import type { IAgentRuntime, Route, RouteRequest, RouteResponse } from '@elizaos/core';
2
+ import { getService, validateLimit } from './_helpers';
3
+
4
+ /**
5
+ * GET /executions?workflowId=x&status=y&limit=z&cursor=c
6
+ */
7
+ async function listExecutions(
8
+ req: RouteRequest,
9
+ res: RouteResponse,
10
+ runtime: IAgentRuntime
11
+ ): Promise<void> {
12
+ try {
13
+ const workflowId = req.query?.workflowId as string | undefined;
14
+ const status = req.query?.status as
15
+ | 'canceled'
16
+ | 'error'
17
+ | 'running'
18
+ | 'success'
19
+ | 'waiting'
20
+ | undefined;
21
+ const limit = validateLimit(req.query?.limit, 50, 250);
22
+ const cursor = req.query?.cursor as string | undefined;
23
+
24
+ const service = getService(runtime);
25
+ const response = await service.listExecutions({
26
+ workflowId,
27
+ status,
28
+ limit,
29
+ cursor,
30
+ });
31
+ res.json({
32
+ success: true,
33
+ data: response.data,
34
+ nextCursor: response.nextCursor,
35
+ });
36
+ } catch (error) {
37
+ res.status(500).json({
38
+ success: false,
39
+ error: 'failed_to_list_executions',
40
+ message: error instanceof Error ? error.message : 'Unknown error',
41
+ });
42
+ }
43
+ }
44
+
45
+ /**
46
+ * GET /executions/:id
47
+ */
48
+ async function getExecution(
49
+ req: RouteRequest,
50
+ res: RouteResponse,
51
+ runtime: IAgentRuntime
52
+ ): Promise<void> {
53
+ try {
54
+ const id = req.params?.id;
55
+ if (!id) {
56
+ res.status(400).json({ success: false, error: 'execution_id_required' });
57
+ return;
58
+ }
59
+
60
+ const service = getService(runtime);
61
+ const execution = await service.getExecutionDetail(id);
62
+ res.json({ success: true, data: execution });
63
+ } catch (error) {
64
+ res.status(500).json({
65
+ success: false,
66
+ error: 'failed_to_fetch_execution',
67
+ message: error instanceof Error ? error.message : 'Unknown error',
68
+ });
69
+ }
70
+ }
71
+
72
+ export const executionRoutes: Route[] = [
73
+ { type: 'GET', path: '/executions', handler: listExecutions },
74
+ { type: 'GET', path: '/executions/:id', handler: getExecution },
75
+ ];
@@ -0,0 +1,16 @@
1
+ import type { Route } from '@elizaos/core';
2
+ import { embeddedWebhookRoutes } from './embedded-webhooks';
3
+ import { executionRoutes } from './executions';
4
+ import { nodeRoutes } from './nodes';
5
+ import { validationRoutes } from './validation';
6
+ import { workflowRoutes as workflowCrudRoutes } from './workflows';
7
+
8
+ export { type AutomationsRouteContext, handleAutomationsRoutes } from './automations';
9
+
10
+ export const workflowRoutes: Route[] = [
11
+ ...validationRoutes,
12
+ ...workflowCrudRoutes,
13
+ ...nodeRoutes,
14
+ ...executionRoutes,
15
+ ...embeddedWebhookRoutes,
16
+ ];