Skip to content

Commit 73bed0d

Browse files
tidy(ui): prefer types from zod schemas for model attrs
1 parent 4070f26 commit 73bed0d

File tree

9 files changed

+16
-20
lines changed

9 files changed

+16
-20
lines changed

invokeai/frontend/web/src/features/metadata/parsing.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
zVideoDuration,
5050
zVideoResolution,
5151
} from 'features/controlLayers/store/types';
52-
import type { ModelIdentifierField } from 'features/nodes/types/common';
52+
import type { ModelIdentifierField, ModelType } from 'features/nodes/types/common';
5353
import { zModelIdentifierField } from 'features/nodes/types/common';
5454
import { zModelIdentifier } from 'features/nodes/types/v2/common';
5555
import { modelSelected } from 'features/parameters/store/actions';
@@ -108,7 +108,7 @@ import { useCallback, useEffect, useState } from 'react';
108108
import { useTranslation } from 'react-i18next';
109109
import { imagesApi } from 'services/api/endpoints/images';
110110
import { modelsApi } from 'services/api/endpoints/models';
111-
import type { AnyModelConfig, ModelType } from 'services/api/types';
111+
import type { AnyModelConfig } from 'services/api/types';
112112
import { assert } from 'tsafe';
113113
import z from 'zod';
114114

invokeai/frontend/web/src/features/modelManagerV2/subpanels/ModelManagerPanel/ModelBaseBadge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Badge } from '@invoke-ai/ui-library';
22
import { MODEL_BASE_TO_COLOR, MODEL_BASE_TO_SHORT_NAME } from 'features/modelManagerV2/models';
3+
import type { BaseModelType } from 'features/nodes/types/common';
34
import { memo } from 'react';
4-
import type { BaseModelType } from 'services/api/types';
55

66
type Props = {
77
base: BaseModelType;

invokeai/frontend/web/src/features/nodes/types/common.test-d.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type {
2-
BaseModelType,
32
BoardField,
43
Classification,
54
ColorField,
@@ -10,11 +9,12 @@ import type {
109
ModelIdentifierField,
1110
ProgressImage,
1211
SchedulerField,
13-
SubModelType,
1412
T2IAdapterField,
13+
zBaseModelType,
1514
zClipVariantType,
1615
zModelFormat,
1716
zModelVariantType,
17+
zSubModelType,
1818
} from 'features/nodes/types/common';
1919
import type { Invocation, S } from 'services/api/types';
2020
import type { Equals, Extends } from 'tsafe';
@@ -24,7 +24,8 @@ import type z from 'zod';
2424

2525
/**
2626
* These types originate from the server and are recreated as zod schemas manually, for use at runtime.
27-
* The tests ensure that the types are correctly recreated.
27+
* The tests ensure that the types are correctly recreated. If one of these tests fails, it means the zod
28+
* schema and the type have diverged and need to be reconciled - update the zod schema.
2829
*/
2930

3031
describe('Common types', () => {
@@ -40,8 +41,8 @@ describe('Common types', () => {
4041

4142
// Model component types
4243
test('ModelIdentifier', () => assert<Equals<ModelIdentifierField, S['ModelIdentifierField']>>());
43-
test('ModelIdentifier', () => assert<Equals<BaseModelType, S['BaseModelType']>>());
44-
test('ModelIdentifier', () => assert<Equals<SubModelType, S['SubModelType']>>());
44+
test('ModelIdentifier', () => assert<Equals<z.infer<typeof zBaseModelType>, S['BaseModelType']>>());
45+
test('ModelIdentifier', () => assert<Equals<z.infer<typeof zSubModelType>, S['SubModelType']>>());
4546
test('ClipVariantType', () => assert<Equals<z.infer<typeof zClipVariantType>, S['ClipVariantType']>>());
4647
test('ModelVariantType', () => assert<Equals<z.infer<typeof zModelVariantType>, S['ModelVariantType']>>());
4748
test('ModelFormat', () => assert<Equals<z.infer<typeof zModelFormat>, S['ModelFormat']>>());

invokeai/frontend/web/src/features/nodes/types/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const zModelType = z.enum([
130130
'unknown',
131131
]);
132132
export type ModelType = z.infer<typeof zModelType>;
133-
const zSubModelType = z.enum([
133+
export const zSubModelType = z.enum([
134134
'unet',
135135
'transformer',
136136
'text_encoder',

invokeai/frontend/web/src/features/nodes/util/graph/buildLinearBatchConfig.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { generateSeeds } from 'common/util/generateSeeds';
33
import { range } from 'es-toolkit/compat';
44
import type { SeedBehaviour } from 'features/dynamicPrompts/store/dynamicPromptsSlice';
55
import { API_BASE_MODELS, VIDEO_BASE_MODELS } from 'features/modelManagerV2/models';
6+
import type { BaseModelType } from 'features/nodes/types/common';
67
import type { Graph } from 'features/nodes/util/graph/generation/Graph';
78
import type { components } from 'services/api/schema';
8-
import type { BaseModelType, Batch, EnqueueBatchArg, Invocation } from 'services/api/types';
9+
import type { Batch, EnqueueBatchArg, Invocation } from 'services/api/types';
910

1011
const getExtendedPrompts = (arg: {
1112
seedBehaviour: SeedBehaviour;

invokeai/frontend/web/src/features/parameters/components/ModelPicker.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
} from 'features/modelManagerV2/models';
3333
import { setInstallModelsTabByName } from 'features/modelManagerV2/store/installModelsStore';
3434
import ModelImage from 'features/modelManagerV2/subpanels/ModelManagerPanel/ModelImage';
35+
import type { BaseModelType } from 'features/nodes/types/common';
3536
import { NavigateToModelManagerButton } from 'features/parameters/components/MainModel/NavigateToModelManagerButton';
3637
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
3738
import { selectIsModelsTabDisabled } from 'features/system/store/configSlice';
@@ -41,7 +42,7 @@ import { memo, useCallback, useMemo, useRef } from 'react';
4142
import { Trans, useTranslation } from 'react-i18next';
4243
import { PiCaretDownBold, PiLinkSimple } from 'react-icons/pi';
4344
import { useGetRelatedModelIdsBatchQuery } from 'services/api/endpoints/modelRelationships';
44-
import type { AnyModelConfig, BaseModelType } from 'services/api/types';
45+
import type { AnyModelConfig } from 'services/api/types';
4546

4647
const selectSelectedModelKeys = createMemoizedSelector(selectParamsSlice, selectLoRAsSlice, (params, loras) => {
4748
const keys: string[] = [];

invokeai/frontend/web/src/features/parameters/types/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ComboboxOption } from '@invoke-ai/ui-library';
2-
import type { BaseModelType } from 'services/api/types';
2+
import type { BaseModelType } from 'features/nodes/types/common';
33

44
/**
55
* Mapping of base model to CLIP skip parameter constraints

invokeai/frontend/web/src/features/parameters/util/optimalDimension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { BaseModelType } from 'services/api/types';
1+
import type { BaseModelType } from 'features/nodes/types/common';
22

33
/**
44
* Gets the optimal dimension for a given base model:

invokeai/frontend/web/src/services/api/types.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,9 @@ export const isVideoDTO = (dto: ImageDTO | VideoDTO): dto is VideoDTO => {
105105
return 'video_id' in dto;
106106
};
107107

108-
// Models
109-
export type ModelType = S['ModelType'];
110-
export type BaseModelType = S['BaseModelType'];
111-
112108
// Model Configs
113-
114109
export type ControlLoRAModelConfig = S['ControlLoRALyCORISConfig'] | S['ControlLoRADiffusersConfig'];
115-
// TODO(MM2): Can we make key required in the pydantic model?
116110
export type LoRAModelConfig = S['LoRADiffusersConfig'] | S['LoRALyCORISConfig'] | S['LoRAOmiConfig'];
117-
// TODO(MM2): Can we rename this from Vae -> VAE
118111
export type VAEModelConfig = S['VAECheckpointConfig'] | S['VAEDiffusersConfig'];
119112
export type ControlNetModelConfig = S['ControlNetDiffusersConfig'] | S['ControlNetCheckpointConfig'];
120113
export type IPAdapterModelConfig = S['IPAdapterInvokeAIConfig'] | S['IPAdapterCheckpointConfig'];

0 commit comments

Comments
 (0)