@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,310 @@
1
+ import type { IAgentRuntime, Route, RouteRequest, RouteResponse } from '@elizaos/core';
2
+ import type { WorkflowDefinition } from '../types/index';
3
+ import {
4
+ positionNodes,
5
+ validateNodeInputs,
6
+ validateNodeParameters,
7
+ validateWorkflow,
8
+ } from '../utils/workflow';
9
+ import { getService } from './_helpers';
10
+
11
+ function isRecord(value: unknown): value is Record<string, unknown> {
12
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
13
+ }
14
+
15
+ function isWorkflowDefinition(value: unknown): value is WorkflowDefinition {
16
+ return (
17
+ isRecord(value) &&
18
+ typeof value.name === 'string' &&
19
+ Array.isArray(value.nodes) &&
20
+ isRecord(value.connections)
21
+ );
22
+ }
23
+
24
+ function readWorkflowBody(
25
+ body: RouteRequest['body']
26
+ ): { workflow: WorkflowDefinition; userId: string; activate?: boolean } | null {
27
+ if (!isRecord(body) || !isWorkflowDefinition(body.workflow) || typeof body.userId !== 'string') {
28
+ return null;
29
+ }
30
+ return {
31
+ workflow: body.workflow,
32
+ userId: body.userId,
33
+ activate: typeof body.activate === 'boolean' ? body.activate : undefined,
34
+ };
35
+ }
36
+
37
+ /**
38
+ * GET /workflows
39
+ */
40
+ async function listWorkflows(
41
+ req: RouteRequest,
42
+ res: RouteResponse,
43
+ runtime: IAgentRuntime
44
+ ): Promise<void> {
45
+ try {
46
+ const userId = req.query?.userId as string | undefined;
47
+ const service = getService(runtime);
48
+ const workflows = await service.listWorkflows(userId);
49
+ res.json({ success: true, data: workflows });
50
+ } catch (error) {
51
+ res.status(500).json({
52
+ success: false,
53
+ error: 'failed_to_list_workflows',
54
+ message: error instanceof Error ? error.message : 'Unknown error',
55
+ });
56
+ }
57
+ }
58
+
59
+ /**
60
+ * POST /workflows
61
+ * Body: { workflow: WorkflowDefinition, userId: string, activate?: boolean }
62
+ */
63
+ async function createWorkflow(
64
+ req: RouteRequest,
65
+ res: RouteResponse,
66
+ runtime: IAgentRuntime
67
+ ): Promise<void> {
68
+ try {
69
+ const payload = readWorkflowBody(req.body);
70
+ if (!payload) {
71
+ res.status(400).json({ success: false, error: 'workflow and userId are required' });
72
+ return;
73
+ }
74
+ const { workflow, userId, activate } = payload;
75
+
76
+ const validation = validateWorkflow(workflow);
77
+ if (!validation.valid) {
78
+ res.status(422).json({
79
+ success: false,
80
+ error: 'validation_failed',
81
+ errors: validation.errors,
82
+ warnings: validation.warnings,
83
+ });
84
+ return;
85
+ }
86
+
87
+ const paramWarnings = validateNodeParameters(workflow);
88
+ const inputWarnings = validateNodeInputs(workflow);
89
+ const positioned = positionNodes(workflow);
90
+
91
+ const service = getService(runtime);
92
+ const result = await service.deployWorkflow(positioned, userId);
93
+
94
+ if (result.missingCredentials.length > 0 && !result.id) {
95
+ res.status(200).json({
96
+ success: false,
97
+ reason: 'missing_integrations',
98
+ missingIntegrations: result.missingCredentials,
99
+ warnings: [...paramWarnings, ...inputWarnings],
100
+ });
101
+ return;
102
+ }
103
+
104
+ if (activate === false && result.active && result.id) {
105
+ await service.deactivateWorkflow(result.id);
106
+ result.active = false;
107
+ }
108
+
109
+ res.json({
110
+ success: true,
111
+ data: result,
112
+ warnings: [...paramWarnings, ...inputWarnings],
113
+ });
114
+ } catch (error) {
115
+ res.status(500).json({
116
+ success: false,
117
+ error: 'failed_to_create_workflow',
118
+ message: error instanceof Error ? error.message : 'Unknown error',
119
+ });
120
+ }
121
+ }
122
+
123
+ /**
124
+ * GET /workflows/:id
125
+ */
126
+ async function getWorkflow(
127
+ req: RouteRequest,
128
+ res: RouteResponse,
129
+ runtime: IAgentRuntime
130
+ ): Promise<void> {
131
+ try {
132
+ const id = req.params?.id;
133
+ if (!id) {
134
+ res.status(400).json({ success: false, error: 'workflow_id_required' });
135
+ return;
136
+ }
137
+
138
+ const service = getService(runtime);
139
+ const workflow = await service.getWorkflow(id);
140
+ res.json({ success: true, data: workflow });
141
+ } catch (error) {
142
+ res.status(500).json({
143
+ success: false,
144
+ error: 'failed_to_get_workflow',
145
+ message: error instanceof Error ? error.message : 'Unknown error',
146
+ });
147
+ }
148
+ }
149
+
150
+ /**
151
+ * PUT /workflows/:id
152
+ * Body: { workflow: WorkflowDefinition, userId: string }
153
+ *
154
+ * Uses deployWorkflow which handles credential resolution + update (when id is set).
155
+ */
156
+ async function updateWorkflow(
157
+ req: RouteRequest,
158
+ res: RouteResponse,
159
+ runtime: IAgentRuntime
160
+ ): Promise<void> {
161
+ try {
162
+ const id = req.params?.id;
163
+ if (!id) {
164
+ res.status(400).json({ success: false, error: 'workflow_id_required' });
165
+ return;
166
+ }
167
+
168
+ const payload = readWorkflowBody(req.body);
169
+ if (!payload) {
170
+ res.status(400).json({ success: false, error: 'workflow and userId are required' });
171
+ return;
172
+ }
173
+ const { workflow, userId } = payload;
174
+
175
+ const validation = validateWorkflow(workflow);
176
+ if (!validation.valid) {
177
+ res.status(422).json({
178
+ success: false,
179
+ error: 'validation_failed',
180
+ errors: validation.errors,
181
+ warnings: validation.warnings,
182
+ });
183
+ return;
184
+ }
185
+
186
+ const paramWarnings = validateNodeParameters(workflow);
187
+ const inputWarnings = validateNodeInputs(workflow);
188
+ const positioned = positionNodes({ ...workflow, id });
189
+
190
+ const service = getService(runtime);
191
+ const result = await service.deployWorkflow(positioned, userId);
192
+
193
+ if (result.missingCredentials.length > 0 && !result.id) {
194
+ res.status(200).json({
195
+ success: false,
196
+ reason: 'missing_integrations',
197
+ missingIntegrations: result.missingCredentials,
198
+ warnings: [...paramWarnings, ...inputWarnings],
199
+ });
200
+ return;
201
+ }
202
+
203
+ res.json({
204
+ success: true,
205
+ data: result,
206
+ warnings: [...paramWarnings, ...inputWarnings],
207
+ });
208
+ } catch (error) {
209
+ res.status(500).json({
210
+ success: false,
211
+ error: 'failed_to_update_workflow',
212
+ message: error instanceof Error ? error.message : 'Unknown error',
213
+ });
214
+ }
215
+ }
216
+
217
+ /**
218
+ * DELETE /workflows/:id
219
+ */
220
+ async function deleteWorkflow(
221
+ req: RouteRequest,
222
+ res: RouteResponse,
223
+ runtime: IAgentRuntime
224
+ ): Promise<void> {
225
+ try {
226
+ const id = req.params?.id;
227
+ if (!id) {
228
+ res.status(400).json({ success: false, error: 'workflow_id_required' });
229
+ return;
230
+ }
231
+
232
+ const service = getService(runtime);
233
+ await service.deleteWorkflow(id);
234
+ res.json({ success: true });
235
+ } catch (error) {
236
+ res.status(500).json({
237
+ success: false,
238
+ error: 'failed_to_delete_workflow',
239
+ message: error instanceof Error ? error.message : 'Unknown error',
240
+ });
241
+ }
242
+ }
243
+
244
+ /**
245
+ * POST /workflows/:id/activate
246
+ */
247
+ async function activateWorkflow(
248
+ req: RouteRequest,
249
+ res: RouteResponse,
250
+ runtime: IAgentRuntime
251
+ ): Promise<void> {
252
+ try {
253
+ const id = req.params?.id;
254
+ if (!id) {
255
+ res.status(400).json({ success: false, error: 'workflow_id_required' });
256
+ return;
257
+ }
258
+
259
+ const service = getService(runtime);
260
+ await service.activateWorkflow(id);
261
+ res.json({ success: true });
262
+ } catch (error) {
263
+ res.status(500).json({
264
+ success: false,
265
+ error: 'failed_to_activate_workflow',
266
+ message: error instanceof Error ? error.message : 'Unknown error',
267
+ });
268
+ }
269
+ }
270
+
271
+ /**
272
+ * POST /workflows/:id/deactivate
273
+ */
274
+ async function deactivateWorkflow(
275
+ req: RouteRequest,
276
+ res: RouteResponse,
277
+ runtime: IAgentRuntime
278
+ ): Promise<void> {
279
+ try {
280
+ const id = req.params?.id;
281
+ if (!id) {
282
+ res.status(400).json({ success: false, error: 'workflow_id_required' });
283
+ return;
284
+ }
285
+
286
+ const service = getService(runtime);
287
+ await service.deactivateWorkflow(id);
288
+ res.json({ success: true });
289
+ } catch (error) {
290
+ res.status(500).json({
291
+ success: false,
292
+ error: 'failed_to_deactivate_workflow',
293
+ message: error instanceof Error ? error.message : 'Unknown error',
294
+ });
295
+ }
296
+ }
297
+
298
+ export const workflowRoutes: Route[] = [
299
+ { type: 'GET', path: '/workflows', handler: listWorkflows },
300
+ { type: 'POST', path: '/workflows', handler: createWorkflow },
301
+ { type: 'GET', path: '/workflows/:id', handler: getWorkflow },
302
+ { type: 'PUT', path: '/workflows/:id', handler: updateWorkflow },
303
+ { type: 'DELETE', path: '/workflows/:id', handler: deleteWorkflow },
304
+ { type: 'POST', path: '/workflows/:id/activate', handler: activateWorkflow },
305
+ {
306
+ type: 'POST',
307
+ path: '/workflows/:id/deactivate',
308
+ handler: deactivateWorkflow,
309
+ },
310
+ ];
@@ -0,0 +1,21 @@
1
+ /**
2
+ * JSON schema for LLM draft intent classification output
3
+ */
4
+ export const draftIntentSchema = {
5
+ type: 'object',
6
+ properties: {
7
+ intent: {
8
+ type: 'string',
9
+ enum: ['confirm', 'cancel', 'modify', 'new'],
10
+ },
11
+ modificationRequest: {
12
+ type: 'string',
13
+ description: 'What the user wants changed (only for modify intent)',
14
+ },
15
+ reason: {
16
+ type: 'string',
17
+ description: 'Brief explanation of the classification',
18
+ },
19
+ },
20
+ required: ['intent', 'modificationRequest', 'reason'],
21
+ };
@@ -0,0 +1,8 @@
1
+ export const feasibilitySchema = {
2
+ type: 'object',
3
+ properties: {
4
+ feasible: { type: 'boolean' },
5
+ reason: { type: 'string' },
6
+ },
7
+ required: ['feasible', 'reason'],
8
+ };
@@ -0,0 +1,4 @@
1
+ export { draftIntentSchema } from './draftIntent';
2
+ export { feasibilitySchema } from './feasibility';
3
+ export { keywordExtractionSchema } from './keywordExtraction';
4
+ export { workflowMatchingSchema } from './workflowMatching';
@@ -0,0 +1,11 @@
1
+ export const keywordExtractionSchema = {
2
+ type: 'object',
3
+ properties: {
4
+ keywords: {
5
+ type: 'array',
6
+ items: { type: 'string' },
7
+ description: 'Up to 5 relevant keywords or phrases',
8
+ },
9
+ },
10
+ required: ['keywords'],
11
+ };
@@ -0,0 +1,29 @@
1
+ export const workflowMatchingSchema = {
2
+ type: 'object',
3
+ properties: {
4
+ matchedWorkflowId: {
5
+ type: 'string',
6
+ nullable: true,
7
+ },
8
+ confidence: {
9
+ type: 'string',
10
+ enum: ['high', 'medium', 'low', 'none'],
11
+ },
12
+ matches: {
13
+ type: 'array',
14
+ items: {
15
+ type: 'object',
16
+ properties: {
17
+ id: { type: 'string' },
18
+ name: { type: 'string' },
19
+ score: { type: 'number' },
20
+ },
21
+ required: ['id', 'name', 'score'],
22
+ },
23
+ },
24
+ reason: {
25
+ type: 'string',
26
+ },
27
+ },
28
+ required: ['matchedWorkflowId', 'confidence', 'matches', 'reason'],
29
+ };