@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.d.mts +20 -8
- package/dist/index.d.ts +20 -8
- package/dist/index.js +356 -241
- package/dist/index.mjs +356 -241
- package/package.json +1 -1
- package/readme.md +105 -82
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__ */ ((
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return
|
|
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__ */ ((
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return
|
|
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(`
|
|
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({
|
|
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
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
{
|
|
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
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
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
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
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
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
key: "
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
key: "
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
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
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
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
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
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
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
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
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
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
|
|
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:
|
|
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 >=
|
|
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
|
-
{
|
|
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(
|
|
1154
|
-
|
|
1155
|
-
|
|
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(
|
|
1168
|
-
super(
|
|
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);
|