@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,17 @@
|
|
|
1
|
+
export {
|
|
2
|
+
EMBEDDED_WORKFLOW_SERVICE_TYPE,
|
|
3
|
+
EmbeddedWorkflowService,
|
|
4
|
+
} from './embedded-workflow-service';
|
|
5
|
+
export { WorkflowCredentialStore } from './workflow-credential-store';
|
|
6
|
+
export {
|
|
7
|
+
createWorkflowDispatchService,
|
|
8
|
+
registerWorkflowDispatchService,
|
|
9
|
+
WORKFLOW_DISPATCH_SERVICE_TYPE,
|
|
10
|
+
type WorkflowDispatchResult,
|
|
11
|
+
type WorkflowDispatchService,
|
|
12
|
+
} from './workflow-dispatch';
|
|
13
|
+
export {
|
|
14
|
+
WORKFLOW_SERVICE_TYPE,
|
|
15
|
+
WorkflowService,
|
|
16
|
+
type WorkflowServiceConfig,
|
|
17
|
+
} from './workflow-service';
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { type IAgentRuntime, logger, Service } from '@elizaos/core';
|
|
2
|
+
import { and, eq, sql } from 'drizzle-orm';
|
|
3
|
+
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
4
|
+
import { credentialMappings } from '../db/schema';
|
|
5
|
+
import type {
|
|
6
|
+
ConnectorDisconnectedPayload,
|
|
7
|
+
CredentialMapping,
|
|
8
|
+
WorkflowCredentialStoreApi,
|
|
9
|
+
} from '../types/index';
|
|
10
|
+
import { CONNECTOR_DISCONNECTED_EVENT, WORKFLOW_CREDENTIAL_STORE_TYPE } from '../types/index';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Default DB-backed credential store.
|
|
14
|
+
* Maps (userId, credType) → workflows credential ID.
|
|
15
|
+
*
|
|
16
|
+
* On the cloud, a different plugin can register its own implementation
|
|
17
|
+
* under the same service type — runtime.getService() returns the first registered.
|
|
18
|
+
*/
|
|
19
|
+
export class WorkflowCredentialStore extends Service implements WorkflowCredentialStoreApi {
|
|
20
|
+
static override readonly serviceType = WORKFLOW_CREDENTIAL_STORE_TYPE;
|
|
21
|
+
|
|
22
|
+
override capabilityDescription =
|
|
23
|
+
'Stores workflows credential ID mappings per user and credential type, backed by PostgreSQL.';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Bound handler for the runtime `connector_disconnected` event. Stored on the
|
|
27
|
+
* instance so `stop()` can unregister exactly the same reference that
|
|
28
|
+
* `start()` registered (referential equality matters for unregisterEvent).
|
|
29
|
+
*/
|
|
30
|
+
private readonly connectorDisconnectedHandler = async (
|
|
31
|
+
payload: ConnectorDisconnectedPayload
|
|
32
|
+
): Promise<void> => {
|
|
33
|
+
if (!payload?.userId || !Array.isArray(payload.credTypes)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (payload.credTypes.length === 0) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
await Promise.all(
|
|
40
|
+
payload.credTypes.map((credType) =>
|
|
41
|
+
this.delete(payload.userId, credType).catch((err: unknown) => {
|
|
42
|
+
logger.warn(
|
|
43
|
+
{
|
|
44
|
+
src: 'plugin:workflow:service:credential-store',
|
|
45
|
+
userId: payload.userId,
|
|
46
|
+
credType,
|
|
47
|
+
connectorName: payload.connectorName,
|
|
48
|
+
error: err instanceof Error ? err.message : String(err),
|
|
49
|
+
},
|
|
50
|
+
'Failed to purge credential mapping on connector_disconnected'
|
|
51
|
+
);
|
|
52
|
+
})
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
private getDb(): NodePgDatabase {
|
|
58
|
+
const db = this.runtime.db;
|
|
59
|
+
if (!db) {
|
|
60
|
+
throw new Error('Database not available for WorkflowCredentialStore');
|
|
61
|
+
}
|
|
62
|
+
return db as NodePgDatabase;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static async start(runtime: IAgentRuntime): Promise<WorkflowCredentialStore> {
|
|
66
|
+
logger.info(
|
|
67
|
+
{ src: 'plugin:workflow:service:credential-store' },
|
|
68
|
+
'Starting Workflow Credential Store...'
|
|
69
|
+
);
|
|
70
|
+
const service = new WorkflowCredentialStore(runtime);
|
|
71
|
+
runtime.registerEvent<ConnectorDisconnectedPayload>(
|
|
72
|
+
CONNECTOR_DISCONNECTED_EVENT,
|
|
73
|
+
service.connectorDisconnectedHandler
|
|
74
|
+
);
|
|
75
|
+
logger.info(
|
|
76
|
+
{ src: 'plugin:workflow:service:credential-store' },
|
|
77
|
+
'Workflow Credential Store started'
|
|
78
|
+
);
|
|
79
|
+
return service;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
override async stop(): Promise<void> {
|
|
83
|
+
this.runtime.unregisterEvent<ConnectorDisconnectedPayload>(
|
|
84
|
+
CONNECTOR_DISCONNECTED_EVENT,
|
|
85
|
+
this.connectorDisconnectedHandler
|
|
86
|
+
);
|
|
87
|
+
logger.info(
|
|
88
|
+
{ src: 'plugin:workflow:service:credential-store' },
|
|
89
|
+
'Workflow Credential Store stopped'
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async get(userId: string, credType: string): Promise<string | null> {
|
|
94
|
+
const db = this.getDb();
|
|
95
|
+
const rows = await db
|
|
96
|
+
.select()
|
|
97
|
+
.from(credentialMappings)
|
|
98
|
+
.where(and(eq(credentialMappings.userId, userId), eq(credentialMappings.credType, credType)))
|
|
99
|
+
.limit(1);
|
|
100
|
+
return rows[0]?.workflowCredentialId ?? null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async set(userId: string, credType: string, workflowCredId: string): Promise<void> {
|
|
104
|
+
const db = this.getDb();
|
|
105
|
+
await db
|
|
106
|
+
.insert(credentialMappings)
|
|
107
|
+
.values({ userId, credType, workflowCredentialId: workflowCredId })
|
|
108
|
+
.onConflictDoUpdate({
|
|
109
|
+
target: [credentialMappings.userId, credentialMappings.credType],
|
|
110
|
+
set: { workflowCredentialId: workflowCredId, updatedAt: sql`now()` },
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async listByUser(userId: string): Promise<CredentialMapping[]> {
|
|
115
|
+
const db = this.getDb();
|
|
116
|
+
const rows = await db
|
|
117
|
+
.select({
|
|
118
|
+
credType: credentialMappings.credType,
|
|
119
|
+
workflowCredentialId: credentialMappings.workflowCredentialId,
|
|
120
|
+
})
|
|
121
|
+
.from(credentialMappings)
|
|
122
|
+
.where(eq(credentialMappings.userId, userId));
|
|
123
|
+
return rows;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async delete(userId: string, credType: string): Promise<void> {
|
|
127
|
+
const db = this.getDb();
|
|
128
|
+
await db
|
|
129
|
+
.delete(credentialMappings)
|
|
130
|
+
.where(and(eq(credentialMappings.userId, userId), eq(credentialMappings.credType, credType)));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow dispatch service - executes a workflow by id via the in-process
|
|
3
|
+
* EmbeddedWorkflowService registered by `@elizaos/plugin-workflow`.
|
|
4
|
+
*
|
|
5
|
+
* Consumed by the trigger dispatcher: triggers carrying `kind: "workflow"`
|
|
6
|
+
* resolve a workflow id and call
|
|
7
|
+
* runtime.getService("WORKFLOW_DISPATCH").execute(workflowId).
|
|
8
|
+
*
|
|
9
|
+
* Registered into the runtime services map by the plugin's `init` (see
|
|
10
|
+
* `plugins/plugin-workflow/src/index.ts`).
|
|
11
|
+
*
|
|
12
|
+
* The dispatch service is a thin routing layer - it looks up the embedded
|
|
13
|
+
* workflow service on the runtime and delegates to its `executeWorkflow`
|
|
14
|
+
* method. There is no HTTP boundary and no sidecar lifecycle.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { IAgentRuntime } from '@elizaos/core';
|
|
18
|
+
import { logger } from '@elizaos/core';
|
|
19
|
+
import {
|
|
20
|
+
EMBEDDED_WORKFLOW_SERVICE_TYPE,
|
|
21
|
+
type EmbeddedWorkflowService,
|
|
22
|
+
} from './embedded-workflow-service';
|
|
23
|
+
|
|
24
|
+
export const WORKFLOW_DISPATCH_SERVICE_TYPE = 'WORKFLOW_DISPATCH' as const;
|
|
25
|
+
|
|
26
|
+
export interface WorkflowDispatchResult {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
error?: string;
|
|
29
|
+
executionId?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface WorkflowDispatchService {
|
|
33
|
+
execute(workflowId: string, payload?: Record<string, unknown>): Promise<WorkflowDispatchResult>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface WorkflowDispatchServiceEntry extends WorkflowDispatchService {
|
|
37
|
+
stop(): Promise<void>;
|
|
38
|
+
capabilityDescription: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface RuntimeServiceRegistry {
|
|
42
|
+
set(serviceType: string, services: WorkflowDispatchServiceEntry[]): void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function resolveEmbeddedService(runtime: IAgentRuntime): EmbeddedWorkflowService | null {
|
|
46
|
+
const service = runtime.getService<EmbeddedWorkflowService>(EMBEDDED_WORKFLOW_SERVICE_TYPE);
|
|
47
|
+
if (service && typeof service.executeWorkflow === 'function') {
|
|
48
|
+
return service;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getRuntimeServiceRegistry(runtime: IAgentRuntime): RuntimeServiceRegistry | null {
|
|
54
|
+
const services: unknown = Reflect.get(runtime, 'services');
|
|
55
|
+
if (!services || typeof services !== 'object') {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const set: unknown = Reflect.get(services, 'set');
|
|
60
|
+
if (typeof set !== 'function') {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
set(serviceType, serviceEntries) {
|
|
66
|
+
Reflect.apply(set, services, [serviceType, serviceEntries]);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Construct the dispatch service. Registered under `WORKFLOW_DISPATCH` on the
|
|
73
|
+
* runtime by the plugin's `init` lifecycle hook.
|
|
74
|
+
*/
|
|
75
|
+
export function createWorkflowDispatchService(runtime: IAgentRuntime): WorkflowDispatchService {
|
|
76
|
+
return {
|
|
77
|
+
async execute(
|
|
78
|
+
workflowId: string,
|
|
79
|
+
_payload: Record<string, unknown> = {}
|
|
80
|
+
): Promise<WorkflowDispatchResult> {
|
|
81
|
+
const id = workflowId.trim();
|
|
82
|
+
if (!id) {
|
|
83
|
+
return { ok: false, error: 'workflow id required' };
|
|
84
|
+
}
|
|
85
|
+
const service = resolveEmbeddedService(runtime);
|
|
86
|
+
if (!service) {
|
|
87
|
+
return { ok: false, error: 'embedded workflow service not registered' };
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const execution = await service.executeWorkflow(id, { mode: 'trigger' });
|
|
91
|
+
return execution.id ? { ok: true, executionId: execution.id } : { ok: true };
|
|
92
|
+
} catch (err) {
|
|
93
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
94
|
+
logger.warn(
|
|
95
|
+
{ src: 'plugin:workflow:dispatch' },
|
|
96
|
+
`Workflow execution failed for ${id}: ${message}`
|
|
97
|
+
);
|
|
98
|
+
return { ok: false, error: message };
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Register the dispatch service in the runtime services map under
|
|
106
|
+
* `WORKFLOW_DISPATCH`. Called from the plugin's `init`.
|
|
107
|
+
*
|
|
108
|
+
* The runtime's `registerService(ServiceClass)` API expects a class with a
|
|
109
|
+
* static `start()`. The dispatch is a closure-based singleton, so we set the
|
|
110
|
+
* services map slot directly (mirrors `runtime/plugin-lifecycle.ts` and
|
|
111
|
+
* `test/scripts/*.ts`).
|
|
112
|
+
*/
|
|
113
|
+
export function registerWorkflowDispatchService(runtime: IAgentRuntime): void {
|
|
114
|
+
const dispatch = createWorkflowDispatchService(runtime);
|
|
115
|
+
const serviceEntry: WorkflowDispatchServiceEntry = {
|
|
116
|
+
execute: dispatch.execute,
|
|
117
|
+
stop: async () => {},
|
|
118
|
+
capabilityDescription: 'Executes embedded workflows by id via the in-process workflow service.',
|
|
119
|
+
};
|
|
120
|
+
getRuntimeServiceRegistry(runtime)?.set(WORKFLOW_DISPATCH_SERVICE_TYPE, [serviceEntry]);
|
|
121
|
+
}
|