fix(Think Tool Node): Use dynamic tool name based on node name (#17364)

This commit is contained in:
Eugene
2025-07-16 13:57:29 +02:00
committed by GitHub
parent 4f45ec70c0
commit ac552e68fd
2 changed files with 49 additions and 15 deletions

View File

@@ -1,27 +1,34 @@
import { mock } from 'jest-mock-extended';
import { DynamicTool } from 'langchain/tools';
import type { ISupplyDataFunctions } from 'n8n-workflow';
import type { ISupplyDataFunctions, INode } from 'n8n-workflow';
import { ToolThink } from '../ToolThink.node';
describe('ToolThink', () => {
const thinkTool = new ToolThink();
const helpers = mock<ISupplyDataFunctions['helpers']>();
const executeFunctions = mock<ISupplyDataFunctions>({
helpers,
});
executeFunctions.addInputData.mockReturnValue({ index: 0 });
executeFunctions.getNodeParameter.mockImplementation((paramName: string) => {
switch (paramName) {
case 'description':
return 'Tool description';
default:
return undefined;
}
});
const createExecuteFunctions = (node: Partial<INode> = { typeVersion: 1 }) => {
const executeFunctions = mock<ISupplyDataFunctions>({
helpers,
});
executeFunctions.addInputData.mockReturnValue({ index: 0 });
executeFunctions.getNodeParameter.mockImplementation((paramName: string) => {
switch (paramName) {
case 'description':
return 'Tool description';
default:
return undefined;
}
});
executeFunctions.getNode.mockReturnValue(mock<INode>(node));
return executeFunctions;
};
describe('Tool response', () => {
it('should return the same text as response when receiving a text input', async () => {
const executeFunctions = createExecuteFunctions();
const { response } = (await thinkTool.supplyData.call(executeFunctions, 0)) as {
response: DynamicTool;
};
@@ -30,5 +37,26 @@ describe('ToolThink', () => {
const res = (await response.invoke('foo')) as string;
expect(res).toEqual('foo');
});
it('should use hardcoded name for version 1', async () => {
const executeFunctions = createExecuteFunctions({ typeVersion: 1 });
const { response } = (await thinkTool.supplyData.call(executeFunctions, 0)) as {
response: DynamicTool;
};
expect(response.name).toEqual('thinking_tool');
});
it('should use dynamic name from node for version 1.1', async () => {
const executeFunctions = createExecuteFunctions({
typeVersion: 1.1,
name: 'My Thinking Tool',
});
const { response } = (await thinkTool.supplyData.call(executeFunctions, 0)) as {
response: DynamicTool;
};
expect(response.name).toEqual('My_Thinking_Tool');
});
});
});