@runware/sdk-js 1.1.12 → 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 +10 -30
  40. package/dist/index.mjs +10 -30
  41. package/package.json +1 -1
  42. package/readme.md +6 -0
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EOpenPosePreProcessor = exports.EPreProcessor = exports.EPreProcessorGroup = exports.EControlMode = exports.ETaskType = exports.SdkType = exports.Environment = void 0;
4
+ var Environment;
5
+ (function (Environment) {
6
+ Environment["PRODUCTION"] = "PRODUCTION";
7
+ Environment["DEVELOPMENT"] = "DEVELOPMENT";
8
+ Environment["TEST"] = "TEST";
9
+ })(Environment || (exports.Environment = Environment = {}));
10
+ var SdkType;
11
+ (function (SdkType) {
12
+ SdkType["CLIENT"] = "CLIENT";
13
+ SdkType["SERVER"] = "SERVER";
14
+ })(SdkType || (exports.SdkType = SdkType = {}));
15
+ var ETaskType;
16
+ (function (ETaskType) {
17
+ ETaskType["IMAGE_INFERENCE"] = "imageInference";
18
+ ETaskType["IMAGE_UPLOAD"] = "imageUpload";
19
+ ETaskType["IMAGE_UPSCALE"] = "imageUpscale";
20
+ ETaskType["IMAGE_BACKGROUND_REMOVAL"] = "imageBackgroundRemoval";
21
+ ETaskType["IMAGE_CAPTION"] = "imageCaption";
22
+ ETaskType["IMAGE_CONTROL_NET_PRE_PROCESS"] = "imageControlNetPreProcess";
23
+ ETaskType["PROMPT_ENHANCE"] = "promptEnhance";
24
+ ETaskType["AUTHENTICATION"] = "authentication";
25
+ })(ETaskType || (exports.ETaskType = ETaskType = {}));
26
+ var EControlMode;
27
+ (function (EControlMode) {
28
+ EControlMode["BALANCED"] = "balanced";
29
+ EControlMode["PROMPT"] = "prompt";
30
+ EControlMode["CONTROL_NET"] = "controlnet";
31
+ })(EControlMode || (exports.EControlMode = EControlMode = {}));
32
+ var EPreProcessorGroup;
33
+ (function (EPreProcessorGroup) {
34
+ EPreProcessorGroup["canny"] = "canny";
35
+ EPreProcessorGroup["depth"] = "depth";
36
+ EPreProcessorGroup["mlsd"] = "mlsd";
37
+ EPreProcessorGroup["normalbae"] = "normalbae";
38
+ EPreProcessorGroup["openpose"] = "openpose";
39
+ EPreProcessorGroup["tile"] = "tile";
40
+ EPreProcessorGroup["seg"] = "seg";
41
+ EPreProcessorGroup["lineart"] = "lineart";
42
+ EPreProcessorGroup["lineart_anime"] = "lineart_anime";
43
+ EPreProcessorGroup["shuffle"] = "shuffle";
44
+ EPreProcessorGroup["scribble"] = "scribble";
45
+ EPreProcessorGroup["softedge"] = "softedge";
46
+ })(EPreProcessorGroup || (exports.EPreProcessorGroup = EPreProcessorGroup = {}));
47
+ var EPreProcessor;
48
+ (function (EPreProcessor) {
49
+ EPreProcessor["canny"] = "canny";
50
+ EPreProcessor["depth_leres"] = "depth_leres";
51
+ EPreProcessor["depth_midas"] = "depth_midas";
52
+ EPreProcessor["depth_zoe"] = "depth_zoe";
53
+ EPreProcessor["inpaint_global_harmonious"] = "inpaint_global_harmonious";
54
+ EPreProcessor["lineart_anime"] = "lineart_anime";
55
+ EPreProcessor["lineart_coarse"] = "lineart_coarse";
56
+ EPreProcessor["lineart_realistic"] = "lineart_realistic";
57
+ EPreProcessor["lineart_standard"] = "lineart_standard";
58
+ EPreProcessor["mlsd"] = "mlsd";
59
+ EPreProcessor["normal_bae"] = "normal_bae";
60
+ EPreProcessor["scribble_hed"] = "scribble_hed";
61
+ EPreProcessor["scribble_pidinet"] = "scribble_pidinet";
62
+ EPreProcessor["seg_ofade20k"] = "seg_ofade20k";
63
+ EPreProcessor["seg_ofcoco"] = "seg_ofcoco";
64
+ EPreProcessor["seg_ufade20k"] = "seg_ufade20k";
65
+ EPreProcessor["shuffle"] = "shuffle";
66
+ EPreProcessor["softedge_hed"] = "softedge_hed";
67
+ EPreProcessor["softedge_hedsafe"] = "softedge_hedsafe";
68
+ EPreProcessor["softedge_pidinet"] = "softedge_pidinet";
69
+ EPreProcessor["softedge_pidisafe"] = "softedge_pidisafe";
70
+ EPreProcessor["tile_gaussian"] = "tile_gaussian";
71
+ EPreProcessor["openpose"] = "openpose";
72
+ EPreProcessor["openpose_face"] = "openpose_face";
73
+ EPreProcessor["openpose_faceonly"] = "openpose_faceonly";
74
+ EPreProcessor["openpose_full"] = "openpose_full";
75
+ EPreProcessor["openpose_hand"] = "openpose_hand";
76
+ })(EPreProcessor || (exports.EPreProcessor = EPreProcessor = {}));
77
+ var EOpenPosePreProcessor;
78
+ (function (EOpenPosePreProcessor) {
79
+ EOpenPosePreProcessor["openpose"] = "openpose";
80
+ EOpenPosePreProcessor["openpose_face"] = "openpose_face";
81
+ EOpenPosePreProcessor["openpose_faceonly"] = "openpose_faceonly";
82
+ EOpenPosePreProcessor["openpose_full"] = "openpose_full";
83
+ EOpenPosePreProcessor["openpose_hand"] = "openpose_hand";
84
+ })(EOpenPosePreProcessor || (exports.EOpenPosePreProcessor = EOpenPosePreProcessor = {}));
@@ -0,0 +1,45 @@
1
+ import { EPreProcessor, EPreProcessorGroup, GetWithPromiseCallBackType } from "./types";
2
+ export declare const BASE_RUNWARE_URLS: {
3
+ PRODUCTION: string;
4
+ TEST: string;
5
+ };
6
+ export declare const removeFromAray: <T>(col: T[], targetElem: T) => void;
7
+ export declare const getIntervalWithPromise: (callback: GetWithPromiseCallBackType, { debugKey, timeOutDuration, shouldThrowError, }: {
8
+ debugKey?: string | undefined;
9
+ timeOutDuration?: number | undefined;
10
+ shouldThrowError?: boolean | undefined;
11
+ }) => Promise<unknown>;
12
+ export declare const fileToBase64: (file: File) => Promise<unknown>;
13
+ export declare const getUUID: () => string;
14
+ export declare const isValidUUID: (uuid: string) => boolean;
15
+ export declare const compact: (value: any, data: any) => any;
16
+ export declare const getPreprocessorType: (processor: EPreProcessor) => EPreProcessorGroup;
17
+ export declare const accessDeepObject: ({ key, data, useZero, shouldReturnString, }: {
18
+ key: string;
19
+ data: Record<string, any>;
20
+ useZero?: boolean | undefined;
21
+ shouldReturnString?: boolean | undefined;
22
+ }) => Record<string, any>;
23
+ export declare const delay: (time: number, milliseconds?: number) => Promise<unknown>;
24
+ export declare class MockFile {
25
+ create: (name: string, size: number, mimeType: string) => any;
26
+ }
27
+ export declare const RETRY_SDK_COUNTS: {
28
+ GLOBAL: number;
29
+ REQUEST_IMAGES: number;
30
+ };
31
+ export declare const remove1Mutate: (col: any, targetElem: any) => void;
32
+ export declare const removeListener: (listeners: any[], listener: any) => any[];
33
+ export declare const removeAllKeyListener: ({ listeners, key, }: {
34
+ listeners: any[];
35
+ key: any;
36
+ }) => any[];
37
+ export declare enum LISTEN_TO_IMAGES_KEY {
38
+ REQUEST_IMAGES = "REQUEST_IMAGES"
39
+ }
40
+ export declare const evaluateNonTrue: ({ key, value, }: {
41
+ key: string;
42
+ value: any;
43
+ }) => {
44
+ [x: string]: any;
45
+ };
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evaluateNonTrue = exports.LISTEN_TO_IMAGES_KEY = exports.removeAllKeyListener = exports.removeListener = exports.remove1Mutate = exports.RETRY_SDK_COUNTS = exports.MockFile = exports.delay = exports.accessDeepObject = exports.getPreprocessorType = exports.compact = exports.isValidUUID = exports.getUUID = exports.fileToBase64 = exports.getIntervalWithPromise = exports.removeFromAray = exports.BASE_RUNWARE_URLS = void 0;
4
+ const types_1 = require("./types");
5
+ const uuid_1 = require("uuid");
6
+ const TIMEOUT_DURATION = 60000; // 120S;
7
+ const POLLING_INTERVAL = 100; // 1s;
8
+ exports.BASE_RUNWARE_URLS = {
9
+ [types_1.Environment.PRODUCTION]: "wss://ws-api.runware.ai/v1",
10
+ [types_1.Environment.TEST]: "ws://localhost:8080",
11
+ };
12
+ const removeFromAray = (col, targetElem) => {
13
+ if (col == null) {
14
+ return;
15
+ }
16
+ let i = col.indexOf(targetElem);
17
+ if (i === -1) {
18
+ return;
19
+ }
20
+ col.splice(i, 1);
21
+ };
22
+ exports.removeFromAray = removeFromAray;
23
+ const getIntervalWithPromise = (callback, { debugKey = "debugKey", timeOutDuration = TIMEOUT_DURATION, shouldThrowError = true, }) => {
24
+ return new Promise((resolve, reject) => {
25
+ const timeoutId = setTimeout(() => {
26
+ if (intervalId) {
27
+ clearInterval(intervalId);
28
+ if (shouldThrowError) {
29
+ reject(`Message could not be received for ${debugKey}`);
30
+ console.error("Message could not be received for ", debugKey);
31
+ }
32
+ }
33
+ clearTimeout(timeoutId);
34
+ // reject();
35
+ }, timeOutDuration);
36
+ let intervalId = setInterval(async () => {
37
+ const shouldClear = callback({ resolve, reject, intervalId });
38
+ if (shouldClear) {
39
+ clearInterval(intervalId);
40
+ clearTimeout(timeoutId);
41
+ }
42
+ // resolve(imagesWithSimilarTask); // Resolve the promise with the data
43
+ }, POLLING_INTERVAL); // Check every 1 second (adjust the interval as needed)
44
+ });
45
+ };
46
+ exports.getIntervalWithPromise = getIntervalWithPromise;
47
+ const fileToBase64 = (file) => new Promise((resolve) => {
48
+ const reader = new FileReader();
49
+ reader.readAsDataURL(file);
50
+ reader.onload = function () {
51
+ resolve(reader.result);
52
+ };
53
+ });
54
+ exports.fileToBase64 = fileToBase64;
55
+ // export const getUUID = () => crypto.randomUUID();
56
+ const getUUID = () => (0, uuid_1.v4)();
57
+ exports.getUUID = getUUID;
58
+ const isValidUUID = (uuid) => (0, uuid_1.validate)(uuid);
59
+ exports.isValidUUID = isValidUUID;
60
+ const evaluateToBoolean = (...args) => [...args].every((e) => !!e);
61
+ const compact = (value, data) => (!!value ? data : {});
62
+ exports.compact = compact;
63
+ const getPreprocessorType = (processor) => {
64
+ const processorGroup = Object.keys(types_1.EPreProcessorGroup);
65
+ switch (processor) {
66
+ case types_1.EPreProcessor.canny:
67
+ return types_1.EPreProcessorGroup.canny;
68
+ // break
69
+ case types_1.EPreProcessor.depth_leres:
70
+ case types_1.EPreProcessor.depth_midas:
71
+ case types_1.EPreProcessor.depth_zoe:
72
+ return types_1.EPreProcessorGroup.depth;
73
+ // break
74
+ case types_1.EPreProcessor.inpaint_global_harmonious:
75
+ return types_1.EPreProcessorGroup.depth;
76
+ // break
77
+ case types_1.EPreProcessor.lineart_anime:
78
+ return types_1.EPreProcessorGroup.lineart_anime;
79
+ // break
80
+ case types_1.EPreProcessor.lineart_coarse:
81
+ case types_1.EPreProcessor.lineart_realistic:
82
+ case types_1.EPreProcessor.lineart_standard:
83
+ return types_1.EPreProcessorGroup.lineart;
84
+ // break
85
+ case types_1.EPreProcessor.mlsd:
86
+ return types_1.EPreProcessorGroup.mlsd;
87
+ // break
88
+ case types_1.EPreProcessor.normal_bae:
89
+ return types_1.EPreProcessorGroup.normalbae;
90
+ // break
91
+ case types_1.EPreProcessor.openpose_face:
92
+ case types_1.EPreProcessor.openpose_faceonly:
93
+ case types_1.EPreProcessor.openpose_full:
94
+ case types_1.EPreProcessor.openpose_hand:
95
+ case types_1.EPreProcessor.openpose:
96
+ return types_1.EPreProcessorGroup.openpose;
97
+ // break
98
+ case types_1.EPreProcessor.scribble_hed:
99
+ case types_1.EPreProcessor.scribble_pidinet:
100
+ return types_1.EPreProcessorGroup.scribble;
101
+ // break
102
+ case types_1.EPreProcessor.seg_ofade20k:
103
+ case types_1.EPreProcessor.seg_ofcoco:
104
+ case types_1.EPreProcessor.seg_ufade20k:
105
+ return types_1.EPreProcessorGroup.seg;
106
+ // break
107
+ case types_1.EPreProcessor.shuffle:
108
+ return types_1.EPreProcessorGroup.shuffle;
109
+ // break
110
+ case types_1.EPreProcessor.softedge_hed:
111
+ case types_1.EPreProcessor.softedge_hedsafe:
112
+ case types_1.EPreProcessor.softedge_pidinet:
113
+ case types_1.EPreProcessor.softedge_pidisafe:
114
+ return types_1.EPreProcessorGroup.softedge;
115
+ // break
116
+ case types_1.EPreProcessor.tile_gaussian:
117
+ return types_1.EPreProcessorGroup.tile;
118
+ // break
119
+ default:
120
+ return types_1.EPreProcessorGroup.canny;
121
+ }
122
+ };
123
+ exports.getPreprocessorType = getPreprocessorType;
124
+ const accessDeepObject = ({ key, data, useZero = true, shouldReturnString = false, }) => {
125
+ const splittedKeys = key.split(/\.|\[/).map((key) => key.replace(/\]$/, ""));
126
+ const value = splittedKeys.reduce((acc, curr) => {
127
+ var _a, _b;
128
+ const returnZero = useZero ? 0 : undefined;
129
+ const currentValue = acc === null || acc === void 0 ? void 0 : acc[curr];
130
+ if (!currentValue) {
131
+ return returnZero;
132
+ }
133
+ if (Array.isArray(currentValue) && /^\d+$/.test(curr)) {
134
+ const index = parseInt(curr, 10);
135
+ if (index >= 0 && index < currentValue.length) {
136
+ return (acc[curr] = currentValue[index]);
137
+ }
138
+ else {
139
+ return (_a = acc[curr]) !== null && _a !== void 0 ? _a : returnZero;
140
+ }
141
+ }
142
+ else {
143
+ return (_b = acc[curr]) !== null && _b !== void 0 ? _b : returnZero;
144
+ }
145
+ }, data || {});
146
+ // if (typeof value === "object" && shouldReturnString) {
147
+ // return JSON.stringify(value);
148
+ // }
149
+ return value !== null && value !== void 0 ? value : {};
150
+ };
151
+ exports.accessDeepObject = accessDeepObject;
152
+ const delay = (time, milliseconds = 1000) => {
153
+ return new Promise((resolve) => setTimeout(resolve, time * milliseconds));
154
+ };
155
+ exports.delay = delay;
156
+ class MockFile {
157
+ constructor() {
158
+ this.create = function (name, size, mimeType) {
159
+ name = name || "mock.txt";
160
+ size = size || 1024;
161
+ mimeType = mimeType || "plain/txt";
162
+ var blob = new Blob([range(size)], { type: mimeType });
163
+ blob.lastModifiedDate = new Date();
164
+ blob.name = name;
165
+ return blob;
166
+ };
167
+ }
168
+ }
169
+ exports.MockFile = MockFile;
170
+ function range(count) {
171
+ var output = "";
172
+ for (var i = 0; i < count; i++) {
173
+ output += "a";
174
+ }
175
+ return output;
176
+ }
177
+ exports.RETRY_SDK_COUNTS = {
178
+ GLOBAL: 2,
179
+ REQUEST_IMAGES: 2,
180
+ };
181
+ const remove1Mutate = (col, targetElem) => {
182
+ if (col == null) {
183
+ return;
184
+ }
185
+ let i = col.indexOf(targetElem);
186
+ if (i === -1) {
187
+ return;
188
+ }
189
+ col.splice(i, 1);
190
+ };
191
+ exports.remove1Mutate = remove1Mutate;
192
+ const removeListener = (listeners, listener) => {
193
+ return listeners.filter((lis) => lis.key !== listener.key);
194
+ };
195
+ exports.removeListener = removeListener;
196
+ const removeAllKeyListener = ({ listeners, key, }) => {
197
+ return listeners.filter((lis) => (lis === null || lis === void 0 ? void 0 : lis.key) !== key);
198
+ };
199
+ exports.removeAllKeyListener = removeAllKeyListener;
200
+ var LISTEN_TO_IMAGES_KEY;
201
+ (function (LISTEN_TO_IMAGES_KEY) {
202
+ LISTEN_TO_IMAGES_KEY["REQUEST_IMAGES"] = "REQUEST_IMAGES";
203
+ })(LISTEN_TO_IMAGES_KEY || (exports.LISTEN_TO_IMAGES_KEY = LISTEN_TO_IMAGES_KEY = {}));
204
+ const evaluateNonTrue = ({ key, value, }) => {
205
+ if (!!value || value === 0 || value === false) {
206
+ return { [key]: value };
207
+ }
208
+ else {
209
+ return {};
210
+ }
211
+ };
212
+ exports.evaluateNonTrue = evaluateNonTrue;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
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 enhance prompt", 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 give an enhanced prompt", async () => {
23
+ const globalListenerSpy = vitest_1.vi.spyOn(runware, "globalListener");
24
+ const sendSpy = vitest_1.vi.spyOn(runware, "send");
25
+ await runware.enhancePrompt({
26
+ prompt: "Mock prompt",
27
+ promptMaxLength: 200,
28
+ promptVersions: 4,
29
+ });
30
+ (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith({
31
+ prompt: "Mock prompt",
32
+ taskUUID: test_utils_1.mockTaskUUID,
33
+ promptMaxLength: 200,
34
+ promptVersions: 4,
35
+ taskType: Runware_1.ETaskType.PROMPT_ENHANCE,
36
+ });
37
+ (0, vitest_1.expect)(globalListenerSpy).toHaveBeenCalledWith({
38
+ taskUUID: test_utils_1.mockTaskUUID,
39
+ });
40
+ });
41
+ (0, vitest_1.test)("it should give an enhanced prompt with default config", async () => {
42
+ const globalListenerSpy = vitest_1.vi.spyOn(runware, "globalListener");
43
+ const sendSpy = vitest_1.vi.spyOn(runware, "send");
44
+ await runware.enhancePrompt({
45
+ prompt: "Mock prompt",
46
+ });
47
+ (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith({
48
+ prompt: "Mock prompt",
49
+ taskUUID: test_utils_1.mockTaskUUID,
50
+ promptMaxLength: 380,
51
+ promptVersions: 1,
52
+ taskType: Runware_1.ETaskType.PROMPT_ENHANCE,
53
+ });
54
+ (0, vitest_1.expect)(globalListenerSpy).toHaveBeenCalledWith({
55
+ taskUUID: test_utils_1.mockTaskUUID,
56
+ });
57
+ });
58
+ });
@@ -0,0 +1,37 @@
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 remove image background", 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 remove an image background", 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.removeImageBackground({ inputImage: test_utils_1.mockUploadFile });
27
+ (0, vitest_1.expect)(imageUploadSpy).toHaveBeenCalled();
28
+ (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith({
29
+ inputImage: test_utils_1.testExamples.imageUploadRes.imageUUID,
30
+ taskUUID: test_utils_1.mockTaskUUID,
31
+ taskType: Runware_1.ETaskType.IMAGE_BACKGROUND_REMOVAL,
32
+ });
33
+ (0, vitest_1.expect)(globalListenerSpy).toHaveBeenCalledWith({
34
+ taskUUID: test_utils_1.mockTaskUUID,
35
+ });
36
+ });
37
+ });
@@ -0,0 +1,37 @@
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 image to text", 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 get a text conversion", 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.requestImageToText({ inputImage: test_utils_1.mockUploadFile });
27
+ (0, vitest_1.expect)(imageUploadSpy).toHaveBeenCalled();
28
+ (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith({
29
+ inputImage: test_utils_1.testExamples.imageUploadRes.imageUUID,
30
+ taskUUID: test_utils_1.mockTaskUUID,
31
+ taskType: Runware_1.ETaskType.IMAGE_CAPTION,
32
+ });
33
+ (0, vitest_1.expect)(globalListenerSpy).toHaveBeenCalledWith({
34
+ taskUUID: test_utils_1.mockTaskUUID,
35
+ });
36
+ });
37
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
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,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,52 @@
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
+ const Runware_1 = require("../../Runware");
8
+ vitest_1.vi.mock("../../Runware/utils", async () => {
9
+ const actual = await vitest_1.vi.importActual("../../Runware/utils");
10
+ 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") });
11
+ });
12
+ (0, vitest_1.describe)("When user uploads an image:", async () => {
13
+ const { mockServer, runware } = await (0, mockServer_1.startMockServer)();
14
+ (0, vitest_1.afterEach)(() => {
15
+ vitest_1.vi.clearAllMocks();
16
+ });
17
+ (0, vitest_1.beforeEach)(() => {
18
+ mockServer.stop();
19
+ });
20
+ (0, vitest_1.test)("it should accept string during image upload", async () => {
21
+ const sendSpy = vitest_1.vi.spyOn(runware, "send");
22
+ await runware["uploadImage"]("IMAGE_UPLOAD");
23
+ (0, vitest_1.expect)(utils_1.fileToBase64).to.not.toHaveBeenCalled();
24
+ (0, vitest_1.expect)(sendSpy).toBeCalledTimes(1);
25
+ });
26
+ (0, vitest_1.test)("it should accept file during image upload", async () => {
27
+ const sendSpy = vitest_1.vi.spyOn(runware, "send");
28
+ await runware["uploadImage"](test_utils_1.mockUploadFile);
29
+ (0, vitest_1.expect)(utils_1.fileToBase64).toHaveBeenCalled();
30
+ (0, vitest_1.expect)(sendSpy).toBeCalledTimes(1);
31
+ (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith({
32
+ image: test_utils_1.mockFileToBase64,
33
+ taskUUID: test_utils_1.mockTaskUUID,
34
+ taskType: Runware_1.ETaskType.IMAGE_UPLOAD,
35
+ });
36
+ });
37
+ (0, vitest_1.test)("it should upload image successfully", async () => {
38
+ const sendSpy = vitest_1.vi.spyOn(runware, "send");
39
+ const globalListenerSpy = vitest_1.vi.spyOn(runware, "globalListener");
40
+ await runware["uploadImage"](test_utils_1.mockTextImageUpload);
41
+ (0, vitest_1.expect)(utils_1.fileToBase64).to.not.toHaveBeenCalled();
42
+ (0, vitest_1.expect)(sendSpy).toHaveBeenCalledWith({
43
+ image: test_utils_1.mockTextImageUpload,
44
+ taskUUID: test_utils_1.mockTaskUUID,
45
+ taskType: Runware_1.ETaskType.IMAGE_UPLOAD,
46
+ });
47
+ (0, vitest_1.expect)(globalListenerSpy).toHaveBeenCalledWith({
48
+ taskUUID: test_utils_1.mockTaskUUID,
49
+ });
50
+ (0, vitest_1.expect)(utils_1.getIntervalWithPromise).toHaveBeenCalledTimes(1);
51
+ });
52
+ });
@@ -0,0 +1 @@
1
+ export {};