Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(HTTP Request Tool Node): Fix subsequent tool calls reusung the same options #10808

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions packages/@n8n/nodes-langchain/nodes/tools/ToolHttpRequest/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { convert } from 'html-to-text';

import { Readability } from '@mozilla/readability';
import { JSDOM } from 'jsdom';
import { z } from 'zod';
import type { DynamicZodObject } from '../../../types/zod.types';
import type {
ParameterInputType,
ParametersValues,
Expand All @@ -27,8 +29,6 @@ import type {
SendIn,
ToolParameter,
} from './interfaces';
import type { DynamicZodObject } from '../../../types/zod.types';
import { z } from 'zod';

const genericCredentialRequest = async (ctx: IExecuteFunctions, itemIndex: number) => {
const genericType = ctx.getNodeParameter('genericAuthType', itemIndex) as string;
Expand Down Expand Up @@ -571,8 +571,10 @@ export const configureToolFunction = (
return async (query: string | IDataObject): Promise<string> => {
const { index } = ctx.addInputData(NodeConnectionType.AiTool, [[{ json: { query } }]]);

// Clone options and rawRequestOptions to avoid mutating the original objects
const options: IHttpRequestOptions | null = structuredClone(requestOptions);
const clonedRawRequestOptions: { [key: string]: string } = structuredClone(rawRequestOptions);
let response: string = '';
let options: IHttpRequestOptions | null = null;
let executionError: Error | undefined = undefined;

if (!toolParameters.length) {
Expand Down Expand Up @@ -614,8 +616,6 @@ export const configureToolFunction = (
}
}

options = requestOptions;

for (const parameter of toolParameters) {
let argument = dataFromModel[parameter.name];

Expand Down Expand Up @@ -659,7 +659,7 @@ export const configureToolFunction = (
argument = String(argument);
if (
!argument.startsWith('"') &&
!rawRequestOptions[parameter.sendIn].includes(`"{${parameter.name}}"`)
!clonedRawRequestOptions[parameter.sendIn].includes(`"{${parameter.name}}"`)
) {
argument = `"${argument}"`;
}
Expand All @@ -669,10 +669,9 @@ export const configureToolFunction = (
argument = JSON.stringify(argument);
}

rawRequestOptions[parameter.sendIn] = rawRequestOptions[parameter.sendIn].replace(
`{${parameter.name}}`,
String(argument),
);
clonedRawRequestOptions[parameter.sendIn] = clonedRawRequestOptions[
parameter.sendIn
].replace(`{${parameter.name}}`, String(argument));
continue;
}

Expand All @@ -693,7 +692,7 @@ export const configureToolFunction = (
set(options, [parameter.sendIn, parameter.name], argument);
}

for (const [key, value] of Object.entries(rawRequestOptions)) {
for (const [key, value] of Object.entries(clonedRawRequestOptions)) {
if (value) {
let parsedValue;
try {
Expand Down
Loading