@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.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
|
};
|
|
@@ -162,9 +174,9 @@ var require_reconnect = __commonJS({
|
|
|
162
174
|
};
|
|
163
175
|
log("init");
|
|
164
176
|
connect();
|
|
165
|
-
this.close = (code = 1e3, reason = "", { keepClosed = false, fastClose = true, delay:
|
|
166
|
-
if (
|
|
167
|
-
reconnectDelay =
|
|
177
|
+
this.close = (code = 1e3, reason = "", { keepClosed = false, fastClose = true, delay: delay3 = 0 } = {}) => {
|
|
178
|
+
if (delay3) {
|
|
179
|
+
reconnectDelay = delay3;
|
|
168
180
|
}
|
|
169
181
|
shouldRetry = !keepClosed;
|
|
170
182
|
ws.close(code, reason);
|
|
@@ -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";
|
|
@@ -297,6 +309,7 @@ var EOpenPosePreProcessor = /* @__PURE__ */ ((EOpenPosePreProcessor2) => {
|
|
|
297
309
|
// Runware/utils.ts
|
|
298
310
|
import { v4 as uuidv4, validate as validateUUID } from "uuid";
|
|
299
311
|
var TIMEOUT_DURATION = 6e4;
|
|
312
|
+
var MINIMUM_TIMEOUT_DURATION = 1e3;
|
|
300
313
|
var POLLING_INTERVAL = 100;
|
|
301
314
|
var BASE_RUNWARE_URLS = {
|
|
302
315
|
["PRODUCTION" /* PRODUCTION */]: "wss://ws-api.runware.ai/v1",
|
|
@@ -314,20 +327,20 @@ var removeFromAray = (col, targetElem) => {
|
|
|
314
327
|
};
|
|
315
328
|
var getIntervalWithPromise = (callback, {
|
|
316
329
|
debugKey = "debugKey",
|
|
317
|
-
|
|
330
|
+
timeoutDuration = TIMEOUT_DURATION,
|
|
318
331
|
shouldThrowError = true
|
|
319
332
|
}) => {
|
|
333
|
+
timeoutDuration = timeoutDuration < MINIMUM_TIMEOUT_DURATION ? MINIMUM_TIMEOUT_DURATION : timeoutDuration;
|
|
320
334
|
return new Promise((resolve, reject) => {
|
|
321
335
|
const timeoutId = setTimeout(() => {
|
|
322
336
|
if (intervalId) {
|
|
323
337
|
clearInterval(intervalId);
|
|
324
338
|
if (shouldThrowError) {
|
|
325
|
-
reject(`
|
|
326
|
-
console.error("Message could not be received for ", debugKey);
|
|
339
|
+
reject(`Response could not be received from server for ${debugKey}`);
|
|
327
340
|
}
|
|
328
341
|
}
|
|
329
342
|
clearTimeout(timeoutId);
|
|
330
|
-
},
|
|
343
|
+
}, timeoutDuration);
|
|
331
344
|
let intervalId = setInterval(async () => {
|
|
332
345
|
const shouldClear = callback({ resolve, reject, intervalId });
|
|
333
346
|
if (shouldClear) {
|
|
@@ -417,7 +430,9 @@ var RunwareBase = class {
|
|
|
417
430
|
constructor({
|
|
418
431
|
apiKey,
|
|
419
432
|
url = BASE_RUNWARE_URLS.PRODUCTION,
|
|
420
|
-
shouldReconnect = true
|
|
433
|
+
shouldReconnect = true,
|
|
434
|
+
globalMaxRetries = 2,
|
|
435
|
+
timeoutDuration = TIMEOUT_DURATION
|
|
421
436
|
}) {
|
|
422
437
|
this._listeners = [];
|
|
423
438
|
// _globalMessages: any[] = [];
|
|
@@ -466,51 +481,68 @@ var RunwareBase = class {
|
|
|
466
481
|
lowThresholdCanny,
|
|
467
482
|
includeHandsAndFaceOpenPose,
|
|
468
483
|
includeCost,
|
|
469
|
-
customTaskUUID
|
|
484
|
+
customTaskUUID,
|
|
485
|
+
retry
|
|
470
486
|
}) => {
|
|
487
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
488
|
+
let lis = void 0;
|
|
471
489
|
try {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
({ resolve, reject }) => {
|
|
496
|
-
const uploadedImage = this.getSingleMessage({
|
|
490
|
+
return await asyncRetry(
|
|
491
|
+
async () => {
|
|
492
|
+
await this.ensureConnection();
|
|
493
|
+
const image = await this.uploadImage(inputImage);
|
|
494
|
+
if (!(image == null ? void 0 : image.imageUUID))
|
|
495
|
+
return null;
|
|
496
|
+
const taskUUID = customTaskUUID || getUUID();
|
|
497
|
+
this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
498
|
+
inputImage: image.imageUUID,
|
|
499
|
+
taskType: "imageControlNetPreProcess" /* IMAGE_CONTROL_NET_PRE_PROCESS */,
|
|
500
|
+
taskUUID,
|
|
501
|
+
preProcessor
|
|
502
|
+
}, 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({
|
|
503
|
+
key: "highThresholdCanny",
|
|
504
|
+
value: highThresholdCanny
|
|
505
|
+
})), evaluateNonTrue({
|
|
506
|
+
key: "lowThresholdCanny",
|
|
507
|
+
value: lowThresholdCanny
|
|
508
|
+
})), evaluateNonTrue({
|
|
509
|
+
key: "includeHandsAndFaceOpenPose",
|
|
510
|
+
value: includeHandsAndFaceOpenPose
|
|
511
|
+
})));
|
|
512
|
+
lis = this.globalListener({
|
|
497
513
|
taskUUID
|
|
498
514
|
});
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
515
|
+
const guideImage = await getIntervalWithPromise(
|
|
516
|
+
({ resolve, reject }) => {
|
|
517
|
+
const uploadedImage = this.getSingleMessage({
|
|
518
|
+
taskUUID
|
|
519
|
+
});
|
|
520
|
+
if (!uploadedImage)
|
|
521
|
+
return;
|
|
522
|
+
if (uploadedImage == null ? void 0 : uploadedImage.error) {
|
|
523
|
+
reject(uploadedImage);
|
|
524
|
+
return true;
|
|
525
|
+
}
|
|
526
|
+
if (uploadedImage) {
|
|
527
|
+
resolve(uploadedImage);
|
|
528
|
+
return true;
|
|
529
|
+
}
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
debugKey: "unprocessed-image",
|
|
533
|
+
timeoutDuration: this._timeoutDuration
|
|
534
|
+
}
|
|
535
|
+
);
|
|
536
|
+
lis.destroy();
|
|
537
|
+
return guideImage;
|
|
509
538
|
},
|
|
510
|
-
{
|
|
539
|
+
{
|
|
540
|
+
maxRetries: totalRetry,
|
|
541
|
+
callback: () => {
|
|
542
|
+
lis == null ? void 0 : lis.destroy();
|
|
543
|
+
}
|
|
544
|
+
}
|
|
511
545
|
);
|
|
512
|
-
lis.destroy();
|
|
513
|
-
return guideImage;
|
|
514
546
|
} catch (e) {
|
|
515
547
|
throw e;
|
|
516
548
|
}
|
|
@@ -518,43 +550,57 @@ var RunwareBase = class {
|
|
|
518
550
|
this.requestImageToText = async ({
|
|
519
551
|
inputImage,
|
|
520
552
|
includeCost,
|
|
521
|
-
customTaskUUID
|
|
553
|
+
customTaskUUID,
|
|
554
|
+
retry
|
|
522
555
|
}) => {
|
|
556
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
557
|
+
let lis = void 0;
|
|
523
558
|
try {
|
|
524
|
-
await
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
559
|
+
return await asyncRetry(
|
|
560
|
+
async () => {
|
|
561
|
+
await this.ensureConnection();
|
|
562
|
+
const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
|
|
563
|
+
const taskUUID = customTaskUUID || getUUID();
|
|
564
|
+
this.send(__spreadValues({
|
|
565
|
+
taskUUID,
|
|
566
|
+
taskType: "imageCaption" /* IMAGE_CAPTION */,
|
|
567
|
+
inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
|
|
568
|
+
}, evaluateNonTrue({ key: "includeCost", value: includeCost })));
|
|
569
|
+
lis = this.globalListener({
|
|
570
|
+
taskUUID
|
|
571
|
+
});
|
|
572
|
+
const response = await getIntervalWithPromise(
|
|
573
|
+
({ resolve, reject }) => {
|
|
574
|
+
const newReverseClip = this.getSingleMessage({
|
|
575
|
+
taskUUID
|
|
576
|
+
});
|
|
577
|
+
if (!newReverseClip)
|
|
578
|
+
return;
|
|
579
|
+
if (newReverseClip == null ? void 0 : newReverseClip.error) {
|
|
580
|
+
reject(newReverseClip);
|
|
581
|
+
return true;
|
|
582
|
+
}
|
|
583
|
+
if (newReverseClip) {
|
|
584
|
+
delete this._globalMessages[taskUUID];
|
|
585
|
+
resolve(newReverseClip);
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
debugKey: "remove-image-background",
|
|
591
|
+
timeoutDuration: this._timeoutDuration
|
|
551
592
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
593
|
+
);
|
|
594
|
+
lis.destroy();
|
|
595
|
+
return response;
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
maxRetries: totalRetry,
|
|
599
|
+
callback: () => {
|
|
600
|
+
lis == null ? void 0 : lis.destroy();
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
);
|
|
558
604
|
} catch (e) {
|
|
559
605
|
throw e;
|
|
560
606
|
}
|
|
@@ -571,53 +617,70 @@ var RunwareBase = class {
|
|
|
571
617
|
alphaMattingBackgroundThreshold,
|
|
572
618
|
alphaMattingErodeSize,
|
|
573
619
|
includeCost,
|
|
574
|
-
customTaskUUID
|
|
620
|
+
customTaskUUID,
|
|
621
|
+
retry
|
|
575
622
|
}) => {
|
|
623
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
624
|
+
let lis = void 0;
|
|
576
625
|
try {
|
|
577
|
-
await
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
key: "
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
key: "
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
626
|
+
return await asyncRetry(
|
|
627
|
+
async () => {
|
|
628
|
+
await this.ensureConnection();
|
|
629
|
+
const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
|
|
630
|
+
const taskUUID = customTaskUUID || getUUID();
|
|
631
|
+
this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
632
|
+
taskType: "imageBackgroundRemoval" /* IMAGE_BACKGROUND_REMOVAL */,
|
|
633
|
+
taskUUID,
|
|
634
|
+
inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
|
|
635
|
+
}, evaluateNonTrue({ key: "rgba", value: rgba })), evaluateNonTrue({
|
|
636
|
+
key: "postProcessMask",
|
|
637
|
+
value: postProcessMask
|
|
638
|
+
})), evaluateNonTrue({
|
|
639
|
+
key: "returnOnlyMask",
|
|
640
|
+
value: returnOnlyMask
|
|
641
|
+
})), evaluateNonTrue({ key: "alphaMatting", value: alphaMatting })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
|
|
642
|
+
key: "alphaMattingForegroundThreshold",
|
|
643
|
+
value: alphaMattingForegroundThreshold
|
|
644
|
+
})), evaluateNonTrue({
|
|
645
|
+
key: "alphaMattingBackgroundThreshold",
|
|
646
|
+
value: alphaMattingBackgroundThreshold
|
|
647
|
+
})), evaluateNonTrue({
|
|
648
|
+
key: "alphaMattingErodeSize",
|
|
649
|
+
value: alphaMattingErodeSize
|
|
650
|
+
})), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })));
|
|
651
|
+
lis = this.globalListener({
|
|
652
|
+
taskUUID
|
|
653
|
+
});
|
|
654
|
+
const response = await getIntervalWithPromise(
|
|
655
|
+
({ resolve, reject }) => {
|
|
656
|
+
const newRemoveBackground = this.getSingleMessage({ taskUUID });
|
|
657
|
+
if (!newRemoveBackground)
|
|
658
|
+
return;
|
|
659
|
+
if (newRemoveBackground == null ? void 0 : newRemoveBackground.error) {
|
|
660
|
+
reject(newRemoveBackground);
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
if (newRemoveBackground) {
|
|
664
|
+
delete this._globalMessages[taskUUID];
|
|
665
|
+
resolve(newRemoveBackground);
|
|
666
|
+
return true;
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
debugKey: "remove-image-background",
|
|
671
|
+
timeoutDuration: this._timeoutDuration
|
|
614
672
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
673
|
+
);
|
|
674
|
+
lis.destroy();
|
|
675
|
+
return response;
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
maxRetries: totalRetry,
|
|
679
|
+
callback: () => {
|
|
680
|
+
lis == null ? void 0 : lis.destroy();
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
);
|
|
621
684
|
} catch (e) {
|
|
622
685
|
throw e;
|
|
623
686
|
}
|
|
@@ -628,43 +691,54 @@ var RunwareBase = class {
|
|
|
628
691
|
outputType,
|
|
629
692
|
outputFormat,
|
|
630
693
|
includeCost,
|
|
631
|
-
customTaskUUID
|
|
694
|
+
customTaskUUID,
|
|
695
|
+
retry
|
|
632
696
|
}) => {
|
|
697
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
698
|
+
let lis = void 0;
|
|
633
699
|
try {
|
|
634
|
-
await
|
|
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
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
700
|
+
return await asyncRetry(
|
|
701
|
+
async () => {
|
|
702
|
+
await this.ensureConnection();
|
|
703
|
+
let imageUploaded;
|
|
704
|
+
imageUploaded = await this.uploadImage(inputImage);
|
|
705
|
+
const taskUUID = customTaskUUID || getUUID();
|
|
706
|
+
this.send(__spreadValues(__spreadValues(__spreadValues({
|
|
707
|
+
taskUUID,
|
|
708
|
+
inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
|
|
709
|
+
taskType: "imageUpscale" /* IMAGE_UPSCALE */,
|
|
710
|
+
upscaleFactor
|
|
711
|
+
}, evaluateNonTrue({ key: "includeCost", value: includeCost })), outputType ? { outputType } : {}), outputFormat ? { outputFormat } : {}));
|
|
712
|
+
lis = this.globalListener({
|
|
713
|
+
taskUUID
|
|
714
|
+
});
|
|
715
|
+
const response = await getIntervalWithPromise(
|
|
716
|
+
({ resolve, reject }) => {
|
|
717
|
+
const newUpscaleGan = this.getSingleMessage({ taskUUID });
|
|
718
|
+
if (!newUpscaleGan)
|
|
719
|
+
return;
|
|
720
|
+
if (newUpscaleGan == null ? void 0 : newUpscaleGan.error) {
|
|
721
|
+
reject(newUpscaleGan);
|
|
722
|
+
return true;
|
|
723
|
+
}
|
|
724
|
+
if (newUpscaleGan) {
|
|
725
|
+
delete this._globalMessages[taskUUID];
|
|
726
|
+
resolve(newUpscaleGan);
|
|
727
|
+
return true;
|
|
728
|
+
}
|
|
729
|
+
},
|
|
730
|
+
{ debugKey: "upscale-gan", timeoutDuration: this._timeoutDuration }
|
|
731
|
+
);
|
|
732
|
+
lis.destroy();
|
|
733
|
+
return response;
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
maxRetries: totalRetry,
|
|
737
|
+
callback: () => {
|
|
738
|
+
lis == null ? void 0 : lis.destroy();
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
);
|
|
668
742
|
} catch (e) {
|
|
669
743
|
throw e;
|
|
670
744
|
}
|
|
@@ -674,41 +748,55 @@ var RunwareBase = class {
|
|
|
674
748
|
promptMaxLength = 380,
|
|
675
749
|
promptVersions = 1,
|
|
676
750
|
includeCost,
|
|
677
|
-
customTaskUUID
|
|
751
|
+
customTaskUUID,
|
|
752
|
+
retry
|
|
678
753
|
}) => {
|
|
754
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
755
|
+
let lis = void 0;
|
|
679
756
|
try {
|
|
680
|
-
await
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
757
|
+
return await asyncRetry(
|
|
758
|
+
async () => {
|
|
759
|
+
await this.ensureConnection();
|
|
760
|
+
const taskUUID = customTaskUUID || getUUID();
|
|
761
|
+
this.send(__spreadProps(__spreadValues({
|
|
762
|
+
prompt,
|
|
763
|
+
taskUUID,
|
|
764
|
+
promptMaxLength,
|
|
765
|
+
promptVersions
|
|
766
|
+
}, evaluateNonTrue({ key: "includeCost", value: includeCost })), {
|
|
767
|
+
taskType: "promptEnhance" /* PROMPT_ENHANCE */
|
|
768
|
+
}));
|
|
769
|
+
lis = this.globalListener({
|
|
770
|
+
taskUUID
|
|
771
|
+
});
|
|
772
|
+
const response = await getIntervalWithPromise(
|
|
773
|
+
({ resolve, reject }) => {
|
|
774
|
+
const reducedPrompt = this._globalMessages[taskUUID];
|
|
775
|
+
if (reducedPrompt == null ? void 0 : reducedPrompt.error) {
|
|
776
|
+
reject(reducedPrompt);
|
|
777
|
+
return true;
|
|
778
|
+
}
|
|
779
|
+
if ((reducedPrompt == null ? void 0 : reducedPrompt.length) >= promptVersions) {
|
|
780
|
+
delete this._globalMessages[taskUUID];
|
|
781
|
+
resolve(reducedPrompt);
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
debugKey: "enhance-prompt",
|
|
787
|
+
timeoutDuration: this._timeoutDuration
|
|
705
788
|
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
789
|
+
);
|
|
790
|
+
lis.destroy();
|
|
791
|
+
return response;
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
maxRetries: totalRetry,
|
|
795
|
+
callback: () => {
|
|
796
|
+
lis == null ? void 0 : lis.destroy();
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
);
|
|
712
800
|
} catch (e) {
|
|
713
801
|
throw e;
|
|
714
802
|
}
|
|
@@ -731,6 +819,17 @@ var RunwareBase = class {
|
|
|
731
819
|
this._url = url;
|
|
732
820
|
this._sdkType = "CLIENT" /* CLIENT */;
|
|
733
821
|
this._shouldReconnect = shouldReconnect;
|
|
822
|
+
this._globalMaxRetries = globalMaxRetries;
|
|
823
|
+
this._timeoutDuration = timeoutDuration;
|
|
824
|
+
}
|
|
825
|
+
static async initialize(props) {
|
|
826
|
+
try {
|
|
827
|
+
const instance = new this(props);
|
|
828
|
+
await instance.ensureConnection();
|
|
829
|
+
return instance;
|
|
830
|
+
} catch (e) {
|
|
831
|
+
throw e;
|
|
832
|
+
}
|
|
734
833
|
}
|
|
735
834
|
// protected addListener({
|
|
736
835
|
// lis,
|
|
@@ -802,7 +901,7 @@ var RunwareBase = class {
|
|
|
802
901
|
lis: (m) => {
|
|
803
902
|
var _a, _b;
|
|
804
903
|
if (m == null ? void 0 : m.error) {
|
|
805
|
-
this._invalidAPIkey =
|
|
904
|
+
this._invalidAPIkey = m;
|
|
806
905
|
return;
|
|
807
906
|
}
|
|
808
907
|
this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
|
|
@@ -821,7 +920,6 @@ var RunwareBase = class {
|
|
|
821
920
|
};
|
|
822
921
|
this._ws.onclose = (e) => {
|
|
823
922
|
if (this._invalidAPIkey) {
|
|
824
|
-
console.error(this._invalidAPIkey);
|
|
825
923
|
return;
|
|
826
924
|
}
|
|
827
925
|
};
|
|
@@ -929,13 +1027,13 @@ var RunwareBase = class {
|
|
|
929
1027
|
onPartialImages,
|
|
930
1028
|
includeCost,
|
|
931
1029
|
customTaskUUID,
|
|
932
|
-
retry
|
|
1030
|
+
retry
|
|
933
1031
|
}) {
|
|
934
|
-
await this.ensureConnection();
|
|
935
1032
|
let lis = void 0;
|
|
936
1033
|
let requestObject = void 0;
|
|
937
1034
|
let taskUUIDs = [];
|
|
938
1035
|
let retryCount = 0;
|
|
1036
|
+
const totalRetry = retry || this._globalMaxRetries;
|
|
939
1037
|
try {
|
|
940
1038
|
await this.ensureConnection();
|
|
941
1039
|
let seedImageUUID = null;
|
|
@@ -1025,7 +1123,7 @@ var RunwareBase = class {
|
|
|
1025
1123
|
return promise;
|
|
1026
1124
|
},
|
|
1027
1125
|
{
|
|
1028
|
-
maxRetries:
|
|
1126
|
+
maxRetries: totalRetry,
|
|
1029
1127
|
callback: () => {
|
|
1030
1128
|
lis == null ? void 0 : lis.destroy();
|
|
1031
1129
|
}
|
|
@@ -1035,7 +1133,7 @@ var RunwareBase = class {
|
|
|
1035
1133
|
if (e.taskUUID) {
|
|
1036
1134
|
throw e;
|
|
1037
1135
|
}
|
|
1038
|
-
if (retryCount >=
|
|
1136
|
+
if (retryCount >= totalRetry) {
|
|
1039
1137
|
return this.handleIncompleteImages({ taskUUIDs, error: e });
|
|
1040
1138
|
}
|
|
1041
1139
|
}
|
|
@@ -1087,18 +1185,15 @@ var RunwareBase = class {
|
|
|
1087
1185
|
if (hasConnected) {
|
|
1088
1186
|
clearAllIntervals();
|
|
1089
1187
|
resolve(true);
|
|
1188
|
+
return;
|
|
1090
1189
|
}
|
|
1091
1190
|
if (!!this._invalidAPIkey) {
|
|
1092
1191
|
clearAllIntervals();
|
|
1093
|
-
reject(
|
|
1192
|
+
reject(this._invalidAPIkey);
|
|
1094
1193
|
return;
|
|
1095
1194
|
}
|
|
1096
1195
|
}, pollingInterval);
|
|
1097
1196
|
});
|
|
1098
|
-
if (!isConnected) {
|
|
1099
|
-
this.connect();
|
|
1100
|
-
await delay(2);
|
|
1101
|
-
}
|
|
1102
1197
|
} catch (e) {
|
|
1103
1198
|
throw (_a = this._invalidAPIkey) != null ? _a : "Could not connect to server. Ensure your API key is correct";
|
|
1104
1199
|
}
|
|
@@ -1130,7 +1225,11 @@ var RunwareBase = class {
|
|
|
1130
1225
|
return true;
|
|
1131
1226
|
}
|
|
1132
1227
|
},
|
|
1133
|
-
{
|
|
1228
|
+
{
|
|
1229
|
+
debugKey: "getting images",
|
|
1230
|
+
shouldThrowError,
|
|
1231
|
+
timeoutDuration: this._timeoutDuration
|
|
1232
|
+
}
|
|
1134
1233
|
);
|
|
1135
1234
|
}
|
|
1136
1235
|
handleIncompleteImages({
|
|
@@ -1155,22 +1254,21 @@ var RunwareBase = class {
|
|
|
1155
1254
|
// Runware/Runware-client.ts
|
|
1156
1255
|
var import_reconnect = __toESM(require_reconnect());
|
|
1157
1256
|
var RunwareClient = class extends RunwareBase {
|
|
1158
|
-
constructor(
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
}
|
|
1257
|
+
constructor(props) {
|
|
1258
|
+
const _a = props, { shouldReconnect } = _a, rest = __objRest(_a, ["shouldReconnect"]);
|
|
1259
|
+
super(rest);
|
|
1260
|
+
this._ws = new import_reconnect.default(
|
|
1261
|
+
this._url
|
|
1262
|
+
);
|
|
1263
|
+
this.connect();
|
|
1166
1264
|
}
|
|
1167
1265
|
};
|
|
1168
1266
|
|
|
1169
1267
|
// Runware/Runware-server.ts
|
|
1170
1268
|
import WebSocket2 from "ws";
|
|
1171
1269
|
var RunwareServer = class extends RunwareBase {
|
|
1172
|
-
constructor(
|
|
1173
|
-
super(
|
|
1270
|
+
constructor(props) {
|
|
1271
|
+
super(props);
|
|
1174
1272
|
this._instantiated = false;
|
|
1175
1273
|
this._listeners = [];
|
|
1176
1274
|
this._reconnectingIntervalId = null;
|
|
@@ -1191,9 +1289,7 @@ var RunwareServer = class extends RunwareBase {
|
|
|
1191
1289
|
}
|
|
1192
1290
|
};
|
|
1193
1291
|
this._sdkType = "SERVER" /* SERVER */;
|
|
1194
|
-
|
|
1195
|
-
this.connect();
|
|
1196
|
-
}
|
|
1292
|
+
this.connect();
|
|
1197
1293
|
}
|
|
1198
1294
|
// protected addListener({
|
|
1199
1295
|
// lis,
|
|
@@ -1255,7 +1351,7 @@ var RunwareServer = class extends RunwareBase {
|
|
|
1255
1351
|
lis: (m) => {
|
|
1256
1352
|
var _a, _b;
|
|
1257
1353
|
if (m == null ? void 0 : m.error) {
|
|
1258
|
-
this._invalidAPIkey =
|
|
1354
|
+
this._invalidAPIkey = m;
|
|
1259
1355
|
return;
|
|
1260
1356
|
}
|
|
1261
1357
|
this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
|
|
@@ -1278,7 +1374,6 @@ var RunwareServer = class extends RunwareBase {
|
|
|
1278
1374
|
}
|
|
1279
1375
|
handleClose() {
|
|
1280
1376
|
if (this._invalidAPIkey) {
|
|
1281
|
-
console.error(this._invalidAPIkey);
|
|
1282
1377
|
return;
|
|
1283
1378
|
}
|
|
1284
1379
|
if (this._reconnectingIntervalId) {
|