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.

refactor(webv2): move generation runtime

joshistoastd6d08beb863c
diff --git a/invokeai/frontend/webv2/src/app/GenerateWidgetSyncRuntime.tsx b/invokeai/frontend/webv2/src/app/GenerateWidgetSyncRuntime.tsx
index a81f6ef41d..b9a5925fef 100644
--- a/invokeai/frontend/webv2/src/app/GenerateWidgetSyncRuntime.tsx
+++ b/invokeai/frontend/webv2/src/app/GenerateWidgetSyncRuntime.tsx
@@ -1,3 +1,4 @@
+import { createGenerateWidgetSyncRuntime, type GenerateWidgetSyncProjectSnapshot } from '@features/generation/runtime';
import { ensureModelsLoaded, getModelsSnapshot, subscribeModels } from '@features/models';
import { useMountEffect } from '@platform/react/useMountEffect';
import { createProjectedExternalStore } from '@platform/state/projectedExternalStore';
@@ -5,8 +6,6 @@ import { useQueryClient } from '@tanstack/react-query';
import { getProjectWidgetValues } from '@workbench/widgetState';
import { useWorkbenchInternalStore } from '@workbench/WorkbenchContext';
-import { createGenerateWidgetSyncRuntime, type GenerateWidgetSyncProjectSnapshot } from './generateWidgetSyncRuntime';
-
/** App-owned production composition of Generation, Models, Query, and Workbench. */
export const GenerateWidgetSyncRuntime = () => {
const store = useWorkbenchInternalStore();
diff --git a/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts b/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts
index fa79bf82f6..e187d1cab6 100644
--- a/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts
+++ b/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts
@@ -176,6 +176,7 @@ describe('feature public-interface registry', () => {
// Workbench resolves prompt expansion before submitting, so it reads
// Generation's prompt cache through the public entry module.
expect(checkDependency('workbench/invocationSubmit.ts', '@features/generation/prompts')).toEqual([]);
+ expect(checkDependency('app/GenerateWidgetSyncRuntime.tsx', '@features/generation/runtime')).toEqual([]);
expect(
checkDependency('workbench/invocationSubmit.ts', '@features/generation/data/dynamicPromptsQueries')
).toMatchObject([{ rule: 'feature-private-interface' }]);
diff --git a/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts b/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts
index 65b78c459d..a8228db607 100644
--- a/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts
+++ b/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts
@@ -6,7 +6,7 @@
*/
export const FEATURE_PUBLIC_INTERFACES: Readonly<Record<string, readonly string[]>> = {
gallery: ['contracts', 'paletteSearch', 'queries', 'react', 'utility', 'widget'],
- generation: ['components', 'contracts', 'graph', 'prompts', 'queries', 'react', 'settings', 'widget'],
+ generation: ['components', 'contracts', 'graph', 'prompts', 'queries', 'react', 'runtime', 'settings', 'widget'],
identity: [],
models: ['react'],
nodes: [],
diff --git a/invokeai/frontend/webv2/src/app/generateWidgetSyncRuntime.test.ts b/invokeai/frontend/webv2/src/features/generation/runtime.test.ts
similarity index 85%
rename from invokeai/frontend/webv2/src/app/generateWidgetSyncRuntime.test.ts
rename to invokeai/frontend/webv2/src/features/generation/runtime.test.ts
index c36acc58ce..55ac91f82d 100644
--- a/invokeai/frontend/webv2/src/app/generateWidgetSyncRuntime.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/runtime.test.ts
@@ -27,7 +27,7 @@ import {
createGenerateWidgetSyncRuntime,
type GenerateWidgetSyncProjectSnapshot,
type GenerateWidgetSyncRuntimeDeps,
-} from './generateWidgetSyncRuntime';
+} from './runtime';
const createModel = (key: string, overrides: Partial<MainModelConfig> = {}): MainModelConfig => ({
base: 'sdxl',
@@ -104,26 +104,6 @@ beforeEach(() => {
});
describe('createGenerateWidgetSyncRuntime', () => {
- it('reconciles the initial project immediately with a bounded synchronous system dispatch', () => {
- const model = createModel('model');
- const { patches, project, runtime } = setup({
- models: [model],
- project: { id: 'project-1', values: {} },
- });
-
- expect(patches).toHaveLength(1);
- expect(patches[0]).toMatchObject({
- origin: 'system',
- projectId: 'project-1',
- values: { model, modelKey: model.key },
- });
- expect(patches[0]?.values).not.toHaveProperty('batchCount');
- expect(project.getSnapshot().values).toMatchObject({ model, modelKey: model.key });
- expect(templateQuery.queryFn).not.toHaveBeenCalled();
-
- runtime.dispose();
- });
-
it('reconciles the newly active project after a project switch', () => {
const model = createModel('model');
const initialValues = createValues(model);
@@ -139,21 +119,6 @@ describe('createGenerateWidgetSyncRuntime', () => {
runtime.dispose();
});
- it('reconciles model snapshots after a model-store notification', () => {
- const stale = createModel('model', { name: 'Stale name' });
- const current = createModel('model', { name: 'Current name' });
- const { models, patches, runtime } = setup({
- models: [stale],
- project: { id: 'project-1', values: createValues(stale) },
- });
-
- models.setSnapshot([current]);
-
- expect(patches).toHaveLength(1);
- expect(patches[0]?.values.model).toBe(current);
- runtime.dispose();
- });
-
it('reconciles an applied template after the observer publishes a successful result', async () => {
const model = createModel('model');
const staleTemplate = {
diff --git a/invokeai/frontend/webv2/src/app/generateWidgetSyncRuntime.ts b/invokeai/frontend/webv2/src/features/generation/runtime.ts
similarity index 100%
rename from invokeai/frontend/webv2/src/app/generateWidgetSyncRuntime.ts
rename to invokeai/frontend/webv2/src/features/generation/runtime.ts