1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-11-10 12:35:46 +03:00

fix(core): Custom workflow tool tweaks (#8561)

This commit is contained in:
Michael Kret 2024-02-08 18:12:45 +02:00 committed by GitHub
parent e28b374170
commit ccc0ad5009
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 22 deletions

View File

@ -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}"`;
}

View File

@ -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',
},
{
displayName: 'Response Property Name',
name: 'responsePropertyName',
type: 'string',
default: 'response',
description: 'The name of the property of the last node that will be returned as response',
},
// ----------------------------------
// For all
// ----------------------------------
{
displayName: 'Workflow Values',
displayName: 'Field to Return',
name: 'responsePropertyName',
type: 'string',
default: '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.',
},
{
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}"`;
}