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 56.4 kB
function e(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 t(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,f(r.key),r)}}function n(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function r(t,n){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,n){if(t){if("string"==typeof t)return e(t,n);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){r&&(t=r);var o=0;return function(){return o>=t.length?{done:!0}:{done:!1,value:t[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 o(){return o=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},o.apply(null,arguments)}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,l(e,t)}function u(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(u=function(){return!!e})()}function c(){var e,t,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",o=n.toStringTag||"@@toStringTag";function i(n,r,o,i){var c=Object.create((r&&r.prototype instanceof u?r:u).prototype);return a(c,"_invoke",function(n,r,o){var i,u,c,a=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function(t,n){return i=t,u=0,c=e,h.n=n,s}};function d(n,r){for(u=n,c=r,t=0;!f&&a&&!o&&t<l.length;t++){var o,i=l[t],d=h.p,p=i[2];n>3?(o=p===r)&&(c=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=n<2&&d<i[1])?(u=0,h.v=r,h.n=i[1]):d<p&&(o=n<3||i[0]>r||r>p)&&(i[4]=n,i[5]=r,h.n=p,u=0))}if(o||n>1)return s;throw f=!0,r}return function(o,l,p){if(a>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,p),u=l,c=p;(t=u<2?e:c)||!f;){i||(u?u<3?(u>1&&(h.n=-1),d(u,c)):h.n=c:h.v=c);try{if(a=2,i){if(u||(o="next"),t=i[o]){if(!(t=t.call(i,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,u<2&&(u=0)}else 1===u&&(t=i.return)&&t.call(i),u<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),u=1);i=e}else if((t=(f=h.n<0)?c:n.call(r,h))!==s)break}catch(t){i=e,u=1,c=t}finally{a=1}}return{value:t,done:f}}}(n,o,i),!0),c}var s={};function u(){}function l(){}function f(){}t=Object.getPrototypeOf;var h=[][r]?t(t([][r]())):(a(t={},r,function(){return this}),t),d=f.prototype=u.prototype=Object.create(h);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,a(e,o,"GeneratorFunction")),e.prototype=Object.create(d),e}return l.prototype=f,a(d,"constructor",f),a(f,"constructor",l),l.displayName="GeneratorFunction",a(f,o,"GeneratorFunction"),a(d),a(d,o,"Generator"),a(d,r,function(){return this}),a(d,"toString",function(){return"[object Generator]"}),(c=function(){return{w:i,m:p}})()}function a(e,t,n,r){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}a=function(e,t,n,r){function i(t,n){a(e,t,function(e){return this._invoke(t,n,e)})}t?o?o(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},a(e,t,n,r)}function l(e,t){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},l(e,t)}function f(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 h(e){var t="function"==typeof Map?new Map:void 0;return h=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(u())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var o=new(e.bind.apply(e,r));return n&&l(o,n.prototype),o}(e,arguments,i(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),l(n,e)},h(e)}var d,p,v=(d=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],f=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),f){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(f-1);a<f;a++)c[a-1]=arguments[a];l.fn.apply(l.context,c)}else{var h,d=l.length;for(a=0;a<d;a++)switch(l[a].once&&this.removeListener(e,l[a].fn,void 0,!0),f){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(h=1,c=new Array(f-1);h<f;h++)c[h-1]=arguments[h];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},d(p={exports:{}}),p.exports),m=function(e){return null==e},_=/*#__PURE__*/function(e){function t(t){return e.call(this,t)||this}return s(t,e),t}(/*#__PURE__*/h(Error)),g=/*#__PURE__*/function(e){function t(t,n){return e.call(this,"Prompt "+t+" timed out after "+n+" ms")||this}return s(t,e),t}(_),w=/*#__PURE__*/function(e){function t(t){var n,r=t.error,o=t.node_errors,i="string"==typeof r?r:null==(n=r.errors)?void 0:n[0].message,s=o?JSON.stringify(o):"";return e.call(this,"Failed to enqueue prompt: "+i+", details: "+s)||this}return s(t,e),t}(_),y=/*#__PURE__*/function(e){function t(t){return e.call(this,"Client enqueue error: "+t)||this}return s(t,e),t}(_),b=/*#__PURE__*/function(e){function t(t){return e.call(this,"Prompt ["+t+"] not found in history")||this}return s(t,e),t}(_),k=/*#__PURE__*/function(e){function t(t){return e.call(this,"Task data type error, please try updating comfyui version: "+JSON.stringify(t))||this}return s(t,e),t}(_),P=/*#__PURE__*/function(e){function t(t,n){return e.call(this,"Prompt "+t+" execution failed with status: "+n)||this}return s(t,e),t}(_),x=/*#__PURE__*/function(e){function t(t){return e.call(this,"Client request error: "+t)||this}return s(t,e),t}(_),S=/*#__PURE__*/function(e){function t(t){return e.call(this,"Polling timed out after "+t+" ms")||this}return s(t,e),t}(_),j=/*#__PURE__*/function(e){function t(t){return e.call(this,"WebSocket timed out after "+t+" ms")||this}return s(t,e),t}(_),O=/*#__PURE__*/function(e){function t(t){return e.call(this,"Connect error: "+t)||this}return s(t,e),t}(_),E=/*#__PURE__*/function(e){function t(t){return e.call(this,"WebSocket parse error: "+t)||this}return s(t,e),t}(_),A=/*#__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 s(t,e),t}(/*#__PURE__*/h(Error));function T(e,t,n){if(!e.s){if(n instanceof L){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)}}var L=/*#__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{T(r,1,i(this.v))}catch(e){T(r,2,e)}return r}return this}return this.o=function(e){try{var 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}(),C="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function N(e){return e instanceof L&&1&e.s}var I=/*#__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 v,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 O("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.readBinaryData=function(e){var t=new DataView(e),n=t.getUint32(0),r=t.getUint32(1);switch(n){case 3:var o=new TextDecoder,i=e.slice(4),s=t.getUint32(4);return[{type:"progress_text",data:{nodeId:o.decode(i.slice(4,4+s)),text:o.decode(i.slice(4+s))}}];case 1:var u={1:"image/jpeg",2:"image/png"}[r]||"image/png",c=e.slice(8);return[{type:"b_preview",data:new Blob([c],{type:u})}];case 4:var a=new TextDecoder,l=t.getUint32(4),f=e.slice(8,8+l),h=JSON.parse(a.decode(f)),d=e.slice(8+l),p=new Blob([d],{type:h.image_type});return[{type:"b_preview_with_metadata",data:{blob:p,nodeId:h.node_id,displayNodeId:h.display_node_id,parentNodeId:h.parent_node_id,realNodeId:h.real_node_id,promptId:h.prompt_id}},{type:"b_preview",data:p}];default:throw new E("Unknown binary websocket message of type "+n)}};var t=e.prototype;return t.apiHeaders=function(e){var t;return o({},this.user?{"Comfy-User":this.user}:{},{Accept:"*/*"},null!=(t=null==e?void 0:e.headers)?t:{})},t.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()},t.internalURL=function(e){return this.apiURL("/internal"+e)},t.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},t.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()},t.fetchApi=function(e,t){try{var n=this,r=n.apiURL(e);return Promise.resolve(n.fetch(r,o({},t,{headers:n.apiHeaders(t)}))).then(function(e){var t=e.status,n=e.statusText,o=function(){if(t<200||t>=400)return Promise.resolve(e.json()).then(function(e){throw new A("Endpoint Bad Request ("+t+" "+n+"): "+r,t,e)})}();return o&&o.then?o.then(function(t){return e}):e})}catch(e){return Promise.reject(e)}},t.addEventListener=function(e,t,n){var r=this;return this.events.on(e,t,n),function(){r.events.off(e,t)}},t.on=function(e,t,n){return this.addEventListener(e,t,n)},t.once=function(e,t,n){var r=this;return this.events.once(e,t,n),function(){r.events.off(e,t)}},t.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))},t.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)}},t.removeSocketCallbacks=function(){if(this.socket)for(var e in this.socket_callbacks)this.socket.removeEventListener(e,this.socket_callbacks[e]);this.socket_callbacks={}},t.createSocket=function(t){var n=this,r=this;if(void 0===t&&(t=!1),!this.socket){if(!this.WebSocket)throw new O("WebSocket is not defined, please provide a WebSocket implementation");if(!this.closed){var o=!1;this.socket=new this.WebSocket(this.wsURL()),this.socket.binaryType="arraybuffer",this.addSocketCallback(this.socket,"open",function(){o=!0,r.events.emit(t?"reconnected":"connected")}),this.addSocketCallback(this.socket,"error",function(e){var n,i=e,s=null==(n=i.message)?void 0:n.includes("404");r.events.emit("connection_error",{type:"404",message:i.message}),r.socket&&r.socket.close(),s||t||o||r.startPollingQueue()}),this.addSocketCallback(this.socket,"close",function(){setTimeout(function(){r.socket=null,r.createSocket(!0)},300),o&&(r.events.emit("status",null),r.events.emit("reconnecting"))}),this.addSocketCallback(this.socket,"message",function(t){try{var r;return n.events.emit("message",t),Promise.resolve(function(){if(function(e){return!("string"==typeof e.data||!(ArrayBuffer&&e.data instanceof ArrayBuffer||Buffer&&Buffer.isBuffer(e.data)))}(t))return function(e,t,n){if("function"==typeof e[C]){var r,o,i,s=function(e){try{for(;!((r=u.next()).done||n&&n());)if((e=t(r.value))&&e.then){if(!N(e))return void e.then(s,i||(i=T.bind(null,o=new L,2)));e=e.v}o?T(o,1,e):o=e}catch(e){T(o||(o=new L),2,e)}},u=e[C]();if(s(),u.return){var c=function(e){try{r.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(c,function(e){throw c(e)});c()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],l=0;l<e.length;l++)a.push(e[l]);return function(e,t,n){var r,o,i=-1;return function s(u){try{for(;++i<e.length&&(!n||!n());)if((u=t(i))&&u.then){if(!N(u))return void u.then(s,o||(o=T.bind(null,r=new L,2)));u=u.v}r?T(r,1,u):r=u}catch(e){T(r||(r=new L),2,e)}}(),r}(a,function(e){return t(a[e])},n)}(e.readBinaryData(t.data),function(e){return 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 L,f=T.bind(null,l,2);return(n?c.then(h):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,f)}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(h).then(void 0,f);var a=t[r][2];r++}while(a&&!a());T(l,1,c)})).then(void 0,f),l;function h(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(h).then(void 0,f)}T(l,1,e)}}(e.type,[[function(){return"b_preview"},function(){n.events.emit("b_preview",e.data);var t=n.events,r=t.emit;return Promise.resolve(e.data.arrayBuffer()).then(function(n){r.call(t,"image_data",{image:n,mime:e.data.type})})}],[function(){return"b_preview_with_metadata"},function(){n.events.emit("b_preview_with_metadata",e.data);var t=n.events,r=t.emit;return Promise.resolve(e.data.blob.arrayBuffer()).then(function(n){r.call(t,"image_data",{image:n,mime:e.data.blob.type})})}],[function(){return"progress_text"},function(){n.events.emit("progress_text",e.data)}],[void 0,function(){r=1}]])},function(){return r});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)}())}catch(e){return Promise.reject(e)}})}}},t.init=function(){this.createSocket()},t.close=function(){this.closed||(this.closed=!0,this.events.emit("close"),this.disconnect(),this.events.removeAllListeners())},t.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 S(l))},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 j(l))},l);n.once("connected",function(){e(!0),clearTimeout(r)})});throw new O("You must enable either polling or websocket")},t.disconnect=function(){this.socket?this._disconnectSocket():process.nextTick(this._disconnectPolling.bind(this)),this._disconnectPolling()},t._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())}},t._disconnectPolling=function(){null!==this._polling_timer&&(clearInterval(this._polling_timer),this._polling_timer=null)},n(e,[{key:"registered",get:function(){return this.events.eventNames()}}])}();I.DEFAULT_API_HOST="127.0.0.1:8188",I.DEFAULT_API_BASE="",I.DEFAULT_USER="",I.IS_BROWSER="undefined"!=typeof window;var U={image:function(e,t,n){var r=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,o=e.type;return m(t)||m(n)||!["output","temp"].includes(o)?null:r.viewURL(t,n,o)}).filter(Boolean).map(function(e){return{type:"url",data:e}});return o({},e,{images:[].concat(e.images,i)})}},R={__proto__:null,RESOLVERS:U},q=/*#__PURE__*/function(e){function t(t,n,r,o){var i;return(i=e.call(this,t)||this).task_id=void 0,i.workflow=void 0,i.invoked=void 0,i.task_id=n,i.workflow=r,i.invoked=o,i}return s(t,e),t}(/*#__PURE__*/h(Error)),D=/*#__PURE__*/function(e){function t(t,n,r,o){var i;return(i=e.call(this,"Execution error: "+t.exception_message+" ("+t.exception_type+")",n,r,o)||this).payload=void 0,i.payload=t,i}return s(t,e),t}(q),W=/*#__PURE__*/function(e){function t(t,n){return e.call(this,"Client connection error ("+t+"): "+n)||this}return s(t,e),t}(/*#__PURE__*/h(Error)),B=/*#__PURE__*/function(e){function t(t,n){var r;return(r=e.call(this,t)||this).invoked=void 0,r.workflow=void 0,r.invoked=n,r.workflow=n.workflow,r}return s(t,e),t}(/*#__PURE__*/h(Error)),F=/*#__PURE__*/function(e){function t(t){return e.call(this,"This workflow is already enqueued",t)||this}return s(t,e),t}(B),H=/*#__PURE__*/function(e){function t(t){return e.call(this,"This workflow is not enqueued and the execution status cannot be interrupted",t)||this}return s(t,e),t}(B),M=/*#__PURE__*/function(e){function t(t){return e.call(this,t.is_done?"This workflow has already finished":"This workflow has been disposed",t)||this}return s(t,e),t}(B),J=/*#__PURE__*/function(e){function t(t){return e.call(this,"WebSocket is not connected",t)||this}return s(t,e),t}(B),z=/*#__PURE__*/function(e){function t(t){var n=t.task_id;return e.call(this,n?"Cannot get task status for task "+n:"Cannot get task status",t)||this}return s(t,e),t}(B),G=/*#__PURE__*/function(e){function t(t){return e.call(this,"Execution has been interrupted",t)||this}return s(t,e),t}(B),V=/*#__PURE__*/function(e){function t(t,n){return e.call(this,n,t)||this}return s(t,e),t}(B),Q=/*#__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 K(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function X(e,t,n){if(!e.s){if(n instanceof Y){if(!n.s)return void(n.o=X.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(X.bind(null,e,t),X.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var Y=/*#__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{X(r,1,i(this.v))}catch(e){X(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?X(r,1,t?t(o):o):n?X(r,1,n(o)):X(r,2,o)}catch(e){X(r,2,e)}},r},e}();function $(e){return e instanceof Y&&1&e.s}var Z=/*#__PURE__*/function(e){function t(t){var n;return(n=e.call(this,t)||this)._plugins=[],n}s(t,e);var n=t.prototype;return n.use=function(e){e.install(this),this._plugins.push(e)},n.getExtensions=function(){var e=this;return 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)}}()},n.getEmbeddings=function(){var e=this;return 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)}}()},n.getNodeDefs=function(){var e=this;return 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)}}()},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{var t=JSON.parse(e);throw new w(t)}catch(t){throw new w({error:e,node_errors:{}})}})}();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(K(function(){return Promise.resolve(e.fetchApi("/queue")).then(function(e){return Promise.resolve(e.json()).then(function(e){return{Running:e.queue_running,Pending:e.queue_pending}})})},function(e){return console.error(e),{Running:[],Pending:[]}}))}catch(e){return Promise.reject(e)}},n.getHistory=function(e,t){void 0===e&&(e=200);try{var n=this,r=(t||{}).offset;if(void 0!==r&&(r<0||!Number.isInteger(r)))throw new Error("Invalid offset parameter: "+r+". Must be a non-negative integer.");var o=new URLSearchParams({max_items:e.toString()});return void 0!==r&&o.set("offset",r.toString()),Promise.resolve(K(function(){return Promise.resolve(n.fetchApi("/history?"+o.toString())).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(e){void 0===e&&(e=null);try{return Promise.resolve(this.postApi("interrupt",e?{prompt_id:e}:void 0)).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),o({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 x("Error storing user data file '"+e+"': "+t.status+" "+n)})}()})}catch(e){return Promise.reject(e)}},n.getModelFolders=function(){try{return Promise.resolve(this.fetchApi("/experiment/models")).then(function(e){if(404===e.status)return[];var t=["configs","custom_nodes"];return Promise.resolve(e.json()).then(function(e){return e.filter(function(e){return!t.includes(e.name)})})})}catch(e){return Promise.reject(e)}},n.getModels=function(e){try{return Promise.resolve(this.fetchApi("/experiment/models/"+e)).then(function(e){return 404===e.status?[]:Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}},n.viewMetadata=function(e,t){try{return Promise.resolve(this.fetchApi("/view_metadata/"+e+"?filename="+encodeURIComponent(t))).then(function(e){return Promise.resolve(e.text()).then(function(t){if(!t)return null;try{return JSON.parse(t)}catch(n){return console.error("Error viewing metadata",e.status,e.statusText,t,n),null}})})}catch(e){return Promise.reject(e)}},n.getLogs=function(){try{return Promise.resolve(this.fetchApi(this.internalURL("/logs"))).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}},n.getRawLogs=function(){try{return Promise.resolve(this.fetchApi(this.internalURL("/logs/raw"))).then(function(e){return Promise.resolve(e.json())})}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=function(e){var t;if(!e)return null;if("prompt"in e)return null==(t=e.prompt)?void 0:t[1];if(Array.isArray(e))return e[1];throw new k(e)},o=t.Running.some(function(t){return r(t)===e}),i=n.some(function(t){return r(t)===e});return{running:o,pending:i,done:!o&&!i}})}catch(e){return Promise.reject(e)}},n.getPromptOutputs=function(e){try{return Promise.resolve(this.getHistory()).then(function(t){var n,r,o=t.History.find(function(t){return t.prompt[1]===e});if(!o)throw new b(e);var i=null!=(n=null==(r=o.status)?void 0:r.status_str)?n:"error";if("error"===i)throw new P(e,null!=i?i:"error");return o.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=U.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,n){void 0===t&&(t=1e3),void 0===n&&(n=3e5);try{var r=this,o=Date.now();return Promise.resolve(r.getPromptStatus(e)).then(function(i){return function(e,t,n){for(var r;;){var o=e();if($(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!$(i)){r=1;break}i=i.s}}var s=new Y,u=X.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):X(s,1,i)})).then(void 0,u),s;function c(t){i=t;do{if(!(o=e())||$(o)&&!o.v)return void X(s,1,i);if(o.then)return void o.then(a).then(void 0,u);$(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):X(s,1,i)}}(function(){return!i.done},0,function(){if(n>=0&&Date.now()-o>n)throw new g(e,n);return Promise.resolve(new Promise(function(e){return setTimeout(e,t)})).then(function(){return Promise.resolve(r.getPromptStatus(e)).then(function(e){i=e})})})})}catch(e){return Promise.reject(e)}},n.waitForPromptWebSocket=function(e,t,n){void 0===n&&(n=3e5);try{var r=this,o={images:[],prompt_id:e,data:null},i=new Q;return Promise.resolve(new Promise(function(s,u){var c=!1;i._connect(r.on("executing",function(t){c=(null==t?void 0:t.prompt_id)===e})),i._connect(r.on("image_data",function(e){c&&o.images.push({type:"buff",data:e.image,mime:e.mime})})),i._connect(r.on("executed",function(n){if(n.prompt_id===e){var i=t(o,n.output,{client:r,prompt_id:e,node_id:n.node});s(i)}})),i._connect(r.on("execution_error",function(t){u(new D(t,e))}));var a=setTimeout(function(){u(new g(e,n))},n);i._connect(function(){return clearTimeout(a)})}).finally(function(){i.dispose()}))}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 w(e);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,null==t?void 0:t.timeout_ms)).then(function(){return Promise.resolve(n.getPromptResult(r,U.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 y("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,null==t?void 0:t.timeout_ms)).then(function(){var e;return Promise.resolve(n.getPromptResult(r,null!=(e=null==t?void 0:t.resolver)?e:U.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:U.image,null==t?void 0:t.timeout_ms))}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 r=o({},"progress"in n?o({},n.progress):{},n);r.prompt_id===t&&e(r)}):function(){}},t}(I);function ee(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var te,ne=/*#__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.delay_done_ms=500,n.is_current_ws_executing=!1,n.options=t;var r=t.client,o=t.resolver;return n.workflow=t.workflow,n.client=r,n.resolver=o||U.image,n}s(t,e);var r=t.prototype;return r._enqueue_guard=function(){if(this.enqueued)throw new F(this);this.enqueued=!0},r._task_id_guard=function(){if(!this._task_id)throw new H(this);return this._task_id},r._done_guard=function(){if(this._disposed||this.is_done)throw new M(this)},r._ws_guard=function(){if(this.client.closed)throw new O("The WebSocket connection has been closed. Please ensure that the client is connected.");if(null===this.client.socket)throw new J(this)},r.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},r.on=function(e,t,n){var r=this;this._done_guard();var o=this.client.on(e,function(){var n=[].slice.call(arguments);if("image_data"===e||"b_preview"===e){if(!r.is_current_ws_executing)return}else if(!r.is_owner_event.apply(r,n))return;t.apply(void 0,n)});return this._connect(o),o},r.once=function(e,t,n){var r=this;this._done_guard();var o=this.client.on(e,function(){var n=[].slice.call(arguments);if("image_data"===e||"b_preview"===e){if(!r.is_current_ws_executing)return}else if(!r.is_owner_event.apply(r,n))return;t.apply(void 0,n),o()});return this._connect(o),o},r.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(),e.hook_executing()})}catch(e){return Promise.reject(e)}},r.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 V(e,"options.progress hook must be a function");if("string"!=typeof n)throw new H(e);var r=e.client.on_progress(t,n);return e._connect(r),Promise.resolve()}catch(e){return Promise.reject(e)}},r.hook_executing=function(){try{var e=this,t=e.client,n=e._task_id_guard();return e._connect(t.on("executing",function(t){e.is_current_ws_executing=(null==t?void 0:t.prompt_id)===n})),Promise.resolve()}catch(e){return Promise.reject(e)}},r.hook_image_data=function(){try{var e=this;return e._connect(e.client.on("image_data",function(t){!1!==e.is_current_ws_executing&&e._result.images.push({type:"buff",data:t.image,mime:t.mime})})),Promise.resolve()}catch(e){return Promise.reject(e)}},r.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})},r.query=function(){try{var e=this._task_id_guard();return Promise.resolve(this.client.getPromptStatus(e))}catch(e){return Promise.reject(e)}},r.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(t);throw new z(e)}e.client.deleteItem("queue",t)}})}catch(e){return Promise.reject(e)}},r.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:U.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)}},r.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)}))},r.when_execution_error=function(e){var t=this._task_id_guard();this._connect(this.client.on("execution_error",function(n){n.prompt_id===t&&e(n)}))},r.on_start=function(e){var t=this._task_id_guard();return this._connect(this.client.on("execution_start",function(n){n.prompt_id===t&&e()}))},r.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 G(n)),s()}),n.when_execution_error(function(e){i(new D(e,r,n.workflow,n)),s()});var u=function(s,u){try{var c=ee(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(function(e){return null==n.options.on_error||n.options.on_error(e),Promise.reject(e)}))}catch(e){return Promise.reject(e)}},r.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(e,t){var n=null;return function(){var r=arguments;n&&clearTimeout(n),n=setTimeout(function(){return e.apply(void 0,[].slice.call(r))},t)}}(function(){try{return e.is_done?Promise.resolve():Promise.resolve(ee(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.delay_done_ms);e.when_interrupted(function(t){r(new G(e)),o()}),e.when_execution_error(function(n){r(new D(n,t,e.workflow,e)),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(function(t){return null==e.options.on_error||e.options.on_error(t),Promise.reject(t)}))}catch(e){return Promise.reject(e)}},n(t,[{key:"is_disposed",get:function(){return this._disposed}},{key:"task_id",get:function(){return this._task_id}}])}(Q),re=globalThis.structuredClone?globalThis.structuredClone:function(e){return JSON.parse(JSON.stringify(e))},oe=/*#__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__*/c().m(i),r={class_type:e,inputs:t},o=(++this._last_node_id).toString();function i(){var e;return c().w(function(t){for(;;)switch(t.n){case 0:e=0;case 1:return t.n=2,[o,e++];case 2:t.n=1;break;case 3:return t.a(2)}},n)}this._workflow.prompt[o]=r;for(var s=i(),u=0;u<24;u++)s[u]=[o,u];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 re(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 ne({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}(),ie=/*#__PURE__*/function(){function e(){this.hooks=[]}var t=e.prototype;return t.install=function(e){for(var t,n=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=r(this.hooks);!(t=o()).done;)n()},t.addHook=function(e){this.hooks.push(e)},e}(),se={__proto__:null,LoginAuthPlugin:/*#__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 s(t,e),t}(ie)};function ue(e,t,n){if(!e.s){if(n instanceof ce){if(!n.s)return void(n.o=ue.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(ue.bind(null,e,t),ue.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}!function(e){e.samplers=["euler","euler_cfg_pp","euler_ancestral","euler_ancestral_cfg_pp","heun","heunpp2","exp_heun_2_x0","exp_heun_2_x0_sde","dpm_2","dpm_2_ancestral","lms","dpm_fast","dpm_adaptive","dpmpp_2s_ancestral","dpmpp_2s_ancestral_cfg_pp","dpmpp_sde","dpmpp_sde_gpu","dpmpp_2m","dpmpp_2m_cfg_pp","dpmpp_2m_sde","dpmpp_2m_sde_gpu","dpmpp_2m_sde_heun","dpmpp_2m_sde_heun_gpu","dpmpp_3m_sde","dpmpp_3m_sde_gpu","ddpm","lcm","ipndm","ipndm_v","deis","res_multistep","res_multistep_cfg_pp","res_multistep_ancestral","res_multistep_ancestral_cfg_pp","gradient_estimation","gradient_estimation_cfg_pp","er_sde","seeds_2","seeds_3","sa_solver","sa_solver_pece","ddim","uni_pc","uni_pc_bh2"],e.schedulers=["simple","sgm_uniform","karras","exponential","ddim_uniform","beta","normal","linear_quadratic","kl_optimal"]}(te||(te={}));const ce=/*#__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{ue(r,1,e(this.v))}catch(e){ue(r,2,e)}return r}return this}return this.o=function(e){try{const o=e.v;1&e.s?ue(r,1,t?t(o):o):n?ue(r,1,n(o)):ue(r,2,o)}catch(e){ue(r,2,e)}},r},e}();var ae="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function le(e){return e instanceof ce&&1&e.s}var fe=/*#__PURE__*/function(e){function t(n){var r;return(r=e.call(this)||this).context=void 0,r._workflow=new oe,r._invoked=void 0,r.context=o({},t.defaultContext,n),r}s(t,e),t.nextSeed=function(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)};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}),f=l[1],h=l[2],d=function(e){return t.CLIPTextEncode({text:e,clip:f})[0]};return{samples:t.KSampler({seed:n,steps:r,cfg:o,sampler_name:a,scheduler:i,denoise:s,model:l[0],positive:d(u),negative:d(c),latent_image:this.build_latent(h)})[0],vae:h,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[ae]){var n,r,o,i=function(e){try{for(;!(n=s.next()).done;)if((e=t(n.value))&&e.then){if(!le(e))return void e.then(i,o||(o=ue.bind(null,r=new ce,2)));e=e.v}r?ue(r,1,e):r=e}catch(e){ue(r||(r=new ce),2,e)}},s=e[ae]();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(!le(s))return void s.then(i,r||(r=ue.bind(null,n=new ce,2)));s=s.v}n?ue(n,1,s):n=s}catch(e){ue(n||(n=new ce),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());retu