@runware/sdk-js 1.1.15 → 1.1.17-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.mjs CHANGED
@@ -21,6 +21,18 @@ var __spreadValues = (a, b) => {
21
21
  return a;
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __objRest = (source, exclude) => {
25
+ var target = {};
26
+ for (var prop in source)
27
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
28
+ target[prop] = source[prop];
29
+ if (source != null && __getOwnPropSymbols)
30
+ for (var prop of __getOwnPropSymbols(source)) {
31
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
32
+ target[prop] = source[prop];
33
+ }
34
+ return target;
35
+ };
24
36
  var __commonJS = (cb, mod) => function __require() {
25
37
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
26
38
  };
@@ -240,50 +252,50 @@ var EControlMode = /* @__PURE__ */ ((EControlMode2) => {
240
252
  EControlMode2["CONTROL_NET"] = "controlnet";
241
253
  return EControlMode2;
242
254
  })(EControlMode || {});
243
- var EPreProcessorGroup = /* @__PURE__ */ ((EPreProcessorGroup3) => {
244
- EPreProcessorGroup3["canny"] = "canny";
245
- EPreProcessorGroup3["depth"] = "depth";
246
- EPreProcessorGroup3["mlsd"] = "mlsd";
247
- EPreProcessorGroup3["normalbae"] = "normalbae";
248
- EPreProcessorGroup3["openpose"] = "openpose";
249
- EPreProcessorGroup3["tile"] = "tile";
250
- EPreProcessorGroup3["seg"] = "seg";
251
- EPreProcessorGroup3["lineart"] = "lineart";
252
- EPreProcessorGroup3["lineart_anime"] = "lineart_anime";
253
- EPreProcessorGroup3["shuffle"] = "shuffle";
254
- EPreProcessorGroup3["scribble"] = "scribble";
255
- EPreProcessorGroup3["softedge"] = "softedge";
256
- return EPreProcessorGroup3;
255
+ var EPreProcessorGroup = /* @__PURE__ */ ((EPreProcessorGroup2) => {
256
+ EPreProcessorGroup2["canny"] = "canny";
257
+ EPreProcessorGroup2["depth"] = "depth";
258
+ EPreProcessorGroup2["mlsd"] = "mlsd";
259
+ EPreProcessorGroup2["normalbae"] = "normalbae";
260
+ EPreProcessorGroup2["openpose"] = "openpose";
261
+ EPreProcessorGroup2["tile"] = "tile";
262
+ EPreProcessorGroup2["seg"] = "seg";
263
+ EPreProcessorGroup2["lineart"] = "lineart";
264
+ EPreProcessorGroup2["lineart_anime"] = "lineart_anime";
265
+ EPreProcessorGroup2["shuffle"] = "shuffle";
266
+ EPreProcessorGroup2["scribble"] = "scribble";
267
+ EPreProcessorGroup2["softedge"] = "softedge";
268
+ return EPreProcessorGroup2;
257
269
  })(EPreProcessorGroup || {});
258
- var EPreProcessor = /* @__PURE__ */ ((EPreProcessor3) => {
259
- EPreProcessor3["canny"] = "canny";
260
- EPreProcessor3["depth_leres"] = "depth_leres";
261
- EPreProcessor3["depth_midas"] = "depth_midas";
262
- EPreProcessor3["depth_zoe"] = "depth_zoe";
263
- EPreProcessor3["inpaint_global_harmonious"] = "inpaint_global_harmonious";
264
- EPreProcessor3["lineart_anime"] = "lineart_anime";
265
- EPreProcessor3["lineart_coarse"] = "lineart_coarse";
266
- EPreProcessor3["lineart_realistic"] = "lineart_realistic";
267
- EPreProcessor3["lineart_standard"] = "lineart_standard";
268
- EPreProcessor3["mlsd"] = "mlsd";
269
- EPreProcessor3["normal_bae"] = "normal_bae";
270
- EPreProcessor3["scribble_hed"] = "scribble_hed";
271
- EPreProcessor3["scribble_pidinet"] = "scribble_pidinet";
272
- EPreProcessor3["seg_ofade20k"] = "seg_ofade20k";
273
- EPreProcessor3["seg_ofcoco"] = "seg_ofcoco";
274
- EPreProcessor3["seg_ufade20k"] = "seg_ufade20k";
275
- EPreProcessor3["shuffle"] = "shuffle";
276
- EPreProcessor3["softedge_hed"] = "softedge_hed";
277
- EPreProcessor3["softedge_hedsafe"] = "softedge_hedsafe";
278
- EPreProcessor3["softedge_pidinet"] = "softedge_pidinet";
279
- EPreProcessor3["softedge_pidisafe"] = "softedge_pidisafe";
280
- EPreProcessor3["tile_gaussian"] = "tile_gaussian";
281
- EPreProcessor3["openpose"] = "openpose";
282
- EPreProcessor3["openpose_face"] = "openpose_face";
283
- EPreProcessor3["openpose_faceonly"] = "openpose_faceonly";
284
- EPreProcessor3["openpose_full"] = "openpose_full";
285
- EPreProcessor3["openpose_hand"] = "openpose_hand";
286
- return EPreProcessor3;
270
+ var EPreProcessor = /* @__PURE__ */ ((EPreProcessor2) => {
271
+ EPreProcessor2["canny"] = "canny";
272
+ EPreProcessor2["depth_leres"] = "depth_leres";
273
+ EPreProcessor2["depth_midas"] = "depth_midas";
274
+ EPreProcessor2["depth_zoe"] = "depth_zoe";
275
+ EPreProcessor2["inpaint_global_harmonious"] = "inpaint_global_harmonious";
276
+ EPreProcessor2["lineart_anime"] = "lineart_anime";
277
+ EPreProcessor2["lineart_coarse"] = "lineart_coarse";
278
+ EPreProcessor2["lineart_realistic"] = "lineart_realistic";
279
+ EPreProcessor2["lineart_standard"] = "lineart_standard";
280
+ EPreProcessor2["mlsd"] = "mlsd";
281
+ EPreProcessor2["normal_bae"] = "normal_bae";
282
+ EPreProcessor2["scribble_hed"] = "scribble_hed";
283
+ EPreProcessor2["scribble_pidinet"] = "scribble_pidinet";
284
+ EPreProcessor2["seg_ofade20k"] = "seg_ofade20k";
285
+ EPreProcessor2["seg_ofcoco"] = "seg_ofcoco";
286
+ EPreProcessor2["seg_ufade20k"] = "seg_ufade20k";
287
+ EPreProcessor2["shuffle"] = "shuffle";
288
+ EPreProcessor2["softedge_hed"] = "softedge_hed";
289
+ EPreProcessor2["softedge_hedsafe"] = "softedge_hedsafe";
290
+ EPreProcessor2["softedge_pidinet"] = "softedge_pidinet";
291
+ EPreProcessor2["softedge_pidisafe"] = "softedge_pidisafe";
292
+ EPreProcessor2["tile_gaussian"] = "tile_gaussian";
293
+ EPreProcessor2["openpose"] = "openpose";
294
+ EPreProcessor2["openpose_face"] = "openpose_face";
295
+ EPreProcessor2["openpose_faceonly"] = "openpose_faceonly";
296
+ EPreProcessor2["openpose_full"] = "openpose_full";
297
+ EPreProcessor2["openpose_hand"] = "openpose_hand";
298
+ return EPreProcessor2;
287
299
  })(EPreProcessor || {});
288
300
  var EOpenPosePreProcessor = /* @__PURE__ */ ((EOpenPosePreProcessor2) => {
289
301
  EOpenPosePreProcessor2["openpose"] = "openpose";
@@ -322,8 +334,7 @@ var getIntervalWithPromise = (callback, {
322
334
  if (intervalId) {
323
335
  clearInterval(intervalId);
324
336
  if (shouldThrowError) {
325
- reject(`Message could not be received for ${debugKey}`);
326
- console.error("Message could not be received for ", debugKey);
337
+ reject(`Response could not be received from server for ${debugKey}`);
327
338
  }
328
339
  }
329
340
  clearTimeout(timeoutId);
@@ -414,7 +425,13 @@ var asyncRetry = async (apiCall, options = {}) => {
414
425
 
415
426
  // Runware/Runware-base.ts
416
427
  var RunwareBase = class {
417
- constructor({ apiKey, url = BASE_RUNWARE_URLS.PRODUCTION }) {
428
+ constructor({
429
+ apiKey,
430
+ url = BASE_RUNWARE_URLS.PRODUCTION,
431
+ shouldReconnect = true,
432
+ globalMaxRetries = 2,
433
+ timeOutDuration = TIMEOUT_DURATION
434
+ }) {
418
435
  this._listeners = [];
419
436
  // _globalMessages: any[] = [];
420
437
  this._globalMessages = {};
@@ -462,51 +479,68 @@ var RunwareBase = class {
462
479
  lowThresholdCanny,
463
480
  includeHandsAndFaceOpenPose,
464
481
  includeCost,
465
- customTaskUUID
482
+ customTaskUUID,
483
+ retry
466
484
  }) => {
485
+ const totalRetry = retry || this._globalMaxRetries;
486
+ let lis = void 0;
467
487
  try {
468
- const image = await this.uploadImage(inputImage);
469
- if (!(image == null ? void 0 : image.imageUUID))
470
- return null;
471
- const taskUUID = customTaskUUID || getUUID();
472
- this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
473
- inputImage: image.imageUUID,
474
- taskType: "imageControlNetPreProcess" /* IMAGE_CONTROL_NET_PRE_PROCESS */,
475
- taskUUID,
476
- preProcessor
477
- }, evaluateNonTrue({ key: "height", value: height })), evaluateNonTrue({ key: "width", value: width })), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
478
- key: "highThresholdCanny",
479
- value: highThresholdCanny
480
- })), evaluateNonTrue({
481
- key: "lowThresholdCanny",
482
- value: lowThresholdCanny
483
- })), evaluateNonTrue({
484
- key: "includeHandsAndFaceOpenPose",
485
- value: includeHandsAndFaceOpenPose
486
- })));
487
- const lis = this.globalListener({
488
- taskUUID
489
- });
490
- const guideImage = await getIntervalWithPromise(
491
- ({ resolve, reject }) => {
492
- const uploadedImage = this.getSingleMessage({
488
+ return await asyncRetry(
489
+ async () => {
490
+ await this.ensureConnection();
491
+ const image = await this.uploadImage(inputImage);
492
+ if (!(image == null ? void 0 : image.imageUUID))
493
+ return null;
494
+ const taskUUID = customTaskUUID || getUUID();
495
+ this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
496
+ inputImage: image.imageUUID,
497
+ taskType: "imageControlNetPreProcess" /* IMAGE_CONTROL_NET_PRE_PROCESS */,
498
+ taskUUID,
499
+ preProcessor
500
+ }, evaluateNonTrue({ key: "height", value: height })), evaluateNonTrue({ key: "width", value: width })), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
501
+ key: "highThresholdCanny",
502
+ value: highThresholdCanny
503
+ })), evaluateNonTrue({
504
+ key: "lowThresholdCanny",
505
+ value: lowThresholdCanny
506
+ })), evaluateNonTrue({
507
+ key: "includeHandsAndFaceOpenPose",
508
+ value: includeHandsAndFaceOpenPose
509
+ })));
510
+ lis = this.globalListener({
493
511
  taskUUID
494
512
  });
495
- if (!uploadedImage)
496
- return;
497
- if (uploadedImage == null ? void 0 : uploadedImage.error) {
498
- reject(uploadedImage);
499
- return true;
500
- }
501
- if (uploadedImage) {
502
- resolve(uploadedImage);
503
- return true;
504
- }
513
+ const guideImage = await getIntervalWithPromise(
514
+ ({ resolve, reject }) => {
515
+ const uploadedImage = this.getSingleMessage({
516
+ taskUUID
517
+ });
518
+ if (!uploadedImage)
519
+ return;
520
+ if (uploadedImage == null ? void 0 : uploadedImage.error) {
521
+ reject(uploadedImage);
522
+ return true;
523
+ }
524
+ if (uploadedImage) {
525
+ resolve(uploadedImage);
526
+ return true;
527
+ }
528
+ },
529
+ {
530
+ debugKey: "unprocessed-image",
531
+ timeOutDuration: this._timeOutDuration
532
+ }
533
+ );
534
+ lis.destroy();
535
+ return guideImage;
505
536
  },
506
- { debugKey: "unprocessed-image" }
537
+ {
538
+ maxRetries: totalRetry,
539
+ callback: () => {
540
+ lis == null ? void 0 : lis.destroy();
541
+ }
542
+ }
507
543
  );
508
- lis.destroy();
509
- return guideImage;
510
544
  } catch (e) {
511
545
  throw e;
512
546
  }
@@ -514,43 +548,57 @@ var RunwareBase = class {
514
548
  this.requestImageToText = async ({
515
549
  inputImage,
516
550
  includeCost,
517
- customTaskUUID
551
+ customTaskUUID,
552
+ retry
518
553
  }) => {
554
+ const totalRetry = retry || this._globalMaxRetries;
555
+ let lis = void 0;
519
556
  try {
520
- await this.ensureConnection();
521
- return await asyncRetry(async () => {
522
- const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
523
- const taskUUID = customTaskUUID || getUUID();
524
- this.send(__spreadValues({
525
- taskUUID,
526
- taskType: "imageCaption" /* IMAGE_CAPTION */,
527
- inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
528
- }, evaluateNonTrue({ key: "includeCost", value: includeCost })));
529
- const lis = this.globalListener({
530
- taskUUID
531
- });
532
- const response = await getIntervalWithPromise(
533
- ({ resolve, reject }) => {
534
- const newReverseClip = this.getSingleMessage({
535
- taskUUID
536
- });
537
- if (!newReverseClip)
538
- return;
539
- if (newReverseClip == null ? void 0 : newReverseClip.error) {
540
- reject(newReverseClip);
541
- return true;
542
- }
543
- if (newReverseClip) {
544
- delete this._globalMessages[taskUUID];
545
- resolve(newReverseClip);
546
- return true;
557
+ return await asyncRetry(
558
+ async () => {
559
+ await this.ensureConnection();
560
+ const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
561
+ const taskUUID = customTaskUUID || getUUID();
562
+ this.send(__spreadValues({
563
+ taskUUID,
564
+ taskType: "imageCaption" /* IMAGE_CAPTION */,
565
+ inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
566
+ }, evaluateNonTrue({ key: "includeCost", value: includeCost })));
567
+ lis = this.globalListener({
568
+ taskUUID
569
+ });
570
+ const response = await getIntervalWithPromise(
571
+ ({ resolve, reject }) => {
572
+ const newReverseClip = this.getSingleMessage({
573
+ taskUUID
574
+ });
575
+ if (!newReverseClip)
576
+ return;
577
+ if (newReverseClip == null ? void 0 : newReverseClip.error) {
578
+ reject(newReverseClip);
579
+ return true;
580
+ }
581
+ if (newReverseClip) {
582
+ delete this._globalMessages[taskUUID];
583
+ resolve(newReverseClip);
584
+ return true;
585
+ }
586
+ },
587
+ {
588
+ debugKey: "remove-image-background",
589
+ timeOutDuration: this._timeOutDuration
547
590
  }
548
- },
549
- { debugKey: "remove-image-background" }
550
- );
551
- lis.destroy();
552
- return response;
553
- });
591
+ );
592
+ lis.destroy();
593
+ return response;
594
+ },
595
+ {
596
+ maxRetries: totalRetry,
597
+ callback: () => {
598
+ lis == null ? void 0 : lis.destroy();
599
+ }
600
+ }
601
+ );
554
602
  } catch (e) {
555
603
  throw e;
556
604
  }
@@ -567,53 +615,70 @@ var RunwareBase = class {
567
615
  alphaMattingBackgroundThreshold,
568
616
  alphaMattingErodeSize,
569
617
  includeCost,
570
- customTaskUUID
618
+ customTaskUUID,
619
+ retry
571
620
  }) => {
621
+ const totalRetry = retry || this._globalMaxRetries;
622
+ let lis = void 0;
572
623
  try {
573
- await this.ensureConnection();
574
- return await asyncRetry(async () => {
575
- const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
576
- const taskUUID = customTaskUUID || getUUID();
577
- this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
578
- taskType: "imageBackgroundRemoval" /* IMAGE_BACKGROUND_REMOVAL */,
579
- taskUUID,
580
- inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
581
- }, evaluateNonTrue({ key: "rgba", value: rgba })), evaluateNonTrue({
582
- key: "postProcessMask",
583
- value: postProcessMask
584
- })), evaluateNonTrue({ key: "returnOnlyMask", value: returnOnlyMask })), evaluateNonTrue({ key: "alphaMatting", value: alphaMatting })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
585
- key: "alphaMattingForegroundThreshold",
586
- value: alphaMattingForegroundThreshold
587
- })), evaluateNonTrue({
588
- key: "alphaMattingBackgroundThreshold",
589
- value: alphaMattingBackgroundThreshold
590
- })), evaluateNonTrue({
591
- key: "alphaMattingErodeSize",
592
- value: alphaMattingErodeSize
593
- })), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })));
594
- const lis = this.globalListener({
595
- taskUUID
596
- });
597
- const response = await getIntervalWithPromise(
598
- ({ resolve, reject }) => {
599
- const newRemoveBackground = this.getSingleMessage({ taskUUID });
600
- if (!newRemoveBackground)
601
- return;
602
- if (newRemoveBackground == null ? void 0 : newRemoveBackground.error) {
603
- reject(newRemoveBackground);
604
- return true;
605
- }
606
- if (newRemoveBackground) {
607
- delete this._globalMessages[taskUUID];
608
- resolve(newRemoveBackground);
609
- return true;
624
+ return await asyncRetry(
625
+ async () => {
626
+ await this.ensureConnection();
627
+ const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
628
+ const taskUUID = customTaskUUID || getUUID();
629
+ this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
630
+ taskType: "imageBackgroundRemoval" /* IMAGE_BACKGROUND_REMOVAL */,
631
+ taskUUID,
632
+ inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
633
+ }, evaluateNonTrue({ key: "rgba", value: rgba })), evaluateNonTrue({
634
+ key: "postProcessMask",
635
+ value: postProcessMask
636
+ })), evaluateNonTrue({
637
+ key: "returnOnlyMask",
638
+ value: returnOnlyMask
639
+ })), evaluateNonTrue({ key: "alphaMatting", value: alphaMatting })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
640
+ key: "alphaMattingForegroundThreshold",
641
+ value: alphaMattingForegroundThreshold
642
+ })), evaluateNonTrue({
643
+ key: "alphaMattingBackgroundThreshold",
644
+ value: alphaMattingBackgroundThreshold
645
+ })), evaluateNonTrue({
646
+ key: "alphaMattingErodeSize",
647
+ value: alphaMattingErodeSize
648
+ })), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })));
649
+ lis = this.globalListener({
650
+ taskUUID
651
+ });
652
+ const response = await getIntervalWithPromise(
653
+ ({ resolve, reject }) => {
654
+ const newRemoveBackground = this.getSingleMessage({ taskUUID });
655
+ if (!newRemoveBackground)
656
+ return;
657
+ if (newRemoveBackground == null ? void 0 : newRemoveBackground.error) {
658
+ reject(newRemoveBackground);
659
+ return true;
660
+ }
661
+ if (newRemoveBackground) {
662
+ delete this._globalMessages[taskUUID];
663
+ resolve(newRemoveBackground);
664
+ return true;
665
+ }
666
+ },
667
+ {
668
+ debugKey: "remove-image-background",
669
+ timeOutDuration: this._timeOutDuration
610
670
  }
611
- },
612
- { debugKey: "remove-image-background" }
613
- );
614
- lis.destroy();
615
- return response;
616
- });
671
+ );
672
+ lis.destroy();
673
+ return response;
674
+ },
675
+ {
676
+ maxRetries: totalRetry,
677
+ callback: () => {
678
+ lis == null ? void 0 : lis.destroy();
679
+ }
680
+ }
681
+ );
617
682
  } catch (e) {
618
683
  throw e;
619
684
  }
@@ -624,43 +689,54 @@ var RunwareBase = class {
624
689
  outputType,
625
690
  outputFormat,
626
691
  includeCost,
627
- customTaskUUID
692
+ customTaskUUID,
693
+ retry
628
694
  }) => {
695
+ const totalRetry = retry || this._globalMaxRetries;
696
+ let lis = void 0;
629
697
  try {
630
- await this.ensureConnection();
631
- return await asyncRetry(async () => {
632
- let imageUploaded;
633
- imageUploaded = await this.uploadImage(inputImage);
634
- const taskUUID = customTaskUUID || getUUID();
635
- this.send(__spreadValues(__spreadValues(__spreadValues({
636
- taskUUID,
637
- inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
638
- taskType: "imageUpscale" /* IMAGE_UPSCALE */,
639
- upscaleFactor
640
- }, evaluateNonTrue({ key: "includeCost", value: includeCost })), outputType ? { outputType } : {}), outputFormat ? { outputFormat } : {}));
641
- const lis = this.globalListener({
642
- taskUUID
643
- });
644
- const response = await getIntervalWithPromise(
645
- ({ resolve, reject }) => {
646
- const newUpscaleGan = this.getSingleMessage({ taskUUID });
647
- if (!newUpscaleGan)
648
- return;
649
- if (newUpscaleGan == null ? void 0 : newUpscaleGan.error) {
650
- reject(newUpscaleGan);
651
- return true;
652
- }
653
- if (newUpscaleGan) {
654
- delete this._globalMessages[taskUUID];
655
- resolve(newUpscaleGan);
656
- return true;
657
- }
658
- },
659
- { debugKey: "upscale-gan" }
660
- );
661
- lis.destroy();
662
- return response;
663
- });
698
+ return await asyncRetry(
699
+ async () => {
700
+ await this.ensureConnection();
701
+ let imageUploaded;
702
+ imageUploaded = await this.uploadImage(inputImage);
703
+ const taskUUID = customTaskUUID || getUUID();
704
+ this.send(__spreadValues(__spreadValues(__spreadValues({
705
+ taskUUID,
706
+ inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
707
+ taskType: "imageUpscale" /* IMAGE_UPSCALE */,
708
+ upscaleFactor
709
+ }, evaluateNonTrue({ key: "includeCost", value: includeCost })), outputType ? { outputType } : {}), outputFormat ? { outputFormat } : {}));
710
+ lis = this.globalListener({
711
+ taskUUID
712
+ });
713
+ const response = await getIntervalWithPromise(
714
+ ({ resolve, reject }) => {
715
+ const newUpscaleGan = this.getSingleMessage({ taskUUID });
716
+ if (!newUpscaleGan)
717
+ return;
718
+ if (newUpscaleGan == null ? void 0 : newUpscaleGan.error) {
719
+ reject(newUpscaleGan);
720
+ return true;
721
+ }
722
+ if (newUpscaleGan) {
723
+ delete this._globalMessages[taskUUID];
724
+ resolve(newUpscaleGan);
725
+ return true;
726
+ }
727
+ },
728
+ { debugKey: "upscale-gan", timeOutDuration: this._timeOutDuration }
729
+ );
730
+ lis.destroy();
731
+ return response;
732
+ },
733
+ {
734
+ maxRetries: totalRetry,
735
+ callback: () => {
736
+ lis == null ? void 0 : lis.destroy();
737
+ }
738
+ }
739
+ );
664
740
  } catch (e) {
665
741
  throw e;
666
742
  }
@@ -670,41 +746,55 @@ var RunwareBase = class {
670
746
  promptMaxLength = 380,
671
747
  promptVersions = 1,
672
748
  includeCost,
673
- customTaskUUID
749
+ customTaskUUID,
750
+ retry
674
751
  }) => {
752
+ const totalRetry = retry || this._globalMaxRetries;
753
+ let lis = void 0;
675
754
  try {
676
- await this.ensureConnection();
677
- return await asyncRetry(async () => {
678
- const taskUUID = customTaskUUID || getUUID();
679
- this.send(__spreadProps(__spreadValues({
680
- prompt,
681
- taskUUID,
682
- promptMaxLength,
683
- promptVersions
684
- }, evaluateNonTrue({ key: "includeCost", value: includeCost })), {
685
- taskType: "promptEnhance" /* PROMPT_ENHANCE */
686
- }));
687
- const lis = this.globalListener({
688
- taskUUID
689
- });
690
- const response = await getIntervalWithPromise(
691
- ({ resolve, reject }) => {
692
- const reducedPrompt = this._globalMessages[taskUUID];
693
- if (reducedPrompt == null ? void 0 : reducedPrompt.error) {
694
- reject(reducedPrompt);
695
- return true;
696
- }
697
- if ((reducedPrompt == null ? void 0 : reducedPrompt.length) >= promptVersions) {
698
- delete this._globalMessages[taskUUID];
699
- resolve(reducedPrompt);
700
- return true;
755
+ return await asyncRetry(
756
+ async () => {
757
+ await this.ensureConnection();
758
+ const taskUUID = customTaskUUID || getUUID();
759
+ this.send(__spreadProps(__spreadValues({
760
+ prompt,
761
+ taskUUID,
762
+ promptMaxLength,
763
+ promptVersions
764
+ }, evaluateNonTrue({ key: "includeCost", value: includeCost })), {
765
+ taskType: "promptEnhance" /* PROMPT_ENHANCE */
766
+ }));
767
+ lis = this.globalListener({
768
+ taskUUID
769
+ });
770
+ const response = await getIntervalWithPromise(
771
+ ({ resolve, reject }) => {
772
+ const reducedPrompt = this._globalMessages[taskUUID];
773
+ if (reducedPrompt == null ? void 0 : reducedPrompt.error) {
774
+ reject(reducedPrompt);
775
+ return true;
776
+ }
777
+ if ((reducedPrompt == null ? void 0 : reducedPrompt.length) >= promptVersions) {
778
+ delete this._globalMessages[taskUUID];
779
+ resolve(reducedPrompt);
780
+ return true;
781
+ }
782
+ },
783
+ {
784
+ debugKey: "enhance-prompt",
785
+ timeOutDuration: this._timeOutDuration
701
786
  }
702
- },
703
- { debugKey: "enhance-prompt" }
704
- );
705
- lis.destroy();
706
- return response;
707
- });
787
+ );
788
+ lis.destroy();
789
+ return response;
790
+ },
791
+ {
792
+ maxRetries: totalRetry,
793
+ callback: () => {
794
+ lis == null ? void 0 : lis.destroy();
795
+ }
796
+ }
797
+ );
708
798
  } catch (e) {
709
799
  throw e;
710
800
  }
@@ -726,6 +816,9 @@ var RunwareBase = class {
726
816
  this._apiKey = apiKey;
727
817
  this._url = url;
728
818
  this._sdkType = "CLIENT" /* CLIENT */;
819
+ this._shouldReconnect = shouldReconnect;
820
+ this._globalMaxRetries = globalMaxRetries;
821
+ this._timeOutDuration = timeOutDuration;
729
822
  }
730
823
  // protected addListener({
731
824
  // lis,
@@ -924,13 +1017,13 @@ var RunwareBase = class {
924
1017
  onPartialImages,
925
1018
  includeCost,
926
1019
  customTaskUUID,
927
- retry = 2
1020
+ retry
928
1021
  }) {
929
- await this.ensureConnection();
930
1022
  let lis = void 0;
931
1023
  let requestObject = void 0;
932
1024
  let taskUUIDs = [];
933
1025
  let retryCount = 0;
1026
+ const totalRetry = retry || this._globalMaxRetries;
934
1027
  try {
935
1028
  await this.ensureConnection();
936
1029
  let seedImageUUID = null;
@@ -1020,7 +1113,7 @@ var RunwareBase = class {
1020
1113
  return promise;
1021
1114
  },
1022
1115
  {
1023
- maxRetries: retry,
1116
+ maxRetries: totalRetry,
1024
1117
  callback: () => {
1025
1118
  lis == null ? void 0 : lis.destroy();
1026
1119
  }
@@ -1030,7 +1123,7 @@ var RunwareBase = class {
1030
1123
  if (e.taskUUID) {
1031
1124
  throw e;
1032
1125
  }
1033
- if (retryCount >= retry) {
1126
+ if (retryCount >= totalRetry) {
1034
1127
  return this.handleIncompleteImages({ taskUUIDs, error: e });
1035
1128
  }
1036
1129
  }
@@ -1125,7 +1218,11 @@ var RunwareBase = class {
1125
1218
  return true;
1126
1219
  }
1127
1220
  },
1128
- { debugKey: "getting images", shouldThrowError }
1221
+ {
1222
+ debugKey: "getting images",
1223
+ shouldThrowError,
1224
+ timeOutDuration: this._timeOutDuration
1225
+ }
1129
1226
  );
1130
1227
  }
1131
1228
  handleIncompleteImages({
@@ -1150,9 +1247,10 @@ var RunwareBase = class {
1150
1247
  // Runware/Runware-client.ts
1151
1248
  var import_reconnect = __toESM(require_reconnect());
1152
1249
  var RunwareClient = class extends RunwareBase {
1153
- constructor({ apiKey, url }) {
1154
- super({ apiKey, url });
1155
- if (apiKey) {
1250
+ constructor(props) {
1251
+ const _a = props, { shouldReconnect } = _a, rest = __objRest(_a, ["shouldReconnect"]);
1252
+ super(rest);
1253
+ if (rest.apiKey) {
1156
1254
  this._ws = new import_reconnect.default(
1157
1255
  this._url
1158
1256
  );
@@ -1164,16 +1262,29 @@ var RunwareClient = class extends RunwareBase {
1164
1262
  // Runware/Runware-server.ts
1165
1263
  import WebSocket2 from "ws";
1166
1264
  var RunwareServer = class extends RunwareBase {
1167
- constructor({ apiKey, url }) {
1168
- super({ apiKey, url });
1265
+ constructor(props) {
1266
+ super(props);
1169
1267
  this._instantiated = false;
1170
1268
  this._listeners = [];
1171
1269
  this._reconnectingIntervalId = null;
1172
1270
  this.send = (msg) => {
1173
1271
  this._ws.send(JSON.stringify([msg]));
1174
1272
  };
1273
+ this.resetConnection = () => {
1274
+ if (this._ws) {
1275
+ this._listeners.forEach((list) => {
1276
+ var _a;
1277
+ (_a = list == null ? void 0 : list.destroy) == null ? void 0 : _a.call(list);
1278
+ });
1279
+ this._ws.removeAllListeners();
1280
+ this._ws.terminate();
1281
+ this._ws.close();
1282
+ this._ws = null;
1283
+ this._listeners = [];
1284
+ }
1285
+ };
1175
1286
  this._sdkType = "SERVER" /* SERVER */;
1176
- if (apiKey) {
1287
+ if (props.apiKey) {
1177
1288
  this.connect();
1178
1289
  }
1179
1290
  }
@@ -1205,6 +1316,7 @@ var RunwareServer = class extends RunwareBase {
1205
1316
  async connect() {
1206
1317
  if (!this._url)
1207
1318
  return;
1319
+ this.resetConnection();
1208
1320
  this._ws = new WebSocket2(this._url, {
1209
1321
  perMessageDeflate: false
1210
1322
  });
@@ -1265,6 +1377,9 @@ var RunwareServer = class extends RunwareBase {
1265
1377
  if (this._reconnectingIntervalId) {
1266
1378
  clearInterval(this._reconnectingIntervalId);
1267
1379
  }
1380
+ if (this._shouldReconnect) {
1381
+ setTimeout(() => this.connect(), 1e3);
1382
+ }
1268
1383
  }
1269
1384
  heartBeat() {
1270
1385
  clearTimeout(this._pingTimeout);