@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.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);
@@ -417,7 +428,9 @@ var RunwareBase = class {
417
428
  constructor({
418
429
  apiKey,
419
430
  url = BASE_RUNWARE_URLS.PRODUCTION,
420
- shouldReconnect = true
431
+ shouldReconnect = true,
432
+ globalMaxRetries = 2,
433
+ timeOutDuration = TIMEOUT_DURATION
421
434
  }) {
422
435
  this._listeners = [];
423
436
  // _globalMessages: any[] = [];
@@ -466,51 +479,68 @@ var RunwareBase = class {
466
479
  lowThresholdCanny,
467
480
  includeHandsAndFaceOpenPose,
468
481
  includeCost,
469
- customTaskUUID
482
+ customTaskUUID,
483
+ retry
470
484
  }) => {
485
+ const totalRetry = retry || this._globalMaxRetries;
486
+ let lis = void 0;
471
487
  try {
472
- const image = await this.uploadImage(inputImage);
473
- if (!(image == null ? void 0 : image.imageUUID))
474
- return null;
475
- const taskUUID = customTaskUUID || getUUID();
476
- this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
477
- inputImage: image.imageUUID,
478
- taskType: "imageControlNetPreProcess" /* IMAGE_CONTROL_NET_PRE_PROCESS */,
479
- taskUUID,
480
- preProcessor
481
- }, 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({
482
- key: "highThresholdCanny",
483
- value: highThresholdCanny
484
- })), evaluateNonTrue({
485
- key: "lowThresholdCanny",
486
- value: lowThresholdCanny
487
- })), evaluateNonTrue({
488
- key: "includeHandsAndFaceOpenPose",
489
- value: includeHandsAndFaceOpenPose
490
- })));
491
- const lis = this.globalListener({
492
- taskUUID
493
- });
494
- const guideImage = await getIntervalWithPromise(
495
- ({ resolve, reject }) => {
496
- 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({
497
511
  taskUUID
498
512
  });
499
- if (!uploadedImage)
500
- return;
501
- if (uploadedImage == null ? void 0 : uploadedImage.error) {
502
- reject(uploadedImage);
503
- return true;
504
- }
505
- if (uploadedImage) {
506
- resolve(uploadedImage);
507
- return true;
508
- }
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;
509
536
  },
510
- { debugKey: "unprocessed-image" }
537
+ {
538
+ maxRetries: totalRetry,
539
+ callback: () => {
540
+ lis == null ? void 0 : lis.destroy();
541
+ }
542
+ }
511
543
  );
512
- lis.destroy();
513
- return guideImage;
514
544
  } catch (e) {
515
545
  throw e;
516
546
  }
@@ -518,43 +548,57 @@ var RunwareBase = class {
518
548
  this.requestImageToText = async ({
519
549
  inputImage,
520
550
  includeCost,
521
- customTaskUUID
551
+ customTaskUUID,
552
+ retry
522
553
  }) => {
554
+ const totalRetry = retry || this._globalMaxRetries;
555
+ let lis = void 0;
523
556
  try {
524
- await this.ensureConnection();
525
- return await asyncRetry(async () => {
526
- const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
527
- const taskUUID = customTaskUUID || getUUID();
528
- this.send(__spreadValues({
529
- taskUUID,
530
- taskType: "imageCaption" /* IMAGE_CAPTION */,
531
- inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
532
- }, evaluateNonTrue({ key: "includeCost", value: includeCost })));
533
- const lis = this.globalListener({
534
- taskUUID
535
- });
536
- const response = await getIntervalWithPromise(
537
- ({ resolve, reject }) => {
538
- const newReverseClip = this.getSingleMessage({
539
- taskUUID
540
- });
541
- if (!newReverseClip)
542
- return;
543
- if (newReverseClip == null ? void 0 : newReverseClip.error) {
544
- reject(newReverseClip);
545
- return true;
546
- }
547
- if (newReverseClip) {
548
- delete this._globalMessages[taskUUID];
549
- resolve(newReverseClip);
550
- 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
551
590
  }
552
- },
553
- { debugKey: "remove-image-background" }
554
- );
555
- lis.destroy();
556
- return response;
557
- });
591
+ );
592
+ lis.destroy();
593
+ return response;
594
+ },
595
+ {
596
+ maxRetries: totalRetry,
597
+ callback: () => {
598
+ lis == null ? void 0 : lis.destroy();
599
+ }
600
+ }
601
+ );
558
602
  } catch (e) {
559
603
  throw e;
560
604
  }
@@ -571,53 +615,70 @@ var RunwareBase = class {
571
615
  alphaMattingBackgroundThreshold,
572
616
  alphaMattingErodeSize,
573
617
  includeCost,
574
- customTaskUUID
618
+ customTaskUUID,
619
+ retry
575
620
  }) => {
621
+ const totalRetry = retry || this._globalMaxRetries;
622
+ let lis = void 0;
576
623
  try {
577
- await this.ensureConnection();
578
- return await asyncRetry(async () => {
579
- const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
580
- const taskUUID = customTaskUUID || getUUID();
581
- this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
582
- taskType: "imageBackgroundRemoval" /* IMAGE_BACKGROUND_REMOVAL */,
583
- taskUUID,
584
- inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
585
- }, evaluateNonTrue({ key: "rgba", value: rgba })), evaluateNonTrue({
586
- key: "postProcessMask",
587
- value: postProcessMask
588
- })), evaluateNonTrue({ key: "returnOnlyMask", value: returnOnlyMask })), evaluateNonTrue({ key: "alphaMatting", value: alphaMatting })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
589
- key: "alphaMattingForegroundThreshold",
590
- value: alphaMattingForegroundThreshold
591
- })), evaluateNonTrue({
592
- key: "alphaMattingBackgroundThreshold",
593
- value: alphaMattingBackgroundThreshold
594
- })), evaluateNonTrue({
595
- key: "alphaMattingErodeSize",
596
- value: alphaMattingErodeSize
597
- })), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })));
598
- const lis = this.globalListener({
599
- taskUUID
600
- });
601
- const response = await getIntervalWithPromise(
602
- ({ resolve, reject }) => {
603
- const newRemoveBackground = this.getSingleMessage({ taskUUID });
604
- if (!newRemoveBackground)
605
- return;
606
- if (newRemoveBackground == null ? void 0 : newRemoveBackground.error) {
607
- reject(newRemoveBackground);
608
- return true;
609
- }
610
- if (newRemoveBackground) {
611
- delete this._globalMessages[taskUUID];
612
- resolve(newRemoveBackground);
613
- 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
614
670
  }
615
- },
616
- { debugKey: "remove-image-background" }
617
- );
618
- lis.destroy();
619
- return response;
620
- });
671
+ );
672
+ lis.destroy();
673
+ return response;
674
+ },
675
+ {
676
+ maxRetries: totalRetry,
677
+ callback: () => {
678
+ lis == null ? void 0 : lis.destroy();
679
+ }
680
+ }
681
+ );
621
682
  } catch (e) {
622
683
  throw e;
623
684
  }
@@ -628,43 +689,54 @@ var RunwareBase = class {
628
689
  outputType,
629
690
  outputFormat,
630
691
  includeCost,
631
- customTaskUUID
692
+ customTaskUUID,
693
+ retry
632
694
  }) => {
695
+ const totalRetry = retry || this._globalMaxRetries;
696
+ let lis = void 0;
633
697
  try {
634
- await this.ensureConnection();
635
- return await asyncRetry(async () => {
636
- let imageUploaded;
637
- imageUploaded = await this.uploadImage(inputImage);
638
- const taskUUID = customTaskUUID || getUUID();
639
- this.send(__spreadValues(__spreadValues(__spreadValues({
640
- taskUUID,
641
- inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
642
- taskType: "imageUpscale" /* IMAGE_UPSCALE */,
643
- upscaleFactor
644
- }, evaluateNonTrue({ key: "includeCost", value: includeCost })), outputType ? { outputType } : {}), outputFormat ? { outputFormat } : {}));
645
- const lis = this.globalListener({
646
- taskUUID
647
- });
648
- const response = await getIntervalWithPromise(
649
- ({ resolve, reject }) => {
650
- const newUpscaleGan = this.getSingleMessage({ taskUUID });
651
- if (!newUpscaleGan)
652
- return;
653
- if (newUpscaleGan == null ? void 0 : newUpscaleGan.error) {
654
- reject(newUpscaleGan);
655
- return true;
656
- }
657
- if (newUpscaleGan) {
658
- delete this._globalMessages[taskUUID];
659
- resolve(newUpscaleGan);
660
- return true;
661
- }
662
- },
663
- { debugKey: "upscale-gan" }
664
- );
665
- lis.destroy();
666
- return response;
667
- });
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
+ );
668
740
  } catch (e) {
669
741
  throw e;
670
742
  }
@@ -674,41 +746,55 @@ var RunwareBase = class {
674
746
  promptMaxLength = 380,
675
747
  promptVersions = 1,
676
748
  includeCost,
677
- customTaskUUID
749
+ customTaskUUID,
750
+ retry
678
751
  }) => {
752
+ const totalRetry = retry || this._globalMaxRetries;
753
+ let lis = void 0;
679
754
  try {
680
- await this.ensureConnection();
681
- return await asyncRetry(async () => {
682
- const taskUUID = customTaskUUID || getUUID();
683
- this.send(__spreadProps(__spreadValues({
684
- prompt,
685
- taskUUID,
686
- promptMaxLength,
687
- promptVersions
688
- }, evaluateNonTrue({ key: "includeCost", value: includeCost })), {
689
- taskType: "promptEnhance" /* PROMPT_ENHANCE */
690
- }));
691
- const lis = this.globalListener({
692
- taskUUID
693
- });
694
- const response = await getIntervalWithPromise(
695
- ({ resolve, reject }) => {
696
- const reducedPrompt = this._globalMessages[taskUUID];
697
- if (reducedPrompt == null ? void 0 : reducedPrompt.error) {
698
- reject(reducedPrompt);
699
- return true;
700
- }
701
- if ((reducedPrompt == null ? void 0 : reducedPrompt.length) >= promptVersions) {
702
- delete this._globalMessages[taskUUID];
703
- resolve(reducedPrompt);
704
- 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
705
786
  }
706
- },
707
- { debugKey: "enhance-prompt" }
708
- );
709
- lis.destroy();
710
- return response;
711
- });
787
+ );
788
+ lis.destroy();
789
+ return response;
790
+ },
791
+ {
792
+ maxRetries: totalRetry,
793
+ callback: () => {
794
+ lis == null ? void 0 : lis.destroy();
795
+ }
796
+ }
797
+ );
712
798
  } catch (e) {
713
799
  throw e;
714
800
  }
@@ -731,6 +817,8 @@ var RunwareBase = class {
731
817
  this._url = url;
732
818
  this._sdkType = "CLIENT" /* CLIENT */;
733
819
  this._shouldReconnect = shouldReconnect;
820
+ this._globalMaxRetries = globalMaxRetries;
821
+ this._timeOutDuration = timeOutDuration;
734
822
  }
735
823
  // protected addListener({
736
824
  // lis,
@@ -929,13 +1017,13 @@ var RunwareBase = class {
929
1017
  onPartialImages,
930
1018
  includeCost,
931
1019
  customTaskUUID,
932
- retry = 2
1020
+ retry
933
1021
  }) {
934
- await this.ensureConnection();
935
1022
  let lis = void 0;
936
1023
  let requestObject = void 0;
937
1024
  let taskUUIDs = [];
938
1025
  let retryCount = 0;
1026
+ const totalRetry = retry || this._globalMaxRetries;
939
1027
  try {
940
1028
  await this.ensureConnection();
941
1029
  let seedImageUUID = null;
@@ -1025,7 +1113,7 @@ var RunwareBase = class {
1025
1113
  return promise;
1026
1114
  },
1027
1115
  {
1028
- maxRetries: retry,
1116
+ maxRetries: totalRetry,
1029
1117
  callback: () => {
1030
1118
  lis == null ? void 0 : lis.destroy();
1031
1119
  }
@@ -1035,7 +1123,7 @@ var RunwareBase = class {
1035
1123
  if (e.taskUUID) {
1036
1124
  throw e;
1037
1125
  }
1038
- if (retryCount >= retry) {
1126
+ if (retryCount >= totalRetry) {
1039
1127
  return this.handleIncompleteImages({ taskUUIDs, error: e });
1040
1128
  }
1041
1129
  }
@@ -1130,7 +1218,11 @@ var RunwareBase = class {
1130
1218
  return true;
1131
1219
  }
1132
1220
  },
1133
- { debugKey: "getting images", shouldThrowError }
1221
+ {
1222
+ debugKey: "getting images",
1223
+ shouldThrowError,
1224
+ timeOutDuration: this._timeOutDuration
1225
+ }
1134
1226
  );
1135
1227
  }
1136
1228
  handleIncompleteImages({
@@ -1155,9 +1247,10 @@ var RunwareBase = class {
1155
1247
  // Runware/Runware-client.ts
1156
1248
  var import_reconnect = __toESM(require_reconnect());
1157
1249
  var RunwareClient = class extends RunwareBase {
1158
- constructor({ apiKey, url }) {
1159
- super({ apiKey, url });
1160
- if (apiKey) {
1250
+ constructor(props) {
1251
+ const _a = props, { shouldReconnect } = _a, rest = __objRest(_a, ["shouldReconnect"]);
1252
+ super(rest);
1253
+ if (rest.apiKey) {
1161
1254
  this._ws = new import_reconnect.default(
1162
1255
  this._url
1163
1256
  );
@@ -1169,8 +1262,8 @@ var RunwareClient = class extends RunwareBase {
1169
1262
  // Runware/Runware-server.ts
1170
1263
  import WebSocket2 from "ws";
1171
1264
  var RunwareServer = class extends RunwareBase {
1172
- constructor({ apiKey, url, shouldReconnect }) {
1173
- super({ apiKey, url, shouldReconnect });
1265
+ constructor(props) {
1266
+ super(props);
1174
1267
  this._instantiated = false;
1175
1268
  this._listeners = [];
1176
1269
  this._reconnectingIntervalId = null;
@@ -1191,7 +1284,7 @@ var RunwareServer = class extends RunwareBase {
1191
1284
  }
1192
1285
  };
1193
1286
  this._sdkType = "SERVER" /* SERVER */;
1194
- if (apiKey) {
1287
+ if (props.apiKey) {
1195
1288
  this.connect();
1196
1289
  }
1197
1290
  }
@@ -1284,9 +1377,7 @@ var RunwareServer = class extends RunwareBase {
1284
1377
  if (this._reconnectingIntervalId) {
1285
1378
  clearInterval(this._reconnectingIntervalId);
1286
1379
  }
1287
- console.log("should reconnect", this._shouldReconnect);
1288
1380
  if (this._shouldReconnect) {
1289
- console.log("reconnecting");
1290
1381
  setTimeout(() => this.connect(), 1e3);
1291
1382
  }
1292
1383
  }