refactor: Migrate NodeConnectionType to const object type (no-changelog) (#14078)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Alex Grozav
2025-03-21 14:01:26 +02:00
committed by GitHub
parent 7e8179b848
commit 8215e0b59f
703 changed files with 3104 additions and 3018 deletions

View File

@@ -1,4 +1,4 @@
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
import type {
INodeInputConfiguration,
INodeInputFilter,
@@ -7,6 +7,7 @@ import type {
INodeType,
INodeTypeDescription,
INodeProperties,
NodeConnectionType,
} from 'n8n-workflow';
import { promptTypeOptions, textFromPreviousNode, textInput } from '@utils/descriptions';
@@ -85,7 +86,7 @@ function getInputs(
if (agent === 'conversationalAgent') {
specialInputs = [
{
type: NodeConnectionType.AiLanguageModel,
type: 'ai_languageModel',
filter: {
nodes: [
'@n8n/n8n-nodes-langchain.lmChatAnthropic',
@@ -103,19 +104,19 @@ function getInputs(
},
},
{
type: NodeConnectionType.AiMemory,
type: 'ai_memory',
},
{
type: NodeConnectionType.AiTool,
type: 'ai_tool',
},
{
type: NodeConnectionType.AiOutputParser,
type: 'ai_outputParser',
},
];
} else if (agent === 'toolsAgent') {
specialInputs = [
{
type: NodeConnectionType.AiLanguageModel,
type: 'ai_languageModel',
filter: {
nodes: [
'@n8n/n8n-nodes-langchain.lmChatAnthropic',
@@ -133,20 +134,20 @@ function getInputs(
},
},
{
type: NodeConnectionType.AiMemory,
type: 'ai_memory',
},
{
type: NodeConnectionType.AiTool,
type: 'ai_tool',
required: true,
},
{
type: NodeConnectionType.AiOutputParser,
type: 'ai_outputParser',
},
];
} else if (agent === 'openAiFunctionsAgent') {
specialInputs = [
{
type: NodeConnectionType.AiLanguageModel,
type: 'ai_languageModel',
filter: {
nodes: [
'@n8n/n8n-nodes-langchain.lmChatOpenAi',
@@ -155,57 +156,55 @@ function getInputs(
},
},
{
type: NodeConnectionType.AiMemory,
type: 'ai_memory',
},
{
type: NodeConnectionType.AiTool,
type: 'ai_tool',
required: true,
},
{
type: NodeConnectionType.AiOutputParser,
type: 'ai_outputParser',
},
];
} else if (agent === 'reActAgent') {
specialInputs = [
{
type: NodeConnectionType.AiLanguageModel,
type: 'ai_languageModel',
},
{
type: NodeConnectionType.AiTool,
type: 'ai_tool',
},
{
type: NodeConnectionType.AiOutputParser,
type: 'ai_outputParser',
},
];
} else if (agent === 'sqlAgent') {
specialInputs = [
{
type: NodeConnectionType.AiLanguageModel,
type: 'ai_languageModel',
},
{
type: NodeConnectionType.AiMemory,
type: 'ai_memory',
},
];
} else if (agent === 'planAndExecuteAgent') {
specialInputs = [
{
type: NodeConnectionType.AiLanguageModel,
type: 'ai_languageModel',
},
{
type: NodeConnectionType.AiTool,
type: 'ai_tool',
},
{
type: NodeConnectionType.AiOutputParser,
type: 'ai_outputParser',
},
];
}
if (hasOutputParser === false) {
specialInputs = specialInputs.filter(
(input) => input.type !== NodeConnectionType.AiOutputParser,
);
specialInputs = specialInputs.filter((input) => input.type !== 'ai_outputParser');
}
return [NodeConnectionType.Main, ...getInputData(specialInputs)];
return ['main', ...getInputData(specialInputs)];
}
const agentTypeProperty: INodeProperties = {
@@ -290,7 +289,7 @@ export class Agent implements INodeType {
return getInputs(agent, hasOutputParser)
})($parameter.agent, $parameter.hasOutputParser === undefined || $parameter.hasOutputParser === true)
}}`,
outputs: [NodeConnectionType.Main],
outputs: [NodeConnectionTypes.Main],
credentials: [
{
// eslint-disable-next-line n8n-nodes-base/node-class-description-credentials-name-unsuffixed
@@ -430,7 +429,7 @@ export class Agent implements INodeType {
},
},
{
displayName: `Connect an <a data-action='openSelectiveNodeCreator' data-action-parameter-connectiontype='${NodeConnectionType.AiOutputParser}'>output parser</a> on the canvas to specify the output format you require`,
displayName: `Connect an <a data-action='openSelectiveNodeCreator' data-action-parameter-connectiontype='${NodeConnectionTypes.AiOutputParser}'>output parser</a> on the canvas to specify the output format you require`,
name: 'notice',
type: 'notice',
default: '',

View File

@@ -2,7 +2,7 @@ import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';
import { PromptTemplate } from '@langchain/core/prompts';
import { initializeAgentExecutorWithOptions } from 'langchain/agents';
import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
import { isChatInstance, getPromptInputByType, getConnectedTools } from '@utils/helpers';
import { getOptionalOutputParser } from '@utils/output_parsers/N8nOutputParser';
@@ -16,13 +16,13 @@ export async function conversationalAgentExecute(
nodeVersion: number,
): Promise<INodeExecutionData[][]> {
this.logger.debug('Executing Conversational Agent');
const model = await this.getInputConnectionData(NodeConnectionType.AiLanguageModel, 0);
const model = await this.getInputConnectionData(NodeConnectionTypes.AiLanguageModel, 0);
if (!isChatInstance(model)) {
throw new NodeOperationError(this.getNode(), 'Conversational Agent requires Chat Model');
}
const memory = (await this.getInputConnectionData(NodeConnectionType.AiMemory, 0)) as
const memory = (await this.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as
| BaseChatMemory
| undefined;

View File

@@ -6,7 +6,7 @@ import { BufferMemory, type BaseChatMemory } from 'langchain/memory';
import {
type IExecuteFunctions,
type INodeExecutionData,
NodeConnectionType,
NodeConnectionTypes,
NodeOperationError,
} from 'n8n-workflow';
@@ -22,7 +22,7 @@ export async function openAiFunctionsAgentExecute(
): Promise<INodeExecutionData[][]> {
this.logger.debug('Executing OpenAi Functions Agent');
const model = (await this.getInputConnectionData(
NodeConnectionType.AiLanguageModel,
NodeConnectionTypes.AiLanguageModel,
0,
)) as ChatOpenAI;
@@ -32,7 +32,7 @@ export async function openAiFunctionsAgentExecute(
'OpenAI Functions Agent requires OpenAI Chat Model',
);
}
const memory = (await this.getInputConnectionData(NodeConnectionType.AiMemory, 0)) as
const memory = (await this.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as
| BaseChatMemory
| undefined;
const tools = await getConnectedTools(this, nodeVersion >= 1.5, false);

View File

@@ -4,7 +4,7 @@ import { PlanAndExecuteAgentExecutor } from 'langchain/experimental/plan_and_exe
import {
type IExecuteFunctions,
type INodeExecutionData,
NodeConnectionType,
NodeConnectionTypes,
NodeOperationError,
} from 'n8n-workflow';
@@ -21,7 +21,7 @@ export async function planAndExecuteAgentExecute(
): Promise<INodeExecutionData[][]> {
this.logger.debug('Executing PlanAndExecute Agent');
const model = (await this.getInputConnectionData(
NodeConnectionType.AiLanguageModel,
NodeConnectionTypes.AiLanguageModel,
0,
)) as BaseChatModel;

View File

@@ -5,7 +5,7 @@ import { AgentExecutor, ChatAgent, ZeroShotAgent } from 'langchain/agents';
import {
type IExecuteFunctions,
type INodeExecutionData,
NodeConnectionType,
NodeConnectionTypes,
NodeOperationError,
} from 'n8n-workflow';
@@ -22,7 +22,7 @@ export async function reActAgentAgentExecute(
): Promise<INodeExecutionData[][]> {
this.logger.debug('Executing ReAct Agent');
const model = (await this.getInputConnectionData(NodeConnectionType.AiLanguageModel, 0)) as
const model = (await this.getInputConnectionData(NodeConnectionTypes.AiLanguageModel, 0)) as
| BaseLanguageModel
| BaseChatModel;

View File

@@ -7,7 +7,7 @@ import { SqlDatabase } from 'langchain/sql_db';
import {
type IExecuteFunctions,
type INodeExecutionData,
NodeConnectionType,
NodeConnectionTypes,
NodeOperationError,
type IDataObject,
} from 'n8n-workflow';
@@ -32,7 +32,7 @@ export async function sqlAgentAgentExecute(
this.logger.debug('Executing SQL Agent');
const model = (await this.getInputConnectionData(
NodeConnectionType.AiLanguageModel,
NodeConnectionTypes.AiLanguageModel,
0,
)) as BaseLanguageModel;
const items = this.getInputData();
@@ -113,7 +113,7 @@ export async function sqlAgentAgentExecute(
const toolkit = new SqlToolkit(dbInstance, model);
const agentExecutor = createSqlAgent(model, toolkit, agentOptions);
const memory = (await this.getInputConnectionData(NodeConnectionType.AiMemory, 0)) as
const memory = (await this.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as
| BaseChatMemory
| undefined;

View File

@@ -11,7 +11,7 @@ import type { AgentAction, AgentFinish } from 'langchain/agents';
import { AgentExecutor, createToolCallingAgent } from 'langchain/agents';
import type { ToolsAgentAction } from 'langchain/dist/agents/tool_calling/output_parser';
import { omit } from 'lodash';
import { BINARY_ENCODING, jsonParse, NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import { BINARY_ENCODING, jsonParse, NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import type { ZodObject } from 'zod';
import { z } from 'zod';
@@ -275,7 +275,7 @@ export const getAgentStepsParser =
* @returns The validated chat model
*/
export async function getChatModel(ctx: IExecuteFunctions): Promise<BaseChatModel> {
const model = await ctx.getInputConnectionData(NodeConnectionType.AiLanguageModel, 0);
const model = await ctx.getInputConnectionData(NodeConnectionTypes.AiLanguageModel, 0);
if (!isChatInstance(model) || !model.bindTools) {
throw new NodeOperationError(
ctx.getNode(),
@@ -294,7 +294,7 @@ export async function getChatModel(ctx: IExecuteFunctions): Promise<BaseChatMode
export async function getOptionalMemory(
ctx: IExecuteFunctions,
): Promise<BaseChatMemory | undefined> {
return (await ctx.getInputConnectionData(NodeConnectionType.AiMemory, 0)) as
return (await ctx.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as
| BaseChatMemory
| undefined;
}