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): bring the recalled panel to the front for image and video recall
Lincoln Steina0a0b6a33224
diff --git a/docs/src/content/docs/development/Guides/recall-api.mdx b/docs/src/content/docs/development/Guides/recall-api.mdxindex 7bbfed8673..eaa0765e00 100644--- a/docs/src/content/docs/development/Guides/recall-api.mdx+++ b/docs/src/content/docs/development/Guides/recall-api.mdx@@ -493,7 +493,11 @@ clients automatically:The update lands in the **Generate** panel of the project that was active whenthe event arrived, and shows a notification summarizing how many fields were-applied. Parameters the Generate panel has no home for, and entries that could+applied. If that project is still on screen, the Generate widget is brought to the+front the same way the [Video Recall API](/development/guides/video-recall-api/#frontend-behavior)+brings the Video widget forward: its tab is selected, a floating window is raised+(and unrolled if shaded),+and nothing moves while the user is typing. Parameters the Generate panel has no home for, and entries that couldnot be resolved, are left out and named in a second notification so the callercan tell what did not land. The editor must be open: events that arrive whilethe user is on the Launchpad are dropped even though the request returns 200.diff --git a/docs/src/content/docs/development/Guides/video-recall-api.mdx b/docs/src/content/docs/development/Guides/video-recall-api.mdxindex fcf803d262..328629c41d 100644--- a/docs/src/content/docs/development/Guides/video-recall-api.mdx+++ b/docs/src/content/docs/development/Guides/video-recall-api.mdx@@ -102,9 +102,12 @@ webv2 applies each event, in arrival order, to the Video panel of the project thwas active when the event arrived. Video recall events are ordered among themselves;image recall events (`POST /api/v1/recall`) are ordered separately. A notificationreports each change applied or declined. An event whose project was closed before it-could be applied is dropped. When something was applied and the project is on screen-without a Video widget anywhere in its layout, the widget is opened; a Video widget-that is already there, docked or floating, is left where it is.+could be applied is dropped. When something was applied and that project is still on+screen, the Video widget is brought to the front: its tab is selected (expanding its+region and opening its panel), a floating window is raised (and unrolled if shaded)+rather than docked, and+the widget is opened if the layout has none. Nothing moves while the user is typing+in a text field; the notification still reports the change.- **Recall / Remix** runs the same mapping as the gallery's *Recall All* and*Remix Video*: the model is resolved against the installed catalog (switchingdiff --git a/invokeai/frontend/webv2/src/app/RecallParametersRuntime.tsx b/invokeai/frontend/webv2/src/app/RecallParametersRuntime.tsxindex 5608f9fb24..3145bca018 100644--- a/invokeai/frontend/webv2/src/app/RecallParametersRuntime.tsx+++ b/invokeai/frontend/webv2/src/app/RecallParametersRuntime.tsx@@ -1,11 +1,11 @@import { getAuthSession } from '@features/identity';import { useMountEffect } from '@platform/react/useMountEffect';import { socketHub } from '@platform/transport/socketHub';+import { isEditableHotkeyTarget } from '@workbench/hotkeys/keys';import {attachRecallParametersRuntime,attachVideoRecallRuntime,} from '@workbench/image-actions/recallParametersBridge';-import { openWorkbenchWidget } from '@workbench/useOpenWorkbenchWidget';import { useWorkbenchInternalStore } from '@workbench/WorkbenchContext';import { useWorkbenchWidgetRegistry } from '@workbench/WorkbenchWidgetRegistryContext';import { useTranslation } from 'react-i18next';@@ -18,7 +18,7 @@ const getSessionUserId = (): string | null => {/*** App-owned composition: external `POST /api/v1/recall` updates land in the active project's Generate panel, and- * `POST /api/v1/recall/video` updates in its Video panel.+ * `POST /api/v1/recall/video` updates in its Video panel; each brings its panel to the front.*/export const RecallParametersRuntime = () => {const store = useWorkbenchInternalStore();@@ -27,21 +27,24 @@ export const RecallParametersRuntime = () => {const { t } = useTranslation();useMountEffect(() => {+ const reveal = {+ getWidgetsForRegion,+ isEditingText: () => isEditableHotkeyTarget(document.activeElement),+ };const recall = attachRecallParametersRuntime({commands: store.commands,getSessionUserId,hub: socketHub,queries: store.queries,+ reveal,t,});const videoRecall = attachVideoRecallRuntime({commands: store.commands,getSessionUserId,hub: socketHub,- openVideoWidget: () => {- openWorkbenchWidget(store.commands.widgets, getWidgetsForRegion, 'video', { preferredRegions: ['left'] });- },queries: store.queries,+ reveal,t,});diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/recallEventRuntime.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/recallEventRuntime.test.tsnew file mode 100644index 0000000000..dea971f818--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/image-actions/recallEventRuntime.test.ts@@ -0,0 +1,193 @@+import type { RegisteredWidget } from '@workbench/widgetContracts';++import { accountLifecycle, captureAccountScope } from '@platform/state/accountLifecycle';+import { createWorkbenchStore } from '@workbench/workbenchStore';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { bringRecallWidgetToFront } from './recallEventRuntime';++/** The registry's view of the Video widget: placeable on the left, nothing to preload. */+const videoWidget = {+ implementation: { preload: () => undefined },+ manifest: { allowedRegions: ['left', 'right'], id: 'video' },+ status: 'enabled',+} as unknown as RegisteredWidget;++const testRevealContext = (isEditingText = false) => ({+ getWidgetsForRegion: (region: string) => (region === 'left' ? [videoWidget] : []),+ isEditingText: () => isEditingText,+});++type Store = ReturnType<typeof createWorkbenchStore>;++const videoInstanceId = (store: Store, projectId: string) =>+ Object.values(store.queries.getProject(projectId)!.widgetInstances).find((instance) => instance.typeId === 'video')+ ?.id;++/** Where the Video widget is visible: the active tab of an expanded region whose panel is open, or floating. */+const videoWidgetPlacement = (store: Store, projectId: string): 'hidden' | 'floating' | 'shown' => {+ const project = store.queries.getProject(projectId)!;+ const id = videoInstanceId(store, projectId);++ if (id && project.floatingWidgets?.[id]) {+ return 'floating';+ }+ const left = project.widgetRegions.left;++ return id && left.activeInstanceId === id && !left.isCollapsed && project.layout.panels.isLeftOpen+ ? 'shown'+ : 'hidden';+};++const setup = () => {+ const store = createWorkbenchStore();+ const projectId = store.queries.getSnapshot().activeProject.id;+ const reveal = (options: { isEditingText?: boolean; projectId?: string } = {}) =>+ bringRecallWidgetToFront({+ commands: store.commands,+ owner: captureAccountScope(),+ projectId: options.projectId ?? projectId,+ queries: store.queries,+ reveal: testRevealContext(options.isEditingText),+ typeId: 'video',+ });++ return { projectId, reveal, store };+};++describe('bringRecallWidgetToFront', () => {+ beforeEach(() => {+ accountLifecycle.activate('owner');+ });++ it('opens the widget when the layout has none', () => {+ const { projectId, reveal, store } = setup();++ reveal();++ expect(videoWidgetPlacement(store, projectId)).toBe('shown');+ });++ it('selects its tab when another widget is in front of it', () => {+ const { projectId, reveal, store } = setup();+ store.commands.widgets.open({ projectId, region: 'left', widgetId: 'video' });+ store.commands.widgets.open({ projectId, region: 'left', widgetId: 'generate' });+ expect(videoWidgetPlacement(store, projectId)).toBe('hidden');++ reveal();++ expect(videoWidgetPlacement(store, projectId)).toBe('shown');+ });++ it('expands its collapsed region, and never collapses a shown one', () => {+ const { projectId, reveal, store } = setup();+ store.commands.widgets.open({ projectId, region: 'left', widgetId: 'video' });+ const id = videoInstanceId(store, projectId)!;+ // Selecting the active, expanded tab collapses its region.+ store.commands.widgets.select({ projectId, region: 'left', widgetId: id });+ expect(videoWidgetPlacement(store, projectId)).toBe('hidden');++ reveal();+ expect(videoWidgetPlacement(store, projectId)).toBe('shown');++ reveal();+ expect(videoWidgetPlacement(store, projectId)).toBe('shown');+ });++ it('raises a floating widget without docking it', () => {+ const { projectId, reveal, store } = setup();+ store.commands.widgets.open({ projectId, region: 'left', widgetId: 'video' });+ store.commands.widgets.open({ projectId, region: 'left', widgetId: 'generate' });+ const videoId = videoInstanceId(store, projectId)!;+ store.commands.widgets.float(videoId);+ const generateId = store.queries.getProject(projectId)!.widgetRegions.left.activeInstanceId!;+ store.commands.widgets.float(generateId);+ const stackOrder = () => store.queries.getProject(projectId)!.floatingWidgets![videoId]!.stackOrder;+ expect(stackOrder()).toBe(1);++ reveal();++ expect(videoWidgetPlacement(store, projectId)).toBe('floating');+ expect(stackOrder()).toBe(2);+ });++ it('unshades a floating widget rolled up to its title bar', () => {+ const { projectId, reveal, store } = setup();+ store.commands.widgets.open({ projectId, region: 'left', widgetId: 'video' });+ const videoId = videoInstanceId(store, projectId)!;+ store.commands.widgets.float(videoId);+ store.commands.widgets.setFloatingMode(videoId, 'shaded');++ reveal();++ expect(store.queries.getProject(projectId)!.floatingWidgets![videoId]!.mode).toBe('windowed');+ });++ it('opens the panel of an active, expanded tab whose panel is closed', () => {+ const { projectId, store } = setup();+ store.commands.widgets.open({ projectId, region: 'left', widgetId: 'video' });+ // Only layout presets close a panel; stand in for one having done so.+ const queries = {+ getSnapshot: () => {+ const snapshot = store.queries.getSnapshot();+ const { activeProject } = snapshot;+ return {+ ...snapshot,+ activeProject: {+ ...activeProject,+ layout: { ...activeProject.layout, panels: { ...activeProject.layout.panels, isLeftOpen: false } },+ },+ };+ },+ };+ const open = vi.spyOn(store.commands.widgets, 'open');++ bringRecallWidgetToFront({+ commands: store.commands,+ owner: captureAccountScope(),+ projectId,+ queries,+ reveal: testRevealContext(),+ typeId: 'video',+ });++ expect(open).toHaveBeenCalledWith({ projectId, region: 'left', widgetId: 'video' });+ });++ it('does nothing for an account that has since signed out', () => {+ const { projectId, store } = setup();+ const owner = captureAccountScope();+ const before = store.queries.getProject(projectId);+ accountLifecycle.activate('someone-else');++ bringRecallWidgetToFront({+ commands: store.commands,+ owner,+ projectId,+ queries: store.queries,+ reveal: testRevealContext(),+ typeId: 'video',+ });++ expect(store.queries.getProject(projectId)).toBe(before);+ });++ it('leaves the layout alone while the user is typing', () => {+ const { projectId, reveal, store } = setup();+ const before = store.queries.getProject(projectId);++ reveal({ isEditingText: true });++ expect(store.queries.getProject(projectId)).toBe(before);+ });++ it('leaves a project that is no longer on screen alone', () => {+ const { projectId, reveal, store } = setup();+ const before = store.queries.getProject(projectId);+ store.commands.projects.create();++ reveal({ projectId });++ expect(store.queries.getProject(projectId)).toBe(before);+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/recallEventRuntime.ts b/invokeai/frontend/webv2/src/workbench/image-actions/recallEventRuntime.tsindex cd330408ba..723a477780 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/recallEventRuntime.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/recallEventRuntime.ts@@ -1,10 +1,13 @@import type { ModelConfig } from '@features/models';import type { AccountScope } from '@platform/state/accountLifecycle';import type { SocketHub } from '@platform/transport/socketHub';+import type { WidgetRegion } from '@workbench/layoutContracts';+import type { RegisteredWidget, WidgetTypeId } from '@workbench/widgetContracts';import type { WorkbenchCommands, WorkbenchQueries } from '@workbench/workbenchStore';import { ensureModelsLoaded, getModelsSnapshot } from '@features/models';import { captureAccountScope, isAccountScopeCurrent } from '@platform/state/accountLifecycle';+import { openWidgetPlacement } from '@workbench/widgetPlacementCommands';export interface RecallRuntime {dispose(): void;@@ -117,3 +120,79 @@ export const createRecallEventRuntime = <Event extends { user_id: string }>({},};};++/** What bringing a recall's widget to the front needs from the app. */+export interface RecallRevealContext {+ getWidgetsForRegion: (region: WidgetRegion) => RegisteredWidget[];+ /** Whether the user is typing in a text field; a reveal must not switch tabs out from under them. */+ isEditingText: () => boolean;+}++const PANEL_OPEN_KEYS = { bottom: 'isBottomOpen', left: 'isLeftOpen', right: 'isRightOpen' } as const;++/**+ * Bring the widget a recall just changed to the front of its project, so the caller sees the result: select its+ * tab (expanding its region and opening its panel), raise (and unshade) it when it floats, or open it when the layout+ * has none. A+ * floating window stays floating. Nothing moves while the user is typing, or when the project is no longer the one+ * on screen; the notification reports the change either way.+ */+export const bringRecallWidgetToFront = ({+ commands,+ owner,+ projectId,+ queries,+ reveal,+ typeId,+}: {+ commands: Pick<WorkbenchCommands, 'widgets'>;+ owner: AccountScope;+ projectId: string;+ queries: Pick<WorkbenchQueries, 'getSnapshot'>;+ reveal: RecallRevealContext;+ typeId: WidgetTypeId;+}): void => {+ const project = queries.getSnapshot().activeProject;++ if (!isAccountScopeCurrent(owner) || project.id !== projectId || reveal.isEditingText()) {+ return;+ }++ const isTarget = (instanceId: string | null | undefined) =>+ instanceId !== null && instanceId !== undefined && project.widgetInstances[instanceId]?.typeId === typeId;+ const floating = Object.keys(project.floatingWidgets ?? {}).find(isTarget);++ if (floating) {+ // A shaded window is rolled up to its title bar; raising it alone would still hide the change.+ if (project.floatingWidgets?.[floating]?.mode === 'shaded') {+ commands.widgets.setFloatingMode(floating, 'windowed');+ }+ commands.widgets.focusFloating(floating);+ return;+ }++ const placed = (+ Object.entries(project.widgetRegions) as [WidgetRegion, (typeof project.widgetRegions)[WidgetRegion]][]+ ).filter(([, region]) => region.instanceIds.some(isTarget));+ const isShown = ([region, state]: (typeof placed)[number]) =>+ isTarget(state.activeInstanceId) &&+ !state.isCollapsed &&+ (region === 'center' || project.layout.panels[PANEL_OPEN_KEYS[region]]);++ if (placed.some(isShown)) {+ return;+ }+ if (placed.length > 0) {+ // Opening a type its region already holds activates that instance, expands the region and opens its panel.+ commands.widgets.open({ projectId, region: placed[0]![0], widgetId: typeId });+ return;+ }++ openWidgetPlacement({+ getWidgetsForRegion: reveal.getWidgetsForRegion,+ options: { preferredRegions: ['left'] },+ projectId,+ typeId,+ widgets: commands.widgets,+ });+};diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.test.tsindex 6c291cb78d..5ea9f3d098 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.test.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.test.ts@@ -51,6 +51,7 @@ const createDeps = () => {commands: {generation: {} as WorkbenchCommands['generation'],notifications: { reportError } as unknown as WorkbenchCommands['notifications'],+ widgets: {} as WorkbenchCommands['widgets'],},createRecallParametersRuntime,dispose,@@ -59,6 +60,7 @@ const createDeps = () => {getSnapshot: () => ({ activeProject: active }),} as unknown as Pick<WorkbenchQueries, 'getProject' | 'getSnapshot'>,received,+ reveal: { getWidgetsForRegion: () => [], isEditingText: () => false },t: ((key: string) => key) as unknown as TFunction,reportError,};@@ -166,14 +168,11 @@ describe('attachVideoRecallRuntime', () => {});const load = vi.fn(() => Promise.resolve({ createVideoRecallRuntime }));const getSessionUserId = () => 'owner';- const openVideoWidget = vi.fn();const bridge = attachVideoRecallRuntime({...deps,- commands: { ...deps.commands, widgets: {} as WorkbenchCommands['widgets'] },getSessionUserId,hub: socket.hub,load,- openVideoWidget,});socket.emit('recall_parameters_updated', event({ steps: 1 }));@@ -184,7 +183,7 @@ describe('attachVideoRecallRuntime', () => {expect(load).toHaveBeenCalledTimes(1);expect(createVideoRecallRuntime).toHaveBeenCalledWith(- expect.objectContaining({ getSessionUserId, openVideoWidget })+ expect.objectContaining({ getSessionUserId, reveal: deps.reveal }));expect(deps.received).toEqual([{ payload: { action: 'initial_video', user_id: 'owner' }, projectId: 'project-1' }]);diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.ts b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.tsindex 51daa7fb0c..25b94f84d9 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.ts@@ -2,7 +2,7 @@ import type { SocketHub } from '@platform/transport/socketHub';import type { WorkbenchCommands, WorkbenchQueries } from '@workbench/workbenchStore';import type { TFunction } from 'i18next';-import type { PendingRecallEvent, RecallRuntime } from './recallEventRuntime';+import type { PendingRecallEvent, RecallRevealContext, RecallRuntime } from './recallEventRuntime';import type { createRecallParametersRuntime } from './recallParametersRuntime';import type { createVideoRecallRuntime } from './videoRecallRuntime';@@ -88,20 +88,22 @@ export const attachRecallParametersRuntime = ({hub,load = () => import('./recallParametersRuntime'),queries,+ reveal,t,}: {- commands: Pick<WorkbenchCommands, 'generation' | 'notifications'>;+ commands: Pick<WorkbenchCommands, 'generation' | 'notifications' | 'widgets'>;getSessionUserId?: () => string | null;hub: Pick<SocketHub, 'on'>;load?: () => Promise<RecallParametersRuntimeModule>;queries: Pick<WorkbenchQueries, 'getProject' | 'getSnapshot'>;+ reveal: RecallRevealContext;t: TFunction;}): RecallRuntime =>attachLazyRecallRuntime({area: 'recall-parameters',commands,create: (module, replay) =>- module.createRecallParametersRuntime({ commands, getSessionUserId, hub, queries, replay, t }),+ module.createRecallParametersRuntime({ commands, getSessionUserId, hub, queries, replay, reveal, t }),eventName: 'recall_parameters_updated',hub,load,@@ -118,23 +120,23 @@ export const attachVideoRecallRuntime = ({getSessionUserId,hub,load = () => import('./videoRecallRuntime'),- openVideoWidget,queries,+ reveal,t,}: {commands: Pick<WorkbenchCommands, 'notifications' | 'widgets'>;getSessionUserId?: () => string | null;hub: Pick<SocketHub, 'on'>;load?: () => Promise<VideoRecallRuntimeModule>;- openVideoWidget: () => void;queries: Pick<WorkbenchQueries, 'getProject' | 'getSnapshot'>;+ reveal: RecallRevealContext;t: TFunction;}): RecallRuntime =>attachLazyRecallRuntime({area: 'video-recall',commands,create: (module, replay) =>- module.createVideoRecallRuntime({ commands, getSessionUserId, hub, openVideoWidget, queries, replay, t }),+ module.createVideoRecallRuntime({ commands, getSessionUserId, hub, queries, replay, reveal, t }),eventName: 'video_recall_requested',hub,load,diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.test.tsindex 17e284eb31..157ec04bb2 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.test.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.test.ts@@ -80,7 +80,16 @@ const createRuntime = (store: ReturnType<typeof createWorkbenchStore>,hub: Pick<SocketHub, 'on'>,options: Partial<Parameters<typeof createRecallParametersRuntime>[0]> = {}-) => createRecallParametersRuntime({ commands: store.commands, hub, queries: store.queries, t, ...options });+ // Nothing registers in this suite, so a reveal can only select or raise an instance already in the layout.+) =>+ createRecallParametersRuntime({+ commands: store.commands,+ hub,+ queries: store.queries,+ reveal: { getWidgetsForRegion: () => [], isEditingText: () => false },+ t,+ ...options,+ });const t = ((key: string) => key) as unknown as TFunction;@@ -276,4 +285,26 @@ describe('createRecallParametersRuntime', () => {runtime.dispose();});++ it('brings the Generate widget to the front once a recall applies', async () => {+ const store = createWorkbenchStore();+ const socket = createFakeSocketHub();+ const projectId = store.queries.getSnapshot().activeProject.id;+ store.commands.widgets.open({ projectId, region: 'left', widgetId: 'generate' });+ store.commands.widgets.open({ projectId, region: 'left', widgetId: 'video' });+ const activeType = () => {+ const project = store.queries.getProject(projectId)!;+ const active = project.widgetRegions.left.activeInstanceId;+ return active ? project.widgetInstances[active]?.typeId : undefined;+ };+ expect(activeType()).toBe('video');+ const runtime = createRuntime(store, socket.hub);++ socket.emit('recall_parameters_updated', event({ positive_prompt: 'a lighthouse' }));+ await flush();++ expect(activeType()).toBe('generate');++ runtime.dispose();+ });});diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.ts b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.tsindex bb33a758a1..98b92f152f 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.ts@@ -4,10 +4,10 @@ import type { TFunction } from 'i18next';import { getProjectWidgetValues } from '@workbench/widgetState';-import type { PendingRecallEvent, RecallRuntime } from './recallEventRuntime';+import type { PendingRecallEvent, RecallRevealContext, RecallRuntime } from './recallEventRuntime';import { executeRecallParameters } from './executeRecallParameters';-import { createRecallEventRuntime } from './recallEventRuntime';+import { bringRecallWidgetToFront, createRecallEventRuntime } from './recallEventRuntime';import { isRecallParametersUpdatedEvent } from './recallParameters';/** Apply `recall_parameters_updated` events to their arrival-time project's Generate panel. */@@ -17,19 +17,21 @@ export const createRecallParametersRuntime = ({hub,queries,replay,+ reveal,t,}: {- commands: Pick<WorkbenchCommands, 'generation' | 'notifications'>;+ commands: Pick<WorkbenchCommands, 'generation' | 'notifications' | 'widgets'>;getSessionUserId?: () => string | null;hub: Pick<SocketHub, 'on'>;queries: Pick<WorkbenchQueries, 'getProject' | 'getSnapshot'>;replay?: readonly PendingRecallEvent[];+ reveal: RecallRevealContext;/** Resolves against the current language at call time; captured once, at attach. */t: TFunction;}): RecallRuntime =>createRecallEventRuntime({- apply: ({ parameters }, { models, owner, projectId }) =>- executeRecallParameters({+ apply: async ({ parameters }, { models, owner, projectId }) => {+ const applied = await executeRecallParameters({commands,t,getGenerateValues: () => {@@ -40,7 +42,12 @@ export const createRecallParametersRuntime = ({owner,parameters,projectId,- }),+ });++ if (applied) {+ bringRecallWidgetToFront({ commands, owner, projectId, queries, reveal, typeId: 'generate' });+ }+ },area: 'recall-parameters',commands,eventName: 'recall_parameters_updated',diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecallRuntime.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecallRuntime.test.tsindex 5d51a26bbd..4b5d16c58e 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecallRuntime.test.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecallRuntime.test.ts@@ -1,5 +1,6 @@import type { ModelConfig, ModelsSnapshot } from '@features/models';import type { SocketHub } from '@platform/transport/socketHub';+import type { RegisteredWidget } from '@workbench/widgetContracts';import type { TFunction } from 'i18next';import { accountLifecycle } from '@platform/state/accountLifecycle';@@ -94,10 +95,16 @@ const placementEvent = (action: 'initial_video' | 'reference_video', video: Recoconst heldFrame = { height: 480, image_name: 'held.png', width: 832 };+/** The registry's view of the Video widget: placeable on the left, nothing to preload. */+const videoWidget = {+ implementation: { preload: () => undefined },+ manifest: { allowedRegions: ['left'], id: 'video' },+ status: 'enabled',+} as unknown as RegisteredWidget;+const setup = (panelModel: ModelConfig = WAN_I2V) => {const store = createWorkbenchStore();const socket = createFakeSocketHub();- const openVideoWidget = vi.fn();const projectId = store.queries.getSnapshot().activeProject.id;store.commands.widgets.patchValues(@@ -112,10 +119,24 @@ const setup = (panelModel: ModelConfig = WAN_I2V) => {const runtime = createVideoRecallRuntime({commands: store.commands,hub: socket.hub,- openVideoWidget,queries: store.queries,+ reveal: {+ getWidgetsForRegion: (region) => (region === 'left' ? [videoWidget] : []),+ isEditingText: () => false,+ },t,});+ /** Whether the Video widget is the visible tab of the project's left region. */+ const videoShown = (id = projectId) => {+ const project = store.queries.getProject(id)!;+ const left = project.widgetRegions.left;++ return (+ !left.isCollapsed &&+ left.activeInstanceId !== null &&+ project.widgetInstances[left.activeInstanceId]?.typeId === 'video'+ );+ };const videoValues = (id = projectId) => {const project = store.queries.getProject(id);return project ? getProjectWidgetValues(project, 'video') : {};@@ -123,7 +144,7 @@ const setup = (panelModel: ModelConfig = WAN_I2V) => {// Newest first.const lastNotice = () => store.queries.getSnapshot().notifications[0];- return { lastNotice, openVideoWidget, projectId, runtime, socket, store, videoValues };+ return { lastNotice, projectId, runtime, socket, store, videoShown, videoValues };};describe('createVideoRecallRuntime', () => {@@ -148,14 +169,14 @@ describe('createVideoRecallRuntime', () => {});it('applies a non-strict recall on top of the panel and reveals the Video widget', async () => {- const { lastNotice, openVideoWidget, runtime, socket, videoValues } = setup();+ const { lastNotice, videoShown, runtime, socket, videoValues } = setup();socket.emit(parametersEvent({ positive_prompt: 'a heron', seed: 99 }));await flush();expect(videoValues()).toMatchObject({ firstFrameImage: heldFrame, positivePrompt: 'a heron', seed: 99 });expect(lastNotice()).toEqual(expect.objectContaining({ kind: 'success', title: 'Recalled video data' }));- expect(openVideoWidget).toHaveBeenCalledTimes(1);+ expect(videoShown()).toBe(true);runtime.dispose();});@@ -183,7 +204,7 @@ describe('createVideoRecallRuntime', () => {});it('applies to the project it arrived for, without pulling a different project to the front', async () => {- const { openVideoWidget, projectId, runtime, socket, store, videoValues } = setup();+ const { videoShown, projectId, runtime, socket, store, videoValues } = setup();let releaseModels: () => void = () => {};modelsApi.ensureModelsLoaded.mockImplementation(() =>@@ -200,13 +221,13 @@ describe('createVideoRecallRuntime', () => {expect(videoValues(projectId).positivePrompt).toBe('for the first project');expect(videoValues(second.id).positivePrompt).toBeUndefined();- expect(openVideoWidget).not.toHaveBeenCalled();+ expect(videoShown()).toBe(false);runtime.dispose();});it('sets the initial video as the Initial Video field would', async () => {- const { lastNotice, openVideoWidget, runtime, socket, videoValues } = setup();+ const { lastNotice, videoShown, runtime, socket, videoValues } = setup();socket.emit(placementEvent('initial_video'));await flush();@@ -215,13 +236,13 @@ describe('createVideoRecallRuntime', () => {expect(lastNotice()).toEqual(expect.objectContaining({ kind: 'success', title: 'widgets.video.placement.initialVideoSet' }));- expect(openVideoWidget).toHaveBeenCalledTimes(1);+ expect(videoShown()).toBe(true);runtime.dispose();});it('declines a reference video the panel model cannot take, leaving the panel alone', async () => {- const { lastNotice, openVideoWidget, runtime, socket, videoValues } = setup();+ const { lastNotice, videoShown, runtime, socket, videoValues } = setup();const before = videoValues();socket.emit(placementEvent('reference_video'));@@ -235,7 +256,7 @@ describe('createVideoRecallRuntime', () => {title: 'widgets.video.placement.referenceNotAdded',}));- expect(openVideoWidget).not.toHaveBeenCalled();+ expect(videoShown()).toBe(false);runtime.dispose();});@@ -246,7 +267,7 @@ describe('createVideoRecallRuntime', () => {['a placement whose video has no size', { ...placementEvent('initial_video'), video: { video_name: 'clip.mp4' } }],['an unknown action', { ...placementEvent('initial_video'), action: 'delete_video' }],])('ignores %s', async (_label, payload) => {- const { openVideoWidget, runtime, socket, store, videoValues } = setup();+ const { videoShown, runtime, socket, store, videoValues } = setup();const before = videoValues();const notices = store.queries.getSnapshot().notifications.length;@@ -255,7 +276,7 @@ describe('createVideoRecallRuntime', () => {expect(videoValues()).toBe(before);expect(store.queries.getSnapshot().notifications).toHaveLength(notices);- expect(openVideoWidget).not.toHaveBeenCalled();+ expect(videoShown()).toBe(false);runtime.dispose();});@@ -355,27 +376,19 @@ describe('createVideoRecallRuntime', () => {});});- it.each(['placed', 'floating'] as const)(- 'leaves the layout alone when the Video widget is already %s there',- async (where) => {- const { openVideoWidget, projectId, runtime, socket, store, videoValues } = setup();-- store.commands.widgets.open({ projectId, region: 'left', widgetId: 'video' });- const project = store.queries.getProject(projectId)!;- const instanceId = Object.values(project.widgetInstances).find((instance) => instance.typeId === 'video')!.id;- if (where === 'floating') {- store.commands.widgets.float(instanceId);- }+ it('brings a Video widget in a background tab to the front', async () => {+ const { projectId, runtime, socket, store, videoShown } = setup();+ store.commands.widgets.open({ projectId, region: 'left', widgetId: 'video' });+ store.commands.widgets.open({ projectId, region: 'left', widgetId: 'generate' });+ expect(videoShown()).toBe(false);- socket.emit(parametersEvent({ positive_prompt: 'a heron' }));- await flush();+ socket.emit(parametersEvent({ positive_prompt: 'a heron' }));+ await flush();- expect(videoValues().positivePrompt).toBe('a heron');- expect(openVideoWidget).not.toHaveBeenCalled();+ expect(videoShown()).toBe(true);- runtime.dispose();- }- );+ runtime.dispose();+ });describe('placements', () => {it('appends a reference video with the defaults its wire facts imply', async () => {diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecallRuntime.ts b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecallRuntime.tsindex ea59edf750..72214d2e57 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecallRuntime.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecallRuntime.ts@@ -4,17 +4,16 @@ import type { SocketHub } from '@platform/transport/socketHub';import type { WorkbenchCommands, WorkbenchQueries } from '@workbench/workbenchStore';import type { TFunction } from 'i18next';-import { isAccountScopeCurrent } from '@platform/state/accountLifecycle';import { getProjectWidgetValues } from '@workbench/widgetState';import type { PlaceableVideo } from './index';-import type { PendingRecallEvent, RecallRuntime } from './recallEventRuntime';+import type { PendingRecallEvent, RecallRevealContext, RecallRuntime } from './recallEventRuntime';// Through the package entry, not the modules themselves: the gallery's actions share these modules, and importing// them from this lazy runtime directly would split them out of the image-actions chunk into one more request on// every editor route.import { appendReferenceVideo, applyVideoRecallMetadata, placeInitialVideo } from './index';-import { createRecallEventRuntime } from './recallEventRuntime';+import { bringRecallWidgetToFront, createRecallEventRuntime } from './recallEventRuntime';/** The `video` of a `video_recall_requested` event: a gallery video, as the backend describes it. */interface VideoRecallEventVideo {@@ -89,38 +88,20 @@ export const createVideoRecallRuntime = ({commands,getSessionUserId,hub,- openVideoWidget,queries,replay,+ reveal,t,}: {commands: Pick<WorkbenchCommands, 'notifications' | 'widgets'>;getSessionUserId?: () => string | null;hub: Pick<SocketHub, 'on'>;- openVideoWidget: () => void;queries: Pick<WorkbenchQueries, 'getProject' | 'getSnapshot'>;replay?: readonly PendingRecallEvent[];+ reveal: RecallRevealContext;/** Resolves against the current language at call time; captured once, at attach. */t: TFunction;}): RecallRuntime => {- // An external event arrives unprompted, so it only brings the Video widget into a layout that lacks it. Where the- // widget already sits (floating, or a tab of any region), revealing it would dock a floating window or switch the- // tab under whatever the user is doing; the notification reports the change instead.- const shouldRevealVideoWidget = (projectId: string, owner: AccountScope) => {- const project = queries.getSnapshot().activeProject;-- if (!isAccountScopeCurrent(owner) || project.id !== projectId) {- return false;- }-- const isVideo = (instanceId: string) => project.widgetInstances[instanceId]?.typeId === 'video';-- return !(- Object.keys(project.floatingWidgets ?? {}).some(isVideo) ||- Object.values(project.widgetRegions).some((region) => region.instanceIds.some(isVideo))- );- };-const apply = async (event: VideoRecallRequestedEvent,{ models, owner, projectId }: { models: ModelConfig[]; owner: AccountScope; projectId: string }@@ -197,8 +178,8 @@ export const createVideoRecallRuntime = ({}// The value patch itself routes the project's invocation to Video, where the user lets edits route it.- if (applied && shouldRevealVideoWidget(projectId, owner)) {- openVideoWidget();+ if (applied) {+ bringRecallWidgetToFront({ commands, owner, projectId, queries, reveal, typeId: 'video' });}};