langmart-gateway-type3 3.0.49 → 3.0.51

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.
@@ -29,6 +29,11 @@ export declare class Type3GatewayServer extends EventEmitter {
29
29
  private reconnectDelay;
30
30
  private isShuttingDown;
31
31
  private headlessSessionManager;
32
+ private apiKeyExpiresAt;
33
+ private keyRenewalCheckInterval;
34
+ private readonly KEY_RENEWAL_CHECK_INTERVAL;
35
+ private readonly KEY_RENEWAL_THRESHOLD;
36
+ private isRenewingKey;
32
37
  private readonly gatewayMode;
33
38
  private readonly enableRemoteLLMSession;
34
39
  private readonly enableLLMRouting;
@@ -177,6 +182,26 @@ export declare class Type3GatewayServer extends EventEmitter {
177
182
  * Checks connection every 30s and triggers proper reconnection if disconnected
178
183
  */
179
184
  private startHealthMonitoring;
185
+ /**
186
+ * Start API key renewal monitoring
187
+ * Checks every 30 minutes if the API key is expiring within 1 hour
188
+ * and automatically renews it
189
+ */
190
+ private startKeyRenewalMonitoring;
191
+ /**
192
+ * Check if API key needs renewal and renew if necessary
193
+ */
194
+ private checkAndRenewApiKey;
195
+ /**
196
+ * Fetch API key info from Type 1 gateway
197
+ * This gets the current expiration time for the API key
198
+ */
199
+ private fetchApiKeyInfo;
200
+ /**
201
+ * Renew the API key by calling the renew-key endpoint
202
+ * This extends the expiration time without reissuing a new key
203
+ */
204
+ private renewApiKey;
180
205
  /**
181
206
  * Handle registry disconnection with robust retry logic
182
207
  * This method schedules reconnection attempts with exponential backoff
@@ -1 +1 @@
1
- {"version":3,"file":"gateway-server.d.ts","sourceRoot":"","sources":["../gateway-server.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAsC7C,qBAAa,kBAAmB,SAAQ,YAAY;IAChD,OAAO,CAAC,GAAG,CAAiC;IAC5C,OAAO,CAAC,UAAU,CA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W,oBAAoB;IA4ClC;;;OAGG;YACW,6BAA6B;IA0D3C;;OAEG;YACW,mBAAmB;IAwBjC;;OAEG;YACW,cAAc;IAkB5B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAYxB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAkBzB;;;;;;;;OAQG;YACW,mBAAmB;IAgOjC;;OAEG;IACH,OAAO,CAAC,eAAe;IAiBvB;;;;;;OAMG;YACW,qBAAqB;IA6CnC;;;OAGG;YACW,eAAe;IAoB7B;;;OAGG;YACW,iBAAiB;IAmP/B;;;OAGG;IACH,OAAO,CAAC,cAAc;IAgBtB;;OAEG;IACU,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;CA8CjD"}
@@ -53,6 +53,12 @@ class Type3GatewayServer extends events_1.EventEmitter {
53
53
  this.reconnectDelay = 15000; // 15 seconds
54
54
  this.isShuttingDown = false;
55
55
  this.headlessSessionManager = null; // For remote automation sessions
56
+ // API Key expiration tracking and auto-renewal
57
+ this.apiKeyExpiresAt = null; // Expiration time of the current API key
58
+ this.keyRenewalCheckInterval = null; // Timer for checking key expiration
59
+ this.KEY_RENEWAL_CHECK_INTERVAL = 30 * 60 * 1000; // Check every 30 minutes
60
+ this.KEY_RENEWAL_THRESHOLD = 60 * 60 * 1000; // Renew if expiring within 1 hour
61
+ this.isRenewingKey = false; // Prevent concurrent renewal attempts
56
62
  this.port = config.port;
57
63
  this.registryUrl = config.registryUrl || 'wss://control.registry.ai';
58
64
  this.registryApiUrl = config.registryUrl?.replace('wss://', 'https://').replace('control.', 'api.') || 'https://api.registry.ai';
@@ -144,7 +150,9 @@ class Type3GatewayServer extends events_1.EventEmitter {
144
150
  }
145
151
  // 5. Start health monitoring
146
152
  this.startHealthMonitoring();
147
- // 6. Register with registry (includes tool discovery)
153
+ // 6. Start API key renewal monitoring (for container keys)
154
+ this.startKeyRenewalMonitoring();
155
+ // 7. Register with registry (includes tool discovery)
148
156
  await this.registerGateway();
149
157
  console.log(`[${this.nodeId}] Type 3 Gateway ready and registered`);
150
158
  console.log(`[${this.nodeId}] Management API: http://localhost:${this.port}`);
@@ -412,7 +420,7 @@ class Type3GatewayServer extends events_1.EventEmitter {
412
420
  version: this.currentVersion,
413
421
  instance_id: this.instanceId,
414
422
  node_id: this.nodeId,
415
- gateway_id: this.nodeId,
423
+ gateway_id: this.gatewayId || this.instanceId,
416
424
  uptime_ms: uptime,
417
425
  uptime_human: this.formatUptime(uptime),
418
426
  registry_connected: isConnected,
@@ -1019,6 +1027,13 @@ class Type3GatewayServer extends events_1.EventEmitter {
1019
1027
  console.log(`[${this.nodeId}] Gateway Name from server: ${serverGatewayName}`);
1020
1028
  }
1021
1029
  }
1030
+ // Store API key expiration time from server (for container keys)
1031
+ const apiKeyExpiration = message.apiKeyExpiresAt || message.api_key_expires_at;
1032
+ if (apiKeyExpiration) {
1033
+ this.apiKeyExpiresAt = new Date(apiKeyExpiration);
1034
+ const hoursRemaining = ((this.apiKeyExpiresAt.getTime() - Date.now()) / (1000 * 60 * 60)).toFixed(2);
1035
+ console.log(`[${this.nodeId}] 📋 API key expires at: ${this.apiKeyExpiresAt.toISOString()} (${hoursRemaining} hours remaining)`);
1036
+ }
1022
1037
  break;
1023
1038
  case 'heartbeat':
1024
1039
  case 'health_check':
@@ -1627,6 +1642,130 @@ class Type3GatewayServer extends events_1.EventEmitter {
1627
1642
  }
1628
1643
  }, 30000);
1629
1644
  }
1645
+ /**
1646
+ * Start API key renewal monitoring
1647
+ * Checks every 30 minutes if the API key is expiring within 1 hour
1648
+ * and automatically renews it
1649
+ */
1650
+ startKeyRenewalMonitoring() {
1651
+ // Initial check after 1 minute (give time for auth to complete)
1652
+ setTimeout(() => {
1653
+ this.checkAndRenewApiKey();
1654
+ }, 60000);
1655
+ // Regular check every 30 minutes
1656
+ this.keyRenewalCheckInterval = setInterval(() => {
1657
+ this.checkAndRenewApiKey();
1658
+ }, this.KEY_RENEWAL_CHECK_INTERVAL);
1659
+ }
1660
+ /**
1661
+ * Check if API key needs renewal and renew if necessary
1662
+ */
1663
+ async checkAndRenewApiKey() {
1664
+ if (!this.apiKeyExpiresAt) {
1665
+ // First time - fetch key info from server
1666
+ await this.fetchApiKeyInfo();
1667
+ return;
1668
+ }
1669
+ const now = Date.now();
1670
+ const expiresAt = this.apiKeyExpiresAt.getTime();
1671
+ const timeUntilExpiry = expiresAt - now;
1672
+ if (timeUntilExpiry <= 0) {
1673
+ // Key has already expired!
1674
+ console.error(`[${this.nodeId}] ❌ TYPE 3 AUTH FAILED: API key has expired at ${this.apiKeyExpiresAt.toISOString()}`);
1675
+ console.error(`[${this.nodeId}] Container API key expired - will disconnect and require new container`);
1676
+ this.emit('api_key_expired', { expiredAt: this.apiKeyExpiresAt });
1677
+ // Trigger disconnection - the container needs to be restarted to get a new key
1678
+ this.handleRegistryDisconnection();
1679
+ return;
1680
+ }
1681
+ if (timeUntilExpiry <= this.KEY_RENEWAL_THRESHOLD) {
1682
+ // Key expiring within 1 hour - renew it
1683
+ const hoursRemaining = (timeUntilExpiry / (1000 * 60 * 60)).toFixed(2);
1684
+ console.log(`[${this.nodeId}] 🔄 API key expiring in ${hoursRemaining} hours - initiating renewal...`);
1685
+ await this.renewApiKey();
1686
+ }
1687
+ else {
1688
+ const hoursRemaining = (timeUntilExpiry / (1000 * 60 * 60)).toFixed(2);
1689
+ console.log(`[${this.nodeId}] ✅ API key valid for ${hoursRemaining} more hours`);
1690
+ }
1691
+ }
1692
+ /**
1693
+ * Fetch API key info from Type 1 gateway
1694
+ * This gets the current expiration time for the API key
1695
+ */
1696
+ async fetchApiKeyInfo() {
1697
+ if (!this.gatewayId || !this.apiKey) {
1698
+ return;
1699
+ }
1700
+ try {
1701
+ // Use the HTTP API to get key info
1702
+ const response = await axios_1.default.get(`${this.registryApiUrl}/api/user/gateways/${this.gatewayId}`, {
1703
+ headers: { 'Authorization': `Bearer ${this.apiKey}` },
1704
+ timeout: 10000
1705
+ });
1706
+ if (response.data?.apiKeyExpiresAt) {
1707
+ this.apiKeyExpiresAt = new Date(response.data.apiKeyExpiresAt);
1708
+ const hoursRemaining = ((this.apiKeyExpiresAt.getTime() - Date.now()) / (1000 * 60 * 60)).toFixed(2);
1709
+ console.log(`[${this.nodeId}] 📋 API key expires at: ${this.apiKeyExpiresAt.toISOString()} (${hoursRemaining} hours remaining)`);
1710
+ }
1711
+ }
1712
+ catch (error) {
1713
+ // If we get 401, the key is already invalid
1714
+ if (error.response?.status === 401) {
1715
+ console.error(`[${this.nodeId}] ❌ TYPE 3 AUTH FAILED: API key is invalid or expired`);
1716
+ console.error(`[${this.nodeId}] Error details:`, error.response?.data);
1717
+ this.emit('api_key_invalid');
1718
+ }
1719
+ else {
1720
+ console.warn(`[${this.nodeId}] Could not fetch API key info:`, error.message);
1721
+ }
1722
+ }
1723
+ }
1724
+ /**
1725
+ * Renew the API key by calling the renew-key endpoint
1726
+ * This extends the expiration time without reissuing a new key
1727
+ */
1728
+ async renewApiKey() {
1729
+ if (this.isRenewingKey) {
1730
+ console.log(`[${this.nodeId}] Key renewal already in progress, skipping`);
1731
+ return;
1732
+ }
1733
+ if (!this.gatewayId || !this.apiKey) {
1734
+ console.warn(`[${this.nodeId}] Cannot renew key - gateway ID or API key not available`);
1735
+ return;
1736
+ }
1737
+ this.isRenewingKey = true;
1738
+ try {
1739
+ const response = await axios_1.default.post(`${this.registryApiUrl}/api/user/gateways/${this.gatewayId}/renew-key`, {}, {
1740
+ headers: { 'Authorization': `Bearer ${this.apiKey}` },
1741
+ timeout: 10000
1742
+ });
1743
+ if (response.data?.success && response.data?.expiresAt) {
1744
+ this.apiKeyExpiresAt = new Date(response.data.expiresAt);
1745
+ console.log(`[${this.nodeId}] ✅ API key renewed successfully - new expiration: ${this.apiKeyExpiresAt.toISOString()}`);
1746
+ console.log(`[${this.nodeId}] Key valid for ${response.data.hoursUntilExpiration} more hours`);
1747
+ }
1748
+ else {
1749
+ console.warn(`[${this.nodeId}] Key renewal response missing expected fields:`, response.data);
1750
+ }
1751
+ }
1752
+ catch (error) {
1753
+ if (error.response?.status === 401) {
1754
+ console.error(`[${this.nodeId}] ❌ TYPE 3 AUTH FAILED: Cannot renew - API key is invalid or expired`);
1755
+ console.error(`[${this.nodeId}] Error details:`, error.response?.data);
1756
+ this.emit('api_key_invalid');
1757
+ // Trigger disconnection
1758
+ this.handleRegistryDisconnection();
1759
+ }
1760
+ else {
1761
+ console.error(`[${this.nodeId}] Failed to renew API key:`, error.message);
1762
+ // Will retry on next interval
1763
+ }
1764
+ }
1765
+ finally {
1766
+ this.isRenewingKey = false;
1767
+ }
1768
+ }
1630
1769
  /**
1631
1770
  * Handle registry disconnection with robust retry logic
1632
1771
  * This method schedules reconnection attempts with exponential backoff
@@ -2676,6 +2815,10 @@ class Type3GatewayServer extends events_1.EventEmitter {
2676
2815
  clearInterval(this.healthCheckInterval);
2677
2816
  this.healthCheckInterval = null;
2678
2817
  }
2818
+ if (this.keyRenewalCheckInterval) {
2819
+ clearInterval(this.keyRenewalCheckInterval);
2820
+ this.keyRenewalCheckInterval = null;
2821
+ }
2679
2822
  // Wait for active requests
2680
2823
  const maxWaitTime = 30000;
2681
2824
  const startTime = Date.now();