@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,156 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EPhotoMakerEnum = exports.EModelConditioning = exports.EModelType = exports.EModelArchitecture = exports.EModelFormat = 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["REMOVE_BACKGROUND"] = "removeBackground";
22
- ETaskType["VIDEO_INFERENCE"] = "videoInference";
23
- ETaskType["GET_RESPONSE"] = "getResponse";
24
- ETaskType["PHOTO_MAKER"] = "photoMaker";
25
- ETaskType["IMAGE_CAPTION"] = "imageCaption";
26
- ETaskType["IMAGE_CONTROL_NET_PRE_PROCESS"] = "imageControlNetPreProcess";
27
- ETaskType["IMAGE_MASKING"] = "imageMasking";
28
- ETaskType["PROMPT_ENHANCE"] = "promptEnhance";
29
- ETaskType["AUTHENTICATION"] = "authentication";
30
- ETaskType["MODEL_UPLOAD"] = "modelUpload";
31
- ETaskType["MODEL_SEARCH"] = "modelSearch";
32
- })(ETaskType || (exports.ETaskType = ETaskType = {}));
33
- var EControlMode;
34
- (function (EControlMode) {
35
- EControlMode["BALANCED"] = "balanced";
36
- EControlMode["PROMPT"] = "prompt";
37
- EControlMode["CONTROL_NET"] = "controlnet";
38
- })(EControlMode || (exports.EControlMode = EControlMode = {}));
39
- var EPreProcessorGroup;
40
- (function (EPreProcessorGroup) {
41
- EPreProcessorGroup["canny"] = "canny";
42
- EPreProcessorGroup["depth"] = "depth";
43
- EPreProcessorGroup["mlsd"] = "mlsd";
44
- EPreProcessorGroup["normalbae"] = "normalbae";
45
- EPreProcessorGroup["openpose"] = "openpose";
46
- EPreProcessorGroup["tile"] = "tile";
47
- EPreProcessorGroup["seg"] = "seg";
48
- EPreProcessorGroup["lineart"] = "lineart";
49
- EPreProcessorGroup["lineart_anime"] = "lineart_anime";
50
- EPreProcessorGroup["shuffle"] = "shuffle";
51
- EPreProcessorGroup["scribble"] = "scribble";
52
- EPreProcessorGroup["softedge"] = "softedge";
53
- })(EPreProcessorGroup || (exports.EPreProcessorGroup = EPreProcessorGroup = {}));
54
- var EPreProcessor;
55
- (function (EPreProcessor) {
56
- EPreProcessor["canny"] = "canny";
57
- EPreProcessor["depth_leres"] = "depth_leres";
58
- EPreProcessor["depth_midas"] = "depth_midas";
59
- EPreProcessor["depth_zoe"] = "depth_zoe";
60
- EPreProcessor["inpaint_global_harmonious"] = "inpaint_global_harmonious";
61
- EPreProcessor["lineart_anime"] = "lineart_anime";
62
- EPreProcessor["lineart_coarse"] = "lineart_coarse";
63
- EPreProcessor["lineart_realistic"] = "lineart_realistic";
64
- EPreProcessor["lineart_standard"] = "lineart_standard";
65
- EPreProcessor["mlsd"] = "mlsd";
66
- EPreProcessor["normal_bae"] = "normal_bae";
67
- EPreProcessor["scribble_hed"] = "scribble_hed";
68
- EPreProcessor["scribble_pidinet"] = "scribble_pidinet";
69
- EPreProcessor["seg_ofade20k"] = "seg_ofade20k";
70
- EPreProcessor["seg_ofcoco"] = "seg_ofcoco";
71
- EPreProcessor["seg_ufade20k"] = "seg_ufade20k";
72
- EPreProcessor["shuffle"] = "shuffle";
73
- EPreProcessor["softedge_hed"] = "softedge_hed";
74
- EPreProcessor["softedge_hedsafe"] = "softedge_hedsafe";
75
- EPreProcessor["softedge_pidinet"] = "softedge_pidinet";
76
- EPreProcessor["softedge_pidisafe"] = "softedge_pidisafe";
77
- EPreProcessor["tile_gaussian"] = "tile_gaussian";
78
- EPreProcessor["openpose"] = "openpose";
79
- EPreProcessor["openpose_face"] = "openpose_face";
80
- EPreProcessor["openpose_faceonly"] = "openpose_faceonly";
81
- EPreProcessor["openpose_full"] = "openpose_full";
82
- EPreProcessor["openpose_hand"] = "openpose_hand";
83
- })(EPreProcessor || (exports.EPreProcessor = EPreProcessor = {}));
84
- var EOpenPosePreProcessor;
85
- (function (EOpenPosePreProcessor) {
86
- EOpenPosePreProcessor["openpose"] = "openpose";
87
- EOpenPosePreProcessor["openpose_face"] = "openpose_face";
88
- EOpenPosePreProcessor["openpose_faceonly"] = "openpose_faceonly";
89
- EOpenPosePreProcessor["openpose_full"] = "openpose_full";
90
- EOpenPosePreProcessor["openpose_hand"] = "openpose_hand";
91
- })(EOpenPosePreProcessor || (exports.EOpenPosePreProcessor = EOpenPosePreProcessor = {}));
92
- var EModelFormat;
93
- (function (EModelFormat) {
94
- EModelFormat["safetensors"] = "safetensors";
95
- EModelFormat["pickletensor"] = "pickletensor";
96
- })(EModelFormat || (exports.EModelFormat = EModelFormat = {}));
97
- var EModelArchitecture;
98
- (function (EModelArchitecture) {
99
- EModelArchitecture["flux1d"] = "flux1d";
100
- EModelArchitecture["flux1s"] = "flux1s";
101
- EModelArchitecture["pony"] = "pony";
102
- EModelArchitecture["sdhyper"] = "sdhyper";
103
- EModelArchitecture["sd1x"] = "sd1x";
104
- EModelArchitecture["sd1xlcm"] = "sd1xlcm";
105
- EModelArchitecture["sd3"] = "sd3";
106
- EModelArchitecture["sdxl"] = "sdxl";
107
- EModelArchitecture["sdxllcm"] = "sdxllcm";
108
- EModelArchitecture["sdxldistilled"] = "sdxldistilled";
109
- EModelArchitecture["sdxlhyper"] = "sdxlhyper";
110
- EModelArchitecture["sdxllightning"] = "sdxllightning";
111
- EModelArchitecture["sdxlturbo"] = "sdxlturbo";
112
- })(EModelArchitecture || (exports.EModelArchitecture = EModelArchitecture = {}));
113
- var EModelType;
114
- (function (EModelType) {
115
- EModelType["base"] = "base";
116
- EModelType["inpainting"] = "inpainting";
117
- EModelType["pix2pix"] = "pix2pix";
118
- })(EModelType || (exports.EModelType = EModelType = {}));
119
- var EModelConditioning;
120
- (function (EModelConditioning) {
121
- EModelConditioning["canny"] = "canny";
122
- EModelConditioning["depth"] = "depth";
123
- EModelConditioning["qrcode"] = "qrcode";
124
- EModelConditioning["hed"] = "hed";
125
- EModelConditioning["scrible"] = "scrible";
126
- EModelConditioning["openpose"] = "openpose";
127
- EModelConditioning["seg"] = "segmentation";
128
- EModelConditioning["openmlsd"] = "openmlsd";
129
- EModelConditioning["softedge"] = "softedge";
130
- EModelConditioning["normal"] = "normal bae";
131
- EModelConditioning["shuffle"] = "shuffle";
132
- EModelConditioning["pix2pix"] = "pix2pix";
133
- EModelConditioning["inpaint"] = "inpaint";
134
- EModelConditioning["lineart"] = "line art";
135
- EModelConditioning["sketch"] = "sketch";
136
- EModelConditioning["inpaintdepth"] = "inpaint depth";
137
- EModelConditioning["tile"] = "tile";
138
- EModelConditioning["outfit"] = "outfit";
139
- EModelConditioning["blur"] = "blur";
140
- EModelConditioning["gray"] = "gray";
141
- EModelConditioning["lowquality"] = "low quality";
142
- })(EModelConditioning || (exports.EModelConditioning = EModelConditioning = {}));
143
- var EPhotoMakerEnum;
144
- (function (EPhotoMakerEnum) {
145
- EPhotoMakerEnum["NoStyle"] = "No style";
146
- EPhotoMakerEnum["Cinematic"] = "Cinematic";
147
- EPhotoMakerEnum["DisneyCharacter"] = "Disney Character";
148
- EPhotoMakerEnum["DigitalArt"] = "Digital Art";
149
- EPhotoMakerEnum["Photographic"] = "Photographic";
150
- EPhotoMakerEnum["FantasyArt"] = "Fantasy art";
151
- EPhotoMakerEnum["Neonpunk"] = "Neonpunk";
152
- EPhotoMakerEnum["Enhance"] = "Enhance";
153
- EPhotoMakerEnum["ComicBook"] = "Comic book";
154
- EPhotoMakerEnum["Lowpoly"] = "Lowpoly";
155
- EPhotoMakerEnum["LineArt"] = "Line art";
156
- })(EPhotoMakerEnum || (exports.EPhotoMakerEnum = EPhotoMakerEnum = {}));
@@ -1,57 +0,0 @@
1
- import { EPreProcessor, EPreProcessorGroup, GetWithPromiseAsyncCallBackType, GetWithPromiseCallBackType } from "./types";
2
- export declare const TIMEOUT_DURATION = 60000;
3
- export declare const MINIMUM_TIMEOUT_DURATION = 1000;
4
- export declare const BASE_RUNWARE_URLS: {
5
- PRODUCTION: string;
6
- TEST: string;
7
- };
8
- export declare const removeFromAray: <T>(col: T[], targetElem: T) => void;
9
- export declare const getIntervalWithPromise: (callback: GetWithPromiseCallBackType, { debugKey, timeoutDuration, shouldThrowError, pollingInterval, }: {
10
- debugKey?: string | undefined;
11
- timeoutDuration?: number | undefined;
12
- shouldThrowError?: boolean | undefined;
13
- pollingInterval?: number | undefined;
14
- }) => Promise<unknown>;
15
- export declare const fileToBase64: (file: File) => Promise<unknown>;
16
- export declare const getUUID: () => string;
17
- export declare const isValidUUID: (uuid: string) => boolean;
18
- export declare const compact: (value: any, data: any) => any;
19
- export declare const getPreprocessorType: (processor: EPreProcessor) => EPreProcessorGroup;
20
- export declare const accessDeepObject: ({ key, data, useZero, shouldReturnString, }: {
21
- key: string;
22
- data: Record<string, any>;
23
- useZero?: boolean | undefined;
24
- shouldReturnString?: boolean | undefined;
25
- }) => Record<string, any>;
26
- export declare const delay: (time: number, milliseconds?: number) => Promise<unknown>;
27
- export declare class MockFile {
28
- create: (name: string, size: number, mimeType: string) => any;
29
- }
30
- export declare const RETRY_SDK_COUNTS: {
31
- GLOBAL: number;
32
- REQUEST_IMAGES: number;
33
- };
34
- export declare const remove1Mutate: (col: any, targetElem: any) => void;
35
- export declare const removeListener: (listeners: any[], listener: any) => any[];
36
- export declare const removeAllKeyListener: ({ listeners, key, }: {
37
- listeners: any[];
38
- key: any;
39
- }) => any[];
40
- export declare enum LISTEN_TO_IMAGES_KEY {
41
- REQUEST_IMAGES = "REQUEST_IMAGES"
42
- }
43
- export declare const evaluateNonTrue: ({ key, value, }: {
44
- key: string;
45
- value: any;
46
- }) => {
47
- [x: string]: any;
48
- };
49
- export declare const getRandomNumber: (min: number, max: number) => number;
50
- export declare const getRandomSeed: () => number;
51
- export declare const getIntervalAsyncWithPromise: (callback: GetWithPromiseAsyncCallBackType, { debugKey, timeoutDuration, shouldThrowError, pollingInterval, }: {
52
- debugKey?: string | undefined;
53
- timeoutDuration?: number | undefined;
54
- shouldThrowError?: boolean | undefined;
55
- pollingInterval?: number | undefined;
56
- }) => Promise<unknown>;
57
- export declare const isUrl: (value: any) => value is string;
@@ -1,262 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUrl = exports.getIntervalAsyncWithPromise = exports.getRandomSeed = exports.getRandomNumber = 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 = exports.MINIMUM_TIMEOUT_DURATION = exports.TIMEOUT_DURATION = void 0;
4
- const types_1 = require("./types");
5
- const uuid_1 = require("uuid");
6
- exports.TIMEOUT_DURATION = 60000; // 120S;
7
- exports.MINIMUM_TIMEOUT_DURATION = 1000; // 120S;
8
- const POLLING_INTERVAL = 100; // 1s;
9
- exports.BASE_RUNWARE_URLS = {
10
- [types_1.Environment.PRODUCTION]: "wss://ws-api.runware.ai/v1",
11
- [types_1.Environment.TEST]: "ws://localhost:8080",
12
- };
13
- const removeFromAray = (col, targetElem) => {
14
- if (col == null) {
15
- return;
16
- }
17
- let i = col.indexOf(targetElem);
18
- if (i === -1) {
19
- return;
20
- }
21
- col.splice(i, 1);
22
- };
23
- exports.removeFromAray = removeFromAray;
24
- const getIntervalWithPromise = (callback, { debugKey = "debugKey", timeoutDuration = exports.TIMEOUT_DURATION, shouldThrowError = true, pollingInterval = POLLING_INTERVAL, }) => {
25
- timeoutDuration =
26
- timeoutDuration < exports.MINIMUM_TIMEOUT_DURATION
27
- ? exports.MINIMUM_TIMEOUT_DURATION
28
- : timeoutDuration;
29
- return new Promise((resolve, reject) => {
30
- const timeoutId = setTimeout(() => {
31
- if (intervalId) {
32
- clearInterval(intervalId);
33
- if (shouldThrowError) {
34
- reject(`Response could not be received from server for ${debugKey}`);
35
- }
36
- }
37
- clearTimeout(timeoutId);
38
- // reject();
39
- }, timeoutDuration);
40
- let intervalId = setInterval(async () => {
41
- const shouldClear = callback({ resolve, reject, intervalId });
42
- if (shouldClear) {
43
- clearInterval(intervalId);
44
- clearTimeout(timeoutId);
45
- }
46
- // resolve(imagesWithSimilarTask); // Resolve the promise with the data
47
- }, pollingInterval); // Check every 1 second (adjust the interval as needed)
48
- });
49
- };
50
- exports.getIntervalWithPromise = getIntervalWithPromise;
51
- const fileToBase64 = (file) => new Promise((resolve) => {
52
- const reader = new FileReader();
53
- reader.readAsDataURL(file);
54
- reader.onload = function () {
55
- resolve(reader.result);
56
- };
57
- });
58
- exports.fileToBase64 = fileToBase64;
59
- // export const getUUID = () => crypto.randomUUID();
60
- const getUUID = () => (0, uuid_1.v4)();
61
- exports.getUUID = getUUID;
62
- const isValidUUID = (uuid) => (0, uuid_1.validate)(uuid);
63
- exports.isValidUUID = isValidUUID;
64
- const evaluateToBoolean = (...args) => [...args].every((e) => !!e);
65
- const compact = (value, data) => (!!value ? data : {});
66
- exports.compact = compact;
67
- const getPreprocessorType = (processor) => {
68
- const processorGroup = Object.keys(types_1.EPreProcessorGroup);
69
- switch (processor) {
70
- case types_1.EPreProcessor.canny:
71
- return types_1.EPreProcessorGroup.canny;
72
- // break
73
- case types_1.EPreProcessor.depth_leres:
74
- case types_1.EPreProcessor.depth_midas:
75
- case types_1.EPreProcessor.depth_zoe:
76
- return types_1.EPreProcessorGroup.depth;
77
- // break
78
- case types_1.EPreProcessor.inpaint_global_harmonious:
79
- return types_1.EPreProcessorGroup.depth;
80
- // break
81
- case types_1.EPreProcessor.lineart_anime:
82
- return types_1.EPreProcessorGroup.lineart_anime;
83
- // break
84
- case types_1.EPreProcessor.lineart_coarse:
85
- case types_1.EPreProcessor.lineart_realistic:
86
- case types_1.EPreProcessor.lineart_standard:
87
- return types_1.EPreProcessorGroup.lineart;
88
- // break
89
- case types_1.EPreProcessor.mlsd:
90
- return types_1.EPreProcessorGroup.mlsd;
91
- // break
92
- case types_1.EPreProcessor.normal_bae:
93
- return types_1.EPreProcessorGroup.normalbae;
94
- // break
95
- case types_1.EPreProcessor.openpose_face:
96
- case types_1.EPreProcessor.openpose_faceonly:
97
- case types_1.EPreProcessor.openpose_full:
98
- case types_1.EPreProcessor.openpose_hand:
99
- case types_1.EPreProcessor.openpose:
100
- return types_1.EPreProcessorGroup.openpose;
101
- // break
102
- case types_1.EPreProcessor.scribble_hed:
103
- case types_1.EPreProcessor.scribble_pidinet:
104
- return types_1.EPreProcessorGroup.scribble;
105
- // break
106
- case types_1.EPreProcessor.seg_ofade20k:
107
- case types_1.EPreProcessor.seg_ofcoco:
108
- case types_1.EPreProcessor.seg_ufade20k:
109
- return types_1.EPreProcessorGroup.seg;
110
- // break
111
- case types_1.EPreProcessor.shuffle:
112
- return types_1.EPreProcessorGroup.shuffle;
113
- // break
114
- case types_1.EPreProcessor.softedge_hed:
115
- case types_1.EPreProcessor.softedge_hedsafe:
116
- case types_1.EPreProcessor.softedge_pidinet:
117
- case types_1.EPreProcessor.softedge_pidisafe:
118
- return types_1.EPreProcessorGroup.softedge;
119
- // break
120
- case types_1.EPreProcessor.tile_gaussian:
121
- return types_1.EPreProcessorGroup.tile;
122
- // break
123
- default:
124
- return types_1.EPreProcessorGroup.canny;
125
- }
126
- };
127
- exports.getPreprocessorType = getPreprocessorType;
128
- const accessDeepObject = ({ key, data, useZero = true, shouldReturnString = false, }) => {
129
- const splittedKeys = key.split(/\.|\[/).map((key) => key.replace(/\]$/, ""));
130
- const value = splittedKeys.reduce((acc, curr) => {
131
- var _a, _b;
132
- const returnZero = useZero ? 0 : undefined;
133
- const currentValue = acc === null || acc === void 0 ? void 0 : acc[curr];
134
- if (!currentValue) {
135
- return returnZero;
136
- }
137
- if (Array.isArray(currentValue) && /^\d+$/.test(curr)) {
138
- const index = parseInt(curr, 10);
139
- if (index >= 0 && index < currentValue.length) {
140
- return (acc[curr] = currentValue[index]);
141
- }
142
- else {
143
- return (_a = acc[curr]) !== null && _a !== void 0 ? _a : returnZero;
144
- }
145
- }
146
- else {
147
- return (_b = acc[curr]) !== null && _b !== void 0 ? _b : returnZero;
148
- }
149
- }, data || {});
150
- // if (typeof value === "object" && shouldReturnString) {
151
- // return JSON.stringify(value);
152
- // }
153
- return value !== null && value !== void 0 ? value : {};
154
- };
155
- exports.accessDeepObject = accessDeepObject;
156
- const delay = (time, milliseconds = 1000) => {
157
- return new Promise((resolve) => setTimeout(resolve, time * milliseconds));
158
- };
159
- exports.delay = delay;
160
- class MockFile {
161
- constructor() {
162
- this.create = function (name, size, mimeType) {
163
- name = name || "mock.txt";
164
- size = size || 1024;
165
- mimeType = mimeType || "plain/txt";
166
- var blob = new Blob([range(size)], { type: mimeType });
167
- blob.lastModifiedDate = new Date();
168
- blob.name = name;
169
- return blob;
170
- };
171
- }
172
- }
173
- exports.MockFile = MockFile;
174
- function range(count) {
175
- var output = "";
176
- for (var i = 0; i < count; i++) {
177
- output += "a";
178
- }
179
- return output;
180
- }
181
- exports.RETRY_SDK_COUNTS = {
182
- GLOBAL: 2,
183
- REQUEST_IMAGES: 2,
184
- };
185
- const remove1Mutate = (col, targetElem) => {
186
- if (col == null) {
187
- return;
188
- }
189
- let i = col.indexOf(targetElem);
190
- if (i === -1) {
191
- return;
192
- }
193
- col.splice(i, 1);
194
- };
195
- exports.remove1Mutate = remove1Mutate;
196
- const removeListener = (listeners, listener) => {
197
- return listeners.filter((lis) => lis.key !== listener.key);
198
- };
199
- exports.removeListener = removeListener;
200
- const removeAllKeyListener = ({ listeners, key, }) => {
201
- return listeners.filter((lis) => (lis === null || lis === void 0 ? void 0 : lis.key) !== key);
202
- };
203
- exports.removeAllKeyListener = removeAllKeyListener;
204
- var LISTEN_TO_IMAGES_KEY;
205
- (function (LISTEN_TO_IMAGES_KEY) {
206
- LISTEN_TO_IMAGES_KEY["REQUEST_IMAGES"] = "REQUEST_IMAGES";
207
- })(LISTEN_TO_IMAGES_KEY || (exports.LISTEN_TO_IMAGES_KEY = LISTEN_TO_IMAGES_KEY = {}));
208
- const evaluateNonTrue = ({ key, value, }) => {
209
- if (!!value || value === 0 || value === false) {
210
- return { [key]: value };
211
- }
212
- else {
213
- return {};
214
- }
215
- };
216
- exports.evaluateNonTrue = evaluateNonTrue;
217
- const getRandomNumber = (min, max) => {
218
- return Math.floor(Math.random() * (max - min + 1)) + min;
219
- };
220
- exports.getRandomNumber = getRandomNumber;
221
- const getRandomSeed = () => {
222
- return (0, exports.getRandomNumber)(1, Number.MAX_SAFE_INTEGER);
223
- };
224
- exports.getRandomSeed = getRandomSeed;
225
- const getIntervalAsyncWithPromise = (callback, { debugKey = "debugKey", timeoutDuration = exports.TIMEOUT_DURATION, shouldThrowError = true, pollingInterval = POLLING_INTERVAL, }) => {
226
- timeoutDuration =
227
- timeoutDuration < exports.MINIMUM_TIMEOUT_DURATION
228
- ? exports.MINIMUM_TIMEOUT_DURATION
229
- : timeoutDuration;
230
- return new Promise((resolve, reject) => {
231
- const timeoutId = setTimeout(() => {
232
- if (intervalId) {
233
- clearInterval(intervalId);
234
- if (shouldThrowError) {
235
- reject(`Response could not be received from server for ${debugKey}`);
236
- }
237
- }
238
- clearTimeout(timeoutId);
239
- }, timeoutDuration);
240
- let intervalId = setInterval(async () => {
241
- try {
242
- const shouldClear = await callback({ resolve, reject, intervalId });
243
- if (shouldClear) {
244
- clearInterval(intervalId);
245
- clearTimeout(timeoutId);
246
- }
247
- }
248
- catch (error) {
249
- clearInterval(intervalId);
250
- clearTimeout(timeoutId);
251
- reject(error);
252
- }
253
- }, pollingInterval);
254
- });
255
- };
256
- exports.getIntervalAsyncWithPromise = getIntervalAsyncWithPromise;
257
- const isUrl = (value) => {
258
- return (typeof value === "string" &&
259
- (value.startsWith("http:") ||
260
- value.startsWith("https:")));
261
- };
262
- exports.isUrl = isUrl;
@@ -1 +0,0 @@
1
- export {};
@@ -1,58 +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 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
- });
@@ -1,37 +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 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
- });
@@ -1,37 +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 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
- });
@@ -1 +0,0 @@
1
- export {};