@runware/sdk-js 1.1.12 → 1.1.13-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/esm/Runware/Runware-base.d.ts +40 -0
- package/dist/esm/Runware/Runware-base.js +651 -0
- package/dist/esm/Runware/Runware-client.d.ts +5 -0
- package/dist/esm/Runware/Runware-client.js +18 -0
- package/dist/esm/Runware/Runware-server.d.ts +14 -0
- package/dist/esm/Runware/Runware-server.js +155 -0
- package/dist/esm/Runware/Runware.d.ts +4 -0
- package/dist/esm/Runware/Runware.js +13 -0
- package/dist/esm/Runware/async-retry.d.ts +5 -0
- package/dist/esm/Runware/async-retry.js +27 -0
- package/dist/esm/Runware/index.d.ts +4 -0
- package/dist/esm/Runware/index.js +20 -0
- package/dist/esm/Runware/reconnect.d.ts +11 -0
- package/dist/esm/Runware/reconnect.js +175 -0
- package/dist/esm/Runware/types.d.ts +244 -0
- package/dist/esm/Runware/types.js +84 -0
- package/dist/esm/Runware/utils.d.ts +45 -0
- package/dist/esm/Runware/utils.js +212 -0
- package/dist/esm/tests/Runware/enhance-prompt.test.d.ts +1 -0
- package/dist/esm/tests/Runware/enhance-prompt.test.js +58 -0
- package/dist/esm/tests/Runware/remove-image-background.test.d.ts +1 -0
- package/dist/esm/tests/Runware/remove-image-background.test.js +37 -0
- package/dist/esm/tests/Runware/request-image-to-text.test.d.ts +1 -0
- package/dist/esm/tests/Runware/request-image-to-text.test.js +37 -0
- package/dist/esm/tests/Runware/request-images.test.d.ts +1 -0
- package/dist/esm/tests/Runware/request-images.test.js +72 -0
- package/dist/esm/tests/Runware/runware-server.test.d.ts +1 -0
- package/dist/esm/tests/Runware/runware-server.test.js +26 -0
- package/dist/esm/tests/Runware/upload-image.test.d.ts +1 -0
- package/dist/esm/tests/Runware/upload-image.test.js +52 -0
- package/dist/esm/tests/Runware/upscale-gan.test.d.ts +1 -0
- package/dist/esm/tests/Runware/upscale-gan.test.js +41 -0
- package/dist/esm/tests/mockServer.d.ts +12 -0
- package/dist/esm/tests/mockServer.js +38 -0
- package/dist/esm/tests/test-utils.d.ts +39 -0
- package/dist/esm/tests/test-utils.js +44 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -33
- package/dist/index.mjs +14 -33
- package/package.json +1 -1
- package/readme.md +6 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const test_utils_1 = require("../test-utils");
|
|
5
|
+
const mockServer_1 = require("../mockServer");
|
|
6
|
+
const Runware_1 = require("../../Runware");
|
|
7
|
+
vitest_1.vi.mock("../../Runware/utils", async () => {
|
|
8
|
+
const actual = await vitest_1.vi.importActual("../../Runware/utils");
|
|
9
|
+
return Object.assign(Object.assign({}, actual), { fileToBase64: vitest_1.vi.fn().mockReturnValue("FILE_TO_BASE_64"), getIntervalWithPromise: vitest_1.vi.fn(), getUUID: vitest_1.vi.fn().mockImplementation(() => "UNIQUE_UID") });
|
|
10
|
+
});
|
|
11
|
+
(0, vitest_1.describe)("When user request to upscale gan", async () => {
|
|
12
|
+
const { mockServer, runware } = await (0, mockServer_1.startMockServer)();
|
|
13
|
+
(0, vitest_1.afterEach)(() => {
|
|
14
|
+
vitest_1.vi.clearAllMocks();
|
|
15
|
+
});
|
|
16
|
+
(0, vitest_1.beforeEach)(() => {
|
|
17
|
+
mockServer.stop();
|
|
18
|
+
});
|
|
19
|
+
(0, vitest_1.beforeAll)(async () => {
|
|
20
|
+
vitest_1.vi.spyOn(runware, "uploadImage").mockReturnValue(test_utils_1.testExamples.imageUploadRes);
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.test)("it should upscale gan", async () => {
|
|
23
|
+
const imageUploadSpy = vitest_1.vi.spyOn(runware, "uploadImage");
|
|
24
|
+
const globalListenerSpy = vitest_1.vi.spyOn(runware, "globalListener");
|
|
25
|
+
const sendSpy = vitest_1.vi.spyOn(runware, "send");
|
|
26
|
+
await runware.upscaleGan({
|
|
27
|
+
inputImage: test_utils_1.mockUploadFile,
|
|
28
|
+
upscaleFactor: 2,
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.expect)(imageUploadSpy).toHaveBeenCalled();
|
|
31
|
+
(0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith({
|
|
32
|
+
inputImage: test_utils_1.testExamples.imageUploadRes.imageUUID,
|
|
33
|
+
taskUUID: test_utils_1.mockTaskUUID,
|
|
34
|
+
upscaleFactor: 2,
|
|
35
|
+
taskType: Runware_1.ETaskType.IMAGE_UPSCALE,
|
|
36
|
+
});
|
|
37
|
+
(0, vitest_1.expect)(globalListenerSpy).toHaveBeenCalledWith({
|
|
38
|
+
taskUUID: test_utils_1.mockTaskUUID,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="ws" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Server } from "mock-socket";
|
|
4
|
+
import { RunwareServer } from "../Runware";
|
|
5
|
+
export declare const startMockServer: () => Promise<{
|
|
6
|
+
runware: import("../Runware").RunwareClient | RunwareServer;
|
|
7
|
+
mockServer: Server;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const startMockBackendServer: () => Promise<{
|
|
10
|
+
runwareServer: RunwareServer;
|
|
11
|
+
mockServer: import("ws").Server<typeof import("ws"), typeof import("http").IncomingMessage>;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startMockBackendServer = exports.startMockServer = void 0;
|
|
4
|
+
const mock_socket_1 = require("mock-socket");
|
|
5
|
+
const Runware_1 = require("../Runware");
|
|
6
|
+
const utils_1 = require("../Runware/utils");
|
|
7
|
+
const ws_1 = require("ws");
|
|
8
|
+
const startMockServer = async () => {
|
|
9
|
+
const mockServer = new mock_socket_1.Server("ws://localhost:8080");
|
|
10
|
+
mockServer.on("connection", (socket) => {
|
|
11
|
+
socket.on("message", (data) => {
|
|
12
|
+
// socket.send("test message from mock server");
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
const runware = new Runware_1.Runware({
|
|
16
|
+
apiKey: "API_KEY",
|
|
17
|
+
url: utils_1.BASE_RUNWARE_URLS.TEST,
|
|
18
|
+
});
|
|
19
|
+
await (0, utils_1.delay)(1);
|
|
20
|
+
return { runware, mockServer };
|
|
21
|
+
};
|
|
22
|
+
exports.startMockServer = startMockServer;
|
|
23
|
+
const startMockBackendServer = async () => {
|
|
24
|
+
const mockServer = new ws_1.WebSocketServer({ port: 8080 });
|
|
25
|
+
mockServer.on("connection", (socket) => {
|
|
26
|
+
socket.on("message", (data, isBinary) => {
|
|
27
|
+
const message = !isBinary ? data === null || data === void 0 ? void 0 : data.toString() : data;
|
|
28
|
+
// socket.send("test message from mock server");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
const runwareServer = new Runware_1.RunwareServer({
|
|
32
|
+
apiKey: "API_KEY",
|
|
33
|
+
url: utils_1.BASE_RUNWARE_URLS.TEST,
|
|
34
|
+
});
|
|
35
|
+
await (0, utils_1.delay)(1);
|
|
36
|
+
return { runwareServer, mockServer };
|
|
37
|
+
};
|
|
38
|
+
exports.startMockBackendServer = startMockBackendServer;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EControlMode, ETaskType } from "../Runware";
|
|
2
|
+
export declare const mockTaskUUID = "UNIQUE_UID";
|
|
3
|
+
export declare const mockTextImageUpload = "IMAGE_UPLOAD";
|
|
4
|
+
export declare const mockFileToBase64 = "FILE_TO_BASE_64";
|
|
5
|
+
export declare const mockNewImageUID = "NEW_IMAGE_UID";
|
|
6
|
+
export declare const mockUploadFile: any;
|
|
7
|
+
export declare const testExamples: {
|
|
8
|
+
imageReq: {
|
|
9
|
+
numberResults: number;
|
|
10
|
+
positivePrompt: string;
|
|
11
|
+
model: number;
|
|
12
|
+
steps: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
imageRes: {
|
|
17
|
+
model: number;
|
|
18
|
+
numberResults: number;
|
|
19
|
+
positivePrompt: string;
|
|
20
|
+
steps: number;
|
|
21
|
+
taskType: ETaskType;
|
|
22
|
+
taskUUID: string;
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
};
|
|
26
|
+
imageUploadRes: {
|
|
27
|
+
imageUUID: string;
|
|
28
|
+
imageURL: string;
|
|
29
|
+
taskUUID: string;
|
|
30
|
+
};
|
|
31
|
+
controlNet: {
|
|
32
|
+
endStep: number;
|
|
33
|
+
startStep: number;
|
|
34
|
+
guideImage: string;
|
|
35
|
+
preprocessor: any;
|
|
36
|
+
weight: number;
|
|
37
|
+
controlMode: EControlMode;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testExamples = exports.mockUploadFile = exports.mockNewImageUID = exports.mockFileToBase64 = exports.mockTextImageUpload = exports.mockTaskUUID = void 0;
|
|
4
|
+
const Runware_1 = require("../Runware");
|
|
5
|
+
const utils_1 = require("../Runware/utils");
|
|
6
|
+
const promptText = "A beautiful runware";
|
|
7
|
+
exports.mockTaskUUID = "UNIQUE_UID";
|
|
8
|
+
exports.mockTextImageUpload = "IMAGE_UPLOAD";
|
|
9
|
+
exports.mockFileToBase64 = "FILE_TO_BASE_64";
|
|
10
|
+
exports.mockNewImageUID = "NEW_IMAGE_UID";
|
|
11
|
+
exports.mockUploadFile = new utils_1.MockFile().create("pic.jpg", 1024 * 1024 * 2, "image/jpeg");
|
|
12
|
+
exports.testExamples = {
|
|
13
|
+
imageReq: {
|
|
14
|
+
numberResults: 8,
|
|
15
|
+
positivePrompt: promptText,
|
|
16
|
+
model: 13,
|
|
17
|
+
steps: 30,
|
|
18
|
+
width: 512,
|
|
19
|
+
height: 512,
|
|
20
|
+
},
|
|
21
|
+
imageRes: {
|
|
22
|
+
model: 13,
|
|
23
|
+
numberResults: 8,
|
|
24
|
+
positivePrompt: promptText,
|
|
25
|
+
steps: 30,
|
|
26
|
+
taskType: Runware_1.ETaskType.IMAGE_INFERENCE,
|
|
27
|
+
taskUUID: exports.mockTaskUUID,
|
|
28
|
+
width: 512,
|
|
29
|
+
height: 512,
|
|
30
|
+
},
|
|
31
|
+
imageUploadRes: {
|
|
32
|
+
imageUUID: exports.mockNewImageUID,
|
|
33
|
+
imageURL: "data:image/png;base64,iVBORw0KGgoAAAA...",
|
|
34
|
+
taskUUID: "50836053-a0ee-4cf5-b9d6-ae7c5d140ada",
|
|
35
|
+
},
|
|
36
|
+
controlNet: {
|
|
37
|
+
endStep: 20,
|
|
38
|
+
startStep: 0,
|
|
39
|
+
guideImage: exports.mockTextImageUpload,
|
|
40
|
+
preprocessor: "canny",
|
|
41
|
+
weight: 1,
|
|
42
|
+
controlMode: Runware_1.EControlMode.CONTROL_NET,
|
|
43
|
+
},
|
|
44
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -299,6 +299,6 @@ declare class RunwareServer extends RunwareBase {
|
|
|
299
299
|
protected heartBeat(): void;
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
-
declare let Runware:
|
|
302
|
+
declare let Runware: typeof RunwareClient | typeof RunwareServer;
|
|
303
303
|
|
|
304
304
|
export { EControlMode, EOpenPosePreProcessor, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, GetWithPromiseCallBackType, IControlNet, IControlNetGeneral, IControlNetImage, IControlNetPreprocess, IControlNetWithUUID, IEnhancedPrompt, IError, IImage, IImageToText, IOutputFormat, IOutputType, IPromptEnhancer, IRemoveImage, IRemoveImageBackground, IRequestImage, IRequestImageToText, ITextToImage, IUpscaleGan, ListenerType, ReconnectingWebsocketProps, RequireAtLeastOne, RequireOnlyOne, Runware, RunwareBaseType, RunwareClient, RunwareServer, SdkType, UploadImageType };
|
package/dist/index.d.ts
CHANGED
|
@@ -299,6 +299,6 @@ declare class RunwareServer extends RunwareBase {
|
|
|
299
299
|
protected heartBeat(): void;
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
-
declare let Runware:
|
|
302
|
+
declare let Runware: typeof RunwareClient | typeof RunwareServer;
|
|
303
303
|
|
|
304
304
|
export { EControlMode, EOpenPosePreProcessor, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, GetWithPromiseCallBackType, IControlNet, IControlNetGeneral, IControlNetImage, IControlNetPreprocess, IControlNetWithUUID, IEnhancedPrompt, IError, IImage, IImageToText, IOutputFormat, IOutputType, IPromptEnhancer, IRemoveImage, IRemoveImageBackground, IRequestImage, IRequestImageToText, ITextToImage, IUpscaleGan, ListenerType, ReconnectingWebsocketProps, RequireAtLeastOne, RequireOnlyOne, Runware, RunwareBaseType, RunwareClient, RunwareServer, SdkType, UploadImageType };
|
package/dist/index.js
CHANGED
|
@@ -462,35 +462,12 @@ var RunwareBase = class {
|
|
|
462
462
|
};
|
|
463
463
|
}
|
|
464
464
|
const imageBase64 = typeof file === "string" ? file : await fileToBase64(file);
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
taskUUID
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
taskUUID
|
|
472
|
-
});
|
|
473
|
-
const image = await getIntervalWithPromise(
|
|
474
|
-
({ resolve, reject }) => {
|
|
475
|
-
const uploadedImage = this.getSingleMessage({
|
|
476
|
-
taskUUID
|
|
477
|
-
});
|
|
478
|
-
if (!uploadedImage)
|
|
479
|
-
return;
|
|
480
|
-
if (uploadedImage == null ? void 0 : uploadedImage.error) {
|
|
481
|
-
reject(uploadedImage);
|
|
482
|
-
return true;
|
|
483
|
-
}
|
|
484
|
-
if (uploadedImage) {
|
|
485
|
-
delete this._globalMessages[taskUUID];
|
|
486
|
-
resolve(uploadedImage);
|
|
487
|
-
return true;
|
|
488
|
-
}
|
|
489
|
-
},
|
|
490
|
-
{ debugKey: "upload-image" }
|
|
491
|
-
);
|
|
492
|
-
lis.destroy();
|
|
493
|
-
return image;
|
|
465
|
+
return {
|
|
466
|
+
imageURL: imageBase64,
|
|
467
|
+
imageUUID: imageBase64,
|
|
468
|
+
taskUUID,
|
|
469
|
+
taskType: "imageUpload" /* IMAGE_UPLOAD */
|
|
470
|
+
};
|
|
494
471
|
});
|
|
495
472
|
} catch (e) {
|
|
496
473
|
throw e;
|
|
@@ -756,10 +733,11 @@ var RunwareBase = class {
|
|
|
756
733
|
};
|
|
757
734
|
this.getSingleMessage = ({ taskUUID }) => {
|
|
758
735
|
var _a;
|
|
759
|
-
const value =
|
|
760
|
-
|
|
736
|
+
const value = (_a = this._globalMessages[taskUUID]) == null ? void 0 : _a[0];
|
|
737
|
+
const errorValue = this._globalMessages[taskUUID];
|
|
738
|
+
if (!value && !errorValue)
|
|
761
739
|
return null;
|
|
762
|
-
return value;
|
|
740
|
+
return (errorValue == null ? void 0 : errorValue.error) ? errorValue : value;
|
|
763
741
|
};
|
|
764
742
|
this.disconnect = async () => {
|
|
765
743
|
var _a, _b, _c, _d;
|
|
@@ -1092,6 +1070,7 @@ var RunwareBase = class {
|
|
|
1092
1070
|
return new Promise((resolve, reject) => {
|
|
1093
1071
|
let retry = 0;
|
|
1094
1072
|
const MAX_RETRY = 30;
|
|
1073
|
+
const SHOULD_RETRY = 30 / 2 === retry;
|
|
1095
1074
|
let retryIntervalId;
|
|
1096
1075
|
let pollingIntervalId;
|
|
1097
1076
|
const clearAllIntervals = () => {
|
|
@@ -1109,7 +1088,9 @@ var RunwareBase = class {
|
|
|
1109
1088
|
clearAllIntervals();
|
|
1110
1089
|
reject(new Error("Retry timed out"));
|
|
1111
1090
|
} else {
|
|
1112
|
-
|
|
1091
|
+
if (SHOULD_RETRY) {
|
|
1092
|
+
this.connect();
|
|
1093
|
+
}
|
|
1113
1094
|
retry++;
|
|
1114
1095
|
}
|
|
1115
1096
|
} catch (error) {
|
package/dist/index.mjs
CHANGED
|
@@ -440,35 +440,12 @@ var RunwareBase = class {
|
|
|
440
440
|
};
|
|
441
441
|
}
|
|
442
442
|
const imageBase64 = typeof file === "string" ? file : await fileToBase64(file);
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
taskUUID
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
taskUUID
|
|
450
|
-
});
|
|
451
|
-
const image = await getIntervalWithPromise(
|
|
452
|
-
({ resolve, reject }) => {
|
|
453
|
-
const uploadedImage = this.getSingleMessage({
|
|
454
|
-
taskUUID
|
|
455
|
-
});
|
|
456
|
-
if (!uploadedImage)
|
|
457
|
-
return;
|
|
458
|
-
if (uploadedImage == null ? void 0 : uploadedImage.error) {
|
|
459
|
-
reject(uploadedImage);
|
|
460
|
-
return true;
|
|
461
|
-
}
|
|
462
|
-
if (uploadedImage) {
|
|
463
|
-
delete this._globalMessages[taskUUID];
|
|
464
|
-
resolve(uploadedImage);
|
|
465
|
-
return true;
|
|
466
|
-
}
|
|
467
|
-
},
|
|
468
|
-
{ debugKey: "upload-image" }
|
|
469
|
-
);
|
|
470
|
-
lis.destroy();
|
|
471
|
-
return image;
|
|
443
|
+
return {
|
|
444
|
+
imageURL: imageBase64,
|
|
445
|
+
imageUUID: imageBase64,
|
|
446
|
+
taskUUID,
|
|
447
|
+
taskType: "imageUpload" /* IMAGE_UPLOAD */
|
|
448
|
+
};
|
|
472
449
|
});
|
|
473
450
|
} catch (e) {
|
|
474
451
|
throw e;
|
|
@@ -734,10 +711,11 @@ var RunwareBase = class {
|
|
|
734
711
|
};
|
|
735
712
|
this.getSingleMessage = ({ taskUUID }) => {
|
|
736
713
|
var _a;
|
|
737
|
-
const value =
|
|
738
|
-
|
|
714
|
+
const value = (_a = this._globalMessages[taskUUID]) == null ? void 0 : _a[0];
|
|
715
|
+
const errorValue = this._globalMessages[taskUUID];
|
|
716
|
+
if (!value && !errorValue)
|
|
739
717
|
return null;
|
|
740
|
-
return value;
|
|
718
|
+
return (errorValue == null ? void 0 : errorValue.error) ? errorValue : value;
|
|
741
719
|
};
|
|
742
720
|
this.disconnect = async () => {
|
|
743
721
|
var _a, _b, _c, _d;
|
|
@@ -1070,6 +1048,7 @@ var RunwareBase = class {
|
|
|
1070
1048
|
return new Promise((resolve, reject) => {
|
|
1071
1049
|
let retry = 0;
|
|
1072
1050
|
const MAX_RETRY = 30;
|
|
1051
|
+
const SHOULD_RETRY = 30 / 2 === retry;
|
|
1073
1052
|
let retryIntervalId;
|
|
1074
1053
|
let pollingIntervalId;
|
|
1075
1054
|
const clearAllIntervals = () => {
|
|
@@ -1087,7 +1066,9 @@ var RunwareBase = class {
|
|
|
1087
1066
|
clearAllIntervals();
|
|
1088
1067
|
reject(new Error("Retry timed out"));
|
|
1089
1068
|
} else {
|
|
1090
|
-
|
|
1069
|
+
if (SHOULD_RETRY) {
|
|
1070
|
+
this.connect();
|
|
1071
|
+
}
|
|
1091
1072
|
retry++;
|
|
1092
1073
|
}
|
|
1093
1074
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runware/sdk-js",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13-beta.1",
|
|
4
4
|
"description": "The SDK is used to run image inference with the Runware API, powered by the RunWare inference platform. It can be used to generate imaged with text-to-image and image-to-image. It also allows the use of an existing gallery of models or selecting any model or LoRA from the CivitAI gallery. The API also supports upscaling, background removal, inpainting and outpainting, and a series of other ControlNet models.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|