n8n-nodes-couchbase 0.1.4 → 1.0.0
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 +133 -65
- package/dist/credentials/CouchbaseApi.credentials.d.ts +8 -0
- package/dist/credentials/CouchbaseApi.credentials.js +39 -0
- package/dist/credentials/CouchbaseApi.credentials.js.map +1 -0
- package/dist/credentials/ExampleCredentialsApi.credentials.d.ts +8 -0
- package/dist/credentials/ExampleCredentialsApi.credentials.js +46 -0
- package/dist/credentials/ExampleCredentialsApi.credentials.js.map +1 -0
- package/dist/credentials/HttpBinApi.credentials.d.ts +9 -0
- package/dist/credentials/HttpBinApi.credentials.js +43 -0
- package/dist/credentials/HttpBinApi.credentials.js.map +1 -0
- package/dist/nodes/Couchbase/Couchbase.node.d.ts +35 -0
- package/dist/nodes/Couchbase/Couchbase.node.js +303 -0
- package/dist/nodes/Couchbase/Couchbase.node.js.map +1 -0
- package/dist/nodes/Couchbase/Couchbase.node.json +18 -0
- package/dist/nodes/Couchbase/CouchbaseProperties.d.ts +16 -0
- package/dist/nodes/Couchbase/CouchbaseProperties.js +478 -0
- package/dist/nodes/Couchbase/CouchbaseProperties.js.map +1 -0
- package/dist/nodes/Couchbase/couchbase.dark.svg +14 -0
- package/dist/nodes/Couchbase/couchbase.svg +14 -0
- package/dist/nodes/ExampleNode/ExampleNode.node.d.ts +5 -0
- package/dist/nodes/ExampleNode/ExampleNode.node.js +59 -0
- package/dist/nodes/ExampleNode/ExampleNode.node.js.map +1 -0
- package/dist/nodes/HttpBin/HttpBin.node.d.ts +4 -0
- package/dist/nodes/HttpBin/HttpBin.node.js +55 -0
- package/dist/nodes/HttpBin/HttpBin.node.js.map +1 -0
- package/dist/nodes/HttpBin/HttpBin.node.json +18 -0
- package/dist/nodes/HttpBin/HttpVerbDescription.d.ts +3 -0
- package/dist/nodes/HttpBin/HttpVerbDescription.js +236 -0
- package/dist/nodes/HttpBin/HttpVerbDescription.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreCouchbase/VectorStoreCouchbase.node.d.ts +16 -0
- package/dist/nodes/vector_store/VectorStoreCouchbase/VectorStoreCouchbase.node.js +407 -0
- package/dist/nodes/vector_store/VectorStoreCouchbase/VectorStoreCouchbase.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreCouchbase/mongodb.dark.svg +3 -0
- package/dist/nodes/vector_store/VectorStoreCouchbase/mongodb.svg +3 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/__tests__/utils.test.d.ts +0 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/__tests__/utils.test.js +2 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/__tests__/utils.test.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/constants.d.ts +4 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/constants.js +45 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/constants.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.d.ts +15 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js +227 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.test.d.ts +0 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.test.js +2 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.test.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/methods/listSearch.d.ts +0 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/methods/listSearch.js +2 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/methods/listSearch.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/insertOperation.test.d.ts +0 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/insertOperation.test.js +2 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/insertOperation.test.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/loadOperation.test.d.ts +0 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/loadOperation.test.js +2 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/loadOperation.test.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/operationHandlers.test.d.ts +0 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/operationHandlers.test.js +2 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/operationHandlers.test.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/retrieveAsToolOperation.test.d.ts +0 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/retrieveAsToolOperation.test.js +2 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/retrieveAsToolOperation.test.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/retrieveOperation.test.d.ts +0 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/retrieveOperation.test.js +2 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/retrieveOperation.test.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/updateOperation.test.d.ts +0 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/updateOperation.test.js +2 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/__tests__/updateOperation.test.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/index.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/index.js +22 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/index.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/insertOperation.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/insertOperation.js +36 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/insertOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.js +34 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js +43 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.js +17 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/updateOperation.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/updateOperation.js +40 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/updateOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/types.d.ts +31 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/types.js +3 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/types.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/utils.d.ts +6 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/utils.js +22 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/utils.js.map +1 -0
- package/dist/nodes/vector_store/shared/processDocuments.d.ts +25 -0
- package/dist/nodes/vector_store/shared/processDocuments.js +46 -0
- package/dist/nodes/vector_store/shared/processDocuments.js.map +1 -0
- package/dist/package.json +29 -19
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/N8nBinaryLoader.d.ts +18 -0
- package/dist/utils/N8nBinaryLoader.js +159 -0
- package/dist/utils/N8nBinaryLoader.js.map +1 -0
- package/dist/utils/N8nJsonLoader.d.ts +11 -0
- package/dist/utils/N8nJsonLoader.js +67 -0
- package/dist/utils/N8nJsonLoader.js.map +1 -0
- package/dist/utils/N8nTool.d.ts +10 -0
- package/dist/utils/N8nTool.js +86 -0
- package/dist/utils/N8nTool.js.map +1 -0
- package/dist/utils/helpers.d.ts +23 -0
- package/dist/utils/helpers.js +172 -0
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/logWrapper.d.ts +27 -0
- package/dist/utils/logWrapper.js +297 -0
- package/dist/utils/logWrapper.js.map +1 -0
- package/dist/utils/sharedFields.d.ts +6 -0
- package/dist/utils/sharedFields.js +122 -0
- package/dist/utils/sharedFields.js.map +1 -0
- package/package.json +35 -27
- package/dist/credentials/CouchbaseCredentialsApi.credentials.d.ts +0 -7
- package/dist/credentials/CouchbaseCredentialsApi.credentials.js +0 -50
- package/dist/credentials/CouchbaseCredentialsApi.credentials.js.map +0 -1
- package/dist/nodes/CouchbaseDB/CouchbaseNode.node.d.ts +0 -6
- package/dist/nodes/CouchbaseDB/CouchbaseNode.node.js +0 -206
- package/dist/nodes/CouchbaseDB/CouchbaseNode.node.js.map +0 -1
- package/dist/nodes/CouchbaseNode/CouchbaseNode.node.d.ts +0 -6
- package/dist/nodes/CouchbaseNode/CouchbaseNode.node.js +0 -256
- package/dist/nodes/CouchbaseNode/CouchbaseNode.node.js.map +0 -1
- /package/dist/nodes/{CouchbaseDB → Couchbase}/CBLogomark.svg +0 -0
- /package/dist/nodes/{CouchbaseNode/CBLogomark.svg → vector_store/VectorStoreCouchbase/couchbase.svg} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"N8nJsonLoader.js","sourceRoot":"","sources":["../../utils/N8nJsonLoader.ts"],"names":[],"mapp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CAAC,YAAY;YAC7B,CAAC,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC;YACrE,CAAC,CAAC,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC;QAE/B,IAAI,QAAQ,EAAE,CAAC;YACd,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACpB,GAAG,CAAC,QAAQ,GAAG;oBACd,GAAG,GAAG,CAAC,QAAQ;oBACf,GAAG,QAAQ;iBACX,CAAC;YACH,CAAC,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AA5ED,sCA4EC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DynamicStructuredToolInput } from '@langchain/core/tools';
|
|
2
|
+
import { DynamicStructuredTool, DynamicTool } from '@langchain/core/tools';
|
|
3
|
+
import type { ISupplyDataFunctions } from 'n8n-workflow';
|
|
4
|
+
import { ZodObject } from 'zod';
|
|
5
|
+
export declare const prepareFallbackToolDescription: (toolDescription: string, schema: ZodObject<any>) => string;
|
|
6
|
+
export declare class N8nTool extends DynamicStructuredTool {
|
|
7
|
+
private context;
|
|
8
|
+
constructor(context: ISupplyDataFunctions, fields: DynamicStructuredToolInput);
|
|
9
|
+
asDynamicTool(): DynamicTool;
|
|
10
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.N8nTool = exports.prepareFallbackToolDescription = void 0;
|
|
4
|
+
const tools_1 = require("@langchain/core/tools");
|
|
5
|
+
const output_parsers_1 = require("langchain/output_parsers");
|
|
6
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const getSimplifiedType = (schema) => {
|
|
9
|
+
if (schema instanceof zod_1.ZodObject) {
|
|
10
|
+
return 'object';
|
|
11
|
+
}
|
|
12
|
+
else if (schema instanceof zod_1.ZodNumber) {
|
|
13
|
+
return 'number';
|
|
14
|
+
}
|
|
15
|
+
else if (schema instanceof zod_1.ZodBoolean) {
|
|
16
|
+
return 'boolean';
|
|
17
|
+
}
|
|
18
|
+
else if (schema instanceof zod_1.ZodNullable || schema instanceof zod_1.ZodOptional) {
|
|
19
|
+
return getSimplifiedType(schema.unwrap());
|
|
20
|
+
}
|
|
21
|
+
return 'string';
|
|
22
|
+
};
|
|
23
|
+
const getParametersDescription = (parameters) => parameters
|
|
24
|
+
.map(([name, schema]) => { var _a; return `${name}: (description: ${(_a = schema.description) !== null && _a !== void 0 ? _a : ''}, type: ${getSimplifiedType(schema)}, required: ${!schema.isOptional()})`; })
|
|
25
|
+
.join(',\n ');
|
|
26
|
+
const prepareFallbackToolDescription = (toolDescription, schema) => {
|
|
27
|
+
let description = `${toolDescription}`;
|
|
28
|
+
const toolParameters = Object.entries(schema.shape);
|
|
29
|
+
if (toolParameters.length) {
|
|
30
|
+
description += `
|
|
31
|
+
Tool expects valid stringified JSON object with ${toolParameters.length} properties.
|
|
32
|
+
Property names with description, type and required status:
|
|
33
|
+
${getParametersDescription(toolParameters)}
|
|
34
|
+
ALL parameters marked as required must be provided`;
|
|
35
|
+
}
|
|
36
|
+
return description;
|
|
37
|
+
};
|
|
38
|
+
exports.prepareFallbackToolDescription = prepareFallbackToolDescription;
|
|
39
|
+
class N8nTool extends tools_1.DynamicStructuredTool {
|
|
40
|
+
constructor(context, fields) {
|
|
41
|
+
super(fields);
|
|
42
|
+
this.context = context;
|
|
43
|
+
}
|
|
44
|
+
asDynamicTool() {
|
|
45
|
+
const { name, func, schema, context, description } = this;
|
|
46
|
+
const parser = new output_parsers_1.StructuredOutputParser(schema);
|
|
47
|
+
const wrappedFunc = async function (query) {
|
|
48
|
+
let parsedQuery;
|
|
49
|
+
try {
|
|
50
|
+
parsedQuery = await parser.parse(query);
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
let dataFromModel;
|
|
54
|
+
try {
|
|
55
|
+
dataFromModel = (0, n8n_workflow_1.jsonParse)(query, { acceptJSObject: true });
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (Object.keys(schema.shape).length === 1) {
|
|
59
|
+
const parameterName = Object.keys(schema.shape)[0];
|
|
60
|
+
dataFromModel = { [parameterName]: query };
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Input is not a valid JSON: ${error.message}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
parsedQuery = schema.parse(dataFromModel);
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const result = await func(parsedQuery);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
const { index } = context.addInputData(n8n_workflow_1.NodeConnectionTypes.AiTool, [[{ json: { query } }]]);
|
|
74
|
+
void context.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiTool, index, e);
|
|
75
|
+
return e.toString();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
return new tools_1.DynamicTool({
|
|
79
|
+
name,
|
|
80
|
+
description: (0, exports.prepareFallbackToolDescription)(description, schema),
|
|
81
|
+
func: wrappedFunc,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.N8nTool = N8nTool;
|
|
86
|
+
//# sourceMappingURL=N8nTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"N8nTool.js","sourceRoot":"","sources":["../../utils/N8nTool.ts"],"names":[],"mappings":";;;AACA,iDAA2E;AAC3E,6DAAkE;AAElE,+CAAkF;AAElF,6BAAiF;AAEjF,MAAM,iBAAiB,GAAG,CAAC,MAAkB,EAAE,EAAE;IAChD,IAAI,MAAM,YAAY,eAAS,EAAE,CAAC;QACjC,OAAO,QAAQ,CAAC;IACjB,CAAC;SAAM,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C,YAAY,CAAC,kCAAmB,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC5F,KAAK,OAAO,CAAC,aAAa,CAAC,kCAAmB,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;gBAEjE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;YACrB,CAAC;QACF,CAAC,CAAC;QAEF,OAAO,IAAI,mBAAW,CAAC;YACtB,IAAI;YACJ,WAAW,EAAE,IAAA,sCAA8B,EAAC,WAAW,EAAE,MAAM,CAAC;YAChE,IAAI,EAAE,WAAW;SACjB,CAAC,CAAC;IACJ,CAAC;CACD;AAjED,0BAiEC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BaseChatMessageHistory } from '@langchain/core/chat_history';
|
|
2
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
3
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
4
|
+
import type { Tool } from '@langchain/core/tools';
|
|
5
|
+
import type { BaseChatMemory } from 'langchain/memory';
|
|
6
|
+
import type { AiEvent, IDataObject, IExecuteFunctions, ISupplyDataFunctions, IWebhookFunctions } from 'n8n-workflow';
|
|
7
|
+
export declare function getMetadataFiltersValues(ctx: IExecuteFunctions | ISupplyDataFunctions, itemIndex: number): Record<string, never> | undefined;
|
|
8
|
+
export declare function isBaseChatMemory(obj: unknown): obj is BaseChatMemory;
|
|
9
|
+
export declare function isBaseChatMessageHistory(obj: unknown): obj is BaseChatMessageHistory;
|
|
10
|
+
export declare function isChatInstance(model: unknown): model is BaseChatModel;
|
|
11
|
+
export declare function isToolsInstance(model: unknown): model is Tool;
|
|
12
|
+
export declare function getPromptInputByType(options: {
|
|
13
|
+
ctx: IExecuteFunctions;
|
|
14
|
+
i: number;
|
|
15
|
+
promptTypeKey: string;
|
|
16
|
+
inputKey: string;
|
|
17
|
+
}): string;
|
|
18
|
+
export declare function getSessionId(ctx: ISupplyDataFunctions | IWebhookFunctions, itemIndex: number, selectorKey?: string, autoSelect?: string, customKey?: string): string;
|
|
19
|
+
export declare function logAiEvent(executeFunctions: IExecuteFunctions | ISupplyDataFunctions, event: AiEvent, data?: IDataObject): void;
|
|
20
|
+
export declare function serializeChatHistory(chatHistory: BaseMessage[]): string;
|
|
21
|
+
export declare function escapeSingleCurlyBrackets(text?: string): string | undefined;
|
|
22
|
+
export declare const getConnectedTools: (ctx: IExecuteFunctions, enforceUniqueNames: boolean, convertStructuredTool?: boolean, escapeCurlyBrackets?: boolean) => Promise<Tool[]>;
|
|
23
|
+
export declare function unwrapNestedOutput(output: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConnectedTools = void 0;
|
|
4
|
+
exports.getMetadataFiltersValues = getMetadataFiltersValues;
|
|
5
|
+
exports.isBaseChatMemory = isBaseChatMemory;
|
|
6
|
+
exports.isBaseChatMessageHistory = isBaseChatMessageHistory;
|
|
7
|
+
exports.isChatInstance = isChatInstance;
|
|
8
|
+
exports.isToolsInstance = isToolsInstance;
|
|
9
|
+
exports.getPromptInputByType = getPromptInputByType;
|
|
10
|
+
exports.getSessionId = getSessionId;
|
|
11
|
+
exports.logAiEvent = logAiEvent;
|
|
12
|
+
exports.serializeChatHistory = serializeChatHistory;
|
|
13
|
+
exports.escapeSingleCurlyBrackets = escapeSingleCurlyBrackets;
|
|
14
|
+
exports.unwrapNestedOutput = unwrapNestedOutput;
|
|
15
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
16
|
+
const N8nTool_1 = require("./N8nTool");
|
|
17
|
+
function hasMethods(obj, ...methodNames) {
|
|
18
|
+
return methodNames.every((methodName) => typeof obj === 'object' &&
|
|
19
|
+
obj !== null &&
|
|
20
|
+
methodName in obj &&
|
|
21
|
+
typeof obj[methodName] === 'function');
|
|
22
|
+
}
|
|
23
|
+
function getMetadataFiltersValues(ctx, itemIndex) {
|
|
24
|
+
const options = ctx.getNodeParameter('options', itemIndex, {});
|
|
25
|
+
if (options.metadata) {
|
|
26
|
+
const { metadataValues: metadata } = options.metadata;
|
|
27
|
+
if (metadata.length > 0) {
|
|
28
|
+
return metadata.reduce((acc, { name, value }) => ({ ...acc, [name]: value }), {});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (options.searchFilterJson) {
|
|
32
|
+
return ctx.getNodeParameter('options.searchFilterJson', itemIndex, '', {
|
|
33
|
+
ensureType: 'object',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
function isBaseChatMemory(obj) {
|
|
39
|
+
return hasMethods(obj, 'loadMemoryVariables', 'saveContext');
|
|
40
|
+
}
|
|
41
|
+
function isBaseChatMessageHistory(obj) {
|
|
42
|
+
return hasMethods(obj, 'getMessages', 'addMessage');
|
|
43
|
+
}
|
|
44
|
+
function isChatInstance(model) {
|
|
45
|
+
var _a;
|
|
46
|
+
const namespace = (_a = model === null || model === void 0 ? void 0 : model.lc_namespace) !== null && _a !== void 0 ? _a : [];
|
|
47
|
+
return namespace.includes('chat_models');
|
|
48
|
+
}
|
|
49
|
+
function isToolsInstance(model) {
|
|
50
|
+
var _a;
|
|
51
|
+
const namespace = (_a = model === null || model === void 0 ? void 0 : model.lc_namespace) !== null && _a !== void 0 ? _a : [];
|
|
52
|
+
return namespace.includes('tools');
|
|
53
|
+
}
|
|
54
|
+
function getPromptInputByType(options) {
|
|
55
|
+
const { ctx, i, promptTypeKey, inputKey } = options;
|
|
56
|
+
const prompt = ctx.getNodeParameter(promptTypeKey, i);
|
|
57
|
+
let input;
|
|
58
|
+
if (prompt === 'auto') {
|
|
59
|
+
input = ctx.evaluateExpression('{{ $json["chatInput"] }}', i);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
input = ctx.getNodeParameter(inputKey, i);
|
|
63
|
+
}
|
|
64
|
+
if (input === undefined) {
|
|
65
|
+
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), 'No prompt specified', {
|
|
66
|
+
description: "Expected to find the prompt in an input field called 'chatInput' (this is what the chat trigger node outputs). To use something else, change the 'Prompt' parameter",
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return input;
|
|
70
|
+
}
|
|
71
|
+
function getSessionId(ctx, itemIndex, selectorKey = 'sessionIdType', autoSelect = 'fromInput', customKey = 'sessionKey') {
|
|
72
|
+
var _a;
|
|
73
|
+
let sessionId = '';
|
|
74
|
+
const selectorType = ctx.getNodeParameter(selectorKey, itemIndex);
|
|
75
|
+
if (selectorType === autoSelect) {
|
|
76
|
+
if ('getBodyData' in ctx) {
|
|
77
|
+
const bodyData = (_a = ctx.getBodyData()) !== null && _a !== void 0 ? _a : {};
|
|
78
|
+
sessionId = bodyData.sessionId;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
sessionId = ctx.evaluateExpression('{{ $json.sessionId }}', itemIndex);
|
|
82
|
+
}
|
|
83
|
+
if (sessionId === '' || sessionId === undefined) {
|
|
84
|
+
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), 'No session ID found', {
|
|
85
|
+
description: "Expected to find the session ID in an input field called 'sessionId' (this is what the chat trigger node outputs). To use something else, change the 'Session ID' parameter",
|
|
86
|
+
itemIndex,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
sessionId = ctx.getNodeParameter(customKey, itemIndex, '');
|
|
92
|
+
if (sessionId === '' || sessionId === undefined) {
|
|
93
|
+
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), 'Key parameter is empty', {
|
|
94
|
+
description: "Provide a key to use as session ID in the 'Key' parameter or use the 'Connected Chat Trigger Node' option to use the session ID from your Chat Trigger",
|
|
95
|
+
itemIndex,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return sessionId;
|
|
100
|
+
}
|
|
101
|
+
function logAiEvent(executeFunctions, event, data) {
|
|
102
|
+
try {
|
|
103
|
+
executeFunctions.logAiEvent(event, data ? (0, n8n_workflow_1.jsonStringify)(data) : undefined);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
executeFunctions.logger.debug(`Error logging AI event: ${event}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function serializeChatHistory(chatHistory) {
|
|
110
|
+
return chatHistory
|
|
111
|
+
.map((chatMessage) => {
|
|
112
|
+
if (chatMessage._getType() === 'human') {
|
|
113
|
+
return `Human: ${chatMessage.content}`;
|
|
114
|
+
}
|
|
115
|
+
else if (chatMessage._getType() === 'ai') {
|
|
116
|
+
return `Assistant: ${chatMessage.content}`;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return `${chatMessage.content}`;
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
.join('\n');
|
|
123
|
+
}
|
|
124
|
+
function escapeSingleCurlyBrackets(text) {
|
|
125
|
+
if (text === undefined)
|
|
126
|
+
return undefined;
|
|
127
|
+
let result = text;
|
|
128
|
+
result = result
|
|
129
|
+
.replace(/(?<!{){{{(?!{)/g, '{{{{')
|
|
130
|
+
.replace(/(?<!})}}}(?!})/g, '}}}}')
|
|
131
|
+
.replace(/(?<!{){(?!{)/g, '{{')
|
|
132
|
+
.replace(/(?<!})}(?!})/g, '}}');
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
const getConnectedTools = async (ctx, enforceUniqueNames, convertStructuredTool = true, escapeCurlyBrackets = false) => {
|
|
136
|
+
var _a;
|
|
137
|
+
const connectedTools = (await ctx.getInputConnectionData(n8n_workflow_1.NodeConnectionTypes.AiTool, 0)) || [];
|
|
138
|
+
if (!enforceUniqueNames)
|
|
139
|
+
return connectedTools;
|
|
140
|
+
const seenNames = new Set();
|
|
141
|
+
const finalTools = [];
|
|
142
|
+
for (const tool of connectedTools) {
|
|
143
|
+
const { name } = tool;
|
|
144
|
+
if (seenNames.has(name)) {
|
|
145
|
+
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), `You have multiple tools with the same name: '${name}', please rename them to avoid conflicts`);
|
|
146
|
+
}
|
|
147
|
+
seenNames.add(name);
|
|
148
|
+
if (escapeCurlyBrackets) {
|
|
149
|
+
tool.description = (_a = escapeSingleCurlyBrackets(tool.description)) !== null && _a !== void 0 ? _a : tool.description;
|
|
150
|
+
}
|
|
151
|
+
if (convertStructuredTool && tool instanceof N8nTool_1.N8nTool) {
|
|
152
|
+
finalTools.push(tool.asDynamicTool());
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
finalTools.push(tool);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return finalTools;
|
|
159
|
+
};
|
|
160
|
+
exports.getConnectedTools = getConnectedTools;
|
|
161
|
+
function unwrapNestedOutput(output) {
|
|
162
|
+
if ('output' in output &&
|
|
163
|
+
Object.keys(output).length === 1 &&
|
|
164
|
+
typeof output.output === 'object' &&
|
|
165
|
+
output.output !== null &&
|
|
166
|
+
'output' in output.output &&
|
|
167
|
+
Object.keys(output.output).length === 1) {
|
|
168
|
+
return output.output;
|
|
169
|
+
}
|
|
170
|
+
return output;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../utils/helpers.ts"],"names":[],"mappings":";;;AA2BA,4DAyBC;AAED,4CAEC;AAED,4DAEC;AAED,wCAIC;AAED,0CAIC;AAED,oDAwBC;AAED,oCAuCC;AAED,gCAUC;AAED,oDAYC;AAED,8DAgBC;AA6CD,gDAaC;AA3OD,+CAAsF;AAStF,uCAAoC;AAEpC,SAAS,UAAU,CAAI,GAAY,EAAE,GAAG,WAAmC;IAC1E,OAAO,WAAW,CAAC,KAAK,CACvB,CAAC,UAAU,EAAE,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
+
import type { BaseChatMessageHistory } from '@langchain/core/chat_history';
|
|
3
|
+
import type { Document } from '@langchain/core/documents';
|
|
4
|
+
import { Embeddings } from '@langchain/core/embeddings';
|
|
5
|
+
import { BaseRetriever } from '@langchain/core/retrievers';
|
|
6
|
+
import type { Tool } from '@langchain/core/tools';
|
|
7
|
+
import { VectorStore } from '@langchain/core/vectorstores';
|
|
8
|
+
import { TextSplitter } from '@langchain/textsplitters';
|
|
9
|
+
import type { BaseDocumentLoader } from 'langchain/dist/document_loaders/base';
|
|
10
|
+
import type { IExecuteFunctions, ISupplyDataFunctions, NodeConnectionType } from 'n8n-workflow';
|
|
11
|
+
import { N8nBinaryLoader } from './N8nBinaryLoader';
|
|
12
|
+
import { N8nJsonLoader } from './N8nJsonLoader';
|
|
13
|
+
export declare function callMethodAsync<T>(this: T, parameters: {
|
|
14
|
+
executeFunctions: IExecuteFunctions | ISupplyDataFunctions;
|
|
15
|
+
connectionType: NodeConnectionType;
|
|
16
|
+
currentNodeRunIndex: number;
|
|
17
|
+
method: (...args: any[]) => Promise<unknown>;
|
|
18
|
+
arguments: unknown[];
|
|
19
|
+
}): Promise<unknown>;
|
|
20
|
+
export declare function callMethodSync<T>(this: T, parameters: {
|
|
21
|
+
executeFunctions: IExecuteFunctions;
|
|
22
|
+
connectionType: NodeConnectionType;
|
|
23
|
+
currentNodeRunIndex: number;
|
|
24
|
+
method: (...args: any[]) => T;
|
|
25
|
+
arguments: unknown[];
|
|
26
|
+
}): unknown;
|
|
27
|
+
export declare function logWrapper(originalInstance: Tool | BaseChatMemory | BaseChatMessageHistory | BaseRetriever | Embeddings | Document[] | Document | BaseDocumentLoader | TextSplitter | VectorStore | N8nBinaryLoader | N8nJsonLoader, executeFunctions: IExecuteFunctions | ISupplyDataFunctions): VectorStore | Document<Record<string, any>> | Document<Record<string, any>>[] | Embeddings | Tool | BaseChatMemory | BaseChatMessageHistory | BaseRetriever<Record<string, any>> | BaseDocumentLoader | TextSplitter | N8nBinaryLoader | N8nJsonLoader;
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callMethodAsync = callMethodAsync;
|
|
4
|
+
exports.callMethodSync = callMethodSync;
|
|
5
|
+
exports.logWrapper = logWrapper;
|
|
6
|
+
const embeddings_1 = require("@langchain/core/embeddings");
|
|
7
|
+
const retrievers_1 = require("@langchain/core/retrievers");
|
|
8
|
+
const vectorstores_1 = require("@langchain/core/vectorstores");
|
|
9
|
+
const textsplitters_1 = require("@langchain/textsplitters");
|
|
10
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
11
|
+
const helpers_1 = require("./helpers");
|
|
12
|
+
const N8nBinaryLoader_1 = require("./N8nBinaryLoader");
|
|
13
|
+
const N8nJsonLoader_1 = require("./N8nJsonLoader");
|
|
14
|
+
async function callMethodAsync(parameters) {
|
|
15
|
+
try {
|
|
16
|
+
return await parameters.method.call(this, ...parameters.arguments);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
const connectedNode = parameters.executeFunctions.getNode();
|
|
20
|
+
const error = new n8n_workflow_1.NodeOperationError(connectedNode, e, {
|
|
21
|
+
functionality: 'configuration-node',
|
|
22
|
+
});
|
|
23
|
+
const metadata = (0, n8n_workflow_1.parseErrorMetadata)(error);
|
|
24
|
+
parameters.executeFunctions.addOutputData(parameters.connectionType, parameters.currentNodeRunIndex, error, metadata);
|
|
25
|
+
if (error.message) {
|
|
26
|
+
if (!error.description) {
|
|
27
|
+
error.description = error.message;
|
|
28
|
+
}
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
throw new n8n_workflow_1.NodeOperationError(connectedNode, `Error on node "${connectedNode.name}" which is connected via input "${parameters.connectionType}"`, { functionality: 'configuration-node' });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function callMethodSync(parameters) {
|
|
35
|
+
try {
|
|
36
|
+
return parameters.method.call(this, ...parameters.arguments);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
const connectedNode = parameters.executeFunctions.getNode();
|
|
40
|
+
const error = new n8n_workflow_1.NodeOperationError(connectedNode, e);
|
|
41
|
+
parameters.executeFunctions.addOutputData(parameters.connectionType, parameters.currentNodeRunIndex, error);
|
|
42
|
+
throw new n8n_workflow_1.NodeOperationError(connectedNode, `Error on node "${connectedNode.name}" which is connected via input "${parameters.connectionType}"`, { functionality: 'configuration-node' });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function logWrapper(originalInstance, executeFunctions) {
|
|
46
|
+
return new Proxy(originalInstance, {
|
|
47
|
+
get: (target, prop) => {
|
|
48
|
+
let connectionType;
|
|
49
|
+
if ((0, helpers_1.isBaseChatMemory)(originalInstance)) {
|
|
50
|
+
if (prop === 'loadMemoryVariables' && 'loadMemoryVariables' in target) {
|
|
51
|
+
return async (values) => {
|
|
52
|
+
var _a;
|
|
53
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiMemory;
|
|
54
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
55
|
+
[{ json: { action: 'loadMemoryVariables', values } }],
|
|
56
|
+
]);
|
|
57
|
+
const response = (await callMethodAsync.call(target, {
|
|
58
|
+
executeFunctions,
|
|
59
|
+
connectionType,
|
|
60
|
+
currentNodeRunIndex: index,
|
|
61
|
+
method: target[prop],
|
|
62
|
+
arguments: [values],
|
|
63
|
+
}));
|
|
64
|
+
const chatHistory = (_a = response === null || response === void 0 ? void 0 : response.chat_history) !== null && _a !== void 0 ? _a : response;
|
|
65
|
+
executeFunctions.addOutputData(connectionType, index, [
|
|
66
|
+
[{ json: { action: 'loadMemoryVariables', chatHistory } }],
|
|
67
|
+
]);
|
|
68
|
+
return response;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
else if (prop === 'saveContext' && 'saveContext' in target) {
|
|
72
|
+
return async (input, output) => {
|
|
73
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiMemory;
|
|
74
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
75
|
+
[{ json: { action: 'saveContext', input, output } }],
|
|
76
|
+
]);
|
|
77
|
+
const response = (await callMethodAsync.call(target, {
|
|
78
|
+
executeFunctions,
|
|
79
|
+
connectionType,
|
|
80
|
+
currentNodeRunIndex: index,
|
|
81
|
+
method: target[prop],
|
|
82
|
+
arguments: [input, output],
|
|
83
|
+
}));
|
|
84
|
+
const chatHistory = await target.chatHistory.getMessages();
|
|
85
|
+
executeFunctions.addOutputData(connectionType, index, [
|
|
86
|
+
[{ json: { action: 'saveContext', chatHistory } }],
|
|
87
|
+
]);
|
|
88
|
+
return response;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if ((0, helpers_1.isBaseChatMessageHistory)(originalInstance)) {
|
|
93
|
+
if (prop === 'getMessages' && 'getMessages' in target) {
|
|
94
|
+
return async () => {
|
|
95
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiMemory;
|
|
96
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
97
|
+
[{ json: { action: 'getMessages' } }],
|
|
98
|
+
]);
|
|
99
|
+
const response = (await callMethodAsync.call(target, {
|
|
100
|
+
executeFunctions,
|
|
101
|
+
connectionType,
|
|
102
|
+
currentNodeRunIndex: index,
|
|
103
|
+
method: target[prop],
|
|
104
|
+
arguments: [],
|
|
105
|
+
}));
|
|
106
|
+
const payload = { action: 'getMessages', response };
|
|
107
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: payload }]]);
|
|
108
|
+
(0, helpers_1.logAiEvent)(executeFunctions, 'ai-messages-retrieved-from-memory', { response });
|
|
109
|
+
return response;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
else if (prop === 'addMessage' && 'addMessage' in target) {
|
|
113
|
+
return async (message) => {
|
|
114
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiMemory;
|
|
115
|
+
const payload = { action: 'addMessage', message };
|
|
116
|
+
const { index } = executeFunctions.addInputData(connectionType, [[{ json: payload }]]);
|
|
117
|
+
await callMethodAsync.call(target, {
|
|
118
|
+
executeFunctions,
|
|
119
|
+
connectionType,
|
|
120
|
+
currentNodeRunIndex: index,
|
|
121
|
+
method: target[prop],
|
|
122
|
+
arguments: [message],
|
|
123
|
+
});
|
|
124
|
+
(0, helpers_1.logAiEvent)(executeFunctions, 'ai-message-added-to-memory', { message });
|
|
125
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: payload }]]);
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (originalInstance instanceof retrievers_1.BaseRetriever) {
|
|
130
|
+
if (prop === 'getRelevantDocuments' && 'getRelevantDocuments' in target) {
|
|
131
|
+
return async (query, config) => {
|
|
132
|
+
var _a, _b, _c, _d;
|
|
133
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiRetriever;
|
|
134
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
135
|
+
[{ json: { query, config } }],
|
|
136
|
+
]);
|
|
137
|
+
const response = (await callMethodAsync.call(target, {
|
|
138
|
+
executeFunctions,
|
|
139
|
+
connectionType,
|
|
140
|
+
currentNodeRunIndex: index,
|
|
141
|
+
method: target[prop],
|
|
142
|
+
arguments: [query, config],
|
|
143
|
+
}));
|
|
144
|
+
const executionId = (_b = (_a = response[0]) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.executionId;
|
|
145
|
+
const workflowId = (_d = (_c = response[0]) === null || _c === void 0 ? void 0 : _c.metadata) === null || _d === void 0 ? void 0 : _d.workflowId;
|
|
146
|
+
const metadata = {};
|
|
147
|
+
if (executionId && workflowId) {
|
|
148
|
+
metadata.subExecution = {
|
|
149
|
+
executionId,
|
|
150
|
+
workflowId,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
(0, helpers_1.logAiEvent)(executeFunctions, 'ai-documents-retrieved', { query });
|
|
154
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]], metadata);
|
|
155
|
+
return response;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (originalInstance instanceof embeddings_1.Embeddings) {
|
|
160
|
+
if (prop === 'embedDocuments' && 'embedDocuments' in target) {
|
|
161
|
+
return async (documents) => {
|
|
162
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiEmbedding;
|
|
163
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
164
|
+
[{ json: { documents } }],
|
|
165
|
+
]);
|
|
166
|
+
const response = (await callMethodAsync.call(target, {
|
|
167
|
+
executeFunctions,
|
|
168
|
+
connectionType,
|
|
169
|
+
currentNodeRunIndex: index,
|
|
170
|
+
method: target[prop],
|
|
171
|
+
arguments: [documents],
|
|
172
|
+
}));
|
|
173
|
+
(0, helpers_1.logAiEvent)(executeFunctions, 'ai-document-embedded');
|
|
174
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
175
|
+
return response;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (prop === 'embedQuery' && 'embedQuery' in target) {
|
|
179
|
+
return async (query) => {
|
|
180
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiEmbedding;
|
|
181
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
182
|
+
[{ json: { query } }],
|
|
183
|
+
]);
|
|
184
|
+
const response = (await callMethodAsync.call(target, {
|
|
185
|
+
executeFunctions,
|
|
186
|
+
connectionType,
|
|
187
|
+
currentNodeRunIndex: index,
|
|
188
|
+
method: target[prop],
|
|
189
|
+
arguments: [query],
|
|
190
|
+
}));
|
|
191
|
+
(0, helpers_1.logAiEvent)(executeFunctions, 'ai-query-embedded');
|
|
192
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
193
|
+
return response;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (originalInstance instanceof N8nJsonLoader_1.N8nJsonLoader ||
|
|
198
|
+
originalInstance instanceof N8nBinaryLoader_1.N8nBinaryLoader) {
|
|
199
|
+
if (prop === 'processAll' && 'processAll' in target) {
|
|
200
|
+
return async (items) => {
|
|
201
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiDocument;
|
|
202
|
+
const { index } = executeFunctions.addInputData(connectionType, [items]);
|
|
203
|
+
const response = (await callMethodAsync.call(target, {
|
|
204
|
+
executeFunctions,
|
|
205
|
+
connectionType,
|
|
206
|
+
currentNodeRunIndex: index,
|
|
207
|
+
method: target[prop],
|
|
208
|
+
arguments: [items],
|
|
209
|
+
}));
|
|
210
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
211
|
+
return response;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (prop === 'processItem' && 'processItem' in target) {
|
|
215
|
+
return async (item, itemIndex) => {
|
|
216
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiDocument;
|
|
217
|
+
const { index } = executeFunctions.addInputData(connectionType, [[item]]);
|
|
218
|
+
const response = (await callMethodAsync.call(target, {
|
|
219
|
+
executeFunctions,
|
|
220
|
+
connectionType,
|
|
221
|
+
currentNodeRunIndex: index,
|
|
222
|
+
method: target[prop],
|
|
223
|
+
arguments: [item, itemIndex],
|
|
224
|
+
}));
|
|
225
|
+
(0, helpers_1.logAiEvent)(executeFunctions, 'ai-document-processed');
|
|
226
|
+
executeFunctions.addOutputData(connectionType, index, [
|
|
227
|
+
[{ json: { response }, pairedItem: { item: itemIndex } }],
|
|
228
|
+
]);
|
|
229
|
+
return response;
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (originalInstance instanceof textsplitters_1.TextSplitter) {
|
|
234
|
+
if (prop === 'splitText' && 'splitText' in target) {
|
|
235
|
+
return async (text) => {
|
|
236
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiTextSplitter;
|
|
237
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
238
|
+
[{ json: { textSplitter: text } }],
|
|
239
|
+
]);
|
|
240
|
+
const response = (await callMethodAsync.call(target, {
|
|
241
|
+
executeFunctions,
|
|
242
|
+
connectionType,
|
|
243
|
+
currentNodeRunIndex: index,
|
|
244
|
+
method: target[prop],
|
|
245
|
+
arguments: [text],
|
|
246
|
+
}));
|
|
247
|
+
(0, helpers_1.logAiEvent)(executeFunctions, 'ai-text-split');
|
|
248
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
249
|
+
return response;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if ((0, helpers_1.isToolsInstance)(originalInstance)) {
|
|
254
|
+
if (prop === '_call' && '_call' in target) {
|
|
255
|
+
return async (query) => {
|
|
256
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiTool;
|
|
257
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
258
|
+
[{ json: { query } }],
|
|
259
|
+
]);
|
|
260
|
+
const response = (await callMethodAsync.call(target, {
|
|
261
|
+
executeFunctions,
|
|
262
|
+
connectionType,
|
|
263
|
+
currentNodeRunIndex: index,
|
|
264
|
+
method: target[prop],
|
|
265
|
+
arguments: [query],
|
|
266
|
+
}));
|
|
267
|
+
(0, helpers_1.logAiEvent)(executeFunctions, 'ai-tool-called', { query, response });
|
|
268
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
269
|
+
return response;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (originalInstance instanceof vectorstores_1.VectorStore) {
|
|
274
|
+
if (prop === 'similaritySearch' && 'similaritySearch' in target) {
|
|
275
|
+
return async (query, k, filter, _callbacks) => {
|
|
276
|
+
connectionType = n8n_workflow_1.NodeConnectionTypes.AiVectorStore;
|
|
277
|
+
const { index } = executeFunctions.addInputData(connectionType, [
|
|
278
|
+
[{ json: { query, k, filter } }],
|
|
279
|
+
]);
|
|
280
|
+
const response = (await callMethodAsync.call(target, {
|
|
281
|
+
executeFunctions,
|
|
282
|
+
connectionType,
|
|
283
|
+
currentNodeRunIndex: index,
|
|
284
|
+
method: target[prop],
|
|
285
|
+
arguments: [query, k, filter, _callbacks],
|
|
286
|
+
}));
|
|
287
|
+
(0, helpers_1.logAiEvent)(executeFunctions, 'ai-vector-store-searched', { query });
|
|
288
|
+
executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]);
|
|
289
|
+
return response;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return target[prop];
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=logWrapper.js.map
|