@runware/sdk-js 1.1.16 → 1.1.17-beta.2

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.js CHANGED
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
22
22
  return a;
23
23
  };
24
24
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
25
37
  var __commonJS = (cb, mod) => function __require() {
26
38
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
27
39
  };
@@ -262,50 +274,50 @@ var EControlMode = /* @__PURE__ */ ((EControlMode2) => {
262
274
  EControlMode2["CONTROL_NET"] = "controlnet";
263
275
  return EControlMode2;
264
276
  })(EControlMode || {});
265
- var EPreProcessorGroup = /* @__PURE__ */ ((EPreProcessorGroup3) => {
266
- EPreProcessorGroup3["canny"] = "canny";
267
- EPreProcessorGroup3["depth"] = "depth";
268
- EPreProcessorGroup3["mlsd"] = "mlsd";
269
- EPreProcessorGroup3["normalbae"] = "normalbae";
270
- EPreProcessorGroup3["openpose"] = "openpose";
271
- EPreProcessorGroup3["tile"] = "tile";
272
- EPreProcessorGroup3["seg"] = "seg";
273
- EPreProcessorGroup3["lineart"] = "lineart";
274
- EPreProcessorGroup3["lineart_anime"] = "lineart_anime";
275
- EPreProcessorGroup3["shuffle"] = "shuffle";
276
- EPreProcessorGroup3["scribble"] = "scribble";
277
- EPreProcessorGroup3["softedge"] = "softedge";
278
- return EPreProcessorGroup3;
277
+ var EPreProcessorGroup = /* @__PURE__ */ ((EPreProcessorGroup2) => {
278
+ EPreProcessorGroup2["canny"] = "canny";
279
+ EPreProcessorGroup2["depth"] = "depth";
280
+ EPreProcessorGroup2["mlsd"] = "mlsd";
281
+ EPreProcessorGroup2["normalbae"] = "normalbae";
282
+ EPreProcessorGroup2["openpose"] = "openpose";
283
+ EPreProcessorGroup2["tile"] = "tile";
284
+ EPreProcessorGroup2["seg"] = "seg";
285
+ EPreProcessorGroup2["lineart"] = "lineart";
286
+ EPreProcessorGroup2["lineart_anime"] = "lineart_anime";
287
+ EPreProcessorGroup2["shuffle"] = "shuffle";
288
+ EPreProcessorGroup2["scribble"] = "scribble";
289
+ EPreProcessorGroup2["softedge"] = "softedge";
290
+ return EPreProcessorGroup2;
279
291
  })(EPreProcessorGroup || {});
280
- var EPreProcessor = /* @__PURE__ */ ((EPreProcessor3) => {
281
- EPreProcessor3["canny"] = "canny";
282
- EPreProcessor3["depth_leres"] = "depth_leres";
283
- EPreProcessor3["depth_midas"] = "depth_midas";
284
- EPreProcessor3["depth_zoe"] = "depth_zoe";
285
- EPreProcessor3["inpaint_global_harmonious"] = "inpaint_global_harmonious";
286
- EPreProcessor3["lineart_anime"] = "lineart_anime";
287
- EPreProcessor3["lineart_coarse"] = "lineart_coarse";
288
- EPreProcessor3["lineart_realistic"] = "lineart_realistic";
289
- EPreProcessor3["lineart_standard"] = "lineart_standard";
290
- EPreProcessor3["mlsd"] = "mlsd";
291
- EPreProcessor3["normal_bae"] = "normal_bae";
292
- EPreProcessor3["scribble_hed"] = "scribble_hed";
293
- EPreProcessor3["scribble_pidinet"] = "scribble_pidinet";
294
- EPreProcessor3["seg_ofade20k"] = "seg_ofade20k";
295
- EPreProcessor3["seg_ofcoco"] = "seg_ofcoco";
296
- EPreProcessor3["seg_ufade20k"] = "seg_ufade20k";
297
- EPreProcessor3["shuffle"] = "shuffle";
298
- EPreProcessor3["softedge_hed"] = "softedge_hed";
299
- EPreProcessor3["softedge_hedsafe"] = "softedge_hedsafe";
300
- EPreProcessor3["softedge_pidinet"] = "softedge_pidinet";
301
- EPreProcessor3["softedge_pidisafe"] = "softedge_pidisafe";
302
- EPreProcessor3["tile_gaussian"] = "tile_gaussian";
303
- EPreProcessor3["openpose"] = "openpose";
304
- EPreProcessor3["openpose_face"] = "openpose_face";
305
- EPreProcessor3["openpose_faceonly"] = "openpose_faceonly";
306
- EPreProcessor3["openpose_full"] = "openpose_full";
307
- EPreProcessor3["openpose_hand"] = "openpose_hand";
308
- return EPreProcessor3;
292
+ var EPreProcessor = /* @__PURE__ */ ((EPreProcessor2) => {
293
+ EPreProcessor2["canny"] = "canny";
294
+ EPreProcessor2["depth_leres"] = "depth_leres";
295
+ EPreProcessor2["depth_midas"] = "depth_midas";
296
+ EPreProcessor2["depth_zoe"] = "depth_zoe";
297
+ EPreProcessor2["inpaint_global_harmonious"] = "inpaint_global_harmonious";
298
+ EPreProcessor2["lineart_anime"] = "lineart_anime";
299
+ EPreProcessor2["lineart_coarse"] = "lineart_coarse";
300
+ EPreProcessor2["lineart_realistic"] = "lineart_realistic";
301
+ EPreProcessor2["lineart_standard"] = "lineart_standard";
302
+ EPreProcessor2["mlsd"] = "mlsd";
303
+ EPreProcessor2["normal_bae"] = "normal_bae";
304
+ EPreProcessor2["scribble_hed"] = "scribble_hed";
305
+ EPreProcessor2["scribble_pidinet"] = "scribble_pidinet";
306
+ EPreProcessor2["seg_ofade20k"] = "seg_ofade20k";
307
+ EPreProcessor2["seg_ofcoco"] = "seg_ofcoco";
308
+ EPreProcessor2["seg_ufade20k"] = "seg_ufade20k";
309
+ EPreProcessor2["shuffle"] = "shuffle";
310
+ EPreProcessor2["softedge_hed"] = "softedge_hed";
311
+ EPreProcessor2["softedge_hedsafe"] = "softedge_hedsafe";
312
+ EPreProcessor2["softedge_pidinet"] = "softedge_pidinet";
313
+ EPreProcessor2["softedge_pidisafe"] = "softedge_pidisafe";
314
+ EPreProcessor2["tile_gaussian"] = "tile_gaussian";
315
+ EPreProcessor2["openpose"] = "openpose";
316
+ EPreProcessor2["openpose_face"] = "openpose_face";
317
+ EPreProcessor2["openpose_faceonly"] = "openpose_faceonly";
318
+ EPreProcessor2["openpose_full"] = "openpose_full";
319
+ EPreProcessor2["openpose_hand"] = "openpose_hand";
320
+ return EPreProcessor2;
309
321
  })(EPreProcessor || {});
310
322
  var EOpenPosePreProcessor = /* @__PURE__ */ ((EOpenPosePreProcessor2) => {
311
323
  EOpenPosePreProcessor2["openpose"] = "openpose";
@@ -344,8 +356,7 @@ var getIntervalWithPromise = (callback, {
344
356
  if (intervalId) {
345
357
  clearInterval(intervalId);
346
358
  if (shouldThrowError) {
347
- reject(`Message could not be received for ${debugKey}`);
348
- console.error("Message could not be received for ", debugKey);
359
+ reject(`Response could not be received from server for ${debugKey}`);
349
360
  }
350
361
  }
351
362
  clearTimeout(timeoutId);
@@ -439,7 +450,9 @@ var RunwareBase = class {
439
450
  constructor({
440
451
  apiKey,
441
452
  url = BASE_RUNWARE_URLS.PRODUCTION,
442
- shouldReconnect = true
453
+ shouldReconnect = true,
454
+ globalMaxRetries = 2,
455
+ timeOutDuration = TIMEOUT_DURATION
443
456
  }) {
444
457
  this._listeners = [];
445
458
  // _globalMessages: any[] = [];
@@ -488,51 +501,68 @@ var RunwareBase = class {
488
501
  lowThresholdCanny,
489
502
  includeHandsAndFaceOpenPose,
490
503
  includeCost,
491
- customTaskUUID
504
+ customTaskUUID,
505
+ retry
492
506
  }) => {
507
+ const totalRetry = retry || this._globalMaxRetries;
508
+ let lis = void 0;
493
509
  try {
494
- const image = await this.uploadImage(inputImage);
495
- if (!(image == null ? void 0 : image.imageUUID))
496
- return null;
497
- const taskUUID = customTaskUUID || getUUID();
498
- this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
499
- inputImage: image.imageUUID,
500
- taskType: "imageControlNetPreProcess" /* IMAGE_CONTROL_NET_PRE_PROCESS */,
501
- taskUUID,
502
- preProcessor
503
- }, 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({
504
- key: "highThresholdCanny",
505
- value: highThresholdCanny
506
- })), evaluateNonTrue({
507
- key: "lowThresholdCanny",
508
- value: lowThresholdCanny
509
- })), evaluateNonTrue({
510
- key: "includeHandsAndFaceOpenPose",
511
- value: includeHandsAndFaceOpenPose
512
- })));
513
- const lis = this.globalListener({
514
- taskUUID
515
- });
516
- const guideImage = await getIntervalWithPromise(
517
- ({ resolve, reject }) => {
518
- const uploadedImage = this.getSingleMessage({
510
+ return await asyncRetry(
511
+ async () => {
512
+ await this.ensureConnection();
513
+ const image = await this.uploadImage(inputImage);
514
+ if (!(image == null ? void 0 : image.imageUUID))
515
+ return null;
516
+ const taskUUID = customTaskUUID || getUUID();
517
+ this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
518
+ inputImage: image.imageUUID,
519
+ taskType: "imageControlNetPreProcess" /* IMAGE_CONTROL_NET_PRE_PROCESS */,
520
+ taskUUID,
521
+ preProcessor
522
+ }, 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({
523
+ key: "highThresholdCanny",
524
+ value: highThresholdCanny
525
+ })), evaluateNonTrue({
526
+ key: "lowThresholdCanny",
527
+ value: lowThresholdCanny
528
+ })), evaluateNonTrue({
529
+ key: "includeHandsAndFaceOpenPose",
530
+ value: includeHandsAndFaceOpenPose
531
+ })));
532
+ lis = this.globalListener({
519
533
  taskUUID
520
534
  });
521
- if (!uploadedImage)
522
- return;
523
- if (uploadedImage == null ? void 0 : uploadedImage.error) {
524
- reject(uploadedImage);
525
- return true;
526
- }
527
- if (uploadedImage) {
528
- resolve(uploadedImage);
529
- return true;
530
- }
535
+ const guideImage = await getIntervalWithPromise(
536
+ ({ resolve, reject }) => {
537
+ const uploadedImage = this.getSingleMessage({
538
+ taskUUID
539
+ });
540
+ if (!uploadedImage)
541
+ return;
542
+ if (uploadedImage == null ? void 0 : uploadedImage.error) {
543
+ reject(uploadedImage);
544
+ return true;
545
+ }
546
+ if (uploadedImage) {
547
+ resolve(uploadedImage);
548
+ return true;
549
+ }
550
+ },
551
+ {
552
+ debugKey: "unprocessed-image",
553
+ timeOutDuration: this._timeOutDuration
554
+ }
555
+ );
556
+ lis.destroy();
557
+ return guideImage;
531
558
  },
532
- { debugKey: "unprocessed-image" }
559
+ {
560
+ maxRetries: totalRetry,
561
+ callback: () => {
562
+ lis == null ? void 0 : lis.destroy();
563
+ }
564
+ }
533
565
  );
534
- lis.destroy();
535
- return guideImage;
536
566
  } catch (e) {
537
567
  throw e;
538
568
  }
@@ -540,43 +570,57 @@ var RunwareBase = class {
540
570
  this.requestImageToText = async ({
541
571
  inputImage,
542
572
  includeCost,
543
- customTaskUUID
573
+ customTaskUUID,
574
+ retry
544
575
  }) => {
576
+ const totalRetry = retry || this._globalMaxRetries;
577
+ let lis = void 0;
545
578
  try {
546
- await this.ensureConnection();
547
- return await asyncRetry(async () => {
548
- const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
549
- const taskUUID = customTaskUUID || getUUID();
550
- this.send(__spreadValues({
551
- taskUUID,
552
- taskType: "imageCaption" /* IMAGE_CAPTION */,
553
- inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
554
- }, evaluateNonTrue({ key: "includeCost", value: includeCost })));
555
- const lis = this.globalListener({
556
- taskUUID
557
- });
558
- const response = await getIntervalWithPromise(
559
- ({ resolve, reject }) => {
560
- const newReverseClip = this.getSingleMessage({
561
- taskUUID
562
- });
563
- if (!newReverseClip)
564
- return;
565
- if (newReverseClip == null ? void 0 : newReverseClip.error) {
566
- reject(newReverseClip);
567
- return true;
568
- }
569
- if (newReverseClip) {
570
- delete this._globalMessages[taskUUID];
571
- resolve(newReverseClip);
572
- return true;
579
+ return await asyncRetry(
580
+ async () => {
581
+ await this.ensureConnection();
582
+ const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
583
+ const taskUUID = customTaskUUID || getUUID();
584
+ this.send(__spreadValues({
585
+ taskUUID,
586
+ taskType: "imageCaption" /* IMAGE_CAPTION */,
587
+ inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
588
+ }, evaluateNonTrue({ key: "includeCost", value: includeCost })));
589
+ lis = this.globalListener({
590
+ taskUUID
591
+ });
592
+ const response = await getIntervalWithPromise(
593
+ ({ resolve, reject }) => {
594
+ const newReverseClip = this.getSingleMessage({
595
+ taskUUID
596
+ });
597
+ if (!newReverseClip)
598
+ return;
599
+ if (newReverseClip == null ? void 0 : newReverseClip.error) {
600
+ reject(newReverseClip);
601
+ return true;
602
+ }
603
+ if (newReverseClip) {
604
+ delete this._globalMessages[taskUUID];
605
+ resolve(newReverseClip);
606
+ return true;
607
+ }
608
+ },
609
+ {
610
+ debugKey: "remove-image-background",
611
+ timeOutDuration: this._timeOutDuration
573
612
  }
574
- },
575
- { debugKey: "remove-image-background" }
576
- );
577
- lis.destroy();
578
- return response;
579
- });
613
+ );
614
+ lis.destroy();
615
+ return response;
616
+ },
617
+ {
618
+ maxRetries: totalRetry,
619
+ callback: () => {
620
+ lis == null ? void 0 : lis.destroy();
621
+ }
622
+ }
623
+ );
580
624
  } catch (e) {
581
625
  throw e;
582
626
  }
@@ -593,53 +637,70 @@ var RunwareBase = class {
593
637
  alphaMattingBackgroundThreshold,
594
638
  alphaMattingErodeSize,
595
639
  includeCost,
596
- customTaskUUID
640
+ customTaskUUID,
641
+ retry
597
642
  }) => {
643
+ const totalRetry = retry || this._globalMaxRetries;
644
+ let lis = void 0;
598
645
  try {
599
- await this.ensureConnection();
600
- return await asyncRetry(async () => {
601
- const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
602
- const taskUUID = customTaskUUID || getUUID();
603
- this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
604
- taskType: "imageBackgroundRemoval" /* IMAGE_BACKGROUND_REMOVAL */,
605
- taskUUID,
606
- inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
607
- }, evaluateNonTrue({ key: "rgba", value: rgba })), evaluateNonTrue({
608
- key: "postProcessMask",
609
- value: postProcessMask
610
- })), evaluateNonTrue({ key: "returnOnlyMask", value: returnOnlyMask })), evaluateNonTrue({ key: "alphaMatting", value: alphaMatting })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
611
- key: "alphaMattingForegroundThreshold",
612
- value: alphaMattingForegroundThreshold
613
- })), evaluateNonTrue({
614
- key: "alphaMattingBackgroundThreshold",
615
- value: alphaMattingBackgroundThreshold
616
- })), evaluateNonTrue({
617
- key: "alphaMattingErodeSize",
618
- value: alphaMattingErodeSize
619
- })), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })));
620
- const lis = this.globalListener({
621
- taskUUID
622
- });
623
- const response = await getIntervalWithPromise(
624
- ({ resolve, reject }) => {
625
- const newRemoveBackground = this.getSingleMessage({ taskUUID });
626
- if (!newRemoveBackground)
627
- return;
628
- if (newRemoveBackground == null ? void 0 : newRemoveBackground.error) {
629
- reject(newRemoveBackground);
630
- return true;
631
- }
632
- if (newRemoveBackground) {
633
- delete this._globalMessages[taskUUID];
634
- resolve(newRemoveBackground);
635
- return true;
646
+ return await asyncRetry(
647
+ async () => {
648
+ await this.ensureConnection();
649
+ const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
650
+ const taskUUID = customTaskUUID || getUUID();
651
+ this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
652
+ taskType: "imageBackgroundRemoval" /* IMAGE_BACKGROUND_REMOVAL */,
653
+ taskUUID,
654
+ inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
655
+ }, evaluateNonTrue({ key: "rgba", value: rgba })), evaluateNonTrue({
656
+ key: "postProcessMask",
657
+ value: postProcessMask
658
+ })), evaluateNonTrue({
659
+ key: "returnOnlyMask",
660
+ value: returnOnlyMask
661
+ })), evaluateNonTrue({ key: "alphaMatting", value: alphaMatting })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
662
+ key: "alphaMattingForegroundThreshold",
663
+ value: alphaMattingForegroundThreshold
664
+ })), evaluateNonTrue({
665
+ key: "alphaMattingBackgroundThreshold",
666
+ value: alphaMattingBackgroundThreshold
667
+ })), evaluateNonTrue({
668
+ key: "alphaMattingErodeSize",
669
+ value: alphaMattingErodeSize
670
+ })), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })));
671
+ lis = this.globalListener({
672
+ taskUUID
673
+ });
674
+ const response = await getIntervalWithPromise(
675
+ ({ resolve, reject }) => {
676
+ const newRemoveBackground = this.getSingleMessage({ taskUUID });
677
+ if (!newRemoveBackground)
678
+ return;
679
+ if (newRemoveBackground == null ? void 0 : newRemoveBackground.error) {
680
+ reject(newRemoveBackground);
681
+ return true;
682
+ }
683
+ if (newRemoveBackground) {
684
+ delete this._globalMessages[taskUUID];
685
+ resolve(newRemoveBackground);
686
+ return true;
687
+ }
688
+ },
689
+ {
690
+ debugKey: "remove-image-background",
691
+ timeOutDuration: this._timeOutDuration
636
692
  }
637
- },
638
- { debugKey: "remove-image-background" }
639
- );
640
- lis.destroy();
641
- return response;
642
- });
693
+ );
694
+ lis.destroy();
695
+ return response;
696
+ },
697
+ {
698
+ maxRetries: totalRetry,
699
+ callback: () => {
700
+ lis == null ? void 0 : lis.destroy();
701
+ }
702
+ }
703
+ );
643
704
  } catch (e) {
644
705
  throw e;
645
706
  }
@@ -650,43 +711,54 @@ var RunwareBase = class {
650
711
  outputType,
651
712
  outputFormat,
652
713
  includeCost,
653
- customTaskUUID
714
+ customTaskUUID,
715
+ retry
654
716
  }) => {
717
+ const totalRetry = retry || this._globalMaxRetries;
718
+ let lis = void 0;
655
719
  try {
656
- await this.ensureConnection();
657
- return await asyncRetry(async () => {
658
- let imageUploaded;
659
- imageUploaded = await this.uploadImage(inputImage);
660
- const taskUUID = customTaskUUID || getUUID();
661
- this.send(__spreadValues(__spreadValues(__spreadValues({
662
- taskUUID,
663
- inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
664
- taskType: "imageUpscale" /* IMAGE_UPSCALE */,
665
- upscaleFactor
666
- }, evaluateNonTrue({ key: "includeCost", value: includeCost })), outputType ? { outputType } : {}), outputFormat ? { outputFormat } : {}));
667
- const lis = this.globalListener({
668
- taskUUID
669
- });
670
- const response = await getIntervalWithPromise(
671
- ({ resolve, reject }) => {
672
- const newUpscaleGan = this.getSingleMessage({ taskUUID });
673
- if (!newUpscaleGan)
674
- return;
675
- if (newUpscaleGan == null ? void 0 : newUpscaleGan.error) {
676
- reject(newUpscaleGan);
677
- return true;
678
- }
679
- if (newUpscaleGan) {
680
- delete this._globalMessages[taskUUID];
681
- resolve(newUpscaleGan);
682
- return true;
683
- }
684
- },
685
- { debugKey: "upscale-gan" }
686
- );
687
- lis.destroy();
688
- return response;
689
- });
720
+ return await asyncRetry(
721
+ async () => {
722
+ await this.ensureConnection();
723
+ let imageUploaded;
724
+ imageUploaded = await this.uploadImage(inputImage);
725
+ const taskUUID = customTaskUUID || getUUID();
726
+ this.send(__spreadValues(__spreadValues(__spreadValues({
727
+ taskUUID,
728
+ inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
729
+ taskType: "imageUpscale" /* IMAGE_UPSCALE */,
730
+ upscaleFactor
731
+ }, evaluateNonTrue({ key: "includeCost", value: includeCost })), outputType ? { outputType } : {}), outputFormat ? { outputFormat } : {}));
732
+ lis = this.globalListener({
733
+ taskUUID
734
+ });
735
+ const response = await getIntervalWithPromise(
736
+ ({ resolve, reject }) => {
737
+ const newUpscaleGan = this.getSingleMessage({ taskUUID });
738
+ if (!newUpscaleGan)
739
+ return;
740
+ if (newUpscaleGan == null ? void 0 : newUpscaleGan.error) {
741
+ reject(newUpscaleGan);
742
+ return true;
743
+ }
744
+ if (newUpscaleGan) {
745
+ delete this._globalMessages[taskUUID];
746
+ resolve(newUpscaleGan);
747
+ return true;
748
+ }
749
+ },
750
+ { debugKey: "upscale-gan", timeOutDuration: this._timeOutDuration }
751
+ );
752
+ lis.destroy();
753
+ return response;
754
+ },
755
+ {
756
+ maxRetries: totalRetry,
757
+ callback: () => {
758
+ lis == null ? void 0 : lis.destroy();
759
+ }
760
+ }
761
+ );
690
762
  } catch (e) {
691
763
  throw e;
692
764
  }
@@ -696,41 +768,55 @@ var RunwareBase = class {
696
768
  promptMaxLength = 380,
697
769
  promptVersions = 1,
698
770
  includeCost,
699
- customTaskUUID
771
+ customTaskUUID,
772
+ retry
700
773
  }) => {
774
+ const totalRetry = retry || this._globalMaxRetries;
775
+ let lis = void 0;
701
776
  try {
702
- await this.ensureConnection();
703
- return await asyncRetry(async () => {
704
- const taskUUID = customTaskUUID || getUUID();
705
- this.send(__spreadProps(__spreadValues({
706
- prompt,
707
- taskUUID,
708
- promptMaxLength,
709
- promptVersions
710
- }, evaluateNonTrue({ key: "includeCost", value: includeCost })), {
711
- taskType: "promptEnhance" /* PROMPT_ENHANCE */
712
- }));
713
- const lis = this.globalListener({
714
- taskUUID
715
- });
716
- const response = await getIntervalWithPromise(
717
- ({ resolve, reject }) => {
718
- const reducedPrompt = this._globalMessages[taskUUID];
719
- if (reducedPrompt == null ? void 0 : reducedPrompt.error) {
720
- reject(reducedPrompt);
721
- return true;
722
- }
723
- if ((reducedPrompt == null ? void 0 : reducedPrompt.length) >= promptVersions) {
724
- delete this._globalMessages[taskUUID];
725
- resolve(reducedPrompt);
726
- return true;
777
+ return await asyncRetry(
778
+ async () => {
779
+ await this.ensureConnection();
780
+ const taskUUID = customTaskUUID || getUUID();
781
+ this.send(__spreadProps(__spreadValues({
782
+ prompt,
783
+ taskUUID,
784
+ promptMaxLength,
785
+ promptVersions
786
+ }, evaluateNonTrue({ key: "includeCost", value: includeCost })), {
787
+ taskType: "promptEnhance" /* PROMPT_ENHANCE */
788
+ }));
789
+ lis = this.globalListener({
790
+ taskUUID
791
+ });
792
+ const response = await getIntervalWithPromise(
793
+ ({ resolve, reject }) => {
794
+ const reducedPrompt = this._globalMessages[taskUUID];
795
+ if (reducedPrompt == null ? void 0 : reducedPrompt.error) {
796
+ reject(reducedPrompt);
797
+ return true;
798
+ }
799
+ if ((reducedPrompt == null ? void 0 : reducedPrompt.length) >= promptVersions) {
800
+ delete this._globalMessages[taskUUID];
801
+ resolve(reducedPrompt);
802
+ return true;
803
+ }
804
+ },
805
+ {
806
+ debugKey: "enhance-prompt",
807
+ timeOutDuration: this._timeOutDuration
727
808
  }
728
- },
729
- { debugKey: "enhance-prompt" }
730
- );
731
- lis.destroy();
732
- return response;
733
- });
809
+ );
810
+ lis.destroy();
811
+ return response;
812
+ },
813
+ {
814
+ maxRetries: totalRetry,
815
+ callback: () => {
816
+ lis == null ? void 0 : lis.destroy();
817
+ }
818
+ }
819
+ );
734
820
  } catch (e) {
735
821
  throw e;
736
822
  }
@@ -753,6 +839,8 @@ var RunwareBase = class {
753
839
  this._url = url;
754
840
  this._sdkType = "CLIENT" /* CLIENT */;
755
841
  this._shouldReconnect = shouldReconnect;
842
+ this._globalMaxRetries = globalMaxRetries;
843
+ this._timeOutDuration = timeOutDuration;
756
844
  }
757
845
  // protected addListener({
758
846
  // lis,
@@ -951,13 +1039,13 @@ var RunwareBase = class {
951
1039
  onPartialImages,
952
1040
  includeCost,
953
1041
  customTaskUUID,
954
- retry = 2
1042
+ retry
955
1043
  }) {
956
- await this.ensureConnection();
957
1044
  let lis = void 0;
958
1045
  let requestObject = void 0;
959
1046
  let taskUUIDs = [];
960
1047
  let retryCount = 0;
1048
+ const totalRetry = retry || this._globalMaxRetries;
961
1049
  try {
962
1050
  await this.ensureConnection();
963
1051
  let seedImageUUID = null;
@@ -1047,7 +1135,7 @@ var RunwareBase = class {
1047
1135
  return promise;
1048
1136
  },
1049
1137
  {
1050
- maxRetries: retry,
1138
+ maxRetries: totalRetry,
1051
1139
  callback: () => {
1052
1140
  lis == null ? void 0 : lis.destroy();
1053
1141
  }
@@ -1057,7 +1145,7 @@ var RunwareBase = class {
1057
1145
  if (e.taskUUID) {
1058
1146
  throw e;
1059
1147
  }
1060
- if (retryCount >= retry) {
1148
+ if (retryCount >= totalRetry) {
1061
1149
  return this.handleIncompleteImages({ taskUUIDs, error: e });
1062
1150
  }
1063
1151
  }
@@ -1152,7 +1240,11 @@ var RunwareBase = class {
1152
1240
  return true;
1153
1241
  }
1154
1242
  },
1155
- { debugKey: "getting images", shouldThrowError }
1243
+ {
1244
+ debugKey: "getting images",
1245
+ shouldThrowError,
1246
+ timeOutDuration: this._timeOutDuration
1247
+ }
1156
1248
  );
1157
1249
  }
1158
1250
  handleIncompleteImages({
@@ -1177,9 +1269,10 @@ var RunwareBase = class {
1177
1269
  // Runware/Runware-client.ts
1178
1270
  var import_reconnect = __toESM(require_reconnect());
1179
1271
  var RunwareClient = class extends RunwareBase {
1180
- constructor({ apiKey, url }) {
1181
- super({ apiKey, url });
1182
- if (apiKey) {
1272
+ constructor(props) {
1273
+ const _a = props, { shouldReconnect } = _a, rest = __objRest(_a, ["shouldReconnect"]);
1274
+ super(rest);
1275
+ if (rest.apiKey) {
1183
1276
  this._ws = new import_reconnect.default(
1184
1277
  this._url
1185
1278
  );
@@ -1191,8 +1284,8 @@ var RunwareClient = class extends RunwareBase {
1191
1284
  // Runware/Runware-server.ts
1192
1285
  var import_ws = __toESM(require("ws"));
1193
1286
  var RunwareServer = class extends RunwareBase {
1194
- constructor({ apiKey, url, shouldReconnect }) {
1195
- super({ apiKey, url, shouldReconnect });
1287
+ constructor(props) {
1288
+ super(props);
1196
1289
  this._instantiated = false;
1197
1290
  this._listeners = [];
1198
1291
  this._reconnectingIntervalId = null;
@@ -1213,7 +1306,7 @@ var RunwareServer = class extends RunwareBase {
1213
1306
  }
1214
1307
  };
1215
1308
  this._sdkType = "SERVER" /* SERVER */;
1216
- if (apiKey) {
1309
+ if (props.apiKey) {
1217
1310
  this.connect();
1218
1311
  }
1219
1312
  }
@@ -1306,9 +1399,7 @@ var RunwareServer = class extends RunwareBase {
1306
1399
  if (this._reconnectingIntervalId) {
1307
1400
  clearInterval(this._reconnectingIntervalId);
1308
1401
  }
1309
- console.log("should reconnect", this._shouldReconnect);
1310
1402
  if (this._shouldReconnect) {
1311
- console.log("reconnecting");
1312
1403
  setTimeout(() => this.connect(), 1e3);
1313
1404
  }
1314
1405
  }