@runware/sdk-js 1.1.46 → 1.1.47-beta.1
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 +45 -83
- package/dist/index.d.ts +45 -83
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +19 -0
package/dist/index.d.cts
CHANGED
|
@@ -22,7 +22,7 @@ declare enum ETaskType {
|
|
|
22
22
|
AUTHENTICATION = "authentication",
|
|
23
23
|
MODEL_UPLOAD = "modelUpload",
|
|
24
24
|
MODEL_SEARCH = "modelSearch",
|
|
25
|
-
|
|
25
|
+
MEDIA_STORAGE = "mediaStorage"
|
|
26
26
|
}
|
|
27
27
|
type RunwareBaseType = {
|
|
28
28
|
apiKey: string;
|
|
@@ -32,7 +32,6 @@ type RunwareBaseType = {
|
|
|
32
32
|
timeoutDuration?: number;
|
|
33
33
|
};
|
|
34
34
|
type IOutputType = "base64Data" | "dataURI" | "URL";
|
|
35
|
-
type IDeliveryType = "sync" | "async";
|
|
36
35
|
type IOutputFormat = "JPG" | "PNG" | "WEBP";
|
|
37
36
|
type IVideoOutputFormat = "MP4" | "WEBM" | "MOV";
|
|
38
37
|
interface IAdditionalResponsePayload {
|
|
@@ -105,6 +104,7 @@ type IControlNetPreprocess = {
|
|
|
105
104
|
includeCost?: boolean;
|
|
106
105
|
outputQuality?: number;
|
|
107
106
|
customTaskUUID?: string;
|
|
107
|
+
taskUUID?: string;
|
|
108
108
|
retry?: number;
|
|
109
109
|
} & IAdditionalResponsePayload;
|
|
110
110
|
type IControlNet = IControlNetGeneral;
|
|
@@ -203,11 +203,8 @@ interface IRequestImageToText extends IAdditionalResponsePayload {
|
|
|
203
203
|
inputImage?: File | string;
|
|
204
204
|
includeCost?: boolean;
|
|
205
205
|
customTaskUUID?: string;
|
|
206
|
+
taskUUID?: string;
|
|
206
207
|
retry?: number;
|
|
207
|
-
model?: string;
|
|
208
|
-
prompts?: string[];
|
|
209
|
-
inputImages?: string[];
|
|
210
|
-
[key: string]: any;
|
|
211
208
|
}
|
|
212
209
|
interface IImageToText {
|
|
213
210
|
taskType: ETaskType;
|
|
@@ -232,6 +229,7 @@ interface IRemoveImageBackground extends IRequestImageToText {
|
|
|
232
229
|
outputQuality?: number;
|
|
233
230
|
retry?: number;
|
|
234
231
|
}
|
|
232
|
+
type InputsValue = string | Record<string, unknown>;
|
|
235
233
|
interface IRequestVideo extends IRequestImageToText {
|
|
236
234
|
outputType?: IOutputType;
|
|
237
235
|
outputFormat?: IVideoOutputFormat;
|
|
@@ -239,7 +237,7 @@ interface IRequestVideo extends IRequestImageToText {
|
|
|
239
237
|
uploadEndpoint?: string;
|
|
240
238
|
checkNSFW?: boolean;
|
|
241
239
|
includeCost?: boolean;
|
|
242
|
-
positivePrompt
|
|
240
|
+
positivePrompt?: string;
|
|
243
241
|
negativePrompt?: string;
|
|
244
242
|
model: string;
|
|
245
243
|
steps?: number;
|
|
@@ -251,6 +249,22 @@ interface IRequestVideo extends IRequestImageToText {
|
|
|
251
249
|
height?: number;
|
|
252
250
|
numberResults?: number;
|
|
253
251
|
inputAudios?: string[];
|
|
252
|
+
referenceVideos?: string[];
|
|
253
|
+
inputs?: {
|
|
254
|
+
image?: InputsValue;
|
|
255
|
+
images?: InputsValue[];
|
|
256
|
+
audio?: InputsValue;
|
|
257
|
+
audios?: InputsValue[];
|
|
258
|
+
mask?: InputsValue[];
|
|
259
|
+
reference?: InputsValue;
|
|
260
|
+
references?: InputsValue[];
|
|
261
|
+
} & {
|
|
262
|
+
[key: string]: unknown;
|
|
263
|
+
};
|
|
264
|
+
speech?: {
|
|
265
|
+
voice: string;
|
|
266
|
+
text: string;
|
|
267
|
+
};
|
|
254
268
|
skipResponse?: boolean;
|
|
255
269
|
customTaskUUID?: string;
|
|
256
270
|
retry?: number;
|
|
@@ -276,6 +290,7 @@ interface IPromptEnhancer extends IAdditionalResponsePayload {
|
|
|
276
290
|
prompt: string;
|
|
277
291
|
includeCost?: boolean;
|
|
278
292
|
customTaskUUID?: string;
|
|
293
|
+
taskUUID?: string;
|
|
279
294
|
retry?: number;
|
|
280
295
|
}
|
|
281
296
|
interface IEnhancedPrompt extends IImageToText {
|
|
@@ -287,26 +302,9 @@ interface IUpscaleGan extends IAdditionalResponsePayload {
|
|
|
287
302
|
outputFormat?: IOutputFormat;
|
|
288
303
|
includeCost?: boolean;
|
|
289
304
|
outputQuality?: number;
|
|
290
|
-
revertExtra?: boolean;
|
|
291
|
-
model?: string;
|
|
292
305
|
customTaskUUID?: string;
|
|
306
|
+
taskUUID?: string;
|
|
293
307
|
retry?: number;
|
|
294
|
-
settings?: {
|
|
295
|
-
seed?: number;
|
|
296
|
-
controlNetWeight?: number;
|
|
297
|
-
CFGScale?: number;
|
|
298
|
-
positivePrompt?: string;
|
|
299
|
-
negativePrompt?: string;
|
|
300
|
-
scheduler?: string;
|
|
301
|
-
colorFix?: boolean;
|
|
302
|
-
tileDiffusion?: boolean;
|
|
303
|
-
clipSkip?: number;
|
|
304
|
-
steps?: number;
|
|
305
|
-
strength?: number;
|
|
306
|
-
checkNSFW?: boolean;
|
|
307
|
-
[key: string]: any;
|
|
308
|
-
};
|
|
309
|
-
[key: string]: any;
|
|
310
308
|
}
|
|
311
309
|
type ReconnectingWebsocketProps = {
|
|
312
310
|
addEventListener: (type: string, listener: EventListener, options: any) => void;
|
|
@@ -421,6 +419,7 @@ type TAddModelBaseType = {
|
|
|
421
419
|
comment?: string;
|
|
422
420
|
private: boolean;
|
|
423
421
|
customTaskUUID?: string;
|
|
422
|
+
taskUUID?: string;
|
|
424
423
|
retry?: number;
|
|
425
424
|
onUploadStream?: (response?: IAddModelResponse, error?: IErrorResponse) => void;
|
|
426
425
|
};
|
|
@@ -464,6 +463,7 @@ type TPhotoMaker = {
|
|
|
464
463
|
includeCost?: boolean;
|
|
465
464
|
outputQuality?: number;
|
|
466
465
|
customTaskUUID?: string;
|
|
466
|
+
taskUUID?: string;
|
|
467
467
|
retry?: number;
|
|
468
468
|
onPartialImages?: (images: IImage[], error?: IError) => void;
|
|
469
469
|
} & IAdditionalResponsePayload;
|
|
@@ -553,36 +553,6 @@ type TModelSearch = {
|
|
|
553
553
|
} & {
|
|
554
554
|
[key: string]: any;
|
|
555
555
|
};
|
|
556
|
-
type TAudioInference = {
|
|
557
|
-
model: string;
|
|
558
|
-
positivePrompt: string;
|
|
559
|
-
negativePrompt?: string;
|
|
560
|
-
duration: number;
|
|
561
|
-
numberResults?: number;
|
|
562
|
-
outputFormat?: "MP3" | "WAV" | "FLAC" | "AAC" | "OGG";
|
|
563
|
-
outputType?: IOutputType;
|
|
564
|
-
webhookURL?: string;
|
|
565
|
-
deliveryMethod?: IDeliveryType;
|
|
566
|
-
uploadEndpoint?: string;
|
|
567
|
-
includeCost?: boolean;
|
|
568
|
-
onPartialResponse?: (images: IImage[], error?: IError) => void;
|
|
569
|
-
audioSettings?: {
|
|
570
|
-
sampleRate?: number;
|
|
571
|
-
bitrate?: number;
|
|
572
|
-
[key: string]: any;
|
|
573
|
-
};
|
|
574
|
-
providerSettings?: {
|
|
575
|
-
elevenlabs?: {
|
|
576
|
-
music?: string;
|
|
577
|
-
[key: string]: any;
|
|
578
|
-
};
|
|
579
|
-
[key: string]: any;
|
|
580
|
-
};
|
|
581
|
-
customTaskUUID?: string;
|
|
582
|
-
retry?: number;
|
|
583
|
-
} & {
|
|
584
|
-
[key: string]: any;
|
|
585
|
-
};
|
|
586
556
|
type TModel = {
|
|
587
557
|
air: string;
|
|
588
558
|
name: string;
|
|
@@ -631,27 +601,23 @@ type TImageUpload = {
|
|
|
631
601
|
customTaskUUID?: string;
|
|
632
602
|
retry?: number;
|
|
633
603
|
};
|
|
634
|
-
type
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
604
|
+
type TMediaStorage = {
|
|
605
|
+
media: string;
|
|
606
|
+
operation?: string;
|
|
607
|
+
customTaskUUID?: string;
|
|
608
|
+
retry?: number;
|
|
639
609
|
};
|
|
640
|
-
type
|
|
610
|
+
type TMediaStorageResponse = {
|
|
641
611
|
taskType: string;
|
|
642
612
|
taskUUID: string;
|
|
643
|
-
|
|
644
|
-
audioURL?: string;
|
|
645
|
-
audioBase64Data?: string;
|
|
646
|
-
audioDataURI?: string;
|
|
647
|
-
cost: number;
|
|
613
|
+
mediaUUID: string;
|
|
648
614
|
};
|
|
649
|
-
type
|
|
650
|
-
|
|
615
|
+
type TImageUploadResponse = {
|
|
616
|
+
image: string;
|
|
651
617
|
taskUUID: string;
|
|
652
|
-
|
|
618
|
+
imageUUID: number;
|
|
619
|
+
imageURL: string;
|
|
653
620
|
};
|
|
654
|
-
type IAudioResult = IAudioSyncResult | IAuidoAsyncResult;
|
|
655
621
|
type TImageMaskingResponse = {
|
|
656
622
|
taskType: string;
|
|
657
623
|
taskUUID: string;
|
|
@@ -707,32 +673,28 @@ declare class RunwareBase {
|
|
|
707
673
|
protected send: (msg: Object) => void;
|
|
708
674
|
private destroy;
|
|
709
675
|
private uploadImage;
|
|
710
|
-
private
|
|
676
|
+
private listenToImages;
|
|
711
677
|
private listenToUpload;
|
|
712
678
|
private globalListener;
|
|
713
|
-
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>;
|
|
714
|
-
controlNetPreProcess: ({ inputImage, preProcessorType, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, outputQuality, customTaskUUID, retry, includeGenerationTime, includePayload, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
715
|
-
requestImageToText: ({ inputImage, includeCost, customTaskUUID, retry, includePayload, includeGenerationTime,
|
|
679
|
+
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>;
|
|
680
|
+
controlNetPreProcess: ({ inputImage, preProcessorType, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, outputQuality, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
681
|
+
requestImageToText: ({ inputImage, includeCost, customTaskUUID, taskUUID: _taskUUID, retry, includePayload, includeGenerationTime, }: IRequestImageToText) => Promise<IImageToText>;
|
|
716
682
|
removeImageBackground: (payload: IRemoveImageBackground) => Promise<IRemoveImage>;
|
|
717
683
|
videoInference: (payload: IRequestVideo) => Promise<IVideoToImage[] | IVideoToImage>;
|
|
718
|
-
getResponse:
|
|
719
|
-
upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, outputQuality, customTaskUUID, retry, includeGenerationTime, includePayload,
|
|
720
|
-
enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, customTaskUUID, retry, includeGenerationTime, includePayload, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
|
|
684
|
+
getResponse: (payload: IAsyncResults) => Promise<IVideoToImage[]>;
|
|
685
|
+
upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, outputQuality, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IUpscaleGan) => Promise<IImage>;
|
|
686
|
+
enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
|
|
721
687
|
modelUpload: (payload: TAddModel) => Promise<any>;
|
|
722
688
|
photoMaker: (payload: TPhotoMaker, moreOptions?: Record<string, any>) => Promise<TPhotoMakerResponse[] | undefined>;
|
|
723
689
|
modelSearch: (payload: TModelSearch) => Promise<TModelSearchResponse>;
|
|
724
690
|
imageMasking: (payload: TImageMasking) => Promise<TImageMaskingResponse>;
|
|
725
691
|
imageUpload: (payload: TImageUpload) => Promise<TImageUploadResponse>;
|
|
726
|
-
|
|
692
|
+
mediaStorage: (payload: TMediaStorage) => Promise<TMediaStorageResponse>;
|
|
727
693
|
protected baseSingleRequest: <T>({ payload, debugKey, isMultiple, }: {
|
|
728
694
|
payload: Record<string, any>;
|
|
729
695
|
debugKey: string;
|
|
730
696
|
isMultiple?: boolean | undefined;
|
|
731
697
|
}) => Promise<T>;
|
|
732
|
-
protected baseSyncRequest: <T>({ payload, debugKey, }: {
|
|
733
|
-
payload: Record<string, any>;
|
|
734
|
-
debugKey: string;
|
|
735
|
-
}) => Promise<T>;
|
|
736
698
|
ensureConnection(): Promise<unknown>;
|
|
737
699
|
private getSimilarImages;
|
|
738
700
|
private getSingleMessage;
|
|
@@ -763,4 +725,4 @@ declare class RunwareServer extends RunwareBase {
|
|
|
763
725
|
|
|
764
726
|
declare let Runware: typeof RunwareClient | typeof RunwareServer;
|
|
765
727
|
|
|
766
|
-
export { EControlMode, EModelArchitecture, EModelConditioning, EModelFormat, EModelType, EOpenPosePreProcessor, EPhotoMakerEnum, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, type GetWithPromiseAsyncCallBackType, type GetWithPromiseCallBackType, type IAddModelResponse, type IAdditionalResponsePayload, type IAsyncResults, type
|
|
728
|
+
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 UploadImageType };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ declare enum ETaskType {
|
|
|
22
22
|
AUTHENTICATION = "authentication",
|
|
23
23
|
MODEL_UPLOAD = "modelUpload",
|
|
24
24
|
MODEL_SEARCH = "modelSearch",
|
|
25
|
-
|
|
25
|
+
MEDIA_STORAGE = "mediaStorage"
|
|
26
26
|
}
|
|
27
27
|
type RunwareBaseType = {
|
|
28
28
|
apiKey: string;
|
|
@@ -32,7 +32,6 @@ type RunwareBaseType = {
|
|
|
32
32
|
timeoutDuration?: number;
|
|
33
33
|
};
|
|
34
34
|
type IOutputType = "base64Data" | "dataURI" | "URL";
|
|
35
|
-
type IDeliveryType = "sync" | "async";
|
|
36
35
|
type IOutputFormat = "JPG" | "PNG" | "WEBP";
|
|
37
36
|
type IVideoOutputFormat = "MP4" | "WEBM" | "MOV";
|
|
38
37
|
interface IAdditionalResponsePayload {
|
|
@@ -105,6 +104,7 @@ type IControlNetPreprocess = {
|
|
|
105
104
|
includeCost?: boolean;
|
|
106
105
|
outputQuality?: number;
|
|
107
106
|
customTaskUUID?: string;
|
|
107
|
+
taskUUID?: string;
|
|
108
108
|
retry?: number;
|
|
109
109
|
} & IAdditionalResponsePayload;
|
|
110
110
|
type IControlNet = IControlNetGeneral;
|
|
@@ -203,11 +203,8 @@ interface IRequestImageToText extends IAdditionalResponsePayload {
|
|
|
203
203
|
inputImage?: File | string;
|
|
204
204
|
includeCost?: boolean;
|
|
205
205
|
customTaskUUID?: string;
|
|
206
|
+
taskUUID?: string;
|
|
206
207
|
retry?: number;
|
|
207
|
-
model?: string;
|
|
208
|
-
prompts?: string[];
|
|
209
|
-
inputImages?: string[];
|
|
210
|
-
[key: string]: any;
|
|
211
208
|
}
|
|
212
209
|
interface IImageToText {
|
|
213
210
|
taskType: ETaskType;
|
|
@@ -232,6 +229,7 @@ interface IRemoveImageBackground extends IRequestImageToText {
|
|
|
232
229
|
outputQuality?: number;
|
|
233
230
|
retry?: number;
|
|
234
231
|
}
|
|
232
|
+
type InputsValue = string | Record<string, unknown>;
|
|
235
233
|
interface IRequestVideo extends IRequestImageToText {
|
|
236
234
|
outputType?: IOutputType;
|
|
237
235
|
outputFormat?: IVideoOutputFormat;
|
|
@@ -239,7 +237,7 @@ interface IRequestVideo extends IRequestImageToText {
|
|
|
239
237
|
uploadEndpoint?: string;
|
|
240
238
|
checkNSFW?: boolean;
|
|
241
239
|
includeCost?: boolean;
|
|
242
|
-
positivePrompt
|
|
240
|
+
positivePrompt?: string;
|
|
243
241
|
negativePrompt?: string;
|
|
244
242
|
model: string;
|
|
245
243
|
steps?: number;
|
|
@@ -251,6 +249,22 @@ interface IRequestVideo extends IRequestImageToText {
|
|
|
251
249
|
height?: number;
|
|
252
250
|
numberResults?: number;
|
|
253
251
|
inputAudios?: string[];
|
|
252
|
+
referenceVideos?: string[];
|
|
253
|
+
inputs?: {
|
|
254
|
+
image?: InputsValue;
|
|
255
|
+
images?: InputsValue[];
|
|
256
|
+
audio?: InputsValue;
|
|
257
|
+
audios?: InputsValue[];
|
|
258
|
+
mask?: InputsValue[];
|
|
259
|
+
reference?: InputsValue;
|
|
260
|
+
references?: InputsValue[];
|
|
261
|
+
} & {
|
|
262
|
+
[key: string]: unknown;
|
|
263
|
+
};
|
|
264
|
+
speech?: {
|
|
265
|
+
voice: string;
|
|
266
|
+
text: string;
|
|
267
|
+
};
|
|
254
268
|
skipResponse?: boolean;
|
|
255
269
|
customTaskUUID?: string;
|
|
256
270
|
retry?: number;
|
|
@@ -276,6 +290,7 @@ interface IPromptEnhancer extends IAdditionalResponsePayload {
|
|
|
276
290
|
prompt: string;
|
|
277
291
|
includeCost?: boolean;
|
|
278
292
|
customTaskUUID?: string;
|
|
293
|
+
taskUUID?: string;
|
|
279
294
|
retry?: number;
|
|
280
295
|
}
|
|
281
296
|
interface IEnhancedPrompt extends IImageToText {
|
|
@@ -287,26 +302,9 @@ interface IUpscaleGan extends IAdditionalResponsePayload {
|
|
|
287
302
|
outputFormat?: IOutputFormat;
|
|
288
303
|
includeCost?: boolean;
|
|
289
304
|
outputQuality?: number;
|
|
290
|
-
revertExtra?: boolean;
|
|
291
|
-
model?: string;
|
|
292
305
|
customTaskUUID?: string;
|
|
306
|
+
taskUUID?: string;
|
|
293
307
|
retry?: number;
|
|
294
|
-
settings?: {
|
|
295
|
-
seed?: number;
|
|
296
|
-
controlNetWeight?: number;
|
|
297
|
-
CFGScale?: number;
|
|
298
|
-
positivePrompt?: string;
|
|
299
|
-
negativePrompt?: string;
|
|
300
|
-
scheduler?: string;
|
|
301
|
-
colorFix?: boolean;
|
|
302
|
-
tileDiffusion?: boolean;
|
|
303
|
-
clipSkip?: number;
|
|
304
|
-
steps?: number;
|
|
305
|
-
strength?: number;
|
|
306
|
-
checkNSFW?: boolean;
|
|
307
|
-
[key: string]: any;
|
|
308
|
-
};
|
|
309
|
-
[key: string]: any;
|
|
310
308
|
}
|
|
311
309
|
type ReconnectingWebsocketProps = {
|
|
312
310
|
addEventListener: (type: string, listener: EventListener, options: any) => void;
|
|
@@ -421,6 +419,7 @@ type TAddModelBaseType = {
|
|
|
421
419
|
comment?: string;
|
|
422
420
|
private: boolean;
|
|
423
421
|
customTaskUUID?: string;
|
|
422
|
+
taskUUID?: string;
|
|
424
423
|
retry?: number;
|
|
425
424
|
onUploadStream?: (response?: IAddModelResponse, error?: IErrorResponse) => void;
|
|
426
425
|
};
|
|
@@ -464,6 +463,7 @@ type TPhotoMaker = {
|
|
|
464
463
|
includeCost?: boolean;
|
|
465
464
|
outputQuality?: number;
|
|
466
465
|
customTaskUUID?: string;
|
|
466
|
+
taskUUID?: string;
|
|
467
467
|
retry?: number;
|
|
468
468
|
onPartialImages?: (images: IImage[], error?: IError) => void;
|
|
469
469
|
} & IAdditionalResponsePayload;
|
|
@@ -553,36 +553,6 @@ type TModelSearch = {
|
|
|
553
553
|
} & {
|
|
554
554
|
[key: string]: any;
|
|
555
555
|
};
|
|
556
|
-
type TAudioInference = {
|
|
557
|
-
model: string;
|
|
558
|
-
positivePrompt: string;
|
|
559
|
-
negativePrompt?: string;
|
|
560
|
-
duration: number;
|
|
561
|
-
numberResults?: number;
|
|
562
|
-
outputFormat?: "MP3" | "WAV" | "FLAC" | "AAC" | "OGG";
|
|
563
|
-
outputType?: IOutputType;
|
|
564
|
-
webhookURL?: string;
|
|
565
|
-
deliveryMethod?: IDeliveryType;
|
|
566
|
-
uploadEndpoint?: string;
|
|
567
|
-
includeCost?: boolean;
|
|
568
|
-
onPartialResponse?: (images: IImage[], error?: IError) => void;
|
|
569
|
-
audioSettings?: {
|
|
570
|
-
sampleRate?: number;
|
|
571
|
-
bitrate?: number;
|
|
572
|
-
[key: string]: any;
|
|
573
|
-
};
|
|
574
|
-
providerSettings?: {
|
|
575
|
-
elevenlabs?: {
|
|
576
|
-
music?: string;
|
|
577
|
-
[key: string]: any;
|
|
578
|
-
};
|
|
579
|
-
[key: string]: any;
|
|
580
|
-
};
|
|
581
|
-
customTaskUUID?: string;
|
|
582
|
-
retry?: number;
|
|
583
|
-
} & {
|
|
584
|
-
[key: string]: any;
|
|
585
|
-
};
|
|
586
556
|
type TModel = {
|
|
587
557
|
air: string;
|
|
588
558
|
name: string;
|
|
@@ -631,27 +601,23 @@ type TImageUpload = {
|
|
|
631
601
|
customTaskUUID?: string;
|
|
632
602
|
retry?: number;
|
|
633
603
|
};
|
|
634
|
-
type
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
604
|
+
type TMediaStorage = {
|
|
605
|
+
media: string;
|
|
606
|
+
operation?: string;
|
|
607
|
+
customTaskUUID?: string;
|
|
608
|
+
retry?: number;
|
|
639
609
|
};
|
|
640
|
-
type
|
|
610
|
+
type TMediaStorageResponse = {
|
|
641
611
|
taskType: string;
|
|
642
612
|
taskUUID: string;
|
|
643
|
-
|
|
644
|
-
audioURL?: string;
|
|
645
|
-
audioBase64Data?: string;
|
|
646
|
-
audioDataURI?: string;
|
|
647
|
-
cost: number;
|
|
613
|
+
mediaUUID: string;
|
|
648
614
|
};
|
|
649
|
-
type
|
|
650
|
-
|
|
615
|
+
type TImageUploadResponse = {
|
|
616
|
+
image: string;
|
|
651
617
|
taskUUID: string;
|
|
652
|
-
|
|
618
|
+
imageUUID: number;
|
|
619
|
+
imageURL: string;
|
|
653
620
|
};
|
|
654
|
-
type IAudioResult = IAudioSyncResult | IAuidoAsyncResult;
|
|
655
621
|
type TImageMaskingResponse = {
|
|
656
622
|
taskType: string;
|
|
657
623
|
taskUUID: string;
|
|
@@ -707,32 +673,28 @@ declare class RunwareBase {
|
|
|
707
673
|
protected send: (msg: Object) => void;
|
|
708
674
|
private destroy;
|
|
709
675
|
private uploadImage;
|
|
710
|
-
private
|
|
676
|
+
private listenToImages;
|
|
711
677
|
private listenToUpload;
|
|
712
678
|
private globalListener;
|
|
713
|
-
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>;
|
|
714
|
-
controlNetPreProcess: ({ inputImage, preProcessorType, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, outputQuality, customTaskUUID, retry, includeGenerationTime, includePayload, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
715
|
-
requestImageToText: ({ inputImage, includeCost, customTaskUUID, retry, includePayload, includeGenerationTime,
|
|
679
|
+
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>;
|
|
680
|
+
controlNetPreProcess: ({ inputImage, preProcessorType, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, outputQuality, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
681
|
+
requestImageToText: ({ inputImage, includeCost, customTaskUUID, taskUUID: _taskUUID, retry, includePayload, includeGenerationTime, }: IRequestImageToText) => Promise<IImageToText>;
|
|
716
682
|
removeImageBackground: (payload: IRemoveImageBackground) => Promise<IRemoveImage>;
|
|
717
683
|
videoInference: (payload: IRequestVideo) => Promise<IVideoToImage[] | IVideoToImage>;
|
|
718
|
-
getResponse:
|
|
719
|
-
upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, outputQuality, customTaskUUID, retry, includeGenerationTime, includePayload,
|
|
720
|
-
enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, customTaskUUID, retry, includeGenerationTime, includePayload, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
|
|
684
|
+
getResponse: (payload: IAsyncResults) => Promise<IVideoToImage[]>;
|
|
685
|
+
upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, outputQuality, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IUpscaleGan) => Promise<IImage>;
|
|
686
|
+
enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, customTaskUUID, taskUUID: _taskUUID, retry, includeGenerationTime, includePayload, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
|
|
721
687
|
modelUpload: (payload: TAddModel) => Promise<any>;
|
|
722
688
|
photoMaker: (payload: TPhotoMaker, moreOptions?: Record<string, any>) => Promise<TPhotoMakerResponse[] | undefined>;
|
|
723
689
|
modelSearch: (payload: TModelSearch) => Promise<TModelSearchResponse>;
|
|
724
690
|
imageMasking: (payload: TImageMasking) => Promise<TImageMaskingResponse>;
|
|
725
691
|
imageUpload: (payload: TImageUpload) => Promise<TImageUploadResponse>;
|
|
726
|
-
|
|
692
|
+
mediaStorage: (payload: TMediaStorage) => Promise<TMediaStorageResponse>;
|
|
727
693
|
protected baseSingleRequest: <T>({ payload, debugKey, isMultiple, }: {
|
|
728
694
|
payload: Record<string, any>;
|
|
729
695
|
debugKey: string;
|
|
730
696
|
isMultiple?: boolean | undefined;
|
|
731
697
|
}) => Promise<T>;
|
|
732
|
-
protected baseSyncRequest: <T>({ payload, debugKey, }: {
|
|
733
|
-
payload: Record<string, any>;
|
|
734
|
-
debugKey: string;
|
|
735
|
-
}) => Promise<T>;
|
|
736
698
|
ensureConnection(): Promise<unknown>;
|
|
737
699
|
private getSimilarImages;
|
|
738
700
|
private getSingleMessage;
|
|
@@ -763,4 +725,4 @@ declare class RunwareServer extends RunwareBase {
|
|
|
763
725
|
|
|
764
726
|
declare let Runware: typeof RunwareClient | typeof RunwareServer;
|
|
765
727
|
|
|
766
|
-
export { EControlMode, EModelArchitecture, EModelConditioning, EModelFormat, EModelType, EOpenPosePreProcessor, EPhotoMakerEnum, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, type GetWithPromiseAsyncCallBackType, type GetWithPromiseCallBackType, type IAddModelResponse, type IAdditionalResponsePayload, type IAsyncResults, type
|
|
728
|
+
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 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 Qe=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports);var je=(l,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of qe(e))!He.call(l,s)&&s!==t&&ue(l,s,{get:()=>e[s],enumerable:!(n=Be(e,s))||n.enumerable});return l};var Je=(l,e,t)=>(t=l!=null?Ge(Ve(l)):{},je(e||!l||!l.__esModule?ue(t,"default",{value:l,enumerable:!0}):t,l));var ve=Qe((cn,xe)=>{"use strict";var ke=l=>l&&l.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=(l,e,t)=>{Object.defineProperty(e,t,{get:()=>l[t],set:n=>{l[t]=n},enumerable:!0,configurable:!0})},_e=l=>l.minReconnectionDelay+Math.random()*l.minReconnectionDelay,it=(l,e)=>{let t=e*l.reconnectionDelayGrowFactor;return t>l.maxReconnectionDelay?l.maxReconnectionDelay:t},lt=["onopen","onclose","onmessage","onerror"],ut=(l,e,t)=>{Object.keys(t).forEach(n=>{t[n].forEach(([s,r])=>{l.addEventListener(n,s,r)})}),e&<.forEach(n=>{l[n]=e[n]})},De=function(l,e,t={}){let n,s,r=0,i=0,u=!0,a={};if(!(this instanceof De))throw new TypeError("Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator");let d=at();if(Object.keys(d).filter(y=>t.hasOwnProperty(y)).forEach(y=>d[y]=t[y]),!ke(d.constructor))throw new TypeError("Invalid WebSocket constructor. Set `options.constructor`");let g=d.debug?(...y)=>console.log("RWS:",...y):()=>{},p=(y,c)=>setTimeout(()=>{let h=new Error(c);h.code=y,Array.isArray(a.error)&&a.error.forEach(([I])=>I(h)),n.onerror&&n.onerror(h)},0),o=()=>{if(g("close"),i++,g("retries count:",i),i>d.maxRetries){p("EHOSTDOWN","Too many failed connection attempts");return}r?r=it(d,r):r=_e(d),g("reconnectDelay:",r),u&&setTimeout(m,r)},m=()=>{g("connect");let y=n;n=new d.constructor(l,e),s=setTimeout(()=>{g("timeout"),n.close(),p("ETIMEDOUT","Connection timeout")},d.connectionTimeout),g("bypass properties");for(let c in n)["addEventListener","removeEventListener","close","send"].indexOf(c)<0&&ot(n,this,c);n.addEventListener("open",()=>{clearTimeout(s),g("open"),r=_e(d),g("reconnectDelay:",r),i=0}),n.addEventListener("close",o),ut(n,y,a)};g("init"),m(),this.close=(y=1e3,c="",{keepClosed:h=!1,fastClose:I=!0,delay:R=0}={})=>{if(R&&(r=R),u=!h,n.close(y,c),I){let U={code:y,reason:c,wasClean:!0};o(),Array.isArray(a.close)&&a.close.forEach(([_,b])=>{_(U),n.removeEventListener("close",_,b)}),n.onclose&&(n.onclose(U),n.onclose=null)}},this.send=y=>{n.send(y)},this.addEventListener=(y,c,h)=>{Array.isArray(a[y])?a[y].some(([I])=>I===c)||a[y].push([c,h]):a[y]=[[c,h]],n.addEventListener(y,c,h)},this.removeEventListener=(y,c,h)=>{Array.isArray(a[y])&&(a[y]=a[y].filter(([I])=>I!==c)),n.removeEventListener(y,c,h)}};xe.exports=De});var ce=(n=>(n.PRODUCTION="PRODUCTION",n.DEVELOPMENT="DEVELOPMENT",n.TEST="TEST",n))(ce||{}),J=(t=>(t.CLIENT="CLIENT",t.SERVER="SERVER",t))(J||{}),$=(c=>(c.IMAGE_INFERENCE="imageInference",c.IMAGE_UPLOAD="imageUpload",c.IMAGE_UPSCALE="imageUpscale",c.IMAGE_BACKGROUND_REMOVAL="imageBackgroundRemoval",c.VIDEO_INFERENCE="videoInference",c.GET_RESPONSE="getResponse",c.PHOTO_MAKER="photoMaker",c.IMAGE_CAPTION="imageCaption",c.IMAGE_CONTROL_NET_PRE_PROCESS="imageControlNetPreProcess",c.IMAGE_MASKING="imageMasking",c.PROMPT_ENHANCE="promptEnhance",c.AUTHENTICATION="authentication",c.MODEL_UPLOAD="modelUpload",c.MODEL_SEARCH="modelSearch",c.AUDIO_INFERENCE="audioInference",c))($||{}),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=(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))(ge||{}),$e=(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))($e||{}),ze=(t=>(t.safetensors="safetensors",t.pickletensor="pickletensor",t))(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=(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 K=6e4,P=1e3,me=100,z={PRODUCTION:"wss://ws-api.runware.ai/v1",TEST:"ws://localhost:8080"},ye=(l,e)=>{if(l==null)return;let t=l.indexOf(e);t!==-1&&l.splice(t,1)},S=(l,{debugKey:e="debugKey",timeoutDuration:t=K,shouldThrowError:n=!0,pollingInterval:s=me})=>(t=t<P?P:t,new Promise((r,i)=>{let u=setTimeout(()=>{a&&(clearInterval(a),n&&i(`Response could not be received from server for ${e}`)),clearTimeout(u)},t),a=setInterval(async()=>{l({resolve:r,reject:i,intervalId:a})&&(clearInterval(a),clearTimeout(u))},s)})),Ie=l=>new Promise(e=>{let t=new FileReader;t.readAsDataURL(l),t.onload=function(){e(t.result)}}),k=()=>tt(),Y=l=>nt(l);var he=({key:l,data:e,useZero:t=!0,shouldReturnString:n=!1})=>l.split(/\.|\[/).map(i=>i.replace(/\]$/,"")).reduce((i,u)=>{let a=t?0:void 0,d=i?.[u];if(!d)return a;if(Array.isArray(d)&&/^\d+$/.test(u)){let g=parseInt(u,10);return g>=0&&g<d.length?i[u]=d[g]:i[u]??a}else return i[u]??a},e||{})??{},be=(l,e=1e3)=>new Promise(t=>setTimeout(t,l*e));var fe=(l,e)=>l.filter(t=>t.key!==e.key);var T=({key:l,value:e})=>e||e===0||e===!1?{[l]:e}:{},st=(l,e)=>Math.floor(Math.random()*(e-l+1))+l,Ue=()=>st(1,Number.MAX_SAFE_INTEGER),Te=(l,{debugKey:e="debugKey",timeoutDuration:t=K,shouldThrowError:n=!0,pollingInterval:s=me})=>(t=t<P?P:t,new Promise((r,i)=>{let u=setTimeout(()=>{a&&(clearInterval(a),n&&i(`Response could not be received from server for ${e}`)),clearTimeout(u)},t),a=setInterval(async()=>{try{await l({resolve:r,reject:i,intervalId:a})&&(clearInterval(a),clearTimeout(u))}catch(d){clearInterval(a),clearTimeout(u),i(d)}},s)})),Re=l=>typeof l=="string"&&(l.startsWith("http:")||l.startsWith("https:"));var D=async(l,e={})=>{let{delayInSeconds:t=1,callback:n}=e,s=e.maxRetries??1;for(;s;)try{return await l()}catch(r){if(n?.(),r?.error)throw r;if(s--,s>0)await be(t),await D(l,{...e,maxRetries:s});else throw r}};var w=class{constructor({apiKey:e,url:t=z.PRODUCTION,shouldReconnect:n=!0,globalMaxRetries:s=2,timeoutDuration:r=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=e=>{this._ws.send(JSON.stringify([e]))};this.uploadImage=async e=>{try{return await D(async()=>{let t=k();if(typeof e=="string"&&Y(e))return{imageURL:e,imageUUID:e,taskUUID:t,taskType:"imageUpload"};let n=typeof e=="string"?e:await Ie(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:i,highThresholdCanny:u,lowThresholdCanny:a,includeHandsAndFaceOpenPose:d,includeCost:g,outputQuality:p,customTaskUUID:o,retry:m,includeGenerationTime:y,includePayload:c})=>{let h=m||this._globalMaxRetries,I,R=Date.now();try{return await D(async()=>{await this.ensureConnection();let U=await this.uploadImage(e);if(!U?.imageUUID)return null;let _=o||k(),b={inputImage:U.imageUUID,taskType:"imageControlNetPreProcess",taskUUID:_,preProcessorType:t,...T({key:"height",value:n}),...T({key:"width",value:s}),...T({key:"outputType",value:r}),...T({key:"outputFormat",value:i}),...T({key:"includeCost",value:g}),...T({key:"highThresholdCanny",value:u}),...T({key:"lowThresholdCanny",value:a}),...T({key:"includeHandsAndFaceOpenPose",value:d}),...p?{outputQuality:p}:{}};this.send({...b}),I=this.globalListener({taskUUID:_});let O=await S(({resolve:G,reject:B})=>{let v=this.getSingleMessage({taskUUID:_});if(v){if(v?.error)return B(v),!0;if(v)return G(v),!0}},{debugKey:"unprocessed-image",timeoutDuration:this._timeoutDuration});return I.destroy(),this.insertAdditionalResponse({response:O,payload:c?b:void 0,startTime:y?R:void 0}),O},{maxRetries:h,callback:()=>{I?.destroy()}})}catch(U){throw U}};this.requestImageToText=async({inputImage:e,includeCost:t,customTaskUUID:n,retry:s,includePayload:r,includeGenerationTime:i,inputImages:u,...a})=>{let d=s||this._globalMaxRetries,g,p=Date.now();try{return await D(async()=>{await this.ensureConnection();let o=e?await this.uploadImage(e):null,m=u?.length?await Promise.all(u.map(I=>this.uploadImage(I))):null,y=n||k(),c={taskUUID:y,taskType:"imageCaption",...o?.imageUUID?{inputImage:o.imageUUID}:{},...m?.length?{inputImages:m.map(I=>I?.imageUUID).filter(Boolean)}:{},...T({key:"includeCost",value:t}),...a};this.send(c),g=this.globalListener({taskUUID:y});let h=await S(({resolve:I,reject:R})=>{let U=this.getSingleMessage({taskUUID:y});if(U){if(U?.error)return R(U),!0;if(U)return delete this._globalMessages[y],I(U),!0}},{debugKey:"remove-image-background",timeoutDuration:this._timeoutDuration});return g.destroy(),this.insertAdditionalResponse({response:h,payload:r?c:void 0,startTime:i?p:void 0}),h},{maxRetries:d,callback:()=>{g?.destroy()}})}catch(o){throw o}};this.removeImageBackground=async e=>this.baseSingleRequest({payload:{...e,taskType:"imageBackgroundRemoval"},debugKey:"remove-image-background"});this.videoInference=async e=>{let{skipResponse:t,inputAudios:n,...s}=e;try{if(n?.length){for(let d of n)if(!Re(d)&&!Y(d))throw new Error(`Invalid audio source: "${d}". Only public URLs or media UUIDs are supported for audio.`)}let r=await this.baseSingleRequest({payload:{...s,...n?.length?{inputAudios:n}:{},deliveryMethod:"async",taskType:"videoInference"},debugKey:"video-inference"});if(t)return r;let i=r?.taskUUID,u=e?.numberResults??1,a=new Map;return await Te(async({resolve:d,reject:g})=>{try{let p=await this.getResponse({taskUUID:i});for(let m of p||[])m.videoUUID&&a.set(m.videoUUID,m);return a.size===u?(d(Array.from(a.values())),!0):!1}catch(p){return g(p),!0}},{debugKey:"async-response",pollingInterval:2*1e3,timeoutDuration:10*60*1e3}),Array.from(a.values())}catch(r){throw r}};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:i,customTaskUUID:u,retry:a,includeGenerationTime:d,includePayload:g,...p})=>{let o=a||this._globalMaxRetries,m,y=Date.now();try{return await D(async()=>{await this.ensureConnection();let c;c=await this.uploadImage(e);let h=u||k(),I={taskUUID:h,inputImage:c?.imageUUID,taskType:"imageUpscale",upscaleFactor:t,...T({key:"includeCost",value:r}),...n?{outputType:n}:{},...i?{outputQuality:i}:{},...s?{outputFormat:s}:{},...p};this.send(I),m=this.globalListener({taskUUID:h});let R=await S(({resolve:U,reject:_})=>{let b=this.getSingleMessage({taskUUID:h});if(b){if(b?.error)return _(b),!0;if(b)return delete this._globalMessages[h],U(b),!0}},{debugKey:"upscale-gan",timeoutDuration:this._timeoutDuration});return m.destroy(),this.insertAdditionalResponse({response:R,payload:g?I:void 0,startTime:d?y:void 0}),R},{maxRetries:o,callback:()=>{m?.destroy()}})}catch(c){throw c}};this.enhancePrompt=async({prompt:e,promptMaxLength:t=380,promptVersions:n=1,includeCost:s,customTaskUUID:r,retry:i,includeGenerationTime:u,includePayload:a})=>{let d=i||this._globalMaxRetries,g,p=Date.now();try{return await D(async()=>{await this.ensureConnection();let o=r||k(),m={prompt:e,taskUUID:o,promptMaxLength:t,promptVersions:n,...T({key:"includeCost",value:s}),taskType:"promptEnhance"};this.send(m),g=this.globalListener({taskUUID:o});let y=await S(({resolve:c,reject:h})=>{let I=this._globalMessages[o];if(I?.error)return h(I),!0;if(I?.length>=n)return delete this._globalMessages[o],c(I),!0},{debugKey:"enhance-prompt",timeoutDuration:this._timeoutDuration});return g.destroy(),this.insertAdditionalResponse({response:y,payload:a?m:void 0,startTime:u?p:void 0}),y},{maxRetries:d,callback:()=>{g?.destroy()}})}catch(o){throw o}};this.modelUpload=async e=>{let{onUploadStream:t,retry:n,customTaskUUID:s,...r}=e,i=n||this._globalMaxRetries,u;try{return await D(async()=>{await this.ensureConnection();let a=s||k();this.send({...r,taskUUID:a,taskType:"modelUpload"});let d,g;return u=this.listenToUpload({taskUUID:a,onUploadStream:(o,m)=>{t?.(o,m),o?.status==="ready"?d=o:m&&(g=m)}}),await S(({resolve:o,reject:m})=>{if(d)return o(d),!0;if(g)return m(g),!1},{shouldThrowError:!1,timeoutDuration:60*60*1e3})},{maxRetries:i,callback:()=>{u?.destroy()}})}catch(a){throw a}};this.photoMaker=async(e,t)=>{let{onPartialImages:n,retry:s,customTaskUUID:r,numberResults:i,includeGenerationTime:u,includePayload:a,...d}=e,g=s||this._globalMaxRetries,p,o=[],m=0,y=Date.now();try{return await D(async()=>{await this.ensureConnection(),m++;let c=this._globalImages.filter(_=>o.includes(_.taskUUID)),h=r||k();o.push(h);let I=i-c.length,R={...d,...d.seed?{seed:d.seed}:{seed:Ue()},...t??{},taskUUID:h,taskType:"photoMaker",numberResults:i};this.send({...R,numberResults:I}),p=this.listenToResponse({onPartialImages:n,taskUUID:h,groupKey:"REQUEST_IMAGES",requestPayload:a?R:void 0,startTime:u?y:void 0});let U=await this.getSimilarImages({taskUUID:o,numberResults:i,lis:p});return p.destroy(),U},{maxRetries:g,callback:()=>{p?.destroy()}})}catch(c){if(c.taskUUID)throw c;if(m>=g)return this.handleIncompleteImages({taskUUIDs:o,error:c})}};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.audioInference=async e=>{let{skipResponse:t,deliveryMethod:n="sync",...s}=e;try{return await(n==="sync"?this.baseSyncRequest:this.baseSingleRequest)({payload:{...s,numberResults:s.numberResults||1,taskType:"audioInference",deliveryMethod:n},debugKey:"audio-inference"})}catch(r){throw r}};this.baseSingleRequest=async({payload:e,debugKey:t,isMultiple:n})=>{let{retry:s,customTaskUUID:r,includePayload:i,includeGenerationTime:u,...a}=e,d=s||this._globalMaxRetries,g,p=Date.now();try{return await D(async()=>{await this.ensureConnection();let o=r||k(),m={...a,taskUUID:o};this.send(m),g=this.globalListener({taskUUID:o});let y=await S(({resolve:c,reject:h})=>{let I=n?this.getMultipleMessages({taskUUID:o}):this.getSingleMessage({taskUUID:o});if(I){if(I?.error)return h(I),!0;if(I)return delete this._globalMessages[o],c(I),!0}},{debugKey:t,timeoutDuration:this._timeoutDuration});return this.insertAdditionalResponse({response:y,payload:i?m:void 0,startTime:u?p:void 0}),g.destroy(),y},{maxRetries:d,callback:()=>{g?.destroy()}})}catch(o){throw o}};this.baseSyncRequest=async({payload:e,debugKey:t})=>{let{retry:n,customTaskUUID:s,includePayload:r,numberResults:i=1,onPartialResponse:u,includeGenerationTime:a,...d}=e,g=n||this._globalMaxRetries,p,o=[],m=0,y=Date.now();try{return await D(async()=>{await this.ensureConnection(),m++;let c=this._globalImages.filter(_=>o.includes(_.taskUUID)),h=s||k();o.push(h);let I=i-c.length,R={...d,taskUUID:h,numberResults:I};this.send(R),p=this.listenToResponse({onPartialImages:u,taskUUID:h,groupKey:"REQUEST_AUDIO",requestPayload:r?R:void 0,startTime:a?y:void 0});let U=await this.getSimilarImages({taskUUID:o,numberResults:i,lis:p,debugKey:t});return p.destroy(),U},{maxRetries:g,callback:()=>{p?.destroy()}})}catch(c){throw c}};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=u=>{let a=Array.isArray(u?.data)?u.data:[u.data],d=u?.[0]?.errors?u?.[0]?.errors:Array.isArray(u?.errors)?u.errors:[u.errors],g=a.filter(o=>(o?.taskUUID||o?.taskType)===n);if(d.filter(o=>(o?.taskUUID||o?.taskType)===n).length){e({error:{...d[0]??{}}});return}if(g.length){e({[n]:a});return}},r={key:n||k(),listener:s,groupKey:t};return this._listeners.push(r),{destroy:()=>{this._listeners=fe(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)}listenToResponse({onPartialImages:e,taskUUID:t,groupKey:n,requestPayload:s,startTime:r}){return this.addListener({taskUUID:t,lis:i=>{let u=i?.[t]?.filter(a=>a.taskUUID===t);i.error?(e?.(u,i?.error&&i),this._globalError=i):(u=u.map(a=>(this.insertAdditionalResponse({response:a,payload:s||void 0,startTime:r||void 0}),{...a})),e?.(u,i?.error&&i),this._sdkType==="CLIENT"?this._globalImages=[...this._globalImages,...(i?.[t]??[]).map(a=>(this.insertAdditionalResponse({response:a,payload:s||void 0,startTime:r||void 0}),{...a}))]:this._globalImages=[...this._globalImages,...u])},groupKey:n})}listenToUpload({onUploadStream:e,taskUUID:t}){return this.addListener({taskUUID:t,lis:n=>{let s=n?.error,r=n?.[t]?.[0],i=r?.taskUUID===t?r:null;(i||s)&&e?.(i||void 0,s)}})}globalListener({taskUUID:e}){return this.addListener({taskUUID:e,lis:t=>{if(t.error){this._globalMessages[e]=t;return}let n=he({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:i,seedImage:u,maskImage:a,strength:d,height:g,width:p,model:o,steps:m,scheduler:y,seed:c,CFGScale:h,clipSkip:I,usePromptWeighting:R,promptWeighting:U,numberResults:_=1,onPartialImages:b,includeCost:O,customTaskUUID:G,retry:B,refiner:v,maskMargin:we,outputQuality:f,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 A=null,V=null,H=[];if(u){let x=await this.uploadImage(u);if(!x)return[];A=x.imageUUID}if(a){let x=await this.uploadImage(a);if(!x)return[];V=x.imageUUID}if(q?.length)for(let x=0;x<q.length;x++){let E=q[x],{endStep:Q,startStep:N,weight:j,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:Q,startStep:N,weight:j,...T({key:"startStepPercentage",value:Pe}),...T({key:"endStepPercentage",value:Ke}),controlMode:Le||"controlnet"})}oe={taskType:"imageInference",model:o,positivePrompt:r,...i?{negativePrompt:i}:{},...g?{height:g}:{},...p?{width:p}:{},numberResults:_,...e?{outputType:e}:{},...t?{outputFormat:t}:{},...n?{uploadEndpoint:n}:{},...T({key:"checkNSFW",value:s}),...T({key:"strength",value:d}),...T({key:"CFGScale",value:h}),...T({key:"clipSkip",value:I}),...T({key:"maskMargin",value:we}),...T({key:"usePromptWeighting",value:R}),...T({key:"steps",value:m}),...U?{promptWeighting:U}:{},...c?{seed:c}:{},...y?{scheduler:y}:{},...v?{refiner:v}:{},...ne?{outpaint:ne}:{},...T({key:"includeCost",value:O}),...A?{seedImage:A}:{},...V?{maskImage:V}:{},...f?{outputQuality:f}:{},...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 D(async()=>{ie++,C?.destroy();let x=this._globalImages.filter(L=>M.includes(L.taskUUID)),E=G||k();M.push(E);let Q=_-x.length,N={...oe,taskUUID:E,numberResults:Q};this.send(N),C=this.listenToResponse({onPartialImages:b,taskUUID:E,groupKey:"REQUEST_IMAGES",requestPayload:Ee?N:void 0,startTime:Ce?Ne:void 0});let j=await this.getSimilarImages({taskUUID:M,numberResults:_,lis:C});return C.destroy(),j},{maxRetries:le,callback:()=>{C?.destroy()}})}catch(A){if(ie>=le)return this.handleIncompleteImages({taskUUIDs:M,error:A});throw A}}async ensureConnection(){if(this.connected()||this._url===z.TEST)return;let t=2e3,n=200;try{if(this.isInvalidAPIKey())throw this._connectionError;return new Promise((s,r)=>{let i=0,u=30,a=k(),d,g,p=()=>{this.ensureConnectionUUID=null,clearInterval(d),clearInterval(g)};this._sdkType==="SERVER"&&(d=setInterval(async()=>{try{let o=this.connected(),m=!1;(!this.ensureConnectionUUID||a===this.ensureConnectionUUID)&&(this.ensureConnectionUUID||(this.ensureConnectionUUID=a),m=!0);let y=i%10===0&&m;o?(p(),s(!0)):i>=u?(p(),r(new Error("Retry timed out"))):(y&&this.connect(),i++)}catch(o){p(),r(o)}},t)),g=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,debugKey:r="getting-images"}){return await S(({resolve:i,reject:u,intervalId:a})=>{let d=Array.isArray(e)?e:[e],g=this._globalImages.filter(p=>d.includes(p.taskUUID));if(this._globalError){let p=this._globalError;return this._globalError=void 0,clearInterval(a),u?.(p),!0}else if(g.length>=t)return clearInterval(a),this._globalImages=this._globalImages.filter(p=>!d.includes(p.taskUUID)),i([...g].slice(0,t)),!0},{debugKey:r,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 Se=Je(ve(),1),W=class extends w{constructor(e){let{shouldReconnect:t,...n}=e;super(n),this._ws=new Se.default(this._url),this.connect()}};import ct from"ws";var F=class extends w{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(i=>{i.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=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,Ae 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 je=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var Qe=(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 Je=(i,e,t)=>(t=i!=null?Fe(qe(i)):{},Qe(e||!i||!i.__esModule?ce(t,"default",{value:i,enumerable:!0}):t,i));var Se=je((dn,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):()=>{},m=(c,g)=>setTimeout(()=>{let h=new Error(g);h.code=c,Array.isArray(a.error)&&a.error.forEach(([b])=>b(h)),n.onerror&&n.onerror(h)},0),p=()=>{if(I("close"),o++,I("retries count:",o),o>d.maxRetries){m("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(),m("ETIMEDOUT","Connection timeout")},d.connectionTimeout),I("bypass properties");for(let g in n)["addEventListener","removeEventListener","close","send"].indexOf(g)<0&&ot(n,this,g);n.addEventListener("open",()=>{clearTimeout(s),I("open"),r=ke(d),I("reconnectDelay:",r),o=0}),n.addEventListener("close",p),ut(n,c,a)};I("init"),u(),this.close=(c=1e3,g="",{keepClosed:h=!1,fastClose:b=!0,delay:U=0}={})=>{if(U&&(r=U),l=!h,n.close(c,g),b){let R={code:c,reason:g,wasClean:!0};p(),Array.isArray(a.close)&&a.close.forEach(([_,y])=>{_(R),n.removeEventListener("close",_,y)}),n.onclose&&(n.onclose(R),n.onclose=null)}},this.send=c=>{n.send(c)},this.addEventListener=(c,g,h)=>{Array.isArray(a[c])?a[c].some(([b])=>b===g)||a[c].push([g,h]):a[c]=[[g,h]],n.addEventListener(c,g,h)},this.removeEventListener=(c,g,h)=>{Array.isArray(a[c])&&(a[c]=a[c].filter(([b])=>b!==g)),n.removeEventListener(c,g,h)}};ve.exports=xe});var de=(n=>(n.PRODUCTION="PRODUCTION",n.DEVELOPMENT="DEVELOPMENT",n.TEST="TEST",n))(de||{}),z=(t=>(t.CLIENT="CLIENT",t.SERVER="SERVER",t))(z||{}),Y=(g=>(g.IMAGE_INFERENCE="imageInference",g.IMAGE_UPLOAD="imageUpload",g.IMAGE_UPSCALE="imageUpscale",g.IMAGE_BACKGROUND_REMOVAL="imageBackgroundRemoval",g.VIDEO_INFERENCE="videoInference",g.GET_RESPONSE="getResponse",g.PHOTO_MAKER="photoMaker",g.IMAGE_CAPTION="imageCaption",g.IMAGE_CONTROL_NET_PRE_PROCESS="imageControlNetPreProcess",g.IMAGE_MASKING="imageMasking",g.PROMPT_ENHANCE="promptEnhance",g.AUTHENTICATION="authentication",g.MODEL_UPLOAD="modelUpload",g.MODEL_SEARCH="modelSearch",g.MEDIA_STORAGE="mediaStorage",g))(Y||{}),pe=(n=>(n.BALANCED="balanced",n.PROMPT="prompt",n.CONTROL_NET="controlnet",n))(pe||{}),ge=(p=>(p.canny="canny",p.depth="depth",p.mlsd="mlsd",p.normalbae="normalbae",p.openpose="openpose",p.tile="tile",p.seg="seg",p.lineart="lineart",p.lineart_anime="lineart_anime",p.shuffle="shuffle",p.scribble="scribble",p.softedge="softedge",p))(ge||{}),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||{}),ze=(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))(ze||{}),Ye=(t=>(t.safetensors="safetensors",t.pickletensor="pickletensor",t))(Ye||{}),$e=(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))($e||{}),Ze=(n=>(n.base="base",n.inpainting="inpainting",n.pix2pix="pix2pix",n))(Ze||{}),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=(m=>(m.NoStyle="No style",m.Cinematic="Cinematic",m.DisneyCharacter="Disney Character",m.DigitalArt="Digital Art",m.Photographic="Photographic",m.FantasyArt="Fantasy art",m.Neonpunk="Neonpunk",m.Enhance="Enhance",m.ComicBook="Comic book",m.Lowpoly="Lowpoly",m.LineArt="Line art",m))(et||{});import{v4 as tt,validate as nt}from"uuid";var W=6e4,K=1e3,Ie=100,$={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,_e=()=>st(1,Number.MAX_SAFE_INTEGER),Re=(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=$.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:m,customTaskUUID:p,taskUUID:u,retry:c,includeGenerationTime:g,includePayload:h})=>{let b=c||this._globalMaxRetries,U,R=Date.now();try{return await x(async()=>{await this.ensureConnection();let _=await this.uploadImage(e);if(!_?.imageUUID)return null;let y=u||p||k(),M={inputImage:_.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}),...m?{outputQuality:m}:{}};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:h?M:void 0,startTime:g?R:void 0}),O},{maxRetries:b,callback:()=>{U?.destroy()}})}catch(_){throw _}};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 m=e?await this.uploadImage(e):null,p=s||n||k(),u={taskUUID:p,taskType:"imageCaption",inputImage:m?.imageUUID,...T({key:"includeCost",value:t})};this.send(u),d=this.globalListener({taskUUID:p});let c=await S(({resolve:g,reject:h})=>{let b=this.getSingleMessage({taskUUID:p});if(b){if(b?.error)return h(b),!0;if(b)return delete this._globalMessages[p],g(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(m){throw m}};this.removeImageBackground=async e=>this.baseSingleRequest({payload:{...e,taskType:"imageBackgroundRemoval"},debugKey:"remove-image-background"});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 Re(async({resolve:I,reject:m})=>{try{let p=await this.getResponse({taskUUID:l});for(let c of p||[])c.videoUUID&&d.set(c.videoUUID,c);return d.size===a?(I(Array.from(d.values())),!0):!1}catch(p){return m(p),!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:m})=>{let p=d||this._globalMaxRetries,u,c=Date.now();try{return await x(async()=>{await this.ensureConnection();let g;g=await this.uploadImage(e);let h=a||l||k(),b={taskUUID:h,inputImage:g?.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:h});let U=await S(({resolve:R,reject:_})=>{let y=this.getSingleMessage({taskUUID:h});if(y){if(y?.error)return _(y),!0;if(y)return delete this._globalMessages[h],R(y),!0}},{debugKey:"upscale-gan",timeoutDuration:this._timeoutDuration});return u.destroy(),this.insertAdditionalResponse({response:U,payload:m?b:void 0,startTime:I?c:void 0}),U},{maxRetries:p,callback:()=>{u?.destroy()}})}catch(g){throw g}};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,m,p=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),m=this.globalListener({taskUUID:u});let g=await S(({resolve:h,reject:b})=>{let U=this._globalMessages[u];if(U?.error)return b(U),!0;if(U?.length>=n)return delete this._globalMessages[u],h(U),!0},{debugKey:"enhance-prompt",timeoutDuration:this._timeoutDuration});return m.destroy(),this.insertAdditionalResponse({response:g,payload:d?c:void 0,startTime:a?p:void 0}),g},{maxRetries:I,callback:()=>{m?.destroy()}})}catch(u){throw u}};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,m;return a=this.listenToUpload({taskUUID:d,onUploadStream:(u,c)=>{t?.(u,c),u?.status==="ready"?I=u:c&&(m=c)}}),await S(({resolve:u,reject:c})=>{if(I)return u(I),!0;if(m)return c(m),!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,m=s||this._globalMaxRetries,p,u=[],c=0,g=Date.now();try{return await x(async()=>{await this.ensureConnection(),c++;let h=this._globalImages.filter(y=>u.includes(y.taskUUID)),b=o||r||k();u.push(b);let U=l-h.length,R={...I,...I.seed?{seed:I.seed}:{seed:_e()},...t??{},taskUUID:b,taskType:"photoMaker",numberResults:l};this.send({...R,numberResults:U}),p=this.listenToImages({onPartialImages:n,taskUUID:b,groupKey:"REQUEST_IMAGES",requestPayload:d?R:void 0,startTime:a?g:void 0});let _=await this.getSimilarImages({taskUUID:u,numberResults:l,lis:p});return p.destroy(),_},{maxRetries:m,callback:()=>{p?.destroy()}})}catch(h){if(h.taskUUID)throw h;if(c>=m)return this.handleIncompleteImages({taskUUIDs:u,error:h})}};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,m,p=Date.now();try{return await x(async()=>{await this.ensureConnection();let u=o||r||k(),c={...d,taskUUID:u};this.send(c),m=this.globalListener({taskUUID:u});let g=await S(({resolve:h,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],h(U),!0}},{debugKey:t,timeoutDuration:this._timeoutDuration});return this.insertAdditionalResponse({response:g,payload:l?c:void 0,startTime:a?p:void 0}),m.destroy(),g},{maxRetries:I,callback:()=>{m?.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(p=>(p?.taskUUID||p?.taskType)===n);if(d.filter(p=>(p?.taskUUID||p?.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:m,model:p,steps:u,scheduler:c,seed:g,CFGScale:h,clipSkip:b,usePromptWeighting:U,promptWeighting:R,numberResults:_=1,onPartialImages:y,includeCost:M,customTaskUUID:O,taskUUID:B,retry:V,refiner:v,maskMargin:f,outputQuality:Z,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,j=[];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:Q,startStep:L,weight:J,guideImage:P,controlMode:Le,startStepPercentage:Pe,endStepPercentage:Ke,model:We}=E,Ge=P?await this.uploadImage(P):null;j.push({guideImage:Ge?.imageUUID,model:We,endStep:Q,startStep:L,weight:J,...T({key:"startStepPercentage",value:Pe}),...T({key:"endStepPercentage",value:Ke}),controlMode:Le||"controlnet"})}ie={taskType:"imageInference",model:p,positivePrompt:r,...o?{negativePrompt:o}:{},...I?{height:I}:{},...m?{width:m}:{},numberResults:_,...e?{outputType:e}:{},...t?{outputFormat:t}:{},...n?{uploadEndpoint:n}:{},...T({key:"checkNSFW",value:s}),...T({key:"strength",value:d}),...T({key:"CFGScale",value:h}),...T({key:"clipSkip",value:b}),...T({key:"maskMargin",value:f}),...T({key:"usePromptWeighting",value:U}),...T({key:"steps",value:u}),...R?{promptWeighting:R}:{},...g?{seed:g}:{},...c?{scheduler:c}:{},...v?{refiner:v}:{},...se?{outpaint:se}:{},...T({key:"includeCost",value:M}),...w?{seedImage:w}:{},...H?{maskImage:H}:{},...Z?{outputQuality:Z}:{},...j.length?{controlNet:j}:{},...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 Q=_-D.length,L={...ie,taskUUID:E,numberResults:Q};this.send(L),C=this.listenToImages({onPartialImages:y,taskUUID:E,groupKey:"REQUEST_IMAGES",requestPayload:Ee?L:void 0,startTime:Ce?Ne:void 0});let J=await this.getSimilarImages({taskUUID:N,numberResults:_,lis:C});return C.destroy(),J},{maxRetries:ue,callback:()=>{C?.destroy()}})}catch(w){if(le>=ue)return this.handleIncompleteImages({taskUUIDs:N,error:w});throw w}}async ensureConnection(){if(this.connected()||this._url===$.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,m=()=>{this.ensureConnectionUUID=null,clearInterval(d),clearInterval(I)};this._sdkType==="SERVER"&&(d=setInterval(async()=>{try{let p=this.connected(),u=!1;(!this.ensureConnectionUUID||a===this.ensureConnectionUUID)&&(this.ensureConnectionUUID||(this.ensureConnectionUUID=a),u=!0);let c=o%10===0&&u;p?(m(),s(!0)):o>=l?(m(),r(new Error("Retry timed out"))):(c&&this.connect(),o++)}catch(p){m(),r(p)}},t)),I=setInterval(async()=>{if(this.connected()){m(),s(!0);return}if(this.isInvalidAPIKey()){m(),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=Je(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{pe as EControlMode,$e as EModelArchitecture,Xe as EModelConditioning,Ye as EModelFormat,Ze as EModelType,ze as EOpenPosePreProcessor,et as EPhotoMakerEnum,me as EPreProcessor,ge as EPreProcessorGroup,Y as ETaskType,de as Environment,Ae as Runware,G as RunwareClient,F as RunwareServer,z as SdkType};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|