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:
parent
f0331d116d
commit
d59f420812
1 changed files with 11 additions and 1 deletions
|
|
@ -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[]) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue