@kwj-team/comfyui-client
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -1,2 +0,2 @@ | ||
function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},e.apply(this,arguments)}function t(e,r){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},t(e,r)}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function n(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i,s=(o=function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function o(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function i(e,t,n,i,s){if("function"!=typeof n)throw new TypeError("The listener must be a function");var u=new o(n,i||e,s),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],u]:e._events[c].push(u):(e._events[c]=u,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function u(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),u.prototype.eventNames=function(){var e,n,o=[];if(0===this._eventsCount)return o;for(n in e=this._events)t.call(e,n)&&o.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},u.prototype.listeners=function(e){var t=this._events[r?r+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var n=0,o=t.length,i=new Array(o);n<o;n++)i[n]=t[n].fn;return i},u.prototype.listenerCount=function(e){var t=this._events[r?r+e:e];return t?t.fn?1:t.length:0},u.prototype.emit=function(e,t,n,o,i,s){var u=r?r+e:e;if(!this._events[u])return!1;var c,a,l=this._events[u],h=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),h){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,n),!0;case 4:return l.fn.call(l.context,t,n,o),!0;case 5:return l.fn.call(l.context,t,n,o,i),!0;case 6:return l.fn.call(l.context,t,n,o,i,s),!0}for(a=1,c=new Array(h-1);a<h;a++)c[a-1]=arguments[a];l.fn.apply(l.context,c)}else{var f,d=l.length;for(a=0;a<d;a++)switch(l[a].once&&this.removeListener(e,l[a].fn,void 0,!0),h){case 1:l[a].fn.call(l[a].context);break;case 2:l[a].fn.call(l[a].context,t);break;case 3:l[a].fn.call(l[a].context,t,n);break;case 4:l[a].fn.call(l[a].context,t,n,o);break;default:if(!c)for(f=1,c=new Array(h-1);f<h;f++)c[f-1]=arguments[f];l[a].fn.apply(l[a].context,c)}}return!0},u.prototype.on=function(e,t,r){return i(this,e,t,r,!1)},u.prototype.once=function(e,t,r){return i(this,e,t,r,!0)},u.prototype.removeListener=function(e,t,n,o){var i=r?r+e:e;if(!this._events[i])return this;if(!t)return s(this,i),this;var u=this._events[i];if(u.fn)u.fn!==t||o&&!u.once||n&&u.context!==n||s(this,i);else{for(var c=0,a=[],l=u.length;c<l;c++)(u[c].fn!==t||o&&!u[c].once||n&&u[c].context!==n)&&a.push(u[c]);a.length?this._events[i]=1===a.length?a[0]:a:s(this,i)}return this},u.prototype.removeAllListeners=function(e){var t;return e?this._events[t=r?r+e:e]&&s(this,t):(this._events=new n,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=r,u.EventEmitter=u,e.exports=u},o(i={exports:{}}),i.exports),u=function(e){return null==e},c=/*#__PURE__*/function(){function t(e){var r,n,o,i,u,c,a,l;if(this._authHeader=void 0,this.auth=void 0,this.api_host=void 0,this.api_base=void 0,this.clientId=void 0,this.socket=void 0,this.WebSocket=void 0,this.ssl=void 0,this.user=void 0,this.fetch=void 0,this.events=new s,this.registered=new Set,this.socket_callbacks={},this._polling_timer=null,this._polling_interval=1e3,this.closed=!1,this.auth=null!=(r=e.auth)?r:"",this.api_host=null!=(n=e.api_host)?n:t.DEFAULT_API_HOST,this.api_base=null!=(o=e.api_base)?o:t.DEFAULT_API_BASE,this.clientId=null!=(i=e.clientId)?i:"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),this.WebSocket=null!=(u=e.WebSocket)?u:WebSocket,this.ssl=null!=(c=e.ssl)&&c,this.user=null!=(a=e.user)?a:t.DEFAULT_USER,!globalThis.fetch)throw new Error("fetch is not defined");this.fetch=null!=(l=e.fetch)?l:globalThis.fetch.bind(globalThis),this._authHeader=""!==this.auth?{Authorization:""+this.auth}:{}}t.loadImageData=function(e){var t=new DataView(e).getUint32(0);if(1===t)return new DataView(e).getUint32(0),e.slice(8);throw new Error("Unknown binary websocket message of type "+t)};var r=t.prototype;return r.apiURL=function(e){return"http"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+e},r.viewURL=function(e,t,r){var n=new URLSearchParams({filename:e,subfolder:t,type:r}).toString();return"http"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+"/view?"+n},r.fetchApi=function(t,r){try{var n,o=this;if(o.closed)throw new Error("Client is closed");var i=e({},o.user?{"Comfy-User":o.user}:{},{Accept:"*/*"},null!=(n=null==r?void 0:r.headers)?n:{}),s=o.apiURL(t);return Promise.resolve(o.fetch(s,e({},r,{headers:i})))}catch(e){return Promise.reject(e)}},r.addEventListener=function(e,t,r){var n=this;return this.events.on(e,t,r),this.registered.add(e),function(){n.events.off(e,t),n.registered.delete(e)}},r.on=function(e,t,r){return this.addEventListener(e,t,r)},r.startPollingQueue=function(){var e=this;this._polling_timer||(this._polling_timer=setInterval(function(){try{var t=function(t,r){try{var n=Promise.resolve(e.fetchApi("/prompt")).then(function(t){return Promise.resolve(t.json()).then(function(t){e.events.emit("status",t)})})}catch(e){return r()}return n&&n.then?n.then(void 0,r):n}(0,function(){e.events.emit("status",null)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},this._polling_interval))},r.addSocketCallback=function(e,t,r,n){var o=this;return this.socket_callbacks[t]=r,e.addEventListener(t,r,n),function(){delete o.socket_callbacks[t],e.removeEventListener(t,r,n)}},r.removeSocketCallbacks=function(){if(this.socket)for(var e in this.socket_callbacks)this.socket.removeEventListener(e,this.socket_callbacks[e]);this.socket_callbacks={}},r.createSocket=function(e){var r=this;if(void 0===e&&(e=!1),!this.socket){var n=!1,o="";this.clientId&&(o="?clientId="+this.clientId),this.socket=new(0,this.WebSocket)("ws"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+"/ws"+o,[],{headers:{Cookie:"ai_dock_token=dXNlcjpwYXNzd29yZA==;"}}),this.socket.binaryType="arraybuffer",this.addSocketCallback(this.socket,"open",function(){n=!0,e&&r.events.emit("reconnected")}),this.addSocketCallback(this.socket,"error",function(){r.socket&&r.socket.close(),e||n||r.startPollingQueue()}),this.addSocketCallback(this.socket,"close",function(){setTimeout(function(){r.socket=null,r.createSocket(!0)},300),n&&(r.events.emit("status",null),r.events.emit("reconnecting"))}),this.addSocketCallback(this.socket,"message",function(e){r.events.emit("message",e);try{if(function(e){return"string"!=typeof e.data&&(t.IS_BROWSER?e.data instanceof Blob:!!(ArrayBuffer&&e.data instanceof ArrayBuffer)||!(!Buffer||!Buffer.isBuffer(e.data)))}(e)){var n=t.loadImageData(e.data);r.events.emit("image_data",n)}else{var o=JSON.parse(e.data);switch(o.type){case"status":o.data.sid&&(r.clientId=o.data.sid),r.events.emit("status",o.data.status);break;case"progress":r.events.emit("progress",o.data);break;case"executing":r.events.emit("executing",o.data);break;case"executed":r.events.emit("executed",o.data);break;case"execution_start":r.events.emit("execution_start",o.data);break;case"execution_error":r.events.emit("execution_error",o.data);break;case"execution_cached":r.events.emit("execution_cached",o.data);break;case"execution_interrupted":r.events.emit("execution_interrupted",o.data);break;default:if(!r.registered.has(o.type))throw new Error("Unknown message type "+o.type);r.events.emit(o.type,o.data)}}}catch(t){console.warn("Unhandled message:",e.data,t)}})}},r.init=function(){this.createSocket()},r.close=function(){this.closed||(this.closed=!0,this.disconnect(),this.events.removeAllListeners())},r.connect=function(e){var t,r=void 0===e?{}:e,n=r.polling,o=void 0===n?{enabled:!1}:n,i=r.websocket,s=void 0===i?{enabled:!0}:i;return null!=o&&o.enabled&&(this._polling_interval=null!=(t=o.interval)?t:this._polling_interval,this.startPollingQueue()),null!=s&&s.enabled&&this.createSocket(),this},r.disconnect=function(){this._disconnectSocket(),this._disconnectPolling()},r._disconnectSocket=function(){var e=this.socket;e&&(this.socket=null,e.readyState===this.WebSocket.OPEN&&e.close(1e3,"Client closed"),this.removeSocketCallbacks(),"removeAllListeners"in e&&(null==e.removeAllListeners||e.removeAllListeners()))},r._disconnectPolling=function(){null!==this._polling_timer&&(clearInterval(this._polling_timer),this._polling_timer=null)},t}();c.DEFAULT_API_HOST="127.0.0.1:8188",c.DEFAULT_API_BASE="",c.DEFAULT_USER="",c.IS_BROWSER="undefined"!=typeof window;var a=/*#__PURE__*/function(){function e(){this._cached=void 0,this._cached=globalThis[e.KEY]||new Map,globalThis[e.KEY]=this._cached}var t=e.prototype;return t.clear=function(){this._cached.clear()},t.get=function(e){return this._cached.get(e)},t.set=function(e,t){this._cached.set(e,t)},e}();a.KEY="__COMFY_UI_CLIENT_CACHE__";var l=/*#__PURE__*/function(){function e(t,r){var n,o;this.expire_time_ms=void 0,this.enabled=void 0,this._cached=new a,this.cache_ns="",this.expire_time_ms=null!=(n=null==r?void 0:r.expire_time)?n:e._defaultExpire,this.enabled=null==(o=null==r?void 0:r.enabled)||o,this.cache_ns=t}var t=e.prototype;return t.reset=function(){this._cached.clear()},t._hashArgs=function(e){try{return JSON.stringify(e)}catch(t){return e.toString()}},t.warp=function(e,t){var r=this;return this.enabled?function(){var n=[].slice.call(arguments),o=Date.now(),i=r._hashArgs(n),s=r.cache_ns+":"+e+":"+i,u=r._cached.get(s);if(u&&u.expire>o)return u.result;var c=t.apply(void 0,n);return r._cached.set(s,{result:c,expire:o+r.expire_time_ms}),c}:t},e}();function h(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}function f(e,t,r){if(!e.s){if(r instanceof d){if(!r.s)return void(r.o=f.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(f.bind(null,e,t),f.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}l._defaultExpire=6e4;var d=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{f(n,1,i(this.v))}catch(e){f(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?f(n,1,t?t(o):o):r?f(n,1,r(o)):f(n,2,o)}catch(e){f(n,2,e)}},n},e}();function p(e){return e instanceof d&&1&e.s}var v=/*#__PURE__*/function(r){function o(e){var t;return(t=r.call(this,e)||this)._cached_fn=void 0,t._cached_fn=new l(""+e.api_host,e.cache),t._authHeader=""!==t.auth?{Authorization:""+t.auth}:{},t}var i,s;s=r,(i=o).prototype=Object.create(s.prototype),i.prototype.constructor=i,t(i,s);var c=o.prototype;return c.getExtensions=function(){try{var t=this,r=t._cached_fn.warp("extensions",function(){try{return Promise.resolve(t.fetchApi("/extensions",{cache:"no-store",headers:e({},t._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.getEmbeddings=function(){try{var t=this,r=t._cached_fn.warp("embeddings",function(){try{return Promise.resolve(t.fetchApi("/embeddings",{cache:"no-store",headers:e({},t._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.getNodeDefs=function(){try{var t=this,r=t._cached_fn.warp("object_info",function(){try{return Promise.resolve(t.fetchApi("/object_info",{cache:"no-store",headers:e({},t._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.resetCache=function(){this._cached_fn.reset()},c.queuePrompt=function(t,r){var n=r.prompt,o=r.workflow;try{var i=this,s={client_id:i.clientId,prompt:n,extra_data:{extra_pnginfo:{workflow:o}}};return-1===t?s.front=!0:0!==t&&(s.number=t),Promise.resolve(i.fetchApi("/prompt",{method:"POST",headers:e({"Content-Type":"application/json"},i._authHeader),body:JSON.stringify(s)})).then(function(e){function t(t){return Promise.resolve(e.json())}var r=function(){if(200!==e.status)return Promise.resolve(e.text()).then(function(e){try{throw{response:JSON.parse(e)}}catch(t){throw{response:e}}})}();return r&&r.then?r.then(t):t()})}catch(e){return Promise.reject(e)}},c.getItems=function(e){try{return Promise.resolve("queue"===e?this.getQueue():this.getHistory())}catch(e){return Promise.reject(e)}},c.getQueue=function(){try{var t=this;return Promise.resolve(h(function(){return Promise.resolve(t.fetchApi("/queue",{headers:e({},t._authHeader)})).then(function(e){return Promise.resolve(e.json()).then(function(e){return{Running:e.queue_running.map(function(e){return{prompt:e,remove:{name:"Cancel",cb:function(){return t.interrupt()}}}}),Pending:e.queue_pending.map(function(e){return{prompt:e}})}})})},function(e){return console.error(e),{Running:[],Pending:[]}}))}catch(e){return Promise.reject(e)}},c.getHistory=function(t){void 0===t&&(t=200);try{var r=this;return Promise.resolve(h(function(){return Promise.resolve(r.fetchApi("/history?max_items="+t,{headers:e({},r._authHeader)})).then(function(e){return Promise.resolve(e.json()).then(function(e){return{History:Object.values(e)}})})},function(e){return console.error(e),{History:[]}}))}catch(e){return Promise.reject(e)}},c.getSystemStats=function(){try{return Promise.resolve(this.fetchApi("/system_stats",{headers:e({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.postApi=function(t,r){try{return Promise.resolve(this.fetchApi("/"+t,{method:"POST",headers:e({"Content-Type":"application/json"},this._authHeader),body:r?JSON.stringify(r):void 0})).then(function(){})}catch(e){return Promise.reject(e)}},c.deleteItem=function(e,t){try{return Promise.resolve(this.postApi(e,{delete:[t]})).then(function(){})}catch(e){return Promise.reject(e)}},c.clearItems=function(e){try{return Promise.resolve(this.postApi(e,{clear:!0})).then(function(){})}catch(e){return Promise.reject(e)}},c.interrupt=function(){try{return Promise.resolve(this.postApi("interrupt",null)).then(function(){})}catch(e){return Promise.reject(e)}},c.free=function(e){try{return Promise.resolve(this.postApi("free",e)).then(function(){})}catch(e){return Promise.reject(e)}},c.getUserConfig=function(){try{return Promise.resolve(this.fetchApi("/users",{headers:e({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.createUser=function(t){try{return Promise.resolve(this.fetchApi("/users",{method:"POST",headers:e({"Content-Type":"application/json"},this._authHeader),body:JSON.stringify({username:t})}))}catch(e){return Promise.reject(e)}},c.getSettings=function(){try{return Promise.resolve(this.fetchApi("/settings",{headers:e({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.getSetting=function(t){try{return Promise.resolve(this.fetchApi("/settings/"+encodeURIComponent(t),{headers:e({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.storeSettings=function(t){try{return Promise.resolve(this.fetchApi("/settings",{method:"POST",body:JSON.stringify(t),headers:e({},this._authHeader)}))}catch(e){return Promise.reject(e)}},c.storeSetting=function(t,r){try{return Promise.resolve(this.fetchApi("/settings/"+encodeURIComponent(t),{method:"POST",body:JSON.stringify(r),headers:e({},this._authHeader)}))}catch(e){return Promise.reject(e)}},c.getUserData=function(e,t){try{return Promise.resolve(this.fetchApi("/userdata/"+encodeURIComponent(e),t))}catch(e){return Promise.reject(e)}},c.storeUserData=function(t,r,n){try{return Promise.resolve(this.fetchApi("/userdata/"+encodeURIComponent(t),e({method:"POST",body:null!=n&&n.stringify?JSON.stringify(r):r,headers:e({},this._authHeader)},n))).then(function(e){return function(){if(200!==e.status)return Promise.resolve(e.text()).then(function(r){throw new Error("Error storing user data file '"+t+"': "+e.status+" "+r)})}()})}catch(e){return Promise.reject(e)}},c.getSamplers=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.KSampler;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.sampler_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getSchedulers=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.KSampler;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.scheduler)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getSDModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.CheckpointLoaderSimple;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.ckpt_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getCNetModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.ControlNetLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.control_net_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getUpscaleModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.UpscaleModelLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.model_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getHyperNetworks=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.HypernetworkLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.hypernetwork_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getLoRAs=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.LoraLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.lora_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getVAEs=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.VAELoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.vae_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getPromptStatus=function(e){try{return Promise.resolve(this.getQueue()).then(function(t){var r=t.Pending,n=t.Running.some(function(t){var r;return(null==t||null==(r=t.prompt)?void 0:r[1])===e}),o=r.some(function(t){var r;return(null==t||null==(r=t.prompt)?void 0:r[1])===e});return{running:n,pending:o,done:!n&&!o}})}catch(e){return Promise.reject(e)}},c.getPromptOutputs=function(e){try{return Promise.resolve(this.getHistory()).then(function(t){var r=t.History.find(function(t){return t.prompt[1]===e});if(!r)throw new Error("Prompt ["+e+"] not found in history");var n=r.status.status_str;if("success"!==n)throw new Error("Prompt ["+e+"] failed with status: "+n);return r.outputs})}catch(e){return Promise.reject(e)}},c.getPromptImageResult=function(e){try{var t=this;return Promise.resolve(t.getPromptOutputs(e)).then(function(r){return{images:Object.values(r).flatMap(function(e){return e.images||[]}).map(function(e){var r=e.filename,n=e.subfolder,o=e.type;return u(r)||u(n)||"output"!==o?null:t.viewURL(r,n,o)}).filter(Boolean).map(function(e){return{type:"url",data:e}}),prompt_id:e}})}catch(e){return Promise.reject(e)}},c.waitForPrompt=function(e,t){void 0===t&&(t=1e3);try{var r=this;return Promise.resolve(r.getPromptStatus(e)).then(function(n){var o=function(e,t,r){for(var n;;){var o=e();if(p(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!p(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!p(s)){n=2;break}}}var u=new d,c=f.bind(null,u,2);return(0===n?o.then(l):1===n?i.then(a):s.then(h)).then(void 0,c),u;function a(n){i=n;do{if(t&&(s=t())&&s.then&&!p(s))return void s.then(h).then(void 0,c);if(!(o=e())||p(o)&&!o.v)return void f(u,1,i);if(o.then)return void o.then(l).then(void 0,c);p(i=r())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,c)}function l(e){e?(i=r())&&i.then?i.then(a).then(void 0,c):a(i):f(u,1,i)}function h(){(o=e())?o.then?o.then(l).then(void 0,c):l(o):f(u,1,i)}}(function(){return!n.done},void 0,function(){return Promise.resolve(new Promise(function(e){return setTimeout(e,t)})).then(function(){return Promise.resolve(r.getPromptStatus(e)).then(function(e){n=e})})});if(o&&o.then)return o.then(function(){})})}catch(e){return Promise.reject(e)}},c.waitForPromptWebSocket=function(e){try{var t=this,r={images:[],prompt_id:e};return Promise.resolve(new Promise(function(o,i){var s=t.on("image_data",function(e){r.images.push({type:"buff",data:e})}),c=t.on("executed",function(i){if(i.prompt_id===e){for(var a,l=(i.output||{}).images,h=n(void 0===l?[]:l);!(a=h()).done;){var f=a.value||{},d=f.filename,p=f.subfolder,v=f.type;u(d)||u(p)||"output"!==v||r.images.push({type:"url",data:t.viewURL(d,p,v)})}o(r),c(),s()}})}))}catch(e){return Promise.reject(e)}},c.randomizePrompt=function(e){for(var t=0,r=Object.values(e);t<r.length;t++){var n=r[t];"KSampler"===n.class_type&&(n.inputs.seed=Math.floor(Math.random()*(Math.pow(2,32)-1)))}},c._enqueue_prompt=function(e,t){try{return null!=t&&t.disable_random_seed||this.randomizePrompt(e),Promise.resolve(this.queuePrompt(0,{prompt:e,workflow:null==t?void 0:t.workflow})).then(function(e){if("error"in e)throw new Error(e.error);return e})}catch(e){return Promise.reject(e)}},c.runPrompt=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n=e.prompt_id;return Promise.resolve(r.waitForPrompt(n,null==t?void 0:t.polling_ms)).then(function(){return Promise.resolve(r.getPromptImageResult(n))})})}catch(e){return Promise.reject(e)}},c.enqueue_polling=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n=e.prompt_id;return Promise.resolve(r.waitForPrompt(n,null==t?void 0:t.polling_ms)).then(function(){return Promise.resolve(r.getPromptImageResult(n))})})}catch(e){return Promise.reject(e)}},c.enqueue=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n,o=e.prompt_id;return null!=t&&t.progress&&(n=r.on("progress",function(e){e.progress.prompt_id===o&&(null==t||null==t.progress||t.progress(e.progress))})),function(e,t){try{var n=Promise.resolve(r.waitForPromptWebSocket(o))}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,n)}(0,function(e,t){if(null==n||n(),e)throw t;return t})})}catch(e){return Promise.reject(e)}},o}(c),m=/*#__PURE__*/function(){function e(e,t){this.workflow=void 0,this.client=void 0,this._task_id=void 0,this._enqueue_req=void 0,this._result={images:[],prompt_id:""},this.executed=!1,this.workflow=e,this.client=t}var t=e.prototype;return t.enqueue=function(){var e=this,t=this.workflow;this._enqueue_req=this.client._enqueue_prompt(t.prompt,{workflow:t.workflow}),this._task_id=this._enqueue_req.then(function(e){return e.prompt_id}),this._enqueue_req.then(function(t){e._result.prompt_id=t.prompt_id})},t.load_result_data=function(e){for(var t,r=(e.output||{}).images,o=n(void 0===r?[]:r);!(t=o()).done;){var i=t.value||{},s=i.filename,c=i.subfolder,a=i.type;u(s)||u(c)||"output"!==a||this._result.images.push({type:"url",data:this.client.viewURL(s,c,a)})}},t.query=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be queried");var t=e.client,r=t.getPromptStatus;return Promise.resolve(e._task_id).then(function(e){return r.call(t,e)})}catch(e){return Promise.reject(e)}},t.interrupt=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be interrupt");return Promise.resolve(e._task_id).then(function(t){return Promise.resolve(e.query()).then(function(r){if(!r.done){if(!r.pending){if(r.running)return e.client.interrupt();throw new Error("wrong task status, id: "+t)}e.client.deleteItem("queue",t)}})})}catch(e){return Promise.reject(e)}},t.wait=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be wait");return Promise.resolve(e._task_id).then(function(t){return new Promise(function(r,n){var o,i;i=[],o=function(){return i.forEach(function(e){return e()})},i=[e.client.on("execution_interrupted",function(e){e.prompt_id===t&&(n(new Error("Execution Interrupted")),o())}),e.client.on("image_data",function(t){e.executed||e._result.images.push({type:"buff",data:t})}),e.client.on("executed",function(n){n.prompt_id===t&&(e.load_result_data(n),e.executed=!0,r(e._result),o())})]})})}catch(e){return Promise.reject(e)}},e}(),_=globalThis.structuredClone?globalThis.structuredClone:function(e){return JSON.parse(JSON.stringify(e))},y=/*#__PURE__*/function(){function e(){this._workflow={prompt:{}},this._last_node_id=0,this.classes=this._createClassesProxy()}var t=e.prototype;return t._createClassesProxy=function(){var e=this;return new Proxy({},{get:function(t,r,n){return r in t?t[r]:function(t){var n={class_type:r.toString(),inputs:t},o=(++e._last_node_id).toString();return e._workflow.prompt[o]=n,Array.from({length:10},function(e,t){return[o,t]})}}})},t.reset=function(){this._workflow.prompt={},this._workflow.workflow=void 0,this._last_node_id=0},t.end=function(){return this.workflow()},t.workflow=function(){return _(this._workflow)},t.invoke=function(e){var t=this.instance(e);return t.enqueue(),t.wait()},t.instance=function(e){var t=this.workflow();return new m({prompt:t.prompt,workflow:t.workflow},e)},t.invoke_polling=function(e){var t=this.workflow();return e.enqueue_polling(t.prompt,{workflow:t.workflow})},e}();exports.ComfyUIApiClient=v,exports.ComfyUIWorkflow=y,exports.ComfyUIWsClient=c; | ||
function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},e.apply(this,arguments)}function t(e,r){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},t(e,r)}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function n(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i,s=(o=function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function o(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function i(e,t,n,i,s){if("function"!=typeof n)throw new TypeError("The listener must be a function");var u=new o(n,i||e,s),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],u]:e._events[c].push(u):(e._events[c]=u,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function u(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),u.prototype.eventNames=function(){var e,n,o=[];if(0===this._eventsCount)return o;for(n in e=this._events)t.call(e,n)&&o.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},u.prototype.listeners=function(e){var t=this._events[r?r+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var n=0,o=t.length,i=new Array(o);n<o;n++)i[n]=t[n].fn;return i},u.prototype.listenerCount=function(e){var t=this._events[r?r+e:e];return t?t.fn?1:t.length:0},u.prototype.emit=function(e,t,n,o,i,s){var u=r?r+e:e;if(!this._events[u])return!1;var c,a,l=this._events[u],h=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),h){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,n),!0;case 4:return l.fn.call(l.context,t,n,o),!0;case 5:return l.fn.call(l.context,t,n,o,i),!0;case 6:return l.fn.call(l.context,t,n,o,i,s),!0}for(a=1,c=new Array(h-1);a<h;a++)c[a-1]=arguments[a];l.fn.apply(l.context,c)}else{var f,d=l.length;for(a=0;a<d;a++)switch(l[a].once&&this.removeListener(e,l[a].fn,void 0,!0),h){case 1:l[a].fn.call(l[a].context);break;case 2:l[a].fn.call(l[a].context,t);break;case 3:l[a].fn.call(l[a].context,t,n);break;case 4:l[a].fn.call(l[a].context,t,n,o);break;default:if(!c)for(f=1,c=new Array(h-1);f<h;f++)c[f-1]=arguments[f];l[a].fn.apply(l[a].context,c)}}return!0},u.prototype.on=function(e,t,r){return i(this,e,t,r,!1)},u.prototype.once=function(e,t,r){return i(this,e,t,r,!0)},u.prototype.removeListener=function(e,t,n,o){var i=r?r+e:e;if(!this._events[i])return this;if(!t)return s(this,i),this;var u=this._events[i];if(u.fn)u.fn!==t||o&&!u.once||n&&u.context!==n||s(this,i);else{for(var c=0,a=[],l=u.length;c<l;c++)(u[c].fn!==t||o&&!u[c].once||n&&u[c].context!==n)&&a.push(u[c]);a.length?this._events[i]=1===a.length?a[0]:a:s(this,i)}return this},u.prototype.removeAllListeners=function(e){var t;return e?this._events[t=r?r+e:e]&&s(this,t):(this._events=new n,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=r,u.EventEmitter=u,e.exports=u},o(i={exports:{}}),i.exports),u=function(e){return null==e},c=/*#__PURE__*/function(){function t(e){var r,n,o,i,u,c,a,l;if(this._authHeader=void 0,this.auth=void 0,this.api_host=void 0,this.api_base=void 0,this.clientId=void 0,this.socket=void 0,this.WebSocket=void 0,this.ssl=void 0,this.user=void 0,this.fetch=void 0,this.events=new s,this.registered=new Set,this.socket_callbacks={},this._polling_timer=null,this._polling_interval=1e3,this.closed=!1,this.auth=null!=(r=e.auth)?r:"",this.api_host=null!=(n=e.api_host)?n:t.DEFAULT_API_HOST,this.api_base=null!=(o=e.api_base)?o:t.DEFAULT_API_BASE,this.clientId=null!=(i=e.clientId)?i:"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),this.WebSocket=null!=(u=e.WebSocket)?u:WebSocket,this.ssl=null!=(c=e.ssl)&&c,this.user=null!=(a=e.user)?a:t.DEFAULT_USER,!globalThis.fetch)throw new Error("fetch is not defined");this.fetch=null!=(l=e.fetch)?l:globalThis.fetch.bind(globalThis),this._authHeader=""!==this.auth?{Authorization:""+this.auth}:{}}t.loadImageData=function(e){var t=new DataView(e).getUint32(0);if(1===t)return new DataView(e).getUint32(0),e.slice(8);throw new Error("Unknown binary websocket message of type "+t)};var r=t.prototype;return r.apiURL=function(e){return"http"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+e},r.viewURL=function(e,t,r){var n=new URLSearchParams({filename:e,subfolder:t,type:r}).toString();return"http"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+"/view?"+n},r.fetchApi=function(t,r){try{var n,o=this;if(o.closed)throw new Error("Client is closed");var i=e({},o.user?{"Comfy-User":o.user}:{},{Accept:"*/*"},null!=(n=null==r?void 0:r.headers)?n:{}),s=o.apiURL(t);return Promise.resolve(o.fetch(s,e({},r,{headers:i})))}catch(e){return Promise.reject(e)}},r.addEventListener=function(e,t,r){var n=this;return this.events.on(e,t,r),this.registered.add(e),function(){n.events.off(e,t),n.registered.delete(e)}},r.on=function(e,t,r){return this.addEventListener(e,t,r)},r.startPollingQueue=function(){var e=this;this._polling_timer||(this._polling_timer=setInterval(function(){try{var t=function(t,r){try{var n=Promise.resolve(e.fetchApi("/prompt")).then(function(t){return Promise.resolve(t.json()).then(function(t){e.events.emit("status",t)})})}catch(e){return r()}return n&&n.then?n.then(void 0,r):n}(0,function(){e.events.emit("status",null)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},this._polling_interval))},r.addSocketCallback=function(e,t,r,n){var o=this;return this.socket_callbacks[t]=r,e.addEventListener(t,r,n),function(){delete o.socket_callbacks[t],e.removeEventListener(t,r,n)}},r.removeSocketCallbacks=function(){if(this.socket)for(var e in this.socket_callbacks)this.socket.removeEventListener(e,this.socket_callbacks[e]);this.socket_callbacks={}},r.createSocket=function(r){var n=this;if(void 0===r&&(r=!1),!this.socket){var o=!1,i="";this.clientId&&(i="?clientId="+this.clientId),this.socket=new(0,this.WebSocket)("ws"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+"/ws"+i,[],{headers:e({},this._authHeader)}),this.socket.binaryType="arraybuffer",this.addSocketCallback(this.socket,"open",function(){o=!0,r&&n.events.emit("reconnected")}),this.addSocketCallback(this.socket,"error",function(){n.socket&&n.socket.close(),r||o||n.startPollingQueue()}),this.addSocketCallback(this.socket,"close",function(){setTimeout(function(){n.socket=null,n.createSocket(!0)},300),o&&(n.events.emit("status",null),n.events.emit("reconnecting"))}),this.addSocketCallback(this.socket,"message",function(e){n.events.emit("message",e);try{if(function(e){return"string"!=typeof e.data&&(t.IS_BROWSER?e.data instanceof Blob:!!(ArrayBuffer&&e.data instanceof ArrayBuffer)||!(!Buffer||!Buffer.isBuffer(e.data)))}(e)){var r=t.loadImageData(e.data);n.events.emit("image_data",r)}else{var o=JSON.parse(e.data);switch(o.type){case"status":o.data.sid&&(n.clientId=o.data.sid),n.events.emit("status",o.data.status);break;case"progress":n.events.emit("progress",o.data);break;case"executing":n.events.emit("executing",o.data);break;case"executed":n.events.emit("executed",o.data);break;case"execution_start":n.events.emit("execution_start",o.data);break;case"execution_error":n.events.emit("execution_error",o.data);break;case"execution_cached":n.events.emit("execution_cached",o.data);break;case"execution_interrupted":n.events.emit("execution_interrupted",o.data);break;default:if(!n.registered.has(o.type))throw new Error("Unknown message type "+o.type);n.events.emit(o.type,o.data)}}}catch(t){console.warn("Unhandled message:",e.data,t)}})}},r.init=function(){this.createSocket()},r.close=function(){this.closed||(this.closed=!0,this.disconnect(),this.events.removeAllListeners())},r.connect=function(e){var t,r=void 0===e?{}:e,n=r.polling,o=void 0===n?{enabled:!1}:n,i=r.websocket,s=void 0===i?{enabled:!0}:i;return null!=o&&o.enabled&&(this._polling_interval=null!=(t=o.interval)?t:this._polling_interval,this.startPollingQueue()),null!=s&&s.enabled&&this.createSocket(),this},r.disconnect=function(){this._disconnectSocket(),this._disconnectPolling()},r._disconnectSocket=function(){var e=this.socket;e&&(this.socket=null,e.readyState===this.WebSocket.OPEN&&e.close(1e3,"Client closed"),this.removeSocketCallbacks(),"removeAllListeners"in e&&(null==e.removeAllListeners||e.removeAllListeners()))},r._disconnectPolling=function(){null!==this._polling_timer&&(clearInterval(this._polling_timer),this._polling_timer=null)},t}();c.DEFAULT_API_HOST="127.0.0.1:8188",c.DEFAULT_API_BASE="",c.DEFAULT_USER="",c.IS_BROWSER="undefined"!=typeof window;var a=/*#__PURE__*/function(){function e(){this._cached=void 0,this._cached=globalThis[e.KEY]||new Map,globalThis[e.KEY]=this._cached}var t=e.prototype;return t.clear=function(){this._cached.clear()},t.get=function(e){return this._cached.get(e)},t.set=function(e,t){this._cached.set(e,t)},e}();a.KEY="__COMFY_UI_CLIENT_CACHE__";var l=/*#__PURE__*/function(){function e(t,r){var n,o;this.expire_time_ms=void 0,this.enabled=void 0,this._cached=new a,this.cache_ns="",this.expire_time_ms=null!=(n=null==r?void 0:r.expire_time)?n:e._defaultExpire,this.enabled=null==(o=null==r?void 0:r.enabled)||o,this.cache_ns=t}var t=e.prototype;return t.reset=function(){this._cached.clear()},t._hashArgs=function(e){try{return JSON.stringify(e)}catch(t){return e.toString()}},t.warp=function(e,t){var r=this;return this.enabled?function(){var n=[].slice.call(arguments),o=Date.now(),i=r._hashArgs(n),s=r.cache_ns+":"+e+":"+i,u=r._cached.get(s);if(u&&u.expire>o)return u.result;var c=t.apply(void 0,n);return r._cached.set(s,{result:c,expire:o+r.expire_time_ms}),c}:t},e}();function h(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}function f(e,t,r){if(!e.s){if(r instanceof d){if(!r.s)return void(r.o=f.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(f.bind(null,e,t),f.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}l._defaultExpire=6e4;var d=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{f(n,1,i(this.v))}catch(e){f(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?f(n,1,t?t(o):o):r?f(n,1,r(o)):f(n,2,o)}catch(e){f(n,2,e)}},n},e}();function p(e){return e instanceof d&&1&e.s}var v=/*#__PURE__*/function(r){function o(e){var t;return(t=r.call(this,e)||this)._cached_fn=void 0,t._cached_fn=new l(""+e.api_host,e.cache),t._authHeader=""!==t.auth?{Authorization:""+t.auth}:{},t}var i,s;s=r,(i=o).prototype=Object.create(s.prototype),i.prototype.constructor=i,t(i,s);var c=o.prototype;return c.getExtensions=function(){try{var t=this,r=t._cached_fn.warp("extensions",function(){try{return Promise.resolve(t.fetchApi("/extensions",{cache:"no-store",headers:e({},t._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.getEmbeddings=function(){try{var t=this,r=t._cached_fn.warp("embeddings",function(){try{return Promise.resolve(t.fetchApi("/embeddings",{cache:"no-store",headers:e({},t._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.getNodeDefs=function(){try{var t=this,r=t._cached_fn.warp("object_info",function(){try{return Promise.resolve(t.fetchApi("/object_info",{cache:"no-store",headers:e({},t._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.resetCache=function(){this._cached_fn.reset()},c.queuePrompt=function(t,r){var n=r.prompt,o=r.workflow;try{var i=this,s={client_id:i.clientId,prompt:n,extra_data:{extra_pnginfo:{workflow:o}}};return-1===t?s.front=!0:0!==t&&(s.number=t),Promise.resolve(i.fetchApi("/prompt",{method:"POST",headers:e({"Content-Type":"application/json"},i._authHeader),body:JSON.stringify(s)})).then(function(e){function t(t){return Promise.resolve(e.json())}var r=function(){if(200!==e.status)return Promise.resolve(e.text()).then(function(e){try{throw{response:JSON.parse(e)}}catch(t){throw{response:e}}})}();return r&&r.then?r.then(t):t()})}catch(e){return Promise.reject(e)}},c.getItems=function(e){try{return Promise.resolve("queue"===e?this.getQueue():this.getHistory())}catch(e){return Promise.reject(e)}},c.getQueue=function(){try{var t=this;return Promise.resolve(h(function(){return Promise.resolve(t.fetchApi("/queue",{headers:e({},t._authHeader)})).then(function(e){return Promise.resolve(e.json()).then(function(e){return{Running:e.queue_running.map(function(e){return{prompt:e,remove:{name:"Cancel",cb:function(){return t.interrupt()}}}}),Pending:e.queue_pending.map(function(e){return{prompt:e}})}})})},function(e){return console.error(e),{Running:[],Pending:[]}}))}catch(e){return Promise.reject(e)}},c.getHistory=function(t){void 0===t&&(t=200);try{var r=this;return Promise.resolve(h(function(){return Promise.resolve(r.fetchApi("/history?max_items="+t,{headers:e({},r._authHeader)})).then(function(e){return Promise.resolve(e.json()).then(function(e){return{History:Object.values(e)}})})},function(e){return console.error(e),{History:[]}}))}catch(e){return Promise.reject(e)}},c.getSystemStats=function(){try{return Promise.resolve(this.fetchApi("/system_stats",{headers:e({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.postApi=function(t,r){try{return Promise.resolve(this.fetchApi("/"+t,{method:"POST",headers:e({"Content-Type":"application/json"},this._authHeader),body:r?JSON.stringify(r):void 0})).then(function(){})}catch(e){return Promise.reject(e)}},c.deleteItem=function(e,t){try{return Promise.resolve(this.postApi(e,{delete:[t]})).then(function(){})}catch(e){return Promise.reject(e)}},c.clearItems=function(e){try{return Promise.resolve(this.postApi(e,{clear:!0})).then(function(){})}catch(e){return Promise.reject(e)}},c.interrupt=function(){try{return Promise.resolve(this.postApi("interrupt",null)).then(function(){})}catch(e){return Promise.reject(e)}},c.free=function(e){try{return Promise.resolve(this.postApi("free",e)).then(function(){})}catch(e){return Promise.reject(e)}},c.getUserConfig=function(){try{return Promise.resolve(this.fetchApi("/users",{headers:e({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.createUser=function(t){try{return Promise.resolve(this.fetchApi("/users",{method:"POST",headers:e({"Content-Type":"application/json"},this._authHeader),body:JSON.stringify({username:t})}))}catch(e){return Promise.reject(e)}},c.getSettings=function(){try{return Promise.resolve(this.fetchApi("/settings",{headers:e({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.getSetting=function(t){try{return Promise.resolve(this.fetchApi("/settings/"+encodeURIComponent(t),{headers:e({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.storeSettings=function(t){try{return Promise.resolve(this.fetchApi("/settings",{method:"POST",body:JSON.stringify(t),headers:e({},this._authHeader)}))}catch(e){return Promise.reject(e)}},c.storeSetting=function(t,r){try{return Promise.resolve(this.fetchApi("/settings/"+encodeURIComponent(t),{method:"POST",body:JSON.stringify(r),headers:e({},this._authHeader)}))}catch(e){return Promise.reject(e)}},c.getUserData=function(e,t){try{return Promise.resolve(this.fetchApi("/userdata/"+encodeURIComponent(e),t))}catch(e){return Promise.reject(e)}},c.storeUserData=function(t,r,n){try{return Promise.resolve(this.fetchApi("/userdata/"+encodeURIComponent(t),e({method:"POST",body:null!=n&&n.stringify?JSON.stringify(r):r,headers:e({},this._authHeader)},n))).then(function(e){return function(){if(200!==e.status)return Promise.resolve(e.text()).then(function(r){throw new Error("Error storing user data file '"+t+"': "+e.status+" "+r)})}()})}catch(e){return Promise.reject(e)}},c.getSamplers=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.KSampler;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.sampler_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getSchedulers=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.KSampler;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.scheduler)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getSDModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.CheckpointLoaderSimple;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.ckpt_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getCNetModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.ControlNetLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.control_net_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getUpscaleModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.UpscaleModelLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.model_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getHyperNetworks=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.HypernetworkLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.hypernetwork_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getLoRAs=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.LoraLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.lora_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getVAEs=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.VAELoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.vae_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getPromptStatus=function(e){try{return Promise.resolve(this.getQueue()).then(function(t){var r=t.Pending,n=t.Running.some(function(t){var r;return(null==t||null==(r=t.prompt)?void 0:r[1])===e}),o=r.some(function(t){var r;return(null==t||null==(r=t.prompt)?void 0:r[1])===e});return{running:n,pending:o,done:!n&&!o}})}catch(e){return Promise.reject(e)}},c.getPromptOutputs=function(e){try{return Promise.resolve(this.getHistory()).then(function(t){var r=t.History.find(function(t){return t.prompt[1]===e});if(!r)throw new Error("Prompt ["+e+"] not found in history");var n=r.status.status_str;if("success"!==n)throw new Error("Prompt ["+e+"] failed with status: "+n);return r.outputs})}catch(e){return Promise.reject(e)}},c.getPromptImageResult=function(e){try{var t=this;return Promise.resolve(t.getPromptOutputs(e)).then(function(r){return{images:Object.values(r).flatMap(function(e){return e.images||[]}).map(function(e){var r=e.filename,n=e.subfolder,o=e.type;return u(r)||u(n)||"output"!==o?null:t.viewURL(r,n,o)}).filter(Boolean).map(function(e){return{type:"url",data:e}}),prompt_id:e}})}catch(e){return Promise.reject(e)}},c.waitForPrompt=function(e,t){void 0===t&&(t=1e3);try{var r=this;return Promise.resolve(r.getPromptStatus(e)).then(function(n){var o=function(e,t,r){for(var n;;){var o=e();if(p(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!p(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!p(s)){n=2;break}}}var u=new d,c=f.bind(null,u,2);return(0===n?o.then(l):1===n?i.then(a):s.then(h)).then(void 0,c),u;function a(n){i=n;do{if(t&&(s=t())&&s.then&&!p(s))return void s.then(h).then(void 0,c);if(!(o=e())||p(o)&&!o.v)return void f(u,1,i);if(o.then)return void o.then(l).then(void 0,c);p(i=r())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,c)}function l(e){e?(i=r())&&i.then?i.then(a).then(void 0,c):a(i):f(u,1,i)}function h(){(o=e())?o.then?o.then(l).then(void 0,c):l(o):f(u,1,i)}}(function(){return!n.done},void 0,function(){return Promise.resolve(new Promise(function(e){return setTimeout(e,t)})).then(function(){return Promise.resolve(r.getPromptStatus(e)).then(function(e){n=e})})});if(o&&o.then)return o.then(function(){})})}catch(e){return Promise.reject(e)}},c.waitForPromptWebSocket=function(e){try{var t=this,r={images:[],prompt_id:e};return Promise.resolve(new Promise(function(o,i){var s=t.on("image_data",function(e){r.images.push({type:"buff",data:e})}),c=t.on("executed",function(i){if(i.prompt_id===e){for(var a,l=(i.output||{}).images,h=n(void 0===l?[]:l);!(a=h()).done;){var f=a.value||{},d=f.filename,p=f.subfolder,v=f.type;u(d)||u(p)||"output"!==v||r.images.push({type:"url",data:t.viewURL(d,p,v)})}o(r),c(),s()}})}))}catch(e){return Promise.reject(e)}},c.randomizePrompt=function(e){for(var t=0,r=Object.values(e);t<r.length;t++){var n=r[t];"KSampler"===n.class_type&&(n.inputs.seed=Math.floor(Math.random()*(Math.pow(2,32)-1)))}},c._enqueue_prompt=function(e,t){try{return null!=t&&t.disable_random_seed||this.randomizePrompt(e),Promise.resolve(this.queuePrompt(0,{prompt:e,workflow:null==t?void 0:t.workflow})).then(function(e){if("error"in e)throw new Error(e.error);return e})}catch(e){return Promise.reject(e)}},c.runPrompt=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n=e.prompt_id;return Promise.resolve(r.waitForPrompt(n,null==t?void 0:t.polling_ms)).then(function(){return Promise.resolve(r.getPromptImageResult(n))})})}catch(e){return Promise.reject(e)}},c.enqueue_polling=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n=e.prompt_id;return Promise.resolve(r.waitForPrompt(n,null==t?void 0:t.polling_ms)).then(function(){return Promise.resolve(r.getPromptImageResult(n))})})}catch(e){return Promise.reject(e)}},c.enqueue=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n,o=e.prompt_id;return null!=t&&t.progress&&(n=r.on("progress",function(e){e.progress.prompt_id===o&&(null==t||null==t.progress||t.progress(e.progress))})),function(e,t){try{var n=Promise.resolve(r.waitForPromptWebSocket(o))}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,n)}(0,function(e,t){if(null==n||n(),e)throw t;return t})})}catch(e){return Promise.reject(e)}},o}(c),m=/*#__PURE__*/function(){function e(e,t){this.workflow=void 0,this.client=void 0,this._task_id=void 0,this._enqueue_req=void 0,this._result={images:[],prompt_id:""},this.executed=!1,this.workflow=e,this.client=t}var t=e.prototype;return t.enqueue=function(){var e=this,t=this.workflow;this._enqueue_req=this.client._enqueue_prompt(t.prompt,{workflow:t.workflow}),this._task_id=this._enqueue_req.then(function(e){return e.prompt_id}),this._enqueue_req.then(function(t){e._result.prompt_id=t.prompt_id})},t.load_result_data=function(e){for(var t,r=(e.output||{}).images,o=n(void 0===r?[]:r);!(t=o()).done;){var i=t.value||{},s=i.filename,c=i.subfolder,a=i.type;u(s)||u(c)||"output"!==a||this._result.images.push({type:"url",data:this.client.viewURL(s,c,a)})}},t.query=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be queried");var t=e.client,r=t.getPromptStatus;return Promise.resolve(e._task_id).then(function(e){return r.call(t,e)})}catch(e){return Promise.reject(e)}},t.interrupt=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be interrupt");return Promise.resolve(e._task_id).then(function(t){return Promise.resolve(e.query()).then(function(r){if(!r.done){if(!r.pending){if(r.running)return e.client.interrupt();throw new Error("wrong task status, id: "+t)}e.client.deleteItem("queue",t)}})})}catch(e){return Promise.reject(e)}},t.wait=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be wait");return Promise.resolve(e._task_id).then(function(t){return new Promise(function(r,n){var o,i;i=[],o=function(){return i.forEach(function(e){return e()})},i=[e.client.on("execution_interrupted",function(e){e.prompt_id===t&&(n(new Error("Execution Interrupted")),o())}),e.client.on("image_data",function(t){e.executed||e._result.images.push({type:"buff",data:t})}),e.client.on("executed",function(n){n.prompt_id===t&&(e.load_result_data(n),e.executed=!0,r(e._result),o())})]})})}catch(e){return Promise.reject(e)}},e}(),_=globalThis.structuredClone?globalThis.structuredClone:function(e){return JSON.parse(JSON.stringify(e))},y=/*#__PURE__*/function(){function e(){this._workflow={prompt:{}},this._last_node_id=0,this.classes=this._createClassesProxy()}var t=e.prototype;return t._createClassesProxy=function(){var e=this;return new Proxy({},{get:function(t,r,n){return r in t?t[r]:function(t){var n={class_type:r.toString(),inputs:t},o=(++e._last_node_id).toString();return e._workflow.prompt[o]=n,Array.from({length:10},function(e,t){return[o,t]})}}})},t.reset=function(){this._workflow.prompt={},this._workflow.workflow=void 0,this._last_node_id=0},t.end=function(){return this.workflow()},t.workflow=function(){return _(this._workflow)},t.invoke=function(e){var t=this.instance(e);return t.enqueue(),t.wait()},t.instance=function(e){var t=this.workflow();return new m({prompt:t.prompt,workflow:t.workflow},e)},t.invoke_polling=function(e){var t=this.workflow();return e.enqueue_polling(t.prompt,{workflow:t.workflow})},e}();exports.ComfyUIApiClient=v,exports.ComfyUIWorkflow=y,exports.ComfyUIWsClient=c; | ||
//# sourceMappingURL=main.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).comfyuiClient={})}(this,function(e){function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function o(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=function(e){var t={exports:{}};return function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function o(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function i(e,t,n,i,s){if("function"!=typeof n)throw new TypeError("The listener must be a function");var u=new o(n,i||e,s),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],u]:e._events[c].push(u):(e._events[c]=u,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function u(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),u.prototype.eventNames=function(){var e,n,o=[];if(0===this._eventsCount)return o;for(n in e=this._events)t.call(e,n)&&o.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},u.prototype.listeners=function(e){var t=this._events[r?r+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var n=0,o=t.length,i=new Array(o);n<o;n++)i[n]=t[n].fn;return i},u.prototype.listenerCount=function(e){var t=this._events[r?r+e:e];return t?t.fn?1:t.length:0},u.prototype.emit=function(e,t,n,o,i,s){var u=r?r+e:e;if(!this._events[u])return!1;var c,a,l=this._events[u],h=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),h){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,n),!0;case 4:return l.fn.call(l.context,t,n,o),!0;case 5:return l.fn.call(l.context,t,n,o,i),!0;case 6:return l.fn.call(l.context,t,n,o,i,s),!0}for(a=1,c=new Array(h-1);a<h;a++)c[a-1]=arguments[a];l.fn.apply(l.context,c)}else{var f,d=l.length;for(a=0;a<d;a++)switch(l[a].once&&this.removeListener(e,l[a].fn,void 0,!0),h){case 1:l[a].fn.call(l[a].context);break;case 2:l[a].fn.call(l[a].context,t);break;case 3:l[a].fn.call(l[a].context,t,n);break;case 4:l[a].fn.call(l[a].context,t,n,o);break;default:if(!c)for(f=1,c=new Array(h-1);f<h;f++)c[f-1]=arguments[f];l[a].fn.apply(l[a].context,c)}}return!0},u.prototype.on=function(e,t,r){return i(this,e,t,r,!1)},u.prototype.once=function(e,t,r){return i(this,e,t,r,!0)},u.prototype.removeListener=function(e,t,n,o){var i=r?r+e:e;if(!this._events[i])return this;if(!t)return s(this,i),this;var u=this._events[i];if(u.fn)u.fn!==t||o&&!u.once||n&&u.context!==n||s(this,i);else{for(var c=0,a=[],l=u.length;c<l;c++)(u[c].fn!==t||o&&!u[c].once||n&&u[c].context!==n)&&a.push(u[c]);a.length?this._events[i]=1===a.length?a[0]:a:s(this,i)}return this},u.prototype.removeAllListeners=function(e){var t;return e?this._events[t=r?r+e:e]&&s(this,t):(this._events=new n,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=r,u.EventEmitter=u,e.exports=u}(t),t.exports}(),s=function(e){return null==e},u=/*#__PURE__*/function(){function e(t){var r,n,o,s,u,c,a,l;if(this._authHeader=void 0,this.auth=void 0,this.api_host=void 0,this.api_base=void 0,this.clientId=void 0,this.socket=void 0,this.WebSocket=void 0,this.ssl=void 0,this.user=void 0,this.fetch=void 0,this.events=new i,this.registered=new Set,this.socket_callbacks={},this._polling_timer=null,this._polling_interval=1e3,this.closed=!1,this.auth=null!=(r=t.auth)?r:"",this.api_host=null!=(n=t.api_host)?n:e.DEFAULT_API_HOST,this.api_base=null!=(o=t.api_base)?o:e.DEFAULT_API_BASE,this.clientId=null!=(s=t.clientId)?s:"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),this.WebSocket=null!=(u=t.WebSocket)?u:WebSocket,this.ssl=null!=(c=t.ssl)&&c,this.user=null!=(a=t.user)?a:e.DEFAULT_USER,!globalThis.fetch)throw new Error("fetch is not defined");this.fetch=null!=(l=t.fetch)?l:globalThis.fetch.bind(globalThis),this._authHeader=""!==this.auth?{Authorization:""+this.auth}:{}}e.loadImageData=function(e){var t=new DataView(e).getUint32(0);if(1===t)return new DataView(e).getUint32(0),e.slice(8);throw new Error("Unknown binary websocket message of type "+t)};var r=e.prototype;return r.apiURL=function(e){return"http"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+e},r.viewURL=function(e,t,r){var n=new URLSearchParams({filename:e,subfolder:t,type:r}).toString();return"http"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+"/view?"+n},r.fetchApi=function(e,r){try{var n,o=this;if(o.closed)throw new Error("Client is closed");var i=t({},o.user?{"Comfy-User":o.user}:{},{Accept:"*/*"},null!=(n=null==r?void 0:r.headers)?n:{}),s=o.apiURL(e);return Promise.resolve(o.fetch(s,t({},r,{headers:i})))}catch(e){return Promise.reject(e)}},r.addEventListener=function(e,t,r){var n=this;return this.events.on(e,t,r),this.registered.add(e),function(){n.events.off(e,t),n.registered.delete(e)}},r.on=function(e,t,r){return this.addEventListener(e,t,r)},r.startPollingQueue=function(){var e=this;this._polling_timer||(this._polling_timer=setInterval(function(){try{var t=function(t,r){try{var n=Promise.resolve(e.fetchApi("/prompt")).then(function(t){return Promise.resolve(t.json()).then(function(t){e.events.emit("status",t)})})}catch(e){return r()}return n&&n.then?n.then(void 0,r):n}(0,function(){e.events.emit("status",null)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},this._polling_interval))},r.addSocketCallback=function(e,t,r,n){var o=this;return this.socket_callbacks[t]=r,e.addEventListener(t,r,n),function(){delete o.socket_callbacks[t],e.removeEventListener(t,r,n)}},r.removeSocketCallbacks=function(){if(this.socket)for(var e in this.socket_callbacks)this.socket.removeEventListener(e,this.socket_callbacks[e]);this.socket_callbacks={}},r.createSocket=function(t){var r=this;if(void 0===t&&(t=!1),!this.socket){var n=!1,o="";this.clientId&&(o="?clientId="+this.clientId),this.socket=new(0,this.WebSocket)("ws"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+"/ws"+o,[],{headers:{Cookie:"ai_dock_token=dXNlcjpwYXNzd29yZA==;"}}),this.socket.binaryType="arraybuffer",this.addSocketCallback(this.socket,"open",function(){n=!0,t&&r.events.emit("reconnected")}),this.addSocketCallback(this.socket,"error",function(){r.socket&&r.socket.close(),t||n||r.startPollingQueue()}),this.addSocketCallback(this.socket,"close",function(){setTimeout(function(){r.socket=null,r.createSocket(!0)},300),n&&(r.events.emit("status",null),r.events.emit("reconnecting"))}),this.addSocketCallback(this.socket,"message",function(t){r.events.emit("message",t);try{if(function(t){return"string"!=typeof t.data&&(e.IS_BROWSER?t.data instanceof Blob:!!(ArrayBuffer&&t.data instanceof ArrayBuffer)||!(!Buffer||!Buffer.isBuffer(t.data)))}(t)){var n=e.loadImageData(t.data);r.events.emit("image_data",n)}else{var o=JSON.parse(t.data);switch(o.type){case"status":o.data.sid&&(r.clientId=o.data.sid),r.events.emit("status",o.data.status);break;case"progress":r.events.emit("progress",o.data);break;case"executing":r.events.emit("executing",o.data);break;case"executed":r.events.emit("executed",o.data);break;case"execution_start":r.events.emit("execution_start",o.data);break;case"execution_error":r.events.emit("execution_error",o.data);break;case"execution_cached":r.events.emit("execution_cached",o.data);break;case"execution_interrupted":r.events.emit("execution_interrupted",o.data);break;default:if(!r.registered.has(o.type))throw new Error("Unknown message type "+o.type);r.events.emit(o.type,o.data)}}}catch(e){console.warn("Unhandled message:",t.data,e)}})}},r.init=function(){this.createSocket()},r.close=function(){this.closed||(this.closed=!0,this.disconnect(),this.events.removeAllListeners())},r.connect=function(e){var t,r=void 0===e?{}:e,n=r.polling,o=void 0===n?{enabled:!1}:n,i=r.websocket,s=void 0===i?{enabled:!0}:i;return null!=o&&o.enabled&&(this._polling_interval=null!=(t=o.interval)?t:this._polling_interval,this.startPollingQueue()),null!=s&&s.enabled&&this.createSocket(),this},r.disconnect=function(){this._disconnectSocket(),this._disconnectPolling()},r._disconnectSocket=function(){var e=this.socket;e&&(this.socket=null,e.readyState===this.WebSocket.OPEN&&e.close(1e3,"Client closed"),this.removeSocketCallbacks(),"removeAllListeners"in e&&(null==e.removeAllListeners||e.removeAllListeners()))},r._disconnectPolling=function(){null!==this._polling_timer&&(clearInterval(this._polling_timer),this._polling_timer=null)},e}();u.DEFAULT_API_HOST="127.0.0.1:8188",u.DEFAULT_API_BASE="",u.DEFAULT_USER="",u.IS_BROWSER="undefined"!=typeof window;var c=/*#__PURE__*/function(){function e(){this._cached=void 0,this._cached=globalThis[e.KEY]||new Map,globalThis[e.KEY]=this._cached}var t=e.prototype;return t.clear=function(){this._cached.clear()},t.get=function(e){return this._cached.get(e)},t.set=function(e,t){this._cached.set(e,t)},e}();c.KEY="__COMFY_UI_CLIENT_CACHE__";var a=/*#__PURE__*/function(){function e(t,r){var n,o;this.expire_time_ms=void 0,this.enabled=void 0,this._cached=new c,this.cache_ns="",this.expire_time_ms=null!=(n=null==r?void 0:r.expire_time)?n:e._defaultExpire,this.enabled=null==(o=null==r?void 0:r.enabled)||o,this.cache_ns=t}var t=e.prototype;return t.reset=function(){this._cached.clear()},t._hashArgs=function(e){try{return JSON.stringify(e)}catch(t){return e.toString()}},t.warp=function(e,t){var r=this;return this.enabled?function(){var n=[].slice.call(arguments),o=Date.now(),i=r._hashArgs(n),s=r.cache_ns+":"+e+":"+i,u=r._cached.get(s);if(u&&u.expire>o)return u.result;var c=t.apply(void 0,n);return r._cached.set(s,{result:c,expire:o+r.expire_time_ms}),c}:t},e}();function l(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}function h(e,t,r){if(!e.s){if(r instanceof f){if(!r.s)return void(r.o=h.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(h.bind(null,e,t),h.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}a._defaultExpire=6e4;var f=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{h(n,1,i(this.v))}catch(e){h(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?h(n,1,t?t(o):o):r?h(n,1,r(o)):h(n,2,o)}catch(e){h(n,2,e)}},n},e}();function d(e){return e instanceof f&&1&e.s}var p=/*#__PURE__*/function(e){function n(t){var r;return(r=e.call(this,t)||this)._cached_fn=void 0,r._cached_fn=new a(""+t.api_host,t.cache),r._authHeader=""!==r.auth?{Authorization:""+r.auth}:{},r}var i,u;u=e,(i=n).prototype=Object.create(u.prototype),i.prototype.constructor=i,r(i,u);var c=n.prototype;return c.getExtensions=function(){try{var e=this,r=e._cached_fn.warp("extensions",function(){try{return Promise.resolve(e.fetchApi("/extensions",{cache:"no-store",headers:t({},e._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.getEmbeddings=function(){try{var e=this,r=e._cached_fn.warp("embeddings",function(){try{return Promise.resolve(e.fetchApi("/embeddings",{cache:"no-store",headers:t({},e._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.getNodeDefs=function(){try{var e=this,r=e._cached_fn.warp("object_info",function(){try{return Promise.resolve(e.fetchApi("/object_info",{cache:"no-store",headers:t({},e._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.resetCache=function(){this._cached_fn.reset()},c.queuePrompt=function(e,r){var n=r.prompt,o=r.workflow;try{var i=this,s={client_id:i.clientId,prompt:n,extra_data:{extra_pnginfo:{workflow:o}}};return-1===e?s.front=!0:0!==e&&(s.number=e),Promise.resolve(i.fetchApi("/prompt",{method:"POST",headers:t({"Content-Type":"application/json"},i._authHeader),body:JSON.stringify(s)})).then(function(e){function t(t){return Promise.resolve(e.json())}var r=function(){if(200!==e.status)return Promise.resolve(e.text()).then(function(e){try{throw{response:JSON.parse(e)}}catch(t){throw{response:e}}})}();return r&&r.then?r.then(t):t()})}catch(e){return Promise.reject(e)}},c.getItems=function(e){try{return Promise.resolve("queue"===e?this.getQueue():this.getHistory())}catch(e){return Promise.reject(e)}},c.getQueue=function(){try{var e=this;return Promise.resolve(l(function(){return Promise.resolve(e.fetchApi("/queue",{headers:t({},e._authHeader)})).then(function(t){return Promise.resolve(t.json()).then(function(t){return{Running:t.queue_running.map(function(t){return{prompt:t,remove:{name:"Cancel",cb:function(){return e.interrupt()}}}}),Pending:t.queue_pending.map(function(e){return{prompt:e}})}})})},function(e){return console.error(e),{Running:[],Pending:[]}}))}catch(e){return Promise.reject(e)}},c.getHistory=function(e){void 0===e&&(e=200);try{var r=this;return Promise.resolve(l(function(){return Promise.resolve(r.fetchApi("/history?max_items="+e,{headers:t({},r._authHeader)})).then(function(e){return Promise.resolve(e.json()).then(function(e){return{History:Object.values(e)}})})},function(e){return console.error(e),{History:[]}}))}catch(e){return Promise.reject(e)}},c.getSystemStats=function(){try{return Promise.resolve(this.fetchApi("/system_stats",{headers:t({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.postApi=function(e,r){try{return Promise.resolve(this.fetchApi("/"+e,{method:"POST",headers:t({"Content-Type":"application/json"},this._authHeader),body:r?JSON.stringify(r):void 0})).then(function(){})}catch(e){return Promise.reject(e)}},c.deleteItem=function(e,t){try{return Promise.resolve(this.postApi(e,{delete:[t]})).then(function(){})}catch(e){return Promise.reject(e)}},c.clearItems=function(e){try{return Promise.resolve(this.postApi(e,{clear:!0})).then(function(){})}catch(e){return Promise.reject(e)}},c.interrupt=function(){try{return Promise.resolve(this.postApi("interrupt",null)).then(function(){})}catch(e){return Promise.reject(e)}},c.free=function(e){try{return Promise.resolve(this.postApi("free",e)).then(function(){})}catch(e){return Promise.reject(e)}},c.getUserConfig=function(){try{return Promise.resolve(this.fetchApi("/users",{headers:t({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.createUser=function(e){try{return Promise.resolve(this.fetchApi("/users",{method:"POST",headers:t({"Content-Type":"application/json"},this._authHeader),body:JSON.stringify({username:e})}))}catch(e){return Promise.reject(e)}},c.getSettings=function(){try{return Promise.resolve(this.fetchApi("/settings",{headers:t({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.getSetting=function(e){try{return Promise.resolve(this.fetchApi("/settings/"+encodeURIComponent(e),{headers:t({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.storeSettings=function(e){try{return Promise.resolve(this.fetchApi("/settings",{method:"POST",body:JSON.stringify(e),headers:t({},this._authHeader)}))}catch(e){return Promise.reject(e)}},c.storeSetting=function(e,r){try{return Promise.resolve(this.fetchApi("/settings/"+encodeURIComponent(e),{method:"POST",body:JSON.stringify(r),headers:t({},this._authHeader)}))}catch(e){return Promise.reject(e)}},c.getUserData=function(e,t){try{return Promise.resolve(this.fetchApi("/userdata/"+encodeURIComponent(e),t))}catch(e){return Promise.reject(e)}},c.storeUserData=function(e,r,n){try{return Promise.resolve(this.fetchApi("/userdata/"+encodeURIComponent(e),t({method:"POST",body:null!=n&&n.stringify?JSON.stringify(r):r,headers:t({},this._authHeader)},n))).then(function(t){return function(){if(200!==t.status)return Promise.resolve(t.text()).then(function(r){throw new Error("Error storing user data file '"+e+"': "+t.status+" "+r)})}()})}catch(e){return Promise.reject(e)}},c.getSamplers=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.KSampler;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.sampler_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getSchedulers=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.KSampler;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.scheduler)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getSDModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.CheckpointLoaderSimple;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.ckpt_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getCNetModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.ControlNetLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.control_net_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getUpscaleModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.UpscaleModelLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.model_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getHyperNetworks=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.HypernetworkLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.hypernetwork_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getLoRAs=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.LoraLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.lora_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getVAEs=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.VAELoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.vae_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getPromptStatus=function(e){try{return Promise.resolve(this.getQueue()).then(function(t){var r=t.Pending,n=t.Running.some(function(t){var r;return(null==t||null==(r=t.prompt)?void 0:r[1])===e}),o=r.some(function(t){var r;return(null==t||null==(r=t.prompt)?void 0:r[1])===e});return{running:n,pending:o,done:!n&&!o}})}catch(e){return Promise.reject(e)}},c.getPromptOutputs=function(e){try{return Promise.resolve(this.getHistory()).then(function(t){var r=t.History.find(function(t){return t.prompt[1]===e});if(!r)throw new Error("Prompt ["+e+"] not found in history");var n=r.status.status_str;if("success"!==n)throw new Error("Prompt ["+e+"] failed with status: "+n);return r.outputs})}catch(e){return Promise.reject(e)}},c.getPromptImageResult=function(e){try{var t=this;return Promise.resolve(t.getPromptOutputs(e)).then(function(r){return{images:Object.values(r).flatMap(function(e){return e.images||[]}).map(function(e){var r=e.filename,n=e.subfolder,o=e.type;return s(r)||s(n)||"output"!==o?null:t.viewURL(r,n,o)}).filter(Boolean).map(function(e){return{type:"url",data:e}}),prompt_id:e}})}catch(e){return Promise.reject(e)}},c.waitForPrompt=function(e,t){void 0===t&&(t=1e3);try{var r=this;return Promise.resolve(r.getPromptStatus(e)).then(function(n){var o=function(e,t,r){for(var n;;){var o=e();if(d(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!d(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!d(s)){n=2;break}}}var u=new f,c=h.bind(null,u,2);return(0===n?o.then(l):1===n?i.then(a):s.then(p)).then(void 0,c),u;function a(n){i=n;do{if(t&&(s=t())&&s.then&&!d(s))return void s.then(p).then(void 0,c);if(!(o=e())||d(o)&&!o.v)return void h(u,1,i);if(o.then)return void o.then(l).then(void 0,c);d(i=r())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,c)}function l(e){e?(i=r())&&i.then?i.then(a).then(void 0,c):a(i):h(u,1,i)}function p(){(o=e())?o.then?o.then(l).then(void 0,c):l(o):h(u,1,i)}}(function(){return!n.done},void 0,function(){return Promise.resolve(new Promise(function(e){return setTimeout(e,t)})).then(function(){return Promise.resolve(r.getPromptStatus(e)).then(function(e){n=e})})});if(o&&o.then)return o.then(function(){})})}catch(e){return Promise.reject(e)}},c.waitForPromptWebSocket=function(e){try{var t=this,r={images:[],prompt_id:e};return Promise.resolve(new Promise(function(n,i){var u=t.on("image_data",function(e){r.images.push({type:"buff",data:e})}),c=t.on("executed",function(i){if(i.prompt_id===e){for(var a,l=(i.output||{}).images,h=o(void 0===l?[]:l);!(a=h()).done;){var f=a.value||{},d=f.filename,p=f.subfolder,v=f.type;s(d)||s(p)||"output"!==v||r.images.push({type:"url",data:t.viewURL(d,p,v)})}n(r),c(),u()}})}))}catch(e){return Promise.reject(e)}},c.randomizePrompt=function(e){for(var t=0,r=Object.values(e);t<r.length;t++){var n=r[t];"KSampler"===n.class_type&&(n.inputs.seed=Math.floor(Math.random()*(Math.pow(2,32)-1)))}},c._enqueue_prompt=function(e,t){try{return null!=t&&t.disable_random_seed||this.randomizePrompt(e),Promise.resolve(this.queuePrompt(0,{prompt:e,workflow:null==t?void 0:t.workflow})).then(function(e){if("error"in e)throw new Error(e.error);return e})}catch(e){return Promise.reject(e)}},c.runPrompt=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n=e.prompt_id;return Promise.resolve(r.waitForPrompt(n,null==t?void 0:t.polling_ms)).then(function(){return Promise.resolve(r.getPromptImageResult(n))})})}catch(e){return Promise.reject(e)}},c.enqueue_polling=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n=e.prompt_id;return Promise.resolve(r.waitForPrompt(n,null==t?void 0:t.polling_ms)).then(function(){return Promise.resolve(r.getPromptImageResult(n))})})}catch(e){return Promise.reject(e)}},c.enqueue=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n,o=e.prompt_id;return null!=t&&t.progress&&(n=r.on("progress",function(e){e.progress.prompt_id===o&&(null==t||null==t.progress||t.progress(e.progress))})),function(e,t){try{var n=Promise.resolve(r.waitForPromptWebSocket(o))}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,n)}(0,function(e,t){if(null==n||n(),e)throw t;return t})})}catch(e){return Promise.reject(e)}},n}(u),v=/*#__PURE__*/function(){function e(e,t){this.workflow=void 0,this.client=void 0,this._task_id=void 0,this._enqueue_req=void 0,this._result={images:[],prompt_id:""},this.executed=!1,this.workflow=e,this.client=t}var t=e.prototype;return t.enqueue=function(){var e=this,t=this.workflow;this._enqueue_req=this.client._enqueue_prompt(t.prompt,{workflow:t.workflow}),this._task_id=this._enqueue_req.then(function(e){return e.prompt_id}),this._enqueue_req.then(function(t){e._result.prompt_id=t.prompt_id})},t.load_result_data=function(e){for(var t,r=(e.output||{}).images,n=o(void 0===r?[]:r);!(t=n()).done;){var i=t.value||{},u=i.filename,c=i.subfolder,a=i.type;s(u)||s(c)||"output"!==a||this._result.images.push({type:"url",data:this.client.viewURL(u,c,a)})}},t.query=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be queried");var t=e.client,r=t.getPromptStatus;return Promise.resolve(e._task_id).then(function(e){return r.call(t,e)})}catch(e){return Promise.reject(e)}},t.interrupt=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be interrupt");return Promise.resolve(e._task_id).then(function(t){return Promise.resolve(e.query()).then(function(r){if(!r.done){if(!r.pending){if(r.running)return e.client.interrupt();throw new Error("wrong task status, id: "+t)}e.client.deleteItem("queue",t)}})})}catch(e){return Promise.reject(e)}},t.wait=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be wait");return Promise.resolve(e._task_id).then(function(t){return new Promise(function(r,n){var o,i;o=[],i=function(){return o.forEach(function(e){return e()})},o=[e.client.on("execution_interrupted",function(e){e.prompt_id===t&&(n(new Error("Execution Interrupted")),i())}),e.client.on("image_data",function(t){e.executed||e._result.images.push({type:"buff",data:t})}),e.client.on("executed",function(n){n.prompt_id===t&&(e.load_result_data(n),e.executed=!0,r(e._result),i())})]})})}catch(e){return Promise.reject(e)}},e}(),m=globalThis.structuredClone?globalThis.structuredClone:function(e){return JSON.parse(JSON.stringify(e))},_=/*#__PURE__*/function(){function e(){this._workflow={prompt:{}},this._last_node_id=0,this.classes=this._createClassesProxy()}var t=e.prototype;return t._createClassesProxy=function(){var e=this;return new Proxy({},{get:function(t,r,n){return r in t?t[r]:function(t){var n={class_type:r.toString(),inputs:t},o=(++e._last_node_id).toString();return e._workflow.prompt[o]=n,Array.from({length:10},function(e,t){return[o,t]})}}})},t.reset=function(){this._workflow.prompt={},this._workflow.workflow=void 0,this._last_node_id=0},t.end=function(){return this.workflow()},t.workflow=function(){return m(this._workflow)},t.invoke=function(e){var t=this.instance(e);return t.enqueue(),t.wait()},t.instance=function(e){var t=this.workflow();return new v({prompt:t.prompt,workflow:t.workflow},e)},t.invoke_polling=function(e){var t=this.workflow();return e.enqueue_polling(t.prompt,{workflow:t.workflow})},e}();e.ComfyUIApiClient=p,e.ComfyUIWorkflow=_,e.ComfyUIWsClient=u}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).comfyuiClient={})}(this,function(e){function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function o(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=function(e){var t={exports:{}};return function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function o(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function i(e,t,n,i,s){if("function"!=typeof n)throw new TypeError("The listener must be a function");var u=new o(n,i||e,s),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],u]:e._events[c].push(u):(e._events[c]=u,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function u(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),u.prototype.eventNames=function(){var e,n,o=[];if(0===this._eventsCount)return o;for(n in e=this._events)t.call(e,n)&&o.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},u.prototype.listeners=function(e){var t=this._events[r?r+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var n=0,o=t.length,i=new Array(o);n<o;n++)i[n]=t[n].fn;return i},u.prototype.listenerCount=function(e){var t=this._events[r?r+e:e];return t?t.fn?1:t.length:0},u.prototype.emit=function(e,t,n,o,i,s){var u=r?r+e:e;if(!this._events[u])return!1;var c,a,l=this._events[u],h=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),h){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,n),!0;case 4:return l.fn.call(l.context,t,n,o),!0;case 5:return l.fn.call(l.context,t,n,o,i),!0;case 6:return l.fn.call(l.context,t,n,o,i,s),!0}for(a=1,c=new Array(h-1);a<h;a++)c[a-1]=arguments[a];l.fn.apply(l.context,c)}else{var f,d=l.length;for(a=0;a<d;a++)switch(l[a].once&&this.removeListener(e,l[a].fn,void 0,!0),h){case 1:l[a].fn.call(l[a].context);break;case 2:l[a].fn.call(l[a].context,t);break;case 3:l[a].fn.call(l[a].context,t,n);break;case 4:l[a].fn.call(l[a].context,t,n,o);break;default:if(!c)for(f=1,c=new Array(h-1);f<h;f++)c[f-1]=arguments[f];l[a].fn.apply(l[a].context,c)}}return!0},u.prototype.on=function(e,t,r){return i(this,e,t,r,!1)},u.prototype.once=function(e,t,r){return i(this,e,t,r,!0)},u.prototype.removeListener=function(e,t,n,o){var i=r?r+e:e;if(!this._events[i])return this;if(!t)return s(this,i),this;var u=this._events[i];if(u.fn)u.fn!==t||o&&!u.once||n&&u.context!==n||s(this,i);else{for(var c=0,a=[],l=u.length;c<l;c++)(u[c].fn!==t||o&&!u[c].once||n&&u[c].context!==n)&&a.push(u[c]);a.length?this._events[i]=1===a.length?a[0]:a:s(this,i)}return this},u.prototype.removeAllListeners=function(e){var t;return e?this._events[t=r?r+e:e]&&s(this,t):(this._events=new n,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=r,u.EventEmitter=u,e.exports=u}(t),t.exports}(),s=function(e){return null==e},u=/*#__PURE__*/function(){function e(t){var r,n,o,s,u,c,a,l;if(this._authHeader=void 0,this.auth=void 0,this.api_host=void 0,this.api_base=void 0,this.clientId=void 0,this.socket=void 0,this.WebSocket=void 0,this.ssl=void 0,this.user=void 0,this.fetch=void 0,this.events=new i,this.registered=new Set,this.socket_callbacks={},this._polling_timer=null,this._polling_interval=1e3,this.closed=!1,this.auth=null!=(r=t.auth)?r:"",this.api_host=null!=(n=t.api_host)?n:e.DEFAULT_API_HOST,this.api_base=null!=(o=t.api_base)?o:e.DEFAULT_API_BASE,this.clientId=null!=(s=t.clientId)?s:"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),this.WebSocket=null!=(u=t.WebSocket)?u:WebSocket,this.ssl=null!=(c=t.ssl)&&c,this.user=null!=(a=t.user)?a:e.DEFAULT_USER,!globalThis.fetch)throw new Error("fetch is not defined");this.fetch=null!=(l=t.fetch)?l:globalThis.fetch.bind(globalThis),this._authHeader=""!==this.auth?{Authorization:""+this.auth}:{}}e.loadImageData=function(e){var t=new DataView(e).getUint32(0);if(1===t)return new DataView(e).getUint32(0),e.slice(8);throw new Error("Unknown binary websocket message of type "+t)};var r=e.prototype;return r.apiURL=function(e){return"http"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+e},r.viewURL=function(e,t,r){var n=new URLSearchParams({filename:e,subfolder:t,type:r}).toString();return"http"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+"/view?"+n},r.fetchApi=function(e,r){try{var n,o=this;if(o.closed)throw new Error("Client is closed");var i=t({},o.user?{"Comfy-User":o.user}:{},{Accept:"*/*"},null!=(n=null==r?void 0:r.headers)?n:{}),s=o.apiURL(e);return Promise.resolve(o.fetch(s,t({},r,{headers:i})))}catch(e){return Promise.reject(e)}},r.addEventListener=function(e,t,r){var n=this;return this.events.on(e,t,r),this.registered.add(e),function(){n.events.off(e,t),n.registered.delete(e)}},r.on=function(e,t,r){return this.addEventListener(e,t,r)},r.startPollingQueue=function(){var e=this;this._polling_timer||(this._polling_timer=setInterval(function(){try{var t=function(t,r){try{var n=Promise.resolve(e.fetchApi("/prompt")).then(function(t){return Promise.resolve(t.json()).then(function(t){e.events.emit("status",t)})})}catch(e){return r()}return n&&n.then?n.then(void 0,r):n}(0,function(){e.events.emit("status",null)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},this._polling_interval))},r.addSocketCallback=function(e,t,r,n){var o=this;return this.socket_callbacks[t]=r,e.addEventListener(t,r,n),function(){delete o.socket_callbacks[t],e.removeEventListener(t,r,n)}},r.removeSocketCallbacks=function(){if(this.socket)for(var e in this.socket_callbacks)this.socket.removeEventListener(e,this.socket_callbacks[e]);this.socket_callbacks={}},r.createSocket=function(r){var n=this;if(void 0===r&&(r=!1),!this.socket){var o=!1,i="";this.clientId&&(i="?clientId="+this.clientId),this.socket=new(0,this.WebSocket)("ws"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+"/ws"+i,[],{headers:t({},this._authHeader)}),this.socket.binaryType="arraybuffer",this.addSocketCallback(this.socket,"open",function(){o=!0,r&&n.events.emit("reconnected")}),this.addSocketCallback(this.socket,"error",function(){n.socket&&n.socket.close(),r||o||n.startPollingQueue()}),this.addSocketCallback(this.socket,"close",function(){setTimeout(function(){n.socket=null,n.createSocket(!0)},300),o&&(n.events.emit("status",null),n.events.emit("reconnecting"))}),this.addSocketCallback(this.socket,"message",function(t){n.events.emit("message",t);try{if(function(t){return"string"!=typeof t.data&&(e.IS_BROWSER?t.data instanceof Blob:!!(ArrayBuffer&&t.data instanceof ArrayBuffer)||!(!Buffer||!Buffer.isBuffer(t.data)))}(t)){var r=e.loadImageData(t.data);n.events.emit("image_data",r)}else{var o=JSON.parse(t.data);switch(o.type){case"status":o.data.sid&&(n.clientId=o.data.sid),n.events.emit("status",o.data.status);break;case"progress":n.events.emit("progress",o.data);break;case"executing":n.events.emit("executing",o.data);break;case"executed":n.events.emit("executed",o.data);break;case"execution_start":n.events.emit("execution_start",o.data);break;case"execution_error":n.events.emit("execution_error",o.data);break;case"execution_cached":n.events.emit("execution_cached",o.data);break;case"execution_interrupted":n.events.emit("execution_interrupted",o.data);break;default:if(!n.registered.has(o.type))throw new Error("Unknown message type "+o.type);n.events.emit(o.type,o.data)}}}catch(e){console.warn("Unhandled message:",t.data,e)}})}},r.init=function(){this.createSocket()},r.close=function(){this.closed||(this.closed=!0,this.disconnect(),this.events.removeAllListeners())},r.connect=function(e){var t,r=void 0===e?{}:e,n=r.polling,o=void 0===n?{enabled:!1}:n,i=r.websocket,s=void 0===i?{enabled:!0}:i;return null!=o&&o.enabled&&(this._polling_interval=null!=(t=o.interval)?t:this._polling_interval,this.startPollingQueue()),null!=s&&s.enabled&&this.createSocket(),this},r.disconnect=function(){this._disconnectSocket(),this._disconnectPolling()},r._disconnectSocket=function(){var e=this.socket;e&&(this.socket=null,e.readyState===this.WebSocket.OPEN&&e.close(1e3,"Client closed"),this.removeSocketCallbacks(),"removeAllListeners"in e&&(null==e.removeAllListeners||e.removeAllListeners()))},r._disconnectPolling=function(){null!==this._polling_timer&&(clearInterval(this._polling_timer),this._polling_timer=null)},e}();u.DEFAULT_API_HOST="127.0.0.1:8188",u.DEFAULT_API_BASE="",u.DEFAULT_USER="",u.IS_BROWSER="undefined"!=typeof window;var c=/*#__PURE__*/function(){function e(){this._cached=void 0,this._cached=globalThis[e.KEY]||new Map,globalThis[e.KEY]=this._cached}var t=e.prototype;return t.clear=function(){this._cached.clear()},t.get=function(e){return this._cached.get(e)},t.set=function(e,t){this._cached.set(e,t)},e}();c.KEY="__COMFY_UI_CLIENT_CACHE__";var a=/*#__PURE__*/function(){function e(t,r){var n,o;this.expire_time_ms=void 0,this.enabled=void 0,this._cached=new c,this.cache_ns="",this.expire_time_ms=null!=(n=null==r?void 0:r.expire_time)?n:e._defaultExpire,this.enabled=null==(o=null==r?void 0:r.enabled)||o,this.cache_ns=t}var t=e.prototype;return t.reset=function(){this._cached.clear()},t._hashArgs=function(e){try{return JSON.stringify(e)}catch(t){return e.toString()}},t.warp=function(e,t){var r=this;return this.enabled?function(){var n=[].slice.call(arguments),o=Date.now(),i=r._hashArgs(n),s=r.cache_ns+":"+e+":"+i,u=r._cached.get(s);if(u&&u.expire>o)return u.result;var c=t.apply(void 0,n);return r._cached.set(s,{result:c,expire:o+r.expire_time_ms}),c}:t},e}();function l(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}function h(e,t,r){if(!e.s){if(r instanceof f){if(!r.s)return void(r.o=h.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(h.bind(null,e,t),h.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}a._defaultExpire=6e4;var f=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{h(n,1,i(this.v))}catch(e){h(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?h(n,1,t?t(o):o):r?h(n,1,r(o)):h(n,2,o)}catch(e){h(n,2,e)}},n},e}();function d(e){return e instanceof f&&1&e.s}var p=/*#__PURE__*/function(e){function n(t){var r;return(r=e.call(this,t)||this)._cached_fn=void 0,r._cached_fn=new a(""+t.api_host,t.cache),r._authHeader=""!==r.auth?{Authorization:""+r.auth}:{},r}var i,u;u=e,(i=n).prototype=Object.create(u.prototype),i.prototype.constructor=i,r(i,u);var c=n.prototype;return c.getExtensions=function(){try{var e=this,r=e._cached_fn.warp("extensions",function(){try{return Promise.resolve(e.fetchApi("/extensions",{cache:"no-store",headers:t({},e._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.getEmbeddings=function(){try{var e=this,r=e._cached_fn.warp("embeddings",function(){try{return Promise.resolve(e.fetchApi("/embeddings",{cache:"no-store",headers:t({},e._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.getNodeDefs=function(){try{var e=this,r=e._cached_fn.warp("object_info",function(){try{return Promise.resolve(e.fetchApi("/object_info",{cache:"no-store",headers:t({},e._authHeader)})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(r())}catch(e){return Promise.reject(e)}},c.resetCache=function(){this._cached_fn.reset()},c.queuePrompt=function(e,r){var n=r.prompt,o=r.workflow;try{var i=this,s={client_id:i.clientId,prompt:n,extra_data:{extra_pnginfo:{workflow:o}}};return-1===e?s.front=!0:0!==e&&(s.number=e),Promise.resolve(i.fetchApi("/prompt",{method:"POST",headers:t({"Content-Type":"application/json"},i._authHeader),body:JSON.stringify(s)})).then(function(e){function t(t){return Promise.resolve(e.json())}var r=function(){if(200!==e.status)return Promise.resolve(e.text()).then(function(e){try{throw{response:JSON.parse(e)}}catch(t){throw{response:e}}})}();return r&&r.then?r.then(t):t()})}catch(e){return Promise.reject(e)}},c.getItems=function(e){try{return Promise.resolve("queue"===e?this.getQueue():this.getHistory())}catch(e){return Promise.reject(e)}},c.getQueue=function(){try{var e=this;return Promise.resolve(l(function(){return Promise.resolve(e.fetchApi("/queue",{headers:t({},e._authHeader)})).then(function(t){return Promise.resolve(t.json()).then(function(t){return{Running:t.queue_running.map(function(t){return{prompt:t,remove:{name:"Cancel",cb:function(){return e.interrupt()}}}}),Pending:t.queue_pending.map(function(e){return{prompt:e}})}})})},function(e){return console.error(e),{Running:[],Pending:[]}}))}catch(e){return Promise.reject(e)}},c.getHistory=function(e){void 0===e&&(e=200);try{var r=this;return Promise.resolve(l(function(){return Promise.resolve(r.fetchApi("/history?max_items="+e,{headers:t({},r._authHeader)})).then(function(e){return Promise.resolve(e.json()).then(function(e){return{History:Object.values(e)}})})},function(e){return console.error(e),{History:[]}}))}catch(e){return Promise.reject(e)}},c.getSystemStats=function(){try{return Promise.resolve(this.fetchApi("/system_stats",{headers:t({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.postApi=function(e,r){try{return Promise.resolve(this.fetchApi("/"+e,{method:"POST",headers:t({"Content-Type":"application/json"},this._authHeader),body:r?JSON.stringify(r):void 0})).then(function(){})}catch(e){return Promise.reject(e)}},c.deleteItem=function(e,t){try{return Promise.resolve(this.postApi(e,{delete:[t]})).then(function(){})}catch(e){return Promise.reject(e)}},c.clearItems=function(e){try{return Promise.resolve(this.postApi(e,{clear:!0})).then(function(){})}catch(e){return Promise.reject(e)}},c.interrupt=function(){try{return Promise.resolve(this.postApi("interrupt",null)).then(function(){})}catch(e){return Promise.reject(e)}},c.free=function(e){try{return Promise.resolve(this.postApi("free",e)).then(function(){})}catch(e){return Promise.reject(e)}},c.getUserConfig=function(){try{return Promise.resolve(this.fetchApi("/users",{headers:t({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.createUser=function(e){try{return Promise.resolve(this.fetchApi("/users",{method:"POST",headers:t({"Content-Type":"application/json"},this._authHeader),body:JSON.stringify({username:e})}))}catch(e){return Promise.reject(e)}},c.getSettings=function(){try{return Promise.resolve(this.fetchApi("/settings",{headers:t({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.getSetting=function(e){try{return Promise.resolve(this.fetchApi("/settings/"+encodeURIComponent(e),{headers:t({},this._authHeader)})).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},c.storeSettings=function(e){try{return Promise.resolve(this.fetchApi("/settings",{method:"POST",body:JSON.stringify(e),headers:t({},this._authHeader)}))}catch(e){return Promise.reject(e)}},c.storeSetting=function(e,r){try{return Promise.resolve(this.fetchApi("/settings/"+encodeURIComponent(e),{method:"POST",body:JSON.stringify(r),headers:t({},this._authHeader)}))}catch(e){return Promise.reject(e)}},c.getUserData=function(e,t){try{return Promise.resolve(this.fetchApi("/userdata/"+encodeURIComponent(e),t))}catch(e){return Promise.reject(e)}},c.storeUserData=function(e,r,n){try{return Promise.resolve(this.fetchApi("/userdata/"+encodeURIComponent(e),t({method:"POST",body:null!=n&&n.stringify?JSON.stringify(r):r,headers:t({},this._authHeader)},n))).then(function(t){return function(){if(200!==t.status)return Promise.resolve(t.text()).then(function(r){throw new Error("Error storing user data file '"+e+"': "+t.status+" "+r)})}()})}catch(e){return Promise.reject(e)}},c.getSamplers=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.KSampler;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.sampler_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getSchedulers=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.KSampler;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.scheduler)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getSDModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.CheckpointLoaderSimple;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.ckpt_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getCNetModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.ControlNetLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.control_net_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getUpscaleModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.UpscaleModelLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.model_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getHyperNetworks=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.HypernetworkLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.hypernetwork_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getLoRAs=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.LoraLoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.lora_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getVAEs=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,r=e.VAELoader;return(null==r||null==(t=r.input)||null==(t=t.required)||null==(t=t.vae_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},c.getPromptStatus=function(e){try{return Promise.resolve(this.getQueue()).then(function(t){var r=t.Pending,n=t.Running.some(function(t){var r;return(null==t||null==(r=t.prompt)?void 0:r[1])===e}),o=r.some(function(t){var r;return(null==t||null==(r=t.prompt)?void 0:r[1])===e});return{running:n,pending:o,done:!n&&!o}})}catch(e){return Promise.reject(e)}},c.getPromptOutputs=function(e){try{return Promise.resolve(this.getHistory()).then(function(t){var r=t.History.find(function(t){return t.prompt[1]===e});if(!r)throw new Error("Prompt ["+e+"] not found in history");var n=r.status.status_str;if("success"!==n)throw new Error("Prompt ["+e+"] failed with status: "+n);return r.outputs})}catch(e){return Promise.reject(e)}},c.getPromptImageResult=function(e){try{var t=this;return Promise.resolve(t.getPromptOutputs(e)).then(function(r){return{images:Object.values(r).flatMap(function(e){return e.images||[]}).map(function(e){var r=e.filename,n=e.subfolder,o=e.type;return s(r)||s(n)||"output"!==o?null:t.viewURL(r,n,o)}).filter(Boolean).map(function(e){return{type:"url",data:e}}),prompt_id:e}})}catch(e){return Promise.reject(e)}},c.waitForPrompt=function(e,t){void 0===t&&(t=1e3);try{var r=this;return Promise.resolve(r.getPromptStatus(e)).then(function(n){var o=function(e,t,r){for(var n;;){var o=e();if(d(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!d(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!d(s)){n=2;break}}}var u=new f,c=h.bind(null,u,2);return(0===n?o.then(l):1===n?i.then(a):s.then(p)).then(void 0,c),u;function a(n){i=n;do{if(t&&(s=t())&&s.then&&!d(s))return void s.then(p).then(void 0,c);if(!(o=e())||d(o)&&!o.v)return void h(u,1,i);if(o.then)return void o.then(l).then(void 0,c);d(i=r())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,c)}function l(e){e?(i=r())&&i.then?i.then(a).then(void 0,c):a(i):h(u,1,i)}function p(){(o=e())?o.then?o.then(l).then(void 0,c):l(o):h(u,1,i)}}(function(){return!n.done},void 0,function(){return Promise.resolve(new Promise(function(e){return setTimeout(e,t)})).then(function(){return Promise.resolve(r.getPromptStatus(e)).then(function(e){n=e})})});if(o&&o.then)return o.then(function(){})})}catch(e){return Promise.reject(e)}},c.waitForPromptWebSocket=function(e){try{var t=this,r={images:[],prompt_id:e};return Promise.resolve(new Promise(function(n,i){var u=t.on("image_data",function(e){r.images.push({type:"buff",data:e})}),c=t.on("executed",function(i){if(i.prompt_id===e){for(var a,l=(i.output||{}).images,h=o(void 0===l?[]:l);!(a=h()).done;){var f=a.value||{},d=f.filename,p=f.subfolder,v=f.type;s(d)||s(p)||"output"!==v||r.images.push({type:"url",data:t.viewURL(d,p,v)})}n(r),c(),u()}})}))}catch(e){return Promise.reject(e)}},c.randomizePrompt=function(e){for(var t=0,r=Object.values(e);t<r.length;t++){var n=r[t];"KSampler"===n.class_type&&(n.inputs.seed=Math.floor(Math.random()*(Math.pow(2,32)-1)))}},c._enqueue_prompt=function(e,t){try{return null!=t&&t.disable_random_seed||this.randomizePrompt(e),Promise.resolve(this.queuePrompt(0,{prompt:e,workflow:null==t?void 0:t.workflow})).then(function(e){if("error"in e)throw new Error(e.error);return e})}catch(e){return Promise.reject(e)}},c.runPrompt=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n=e.prompt_id;return Promise.resolve(r.waitForPrompt(n,null==t?void 0:t.polling_ms)).then(function(){return Promise.resolve(r.getPromptImageResult(n))})})}catch(e){return Promise.reject(e)}},c.enqueue_polling=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n=e.prompt_id;return Promise.resolve(r.waitForPrompt(n,null==t?void 0:t.polling_ms)).then(function(){return Promise.resolve(r.getPromptImageResult(n))})})}catch(e){return Promise.reject(e)}},c.enqueue=function(e,t){try{var r=this;return Promise.resolve(r._enqueue_prompt(e,t)).then(function(e){var n,o=e.prompt_id;return null!=t&&t.progress&&(n=r.on("progress",function(e){e.progress.prompt_id===o&&(null==t||null==t.progress||t.progress(e.progress))})),function(e,t){try{var n=Promise.resolve(r.waitForPromptWebSocket(o))}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,n)}(0,function(e,t){if(null==n||n(),e)throw t;return t})})}catch(e){return Promise.reject(e)}},n}(u),v=/*#__PURE__*/function(){function e(e,t){this.workflow=void 0,this.client=void 0,this._task_id=void 0,this._enqueue_req=void 0,this._result={images:[],prompt_id:""},this.executed=!1,this.workflow=e,this.client=t}var t=e.prototype;return t.enqueue=function(){var e=this,t=this.workflow;this._enqueue_req=this.client._enqueue_prompt(t.prompt,{workflow:t.workflow}),this._task_id=this._enqueue_req.then(function(e){return e.prompt_id}),this._enqueue_req.then(function(t){e._result.prompt_id=t.prompt_id})},t.load_result_data=function(e){for(var t,r=(e.output||{}).images,n=o(void 0===r?[]:r);!(t=n()).done;){var i=t.value||{},u=i.filename,c=i.subfolder,a=i.type;s(u)||s(c)||"output"!==a||this._result.images.push({type:"url",data:this.client.viewURL(u,c,a)})}},t.query=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be queried");var t=e.client,r=t.getPromptStatus;return Promise.resolve(e._task_id).then(function(e){return r.call(t,e)})}catch(e){return Promise.reject(e)}},t.interrupt=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be interrupt");return Promise.resolve(e._task_id).then(function(t){return Promise.resolve(e.query()).then(function(r){if(!r.done){if(!r.pending){if(r.running)return e.client.interrupt();throw new Error("wrong task status, id: "+t)}e.client.deleteItem("queue",t)}})})}catch(e){return Promise.reject(e)}},t.wait=function(){try{var e=this;if(!e._task_id)throw new Error("This workflow is not enqueued and the execution status cannot be wait");return Promise.resolve(e._task_id).then(function(t){return new Promise(function(r,n){var o,i;o=[],i=function(){return o.forEach(function(e){return e()})},o=[e.client.on("execution_interrupted",function(e){e.prompt_id===t&&(n(new Error("Execution Interrupted")),i())}),e.client.on("image_data",function(t){e.executed||e._result.images.push({type:"buff",data:t})}),e.client.on("executed",function(n){n.prompt_id===t&&(e.load_result_data(n),e.executed=!0,r(e._result),i())})]})})}catch(e){return Promise.reject(e)}},e}(),m=globalThis.structuredClone?globalThis.structuredClone:function(e){return JSON.parse(JSON.stringify(e))},_=/*#__PURE__*/function(){function e(){this._workflow={prompt:{}},this._last_node_id=0,this.classes=this._createClassesProxy()}var t=e.prototype;return t._createClassesProxy=function(){var e=this;return new Proxy({},{get:function(t,r,n){return r in t?t[r]:function(t){var n={class_type:r.toString(),inputs:t},o=(++e._last_node_id).toString();return e._workflow.prompt[o]=n,Array.from({length:10},function(e,t){return[o,t]})}}})},t.reset=function(){this._workflow.prompt={},this._workflow.workflow=void 0,this._last_node_id=0},t.end=function(){return this.workflow()},t.workflow=function(){return m(this._workflow)},t.invoke=function(e){var t=this.instance(e);return t.enqueue(),t.wait()},t.instance=function(e){var t=this.workflow();return new v({prompt:t.prompt,workflow:t.workflow},e)},t.invoke_polling=function(e){var t=this.workflow();return e.enqueue_polling(t.prompt,{workflow:t.workflow})},e}();e.ComfyUIApiClient=p,e.ComfyUIWorkflow=_,e.ComfyUIWsClient=u}); | ||
//# sourceMappingURL=main.umd.js.map |
{ | ||
"name": "@kwj-team/comfyui-client", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "api Client for ComfyUI that supports both NodeJS and Browser environments. It provides full support for all RESTful / WebSocket APIs.", | ||
@@ -5,0 +5,0 @@ "source": "src/main.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
560537