From d59f42081251db9bd0b53c72f583ce4eb5c7a671 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 13 Mar 2025 12:06:36 -0300 Subject: [PATCH] fix: check if component is in tool mode as well to display Tool Mode switch (#7042) feat: Enhance checkHasToolMode function to include tool mode detection Updated the checkHasToolMode function to account for an additional condition where the template is considered to be in tool mode if it contains exactly three fields: _type, code, and tools_metadata. This improves the function's ability to accurately determine the tool mode status of a template. --- src/frontend/src/utils/reactflowUtils.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index e91ffbe2a..699a9e3d4 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -1954,16 +1954,26 @@ export function checkHasToolMode(template: APITemplateType): boolean { if (!template) return false; const templateKeys = Object.keys(template); + + // Check if the template has no additional fields const hasNoAdditionalFields = templateKeys.length === 2 && Boolean(template.code) && Boolean(template._type); + // Check if the template has at least one field with a truthy 'tool_mode' property const hasToolModeFields = Object.values(template).some((field) => Boolean(field.tool_mode), ); + // Check if the component is already in tool mode + // This occurs when the template has exactly 3 fields: _type, code, and tools_metadata + const isInToolMode = + templateKeys.length === 3 && + Boolean(template.code) && + Boolean(template._type) && + Boolean(template.tools_metadata); - return hasNoAdditionalFields || hasToolModeFields; + return hasNoAdditionalFields || hasToolModeFields || isInToolMode; } export function buildPositionDictionary(nodes: AllNodeType[]) {