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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(ui): add date token suggestions and feedback to command palette
joshistoast8fa58ad94fb8
diff --git a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.browser.test.tsxindex c1559c51c3..19cc31f7c6 100644--- a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.browser.test.tsx@@ -139,6 +139,127 @@ describe('CommandPaletteDialog interaction', () => {await vi.waitFor(() => expect(document.activeElement).toBe(input));});+ it('shows key-specific date suggestions while typing a token, without flashing an error', async () => {+ const provider: PaletteSearchProvider = {+ contextKey: 'context',+ label: 'Images',+ providerKey: 'images',+ search: vi.fn(() => []),+ supportsCreatedAtRange: true,+ };+ const { input } = await renderPalette({ entries: [entry('first', 'First command')], providers: [provider] });++ await act(() => userEvent.fill(input, 'from:'));++ expect(document.body.textContent).toContain('Today');+ expect(document.body.textContent).toContain('Yesterday');+ expect(document.body.textContent).toContain('Past week');+ expect(document.body.textContent).toContain('Or type a date');+ expect(document.body.textContent).not.toContain('Invalid date');+ expect(input.getAttribute('aria-invalid')).toBeNull();++ // `to:` must not offer a span-shaped completion.+ await act(() => userEvent.fill(input, 'to:'));+ expect(document.body.textContent).not.toContain('Past week');+ });++ it('completes a suggestion in place and immediately queries providers with the structured query', async () => {+ const providerSearch = vi.fn(() => []);+ const provider: PaletteSearchProvider = {+ contextKey: 'context',+ label: 'Images',+ providerKey: 'images',+ search: providerSearch,+ supportsCreatedAtRange: true,+ };+ const { input, onClose } = await renderPalette({ entries: [], providers: [provider] });++ await act(() => userEvent.fill(input, 'from:y'));+ await act(() => userEvent.keyboard('{Enter}'));++ expect(input.value).toBe('from:yesterday ');+ expect(onClose).not.toHaveBeenCalled();+ await vi.waitFor(() => {+ expect(providerSearch).toHaveBeenCalledWith({+ range: { from: expect.stringMatching(/^\d{4}-\d{2}-\d{2}$/), to: undefined },+ text: '',+ });+ });+ expect(document.body.textContent).toContain('Search images by date');+ });++ it('fires only range-capable providers for a pure date query', async () => {+ const capableSearch = vi.fn(() => []);+ const dateLessSearch = vi.fn(() => []);+ const capable: PaletteSearchProvider = {+ contextKey: 'context',+ label: 'Images',+ providerKey: 'images',+ search: capableSearch,+ supportsCreatedAtRange: true,+ };+ const dateLess: PaletteSearchProvider = {+ contextKey: 'context',+ label: 'Workflows',+ providerKey: 'workflows',+ search: dateLessSearch,+ };+ const { input } = await renderPalette({ entries: [], providers: [capable, dateLess] });++ await act(() => userEvent.fill(input, 'from:7d'));+ await new Promise((resolve) => {+ globalThis.setTimeout(resolve, 250);+ });++ await vi.waitFor(() => expect(capableSearch).toHaveBeenCalled());+ expect(dateLessSearch).not.toHaveBeenCalled();+ });++ it('renders invalid date feedback with combobox aria wiring once the token is settled', async () => {+ const provider: PaletteSearchProvider = {+ contextKey: 'context',+ label: 'Images',+ providerKey: 'images',+ search: vi.fn(() => []),+ supportsCreatedAtRange: true,+ };+ const { input } = await renderPalette({ entries: [], providers: [provider] });++ // The trailing space settles the token — no longer an in-progress prefix.+ await act(() => userEvent.fill(input, 'from:lastweek '));++ const hint = document.getElementById('command-palette-date-hint');+ expect(hint?.textContent).toContain('Invalid date: “lastweek”');+ expect(hint?.getAttribute('role')).toBe('status');+ expect(input.getAttribute('aria-invalid')).toBe('true');+ expect(input.getAttribute('aria-describedby')).toBe('command-palette-date-hint');+ });++ it('treats date tokens as literal text when no range-capable provider is present', async () => {+ const dateLessSearch = vi.fn(() => []);+ const dateLess: PaletteSearchProvider = {+ contextKey: 'context',+ label: 'Workflows',+ providerKey: 'workflows',+ search: dateLessSearch,+ };+ const { input } = await renderPalette({ entries: [], providers: [dateLess] });++ await act(() => userEvent.fill(input, 'from:'));+ expect(document.body.textContent).not.toContain('Or type a date');++ await act(() => userEvent.fill(input, 'from:7d'));+ await new Promise((resolve) => {+ globalThis.setTimeout(resolve, 250);+ });++ // No acknowledgment chip, and the provider receives the literal text.+ expect(document.getElementById('command-palette-date-hint')).toBeNull();+ await vi.waitFor(() => {+ expect(dateLessSearch).toHaveBeenCalledWith({ range: undefined, text: 'from:7d' });+ });+ });+it('drives stage preview from navigation and restores it on Escape and unmount', async () => {const preview = vi.fn();const clearPreview = vi.fn();diff --git a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsx b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsxindex 44d6fc7ae0..8043091241 100644--- a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsx@@ -17,6 +17,7 @@ import { useCommandPaletteController } from './useCommandPaletteController';const INPUT_PLACEHOLDER_STYLE = { color: 'fg.subtle' };const INPUT_FOCUS_WITHIN_STYLE = { outlineColor: 'accent.focusRing' };+const DATE_HINT_ID = 'command-palette-date-hint';const NO_PROVIDERS: PaletteSearchProvider[] = [];const NAV_HINT_KEYS = ['↑', '↓'];const ENTER_HINT_KEYS = ['↵'];@@ -176,7 +177,9 @@ const CommandPaletteContent = ({controller.activeRowId ? getCommandPaletteRowDomId(controller.activeRowId) : undefined}aria-controls="command-palette-results"+ aria-describedby={controller.dateInvalidHint ? DATE_HINT_ID : undefined}aria-expanded="true"+ aria-invalid={controller.dateInvalidHint ? true : undefined}aria-label="Search commands and settings"bg="transparent"color="fg"@@ -191,6 +194,25 @@ const CommandPaletteContent = ({onChange={controller.onSearchChange}onKeyDown={onSearchKeyDown}/>+ {controller.dateInvalidHint ? (+ <Text color="fg.error" flexShrink={0} fontSize="xs" id={DATE_HINT_ID} maxW="45%" role="status" truncate>+ {controller.dateInvalidHint}+ </Text>+ ) : controller.dateSummary ? (+ <Text+ bg="bg.emphasized"+ borderRadius="sm"+ color="fg.muted"+ flexShrink={0}+ fontSize="xs"+ id={DATE_HINT_ID}+ px="1.5"+ py="0.5"+ role="status"+ >+ {controller.dateSummary}+ </Text>+ ) : null}</HStack>{controller.rows.length === 0 ? (emptyStatediff --git a/invokeai/frontend/webv2/src/workbench/palette/useCommandPaletteController.ts b/invokeai/frontend/webv2/src/workbench/palette/useCommandPaletteController.tsindex d78e3542f0..4765b58132 100644--- a/invokeai/frontend/webv2/src/workbench/palette/useCommandPaletteController.ts+++ b/invokeai/frontend/webv2/src/workbench/palette/useCommandPaletteController.ts@@ -1,8 +1,15 @@+import type { DateTokenKey } from '@platform/search/dateTokens';/* eslint-disable react/react-compiler */import type { ChangeEvent, KeyboardEvent } from 'react';import { useMountEffect } from '@platform/react/useMountEffect';-import { parseDateTokens } from '@platform/search/dateTokens';+import {+ completeTrailingDateToken,+ formatDateRangeLabel,+ isPossibleDatePrefix,+ matchTrailingDateToken,+ parseDateTokens,+} from '@platform/search/dateTokens';import { useQueries } from '@tanstack/react-query';import { useCallback, useMemo, useRef, useState } from 'react';@@ -24,12 +31,40 @@ const PAGE_JUMP_ROWS = 8;const PROVIDER_DEBOUNCE_MS = 200;const NO_PROVIDERS: PaletteSearchProvider[] = [];+/**+ * Completions offered while a date token is being typed. `Nd` resolves to a+ * single date N days ago, so the labels are key-specific: `from:7d` is a+ * starting point ("Past week"), while `date:7d` is one day ("A week ago").+ */+const DATE_TOKEN_SUGGESTIONS: Record<DateTokenKey, ReadonlyArray<{ label: string; value: string }>> = {+ date: [+ { label: 'Today', value: 'today' },+ { label: 'Yesterday', value: 'yesterday' },+ { label: 'A week ago', value: '7d' },+ ],+ from: [+ { label: 'Today', value: 'today' },+ { label: 'Yesterday', value: 'yesterday' },+ { label: 'Past week', value: '7d' },+ ],+ to: [+ { label: 'Today', value: 'today' },+ { label: 'Yesterday', value: 'yesterday' },+ ],+};++const DATE_FORMAT_HINT = 'Or type a date — YYYY-MM-DD, 7d, 2w, 1m';+type ScrollToIndex = (index: number) => void;export interface CommandPaletteController {activeRow: PaletteRow | undefined;activeRowId: string | null;chipLabel: string | null;+ /** Inline feedback for an unparseable date token value, or null. */+ dateInvalidHint: string | null;+ /** Formatted label of the applied date range, or null. */+ dateSummary: string | null;hasScopeRows: boolean;isOverlayOpen: boolean;onContentKeyDown: (event: KeyboardEvent<HTMLDivElement>) => void;@@ -94,23 +129,35 @@ export const useCommandPaletteController = ({const isCommandsScope = !stage && !scopeProvider && query.startsWith('>');const localQuery = isCommandsScope ? query.slice(1) : query;const trimmedQuery = localQuery.trim();- // In commands scope date tokens are literal text; everywhere else the raw- // query stays the source of truth and the parse is derived alongside it.- const dateParse = useMemo(- () => (isCommandsScope ? null : parseDateTokens(localQuery)),- [isCommandsScope, localQuery]+ // Date tokens only mean anything when a provider can apply the range.+ // Everywhere else — commands scope, date-less scoped searches, hosts with+ // no capable providers (Launchpad) — they stay literal text, with no+ // affordances, so a filter is never silently dropped or falsely acknowledged.+ const datesEnabled =+ !stage &&+ !isCommandsScope &&+ (scopeProvider+ ? Boolean(scopeProvider.supportsCreatedAtRange)+ : providers.some((provider) => provider.supportsCreatedAtRange));+ // The raw query stays the source of truth; the parse is derived alongside it.+ const dateParse = useMemo(() => (datesEnabled ? parseDateTokens(localQuery) : null), [datesEnabled, localQuery]);+ const debouncedParse = useMemo(+ () => (datesEnabled ? parseDateTokens(debouncedQuery) : null),+ [datesEnabled, debouncedQuery]+ );+ const providerQuery = useMemo(+ () => ({ range: debouncedParse?.range, text: debouncedParse === null ? debouncedQuery : debouncedParse.text }),+ [debouncedParse, debouncedQuery]);- const debouncedParse = useMemo(() => parseDateTokens(debouncedQuery), [debouncedQuery]);- const providerQuery = useMemo(() => ({ range: debouncedParse.range, text: debouncedParse.text }), [debouncedParse]);// A valid date range is a complete query on its own — it bypasses the// minimum text length so `from:7d` alone searches.const shouldSearchProviders =- (debouncedParse.text.length >= PROVIDER_MIN_QUERY_LENGTH || debouncedParse.range !== undefined) &&+ (providerQuery.text.length >= PROVIDER_MIN_QUERY_LENGTH || providerQuery.range !== undefined) &&!stage &&!isCommandsScope;// Pure date query (range, no text): only range-capable providers run —// the rest would return broad, unfiltered results for empty text.- const isPureDateQuery = debouncedParse.range !== undefined && debouncedParse.text.length === 0;+ const isPureDateQuery = providerQuery.range !== undefined && providerQuery.text.length === 0;const activeProviders = useMemo(() => {if (stage || isCommandsScope) {return NO_PROVIDERS;@@ -162,6 +209,96 @@ export const useCommandPaletteController = ({}, [focusInput, resetOverlayState]);const onStageApplied = resetOverlayState;+ const previewRow = useCallback(+ (row: PaletteRow | undefined) => {+ if (!stage?.preview) {+ return;+ }++ if (row?.kind !== 'entry' || !row.entry.id.startsWith(STAGE_ENTRY_ID_PREFIX)) {+ stage.clearPreview?.();+ return;+ }++ stage.preview(row.entry.id.slice(STAGE_ENTRY_ID_PREFIX.length));+ },+ [stage]+ );++ // The single write path for the query: every mutation (typing, programmatic+ // completion) must go through here so the debounced provider query can never+ // go stale relative to the input. `immediate` skips the debounce for+ // discrete completions (suggestion rows) where results should refresh now.+ const replaceQuery = useCallback(+ (nextQuery: string, { immediate = false }: { immediate?: boolean } = {}) => {+ const nextLocalQuery = !stage && !scopeProvider && nextQuery.startsWith('>') ? nextQuery.slice(1) : nextQuery;+ const nextTrimmedQuery = nextLocalQuery.trim();++ setQuery(nextQuery);+ setActiveRowId(null);+ clearDebounce();++ if (stage) {+ const nextRows = searchPaletteRows(buildStageEntries(stage, onStageApplied), nextQuery, [], {+ showAllOnEmpty: true,+ });+ previewRow(nextRows.find((row) => row.kind !== 'label'));+ }++ if (immediate) {+ setDebouncedQuery(nextTrimmedQuery);+ return;+ }++ debounceTimerRef.current = window.setTimeout(() => {+ debounceTimerRef.current = null;+ setDebouncedQuery(nextTrimmedQuery);+ }, PROVIDER_DEBOUNCE_MS);+ },+ [clearDebounce, onStageApplied, previewRow, scopeProvider, stage]+ );++ // Completion rows for an in-progress trailing token (`from:` → Today /+ // Yesterday / …), rendered above all other sections. Selecting one rewrites+ // the token in place and refreshes provider results immediately.+ const dateSuggestionRows = useMemo<PaletteRow[]>(() => {+ if (!datesEnabled) {+ return [];+ }++ const trailing = matchTrailingDateToken(query);++ if (!trailing) {+ return [];+ }++ const partial = trailing.partialValue.toLowerCase();+ const options = DATE_TOKEN_SUGGESTIONS[trailing.key].filter((option) => option.value.startsWith(partial));+ const rows: PaletteRow[] = [{ id: 'label:date-suggestions', kind: 'label', label: 'Date' }];++ for (const option of options) {+ const id = `date-suggestion:${trailing.key}:${option.value}`;++ rows.push({+ entry: {+ group: 'Date',+ id,+ isPersistentRecent: false,+ keepOpen: true,+ run: () => replaceQuery(completeTrailingDateToken(query, option.value), { immediate: true }),+ subtitle: `${trailing.key}:${option.value}`,+ title: option.label,+ },+ id,+ kind: 'entry',+ });+ }++ rows.push({ id: 'label:date-format-hint', kind: 'label', label: DATE_FORMAT_HINT });++ return rows;+ }, [datesEnabled, query, replaceQuery]);+const rows = useMemo<PaletteRow[]>(() => {if (stage) {return searchPaletteRows(buildStageEntries(stage, onStageApplied), query, [], { showAllOnEmpty: true });@@ -190,6 +327,7 @@ export const useCommandPaletteController = ({const scopeProviders = isLivePureDate ? providers.filter((provider) => provider.supportsCreatedAtRange) : providers;return [+ ...dateSuggestionRows,...localRows,...(matchText.trim().length >= PROVIDER_MIN_QUERY_LENGTH || hasLiveRange? buildProviderSectionRows(providerSections)@@ -198,6 +336,7 @@ export const useCommandPaletteController = ({];}, [dateParse,+ dateSuggestionRows,entries,isCommandsScope,localQuery,@@ -218,22 +357,6 @@ export const useCommandPaletteController = ({const effectiveActiveRowId = effectiveActive?.row.id ?? null;const activeRow = effectiveActive?.row;- const previewRow = useCallback(- (row: PaletteRow | undefined) => {- if (!stage?.preview) {- return;- }-- if (row?.kind !== 'entry' || !row.entry.id.startsWith(STAGE_ENTRY_ID_PREFIX)) {- stage.clearPreview?.();- return;- }-- stage.preview(row.entry.id.slice(STAGE_ENTRY_ID_PREFIX.length));- },- [stage]- );-const enterScope = useCallback((providerKey: string) => {clearDebounce();@@ -384,39 +507,6 @@ export const useCommandPaletteController = ({[activeRow, enterScope, moveActive, popOverlay, query.length, runRow, runSecondary, scopeProviderKey, stage]);- // The single write path for the query: every mutation (typing, programmatic- // completion) must go through here so the debounced provider query can never- // go stale relative to the input. `immediate` skips the debounce for- // discrete completions (suggestion rows) where results should refresh now.- const replaceQuery = useCallback(- (nextQuery: string, { immediate = false }: { immediate?: boolean } = {}) => {- const nextLocalQuery = !stage && !scopeProvider && nextQuery.startsWith('>') ? nextQuery.slice(1) : nextQuery;- const nextTrimmedQuery = nextLocalQuery.trim();-- setQuery(nextQuery);- setActiveRowId(null);- clearDebounce();-- if (stage) {- const nextRows = searchPaletteRows(buildStageEntries(stage, onStageApplied), nextQuery, [], {- showAllOnEmpty: true,- });- previewRow(nextRows.find((row) => row.kind !== 'label'));- }-- if (immediate) {- setDebouncedQuery(nextTrimmedQuery);- return;- }-- debounceTimerRef.current = window.setTimeout(() => {- debounceTimerRef.current = null;- setDebouncedQuery(nextTrimmedQuery);- }, PROVIDER_DEBOUNCE_MS);- },- [clearDebounce, onStageApplied, previewRow, scopeProvider, stage]- );-const onSearchChange = useCallback((event: ChangeEvent<HTMLInputElement>) => replaceQuery(event.currentTarget.value),[replaceQuery]@@ -436,7 +526,33 @@ export const useCommandPaletteController = ({focusInput();}, [focusInput, scopedQueryResult]);+ // Quiet acknowledgment of the applied range, and inline feedback for values+ // that cannot parse. A trailing token that could still become valid+ // (`from:`, `from:2026-`) is normal typing, not an error. Feedback beats+ // acknowledgment when both apply.+ const dateInvalidHint = useMemo(() => {+ if (dateParse === null) {+ return null;+ }++ const trailing = matchTrailingDateToken(localQuery);+ const invalid = dateParse.invalidTokens.find(+ (token) =>+ !(+ trailing &&+ token.key === trailing.key &&+ token.raw === trailing.partialValue &&+ isPossibleDatePrefix(token.raw)+ )+ );++ return invalid ? `Invalid date: “${invalid.raw}”` : null;+ }, [dateParse, localQuery]);+ const dateSummary = dateParse?.range && dateInvalidHint === null ? formatDateRangeLabel(dateParse.range) : null;+return {+ dateInvalidHint,+ dateSummary,activeRow,activeRowId: effectiveActiveRowId,chipLabel: stage ? stage.title : (scopeProvider?.label ?? null),