mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix(core): Fix race condition in AI tool invocation with multiple items from the parent (#12169)
This commit is contained in:
parent
57c6a6167d
commit
dce0c58f86
|
@ -391,7 +391,8 @@ class AIParametersParser {
|
|||
description,
|
||||
schema,
|
||||
func: async (toolArgs: z.infer<typeof schema>) => {
|
||||
const context = this.options.contextFactory(this.runIndex, {});
|
||||
const currentRunIndex = this.runIndex++;
|
||||
const context = this.options.contextFactory(currentRunIndex, {});
|
||||
context.addInputData(NodeConnectionType.AiTool, [[{ json: toolArgs }]]);
|
||||
|
||||
try {
|
||||
|
@ -402,7 +403,7 @@ class AIParametersParser {
|
|||
const mappedResults = result?.[0]?.flatMap((item) => item.json);
|
||||
|
||||
// Add output data to the context
|
||||
context.addOutputData(NodeConnectionType.AiTool, this.runIndex, [
|
||||
context.addOutputData(NodeConnectionType.AiTool, currentRunIndex, [
|
||||
[{ json: { response: mappedResults } }],
|
||||
]);
|
||||
|
||||
|
@ -410,10 +411,8 @@ class AIParametersParser {
|
|||
return JSON.stringify(mappedResults);
|
||||
} catch (error) {
|
||||
const nodeError = new NodeOperationError(this.options.node, error as Error);
|
||||
context.addOutputData(NodeConnectionType.AiTool, this.runIndex, nodeError);
|
||||
context.addOutputData(NodeConnectionType.AiTool, currentRunIndex, nodeError);
|
||||
return 'Error during node execution: ' + nodeError.description;
|
||||
} finally {
|
||||
this.runIndex++;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue