From 240f4801db451373a53542b5be58966d8041a70a Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 27 Feb 2024 18:17:25 +1100 Subject: [PATCH] tidy(ui): clean up unused code 6 unused files --- .../src/features/nodes/types/v2/constants.ts | 80 ----------------- .../web/src/features/nodes/types/v2/error.ts | 58 ------------- .../src/features/nodes/types/v2/metadata.ts | 77 ----------------- .../src/features/nodes/types/v2/openapi.ts | 86 ------------------- 4 files changed, 301 deletions(-) delete mode 100644 invokeai/frontend/web/src/features/nodes/types/v2/constants.ts delete mode 100644 invokeai/frontend/web/src/features/nodes/types/v2/error.ts delete mode 100644 invokeai/frontend/web/src/features/nodes/types/v2/metadata.ts delete mode 100644 invokeai/frontend/web/src/features/nodes/types/v2/openapi.ts diff --git a/invokeai/frontend/web/src/features/nodes/types/v2/constants.ts b/invokeai/frontend/web/src/features/nodes/types/v2/constants.ts deleted file mode 100644 index 35ef9e9fd2..0000000000 --- a/invokeai/frontend/web/src/features/nodes/types/v2/constants.ts +++ /dev/null @@ -1,80 +0,0 @@ -import type { Node } from 'reactflow'; - -/** - * How long to wait before showing a tooltip when hovering a field handle. - */ -export const HANDLE_TOOLTIP_OPEN_DELAY = 500; - -/** - * The width of a node in the UI in pixels. - */ -export const NODE_WIDTH = 320; - -/** - * This class name is special - reactflow uses it to identify the drag handle of a node, - * applying the appropriate listeners to it. - */ -export const DRAG_HANDLE_CLASSNAME = 'node-drag-handle'; - -/** - * reactflow-specifc properties shared between all node types. - */ -export const SHARED_NODE_PROPERTIES: Partial = { - dragHandle: `.${DRAG_HANDLE_CLASSNAME}`, -}; - -/** - * Helper for getting the kind of a field. - */ -export const KIND_MAP = { - input: 'inputs' as const, - output: 'outputs' as const, -}; - -/** - * Model types' handles are rendered as squares in the UI. - */ -export const MODEL_TYPES = [ - 'IPAdapterModelField', - 'ControlNetModelField', - 'LoRAModelField', - 'MainModelField', - 'SDXLMainModelField', - 'SDXLRefinerModelField', - 'VaeModelField', - 'UNetField', - 'VaeField', - 'ClipField', - 'T2IAdapterModelField', - 'IPAdapterModelField', -]; - -/** - * Colors for each field type - applies to their handles and edges. - */ -export const FIELD_COLORS: { [key: string]: string } = { - BoardField: 'purple.500', - BooleanField: 'green.500', - ClipField: 'green.500', - ColorField: 'pink.300', - ConditioningField: 'cyan.500', - ControlField: 'teal.500', - ControlNetModelField: 'teal.500', - EnumField: 'blue.500', - FloatField: 'orange.500', - ImageField: 'purple.500', - IntegerField: 'red.500', - IPAdapterField: 'teal.500', - IPAdapterModelField: 'teal.500', - LatentsField: 'pink.500', - LoRAModelField: 'teal.500', - MainModelField: 'teal.500', - SDXLMainModelField: 'teal.500', - SDXLRefinerModelField: 'teal.500', - StringField: 'yellow.500', - T2IAdapterField: 'teal.500', - T2IAdapterModelField: 'teal.500', - UNetField: 'red.500', - VaeField: 'blue.500', - VaeModelField: 'teal.500', -}; diff --git a/invokeai/frontend/web/src/features/nodes/types/v2/error.ts b/invokeai/frontend/web/src/features/nodes/types/v2/error.ts deleted file mode 100644 index 905b487fb0..0000000000 --- a/invokeai/frontend/web/src/features/nodes/types/v2/error.ts +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Invalid Workflow Version Error - * Raised when a workflow version is not recognized. - */ -export class WorkflowVersionError extends Error { - /** - * Create WorkflowVersionError - * @param {String} message - */ - constructor(message: string) { - super(message); - this.name = this.constructor.name; - } -} -/** - * Workflow Migration Error - * Raised when a workflow migration fails. - */ -export class WorkflowMigrationError extends Error { - /** - * Create WorkflowMigrationError - * @param {String} message - */ - constructor(message: string) { - super(message); - this.name = this.constructor.name; - } -} - -/** - * Unable to Update Node Error - * Raised when a node cannot be updated. - */ -export class NodeUpdateError extends Error { - /** - * Create NodeUpdateError - * @param {String} message - */ - constructor(message: string) { - super(message); - this.name = this.constructor.name; - } -} - -/** - * FieldParseError - * Raised when a field cannot be parsed from a field schema. - */ -export class FieldParseError extends Error { - /** - * Create FieldTypeParseError - * @param {String} message - */ - constructor(message: string) { - super(message); - this.name = this.constructor.name; - } -} diff --git a/invokeai/frontend/web/src/features/nodes/types/v2/metadata.ts b/invokeai/frontend/web/src/features/nodes/types/v2/metadata.ts deleted file mode 100644 index 0cc30499e3..0000000000 --- a/invokeai/frontend/web/src/features/nodes/types/v2/metadata.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { z } from 'zod'; - -import { - zControlField, - zIPAdapterField, - zLoRAModelField, - zMainModelField, - zSDXLRefinerModelField, - zT2IAdapterField, - zVAEModelField, -} from './common'; - -// #region Metadata-optimized versions of schemas -// TODO: It's possible that `deepPartial` will be deprecated: -// - https://github.com/colinhacks/zod/issues/2106 -// - https://github.com/colinhacks/zod/issues/2854 -export const zLoRAMetadataItem = z.object({ - lora: zLoRAModelField.deepPartial(), - weight: z.number(), -}); -const zControlNetMetadataItem = zControlField.deepPartial(); -const zIPAdapterMetadataItem = zIPAdapterField.deepPartial(); -const zT2IAdapterMetadataItem = zT2IAdapterField.deepPartial(); -const zSDXLRefinerModelMetadataItem = zSDXLRefinerModelField.deepPartial(); -const zModelMetadataItem = zMainModelField.deepPartial(); -const zVAEModelMetadataItem = zVAEModelField.deepPartial(); -export type LoRAMetadataItem = z.infer; -export type ControlNetMetadataItem = z.infer; -export type IPAdapterMetadataItem = z.infer; -export type T2IAdapterMetadataItem = z.infer; -export type SDXLRefinerModelMetadataItem = z.infer; -export type ModelMetadataItem = z.infer; -export type VAEModelMetadataItem = z.infer; -// #endregion - -// #region CoreMetadata -export const zCoreMetadata = z - .object({ - app_version: z.string().nullish().catch(null), - generation_mode: z.string().nullish().catch(null), - created_by: z.string().nullish().catch(null), - positive_prompt: z.string().nullish().catch(null), - negative_prompt: z.string().nullish().catch(null), - width: z.number().int().nullish().catch(null), - height: z.number().int().nullish().catch(null), - seed: z.number().int().nullish().catch(null), - rand_device: z.string().nullish().catch(null), - cfg_scale: z.number().nullish().catch(null), - cfg_rescale_multiplier: z.number().nullish().catch(null), - steps: z.number().int().nullish().catch(null), - scheduler: z.string().nullish().catch(null), - clip_skip: z.number().int().nullish().catch(null), - model: zModelMetadataItem.nullish().catch(null), - controlnets: z.array(zControlNetMetadataItem).nullish().catch(null), - ipAdapters: z.array(zIPAdapterMetadataItem).nullish().catch(null), - t2iAdapters: z.array(zT2IAdapterMetadataItem).nullish().catch(null), - loras: z.array(zLoRAMetadataItem).nullish().catch(null), - vae: zVAEModelMetadataItem.nullish().catch(null), - strength: z.number().nullish().catch(null), - hrf_enabled: z.boolean().nullish().catch(null), - hrf_strength: z.number().nullish().catch(null), - hrf_method: z.string().nullish().catch(null), - init_image: z.string().nullish().catch(null), - positive_style_prompt: z.string().nullish().catch(null), - negative_style_prompt: z.string().nullish().catch(null), - refiner_model: zSDXLRefinerModelMetadataItem.nullish().catch(null), - refiner_cfg_scale: z.number().nullish().catch(null), - refiner_steps: z.number().int().nullish().catch(null), - refiner_scheduler: z.string().nullish().catch(null), - refiner_positive_aesthetic_score: z.number().nullish().catch(null), - refiner_negative_aesthetic_score: z.number().nullish().catch(null), - refiner_start: z.number().nullish().catch(null), - }) - .passthrough(); -export type CoreMetadata = z.infer; - -// #endregion diff --git a/invokeai/frontend/web/src/features/nodes/types/v2/openapi.ts b/invokeai/frontend/web/src/features/nodes/types/v2/openapi.ts deleted file mode 100644 index 83d774439a..0000000000 --- a/invokeai/frontend/web/src/features/nodes/types/v2/openapi.ts +++ /dev/null @@ -1,86 +0,0 @@ -import type { OpenAPIV3_1 } from 'openapi-types'; -import type { - InputFieldJSONSchemaExtra, - InvocationJSONSchemaExtra, - OutputFieldJSONSchemaExtra, -} from 'services/api/types'; - -// Janky customization of OpenAPI Schema :/ - -export type InvocationSchemaExtra = InvocationJSONSchemaExtra & { - output: OpenAPIV3_1.ReferenceObject; // the output of the invocation - title: string; - category?: string; - tags?: string[]; - version: string; - properties: Omit< - NonNullable & (InputFieldJSONSchemaExtra | OutputFieldJSONSchemaExtra), - 'type' - > & { - type: Omit & { - default: string; - }; - use_cache: Omit & { - default: boolean; - }; - }; -}; - -export type InvocationSchemaType = { - default: string; // the type of the invocation -}; - -export type InvocationBaseSchemaObject = Omit & - InvocationSchemaExtra; - -export type InvocationOutputSchemaObject = Omit & { - properties: OpenAPIV3_1.SchemaObject['properties'] & { - type: Omit & { - default: string; - }; - } & { - class: 'output'; - }; -}; - -export type InvocationFieldSchema = OpenAPIV3_1.SchemaObject & InputFieldJSONSchemaExtra; - -export type OpenAPIV3_1SchemaOrRef = OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject; - -export interface ArraySchemaObject extends InvocationBaseSchemaObject { - type: OpenAPIV3_1.ArraySchemaObjectType; - items: OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject; -} -export interface NonArraySchemaObject extends InvocationBaseSchemaObject { - type?: OpenAPIV3_1.NonArraySchemaObjectType; -} - -export type InvocationSchemaObject = (ArraySchemaObject | NonArraySchemaObject) & { class: 'invocation' }; - -export const isSchemaObject = ( - obj: OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject | undefined -): obj is OpenAPIV3_1.SchemaObject => Boolean(obj && !('$ref' in obj)); - -export const isArraySchemaObject = ( - obj: OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject | undefined -): obj is OpenAPIV3_1.ArraySchemaObject => Boolean(obj && !('$ref' in obj) && obj.type === 'array'); - -export const isNonArraySchemaObject = ( - obj: OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject | undefined -): obj is OpenAPIV3_1.NonArraySchemaObject => Boolean(obj && !('$ref' in obj) && obj.type !== 'array'); - -export const isRefObject = ( - obj: OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject | undefined -): obj is OpenAPIV3_1.ReferenceObject => Boolean(obj && '$ref' in obj); - -export const isInvocationSchemaObject = ( - obj: OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject | InvocationSchemaObject -): obj is InvocationSchemaObject => 'class' in obj && obj.class === 'invocation'; - -export const isInvocationOutputSchemaObject = ( - obj: OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject | InvocationOutputSchemaObject -): obj is InvocationOutputSchemaObject => 'class' in obj && obj.class === 'output'; - -export const isInvocationFieldSchema = ( - obj: OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject -): obj is InvocationFieldSchema => !('$ref' in obj);