chore(ui): rebuild api, update types

This commit is contained in:
psychedelicious
2023-04-11 21:19:14 +10:00
parent cf562f140c
commit 387e7f949a
14 changed files with 73 additions and 40 deletions

View File

@@ -48,7 +48,7 @@ export const buildImg2ImgNode = (
width,
height,
cfg_scale: cfgScale,
sampler_name: sampler as ImageToImageInvocation['sampler_name'],
scheduler: sampler as ImageToImageInvocation['scheduler'],
seamless,
model,
progress_images: shouldDisplayInProgressType === 'full-res',

View File

@@ -34,7 +34,7 @@ export const buildTxt2ImgNode = (
width,
height,
cfg_scale,
sampler_name: sampler as TextToImageInvocation['sampler_name'],
scheduler: sampler as TextToImageInvocation['scheduler'],
seamless,
model,
progress_images: shouldDisplayInProgressType === 'full-res',

View File

@@ -38,9 +38,9 @@ export type ImageToImageInvocation = {
*/
cfg_scale?: number;
/**
* The sampler to use
* The scheduler to use
*/
sampler_name?: 'ddim' | 'dpmpp_2' | 'k_dpm_2' | 'k_dpm_2_a' | 'k_dpmpp_2' | 'k_euler' | 'k_euler_a' | 'k_heun' | 'k_lms' | 'plms';
scheduler?: 'ddim' | 'dpmpp_2' | 'k_dpm_2' | 'k_dpm_2_a' | 'k_dpmpp_2' | 'k_euler' | 'k_euler_a' | 'k_heun' | 'k_lms' | 'plms';
/**
* Whether or not to generate an image that can tile without seams
*/

View File

@@ -38,9 +38,9 @@ export type InpaintInvocation = {
*/
cfg_scale?: number;
/**
* The sampler to use
* The scheduler to use
*/
sampler_name?: 'ddim' | 'dpmpp_2' | 'k_dpm_2' | 'k_dpm_2_a' | 'k_dpmpp_2' | 'k_euler' | 'k_euler_a' | 'k_heun' | 'k_lms' | 'plms';
scheduler?: 'ddim' | 'dpmpp_2' | 'k_dpm_2' | 'k_dpm_2_a' | 'k_dpmpp_2' | 'k_euler' | 'k_euler_a' | 'k_heun' | 'k_lms' | 'plms';
/**
* Whether or not to generate an image that can tile without seams
*/

View File

@@ -42,9 +42,9 @@ export type LatentsToLatentsInvocation = {
*/
cfg_scale?: number;
/**
* The sampler to use
* The scheduler to use
*/
sampler_name?: 'ddim' | 'dpmpp_2' | 'k_dpm_2' | 'k_dpm_2_a' | 'k_dpmpp_2' | 'k_euler' | 'k_euler_a' | 'k_heun' | 'k_lms' | 'plms';
scheduler?: 'ddim' | 'dpmpp_2' | 'k_dpm_2' | 'k_dpm_2_a' | 'k_dpmpp_2' | 'k_euler' | 'k_euler_a' | 'k_heun' | 'k_lms' | 'plms';
/**
* Whether or not to generate an image that can tile without seams
*/

View File

@@ -36,9 +36,9 @@ export type TextToImageInvocation = {
*/
cfg_scale?: number;
/**
* The sampler to use
* The scheduler to use
*/
sampler_name?: 'ddim' | 'dpmpp_2' | 'k_dpm_2' | 'k_dpm_2_a' | 'k_dpmpp_2' | 'k_euler' | 'k_euler_a' | 'k_heun' | 'k_lms' | 'plms';
scheduler?: 'ddim' | 'dpmpp_2' | 'k_dpm_2' | 'k_dpm_2_a' | 'k_dpmpp_2' | 'k_euler' | 'k_euler_a' | 'k_heun' | 'k_lms' | 'plms';
/**
* Whether or not to generate an image that can tile without seams
*/

View File

@@ -42,9 +42,9 @@ export type TextToLatentsInvocation = {
*/
cfg_scale?: number;
/**
* The sampler to use
* The scheduler to use
*/
sampler_name?: 'ddim' | 'dpmpp_2' | 'k_dpm_2' | 'k_dpm_2_a' | 'k_dpmpp_2' | 'k_euler' | 'k_euler_a' | 'k_heun' | 'k_lms' | 'plms';
scheduler?: 'ddim' | 'dpmpp_2' | 'k_dpm_2' | 'k_dpm_2_a' | 'k_dpmpp_2' | 'k_euler' | 'k_euler_a' | 'k_heun' | 'k_lms' | 'plms';
/**
* Whether or not to generate an image that can tile without seams
*/

View File

@@ -40,7 +40,7 @@ export const $ImageToImageInvocation = {
type: 'number',
description: `The Classifier-Free Guidance, higher values may result in a result closer to the prompt`,
},
sampler_name: {
scheduler: {
type: 'Enum',
},
seamless: {

View File

@@ -40,7 +40,7 @@ export const $InpaintInvocation = {
type: 'number',
description: `The Classifier-Free Guidance, higher values may result in a result closer to the prompt`,
},
sampler_name: {
scheduler: {
type: 'Enum',
},
seamless: {

View File

@@ -47,7 +47,7 @@ export const $LatentsToLatentsInvocation = {
type: 'number',
description: `The Classifier-Free Guidance, higher values may result in a result closer to the prompt`,
},
sampler_name: {
scheduler: {
type: 'Enum',
},
seamless: {

View File

@@ -40,7 +40,7 @@ export const $TextToImageInvocation = {
type: 'number',
description: `The Classifier-Free Guidance, higher values may result in a result closer to the prompt`,
},
sampler_name: {
scheduler: {
type: 'Enum',
},
seamless: {

View File

@@ -47,7 +47,7 @@ export const $TextToLatentsInvocation = {
type: 'number',
description: `The Classifier-Free Guidance, higher values may result in a result closer to the prompt`,
},
sampler_name: {
scheduler: {
type: 'Enum',
},
seamless: {

View File

@@ -1,11 +1,9 @@
import { Middleware, MiddlewareAPI } from '@reduxjs/toolkit';
import { io } from 'socket.io-client';
import { io, Socket } from 'socket.io-client';
import {
GeneratorProgressEvent,
InvocationCompleteEvent,
InvocationErrorEvent,
InvocationStartedEvent,
ClientToServerEvents,
ServerToClientEvents,
} from 'services/events/types';
import {
generatorProgress,
@@ -36,25 +34,31 @@ import { receivedOpenAPISchema } from 'services/thunks/schema';
export const socketMiddleware = () => {
let areListenersSet = false;
let socket_url = `ws://${window.location.host}`;
let socketUrl = `ws://${window.location.host}`;
const socketOptions: Parameters<typeof io>[0] = {
timeout: 60000,
path: '/ws/socket.io',
autoConnect: false, // achtung! removing this breaks the dynamic middleware
};
// if building in package mode, replace socket url with open api base url minus the http protocol
if (import.meta.env.MODE === 'package') {
if (['nodes', 'package'].includes(import.meta.env.MODE)) {
if (OpenAPI.BASE) {
//eslint-disable-next-line
socket_url = OpenAPI.BASE.replace(/^https?\:\/\//i, '');
socketUrl = OpenAPI.BASE.replace(/^https?\:\/\//i, '');
}
if (OpenAPI.TOKEN) {
// TODO: handle providing jwt to socket.io
socketOptions.auth = { token: OpenAPI.TOKEN };
}
}
const socket = io(socket_url, {
timeout: 60000,
path: '/ws/socket.io',
autoConnect: false, // achtung! removing this breaks the dynamic middleware
});
const socket: Socket<ServerToClientEvents, ClientToServerEvents> = io(
socketUrl,
socketOptions
);
const middleware: Middleware =
(store: MiddlewareAPI<AppDispatch, RootState>) => (next) => (action) => {
@@ -65,7 +69,7 @@ export const socketMiddleware = () => {
const { sessionId } = getState().system;
if (sessionId) {
socket.emit('unsubscribe', { sessionId });
socket.emit('unsubscribe', { session: sessionId });
dispatch(
socketUnsubscribed({ sessionId, timestamp: getTimestamp() })
);
@@ -119,11 +123,11 @@ export const socketMiddleware = () => {
// Everything else only happens once we have created a session
if (isFulfilledSessionCreatedAction(action)) {
const oldSessionId = getState().system.sessionId;
const subscribedNodeIds = getState().system.subscribedNodeIds;
// temp disable this
// temp disable event subscription
const shouldHandleEvent = (id: string): boolean => true;
// const subscribedNodeIds = getState().system.subscribedNodeIds;
// const shouldHandleEvent = (id: string): boolean => {
// if (subscribedNodeIds.length === 1 && subscribedNodeIds[0] === '*') {
// return true;
@@ -145,13 +149,17 @@ export const socketMiddleware = () => {
})
);
// Remove listeners for these events; we need to set them up fresh whenever we subscribe
[
const listenersToRemove: (keyof ServerToClientEvents)[] = [
'invocation_started',
'generator_progress',
'invocation_error',
'invocation_complete',
].forEach((event) => socket.removeAllListeners(event));
];
// Remove listeners for these events; we need to set them up fresh whenever we subscribe
listenersToRemove.forEach((event: keyof ServerToClientEvents) => {
socket.removeAllListeners(event);
});
}
const sessionId = action.payload.id;
@@ -168,25 +176,25 @@ export const socketMiddleware = () => {
);
// Set up listeners for the present subscription
socket.on('invocation_started', (data: InvocationStartedEvent) => {
socket.on('invocation_started', (data) => {
if (shouldHandleEvent(data.source_id)) {
dispatch(invocationStarted({ data, timestamp: getTimestamp() }));
}
});
socket.on('generator_progress', (data: GeneratorProgressEvent) => {
socket.on('generator_progress', (data) => {
if (shouldHandleEvent(data.source_id)) {
dispatch(generatorProgress({ data, timestamp: getTimestamp() }));
}
});
socket.on('invocation_error', (data: InvocationErrorEvent) => {
socket.on('invocation_error', (data) => {
if (shouldHandleEvent(data.source_id)) {
dispatch(invocationError({ data, timestamp: getTimestamp() }));
}
});
socket.on('invocation_complete', (data: InvocationCompleteEvent) => {
socket.on('invocation_complete', (data) => {
if (shouldHandleEvent(data.source_id)) {
const sessionId = data.graph_execution_state_id;

View File

@@ -73,3 +73,28 @@ export type InvocationStartedEvent = {
export type GraphExecutionStateCompleteEvent = {
graph_execution_state_id: string;
};
export type ClientEmitSubscribe = {
session: string;
};
export type ClientEmitUnsubscribe = {
session: string;
};
export type ServerToClientEvents = {
generator_progress: (payload: GeneratorProgressEvent) => void;
invocation_complete: (payload: InvocationCompleteEvent) => void;
invocation_error: (payload: InvocationErrorEvent) => void;
invocation_started: (payload: InvocationStartedEvent) => void;
graph_execution_state_complete: (
payload: GraphExecutionStateCompleteEvent
) => void;
};
export type ClientToServerEvents = {
connect: () => void;
disconnect: () => void;
subscribe: (payload: ClientEmitSubscribe) => void;
unsubscribe: (payload: ClientEmitUnsubscribe) => void;
};