langmart-gateway-type3 3.0.1 → 3.0.3
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/README.md +223 -14
- package/package.json +2 -1
- package/scripts/install.ps1 +367 -0
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Gateway Type 3 - Seller-Managed Gateway
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/langmart-gateway-type3)
|
|
4
|
+
|
|
3
5
|
## Overview
|
|
4
6
|
Type 3 Gateway is a seller-managed gateway client that runs on the seller's infrastructure. It connects to the marketplace via WebSocket and uses the seller's own API keys to fulfill requests.
|
|
5
7
|
|
|
@@ -18,42 +20,249 @@ Type 3 Gateway is a seller-managed gateway client that runs on the seller's infr
|
|
|
18
20
|
- **Interactive CLI UI** with chat interface and model management
|
|
19
21
|
- **Intelligent Image Generation** with keyword-based auto-detection
|
|
20
22
|
- **Terminal Image Preview** for generated images
|
|
23
|
+
- **DevOps Mode**: Full session management with bash, SSH, and system tools
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 🚀 Quick Install (Recommended)
|
|
28
|
+
|
|
29
|
+
### Linux/macOS
|
|
30
|
+
|
|
31
|
+
Install the gateway on any Linux/macOS server with a single command:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Using unpkg CDN (recommended)
|
|
35
|
+
curl -fsSL https://unpkg.com/langmart-gateway-type3/scripts/install.sh | bash -s -- \
|
|
36
|
+
--marketplace-url ws://your-marketplace:8081 \
|
|
37
|
+
--api-key YOUR_API_KEY \
|
|
38
|
+
--full \
|
|
39
|
+
--service
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Windows (PowerShell)
|
|
43
|
+
|
|
44
|
+
Install on Windows using PowerShell:
|
|
45
|
+
|
|
46
|
+
```powershell
|
|
47
|
+
# One-liner installation
|
|
48
|
+
$env:MARKETPLACE_URL="ws://your-marketplace:8081"; $env:GATEWAY_API_KEY="YOUR_API_KEY"; iwr -useb https://unpkg.com/langmart-gateway-type3/scripts/install.ps1 | iex
|
|
49
|
+
|
|
50
|
+
# Or download and run with parameters
|
|
51
|
+
iwr -OutFile install.ps1 https://unpkg.com/langmart-gateway-type3/scripts/install.ps1
|
|
52
|
+
.\install.ps1 -MarketplaceUrl "ws://your-marketplace:8081" -ApiKey "YOUR_API_KEY" -Full -Service
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Install Options
|
|
56
|
+
|
|
57
|
+
#### Linux/macOS (Bash)
|
|
58
|
+
|
|
59
|
+
| Option | Description | Default |
|
|
60
|
+
|--------|-------------|---------|
|
|
61
|
+
| `--marketplace-url URL` | Marketplace WebSocket URL | `ws://localhost:8081` |
|
|
62
|
+
| `--api-key KEY` | Gateway API key for authentication | (none) |
|
|
63
|
+
| `--port PORT` | Gateway port | `8083` |
|
|
64
|
+
| `--install-dir DIR` | Installation directory | `/opt/langmart-gateway` |
|
|
65
|
+
| `--capabilities CAPS` | Capabilities: `session,llm` or `llm` | `llm` |
|
|
66
|
+
| `--full` | Enable full capabilities (DevOps + LLM) | (disabled) |
|
|
67
|
+
| `--service` | Install as systemd service | (disabled) |
|
|
68
|
+
|
|
69
|
+
#### Windows (PowerShell)
|
|
70
|
+
|
|
71
|
+
| Parameter | Description | Default |
|
|
72
|
+
|-----------|-------------|---------|
|
|
73
|
+
| `-MarketplaceUrl URL` | Marketplace WebSocket URL | `ws://localhost:8081` |
|
|
74
|
+
| `-ApiKey KEY` | Gateway API key for authentication | (none) |
|
|
75
|
+
| `-Port PORT` | Gateway port | `8083` |
|
|
76
|
+
| `-InstallDir DIR` | Installation directory | `C:\langmart-gateway` |
|
|
77
|
+
| `-Capabilities CAPS` | Capabilities: `session,llm` or `llm` | `llm` |
|
|
78
|
+
| `-Full` | Enable full capabilities (DevOps + LLM) | (disabled) |
|
|
79
|
+
| `-Service` | Install as Windows Service (requires nssm) | (disabled) |
|
|
80
|
+
|
|
81
|
+
### Examples
|
|
82
|
+
|
|
83
|
+
#### Linux/macOS
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# LLM routing only (default)
|
|
87
|
+
curl -fsSL https://unpkg.com/langmart-gateway-type3/scripts/install.sh | bash -s -- \
|
|
88
|
+
--marketplace-url ws://10.0.1.117:8081 \
|
|
89
|
+
--api-key sk-test-inference-key
|
|
90
|
+
|
|
91
|
+
# Full DevOps mode with systemd service
|
|
92
|
+
curl -fsSL https://unpkg.com/langmart-gateway-type3/scripts/install.sh | bash -s -- \
|
|
93
|
+
--marketplace-url ws://10.0.1.117:8081 \
|
|
94
|
+
--api-key sk-test-inference-key \
|
|
95
|
+
--full \
|
|
96
|
+
--service
|
|
97
|
+
|
|
98
|
+
# Custom port and directory
|
|
99
|
+
curl -fsSL https://unpkg.com/langmart-gateway-type3/scripts/install.sh | bash -s -- \
|
|
100
|
+
--marketplace-url ws://10.0.1.117:8081 \
|
|
101
|
+
--api-key sk-test-inference-key \
|
|
102
|
+
--port 9000 \
|
|
103
|
+
--install-dir /home/user/gateway
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Windows
|
|
107
|
+
|
|
108
|
+
```powershell
|
|
109
|
+
# LLM routing only (default)
|
|
110
|
+
.\install.ps1 -MarketplaceUrl "ws://10.0.1.117:8081" -ApiKey "sk-test-inference-key"
|
|
111
|
+
|
|
112
|
+
# Full DevOps mode with Windows Service
|
|
113
|
+
.\install.ps1 -MarketplaceUrl "ws://10.0.1.117:8081" -ApiKey "sk-test-inference-key" -Full -Service
|
|
114
|
+
|
|
115
|
+
# Custom port and directory
|
|
116
|
+
.\install.ps1 -MarketplaceUrl "ws://10.0.1.117:8081" -ApiKey "sk-test-inference-key" -Port 9000 -InstallDir "D:\gateway"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Alternative CDN
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Linux/macOS - Using jsdelivr
|
|
123
|
+
curl -fsSL https://cdn.jsdelivr.net/npm/langmart-gateway-type3/scripts/install.sh | bash -s -- [OPTIONS]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```powershell
|
|
127
|
+
# Windows - Using jsdelivr
|
|
128
|
+
iwr -useb https://cdn.jsdelivr.net/npm/langmart-gateway-type3/scripts/install.ps1 | iex
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## 📦 Manual Installation
|
|
21
134
|
|
|
22
|
-
|
|
135
|
+
### Option 1: npm install
|
|
23
136
|
|
|
24
137
|
```bash
|
|
138
|
+
# Create installation directory
|
|
139
|
+
mkdir -p /opt/langmart-gateway && cd /opt/langmart-gateway
|
|
140
|
+
|
|
141
|
+
# Initialize and install
|
|
142
|
+
npm init -y
|
|
143
|
+
npm install langmart-gateway-type3
|
|
144
|
+
|
|
145
|
+
# Create .env file
|
|
146
|
+
cat > .env << EOF
|
|
147
|
+
INSTANCE_ID=gw3-$(hostname)-$(date +%s | tail -c 5)
|
|
148
|
+
GATEWAY_PORT=8083
|
|
149
|
+
MARKETPLACE_URL=ws://your-marketplace:8081
|
|
150
|
+
GATEWAY_API_KEY=your-api-key
|
|
151
|
+
GATEWAY_CAPABILITIES=llm
|
|
152
|
+
NODE_ENV=production
|
|
153
|
+
EOF
|
|
154
|
+
|
|
155
|
+
# Start the gateway
|
|
156
|
+
node node_modules/langmart-gateway-type3/dist/index-server.js
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Option 2: Clone and Build
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Clone the repository
|
|
163
|
+
git clone https://github.com/YiHuangDB/LangMartDesign.git
|
|
164
|
+
cd LangMartDesign/gateway-type3
|
|
165
|
+
|
|
25
166
|
# Install dependencies
|
|
26
167
|
npm install
|
|
27
168
|
|
|
28
169
|
# Build TypeScript
|
|
29
170
|
npm run build
|
|
171
|
+
|
|
172
|
+
# Configure
|
|
173
|
+
cp .env.example .env
|
|
174
|
+
# Edit .env with your settings
|
|
175
|
+
|
|
176
|
+
# Start
|
|
177
|
+
npm start
|
|
30
178
|
```
|
|
31
179
|
|
|
32
|
-
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## ⚙️ Configuration
|
|
183
|
+
|
|
184
|
+
### Environment Variables
|
|
33
185
|
|
|
34
|
-
Environment variables:
|
|
35
186
|
```bash
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
187
|
+
# Gateway identification
|
|
188
|
+
INSTANCE_ID=gw3-server-001 # Gateway identifier (auto-generated if not set)
|
|
189
|
+
GATEWAY_PORT=8083 # Gateway HTTP/WebSocket port
|
|
190
|
+
|
|
191
|
+
# Marketplace connection
|
|
192
|
+
MARKETPLACE_URL=ws://localhost:8081 # Marketplace WebSocket URL
|
|
193
|
+
GATEWAY_API_KEY=sk-your-key # Marketplace API key
|
|
194
|
+
|
|
195
|
+
# Capabilities
|
|
196
|
+
GATEWAY_CAPABILITIES=llm # "llm" or "session,llm" for full DevOps
|
|
39
197
|
|
|
40
|
-
#
|
|
198
|
+
# Local vault (for storing provider API keys)
|
|
199
|
+
VAULT_PATH=.vault/credentials.enc # Encrypted vault path
|
|
200
|
+
VAULT_PASSWORD=random-secure-password # Vault encryption password
|
|
201
|
+
|
|
202
|
+
# Provider API Keys (seller's own keys - stored in vault)
|
|
41
203
|
OPENAI_API_KEY=sk-... # OpenAI API key
|
|
42
204
|
ANTHROPIC_API_KEY=sk-ant-... # Anthropic API key
|
|
43
|
-
|
|
44
|
-
|
|
205
|
+
GROQ_API_KEY=gsk_... # Groq API key
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Capability Modes
|
|
209
|
+
|
|
210
|
+
| Mode | GATEWAY_CAPABILITIES | Description |
|
|
211
|
+
|------|---------------------|-------------|
|
|
212
|
+
| **LLM Only** | `llm` | Routes LLM requests to providers (default) |
|
|
213
|
+
| **Full DevOps** | `session,llm` | LLM routing + bash, SSH, file ops, system tools |
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## 🏃 Running
|
|
218
|
+
|
|
219
|
+
### Manual Start
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
cd /opt/langmart-gateway
|
|
223
|
+
|
|
224
|
+
# If installed via npm
|
|
225
|
+
./start.sh
|
|
226
|
+
|
|
227
|
+
# Or directly
|
|
228
|
+
node node_modules/langmart-gateway-type3/dist/index-server.js
|
|
45
229
|
```
|
|
46
230
|
|
|
47
|
-
|
|
231
|
+
### Systemd Service
|
|
232
|
+
|
|
233
|
+
If installed with `--service`:
|
|
48
234
|
|
|
49
235
|
```bash
|
|
50
|
-
#
|
|
51
|
-
|
|
236
|
+
# Start
|
|
237
|
+
sudo systemctl start langmart-gateway
|
|
52
238
|
|
|
53
|
-
#
|
|
54
|
-
|
|
239
|
+
# Stop
|
|
240
|
+
sudo systemctl stop langmart-gateway
|
|
241
|
+
|
|
242
|
+
# Status
|
|
243
|
+
sudo systemctl status langmart-gateway
|
|
244
|
+
|
|
245
|
+
# Logs
|
|
246
|
+
sudo journalctl -u langmart-gateway -f
|
|
55
247
|
```
|
|
56
248
|
|
|
249
|
+
### Verify Installation
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
# Health check
|
|
253
|
+
curl http://localhost:8083/health
|
|
254
|
+
|
|
255
|
+
# Expected response:
|
|
256
|
+
{
|
|
257
|
+
"status": "healthy",
|
|
258
|
+
"gatewayId": "gw3-server-12345",
|
|
259
|
+
"capabilities": ["session", "llm"],
|
|
260
|
+
"tools": 18
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
57
266
|
## How It Works
|
|
58
267
|
|
|
59
268
|
1. **Connection**: Gateway connects to marketplace via WebSocket
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langmart-gateway-type3",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "LangMart Type 3 Gateway - Seller-Managed Gateway with Local Vault",
|
|
5
5
|
"main": "dist/index-server.js",
|
|
6
6
|
"types": "dist/index-server.d.ts",
|
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
"scripts/stop.sh",
|
|
103
103
|
"scripts/status.sh",
|
|
104
104
|
"scripts/install.sh",
|
|
105
|
+
"scripts/install.ps1",
|
|
105
106
|
".env.example",
|
|
106
107
|
"README.md"
|
|
107
108
|
],
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
# Installation Script for LangMart Gateway Type 3 (Windows)
|
|
2
|
+
# Run this script ON the target Windows server to install the gateway
|
|
3
|
+
#
|
|
4
|
+
# Usage (from PowerShell - recommended):
|
|
5
|
+
# iwr -useb https://unpkg.com/langmart-gateway-type3/scripts/install.ps1 | iex
|
|
6
|
+
#
|
|
7
|
+
# Or with parameters:
|
|
8
|
+
# $env:MARKETPLACE_URL="ws://your-server:8081"; $env:GATEWAY_API_KEY="your-key"; iwr -useb https://unpkg.com/langmart-gateway-type3/scripts/install.ps1 | iex
|
|
9
|
+
#
|
|
10
|
+
# Or download and run:
|
|
11
|
+
# .\install.ps1 -MarketplaceUrl "ws://localhost:8081" -ApiKey "your-key" -Full -Service
|
|
12
|
+
#
|
|
13
|
+
# Parameters:
|
|
14
|
+
# -MarketplaceUrl Marketplace WebSocket URL (default: ws://localhost:8081)
|
|
15
|
+
# -ApiKey Gateway API key for authentication
|
|
16
|
+
# -Port Gateway port (default: 8083)
|
|
17
|
+
# -InstallDir Installation directory (default: C:\langmart-gateway)
|
|
18
|
+
# -Capabilities Gateway capabilities: session,llm or llm (default: llm)
|
|
19
|
+
# -Full Enable full capabilities (DevOps + LLM routing)
|
|
20
|
+
# -Service Install as Windows Service
|
|
21
|
+
|
|
22
|
+
[CmdletBinding()]
|
|
23
|
+
param(
|
|
24
|
+
[string]$MarketplaceUrl = $env:MARKETPLACE_URL,
|
|
25
|
+
[string]$ApiKey = $env:GATEWAY_API_KEY,
|
|
26
|
+
[int]$Port = 8083,
|
|
27
|
+
[string]$InstallDir = "C:\langmart-gateway",
|
|
28
|
+
[string]$Capabilities = "",
|
|
29
|
+
[switch]$Full,
|
|
30
|
+
[switch]$Service,
|
|
31
|
+
[switch]$Help
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# Set defaults if not provided
|
|
35
|
+
if ([string]::IsNullOrEmpty($MarketplaceUrl)) {
|
|
36
|
+
$MarketplaceUrl = "ws://localhost:8081"
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# Colors for output
|
|
40
|
+
function Write-ColorOutput($ForegroundColor) {
|
|
41
|
+
$fc = $host.UI.RawUI.ForegroundColor
|
|
42
|
+
$host.UI.RawUI.ForegroundColor = $ForegroundColor
|
|
43
|
+
if ($args) {
|
|
44
|
+
Write-Output $args
|
|
45
|
+
}
|
|
46
|
+
$host.UI.RawUI.ForegroundColor = $fc
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function Write-Info { Write-Host $args -ForegroundColor Cyan }
|
|
50
|
+
function Write-Success { Write-Host $args -ForegroundColor Green }
|
|
51
|
+
function Write-Warning { Write-Host $args -ForegroundColor Yellow }
|
|
52
|
+
function Write-Error { Write-Host $args -ForegroundColor Red }
|
|
53
|
+
|
|
54
|
+
# Show help
|
|
55
|
+
if ($Help) {
|
|
56
|
+
Write-Host @"
|
|
57
|
+
LangMart Gateway Type 3 - Windows Installation Script
|
|
58
|
+
|
|
59
|
+
Usage: .\install.ps1 [OPTIONS]
|
|
60
|
+
|
|
61
|
+
Options:
|
|
62
|
+
-MarketplaceUrl URL Marketplace WebSocket URL (default: ws://localhost:8081)
|
|
63
|
+
-ApiKey KEY Gateway API key for authentication
|
|
64
|
+
-Port PORT Gateway port (default: 8083)
|
|
65
|
+
-InstallDir DIR Installation directory (default: C:\langmart-gateway)
|
|
66
|
+
-Capabilities CAPS Gateway capabilities: session,llm or llm (default: llm)
|
|
67
|
+
-Full Enable full capabilities (DevOps + LLM routing)
|
|
68
|
+
-Service Install as Windows Service
|
|
69
|
+
-Help Show this help message
|
|
70
|
+
|
|
71
|
+
Examples:
|
|
72
|
+
# Basic installation (LLM routing only)
|
|
73
|
+
.\install.ps1 -MarketplaceUrl "ws://10.0.1.117:8081" -ApiKey "sk-test-key"
|
|
74
|
+
|
|
75
|
+
# Full DevOps mode with Windows Service
|
|
76
|
+
.\install.ps1 -MarketplaceUrl "ws://10.0.1.117:8081" -ApiKey "sk-test-key" -Full -Service
|
|
77
|
+
|
|
78
|
+
# One-liner from web (set env vars first)
|
|
79
|
+
`$env:MARKETPLACE_URL="ws://10.0.1.117:8081"; `$env:GATEWAY_API_KEY="sk-test-key"; iwr -useb https://unpkg.com/langmart-gateway-type3/scripts/install.ps1 | iex
|
|
80
|
+
"@
|
|
81
|
+
exit 0
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Write-Host ""
|
|
85
|
+
Write-Host "===============================================================" -ForegroundColor Blue
|
|
86
|
+
Write-Host " LangMart Gateway Type 3 - Windows Installation " -ForegroundColor Blue
|
|
87
|
+
Write-Host "===============================================================" -ForegroundColor Blue
|
|
88
|
+
Write-Host ""
|
|
89
|
+
|
|
90
|
+
# Set capabilities
|
|
91
|
+
if ($Full) {
|
|
92
|
+
$Capabilities = "session,llm"
|
|
93
|
+
}
|
|
94
|
+
if ([string]::IsNullOrEmpty($Capabilities)) {
|
|
95
|
+
$Capabilities = "llm"
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
# Check if running as Administrator
|
|
99
|
+
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
|
100
|
+
if (-not $isAdmin -and $Service) {
|
|
101
|
+
Write-Warning "Warning: Not running as Administrator. Service installation may fail."
|
|
102
|
+
Write-Warning "Please run PowerShell as Administrator for service installation."
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
# Step 1: Check Node.js installation
|
|
106
|
+
Write-Info "[1/6] Checking Node.js installation..."
|
|
107
|
+
|
|
108
|
+
$nodeVersion = $null
|
|
109
|
+
try {
|
|
110
|
+
$nodeVersion = & node -v 2>$null
|
|
111
|
+
} catch {
|
|
112
|
+
$nodeVersion = $null
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if ([string]::IsNullOrEmpty($nodeVersion)) {
|
|
116
|
+
Write-Warning "Node.js not found. Installing Node.js..."
|
|
117
|
+
|
|
118
|
+
# Download and install Node.js using winget or chocolatey
|
|
119
|
+
$hasWinget = Get-Command winget -ErrorAction SilentlyContinue
|
|
120
|
+
$hasChoco = Get-Command choco -ErrorAction SilentlyContinue
|
|
121
|
+
|
|
122
|
+
if ($hasWinget) {
|
|
123
|
+
Write-Info "Installing Node.js via winget..."
|
|
124
|
+
winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements
|
|
125
|
+
} elseif ($hasChoco) {
|
|
126
|
+
Write-Info "Installing Node.js via Chocolatey..."
|
|
127
|
+
choco install nodejs-lts -y
|
|
128
|
+
} else {
|
|
129
|
+
Write-Error "Please install Node.js manually from https://nodejs.org/"
|
|
130
|
+
Write-Error "Or install winget/chocolatey first."
|
|
131
|
+
exit 1
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# Refresh PATH
|
|
135
|
+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
|
|
136
|
+
|
|
137
|
+
$nodeVersion = & node -v 2>$null
|
|
138
|
+
if ([string]::IsNullOrEmpty($nodeVersion)) {
|
|
139
|
+
Write-Error "Node.js installation failed. Please install manually and try again."
|
|
140
|
+
exit 1
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
Write-Success "Node.js $nodeVersion installed"
|
|
145
|
+
|
|
146
|
+
# Check npm
|
|
147
|
+
$npmVersion = & npm -v 2>$null
|
|
148
|
+
if ([string]::IsNullOrEmpty($npmVersion)) {
|
|
149
|
+
Write-Error "npm not found. Please reinstall Node.js."
|
|
150
|
+
exit 1
|
|
151
|
+
}
|
|
152
|
+
Write-Success "npm v$npmVersion installed"
|
|
153
|
+
|
|
154
|
+
# Step 2: Create installation directory
|
|
155
|
+
Write-Info "[2/6] Creating installation directory..."
|
|
156
|
+
|
|
157
|
+
if (-not (Test-Path $InstallDir)) {
|
|
158
|
+
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
|
159
|
+
}
|
|
160
|
+
Set-Location $InstallDir
|
|
161
|
+
Write-Success "Directory created: $InstallDir"
|
|
162
|
+
|
|
163
|
+
# Step 3: Initialize npm project
|
|
164
|
+
Write-Info "[3/6] Initializing npm project..."
|
|
165
|
+
|
|
166
|
+
if (-not (Test-Path "package.json")) {
|
|
167
|
+
@{
|
|
168
|
+
name = "langmart-gateway-instance"
|
|
169
|
+
version = "1.0.0"
|
|
170
|
+
private = $true
|
|
171
|
+
} | ConvertTo-Json | Set-Content "package.json"
|
|
172
|
+
}
|
|
173
|
+
Write-Success "npm project initialized"
|
|
174
|
+
|
|
175
|
+
# Step 4: Install the gateway package
|
|
176
|
+
Write-Info "[4/6] Installing langmart-gateway-type3..."
|
|
177
|
+
|
|
178
|
+
npm install langmart-gateway-type3@latest
|
|
179
|
+
if ($LASTEXITCODE -ne 0) {
|
|
180
|
+
Write-Error "Failed to install langmart-gateway-type3 package"
|
|
181
|
+
exit 1
|
|
182
|
+
}
|
|
183
|
+
Write-Success "Gateway package installed"
|
|
184
|
+
|
|
185
|
+
# Step 5: Create environment file
|
|
186
|
+
Write-Info "[5/6] Creating environment configuration..."
|
|
187
|
+
|
|
188
|
+
# Generate instance ID
|
|
189
|
+
$instanceId = "gw3-$($env:COMPUTERNAME.ToLower())-$(Get-Date -Format 'HHmm')"
|
|
190
|
+
|
|
191
|
+
# Generate vault password
|
|
192
|
+
$vaultPassword = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 32 | ForEach-Object {[char]$_})
|
|
193
|
+
|
|
194
|
+
$envContent = @"
|
|
195
|
+
# LangMart Gateway Type 3 Configuration
|
|
196
|
+
# Generated by install.ps1 on $(Get-Date)
|
|
197
|
+
|
|
198
|
+
# Gateway identification
|
|
199
|
+
INSTANCE_ID=$instanceId
|
|
200
|
+
GATEWAY_PORT=$Port
|
|
201
|
+
|
|
202
|
+
# Marketplace connection
|
|
203
|
+
MARKETPLACE_URL=$MarketplaceUrl
|
|
204
|
+
|
|
205
|
+
# Gateway authentication
|
|
206
|
+
GATEWAY_API_KEY=$ApiKey
|
|
207
|
+
|
|
208
|
+
# Gateway capabilities (session,llm = full DevOps mode, llm = LLM routing only)
|
|
209
|
+
GATEWAY_CAPABILITIES=$Capabilities
|
|
210
|
+
|
|
211
|
+
# Local vault configuration
|
|
212
|
+
VAULT_PATH=.vault\credentials.enc
|
|
213
|
+
VAULT_PASSWORD=$vaultPassword
|
|
214
|
+
|
|
215
|
+
# Environment
|
|
216
|
+
NODE_ENV=production
|
|
217
|
+
"@
|
|
218
|
+
|
|
219
|
+
$envContent | Set-Content ".env"
|
|
220
|
+
Write-Success "Environment file created"
|
|
221
|
+
|
|
222
|
+
# Create start script
|
|
223
|
+
$startScript = @'
|
|
224
|
+
@echo off
|
|
225
|
+
cd /d "%~dp0"
|
|
226
|
+
|
|
227
|
+
:: Load environment variables from .env
|
|
228
|
+
for /f "usebackq tokens=1,* delims==" %%a in (".env") do (
|
|
229
|
+
if not "%%a"=="" if not "%%a:~0,1%"=="#" set "%%a=%%b"
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
:: Start the gateway
|
|
233
|
+
if exist "node_modules\langmart-gateway-type3" (
|
|
234
|
+
node node_modules\langmart-gateway-type3\dist\index-server.js
|
|
235
|
+
) else (
|
|
236
|
+
node dist\index-server.js
|
|
237
|
+
)
|
|
238
|
+
'@
|
|
239
|
+
$startScript | Set-Content "start.bat"
|
|
240
|
+
|
|
241
|
+
# Create PowerShell start script
|
|
242
|
+
$startPs1 = @'
|
|
243
|
+
# Load environment variables
|
|
244
|
+
Get-Content .env | ForEach-Object {
|
|
245
|
+
if ($_ -match '^([^#][^=]+)=(.*)$') {
|
|
246
|
+
[Environment]::SetEnvironmentVariable($matches[1], $matches[2], "Process")
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
# Start the gateway
|
|
251
|
+
if (Test-Path "node_modules\langmart-gateway-type3") {
|
|
252
|
+
node node_modules\langmart-gateway-type3\dist\index-server.js
|
|
253
|
+
} else {
|
|
254
|
+
node dist\index-server.js
|
|
255
|
+
}
|
|
256
|
+
'@
|
|
257
|
+
$startPs1 | Set-Content "start.ps1"
|
|
258
|
+
|
|
259
|
+
# Create stop script
|
|
260
|
+
$stopScript = @'
|
|
261
|
+
@echo off
|
|
262
|
+
for /f "tokens=5" %%a in ('netstat -ano ^| findstr :8083 ^| findstr LISTENING') do (
|
|
263
|
+
taskkill /PID %%a /F
|
|
264
|
+
echo Gateway stopped (PID: %%a)
|
|
265
|
+
goto :done
|
|
266
|
+
)
|
|
267
|
+
echo Gateway not running
|
|
268
|
+
:done
|
|
269
|
+
'@
|
|
270
|
+
$stopScript | Set-Content "stop.bat"
|
|
271
|
+
|
|
272
|
+
Write-Success "Start/stop scripts created"
|
|
273
|
+
|
|
274
|
+
# Step 6: Install as Windows Service (optional)
|
|
275
|
+
if ($Service) {
|
|
276
|
+
Write-Info "[6/6] Installing Windows Service..."
|
|
277
|
+
|
|
278
|
+
# Check for nssm (Non-Sucking Service Manager)
|
|
279
|
+
$hasNssm = Get-Command nssm -ErrorAction SilentlyContinue
|
|
280
|
+
|
|
281
|
+
if (-not $hasNssm) {
|
|
282
|
+
Write-Warning "nssm not found. Installing via chocolatey..."
|
|
283
|
+
if (Get-Command choco -ErrorAction SilentlyContinue) {
|
|
284
|
+
choco install nssm -y
|
|
285
|
+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
|
|
286
|
+
} else {
|
|
287
|
+
Write-Warning "Cannot install nssm automatically. Please install manually:"
|
|
288
|
+
Write-Warning " choco install nssm"
|
|
289
|
+
Write-Warning " Or download from https://nssm.cc/"
|
|
290
|
+
Write-Warning ""
|
|
291
|
+
Write-Warning "Then run: nssm install LangMartGateway"
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
$hasNssm = Get-Command nssm -ErrorAction SilentlyContinue
|
|
296
|
+
if ($hasNssm) {
|
|
297
|
+
# Remove existing service if present
|
|
298
|
+
nssm stop LangMartGateway 2>$null
|
|
299
|
+
nssm remove LangMartGateway confirm 2>$null
|
|
300
|
+
|
|
301
|
+
# Install new service
|
|
302
|
+
$nodePath = (Get-Command node).Source
|
|
303
|
+
$scriptPath = Join-Path $InstallDir "node_modules\langmart-gateway-type3\dist\index-server.js"
|
|
304
|
+
|
|
305
|
+
nssm install LangMartGateway $nodePath $scriptPath
|
|
306
|
+
nssm set LangMartGateway AppDirectory $InstallDir
|
|
307
|
+
nssm set LangMartGateway DisplayName "LangMart Gateway Type 3"
|
|
308
|
+
nssm set LangMartGateway Description "LangMart Type 3 Gateway - Seller-Managed Gateway"
|
|
309
|
+
nssm set LangMartGateway Start SERVICE_AUTO_START
|
|
310
|
+
|
|
311
|
+
# Set environment variables for the service
|
|
312
|
+
$envVars = @(
|
|
313
|
+
"INSTANCE_ID=$instanceId",
|
|
314
|
+
"GATEWAY_PORT=$Port",
|
|
315
|
+
"MARKETPLACE_URL=$MarketplaceUrl",
|
|
316
|
+
"GATEWAY_API_KEY=$ApiKey",
|
|
317
|
+
"GATEWAY_CAPABILITIES=$Capabilities",
|
|
318
|
+
"NODE_ENV=production"
|
|
319
|
+
) -join "`n"
|
|
320
|
+
nssm set LangMartGateway AppEnvironmentExtra $envVars
|
|
321
|
+
|
|
322
|
+
Write-Success "Windows Service installed"
|
|
323
|
+
Write-Info " Start: nssm start LangMartGateway"
|
|
324
|
+
Write-Info " Stop: nssm stop LangMartGateway"
|
|
325
|
+
Write-Info " Status: nssm status LangMartGateway"
|
|
326
|
+
Write-Info " Logs: nssm edit LangMartGateway (configure stdout/stderr)"
|
|
327
|
+
}
|
|
328
|
+
} else {
|
|
329
|
+
Write-Info "[6/6] Skipping Windows Service installation..."
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
Write-Host ""
|
|
333
|
+
Write-Host "===============================================================" -ForegroundColor Green
|
|
334
|
+
Write-Host " Installation Complete! " -ForegroundColor Green
|
|
335
|
+
Write-Host "===============================================================" -ForegroundColor Green
|
|
336
|
+
Write-Host ""
|
|
337
|
+
Write-Info "Installation Directory: $InstallDir"
|
|
338
|
+
Write-Info "Gateway Port: $Port"
|
|
339
|
+
Write-Info "Marketplace URL: $MarketplaceUrl"
|
|
340
|
+
|
|
341
|
+
if ($Capabilities -eq "session,llm") {
|
|
342
|
+
Write-Info "Mode: Full (DevOps + LLM Routing)"
|
|
343
|
+
} else {
|
|
344
|
+
Write-Info "Mode: LLM Routing Only"
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
Write-Host ""
|
|
348
|
+
if ([string]::IsNullOrEmpty($ApiKey)) {
|
|
349
|
+
Write-Warning "Before starting, configure your API key:"
|
|
350
|
+
Write-Info " 1. Edit $InstallDir\.env"
|
|
351
|
+
Write-Info " 2. Set GATEWAY_API_KEY=your-api-key"
|
|
352
|
+
Write-Host ""
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
Write-Warning "To start the gateway:"
|
|
356
|
+
if ($Service) {
|
|
357
|
+
Write-Info " nssm start LangMartGateway"
|
|
358
|
+
} else {
|
|
359
|
+
Write-Info " cd $InstallDir"
|
|
360
|
+
Write-Info " .\start.ps1"
|
|
361
|
+
Write-Info " # Or: .\start.bat"
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
Write-Host ""
|
|
365
|
+
Write-Warning "To verify installation:"
|
|
366
|
+
Write-Info " Invoke-RestMethod http://localhost:$Port/health"
|
|
367
|
+
Write-Host ""
|