n8n-nodes-browser-smart-automation 0.1.2 → 0.1.4
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/dist/McpClientTool/McpClientTool.node.js +2 -13
- package/dist/McpClientTool/McpClientTool.node.js.map +1 -1
- package/dist/McpClientTool/utils.js +1 -1
- package/dist/McpClientTool/utils.js.map +1 -1
- package/dist/McpTrigger/McpTrigger.node.js +1 -1
- package/dist/McpTrigger/McpTrigger.node.js.map +1 -1
- package/dist/shared/N8nBinaryLoader.js +203 -0
- package/dist/shared/N8nBinaryLoader.js.map +1 -0
- package/dist/shared/N8nJsonLoader.js +89 -0
- package/dist/shared/N8nJsonLoader.js.map +1 -0
- package/dist/shared/N8nTool.js +106 -0
- package/dist/shared/N8nTool.js.map +1 -0
- package/dist/shared/embeddingInputValidation.js +55 -0
- package/dist/shared/embeddingInputValidation.js.map +1 -0
- package/dist/shared/helpers.js +220 -13
- package/dist/shared/helpers.js.map +1 -1
- package/dist/shared/httpProxyAgent.js +40 -2
- package/dist/shared/httpProxyAgent.js.map +1 -1
- package/dist/shared/logWrapper.js +347 -2
- package/dist/shared/logWrapper.js.map +1 -1
- package/dist/shared/schemaParsing.js +47 -4
- package/dist/shared/schemaParsing.js.map +1 -1
- package/dist/shared/sharedFields.js +142 -7
- package/dist/shared/sharedFields.js.map +1 -1
- package/dist/shared/typesN8nTool.js +17 -0
- package/dist/shared/typesN8nTool.js.map +1 -0
- package/dist/shared/utils.js +1 -1
- package/dist/shared/utils.js.map +1 -1
- package/package.json +23 -7
- package/jest.config.js +0 -24
- package/nodes/McpClient/McpClient.node.ts +0 -327
- package/nodes/McpClient/__test__/McpClient.node.test.ts +0 -221
- package/nodes/McpClient/__test__/utils.test.ts +0 -302
- package/nodes/McpClient/listSearch.ts +0 -48
- package/nodes/McpClient/resourceMapping.ts +0 -48
- package/nodes/McpClient/utils.ts +0 -281
- package/nodes/McpClientTool/McpClientTool.node.ts +0 -468
- package/nodes/McpClientTool/__test__/McpClientTool.node.test.ts +0 -730
- package/nodes/McpClientTool/loadOptions.ts +0 -45
- package/nodes/McpClientTool/types.ts +0 -1
- package/nodes/McpClientTool/utils.ts +0 -116
- package/nodes/McpTrigger/FlushingTransport.ts +0 -61
- package/nodes/McpTrigger/McpServer.ts +0 -317
- package/nodes/McpTrigger/McpTrigger.node.ts +0 -204
- package/nodes/McpTrigger/__test__/FlushingTransport.test.ts +0 -102
- package/nodes/McpTrigger/__test__/McpServer.test.ts +0 -532
- package/nodes/McpTrigger/__test__/McpTrigger.node.test.ts +0 -171
- package/nodes/shared/__test__/utils.test.ts +0 -318
- package/nodes/shared/descriptions.ts +0 -65
- package/nodes/shared/helpers.ts +0 -31
- package/nodes/shared/httpProxyAgent.ts +0 -11
- package/nodes/shared/logWrapper.ts +0 -13
- package/nodes/shared/schemaParsing.ts +0 -9
- package/nodes/shared/sharedFields.ts +0 -20
- package/nodes/shared/types.ts +0 -12
- package/nodes/shared/utils.ts +0 -296
- package/officail/package.json +0 -255
- package/tsconfig.json +0 -32
- package/tsup.config.ts +0 -16
|
@@ -18,14 +18,359 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var logWrapper_exports = {};
|
|
20
20
|
__export(logWrapper_exports, {
|
|
21
|
+
callMethodAsync: () => callMethodAsync,
|
|
22
|
+
callMethodSync: () => callMethodSync,
|
|
21
23
|
logWrapper: () => logWrapper
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(logWrapper_exports);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
var import_embeddings = require("@langchain/core/embeddings");
|
|
27
|
+
var import_retrievers = require("@langchain/core/retrievers");
|
|
28
|
+
var import_document_compressors = require("@langchain/core/retrievers/document_compressors");
|
|
29
|
+
var import_vectorstores = require("@langchain/core/vectorstores");
|
|
30
|
+
var import_textsplitters = require("@langchain/textsplitters");
|
|
31
|
+
var import_openai = require("@langchain/openai");
|
|
32
|
+
var import_n8n_workflow = require("n8n-workflow");
|
|
33
|
+
var import_embeddingInputValidation = require("./embeddingInputValidation");
|
|
34
|
+
var import_helpers = require("./helpers");
|
|
35
|
+
var import_N8nBinaryLoader = require("./N8nBinaryLoader");
|
|
36
|
+
var import_N8nJsonLoader = require("./N8nJsonLoader");
|
|
37
|
+
async function callMethodAsync(parameters) {
|
|
38
|
+
try {
|
|
39
|
+
return await parameters.method.call(this, ...parameters.arguments);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
const connectedNode = parameters.executeFunctions.getNode();
|
|
42
|
+
const error = new import_n8n_workflow.NodeOperationError(connectedNode, e, {
|
|
43
|
+
functionality: "configuration-node"
|
|
44
|
+
});
|
|
45
|
+
const metadata = (0, import_n8n_workflow.parseErrorMetadata)(error);
|
|
46
|
+
parameters.executeFunctions.addOutputData(
|
|
47
|
+
parameters.connectionType,
|
|
48
|
+
parameters.currentNodeRunIndex,
|
|
49
|
+
error,
|
|
50
|
+
metadata
|
|
51
|
+
);
|
|
52
|
+
if (error.message) {
|
|
53
|
+
if (!error.description) {
|
|
54
|
+
error.description = error.message;
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
throw new import_n8n_workflow.NodeOperationError(
|
|
59
|
+
connectedNode,
|
|
60
|
+
`Error on node "${connectedNode.name}" which is connected via input "${parameters.connectionType}"`,
|
|
61
|
+
{ functionality: "configuration-node" }
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function callMethodSync(parameters) {
|
|
66
|
+
try {
|
|
67
|
+
return parameters.method.call(this, ...parameters.arguments);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
const connectedNode = parameters.executeFunctions.getNode();
|
|
70
|
+
const error = new import_n8n_workflow.NodeOperationError(connectedNode, e);
|
|
71
|
+
parameters.executeFunctions.addOutputData(
|
|
72
|
+
parameters.connectionType,
|
|
73
|
+
parameters.currentNodeRunIndex,
|
|
74
|
+
error
|
|
75
|
+
);
|
|
76
|
+
throw new import_n8n_workflow.NodeOperationError(
|
|
77
|
+
connectedNode,
|
|
78
|
+
`Error on node "${connectedNode.name}" which is connected via input "${parameters.connectionType}"`,
|
|
79
|
+
{ functionality: "configuration-node" }
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function logWrapper(originalInstance, executeFunctions) {
|
|
84
|
+
return new Proxy(originalInstance, {
|
|
85
|
+
get: (target, prop) => {
|
|
86
|
+
let connectionType;
|
|
87
|
+
if ((0, import_helpers.isBaseChatMemory)(originalInstance)) {
|
|
88
|
+
if (prop === "loadMemoryVariables" && "loadMemoryVariables" in target) {
|
|
89
|
+
return async (values) => {
|
|
90
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiMemory;
|
|
91
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
92
|
+
[{ json: { action: "loadMemoryVariables", values } }]
|
|
93
|
+
]);
|
|
94
|
+
const response = await callMethodAsync.call(target, {
|
|
95
|
+
executeFunctions,
|
|
96
|
+
connectionType,
|
|
97
|
+
currentNodeRunIndex: index,
|
|
98
|
+
method: target[prop],
|
|
99
|
+
arguments: [values]
|
|
100
|
+
});
|
|
101
|
+
const chatHistory = response?.chat_history ?? response;
|
|
102
|
+
executeFunctions.addOutputData(connectionType, index, [
|
|
103
|
+
[{ json: { action: "loadMemoryVariables", chatHistory } }]
|
|
104
|
+
]);
|
|
105
|
+
return response;
|
|
106
|
+
};
|
|
107
|
+
} else if (prop === "saveContext" && "saveContext" in target) {
|
|
108
|
+
return async (input, output) => {
|
|
109
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiMemory;
|
|
110
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
111
|
+
[{ json: { action: "saveContext", input, output } }]
|
|
112
|
+
]);
|
|
113
|
+
const response = await callMethodAsync.call(target, {
|
|
114
|
+
executeFunctions,
|
|
115
|
+
connectionType,
|
|
116
|
+
currentNodeRunIndex: index,
|
|
117
|
+
method: target[prop],
|
|
118
|
+
arguments: [input, output]
|
|
119
|
+
});
|
|
120
|
+
const chatHistory = await target.chatHistory.getMessages();
|
|
121
|
+
executeFunctions.addOutputData(connectionType, index, [
|
|
122
|
+
[{ json: { action: "saveContext", chatHistory } }]
|
|
123
|
+
]);
|
|
124
|
+
return response;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if ((0, import_helpers.isBaseChatMessageHistory)(originalInstance)) {
|
|
129
|
+
if (prop === "getMessages" && "getMessages" in target) {
|
|
130
|
+
return async () => {
|
|
131
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiMemory;
|
|
132
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
133
|
+
[{ json: { action: "getMessages" } }]
|
|
134
|
+
]);
|
|
135
|
+
const response = await callMethodAsync.call(target, {
|
|
136
|
+
executeFunctions,
|
|
137
|
+
connectionType,
|
|
138
|
+
currentNodeRunIndex: index,
|
|
139
|
+
method: target[prop],
|
|
140
|
+
arguments: []
|
|
141
|
+
});
|
|
142
|
+
const payload = { action: "getMessages", response };
|
|
143
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: payload }]]);
|
|
144
|
+
(0, import_helpers.logAiEvent)(executeFunctions, "ai-messages-retrieved-from-memory", { response });
|
|
145
|
+
return response;
|
|
146
|
+
};
|
|
147
|
+
} else if (prop === "addMessage" && "addMessage" in target) {
|
|
148
|
+
return async (message) => {
|
|
149
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiMemory;
|
|
150
|
+
const payload = { action: "addMessage", message };
|
|
151
|
+
const { index } = executeFunctions.addInputData(connectionType, [[{ json: payload }]]);
|
|
152
|
+
await callMethodAsync.call(target, {
|
|
153
|
+
executeFunctions,
|
|
154
|
+
connectionType,
|
|
155
|
+
currentNodeRunIndex: index,
|
|
156
|
+
method: target[prop],
|
|
157
|
+
arguments: [message]
|
|
158
|
+
});
|
|
159
|
+
(0, import_helpers.logAiEvent)(executeFunctions, "ai-message-added-to-memory", { message });
|
|
160
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: payload }]]);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (originalInstance instanceof import_retrievers.BaseRetriever) {
|
|
165
|
+
if (prop === "getRelevantDocuments" && "getRelevantDocuments" in target) {
|
|
166
|
+
return async (query, config) => {
|
|
167
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiRetriever;
|
|
168
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
169
|
+
[{ json: { query, config } }]
|
|
170
|
+
]);
|
|
171
|
+
const response = await callMethodAsync.call(target, {
|
|
172
|
+
executeFunctions,
|
|
173
|
+
connectionType,
|
|
174
|
+
currentNodeRunIndex: index,
|
|
175
|
+
method: target[prop],
|
|
176
|
+
arguments: [query, config]
|
|
177
|
+
});
|
|
178
|
+
const executionId = response[0]?.metadata?.executionId;
|
|
179
|
+
const workflowId = response[0]?.metadata?.workflowId;
|
|
180
|
+
const metadata = {};
|
|
181
|
+
if (executionId && workflowId) {
|
|
182
|
+
metadata.subExecution = {
|
|
183
|
+
executionId,
|
|
184
|
+
workflowId
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
(0, import_helpers.logAiEvent)(executeFunctions, "ai-documents-retrieved", { query });
|
|
188
|
+
executeFunctions.addOutputData(
|
|
189
|
+
connectionType,
|
|
190
|
+
index,
|
|
191
|
+
[[{ json: { response } }]],
|
|
192
|
+
metadata
|
|
193
|
+
);
|
|
194
|
+
return response;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (originalInstance instanceof import_embeddings.Embeddings || originalInstance instanceof import_openai.OpenAIEmbeddings || originalInstance instanceof import_openai.AzureOpenAIEmbeddings) {
|
|
199
|
+
if (prop === "embedDocuments" && "embedDocuments" in target) {
|
|
200
|
+
return async (documents) => {
|
|
201
|
+
const validatedDocuments = (0, import_embeddingInputValidation.validateEmbedDocumentsInput)(
|
|
202
|
+
documents,
|
|
203
|
+
executeFunctions.getNode()
|
|
204
|
+
);
|
|
205
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiEmbedding;
|
|
206
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
207
|
+
[{ json: { documents: validatedDocuments } }]
|
|
208
|
+
]);
|
|
209
|
+
const response = await callMethodAsync.call(target, {
|
|
210
|
+
executeFunctions,
|
|
211
|
+
connectionType,
|
|
212
|
+
currentNodeRunIndex: index,
|
|
213
|
+
method: target[prop],
|
|
214
|
+
arguments: [validatedDocuments]
|
|
215
|
+
});
|
|
216
|
+
(0, import_helpers.logAiEvent)(executeFunctions, "ai-document-embedded");
|
|
217
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
218
|
+
return response;
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
if (prop === "embedQuery" && "embedQuery" in target) {
|
|
222
|
+
return async (query) => {
|
|
223
|
+
const validatedQuery = (0, import_embeddingInputValidation.validateEmbedQueryInput)(query, executeFunctions.getNode());
|
|
224
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiEmbedding;
|
|
225
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
226
|
+
[{ json: { query: validatedQuery } }]
|
|
227
|
+
]);
|
|
228
|
+
const response = await callMethodAsync.call(target, {
|
|
229
|
+
executeFunctions,
|
|
230
|
+
connectionType,
|
|
231
|
+
currentNodeRunIndex: index,
|
|
232
|
+
method: target[prop],
|
|
233
|
+
arguments: [validatedQuery]
|
|
234
|
+
});
|
|
235
|
+
(0, import_helpers.logAiEvent)(executeFunctions, "ai-query-embedded");
|
|
236
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
237
|
+
return response;
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (originalInstance instanceof import_document_compressors.BaseDocumentCompressor) {
|
|
242
|
+
if (prop === "compressDocuments" && "compressDocuments" in target) {
|
|
243
|
+
return async (documents, query) => {
|
|
244
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiReranker;
|
|
245
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
246
|
+
[{ json: { query, documents } }]
|
|
247
|
+
]);
|
|
248
|
+
const response = await callMethodAsync.call(target, {
|
|
249
|
+
executeFunctions,
|
|
250
|
+
connectionType,
|
|
251
|
+
currentNodeRunIndex: index,
|
|
252
|
+
method: target[prop],
|
|
253
|
+
// compressDocuments mutates the original object
|
|
254
|
+
// messing up the input data logging
|
|
255
|
+
arguments: [(0, import_n8n_workflow.deepCopy)(documents), query]
|
|
256
|
+
});
|
|
257
|
+
(0, import_helpers.logAiEvent)(executeFunctions, "ai-document-reranked", { query });
|
|
258
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
259
|
+
return response;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (originalInstance instanceof import_N8nJsonLoader.N8nJsonLoader || originalInstance instanceof import_N8nBinaryLoader.N8nBinaryLoader) {
|
|
264
|
+
if (prop === "processAll" && "processAll" in target) {
|
|
265
|
+
return async (items) => {
|
|
266
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiDocument;
|
|
267
|
+
const { index } = executeFunctions.addInputData(connectionType, [items]);
|
|
268
|
+
const response = await callMethodAsync.call(target, {
|
|
269
|
+
executeFunctions,
|
|
270
|
+
connectionType,
|
|
271
|
+
currentNodeRunIndex: index,
|
|
272
|
+
method: target[prop],
|
|
273
|
+
arguments: [items]
|
|
274
|
+
});
|
|
275
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
276
|
+
return response;
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
if (prop === "processItem" && "processItem" in target) {
|
|
280
|
+
return async (item, itemIndex) => {
|
|
281
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiDocument;
|
|
282
|
+
const { index } = executeFunctions.addInputData(connectionType, [[item]]);
|
|
283
|
+
const response = await callMethodAsync.call(target, {
|
|
284
|
+
executeFunctions,
|
|
285
|
+
connectionType,
|
|
286
|
+
currentNodeRunIndex: index,
|
|
287
|
+
method: target[prop],
|
|
288
|
+
arguments: [item, itemIndex]
|
|
289
|
+
});
|
|
290
|
+
(0, import_helpers.logAiEvent)(executeFunctions, "ai-document-processed");
|
|
291
|
+
executeFunctions.addOutputData(connectionType, index, [
|
|
292
|
+
[{ json: { response }, pairedItem: { item: itemIndex } }]
|
|
293
|
+
]);
|
|
294
|
+
return response;
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (originalInstance instanceof import_textsplitters.TextSplitter) {
|
|
299
|
+
if (prop === "splitText" && "splitText" in target) {
|
|
300
|
+
return async (text) => {
|
|
301
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiTextSplitter;
|
|
302
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
303
|
+
[{ json: { textSplitter: text } }]
|
|
304
|
+
]);
|
|
305
|
+
const response = await callMethodAsync.call(target, {
|
|
306
|
+
executeFunctions,
|
|
307
|
+
connectionType,
|
|
308
|
+
currentNodeRunIndex: index,
|
|
309
|
+
method: target[prop],
|
|
310
|
+
arguments: [text]
|
|
311
|
+
});
|
|
312
|
+
(0, import_helpers.logAiEvent)(executeFunctions, "ai-text-split");
|
|
313
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
314
|
+
return response;
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if ((0, import_helpers.isToolsInstance)(originalInstance)) {
|
|
319
|
+
if (prop === "_call" && "_call" in target) {
|
|
320
|
+
return async (query) => {
|
|
321
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiTool;
|
|
322
|
+
const inputData = { query };
|
|
323
|
+
if (target.metadata?.isFromToolkit) {
|
|
324
|
+
inputData.tool = {
|
|
325
|
+
name: target.name,
|
|
326
|
+
description: target.description
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
330
|
+
[{ json: inputData }]
|
|
331
|
+
]);
|
|
332
|
+
const response = await callMethodAsync.call(target, {
|
|
333
|
+
executeFunctions,
|
|
334
|
+
connectionType,
|
|
335
|
+
currentNodeRunIndex: index,
|
|
336
|
+
method: target[prop],
|
|
337
|
+
arguments: [query]
|
|
338
|
+
});
|
|
339
|
+
(0, import_helpers.logAiEvent)(executeFunctions, "ai-tool-called", { ...inputData, response });
|
|
340
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
341
|
+
if (typeof response === "string") return response;
|
|
342
|
+
return JSON.stringify(response);
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (originalInstance instanceof import_vectorstores.VectorStore) {
|
|
347
|
+
if (prop === "similaritySearch" && "similaritySearch" in target) {
|
|
348
|
+
return async (query, k, filter, _callbacks) => {
|
|
349
|
+
connectionType = import_n8n_workflow.NodeConnectionTypes.AiVectorStore;
|
|
350
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
351
|
+
[{ json: { query, k, filter } }]
|
|
352
|
+
]);
|
|
353
|
+
const response = await callMethodAsync.call(target, {
|
|
354
|
+
executeFunctions,
|
|
355
|
+
connectionType,
|
|
356
|
+
currentNodeRunIndex: index,
|
|
357
|
+
method: target[prop],
|
|
358
|
+
arguments: [query, k, filter, _callbacks]
|
|
359
|
+
});
|
|
360
|
+
(0, import_helpers.logAiEvent)(executeFunctions, "ai-vector-store-searched", { query });
|
|
361
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
362
|
+
return response;
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return target[prop];
|
|
367
|
+
}
|
|
368
|
+
});
|
|
26
369
|
}
|
|
27
370
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
371
|
0 && (module.exports = {
|
|
372
|
+
callMethodAsync,
|
|
373
|
+
callMethodSync,
|
|
29
374
|
logWrapper
|
|
30
375
|
});
|
|
31
376
|
//# sourceMappingURL=logWrapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../nodes/shared/logWrapper.ts"],"sourcesContent":["import type { DynamicTool } from '@langchain/core/tools';\nimport type { ISupplyDataFunctions } from 'n8n-workflow';\n\n/**\n * Wraps a LangChain tool with logging functionality for n8n\n */\nexport function logWrapper(\n\ttool: DynamicTool,\n\tcontext: ISupplyDataFunctions,\n): DynamicTool {\n\t// Simply return the tool as-is since we don't have full n8n logging infrastructure\n\treturn tool;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,SAAS,WACf,MACA,SACc;AAEd,SAAO;AACR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../nodes/shared/logWrapper.ts"],"sourcesContent":["import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';\nimport type { BaseCallbackConfig, Callbacks } from '@langchain/core/callbacks/manager';\nimport type { BaseChatMessageHistory } from '@langchain/core/chat_history';\nimport type { Document } from '@langchain/core/documents';\nimport { Embeddings } from '@langchain/core/embeddings';\nimport type { InputValues, MemoryVariables, OutputValues } from '@langchain/core/memory';\nimport type { BaseMessage } from '@langchain/core/messages';\nimport { BaseRetriever } from '@langchain/core/retrievers';\nimport { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';\nimport type { StructuredTool, Tool } from '@langchain/core/tools';\nimport { VectorStore } from '@langchain/core/vectorstores';\nimport { TextSplitter } from '@langchain/textsplitters';\nimport type { BaseDocumentLoader } from '@langchain/classic/dist/document_loaders/base';\nimport { OpenAIEmbeddings, AzureOpenAIEmbeddings } from '@langchain/openai';\nimport type {\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tISupplyDataFunctions,\n\tITaskMetadata,\n\tNodeConnectionType,\n} from 'n8n-workflow';\nimport {\n\tNodeOperationError,\n\tNodeConnectionTypes,\n\tparseErrorMetadata,\n\tdeepCopy,\n} from 'n8n-workflow';\n\nimport {\n\tvalidateEmbedQueryInput,\n\tvalidateEmbedDocumentsInput,\n} from './embeddingInputValidation';\nimport { logAiEvent, isToolsInstance, isBaseChatMemory, isBaseChatMessageHistory } from './helpers';\nimport { N8nBinaryLoader } from './N8nBinaryLoader';\nimport { N8nJsonLoader } from './N8nJsonLoader';\n\nexport async function callMethodAsync<T>(\n\tthis: T,\n\tparameters: {\n\t\texecuteFunctions: IExecuteFunctions | ISupplyDataFunctions;\n\t\tconnectionType: NodeConnectionType;\n\t\tcurrentNodeRunIndex: number;\n\t\tmethod: (...args: any[]) => Promise<unknown>;\n\t\targuments: unknown[];\n\t},\n): Promise<unknown> {\n\ttry {\n\t\treturn await parameters.method.call(this, ...parameters.arguments);\n\t} catch (e) {\n\t\tconst connectedNode = parameters.executeFunctions.getNode();\n\n\t\tconst error = new NodeOperationError(connectedNode, e, {\n\t\t\tfunctionality: 'configuration-node',\n\t\t});\n\n\t\tconst metadata = parseErrorMetadata(error);\n\t\tparameters.executeFunctions.addOutputData(\n\t\t\tparameters.connectionType,\n\t\t\tparameters.currentNodeRunIndex,\n\t\t\terror,\n\t\t\tmetadata,\n\t\t);\n\n\t\tif (error.message) {\n\t\t\tif (!error.description) {\n\t\t\t\terror.description = error.message;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\n\t\tthrow new NodeOperationError(\n\t\t\tconnectedNode,\n\t\t\t`Error on node \"${connectedNode.name}\" which is connected via input \"${parameters.connectionType}\"`,\n\t\t\t{ functionality: 'configuration-node' },\n\t\t);\n\t}\n}\n\nexport function callMethodSync<T>(\n\tthis: T,\n\tparameters: {\n\t\texecuteFunctions: IExecuteFunctions;\n\t\tconnectionType: NodeConnectionType;\n\t\tcurrentNodeRunIndex: number;\n\t\tmethod: (...args: any[]) => T;\n\t\targuments: unknown[];\n\t},\n): unknown {\n\ttry {\n\t\treturn parameters.method.call(this, ...parameters.arguments);\n\t} catch (e) {\n\t\tconst connectedNode = parameters.executeFunctions.getNode();\n\t\tconst error = new NodeOperationError(connectedNode, e);\n\t\tparameters.executeFunctions.addOutputData(\n\t\t\tparameters.connectionType,\n\t\t\tparameters.currentNodeRunIndex,\n\t\t\terror,\n\t\t);\n\n\t\tthrow new NodeOperationError(\n\t\t\tconnectedNode,\n\t\t\t`Error on node \"${connectedNode.name}\" which is connected via input \"${parameters.connectionType}\"`,\n\t\t\t{ functionality: 'configuration-node' },\n\t\t);\n\t}\n}\n\nexport function logWrapper<\n\tT extends\n\t\t| Tool\n\t\t| StructuredTool\n\t\t| BaseChatMemory\n\t\t| BaseChatMessageHistory\n\t\t| BaseRetriever\n\t\t| BaseDocumentCompressor\n\t\t| Embeddings\n\t\t| OpenAIEmbeddings\n\t\t| AzureOpenAIEmbeddings\n\t\t| Document[]\n\t\t| Document\n\t\t| BaseDocumentLoader\n\t\t| TextSplitter\n\t\t| VectorStore\n\t\t| N8nBinaryLoader\n\t\t| N8nJsonLoader,\n>(originalInstance: T, executeFunctions: IExecuteFunctions | ISupplyDataFunctions): T {\n\treturn new Proxy(originalInstance, {\n\t\tget: (target, prop) => {\n\t\t\tlet connectionType: NodeConnectionType | undefined;\n\t\t\t// ========== BaseChatMemory ==========\n\t\t\tif (isBaseChatMemory(originalInstance)) {\n\t\t\t\tif (prop === 'loadMemoryVariables' && 'loadMemoryVariables' in target) {\n\t\t\t\t\treturn async (values: InputValues): Promise<MemoryVariables> => {\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiMemory;\n\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [\n\t\t\t\t\t\t\t[{ json: { action: 'loadMemoryVariables', values } }],\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [values],\n\t\t\t\t\t\t})) as MemoryVariables;\n\n\t\t\t\t\t\tconst chatHistory = (response?.chat_history as BaseMessage[]) ?? response;\n\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [\n\t\t\t\t\t\t\t[{ json: { action: 'loadMemoryVariables', chatHistory } }],\n\t\t\t\t\t\t]);\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t};\n\t\t\t\t} else if (prop === 'saveContext' && 'saveContext' in target) {\n\t\t\t\t\treturn async (input: InputValues, output: OutputValues): Promise<MemoryVariables> => {\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiMemory;\n\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [\n\t\t\t\t\t\t\t[{ json: { action: 'saveContext', input, output } }],\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [input, output],\n\t\t\t\t\t\t})) as MemoryVariables;\n\n\t\t\t\t\t\tconst chatHistory = await target.chatHistory.getMessages();\n\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [\n\t\t\t\t\t\t\t[{ json: { action: 'saveContext', chatHistory } }],\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ========== BaseChatMessageHistory ==========\n\t\t\tif (isBaseChatMessageHistory(originalInstance)) {\n\t\t\t\tif (prop === 'getMessages' && 'getMessages' in target) {\n\t\t\t\t\treturn async (): Promise<BaseMessage[]> => {\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiMemory;\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [\n\t\t\t\t\t\t\t[{ json: { action: 'getMessages' } }],\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [],\n\t\t\t\t\t\t})) as BaseMessage[];\n\n\t\t\t\t\t\tconst payload = { action: 'getMessages', response };\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [[{ json: payload }]]);\n\n\t\t\t\t\t\tlogAiEvent(executeFunctions, 'ai-messages-retrieved-from-memory', { response });\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t};\n\t\t\t\t} else if (prop === 'addMessage' && 'addMessage' in target) {\n\t\t\t\t\treturn async (message: BaseMessage): Promise<void> => {\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiMemory;\n\t\t\t\t\t\tconst payload = { action: 'addMessage', message };\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [[{ json: payload }]]);\n\n\t\t\t\t\t\tawait callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [message],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tlogAiEvent(executeFunctions, 'ai-message-added-to-memory', { message });\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [[{ json: payload }]]);\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ========== BaseRetriever ==========\n\t\t\tif (originalInstance instanceof BaseRetriever) {\n\t\t\t\tif (prop === 'getRelevantDocuments' && 'getRelevantDocuments' in target) {\n\t\t\t\t\treturn async (\n\t\t\t\t\t\tquery: string,\n\t\t\t\t\t\tconfig?: Callbacks | BaseCallbackConfig,\n\t\t\t\t\t): Promise<Document[]> => {\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiRetriever;\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [\n\t\t\t\t\t\t\t[{ json: { query, config } }],\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [query, config],\n\t\t\t\t\t\t})) as Array<Document<Record<string, any>>>;\n\n\t\t\t\t\t\tconst executionId: string | undefined = response[0]?.metadata?.executionId as string;\n\t\t\t\t\t\tconst workflowId: string | undefined = response[0]?.metadata?.workflowId as string;\n\n\t\t\t\t\t\tconst metadata: ITaskMetadata = {};\n\t\t\t\t\t\tif (executionId && workflowId) {\n\t\t\t\t\t\t\tmetadata.subExecution = {\n\t\t\t\t\t\t\t\texecutionId,\n\t\t\t\t\t\t\t\tworkflowId,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlogAiEvent(executeFunctions, 'ai-documents-retrieved', { query });\n\t\t\t\t\t\texecuteFunctions.addOutputData(\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\t[[{ json: { response } }]],\n\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ========== Embeddings ==========\n\t\t\tif (\n\t\t\t\toriginalInstance instanceof Embeddings ||\n\t\t\t\toriginalInstance instanceof OpenAIEmbeddings ||\n\t\t\t\toriginalInstance instanceof AzureOpenAIEmbeddings\n\t\t\t) {\n\t\t\t\t// Docs -> Embeddings\n\t\t\t\tif (prop === 'embedDocuments' && 'embedDocuments' in target) {\n\t\t\t\t\treturn async (documents: string[]): Promise<number[][]> => {\n\t\t\t\t\t\t// Validate documents input before embedding\n\t\t\t\t\t\tconst validatedDocuments = validateEmbedDocumentsInput(\n\t\t\t\t\t\t\tdocuments,\n\t\t\t\t\t\t\texecuteFunctions.getNode(),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiEmbedding;\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [\n\t\t\t\t\t\t\t[{ json: { documents: validatedDocuments } }],\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [validatedDocuments],\n\t\t\t\t\t\t})) as number[][];\n\n\t\t\t\t\t\tlogAiEvent(executeFunctions, 'ai-document-embedded');\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\t// Query -> Embeddings\n\t\t\t\tif (prop === 'embedQuery' && 'embedQuery' in target) {\n\t\t\t\t\treturn async (query: string): Promise<number[]> => {\n\t\t\t\t\t\t// Validate query input before embedding\n\t\t\t\t\t\tconst validatedQuery = validateEmbedQueryInput(query, executeFunctions.getNode());\n\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiEmbedding;\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [\n\t\t\t\t\t\t\t[{ json: { query: validatedQuery } }],\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [validatedQuery],\n\t\t\t\t\t\t})) as number[];\n\n\t\t\t\t\t\tlogAiEvent(executeFunctions, 'ai-query-embedded');\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ========== Rerankers ==========\n\t\t\tif (originalInstance instanceof BaseDocumentCompressor) {\n\t\t\t\tif (prop === 'compressDocuments' && 'compressDocuments' in target) {\n\t\t\t\t\treturn async (documents: Document[], query: string): Promise<Document[]> => {\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiReranker;\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [\n\t\t\t\t\t\t\t[{ json: { query, documents } }],\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\t// compressDocuments mutates the original object\n\t\t\t\t\t\t\t// messing up the input data logging\n\t\t\t\t\t\t\targuments: [deepCopy(documents), query],\n\t\t\t\t\t\t})) as Document[];\n\n\t\t\t\t\t\tlogAiEvent(executeFunctions, 'ai-document-reranked', { query });\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ========== N8n Loaders Process All ==========\n\t\t\tif (\n\t\t\t\toriginalInstance instanceof N8nJsonLoader ||\n\t\t\t\toriginalInstance instanceof N8nBinaryLoader\n\t\t\t) {\n\t\t\t\t// Process All\n\t\t\t\tif (prop === 'processAll' && 'processAll' in target) {\n\t\t\t\t\treturn async (items: INodeExecutionData[]): Promise<number[]> => {\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiDocument;\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [items]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [items],\n\t\t\t\t\t\t})) as number[];\n\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// Process Each\n\t\t\t\tif (prop === 'processItem' && 'processItem' in target) {\n\t\t\t\t\treturn async (item: INodeExecutionData, itemIndex: number): Promise<number[]> => {\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiDocument;\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [[item]]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [item, itemIndex],\n\t\t\t\t\t\t})) as number[];\n\n\t\t\t\t\t\tlogAiEvent(executeFunctions, 'ai-document-processed');\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [\n\t\t\t\t\t\t\t[{ json: { response }, pairedItem: { item: itemIndex } }],\n\t\t\t\t\t\t]);\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ========== TextSplitter ==========\n\t\t\tif (originalInstance instanceof TextSplitter) {\n\t\t\t\tif (prop === 'splitText' && 'splitText' in target) {\n\t\t\t\t\treturn async (text: string): Promise<string[]> => {\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiTextSplitter;\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [\n\t\t\t\t\t\t\t[{ json: { textSplitter: text } }],\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [text],\n\t\t\t\t\t\t})) as string[];\n\n\t\t\t\t\t\tlogAiEvent(executeFunctions, 'ai-text-split');\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ========== Tool ==========\n\t\t\tif (isToolsInstance(originalInstance)) {\n\t\t\t\tif (prop === '_call' && '_call' in target) {\n\t\t\t\t\treturn async (query: string): Promise<string> => {\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiTool;\n\t\t\t\t\t\tconst inputData: IDataObject = { query };\n\n\t\t\t\t\t\tif (target.metadata?.isFromToolkit) {\n\t\t\t\t\t\t\tinputData.tool = {\n\t\t\t\t\t\t\t\tname: target.name,\n\t\t\t\t\t\t\t\tdescription: target.description,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [\n\t\t\t\t\t\t\t[{ json: inputData }],\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [query],\n\t\t\t\t\t\t})) as string;\n\n\t\t\t\t\t\tlogAiEvent(executeFunctions, 'ai-tool-called', { ...inputData, response });\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);\n\n\t\t\t\t\t\tif (typeof response === 'string') return response;\n\t\t\t\t\t\treturn JSON.stringify(response);\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ========== VectorStore ==========\n\t\t\tif (originalInstance instanceof VectorStore) {\n\t\t\t\tif (prop === 'similaritySearch' && 'similaritySearch' in target) {\n\t\t\t\t\treturn async (\n\t\t\t\t\t\tquery: string,\n\t\t\t\t\t\tk?: number,\n\t\t\t\t\t\tfilter?: BiquadFilterType,\n\t\t\t\t\t\t_callbacks?: Callbacks,\n\t\t\t\t\t): Promise<Document[]> => {\n\t\t\t\t\t\tconnectionType = NodeConnectionTypes.AiVectorStore;\n\t\t\t\t\t\tconst { index } = executeFunctions.addInputData(connectionType, [\n\t\t\t\t\t\t\t[{ json: { query, k, filter } }],\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\tconst response = (await callMethodAsync.call(target, {\n\t\t\t\t\t\t\texecuteFunctions,\n\t\t\t\t\t\t\tconnectionType,\n\t\t\t\t\t\t\tcurrentNodeRunIndex: index,\n\t\t\t\t\t\t\tmethod: target[prop] as (...args: any[]) => Promise<unknown>,\n\t\t\t\t\t\t\targuments: [query, k, filter, _callbacks],\n\t\t\t\t\t\t})) as Array<Document<Record<string, any>>>;\n\n\t\t\t\t\t\tlogAiEvent(executeFunctions, 'ai-vector-store-searched', { query });\n\t\t\t\t\t\texecuteFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);\n\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\treturn (target as any)[prop];\n\t\t},\n\t});\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,wBAA2B;AAG3B,wBAA8B;AAC9B,kCAAuC;AAEvC,0BAA4B;AAC5B,2BAA6B;AAE7B,oBAAwD;AASxD,0BAKO;AAEP,sCAGO;AACP,qBAAwF;AACxF,6BAAgC;AAChC,2BAA8B;AAE9B,eAAsB,gBAErB,YAOmB;AACnB,MAAI;AACH,WAAO,MAAM,WAAW,OAAO,KAAK,MAAM,GAAG,WAAW,SAAS;AAAA,EAClE,SAAS,GAAG;AACX,UAAM,gBAAgB,WAAW,iBAAiB,QAAQ;AAE1D,UAAM,QAAQ,IAAI,uCAAmB,eAAe,GAAG;AAAA,MACtD,eAAe;AAAA,IAChB,CAAC;AAED,UAAM,eAAW,wCAAmB,KAAK;AACzC,eAAW,iBAAiB;AAAA,MAC3B,WAAW;AAAA,MACX,WAAW;AAAA,MACX;AAAA,MACA;AAAA,IACD;AAEA,QAAI,MAAM,SAAS;AAClB,UAAI,CAAC,MAAM,aAAa;AACvB,cAAM,cAAc,MAAM;AAAA,MAC3B;AACA,YAAM;AAAA,IACP;AAEA,UAAM,IAAI;AAAA,MACT;AAAA,MACA,kBAAkB,cAAc,IAAI,mCAAmC,WAAW,cAAc;AAAA,MAChG,EAAE,eAAe,qBAAqB;AAAA,IACvC;AAAA,EACD;AACD;AAEO,SAAS,eAEf,YAOU;AACV,MAAI;AACH,WAAO,WAAW,OAAO,KAAK,MAAM,GAAG,WAAW,SAAS;AAAA,EAC5D,SAA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AAAA,YACzC,CAAC;AAED,2CAAW,kBAAkB,4BAA4B,EAAE,MAAM,CAAC;AAClE,6BAAiB,cAAc,gBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;AAEhF,mBAAO;AAAA,UACR;AAAA,QACD;AAAA,MACD;AAGA,aAAQ,OAAe,IAAI;AAAA,IAC5B;AAAA,EACD,CAAC;AACF;","names":[]}
|
|
@@ -18,15 +18,58 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var schemaParsing_exports = {};
|
|
20
20
|
__export(schemaParsing_exports, {
|
|
21
|
-
convertJsonSchemaToZod: () => convertJsonSchemaToZod
|
|
21
|
+
convertJsonSchemaToZod: () => convertJsonSchemaToZod,
|
|
22
|
+
generateSchemaFromExample: () => generateSchemaFromExample,
|
|
23
|
+
throwIfToolSchema: () => throwIfToolSchema
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(schemaParsing_exports);
|
|
26
|
+
var import_json_schema_to_zod = require("@n8n/json-schema-to-zod");
|
|
27
|
+
var import_generate_schema = require("generate-schema");
|
|
28
|
+
var import_n8n_workflow = require("n8n-workflow");
|
|
29
|
+
function makeAllPropertiesRequired(schema) {
|
|
30
|
+
function isPropertySchema(property) {
|
|
31
|
+
return typeof property === "object" && property !== null && "type" in property;
|
|
32
|
+
}
|
|
33
|
+
if (schema.type === "object" && schema.properties) {
|
|
34
|
+
const properties = Object.keys(schema.properties);
|
|
35
|
+
if (properties.length > 0) {
|
|
36
|
+
schema.required = properties;
|
|
37
|
+
}
|
|
38
|
+
for (const key of properties) {
|
|
39
|
+
if (isPropertySchema(schema.properties[key])) {
|
|
40
|
+
makeAllPropertiesRequired(schema.properties[key]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (schema.type === "array" && schema.items && isPropertySchema(schema.items)) {
|
|
45
|
+
schema.items = makeAllPropertiesRequired(schema.items);
|
|
46
|
+
}
|
|
47
|
+
return schema;
|
|
48
|
+
}
|
|
49
|
+
function generateSchemaFromExample(exampleJsonString, allFieldsRequired = false) {
|
|
50
|
+
const parsedExample = (0, import_n8n_workflow.jsonParse)(exampleJsonString);
|
|
51
|
+
const schema = (0, import_generate_schema.json)(parsedExample);
|
|
52
|
+
if (allFieldsRequired) {
|
|
53
|
+
return makeAllPropertiesRequired(schema);
|
|
54
|
+
}
|
|
55
|
+
return schema;
|
|
56
|
+
}
|
|
24
57
|
function convertJsonSchemaToZod(schema) {
|
|
25
|
-
|
|
26
|
-
|
|
58
|
+
return (0, import_json_schema_to_zod.jsonSchemaToZod)(schema);
|
|
59
|
+
}
|
|
60
|
+
function throwIfToolSchema(ctx, error) {
|
|
61
|
+
if (error?.message?.includes("tool input did not match expected schema")) {
|
|
62
|
+
throw new import_n8n_workflow.NodeOperationError(
|
|
63
|
+
ctx.getNode(),
|
|
64
|
+
`${error.message}.
|
|
65
|
+
This is most likely because some of your tools are configured to require a specific schema. This is not supported by Conversational Agent. Remove the schema from the tool configuration or use Tools agent instead.`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
27
68
|
}
|
|
28
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
70
|
0 && (module.exports = {
|
|
30
|
-
convertJsonSchemaToZod
|
|
71
|
+
convertJsonSchemaToZod,
|
|
72
|
+
generateSchemaFromExample,
|
|
73
|
+
throwIfToolSchema
|
|
31
74
|
});
|
|
32
75
|
//# sourceMappingURL=schemaParsing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../nodes/shared/schemaParsing.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../nodes/shared/schemaParsing.ts"],"sourcesContent":["import { jsonSchemaToZod } from '@n8n/json-schema-to-zod';\nimport { json as generateJsonSchema } from 'generate-schema';\nimport type { SchemaObject } from 'generate-schema';\nimport type { JSONSchema7 } from 'json-schema';\nimport type { IExecuteFunctions } from 'n8n-workflow';\nimport { NodeOperationError, jsonParse } from 'n8n-workflow';\nimport type { z } from 'zod';\n\nfunction makeAllPropertiesRequired(schema: JSONSchema7): JSONSchema7 {\n\tfunction isPropertySchema(property: unknown): property is JSONSchema7 {\n\t\treturn typeof property === 'object' && property !== null && 'type' in property;\n\t}\n\n\t// Handle object properties\n\tif (schema.type === 'object' && schema.properties) {\n\t\tconst properties = Object.keys(schema.properties);\n\t\tif (properties.length > 0) {\n\t\t\tschema.required = properties;\n\t\t}\n\n\t\tfor (const key of properties) {\n\t\t\tif (isPropertySchema(schema.properties[key])) {\n\t\t\t\tmakeAllPropertiesRequired(schema.properties[key]);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Handle arrays\n\tif (schema.type === 'array' && schema.items && isPropertySchema(schema.items)) {\n\t\tschema.items = makeAllPropertiesRequired(schema.items);\n\t}\n\n\treturn schema;\n}\n\nexport function generateSchemaFromExample(\n\texampleJsonString: string,\n\tallFieldsRequired = false,\n): JSONSchema7 {\n\tconst parsedExample = jsonParse<SchemaObject>(exampleJsonString);\n\n\tconst schema = generateJsonSchema(parsedExample) as JSONSchema7;\n\n\tif (allFieldsRequired) {\n\t\treturn makeAllPropertiesRequired(schema);\n\t}\n\n\treturn schema;\n}\n\nexport function convertJsonSchemaToZod<T extends z.ZodTypeAny = z.ZodTypeAny>(schema: JSONSchema7) {\n\treturn jsonSchemaToZod<T>(schema);\n}\n\nexport function throwIfToolSchema(ctx: IExecuteFunctions, error: Error) {\n\tif (error?.message?.includes('tool input did not match expected schema')) {\n\t\tthrow new NodeOperationError(\n\t\t\tctx.getNode(),\n\t\t\t`${error.message}.\n\t\t\tThis is most likely because some of your tools are configured to require a specific schema. This is not supported by Conversational Agent. Remove the schema from the tool configuration or use Tools agent instead.`,\n\t\t);\n\t}\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAAgC;AAChC,6BAA2C;AAI3C,0BAA8C;AAG9C,SAAS,0BAA0B,QAAkC;AACpE,WAAS,iBAAiB,UAA4C;AACrE,WAAO,OAAO,aAAa,YAAY,aAAa,QAAQ,UAAU;AAAA,EACvE;AAGA,MAAI,OAAO,SAAS,YAAY,OAAO,YAAY;AAClD,UAAM,aAAa,OAAO,KAAK,OAAO,UAAU;AAChD,QAAI,WAAW,SAAS,GAAG;AAC1B,aAAO,WAAW;AAAA,IACnB;AAEA,eAAW,OAAO,YAAY;AAC7B,UAAI,iBAAiB,OAAO,WAAW,GAAG,CAAC,GAAG;AAC7C,kCAA0B,OAAO,WAAW,GAAG,CAAC;AAAA,MACjD;AAAA,IACD;AAAA,EACD;AAGA,MAAI,OAAO,SAAS,WAAW,OAAO,SAAS,iBAAiB,OAAO,KAAK,GAAG;AAC9E,WAAO,QAAQ,0BAA0B,OAAO,KAAK;AAAA,EACtD;AAEA,SAAO;AACR;AAEO,SAAS,0BACf,mBACA,oBAAoB,OACN;AACd,QAAM,oBAAgB,+BAAwB,iBAAiB;AAE/D,QAAM,aAAS,uBAAAA,MAAmB,aAAa;AAE/C,MAAI,mBAAmB;AACtB,WAAO,0BAA0B,MAAM;AAAA,EACxC;AAEA,SAAO;AACR;AAEO,SAAS,uBAA8D,QAAqB;AAClG,aAAO,2CAAmB,MAAM;AACjC;AAEO,SAAS,kBAAkB,KAAwB,OAAc;AACvE,MAAI,OAAO,SAAS,SAAS,0CAA0C,GAAG;AACzE,UAAM,IAAI;AAAA,MACT,IAAI,QAAQ;AAAA,MACZ,GAAG,MAAM,OAAO;AAAA;AAAA,IAEjB;AAAA,EACD;AACD;","names":["generateJsonSchema"]}
|