@runware/sdk-js 1.1.17 → 1.1.18
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 +19 -9
- package/dist/index.d.ts +19 -9
- package/dist/index.js +357 -262
- package/dist/index.mjs +357 -262
- package/package.json +1 -1
- package/readme.md +126 -86
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
|
};
|
|
@@ -168,9 +180,9 @@ var require_reconnect = __commonJS({
|
|
|
168
180
|
};
|
|
169
181
|
log("init");
|
|
170
182
|
connect();
|
|
171
|
-
this.close = (code = 1e3, reason = "", { keepClosed = false, fastClose = true, delay:
|
|
172
|
-
if (
|
|
173
|
-
reconnectDelay =
|
|
183
|
+
this.close = (code = 1e3, reason = "", { keepClosed = false, fastClose = true, delay: delay3 = 0 } = {}) => {
|
|
184
|
+
if (delay3) {
|
|
185
|
+
reconnectDelay = delay3;
|
|
174
186
|
}
|
|
175
187
|
shouldRetry = !keepClosed;
|
|
176
188
|
ws.close(code, reason);
|
|
@@ -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__ */ ((
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return
|
|
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__ */ ((
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return
|
|
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";
|
|
@@ -319,6 +331,7 @@ var EOpenPosePreProcessor = /* @__PURE__ */ ((EOpenPosePreProcessor2) => {
|
|
|
319
331
|
// Runware/utils.ts
|
|
320
332
|
var import_uuid = require("uuid");
|
|
321
333
|
var TIMEOUT_DURATION = 6e4;
|
|
334
|
+
var MINIMUM_TIMEOUT_DURATION = 1e3;
|
|
322
335
|
var POLLING_INTERVAL = 100;
|
|
323
336
|
var BASE_RUNWARE_URLS = {
|
|
324
337
|
["PRODUCTION" /* PRODUCTION */]: "wss://ws-api.runware.ai/v1",
|
|
@@ -336,20 +349,20 @@ var removeFromAray = (col, targetElem) => {
|
|
|
336
349
|
};
|
|
337
350
|
var getIntervalWithPromise = (callback, {
|
|
338
351
|
debugKey = "debugKey",
|
|
339
|
-
|
|
352
|
+
timeoutDuration = TIMEOUT_DURATION,
|
|
340
353
|
shouldThrowError = true
|
|
341
354
|
}) => {
|
|
355
|
+
timeoutDuration = timeoutDuration < MINIMUM_TIMEOUT_DURATION ? MINIMUM_TIMEOUT_DURATION : timeoutDuration;
|
|
342
356
|
return new Promise((resolve, reject) => {
|
|
343
357
|
const timeoutId = setTimeout(() => {
|
|
344
358
|
if (intervalId) {
|
|
345
359
|
clearInterval(intervalId);
|
|
346
360
|
if (shouldThrowError) {
|
|
347
|
-
reject(`
|
|
348
|
-
console.error("Message could not be received for ", debugKey);
|
|
361
|
+
reject(`Response could not be received from server for ${debugKey}`);
|
|
349
362
|
}
|
|
350
363
|
}
|
|
351
364
|
clearTimeout(timeoutId);
|
|
352
|
-
},
|
|
365
|
+
}, timeoutDuration);
|
|
353
366
|
let intervalId = setInterval(async () => {
|
|
354
367
|
const shouldClear = callback({ resolve, reject, intervalId });
|
|
355
368
|
if (shouldClear) {
|
|
@@ -439,7 +452,9 @@ var RunwareBase = class {
|
|
|
439
452
|
constructor({
|
|
440
453
|
apiKey,
|
|
441
454
|
url = BASE_RUNWARE_URLS.PRODUCTION,
|
|
442
|
-
shouldReconnect = true
|
|
455
|
+
shouldReconnect = true,
|
|
456
|
+
globalMaxRetries = 2,
|
|
457
|
+
timeoutDuration = TIMEOUT_DURATION
|
|
443
458
|
}) {
|
|
444
459
|
this._listeners = [];
|
|
445
460
|
// _globalMessages: any[] = [];
|
|
@@ -488,51 +503,68 @@ var RunwareBase = class {
|
|
|
488
503
|
lowThresholdCanny,
|
|
489
504
|
includeHandsAndFaceOpenPose,
|
|
490
505
|
includeCost,
|
|
491
|
-
customTaskUUID
|
|
506
|
+
customTaskUUID,
|
|
507
|
+
retry
|
|
492
508
|
}) => {
|
|
509
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
510
|
+
let lis = void 0;
|
|
493
511
|
try {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
({ resolve, reject }) => {
|
|
518
|
-
const uploadedImage = this.getSingleMessage({
|
|
512
|
+
return await asyncRetry(
|
|
513
|
+
async () => {
|
|
514
|
+
await this.ensureConnection();
|
|
515
|
+
const image = await this.uploadImage(inputImage);
|
|
516
|
+
if (!(image == null ? void 0 : image.imageUUID))
|
|
517
|
+
return null;
|
|
518
|
+
const taskUUID = customTaskUUID || getUUID();
|
|
519
|
+
this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
520
|
+
inputImage: image.imageUUID,
|
|
521
|
+
taskType: "imageControlNetPreProcess" /* IMAGE_CONTROL_NET_PRE_PROCESS */,
|
|
522
|
+
taskUUID,
|
|
523
|
+
preProcessor
|
|
524
|
+
}, 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({
|
|
525
|
+
key: "highThresholdCanny",
|
|
526
|
+
value: highThresholdCanny
|
|
527
|
+
})), evaluateNonTrue({
|
|
528
|
+
key: "lowThresholdCanny",
|
|
529
|
+
value: lowThresholdCanny
|
|
530
|
+
})), evaluateNonTrue({
|
|
531
|
+
key: "includeHandsAndFaceOpenPose",
|
|
532
|
+
value: includeHandsAndFaceOpenPose
|
|
533
|
+
})));
|
|
534
|
+
lis = this.globalListener({
|
|
519
535
|
taskUUID
|
|
520
536
|
});
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
537
|
+
const guideImage = await getIntervalWithPromise(
|
|
538
|
+
({ resolve, reject }) => {
|
|
539
|
+
const uploadedImage = this.getSingleMessage({
|
|
540
|
+
taskUUID
|
|
541
|
+
});
|
|
542
|
+
if (!uploadedImage)
|
|
543
|
+
return;
|
|
544
|
+
if (uploadedImage == null ? void 0 : uploadedImage.error) {
|
|
545
|
+
reject(uploadedImage);
|
|
546
|
+
return true;
|
|
547
|
+
}
|
|
548
|
+
if (uploadedImage) {
|
|
549
|
+
resolve(uploadedImage);
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
debugKey: "unprocessed-image",
|
|
555
|
+
timeoutDuration: this._timeoutDuration
|
|
556
|
+
}
|
|
557
|
+
);
|
|
558
|
+
lis.destroy();
|
|
559
|
+
return guideImage;
|
|
531
560
|
},
|
|
532
|
-
{
|
|
561
|
+
{
|
|
562
|
+
maxRetries: totalRetry,
|
|
563
|
+
callback: () => {
|
|
564
|
+
lis == null ? void 0 : lis.destroy();
|
|
565
|
+
}
|
|
566
|
+
}
|
|
533
567
|
);
|
|
534
|
-
lis.destroy();
|
|
535
|
-
return guideImage;
|
|
536
568
|
} catch (e) {
|
|
537
569
|
throw e;
|
|
538
570
|
}
|
|
@@ -540,43 +572,57 @@ var RunwareBase = class {
|
|
|
540
572
|
this.requestImageToText = async ({
|
|
541
573
|
inputImage,
|
|
542
574
|
includeCost,
|
|
543
|
-
customTaskUUID
|
|
575
|
+
customTaskUUID,
|
|
576
|
+
retry
|
|
544
577
|
}) => {
|
|
578
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
579
|
+
let lis = void 0;
|
|
545
580
|
try {
|
|
546
|
-
await
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
581
|
+
return await asyncRetry(
|
|
582
|
+
async () => {
|
|
583
|
+
await this.ensureConnection();
|
|
584
|
+
const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
|
|
585
|
+
const taskUUID = customTaskUUID || getUUID();
|
|
586
|
+
this.send(__spreadValues({
|
|
587
|
+
taskUUID,
|
|
588
|
+
taskType: "imageCaption" /* IMAGE_CAPTION */,
|
|
589
|
+
inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
|
|
590
|
+
}, evaluateNonTrue({ key: "includeCost", value: includeCost })));
|
|
591
|
+
lis = this.globalListener({
|
|
592
|
+
taskUUID
|
|
593
|
+
});
|
|
594
|
+
const response = await getIntervalWithPromise(
|
|
595
|
+
({ resolve, reject }) => {
|
|
596
|
+
const newReverseClip = this.getSingleMessage({
|
|
597
|
+
taskUUID
|
|
598
|
+
});
|
|
599
|
+
if (!newReverseClip)
|
|
600
|
+
return;
|
|
601
|
+
if (newReverseClip == null ? void 0 : newReverseClip.error) {
|
|
602
|
+
reject(newReverseClip);
|
|
603
|
+
return true;
|
|
604
|
+
}
|
|
605
|
+
if (newReverseClip) {
|
|
606
|
+
delete this._globalMessages[taskUUID];
|
|
607
|
+
resolve(newReverseClip);
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
debugKey: "remove-image-background",
|
|
613
|
+
timeoutDuration: this._timeoutDuration
|
|
573
614
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
615
|
+
);
|
|
616
|
+
lis.destroy();
|
|
617
|
+
return response;
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
maxRetries: totalRetry,
|
|
621
|
+
callback: () => {
|
|
622
|
+
lis == null ? void 0 : lis.destroy();
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
);
|
|
580
626
|
} catch (e) {
|
|
581
627
|
throw e;
|
|
582
628
|
}
|
|
@@ -593,53 +639,70 @@ var RunwareBase = class {
|
|
|
593
639
|
alphaMattingBackgroundThreshold,
|
|
594
640
|
alphaMattingErodeSize,
|
|
595
641
|
includeCost,
|
|
596
|
-
customTaskUUID
|
|
642
|
+
customTaskUUID,
|
|
643
|
+
retry
|
|
597
644
|
}) => {
|
|
645
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
646
|
+
let lis = void 0;
|
|
598
647
|
try {
|
|
599
|
-
await
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
key: "
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
key: "
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
648
|
+
return await asyncRetry(
|
|
649
|
+
async () => {
|
|
650
|
+
await this.ensureConnection();
|
|
651
|
+
const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
|
|
652
|
+
const taskUUID = customTaskUUID || getUUID();
|
|
653
|
+
this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
654
|
+
taskType: "imageBackgroundRemoval" /* IMAGE_BACKGROUND_REMOVAL */,
|
|
655
|
+
taskUUID,
|
|
656
|
+
inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
|
|
657
|
+
}, evaluateNonTrue({ key: "rgba", value: rgba })), evaluateNonTrue({
|
|
658
|
+
key: "postProcessMask",
|
|
659
|
+
value: postProcessMask
|
|
660
|
+
})), evaluateNonTrue({
|
|
661
|
+
key: "returnOnlyMask",
|
|
662
|
+
value: returnOnlyMask
|
|
663
|
+
})), evaluateNonTrue({ key: "alphaMatting", value: alphaMatting })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
|
|
664
|
+
key: "alphaMattingForegroundThreshold",
|
|
665
|
+
value: alphaMattingForegroundThreshold
|
|
666
|
+
})), evaluateNonTrue({
|
|
667
|
+
key: "alphaMattingBackgroundThreshold",
|
|
668
|
+
value: alphaMattingBackgroundThreshold
|
|
669
|
+
})), evaluateNonTrue({
|
|
670
|
+
key: "alphaMattingErodeSize",
|
|
671
|
+
value: alphaMattingErodeSize
|
|
672
|
+
})), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })));
|
|
673
|
+
lis = this.globalListener({
|
|
674
|
+
taskUUID
|
|
675
|
+
});
|
|
676
|
+
const response = await getIntervalWithPromise(
|
|
677
|
+
({ resolve, reject }) => {
|
|
678
|
+
const newRemoveBackground = this.getSingleMessage({ taskUUID });
|
|
679
|
+
if (!newRemoveBackground)
|
|
680
|
+
return;
|
|
681
|
+
if (newRemoveBackground == null ? void 0 : newRemoveBackground.error) {
|
|
682
|
+
reject(newRemoveBackground);
|
|
683
|
+
return true;
|
|
684
|
+
}
|
|
685
|
+
if (newRemoveBackground) {
|
|
686
|
+
delete this._globalMessages[taskUUID];
|
|
687
|
+
resolve(newRemoveBackground);
|
|
688
|
+
return true;
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
debugKey: "remove-image-background",
|
|
693
|
+
timeoutDuration: this._timeoutDuration
|
|
636
694
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
695
|
+
);
|
|
696
|
+
lis.destroy();
|
|
697
|
+
return response;
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
maxRetries: totalRetry,
|
|
701
|
+
callback: () => {
|
|
702
|
+
lis == null ? void 0 : lis.destroy();
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
);
|
|
643
706
|
} catch (e) {
|
|
644
707
|
throw e;
|
|
645
708
|
}
|
|
@@ -650,43 +713,54 @@ var RunwareBase = class {
|
|
|
650
713
|
outputType,
|
|
651
714
|
outputFormat,
|
|
652
715
|
includeCost,
|
|
653
|
-
customTaskUUID
|
|
716
|
+
customTaskUUID,
|
|
717
|
+
retry
|
|
654
718
|
}) => {
|
|
719
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
720
|
+
let lis = void 0;
|
|
655
721
|
try {
|
|
656
|
-
await
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
722
|
+
return await asyncRetry(
|
|
723
|
+
async () => {
|
|
724
|
+
await this.ensureConnection();
|
|
725
|
+
let imageUploaded;
|
|
726
|
+
imageUploaded = await this.uploadImage(inputImage);
|
|
727
|
+
const taskUUID = customTaskUUID || getUUID();
|
|
728
|
+
this.send(__spreadValues(__spreadValues(__spreadValues({
|
|
729
|
+
taskUUID,
|
|
730
|
+
inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
|
|
731
|
+
taskType: "imageUpscale" /* IMAGE_UPSCALE */,
|
|
732
|
+
upscaleFactor
|
|
733
|
+
}, evaluateNonTrue({ key: "includeCost", value: includeCost })), outputType ? { outputType } : {}), outputFormat ? { outputFormat } : {}));
|
|
734
|
+
lis = this.globalListener({
|
|
735
|
+
taskUUID
|
|
736
|
+
});
|
|
737
|
+
const response = await getIntervalWithPromise(
|
|
738
|
+
({ resolve, reject }) => {
|
|
739
|
+
const newUpscaleGan = this.getSingleMessage({ taskUUID });
|
|
740
|
+
if (!newUpscaleGan)
|
|
741
|
+
return;
|
|
742
|
+
if (newUpscaleGan == null ? void 0 : newUpscaleGan.error) {
|
|
743
|
+
reject(newUpscaleGan);
|
|
744
|
+
return true;
|
|
745
|
+
}
|
|
746
|
+
if (newUpscaleGan) {
|
|
747
|
+
delete this._globalMessages[taskUUID];
|
|
748
|
+
resolve(newUpscaleGan);
|
|
749
|
+
return true;
|
|
750
|
+
}
|
|
751
|
+
},
|
|
752
|
+
{ debugKey: "upscale-gan", timeoutDuration: this._timeoutDuration }
|
|
753
|
+
);
|
|
754
|
+
lis.destroy();
|
|
755
|
+
return response;
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
maxRetries: totalRetry,
|
|
759
|
+
callback: () => {
|
|
760
|
+
lis == null ? void 0 : lis.destroy();
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
);
|
|
690
764
|
} catch (e) {
|
|
691
765
|
throw e;
|
|
692
766
|
}
|
|
@@ -696,41 +770,55 @@ var RunwareBase = class {
|
|
|
696
770
|
promptMaxLength = 380,
|
|
697
771
|
promptVersions = 1,
|
|
698
772
|
includeCost,
|
|
699
|
-
customTaskUUID
|
|
773
|
+
customTaskUUID,
|
|
774
|
+
retry
|
|
700
775
|
}) => {
|
|
776
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
777
|
+
let lis = void 0;
|
|
701
778
|
try {
|
|
702
|
-
await
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
779
|
+
return await asyncRetry(
|
|
780
|
+
async () => {
|
|
781
|
+
await this.ensureConnection();
|
|
782
|
+
const taskUUID = customTaskUUID || getUUID();
|
|
783
|
+
this.send(__spreadProps(__spreadValues({
|
|
784
|
+
prompt,
|
|
785
|
+
taskUUID,
|
|
786
|
+
promptMaxLength,
|
|
787
|
+
promptVersions
|
|
788
|
+
}, evaluateNonTrue({ key: "includeCost", value: includeCost })), {
|
|
789
|
+
taskType: "promptEnhance" /* PROMPT_ENHANCE */
|
|
790
|
+
}));
|
|
791
|
+
lis = this.globalListener({
|
|
792
|
+
taskUUID
|
|
793
|
+
});
|
|
794
|
+
const response = await getIntervalWithPromise(
|
|
795
|
+
({ resolve, reject }) => {
|
|
796
|
+
const reducedPrompt = this._globalMessages[taskUUID];
|
|
797
|
+
if (reducedPrompt == null ? void 0 : reducedPrompt.error) {
|
|
798
|
+
reject(reducedPrompt);
|
|
799
|
+
return true;
|
|
800
|
+
}
|
|
801
|
+
if ((reducedPrompt == null ? void 0 : reducedPrompt.length) >= promptVersions) {
|
|
802
|
+
delete this._globalMessages[taskUUID];
|
|
803
|
+
resolve(reducedPrompt);
|
|
804
|
+
return true;
|
|
805
|
+
}
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
debugKey: "enhance-prompt",
|
|
809
|
+
timeoutDuration: this._timeoutDuration
|
|
727
810
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
811
|
+
);
|
|
812
|
+
lis.destroy();
|
|
813
|
+
return response;
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
maxRetries: totalRetry,
|
|
817
|
+
callback: () => {
|
|
818
|
+
lis == null ? void 0 : lis.destroy();
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
);
|
|
734
822
|
} catch (e) {
|
|
735
823
|
throw e;
|
|
736
824
|
}
|
|
@@ -753,6 +841,17 @@ var RunwareBase = class {
|
|
|
753
841
|
this._url = url;
|
|
754
842
|
this._sdkType = "CLIENT" /* CLIENT */;
|
|
755
843
|
this._shouldReconnect = shouldReconnect;
|
|
844
|
+
this._globalMaxRetries = globalMaxRetries;
|
|
845
|
+
this._timeoutDuration = timeoutDuration;
|
|
846
|
+
}
|
|
847
|
+
static async initialize(props) {
|
|
848
|
+
try {
|
|
849
|
+
const instance = new this(props);
|
|
850
|
+
await instance.ensureConnection();
|
|
851
|
+
return instance;
|
|
852
|
+
} catch (e) {
|
|
853
|
+
throw e;
|
|
854
|
+
}
|
|
756
855
|
}
|
|
757
856
|
// protected addListener({
|
|
758
857
|
// lis,
|
|
@@ -824,7 +923,7 @@ var RunwareBase = class {
|
|
|
824
923
|
lis: (m) => {
|
|
825
924
|
var _a, _b;
|
|
826
925
|
if (m == null ? void 0 : m.error) {
|
|
827
|
-
this._invalidAPIkey =
|
|
926
|
+
this._invalidAPIkey = m;
|
|
828
927
|
return;
|
|
829
928
|
}
|
|
830
929
|
this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
|
|
@@ -843,7 +942,6 @@ var RunwareBase = class {
|
|
|
843
942
|
};
|
|
844
943
|
this._ws.onclose = (e) => {
|
|
845
944
|
if (this._invalidAPIkey) {
|
|
846
|
-
console.error(this._invalidAPIkey);
|
|
847
945
|
return;
|
|
848
946
|
}
|
|
849
947
|
};
|
|
@@ -951,13 +1049,13 @@ var RunwareBase = class {
|
|
|
951
1049
|
onPartialImages,
|
|
952
1050
|
includeCost,
|
|
953
1051
|
customTaskUUID,
|
|
954
|
-
retry
|
|
1052
|
+
retry
|
|
955
1053
|
}) {
|
|
956
|
-
await this.ensureConnection();
|
|
957
1054
|
let lis = void 0;
|
|
958
1055
|
let requestObject = void 0;
|
|
959
1056
|
let taskUUIDs = [];
|
|
960
1057
|
let retryCount = 0;
|
|
1058
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
961
1059
|
try {
|
|
962
1060
|
await this.ensureConnection();
|
|
963
1061
|
let seedImageUUID = null;
|
|
@@ -1047,7 +1145,7 @@ var RunwareBase = class {
|
|
|
1047
1145
|
return promise;
|
|
1048
1146
|
},
|
|
1049
1147
|
{
|
|
1050
|
-
maxRetries:
|
|
1148
|
+
maxRetries: totalRetry,
|
|
1051
1149
|
callback: () => {
|
|
1052
1150
|
lis == null ? void 0 : lis.destroy();
|
|
1053
1151
|
}
|
|
@@ -1057,7 +1155,7 @@ var RunwareBase = class {
|
|
|
1057
1155
|
if (e.taskUUID) {
|
|
1058
1156
|
throw e;
|
|
1059
1157
|
}
|
|
1060
|
-
if (retryCount >=
|
|
1158
|
+
if (retryCount >= totalRetry) {
|
|
1061
1159
|
return this.handleIncompleteImages({ taskUUIDs, error: e });
|
|
1062
1160
|
}
|
|
1063
1161
|
}
|
|
@@ -1109,18 +1207,15 @@ var RunwareBase = class {
|
|
|
1109
1207
|
if (hasConnected) {
|
|
1110
1208
|
clearAllIntervals();
|
|
1111
1209
|
resolve(true);
|
|
1210
|
+
return;
|
|
1112
1211
|
}
|
|
1113
1212
|
if (!!this._invalidAPIkey) {
|
|
1114
1213
|
clearAllIntervals();
|
|
1115
|
-
reject(
|
|
1214
|
+
reject(this._invalidAPIkey);
|
|
1116
1215
|
return;
|
|
1117
1216
|
}
|
|
1118
1217
|
}, pollingInterval);
|
|
1119
1218
|
});
|
|
1120
|
-
if (!isConnected) {
|
|
1121
|
-
this.connect();
|
|
1122
|
-
await delay(2);
|
|
1123
|
-
}
|
|
1124
1219
|
} catch (e) {
|
|
1125
1220
|
throw (_a = this._invalidAPIkey) != null ? _a : "Could not connect to server. Ensure your API key is correct";
|
|
1126
1221
|
}
|
|
@@ -1152,7 +1247,11 @@ var RunwareBase = class {
|
|
|
1152
1247
|
return true;
|
|
1153
1248
|
}
|
|
1154
1249
|
},
|
|
1155
|
-
{
|
|
1250
|
+
{
|
|
1251
|
+
debugKey: "getting images",
|
|
1252
|
+
shouldThrowError,
|
|
1253
|
+
timeoutDuration: this._timeoutDuration
|
|
1254
|
+
}
|
|
1156
1255
|
);
|
|
1157
1256
|
}
|
|
1158
1257
|
handleIncompleteImages({
|
|
@@ -1177,22 +1276,21 @@ var RunwareBase = class {
|
|
|
1177
1276
|
// Runware/Runware-client.ts
|
|
1178
1277
|
var import_reconnect = __toESM(require_reconnect());
|
|
1179
1278
|
var RunwareClient = class extends RunwareBase {
|
|
1180
|
-
constructor(
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
}
|
|
1279
|
+
constructor(props) {
|
|
1280
|
+
const _a = props, { shouldReconnect } = _a, rest = __objRest(_a, ["shouldReconnect"]);
|
|
1281
|
+
super(rest);
|
|
1282
|
+
this._ws = new import_reconnect.default(
|
|
1283
|
+
this._url
|
|
1284
|
+
);
|
|
1285
|
+
this.connect();
|
|
1188
1286
|
}
|
|
1189
1287
|
};
|
|
1190
1288
|
|
|
1191
1289
|
// Runware/Runware-server.ts
|
|
1192
1290
|
var import_ws = __toESM(require("ws"));
|
|
1193
1291
|
var RunwareServer = class extends RunwareBase {
|
|
1194
|
-
constructor(
|
|
1195
|
-
super(
|
|
1292
|
+
constructor(props) {
|
|
1293
|
+
super(props);
|
|
1196
1294
|
this._instantiated = false;
|
|
1197
1295
|
this._listeners = [];
|
|
1198
1296
|
this._reconnectingIntervalId = null;
|
|
@@ -1213,9 +1311,7 @@ var RunwareServer = class extends RunwareBase {
|
|
|
1213
1311
|
}
|
|
1214
1312
|
};
|
|
1215
1313
|
this._sdkType = "SERVER" /* SERVER */;
|
|
1216
|
-
|
|
1217
|
-
this.connect();
|
|
1218
|
-
}
|
|
1314
|
+
this.connect();
|
|
1219
1315
|
}
|
|
1220
1316
|
// protected addListener({
|
|
1221
1317
|
// lis,
|
|
@@ -1277,7 +1373,7 @@ var RunwareServer = class extends RunwareBase {
|
|
|
1277
1373
|
lis: (m) => {
|
|
1278
1374
|
var _a, _b;
|
|
1279
1375
|
if (m == null ? void 0 : m.error) {
|
|
1280
|
-
this._invalidAPIkey =
|
|
1376
|
+
this._invalidAPIkey = m;
|
|
1281
1377
|
return;
|
|
1282
1378
|
}
|
|
1283
1379
|
this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
|
|
@@ -1300,7 +1396,6 @@ var RunwareServer = class extends RunwareBase {
|
|
|
1300
1396
|
}
|
|
1301
1397
|
handleClose() {
|
|
1302
1398
|
if (this._invalidAPIkey) {
|
|
1303
|
-
console.error(this._invalidAPIkey);
|
|
1304
1399
|
return;
|
|
1305
1400
|
}
|
|
1306
1401
|
if (this._reconnectingIntervalId) {
|