Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(flows): chips no longer hide the rest of an expression after the variable (#14937)

Bartosz Majewskid0223e562606
diff --git a/brain/knowledge/flows-execution/variables.md b/brain/knowledge/flows-execution/variables.md
index 7f9e53f926c..004ca7faea0 100644
--- a/brain/knowledge/flows-execution/variables.md
+++ b/brain/knowledge/flows-execution/variables.md
@@ -19,6 +19,7 @@ Project-scoped, encrypted secret values (API keys, tokens) users create once and
### Gotchas
- The create/rotate dialog value field is deliberately **NOT** `type="password"` (Chrome's leaked-password breach check + password-manager prompt, GIT-1619). It's `type="text"` masked with CSS `-webkit-text-security: disc`, `autoComplete="off"`, `spellCheck={false}`. Firefox < 118 renders unmasked (acceptable — only holds text being typed).
- Every reveal fires `VARIABLE_VALUE_REVEALED` (audit event `variable.value.revealed`) — use it for "who pulled variable X and when". Also `VARIABLE_UPSERTED`, `VARIABLE_DELETED`.
+- The engine ignores anything after the key in a `variables` token: `{{ variables['X'] || 'fallback' }}` goes to `parseVariableName`, never the script evaluator, so the fallback never runs and a missing variable still fails the step. Step tokens do evaluate `||`. The builder chip shows such tokens as the raw expression so the dropped part stays visible (GIT-1768).
### Key files
Entry point: `variableModule`, registered in `packages/server/api/src/app/app.ts`.
diff --git a/packages/web/src/app/builder/piece-properties/text-input-with-mentions/text-input-utils.ts b/packages/web/src/app/builder/piece-properties/text-input-with-mentions/text-input-utils.ts
index 38bbba81429..c63ef079d80 100644
--- a/packages/web/src/app/builder/piece-properties/text-input-with-mentions/text-input-utils.ts
+++ b/packages/web/src/app/builder/piece-properties/text-input-with-mentions/text-input-utils.ts
@@ -332,28 +332,36 @@ const removeIntroplationBrackets = (text: string) => {
return text;
};
+const pureAccessorRegex =
+ /^[\p{L}_$][\p{L}\p{N}_$]*(?:\.[\p{L}\p{N}_$]+|\[\s*(?:'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|\d+)\s*\])*$/u;
+
function parseStepAndNameFromMention(mention: string) {
- const mentionWithoutInterpolationBrackets =
- removeIntroplationBrackets(mention);
- const { isValid, stepName, arrayPath } = parseFlattenArrayPath(
- mentionWithoutInterpolationBrackets,
- );
+ const expression = removeIntroplationBrackets(mention);
+ const { isValid, stepName, arrayPath } = parseFlattenArrayPath(expression);
if (isValid) {
return {
stepName,
path: arrayPath ?? [],
+ expression,
+ isPureAccessor: true,
};
}
- const keys = keysWithinPath(mentionWithoutInterpolationBrackets);
+ const keys = pureAccessorRegex.test(expression)
+ ? keysWithinPath(expression)
+ : [];
if (keys.length === 0) {
return {
stepName: null,
path: [],
+ expression,
+ isPureAccessor: false,
};
}
return {
stepName: keys[0],
path: keys.slice(1),
+ expression,
+ isPureAccessor: true,
};
}
@@ -363,7 +371,16 @@ function parseLabelFromMention(
stepsMetadata: (StepMetadataWithDisplayName | undefined)[],
variableByName?: Map<string, string>,
) {
- const { stepName, path } = parseStepAndNameFromMention(mention);
+ const { stepName, path, expression, isPureAccessor } =
+ parseStepAndNameFromMention(mention);
+ if (!isPureAccessor) {
+ return {
+ displayText: expression,
+ serverValue: mention,
+ logoUrl: undefined,
+ isVariable: expression.startsWith('variables'),
+ };
+ }
if (stepName === 'variables') {
const name = path[0] ?? '';
const displayName = variableByName?.get(name) ?? name;
diff --git a/packages/web/test/app/builder/piece-properties/text-input-with-mentions/text-input-utils.test.ts b/packages/web/test/app/builder/piece-properties/text-input-with-mentions/text-input-utils.test.ts
index e53ef72848e..915dfa36c88 100644
--- a/packages/web/test/app/builder/piece-properties/text-input-with-mentions/text-input-utils.test.ts
+++ b/packages/web/test/app/builder/piece-properties/text-input-with-mentions/text-input-utils.test.ts
@@ -23,6 +23,73 @@ describe('textMentionUtils.parseLabelFromMention — flattenNestedKeys', () => {
});
});
+describe('textMentionUtils.parseLabelFromMention: expressions render raw', () => {
+ it('shows the || fallback on a variable chip', () => {
+ const label = textMentionUtils.parseLabelFromMention(
+ "{{ variables['X'] || 'fallback' }}",
+ [],
+ [],
+ );
+ expect(label.displayText).toBe("variables['X'] || 'fallback'");
+ expect(label.isVariable).toBe(true);
+ expect(label.serverValue).toBe("{{ variables['X'] || 'fallback' }}");
+ });
+
+ it('keeps a plain variable chip label friendly', () => {
+ const label = textMentionUtils.parseLabelFromMention(
+ "{{ variables['X'] }}",
+ [],
+ [],
+ );
+ expect(label.displayText).toBe('Variable · X');
+ });
+
+ it('shows a step expression whole instead of dot-splitting it', () => {
+ const label = textMentionUtils.parseLabelFromMention(
+ '{{ step_1.body.x || step_1.body.y }}',
+ [],
+ [],
+ );
+ expect(label.displayText).toBe('step_1.body.x || step_1.body.y');
+ });
+
+ it('shows a parenthesized expression whole', () => {
+ const label = textMentionUtils.parseLabelFromMention(
+ '{{ (step_1.body.x || step_1.body.y) }}',
+ [],
+ [],
+ );
+ expect(label.displayText).toBe('(step_1.body.x || step_1.body.y)');
+ });
+
+ it('keeps a pure accessor with array index on the friendly path', () => {
+ const label = textMentionUtils.parseLabelFromMention(
+ "{{ step_1['output'].items[0] }}",
+ [],
+ [],
+ );
+ expect(label.displayText).toBe('(Missing) step_1');
+ });
+
+ it('keeps an escaped-quote bracket key on the friendly path', () => {
+ const label = textMentionUtils.parseLabelFromMention(
+ "{{ step_1['output']['it\\'s here'] }}",
+ [],
+ [],
+ );
+ expect(label.displayText).toBe('(Missing) step_1');
+ });
+
+ it('keeps a non-ascii dot key on the friendly path', () => {
+ const label = textMentionUtils.parseLabelFromMention(
+ '{{ trigger.body.pełna }}',
+ [],
+ [],
+ );
+ expect(label.displayText).toBe('(Missing) trigger');
+ });
+});
+
const convert = (text: string) =>
textMentionUtils.convertTextToTipTapJsonContent(text, [], []);