[Cleanup] Remove combo connection type check (#2838)

This commit is contained in:
Chenlei Hu
2025-03-03 17:35:18 -05:00
committed by GitHub
parent 47604e6c2d
commit 8affd7eec7
2 changed files with 8 additions and 54 deletions

View File

@@ -551,26 +551,6 @@ function getWidgetType(config: InputSpec) {
return { type }
}
function isValidCombo(combo: string[], obj: unknown) {
// New input isnt a combo
if (!(obj instanceof Array)) {
console.log(`connection rejected: tried to connect combo to ${obj}`)
return false
}
// New input combo has a different size
if (combo.length !== obj.length) {
console.log(`connection rejected: combo lists dont match`)
return false
}
// New input combo has different elements
if (combo.find((v, i) => obj[i] !== v)) {
console.log(`connection rejected: combo lists dont match`)
return false
}
return true
}
export function setWidgetConfig(
slot: INodeInputSlot | INodeOutputSlot,
config: InputSpec
@@ -931,37 +911,6 @@ app.registerExtension({
return r
}
// Prevent connecting COMBO lists to converted inputs that dont match types
const onConnectInput = nodeType.prototype.onConnectInput
nodeType.prototype.onConnectInput = function (
this: LGraphNode,
targetSlot: number,
type: string,
output: INodeOutputSlot,
originNode: LGraphNode,
originSlot: number
) {
// @ts-expect-error onConnectInput has 5 arguments
const v = onConnectInput?.(this, arguments)
// Not a combo, ignore
if (type !== 'COMBO') return v
// Primitive output, allow that to handle
if (originNode.outputs[originSlot].widget) return v
// Ensure target is also a combo
const targetCombo = this.inputs[targetSlot].widget?.[GET_CONFIG]?.()?.[0]
if (!targetCombo || !(targetCombo instanceof Array)) return v
// Check they match
const originConfig =
originNode.constructor?.nodeData?.output?.[originSlot]
if (!originConfig || !isValidCombo(targetCombo, originConfig)) {
return false
}
return v
}
},
registerCustomNodes() {
LiteGraph.registerNodeType(

View File

@@ -1,6 +1,7 @@
import { z } from 'zod'
import { fromZodError } from 'zod-validation-error'
const zComboOption = z.union([z.string(), z.number()])
const zRemoteWidgetConfig = z.object({
route: z.string().url().or(z.string().startsWith('/')),
refresh: z.number().gte(128).safe().or(z.number().lte(0).safe()).optional(),
@@ -71,7 +72,7 @@ const zComboInputOptions = zBaseInputOptions.extend({
allow_batch: z.boolean().optional(),
video_upload: z.boolean().optional(),
remote: zRemoteWidgetConfig.optional(),
options: z.array(z.union([z.string(), z.number()])).optional()
options: z.array(zComboOption).optional()
})
const zIntInputSpec = z.tuple([z.literal('INT'), zIntInputOptions.optional()])
@@ -87,8 +88,12 @@ const zStringInputSpec = z.tuple([
z.literal('STRING'),
zStringInputOptions.optional()
])
/**
* Legacy combo syntax.
* @deprecated Use `zComboInputSpecV2` instead.
*/
const zComboInputSpec = z.tuple([
z.array(z.union([z.string(), z.number()])),
z.array(zComboOption),
zComboInputOptions.optional()
])
const zComboInputSpecV2 = z.tuple([
@@ -193,7 +198,7 @@ const zComfyInputsSpec = z.object({
})
const zComfyNodeDataType = z.string()
const zComfyComboOutput = z.array(z.any())
const zComfyComboOutput = z.array(zComboOption)
const zComfyOutputTypesSpec = z.array(
z.union([zComfyNodeDataType, zComfyComboOutput])
)