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(webv2): default and remember the prompt tool models
Josh Corbettdd48b768119f
diff --git a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.tsindex c8a47b16b6..af0b37053a 100644--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts@@ -517,6 +517,8 @@ export const getDefaultGenerateSettings = (model?: GenerateModelConfig): GeneratnegativePromptHeightPx: 56,positivePrompt: '',positivePromptHeightPx: 96,+ expandPromptModelKey: null,+ imageToPromptModelKey: null,promptTemplate: null,promptTemplateViewMode: false,qwen3EncoderModel: null,diff --git a/invokeai/frontend/webv2/src/features/generation/core/settings.test.ts b/invokeai/frontend/webv2/src/features/generation/core/settings.test.tsindex 708d483563..bd621bc83a 100644--- a/invokeai/frontend/webv2/src/features/generation/core/settings.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/settings.test.ts@@ -66,6 +66,16 @@ describe('normalizeGenerateSettings', () => {).toBe('random');});+ it('reads prompt tool model picks, defaulting projects saved before them to none', () => {+ expect(normalizeGenerateSettings(legacyStoredValues)).toMatchObject({+ expandPromptModelKey: null,+ imageToPromptModelKey: null,+ });+ expect(+ normalizeGenerateSettings({ ...legacyStoredValues, expandPromptModelKey: 'llm', imageToPromptModelKey: 7 })+ ).toMatchObject({ expandPromptModelKey: 'llm', imageToPromptModelKey: null });+ });+it('rejects values that name neither a seed mode nor the random toggle', () => {const { shouldRandomizeSeed: _, ...withoutSeedPolicy } = legacyStoredValues;diff --git a/invokeai/frontend/webv2/src/features/generation/core/settings.ts b/invokeai/frontend/webv2/src/features/generation/core/settings.tsindex e2ac67b108..2399ad20e4 100644--- a/invokeai/frontend/webv2/src/features/generation/core/settings.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/settings.ts@@ -624,10 +624,18 @@ export const isWanLoraTargetingMain = (};/** Require core fields but default newer fields to preserve older project content. */+/** Tool model picks: widget preferences that presets and whole-form replacements leave alone. */+export const GENERATE_TOOL_MODEL_PICK_KEYS = [+ 'expandPromptModelKey',+ 'imageToPromptModelKey',+] as const satisfies readonly (keyof GenerateSettings)[];+/** Exclude arrangement keys from generation-intent routing, including template view but not template application. */export const GENERATE_UI_STATE_KEYS = {aspectRatioIsLocked: true,batchCount: true,+ expandPromptModelKey: true,+ imageToPromptModelKey: true,negativePromptHeightPx: true,positivePromptHeightPx: true,promptTemplateViewMode: true,@@ -719,6 +727,8 @@ export const normalizeGenerateSettings = (values: unknown): GenerateSettings | nMAX_POSITIVE_PROMPT_HEIGHT_PX,DEFAULT_POSITIVE_PROMPT_HEIGHT_PX),+ expandPromptModelKey: typeof values.expandPromptModelKey === 'string' ? values.expandPromptModelKey : null,+ imageToPromptModelKey: typeof values.imageToPromptModelKey === 'string' ? values.imageToPromptModelKey : null,// Preserve canonical object identity to avoid false Object.is changes and reconciliation loops.promptTemplate,promptTemplateViewMode: promptTemplate !== null && values.promptTemplateViewMode === true,diff --git a/invokeai/frontend/webv2/src/features/generation/core/types.ts b/invokeai/frontend/webv2/src/features/generation/core/types.tsindex e2f25ff569..8631409294 100644--- a/invokeai/frontend/webv2/src/features/generation/core/types.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/types.ts@@ -174,6 +174,10 @@ export interface GenerateSettings {modelKey: string;positivePrompt: string;positivePromptHeightPx: number;+ /** The text LLM last picked for Expand Prompt; unset or uninstalled falls back to the first installed one. */+ expandPromptModelKey: string | null;+ /** The vision model last picked for Image to Prompt, with the same fallback. */+ imageToPromptModelKey: string | null;negativePromptEnabled: boolean;negativePrompt: string;negativePromptHeightPx: number;diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GeneratePresetsPopover.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GeneratePresetsPopover.tsxindex a316066f16..d489c98152 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GeneratePresetsPopover.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GeneratePresetsPopover.tsx@@ -6,7 +6,7 @@ import {getGenerateModelSelectionResult,isSupportedGenerateModel,} from '@features/generation/core/baseGenerationPolicies';-import { normalizeGenerateSettings } from '@features/generation/core/settings';+import { GENERATE_TOOL_MODEL_PICK_KEYS, normalizeGenerateSettings } from '@features/generation/core/settings';import { resolveGenerateWidgetValues } from '@features/generation/settings';import {Button,@@ -45,6 +45,11 @@ const getPresetComparisonKey = (settings: GenerateSettings): string => {const comparable: Record<string, unknown> = { ...settings };delete comparable.batchCount;++ for (const key of GENERATE_TOOL_MODEL_PICK_KEYS) {+ delete comparable[key];+ }+delete comparable.negativePromptHeightPx;delete comparable.positivePromptHeightPx;delete comparable.promptTemplateViewMode;diff --git a/invokeai/frontend/webv2/src/features/generation/ui/generateFormViewModel.test.ts b/invokeai/frontend/webv2/src/features/generation/ui/generateFormViewModel.test.tsindex 935126e16a..fa8115fe81 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/generateFormViewModel.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/ui/generateFormViewModel.test.ts@@ -111,4 +111,13 @@ describe('getGenerateFormCommitPatch', () => {expect(patch.batchCount).toBeUndefined();expect(patch.positivePrompt).toBe('keep prompt');});++ it('leaves the saved prompt tool models alone, so applying a preset keeps them', () => {+ const patch = getGenerateFormCommitPatch(+ createSettings({ expandPromptModelKey: 'preset-llm', imageToPromptModelKey: 'preset-vision' })+ );++ expect(patch).not.toHaveProperty('expandPromptModelKey');+ expect(patch).not.toHaveProperty('imageToPromptModelKey');+ });});diff --git a/invokeai/frontend/webv2/src/features/generation/ui/generateFormViewModel.ts b/invokeai/frontend/webv2/src/features/generation/ui/generateFormViewModel.tsindex f81888b594..594220f5f9 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/generateFormViewModel.ts+++ b/invokeai/frontend/webv2/src/features/generation/ui/generateFormViewModel.ts@@ -1,5 +1,6 @@import type { GenerateSettings, GenerateWidgetValues } from '@features/generation/core/types';+import { GENERATE_TOOL_MODEL_PICK_KEYS } from '@features/generation/core/settings';import { createStableSelector } from '@platform/state/selectors';const PROMPT_FORM_KEYS = [@@ -70,5 +71,9 @@ export const getGenerateFormCommitPatch = (delete patch.batchCount;+ for (const key of GENERATE_TOOL_MODEL_PICK_KEYS) {+ delete patch[key];+ }+return patch;};diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/ExpandPromptSuggestion.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/ExpandPromptSuggestion.browser.test.tsxindex 11d46077a0..a368b722af 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/ExpandPromptSuggestion.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/ExpandPromptSuggestion.browser.test.tsx@@ -1,10 +1,11 @@/* oxlint-disable react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop */import type { ExpandPromptSuggestion } from '@features/generation/core/types';+import type { SavedPromptModels } from '@features/generation/ui/promptFields/PositivePromptActions';import type { ChangeEvent } from 'react';import { ChakraProvider } from '@chakra-ui/react';import { DndContext } from '@dnd-kit/core';-import { expandPrompt } from '@features/generation/data/promptUtilities';+import { expandPrompt, imageToPrompt } from '@features/generation/data/promptUtilities';import { PositivePromptField } from '@features/generation/ui/promptFields/PositivePromptField';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { system } from '@theme/system';@@ -42,6 +43,9 @@ const prompt = (id: string, content: string) => ({name: id,userId: 'system',});+const VISION_A = { base: 'any', key: 'llava-a', name: 'LLaVA A', type: 'llava_onevision' };+const VISION_B = { base: 'any', key: 'llava-b', name: 'LLaVA B', type: 'llava_onevision' };+const PROMPTS = [prompt('default', 'DEFAULT'), prompt('t2v', 'T2V'), prompt('i2v', 'I2V')];const FRAME = { height: 512, image_name: 'frame.png', width: 768 };@@ -54,7 +58,7 @@ const LTX_SUGGESTION: ExpandPromptSuggestion = {};// Read at render time by the mocks below, so each test can set them before rendering.-let catalog: (typeof TEXT_ONLY | typeof ENHANCER)[] = [];+let catalog: (typeof TEXT_ONLY | typeof ENHANCER | typeof VISION_A)[] = [];let arePromptsLoading = false;const StubSelect = ({@@ -101,7 +105,7 @@ vi.mock('@features/generation/ui/GenerationUiContext', async (importOriginal) =>useGenerationUi: () => ({account: { isAdmin: false, userId: 'system' },capabilities: { canManagePromptTemplates: false, canManageSharedSystemPrompts: false },- gallery: { selectedImage: null },+ gallery: { selectedImage: { imageName: 'selected.png' } },models: { catalog, ensureLoaded: vi.fn(), openManager: vi.fn() },notifications: { reportError: vi.fn() },project: { activeProjectId: 'project-1' },@@ -137,6 +141,7 @@ vi.mock('@features/generation/ui/promptFields/useSystemPrompts', () => ({vi.mock('@features/generation/data/promptUtilities', async (importOriginal) => ({...(await importOriginal<object>()),expandPrompt: vi.fn(() => Promise.resolve({ expanded_prompt: 'rewritten', seed: 1 })),+ imageToPrompt: vi.fn(() => Promise.resolve({ prompt: 'described' })),}));vi.mock('@features/generation/data/wildcards', () => ({@@ -153,6 +158,7 @@ let root: Root | null = null;beforeEach(() => {vi.mocked(expandPrompt).mockClear();+ vi.mocked(imageToPrompt).mockClear();catalog = [TEXT_ONLY, ENHANCER];arePromptsLoading = false;});@@ -164,7 +170,7 @@ afterEach(async () => {root = null;});-const renderField = (suggestion: ExpandPromptSuggestion | null) =>+const renderField = (suggestion: ExpandPromptSuggestion | null, savedPromptModels?: SavedPromptModels) =>root?.render(<I18nextProvider i18n={i18n}><QueryClientProvider client={new QueryClient()}>@@ -175,6 +181,7 @@ const renderField = (suggestion: ExpandPromptSuggestion | null) =>heightPx={96}loras={[]}projectId="project-1"+ savedPromptModels={savedPromptModels}selectedModel={undefined}showSyntaxHighlighting={false}value="she waves"@@ -188,15 +195,26 @@ const renderField = (suggestion: ExpandPromptSuggestion | null) =></I18nextProvider>);-const renderAndOpen = async (suggestion: ExpandPromptSuggestion | null) => {+const renderAndOpen = async (+ suggestion: ExpandPromptSuggestion | null,+ savedPromptModels?: SavedPromptModels,+ trigger = 'widgets.generate.expandPrompt'+) => {host = document.createElement('div');document.body.append(host);root = createRoot(host);- await act(() => renderField(suggestion));- await act(() => host?.querySelector<HTMLButtonElement>('[aria-label="widgets.generate.expandPrompt"]')?.click());+ await act(() => renderField(suggestion, savedPromptModels));+ await act(() => host?.querySelector<HTMLButtonElement>(`[aria-label="${trigger}"]`)?.click());};+const savedModels = (overrides: Partial<SavedPromptModels> = {}): SavedPromptModels => ({+ expandPromptModelKey: null,+ imageToPromptModelKey: null,+ onChange: vi.fn(),+ ...overrides,+});+const select = (label: string) => document.querySelector<HTMLSelectElement>(`select[aria-label="${label}"]`);const choose = (label: string, value: string) =>act(() => {@@ -263,15 +281,14 @@ it("keeps the user's own system prompt over the suggestion", async () => {expect(await runExpand()).toMatchObject({ image_name: 'frame.png', system_prompt: 'DEFAULT' });});-it('points to the starter models when the suggested enhancer is not installed', async () => {+it('points to the starter models and falls back to an installed model when the enhancer is missing', async () => {catalog = [TEXT_ONLY];await renderAndOpen(LTX_SUGGESTION);- expect(select('text llm')?.value).toBe('');+ expect(select('text llm')?.value).toBe('qwen');expect(document.body.textContent).toContain('LTX-2.5 Prompt Enhancer (Gemma-4 E2B) is not installed');- // No model is chosen, so there is nothing to say about reading images yet.- expect(document.body.textContent).not.toContain('widgets.generate.expandFirstFrameUnreadable');- expect(expandButton()?.disabled).toBe(true);+ expect(document.body.textContent).toContain('widgets.generate.expandFirstFrameUnreadable');+ expect(await runExpand()).toMatchObject({ model_key: 'qwen', system_prompt: 'T2V' });});it('waits for the system prompts before expanding', async () => {@@ -281,10 +298,51 @@ it('waits for the system prompts before expanding', async () => {expect(expandButton()?.disabled).toBe(true);});-it('preselects nothing without a suggestion', async () => {+it('starts from the first listed model without a suggestion', async () => {await renderAndOpen(null);- expect(select('text llm')?.value).toBe('');+ // Listed by name: "Gemma-4 E2B" before "Qwen".+ expect(select('text llm')?.value).toBe('e2b');expect(document.body.textContent).not.toContain('is not installed');- expect(expandButton()?.disabled).toBe(true);+ expect(await runExpand()).toMatchObject({ model_key: 'e2b' });+});++it("uses the surface's saved pick over the suggestion and saves a different one", async () => {+ const saved = savedModels({ expandPromptModelKey: 'qwen' });+ await renderAndOpen(LTX_SUGGESTION, saved);++ expect(select('text llm')?.value).toBe('qwen');+ await choose('text llm', 'e2b');+ expect(saved.onChange).toHaveBeenCalledExactlyOnceWith({ expandPromptModelKey: 'e2b' });++ // Once saved, picking the same model again saves nothing.+ await act(() => renderField(LTX_SUGGESTION, { ...saved, expandPromptModelKey: 'e2b' }));+ await choose('text llm', 'e2b');+ expect(saved.onChange).toHaveBeenCalledOnce();+});++it('falls back when the saved pick is no longer installed', async () => {+ await renderAndOpen(null, savedModels({ expandPromptModelKey: 'uninstalled' }));++ expect(select('text llm')?.value).toBe('e2b');+});++it('starts Image to Prompt from the first listed vision model and saves a different pick', async () => {+ catalog = [VISION_B, VISION_A];+ const saved = savedModels();+ await renderAndOpen(null, saved, 'widgets.generate.imageToPrompt');++ expect(select('text llm')?.value).toBe('llava-a');+ const generateButton = () =>+ [...document.querySelectorAll<HTMLButtonElement>('button')].find(+ (button) => button.textContent === 'widgets.generate.generatePrompt'+ );+ await act(() => generateButton()?.click());+ expect(imageToPrompt).toHaveBeenCalledWith(+ expect.objectContaining({ image_name: 'selected.png', model_key: 'llava-a' })+ );++ await act(() => host?.querySelector<HTMLButtonElement>('[aria-label="widgets.generate.imageToPrompt"]')?.click());+ await choose('text llm', 'llava-b');+ expect(saved.onChange).toHaveBeenCalledExactlyOnceWith({ imageToPromptModelKey: 'llava-b' });});diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/GeneratePromptFields.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/GeneratePromptFields.tsxindex 0a1a7aab9f..f8ed72b3ed 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/GeneratePromptFields.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/GeneratePromptFields.tsx@@ -162,6 +162,15 @@ export const GeneratePromptFields = ({const clearPromptTemplate = useCallback(() => applyPromptTemplate(null), [applyPromptTemplate]);+ const savedPromptModels = useMemo(+ () => ({+ expandPromptModelKey: settings.expandPromptModelKey,+ imageToPromptModelKey: settings.imageToPromptModelKey,+ onChange: onCommitImmediate,+ }),+ [onCommitImmediate, settings.expandPromptModelKey, settings.imageToPromptModelKey]+ );+return (<Stack gap="1" py="2"><PositivePromptField@@ -172,6 +181,7 @@ export const GeneratePromptFields = ({loras={settings.loras}projectId={projectId}promptTemplate={settings.promptTemplate}+ savedPromptModels={savedPromptModels}selectedModel={selectedModel}showSyntaxHighlighting={showPromptSyntaxHighlighting}isTemplateViewMode={settings.promptTemplateViewMode}diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsxindex 526561c615..a95d5eb55b 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx@@ -4,6 +4,7 @@ import type {ExpandPromptSuggestion,GenerateLora,GenerateModelConfig,+ GenerateSettings,ImageWithDims,} from '@features/generation/core/types';import type { DynamicPromptsFieldConfig } from '@features/generation/ui/promptFields/DynamicPromptsPanel';@@ -67,6 +68,58 @@ const OpenModelManagerButton = ({ modelType }: { modelType?: string }) => {);};+type SavedPromptModelKeys = Pick<GenerateSettings, 'expandPromptModelKey' | 'imageToPromptModelKey'>;++/** A surface that keeps the Expand and Image to Prompt model picks; without one they last for the session. */+export interface SavedPromptModels extends SavedPromptModelKeys {+ onChange: (patch: Partial<SavedPromptModelKeys>) => void;+}++/** The picker lists these single-base model types by name, so the first listed is the first by name. */+const getFirstModelByName = (models: readonly ModelConfig[]): ModelConfig | null =>+ models.reduce<ModelConfig | null>(+ (first, model) =>+ first === null || model.name.localeCompare(first.name, undefined, { sensitivity: 'base' }) < 0 ? model : first,+ null+ );++/**+ * The picked model when it is still installed, else the suggested one, else the first listed. A pick is saved+ * to the surface when it keeps one, and only when it differs from what is saved.+ */+const usePromptModelPick = ({+ candidates,+ onSave,+ savedKey,+ suggestedKey = null,+}: {+ candidates: readonly ModelConfig[];+ onSave?: (key: string) => void;+ savedKey?: string | null;+ suggestedKey?: string | null;+}) => {+ const [sessionKey, setSessionKey] = useState<string | null>(null);+ const pickedKey = onSave ? (savedKey ?? null) : sessionKey;+ const findModel = (key: string | null) => (key ? (candidates.find((model) => model.key === key) ?? null) : null);+ const model = findModel(pickedKey) ?? findModel(suggestedKey) ?? getFirstModelByName(candidates);+ const pick = useCallback(+ (next: ModelConfig | null) => {+ if (!next) {+ return;+ }++ if (!onSave) {+ setSessionKey(next.key);+ } else if (next.key !== savedKey) {+ onSave(next.key);+ }+ },+ [onSave, savedKey]+ );++ return { model, pick };+};+export interface PromptTemplateState {/** The applied template, or null when none is. */active: PromptTemplateSnapshot | null;@@ -98,6 +151,7 @@ interface PositivePromptActionsProps {projectId: string;onOpenPromptTriggerPicker: (anchorElement: HTMLElement) => void;onPositivePromptChangeImmediate: (prompt: string) => void;+ savedPromptModels?: SavedPromptModels;template: PromptTemplateState;onInsertText: (text: string) => void;showSyntaxHighlighting: boolean;@@ -116,6 +170,7 @@ export const PositivePromptActions = ({onUsePrompt,positivePrompt,projectId,+ savedPromptModels,showSyntaxHighlighting,template,}: PositivePromptActionsProps) => {@@ -142,6 +197,7 @@ export const PositivePromptActions = ({isDisabled={template.isViewMode}positivePrompt={positivePrompt}projectId={projectId}+ savedPromptModels={savedPromptModels}suggestion={expandPromptSuggestion ?? null}onPositivePromptChange={onPositivePromptChangeImmediate}/>@@ -149,6 +205,7 @@ export const PositivePromptActions = ({droppedImage={droppedImage}isDisabled={template.isViewMode}projectId={projectId}+ savedPromptModels={savedPromptModels}onPositivePromptChange={onPositivePromptChangeImmediate}/><PositivePromptHistoryButton onUsePrompt={onUsePrompt} />@@ -376,11 +433,13 @@ const ExpandPromptButton = ({onPositivePromptChange,positivePrompt,projectId,+ savedPromptModels,suggestion,}: {isDisabled: boolean;positivePrompt: string;projectId: string;+ savedPromptModels: SavedPromptModels | undefined;suggestion: ExpandPromptSuggestion | null;onPositivePromptChange: (prompt: string) => void;}) => {@@ -395,7 +454,6 @@ const ExpandPromptButton = ({const [isOpen, setIsOpen] = useState(false);const [isLoading, setIsLoading] = useState(false);const [taskId, setTaskId] = useState<string | null>(null);- const [selectedModelKey, setSelectedModelKey] = useState<string | null>(null);const [selectedSystemPromptId, setSelectedSystemPromptId] = useState<string | null>(null);// Keyed by image so unticking one frame does not carry over to the next one.const [excludedImageName, setExcludedImageName] = useState<string | null>(null);@@ -403,9 +461,17 @@ const ExpandPromptButton = ({const suggestedModelKey = suggestion?.modelSource? (textLlmModels.find((model) => model.source === suggestion.modelSource)?.key ?? null): null;- // An explicit choice wins; otherwise the widget's suggested enhancer, when it is installed.- const effectiveModelKey = selectedModelKey ?? suggestedModelKey;- const selectedModel = effectiveModelKey ? textLlmModels.find((model) => model.key === effectiveModelKey) : null;+ const onSaveModelKey = savedPromptModels?.onChange;+ const saveModelKey = useMemo(+ () => (onSaveModelKey ? (key: string) => onSaveModelKey({ expandPromptModelKey: key }) : undefined),+ [onSaveModelKey]+ );+ const { model: selectedModel, pick: handleModelChange } = usePromptModelPick({+ candidates: textLlmModels,+ onSave: saveModelKey,+ savedKey: savedPromptModels?.expandPromptModelKey,+ suggestedKey: suggestedModelKey,+ });const suggestedImage = suggestion?.image ?? null;const canReadImages = selectedModel?.supports_images === true;const isImageIncluded = suggestedImage !== null && excludedImageName !== suggestedImage.image_name;@@ -483,7 +549,6 @@ const ExpandPromptButton = ({[suggestedImageName]);const handleOpenChange = useCallback((event: { open: boolean }) => setIsOpen(event.open), []);- const handleModelChange = useCallback((model: ModelConfig | null) => setSelectedModelKey(model?.key ?? null), []);const handleRunExpandPrompt = useCallback(() => void runExpandPrompt(), [runExpandPrompt]);return (@@ -529,7 +594,7 @@ const ExpandPromptButton = ({modelTypes={TEXT_LLM_MODEL_TYPES}placeholder={t('widgets.generate.selectTextLlm')}size="xs"- value={effectiveModelKey}+ value={selectedModel?.key ?? null}onChange={handleModelChange}/>{suggestion?.modelSource && !suggestedModelKey ? (@@ -626,10 +691,12 @@ const ImageToPromptButton = ({isDisabled,onPositivePromptChange,projectId,+ savedPromptModels,}: {droppedImage: DroppedPromptImage;isDisabled: boolean;projectId: string;+ savedPromptModels: SavedPromptModels | undefined;onPositivePromptChange: (prompt: string) => void;}) => {const { t } = useTranslation();@@ -644,9 +711,17 @@ const ImageToPromptButton = ({const [isOpen, setIsOpen] = useState(false);const [isLoading, setIsLoading] = useState(false);const [taskId, setTaskId] = useState<string | null>(null);- const [selectedModelKey, setSelectedModelKey] = useState<string | null>(null);const llavaModels = models.filter((model) => model.type === 'llava_onevision');- const selectedModel = selectedModelKey ? llavaModels.find((model) => model.key === selectedModelKey) : null;+ const onSaveModelKey = savedPromptModels?.onChange;+ const saveModelKey = useMemo(+ () => (onSaveModelKey ? (key: string) => onSaveModelKey({ imageToPromptModelKey: key }) : undefined),+ [onSaveModelKey]+ );+ const { model: selectedModel, pick: handleModelChange } = usePromptModelPick({+ candidates: llavaModels,+ onSave: saveModelKey,+ savedKey: savedPromptModels?.imageToPromptModelKey,+ });// Dropped images take precedence over gallery selection.const image = droppedImage.image ?? selectedImage;const droppedImageName = droppedImage.image?.imageName ?? null;@@ -710,7 +785,6 @@ const ImageToPromptButton = ({const popoverIds = useMemo(() => ({ trigger: triggerId }), [triggerId]);const handleOpenChange = useCallback((event: { open: boolean }) => (event.open ? setIsOpen(true) : close()), [close]);- const handleModelChange = useCallback((model: ModelConfig | null) => setSelectedModelKey(model?.key ?? null), []);const handleRunImageToPrompt = useCallback(() => void runImageToPrompt(), [runImageToPrompt]);return (@@ -755,7 +829,7 @@ const ImageToPromptButton = ({modelTypes={LLAVA_MODEL_TYPES}placeholder={t('widgets.generate.selectVisionModel')}size="xs"- value={selectedModelKey}+ value={selectedModel?.key ?? null}onChange={handleModelChange}/>{image ? (diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsxindex 33134304a8..0df659fb59 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsx@@ -14,7 +14,12 @@ import { useTranslation } from 'react-i18next';import type { DynamicPromptsFieldConfig } from './DynamicPromptsPanel';-import { PositivePromptActions, PromptTriggerPopover, type PromptTemplateState } from './PositivePromptActions';+import {+ PositivePromptActions,+ PromptTriggerPopover,+ type PromptTemplateState,+ type SavedPromptModels,+} from './PositivePromptActions';import { PROMPT_ATTENTION_TARGET_PROPS } from './promptAttentionHotkeys';import { insertPromptText, registerPositivePromptElement } from './promptFocus';import { promptHistoryNavigation } from './promptHistoryNavigation';@@ -49,6 +54,8 @@ interface PositivePromptFieldProps {onApplyPromptTemplate?: (template: PromptTemplateSnapshot | null) => void;onResizeEnd: (heightPx: number) => void;onUsePrompt: (prompt: PromptHistoryItem) => void;+ /** Where Expand and Image to Prompt save their model picks; absent keeps them for the session. */+ savedPromptModels?: SavedPromptModels;}/** The positive prompt is the only field whose `__name__` references resolve. */@@ -69,6 +76,7 @@ export const PositivePromptField = ({onUsePrompt,projectId,promptTemplate = null,+ savedPromptModels,selectedModel,showSyntaxHighlighting,value,@@ -205,6 +213,7 @@ export const PositivePromptField = ({effectivePositivePrompt={effectivePositivePrompt}template={templateState}projectId={projectId}+ savedPromptModels={savedPromptModels}selectedModel={selectedModel}onOpenPromptTriggerPicker={triggerPicker.open}onPositivePromptChangeImmediate={commitPromptChangeImmediately}@@ -223,6 +232,7 @@ export const PositivePromptField = ({insertTextAtCaret,loras,projectId,+ savedPromptModels,selectedModel,showSyntaxHighlighting,templateState,diff --git a/invokeai/frontend/webv2/src/workbench/canvas-operations/importGalleryImages.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-operations/importGalleryImages.test.tsindex f7562b68cd..6b44e6e8ba 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-operations/importGalleryImages.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-operations/importGalleryImages.test.ts@@ -100,6 +100,8 @@ const setModel = (project: Project, base: GenerateWidgetValues['model']['base'])negativePromptHeightPx: 56,positivePrompt: '',positivePromptHeightPx: 96,+ expandPromptModelKey: null,+ imageToPromptModelKey: null,promptTemplate: null,promptTemplateViewMode: false,mistralEncoderModel: null,diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.tsindex 2bf7de5c0a..fcd3c97ec2 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts@@ -102,6 +102,8 @@ const createValues = (overrides: Partial<GenerateWidgetValues> = {}): GenerateWinegativePromptHeightPx: 56,positivePrompt: '',positivePromptHeightPx: 96,+ expandPromptModelKey: null,+ imageToPromptModelKey: null,promptTemplate: null,promptTemplateViewMode: false,mistralEncoderModel: null,diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.tsindex 084e5b16aa..7c0c6bcc54 100644--- a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts@@ -17,6 +17,8 @@ const makeValues = (overrides: Partial<GenerateWidgetValues> = {}): GenerateWidgaspectRatioIsLocked: true,aspectRatioValue: 1,clipSkip: 0,+ expandPromptModelKey: null,+ imageToPromptModelKey: null,height: 1024,negativePrompt: '',negativePromptEnabled: false,@@ -63,13 +65,30 @@ describe('buildQueueRecallValues', () => {it('recalls all as the exact snapshot and remix with a randomized seed', () => {const snapshot = makeValues({ positivePrompt: 'snap', seedMode: 'fixed' });- expect(buildQueueRecallValues('all', { current, meta: {}, snapshot })).toBe(snapshot);+ expect(buildQueueRecallValues('all', { current, meta: {}, snapshot })).toEqual(snapshot);expect(buildQueueRecallValues('remix', { current, meta: {}, snapshot })).toEqual({...snapshot,seedMode: 'random',});});+ it('keeps the current prompt tool model picks when restoring a snapshot', () => {+ const picked = makeValues({ expandPromptModelKey: 'llm-b', imageToPromptModelKey: 'vision-b' });+ const snapshot = makeValues({+ expandPromptModelKey: null,+ imageToPromptModelKey: 'vision-a',+ positivePrompt: 'snap',+ });++ for (const kind of ['all', 'remix'] as const) {+ expect(buildQueueRecallValues(kind, { current: picked, meta: {}, snapshot })).toMatchObject({+ expandPromptModelKey: 'llm-b',+ imageToPromptModelKey: 'vision-b',+ positivePrompt: 'snap',+ });+ }+ });+it('merges prompts into the current values, preferring the snapshot', () => {const snapshot = makeValues({ negativePrompt: 'snap neg', negativePromptEnabled: true, positivePrompt: 'snap' });const result = buildQueueRecallValues('prompts', { current, meta: { positivePrompt: 'meta' }, snapshot });diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.tsindex 3f445c45f4..553c32b39e 100644--- a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts@@ -36,6 +36,19 @@ export const getVideoQueueRecallCapabilities = (workflow: false,});+/** The prompt tool model picks are the widget's preference, not part of what was submitted. */+const withCurrentToolModelPicks = (+ values: GenerateWidgetValues,+ current: GenerateWidgetValues | null+): GenerateWidgetValues =>+ current+ ? {+ ...values,+ expandPromptModelKey: current.expandPromptModelKey ?? null,+ imageToPromptModelKey: current.imageToPromptModelKey ?? null,+ }+ : values;+export const buildQueueRecallValues = (kind: ImageRecallKind,{@@ -49,11 +62,11 @@ export const buildQueueRecallValues = (}): GenerateWidgetValues | null => {if (kind === 'all') {- return snapshot;+ return snapshot ? withCurrentToolModelPicks(snapshot, current) : null;}if (kind === 'remix') {- return snapshot ? { ...snapshot, seedMode: 'random' } : null;+ return snapshot ? withCurrentToolModelPicks({ ...snapshot, seedMode: 'random' }, current) : null;}if (!current) {diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.tsindex 7f262b3efd..d42484a1b4 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts@@ -229,6 +229,8 @@ const createGenerateValues = (overrides: Partial<GenerateWidgetValues> = {}): GenegativePromptHeightPx: 56,positivePrompt: 'first prompt',positivePromptHeightPx: 96,+ expandPromptModelKey: null,+ imageToPromptModelKey: null,promptTemplate: null,promptTemplateViewMode: false,mistralEncoderModel: null,