UNPKG

@node-ai/comfyui

Version:

node-ai for comfyui

5 lines (4 loc) 34.7 kB
"use strict";var Ut=Object.create;var G=Object.defineProperty;var Bt=Object.getOwnPropertyDescriptor;var Pt=Object.getOwnPropertyNames;var jt=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty;var m=(n,e)=>()=>(n&&(e=n(n=0)),e);var y=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),$t=(n,e)=>{for(var t in e)G(n,t,{get:e[t],enumerable:!0})},xe=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Pt(e))!Ct.call(n,r)&&r!==t&&G(n,r,{get:()=>e[r],enumerable:!(i=Bt(e,r))||i.enumerable});return n};var z=(n,e,t)=>(t=n!=null?Ut(jt(n)):{},xe(e||!n||!n.__esModule?G(t,"default",{value:n,enumerable:!0}):t,n)),kt=n=>xe(G({},"__esModule",{value:!0}),n);var Se=y(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.isNone=void 0;var It=n=>n==null;K.isNone=It});var Q=y(C=>{"use strict";var Et=C&&C.__createBinding||(Object.create?function(n,e,t,i){i===void 0&&(i=t);var r=Object.getOwnPropertyDescriptor(e,t);(!r||("get"in r?!e.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(n,i,r)}:function(n,e,t,i){i===void 0&&(i=t),n[i]=e[t]}),Ft=C&&C.__exportStar||function(n,e){for(var t in n)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Et(e,n,t)};Object.defineProperty(C,"__esModule",{value:!0});Ft(Se(),C)});function A(){return V>Y.length-16&&(Oe.default.randomFillSync(Y),V=0),Y.slice(V,V+=16)}var Oe,Y,V,oe=m(()=>{Oe=z(require("crypto")),Y=new Uint8Array(256),V=Y.length});var Ue,Be=m(()=>{Ue=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i});function qt(n){return typeof n=="string"&&Ue.test(n)}var B,M=m(()=>{Be();B=qt});function $(n,e=0){return p[n[e+0]]+p[n[e+1]]+p[n[e+2]]+p[n[e+3]]+"-"+p[n[e+4]]+p[n[e+5]]+"-"+p[n[e+6]]+p[n[e+7]]+"-"+p[n[e+8]]+p[n[e+9]]+"-"+p[n[e+10]]+p[n[e+11]]+p[n[e+12]]+p[n[e+13]]+p[n[e+14]]+p[n[e+15]]}function Tt(n,e=0){let t=$(n,e);if(!B(t))throw TypeError("Stringified UUID is invalid");return t}var p,Pe,W=m(()=>{M();p=[];for(let n=0;n<256;++n)p.push((n+256).toString(16).slice(1));Pe=Tt});function Lt(n,e,t){let i=e&&t||0,r=e||new Array(16);n=n||{};let o=n.node||je,s=n.clockseq!==void 0?n.clockseq:se;if(o==null||s==null){let h=n.random||(n.rng||A)();o==null&&(o=je=[h[0]|1,h[1],h[2],h[3],h[4],h[5]]),s==null&&(s=se=(h[6]<<8|h[7])&16383)}let c=n.msecs!==void 0?n.msecs:Date.now(),a=n.nsecs!==void 0?n.nsecs:ce+1,d=c-ae+(a-ce)/1e4;if(d<0&&n.clockseq===void 0&&(s=s+1&16383),(d<0||c>ae)&&n.nsecs===void 0&&(a=0),a>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");ae=c,ce=a,se=s,c+=122192928e5;let l=((c&268435455)*1e4+a)%4294967296;r[i++]=l>>>24&255,r[i++]=l>>>16&255,r[i++]=l>>>8&255,r[i++]=l&255;let u=c/4294967296*1e4&268435455;r[i++]=u>>>8&255,r[i++]=u&255,r[i++]=u>>>24&15|16,r[i++]=u>>>16&255,r[i++]=s>>>8|128,r[i++]=s&255;for(let h=0;h<6;++h)r[i+h]=o[h];return e||$(r)}var je,se,ae,ce,Ce,$e=m(()=>{oe();W();ae=0,ce=0;Ce=Lt});function At(n){if(!B(n))throw TypeError("Invalid UUID");let e,t=new Uint8Array(16);return t[0]=(e=parseInt(n.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(n.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(n.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(n.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(n.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}var X,de=m(()=>{M();X=At});function Mt(n){n=unescape(encodeURIComponent(n));let e=[];for(let t=0;t<n.length;++t)e.push(n.charCodeAt(t));return e}function N(n,e,t){function i(r,o,s,c){var a;if(typeof r=="string"&&(r=Mt(r)),typeof o=="string"&&(o=X(o)),((a=o)===null||a===void 0?void 0:a.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let d=new Uint8Array(16+r.length);if(d.set(o),d.set(r,o.length),d=t(d),d[6]=d[6]&15|e,d[8]=d[8]&63|128,s){c=c||0;for(let l=0;l<16;++l)s[c+l]=d[l];return s}return $(d)}try{i.name=n}catch{}return i.DNS=Wt,i.URL=Nt,i}var Wt,Nt,le=m(()=>{W();de();Wt="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Nt="6ba7b811-9dad-11d1-80b4-00c04fd430c8"});function Dt(n){return Array.isArray(n)?n=Buffer.from(n):typeof n=="string"&&(n=Buffer.from(n,"utf8")),ke.default.createHash("md5").update(n).digest()}var ke,Ie,Ee=m(()=>{ke=z(require("crypto"));Ie=Dt});var Rt,Fe,qe=m(()=>{le();Ee();Rt=N("v3",48,Ie),Fe=Rt});var Te,ue,Le=m(()=>{Te=z(require("crypto")),ue={randomUUID:Te.default.randomUUID}});function Jt(n,e,t){if(ue.randomUUID&&!e&&!n)return ue.randomUUID();n=n||{};let i=n.random||(n.rng||A)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){t=t||0;for(let r=0;r<16;++r)e[t+r]=i[r];return e}return $(i)}var Ae,Me=m(()=>{Le();oe();W();Ae=Jt});function Ht(n){return Array.isArray(n)?n=Buffer.from(n):typeof n=="string"&&(n=Buffer.from(n,"utf8")),We.default.createHash("sha1").update(n).digest()}var We,Ne,De=m(()=>{We=z(require("crypto"));Ne=Ht});var Gt,Re,Je=m(()=>{le();De();Gt=N("v5",80,Ne),Re=Gt});var He,Ge=m(()=>{He="00000000-0000-0000-0000-000000000000"});function zt(n){if(!B(n))throw TypeError("Invalid UUID");return parseInt(n.slice(14,15),16)}var ze,Ke=m(()=>{M();ze=zt});var Qe={};$t(Qe,{NIL:()=>He,parse:()=>X,stringify:()=>Pe,v1:()=>Ce,v3:()=>Fe,v4:()=>Ae,v5:()=>Re,validate:()=>B,version:()=>ze});var Ve=m(()=>{$e();qe();Me();Je();Ge();Ke();M();W();de()});var Xe=y((Qi,fe)=>{"use strict";var Kt=Object.prototype.hasOwnProperty,g="~";function D(){}Object.create&&(D.prototype=Object.create(null),new D().__proto__||(g=!1));function Qt(n,e,t){this.fn=n,this.context=e,this.once=t||!1}function Ye(n,e,t,i,r){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new Qt(t,i||n,r),s=g?g+e:e;return n._events[s]?n._events[s].fn?n._events[s]=[n._events[s],o]:n._events[s].push(o):(n._events[s]=o,n._eventsCount++),n}function Z(n,e){--n._eventsCount===0?n._events=new D:delete n._events[e]}function _(){this._events=new D,this._eventsCount=0}_.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)Kt.call(t,i)&&e.push(g?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};_.prototype.listeners=function(e){var t=g?g+e:e,i=this._events[t];if(!i)return[];if(i.fn)return[i.fn];for(var r=0,o=i.length,s=new Array(o);r<o;r++)s[r]=i[r].fn;return s};_.prototype.listenerCount=function(e){var t=g?g+e:e,i=this._events[t];return i?i.fn?1:i.length:0};_.prototype.emit=function(e,t,i,r,o,s){var c=g?g+e:e;if(!this._events[c])return!1;var a=this._events[c],d=arguments.length,l,u;if(a.fn){switch(a.once&&this.removeListener(e,a.fn,void 0,!0),d){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,t),!0;case 3:return a.fn.call(a.context,t,i),!0;case 4:return a.fn.call(a.context,t,i,r),!0;case 5:return a.fn.call(a.context,t,i,r,o),!0;case 6:return a.fn.call(a.context,t,i,r,o,s),!0}for(u=1,l=new Array(d-1);u<d;u++)l[u-1]=arguments[u];a.fn.apply(a.context,l)}else{var h=a.length,v;for(u=0;u<h;u++)switch(a[u].once&&this.removeListener(e,a[u].fn,void 0,!0),d){case 1:a[u].fn.call(a[u].context);break;case 2:a[u].fn.call(a[u].context,t);break;case 3:a[u].fn.call(a[u].context,t,i);break;case 4:a[u].fn.call(a[u].context,t,i,r);break;default:if(!l)for(v=1,l=new Array(d-1);v<d;v++)l[v-1]=arguments[v];a[u].fn.apply(a[u].context,l)}}return!0};_.prototype.on=function(e,t,i){return Ye(this,e,t,i,!1)};_.prototype.once=function(e,t,i){return Ye(this,e,t,i,!0)};_.prototype.removeListener=function(e,t,i,r){var o=g?g+e:e;if(!this._events[o])return this;if(!t)return Z(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!r||s.once)&&(!i||s.context===i)&&Z(this,o);else{for(var c=0,a=[],d=s.length;c<d;c++)(s[c].fn!==t||r&&!s[c].once||i&&s[c].context!==i)&&a.push(s[c]);a.length?this._events[o]=a.length===1?a[0]:a:Z(this,o)}return this};_.prototype.removeAllListeners=function(e){var t;return e?(t=g?g+e:e,this._events[t]&&Z(this,t)):(this._events=new D,this._eventsCount=0),this};_.prototype.off=_.prototype.removeListener;_.prototype.addListener=_.prototype.on;_.prefixed=g;_.EventEmitter=_;typeof fe<"u"&&(fe.exports=_)});var me=y(O=>{"use strict";var Ze=O&&O.__awaiter||function(n,e,t,i){function r(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(l){try{d(i.next(l))}catch(u){s(u)}}function a(l){try{d(i.throw(l))}catch(u){s(u)}}function d(l){l.done?o(l.value):r(l.value).then(c,a)}d((i=i.apply(n,e||[])).next())})},S=O&&O.__classPrivateFieldGet||function(n,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?n!==e||!i:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(n):i?i.value:e.get(n)},he=O&&O.__classPrivateFieldSet||function(n,e,t,i,r){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?n!==e||!r:!e.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?r.call(n,t):r?r.value=t:e.set(n,t),t},P,k,R,ve,et,tt,it;Object.defineProperty(O,"__esModule",{value:!0});O.ComfyUIWsClient=void 0;var Vt=(Ve(),kt(Qe)),Yt=Xe(),nt=typeof window<"u",pe=class{constructor(e){P.add(this),this.config=e,this.closed=!1,this.socketReconnectDelay=300,this.events=new Yt.EventEmitter,this.socketCallbacks={},k.set(this,null),R.set(this,1e3),this.logError=!0,this.log=(o,s,c)=>{var a;if(!((a=this.config)===null||a===void 0)&&a.debug){let{logger:d}=this.config;d?d(o,s):console[o](s)}else o==="error"&&this.logError&&console.error(c||s)},e?.logError===!1&&(this.logError=!1);let t=e?.serverAddress||"127.0.0.1:8188";t.endsWith("/")&&(t=t.substring(0,t.length-1));let i=e?.ssl?"s":"",r=t.split("://");if(r.length>1){let o=r[0];this.apiBaseUrl=`${o}://${r[1]}`,this.wsBaseUrl=`${o.replace("http","ws")}://${r[1]}`}else this.apiBaseUrl=`http${i}://${r[0]}`,this.wsBaseUrl=`ws${i}://${r[0]}`;if(this.host=new URL(this.apiBaseUrl).host,this.user=e?.user||"",this.clientId=e?.clientId||(0,Vt.v4)(),e?.WebSocket)this.WebSocket=e.WebSocket;else{let o;if(nt&&(typeof WebSocket<"u"?o=WebSocket:typeof MozWebSocket<"u"?o=MozWebSocket:typeof global<"u"?o=global.WebSocket||global.MozWebSocket:typeof window<"u"?o=window.WebSocket||window.MozWebSocket:typeof self<"u"&&(o=self.WebSocket||self.MozWebSocket)),!o)throw new Error("WebSocket is not defined, please config it manual");this.WebSocket=o}if(e?.fetch)this.fetch=e.fetch;else if(globalThis.fetch)this.fetch=globalThis.fetch;else throw new Error("fetch is not defined, please config it manual")}apiURL(e){return`${this.apiBaseUrl}/${e}`}viewURL(e,t,i,r,o){let s=new URLSearchParams(Object.entries({filename:e,subfolder:t,type:i,preview:r,channel:o}).reduce((c,[a,d])=>(d!=null&&(c[a]=d.toString()),c),{})).toString();return`${this.apiBaseUrl}/view?${s}`}fetchApi(e,t){return Ze(this,void 0,void 0,function*(){var i;let r=Object.assign(Object.assign(Object.assign({},this.user?{"Comfy-User":this.user}:{}),{Accept:"*/*"}),(i=t?.headers)!==null&&i!==void 0?i:{}),o=this.apiURL(e);return this.doFetch(o,Object.assign(Object.assign({},t),{headers:r}))})}addEventListener(e,t,i){return this.events.on(e,t,i),()=>{this.events.off(e,t)}}addOnceEventListener(e,t,i){return this.events.once(e,t,i),()=>{this.events.off(e,t)}}removeEventListener(e,t){this.events.off(e,t)}on(e,t,i){return this.addEventListener(e,t,i)}once(e,t,i){return this.addOnceEventListener(e,t,i)}off(e,t){return this.removeEventListener(e,t)}addSocketCallback(e,t,i,r){return this.socketCallbacks[t]=i,e.addEventListener(t,i,r),()=>{delete this.socketCallbacks[t],e.removeEventListener(t,i,r)}}removeSocketCallbacks(){if(this.socket)for(let e in this.socketCallbacks){let t=this.socketCallbacks[e];this.socket.removeEventListener(e,t)}this.socketCallbacks={}}loadImageData(e){let i=new DataView(e).getUint32(0),r=e.slice(4);switch(i){case 1:let s=new DataView(r).getUint32(0),c;switch(s){case 1:c="image/jpeg";break;case 2:default:c="image/png";break}return{image:e.slice(8),mime:c};case 2:default:throw new Error(`Unknown binary websocket message of type ${i}`)}}close(){this.closed||(this.closed=!0,this.disconnect(),this.events.removeAllListeners())}connect({polling:e={enabled:!1},websocket:t={enabled:!0}}={}){var i;return e?.enabled&&(he(this,R,(i=e.interval)!==null&&i!==void 0?i:S(this,R,"f"),"f"),S(this,P,"m",ve).call(this)),t?.enabled&&S(this,P,"m",et).call(this),this}waitForConnect(e={}){return new Promise((t,i)=>{if(this.socket&&this.socket.readyState===1){t();return}let r=()=>{this.off("open",o),this.off("error",s)},o=()=>{r(),t()},s=c=>{r(),i(c)};this.on("open",o),this.on("error",s),this.connect(e)})}disconnect(){S(this,P,"m",tt).call(this),S(this,P,"m",it).call(this)}getFetchHeaders(e){var t;return Object.assign(Object.assign(Object.assign({},this.user?{"Comfy-User":this.user}:{}),{Accept:"*/*"}),(t=e?.headers)!==null&&t!==void 0?t:{})}doFetch(e,t){return t??(t={}),t.headers=this.getFetchHeaders(t),this.fetch(e,t)}};O.ComfyUIWsClient=pe;k=new WeakMap,R=new WeakMap,P=new WeakSet,ve=function(){S(this,k,"f")||he(this,k,setInterval(()=>Ze(this,void 0,void 0,function*(){try{let t=yield(yield this.fetchApi("/prompt")).json();this.events.emit("status",t)}catch{this.events.emit("status",null)}}),S(this,R,"f")),"f")},et=function n(e=!1){if(this.socket||this.closed)return;let t=!1,i="";this.clientId&&(i="?clientId="+this.clientId);let r=`${this.wsBaseUrl}/ws${i}`;this.log("info",`Connecting to url: ${r}`),this.socket=new this.WebSocket(r),this.socket.binaryType="arraybuffer",this.addSocketCallback(this.socket,"open",()=>{this.log("info","Connection open"),t=!0,e?this.events.emit("reconnected"):this.events.emit("open")}),this.addSocketCallback(this.socket,"error",s=>{this.log("warn",`WebSockets error: ${s}`),this.socket&&this.socket.close(),this.events.emit("error",s),!e&&!t&&S(this,P,"m",ve).call(this)}),this.addSocketCallback(this.socket,"close",()=>{this.log("info","Connection closed"),setTimeout(()=>{this.socket=null,S(this,P,"m",n).call(this,!0)},this.socketReconnectDelay),t&&(this.events.emit("status",null),this.events.emit("reconnecting"))});let o=s=>typeof s.data=="string"?!1:nt?s.data instanceof Blob:!!(ArrayBuffer&&s.data instanceof ArrayBuffer||Buffer&&Buffer.isBuffer(s.data));this.addSocketCallback(this.socket,"message",s=>{typeof s.data!="string"?this.log("debug","Received binary data"):this.log("debug",`Received data: ${s.data.toString()}`),this.events.emit("message",s.data);try{if(o(s)){let a=this.loadImageData(s.data);this.events.emit("image_data",a)}else{let a=JSON.parse(s.data);switch(a.type){case"status":a.data.sid&&(this.clientId=a.data.sid),this.events.emit("status",a.data.status);break;case"execution_start":this.events.emit("execution_start",a.data);break;case"execution_interrupted":this.events.emit("execution_interrupted",a.data);break;case"executing":this.events.emit(a.data.node?"executing":"execution_finish",a.data);break;case"execution_cached":this.events.emit("execution_cached",a.data);break;case"progress":this.events.emit("progress",a.data);break;case"executed":this.events.emit("executed",a.data);break;case"execution_error":this.events.emit("execution_error",a.data);break;case"download_progress":this.events.emit("download_progress",a.data);break;default:let{type:l,data:u}=a;this.events.emit(l,u)}let{type:d}=a;d!=="message"&&!this.events.eventNames().includes(d)&&this.events.emit("unhandled",d,a.data)}}catch(a){this.log("error",`exception when process message: ${a} [${s.data}]`,a)}})},tt=function(){var e;let{socket:t}=this;if(t){if(this.socket=null,t.readyState===1){this.log("info","Closing connection");try{t.close(1e3,"Client closed")}catch{}}this.removeSocketCallbacks(),"removeAllListeners"in t&&((e=t.removeAllListeners)===null||e===void 0||e.call(t))}},it=function(){S(this,k,"f")!==null&&(clearInterval(S(this,k,"f")),he(this,k,null,"f"))}});var rt=y(ie=>{"use strict";Object.defineProperty(ie,"__esModule",{value:!0});ie.CachedFn=void 0;var ee=class n{constructor(){this._cached=globalThis[n.__KEY__]||new Map,globalThis[n.__KEY__]=this._cached}clear(){this._cached.clear()}get(e){return this._cached.get(e)}set(e,t){this._cached.set(e,t)}};ee.__KEY__="__GLOBAL_CACHE__";var te=class n{constructor(e,t){var i,r;this._cached=new ee,this.cache_ns="",this.expire_time_ms=(i=t?.expire_time)!==null&&i!==void 0?i:n._defaultExpire,this.enabled=(r=t?.enabled)!==null&&r!==void 0?r:!0,this.cache_ns=e}reset(){this._cached.clear()}_hashArgs(e){try{return JSON.stringify(e)}catch{return e.toString()}}warp(e,t){return this.enabled?(...i)=>{let r=Date.now(),o=this._hashArgs(i),s=`${this.cache_ns}:${e}:${o}`,c=this._cached.get(s);if(c&&c.expire>r)return c.result;let a=t(...i);return this._cached.set(s,{result:a,expire:r+this.expire_time_ms}),a}:t}};ie.CachedFn=te;te._defaultExpire=60*1e3});var ge=y(x=>{"use strict";var f=x&&x.__awaiter||function(n,e,t,i){function r(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(l){try{d(i.next(l))}catch(u){s(u)}}function a(l){try{d(i.throw(l))}catch(u){s(u)}}function d(l){l.done?o(l.value):r(l.value).then(c,a)}d((i=i.apply(n,e||[])).next())})},Xt=x&&x.__classPrivateFieldSet||function(n,e,t,i,r){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?n!==e||!r:!e.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?r.call(n,t):r?r.value=t:e.set(n,t),t},F=x&&x.__classPrivateFieldGet||function(n,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?n!==e||!i:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(n):i?i.value:e.get(n)},Zt=x&&x.__rest||function(n,e){var t={};for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&e.indexOf(i)<0&&(t[i]=n[i]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(n);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(n,i[r])&&(t[i[r]]=n[i[r]]);return t},U;Object.defineProperty(x,"__esModule",{value:!0});x.ComfyUIApiClient=void 0;var _e=Q(),ei=me(),ti=rt(),ii=require("node:assert");function ni(n){return f(this,arguments,void 0,function*(e,t="json",i){try{let r,o=e.headers.get("content-length");if(o){let s=parseInt(o);if(e.status>=400)throw new Error(s>0?yield e.text():"");if(s>0){if(r=yield e[t](),r&&typeof r=="object"&&"error"in r)throw new Error(JSON.stringify(r));return r}}return}catch(r){throw i?.("error",r.message),new Error(r.message)}})}var ye=class extends ei.ComfyUIWsClient{constructor(e){super(e),U.set(this,void 0);let t=`${this.apiBaseUrl}`;Xt(this,U,new ti.CachedFn(t),"f")}extractBody(e,t="json"){return ni(e,t,this.log)}getExtensions(){return f(this,void 0,void 0,function*(){let e=()=>f(this,void 0,void 0,function*(){let i=yield this.doFetch(`${this.apiBaseUrl}/extensions`);return this.extractBody(i)});return F(this,U,"f").warp("extensions",e)()})}getEmbeddings(){return f(this,void 0,void 0,function*(){let e=()=>f(this,void 0,void 0,function*(){let i=yield this.fetchApi(`${this.apiBaseUrl}/embeddings`);return this.extractBody(i)});return F(this,U,"f").warp("embeddings",e)()})}getModelTypes(){return f(this,void 0,void 0,function*(){let e=()=>f(this,void 0,void 0,function*(){let i=yield this.fetchApi(`${this.apiBaseUrl}/models`);return this.extractBody(i)});return F(this,U,"f").warp("embeddings",e)()})}getModels(e){return f(this,void 0,void 0,function*(){let t=()=>f(this,void 0,void 0,function*(){let r=yield this.fetchApi(`${this.apiBaseUrl}/models/${e}`);return this.extractBody(r)});return F(this,U,"f").warp("embeddings",t)()})}getObjectInfo(e){return f(this,void 0,void 0,function*(){let t=()=>f(this,void 0,void 0,function*(){let r=yield this.doFetch(`${this.apiBaseUrl}/object_info`+(e?`/${e}`:""));return this.extractBody(r)});return F(this,U,"f").warp("object_info",t)()})}resetCache(){F(this,U,"f").reset()}getSettings(){return f(this,void 0,void 0,function*(){let e=yield this.doFetch(`${this.apiBaseUrl}/settings`);return this.extractBody(e)})}getSetting(e){return f(this,void 0,void 0,function*(){let t=yield this.doFetch(`${this.apiBaseUrl}/settings/${encodeURIComponent(e)}`);return this.extractBody(t)})}putSettings(e){return f(this,void 0,void 0,function*(){let t=yield this.doFetch(`${this.apiBaseUrl}/settings`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return this.extractBody(t)})}putSetting(e,t){return f(this,void 0,void 0,function*(){let i=yield this.doFetch(`${this.apiBaseUrl}/settings/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return this.extractBody(i)})}getUsers(){return f(this,void 0,void 0,function*(){let e=yield this.doFetch(`${this.apiBaseUrl}/users`);return this.extractBody(e)})}createUser(e){return f(this,void 0,void 0,function*(){let t=yield this.doFetch(`${this.apiBaseUrl}/users`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e})});return this.extractBody(t)})}getUserDataList(e,t,i,r){return f(this,void 0,void 0,function*(){let o=yield this.doFetch(`${this.apiBaseUrl}/userdata?`+new URLSearchParams({dir:e,recurse:t?"true":"false",full_info:i?"true":"false",split:r?"true":"false"}).toString());return this.extractBody(o)})}getUserData(e){return f(this,void 0,void 0,function*(){let t=yield this.doFetch(`${this.apiBaseUrl}/userdata/${encodeURIComponent(e)}`);return this.extractBody(t)})}putUserData(e,t){return f(this,void 0,void 0,function*(){let i=yield this.doFetch(`${this.apiBaseUrl}/userdata/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:typeof t=="object"?JSON.stringify(t):t});return this.extractBody(i)})}getSystemStats(){return f(this,void 0,void 0,function*(){let e=yield this.doFetch(`${this.apiBaseUrl}/system_stats`);return this.extractBody(e)})}getPrompt(){return f(this,void 0,void 0,function*(){let e=yield this.doFetch(`${this.apiBaseUrl}/prompt`);return this.extractBody(e)})}getHistory(e){return f(this,arguments,void 0,function*(t,i=10){let r;t?.length?r=`/${t}`:r=`?max_items=${i}`;let o=yield this.doFetch(`${this.apiBaseUrl}/history${r}`);return this.extractBody(o)})}updateHistory(e){return f(this,void 0,void 0,function*(){let t=yield this.doFetch(`${this.apiBaseUrl}/history`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e)});yield this.extractBody(t)})}getQueue(){return f(this,void 0,void 0,function*(){let e=yield this.doFetch(`${this.apiBaseUrl}/queue`);return this.extractBody(e)})}updateQueue(e){return f(this,void 0,void 0,function*(){let t=yield this.doFetch(`${this.apiBaseUrl}/queue`,{method:"post",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e)});return this.extractBody(t)})}uploadImage(e,t,i,r,o){return f(this,void 0,void 0,function*(){let s=new FormData;s.append("image",new Blob([e]),t),i!=null&&s.append("overwrite",i.toString()),r&&s.append("type",r),o&&s.append("subfolder",o);let c=yield this.doFetch(`${this.apiBaseUrl}/upload/image`,{method:"POST",body:s});return this.extractBody(c)})}uploadMask(e,t,i,r,o,s){return f(this,void 0,void 0,function*(){let c=new FormData;c.append("image",new Blob([e]),t),c.append("original_ref",JSON.stringify(i)),r!==void 0&&c.append("overwrite",r.toString()),o&&c.append("type",o),s&&c.append("subfolder",s);let a=yield this.doFetch(`${this.apiBaseUrl}/upload/mask`,{method:"POST",body:c});return this.extractBody(a)})}viewImage(e,t,i,r,o){return f(this,arguments,void 0,function*(s,c,a,d,l,u=!0){let h=yield this.doFetch(this.viewURL(s,a,c,d,l));return u?h.arrayBuffer():h.blob()})}viewMetadata(e,t){return f(this,void 0,void 0,function*(){let i=yield this.doFetch(`${this.apiBaseUrl}/view_metadata/${e}?filename=${t}`);return this.extractBody(i)})}queuePrompt(e,t){return f(this,void 0,void 0,function*(){var i;let r={client_id:this.clientId,prompt:e,extra_data:{extra_pnginfo:Object.assign({workflow:t?.extraPnginfoWorkflow,prompt:t?.extraPnginfoPrompt?e:void 0},t?.extraPnginfo)}},o=(i=t?.queueIndex)!==null&&i!==void 0?i:0;o===-1?r.front=!0:o!==0&&(r.number=o);let s=yield this.doFetch(`${this.apiBaseUrl}/prompt`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(r)});return this.extractBody(s)})}interrupt(){return f(this,void 0,void 0,function*(){let e=yield this.doFetch(`${this.apiBaseUrl}/interrupt`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"}});yield this.extractBody(e)})}free(e,t){return f(this,void 0,void 0,function*(){let i=yield this.doFetch(`${this.apiBaseUrl}/free`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({unload_models:e,free_memory:t})});yield this.extractBody(i)})}_extract_pose_json(e){try{let t=e.output;if("openpose_json"in t)return JSON.parse(t.openpose_json[0])}catch(t){this.log("warn",`Error processing message, error=${t}, msg=${e}`)}return null}_validate_executed_node(e,t){try{let i=e.output;ii(!("openpose_json"in i));let r=i.images;if(r.length!==t&&this.log("warn",`Received number of images does not match: ${r.length} !== ${t}`),r.length>0&&r[0].type==="output")return!0}catch(i){return this.log("warn",`Error processing message, error=${i}, msg=${e}`),!1}}waitForPromptWebSocket(e,t){return f(this,void 0,void 0,function*(){let i={images:[],outputs:{},prompt_id:e},r=t?.withPreviewImage;return new Promise((o,s)=>{let c=!1,a=this.on("image_data",v=>{i.images.push({node:"",type:"buff",data:v.image,mime:v.mime})}),d=this.on("execution_finish",v=>{v.prompt_id===e&&(c=!0,h(),o(i))}),l=this.on("executed",v=>{let{node:E,prompt_id:T,output:j}=v;if(c||T!==e){this.log("warn",`when executed but finish is ${c} or current_prompt_id[${T}] !== ${e}`);return}let L=this._extract_pose_json(v);L&&(i.pose_json=L);let be=j||{},{images:xt=[]}=be,St=Zt(be,["images"]);for(let Ot of xt){let{filename:ne,subfolder:re,type:H}=Ot||{};(0,_e.isNone)(ne)||(0,_e.isNone)(re)||(0,_e.isNone)(H)||!r&&H!=="output"||i.images.push({node:E,type:"url",filename:ne,subfolder:re,dir:H,data:this.viewURL(ne,re,H)})}i.outputs[E]=St}),u=this.on("execution_error",v=>{let E=v.exception_message||"execution_error",T=v.traceback||["no traceback"],j=`${E} ${T.join(` `)}`;this.log("error",j),h(),s(new Error(j))});function h(){a(),d(),l(),u()}})})}randomizePrompt(e){for(let t of Object.values(e))t.class_type==="KSampler"&&(t.inputs.seed=Math.floor(Math.random()*(2**32-1)))}_enqueue_prompt(e,t){return t?.enableRandomSeed&&this.randomizePrompt(e),this.queuePrompt(e,t)}enqueue(e,t){return f(this,void 0,void 0,function*(){let i=yield this._enqueue_prompt(e,t);try{this.events.emit("enqueue",i)}catch(s){this.log("error","emit enqueue error",s)}let r=i.prompt_id,o;t?.progress&&(o=this.on("progress",s=>{var c;s.prompt_id===r&&((c=t?.progress)===null||c===void 0||c.call(t,s))}));try{return yield this.waitForPromptWebSocket(r,t)}finally{o?.()}})}execPromptAndWaitOutputs(e,t){return f(this,void 0,void 0,function*(){if(!this.socket)throw new Error("WebSocket client is not connected. Please call connect() before interacting.");let r=(yield this.queuePrompt(e)).prompt_id;return new Promise((o,s)=>{var c;let a={},d=l=>f(this,void 0,void 0,function*(){var u;if(typeof l.data=="string")try{let h=JSON.parse(l.data);if(h.type==="executing"){let v=h.data;if(!v.node){let E=v.prompt_id;if(this.log("info",`done executing prompt (ID: ${E})`),v.prompt_id===r){let j=(yield this.getHistory(r))[r];for(let L of Object.keys(j.outputs))if(L===t.toString()){a=j.outputs[L];break}return(u=this.socket)===null||u===void 0||u.removeEventListener("message",d),o(a)}}}}catch(h){return s(h)}});(c=this.socket)===null||c===void 0||c.addEventListener("message",d)})})}internalGetFiles(e){return f(this,void 0,void 0,function*(){let t=yield this.doFetch(`${this.apiBaseUrl}/internal/files?directory=${e}`);return this.extractBody(t)})}internalGetLogs(){return f(this,void 0,void 0,function*(){let e=yield this.doFetch(`${this.apiBaseUrl}/internal/logs`);return this.extractBody(e)})}internalGetFolderPaths(){return f(this,void 0,void 0,function*(){let e=yield this.doFetch(`${this.apiBaseUrl}/internal/folder_paths`);return this.extractBody(e)})}internalDownloadModel(e,t,i,r){return f(this,arguments,void 0,function*(o,s,c,a,d=1){let l=yield this.doFetch(`${this.apiBaseUrl}/internal/models/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:o,model_directory:s,folder_path:c,model_filename:a,progress_interval:d})});return this.extractBody(l)})}};x.ComfyUIApiClient=ye;U=new WeakMap});var st=y(q=>{"use strict";var w=q&&q.__awaiter||function(n,e,t,i){function r(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(l){try{d(i.next(l))}catch(u){s(u)}}function a(l){try{d(i.throw(l))}catch(u){s(u)}}function d(l){l.done?o(l.value):r(l.value).then(c,a)}d((i=i.apply(n,e||[])).next())})};Object.defineProperty(q,"__esModule",{value:!0});q.ComfyUIHApiClient=void 0;var ri=ge(),ot=Q(),we=class extends ri.ComfyUIApiClient{constructor(e){super(e)}getSamplers(){return w(this,void 0,void 0,function*(){var e,t,i;let o=(yield this.getObjectInfo()).KSampler;return((i=(t=(e=o?.input)===null||e===void 0?void 0:e.required)===null||t===void 0?void 0:t.sampler_name)===null||i===void 0?void 0:i[0])||[]})}getSchedulers(){return w(this,void 0,void 0,function*(){var e,t,i;let o=(yield this.getObjectInfo()).KSampler;return((i=(t=(e=o?.input)===null||e===void 0?void 0:e.required)===null||t===void 0?void 0:t.scheduler)===null||i===void 0?void 0:i[0])||[]})}getSDModels(){return w(this,void 0,void 0,function*(){var e,t,i;let o=(yield this.getObjectInfo()).CheckpointLoaderSimple;return((i=(t=(e=o?.input)===null||e===void 0?void 0:e.required)===null||t===void 0?void 0:t.ckpt_name)===null||i===void 0?void 0:i[0])||[]})}getControlNetModels(){return w(this,void 0,void 0,function*(){var e,t,i;let o=(yield this.getObjectInfo()).ControlNetLoader;return((i=(t=(e=o?.input)===null||e===void 0?void 0:e.required)===null||t===void 0?void 0:t.control_net_name)===null||i===void 0?void 0:i[0])||[]})}getUpscaleModels(){return w(this,void 0,void 0,function*(){var e,t,i;let o=(yield this.getObjectInfo()).UpscaleModelLoader;return((i=(t=(e=o?.input)===null||e===void 0?void 0:e.required)===null||t===void 0?void 0:t.model_name)===null||i===void 0?void 0:i[0])||[]})}getHyperNetworks(){return w(this,void 0,void 0,function*(){var e,t,i;let o=(yield this.getObjectInfo()).HypernetworkLoader;return((i=(t=(e=o?.input)===null||e===void 0?void 0:e.required)===null||t===void 0?void 0:t.hypernetwork_name)===null||i===void 0?void 0:i[0])||[]})}getLoRAs(){return w(this,void 0,void 0,function*(){var e,t,i;let o=(yield this.getObjectInfo()).LoraLoader;return((i=(t=(e=o?.input)===null||e===void 0?void 0:e.required)===null||t===void 0?void 0:t.lora_name)===null||i===void 0?void 0:i[0])||[]})}getVAEs(){return w(this,void 0,void 0,function*(){var e,t,i;let o=(yield this.getObjectInfo()).VAELoader;return((i=(t=(e=o?.input)===null||e===void 0?void 0:e.required)===null||t===void 0?void 0:t.vae_name)===null||i===void 0?void 0:i[0])||[]})}getPromptStatus(e){return w(this,void 0,void 0,function*(){let{queue_running:t,queue_pending:i}=yield this.getQueue(),r=t.some(c=>c?.[1]===e),o=i.some(c=>c?.[1]===e);return{running:r,pending:o,done:!r&&!o}})}getPromptOutputs(e){return w(this,void 0,void 0,function*(){let i=(yield this.getHistory())[e];if(!i)throw new Error(`Prompt [${e}] not found in history`);let r=i.status.status_str;if(r!=="success")throw new Error(`Prompt [${e}] failed with status: ${r}`);return i.outputs})}getPromptImageResult(e){return w(this,void 0,void 0,function*(){let t=yield this.getPromptOutputs(e);return{images:Object.values(t).flatMap(o=>o.images||[]).map(o=>{let{filename:s,subfolder:c,type:a}=o;return(0,ot.isNone)(s)||(0,ot.isNone)(c)||a!=="output"?null:this.viewURL(s,c,a)}).filter(Boolean).map(o=>({type:"url",data:o})),prompt_id:e}})}waitForPrompt(e){return w(this,arguments,void 0,function*(t,i=1e3){let r=yield this.getPromptStatus(t);for(;!r.done;)yield new Promise(o=>setTimeout(o,i)),r=yield this.getPromptStatus(t)})}enqueue_polling(e,t){return w(this,void 0,void 0,function*(){let r=(yield this._enqueue_prompt(e,t)).prompt_id;return yield this.waitForPrompt(r,t?.pollingMs),this.getPromptImageResult(r)})}};q.ComfyUIHApiClient=we});var ct=y(at=>{"use strict";Object.defineProperty(at,"__esModule",{value:!0})});var lt=y(dt=>{"use strict";Object.defineProperty(dt,"__esModule",{value:!0})});var ft=y(ut=>{"use strict";Object.defineProperty(ut,"__esModule",{value:!0})});var vt=y(ht=>{"use strict";Object.defineProperty(ht,"__esModule",{value:!0})});var mt=y(pt=>{"use strict";Object.defineProperty(pt,"__esModule",{value:!0})});var yt=y(_t=>{"use strict";Object.defineProperty(_t,"__esModule",{value:!0})});var wt=y(gt=>{"use strict";Object.defineProperty(gt,"__esModule",{value:!0})});var bt=y(b=>{"use strict";var oi=b&&b.__createBinding||(Object.create?function(n,e,t,i){i===void 0&&(i=t);var r=Object.getOwnPropertyDescriptor(e,t);(!r||("get"in r?!e.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(n,i,r)}:function(n,e,t,i){i===void 0&&(i=t),n[i]=e[t]}),I=b&&b.__exportStar||function(n,e){for(var t in n)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&oi(e,n,t)};Object.defineProperty(b,"__esModule",{value:!0});I(ct(),b);I(lt(),b);I(ft(),b);I(vt(),b);I(mt(),b);I(yt(),b);I(wt(),b)});var si=exports&&exports.__createBinding||(Object.create?function(n,e,t,i){i===void 0&&(i=t);var r=Object.getOwnPropertyDescriptor(e,t);(!r||("get"in r?!e.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(n,i,r)}:function(n,e,t,i){i===void 0&&(i=t),n[i]=e[t]}),J=exports&&exports.__exportStar||function(n,e){for(var t in n)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&si(e,n,t)};Object.defineProperty(exports,"__esModule",{value:!0});J(Q(),exports);J(me(),exports);J(ge(),exports);J(st(),exports);J(bt(),exports); //# sourceMappingURL=index.js.map