From ae6bbf507931cd0772148259b3025bd0dabd5d78 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 11 Mar 2025 13:00:31 -0300 Subject: [PATCH] fix: allow Components with no Inputs to have tool mode (#6958) refactor: Improve tool mode detection in template validation --- src/frontend/src/utils/reactflowUtils.ts | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 23f215c9b..e91ffbe2a 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -1939,8 +1939,31 @@ export function someFlowTemplateFields( }); } -export function checkHasToolMode(template: APITemplateType) { - return template && Object.values(template).some((field) => field.tool_mode); +/** + * Determines if the provided API template supports tool mode. + * + * A template is considered to support tool mode if either: + * - It contains only the 'code' and '_type' fields (with both being truthy), + * indicating that no additional fields exist. + * - At least one field in the template has a truthy 'tool_mode' property. + * + * @param template - The API template to evaluate. + * @returns True if the template supports tool mode capability; otherwise, false. + */ +export function checkHasToolMode(template: APITemplateType): boolean { + if (!template) return false; + + const templateKeys = Object.keys(template); + const hasNoAdditionalFields = + templateKeys.length === 2 && + Boolean(template.code) && + Boolean(template._type); + + const hasToolModeFields = Object.values(template).some((field) => + Boolean(field.tool_mode), + ); + + return hasNoAdditionalFields || hasToolModeFields; } export function buildPositionDictionary(nodes: AllNodeType[]) {