Add more Zod types to api.ts (#440)

This commit is contained in:
Björn Söderqvist
2024-08-15 16:45:40 +02:00
committed by GitHub
parent 1ff7a70579
commit 775f536d30
11 changed files with 165 additions and 57 deletions

View File

@@ -1,6 +1,7 @@
import { ZodType, z } from 'zod'
import { zComfyWorkflow, zNodeId } from './comfyWorkflow'
import { fromZodError } from 'zod-validation-error'
import { colorPalettesSchema } from './colorPalette'
const zNodeType = z.string()
const zQueueIndex = z.number()
@@ -356,3 +357,83 @@ export function validateComfyNodeDef(
}
return result.data
}
const zEmbeddingsResponse = z.array(z.string())
const zExtensionsResponse = z.array(z.string())
const zPromptResponse = z.object({
node_errors: z.array(z.string()).optional(),
prompt_id: z.string().optional(),
exec_info: z
.object({
queue_remaining: z.number().optional()
})
.optional()
})
export const zSystemStats = z.object({
system: z.object({
os: z.string(),
python_version: z.string(),
embedded_python: z.boolean()
}),
devices: z.array(
z.object({
name: z.string(),
type: z.string(),
index: z.number().optional(),
vram_total: z.number(),
vram_free: z.number(),
torch_vram_total: z.number(),
torch_vram_free: z.number()
})
)
})
const zUser = z.object({
storage: z.enum(['server', 'browser']),
migrated: z.boolean(),
users: z.record(z.string(), z.unknown())
})
const zUserData = z.array(z.array(z.string(), z.string()))
const zSettings = z.record(z.any()).and(
z
.object({
'Comfy.ColorPalette': z.string(),
'Comfy.CustomColorPalettes': colorPalettesSchema,
'Comfy.ConfirmClear': z.boolean(),
'Comfy.DevMode': z.boolean(),
'Comfy.DisableFloatRounding': z.boolean(),
'Comfy.DisableSliders': z.boolean(),
'Comfy.DOMClippingEnabled': z.boolean(),
'Comfy.EditAttention.Delta': z.number(),
'Comfy.EnableTooltips': z.boolean(),
'Comfy.EnableWorkflowViewRestore': z.boolean(),
'Comfy.FloatRoundingPrecision': z.number(),
'Comfy.InvertMenuScrolling': z.boolean(),
'Comfy.Logging.Enabled': z.boolean(),
'Comfy.NodeInputConversionSubmenus': z.boolean(),
'Comfy.NodeSearchBoxImpl.LinkReleaseTrigger': z.enum([
'always',
'hold shift',
'NOT hold shift'
]),
'Comfy.NodeSearchBoxImpl.NodePreview': z.boolean(),
'Comfy.NodeSearchBoxImpl': z.enum(['default', 'simple']),
'Comfy.NodeSuggestions.number': z.number(),
'Comfy.PreviewFormat': z.string(),
'Comfy.PromptFilename': z.boolean(),
'Comfy.Sidebar.Location': z.enum(['left', 'right']),
'Comfy.Sidebar.Size': z.number(),
'Comfy.SwitchUser': z.any(),
'Comfy.SnapToGrid.GridSize': z.number(),
'Comfy.UseNewMenu': z.any(),
'Comfy.Validation.Workflows': z.boolean()
})
.optional()
)
export type EmbeddingsResponse = z.infer<typeof zEmbeddingsResponse>
export type ExtensionsResponse = z.infer<typeof zExtensionsResponse>
export type PromptResponse = z.infer<typeof zPromptResponse>
export type Settings = z.infer<typeof zSettings>
export type SystemStats = z.infer<typeof zSystemStats>
export type User = z.infer<typeof zUser>
export type UserData = z.infer<typeof zUserData>

View File

@@ -88,7 +88,7 @@ const paletteSchema = z.object({
colors: colorsSchema
})
const colorPalettesSchema = z.record(paletteSchema)
export const colorPalettesSchema = z.record(paletteSchema)
export type Colors = z.infer<typeof colorsSchema>
export type Palette = z.infer<typeof paletteSchema>

View File

@@ -1,3 +1,5 @@
import { Settings } from './apiTypes'
export type StorageLocation = 'browser' | 'server'
export type SettingInputType =
@@ -21,14 +23,14 @@ export interface SettingOption {
}
export interface Setting {
id: string
id: keyof Settings
onChange?: (value: any, oldValue?: any) => void
name: string
render: () => HTMLElement
}
export interface SettingParams {
id: string
id: keyof Settings
name: string
type: SettingInputType | SettingCustomRenderer
defaultValue: any