@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,5 +0,0 @@
1
- import { RunwareBase } from "./Runware-base";
2
- import { RunwareBaseType } from "./types";
3
- export declare class RunwareClient extends RunwareBase {
4
- constructor(props: RunwareBaseType);
5
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.RunwareClient = void 0;
18
- const Runware_base_1 = require("./Runware-base");
19
- const reconnect_1 = __importDefault(require("./reconnect"));
20
- class RunwareClient extends Runware_base_1.RunwareBase {
21
- constructor(props) {
22
- const { shouldReconnect } = props, rest = __rest(props, ["shouldReconnect"]);
23
- super(rest);
24
- this._ws = new reconnect_1.default(this._url);
25
- this.connect();
26
- }
27
- }
28
- exports.RunwareClient = RunwareClient;
@@ -1,15 +0,0 @@
1
- import { RunwareBase } from "./Runware-base";
2
- import { RunwareBaseType } from "./types";
3
- export declare class RunwareServer extends RunwareBase {
4
- _instantiated: boolean;
5
- _listeners: any[];
6
- _reconnectingIntervalId: null | any;
7
- _pingTimeout: any;
8
- _pongListener: any;
9
- constructor(props: RunwareBaseType);
10
- protected connect(): Promise<void>;
11
- protected send: (msg: Object) => void;
12
- protected handleClose(): void;
13
- protected resetConnection: () => void;
14
- protected heartBeat(): void;
15
- }
@@ -1,145 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.RunwareServer = void 0;
7
- // @ts-ignore
8
- // import ReconnectingWebsocket from "./reconnect";
9
- const ws_1 = __importDefault(require("ws"));
10
- const Runware_base_1 = require("./Runware-base");
11
- const types_1 = require("./types");
12
- // let allImages: IImage[] = [];
13
- class RunwareServer extends Runware_base_1.RunwareBase {
14
- constructor(props) {
15
- super(props);
16
- this._instantiated = false;
17
- this._listeners = [];
18
- this._reconnectingIntervalId = null;
19
- this.send = (msg) => {
20
- this._ws.send(JSON.stringify([msg]));
21
- };
22
- this.resetConnection = () => {
23
- if (this._ws) {
24
- this._listeners.forEach((list) => {
25
- var _a;
26
- (_a = list === null || list === void 0 ? void 0 : list.destroy) === null || _a === void 0 ? void 0 : _a.call(list);
27
- });
28
- this._ws.removeAllListeners(); // Remove all listeners
29
- if (this._ws.readyState === 1) {
30
- this._ws.terminate();
31
- this._ws.close(); // Attempt to close gracefully
32
- }
33
- this._ws = null;
34
- this._listeners = [];
35
- }
36
- };
37
- this._sdkType = types_1.SdkType.SERVER;
38
- this.connect();
39
- }
40
- // protected addListener({
41
- // lis,
42
- // check,
43
- // groupKey,
44
- // }: {
45
- // lis: (v: any) => any;
46
- // check: (v: any) => any;
47
- // groupKey?: string;
48
- // }) {
49
- // const listener = (msg: any) => {
50
- // if (msg?.error) {
51
- // lis(msg);
52
- // } else if (check(msg)) {
53
- // lis(msg);
54
- // }
55
- // };
56
- // const groupListener = { key: getUUID(), listener, groupKey };
57
- // this._listeners.push(groupListener);
58
- // const destroy = () => {
59
- // this._listeners = removeListener(this._listeners, groupListener);
60
- // };
61
- // return {
62
- // destroy,
63
- // };
64
- // }
65
- async connect() {
66
- if (!this._url)
67
- return;
68
- this.resetConnection();
69
- this._ws = new ws_1.default(this._url, {
70
- perMessageDeflate: false,
71
- });
72
- // delay(1);
73
- this._ws.on("error", () => { });
74
- this._ws.on("close", () => {
75
- this.handleClose();
76
- });
77
- this._ws.on("open", () => {
78
- if (this._reconnectingIntervalId) {
79
- clearInterval(this._reconnectingIntervalId);
80
- }
81
- if (this._connectionSessionUUID && this.isWebsocketReadyState()) {
82
- this.send({
83
- taskType: types_1.ETaskType.AUTHENTICATION,
84
- apiKey: this._apiKey,
85
- connectionSessionUUID: this._connectionSessionUUID,
86
- });
87
- }
88
- else {
89
- if (this.isWebsocketReadyState()) {
90
- this.send({
91
- apiKey: this._apiKey,
92
- taskType: types_1.ETaskType.AUTHENTICATION,
93
- });
94
- }
95
- }
96
- this.addListener({
97
- taskUUID: types_1.ETaskType.AUTHENTICATION,
98
- lis: (m) => {
99
- var _a, _b;
100
- if (m === null || m === void 0 ? void 0 : m.error) {
101
- this._connectionError = m;
102
- return;
103
- }
104
- this._connectionSessionUUID =
105
- (_b = (_a = m === null || m === void 0 ? void 0 : m[types_1.ETaskType.AUTHENTICATION]) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.connectionSessionUUID;
106
- this._connectionError = undefined;
107
- },
108
- });
109
- });
110
- this._ws.on("message", (e, isBinary) => {
111
- const data = isBinary ? e : e === null || e === void 0 ? void 0 : e.toString();
112
- if (!data)
113
- return;
114
- const m = JSON.parse(data);
115
- // console.log("response", JSON.stringify(m, null, 4));
116
- this._listeners.forEach((lis) => {
117
- const result = lis.listener(m);
118
- if (result) {
119
- return;
120
- }
121
- });
122
- });
123
- }
124
- handleClose() {
125
- if (this.isInvalidAPIKey()) {
126
- return;
127
- }
128
- if (this._reconnectingIntervalId) {
129
- clearInterval(this._reconnectingIntervalId);
130
- }
131
- if (this._shouldReconnect) {
132
- setTimeout(() => this.connect(), 1000);
133
- }
134
- // this._reconnectingIntervalId = setInterval(() => this.connect(), 1000);
135
- }
136
- heartBeat() {
137
- clearTimeout(this._pingTimeout);
138
- this._pingTimeout = setTimeout(() => {
139
- if (this.isWebsocketReadyState()) {
140
- this.send({ ping: true });
141
- }
142
- }, 5000);
143
- }
144
- }
145
- exports.RunwareServer = RunwareServer;
@@ -1,4 +0,0 @@
1
- import { RunwareClient } from "./Runware-client";
2
- import { RunwareServer } from "./Runware-server";
3
- declare let Runware: typeof RunwareClient | typeof RunwareServer;
4
- export { Runware };
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Runware = void 0;
4
- // @ts-ignore
5
- const Runware_client_1 = require("./Runware-client");
6
- const Runware_server_1 = require("./Runware-server");
7
- let Runware;
8
- if (typeof window === "undefined") {
9
- exports.Runware = Runware = Runware_server_1.RunwareServer;
10
- }
11
- else {
12
- exports.Runware = Runware = Runware_client_1.RunwareClient;
13
- }
@@ -1,5 +0,0 @@
1
- export declare const asyncRetry: (apiCall: Function, options?: {
2
- maxRetries?: number;
3
- delayInSeconds?: number;
4
- callback?: Function;
5
- }) => Promise<any>;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asyncRetry = void 0;
4
- const utils_1 = require("./utils");
5
- const asyncRetry = async (apiCall, options = {}) => {
6
- var _a;
7
- const { delayInSeconds = 1, callback } = options;
8
- let maxRetries = (_a = options.maxRetries) !== null && _a !== void 0 ? _a : 1;
9
- while (maxRetries) {
10
- try {
11
- const result = await apiCall();
12
- return result; // Return the result if successful
13
- }
14
- catch (error) {
15
- callback === null || callback === void 0 ? void 0 : callback();
16
- if (error === null || error === void 0 ? void 0 : error.error) {
17
- throw error;
18
- }
19
- maxRetries--;
20
- if (maxRetries > 0) {
21
- await (0, utils_1.delay)(delayInSeconds); // Delay before the next retry
22
- await (0, exports.asyncRetry)(apiCall, Object.assign(Object.assign({}, options), { maxRetries }));
23
- }
24
- else {
25
- throw error; // Throw the error if max retries are reached
26
- }
27
- }
28
- }
29
- };
30
- exports.asyncRetry = asyncRetry;
@@ -1,4 +0,0 @@
1
- export * from "./Runware-client";
2
- export * from "./types";
3
- export * from "./Runware-server";
4
- export * from "./Runware";
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Runware-client"), exports);
18
- __exportStar(require("./types"), exports);
19
- __exportStar(require("./Runware-server"), exports);
20
- __exportStar(require("./Runware"), exports);
@@ -1,11 +0,0 @@
1
- type Options = {
2
- constructor?: new (url: string, protocols?: string | string[]) => WebSocket;
3
- maxReconnectionDelay?: number;
4
- minReconnectionDelay?: number;
5
- reconnectionDelayGrowFactor?: number;
6
- connectionTimeout?: number;
7
- maxRetries?: number;
8
- debug?: boolean;
9
- };
10
- declare const ReconnectingWebsocket: (url: string, protocols?: string | string[], options?: Options) => void;
11
- export = ReconnectingWebsocket;
@@ -1,175 +0,0 @@
1
- "use strict";
2
- const isWebSocket = (constructor) => constructor && constructor.CLOSING === 2;
3
- const isGlobalWebSocket = () => typeof WebSocket !== "undefined" && isWebSocket(WebSocket);
4
- const getDefaultOptions = () => ({
5
- constructor: isGlobalWebSocket() ? WebSocket : null,
6
- maxReconnectionDelay: 10000,
7
- minReconnectionDelay: 1500,
8
- reconnectionDelayGrowFactor: 1.3,
9
- connectionTimeout: 4000,
10
- maxRetries: Infinity,
11
- debug: false,
12
- });
13
- const bypassProperty = (src, dst, name) => {
14
- Object.defineProperty(dst, name, {
15
- get: () => src[name],
16
- set: (value) => {
17
- src[name] = value;
18
- },
19
- enumerable: true,
20
- configurable: true,
21
- });
22
- };
23
- const initReconnectionDelay = (config) => config.minReconnectionDelay + Math.random() * config.minReconnectionDelay;
24
- const updateReconnectionDelay = (config, previousDelay) => {
25
- const newDelay = previousDelay * config.reconnectionDelayGrowFactor;
26
- return newDelay > config.maxReconnectionDelay
27
- ? config.maxReconnectionDelay
28
- : newDelay;
29
- };
30
- const LEVEL_0_EVENTS = ["onopen", "onclose", "onmessage", "onerror"];
31
- const reassignEventListeners = (ws, oldWs, listeners) => {
32
- Object.keys(listeners).forEach((type) => {
33
- listeners[type].forEach(([listener, options]) => {
34
- ws.addEventListener(type, listener, options);
35
- });
36
- });
37
- if (oldWs) {
38
- LEVEL_0_EVENTS.forEach((name) => {
39
- ws[name] = oldWs[name];
40
- });
41
- }
42
- };
43
- const ReconnectingWebsocket = function (url, protocols, options = {}) {
44
- let ws;
45
- let connectingTimeout;
46
- let reconnectDelay = 0;
47
- let retriesCount = 0;
48
- let shouldRetry = true;
49
- const listeners = {};
50
- // require new to construct
51
- if (!(this instanceof ReconnectingWebsocket)) {
52
- throw new TypeError("Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator");
53
- }
54
- // Set config. Not using `Object.assign` because of IE11
55
- const config = getDefaultOptions();
56
- Object.keys(config)
57
- .filter((key) => options.hasOwnProperty(key))
58
- .forEach((key) => (config[key] = options[key]));
59
- if (!isWebSocket(config.constructor)) {
60
- throw new TypeError("Invalid WebSocket constructor. Set `options.constructor`");
61
- }
62
- const log = config.debug
63
- ? (...params) => console.log("RWS:", ...params)
64
- : () => { };
65
- /**
66
- * Not using dispatchEvent, otherwise we must use a DOM Event object
67
- * Deferred because we want to handle the close event before this
68
- */
69
- const emitError = (code, msg) => setTimeout(() => {
70
- const err = new Error(msg);
71
- err.code = code;
72
- if (Array.isArray(listeners.error)) {
73
- listeners.error.forEach(([fn]) => fn(err));
74
- }
75
- if (ws.onerror) {
76
- ws.onerror(err);
77
- }
78
- }, 0);
79
- const handleClose = () => {
80
- log("close");
81
- retriesCount++;
82
- log("retries count:", retriesCount);
83
- if (retriesCount > config.maxRetries) {
84
- emitError("EHOSTDOWN", "Too many failed connection attempts");
85
- return;
86
- }
87
- if (!reconnectDelay) {
88
- reconnectDelay = initReconnectionDelay(config);
89
- }
90
- else {
91
- reconnectDelay = updateReconnectionDelay(config, reconnectDelay);
92
- }
93
- log("reconnectDelay:", reconnectDelay);
94
- if (shouldRetry) {
95
- setTimeout(connect, reconnectDelay);
96
- }
97
- };
98
- const connect = () => {
99
- log("connect");
100
- const oldWs = ws;
101
- ws = new config.constructor(url, protocols);
102
- connectingTimeout = setTimeout(() => {
103
- log("timeout");
104
- ws.close();
105
- emitError("ETIMEDOUT", "Connection timeout");
106
- }, config.connectionTimeout);
107
- log("bypass properties");
108
- for (let key in ws) {
109
- // @todo move to constant
110
- if (["addEventListener", "removeEventListener", "close", "send"].indexOf(key) < 0) {
111
- bypassProperty(ws, this, key);
112
- }
113
- }
114
- ws.addEventListener("open", () => {
115
- clearTimeout(connectingTimeout);
116
- log("open");
117
- reconnectDelay = initReconnectionDelay(config);
118
- log("reconnectDelay:", reconnectDelay);
119
- retriesCount = 0;
120
- });
121
- ws.addEventListener("close", handleClose);
122
- reassignEventListeners(ws, oldWs, listeners);
123
- };
124
- log("init");
125
- connect();
126
- this.close = (code = 1000, reason = "", { keepClosed = false, fastClose = true, delay = 0 } = {}) => {
127
- if (delay) {
128
- reconnectDelay = delay;
129
- }
130
- shouldRetry = !keepClosed;
131
- ws.close(code, reason);
132
- if (fastClose) {
133
- const fakeCloseEvent = {
134
- code,
135
- reason,
136
- wasClean: true,
137
- };
138
- // execute close listeners soon with a fake closeEvent
139
- // and remove all close listeners from the WS instance
140
- // so they don't get fired on the real close.
141
- handleClose();
142
- if (Array.isArray(listeners.close)) {
143
- listeners.close.forEach(([listener, options]) => {
144
- listener(fakeCloseEvent);
145
- ws.removeEventListener("close", listener, options);
146
- });
147
- }
148
- if (ws.onclose) {
149
- ws.onclose(fakeCloseEvent);
150
- ws.onclose = null;
151
- }
152
- }
153
- };
154
- this.send = (data) => {
155
- ws.send(data);
156
- };
157
- this.addEventListener = (type, listener, options) => {
158
- if (Array.isArray(listeners[type])) {
159
- if (!listeners[type].some(([l]) => l === listener)) {
160
- listeners[type].push([listener, options]);
161
- }
162
- }
163
- else {
164
- listeners[type] = [[listener, options]];
165
- }
166
- ws.addEventListener(type, listener, options);
167
- };
168
- this.removeEventListener = (type, listener, options) => {
169
- if (Array.isArray(listeners[type])) {
170
- listeners[type] = listeners[type].filter(([l]) => l !== listener);
171
- }
172
- ws.removeEventListener(type, listener, options);
173
- };
174
- };
175
- module.exports = ReconnectingWebsocket;