diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts index 80e5da9cfa..230a6ddc6e 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts @@ -9,6 +9,8 @@ import type { INodeProperties, } from 'n8n-workflow'; +import { promptTypeOptions, textFromPreviousNode, textInput } from '@utils/descriptions'; + import { conversationalAgentProperties } from './agents/ConversationalAgent/description'; import { conversationalAgentExecute } from './agents/ConversationalAgent/execute'; import { openAiFunctionsAgentProperties } from './agents/OpenAiFunctionsAgent/description'; @@ -21,7 +23,6 @@ import { sqlAgentAgentProperties } from './agents/SqlAgent/description'; import { sqlAgentAgentExecute } from './agents/SqlAgent/execute'; import { toolsAgentProperties } from './agents/ToolsAgent/description'; import { toolsAgentExecute } from './agents/ToolsAgent/execute'; -import { promptTypeOptions, textFromPreviousNode, textInput } from '../../../utils/descriptions'; // Function used in the inputs expression to figure out which inputs to // display based on the agent type diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ConversationalAgent/description.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ConversationalAgent/description.ts index c3507b328c..0a65f4919c 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ConversationalAgent/description.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ConversationalAgent/description.ts @@ -1,4 +1,5 @@ import type { INodeProperties } from 'n8n-workflow'; + import { SYSTEM_MESSAGE, HUMAN_MESSAGE } from './prompt'; export const conversationalAgentProperties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ConversationalAgent/execute.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ConversationalAgent/execute.ts index 09e04c0b76..04a565971c 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ConversationalAgent/execute.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ConversationalAgent/execute.ts @@ -6,14 +6,11 @@ import { CombiningOutputParser } from 'langchain/output_parsers'; import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; -import { - isChatInstance, - getPromptInputByType, - getConnectedTools, -} from '../../../../../utils/helpers'; -import { getOptionalOutputParsers } from '../../../../../utils/output_parsers/N8nOutputParser'; -import { throwIfToolSchema } from '../../../../../utils/schemaParsing'; -import { getTracingConfig } from '../../../../../utils/tracing'; +import { isChatInstance, getPromptInputByType, getConnectedTools } from '@utils/helpers'; +import { getOptionalOutputParsers } from '@utils/output_parsers/N8nOutputParser'; +import { throwIfToolSchema } from '@utils/schemaParsing'; +import { getTracingConfig } from '@utils/tracing'; + import { checkForStructuredTools, extractParsedOutput } from '../utils'; export async function conversationalAgentExecute( diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/OpenAiFunctionsAgent/description.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/OpenAiFunctionsAgent/description.ts index 40f9ad1945..0a0f6ac55e 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/OpenAiFunctionsAgent/description.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/OpenAiFunctionsAgent/description.ts @@ -1,4 +1,5 @@ import type { INodeProperties } from 'n8n-workflow'; + import { SYSTEM_MESSAGE } from './prompt'; export const openAiFunctionsAgentProperties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.ts index a9b324678c..17a2d43590 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.ts @@ -12,9 +12,10 @@ import { NodeOperationError, } from 'n8n-workflow'; -import { getConnectedTools, getPromptInputByType } from '../../../../../utils/helpers'; -import { getOptionalOutputParsers } from '../../../../../utils/output_parsers/N8nOutputParser'; -import { getTracingConfig } from '../../../../../utils/tracing'; +import { getConnectedTools, getPromptInputByType } from '@utils/helpers'; +import { getOptionalOutputParsers } from '@utils/output_parsers/N8nOutputParser'; +import { getTracingConfig } from '@utils/tracing'; + import { extractParsedOutput } from '../utils'; export async function openAiFunctionsAgentExecute( diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/PlanAndExecuteAgent/description.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/PlanAndExecuteAgent/description.ts index 608f9e9def..8dcb8f8385 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/PlanAndExecuteAgent/description.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/PlanAndExecuteAgent/description.ts @@ -1,4 +1,5 @@ import type { INodeProperties } from 'n8n-workflow'; + import { DEFAULT_STEP_EXECUTOR_HUMAN_CHAT_MESSAGE_TEMPLATE } from './prompt'; export const planAndExecuteAgentProperties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.ts index d2dc152ebb..379475f923 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.ts @@ -10,10 +10,11 @@ import { NodeOperationError, } from 'n8n-workflow'; -import { getConnectedTools, getPromptInputByType } from '../../../../../utils/helpers'; -import { getOptionalOutputParsers } from '../../../../../utils/output_parsers/N8nOutputParser'; -import { throwIfToolSchema } from '../../../../../utils/schemaParsing'; -import { getTracingConfig } from '../../../../../utils/tracing'; +import { getConnectedTools, getPromptInputByType } from '@utils/helpers'; +import { getOptionalOutputParsers } from '@utils/output_parsers/N8nOutputParser'; +import { throwIfToolSchema } from '@utils/schemaParsing'; +import { getTracingConfig } from '@utils/tracing'; + import { checkForStructuredTools, extractParsedOutput } from '../utils'; export async function planAndExecuteAgentExecute( diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ReActAgent/description.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ReActAgent/description.ts index f95026f7a4..890d83dc4a 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ReActAgent/description.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ReActAgent/description.ts @@ -1,4 +1,5 @@ import type { INodeProperties } from 'n8n-workflow'; + import { HUMAN_MESSAGE_TEMPLATE, PREFIX, SUFFIX, SUFFIX_CHAT } from './prompt'; export const reActAgentAgentProperties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ReActAgent/execute.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ReActAgent/execute.ts index b671a8189c..4db35634d6 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ReActAgent/execute.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ReActAgent/execute.ts @@ -11,14 +11,11 @@ import { NodeOperationError, } from 'n8n-workflow'; -import { - getConnectedTools, - getPromptInputByType, - isChatInstance, -} from '../../../../../utils/helpers'; -import { getOptionalOutputParsers } from '../../../../../utils/output_parsers/N8nOutputParser'; -import { throwIfToolSchema } from '../../../../../utils/schemaParsing'; -import { getTracingConfig } from '../../../../../utils/tracing'; +import { getConnectedTools, getPromptInputByType, isChatInstance } from '@utils/helpers'; +import { getOptionalOutputParsers } from '@utils/output_parsers/N8nOutputParser'; +import { throwIfToolSchema } from '@utils/schemaParsing'; +import { getTracingConfig } from '@utils/tracing'; + import { checkForStructuredTools, extractParsedOutput } from '../utils'; export async function reActAgentAgentExecute( diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/description.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/description.ts index bed547ba6d..919f501d17 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/description.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/description.ts @@ -1,11 +1,8 @@ import type { INodeProperties } from 'n8n-workflow'; +import { promptTypeOptions, textFromPreviousNode, textInput } from '@utils/descriptions'; + import { SQL_PREFIX, SQL_SUFFIX } from './other/prompts'; -import { - promptTypeOptions, - textFromPreviousNode, - textInput, -} from '../../../../../utils/descriptions'; const dataSourceOptions: INodeProperties = { displayName: 'Data Source', diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/execute.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/execute.ts index b9c0f3db8e..369ca109af 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/execute.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/execute.ts @@ -12,12 +12,13 @@ import { type IDataObject, } from 'n8n-workflow'; +import { getPromptInputByType, serializeChatHistory } from '@utils/helpers'; +import { getTracingConfig } from '@utils/tracing'; + import { getMysqlDataSource } from './other/handlers/mysql'; import { getPostgresDataSource } from './other/handlers/postgres'; import { getSqliteDataSource } from './other/handlers/sqlite'; import { SQL_PREFIX, SQL_SUFFIX } from './other/prompts'; -import { getPromptInputByType, serializeChatHistory } from '../../../../../utils/helpers'; -import { getTracingConfig } from '../../../../../utils/tracing'; const parseTablesString = (tablesString: string) => tablesString diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/mysql.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/mysql.ts index ea1b360f04..dd56f93d6c 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/mysql.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/mysql.ts @@ -1,5 +1,5 @@ -import { type IExecuteFunctions } from 'n8n-workflow'; import { DataSource } from '@n8n/typeorm'; +import { type IExecuteFunctions } from 'n8n-workflow'; export async function getMysqlDataSource(this: IExecuteFunctions): Promise { const credentials = await this.getCredentials('mySql'); diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/postgres.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/postgres.ts index 6971d9119f..31dda9ed72 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/postgres.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/postgres.ts @@ -1,5 +1,5 @@ -import { type IExecuteFunctions } from 'n8n-workflow'; import { DataSource } from '@n8n/typeorm'; +import { type IExecuteFunctions } from 'n8n-workflow'; export async function getPostgresDataSource(this: IExecuteFunctions): Promise { const credentials = await this.getCredentials('postgres'); diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/sqlite.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/sqlite.ts index 9240feb280..31db7b0dca 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/sqlite.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/sqlite.ts @@ -1,9 +1,9 @@ +import { DataSource } from '@n8n/typeorm'; import * as fs from 'fs'; import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; import { BINARY_ENCODING, NodeOperationError } from 'n8n-workflow'; -import * as temp from 'temp'; import * as sqlite3 from 'sqlite3'; -import { DataSource } from '@n8n/typeorm'; +import * as temp from 'temp'; export async function getSqliteDataSource( this: IExecuteFunctions, diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/description.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/description.ts index cb33560cc6..06b64a91de 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/description.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/description.ts @@ -1,4 +1,5 @@ import type { INodeProperties } from 'n8n-workflow'; + import { SYSTEM_MESSAGE } from './prompt'; export const toolsAgentProperties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts index 9c92a63361..b0e36d0d8b 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts @@ -14,16 +14,13 @@ import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; import type { ZodObject } from 'zod'; import { z } from 'zod'; -import { SYSTEM_MESSAGE } from './prompt'; -import { - isChatInstance, - getPromptInputByType, - getConnectedTools, -} from '../../../../../utils/helpers'; +import { isChatInstance, getPromptInputByType, getConnectedTools } from '@utils/helpers'; import { getOptionalOutputParsers, type N8nOutputParser, -} from '../../../../../utils/output_parsers/N8nOutputParser'; +} from '@utils/output_parsers/N8nOutputParser'; + +import { SYSTEM_MESSAGE } from './prompt'; function getOutputParserSchema(outputParser: N8nOutputParser): ZodObject { const schema = diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/utils.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/utils.ts index 144b622c76..991b5895a7 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/utils.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/utils.ts @@ -1,7 +1,7 @@ -import type { z } from 'zod'; import type { BaseOutputParser } from '@langchain/core/output_parsers'; import type { DynamicStructuredTool, Tool } from 'langchain/tools'; import { NodeOperationError, type IExecuteFunctions, type INode } from 'n8n-workflow'; +import type { z } from 'zod'; type ZodObjectAny = z.ZodObject; diff --git a/packages/@n8n/nodes-langchain/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.ts b/packages/@n8n/nodes-langchain/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.ts index ca42323fc3..e44ad8f9d2 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.ts @@ -10,9 +10,10 @@ import type { } from 'n8n-workflow'; import { OpenAI as OpenAIClient } from 'openai'; +import { getConnectedTools } from '@utils/helpers'; +import { getTracingConfig } from '@utils/tracing'; + import { formatToOpenAIAssistantTool } from './utils'; -import { getConnectedTools } from '../../../utils/helpers'; -import { getTracingConfig } from '../../../utils/tracing'; export class OpenAiAssistant implements INodeType { description: INodeTypeDescription = { diff --git a/packages/@n8n/nodes-langchain/nodes/agents/OpenAiAssistant/utils.ts b/packages/@n8n/nodes-langchain/nodes/agents/OpenAiAssistant/utils.ts index 294fc47847..d0db590bc3 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/OpenAiAssistant/utils.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/OpenAiAssistant/utils.ts @@ -1,6 +1,6 @@ -import { zodToJsonSchema } from 'zod-to-json-schema'; -import type { OpenAIClient } from '@langchain/openai'; import type { StructuredTool } from '@langchain/core/tools'; +import type { OpenAIClient } from '@langchain/openai'; +import { zodToJsonSchema } from 'zod-to-json-schema'; // Copied from langchain(`langchain/src/tools/convert_to_openai.ts`) // since these functions are not exported diff --git a/packages/@n8n/nodes-langchain/nodes/chains/ChainLLM/ChainLlm.node.ts b/packages/@n8n/nodes-langchain/nodes/chains/ChainLLM/ChainLlm.node.ts index 32d70f2d32..d4e205ec88 100644 --- a/packages/@n8n/nodes-langchain/nodes/chains/ChainLLM/ChainLlm.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/chains/ChainLLM/ChainLlm.node.ts @@ -27,16 +27,17 @@ import { NodeOperationError, } from 'n8n-workflow'; -import { getPromptInputByType, isChatInstance } from '../../../utils/helpers'; -import type { N8nOutputParser } from '../../../utils/output_parsers/N8nOutputParser'; -import { getOptionalOutputParsers } from '../../../utils/output_parsers/N8nOutputParser'; -import { getTemplateNoticeField } from '../../../utils/sharedFields'; -import { getTracingConfig } from '../../../utils/tracing'; +import { promptTypeOptions, textFromPreviousNode } from '@utils/descriptions'; +import { getPromptInputByType, isChatInstance } from '@utils/helpers'; +import type { N8nOutputParser } from '@utils/output_parsers/N8nOutputParser'; +import { getOptionalOutputParsers } from '@utils/output_parsers/N8nOutputParser'; +import { getTemplateNoticeField } from '@utils/sharedFields'; +import { getTracingConfig } from '@utils/tracing'; + import { getCustomErrorMessage as getCustomOpenAiErrorMessage, isOpenAiError, } from '../../vendors/OpenAi/helpers/error-handling'; -import { promptTypeOptions, textFromPreviousNode } from '../../../utils/descriptions'; interface MessagesTemplate { type: string; diff --git a/packages/@n8n/nodes-langchain/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.ts b/packages/@n8n/nodes-langchain/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.ts index 75f7458438..9c7c739701 100644 --- a/packages/@n8n/nodes-langchain/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.ts @@ -16,10 +16,10 @@ import { NodeOperationError, } from 'n8n-workflow'; -import { promptTypeOptions, textFromPreviousNode } from '../../../utils/descriptions'; -import { getPromptInputByType, isChatInstance } from '../../../utils/helpers'; -import { getTemplateNoticeField } from '../../../utils/sharedFields'; -import { getTracingConfig } from '../../../utils/tracing'; +import { promptTypeOptions, textFromPreviousNode } from '@utils/descriptions'; +import { getPromptInputByType, isChatInstance } from '@utils/helpers'; +import { getTemplateNoticeField } from '@utils/sharedFields'; +import { getTracingConfig } from '@utils/tracing'; const SYSTEM_PROMPT_TEMPLATE = `Use the following pieces of context to answer the users question. If you don't know the answer, just say that you don't know, don't try to make up an answer. diff --git a/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.ts b/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.ts index 3e7b6997d6..fedf979082 100644 --- a/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.ts @@ -1,3 +1,8 @@ +import type { Document } from '@langchain/core/documents'; +import type { BaseLanguageModel } from '@langchain/core/language_models/base'; +import { PromptTemplate } from '@langchain/core/prompts'; +import type { SummarizationChainParams } from 'langchain/chains'; +import { loadSummarizationChain } from 'langchain/chains'; import { NodeConnectionType, type INodeTypeBaseDescription, @@ -7,14 +12,10 @@ import { type INodeTypeDescription, } from 'n8n-workflow'; -import type { SummarizationChainParams } from 'langchain/chains'; -import { loadSummarizationChain } from 'langchain/chains'; -import type { BaseLanguageModel } from '@langchain/core/language_models/base'; -import type { Document } from '@langchain/core/documents'; -import { PromptTemplate } from '@langchain/core/prompts'; -import { N8nJsonLoader } from '../../../../utils/N8nJsonLoader'; -import { N8nBinaryLoader } from '../../../../utils/N8nBinaryLoader'; -import { getTemplateNoticeField } from '../../../../utils/sharedFields'; +import { N8nBinaryLoader } from '@utils/N8nBinaryLoader'; +import { N8nJsonLoader } from '@utils/N8nJsonLoader'; +import { getTemplateNoticeField } from '@utils/sharedFields'; + import { REFINE_PROMPT_TEMPLATE, DEFAULT_PROMPT_TEMPLATE } from '../prompt'; export class ChainSummarizationV1 implements INodeType { diff --git a/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.ts b/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.ts index 76964e99f1..ff6dadde59 100644 --- a/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.ts @@ -1,4 +1,8 @@ -import { NodeConnectionType } from 'n8n-workflow'; +import type { Document } from '@langchain/core/documents'; +import type { BaseLanguageModel } from '@langchain/core/language_models/base'; +import type { TextSplitter } from '@langchain/textsplitters'; +import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters'; +import { loadSummarizationChain } from 'langchain/chains'; import type { INodeTypeBaseDescription, IExecuteFunctions, @@ -7,18 +11,15 @@ import type { INodeTypeDescription, IDataObject, } from 'n8n-workflow'; +import { NodeConnectionType } from 'n8n-workflow'; + +import { N8nBinaryLoader } from '@utils/N8nBinaryLoader'; +import { N8nJsonLoader } from '@utils/N8nJsonLoader'; +import { getTemplateNoticeField } from '@utils/sharedFields'; +import { getTracingConfig } from '@utils/tracing'; -import { loadSummarizationChain } from 'langchain/chains'; -import type { BaseLanguageModel } from '@langchain/core/language_models/base'; -import type { Document } from '@langchain/core/documents'; -import type { TextSplitter } from '@langchain/textsplitters'; -import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters'; -import { N8nJsonLoader } from '../../../../utils/N8nJsonLoader'; -import { N8nBinaryLoader } from '../../../../utils/N8nBinaryLoader'; -import { getTemplateNoticeField } from '../../../../utils/sharedFields'; -import { REFINE_PROMPT_TEMPLATE, DEFAULT_PROMPT_TEMPLATE } from '../prompt'; import { getChainPromptsArgs } from '../helpers'; -import { getTracingConfig } from '../../../../utils/tracing'; +import { REFINE_PROMPT_TEMPLATE, DEFAULT_PROMPT_TEMPLATE } from '../prompt'; function getInputs(parameters: IDataObject) { const chunkingMode = parameters?.chunkingMode; diff --git a/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/helpers.ts b/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/helpers.ts index 2a00d836e8..2da507ed00 100644 --- a/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/helpers.ts +++ b/packages/@n8n/nodes-langchain/nodes/chains/ChainSummarization/helpers.ts @@ -1,5 +1,5 @@ -import type { SummarizationChainParams } from 'langchain/chains'; import { PromptTemplate } from '@langchain/core/prompts'; +import type { SummarizationChainParams } from 'langchain/chains'; interface ChainTypeOptions { combineMapPrompt?: string; prompt?: string; diff --git a/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/InformationExtractor.node.ts b/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/InformationExtractor.node.ts index ab6cd8f201..365a35ddd3 100644 --- a/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/InformationExtractor.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/InformationExtractor.node.ts @@ -13,15 +13,12 @@ import type { } from 'n8n-workflow'; import type { z } from 'zod'; +import { inputSchemaField, jsonSchemaExampleField, schemaTypeField } from '@utils/descriptions'; +import { convertJsonSchemaToZod, generateSchema } from '@utils/schemaParsing'; +import { getTracingConfig } from '@utils/tracing'; + import { makeZodSchemaFromAttributes } from './helpers'; import type { AttributeDefinition } from './types'; -import { - inputSchemaField, - jsonSchemaExampleField, - schemaTypeField, -} from '../../../utils/descriptions'; -import { convertJsonSchemaToZod, generateSchema } from '../../../utils/schemaParsing'; -import { getTracingConfig } from '../../../utils/tracing'; const SYSTEM_PROMPT_TEMPLATE = `You are an expert extraction algorithm. Only extract relevant information from the text. diff --git a/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/helpers.ts b/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/helpers.ts index acde52765e..22f39f25a9 100644 --- a/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/helpers.ts +++ b/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/helpers.ts @@ -1,4 +1,5 @@ import { z } from 'zod'; + import type { AttributeDefinition } from './types'; function makeAttributeSchema(attributeDefinition: AttributeDefinition, required: boolean = true) { diff --git a/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/test/InformationExtraction.node.test.ts b/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/test/InformationExtraction.node.test.ts index b4e4672dac..725af39a60 100644 --- a/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/test/InformationExtraction.node.test.ts +++ b/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/test/InformationExtraction.node.test.ts @@ -1,10 +1,10 @@ -import type { IDataObject, IExecuteFunctions } from 'n8n-workflow/src'; -import get from 'lodash/get'; - -import { FakeLLM, FakeListChatModel } from '@langchain/core/utils/testing'; import type { BaseLanguageModel } from '@langchain/core/language_models/base'; -import { InformationExtractor } from '../InformationExtractor.node'; +import { FakeLLM, FakeListChatModel } from '@langchain/core/utils/testing'; +import get from 'lodash/get'; +import type { IDataObject, IExecuteFunctions } from 'n8n-workflow/src'; + import { makeZodSchemaFromAttributes } from '../helpers'; +import { InformationExtractor } from '../InformationExtractor.node'; import type { AttributeDefinition } from '../types'; const mockPersonAttributes: AttributeDefinition[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.ts b/packages/@n8n/nodes-langchain/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.ts index 5f5c6f19db..e810b0f98a 100644 --- a/packages/@n8n/nodes-langchain/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.ts @@ -1,3 +1,8 @@ +import type { BaseLanguageModel } from '@langchain/core/language_models/base'; +import { HumanMessage } from '@langchain/core/messages'; +import { SystemMessagePromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts'; +import { OutputFixingParser, StructuredOutputParser } from 'langchain/output_parsers'; +import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; import type { IDataObject, IExecuteFunctions, @@ -6,15 +11,9 @@ import type { INodeType, INodeTypeDescription, } from 'n8n-workflow'; - -import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; - -import type { BaseLanguageModel } from '@langchain/core/language_models/base'; -import { HumanMessage } from '@langchain/core/messages'; -import { SystemMessagePromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts'; -import { OutputFixingParser, StructuredOutputParser } from 'langchain/output_parsers'; import { z } from 'zod'; -import { getTracingConfig } from '../../../utils/tracing'; + +import { getTracingConfig } from '@utils/tracing'; const DEFAULT_SYSTEM_PROMPT_TEMPLATE = 'You are highly intelligent and accurate sentiment analyzer. Analyze the sentiment of the provided text. Categorize it into one of the following: {categories}. Use the provided formatting instructions. Only output the JSON.'; diff --git a/packages/@n8n/nodes-langchain/nodes/chains/TextClassifier/TextClassifier.node.ts b/packages/@n8n/nodes-langchain/nodes/chains/TextClassifier/TextClassifier.node.ts index 7afc317c37..298c41572d 100644 --- a/packages/@n8n/nodes-langchain/nodes/chains/TextClassifier/TextClassifier.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/chains/TextClassifier/TextClassifier.node.ts @@ -13,7 +13,7 @@ import type { } from 'n8n-workflow'; import { z } from 'zod'; -import { getTracingConfig } from '../../../utils/tracing'; +import { getTracingConfig } from '@utils/tracing'; const SYSTEM_PROMPT_TEMPLATE = "Please classify the text provided by the user into one of the following categories: {categories}, and use the provided formatting instructions below. Don't explain, and only output the json."; diff --git a/packages/@n8n/nodes-langchain/nodes/code/Code.node.ts b/packages/@n8n/nodes-langchain/nodes/code/Code.node.ts index d73d6d3268..dda3f24414 100644 --- a/packages/@n8n/nodes-langchain/nodes/code/Code.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/code/Code.node.ts @@ -1,4 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { Tool } from '@langchain/core/tools'; +import { makeResolverFromLegacyOptions } from '@n8n/vm2'; +import { JavaScriptSandbox } from 'n8n-nodes-base/dist/nodes/Code/JavaScriptSandbox'; +import { getSandboxContext } from 'n8n-nodes-base/dist/nodes/Code/Sandbox'; +import { standardizeOutput } from 'n8n-nodes-base/dist/nodes/Code/utils'; import { NodeOperationError, NodeConnectionType } from 'n8n-workflow'; import type { IExecuteFunctions, @@ -12,12 +17,7 @@ import type { // TODO: Add support for execute function. Got already started but got commented out -import { getSandboxContext } from 'n8n-nodes-base/dist/nodes/Code/Sandbox'; -import { JavaScriptSandbox } from 'n8n-nodes-base/dist/nodes/Code/JavaScriptSandbox'; -import { standardizeOutput } from 'n8n-nodes-base/dist/nodes/Code/utils'; -import type { Tool } from '@langchain/core/tools'; -import { makeResolverFromLegacyOptions } from '@n8n/vm2'; -import { logWrapper } from '../../utils/logWrapper'; +import { logWrapper } from '@utils/logWrapper'; const { NODE_FUNCTION_ALLOW_BUILTIN: builtIn, NODE_FUNCTION_ALLOW_EXTERNAL: external } = process.env; 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 2e68db4e69..5c9ebf08b0 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,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { TextSplitter } from '@langchain/textsplitters'; import { NodeConnectionType, type INodeType, @@ -7,11 +8,9 @@ import { type SupplyData, } from 'n8n-workflow'; -import type { TextSplitter } from '@langchain/textsplitters'; - -import { logWrapper } from '../../../utils/logWrapper'; -import { N8nBinaryLoader } from '../../../utils/N8nBinaryLoader'; -import { getConnectionHintNoticeField, metadataFilterField } from '../../../utils/sharedFields'; +import { logWrapper } from '@utils/logWrapper'; +import { N8nBinaryLoader } from '@utils/N8nBinaryLoader'; +import { getConnectionHintNoticeField, metadataFilterField } from '@utils/sharedFields'; // Dependencies needed underneath the hood for the loaders. We add them // here only to track where what dependency is sued 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 5e6457951e..1f5ad6228a 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,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { TextSplitter } from '@langchain/textsplitters'; import { NodeConnectionType, type INodeType, @@ -7,10 +8,9 @@ import { type SupplyData, } from 'n8n-workflow'; -import type { TextSplitter } from '@langchain/textsplitters'; -import { logWrapper } from '../../../utils/logWrapper'; -import { N8nBinaryLoader } from '../../../utils/N8nBinaryLoader'; -import { metadataFilterField } from '../../../utils/sharedFields'; +import { logWrapper } from '@utils/logWrapper'; +import { N8nBinaryLoader } from '@utils/N8nBinaryLoader'; +import { metadataFilterField } from '@utils/sharedFields'; // Dependencies needed underneath the hood for the loaders. We add them // here only to track where what dependency is sued @@ -18,7 +18,7 @@ import { metadataFilterField } from '../../../utils/sharedFields'; import 'mammoth'; // for docx import 'epub2'; // for epub import 'pdf-parse'; // for pdf -import { N8nJsonLoader } from '../../../utils/N8nJsonLoader'; +import { N8nJsonLoader } from '@utils/N8nJsonLoader'; export class DocumentDefaultDataLoader implements INodeType { description: INodeTypeDescription = { 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 71a77f013c..7d63e32f0b 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,4 +1,6 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { GithubRepoLoader } from '@langchain/community/document_loaders/web/github'; +import type { CharacterTextSplitter } from '@langchain/textsplitters'; import { NodeConnectionType, type INodeType, @@ -6,10 +8,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import { GithubRepoLoader } from '@langchain/community/document_loaders/web/github'; -import type { CharacterTextSplitter } from '@langchain/textsplitters'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class DocumentGithubLoader implements INodeType { description: INodeTypeDescription = { 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 2e8cb95a11..9c295ba144 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,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { TextSplitter } from '@langchain/textsplitters'; import { NodeConnectionType, type INodeType, @@ -7,10 +8,9 @@ import { type SupplyData, } from 'n8n-workflow'; -import type { TextSplitter } from '@langchain/textsplitters'; -import { logWrapper } from '../../../utils/logWrapper'; -import { N8nJsonLoader } from '../../../utils/N8nJsonLoader'; -import { getConnectionHintNoticeField, metadataFilterField } from '../../../utils/sharedFields'; +import { logWrapper } from '@utils/logWrapper'; +import { N8nJsonLoader } from '@utils/N8nJsonLoader'; +import { getConnectionHintNoticeField, metadataFilterField } from '@utils/sharedFields'; export class DocumentJsonInputLoader implements INodeType { description: INodeTypeDescription = { 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 6e0782f1c1..fdb2da5ce0 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAwsBedrock/EmbeddingsAwsBedrock.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAwsBedrock/EmbeddingsAwsBedrock.node.ts @@ -8,8 +8,8 @@ import { type SupplyData, } from 'n8n-workflow'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class EmbeddingsAwsBedrock implements INodeType { description: INodeTypeDescription = { 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 bf101292f2..65f493d578 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { OpenAIEmbeddings } from '@langchain/openai'; import { NodeConnectionType, type INodeType, @@ -7,9 +8,8 @@ import { type SupplyData, } from 'n8n-workflow'; -import { OpenAIEmbeddings } from '@langchain/openai'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class EmbeddingsAzureOpenAi implements INodeType { description: INodeTypeDescription = { 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 26e5d39b70..ebab22ec55 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { CohereEmbeddings } from '@langchain/cohere'; import { NodeConnectionType, type INodeType, @@ -6,9 +7,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import { CohereEmbeddings } from '@langchain/cohere'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class EmbeddingsCohere implements INodeType { description: INodeTypeDescription = { 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 2a455e4574..949d6ee24e 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { GoogleGenerativeAIEmbeddings } from '@langchain/google-genai'; import { NodeConnectionType, type INodeType, @@ -6,10 +7,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import { GoogleGenerativeAIEmbeddings } from '@langchain/google-genai'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class EmbeddingsGoogleGemini implements INodeType { description: INodeTypeDescription = { 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 c8317630c3..c8023354ef 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsHuggingFaceInference/EmbeddingsHuggingFaceInference.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsHuggingFaceInference/EmbeddingsHuggingFaceInference.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { HuggingFaceInferenceEmbeddings } from '@langchain/community/embeddings/hf'; import { NodeConnectionType, type INodeType, @@ -6,9 +7,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import { HuggingFaceInferenceEmbeddings } from '@langchain/community/embeddings/hf'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class EmbeddingsHuggingFaceInference implements INodeType { description: INodeTypeDescription = { 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 dbfb93b82e..553abfa406 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.ts @@ -1,4 +1,6 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { MistralAIEmbeddingsParams } from '@langchain/mistralai'; +import { MistralAIEmbeddings } from '@langchain/mistralai'; import { NodeConnectionType, type INodeType, @@ -6,10 +8,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import type { MistralAIEmbeddingsParams } from '@langchain/mistralai'; -import { MistralAIEmbeddings } from '@langchain/mistralai'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class EmbeddingsMistralCloud implements INodeType { description: INodeTypeDescription = { 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 d84aa537ec..08feb90309 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { OllamaEmbeddings } from '@langchain/ollama'; import { NodeConnectionType, type INodeType, @@ -6,9 +7,10 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import { OllamaEmbeddings } from '@langchain/ollama'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { ollamaDescription, ollamaModel } from '../../llms/LMOllama/description'; export class EmbeddingsOllama implements INodeType { 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 aececc09ae..fb5f67e30c 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { OpenAIEmbeddings } from '@langchain/openai'; import { NodeConnectionType, type INodeType, @@ -7,11 +8,10 @@ import { type ISupplyDataFunctions, type INodeProperties, } from 'n8n-workflow'; - import type { ClientOptions } from 'openai'; -import { OpenAIEmbeddings } from '@langchain/openai'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; const modelParameter: INodeProperties = { displayName: 'Model', 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 c575b59aa8..3a38ce3a31 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.ts @@ -12,9 +12,10 @@ import { type SupplyData, } from 'n8n-workflow'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; -import { N8nLlmTracing } from '../N8nLlmTracing'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; const modelField: INodeProperties = { displayName: 'Model', 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 354e54e27a..d4685fa802 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMChatOllama/LmChatOllama.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMChatOllama/LmChatOllama.node.ts @@ -1,4 +1,7 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ + +import type { ChatOllamaInput } from '@langchain/ollama'; +import { ChatOllama } from '@langchain/ollama'; import { NodeConnectionType, type INodeType, @@ -7,12 +10,11 @@ import { type SupplyData, } from 'n8n-workflow'; -import type { ChatOllamaInput } from '@langchain/ollama'; -import { ChatOllama } from '@langchain/ollama'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { ollamaModel, ollamaOptions, ollamaDescription } from '../LMOllama/description'; -import { N8nLlmTracing } from '../N8nLlmTracing'; import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; export class LmChatOllama implements INodeType { description: INodeTypeDescription = { 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 2e55e56722..f3dceb5dd1 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.ts @@ -9,7 +9,8 @@ import { type SupplyData, } from 'n8n-workflow'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { openAiFailedAttemptHandler } from '../../vendors/OpenAi/helpers/error-handling'; import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; import { N8nLlmTracing } from '../N8nLlmTracing'; 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 4b5f85f915..6b9559104b 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMCohere/LmCohere.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMCohere/LmCohere.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { Cohere } from '@langchain/cohere'; import { NodeConnectionType, type INodeType, @@ -7,10 +8,10 @@ import { type SupplyData, } from 'n8n-workflow'; -import { Cohere } from '@langchain/cohere'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; -import { N8nLlmTracing } from '../N8nLlmTracing'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; export class LmCohere implements INodeType { description: INodeTypeDescription = { 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 ddd565e3a9..21a7a0c50f 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMOllama/LmOllama.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMOllama/LmOllama.node.ts @@ -1,4 +1,6 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ + +import { Ollama } from '@langchain/community/llms/ollama'; import { NodeConnectionType, type INodeType, @@ -7,11 +9,11 @@ import { type SupplyData, } from 'n8n-workflow'; -import { Ollama } from '@langchain/community/llms/ollama'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; -import { N8nLlmTracing } from '../N8nLlmTracing'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { ollamaDescription, ollamaModel, ollamaOptions } from './description'; import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; export class LmOllama implements INodeType { description: INodeTypeDescription = { 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 41cb622294..1a64f07cca 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMOpenAi/LmOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMOpenAi/LmOpenAi.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { OpenAI, type ClientOptions } from '@langchain/openai'; import { NodeConnectionType } from 'n8n-workflow'; import type { INodeType, @@ -8,9 +9,8 @@ import type { ILoadOptionsFunctions, } from 'n8n-workflow'; -import { OpenAI, type ClientOptions } from '@langchain/openai'; -import { N8nLlmTracing } from '../N8nLlmTracing'; import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; type LmOpenAiOptions = { baseURL?: string; 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 7823c91b52..e393d86f8a 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMOpenHuggingFaceInference/LmOpenHuggingFaceInference.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMOpenHuggingFaceInference/LmOpenHuggingFaceInference.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { HuggingFaceInference } from '@langchain/community/llms/hf'; import { NodeConnectionType, type INodeType, @@ -7,10 +8,10 @@ import { type SupplyData, } from 'n8n-workflow'; -import { HuggingFaceInference } from '@langchain/community/llms/hf'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; -import { N8nLlmTracing } from '../N8nLlmTracing'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; export class LmOpenHuggingFaceInference implements INodeType { description: INodeTypeDescription = { 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 3d928ce801..ef15a531cf 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.ts @@ -8,9 +8,10 @@ import { type SupplyData, } from 'n8n-workflow'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; -import { N8nLlmTracing } from '../N8nLlmTracing'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; export class LmChatAwsBedrock implements INodeType { description: INodeTypeDescription = { 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 e2292abc77..5fc562153d 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { ChatOpenAI } from '@langchain/openai'; import { NodeConnectionType, type INodeType, @@ -7,10 +8,10 @@ import { type SupplyData, } from 'n8n-workflow'; -import { ChatOpenAI } from '@langchain/openai'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; -import { N8nLlmTracing } from '../N8nLlmTracing'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; export class LmChatAzureOpenAi implements INodeType { description: INodeTypeDescription = { 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 9bade1e26a..f8b7d2bb3e 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.ts @@ -1,4 +1,6 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { SafetySetting } from '@google/generative-ai'; +import { ChatGoogleGenerativeAI } from '@langchain/google-genai'; import { NodeConnectionType, type INodeType, @@ -6,12 +8,12 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import { ChatGoogleGenerativeAI } from '@langchain/google-genai'; -import type { SafetySetting } from '@google/generative-ai'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; -import { N8nLlmTracing } from '../N8nLlmTracing'; + +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { additionalOptions } from '../gemini-common/additional-options'; import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; export class LmChatGoogleGemini implements INodeType { description: INodeTypeDescription = { 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 92b51e534f..5ca6091378 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleVertex/LmChatGoogleVertex.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatGoogleVertex/LmChatGoogleVertex.node.ts @@ -1,4 +1,8 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { SafetySetting } from '@google/generative-ai'; +import { ProjectsClient } from '@google-cloud/resource-manager'; +import { ChatVertexAI } from '@langchain/google-vertexai'; +import { formatPrivateKey } from 'n8n-nodes-base/dist/utils/utilities'; import { NodeConnectionType, type INodeType, @@ -9,15 +13,13 @@ import { type JsonObject, NodeOperationError, } from 'n8n-workflow'; -import { ChatVertexAI } from '@langchain/google-vertexai'; -import type { SafetySetting } from '@google/generative-ai'; -import { ProjectsClient } from '@google-cloud/resource-manager'; -import { formatPrivateKey } from 'n8n-nodes-base/dist/utils/utilities'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; -import { N8nLlmTracing } from '../N8nLlmTracing'; -import { additionalOptions } from '../gemini-common/additional-options'; + +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { makeErrorFromStatus } from './error-handling'; +import { additionalOptions } from '../gemini-common/additional-options'; import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; export class LmChatGoogleVertex implements INodeType { description: INodeTypeDescription = { 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 1494dbcf55..fb859e3fce 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatGroq/LmChatGroq.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatGroq/LmChatGroq.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { ChatGroq } from '@langchain/groq'; import { NodeConnectionType, type INodeType, @@ -7,10 +8,10 @@ import { type SupplyData, } from 'n8n-workflow'; -import { ChatGroq } from '@langchain/groq'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; -import { N8nLlmTracing } from '../N8nLlmTracing'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; export class LmChatGroq implements INodeType { description: INodeTypeDescription = { 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 edd533b6ba..a23c2d4e9f 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.ts @@ -1,4 +1,7 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ + +import type { ChatMistralAIInput } from '@langchain/mistralai'; +import { ChatMistralAI } from '@langchain/mistralai'; import { NodeConnectionType, type INodeType, @@ -7,11 +10,10 @@ import { type SupplyData, } from 'n8n-workflow'; -import type { ChatMistralAIInput } from '@langchain/mistralai'; -import { ChatMistralAI } from '@langchain/mistralai'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; -import { N8nLlmTracing } from '../N8nLlmTracing'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; +import { N8nLlmTracing } from '../N8nLlmTracing'; export class LmChatMistralCloud implements INodeType { description: INodeTypeDescription = { diff --git a/packages/@n8n/nodes-langchain/nodes/llms/N8nLlmTracing.ts b/packages/@n8n/nodes-langchain/nodes/llms/N8nLlmTracing.ts index af60b72982..3d426309b7 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/N8nLlmTracing.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/N8nLlmTracing.ts @@ -9,11 +9,11 @@ import type { import type { BaseMessage } from '@langchain/core/messages'; import type { LLMResult } from '@langchain/core/outputs'; import { encodingForModel } from '@langchain/core/utils/tiktoken'; -import type { IDataObject, ISupplyDataFunctions, JsonObject } from 'n8n-workflow'; import { pick } from 'lodash'; +import type { IDataObject, ISupplyDataFunctions, JsonObject } from 'n8n-workflow'; import { NodeConnectionType, NodeError, NodeOperationError } from 'n8n-workflow'; -import { logAiEvent } from '../../utils/helpers'; +import { logAiEvent } from '@utils/helpers'; type TokensUsageParser = (llmOutput: LLMResult['llmOutput']) => { completionTokens: number; diff --git a/packages/@n8n/nodes-langchain/nodes/llms/gemini-common/additional-options.ts b/packages/@n8n/nodes-langchain/nodes/llms/gemini-common/additional-options.ts index 3fc1900b8a..f154b676c5 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/gemini-common/additional-options.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/gemini-common/additional-options.ts @@ -1,5 +1,6 @@ import type { HarmBlockThreshold, HarmCategory } from '@google/generative-ai'; import type { INodeProperties } from 'n8n-workflow'; + import { harmCategories, harmThresholds } from './safety-options'; export const additionalOptions: INodeProperties = { 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 28025f2884..480bed68f9 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts @@ -9,9 +9,10 @@ import { type SupplyData, } from 'n8n-workflow'; -import { getSessionId } from '../../../utils/helpers'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { getSessionId } from '@utils/helpers'; +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { sessionIdOption, sessionKeyProperty, diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryChatRetriever/MemoryChatRetriever.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryChatRetriever/MemoryChatRetriever.node.ts index f2bb0f43b0..fa54f25a16 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryChatRetriever/MemoryChatRetriever.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryChatRetriever/MemoryChatRetriever.node.ts @@ -1,4 +1,6 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { BaseChatMemory } from '@langchain/community/memory/chat_memory'; +import type { BaseMessage } from '@langchain/core/messages'; import { NodeConnectionType, type IDataObject, @@ -7,8 +9,6 @@ import { type INodeType, type INodeTypeDescription, } from 'n8n-workflow'; -import type { BaseChatMemory } from '@langchain/community/memory/chat_memory'; -import type { BaseMessage } from '@langchain/core/messages'; function simplifyMessages(messages: BaseMessage[]) { const chunkedMessages = []; diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryManager/MemoryManager.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryManager/MemoryManager.node.ts index 04d6035e7f..964da65475 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryManager/MemoryManager.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryManager/MemoryManager.node.ts @@ -1,4 +1,6 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { BaseChatMemory } from '@langchain/community/memory/chat_memory'; +import { AIMessage, SystemMessage, HumanMessage, type BaseMessage } from '@langchain/core/messages'; import { NodeConnectionType } from 'n8n-workflow'; import type { IDataObject, @@ -7,8 +9,6 @@ import type { INodeType, INodeTypeDescription, } from 'n8n-workflow'; -import type { BaseChatMemory } from '@langchain/community/memory/chat_memory'; -import { AIMessage, SystemMessage, HumanMessage, type BaseMessage } from '@langchain/core/messages'; type MessageRole = 'ai' | 'system' | 'user'; interface MessageRecord { 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 a326f4c1be..f5184d7e93 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryMotorhead/MemoryMotorhead.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryMotorhead/MemoryMotorhead.node.ts @@ -8,9 +8,10 @@ import { type SupplyData, } from 'n8n-workflow'; -import { getSessionId } from '../../../utils/helpers'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { getSessionId } from '@utils/helpers'; +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { expressionSessionKeyProperty, sessionIdOption, sessionKeyProperty } from '../descriptions'; export class MemoryMotorhead implements INodeType { 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 b3d5f2f409..18fd76e3c5 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts @@ -13,9 +13,10 @@ import type { import { NodeConnectionType } from 'n8n-workflow'; import type pg from 'pg'; -import { getSessionId } from '../../../utils/helpers'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { getSessionId } from '@utils/helpers'; +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { sessionIdOption, sessionKeyProperty, 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 09208d96f7..ab7d02e2c4 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts @@ -13,9 +13,10 @@ import { import type { RedisClientOptions } from 'redis'; import { createClient } from 'redis'; -import { getSessionId } from '../../../utils/helpers'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { getSessionId } from '@utils/helpers'; +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { sessionIdOption, sessionKeyProperty, 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 c48f32976b..c1ad7b9539 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryXata/MemoryXata.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryXata/MemoryXata.node.ts @@ -10,9 +10,10 @@ import type { SupplyData, } from 'n8n-workflow'; -import { getSessionId } from '../../../utils/helpers'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { getSessionId } from '@utils/helpers'; +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { sessionIdOption, sessionKeyProperty, 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 3c9ab307e2..1943f41c03 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryZep/MemoryZep.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryZep/MemoryZep.node.ts @@ -1,4 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { BaseChatMemory } from '@langchain/community/dist/memory/chat_memory'; +import { ZepMemory } from '@langchain/community/memory/zep'; +import { ZepCloudMemory } from '@langchain/community/memory/zep_cloud'; +import type { InputValues, MemoryVariables } from '@langchain/core/memory'; +import type { BaseMessage } from '@langchain/core/messages'; import { NodeConnectionType, type ISupplyDataFunctions, @@ -7,16 +12,12 @@ import { type SupplyData, NodeOperationError, } from 'n8n-workflow'; -import { ZepMemory } from '@langchain/community/memory/zep'; -import { ZepCloudMemory } from '@langchain/community/memory/zep_cloud'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { getSessionId } from '@utils/helpers'; +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { expressionSessionKeyProperty, sessionIdOption, sessionKeyProperty } from '../descriptions'; -import { getSessionId } from '../../../utils/helpers'; -import type { BaseChatMemory } from '@langchain/community/dist/memory/chat_memory'; -import type { InputValues, MemoryVariables } from '@langchain/core/memory'; -import type { BaseMessage } from '@langchain/core/messages'; // Extend ZepCloudMemory to trim white space in messages. class WhiteSpaceTrimmedZepCloudMemory extends ZepCloudMemory { 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 4f385e1770..0ccf4c27c0 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 @@ -8,12 +8,13 @@ import type { SupplyData, } from 'n8n-workflow'; -import { NAIVE_FIX_PROMPT } from './prompt'; import { N8nOutputFixingParser, type N8nStructuredOutputParser, -} from '../../../utils/output_parsers/N8nOutputParser'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +} from '@utils/output_parsers/N8nOutputParser'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + +import { NAIVE_FIX_PROMPT } from './prompt'; export class OutputParserAutofixing implements INodeType { description: INodeTypeDescription = { diff --git a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/test/OutputParserAutofixing.node.test.ts b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/test/OutputParserAutofixing.node.test.ts index 9fcae1a8fa..45f054a34b 100644 --- a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/test/OutputParserAutofixing.node.test.ts +++ b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/test/OutputParserAutofixing.node.test.ts @@ -11,7 +11,8 @@ import { ApplicationError, NodeConnectionType, NodeOperationError } from 'n8n-wo import type { N8nOutputFixingParser, N8nStructuredOutputParser, -} from '../../../../utils/output_parsers/N8nOutputParser'; +} from '@utils/output_parsers/N8nOutputParser'; + import { OutputParserAutofixing } from '../OutputParserAutofixing.node'; import { NAIVE_FIX_PROMPT } from '../prompt'; 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 b613c14775..696a6be79c 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 @@ -7,8 +7,8 @@ import { type SupplyData, } from 'n8n-workflow'; -import { N8nItemListOutputParser } from '../../../utils/output_parsers/N8nItemListOutputParser'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { N8nItemListOutputParser } from '@utils/output_parsers/N8nItemListOutputParser'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class OutputParserItemList implements INodeType { description: INodeTypeDescription = { diff --git a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserItemList/test/OutputParserItemList.node.test.ts b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserItemList/test/OutputParserItemList.node.test.ts index c8ac869169..ae31e88353 100644 --- a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserItemList/test/OutputParserItemList.node.test.ts +++ b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserItemList/test/OutputParserItemList.node.test.ts @@ -6,7 +6,8 @@ import { type IWorkflowDataProxyData, } from 'n8n-workflow'; -import { N8nItemListOutputParser } from '../../../../utils/output_parsers/N8nItemListOutputParser'; +import { N8nItemListOutputParser } from '@utils/output_parsers/N8nItemListOutputParser'; + import { OutputParserItemList } from '../OutputParserItemList.node'; describe('OutputParserItemList', () => { 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 c35cb1d145..8da4cb05d8 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 @@ -10,14 +10,10 @@ import { } from 'n8n-workflow'; import type { z } from 'zod'; -import { - inputSchemaField, - jsonSchemaExampleField, - schemaTypeField, -} from '../../../utils/descriptions'; -import { N8nStructuredOutputParser } from '../../../utils/output_parsers/N8nOutputParser'; -import { convertJsonSchemaToZod, generateSchema } from '../../../utils/schemaParsing'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; +import { inputSchemaField, jsonSchemaExampleField, schemaTypeField } from '@utils/descriptions'; +import { N8nStructuredOutputParser } from '@utils/output_parsers/N8nOutputParser'; +import { convertJsonSchemaToZod, generateSchema } from '@utils/schemaParsing'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class OutputParserStructured implements INodeType { description: INodeTypeDescription = { diff --git a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserStructured/test/OutputParserStructured.node.test.ts b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserStructured/test/OutputParserStructured.node.test.ts index af72c49d7e..e07b012ec6 100644 --- a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserStructured/test/OutputParserStructured.node.test.ts +++ b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserStructured/test/OutputParserStructured.node.test.ts @@ -7,7 +7,8 @@ import { type IWorkflowDataProxyData, } from 'n8n-workflow'; -import type { N8nStructuredOutputParser } from '../../../../utils/output_parsers/N8nStructuredOutputParser'; +import type { N8nStructuredOutputParser } from '@utils/output_parsers/N8nStructuredOutputParser'; + import { OutputParserStructured } from '../OutputParserStructured.node'; describe('OutputParserStructured', () => { 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 8017caa1ad..74db608551 100644 --- a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.ts @@ -1,4 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ + +import type { BaseLanguageModel } from '@langchain/core/language_models/base'; +import type { BaseRetriever } from '@langchain/core/retrievers'; +import { ContextualCompressionRetriever } from 'langchain/retrievers/contextual_compression'; +import { LLMChainExtractor } from 'langchain/retrievers/document_compressors/chain_extract'; import { NodeConnectionType, type INodeType, @@ -7,12 +12,7 @@ import { type SupplyData, } from 'n8n-workflow'; -import { ContextualCompressionRetriever } from 'langchain/retrievers/contextual_compression'; -import { LLMChainExtractor } from 'langchain/retrievers/document_compressors/chain_extract'; -import type { BaseLanguageModel } from '@langchain/core/language_models/base'; -import type { BaseRetriever } from '@langchain/core/retrievers'; - -import { logWrapper } from '../../../utils/logWrapper'; +import { logWrapper } from '@utils/logWrapper'; export class RetrieverContextualCompression implements INodeType { description: INodeTypeDescription = { 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 f814ba875e..3805eb5374 100644 --- a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.ts @@ -1,4 +1,8 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ + +import type { BaseLanguageModel } from '@langchain/core/language_models/base'; +import type { BaseRetriever } from '@langchain/core/retrievers'; +import { MultiQueryRetriever } from 'langchain/retrievers/multi_query'; import { NodeConnectionType, type INodeType, @@ -7,11 +11,7 @@ import { type SupplyData, } from 'n8n-workflow'; -import { MultiQueryRetriever } from 'langchain/retrievers/multi_query'; -import type { BaseLanguageModel } from '@langchain/core/language_models/base'; -import type { BaseRetriever } from '@langchain/core/retrievers'; - -import { logWrapper } from '../../../utils/logWrapper'; +import { logWrapper } from '@utils/logWrapper'; export class RetrieverMultiQuery implements INodeType { description: INodeTypeDescription = { 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 5e79a6a754..74f88e5561 100644 --- a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { VectorStore } from '@langchain/core/vectorstores'; import { NodeConnectionType, type INodeType, @@ -6,8 +7,8 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import type { VectorStore } from '@langchain/core/vectorstores'; -import { logWrapper } from '../../../utils/logWrapper'; + +import { logWrapper } from '@utils/logWrapper'; export class RetrieverVectorStore implements INodeType { description: INodeTypeDescription = { 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 bbee553999..5e9fecd47a 100644 --- a/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverWorkflow/RetrieverWorkflow.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/retrievers/RetrieverWorkflow/RetrieverWorkflow.node.ts @@ -1,4 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { CallbackManagerForRetrieverRun } from '@langchain/core/callbacks/manager'; +import { Document } from '@langchain/core/documents'; +import { BaseRetriever, type BaseRetrieverInput } from '@langchain/core/retrievers'; +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 { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; import type { IDataObject, @@ -13,13 +18,7 @@ import type { ExecuteWorkflowData, } from 'n8n-workflow'; -import { BaseRetriever, type BaseRetrieverInput } from '@langchain/core/retrievers'; -import { Document } from '@langchain/core/documents'; - -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 { CallbackManagerForRetrieverRun } from '@langchain/core/callbacks/manager'; -import { logWrapper } from '../../../utils/logWrapper'; +import { logWrapper } from '@utils/logWrapper'; function objectToString(obj: Record | IDataObject, level = 0) { let result = ''; 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 f62e8f01f1..c78bd39a6c 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,4 +1,6 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { CharacterTextSplitterParams } from '@langchain/textsplitters'; +import { CharacterTextSplitter } from '@langchain/textsplitters'; import { NodeConnectionType, type INodeType, @@ -6,10 +8,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import type { CharacterTextSplitterParams } from '@langchain/textsplitters'; -import { CharacterTextSplitter } from '@langchain/textsplitters'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class TextSplitterCharacterTextSplitter implements INodeType { description: INodeTypeDescription = { 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 21a0520766..cfe8a32757 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,4 +1,9 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { + RecursiveCharacterTextSplitterParams, + SupportedTextSplitterLanguage, +} from '@langchain/textsplitters'; +import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters'; import { NodeConnectionType, type INodeType, @@ -6,13 +11,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import type { - RecursiveCharacterTextSplitterParams, - SupportedTextSplitterLanguage, -} from '@langchain/textsplitters'; -import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; const supportedLanguages: SupportedTextSplitterLanguage[] = [ 'cpp', 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 247d142fa8..cd881916d6 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,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { TokenTextSplitter } from '@langchain/textsplitters'; import { NodeConnectionType, type INodeType, @@ -6,9 +7,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import { TokenTextSplitter } from '@langchain/textsplitters'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class TextSplitterTokenSplitter implements INodeType { description: INodeTypeDescription = { 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 f50a6216c0..b3ed23c576 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolCalculator/ToolCalculator.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolCalculator/ToolCalculator.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { Calculator } from '@langchain/community/tools/calculator'; import { NodeConnectionType, type INodeType, @@ -6,9 +7,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import { Calculator } from '@langchain/community/tools/calculator'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class ToolCalculator implements INodeType { description: INodeTypeDescription = { 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 1491662e61..214d4ed82a 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolCode/ToolCode.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolCode/ToolCode.node.ts @@ -15,14 +15,11 @@ import type { } from 'n8n-workflow'; import { jsonParse, NodeConnectionType, NodeOperationError } from 'n8n-workflow'; +import { inputSchemaField, jsonSchemaExampleField, schemaTypeField } from '@utils/descriptions'; +import { convertJsonSchemaToZod, generateSchema } from '@utils/schemaParsing'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import type { DynamicZodObject } from '../../../types/zod.types'; -import { - inputSchemaField, - jsonSchemaExampleField, - schemaTypeField, -} from '../../../utils/descriptions'; -import { convertJsonSchemaToZod, generateSchema } from '../../../utils/schemaParsing'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; export class ToolCode implements INodeType { description: INodeTypeDescription = { 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 f279c1e751..bfdd3e7ace 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/ToolHttpRequest.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/ToolHttpRequest.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { DynamicTool } from '@langchain/core/tools'; import type { INodeType, INodeTypeDescription, @@ -9,19 +10,8 @@ import type { } from 'n8n-workflow'; import { NodeConnectionType, NodeOperationError, tryToParseAlphanumericString } from 'n8n-workflow'; -import { DynamicTool } from '@langchain/core/tools'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; - -import { N8nTool } from '../../../utils/N8nTool'; -import { - configureHttpRequestFunction, - configureResponseOptimizer, - extractParametersFromText, - prepareToolDescription, - configureToolFunction, - updateParametersAndOptions, - makeToolInputSchema, -} from './utils'; +import { N8nTool } from '@utils/N8nTool'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; import { authenticationProperties, @@ -31,8 +21,16 @@ import { placeholderDefinitionsCollection, specifyBySelector, } from './descriptions'; - import type { PlaceholderDefinition, ToolParameter } from './interfaces'; +import { + configureHttpRequestFunction, + configureResponseOptimizer, + extractParametersFromText, + prepareToolDescription, + configureToolFunction, + updateParametersAndOptions, + makeToolInputSchema, +} from './utils'; export class ToolHttpRequest implements INodeType { description: INodeTypeDescription = { diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/test/ToolHttpRequest.node.test.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/test/ToolHttpRequest.node.test.ts index 1a99896fff..05ed1e619c 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/test/ToolHttpRequest.node.test.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/test/ToolHttpRequest.node.test.ts @@ -2,7 +2,8 @@ import { mock } from 'jest-mock-extended'; import type { IExecuteFunctions, INode } from 'n8n-workflow'; import { jsonParse } from 'n8n-workflow'; -import type { N8nTool } from '../../../../utils/N8nTool'; +import type { N8nTool } from '@utils/N8nTool'; + import { ToolHttpRequest } from '../ToolHttpRequest.node'; describe('ToolHttpRequest', () => { 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 709b06b7ac..7a7a09b933 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolSerpApi/ToolSerpApi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolSerpApi/ToolSerpApi.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { SerpAPI } from '@langchain/community/tools/serpapi'; import { NodeConnectionType, type INodeType, @@ -6,9 +7,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import { SerpAPI } from '@langchain/community/tools/serpapi'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class ToolSerpApi implements INodeType { description: INodeTypeDescription = { 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 6f4aa19fb3..4b539e7e85 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolVectorStore/ToolVectorStore.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolVectorStore/ToolVectorStore.node.ts @@ -1,3 +1,7 @@ +import type { BaseLanguageModel } from '@langchain/core/language_models/base'; +import type { VectorStore } from '@langchain/core/vectorstores'; +import { VectorDBQAChain } from 'langchain/chains'; +import { VectorStoreQATool } from 'langchain/tools'; import type { INodeType, INodeTypeDescription, @@ -6,12 +10,8 @@ import type { } from 'n8n-workflow'; import { NodeConnectionType } from 'n8n-workflow'; -import { VectorStoreQATool } from 'langchain/tools'; -import type { VectorStore } from '@langchain/core/vectorstores'; -import type { BaseLanguageModel } from '@langchain/core/language_models/base'; -import { VectorDBQAChain } from 'langchain/chains'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; -import { logWrapper } from '../../../utils/logWrapper'; +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class ToolVectorStore implements INodeType { description: INodeTypeDescription = { 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 e462e38feb..4eef3a1b45 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolWikipedia/ToolWikipedia.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolWikipedia/ToolWikipedia.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { WikipediaQueryRun } from '@langchain/community/tools/wikipedia_query_run'; import { NodeConnectionType, type INodeType, @@ -6,9 +7,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import { WikipediaQueryRun } from '@langchain/community/tools/wikipedia_query_run'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class ToolWikipedia implements INodeType { description: INodeTypeDescription = { 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 93290e63ad..162b78ba8e 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.ts @@ -1,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import { WolframAlphaTool } from '@langchain/community/tools/wolframalpha'; import { NodeConnectionType, type INodeType, @@ -6,9 +7,9 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import { WolframAlphaTool } from '@langchain/community/tools/wolframalpha'; -import { logWrapper } from '../../../utils/logWrapper'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; + +import { logWrapper } from '@utils/logWrapper'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; export class ToolWolframAlpha implements INodeType { description: INodeTypeDescription = { 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 d85ff72271..6b09cbfc88 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/ToolWorkflow.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/ToolWorkflow.node.ts @@ -21,14 +21,11 @@ import type { } from 'n8n-workflow'; import { NodeConnectionType, NodeOperationError, jsonParse } from 'n8n-workflow'; +import { jsonSchemaExampleField, schemaTypeField, inputSchemaField } from '@utils/descriptions'; +import { convertJsonSchemaToZod, generateSchema } from '@utils/schemaParsing'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import type { DynamicZodObject } from '../../../types/zod.types'; -import { - jsonSchemaExampleField, - schemaTypeField, - inputSchemaField, -} from '../../../utils/descriptions'; -import { convertJsonSchemaToZod, generateSchema } from '../../../utils/schemaParsing'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; export class ToolWorkflow implements INodeType { description: INodeTypeDescription = { diff --git a/packages/@n8n/nodes-langchain/nodes/trigger/ChatTrigger/GenericFunctions.ts b/packages/@n8n/nodes-langchain/nodes/trigger/ChatTrigger/GenericFunctions.ts index 02620ab797..c065569eb2 100644 --- a/packages/@n8n/nodes-langchain/nodes/trigger/ChatTrigger/GenericFunctions.ts +++ b/packages/@n8n/nodes-langchain/nodes/trigger/ChatTrigger/GenericFunctions.ts @@ -1,5 +1,6 @@ -import type { ICredentialDataDecryptedObject, IWebhookFunctions } from 'n8n-workflow'; import basicAuth from 'basic-auth'; +import type { ICredentialDataDecryptedObject, IWebhookFunctions } from 'n8n-workflow'; + import { ChatTriggerAuthorizationError } from './error'; import type { AuthenticationChatOption } from './types'; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.ts index 5508f957f8..dc99db630d 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.ts @@ -1,4 +1,5 @@ import type { INodeProperties } from 'n8n-workflow'; + import { createVectorStoreNode } from '../shared/createVectorStoreNode'; import { MemoryVectorStoreManager } from '../shared/MemoryVectorStoreManager'; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemoryInsert/VectorStoreInMemoryInsert.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemoryInsert/VectorStoreInMemoryInsert.node.ts index 225201a5e1..34d4815034 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemoryInsert/VectorStoreInMemoryInsert.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemoryInsert/VectorStoreInMemoryInsert.node.ts @@ -1,4 +1,6 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { Embeddings } from '@langchain/core/embeddings'; +import type { Document } from 'langchain/document'; import { NodeConnectionType, type INodeExecutionData, @@ -6,11 +8,11 @@ import { type INodeType, type INodeTypeDescription, } from 'n8n-workflow'; -import type { Document } from 'langchain/document'; -import type { Embeddings } from '@langchain/core/embeddings'; -import type { N8nJsonLoader } from '../../../utils/N8nJsonLoader'; -import { processDocuments } from '../shared/processDocuments'; + +import type { N8nJsonLoader } from '@utils/N8nJsonLoader'; + import { MemoryVectorStoreManager } from '../shared/MemoryVectorStoreManager'; +import { processDocuments } from '../shared/processDocuments'; // This node is deprecated. Use VectorStoreInMemory instead. export class VectorStoreInMemoryInsert implements INodeType { 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 7bf48c3d8c..dd2def31e3 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,4 +1,5 @@ /* eslint-disable n8n-nodes-base/node-dirname-against-convention */ +import type { Embeddings } from '@langchain/core/embeddings'; import { NodeConnectionType, type INodeType, @@ -6,9 +7,10 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import type { Embeddings } from '@langchain/core/embeddings'; + +import { logWrapper } from '@utils/logWrapper'; + import { MemoryVectorStoreManager } from '../shared/MemoryVectorStoreManager'; -import { logWrapper } from '../../../utils/logWrapper'; // This node is deprecated. Use VectorStoreInMemory instead. export class VectorStoreInMemoryLoad implements INodeType { diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.ts index 8336958cc5..6d5da1615b 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.ts @@ -9,7 +9,8 @@ import { configurePostgres } from 'n8n-nodes-base/dist/nodes/Postgres/v2/transpo import type { INodeProperties } from 'n8n-workflow'; import type pg from 'pg'; -import { metadataFilterField } from '../../../utils/sharedFields'; +import { metadataFilterField } from '@utils/sharedFields'; + import { createVectorStoreNode } from '../shared/createVectorStoreNode'; type CollectionOptions = { diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePinecone/VectorStorePinecone.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePinecone/VectorStorePinecone.node.ts index d153979ef4..6e684ebed3 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePinecone/VectorStorePinecone.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePinecone/VectorStorePinecone.node.ts @@ -1,9 +1,11 @@ -import { NodeOperationError, type INodeProperties } from 'n8n-workflow'; import type { PineconeStoreParams } from '@langchain/pinecone'; import { PineconeStore } from '@langchain/pinecone'; import { Pinecone } from '@pinecone-database/pinecone'; +import { NodeOperationError, type INodeProperties } from 'n8n-workflow'; + +import { metadataFilterField } from '@utils/sharedFields'; + import { createVectorStoreNode } from '../shared/createVectorStoreNode'; -import { metadataFilterField } from '../../../utils/sharedFields'; import { pineconeIndexRLC } from '../shared/descriptions'; import { pineconeIndexSearch } from '../shared/methods/listSearch'; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePineconeInsert/VectorStorePineconeInsert.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePineconeInsert/VectorStorePineconeInsert.node.ts index 023b65be84..6c10ff1427 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePineconeInsert/VectorStorePineconeInsert.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePineconeInsert/VectorStorePineconeInsert.node.ts @@ -1,3 +1,7 @@ +import type { Document } from '@langchain/core/documents'; +import type { Embeddings } from '@langchain/core/embeddings'; +import { PineconeStore } from '@langchain/pinecone'; +import { Pinecone } from '@pinecone-database/pinecone'; import { type IExecuteFunctions, type INodeType, @@ -5,15 +9,12 @@ import { type INodeExecutionData, NodeConnectionType, } from 'n8n-workflow'; -import type { Embeddings } from '@langchain/core/embeddings'; -import type { Document } from '@langchain/core/documents'; -import { PineconeStore } from '@langchain/pinecone'; -import { Pinecone } from '@pinecone-database/pinecone'; -import type { N8nJsonLoader } from '../../../utils/N8nJsonLoader'; -import { processDocuments } from '../shared/processDocuments'; +import type { N8nJsonLoader } from '@utils/N8nJsonLoader'; + import { pineconeIndexRLC } from '../shared/descriptions'; import { pineconeIndexSearch } from '../shared/methods/listSearch'; +import { processDocuments } from '../shared/processDocuments'; // This node is deprecated. Use VectorStorePinecone instead. export class VectorStorePineconeInsert implements INodeType { 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 d46bccd9f7..54eea2e902 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,3 +1,7 @@ +import type { Embeddings } from '@langchain/core/embeddings'; +import type { PineconeStoreParams } from '@langchain/pinecone'; +import { PineconeStore } from '@langchain/pinecone'; +import { Pinecone } from '@pinecone-database/pinecone'; import { NodeConnectionType, type INodeType, @@ -5,14 +9,11 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import type { PineconeStoreParams } from '@langchain/pinecone'; -import { PineconeStore } from '@langchain/pinecone'; -import { Pinecone } from '@pinecone-database/pinecone'; -import type { Embeddings } from '@langchain/core/embeddings'; -import { logWrapper } from '../../../utils/logWrapper'; -import { metadataFilterField } from '../../../utils/sharedFields'; -import { getMetadataFiltersValues } from '../../../utils/helpers'; +import { getMetadataFiltersValues } from '@utils/helpers'; +import { logWrapper } from '@utils/logWrapper'; +import { metadataFilterField } from '@utils/sharedFields'; + import { pineconeIndexRLC } from '../shared/descriptions'; import { pineconeIndexSearch } from '../shared/methods/listSearch'; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.ts index 0b5859e0bc..988f607ad7 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.ts @@ -1,12 +1,13 @@ -import type { IDataObject, INodeProperties } from 'n8n-workflow'; +import type { Callbacks } from '@langchain/core/callbacks/manager'; +import type { Embeddings } from '@langchain/core/embeddings'; import type { QdrantLibArgs } from '@langchain/qdrant'; import { QdrantVectorStore } from '@langchain/qdrant'; import type { Schemas as QdrantSchemas } from '@qdrant/js-client-rest'; +import type { IDataObject, INodeProperties } from 'n8n-workflow'; + import { createVectorStoreNode } from '../shared/createVectorStoreNode'; import { qdrantCollectionRLC } from '../shared/descriptions'; import { qdrantCollectionsSearch } from '../shared/methods/listSearch'; -import type { Embeddings } from '@langchain/core/embeddings'; -import type { Callbacks } from '@langchain/core/callbacks/manager'; class ExtendedQdrantVectorStore extends QdrantVectorStore { private static defaultFilter: IDataObject = {}; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabase/VectorStoreSupabase.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabase/VectorStoreSupabase.node.ts index 549fcd5e7f..b1b80fea5a 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabase/VectorStoreSupabase.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabase/VectorStoreSupabase.node.ts @@ -1,8 +1,10 @@ -import { NodeOperationError, type INodeProperties } from 'n8n-workflow'; -import { createClient } from '@supabase/supabase-js'; import { SupabaseVectorStore } from '@langchain/community/vectorstores/supabase'; +import { createClient } from '@supabase/supabase-js'; +import { NodeOperationError, type INodeProperties } from 'n8n-workflow'; + +import { metadataFilterField } from '@utils/sharedFields'; + import { createVectorStoreNode } from '../shared/createVectorStoreNode'; -import { metadataFilterField } from '../../../utils/sharedFields'; import { supabaseTableNameRLC } from '../shared/descriptions'; import { supabaseTableNameSearch } from '../shared/methods/listSearch'; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabaseInsert/VectorStoreSupabaseInsert.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabaseInsert/VectorStoreSupabaseInsert.node.ts index 44b3a6a397..332f534fe6 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabaseInsert/VectorStoreSupabaseInsert.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreSupabaseInsert/VectorStoreSupabaseInsert.node.ts @@ -1,3 +1,7 @@ +import { SupabaseVectorStore } from '@langchain/community/vectorstores/supabase'; +import type { Document } from '@langchain/core/documents'; +import type { Embeddings } from '@langchain/core/embeddings'; +import { createClient } from '@supabase/supabase-js'; import { type IExecuteFunctions, type INodeType, @@ -5,15 +9,12 @@ import { type INodeExecutionData, NodeConnectionType, } from 'n8n-workflow'; -import type { Embeddings } from '@langchain/core/embeddings'; -import type { Document } from '@langchain/core/documents'; -import { createClient } from '@supabase/supabase-js'; -import { SupabaseVectorStore } from '@langchain/community/vectorstores/supabase'; -import type { N8nJsonLoader } from '../../../utils/N8nJsonLoader'; -import { processDocuments } from '../shared/processDocuments'; +import type { N8nJsonLoader } from '@utils/N8nJsonLoader'; + import { supabaseTableNameRLC } from '../shared/descriptions'; import { supabaseTableNameSearch } from '../shared/methods/listSearch'; +import { processDocuments } from '../shared/processDocuments'; // This node is deprecated. Use VectorStoreSupabase instead. export class VectorStoreSupabaseInsert implements INodeType { 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 f4bdc49e44..eae056adb9 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,3 +1,7 @@ +import type { SupabaseLibArgs } from '@langchain/community/vectorstores/supabase'; +import { SupabaseVectorStore } from '@langchain/community/vectorstores/supabase'; +import type { Embeddings } from '@langchain/core/embeddings'; +import { createClient } from '@supabase/supabase-js'; import { type INodeType, type INodeTypeDescription, @@ -5,13 +9,11 @@ import { type SupplyData, NodeConnectionType, } from 'n8n-workflow'; -import type { Embeddings } from '@langchain/core/embeddings'; -import { createClient } from '@supabase/supabase-js'; -import type { SupabaseLibArgs } from '@langchain/community/vectorstores/supabase'; -import { SupabaseVectorStore } from '@langchain/community/vectorstores/supabase'; -import { logWrapper } from '../../../utils/logWrapper'; -import { metadataFilterField } from '../../../utils/sharedFields'; -import { getMetadataFiltersValues } from '../../../utils/helpers'; + +import { getMetadataFiltersValues } from '@utils/helpers'; +import { logWrapper } from '@utils/logWrapper'; +import { metadataFilterField } from '@utils/sharedFields'; + import { supabaseTableNameRLC } from '../shared/descriptions'; import { supabaseTableNameSearch } from '../shared/methods/listSearch'; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.ts index 184b720d31..d6e8914ae5 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.ts @@ -1,9 +1,11 @@ -import type { IDataObject, INodeProperties } from 'n8n-workflow'; -import { NodeOperationError } from 'n8n-workflow'; import type { IZepConfig } from '@langchain/community/vectorstores/zep'; import { ZepVectorStore } from '@langchain/community/vectorstores/zep'; +import type { IDataObject, INodeProperties } from 'n8n-workflow'; +import { NodeOperationError } from 'n8n-workflow'; + +import { metadataFilterField } from '@utils/sharedFields'; + import { createVectorStoreNode } from '../shared/createVectorStoreNode'; -import { metadataFilterField } from '../../../utils/sharedFields'; const embeddingDimensions: INodeProperties = { displayName: 'Embedding Dimensions', diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepInsert/VectorStoreZepInsert.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepInsert/VectorStoreZepInsert.node.ts index 3b40e07d65..4892d8ad85 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepInsert/VectorStoreZepInsert.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepInsert/VectorStoreZepInsert.node.ts @@ -1,3 +1,6 @@ +import { ZepVectorStore } from '@langchain/community/vectorstores/zep'; +import type { Document } from '@langchain/core/documents'; +import type { Embeddings } from '@langchain/core/embeddings'; import { type IExecuteFunctions, type INodeType, @@ -5,10 +8,9 @@ import { type INodeExecutionData, NodeConnectionType, } from 'n8n-workflow'; -import { ZepVectorStore } from '@langchain/community/vectorstores/zep'; -import type { Embeddings } from '@langchain/core/embeddings'; -import type { Document } from '@langchain/core/documents'; -import type { N8nJsonLoader } from '../../../utils/N8nJsonLoader'; + +import type { N8nJsonLoader } from '@utils/N8nJsonLoader'; + import { processDocuments } from '../shared/processDocuments'; // This node is deprecated. Use VectorStoreZep instead. 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 dd30a0808e..040b845e57 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,3 +1,6 @@ +import type { IZepConfig } from '@langchain/community/vectorstores/zep'; +import { ZepVectorStore } from '@langchain/community/vectorstores/zep'; +import type { Embeddings } from '@langchain/core/embeddings'; import { NodeConnectionType, type INodeType, @@ -5,12 +8,10 @@ import { type ISupplyDataFunctions, type SupplyData, } from 'n8n-workflow'; -import type { IZepConfig } from '@langchain/community/vectorstores/zep'; -import { ZepVectorStore } from '@langchain/community/vectorstores/zep'; -import type { Embeddings } from '@langchain/core/embeddings'; -import { metadataFilterField } from '../../../utils/sharedFields'; -import { getMetadataFiltersValues } from '../../../utils/helpers'; -import { logWrapper } from '../../../utils/logWrapper'; + +import { getMetadataFiltersValues } from '@utils/helpers'; +import { logWrapper } from '@utils/logWrapper'; +import { metadataFilterField } from '@utils/sharedFields'; // This node is deprecated. Use VectorStoreZep instead. export class VectorStoreZepLoad implements INodeType { diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/MemoryVectorStoreManager.test.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/MemoryVectorStoreManager.test.ts index 6229868f32..1088505a0a 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/MemoryVectorStoreManager.test.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/MemoryVectorStoreManager.test.ts @@ -1,7 +1,7 @@ import type { OpenAIEmbeddings } from '@langchain/openai'; +import { mock } from 'jest-mock-extended'; import { MemoryVectorStoreManager } from './MemoryVectorStoreManager'; -import { mock } from 'jest-mock-extended'; describe('MemoryVectorStoreManager', () => { it('should create an instance of 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 2de9304fc5..6d4abfb0cd 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/createVectorStoreNode.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/createVectorStoreNode.ts @@ -19,12 +19,13 @@ import type { INodePropertyOptions, } from 'n8n-workflow'; +import { getMetadataFiltersValues, logAiEvent } from '@utils/helpers'; +import { logWrapper } from '@utils/logWrapper'; +import type { N8nBinaryLoader } from '@utils/N8nBinaryLoader'; +import { N8nJsonLoader } from '@utils/N8nJsonLoader'; +import { getConnectionHintNoticeField } from '@utils/sharedFields'; + import { processDocument } from './processDocuments'; -import { getMetadataFiltersValues, logAiEvent } from '../../../utils/helpers'; -import { logWrapper } from '../../../utils/logWrapper'; -import type { N8nBinaryLoader } from '../../../utils/N8nBinaryLoader'; -import { N8nJsonLoader } from '../../../utils/N8nJsonLoader'; -import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; type NodeOperationMode = 'insert' | 'load' | 'retrieve' | 'update'; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/methods/listSearch.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/methods/listSearch.ts index f12ff5d5cf..278d879f90 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/methods/listSearch.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/methods/listSearch.ts @@ -1,6 +1,6 @@ -import { ApplicationError, type IDataObject, type ILoadOptionsFunctions } from 'n8n-workflow'; import { Pinecone } from '@pinecone-database/pinecone'; import { QdrantClient } from '@qdrant/js-client-rest'; +import { ApplicationError, type IDataObject, type ILoadOptionsFunctions } from 'n8n-workflow'; export async function pineconeIndexSearch(this: ILoadOptionsFunctions) { const credentials = await this.getCredentials('pineconeApi'); diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/processDocuments.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/processDocuments.ts index 5a3847d691..0c28d8db25 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/processDocuments.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/processDocuments.ts @@ -1,7 +1,8 @@ import type { Document } from '@langchain/core/documents'; import type { INodeExecutionData } from 'n8n-workflow'; -import { N8nJsonLoader } from '../../../utils/N8nJsonLoader'; -import { N8nBinaryLoader } from '../../../utils/N8nBinaryLoader'; + +import { N8nBinaryLoader } from '@utils/N8nBinaryLoader'; +import { N8nJsonLoader } from '@utils/N8nJsonLoader'; export async function processDocuments( documentInput: N8nJsonLoader | N8nBinaryLoader | Array>>, diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/OpenAi.node.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/OpenAi.node.ts index 1743c69618..251618c01e 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/OpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/OpenAi.node.ts @@ -1,4 +1,5 @@ import type { IExecuteFunctions, INodeType } from 'n8n-workflow'; + import { router } from './actions/router'; import { versionDescription } from './actions/versionDescription'; import { listSearch, loadOptions } from './methods'; diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts index b9a0dee535..3ac5e45352 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts @@ -5,6 +5,7 @@ import type { IDataObject, } from 'n8n-workflow'; import { NodeOperationError, updateDisplayOptions } from 'n8n-workflow'; + import { apiRequest } from '../../transport'; import { modelRLC } from '../descriptions'; diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/deleteAssistant.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/deleteAssistant.operation.ts index 099e5fd3e6..7287d8ebfd 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/deleteAssistant.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/deleteAssistant.operation.ts @@ -1,5 +1,6 @@ import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; import { updateDisplayOptions } from 'n8n-workflow'; + import { apiRequest } from '../../transport'; import { assistantRLC } from '../descriptions'; diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/index.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/index.ts index 3f869ffcc8..5973319492 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/index.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/index.ts @@ -2,8 +2,8 @@ import type { INodeProperties } from 'n8n-workflow'; import * as create from './create.operation'; import * as deleteAssistant from './deleteAssistant.operation'; -import * as message from './message.operation'; import * as list from './list.operation'; +import * as message from './message.operation'; import * as update from './update.operation'; export { create, deleteAssistant, message, list, update }; diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/list.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/list.operation.ts index c029af4d48..ec75be1cfd 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/list.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/list.operation.ts @@ -1,5 +1,6 @@ import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; import { updateDisplayOptions } from 'n8n-workflow'; + import { apiRequest } from '../../transport'; const properties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts index 959d487abe..977530cc83 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/message.operation.ts @@ -18,9 +18,10 @@ import { } from 'n8n-workflow'; import { OpenAI as OpenAIClient } from 'openai'; -import { promptTypeOptions } from '../../../../../utils/descriptions'; -import { getConnectedTools } from '../../../../../utils/helpers'; -import { getTracingConfig } from '../../../../../utils/tracing'; +import { promptTypeOptions } from '@utils/descriptions'; +import { getConnectedTools } from '@utils/helpers'; +import { getTracingConfig } from '@utils/tracing'; + import { formatToOpenAIAssistantTool } from '../../helpers/utils'; import { assistantRLC } from '../descriptions'; diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/update.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/update.operation.ts index bd26ab0a0c..f197ace5ec 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/update.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/update.operation.ts @@ -5,6 +5,7 @@ import type { IDataObject, } from 'n8n-workflow'; import { ApplicationError, NodeOperationError, updateDisplayOptions } from 'n8n-workflow'; + import { apiRequest } from '../../transport'; import { assistantRLC, modelRLC } from '../descriptions'; diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/generate.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/generate.operation.ts index 2a1c59090d..4058a3bcf7 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/generate.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/generate.operation.ts @@ -5,6 +5,7 @@ import type { INodeExecutionData, } from 'n8n-workflow'; import { updateDisplayOptions } from 'n8n-workflow'; + import { apiRequest } from '../../transport'; const properties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/transcribe.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/transcribe.operation.ts index 1f419066ad..ddbc1f09ae 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/transcribe.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/transcribe.operation.ts @@ -1,7 +1,7 @@ +import FormData from 'form-data'; import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; import { updateDisplayOptions } from 'n8n-workflow'; -import FormData from 'form-data'; import { apiRequest } from '../../transport'; const properties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/translate.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/translate.operation.ts index 3ba7e53c64..911da72296 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/translate.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/audio/translate.operation.ts @@ -1,6 +1,7 @@ +import FormData from 'form-data'; import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; import { updateDisplayOptions } from 'n8n-workflow'; -import FormData from 'form-data'; + import { apiRequest } from '../../transport'; const properties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/file/index.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/file/index.ts index 809c1ec947..248d01fc27 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/file/index.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/file/index.ts @@ -1,8 +1,8 @@ import type { INodeProperties } from 'n8n-workflow'; -import * as upload from './upload.operation'; import * as deleteFile from './deleteFile.operation'; import * as list from './list.operation'; +import * as upload from './upload.operation'; export { upload, deleteFile, list }; diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/file/upload.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/file/upload.operation.ts index 9776c0f385..38bcd1e824 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/file/upload.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/file/upload.operation.ts @@ -1,6 +1,7 @@ +import FormData from 'form-data'; import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; import { updateDisplayOptions, NodeOperationError } from 'n8n-workflow'; -import FormData from 'form-data'; + import { apiRequest } from '../../transport'; const properties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/analyze.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/analyze.operation.ts index 07a91ab82d..a46e77a494 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/analyze.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/analyze.operation.ts @@ -5,6 +5,7 @@ import type { IDataObject, } from 'n8n-workflow'; import { updateDisplayOptions, NodeOperationError } from 'n8n-workflow'; + import { apiRequest } from '../../transport'; import { modelRLC } from '../descriptions'; diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/generate.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/generate.operation.ts index 48a03158b5..0c443bb6c7 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/generate.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/generate.operation.ts @@ -5,6 +5,7 @@ import type { IDataObject, } from 'n8n-workflow'; import { updateDisplayOptions } from 'n8n-workflow'; + import { apiRequest } from '../../transport'; const properties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/index.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/index.ts index 0516ae3ce4..3ad3648273 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/index.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/image/index.ts @@ -1,7 +1,7 @@ import type { INodeProperties } from 'n8n-workflow'; -import * as generate from './generate.operation'; import * as analyze from './analyze.operation'; +import * as generate from './generate.operation'; export { generate, analyze }; diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/router.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/router.ts index 634923a5e6..2b64993e2d 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/router.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/router.ts @@ -9,9 +9,8 @@ import * as assistant from './assistant'; import * as audio from './audio'; import * as file from './file'; import * as image from './image'; -import * as text from './text'; - import type { OpenAiType } from './node.type'; +import * as text from './text'; import { getCustomErrorMessage } from '../helpers/error-handling'; export async function router(this: IExecuteFunctions) { diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/classify.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/classify.operation.ts index 338d4ade1e..dfc9a5f38a 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/classify.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/classify.operation.ts @@ -1,5 +1,6 @@ import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; import { updateDisplayOptions } from 'n8n-workflow'; + import { apiRequest } from '../../transport'; const properties: INodeProperties[] = [ diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts index 231fdb4b77..2da3163099 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts @@ -1,3 +1,5 @@ +import type { Tool } from '@langchain/core/tools'; +import _omit from 'lodash/omit'; import type { INodeProperties, IExecuteFunctions, @@ -5,14 +7,15 @@ import type { IDataObject, } from 'n8n-workflow'; import { jsonParse, updateDisplayOptions } from 'n8n-workflow'; -import type { Tool } from '@langchain/core/tools'; -import _omit from 'lodash/omit'; -import { apiRequest } from '../../transport'; + +import { getConnectedTools } from '@utils/helpers'; + +import { MODELS_NOT_SUPPORT_FUNCTION_CALLS } from '../../helpers/constants'; import type { ChatCompletion } from '../../helpers/interfaces'; import { formatToOpenAIAssistantTool } from '../../helpers/utils'; +import { apiRequest } from '../../transport'; import { modelRLC } from '../descriptions'; -import { getConnectedTools } from '../../../../../utils/helpers'; -import { MODELS_NOT_SUPPORT_FUNCTION_CALLS } from '../../helpers/constants'; + const properties: INodeProperties[] = [ modelRLC('modelSearch'), { diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/helpers/utils.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/helpers/utils.ts index 294fc47847..d0db590bc3 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/helpers/utils.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/helpers/utils.ts @@ -1,6 +1,6 @@ -import { zodToJsonSchema } from 'zod-to-json-schema'; -import type { OpenAIClient } from '@langchain/openai'; import type { StructuredTool } from '@langchain/core/tools'; +import type { OpenAIClient } from '@langchain/openai'; +import { zodToJsonSchema } from 'zod-to-json-schema'; // Copied from langchain(`langchain/src/tools/convert_to_openai.ts`) // since these functions are not exported diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/methods/listSearch.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/methods/listSearch.ts index 4475029481..dcf056618a 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/methods/listSearch.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/methods/listSearch.ts @@ -4,9 +4,9 @@ import type { INodeListSearchItems, INodeListSearchResult, } from 'n8n-workflow'; - -import type { Model } from 'openai/resources/models'; import type { Assistant } from 'openai/resources/beta/assistants'; +import type { Model } from 'openai/resources/models'; + import { apiRequest } from '../transport'; export async function fileSearch( diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/methods/loadOptions.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/methods/loadOptions.ts index a25f24c698..9f53ca1f86 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/methods/loadOptions.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/methods/loadOptions.ts @@ -1,4 +1,5 @@ import type { ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow'; + import { apiRequest } from '../transport'; export async function getFiles(this: ILoadOptionsFunctions): Promise { diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/test/OpenAi.node.test.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/test/OpenAi.node.test.ts index a78260844c..b8a32c45bf 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/test/OpenAi.node.test.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/test/OpenAi.node.test.ts @@ -1,11 +1,11 @@ -import type { IDataObject, IExecuteFunctions } from 'n8n-workflow'; import get from 'lodash/get'; +import type { IDataObject, IExecuteFunctions } from 'n8n-workflow'; + import * as assistant from '../actions/assistant'; import * as audio from '../actions/audio'; import * as file from '../actions/file'; import * as image from '../actions/image'; import * as text from '../actions/text'; - import * as transport from '../transport'; const createExecuteFunctionsMock = (parameters: IDataObject) => { diff --git a/packages/@n8n/nodes-langchain/package.json b/packages/@n8n/nodes-langchain/package.json index d8e8c7db40..05715fcf7c 100644 --- a/packages/@n8n/nodes-langchain/package.json +++ b/packages/@n8n/nodes-langchain/package.json @@ -7,7 +7,7 @@ "clean": "rimraf dist .turbo", "dev": "pnpm run watch", "typecheck": "tsc --noEmit", - "build": "tsc -p tsconfig.build.json && pnpm n8n-copy-icons && pnpm n8n-generate-metadata", + "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && pnpm n8n-copy-icons && pnpm n8n-generate-metadata", "format": "biome format --write .", "format:check": "biome ci .", "lint": "eslint nodes credentials --quiet", diff --git a/packages/@n8n/nodes-langchain/tsconfig.json b/packages/@n8n/nodes-langchain/tsconfig.json index a0bd21149f..d72fd76a4a 100644 --- a/packages/@n8n/nodes-langchain/tsconfig.json +++ b/packages/@n8n/nodes-langchain/tsconfig.json @@ -1,6 +1,9 @@ { "extends": ["../../../tsconfig.json", "../../../tsconfig.backend.json"], "compilerOptions": { + "paths": { + "@utils/*": ["./utils/*"] + }, "tsBuildInfoFile": "dist/typecheck.tsbuildinfo", // TODO: remove all options below this line "useUnknownInCatchVariables": false diff --git a/packages/core/src/CreateNodeAsTool.ts b/packages/core/src/CreateNodeAsTool.ts index b4215f8481..7c67b6ac58 100644 --- a/packages/core/src/CreateNodeAsTool.ts +++ b/packages/core/src/CreateNodeAsTool.ts @@ -1,13 +1,6 @@ import { DynamicStructuredTool } from '@langchain/core/tools'; -import type { - IExecuteFunctions, - INode, - INodeParameters, - INodeType, - ISupplyDataFunctions, - ITaskDataConnections, -} from 'n8n-workflow'; -import { jsonParse, NodeConnectionType, NodeOperationError } from 'n8n-workflow'; +import type { IDataObject, INode, INodeType } from 'n8n-workflow'; +import { jsonParse, NodeOperationError } from 'n8n-workflow'; import { z } from 'zod'; type AllowedTypes = 'string' | 'number' | 'boolean' | 'json'; @@ -21,7 +14,7 @@ interface FromAIArgument { type ParserOptions = { node: INode; nodeType: INodeType; - contextFactory: (runIndex: number, inputData: ITaskDataConnections) => ISupplyDataFunctions; + handleToolInvocation: (toolArgs: IDataObject) => Promise; }; /** @@ -31,8 +24,6 @@ type ParserOptions = { * generating Zod schemas, and creating LangChain tools. */ class AIParametersParser { - private runIndex = 0; - /** * Constructs an instance of AIParametersParser. */ @@ -291,39 +282,19 @@ class AIParametersParser { } /** - * Generates a description for a node based on the provided parameters. - * @param node The node type. - * @param nodeParameters The parameters of the node. - * @returns A string description for the node. + * Retrieves and validates the Zod schema for the tool. + * + * This method: + * 1. Collects all $fromAI arguments from node parameters + * 2. Validates parameter keys against naming rules + * 3. Checks for duplicate keys and ensures consistency + * 4. Generates a Zod schema from the validated arguments + * + * @throws {NodeOperationError} When parameter keys are invalid or when duplicate keys have inconsistent definitions + * @returns {z.ZodObject} A Zod schema object representing the structure and validation rules for the node parameters */ - private getDescription(node: INodeType, nodeParameters: INodeParameters): string { - const manualDescription = nodeParameters.toolDescription as string; - - if (nodeParameters.descriptionType === 'auto') { - const resource = nodeParameters.resource as string; - const operation = nodeParameters.operation as string; - let description = node.description.description; - if (resource) { - description += `\n Resource: ${resource}`; - } - if (operation) { - description += `\n Operation: ${operation}`; - } - return description.trim(); - } - if (nodeParameters.descriptionType === 'manual') { - return manualDescription ?? node.description.description; - } - - return node.description.description; - } - - /** - * Creates a DynamicStructuredTool from a node. - * @returns A DynamicStructuredTool instance. - */ - public createTool(): DynamicStructuredTool { - const { node, nodeType } = this.options; + private getSchema() { + const { node } = this.options; const collectedArguments: FromAIArgument[] = []; this.traverseNodeParameters(node.parameters, collectedArguments); @@ -381,43 +352,56 @@ class AIParametersParser { return acc; }, {}); - const schema = z.object(schemaObj).required(); - const description = this.getDescription(nodeType, node.parameters); + return z.object(schemaObj).required(); + } + + /** + * Generates a description for a node based on the provided parameters. + * @param node The node type. + * @param nodeParameters The parameters of the node. + * @returns A string description for the node. + */ + private getDescription(): string { + const { node, nodeType } = this.options; + const manualDescription = node.parameters.toolDescription as string; + + if (node.parameters.descriptionType === 'auto') { + const resource = node.parameters.resource as string; + const operation = node.parameters.operation as string; + let description = nodeType.description.description; + if (resource) { + description += `\n Resource: ${resource}`; + } + if (operation) { + description += `\n Operation: ${operation}`; + } + return description.trim(); + } + if (node.parameters.descriptionType === 'manual') { + return manualDescription ?? nodeType.description.description; + } + + return nodeType.description.description; + } + + /** + * Creates a DynamicStructuredTool from a node. + * @returns A DynamicStructuredTool instance. + */ + public createTool(): DynamicStructuredTool { + const { node, nodeType } = this.options; + const schema = this.getSchema(); + const description = this.getDescription(); const nodeName = node.name.replace(/ /g, '_'); const name = nodeName || nodeType.description.name; - const tool = new DynamicStructuredTool({ + return new DynamicStructuredTool({ name, description, schema, - func: async (toolArgs: z.infer) => { - const currentRunIndex = this.runIndex++; - const context = this.options.contextFactory(currentRunIndex, {}); - context.addInputData(NodeConnectionType.AiTool, [[{ json: toolArgs }]]); - - try { - // Execute the node with the proxied context - const result = await nodeType.execute?.call(context as IExecuteFunctions); - - // Process and map the results - const mappedResults = result?.[0]?.flatMap((item) => item.json); - - // Add output data to the context - context.addOutputData(NodeConnectionType.AiTool, currentRunIndex, [ - [{ json: { response: mappedResults } }], - ]); - - // Return the stringified results - return JSON.stringify(mappedResults); - } catch (error) { - const nodeError = new NodeOperationError(this.options.node, error as Error); - context.addOutputData(NodeConnectionType.AiTool, currentRunIndex, nodeError); - return 'Error during node execution: ' + nodeError.description; - } - }, + func: async (toolArgs: z.infer) => + await this.options.handleToolInvocation(toolArgs), }); - - return tool; } } diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index 047c4e23ad..578752b3ef 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -76,6 +76,7 @@ import type { WebhookType, SchedulingFunctions, SupplyData, + AINodeConnectionType, } from 'n8n-workflow'; import { NodeConnectionType, @@ -2018,7 +2019,7 @@ export async function getInputConnectionData( executeData: IExecuteData, mode: WorkflowExecuteMode, closeFunctions: CloseFunction[], - connectionType: NodeConnectionType, + connectionType: AINodeConnectionType, itemIndex: number, abortSignal?: AbortSignal, ): Promise { @@ -2098,10 +2099,41 @@ export async function getInputConnectionData( if (!connectedNodeType.supplyData) { if (connectedNodeType.description.outputs.includes(NodeConnectionType.AiTool)) { + /** + * This keeps track of how many times this specific AI tool node has been invoked. + * It is incremented on every invocation of the tool to keep the output of each invocation separate from each other. + */ + let toolRunIndex = 0; const supplyData = createNodeAsTool({ node: connectedNode, nodeType: connectedNodeType, - contextFactory, + handleToolInvocation: async (toolArgs) => { + const runIndex = toolRunIndex++; + const context = contextFactory(runIndex, {}); + context.addInputData(NodeConnectionType.AiTool, [[{ json: toolArgs }]]); + + try { + // Execute the sub-node with the proxied context + const result = await connectedNodeType.execute?.call( + context as unknown as IExecuteFunctions, + ); + + // Process and map the results + const mappedResults = result?.[0]?.flatMap((item) => item.json); + + // Add output data to the context + context.addOutputData(NodeConnectionType.AiTool, runIndex, [ + [{ json: { response: mappedResults } }], + ]); + + // Return the stringified results + return JSON.stringify(mappedResults); + } catch (error) { + const nodeError = new NodeOperationError(connectedNode, error as Error); + context.addOutputData(NodeConnectionType.AiTool, runIndex, nodeError); + return 'Error during node execution: ' + nodeError.description; + } + }, }); nodes.push(supplyData); } else { diff --git a/packages/core/src/WorkflowExecute.ts b/packages/core/src/WorkflowExecute.ts index ba855c0b57..6f2cce0b3d 100644 --- a/packages/core/src/WorkflowExecute.ts +++ b/packages/core/src/WorkflowExecute.ts @@ -1691,7 +1691,7 @@ export class WorkflowExecute { } } - if (nodeSuccessData === null && !this.runExecutionData.waitTill!) { + if (nodeSuccessData === null && !this.runExecutionData.waitTill) { // If null gets returned it means that the node did succeed // but did not have any data. So the branch should end // (meaning the nodes afterwards should not be processed) @@ -1818,7 +1818,7 @@ export class WorkflowExecute { this.runExecutionData.resultData.runData[executionNode.name].push(taskData); - if (this.runExecutionData.waitTill!) { + if (this.runExecutionData.waitTill) { await this.executeHook('nodeExecuteAfter', [ executionNode.name, taskData, @@ -2199,7 +2199,7 @@ export class WorkflowExecute { if (executionError.message?.includes('canceled')) { fullRunData.status = 'canceled'; } - } else if (this.runExecutionData.waitTill!) { + } else if (this.runExecutionData.waitTill) { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions Logger.debug(`Workflow execution will wait until ${this.runExecutionData.waitTill}`, { workflowId: workflow.id, diff --git a/packages/core/src/node-execution-context/execute-context.ts b/packages/core/src/node-execution-context/execute-context.ts index 2424697c6f..954059d86d 100644 --- a/packages/core/src/node-execution-context/execute-context.ts +++ b/packages/core/src/node-execution-context/execute-context.ts @@ -1,4 +1,5 @@ import type { + AINodeConnectionType, CallbackManager, CloseFunction, IExecuteData, @@ -149,7 +150,7 @@ export class ExecuteContext extends BaseExecuteContext implements IExecuteFuncti } async getInputConnectionData( - connectionType: NodeConnectionType, + connectionType: AINodeConnectionType, itemIndex: number, ): Promise { return await getInputConnectionData.call( diff --git a/packages/core/src/node-execution-context/supply-data-context.ts b/packages/core/src/node-execution-context/supply-data-context.ts index 0ca059d048..c3d7f45468 100644 --- a/packages/core/src/node-execution-context/supply-data-context.ts +++ b/packages/core/src/node-execution-context/supply-data-context.ts @@ -1,5 +1,6 @@ import get from 'lodash/get'; import type { + AINodeConnectionType, CloseFunction, ExecutionBaseError, IExecuteData, @@ -12,10 +13,11 @@ import type { ITaskDataConnections, ITaskMetadata, IWorkflowExecuteAdditionalData, + NodeConnectionType, Workflow, WorkflowExecuteMode, } from 'n8n-workflow'; -import { ApplicationError, NodeConnectionType, createDeferredPromise } from 'n8n-workflow'; +import { createDeferredPromise } from 'n8n-workflow'; // eslint-disable-next-line import/no-cycle import { @@ -107,7 +109,7 @@ export class SupplyDataContext extends BaseExecuteContext implements ISupplyData } async getInputConnectionData( - connectionType: NodeConnectionType, + connectionType: AINodeConnectionType, itemIndex: number, ): Promise { return await getInputConnectionData.call( @@ -137,7 +139,7 @@ export class SupplyDataContext extends BaseExecuteContext implements ISupplyData /** @deprecated create a context object with inputData for every runIndex */ addInputData( - connectionType: NodeConnectionType, + connectionType: AINodeConnectionType, data: INodeExecutionData[][], ): { index: number } { const nodeName = this.node.name; @@ -166,9 +168,9 @@ export class SupplyDataContext extends BaseExecuteContext implements ISupplyData /** @deprecated Switch to WorkflowExecute to store output on runExecutionData.resultData.runData */ addOutputData( - connectionType: NodeConnectionType, + connectionType: AINodeConnectionType, currentNodeRunIndex: number, - data: INodeExecutionData[][], + data: INodeExecutionData[][] | ExecutionBaseError, metadata?: ITaskMetadata, ): void { const nodeName = this.node.name; @@ -192,17 +194,11 @@ export class SupplyDataContext extends BaseExecuteContext implements ISupplyData async addExecutionDataFunctions( type: 'input' | 'output', data: INodeExecutionData[][] | ExecutionBaseError, - connectionType: NodeConnectionType, + connectionType: AINodeConnectionType, sourceNodeName: string, currentNodeRunIndex: number, metadata?: ITaskMetadata, ): Promise { - if (connectionType === NodeConnectionType.Main) { - throw new ApplicationError('Setting type is not supported for main connection', { - extra: { type }, - }); - } - const { additionalData, runExecutionData, @@ -258,23 +254,16 @@ export class SupplyDataContext extends BaseExecuteContext implements ISupplyData } runExecutionData.resultData.runData[nodeName][currentNodeRunIndex] = taskData; - if (additionalData.sendDataToUI) { - additionalData.sendDataToUI('nodeExecuteBefore', { - executionId: additionalData.executionId, - nodeName, - }); - } + await additionalData.hooks?.executeHookFunctions('nodeExecuteBefore', [nodeName]); } else { // Outputs taskData.executionTime = new Date().getTime() - taskData.startTime; - if (additionalData.sendDataToUI) { - additionalData.sendDataToUI('nodeExecuteAfter', { - executionId: additionalData.executionId, - nodeName, - data: taskData, - }); - } + await additionalData.hooks?.executeHookFunctions('nodeExecuteAfter', [ + nodeName, + taskData, + this.runExecutionData, + ]); if (get(runExecutionData, 'executionData.metadata', undefined) === undefined) { runExecutionData.executionData!.metadata = {}; diff --git a/packages/core/src/node-execution-context/webhook-context.ts b/packages/core/src/node-execution-context/webhook-context.ts index 8f55b26097..04d1df5e40 100644 --- a/packages/core/src/node-execution-context/webhook-context.ts +++ b/packages/core/src/node-execution-context/webhook-context.ts @@ -1,5 +1,6 @@ import type { Request, Response } from 'express'; import type { + AINodeConnectionType, CloseFunction, ICredentialDataDecryptedObject, IDataObject, @@ -11,7 +12,6 @@ import type { IWebhookData, IWebhookFunctions, IWorkflowExecuteAdditionalData, - NodeConnectionType, WebhookType, Workflow, WorkflowExecuteMode, @@ -139,7 +139,7 @@ export class WebhookContext extends NodeExecutionContext implements IWebhookFunc } async getInputConnectionData( - connectionType: NodeConnectionType, + connectionType: AINodeConnectionType, itemIndex: number, ): Promise { // To be able to use expressions like "$json.sessionId" set the diff --git a/packages/core/test/CreateNodeAsTool.test.ts b/packages/core/test/CreateNodeAsTool.test.ts index 2f6dd31322..fdc14269e1 100644 --- a/packages/core/test/CreateNodeAsTool.test.ts +++ b/packages/core/test/CreateNodeAsTool.test.ts @@ -1,6 +1,5 @@ import { mock } from 'jest-mock-extended'; import type { INodeType, ISupplyDataFunctions, INode } from 'n8n-workflow'; -import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; import { z } from 'zod'; import { createNodeAsTool } from '@/CreateNodeAsTool'; @@ -21,7 +20,7 @@ describe('createNodeAsTool', () => { addOutputData: jest.fn(), getNode: jest.fn(), }); - const contextFactory = () => context; + const handleToolInvocation = jest.fn(); const nodeType = mock({ description: { name: 'TestNode', @@ -29,7 +28,7 @@ describe('createNodeAsTool', () => { }, }); const node = mock({ name: 'Test_Node' }); - const options = { node, nodeType, contextFactory }; + const options = { node, nodeType, handleToolInvocation }; beforeEach(() => { jest.clearAllMocks(); @@ -142,15 +141,11 @@ describe('createNodeAsTool', () => { it('should handle error during node execution', async () => { nodeType.execute = jest.fn().mockRejectedValue(new Error('Execution failed')); const tool = createNodeAsTool(options).response; + handleToolInvocation.mockReturnValue('Error during node execution: some random issue.'); const result = await tool.func({ param1: 'test value' }); expect(result).toContain('Error during node execution:'); - expect(context.addOutputData).toHaveBeenCalledWith( - NodeConnectionType.AiTool, - 0, - expect.any(NodeOperationError), - ); }); it('should throw an error for invalid parameter names', () => { diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index 4f5bf9e6d1..116d392722 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -909,7 +909,7 @@ export type IExecuteFunctions = ExecuteFunctions.GetNodeParameterFn & }, ): Promise; getInputConnectionData( - connectionType: NodeConnectionType, + connectionType: AINodeConnectionType, itemIndex: number, inputIndex?: number, ): Promise; @@ -1074,7 +1074,7 @@ export interface IWebhookFunctions extends FunctionsBaseWithRequiredKeys<'getMod getBodyData(): IDataObject; getHeaderData(): IncomingHttpHeaders; getInputConnectionData( - connectionType: NodeConnectionType, + connectionType: AINodeConnectionType, itemIndex: number, inputIndex?: number, ): Promise; @@ -1805,30 +1805,21 @@ export interface IPostReceiveSort extends IPostReceiveBase { export const enum NodeConnectionType { AiAgent = 'ai_agent', - AiChain = 'ai_chain', - AiDocument = 'ai_document', - AiEmbedding = 'ai_embedding', - AiLanguageModel = 'ai_languageModel', - AiMemory = 'ai_memory', - AiOutputParser = 'ai_outputParser', - AiRetriever = 'ai_retriever', - AiTextSplitter = 'ai_textSplitter', - AiTool = 'ai_tool', - AiVectorStore = 'ai_vectorStore', - Main = 'main', } +export type AINodeConnectionType = Exclude; + export const nodeConnectionTypes: NodeConnectionType[] = [ NodeConnectionType.AiAgent, NodeConnectionType.AiChain,