Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

restore isTemplateVarsEnabled() to accept attribute value

Forhad Hosain5642085d5966
diff --git a/packages/app/src/builder-ui/ui/dom.ts b/packages/app/src/builder-ui/ui/dom.ts
index d3233e46..5a5432cd 100644
--- a/packages/app/src/builder-ui/ui/dom.ts
+++ b/packages/app/src/builder-ui/ui/dom.ts
@@ -6,6 +6,7 @@ declare global {
}
}
+import { isTemplateVarsEnabled } from '../utils/form.utils';
import { addBracketSelection } from './form/misc';
export function setCaratAtEnd(element) {
@@ -125,7 +126,8 @@ export function setCodeEditor(
textAreas?.forEach((textArea) => {
if (textArea?.tagName !== 'TEXTAREA') return;
const isReadOnly = textArea?.hasAttribute('readonly');
- const hasDataTempVarsTrue = textArea && textArea?.getAttribute('data-template-vars') === 'true';
+ const hasDataTempVarsTrue =
+ textArea && isTemplateVarsEnabled(textArea.getAttribute('data-template-vars'));
const dataAttr = textArea?.getAttribute('data-hide-line-numbers');
const scrollMarginTop = textArea?.getAttribute('data-scroll-margin-top') || 20;
const scrollMarginBottom = textArea?.getAttribute('data-scroll-margin-bottom') || 20;
@@ -240,9 +242,11 @@ export function setCodeEditor(
Object.values(errorTooltips).forEach((tooltip: any) => (tooltip.style.display = 'none'));
// Hide all tooltips from other editors to prevent duplicates
- document.querySelectorAll(`.ace_tooltip:not([data-editor-tooltip-id="${editorTooltipId}"])`).forEach((tooltip: any) => {
- tooltip.style.display = 'none';
- });
+ document
+ .querySelectorAll(`.ace_tooltip:not([data-editor-tooltip-id="${editorTooltipId}"])`)
+ .forEach((tooltip: any) => {
+ tooltip.style.display = 'none';
+ });
const row = e.getDocumentPosition().row;
const gutterRegion = e.domEvent.target.className;
@@ -255,8 +259,9 @@ export function setCodeEditor(
// Check if this editor has internal scrolling enabled (maxLines !== Infinity)
// Only apply scroll offset for editors with internal scrolling
- const hasInternalScrolling = editor.getOption('maxLines') === null || editor.getOption('maxLines') === undefined;
- const scrollTop = hasInternalScrolling ? (editor.renderer.scrollTop || 0) : 0;
+ const hasInternalScrolling =
+ editor.getOption('maxLines') === null || editor.getOption('maxLines') === undefined;
+ const scrollTop = hasInternalScrolling ? editor.renderer.scrollTop || 0 : 0;
// Temporarily display the tooltip to measure its dimensions
tooltip.style.visibility = 'hidden';
@@ -300,9 +305,11 @@ export function setCodeEditor(
if (!e.domEvent.target.className.includes('ace_gutter-cell')) {
// Hide all tooltips from this editor and other editors
Object.values(errorTooltips)?.forEach((tooltip: any) => (tooltip.style.display = 'none'));
- document.querySelectorAll(`.ace_tooltip:not([data-editor-tooltip-id="${editorTooltipId}"])`).forEach((tooltip: any) => {
- tooltip.style.display = 'none';
- });
+ document
+ .querySelectorAll(`.ace_tooltip:not([data-editor-tooltip-id="${editorTooltipId}"])`)
+ .forEach((tooltip: any) => {
+ tooltip.style.display = 'none';
+ });
}
});
@@ -320,9 +327,11 @@ export function setCodeEditor(
Object?.values(errorTooltips)?.forEach?.(
(tooltip: any) => (tooltip.style.display = 'none'),
);
- document.querySelectorAll(`.ace_tooltip:not([data-editor-tooltip-id="${editorTooltipId}"])`)?.forEach((tooltip: any) => {
- tooltip.style.display = 'none';
- });
+ document
+ .querySelectorAll(`.ace_tooltip:not([data-editor-tooltip-id="${editorTooltipId}"])`)
+ ?.forEach((tooltip: any) => {
+ tooltip.style.display = 'none';
+ });
}
});
diff --git a/packages/app/src/builder-ui/ui/form/createFormField.ts b/packages/app/src/builder-ui/ui/form/createFormField.ts
index ab56a7e2..def0168d 100644
--- a/packages/app/src/builder-ui/ui/form/createFormField.ts
+++ b/packages/app/src/builder-ui/ui/form/createFormField.ts
@@ -479,7 +479,7 @@ export default function createFormField(entry, displayType = 'block', entryIndex
// Automatically set autocomplete="off" for fields that support variable insertion
// data-template-vars can be "true" or an object like '{"enabled": true, "singleOnly": true}'
- const hasTemplateVars = isTemplateVarsEnabled(formElement);
+ const hasTemplateVars = isTemplateVarsEnabled(formElement.getAttribute('data-template-vars'));
if (
(hasTemplateVars ||
diff --git a/packages/app/src/builder-ui/ui/form/fields/index.ts b/packages/app/src/builder-ui/ui/form/fields/index.ts
index daa13a64..ef30a81c 100644
--- a/packages/app/src/builder-ui/ui/form/fields/index.ts
+++ b/packages/app/src/builder-ui/ui/form/fields/index.ts
@@ -9,6 +9,7 @@ import React from 'react';
import { createRoot } from 'react-dom/client';
import { delay } from '../../../utils';
import { handleKvFieldEditBtn, handleVaultBtn } from '../../../utils/component.utils';
+import { isTemplateVarsEnabled } from '../../../utils/form.utils';
import { addBracketSelection, handleTemplateVars } from '../misc';
declare var Metro;
@@ -796,7 +797,9 @@ function setupTemplateVarsIfNeeded(
modalTextareaInDialog: TextAreaWithEditor,
currentComponent: { _uid: string } | null,
): void {
- const hasTemplateVars = modalTextareaInDialog.getAttribute('data-template-vars') === 'true';
+ const hasTemplateVars = isTemplateVarsEnabled(
+ modalTextareaInDialog.getAttribute('data-template-vars'),
+ );
const hasAgentVars = modalTextareaInDialog.getAttribute('data-agent-vars') === 'true';
if (!hasTemplateVars && !hasAgentVars) {
diff --git a/packages/app/src/builder-ui/ui/form/misc.ts b/packages/app/src/builder-ui/ui/form/misc.ts
index 65b4fb69..73267df1 100644
--- a/packages/app/src/builder-ui/ui/form/misc.ts
+++ b/packages/app/src/builder-ui/ui/form/misc.ts
@@ -640,7 +640,7 @@ function shouldSkipDueToExistingVars(clickedElm: HTMLElement): boolean {
// Check if this is a field that should show variables
const isDatalistField = clickedElm.getAttribute('list');
const isVarField =
- isTemplateVarsEnabled(clickedElm) ||
+ isTemplateVarsEnabled(clickedElm.getAttribute('data-template-vars')) ||
clickedElm.getAttribute('data-agent-vars') === 'true' ||
clickedElm.getAttribute('data-trigger-vars') === 'true' ||
isDatalistField ||
@@ -815,7 +815,7 @@ export function handleTemplateVars(targetElm, component = null) {
// Handle template-vars fields
if (
- (isTemplateVarsEnabled(clickedElm) ||
+ (isTemplateVarsEnabled(clickedElm.getAttribute('data-template-vars')) ||
(clickedElm as HTMLElement)?.closest?.('[data-template-vars]')) &&
!(clickedElm as HTMLElement)?.closest?.('[readonly]')
) {
@@ -1019,7 +1019,7 @@ export function handleTemplateVars(targetElm, component = null) {
) as HTMLInputElement;
const isVarField =
- isTemplateVarsEnabled(clickedElm) ||
+ isTemplateVarsEnabled(clickedElm.getAttribute('data-template-vars')) ||
clickedElm.getAttribute('data-agent-vars') === 'true' ||
clickedElm.getAttribute('data-trigger-vars') === 'true' ||
clickedElm.getAttribute('list') || // Direct datalist field
@@ -1054,7 +1054,10 @@ export function handleTemplateVars(targetElm, component = null) {
const target = e.target as HTMLElement;
// Only trigger for datalist inputs with template vars (supports both "true" and object format)
- if (target.getAttribute('list') && isTemplateVarsEnabled(target)) {
+ if (
+ target.getAttribute('list') &&
+ isTemplateVarsEnabled(target.getAttribute('data-template-vars'))
+ ) {
// Check if variables are already showing for this field
const formGroup = target.closest('.form-group');
const existingWrapper = formGroup?.querySelector(`.${TEMPLATE_VAR_BTNS_WRAPPER_CLASS}`);
diff --git a/packages/app/src/builder-ui/utils/form.utils.ts b/packages/app/src/builder-ui/utils/form.utils.ts
index 164d7330..f0e8f547 100644
--- a/packages/app/src/builder-ui/utils/form.utils.ts
+++ b/packages/app/src/builder-ui/utils/form.utils.ts
@@ -30,32 +30,38 @@ export const dispatchInputEvent = (elm: HTMLInputElement | HTMLTextAreaElement):
};
/**
- * Checks if template variables are enabled based on the element's data-template-vars attribute.
+ * Checks if template variables are enabled from attribute value.
* Supports both simple boolean string ("true") and JSON object format ({"enabled": true, "singleOnly": true}).
+ * Returns true only if explicitly enabled, false for everything else.
*
* @example
- * // Pass element directly
- * isTemplateVarsEnabled(inputElement) // returns true if enabled
+ * const attrValue = element.getAttribute('data-template-vars');
+ * if (isTemplateVarsEnabled(attrValue)) {
+ * // Show template variable buttons
+ * }
*
- * // Works with any HTMLElement that has data-template-vars attribute
- * const formField = document.querySelector('.my-field');
- * isTemplateVarsEnabled(formField) // returns true if enabled
+ * isTemplateVarsEnabled('true') // returns true
+ * isTemplateVarsEnabled('{"enabled": true, "singleOnly": true}') // returns true
+ * isTemplateVarsEnabled('false') // returns false
+ * isTemplateVarsEnabled('{"enabled": false}') // returns false
+ * isTemplateVarsEnabled(null) // returns false
*
- * @param element - The HTML element to check for data-template-vars attribute
- * @returns true if template vars are enabled, false otherwise
+ * @param attributeValue - The data-template-vars attribute value string
+ * @returns true if explicitly enabled, false otherwise
*/
-export function isTemplateVarsEnabled(element: HTMLElement | null | undefined): boolean {
- if (!element) return false;
-
- const attributeValue = element.getAttribute('data-template-vars');
+export function isTemplateVarsEnabled(attributeValue: string | null | undefined): boolean {
if (!attributeValue) return false;
+
+ // Simple boolean string
if (attributeValue === 'true') return true;
+ // Try to parse as JSON object
try {
const config = JSON.parse(attributeValue);
+ // Check if enabled property is explicitly true
return config.enabled === true;
} catch {
- // Fallback: check for "enabled":true or "enabled": true in string
- return attributeValue.includes('"enabled":true') || attributeValue.includes('"enabled": true');
+ // Not valid JSON - return false
+ return false;
}
}