@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.
- package/README.md +71 -0
- package/auto-enable.ts +18 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +2 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/workflow.d.ts +23 -0
- package/dist/actions/workflow.d.ts.map +1 -0
- package/dist/actions/workflow.js +425 -0
- package/dist/actions/workflow.js.map +1 -0
- package/dist/data/defaultNodes.json +9887 -0
- package/dist/data/schemaIndex.json +1 -0
- package/dist/data/triggerSchemaIndex.json +1 -0
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +2 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/schema.d.ts +588 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +59 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +126 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/automations-builder.d.ts +21 -0
- package/dist/lib/automations-builder.d.ts.map +1 -0
- package/dist/lib/automations-builder.js +557 -0
- package/dist/lib/automations-builder.js.map +1 -0
- package/dist/lib/automations-types.d.ts +153 -0
- package/dist/lib/automations-types.d.ts.map +1 -0
- package/dist/lib/automations-types.js +191 -0
- package/dist/lib/automations-types.js.map +1 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +3 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/legacy-task-migration.d.ts +20 -0
- package/dist/lib/legacy-task-migration.d.ts.map +1 -0
- package/dist/lib/legacy-task-migration.js +110 -0
- package/dist/lib/legacy-task-migration.js.map +1 -0
- package/dist/lib/legacy-text-trigger-migration.d.ts +18 -0
- package/dist/lib/legacy-text-trigger-migration.d.ts.map +1 -0
- package/dist/lib/legacy-text-trigger-migration.js +131 -0
- package/dist/lib/legacy-text-trigger-migration.js.map +1 -0
- package/dist/lib/workflow-clarification.d.ts +113 -0
- package/dist/lib/workflow-clarification.d.ts.map +1 -0
- package/dist/lib/workflow-clarification.js +425 -0
- package/dist/lib/workflow-clarification.js.map +1 -0
- package/dist/plugin-routes.d.ts +9 -0
- package/dist/plugin-routes.d.ts.map +1 -0
- package/dist/plugin-routes.js +147 -0
- package/dist/plugin-routes.js.map +1 -0
- package/dist/providers/activeWorkflows.d.ts +11 -0
- package/dist/providers/activeWorkflows.d.ts.map +1 -0
- package/dist/providers/activeWorkflows.js +72 -0
- package/dist/providers/activeWorkflows.js.map +1 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/pendingDraft.d.ts +9 -0
- package/dist/providers/pendingDraft.d.ts.map +1 -0
- package/dist/providers/pendingDraft.js +48 -0
- package/dist/providers/pendingDraft.js.map +1 -0
- package/dist/providers/workflowStatus.d.ts +3 -0
- package/dist/providers/workflowStatus.d.ts.map +1 -0
- package/dist/providers/workflowStatus.js +69 -0
- package/dist/providers/workflowStatus.js.map +1 -0
- package/dist/register-routes.d.ts +2 -0
- package/dist/register-routes.d.ts.map +1 -0
- package/dist/register-routes.js +6 -0
- package/dist/register-routes.js.map +1 -0
- package/dist/routes/_helpers.d.ts +11 -0
- package/dist/routes/_helpers.d.ts.map +1 -0
- package/dist/routes/_helpers.js +22 -0
- package/dist/routes/_helpers.js.map +1 -0
- package/dist/routes/automations.d.ts +19 -0
- package/dist/routes/automations.d.ts.map +1 -0
- package/dist/routes/automations.js +32 -0
- package/dist/routes/automations.js.map +1 -0
- package/dist/routes/embedded-webhooks.d.ts +3 -0
- package/dist/routes/embedded-webhooks.d.ts.map +1 -0
- package/dist/routes/embedded-webhooks.js +47 -0
- package/dist/routes/embedded-webhooks.js.map +1 -0
- package/dist/routes/executions.d.ts +3 -0
- package/dist/routes/executions.d.ts.map +1 -0
- package/dist/routes/executions.js +58 -0
- package/dist/routes/executions.js.map +1 -0
- package/dist/routes/index.d.ts +4 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +14 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/nodes.d.ts +3 -0
- package/dist/routes/nodes.d.ts.map +1 -0
- package/dist/routes/nodes.js +168 -0
- package/dist/routes/nodes.js.map +1 -0
- package/dist/routes/validation.d.ts +3 -0
- package/dist/routes/validation.d.ts.map +1 -0
- package/dist/routes/validation.js +41 -0
- package/dist/routes/validation.js.map +1 -0
- package/dist/routes/workflow-routes.d.ts +27 -0
- package/dist/routes/workflow-routes.d.ts.map +1 -0
- package/dist/routes/workflow-routes.js +326 -0
- package/dist/routes/workflow-routes.js.map +1 -0
- package/dist/routes/workflows.d.ts +3 -0
- package/dist/routes/workflows.d.ts.map +1 -0
- package/dist/routes/workflows.js +252 -0
- package/dist/routes/workflows.js.map +1 -0
- package/dist/schemas/draftIntent.d.ts +22 -0
- package/dist/schemas/draftIntent.d.ts.map +1 -0
- package/dist/schemas/draftIntent.js +22 -0
- package/dist/schemas/draftIntent.js.map +1 -0
- package/dist/schemas/feasibility.d.ts +13 -0
- package/dist/schemas/feasibility.d.ts.map +1 -0
- package/dist/schemas/feasibility.js +9 -0
- package/dist/schemas/feasibility.js.map +1 -0
- package/dist/schemas/index.d.ts +5 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +5 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/keywordExtraction.d.ts +14 -0
- package/dist/schemas/keywordExtraction.d.ts.map +1 -0
- package/dist/schemas/keywordExtraction.js +12 -0
- package/dist/schemas/keywordExtraction.js.map +1 -0
- package/dist/schemas/workflowMatching.d.ts +36 -0
- package/dist/schemas/workflowMatching.d.ts.map +1 -0
- package/dist/schemas/workflowMatching.js +30 -0
- package/dist/schemas/workflowMatching.js.map +1 -0
- package/dist/services/embedded-workflow-service.d.ts +106 -0
- package/dist/services/embedded-workflow-service.d.ts.map +1 -0
- package/dist/services/embedded-workflow-service.js +1900 -0
- package/dist/services/embedded-workflow-service.js.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +5 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/workflow-credential-store.d.ts +27 -0
- package/dist/services/workflow-credential-store.d.ts.map +1 -0
- package/dist/services/workflow-credential-store.js +92 -0
- package/dist/services/workflow-credential-store.js.map +1 -0
- package/dist/services/workflow-dispatch.d.ts +41 -0
- package/dist/services/workflow-dispatch.d.ts.map +1 -0
- package/dist/services/workflow-dispatch.js +86 -0
- package/dist/services/workflow-dispatch.js.map +1 -0
- package/dist/services/workflow-service.d.ts +63 -0
- package/dist/services/workflow-service.d.ts.map +1 -0
- package/dist/services/workflow-service.js +492 -0
- package/dist/services/workflow-service.js.map +1 -0
- package/dist/trigger-routes.d.ts +153 -0
- package/dist/trigger-routes.d.ts.map +1 -0
- package/dist/trigger-routes.js +424 -0
- package/dist/trigger-routes.js.map +1 -0
- package/dist/types/index.d.ts +457 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +59 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/catalog.d.ts +16 -0
- package/dist/utils/catalog.d.ts.map +1 -0
- package/dist/utils/catalog.js +211 -0
- package/dist/utils/catalog.js.map +1 -0
- package/dist/utils/clarification.d.ts +17 -0
- package/dist/utils/clarification.d.ts.map +1 -0
- package/dist/utils/clarification.js +46 -0
- package/dist/utils/clarification.js.map +1 -0
- package/dist/utils/context.d.ts +4 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +18 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/credentialResolver.d.ts +22 -0
- package/dist/utils/credentialResolver.d.ts.map +1 -0
- package/dist/utils/credentialResolver.js +146 -0
- package/dist/utils/credentialResolver.js.map +1 -0
- package/dist/utils/generation.d.ts +36 -0
- package/dist/utils/generation.d.ts.map +1 -0
- package/dist/utils/generation.js +701 -0
- package/dist/utils/generation.js.map +1 -0
- package/dist/utils/host-capabilities.d.ts +27 -0
- package/dist/utils/host-capabilities.d.ts.map +1 -0
- package/dist/utils/host-capabilities.js +59 -0
- package/dist/utils/host-capabilities.js.map +1 -0
- package/dist/utils/inferSyntheticOutputSchema.d.ts +20 -0
- package/dist/utils/inferSyntheticOutputSchema.d.ts.map +1 -0
- package/dist/utils/inferSyntheticOutputSchema.js +151 -0
- package/dist/utils/inferSyntheticOutputSchema.js.map +1 -0
- package/dist/utils/outputSchema.d.ts +26 -0
- package/dist/utils/outputSchema.d.ts.map +1 -0
- package/dist/utils/outputSchema.js +297 -0
- package/dist/utils/outputSchema.js.map +1 -0
- package/dist/utils/validateAndRepair.d.ts +41 -0
- package/dist/utils/validateAndRepair.d.ts.map +1 -0
- package/dist/utils/validateAndRepair.js +483 -0
- package/dist/utils/validateAndRepair.js.map +1 -0
- package/dist/utils/workflow-prompts/actionResponse.d.ts +2 -0
- package/dist/utils/workflow-prompts/actionResponse.d.ts.map +1 -0
- package/dist/utils/workflow-prompts/actionResponse.js +17 -0
- package/dist/utils/workflow-prompts/actionResponse.js.map +1 -0
- package/dist/utils/workflow-prompts/draftIntent.d.ts +2 -0
- package/dist/utils/workflow-prompts/draftIntent.d.ts.map +1 -0
- package/dist/utils/workflow-prompts/draftIntent.js +23 -0
- package/dist/utils/workflow-prompts/draftIntent.js.map +1 -0
- package/dist/utils/workflow-prompts/feasibilityCheck.d.ts +2 -0
- package/dist/utils/workflow-prompts/feasibilityCheck.d.ts.map +1 -0
- package/dist/utils/workflow-prompts/feasibilityCheck.js +21 -0
- package/dist/utils/workflow-prompts/feasibilityCheck.js.map +1 -0
- package/dist/utils/workflow-prompts/fieldCorrection.d.ts +3 -0
- package/dist/utils/workflow-prompts/fieldCorrection.d.ts.map +1 -0
- package/dist/utils/workflow-prompts/fieldCorrection.js +20 -0
- package/dist/utils/workflow-prompts/fieldCorrection.js.map +1 -0
- package/dist/utils/workflow-prompts/index.d.ts +8 -0
- package/dist/utils/workflow-prompts/index.d.ts.map +1 -0
- package/dist/utils/workflow-prompts/index.js +8 -0
- package/dist/utils/workflow-prompts/index.js.map +1 -0
- package/dist/utils/workflow-prompts/keywordExtraction.d.ts +2 -0
- package/dist/utils/workflow-prompts/keywordExtraction.d.ts.map +1 -0
- package/dist/utils/workflow-prompts/keywordExtraction.js +21 -0
- package/dist/utils/workflow-prompts/keywordExtraction.js.map +1 -0
- package/dist/utils/workflow-prompts/parameterCorrection.d.ts +3 -0
- package/dist/utils/workflow-prompts/parameterCorrection.d.ts.map +1 -0
- package/dist/utils/workflow-prompts/parameterCorrection.js +29 -0
- package/dist/utils/workflow-prompts/parameterCorrection.js.map +1 -0
- package/dist/utils/workflow-prompts/workflowGeneration.d.ts +2 -0
- package/dist/utils/workflow-prompts/workflowGeneration.d.ts.map +1 -0
- package/dist/utils/workflow-prompts/workflowGeneration.js +529 -0
- package/dist/utils/workflow-prompts/workflowGeneration.js.map +1 -0
- package/dist/utils/workflow-prompts/workflowMatching.d.ts +2 -0
- package/dist/utils/workflow-prompts/workflowMatching.d.ts.map +1 -0
- package/dist/utils/workflow-prompts/workflowMatching.js +23 -0
- package/dist/utils/workflow-prompts/workflowMatching.js.map +1 -0
- package/dist/utils/workflow.d.ts +62 -0
- package/dist/utils/workflow.d.ts.map +1 -0
- package/dist/utils/workflow.js +712 -0
- package/dist/utils/workflow.js.map +1 -0
- package/package.json +87 -0
- package/src/actions/index.ts +1 -0
- package/src/actions/workflow.ts +494 -0
- package/src/data/defaultNodes.json +9887 -0
- package/src/data/schemaIndex.json +1 -0
- package/src/data/triggerSchemaIndex.json +1 -0
- package/src/db/index.ts +8 -0
- package/src/db/schema.ts +94 -0
- package/src/index.ts +179 -0
- package/src/lib/automations-builder.ts +679 -0
- package/src/lib/automations-types.ts +391 -0
- package/src/lib/index.ts +8 -0
- package/src/lib/legacy-task-migration.ts +143 -0
- package/src/lib/legacy-text-trigger-migration.ts +178 -0
- package/src/lib/workflow-clarification.ts +497 -0
- package/src/plugin-routes.ts +164 -0
- package/src/providers/activeWorkflows.ts +81 -0
- package/src/providers/index.ts +3 -0
- package/src/providers/pendingDraft.ts +55 -0
- package/src/providers/workflowStatus.ts +88 -0
- package/src/register-routes.ts +6 -0
- package/src/routes/_helpers.ts +27 -0
- package/src/routes/automations.ts +46 -0
- package/src/routes/embedded-webhooks.ts +64 -0
- package/src/routes/executions.ts +75 -0
- package/src/routes/index.ts +16 -0
- package/src/routes/nodes.ts +211 -0
- package/src/routes/validation.ts +51 -0
- package/src/routes/workflow-routes.ts +469 -0
- package/src/routes/workflows.ts +310 -0
- package/src/schemas/draftIntent.ts +21 -0
- package/src/schemas/feasibility.ts +8 -0
- package/src/schemas/index.ts +4 -0
- package/src/schemas/keywordExtraction.ts +11 -0
- package/src/schemas/workflowMatching.ts +29 -0
- package/src/services/embedded-workflow-service.ts +2224 -0
- package/src/services/index.ts +17 -0
- package/src/services/workflow-credential-store.ts +132 -0
- package/src/services/workflow-dispatch.ts +121 -0
- package/src/services/workflow-service.ts +839 -0
- package/src/trigger-routes.ts +714 -0
- package/src/types/index.ts +562 -0
- package/src/utils/catalog.ts +260 -0
- package/src/utils/clarification.ts +52 -0
- package/src/utils/context.ts +22 -0
- package/src/utils/credentialResolver.ts +234 -0
- package/src/utils/generation.ts +987 -0
- package/src/utils/host-capabilities.ts +81 -0
- package/src/utils/inferSyntheticOutputSchema.ts +163 -0
- package/src/utils/outputSchema.ts +372 -0
- package/src/utils/validateAndRepair.ts +610 -0
- package/src/utils/workflow-prompts/actionResponse.ts +16 -0
- package/src/utils/workflow-prompts/draftIntent.ts +22 -0
- package/src/utils/workflow-prompts/feasibilityCheck.ts +20 -0
- package/src/utils/workflow-prompts/fieldCorrection.ts +20 -0
- package/src/utils/workflow-prompts/index.ts +10 -0
- package/src/utils/workflow-prompts/keywordExtraction.ts +20 -0
- package/src/utils/workflow-prompts/parameterCorrection.ts +29 -0
- package/src/utils/workflow-prompts/workflowGeneration.ts +528 -0
- package/src/utils/workflow-prompts/workflowMatching.ts +22 -0
- package/src/utils/workflow.ts +895 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/src/db/index.ts
ADDED
package/src/db/schema.ts
ADDED
|
@@ -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';
|