fix(Call n8n Workflow Tool Node): Support concurrent invocations of the tool (#13526)

Co-authored-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
Charlie Kolb
2025-02-26 16:23:31 +01:00
committed by GitHub
co-authored by Oleg Ivaniv
parent 24a38b99a1
commit 5334661b76
15 changed files with 171 additions and 86 deletions
@@ -54,7 +54,9 @@ describe('SupplyDataContext', () => {
const credentialsHelper = mock<ICredentialsHelper>();
const additionalData = mock<IWorkflowExecuteAdditionalData>({ credentialsHelper });
const mode: WorkflowExecuteMode = 'manual';
const runExecutionData = mock<IRunExecutionData>();
const runExecutionData = mock<IRunExecutionData>({
resultData: { runData: {} },
});
const connectionInputData: INodeExecutionData[] = [];
const connectionType = NodeConnectionType.Main;
const inputData: ITaskDataConnections = { [connectionType]: [[{ json: { test: 'data' } }]] };
@@ -175,4 +177,12 @@ describe('SupplyDataContext', () => {
]);
});
});
describe('cloneWith', () => {
it('should return a new copy', () => {
const clone = supplyDataContext.cloneWith({ runIndex: 12, inputData: [[{ json: {} }]] });
expect(clone.runIndex).toBe(12);
expect(clone).not.toBe(supplyDataContext);
});
});
});
@@ -13,11 +13,10 @@ import type {
ITaskDataConnections,
ITaskMetadata,
IWorkflowExecuteAdditionalData,
NodeConnectionType,
Workflow,
WorkflowExecuteMode,
} from 'n8n-workflow';
import { createDeferredPromise } from 'n8n-workflow';
import { createDeferredPromise, NodeConnectionType } from 'n8n-workflow';
import { BaseExecuteContext } from './base-execute-context';
import {
@@ -109,6 +108,28 @@ export class SupplyDataContext extends BaseExecuteContext implements ISupplyData
)) as ISupplyDataFunctions['getNodeParameter'];
}
cloneWith(replacements: {
runIndex: number;
inputData: INodeExecutionData[][];
}): SupplyDataContext {
const context = new SupplyDataContext(
this.workflow,
this.node,
this.additionalData,
this.mode,
this.runExecutionData,
replacements.runIndex,
this.connectionInputData,
{},
this.connectionType,
this.executeData,
this.closeFunctions,
this.abortSignal,
);
context.addInputData(NodeConnectionType.AiTool, replacements.inputData);
return context;
}
async getInputConnectionData(
connectionType: AINodeConnectionType,
itemIndex: number,