mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-12 15:44:06 -08:00
fix(HTTP Request Tool Node): Fix subsequent tool calls reusung the same options (#10808)
This commit is contained in:
parent
394ef88843
commit
d647ef41ac
|
@ -19,6 +19,8 @@ import { convert } from 'html-to-text';
|
||||||
|
|
||||||
import { Readability } from '@mozilla/readability';
|
import { Readability } from '@mozilla/readability';
|
||||||
import { JSDOM } from 'jsdom';
|
import { JSDOM } from 'jsdom';
|
||||||
|
import { z } from 'zod';
|
||||||
|
import type { DynamicZodObject } from '../../../types/zod.types';
|
||||||
import type {
|
import type {
|
||||||
ParameterInputType,
|
ParameterInputType,
|
||||||
ParametersValues,
|
ParametersValues,
|
||||||
|
@ -27,8 +29,6 @@ import type {
|
||||||
SendIn,
|
SendIn,
|
||||||
ToolParameter,
|
ToolParameter,
|
||||||
} from './interfaces';
|
} from './interfaces';
|
||||||
import type { DynamicZodObject } from '../../../types/zod.types';
|
|
||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
const genericCredentialRequest = async (ctx: IExecuteFunctions, itemIndex: number) => {
|
const genericCredentialRequest = async (ctx: IExecuteFunctions, itemIndex: number) => {
|
||||||
const genericType = ctx.getNodeParameter('genericAuthType', itemIndex) as string;
|
const genericType = ctx.getNodeParameter('genericAuthType', itemIndex) as string;
|
||||||
|
@ -571,8 +571,10 @@ export const configureToolFunction = (
|
||||||
return async (query: string | IDataObject): Promise<string> => {
|
return async (query: string | IDataObject): Promise<string> => {
|
||||||
const { index } = ctx.addInputData(NodeConnectionType.AiTool, [[{ json: { query } }]]);
|
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 response: string = '';
|
||||||
let options: IHttpRequestOptions | null = null;
|
|
||||||
let executionError: Error | undefined = undefined;
|
let executionError: Error | undefined = undefined;
|
||||||
|
|
||||||
if (!toolParameters.length) {
|
if (!toolParameters.length) {
|
||||||
|
@ -614,8 +616,6 @@ export const configureToolFunction = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
options = requestOptions;
|
|
||||||
|
|
||||||
for (const parameter of toolParameters) {
|
for (const parameter of toolParameters) {
|
||||||
let argument = dataFromModel[parameter.name];
|
let argument = dataFromModel[parameter.name];
|
||||||
|
|
||||||
|
@ -659,7 +659,7 @@ export const configureToolFunction = (
|
||||||
argument = String(argument);
|
argument = String(argument);
|
||||||
if (
|
if (
|
||||||
!argument.startsWith('"') &&
|
!argument.startsWith('"') &&
|
||||||
!rawRequestOptions[parameter.sendIn].includes(`"{${parameter.name}}"`)
|
!clonedRawRequestOptions[parameter.sendIn].includes(`"{${parameter.name}}"`)
|
||||||
) {
|
) {
|
||||||
argument = `"${argument}"`;
|
argument = `"${argument}"`;
|
||||||
}
|
}
|
||||||
|
@ -669,10 +669,9 @@ export const configureToolFunction = (
|
||||||
argument = JSON.stringify(argument);
|
argument = JSON.stringify(argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
rawRequestOptions[parameter.sendIn] = rawRequestOptions[parameter.sendIn].replace(
|
clonedRawRequestOptions[parameter.sendIn] = clonedRawRequestOptions[
|
||||||
`{${parameter.name}}`,
|
parameter.sendIn
|
||||||
String(argument),
|
].replace(`{${parameter.name}}`, String(argument));
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,7 +692,7 @@ export const configureToolFunction = (
|
||||||
set(options, [parameter.sendIn, parameter.name], argument);
|
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) {
|
if (value) {
|
||||||
let parsedValue;
|
let parsedValue;
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue