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): notify on every successful enqueue

joshistoast16960177a8f9
diff --git a/invokeai/frontend/webv2/src/workbench/projectContracts.ts b/invokeai/frontend/webv2/src/workbench/projectContracts.ts
index 71b3c041a2..0a45d4723f 100644
--- a/invokeai/frontend/webv2/src/workbench/projectContracts.ts
+++ b/invokeai/frontend/webv2/src/workbench/projectContracts.ts
@@ -74,6 +74,10 @@ export interface WorkbenchNotification {
createdAt: string;
projectId?: string;
isRead: boolean;
+ /** Machine category for toast policy (e.g. 'enqueue'); absent = always toast. */
+ category?: string;
+ /** Coalesced repeat count (see addNotification); absent = 1. */
+ occurrenceCount?: number;
}
/**
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index 645db45014..982b9c6516 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -2101,6 +2101,40 @@ describe('workbenchReducer Phase 5 generation flow', () => {
expect(state.notifications).toEqual([]);
});
+ describe('enqueue notifications', () => {
+ it('records an enqueue notification when submitResolvedInvocationSnapshot adds a queue item', () => {
+ const state = primeGenerate();
+
+ const next = workbenchReducer(state, {
+ backendSupportsCancellation: true,
+ route: { destination: 'gallery', destinationLocked: false, sourceId: 'generate', sourceLocked: false },
+ type: 'submitResolvedInvocationSnapshot',
+ });
+
+ expect(getActiveProject(next).queue.items.length).toBeGreaterThan(0);
+ expect(next.notifications[0]?.title).toBe('Invocation queued');
+ expect(next.notifications[0]?.category).toBe('enqueue');
+ expect(next.notifications[0]?.kind).toBe('success');
+ });
+
+ it('does not record a notification when the submit adds no queue item', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { sourceId: 'upscale', type: 'setInvocationSource' });
+
+ const notificationCount = state.notifications.length;
+
+ const next = workbenchReducer(state, {
+ backendSupportsCancellation: true,
+ route: { destination: 'canvas', destinationLocked: false, sourceId: 'upscale', sourceLocked: true },
+ type: 'submitResolvedInvocationSnapshot',
+ });
+
+ expect(getActiveProject(next).queue.items).toEqual([]);
+ expect(next.notifications).toHaveLength(notificationCount);
+ });
+ });
+
it('accepts the project graph source but does not queue an empty project graph', () => {
let state = createInitialWorkbenchState();
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
index 50fad34da8..a58f70480c 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
@@ -402,16 +402,19 @@ const createId = (prefix: string): string =>
`${prefix}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
const createNotification = ({
+ category,
kind,
message,
projectId,
title,
}: {
+ category?: string;
kind: WorkbenchNotificationKind;
message?: string;
projectId?: string;
title: string;
}): WorkbenchNotification => ({
+ category,
createdAt: now(),
id: createId('notification'),
isRead: false,
@@ -426,6 +429,29 @@ const addNotification = (state: WorkbenchState, notification: WorkbenchNotificat
notifications: [notification, ...state.notifications].slice(0, NOTIFICATION_LIMIT),
});
+/** Adds the "Invocation queued" notice iff the reduction actually grew the active queue. */
+const withEnqueueNotification = (state: WorkbenchState, nextState: WorkbenchState): WorkbenchState => {
+ const before = state.projects.find((project) => project.id === state.activeProjectId);
+ const after = nextState.projects.find((project) => project.id === nextState.activeProjectId);
+
+ if (!before || !after || before.queue.items.length >= after.queue.items.length) {
+ return nextState;
+ }
+
+ const queueItem = after.queue.items[0];
+
+ return addNotification(
+ nextState,
+ createNotification({
+ category: 'enqueue',
+ kind: 'success',
+ message: `${after.name}: ${queueItem.snapshot.sourceId} to ${queueItem.snapshot.destination}`,
+ projectId: after.id,
+ title: 'Invocation queued',
+ })
+ );
+};
+
const areRecordsShallowEqual = (left: Record<string, unknown>, right: Record<string, unknown>): boolean => {
if (left === right) {
return true;
@@ -3358,36 +3384,24 @@ export const __workbenchReducerInternal = (
}));
}
case 'submitInvocationSnapshot': {
- const beforeProject = state.projects.find((project) => project.id === state.activeProjectId);
- const nextState = updateActiveProject(state, (project) =>
- submitInvocationSnapshot(project, action.backendSupportsCancellation, undefined, action.models)
- );
- const afterProject = nextState.projects.find((project) => project.id === nextState.activeProjectId);
-
- if (!beforeProject || !afterProject || beforeProject.queue.items.length === afterProject.queue.items.length) {
- return nextState;
- }
-
- const queueItem = afterProject.queue.items[0];
-
- return addNotification(
- nextState,
- createNotification({
- kind: 'info',
- message: `${afterProject.name}: ${queueItem.snapshot.sourceId} to ${queueItem.snapshot.destination}`,
- projectId: afterProject.id,
- title: 'Invocation queued',
- })
+ return withEnqueueNotification(
+ state,
+ updateActiveProject(state, (project) =>
+ submitInvocationSnapshot(project, action.backendSupportsCancellation, undefined, action.models)
+ )
);
}
case 'submitResolvedInvocationSnapshot': {
- return updateActiveProject(state, (project) =>
- submitInvocationSnapshot(
- project,
- action.backendSupportsCancellation,
- resolveInvocationRoute(project, 'global', action.route, action.models),
- action.models,
- action.positivePrompts
+ return withEnqueueNotification(
+ state,
+ updateActiveProject(state, (project) =>
+ submitInvocationSnapshot(
+ project,
+ action.backendSupportsCancellation,
+ resolveInvocationRoute(project, 'global', action.route, action.models),
+ action.models,
+ action.positivePrompts
+ )
)
);
}
@@ -3774,18 +3788,21 @@ export const __workbenchReducerInternal = (
return updateProjectById(state, action.projectId, (project) => applyAutoRouteForEdit(project, 'canvas', context));
}
case 'submitCanvasInvocationSnapshot': {
- return updateProjectById(state, action.projectId, (project) =>
- enqueueCompiledSnapshot(
- project,
- { ...project.invocation, destination: action.destination, sourceId: 'canvas' },
- {
- generate: action.generate,
- graph: action.graph,
- positivePrompts: action.positivePrompts,
- widgetStates: getWidgetStatesSnapshot(project.widgetInstances),
- },
- action.backendSupportsCancellation,
- action.canvas
+ return withEnqueueNotification(
+ state,
+ updateProjectById(state, action.projectId, (project) =>
+ enqueueCompiledSnapshot(
+ project,
+ { ...project.invocation, destination: action.destination, sourceId: 'canvas' },
+ {
+ generate: action.generate,
+ graph: action.graph,
+ positivePrompts: action.positivePrompts,
+ widgetStates: getWidgetStatesSnapshot(project.widgetInstances),
+ },
+ action.backendSupportsCancellation,
+ action.canvas
+ )
)
);
}