@resolveio/server-lib 20.16.0 → 22.0.1
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/managers/subscription.manager.d.ts +3 -0
- package/managers/subscription.manager.js +111 -12
- package/managers/subscription.manager.js.map +1 -1
- package/managers/websocket.manager.d.ts +4 -0
- package/managers/websocket.manager.js +37 -0
- package/managers/websocket.manager.js.map +1 -1
- package/managers/worker-dispatcher.manager.d.ts +4 -0
- package/managers/worker-dispatcher.manager.js +102 -1
- package/managers/worker-dispatcher.manager.js.map +1 -1
- package/methods/ai-terminal.js +58 -2
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +4 -1
- package/server-app.d.ts +1 -0
- package/server-app.js +44 -2
- package/server-app.js.map +1 -1
|
@@ -41,6 +41,7 @@ export declare class SubscriptionManager {
|
|
|
41
41
|
private _subSendLogThresholdMs;
|
|
42
42
|
private _subSendLogBytes;
|
|
43
43
|
private _subSendLogSampleRate;
|
|
44
|
+
private _aiWorkerDebug;
|
|
44
45
|
private _oplogRetryCount;
|
|
45
46
|
private _lastResumeToken;
|
|
46
47
|
private _lastResumeTokenSaveMs;
|
|
@@ -111,6 +112,8 @@ export declare class SubscriptionManager {
|
|
|
111
112
|
private parseSampleRate;
|
|
112
113
|
private shouldLogSubSend;
|
|
113
114
|
private logSubSend;
|
|
115
|
+
private isAiPublication;
|
|
116
|
+
private logAiSubSend;
|
|
114
117
|
private connectDebug;
|
|
115
118
|
private parsePositiveFloat;
|
|
116
119
|
private isChangeStreamUnsupported;
|
|
@@ -151,6 +151,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
151
151
|
this._subSendLogThresholdMs = 0;
|
|
152
152
|
this._subSendLogBytes = 0;
|
|
153
153
|
this._subSendLogSampleRate = 1;
|
|
154
|
+
this._aiWorkerDebug = false;
|
|
154
155
|
this._oplogRetryCount = 0;
|
|
155
156
|
this._lastResumeToken = null;
|
|
156
157
|
this._lastResumeTokenSaveMs = 0;
|
|
@@ -237,6 +238,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
237
238
|
this._subSendLogThresholdMs = this.resolveSubSendLogThresholdMs();
|
|
238
239
|
this._subSendLogBytes = this.resolveSubSendLogBytes();
|
|
239
240
|
this._subSendLogSampleRate = this.resolveSubSendLogSampleRate();
|
|
241
|
+
this._aiWorkerDebug = this.parseDebugFlag(process.env.AI_ASSISTANT_WORKER_DEBUG);
|
|
240
242
|
this._oplogMode = this.resolveOplogMode();
|
|
241
243
|
this._localOplogResyncIntervalMs = this.resolveLocalOplogResyncIntervalMs();
|
|
242
244
|
this.registerCorePublications();
|
|
@@ -1355,6 +1357,31 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1355
1357
|
type: details.type
|
|
1356
1358
|
}));
|
|
1357
1359
|
};
|
|
1360
|
+
SubscriptionManager.prototype.isAiPublication = function (publication) {
|
|
1361
|
+
return publication === 'aiTerminalMessages' || publication === 'aiTerminalConversations';
|
|
1362
|
+
};
|
|
1363
|
+
SubscriptionManager.prototype.logAiSubSend = function (details) {
|
|
1364
|
+
var _a;
|
|
1365
|
+
if (!this._aiWorkerDebug) {
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
if (!this.isAiPublication(details.publication)) {
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
console.log(new Date(), '[AI Worker Debug] subSend', JSON.stringify({
|
|
1372
|
+
publication: details.publication,
|
|
1373
|
+
subscriptionKey: details.subscriptionKey,
|
|
1374
|
+
messageId: details.messageId,
|
|
1375
|
+
id_socket: details.id_socket,
|
|
1376
|
+
clients: details.clients,
|
|
1377
|
+
payloadBytes: details.payloadBytes,
|
|
1378
|
+
packed: details.packed,
|
|
1379
|
+
cacheHit: (_a = details.cacheHit) !== null && _a !== void 0 ? _a : false,
|
|
1380
|
+
collection: details.collection,
|
|
1381
|
+
type: details.type,
|
|
1382
|
+
subscriptionData: details.subscriptionData
|
|
1383
|
+
}));
|
|
1384
|
+
};
|
|
1358
1385
|
SubscriptionManager.prototype.connectDebug = function (message, details) {
|
|
1359
1386
|
if (!this._connectDebug) {
|
|
1360
1387
|
return;
|
|
@@ -2195,6 +2222,19 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2195
2222
|
console.log(new Date(), 'Process Sub, Cache (packed)', sub.publication);
|
|
2196
2223
|
}
|
|
2197
2224
|
this._websocketManager.sendPackedBuffer(ws, messageId, false, cachedBuffer, 'msgpack');
|
|
2225
|
+
this.logAiSubSend({
|
|
2226
|
+
publication: sub.publication,
|
|
2227
|
+
subscriptionKey: sub.subscriptionKey,
|
|
2228
|
+
messageId: messageId,
|
|
2229
|
+
id_socket: ws['id_socket'],
|
|
2230
|
+
clients: 1,
|
|
2231
|
+
payloadBytes: cachedBuffer.byteLength,
|
|
2232
|
+
packed: true,
|
|
2233
|
+
cacheHit: true,
|
|
2234
|
+
collection: '',
|
|
2235
|
+
type: 'cache',
|
|
2236
|
+
subscriptionData: sub.subscriptionData
|
|
2237
|
+
});
|
|
2198
2238
|
}
|
|
2199
2239
|
else {
|
|
2200
2240
|
cacheData = this.decodeCachePayload(cachedRaw);
|
|
@@ -2210,6 +2250,19 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2210
2250
|
console.log(new Date(), 'Process Sub, Cache', sub.publication);
|
|
2211
2251
|
}
|
|
2212
2252
|
this.sendWS(ws, serverRes);
|
|
2253
|
+
this.logAiSubSend({
|
|
2254
|
+
publication: sub.publication,
|
|
2255
|
+
subscriptionKey: sub.subscriptionKey,
|
|
2256
|
+
messageId: messageId,
|
|
2257
|
+
id_socket: ws['id_socket'],
|
|
2258
|
+
clients: 1,
|
|
2259
|
+
payloadBytes: cacheData ? Buffer.byteLength(JSON.stringify(cacheData)) : null,
|
|
2260
|
+
packed: false,
|
|
2261
|
+
cacheHit: true,
|
|
2262
|
+
collection: '',
|
|
2263
|
+
type: 'cache',
|
|
2264
|
+
subscriptionData: sub.subscriptionData
|
|
2265
|
+
});
|
|
2213
2266
|
}
|
|
2214
2267
|
return [3 /*break*/, 4];
|
|
2215
2268
|
case 2:
|
|
@@ -2251,25 +2304,27 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2251
2304
|
};
|
|
2252
2305
|
SubscriptionManager.prototype.sendDataToOne = function (ws, messageId, sub, collection, type) {
|
|
2253
2306
|
return __awaiter(this, void 0, void 0, function () {
|
|
2254
|
-
var monitor, dependencySnapshot, res, execution, serverRes, err_1, _a, normalizedError, correlationId, serverRes, errorPayload;
|
|
2255
|
-
var _b;
|
|
2256
|
-
return __generator(this, function (
|
|
2257
|
-
switch (
|
|
2307
|
+
var monitor, dependencySnapshot, res, execution, packedRes, payloadBytes, serverRes, err_1, _a, normalizedError, correlationId, serverRes, errorPayload;
|
|
2308
|
+
var _b, _c;
|
|
2309
|
+
return __generator(this, function (_d) {
|
|
2310
|
+
switch (_d.label) {
|
|
2258
2311
|
case 0:
|
|
2259
2312
|
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
2260
2313
|
return [2 /*return*/];
|
|
2261
2314
|
}
|
|
2262
2315
|
monitor = this._monitorManagerFunction.startMonitorFunction('User Specific Publication', sub.publication, '', '', sub.subscriptionData);
|
|
2263
|
-
|
|
2316
|
+
_d.label = 1;
|
|
2264
2317
|
case 1:
|
|
2265
|
-
|
|
2318
|
+
_d.trys.push([1, 3, 5, 7]);
|
|
2266
2319
|
resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethod.call(resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager(), 'insertSubscriptionLog', type, sub.publication, collection, JSON.stringify(sub.subscriptionData));
|
|
2267
2320
|
return [4 /*yield*/, this.runPublicationExecution(sub, ws['id_user'])];
|
|
2268
2321
|
case 2:
|
|
2269
|
-
execution =
|
|
2322
|
+
execution = _d.sent();
|
|
2270
2323
|
res = execution.result;
|
|
2271
2324
|
dependencySnapshot = execution.snapshot;
|
|
2272
2325
|
this.updateSubscriptionDependencies(sub, dependencySnapshot);
|
|
2326
|
+
packedRes = (_b = execution.packedResult) !== null && _b !== void 0 ? _b : this.packCachePayload(res);
|
|
2327
|
+
payloadBytes = packedRes ? packedRes.byteLength : null;
|
|
2273
2328
|
if (execution.packedResult) {
|
|
2274
2329
|
this._websocketManager.sendPackedBuffer(ws, messageId, false, execution.packedResult, execution.encoding || 'msgpack', { passThrough: !!execution.workerUsed });
|
|
2275
2330
|
}
|
|
@@ -2281,9 +2336,22 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2281
2336
|
};
|
|
2282
2337
|
this.sendWS(ws, serverRes);
|
|
2283
2338
|
}
|
|
2339
|
+
this.logAiSubSend({
|
|
2340
|
+
publication: sub.publication,
|
|
2341
|
+
subscriptionKey: sub.subscriptionKey,
|
|
2342
|
+
messageId: messageId,
|
|
2343
|
+
id_socket: ws['id_socket'],
|
|
2344
|
+
clients: 1,
|
|
2345
|
+
payloadBytes: payloadBytes,
|
|
2346
|
+
packed: !!execution.packedResult,
|
|
2347
|
+
cacheHit: false,
|
|
2348
|
+
collection: collection,
|
|
2349
|
+
type: type,
|
|
2350
|
+
subscriptionData: sub.subscriptionData
|
|
2351
|
+
});
|
|
2284
2352
|
return [3 /*break*/, 7];
|
|
2285
2353
|
case 3:
|
|
2286
|
-
err_1 =
|
|
2354
|
+
err_1 = _d.sent();
|
|
2287
2355
|
_a = (0, error_tracking_1.ensureErrorWithCorrelation)(err_1), normalizedError = _a.error, correlationId = _a.correlationId;
|
|
2288
2356
|
serverRes = {
|
|
2289
2357
|
messageId: messageId,
|
|
@@ -2309,7 +2377,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2309
2377
|
return [4 /*yield*/, error_reporter_1.ErrorReporter.report({
|
|
2310
2378
|
sourceApp: 'subscription-manager',
|
|
2311
2379
|
message: 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'],
|
|
2312
|
-
environment: (
|
|
2380
|
+
environment: (_c = this.serverConfig) === null || _c === void 0 ? void 0 : _c.ROOT_URL,
|
|
2313
2381
|
clientSlug: resolveio_server_app_1.ResolveIOServer.getClientName(),
|
|
2314
2382
|
clientName: this.serverConfig['CLIENT_NAME'],
|
|
2315
2383
|
stack: normalizedError === null || normalizedError === void 0 ? void 0 : normalizedError.stack,
|
|
@@ -2322,11 +2390,11 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2322
2390
|
correlationId: correlationId
|
|
2323
2391
|
})];
|
|
2324
2392
|
case 4:
|
|
2325
|
-
|
|
2393
|
+
_d.sent();
|
|
2326
2394
|
return [3 /*break*/, 7];
|
|
2327
2395
|
case 5: return [4 /*yield*/, this._monitorManagerFunction.finishMonitorFunction(monitor)];
|
|
2328
2396
|
case 6:
|
|
2329
|
-
|
|
2397
|
+
_d.sent();
|
|
2330
2398
|
return [7 /*endfinally*/];
|
|
2331
2399
|
case 7: return [2 /*return*/];
|
|
2332
2400
|
}
|
|
@@ -2336,7 +2404,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2336
2404
|
// Fetch pub once, send to all clients linked to this pub
|
|
2337
2405
|
SubscriptionManager.prototype.sendDataToAll = function (sub, collection, type) {
|
|
2338
2406
|
return __awaiter(this, void 0, void 0, function () {
|
|
2339
|
-
var activeClients, _a, _b, client, ws, subIndex, monitor, res, dependencySnapshot, execution, packedRes, passThrough, payloadBytes, shouldCache, cachedBuffer, isSame, sendStartMs, sentClients, activeClients_1, activeClients_1_1, entry, client, ws, serverRes, sendStartMs, sentClients, activeClients_2, activeClients_2_1, entry, client, ws, serverRes, nodeCacheSize, deleteCount, subArr, zz, err_2, _c, normalizedError, correlationId, _d, _e, client, ws, serverRes, errorPayload;
|
|
2407
|
+
var activeClients, _a, _b, client, ws, subIndex, monitor, res, dependencySnapshot, execution, packedRes, passThrough, payloadBytes, shouldCache, isAiPublication, cachedBuffer, isSame, sendStartMs, sentClients, activeClients_1, activeClients_1_1, entry, client, ws, serverRes, sendStartMs, sentClients, activeClients_2, activeClients_2_1, entry, client, ws, serverRes, nodeCacheSize, deleteCount, subArr, zz, err_2, _c, normalizedError, correlationId, _d, _e, client, ws, serverRes, errorPayload;
|
|
2340
2408
|
var e_6, _f, e_7, _g, e_8, _h, e_9, _j;
|
|
2341
2409
|
var _k, _l;
|
|
2342
2410
|
return __generator(this, function (_m) {
|
|
@@ -2394,6 +2462,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2394
2462
|
passThrough = !!execution.workerUsed;
|
|
2395
2463
|
payloadBytes = packedRes ? packedRes.byteLength : null;
|
|
2396
2464
|
shouldCache = this.shouldCachePayload(sub, packedRes);
|
|
2465
|
+
isAiPublication = this.isAiPublication(sub.publication);
|
|
2397
2466
|
if (sub.cacheId) {
|
|
2398
2467
|
cachedBuffer = this.getCacheBuffer(this._nodeCache.get(sub.cacheId));
|
|
2399
2468
|
isSame = this.buffersEqual(cachedBuffer, packedRes);
|
|
@@ -2415,6 +2484,21 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2415
2484
|
};
|
|
2416
2485
|
this.sendWS(ws, serverRes);
|
|
2417
2486
|
}
|
|
2487
|
+
if (isAiPublication) {
|
|
2488
|
+
this.logAiSubSend({
|
|
2489
|
+
publication: sub.publication,
|
|
2490
|
+
subscriptionKey: sub.subscriptionKey,
|
|
2491
|
+
messageId: client.messageId,
|
|
2492
|
+
id_socket: ws['id_socket'],
|
|
2493
|
+
clients: activeClients.length,
|
|
2494
|
+
payloadBytes: payloadBytes,
|
|
2495
|
+
packed: !!packedRes,
|
|
2496
|
+
cacheHit: false,
|
|
2497
|
+
collection: collection,
|
|
2498
|
+
type: type,
|
|
2499
|
+
subscriptionData: sub.subscriptionData
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2418
2502
|
sentClients += 1;
|
|
2419
2503
|
}
|
|
2420
2504
|
}
|
|
@@ -2466,6 +2550,21 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2466
2550
|
};
|
|
2467
2551
|
this.sendWS(ws, serverRes);
|
|
2468
2552
|
}
|
|
2553
|
+
if (isAiPublication) {
|
|
2554
|
+
this.logAiSubSend({
|
|
2555
|
+
publication: sub.publication,
|
|
2556
|
+
subscriptionKey: sub.subscriptionKey,
|
|
2557
|
+
messageId: client.messageId,
|
|
2558
|
+
id_socket: ws['id_socket'],
|
|
2559
|
+
clients: activeClients.length,
|
|
2560
|
+
payloadBytes: payloadBytes,
|
|
2561
|
+
packed: !!packedRes,
|
|
2562
|
+
cacheHit: false,
|
|
2563
|
+
collection: collection,
|
|
2564
|
+
type: type,
|
|
2565
|
+
subscriptionData: sub.subscriptionData
|
|
2566
|
+
});
|
|
2567
|
+
}
|
|
2469
2568
|
sentClients += 1;
|
|
2470
2569
|
}
|
|
2471
2570
|
}
|