@runware/sdk-js 1.1.48 → 1.1.50
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 +69 -8
- package/dist/index.d.ts +69 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +16 -6
- package/dist/esm/Runware/Runware-base.d.ts +0 -70
- package/dist/esm/Runware/Runware-base.js +0 -1002
- package/dist/esm/Runware/Runware-client.d.ts +0 -5
- package/dist/esm/Runware/Runware-client.js +0 -28
- package/dist/esm/Runware/Runware-server.d.ts +0 -15
- package/dist/esm/Runware/Runware-server.js +0 -145
- package/dist/esm/Runware/Runware.d.ts +0 -4
- package/dist/esm/Runware/Runware.js +0 -13
- package/dist/esm/Runware/async-retry.d.ts +0 -5
- package/dist/esm/Runware/async-retry.js +0 -30
- package/dist/esm/Runware/index.d.ts +0 -4
- package/dist/esm/Runware/index.js +0 -20
- package/dist/esm/Runware/reconnect.d.ts +0 -11
- package/dist/esm/Runware/reconnect.js +0 -175
- package/dist/esm/Runware/types.d.ts +0 -644
- package/dist/esm/Runware/types.js +0 -156
- package/dist/esm/Runware/utils.d.ts +0 -57
- package/dist/esm/Runware/utils.js +0 -262
- package/dist/esm/tests/Runware/enhance-prompt.test.d.ts +0 -1
- package/dist/esm/tests/Runware/enhance-prompt.test.js +0 -58
- package/dist/esm/tests/Runware/remove-image-background.test.d.ts +0 -1
- package/dist/esm/tests/Runware/remove-image-background.test.js +0 -37
- package/dist/esm/tests/Runware/request-image-to-text.test.d.ts +0 -1
- package/dist/esm/tests/Runware/request-image-to-text.test.js +0 -37
- package/dist/esm/tests/Runware/request-images.test.d.ts +0 -1
- package/dist/esm/tests/Runware/request-images.test.js +0 -84
- package/dist/esm/tests/Runware/runware-server.test.d.ts +0 -1
- package/dist/esm/tests/Runware/runware-server.test.js +0 -26
- package/dist/esm/tests/Runware/upload-image.test.d.ts +0 -1
- package/dist/esm/tests/Runware/upload-image.test.js +0 -28
- package/dist/esm/tests/Runware/upscale-gan.test.d.ts +0 -1
- package/dist/esm/tests/Runware/upscale-gan.test.js +0 -41
- package/dist/esm/tests/mockServer.d.ts +0 -12
- package/dist/esm/tests/mockServer.js +0 -38
- package/dist/esm/tests/script.d.ts +0 -8
- package/dist/esm/tests/script.js +0 -570
- package/dist/esm/tests/test-utils.d.ts +0 -40
- package/dist/esm/tests/test-utils.js +0 -45
package/dist/index.d.cts
CHANGED
|
@@ -21,7 +21,9 @@ declare enum ETaskType {
|
|
|
21
21
|
PROMPT_ENHANCE = "promptEnhance",
|
|
22
22
|
AUTHENTICATION = "authentication",
|
|
23
23
|
MODEL_UPLOAD = "modelUpload",
|
|
24
|
-
MODEL_SEARCH = "modelSearch"
|
|
24
|
+
MODEL_SEARCH = "modelSearch",
|
|
25
|
+
MEDIA_STORAGE = "mediaStorage",
|
|
26
|
+
VECTORIZE = "vectorize"
|
|
25
27
|
}
|
|
26
28
|
type RunwareBaseType = {
|
|
27
29
|
apiKey: string;
|
|
@@ -103,6 +105,7 @@ type IControlNetPreprocess = {
|
|
|
103
105
|
includeCost?: boolean;
|
|
104
106
|
outputQuality?: number;
|
|
105
107
|
customTaskUUID?: string;
|
|
108
|
+
taskUUID?: string;
|
|
106
109
|
retry?: number;
|
|
107
110
|
} & IAdditionalResponsePayload;
|
|
108
111
|
type IControlNet = IControlNetGeneral;
|
|
@@ -201,6 +204,7 @@ interface IRequestImageToText extends IAdditionalResponsePayload {
|
|
|
201
204
|
inputImage?: File | string;
|
|
202
205
|
includeCost?: boolean;
|
|
203
206
|
customTaskUUID?: string;
|
|
207
|
+
taskUUID?: string;
|
|
204
208
|
retry?: number;
|
|
205
209
|
}
|
|
206
210
|
interface IImageToText {
|
|
@@ -226,6 +230,7 @@ interface IRemoveImageBackground extends IRequestImageToText {
|
|
|
226
230
|
outputQuality?: number;
|
|
227
231
|
retry?: number;
|
|
228
232
|
}
|
|
233
|
+
type InputsValue = string | Record<string, unknown>;
|
|
229
234
|
interface IRequestVideo extends IRequestImageToText {
|
|
230
235
|
outputType?: IOutputType;
|
|
231
236
|
outputFormat?: IVideoOutputFormat;
|
|
@@ -233,7 +238,7 @@ interface IRequestVideo extends IRequestImageToText {
|
|
|
233
238
|
uploadEndpoint?: string;
|
|
234
239
|
checkNSFW?: boolean;
|
|
235
240
|
includeCost?: boolean;
|
|
236
|
-
positivePrompt
|
|
241
|
+
positivePrompt?: string;
|
|
237
242
|
negativePrompt?: string;
|
|
238
243
|
model: string;
|
|
239
244
|
steps?: number;
|
|
@@ -245,6 +250,22 @@ interface IRequestVideo extends IRequestImageToText {
|
|
|
245
250
|
height?: number;
|
|
246
251
|
numberResults?: number;
|
|
247
252
|
inputAudios?: string[];
|
|
253
|
+
referenceVideos?: string[];
|
|
254
|
+
inputs?: {
|
|
255
|
+
image?: InputsValue;
|
|
256
|
+
images?: InputsValue[];
|
|
257
|
+
audio?: InputsValue;
|
|
258
|
+
audios?: InputsValue[];
|
|
259
|
+
mask?: InputsValue[];
|
|
260
|
+
reference?: InputsValue;
|
|
261
|
+
references?: InputsValue[];
|
|
262
|
+
} & {
|
|
263
|
+
[key: string]: unknown;
|
|
264
|
+
};
|
|
265
|
+
speech?: {
|
|
266
|
+
voice: string;
|
|
267
|
+
text: string;
|
|
268
|
+
};
|
|
248
269
|
skipResponse?: boolean;
|
|
249
270
|
customTaskUUID?: string;
|
|
250
271
|
retry?: number;
|
|
@@ -270,6 +291,7 @@ interface IPromptEnhancer extends IAdditionalResponsePayload {
|
|
|
270
291
|
prompt: string;
|
|
271
292
|
includeCost?: boolean;
|
|
272
293
|
customTaskUUID?: string;
|
|
294
|
+
taskUUID?: string;
|
|
273
295
|
retry?: number;
|
|
274
296
|
}
|
|
275
297
|
interface IEnhancedPrompt extends IImageToText {
|
|
@@ -282,6 +304,7 @@ interface IUpscaleGan extends IAdditionalResponsePayload {
|
|
|
282
304
|
includeCost?: boolean;
|
|
283
305
|
outputQuality?: number;
|
|
284
306
|
customTaskUUID?: string;
|
|
307
|
+
taskUUID?: string;
|
|
285
308
|
retry?: number;
|
|
286
309
|
}
|
|
287
310
|
type ReconnectingWebsocketProps = {
|
|
@@ -397,6 +420,7 @@ type TAddModelBaseType = {
|
|
|
397
420
|
comment?: string;
|
|
398
421
|
private: boolean;
|
|
399
422
|
customTaskUUID?: string;
|
|
423
|
+
taskUUID?: string;
|
|
400
424
|
retry?: number;
|
|
401
425
|
onUploadStream?: (response?: IAddModelResponse, error?: IErrorResponse) => void;
|
|
402
426
|
};
|
|
@@ -440,6 +464,7 @@ type TPhotoMaker = {
|
|
|
440
464
|
includeCost?: boolean;
|
|
441
465
|
outputQuality?: number;
|
|
442
466
|
customTaskUUID?: string;
|
|
467
|
+
taskUUID?: string;
|
|
443
468
|
retry?: number;
|
|
444
469
|
onPartialImages?: (images: IImage[], error?: IError) => void;
|
|
445
470
|
} & IAdditionalResponsePayload;
|
|
@@ -572,11 +597,39 @@ type TImageMasking = {
|
|
|
572
597
|
customTaskUUID?: string;
|
|
573
598
|
retry?: number;
|
|
574
599
|
};
|
|
600
|
+
type TVectorize = {
|
|
601
|
+
model: string;
|
|
602
|
+
outputFormat?: string;
|
|
603
|
+
outputType?: string;
|
|
604
|
+
includeCost?: boolean;
|
|
605
|
+
inputs: {
|
|
606
|
+
image: string;
|
|
607
|
+
};
|
|
608
|
+
customTaskUUID?: string;
|
|
609
|
+
retry?: number;
|
|
610
|
+
};
|
|
611
|
+
type TVectorizeResponse = {
|
|
612
|
+
taskType: string;
|
|
613
|
+
taskUUID: string;
|
|
614
|
+
cost: number;
|
|
615
|
+
imageURL: string;
|
|
616
|
+
};
|
|
575
617
|
type TImageUpload = {
|
|
576
618
|
image: string;
|
|
577
619
|
customTaskUUID?: string;
|
|
578
620
|
retry?: number;
|
|
579
621
|
};
|
|
622
|
+
type TMediaStorage = {
|
|
623
|
+
media: string;
|
|
624
|
+
operation?: string;
|
|
625
|
+
customTaskUUID?: string;
|
|
626
|
+
retry?: number;
|
|
627
|
+
};
|
|
628
|
+
type TMediaStorageResponse = {
|
|
629
|
+
taskType: string;
|
|
630
|
+
taskUUID: string;
|
|
631
|
+
mediaUUID: string;
|
|
632
|
+
};
|
|
580
633
|
type TImageUploadResponse = {
|
|
581
634
|
image: string;
|
|
582
635
|
taskUUID: string;
|
|
@@ -641,19 +694,27 @@ declare class RunwareBase {
|
|
|
641
694
|
private listenToImages;
|
|
642
695
|
private listenToUpload;
|
|
643
696
|
private globalListener;
|
|
644
|
-
requestImages({ outputType, outputFormat, uploadEndpoint, checkNSFW, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, promptWeighting, numberResults, onPartialImages, includeCost, customTaskUUID, retry, refiner, maskMargin, outputQuality, controlNet, lora, embeddings, ipAdapters, providerSettings, outpaint, acceleratorOptions, advancedFeatures, referenceImages, includeGenerationTime, includePayload, ...rest }: IRequestImage, moreOptions?: Record<string, any>): Promise<ITextToImage[] | undefined>;
|
|
645
|
-
|
|
646
|
-
|
|
697
|
+
requestImages({ outputType, outputFormat, uploadEndpoint, checkNSFW, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, promptWeighting, numberResults, onPartialImages, includeCost, customTaskUUID, taskUUID: _taskUUID, retry, refiner, maskMargin, outputQuality, controlNet, lora, embeddings, ipAdapters, providerSettings, outpaint, acceleratorOptions, advancedFeatures, referenceImages, includeGenerationTime, includePayload, ...rest }: IRequestImage, moreOptions?: Record<string, any>): Promise<ITextToImage[] | undefined>;
|
|
698
|
+
imageInference(params: IRequestImage, moreOptions?: Record<string, any>): Promise<ITextToImage[] | undefined>;
|
|
699
|
+
controlNetPreProcess: ({ inputImage, preProcessorType, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, outputQuality, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
700
|
+
controlNetPreprocess: (params: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
701
|
+
requestImageToText: ({ inputImage, includeCost, customTaskUUID, taskUUID: _taskUUID, retry, includePayload, includeGenerationTime, }: IRequestImageToText) => Promise<IImageToText>;
|
|
702
|
+
caption: (params: IRequestImageToText) => Promise<IImageToText>;
|
|
647
703
|
removeImageBackground: (payload: IRemoveImageBackground) => Promise<IRemoveImage>;
|
|
704
|
+
removeBackground: (payload: IRemoveImageBackground) => Promise<IRemoveImage>;
|
|
705
|
+
vectorize: (payload: TVectorize) => Promise<TVectorizeResponse>;
|
|
648
706
|
videoInference: (payload: IRequestVideo) => Promise<IVideoToImage[] | IVideoToImage>;
|
|
649
707
|
getResponse: (payload: IAsyncResults) => Promise<IVideoToImage[]>;
|
|
650
|
-
upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, outputQuality, customTaskUUID, retry, includeGenerationTime, includePayload, }: IUpscaleGan) => Promise<IImage>;
|
|
651
|
-
|
|
708
|
+
upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, outputQuality, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IUpscaleGan) => Promise<IImage>;
|
|
709
|
+
upscale: (params: IUpscaleGan) => Promise<IImage>;
|
|
710
|
+
enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
|
|
711
|
+
promptEnhance: (params: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
|
|
652
712
|
modelUpload: (payload: TAddModel) => Promise<any>;
|
|
653
713
|
photoMaker: (payload: TPhotoMaker, moreOptions?: Record<string, any>) => Promise<TPhotoMakerResponse[] | undefined>;
|
|
654
714
|
modelSearch: (payload: TModelSearch) => Promise<TModelSearchResponse>;
|
|
655
715
|
imageMasking: (payload: TImageMasking) => Promise<TImageMaskingResponse>;
|
|
656
716
|
imageUpload: (payload: TImageUpload) => Promise<TImageUploadResponse>;
|
|
717
|
+
mediaStorage: (payload: TMediaStorage) => Promise<TMediaStorageResponse>;
|
|
657
718
|
protected baseSingleRequest: <T>({ payload, debugKey, isMultiple, }: {
|
|
658
719
|
payload: Record<string, any>;
|
|
659
720
|
debugKey: string;
|
|
@@ -689,4 +750,4 @@ declare class RunwareServer extends RunwareBase {
|
|
|
689
750
|
|
|
690
751
|
declare let Runware: typeof RunwareClient | typeof RunwareServer;
|
|
691
752
|
|
|
692
|
-
export { EControlMode, EModelArchitecture, EModelConditioning, EModelFormat, EModelType, EOpenPosePreProcessor, EPhotoMakerEnum, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, type GetWithPromiseAsyncCallBackType, type GetWithPromiseCallBackType, type IAddModelResponse, type IAdditionalResponsePayload, type IAsyncResults, type IBflProviderSettings, type IControlNet, type IControlNetGeneral, type IControlNetImage, type IControlNetPreprocess, type IControlNetWithUUID, type IEmbedding, type IEnhancedPrompt, type IError, type IErrorResponse, type IImage, type IImageToText, type IOutpaint, type IOutputFormat, type IOutputType, type IPromptEnhancer, type IProviderSettings, type IRefiner, type IRemoveImage, type IRemoveImageBackground, type IRequestImage, type IRequestImageToText, type IRequestVideo, type ITextToImage, type IUpscaleGan, type IVideoOutputFormat, type IVideoToImage, type IipAdapter, type ListenerType, type ProviderSettings, type ReconnectingWebsocketProps, type RequireAtLeastOne, type RequireOnlyOne, Runware, type RunwareBaseType, RunwareClient, RunwareServer, SdkType, type TAcceleratorOptions, type TAddModel, type TAddModelBaseType, type TAddModelCheckPoint, type TAddModelControlNet, type TAddModelLora, type TImageMasking, type TImageMaskingResponse, type TImageUpload, type TImageUploadResponse, type TModel, type TModelSearch, type TModelSearchResponse, type TPhotoMaker, type TPhotoMakerResponse, type TPromptWeighting, type TServerError, type UploadImageType };
|
|
753
|
+
export { EControlMode, EModelArchitecture, EModelConditioning, EModelFormat, EModelType, EOpenPosePreProcessor, EPhotoMakerEnum, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, type GetWithPromiseAsyncCallBackType, type GetWithPromiseCallBackType, type IAddModelResponse, type IAdditionalResponsePayload, type IAsyncResults, type IBflProviderSettings, type IControlNet, type IControlNetGeneral, type IControlNetImage, type IControlNetPreprocess, type IControlNetWithUUID, type IEmbedding, type IEnhancedPrompt, type IError, type IErrorResponse, type IImage, type IImageToText, type IOutpaint, type IOutputFormat, type IOutputType, type IPromptEnhancer, type IProviderSettings, type IRefiner, type IRemoveImage, type IRemoveImageBackground, type IRequestImage, type IRequestImageToText, type IRequestVideo, type ITextToImage, type IUpscaleGan, type IVideoOutputFormat, type IVideoToImage, type IipAdapter, type ListenerType, type ProviderSettings, type ReconnectingWebsocketProps, type RequireAtLeastOne, type RequireOnlyOne, Runware, type RunwareBaseType, RunwareClient, RunwareServer, SdkType, type TAcceleratorOptions, type TAddModel, type TAddModelBaseType, type TAddModelCheckPoint, type TAddModelControlNet, type TAddModelLora, type TImageMasking, type TImageMaskingResponse, type TImageUpload, type TImageUploadResponse, type TMediaStorage, type TMediaStorageResponse, type TModel, type TModelSearch, type TModelSearchResponse, type TPhotoMaker, type TPhotoMakerResponse, type TPromptWeighting, type TServerError, type TVectorize, type TVectorizeResponse, type UploadImageType };
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,9 @@ declare enum ETaskType {
|
|
|
21
21
|
PROMPT_ENHANCE = "promptEnhance",
|
|
22
22
|
AUTHENTICATION = "authentication",
|
|
23
23
|
MODEL_UPLOAD = "modelUpload",
|
|
24
|
-
MODEL_SEARCH = "modelSearch"
|
|
24
|
+
MODEL_SEARCH = "modelSearch",
|
|
25
|
+
MEDIA_STORAGE = "mediaStorage",
|
|
26
|
+
VECTORIZE = "vectorize"
|
|
25
27
|
}
|
|
26
28
|
type RunwareBaseType = {
|
|
27
29
|
apiKey: string;
|
|
@@ -103,6 +105,7 @@ type IControlNetPreprocess = {
|
|
|
103
105
|
includeCost?: boolean;
|
|
104
106
|
outputQuality?: number;
|
|
105
107
|
customTaskUUID?: string;
|
|
108
|
+
taskUUID?: string;
|
|
106
109
|
retry?: number;
|
|
107
110
|
} & IAdditionalResponsePayload;
|
|
108
111
|
type IControlNet = IControlNetGeneral;
|
|
@@ -201,6 +204,7 @@ interface IRequestImageToText extends IAdditionalResponsePayload {
|
|
|
201
204
|
inputImage?: File | string;
|
|
202
205
|
includeCost?: boolean;
|
|
203
206
|
customTaskUUID?: string;
|
|
207
|
+
taskUUID?: string;
|
|
204
208
|
retry?: number;
|
|
205
209
|
}
|
|
206
210
|
interface IImageToText {
|
|
@@ -226,6 +230,7 @@ interface IRemoveImageBackground extends IRequestImageToText {
|
|
|
226
230
|
outputQuality?: number;
|
|
227
231
|
retry?: number;
|
|
228
232
|
}
|
|
233
|
+
type InputsValue = string | Record<string, unknown>;
|
|
229
234
|
interface IRequestVideo extends IRequestImageToText {
|
|
230
235
|
outputType?: IOutputType;
|
|
231
236
|
outputFormat?: IVideoOutputFormat;
|
|
@@ -233,7 +238,7 @@ interface IRequestVideo extends IRequestImageToText {
|
|
|
233
238
|
uploadEndpoint?: string;
|
|
234
239
|
checkNSFW?: boolean;
|
|
235
240
|
includeCost?: boolean;
|
|
236
|
-
positivePrompt
|
|
241
|
+
positivePrompt?: string;
|
|
237
242
|
negativePrompt?: string;
|
|
238
243
|
model: string;
|
|
239
244
|
steps?: number;
|
|
@@ -245,6 +250,22 @@ interface IRequestVideo extends IRequestImageToText {
|
|
|
245
250
|
height?: number;
|
|
246
251
|
numberResults?: number;
|
|
247
252
|
inputAudios?: string[];
|
|
253
|
+
referenceVideos?: string[];
|
|
254
|
+
inputs?: {
|
|
255
|
+
image?: InputsValue;
|
|
256
|
+
images?: InputsValue[];
|
|
257
|
+
audio?: InputsValue;
|
|
258
|
+
audios?: InputsValue[];
|
|
259
|
+
mask?: InputsValue[];
|
|
260
|
+
reference?: InputsValue;
|
|
261
|
+
references?: InputsValue[];
|
|
262
|
+
} & {
|
|
263
|
+
[key: string]: unknown;
|
|
264
|
+
};
|
|
265
|
+
speech?: {
|
|
266
|
+
voice: string;
|
|
267
|
+
text: string;
|
|
268
|
+
};
|
|
248
269
|
skipResponse?: boolean;
|
|
249
270
|
customTaskUUID?: string;
|
|
250
271
|
retry?: number;
|
|
@@ -270,6 +291,7 @@ interface IPromptEnhancer extends IAdditionalResponsePayload {
|
|
|
270
291
|
prompt: string;
|
|
271
292
|
includeCost?: boolean;
|
|
272
293
|
customTaskUUID?: string;
|
|
294
|
+
taskUUID?: string;
|
|
273
295
|
retry?: number;
|
|
274
296
|
}
|
|
275
297
|
interface IEnhancedPrompt extends IImageToText {
|
|
@@ -282,6 +304,7 @@ interface IUpscaleGan extends IAdditionalResponsePayload {
|
|
|
282
304
|
includeCost?: boolean;
|
|
283
305
|
outputQuality?: number;
|
|
284
306
|
customTaskUUID?: string;
|
|
307
|
+
taskUUID?: string;
|
|
285
308
|
retry?: number;
|
|
286
309
|
}
|
|
287
310
|
type ReconnectingWebsocketProps = {
|
|
@@ -397,6 +420,7 @@ type TAddModelBaseType = {
|
|
|
397
420
|
comment?: string;
|
|
398
421
|
private: boolean;
|
|
399
422
|
customTaskUUID?: string;
|
|
423
|
+
taskUUID?: string;
|
|
400
424
|
retry?: number;
|
|
401
425
|
onUploadStream?: (response?: IAddModelResponse, error?: IErrorResponse) => void;
|
|
402
426
|
};
|
|
@@ -440,6 +464,7 @@ type TPhotoMaker = {
|
|
|
440
464
|
includeCost?: boolean;
|
|
441
465
|
outputQuality?: number;
|
|
442
466
|
customTaskUUID?: string;
|
|
467
|
+
taskUUID?: string;
|
|
443
468
|
retry?: number;
|
|
444
469
|
onPartialImages?: (images: IImage[], error?: IError) => void;
|
|
445
470
|
} & IAdditionalResponsePayload;
|
|
@@ -572,11 +597,39 @@ type TImageMasking = {
|
|
|
572
597
|
customTaskUUID?: string;
|
|
573
598
|
retry?: number;
|
|
574
599
|
};
|
|
600
|
+
type TVectorize = {
|
|
601
|
+
model: string;
|
|
602
|
+
outputFormat?: string;
|
|
603
|
+
outputType?: string;
|
|
604
|
+
includeCost?: boolean;
|
|
605
|
+
inputs: {
|
|
606
|
+
image: string;
|
|
607
|
+
};
|
|
608
|
+
customTaskUUID?: string;
|
|
609
|
+
retry?: number;
|
|
610
|
+
};
|
|
611
|
+
type TVectorizeResponse = {
|
|
612
|
+
taskType: string;
|
|
613
|
+
taskUUID: string;
|
|
614
|
+
cost: number;
|
|
615
|
+
imageURL: string;
|
|
616
|
+
};
|
|
575
617
|
type TImageUpload = {
|
|
576
618
|
image: string;
|
|
577
619
|
customTaskUUID?: string;
|
|
578
620
|
retry?: number;
|
|
579
621
|
};
|
|
622
|
+
type TMediaStorage = {
|
|
623
|
+
media: string;
|
|
624
|
+
operation?: string;
|
|
625
|
+
customTaskUUID?: string;
|
|
626
|
+
retry?: number;
|
|
627
|
+
};
|
|
628
|
+
type TMediaStorageResponse = {
|
|
629
|
+
taskType: string;
|
|
630
|
+
taskUUID: string;
|
|
631
|
+
mediaUUID: string;
|
|
632
|
+
};
|
|
580
633
|
type TImageUploadResponse = {
|
|
581
634
|
image: string;
|
|
582
635
|
taskUUID: string;
|
|
@@ -641,19 +694,27 @@ declare class RunwareBase {
|
|
|
641
694
|
private listenToImages;
|
|
642
695
|
private listenToUpload;
|
|
643
696
|
private globalListener;
|
|
644
|
-
requestImages({ outputType, outputFormat, uploadEndpoint, checkNSFW, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, promptWeighting, numberResults, onPartialImages, includeCost, customTaskUUID, retry, refiner, maskMargin, outputQuality, controlNet, lora, embeddings, ipAdapters, providerSettings, outpaint, acceleratorOptions, advancedFeatures, referenceImages, includeGenerationTime, includePayload, ...rest }: IRequestImage, moreOptions?: Record<string, any>): Promise<ITextToImage[] | undefined>;
|
|
645
|
-
|
|
646
|
-
|
|
697
|
+
requestImages({ outputType, outputFormat, uploadEndpoint, checkNSFW, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, promptWeighting, numberResults, onPartialImages, includeCost, customTaskUUID, taskUUID: _taskUUID, retry, refiner, maskMargin, outputQuality, controlNet, lora, embeddings, ipAdapters, providerSettings, outpaint, acceleratorOptions, advancedFeatures, referenceImages, includeGenerationTime, includePayload, ...rest }: IRequestImage, moreOptions?: Record<string, any>): Promise<ITextToImage[] | undefined>;
|
|
698
|
+
imageInference(params: IRequestImage, moreOptions?: Record<string, any>): Promise<ITextToImage[] | undefined>;
|
|
699
|
+
controlNetPreProcess: ({ inputImage, preProcessorType, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, outputQuality, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
700
|
+
controlNetPreprocess: (params: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
701
|
+
requestImageToText: ({ inputImage, includeCost, customTaskUUID, taskUUID: _taskUUID, retry, includePayload, includeGenerationTime, }: IRequestImageToText) => Promise<IImageToText>;
|
|
702
|
+
caption: (params: IRequestImageToText) => Promise<IImageToText>;
|
|
647
703
|
removeImageBackground: (payload: IRemoveImageBackground) => Promise<IRemoveImage>;
|
|
704
|
+
removeBackground: (payload: IRemoveImageBackground) => Promise<IRemoveImage>;
|
|
705
|
+
vectorize: (payload: TVectorize) => Promise<TVectorizeResponse>;
|
|
648
706
|
videoInference: (payload: IRequestVideo) => Promise<IVideoToImage[] | IVideoToImage>;
|
|
649
707
|
getResponse: (payload: IAsyncResults) => Promise<IVideoToImage[]>;
|
|
650
|
-
upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, outputQuality, customTaskUUID, retry, includeGenerationTime, includePayload, }: IUpscaleGan) => Promise<IImage>;
|
|
651
|
-
|
|
708
|
+
upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, outputQuality, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IUpscaleGan) => Promise<IImage>;
|
|
709
|
+
upscale: (params: IUpscaleGan) => Promise<IImage>;
|
|
710
|
+
enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
|
|
711
|
+
promptEnhance: (params: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
|
|
652
712
|
modelUpload: (payload: TAddModel) => Promise<any>;
|
|
653
713
|
photoMaker: (payload: TPhotoMaker, moreOptions?: Record<string, any>) => Promise<TPhotoMakerResponse[] | undefined>;
|
|
654
714
|
modelSearch: (payload: TModelSearch) => Promise<TModelSearchResponse>;
|
|
655
715
|
imageMasking: (payload: TImageMasking) => Promise<TImageMaskingResponse>;
|
|
656
716
|
imageUpload: (payload: TImageUpload) => Promise<TImageUploadResponse>;
|
|
717
|
+
mediaStorage: (payload: TMediaStorage) => Promise<TMediaStorageResponse>;
|
|
657
718
|
protected baseSingleRequest: <T>({ payload, debugKey, isMultiple, }: {
|
|
658
719
|
payload: Record<string, any>;
|
|
659
720
|
debugKey: string;
|
|
@@ -689,4 +750,4 @@ declare class RunwareServer extends RunwareBase {
|
|
|
689
750
|
|
|
690
751
|
declare let Runware: typeof RunwareClient | typeof RunwareServer;
|
|
691
752
|
|
|
692
|
-
export { EControlMode, EModelArchitecture, EModelConditioning, EModelFormat, EModelType, EOpenPosePreProcessor, EPhotoMakerEnum, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, type GetWithPromiseAsyncCallBackType, type GetWithPromiseCallBackType, type IAddModelResponse, type IAdditionalResponsePayload, type IAsyncResults, type IBflProviderSettings, type IControlNet, type IControlNetGeneral, type IControlNetImage, type IControlNetPreprocess, type IControlNetWithUUID, type IEmbedding, type IEnhancedPrompt, type IError, type IErrorResponse, type IImage, type IImageToText, type IOutpaint, type IOutputFormat, type IOutputType, type IPromptEnhancer, type IProviderSettings, type IRefiner, type IRemoveImage, type IRemoveImageBackground, type IRequestImage, type IRequestImageToText, type IRequestVideo, type ITextToImage, type IUpscaleGan, type IVideoOutputFormat, type IVideoToImage, type IipAdapter, type ListenerType, type ProviderSettings, type ReconnectingWebsocketProps, type RequireAtLeastOne, type RequireOnlyOne, Runware, type RunwareBaseType, RunwareClient, RunwareServer, SdkType, type TAcceleratorOptions, type TAddModel, type TAddModelBaseType, type TAddModelCheckPoint, type TAddModelControlNet, type TAddModelLora, type TImageMasking, type TImageMaskingResponse, type TImageUpload, type TImageUploadResponse, type TModel, type TModelSearch, type TModelSearchResponse, type TPhotoMaker, type TPhotoMakerResponse, type TPromptWeighting, type TServerError, type UploadImageType };
|
|
753
|
+
export { EControlMode, EModelArchitecture, EModelConditioning, EModelFormat, EModelType, EOpenPosePreProcessor, EPhotoMakerEnum, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, type GetWithPromiseAsyncCallBackType, type GetWithPromiseCallBackType, type IAddModelResponse, type IAdditionalResponsePayload, type IAsyncResults, type IBflProviderSettings, type IControlNet, type IControlNetGeneral, type IControlNetImage, type IControlNetPreprocess, type IControlNetWithUUID, type IEmbedding, type IEnhancedPrompt, type IError, type IErrorResponse, type IImage, type IImageToText, type IOutpaint, type IOutputFormat, type IOutputType, type IPromptEnhancer, type IProviderSettings, type IRefiner, type IRemoveImage, type IRemoveImageBackground, type IRequestImage, type IRequestImageToText, type IRequestVideo, type ITextToImage, type IUpscaleGan, type IVideoOutputFormat, type IVideoToImage, type IipAdapter, type ListenerType, type ProviderSettings, type ReconnectingWebsocketProps, type RequireAtLeastOne, type RequireOnlyOne, Runware, type RunwareBaseType, RunwareClient, RunwareServer, SdkType, type TAcceleratorOptions, type TAddModel, type TAddModelBaseType, type TAddModelCheckPoint, type TAddModelControlNet, type TAddModelLora, type TImageMasking, type TImageMaskingResponse, type TImageUpload, type TImageUploadResponse, type TMediaStorage, type TMediaStorageResponse, type TModel, type TModelSearch, type TModelSearchResponse, type TPhotoMaker, type TPhotoMakerResponse, type TPromptWeighting, type TServerError, type TVectorize, type TVectorizeResponse, type UploadImageType };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var Ge=Object.create;var ue=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ve=Object.getPrototypeOf,He=Object.prototype.hasOwnProperty;var je=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports);var Qe=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of qe(t))!He.call(i,r)&&r!==e&&ue(i,r,{get:()=>t[r],enumerable:!(n=Be(t,r))||n.enumerable});return i};var Je=(i,t,e)=>(e=i!=null?Ge(Ve(i)):{},Qe(t||!i||!i.__esModule?ue(e,"default",{value:i,enumerable:!0}):e,i));var ve=je((ln,xe)=>{"use strict";var ke=i=>i&&i.CLOSING===2,rt=()=>typeof WebSocket<"u"&&ke(WebSocket),at=()=>({constructor:rt()?WebSocket:null,maxReconnectionDelay:1e4,minReconnectionDelay:1500,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,debug:!1}),ot=(i,t,e)=>{Object.defineProperty(t,e,{get:()=>i[e],set:n=>{i[e]=n},enumerable:!0,configurable:!0})},Re=i=>i.minReconnectionDelay+Math.random()*i.minReconnectionDelay,it=(i,t)=>{let e=t*i.reconnectionDelayGrowFactor;return e>i.maxReconnectionDelay?i.maxReconnectionDelay:e},lt=["onopen","onclose","onmessage","onerror"],ut=(i,t,e)=>{Object.keys(e).forEach(n=>{e[n].forEach(([r,a])=>{i.addEventListener(n,r,a)})}),t&<.forEach(n=>{i[n]=t[n]})},De=function(i,t,e={}){let n,r,a=0,u=0,c=!0,s={};if(!(this instanceof De))throw new TypeError("Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator");let d=at();if(Object.keys(d).filter(l=>e.hasOwnProperty(l)).forEach(l=>d[l]=e[l]),!ke(d.constructor))throw new TypeError("Invalid WebSocket constructor. Set `options.constructor`");let p=d.debug?(...l)=>console.log("RWS:",...l):()=>{},g=(l,y)=>setTimeout(()=>{let I=new Error(y);I.code=l,Array.isArray(s.error)&&s.error.forEach(([f])=>f(I)),n.onerror&&n.onerror(I)},0),o=()=>{if(p("close"),u++,p("retries count:",u),u>d.maxRetries){g("EHOSTDOWN","Too many failed connection attempts");return}a?a=it(d,a):a=Re(d),p("reconnectDelay:",a),c&&setTimeout(m,a)},m=()=>{p("connect");let l=n;n=new d.constructor(i,t),r=setTimeout(()=>{p("timeout"),n.close(),g("ETIMEDOUT","Connection timeout")},d.connectionTimeout),p("bypass properties");for(let y in n)["addEventListener","removeEventListener","close","send"].indexOf(y)<0&&ot(n,this,y);n.addEventListener("open",()=>{clearTimeout(r),p("open"),a=Re(d),p("reconnectDelay:",a),u=0}),n.addEventListener("close",o),ut(n,l,s)};p("init"),m(),this.close=(l=1e3,y="",{keepClosed:I=!1,fastClose:f=!0,delay:k=0}={})=>{if(k&&(a=k),c=!I,n.close(l,y),f){let _={code:l,reason:y,wasClean:!0};o(),Array.isArray(s.close)&&s.close.forEach(([U,b])=>{U(_),n.removeEventListener("close",U,b)}),n.onclose&&(n.onclose(_),n.onclose=null)}},this.send=l=>{n.send(l)},this.addEventListener=(l,y,I)=>{Array.isArray(s[l])?s[l].some(([f])=>f===y)||s[l].push([y,I]):s[l]=[[y,I]],n.addEventListener(l,y,I)},this.removeEventListener=(l,y,I)=>{Array.isArray(s[l])&&(s[l]=s[l].filter(([f])=>f!==y)),n.removeEventListener(l,y,I)}};xe.exports=De});var ce=(n=>(n.PRODUCTION="PRODUCTION",n.DEVELOPMENT="DEVELOPMENT",n.TEST="TEST",n))(ce||{}),J=(e=>(e.CLIENT="CLIENT",e.SERVER="SERVER",e))(J||{}),$=(l=>(l.IMAGE_INFERENCE="imageInference",l.IMAGE_UPLOAD="imageUpload",l.IMAGE_UPSCALE="imageUpscale",l.IMAGE_BACKGROUND_REMOVAL="imageBackgroundRemoval",l.VIDEO_INFERENCE="videoInference",l.GET_RESPONSE="getResponse",l.PHOTO_MAKER="photoMaker",l.IMAGE_CAPTION="imageCaption",l.IMAGE_CONTROL_NET_PRE_PROCESS="imageControlNetPreProcess",l.IMAGE_MASKING="imageMasking",l.PROMPT_ENHANCE="promptEnhance",l.AUTHENTICATION="authentication",l.MODEL_UPLOAD="modelUpload",l.MODEL_SEARCH="modelSearch",l))($||{}),de=(n=>(n.BALANCED="balanced",n.PROMPT="prompt",n.CONTROL_NET="controlnet",n))(de||{}),pe=(o=>(o.canny="canny",o.depth="depth",o.mlsd="mlsd",o.normalbae="normalbae",o.openpose="openpose",o.tile="tile",o.seg="seg",o.lineart="lineart",o.lineart_anime="lineart_anime",o.shuffle="shuffle",o.scribble="scribble",o.softedge="softedge",o))(pe||{}),ge=(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))(ge||{}),$e=(a=>(a.openpose="openpose",a.openpose_face="openpose_face",a.openpose_faceonly="openpose_faceonly",a.openpose_full="openpose_full",a.openpose_hand="openpose_hand",a))($e||{}),ze=(e=>(e.safetensors="safetensors",e.pickletensor="pickletensor",e))(ze||{}),Ye=(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))(Ye||{}),Ze=(n=>(n.base="base",n.inpainting="inpainting",n.pix2pix="pix2pix",n))(Ze||{}),Xe=(b=>(b.canny="canny",b.depth="depth",b.qrcode="qrcode",b.hed="hed",b.scrible="scrible",b.openpose="openpose",b.seg="segmentation",b.openmlsd="openmlsd",b.softedge="softedge",b.normal="normal bae",b.shuffle="shuffle",b.pix2pix="pix2pix",b.inpaint="inpaint",b.lineart="line art",b.sketch="sketch",b.inpaintdepth="inpaint depth",b.tile="tile",b.outfit="outfit",b.blur="blur",b.gray="gray",b.lowquality="low quality",b))(Xe||{}),et=(g=>(g.NoStyle="No style",g.Cinematic="Cinematic",g.DisneyCharacter="Disney Character",g.DigitalArt="Digital Art",g.Photographic="Photographic",g.FantasyArt="Fantasy art",g.Neonpunk="Neonpunk",g.Enhance="Enhance",g.ComicBook="Comic book",g.Lowpoly="Lowpoly",g.LineArt="Line art",g))(et||{});import{v4 as tt,validate as nt}from"uuid";var K=6e4,P=1e3,me=100,z={PRODUCTION:"wss://ws-api.runware.ai/v1",TEST:"ws://localhost:8080"},ye=(i,t)=>{if(i==null)return;let e=i.indexOf(t);e!==-1&&i.splice(e,1)},S=(i,{debugKey:t="debugKey",timeoutDuration:e=K,shouldThrowError:n=!0,pollingInterval:r=me})=>(e=e<P?P:e,new Promise((a,u)=>{let c=setTimeout(()=>{s&&(clearInterval(s),n&&u(`Response could not be received from server for ${t}`)),clearTimeout(c)},e),s=setInterval(async()=>{i({resolve:a,reject:u,intervalId:s})&&(clearInterval(s),clearTimeout(c))},r)})),Ie=i=>new Promise(t=>{let e=new FileReader;e.readAsDataURL(i),e.onload=function(){t(e.result)}}),R=()=>tt(),Y=i=>nt(i);var he=({key:i,data:t,useZero:e=!0,shouldReturnString:n=!1})=>i.split(/\.|\[/).map(u=>u.replace(/\]$/,"")).reduce((u,c)=>{let s=e?0:void 0,d=u?.[c];if(!d)return s;if(Array.isArray(d)&&/^\d+$/.test(c)){let p=parseInt(c,10);return p>=0&&p<d.length?u[c]=d[p]:u[c]??s}else return u[c]??s},t||{})??{},fe=(i,t=1e3)=>new Promise(e=>setTimeout(e,i*t));var be=(i,t)=>i.filter(e=>e.key!==t.key);var T=({key:i,value:t})=>t||t===0||t===!1?{[i]:t}:{},st=(i,t)=>Math.floor(Math.random()*(t-i+1))+i,Te=()=>st(1,Number.MAX_SAFE_INTEGER),Ue=(i,{debugKey:t="debugKey",timeoutDuration:e=K,shouldThrowError:n=!0,pollingInterval:r=me})=>(e=e<P?P:e,new Promise((a,u)=>{let c=setTimeout(()=>{s&&(clearInterval(s),n&&u(`Response could not be received from server for ${t}`)),clearTimeout(c)},e),s=setInterval(async()=>{try{await i({resolve:a,reject:u,intervalId:s})&&(clearInterval(s),clearTimeout(c))}catch(d){clearInterval(s),clearTimeout(c),u(d)}},r)})),_e=i=>typeof i=="string"&&(i.startsWith("http:")||i.startsWith("https:"));var x=async(i,t={})=>{let{delayInSeconds:e=1,callback:n}=t,r=t.maxRetries??1;for(;r;)try{return await i()}catch(a){if(n?.(),a?.error)throw a;if(r--,r>0)await fe(e),await x(i,{...t,maxRetries:r});else throw a}};var A=class{constructor({apiKey:t,url:e=z.PRODUCTION,shouldReconnect:n=!0,globalMaxRetries:r=2,timeoutDuration:a=K}){this._listeners=[];this._globalMessages={};this._globalImages=[];this.ensureConnectionUUID=null;this.isWebsocketReadyState=()=>this._ws?.readyState===1;this.isInvalidAPIKey=()=>this._connectionError?.error?.code==="invalidApiKey";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"&&Y(t))return{imageURL:t,imageUUID:t,taskUUID:e,taskType:"imageUpload"};let n=typeof t=="string"?t:await Ie(t);return{imageURL:n,imageUUID:n,taskUUID:e,taskType:"imageUpload"}})}catch(e){throw e}};this.controlNetPreProcess=async({inputImage:t,preProcessorType:e,height:n,width:r,outputType:a,outputFormat:u,highThresholdCanny:c,lowThresholdCanny:s,includeHandsAndFaceOpenPose:d,includeCost:p,outputQuality:g,customTaskUUID:o,retry:m,includeGenerationTime:l,includePayload:y})=>{let I=m||this._globalMaxRetries,f,k=Date.now();try{return await x(async()=>{await this.ensureConnection();let _=await this.uploadImage(t);if(!_?.imageUUID)return null;let U=o||R(),b={inputImage:_.imageUUID,taskType:"imageControlNetPreProcess",taskUUID:U,preProcessorType:e,...T({key:"height",value:n}),...T({key:"width",value:r}),...T({key:"outputType",value:a}),...T({key:"outputFormat",value:u}),...T({key:"includeCost",value:p}),...T({key:"highThresholdCanny",value:c}),...T({key:"lowThresholdCanny",value:s}),...T({key:"includeHandsAndFaceOpenPose",value:d}),...g?{outputQuality:g}:{}};this.send({...b}),f=this.globalListener({taskUUID:U});let O=await S(({resolve:G,reject:B})=>{let v=this.getSingleMessage({taskUUID:U});if(v){if(v?.error)return B(v),!0;if(v)return G(v),!0}},{debugKey:"unprocessed-image",timeoutDuration:this._timeoutDuration});return f.destroy(),this.insertAdditionalResponse({response:O,payload:y?b:void 0,startTime:l?k:void 0}),O},{maxRetries:I,callback:()=>{f?.destroy()}})}catch(_){throw _}};this.requestImageToText=async({inputImage:t,includeCost:e,customTaskUUID:n,retry:r,includePayload:a,includeGenerationTime:u})=>{let c=r||this._globalMaxRetries,s,d=Date.now();try{return await x(async()=>{await this.ensureConnection();let p=t?await this.uploadImage(t):null,g=n||R(),o={taskUUID:g,taskType:"imageCaption",inputImage:p?.imageUUID,...T({key:"includeCost",value:e})};this.send(o),s=this.globalListener({taskUUID:g});let m=await S(({resolve:l,reject:y})=>{let I=this.getSingleMessage({taskUUID:g});if(I){if(I?.error)return y(I),!0;if(I)return delete this._globalMessages[g],l(I),!0}},{debugKey:"remove-image-background",timeoutDuration:this._timeoutDuration});return s.destroy(),this.insertAdditionalResponse({response:m,payload:a?o:void 0,startTime:u?d:void 0}),m},{maxRetries:c,callback:()=>{s?.destroy()}})}catch(p){throw p}};this.removeImageBackground=async t=>this.baseSingleRequest({payload:{...t,taskType:"imageBackgroundRemoval"},debugKey:"remove-image-background"});this.videoInference=async t=>{let{skipResponse:e,inputAudios:n,...r}=t;try{if(n?.length){for(let d of n)if(!_e(d)&&!Y(d))throw new Error(`Invalid audio source: "${d}". Only public URLs or media UUIDs are supported for audio.`)}let a=await this.baseSingleRequest({payload:{...r,...n?.length?{inputAudios:n}:{},deliveryMethod:"async",taskType:"videoInference"},debugKey:"video-inference"});if(e)return a;let u=a?.taskUUID,c=t?.numberResults??1,s=new Map;return await Ue(async({resolve:d,reject:p})=>{try{let g=await this.getResponse({taskUUID:u});for(let m of g||[])m.videoUUID&&s.set(m.videoUUID,m);return s.size===c?(d(Array.from(s.values())),!0):!1}catch(g){return p(g),!0}},{debugKey:"async-response",pollingInterval:2*1e3,timeoutDuration:10*60*1e3}),Array.from(s.values())}catch(a){throw a}};this.getResponse=async t=>{let e=t.taskUUID;return this.baseSingleRequest({payload:{...t,customTaskUUID:e,taskType:"getResponse"},isMultiple:!0,debugKey:"async-results"})};this.upscaleGan=async({inputImage:t,upscaleFactor:e,outputType:n,outputFormat:r,includeCost:a,outputQuality:u,customTaskUUID:c,retry:s,includeGenerationTime:d,includePayload:p})=>{let g=s||this._globalMaxRetries,o,m=Date.now();try{return await x(async()=>{await this.ensureConnection();let l;l=await this.uploadImage(t);let y=c||R(),I={taskUUID:y,inputImage:l?.imageUUID,taskType:"imageUpscale",upscaleFactor:e,...T({key:"includeCost",value:a}),...n?{outputType:n}:{},...u?{outputQuality:u}:{},...r?{outputFormat:r}:{}};this.send(I),o=this.globalListener({taskUUID:y});let f=await S(({resolve:k,reject:_})=>{let U=this.getSingleMessage({taskUUID:y});if(U){if(U?.error)return _(U),!0;if(U)return delete this._globalMessages[y],k(U),!0}},{debugKey:"upscale-gan",timeoutDuration:this._timeoutDuration});return o.destroy(),this.insertAdditionalResponse({response:f,payload:p?I:void 0,startTime:d?m:void 0}),f},{maxRetries:g,callback:()=>{o?.destroy()}})}catch(l){throw l}};this.enhancePrompt=async({prompt:t,promptMaxLength:e=380,promptVersions:n=1,includeCost:r,customTaskUUID:a,retry:u,includeGenerationTime:c,includePayload:s})=>{let d=u||this._globalMaxRetries,p,g=Date.now();try{return await x(async()=>{await this.ensureConnection();let o=a||R(),m={prompt:t,taskUUID:o,promptMaxLength:e,promptVersions:n,...T({key:"includeCost",value:r}),taskType:"promptEnhance"};this.send(m),p=this.globalListener({taskUUID:o});let l=await S(({resolve:y,reject:I})=>{let f=this._globalMessages[o];if(f?.error)return I(f),!0;if(f?.length>=n)return delete this._globalMessages[o],y(f),!0},{debugKey:"enhance-prompt",timeoutDuration:this._timeoutDuration});return p.destroy(),this.insertAdditionalResponse({response:l,payload:s?m:void 0,startTime:c?g:void 0}),l},{maxRetries:d,callback:()=>{p?.destroy()}})}catch(o){throw o}};this.modelUpload=async t=>{let{onUploadStream:e,retry:n,customTaskUUID:r,...a}=t,u=n||this._globalMaxRetries,c;try{return await x(async()=>{await this.ensureConnection();let s=r||R();this.send({...a,taskUUID:s,taskType:"modelUpload"});let d,p;return c=this.listenToUpload({taskUUID:s,onUploadStream:(o,m)=>{e?.(o,m),o?.status==="ready"?d=o:m&&(p=m)}}),await S(({resolve:o,reject:m})=>{if(d)return o(d),!0;if(p)return m(p),!1},{shouldThrowError:!1,timeoutDuration:60*60*1e3})},{maxRetries:u,callback:()=>{c?.destroy()}})}catch(s){throw s}};this.photoMaker=async(t,e)=>{let{onPartialImages:n,retry:r,customTaskUUID:a,numberResults:u,includeGenerationTime:c,includePayload:s,...d}=t,p=r||this._globalMaxRetries,g,o=[],m=0,l=Date.now();try{return await x(async()=>{await this.ensureConnection(),m++;let y=this._globalImages.filter(U=>o.includes(U.taskUUID)),I=a||R();o.push(I);let f=u-y.length,k={...d,...d.seed?{seed:d.seed}:{seed:Te()},...e??{},taskUUID:I,taskType:"photoMaker",numberResults:u};this.send({...k,numberResults:f}),g=this.listenToImages({onPartialImages:n,taskUUID:I,groupKey:"REQUEST_IMAGES",requestPayload:s?k:void 0,startTime:c?l:void 0});let _=await this.getSimilarImages({taskUUID:o,numberResults:u,lis:g});return g.destroy(),_},{maxRetries:p,callback:()=>{g?.destroy()}})}catch(y){if(y.taskUUID)throw y;if(m>=p)return this.handleIncompleteImages({taskUUIDs:o,error:y})}};this.modelSearch=async t=>this.baseSingleRequest({payload:{...t,taskType:"modelSearch"},debugKey:"model-search"});this.imageMasking=async t=>this.baseSingleRequest({payload:{...t,taskType:"imageMasking"},debugKey:"image-masking"});this.imageUpload=async t=>this.baseSingleRequest({payload:{...t,taskType:"imageUpload"},debugKey:"image-upload"});this.baseSingleRequest=async({payload:t,debugKey:e,isMultiple:n})=>{let{retry:r,customTaskUUID:a,includePayload:u,includeGenerationTime:c,...s}=t,d=r||this._globalMaxRetries,p,g=Date.now();try{return await x(async()=>{await this.ensureConnection();let o=a||R(),m={...s,taskUUID:o};this.send(m),p=this.globalListener({taskUUID:o});let l=await S(({resolve:y,reject:I})=>{let f=n?this.getMultipleMessages({taskUUID:o}):this.getSingleMessage({taskUUID:o});if(f){if(f?.error)return I(f),!0;if(f)return delete this._globalMessages[o],y(f),!0}},{debugKey:e,timeoutDuration:this._timeoutDuration});return this.insertAdditionalResponse({response:l,payload:u?m:void 0,startTime:c?g:void 0}),p.destroy(),l},{maxRetries:d,callback:()=>{p?.destroy()}})}catch(o){throw o}};this.getSingleMessage=({taskUUID:t})=>{let e=this._globalMessages[t]?.[0],n=this._globalMessages[t];return!e&&!n?null:n?.error?n:e};this.getMultipleMessages=({taskUUID:t})=>{let e=this._globalMessages[t]?.[0],n=this._globalMessages[t];return!e&&!n?null:n};this.insertAdditionalResponse=({response:t,payload:e,startTime:n})=>{if(!e&&!n)return;let r=t;r.additionalResponse={},e&&(t.additionalResponse.payload=e),n&&(t.additionalResponse.generationTime=Date.now()-n)};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=r,this._timeoutDuration=a}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 r=c=>{let s=Array.isArray(c?.data)?c.data:[c.data],d=c?.[0]?.errors?c?.[0]?.errors:Array.isArray(c?.errors)?c.errors:[c.errors],p=s.filter(o=>(o?.taskUUID||o?.taskType)===n);if(d.filter(o=>(o?.taskUUID||o?.taskType)===n).length){t({error:{...d[0]??{}}});return}if(p.length){t({[n]:s});return}},a={key:n||R(),listener:r,groupKey:e};return this._listeners.push(a),{destroy:()=>{this._listeners=be(this._listeners,a)}}}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._connectionError=e;return}this._connectionSessionUUID=e?.authentication?.[0]?.connectionSessionUUID,this._connectionError=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.isInvalidAPIKey()}}destroy(t){ye(this._listeners,t)}listenToImages({onPartialImages:t,taskUUID:e,groupKey:n,requestPayload:r,startTime:a}){return this.addListener({taskUUID:e,lis:u=>{let c=u?.[e]?.filter(s=>s.taskUUID===e);u.error?(t?.(c,u?.error&&u),this._globalError=u):(c=c.map(s=>(this.insertAdditionalResponse({response:s,payload:r||void 0,startTime:a||void 0}),{...s})),t?.(c,u?.error&&u),this._sdkType==="CLIENT"?this._globalImages=[...this._globalImages,...(u?.[e]??[]).map(s=>(this.insertAdditionalResponse({response:s,payload:r||void 0,startTime:a||void 0}),{...s}))]:this._globalImages=[...this._globalImages,...c])},groupKey:n})}listenToUpload({onUploadStream:t,taskUUID:e}){return this.addListener({taskUUID:e,lis:n=>{let r=n?.error,a=n?.[e]?.[0],u=a?.taskUUID===e?a:null;(u||r)&&t?.(u||void 0,r)}})}globalListener({taskUUID:t}){return this.addListener({taskUUID:t,lis:e=>{if(e.error){this._globalMessages[t]=e;return}let n=he({key:t,data:e,useZero:!1});Array.isArray(n)?n.forEach(r=>{this._globalMessages[r.taskUUID]=[...this._globalMessages[r.taskUUID]??[],r]}):this._globalMessages[n.taskUUID]=n}})}async requestImages({outputType:t,outputFormat:e,uploadEndpoint:n,checkNSFW:r,positivePrompt:a,negativePrompt:u,seedImage:c,maskImage:s,strength:d,height:p,width:g,model:o,steps:m,scheduler:l,seed:y,CFGScale:I,clipSkip:f,usePromptWeighting:k,promptWeighting:_,numberResults:U=1,onPartialImages:b,includeCost:O,customTaskUUID:G,retry:B,refiner:v,maskMargin:Ae,outputQuality:h,controlNet:q,lora:Z,embeddings:X,ipAdapters:ee,providerSettings:te,outpaint:ne,acceleratorOptions:se,advancedFeatures:re,referenceImages:ae,includeGenerationTime:Ce,includePayload:Ee,...Oe},Me){let C,oe,M=[],ie=0,le=B||this._globalMaxRetries;try{await this.ensureConnection();let w=null,V=null,H=[];if(c){let D=await this.uploadImage(c);if(!D)return[];w=D.imageUUID}if(s){let D=await this.uploadImage(s);if(!D)return[];V=D.imageUUID}if(q?.length)for(let D=0;D<q.length;D++){let E=q[D],{endStep:j,startStep:N,weight:Q,guideImage:L,controlMode:Le,startStepPercentage:Pe,endStepPercentage:Ke,model:We}=E,Fe=L?await this.uploadImage(L):null;H.push({guideImage:Fe?.imageUUID,model:We,endStep:j,startStep:N,weight:Q,...T({key:"startStepPercentage",value:Pe}),...T({key:"endStepPercentage",value:Ke}),controlMode:Le||"controlnet"})}oe={taskType:"imageInference",model:o,positivePrompt:a,...u?{negativePrompt:u}:{},...p?{height:p}:{},...g?{width:g}:{},numberResults:U,...t?{outputType:t}:{},...e?{outputFormat:e}:{},...n?{uploadEndpoint:n}:{},...T({key:"checkNSFW",value:r}),...T({key:"strength",value:d}),...T({key:"CFGScale",value:I}),...T({key:"clipSkip",value:f}),...T({key:"maskMargin",value:Ae}),...T({key:"usePromptWeighting",value:k}),...T({key:"steps",value:m}),..._?{promptWeighting:_}:{},...y?{seed:y}:{},...l?{scheduler:l}:{},...v?{refiner:v}:{},...ne?{outpaint:ne}:{},...T({key:"includeCost",value:O}),...w?{seedImage:w}:{},...V?{maskImage:V}:{},...h?{outputQuality:h}:{},...H.length?{controlNet:H}:{},...Z?.length?{lora:Z}:{},...X?.length?{embeddings:X}:{},...ee?.length?{ipAdapters:ee}:{},...te?{providerSettings:te}:{},...se?{acceleratorOptions:se}:{},...re?{advancedFeatures:re}:{},...ae?.length?{referenceImages:ae}:{},...Oe,...Me??{}};let Ne=Date.now();return await x(async()=>{ie++,C?.destroy();let D=this._globalImages.filter(L=>M.includes(L.taskUUID)),E=G||R();M.push(E);let j=U-D.length,N={...oe,taskUUID:E,numberResults:j};this.send(N),C=this.listenToImages({onPartialImages:b,taskUUID:E,groupKey:"REQUEST_IMAGES",requestPayload:Ee?N:void 0,startTime:Ce?Ne:void 0});let Q=await this.getSimilarImages({taskUUID:M,numberResults:U,lis:C});return C.destroy(),Q},{maxRetries:le,callback:()=>{C?.destroy()}})}catch(w){if(ie>=le)return this.handleIncompleteImages({taskUUIDs:M,error:w});throw w}}async ensureConnection(){if(this.connected()||this._url===z.TEST)return;let e=2e3,n=200;try{if(this.isInvalidAPIKey())throw this._connectionError;return new Promise((r,a)=>{let u=0,c=30,s=R(),d,p,g=()=>{this.ensureConnectionUUID=null,clearInterval(d),clearInterval(p)};this._sdkType==="SERVER"&&(d=setInterval(async()=>{try{let o=this.connected(),m=!1;(!this.ensureConnectionUUID||s===this.ensureConnectionUUID)&&(this.ensureConnectionUUID||(this.ensureConnectionUUID=s),m=!0);let l=u%10===0&&m;o?(g(),r(!0)):u>=c?(g(),a(new Error("Retry timed out"))):(l&&this.connect(),u++)}catch(o){g(),a(o)}},e)),p=setInterval(async()=>{if(this.connected()){g(),r(!0);return}if(this.isInvalidAPIKey()){g(),a(this._connectionError);return}},n)})}catch{throw this.ensureConnectionUUID=null,this._connectionError=void 0,this._connectionError??"Could not connect to server. Ensure your API key is correct"}}async getSimilarImages({taskUUID:t,numberResults:e,shouldThrowError:n,lis:r}){return await S(({resolve:a,reject:u,intervalId:c})=>{let s=Array.isArray(t)?t:[t],d=this._globalImages.filter(p=>s.includes(p.taskUUID));if(this._globalError){let p=this._globalError;return this._globalError=void 0,clearInterval(c),u?.(p),!0}else if(d.length>=e)return clearInterval(c),this._globalImages=this._globalImages.filter(p=>!s.includes(p.taskUUID)),a([...d].slice(0,e)),!0},{debugKey:"getting images",shouldThrowError:n,timeoutDuration:this._timeoutDuration})}handleIncompleteImages({taskUUIDs:t,error:e}){let n=this._globalImages.filter(r=>t.includes(r.taskUUID));if(n.length>1)return this._globalImages=this._globalImages.filter(r=>!t.includes(r.taskUUID)),n;throw e}};var Se=Je(ve(),1),W=class extends A{constructor(t){let{shouldReconnect:e,...n}=t;super(n),this._ws=new Se.default(this._url),this.connect()}};import ct from"ws";var F=class extends A{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.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 ct(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._connectionError=e;return}this._connectionSessionUUID=e?.authentication?.[0]?.connectionSessionUUID,this._connectionError=void 0}})}),this._ws.on("message",(e,n)=>{let r=n?e:e?.toString();if(!r)return;let a=JSON.parse(r);this._listeners.forEach(u=>{u.listener(a)})}))}handleClose(){this.isInvalidAPIKey()||(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 we;typeof window>"u"?we=F:we=W;export{de as EControlMode,Ye as EModelArchitecture,Xe as EModelConditioning,ze as EModelFormat,Ze as EModelType,$e as EOpenPosePreProcessor,et as EPhotoMakerEnum,ge as EPreProcessor,pe as EPreProcessorGroup,$ as ETaskType,ce as Environment,we as Runware,W as RunwareClient,F as RunwareServer,J as SdkType};
|
|
1
|
+
var Fe=Object.create;var ce=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,He=Object.prototype.hasOwnProperty;var ze=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var je=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ve(e))!He.call(i,s)&&s!==t&&ce(i,s,{get:()=>e[s],enumerable:!(n=Be(e,s))||n.enumerable});return i};var Qe=(i,e,t)=>(t=i!=null?Fe(qe(i)):{},je(e||!i||!i.__esModule?ce(t,"default",{value:i,enumerable:!0}):t,i));var Se=ze((pn,ve)=>{"use strict";var De=i=>i&&i.CLOSING===2,rt=()=>typeof WebSocket<"u"&&De(WebSocket),at=()=>({constructor:rt()?WebSocket:null,maxReconnectionDelay:1e4,minReconnectionDelay:1500,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,debug:!1}),ot=(i,e,t)=>{Object.defineProperty(e,t,{get:()=>i[t],set:n=>{i[t]=n},enumerable:!0,configurable:!0})},ke=i=>i.minReconnectionDelay+Math.random()*i.minReconnectionDelay,it=(i,e)=>{let t=e*i.reconnectionDelayGrowFactor;return t>i.maxReconnectionDelay?i.maxReconnectionDelay:t},lt=["onopen","onclose","onmessage","onerror"],ut=(i,e,t)=>{Object.keys(t).forEach(n=>{t[n].forEach(([s,r])=>{i.addEventListener(n,s,r)})}),e&<.forEach(n=>{i[n]=e[n]})},xe=function(i,e,t={}){let n,s,r=0,o=0,l=!0,a={};if(!(this instanceof xe))throw new TypeError("Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator");let d=at();if(Object.keys(d).filter(c=>t.hasOwnProperty(c)).forEach(c=>d[c]=t[c]),!De(d.constructor))throw new TypeError("Invalid WebSocket constructor. Set `options.constructor`");let I=d.debug?(...c)=>console.log("RWS:",...c):()=>{},p=(c,h)=>setTimeout(()=>{let m=new Error(h);m.code=c,Array.isArray(a.error)&&a.error.forEach(([b])=>b(m)),n.onerror&&n.onerror(m)},0),g=()=>{if(I("close"),o++,I("retries count:",o),o>d.maxRetries){p("EHOSTDOWN","Too many failed connection attempts");return}r?r=it(d,r):r=ke(d),I("reconnectDelay:",r),l&&setTimeout(u,r)},u=()=>{I("connect");let c=n;n=new d.constructor(i,e),s=setTimeout(()=>{I("timeout"),n.close(),p("ETIMEDOUT","Connection timeout")},d.connectionTimeout),I("bypass properties");for(let h in n)["addEventListener","removeEventListener","close","send"].indexOf(h)<0&&ot(n,this,h);n.addEventListener("open",()=>{clearTimeout(s),I("open"),r=ke(d),I("reconnectDelay:",r),o=0}),n.addEventListener("close",g),ut(n,c,a)};I("init"),u(),this.close=(c=1e3,h="",{keepClosed:m=!1,fastClose:b=!0,delay:U=0}={})=>{if(U&&(r=U),l=!m,n.close(c,h),b){let _={code:c,reason:h,wasClean:!0};g(),Array.isArray(a.close)&&a.close.forEach(([R,y])=>{R(_),n.removeEventListener("close",R,y)}),n.onclose&&(n.onclose(_),n.onclose=null)}},this.send=c=>{n.send(c)},this.addEventListener=(c,h,m)=>{Array.isArray(a[c])?a[c].some(([b])=>b===h)||a[c].push([h,m]):a[c]=[[h,m]],n.addEventListener(c,h,m)},this.removeEventListener=(c,h,m)=>{Array.isArray(a[c])&&(a[c]=a[c].filter(([b])=>b!==h)),n.removeEventListener(c,h,m)}};ve.exports=xe});var de=(n=>(n.PRODUCTION="PRODUCTION",n.DEVELOPMENT="DEVELOPMENT",n.TEST="TEST",n))(de||{}),J=(t=>(t.CLIENT="CLIENT",t.SERVER="SERVER",t))(J||{}),Z=(m=>(m.IMAGE_INFERENCE="imageInference",m.IMAGE_UPLOAD="imageUpload",m.IMAGE_UPSCALE="imageUpscale",m.IMAGE_BACKGROUND_REMOVAL="imageBackgroundRemoval",m.VIDEO_INFERENCE="videoInference",m.GET_RESPONSE="getResponse",m.PHOTO_MAKER="photoMaker",m.IMAGE_CAPTION="imageCaption",m.IMAGE_CONTROL_NET_PRE_PROCESS="imageControlNetPreProcess",m.IMAGE_MASKING="imageMasking",m.PROMPT_ENHANCE="promptEnhance",m.AUTHENTICATION="authentication",m.MODEL_UPLOAD="modelUpload",m.MODEL_SEARCH="modelSearch",m.MEDIA_STORAGE="mediaStorage",m.VECTORIZE="vectorize",m))(Z||{}),ge=(n=>(n.BALANCED="balanced",n.PROMPT="prompt",n.CONTROL_NET="controlnet",n))(ge||{}),pe=(g=>(g.canny="canny",g.depth="depth",g.mlsd="mlsd",g.normalbae="normalbae",g.openpose="openpose",g.tile="tile",g.seg="seg",g.lineart="lineart",g.lineart_anime="lineart_anime",g.shuffle="shuffle",g.scribble="scribble",g.softedge="softedge",g))(pe||{}),me=(f=>(f.canny="canny",f.depth_leres="depth_leres",f.depth_midas="depth_midas",f.depth_zoe="depth_zoe",f.inpaint_global_harmonious="inpaint_global_harmonious",f.lineart_anime="lineart_anime",f.lineart_coarse="lineart_coarse",f.lineart_realistic="lineart_realistic",f.lineart_standard="lineart_standard",f.mlsd="mlsd",f.normal_bae="normal_bae",f.scribble_hed="scribble_hed",f.scribble_pidinet="scribble_pidinet",f.seg_ofade20k="seg_ofade20k",f.seg_ofcoco="seg_ofcoco",f.seg_ufade20k="seg_ufade20k",f.shuffle="shuffle",f.softedge_hed="softedge_hed",f.softedge_hedsafe="softedge_hedsafe",f.softedge_pidinet="softedge_pidinet",f.softedge_pidisafe="softedge_pidisafe",f.tile_gaussian="tile_gaussian",f.openpose="openpose",f.openpose_face="openpose_face",f.openpose_faceonly="openpose_faceonly",f.openpose_full="openpose_full",f.openpose_hand="openpose_hand",f))(me||{}),Je=(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))(Je||{}),Ze=(t=>(t.safetensors="safetensors",t.pickletensor="pickletensor",t))(Ze||{}),Ye=(u=>(u.flux1d="flux1d",u.flux1s="flux1s",u.pony="pony",u.sdhyper="sdhyper",u.sd1x="sd1x",u.sd1xlcm="sd1xlcm",u.sd3="sd3",u.sdxl="sdxl",u.sdxllcm="sdxllcm",u.sdxldistilled="sdxldistilled",u.sdxlhyper="sdxlhyper",u.sdxllightning="sdxllightning",u.sdxlturbo="sdxlturbo",u))(Ye||{}),$e=(n=>(n.base="base",n.inpainting="inpainting",n.pix2pix="pix2pix",n))($e||{}),Xe=(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))(Xe||{}),et=(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))(et||{});import{v4 as tt,validate as nt}from"uuid";var W=6e4,K=1e3,Ie=100,Y={PRODUCTION:"wss://ws-api.runware.ai/v1",TEST:"ws://localhost:8080"},ye=(i,e)=>{if(i==null)return;let t=i.indexOf(e);t!==-1&&i.splice(t,1)},S=(i,{debugKey:e="debugKey",timeoutDuration:t=W,shouldThrowError:n=!0,pollingInterval:s=Ie})=>(t=t<K?K:t,new Promise((r,o)=>{let l=setTimeout(()=>{a&&(clearInterval(a),n&&o(`Response could not be received from server for ${e}`)),clearTimeout(l)},t),a=setInterval(async()=>{i({resolve:r,reject:o,intervalId:a})&&(clearInterval(a),clearTimeout(l))},s)})),he=i=>new Promise(e=>{let t=new FileReader;t.readAsDataURL(i),t.onload=function(){e(t.result)}}),k=()=>tt(),fe=i=>nt(i);var be=({key:i,data:e,useZero:t=!0,shouldReturnString:n=!1})=>i.split(/\.|\[/).map(o=>o.replace(/\]$/,"")).reduce((o,l)=>{let a=t?0:void 0,d=o?.[l];if(!d)return a;if(Array.isArray(d)&&/^\d+$/.test(l)){let I=parseInt(l,10);return I>=0&&I<d.length?o[l]=d[I]:o[l]??a}else return o[l]??a},e||{})??{},Ue=(i,e=1e3)=>new Promise(t=>setTimeout(t,i*e));var Te=(i,e)=>i.filter(t=>t.key!==e.key);var T=({key:i,value:e})=>e||e===0||e===!1?{[i]:e}:{},st=(i,e)=>Math.floor(Math.random()*(e-i+1))+i,Re=()=>st(1,Number.MAX_SAFE_INTEGER),_e=(i,{debugKey:e="debugKey",timeoutDuration:t=W,shouldThrowError:n=!0,pollingInterval:s=Ie})=>(t=t<K?K:t,new Promise((r,o)=>{let l=setTimeout(()=>{a&&(clearInterval(a),n&&o(`Response could not be received from server for ${e}`)),clearTimeout(l)},t),a=setInterval(async()=>{try{await i({resolve:r,reject:o,intervalId:a})&&(clearInterval(a),clearTimeout(l))}catch(d){clearInterval(a),clearTimeout(l),o(d)}},s)}));var x=async(i,e={})=>{let{delayInSeconds:t=1,callback:n}=e,s=e.maxRetries??1;for(;s;)try{return await i()}catch(r){if(n?.(),r?.error)throw r;if(s--,s>0)await Ue(t),await x(i,{...e,maxRetries:s});else throw r}};var A=class{constructor({apiKey:e,url:t=Y.PRODUCTION,shouldReconnect:n=!0,globalMaxRetries:s=2,timeoutDuration:r=W}){this._listeners=[];this._globalMessages={};this._globalImages=[];this.ensureConnectionUUID=null;this.isWebsocketReadyState=()=>this._ws?.readyState===1;this.isInvalidAPIKey=()=>this._connectionError?.error?.code==="invalidApiKey";this.send=e=>{this._ws.send(JSON.stringify([e]))};this.uploadImage=async e=>{try{return await x(async()=>{let t=k();if(typeof e=="string"&&fe(e))return{imageURL:e,imageUUID:e,taskUUID:t,taskType:"imageUpload"};let n=typeof e=="string"?e:await he(e);return{imageURL:n,imageUUID:n,taskUUID:t,taskType:"imageUpload"}})}catch(t){throw t}};this.controlNetPreProcess=async({inputImage:e,preProcessorType:t,height:n,width:s,outputType:r,outputFormat:o,highThresholdCanny:l,lowThresholdCanny:a,includeHandsAndFaceOpenPose:d,includeCost:I,outputQuality:p,customTaskUUID:g,taskUUID:u,retry:c,includeGenerationTime:h,includePayload:m})=>{let b=c||this._globalMaxRetries,U,_=Date.now();try{return await x(async()=>{await this.ensureConnection();let R=await this.uploadImage(e);if(!R?.imageUUID)return null;let y=u||g||k(),M={inputImage:R.imageUUID,taskType:"imageControlNetPreProcess",taskUUID:y,preProcessorType:t,...T({key:"height",value:n}),...T({key:"width",value:s}),...T({key:"outputType",value:r}),...T({key:"outputFormat",value:o}),...T({key:"includeCost",value:I}),...T({key:"highThresholdCanny",value:l}),...T({key:"lowThresholdCanny",value:a}),...T({key:"includeHandsAndFaceOpenPose",value:d}),...p?{outputQuality:p}:{}};this.send({...M}),U=this.globalListener({taskUUID:y});let O=await S(({resolve:B,reject:V})=>{let v=this.getSingleMessage({taskUUID:y});if(v){if(v?.error)return V(v),!0;if(v)return B(v),!0}},{debugKey:"unprocessed-image",timeoutDuration:this._timeoutDuration});return U.destroy(),this.insertAdditionalResponse({response:O,payload:m?M:void 0,startTime:h?_:void 0}),O},{maxRetries:b,callback:()=>{U?.destroy()}})}catch(R){throw R}};this.controlNetPreprocess=async e=>this.controlNetPreProcess(e);this.requestImageToText=async({inputImage:e,includeCost:t,customTaskUUID:n,taskUUID:s,retry:r,includePayload:o,includeGenerationTime:l})=>{let a=r||this._globalMaxRetries,d,I=Date.now();try{return await x(async()=>{await this.ensureConnection();let p=e?await this.uploadImage(e):null,g=s||n||k(),u={taskUUID:g,taskType:"imageCaption",inputImage:p?.imageUUID,...T({key:"includeCost",value:t})};this.send(u),d=this.globalListener({taskUUID:g});let c=await S(({resolve:h,reject:m})=>{let b=this.getSingleMessage({taskUUID:g});if(b){if(b?.error)return m(b),!0;if(b)return delete this._globalMessages[g],h(b),!0}},{debugKey:"remove-image-background",timeoutDuration:this._timeoutDuration});return d.destroy(),this.insertAdditionalResponse({response:c,payload:o?u:void 0,startTime:l?I:void 0}),c},{maxRetries:a,callback:()=>{d?.destroy()}})}catch(p){throw p}};this.caption=async e=>this.requestImageToText(e);this.removeImageBackground=async e=>this.baseSingleRequest({payload:{...e,taskType:"imageBackgroundRemoval"},debugKey:"remove-image-background"});this.removeBackground=async e=>this.removeImageBackground(e);this.vectorize=async e=>this.baseSingleRequest({payload:{...e,taskType:"vectorize"},debugKey:"vectorize"});this.videoInference=async e=>{let{skipResponse:t,inputAudios:n,referenceVideos:s,...r}=e;try{let o=await this.baseSingleRequest({payload:{...r,...n?.length&&{inputAudios:n},...s?.length&&{referenceVideos:s},deliveryMethod:"async",taskType:"videoInference"},debugKey:"video-inference"});if(t)return o;let l=o?.taskUUID,a=e?.numberResults??1,d=new Map;return await _e(async({resolve:I,reject:p})=>{try{let g=await this.getResponse({taskUUID:l});for(let c of g||[])c.videoUUID&&d.set(c.videoUUID,c);return d.size===a?(I(Array.from(d.values())),!0):!1}catch(g){return p(g),!0}},{debugKey:"async-response",pollingInterval:2*1e3,timeoutDuration:10*60*1e3}),Array.from(d.values())}catch(o){throw o}};this.getResponse=async e=>{let t=e.taskUUID;return this.baseSingleRequest({payload:{...e,customTaskUUID:t,taskType:"getResponse"},isMultiple:!0,debugKey:"async-results"})};this.upscaleGan=async({inputImage:e,upscaleFactor:t,outputType:n,outputFormat:s,includeCost:r,outputQuality:o,customTaskUUID:l,taskUUID:a,retry:d,includeGenerationTime:I,includePayload:p})=>{let g=d||this._globalMaxRetries,u,c=Date.now();try{return await x(async()=>{await this.ensureConnection();let h;h=await this.uploadImage(e);let m=a||l||k(),b={taskUUID:m,inputImage:h?.imageUUID,taskType:"imageUpscale",upscaleFactor:t,...T({key:"includeCost",value:r}),...n?{outputType:n}:{},...o?{outputQuality:o}:{},...s?{outputFormat:s}:{}};this.send(b),u=this.globalListener({taskUUID:m});let U=await S(({resolve:_,reject:R})=>{let y=this.getSingleMessage({taskUUID:m});if(y){if(y?.error)return R(y),!0;if(y)return delete this._globalMessages[m],_(y),!0}},{debugKey:"upscale-gan",timeoutDuration:this._timeoutDuration});return u.destroy(),this.insertAdditionalResponse({response:U,payload:p?b:void 0,startTime:I?c:void 0}),U},{maxRetries:g,callback:()=>{u?.destroy()}})}catch(h){throw h}};this.upscale=async e=>this.upscaleGan(e);this.enhancePrompt=async({prompt:e,promptMaxLength:t=380,promptVersions:n=1,includeCost:s,customTaskUUID:r,taskUUID:o,retry:l,includeGenerationTime:a,includePayload:d})=>{let I=l||this._globalMaxRetries,p,g=Date.now();try{return await x(async()=>{await this.ensureConnection();let u=o||r||k(),c={prompt:e,taskUUID:u,promptMaxLength:t,promptVersions:n,...T({key:"includeCost",value:s}),taskType:"promptEnhance"};this.send(c),p=this.globalListener({taskUUID:u});let h=await S(({resolve:m,reject:b})=>{let U=this._globalMessages[u];if(U?.error)return b(U),!0;if(U?.length>=n)return delete this._globalMessages[u],m(U),!0},{debugKey:"enhance-prompt",timeoutDuration:this._timeoutDuration});return p.destroy(),this.insertAdditionalResponse({response:h,payload:d?c:void 0,startTime:a?g:void 0}),h},{maxRetries:I,callback:()=>{p?.destroy()}})}catch(u){throw u}};this.promptEnhance=async e=>this.enhancePrompt(e);this.modelUpload=async e=>{let{onUploadStream:t,retry:n,customTaskUUID:s,taskUUID:r,...o}=e,l=n||this._globalMaxRetries,a;try{return await x(async()=>{await this.ensureConnection();let d=r||s||k();this.send({...o,taskUUID:d,taskType:"modelUpload"});let I,p;return a=this.listenToUpload({taskUUID:d,onUploadStream:(u,c)=>{t?.(u,c),u?.status==="ready"?I=u:c&&(p=c)}}),await S(({resolve:u,reject:c})=>{if(I)return u(I),!0;if(p)return c(p),!1},{shouldThrowError:!1,timeoutDuration:60*60*1e3})},{maxRetries:l,callback:()=>{a?.destroy()}})}catch(d){throw d}};this.photoMaker=async(e,t)=>{let{onPartialImages:n,retry:s,customTaskUUID:r,taskUUID:o,numberResults:l,includeGenerationTime:a,includePayload:d,...I}=e,p=s||this._globalMaxRetries,g,u=[],c=0,h=Date.now();try{return await x(async()=>{await this.ensureConnection(),c++;let m=this._globalImages.filter(y=>u.includes(y.taskUUID)),b=o||r||k();u.push(b);let U=l-m.length,_={...I,...I.seed?{seed:I.seed}:{seed:Re()},...t??{},taskUUID:b,taskType:"photoMaker",numberResults:l};this.send({..._,numberResults:U}),g=this.listenToImages({onPartialImages:n,taskUUID:b,groupKey:"REQUEST_IMAGES",requestPayload:d?_:void 0,startTime:a?h:void 0});let R=await this.getSimilarImages({taskUUID:u,numberResults:l,lis:g});return g.destroy(),R},{maxRetries:p,callback:()=>{g?.destroy()}})}catch(m){if(m.taskUUID)throw m;if(c>=p)return this.handleIncompleteImages({taskUUIDs:u,error:m})}};this.modelSearch=async e=>this.baseSingleRequest({payload:{...e,taskType:"modelSearch"},debugKey:"model-search"});this.imageMasking=async e=>this.baseSingleRequest({payload:{...e,taskType:"imageMasking"},debugKey:"image-masking"});this.imageUpload=async e=>this.baseSingleRequest({payload:{...e,taskType:"imageUpload"},debugKey:"image-upload"});this.mediaStorage=async e=>this.baseSingleRequest({payload:{...e,operation:e.operation||"upload",taskType:"mediaStorage"},debugKey:"media-storage"});this.baseSingleRequest=async({payload:e,debugKey:t,isMultiple:n})=>{let{retry:s,customTaskUUID:r,taskUUID:o,includePayload:l,includeGenerationTime:a,...d}=e,I=s||this._globalMaxRetries,p,g=Date.now();try{return await x(async()=>{await this.ensureConnection();let u=o||r||k(),c={...d,taskUUID:u};this.send(c),p=this.globalListener({taskUUID:u});let h=await S(({resolve:m,reject:b})=>{let U=n?this.getMultipleMessages({taskUUID:u}):this.getSingleMessage({taskUUID:u});if(U){if(U?.error)return b(U),!0;if(U)return delete this._globalMessages[u],m(U),!0}},{debugKey:t,timeoutDuration:this._timeoutDuration});return this.insertAdditionalResponse({response:h,payload:l?c:void 0,startTime:a?g:void 0}),p.destroy(),h},{maxRetries:I,callback:()=>{p?.destroy()}})}catch(u){throw u}};this.getSingleMessage=({taskUUID:e})=>{let t=this._globalMessages[e]?.[0],n=this._globalMessages[e];return!t&&!n?null:n?.error?n:t};this.getMultipleMessages=({taskUUID:e})=>{let t=this._globalMessages[e]?.[0],n=this._globalMessages[e];return!t&&!n?null:n};this.insertAdditionalResponse=({response:e,payload:t,startTime:n})=>{if(!t&&!n)return;let s=e;s.additionalResponse={},t&&(e.additionalResponse.payload=t),n&&(e.additionalResponse.generationTime=Date.now()-n)};this.disconnect=async()=>{this._shouldReconnect=!1,this._ws?.terminate?.(),this._ws?.close?.()};this.connected=()=>this.isWebsocketReadyState()&&!!this._connectionSessionUUID;this._apiKey=e,this._url=t,this._sdkType="CLIENT",this._shouldReconnect=n,this._globalMaxRetries=s,this._timeoutDuration=r}static async initialize(e){try{let t=new this(e);return await t.ensureConnection(),t}catch(t){throw t}}addListener({lis:e,groupKey:t,taskUUID:n}){let s=l=>{let a=Array.isArray(l?.data)?l.data:[l.data],d=l?.[0]?.errors?l?.[0]?.errors:Array.isArray(l?.errors)?l.errors:[l.errors],I=a.filter(g=>(g?.taskUUID||g?.taskType)===n);if(d.filter(g=>(g?.taskUUID||g?.taskType)===n).length){e({error:{...d[0]??{}}});return}if(I.length){e({[n]:a});return}},r={key:n||k(),listener:s,groupKey:t};return this._listeners.push(r),{destroy:()=>{this._listeners=Te(this._listeners,r)}}}connect(){this._ws.onopen=e=>{this._connectionSessionUUID?this.send({taskType:"authentication",apiKey:this._apiKey,connectionSessionUUID:this._connectionSessionUUID}):this.send({apiKey:this._apiKey,taskType:"authentication"}),this.addListener({taskUUID:"authentication",lis:t=>{if(t?.error){this._connectionError=t;return}this._connectionSessionUUID=t?.authentication?.[0]?.connectionSessionUUID,this._connectionError=void 0}})},this._ws.onmessage=e=>{let t=JSON.parse(e.data);for(let n of this._listeners)if(n?.listener?.(t))return},this._ws.onclose=e=>{this.isInvalidAPIKey()}}destroy(e){ye(this._listeners,e)}listenToImages({onPartialImages:e,taskUUID:t,groupKey:n,requestPayload:s,startTime:r}){return this.addListener({taskUUID:t,lis:o=>{let l=o?.[t]?.filter(a=>a.taskUUID===t);o.error?(e?.(l,o?.error&&o),this._globalError=o):(l=l.map(a=>(this.insertAdditionalResponse({response:a,payload:s||void 0,startTime:r||void 0}),{...a})),e?.(l,o?.error&&o),this._sdkType==="CLIENT"?this._globalImages=[...this._globalImages,...(o?.[t]??[]).map(a=>(this.insertAdditionalResponse({response:a,payload:s||void 0,startTime:r||void 0}),{...a}))]:this._globalImages=[...this._globalImages,...l])},groupKey:n})}listenToUpload({onUploadStream:e,taskUUID:t}){return this.addListener({taskUUID:t,lis:n=>{let s=n?.error,r=n?.[t]?.[0],o=r?.taskUUID===t?r:null;(o||s)&&e?.(o||void 0,s)}})}globalListener({taskUUID:e}){return this.addListener({taskUUID:e,lis:t=>{if(t.error){this._globalMessages[e]=t;return}let n=be({key:e,data:t,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:e,outputFormat:t,uploadEndpoint:n,checkNSFW:s,positivePrompt:r,negativePrompt:o,seedImage:l,maskImage:a,strength:d,height:I,width:p,model:g,steps:u,scheduler:c,seed:h,CFGScale:m,clipSkip:b,usePromptWeighting:U,promptWeighting:_,numberResults:R=1,onPartialImages:y,includeCost:M,customTaskUUID:O,taskUUID:B,retry:V,refiner:v,maskMargin:f,outputQuality:$,controlNet:q,lora:X,embeddings:ee,ipAdapters:te,providerSettings:ne,outpaint:se,acceleratorOptions:re,advancedFeatures:ae,referenceImages:oe,includeGenerationTime:Ce,includePayload:Ee,...Me},Oe){let C,ie,N=[],le=0,ue=V||this._globalMaxRetries;try{await this.ensureConnection();let w=null,H=null,z=[];if(l){let D=await this.uploadImage(l);if(!D)return[];w=D.imageUUID}if(a){let D=await this.uploadImage(a);if(!D)return[];H=D.imageUUID}if(q?.length)for(let D=0;D<q.length;D++){let E=q[D],{endStep:j,startStep:L,weight:Q,guideImage:P,controlMode:Le,startStepPercentage:Pe,endStepPercentage:Ke,model:We}=E,Ge=P?await this.uploadImage(P):null;z.push({guideImage:Ge?.imageUUID,model:We,endStep:j,startStep:L,weight:Q,...T({key:"startStepPercentage",value:Pe}),...T({key:"endStepPercentage",value:Ke}),controlMode:Le||"controlnet"})}ie={taskType:"imageInference",model:g,positivePrompt:r,...o?{negativePrompt:o}:{},...I?{height:I}:{},...p?{width:p}:{},numberResults:R,...e?{outputType:e}:{},...t?{outputFormat:t}:{},...n?{uploadEndpoint:n}:{},...T({key:"checkNSFW",value:s}),...T({key:"strength",value:d}),...T({key:"CFGScale",value:m}),...T({key:"clipSkip",value:b}),...T({key:"maskMargin",value:f}),...T({key:"usePromptWeighting",value:U}),...T({key:"steps",value:u}),..._?{promptWeighting:_}:{},...h?{seed:h}:{},...c?{scheduler:c}:{},...v?{refiner:v}:{},...se?{outpaint:se}:{},...T({key:"includeCost",value:M}),...w?{seedImage:w}:{},...H?{maskImage:H}:{},...$?{outputQuality:$}:{},...z.length?{controlNet:z}:{},...X?.length?{lora:X}:{},...ee?.length?{embeddings:ee}:{},...te?.length?{ipAdapters:te}:{},...ne?{providerSettings:ne}:{},...re?{acceleratorOptions:re}:{},...ae?{advancedFeatures:ae}:{},...oe?.length?{referenceImages:oe}:{},...Me,...Oe??{}};let Ne=Date.now();return await x(async()=>{le++,C?.destroy();let D=this._globalImages.filter(P=>N.includes(P.taskUUID)),E=B||O||k();N.push(E);let j=R-D.length,L={...ie,taskUUID:E,numberResults:j};this.send(L),C=this.listenToImages({onPartialImages:y,taskUUID:E,groupKey:"REQUEST_IMAGES",requestPayload:Ee?L:void 0,startTime:Ce?Ne:void 0});let Q=await this.getSimilarImages({taskUUID:N,numberResults:R,lis:C});return C.destroy(),Q},{maxRetries:ue,callback:()=>{C?.destroy()}})}catch(w){if(le>=ue)return this.handleIncompleteImages({taskUUIDs:N,error:w});throw w}}async imageInference(e,t){return this.requestImages(e,t)}async ensureConnection(){if(this.connected()||this._url===Y.TEST)return;let t=2e3,n=200;try{if(this.isInvalidAPIKey())throw this._connectionError;return new Promise((s,r)=>{let o=0,l=30,a=k(),d,I,p=()=>{this.ensureConnectionUUID=null,clearInterval(d),clearInterval(I)};this._sdkType==="SERVER"&&(d=setInterval(async()=>{try{let g=this.connected(),u=!1;(!this.ensureConnectionUUID||a===this.ensureConnectionUUID)&&(this.ensureConnectionUUID||(this.ensureConnectionUUID=a),u=!0);let c=o%10===0&&u;g?(p(),s(!0)):o>=l?(p(),r(new Error("Retry timed out"))):(c&&this.connect(),o++)}catch(g){p(),r(g)}},t)),I=setInterval(async()=>{if(this.connected()){p(),s(!0);return}if(this.isInvalidAPIKey()){p(),r(this._connectionError);return}},n)})}catch{throw this.ensureConnectionUUID=null,this._connectionError=void 0,this._connectionError??"Could not connect to server. Ensure your API key is correct"}}async getSimilarImages({taskUUID:e,numberResults:t,shouldThrowError:n,lis:s}){return await S(({resolve:r,reject:o,intervalId:l})=>{let a=Array.isArray(e)?e:[e],d=this._globalImages.filter(I=>a.includes(I.taskUUID));if(this._globalError){let I=this._globalError;return this._globalError=void 0,clearInterval(l),o?.(I),!0}else if(d.length>=t)return clearInterval(l),this._globalImages=this._globalImages.filter(I=>!a.includes(I.taskUUID)),r([...d].slice(0,t)),!0},{debugKey:"getting images",shouldThrowError:n,timeoutDuration:this._timeoutDuration})}handleIncompleteImages({taskUUIDs:e,error:t}){let n=this._globalImages.filter(s=>e.includes(s.taskUUID));if(n.length>1)return this._globalImages=this._globalImages.filter(s=>!e.includes(s.taskUUID)),n;throw t}};var we=Qe(Se(),1),G=class extends A{constructor(e){let{shouldReconnect:t,...n}=e;super(n),this._ws=new we.default(this._url),this.connect()}};import ct from"ws";var F=class extends A{constructor(t){super(t);this._instantiated=!1;this._listeners=[];this._reconnectingIntervalId=null;this.send=t=>{this._ws.send(JSON.stringify([t]))};this.resetConnection=()=>{this._ws&&(this._listeners.forEach(t=>{t?.destroy?.()}),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 ct(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:t=>{if(t?.error){this._connectionError=t;return}this._connectionSessionUUID=t?.authentication?.[0]?.connectionSessionUUID,this._connectionError=void 0}})}),this._ws.on("message",(t,n)=>{let s=n?t:t?.toString();if(!s)return;let r=JSON.parse(s);this._listeners.forEach(o=>{o.listener(r)})}))}handleClose(){this.isInvalidAPIKey()||(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 Ae;typeof window>"u"?Ae=F:Ae=G;export{ge as EControlMode,Ye as EModelArchitecture,Xe as EModelConditioning,Ze as EModelFormat,$e as EModelType,Je as EOpenPosePreProcessor,et as EPhotoMakerEnum,me as EPreProcessor,pe as EPreProcessorGroup,Z as ETaskType,de as Environment,Ae as Runware,G as RunwareClient,F as RunwareServer,J as SdkType};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|