@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 @@
1
+ {}
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,8 @@
1
+ export {
2
+ credentialMappings,
3
+ embeddedCredentials,
4
+ embeddedExecutions,
5
+ embeddedTags,
6
+ embeddedWorkflows,
7
+ workflowSchema,
8
+ } from './schema';
@@ -0,0 +1,94 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import {
3
+ boolean,
4
+ index,
5
+ jsonb,
6
+ pgSchema,
7
+ text,
8
+ timestamp,
9
+ uniqueIndex,
10
+ uuid,
11
+ } from 'drizzle-orm/pg-core';
12
+ import type { WorkflowDefinition, WorkflowExecution } from '../types/index';
13
+
14
+ export const workflowSchema = pgSchema('workflow');
15
+
16
+ export const credentialMappings = workflowSchema.table(
17
+ 'credential_mappings',
18
+ {
19
+ id: uuid('id').primaryKey().defaultRandom(),
20
+ userId: text('user_id').notNull(),
21
+ credType: text('cred_type').notNull(),
22
+ workflowCredentialId: text('workflow_credential_id').notNull(),
23
+ createdAt: timestamp('created_at').default(sql`now()`).notNull(),
24
+ updatedAt: timestamp('updated_at').default(sql`now()`).notNull(),
25
+ },
26
+ (table) => ({
27
+ userCredIdx: uniqueIndex('idx_user_cred').on(table.userId, table.credType),
28
+ })
29
+ );
30
+
31
+ export const embeddedWorkflows = workflowSchema.table(
32
+ 'embedded_workflows',
33
+ {
34
+ id: text('id').primaryKey(),
35
+ name: text('name').notNull(),
36
+ active: boolean('active').default(false).notNull(),
37
+ workflow: jsonb('workflow').$type<WorkflowDefinition>().notNull(),
38
+ createdAt: text('created_at').notNull(),
39
+ updatedAt: text('updated_at').notNull(),
40
+ versionId: text('version_id').notNull(),
41
+ },
42
+ (table) => ({
43
+ activeIdx: index('idx_embedded_workflows_active').on(table.active),
44
+ updatedAtIdx: index('idx_embedded_workflows_updated_at').on(table.updatedAt),
45
+ })
46
+ );
47
+
48
+ export const embeddedExecutions = workflowSchema.table(
49
+ 'embedded_executions',
50
+ {
51
+ id: text('id').primaryKey(),
52
+ workflowId: text('workflow_id').notNull(),
53
+ status: text('status').notNull(),
54
+ mode: text('mode').notNull(),
55
+ finished: boolean('finished').default(false).notNull(),
56
+ startedAt: text('started_at').notNull(),
57
+ stoppedAt: text('stopped_at'),
58
+ execution: jsonb('execution').$type<WorkflowExecution>().notNull(),
59
+ },
60
+ (table) => ({
61
+ workflowIdx: index('idx_embedded_executions_workflow_id').on(table.workflowId),
62
+ statusIdx: index('idx_embedded_executions_status').on(table.status),
63
+ startedAtIdx: index('idx_embedded_executions_started_at').on(table.startedAt),
64
+ })
65
+ );
66
+
67
+ export const embeddedCredentials = workflowSchema.table(
68
+ 'embedded_credentials',
69
+ {
70
+ id: text('id').primaryKey(),
71
+ name: text('name').notNull(),
72
+ type: text('type').notNull(),
73
+ data: jsonb('data').$type<Record<string, unknown>>().notNull(),
74
+ isResolvable: boolean('is_resolvable').default(true).notNull(),
75
+ createdAt: text('created_at').notNull(),
76
+ updatedAt: text('updated_at').notNull(),
77
+ },
78
+ (table) => ({
79
+ typeIdx: index('idx_embedded_credentials_type').on(table.type),
80
+ })
81
+ );
82
+
83
+ export const embeddedTags = workflowSchema.table(
84
+ 'embedded_tags',
85
+ {
86
+ id: text('id').primaryKey(),
87
+ name: text('name').notNull(),
88
+ createdAt: text('created_at').notNull(),
89
+ updatedAt: text('updated_at').notNull(),
90
+ },
91
+ (table) => ({
92
+ nameIdx: uniqueIndex('idx_embedded_tags_name').on(table.name),
93
+ })
94
+ );
package/src/index.ts ADDED
@@ -0,0 +1,179 @@
1
+ import { type IAgentRuntime, logger, type Plugin } from '@elizaos/core';
2
+ import { workflowAction } from './actions/index';
3
+ import * as dbSchema from './db/index';
4
+ import { migrateLegacyTextTriggers, migrateLegacyWorkbenchTasks } from './lib/index';
5
+ import {
6
+ activeWorkflowsProvider,
7
+ pendingDraftProvider,
8
+ workflowStatusProvider,
9
+ } from './providers/index';
10
+ import { workflowRoutes } from './routes/index';
11
+ import {
12
+ EmbeddedWorkflowService,
13
+ registerWorkflowDispatchService,
14
+ WORKFLOW_SERVICE_TYPE,
15
+ WorkflowCredentialStore,
16
+ WorkflowService,
17
+ } from './services/index';
18
+ // Side-effect: register the rawPath route plugin
19
+ // (`@elizaos/plugin-workflow:routes`) with the app-route-plugin-registry so
20
+ // the runtime mounts /api/workflow/* on the host HTTP server. Without this
21
+ // import the registry call in register-routes.ts never fires and every
22
+ // /api/workflow/* request returns 404.
23
+ import './register-routes';
24
+
25
+ /**
26
+ * Workflow Plugin for ElizaOS
27
+ *
28
+ * Generate and manage workflows from natural language using a RAG pipeline.
29
+ * Supports workflow CRUD, execution management, and credential resolution.
30
+ *
31
+ * **Optional Configuration:**
32
+ * - `workflows.credentials`: Pre-configured credential IDs for local mode
33
+ *
34
+ * **Example Character Configuration:**
35
+ * ```json
36
+ * {
37
+ * "name": "AI Workflow Builder",
38
+ * "plugins": ["@elizaos/plugin-workflow"],
39
+ * "settings": {
40
+ * "workflows": {
41
+ * "credentials": {
42
+ * "gmailOAuth2": "cred_gmail_123",
43
+ * "stripeApi": "cred_stripe_456"
44
+ * }
45
+ * }
46
+ * }
47
+ * }
48
+ * ```
49
+ */
50
+ export const workflowPlugin: Plugin = {
51
+ name: 'workflow',
52
+ description:
53
+ 'Generate and deploy workflows from natural language. ' +
54
+ 'Runs supported workflow nodes in-process with credential resolution.',
55
+
56
+ services: [EmbeddedWorkflowService, WorkflowService, WorkflowCredentialStore],
57
+
58
+ schema: dbSchema,
59
+
60
+ actions: [workflowAction],
61
+
62
+ providers: [workflowStatusProvider, activeWorkflowsProvider, pendingDraftProvider],
63
+
64
+ routes: workflowRoutes,
65
+
66
+ init: async (_config: Record<string, string>, runtime: IAgentRuntime): Promise<void> => {
67
+ // Check for pre-configured credentials (optional)
68
+ // Note: runtime.getSetting() only returns primitives — nested objects must be read directly
69
+ const workflowSettings = runtime.character?.settings?.workflows as
70
+ | { credentials?: Record<string, string> }
71
+ | undefined;
72
+ if (workflowSettings?.credentials) {
73
+ const credCount = Object.keys(workflowSettings.credentials).filter(
74
+ (k) => workflowSettings.credentials?.[k]
75
+ ).length;
76
+ logger.info(
77
+ { src: 'plugin:workflow:plugin:init' },
78
+ `Pre-configured credentials: ${credCount} credential types`
79
+ );
80
+ }
81
+
82
+ // Register WORKFLOW_DISPATCH so trigger-kind=workflow tasks can call
83
+ // runtime.getService("WORKFLOW_DISPATCH").execute(workflowId).
84
+ registerWorkflowDispatchService(runtime);
85
+
86
+ // Schedule one-shot legacy migrations off the init critical path. Service
87
+ // start-order is not guaranteed at init: WorkflowService may not be in
88
+ // the registry yet. Poll up to 10 times (1s spacing) and bail quietly
89
+ // if it never appears. Each migration is idempotent so a duplicate run
90
+ // on a future boot is harmless.
91
+ scheduleLegacyMigrations(runtime);
92
+
93
+ logger.info(
94
+ { src: 'plugin:workflow:plugin:init' },
95
+ 'Workflow Plugin initialized successfully (in-process runtime)'
96
+ );
97
+ },
98
+ };
99
+
100
+ const MIGRATION_RETRY_LIMIT = 10;
101
+ const MIGRATION_RETRY_INTERVAL_MS = 1000;
102
+
103
+ function scheduleLegacyMigrations(runtime: IAgentRuntime): void {
104
+ let attempts = 0;
105
+ const tick = (): void => {
106
+ attempts += 1;
107
+ const ready = runtime.getService(WORKFLOW_SERVICE_TYPE);
108
+ if (!ready) {
109
+ if (attempts >= MIGRATION_RETRY_LIMIT) {
110
+ logger.warn(
111
+ { src: 'plugin:workflow:plugin:migration' },
112
+ `WorkflowService still not registered after ${MIGRATION_RETRY_LIMIT} retries; legacy migrations will run on next boot`
113
+ );
114
+ return;
115
+ }
116
+ setTimeout(tick, MIGRATION_RETRY_INTERVAL_MS);
117
+ return;
118
+ }
119
+ void runLegacyMigrations(runtime);
120
+ };
121
+ // Defer the first attempt off the init stack so the host runtime can
122
+ // finish wiring before we probe the service registry.
123
+ setImmediate(tick);
124
+ }
125
+
126
+ async function runLegacyMigrations(runtime: IAgentRuntime): Promise<void> {
127
+ try {
128
+ const summary = await migrateLegacyWorkbenchTasks(runtime);
129
+ logger.info(
130
+ {
131
+ src: 'plugin:workflow:plugin:migration',
132
+ migrated: summary.migrated,
133
+ skipped: summary.skipped,
134
+ failed: summary.failed,
135
+ },
136
+ `Workbench-task migration: ${summary.migrated} migrated, ${summary.skipped} skipped, ${summary.failed} failed`
137
+ );
138
+ } catch (err) {
139
+ logger.warn(
140
+ {
141
+ src: 'plugin:workflow:plugin:migration',
142
+ err: err instanceof Error ? err.message : String(err),
143
+ },
144
+ 'Workbench-task migration threw; continuing'
145
+ );
146
+ }
147
+
148
+ try {
149
+ const summary = await migrateLegacyTextTriggers(runtime);
150
+ logger.info(
151
+ {
152
+ src: 'plugin:workflow:plugin:migration',
153
+ migrated: summary.migrated,
154
+ skipped: summary.skipped,
155
+ failed: summary.failed,
156
+ },
157
+ `Text-trigger migration: ${summary.migrated} migrated, ${summary.skipped} skipped, ${summary.failed} failed`
158
+ );
159
+ } catch (err) {
160
+ logger.warn(
161
+ {
162
+ src: 'plugin:workflow:plugin:migration',
163
+ err: err instanceof Error ? err.message : String(err),
164
+ },
165
+ 'Text-trigger migration threw; continuing'
166
+ );
167
+ }
168
+ }
169
+
170
+ export default workflowPlugin;
171
+
172
+ export * from './plugin-routes.js';
173
+ export * from './register-routes.js';
174
+ export * from './services/workflow-dispatch.js';
175
+ export {
176
+ handleTriggerRoutes,
177
+ type TriggerRouteContext,
178
+ type TriggerRouteHelpers,
179
+ } from './trigger-routes.js';