@runware/sdk-js 1.1.48 → 1.1.49

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.
Files changed (46) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +45 -3
  4. package/dist/index.d.ts +45 -3
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/readme.md +13 -6
  9. package/dist/esm/Runware/Runware-base.d.ts +0 -70
  10. package/dist/esm/Runware/Runware-base.js +0 -1002
  11. package/dist/esm/Runware/Runware-client.d.ts +0 -5
  12. package/dist/esm/Runware/Runware-client.js +0 -28
  13. package/dist/esm/Runware/Runware-server.d.ts +0 -15
  14. package/dist/esm/Runware/Runware-server.js +0 -145
  15. package/dist/esm/Runware/Runware.d.ts +0 -4
  16. package/dist/esm/Runware/Runware.js +0 -13
  17. package/dist/esm/Runware/async-retry.d.ts +0 -5
  18. package/dist/esm/Runware/async-retry.js +0 -30
  19. package/dist/esm/Runware/index.d.ts +0 -4
  20. package/dist/esm/Runware/index.js +0 -20
  21. package/dist/esm/Runware/reconnect.d.ts +0 -11
  22. package/dist/esm/Runware/reconnect.js +0 -175
  23. package/dist/esm/Runware/types.d.ts +0 -644
  24. package/dist/esm/Runware/types.js +0 -156
  25. package/dist/esm/Runware/utils.d.ts +0 -57
  26. package/dist/esm/Runware/utils.js +0 -262
  27. package/dist/esm/tests/Runware/enhance-prompt.test.d.ts +0 -1
  28. package/dist/esm/tests/Runware/enhance-prompt.test.js +0 -58
  29. package/dist/esm/tests/Runware/remove-image-background.test.d.ts +0 -1
  30. package/dist/esm/tests/Runware/remove-image-background.test.js +0 -37
  31. package/dist/esm/tests/Runware/request-image-to-text.test.d.ts +0 -1
  32. package/dist/esm/tests/Runware/request-image-to-text.test.js +0 -37
  33. package/dist/esm/tests/Runware/request-images.test.d.ts +0 -1
  34. package/dist/esm/tests/Runware/request-images.test.js +0 -84
  35. package/dist/esm/tests/Runware/runware-server.test.d.ts +0 -1
  36. package/dist/esm/tests/Runware/runware-server.test.js +0 -26
  37. package/dist/esm/tests/Runware/upload-image.test.d.ts +0 -1
  38. package/dist/esm/tests/Runware/upload-image.test.js +0 -28
  39. package/dist/esm/tests/Runware/upscale-gan.test.d.ts +0 -1
  40. package/dist/esm/tests/Runware/upscale-gan.test.js +0 -41
  41. package/dist/esm/tests/mockServer.d.ts +0 -12
  42. package/dist/esm/tests/mockServer.js +0 -38
  43. package/dist/esm/tests/script.d.ts +0 -8
  44. package/dist/esm/tests/script.js +0 -570
  45. package/dist/esm/tests/test-utils.d.ts +0 -40
  46. package/dist/esm/tests/test-utils.js +0 -45
@@ -1,84 +0,0 @@
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 an image", 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 request image without an image initiator", async () => {
23
- const imageUploadSpy = vitest_1.vi.spyOn(runware, "uploadImage");
24
- const sendSpy = vitest_1.vi.spyOn(runware, "send");
25
- await runware.requestImages(test_utils_1.testExamples.imageReq);
26
- (0, vitest_1.expect)(imageUploadSpy).not.toHaveBeenCalled();
27
- (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith(Object.assign({}, test_utils_1.testExamples.imageRes));
28
- });
29
- (0, vitest_1.test)("it should request image with an image initiator", async () => {
30
- const imageUploadSpy = vitest_1.vi.spyOn(runware, "uploadImage");
31
- const sendSpy = vitest_1.vi.spyOn(runware, "send");
32
- await runware.requestImages(Object.assign(Object.assign({}, test_utils_1.testExamples.imageReq), { seedImage: test_utils_1.mockTextImageUpload }));
33
- (0, vitest_1.expect)(imageUploadSpy).toHaveBeenCalled();
34
- (0, vitest_1.expect)(imageUploadSpy).toHaveBeenCalledTimes(1);
35
- (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith(Object.assign(Object.assign({}, test_utils_1.testExamples.imageRes), { seedImage: test_utils_1.testExamples.imageUploadRes.imageUUID, taskType: Runware_1.ETaskType.IMAGE_INFERENCE }));
36
- });
37
- (0, vitest_1.test)("it should request image with an image initiator and image mask initiator", async () => {
38
- const imageUploadSpy = vitest_1.vi.spyOn(runware, "uploadImage");
39
- const sendSpy = vitest_1.vi.spyOn(runware, "send");
40
- await runware.requestImages(Object.assign(Object.assign({}, test_utils_1.testExamples.imageReq), { seedImage: test_utils_1.mockTextImageUpload, maskImage: test_utils_1.mockTextImageUpload }));
41
- (0, vitest_1.expect)(imageUploadSpy).toHaveBeenCalledTimes(2);
42
- (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith(Object.assign(Object.assign({}, test_utils_1.testExamples.imageRes), { seedImage: test_utils_1.testExamples.imageUploadRes.imageUUID, maskImage: test_utils_1.testExamples.imageUploadRes.imageUUID, taskType: Runware_1.ETaskType.IMAGE_INFERENCE }));
43
- });
44
- (0, vitest_1.test)("it should request image with an image initiator and image mask initiator and control net", async () => {
45
- const imageUploadSpy = vitest_1.vi.spyOn(runware, "uploadImage");
46
- const sendSpy = vitest_1.vi.spyOn(runware, "send");
47
- await runware.requestImages(Object.assign(Object.assign({}, test_utils_1.testExamples.imageReq), { seedImage: test_utils_1.mockTextImageUpload, maskImage: test_utils_1.mockTextImageUpload, controlNet: [Object.assign(Object.assign({}, test_utils_1.testExamples.controlNet), { model: "control_net_model" })] }));
48
- (0, vitest_1.expect)(imageUploadSpy).toHaveBeenCalledTimes(3);
49
- (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith(Object.assign(Object.assign({}, test_utils_1.testExamples.imageRes), { seedImage: test_utils_1.testExamples.imageUploadRes.imageUUID, maskImage: test_utils_1.testExamples.imageUploadRes.imageUUID, controlNet: [
50
- {
51
- controlMode: Runware_1.EControlMode.CONTROL_NET,
52
- endStep: 20,
53
- guideImage: "NEW_IMAGE_UID",
54
- model: "control_net_model",
55
- startStep: 0,
56
- weight: 1,
57
- },
58
- ], taskType: Runware_1.ETaskType.IMAGE_INFERENCE }));
59
- });
60
- (0, vitest_1.test)("it should request multiple images in parallel", async () => {
61
- const sendSpy = vitest_1.vi.spyOn(runware, "send");
62
- const listenToImages = vitest_1.vi.spyOn(runware, "listenToImages");
63
- await Promise.all([
64
- runware.requestImages(Object.assign({}, test_utils_1.testExamples.imageReq)),
65
- runware.requestImages(Object.assign(Object.assign({}, test_utils_1.testExamples.imageReq), { positivePrompt: "cat" })),
66
- ]);
67
- (0, vitest_1.expect)(sendSpy).toHaveBeenCalledTimes(2);
68
- (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith(Object.assign(Object.assign({}, test_utils_1.testExamples.imageRes), { taskType: Runware_1.ETaskType.IMAGE_INFERENCE }));
69
- (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith(Object.assign(Object.assign({}, test_utils_1.testExamples.imageRes), { positivePrompt: "cat", taskType: Runware_1.ETaskType.IMAGE_INFERENCE }));
70
- (0, vitest_1.expect)(listenToImages).toHaveBeenCalledTimes(2);
71
- });
72
- (0, vitest_1.test)("it should request providerSettings", async () => {
73
- const sendSpy = vitest_1.vi.spyOn(runware, "send");
74
- const providerSettings = {
75
- bfl: {
76
- promptUpsampling: true,
77
- safetyTolerance: 4,
78
- raw: true,
79
- },
80
- };
81
- await runware.requestImages(Object.assign(Object.assign({}, test_utils_1.testExamples.imageReq), { providerSettings }));
82
- (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith(Object.assign(Object.assign({}, test_utils_1.testExamples.imageRes), { providerSettings }));
83
- });
84
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const vitest_1 = require("vitest");
4
- const mockServer_1 = require("../mockServer");
5
- const Runware_1 = require("../../Runware");
6
- const utils_1 = require("../../Runware/utils");
7
- const PORT = 8080;
8
- (0, vitest_1.describe)("When using backend mockServer", async () => {
9
- const { mockServer } = await (0, mockServer_1.startMockBackendServer)();
10
- (0, vitest_1.beforeAll)(async () => { });
11
- (0, vitest_1.afterEach)(() => {
12
- vitest_1.vi.clearAllMocks();
13
- });
14
- (0, vitest_1.beforeAll)(async () => { });
15
- (0, vitest_1.test)("it should instantiate server correctly", async () => {
16
- vitest_1.vi.spyOn(Runware_1.RunwareServer.prototype, "addListener").mockImplementation(() => "afa");
17
- vitest_1.vi.spyOn(Runware_1.RunwareServer.prototype, "connect");
18
- const runwareServer = new Runware_1.RunwareServer({
19
- apiKey: "API_KEY",
20
- url: utils_1.BASE_RUNWARE_URLS.TEST,
21
- });
22
- (0, vitest_1.expect)(runwareServer._apiKey).toBe("API_KEY");
23
- (0, vitest_1.expect)(runwareServer.connect).toBeCalledTimes(1);
24
- (0, vitest_1.expect)(runwareServer._ws).toBeDefined();
25
- });
26
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const vitest_1 = require("vitest");
4
- const utils_1 = require("../../Runware/utils");
5
- const test_utils_1 = require("../test-utils");
6
- const mockServer_1 = require("../mockServer");
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().mockReturnValue("UNIQUE_UID") });
10
- });
11
- (0, vitest_1.describe)("When user uploads an image:", 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.test)("it should accept string during image upload", async () => {
20
- await runware["uploadImage"]("IMAGE_UPLOAD");
21
- (0, vitest_1.expect)(utils_1.fileToBase64).to.not.toHaveBeenCalled();
22
- });
23
- (0, vitest_1.test)("it should accept file during image upload", async () => {
24
- const sendSpy = vitest_1.vi.spyOn(runware, "send");
25
- await runware["uploadImage"](test_utils_1.mockUploadFile);
26
- (0, vitest_1.expect)(utils_1.fileToBase64).toHaveBeenCalled();
27
- });
28
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,41 +0,0 @@
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
- });
@@ -1,12 +0,0 @@
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
- }>;
@@ -1,38 +0,0 @@
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;
@@ -1,8 +0,0 @@
1
- export declare const uploadModelTest: () => Promise<void>;
2
- export declare const photoMakerTest: () => Promise<void>;
3
- export declare const generateImages: () => Promise<void>;
4
- export declare const imageMasking: () => Promise<void>;
5
- export declare const imageUpload: () => Promise<void>;
6
- export declare const modelSearch: () => Promise<void>;
7
- export declare const removeBackground: () => Promise<void>;
8
- export declare const asyncResults: () => Promise<void>;