UNPKG

@stable-canvas/comfyui-client

Version:

api Client for ComfyUI that supports both NodeJS and Browser environments. It provides full support for all RESTful / WebSocket APIs.

1 lines 50.1 kB
!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(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function n(e,n){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,n){if(e){if("string"==typeof e)return t(e,n);var r={}.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)?t(e,n):void 0}}(e))||n&&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.")}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},r.apply(null,arguments)}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function i(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,c(e,t)}function s(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(s=function(){return!!e})()}function u(){u=function(){return t};var e,t={},n=Object.prototype,r=n.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function a(e,t,n,r){Object.defineProperty(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r})}try{a({},"")}catch(e){a=function(e,t,n){return e[t]=n}}function l(t,n,r,o){var i=Object.create((n&&n.prototype instanceof p?n:p).prototype);return a(i,"_invoke",function(t,n,r){var o=1;return function(i,s){if(3===o)throw Error("Generator is already running");if(4===o){if("throw"===i)throw s;return{value:e,done:!0}}for(r.method=i,r.arg=s;;){var u=r.delegate;if(u){var c=k(u,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(1===o)throw o=4,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=3;var a=h(t,n,r);if("normal"===a.type){if(o=r.done?4:2,a.arg===f)continue;return{value:a.arg,done:r.done}}"throw"===a.type&&(o=4,r.method="throw",r.arg=a.arg)}}}(t,r,new S(o||[])),!0),i}function h(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=l;var f={};function p(){}function d(){}function v(){}var m={};a(m,i,function(){return this});var _=Object.getPrototypeOf,g=_&&_(_(j([])));g&&g!==n&&r.call(g,i)&&(m=g);var y=v.prototype=p.prototype=Object.create(m);function w(e){["next","throw","return"].forEach(function(t){a(e,t,function(e){return this._invoke(t,e)})})}function b(e,t){function n(o,i,s,u){var c=h(e[o],e,i);if("throw"!==c.type){var a=c.arg,l=a.value;return l&&"object"==typeof l&&r.call(l,"__await")?t.resolve(l.__await).then(function(e){n("next",e,s,u)},function(e){n("throw",e,s,u)}):t.resolve(l).then(function(e){a.value=e,s(a)},function(e){return n("throw",e,s,u)})}u(c.arg)}var o;a(this,"_invoke",function(e,r){function i(){return new t(function(t,o){n(e,r,t,o)})}return o=o?o.then(i,i):i()},!0)}function k(t,n){var r=n.method,o=t.i[r];if(o===e)return n.delegate=null,"throw"===r&&t.i.return&&(n.method="return",n.arg=e,k(t,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var i=h(o,t.i,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,f;var s=i.arg;return s?s.done?(n[t.r]=s.value,n.next=t.n,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,f):s:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,f)}function P(e){this.tryEntries.push(e)}function x(t){var n=t[4]||{};n.type="normal",n.arg=e,t[4]=n}function S(e){this.tryEntries=[[-1]],e.forEach(P,this),this.reset(!0)}function j(t){if(null!=t){var n=t[i];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,s=function n(){for(;++o<t.length;)if(r.call(t,o))return n.value=t[o],n.done=!1,n;return n.value=e,n.done=!0,n};return s.next=s}}throw new TypeError(typeof t+" is not iterable")}return d.prototype=v,a(y,"constructor",v),a(v,"constructor",d),a(v,c,d.displayName="GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,a(e,c,"GeneratorFunction")),e.prototype=Object.create(y),e},t.awrap=function(e){return{__await:e}},w(b.prototype),a(b.prototype,s,function(){return this}),t.AsyncIterator=b,t.async=function(e,n,r,o,i){void 0===i&&(i=Promise);var s=new b(l(e,n,r,o),i);return t.isGeneratorFunction(n)?s:s.next().then(function(e){return e.done?e.value:s.next()})},w(y),a(y,c,"Generator"),a(y,i,function(){return this}),a(y,"toString",function(){return"[object Generator]"}),t.keys=function(e){var t=Object(e),n=[];for(var r in t)n.unshift(r);return function e(){for(;n.length;)if((r=n.pop())in t)return e.value=r,e.done=!1,e;return e.done=!0,e}},t.values=j,S.prototype={constructor:S,reset:function(t){if(this.prev=this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(x),!t)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0][4];if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function r(e){s.type="throw",s.arg=t,n.next=e}for(var o=n.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i[4],u=this.prev,c=i[1],a=i[2];if(-1===i[0])return r("end"),!1;if(!c&&!a)throw Error("try statement without catch or finally");if(null!=i[0]&&i[0]<=u){if(u<c)return this.method="next",this.arg=e,r(c),!0;if(u<a)return r(a),!1}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r[0]>-1&&r[0]<=this.prev&&this.prev<r[2]){var o=r;break}}o&&("break"===e||"continue"===e)&&o[0]<=t&&t<=o[2]&&(o=null);var i=o?o[4]:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o[2],f):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),f},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n[2]===e)return this.complete(n[4],n[3]),x(n),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n[0]===e){var r=n[4];if("throw"===r.type){var o=r.arg;x(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={i:j(t),r:n,n:r},"next"===this.method&&(this.arg=e),f}},t}function c(e,t){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},c(e,t)}function a(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}function l(e){var t="function"==typeof Map?new Map:void 0;return l=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return function(e,t,n){if(s())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var o=new(e.bind.apply(e,r));return n&&c(o,n.prototype),o}(e,arguments,o(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,e)},l(e)}var h,f=function(){var e={exports:{}};return function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function i(e,t,r,i,s){if("function"!=typeof r)throw new TypeError("The listener must be a function");var u=new o(r,i||e,s),c=n?n+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 r:delete e._events[t]}function u(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),u.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},u.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var r=0,o=t.length,i=new Array(o);r<o;r++)i[r]=t[r].fn;return i},u.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},u.prototype.emit=function(e,t,r,o,i,s){var u=n?n+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,r),!0;case 4:return l.fn.call(l.context,t,r,o),!0;case 5:return l.fn.call(l.context,t,r,o,i),!0;case 6:return l.fn.call(l.context,t,r,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,p=l.length;for(a=0;a<p;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,r);break;case 4:l[a].fn.call(l[a].context,t,r,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,n){return i(this,e,t,n,!1)},u.prototype.once=function(e,t,n){return i(this,e,t,n,!0)},u.prototype.removeListener=function(e,t,r,o){var i=n?n+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||r&&u.context!==r||s(this,i);else{for(var c=0,a=[],l=u.length;c<l;c++)(u[c].fn!==t||o&&!u[c].once||r&&u[c].context!==r)&&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=n?n+e:e]&&s(this,t):(this._events=new r,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=n,u.EventEmitter=u,e.exports=u}(e),e.exports}(),p=function(e){return null==e};!function(e){var t=/*#__PURE__*/function(e){function t(t,n,r){var o;return(o=e.call(this,t)||this).status=void 0,o.json=void 0,o.name="HttpError",o.status=n,o.json=r,o}return i(t,e),t}(/*#__PURE__*/l(Error));e.HttpError=t}(h||(h={}));var d=/*#__PURE__*/function(){function e(t){var n,r,o,i,s,u,c;if(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 f,this.socket_callbacks={},this._polling_timer=null,this._polling_interval=1e3,this.closed=!1,this.api_host=null!=(n=t.api_host)?n:e.DEFAULT_API_HOST,this.api_base=null!=(r=t.api_base)?r:e.DEFAULT_API_BASE,this.clientId=null!=(o=t.clientId)?o:"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!=(i=t.WebSocket)?i:globalThis.WebSocket,this.ssl=null!=(s=t.ssl)&&s,this.user=null!=(u=t.user)?u:e.DEFAULT_USER,!globalThis.fetch)throw new Error("fetch is not defined");this.fetch=null!=(c=t.fetch)?c:globalThis.fetch.bind(globalThis),this.WebSocket||console.warn("No WebSocket implementation available, WebSocket disabled")}e.loadImageData=function(e){var t=new DataView(e),n=t.getUint32(0),r=t.getUint32(1);if(1!==n)throw new Error("Unknown binary websocket message of type "+n);var o={1:"image/jpeg",2:"image/png"}[r]||"image/png";return{image:e.slice(8),mime:o}};var t,n,o=e.prototype;return o.apiHeaders=function(e){var t;return r({},this.user?{"Comfy-User":this.user}:{},{Accept:"*/*"},null!=(t=null==e?void 0:e.headers)?t:{})},o.apiURL=function(e){var t=new URL("http"+(this.ssl?"s":"")+"://"+this.api_host),n=(this.api_base+e).split("?"),r=n[1];return t.pathname=n[0],t.pathname=t.pathname.replace(/\/+/g,"/"),r&&(t.search=r),this.clientId&&t.searchParams.set("clientId",this.clientId),t.toString()},o.viewURL=function(e,t,n){var r=new URLSearchParams({filename:e,subfolder:t,type:n}).toString();return"http"+(this.ssl?"s":"")+"://"+this.api_host+this.api_base+"/view?"+r},o.wsURL=function(){var e=new URL("ws"+(this.ssl?"s":"")+"://"+this.api_host);return e.pathname="/ws",this.clientId&&e.searchParams.set("clientId",this.clientId),e.toString()},o.fetchApi=function(e,t){try{var n=this;if(n.closed)throw new Error("Client is closed");var o=n.apiURL(e);return Promise.resolve(n.fetch(o,r({},t,{headers:n.apiHeaders(t)}))).then(function(e){var t=e.status,n=e.statusText,r=function(){if(t<200||t>=400)return Promise.resolve(e.json()).then(function(e){throw new h.HttpError("Endpoint Bad Request ("+t+" "+n+"): "+o,t,e)})}();return r&&r.then?r.then(function(t){return e}):e})}catch(e){return Promise.reject(e)}},o.addEventListener=function(e,t,n){var r=this;return this.events.on(e,t,n),function(){r.events.off(e,t)}},o.on=function(e,t,n){return this.addEventListener(e,t,n)},o.once=function(e,t,n){var r=this;return this.events.once(e,t,n),function(){r.events.off(e,t)}},o.startPollingQueue=function(){var e=this;this._polling_timer||(this._polling_timer=setInterval(function(){try{var t=function(t,n){try{var r=Promise.resolve(e.fetchApi("/prompt")).then(function(t){return Promise.resolve(t.json()).then(function(t){e.events.emit("status",t)})})}catch(e){return n()}return r&&r.then?r.then(void 0,n):r}(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))},o.addSocketCallback=function(e,t,n,r){var o=this;return this.socket_callbacks[t]=n,e.addEventListener(t,n,r),function(){delete o.socket_callbacks[t],e.removeEventListener(t,n,r)}},o.removeSocketCallbacks=function(){if(this.socket)for(var e in this.socket_callbacks)this.socket.removeEventListener(e,this.socket_callbacks[e]);this.socket_callbacks={}},o.createSocket=function(t){var n=this;if(void 0===t&&(t=!1),!this.socket){if(!this.WebSocket)throw new Error("WebSocket is not defined, please provide a WebSocket implementation");if(!this.closed){var r=!1;this.socket=new this.WebSocket(this.wsURL()),this.socket.binaryType="arraybuffer",this.addSocketCallback(this.socket,"open",function(){r=!0,n.events.emit(t?"reconnected":"connected")}),this.addSocketCallback(this.socket,"error",function(e){var o,i=e,s=null==(o=i.message)?void 0:o.includes("404");n.events.emit("connection_error",{type:"404",message:i.message}),n.socket&&n.socket.close(),s||t||r||n.startPollingQueue()}),this.addSocketCallback(this.socket,"close",function(){setTimeout(function(){n.socket=null,n.createSocket(!0)},300),r&&(n.events.emit("status",null),n.events.emit("reconnecting"))}),this.addSocketCallback(this.socket,"message",function(t){if(n.events.emit("message",t),function(e){return!("string"==typeof e.data||!(ArrayBuffer&&e.data instanceof ArrayBuffer||Buffer&&Buffer.isBuffer(e.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:n.events.emit(o.type,o.data)}"message"!==o.type&&!1===n.registered.includes(o.type)&&n.events.emit("unhandled",o)}})}}},o.init=function(){this.createSocket()},o.close=function(){this.closed||(this.closed=!0,this.events.emit("close"),this.disconnect(),this.events.removeAllListeners())},o.connect=function(e){var t,n=this,r=this,o=void 0===e?{}:e,i=o.polling,s=void 0===i?{enabled:!1}:i,u=o.websocket,c=void 0===u?{enabled:!0}:u,a=o.timeout_ms,l=void 0===a?15e3:a;if(null!=s&&s.enabled)return this._polling_interval=null!=(t=s.interval)?t:this._polling_interval,this.startPollingQueue(),new Promise(function(e,t){try{var n=setTimeout(function(){t(new Error("Polling connection timed out"))},l);return Promise.resolve(r.fetchApi("/system_stats")).then(function(t){e(t.ok&&200===t.status),clearTimeout(n)})}catch(e){return Promise.reject(e)}});if(null!=c&&c.enabled)return this.createSocket(),new Promise(function(e,t){var r=setTimeout(function(){t(new Error("WebSocket connection timed out"))},l);n.once("connected",function(){e(!0),clearTimeout(r)})});throw new Error("You must enable either polling or websocket")},o.disconnect=function(){this.socket?this._disconnectSocket():process.nextTick(this._disconnectPolling.bind(this)),this._disconnectPolling()},o._disconnectSocket=function(){var e=this.socket;if(e){this.socket=null;try{e.readyState===e.OPEN&&e.close(1e3,"Client closed")}catch(e){}this.removeSocketCallbacks(),"removeAllListeners"in e&&(null==e.removeAllListeners||e.removeAllListeners())}},o._disconnectPolling=function(){null!==this._polling_timer&&(clearInterval(this._polling_timer),this._polling_timer=null)},t=e,(n=[{key:"registered",get:function(){return this.events.eventNames()}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,a(r.key),r)}}(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),t}();d.DEFAULT_API_HOST="127.0.0.1:8188",d.DEFAULT_API_BASE="",d.DEFAULT_USER="",d.IS_BROWSER="undefined"!=typeof window;var v=/*#__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}();v.KEY="__COMFY_UI_CLIENT_CACHE__";var m=/*#__PURE__*/function(){function e(t,n){var r,o;this.expire_time_ms=void 0,this.enabled=void 0,this._cached=new v,this.cache_ns="",this.expire_time_ms=null!=(r=null==n?void 0:n.expire_time)?r:e._defaultExpire,this.enabled=null==(o=null==n?void 0:n.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 n=this;return this.enabled?function(){var r=[].slice.call(arguments),o=Date.now(),i=n._hashArgs(r),s=n.cache_ns+":"+e+":"+i,u=n._cached.get(s);if(u&&u.expire>o)return u.result;var c=t.apply(void 0,r);return n._cached.set(s,{result:c,expire:o+n.expire_time_ms}),c}:t},e}();m._defaultExpire=6e4;var _={image:function(e,t,n){var o=n.client;if(null==t)return e;var i=((null==t?void 0:t.images)||[]).map(function(e){var t=e.filename,n=e.subfolder,r=e.type;return p(t)||p(n)||"output"!==r?null:o.viewURL(t,n,r)}).filter(Boolean).map(function(e){return{type:"url",data:e}});return r({},e,{images:[].concat(e.images,i)})}},g={__proto__:null,RESOLVERS:_};function y(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function w(e,t,n){if(!e.s){if(n instanceof b){if(!n.s)return void(n.o=w.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(w.bind(null,e,t),w.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var b=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{w(r,1,i(this.v))}catch(e){w(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?w(r,1,t?t(o):o):n?w(r,1,n(o)):w(r,2,o)}catch(e){w(r,2,e)}},r},e}();function k(e){return e instanceof b&&1&e.s}var P=/*#__PURE__*/function(e){function t(t){var n;return(n=e.call(this,t)||this)._cached_fn=void 0,n._plugins=[],n._cached_fn=new m(""+t.api_host,t.cache),n}i(t,e);var n=t.prototype;return n.use=function(e){e.install(this),this._plugins.push(e)},n.getExtensions=function(){try{var e=this,t=e._cached_fn.warp("extensions",function(){try{return Promise.resolve(e.fetchApi("/extensions",{cache:"no-store"})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(t())}catch(e){return Promise.reject(e)}},n.getEmbeddings=function(){try{var e=this,t=e._cached_fn.warp("embeddings",function(){try{return Promise.resolve(e.fetchApi("/embeddings",{cache:"no-store"})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(t())}catch(e){return Promise.reject(e)}},n.getNodeDefs=function(){try{var e=this,t=e._cached_fn.warp("object_info",function(){try{return Promise.resolve(e.fetchApi("/object_info",{cache:"no-store"})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}});return Promise.resolve(t())}catch(e){return Promise.reject(e)}},n.resetCache=function(){this._cached_fn.reset()},n.queuePrompt=function(e,t){var n=t.prompt,r=t.workflow;try{var o={client_id:this.clientId,prompt:n,extra_data:{extra_pnginfo:{workflow:r}}};return-1===e?o.front=!0:0!==e&&(o.number=e),Promise.resolve(this.fetchApi("/prompt",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)})).then(function(e){function t(t){return Promise.resolve(e.json())}var n=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 n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},n.getItems=function(e){try{return Promise.resolve("queue"===e?this.getQueue():this.getHistory())}catch(e){return Promise.reject(e)}},n.getQueue=function(){try{var e=this;return Promise.resolve(y(function(){return Promise.resolve(e.fetchApi("/queue")).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)}},n.getHistory=function(e){void 0===e&&(e=200);try{var t=this;return Promise.resolve(y(function(){return Promise.resolve(t.fetchApi("/history?max_items="+e)).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)}},n.getSystemStats=function(){try{return Promise.resolve(this.fetchApi("/system_stats")).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},n.postApi=function(e,t){try{return Promise.resolve(this.fetchApi("/"+e,{method:"POST",headers:{"Content-Type":"application/json"},body:t?JSON.stringify(t):void 0})).then(function(){})}catch(e){return Promise.reject(e)}},n.deleteItem=function(e,t){try{return Promise.resolve(this.postApi(e,{delete:[t]})).then(function(){})}catch(e){return Promise.reject(e)}},n.clearItems=function(e){try{return Promise.resolve(this.postApi(e,{clear:!0})).then(function(){})}catch(e){return Promise.reject(e)}},n.interrupt=function(){try{return Promise.resolve(this.postApi("interrupt",null)).then(function(){})}catch(e){return Promise.reject(e)}},n.free=function(e){try{return Promise.resolve(this.postApi("free",e)).then(function(){})}catch(e){return Promise.reject(e)}},n.getUserConfig=function(){try{return Promise.resolve(this.fetchApi("/users")).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},n.createUser=function(e){try{return Promise.resolve(this.fetchApi("/users",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e})}))}catch(e){return Promise.reject(e)}},n.getSettings=function(){try{return Promise.resolve(this.fetchApi("/settings")).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},n.getSetting=function(e){try{return Promise.resolve(this.fetchApi("/settings/"+encodeURIComponent(e))).then(function(e){return e.json()})}catch(e){return Promise.reject(e)}},n.storeSettings=function(e){try{return Promise.resolve(this.fetchApi("/settings",{method:"POST",body:JSON.stringify(e)}))}catch(e){return Promise.reject(e)}},n.storeSetting=function(e,t){try{return Promise.resolve(this.fetchApi("/settings/"+encodeURIComponent(e),{method:"POST",body:JSON.stringify(t)}))}catch(e){return Promise.reject(e)}},n.getUserData=function(e,t){try{return Promise.resolve(this.fetchApi("/userdata/"+encodeURIComponent(e),t))}catch(e){return Promise.reject(e)}},n.storeUserData=function(e,t,n){try{return Promise.resolve(this.fetchApi("/userdata/"+encodeURIComponent(e),r({method:"POST",body:null!=n&&n.stringify?JSON.stringify(t):t},n))).then(function(t){return function(){if(200!==t.status)return Promise.resolve(t.text()).then(function(n){throw new Error("Error storing user data file '"+e+"': "+t.status+" "+n)})}()})}catch(e){return Promise.reject(e)}},n.getSamplers=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,n=e.KSampler;return(null==n||null==(t=n.input)||null==(t=t.required)||null==(t=t.sampler_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},n.getSchedulers=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,n=e.KSampler;return(null==n||null==(t=n.input)||null==(t=t.required)||null==(t=t.scheduler)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},n.getSDModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,n=e.CheckpointLoaderSimple;return(null==n||null==(t=n.input)||null==(t=t.required)||null==(t=t.ckpt_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},n.getCNetModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,n=e.ControlNetLoader;return(null==n||null==(t=n.input)||null==(t=t.required)||null==(t=t.control_net_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},n.getUpscaleModels=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,n=e.UpscaleModelLoader;return(null==n||null==(t=n.input)||null==(t=t.required)||null==(t=t.model_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},n.getHyperNetworks=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,n=e.HypernetworkLoader;return(null==n||null==(t=n.input)||null==(t=t.required)||null==(t=t.hypernetwork_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},n.getLoRAs=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,n=e.LoraLoader;return(null==n||null==(t=n.input)||null==(t=t.required)||null==(t=t.lora_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},n.getVAEs=function(){try{return Promise.resolve(this.getNodeDefs()).then(function(e){var t,n=e.VAELoader;return(null==n||null==(t=n.input)||null==(t=t.required)||null==(t=t.vae_name)?void 0:t[0])||[]})}catch(e){return Promise.reject(e)}},n.getPromptStatus=function(e){try{return Promise.resolve(this.getQueue()).then(function(t){var n=t.Pending,r=t.Running.some(function(t){var n;return(null==t||null==(n=t.prompt)?void 0:n[1])===e}),o=n.some(function(t){var n;return(null==t||null==(n=t.prompt)?void 0:n[1])===e});return{running:r,pending:o,done:!r&&!o}})}catch(e){return Promise.reject(e)}},n.getPromptOutputs=function(e){try{return Promise.resolve(this.getHistory()).then(function(t){var n=t.History.find(function(t){return t.prompt[1]===e});if(!n)throw new Error("Prompt ["+e+"] not found in history");var r=n.status.status_str;if("success"!==r)throw new Error("Prompt ["+e+"] failed with status: "+r);return n.outputs})}catch(e){return Promise.reject(e)}},n.getPromptResult=function(e,t){try{var n=this;return Promise.resolve(n.getPromptOutputs(e)).then(function(r){return"function"!=typeof t&&(t=_.image),Object.entries(r).reduce(function(r,o){return t(r,o[1],{client:n,prompt_id:e,node_id:o[0]})},{images:[],prompt_id:e,data:null})})}catch(e){return Promise.reject(e)}},n.waitForPrompt=function(e,t){void 0===t&&(t=1e3);try{var n=this;return Promise.resolve(n.getPromptStatus(e)).then(function(r){var o=function(e,t,n){for(var r;;){var o=e();if(k(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!k(i)){r=1;break}i=i.s}}var s=new b,u=w.bind(null,s,2);return(0===r?o.then(a):1===r?i.then(c):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,u):a(o):w(s,1,i)})).then(void 0,u),s;function c(t){i=t;do{if(!(o=e())||k(o)&&!o.v)return void w(s,1,i);if(o.then)return void o.then(a).then(void 0,u);k(i=n())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,u)}function a(e){e?(i=n())&&i.then?i.then(c).then(void 0,u):c(i):w(s,1,i)}}(function(){return!r.done},0,function(){return Promise.resolve(new Promise(function(e){return setTimeout(e,t)})).then(function(){return Promise.resolve(n.getPromptStatus(e)).then(function(e){r=e})})});if(o&&o.then)return o.then(function(){})})}catch(e){return Promise.reject(e)}},n.waitForPromptWebSocket=function(e,t){try{var n=this,r={images:[],prompt_id:e,data:null};return Promise.resolve(new Promise(function(o,i){var s=n.on("image_data",function(e){r.images.push({type:"buff",data:e.image,mime:e.mime})}),u=n.on("executed",function(i){if(i.prompt_id===e){var c=t(r,i.output,{client:n,prompt_id:e,node_id:i.node});o(c),u(),s()}})}))}catch(e){return Promise.reject(e)}},n._enqueue_prompt=function(e,t){try{return 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)}},n.runPrompt=function(e,t){try{var n=this;return Promise.resolve(n._enqueue_prompt(e,t)).then(function(e){var r=e.prompt_id;return Promise.resolve(n.waitForPrompt(r,null==t?void 0:t.polling_ms)).then(function(){return Promise.resolve(n.getPromptResult(r,_.image))})})}catch(e){return Promise.reject(e)}},n.enqueue_polling=function(e,t){try{var n=this;if("function"==typeof(null==t?void 0:t.progress))throw new Error("progress option is not supported in polling mode");return Promise.resolve(n._enqueue_prompt(e,t)).then(function(e){var r=e.prompt_id;return Promise.resolve(n.waitForPrompt(r,null==t?void 0:t.polling_ms)).then(function(){var e;return Promise.resolve(n.getPromptResult(r,null!=(e=null==t?void 0:t.resolver)?e:_.image))})})}catch(e){return Promise.reject(e)}},n.enqueue=function(e,t){try{var n=this;return Promise.resolve(n._enqueue_prompt(e,t)).then(function(e){var r=e.prompt_id,o=n.on_progress(null==t?void 0:t.progress,r);return function(e,o){try{var i=Promise.resolve(n.waitForPromptWebSocket(r,null!=(s=null==t?void 0:t.resolver)?s:_.image))}catch(e){return o(!0,e)}var s;return i&&i.then?i.then(o.bind(null,!1),o.bind(null,!0)):o(!1,i)}(0,function(e,t){if(o(),e)throw t;return t})})}catch(e){return Promise.reject(e)}},n.on_progress=function(e,t){return e?this.on("progress",function(n){var o=r({},"progress"in n?r({},n.progress):{},n);o.prompt_id===t&&e(o)}):function(){}},t}(d),x=/*#__PURE__*/function(){function e(){this._disposed=!1,this._disposed_cbs=[]}var t=e.prototype;return t.dispose=function(){this._disposed||(this._disposed=!0,this._disposed_cbs.forEach(function(e){"function"==typeof e&&e()}))},t._connect=function(e){this._disposed?e():this._disposed_cbs.push(e)},e}();function S(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var j,E=/*#__PURE__*/function(e){function t(t){var n;(n=e.call(this)||this).options=void 0,n.task_id=void 0,n._result={images:[],prompt_id:""},n.is_done=!1,n.enqueued=!1,n.workflow=void 0,n.client=void 0,n.resolver=void 0,n.options=t;var r=t.client,o=t.resolver;return n.workflow=t.workflow,n.client=r,n.resolver=o||_.image,n}i(t,e);var n=t.prototype;return n._enqueue_guard=function(){if(this.enqueued)throw new Error("This workflow is already enqueued");this.enqueued=!0},n._task_id_guard=function(){if(!this.task_id)throw new Error("This workflow is not enqueued and the execution status cannot be interrupt");return this.task_id},n._done_guard=function(){if(this._disposed||this.is_done)throw new Error("This workflow has been disposed")},n._ws_guard=function(){if(null===this.client.socket)throw new Error("WebSocket is not connected")},n.is_owner_event=function(){var e=([].slice.call(arguments)||[])[0],t=this.task_id;return!!t&&"object"==typeof e&&null!==e&&"prompt_id"in e&&e.prompt_id===t},n.on=function(e,t,n){var r=this;this._done_guard();var o=this.client.on(e,function(){var e=[].slice.call(arguments);r.is_owner_event.apply(r,e)&&t.apply(void 0,e)});return this._connect(o),o},n.once=function(e,t,n){var r=this;this._done_guard();var o=this.client.on(e,function(){var e=[].slice.call(arguments);r.is_owner_event.apply(r,e)&&(t.apply(void 0,e),o())});return this._connect(o),o},n.enqueue=function(){try{var e=this;e._enqueue_guard();var t=e.workflow;return Promise.resolve(e.client._enqueue_prompt(t.prompt,{workflow:t.workflow})).then(function(t){e.task_id=t.prompt_id,e.hook_progress(),e.hook_image_data()})}catch(e){return Promise.reject(e)}},n.hook_progress=function(){try{var e=this,t=e.options.progress,n=e.task_id;if(!t)return Promise.resolve();if("function"!=typeof t)throw new Error("progress hook must be a function");if("string"!=typeof n)throw new Error("this workflow is not enqueued");var r=e.client.on_progress(t,n);return e._connect(r),Promise.resolve()}catch(e){return Promise.reject(e)}},n.hook_image_data=function(){try{var e=this,t=e.client.on("image_data",function(t){e.is_done||e._result.images.push({type:"buff",data:t.image,mime:t.mime})});return e._connect(t),Promise.resolve()}catch(e){return Promise.reject(e)}},n.resolve_to_result=function(e){this._result=(0,this.resolver)(this._result,e.output,{client:this.client,prompt_id:e.prompt_id,node_id:e.node})},n.query=function(){try{var e=this._task_id_guard();return Promise.resolve(this.client.getPromptStatus(e))}catch(e){return Promise.reject(e)}},n.interrupt=function(){try{var e=this,t=e._task_id_guard();return Promise.resolve(e.query()).then(function(n){if(!n.done){if(!n.pending){if(n.running)return e.client.interrupt();throw new Error("wrong task status, id: "+t)}e.client.deleteItem("queue",t)}})}catch(e){return Promise.reject(e)}},n.collect_result=function(){try{var e=this,t=e.client,n=e.resolver,r=e._task_id_guard();return Promise.resolve(t.getPromptResult(r,null!=n?n:_.image)).then(function(t){var n;return e._result.images=[].concat(e._result.images,t.images),e._result.data=null!=(n=e._result.data)?n:t.data,e._result})}catch(e){return Promise.reject(e)}},n.when_interrupted=function(e){var t=this._task_id_guard();this._connect(this.client.on("execution_interrupted",function(n){n.prompt_id===t&&e(n)}))},n.wait_polling=function(e){var t=(void 0===e?{}:e).polling_ms;try{var n=this;n._done_guard();var r=n._task_id_guard(),o=n.client;return Promise.resolve(new Promise(function(e,i){try{var s=function(){n.is_done=!0,n.dispose()};n.when_interrupted(function(e){i(new Error("Execution Interrupted")),s()});var u=function(s,u){try{var c=S(function(){return Promise.resolve(o.waitForPrompt(r,null!=t?t:1e3)).then(function(){return Promise.resolve(n.collect_result()).then(function(t){e(t)})})},function(e){i(e)})}catch(e){return u(!0,e)}return c&&c.then?c.then(u.bind(null,!1),u.bind(null,!0)):u(!1,c)}(0,function(e,t){if(s(),e)throw t;return t});return Promise.resolve(u&&u.then?u.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},n.wait=function(){try{var e=this;e._done_guard(),e._ws_guard();var t=e._task_id_guard();return Promise.resolve(new Promise(function(n,r){var o=function(){e.is_done=!0,e.dispose()},i=function(){try{return Promise.resolve(S(function(){return Promise.resolve(e.query()).then(function(t){t.done&&(n(e._result),o())})},function(e){r(e),o()}))}catch(e){return Promise.reject(e)}};e.when_interrupted(function(e){r(new Error("Execution Interrupted")),o()}),e._connect(i),e._connect(e.client.on("executed",function(n){try{return n.prompt_id!==t||(e.resolve_to_result(n),i()),Promise.resolve()}catch(e){return Promise.reject(e)}})),e._connect(e.client.on("execution_success",function(e){try{return e.prompt_id!==t||i(),Promise.resolve()}catch(e){return Promise.reject(e)}}))}))}catch(e){return Promise.reject(e)}},t}(x),O=globalThis.structuredClone?globalThis.structuredClone:function(e){return JSON.parse(JSON.stringify(e))},A=/*#__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,n,r){return n in t?t[n]:function(t){return e.node(n,t)}}})},t.node=function(e,t){var n=/*#__PURE__*/u().mark(i),r={class_type:e,inputs:t},o=(++this._last_node_id).toString();function i(){var e;return u().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e=0;case 1:return t.next=4,[o,e++];case 4:t.next=1;break;case 6:case"end":return t.stop()}},n)}this._workflow.prompt[o]=r;for(var s=i(),c=0;c<24;c++)s[c]=[o,c];return s},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 O(this._workflow)},t._ws_connected_guard=function(e){if(!e.socket||e.socket.readyState!==e.WebSocket.OPEN){var t,n,r,o=(t={},t[e.WebSocket.CLOSED]="CLOSED",t[e.WebSocket.CONNECTING]="CONNECTING",t[e.WebSocket.OPEN]="OPEN",t[e.WebSocket.CLOSING]="CLOSING",t[-1]="UNKNOWN",t)[null!=(n=null==(r=e.socket)?void 0:r.readyState)?n:-1];throw new Error("WebSocket is not connected, cannot invoke workflow. readyState="+o)}},t.invoke=function(e,t){try{this._ws_connected_guard(e);var n=this.instance(e,t);return Promise.resolve(n.enqueue()).then(function(){return n.wait()})}catch(e){return Promise.reject(e)}},t.instance=function(e,t){var n=this.workflow();return new E({workflow:n,client:e,resolver:null==t?void 0:t.resolver,progress:null==t?void 0:t.progress})},t.invoke_polling=function(e,t){if("function"==typeof(null==t?void 0:t.progress))throw new Error("progress option is not supported in polling mode");var n=this.workflow();return e.enqueue_polling(n.prompt,{workflow:n.workflow,resolver:null==t?void 0:t.resolver,polling_ms:null==t?void 0:t.polling_ms})},e}(),C=/*#__PURE__*/function(){function e(){this.hooks=[]}var t=e.prototype;return t.install=function(e){for(var t,r=function(){var n=t.value,r=e,o=r[n.name].bind(e);r[n.name]=function(){return n.fn.bind(e).apply(void 0,[o].concat([].slice.call(arguments)))}},o=n(this.hooks);!(t=o()).done;)r()},t.addHook=function(e){this.hooks.push(e)},e}(),L=/*#__PURE__*/function(e){function t(t){var n,r;return(r=e.call(this)||this).options=void 0,n=this,r.options=t,r.addHook({type:"function",name:"apiURL",fn:function(e){var t=e.apply(void 0,[].slice.call(arguments,1)),r=new URL(t);return r.searchParams.set("token",n.options.token),r.toString()}}),r.addHook({type:"function",name:"wsURL",fn:function(e){var t=e.apply(void 0,[].slice.call(arguments,1)),r=new URL(t);return r.searchParams.set("token",n.options.token),r.toString()}}),r}return i(t,e),t}(C),N={__proto__:null,LoginAuthPlugin:L};function T(e,t,n){if(!e.s){if(n instanceof I){if(!n.s)return void(n.o=T.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(T.bind(null,e,t),T.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}e.NSPipeline=void 0,(j=e.NSPipeline||(e.NSPipeline={})).samplers=["euler","euler_cfg_pp","euler_ancestral","euler_ancestral_cfg_pp","heun","heunpp2","dpm_2","dpm_2_ancestral","lms","dpm_fast","dpm_adaptive","dpmpp_2s_ancestral","dpmpp_sde","dpmpp_sde_gpu","dpmpp_2m","dpmpp_2m_sde","dpmpp_2m_sde_gpu","dpmpp_3m_sde","dpmpp_3m_sde_gpu","ddpm","lcm","ipndm","ipndm_v","deis","ddim","uni_pc","uni_pc_bh2"],j.schedulers=["normal","karras","exponential","sgm_uniform","simple","ddim_uniform","beta"];const I=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){const r=new e,o=this.s;if(o){const e=1&o?t:n;if(e){try{T(r,1,e(this.v))}catch(e){T(r,2,e)}return r}return this}return this.o=function(e){try{const o=e.v;1&e.s?T(r,1,t?t(o):o):n?T(r,1,n(o)):T(r,2,o)}catch(e){T(r,2,e)}},r},e}();var U="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function q(e){return e instanceof I&&1&e.s}var R=/*#__PURE__*/function(e){function t(n){var o;return(o=e.call(this)||this).context=void 0,o._workflow=new A,o._invoked=void 0,o.context=r({},t.defaultContext,n),o}i(t,e),t.nextSeed=function(){return Math.floor(Math.random()*Math.pow(2,32))};var n=t.prototype;return n.update=function(e){Object.assign(this.context,e)},n.image=function(e){return this.update({input_image:e}),this},n.mask=function(e){return this.update({input_mask:e}),this},n.model=function(e){return this.update({ckpt_name:e}),this},n.size=function(e,t){return this.update({width:e,height:t}),this},n.prompt=function(e){return this.update({positive:e}),this},n.negative=function(e){return this.update({negative:e}),this},n.steps=function(e){return this.update({steps:e}),this},n.cfg=function(e){return this.update({cfg:e}),this},n.seed=function(e){return void 0===e&&(e=t.nextSeed()),this.update({seed:e}),this},n.denoise=function(e){return this.update({denoise:e}),this},n.scheduler=function(e){return this.update({scheduler:e}),this},n.sampler=function(e){return this.update({sampler_name:e}),this},n.batch_size=function(e){return this.update({batch_size:e}),this},n.with=function(e){return this.update({client:e}),this},n.on=function(e,t,n){var r=this._invoked;if(!r)throw new Error("workflow not invoked");return r.then(function(r){r.on(e,t,n)}),this},n.once=function(e,t,n){var r=this._invoked;if(!r)throw new Error("workflow not invoked");return r.then(function(r){r.once(e,t,n)}),this},n.build_latent=function(e){var t=this.context,n=this._workflow.classes,r=this.context,o=r.input_image,i=r.input_mask,s=r.grow_mask_by;if(!o)return n.EmptyLatentImage({width:t.width,height:t.height,batch_size:t.batch_size})[0];var u=n.ETN_LoadImageBase64({image:o.toString("base64")})[0];if(!i)return n.VAEEncode({pixels:u,vae:e})[0];var c=n.ETN_LoadMaskBase64({mask:i.toString("base64")})[0];return n.VAEEncodeForInpaint({pixels:u,vae:e,mask:c,grow_mask_by:s})[0]},n.build=function(){var e=this.context,t=this._workflow.classes,n=e.seed,r=e.steps,o=e.cfg,i=e.scheduler,s=e.denoise,u=e.positive,c=e.negative,a=e.sampler_name,l=t.CheckpointLoaderSimple({ckpt_name:e.ckpt_name}),h=l[1],f=l[2],p=function(e){return t.CLIPTextEncode({text:e,clip:h})[0]};return{samples:t.KSampler({seed:n,steps:r,cfg:o,sampler_name:a,scheduler:i,denoise:s,model:l[0],positive:p(u),negative:p(c),latent_image:this.build_latent(f)})[0],vae:f,cls:t}},n._save=function(e){var t=this.build(),n=t.cls,r=n.VAEDecode({samples:t.samples,vae:t.vae})[0];e?n.SaveImage({filename_prefix:e,images:r}):n.SaveImageWebsocket({images:r})},n.read_response=function(e){try{var t=[],n=function(e,t){if("function"==typeof e[U]){var n,r,o,i=function(e){try{for(;!(n=s.next()).done;)if((e=t(n.value))&&e.then){if(!q(e))return void e.then(i,o||(o=T.bind(null,r=new I,2)));e=e.v}r?T(r,1,e):r=e}catch(e){T(r||(r=new I),2,e)}},s=e[U]();if(i(),s.return){var u=function(e){try{n.done||s.return()}catch(e){}return e};if(r&&r.then)return r.then(u,function(e){throw u(e)});u()}return r}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],a=0;a<e.length;a++)c.push(e[a]);return function(e,t){var n,r,o=-1;return function i(s){try{for(;++o<e.length;)if((s=t(o))&&s.then){if(!q(s))return void s.then(i,r||(r=T.bind(null,n=new I,2)));s=s.v}n?T(n,1,s):n=s}catch(e){T(n||(n=new I),2,e)}}(),n}(c,function(e){return t(c[e])})}(e.images,function(e){var n=function(e,t){var n,r=-1;e:{for(var o=0;o<t.length;o++){var i=t[o][0];if(i){var s=i();if(s&&s.then)break e;if(s===e){r=o;break}}else r=o}if(-1!==r){do{for(var u=t[r][1];!u;)r++,u=t[r][1];var c=u();if(c&&c.then){n=!0;break e}var a=t[r][2];r++}while(a&&!a());return c}}var l=new I,h=T.bind(null,l,2);return(n?c.then(f):s.then(function n(s){for(;;){if(s===e){r=o;break}if(++o===t.length){if(-1!==r)break;return void T(l,1,c)}if(i=t[o][0]){if((s=i())&&s.then)return void s.then(n).then(void 0,h)}else r=o}do{for(var u=t[r][1];!u;)r++,u=t[r][1];var c=u();if(c&&c.then)return void c.then(f).then(void 0,h);var a=t[r][2];r++}while(a&&!a());T(l,1,c)})).then(void 0,h),l;function f(e){for(;;){var n=t[r][2];if(!n||n())break;r++;for(var o=t[r][1];!o;)r++,o=t[r][1];if((e=o())&&e.then)return void e.then(f).then(void 0,h)}T(l,1,e)}}(e.type,[[function(){return"buff"},function(){t.push({data:e.data,mime:e.mime})}],[function(){return"url"},function(){return Promise.resolve(fetch(e.data)).then(function(e){var n,r=null!=(n=e.headers.get("content-type"))?n:"image/png";return Promise.resolve(e.blob()).then(function(e){var n=t.push;return Promise.resolve(e.arrayBuffer()).then(function(e){n.call(t,{data:e,mime:r})})})})}]]);if(n&&n.then)return n.then(function(){})});return Promise.resolve(n&&n.then?n.then(function(){return t}):t)}catch(e){return Promise.reject(e)}},n.save=function(e){var t=this,n=this.context.client,r=this._workflow;if(!n)throw new Error("client is not defined");return this._save(e),this._invoked=function(){try{var e=r.instance(n);return e._connect(function(){return t.dispose()}),Promise.resolve(e.enqueue()).then(function(){return e})}catch(e){return Promise.reject(e)}}(),this},n.wait=function(){try{var e=this,t=e._invoked;if(!t)throw new Error("workflow not invoked");return Promise.resolve(t).then(function(t){return Promise.resolve(t.wait()).then(function(t){return Promise.resolve(e.read_response(t)).then(function(e){return{result:t,images:e}})})})}catch(e){return Promise.reject(e)}},n.wait_polling=function(){try{var e=this,t=e._invoked;if(!t)throw new Error("workflow not invoked");return Promise.resolve(t).then(function(t){return Promise.resolve(t.wait_polling()).then(function(t){return Promise.resolve(e.read_response(t)).then(function(e){return{result:t,images:e}})})})}catch(e){return Promise.reject(e)}},t}(x);R.defaultContext={seed:R.nextSeed(),steps:35,cfg:4,sampler_name:"dpmpp_2m_sde_gpu",scheduler:"karras",denoise:1,width:512,height:512,batch_size:1,ckpt_name:"",input_image:null,input_mask:null,grow_mask_by:6,positive:"",negative:"",client:null};var W=/*#__PURE__*/function(e){function t(n){var o;return(o=e.call(this)||this).context=r({},t.defaultContext,n),o}i(t,e);var o=t.prototype;return o.lora=function(e,t){var n=void 0===t?{}:t,r=n.weight,o=n.strength,i=n.clip_strength;return this.context.loras.push({name:e,weight:void 0===r?1:r,model_strength:void 0===o?1:o,clip_strength:void 0===i?1:i}),this},o.cnet=function(e,t,n){var r=void 0===n?{}:n,o=r.strength,i=r.start,s=r.end;return this.context.control_net_blocks.push({image:t,name:e,strength:void 0===o?1:o,start:void 0===i?0:i,end:void 0===s?1:s}),this},o.build_lora_stack=function(){var e=this.context.loras;if(0!==e.length){for(var t=this._workflow.classes,n={lora_count:e.length},o=0;o<50;o++){var i=e[o];if(i){var s=i.weight,u=i.model_strength,c=i.clip_strength;n["lora_name_"+o]=i.name,n["lora_wt_"+o]=s,n["model_str_"+o]=u,n["clip_str_"+o]=c}else n["lora_name_"+o]="None",n["lora_wt_"+o]=1,n["model_str_"+o]=1,n["clip_str_"+o]=1}return t["LoRA Stacker"](r({input_mode:"advanced"},n))[0]}},o.build_cnet_block=function(e,t){var n=e.image,r=e.strength,o=e.start,i=e.end,s=this._workflow,u=s.classes,c=u.ETN_LoadImageBase64,a=s.classes,l=(0,u.ControlNetLoader)({control_net_name:e.name})[0],h=c({image:n.toString("base64")});return a["Control Net Stacker"]({control_net:l,image:h[0],strength:r,start_percent:o,end_percent:i,cnet_stack:t})[0]},o.build_cnet_stack=function(){var e=this.context.control_net_blocks;if(0!==e.length){for(var t,r=void 0,o=n(e);!(t=o()).done;)r=this.build_cnet_block(t.value,r);return r}},o.build=function(){var e=this.context,t=this._workflow.classes,n=e.seed,r=e.steps,o=e.cfg,i=e.scheduler,s=e.denoise,u=e.sampler_name,c=t["Efficient Loader"]({ckpt_name:e.ckpt_name,vae_name:e.vae_name,clip_skip:e.clip_skip,token_normalization:e.token_normalization,weight_interpretation:e.weight_interpretation,empty_latent_height:e.height,empty_latent_width:e.width,batch_size:e.batch_size,positive:e.positive,negative:e.negative,lora_stack:this.build_lora_stack(),cnet_stack:this.build_cnet_stack(),lora_name:"None",lora_model_strength:1,lora_clip_strength:1}),a=c[4];return{samples:t.KSampler({seed:n,steps:r,cfg:o,sampler_name:u,scheduler:i,denoise:s,model:c[0],positive:c[1],negative:c[2],latent_image:this.build_latent(a)})[0],vae:a,cls:t}},t}(R);W.defaultContext=r({},R.defaultContext,{vae_name:"Baked VAE",clip_skip:-2,token_normalization:"none",weight_interpretation:"A1111",loras:[],control_net_blocks:[]});var D=P,F=d,H=A,B=C;e.BasePipe=R,e.Client=P,e.ClientPlugin=B,e.ComfyUIApiClient=D,e.ComfyUIW