feat(ui): update UI to use new events

- Use OpenAPI schema for event payload types
- Update all event listeners
- Add missing events / remove old nonexistent events
This commit is contained in:
psychedelicious 2024-03-14 19:05:40 +11:00
parent 975dc14579
commit 8d79ce94aa
16 changed files with 282 additions and 568 deletions

View File

@ -275,7 +275,7 @@ class SessionCanceledEvent(SessionEvent):
@payload_schema.register # pyright: ignore [reportUnknownMemberType] @payload_schema.register # pyright: ignore [reportUnknownMemberType]
class QueueItemStatusChangedEvent(QueueItemEvent): class QueueItemStatusChangedEvent(SessionEvent):
"""Emitted when a queue item's status changes""" """Emitted when a queue item's status changes"""
__event_name__ = "queue_item_status_changed" __event_name__ = "queue_item_status_changed"
@ -299,6 +299,7 @@ class QueueItemStatusChangedEvent(QueueItemEvent):
queue_id=queue_item.queue_id, queue_id=queue_item.queue_id,
item_id=queue_item.item_id, item_id=queue_item.item_id,
batch_id=queue_item.batch_id, batch_id=queue_item.batch_id,
session_id=queue_item.session_id,
status=queue_item.status, status=queue_item.status,
error_type=queue_item.error_type, error_type=queue_item.error_type,
error_message=queue_item.error_message, error_message=queue_item.error_message,

View File

@ -35,6 +35,7 @@ import { addImageUploadedFulfilledListener } from 'app/store/middleware/listener
import { addModelSelectedListener } from 'app/store/middleware/listenerMiddleware/listeners/modelSelected'; import { addModelSelectedListener } from 'app/store/middleware/listenerMiddleware/listeners/modelSelected';
import { addModelsLoadedListener } from 'app/store/middleware/listenerMiddleware/listeners/modelsLoaded'; import { addModelsLoadedListener } from 'app/store/middleware/listenerMiddleware/listeners/modelsLoaded';
import { addDynamicPromptsListener } from 'app/store/middleware/listenerMiddleware/listeners/promptChanged'; import { addDynamicPromptsListener } from 'app/store/middleware/listenerMiddleware/listeners/promptChanged';
import { addSetDefaultSettingsListener } from 'app/store/middleware/listenerMiddleware/listeners/setDefaultSettings';
import { addSocketConnectedEventListener } from 'app/store/middleware/listenerMiddleware/listeners/socketio/socketConnected'; import { addSocketConnectedEventListener } from 'app/store/middleware/listenerMiddleware/listeners/socketio/socketConnected';
import { addSocketDisconnectedEventListener } from 'app/store/middleware/listenerMiddleware/listeners/socketio/socketDisconnected'; import { addSocketDisconnectedEventListener } from 'app/store/middleware/listenerMiddleware/listeners/socketio/socketDisconnected';
import { addGeneratorProgressEventListener } from 'app/store/middleware/listenerMiddleware/listeners/socketio/socketGeneratorProgress'; import { addGeneratorProgressEventListener } from 'app/store/middleware/listenerMiddleware/listeners/socketio/socketGeneratorProgress';
@ -53,8 +54,6 @@ import { addUpscaleRequestedListener } from 'app/store/middleware/listenerMiddle
import { addWorkflowLoadRequestedListener } from 'app/store/middleware/listenerMiddleware/listeners/workflowLoadRequested'; import { addWorkflowLoadRequestedListener } from 'app/store/middleware/listenerMiddleware/listeners/workflowLoadRequested';
import type { AppDispatch, RootState } from 'app/store/store'; import type { AppDispatch, RootState } from 'app/store/store';
import { addSetDefaultSettingsListener } from './listeners/setDefaultSettings';
export const listenerMiddleware = createListenerMiddleware(); export const listenerMiddleware = createListenerMiddleware();
export type AppStartListening = TypedStartListening<RootState, AppDispatch>; export type AppStartListening = TypedStartListening<RootState, AppDispatch>;

View File

@ -5,8 +5,8 @@ import { toast } from 'features/toast/toast';
import { t } from 'i18next'; import { t } from 'i18next';
import { imagesApi } from 'services/api/endpoints/images'; import { imagesApi } from 'services/api/endpoints/images';
import { import {
socketBulkDownloadCompleted, socketBulkDownloadComplete,
socketBulkDownloadFailed, socketBulkDownloadError,
socketBulkDownloadStarted, socketBulkDownloadStarted,
} from 'services/events/actions'; } from 'services/events/actions';
@ -54,7 +54,7 @@ export const addBulkDownloadListeners = (startAppListening: AppStartListening) =
}); });
startAppListening({ startAppListening({
actionCreator: socketBulkDownloadCompleted, actionCreator: socketBulkDownloadComplete,
effect: async (action) => { effect: async (action) => {
log.debug(action.payload.data, 'Bulk download preparation completed'); log.debug(action.payload.data, 'Bulk download preparation completed');
@ -80,7 +80,7 @@ export const addBulkDownloadListeners = (startAppListening: AppStartListening) =
}); });
startAppListening({ startAppListening({
actionCreator: socketBulkDownloadFailed, actionCreator: socketBulkDownloadError,
effect: async (action) => { effect: async (action) => {
log.debug(action.payload.data, 'Bulk download preparation failed'); log.debug(action.payload.data, 'Bulk download preparation failed');

View File

@ -69,8 +69,8 @@ export const addControlNetImageProcessedListener = (startAppListening: AppStartL
const [invocationCompleteAction] = await take( const [invocationCompleteAction] = await take(
(action): action is ReturnType<typeof socketInvocationComplete> => (action): action is ReturnType<typeof socketInvocationComplete> =>
socketInvocationComplete.match(action) && socketInvocationComplete.match(action) &&
action.payload.data.queue_batch_id === enqueueResult.batch.batch_id && action.payload.data.batch_id === enqueueResult.batch.batch_id &&
action.payload.data.source_node_id === nodeId action.payload.data.invocation_source_id === nodeId
); );
// We still have to check the output type // We still have to check the output type

View File

@ -29,12 +29,12 @@ export const addInvocationCompleteEventListener = (startAppListening: AppStartLi
actionCreator: socketInvocationComplete, actionCreator: socketInvocationComplete,
effect: async (action, { dispatch, getState }) => { effect: async (action, { dispatch, getState }) => {
const { data } = action.payload; const { data } = action.payload;
log.debug({ data: parseify(data) }, `Invocation complete (${action.payload.data.node.type})`); log.debug({ data: parseify(data) }, `Invocation complete (${data.invocation_type})`);
const { result, node, queue_batch_id, source_node_id } = data; const { result, invocation_source_id } = data;
// This complete event has an associated image output // This complete event has an associated image output
if (isImageOutput(result) && !nodeTypeDenylist.includes(node.type)) { if (isImageOutput(data.result) && !nodeTypeDenylist.includes(data.invocation_type)) {
const { image_name } = result.image; const { image_name } = data.result.image;
const { canvas, gallery } = getState(); const { canvas, gallery } = getState();
// This populates the `getImageDTO` cache // This populates the `getImageDTO` cache
@ -48,7 +48,7 @@ export const addInvocationCompleteEventListener = (startAppListening: AppStartLi
imageDTORequest.unsubscribe(); imageDTORequest.unsubscribe();
// Add canvas images to the staging area // Add canvas images to the staging area
if (canvas.batchIds.includes(queue_batch_id) && data.source_node_id === CANVAS_OUTPUT) { if (canvas.batchIds.includes(data.batch_id) && data.invocation_source_id === CANVAS_OUTPUT) {
dispatch(addImageToStagingArea(imageDTO)); dispatch(addImageToStagingArea(imageDTO));
} }
@ -114,7 +114,7 @@ export const addInvocationCompleteEventListener = (startAppListening: AppStartLi
} }
} }
const nes = deepClone($nodeExecutionStates.get()[source_node_id]); const nes = deepClone($nodeExecutionStates.get()[invocation_source_id]);
if (nes) { if (nes) {
nes.status = zNodeStatus.enum.COMPLETED; nes.status = zNodeStatus.enum.COMPLETED;
if (nes.progress !== null) { if (nes.progress !== null) {

View File

@ -11,9 +11,9 @@ export const addInvocationErrorEventListener = (startAppListening: AppStartListe
startAppListening({ startAppListening({
actionCreator: socketInvocationError, actionCreator: socketInvocationError,
effect: (action) => { effect: (action) => {
log.error(action.payload, `Invocation error (${action.payload.data.node.type})`); const { invocation_source_id, invocation_type, error_type, error_message, error_traceback } = action.payload.data;
const { source_node_id, error_type, error_message, error_traceback } = action.payload.data; log.error(action.payload, `Invocation error (${invocation_type})`);
const nes = deepClone($nodeExecutionStates.get()[source_node_id]); const nes = deepClone($nodeExecutionStates.get()[invocation_source_id]);
if (nes) { if (nes) {
nes.status = zNodeStatus.enum.FAILED; nes.status = zNodeStatus.enum.FAILED;
nes.progress = null; nes.progress = null;

View File

@ -11,9 +11,9 @@ export const addInvocationStartedEventListener = (startAppListening: AppStartLis
startAppListening({ startAppListening({
actionCreator: socketInvocationStarted, actionCreator: socketInvocationStarted,
effect: (action) => { effect: (action) => {
log.debug(action.payload, `Invocation started (${action.payload.data.node.type})`); log.debug(action.payload, `Invocation started (${action.payload.data.invocation_type})`);
const { source_node_id } = action.payload.data; const { invocation_source_id } = action.payload.data;
const nes = deepClone($nodeExecutionStates.get()[source_node_id]); const nes = deepClone($nodeExecutionStates.get()[invocation_source_id]);
if (nes) { if (nes) {
nes.status = zNodeStatus.enum.IN_PROGRESS; nes.status = zNodeStatus.enum.IN_PROGRESS;
upsertExecutionState(nes.nodeId, nes); upsertExecutionState(nes.nodeId, nes);

View File

@ -3,14 +3,14 @@ import { api, LIST_TAG } from 'services/api';
import { modelsApi } from 'services/api/endpoints/models'; import { modelsApi } from 'services/api/endpoints/models';
import { import {
socketModelInstallCancelled, socketModelInstallCancelled,
socketModelInstallCompleted, socketModelInstallComplete,
socketModelInstallDownloading, socketModelInstallDownloadProgress,
socketModelInstallError, socketModelInstallError,
} from 'services/events/actions'; } from 'services/events/actions';
export const addModelInstallEventListener = (startAppListening: AppStartListening) => { export const addModelInstallEventListener = (startAppListening: AppStartListening) => {
startAppListening({ startAppListening({
actionCreator: socketModelInstallDownloading, actionCreator: socketModelInstallDownloadProgress,
effect: async (action, { dispatch }) => { effect: async (action, { dispatch }) => {
const { bytes, total_bytes, id } = action.payload.data; const { bytes, total_bytes, id } = action.payload.data;
@ -29,7 +29,7 @@ export const addModelInstallEventListener = (startAppListening: AppStartListenin
}); });
startAppListening({ startAppListening({
actionCreator: socketModelInstallCompleted, actionCreator: socketModelInstallComplete,
effect: (action, { dispatch }) => { effect: (action, { dispatch }) => {
const { id } = action.payload.data; const { id } = action.payload.data;

View File

@ -1,6 +1,6 @@
import { logger } from 'app/logging/logger'; import { logger } from 'app/logging/logger';
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware'; import type { AppStartListening } from 'app/store/middleware/listenerMiddleware';
import { socketModelLoadCompleted, socketModelLoadStarted } from 'services/events/actions'; import { socketModelLoadComplete, socketModelLoadStarted } from 'services/events/actions';
const log = logger('socketio'); const log = logger('socketio');
@ -8,10 +8,11 @@ export const addModelLoadEventListener = (startAppListening: AppStartListening)
startAppListening({ startAppListening({
actionCreator: socketModelLoadStarted, actionCreator: socketModelLoadStarted,
effect: (action) => { effect: (action) => {
const { model_config, submodel_type } = action.payload.data; const { config, submodel_type } = action.payload.data;
const { name, base, type } = model_config; const { name, base, type } = config;
const extras: string[] = [base, type]; const extras: string[] = [base, type];
if (submodel_type) { if (submodel_type) {
extras.push(submodel_type); extras.push(submodel_type);
} }
@ -23,16 +24,15 @@ export const addModelLoadEventListener = (startAppListening: AppStartListening)
}); });
startAppListening({ startAppListening({
actionCreator: socketModelLoadCompleted, actionCreator: socketModelLoadComplete,
effect: (action) => { effect: (action) => {
const { model_config, submodel_type } = action.payload.data; const { config, submodel_type } = action.payload.data;
const { name, base, type } = model_config; const { name, base, type } = config;
const extras: string[] = [base, type]; const extras: string[] = [base, type];
if (submodel_type) { if (submodel_type) {
extras.push(submodel_type); extras.push(submodel_type);
} }
const message = `Model load complete: ${name} (${extras.join(', ')})`; const message = `Model load complete: ${name} (${extras.join(', ')})`;
log.debug(action.payload, message); log.debug(action.payload, message);

View File

@ -16,16 +16,36 @@ export const addSocketQueueItemStatusChangedEventListener = (startAppListening:
actionCreator: socketQueueItemStatusChanged, actionCreator: socketQueueItemStatusChanged,
effect: async (action, { dispatch, getState }) => { effect: async (action, { dispatch, getState }) => {
// we've got new status for the queue item, batch and queue // we've got new status for the queue item, batch and queue
const { queue_item, batch_status, queue_status } = action.payload.data; const {
item_id,
session_id,
status,
started_at,
updated_at,
completed_at,
batch_status,
queue_status,
error_type,
error_message,
error_traceback,
} = action.payload.data;
log.debug(action.payload, `Queue item ${queue_item.item_id} status updated: ${queue_item.status}`); log.debug(action.payload, `Queue item ${item_id} status updated: ${status}`);
// Update this specific queue item in the list of queue items (this is the queue item DTO, without the session) // Update this specific queue item in the list of queue items (this is the queue item DTO, without the session)
dispatch( dispatch(
queueApi.util.updateQueryData('listQueueItems', undefined, (draft) => { queueApi.util.updateQueryData('listQueueItems', undefined, (draft) => {
queueItemsAdapter.updateOne(draft, { queueItemsAdapter.updateOne(draft, {
id: String(queue_item.item_id), id: String(item_id),
changes: queue_item, changes: {
status,
started_at,
updated_at: updated_at ?? undefined,
completed_at: completed_at ?? undefined,
error_type,
error_message,
error_traceback,
},
}); });
}) })
); );
@ -52,11 +72,11 @@ export const addSocketQueueItemStatusChangedEventListener = (startAppListening:
'CurrentSessionQueueItem', 'CurrentSessionQueueItem',
'NextSessionQueueItem', 'NextSessionQueueItem',
'InvocationCacheStatus', 'InvocationCacheStatus',
{ type: 'SessionQueueItem', id: queue_item.item_id }, { type: 'SessionQueueItem', id: item_id },
]) ])
); );
if (queue_item.status === 'in_progress') { if (status === 'in_progress') {
forEach($nodeExecutionStates.get(), (nes) => { forEach($nodeExecutionStates.get(), (nes) => {
if (!nes) { if (!nes) {
return; return;
@ -69,8 +89,7 @@ export const addSocketQueueItemStatusChangedEventListener = (startAppListening:
clone.outputs = []; clone.outputs = [];
$nodeExecutionStates.setKey(clone.nodeId, clone); $nodeExecutionStates.setKey(clone.nodeId, clone);
}); });
} else if (queue_item.status === 'failed' && queue_item.error_type) { } else if (status === 'failed' && error_type) {
const { error_type, error_message, session_id } = queue_item;
const isLocal = getState().config.isLocal ?? true; const isLocal = getState().config.isLocal ?? true;
const sessionId = session_id; const sessionId = session_id;

View File

@ -1,7 +1,6 @@
import type { PayloadAction } from '@reduxjs/toolkit'; import type { PayloadAction } from '@reduxjs/toolkit';
import { createSlice } from '@reduxjs/toolkit'; import { createSlice } from '@reduxjs/toolkit';
import type { PersistConfig, RootState } from 'app/store/store'; import type { PersistConfig, RootState } from 'app/store/store';
import { calculateStepPercentage } from 'features/system/util/calculateStepPercentage';
import type { LogLevelName } from 'roarr'; import type { LogLevelName } from 'roarr';
import { import {
socketConnected, socketConnected,
@ -10,7 +9,7 @@ import {
socketGraphExecutionStateComplete, socketGraphExecutionStateComplete,
socketInvocationComplete, socketInvocationComplete,
socketInvocationStarted, socketInvocationStarted,
socketModelLoadCompleted, socketModelLoadComplete,
socketModelLoadStarted, socketModelLoadStarted,
socketQueueItemStatusChanged, socketQueueItemStatusChanged,
} from 'services/events/actions'; } from 'services/events/actions';
@ -98,14 +97,7 @@ export const systemSlice = createSlice({
* Generator Progress * Generator Progress
*/ */
builder.addCase(socketGeneratorProgress, (state, action) => { builder.addCase(socketGeneratorProgress, (state, action) => {
const { const { step, total_steps, progress_image, session_id, batch_id } = action.payload.data;
step,
total_steps,
order,
progress_image,
graph_execution_state_id: session_id,
queue_batch_id: batch_id,
} = action.payload.data;
if (state.cancellations.includes(session_id)) { if (state.cancellations.includes(session_id)) {
// Do not update the progress if this session has been cancelled. This prevents a race condition where we get a // Do not update the progress if this session has been cancelled. This prevents a race condition where we get a
@ -116,8 +108,7 @@ export const systemSlice = createSlice({
state.denoiseProgress = { state.denoiseProgress = {
step, step,
total_steps, total_steps,
order, percentage: step / total_steps,
percentage: calculateStepPercentage(step, total_steps, order),
progress_image, progress_image,
session_id, session_id,
batch_id, batch_id,
@ -146,15 +137,15 @@ export const systemSlice = createSlice({
state.status = 'LOADING_MODEL'; state.status = 'LOADING_MODEL';
}); });
builder.addCase(socketModelLoadCompleted, (state) => { builder.addCase(socketModelLoadComplete, (state) => {
state.status = 'CONNECTED'; state.status = 'CONNECTED';
}); });
builder.addCase(socketQueueItemStatusChanged, (state, action) => { builder.addCase(socketQueueItemStatusChanged, (state, action) => {
if (['completed', 'canceled', 'failed'].includes(action.payload.data.queue_item.status)) { if (['completed', 'canceled', 'failed'].includes(action.payload.data.status)) {
state.status = 'CONNECTED'; state.status = 'CONNECTED';
state.denoiseProgress = null; state.denoiseProgress = null;
state.cancellations.push(action.payload.data.queue_item.session_id); state.cancellations.push(action.payload.data.session_id);
} }
}); });
}, },

View File

@ -10,7 +10,6 @@ type DenoiseProgress = {
progress_image: ProgressImage | null | undefined; progress_image: ProgressImage | null | undefined;
step: number; step: number;
total_steps: number; total_steps: number;
order: number;
percentage: number; percentage: number;
}; };

File diff suppressed because one or more lines are too long

View File

@ -1,22 +1,21 @@
import { createAction } from '@reduxjs/toolkit'; import { createAction } from '@reduxjs/toolkit';
import type { import type {
BulkDownloadCompletedEvent, BulkDownloadCompleteEvent,
BulkDownloadFailedEvent, BulkDownloadFailedEvent,
BulkDownloadStartedEvent, BulkDownloadStartedEvent,
GeneratorProgressEvent,
GraphExecutionStateCompleteEvent,
InvocationCompleteEvent, InvocationCompleteEvent,
InvocationDenoiseProgressEvent,
InvocationErrorEvent, InvocationErrorEvent,
InvocationRetrievalErrorEvent,
InvocationStartedEvent, InvocationStartedEvent,
ModelInstallCancelledEvent, ModelInstallCancelledEvent,
ModelInstallCompletedEvent, ModelInstallCompleteEvent,
ModelInstallDownloadingEvent, ModelInstallDownloadProgressEvent,
ModelInstallErrorEvent, ModelInstallErrorEvent,
ModelLoadCompletedEvent, ModelInstallStartedEvent,
ModelLoadCompleteEvent,
ModelLoadStartedEvent, ModelLoadStartedEvent,
QueueItemStatusChangedEvent, QueueItemStatusChangedEvent,
SessionRetrievalErrorEvent, SessionCompleteEvent,
} from 'services/events/types'; } from 'services/events/types';
// Create actions for each socket // Create actions for each socket
@ -45,28 +44,32 @@ export const socketInvocationError = createAction<{
}>('socket/socketInvocationError'); }>('socket/socketInvocationError');
export const socketGraphExecutionStateComplete = createAction<{ export const socketGraphExecutionStateComplete = createAction<{
data: GraphExecutionStateCompleteEvent; data: SessionCompleteEvent;
}>('socket/socketGraphExecutionStateComplete'); }>('socket/socketGraphExecutionStateComplete');
export const socketGeneratorProgress = createAction<{ export const socketGeneratorProgress = createAction<{
data: GeneratorProgressEvent; data: InvocationDenoiseProgressEvent;
}>('socket/socketGeneratorProgress'); }>('socket/socketGeneratorProgress');
export const socketModelLoadStarted = createAction<{ export const socketModelLoadStarted = createAction<{
data: ModelLoadStartedEvent; data: ModelLoadStartedEvent;
}>('socket/socketModelLoadStarted'); }>('socket/socketModelLoadStarted');
export const socketModelLoadCompleted = createAction<{ export const socketModelLoadComplete = createAction<{
data: ModelLoadCompletedEvent; data: ModelLoadCompleteEvent;
}>('socket/socketModelLoadCompleted'); }>('socket/socketModelLoadComplete');
export const socketModelInstallDownloading = createAction<{ export const socketModelInstallStarted = createAction<{
data: ModelInstallDownloadingEvent; data: ModelInstallStartedEvent;
}>('socket/socketModelInstallDownloading'); }>('socket/socketModelInstallStarted');
export const socketModelInstallCompleted = createAction<{ export const socketModelInstallDownloadProgress = createAction<{
data: ModelInstallCompletedEvent; data: ModelInstallDownloadProgressEvent;
}>('socket/socketModelInstallCompleted'); }>('socket/socketModelInstallDownloadProgress');
export const socketModelInstallComplete = createAction<{
data: ModelInstallCompleteEvent;
}>('socket/socketModelInstallComplete');
export const socketModelInstallError = createAction<{ export const socketModelInstallError = createAction<{
data: ModelInstallErrorEvent; data: ModelInstallErrorEvent;
@ -76,14 +79,6 @@ export const socketModelInstallCancelled = createAction<{
data: ModelInstallCancelledEvent; data: ModelInstallCancelledEvent;
}>('socket/socketModelInstallCancelled'); }>('socket/socketModelInstallCancelled');
export const socketSessionRetrievalError = createAction<{
data: SessionRetrievalErrorEvent;
}>('socket/socketSessionRetrievalError');
export const socketInvocationRetrievalError = createAction<{
data: InvocationRetrievalErrorEvent;
}>('socket/socketInvocationRetrievalError');
export const socketQueueItemStatusChanged = createAction<{ export const socketQueueItemStatusChanged = createAction<{
data: QueueItemStatusChangedEvent; data: QueueItemStatusChangedEvent;
}>('socket/socketQueueItemStatusChanged'); }>('socket/socketQueueItemStatusChanged');
@ -92,10 +87,10 @@ export const socketBulkDownloadStarted = createAction<{
data: BulkDownloadStartedEvent; data: BulkDownloadStartedEvent;
}>('socket/socketBulkDownloadStarted'); }>('socket/socketBulkDownloadStarted');
export const socketBulkDownloadCompleted = createAction<{ export const socketBulkDownloadComplete = createAction<{
data: BulkDownloadCompletedEvent; data: BulkDownloadCompleteEvent;
}>('socket/socketBulkDownloadCompleted'); }>('socket/socketBulkDownloadComplete');
export const socketBulkDownloadFailed = createAction<{ export const socketBulkDownloadError = createAction<{
data: BulkDownloadFailedEvent; data: BulkDownloadFailedEvent;
}>('socket/socketBulkDownloadFailed'); }>('socket/socketBulkDownloadError');

View File

@ -1,278 +1,59 @@
import type { components } from 'services/api/schema'; import type { Graph, GraphExecutionState, S } from 'services/api/types';
import type { AnyModelConfig, Graph, GraphExecutionState, SubModelType } from 'services/api/types';
/**
* A progress image, we get one for each step in the generation
*/
export type ProgressImage = {
dataURL: string;
width: number;
height: number;
};
export type AnyInvocation = NonNullable<NonNullable<Graph['nodes']>[string]>; export type AnyInvocation = NonNullable<NonNullable<Graph['nodes']>[string]>;
export type AnyResult = NonNullable<GraphExecutionState['results'][string]>; export type AnyResult = NonNullable<GraphExecutionState['results'][string]>;
type BaseNode = { export type ModelLoadStartedEvent = S['ModelLoadStartedEvent'];
id: string; export type ModelLoadCompleteEvent = S['ModelLoadCompleteEvent'];
type: string;
[key: string]: AnyInvocation[keyof AnyInvocation];
};
export type ModelLoadStartedEvent = { export type InvocationStartedEvent = S['InvocationStartedEvent'];
queue_id: string; export type InvocationDenoiseProgressEvent = S['InvocationDenoiseProgressEvent'];
queue_item_id: number; export type InvocationCompleteEvent = Omit<S['InvocationCompleteEvent'], 'result'> & { result: AnyResult };
queue_batch_id: string; export type InvocationErrorEvent = S['InvocationErrorEvent'];
graph_execution_state_id: string; export type ProgressImage = InvocationDenoiseProgressEvent['progress_image'];
model_config: AnyModelConfig;
submodel_type?: SubModelType | null;
};
export type ModelLoadCompletedEvent = { export type ModelInstallDownloadProgressEvent = S['ModelInstallDownloadProgressEvent'];
queue_id: string; export type ModelInstallCompleteEvent = S['ModelInstallCompleteEvent'];
queue_item_id: number; export type ModelInstallErrorEvent = S['ModelInstallErrorEvent'];
queue_batch_id: string; export type ModelInstallStartedEvent = S['ModelInstallStartedEvent'];
graph_execution_state_id: string; export type ModelInstallCancelledEvent = S['ModelInstallCancelledEvent'];
model_config: AnyModelConfig;
submodel_type?: SubModelType | null;
};
export type ModelInstallDownloadingEvent = { export type SessionCompleteEvent = S['SessionCompleteEvent'];
bytes: number; export type SessionCanceledEvent = S['SessionCanceledEvent'];
local_path: string;
source: string;
timestamp: number;
total_bytes: number;
id: number;
};
export type ModelInstallCompletedEvent = { export type QueueItemStatusChangedEvent = S['QueueItemStatusChangedEvent'];
key: number;
source: string;
timestamp: number;
id: number;
};
export type ModelInstallErrorEvent = { export type BulkDownloadStartedEvent = S['BulkDownloadStartedEvent'];
error: string; export type BulkDownloadCompleteEvent = S['BulkDownloadCompleteEvent'];
error_type: string; export type BulkDownloadFailedEvent = S['BulkDownloadErrorEvent'];
source: string;
timestamp: number;
id: number;
};
export type ModelInstallCancelledEvent = {
source: string;
timestamp: number;
id: number;
};
/**
* A `generator_progress` socket.io event.
*
* @example socket.on('generator_progress', (data: GeneratorProgressEvent) => { ... }
*/
export type GeneratorProgressEvent = {
queue_id: string;
queue_item_id: number;
queue_batch_id: string;
graph_execution_state_id: string;
node_id: string;
source_node_id: string;
progress_image?: ProgressImage;
step: number;
order: number;
total_steps: number;
};
/**
* A `invocation_complete` socket.io event.
*
* `result` is a discriminated union with a `type` property as the discriminant.
*
* @example socket.on('invocation_complete', (data: InvocationCompleteEvent) => { ... }
*/
export type InvocationCompleteEvent = {
queue_id: string;
queue_item_id: number;
queue_batch_id: string;
graph_execution_state_id: string;
node: BaseNode;
source_node_id: string;
result: AnyResult;
};
/**
* A `invocation_error` socket.io event.
*
* @example socket.on('invocation_error', (data: InvocationErrorEvent) => { ... }
*/
export type InvocationErrorEvent = {
queue_id: string;
queue_item_id: number;
queue_batch_id: string;
graph_execution_state_id: string;
node: BaseNode;
source_node_id: string;
error_type: string;
error_message: string;
error_traceback: string;
};
/**
* A `invocation_started` socket.io event.
*
* @example socket.on('invocation_started', (data: InvocationStartedEvent) => { ... }
*/
export type InvocationStartedEvent = {
queue_id: string;
queue_item_id: number;
queue_batch_id: string;
graph_execution_state_id: string;
node: BaseNode;
source_node_id: string;
};
/**
* A `graph_execution_state_complete` socket.io event.
*
* @example socket.on('graph_execution_state_complete', (data: GraphExecutionStateCompleteEvent) => { ... }
*/
export type GraphExecutionStateCompleteEvent = {
queue_id: string;
queue_item_id: number;
queue_batch_id: string;
graph_execution_state_id: string;
};
/**
* A `session_retrieval_error` socket.io event.
*
* @example socket.on('session_retrieval_error', (data: SessionRetrievalErrorEvent) => { ... }
*/
export type SessionRetrievalErrorEvent = {
queue_id: string;
queue_item_id: number;
queue_batch_id: string;
graph_execution_state_id: string;
error_type: string;
error: string;
};
/**
* A `invocation_retrieval_error` socket.io event.
*
* @example socket.on('invocation_retrieval_error', (data: InvocationRetrievalErrorEvent) => { ... }
*/
export type InvocationRetrievalErrorEvent = {
queue_id: string;
queue_item_id: number;
queue_batch_id: string;
graph_execution_state_id: string;
node_id: string;
error_type: string;
error: string;
};
/**
* A `queue_item_status_changed` socket.io event.
*
* @example socket.on('queue_item_status_changed', (data: QueueItemStatusChangedEvent) => { ... }
*/
export type QueueItemStatusChangedEvent = {
queue_id: string;
queue_item: {
queue_id: string;
item_id: number;
batch_id: string;
session_id: string;
status: components['schemas']['SessionQueueItemDTO']['status'];
error_type?: string | null;
error_message?: string | null;
error_traceback?: string | null;
created_at: string;
updated_at: string;
started_at: string | undefined;
completed_at: string | undefined;
};
batch_status: {
queue_id: string;
batch_id: string;
pending: number;
in_progress: number;
completed: number;
failed: number;
canceled: number;
total: number;
};
queue_status: {
queue_id: string;
item_id?: number;
batch_id?: string;
session_id?: string;
pending: number;
in_progress: number;
completed: number;
failed: number;
canceled: number;
total: number;
};
};
type ClientEmitSubscribeQueue = { type ClientEmitSubscribeQueue = {
queue_id: string; queue_id: string;
}; };
export type ClientEmitUnsubscribeQueue = ClientEmitSubscribeQueue;
type ClientEmitUnsubscribeQueue = { export type ClientEmitSubscribeBulkDownload = {
queue_id: string;
};
export type BulkDownloadStartedEvent = {
bulk_download_id: string;
bulk_download_item_id: string;
bulk_download_item_name: string;
};
export type BulkDownloadCompletedEvent = {
bulk_download_id: string;
bulk_download_item_id: string;
bulk_download_item_name: string;
};
export type BulkDownloadFailedEvent = {
bulk_download_id: string;
bulk_download_item_id: string;
bulk_download_item_name: string;
error: string;
};
type ClientEmitSubscribeBulkDownload = {
bulk_download_id: string;
};
type ClientEmitUnsubscribeBulkDownload = {
bulk_download_id: string; bulk_download_id: string;
}; };
export type ClientEmitUnsubscribeBulkDownload = ClientEmitSubscribeBulkDownload;
export type ServerToClientEvents = { export type ServerToClientEvents = {
generator_progress: (payload: GeneratorProgressEvent) => void; invocation_denoise_progress: (payload: InvocationDenoiseProgressEvent) => void;
invocation_complete: (payload: InvocationCompleteEvent) => void; invocation_complete: (payload: InvocationCompleteEvent) => void;
invocation_error: (payload: InvocationErrorEvent) => void; invocation_error: (payload: InvocationErrorEvent) => void;
invocation_started: (payload: InvocationStartedEvent) => void; invocation_started: (payload: InvocationStartedEvent) => void;
graph_execution_state_complete: (payload: GraphExecutionStateCompleteEvent) => void; session_complete: (payload: SessionCompleteEvent) => void;
model_load_started: (payload: ModelLoadStartedEvent) => void; model_load_started: (payload: ModelLoadStartedEvent) => void;
model_load_completed: (payload: ModelLoadCompletedEvent) => void; model_install_started: (payload: ModelInstallStartedEvent) => void;
model_install_downloading: (payload: ModelInstallDownloadingEvent) => void; model_install_download_progress: (payload: ModelInstallDownloadProgressEvent) => void;
model_install_completed: (payload: ModelInstallCompletedEvent) => void; model_install_complete: (payload: ModelInstallCompleteEvent) => void;
model_install_error: (payload: ModelInstallErrorEvent) => void; model_install_error: (payload: ModelInstallErrorEvent) => void;
model_install_canceled: (payload: ModelInstallCancelledEvent) => void; model_install_cancelled: (payload: ModelInstallCancelledEvent) => void;
session_retrieval_error: (payload: SessionRetrievalErrorEvent) => void; model_load_complete: (payload: ModelLoadCompleteEvent) => void;
invocation_retrieval_error: (payload: InvocationRetrievalErrorEvent) => void;
queue_item_status_changed: (payload: QueueItemStatusChangedEvent) => void; queue_item_status_changed: (payload: QueueItemStatusChangedEvent) => void;
bulk_download_started: (payload: BulkDownloadStartedEvent) => void; bulk_download_started: (payload: BulkDownloadStartedEvent) => void;
bulk_download_completed: (payload: BulkDownloadCompletedEvent) => void; bulk_download_complete: (payload: BulkDownloadCompleteEvent) => void;
bulk_download_failed: (payload: BulkDownloadFailedEvent) => void; bulk_download_error: (payload: BulkDownloadFailedEvent) => void;
}; };
export type ClientToServerEvents = { export type ClientToServerEvents = {

View File

@ -4,8 +4,8 @@ import { $queueId } from 'app/store/nanostores/queueId';
import type { AppDispatch } from 'app/store/store'; import type { AppDispatch } from 'app/store/store';
import { toast } from 'features/toast/toast'; import { toast } from 'features/toast/toast';
import { import {
socketBulkDownloadCompleted, socketBulkDownloadComplete,
socketBulkDownloadFailed, socketBulkDownloadError,
socketBulkDownloadStarted, socketBulkDownloadStarted,
socketConnected, socketConnected,
socketDisconnected, socketDisconnected,
@ -13,15 +13,15 @@ import {
socketGraphExecutionStateComplete, socketGraphExecutionStateComplete,
socketInvocationComplete, socketInvocationComplete,
socketInvocationError, socketInvocationError,
socketInvocationRetrievalError,
socketInvocationStarted, socketInvocationStarted,
socketModelInstallCompleted, socketModelInstallCancelled,
socketModelInstallDownloading, socketModelInstallComplete,
socketModelInstallDownloadProgress,
socketModelInstallError, socketModelInstallError,
socketModelLoadCompleted, socketModelInstallStarted,
socketModelLoadComplete,
socketModelLoadStarted, socketModelLoadStarted,
socketQueueItemStatusChanged, socketQueueItemStatusChanged,
socketSessionRetrievalError,
} from 'services/events/actions'; } from 'services/events/actions';
import type { ClientToServerEvents, ServerToClientEvents } from 'services/events/types'; import type { ClientToServerEvents, ServerToClientEvents } from 'services/events/types';
import type { Socket } from 'socket.io-client'; import type { Socket } from 'socket.io-client';
@ -61,131 +61,55 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
} }
}); });
/**
* Disconnect
*/
socket.on('disconnect', () => { socket.on('disconnect', () => {
dispatch(socketDisconnected()); dispatch(socketDisconnected());
}); });
/**
* Invocation started
*/
socket.on('invocation_started', (data) => { socket.on('invocation_started', (data) => {
dispatch(socketInvocationStarted({ data })); dispatch(socketInvocationStarted({ data }));
}); });
/** socket.on('invocation_denoise_progress', (data) => {
* Generator progress
*/
socket.on('generator_progress', (data) => {
dispatch(socketGeneratorProgress({ data })); dispatch(socketGeneratorProgress({ data }));
}); });
/**
* Invocation error
*/
socket.on('invocation_error', (data) => { socket.on('invocation_error', (data) => {
dispatch(socketInvocationError({ data })); dispatch(socketInvocationError({ data }));
}); });
/**
* Invocation complete
*/
socket.on('invocation_complete', (data) => { socket.on('invocation_complete', (data) => {
dispatch( dispatch(socketInvocationComplete({ data }));
socketInvocationComplete({
data,
})
);
}); });
/** socket.on('session_complete', (data) => {
* Graph complete dispatch(socketGraphExecutionStateComplete({ data }));
*/
socket.on('graph_execution_state_complete', (data) => {
dispatch(
socketGraphExecutionStateComplete({
data,
})
);
}); });
/**
* Model load started
*/
socket.on('model_load_started', (data) => { socket.on('model_load_started', (data) => {
dispatch( dispatch(socketModelLoadStarted({ data }));
socketModelLoadStarted({
data,
})
);
}); });
/** socket.on('model_load_complete', (data) => {
* Model load completed dispatch(socketModelLoadComplete({ data }));
*/
socket.on('model_load_completed', (data) => {
dispatch(
socketModelLoadCompleted({
data,
})
);
}); });
/** socket.on('model_install_started', (data) => {
* Model Install Downloading dispatch(socketModelInstallStarted({ data }));
*/
socket.on('model_install_downloading', (data) => {
dispatch(
socketModelInstallDownloading({
data,
})
);
}); });
/** socket.on('model_install_download_progress', (data) => {
* Model Install Completed dispatch(socketModelInstallDownloadProgress({ data }));
*/ });
socket.on('model_install_completed', (data) => {
dispatch( socket.on('model_install_complete', (data) => {
socketModelInstallCompleted({ dispatch(socketModelInstallComplete({ data }));
data,
})
);
}); });
/**
* Model Install Error
*/
socket.on('model_install_error', (data) => { socket.on('model_install_error', (data) => {
dispatch( dispatch(socketModelInstallError({ data }));
socketModelInstallError({
data,
})
);
}); });
/** socket.on('model_install_cancelled', (data) => {
* Session retrieval error dispatch(socketModelInstallCancelled({ data }));
*/
socket.on('session_retrieval_error', (data) => {
dispatch(
socketSessionRetrievalError({
data,
})
);
});
/**
* Invocation retrieval error
*/
socket.on('invocation_retrieval_error', (data) => {
dispatch(
socketInvocationRetrievalError({
data,
})
);
}); });
socket.on('queue_item_status_changed', (data) => { socket.on('queue_item_status_changed', (data) => {
@ -196,11 +120,11 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
dispatch(socketBulkDownloadStarted({ data })); dispatch(socketBulkDownloadStarted({ data }));
}); });
socket.on('bulk_download_completed', (data) => { socket.on('bulk_download_complete', (data) => {
dispatch(socketBulkDownloadCompleted({ data })); dispatch(socketBulkDownloadComplete({ data }));
}); });
socket.on('bulk_download_failed', (data) => { socket.on('bulk_download_error', (data) => {
dispatch(socketBulkDownloadFailed({ data })); dispatch(socketBulkDownloadError({ data }));
}); });
}; };