From ccc0ad5009b2d547accfc34a9c0917114fd19c81 Mon Sep 17 00:00:00 2001 From: Michael Kret <88898367+michael-radency@users.noreply.github.com> Date: Thu, 8 Feb 2024 18:12:45 +0200 Subject: [PATCH] fix(core): Custom workflow tool tweaks (#8561) --- .../nodes/tools/ToolCode/ToolCode.node.ts | 7 ++- .../tools/ToolWorkflow/ToolWorkflow.node.ts | 43 ++++++++++++------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolCode/ToolCode.node.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolCode/ToolCode.node.ts index 945416c3c52c5..12b57b52cf71d 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolCode/ToolCode.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolCode/ToolCode.node.ts @@ -189,10 +189,9 @@ export class ToolCode implements INodeType { if (typeof response !== 'string') { // TODO: Do some more testing. Issues here should actually fail the workflow - executionError = new NodeOperationError( - this.getNode(), - `The code did not return a valid value. Instead of a string did a value of type '${typeof response}' get returned.`, - ); + executionError = new NodeOperationError(this.getNode(), 'Wrong output type returned', { + description: `The response property should be a string, but it is an ${typeof response}`, + }); response = `There was an error: "${executionError.message}"`; } diff --git a/packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/ToolWorkflow.node.ts b/packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/ToolWorkflow.node.ts index 14e85111684f0..88c7578e16008 100644 --- a/packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/ToolWorkflow.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/tools/ToolWorkflow/ToolWorkflow.node.ts @@ -70,7 +70,7 @@ export class ToolWorkflow implements INodeType { { displayName: - 'The workflow will receive "query" as input and the output of the last node will be returned as response', + 'This tool will call the workflow you define below, and look in the last node for the response. The workflow needs to start with an Execute Workflow trigger', name: 'executeNotice', type: 'notice', default: '', @@ -87,9 +87,9 @@ export class ToolWorkflow implements INodeType { description: 'Load the workflow from the database by ID', }, { - name: 'Parameter', + name: 'Define Below', value: 'parameter', - description: 'Load the workflow from a parameter', + description: 'Pass the JSON code of a workflow', }, ], default: 'database', @@ -111,6 +111,7 @@ export class ToolWorkflow implements INodeType { default: '', required: true, description: 'The workflow to execute', + hint: 'Can be found in the URL of the workflow', }, // ---------------------------------- @@ -128,27 +129,30 @@ export class ToolWorkflow implements INodeType { source: ['parameter'], }, }, - default: '\n\n\n', + default: '\n\n\n\n\n\n\n\n\n', required: true, description: 'The workflow JSON code to execute', }, + // ---------------------------------- + // For all + // ---------------------------------- { - displayName: 'Response Property Name', + displayName: 'Field to Return', name: 'responsePropertyName', type: 'string', default: 'response', - description: 'The name of the property of the last node that will be returned as response', + required: true, + hint: 'The field in the last-executed node of the workflow that contains the response', + description: + 'Where to find the data that this tool should return. n8n will look in the output of the last-executed node of the workflow for a field with this name, and return its value.', }, - - // ---------------------------------- - // For all - // ---------------------------------- { - displayName: 'Workflow Values', + displayName: 'Extra Workflow Inputs', name: 'fields', placeholder: 'Add Value', type: 'fixedCollection', - description: 'Set the values which should be made available in the workflow', + description: + "These will be output by the 'execute workflow' trigger of the workflow being called", typeOptions: { multipleValues: true, sortable: true, @@ -296,6 +300,14 @@ export class ToolWorkflow implements INodeType { itemIndex, ) as string; + if (!responsePropertyName) { + throw new NodeOperationError(this.getNode(), "Field to return can't be empty", { + itemIndex, + description: + 'Enter the name of a field in the last node of the workflow that contains the response to return', + }); + } + const workflowInfo: IExecuteWorkflowInfo = {}; if (source === 'database') { // Read workflow from database @@ -399,10 +411,9 @@ export class ToolWorkflow implements INodeType { if (typeof response !== 'string') { // TODO: Do some more testing. Issues here should actually fail the workflow - executionError = new NodeOperationError( - this.getNode(), - `The code did not return a valid value. Instead of a string did a value of type '${typeof response}' get returned.`, - ); + executionError = new NodeOperationError(this.getNode(), 'Wrong output type returned', { + description: `The response property should be a string, but it is an ${typeof response}`, + }); response = `There was an error: "${executionError.message}"`; }