@runware/sdk-js 1.1.20-beta.4 → 1.1.20
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.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -5
- package/dist/index.d.ts +58 -5
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +152 -11
package/dist/index.d.cts
CHANGED
|
@@ -16,7 +16,8 @@ declare enum ETaskType {
|
|
|
16
16
|
IMAGE_CONTROL_NET_PRE_PROCESS = "imageControlNetPreProcess",
|
|
17
17
|
PROMPT_ENHANCE = "promptEnhance",
|
|
18
18
|
AUTHENTICATION = "authentication",
|
|
19
|
-
MODEL_UPLOAD = "modelUpload"
|
|
19
|
+
MODEL_UPLOAD = "modelUpload",
|
|
20
|
+
PHOTO_MAKER = "photoMaker"
|
|
20
21
|
}
|
|
21
22
|
type RunwareBaseType = {
|
|
22
23
|
apiKey: string;
|
|
@@ -37,6 +38,7 @@ interface IImage {
|
|
|
37
38
|
imageDataURI?: string;
|
|
38
39
|
NSFWContent?: boolean;
|
|
39
40
|
cost?: number;
|
|
41
|
+
seed?: number;
|
|
40
42
|
}
|
|
41
43
|
interface ITextToImage extends IImage {
|
|
42
44
|
positivePrompt?: string;
|
|
@@ -119,6 +121,12 @@ interface IRequestImage {
|
|
|
119
121
|
customTaskUUID?: string;
|
|
120
122
|
onPartialImages?: (images: IImage[], error?: IError) => void;
|
|
121
123
|
retry?: number;
|
|
124
|
+
refiner?: IRefiner;
|
|
125
|
+
}
|
|
126
|
+
interface IRefiner {
|
|
127
|
+
model: string;
|
|
128
|
+
startStep?: number;
|
|
129
|
+
startStepPercentage?: number;
|
|
122
130
|
}
|
|
123
131
|
interface IRequestImageToText {
|
|
124
132
|
inputImage?: File | string;
|
|
@@ -264,6 +272,9 @@ interface IErrorResponse {
|
|
|
264
272
|
type: string;
|
|
265
273
|
documentation: string;
|
|
266
274
|
taskUUID: string;
|
|
275
|
+
min?: number;
|
|
276
|
+
max?: number;
|
|
277
|
+
default?: string | number;
|
|
267
278
|
}
|
|
268
279
|
type TAddModelBaseType = {
|
|
269
280
|
air: string;
|
|
@@ -288,12 +299,10 @@ type TAddModelControlNet = {
|
|
|
288
299
|
} & TAddModelBaseType;
|
|
289
300
|
type TAddModelCheckPoint = {
|
|
290
301
|
category: "checkpoint";
|
|
291
|
-
positiveTriggerWords?: string;
|
|
292
302
|
defaultCFGScale?: number;
|
|
293
303
|
defaultStrength: number;
|
|
294
304
|
defaultSteps?: number;
|
|
295
305
|
defaultScheduler?: number;
|
|
296
|
-
negativeTriggerWords?: string;
|
|
297
306
|
type?: EModelType;
|
|
298
307
|
} & TAddModelBaseType;
|
|
299
308
|
type TAddModelLora = {
|
|
@@ -302,6 +311,36 @@ type TAddModelLora = {
|
|
|
302
311
|
positiveTriggerWords?: string;
|
|
303
312
|
} & TAddModelBaseType;
|
|
304
313
|
type TAddModel = TAddModelCheckPoint | TAddModelControlNet | TAddModelLora;
|
|
314
|
+
type TPhotoMaker = {
|
|
315
|
+
model?: string;
|
|
316
|
+
inputImages: string[];
|
|
317
|
+
style: EPhotoMakerEnum;
|
|
318
|
+
strength?: number;
|
|
319
|
+
positivePrompt: string;
|
|
320
|
+
height: number;
|
|
321
|
+
width: number;
|
|
322
|
+
scheduler?: string;
|
|
323
|
+
steps?: number;
|
|
324
|
+
CFGScale?: number;
|
|
325
|
+
outputFormat?: string;
|
|
326
|
+
includeCost?: boolean;
|
|
327
|
+
numberResults: number;
|
|
328
|
+
seed?: number;
|
|
329
|
+
customTaskUUID?: string;
|
|
330
|
+
retry?: number;
|
|
331
|
+
onPartialImages?: (images: IImage[], error?: IError) => void;
|
|
332
|
+
};
|
|
333
|
+
type TPhotoMakerResponse = {
|
|
334
|
+
taskType: string;
|
|
335
|
+
taskUUID: string;
|
|
336
|
+
imageUUID: string;
|
|
337
|
+
NSFWContent: boolean;
|
|
338
|
+
cost: number;
|
|
339
|
+
seed: number;
|
|
340
|
+
imageURL: string;
|
|
341
|
+
positivePrompt: string;
|
|
342
|
+
negativePrompt?: string;
|
|
343
|
+
};
|
|
305
344
|
declare enum EModelFormat {
|
|
306
345
|
safetensors = "safetensors",
|
|
307
346
|
pickletensor = "pickletensor"
|
|
@@ -349,6 +388,19 @@ declare enum EModelConditioning {
|
|
|
349
388
|
gray = "gray",
|
|
350
389
|
lowquality = "low quality"
|
|
351
390
|
}
|
|
391
|
+
declare enum EPhotoMakerEnum {
|
|
392
|
+
NoStyle = "No style",
|
|
393
|
+
Cinematic = "Cinematic",
|
|
394
|
+
DisneyCharacter = "Disney Character",
|
|
395
|
+
DigitalArt = "Digital Art",
|
|
396
|
+
Photographic = "Photographic",
|
|
397
|
+
FantasyArt = "Fantasy art",
|
|
398
|
+
Neonpunk = "Neonpunk",
|
|
399
|
+
Enhance = "Enhance",
|
|
400
|
+
ComicBook = "Comic book",
|
|
401
|
+
Lowpoly = "Lowpoly",
|
|
402
|
+
LineArt = "Line art"
|
|
403
|
+
}
|
|
352
404
|
|
|
353
405
|
declare class RunwareBase {
|
|
354
406
|
_ws: ReconnectingWebsocketProps | any;
|
|
@@ -381,13 +433,14 @@ declare class RunwareBase {
|
|
|
381
433
|
private listenToImages;
|
|
382
434
|
private listenToUpload;
|
|
383
435
|
private globalListener;
|
|
384
|
-
requestImages({ outputType, outputFormat, uploadEndpoint, checkNsfw, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, numberResults, controlNet, lora, onPartialImages, includeCost, customTaskUUID, retry, }: IRequestImage): Promise<ITextToImage[] | undefined>;
|
|
436
|
+
requestImages({ outputType, outputFormat, uploadEndpoint, checkNsfw, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, numberResults, controlNet, lora, onPartialImages, includeCost, customTaskUUID, retry, refiner, }: IRequestImage): Promise<ITextToImage[] | undefined>;
|
|
385
437
|
controlNetPreProcess: ({ inputImage, preProcessorType, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, customTaskUUID, retry, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
386
438
|
requestImageToText: ({ inputImage, includeCost, customTaskUUID, retry, }: IRequestImageToText) => Promise<IImageToText>;
|
|
387
439
|
removeImageBackground: ({ inputImage, outputType, outputFormat, rgba, postProcessMask, returnOnlyMask, alphaMatting, alphaMattingForegroundThreshold, alphaMattingBackgroundThreshold, alphaMattingErodeSize, includeCost, customTaskUUID, retry, }: IRemoveImageBackground) => Promise<IRemoveImage>;
|
|
388
440
|
upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, customTaskUUID, retry, }: IUpscaleGan) => Promise<IImage>;
|
|
389
441
|
enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, customTaskUUID, retry, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
|
|
390
442
|
modelUpload: (payload: TAddModel) => Promise<any>;
|
|
443
|
+
photoMaker: (payload: TPhotoMaker) => Promise<TPhotoMakerResponse[] | undefined>;
|
|
391
444
|
ensureConnection(): Promise<unknown>;
|
|
392
445
|
private getSimilarImages;
|
|
393
446
|
private getSingleMessage;
|
|
@@ -416,4 +469,4 @@ declare class RunwareServer extends RunwareBase {
|
|
|
416
469
|
|
|
417
470
|
declare let Runware: typeof RunwareClient | typeof RunwareServer;
|
|
418
471
|
|
|
419
|
-
export { EControlMode, EModelArchitecture, EModelConditioning, EModelFormat, EModelType, EOpenPosePreProcessor, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, type GetWithPromiseCallBackType, type IAddModelResponse, type IControlNet, type IControlNetGeneral, type IControlNetImage, type IControlNetPreprocess, type IControlNetWithUUID, type IEnhancedPrompt, type IError, type IErrorResponse, type IImage, type IImageToText, type IOutputFormat, type IOutputType, type IPromptEnhancer, type IRemoveImage, type IRemoveImageBackground, type IRequestImage, type IRequestImageToText, type ITextToImage, type IUpscaleGan, type ListenerType, type ReconnectingWebsocketProps, type RequireAtLeastOne, type RequireOnlyOne, Runware, type RunwareBaseType, RunwareClient, RunwareServer, SdkType, type TAddModel, type TAddModelBaseType, type TAddModelCheckPoint, type TAddModelControlNet, type TAddModelLora, type UploadImageType };
|
|
472
|
+
export { EControlMode, EModelArchitecture, EModelConditioning, EModelFormat, EModelType, EOpenPosePreProcessor, EPhotoMakerEnum, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, type GetWithPromiseCallBackType, type IAddModelResponse, type IControlNet, type IControlNetGeneral, type IControlNetImage, type IControlNetPreprocess, type IControlNetWithUUID, type IEnhancedPrompt, type IError, type IErrorResponse, type IImage, type IImageToText, type IOutputFormat, type IOutputType, type IPromptEnhancer, type IRefiner, type IRemoveImage, type IRemoveImageBackground, type IRequestImage, type IRequestImageToText, type ITextToImage, type IUpscaleGan, type ListenerType, type ReconnectingWebsocketProps, type RequireAtLeastOne, type RequireOnlyOne, Runware, type RunwareBaseType, RunwareClient, RunwareServer, SdkType, type TAddModel, type TAddModelBaseType, type TAddModelCheckPoint, type TAddModelControlNet, type TAddModelLora, type TPhotoMaker, type TPhotoMakerResponse, type UploadImageType };
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,8 @@ declare enum ETaskType {
|
|
|
16
16
|
IMAGE_CONTROL_NET_PRE_PROCESS = "imageControlNetPreProcess",
|
|
17
17
|
PROMPT_ENHANCE = "promptEnhance",
|
|
18
18
|
AUTHENTICATION = "authentication",
|
|
19
|
-
MODEL_UPLOAD = "modelUpload"
|
|
19
|
+
MODEL_UPLOAD = "modelUpload",
|
|
20
|
+
PHOTO_MAKER = "photoMaker"
|
|
20
21
|
}
|
|
21
22
|
type RunwareBaseType = {
|
|
22
23
|
apiKey: string;
|
|
@@ -37,6 +38,7 @@ interface IImage {
|
|
|
37
38
|
imageDataURI?: string;
|
|
38
39
|
NSFWContent?: boolean;
|
|
39
40
|
cost?: number;
|
|
41
|
+
seed?: number;
|
|
40
42
|
}
|
|
41
43
|
interface ITextToImage extends IImage {
|
|
42
44
|
positivePrompt?: string;
|
|
@@ -119,6 +121,12 @@ interface IRequestImage {
|
|
|
119
121
|
customTaskUUID?: string;
|
|
120
122
|
onPartialImages?: (images: IImage[], error?: IError) => void;
|
|
121
123
|
retry?: number;
|
|
124
|
+
refiner?: IRefiner;
|
|
125
|
+
}
|
|
126
|
+
interface IRefiner {
|
|
127
|
+
model: string;
|
|
128
|
+
startStep?: number;
|
|
129
|
+
startStepPercentage?: number;
|
|
122
130
|
}
|
|
123
131
|
interface IRequestImageToText {
|
|
124
132
|
inputImage?: File | string;
|
|
@@ -264,6 +272,9 @@ interface IErrorResponse {
|
|
|
264
272
|
type: string;
|
|
265
273
|
documentation: string;
|
|
266
274
|
taskUUID: string;
|
|
275
|
+
min?: number;
|
|
276
|
+
max?: number;
|
|
277
|
+
default?: string | number;
|
|
267
278
|
}
|
|
268
279
|
type TAddModelBaseType = {
|
|
269
280
|
air: string;
|
|
@@ -288,12 +299,10 @@ type TAddModelControlNet = {
|
|
|
288
299
|
} & TAddModelBaseType;
|
|
289
300
|
type TAddModelCheckPoint = {
|
|
290
301
|
category: "checkpoint";
|
|
291
|
-
positiveTriggerWords?: string;
|
|
292
302
|
defaultCFGScale?: number;
|
|
293
303
|
defaultStrength: number;
|
|
294
304
|
defaultSteps?: number;
|
|
295
305
|
defaultScheduler?: number;
|
|
296
|
-
negativeTriggerWords?: string;
|
|
297
306
|
type?: EModelType;
|
|
298
307
|
} & TAddModelBaseType;
|
|
299
308
|
type TAddModelLora = {
|
|
@@ -302,6 +311,36 @@ type TAddModelLora = {
|
|
|
302
311
|
positiveTriggerWords?: string;
|
|
303
312
|
} & TAddModelBaseType;
|
|
304
313
|
type TAddModel = TAddModelCheckPoint | TAddModelControlNet | TAddModelLora;
|
|
314
|
+
type TPhotoMaker = {
|
|
315
|
+
model?: string;
|
|
316
|
+
inputImages: string[];
|
|
317
|
+
style: EPhotoMakerEnum;
|
|
318
|
+
strength?: number;
|
|
319
|
+
positivePrompt: string;
|
|
320
|
+
height: number;
|
|
321
|
+
width: number;
|
|
322
|
+
scheduler?: string;
|
|
323
|
+
steps?: number;
|
|
324
|
+
CFGScale?: number;
|
|
325
|
+
outputFormat?: string;
|
|
326
|
+
includeCost?: boolean;
|
|
327
|
+
numberResults: number;
|
|
328
|
+
seed?: number;
|
|
329
|
+
customTaskUUID?: string;
|
|
330
|
+
retry?: number;
|
|
331
|
+
onPartialImages?: (images: IImage[], error?: IError) => void;
|
|
332
|
+
};
|
|
333
|
+
type TPhotoMakerResponse = {
|
|
334
|
+
taskType: string;
|
|
335
|
+
taskUUID: string;
|
|
336
|
+
imageUUID: string;
|
|
337
|
+
NSFWContent: boolean;
|
|
338
|
+
cost: number;
|
|
339
|
+
seed: number;
|
|
340
|
+
imageURL: string;
|
|
341
|
+
positivePrompt: string;
|
|
342
|
+
negativePrompt?: string;
|
|
343
|
+
};
|
|
305
344
|
declare enum EModelFormat {
|
|
306
345
|
safetensors = "safetensors",
|
|
307
346
|
pickletensor = "pickletensor"
|
|
@@ -349,6 +388,19 @@ declare enum EModelConditioning {
|
|
|
349
388
|
gray = "gray",
|
|
350
389
|
lowquality = "low quality"
|
|
351
390
|
}
|
|
391
|
+
declare enum EPhotoMakerEnum {
|
|
392
|
+
NoStyle = "No style",
|
|
393
|
+
Cinematic = "Cinematic",
|
|
394
|
+
DisneyCharacter = "Disney Character",
|
|
395
|
+
DigitalArt = "Digital Art",
|
|
396
|
+
Photographic = "Photographic",
|
|
397
|
+
FantasyArt = "Fantasy art",
|
|
398
|
+
Neonpunk = "Neonpunk",
|
|
399
|
+
Enhance = "Enhance",
|
|
400
|
+
ComicBook = "Comic book",
|
|
401
|
+
Lowpoly = "Lowpoly",
|
|
402
|
+
LineArt = "Line art"
|
|
403
|
+
}
|
|
352
404
|
|
|
353
405
|
declare class RunwareBase {
|
|
354
406
|
_ws: ReconnectingWebsocketProps | any;
|
|
@@ -381,13 +433,14 @@ declare class RunwareBase {
|
|
|
381
433
|
private listenToImages;
|
|
382
434
|
private listenToUpload;
|
|
383
435
|
private globalListener;
|
|
384
|
-
requestImages({ outputType, outputFormat, uploadEndpoint, checkNsfw, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, numberResults, controlNet, lora, onPartialImages, includeCost, customTaskUUID, retry, }: IRequestImage): Promise<ITextToImage[] | undefined>;
|
|
436
|
+
requestImages({ outputType, outputFormat, uploadEndpoint, checkNsfw, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, numberResults, controlNet, lora, onPartialImages, includeCost, customTaskUUID, retry, refiner, }: IRequestImage): Promise<ITextToImage[] | undefined>;
|
|
385
437
|
controlNetPreProcess: ({ inputImage, preProcessorType, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, customTaskUUID, retry, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
386
438
|
requestImageToText: ({ inputImage, includeCost, customTaskUUID, retry, }: IRequestImageToText) => Promise<IImageToText>;
|
|
387
439
|
removeImageBackground: ({ inputImage, outputType, outputFormat, rgba, postProcessMask, returnOnlyMask, alphaMatting, alphaMattingForegroundThreshold, alphaMattingBackgroundThreshold, alphaMattingErodeSize, includeCost, customTaskUUID, retry, }: IRemoveImageBackground) => Promise<IRemoveImage>;
|
|
388
440
|
upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, customTaskUUID, retry, }: IUpscaleGan) => Promise<IImage>;
|
|
389
441
|
enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, customTaskUUID, retry, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
|
|
390
442
|
modelUpload: (payload: TAddModel) => Promise<any>;
|
|
443
|
+
photoMaker: (payload: TPhotoMaker) => Promise<TPhotoMakerResponse[] | undefined>;
|
|
391
444
|
ensureConnection(): Promise<unknown>;
|
|
392
445
|
private getSimilarImages;
|
|
393
446
|
private getSingleMessage;
|
|
@@ -416,4 +469,4 @@ declare class RunwareServer extends RunwareBase {
|
|
|
416
469
|
|
|
417
470
|
declare let Runware: typeof RunwareClient | typeof RunwareServer;
|
|
418
471
|
|
|
419
|
-
export { EControlMode, EModelArchitecture, EModelConditioning, EModelFormat, EModelType, EOpenPosePreProcessor, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, type GetWithPromiseCallBackType, type IAddModelResponse, type IControlNet, type IControlNetGeneral, type IControlNetImage, type IControlNetPreprocess, type IControlNetWithUUID, type IEnhancedPrompt, type IError, type IErrorResponse, type IImage, type IImageToText, type IOutputFormat, type IOutputType, type IPromptEnhancer, type IRemoveImage, type IRemoveImageBackground, type IRequestImage, type IRequestImageToText, type ITextToImage, type IUpscaleGan, type ListenerType, type ReconnectingWebsocketProps, type RequireAtLeastOne, type RequireOnlyOne, Runware, type RunwareBaseType, RunwareClient, RunwareServer, SdkType, type TAddModel, type TAddModelBaseType, type TAddModelCheckPoint, type TAddModelControlNet, type TAddModelLora, type UploadImageType };
|
|
472
|
+
export { EControlMode, EModelArchitecture, EModelConditioning, EModelFormat, EModelType, EOpenPosePreProcessor, EPhotoMakerEnum, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, type GetWithPromiseCallBackType, type IAddModelResponse, type IControlNet, type IControlNetGeneral, type IControlNetImage, type IControlNetPreprocess, type IControlNetWithUUID, type IEnhancedPrompt, type IError, type IErrorResponse, type IImage, type IImageToText, type IOutputFormat, type IOutputType, type IPromptEnhancer, type IRefiner, type IRemoveImage, type IRemoveImageBackground, type IRequestImage, type IRequestImageToText, type ITextToImage, type IUpscaleGan, type ListenerType, type ReconnectingWebsocketProps, type RequireAtLeastOne, type RequireOnlyOne, Runware, type RunwareBaseType, RunwareClient, RunwareServer, SdkType, type TAddModel, type TAddModelBaseType, type TAddModelCheckPoint, type TAddModelControlNet, type TAddModelLora, type TPhotoMaker, type TPhotoMakerResponse, type UploadImageType };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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};
|
|
1
|
+
var Ue=Object.create;var Q=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var xe=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty;var ve=(c,t)=>()=>(t||c((t={exports:{}}).exports,t),t.exports);var we=(c,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Re(t))!De.call(c,s)&&s!==e&&Q(c,s,{get:()=>t[s],enumerable:!(n=ke(t,s))||n.enumerable});return c};var Se=(c,t,e)=>(e=c!=null?Ue(xe(c)):{},we(t||!c||!c.__esModule?Q(e,"default",{value:c,enumerable:!0}):e,c));var ue=ve((Ct,ce)=>{"use strict";var ie=c=>c&&c.CLOSING===2,Fe=()=>typeof WebSocket<"u"&&ie(WebSocket),Pe=()=>({constructor:Fe()?WebSocket:null,maxReconnectionDelay:1e4,minReconnectionDelay:1500,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,debug:!1}),Be=(c,t,e)=>{Object.defineProperty(t,e,{get:()=>c[e],set:n=>{c[e]=n},enumerable:!0,configurable:!0})},oe=c=>c.minReconnectionDelay+Math.random()*c.minReconnectionDelay,Ge=(c,t)=>{let e=t*c.reconnectionDelayGrowFactor;return e>c.maxReconnectionDelay?c.maxReconnectionDelay:e},qe=["onopen","onclose","onmessage","onerror"],He=(c,t,e)=>{Object.keys(e).forEach(n=>{e[n].forEach(([s,r])=>{c.addEventListener(n,s,r)})}),t&&qe.forEach(n=>{c[n]=t[n]})},le=function(c,t,e={}){let n,s,r=0,i=0,l=!0,a={};if(!(this instanceof le))throw new TypeError("Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator");let u=Pe();if(Object.keys(u).filter(g=>e.hasOwnProperty(g)).forEach(g=>u[g]=e[g]),!ie(u.constructor))throw new TypeError("Invalid WebSocket constructor. Set `options.constructor`");let o=u.debug?(...g)=>console.log("RWS:",...g):()=>{},p=(g,y)=>setTimeout(()=>{let _=new Error(y);_.code=g,Array.isArray(a.error)&&a.error.forEach(([b])=>b(_)),n.onerror&&n.onerror(_)},0),d=()=>{if(o("close"),i++,o("retries count:",i),i>u.maxRetries){p("EHOSTDOWN","Too many failed connection attempts");return}r?r=Ge(u,r):r=oe(u),o("reconnectDelay:",r),l&&setTimeout(m,r)},m=()=>{o("connect");let g=n;n=new u.constructor(c,t),s=setTimeout(()=>{o("timeout"),n.close(),p("ETIMEDOUT","Connection timeout")},u.connectionTimeout),o("bypass properties");for(let y in n)["addEventListener","removeEventListener","close","send"].indexOf(y)<0&&Be(n,this,y);n.addEventListener("open",()=>{clearTimeout(s),o("open"),r=oe(u),o("reconnectDelay:",r),i=0}),n.addEventListener("close",d),He(n,g,a)};o("init"),m(),this.close=(g=1e3,y="",{keepClosed:_=!1,fastClose:b=!0,delay:D=0}={})=>{if(D&&(r=D),l=!_,n.close(g,y),b){let x={code:g,reason:y,wasClean:!0};d(),Array.isArray(a.close)&&a.close.forEach(([T,h])=>{T(x),n.removeEventListener("close",T,h)}),n.onclose&&(n.onclose(x),n.onclose=null)}},this.send=g=>{n.send(g)},this.addEventListener=(g,y,_)=>{Array.isArray(a[g])?a[g].some(([b])=>b===y)||a[g].push([y,_]):a[g]=[[y,_]],n.addEventListener(g,y,_)},this.removeEventListener=(g,y,_)=>{Array.isArray(a[g])&&(a[g]=a[g].filter(([b])=>b!==y)),n.removeEventListener(g,y,_)}};ce.exports=le});var z=(n=>(n.PRODUCTION="PRODUCTION",n.DEVELOPMENT="DEVELOPMENT",n.TEST="TEST",n))(z||{}),P=(e=>(e.CLIENT="CLIENT",e.SERVER="SERVER",e))(P||{}),B=(o=>(o.IMAGE_INFERENCE="imageInference",o.IMAGE_UPLOAD="imageUpload",o.IMAGE_UPSCALE="imageUpscale",o.IMAGE_BACKGROUND_REMOVAL="imageBackgroundRemoval",o.IMAGE_CAPTION="imageCaption",o.IMAGE_CONTROL_NET_PRE_PROCESS="imageControlNetPreProcess",o.PROMPT_ENHANCE="promptEnhance",o.AUTHENTICATION="authentication",o.MODEL_UPLOAD="modelUpload",o.PHOTO_MAKER="photoMaker",o))(B||{}),Y=(n=>(n.BALANCED="balanced",n.PROMPT="prompt",n.CONTROL_NET="controlnet",n))(Y||{}),Z=(d=>(d.canny="canny",d.depth="depth",d.mlsd="mlsd",d.normalbae="normalbae",d.openpose="openpose",d.tile="tile",d.seg="seg",d.lineart="lineart",d.lineart_anime="lineart_anime",d.shuffle="shuffle",d.scribble="scribble",d.softedge="softedge",d))(Z||{}),$=(I=>(I.canny="canny",I.depth_leres="depth_leres",I.depth_midas="depth_midas",I.depth_zoe="depth_zoe",I.inpaint_global_harmonious="inpaint_global_harmonious",I.lineart_anime="lineart_anime",I.lineart_coarse="lineart_coarse",I.lineart_realistic="lineart_realistic",I.lineart_standard="lineart_standard",I.mlsd="mlsd",I.normal_bae="normal_bae",I.scribble_hed="scribble_hed",I.scribble_pidinet="scribble_pidinet",I.seg_ofade20k="seg_ofade20k",I.seg_ofcoco="seg_ofcoco",I.seg_ufade20k="seg_ufade20k",I.shuffle="shuffle",I.softedge_hed="softedge_hed",I.softedge_hedsafe="softedge_hedsafe",I.softedge_pidinet="softedge_pidinet",I.softedge_pidisafe="softedge_pidisafe",I.tile_gaussian="tile_gaussian",I.openpose="openpose",I.openpose_face="openpose_face",I.openpose_faceonly="openpose_faceonly",I.openpose_full="openpose_full",I.openpose_hand="openpose_hand",I))($||{}),Ae=(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))(Ae||{}),Ce=(e=>(e.safetensors="safetensors",e.pickletensor="pickletensor",e))(Ce||{}),Oe=(m=>(m.flux1d="flux1d",m.flux1s="flux1s",m.pony="pony",m.sdhyper="sdhyper",m.sd1x="sd1x",m.sd1xlcm="sd1xlcm",m.sd3="sd3",m.sdxl="sdxl",m.sdxllcm="sdxllcm",m.sdxldistilled="sdxldistilled",m.sdxlhyper="sdxlhyper",m.sdxllightning="sdxllightning",m.sdxlturbo="sdxlturbo",m))(Oe||{}),Ne=(n=>(n.base="base",n.inpainting="inpainting",n.pix2pix="pix2pix",n))(Ne||{}),Le=(h=>(h.canny="canny",h.depth="depth",h.qrcode="qrcode",h.hed="hed",h.scrible="scrible",h.openpose="openpose",h.seg="segmentation",h.openmlsd="openmlsd",h.softedge="softedge",h.normal="normal bae",h.shuffle="shuffle",h.pix2pix="pix2pix",h.inpaint="inpaint",h.lineart="line art",h.sketch="sketch",h.inpaintdepth="inpaint depth",h.tile="tile",h.outfit="outfit",h.blur="blur",h.gray="gray",h.lowquality="low quality",h))(Le||{}),Ee=(p=>(p.NoStyle="No style",p.Cinematic="Cinematic",p.DisneyCharacter="Disney Character",p.DigitalArt="Digital Art",p.Photographic="Photographic",p.FantasyArt="Fantasy art",p.Neonpunk="Neonpunk",p.Enhance="Enhance",p.ComicBook="Comic book",p.Lowpoly="Lowpoly",p.LineArt="Line art",p))(Ee||{});import{v4 as Me,validate as Ke}from"uuid";var G=6e4,X=1e3,We=100,q={PRODUCTION:"wss://ws-api.runware.ai/v1",TEST:"ws://localhost:8080"},ee=(c,t)=>{if(c==null)return;let e=c.indexOf(t);e!==-1&&c.splice(e,1)},v=(c,{debugKey:t="debugKey",timeoutDuration:e=G,shouldThrowError:n=!0})=>(e=e<X?X:e,new Promise((s,r)=>{let i=setTimeout(()=>{l&&(clearInterval(l),n&&r(`Response could not be received from server for ${t}`)),clearTimeout(i)},e),l=setInterval(async()=>{c({resolve:s,reject:r,intervalId:l})&&(clearInterval(l),clearTimeout(i))},We)})),te=c=>new Promise(t=>{let e=new FileReader;e.readAsDataURL(c),e.onload=function(){t(e.result)}}),k=()=>Me(),ne=c=>Ke(c);var se=({key:c,data:t,useZero:e=!0,shouldReturnString:n=!1})=>c.split(/\.|\[/).map(i=>i.replace(/\]$/,"")).reduce((i,l)=>{let a=e?0:void 0,u=i?.[l];if(!u)return a;if(Array.isArray(u)&&/^\d+$/.test(l)){let o=parseInt(l,10);return o>=0&&o<u.length?i[l]=u[o]:i[l]??a}else return i[l]??a},t||{})??{},re=(c,t=1e3)=>new Promise(e=>setTimeout(e,c*t));var ae=(c,t)=>c.filter(e=>e.key!==t.key);var f=({key:c,value:t})=>t||t===0||t===!1?{[c]:t}:{};var R=async(c,t={})=>{let{delayInSeconds:e=1,callback:n}=t,s=t.maxRetries??1;for(;s;)try{return await c()}catch(r){if(n?.(),s--,s>0)await re(e),await R(c,{...t,maxRetries:s});else throw r}};var S=class{constructor({apiKey:t,url:e=q.PRODUCTION,shouldReconnect:n=!0,globalMaxRetries:s=2,timeoutDuration:r=G}){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 R(async()=>{let e=k();if(typeof t=="string"&&ne(t))return{imageURL:t,imageUUID:t,taskUUID:e,taskType:"imageUpload"};let n=typeof t=="string"?t:await te(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:i,highThresholdCanny:l,lowThresholdCanny:a,includeHandsAndFaceOpenPose:u,includeCost:o,customTaskUUID:p,retry:d})=>{let m=d||this._globalMaxRetries,g;try{return await R(async()=>{await this.ensureConnection();let y=await this.uploadImage(t);if(!y?.imageUUID)return null;let _=p||k();this.send({inputImage:y.imageUUID,taskType:"imageControlNetPreProcess",taskUUID:_,preProcessorType:e,...f({key:"height",value:n}),...f({key:"width",value:s}),...f({key:"outputType",value:r}),...f({key:"outputFormat",value:i}),...f({key:"includeCost",value:o}),...f({key:"highThresholdCanny",value:l}),...f({key:"lowThresholdCanny",value:a}),...f({key:"includeHandsAndFaceOpenPose",value:u})}),g=this.globalListener({taskUUID:_});let b=await v(({resolve:D,reject:x})=>{let T=this.getSingleMessage({taskUUID:_});if(T){if(T?.error)return x(T),!0;if(T)return D(T),!0}},{debugKey:"unprocessed-image",timeoutDuration:this._timeoutDuration});return g.destroy(),b},{maxRetries:m,callback:()=>{g?.destroy()}})}catch(y){throw y}};this.requestImageToText=async({inputImage:t,includeCost:e,customTaskUUID:n,retry:s})=>{let r=s||this._globalMaxRetries,i;try{return await R(async()=>{await this.ensureConnection();let l=t?await this.uploadImage(t):null,a=n||k();this.send({taskUUID:a,taskType:"imageCaption",inputImage:l?.imageUUID,...f({key:"includeCost",value:e})}),i=this.globalListener({taskUUID:a});let u=await v(({resolve:o,reject:p})=>{let d=this.getSingleMessage({taskUUID:a});if(d){if(d?.error)return p(d),!0;if(d)return delete this._globalMessages[a],o(d),!0}},{debugKey:"remove-image-background",timeoutDuration:this._timeoutDuration});return i.destroy(),u},{maxRetries:r,callback:()=>{i?.destroy()}})}catch(l){throw l}};this.removeImageBackground=async({inputImage:t,outputType:e,outputFormat:n,rgba:s,postProcessMask:r,returnOnlyMask:i,alphaMatting:l,alphaMattingForegroundThreshold:a,alphaMattingBackgroundThreshold:u,alphaMattingErodeSize:o,includeCost:p,customTaskUUID:d,retry:m})=>{let g=m||this._globalMaxRetries,y;try{return await R(async()=>{await this.ensureConnection();let _=t?await this.uploadImage(t):null,b=d||k();this.send({taskType:"imageBackgroundRemoval",taskUUID:b,inputImage:_?.imageUUID,...f({key:"rgba",value:s}),...f({key:"postProcessMask",value:r}),...f({key:"returnOnlyMask",value:i}),...f({key:"alphaMatting",value:l}),...f({key:"includeCost",value:p}),...f({key:"alphaMattingForegroundThreshold",value:a}),...f({key:"alphaMattingBackgroundThreshold",value:u}),...f({key:"alphaMattingErodeSize",value:o}),...f({key:"outputType",value:e}),...f({key:"outputFormat",value:n})}),y=this.globalListener({taskUUID:b});let D=await v(({resolve:x,reject:T})=>{let h=this.getSingleMessage({taskUUID:b});if(h){if(h?.error)return T(h),!0;if(h)return delete this._globalMessages[b],x(h),!0}},{debugKey:"remove-image-background",timeoutDuration:this._timeoutDuration});return y.destroy(),D},{maxRetries:g,callback:()=>{y?.destroy()}})}catch(_){throw _}};this.upscaleGan=async({inputImage:t,upscaleFactor:e,outputType:n,outputFormat:s,includeCost:r,customTaskUUID:i,retry:l})=>{let a=l||this._globalMaxRetries,u;try{return await R(async()=>{await this.ensureConnection();let o;o=await this.uploadImage(t);let p=i||k();this.send({taskUUID:p,inputImage:o?.imageUUID,taskType:"imageUpscale",upscaleFactor:e,...f({key:"includeCost",value:r}),...n?{outputType:n}:{},...s?{outputFormat:s}:{}}),u=this.globalListener({taskUUID:p});let d=await v(({resolve:m,reject:g})=>{let y=this.getSingleMessage({taskUUID:p});if(y){if(y?.error)return g(y),!0;if(y)return delete this._globalMessages[p],m(y),!0}},{debugKey:"upscale-gan",timeoutDuration:this._timeoutDuration});return u.destroy(),d},{maxRetries:a,callback:()=>{u?.destroy()}})}catch(o){throw o}};this.enhancePrompt=async({prompt:t,promptMaxLength:e=380,promptVersions:n=1,includeCost:s,customTaskUUID:r,retry:i})=>{let l=i||this._globalMaxRetries,a;try{return await R(async()=>{await this.ensureConnection();let u=r||k();this.send({prompt:t,taskUUID:u,promptMaxLength:e,promptVersions:n,...f({key:"includeCost",value:s}),taskType:"promptEnhance"}),a=this.globalListener({taskUUID:u});let o=await v(({resolve:p,reject:d})=>{let m=this._globalMessages[u];if(m?.error)return d(m),!0;if(m?.length>=n)return delete this._globalMessages[u],p(m),!0},{debugKey:"enhance-prompt",timeoutDuration:this._timeoutDuration});return a.destroy(),o},{maxRetries:l,callback:()=>{a?.destroy()}})}catch(u){throw u}};this.modelUpload=async t=>{let{onUploadStream:e,retry:n,customTaskUUID:s,...r}=t,i=n||this._globalMaxRetries,l;try{return await R(async()=>{await this.ensureConnection();let a=s||k();this.send({...r,taskUUID:a,taskType:"modelUpload"});let u,o;return l=this.listenToUpload({taskUUID:a,onUploadStream:(d,m)=>{e?.(d,m),d?.status==="ready"?u=d:m&&(o=m)}}),await v(({resolve:d,reject:m})=>{if(u)return d(u),!0;if(o)return m(o),!1},{shouldThrowError:!1,timeoutDuration:60*60*1e3})},{maxRetries:i,callback:()=>{l?.destroy()}})}catch(a){throw a}};this.photoMaker=async t=>{let{onPartialImages:e,retry:n,customTaskUUID:s,numberResults:r,...i}=t,l=n||this._globalMaxRetries,a,u=[],o=0;try{return await R(async()=>{await this.ensureConnection(),o++;let p=this._globalImages.filter(y=>u.includes(y.taskUUID)),d=s||k();u.push(d);let m=r-p.length;this.send({...i,numberResults:m,taskUUID:d,taskType:"photoMaker"}),a=this.listenToImages({onPartialImages:e,taskUUID:d,groupKey:"REQUEST_IMAGES",positivePrompt:i.positivePrompt});let g=await this.getSimilarImages({taskUUID:u,numberResults:r,lis:a});return a.destroy(),g},{maxRetries:l,callback:()=>{a?.destroy()}})}catch(p){if(p.taskUUID)throw p;if(o>=l)return this.handleIncompleteImages({taskUUIDs:u,error:p})}};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=l=>{let a=Array.isArray(l?.data)?l.data:[l.data],u=l?.[0]?.errors?l?.[0]?.errors:Array.isArray(l?.errors)?l.errors:[l.errors],o=a.filter(d=>(d?.taskUUID||d?.taskType)===n);if(u.filter(d=>(d?.taskUUID||d?.taskType)===n).length){t({error:{...u[0]??{}}});return}if(o.length){t({[n]:a});return}},r={key:n||k(),listener:s,groupKey:e};return this._listeners.push(r),{destroy:()=>{this._listeners=ae(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){ee(this._listeners,t)}listenToImages({onPartialImages:t,taskUUID:e,groupKey:n,positivePrompt:s,negativePrompt:r}){return this.addListener({taskUUID:e,lis:i=>{let l=i?.[e]?.filter(a=>a.taskUUID===e);i.error?(t?.(l,i?.error&&i),this._globalError=i):(l=l.map(a=>({...a,positivePrompt:s,negativePrompt:r})),t?.(l,i?.error&&i),this._sdkType==="CLIENT"?this._globalImages=[...this._globalImages,...(i?.[e]??[]).map(a=>({...a,positivePrompt:s,negativePrompt:r}))]:this._globalImages=[...this._globalImages,...l])},groupKey:n})}listenToUpload({onUploadStream:t,taskUUID:e}){return this.addListener({taskUUID:e,lis:n=>{let s=n?.error,r=n?.[e]?.[0],i=r?.taskUUID===e?r:null;(i||s)&&t?.(i||void 0,s)}})}globalListener({taskUUID:t}){return this.addListener({taskUUID:t,lis:e=>{if(e.error){this._globalMessages[t]=e;return}let n=se({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:i,seedImage:l,maskImage:a,strength:u,height:o,width:p,model:d,steps:m,scheduler:g,seed:y,CFGScale:_,clipSkip:b,usePromptWeighting:D,numberResults:x=1,controlNet:T,lora:h,onPartialImages:ge,includeCost:me,customTaskUUID:ye,retry:Ie,refiner:H}){let I,V,C=[],j=0,J=Ie||this._globalMaxRetries;try{await this.ensureConnection();let w=null,E=null,M=[];if(l){let U=await this.uploadImage(l);if(!U)return[];w=U.imageUUID}if(a){let U=await this.uploadImage(a);if(!U)return[];E=U.imageUUID}if(T?.length)for(let U=0;U<T.length;U++){let A=T[U],{endStep:K,startStep:W,weight:F,guideImage:O,controlMode:he,startStepPercentage:fe,endStepPercentage:_e,model:be}=A,Te=O?await this.uploadImage(O):null;M.push({guideImage:Te?.imageUUID,model:be,endStep:K,startStep:W,weight:F,...f({key:"startStepPercentage",value:fe}),...f({key:"endStepPercentage",value:_e}),controlMode:he||"controlnet"})}return V={taskType:"imageInference",model:d,positivePrompt:r,...i?{negativePrompt:i}:{},...o?{height:o}:{},...p?{width:p}:{},numberResults:x,...h?.length?{lora:h}:{},...t?{outputType:t}:{},...e?{outputFormat:e}:{},...n?{uploadEndpoint:n}:{},...f({key:"checkNsfw",value:s}),...f({key:"strength",value:u}),...f({key:"CFGScale",value:_}),...f({key:"clipSkip",value:b}),...f({key:"usePromptWeighting",value:D}),...f({key:"steps",value:m}),...M.length?{controlNet:M}:{},...y?{seed:y}:{},...g?{scheduler:g}:{},...H?{refiner:H}:{},...f({key:"includeCost",value:me}),...w?{seedImage:w}:{},...E?{maskImage:E}:{}},await R(async()=>{j++,I?.destroy();let U=this._globalImages.filter(O=>C.includes(O.taskUUID)),A=ye||k();C.push(A);let K=x-U.length,W={...V,taskUUID:A,numberResults:K};this.send(W),I=this.listenToImages({onPartialImages:ge,taskUUID:A,groupKey:"REQUEST_IMAGES",positivePrompt:r,negativePrompt:i});let F=await this.getSimilarImages({taskUUID:C,numberResults:x,lis:I});return I.destroy(),F},{maxRetries:J,callback:()=>{I?.destroy()}})}catch(w){if(w.taskUUID)throw w;if(j>=J)return this.handleIncompleteImages({taskUUIDs:C,error:w})}}async ensureConnection(){if(this.connected()||this._url===q.TEST)return;let e=2e3,n=200;try{if(this._invalidAPIkey)throw this._invalidAPIkey;return new Promise((s,r)=>{let i=0,l=30,a=i%10===0,u,o,p=()=>{clearInterval(u),clearInterval(o)};this._sdkType==="SERVER"&&(u=setInterval(async()=>{try{this.connected()?(p(),s(!0)):i>=l?(p(),r(new Error("Retry timed out"))):(a&&this.connect(),i++)}catch(d){p(),r(d)}},e)),o=setInterval(async()=>{if(this.connected()){p(),s(!0);return}if(this._invalidAPIkey){p(),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:i,intervalId:l})=>{let a=Array.isArray(t)?t:[t],u=this._globalImages.filter(o=>a.includes(o.taskUUID));if(this._globalError){let o=this._globalError;return this._globalError=void 0,clearInterval(l),i?.(o),!0}else if(u.length>=e)return clearInterval(l),this._globalImages=this._globalImages.filter(o=>!a.includes(o.taskUUID)),r([...u].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 de=Se(ue(),1),N=class extends S{constructor(t){let{shouldReconnect:e,...n}=t;super(n),this._ws=new de.default(this._url),this.connect()}};import Ve 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=>{let n;(n=e?.destroy)==null||n.call(e)}),this._ws.removeAllListeners(),this._ws.readyState===1&&(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 Ve(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(i=>{i.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 pe;typeof window>"u"?pe=L:pe=N;export{Y as EControlMode,Oe as EModelArchitecture,Le as EModelConditioning,Ce as EModelFormat,Ne as EModelType,Ae as EOpenPosePreProcessor,Ee as EPhotoMakerEnum,$ as EPreProcessor,Z as EPreProcessorGroup,B as ETaskType,z as Environment,pe as Runware,N as RunwareClient,L as RunwareServer,P as SdkType};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|