diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlAdapterPreprocessor.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlAdapterPreprocessor.ts index 581146c25c..ba04947a2d 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlAdapterPreprocessor.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlAdapterPreprocessor.ts @@ -13,7 +13,6 @@ import { isControlAdapterLayer, } from 'features/controlLayers/store/controlLayersSlice'; import { CA_PROCESSOR_DATA } from 'features/controlLayers/util/controlAdapters'; -import { isImageOutput } from 'features/nodes/types/common'; import { toast } from 'features/toast/toast'; import { t } from 'i18next'; import { isEqual } from 'lodash-es'; @@ -139,7 +138,7 @@ export const addControlAdapterPreprocessor = (startAppListening: AppStartListeni // We still have to check the output type assert( - isImageOutput(invocationCompleteAction.payload.data.result), + invocationCompleteAction.payload.data.result.type === 'image_output', `Processor did not return an image output, got: ${invocationCompleteAction.payload.data.result}` ); const { image_name } = invocationCompleteAction.payload.data.result.image; diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetImageProcessed.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetImageProcessed.ts index 1e485b31d5..574dad00eb 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetImageProcessed.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/controlNetImageProcessed.ts @@ -9,7 +9,6 @@ import { selectControlAdapterById, } from 'features/controlAdapters/store/controlAdaptersSlice'; import { isControlNetOrT2IAdapter } from 'features/controlAdapters/store/types'; -import { isImageOutput } from 'features/nodes/types/common'; import { toast } from 'features/toast/toast'; import { t } from 'i18next'; import { imagesApi } from 'services/api/endpoints/images'; @@ -74,7 +73,7 @@ export const addControlNetImageProcessedListener = (startAppListening: AppStartL ); // We still have to check the output type - if (isImageOutput(invocationCompleteAction.payload.data.result)) { + if (invocationCompleteAction.payload.data.result.type === 'image_output') { const { image_name } = invocationCompleteAction.payload.data.result.image; // Wait for the ImageDTO to be received diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketInvocationComplete.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketInvocationComplete.ts index 1a04f9493a..2841493ca6 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketInvocationComplete.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketInvocationComplete.ts @@ -11,7 +11,6 @@ import { } from 'features/gallery/store/gallerySlice'; import { IMAGE_CATEGORIES } from 'features/gallery/store/types'; import { $nodeExecutionStates, upsertExecutionState } from 'features/nodes/hooks/useExecutionState'; -import { isImageOutput } from 'features/nodes/types/common'; import { zNodeStatus } from 'features/nodes/types/invocation'; import { CANVAS_OUTPUT } from 'features/nodes/util/graph/constants'; import { boardsApi } from 'services/api/endpoints/boards'; @@ -33,7 +32,7 @@ export const addInvocationCompleteEventListener = (startAppListening: AppStartLi const { result, invocation_source_id } = data; // This complete event has an associated image output - if (isImageOutput(data.result) && !nodeTypeDenylist.includes(data.invocation.type)) { + if (data.result.type === 'image_output' && !nodeTypeDenylist.includes(data.invocation.type)) { const { image_name } = data.result.image; const { canvas, gallery } = getState(); diff --git a/invokeai/frontend/web/src/features/nodes/components/sidePanel/inspector/InspectorOutputsTab.tsx b/invokeai/frontend/web/src/features/nodes/components/sidePanel/inspector/InspectorOutputsTab.tsx index d4150243b9..59a603e7f1 100644 --- a/invokeai/frontend/web/src/features/nodes/components/sidePanel/inspector/InspectorOutputsTab.tsx +++ b/invokeai/frontend/web/src/features/nodes/components/sidePanel/inspector/InspectorOutputsTab.tsx @@ -11,8 +11,7 @@ import { selectLastSelectedNode } from 'features/nodes/store/selectors'; import { isInvocationNode } from 'features/nodes/types/invocation'; import { memo, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; -import type { ImageOutput } from 'services/api/types'; -import type { AnyResult } from 'services/events/types'; +import type { ImageOutput, S } from 'services/api/types'; import ImageOutputPreview from './outputs/ImageOutputPreview'; @@ -66,4 +65,4 @@ const InspectorOutputsTab = () => { export default memo(InspectorOutputsTab); -const getKey = (result: AnyResult, i: number) => `${result.type}-${i}`; +const getKey = (result: S['AnyInvocationOutput'], i: number) => `${result.type}-${i}`; diff --git a/invokeai/frontend/web/src/features/nodes/types/common.ts b/invokeai/frontend/web/src/features/nodes/types/common.ts index ca44259995..54e126af3a 100644 --- a/invokeai/frontend/web/src/features/nodes/types/common.ts +++ b/invokeai/frontend/web/src/features/nodes/types/common.ts @@ -144,5 +144,4 @@ const zImageOutput = z.object({ type: z.literal('image_output'), }); export type ImageOutput = z.infer; -export const isImageOutput = (output: unknown): output is ImageOutput => zImageOutput.safeParse(output).success; // #endregion diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.ts index 130da8bf15..8f880a46a7 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.ts @@ -1,8 +1,7 @@ import type { NodesState } from 'features/nodes/store/types'; import { isInvocationNode } from 'features/nodes/types/invocation'; import { omit, reduce } from 'lodash-es'; -import type { Graph } from 'services/api/types'; -import type { AnyInvocation } from 'services/events/types'; +import type { Graph, S } from 'services/api/types'; import { v4 as uuidv4 } from 'uuid'; /** @@ -82,7 +81,7 @@ export const buildNodesGraph = (nodesState: NodesState): Graph => { parsedEdges.forEach((edge) => { const destination_node = parsedNodes[edge.destination.node_id]; const field = edge.destination.field; - parsedNodes[edge.destination.node_id] = omit(destination_node, field) as AnyInvocation; + parsedNodes[edge.destination.node_id] = omit(destination_node, field) as S['AnyInvocation']; }); // Assemble! diff --git a/invokeai/frontend/web/src/services/api/types.ts b/invokeai/frontend/web/src/services/api/types.ts index 3522d719fb..17b63f6f7c 100644 --- a/invokeai/frontend/web/src/services/api/types.ts +++ b/invokeai/frontend/web/src/services/api/types.ts @@ -122,7 +122,6 @@ export type ModelInstallStatus = S['InstallStatus']; // Graphs export type Graph = S['Graph']; export type NonNullableGraph = O.Required; -export type GraphExecutionState = S['GraphExecutionState']; export type Batch = S['Batch']; export type SessionQueueItemDTO = S['SessionQueueItemDTO']; export type WorkflowRecordOrderBy = S['WorkflowRecordOrderBy']; @@ -132,10 +131,10 @@ export type WorkflowRecordListItemDTO = S['WorkflowRecordListItemDTO']; type KeysOfUnion = T extends T ? keyof T : never; export type AnyInvocation = Exclude< - Graph['nodes'][string], + S['AnyInvocation'], S['CoreMetadataInvocation'] | S['MetadataInvocation'] | S['MetadataItemInvocation'] | S['MergeMetadataInvocation'] >; -export type AnyInvocationIncMetadata = S['Graph']['nodes'][string]; +export type AnyInvocationIncMetadata = S['AnyInvocation']; export type InvocationType = AnyInvocation['type']; type InvocationOutputMap = S['InvocationOutputMap']; diff --git a/invokeai/frontend/web/src/services/events/types.ts b/invokeai/frontend/web/src/services/events/types.ts index 3a7de93627..a84049cc28 100644 --- a/invokeai/frontend/web/src/services/events/types.ts +++ b/invokeai/frontend/web/src/services/events/types.ts @@ -1,21 +1,12 @@ -import type { Graph, GraphExecutionState, S } from 'services/api/types'; - -export type AnyInvocation = NonNullable[string]>; - -export type AnyResult = NonNullable; +import type { S } from 'services/api/types'; export type ModelLoadStartedEvent = S['ModelLoadStartedEvent']; export type ModelLoadCompleteEvent = S['ModelLoadCompleteEvent']; -export type InvocationStartedEvent = Omit & { invocation: AnyInvocation }; -export type InvocationDenoiseProgressEvent = Omit & { - invocation: AnyInvocation; -}; -export type InvocationCompleteEvent = Omit & { - result: AnyResult; - invocation: AnyInvocation; -}; -export type InvocationErrorEvent = Omit & { invocation: AnyInvocation }; +export type InvocationStartedEvent = S['InvocationStartedEvent']; +export type InvocationDenoiseProgressEvent = S['InvocationDenoiseProgressEvent']; +export type InvocationCompleteEvent = S['InvocationCompleteEvent']; +export type InvocationErrorEvent = S['InvocationErrorEvent']; export type ProgressImage = InvocationDenoiseProgressEvent['progress_image']; export type ModelInstallDownloadProgressEvent = S['ModelInstallDownloadProgressEvent'];