@runware/sdk-js 1.1.11 → 1.1.13

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 (42) hide show
  1. package/dist/esm/Runware/Runware-base.d.ts +40 -0
  2. package/dist/esm/Runware/Runware-base.js +651 -0
  3. package/dist/esm/Runware/Runware-client.d.ts +5 -0
  4. package/dist/esm/Runware/Runware-client.js +18 -0
  5. package/dist/esm/Runware/Runware-server.d.ts +14 -0
  6. package/dist/esm/Runware/Runware-server.js +155 -0
  7. package/dist/esm/Runware/Runware.d.ts +4 -0
  8. package/dist/esm/Runware/Runware.js +13 -0
  9. package/dist/esm/Runware/async-retry.d.ts +5 -0
  10. package/dist/esm/Runware/async-retry.js +27 -0
  11. package/dist/esm/Runware/index.d.ts +4 -0
  12. package/dist/esm/Runware/index.js +20 -0
  13. package/dist/esm/Runware/reconnect.d.ts +11 -0
  14. package/dist/esm/Runware/reconnect.js +175 -0
  15. package/dist/esm/Runware/types.d.ts +244 -0
  16. package/dist/esm/Runware/types.js +84 -0
  17. package/dist/esm/Runware/utils.d.ts +45 -0
  18. package/dist/esm/Runware/utils.js +212 -0
  19. package/dist/esm/tests/Runware/enhance-prompt.test.d.ts +1 -0
  20. package/dist/esm/tests/Runware/enhance-prompt.test.js +58 -0
  21. package/dist/esm/tests/Runware/remove-image-background.test.d.ts +1 -0
  22. package/dist/esm/tests/Runware/remove-image-background.test.js +37 -0
  23. package/dist/esm/tests/Runware/request-image-to-text.test.d.ts +1 -0
  24. package/dist/esm/tests/Runware/request-image-to-text.test.js +37 -0
  25. package/dist/esm/tests/Runware/request-images.test.d.ts +1 -0
  26. package/dist/esm/tests/Runware/request-images.test.js +72 -0
  27. package/dist/esm/tests/Runware/runware-server.test.d.ts +1 -0
  28. package/dist/esm/tests/Runware/runware-server.test.js +26 -0
  29. package/dist/esm/tests/Runware/upload-image.test.d.ts +1 -0
  30. package/dist/esm/tests/Runware/upload-image.test.js +52 -0
  31. package/dist/esm/tests/Runware/upscale-gan.test.d.ts +1 -0
  32. package/dist/esm/tests/Runware/upscale-gan.test.js +41 -0
  33. package/dist/esm/tests/mockServer.d.ts +12 -0
  34. package/dist/esm/tests/mockServer.js +38 -0
  35. package/dist/esm/tests/test-utils.d.ts +39 -0
  36. package/dist/esm/tests/test-utils.js +44 -0
  37. package/dist/index.d.mts +1 -1
  38. package/dist/index.d.ts +1 -1
  39. package/dist/index.js +12 -32
  40. package/dist/index.mjs +12 -32
  41. package/package.json +1 -1
  42. package/readme.md +14 -2
@@ -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: any;
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: any;
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
- this.send({
466
- taskType: "imageUpload" /* IMAGE_UPLOAD */,
467
- image: imageBase64,
468
- taskUUID
469
- });
470
- const lis = this.globalListener({
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;
@@ -650,7 +627,7 @@ var RunwareBase = class {
650
627
  }
651
628
  if (newRemoveBackground) {
652
629
  delete this._globalMessages[taskUUID];
653
- resolve([newRemoveBackground]);
630
+ resolve(newRemoveBackground);
654
631
  return true;
655
632
  }
656
633
  },
@@ -697,7 +674,7 @@ var RunwareBase = class {
697
674
  }
698
675
  if (newUpscaleGan) {
699
676
  delete this._globalMessages[taskUUID];
700
- resolve([newUpscaleGan]);
677
+ resolve(newUpscaleGan);
701
678
  return true;
702
679
  }
703
680
  },
@@ -1092,6 +1069,7 @@ var RunwareBase = class {
1092
1069
  return new Promise((resolve, reject) => {
1093
1070
  let retry = 0;
1094
1071
  const MAX_RETRY = 30;
1072
+ const SHOULD_RETRY = 30 / 2 === retry;
1095
1073
  let retryIntervalId;
1096
1074
  let pollingIntervalId;
1097
1075
  const clearAllIntervals = () => {
@@ -1109,7 +1087,9 @@ var RunwareBase = class {
1109
1087
  clearAllIntervals();
1110
1088
  reject(new Error("Retry timed out"));
1111
1089
  } else {
1112
- this.connect();
1090
+ if (SHOULD_RETRY) {
1091
+ this.connect();
1092
+ }
1113
1093
  retry++;
1114
1094
  }
1115
1095
  } 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
- this.send({
444
- taskType: "imageUpload" /* IMAGE_UPLOAD */,
445
- image: imageBase64,
446
- taskUUID
447
- });
448
- const lis = this.globalListener({
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;
@@ -628,7 +605,7 @@ var RunwareBase = class {
628
605
  }
629
606
  if (newRemoveBackground) {
630
607
  delete this._globalMessages[taskUUID];
631
- resolve([newRemoveBackground]);
608
+ resolve(newRemoveBackground);
632
609
  return true;
633
610
  }
634
611
  },
@@ -675,7 +652,7 @@ var RunwareBase = class {
675
652
  }
676
653
  if (newUpscaleGan) {
677
654
  delete this._globalMessages[taskUUID];
678
- resolve([newUpscaleGan]);
655
+ resolve(newUpscaleGan);
679
656
  return true;
680
657
  }
681
658
  },
@@ -1070,6 +1047,7 @@ var RunwareBase = class {
1070
1047
  return new Promise((resolve, reject) => {
1071
1048
  let retry = 0;
1072
1049
  const MAX_RETRY = 30;
1050
+ const SHOULD_RETRY = 30 / 2 === retry;
1073
1051
  let retryIntervalId;
1074
1052
  let pollingIntervalId;
1075
1053
  const clearAllIntervals = () => {
@@ -1087,7 +1065,9 @@ var RunwareBase = class {
1087
1065
  clearAllIntervals();
1088
1066
  reject(new Error("Retry timed out"));
1089
1067
  } else {
1090
- this.connect();
1068
+ if (SHOULD_RETRY) {
1069
+ this.connect();
1070
+ }
1091
1071
  retry++;
1092
1072
  }
1093
1073
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runware/sdk-js",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
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",
package/readme.md CHANGED
@@ -360,12 +360,24 @@ return interface IControlNetImage {
360
360
 
361
361
  ## Changelog
362
362
 
363
+ ### - v1.1.13
364
+
365
+ **Added or Changed**
366
+
367
+ - Fix image upload
368
+
369
+ ### - v1.1.12
370
+
371
+ **Added or Changed**
372
+
373
+ - Fix imageUpscale and backgroundRemoval wrong response
374
+
363
375
  ### - v1.1.11
364
376
 
365
377
  **Added or Changed**
366
378
 
367
- - Automatically detect environment with Runware
368
- - Fix invalid images not returning server errors
379
+ - Automatically detect environment with Runware class
380
+ - Fix invalid input image not returning server errors
369
381
 
370
382
  ### - v1.1.10
371
383