langmart-gateway-type3
v3.0.19
Published
LangMart Type 3 Gateway - Seller-Managed Gateway with Local Vault
Maintainers
Readme
Gateway Type 3 - Seller-Managed Gateway
Overview
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.
Architecture
- Deployment: Seller's own infrastructure
- Credentials: Seller's own API keys
- Connection: WebSocket client to marketplace
- Control: Fully managed by seller
Features
- Persistent WebSocket connection
- Automatic reconnection with exponential backoff
- Heartbeat monitoring
- Request/response routing to provider APIs
- Version management with auto-upgrade notifications
- Interactive CLI UI with chat interface and model management
- Intelligent Image Generation with keyword-based auto-detection
- Terminal Image Preview for generated images
- Automation Mode: Full session management with bash, SSH, and system tools
🚀 Quick Install (Recommended)
Linux/macOS
Install the gateway on any Linux/macOS server with a single command:
# Using unpkg CDN (recommended)
curl -fsSL https://unpkg.com/langmart-gateway-type3/scripts/install.sh | bash -s -- \
--marketplace-url ws://your-marketplace:8081 \
--api-key YOUR_API_KEY \
--full \
--serviceWindows (PowerShell)
Install on Windows using PowerShell:
# One-liner installation
$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
# Or download and run with parameters
iwr -OutFile install.ps1 https://unpkg.com/langmart-gateway-type3/scripts/install.ps1
.\install.ps1 -MarketplaceUrl "ws://your-marketplace:8081" -ApiKey "YOUR_API_KEY" -Full -ServiceInstall Options
Linux/macOS (Bash)
| Option | Description | Default |
|--------|-------------|---------|
| --marketplace-url URL | Marketplace WebSocket URL | ws://localhost:8081 |
| --api-key KEY | Gateway API key for authentication | (none) |
| --port PORT | Gateway port | 8083 |
| --install-dir DIR | Installation directory | /opt/langmart-gateway |
| --capabilities CAPS | Capabilities: session,llm or llm | llm |
| --full | Enable full capabilities (Automation + LLM) | (disabled) |
| --service | Install as systemd service | (disabled) |
Windows (PowerShell)
| Parameter | Description | Default |
|-----------|-------------|---------|
| -MarketplaceUrl URL | Marketplace WebSocket URL | ws://localhost:8081 |
| -ApiKey KEY | Gateway API key for authentication | (none) |
| -Port PORT | Gateway port | 8083 |
| -InstallDir DIR | Installation directory | C:\langmart-gateway |
| -Capabilities CAPS | Capabilities: session,llm or llm | llm |
| -Full | Enable full capabilities (Automation + LLM) | (disabled) |
| -Service | Install as Windows Service (requires nssm) | (disabled) |
Examples
Linux/macOS
# LLM routing only (default)
curl -fsSL https://unpkg.com/langmart-gateway-type3/scripts/install.sh | bash -s -- \
--marketplace-url ws://10.0.1.117:8081 \
--api-key sk-test-inference-key
# Full Automation mode with systemd service
curl -fsSL https://unpkg.com/langmart-gateway-type3/scripts/install.sh | bash -s -- \
--marketplace-url ws://10.0.1.117:8081 \
--api-key sk-test-inference-key \
--full \
--service
# Custom port and directory
curl -fsSL https://unpkg.com/langmart-gateway-type3/scripts/install.sh | bash -s -- \
--marketplace-url ws://10.0.1.117:8081 \
--api-key sk-test-inference-key \
--port 9000 \
--install-dir /home/user/gatewayWindows
# LLM routing only (default)
.\install.ps1 -MarketplaceUrl "ws://10.0.1.117:8081" -ApiKey "sk-test-inference-key"
# Full Automation mode with Windows Service
.\install.ps1 -MarketplaceUrl "ws://10.0.1.117:8081" -ApiKey "sk-test-inference-key" -Full -Service
# Custom port and directory
.\install.ps1 -MarketplaceUrl "ws://10.0.1.117:8081" -ApiKey "sk-test-inference-key" -Port 9000 -InstallDir "D:\gateway"Alternative CDN
# Linux/macOS - Using jsdelivr
curl -fsSL https://cdn.jsdelivr.net/npm/langmart-gateway-type3/scripts/install.sh | bash -s -- [OPTIONS]# Windows - Using jsdelivr
iwr -useb https://cdn.jsdelivr.net/npm/langmart-gateway-type3/scripts/install.ps1 | iex📦 Manual Installation
Option 1: npm install
# Create installation directory
mkdir -p /opt/langmart-gateway && cd /opt/langmart-gateway
# Initialize and install
npm init -y
npm install langmart-gateway-type3
# Create .env file
cat > .env << EOF
INSTANCE_ID=gw3-$(hostname)-$(date +%s | tail -c 5)
GATEWAY_PORT=8083
MARKETPLACE_URL=ws://your-marketplace:8081
GATEWAY_API_KEY=your-api-key
GATEWAY_CAPABILITIES=llm
NODE_ENV=production
EOF
# Start the gateway
node node_modules/langmart-gateway-type3/dist/index-server.jsOption 2: Clone and Build
# Clone the repository
git clone https://github.com/YiHuangDB/LangMartDesign.git
cd LangMartDesign/gateway-type3
# Install dependencies
npm install
# Build TypeScript
npm run build
# Configure
cp .env.example .env
# Edit .env with your settings
# Start
npm start⚙️ Configuration
Environment Variables
# Gateway identification
INSTANCE_ID=gw3-server-001 # Gateway identifier (auto-generated if not set)
GATEWAY_PORT=8083 # Gateway HTTP/WebSocket port
# Marketplace connection
MARKETPLACE_URL=ws://localhost:8081 # Marketplace WebSocket URL
GATEWAY_API_KEY=sk-your-key # Marketplace API key
# Capabilities
GATEWAY_CAPABILITIES=llm # "llm" or "session,llm" for full Automation
# Local vault (for storing provider API keys)
VAULT_PATH=.vault/credentials.enc # Encrypted vault path
VAULT_PASSWORD=random-secure-password # Vault encryption password
# Provider API Keys (seller's own keys - stored in vault)
OPENAI_API_KEY=sk-... # OpenAI API key
ANTHROPIC_API_KEY=sk-ant-... # Anthropic API key
GROQ_API_KEY=gsk_... # Groq API keyCapability Modes
| Mode | GATEWAY_CAPABILITIES | Description |
|------|---------------------|-------------|
| LLM Only | llm | Routes LLM requests to providers (default) |
| Full Automation | session,llm | LLM routing + bash, SSH, file ops, system tools |
🏃 Running
Manual Start
cd /opt/langmart-gateway
# If installed via npm
./start.sh
# Or directly
node node_modules/langmart-gateway-type3/dist/index-server.jsSystemd Service
If installed with --service:
# Start
sudo systemctl start langmart-gateway
# Stop
sudo systemctl stop langmart-gateway
# Status
sudo systemctl status langmart-gateway
# Logs
sudo journalctl -u langmart-gateway -fVerify Installation
# Health check
curl http://localhost:8083/health
# Expected response:
{
"status": "healthy",
"gatewayId": "gw3-server-12345",
"capabilities": ["session", "llm"],
"tools": 18
}How It Works
- Connection: Gateway connects to marketplace via WebSocket
- Authentication: Authenticates using marketplace API key
- Registration: Registers available models and capabilities
- Requests: Receives inference requests from marketplace
- Processing: Routes requests to appropriate provider using seller's keys
- Response: Streams responses back to marketplace
Interactive CLI UI
Overview
Gateway Type 3 includes a powerful interactive CLI UI built with React Ink that provides a rich terminal-based interface for:
- Chat conversations with LLM models
- Model management and browsing
- Connection management
- Automatic image generation with keyword detection
- Terminal-based image previews
Running the CLI UI
Local Development
# Start the interactive UI locally
npm run ui
# Or with debug mode
npm run ui:debugDocker Container
# Access the UI in a running Docker container
docker exec -it <container-name> npm run ui
# Example with actual container name
docker exec -it langmart-gw3-aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa npm run uiChat Interface Features
Basic Chat
The CLI UI provides a split-screen interface with:
- Top Panel: Chat conversation history
- Bottom Panel: Input field with autocomplete support
- Status Bar: Current model, connection status, and user info
Model Selection
Press Tab key to enter model selection mode where you can:
- Browse available models
- Filter models by typing keywords (AND-condition search)
- View model details (pricing, context window, capabilities)
- Select models from your own connections or the marketplace
Slash Commands
Type / to see available commands:
/clear- Clear conversation history/connections- List your connections/models- Browse and filter models/vault- Manage API keys/help- Show available commands
🎨 Intelligent Image Generation
Overview
The CLI UI automatically detects when you want to generate an image and seamlessly switches from the chat completion API to the image generation API. No special commands needed!
How It Works
The image detection system analyzes your input for:
Action Keywords (what you want to do):
generatecreatedrawmakeproducedesign
Subject Keywords (what to generate):
imagepicturephotoillustrationartworkvisual
When both an action keyword AND a subject keyword are detected, and your selected model has image_gen capability, the CLI automatically:
- Extracts the clean prompt
- Calls the image generation API (
/v1/images/generations) - Displays the image preview in the terminal
- Saves the conversation history
Example Prompts
✅ These will trigger image generation:
generate an image of a sunset over mountains
create a picture of a futuristic city
draw an illustration of a cat wearing a hat
make a photo of abstract art
produce artwork of a forest landscape
design a visual of a cyberpunk street scene❌ These will use regular chat:
what is a sunset? (no subject keyword)
tell me about images (no action keyword)
how do I create a website? (wrong context)Automatic Prompt Cleaning
The system automatically removes action phrases from your prompt to extract the clean description:
Input:
generate an image of a beautiful sunset over mountainsExtracted Prompt:
a beautiful sunset over mountainsThis ensures the image generation API receives clean, descriptive prompts.
Model Requirements
For image generation to work:
- Your selected model MUST have
image_gencapability - The model must support the
/v1/images/generationsendpoint - Compatible models include: DALL-E, Stable Diffusion, and similar image generation models
Terminal Image Preview
When an image is generated, you'll see:
- ✅ Success confirmation message
- The prompt used for generation
- Terminal-based image preview (ASCII/pixel art rendering)
- Note about terminal resolution limitations
The preview uses 50% of your terminal width/height for optimal display.
Image Generation API Call
Behind the scenes, the CLI calls:
POST /v1/images/generations
{
"model": "your-selected-model",
"prompt": "extracted-clean-prompt",
"n": 1,
"size": "1024x1024",
"response_format": "b64_json"
}The response is automatically:
- Decoded from base64
- Converted to terminal-friendly display format
- Rendered in the chat interface
- Added to conversation history
Advanced Features
Keyword-Based Filtering
In model selection mode, type keywords to filter:
groq llama # Shows only Groq models with "llama" in name
openai gpt-4 # Shows only OpenAI GPT-4 models
image gen # Shows only models with image generationMultiple keywords use AND logic - all must match.
Autocomplete Support
Type / and the CLI will suggest commands:
- Type
/c→ suggests/clear - Press
Tabto accept suggestion - Cursor automatically positioned at end
Tool Calling
The CLI supports native function calling with:
- Marketplace tools (connections, models, vault, logs)
- Web tools (search, fetch)
- Core tools (system operations)
- MCP tools (Model Context Protocol servers)
Conversation Persistence
Conversations are automatically saved to:
~/.gateway-type3/sessions/<session-id>.jsonThis allows resuming conversations across sessions.
Troubleshooting
Image Generation Not Working
Problem: Image generation doesn't trigger Solutions:
- Verify your model has
image_gencapability - Include both action and subject keywords
- Check model is properly selected (not "No model selected")
- Verify marketplace connection is active
Problem: Image preview not showing Solutions:
- Check terminal supports image rendering
- Verify
terminal-imagepackage is installed - Check Docker container has necessary dependencies
- Review logs for base64 decode errors
Connection Issues
Problem: CLI shows "Not connected" Solutions:
- Verify Gateway Type 3 server is running
- Check
MARKETPLACE_URLenvironment variable - Ensure API key is valid and authenticated
- Review gateway logs for connection errors
Model List Empty
Problem: No models shown in model selection Solutions:
- Wait for initial model sync to complete
- Verify connections are configured and active
- Check API keys are valid in vault
- Run
/connectionsto verify connection status
Docker-Specific Instructions
Running in Docker
When using the Docker container, you can access the CLI UI by:
# 1. Find your container name
docker ps | grep type3
# 2. Access the interactive UI
docker exec -it <container-name> npm run ui
# 3. Exit the UI
# Press Ctrl+C to exit back to shellEnvironment Variables for Docker
The container needs these environment variables:
GATEWAY_API_KEY=sk-test-inference-key # Your marketplace API key
MARKETPLACE_URL=ws://localhost:8081 # WebSocket URL for gateway connection
MARKETPLACE_API_URL=http://localhost:8081 # HTTP URL for REST API calls
USER_ID=aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa # Your user IDImportant: The Docker container needs both URLs:
MARKETPLACE_URL(ws://) for WebSocket gateway connectionMARKETPLACE_API_URL(http://) for REST API calls (models, connections, etc.)
Persistent Data in Docker
The container uses volumes to persist:
/app/data/vault- API keys and credentials/app/data/config- Gateway configuration/root/.gateway-type3/sessions- Conversation history
Make sure to mount these volumes when creating the container:
docker run -d \
--name my-gateway-type3 \
--network host \
-e GATEWAY_API_KEY=sk-test-inference-key \
-e MARKETPLACE_URL=ws://localhost:8081 \
-e MARKETPLACE_API_URL=http://localhost:8081 \
-v gateway-type3-data:/app/data \
langmart-gateway-type3-ui:latestCode Reference
Image Detection Logic
Located in: cli-split-layout.tsx (lines 1701-1746)
The detectImageGeneration() function:
- Checks if model has
image_gencapability - Detects action and subject keywords
- Extracts clean prompt using regex patterns
- Returns detection result with cleaned prompt
Image Generation Function
Located in: cli-split-layout.tsx (lines 1748-1823)
The generateImage() function:
- Calls
/v1/images/generationsAPI - Receives base64-encoded image data
- Converts to terminal display format
- Renders in chat interface
- Saves to conversation history
Chat Message Handler
Located in: cli-split-layout.tsx (lines 1825-1860)
The sendChatMessage() function:
- Checks for image generation intent first
- If detected, calls
generateImage()and returns - Otherwise, proceeds with chat completion API
Tips and Best Practices
For Best Image Results
- Use descriptive, detailed prompts
- Include style keywords (e.g., "photorealistic", "watercolor", "3D render")
- Specify composition (e.g., "close-up", "wide angle", "aerial view")
- Add lighting details (e.g., "golden hour", "studio lighting", "neon lights")
Example High-Quality Prompts
generate an image of a photorealistic sunset over snow-capped mountains,
golden hour lighting, wide angle view
create a picture of a cyberpunk street scene at night, neon signs,
rain-soaked streets, cinematic lighting
draw an illustration of a magical forest with glowing mushrooms,
fantasy art style, ethereal atmosphereFor Better Terminal Experience
- Use a terminal with good Unicode support
- Increase terminal font size for better image preview
- Use a color-capable terminal (256-color or true-color)
- Maximize terminal window for larger previews
Related Documentation
- Gateway Server: See main README sections above for server operations
- Tool Calling: See
marketplace-tools.tsfor available marketplace tools - MCP Integration: See
mcp-manager.tsfor Model Context Protocol support - Local Vault: See
local-vault.tsfor credential management - Web Tools: See
web-tools.tsfor web search and fetch capabilities
WebSocket Protocol
Connection
ws://marketplace.api/gateway
Headers: {
'Authorization': 'Bearer sk-...',
'X-Gateway-ID': 'gw3-seller-001'
}Message Types
auth: Authentication handshakeheartbeat: Keep-alive ping/pongrequest: Inference request from marketplaceresponse: Streaming response to marketplaceerror: Error notificationupdate: Version/configuration updates
Monitoring
The gateway emits events for monitoring:
connected: Successfully connected to marketplacedisconnected: Connection losterror: Error occurredrequest: Processing requestrequest_complete: Request completed
Security
- TLS/SSL WebSocket connection
- API key authentication
- Request signing
- Rate limiting
- IP whitelisting (optional)
Dependencies
ws: WebSocket clientaxios: HTTP client for provider APIsuuid: Request ID generation
Troubleshooting
Connection Issues
- Check firewall rules for WebSocket
- Verify marketplace URL
- Ensure API key is valid
Provider Errors
- Verify provider API keys
- Check rate limits
- Monitor provider status
Performance
- Monitor latency metrics
- Check network connectivity
- Consider geographic proximity
