@runware/sdk-js 1.1.20-beta.2 → 1.1.20-beta.4
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/index.cjs +2 -1510
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +76 -28
- package/dist/index.d.ts +76 -28
- package/dist/index.js +2 -1487
- package/dist/index.js.map +1 -0
- package/package.json +6 -5
- package/dist/Runware-base-EVIFLT6I.mjs +0 -8
- package/dist/Runware-client-RIKDIM4I.mjs +0 -6
- package/dist/chunk-GKWTIXRV.mjs +0 -1064
- package/dist/chunk-IZ7MFCL7.mjs +0 -1249
- package/dist/esm/Runware/Runware-base.d.ts +0 -40
- package/dist/esm/Runware/Runware-base.js +0 -651
- package/dist/esm/Runware/Runware-client.d.ts +0 -5
- package/dist/esm/Runware/Runware-client.js +0 -18
- package/dist/esm/Runware/Runware-server.d.ts +0 -14
- package/dist/esm/Runware/Runware-server.js +0 -155
- package/dist/esm/Runware/Runware.d.ts +0 -4
- package/dist/esm/Runware/Runware.js +0 -13
- package/dist/esm/Runware/async-retry.d.ts +0 -5
- package/dist/esm/Runware/async-retry.js +0 -27
- package/dist/esm/Runware/index.d.ts +0 -4
- package/dist/esm/Runware/index.js +0 -20
- package/dist/esm/Runware/reconnect.d.ts +0 -11
- package/dist/esm/Runware/reconnect.js +0 -175
- package/dist/esm/Runware/types.d.ts +0 -244
- package/dist/esm/Runware/types.js +0 -84
- package/dist/esm/Runware/utils.d.ts +0 -45
- package/dist/esm/Runware/utils.js +0 -212
- package/dist/esm/tests/Runware/enhance-prompt.test.d.ts +0 -1
- package/dist/esm/tests/Runware/enhance-prompt.test.js +0 -58
- package/dist/esm/tests/Runware/remove-image-background.test.d.ts +0 -1
- package/dist/esm/tests/Runware/remove-image-background.test.js +0 -37
- package/dist/esm/tests/Runware/request-image-to-text.test.d.ts +0 -1
- package/dist/esm/tests/Runware/request-image-to-text.test.js +0 -37
- package/dist/esm/tests/Runware/request-images.test.d.ts +0 -1
- package/dist/esm/tests/Runware/request-images.test.js +0 -72
- package/dist/esm/tests/Runware/runware-server.test.d.ts +0 -1
- package/dist/esm/tests/Runware/runware-server.test.js +0 -26
- package/dist/esm/tests/Runware/upload-image.test.d.ts +0 -1
- package/dist/esm/tests/Runware/upload-image.test.js +0 -52
- package/dist/esm/tests/Runware/upscale-gan.test.d.ts +0 -1
- package/dist/esm/tests/Runware/upscale-gan.test.js +0 -41
- package/dist/esm/tests/mockServer.d.ts +0 -12
- package/dist/esm/tests/mockServer.js +0 -38
- package/dist/esm/tests/test-utils.d.ts +0 -39
- package/dist/esm/tests/test-utils.js +0 -44
- package/dist/index.d.mts +0 -338
- package/dist/index.mjs +0 -1464
package/dist/index.cjs
CHANGED
|
@@ -1,1510 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
38
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
39
|
-
};
|
|
40
|
-
var __export = (target, all) => {
|
|
41
|
-
for (var name in all)
|
|
42
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
43
|
-
};
|
|
44
|
-
var __copyProps = (to, from, except, desc) => {
|
|
45
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
46
|
-
for (let key of __getOwnPropNames(from))
|
|
47
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
48
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
49
|
-
}
|
|
50
|
-
return to;
|
|
51
|
-
};
|
|
52
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
53
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
54
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
55
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
56
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
57
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
58
|
-
mod
|
|
59
|
-
));
|
|
60
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
61
|
-
|
|
62
|
-
// Runware/reconnect.ts
|
|
63
|
-
var require_reconnect = __commonJS({
|
|
64
|
-
"Runware/reconnect.ts"(exports, module) {
|
|
65
|
-
"use strict";
|
|
66
|
-
var isWebSocket = (constructor) => constructor && constructor.CLOSING === 2;
|
|
67
|
-
var isGlobalWebSocket = () => typeof WebSocket !== "undefined" && isWebSocket(WebSocket);
|
|
68
|
-
var getDefaultOptions = () => ({
|
|
69
|
-
constructor: isGlobalWebSocket() ? WebSocket : null,
|
|
70
|
-
maxReconnectionDelay: 1e4,
|
|
71
|
-
minReconnectionDelay: 1500,
|
|
72
|
-
reconnectionDelayGrowFactor: 1.3,
|
|
73
|
-
connectionTimeout: 4e3,
|
|
74
|
-
maxRetries: Infinity,
|
|
75
|
-
debug: false
|
|
76
|
-
});
|
|
77
|
-
var bypassProperty = (src, dst, name) => {
|
|
78
|
-
Object.defineProperty(dst, name, {
|
|
79
|
-
get: () => src[name],
|
|
80
|
-
set: (value) => {
|
|
81
|
-
src[name] = value;
|
|
82
|
-
},
|
|
83
|
-
enumerable: true,
|
|
84
|
-
configurable: true
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
var initReconnectionDelay = (config) => config.minReconnectionDelay + Math.random() * config.minReconnectionDelay;
|
|
88
|
-
var updateReconnectionDelay = (config, previousDelay) => {
|
|
89
|
-
const newDelay = previousDelay * config.reconnectionDelayGrowFactor;
|
|
90
|
-
return newDelay > config.maxReconnectionDelay ? config.maxReconnectionDelay : newDelay;
|
|
91
|
-
};
|
|
92
|
-
var LEVEL_0_EVENTS = ["onopen", "onclose", "onmessage", "onerror"];
|
|
93
|
-
var reassignEventListeners = (ws, oldWs, listeners) => {
|
|
94
|
-
Object.keys(listeners).forEach((type) => {
|
|
95
|
-
listeners[type].forEach(([listener, options]) => {
|
|
96
|
-
ws.addEventListener(type, listener, options);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
if (oldWs) {
|
|
100
|
-
LEVEL_0_EVENTS.forEach((name) => {
|
|
101
|
-
ws[name] = oldWs[name];
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
var ReconnectingWebsocket2 = function(url, protocols, options = {}) {
|
|
106
|
-
let ws;
|
|
107
|
-
let connectingTimeout;
|
|
108
|
-
let reconnectDelay = 0;
|
|
109
|
-
let retriesCount = 0;
|
|
110
|
-
let shouldRetry = true;
|
|
111
|
-
const listeners = {};
|
|
112
|
-
if (!(this instanceof ReconnectingWebsocket2)) {
|
|
113
|
-
throw new TypeError(
|
|
114
|
-
"Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator"
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
const config = getDefaultOptions();
|
|
118
|
-
Object.keys(config).filter((key) => options.hasOwnProperty(key)).forEach((key) => config[key] = options[key]);
|
|
119
|
-
if (!isWebSocket(config.constructor)) {
|
|
120
|
-
throw new TypeError(
|
|
121
|
-
"Invalid WebSocket constructor. Set `options.constructor`"
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
const log = config.debug ? (...params) => console.log("RWS:", ...params) : () => {
|
|
125
|
-
};
|
|
126
|
-
const emitError = (code, msg) => setTimeout(() => {
|
|
127
|
-
const err = new Error(msg);
|
|
128
|
-
err.code = code;
|
|
129
|
-
if (Array.isArray(listeners.error)) {
|
|
130
|
-
listeners.error.forEach(([fn]) => fn(err));
|
|
131
|
-
}
|
|
132
|
-
if (ws.onerror) {
|
|
133
|
-
ws.onerror(err);
|
|
134
|
-
}
|
|
135
|
-
}, 0);
|
|
136
|
-
const handleClose = () => {
|
|
137
|
-
log("close");
|
|
138
|
-
retriesCount++;
|
|
139
|
-
log("retries count:", retriesCount);
|
|
140
|
-
if (retriesCount > config.maxRetries) {
|
|
141
|
-
emitError("EHOSTDOWN", "Too many failed connection attempts");
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (!reconnectDelay) {
|
|
145
|
-
reconnectDelay = initReconnectionDelay(config);
|
|
146
|
-
} else {
|
|
147
|
-
reconnectDelay = updateReconnectionDelay(config, reconnectDelay);
|
|
148
|
-
}
|
|
149
|
-
log("reconnectDelay:", reconnectDelay);
|
|
150
|
-
if (shouldRetry) {
|
|
151
|
-
setTimeout(connect, reconnectDelay);
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
const connect = () => {
|
|
155
|
-
log("connect");
|
|
156
|
-
const oldWs = ws;
|
|
157
|
-
ws = new config.constructor(url, protocols);
|
|
158
|
-
connectingTimeout = setTimeout(() => {
|
|
159
|
-
log("timeout");
|
|
160
|
-
ws.close();
|
|
161
|
-
emitError("ETIMEDOUT", "Connection timeout");
|
|
162
|
-
}, config.connectionTimeout);
|
|
163
|
-
log("bypass properties");
|
|
164
|
-
for (let key in ws) {
|
|
165
|
-
if (["addEventListener", "removeEventListener", "close", "send"].indexOf(
|
|
166
|
-
key
|
|
167
|
-
) < 0) {
|
|
168
|
-
bypassProperty(ws, this, key);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
ws.addEventListener("open", () => {
|
|
172
|
-
clearTimeout(connectingTimeout);
|
|
173
|
-
log("open");
|
|
174
|
-
reconnectDelay = initReconnectionDelay(config);
|
|
175
|
-
log("reconnectDelay:", reconnectDelay);
|
|
176
|
-
retriesCount = 0;
|
|
177
|
-
});
|
|
178
|
-
ws.addEventListener("close", handleClose);
|
|
179
|
-
reassignEventListeners(ws, oldWs, listeners);
|
|
180
|
-
};
|
|
181
|
-
log("init");
|
|
182
|
-
connect();
|
|
183
|
-
this.close = (code = 1e3, reason = "", { keepClosed = false, fastClose = true, delay: delay3 = 0 } = {}) => {
|
|
184
|
-
if (delay3) {
|
|
185
|
-
reconnectDelay = delay3;
|
|
186
|
-
}
|
|
187
|
-
shouldRetry = !keepClosed;
|
|
188
|
-
ws.close(code, reason);
|
|
189
|
-
if (fastClose) {
|
|
190
|
-
const fakeCloseEvent = {
|
|
191
|
-
code,
|
|
192
|
-
reason,
|
|
193
|
-
wasClean: true
|
|
194
|
-
};
|
|
195
|
-
handleClose();
|
|
196
|
-
if (Array.isArray(listeners.close)) {
|
|
197
|
-
listeners.close.forEach(([listener, options2]) => {
|
|
198
|
-
listener(fakeCloseEvent);
|
|
199
|
-
ws.removeEventListener("close", listener, options2);
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
if (ws.onclose) {
|
|
203
|
-
ws.onclose(fakeCloseEvent);
|
|
204
|
-
ws.onclose = null;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
this.send = (data) => {
|
|
209
|
-
ws.send(data);
|
|
210
|
-
};
|
|
211
|
-
this.addEventListener = (type, listener, options2) => {
|
|
212
|
-
if (Array.isArray(listeners[type])) {
|
|
213
|
-
if (!listeners[type].some(([l]) => l === listener)) {
|
|
214
|
-
listeners[type].push([listener, options2]);
|
|
215
|
-
}
|
|
216
|
-
} else {
|
|
217
|
-
listeners[type] = [[listener, options2]];
|
|
218
|
-
}
|
|
219
|
-
ws.addEventListener(type, listener, options2);
|
|
220
|
-
};
|
|
221
|
-
this.removeEventListener = (type, listener, options2) => {
|
|
222
|
-
if (Array.isArray(listeners[type])) {
|
|
223
|
-
listeners[type] = listeners[type].filter(([l]) => l !== listener);
|
|
224
|
-
}
|
|
225
|
-
ws.removeEventListener(type, listener, options2);
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
|
-
module.exports = ReconnectingWebsocket2;
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
// Runware/index.ts
|
|
233
|
-
var Runware_exports = {};
|
|
234
|
-
__export(Runware_exports, {
|
|
235
|
-
EControlMode: () => EControlMode,
|
|
236
|
-
EOpenPosePreProcessor: () => EOpenPosePreProcessor,
|
|
237
|
-
EPreProcessor: () => EPreProcessor,
|
|
238
|
-
EPreProcessorGroup: () => EPreProcessorGroup,
|
|
239
|
-
ETaskType: () => ETaskType,
|
|
240
|
-
Environment: () => Environment,
|
|
241
|
-
Runware: () => Runware,
|
|
242
|
-
RunwareClient: () => RunwareClient,
|
|
243
|
-
RunwareServer: () => RunwareServer,
|
|
244
|
-
SdkType: () => SdkType
|
|
245
|
-
});
|
|
246
|
-
module.exports = __toCommonJS(Runware_exports);
|
|
247
|
-
|
|
248
|
-
// Runware/types.ts
|
|
249
|
-
var Environment = /* @__PURE__ */ ((Environment2) => {
|
|
250
|
-
Environment2["PRODUCTION"] = "PRODUCTION";
|
|
251
|
-
Environment2["DEVELOPMENT"] = "DEVELOPMENT";
|
|
252
|
-
Environment2["TEST"] = "TEST";
|
|
253
|
-
return Environment2;
|
|
254
|
-
})(Environment || {});
|
|
255
|
-
var SdkType = /* @__PURE__ */ ((SdkType2) => {
|
|
256
|
-
SdkType2["CLIENT"] = "CLIENT";
|
|
257
|
-
SdkType2["SERVER"] = "SERVER";
|
|
258
|
-
return SdkType2;
|
|
259
|
-
})(SdkType || {});
|
|
260
|
-
var ETaskType = /* @__PURE__ */ ((ETaskType2) => {
|
|
261
|
-
ETaskType2["IMAGE_INFERENCE"] = "imageInference";
|
|
262
|
-
ETaskType2["IMAGE_UPLOAD"] = "imageUpload";
|
|
263
|
-
ETaskType2["IMAGE_UPSCALE"] = "imageUpscale";
|
|
264
|
-
ETaskType2["IMAGE_BACKGROUND_REMOVAL"] = "imageBackgroundRemoval";
|
|
265
|
-
ETaskType2["IMAGE_CAPTION"] = "imageCaption";
|
|
266
|
-
ETaskType2["IMAGE_CONTROL_NET_PRE_PROCESS"] = "imageControlNetPreProcess";
|
|
267
|
-
ETaskType2["PROMPT_ENHANCE"] = "promptEnhance";
|
|
268
|
-
ETaskType2["AUTHENTICATION"] = "authentication";
|
|
269
|
-
ETaskType2["MODEL_UPLOAD"] = "modelUpload";
|
|
270
|
-
return ETaskType2;
|
|
271
|
-
})(ETaskType || {});
|
|
272
|
-
var EControlMode = /* @__PURE__ */ ((EControlMode2) => {
|
|
273
|
-
EControlMode2["BALANCED"] = "balanced";
|
|
274
|
-
EControlMode2["PROMPT"] = "prompt";
|
|
275
|
-
EControlMode2["CONTROL_NET"] = "controlnet";
|
|
276
|
-
return EControlMode2;
|
|
277
|
-
})(EControlMode || {});
|
|
278
|
-
var EPreProcessorGroup = /* @__PURE__ */ ((EPreProcessorGroup2) => {
|
|
279
|
-
EPreProcessorGroup2["canny"] = "canny";
|
|
280
|
-
EPreProcessorGroup2["depth"] = "depth";
|
|
281
|
-
EPreProcessorGroup2["mlsd"] = "mlsd";
|
|
282
|
-
EPreProcessorGroup2["normalbae"] = "normalbae";
|
|
283
|
-
EPreProcessorGroup2["openpose"] = "openpose";
|
|
284
|
-
EPreProcessorGroup2["tile"] = "tile";
|
|
285
|
-
EPreProcessorGroup2["seg"] = "seg";
|
|
286
|
-
EPreProcessorGroup2["lineart"] = "lineart";
|
|
287
|
-
EPreProcessorGroup2["lineart_anime"] = "lineart_anime";
|
|
288
|
-
EPreProcessorGroup2["shuffle"] = "shuffle";
|
|
289
|
-
EPreProcessorGroup2["scribble"] = "scribble";
|
|
290
|
-
EPreProcessorGroup2["softedge"] = "softedge";
|
|
291
|
-
return EPreProcessorGroup2;
|
|
292
|
-
})(EPreProcessorGroup || {});
|
|
293
|
-
var EPreProcessor = /* @__PURE__ */ ((EPreProcessor2) => {
|
|
294
|
-
EPreProcessor2["canny"] = "canny";
|
|
295
|
-
EPreProcessor2["depth_leres"] = "depth_leres";
|
|
296
|
-
EPreProcessor2["depth_midas"] = "depth_midas";
|
|
297
|
-
EPreProcessor2["depth_zoe"] = "depth_zoe";
|
|
298
|
-
EPreProcessor2["inpaint_global_harmonious"] = "inpaint_global_harmonious";
|
|
299
|
-
EPreProcessor2["lineart_anime"] = "lineart_anime";
|
|
300
|
-
EPreProcessor2["lineart_coarse"] = "lineart_coarse";
|
|
301
|
-
EPreProcessor2["lineart_realistic"] = "lineart_realistic";
|
|
302
|
-
EPreProcessor2["lineart_standard"] = "lineart_standard";
|
|
303
|
-
EPreProcessor2["mlsd"] = "mlsd";
|
|
304
|
-
EPreProcessor2["normal_bae"] = "normal_bae";
|
|
305
|
-
EPreProcessor2["scribble_hed"] = "scribble_hed";
|
|
306
|
-
EPreProcessor2["scribble_pidinet"] = "scribble_pidinet";
|
|
307
|
-
EPreProcessor2["seg_ofade20k"] = "seg_ofade20k";
|
|
308
|
-
EPreProcessor2["seg_ofcoco"] = "seg_ofcoco";
|
|
309
|
-
EPreProcessor2["seg_ufade20k"] = "seg_ufade20k";
|
|
310
|
-
EPreProcessor2["shuffle"] = "shuffle";
|
|
311
|
-
EPreProcessor2["softedge_hed"] = "softedge_hed";
|
|
312
|
-
EPreProcessor2["softedge_hedsafe"] = "softedge_hedsafe";
|
|
313
|
-
EPreProcessor2["softedge_pidinet"] = "softedge_pidinet";
|
|
314
|
-
EPreProcessor2["softedge_pidisafe"] = "softedge_pidisafe";
|
|
315
|
-
EPreProcessor2["tile_gaussian"] = "tile_gaussian";
|
|
316
|
-
EPreProcessor2["openpose"] = "openpose";
|
|
317
|
-
EPreProcessor2["openpose_face"] = "openpose_face";
|
|
318
|
-
EPreProcessor2["openpose_faceonly"] = "openpose_faceonly";
|
|
319
|
-
EPreProcessor2["openpose_full"] = "openpose_full";
|
|
320
|
-
EPreProcessor2["openpose_hand"] = "openpose_hand";
|
|
321
|
-
return EPreProcessor2;
|
|
322
|
-
})(EPreProcessor || {});
|
|
323
|
-
var EOpenPosePreProcessor = /* @__PURE__ */ ((EOpenPosePreProcessor2) => {
|
|
324
|
-
EOpenPosePreProcessor2["openpose"] = "openpose";
|
|
325
|
-
EOpenPosePreProcessor2["openpose_face"] = "openpose_face";
|
|
326
|
-
EOpenPosePreProcessor2["openpose_faceonly"] = "openpose_faceonly";
|
|
327
|
-
EOpenPosePreProcessor2["openpose_full"] = "openpose_full";
|
|
328
|
-
EOpenPosePreProcessor2["openpose_hand"] = "openpose_hand";
|
|
329
|
-
return EOpenPosePreProcessor2;
|
|
330
|
-
})(EOpenPosePreProcessor || {});
|
|
331
|
-
|
|
332
|
-
// Runware/utils.ts
|
|
333
|
-
var import_uuid = require("uuid");
|
|
334
|
-
var TIMEOUT_DURATION = 6e4;
|
|
335
|
-
var MINIMUM_TIMEOUT_DURATION = 1e3;
|
|
336
|
-
var POLLING_INTERVAL = 100;
|
|
337
|
-
var BASE_RUNWARE_URLS = {
|
|
338
|
-
["PRODUCTION" /* PRODUCTION */]: "wss://ws-api.runware.ai/v1",
|
|
339
|
-
["TEST" /* TEST */]: "ws://localhost:8080"
|
|
340
|
-
};
|
|
341
|
-
var removeFromAray = (col, targetElem) => {
|
|
342
|
-
if (col == null) {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
let i = col.indexOf(targetElem);
|
|
346
|
-
if (i === -1) {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
col.splice(i, 1);
|
|
350
|
-
};
|
|
351
|
-
var getIntervalWithPromise = (callback, {
|
|
352
|
-
debugKey = "debugKey",
|
|
353
|
-
timeoutDuration = TIMEOUT_DURATION,
|
|
354
|
-
shouldThrowError = true
|
|
355
|
-
}) => {
|
|
356
|
-
timeoutDuration = timeoutDuration < MINIMUM_TIMEOUT_DURATION ? MINIMUM_TIMEOUT_DURATION : timeoutDuration;
|
|
357
|
-
return new Promise((resolve, reject) => {
|
|
358
|
-
const timeoutId = setTimeout(() => {
|
|
359
|
-
if (intervalId) {
|
|
360
|
-
clearInterval(intervalId);
|
|
361
|
-
if (shouldThrowError) {
|
|
362
|
-
reject(`Response could not be received from server for ${debugKey}`);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
clearTimeout(timeoutId);
|
|
366
|
-
}, timeoutDuration);
|
|
367
|
-
let intervalId = setInterval(async () => {
|
|
368
|
-
const shouldClear = callback({ resolve, reject, intervalId });
|
|
369
|
-
if (shouldClear) {
|
|
370
|
-
clearInterval(intervalId);
|
|
371
|
-
clearTimeout(timeoutId);
|
|
372
|
-
}
|
|
373
|
-
}, POLLING_INTERVAL);
|
|
374
|
-
});
|
|
375
|
-
};
|
|
376
|
-
var fileToBase64 = (file) => new Promise((resolve) => {
|
|
377
|
-
const reader = new FileReader();
|
|
378
|
-
reader.readAsDataURL(file);
|
|
379
|
-
reader.onload = function() {
|
|
380
|
-
resolve(reader.result);
|
|
381
|
-
};
|
|
382
|
-
});
|
|
383
|
-
var getUUID = () => (0, import_uuid.v4)();
|
|
384
|
-
var isValidUUID = (uuid) => (0, import_uuid.validate)(uuid);
|
|
385
|
-
var accessDeepObject = ({
|
|
386
|
-
key,
|
|
387
|
-
data,
|
|
388
|
-
useZero = true,
|
|
389
|
-
shouldReturnString = false
|
|
390
|
-
}) => {
|
|
391
|
-
const splittedKeys = key.split(/\.|\[/).map((key2) => key2.replace(/\]$/, ""));
|
|
392
|
-
const value = splittedKeys.reduce((acc, curr) => {
|
|
393
|
-
var _a, _b;
|
|
394
|
-
const returnZero = useZero ? 0 : void 0;
|
|
395
|
-
const currentValue = acc == null ? void 0 : acc[curr];
|
|
396
|
-
if (!currentValue) {
|
|
397
|
-
return returnZero;
|
|
398
|
-
}
|
|
399
|
-
if (Array.isArray(currentValue) && /^\d+$/.test(curr)) {
|
|
400
|
-
const index = parseInt(curr, 10);
|
|
401
|
-
if (index >= 0 && index < currentValue.length) {
|
|
402
|
-
return acc[curr] = currentValue[index];
|
|
403
|
-
} else {
|
|
404
|
-
return (_a = acc[curr]) != null ? _a : returnZero;
|
|
405
|
-
}
|
|
406
|
-
} else {
|
|
407
|
-
return (_b = acc[curr]) != null ? _b : returnZero;
|
|
408
|
-
}
|
|
409
|
-
}, data || {});
|
|
410
|
-
return value != null ? value : {};
|
|
411
|
-
};
|
|
412
|
-
var delay = (time, milliseconds = 1e3) => {
|
|
413
|
-
return new Promise((resolve) => setTimeout(resolve, time * milliseconds));
|
|
414
|
-
};
|
|
415
|
-
var removeListener = (listeners, listener) => {
|
|
416
|
-
return listeners.filter((lis) => lis.key !== listener.key);
|
|
417
|
-
};
|
|
418
|
-
var evaluateNonTrue = ({
|
|
419
|
-
key,
|
|
420
|
-
value
|
|
421
|
-
}) => {
|
|
422
|
-
if (!!value || value === 0 || value === false) {
|
|
423
|
-
return { [key]: value };
|
|
424
|
-
} else {
|
|
425
|
-
return {};
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
// Runware/async-retry.ts
|
|
430
|
-
var asyncRetry = async (apiCall, options = {}) => {
|
|
431
|
-
var _a;
|
|
432
|
-
const { delayInSeconds = 1, callback } = options;
|
|
433
|
-
let maxRetries = (_a = options.maxRetries) != null ? _a : 1;
|
|
434
|
-
while (maxRetries) {
|
|
435
|
-
try {
|
|
436
|
-
const result = await apiCall();
|
|
437
|
-
return result;
|
|
438
|
-
} catch (error) {
|
|
439
|
-
callback == null ? void 0 : callback();
|
|
440
|
-
maxRetries--;
|
|
441
|
-
if (maxRetries > 0) {
|
|
442
|
-
await delay(delayInSeconds);
|
|
443
|
-
await asyncRetry(apiCall, __spreadProps(__spreadValues({}, options), { maxRetries }));
|
|
444
|
-
} else {
|
|
445
|
-
throw error;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
// Runware/Runware-base.ts
|
|
452
|
-
var RunwareBase = class {
|
|
453
|
-
constructor({
|
|
454
|
-
apiKey,
|
|
455
|
-
url = BASE_RUNWARE_URLS.PRODUCTION,
|
|
456
|
-
shouldReconnect = true,
|
|
457
|
-
globalMaxRetries = 2,
|
|
458
|
-
timeoutDuration = TIMEOUT_DURATION
|
|
459
|
-
}) {
|
|
460
|
-
this._listeners = [];
|
|
461
|
-
// _globalMessages: any[] = [];
|
|
462
|
-
this._globalMessages = {};
|
|
463
|
-
this._globalImages = [];
|
|
464
|
-
this.isWebsocketReadyState = () => {
|
|
465
|
-
var _a;
|
|
466
|
-
return ((_a = this._ws) == null ? void 0 : _a.readyState) === 1;
|
|
467
|
-
};
|
|
468
|
-
// We moving to an array format, it make sense to consolidate all request to an array here
|
|
469
|
-
this.send = (msg) => {
|
|
470
|
-
this._ws.send(JSON.stringify([msg]));
|
|
471
|
-
};
|
|
472
|
-
this.uploadImage = async (file) => {
|
|
473
|
-
try {
|
|
474
|
-
return await asyncRetry(async () => {
|
|
475
|
-
const taskUUID = getUUID();
|
|
476
|
-
if (typeof file === "string" && isValidUUID(file)) {
|
|
477
|
-
return {
|
|
478
|
-
imageURL: file,
|
|
479
|
-
imageUUID: file,
|
|
480
|
-
taskUUID,
|
|
481
|
-
taskType: "imageUpload" /* IMAGE_UPLOAD */
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
const imageBase64 = typeof file === "string" ? file : await fileToBase64(file);
|
|
485
|
-
return {
|
|
486
|
-
imageURL: imageBase64,
|
|
487
|
-
imageUUID: imageBase64,
|
|
488
|
-
taskUUID,
|
|
489
|
-
taskType: "imageUpload" /* IMAGE_UPLOAD */
|
|
490
|
-
};
|
|
491
|
-
});
|
|
492
|
-
} catch (e) {
|
|
493
|
-
throw e;
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
this.controlNetPreProcess = async ({
|
|
497
|
-
inputImage,
|
|
498
|
-
preProcessorType,
|
|
499
|
-
height,
|
|
500
|
-
width,
|
|
501
|
-
outputType,
|
|
502
|
-
outputFormat,
|
|
503
|
-
highThresholdCanny,
|
|
504
|
-
lowThresholdCanny,
|
|
505
|
-
includeHandsAndFaceOpenPose,
|
|
506
|
-
includeCost,
|
|
507
|
-
customTaskUUID,
|
|
508
|
-
retry
|
|
509
|
-
}) => {
|
|
510
|
-
const totalRetry = retry || this._globalMaxRetries;
|
|
511
|
-
let lis = void 0;
|
|
512
|
-
try {
|
|
513
|
-
return await asyncRetry(
|
|
514
|
-
async () => {
|
|
515
|
-
await this.ensureConnection();
|
|
516
|
-
const image = await this.uploadImage(inputImage);
|
|
517
|
-
if (!(image == null ? void 0 : image.imageUUID))
|
|
518
|
-
return null;
|
|
519
|
-
const taskUUID = customTaskUUID || getUUID();
|
|
520
|
-
this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
521
|
-
inputImage: image.imageUUID,
|
|
522
|
-
taskType: "imageControlNetPreProcess" /* IMAGE_CONTROL_NET_PRE_PROCESS */,
|
|
523
|
-
taskUUID,
|
|
524
|
-
preProcessorType
|
|
525
|
-
}, evaluateNonTrue({ key: "height", value: height })), evaluateNonTrue({ key: "width", value: width })), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
|
|
526
|
-
key: "highThresholdCanny",
|
|
527
|
-
value: highThresholdCanny
|
|
528
|
-
})), evaluateNonTrue({
|
|
529
|
-
key: "lowThresholdCanny",
|
|
530
|
-
value: lowThresholdCanny
|
|
531
|
-
})), evaluateNonTrue({
|
|
532
|
-
key: "includeHandsAndFaceOpenPose",
|
|
533
|
-
value: includeHandsAndFaceOpenPose
|
|
534
|
-
})));
|
|
535
|
-
lis = this.globalListener({
|
|
536
|
-
taskUUID
|
|
537
|
-
});
|
|
538
|
-
const guideImage = await getIntervalWithPromise(
|
|
539
|
-
({ resolve, reject }) => {
|
|
540
|
-
const uploadedImage = this.getSingleMessage({
|
|
541
|
-
taskUUID
|
|
542
|
-
});
|
|
543
|
-
if (!uploadedImage)
|
|
544
|
-
return;
|
|
545
|
-
if (uploadedImage == null ? void 0 : uploadedImage.error) {
|
|
546
|
-
reject(uploadedImage);
|
|
547
|
-
return true;
|
|
548
|
-
}
|
|
549
|
-
if (uploadedImage) {
|
|
550
|
-
resolve(uploadedImage);
|
|
551
|
-
return true;
|
|
552
|
-
}
|
|
553
|
-
},
|
|
554
|
-
{
|
|
555
|
-
debugKey: "unprocessed-image",
|
|
556
|
-
timeoutDuration: this._timeoutDuration
|
|
557
|
-
}
|
|
558
|
-
);
|
|
559
|
-
lis.destroy();
|
|
560
|
-
return guideImage;
|
|
561
|
-
},
|
|
562
|
-
{
|
|
563
|
-
maxRetries: totalRetry,
|
|
564
|
-
callback: () => {
|
|
565
|
-
lis == null ? void 0 : lis.destroy();
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
);
|
|
569
|
-
} catch (e) {
|
|
570
|
-
throw e;
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
this.requestImageToText = async ({
|
|
574
|
-
inputImage,
|
|
575
|
-
includeCost,
|
|
576
|
-
customTaskUUID,
|
|
577
|
-
retry
|
|
578
|
-
}) => {
|
|
579
|
-
const totalRetry = retry || this._globalMaxRetries;
|
|
580
|
-
let lis = void 0;
|
|
581
|
-
try {
|
|
582
|
-
return await asyncRetry(
|
|
583
|
-
async () => {
|
|
584
|
-
await this.ensureConnection();
|
|
585
|
-
const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
|
|
586
|
-
const taskUUID = customTaskUUID || getUUID();
|
|
587
|
-
this.send(__spreadValues({
|
|
588
|
-
taskUUID,
|
|
589
|
-
taskType: "imageCaption" /* IMAGE_CAPTION */,
|
|
590
|
-
inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
|
|
591
|
-
}, evaluateNonTrue({ key: "includeCost", value: includeCost })));
|
|
592
|
-
lis = this.globalListener({
|
|
593
|
-
taskUUID
|
|
594
|
-
});
|
|
595
|
-
const response = await getIntervalWithPromise(
|
|
596
|
-
({ resolve, reject }) => {
|
|
597
|
-
const newReverseClip = this.getSingleMessage({
|
|
598
|
-
taskUUID
|
|
599
|
-
});
|
|
600
|
-
if (!newReverseClip)
|
|
601
|
-
return;
|
|
602
|
-
if (newReverseClip == null ? void 0 : newReverseClip.error) {
|
|
603
|
-
reject(newReverseClip);
|
|
604
|
-
return true;
|
|
605
|
-
}
|
|
606
|
-
if (newReverseClip) {
|
|
607
|
-
delete this._globalMessages[taskUUID];
|
|
608
|
-
resolve(newReverseClip);
|
|
609
|
-
return true;
|
|
610
|
-
}
|
|
611
|
-
},
|
|
612
|
-
{
|
|
613
|
-
debugKey: "remove-image-background",
|
|
614
|
-
timeoutDuration: this._timeoutDuration
|
|
615
|
-
}
|
|
616
|
-
);
|
|
617
|
-
lis.destroy();
|
|
618
|
-
return response;
|
|
619
|
-
},
|
|
620
|
-
{
|
|
621
|
-
maxRetries: totalRetry,
|
|
622
|
-
callback: () => {
|
|
623
|
-
lis == null ? void 0 : lis.destroy();
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
);
|
|
627
|
-
} catch (e) {
|
|
628
|
-
throw e;
|
|
629
|
-
}
|
|
630
|
-
};
|
|
631
|
-
this.removeImageBackground = async ({
|
|
632
|
-
inputImage,
|
|
633
|
-
outputType,
|
|
634
|
-
outputFormat,
|
|
635
|
-
rgba,
|
|
636
|
-
postProcessMask,
|
|
637
|
-
returnOnlyMask,
|
|
638
|
-
alphaMatting,
|
|
639
|
-
alphaMattingForegroundThreshold,
|
|
640
|
-
alphaMattingBackgroundThreshold,
|
|
641
|
-
alphaMattingErodeSize,
|
|
642
|
-
includeCost,
|
|
643
|
-
customTaskUUID,
|
|
644
|
-
retry
|
|
645
|
-
}) => {
|
|
646
|
-
const totalRetry = retry || this._globalMaxRetries;
|
|
647
|
-
let lis = void 0;
|
|
648
|
-
try {
|
|
649
|
-
return await asyncRetry(
|
|
650
|
-
async () => {
|
|
651
|
-
await this.ensureConnection();
|
|
652
|
-
const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
|
|
653
|
-
const taskUUID = customTaskUUID || getUUID();
|
|
654
|
-
this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
655
|
-
taskType: "imageBackgroundRemoval" /* IMAGE_BACKGROUND_REMOVAL */,
|
|
656
|
-
taskUUID,
|
|
657
|
-
inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
|
|
658
|
-
}, evaluateNonTrue({ key: "rgba", value: rgba })), evaluateNonTrue({
|
|
659
|
-
key: "postProcessMask",
|
|
660
|
-
value: postProcessMask
|
|
661
|
-
})), evaluateNonTrue({
|
|
662
|
-
key: "returnOnlyMask",
|
|
663
|
-
value: returnOnlyMask
|
|
664
|
-
})), evaluateNonTrue({ key: "alphaMatting", value: alphaMatting })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
|
|
665
|
-
key: "alphaMattingForegroundThreshold",
|
|
666
|
-
value: alphaMattingForegroundThreshold
|
|
667
|
-
})), evaluateNonTrue({
|
|
668
|
-
key: "alphaMattingBackgroundThreshold",
|
|
669
|
-
value: alphaMattingBackgroundThreshold
|
|
670
|
-
})), evaluateNonTrue({
|
|
671
|
-
key: "alphaMattingErodeSize",
|
|
672
|
-
value: alphaMattingErodeSize
|
|
673
|
-
})), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })));
|
|
674
|
-
lis = this.globalListener({
|
|
675
|
-
taskUUID
|
|
676
|
-
});
|
|
677
|
-
const response = await getIntervalWithPromise(
|
|
678
|
-
({ resolve, reject }) => {
|
|
679
|
-
const newRemoveBackground = this.getSingleMessage({ taskUUID });
|
|
680
|
-
if (!newRemoveBackground)
|
|
681
|
-
return;
|
|
682
|
-
if (newRemoveBackground == null ? void 0 : newRemoveBackground.error) {
|
|
683
|
-
reject(newRemoveBackground);
|
|
684
|
-
return true;
|
|
685
|
-
}
|
|
686
|
-
if (newRemoveBackground) {
|
|
687
|
-
delete this._globalMessages[taskUUID];
|
|
688
|
-
resolve(newRemoveBackground);
|
|
689
|
-
return true;
|
|
690
|
-
}
|
|
691
|
-
},
|
|
692
|
-
{
|
|
693
|
-
debugKey: "remove-image-background",
|
|
694
|
-
timeoutDuration: this._timeoutDuration
|
|
695
|
-
}
|
|
696
|
-
);
|
|
697
|
-
lis.destroy();
|
|
698
|
-
return response;
|
|
699
|
-
},
|
|
700
|
-
{
|
|
701
|
-
maxRetries: totalRetry,
|
|
702
|
-
callback: () => {
|
|
703
|
-
lis == null ? void 0 : lis.destroy();
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
);
|
|
707
|
-
} catch (e) {
|
|
708
|
-
throw e;
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
this.upscaleGan = async ({
|
|
712
|
-
inputImage,
|
|
713
|
-
upscaleFactor,
|
|
714
|
-
outputType,
|
|
715
|
-
outputFormat,
|
|
716
|
-
includeCost,
|
|
717
|
-
customTaskUUID,
|
|
718
|
-
retry
|
|
719
|
-
}) => {
|
|
720
|
-
const totalRetry = retry || this._globalMaxRetries;
|
|
721
|
-
let lis = void 0;
|
|
722
|
-
try {
|
|
723
|
-
return await asyncRetry(
|
|
724
|
-
async () => {
|
|
725
|
-
await this.ensureConnection();
|
|
726
|
-
let imageUploaded;
|
|
727
|
-
imageUploaded = await this.uploadImage(inputImage);
|
|
728
|
-
const taskUUID = customTaskUUID || getUUID();
|
|
729
|
-
this.send(__spreadValues(__spreadValues(__spreadValues({
|
|
730
|
-
taskUUID,
|
|
731
|
-
inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
|
|
732
|
-
taskType: "imageUpscale" /* IMAGE_UPSCALE */,
|
|
733
|
-
upscaleFactor
|
|
734
|
-
}, evaluateNonTrue({ key: "includeCost", value: includeCost })), outputType ? { outputType } : {}), outputFormat ? { outputFormat } : {}));
|
|
735
|
-
lis = this.globalListener({
|
|
736
|
-
taskUUID
|
|
737
|
-
});
|
|
738
|
-
const response = await getIntervalWithPromise(
|
|
739
|
-
({ resolve, reject }) => {
|
|
740
|
-
const newUpscaleGan = this.getSingleMessage({ taskUUID });
|
|
741
|
-
if (!newUpscaleGan)
|
|
742
|
-
return;
|
|
743
|
-
if (newUpscaleGan == null ? void 0 : newUpscaleGan.error) {
|
|
744
|
-
reject(newUpscaleGan);
|
|
745
|
-
return true;
|
|
746
|
-
}
|
|
747
|
-
if (newUpscaleGan) {
|
|
748
|
-
delete this._globalMessages[taskUUID];
|
|
749
|
-
resolve(newUpscaleGan);
|
|
750
|
-
return true;
|
|
751
|
-
}
|
|
752
|
-
},
|
|
753
|
-
{ debugKey: "upscale-gan", timeoutDuration: this._timeoutDuration }
|
|
754
|
-
);
|
|
755
|
-
lis.destroy();
|
|
756
|
-
return response;
|
|
757
|
-
},
|
|
758
|
-
{
|
|
759
|
-
maxRetries: totalRetry,
|
|
760
|
-
callback: () => {
|
|
761
|
-
lis == null ? void 0 : lis.destroy();
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
);
|
|
765
|
-
} catch (e) {
|
|
766
|
-
throw e;
|
|
767
|
-
}
|
|
768
|
-
};
|
|
769
|
-
this.enhancePrompt = async ({
|
|
770
|
-
prompt,
|
|
771
|
-
promptMaxLength = 380,
|
|
772
|
-
promptVersions = 1,
|
|
773
|
-
includeCost,
|
|
774
|
-
customTaskUUID,
|
|
775
|
-
retry
|
|
776
|
-
}) => {
|
|
777
|
-
const totalRetry = retry || this._globalMaxRetries;
|
|
778
|
-
let lis = void 0;
|
|
779
|
-
try {
|
|
780
|
-
return await asyncRetry(
|
|
781
|
-
async () => {
|
|
782
|
-
await this.ensureConnection();
|
|
783
|
-
const taskUUID = customTaskUUID || getUUID();
|
|
784
|
-
this.send(__spreadProps(__spreadValues({
|
|
785
|
-
prompt,
|
|
786
|
-
taskUUID,
|
|
787
|
-
promptMaxLength,
|
|
788
|
-
promptVersions
|
|
789
|
-
}, evaluateNonTrue({ key: "includeCost", value: includeCost })), {
|
|
790
|
-
taskType: "promptEnhance" /* PROMPT_ENHANCE */
|
|
791
|
-
}));
|
|
792
|
-
lis = this.globalListener({
|
|
793
|
-
taskUUID
|
|
794
|
-
});
|
|
795
|
-
const response = await getIntervalWithPromise(
|
|
796
|
-
({ resolve, reject }) => {
|
|
797
|
-
const reducedPrompt = this._globalMessages[taskUUID];
|
|
798
|
-
if (reducedPrompt == null ? void 0 : reducedPrompt.error) {
|
|
799
|
-
reject(reducedPrompt);
|
|
800
|
-
return true;
|
|
801
|
-
}
|
|
802
|
-
if ((reducedPrompt == null ? void 0 : reducedPrompt.length) >= promptVersions) {
|
|
803
|
-
delete this._globalMessages[taskUUID];
|
|
804
|
-
resolve(reducedPrompt);
|
|
805
|
-
return true;
|
|
806
|
-
}
|
|
807
|
-
},
|
|
808
|
-
{
|
|
809
|
-
debugKey: "enhance-prompt",
|
|
810
|
-
timeoutDuration: this._timeoutDuration
|
|
811
|
-
}
|
|
812
|
-
);
|
|
813
|
-
lis.destroy();
|
|
814
|
-
return response;
|
|
815
|
-
},
|
|
816
|
-
{
|
|
817
|
-
maxRetries: totalRetry,
|
|
818
|
-
callback: () => {
|
|
819
|
-
lis == null ? void 0 : lis.destroy();
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
);
|
|
823
|
-
} catch (e) {
|
|
824
|
-
throw e;
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
this.modelUpload = async (payload) => {
|
|
828
|
-
const _a = payload, { onUploadStream, retry, customTaskUUID } = _a, addModelPayload = __objRest(_a, ["onUploadStream", "retry", "customTaskUUID"]);
|
|
829
|
-
const totalRetry = retry || this._globalMaxRetries;
|
|
830
|
-
let lis = void 0;
|
|
831
|
-
try {
|
|
832
|
-
return await asyncRetry(
|
|
833
|
-
async () => {
|
|
834
|
-
await this.ensureConnection();
|
|
835
|
-
const taskUUID = customTaskUUID || getUUID();
|
|
836
|
-
this.send(__spreadProps(__spreadValues({}, addModelPayload), {
|
|
837
|
-
taskUUID,
|
|
838
|
-
taskType: "modelUpload" /* MODEL_UPLOAD */
|
|
839
|
-
}));
|
|
840
|
-
let result;
|
|
841
|
-
let errorResult;
|
|
842
|
-
lis = this.listenToUpload({
|
|
843
|
-
taskUUID,
|
|
844
|
-
onUploadStream: (response, error) => {
|
|
845
|
-
onUploadStream == null ? void 0 : onUploadStream(response, error);
|
|
846
|
-
if ((response == null ? void 0 : response.statusId) === 1) {
|
|
847
|
-
result = response;
|
|
848
|
-
} else if (error) {
|
|
849
|
-
errorResult = error;
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
});
|
|
853
|
-
const modelUploadResponse = await getIntervalWithPromise(
|
|
854
|
-
({ resolve, reject }) => {
|
|
855
|
-
if (result) {
|
|
856
|
-
resolve(result);
|
|
857
|
-
return true;
|
|
858
|
-
} else if (errorResult) {
|
|
859
|
-
reject(errorResult);
|
|
860
|
-
return false;
|
|
861
|
-
}
|
|
862
|
-
},
|
|
863
|
-
{
|
|
864
|
-
shouldThrowError: false,
|
|
865
|
-
timeoutDuration: 60 * 60 * 1e3
|
|
866
|
-
}
|
|
867
|
-
);
|
|
868
|
-
return modelUploadResponse;
|
|
869
|
-
},
|
|
870
|
-
{
|
|
871
|
-
maxRetries: totalRetry,
|
|
872
|
-
callback: () => {
|
|
873
|
-
lis == null ? void 0 : lis.destroy();
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
);
|
|
877
|
-
} catch (e) {
|
|
878
|
-
throw e;
|
|
879
|
-
}
|
|
880
|
-
};
|
|
881
|
-
this.getSingleMessage = ({ taskUUID }) => {
|
|
882
|
-
var _a;
|
|
883
|
-
const value = (_a = this._globalMessages[taskUUID]) == null ? void 0 : _a[0];
|
|
884
|
-
const errorValue = this._globalMessages[taskUUID];
|
|
885
|
-
if (!value && !errorValue)
|
|
886
|
-
return null;
|
|
887
|
-
return (errorValue == null ? void 0 : errorValue.error) ? errorValue : value;
|
|
888
|
-
};
|
|
889
|
-
this.disconnect = async () => {
|
|
890
|
-
var _a, _b, _c, _d;
|
|
891
|
-
(_b = (_a = this._ws) == null ? void 0 : _a.terminate) == null ? void 0 : _b.call(_a);
|
|
892
|
-
(_d = (_c = this._ws) == null ? void 0 : _c.close) == null ? void 0 : _d.call(_c);
|
|
893
|
-
};
|
|
894
|
-
this.connected = () => this.isWebsocketReadyState() && !!this._connectionSessionUUID;
|
|
895
|
-
this._apiKey = apiKey;
|
|
896
|
-
this._url = url;
|
|
897
|
-
this._sdkType = "CLIENT" /* CLIENT */;
|
|
898
|
-
this._shouldReconnect = shouldReconnect;
|
|
899
|
-
this._globalMaxRetries = globalMaxRetries;
|
|
900
|
-
this._timeoutDuration = timeoutDuration;
|
|
901
|
-
}
|
|
902
|
-
static async initialize(props) {
|
|
903
|
-
try {
|
|
904
|
-
const instance = new this(props);
|
|
905
|
-
await instance.ensureConnection();
|
|
906
|
-
return instance;
|
|
907
|
-
} catch (e) {
|
|
908
|
-
throw e;
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
// protected addListener({
|
|
912
|
-
// lis,
|
|
913
|
-
// check,
|
|
914
|
-
// }: {
|
|
915
|
-
// lis: (v: any) => any;
|
|
916
|
-
// check: (v: any) => any;
|
|
917
|
-
// groupKey?: string;
|
|
918
|
-
// }): { destroy: Function } {
|
|
919
|
-
// this._ws.onmessage = (e: any) => {
|
|
920
|
-
// const m = JSON.parse(e.data);
|
|
921
|
-
// if (m?.error) {
|
|
922
|
-
// lis(m);
|
|
923
|
-
// } else if (check(m)) {
|
|
924
|
-
// lis(m);
|
|
925
|
-
// }
|
|
926
|
-
// };
|
|
927
|
-
// return {
|
|
928
|
-
// destroy: () => {},
|
|
929
|
-
// };
|
|
930
|
-
// }
|
|
931
|
-
addListener({
|
|
932
|
-
lis,
|
|
933
|
-
// check,
|
|
934
|
-
groupKey,
|
|
935
|
-
taskUUID
|
|
936
|
-
}) {
|
|
937
|
-
const listener = (msg) => {
|
|
938
|
-
var _a, _b, _c;
|
|
939
|
-
const arrayMessage = Array.isArray(msg == null ? void 0 : msg.data) ? msg.data : [msg.data];
|
|
940
|
-
const arrayErrors = ((_a = msg == null ? void 0 : msg[0]) == null ? void 0 : _a.errors) ? (_b = msg == null ? void 0 : msg[0]) == null ? void 0 : _b.errors : Array.isArray(msg == null ? void 0 : msg.errors) ? msg.errors : [msg.errors];
|
|
941
|
-
const filteredMessage = arrayMessage.filter(
|
|
942
|
-
(v) => ((v == null ? void 0 : v.taskUUID) || (v == null ? void 0 : v.taskType)) === taskUUID
|
|
943
|
-
);
|
|
944
|
-
const filteredErrors = arrayErrors.filter(
|
|
945
|
-
(v) => ((v == null ? void 0 : v.taskUUID) || (v == null ? void 0 : v.taskType)) === taskUUID
|
|
946
|
-
);
|
|
947
|
-
if (filteredErrors.length) {
|
|
948
|
-
lis({ error: __spreadValues({}, (_c = arrayErrors[0]) != null ? _c : {}) });
|
|
949
|
-
return;
|
|
950
|
-
}
|
|
951
|
-
if (filteredMessage.length) {
|
|
952
|
-
lis({ [taskUUID]: arrayMessage });
|
|
953
|
-
return;
|
|
954
|
-
}
|
|
955
|
-
};
|
|
956
|
-
const groupListener = { key: taskUUID || getUUID(), listener, groupKey };
|
|
957
|
-
this._listeners.push(groupListener);
|
|
958
|
-
const destroy = () => {
|
|
959
|
-
this._listeners = removeListener(this._listeners, groupListener);
|
|
960
|
-
};
|
|
961
|
-
return {
|
|
962
|
-
destroy
|
|
963
|
-
};
|
|
964
|
-
}
|
|
965
|
-
connect() {
|
|
966
|
-
this._ws.onopen = (e) => {
|
|
967
|
-
if (this._connectionSessionUUID) {
|
|
968
|
-
this.send({
|
|
969
|
-
taskType: "authentication" /* AUTHENTICATION */,
|
|
970
|
-
apiKey: this._apiKey,
|
|
971
|
-
connectionSessionUUID: this._connectionSessionUUID
|
|
972
|
-
});
|
|
973
|
-
} else {
|
|
974
|
-
this.send({ apiKey: this._apiKey, taskType: "authentication" /* AUTHENTICATION */ });
|
|
975
|
-
}
|
|
976
|
-
this.addListener({
|
|
977
|
-
taskUUID: "authentication" /* AUTHENTICATION */,
|
|
978
|
-
lis: (m) => {
|
|
979
|
-
var _a, _b;
|
|
980
|
-
if (m == null ? void 0 : m.error) {
|
|
981
|
-
this._invalidAPIkey = m;
|
|
982
|
-
return;
|
|
983
|
-
}
|
|
984
|
-
this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
|
|
985
|
-
this._invalidAPIkey = void 0;
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
|
-
};
|
|
989
|
-
this._ws.onmessage = (e) => {
|
|
990
|
-
var _a;
|
|
991
|
-
const data = JSON.parse(e.data);
|
|
992
|
-
for (const lis of this._listeners) {
|
|
993
|
-
const result = (_a = lis == null ? void 0 : lis.listener) == null ? void 0 : _a.call(lis, data);
|
|
994
|
-
if (result)
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
};
|
|
998
|
-
this._ws.onclose = (e) => {
|
|
999
|
-
if (this._invalidAPIkey) {
|
|
1000
|
-
return;
|
|
1001
|
-
}
|
|
1002
|
-
};
|
|
1003
|
-
}
|
|
1004
|
-
destroy(lis) {
|
|
1005
|
-
removeFromAray(this._listeners, lis);
|
|
1006
|
-
}
|
|
1007
|
-
listenToImages({
|
|
1008
|
-
onPartialImages,
|
|
1009
|
-
taskUUID,
|
|
1010
|
-
groupKey,
|
|
1011
|
-
positivePrompt,
|
|
1012
|
-
negativePrompt
|
|
1013
|
-
}) {
|
|
1014
|
-
return this.addListener({
|
|
1015
|
-
taskUUID,
|
|
1016
|
-
lis: (m) => {
|
|
1017
|
-
var _a, _b;
|
|
1018
|
-
let images = (_a = m == null ? void 0 : m[taskUUID]) == null ? void 0 : _a.filter(
|
|
1019
|
-
(img) => img.taskUUID === taskUUID
|
|
1020
|
-
);
|
|
1021
|
-
if (m.error) {
|
|
1022
|
-
onPartialImages == null ? void 0 : onPartialImages(images, (m == null ? void 0 : m.error) && m);
|
|
1023
|
-
this._globalError = m;
|
|
1024
|
-
} else {
|
|
1025
|
-
images = images.map((image) => __spreadProps(__spreadValues({}, image), {
|
|
1026
|
-
positivePrompt,
|
|
1027
|
-
negativePrompt
|
|
1028
|
-
}));
|
|
1029
|
-
onPartialImages == null ? void 0 : onPartialImages(images, (m == null ? void 0 : m.error) && m);
|
|
1030
|
-
if (this._sdkType === "CLIENT" /* CLIENT */) {
|
|
1031
|
-
this._globalImages = [
|
|
1032
|
-
...this._globalImages,
|
|
1033
|
-
...((_b = m == null ? void 0 : m[taskUUID]) != null ? _b : []).map((image) => __spreadProps(__spreadValues({}, image), {
|
|
1034
|
-
positivePrompt,
|
|
1035
|
-
negativePrompt
|
|
1036
|
-
}))
|
|
1037
|
-
];
|
|
1038
|
-
} else {
|
|
1039
|
-
this._globalImages = [...this._globalImages, ...images];
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
},
|
|
1043
|
-
groupKey
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
listenToUpload({
|
|
1047
|
-
onUploadStream,
|
|
1048
|
-
taskUUID
|
|
1049
|
-
}) {
|
|
1050
|
-
return this.addListener({
|
|
1051
|
-
taskUUID,
|
|
1052
|
-
lis: (m) => {
|
|
1053
|
-
var _a;
|
|
1054
|
-
const error = m == null ? void 0 : m.error;
|
|
1055
|
-
const result = (_a = m == null ? void 0 : m[taskUUID]) == null ? void 0 : _a[0];
|
|
1056
|
-
let response = (result == null ? void 0 : result.taskUUID) === taskUUID ? result : null;
|
|
1057
|
-
if (response || error) {
|
|
1058
|
-
onUploadStream == null ? void 0 : onUploadStream(response || void 0, error);
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
});
|
|
1062
|
-
}
|
|
1063
|
-
globalListener({ taskUUID }) {
|
|
1064
|
-
return this.addListener({
|
|
1065
|
-
// check: (m) => {
|
|
1066
|
-
// const value = accessDeepObject({
|
|
1067
|
-
// key: responseKey,
|
|
1068
|
-
// data: m,
|
|
1069
|
-
// useZero: false,
|
|
1070
|
-
// });
|
|
1071
|
-
// return !!value;
|
|
1072
|
-
// },
|
|
1073
|
-
// check: responseKey,
|
|
1074
|
-
taskUUID,
|
|
1075
|
-
lis: (m) => {
|
|
1076
|
-
if (m.error) {
|
|
1077
|
-
this._globalMessages[taskUUID] = m;
|
|
1078
|
-
return;
|
|
1079
|
-
}
|
|
1080
|
-
const value = accessDeepObject({
|
|
1081
|
-
key: taskUUID,
|
|
1082
|
-
data: m,
|
|
1083
|
-
useZero: false
|
|
1084
|
-
});
|
|
1085
|
-
if (Array.isArray(value)) {
|
|
1086
|
-
value.forEach((v) => {
|
|
1087
|
-
var _a;
|
|
1088
|
-
this._globalMessages[v.taskUUID] = [
|
|
1089
|
-
...(_a = this._globalMessages[v.taskUUID]) != null ? _a : [],
|
|
1090
|
-
v
|
|
1091
|
-
];
|
|
1092
|
-
});
|
|
1093
|
-
} else {
|
|
1094
|
-
this._globalMessages[value.taskUUID] = value;
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
async requestImages({
|
|
1100
|
-
outputType,
|
|
1101
|
-
outputFormat,
|
|
1102
|
-
uploadEndpoint,
|
|
1103
|
-
checkNsfw,
|
|
1104
|
-
positivePrompt,
|
|
1105
|
-
negativePrompt,
|
|
1106
|
-
seedImage,
|
|
1107
|
-
maskImage,
|
|
1108
|
-
strength,
|
|
1109
|
-
height,
|
|
1110
|
-
width,
|
|
1111
|
-
model,
|
|
1112
|
-
steps,
|
|
1113
|
-
scheduler,
|
|
1114
|
-
seed,
|
|
1115
|
-
CFGScale,
|
|
1116
|
-
clipSkip,
|
|
1117
|
-
usePromptWeighting,
|
|
1118
|
-
numberResults = 1,
|
|
1119
|
-
controlNet,
|
|
1120
|
-
lora,
|
|
1121
|
-
onPartialImages,
|
|
1122
|
-
includeCost,
|
|
1123
|
-
customTaskUUID,
|
|
1124
|
-
retry
|
|
1125
|
-
}) {
|
|
1126
|
-
let lis = void 0;
|
|
1127
|
-
let requestObject = void 0;
|
|
1128
|
-
let taskUUIDs = [];
|
|
1129
|
-
let retryCount = 0;
|
|
1130
|
-
const totalRetry = retry || this._globalMaxRetries;
|
|
1131
|
-
try {
|
|
1132
|
-
await this.ensureConnection();
|
|
1133
|
-
let seedImageUUID = null;
|
|
1134
|
-
let maskImageUUID = null;
|
|
1135
|
-
let controlNetData = [];
|
|
1136
|
-
if (seedImage) {
|
|
1137
|
-
const uploadedImage = await this.uploadImage(seedImage);
|
|
1138
|
-
if (!uploadedImage)
|
|
1139
|
-
return [];
|
|
1140
|
-
seedImageUUID = uploadedImage.imageUUID;
|
|
1141
|
-
}
|
|
1142
|
-
if (maskImage) {
|
|
1143
|
-
const uploadedMaskInitiator = await this.uploadImage(maskImage);
|
|
1144
|
-
if (!uploadedMaskInitiator)
|
|
1145
|
-
return [];
|
|
1146
|
-
maskImageUUID = uploadedMaskInitiator.imageUUID;
|
|
1147
|
-
}
|
|
1148
|
-
if (controlNet == null ? void 0 : controlNet.length) {
|
|
1149
|
-
for (let i = 0; i < controlNet.length; i++) {
|
|
1150
|
-
const controlData = controlNet[i];
|
|
1151
|
-
const {
|
|
1152
|
-
endStep,
|
|
1153
|
-
startStep,
|
|
1154
|
-
weight,
|
|
1155
|
-
guideImage,
|
|
1156
|
-
controlMode,
|
|
1157
|
-
startStepPercentage,
|
|
1158
|
-
endStepPercentage,
|
|
1159
|
-
model: controlNetModel
|
|
1160
|
-
} = controlData;
|
|
1161
|
-
const imageUploaded = guideImage ? await this.uploadImage(guideImage) : null;
|
|
1162
|
-
controlNetData.push(__spreadProps(__spreadValues(__spreadValues({
|
|
1163
|
-
guideImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
|
|
1164
|
-
model: controlNetModel,
|
|
1165
|
-
endStep,
|
|
1166
|
-
startStep,
|
|
1167
|
-
weight
|
|
1168
|
-
}, evaluateNonTrue({
|
|
1169
|
-
key: "startStepPercentage",
|
|
1170
|
-
value: startStepPercentage
|
|
1171
|
-
})), evaluateNonTrue({
|
|
1172
|
-
key: "endStepPercentage",
|
|
1173
|
-
value: endStepPercentage
|
|
1174
|
-
})), {
|
|
1175
|
-
controlMode: controlMode || "controlnet" /* CONTROL_NET */
|
|
1176
|
-
}));
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
requestObject = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues({
|
|
1180
|
-
taskType: "imageInference" /* IMAGE_INFERENCE */,
|
|
1181
|
-
model,
|
|
1182
|
-
positivePrompt
|
|
1183
|
-
}, negativePrompt ? { negativePrompt } : {}), height ? { height } : {}), width ? { width } : {}), {
|
|
1184
|
-
numberResults
|
|
1185
|
-
}), (lora == null ? void 0 : lora.length) ? { lora } : {}), outputType ? { outputType } : {}), outputFormat ? { outputFormat } : {}), uploadEndpoint ? { uploadEndpoint } : {}), evaluateNonTrue({ key: "checkNsfw", value: checkNsfw })), evaluateNonTrue({ key: "strength", value: strength })), evaluateNonTrue({ key: "CFGScale", value: CFGScale })), evaluateNonTrue({ key: "clipSkip", value: clipSkip })), evaluateNonTrue({
|
|
1186
|
-
key: "usePromptWeighting",
|
|
1187
|
-
value: usePromptWeighting
|
|
1188
|
-
})), evaluateNonTrue({ key: "steps", value: steps })), controlNetData.length ? { controlNet: controlNetData } : {}), seed ? { seed } : {}), scheduler ? { scheduler } : {}), evaluateNonTrue({ key: "includeCost", value: includeCost })), seedImageUUID ? { seedImage: seedImageUUID } : {}), maskImageUUID ? { maskImage: maskImageUUID } : {});
|
|
1189
|
-
return await asyncRetry(
|
|
1190
|
-
async () => {
|
|
1191
|
-
retryCount++;
|
|
1192
|
-
lis == null ? void 0 : lis.destroy();
|
|
1193
|
-
const imagesWithSimilarTask = this._globalImages.filter(
|
|
1194
|
-
(img) => taskUUIDs.includes(img.taskUUID)
|
|
1195
|
-
);
|
|
1196
|
-
const taskUUID = customTaskUUID || getUUID();
|
|
1197
|
-
taskUUIDs.push(taskUUID);
|
|
1198
|
-
const imageRemaining = numberResults - imagesWithSimilarTask.length;
|
|
1199
|
-
const newRequestObject = __spreadProps(__spreadValues({}, requestObject), {
|
|
1200
|
-
taskUUID,
|
|
1201
|
-
numberResults: imageRemaining
|
|
1202
|
-
});
|
|
1203
|
-
this.send(newRequestObject);
|
|
1204
|
-
lis = this.listenToImages({
|
|
1205
|
-
onPartialImages,
|
|
1206
|
-
taskUUID,
|
|
1207
|
-
groupKey: "REQUEST_IMAGES" /* REQUEST_IMAGES */,
|
|
1208
|
-
positivePrompt,
|
|
1209
|
-
negativePrompt
|
|
1210
|
-
});
|
|
1211
|
-
const promise = await this.getSimilarImages({
|
|
1212
|
-
taskUUID: taskUUIDs,
|
|
1213
|
-
numberResults,
|
|
1214
|
-
lis
|
|
1215
|
-
});
|
|
1216
|
-
lis.destroy();
|
|
1217
|
-
return promise;
|
|
1218
|
-
},
|
|
1219
|
-
{
|
|
1220
|
-
maxRetries: totalRetry,
|
|
1221
|
-
callback: () => {
|
|
1222
|
-
lis == null ? void 0 : lis.destroy();
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
);
|
|
1226
|
-
} catch (e) {
|
|
1227
|
-
if (e.taskUUID) {
|
|
1228
|
-
throw e;
|
|
1229
|
-
}
|
|
1230
|
-
if (retryCount >= totalRetry) {
|
|
1231
|
-
return this.handleIncompleteImages({ taskUUIDs, error: e });
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
async ensureConnection() {
|
|
1236
|
-
var _a;
|
|
1237
|
-
let isConnected = this.connected();
|
|
1238
|
-
if (isConnected || this._url === BASE_RUNWARE_URLS.TEST)
|
|
1239
|
-
return;
|
|
1240
|
-
const retryInterval = 2e3;
|
|
1241
|
-
const pollingInterval = 200;
|
|
1242
|
-
try {
|
|
1243
|
-
if (this._invalidAPIkey)
|
|
1244
|
-
throw this._invalidAPIkey;
|
|
1245
|
-
return new Promise((resolve, reject) => {
|
|
1246
|
-
let retry = 0;
|
|
1247
|
-
const MAX_RETRY = 30;
|
|
1248
|
-
const SHOULD_RETRY = 30 / 2 === retry;
|
|
1249
|
-
let retryIntervalId;
|
|
1250
|
-
let pollingIntervalId;
|
|
1251
|
-
const clearAllIntervals = () => {
|
|
1252
|
-
clearInterval(retryIntervalId);
|
|
1253
|
-
clearInterval(pollingIntervalId);
|
|
1254
|
-
};
|
|
1255
|
-
if (this._sdkType === "SERVER" /* SERVER */) {
|
|
1256
|
-
retryIntervalId = setInterval(async () => {
|
|
1257
|
-
try {
|
|
1258
|
-
const hasConnected = this.connected();
|
|
1259
|
-
if (hasConnected) {
|
|
1260
|
-
clearAllIntervals();
|
|
1261
|
-
resolve(true);
|
|
1262
|
-
} else if (retry >= MAX_RETRY) {
|
|
1263
|
-
clearAllIntervals();
|
|
1264
|
-
reject(new Error("Retry timed out"));
|
|
1265
|
-
} else {
|
|
1266
|
-
if (SHOULD_RETRY) {
|
|
1267
|
-
this.connect();
|
|
1268
|
-
}
|
|
1269
|
-
retry++;
|
|
1270
|
-
}
|
|
1271
|
-
} catch (error) {
|
|
1272
|
-
clearAllIntervals();
|
|
1273
|
-
reject(error);
|
|
1274
|
-
}
|
|
1275
|
-
}, retryInterval);
|
|
1276
|
-
}
|
|
1277
|
-
pollingIntervalId = setInterval(async () => {
|
|
1278
|
-
const hasConnected = this.connected();
|
|
1279
|
-
if (hasConnected) {
|
|
1280
|
-
clearAllIntervals();
|
|
1281
|
-
resolve(true);
|
|
1282
|
-
return;
|
|
1283
|
-
}
|
|
1284
|
-
if (!!this._invalidAPIkey) {
|
|
1285
|
-
clearAllIntervals();
|
|
1286
|
-
reject(this._invalidAPIkey);
|
|
1287
|
-
return;
|
|
1288
|
-
}
|
|
1289
|
-
}, pollingInterval);
|
|
1290
|
-
});
|
|
1291
|
-
} catch (e) {
|
|
1292
|
-
throw (_a = this._invalidAPIkey) != null ? _a : "Could not connect to server. Ensure your API key is correct";
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
async getSimilarImages({
|
|
1296
|
-
taskUUID,
|
|
1297
|
-
numberResults,
|
|
1298
|
-
shouldThrowError,
|
|
1299
|
-
lis
|
|
1300
|
-
}) {
|
|
1301
|
-
return await getIntervalWithPromise(
|
|
1302
|
-
({ resolve, reject, intervalId }) => {
|
|
1303
|
-
const taskUUIDs = Array.isArray(taskUUID) ? taskUUID : [taskUUID];
|
|
1304
|
-
const imagesWithSimilarTask = this._globalImages.filter(
|
|
1305
|
-
(img) => taskUUIDs.includes(img.taskUUID)
|
|
1306
|
-
);
|
|
1307
|
-
if (this._globalError) {
|
|
1308
|
-
const newData = this._globalError;
|
|
1309
|
-
this._globalError = void 0;
|
|
1310
|
-
clearInterval(intervalId);
|
|
1311
|
-
reject == null ? void 0 : reject(newData);
|
|
1312
|
-
return true;
|
|
1313
|
-
} else if (imagesWithSimilarTask.length >= numberResults) {
|
|
1314
|
-
clearInterval(intervalId);
|
|
1315
|
-
this._globalImages = this._globalImages.filter(
|
|
1316
|
-
(img) => !taskUUIDs.includes(img.taskUUID)
|
|
1317
|
-
);
|
|
1318
|
-
resolve([...imagesWithSimilarTask].slice(0, numberResults));
|
|
1319
|
-
return true;
|
|
1320
|
-
}
|
|
1321
|
-
},
|
|
1322
|
-
{
|
|
1323
|
-
debugKey: "getting images",
|
|
1324
|
-
shouldThrowError,
|
|
1325
|
-
timeoutDuration: this._timeoutDuration
|
|
1326
|
-
}
|
|
1327
|
-
);
|
|
1328
|
-
}
|
|
1329
|
-
handleIncompleteImages({
|
|
1330
|
-
taskUUIDs,
|
|
1331
|
-
error
|
|
1332
|
-
}) {
|
|
1333
|
-
const imagesWithSimilarTask = this._globalImages.filter(
|
|
1334
|
-
(img) => taskUUIDs.includes(img.taskUUID)
|
|
1335
|
-
);
|
|
1336
|
-
if (imagesWithSimilarTask.length > 1) {
|
|
1337
|
-
this._globalImages = this._globalImages.filter(
|
|
1338
|
-
(img) => !taskUUIDs.includes(img.taskUUID)
|
|
1339
|
-
);
|
|
1340
|
-
return imagesWithSimilarTask;
|
|
1341
|
-
} else {
|
|
1342
|
-
throw error;
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
//end of data
|
|
1346
|
-
};
|
|
1347
|
-
|
|
1348
|
-
// Runware/Runware-client.ts
|
|
1349
|
-
var import_reconnect = __toESM(require_reconnect(), 1);
|
|
1350
|
-
var RunwareClient = class extends RunwareBase {
|
|
1351
|
-
constructor(props) {
|
|
1352
|
-
const _a = props, { shouldReconnect } = _a, rest = __objRest(_a, ["shouldReconnect"]);
|
|
1353
|
-
super(rest);
|
|
1354
|
-
this._ws = new import_reconnect.default(
|
|
1355
|
-
this._url
|
|
1356
|
-
);
|
|
1357
|
-
this.connect();
|
|
1358
|
-
}
|
|
1359
|
-
};
|
|
1360
|
-
|
|
1361
|
-
// Runware/Runware-server.ts
|
|
1362
|
-
var import_ws = __toESM(require("ws"), 1);
|
|
1363
|
-
var RunwareServer = class extends RunwareBase {
|
|
1364
|
-
constructor(props) {
|
|
1365
|
-
super(props);
|
|
1366
|
-
this._instantiated = false;
|
|
1367
|
-
this._listeners = [];
|
|
1368
|
-
this._reconnectingIntervalId = null;
|
|
1369
|
-
this.send = (msg) => {
|
|
1370
|
-
this._ws.send(JSON.stringify([msg]));
|
|
1371
|
-
};
|
|
1372
|
-
this.resetConnection = () => {
|
|
1373
|
-
if (this._ws) {
|
|
1374
|
-
this._listeners.forEach((list) => {
|
|
1375
|
-
var _a;
|
|
1376
|
-
(_a = list == null ? void 0 : list.destroy) == null ? void 0 : _a.call(list);
|
|
1377
|
-
});
|
|
1378
|
-
this._ws.removeAllListeners();
|
|
1379
|
-
this._ws.terminate();
|
|
1380
|
-
this._ws.close();
|
|
1381
|
-
this._ws = null;
|
|
1382
|
-
this._listeners = [];
|
|
1383
|
-
}
|
|
1384
|
-
};
|
|
1385
|
-
this._sdkType = "SERVER" /* SERVER */;
|
|
1386
|
-
this.connect();
|
|
1387
|
-
}
|
|
1388
|
-
// protected addListener({
|
|
1389
|
-
// lis,
|
|
1390
|
-
// check,
|
|
1391
|
-
// groupKey,
|
|
1392
|
-
// }: {
|
|
1393
|
-
// lis: (v: any) => any;
|
|
1394
|
-
// check: (v: any) => any;
|
|
1395
|
-
// groupKey?: string;
|
|
1396
|
-
// }) {
|
|
1397
|
-
// const listener = (msg: any) => {
|
|
1398
|
-
// if (msg?.error) {
|
|
1399
|
-
// lis(msg);
|
|
1400
|
-
// } else if (check(msg)) {
|
|
1401
|
-
// lis(msg);
|
|
1402
|
-
// }
|
|
1403
|
-
// };
|
|
1404
|
-
// const groupListener = { key: getUUID(), listener, groupKey };
|
|
1405
|
-
// this._listeners.push(groupListener);
|
|
1406
|
-
// const destroy = () => {
|
|
1407
|
-
// this._listeners = removeListener(this._listeners, groupListener);
|
|
1408
|
-
// };
|
|
1409
|
-
// return {
|
|
1410
|
-
// destroy,
|
|
1411
|
-
// };
|
|
1412
|
-
// }
|
|
1413
|
-
async connect() {
|
|
1414
|
-
if (!this._url)
|
|
1415
|
-
return;
|
|
1416
|
-
this.resetConnection();
|
|
1417
|
-
this._ws = new import_ws.default(this._url, {
|
|
1418
|
-
perMessageDeflate: false
|
|
1419
|
-
});
|
|
1420
|
-
this._ws.on("error", () => {
|
|
1421
|
-
});
|
|
1422
|
-
this._ws.on("close", () => {
|
|
1423
|
-
this.handleClose();
|
|
1424
|
-
});
|
|
1425
|
-
this._ws.on("open", () => {
|
|
1426
|
-
if (this._reconnectingIntervalId) {
|
|
1427
|
-
clearInterval(this._reconnectingIntervalId);
|
|
1428
|
-
}
|
|
1429
|
-
if (this._connectionSessionUUID && this.isWebsocketReadyState()) {
|
|
1430
|
-
this.send({
|
|
1431
|
-
taskType: "authentication" /* AUTHENTICATION */,
|
|
1432
|
-
apiKey: this._apiKey,
|
|
1433
|
-
connectionSessionUUID: this._connectionSessionUUID
|
|
1434
|
-
});
|
|
1435
|
-
} else {
|
|
1436
|
-
if (this.isWebsocketReadyState()) {
|
|
1437
|
-
this.send({
|
|
1438
|
-
apiKey: this._apiKey,
|
|
1439
|
-
taskType: "authentication" /* AUTHENTICATION */
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
this.addListener({
|
|
1444
|
-
taskUUID: "authentication" /* AUTHENTICATION */,
|
|
1445
|
-
lis: (m) => {
|
|
1446
|
-
var _a, _b;
|
|
1447
|
-
if (m == null ? void 0 : m.error) {
|
|
1448
|
-
this._invalidAPIkey = m;
|
|
1449
|
-
return;
|
|
1450
|
-
}
|
|
1451
|
-
this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
|
|
1452
|
-
this._invalidAPIkey = void 0;
|
|
1453
|
-
}
|
|
1454
|
-
});
|
|
1455
|
-
});
|
|
1456
|
-
this._ws.on("message", (e, isBinary) => {
|
|
1457
|
-
const data = isBinary ? e : e == null ? void 0 : e.toString();
|
|
1458
|
-
if (!data)
|
|
1459
|
-
return;
|
|
1460
|
-
const m = JSON.parse(data);
|
|
1461
|
-
this._listeners.forEach((lis) => {
|
|
1462
|
-
const result = lis.listener(m);
|
|
1463
|
-
if (result) {
|
|
1464
|
-
return;
|
|
1465
|
-
}
|
|
1466
|
-
});
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
handleClose() {
|
|
1470
|
-
if (this._invalidAPIkey) {
|
|
1471
|
-
return;
|
|
1472
|
-
}
|
|
1473
|
-
if (this._reconnectingIntervalId) {
|
|
1474
|
-
clearInterval(this._reconnectingIntervalId);
|
|
1475
|
-
}
|
|
1476
|
-
if (this._shouldReconnect) {
|
|
1477
|
-
setTimeout(() => this.connect(), 1e3);
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
heartBeat() {
|
|
1481
|
-
clearTimeout(this._pingTimeout);
|
|
1482
|
-
this._pingTimeout = setTimeout(() => {
|
|
1483
|
-
if (this.isWebsocketReadyState()) {
|
|
1484
|
-
this.send({ ping: true });
|
|
1485
|
-
}
|
|
1486
|
-
}, 5e3);
|
|
1487
|
-
}
|
|
1488
|
-
//end of data
|
|
1489
|
-
};
|
|
1490
|
-
|
|
1491
|
-
// Runware/Runware.ts
|
|
1492
|
-
var Runware;
|
|
1493
|
-
if (typeof window === "undefined") {
|
|
1494
|
-
Runware = RunwareServer;
|
|
1495
|
-
} else {
|
|
1496
|
-
Runware = RunwareClient;
|
|
1497
|
-
}
|
|
1498
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1499
|
-
0 && (module.exports = {
|
|
1500
|
-
EControlMode,
|
|
1501
|
-
EOpenPosePreProcessor,
|
|
1502
|
-
EPreProcessor,
|
|
1503
|
-
EPreProcessorGroup,
|
|
1504
|
-
ETaskType,
|
|
1505
|
-
Environment,
|
|
1506
|
-
Runware,
|
|
1507
|
-
RunwareClient,
|
|
1508
|
-
RunwareServer,
|
|
1509
|
-
SdkType
|
|
1510
|
-
});
|
|
1
|
+
"use strict";var Ae=Object.create;var M=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var Ee=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var Le=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),Me=(r,t)=>{for(var e in t)M(r,e,{get:t[e],enumerable:!0})},ee=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ne(t))!Ce.call(r,s)&&s!==e&&M(r,s,{get:()=>t[s],enumerable:!(n=Oe(t,s))||n.enumerable});return r};var te=(r,t,e)=>(e=r!=null?Ae(Ee(r)):{},ee(t||!r||!r.__esModule?M(e,"default",{value:r,enumerable:!0}):e,r)),We=r=>ee(M({},"__esModule",{value:!0}),r);var fe=Le((wt,he)=>{"use strict";var ye=r=>r&&r.CLOSING===2,Be=()=>typeof WebSocket<"u"&&ye(WebSocket),Fe=()=>({constructor:Be()?WebSocket:null,maxReconnectionDelay:1e4,minReconnectionDelay:1500,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,debug:!1}),Ge=(r,t,e)=>{Object.defineProperty(t,e,{get:()=>r[e],set:n=>{r[e]=n},enumerable:!0,configurable:!0})},me=r=>r.minReconnectionDelay+Math.random()*r.minReconnectionDelay,Pe=(r,t)=>{let e=t*r.reconnectionDelayGrowFactor;return e>r.maxReconnectionDelay?r.maxReconnectionDelay:e},qe=["onopen","onclose","onmessage","onerror"],He=(r,t,e)=>{Object.keys(e).forEach(n=>{e[n].forEach(([s,a])=>{r.addEventListener(n,s,a)})}),t&&qe.forEach(n=>{r[n]=t[n]})},Ie=function(r,t,e={}){let n,s,a=0,l=0,c=!0,i={};if(!(this instanceof Ie))throw new TypeError("Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator");let o=Fe();if(Object.keys(o).filter(p=>e.hasOwnProperty(p)).forEach(p=>o[p]=e[p]),!ye(o.constructor))throw new TypeError("Invalid WebSocket constructor. Set `options.constructor`");let d=o.debug?(...p)=>console.log("RWS:",...p):()=>{},f=(p,m)=>setTimeout(()=>{let _=new Error(m);_.code=p,Array.isArray(i.error)&&i.error.forEach(([T])=>T(_)),n.onerror&&n.onerror(_)},0),u=()=>{if(d("close"),l++,d("retries count:",l),l>o.maxRetries){f("EHOSTDOWN","Too many failed connection attempts");return}a?a=Pe(o,a):a=me(o),d("reconnectDelay:",a),c&&setTimeout(g,a)},g=()=>{d("connect");let p=n;n=new o.constructor(r,t),s=setTimeout(()=>{d("timeout"),n.close(),f("ETIMEDOUT","Connection timeout")},o.connectionTimeout),d("bypass properties");for(let m in n)["addEventListener","removeEventListener","close","send"].indexOf(m)<0&&Ge(n,this,m);n.addEventListener("open",()=>{clearTimeout(s),d("open"),a=me(o),d("reconnectDelay:",a),l=0}),n.addEventListener("close",u),He(n,p,i)};d("init"),g(),this.close=(p=1e3,m="",{keepClosed:_=!1,fastClose:T=!0,delay:D=0}={})=>{if(D&&(a=D),c=!_,n.close(p,m),T){let k={code:p,reason:m,wasClean:!0};u(),Array.isArray(i.close)&&i.close.forEach(([U,y])=>{U(k),n.removeEventListener("close",U,y)}),n.onclose&&(n.onclose(k),n.onclose=null)}},this.send=p=>{n.send(p)},this.addEventListener=(p,m,_)=>{Array.isArray(i[p])?i[p].some(([T])=>T===m)||i[p].push([m,_]):i[p]=[[m,_]],n.addEventListener(p,m,_)},this.removeEventListener=(p,m,_)=>{Array.isArray(i[p])&&(i[p]=i[p].filter(([T])=>T!==m)),n.removeEventListener(p,m,_)}};he.exports=Ie});var Ve={};Me(Ve,{EControlMode:()=>j,EModelArchitecture:()=>re,EModelConditioning:()=>oe,EModelFormat:()=>se,EModelType:()=>ae,EOpenPosePreProcessor:()=>ne,EPreProcessor:()=>z,EPreProcessorGroup:()=>J,ETaskType:()=>K,Environment:()=>V,Runware:()=>Z,RunwareClient:()=>N,RunwareServer:()=>E,SdkType:()=>W});module.exports=We(Ve);var V=(n=>(n.PRODUCTION="PRODUCTION",n.DEVELOPMENT="DEVELOPMENT",n.TEST="TEST",n))(V||{}),W=(e=>(e.CLIENT="CLIENT",e.SERVER="SERVER",e))(W||{}),K=(o=>(o.IMAGE_INFERENCE="imageInference",o.IMAGE_UPLOAD="imageUpload",o.IMAGE_UPSCALE="imageUpscale",o.IMAGE_BACKGROUND_REMOVAL="imageBackgroundRemoval",o.IMAGE_CAPTION="imageCaption",o.IMAGE_CONTROL_NET_PRE_PROCESS="imageControlNetPreProcess",o.PROMPT_ENHANCE="promptEnhance",o.AUTHENTICATION="authentication",o.MODEL_UPLOAD="modelUpload",o))(K||{}),j=(n=>(n.BALANCED="balanced",n.PROMPT="prompt",n.CONTROL_NET="controlnet",n))(j||{}),J=(u=>(u.canny="canny",u.depth="depth",u.mlsd="mlsd",u.normalbae="normalbae",u.openpose="openpose",u.tile="tile",u.seg="seg",u.lineart="lineart",u.lineart_anime="lineart_anime",u.shuffle="shuffle",u.scribble="scribble",u.softedge="softedge",u))(J||{}),z=(h=>(h.canny="canny",h.depth_leres="depth_leres",h.depth_midas="depth_midas",h.depth_zoe="depth_zoe",h.inpaint_global_harmonious="inpaint_global_harmonious",h.lineart_anime="lineart_anime",h.lineart_coarse="lineart_coarse",h.lineart_realistic="lineart_realistic",h.lineart_standard="lineart_standard",h.mlsd="mlsd",h.normal_bae="normal_bae",h.scribble_hed="scribble_hed",h.scribble_pidinet="scribble_pidinet",h.seg_ofade20k="seg_ofade20k",h.seg_ofcoco="seg_ofcoco",h.seg_ufade20k="seg_ufade20k",h.shuffle="shuffle",h.softedge_hed="softedge_hed",h.softedge_hedsafe="softedge_hedsafe",h.softedge_pidinet="softedge_pidinet",h.softedge_pidisafe="softedge_pidisafe",h.tile_gaussian="tile_gaussian",h.openpose="openpose",h.openpose_face="openpose_face",h.openpose_faceonly="openpose_faceonly",h.openpose_full="openpose_full",h.openpose_hand="openpose_hand",h))(z||{}),ne=(a=>(a.openpose="openpose",a.openpose_face="openpose_face",a.openpose_faceonly="openpose_faceonly",a.openpose_full="openpose_full",a.openpose_hand="openpose_hand",a))(ne||{}),se=(e=>(e.safetensors="safetensors",e.pickletensor="pickletensor",e))(se||{}),re=(g=>(g.flux1d="flux1d",g.flux1s="flux1s",g.pony="pony",g.sdhyper="sdhyper",g.sd1x="sd1x",g.sd1xlcm="sd1xlcm",g.sd3="sd3",g.sdxl="sdxl",g.sdxllcm="sdxllcm",g.sdxldistilled="sdxldistilled",g.sdxlhyper="sdxlhyper",g.sdxllightning="sdxllightning",g.sdxlturbo="sdxlturbo",g))(re||{}),ae=(n=>(n.base="base",n.inpainting="inpainting",n.pix2pix="pix2pix",n))(ae||{}),oe=(y=>(y.canny="canny",y.depth="depth",y.qrcode="qrcode",y.hed="hed",y.scrible="scrible",y.openpose="openpose",y.seg="segmentation",y.openmlsd="openmlsd",y.softedge="softedge",y.normal="normal bae",y.shuffle="shuffle",y.pix2pix="pix2pix",y.inpaint="inpaint",y.lineart="line art",y.sketch="sketch",y.inpaintdepth="inpaint depth",y.tile="tile",y.outfit="outfit",y.blur="blur",y.gray="gray",y.lowquality="low quality",y))(oe||{});var B=require("uuid"),Q=6e4,ie=1e3,Ke=100,Y={PRODUCTION:"wss://ws-api.runware.ai/v1",TEST:"ws://localhost:8080"},le=(r,t)=>{if(r==null)return;let e=r.indexOf(t);e!==-1&&r.splice(e,1)},v=(r,{debugKey:t="debugKey",timeoutDuration:e=Q,shouldThrowError:n=!0})=>(e=e<ie?ie:e,new Promise((s,a)=>{let l=setTimeout(()=>{c&&(clearInterval(c),n&&a(`Response could not be received from server for ${t}`)),clearTimeout(l)},e),c=setInterval(async()=>{r({resolve:s,reject:a,intervalId:c})&&(clearInterval(c),clearTimeout(l))},Ke)})),ce=r=>new Promise(t=>{let e=new FileReader;e.readAsDataURL(r),e.onload=function(){t(e.result)}}),R=()=>(0,B.v4)(),ue=r=>(0,B.validate)(r);var de=({key:r,data:t,useZero:e=!0,shouldReturnString:n=!1})=>r.split(/\.|\[/).map(l=>l.replace(/\]$/,"")).reduce((l,c)=>{let i=e?0:void 0,o=l?.[c];if(!o)return i;if(Array.isArray(o)&&/^\d+$/.test(c)){let d=parseInt(c,10);return d>=0&&d<o.length?l[c]=o[d]:l[c]??i}else return l[c]??i},t||{})??{},pe=(r,t=1e3)=>new Promise(e=>setTimeout(e,r*t));var ge=(r,t)=>r.filter(e=>e.key!==t.key);var I=({key:r,value:t})=>t||t===0||t===!1?{[r]:t}:{};var x=async(r,t={})=>{let{delayInSeconds:e=1,callback:n}=t,s=t.maxRetries??1;for(;s;)try{return await r()}catch(a){if(n?.(),s--,s>0)await pe(e),await x(r,{...t,maxRetries:s});else throw a}};var S=class{constructor({apiKey:t,url:e=Y.PRODUCTION,shouldReconnect:n=!0,globalMaxRetries:s=2,timeoutDuration:a=Q}){this._listeners=[];this._globalMessages={};this._globalImages=[];this.isWebsocketReadyState=()=>this._ws?.readyState===1;this.send=t=>{this._ws.send(JSON.stringify([t]))};this.uploadImage=async t=>{try{return await x(async()=>{let e=R();if(typeof t=="string"&&ue(t))return{imageURL:t,imageUUID:t,taskUUID:e,taskType:"imageUpload"};let n=typeof t=="string"?t:await ce(t);return{imageURL:n,imageUUID:n,taskUUID:e,taskType:"imageUpload"}})}catch(e){throw e}};this.controlNetPreProcess=async({inputImage:t,preProcessorType:e,height:n,width:s,outputType:a,outputFormat:l,highThresholdCanny:c,lowThresholdCanny:i,includeHandsAndFaceOpenPose:o,includeCost:d,customTaskUUID:f,retry:u})=>{let g=u||this._globalMaxRetries,p;try{return await x(async()=>{await this.ensureConnection();let m=await this.uploadImage(t);if(!m?.imageUUID)return null;let _=f||R();this.send({inputImage:m.imageUUID,taskType:"imageControlNetPreProcess",taskUUID:_,preProcessorType:e,...I({key:"height",value:n}),...I({key:"width",value:s}),...I({key:"outputType",value:a}),...I({key:"outputFormat",value:l}),...I({key:"includeCost",value:d}),...I({key:"highThresholdCanny",value:c}),...I({key:"lowThresholdCanny",value:i}),...I({key:"includeHandsAndFaceOpenPose",value:o})}),p=this.globalListener({taskUUID:_});let T=await v(({resolve:D,reject:k})=>{let U=this.getSingleMessage({taskUUID:_});if(U){if(U?.error)return k(U),!0;if(U)return D(U),!0}},{debugKey:"unprocessed-image",timeoutDuration:this._timeoutDuration});return p.destroy(),T},{maxRetries:g,callback:()=>{p?.destroy()}})}catch(m){throw m}};this.requestImageToText=async({inputImage:t,includeCost:e,customTaskUUID:n,retry:s})=>{let a=s||this._globalMaxRetries,l;try{return await x(async()=>{await this.ensureConnection();let c=t?await this.uploadImage(t):null,i=n||R();this.send({taskUUID:i,taskType:"imageCaption",inputImage:c?.imageUUID,...I({key:"includeCost",value:e})}),l=this.globalListener({taskUUID:i});let o=await v(({resolve:d,reject:f})=>{let u=this.getSingleMessage({taskUUID:i});if(u){if(u?.error)return f(u),!0;if(u)return delete this._globalMessages[i],d(u),!0}},{debugKey:"remove-image-background",timeoutDuration:this._timeoutDuration});return l.destroy(),o},{maxRetries:a,callback:()=>{l?.destroy()}})}catch(c){throw c}};this.removeImageBackground=async({inputImage:t,outputType:e,outputFormat:n,rgba:s,postProcessMask:a,returnOnlyMask:l,alphaMatting:c,alphaMattingForegroundThreshold:i,alphaMattingBackgroundThreshold:o,alphaMattingErodeSize:d,includeCost:f,customTaskUUID:u,retry:g})=>{let p=g||this._globalMaxRetries,m;try{return await x(async()=>{await this.ensureConnection();let _=t?await this.uploadImage(t):null,T=u||R();this.send({taskType:"imageBackgroundRemoval",taskUUID:T,inputImage:_?.imageUUID,...I({key:"rgba",value:s}),...I({key:"postProcessMask",value:a}),...I({key:"returnOnlyMask",value:l}),...I({key:"alphaMatting",value:c}),...I({key:"includeCost",value:f}),...I({key:"alphaMattingForegroundThreshold",value:i}),...I({key:"alphaMattingBackgroundThreshold",value:o}),...I({key:"alphaMattingErodeSize",value:d}),...I({key:"outputType",value:e}),...I({key:"outputFormat",value:n})}),m=this.globalListener({taskUUID:T});let D=await v(({resolve:k,reject:U})=>{let y=this.getSingleMessage({taskUUID:T});if(y){if(y?.error)return U(y),!0;if(y)return delete this._globalMessages[T],k(y),!0}},{debugKey:"remove-image-background",timeoutDuration:this._timeoutDuration});return m.destroy(),D},{maxRetries:p,callback:()=>{m?.destroy()}})}catch(_){throw _}};this.upscaleGan=async({inputImage:t,upscaleFactor:e,outputType:n,outputFormat:s,includeCost:a,customTaskUUID:l,retry:c})=>{let i=c||this._globalMaxRetries,o;try{return await x(async()=>{await this.ensureConnection();let d;d=await this.uploadImage(t);let f=l||R();this.send({taskUUID:f,inputImage:d?.imageUUID,taskType:"imageUpscale",upscaleFactor:e,...I({key:"includeCost",value:a}),...n?{outputType:n}:{},...s?{outputFormat:s}:{}}),o=this.globalListener({taskUUID:f});let u=await v(({resolve:g,reject:p})=>{let m=this.getSingleMessage({taskUUID:f});if(m){if(m?.error)return p(m),!0;if(m)return delete this._globalMessages[f],g(m),!0}},{debugKey:"upscale-gan",timeoutDuration:this._timeoutDuration});return o.destroy(),u},{maxRetries:i,callback:()=>{o?.destroy()}})}catch(d){throw d}};this.enhancePrompt=async({prompt:t,promptMaxLength:e=380,promptVersions:n=1,includeCost:s,customTaskUUID:a,retry:l})=>{let c=l||this._globalMaxRetries,i;try{return await x(async()=>{await this.ensureConnection();let o=a||R();this.send({prompt:t,taskUUID:o,promptMaxLength:e,promptVersions:n,...I({key:"includeCost",value:s}),taskType:"promptEnhance"}),i=this.globalListener({taskUUID:o});let d=await v(({resolve:f,reject:u})=>{let g=this._globalMessages[o];if(g?.error)return u(g),!0;if(g?.length>=n)return delete this._globalMessages[o],f(g),!0},{debugKey:"enhance-prompt",timeoutDuration:this._timeoutDuration});return i.destroy(),d},{maxRetries:c,callback:()=>{i?.destroy()}})}catch(o){throw o}};this.modelUpload=async t=>{let{onUploadStream:e,retry:n,customTaskUUID:s,...a}=t,l=n||this._globalMaxRetries,c;try{return await x(async()=>{await this.ensureConnection();let i=s||R();this.send({...a,taskUUID:i,taskType:"modelUpload"});let o,d;return c=this.listenToUpload({taskUUID:i,onUploadStream:(u,g)=>{e?.(u,g),u?.status==="ready"?o=u:g&&(d=g)}}),await v(({resolve:u,reject:g})=>{if(o)return u(o),!0;if(d)return g(d),!1},{shouldThrowError:!1,timeoutDuration:60*60*1e3})},{maxRetries:l,callback:()=>{c?.destroy()}})}catch(i){throw i}};this.getSingleMessage=({taskUUID:t})=>{let e=this._globalMessages[t]?.[0],n=this._globalMessages[t];return!e&&!n?null:n?.error?n:e};this.disconnect=async()=>{this._shouldReconnect=!1,this._ws?.terminate?.(),this._ws?.close?.()};this.connected=()=>this.isWebsocketReadyState()&&!!this._connectionSessionUUID;this._apiKey=t,this._url=e,this._sdkType="CLIENT",this._shouldReconnect=n,this._globalMaxRetries=s,this._timeoutDuration=a}static async initialize(t){try{let e=new this(t);return await e.ensureConnection(),e}catch(e){throw e}}addListener({lis:t,groupKey:e,taskUUID:n}){let s=c=>{let i=Array.isArray(c?.data)?c.data:[c.data],o=c?.[0]?.errors?c?.[0]?.errors:Array.isArray(c?.errors)?c.errors:[c.errors],d=i.filter(u=>(u?.taskUUID||u?.taskType)===n);if(o.filter(u=>(u?.taskUUID||u?.taskType)===n).length){t({error:{...o[0]??{}}});return}if(d.length){t({[n]:i});return}},a={key:n||R(),listener:s,groupKey:e};return this._listeners.push(a),{destroy:()=>{this._listeners=ge(this._listeners,a)}}}connect(){this._ws.onopen=t=>{this._connectionSessionUUID?this.send({taskType:"authentication",apiKey:this._apiKey,connectionSessionUUID:this._connectionSessionUUID}):this.send({apiKey:this._apiKey,taskType:"authentication"}),this.addListener({taskUUID:"authentication",lis:e=>{if(e?.error){this._invalidAPIkey=e;return}this._connectionSessionUUID=e?.authentication?.[0]?.connectionSessionUUID,this._invalidAPIkey=void 0}})},this._ws.onmessage=t=>{let e=JSON.parse(t.data);for(let n of this._listeners)if(n?.listener?.(e))return},this._ws.onclose=t=>{this._invalidAPIkey}}destroy(t){le(this._listeners,t)}listenToImages({onPartialImages:t,taskUUID:e,groupKey:n,positivePrompt:s,negativePrompt:a}){return this.addListener({taskUUID:e,lis:l=>{let c=l?.[e]?.filter(i=>i.taskUUID===e);l.error?(t?.(c,l?.error&&l),this._globalError=l):(c=c.map(i=>({...i,positivePrompt:s,negativePrompt:a})),t?.(c,l?.error&&l),this._sdkType==="CLIENT"?this._globalImages=[...this._globalImages,...(l?.[e]??[]).map(i=>({...i,positivePrompt:s,negativePrompt:a}))]:this._globalImages=[...this._globalImages,...c])},groupKey:n})}listenToUpload({onUploadStream:t,taskUUID:e}){return this.addListener({taskUUID:e,lis:n=>{let s=n?.error,a=n?.[e]?.[0],l=a?.taskUUID===e?a:null;(l||s)&&t?.(l||void 0,s)}})}globalListener({taskUUID:t}){return this.addListener({taskUUID:t,lis:e=>{if(e.error){this._globalMessages[t]=e;return}let n=de({key:t,data:e,useZero:!1});Array.isArray(n)?n.forEach(s=>{this._globalMessages[s.taskUUID]=[...this._globalMessages[s.taskUUID]??[],s]}):this._globalMessages[n.taskUUID]=n}})}async requestImages({outputType:t,outputFormat:e,uploadEndpoint:n,checkNsfw:s,positivePrompt:a,negativePrompt:l,seedImage:c,maskImage:i,strength:o,height:d,width:f,model:u,steps:g,scheduler:p,seed:m,CFGScale:_,clipSkip:T,usePromptWeighting:D,numberResults:k=1,controlNet:U,lora:y,onPartialImages:Ue,includeCost:be,customTaskUUID:ke,retry:Re}){let A,h,C=[],$=0,X=Re||this._globalMaxRetries;try{await this.ensureConnection();let w=null,F=null,G=[];if(c){let b=await this.uploadImage(c);if(!b)return[];w=b.imageUUID}if(i){let b=await this.uploadImage(i);if(!b)return[];F=b.imageUUID}if(U?.length)for(let b=0;b<U.length;b++){let O=U[b],{endStep:P,startStep:q,weight:H,guideImage:L,controlMode:xe,startStepPercentage:De,endStepPercentage:ve,model:we}=O,Se=L?await this.uploadImage(L):null;G.push({guideImage:Se?.imageUUID,model:we,endStep:P,startStep:q,weight:H,...I({key:"startStepPercentage",value:De}),...I({key:"endStepPercentage",value:ve}),controlMode:xe||"controlnet"})}return h={taskType:"imageInference",model:u,positivePrompt:a,...l?{negativePrompt:l}:{},...d?{height:d}:{},...f?{width:f}:{},numberResults:k,...y?.length?{lora:y}:{},...t?{outputType:t}:{},...e?{outputFormat:e}:{},...n?{uploadEndpoint:n}:{},...I({key:"checkNsfw",value:s}),...I({key:"strength",value:o}),...I({key:"CFGScale",value:_}),...I({key:"clipSkip",value:T}),...I({key:"usePromptWeighting",value:D}),...I({key:"steps",value:g}),...G.length?{controlNet:G}:{},...m?{seed:m}:{},...p?{scheduler:p}:{},...I({key:"includeCost",value:be}),...w?{seedImage:w}:{},...F?{maskImage:F}:{}},await x(async()=>{$++,A?.destroy();let b=this._globalImages.filter(L=>C.includes(L.taskUUID)),O=ke||R();C.push(O);let P=k-b.length,q={...h,taskUUID:O,numberResults:P};this.send(q),A=this.listenToImages({onPartialImages:Ue,taskUUID:O,groupKey:"REQUEST_IMAGES",positivePrompt:a,negativePrompt:l});let H=await this.getSimilarImages({taskUUID:C,numberResults:k,lis:A});return A.destroy(),H},{maxRetries:X,callback:()=>{A?.destroy()}})}catch(w){if(w.taskUUID)throw w;if($>=X)return this.handleIncompleteImages({taskUUIDs:C,error:w})}}async ensureConnection(){if(this.connected()||this._url===Y.TEST)return;let e=2e3,n=200;try{if(this._invalidAPIkey)throw this._invalidAPIkey;return new Promise((s,a)=>{let l=0,c=30,i=30/2===l,o,d,f=()=>{clearInterval(o),clearInterval(d)};this._sdkType==="SERVER"&&(o=setInterval(async()=>{try{this.connected()?(f(),s(!0)):l>=c?(f(),a(new Error("Retry timed out"))):(i&&this.connect(),l++)}catch(u){f(),a(u)}},e)),d=setInterval(async()=>{if(this.connected()){f(),s(!0);return}if(this._invalidAPIkey){f(),a(this._invalidAPIkey);return}},n)})}catch{throw this._invalidAPIkey??"Could not connect to server. Ensure your API key is correct"}}async getSimilarImages({taskUUID:t,numberResults:e,shouldThrowError:n,lis:s}){return await v(({resolve:a,reject:l,intervalId:c})=>{let i=Array.isArray(t)?t:[t],o=this._globalImages.filter(d=>i.includes(d.taskUUID));if(this._globalError){let d=this._globalError;return this._globalError=void 0,clearInterval(c),l?.(d),!0}else if(o.length>=e)return clearInterval(c),this._globalImages=this._globalImages.filter(d=>!i.includes(d.taskUUID)),a([...o].slice(0,e)),!0},{debugKey:"getting images",shouldThrowError:n,timeoutDuration:this._timeoutDuration})}handleIncompleteImages({taskUUIDs:t,error:e}){let n=this._globalImages.filter(s=>t.includes(s.taskUUID));if(n.length>1)return this._globalImages=this._globalImages.filter(s=>!t.includes(s.taskUUID)),n;throw e}};var _e=te(fe(),1),N=class extends S{constructor(t){let{shouldReconnect:e,...n}=t;super(n),this._ws=new _e.default(this._url),this.connect()}};var Te=te(require("ws"),1);var E=class extends S{constructor(e){super(e);this._instantiated=!1;this._listeners=[];this._reconnectingIntervalId=null;this.send=e=>{this._ws.send(JSON.stringify([e]))};this.resetConnection=()=>{this._ws&&(this._listeners.forEach(e=>{e?.destroy?.()}),this._ws.removeAllListeners(),this._ws.terminate(),this._ws.close(),this._ws=null,this._listeners=[])};this._sdkType="SERVER",this.connect()}async connect(){this._url&&(this.resetConnection(),this._ws=new Te.default(this._url,{perMessageDeflate:!1}),this._ws.on("error",()=>{}),this._ws.on("close",()=>{this.handleClose()}),this._ws.on("open",()=>{this._reconnectingIntervalId&&clearInterval(this._reconnectingIntervalId),this._connectionSessionUUID&&this.isWebsocketReadyState()?this.send({taskType:"authentication",apiKey:this._apiKey,connectionSessionUUID:this._connectionSessionUUID}):this.isWebsocketReadyState()&&this.send({apiKey:this._apiKey,taskType:"authentication"}),this.addListener({taskUUID:"authentication",lis:e=>{if(e?.error){this._invalidAPIkey=e;return}this._connectionSessionUUID=e?.authentication?.[0]?.connectionSessionUUID,this._invalidAPIkey=void 0}})}),this._ws.on("message",(e,n)=>{let s=n?e:e?.toString();if(!s)return;let a=JSON.parse(s);this._listeners.forEach(l=>{l.listener(a)})}))}handleClose(){this._invalidAPIkey||(this._reconnectingIntervalId&&clearInterval(this._reconnectingIntervalId),this._shouldReconnect&&setTimeout(()=>this.connect(),1e3))}heartBeat(){clearTimeout(this._pingTimeout),this._pingTimeout=setTimeout(()=>{this.isWebsocketReadyState()&&this.send({ping:!0})},5e3)}};var Z;typeof window>"u"?Z=E:Z=N;0&&(module.exports={EControlMode,EModelArchitecture,EModelConditioning,EModelFormat,EModelType,EOpenPosePreProcessor,EPreProcessor,EPreProcessorGroup,ETaskType,Environment,Runware,RunwareClient,RunwareServer,SdkType});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|