diff --git a/invokeai/frontend/web/src/services/api/core/CancelablePromise.ts b/invokeai/frontend/web/src/services/api/core/CancelablePromise.ts index b923479fea..a0f92e01b7 100644 --- a/invokeai/frontend/web/src/services/api/core/CancelablePromise.ts +++ b/invokeai/frontend/web/src/services/api/core/CancelablePromise.ts @@ -22,15 +22,13 @@ export interface OnCancel { } export class CancelablePromise implements Promise { - readonly [Symbol.toStringTag]!: string; - - private _isResolved: boolean; - private _isRejected: boolean; - private _isCancelled: boolean; - private readonly _cancelHandlers: (() => void)[]; - private readonly _promise: Promise; - private _resolve?: (value: T | PromiseLike) => void; - private _reject?: (reason?: any) => void; + #isResolved: boolean; + #isRejected: boolean; + #isCancelled: boolean; + readonly #cancelHandlers: (() => void)[]; + readonly #promise: Promise; + #resolve?: (value: T | PromiseLike) => void; + #reject?: (reason?: any) => void; constructor( executor: ( @@ -39,78 +37,82 @@ export class CancelablePromise implements Promise { onCancel: OnCancel ) => void ) { - this._isResolved = false; - this._isRejected = false; - this._isCancelled = false; - this._cancelHandlers = []; - this._promise = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; + this.#isResolved = false; + this.#isRejected = false; + this.#isCancelled = false; + this.#cancelHandlers = []; + this.#promise = new Promise((resolve, reject) => { + this.#resolve = resolve; + this.#reject = reject; const onResolve = (value: T | PromiseLike): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { + if (this.#isResolved || this.#isRejected || this.#isCancelled) { return; } - this._isResolved = true; - this._resolve?.(value); + this.#isResolved = true; + this.#resolve?.(value); }; const onReject = (reason?: any): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { + if (this.#isResolved || this.#isRejected || this.#isCancelled) { return; } - this._isRejected = true; - this._reject?.(reason); + this.#isRejected = true; + this.#reject?.(reason); }; const onCancel = (cancelHandler: () => void): void => { - if (this._isResolved || this._isRejected || this._isCancelled) { + if (this.#isResolved || this.#isRejected || this.#isCancelled) { return; } - this._cancelHandlers.push(cancelHandler); + this.#cancelHandlers.push(cancelHandler); }; Object.defineProperty(onCancel, 'isResolved', { - get: (): boolean => this._isResolved, + get: (): boolean => this.#isResolved, }); Object.defineProperty(onCancel, 'isRejected', { - get: (): boolean => this._isRejected, + get: (): boolean => this.#isRejected, }); Object.defineProperty(onCancel, 'isCancelled', { - get: (): boolean => this._isCancelled, + get: (): boolean => this.#isCancelled, }); return executor(onResolve, onReject, onCancel as OnCancel); }); } + get [Symbol.toStringTag]() { + return "Cancellable Promise"; + } + public then( onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, onRejected?: ((reason: any) => TResult2 | PromiseLike) | null ): Promise { - return this._promise.then(onFulfilled, onRejected); + return this.#promise.then(onFulfilled, onRejected); } public catch( onRejected?: ((reason: any) => TResult | PromiseLike) | null ): Promise { - return this._promise.catch(onRejected); + return this.#promise.catch(onRejected); } public finally(onFinally?: (() => void) | null): Promise { - return this._promise.finally(onFinally); + return this.#promise.finally(onFinally); } public cancel(): void { - if (this._isResolved || this._isRejected || this._isCancelled) { + if (this.#isResolved || this.#isRejected || this.#isCancelled) { return; } - this._isCancelled = true; - if (this._cancelHandlers.length) { + this.#isCancelled = true; + if (this.#cancelHandlers.length) { try { - for (const cancelHandler of this._cancelHandlers) { + for (const cancelHandler of this.#cancelHandlers) { cancelHandler(); } } catch (error) { @@ -118,11 +120,11 @@ export class CancelablePromise implements Promise { return; } } - this._cancelHandlers.length = 0; - this._reject?.(new CancelError('Request aborted')); + this.#cancelHandlers.length = 0; + this.#reject?.(new CancelError('Request aborted')); } public get isCancelled(): boolean { - return this._isCancelled; + return this.#isCancelled; } } diff --git a/invokeai/frontend/web/src/services/api/index.ts b/invokeai/frontend/web/src/services/api/index.ts index f1b84f8465..2a34837715 100644 --- a/invokeai/frontend/web/src/services/api/index.ts +++ b/invokeai/frontend/web/src/services/api/index.ts @@ -58,7 +58,9 @@ export type { PasteImageInvocation } from './models/PasteImageInvocation'; export type { PromptOutput } from './models/PromptOutput'; export type { RandomRangeInvocation } from './models/RandomRangeInvocation'; export type { RangeInvocation } from './models/RangeInvocation'; +export type { ResizeLatentsInvocation } from './models/ResizeLatentsInvocation'; export type { RestoreFaceInvocation } from './models/RestoreFaceInvocation'; +export type { ScaleLatentsInvocation } from './models/ScaleLatentsInvocation'; export type { ShowImageInvocation } from './models/ShowImageInvocation'; export type { SubtractInvocation } from './models/SubtractInvocation'; export type { TextToImageInvocation } from './models/TextToImageInvocation'; @@ -119,7 +121,9 @@ export { $PasteImageInvocation } from './schemas/$PasteImageInvocation'; export { $PromptOutput } from './schemas/$PromptOutput'; export { $RandomRangeInvocation } from './schemas/$RandomRangeInvocation'; export { $RangeInvocation } from './schemas/$RangeInvocation'; +export { $ResizeLatentsInvocation } from './schemas/$ResizeLatentsInvocation'; export { $RestoreFaceInvocation } from './schemas/$RestoreFaceInvocation'; +export { $ScaleLatentsInvocation } from './schemas/$ScaleLatentsInvocation'; export { $ShowImageInvocation } from './schemas/$ShowImageInvocation'; export { $SubtractInvocation } from './schemas/$SubtractInvocation'; export { $TextToImageInvocation } from './schemas/$TextToImageInvocation'; diff --git a/invokeai/frontend/web/src/services/api/models/Graph.ts b/invokeai/frontend/web/src/services/api/models/Graph.ts index 1e590e4ba9..57a9178290 100644 --- a/invokeai/frontend/web/src/services/api/models/Graph.ts +++ b/invokeai/frontend/web/src/services/api/models/Graph.ts @@ -25,7 +25,9 @@ import type { ParamIntInvocation } from './ParamIntInvocation'; import type { PasteImageInvocation } from './PasteImageInvocation'; import type { RandomRangeInvocation } from './RandomRangeInvocation'; import type { RangeInvocation } from './RangeInvocation'; +import type { ResizeLatentsInvocation } from './ResizeLatentsInvocation'; import type { RestoreFaceInvocation } from './RestoreFaceInvocation'; +import type { ScaleLatentsInvocation } from './ScaleLatentsInvocation'; import type { ShowImageInvocation } from './ShowImageInvocation'; import type { SubtractInvocation } from './SubtractInvocation'; import type { TextToImageInvocation } from './TextToImageInvocation'; @@ -40,7 +42,7 @@ export type Graph = { /** * The nodes in this graph */ - nodes?: Record; + nodes?: Record; /** * The connections between nodes and their fields in this graph */ diff --git a/invokeai/frontend/web/src/services/api/models/LatentsToLatentsInvocation.ts b/invokeai/frontend/web/src/services/api/models/LatentsToLatentsInvocation.ts index 8210f01bb6..d04885bf85 100644 --- a/invokeai/frontend/web/src/services/api/models/LatentsToLatentsInvocation.ts +++ b/invokeai/frontend/web/src/services/api/models/LatentsToLatentsInvocation.ts @@ -17,10 +17,6 @@ export type LatentsToLatentsInvocation = { * The prompt to generate an image from */ prompt?: string; - /** - * The seed to use (-1 for a random seed) - */ - seed?: number; /** * The noise to use */ @@ -29,14 +25,6 @@ export type LatentsToLatentsInvocation = { * The number of steps to use to generate the image */ steps?: number; - /** - * The width of the resulting image - */ - width?: number; - /** - * The height of the resulting image - */ - height?: number; /** * The Classifier-Free Guidance, higher values may result in a result closer to the prompt */ diff --git a/invokeai/frontend/web/src/services/api/models/ResizeLatentsInvocation.ts b/invokeai/frontend/web/src/services/api/models/ResizeLatentsInvocation.ts new file mode 100644 index 0000000000..c0fabb4984 --- /dev/null +++ b/invokeai/frontend/web/src/services/api/models/ResizeLatentsInvocation.ts @@ -0,0 +1,37 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import type { LatentsField } from './LatentsField'; + +/** + * Resizes latents to explicit width/height (in pixels). Provided dimensions are floor-divided by 8. + */ +export type ResizeLatentsInvocation = { + /** + * The id of this node. Must be unique among all nodes. + */ + id: string; + type?: 'lresize'; + /** + * The latents to resize + */ + latents?: LatentsField; + /** + * The width to resize to (px) + */ + width: number; + /** + * The height to resize to (px) + */ + height: number; + /** + * The interpolation mode + */ + mode?: 'nearest' | 'linear' | 'bilinear' | 'bicubic' | 'trilinear' | 'area' | 'nearest-exact'; + /** + * Whether or not to antialias (applied in bilinear and bicubic modes only) + */ + antialias?: boolean; +}; + diff --git a/invokeai/frontend/web/src/services/api/models/ScaleLatentsInvocation.ts b/invokeai/frontend/web/src/services/api/models/ScaleLatentsInvocation.ts new file mode 100644 index 0000000000..f398eaf408 --- /dev/null +++ b/invokeai/frontend/web/src/services/api/models/ScaleLatentsInvocation.ts @@ -0,0 +1,33 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import type { LatentsField } from './LatentsField'; + +/** + * Scales latents by a given factor. + */ +export type ScaleLatentsInvocation = { + /** + * The id of this node. Must be unique among all nodes. + */ + id: string; + type?: 'lscale'; + /** + * The latents to scale + */ + latents?: LatentsField; + /** + * The factor by which to scale the latents + */ + scale_factor: number; + /** + * The interpolation mode + */ + mode?: 'nearest' | 'linear' | 'bilinear' | 'bicubic' | 'trilinear' | 'area' | 'nearest-exact'; + /** + * Whether or not to antialias (applied in bilinear and bicubic modes only) + */ + antialias?: boolean; +}; + diff --git a/invokeai/frontend/web/src/services/api/models/TextToLatentsInvocation.ts b/invokeai/frontend/web/src/services/api/models/TextToLatentsInvocation.ts index 63754db163..217b917f18 100644 --- a/invokeai/frontend/web/src/services/api/models/TextToLatentsInvocation.ts +++ b/invokeai/frontend/web/src/services/api/models/TextToLatentsInvocation.ts @@ -17,10 +17,6 @@ export type TextToLatentsInvocation = { * The prompt to generate an image from */ prompt?: string; - /** - * The seed to use (-1 for a random seed) - */ - seed?: number; /** * The noise to use */ @@ -29,14 +25,6 @@ export type TextToLatentsInvocation = { * The number of steps to use to generate the image */ steps?: number; - /** - * The width of the resulting image - */ - width?: number; - /** - * The height of the resulting image - */ - height?: number; /** * The Classifier-Free Guidance, higher values may result in a result closer to the prompt */ diff --git a/invokeai/frontend/web/src/services/api/schemas/$Graph.ts b/invokeai/frontend/web/src/services/api/schemas/$Graph.ts index b431011ba6..6fd8117db8 100644 --- a/invokeai/frontend/web/src/services/api/schemas/$Graph.ts +++ b/invokeai/frontend/web/src/services/api/schemas/$Graph.ts @@ -33,6 +33,10 @@ export const $Graph = { type: 'TextToLatentsInvocation', }, { type: 'LatentsToImageInvocation', + }, { + type: 'ResizeLatentsInvocation', + }, { + type: 'ScaleLatentsInvocation', }, { type: 'AddInvocation', }, { diff --git a/invokeai/frontend/web/src/services/api/schemas/$LatentsToLatentsInvocation.ts b/invokeai/frontend/web/src/services/api/schemas/$LatentsToLatentsInvocation.ts index d27fdc7c1f..b20ee88a52 100644 --- a/invokeai/frontend/web/src/services/api/schemas/$LatentsToLatentsInvocation.ts +++ b/invokeai/frontend/web/src/services/api/schemas/$LatentsToLatentsInvocation.ts @@ -16,12 +16,6 @@ export const $LatentsToLatentsInvocation = { type: 'string', description: `The prompt to generate an image from`, }, - seed: { - type: 'number', - description: `The seed to use (-1 for a random seed)`, - maximum: 4294967295, - minimum: -1, - }, noise: { type: 'all-of', description: `The noise to use`, @@ -33,16 +27,6 @@ export const $LatentsToLatentsInvocation = { type: 'number', description: `The number of steps to use to generate the image`, }, - width: { - type: 'number', - description: `The width of the resulting image`, - multipleOf: 64, - }, - height: { - type: 'number', - description: `The height of the resulting image`, - multipleOf: 64, - }, cfg_scale: { type: 'number', description: `The Classifier-Free Guidance, higher values may result in a result closer to the prompt`, diff --git a/invokeai/frontend/web/src/services/api/schemas/$ResizeLatentsInvocation.ts b/invokeai/frontend/web/src/services/api/schemas/$ResizeLatentsInvocation.ts new file mode 100644 index 0000000000..2609b1a681 --- /dev/null +++ b/invokeai/frontend/web/src/services/api/schemas/$ResizeLatentsInvocation.ts @@ -0,0 +1,44 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ResizeLatentsInvocation = { + description: `Resizes latents to explicit width/height (in pixels). Provided dimensions are floor-divided by 8.`, + properties: { + id: { + type: 'string', + description: `The id of this node. Must be unique among all nodes.`, + isRequired: true, + }, + type: { + type: 'Enum', + }, + latents: { + type: 'all-of', + description: `The latents to resize`, + contains: [{ + type: 'LatentsField', + }], + }, + width: { + type: 'number', + description: `The width to resize to (px)`, + isRequired: true, + minimum: 64, + multipleOf: 8, + }, + height: { + type: 'number', + description: `The height to resize to (px)`, + isRequired: true, + minimum: 64, + multipleOf: 8, + }, + mode: { + type: 'Enum', + }, + antialias: { + type: 'boolean', + description: `Whether or not to antialias (applied in bilinear and bicubic modes only)`, + }, + }, +} as const; diff --git a/invokeai/frontend/web/src/services/api/schemas/$ScaleLatentsInvocation.ts b/invokeai/frontend/web/src/services/api/schemas/$ScaleLatentsInvocation.ts new file mode 100644 index 0000000000..8d4d15e2e8 --- /dev/null +++ b/invokeai/frontend/web/src/services/api/schemas/$ScaleLatentsInvocation.ts @@ -0,0 +1,35 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export const $ScaleLatentsInvocation = { + description: `Scales latents by a given factor.`, + properties: { + id: { + type: 'string', + description: `The id of this node. Must be unique among all nodes.`, + isRequired: true, + }, + type: { + type: 'Enum', + }, + latents: { + type: 'all-of', + description: `The latents to scale`, + contains: [{ + type: 'LatentsField', + }], + }, + scale_factor: { + type: 'number', + description: `The factor by which to scale the latents`, + isRequired: true, + }, + mode: { + type: 'Enum', + }, + antialias: { + type: 'boolean', + description: `Whether or not to antialias (applied in bilinear and bicubic modes only)`, + }, + }, +} as const; diff --git a/invokeai/frontend/web/src/services/api/schemas/$TextToLatentsInvocation.ts b/invokeai/frontend/web/src/services/api/schemas/$TextToLatentsInvocation.ts index 7b6dd155ca..06376824c6 100644 --- a/invokeai/frontend/web/src/services/api/schemas/$TextToLatentsInvocation.ts +++ b/invokeai/frontend/web/src/services/api/schemas/$TextToLatentsInvocation.ts @@ -16,12 +16,6 @@ export const $TextToLatentsInvocation = { type: 'string', description: `The prompt to generate an image from`, }, - seed: { - type: 'number', - description: `The seed to use (-1 for a random seed)`, - maximum: 4294967295, - minimum: -1, - }, noise: { type: 'all-of', description: `The noise to use`, @@ -33,16 +27,6 @@ export const $TextToLatentsInvocation = { type: 'number', description: `The number of steps to use to generate the image`, }, - width: { - type: 'number', - description: `The width of the resulting image`, - multipleOf: 64, - }, - height: { - type: 'number', - description: `The height of the resulting image`, - multipleOf: 64, - }, cfg_scale: { type: 'number', description: `The Classifier-Free Guidance, higher values may result in a result closer to the prompt`, diff --git a/invokeai/frontend/web/src/services/api/services/SessionsService.ts b/invokeai/frontend/web/src/services/api/services/SessionsService.ts index 269092c6d9..dad455fc80 100644 --- a/invokeai/frontend/web/src/services/api/services/SessionsService.ts +++ b/invokeai/frontend/web/src/services/api/services/SessionsService.ts @@ -27,7 +27,9 @@ import type { ParamIntInvocation } from '../models/ParamIntInvocation'; import type { PasteImageInvocation } from '../models/PasteImageInvocation'; import type { RandomRangeInvocation } from '../models/RandomRangeInvocation'; import type { RangeInvocation } from '../models/RangeInvocation'; +import type { ResizeLatentsInvocation } from '../models/ResizeLatentsInvocation'; import type { RestoreFaceInvocation } from '../models/RestoreFaceInvocation'; +import type { ScaleLatentsInvocation } from '../models/ScaleLatentsInvocation'; import type { ShowImageInvocation } from '../models/ShowImageInvocation'; import type { SubtractInvocation } from '../models/SubtractInvocation'; import type { TextToImageInvocation } from '../models/TextToImageInvocation'; @@ -142,7 +144,7 @@ export class SessionsService { * The id of the session */ sessionId: string, - requestBody: (LoadImageInvocation | ShowImageInvocation | CropImageInvocation | PasteImageInvocation | MaskFromAlphaInvocation | BlurInvocation | LerpInvocation | InverseLerpInvocation | NoiseInvocation | TextToLatentsInvocation | LatentsToImageInvocation | AddInvocation | SubtractInvocation | MultiplyInvocation | DivideInvocation | ParamIntInvocation | CvInpaintInvocation | RangeInvocation | RandomRangeInvocation | UpscaleInvocation | RestoreFaceInvocation | TextToImageInvocation | GraphInvocation | IterateInvocation | CollectInvocation | LatentsToLatentsInvocation | ImageToImageInvocation | InpaintInvocation), + requestBody: (LoadImageInvocation | ShowImageInvocation | CropImageInvocation | PasteImageInvocation | MaskFromAlphaInvocation | BlurInvocation | LerpInvocation | InverseLerpInvocation | NoiseInvocation | TextToLatentsInvocation | LatentsToImageInvocation | ResizeLatentsInvocation | ScaleLatentsInvocation | AddInvocation | SubtractInvocation | MultiplyInvocation | DivideInvocation | ParamIntInvocation | CvInpaintInvocation | RangeInvocation | RandomRangeInvocation | UpscaleInvocation | RestoreFaceInvocation | TextToImageInvocation | GraphInvocation | IterateInvocation | CollectInvocation | LatentsToLatentsInvocation | ImageToImageInvocation | InpaintInvocation), }): CancelablePromise { return __request(OpenAPI, { method: 'POST', @@ -179,7 +181,7 @@ export class SessionsService { * The path to the node in the graph */ nodePath: string, - requestBody: (LoadImageInvocation | ShowImageInvocation | CropImageInvocation | PasteImageInvocation | MaskFromAlphaInvocation | BlurInvocation | LerpInvocation | InverseLerpInvocation | NoiseInvocation | TextToLatentsInvocation | LatentsToImageInvocation | AddInvocation | SubtractInvocation | MultiplyInvocation | DivideInvocation | ParamIntInvocation | CvInpaintInvocation | RangeInvocation | RandomRangeInvocation | UpscaleInvocation | RestoreFaceInvocation | TextToImageInvocation | GraphInvocation | IterateInvocation | CollectInvocation | LatentsToLatentsInvocation | ImageToImageInvocation | InpaintInvocation), + requestBody: (LoadImageInvocation | ShowImageInvocation | CropImageInvocation | PasteImageInvocation | MaskFromAlphaInvocation | BlurInvocation | LerpInvocation | InverseLerpInvocation | NoiseInvocation | TextToLatentsInvocation | LatentsToImageInvocation | ResizeLatentsInvocation | ScaleLatentsInvocation | AddInvocation | SubtractInvocation | MultiplyInvocation | DivideInvocation | ParamIntInvocation | CvInpaintInvocation | RangeInvocation | RandomRangeInvocation | UpscaleInvocation | RestoreFaceInvocation | TextToImageInvocation | GraphInvocation | IterateInvocation | CollectInvocation | LatentsToLatentsInvocation | ImageToImageInvocation | InpaintInvocation), }): CancelablePromise { return __request(OpenAPI, { method: 'PUT',