flowscale 2.1.0-beta.6 → 2.1.0-beta.7
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/operator-server.js +86 -35
- package/package.json +1 -1
package/dist/operator-server.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
14
|
if (k2 === undefined) k2 = k;
|
|
4
15
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -109,11 +120,11 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
109
120
|
if (this.server)
|
|
110
121
|
return;
|
|
111
122
|
this.server = http.createServer(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
112
|
-
var url, query, pods, podMatch, pod, uploadMatch, podId, port_1, executeMatch, podId, body, _a, _b, result, viewMatch, podId, port, workflowMatch, podId, port, filename, encoded, queueMatch, podId, port_2, body_1, historyMatch, podId, promptId, port, objectInfoMatch, podId, port, interruptMatch, podId, port_3, err_1;
|
|
123
|
+
var url, query, pods, podMatch, pod, uploadMatch, podId, port_1, executeMatch, podId, body, _a, _b, result, viewMatch, podId, port, workflowMatch, podId, port, filename, encoded, queueMatch, podId, port_2, body_1, historyMatch, podId, promptId, port, objectInfoMatch, podId, port, interruptMatch, podId, port_3, catchAllMatch, podId, subpath, port_4, qs, fullPath_1, err_1;
|
|
113
124
|
var _this = this;
|
|
114
|
-
var _c, _d, _e, _f, _g, _h;
|
|
115
|
-
return __generator(this, function (
|
|
116
|
-
switch (
|
|
125
|
+
var _c, _d, _e, _f, _g, _h, _j;
|
|
126
|
+
return __generator(this, function (_k) {
|
|
127
|
+
switch (_k.label) {
|
|
117
128
|
case 0:
|
|
118
129
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
119
130
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
@@ -125,20 +136,20 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
125
136
|
}
|
|
126
137
|
url = ((_c = req.url) !== null && _c !== void 0 ? _c : '/').split('?')[0];
|
|
127
138
|
query = new URLSearchParams((_e = ((_d = req.url) !== null && _d !== void 0 ? _d : '').split('?')[1]) !== null && _e !== void 0 ? _e : '');
|
|
128
|
-
|
|
139
|
+
_k.label = 1;
|
|
129
140
|
case 1:
|
|
130
|
-
|
|
141
|
+
_k.trys.push([1, 36, , 37]);
|
|
131
142
|
if (!(req.method === 'GET' && (url === '/api/pods' || url === '/api/pods/'))) return [3 /*break*/, 3];
|
|
132
143
|
return [4 /*yield*/, this.transport.list()];
|
|
133
144
|
case 2:
|
|
134
|
-
pods =
|
|
145
|
+
pods = _k.sent();
|
|
135
146
|
return [2 /*return*/, this._json(res, 200, pods)];
|
|
136
147
|
case 3:
|
|
137
148
|
podMatch = url.match(/^\/api\/pods\/([^/]+)$/);
|
|
138
149
|
if (!(req.method === 'GET' && podMatch)) return [3 /*break*/, 5];
|
|
139
150
|
return [4 /*yield*/, this.transport.get(decodeURIComponent(podMatch[1]))];
|
|
140
151
|
case 4:
|
|
141
|
-
pod =
|
|
152
|
+
pod = _k.sent();
|
|
142
153
|
if (!pod)
|
|
143
154
|
return [2 /*return*/, this._json(res, 404, { error: 'Pod not found' })];
|
|
144
155
|
return [2 /*return*/, this._json(res, 200, pod)];
|
|
@@ -148,7 +159,7 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
148
159
|
podId = decodeURIComponent(uploadMatch[1]);
|
|
149
160
|
return [4 /*yield*/, this._runningPort(podId)];
|
|
150
161
|
case 6:
|
|
151
|
-
port_1 =
|
|
162
|
+
port_1 = _k.sent();
|
|
152
163
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
153
164
|
var _a;
|
|
154
165
|
var headers = {
|
|
@@ -178,7 +189,7 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
178
189
|
req.pipe(upstreamReq);
|
|
179
190
|
})];
|
|
180
191
|
case 7:
|
|
181
|
-
|
|
192
|
+
_k.sent();
|
|
182
193
|
return [2 /*return*/];
|
|
183
194
|
case 8:
|
|
184
195
|
executeMatch = url.match(/^\/api\/pods\/([^/]+)\/execute$/);
|
|
@@ -187,10 +198,10 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
187
198
|
_b = (_a = JSON).parse;
|
|
188
199
|
return [4 /*yield*/, this._readBody(req)];
|
|
189
200
|
case 9:
|
|
190
|
-
body = _b.apply(_a, [(
|
|
201
|
+
body = _b.apply(_a, [(_k.sent()).toString()]);
|
|
191
202
|
return [4 /*yield*/, this.api.executeWorkflowAndWait(podId, body.workflow, (_f = body.options) !== null && _f !== void 0 ? _f : {})];
|
|
192
203
|
case 10:
|
|
193
|
-
result =
|
|
204
|
+
result = _k.sent();
|
|
194
205
|
return [2 /*return*/, this._json(res, 200, result)];
|
|
195
206
|
case 11:
|
|
196
207
|
viewMatch = url.match(/^\/api\/pods\/([^/]+)\/view$/);
|
|
@@ -198,10 +209,10 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
198
209
|
podId = decodeURIComponent(viewMatch[1]);
|
|
199
210
|
return [4 /*yield*/, this._runningPort(podId)];
|
|
200
211
|
case 12:
|
|
201
|
-
port =
|
|
212
|
+
port = _k.sent();
|
|
202
213
|
return [4 /*yield*/, this._proxyGet(res, port, "/view?".concat(query))];
|
|
203
214
|
case 13:
|
|
204
|
-
|
|
215
|
+
_k.sent();
|
|
205
216
|
return [2 /*return*/];
|
|
206
217
|
case 14:
|
|
207
218
|
workflowMatch = url.match(/^\/api\/pods\/([^/]+)\/workflow$/);
|
|
@@ -209,12 +220,12 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
209
220
|
podId = decodeURIComponent(workflowMatch[1]);
|
|
210
221
|
return [4 /*yield*/, this._runningPort(podId)];
|
|
211
222
|
case 15:
|
|
212
|
-
port =
|
|
223
|
+
port = _k.sent();
|
|
213
224
|
filename = (_g = query.get('filename')) !== null && _g !== void 0 ? _g : '';
|
|
214
225
|
encoded = encodeURIComponent("workflows/".concat(filename));
|
|
215
226
|
return [4 /*yield*/, this._proxyGet(res, port, "/api/userdata/".concat(encoded))];
|
|
216
227
|
case 16:
|
|
217
|
-
|
|
228
|
+
_k.sent();
|
|
218
229
|
return [2 /*return*/];
|
|
219
230
|
case 17:
|
|
220
231
|
queueMatch = url.match(/^\/api\/pods\/([^/]+)\/queue$/);
|
|
@@ -222,10 +233,10 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
222
233
|
podId = decodeURIComponent(queueMatch[1]);
|
|
223
234
|
return [4 /*yield*/, this._runningPort(podId)];
|
|
224
235
|
case 18:
|
|
225
|
-
port_2 =
|
|
236
|
+
port_2 = _k.sent();
|
|
226
237
|
return [4 /*yield*/, this._readBody(req)];
|
|
227
238
|
case 19:
|
|
228
|
-
body_1 =
|
|
239
|
+
body_1 = _k.sent();
|
|
229
240
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
230
241
|
var upstreamReq = http.request({
|
|
231
242
|
hostname: 'localhost',
|
|
@@ -253,7 +264,7 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
253
264
|
upstreamReq.end();
|
|
254
265
|
})];
|
|
255
266
|
case 20:
|
|
256
|
-
|
|
267
|
+
_k.sent();
|
|
257
268
|
return [2 /*return*/];
|
|
258
269
|
case 21:
|
|
259
270
|
historyMatch = url.match(/^\/api\/pods\/([^/]+)\/history\/([^/]+)$/);
|
|
@@ -262,10 +273,10 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
262
273
|
promptId = decodeURIComponent(historyMatch[2]);
|
|
263
274
|
return [4 /*yield*/, this._runningPort(podId)];
|
|
264
275
|
case 22:
|
|
265
|
-
port =
|
|
276
|
+
port = _k.sent();
|
|
266
277
|
return [4 /*yield*/, this._proxyGet(res, port, "/history/".concat(promptId))];
|
|
267
278
|
case 23:
|
|
268
|
-
|
|
279
|
+
_k.sent();
|
|
269
280
|
return [2 /*return*/];
|
|
270
281
|
case 24:
|
|
271
282
|
objectInfoMatch = url.match(/^\/api\/pods\/([^/]+)\/object_info$/);
|
|
@@ -273,10 +284,10 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
273
284
|
podId = decodeURIComponent(objectInfoMatch[1]);
|
|
274
285
|
return [4 /*yield*/, this._runningPort(podId)];
|
|
275
286
|
case 25:
|
|
276
|
-
port =
|
|
287
|
+
port = _k.sent();
|
|
277
288
|
return [4 /*yield*/, this._proxyGet(res, port, '/object_info')];
|
|
278
289
|
case 26:
|
|
279
|
-
|
|
290
|
+
_k.sent();
|
|
280
291
|
return [2 /*return*/];
|
|
281
292
|
case 27:
|
|
282
293
|
interruptMatch = url.match(/^\/api\/pods\/([^/]+)\/interrupt$/);
|
|
@@ -284,31 +295,71 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
284
295
|
podId = decodeURIComponent(interruptMatch[1]);
|
|
285
296
|
return [4 /*yield*/, this._runningPort(podId)];
|
|
286
297
|
case 28:
|
|
287
|
-
port_3 =
|
|
298
|
+
port_3 = _k.sent();
|
|
288
299
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
289
300
|
var upstreamReq = http.request({ hostname: 'localhost', port: port_3, path: '/interrupt', method: 'POST' }, function (upstreamRes) { upstreamRes.resume(); upstreamRes.on('end', resolve); });
|
|
290
301
|
upstreamReq.on('error', reject);
|
|
291
302
|
upstreamReq.end();
|
|
292
303
|
})];
|
|
293
304
|
case 29:
|
|
294
|
-
|
|
305
|
+
_k.sent();
|
|
295
306
|
return [2 /*return*/, this._json(res, 200, { ok: true })];
|
|
296
307
|
case 30:
|
|
308
|
+
catchAllMatch = url.match(/^\/api\/pods\/([^/]+)(\/.+)$/);
|
|
309
|
+
if (!catchAllMatch) return [3 /*break*/, 35];
|
|
310
|
+
podId = decodeURIComponent(catchAllMatch[1]);
|
|
311
|
+
subpath = catchAllMatch[2];
|
|
312
|
+
return [4 /*yield*/, this._runningPort(podId)];
|
|
313
|
+
case 31:
|
|
314
|
+
port_4 = _k.sent();
|
|
315
|
+
qs = ((_h = req.url) !== null && _h !== void 0 ? _h : '').split('?')[1];
|
|
316
|
+
fullPath_1 = qs ? "".concat(subpath, "?").concat(qs) : subpath;
|
|
317
|
+
if (!(req.method === 'GET' || req.method === 'HEAD')) return [3 /*break*/, 33];
|
|
318
|
+
return [4 /*yield*/, this._proxyGet(res, port_4, fullPath_1)];
|
|
319
|
+
case 32:
|
|
320
|
+
_k.sent();
|
|
321
|
+
return [2 /*return*/];
|
|
322
|
+
case 33:
|
|
323
|
+
// POST / PUT / PATCH / DELETE — pipe body through
|
|
324
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
325
|
+
var upstream = http.request({
|
|
326
|
+
hostname: 'localhost',
|
|
327
|
+
port: port_4,
|
|
328
|
+
path: fullPath_1, method: req.method,
|
|
329
|
+
headers: __assign(__assign({}, (req.headers['content-type'] ? { 'content-type': req.headers['content-type'] } : {})), (req.headers['content-length'] ? { 'content-length': req.headers['content-length'] } : {})),
|
|
330
|
+
}, function (upstreamRes) {
|
|
331
|
+
var _a, _b;
|
|
332
|
+
res.writeHead((_a = upstreamRes.statusCode) !== null && _a !== void 0 ? _a : 200, {
|
|
333
|
+
'Content-Type': (_b = upstreamRes.headers['content-type']) !== null && _b !== void 0 ? _b : 'application/json',
|
|
334
|
+
'Access-Control-Allow-Origin': '*',
|
|
335
|
+
});
|
|
336
|
+
upstreamRes.pipe(res);
|
|
337
|
+
upstreamRes.on('end', resolve);
|
|
338
|
+
upstreamRes.on('error', reject);
|
|
339
|
+
});
|
|
340
|
+
upstream.on('error', reject);
|
|
341
|
+
req.pipe(upstream);
|
|
342
|
+
})];
|
|
343
|
+
case 34:
|
|
344
|
+
// POST / PUT / PATCH / DELETE — pipe body through
|
|
345
|
+
_k.sent();
|
|
346
|
+
return [2 /*return*/];
|
|
347
|
+
case 35:
|
|
297
348
|
res.writeHead(404);
|
|
298
349
|
res.end('Not found');
|
|
299
|
-
return [3 /*break*/,
|
|
300
|
-
case
|
|
301
|
-
err_1 =
|
|
350
|
+
return [3 /*break*/, 37];
|
|
351
|
+
case 36:
|
|
352
|
+
err_1 = _k.sent();
|
|
302
353
|
console.error('[PodsOperatorServer] Error handling request:', err_1);
|
|
303
|
-
this._json(res, 500, { error: (
|
|
304
|
-
return [3 /*break*/,
|
|
305
|
-
case
|
|
354
|
+
this._json(res, 500, { error: (_j = err_1 === null || err_1 === void 0 ? void 0 : err_1.message) !== null && _j !== void 0 ? _j : 'Internal server error' });
|
|
355
|
+
return [3 /*break*/, 37];
|
|
356
|
+
case 37: return [2 /*return*/];
|
|
306
357
|
}
|
|
307
358
|
});
|
|
308
359
|
}); });
|
|
309
360
|
// ── WebSocket tunnel: WS /api/pods/:id/ws?clientId= ─────────────────────
|
|
310
361
|
this.server.on('upgrade', function (req, socket, head) { return __awaiter(_this, void 0, void 0, function () {
|
|
311
|
-
var rawUrl, urlPath, qs, wsMatch, podId,
|
|
362
|
+
var rawUrl, urlPath, qs, wsMatch, podId, port_5, clientId_1, upstream_1, err_2;
|
|
312
363
|
var _a, _b, _c;
|
|
313
364
|
return __generator(this, function (_d) {
|
|
314
365
|
switch (_d.label) {
|
|
@@ -327,14 +378,14 @@ var PodsOperatorServer = /** @class */ (function () {
|
|
|
327
378
|
_d.trys.push([1, 3, , 4]);
|
|
328
379
|
return [4 /*yield*/, this._runningPort(podId)];
|
|
329
380
|
case 2:
|
|
330
|
-
|
|
381
|
+
port_5 = _d.sent();
|
|
331
382
|
clientId_1 = (_c = qs.get('clientId')) !== null && _c !== void 0 ? _c : '';
|
|
332
|
-
upstream_1 = net.createConnection({ host: 'localhost', port:
|
|
383
|
+
upstream_1 = net.createConnection({ host: 'localhost', port: port_5 });
|
|
333
384
|
upstream_1.on('connect', function () {
|
|
334
385
|
var _a, _b;
|
|
335
386
|
var upgradeReq = [
|
|
336
387
|
"GET /ws?clientId=".concat(encodeURIComponent(clientId_1), " HTTP/1.1"),
|
|
337
|
-
"Host: localhost:".concat(
|
|
388
|
+
"Host: localhost:".concat(port_5),
|
|
338
389
|
'Upgrade: websocket',
|
|
339
390
|
'Connection: Upgrade',
|
|
340
391
|
"Sec-WebSocket-Key: ".concat((_a = req.headers['sec-websocket-key']) !== null && _a !== void 0 ? _a : ''),
|