langmart-gateway-type3 3.0.7 → 3.0.9
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/gateway-config.d.ts +19 -8
- package/dist/gateway-config.d.ts.map +1 -1
- package/dist/gateway-config.js +66 -41
- package/dist/gateway-config.js.map +1 -1
- package/dist/gateway-server.d.ts +7 -0
- package/dist/gateway-server.d.ts.map +1 -1
- package/dist/gateway-server.js +99 -6
- package/dist/gateway-server.js.map +1 -1
- package/dist/mcp-manager.d.ts.map +1 -1
- package/dist/mcp-manager.js +1 -3
- package/dist/mcp-manager.js.map +1 -1
- package/package.json +4 -1
- package/scripts/start.ps1 +142 -0
- package/scripts/status.ps1 +211 -0
- package/scripts/stop.ps1 +108 -0
package/dist/gateway-config.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
export interface GatewayConfig {
|
|
2
|
-
gateway_id: string;
|
|
2
|
+
gateway_id: string | null;
|
|
3
|
+
gateway_name?: string | null;
|
|
3
4
|
instance_id: string;
|
|
4
5
|
created_at: string;
|
|
5
6
|
last_started_at: string;
|
|
7
|
+
server_assigned: boolean;
|
|
6
8
|
}
|
|
7
9
|
/**
|
|
8
10
|
* Gateway Configuration Manager
|
|
9
|
-
* Manages persistent gateway and instance IDs with
|
|
11
|
+
* Manages persistent gateway and instance IDs with server-assigned ID support
|
|
12
|
+
*
|
|
13
|
+
* Flow:
|
|
14
|
+
* 1. First connection: gateway_id = null, server assigns UUID
|
|
15
|
+
* 2. auth_confirmed message contains assigned gateway_id and gateway_name
|
|
16
|
+
* 3. Store received IDs locally for reconnections
|
|
17
|
+
* 4. Subsequent connections: send stored gateway_id
|
|
10
18
|
*/
|
|
11
19
|
export declare class GatewayConfigManager {
|
|
12
20
|
private configPath;
|
|
@@ -15,16 +23,19 @@ export declare class GatewayConfigManager {
|
|
|
15
23
|
/**
|
|
16
24
|
* Get or create gateway configuration
|
|
17
25
|
* If GATEWAY_ID env var is set, uses that (for Docker containers)
|
|
18
|
-
* If config exists, returns existing IDs
|
|
19
|
-
* If config doesn't exist,
|
|
26
|
+
* If config exists with gateway_id, returns existing IDs (reconnection)
|
|
27
|
+
* If config doesn't exist or has no gateway_id, returns null gateway_id (first connection)
|
|
20
28
|
*/
|
|
21
29
|
getOrCreateConfig(): GatewayConfig;
|
|
22
30
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Where NNNN is a 4-digit number seeded from timestamp
|
|
31
|
+
* Update configuration with server-assigned gateway_id and gateway_name
|
|
32
|
+
* Called when auth_confirmed message is received from Type 1 server
|
|
26
33
|
*/
|
|
27
|
-
|
|
34
|
+
updateServerAssignedId(gatewayId: string, gatewayName?: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Check if this is a first connection (no stored gateway_id)
|
|
37
|
+
*/
|
|
38
|
+
isFirstConnection(): boolean;
|
|
28
39
|
/**
|
|
29
40
|
* Load configuration from file
|
|
30
41
|
* Returns null if file doesn't exist or is invalid
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway-config.d.ts","sourceRoot":"","sources":["../gateway-config.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"gateway-config.d.ts","sourceRoot":"","sources":["../gateway-config.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;;;GASG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAA8B;gBAEhC,UAAU,CAAC,EAAE,MAAM;IAK/B;;;;;OAKG;IACI,iBAAiB,IAAI,aAAa;IAqDzC;;;OAGG;IACI,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAwB5E;;OAEG;IACI,iBAAiB,IAAI,OAAO;IAInC;;;OAGG;IACH,OAAO,CAAC,UAAU;IA6BlB;;OAEG;IACH,OAAO,CAAC,UAAU;IAelB;;;OAGG;IACI,SAAS,IAAI,aAAa,GAAG,IAAI;IAIxC;;OAEG;IACI,YAAY,IAAI,MAAM,GAAG,IAAI;IAIpC;;OAEG;IACI,aAAa,IAAI,MAAM,GAAG,IAAI;IAIrC;;;OAGG;IACI,WAAW,IAAI,IAAI;CAW3B"}
|
package/dist/gateway-config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// File: gateway-type3/gateway-config.ts
|
|
3
|
-
// Gateway configuration management with
|
|
3
|
+
// Gateway configuration management with server-assigned ID support
|
|
4
4
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
5
|
if (k2 === undefined) k2 = k;
|
|
6
6
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -40,7 +40,13 @@ const fs = __importStar(require("fs"));
|
|
|
40
40
|
const path = __importStar(require("path"));
|
|
41
41
|
/**
|
|
42
42
|
* Gateway Configuration Manager
|
|
43
|
-
* Manages persistent gateway and instance IDs with
|
|
43
|
+
* Manages persistent gateway and instance IDs with server-assigned ID support
|
|
44
|
+
*
|
|
45
|
+
* Flow:
|
|
46
|
+
* 1. First connection: gateway_id = null, server assigns UUID
|
|
47
|
+
* 2. auth_confirmed message contains assigned gateway_id and gateway_name
|
|
48
|
+
* 3. Store received IDs locally for reconnections
|
|
49
|
+
* 4. Subsequent connections: send stored gateway_id
|
|
44
50
|
*/
|
|
45
51
|
class GatewayConfigManager {
|
|
46
52
|
constructor(configPath) {
|
|
@@ -51,8 +57,8 @@ class GatewayConfigManager {
|
|
|
51
57
|
/**
|
|
52
58
|
* Get or create gateway configuration
|
|
53
59
|
* If GATEWAY_ID env var is set, uses that (for Docker containers)
|
|
54
|
-
* If config exists, returns existing IDs
|
|
55
|
-
* If config doesn't exist,
|
|
60
|
+
* If config exists with gateway_id, returns existing IDs (reconnection)
|
|
61
|
+
* If config doesn't exist or has no gateway_id, returns null gateway_id (first connection)
|
|
56
62
|
*/
|
|
57
63
|
getOrCreateConfig() {
|
|
58
64
|
// Check for GATEWAY_ID environment variable override (for Docker containers)
|
|
@@ -61,9 +67,11 @@ class GatewayConfigManager {
|
|
|
61
67
|
const now = new Date();
|
|
62
68
|
this.config = {
|
|
63
69
|
gateway_id: envGatewayId,
|
|
70
|
+
gateway_name: process.env.GATEWAY_NAME || null,
|
|
64
71
|
instance_id: `node-${envGatewayId}-${process.pid}`,
|
|
65
72
|
created_at: now.toISOString(),
|
|
66
|
-
last_started_at: now.toISOString()
|
|
73
|
+
last_started_at: now.toISOString(),
|
|
74
|
+
server_assigned: false
|
|
67
75
|
};
|
|
68
76
|
console.log('[GatewayConfig] Using GATEWAY_ID from environment variable');
|
|
69
77
|
console.log(`[GatewayConfig] Gateway ID: ${this.config.gateway_id}`);
|
|
@@ -72,50 +80,62 @@ class GatewayConfigManager {
|
|
|
72
80
|
}
|
|
73
81
|
// Try to load existing config
|
|
74
82
|
this.config = this.loadConfig();
|
|
75
|
-
if (this.config) {
|
|
76
|
-
console.log('[GatewayConfig] Loaded existing configuration');
|
|
83
|
+
if (this.config && this.config.gateway_id) {
|
|
84
|
+
console.log('[GatewayConfig] Loaded existing configuration with server-assigned ID');
|
|
77
85
|
console.log(`[GatewayConfig] Gateway ID: ${this.config.gateway_id}`);
|
|
86
|
+
console.log(`[GatewayConfig] Gateway Name: ${this.config.gateway_name || 'not set'}`);
|
|
78
87
|
console.log(`[GatewayConfig] Instance ID: ${this.config.instance_id}`);
|
|
79
88
|
console.log(`[GatewayConfig] Created: ${this.config.created_at}`);
|
|
80
|
-
// Update last_started_at
|
|
89
|
+
// Update last_started_at and instance_id for this process
|
|
81
90
|
this.config.last_started_at = new Date().toISOString();
|
|
91
|
+
this.config.instance_id = `node-${this.config.gateway_id}-${process.pid}`;
|
|
82
92
|
this.saveConfig();
|
|
83
93
|
return this.config;
|
|
84
94
|
}
|
|
85
|
-
//
|
|
86
|
-
console.log('[GatewayConfig] No existing configuration found,
|
|
87
|
-
|
|
88
|
-
this.
|
|
89
|
-
|
|
90
|
-
|
|
95
|
+
// First connection - gateway_id will be assigned by server
|
|
96
|
+
console.log('[GatewayConfig] No existing configuration found, will request server-assigned ID');
|
|
97
|
+
const now = new Date();
|
|
98
|
+
this.config = {
|
|
99
|
+
gateway_id: null, // Server will assign this
|
|
100
|
+
gateway_name: process.env.GATEWAY_NAME || null, // Optional user-provided name
|
|
101
|
+
instance_id: `node-new-${process.pid}`, // Temporary instance ID
|
|
102
|
+
created_at: now.toISOString(),
|
|
103
|
+
last_started_at: now.toISOString(),
|
|
104
|
+
server_assigned: false
|
|
105
|
+
};
|
|
106
|
+
// Don't save yet - wait for server-assigned ID
|
|
91
107
|
return this.config;
|
|
92
108
|
}
|
|
93
109
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* Where NNNN is a 4-digit number seeded from timestamp
|
|
110
|
+
* Update configuration with server-assigned gateway_id and gateway_name
|
|
111
|
+
* Called when auth_confirmed message is received from Type 1 server
|
|
97
112
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
updateServerAssignedId(gatewayId, gatewayName) {
|
|
114
|
+
if (!this.config) {
|
|
115
|
+
console.error('[GatewayConfig] Cannot update - no config initialized');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const previousId = this.config.gateway_id;
|
|
119
|
+
this.config.gateway_id = gatewayId;
|
|
120
|
+
this.config.gateway_name = gatewayName || this.config.gateway_name;
|
|
121
|
+
this.config.instance_id = `node-${gatewayId}-${process.pid}`;
|
|
122
|
+
this.config.server_assigned = true;
|
|
123
|
+
this.saveConfig();
|
|
124
|
+
if (previousId === null) {
|
|
125
|
+
console.log(`[GatewayConfig] Server assigned new Gateway ID: ${gatewayId}`);
|
|
126
|
+
}
|
|
127
|
+
else if (previousId !== gatewayId) {
|
|
128
|
+
console.log(`[GatewayConfig] Server updated Gateway ID: ${previousId} -> ${gatewayId}`);
|
|
129
|
+
}
|
|
130
|
+
if (gatewayName) {
|
|
131
|
+
console.log(`[GatewayConfig] Gateway Name: ${gatewayName}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Check if this is a first connection (no stored gateway_id)
|
|
136
|
+
*/
|
|
137
|
+
isFirstConnection() {
|
|
138
|
+
return this.config === null || this.config.gateway_id === null;
|
|
119
139
|
}
|
|
120
140
|
/**
|
|
121
141
|
* Load configuration from file
|
|
@@ -129,11 +149,16 @@ class GatewayConfigManager {
|
|
|
129
149
|
}
|
|
130
150
|
const fileContent = fs.readFileSync(this.configPath, 'utf-8');
|
|
131
151
|
const config = JSON.parse(fileContent);
|
|
132
|
-
// Validate config structure
|
|
133
|
-
|
|
134
|
-
|
|
152
|
+
// Validate config structure - gateway_id can be null (first connection)
|
|
153
|
+
// but instance_id and created_at are required
|
|
154
|
+
if (!config.instance_id || !config.created_at) {
|
|
155
|
+
console.warn('[GatewayConfig] Invalid config structure (missing instance_id or created_at)');
|
|
135
156
|
return null;
|
|
136
157
|
}
|
|
158
|
+
// Ensure server_assigned field exists for backward compatibility
|
|
159
|
+
if (config.server_assigned === undefined) {
|
|
160
|
+
config.server_assigned = config.gateway_id !== null;
|
|
161
|
+
}
|
|
137
162
|
return config;
|
|
138
163
|
}
|
|
139
164
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway-config.js","sourceRoot":"","sources":["../gateway-config.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"gateway-config.js","sourceRoot":"","sources":["../gateway-config.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,mEAAmE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEnE,uCAAyB;AACzB,2CAA6B;AAW7B;;;;;;;;;GASG;AACH,MAAa,oBAAoB;IAI/B,YAAY,UAAmB;QAFvB,WAAM,GAAyB,IAAI,CAAC;QAG1C,0DAA0D;QAC1D,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,qBAAqB,CAAC,CAAC;IAClF,CAAC;IAED;;;;;OAKG;IACI,iBAAiB;QACtB,6EAA6E;QAC7E,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;QAC5C,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG;gBACZ,UAAU,EAAE,YAAY;gBACxB,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,IAAI;gBAC9C,WAAW,EAAE,QAAQ,YAAY,IAAI,OAAO,CAAC,GAAG,EAAE;gBAClD,UAAU,EAAE,GAAG,CAAC,WAAW,EAAE;gBAC7B,eAAe,EAAE,GAAG,CAAC,WAAW,EAAE;gBAClC,eAAe,EAAE,KAAK;aACvB,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,4DAA4D,CAAC,CAAC;YAC1E,OAAO,CAAC,GAAG,CAAC,+BAA+B,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CA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,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACxD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;YACvD,OAAO,CAAC,GAAG,CAAC,0CAA0C,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAC3E,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,0CAA0C,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACI,YAAY;QACjB,OAAO,IAAI,CAAC,MAAM,EAAE,UAAU,IAAI,IAAI,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,aAAa;QAClB,OAAO,IAAI,CAAC,MAAM,EAAE,WAAW,IAAI,IAAI,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACI,WAAW;QAChB,IAAI,CAAC;YACH,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBACnC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAC/B,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,2CAA2C,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;CACF;AA/LD,oDA+LC"}
|
package/dist/gateway-server.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export declare class Type3GatewayServer extends EventEmitter {
|
|
|
19
19
|
private marketplaceWs;
|
|
20
20
|
private nodeId;
|
|
21
21
|
private instanceId;
|
|
22
|
+
private gatewayId;
|
|
23
|
+
private configManager;
|
|
22
24
|
private vault;
|
|
23
25
|
private activeRequests;
|
|
24
26
|
private healthCheckInterval;
|
|
@@ -154,6 +156,11 @@ export declare class Type3GatewayServer extends EventEmitter {
|
|
|
154
156
|
* Get CPU usage
|
|
155
157
|
*/
|
|
156
158
|
private getCpuUsage;
|
|
159
|
+
/**
|
|
160
|
+
* Detect if running inside a container (Docker, Podman, Kubernetes, etc.)
|
|
161
|
+
* Container-based gateways cannot auto-update via npm - they require image updates
|
|
162
|
+
*/
|
|
163
|
+
private detectContainerEnvironment;
|
|
157
164
|
/**
|
|
158
165
|
* Get test URL for provider
|
|
159
166
|
* Uses /v1/models endpoint for OpenAI-compatible providers
|
|
@@ -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;AAE7C;;;;;;;;;;;;;GAaG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;IAChD,OAAO,CAAC,GAAG,CAAiC;IAC5C,OAAO,CAAC,aAAa,CAA0B;IAC/C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,mBAAmB,CAA+B;IAE1D,OAAO,CAAC,cAAc,CAYjB;IACL,OAAO,CAAC,eAAe,CAA+E;IACtG,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,IAAI,CAAS;IAErB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,gBAAgB,CAAa;IACrC,OAAO,CAAC,OAAO,CAOb;IACF,OAAO,CAAC,MAAM,CA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AAgB,IAAI,OAAO,CAAC,IAAI,CAAC;CAyCjD"}
|
package/dist/gateway-server.js
CHANGED
|
@@ -77,13 +77,24 @@ class Type3GatewayServer extends events_1.EventEmitter {
|
|
|
77
77
|
console.log(`[Gateway Type 3] Remote LLM Sessions: ${this.enableRemoteLLMSession ? '✅ Enabled' : '❌ Disabled'}`);
|
|
78
78
|
console.log(`[Gateway Type 3] LLM Routing: ${this.enableLLMRouting ? '✅ Enabled' : '❌ Disabled'}`);
|
|
79
79
|
// Use persistent configuration manager for gateway and instance IDs
|
|
80
|
+
// This handles server-assigned gateway IDs for first-time connections
|
|
80
81
|
console.log('[Gateway Type 3] Initializing gateway configuration...');
|
|
81
|
-
|
|
82
|
-
const gatewayConfig = configManager.getOrCreateConfig();
|
|
83
|
-
//
|
|
84
|
-
this.
|
|
85
|
-
this
|
|
86
|
-
|
|
82
|
+
this.configManager = new gateway_config_1.GatewayConfigManager(config.configPath);
|
|
83
|
+
const gatewayConfig = this.configManager.getOrCreateConfig();
|
|
84
|
+
// Gateway ID may be null for first connection (server will assign)
|
|
85
|
+
this.gatewayId = gatewayConfig.gateway_id;
|
|
86
|
+
// Use temporary IDs if this is first connection, will be updated after auth_confirmed
|
|
87
|
+
if (this.gatewayId) {
|
|
88
|
+
this.instanceId = this.gatewayId;
|
|
89
|
+
this.nodeId = `node-${this.gatewayId}-${process.pid}`;
|
|
90
|
+
console.log(`[Gateway Type 3] Using stored Gateway ID: ${this.gatewayId}`);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// First connection - use temporary ID until server assigns one
|
|
94
|
+
this.instanceId = `temp-${Date.now()}-${process.pid}`;
|
|
95
|
+
this.nodeId = `node-temp-${process.pid}`;
|
|
96
|
+
console.log(`[Gateway Type 3] First connection - awaiting server-assigned Gateway ID`);
|
|
97
|
+
}
|
|
87
98
|
console.log(`[Gateway Type 3] Using Node ID: ${this.nodeId}`);
|
|
88
99
|
this.apiKey = config.apiKey || '';
|
|
89
100
|
// Initialize local vault - KEY DIFFERENCE from Type 2
|
|
@@ -640,9 +651,15 @@ class Type3GatewayServer extends events_1.EventEmitter {
|
|
|
640
651
|
// Get connections list (only if LLM routing is enabled)
|
|
641
652
|
const connections = this.enableLLMRouting ? this.vault.listAccessPoints() : [];
|
|
642
653
|
const modeNames = { [gateway_mode_1.GatewayMode.REMOTE_LLM_SESSION_ONLY]: 'remote_llm_session_only', [gateway_mode_1.GatewayMode.LLM_ROUTING_ONLY]: 'llm_routing_only', [gateway_mode_1.GatewayMode.FULL]: 'full' };
|
|
654
|
+
// Get config for gateway_id and gateway_name
|
|
655
|
+
const config = this.configManager.getConfig();
|
|
643
656
|
const registration = {
|
|
644
657
|
event: 'gateway_register',
|
|
645
658
|
gateway_type: 3,
|
|
659
|
+
// IMPORTANT: gateway_id can be null for first connections (server will assign)
|
|
660
|
+
// For reconnections, send the stored ID from config
|
|
661
|
+
gateway_id: config?.gateway_id || null, // Server generates if null
|
|
662
|
+
gateway_name: config?.gateway_name || null, // Optional user-provided name
|
|
646
663
|
instance_id: this.instanceId,
|
|
647
664
|
node_id: this.nodeId,
|
|
648
665
|
version: this.currentVersion,
|
|
@@ -650,6 +667,15 @@ class Type3GatewayServer extends events_1.EventEmitter {
|
|
|
650
667
|
api_key: this.apiKey,
|
|
651
668
|
// Gateway mode - tells Type 1 what this gateway can handle
|
|
652
669
|
mode: modeNames[this.gatewayMode],
|
|
670
|
+
// System information for tracking/management
|
|
671
|
+
system_info: {
|
|
672
|
+
os_platform: process.platform, // 'linux', 'win32', 'darwin'
|
|
673
|
+
os_release: require('os').release(), // OS kernel/release version
|
|
674
|
+
node_version: process.version, // Node.js version (e.g., 'v22.9.0')
|
|
675
|
+
arch: process.arch, // CPU architecture (e.g., 'x64', 'arm64')
|
|
676
|
+
hostname: require('os').hostname(), // Machine hostname
|
|
677
|
+
is_container: this.detectContainerEnvironment() // Container detection
|
|
678
|
+
},
|
|
653
679
|
capabilities: {
|
|
654
680
|
// LLM routing capabilities (only advertised if LLM routing is enabled)
|
|
655
681
|
connections: connections,
|
|
@@ -710,8 +736,26 @@ class Type3GatewayServer extends events_1.EventEmitter {
|
|
|
710
736
|
break;
|
|
711
737
|
case 'auth_confirmed':
|
|
712
738
|
// Gateway Type 1 sends auth_confirmed after successful authentication
|
|
739
|
+
// It also includes the server-assigned gateway_id and gateway_name
|
|
713
740
|
console.log(`[${this.nodeId}] Authentication confirmed by Gateway Type 1`);
|
|
714
741
|
this.isAuthenticated = true;
|
|
742
|
+
// IMPORTANT: Store server-assigned gateway_id for future reconnections
|
|
743
|
+
const serverGatewayId = message.gatewayId || message.gateway_id;
|
|
744
|
+
const serverGatewayName = message.gatewayName || message.gateway_name;
|
|
745
|
+
if (serverGatewayId) {
|
|
746
|
+
// Update config with server-assigned ID
|
|
747
|
+
this.configManager.updateServerAssignedId(serverGatewayId, serverGatewayName);
|
|
748
|
+
// Update our instance variables with the server-assigned ID
|
|
749
|
+
if (this.gatewayId !== serverGatewayId) {
|
|
750
|
+
console.log(`[${this.nodeId}] Gateway ID updated from server: ${this.gatewayId} -> ${serverGatewayId}`);
|
|
751
|
+
this.gatewayId = serverGatewayId;
|
|
752
|
+
// Update nodeId to include new gateway ID
|
|
753
|
+
this.nodeId = `node-${serverGatewayId}-${process.pid}`;
|
|
754
|
+
}
|
|
755
|
+
if (serverGatewayName) {
|
|
756
|
+
console.log(`[${this.nodeId}] Gateway Name from server: ${serverGatewayName}`);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
715
759
|
break;
|
|
716
760
|
case 'heartbeat':
|
|
717
761
|
case 'health_check':
|
|
@@ -1326,6 +1370,55 @@ class Type3GatewayServer extends events_1.EventEmitter {
|
|
|
1326
1370
|
const total = totalTick / cpus.length;
|
|
1327
1371
|
return 100 - ~~(100 * idle / total);
|
|
1328
1372
|
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Detect if running inside a container (Docker, Podman, Kubernetes, etc.)
|
|
1375
|
+
* Container-based gateways cannot auto-update via npm - they require image updates
|
|
1376
|
+
*/
|
|
1377
|
+
detectContainerEnvironment() {
|
|
1378
|
+
const fs = require('fs');
|
|
1379
|
+
// Method 1: Check for Docker's .dockerenv file
|
|
1380
|
+
if (fs.existsSync('/.dockerenv')) {
|
|
1381
|
+
return true;
|
|
1382
|
+
}
|
|
1383
|
+
// Method 2: Check for Podman's container marker
|
|
1384
|
+
if (fs.existsSync('/run/.containerenv')) {
|
|
1385
|
+
return true;
|
|
1386
|
+
}
|
|
1387
|
+
// Method 3: Check for Kubernetes environment variables
|
|
1388
|
+
if (process.env.KUBERNETES_SERVICE_HOST || process.env.KUBERNETES_PORT) {
|
|
1389
|
+
return true;
|
|
1390
|
+
}
|
|
1391
|
+
// Method 4: Check for common container-related environment variables
|
|
1392
|
+
if (process.env.container === 'docker' || process.env.container === 'podman') {
|
|
1393
|
+
return true;
|
|
1394
|
+
}
|
|
1395
|
+
// Method 5: Check cgroups for container indicators (Linux only)
|
|
1396
|
+
if (process.platform === 'linux') {
|
|
1397
|
+
try {
|
|
1398
|
+
const cgroup = fs.readFileSync('/proc/1/cgroup', 'utf8');
|
|
1399
|
+
if (cgroup.includes('docker') || cgroup.includes('kubepods') ||
|
|
1400
|
+
cgroup.includes('containerd') || cgroup.includes('lxc')) {
|
|
1401
|
+
return true;
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
catch {
|
|
1405
|
+
// File doesn't exist or can't be read - not in container
|
|
1406
|
+
}
|
|
1407
|
+
// Method 6: Check /proc/1/sched for container init process
|
|
1408
|
+
try {
|
|
1409
|
+
const sched = fs.readFileSync('/proc/1/sched', 'utf8');
|
|
1410
|
+
// In containers, PID 1 is often not "init" or "systemd"
|
|
1411
|
+
const firstLine = sched.split('\n')[0];
|
|
1412
|
+
if (!firstLine.includes('init') && !firstLine.includes('systemd')) {
|
|
1413
|
+
return true;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
catch {
|
|
1417
|
+
// File doesn't exist or can't be read
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
return false;
|
|
1421
|
+
}
|
|
1329
1422
|
/**
|
|
1330
1423
|
* Get test URL for provider
|
|
1331
1424
|
* Uses /v1/models endpoint for OpenAI-compatible providers
|