Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(webv2): cover the rest of the dynamic prompts syntax

joshistoast206c7a0aece5
diff --git a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.ts b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.ts
index da46d39e0c..0071b48b42 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.ts
@@ -17,6 +17,16 @@ describe('hasDynamicPromptSyntax', () => {
it('detects a wildcard reference', () => {
expect(hasDynamicPromptSyntax('a __colors__ ball')).toBe(true);
expect(hasDynamicPromptSyntax('a __animals/dogs__ ball')).toBe(true);
+ expect(hasDynamicPromptSyntax('a __artists/*__ ball')).toBe(true);
+ expect(hasDynamicPromptSyntax('a __~colors__ ball')).toBe(true);
+ expect(hasDynamicPromptSyntax('a __outfit(mood=warm)__ ball')).toBe(true);
+ });
+
+ // A comment is only stripped by going through the expander, and upstream has
+ // no escape for `#`, so any prompt containing one has to take the trip.
+ it('detects a comment', () => {
+ expect(hasDynamicPromptSyntax('a red ball # for now')).toBe(true);
+ expect(hasDynamicPromptSyntax('a red ball \\# for now')).toBe(true);
});
it('ignores prompts with neither a variant nor a wildcard', () => {
diff --git a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.ts b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.ts
index c585ef80ce..dd344d5edf 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.ts
@@ -38,15 +38,62 @@ export interface DynamicPromptsConfig {
const WILDCARD_NAME_SEGMENT = '[A-Za-z0-9](?:[A-Za-z0-9_-]*[A-Za-z0-9])?';
const WILDCARD_NAME_SOURCE = `${WILDCARD_NAME_SEGMENT}(?:/${WILDCARD_NAME_SEGMENT})*`;
+/**
+ * A referenced path, which is looser than a storable name: `*` may stand
+ * anywhere in it, and it may cross `/` while doing so. `__animals/*__`,
+ * `__colour*__` and a bare `__*__` are all things the backend resolves.
+ */
+const WILDCARD_PATH_SEGMENT = '[A-Za-z0-9*](?:[A-Za-z0-9_*-]*[A-Za-z0-9*])?';
+const WILDCARD_PATH_SOURCE = `${WILDCARD_PATH_SEGMENT}(?:/${WILDCARD_PATH_SEGMENT})*`;
+
/**
* `__name__`, the reference form for a wildcard. Shared with the syntax scanner
* so highlighting and expansion agree on what counts as a wildcard.
+ *
+ * Three optional parts ride along, all of which the backend accepts and none of
+ * which is part of the name being looked up:
+ *
+ * - a sampler override, `__~name__` (random) or `__@name__` (cyclical);
+ * - a glob, `__artists/*__`, resolving to every matching wildcard at once;
+ * - parameters, `__name(mood=warm)__`, binding `${mood}` inside the values.
+ *
+ * Capture group 1 is the path alone — the part to look up.
*/
-export const WILDCARD_REFERENCE_RE = new RegExp(`__(${WILDCARD_NAME_SOURCE})__`);
+export const WILDCARD_REFERENCE_RE = new RegExp(`__[~@]?(${WILDCARD_PATH_SOURCE})(?:\\([^()]*\\))?__`);
/** The same rule anchored, for validating a name the user is typing. */
export const WILDCARD_NAME_RE = new RegExp(`^${WILDCARD_NAME_SOURCE}$`);
+const escapeRegExp = (value: string): string => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
+
+/**
+ * Whether a referenced path resolves against the catalog.
+ *
+ * A glob matches when *any* known name matches it, mirroring the backend, where
+ * `*` is an unanchored run of any characters — `/` included, so `__*s__` reaches
+ * `animals/dogs`. `**` is spelt differently but means the same thing there, and
+ * falls out of the same translation.
+ *
+ * A path matching nothing is still worth flagging: the expansion leaves the
+ * literal `__name__` in the prompt rather than failing, so an unnoticed typo
+ * goes to the model as text.
+ */
+export const matchesKnownWildcard = (path: string, knownNames: ReadonlySet<string>): boolean => {
+ if (!path.includes('*')) {
+ return knownNames.has(path);
+ }
+
+ const pattern = new RegExp(`^${path.split('*').map(escapeRegExp).join('.*')}$`);
+
+ for (const name of knownNames) {
+ if (pattern.test(name)) {
+ return true;
+ }
+ }
+
+ return false;
+};
+
/** Mirrors the backend's `MAX_WILDCARD_NAME_LENGTH`. */
export const MAX_WILDCARD_NAME_LENGTH = 128;
@@ -81,11 +128,16 @@ export const getWildcardNameError = (
/**
* Whether a prompt is worth sending to the expansion route at all. A prompt with
- * neither a `{…}` variant nor a `__wildcard__` reference is its own single
- * expansion, so the round trip is skipped entirely.
+ * no dynamic syntax in it is its own single expansion, so the round trip is
+ * skipped entirely.
+ *
+ * `#` counts, because upstream treats it as a comment to end of line and strips
+ * it — with no way to escape it. Leaving it out would make whether a `#` reaches
+ * the model depend on whether the prompt happened to contain a `{…}` elsewhere,
+ * which is a worse surprise than the round trip.
*/
export const hasDynamicPromptSyntax = (prompt: string): boolean =>
- /\{[\s\S]*\}/.test(prompt) || WILDCARD_REFERENCE_RE.test(prompt);
+ /\{[\s\S]*\}/.test(prompt) || prompt.includes('#') || WILDCARD_REFERENCE_RE.test(prompt);
export const isDynamicPromptsSeedBehaviour = (value: unknown): value is DynamicPromptsSeedBehaviour =>
value === 'per-iteration' || value === 'per-image';
diff --git a/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.test.ts b/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.test.ts
index 0ddbff2ca3..063d00be42 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.test.ts
@@ -81,9 +81,113 @@ describe('scanDynamicPromptSyntax', () => {
]);
});
+ // Regression: globs, sampler overrides and parameters are all valid, and all
+ // read as ordinary text — or worse, as errors — before this.
+ it('annotates the looser reference forms the backend accepts', () => {
+ expect(annotate('__artists/*__ __~colours__ __@colours__ __outfit(mood=warm)__')).toEqual([
+ ['wildcard', '__artists/*__'],
+ ['wildcard', '__~colours__'],
+ ['wildcard', '__@colours__'],
+ ['wildcard', '__outfit(mood=warm)__'],
+ ]);
+ });
+
+ it('flags a reference no known wildcard answers to', () => {
+ const known = new Set(['colours', 'animals/dogs']);
+ const scan = (prompt: string) => scanDynamicPromptSyntax(prompt, known).map(({ kind }) => kind);
+
+ expect(scan('__colours__')).toEqual(['wildcard']);
+ expect(scan('__nope__')).toEqual(['error']);
+ // A glob is known when anything matches it, and `*` crosses `/` as it does
+ // on the backend.
+ expect(scan('__animals/*__')).toEqual(['wildcard']);
+ expect(scan('__*s__')).toEqual(['wildcard']);
+ expect(scan('__nope/*__')).toEqual(['error']);
+ // The sampler and the parameters are not part of the name being looked up.
+ expect(scan('__~colours__')).toEqual(['wildcard']);
+ expect(scan('__colours(mood=warm)__')).toEqual(['wildcard']);
+ });
+
+ it('leaves snake__case alone', () => {
+ expect(annotate('a snake__case word')).toEqual([]);
+ });
+
it('annotates a variable reference as one span, without descending into it', () => {
expect(annotate(`\${colour} ball`)).toEqual([['promptVariable', `\${colour}`]]);
- expect(annotate(`\${colour=red|green}`)).toEqual([['promptVariable', `\${colour=red|green}`]]);
+ });
+
+ it('marks the operator that makes a variable an assignment', () => {
+ expect(annotate(`\${colour=red|green}`)).toEqual([
+ ['promptVariable', `\${colour=red|green}`],
+ ['promptVariableOperator', '='],
+ ]);
+ expect(annotate(`\${colour=!{red|green}}`)).toEqual([
+ ['promptVariable', `\${colour=!{red|green}}`],
+ ['promptVariableOperator', '=!'],
+ ]);
+ expect(annotate(`\${colour:crimson}`)).toEqual([
+ ['promptVariable', `\${colour:crimson}`],
+ ['promptVariableOperator', ':'],
+ ]);
+ });
+
+ // A `:` in the assigned value belongs to the value, not to this variable.
+ it('marks only the first operator in a variable', () => {
+ expect(annotate(`\${caption=a:b:c}`)).toEqual([
+ ['promptVariable', `\${caption=a:b:c}`],
+ ['promptVariableOperator', '='],
+ ]);
+ });
+
+ it('annotates the sampler that opens a variant', () => {
+ expect(annotate('{~red|green}')).toEqual([
+ ['variantBrace', '{'],
+ ['variantSampler', '~'],
+ ['variantSeparator', '|'],
+ ['variantBrace', '}'],
+ ]);
+ expect(annotate('{@red|green}')).toEqual([
+ ['variantBrace', '{'],
+ ['variantSampler', '@'],
+ ['variantSeparator', '|'],
+ ['variantBrace', '}'],
+ ]);
+ });
+
+ // The sampler binds tighter than the count: `{2$$~a|b}` has `~a` as a value.
+ it('takes the sampler before the count, and only there', () => {
+ expect(annotate('{~2$$red|green}')).toEqual([
+ ['variantBrace', '{'],
+ ['variantSampler', '~'],
+ ['variantRange', '2$$'],
+ ['variantSeparator', '|'],
+ ['variantBrace', '}'],
+ ]);
+ expect(annotate('{2$$~red|green}')).toEqual([
+ ['variantBrace', '{'],
+ ['variantRange', '2$$'],
+ ['variantSeparator', '|'],
+ ['variantBrace', '}'],
+ ]);
+ });
+
+ it('dims a comment, and everything it swallows', () => {
+ expect(annotate('a cat # {unclosed __nope__')).toEqual([['comment', '# {unclosed __nope__']]);
+ });
+
+ // `\#` is not an escape upstream — it comments from the `#` and leaves the
+ // backslash in the prompt — so the scanner must not treat it as one either.
+ it('comments from a backslash-escaped hash too', () => {
+ expect(annotate('a \\# b')).toEqual([['comment', '# b']]);
+ });
+
+ it('ends a comment at the newline', () => {
+ expect(annotate('a # note\n{red|green}')).toEqual([
+ ['comment', '# note'],
+ ['variantBrace', '{'],
+ ['variantSeparator', '|'],
+ ['variantBrace', '}'],
+ ]);
});
it('skips escaped braces', () => {
diff --git a/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.ts b/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.ts
index c0cb088e6f..639bf3dd86 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.ts
@@ -1,6 +1,35 @@
/**
- * Scanner for adieyal/dynamicprompts syntax (`{a|b}`, `{2::a|b}`, `{2-3$$a|b}`,
- * `__wildcard__`, `${variable}`).
+ * Scanner for adieyal/dynamicprompts syntax.
+ *
+ * ## The syntax, in full
+ *
+ * The backend runs the real `dynamicprompts` library, so everything below works
+ * at generate time whether or not this scanner colours it. Kept here, beside the
+ * code that recognizes each form, so the two cannot drift apart.
+ *
+ * | Form | Meaning | Example |
+ * | --- | --- | --- |
+ * | `{a\|b}` | Pick one alternative | `a {red\|green} ball` |
+ * | `{2$$a\|b\|c}` | Pick exactly two, comma-joined | `{2$$red\|green\|blue}` |
+ * | `{1-3$$a\|b\|c}` | Pick between one and three | `{1-3$$red\|green\|blue}` |
+ * | `{2$$ and $$a\|b}` | Pick two, joined by a custom separator | `{2$$ and $$red\|green}` |
+ * | `{2::a\|b}` | Weight an alternative — `a` twice as likely | `{2::red\|green}` |
+ * | `{~a\|b}` | Sample randomly, ignoring combinatorial mode | `{~red\|green}` |
+ * | `{@a\|b}` | Cycle through the alternatives in order | `{@red\|green}` |
+ * | `__name__` | Substitute one value from a wildcard | `a __colours__ ball` |
+ * | `__a/b__` | Nested wildcard names | `__animals/dogs__` |
+ * | `__art/*__` | Glob — draws from every matching wildcard | `__artists/*__` |
+ * | `__~name__` | Sampler override on a wildcard | `__@colours__` |
+ * | `__name(k=v)__` | Bind `${k}` inside that wildcard's values | `__outfit(mood=warm)__` |
+ * | `${v=a}` | Assign a variable; expands to nothing itself | `${lens=85mm} shot on ${lens}` |
+ * | `${v=!{a\|b}}` | Assign once, immediately — every use is the same value | `${v=!{a\|b}} ${v} ${v}` |
+ * | `${v}` | Use a variable | `${lens}` |
+ * | `${v:fallback}` | Use a variable, or this if it is unset | `${lens:50mm}` |
+ * | `# …` | Comment to end of line; stripped before generating | `a cat # for now` |
+ *
+ * Written to be lifted wholesale into the app-wide help system when that lands.
+ *
+ * ## Why a separate scanner
*
* This is intentionally a standalone character scanner rather than an extension
* of `ast.ts`. That tokenizer already emits every character we care about as its
@@ -11,7 +40,7 @@
* embedding parser untouched.
*/
-import { WILDCARD_REFERENCE_RE } from '@features/generation/core/dynamicPrompts';
+import { matchesKnownWildcard, WILDCARD_REFERENCE_RE } from '@features/generation/core/dynamicPrompts';
import type { PromptRange } from './ast';
@@ -20,8 +49,11 @@ export type DynamicPromptSyntaxKind =
| 'variantSeparator'
| 'variantWeight'
| 'variantRange'
+ | 'variantSampler'
| 'wildcard'
| 'promptVariable'
+ | 'promptVariableOperator'
+ | 'comment'
| 'error';
export interface DynamicPromptSyntaxAnnotation {
@@ -33,6 +65,13 @@ export interface DynamicPromptSyntaxAnnotation {
const WEIGHT_PATTERN = /^\s*\d+(?:\.\d+)?::/;
/** `2$$`, `2-3$$`, `-3$$`, and the custom-separator form `2$$, $$`. */
const RANGE_PATTERN = /^\s*(?:\d+)?(?:-\d+)?\$\$(?:[^$|{}]*\$\$)?/;
+/**
+ * The operator that makes a `${…}` an assignment rather than a use: `=`, the
+ * immediate `=!`, or the `:` introducing a fallback. Muted like a variant's `|`,
+ * which is enough to tell a definition from a reference at a glance without
+ * spending another colour on it.
+ */
+const VARIABLE_OPERATOR_PATTERN = /=!?|:/;
const isEscaped = (prompt: string, index: number): boolean => {
let backslashes = 0;
@@ -79,7 +118,11 @@ export const scanDynamicPromptSyntax = (
knownWildcards?: ReadonlySet<string>
): DynamicPromptSyntaxAnnotation[] => {
const annotations: DynamicPromptSyntaxAnnotation[] = [];
+ // Spans the wildcard sweep below must not look inside: a `__name__` written in
+ // either is not a reference, and reporting one would be a mistake the renderer
+ // then has to out-prioritize.
const variableRanges: PromptRange[] = [];
+ const commentRanges: PromptRange[] = [];
// Open braces awaiting a `}`, paired with the annotation to rewrite if none arrives.
const openBraces: { annotationIndex: number }[] = [];
let index = 0;
@@ -92,11 +135,43 @@ export const scanDynamicPromptSyntax = (
}
};
+ /**
+ * The first operator inside a `${…}`, over the name and nothing after it — a
+ * `:` or `=` further in belongs to the assigned value, which may itself be a
+ * whole nested prompt.
+ */
+ const annotateVariableOperator = (contentStart: number, contentEnd: number): void => {
+ const name = prompt.slice(contentStart, contentEnd);
+ const operator = name.match(VARIABLE_OPERATOR_PATTERN);
+
+ if (operator?.index !== undefined) {
+ const start = contentStart + operator.index;
+
+ annotations.push({ kind: 'promptVariableOperator', range: { end: start + operator[0].length, start } });
+ }
+ };
+
while (index < prompt.length) {
const char = prompt[index];
+ // Comments outrank everything: the parser strips them before it sees any of
+ // the syntax below, so an unbalanced brace or an unknown wildcard inside one
+ // is inert text rather than a mistake.
+ if (char === '#') {
+ const lineEnd = prompt.indexOf('\n', index);
+ const end = lineEnd === -1 ? prompt.length : lineEnd;
+
+ annotations.push({ kind: 'comment', range: { end, start: index } });
+ commentRanges.push({ end, start: index });
+ index = end;
+ continue;
+ }
+
if (char === '\\') {
- index += 2;
+ // `#` is the one character a backslash does not escape: upstream still
+ // comments from it and leaves the backslash in the prompt. Stepping over
+ // just the backslash lets the branch above see it on the next pass.
+ index += prompt[index + 1] === '#' ? 1 : 2;
continue;
}
@@ -106,6 +181,7 @@ export const scanDynamicPromptSyntax = (
if (end > 0) {
annotations.push({ kind: 'promptVariable', range: { end, start: index } });
variableRanges.push({ end, start: index });
+ annotateVariableOperator(index + 2, end - 1);
index = end;
continue;
}
@@ -115,6 +191,13 @@ export const scanDynamicPromptSyntax = (
annotations.push({ kind: 'variantBrace', range: { end: index + 1, start: index } });
openBraces.push({ annotationIndex: annotations.length - 1 });
+ // The sampler override binds tightest — `{~2$$a|b}` samples randomly, while
+ // `{2$$~a|b}` has `~a` as an ordinary alternative.
+ if (prompt[index + 1] === '~' || prompt[index + 1] === '@') {
+ annotations.push({ kind: 'variantSampler', range: { end: index + 2, start: index + 1 } });
+ index++;
+ }
+
const rangePrefix = prompt.slice(index + 1).match(RANGE_PATTERN)?.[0];
if (rangePrefix) {
@@ -160,10 +243,12 @@ export const scanDynamicPromptSyntax = (
for (let match = wildcardPattern.exec(prompt); match; match = wildcardPattern.exec(prompt)) {
const wildcardRange = { end: match.index + match[0].length, start: match.index };
- if (!variableRanges.some((variableRange) => covers(variableRange, wildcardRange))) {
- // An unresolvable wildcard makes the whole prompt fail to expand, so it earns the same
- // treatment as an unbalanced brace rather than looking like ordinary recognised syntax.
- const isUnknown = knownWildcards !== undefined && !knownWildcards.has(match[1]);
+ if (![...variableRanges, ...commentRanges].some((outer) => covers(outer, wildcardRange))) {
+ // An unresolvable wildcard survives expansion as its own literal text, so it earns the
+ // same treatment as an unbalanced brace rather than looking like ordinary recognised
+ // syntax. `matchesKnownWildcard` resolves globs, which is why a valid `__artists/*__`
+ // is no longer flagged for the sin of not being a name.
+ const isUnknown = knownWildcards !== undefined && !matchesKnownWildcard(match[1], knownWildcards);
annotations.push({ kind: isUnknown ? 'error' : 'wildcard', range: wildcardRange });
}
diff --git a/invokeai/frontend/webv2/src/features/generation/core/prompt/highlight.test.ts b/invokeai/frontend/webv2/src/features/generation/core/prompt/highlight.test.ts
index f0f057f8e3..ed630e03dd 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/prompt/highlight.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/prompt/highlight.test.ts
@@ -75,6 +75,28 @@ describe('prompt highlight segments', () => {
expect(dynamicKindForText(`\${colour} ball`, `\${colour}`)).toBe('promptVariable');
});
+ it('marks a sampler prefix and a variable’s assignment operator', () => {
+ expect(dynamicKindForText('{~red|green}', '~')).toBe('variantSampler');
+ expect(dynamicKindForText('{@red|green}', '@')).toBe('variantSampler');
+ expect(dynamicKindForText(`\${lens=85mm}`, '=')).toBe('promptVariableOperator');
+ // A bare reference has no operator to mark, and stays one flat span.
+ expect(dynamicKindForText(`\${lens}`, `\${lens}`)).toBe('promptVariable');
+ });
+
+ // The comment wins over the error the unknown wildcard would otherwise be:
+ // upstream strips the comment before it ever looks the name up.
+ it('dims a comment over everything inside it', () => {
+ const known = new Set(['colors']);
+ const segments = buildPromptHighlightSegments('a cat # __nope__ {unclosed', {
+ dynamicPrompts: true,
+ knownWildcards: known,
+ });
+
+ expect(segments.filter((segment) => segment.range.start >= 6).map((segment) => segment.kind)).toEqual([
+ 'comment',
+ ]);
+ });
+
it('marks an unknown wildcard as an error and a known one as recognised syntax', () => {
const known = new Set(['colors']);
const kindWithCatalog = (prompt: string, text: string) =>
@@ -84,6 +106,10 @@ describe('prompt highlight segments', () => {
expect(kindWithCatalog('a __colors__ ball', '__colors__')).toBe('wildcard');
expect(kindWithCatalog('a __nope__ ball', '__nope__')).toBe('error');
+ // A glob resolves against the catalog rather than being flagged for not
+ // being a name of its own.
+ expect(kindWithCatalog('a __colo*__ ball', '__colo*__')).toBe('wildcard');
+ expect(kindWithCatalog('a __nope/*__ ball', '__nope/*__')).toBe('error');
// Without a catalog nothing is known to be missing, so neither is an error.
expect(dynamicKindForText('a __nope__ ball', '__nope__')).toBe('wildcard');
});
diff --git a/invokeai/frontend/webv2/src/features/generation/core/prompt/highlight.ts b/invokeai/frontend/webv2/src/features/generation/core/prompt/highlight.ts
index 62c757d5e1..b63882719e 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/prompt/highlight.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/prompt/highlight.ts
@@ -17,8 +17,11 @@ export type PromptHighlightKind =
| 'variantSeparator'
| 'variantWeight'
| 'variantRange'
+ | 'variantSampler'
| 'wildcard'
| 'promptVariable'
+ | 'promptVariableOperator'
+ | 'comment'
| 'error';
export interface PromptHighlightOptions {
@@ -46,10 +49,15 @@ interface HighlightAnnotation {
}
const ANNOTATION_PRIORITY = {
+ // A comment outranks even an error: the parser strips it before it sees the
+ // syntax inside, so nothing in there can be wrong.
+ comment: 110,
error: 100,
+ promptVariableOperator: 46,
wildcard: 45,
promptVariable: 45,
variantRange: 42,
+ variantSampler: 42,
variantWeight: 42,
variantBrace: 41,
variantSeparator: 41,
@@ -61,6 +69,7 @@ const ANNOTATION_PRIORITY = {
const BASE_PRIORITY: Record<PromptHighlightKind, number> = {
attention: 30,
attentionNumeric: 30,
+ comment: 110,
embedding: 30,
error: 100,
escapedParen: 20,
@@ -68,10 +77,12 @@ const BASE_PRIORITY: Record<PromptHighlightKind, number> = {
promptFunctionArg: 5,
promptFunctionMethod: 35,
promptVariable: 45,
+ promptVariableOperator: 46,
punctuation: 10,
text: 0,
variantBrace: 41,
variantRange: 42,
+ variantSampler: 42,
variantSeparator: 41,
variantWeight: 42,
wildcard: 45,
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptHighlight.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptHighlight.tsx
index 7ecb21b20d..4ee5490560 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptHighlight.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptHighlight.tsx
@@ -21,6 +21,8 @@ export const HIGHLIGHT_STYLE_BY_KIND: Record<
> = {
attention: { color: 'accent.solid' },
attentionNumeric: { color: 'fg.success' },
+ // Stripped before generating, so it reads as the quietest thing on the line.
+ comment: { color: 'fg.muted' },
embedding: { bg: 'bg.warning', color: 'fg.warning' },
error: { bg: 'bg.error', color: 'fg.error', textDecoration: 'underline wavy', textDecorationColor: 'fg.error' },
escapedParen: { color: 'fg.muted' },
@@ -28,10 +30,16 @@ export const HIGHLIGHT_STYLE_BY_KIND: Record<
promptFunctionArg: { bg: 'accent.subtle/20', color: 'fg' },
promptFunctionMethod: { color: 'accent.fg' },
promptVariable: { color: 'accent.fg' },
+ // Muted like a variant's `|`: structure, not content. Its presence is what
+ // separates `${lens=85mm}` defining a variable from `${lens}` using one.
+ promptVariableOperator: { color: 'fg.muted' },
punctuation: { color: 'fg.subtle' },
text: { color: 'fg' },
variantBrace: { color: 'accent.fg' },
variantRange: { color: 'fg.success' },
+ // A sampler override changes how many/which alternatives come out, so it sits
+ // with the other count modifiers rather than earning a colour of its own.
+ variantSampler: { color: 'fg.success' },
variantSeparator: { color: 'fg.muted' },
variantWeight: { color: 'fg.success' },
wildcard: { color: 'fg.subtle' },