@runware/sdk-js 1.1.20-beta.3 → 1.1.20-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  var Ue=Object.create;var J=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var ke=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,xe=Object.prototype.hasOwnProperty;var De=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports);var ve=(o,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ke(t))!xe.call(o,s)&&s!==e&&J(o,s,{get:()=>t[s],enumerable:!(n=be(t,s))||n.enumerable});return o};var we=(o,t,e)=>(e=o!=null?Ue(Re(o)):{},ve(t||!o||!o.__esModule?J(e,"default",{value:o,enumerable:!0}):e,o));var ce=De((vt,le)=>{"use strict";var oe=o=>o&&o.CLOSING===2,We=()=>typeof WebSocket<"u"&&oe(WebSocket),Ke=()=>({constructor:We()?WebSocket:null,maxReconnectionDelay:1e4,minReconnectionDelay:1500,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,debug:!1}),Be=(o,t,e)=>{Object.defineProperty(t,e,{get:()=>o[e],set:n=>{o[e]=n},enumerable:!0,configurable:!0})},ae=o=>o.minReconnectionDelay+Math.random()*o.minReconnectionDelay,Fe=(o,t)=>{let e=t*o.reconnectionDelayGrowFactor;return e>o.maxReconnectionDelay?o.maxReconnectionDelay:e},Ge=["onopen","onclose","onmessage","onerror"],Pe=(o,t,e)=>{Object.keys(e).forEach(n=>{e[n].forEach(([s,r])=>{o.addEventListener(n,s,r)})}),t&&Ge.forEach(n=>{o[n]=t[n]})},ie=function(o,t,e={}){let n,s,r=0,l=0,c=!0,i={};if(!(this instanceof ie))throw new TypeError("Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator");let a=Ke();if(Object.keys(a).filter(p=>e.hasOwnProperty(p)).forEach(p=>a[p]=e[p]),!oe(a.constructor))throw new TypeError("Invalid WebSocket constructor. Set `options.constructor`");let d=a.debug?(...p)=>console.log("RWS:",...p):()=>{},f=(p,m)=>setTimeout(()=>{let _=new Error(m);_.code=p,Array.isArray(i.error)&&i.error.forEach(([T])=>T(_)),n.onerror&&n.onerror(_)},0),u=()=>{if(d("close"),l++,d("retries count:",l),l>a.maxRetries){f("EHOSTDOWN","Too many failed connection attempts");return}r?r=Fe(a,r):r=ae(a),d("reconnectDelay:",r),c&&setTimeout(g,r)},g=()=>{d("connect");let p=n;n=new a.constructor(o,t),s=setTimeout(()=>{d("timeout"),n.close(),f("ETIMEDOUT","Connection timeout")},a.connectionTimeout),d("bypass properties");for(let m in n)["addEventListener","removeEventListener","close","send"].indexOf(m)<0&&Be(n,this,m);n.addEventListener("open",()=>{clearTimeout(s),d("open"),r=ae(a),d("reconnectDelay:",r),l=0}),n.addEventListener("close",u),Pe(n,p,i)};d("init"),g(),this.close=(p=1e3,m="",{keepClosed:_=!1,fastClose:T=!0,delay:D=0}={})=>{if(D&&(r=D),c=!_,n.close(p,m),T){let k={code:p,reason:m,wasClean:!0};u(),Array.isArray(i.close)&&i.close.forEach(([U,y])=>{U(k),n.removeEventListener("close",U,y)}),n.onclose&&(n.onclose(k),n.onclose=null)}},this.send=p=>{n.send(p)},this.addEventListener=(p,m,_)=>{Array.isArray(i[p])?i[p].some(([T])=>T===m)||i[p].push([m,_]):i[p]=[[m,_]],n.addEventListener(p,m,_)},this.removeEventListener=(p,m,_)=>{Array.isArray(i[p])&&(i[p]=i[p].filter(([T])=>T!==m)),n.removeEventListener(p,m,_)}};le.exports=ie});var z=(n=>(n.PRODUCTION="PRODUCTION",n.DEVELOPMENT="DEVELOPMENT",n.TEST="TEST",n))(z||{}),G=(e=>(e.CLIENT="CLIENT",e.SERVER="SERVER",e))(G||{}),P=(a=>(a.IMAGE_INFERENCE="imageInference",a.IMAGE_UPLOAD="imageUpload",a.IMAGE_UPSCALE="imageUpscale",a.IMAGE_BACKGROUND_REMOVAL="imageBackgroundRemoval",a.IMAGE_CAPTION="imageCaption",a.IMAGE_CONTROL_NET_PRE_PROCESS="imageControlNetPreProcess",a.PROMPT_ENHANCE="promptEnhance",a.AUTHENTICATION="authentication",a.MODEL_UPLOAD="modelUpload",a))(P||{}),Q=(n=>(n.BALANCED="balanced",n.PROMPT="prompt",n.CONTROL_NET="controlnet",n))(Q||{}),Y=(u=>(u.canny="canny",u.depth="depth",u.mlsd="mlsd",u.normalbae="normalbae",u.openpose="openpose",u.tile="tile",u.seg="seg",u.lineart="lineart",u.lineart_anime="lineart_anime",u.shuffle="shuffle",u.scribble="scribble",u.softedge="softedge",u))(Y||{}),Z=(h=>(h.canny="canny",h.depth_leres="depth_leres",h.depth_midas="depth_midas",h.depth_zoe="depth_zoe",h.inpaint_global_harmonious="inpaint_global_harmonious",h.lineart_anime="lineart_anime",h.lineart_coarse="lineart_coarse",h.lineart_realistic="lineart_realistic",h.lineart_standard="lineart_standard",h.mlsd="mlsd",h.normal_bae="normal_bae",h.scribble_hed="scribble_hed",h.scribble_pidinet="scribble_pidinet",h.seg_ofade20k="seg_ofade20k",h.seg_ofcoco="seg_ofcoco",h.seg_ufade20k="seg_ufade20k",h.shuffle="shuffle",h.softedge_hed="softedge_hed",h.softedge_hedsafe="softedge_hedsafe",h.softedge_pidinet="softedge_pidinet",h.softedge_pidisafe="softedge_pidisafe",h.tile_gaussian="tile_gaussian",h.openpose="openpose",h.openpose_face="openpose_face",h.openpose_faceonly="openpose_faceonly",h.openpose_full="openpose_full",h.openpose_hand="openpose_hand",h))(Z||{}),Se=(r=>(r.openpose="openpose",r.openpose_face="openpose_face",r.openpose_faceonly="openpose_faceonly",r.openpose_full="openpose_full",r.openpose_hand="openpose_hand",r))(Se||{}),Ae=(e=>(e.safetensors="safetensors",e.pickletensor="pickletensor",e))(Ae||{}),Oe=(g=>(g.flux1d="flux1d",g.flux1s="flux1s",g.pony="pony",g.sdhyper="sdhyper",g.sd1x="sd1x",g.sd1xlcm="sd1xlcm",g.sd3="sd3",g.sdxl="sdxl",g.sdxllcm="sdxllcm",g.sdxldistilled="sdxldistilled",g.sdxlhyper="sdxlhyper",g.sdxllightning="sdxllightning",g.sdxlturbo="sdxlturbo",g))(Oe||{}),Ne=(n=>(n.base="base",n.inpainting="inpainting",n.pix2pix="pix2pix",n))(Ne||{}),Ee=(y=>(y.canny="canny",y.depth="depth",y.qrcode="qrcode",y.hed="hed",y.scrible="scrible",y.openpose="openpose",y.seg="segmentation",y.openmlsd="openmlsd",y.softedge="softedge",y.normal="normal bae",y.shuffle="shuffle",y.pix2pix="pix2pix",y.inpaint="inpaint",y.lineart="line art",y.sketch="sketch",y.inpaintdepth="inpaint depth",y.tile="tile",y.outfit="outfit",y.blur="blur",y.gray="gray",y.lowquality="low quality",y))(Ee||{});import{v4 as Ce,validate as Le}from"uuid";var q=6e4,$=1e3,Me=100,H={PRODUCTION:"wss://ws-api.runware.ai/v1",TEST:"ws://localhost:8080"},X=(o,t)=>{if(o==null)return;let e=o.indexOf(t);e!==-1&&o.splice(e,1)},v=(o,{debugKey:t="debugKey",timeoutDuration:e=q,shouldThrowError:n=!0})=>(e=e<$?$:e,new Promise((s,r)=>{let l=setTimeout(()=>{c&&(clearInterval(c),n&&r(`Response could not be received from server for ${t}`)),clearTimeout(l)},e),c=setInterval(async()=>{o({resolve:s,reject:r,intervalId:c})&&(clearInterval(c),clearTimeout(l))},Me)})),ee=o=>new Promise(t=>{let e=new FileReader;e.readAsDataURL(o),e.onload=function(){t(e.result)}}),R=()=>Ce(),te=o=>Le(o);var ne=({key:o,data:t,useZero:e=!0,shouldReturnString:n=!1})=>o.split(/\.|\[/).map(l=>l.replace(/\]$/,"")).reduce((l,c)=>{let i=e?0:void 0,a=l?.[c];if(!a)return i;if(Array.isArray(a)&&/^\d+$/.test(c)){let d=parseInt(c,10);return d>=0&&d<a.length?l[c]=a[d]:l[c]??i}else return l[c]??i},t||{})??{},se=(o,t=1e3)=>new Promise(e=>setTimeout(e,o*t));var re=(o,t)=>o.filter(e=>e.key!==t.key);var I=({key:o,value:t})=>t||t===0||t===!1?{[o]:t}:{};var x=async(o,t={})=>{let{delayInSeconds:e=1,callback:n}=t,s=t.maxRetries??1;for(;s;)try{return await o()}catch(r){if(n?.(),s--,s>0)await se(e),await x(o,{...t,maxRetries:s});else throw r}};var S=class{constructor({apiKey:t,url:e=H.PRODUCTION,shouldReconnect:n=!0,globalMaxRetries:s=2,timeoutDuration:r=q}){this._listeners=[];this._globalMessages={};this._globalImages=[];this.isWebsocketReadyState=()=>this._ws?.readyState===1;this.send=t=>{this._ws.send(JSON.stringify([t]))};this.uploadImage=async t=>{try{return await x(async()=>{let e=R();if(typeof t=="string"&&te(t))return{imageURL:t,imageUUID:t,taskUUID:e,taskType:"imageUpload"};let n=typeof t=="string"?t:await ee(t);return{imageURL:n,imageUUID:n,taskUUID:e,taskType:"imageUpload"}})}catch(e){throw e}};this.controlNetPreProcess=async({inputImage:t,preProcessorType:e,height:n,width:s,outputType:r,outputFormat:l,highThresholdCanny:c,lowThresholdCanny:i,includeHandsAndFaceOpenPose:a,includeCost:d,customTaskUUID:f,retry:u})=>{let g=u||this._globalMaxRetries,p;try{return await x(async()=>{await this.ensureConnection();let m=await this.uploadImage(t);if(!m?.imageUUID)return null;let _=f||R();this.send({inputImage:m.imageUUID,taskType:"imageControlNetPreProcess",taskUUID:_,preProcessorType:e,...I({key:"height",value:n}),...I({key:"width",value:s}),...I({key:"outputType",value:r}),...I({key:"outputFormat",value:l}),...I({key:"includeCost",value:d}),...I({key:"highThresholdCanny",value:c}),...I({key:"lowThresholdCanny",value:i}),...I({key:"includeHandsAndFaceOpenPose",value:a})}),p=this.globalListener({taskUUID:_});let T=await v(({resolve:D,reject:k})=>{let U=this.getSingleMessage({taskUUID:_});if(U){if(U?.error)return k(U),!0;if(U)return D(U),!0}},{debugKey:"unprocessed-image",timeoutDuration:this._timeoutDuration});return p.destroy(),T},{maxRetries:g,callback:()=>{p?.destroy()}})}catch(m){throw m}};this.requestImageToText=async({inputImage:t,includeCost:e,customTaskUUID:n,retry:s})=>{let r=s||this._globalMaxRetries,l;try{return await x(async()=>{await this.ensureConnection();let c=t?await this.uploadImage(t):null,i=n||R();this.send({taskUUID:i,taskType:"imageCaption",inputImage:c?.imageUUID,...I({key:"includeCost",value:e})}),l=this.globalListener({taskUUID:i});let a=await v(({resolve:d,reject:f})=>{let u=this.getSingleMessage({taskUUID:i});if(u){if(u?.error)return f(u),!0;if(u)return delete this._globalMessages[i],d(u),!0}},{debugKey:"remove-image-background",timeoutDuration:this._timeoutDuration});return l.destroy(),a},{maxRetries:r,callback:()=>{l?.destroy()}})}catch(c){throw c}};this.removeImageBackground=async({inputImage:t,outputType:e,outputFormat:n,rgba:s,postProcessMask:r,returnOnlyMask:l,alphaMatting:c,alphaMattingForegroundThreshold:i,alphaMattingBackgroundThreshold:a,alphaMattingErodeSize:d,includeCost:f,customTaskUUID:u,retry:g})=>{let p=g||this._globalMaxRetries,m;try{return await x(async()=>{await this.ensureConnection();let _=t?await this.uploadImage(t):null,T=u||R();this.send({taskType:"imageBackgroundRemoval",taskUUID:T,inputImage:_?.imageUUID,...I({key:"rgba",value:s}),...I({key:"postProcessMask",value:r}),...I({key:"returnOnlyMask",value:l}),...I({key:"alphaMatting",value:c}),...I({key:"includeCost",value:f}),...I({key:"alphaMattingForegroundThreshold",value:i}),...I({key:"alphaMattingBackgroundThreshold",value:a}),...I({key:"alphaMattingErodeSize",value:d}),...I({key:"outputType",value:e}),...I({key:"outputFormat",value:n})}),m=this.globalListener({taskUUID:T});let D=await v(({resolve:k,reject:U})=>{let y=this.getSingleMessage({taskUUID:T});if(y){if(y?.error)return U(y),!0;if(y)return delete this._globalMessages[T],k(y),!0}},{debugKey:"remove-image-background",timeoutDuration:this._timeoutDuration});return m.destroy(),D},{maxRetries:p,callback:()=>{m?.destroy()}})}catch(_){throw _}};this.upscaleGan=async({inputImage:t,upscaleFactor:e,outputType:n,outputFormat:s,includeCost:r,customTaskUUID:l,retry:c})=>{let i=c||this._globalMaxRetries,a;try{return await x(async()=>{await this.ensureConnection();let d;d=await this.uploadImage(t);let f=l||R();this.send({taskUUID:f,inputImage:d?.imageUUID,taskType:"imageUpscale",upscaleFactor:e,...I({key:"includeCost",value:r}),...n?{outputType:n}:{},...s?{outputFormat:s}:{}}),a=this.globalListener({taskUUID:f});let u=await v(({resolve:g,reject:p})=>{let m=this.getSingleMessage({taskUUID:f});if(m){if(m?.error)return p(m),!0;if(m)return delete this._globalMessages[f],g(m),!0}},{debugKey:"upscale-gan",timeoutDuration:this._timeoutDuration});return a.destroy(),u},{maxRetries:i,callback:()=>{a?.destroy()}})}catch(d){throw d}};this.enhancePrompt=async({prompt:t,promptMaxLength:e=380,promptVersions:n=1,includeCost:s,customTaskUUID:r,retry:l})=>{let c=l||this._globalMaxRetries,i;try{return await x(async()=>{await this.ensureConnection();let a=r||R();this.send({prompt:t,taskUUID:a,promptMaxLength:e,promptVersions:n,...I({key:"includeCost",value:s}),taskType:"promptEnhance"}),i=this.globalListener({taskUUID:a});let d=await v(({resolve:f,reject:u})=>{let g=this._globalMessages[a];if(g?.error)return u(g),!0;if(g?.length>=n)return delete this._globalMessages[a],f(g),!0},{debugKey:"enhance-prompt",timeoutDuration:this._timeoutDuration});return i.destroy(),d},{maxRetries:c,callback:()=>{i?.destroy()}})}catch(a){throw a}};this.modelUpload=async t=>{let{onUploadStream:e,retry:n,customTaskUUID:s,...r}=t,l=n||this._globalMaxRetries,c;try{return await x(async()=>{await this.ensureConnection();let i=s||R();this.send({...r,taskUUID:i,taskType:"modelUpload"});let a,d;return c=this.listenToUpload({taskUUID:i,onUploadStream:(u,g)=>{e?.(u,g),u?.status==="ready"?a=u:g&&(d=g)}}),await v(({resolve:u,reject:g})=>{if(a)return u(a),!0;if(d)return g(d),!1},{shouldThrowError:!1,timeoutDuration:60*60*1e3})},{maxRetries:l,callback:()=>{c?.destroy()}})}catch(i){throw i}};this.getSingleMessage=({taskUUID:t})=>{let e=this._globalMessages[t]?.[0],n=this._globalMessages[t];return!e&&!n?null:n?.error?n:e};this.disconnect=async()=>{this._shouldReconnect=!1,this._ws?.terminate?.(),this._ws?.close?.()};this.connected=()=>this.isWebsocketReadyState()&&!!this._connectionSessionUUID;this._apiKey=t,this._url=e,this._sdkType="CLIENT",this._shouldReconnect=n,this._globalMaxRetries=s,this._timeoutDuration=r}static async initialize(t){try{let e=new this(t);return await e.ensureConnection(),e}catch(e){throw e}}addListener({lis:t,groupKey:e,taskUUID:n}){let s=c=>{let i=Array.isArray(c?.data)?c.data:[c.data],a=c?.[0]?.errors?c?.[0]?.errors:Array.isArray(c?.errors)?c.errors:[c.errors],d=i.filter(u=>(u?.taskUUID||u?.taskType)===n);if(a.filter(u=>(u?.taskUUID||u?.taskType)===n).length){t({error:{...a[0]??{}}});return}if(d.length){t({[n]:i});return}},r={key:n||R(),listener:s,groupKey:e};return this._listeners.push(r),{destroy:()=>{this._listeners=re(this._listeners,r)}}}connect(){this._ws.onopen=t=>{this._connectionSessionUUID?this.send({taskType:"authentication",apiKey:this._apiKey,connectionSessionUUID:this._connectionSessionUUID}):this.send({apiKey:this._apiKey,taskType:"authentication"}),this.addListener({taskUUID:"authentication",lis:e=>{if(e?.error){this._invalidAPIkey=e;return}this._connectionSessionUUID=e?.authentication?.[0]?.connectionSessionUUID,this._invalidAPIkey=void 0}})},this._ws.onmessage=t=>{let e=JSON.parse(t.data);for(let n of this._listeners)if(n?.listener?.(e))return},this._ws.onclose=t=>{this._invalidAPIkey}}destroy(t){X(this._listeners,t)}listenToImages({onPartialImages:t,taskUUID:e,groupKey:n,positivePrompt:s,negativePrompt:r}){return this.addListener({taskUUID:e,lis:l=>{let c=l?.[e]?.filter(i=>i.taskUUID===e);l.error?(t?.(c,l?.error&&l),this._globalError=l):(c=c.map(i=>({...i,positivePrompt:s,negativePrompt:r})),t?.(c,l?.error&&l),this._sdkType==="CLIENT"?this._globalImages=[...this._globalImages,...(l?.[e]??[]).map(i=>({...i,positivePrompt:s,negativePrompt:r}))]:this._globalImages=[...this._globalImages,...c])},groupKey:n})}listenToUpload({onUploadStream:t,taskUUID:e}){return this.addListener({taskUUID:e,lis:n=>{let s=n?.error,r=n?.[e]?.[0],l=r?.taskUUID===e?r:null;(l||s)&&t?.(l||void 0,s)}})}globalListener({taskUUID:t}){return this.addListener({taskUUID:t,lis:e=>{if(e.error){this._globalMessages[t]=e;return}let n=ne({key:t,data:e,useZero:!1});Array.isArray(n)?n.forEach(s=>{this._globalMessages[s.taskUUID]=[...this._globalMessages[s.taskUUID]??[],s]}):this._globalMessages[n.taskUUID]=n}})}async requestImages({outputType:t,outputFormat:e,uploadEndpoint:n,checkNsfw:s,positivePrompt:r,negativePrompt:l,seedImage:c,maskImage:i,strength:a,height:d,width:f,model:u,steps:g,scheduler:p,seed:m,CFGScale:_,clipSkip:T,usePromptWeighting:D,numberResults:k=1,controlNet:U,lora:y,onPartialImages:pe,includeCost:ge,customTaskUUID:me,retry:ye}){let A,h,N=[],V=0,j=ye||this._globalMaxRetries;try{await this.ensureConnection();let w=null,M=null,W=[];if(c){let b=await this.uploadImage(c);if(!b)return[];w=b.imageUUID}if(i){let b=await this.uploadImage(i);if(!b)return[];M=b.imageUUID}if(U?.length)for(let b=0;b<U.length;b++){let O=U[b],{endStep:K,startStep:B,weight:F,guideImage:E,controlMode:Ie,startStepPercentage:he,endStepPercentage:fe,model:_e}=O,Te=E?await this.uploadImage(E):null;W.push({guideImage:Te?.imageUUID,model:_e,endStep:K,startStep:B,weight:F,...I({key:"startStepPercentage",value:he}),...I({key:"endStepPercentage",value:fe}),controlMode:Ie||"controlnet"})}return h={taskType:"imageInference",model:u,positivePrompt:r,...l?{negativePrompt:l}:{},...d?{height:d}:{},...f?{width:f}:{},numberResults:k,...y?.length?{lora:y}:{},...t?{outputType:t}:{},...e?{outputFormat:e}:{},...n?{uploadEndpoint:n}:{},...I({key:"checkNsfw",value:s}),...I({key:"strength",value:a}),...I({key:"CFGScale",value:_}),...I({key:"clipSkip",value:T}),...I({key:"usePromptWeighting",value:D}),...I({key:"steps",value:g}),...W.length?{controlNet:W}:{},...m?{seed:m}:{},...p?{scheduler:p}:{},...I({key:"includeCost",value:ge}),...w?{seedImage:w}:{},...M?{maskImage:M}:{}},await x(async()=>{V++,A?.destroy();let b=this._globalImages.filter(E=>N.includes(E.taskUUID)),O=me||R();N.push(O);let K=k-b.length,B={...h,taskUUID:O,numberResults:K};this.send(B),A=this.listenToImages({onPartialImages:pe,taskUUID:O,groupKey:"REQUEST_IMAGES",positivePrompt:r,negativePrompt:l});let F=await this.getSimilarImages({taskUUID:N,numberResults:k,lis:A});return A.destroy(),F},{maxRetries:j,callback:()=>{A?.destroy()}})}catch(w){if(w.taskUUID)throw w;if(V>=j)return this.handleIncompleteImages({taskUUIDs:N,error:w})}}async ensureConnection(){if(this.connected()||this._url===H.TEST)return;let e=2e3,n=200;try{if(this._invalidAPIkey)throw this._invalidAPIkey;return new Promise((s,r)=>{let l=0,c=30,i=30/2===l,a,d,f=()=>{clearInterval(a),clearInterval(d)};this._sdkType==="SERVER"&&(a=setInterval(async()=>{try{this.connected()?(f(),s(!0)):l>=c?(f(),r(new Error("Retry timed out"))):(i&&this.connect(),l++)}catch(u){f(),r(u)}},e)),d=setInterval(async()=>{if(this.connected()){f(),s(!0);return}if(this._invalidAPIkey){f(),r(this._invalidAPIkey);return}},n)})}catch{throw this._invalidAPIkey??"Could not connect to server. Ensure your API key is correct"}}async getSimilarImages({taskUUID:t,numberResults:e,shouldThrowError:n,lis:s}){return await v(({resolve:r,reject:l,intervalId:c})=>{let i=Array.isArray(t)?t:[t],a=this._globalImages.filter(d=>i.includes(d.taskUUID));if(this._globalError){let d=this._globalError;return this._globalError=void 0,clearInterval(c),l?.(d),!0}else if(a.length>=e)return clearInterval(c),this._globalImages=this._globalImages.filter(d=>!i.includes(d.taskUUID)),r([...a].slice(0,e)),!0},{debugKey:"getting images",shouldThrowError:n,timeoutDuration:this._timeoutDuration})}handleIncompleteImages({taskUUIDs:t,error:e}){let n=this._globalImages.filter(s=>t.includes(s.taskUUID));if(n.length>1)return this._globalImages=this._globalImages.filter(s=>!t.includes(s.taskUUID)),n;throw e}};var ue=we(ce(),1),C=class extends S{constructor(t){let{shouldReconnect:e,...n}=t;super(n),this._ws=new ue.default(this._url),this.connect()}};import qe from"ws";var L=class extends S{constructor(e){super(e);this._instantiated=!1;this._listeners=[];this._reconnectingIntervalId=null;this.send=e=>{this._ws.send(JSON.stringify([e]))};this.resetConnection=()=>{this._ws&&(this._listeners.forEach(e=>{e?.destroy?.()}),this._ws.removeAllListeners(),this._ws.terminate(),this._ws.close(),this._ws=null,this._listeners=[])};this._sdkType="SERVER",this.connect()}async connect(){this._url&&(this.resetConnection(),this._ws=new qe(this._url,{perMessageDeflate:!1}),this._ws.on("error",()=>{}),this._ws.on("close",()=>{this.handleClose()}),this._ws.on("open",()=>{this._reconnectingIntervalId&&clearInterval(this._reconnectingIntervalId),this._connectionSessionUUID&&this.isWebsocketReadyState()?this.send({taskType:"authentication",apiKey:this._apiKey,connectionSessionUUID:this._connectionSessionUUID}):this.isWebsocketReadyState()&&this.send({apiKey:this._apiKey,taskType:"authentication"}),this.addListener({taskUUID:"authentication",lis:e=>{if(e?.error){this._invalidAPIkey=e;return}this._connectionSessionUUID=e?.authentication?.[0]?.connectionSessionUUID,this._invalidAPIkey=void 0}})}),this._ws.on("message",(e,n)=>{let s=n?e:e?.toString();if(!s)return;let r=JSON.parse(s);this._listeners.forEach(l=>{l.listener(r)})}))}handleClose(){this._invalidAPIkey||(this._reconnectingIntervalId&&clearInterval(this._reconnectingIntervalId),this._shouldReconnect&&setTimeout(()=>this.connect(),1e3))}heartBeat(){clearTimeout(this._pingTimeout),this._pingTimeout=setTimeout(()=>{this.isWebsocketReadyState()&&this.send({ping:!0})},5e3)}};var de;typeof window>"u"?de=L:de=C;export{Q as EControlMode,Oe as EModelArchitecture,Ee as EModelConditioning,Ae as EModelFormat,Ne as EModelType,Se as EOpenPosePreProcessor,Z as EPreProcessor,Y as EPreProcessorGroup,P as ETaskType,z as Environment,de as Runware,C as RunwareClient,L as RunwareServer,G as SdkType};
2
- //# sourceMappingURL=index.mjs.map
2
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@runware/sdk-js",
3
- "version": "1.1.20-beta.3",
3
+ "version": "1.1.20-beta.4",
4
4
  "description": "The SDK is used to run image inference with the Runware API, powered by the RunWare inference platform. It can be used to generate imaged with text-to-image and image-to-image. It also allows the use of an existing gallery of models or selecting any model or LoRA from the CivitAI gallery. The API also supports upscaling, background removal, inpainting and outpainting, and a series of other ControlNet models.",
5
5
  "main": "dist/index.js",
6
- "module": "dist/index.mjs",
6
+ "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "type": "module",
9
9
  "files": [
@@ -16,7 +16,8 @@
16
16
  "dev:test": "vitest --reporter verbose",
17
17
  "test": "vitest run --reporter verbose",
18
18
  "test:single": "vitest run --reporter verbose tests/Runware/upscale-gan.test.ts",
19
- "debug": "tsx tests/script.ts"
19
+ "debug": "tsx tests/script.ts",
20
+ "beta:tag": "npm publish --tag beta"
20
21
  },
21
22
  "keywords": [
22
23
  "runware",
File without changes