@elizaos/plugin-n8n-workflow 1.0.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 +199 -0
- package/dist/actions/activateWorkflow.d.ts +4 -0
- package/dist/actions/activateWorkflow.d.ts.map +1 -0
- package/dist/actions/activateWorkflow.js +116 -0
- package/dist/actions/activateWorkflow.js.map +1 -0
- package/dist/actions/createWorkflow.d.ts +4 -0
- package/dist/actions/createWorkflow.d.ts.map +1 -0
- package/dist/actions/createWorkflow.js +141 -0
- package/dist/actions/createWorkflow.js.map +1 -0
- package/dist/actions/deactivateWorkflow.d.ts +4 -0
- package/dist/actions/deactivateWorkflow.d.ts.map +1 -0
- package/dist/actions/deactivateWorkflow.js +121 -0
- package/dist/actions/deactivateWorkflow.js.map +1 -0
- package/dist/actions/deleteWorkflow.d.ts +4 -0
- package/dist/actions/deleteWorkflow.d.ts.map +1 -0
- package/dist/actions/deleteWorkflow.js +115 -0
- package/dist/actions/deleteWorkflow.js.map +1 -0
- package/dist/actions/executeWorkflow.d.ts +4 -0
- package/dist/actions/executeWorkflow.d.ts.map +1 -0
- package/dist/actions/executeWorkflow.js +74 -0
- package/dist/actions/executeWorkflow.js.map +1 -0
- package/dist/actions/getExecutions.d.ts +4 -0
- package/dist/actions/getExecutions.d.ts.map +1 -0
- package/dist/actions/getExecutions.js +108 -0
- package/dist/actions/getExecutions.js.map +1 -0
- package/dist/actions/index.d.ts +9 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +9 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/listCredentials.d.ts +4 -0
- package/dist/actions/listCredentials.d.ts.map +1 -0
- package/dist/actions/listCredentials.js +102 -0
- package/dist/actions/listCredentials.js.map +1 -0
- package/dist/actions/listWorkflows.d.ts +4 -0
- package/dist/actions/listWorkflows.d.ts.map +1 -0
- package/dist/actions/listWorkflows.js +97 -0
- package/dist/actions/listWorkflows.js.map +1 -0
- package/dist/data/defaultNodes.json +427888 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +75 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts/index.d.ts +3 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +3 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/keywordExtraction.d.ts +6 -0
- package/dist/prompts/keywordExtraction.d.ts.map +1 -0
- package/dist/prompts/keywordExtraction.js +19 -0
- package/dist/prompts/keywordExtraction.js.map +1 -0
- package/dist/prompts/workflowGeneration.d.ts +7 -0
- package/dist/prompts/workflowGeneration.d.ts.map +1 -0
- package/dist/prompts/workflowGeneration.js +330 -0
- package/dist/prompts/workflowGeneration.js.map +1 -0
- package/dist/prompts/workflowMatching.d.ts +7 -0
- package/dist/prompts/workflowMatching.d.ts.map +1 -0
- package/dist/prompts/workflowMatching.js +25 -0
- package/dist/prompts/workflowMatching.js.map +1 -0
- package/dist/providers/activeWorkflows.d.ts +12 -0
- package/dist/providers/activeWorkflows.d.ts.map +1 -0
- package/dist/providers/activeWorkflows.js +69 -0
- package/dist/providers/activeWorkflows.js.map +1 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +3 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/workflowStatus.d.ts +4 -0
- package/dist/providers/workflowStatus.d.ts.map +1 -0
- package/dist/providers/workflowStatus.js +66 -0
- package/dist/providers/workflowStatus.js.map +1 -0
- package/dist/schemas/index.d.ts +3 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +3 -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/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +2 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/n8n-workflow-service.d.ts +83 -0
- package/dist/services/n8n-workflow-service.d.ts.map +1 -0
- package/dist/services/n8n-workflow-service.js +234 -0
- package/dist/services/n8n-workflow-service.js.map +1 -0
- package/dist/types/index.d.ts +313 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +43 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/api.d.ts +137 -0
- package/dist/utils/api.d.ts.map +1 -0
- package/dist/utils/api.js +247 -0
- package/dist/utils/api.js.map +1 -0
- package/dist/utils/catalog.d.ts +22 -0
- package/dist/utils/catalog.d.ts.map +1 -0
- package/dist/utils/catalog.js +81 -0
- package/dist/utils/catalog.js.map +1 -0
- package/dist/utils/context.d.ts +8 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +17 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/credentialResolver.d.ts +13 -0
- package/dist/utils/credentialResolver.d.ts.map +1 -0
- package/dist/utils/credentialResolver.js +177 -0
- package/dist/utils/credentialResolver.js.map +1 -0
- package/dist/utils/generation.d.ts +46 -0
- package/dist/utils/generation.d.ts.map +1 -0
- package/dist/utils/generation.js +145 -0
- package/dist/utils/generation.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/workflow.d.ts +27 -0
- package/dist/utils/workflow.d.ts.map +1 -0
- package/dist/utils/workflow.js +289 -0
- package/dist/utils/workflow.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { N8nApiError, } from '../types/index';
|
|
2
|
+
/**
|
|
3
|
+
* n8n REST API client
|
|
4
|
+
* Full coverage of n8n Cloud API for workflow, credential, execution, and tag management
|
|
5
|
+
* @see https://docs.n8n.io/api/
|
|
6
|
+
*/
|
|
7
|
+
export class N8nApiClient {
|
|
8
|
+
baseUrl;
|
|
9
|
+
apiKey;
|
|
10
|
+
constructor(host, apiKey) {
|
|
11
|
+
this.baseUrl = host.replace(/\/$/, ''); // Remove trailing slash
|
|
12
|
+
this.apiKey = apiKey;
|
|
13
|
+
}
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// WORKFLOWS
|
|
16
|
+
// ============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* Create a new workflow
|
|
19
|
+
* @see POST /workflows
|
|
20
|
+
*/
|
|
21
|
+
async createWorkflow(workflow) {
|
|
22
|
+
return this.request('POST', '/workflows', workflow);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* List all workflows
|
|
26
|
+
* @see GET /workflows
|
|
27
|
+
*/
|
|
28
|
+
async listWorkflows(params) {
|
|
29
|
+
const query = new URLSearchParams();
|
|
30
|
+
if (params?.active !== undefined) {
|
|
31
|
+
query.append('active', params.active.toString());
|
|
32
|
+
}
|
|
33
|
+
if (params?.tags) {
|
|
34
|
+
params.tags.forEach((tag) => query.append('tags', tag));
|
|
35
|
+
}
|
|
36
|
+
if (params?.limit) {
|
|
37
|
+
query.append('limit', params.limit.toString());
|
|
38
|
+
}
|
|
39
|
+
if (params?.cursor) {
|
|
40
|
+
query.append('cursor', params.cursor);
|
|
41
|
+
}
|
|
42
|
+
return this.request('GET', `/workflows${query.toString() ? `?${query.toString()}` : ''}`);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get a specific workflow by ID
|
|
46
|
+
* @see GET /workflows/{id}
|
|
47
|
+
*/
|
|
48
|
+
async getWorkflow(id) {
|
|
49
|
+
return this.request('GET', `/workflows/${id}`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Update a workflow
|
|
53
|
+
* @see PUT /workflows/{id}
|
|
54
|
+
*/
|
|
55
|
+
async updateWorkflow(id, workflow) {
|
|
56
|
+
return this.request('PUT', `/workflows/${id}`, workflow);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Delete a workflow
|
|
60
|
+
* @see DELETE /workflows/{id}
|
|
61
|
+
*/
|
|
62
|
+
async deleteWorkflow(id) {
|
|
63
|
+
await this.request('DELETE', `/workflows/${id}`);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Activate a workflow
|
|
67
|
+
* @see POST /workflows/{id}/activate
|
|
68
|
+
*/
|
|
69
|
+
async activateWorkflow(id) {
|
|
70
|
+
return this.request('POST', `/workflows/${id}/activate`);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Deactivate a workflow
|
|
74
|
+
* @see POST /workflows/{id}/deactivate
|
|
75
|
+
*/
|
|
76
|
+
async deactivateWorkflow(id) {
|
|
77
|
+
return this.request('POST', `/workflows/${id}/deactivate`);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Manually execute a workflow
|
|
81
|
+
* @see POST /workflows/{id}/execute
|
|
82
|
+
*/
|
|
83
|
+
async executeWorkflow(id) {
|
|
84
|
+
return this.request('POST', `/workflows/${id}/execute`);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Update workflow tags
|
|
88
|
+
* @see PUT /workflows/{id}/tags
|
|
89
|
+
*/
|
|
90
|
+
async updateWorkflowTags(id, tagIds) {
|
|
91
|
+
return this.request('PUT', `/workflows/${id}/tags`, {
|
|
92
|
+
tags: tagIds,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// ============================================================================
|
|
96
|
+
// CREDENTIALS
|
|
97
|
+
// ============================================================================
|
|
98
|
+
/**
|
|
99
|
+
* Create a credential
|
|
100
|
+
* @see POST /credentials
|
|
101
|
+
*/
|
|
102
|
+
async createCredential(credential) {
|
|
103
|
+
return this.request('POST', '/credentials', credential);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* List credentials (filtered by type if provided)
|
|
107
|
+
* @see GET /credentials
|
|
108
|
+
*/
|
|
109
|
+
async listCredentials(params) {
|
|
110
|
+
const query = new URLSearchParams();
|
|
111
|
+
if (params?.type) {
|
|
112
|
+
query.append('type', params.type);
|
|
113
|
+
}
|
|
114
|
+
return this.request('GET', `/credentials${query.toString() ? `?${query.toString()}` : ''}`);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get credential schema for a specific type
|
|
118
|
+
* @see GET /credentials/schema/{type}
|
|
119
|
+
*/
|
|
120
|
+
async getCredentialSchema(type) {
|
|
121
|
+
return this.request('GET', `/credentials/schema/${type}`);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Delete a credential
|
|
125
|
+
* @see DELETE /credentials/{id}
|
|
126
|
+
*/
|
|
127
|
+
async deleteCredential(id) {
|
|
128
|
+
await this.request('DELETE', `/credentials/${id}`);
|
|
129
|
+
}
|
|
130
|
+
// ============================================================================
|
|
131
|
+
// EXECUTIONS
|
|
132
|
+
// ============================================================================
|
|
133
|
+
/**
|
|
134
|
+
* List workflow executions
|
|
135
|
+
* @see GET /executions
|
|
136
|
+
*/
|
|
137
|
+
async listExecutions(params) {
|
|
138
|
+
const query = new URLSearchParams();
|
|
139
|
+
if (params?.workflowId) {
|
|
140
|
+
query.append('workflowId', params.workflowId);
|
|
141
|
+
}
|
|
142
|
+
if (params?.status) {
|
|
143
|
+
query.append('status', params.status);
|
|
144
|
+
}
|
|
145
|
+
if (params?.limit) {
|
|
146
|
+
query.append('limit', params.limit.toString());
|
|
147
|
+
}
|
|
148
|
+
if (params?.cursor) {
|
|
149
|
+
query.append('cursor', params.cursor);
|
|
150
|
+
}
|
|
151
|
+
return this.request('GET', `/executions${query.toString() ? `?${query.toString()}` : ''}`);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get execution details
|
|
155
|
+
* @see GET /executions/{id}
|
|
156
|
+
*/
|
|
157
|
+
async getExecution(id) {
|
|
158
|
+
return this.request('GET', `/executions/${id}`);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Delete an execution
|
|
162
|
+
* @see DELETE /executions/{id}
|
|
163
|
+
*/
|
|
164
|
+
async deleteExecution(id) {
|
|
165
|
+
await this.request('DELETE', `/executions/${id}`);
|
|
166
|
+
}
|
|
167
|
+
// ============================================================================
|
|
168
|
+
// TAGS
|
|
169
|
+
// ============================================================================
|
|
170
|
+
/**
|
|
171
|
+
* List all tags
|
|
172
|
+
* @see GET /tags
|
|
173
|
+
*/
|
|
174
|
+
async listTags() {
|
|
175
|
+
return this.request('GET', '/tags');
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Create a tag
|
|
179
|
+
* @see POST /tags
|
|
180
|
+
*/
|
|
181
|
+
async createTag(name) {
|
|
182
|
+
return this.request('POST', '/tags', { name });
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get or create a tag by name (helper method)
|
|
186
|
+
* Used for per-user workflow organization
|
|
187
|
+
*/
|
|
188
|
+
async getOrCreateTag(name) {
|
|
189
|
+
const { data: tags } = await this.listTags();
|
|
190
|
+
const existing = tags.find((tag) => tag.name.toLowerCase() === name.toLowerCase());
|
|
191
|
+
if (existing) {
|
|
192
|
+
return existing;
|
|
193
|
+
}
|
|
194
|
+
return this.createTag(name);
|
|
195
|
+
}
|
|
196
|
+
// ============================================================================
|
|
197
|
+
// INTERNAL HELPERS
|
|
198
|
+
// ============================================================================
|
|
199
|
+
/**
|
|
200
|
+
* Generic request handler with error handling
|
|
201
|
+
*/
|
|
202
|
+
async request(method, path, body) {
|
|
203
|
+
const url = `${this.baseUrl}/api/v1${path}`;
|
|
204
|
+
const options = {
|
|
205
|
+
method,
|
|
206
|
+
headers: {
|
|
207
|
+
'Content-Type': 'application/json',
|
|
208
|
+
'X-N8N-API-KEY': this.apiKey,
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
if (body) {
|
|
212
|
+
options.body = JSON.stringify(body);
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
const response = await fetch(url, options);
|
|
216
|
+
// Handle empty responses (DELETE, etc.)
|
|
217
|
+
if (response.status === 204) {
|
|
218
|
+
// 204 No Content - return undefined for void operations
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
if (response.status === 200) {
|
|
222
|
+
const text = await response.text();
|
|
223
|
+
// Empty 200 response - return undefined for void operations
|
|
224
|
+
if (!text) {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
// Non-empty response - parse JSON
|
|
228
|
+
return JSON.parse(text);
|
|
229
|
+
}
|
|
230
|
+
// For other status codes, try to parse JSON for error messages
|
|
231
|
+
const data = (await response.json());
|
|
232
|
+
// Handle errors
|
|
233
|
+
if (!response.ok) {
|
|
234
|
+
throw new N8nApiError(data.message || `n8n API error: ${response.statusText}`, response.status, data);
|
|
235
|
+
}
|
|
236
|
+
return data;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
if (error instanceof N8nApiError) {
|
|
240
|
+
throw error;
|
|
241
|
+
}
|
|
242
|
+
// Network or parsing errors
|
|
243
|
+
throw new N8nApiError(`Failed to call n8n API: ${error instanceof Error ? error.message : String(error)}`, undefined, error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/utils/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,WAAW,GACZ,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,MAAM,OAAO,YAAY;IACf,OAAO,CAAS;IAChB,MAAM,CAAS;IAEvB,YAAY,IAAY,EAAE,MAAc;QACtC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CA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AAU,EAAE,EACvD,QAAQ,CAAC,MAAM,EACf,IAAI,CACL,CAAC;YACJ,CAAC;YAED,OAAO,IAAS,CAAC;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;gBACjC,MAAM,KAAK,CAAC;YACd,CAAC;YAED,4BAA4B;YAC5B,MAAM,IAAI,WAAW,CACnB,2BAA2B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACnF,SAAS,EACT,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NodeSearchResult } from '../types/index';
|
|
2
|
+
/**
|
|
3
|
+
* Search n8n node catalog using keyword scoring
|
|
4
|
+
*
|
|
5
|
+
* Scoring algorithm:
|
|
6
|
+
* - Exact name match: 10 points
|
|
7
|
+
* - Partial name match: 5 points
|
|
8
|
+
* - Description match: 2 points
|
|
9
|
+
* - Individual word match: 1 point
|
|
10
|
+
*
|
|
11
|
+
* @param keywords - Array of search keywords (e.g., ["gmail", "send", "email"])
|
|
12
|
+
* @param limit - Maximum number of results to return (default: 15)
|
|
13
|
+
* @returns Array of nodes sorted by relevance score (highest first)
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const results = searchNodes(["gmail", "send"], 10);
|
|
18
|
+
* // Returns Gmail node with high score, plus other email-related nodes
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function searchNodes(keywords: string[], limit?: number): NodeSearchResult[];
|
|
22
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/utils/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAYlE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,KAAK,SAAK,GAAG,gBAAgB,EAAE,CAgE9E"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import defaultNodesData from '../data/defaultNodes.json' assert { type: 'json' };
|
|
2
|
+
/**
|
|
3
|
+
* n8n node catalog with keyword-based search
|
|
4
|
+
* @note Uses embedded catalog (457 nodes as of April 2025)
|
|
5
|
+
* @todo Add dynamic refresh via GET /node-types in v2
|
|
6
|
+
*/
|
|
7
|
+
// Cast imported data to typed array
|
|
8
|
+
const NODE_CATALOG = defaultNodesData;
|
|
9
|
+
/**
|
|
10
|
+
* Search n8n node catalog using keyword scoring
|
|
11
|
+
*
|
|
12
|
+
* Scoring algorithm:
|
|
13
|
+
* - Exact name match: 10 points
|
|
14
|
+
* - Partial name match: 5 points
|
|
15
|
+
* - Description match: 2 points
|
|
16
|
+
* - Individual word match: 1 point
|
|
17
|
+
*
|
|
18
|
+
* @param keywords - Array of search keywords (e.g., ["gmail", "send", "email"])
|
|
19
|
+
* @param limit - Maximum number of results to return (default: 15)
|
|
20
|
+
* @returns Array of nodes sorted by relevance score (highest first)
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const results = searchNodes(["gmail", "send"], 10);
|
|
25
|
+
* // Returns Gmail node with high score, plus other email-related nodes
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function searchNodes(keywords, limit = 15) {
|
|
29
|
+
if (keywords.length === 0) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
// Normalize keywords to lowercase
|
|
33
|
+
const normalizedKeywords = keywords.map((kw) => kw.toLowerCase().trim());
|
|
34
|
+
// Score each node (skip entries with missing name/displayName)
|
|
35
|
+
const scoredNodes = NODE_CATALOG.filter((node) => node.name && node.displayName).map((node) => {
|
|
36
|
+
let score = 0;
|
|
37
|
+
const matchReasons = [];
|
|
38
|
+
const nodeName = node.name.toLowerCase();
|
|
39
|
+
const nodeDisplayName = node.displayName.toLowerCase();
|
|
40
|
+
const nodeDescription = node.description?.toLowerCase() || '';
|
|
41
|
+
for (const keyword of normalizedKeywords) {
|
|
42
|
+
// Exact name match (highest priority)
|
|
43
|
+
if (nodeName === keyword || nodeDisplayName === keyword) {
|
|
44
|
+
score += 10;
|
|
45
|
+
matchReasons.push(`exact match: "${keyword}"`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
// Partial name match
|
|
49
|
+
if (nodeName.includes(keyword) || nodeDisplayName.includes(keyword)) {
|
|
50
|
+
score += 5;
|
|
51
|
+
matchReasons.push(`name contains: "${keyword}"`);
|
|
52
|
+
}
|
|
53
|
+
// Description match
|
|
54
|
+
if (nodeDescription.includes(keyword)) {
|
|
55
|
+
score += 2;
|
|
56
|
+
matchReasons.push(`description contains: "${keyword}"`);
|
|
57
|
+
}
|
|
58
|
+
// Individual word match in description
|
|
59
|
+
const descriptionWords = nodeDescription.split(/\s+/);
|
|
60
|
+
if (descriptionWords.some((word) => word.includes(keyword))) {
|
|
61
|
+
score += 1;
|
|
62
|
+
}
|
|
63
|
+
// Group/category match
|
|
64
|
+
if (node.group.some((group) => group.toLowerCase().includes(keyword))) {
|
|
65
|
+
score += 3;
|
|
66
|
+
matchReasons.push(`category: "${keyword}"`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
node,
|
|
71
|
+
score,
|
|
72
|
+
matchReason: matchReasons.join(', ') || 'no strong match',
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
// Filter out nodes with zero score and sort by score (highest first)
|
|
76
|
+
return scoredNodes
|
|
77
|
+
.filter((result) => result.score > 0)
|
|
78
|
+
.sort((a, b) => b.score - a.score)
|
|
79
|
+
.slice(0, limit);
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=catalog.js.map
|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,CAAC,KAAK,GAAG,CAAC,CAAC;SACpC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;SACjC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type IAgentRuntime, type Memory, type State } from '@elizaos/core';
|
|
2
|
+
/**
|
|
3
|
+
* Build conversation context from recent messages
|
|
4
|
+
*
|
|
5
|
+
* Takes last 5 messages from state and formats them for LLM context.
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildConversationContext(runtime: IAgentRuntime, message: Memory, state: State | undefined): string;
|
|
8
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAE5E;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,KAAK,GAAG,SAAS,GACvB,MAAM,CAaR"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build conversation context from recent messages
|
|
3
|
+
*
|
|
4
|
+
* Takes last 5 messages from state and formats them for LLM context.
|
|
5
|
+
*/
|
|
6
|
+
export function buildConversationContext(runtime, message, state) {
|
|
7
|
+
const recentMessages = state?.data?.recentMessages || [];
|
|
8
|
+
if (recentMessages.length === 0) {
|
|
9
|
+
return message.content.text || '';
|
|
10
|
+
}
|
|
11
|
+
const context = recentMessages
|
|
12
|
+
.slice(-5)
|
|
13
|
+
.map((m) => `${m.entityId === runtime.agentId ? 'Assistant' : 'User'}: ${m.content.text}`)
|
|
14
|
+
.join('\n');
|
|
15
|
+
return `Recent conversation:\n${context}\n\nCurrent request: ${message.content.text || ''}`;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAAsB,EACtB,OAAe,EACf,KAAwB;IAExB,MAAM,cAAc,GAAI,KAAK,EAAE,IAAI,EAAE,cAA2B,IAAI,EAAE,CAAC;IAEvE,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;IACpC,CAAC;IAED,MAAM,OAAO,GAAG,cAAc;SAC3B,KAAK,CAAC,CAAC,CAAC,CAAC;SACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;SACzF,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO,yBAAyB,OAAO,wBAAwB,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;AAC9F,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type IAgentRuntime } from '@elizaos/core';
|
|
2
|
+
import { N8nWorkflow, CredentialResolutionResult, N8nPluginConfig } from '../types/index';
|
|
3
|
+
import { N8nApiClient } from './api';
|
|
4
|
+
/**
|
|
5
|
+
* Resolve and inject credentials into workflow
|
|
6
|
+
* Supports three modes:
|
|
7
|
+
* 1. Cloud mode (with OAuth service): Auto-create credentials via OAuth
|
|
8
|
+
* 2. Local pre-configured mode: Use credential IDs from config
|
|
9
|
+
* 3. Local placeholder mode: Leave placeholders for manual configuration
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveCredentials(workflow: N8nWorkflow, userId: string, runtime: IAgentRuntime, apiClient: N8nApiClient, config: N8nPluginConfig): Promise<CredentialResolutionResult>;
|
|
12
|
+
export declare function getMissingCredentials(workflow: N8nWorkflow): string[];
|
|
13
|
+
//# sourceMappingURL=credentialResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentialResolver.d.ts","sourceRoot":"","sources":["../../src/utils/credentialResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,eAAe,CAAC;AAC3D,OAAO,EACL,WAAW,EAGX,0BAA0B,EAE1B,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,WAAW,EACrB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,YAAY,EACvB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,0BAA0B,CAAC,CA8CrC;AAqKD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,EAAE,CAcrE"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { logger } from '@elizaos/core';
|
|
2
|
+
import { isOAuthService, } from '../types/index';
|
|
3
|
+
/**
|
|
4
|
+
* Resolve and inject credentials into workflow
|
|
5
|
+
* Supports three modes:
|
|
6
|
+
* 1. Cloud mode (with OAuth service): Auto-create credentials via OAuth
|
|
7
|
+
* 2. Local pre-configured mode: Use credential IDs from config
|
|
8
|
+
* 3. Local placeholder mode: Leave placeholders for manual configuration
|
|
9
|
+
*/
|
|
10
|
+
export async function resolveCredentials(workflow, userId, runtime, apiClient, config) {
|
|
11
|
+
const requiredCredTypes = extractRequiredCredentialTypes(workflow);
|
|
12
|
+
if (requiredCredTypes.size === 0) {
|
|
13
|
+
return {
|
|
14
|
+
workflow,
|
|
15
|
+
missingConnections: [],
|
|
16
|
+
injectedCredentials: new Map(),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const oauthService = runtime.getService('oauth');
|
|
20
|
+
const hasOAuthService = oauthService && isOAuthService(oauthService);
|
|
21
|
+
const injectedCredentials = new Map();
|
|
22
|
+
const missingConnections = [];
|
|
23
|
+
for (const credType of requiredCredTypes) {
|
|
24
|
+
let credId = null;
|
|
25
|
+
if (hasOAuthService) {
|
|
26
|
+
credId = await resolveWithOAuth(credType, userId, oauthService, apiClient, missingConnections);
|
|
27
|
+
}
|
|
28
|
+
else if (config.credentials?.[credType]) {
|
|
29
|
+
credId = config.credentials[credType];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
missingConnections.push({ credType });
|
|
33
|
+
}
|
|
34
|
+
if (credId) {
|
|
35
|
+
injectedCredentials.set(credType, credId);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const resolvedWorkflow = injectCredentialIds(workflow, injectedCredentials);
|
|
39
|
+
return {
|
|
40
|
+
workflow: resolvedWorkflow,
|
|
41
|
+
missingConnections,
|
|
42
|
+
injectedCredentials,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function extractRequiredCredentialTypes(workflow) {
|
|
46
|
+
const credTypes = new Set();
|
|
47
|
+
for (const node of workflow.nodes) {
|
|
48
|
+
if (node.credentials) {
|
|
49
|
+
for (const credType of Object.keys(node.credentials)) {
|
|
50
|
+
credTypes.add(credType);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return credTypes;
|
|
55
|
+
}
|
|
56
|
+
function getProviderName(credType) {
|
|
57
|
+
return credType
|
|
58
|
+
.replace(/OAuth2Api$/, '')
|
|
59
|
+
.replace(/Api$/, '')
|
|
60
|
+
.replace(/TokenApi$/, '')
|
|
61
|
+
.toLowerCase();
|
|
62
|
+
}
|
|
63
|
+
async function resolveWithOAuth(credType, userId, oauthService, apiClient, missingConnections) {
|
|
64
|
+
const existingCredId = await oauthService.getN8nCredId(userId, credType);
|
|
65
|
+
if (existingCredId) {
|
|
66
|
+
return existingCredId;
|
|
67
|
+
}
|
|
68
|
+
const hasConnection = await oauthService.hasConnection(userId, credType);
|
|
69
|
+
if (!hasConnection) {
|
|
70
|
+
const oauthUrl = await oauthService.getAuthUrl(userId, getProviderName(credType), []);
|
|
71
|
+
missingConnections.push({
|
|
72
|
+
credType,
|
|
73
|
+
oauthUrl,
|
|
74
|
+
});
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const tokens = await oauthService.getTokens(userId, credType);
|
|
79
|
+
if (!tokens) {
|
|
80
|
+
throw new Error(`Failed to get tokens for ${credType}`);
|
|
81
|
+
}
|
|
82
|
+
const schema = await apiClient.getCredentialSchema(credType);
|
|
83
|
+
const appConfig = await oauthService.getOAuthAppConfig?.(getProviderName(credType));
|
|
84
|
+
const credData = buildCredentialData(schema, tokens, appConfig);
|
|
85
|
+
const credential = await apiClient.createCredential({
|
|
86
|
+
name: `${credType} - ${userId}`,
|
|
87
|
+
type: credType,
|
|
88
|
+
data: credData,
|
|
89
|
+
});
|
|
90
|
+
await oauthService.setN8nCredId(userId, credType, credential.id);
|
|
91
|
+
return credential.id;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
logger.error({ src: 'plugin:n8n-workflow:utils:credentials' }, `Failed to create credential for ${credType}: ${error instanceof Error ? error.message : String(error)}`);
|
|
95
|
+
missingConnections.push({ credType });
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function buildCredentialData(schema, tokens, appConfig) {
|
|
100
|
+
const data = {};
|
|
101
|
+
if (schema.properties.oauthTokenData) {
|
|
102
|
+
data.oauthTokenData = {
|
|
103
|
+
access_token: tokens.accessToken,
|
|
104
|
+
refresh_token: tokens.refreshToken,
|
|
105
|
+
token_type: tokens.tokenType || 'Bearer',
|
|
106
|
+
expires_in: tokens.expiresIn || 3600,
|
|
107
|
+
scope: appConfig?.scope || tokens.scope,
|
|
108
|
+
};
|
|
109
|
+
if (appConfig) {
|
|
110
|
+
data.clientId = appConfig.clientId;
|
|
111
|
+
data.clientSecret = appConfig.clientSecret;
|
|
112
|
+
if (appConfig.scope) {
|
|
113
|
+
data.scope = appConfig.scope;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return data;
|
|
117
|
+
}
|
|
118
|
+
if (schema.properties.apiKey) {
|
|
119
|
+
data.apiKey = tokens.apiKey || tokens.accessToken;
|
|
120
|
+
}
|
|
121
|
+
if (schema.properties.token) {
|
|
122
|
+
data.token = tokens.accessToken;
|
|
123
|
+
}
|
|
124
|
+
if (schema.properties.domain && tokens.domain) {
|
|
125
|
+
data.domain = tokens.domain;
|
|
126
|
+
}
|
|
127
|
+
for (const [field, fieldSchema] of Object.entries(schema.properties)) {
|
|
128
|
+
if (data[field] === undefined &&
|
|
129
|
+
typeof fieldSchema === 'object' &&
|
|
130
|
+
fieldSchema !== null &&
|
|
131
|
+
'default' in fieldSchema &&
|
|
132
|
+
fieldSchema.default !== undefined) {
|
|
133
|
+
data[field] = fieldSchema.default;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return data;
|
|
137
|
+
}
|
|
138
|
+
function injectCredentialIds(workflow, credentialMap) {
|
|
139
|
+
const injected = { ...workflow };
|
|
140
|
+
injected.nodes = workflow.nodes.map((node) => {
|
|
141
|
+
if (!node.credentials) {
|
|
142
|
+
return node;
|
|
143
|
+
}
|
|
144
|
+
const updatedCredentials = {};
|
|
145
|
+
for (const [credType, credRef] of Object.entries(node.credentials)) {
|
|
146
|
+
const credId = credentialMap.get(credType);
|
|
147
|
+
if (credId) {
|
|
148
|
+
updatedCredentials[credType] = {
|
|
149
|
+
id: credId,
|
|
150
|
+
name: credRef.name,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
updatedCredentials[credType] = credRef;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
...node,
|
|
159
|
+
credentials: updatedCredentials,
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
return injected;
|
|
163
|
+
}
|
|
164
|
+
export function getMissingCredentials(workflow) {
|
|
165
|
+
const missing = new Set();
|
|
166
|
+
for (const node of workflow.nodes || []) {
|
|
167
|
+
if (node.credentials) {
|
|
168
|
+
for (const [credType, credRef] of Object.entries(node.credentials)) {
|
|
169
|
+
if (typeof credRef === 'object' && 'id' in credRef && credRef.id === 'PLACEHOLDER') {
|
|
170
|
+
missing.add(credType);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return Array.from(missing);
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=credentialResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentialResolver.js","sourceRoot":"","sources":["../../src/utils/credentialResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,MAAM,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAGL,cAAc,GAMf,MAAM,gBAAgB,CAAC;AAGxB;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAqB,EACrB,MAAc,EACd,OAAsB,EACtB,SAAuB,EACvB,MAAuB;IAEvB,MAAM,iBAAiB,GAAG,8BAA8B,CAAC,QAAQ,CAAC,CAAC;IAEnE,IAAI,iBAAiB,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO;YACL,QAAQ;YACR,kBAAkB,EAAE,EAAE;YACtB,mBAAmB,EAAE,IAAI,GAAG,EAAE;SAC/B,CAAC;IACJ,CAAC;IAED,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACjD,MAAM,eAAe,GAAG,YAAY,IAA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KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type IAgentRuntime } from '@elizaos/core';
|
|
2
|
+
import { N8nWorkflow, WorkflowMatchResult, NodeDefinition } from '../types/index';
|
|
3
|
+
/**
|
|
4
|
+
* Extracts keywords from user prompt using LLM
|
|
5
|
+
* Adapted from n8n-intelligence to use ElizaOS runtime
|
|
6
|
+
*
|
|
7
|
+
* @param runtime - ElizaOS runtime for model access
|
|
8
|
+
* @param userPrompt - User's workflow description
|
|
9
|
+
* @returns Array of 1-5 keywords for node search
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const keywords = await extractKeywords(runtime, "Send Stripe summaries via Gmail");
|
|
14
|
+
* // Returns: ["stripe", "gmail", "send", "email"]
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractKeywords(runtime: IAgentRuntime, userPrompt: string): Promise<string[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Match user request to available workflows using LLM semantic matching with conversation context
|
|
20
|
+
*
|
|
21
|
+
* @param runtime - Agent runtime with LLM access
|
|
22
|
+
* @param userRequest - User's current message (for context-aware matching, include conversation history)
|
|
23
|
+
* @param workflows - List of available workflows
|
|
24
|
+
* @returns Match result with workflow ID and confidence
|
|
25
|
+
*/
|
|
26
|
+
export declare function matchWorkflow(runtime: IAgentRuntime, userRequest: string, workflows: N8nWorkflow[]): Promise<WorkflowMatchResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Generate n8n workflow from natural language using LLM
|
|
29
|
+
* Adapted from n8n-intelligence to use ElizaOS runtime
|
|
30
|
+
*
|
|
31
|
+
* @param runtime - ElizaOS runtime for model access
|
|
32
|
+
* @param userPrompt - User's workflow description
|
|
33
|
+
* @param relevantNodes - Nodes found by keyword search
|
|
34
|
+
* @returns Generated workflow JSON
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const workflow = await generateWorkflow(
|
|
39
|
+
* runtime,
|
|
40
|
+
* "Send me Stripe summaries via Gmail",
|
|
41
|
+
* [gmailNode, stripeNode, scheduleNode]
|
|
42
|
+
* );
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function generateWorkflow(runtime: IAgentRuntime, userPrompt: string, relevantNodes: NodeDefinition[]): Promise<N8nWorkflow>;
|
|
46
|
+
//# sourceMappingURL=generation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generation.d.ts","sourceRoot":"","sources":["../../src/utils/generation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAqB,MAAM,eAAe,CAAC;AACtE,OAAO,EAEL,WAAW,EACX,mBAAmB,EACnB,cAAc,EACf,MAAM,gBAAgB,CAAC;AAQxB;;;;;;;;;;;;;GAaG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CAqBnB;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,WAAW,EAAE,GACvB,OAAO,CAAC,mBAAmB,CAAC,CAmD9B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,cAAc,EAAE,GAC9B,OAAO,CAAC,WAAW,CAAC,CAkDtB"}
|