mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-12 16:40:05 +00:00
Apply new code format standard (#217)
This commit is contained in:
@@ -1,65 +1,65 @@
|
||||
import { ZodType, z } from "zod";
|
||||
import { zComfyWorkflow } from "./comfyWorkflow";
|
||||
import { fromZodError } from "zod-validation-error";
|
||||
import { ZodType, z } from 'zod'
|
||||
import { zComfyWorkflow } from './comfyWorkflow'
|
||||
import { fromZodError } from 'zod-validation-error'
|
||||
|
||||
const zNodeId = z.union([z.number(), z.string()]);
|
||||
const zNodeType = z.string();
|
||||
const zQueueIndex = z.number();
|
||||
const zPromptId = z.string();
|
||||
const zNodeId = z.union([z.number(), z.string()])
|
||||
const zNodeType = z.string()
|
||||
const zQueueIndex = z.number()
|
||||
const zPromptId = z.string()
|
||||
|
||||
const zPromptInputItem = z.object({
|
||||
inputs: z.record(z.string(), z.any()),
|
||||
class_type: zNodeType,
|
||||
});
|
||||
class_type: zNodeType
|
||||
})
|
||||
|
||||
const zPromptInputs = z.record(zPromptInputItem);
|
||||
const zPromptInputs = z.record(zPromptInputItem)
|
||||
|
||||
const zExtraPngInfo = z
|
||||
.object({
|
||||
workflow: zComfyWorkflow,
|
||||
workflow: zComfyWorkflow
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const zExtraData = z.object({
|
||||
extra_pnginfo: zExtraPngInfo,
|
||||
client_id: z.string(),
|
||||
});
|
||||
const zOutputsToExecute = z.array(zNodeId);
|
||||
client_id: z.string()
|
||||
})
|
||||
const zOutputsToExecute = z.array(zNodeId)
|
||||
|
||||
const zMessageDetailBase = z.object({
|
||||
prompt_id: zPromptId,
|
||||
timestamp: z.number(),
|
||||
});
|
||||
timestamp: z.number()
|
||||
})
|
||||
|
||||
const zExecutionStartMessage = z.tuple([
|
||||
z.literal("execution_start"),
|
||||
zMessageDetailBase,
|
||||
]);
|
||||
z.literal('execution_start'),
|
||||
zMessageDetailBase
|
||||
])
|
||||
|
||||
const zExecutionSuccessMessage = z.tuple([
|
||||
z.literal("execution_success"),
|
||||
zMessageDetailBase,
|
||||
]);
|
||||
z.literal('execution_success'),
|
||||
zMessageDetailBase
|
||||
])
|
||||
|
||||
const zExecutionCachedMessage = z.tuple([
|
||||
z.literal("execution_cached"),
|
||||
z.literal('execution_cached'),
|
||||
zMessageDetailBase.extend({
|
||||
nodes: z.array(zNodeId),
|
||||
}),
|
||||
]);
|
||||
nodes: z.array(zNodeId)
|
||||
})
|
||||
])
|
||||
|
||||
const zExecutionInterruptedMessage = z.tuple([
|
||||
z.literal("execution_interrupted"),
|
||||
z.literal('execution_interrupted'),
|
||||
zMessageDetailBase.extend({
|
||||
// InterruptProcessingException
|
||||
node_id: zNodeId,
|
||||
node_type: zNodeType,
|
||||
executed: z.array(zNodeId),
|
||||
}),
|
||||
]);
|
||||
executed: z.array(zNodeId)
|
||||
})
|
||||
])
|
||||
|
||||
const zExecutionErrorMessage = z.tuple([
|
||||
z.literal("execution_error"),
|
||||
z.literal('execution_error'),
|
||||
zMessageDetailBase.extend({
|
||||
node_id: zNodeId,
|
||||
node_type: zNodeType,
|
||||
@@ -69,154 +69,154 @@ const zExecutionErrorMessage = z.tuple([
|
||||
exception_type: z.string(),
|
||||
traceback: z.string(),
|
||||
current_inputs: z.any(),
|
||||
current_outputs: z.any(),
|
||||
}),
|
||||
]);
|
||||
current_outputs: z.any()
|
||||
})
|
||||
])
|
||||
|
||||
const zStatusMessage = z.union([
|
||||
zExecutionStartMessage,
|
||||
zExecutionSuccessMessage,
|
||||
zExecutionCachedMessage,
|
||||
zExecutionInterruptedMessage,
|
||||
zExecutionErrorMessage,
|
||||
]);
|
||||
zExecutionErrorMessage
|
||||
])
|
||||
|
||||
const zStatus = z.object({
|
||||
status_str: z.enum(["success", "error"]),
|
||||
status_str: z.enum(['success', 'error']),
|
||||
completed: z.boolean(),
|
||||
messages: z.array(zStatusMessage),
|
||||
});
|
||||
messages: z.array(zStatusMessage)
|
||||
})
|
||||
|
||||
// TODO: this is a placeholder
|
||||
const zOutput = z.any();
|
||||
const zOutput = z.any()
|
||||
|
||||
const zTaskPrompt = z.tuple([
|
||||
zQueueIndex,
|
||||
zPromptId,
|
||||
zPromptInputs,
|
||||
zExtraData,
|
||||
zOutputsToExecute,
|
||||
]);
|
||||
zOutputsToExecute
|
||||
])
|
||||
|
||||
const zRunningTaskItem = z.object({
|
||||
taskType: z.literal("Running"),
|
||||
taskType: z.literal('Running'),
|
||||
prompt: zTaskPrompt,
|
||||
// @Deprecated
|
||||
remove: z.object({
|
||||
name: z.literal("Cancel"),
|
||||
cb: z.function(),
|
||||
}),
|
||||
});
|
||||
name: z.literal('Cancel'),
|
||||
cb: z.function()
|
||||
})
|
||||
})
|
||||
|
||||
const zPendingTaskItem = z.object({
|
||||
taskType: z.literal("Pending"),
|
||||
prompt: zTaskPrompt,
|
||||
});
|
||||
taskType: z.literal('Pending'),
|
||||
prompt: zTaskPrompt
|
||||
})
|
||||
|
||||
const zTaskOutput = z.record(zNodeId, zOutput);
|
||||
const zTaskOutput = z.record(zNodeId, zOutput)
|
||||
|
||||
const zHistoryTaskItem = z.object({
|
||||
taskType: z.literal("History"),
|
||||
taskType: z.literal('History'),
|
||||
prompt: zTaskPrompt,
|
||||
status: zStatus.optional(),
|
||||
outputs: zTaskOutput,
|
||||
});
|
||||
outputs: zTaskOutput
|
||||
})
|
||||
|
||||
const zTaskItem = z.union([
|
||||
zRunningTaskItem,
|
||||
zPendingTaskItem,
|
||||
zHistoryTaskItem,
|
||||
]);
|
||||
zHistoryTaskItem
|
||||
])
|
||||
|
||||
const zTaskType = z.union([
|
||||
z.literal("Running"),
|
||||
z.literal("Pending"),
|
||||
z.literal("History"),
|
||||
]);
|
||||
z.literal('Running'),
|
||||
z.literal('Pending'),
|
||||
z.literal('History')
|
||||
])
|
||||
|
||||
export type TaskType = z.infer<typeof zTaskType>;
|
||||
export type TaskPrompt = z.infer<typeof zTaskPrompt>;
|
||||
export type TaskStatus = z.infer<typeof zStatus>;
|
||||
export type TaskOutput = z.infer<typeof zTaskOutput>;
|
||||
export type TaskType = z.infer<typeof zTaskType>
|
||||
export type TaskPrompt = z.infer<typeof zTaskPrompt>
|
||||
export type TaskStatus = z.infer<typeof zStatus>
|
||||
export type TaskOutput = z.infer<typeof zTaskOutput>
|
||||
|
||||
// `/queue`
|
||||
export type RunningTaskItem = z.infer<typeof zRunningTaskItem>;
|
||||
export type PendingTaskItem = z.infer<typeof zPendingTaskItem>;
|
||||
export type RunningTaskItem = z.infer<typeof zRunningTaskItem>
|
||||
export type PendingTaskItem = z.infer<typeof zPendingTaskItem>
|
||||
// `/history`
|
||||
export type HistoryTaskItem = z.infer<typeof zHistoryTaskItem>;
|
||||
export type TaskItem = z.infer<typeof zTaskItem>;
|
||||
export type HistoryTaskItem = z.infer<typeof zHistoryTaskItem>
|
||||
export type TaskItem = z.infer<typeof zTaskItem>
|
||||
|
||||
export function validateTaskItem(taskItem: unknown) {
|
||||
const result = zTaskItem.safeParse(taskItem);
|
||||
const result = zTaskItem.safeParse(taskItem)
|
||||
if (!result.success) {
|
||||
const zodError = fromZodError(result.error);
|
||||
const zodError = fromZodError(result.error)
|
||||
// TODO accept a callback to report error.
|
||||
console.warn(
|
||||
`Invalid TaskItem: ${JSON.stringify(taskItem)}\n${zodError.message}`
|
||||
);
|
||||
)
|
||||
}
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
function inputSpec(
|
||||
spec: [ZodType, ZodType],
|
||||
allowUpcast: boolean = true
|
||||
): ZodType {
|
||||
const [inputType, inputSpec] = spec;
|
||||
const [inputType, inputSpec] = spec
|
||||
// e.g. "INT" => ["INT", {}]
|
||||
const upcastTypes: ZodType[] = allowUpcast
|
||||
? [inputType.transform((type) => [type, {}])]
|
||||
: [];
|
||||
: []
|
||||
|
||||
return z.union([
|
||||
z.tuple([inputType, inputSpec]),
|
||||
z.tuple([inputType]).transform(([type]) => [type, {}]),
|
||||
...upcastTypes,
|
||||
]);
|
||||
...upcastTypes
|
||||
])
|
||||
}
|
||||
|
||||
const zIntInputSpec = inputSpec([
|
||||
z.literal("INT"),
|
||||
z.literal('INT'),
|
||||
z.object({
|
||||
min: z.number().optional(),
|
||||
max: z.number().optional(),
|
||||
step: z.number().optional(),
|
||||
default: z.number().optional(),
|
||||
forceInput: z.boolean().optional(),
|
||||
}),
|
||||
]);
|
||||
forceInput: z.boolean().optional()
|
||||
})
|
||||
])
|
||||
|
||||
const zFloatInputSpec = inputSpec([
|
||||
z.literal("FLOAT"),
|
||||
z.literal('FLOAT'),
|
||||
z.object({
|
||||
min: z.number().optional(),
|
||||
max: z.number().optional(),
|
||||
step: z.number().optional(),
|
||||
round: z.number().optional(),
|
||||
default: z.number().optional(),
|
||||
forceInput: z.boolean().optional(),
|
||||
}),
|
||||
]);
|
||||
forceInput: z.boolean().optional()
|
||||
})
|
||||
])
|
||||
|
||||
const zBooleanInputSpec = inputSpec([
|
||||
z.literal("BOOLEAN"),
|
||||
z.literal('BOOLEAN'),
|
||||
z.object({
|
||||
label_on: z.string().optional(),
|
||||
label_off: z.string().optional(),
|
||||
default: z.boolean().optional(),
|
||||
forceInput: z.boolean().optional(),
|
||||
}),
|
||||
]);
|
||||
forceInput: z.boolean().optional()
|
||||
})
|
||||
])
|
||||
|
||||
const zStringInputSpec = inputSpec([
|
||||
z.literal("STRING"),
|
||||
z.literal('STRING'),
|
||||
z.object({
|
||||
default: z.string().optional(),
|
||||
multiline: z.boolean().optional(),
|
||||
dynamicPrompts: z.boolean().optional(),
|
||||
forceInput: z.boolean().optional(),
|
||||
}),
|
||||
]);
|
||||
forceInput: z.boolean().optional()
|
||||
})
|
||||
])
|
||||
|
||||
// Dropdown Selection.
|
||||
const zComboInputSpec = inputSpec(
|
||||
@@ -226,19 +226,19 @@ const zComboInputSpec = inputSpec(
|
||||
default: z.any().optional(),
|
||||
control_after_generate: z.boolean().optional(),
|
||||
image_upload: z.boolean().optional(),
|
||||
forceInput: z.boolean().optional(),
|
||||
}),
|
||||
forceInput: z.boolean().optional()
|
||||
})
|
||||
],
|
||||
/* allowUpcast=*/ false
|
||||
);
|
||||
)
|
||||
|
||||
const zCustomInputSpec = inputSpec([
|
||||
z.string(),
|
||||
z.object({
|
||||
default: z.any().optional(),
|
||||
forceInput: z.boolean().optional(),
|
||||
}),
|
||||
]);
|
||||
forceInput: z.boolean().optional()
|
||||
})
|
||||
])
|
||||
|
||||
const zInputSpec = z.union([
|
||||
zIntInputSpec,
|
||||
@@ -246,14 +246,14 @@ const zInputSpec = z.union([
|
||||
zBooleanInputSpec,
|
||||
zStringInputSpec,
|
||||
zComboInputSpec,
|
||||
zCustomInputSpec,
|
||||
]);
|
||||
zCustomInputSpec
|
||||
])
|
||||
|
||||
const zComfyNodeDataType = z.string();
|
||||
const zComfyComboOutput = z.array(z.any());
|
||||
const zComfyNodeDataType = z.string()
|
||||
const zComfyComboOutput = z.array(z.any())
|
||||
const zComfyOutputSpec = z.array(
|
||||
z.union([zComfyNodeDataType, zComfyComboOutput])
|
||||
);
|
||||
)
|
||||
|
||||
const zComfyNodeDef = z.object({
|
||||
input: z.object({
|
||||
@@ -261,7 +261,7 @@ const zComfyNodeDef = z.object({
|
||||
optional: z.record(zInputSpec).optional(),
|
||||
// Frontend repo is not using it, but some custom nodes are using the
|
||||
// hidden field to pass various values.
|
||||
hidden: z.record(z.any()).optional(),
|
||||
hidden: z.record(z.any()).optional()
|
||||
}),
|
||||
output: zComfyOutputSpec,
|
||||
output_is_list: z.array(z.boolean()),
|
||||
@@ -271,23 +271,23 @@ const zComfyNodeDef = z.object({
|
||||
description: z.string(),
|
||||
category: z.string(),
|
||||
output_node: z.boolean(),
|
||||
python_module: z.string(),
|
||||
});
|
||||
python_module: z.string()
|
||||
})
|
||||
|
||||
// `/object_info`
|
||||
export type ComfyInputSpec = z.infer<typeof zInputSpec>;
|
||||
export type ComfyOutputSpec = z.infer<typeof zComfyOutputSpec>;
|
||||
export type ComfyNodeDef = z.infer<typeof zComfyNodeDef>;
|
||||
export type ComfyInputSpec = z.infer<typeof zInputSpec>
|
||||
export type ComfyOutputSpec = z.infer<typeof zComfyOutputSpec>
|
||||
export type ComfyNodeDef = z.infer<typeof zComfyNodeDef>
|
||||
|
||||
export function validateComfyNodeDef(data: any): ComfyNodeDef {
|
||||
const result = zComfyNodeDef.safeParse(data);
|
||||
const result = zComfyNodeDef.safeParse(data)
|
||||
if (!result.success) {
|
||||
const zodError = fromZodError(result.error);
|
||||
const zodError = fromZodError(result.error)
|
||||
const error = new Error(
|
||||
`Invalid ComfyNodeDef: ${JSON.stringify(data)}\n${zodError.message}`
|
||||
);
|
||||
error.cause = zodError;
|
||||
throw error;
|
||||
)
|
||||
error.cause = zodError
|
||||
throw error
|
||||
}
|
||||
return result.data;
|
||||
return result.data
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { z } from "zod";
|
||||
import { z } from 'zod'
|
||||
|
||||
const nodeSlotSchema = z
|
||||
.object({
|
||||
@@ -26,9 +26,9 @@ const nodeSlotSchema = z
|
||||
TAESD: z.string(),
|
||||
TIMESTEP_KEYFRAME: z.string().optional(),
|
||||
UPSCALE_MODEL: z.string().optional(),
|
||||
VAE: z.string(),
|
||||
VAE: z.string()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const litegraphBaseSchema = z
|
||||
.object({
|
||||
@@ -52,44 +52,44 @@ const litegraphBaseSchema = z
|
||||
WIDGET_SECONDARY_TEXT_COLOR: z.string(),
|
||||
LINK_COLOR: z.string(),
|
||||
EVENT_LINK_COLOR: z.string(),
|
||||
CONNECTING_LINK_COLOR: z.string(),
|
||||
CONNECTING_LINK_COLOR: z.string()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const comfyBaseSchema = z.object({
|
||||
["fg-color"]: z.string(),
|
||||
["bg-color"]: z.string(),
|
||||
["comfy-menu-bg"]: z.string(),
|
||||
["comfy-input-bg"]: z.string(),
|
||||
["input-text"]: z.string(),
|
||||
["descrip-text"]: z.string(),
|
||||
["drag-text"]: z.string(),
|
||||
["error-text"]: z.string(),
|
||||
["border-color"]: z.string(),
|
||||
["tr-even-bg-color"]: z.string(),
|
||||
["tr-odd-bg-color"]: z.string(),
|
||||
["content-bg"]: z.string(),
|
||||
["content-fg"]: z.string(),
|
||||
["content-hover-bg"]: z.string(),
|
||||
["content-hover-fg"]: z.string(),
|
||||
});
|
||||
['fg-color']: z.string(),
|
||||
['bg-color']: z.string(),
|
||||
['comfy-menu-bg']: z.string(),
|
||||
['comfy-input-bg']: z.string(),
|
||||
['input-text']: z.string(),
|
||||
['descrip-text']: z.string(),
|
||||
['drag-text']: z.string(),
|
||||
['error-text']: z.string(),
|
||||
['border-color']: z.string(),
|
||||
['tr-even-bg-color']: z.string(),
|
||||
['tr-odd-bg-color']: z.string(),
|
||||
['content-bg']: z.string(),
|
||||
['content-fg']: z.string(),
|
||||
['content-hover-bg']: z.string(),
|
||||
['content-hover-fg']: z.string()
|
||||
})
|
||||
|
||||
const colorsSchema = z
|
||||
.object({
|
||||
node_slot: nodeSlotSchema,
|
||||
litegraph_base: litegraphBaseSchema,
|
||||
comfy_base: comfyBaseSchema,
|
||||
comfy_base: comfyBaseSchema
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const paletteSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
colors: colorsSchema,
|
||||
});
|
||||
colors: colorsSchema
|
||||
})
|
||||
|
||||
const colorPalettesSchema = z.record(paletteSchema);
|
||||
const colorPalettesSchema = z.record(paletteSchema)
|
||||
|
||||
export type Colors = z.infer<typeof colorsSchema>;
|
||||
export type Palette = z.infer<typeof paletteSchema>;
|
||||
export type ColorPalettes = z.infer<typeof colorPalettesSchema>;
|
||||
export type Colors = z.infer<typeof colorsSchema>
|
||||
export type Palette = z.infer<typeof paletteSchema>
|
||||
export type ColorPalettes = z.infer<typeof colorPalettesSchema>
|
||||
|
||||
44
src/types/comfy.d.ts
vendored
44
src/types/comfy.d.ts
vendored
@@ -1,21 +1,21 @@
|
||||
import { LGraphNode, IWidget } from "./litegraph";
|
||||
import { ComfyApp } from "../../scripts/app";
|
||||
import { LGraphNode, IWidget } from './litegraph'
|
||||
import { ComfyApp } from '../../scripts/app'
|
||||
|
||||
export interface ComfyExtension {
|
||||
/**
|
||||
* The name of the extension
|
||||
*/
|
||||
name: string;
|
||||
name: string
|
||||
/**
|
||||
* Allows any initialisation, e.g. loading resources. Called after the canvas is created but before nodes are added
|
||||
* @param app The ComfyUI app instance
|
||||
*/
|
||||
init?(app: ComfyApp): Promise<void>;
|
||||
init?(app: ComfyApp): Promise<void>
|
||||
/**
|
||||
* Allows any additonal setup, called after the application is fully set up and running
|
||||
* @param app The ComfyUI app instance
|
||||
*/
|
||||
setup?(app: ComfyApp): Promise<void>;
|
||||
setup?(app: ComfyApp): Promise<void>
|
||||
/**
|
||||
* Called before nodes are registered with the graph
|
||||
* @param defs The collection of node definitions, add custom ones or edit existing ones
|
||||
@@ -24,7 +24,7 @@ export interface ComfyExtension {
|
||||
addCustomNodeDefs?(
|
||||
defs: Record<string, ComfyObjectInfo>,
|
||||
app: ComfyApp
|
||||
): Promise<void>;
|
||||
): Promise<void>
|
||||
/**
|
||||
* Allows the extension to add custom widgets
|
||||
* @param app The ComfyUI app instance
|
||||
@@ -42,7 +42,7 @@ export interface ComfyExtension {
|
||||
app
|
||||
) => { widget?: IWidget; minWidth?: number; minHeight?: number }
|
||||
>
|
||||
>;
|
||||
>
|
||||
/**
|
||||
* Allows the extension to add additional handling to the node before it is registered with LGraph
|
||||
* @param nodeType The node class (not an instance)
|
||||
@@ -53,12 +53,12 @@ export interface ComfyExtension {
|
||||
nodeType: typeof LGraphNode,
|
||||
nodeData: ComfyObjectInfo,
|
||||
app: ComfyApp
|
||||
): Promise<void>;
|
||||
): Promise<void>
|
||||
/**
|
||||
* Allows the extension to register additional nodes with LGraph after standard nodes are added
|
||||
* @param app The ComfyUI app instance
|
||||
*/
|
||||
registerCustomNodes?(app: ComfyApp): Promise<void>;
|
||||
registerCustomNodes?(app: ComfyApp): Promise<void>
|
||||
/**
|
||||
* Allows the extension to modify a node that has been reloaded onto the graph.
|
||||
* If you break something in the backend and want to patch workflows in the frontend
|
||||
@@ -66,26 +66,26 @@ export interface ComfyExtension {
|
||||
* @param node The node that has been loaded
|
||||
* @param app The ComfyUI app instance
|
||||
*/
|
||||
loadedGraphNode?(node: LGraphNode, app: ComfyApp);
|
||||
loadedGraphNode?(node: LGraphNode, app: ComfyApp)
|
||||
/**
|
||||
* Allows the extension to run code after the constructor of the node
|
||||
* @param node The node that has been created
|
||||
* @param app The ComfyUI app instance
|
||||
*/
|
||||
nodeCreated?(node: LGraphNode, app: ComfyApp);
|
||||
nodeCreated?(node: LGraphNode, app: ComfyApp)
|
||||
}
|
||||
|
||||
export type ComfyObjectInfo = {
|
||||
name: string;
|
||||
display_name?: string;
|
||||
description?: string;
|
||||
category: string;
|
||||
name: string
|
||||
display_name?: string
|
||||
description?: string
|
||||
category: string
|
||||
input?: {
|
||||
required?: Record<string, ComfyObjectInfoConfig>;
|
||||
optional?: Record<string, ComfyObjectInfoConfig>;
|
||||
};
|
||||
output?: string[];
|
||||
output_name: string[];
|
||||
};
|
||||
required?: Record<string, ComfyObjectInfoConfig>
|
||||
optional?: Record<string, ComfyObjectInfoConfig>
|
||||
}
|
||||
output?: string[]
|
||||
output_name: string[]
|
||||
}
|
||||
|
||||
export type ComfyObjectInfoConfig = [string | any[]] | [string | any[], any];
|
||||
export type ComfyObjectInfoConfig = [string | any[]] | [string | any[], any]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { fromZodError } from "zod-validation-error";
|
||||
import { z } from 'zod'
|
||||
import { fromZodError } from 'zod-validation-error'
|
||||
|
||||
const zComfyLink = z.tuple([
|
||||
z.number(), // Link id
|
||||
@@ -7,26 +7,26 @@ const zComfyLink = z.tuple([
|
||||
z.number(), // Output slot# of source node
|
||||
z.number(), // Node id of destination node
|
||||
z.number(), // Input slot# of destination node
|
||||
z.string(), // Data type
|
||||
]);
|
||||
z.string() // Data type
|
||||
])
|
||||
|
||||
const zNodeOutput = z
|
||||
.object({
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
links: z.array(z.number()).nullable(),
|
||||
slot_index: z.number().optional(),
|
||||
slot_index: z.number().optional()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const zNodeInput = z
|
||||
.object({
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
link: z.number().nullable(),
|
||||
slot_index: z.number().optional(),
|
||||
slot_index: z.number().optional()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const zFlags = z
|
||||
.object({
|
||||
@@ -34,22 +34,22 @@ const zFlags = z
|
||||
pinned: z.boolean().optional(),
|
||||
allow_interaction: z.boolean().optional(),
|
||||
horizontal: z.boolean().optional(),
|
||||
skip_repeated_outputs: z.boolean().optional(),
|
||||
skip_repeated_outputs: z.boolean().optional()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const zProperties = z
|
||||
.object({
|
||||
["Node name for S&R"]: z.string().optional(),
|
||||
['Node name for S&R']: z.string().optional()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const zVector2 = z.union([
|
||||
z.object({ 0: z.number(), 1: z.number() }).transform((v) => [v[0], v[1]]),
|
||||
z.tuple([z.number(), z.number()]),
|
||||
]);
|
||||
z.tuple([z.number(), z.number()])
|
||||
])
|
||||
|
||||
const zWidgetValues = z.union([z.array(z.any()), z.record(z.any())]);
|
||||
const zWidgetValues = z.union([z.array(z.any()), z.record(z.any())])
|
||||
|
||||
const zComfyNode = z
|
||||
.object({
|
||||
@@ -65,9 +65,9 @@ const zComfyNode = z
|
||||
properties: zProperties,
|
||||
widgets_values: zWidgetValues.optional(),
|
||||
color: z.string().optional(),
|
||||
bgcolor: z.string().optional(),
|
||||
bgcolor: z.string().optional()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const zGroup = z
|
||||
.object({
|
||||
@@ -75,9 +75,9 @@ const zGroup = z
|
||||
bounding: z.tuple([z.number(), z.number(), z.number(), z.number()]),
|
||||
color: z.string(),
|
||||
font_size: z.number(),
|
||||
locked: z.boolean().optional(),
|
||||
locked: z.boolean().optional()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const zInfo = z
|
||||
.object({
|
||||
@@ -87,30 +87,30 @@ const zInfo = z
|
||||
version: z.string(),
|
||||
created: z.string(),
|
||||
modified: z.string(),
|
||||
software: z.string(),
|
||||
software: z.string()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const zDS = z
|
||||
.object({
|
||||
scale: z.number(),
|
||||
offset: zVector2,
|
||||
offset: zVector2
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const zConfig = z
|
||||
.object({
|
||||
links_ontop: z.boolean().optional(),
|
||||
align_to_grid: z.boolean().optional(),
|
||||
align_to_grid: z.boolean().optional()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
const zExtra = z
|
||||
.object({
|
||||
ds: zDS.optional(),
|
||||
info: zInfo.optional(),
|
||||
info: zInfo.optional()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
export const zComfyWorkflow = z
|
||||
.object({
|
||||
@@ -121,26 +121,26 @@ export const zComfyWorkflow = z
|
||||
groups: z.array(zGroup).optional(),
|
||||
config: zConfig.optional().nullable(),
|
||||
extra: zExtra.optional().nullable(),
|
||||
version: z.number(),
|
||||
version: z.number()
|
||||
})
|
||||
.passthrough();
|
||||
.passthrough()
|
||||
|
||||
export type NodeInput = z.infer<typeof zNodeInput>;
|
||||
export type NodeOutput = z.infer<typeof zNodeOutput>;
|
||||
export type ComfyLink = z.infer<typeof zComfyLink>;
|
||||
export type ComfyNode = z.infer<typeof zComfyNode>;
|
||||
export type ComfyWorkflowJSON = z.infer<typeof zComfyWorkflow>;
|
||||
export type NodeInput = z.infer<typeof zNodeInput>
|
||||
export type NodeOutput = z.infer<typeof zNodeOutput>
|
||||
export type ComfyLink = z.infer<typeof zComfyLink>
|
||||
export type ComfyNode = z.infer<typeof zComfyNode>
|
||||
export type ComfyWorkflowJSON = z.infer<typeof zComfyWorkflow>
|
||||
|
||||
export async function parseComfyWorkflow(
|
||||
data: string
|
||||
): Promise<ComfyWorkflowJSON> {
|
||||
// Validate
|
||||
const result = await zComfyWorkflow.safeParseAsync(JSON.parse(data));
|
||||
const result = await zComfyWorkflow.safeParseAsync(JSON.parse(data))
|
||||
if (!result.success) {
|
||||
// TODO: Pretty print the error on UI modal.
|
||||
const error = fromZodError(result.error);
|
||||
alert(`Invalid workflow against zod schema:\n${error}`);
|
||||
throw error;
|
||||
const error = fromZodError(result.error)
|
||||
alert(`Invalid workflow against zod schema:\n${error}`)
|
||||
throw error
|
||||
}
|
||||
return result.data;
|
||||
return result.data
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import { Component } from "vue";
|
||||
import { Component } from 'vue'
|
||||
|
||||
export interface BaseSidebarTabExtension {
|
||||
id: string;
|
||||
title: string;
|
||||
icon?: string;
|
||||
order?: number;
|
||||
tooltip?: string;
|
||||
id: string
|
||||
title: string
|
||||
icon?: string
|
||||
order?: number
|
||||
tooltip?: string
|
||||
}
|
||||
|
||||
export interface VueSidebarTabExtension extends BaseSidebarTabExtension {
|
||||
type: "vue";
|
||||
component: Component;
|
||||
type: 'vue'
|
||||
component: Component
|
||||
}
|
||||
|
||||
export interface CustomSidebarTabExtension extends BaseSidebarTabExtension {
|
||||
type: "custom";
|
||||
render: (container: HTMLElement) => void;
|
||||
destroy?: () => void;
|
||||
type: 'custom'
|
||||
render: (container: HTMLElement) => void
|
||||
destroy?: () => void
|
||||
}
|
||||
|
||||
export type SidebarTabExtension =
|
||||
| VueSidebarTabExtension
|
||||
| CustomSidebarTabExtension;
|
||||
| CustomSidebarTabExtension
|
||||
|
||||
export interface ExtensionManager {
|
||||
registerSidebarTab(tab: SidebarTabExtension): void;
|
||||
unregisterSidebarTab(id: string): void;
|
||||
getSidebarTabs(): SidebarTabExtension[];
|
||||
registerSidebarTab(tab: SidebarTabExtension): void
|
||||
unregisterSidebarTab(id: string): void
|
||||
getSidebarTabs(): SidebarTabExtension[]
|
||||
}
|
||||
|
||||
20
src/types/litegraph-augmentation.d.ts
vendored
20
src/types/litegraph-augmentation.d.ts
vendored
@@ -1,46 +1,46 @@
|
||||
import "@comfyorg/litegraph";
|
||||
import '@comfyorg/litegraph'
|
||||
|
||||
/**
|
||||
* ComfyUI extensions of litegraph
|
||||
*/
|
||||
declare module "@comfyorg/litegraph" {
|
||||
declare module '@comfyorg/litegraph' {
|
||||
interface LGraphNode {
|
||||
/**
|
||||
* Callback fired on each node after the graph is configured
|
||||
*/
|
||||
onAfterGraphConfigured?(): void;
|
||||
onAfterGraphConfigured?(): void
|
||||
|
||||
/**
|
||||
* If the node is a frontend only node and should not be serialized into the prompt.
|
||||
*/
|
||||
isVirtualNode?: boolean;
|
||||
isVirtualNode?: boolean
|
||||
}
|
||||
|
||||
interface IWidget<TValue = any, TOptions = any> {
|
||||
/**
|
||||
* Allows for additional cleanup when removing a widget when converting to input.
|
||||
*/
|
||||
onRemove?(): void;
|
||||
onRemove?(): void
|
||||
}
|
||||
|
||||
interface INodeOutputSlot {
|
||||
widget?: unknown;
|
||||
widget?: unknown
|
||||
}
|
||||
|
||||
interface INodeInputSlot {
|
||||
widget?: unknown;
|
||||
widget?: unknown
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extended types for litegraph, to be merged upstream once it has stabilized.
|
||||
*/
|
||||
declare module "@comfyorg/litegraph" {
|
||||
declare module '@comfyorg/litegraph' {
|
||||
interface INodeInputSlot {
|
||||
pos?: [number, number];
|
||||
pos?: [number, number]
|
||||
}
|
||||
|
||||
interface LGraphNode {
|
||||
widgets_values?: unknown[];
|
||||
widgets_values?: unknown[]
|
||||
}
|
||||
}
|
||||
|
||||
22
src/types/litegraph-core-augmentation.d.ts
vendored
22
src/types/litegraph-core-augmentation.d.ts
vendored
@@ -2,18 +2,18 @@
|
||||
Extended types for litegraph, to be merged upstream once it has stabilized.
|
||||
Augmenting the LiteGraph type really didn't want to work, however doing it like this seems to allow it.
|
||||
*/
|
||||
declare module "@comfyorg/litegraph" {
|
||||
declare module '@comfyorg/litegraph' {
|
||||
interface LiteGraphExtended {
|
||||
search_filter_enabled: boolean;
|
||||
middle_click_slot_add_default_node: boolean;
|
||||
registered_slot_out_types: Record<string, { nodes: string[] }>;
|
||||
registered_slot_in_types: Record<string, { nodes: string[] }>;
|
||||
slot_types_out: string[];
|
||||
slot_types_default_out: Record<string, string[]>;
|
||||
slot_types_default_in: Record<string, string[]>;
|
||||
search_filter_enabled: boolean
|
||||
middle_click_slot_add_default_node: boolean
|
||||
registered_slot_out_types: Record<string, { nodes: string[] }>
|
||||
registered_slot_in_types: Record<string, { nodes: string[] }>
|
||||
slot_types_out: string[]
|
||||
slot_types_default_out: Record<string, string[]>
|
||||
slot_types_default_in: Record<string, string[]>
|
||||
}
|
||||
|
||||
import type { LiteGraph as LG } from "@comfyorg/litegraph/src/litegraph";
|
||||
export const LiteGraph: LiteGraphExtended & typeof LG;
|
||||
export * from "@comfyorg/litegraph/src/litegraph";
|
||||
import type { LiteGraph as LG } from '@comfyorg/litegraph/src/litegraph'
|
||||
export const LiteGraph: LiteGraphExtended & typeof LG
|
||||
export * from '@comfyorg/litegraph/src/litegraph'
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
export type NodeSourceType = "core" | "custom_nodes";
|
||||
export type NodeSourceType = 'core' | 'custom_nodes'
|
||||
export type NodeSource = {
|
||||
type: NodeSourceType;
|
||||
className: string;
|
||||
displayText: string;
|
||||
};
|
||||
type: NodeSourceType
|
||||
className: string
|
||||
displayText: string
|
||||
}
|
||||
|
||||
export const getNodeSource = (python_module: string): NodeSource => {
|
||||
const modules = python_module.split(".");
|
||||
if (["nodes", "comfy_extras"].includes(modules[0])) {
|
||||
const modules = python_module.split('.')
|
||||
if (['nodes', 'comfy_extras'].includes(modules[0])) {
|
||||
return {
|
||||
type: "core",
|
||||
className: "comfy-core",
|
||||
displayText: "Comfy Core",
|
||||
};
|
||||
} else if (modules[0] === "custom_nodes") {
|
||||
type: 'core',
|
||||
className: 'comfy-core',
|
||||
displayText: 'Comfy Core'
|
||||
}
|
||||
} else if (modules[0] === 'custom_nodes') {
|
||||
return {
|
||||
type: "custom_nodes",
|
||||
className: "comfy-custom-nodes",
|
||||
displayText: modules[1],
|
||||
};
|
||||
type: 'custom_nodes',
|
||||
className: 'comfy-custom-nodes',
|
||||
displayText: modules[1]
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Unknown node source: ${python_module}`);
|
||||
throw new Error(`Unknown node source: ${python_module}`)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
export type StorageLocation = "browser" | "server";
|
||||
export type StorageLocation = 'browser' | 'server'
|
||||
|
||||
export type SettingInputType =
|
||||
| "boolean"
|
||||
| "number"
|
||||
| "slider"
|
||||
| "combo"
|
||||
| "text"
|
||||
| "hidden";
|
||||
| 'boolean'
|
||||
| 'number'
|
||||
| 'slider'
|
||||
| 'combo'
|
||||
| 'text'
|
||||
| 'hidden'
|
||||
|
||||
export type SettingCustomRenderer = (
|
||||
name: string,
|
||||
setter: (v: any) => void,
|
||||
value: any,
|
||||
attrs: any
|
||||
) => HTMLElement;
|
||||
) => HTMLElement
|
||||
|
||||
export interface SettingOption {
|
||||
text: string;
|
||||
value?: string;
|
||||
text: string
|
||||
value?: string
|
||||
}
|
||||
|
||||
export interface Setting {
|
||||
id: string;
|
||||
onChange?: (value: any, oldValue?: any) => void;
|
||||
name: string;
|
||||
render: () => HTMLElement;
|
||||
id: string
|
||||
onChange?: (value: any, oldValue?: any) => void
|
||||
name: string
|
||||
render: () => HTMLElement
|
||||
}
|
||||
|
||||
export interface SettingParams {
|
||||
id: string;
|
||||
name: string;
|
||||
type: SettingInputType | SettingCustomRenderer;
|
||||
defaultValue: any;
|
||||
onChange?: (newValue: any, oldValue?: any) => void;
|
||||
attrs?: any;
|
||||
tooltip?: string;
|
||||
options?: Array<string | SettingOption> | ((value: any) => SettingOption[]);
|
||||
id: string
|
||||
name: string
|
||||
type: SettingInputType | SettingCustomRenderer
|
||||
defaultValue: any
|
||||
onChange?: (newValue: any, oldValue?: any) => void
|
||||
attrs?: any
|
||||
tooltip?: string
|
||||
options?: Array<string | SettingOption> | ((value: any) => SettingOption[])
|
||||
}
|
||||
|
||||
8
src/types/vue-shim.d.ts
vendored
8
src/types/vue-shim.d.ts
vendored
@@ -1,6 +1,6 @@
|
||||
// vue-shim.d.ts
|
||||
declare module "*.vue" {
|
||||
import { DefineComponent } from "vue";
|
||||
const component: DefineComponent<{}, {}, any>;
|
||||
export default component;
|
||||
declare module '*.vue' {
|
||||
import { DefineComponent } from 'vue'
|
||||
const component: DefineComponent<{}, {}, any>
|
||||
export default component
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user