@resolveio/server-lib 22.1.17 → 22.1.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "22.1.17",
3
+ "version": "22.1.18",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "package": "./build_package.sh",
package/server-app.d.ts CHANGED
@@ -58,9 +58,12 @@ export declare class ResolveIOMainServer {
58
58
  private _isWorkersEnabled;
59
59
  private _isWorkerInstance;
60
60
  private _safeShutdown;
61
+ private _dynamicAppGatewayEnabled;
62
+ private _dynamicAppGatewayCache;
61
63
  private readonly _clientHeartbeatIntervalMs;
62
64
  private readonly _clientHeartbeatInitialDelayMs;
63
65
  private readonly _clientHeartbeatBackpressureBytes;
66
+ private readonly _dynamicAppGatewayCacheMs;
64
67
  constructor();
65
68
  static create(): Promise<ResolveIOMainServer>;
66
69
  private initialize;
@@ -68,6 +71,18 @@ export declare class ResolveIOMainServer {
68
71
  private closeHttpServerGracefully;
69
72
  private closeWebSocketServerGracefully;
70
73
  private startServerInstance;
74
+ private installDynamicAppGatewayMiddleware;
75
+ private resolveDynamicAppGatewayEnabled;
76
+ private extractDynamicAppGatewayId;
77
+ private resolveDynamicAppGatewayToken;
78
+ private normalizeHeaderValue;
79
+ private normalizeHostname;
80
+ private resolveOriginHostname;
81
+ private isLocalHostname;
82
+ private resolveDynamicAppControlHosts;
83
+ private resolveDynamicAppAllowedHosts;
84
+ private applyDynamicAppGatewayCorsHeaders;
85
+ private resolveCachedDynamicAppGatewayApp;
71
86
  private safeShutdown;
72
87
  getIsWorkersEnabled(): boolean;
73
88
  getIsWorkerInstance(): boolean;
package/server-app.js CHANGED
@@ -76,6 +76,7 @@ exports.ResolveIOMainServer = void 0;
76
76
  var express = require("express");
77
77
  var xmlParser = require("express-xml-bodyparser");
78
78
  var http_1 = require("http");
79
+ var crypto = require("crypto");
79
80
  var fs = require("fs");
80
81
  var jwt = require("jsonwebtoken");
81
82
  var moment = require("moment-timezone");
@@ -142,9 +143,12 @@ var ResolveIOMainServer = /** @class */ (function () {
142
143
  this._isWorkersEnabled = false;
143
144
  this._isWorkerInstance = false;
144
145
  this._safeShutdown = false;
146
+ this._dynamicAppGatewayEnabled = false;
147
+ this._dynamicAppGatewayCache = new Map();
145
148
  this._clientHeartbeatIntervalMs = 20000;
146
149
  this._clientHeartbeatInitialDelayMs = 5000;
147
150
  this._clientHeartbeatBackpressureBytes = 5 * 1024 * 1024;
151
+ this._dynamicAppGatewayCacheMs = 30 * 1000;
148
152
  }
149
153
  ResolveIOMainServer.create = function () {
150
154
  return __awaiter(this, void 0, void 0, function () {
@@ -184,6 +188,7 @@ var ResolveIOMainServer = /** @class */ (function () {
184
188
  this._timerDebugSampleRate = this.resolveTimerDebugSampleRate();
185
189
  this._timerDebugLogLimit = this.resolveTimerDebugLogLimit();
186
190
  this._aiWorkerDebug = this.parseDebugFlag(process.env.AI_ASSISTANT_WORKER_DEBUG);
191
+ this._dynamicAppGatewayEnabled = this.resolveDynamicAppGatewayEnabled();
187
192
  _a = this;
188
193
  return [4 /*yield*/, monitor_manager_1.MonitorManager.create()];
189
194
  case 1:
@@ -566,6 +571,7 @@ var ResolveIOMainServer = /** @class */ (function () {
566
571
  if (this.LOGGER === 'DEBUG') {
567
572
  console.log('Setup cors');
568
573
  }
574
+ this.installDynamicAppGatewayMiddleware();
569
575
  // Set up http login route
570
576
  (0, auth_1.setupAuthRoutes)(this, this._app, resolveio_server_app_1.ResolveIOServer.getServerConfig());
571
577
  (0, health_1.setupHealthRoutes)(this._app);
@@ -577,6 +583,377 @@ var ResolveIOMainServer = /** @class */ (function () {
577
583
  console.log('Setup express routes');
578
584
  }
579
585
  };
586
+ ResolveIOMainServer.prototype.installDynamicAppGatewayMiddleware = function () {
587
+ var _this = this;
588
+ if (!this._dynamicAppGatewayEnabled) {
589
+ return;
590
+ }
591
+ this._app.use(function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
592
+ var appId, appDoc, allowedHosts, controlHosts, requestHost, originHeader, originHost, expectedToken, providedToken, error_4;
593
+ var _a, _b, _c;
594
+ return __generator(this, function (_d) {
595
+ switch (_d.label) {
596
+ case 0:
597
+ appId = this.extractDynamicAppGatewayId(req);
598
+ if (!appId) {
599
+ next();
600
+ return [2 /*return*/];
601
+ }
602
+ _d.label = 1;
603
+ case 1:
604
+ _d.trys.push([1, 3, , 4]);
605
+ return [4 /*yield*/, this.resolveCachedDynamicAppGatewayApp(appId)];
606
+ case 2:
607
+ appDoc = _d.sent();
608
+ if (!appDoc) {
609
+ res.status(404).send(JSON.stringify({
610
+ error: true,
611
+ result: 'App not found.'
612
+ }));
613
+ return [2 /*return*/];
614
+ }
615
+ allowedHosts = this.resolveDynamicAppAllowedHosts(appDoc);
616
+ controlHosts = this.resolveDynamicAppControlHosts();
617
+ requestHost = this.normalizeHostname(this.normalizeHeaderValue((_a = req.headers) === null || _a === void 0 ? void 0 : _a['x-forwarded-host'])
618
+ || this.normalizeHeaderValue((_b = req.headers) === null || _b === void 0 ? void 0 : _b.host));
619
+ originHeader = this.normalizeHeaderValue((_c = req.headers) === null || _c === void 0 ? void 0 : _c.origin);
620
+ originHost = this.resolveOriginHostname(originHeader);
621
+ if (requestHost && controlHosts.has(requestHost) && !this.isLocalHostname(requestHost)) {
622
+ res.status(403).send(JSON.stringify({
623
+ error: true,
624
+ result: 'App API must be requested from an app domain.'
625
+ }));
626
+ return [2 /*return*/];
627
+ }
628
+ if (requestHost && !allowedHosts.has(requestHost) && !this.isLocalHostname(requestHost)) {
629
+ res.status(403).send(JSON.stringify({
630
+ error: true,
631
+ result: 'Host not allowed for app API.'
632
+ }));
633
+ return [2 /*return*/];
634
+ }
635
+ if (originHost && controlHosts.has(originHost) && !this.isLocalHostname(originHost)) {
636
+ res.status(403).send(JSON.stringify({
637
+ error: true,
638
+ result: 'App API origin must be an app domain.'
639
+ }));
640
+ return [2 /*return*/];
641
+ }
642
+ if (originHost && !allowedHosts.has(originHost)) {
643
+ res.status(403).send(JSON.stringify({
644
+ error: true,
645
+ result: 'Origin not allowed for app API.'
646
+ }));
647
+ return [2 /*return*/];
648
+ }
649
+ if (originHeader) {
650
+ this.applyDynamicAppGatewayCorsHeaders(res, originHeader);
651
+ }
652
+ if (req.method === 'OPTIONS') {
653
+ res.status(204).end();
654
+ return [2 /*return*/];
655
+ }
656
+ expectedToken = this.normalizeHeaderValue(appDoc === null || appDoc === void 0 ? void 0 : appDoc.rio_token);
657
+ if (!expectedToken) {
658
+ res.status(500).send(JSON.stringify({
659
+ error: true,
660
+ result: 'App token is not configured.'
661
+ }));
662
+ return [2 /*return*/];
663
+ }
664
+ providedToken = this.resolveDynamicAppGatewayToken(req);
665
+ if (!providedToken || providedToken !== expectedToken) {
666
+ res.status(401).send(JSON.stringify({
667
+ error: true,
668
+ result: 'Invalid or missing RIO token.'
669
+ }));
670
+ return [2 /*return*/];
671
+ }
672
+ next();
673
+ return [3 /*break*/, 4];
674
+ case 3:
675
+ error_4 = _d.sent();
676
+ console.error(new Date(), '[DynamicAppGateway] middleware failure', error_4);
677
+ res.status(500).send(JSON.stringify({
678
+ error: true,
679
+ result: (error_4 === null || error_4 === void 0 ? void 0 : error_4.message) || 'Dynamic app gateway error.'
680
+ }));
681
+ return [3 /*break*/, 4];
682
+ case 4: return [2 /*return*/];
683
+ }
684
+ });
685
+ }); });
686
+ };
687
+ ResolveIOMainServer.prototype.resolveDynamicAppGatewayEnabled = function () {
688
+ var _a;
689
+ var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
690
+ var raw = (_a = config['AI_CODER_DYNAMIC_APP_GATEWAY']) !== null && _a !== void 0 ? _a : process.env.AI_CODER_DYNAMIC_APP_GATEWAY;
691
+ if (raw !== undefined && raw !== null && "".concat(raw).trim() !== '') {
692
+ return this.parseDebugFlag(raw);
693
+ }
694
+ var urls = [
695
+ config['ROOT_URL'],
696
+ config['SEC_ROOT_URL'],
697
+ config['SERVER_URL'],
698
+ process.env.ROOT_URL,
699
+ process.env.SEC_ROOT_URL,
700
+ process.env.SERVER_URL
701
+ ]
702
+ .map(function (value) { return "".concat(value || '').trim().toLowerCase(); })
703
+ .filter(Boolean);
704
+ return urls.some(function (value) { return value.includes('aicoder'); });
705
+ };
706
+ ResolveIOMainServer.prototype.extractDynamicAppGatewayId = function (req) {
707
+ var rawPath = "".concat(req.originalUrl || req.url || req.path || '');
708
+ var normalizedPath = rawPath.split('?')[0];
709
+ if (!normalizedPath.startsWith('/api/apps/')) {
710
+ return '';
711
+ }
712
+ var parts = normalizedPath.split('/').filter(Boolean);
713
+ if (parts.length < 3) {
714
+ return '';
715
+ }
716
+ return "".concat(parts[2] || '').trim();
717
+ };
718
+ ResolveIOMainServer.prototype.resolveDynamicAppGatewayToken = function (req) {
719
+ var e_1, _a, e_2, _b, e_3, _c;
720
+ var _d, _e, _f, _g, _h;
721
+ var authHeader = this.normalizeHeaderValue(((_d = req.headers) === null || _d === void 0 ? void 0 : _d.authorization) || ((_e = req.headers) === null || _e === void 0 ? void 0 : _e.Authorization));
722
+ if (authHeader) {
723
+ var bearerMatch = authHeader.match(/^bearer\s+(.+)$/i);
724
+ if (bearerMatch && bearerMatch[1]) {
725
+ return bearerMatch[1].trim();
726
+ }
727
+ }
728
+ var headerCandidates = [
729
+ (_f = req.headers) === null || _f === void 0 ? void 0 : _f['x-rio-token'],
730
+ (_g = req.headers) === null || _g === void 0 ? void 0 : _g['x-app-token'],
731
+ (_h = req.headers) === null || _h === void 0 ? void 0 : _h['x-api-key']
732
+ ];
733
+ try {
734
+ for (var headerCandidates_1 = __values(headerCandidates), headerCandidates_1_1 = headerCandidates_1.next(); !headerCandidates_1_1.done; headerCandidates_1_1 = headerCandidates_1.next()) {
735
+ var candidate = headerCandidates_1_1.value;
736
+ var value = this.normalizeHeaderValue(candidate);
737
+ if (value) {
738
+ return value;
739
+ }
740
+ }
741
+ }
742
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
743
+ finally {
744
+ try {
745
+ if (headerCandidates_1_1 && !headerCandidates_1_1.done && (_a = headerCandidates_1.return)) _a.call(headerCandidates_1);
746
+ }
747
+ finally { if (e_1) throw e_1.error; }
748
+ }
749
+ var body = req.body || {};
750
+ var query = req.query || {};
751
+ var bodyCandidates = [body.rioToken, body.rio_token, body.apiKey, body.token];
752
+ try {
753
+ for (var bodyCandidates_1 = __values(bodyCandidates), bodyCandidates_1_1 = bodyCandidates_1.next(); !bodyCandidates_1_1.done; bodyCandidates_1_1 = bodyCandidates_1.next()) {
754
+ var candidate = bodyCandidates_1_1.value;
755
+ var value = this.normalizeHeaderValue(candidate);
756
+ if (value) {
757
+ return value;
758
+ }
759
+ }
760
+ }
761
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
762
+ finally {
763
+ try {
764
+ if (bodyCandidates_1_1 && !bodyCandidates_1_1.done && (_b = bodyCandidates_1.return)) _b.call(bodyCandidates_1);
765
+ }
766
+ finally { if (e_2) throw e_2.error; }
767
+ }
768
+ var queryCandidates = [query.rioToken, query.rio_token, query.apiKey, query.token];
769
+ try {
770
+ for (var queryCandidates_1 = __values(queryCandidates), queryCandidates_1_1 = queryCandidates_1.next(); !queryCandidates_1_1.done; queryCandidates_1_1 = queryCandidates_1.next()) {
771
+ var candidate = queryCandidates_1_1.value;
772
+ var value = this.normalizeHeaderValue(candidate);
773
+ if (value) {
774
+ return value;
775
+ }
776
+ }
777
+ }
778
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
779
+ finally {
780
+ try {
781
+ if (queryCandidates_1_1 && !queryCandidates_1_1.done && (_c = queryCandidates_1.return)) _c.call(queryCandidates_1);
782
+ }
783
+ finally { if (e_3) throw e_3.error; }
784
+ }
785
+ return '';
786
+ };
787
+ ResolveIOMainServer.prototype.normalizeHeaderValue = function (value) {
788
+ if (Array.isArray(value)) {
789
+ return value.map(function (entry) { return "".concat(entry || '').trim(); }).filter(Boolean).join(',');
790
+ }
791
+ return "".concat(value || '').trim();
792
+ };
793
+ ResolveIOMainServer.prototype.normalizeHostname = function (value) {
794
+ var raw = "".concat(value || '').trim();
795
+ if (!raw) {
796
+ return '';
797
+ }
798
+ var candidate = raw.split(',')[0].trim();
799
+ if (!candidate) {
800
+ return '';
801
+ }
802
+ try {
803
+ if (candidate.startsWith('http://') || candidate.startsWith('https://')) {
804
+ return new url_1.URL(candidate).hostname.toLowerCase();
805
+ }
806
+ if (candidate.includes('/')) {
807
+ return new url_1.URL("http://".concat(candidate)).hostname.toLowerCase();
808
+ }
809
+ }
810
+ catch (_a) { }
811
+ candidate = candidate.replace(/^\[/, '').replace(/\]$/, '');
812
+ var lastColon = candidate.lastIndexOf(':');
813
+ if (lastColon > -1 && candidate.indexOf(':') === lastColon) {
814
+ candidate = candidate.slice(0, lastColon);
815
+ }
816
+ return candidate.toLowerCase();
817
+ };
818
+ ResolveIOMainServer.prototype.resolveOriginHostname = function (origin) {
819
+ var raw = "".concat(origin || '').trim();
820
+ if (!raw) {
821
+ return '';
822
+ }
823
+ try {
824
+ return new url_1.URL(raw).hostname.toLowerCase();
825
+ }
826
+ catch (_a) {
827
+ return this.normalizeHostname(raw);
828
+ }
829
+ };
830
+ ResolveIOMainServer.prototype.isLocalHostname = function (hostname) {
831
+ var normalized = this.normalizeHostname(hostname);
832
+ return normalized === 'localhost' || normalized === '127.0.0.1' || normalized === '::1';
833
+ };
834
+ ResolveIOMainServer.prototype.resolveDynamicAppControlHosts = function () {
835
+ var e_4, _a;
836
+ var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
837
+ var hosts = new Set();
838
+ var candidates = [
839
+ config['ROOT_URL'],
840
+ config['SEC_ROOT_URL'],
841
+ config['SERVER_URL'],
842
+ process.env.ROOT_URL,
843
+ process.env.SEC_ROOT_URL,
844
+ process.env.SERVER_URL,
845
+ process.env.AI_CODER_ROOT_URL,
846
+ process.env.AI_CODER_SEC_ROOT_URL,
847
+ process.env.AI_CODER_SERVER_URL
848
+ ];
849
+ try {
850
+ for (var candidates_1 = __values(candidates), candidates_1_1 = candidates_1.next(); !candidates_1_1.done; candidates_1_1 = candidates_1.next()) {
851
+ var candidate = candidates_1_1.value;
852
+ var normalized = this.normalizeHostname("".concat(candidate || ''));
853
+ if (normalized) {
854
+ hosts.add(normalized);
855
+ }
856
+ }
857
+ }
858
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
859
+ finally {
860
+ try {
861
+ if (candidates_1_1 && !candidates_1_1.done && (_a = candidates_1.return)) _a.call(candidates_1);
862
+ }
863
+ finally { if (e_4) throw e_4.error; }
864
+ }
865
+ return hosts;
866
+ };
867
+ ResolveIOMainServer.prototype.resolveDynamicAppAllowedHosts = function (appDoc) {
868
+ var e_5, _a;
869
+ var hosts = new Set();
870
+ var candidates = [
871
+ appDoc === null || appDoc === void 0 ? void 0 : appDoc.domain,
872
+ appDoc === null || appDoc === void 0 ? void 0 : appDoc.backend_domain
873
+ ];
874
+ if ((appDoc === null || appDoc === void 0 ? void 0 : appDoc.subdomain) && (appDoc === null || appDoc === void 0 ? void 0 : appDoc.domain_base)) {
875
+ candidates.push("".concat(appDoc.subdomain, ".").concat(appDoc.domain_base));
876
+ }
877
+ try {
878
+ for (var candidates_2 = __values(candidates), candidates_2_1 = candidates_2.next(); !candidates_2_1.done; candidates_2_1 = candidates_2.next()) {
879
+ var candidate = candidates_2_1.value;
880
+ var normalized = this.normalizeHostname("".concat(candidate || ''));
881
+ if (normalized) {
882
+ hosts.add(normalized);
883
+ }
884
+ }
885
+ }
886
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
887
+ finally {
888
+ try {
889
+ if (candidates_2_1 && !candidates_2_1.done && (_a = candidates_2.return)) _a.call(candidates_2);
890
+ }
891
+ finally { if (e_5) throw e_5.error; }
892
+ }
893
+ return hosts;
894
+ };
895
+ ResolveIOMainServer.prototype.applyDynamicAppGatewayCorsHeaders = function (res, origin) {
896
+ res.setHeader('Access-Control-Allow-Origin', origin);
897
+ res.setHeader('Vary', 'Origin');
898
+ res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS');
899
+ res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Rio-Token, X-API-Key');
900
+ res.setHeader('Access-Control-Allow-Credentials', 'true');
901
+ res.setHeader('Access-Control-Max-Age', '600');
902
+ };
903
+ ResolveIOMainServer.prototype.resolveCachedDynamicAppGatewayApp = function (appId) {
904
+ return __awaiter(this, void 0, void 0, function () {
905
+ var now, cached, db, appCollection, appDoc, generated;
906
+ return __generator(this, function (_a) {
907
+ switch (_a.label) {
908
+ case 0:
909
+ now = Date.now();
910
+ cached = this._dynamicAppGatewayCache.get(appId);
911
+ if (cached && cached.expiresAt > now) {
912
+ return [2 /*return*/, cached.app];
913
+ }
914
+ db = resolveio_server_app_1.ResolveIOServer.getMainDB();
915
+ if (!db) {
916
+ return [2 /*return*/, null];
917
+ }
918
+ appCollection = db.collection('ai-coder-apps');
919
+ return [4 /*yield*/, appCollection.findOne({ _id: appId }, {
920
+ projection: {
921
+ _id: 1,
922
+ domain: 1,
923
+ backend_domain: 1,
924
+ subdomain: 1,
925
+ domain_base: 1,
926
+ rio_token: 1
927
+ }
928
+ })];
929
+ case 1:
930
+ appDoc = _a.sent();
931
+ if (!appDoc) {
932
+ this._dynamicAppGatewayCache.delete(appId);
933
+ return [2 /*return*/, null];
934
+ }
935
+ if (!!this.normalizeHeaderValue(appDoc.rio_token)) return [3 /*break*/, 3];
936
+ generated = crypto.randomBytes(32).toString('hex');
937
+ return [4 /*yield*/, appCollection.updateOne({ _id: appId }, {
938
+ $set: {
939
+ rio_token: generated,
940
+ updatedAt: new Date()
941
+ }
942
+ })];
943
+ case 2:
944
+ _a.sent();
945
+ appDoc.rio_token = generated;
946
+ _a.label = 3;
947
+ case 3:
948
+ this._dynamicAppGatewayCache.set(appId, {
949
+ expiresAt: now + this._dynamicAppGatewayCacheMs,
950
+ app: appDoc
951
+ });
952
+ return [2 /*return*/, appDoc];
953
+ }
954
+ });
955
+ });
956
+ };
580
957
  ResolveIOMainServer.prototype.safeShutdown = function () {
581
958
  return __awaiter(this, void 0, void 0, function () {
582
959
  var _a;
@@ -963,7 +1340,7 @@ var ResolveIOMainServer = /** @class */ (function () {
963
1340
  }
964
1341
  });
965
1342
  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;
1343
+ var socketData, usedBinary, bufferPayload, decodeResult, decodeResult, decodeResult, view, decodeResult, e_6, correlationId, context;
967
1344
  return __generator(this, function (_a) {
968
1345
  switch (_a.label) {
969
1346
  case 0:
@@ -1011,15 +1388,15 @@ var ResolveIOMainServer = /** @class */ (function () {
1011
1388
  }
1012
1389
  return [3 /*break*/, 4];
1013
1390
  case 2:
1014
- e_1 = _a.sent();
1015
- console.log('Error - WS message parse', e_1);
1391
+ e_6 = _a.sent();
1392
+ console.log('Error - WS message parse', e_6);
1016
1393
  correlationId = (0, common_1.objectIdHexString)();
1017
1394
  context = {
1018
1395
  rawBinary: bufferPayload ? bufferPayload.toString('base64') : undefined,
1019
1396
  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
1397
+ error: e_6 instanceof Error ? { name: e_6.name, message: e_6.message, stack: e_6.stack } : e_6
1021
1398
  };
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)];
1399
+ 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_6 instanceof Error ? e_6.stack : undefined)];
1023
1400
  case 3:
1024
1401
  _a.sent();
1025
1402
  return [2 /*return*/];
@@ -1061,7 +1438,7 @@ var ResolveIOMainServer = /** @class */ (function () {
1061
1438
  // Do not block message handler registration on DB write; this avoids losing
1062
1439
  // very-early subscription messages sent immediately after websocket open.
1063
1440
  setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
1064
- var error_4;
1441
+ var error_5;
1065
1442
  return __generator(this, function (_a) {
1066
1443
  switch (_a.label) {
1067
1444
  case 0:
@@ -1071,13 +1448,13 @@ var ResolveIOMainServer = /** @class */ (function () {
1071
1448
  _a.sent();
1072
1449
  return [3 /*break*/, 3];
1073
1450
  case 2:
1074
- error_4 = _a.sent();
1075
- console.error(new Date(), 'Error creating logged-in user', ws['id_socket'], error_4);
1451
+ error_5 = _a.sent();
1452
+ console.error(new Date(), 'Error creating logged-in user', ws['id_socket'], error_5);
1076
1453
  this.logConnectDebug('Create logged-in user failed', {
1077
1454
  id_socket: ws['id_socket'],
1078
1455
  id_user: ws['id_user'],
1079
1456
  user: ws['user'],
1080
- error: (error_4 === null || error_4 === void 0 ? void 0 : error_4.message) || error_4
1457
+ error: (error_5 === null || error_5 === void 0 ? void 0 : error_5.message) || error_5
1081
1458
  });
1082
1459
  return [3 /*break*/, 3];
1083
1460
  case 3: return [2 /*return*/];
@@ -1088,8 +1465,8 @@ var ResolveIOMainServer = /** @class */ (function () {
1088
1465
  });
1089
1466
  // Keep alive timer
1090
1467
  setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
1091
- var _a, _b, ws, e_2_1;
1092
- var e_2, _c;
1468
+ var _a, _b, ws, e_7_1;
1469
+ var e_7, _c;
1093
1470
  return __generator(this, function (_d) {
1094
1471
  switch (_d.label) {
1095
1472
  case 0:
@@ -1130,14 +1507,14 @@ var ResolveIOMainServer = /** @class */ (function () {
1130
1507
  return [3 /*break*/, 1];
1131
1508
  case 9: return [3 /*break*/, 12];
1132
1509
  case 10:
1133
- e_2_1 = _d.sent();
1134
- e_2 = { error: e_2_1 };
1510
+ e_7_1 = _d.sent();
1511
+ e_7 = { error: e_7_1 };
1135
1512
  return [3 /*break*/, 12];
1136
1513
  case 11:
1137
1514
  try {
1138
1515
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1139
1516
  }
1140
- finally { if (e_2) throw e_2.error; }
1517
+ finally { if (e_7) throw e_7.error; }
1141
1518
  return [7 /*endfinally*/];
1142
1519
  case 12: return [2 /*return*/];
1143
1520
  }
@@ -1146,8 +1523,8 @@ var ResolveIOMainServer = /** @class */ (function () {
1146
1523
  };
1147
1524
  ResolveIOMainServer.prototype.processSocketMessage = function (ws, socketData) {
1148
1525
  return __awaiter(this, void 0, void 0, function () {
1149
- var socketData_1, socketData_1_1, message, e_3_1;
1150
- var e_3, _a;
1526
+ var socketData_1, socketData_1_1, message, e_8_1;
1527
+ var e_8, _a;
1151
1528
  return __generator(this, function (_b) {
1152
1529
  switch (_b.label) {
1153
1530
  case 0:
@@ -1191,14 +1568,14 @@ var ResolveIOMainServer = /** @class */ (function () {
1191
1568
  return [3 /*break*/, 2];
1192
1569
  case 5: return [3 /*break*/, 8];
1193
1570
  case 6:
1194
- e_3_1 = _b.sent();
1195
- e_3 = { error: e_3_1 };
1571
+ e_8_1 = _b.sent();
1572
+ e_8 = { error: e_8_1 };
1196
1573
  return [3 /*break*/, 8];
1197
1574
  case 7:
1198
1575
  try {
1199
1576
  if (socketData_1_1 && !socketData_1_1.done && (_a = socketData_1.return)) _a.call(socketData_1);
1200
1577
  }
1201
- finally { if (e_3) throw e_3.error; }
1578
+ finally { if (e_8) throw e_8.error; }
1202
1579
  return [7 /*endfinally*/];
1203
1580
  case 8: return [2 /*return*/];
1204
1581
  }
@@ -1953,7 +2330,7 @@ var ResolveIOMainServer = /** @class */ (function () {
1953
2330
  });
1954
2331
  }
1955
2332
  setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
1956
- var error_5;
2333
+ var error_6;
1957
2334
  return __generator(this, function (_a) {
1958
2335
  switch (_a.label) {
1959
2336
  case 0:
@@ -1963,8 +2340,8 @@ var ResolveIOMainServer = /** @class */ (function () {
1963
2340
  _a.sent();
1964
2341
  return [3 /*break*/, 3];
1965
2342
  case 2:
1966
- error_5 = _a.sent();
1967
- console.error(new Date(), 'aiCoderTerminalRunCodex failed:', error_5);
2343
+ error_6 = _a.sent();
2344
+ console.error(new Date(), 'aiCoderTerminalRunCodex failed:', error_6);
1968
2345
  return [3 /*break*/, 3];
1969
2346
  case 3: return [2 /*return*/];
1970
2347
  }