@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.
- package/dist/esm/Runware/Runware-base.d.ts +40 -0
- package/dist/esm/Runware/Runware-base.js +651 -0
- package/dist/esm/Runware/Runware-client.d.ts +5 -0
- package/dist/esm/Runware/Runware-client.js +18 -0
- package/dist/esm/Runware/Runware-server.d.ts +14 -0
- package/dist/esm/Runware/Runware-server.js +155 -0
- package/dist/esm/Runware/Runware.d.ts +4 -0
- package/dist/esm/Runware/Runware.js +13 -0
- package/dist/esm/Runware/async-retry.d.ts +5 -0
- package/dist/esm/Runware/async-retry.js +27 -0
- package/dist/esm/Runware/index.d.ts +4 -0
- package/dist/esm/Runware/index.js +20 -0
- package/dist/esm/Runware/reconnect.d.ts +11 -0
- package/dist/esm/Runware/reconnect.js +175 -0
- package/dist/esm/Runware/types.d.ts +244 -0
- package/dist/esm/Runware/types.js +84 -0
- package/dist/esm/Runware/utils.d.ts +45 -0
- package/dist/esm/Runware/utils.js +212 -0
- package/dist/esm/tests/Runware/enhance-prompt.test.d.ts +1 -0
- package/dist/esm/tests/Runware/enhance-prompt.test.js +58 -0
- package/dist/esm/tests/Runware/remove-image-background.test.d.ts +1 -0
- package/dist/esm/tests/Runware/remove-image-background.test.js +37 -0
- package/dist/esm/tests/Runware/request-image-to-text.test.d.ts +1 -0
- package/dist/esm/tests/Runware/request-image-to-text.test.js +37 -0
- package/dist/esm/tests/Runware/request-images.test.d.ts +1 -0
- package/dist/esm/tests/Runware/request-images.test.js +72 -0
- package/dist/esm/tests/Runware/runware-server.test.d.ts +1 -0
- package/dist/esm/tests/Runware/runware-server.test.js +26 -0
- package/dist/esm/tests/Runware/upload-image.test.d.ts +1 -0
- package/dist/esm/tests/Runware/upload-image.test.js +52 -0
- package/dist/esm/tests/Runware/upscale-gan.test.d.ts +1 -0
- package/dist/esm/tests/Runware/upscale-gan.test.js +41 -0
- package/dist/esm/tests/mockServer.d.ts +12 -0
- package/dist/esm/tests/mockServer.js +38 -0
- package/dist/esm/tests/test-utils.d.ts +39 -0
- package/dist/esm/tests/test-utils.js +44 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -32
- package/dist/index.mjs +12 -32
- package/package.json +1 -1
- package/readme.md +14 -2
|
@@ -0,0 +1,14 @@
|
|
|
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({ apiKey, url }: RunwareBaseType);
|
|
10
|
+
protected connect(): Promise<void>;
|
|
11
|
+
protected send: (msg: Object) => void;
|
|
12
|
+
protected handleClose(): void;
|
|
13
|
+
protected heartBeat(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
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({ apiKey, url }) {
|
|
15
|
+
super({ apiKey, url });
|
|
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._sdkType = types_1.SdkType.SERVER;
|
|
23
|
+
if (apiKey) {
|
|
24
|
+
this.connect();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// protected addListener({
|
|
28
|
+
// lis,
|
|
29
|
+
// check,
|
|
30
|
+
// groupKey,
|
|
31
|
+
// }: {
|
|
32
|
+
// lis: (v: any) => any;
|
|
33
|
+
// check: (v: any) => any;
|
|
34
|
+
// groupKey?: string;
|
|
35
|
+
// }) {
|
|
36
|
+
// const listener = (msg: any) => {
|
|
37
|
+
// if (msg?.error) {
|
|
38
|
+
// lis(msg);
|
|
39
|
+
// } else if (check(msg)) {
|
|
40
|
+
// lis(msg);
|
|
41
|
+
// }
|
|
42
|
+
// };
|
|
43
|
+
// const groupListener = { key: getUUID(), listener, groupKey };
|
|
44
|
+
// this._listeners.push(groupListener);
|
|
45
|
+
// const destroy = () => {
|
|
46
|
+
// this._listeners = removeListener(this._listeners, groupListener);
|
|
47
|
+
// };
|
|
48
|
+
// return {
|
|
49
|
+
// destroy,
|
|
50
|
+
// };
|
|
51
|
+
// }
|
|
52
|
+
async connect() {
|
|
53
|
+
if (!this._url)
|
|
54
|
+
return;
|
|
55
|
+
this._ws = new ws_1.default(this._url, {
|
|
56
|
+
perMessageDeflate: false,
|
|
57
|
+
});
|
|
58
|
+
// delay(1);
|
|
59
|
+
this._ws.on("error", () => { });
|
|
60
|
+
this._ws.on("close", () => {
|
|
61
|
+
this.handleClose();
|
|
62
|
+
});
|
|
63
|
+
this._ws.on("open", () => {
|
|
64
|
+
if (this._reconnectingIntervalId) {
|
|
65
|
+
clearInterval(this._reconnectingIntervalId);
|
|
66
|
+
}
|
|
67
|
+
if (this._connectionSessionUUID && this.isWebsocketReadyState()) {
|
|
68
|
+
this.send({
|
|
69
|
+
taskType: types_1.ETaskType.AUTHENTICATION,
|
|
70
|
+
apiKey: this._apiKey,
|
|
71
|
+
connectionSessionUUID: this._connectionSessionUUID,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
if (this.isWebsocketReadyState()) {
|
|
76
|
+
this.send({
|
|
77
|
+
apiKey: this._apiKey,
|
|
78
|
+
taskType: types_1.ETaskType.AUTHENTICATION,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
this.addListener({
|
|
83
|
+
taskUUID: types_1.ETaskType.AUTHENTICATION,
|
|
84
|
+
lis: (m) => {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
if (m === null || m === void 0 ? void 0 : m.error) {
|
|
87
|
+
this._invalidAPIkey = "Invalid API key";
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this._connectionSessionUUID =
|
|
91
|
+
(_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;
|
|
92
|
+
this._invalidAPIkey = undefined;
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
// this.addListener({
|
|
96
|
+
// check: (m) => m?.newConnectionSessionUUID?.connectionSessionUUID,
|
|
97
|
+
// lis: (m) => {
|
|
98
|
+
// if (m?.error) {
|
|
99
|
+
// if (m.errorId === 19) {
|
|
100
|
+
// this._invalidAPIkey = "Invalid API key";
|
|
101
|
+
// } else {
|
|
102
|
+
// this._invalidAPIkey = "Error connection ";
|
|
103
|
+
// }
|
|
104
|
+
// return;
|
|
105
|
+
// }
|
|
106
|
+
// this._connectionSessionUUID =
|
|
107
|
+
// m?.newConnectionSessionUUID?.connectionSessionUUID;
|
|
108
|
+
// this._invalidAPIkey = undefined;
|
|
109
|
+
// this.heartBeat();
|
|
110
|
+
// },
|
|
111
|
+
// });
|
|
112
|
+
// this._pongListener?.destroy();
|
|
113
|
+
// this._pongListener = this.addListener({
|
|
114
|
+
// check: (m) => m?.pong,
|
|
115
|
+
// lis: (m) => {
|
|
116
|
+
// // console.log({ m });
|
|
117
|
+
// if (m.pong) {
|
|
118
|
+
// this.heartBeat();
|
|
119
|
+
// }
|
|
120
|
+
// },
|
|
121
|
+
// });
|
|
122
|
+
});
|
|
123
|
+
this._ws.on("message", (e, isBinary) => {
|
|
124
|
+
const data = isBinary ? e : e === null || e === void 0 ? void 0 : e.toString();
|
|
125
|
+
if (!data)
|
|
126
|
+
return;
|
|
127
|
+
const m = JSON.parse(data);
|
|
128
|
+
this._listeners.forEach((lis) => {
|
|
129
|
+
const result = lis.listener(m);
|
|
130
|
+
if (result) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
handleClose() {
|
|
137
|
+
if (this._invalidAPIkey) {
|
|
138
|
+
console.error(this._invalidAPIkey);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (this._reconnectingIntervalId) {
|
|
142
|
+
clearInterval(this._reconnectingIntervalId);
|
|
143
|
+
}
|
|
144
|
+
// this._reconnectingIntervalId = setInterval(() => this.connect(), 1000);
|
|
145
|
+
}
|
|
146
|
+
heartBeat() {
|
|
147
|
+
clearTimeout(this._pingTimeout);
|
|
148
|
+
this._pingTimeout = setTimeout(() => {
|
|
149
|
+
if (this.isWebsocketReadyState()) {
|
|
150
|
+
this.send({ ping: true });
|
|
151
|
+
}
|
|
152
|
+
}, 5000);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.RunwareServer = RunwareServer;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
maxRetries--;
|
|
17
|
+
if (maxRetries > 0) {
|
|
18
|
+
await (0, utils_1.delay)(delayInSeconds); // Delay before the next retry
|
|
19
|
+
await (0, exports.asyncRetry)(apiCall, Object.assign(Object.assign({}, options), { maxRetries }));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
throw error; // Throw the error if max retries are reached
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.asyncRetry = asyncRetry;
|
|
@@ -0,0 +1,20 @@
|
|
|
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);
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,175 @@
|
|
|
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;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
export declare enum Environment {
|
|
2
|
+
PRODUCTION = "PRODUCTION",
|
|
3
|
+
DEVELOPMENT = "DEVELOPMENT",
|
|
4
|
+
TEST = "TEST"
|
|
5
|
+
}
|
|
6
|
+
export declare enum SdkType {
|
|
7
|
+
CLIENT = "CLIENT",
|
|
8
|
+
SERVER = "SERVER"
|
|
9
|
+
}
|
|
10
|
+
export declare enum ETaskType {
|
|
11
|
+
IMAGE_INFERENCE = "imageInference",
|
|
12
|
+
IMAGE_UPLOAD = "imageUpload",
|
|
13
|
+
IMAGE_UPSCALE = "imageUpscale",
|
|
14
|
+
IMAGE_BACKGROUND_REMOVAL = "imageBackgroundRemoval",
|
|
15
|
+
IMAGE_CAPTION = "imageCaption",
|
|
16
|
+
IMAGE_CONTROL_NET_PRE_PROCESS = "imageControlNetPreProcess",
|
|
17
|
+
PROMPT_ENHANCE = "promptEnhance",
|
|
18
|
+
AUTHENTICATION = "authentication"
|
|
19
|
+
}
|
|
20
|
+
export type RunwareBaseType = {
|
|
21
|
+
apiKey: string;
|
|
22
|
+
url?: string;
|
|
23
|
+
};
|
|
24
|
+
export type IOutputType = "base64Data" | "dataURI" | "URL";
|
|
25
|
+
export type IOutputFormat = "JPG" | "PNG" | "WEBP";
|
|
26
|
+
export interface IImage {
|
|
27
|
+
taskType: ETaskType;
|
|
28
|
+
imageUUID: string;
|
|
29
|
+
inputImageUUID?: string;
|
|
30
|
+
taskUUID: string;
|
|
31
|
+
imageURL?: string;
|
|
32
|
+
imageBase64Data?: string;
|
|
33
|
+
imageDataURI?: string;
|
|
34
|
+
NSFWContent?: boolean;
|
|
35
|
+
cost?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface ITextToImage extends IImage {
|
|
38
|
+
positivePrompt?: string;
|
|
39
|
+
negativePrompt?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface IControlNetImage {
|
|
42
|
+
taskUUID: string;
|
|
43
|
+
inputImageUUID: string;
|
|
44
|
+
guideImageUUID: string;
|
|
45
|
+
guideImageURL?: string;
|
|
46
|
+
guideImageBase64Data?: string;
|
|
47
|
+
guideImageDataURI?: string;
|
|
48
|
+
cost?: number;
|
|
49
|
+
}
|
|
50
|
+
interface ILora {
|
|
51
|
+
model: string | number;
|
|
52
|
+
weight: number;
|
|
53
|
+
}
|
|
54
|
+
export declare enum EControlMode {
|
|
55
|
+
BALANCED = "balanced",
|
|
56
|
+
PROMPT = "prompt",
|
|
57
|
+
CONTROL_NET = "controlnet"
|
|
58
|
+
}
|
|
59
|
+
export type IControlNetGeneral = {
|
|
60
|
+
model: string;
|
|
61
|
+
guideImage: string | File;
|
|
62
|
+
weight?: number;
|
|
63
|
+
startStep?: number;
|
|
64
|
+
startStepPercentage?: number;
|
|
65
|
+
endStep?: number;
|
|
66
|
+
endStepPercentage?: number;
|
|
67
|
+
controlMode: EControlMode;
|
|
68
|
+
};
|
|
69
|
+
export type IControlNetPreprocess = {
|
|
70
|
+
inputImage: string | File;
|
|
71
|
+
preProcessor: EPreProcessor;
|
|
72
|
+
height?: number;
|
|
73
|
+
width?: number;
|
|
74
|
+
outputType?: IOutputType;
|
|
75
|
+
outputFormat?: IOutputFormat;
|
|
76
|
+
highThresholdCanny?: number;
|
|
77
|
+
lowThresholdCanny?: number;
|
|
78
|
+
includeHandsAndFaceOpenPose?: boolean;
|
|
79
|
+
includeCost?: boolean;
|
|
80
|
+
customTaskUUID?: string;
|
|
81
|
+
};
|
|
82
|
+
export type IControlNet = IControlNetGeneral;
|
|
83
|
+
export type IControlNetWithUUID = Omit<IControlNet, "guideImage"> & {
|
|
84
|
+
guideImage?: string;
|
|
85
|
+
};
|
|
86
|
+
export interface IError {
|
|
87
|
+
error: boolean;
|
|
88
|
+
errorMessage: string;
|
|
89
|
+
taskUUID: string;
|
|
90
|
+
}
|
|
91
|
+
export interface IRequestImage {
|
|
92
|
+
outputType?: IOutputType;
|
|
93
|
+
outputFormat?: IOutputFormat;
|
|
94
|
+
uploadEndpoint?: string;
|
|
95
|
+
checkNsfw?: boolean;
|
|
96
|
+
positivePrompt: string;
|
|
97
|
+
negativePrompt?: string;
|
|
98
|
+
seedImage?: File | string;
|
|
99
|
+
maskImage?: File | string;
|
|
100
|
+
strength?: number;
|
|
101
|
+
height?: number;
|
|
102
|
+
width?: number;
|
|
103
|
+
model: number | string;
|
|
104
|
+
steps?: number;
|
|
105
|
+
scheduler?: string;
|
|
106
|
+
seed?: number;
|
|
107
|
+
CFGScale?: number;
|
|
108
|
+
clipSkip?: number;
|
|
109
|
+
usePromptWeighting?: boolean;
|
|
110
|
+
numberResults?: number;
|
|
111
|
+
controlNet?: IControlNet[];
|
|
112
|
+
lora?: ILora[];
|
|
113
|
+
includeCost?: boolean;
|
|
114
|
+
customTaskUUID?: string;
|
|
115
|
+
onPartialImages?: (images: IImage[], error?: IError) => void;
|
|
116
|
+
retry?: number;
|
|
117
|
+
}
|
|
118
|
+
export interface IRequestImageToText {
|
|
119
|
+
inputImage?: File | string;
|
|
120
|
+
includeCost?: boolean;
|
|
121
|
+
customTaskUUID?: string;
|
|
122
|
+
}
|
|
123
|
+
export interface IImageToText {
|
|
124
|
+
taskType: ETaskType;
|
|
125
|
+
taskUUID: string;
|
|
126
|
+
text: string;
|
|
127
|
+
cost?: number;
|
|
128
|
+
}
|
|
129
|
+
export interface IRemoveImageBackground extends IRequestImageToText {
|
|
130
|
+
outputType?: IOutputType;
|
|
131
|
+
outputFormat?: IOutputFormat;
|
|
132
|
+
rgba?: number[];
|
|
133
|
+
postProcessMask?: boolean;
|
|
134
|
+
returnOnlyMask?: boolean;
|
|
135
|
+
alphaMatting?: boolean;
|
|
136
|
+
alphaMattingForegroundThreshold?: number;
|
|
137
|
+
alphaMattingBackgroundThreshold?: number;
|
|
138
|
+
alphaMattingErodeSize?: number;
|
|
139
|
+
includeCost?: boolean;
|
|
140
|
+
}
|
|
141
|
+
export interface IRemoveImage {
|
|
142
|
+
taskType: ETaskType;
|
|
143
|
+
taskUUID: string;
|
|
144
|
+
imageUUID: string;
|
|
145
|
+
inputImageUUID: string;
|
|
146
|
+
imageURL?: string;
|
|
147
|
+
imageBase64Data?: string;
|
|
148
|
+
imageDataURI?: string;
|
|
149
|
+
cost?: number;
|
|
150
|
+
}
|
|
151
|
+
export interface IPromptEnhancer {
|
|
152
|
+
promptMaxLength?: number;
|
|
153
|
+
promptVersions?: number;
|
|
154
|
+
prompt: string;
|
|
155
|
+
includeCost?: boolean;
|
|
156
|
+
customTaskUUID?: string;
|
|
157
|
+
}
|
|
158
|
+
export interface IEnhancedPrompt extends IImageToText {
|
|
159
|
+
}
|
|
160
|
+
export interface IUpscaleGan {
|
|
161
|
+
inputImage: File | string;
|
|
162
|
+
upscaleFactor: number;
|
|
163
|
+
outputType?: IOutputType;
|
|
164
|
+
outputFormat?: IOutputFormat;
|
|
165
|
+
includeCost?: boolean;
|
|
166
|
+
customTaskUUID?: string;
|
|
167
|
+
}
|
|
168
|
+
export type ReconnectingWebsocketProps = {
|
|
169
|
+
addEventListener: (type: string, listener: EventListener, options: any) => void;
|
|
170
|
+
send: (data: any) => void;
|
|
171
|
+
} & WebSocket;
|
|
172
|
+
export type UploadImageType = {
|
|
173
|
+
imageURL: string;
|
|
174
|
+
imageUUID: string;
|
|
175
|
+
taskUUID: string;
|
|
176
|
+
taskType: ETaskType;
|
|
177
|
+
};
|
|
178
|
+
export type GetWithPromiseCallBackType = ({ resolve, reject, intervalId, }: {
|
|
179
|
+
resolve: <T>(value: T) => void;
|
|
180
|
+
reject: <T>(value: T) => void;
|
|
181
|
+
intervalId: any;
|
|
182
|
+
}) => boolean | undefined;
|
|
183
|
+
export declare enum EPreProcessorGroup {
|
|
184
|
+
"canny" = "canny",
|
|
185
|
+
"depth" = "depth",
|
|
186
|
+
"mlsd" = "mlsd",
|
|
187
|
+
"normalbae" = "normalbae",
|
|
188
|
+
"openpose" = "openpose",
|
|
189
|
+
"tile" = "tile",
|
|
190
|
+
"seg" = "seg",
|
|
191
|
+
"lineart" = "lineart",
|
|
192
|
+
"lineart_anime" = "lineart_anime",
|
|
193
|
+
"shuffle" = "shuffle",
|
|
194
|
+
"scribble" = "scribble",
|
|
195
|
+
"softedge" = "softedge"
|
|
196
|
+
}
|
|
197
|
+
export declare enum EPreProcessor {
|
|
198
|
+
"canny" = "canny",
|
|
199
|
+
"depth_leres" = "depth_leres",
|
|
200
|
+
"depth_midas" = "depth_midas",
|
|
201
|
+
"depth_zoe" = "depth_zoe",
|
|
202
|
+
"inpaint_global_harmonious" = "inpaint_global_harmonious",
|
|
203
|
+
"lineart_anime" = "lineart_anime",
|
|
204
|
+
"lineart_coarse" = "lineart_coarse",
|
|
205
|
+
"lineart_realistic" = "lineart_realistic",
|
|
206
|
+
"lineart_standard" = "lineart_standard",
|
|
207
|
+
"mlsd" = "mlsd",
|
|
208
|
+
"normal_bae" = "normal_bae",
|
|
209
|
+
"scribble_hed" = "scribble_hed",
|
|
210
|
+
"scribble_pidinet" = "scribble_pidinet",
|
|
211
|
+
"seg_ofade20k" = "seg_ofade20k",
|
|
212
|
+
"seg_ofcoco" = "seg_ofcoco",
|
|
213
|
+
"seg_ufade20k" = "seg_ufade20k",
|
|
214
|
+
"shuffle" = "shuffle",
|
|
215
|
+
"softedge_hed" = "softedge_hed",
|
|
216
|
+
"softedge_hedsafe" = "softedge_hedsafe",
|
|
217
|
+
"softedge_pidinet" = "softedge_pidinet",
|
|
218
|
+
"softedge_pidisafe" = "softedge_pidisafe",
|
|
219
|
+
"tile_gaussian" = "tile_gaussian",
|
|
220
|
+
"openpose" = "openpose",
|
|
221
|
+
"openpose_face" = "openpose_face",
|
|
222
|
+
"openpose_faceonly" = "openpose_faceonly",
|
|
223
|
+
"openpose_full" = "openpose_full",
|
|
224
|
+
"openpose_hand" = "openpose_hand"
|
|
225
|
+
}
|
|
226
|
+
export declare enum EOpenPosePreProcessor {
|
|
227
|
+
"openpose" = "openpose",
|
|
228
|
+
"openpose_face" = "openpose_face",
|
|
229
|
+
"openpose_faceonly" = "openpose_faceonly",
|
|
230
|
+
"openpose_full" = "openpose_full",
|
|
231
|
+
"openpose_hand" = "openpose_hand"
|
|
232
|
+
}
|
|
233
|
+
export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
|
234
|
+
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
|
|
235
|
+
}[Keys];
|
|
236
|
+
export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
|
237
|
+
[K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>;
|
|
238
|
+
}[Keys];
|
|
239
|
+
export type ListenerType = {
|
|
240
|
+
key: string;
|
|
241
|
+
listener: (msg: any) => void;
|
|
242
|
+
groupKey?: string;
|
|
243
|
+
};
|
|
244
|
+
export {};
|