@resolveio/server-lib 22.0.24 → 22.1.0
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/methods/ai-terminal.d.ts +50 -0
- package/methods/ai-terminal.js +3223 -805
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +6 -2
- package/server-app.js +266 -250
- package/server-app.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@resolveio/server-lib",
|
|
3
|
-
"version": "22.0
|
|
3
|
+
"version": "22.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"package": "./build_package.sh",
|
|
@@ -10,8 +10,12 @@
|
|
|
10
10
|
"build-prod": "node_modules/gulp/bin/gulp.js build-prod",
|
|
11
11
|
"dependency-test": "node --require ts-node/register tests/subscription-dependency-context.test.ts",
|
|
12
12
|
"subscription-invalidation-test": "node --require ts-node/register tests/subscription-manager-invalidation.test.ts",
|
|
13
|
+
"subscription-connect-race-test": "node --require ts-node/register tests/subscription-connect-race.test.ts",
|
|
13
14
|
"error-reporter-test": "node --require ts-node/register tests/error-reporter.test.ts",
|
|
14
|
-
"ai-assistant-utils-test": "node --require ts-node/register tests/ai-assistant-utils.test.ts"
|
|
15
|
+
"ai-assistant-utils-test": "node --require ts-node/register tests/ai-assistant-utils.test.ts",
|
|
16
|
+
"ai-assistant-routing-eval-test": "node --require ts-node/register tests/ai-assistant-routing-eval.test.ts",
|
|
17
|
+
"ai-assistant-snf-live-eval": "node --require ts-node/register tests/ai-assistant-snf-live-eval.ts",
|
|
18
|
+
"ai-assistant-openai-e2e": "node --require ts-node/register tests/ai-assistant-openai-e2e.ts"
|
|
15
19
|
},
|
|
16
20
|
"author": "",
|
|
17
21
|
"license": "ISC",
|
package/server-app.js
CHANGED
|
@@ -808,268 +808,284 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
808
808
|
this._serverHTTP.listen(this._portHTTP, host, function () {
|
|
809
809
|
console.log('Running HTTP/WS server on port %s', _this._portHTTP);
|
|
810
810
|
});
|
|
811
|
-
this._serverWSS.on('connection', function (ws, req) {
|
|
812
|
-
var workerId_1, workerIndex, workerInstance, rootUrl, requestUrl, workerIndexForLog, workerInstanceForLog, interval_1, lastComm_1, missedPongs_1, heartbeatIntervalMs, maxMissedPongs_1, maxSilenceMs_1;
|
|
813
|
-
var _this = this;
|
|
811
|
+
this._serverWSS.on('connection', function (ws, req) {
|
|
814
812
|
var _a, _b;
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
813
|
+
if (req.url && req.url.includes('workerToken=')) {
|
|
814
|
+
// It's a WORKER
|
|
815
|
+
var workerId_1 = (0, common_1.objectIdHexString)();
|
|
816
|
+
ws['id_worker'] = workerId_1;
|
|
817
|
+
var workerIndex = null;
|
|
818
|
+
var workerInstance = null;
|
|
819
|
+
ws['supportsBinary'] = true;
|
|
820
|
+
if (req.url) {
|
|
821
|
+
var rootUrl = resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] || 'http://localhost';
|
|
822
|
+
try {
|
|
823
|
+
var requestUrl = new url_1.URL(req.url, rootUrl);
|
|
824
|
+
workerIndex = requestUrl.searchParams.get('workerIndex');
|
|
825
|
+
workerInstance = requestUrl.searchParams.get('workerInstance');
|
|
826
|
+
}
|
|
827
|
+
catch (_c) {
|
|
821
828
|
workerIndex = null;
|
|
822
829
|
workerInstance = null;
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (!workerIndex && req['workerIndex']) {
|
|
833
|
+
workerIndex = req['workerIndex'];
|
|
834
|
+
}
|
|
835
|
+
if (!workerInstance && req['workerInstance']) {
|
|
836
|
+
workerInstance = req['workerInstance'];
|
|
837
|
+
}
|
|
838
|
+
if (workerIndex !== null && workerIndex !== undefined) {
|
|
839
|
+
ws['workerIndex'] = workerIndex;
|
|
840
|
+
}
|
|
841
|
+
if (workerInstance !== null && workerInstance !== undefined) {
|
|
842
|
+
ws['workerInstance'] = workerInstance;
|
|
843
|
+
}
|
|
844
|
+
var workerIndexForLog = ws['workerIndex'] || 'UNKNOWN';
|
|
845
|
+
var workerInstanceForLog = ws['workerInstance'] || 'UNKNOWN';
|
|
846
|
+
console.log(new Date(), 'Worker Connected', workerIndexForLog, workerInstanceForLog);
|
|
847
|
+
_this._workerDispatcherManager.addWorker(ws);
|
|
848
|
+
var interval_1 = null;
|
|
849
|
+
var lastComm_1 = new Date();
|
|
850
|
+
var missedPongs_1 = 0;
|
|
851
|
+
var heartbeatIntervalMs = 30000;
|
|
852
|
+
var maxMissedPongs_1 = 2;
|
|
853
|
+
var maxSilenceMs_1 = heartbeatIntervalMs * (maxMissedPongs_1 + 1);
|
|
854
|
+
_this._workerDispatcherManager.sendWorkerPayload(ws, 'ping');
|
|
855
|
+
interval_1 = setInterval(function () {
|
|
856
|
+
var now = Date.now();
|
|
857
|
+
var last = lastComm_1 ? lastComm_1.getTime() : 0;
|
|
858
|
+
var silenceMs = last ? now - last : maxSilenceMs_1 + 1;
|
|
859
|
+
if (silenceMs > maxSilenceMs_1 || missedPongs_1 > maxMissedPongs_1) {
|
|
860
|
+
_this._workerDispatcherManager.disconnectWorker(ws['id_worker']);
|
|
861
|
+
ws.close();
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
missedPongs_1 += 1;
|
|
865
|
+
_this._workerDispatcherManager.sendWorkerPayload(ws, 'ping');
|
|
866
|
+
}, heartbeatIntervalMs);
|
|
867
|
+
ws.on('message', function (message) {
|
|
868
|
+
lastComm_1 = new Date();
|
|
869
|
+
if (typeof message === 'string') {
|
|
870
|
+
if (message === 'ping') {
|
|
871
|
+
_this._workerDispatcherManager.sendWorkerPayload(ws, 'pong');
|
|
835
872
|
}
|
|
836
|
-
if (
|
|
837
|
-
|
|
873
|
+
else if (message === 'pong') {
|
|
874
|
+
missedPongs_1 = 0;
|
|
838
875
|
}
|
|
839
|
-
|
|
840
|
-
|
|
876
|
+
else {
|
|
877
|
+
_this._workerDispatcherManager.handleWorkerMessage(ws['id_worker'], message);
|
|
841
878
|
}
|
|
842
|
-
|
|
843
|
-
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
var buffer;
|
|
882
|
+
if (Buffer.isBuffer(message)) {
|
|
883
|
+
buffer = message;
|
|
884
|
+
}
|
|
885
|
+
else if (Array.isArray(message)) {
|
|
886
|
+
var chunks = message;
|
|
887
|
+
buffer = Buffer.concat(chunks);
|
|
888
|
+
}
|
|
889
|
+
else if (message instanceof ArrayBuffer) {
|
|
890
|
+
buffer = Buffer.from(message);
|
|
891
|
+
}
|
|
892
|
+
else if (ArrayBuffer.isView(message)) {
|
|
893
|
+
var view = message;
|
|
894
|
+
buffer = Buffer.from(view.buffer, view.byteOffset, view.byteLength);
|
|
895
|
+
}
|
|
896
|
+
else {
|
|
897
|
+
buffer = Buffer.from(message);
|
|
898
|
+
}
|
|
899
|
+
if (buffer.length === 4) {
|
|
900
|
+
var heartbeat = buffer.toString('utf8');
|
|
901
|
+
if (heartbeat === 'ping') {
|
|
902
|
+
_this._workerDispatcherManager.sendWorkerPayload(ws, 'pong');
|
|
903
|
+
return;
|
|
844
904
|
}
|
|
845
|
-
if (
|
|
846
|
-
|
|
905
|
+
else if (heartbeat === 'pong') {
|
|
906
|
+
missedPongs_1 = 0;
|
|
907
|
+
return;
|
|
847
908
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
909
|
+
}
|
|
910
|
+
_this._workerDispatcherManager.handleWorkerMessage(ws['id_worker'], buffer);
|
|
911
|
+
});
|
|
912
|
+
ws.on('close', function () {
|
|
913
|
+
_this._workerDispatcherManager.disconnectWorker(ws['id_worker']);
|
|
914
|
+
console.log(new Date(), 'Worker disconnected:', workerId_1);
|
|
915
|
+
if (interval_1) {
|
|
916
|
+
clearInterval(interval_1);
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
ws.on('error', function (error) {
|
|
920
|
+
_this._workerDispatcherManager.disconnectWorker(ws['id_worker']);
|
|
921
|
+
console.error('Error on WS Worker', error);
|
|
922
|
+
ws.close();
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
else {
|
|
926
|
+
// Normal client
|
|
927
|
+
ws['id_socket'] = (0, common_1.objectIdHexString)();
|
|
928
|
+
ws['supportsBinary'] = true;
|
|
929
|
+
ws['id_user'] = req['id_user'];
|
|
930
|
+
ws['user'] = req['user'];
|
|
931
|
+
ws['user_readonly'] = req['user_readonly'];
|
|
932
|
+
ws['doc_user'] = req['doc_user'];
|
|
933
|
+
_this._websocketManager.addWebSocket(ws);
|
|
934
|
+
_this.logConnectDebug('WS client connected', {
|
|
935
|
+
id_socket: ws['id_socket'],
|
|
936
|
+
id_user: ws['id_user'],
|
|
937
|
+
user: ws['user'],
|
|
938
|
+
url: req === null || req === void 0 ? void 0 : req.url,
|
|
939
|
+
ip: (_a = req === null || req === void 0 ? void 0 : req.socket) === null || _a === void 0 ? void 0 : _a.remoteAddress,
|
|
940
|
+
origin: (_b = req === null || req === void 0 ? void 0 : req.headers) === null || _b === void 0 ? void 0 : _b.origin
|
|
941
|
+
});
|
|
942
|
+
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
943
|
+
return __generator(this, function (_a) {
|
|
944
|
+
switch (_a.label) {
|
|
945
|
+
case 0: return [4 /*yield*/, this.triggerClientHeartbeat(ws)];
|
|
946
|
+
case 1:
|
|
947
|
+
_a.sent();
|
|
948
|
+
return [2 /*return*/];
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
}); }, _this._clientHeartbeatInitialDelayMs);
|
|
952
|
+
if (_this.LOGGER === 'DEBUG') {
|
|
953
|
+
console.log('Connection from user: ' + req['user']);
|
|
954
|
+
}
|
|
955
|
+
ws['isAlive'] = true;
|
|
956
|
+
ws['retryCnt'] = 0;
|
|
957
|
+
ws.on('pong', function () {
|
|
958
|
+
ws['isAlive'] = true;
|
|
959
|
+
ws['pongTime'] = new Date();
|
|
960
|
+
if (ws['pingTime']) {
|
|
961
|
+
ws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();
|
|
962
|
+
_this._subscriptionManager.loggedInLatency(ws);
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
966
|
+
var socketData, usedBinary, bufferPayload, decodeResult, decodeResult, decodeResult, view, decodeResult, e_1, correlationId, context;
|
|
967
|
+
return __generator(this, function (_a) {
|
|
968
|
+
switch (_a.label) {
|
|
969
|
+
case 0:
|
|
970
|
+
this._debugMsgRecv += 1;
|
|
971
|
+
socketData = [];
|
|
972
|
+
usedBinary = false;
|
|
973
|
+
_a.label = 1;
|
|
974
|
+
case 1:
|
|
975
|
+
_a.trys.push([1, 2, , 4]);
|
|
976
|
+
if (typeof message === 'string') {
|
|
977
|
+
if (message === 'ping' || message === 'pong') {
|
|
978
|
+
socketData = message;
|
|
979
|
+
}
|
|
980
|
+
else {
|
|
981
|
+
socketData = JSON.parse(message, common_1.dateReviver);
|
|
982
|
+
}
|
|
879
983
|
}
|
|
880
|
-
else {
|
|
881
|
-
|
|
984
|
+
else if (Buffer.isBuffer(message)) {
|
|
985
|
+
bufferPayload = message;
|
|
986
|
+
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
987
|
+
socketData = decodeResult.data;
|
|
988
|
+
usedBinary = decodeResult.usedBinary;
|
|
882
989
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
}
|
|
889
|
-
else if (Array.isArray(message)) {
|
|
890
|
-
var chunks = message;
|
|
891
|
-
buffer = Buffer.concat(chunks);
|
|
892
|
-
}
|
|
893
|
-
else if (message instanceof ArrayBuffer) {
|
|
894
|
-
buffer = Buffer.from(message);
|
|
895
|
-
}
|
|
896
|
-
else if (ArrayBuffer.isView(message)) {
|
|
897
|
-
var view = message;
|
|
898
|
-
buffer = Buffer.from(view.buffer, view.byteOffset, view.byteLength);
|
|
899
|
-
}
|
|
900
|
-
else {
|
|
901
|
-
buffer = Buffer.from(message);
|
|
902
|
-
}
|
|
903
|
-
if (buffer.length === 4) {
|
|
904
|
-
var heartbeat = buffer.toString('utf8');
|
|
905
|
-
if (heartbeat === 'ping') {
|
|
906
|
-
_this._workerDispatcherManager.sendWorkerPayload(ws, 'pong');
|
|
907
|
-
return;
|
|
990
|
+
else if (Array.isArray(message)) {
|
|
991
|
+
bufferPayload = Buffer.concat(message);
|
|
992
|
+
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
993
|
+
socketData = decodeResult.data;
|
|
994
|
+
usedBinary = decodeResult.usedBinary;
|
|
908
995
|
}
|
|
909
|
-
else if (
|
|
910
|
-
|
|
911
|
-
|
|
996
|
+
else if (message instanceof ArrayBuffer) {
|
|
997
|
+
bufferPayload = Buffer.from(message);
|
|
998
|
+
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
999
|
+
socketData = decodeResult.data;
|
|
1000
|
+
usedBinary = decodeResult.usedBinary;
|
|
912
1001
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
if (interval_1) {
|
|
920
|
-
clearInterval(interval_1);
|
|
921
|
-
}
|
|
922
|
-
});
|
|
923
|
-
ws.on('error', function (error) {
|
|
924
|
-
_this._workerDispatcherManager.disconnectWorker(ws['id_worker']);
|
|
925
|
-
console.error('Error on WS Worker', error);
|
|
926
|
-
ws.close();
|
|
927
|
-
});
|
|
928
|
-
return [3 /*break*/, 3];
|
|
929
|
-
case 1:
|
|
930
|
-
// Normal client
|
|
931
|
-
ws['id_socket'] = (0, common_1.objectIdHexString)();
|
|
932
|
-
ws['supportsBinary'] = true;
|
|
933
|
-
ws['id_user'] = req['id_user'];
|
|
934
|
-
ws['user'] = req['user'];
|
|
935
|
-
ws['user_readonly'] = req['user_readonly'];
|
|
936
|
-
ws['doc_user'] = req['doc_user'];
|
|
937
|
-
this._websocketManager.addWebSocket(ws);
|
|
938
|
-
this.logConnectDebug('WS client connected', {
|
|
939
|
-
id_socket: ws['id_socket'],
|
|
940
|
-
id_user: ws['id_user'],
|
|
941
|
-
user: ws['user'],
|
|
942
|
-
url: req === null || req === void 0 ? void 0 : req.url,
|
|
943
|
-
ip: (_a = req === null || req === void 0 ? void 0 : req.socket) === null || _a === void 0 ? void 0 : _a.remoteAddress,
|
|
944
|
-
origin: (_b = req === null || req === void 0 ? void 0 : req.headers) === null || _b === void 0 ? void 0 : _b.origin
|
|
945
|
-
});
|
|
946
|
-
return [4 /*yield*/, this._subscriptionManager.createLoggedInUser(ws['id_socket'])];
|
|
947
|
-
case 2:
|
|
948
|
-
_c.sent();
|
|
949
|
-
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
950
|
-
return __generator(this, function (_a) {
|
|
951
|
-
switch (_a.label) {
|
|
952
|
-
case 0: return [4 /*yield*/, this.triggerClientHeartbeat(ws)];
|
|
953
|
-
case 1:
|
|
954
|
-
_a.sent();
|
|
955
|
-
return [2 /*return*/];
|
|
1002
|
+
else if (ArrayBuffer.isView(message)) {
|
|
1003
|
+
view = message;
|
|
1004
|
+
bufferPayload = Buffer.from(view.buffer, view.byteOffset, view.byteLength);
|
|
1005
|
+
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
1006
|
+
socketData = decodeResult.data;
|
|
1007
|
+
usedBinary = decodeResult.usedBinary;
|
|
956
1008
|
}
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
if (this.LOGGER === 'DEBUG') {
|
|
960
|
-
console.log('Connection from user: ' + req['user']);
|
|
961
|
-
}
|
|
962
|
-
ws['isAlive'] = true;
|
|
963
|
-
ws['retryCnt'] = 0;
|
|
964
|
-
ws.on('pong', function () {
|
|
965
|
-
ws['isAlive'] = true;
|
|
966
|
-
ws['pongTime'] = new Date();
|
|
967
|
-
if (ws['pingTime']) {
|
|
968
|
-
ws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();
|
|
969
|
-
_this._subscriptionManager.loggedInLatency(ws);
|
|
970
|
-
}
|
|
971
|
-
});
|
|
972
|
-
ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
973
|
-
var socketData, usedBinary, bufferPayload, decodeResult, decodeResult, decodeResult, view, decodeResult, e_1, correlationId, context;
|
|
974
|
-
return __generator(this, function (_a) {
|
|
975
|
-
switch (_a.label) {
|
|
976
|
-
case 0:
|
|
977
|
-
this._debugMsgRecv += 1;
|
|
978
|
-
socketData = [];
|
|
979
|
-
usedBinary = false;
|
|
980
|
-
_a.label = 1;
|
|
981
|
-
case 1:
|
|
982
|
-
_a.trys.push([1, 2, , 4]);
|
|
983
|
-
if (typeof message === 'string') {
|
|
984
|
-
if (message === 'ping' || message === 'pong') {
|
|
985
|
-
socketData = message;
|
|
986
|
-
}
|
|
987
|
-
else {
|
|
988
|
-
socketData = JSON.parse(message, common_1.dateReviver);
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
else if (Buffer.isBuffer(message)) {
|
|
992
|
-
bufferPayload = message;
|
|
993
|
-
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
994
|
-
socketData = decodeResult.data;
|
|
995
|
-
usedBinary = decodeResult.usedBinary;
|
|
996
|
-
}
|
|
997
|
-
else if (Array.isArray(message)) {
|
|
998
|
-
bufferPayload = Buffer.concat(message);
|
|
999
|
-
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
1000
|
-
socketData = decodeResult.data;
|
|
1001
|
-
usedBinary = decodeResult.usedBinary;
|
|
1002
|
-
}
|
|
1003
|
-
else if (message instanceof ArrayBuffer) {
|
|
1004
|
-
bufferPayload = Buffer.from(message);
|
|
1005
|
-
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
1006
|
-
socketData = decodeResult.data;
|
|
1007
|
-
usedBinary = decodeResult.usedBinary;
|
|
1008
|
-
}
|
|
1009
|
-
else if (ArrayBuffer.isView(message)) {
|
|
1010
|
-
view = message;
|
|
1011
|
-
bufferPayload = Buffer.from(view.buffer, view.byteOffset, view.byteLength);
|
|
1012
|
-
decodeResult = this.decodeBufferPayload(bufferPayload);
|
|
1013
|
-
socketData = decodeResult.data;
|
|
1014
|
-
usedBinary = decodeResult.usedBinary;
|
|
1015
|
-
}
|
|
1016
|
-
else {
|
|
1017
|
-
throw new Error('Unsupported WebSocket message type: ' + typeof message);
|
|
1018
|
-
}
|
|
1019
|
-
return [3 /*break*/, 4];
|
|
1020
|
-
case 2:
|
|
1021
|
-
e_1 = _a.sent();
|
|
1022
|
-
console.log('Error - WS message parse', e_1);
|
|
1023
|
-
correlationId = (0, common_1.objectIdHexString)();
|
|
1024
|
-
context = {
|
|
1025
|
-
rawBinary: bufferPayload ? bufferPayload.toString('base64') : undefined,
|
|
1026
|
-
rawMessage: typeof message === 'string' ? message : undefined,
|
|
1027
|
-
error: e_1 instanceof Error ? { name: e_1.name, message: e_1.message, stack: e_1.stack } : e_1
|
|
1028
|
-
};
|
|
1029
|
-
return [4 /*yield*/, this.reportServerError('SERVER - JSON Parse Error - ' + resolveio_server_app_1.ResolveIOServer.getServerConfig()['CLIENT_NAME'], correlationId, context, { context: 'websocket-message-parse' }, 'error', e_1 instanceof Error ? e_1.stack : undefined)];
|
|
1030
|
-
case 3:
|
|
1031
|
-
_a.sent();
|
|
1032
|
-
return [2 /*return*/];
|
|
1033
|
-
case 4:
|
|
1034
|
-
if (usedBinary) {
|
|
1035
|
-
ws['supportsBinary'] = true;
|
|
1036
|
-
}
|
|
1037
|
-
// call our existing processSocketMessage
|
|
1038
|
-
return [4 /*yield*/, this.processSocketMessage(ws, socketData)];
|
|
1039
|
-
case 5:
|
|
1040
|
-
// call our existing processSocketMessage
|
|
1041
|
-
_a.sent();
|
|
1042
|
-
return [2 /*return*/];
|
|
1009
|
+
else {
|
|
1010
|
+
throw new Error('Unsupported WebSocket message type: ' + typeof message);
|
|
1043
1011
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
return [4 /*yield*/, this.unsubscribeWS(ws)];
|
|
1062
|
-
case 1:
|
|
1063
|
-
_a.sent();
|
|
1064
|
-
return [2 /*return*/];
|
|
1012
|
+
return [3 /*break*/, 4];
|
|
1013
|
+
case 2:
|
|
1014
|
+
e_1 = _a.sent();
|
|
1015
|
+
console.log('Error - WS message parse', e_1);
|
|
1016
|
+
correlationId = (0, common_1.objectIdHexString)();
|
|
1017
|
+
context = {
|
|
1018
|
+
rawBinary: bufferPayload ? bufferPayload.toString('base64') : undefined,
|
|
1019
|
+
rawMessage: typeof message === 'string' ? message : undefined,
|
|
1020
|
+
error: e_1 instanceof Error ? { name: e_1.name, message: e_1.message, stack: e_1.stack } : e_1
|
|
1021
|
+
};
|
|
1022
|
+
return [4 /*yield*/, this.reportServerError('SERVER - JSON Parse Error - ' + resolveio_server_app_1.ResolveIOServer.getServerConfig()['CLIENT_NAME'], correlationId, context, { context: 'websocket-message-parse' }, 'error', e_1 instanceof Error ? e_1.stack : undefined)];
|
|
1023
|
+
case 3:
|
|
1024
|
+
_a.sent();
|
|
1025
|
+
return [2 /*return*/];
|
|
1026
|
+
case 4:
|
|
1027
|
+
if (usedBinary) {
|
|
1028
|
+
ws['supportsBinary'] = true;
|
|
1065
1029
|
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1030
|
+
// call our existing processSocketMessage
|
|
1031
|
+
return [4 /*yield*/, this.processSocketMessage(ws, socketData)];
|
|
1032
|
+
case 5:
|
|
1033
|
+
// call our existing processSocketMessage
|
|
1034
|
+
_a.sent();
|
|
1035
|
+
return [2 /*return*/];
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
}); })
|
|
1039
|
+
.on('end', function () {
|
|
1040
|
+
ws.close();
|
|
1041
|
+
})
|
|
1042
|
+
.on('error', function () {
|
|
1043
|
+
ws.close();
|
|
1044
|
+
})
|
|
1045
|
+
.on('close', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1046
|
+
return __generator(this, function (_a) {
|
|
1047
|
+
switch (_a.label) {
|
|
1048
|
+
case 0:
|
|
1049
|
+
this.logConnectDebug('WS client closed', {
|
|
1050
|
+
id_socket: ws['id_socket'],
|
|
1051
|
+
id_user: ws['id_user'],
|
|
1052
|
+
user: ws['user']
|
|
1053
|
+
});
|
|
1054
|
+
return [4 /*yield*/, this.unsubscribeWS(ws)];
|
|
1055
|
+
case 1:
|
|
1056
|
+
_a.sent();
|
|
1057
|
+
return [2 /*return*/];
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
}); });
|
|
1061
|
+
// Do not block message handler registration on DB write; this avoids losing
|
|
1062
|
+
// very-early subscription messages sent immediately after websocket open.
|
|
1063
|
+
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1064
|
+
var error_4;
|
|
1065
|
+
return __generator(this, function (_a) {
|
|
1066
|
+
switch (_a.label) {
|
|
1067
|
+
case 0:
|
|
1068
|
+
_a.trys.push([0, 2, , 3]);
|
|
1069
|
+
return [4 /*yield*/, this._subscriptionManager.createLoggedInUser(ws['id_socket'])];
|
|
1070
|
+
case 1:
|
|
1071
|
+
_a.sent();
|
|
1072
|
+
return [3 /*break*/, 3];
|
|
1073
|
+
case 2:
|
|
1074
|
+
error_4 = _a.sent();
|
|
1075
|
+
console.error(new Date(), 'Error creating logged-in user', ws['id_socket'], error_4);
|
|
1076
|
+
this.logConnectDebug('Create logged-in user failed', {
|
|
1077
|
+
id_socket: ws['id_socket'],
|
|
1078
|
+
id_user: ws['id_user'],
|
|
1079
|
+
user: ws['user'],
|
|
1080
|
+
error: (error_4 === null || error_4 === void 0 ? void 0 : error_4.message) || error_4
|
|
1081
|
+
});
|
|
1082
|
+
return [3 /*break*/, 3];
|
|
1083
|
+
case 3: return [2 /*return*/];
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
}); }, 0);
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1073
1089
|
// Keep alive timer
|
|
1074
1090
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1075
1091
|
var _a, _b, ws, e_2_1;
|
|
@@ -1937,7 +1953,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1937
1953
|
});
|
|
1938
1954
|
}
|
|
1939
1955
|
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1940
|
-
var
|
|
1956
|
+
var error_5;
|
|
1941
1957
|
return __generator(this, function (_a) {
|
|
1942
1958
|
switch (_a.label) {
|
|
1943
1959
|
case 0:
|
|
@@ -1947,8 +1963,8 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1947
1963
|
_a.sent();
|
|
1948
1964
|
return [3 /*break*/, 3];
|
|
1949
1965
|
case 2:
|
|
1950
|
-
|
|
1951
|
-
console.error(new Date(), 'aiCoderTerminalRunCodex failed:',
|
|
1966
|
+
error_5 = _a.sent();
|
|
1967
|
+
console.error(new Date(), 'aiCoderTerminalRunCodex failed:', error_5);
|
|
1952
1968
|
return [3 /*break*/, 3];
|
|
1953
1969
|
case 3: return [2 /*return*/];
|
|
1954
1970
|
}
|