From 8f5fe05a9285a275094f08a5e5768366ff42556b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Mon, 28 Oct 2024 11:37:23 +0100 Subject: [PATCH] refactor(core): All calls to supplyData should use a distinct context type (no-changelog) (#11421) --- .../nodes-langchain/nodes/code/Code.node.ts | 22 +- .../DocumentBinaryInputLoader.node.ts | 4 +- .../DocumentDefaultDataLoader.node.ts | 4 +- .../DocumentGithubLoader.node.ts | 4 +- .../DocumentJsonInputLoader.node.ts | 4 +- .../EmbeddingsAwsBedrock.node.ts | 4 +- .../EmbeddingsAzureOpenAi.node.ts | 4 +- .../EmbeddingsCohere/EmbeddingsCohere.node.ts | 4 +- .../EmbeddingsGoogleGemini.node.ts | 4 +- .../EmbeddingsHuggingFaceInference.node.ts | 4 +- .../EmbeddingsMistralCloud.node.ts | 4 +- .../EmbeddingsOllama/EmbeddingsOllama.node.ts | 4 +- .../EmbeddingsOpenAI/EmbeddingsOpenAi.node.ts | 4 +- .../LMChatAnthropic/LmChatAnthropic.node.ts | 4 +- .../llms/LMChatOllama/LmChatOllama.node.ts | 4 +- .../llms/LMChatOpenAi/LmChatOpenAi.node.ts | 4 +- .../nodes/llms/LMCohere/LmCohere.node.ts | 4 +- .../nodes/llms/LMOllama/LmOllama.node.ts | 4 +- .../nodes/llms/LMOpenAi/LmOpenAi.node.ts | 4 +- .../LmOpenHuggingFaceInference.node.ts | 4 +- .../LmChatAwsBedrock/LmChatAwsBedrock.node.ts | 4 +- .../LmChatAzureOpenAi.node.ts | 4 +- .../LmChatGoogleGemini.node.ts | 4 +- .../LmChatGoogleVertex.node.ts | 4 +- .../nodes/llms/LmChatGroq/LmChatGroq.node.ts | 4 +- .../LmChatMistralCloud.node.ts | 4 +- .../nodes/llms/N8nLlmTracing.ts | 11 +- .../MemoryBufferWindow.node.ts | 4 +- .../MemoryMotorhead/MemoryMotorhead.node.ts | 4 +- .../MemoryPostgresChat.node.ts | 9 +- .../MemoryRedisChat/MemoryRedisChat.node.ts | 4 +- .../memory/MemoryXata/MemoryXata.node.ts | 9 +- .../nodes/memory/MemoryZep/MemoryZep.node.ts | 4 +- .../OutputParserAutofixing.node.ts | 9 +- .../OutputParserItemList.node.ts | 4 +- .../OutputParserStructured.node.ts | 4 +- .../RetrieverContextualCompression.node.ts | 4 +- .../RetrieverMultiQuery.node.ts | 4 +- .../RetrieverVectorStore.node.ts | 4 +- .../RetrieverWorkflow.node.ts | 12 +- .../TextSplitterCharacterTextSplitter.node.ts | 4 +- ...tterRecursiveCharacterTextSplitter.node.ts | 4 +- .../TextSplitterTokenSplitter.node.ts | 4 +- .../ToolCalculator/ToolCalculator.node.ts | 4 +- .../nodes/tools/ToolCode/ToolCode.node.ts | 4 +- .../ToolHttpRequest/ToolHttpRequest.node.ts | 4 +- .../nodes/tools/ToolHttpRequest/utils.ts | 20 +- .../tools/ToolSerpApi/ToolSerpApi.node.ts | 4 +- .../ToolVectorStore/ToolVectorStore.node.ts | 9 +- .../tools/ToolWikipedia/ToolWikipedia.node.ts | 4 +- .../ToolWolframAlpha/ToolWolframAlpha.node.ts | 4 +- .../tools/ToolWorkflow/ToolWorkflow.node.ts | 4 +- .../VectorStoreInMemoryLoad.node.ts | 6 +- .../VectorStorePineconeLoad.node.ts | 4 +- .../VectorStoreSupabaseLoad.node.ts | 4 +- .../VectorStoreZepLoad.node.ts | 4 +- .../shared/MemoryVectorStoreManager.ts | 5 +- .../shared/createVectorStoreNode.ts | 15 +- .../nodes-langchain/utils/N8nBinaryLoader.ts | 30 +- .../nodes-langchain/utils/N8nJsonLoader.ts | 23 +- .../@n8n/nodes-langchain/utils/N8nTool.ts | 11 +- .../@n8n/nodes-langchain/utils/helpers.ts | 18 +- .../@n8n/nodes-langchain/utils/logWrapper.ts | 24 +- .../output_parsers/N8nOutputFixingParser.ts | 19 +- .../N8nStructuredOutputParser.ts | 16 +- packages/core/src/NodeExecuteFunctions.ts | 362 ++++++++++++++---- packages/nodes-base/nodes/Code/Sandbox.ts | 12 +- .../nodes-base/nodes/Set/v2/helpers/utils.ts | 9 +- .../nodes-base/nodes/Set/v2/manual.mode.ts | 3 +- packages/workflow/src/Interfaces.ts | 26 +- 70 files changed, 560 insertions(+), 308 deletions(-) diff --git a/packages/@n8n/nodes-langchain/nodes/code/Code.node.ts b/packages/@n8n/nodes-langchain/nodes/code/Code.node.ts index abe9b01530..8708e0c7ea 100644 --- a/packages/@n8n/nodes-langchain/nodes/code/Code.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/code/Code.node.ts @@ -1,13 +1,13 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ -import { - NodeOperationError, - type IExecuteFunctions, - type INodeExecutionData, - type INodeType, - type INodeTypeDescription, - type INodeOutputConfiguration, - type SupplyData, - NodeConnectionType, +import { NodeOperationError, NodeConnectionType } from 'n8n-workflow'; +import type { + IExecuteFunctions, + INodeExecutionData, + INodeType, + INodeTypeDescription, + INodeOutputConfiguration, + SupplyData, + ISupplyDataFunctions, } from 'n8n-workflow'; // TODO: Add support for execute function. Got already started but got commented out @@ -72,7 +72,7 @@ export const vmResolver = makeResolverFromLegacyOptions({ }); function getSandbox( - this: IExecuteFunctions, + this: IExecuteFunctions | ISupplyDataFunctions, code: string, options?: { addItems?: boolean; itemIndex?: number }, ) { @@ -354,7 +354,7 @@ export class Code implements INodeType { } } - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const code = this.getNodeParameter('code', itemIndex) as { supplyData?: { code: string } }; if (!code.supplyData?.code) { diff --git a/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentBinaryInputLoader/DocumentBinaryInputLoader.node.ts b/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentBinaryInputLoader/DocumentBinaryInputLoader.node.ts index 783f12be9d..2e68db4e69 100644 --- a/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentBinaryInputLoader/DocumentBinaryInputLoader.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentBinaryInputLoader/DocumentBinaryInputLoader.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -177,7 +177,7 @@ export class DocumentBinaryInputLoader implements INodeType { ], }; - async supplyData(this: IExecuteFunctions): Promise { + async supplyData(this: ISupplyDataFunctions): Promise { this.logger.debug('Supply Data for Binary Input Loader'); const textSplitter = (await this.getInputConnectionData( NodeConnectionType.AiTextSplitter, diff --git a/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.ts b/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.ts index 062008db2f..5e6457951e 100644 --- a/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -283,7 +283,7 @@ export class DocumentDefaultDataLoader implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const dataType = this.getNodeParameter('dataType', itemIndex, 'json') as 'json' | 'binary'; const textSplitter = (await this.getInputConnectionData( NodeConnectionType.AiTextSplitter, diff --git a/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.ts b/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.ts index 916f0e7159..071134f25e 100644 --- a/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import { GithubRepoLoader } from '@langchain/community/document_loaders/web/github'; @@ -93,7 +93,7 @@ export class DocumentGithubLoader implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { console.log('Supplying data for Github Document Loader'); const repository = this.getNodeParameter('repository', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentJSONInputLoader/DocumentJsonInputLoader.node.ts b/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentJSONInputLoader/DocumentJsonInputLoader.node.ts index 3cb2c4bfdb..2e8cb95a11 100644 --- a/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentJSONInputLoader/DocumentJsonInputLoader.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/document_loaders/DocumentJSONInputLoader/DocumentJsonInputLoader.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -79,7 +79,7 @@ export class DocumentJsonInputLoader implements INodeType { ], }; - async supplyData(this: IExecuteFunctions): Promise { + async supplyData(this: ISupplyDataFunctions): Promise { this.logger.debug('Supply Data for JSON Input Loader'); const textSplitter = (await this.getInputConnectionData( NodeConnectionType.AiTextSplitter, diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAwsBedrock/EmbeddingsAwsBedrock.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAwsBedrock/EmbeddingsAwsBedrock.node.ts index 58caebe05b..6e0782f1c1 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAwsBedrock/EmbeddingsAwsBedrock.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAwsBedrock/EmbeddingsAwsBedrock.node.ts @@ -2,9 +2,9 @@ import { BedrockEmbeddings } from '@langchain/aws'; import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -104,7 +104,7 @@ export class EmbeddingsAwsBedrock implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('aws'); const modelName = this.getNodeParameter('model', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts index 46195be0d3..a75a93c9f4 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -92,7 +92,7 @@ export class EmbeddingsAzureOpenAi implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supply data for embeddings'); const credentials = await this.getCredentials<{ apiKey: string; diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.ts index a6c246acb5..26e5d39b70 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import { CohereEmbeddings } from '@langchain/cohere'; @@ -99,7 +99,7 @@ export class EmbeddingsCohere implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supply data for embeddings Cohere'); const modelName = this.getNodeParameter('modelName', itemIndex, 'embed-english-v2.0') as string; const credentials = await this.getCredentials<{ apiKey: string }>('cohereApi'); diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.ts index 92882dfffa..2a455e4574 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import { GoogleGenerativeAIEmbeddings } from '@langchain/google-genai'; @@ -116,7 +116,7 @@ export class EmbeddingsGoogleGemini implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supply data for embeddings Google Gemini'); const modelName = this.getNodeParameter( 'modelName', diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsHuggingFaceInference/EmbeddingsHuggingFaceInference.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsHuggingFaceInference/EmbeddingsHuggingFaceInference.node.ts index 93d751b9c4..c8317630c3 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsHuggingFaceInference/EmbeddingsHuggingFaceInference.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsHuggingFaceInference/EmbeddingsHuggingFaceInference.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import { HuggingFaceInferenceEmbeddings } from '@langchain/community/embeddings/hf'; @@ -81,7 +81,7 @@ export class EmbeddingsHuggingFaceInference implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supply data for embeddings HF Inference'); const model = this.getNodeParameter( 'modelName', diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.ts index d8223a2ffe..dbfb93b82e 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import type { MistralAIEmbeddingsParams } from '@langchain/mistralai'; @@ -134,7 +134,7 @@ export class EmbeddingsMistralCloud implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('mistralCloudApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; const options = this.getNodeParameter( diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.ts index ec404f2306..d84aa537ec 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import { OllamaEmbeddings } from '@langchain/ollama'; @@ -44,7 +44,7 @@ export class EmbeddingsOllama implements INodeType { properties: [getConnectionHintNoticeField([NodeConnectionType.AiVectorStore]), ollamaModel], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supply data for embeddings Ollama'); const modelName = this.getNodeParameter('model', itemIndex) as string; const credentials = await this.getCredentials('ollamaApi'); diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.ts index 3c40e03203..167581ed2e 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.ts @@ -1,10 +1,10 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, type SupplyData, + type ISupplyDataFunctions, type INodeProperties, } from 'n8n-workflow'; @@ -170,7 +170,7 @@ export class EmbeddingsOpenAi implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supply data for embeddings'); const credentials = await this.getCredentials('openAiApi'); diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.ts index ecc14e1344..416a28b655 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.ts @@ -3,7 +3,7 @@ import { NodeConnectionType, type INodePropertyOptions, type INodeProperties, - type IExecuteFunctions, + type ISupplyDataFunctions, type INodeType, type INodeTypeDescription, type SupplyData, @@ -175,7 +175,7 @@ export class LmChatAnthropic implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('anthropicApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LMChatOllama/LmChatOllama.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LMChatOllama/LmChatOllama.node.ts index b4fc474dd2..dc2f716b2b 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMChatOllama/LmChatOllama.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMChatOllama/LmChatOllama.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -52,7 +52,7 @@ export class LmChatOllama implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('ollamaApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.ts index 3556bca0cf..2e724bf3a7 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, type JsonObject, NodeApiError, @@ -242,7 +242,7 @@ export class LmChatOpenAi implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('openAiApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LMCohere/LmCohere.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LMCohere/LmCohere.node.ts index 191209bb33..6957cd9d9a 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMCohere/LmCohere.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMCohere/LmCohere.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -90,7 +90,7 @@ export class LmCohere implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('cohereApi'); const options = this.getNodeParameter('options', itemIndex, {}) as object; diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LMOllama/LmOllama.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LMOllama/LmOllama.node.ts index 5492a51a97..f71708cbca 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMOllama/LmOllama.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMOllama/LmOllama.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -51,7 +51,7 @@ export class LmOllama implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('ollamaApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LMOpenAi/LmOpenAi.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LMOpenAi/LmOpenAi.node.ts index a46ad429a2..5fb9be937e 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMOpenAi/LmOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMOpenAi/LmOpenAi.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType } from 'n8n-workflow'; import type { - IExecuteFunctions, INodeType, INodeTypeDescription, + ISupplyDataFunctions, SupplyData, ILoadOptionsFunctions, } from 'n8n-workflow'; @@ -229,7 +229,7 @@ export class LmOpenAi implements INodeType { }, }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('openAiApi'); const modelName = this.getNodeParameter('model', itemIndex, '', { diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LMOpenHuggingFaceInference/LmOpenHuggingFaceInference.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LMOpenHuggingFaceInference/LmOpenHuggingFaceInference.node.ts index 7b2c821f9c..ddf8065bf6 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMOpenHuggingFaceInference/LmOpenHuggingFaceInference.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMOpenHuggingFaceInference/LmOpenHuggingFaceInference.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -132,7 +132,7 @@ export class LmOpenHuggingFaceInference implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('huggingFaceApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.ts index c7b3d8ad95..b4eafde76e 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.ts @@ -2,9 +2,9 @@ import { ChatBedrockConverse } from '@langchain/aws'; import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -132,7 +132,7 @@ export class LmChatAwsBedrock implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('aws'); const modelName = this.getNodeParameter('model', itemIndex) as string; const options = this.getNodeParameter('options', itemIndex, {}) as { diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts index 03548142db..55a5afb7ce 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -162,7 +162,7 @@ export class LmChatAzureOpenAi implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials<{ apiKey: string; resourceName: string; diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.ts index ce08a650f2..44691a47ef 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import { ChatGoogleGenerativeAI } from '@langchain/google-genai'; @@ -113,7 +113,7 @@ export class LmChatGoogleGemini implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('googlePalmApi'); const modelName = this.getNodeParameter('modelName', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleVertex/LmChatGoogleVertex.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleVertex/LmChatGoogleVertex.node.ts index 55ccda90d2..a9a01ebf1b 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleVertex/LmChatGoogleVertex.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleVertex/LmChatGoogleVertex.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, type ILoadOptionsFunctions, type JsonObject, @@ -124,7 +124,7 @@ export class LmChatGoogleVertex implements INodeType { }, }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('googleApi'); const privateKey = formatPrivateKey(credentials.privateKey as string); const email = (credentials.email as string).trim(); diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LmChatGroq/LmChatGroq.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LmChatGroq/LmChatGroq.node.ts index d0a28715e1..3588cf0cc3 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatGroq/LmChatGroq.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatGroq/LmChatGroq.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -129,7 +129,7 @@ export class LmChatGroq implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('groqApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.ts index 129beeadfe..5ff28bd30d 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -172,7 +172,7 @@ export class LmChatMistralCloud implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('mistralCloudApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/llms/N8nLlmTracing.ts b/packages/@n8n/nodes-langchain/nodes/llms/N8nLlmTracing.ts index a0f47677f7..660bf3b0a9 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/N8nLlmTracing.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/N8nLlmTracing.ts @@ -7,7 +7,7 @@ import type { SerializedSecret, } from '@langchain/core/load/serializable'; import type { LLMResult } from '@langchain/core/outputs'; -import type { IDataObject, IExecuteFunctions } from 'n8n-workflow'; +import type { IDataObject, ISupplyDataFunctions } from 'n8n-workflow'; import { NodeConnectionType } from 'n8n-workflow'; import { pick } from 'lodash'; import type { BaseMessage } from '@langchain/core/messages'; @@ -30,8 +30,6 @@ const TIKTOKEN_ESTIMATE_MODEL = 'gpt-4o'; export class N8nLlmTracing extends BaseCallbackHandler { name = 'N8nLlmTracing'; - executionFunctions: IExecuteFunctions; - connectionType = NodeConnectionType.AiLanguageModel; promptTokensEstimate = 0; @@ -61,11 +59,10 @@ export class N8nLlmTracing extends BaseCallbackHandler { }; constructor( - executionFunctions: IExecuteFunctions, + private executionFunctions: ISupplyDataFunctions, options?: { tokensUsageParser: TokensUsageParser }, ) { super(); - this.executionFunctions = executionFunctions; this.options = { ...this.options, ...options }; } @@ -138,7 +135,7 @@ export class N8nLlmTracing extends BaseCallbackHandler { this.executionFunctions.addOutputData(this.connectionType, runDetails.index, [ [{ json: { ...response } }], ]); - void logAiEvent(this.executionFunctions, 'ai-llm-generated-output', { + logAiEvent(this.executionFunctions, 'ai-llm-generated-output', { messages: parsedMessages, options: runDetails.options, response, @@ -186,7 +183,7 @@ export class N8nLlmTracing extends BaseCallbackHandler { }); } - void logAiEvent(this.executionFunctions, 'ai-llm-errored', { + logAiEvent(this.executionFunctions, 'ai-llm-errored', { error: Object.keys(error).length === 0 ? error.toString() : error, runId, parentRunId, diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts index b8eea7a5e2..fae6927c25 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import type { BufferWindowMemoryInput } from 'langchain/memory'; @@ -134,7 +134,7 @@ export class MemoryBufferWindow implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const contextWindowLength = this.getNodeParameter('contextWindowLength', itemIndex) as number; const workflowId = this.getWorkflow().id; const memoryInstance = MemoryChatBufferSingleton.getInstance(); diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryMotorhead/MemoryMotorhead.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryMotorhead/MemoryMotorhead.node.ts index 9b2f46fb30..7f8d88fbaf 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryMotorhead/MemoryMotorhead.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryMotorhead/MemoryMotorhead.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -86,7 +86,7 @@ export class MemoryMotorhead implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('motorheadApi'); const nodeVersion = this.getNode().typeVersion; diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts index f42cb93fe1..f51b76fb18 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts @@ -1,5 +1,10 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ -import type { IExecuteFunctions, INodeType, INodeTypeDescription, SupplyData } from 'n8n-workflow'; +import type { + ISupplyDataFunctions, + INodeType, + INodeTypeDescription, + SupplyData, +} from 'n8n-workflow'; import { NodeConnectionType } from 'n8n-workflow'; import { BufferMemory, BufferWindowMemory } from 'langchain/memory'; import { PostgresChatMessageHistory } from '@langchain/community/stores/message/postgres'; @@ -73,7 +78,7 @@ export class MemoryPostgresChat implements INodeType { }, }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('postgres'); const tableName = this.getNodeParameter('tableName', itemIndex, 'n8n_chat_histories') as string; const sessionId = getSessionId(this, itemIndex); diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts index da57ede1d2..01a31458de 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeOperationError, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, NodeConnectionType, } from 'n8n-workflow'; @@ -102,7 +102,7 @@ export class MemoryRedisChat implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('redis'); const nodeVersion = this.getNode().typeVersion; diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryXata/MemoryXata.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryXata/MemoryXata.node.ts index f0177d9e75..be431b9b3c 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryXata/MemoryXata.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryXata/MemoryXata.node.ts @@ -1,6 +1,11 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; -import type { IExecuteFunctions, INodeType, INodeTypeDescription, SupplyData } from 'n8n-workflow'; +import type { + ISupplyDataFunctions, + INodeType, + INodeTypeDescription, + SupplyData, +} from 'n8n-workflow'; import { XataChatMessageHistory } from '@langchain/community/stores/message/xata'; import { BufferMemory, BufferWindowMemory } from 'langchain/memory'; import { BaseClient } from '@xata.io/client'; @@ -88,7 +93,7 @@ export class MemoryXata implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('xataApi'); const nodeVersion = this.getNode().typeVersion; diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryZep/MemoryZep.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryZep/MemoryZep.node.ts index 7cbf1da574..20e70fd920 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryZep/MemoryZep.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryZep/MemoryZep.node.ts @@ -1,7 +1,7 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, + type ISupplyDataFunctions, type INodeType, type INodeTypeDescription, type SupplyData, @@ -103,7 +103,7 @@ export class MemoryZep implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials<{ apiKey?: string; apiUrl?: string; diff --git a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts index 7d676c7607..d4743fb043 100644 --- a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts @@ -1,6 +1,11 @@ import type { BaseLanguageModel } from '@langchain/core/language_models/base'; import { NodeConnectionType } from 'n8n-workflow'; -import type { IExecuteFunctions, INodeType, INodeTypeDescription, SupplyData } from 'n8n-workflow'; +import type { + ISupplyDataFunctions, + INodeType, + INodeTypeDescription, + SupplyData, +} from 'n8n-workflow'; import { N8nOutputFixingParser, @@ -63,7 +68,7 @@ export class OutputParserAutofixing implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const model = (await this.getInputConnectionData( NodeConnectionType.AiLanguageModel, itemIndex, diff --git a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserItemList/OutputParserItemList.node.ts b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserItemList/OutputParserItemList.node.ts index cb67afb453..b613c14775 100644 --- a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserItemList/OutputParserItemList.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserItemList/OutputParserItemList.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -80,7 +80,7 @@ export class OutputParserItemList implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const options = this.getNodeParameter('options', itemIndex, {}) as { numberOfItems?: number; separator?: string; diff --git a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.ts b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.ts index b5b6a5846c..c35cb1d145 100644 --- a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.ts @@ -1,9 +1,9 @@ import type { JSONSchema7 } from 'json-schema'; import { jsonParse, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, NodeOperationError, NodeConnectionType, @@ -122,7 +122,7 @@ export class OutputParserStructured implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const schemaType = this.getNodeParameter('schemaType', itemIndex, '') as 'fromJson' | 'manual'; // We initialize these even though one of them will always be empty // it makes it easer to navigate the ternary operator diff --git a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.ts b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.ts index 5b89a0bf26..8017caa1ad 100644 --- a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -63,7 +63,7 @@ export class RetrieverContextualCompression implements INodeType { properties: [], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supplying data for Contextual Compression Retriever'); const model = (await this.getInputConnectionData( diff --git a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.ts b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.ts index 3cb377d654..f814ba875e 100644 --- a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; @@ -82,7 +82,7 @@ export class RetrieverMultiQuery implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supplying data for MultiQuery Retriever'); const options = this.getNodeParameter('options', itemIndex, {}) as { queryCount?: number }; diff --git a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.ts b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.ts index 6543d061d4..5e79a6a754 100644 --- a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import type { VectorStore } from '@langchain/core/vectorstores'; @@ -56,7 +56,7 @@ export class RetrieverVectorStore implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supplying data for Vector Store Retriever'); const topK = this.getNodeParameter('topK', itemIndex, 4) as number; diff --git a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverWorkflow/RetrieverWorkflow.node.ts b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverWorkflow/RetrieverWorkflow.node.ts index 6b446149fc..0aafabf1d4 100644 --- a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverWorkflow/RetrieverWorkflow.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverWorkflow/RetrieverWorkflow.node.ts @@ -5,7 +5,7 @@ import type { IExecuteWorkflowInfo, INodeExecutionData, IWorkflowBase, - IExecuteFunctions, + ISupplyDataFunctions, INodeType, INodeTypeDescription, SupplyData, @@ -292,15 +292,15 @@ export class RetrieverWorkflow implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { class WorkflowRetriever extends BaseRetriever { lc_namespace = ['n8n-nodes-langchain', 'retrievers', 'workflow']; - executeFunctions: IExecuteFunctions; - - constructor(executeFunctions: IExecuteFunctions, fields: BaseRetrieverInput) { + constructor( + private executeFunctions: ISupplyDataFunctions, + fields: BaseRetrieverInput, + ) { super(fields); - this.executeFunctions = executeFunctions; } async _getRelevantDocuments( diff --git a/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterCharacterTextSplitter/TextSplitterCharacterTextSplitter.node.ts b/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterCharacterTextSplitter/TextSplitterCharacterTextSplitter.node.ts index 61e62def0f..f62e8f01f1 100644 --- a/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterCharacterTextSplitter/TextSplitterCharacterTextSplitter.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterCharacterTextSplitter/TextSplitterCharacterTextSplitter.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import type { CharacterTextSplitterParams } from '@langchain/textsplitters'; @@ -63,7 +63,7 @@ export class TextSplitterCharacterTextSplitter implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supply Data for Text Splitter'); const separator = this.getNodeParameter('separator', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterRecursiveCharacterTextSplitter/TextSplitterRecursiveCharacterTextSplitter.node.ts b/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterRecursiveCharacterTextSplitter/TextSplitterRecursiveCharacterTextSplitter.node.ts index 4d2c5a6ec8..21a0520766 100644 --- a/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterRecursiveCharacterTextSplitter/TextSplitterRecursiveCharacterTextSplitter.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterRecursiveCharacterTextSplitter/TextSplitterRecursiveCharacterTextSplitter.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import type { @@ -94,7 +94,7 @@ export class TextSplitterRecursiveCharacterTextSplitter implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supply Data for Text Splitter'); const chunkSize = this.getNodeParameter('chunkSize', itemIndex) as number; diff --git a/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.ts b/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.ts index c021aa1df7..247d142fa8 100644 --- a/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import { TokenTextSplitter } from '@langchain/textsplitters'; @@ -56,7 +56,7 @@ export class TextSplitterTokenSplitter implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supply Data for Text Splitter'); const chunkSize = this.getNodeParameter('chunkSize', itemIndex) as number; diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolCalculator/ToolCalculator.node.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolCalculator/ToolCalculator.node.ts index f37a3176a4..f50a6216c0 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolCalculator/ToolCalculator.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolCalculator/ToolCalculator.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import { Calculator } from '@langchain/community/tools/calculator'; @@ -43,7 +43,7 @@ export class ToolCalculator implements INodeType { properties: [getConnectionHintNoticeField([NodeConnectionType.AiAgent])], }; - async supplyData(this: IExecuteFunctions): Promise { + async supplyData(this: ISupplyDataFunctions): Promise { return { response: logWrapper(new Calculator(), this), }; diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolCode/ToolCode.node.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolCode/ToolCode.node.ts index 2a2a635c90..1491662e61 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolCode/ToolCode.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolCode/ToolCode.node.ts @@ -6,9 +6,9 @@ import { PythonSandbox } from 'n8n-nodes-base/dist/nodes/Code/PythonSandbox'; import type { Sandbox } from 'n8n-nodes-base/dist/nodes/Code/Sandbox'; import { getSandboxContext } from 'n8n-nodes-base/dist/nodes/Code/Sandbox'; import type { - IExecuteFunctions, INodeType, INodeTypeDescription, + ISupplyDataFunctions, SupplyData, ExecutionError, IDataObject, @@ -175,7 +175,7 @@ export class ToolCode implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const node = this.getNode(); const workflowMode = this.getMode(); diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/ToolHttpRequest.node.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/ToolHttpRequest.node.ts index 2fbac43474..f279c1e751 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/ToolHttpRequest.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/ToolHttpRequest.node.ts @@ -1,8 +1,8 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import type { - IExecuteFunctions, INodeType, INodeTypeDescription, + ISupplyDataFunctions, SupplyData, IHttpRequestMethods, IHttpRequestOptions, @@ -250,7 +250,7 @@ export class ToolHttpRequest implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const name = this.getNode().name.replace(/ /g, '_'); try { tryToParseAlphanumericString(name); diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/utils.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/utils.ts index cd12ac00eb..74f40f0a02 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/utils.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/utils.ts @@ -8,12 +8,12 @@ import unset from 'lodash/unset'; import * as mime from 'mime-types'; import { getOAuth2AdditionalParameters } from 'n8n-nodes-base/dist/nodes/HttpRequest/GenericFunctions'; import type { - IExecuteFunctions, IDataObject, IHttpRequestOptions, IRequestOptionsSimplified, ExecutionError, NodeApiError, + ISupplyDataFunctions, } from 'n8n-workflow'; import { NodeConnectionType, NodeOperationError, jsonParse } from 'n8n-workflow'; import { z } from 'zod'; @@ -28,7 +28,7 @@ import type { } from './interfaces'; import type { DynamicZodObject } from '../../../types/zod.types'; -const genericCredentialRequest = async (ctx: IExecuteFunctions, itemIndex: number) => { +const genericCredentialRequest = async (ctx: ISupplyDataFunctions, itemIndex: number) => { const genericType = ctx.getNodeParameter('genericAuthType', itemIndex) as string; if (genericType === 'httpBasicAuth' || genericType === 'httpDigestAuth') { @@ -104,7 +104,7 @@ const genericCredentialRequest = async (ctx: IExecuteFunctions, itemIndex: numbe }); }; -const predefinedCredentialRequest = async (ctx: IExecuteFunctions, itemIndex: number) => { +const predefinedCredentialRequest = async (ctx: ISupplyDataFunctions, itemIndex: number) => { const predefinedType = ctx.getNodeParameter('nodeCredentialType', itemIndex) as string; const additionalOptions = getOAuth2AdditionalParameters(predefinedType); @@ -119,7 +119,7 @@ const predefinedCredentialRequest = async (ctx: IExecuteFunctions, itemIndex: nu }; export const configureHttpRequestFunction = async ( - ctx: IExecuteFunctions, + ctx: ISupplyDataFunctions, credentialsType: 'predefinedCredentialType' | 'genericCredentialType' | 'none', itemIndex: number, ) => { @@ -146,7 +146,7 @@ const defaultOptimizer = (response: T) => { return String(response); }; -const htmlOptimizer = (ctx: IExecuteFunctions, itemIndex: number, maxLength: number) => { +const htmlOptimizer = (ctx: ISupplyDataFunctions, itemIndex: number, maxLength: number) => { const cssSelector = ctx.getNodeParameter('cssSelector', itemIndex, '') as string; const onlyContent = ctx.getNodeParameter('onlyContent', itemIndex, false) as boolean; let elementsToOmit: string[] = []; @@ -214,7 +214,7 @@ const htmlOptimizer = (ctx: IExecuteFunctions, itemIndex: number, maxLength: num }; }; -const textOptimizer = (ctx: IExecuteFunctions, itemIndex: number, maxLength: number) => { +const textOptimizer = (ctx: ISupplyDataFunctions, itemIndex: number, maxLength: number) => { return (response: string | IDataObject) => { if (typeof response === 'object') { try { @@ -245,7 +245,7 @@ const textOptimizer = (ctx: IExecuteFunctions, itemIndex: number, maxLength: num }; }; -const jsonOptimizer = (ctx: IExecuteFunctions, itemIndex: number) => { +const jsonOptimizer = (ctx: ISupplyDataFunctions, itemIndex: number) => { return (response: string): string => { let responseData: IDataObject | IDataObject[] | string = response; @@ -324,7 +324,7 @@ const jsonOptimizer = (ctx: IExecuteFunctions, itemIndex: number) => { }; }; -export const configureResponseOptimizer = (ctx: IExecuteFunctions, itemIndex: number) => { +export const configureResponseOptimizer = (ctx: ISupplyDataFunctions, itemIndex: number) => { const optimizeResponse = ctx.getNodeParameter('optimizeResponse', itemIndex, false) as boolean; if (optimizeResponse) { @@ -469,7 +469,7 @@ const MODEL_INPUT_DESCRIPTION = { }; export const updateParametersAndOptions = (options: { - ctx: IExecuteFunctions; + ctx: ISupplyDataFunctions; itemIndex: number; toolParameters: ToolParameter[]; placeholdersDefinitions: PlaceholderDefinition[]; @@ -558,7 +558,7 @@ export const prepareToolDescription = ( }; export const configureToolFunction = ( - ctx: IExecuteFunctions, + ctx: ISupplyDataFunctions, itemIndex: number, toolParameters: ToolParameter[], requestOptions: IHttpRequestOptions, diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolSerpApi/ToolSerpApi.node.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolSerpApi/ToolSerpApi.node.ts index c08553b96e..709b06b7ac 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolSerpApi/ToolSerpApi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolSerpApi/ToolSerpApi.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import { SerpAPI } from '@langchain/community/tools/serpapi'; @@ -113,7 +113,7 @@ export class ToolSerpApi implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const credentials = await this.getCredentials('serpApi'); const options = this.getNodeParameter('options', itemIndex) as object; diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolVectorStore/ToolVectorStore.node.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolVectorStore/ToolVectorStore.node.ts index b4ea7c3321..b4016f06ca 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolVectorStore/ToolVectorStore.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolVectorStore/ToolVectorStore.node.ts @@ -1,4 +1,9 @@ -import type { IExecuteFunctions, INodeType, INodeTypeDescription, SupplyData } from 'n8n-workflow'; +import type { + INodeType, + INodeTypeDescription, + ISupplyDataFunctions, + SupplyData, +} from 'n8n-workflow'; import { NodeConnectionType } from 'n8n-workflow'; import { VectorStoreQATool } from 'langchain/tools'; @@ -82,7 +87,7 @@ export class ToolVectorStore implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const name = this.getNodeParameter('name', itemIndex) as string; const toolDescription = this.getNodeParameter('description', itemIndex) as string; const topK = this.getNodeParameter('topK', itemIndex, 4) as number; diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolWikipedia/ToolWikipedia.node.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolWikipedia/ToolWikipedia.node.ts index 0b3aeaff74..e462e38feb 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolWikipedia/ToolWikipedia.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolWikipedia/ToolWikipedia.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import { WikipediaQueryRun } from '@langchain/community/tools/wikipedia_query_run'; @@ -43,7 +43,7 @@ export class ToolWikipedia implements INodeType { properties: [getConnectionHintNoticeField([NodeConnectionType.AiAgent])], }; - async supplyData(this: IExecuteFunctions): Promise { + async supplyData(this: ISupplyDataFunctions): Promise { const WikiTool = new WikipediaQueryRun(); WikiTool.description = diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.ts index 3a1f7ea2cc..93290e63ad 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.ts @@ -1,9 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import { WolframAlphaTool } from '@langchain/community/tools/wolframalpha'; @@ -49,7 +49,7 @@ export class ToolWolframAlpha implements INodeType { properties: [getConnectionHintNoticeField([NodeConnectionType.AiAgent])], }; - async supplyData(this: IExecuteFunctions): Promise { + async supplyData(this: ISupplyDataFunctions): Promise { const credentials = await this.getCredentials('wolframAlphaApi'); return { diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/ToolWorkflow.node.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/ToolWorkflow.node.ts index 6cc983eae4..f912e162d9 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/ToolWorkflow.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/ToolWorkflow.node.ts @@ -6,12 +6,12 @@ import isObject from 'lodash/isObject'; import type { SetField, SetNodeOptions } from 'n8n-nodes-base/dist/nodes/Set/v2/helpers/interfaces'; import * as manual from 'n8n-nodes-base/dist/nodes/Set/v2/manual.mode'; import type { - IExecuteFunctions, IExecuteWorkflowInfo, INodeExecutionData, INodeType, INodeTypeDescription, IWorkflowBase, + ISupplyDataFunctions, SupplyData, ExecutionError, IDataObject, @@ -357,7 +357,7 @@ export class ToolWorkflow implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const name = this.getNodeParameter('name', itemIndex) as string; const description = this.getNodeParameter('description', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemoryLoad/VectorStoreInMemoryLoad.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemoryLoad/VectorStoreInMemoryLoad.node.ts index c85a245073..7bf48c3d8c 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemoryLoad/VectorStoreInMemoryLoad.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemoryLoad/VectorStoreInMemoryLoad.node.ts @@ -1,10 +1,10 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ import { NodeConnectionType, - type SupplyData, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, + type SupplyData, } from 'n8n-workflow'; import type { Embeddings } from '@langchain/core/embeddings'; import { MemoryVectorStoreManager } from '../shared/MemoryVectorStoreManager'; @@ -59,7 +59,7 @@ export class VectorStoreInMemoryLoad implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const embeddings = (await this.getInputConnectionData( NodeConnectionType.AiEmbedding, itemIndex, diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePineconeLoad/VectorStorePineconeLoad.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePineconeLoad/VectorStorePineconeLoad.node.ts index 7cae9c9d85..d46bccd9f7 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePineconeLoad/VectorStorePineconeLoad.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePineconeLoad/VectorStorePineconeLoad.node.ts @@ -1,8 +1,8 @@ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import type { PineconeStoreParams } from '@langchain/pinecone'; @@ -84,7 +84,7 @@ export class VectorStorePineconeLoad implements INodeType { }, }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supplying data for Pinecone Load Vector Store'); const namespace = this.getNodeParameter('pineconeNamespace', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabaseLoad/VectorStoreSupabaseLoad.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabaseLoad/VectorStoreSupabaseLoad.node.ts index bae6d0e1a9..f4bdc49e44 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabaseLoad/VectorStoreSupabaseLoad.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabaseLoad/VectorStoreSupabaseLoad.node.ts @@ -1,7 +1,7 @@ import { - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, NodeConnectionType, } from 'n8n-workflow'; @@ -81,7 +81,7 @@ export class VectorStoreSupabaseLoad implements INodeType { methods = { listSearch: { supabaseTableNameSearch } }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supply Supabase Load Vector Store'); const tableName = this.getNodeParameter('tableName', itemIndex, '', { diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepLoad/VectorStoreZepLoad.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepLoad/VectorStoreZepLoad.node.ts index 244c0a9843..dd30a0808e 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepLoad/VectorStoreZepLoad.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepLoad/VectorStoreZepLoad.node.ts @@ -1,8 +1,8 @@ import { NodeConnectionType, - type IExecuteFunctions, type INodeType, type INodeTypeDescription, + type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; import type { IZepConfig } from '@langchain/community/vectorstores/zep'; @@ -83,7 +83,7 @@ export class VectorStoreZepLoad implements INodeType { ], }; - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { this.logger.debug('Supplying data for Zep Load Vector Store'); const collectionName = this.getNodeParameter('collectionName', itemIndex) as string; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/MemoryVectorStoreManager.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/MemoryVectorStoreManager.ts index 806a5129c5..1076fb93ba 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/MemoryVectorStoreManager.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/MemoryVectorStoreManager.ts @@ -7,11 +7,8 @@ export class MemoryVectorStoreManager { private vectorStoreBuffer: Map; - private embeddings: Embeddings; - - private constructor(embeddings: Embeddings) { + private constructor(private embeddings: Embeddings) { this.vectorStoreBuffer = new Map(); - this.embeddings = embeddings; } public static getInstance(embeddings: Embeddings): MemoryVectorStoreManager { diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/createVectorStoreNode.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/createVectorStoreNode.ts index 45d28542d7..2de9304fc5 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/createVectorStoreNode.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/createVectorStoreNode.ts @@ -5,12 +5,13 @@ import type { Embeddings } from '@langchain/core/embeddings'; import type { VectorStore } from '@langchain/core/vectorstores'; import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; import type { + IExecuteFunctions, INodeCredentialDescription, INodeProperties, INodeExecutionData, - IExecuteFunctions, INodeTypeDescription, SupplyData, + ISupplyDataFunctions, INodeType, ILoadOptionsFunctions, INodeListSearchResult, @@ -57,13 +58,13 @@ interface VectorStoreNodeConstructorArgs { retrieveFields?: INodeProperties[]; updateFields?: INodeProperties[]; populateVectorStore: ( - context: IExecuteFunctions, + context: ISupplyDataFunctions, embeddings: Embeddings, documents: Array>>, itemIndex: number, ) => Promise; getVectorStoreClient: ( - context: IExecuteFunctions, + context: ISupplyDataFunctions, filter: Record | undefined, embeddings: Embeddings, itemIndex: number, @@ -281,7 +282,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) => }); resultData.push(...serializedDocs); - void logAiEvent(this, 'ai-vector-store-searched', { query: prompt }); + logAiEvent(this, 'ai-vector-store-searched', { query: prompt }); } return [resultData]; @@ -311,7 +312,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) => try { await args.populateVectorStore(this, embeddings, processedDocuments, itemIndex); - void logAiEvent(this, 'ai-vector-store-populated'); + logAiEvent(this, 'ai-vector-store-populated'); } catch (error) { throw error; } @@ -365,7 +366,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) => ids: [documentId], }); - void logAiEvent(this, 'ai-vector-store-updated'); + logAiEvent(this, 'ai-vector-store-updated'); } catch (error) { throw error; } @@ -380,7 +381,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) => ); } - async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { + async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise { const mode = this.getNodeParameter('mode', 0) as 'load' | 'insert' | 'retrieve'; const filter = getMetadataFiltersValues(this, itemIndex); const embeddings = (await this.getInputConnectionData( diff --git a/packages/@n8n/nodes-langchain/utils/N8nBinaryLoader.ts b/packages/@n8n/nodes-langchain/utils/N8nBinaryLoader.ts index 491bb03e28..53f4f95a74 100644 --- a/packages/@n8n/nodes-langchain/utils/N8nBinaryLoader.ts +++ b/packages/@n8n/nodes-langchain/utils/N8nBinaryLoader.ts @@ -1,6 +1,11 @@ import { pipeline } from 'stream/promises'; import { createWriteStream } from 'fs'; -import type { IBinaryData, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; +import type { + IBinaryData, + IExecuteFunctions, + INodeExecutionData, + ISupplyDataFunctions, +} from 'n8n-workflow'; import { NodeOperationError, BINARY_ENCODING } from 'n8n-workflow'; import type { TextSplitter } from '@langchain/textsplitters'; @@ -26,25 +31,12 @@ const SUPPORTED_MIME_TYPES = { }; export class N8nBinaryLoader { - private context: IExecuteFunctions; - - private optionsPrefix: string; - - private binaryDataKey: string; - - private textSplitter?: TextSplitter; - constructor( - context: IExecuteFunctions, - optionsPrefix = '', - binaryDataKey = '', - textSplitter?: TextSplitter, - ) { - this.context = context; - this.textSplitter = textSplitter; - this.optionsPrefix = optionsPrefix; - this.binaryDataKey = binaryDataKey; - } + private context: IExecuteFunctions | ISupplyDataFunctions, + private optionsPrefix = '', + private binaryDataKey = '', + private textSplitter?: TextSplitter, + ) {} async processAll(items?: INodeExecutionData[]): Promise { const docs: Document[] = []; diff --git a/packages/@n8n/nodes-langchain/utils/N8nJsonLoader.ts b/packages/@n8n/nodes-langchain/utils/N8nJsonLoader.ts index 6cc4862d22..7c44d8a8f9 100644 --- a/packages/@n8n/nodes-langchain/utils/N8nJsonLoader.ts +++ b/packages/@n8n/nodes-langchain/utils/N8nJsonLoader.ts @@ -1,4 +1,9 @@ -import { type IExecuteFunctions, type INodeExecutionData, NodeOperationError } from 'n8n-workflow'; +import { + type IExecuteFunctions, + type INodeExecutionData, + type ISupplyDataFunctions, + NodeOperationError, +} from 'n8n-workflow'; import type { TextSplitter } from '@langchain/textsplitters'; import type { Document } from '@langchain/core/documents'; @@ -7,17 +12,11 @@ import { TextLoader } from 'langchain/document_loaders/fs/text'; import { getMetadataFiltersValues } from './helpers'; export class N8nJsonLoader { - private context: IExecuteFunctions; - - private optionsPrefix: string; - - private textSplitter?: TextSplitter; - - constructor(context: IExecuteFunctions, optionsPrefix = '', textSplitter?: TextSplitter) { - this.context = context; - this.textSplitter = textSplitter; - this.optionsPrefix = optionsPrefix; - } + constructor( + private context: IExecuteFunctions | ISupplyDataFunctions, + private optionsPrefix = '', + private textSplitter?: TextSplitter, + ) {} async processAll(items?: INodeExecutionData[]): Promise { const docs: Document[] = []; diff --git a/packages/@n8n/nodes-langchain/utils/N8nTool.ts b/packages/@n8n/nodes-langchain/utils/N8nTool.ts index bb8bab08bd..2cb89630f0 100644 --- a/packages/@n8n/nodes-langchain/utils/N8nTool.ts +++ b/packages/@n8n/nodes-langchain/utils/N8nTool.ts @@ -1,6 +1,6 @@ import type { DynamicStructuredToolInput } from '@langchain/core/tools'; import { DynamicStructuredTool, DynamicTool } from '@langchain/core/tools'; -import type { IExecuteFunctions, IDataObject } from 'n8n-workflow'; +import type { ISupplyDataFunctions, IDataObject } from 'n8n-workflow'; import { NodeConnectionType, jsonParse, NodeOperationError } from 'n8n-workflow'; import { StructuredOutputParser } from 'langchain/output_parsers'; import type { ZodTypeAny } from 'zod'; @@ -45,12 +45,11 @@ ALL parameters marked as required must be provided`; }; export class N8nTool extends DynamicStructuredTool { - private context: IExecuteFunctions; - - constructor(context: IExecuteFunctions, fields: DynamicStructuredToolInput) { + constructor( + private context: ISupplyDataFunctions, + fields: DynamicStructuredToolInput, + ) { super(fields); - - this.context = context; } asDynamicTool(): DynamicTool { diff --git a/packages/@n8n/nodes-langchain/utils/helpers.ts b/packages/@n8n/nodes-langchain/utils/helpers.ts index a760c32ba8..f1e02e9c9f 100644 --- a/packages/@n8n/nodes-langchain/utils/helpers.ts +++ b/packages/@n8n/nodes-langchain/utils/helpers.ts @@ -5,7 +5,13 @@ import type { BaseMessage } from '@langchain/core/messages'; import type { Tool } from '@langchain/core/tools'; import type { BaseChatMemory } from 'langchain/memory'; import { NodeConnectionType, NodeOperationError, jsonStringify } from 'n8n-workflow'; -import type { AiEvent, IDataObject, IExecuteFunctions, IWebhookFunctions } from 'n8n-workflow'; +import type { + AiEvent, + IDataObject, + IExecuteFunctions, + ISupplyDataFunctions, + IWebhookFunctions, +} from 'n8n-workflow'; import { N8nTool } from './N8nTool'; @@ -20,7 +26,7 @@ function hasMethods(obj: unknown, ...methodNames: Array): ob } export function getMetadataFiltersValues( - ctx: IExecuteFunctions, + ctx: IExecuteFunctions | ISupplyDataFunctions, itemIndex: number, ): Record | undefined { const options = ctx.getNodeParameter('options', itemIndex, {}); @@ -93,7 +99,7 @@ export function getPromptInputByType(options: { } export function getSessionId( - ctx: IExecuteFunctions | IWebhookFunctions, + ctx: ISupplyDataFunctions | IWebhookFunctions, itemIndex: number, selectorKey = 'sessionIdType', autoSelect = 'fromInput', @@ -133,13 +139,13 @@ export function getSessionId( return sessionId; } -export async function logAiEvent( - executeFunctions: IExecuteFunctions, +export function logAiEvent( + executeFunctions: IExecuteFunctions | ISupplyDataFunctions, event: AiEvent, data?: IDataObject, ) { try { - await executeFunctions.logAiEvent(event, data ? jsonStringify(data) : undefined); + executeFunctions.logAiEvent(event, data ? jsonStringify(data) : undefined); } catch (error) { executeFunctions.logger.debug(`Error logging AI event: ${event}`); } diff --git a/packages/@n8n/nodes-langchain/utils/logWrapper.ts b/packages/@n8n/nodes-langchain/utils/logWrapper.ts index c1ecd1799c..eca1431a4b 100644 --- a/packages/@n8n/nodes-langchain/utils/logWrapper.ts +++ b/packages/@n8n/nodes-langchain/utils/logWrapper.ts @@ -10,7 +10,7 @@ import type { Tool } from '@langchain/core/tools'; import { VectorStore } from '@langchain/core/vectorstores'; import { TextSplitter } from '@langchain/textsplitters'; import type { BaseDocumentLoader } from 'langchain/dist/document_loaders/base'; -import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; +import type { IExecuteFunctions, INodeExecutionData, ISupplyDataFunctions } from 'n8n-workflow'; import { NodeOperationError, NodeConnectionType } from 'n8n-workflow'; import { logAiEvent, isToolsInstance, isBaseChatMemory, isBaseChatMessageHistory } from './helpers'; @@ -27,7 +27,7 @@ const errorsMap: { [key: string]: { message: string; description: string } } = { export async function callMethodAsync( this: T, parameters: { - executeFunctions: IExecuteFunctions; + executeFunctions: IExecuteFunctions | ISupplyDataFunctions; connectionType: NodeConnectionType; currentNodeRunIndex: number; method: (...args: any[]) => Promise; @@ -113,7 +113,7 @@ export function logWrapper( | VectorStore | N8nBinaryLoader | N8nJsonLoader, - executeFunctions: IExecuteFunctions, + executeFunctions: IExecuteFunctions | ISupplyDataFunctions, ) { return new Proxy(originalInstance, { get: (target, prop) => { @@ -190,7 +190,7 @@ export function logWrapper( const payload = { action: 'getMessages', response }; executeFunctions.addOutputData(connectionType, index, [[{ json: payload }]]); - void logAiEvent(executeFunctions, 'ai-messages-retrieved-from-memory', { response }); + logAiEvent(executeFunctions, 'ai-messages-retrieved-from-memory', { response }); return response; }; } else if (prop === 'addMessage' && 'addMessage' in target) { @@ -207,7 +207,7 @@ export function logWrapper( arguments: [message], }); - void logAiEvent(executeFunctions, 'ai-message-added-to-memory', { message }); + logAiEvent(executeFunctions, 'ai-message-added-to-memory', { message }); executeFunctions.addOutputData(connectionType, index, [[{ json: payload }]]); }; } @@ -233,7 +233,7 @@ export function logWrapper( arguments: [query, config], })) as Array>>; - void logAiEvent(executeFunctions, 'ai-documents-retrieved', { query }); + logAiEvent(executeFunctions, 'ai-documents-retrieved', { query }); executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]); return response; }; @@ -258,7 +258,7 @@ export function logWrapper( arguments: [documents], })) as number[][]; - void logAiEvent(executeFunctions, 'ai-document-embedded'); + logAiEvent(executeFunctions, 'ai-document-embedded'); executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]); return response; }; @@ -278,7 +278,7 @@ export function logWrapper( method: target[prop], arguments: [query], })) as number[]; - void logAiEvent(executeFunctions, 'ai-query-embedded'); + logAiEvent(executeFunctions, 'ai-query-embedded'); executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]); return response; }; @@ -323,7 +323,7 @@ export function logWrapper( arguments: [item, itemIndex], })) as number[]; - void logAiEvent(executeFunctions, 'ai-document-processed'); + logAiEvent(executeFunctions, 'ai-document-processed'); executeFunctions.addOutputData(connectionType, index, [ [{ json: { response }, pairedItem: { item: itemIndex } }], ]); @@ -349,7 +349,7 @@ export function logWrapper( arguments: [text], })) as string[]; - void logAiEvent(executeFunctions, 'ai-text-split'); + logAiEvent(executeFunctions, 'ai-text-split'); executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]); return response; }; @@ -373,7 +373,7 @@ export function logWrapper( arguments: [query], })) as string; - void logAiEvent(executeFunctions, 'ai-tool-called', { query, response }); + logAiEvent(executeFunctions, 'ai-tool-called', { query, response }); executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]); return response; }; @@ -403,7 +403,7 @@ export function logWrapper( arguments: [query, k, filter, _callbacks], })) as Array>>; - void logAiEvent(executeFunctions, 'ai-vector-store-searched', { query }); + logAiEvent(executeFunctions, 'ai-vector-store-searched', { query }); executeFunctions.addOutputData(connectionType, index, [[{ json: { response } }]]); return response; diff --git a/packages/@n8n/nodes-langchain/utils/output_parsers/N8nOutputFixingParser.ts b/packages/@n8n/nodes-langchain/utils/output_parsers/N8nOutputFixingParser.ts index bfcbf88b33..eec3b0c187 100644 --- a/packages/@n8n/nodes-langchain/utils/output_parsers/N8nOutputFixingParser.ts +++ b/packages/@n8n/nodes-langchain/utils/output_parsers/N8nOutputFixingParser.ts @@ -2,7 +2,7 @@ import type { Callbacks } from '@langchain/core/callbacks/manager'; import type { BaseLanguageModel } from '@langchain/core/language_models/base'; import type { AIMessage } from '@langchain/core/messages'; import { BaseOutputParser } from '@langchain/core/output_parsers'; -import type { IExecuteFunctions } from 'n8n-workflow'; +import type { ISupplyDataFunctions } from 'n8n-workflow'; import { NodeConnectionType } from 'n8n-workflow'; import type { N8nStructuredOutputParser } from './N8nStructuredOutputParser'; @@ -10,23 +10,14 @@ import { NAIVE_FIX_PROMPT } from './prompt'; import { logAiEvent } from '../helpers'; export class N8nOutputFixingParser extends BaseOutputParser { - private context: IExecuteFunctions; - - private model: BaseLanguageModel; - - private outputParser: N8nStructuredOutputParser; - lc_namespace = ['langchain', 'output_parsers', 'fix']; constructor( - context: IExecuteFunctions, - model: BaseLanguageModel, - outputParser: N8nStructuredOutputParser, + private context: ISupplyDataFunctions, + private model: BaseLanguageModel, + private outputParser: N8nStructuredOutputParser, ) { super(); - this.context = context; - this.model = model; - this.outputParser = outputParser; } getRetryChain() { @@ -48,7 +39,7 @@ export class N8nOutputFixingParser extends BaseOutputParser { try { // First attempt to parse the completion const response = await this.outputParser.parse(completion, callbacks, (e) => e); - void logAiEvent(this.context, 'ai-output-parsed', { text: completion, response }); + logAiEvent(this.context, 'ai-output-parsed', { text: completion, response }); this.context.addOutputData(NodeConnectionType.AiOutputParser, index, [ [{ json: { action: 'parse', response } }], diff --git a/packages/@n8n/nodes-langchain/utils/output_parsers/N8nStructuredOutputParser.ts b/packages/@n8n/nodes-langchain/utils/output_parsers/N8nStructuredOutputParser.ts index 4799193be6..a24052f5e1 100644 --- a/packages/@n8n/nodes-langchain/utils/output_parsers/N8nStructuredOutputParser.ts +++ b/packages/@n8n/nodes-langchain/utils/output_parsers/N8nStructuredOutputParser.ts @@ -1,7 +1,7 @@ import type { Callbacks } from '@langchain/core/callbacks/manager'; import { StructuredOutputParser } from 'langchain/output_parsers'; import get from 'lodash/get'; -import type { IExecuteFunctions } from 'n8n-workflow'; +import type { ISupplyDataFunctions } from 'n8n-workflow'; import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; import { z } from 'zod'; @@ -14,11 +14,11 @@ const STRUCTURED_OUTPUT_ARRAY_KEY = '__structured__output__array'; export class N8nStructuredOutputParser extends StructuredOutputParser< z.ZodType > { - context: IExecuteFunctions; - - constructor(context: IExecuteFunctions, zodSchema: z.ZodSchema) { + constructor( + private context: ISupplyDataFunctions, + zodSchema: z.ZodSchema, + ) { super(zodSchema); - this.context = context; } lc_namespace = ['langchain', 'output_parsers', 'structured']; @@ -39,7 +39,7 @@ export class N8nStructuredOutputParser extends StructuredOutputParser< get(parsed, STRUCTURED_OUTPUT_KEY) ?? parsed) as Record; - void logAiEvent(this.context, 'ai-output-parsed', { text, response: result }); + logAiEvent(this.context, 'ai-output-parsed', { text, response: result }); this.context.addOutputData(NodeConnectionType.AiOutputParser, index, [ [{ json: { action: 'parse', response: result } }], @@ -56,7 +56,7 @@ export class N8nStructuredOutputParser extends StructuredOutputParser< }, ); - void logAiEvent(this.context, 'ai-output-parsed', { + logAiEvent(this.context, 'ai-output-parsed', { text, response: e.message ?? e, }); @@ -73,7 +73,7 @@ export class N8nStructuredOutputParser extends StructuredOutputParser< static async fromZodJsonSchema( zodSchema: z.ZodSchema, nodeVersion: number, - context: IExecuteFunctions, + context: ISupplyDataFunctions, ): Promise { let returnSchema: z.ZodType; if (nodeVersion === 1) { diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index 529d6fc94b..10c44efced 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -110,6 +110,7 @@ import type { DeduplicationItemTypes, ICheckProcessedContextData, AiEvent, + ISupplyDataFunctions, } from 'n8n-workflow'; import { NodeConnectionType, @@ -2803,12 +2804,14 @@ async function getInputConnectionData( runExecutionData: IRunExecutionData, runIndex: number, connectionInputData: INodeExecutionData[], + inputData: ITaskDataConnections, additionalData: IWorkflowExecuteAdditionalData, - executeData: IExecuteData | undefined, + executeData: IExecuteData, mode: WorkflowExecuteMode, closeFunctions: CloseFunction[], inputName: NodeConnectionType, itemIndex: number, + abortSignal?: AbortSignal, ): Promise { const node = this.getNode(); const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion); @@ -2856,74 +2859,20 @@ async function getInputConnectionData( connectedNode.typeVersion, ); - // TODO: create a new context object here based on the type of `connectedNode`, and avoid using `Object.assign` on context objects - // https://linear.app/n8n/issue/CAT-269 - const context = Object.assign({}, this); - - context.getNodeParameter = ( - parameterName: string, - itemIndex: number, - fallbackValue?: any, - options?: IGetNodeParameterOptions, - ) => { - return getNodeParameter( - workflow, - runExecutionData, - runIndex, - connectionInputData, - connectedNode, - parameterName, - itemIndex, - mode, - getAdditionalKeys(additionalData, mode, runExecutionData), - executeData, - fallbackValue, - { ...(options || {}), contextNode: node }, - ) as any; - }; - - // TODO: Check what else should be overwritten - context.getNode = () => { - return deepCopy(connectedNode); - }; - - context.getCredentials = async (key: string) => { - try { - return await getCredentials( - workflow, - connectedNode, - key, - additionalData, - mode, - executeData, - runExecutionData, - runIndex, - connectionInputData, - itemIndex, - ); - } catch (error) { - // Display the error on the node which is causing it - - let currentNodeRunIndex = 0; - if (runExecutionData.resultData.runData.hasOwnProperty(node.name)) { - currentNodeRunIndex = runExecutionData.resultData.runData[node.name].length; - } - - await addExecutionDataFunctions( - 'input', - connectedNode.name, - error, - runExecutionData, - inputName, - additionalData, - node.name, - runIndex, - currentNodeRunIndex, - ); - - throw error; - } - }; + // eslint-disable-next-line @typescript-eslint/no-use-before-define + const context = getSupplyDataFunctions( + workflow, + runExecutionData, + runIndex, + connectionInputData, + inputData, + connectedNode, + additionalData, + executeData, + mode, + closeFunctions, + abortSignal, + ); if (!nodeType.supplyData) { if (nodeType.description.outputs.includes(NodeConnectionType.AiTool)) { @@ -3767,9 +3716,7 @@ export function getExecuteFunctions( runExecutionData, runIndex, itemIndex, - // TODO: revert this back to `node.name` when we stop using `IExecuteFunctions` as the context object in AI nodes. - // https://linear.app/n8n/issue/CAT-269 - this.getNode().name, + node.name, connectionInputData, mode, getAdditionalKeys(additionalData, mode, runExecutionData), @@ -3812,12 +3759,14 @@ export function getExecuteFunctions( runExecutionData, runIndex, connectionInputData, + inputData, additionalData, executeData, mode, closeFunctions, inputName, itemIndex, + abortSignal, ); }, @@ -4031,7 +3980,7 @@ export function getExecuteFunctions( constructExecutionMetaData, }, nodeHelpers: getNodeHelperFunctions(additionalData, workflow.id), - logAiEvent: async (eventName: AiEvent, msg: string) => { + logAiEvent: (eventName: AiEvent, msg: string) => { return additionalData.logAiEvent(eventName, { executionId: additionalData.executionId ?? 'unsaved-execution', nodeName: node.name, @@ -4059,6 +4008,270 @@ export function getExecuteFunctions( })(workflow, runExecutionData, connectionInputData, inputData, node) as IExecuteFunctions; } +export function getSupplyDataFunctions( + workflow: Workflow, + runExecutionData: IRunExecutionData, + runIndex: number, + connectionInputData: INodeExecutionData[], + inputData: ITaskDataConnections, + node: INode, + additionalData: IWorkflowExecuteAdditionalData, + executeData: IExecuteData, + mode: WorkflowExecuteMode, + closeFunctions: CloseFunction[], + abortSignal?: AbortSignal, +): ISupplyDataFunctions { + return { + ...getCommonWorkflowFunctions(workflow, node, additionalData), + ...executionCancellationFunctions(abortSignal), + getMode: () => mode, + getCredentials: async (type, itemIndex) => + await getCredentials( + workflow, + node, + type, + additionalData, + mode, + executeData, + runExecutionData, + runIndex, + connectionInputData, + itemIndex, + ), + continueOnFail: () => continueOnFail(node), + evaluateExpression: (expression: string, itemIndex: number) => + workflow.expression.resolveSimpleParameterValue( + `=${expression}`, + {}, + runExecutionData, + runIndex, + itemIndex, + node.name, + connectionInputData, + mode, + getAdditionalKeys(additionalData, mode, runExecutionData), + executeData, + ), + executeWorkflow: async ( + workflowInfo: IExecuteWorkflowInfo, + inputData?: INodeExecutionData[], + parentCallbackManager?: CallbackManager, + ) => + await additionalData + .executeWorkflow(workflowInfo, additionalData, { + parentWorkflowId: workflow.id?.toString(), + inputData, + parentWorkflowSettings: workflow.settings, + node, + parentCallbackManager, + }) + .then( + async (result) => + await Container.get(BinaryDataService).duplicateBinaryData( + workflow.id, + additionalData.executionId!, + result, + ), + ), + getNodeOutputs() { + const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion); + return NodeHelpers.getNodeOutputs(workflow, node, nodeType.description).map((output) => { + if (typeof output === 'string') { + return { + type: output, + }; + } + return output; + }); + }, + async getInputConnectionData( + inputName: NodeConnectionType, + itemIndex: number, + ): Promise { + return await getInputConnectionData.call( + this, + workflow, + runExecutionData, + runIndex, + connectionInputData, + inputData, + additionalData, + executeData, + mode, + closeFunctions, + inputName, + itemIndex, + abortSignal, + ); + }, + getInputData: (inputIndex = 0, inputName = 'main') => { + if (!inputData.hasOwnProperty(inputName)) { + // Return empty array because else it would throw error when nothing is connected to input + return []; + } + + // TODO: Check if nodeType has input with that index defined + if (inputData[inputName].length < inputIndex) { + throw new ApplicationError('Could not get input with given index', { + extra: { inputIndex, inputName }, + }); + } + + if (inputData[inputName][inputIndex] === null) { + throw new ApplicationError('Value of input was not set', { + extra: { inputIndex, inputName }, + }); + } + + return inputData[inputName][inputIndex]; + }, + getNodeParameter: (( + parameterName: string, + itemIndex: number, + fallbackValue?: any, + options?: IGetNodeParameterOptions, + ) => + getNodeParameter( + workflow, + runExecutionData, + runIndex, + connectionInputData, + node, + parameterName, + itemIndex, + mode, + getAdditionalKeys(additionalData, mode, runExecutionData), + executeData, + fallbackValue, + options, + )) as ISupplyDataFunctions['getNodeParameter'], + getWorkflowDataProxy: (itemIndex: number) => + new WorkflowDataProxy( + workflow, + runExecutionData, + runIndex, + itemIndex, + node.name, + connectionInputData, + {}, + mode, + getAdditionalKeys(additionalData, mode, runExecutionData), + executeData, + ).getDataProxy(), + sendMessageToUI(...args: any[]): void { + if (mode !== 'manual') { + return; + } + try { + if (additionalData.sendDataToUI) { + args = args.map((arg) => { + // prevent invalid dates from being logged as null + if (arg.isLuxonDateTime && arg.invalidReason) return { ...arg }; + + // log valid dates in human readable format, as in browser + if (arg.isLuxonDateTime) return new Date(arg.ts).toString(); + if (arg instanceof Date) return arg.toString(); + + return arg; + }); + + additionalData.sendDataToUI('sendConsoleMessage', { + source: `[Node: "${node.name}"]`, + messages: args, + }); + } + } catch (error) { + Logger.warn(`There was a problem sending message to UI: ${error.message}`); + } + }, + logAiEvent: (eventName: AiEvent, msg: string) => + additionalData.logAiEvent(eventName, { + executionId: additionalData.executionId ?? 'unsaved-execution', + nodeName: node.name, + workflowName: workflow.name ?? 'Unnamed workflow', + nodeType: node.type, + workflowId: workflow.id ?? 'unsaved-workflow', + msg, + }), + addInputData( + connectionType: NodeConnectionType, + data: INodeExecutionData[][], + ): { index: number } { + const nodeName = this.getNode().name; + let currentNodeRunIndex = 0; + if (runExecutionData.resultData.runData.hasOwnProperty(nodeName)) { + currentNodeRunIndex = runExecutionData.resultData.runData[nodeName].length; + } + + addExecutionDataFunctions( + 'input', + this.getNode().name, + data, + runExecutionData, + connectionType, + additionalData, + node.name, + runIndex, + currentNodeRunIndex, + ).catch((error) => { + Logger.warn( + `There was a problem logging input data of node "${this.getNode().name}": ${ + error.message + }`, + ); + }); + + return { index: currentNodeRunIndex }; + }, + addOutputData( + connectionType: NodeConnectionType, + currentNodeRunIndex: number, + data: INodeExecutionData[][], + ): void { + addExecutionDataFunctions( + 'output', + this.getNode().name, + data, + runExecutionData, + connectionType, + additionalData, + node.name, + runIndex, + currentNodeRunIndex, + ).catch((error) => { + Logger.warn( + `There was a problem logging output data of node "${this.getNode().name}": ${ + error.message + }`, + ); + }); + }, + helpers: { + createDeferredPromise, + copyInputItems, + ...getRequestHelperFunctions( + workflow, + node, + additionalData, + runExecutionData, + connectionInputData, + ), + ...getSSHTunnelFunctions(), + ...getFileSystemHelperFunctions(node), + ...getBinaryHelperFunctions(additionalData, workflow.id), + ...getCheckProcessedHelperFunctions(workflow, node), + assertBinaryData: (itemIndex, propertyName) => + assertBinaryData(inputData, node, itemIndex, propertyName, 0), + getBinaryDataBuffer: async (itemIndex, propertyName) => + await getBinaryDataBuffer(inputData, itemIndex, propertyName, 0), + + returnJsonArray, + normalizeItems, + constructExecutionMetaData, + }, + }; +} + /** * Returns the execute functions regular nodes have access to when single-function is defined. */ @@ -4201,7 +4414,7 @@ export function getExecuteSingleFunctions( getBinaryDataBuffer: async (propertyName, inputIndex = 0) => await getBinaryDataBuffer(inputData, itemIndex, propertyName, inputIndex), }, - logAiEvent: async (eventName: AiEvent, msg: string) => { + logAiEvent: (eventName: AiEvent, msg: string) => { return additionalData.logAiEvent(eventName, { executionId: additionalData.executionId ?? 'unsaved-execution', nodeName: node.name, @@ -4431,6 +4644,7 @@ export function getExecuteWebhookFunctions( runExecutionData, runIndex, connectionInputData, + {} as ITaskDataConnections, additionalData, executeData, mode, diff --git a/packages/nodes-base/nodes/Code/Sandbox.ts b/packages/nodes-base/nodes/Code/Sandbox.ts index 932a3f0c39..917de0ecc1 100644 --- a/packages/nodes-base/nodes/Code/Sandbox.ts +++ b/packages/nodes-base/nodes/Code/Sandbox.ts @@ -1,5 +1,10 @@ import { EventEmitter } from 'events'; -import type { IExecuteFunctions, INodeExecutionData, IWorkflowDataProxyData } from 'n8n-workflow'; +import type { + IExecuteFunctions, + INodeExecutionData, + ISupplyDataFunctions, + IWorkflowDataProxyData, +} from 'n8n-workflow'; import { isObject } from './utils'; import { ValidationError } from './ValidationError'; @@ -19,7 +24,10 @@ export interface SandboxContext extends IWorkflowDataProxyData { export const REQUIRED_N8N_ITEM_KEYS = new Set(['json', 'binary', 'pairedItem', 'error']); -export function getSandboxContext(this: IExecuteFunctions, index: number): SandboxContext { +export function getSandboxContext( + this: IExecuteFunctions | ISupplyDataFunctions, + index: number, +): SandboxContext { const helpers = { ...this.helpers, httpRequestWithAuthentication: this.helpers.httpRequestWithAuthentication.bind(this), diff --git a/packages/nodes-base/nodes/Set/v2/helpers/utils.ts b/packages/nodes-base/nodes/Set/v2/helpers/utils.ts index 46536f312b..d6754914ce 100644 --- a/packages/nodes-base/nodes/Set/v2/helpers/utils.ts +++ b/packages/nodes-base/nodes/Set/v2/helpers/utils.ts @@ -4,6 +4,7 @@ import type { IExecuteFunctions, INode, INodeExecutionData, + ISupplyDataFunctions, } from 'n8n-workflow'; import { ApplicationError, @@ -51,7 +52,7 @@ const configureFieldHelper = (dotNotation?: boolean) => { }; export function composeReturnItem( - this: IExecuteFunctions, + this: IExecuteFunctions | ISupplyDataFunctions, itemIndex: number, inputItem: INodeExecutionData, newFields: IDataObject, @@ -220,7 +221,11 @@ export const validateEntry = ( }; }; -export function resolveRawData(this: IExecuteFunctions, rawData: string, i: number) { +export function resolveRawData( + this: IExecuteFunctions | ISupplyDataFunctions, + rawData: string, + i: number, +) { const resolvables = getResolvables(rawData); let returnData: string = rawData; diff --git a/packages/nodes-base/nodes/Set/v2/manual.mode.ts b/packages/nodes-base/nodes/Set/v2/manual.mode.ts index 282730bbf0..0865e2c4ee 100644 --- a/packages/nodes-base/nodes/Set/v2/manual.mode.ts +++ b/packages/nodes-base/nodes/Set/v2/manual.mode.ts @@ -6,6 +6,7 @@ import type { INode, INodeExecutionData, INodeProperties, + ISupplyDataFunctions, } from 'n8n-workflow'; import { NodeOperationError } from 'n8n-workflow'; @@ -185,7 +186,7 @@ const displayOptions = { export const description = updateDisplayOptions(displayOptions, properties); export async function execute( - this: IExecuteFunctions, + this: IExecuteFunctions | ISupplyDataFunctions, item: INodeExecutionData, i: number, options: SetNodeOptions, diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index d0da574649..4f92a219e6 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -35,6 +35,7 @@ export type IAllExecuteFunctions = | IExecuteFunctions | IExecutePaginationFunctions | IExecuteSingleFunctions + | ISupplyDataFunctions | IHookFunctions | ILoadOptionsFunctions | IPollFunctions @@ -943,7 +944,7 @@ type BaseExecutionFunctions = FunctionsBaseWithRequiredKeys<'getMode'> & { getInputSourceData(inputIndex?: number, inputName?: string): ISourceData; getExecutionCancelSignal(): AbortSignal | undefined; onExecutionCancellation(handler: () => unknown): void; - logAiEvent(eventName: AiEvent, msg?: string | undefined): Promise; + logAiEvent(eventName: AiEvent, msg?: string | undefined): void; }; // TODO: Create later own type only for Config-Nodes @@ -1022,6 +1023,27 @@ export interface IExecuteSingleFunctions extends BaseExecutionFunctions { }; } +export type ISupplyDataFunctions = ExecuteFunctions.GetNodeParameterFn & + FunctionsBaseWithRequiredKeys<'getMode'> & + Pick< + IExecuteFunctions, + | 'addInputData' + | 'addOutputData' + | 'getInputConnectionData' + | 'getInputData' + | 'getNodeOutputs' + | 'executeWorkflow' + | 'sendMessageToUI' + | 'helpers' + > & { + continueOnFail(): boolean; + evaluateExpression(expression: string, itemIndex: number): NodeParameterValueType; + getWorkflowDataProxy(itemIndex: number): IWorkflowDataProxyData; + getExecutionCancelSignal(): AbortSignal | undefined; + onExecutionCancellation(handler: () => unknown): void; + logAiEvent(eventName: AiEvent, msg?: string | undefined): void; + }; + export interface IExecutePaginationFunctions extends IExecuteSingleFunctions { makeRoutingRequest( this: IAllExecuteFunctions, @@ -1572,7 +1594,7 @@ export class NodeExecutionOutput extends Array { export interface INodeType { description: INodeTypeDescription; - supplyData?(this: IAllExecuteFunctions, itemIndex: number): Promise; + supplyData?(this: ISupplyDataFunctions, itemIndex: number): Promise; execute?( this: IExecuteFunctions, ): Promise;