feat(ui): change intermediates handling

- Update the canvas graph generation to flag its uploaded init and mask images as `intermediate`.
- During canvas setup, hit the update route to associate the uploaded images with the session id.
- Organize the socketio and RTK listener middlware better. Needed to facilitate the updated canvas logic.
- Add a new action `sessionReadyToInvoke`. The `sessionInvoked` action is *only* ever run in response to this event. This lets us do whatever complicated setup (eg canvas) and explicitly invoking. Previously, invoking was tied to the socket subscribe events.
- Some minor tidying.
This commit is contained in:
psychedelicious
2023-05-25 23:47:57 +10:00
committed by Kent Keirsey
parent 5025f84627
commit a2de5c9963
25 changed files with 529 additions and 185 deletions

View File

@ -8,7 +8,11 @@ import {
import { socketSubscribed, socketUnsubscribed } from './actions';
import { AppThunkDispatch, RootState } from 'app/store/store';
import { getTimestamp } from 'common/util/getTimestamp';
import { sessionInvoked, sessionCreated } from 'services/thunks/session';
import {
sessionInvoked,
sessionCreated,
sessionWithoutGraphCreated,
} from 'services/thunks/session';
import { OpenAPI } from 'services/api';
import { setEventListeners } from 'services/events/util/setEventListeners';
import { log } from 'app/logging/useLogger';
@ -62,17 +66,14 @@ export const socketMiddleware = () => {
socket.connect();
}
if (sessionCreated.fulfilled.match(action)) {
if (
sessionCreated.fulfilled.match(action) ||
sessionWithoutGraphCreated.fulfilled.match(action)
) {
const sessionId = action.payload.id;
const sessionLog = socketioLog.child({ sessionId });
const oldSessionId = getState().system.sessionId;
if (oldSessionId) {
sessionLog.debug(
{ oldSessionId },
`Unsubscribed from old session (${oldSessionId})`
);
socket.emit('unsubscribe', {
session: oldSessionId,
});
@ -85,8 +86,6 @@ export const socketMiddleware = () => {
);
}
sessionLog.debug(`Subscribe to new session (${sessionId})`);
socket.emit('subscribe', { session: sessionId });
dispatch(
@ -95,9 +94,6 @@ export const socketMiddleware = () => {
timestamp: getTimestamp(),
})
);
// Finally we actually invoke the session, starting processing
dispatch(sessionInvoked({ sessionId }));
}
next(action);

View File

@ -1,7 +1,6 @@
import { MiddlewareAPI } from '@reduxjs/toolkit';
import { AppDispatch, RootState } from 'app/store/store';
import { getTimestamp } from 'common/util/getTimestamp';
import { sessionCanceled } from 'services/thunks/session';
import { Socket } from 'socket.io-client';
import {
generatorProgress,
@ -16,12 +15,6 @@ import {
import { ClientToServerEvents, ServerToClientEvents } from '../types';
import { Logger } from 'roarr';
import { JsonObject } from 'roarr/dist/types';
import {
receivedResultImagesPage,
receivedUploadImagesPage,
} from 'services/thunks/gallery';
import { receivedModels } from 'services/thunks/model';
import { receivedOpenAPISchema } from 'services/thunks/schema';
import { makeToast } from '../../../app/components/Toaster';
import { addToast } from '../../../features/system/store/systemSlice';
@ -43,37 +36,13 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
dispatch(socketConnected({ timestamp: getTimestamp() }));
const { results, uploads, models, nodes, config, system } = getState();
const { sessionId } = getState().system;
const { disabledTabs } = config;
// These thunks need to be dispatch in middleware; cannot handle in a reducer
if (!results.ids.length) {
dispatch(receivedResultImagesPage());
}
if (!uploads.ids.length) {
dispatch(receivedUploadImagesPage());
}
if (!models.ids.length) {
dispatch(receivedModels());
}
if (!nodes.schema && !disabledTabs.includes('nodes')) {
dispatch(receivedOpenAPISchema());
}
if (system.sessionId) {
log.debug(
{ sessionId: system.sessionId },
`Subscribed to existing session (${system.sessionId})`
);
socket.emit('subscribe', { session: system.sessionId });
if (sessionId) {
socket.emit('subscribe', { session: sessionId });
dispatch(
socketSubscribed({
sessionId: system.sessionId,
sessionId,
timestamp: getTimestamp(),
})
);
@ -101,7 +70,6 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
* Disconnect
*/
socket.on('disconnect', () => {
log.debug('Disconnected');
dispatch(socketDisconnected({ timestamp: getTimestamp() }));
});
@ -109,18 +77,6 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
* Invocation started
*/
socket.on('invocation_started', (data) => {
if (getState().system.canceledSession === data.graph_execution_state_id) {
log.trace(
{ data, sessionId: data.graph_execution_state_id },
`Ignored invocation started (${data.node.type}) for canceled session (${data.graph_execution_state_id})`
);
return;
}
log.info(
{ data, sessionId: data.graph_execution_state_id },
`Invocation started (${data.node.type})`
);
dispatch(invocationStarted({ data, timestamp: getTimestamp() }));
});
@ -128,18 +84,6 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
* Generator progress
*/
socket.on('generator_progress', (data) => {
if (getState().system.canceledSession === data.graph_execution_state_id) {
log.trace(
{ data, sessionId: data.graph_execution_state_id },
`Ignored generator progress (${data.node.type}) for canceled session (${data.graph_execution_state_id})`
);
return;
}
log.trace(
{ data, sessionId: data.graph_execution_state_id },
`Generator progress (${data.node.type})`
);
dispatch(generatorProgress({ data, timestamp: getTimestamp() }));
});
@ -147,10 +91,6 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
* Invocation error
*/
socket.on('invocation_error', (data) => {
log.error(
{ data, sessionId: data.graph_execution_state_id },
`Invocation error (${data.node.type})`
);
dispatch(invocationError({ data, timestamp: getTimestamp() }));
});
@ -158,19 +98,6 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
* Invocation complete
*/
socket.on('invocation_complete', (data) => {
log.info(
{ data, sessionId: data.graph_execution_state_id },
`Invocation complete (${data.node.type})`
);
const sessionId = data.graph_execution_state_id;
const { cancelType, isCancelScheduled } = getState().system;
// Handle scheduled cancelation
if (cancelType === 'scheduled' && isCancelScheduled) {
dispatch(sessionCanceled({ sessionId }));
}
dispatch(
invocationComplete({
data,
@ -183,10 +110,6 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
* Graph complete
*/
socket.on('graph_execution_state_complete', (data) => {
log.info(
{ data, sessionId: data.graph_execution_state_id },
`Graph execution state complete (${data.graph_execution_state_id})`
);
dispatch(graphExecutionStateComplete({ data, timestamp: getTimestamp() }));
});
};