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.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2025-03-13 12:06:36 -03:00 committed by GitHub
commit d59f420812
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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[]) {