@@ -6,6 +6,8 @@ let hasComfyLoaded = false;
66
77let comfyButtonsArea = getRequiredElementById ( 'comfy_workflow_buttons' ) ;
88
9+ let comfyObjectData = { } ;
10+
911/**
1012 * Tries to load the ComfyUI workflow frame.
1113 */
@@ -36,6 +38,11 @@ function comfyOnLoadCallback() {
3638 comfyFrame ( ) . remove ( ) ;
3739 getRequiredElementById ( 'comfy_workflow_frameholder' ) . innerHTML = `<h2>Failed to load ComfyUI workflow editor. <button onclick="comfyTryToLoad()">Try Again?</button></h2>` ;
3840 }
41+ else {
42+ getJsonDirect ( '/ComfyBackendDirect/object_info' , ( _ , data ) => {
43+ comfyObjectData = data ;
44+ } ) ;
45+ }
3946}
4047
4148/**
@@ -172,6 +179,13 @@ function comfyBuildParams(callback) {
172179 return id ;
173180 }
174181 function addParam ( inputId , inputIdDirect , inputLabel , val , groupId , groupLabel ) {
182+ let paramDataRaw ;
183+ if ( node . class_type in comfyObjectData ) {
184+ let possible = comfyObjectData [ node . class_type ] . input ;
185+ if ( 'required' in possible && inputId in possible . required ) {
186+ paramDataRaw = possible . required [ inputId ] ;
187+ }
188+ }
175189 let type , values = null , min = - 9999999999 , max = 9999999999 , number_view_type = 'big' , step = 1 ;
176190 if ( typeof val == 'number' ) {
177191 let asSeed = false ;
@@ -210,7 +224,23 @@ function comfyBuildParams(callback) {
210224 step = 1 ;
211225 }
212226 else {
213- type = 'decimal' ;
227+ if ( paramDataRaw && paramDataRaw [ 0 ] == 'INT' && paramDataRaw . length == 2 ) {
228+ type = 'integer' ;
229+ number_view_type = 'big' ;
230+ min = paramDataRaw [ 1 ] . min ;
231+ max = paramDataRaw [ 1 ] . max ;
232+ step = 1 ;
233+ }
234+ else if ( paramDataRaw && paramDataRaw [ 0 ] == 'FLOAT' && paramDataRaw . length == 2 ) {
235+ type = 'decimal' ;
236+ number_view_type = 'slider' ;
237+ min = paramDataRaw [ 1 ] . min ;
238+ max = paramDataRaw [ 1 ] . max ;
239+ step = ( max - min ) * 0.01 ;
240+ }
241+ else {
242+ type = 'decimal' ;
243+ }
214244 }
215245 inputIdDirect = injectType ( inputIdDirect , type ) ;
216246 node . inputs [ inputId ] = "%%_COMFYFIXME_${" + inputIdDirect + ( asSeed ? "+seed" : "" ) + ":" + val + "}_ENDFIXME_%%" ;
@@ -235,7 +265,13 @@ function comfyBuildParams(callback) {
235265 }
236266 // TODO: Can we interrogate ComfyUI to ask what values are valid? For eg LoRA inputs, sampler, etc.
237267 else {
238- type = 'text' ;
268+ if ( paramDataRaw && paramDataRaw . length == 1 && paramDataRaw [ 0 ] . length > 1 ) {
269+ type = 'dropdown' ;
270+ values = paramDataRaw [ 0 ] ;
271+ }
272+ else {
273+ type = 'text' ;
274+ }
239275 }
240276 inputIdDirect = injectType ( inputIdDirect , type ) ;
241277 node . inputs [ inputId ] = "${" + inputIdDirect + ":" + val . replaceAll ( '${' , '(' ) . replaceAll ( '}' , ')' ) + "}" ;
@@ -333,6 +369,10 @@ function replaceParamsToComfy() {
333369 actualParams . push ( param ) ;
334370 let val = paramVal [ param . id ] ;
335371 if ( val ) {
372+ // Comfy for some reason generates impossibly high seeds, so discard those
373+ if ( param . type == 'integer' && param . number_view_type == 'seed' && val > 4294967295 ) {
374+ val = - 1 ;
375+ }
336376 setCookie ( `lastparam_input_${ param . id } ` , `${ val } ` , 0.5 ) ;
337377 }
338378 }
0 commit comments