langmart-gateway-type3 3.0.0
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/.env.example +29 -0
- package/README.md +480 -0
- package/dist/bash-tools.d.ts +56 -0
- package/dist/bash-tools.d.ts.map +1 -0
- package/dist/bash-tools.js +188 -0
- package/dist/bash-tools.js.map +1 -0
- package/dist/core-tools.d.ts +94 -0
- package/dist/core-tools.d.ts.map +1 -0
- package/dist/core-tools.js +694 -0
- package/dist/core-tools.js.map +1 -0
- package/dist/debug-utils.d.ts +22 -0
- package/dist/debug-utils.d.ts.map +1 -0
- package/dist/debug-utils.js +37 -0
- package/dist/debug-utils.js.map +1 -0
- package/dist/devops-tools.d.ts +147 -0
- package/dist/devops-tools.d.ts.map +1 -0
- package/dist/devops-tools.js +718 -0
- package/dist/devops-tools.js.map +1 -0
- package/dist/gateway-config.d.ts +56 -0
- package/dist/gateway-config.d.ts.map +1 -0
- package/dist/gateway-config.js +198 -0
- package/dist/gateway-config.js.map +1 -0
- package/dist/gateway-mode.d.ts +58 -0
- package/dist/gateway-mode.d.ts.map +1 -0
- package/dist/gateway-mode.js +240 -0
- package/dist/gateway-mode.js.map +1 -0
- package/dist/gateway-server.d.ts +208 -0
- package/dist/gateway-server.d.ts.map +1 -0
- package/dist/gateway-server.js +1811 -0
- package/dist/gateway-server.js.map +1 -0
- package/dist/headless-session.d.ts +192 -0
- package/dist/headless-session.d.ts.map +1 -0
- package/dist/headless-session.js +584 -0
- package/dist/headless-session.js.map +1 -0
- package/dist/index-server.d.ts +4 -0
- package/dist/index-server.d.ts.map +1 -0
- package/dist/index-server.js +129 -0
- package/dist/index-server.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +101 -0
- package/dist/index.js.map +1 -0
- package/dist/key-vault.d.ts +102 -0
- package/dist/key-vault.d.ts.map +1 -0
- package/dist/key-vault.js +365 -0
- package/dist/key-vault.js.map +1 -0
- package/dist/local-vault.d.ts +195 -0
- package/dist/local-vault.d.ts.map +1 -0
- package/dist/local-vault.js +571 -0
- package/dist/local-vault.js.map +1 -0
- package/dist/marketplace-tools.d.ts +104 -0
- package/dist/marketplace-tools.d.ts.map +1 -0
- package/dist/marketplace-tools.js +2846 -0
- package/dist/marketplace-tools.js.map +1 -0
- package/dist/mcp-manager.d.ts +114 -0
- package/dist/mcp-manager.d.ts.map +1 -0
- package/dist/mcp-manager.js +338 -0
- package/dist/mcp-manager.js.map +1 -0
- package/dist/web-tools.d.ts +86 -0
- package/dist/web-tools.d.ts.map +1 -0
- package/dist/web-tools.js +431 -0
- package/dist/web-tools.js.map +1 -0
- package/dist/websocket-handler.d.ts +131 -0
- package/dist/websocket-handler.d.ts.map +1 -0
- package/dist/websocket-handler.js +596 -0
- package/dist/websocket-handler.js.map +1 -0
- package/dist/welcome-pages.d.ts +6 -0
- package/dist/welcome-pages.d.ts.map +1 -0
- package/dist/welcome-pages.js +200 -0
- package/dist/welcome-pages.js.map +1 -0
- package/package.json +168 -0
- package/scripts/install-remote.sh +282 -0
- package/scripts/start.sh +85 -0
- package/scripts/status.sh +79 -0
- package/scripts/stop.sh +67 -0
package/.env.example
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Gateway Type 3 Configuration
|
|
2
|
+
# Seller-managed gateway with local vault for provider credentials
|
|
3
|
+
|
|
4
|
+
# Gateway identification
|
|
5
|
+
INSTANCE_ID=gw3-local-001
|
|
6
|
+
GATEWAY_PORT=8083
|
|
7
|
+
|
|
8
|
+
# Marketplace connection
|
|
9
|
+
MARKETPLACE_URL=ws://10.0.1.117:8081
|
|
10
|
+
|
|
11
|
+
# Gateway authentication (required for marketplace connection)
|
|
12
|
+
GATEWAY_API_KEY=sk-test-inference-key
|
|
13
|
+
# Alternative: API_KEY=sk-test-inference-key
|
|
14
|
+
|
|
15
|
+
# Local vault configuration
|
|
16
|
+
VAULT_PATH=.vault/credentials.enc
|
|
17
|
+
VAULT_PASSWORD=my-secure-vault-password
|
|
18
|
+
|
|
19
|
+
# Provider API keys (for initial vault setup)
|
|
20
|
+
# These are read once to initialize the vault, then stored encrypted
|
|
21
|
+
GROQ_API_KEY=gsk_your_groq_api_key_here
|
|
22
|
+
OPENAI_API_KEY=sk-your_openai_api_key_here
|
|
23
|
+
ANTHROPIC_API_KEY=sk-ant-your_anthropic_api_key_here
|
|
24
|
+
GOOGLE_API_KEY=your_google_api_key_here
|
|
25
|
+
DEEPSEEK_API_KEY=sk-your_deepseek_api_key_here
|
|
26
|
+
MISTRAL_API_KEY=your_mistral_api_key_here
|
|
27
|
+
|
|
28
|
+
# Environment
|
|
29
|
+
NODE_ENV=development
|
package/README.md
ADDED
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
# Gateway Type 3 - Seller-Managed Gateway
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
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
|
+
|
|
6
|
+
## Architecture
|
|
7
|
+
- **Deployment**: Seller's own infrastructure
|
|
8
|
+
- **Credentials**: Seller's own API keys
|
|
9
|
+
- **Connection**: WebSocket client to marketplace
|
|
10
|
+
- **Control**: Fully managed by seller
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
- Persistent WebSocket connection
|
|
14
|
+
- Automatic reconnection with exponential backoff
|
|
15
|
+
- Heartbeat monitoring
|
|
16
|
+
- Request/response routing to provider APIs
|
|
17
|
+
- Version management with auto-upgrade notifications
|
|
18
|
+
- **Interactive CLI UI** with chat interface and model management
|
|
19
|
+
- **Intelligent Image Generation** with keyword-based auto-detection
|
|
20
|
+
- **Terminal Image Preview** for generated images
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Install dependencies
|
|
26
|
+
npm install
|
|
27
|
+
|
|
28
|
+
# Build TypeScript
|
|
29
|
+
npm run build
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
Environment variables:
|
|
35
|
+
```bash
|
|
36
|
+
GATEWAY3_ID=gw3-seller-001 # Gateway identifier
|
|
37
|
+
GATEWAY3_API_KEY=sk-test-001 # Marketplace API key
|
|
38
|
+
MARKETPLACE_URL=ws://localhost:8090 # Marketplace WebSocket URL
|
|
39
|
+
|
|
40
|
+
# Provider API Keys (seller's own keys)
|
|
41
|
+
OPENAI_API_KEY=sk-... # OpenAI API key
|
|
42
|
+
ANTHROPIC_API_KEY=sk-ant-... # Anthropic API key
|
|
43
|
+
GOOGLE_API_KEY=... # Google API key
|
|
44
|
+
DEEPSEEK_API_KEY=sk-... # DeepSeek API key
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Running
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Development mode (with TypeScript)
|
|
51
|
+
npm run dev
|
|
52
|
+
|
|
53
|
+
# Production mode (compiled JavaScript)
|
|
54
|
+
npm start
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## How It Works
|
|
58
|
+
|
|
59
|
+
1. **Connection**: Gateway connects to marketplace via WebSocket
|
|
60
|
+
2. **Authentication**: Authenticates using marketplace API key
|
|
61
|
+
3. **Registration**: Registers available models and capabilities
|
|
62
|
+
4. **Requests**: Receives inference requests from marketplace
|
|
63
|
+
5. **Processing**: Routes requests to appropriate provider using seller's keys
|
|
64
|
+
6. **Response**: Streams responses back to marketplace
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
# Interactive CLI UI
|
|
69
|
+
|
|
70
|
+
## Overview
|
|
71
|
+
|
|
72
|
+
Gateway Type 3 includes a powerful interactive CLI UI built with React Ink that provides a rich terminal-based interface for:
|
|
73
|
+
- Chat conversations with LLM models
|
|
74
|
+
- Model management and browsing
|
|
75
|
+
- Connection management
|
|
76
|
+
- **Automatic image generation** with keyword detection
|
|
77
|
+
- Terminal-based image previews
|
|
78
|
+
|
|
79
|
+
## Running the CLI UI
|
|
80
|
+
|
|
81
|
+
### Local Development
|
|
82
|
+
```bash
|
|
83
|
+
# Start the interactive UI locally
|
|
84
|
+
npm run ui
|
|
85
|
+
|
|
86
|
+
# Or with debug mode
|
|
87
|
+
npm run ui:debug
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Docker Container
|
|
91
|
+
```bash
|
|
92
|
+
# Access the UI in a running Docker container
|
|
93
|
+
docker exec -it <container-name> npm run ui
|
|
94
|
+
|
|
95
|
+
# Example with actual container name
|
|
96
|
+
docker exec -it langmart-gw3-aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa npm run ui
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Chat Interface Features
|
|
100
|
+
|
|
101
|
+
### Basic Chat
|
|
102
|
+
The CLI UI provides a split-screen interface with:
|
|
103
|
+
- **Top Panel**: Chat conversation history
|
|
104
|
+
- **Bottom Panel**: Input field with autocomplete support
|
|
105
|
+
- **Status Bar**: Current model, connection status, and user info
|
|
106
|
+
|
|
107
|
+
### Model Selection
|
|
108
|
+
Press `Tab` key to enter model selection mode where you can:
|
|
109
|
+
- Browse available models
|
|
110
|
+
- Filter models by typing keywords (AND-condition search)
|
|
111
|
+
- View model details (pricing, context window, capabilities)
|
|
112
|
+
- Select models from your own connections or the marketplace
|
|
113
|
+
|
|
114
|
+
### Slash Commands
|
|
115
|
+
Type `/` to see available commands:
|
|
116
|
+
- `/clear` - Clear conversation history
|
|
117
|
+
- `/connections` - List your connections
|
|
118
|
+
- `/models` - Browse and filter models
|
|
119
|
+
- `/vault` - Manage API keys
|
|
120
|
+
- `/help` - Show available commands
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 🎨 Intelligent Image Generation
|
|
125
|
+
|
|
126
|
+
### Overview
|
|
127
|
+
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!
|
|
128
|
+
|
|
129
|
+
### How It Works
|
|
130
|
+
|
|
131
|
+
The image detection system analyzes your input for:
|
|
132
|
+
|
|
133
|
+
1. **Action Keywords** (what you want to do):
|
|
134
|
+
- `generate`
|
|
135
|
+
- `create`
|
|
136
|
+
- `draw`
|
|
137
|
+
- `make`
|
|
138
|
+
- `produce`
|
|
139
|
+
- `design`
|
|
140
|
+
|
|
141
|
+
2. **Subject Keywords** (what to generate):
|
|
142
|
+
- `image`
|
|
143
|
+
- `picture`
|
|
144
|
+
- `photo`
|
|
145
|
+
- `illustration`
|
|
146
|
+
- `artwork`
|
|
147
|
+
- `visual`
|
|
148
|
+
|
|
149
|
+
When **both** an action keyword AND a subject keyword are detected, and your selected model has `image_gen` capability, the CLI automatically:
|
|
150
|
+
1. Extracts the clean prompt
|
|
151
|
+
2. Calls the image generation API (`/v1/images/generations`)
|
|
152
|
+
3. Displays the image preview in the terminal
|
|
153
|
+
4. Saves the conversation history
|
|
154
|
+
|
|
155
|
+
### Example Prompts
|
|
156
|
+
|
|
157
|
+
✅ **These will trigger image generation:**
|
|
158
|
+
```
|
|
159
|
+
generate an image of a sunset over mountains
|
|
160
|
+
create a picture of a futuristic city
|
|
161
|
+
draw an illustration of a cat wearing a hat
|
|
162
|
+
make a photo of abstract art
|
|
163
|
+
produce artwork of a forest landscape
|
|
164
|
+
design a visual of a cyberpunk street scene
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
❌ **These will use regular chat:**
|
|
168
|
+
```
|
|
169
|
+
what is a sunset? (no subject keyword)
|
|
170
|
+
tell me about images (no action keyword)
|
|
171
|
+
how do I create a website? (wrong context)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Automatic Prompt Cleaning
|
|
175
|
+
|
|
176
|
+
The system automatically removes action phrases from your prompt to extract the clean description:
|
|
177
|
+
|
|
178
|
+
**Input:**
|
|
179
|
+
```
|
|
180
|
+
generate an image of a beautiful sunset over mountains
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**Extracted Prompt:**
|
|
184
|
+
```
|
|
185
|
+
a beautiful sunset over mountains
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
This ensures the image generation API receives clean, descriptive prompts.
|
|
189
|
+
|
|
190
|
+
### Model Requirements
|
|
191
|
+
|
|
192
|
+
For image generation to work:
|
|
193
|
+
- Your selected model MUST have `image_gen` capability
|
|
194
|
+
- The model must support the `/v1/images/generations` endpoint
|
|
195
|
+
- Compatible models include: DALL-E, Stable Diffusion, and similar image generation models
|
|
196
|
+
|
|
197
|
+
### Terminal Image Preview
|
|
198
|
+
|
|
199
|
+
When an image is generated, you'll see:
|
|
200
|
+
1. ✅ Success confirmation message
|
|
201
|
+
2. The prompt used for generation
|
|
202
|
+
3. **Terminal-based image preview** (ASCII/pixel art rendering)
|
|
203
|
+
4. Note about terminal resolution limitations
|
|
204
|
+
|
|
205
|
+
The preview uses 50% of your terminal width/height for optimal display.
|
|
206
|
+
|
|
207
|
+
### Image Generation API Call
|
|
208
|
+
|
|
209
|
+
Behind the scenes, the CLI calls:
|
|
210
|
+
```javascript
|
|
211
|
+
POST /v1/images/generations
|
|
212
|
+
{
|
|
213
|
+
"model": "your-selected-model",
|
|
214
|
+
"prompt": "extracted-clean-prompt",
|
|
215
|
+
"n": 1,
|
|
216
|
+
"size": "1024x1024",
|
|
217
|
+
"response_format": "b64_json"
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
The response is automatically:
|
|
222
|
+
- Decoded from base64
|
|
223
|
+
- Converted to terminal-friendly display format
|
|
224
|
+
- Rendered in the chat interface
|
|
225
|
+
- Added to conversation history
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## Advanced Features
|
|
230
|
+
|
|
231
|
+
### Keyword-Based Filtering
|
|
232
|
+
|
|
233
|
+
In model selection mode, type keywords to filter:
|
|
234
|
+
```
|
|
235
|
+
groq llama # Shows only Groq models with "llama" in name
|
|
236
|
+
openai gpt-4 # Shows only OpenAI GPT-4 models
|
|
237
|
+
image gen # Shows only models with image generation
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Multiple keywords use AND logic - all must match.
|
|
241
|
+
|
|
242
|
+
### Autocomplete Support
|
|
243
|
+
|
|
244
|
+
Type `/` and the CLI will suggest commands:
|
|
245
|
+
- Type `/c` → suggests `/clear`
|
|
246
|
+
- Press `Tab` to accept suggestion
|
|
247
|
+
- Cursor automatically positioned at end
|
|
248
|
+
|
|
249
|
+
### Tool Calling
|
|
250
|
+
|
|
251
|
+
The CLI supports native function calling with:
|
|
252
|
+
- Marketplace tools (connections, models, vault, logs)
|
|
253
|
+
- Web tools (search, fetch)
|
|
254
|
+
- Core tools (system operations)
|
|
255
|
+
- MCP tools (Model Context Protocol servers)
|
|
256
|
+
|
|
257
|
+
### Conversation Persistence
|
|
258
|
+
|
|
259
|
+
Conversations are automatically saved to:
|
|
260
|
+
```
|
|
261
|
+
~/.gateway-type3/sessions/<session-id>.json
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
This allows resuming conversations across sessions.
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Troubleshooting
|
|
269
|
+
|
|
270
|
+
### Image Generation Not Working
|
|
271
|
+
|
|
272
|
+
**Problem**: Image generation doesn't trigger
|
|
273
|
+
**Solutions**:
|
|
274
|
+
1. Verify your model has `image_gen` capability
|
|
275
|
+
2. Include both action and subject keywords
|
|
276
|
+
3. Check model is properly selected (not "No model selected")
|
|
277
|
+
4. Verify marketplace connection is active
|
|
278
|
+
|
|
279
|
+
**Problem**: Image preview not showing
|
|
280
|
+
**Solutions**:
|
|
281
|
+
1. Check terminal supports image rendering
|
|
282
|
+
2. Verify `terminal-image` package is installed
|
|
283
|
+
3. Check Docker container has necessary dependencies
|
|
284
|
+
4. Review logs for base64 decode errors
|
|
285
|
+
|
|
286
|
+
### Connection Issues
|
|
287
|
+
|
|
288
|
+
**Problem**: CLI shows "Not connected"
|
|
289
|
+
**Solutions**:
|
|
290
|
+
1. Verify Gateway Type 3 server is running
|
|
291
|
+
2. Check `MARKETPLACE_URL` environment variable
|
|
292
|
+
3. Ensure API key is valid and authenticated
|
|
293
|
+
4. Review gateway logs for connection errors
|
|
294
|
+
|
|
295
|
+
### Model List Empty
|
|
296
|
+
|
|
297
|
+
**Problem**: No models shown in model selection
|
|
298
|
+
**Solutions**:
|
|
299
|
+
1. Wait for initial model sync to complete
|
|
300
|
+
2. Verify connections are configured and active
|
|
301
|
+
3. Check API keys are valid in vault
|
|
302
|
+
4. Run `/connections` to verify connection status
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Docker-Specific Instructions
|
|
307
|
+
|
|
308
|
+
### Running in Docker
|
|
309
|
+
|
|
310
|
+
When using the Docker container, you can access the CLI UI by:
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
# 1. Find your container name
|
|
314
|
+
docker ps | grep type3
|
|
315
|
+
|
|
316
|
+
# 2. Access the interactive UI
|
|
317
|
+
docker exec -it <container-name> npm run ui
|
|
318
|
+
|
|
319
|
+
# 3. Exit the UI
|
|
320
|
+
# Press Ctrl+C to exit back to shell
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Environment Variables for Docker
|
|
324
|
+
|
|
325
|
+
The container needs these environment variables:
|
|
326
|
+
```bash
|
|
327
|
+
GATEWAY_API_KEY=sk-test-inference-key # Your marketplace API key
|
|
328
|
+
MARKETPLACE_URL=ws://localhost:8081 # WebSocket URL for gateway connection
|
|
329
|
+
MARKETPLACE_API_URL=http://localhost:8081 # HTTP URL for REST API calls
|
|
330
|
+
USER_ID=aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa # Your user ID
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
**Important**: The Docker container needs **both** URLs:
|
|
334
|
+
- `MARKETPLACE_URL` (ws://) for WebSocket gateway connection
|
|
335
|
+
- `MARKETPLACE_API_URL` (http://) for REST API calls (models, connections, etc.)
|
|
336
|
+
|
|
337
|
+
### Persistent Data in Docker
|
|
338
|
+
|
|
339
|
+
The container uses volumes to persist:
|
|
340
|
+
- `/app/data/vault` - API keys and credentials
|
|
341
|
+
- `/app/data/config` - Gateway configuration
|
|
342
|
+
- `/root/.gateway-type3/sessions` - Conversation history
|
|
343
|
+
|
|
344
|
+
Make sure to mount these volumes when creating the container:
|
|
345
|
+
```bash
|
|
346
|
+
docker run -d \
|
|
347
|
+
--name my-gateway-type3 \
|
|
348
|
+
--network host \
|
|
349
|
+
-e GATEWAY_API_KEY=sk-test-inference-key \
|
|
350
|
+
-e MARKETPLACE_URL=ws://localhost:8081 \
|
|
351
|
+
-e MARKETPLACE_API_URL=http://localhost:8081 \
|
|
352
|
+
-v gateway-type3-data:/app/data \
|
|
353
|
+
langmart-gateway-type3-ui:latest
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## Code Reference
|
|
359
|
+
|
|
360
|
+
### Image Detection Logic
|
|
361
|
+
Located in: `cli-split-layout.tsx` (lines 1701-1746)
|
|
362
|
+
|
|
363
|
+
The `detectImageGeneration()` function:
|
|
364
|
+
1. Checks if model has `image_gen` capability
|
|
365
|
+
2. Detects action and subject keywords
|
|
366
|
+
3. Extracts clean prompt using regex patterns
|
|
367
|
+
4. Returns detection result with cleaned prompt
|
|
368
|
+
|
|
369
|
+
### Image Generation Function
|
|
370
|
+
Located in: `cli-split-layout.tsx` (lines 1748-1823)
|
|
371
|
+
|
|
372
|
+
The `generateImage()` function:
|
|
373
|
+
1. Calls `/v1/images/generations` API
|
|
374
|
+
2. Receives base64-encoded image data
|
|
375
|
+
3. Converts to terminal display format
|
|
376
|
+
4. Renders in chat interface
|
|
377
|
+
5. Saves to conversation history
|
|
378
|
+
|
|
379
|
+
### Chat Message Handler
|
|
380
|
+
Located in: `cli-split-layout.tsx` (lines 1825-1860)
|
|
381
|
+
|
|
382
|
+
The `sendChatMessage()` function:
|
|
383
|
+
1. Checks for image generation intent first
|
|
384
|
+
2. If detected, calls `generateImage()` and returns
|
|
385
|
+
3. Otherwise, proceeds with chat completion API
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
## Tips and Best Practices
|
|
390
|
+
|
|
391
|
+
### For Best Image Results
|
|
392
|
+
1. Use descriptive, detailed prompts
|
|
393
|
+
2. Include style keywords (e.g., "photorealistic", "watercolor", "3D render")
|
|
394
|
+
3. Specify composition (e.g., "close-up", "wide angle", "aerial view")
|
|
395
|
+
4. Add lighting details (e.g., "golden hour", "studio lighting", "neon lights")
|
|
396
|
+
|
|
397
|
+
### Example High-Quality Prompts
|
|
398
|
+
```
|
|
399
|
+
generate an image of a photorealistic sunset over snow-capped mountains,
|
|
400
|
+
golden hour lighting, wide angle view
|
|
401
|
+
|
|
402
|
+
create a picture of a cyberpunk street scene at night, neon signs,
|
|
403
|
+
rain-soaked streets, cinematic lighting
|
|
404
|
+
|
|
405
|
+
draw an illustration of a magical forest with glowing mushrooms,
|
|
406
|
+
fantasy art style, ethereal atmosphere
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### For Better Terminal Experience
|
|
410
|
+
1. Use a terminal with good Unicode support
|
|
411
|
+
2. Increase terminal font size for better image preview
|
|
412
|
+
3. Use a color-capable terminal (256-color or true-color)
|
|
413
|
+
4. Maximize terminal window for larger previews
|
|
414
|
+
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
## Related Documentation
|
|
418
|
+
|
|
419
|
+
- **Gateway Server**: See main README sections above for server operations
|
|
420
|
+
- **Tool Calling**: See `marketplace-tools.ts` for available marketplace tools
|
|
421
|
+
- **MCP Integration**: See `mcp-manager.ts` for Model Context Protocol support
|
|
422
|
+
- **Local Vault**: See `local-vault.ts` for credential management
|
|
423
|
+
- **Web Tools**: See `web-tools.ts` for web search and fetch capabilities
|
|
424
|
+
|
|
425
|
+
## WebSocket Protocol
|
|
426
|
+
|
|
427
|
+
### Connection
|
|
428
|
+
```javascript
|
|
429
|
+
ws://marketplace.api/gateway
|
|
430
|
+
Headers: {
|
|
431
|
+
'Authorization': 'Bearer sk-...',
|
|
432
|
+
'X-Gateway-ID': 'gw3-seller-001'
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Message Types
|
|
437
|
+
- `auth`: Authentication handshake
|
|
438
|
+
- `heartbeat`: Keep-alive ping/pong
|
|
439
|
+
- `request`: Inference request from marketplace
|
|
440
|
+
- `response`: Streaming response to marketplace
|
|
441
|
+
- `error`: Error notification
|
|
442
|
+
- `update`: Version/configuration updates
|
|
443
|
+
|
|
444
|
+
## Monitoring
|
|
445
|
+
|
|
446
|
+
The gateway emits events for monitoring:
|
|
447
|
+
- `connected`: Successfully connected to marketplace
|
|
448
|
+
- `disconnected`: Connection lost
|
|
449
|
+
- `error`: Error occurred
|
|
450
|
+
- `request`: Processing request
|
|
451
|
+
- `request_complete`: Request completed
|
|
452
|
+
|
|
453
|
+
## Security
|
|
454
|
+
- TLS/SSL WebSocket connection
|
|
455
|
+
- API key authentication
|
|
456
|
+
- Request signing
|
|
457
|
+
- Rate limiting
|
|
458
|
+
- IP whitelisting (optional)
|
|
459
|
+
|
|
460
|
+
## Dependencies
|
|
461
|
+
- `ws`: WebSocket client
|
|
462
|
+
- `axios`: HTTP client for provider APIs
|
|
463
|
+
- `uuid`: Request ID generation
|
|
464
|
+
|
|
465
|
+
## Troubleshooting
|
|
466
|
+
|
|
467
|
+
### Connection Issues
|
|
468
|
+
- Check firewall rules for WebSocket
|
|
469
|
+
- Verify marketplace URL
|
|
470
|
+
- Ensure API key is valid
|
|
471
|
+
|
|
472
|
+
### Provider Errors
|
|
473
|
+
- Verify provider API keys
|
|
474
|
+
- Check rate limits
|
|
475
|
+
- Monitor provider status
|
|
476
|
+
|
|
477
|
+
### Performance
|
|
478
|
+
- Monitor latency metrics
|
|
479
|
+
- Check network connectivity
|
|
480
|
+
- Consider geographic proximity
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Bash Tools for Chat Mode
|
|
3
|
+
* Provides bash command execution without external MCP server dependency
|
|
4
|
+
*/
|
|
5
|
+
export interface BashTool {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
inputSchema: any;
|
|
9
|
+
}
|
|
10
|
+
export interface BashToolResult {
|
|
11
|
+
stdout: string;
|
|
12
|
+
stderr: string;
|
|
13
|
+
exitCode: number;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class BashTools {
|
|
17
|
+
private static instance;
|
|
18
|
+
private constructor();
|
|
19
|
+
static getInstance(): BashTools;
|
|
20
|
+
/**
|
|
21
|
+
* Get available bash tools
|
|
22
|
+
*/
|
|
23
|
+
getTools(): BashTool[];
|
|
24
|
+
/**
|
|
25
|
+
* Execute a bash tool
|
|
26
|
+
*/
|
|
27
|
+
executeTool(toolName: string, args: any): Promise<BashToolResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Format tools for AI system prompt
|
|
30
|
+
*/
|
|
31
|
+
formatToolsForPrompt(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Parse tool call from AI response
|
|
34
|
+
*/
|
|
35
|
+
parseToolCall(response: string): {
|
|
36
|
+
tool: string;
|
|
37
|
+
args: any;
|
|
38
|
+
} | null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Usage Example:
|
|
42
|
+
*
|
|
43
|
+
* const bashTools = BashTools.getInstance();
|
|
44
|
+
*
|
|
45
|
+
* // Get available tools
|
|
46
|
+
* const tools = bashTools.getTools();
|
|
47
|
+
*
|
|
48
|
+
* // Execute a command
|
|
49
|
+
* const result = await bashTools.executeTool('bash.execute_command', {
|
|
50
|
+
* command: 'ls -la'
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // Add tools to AI prompt
|
|
54
|
+
* const systemPrompt = "You are a helpful assistant." + bashTools.formatToolsForPrompt();
|
|
55
|
+
*/
|
|
56
|
+
//# sourceMappingURL=bash-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bash-tools.d.ts","sourceRoot":"","sources":["../bash-tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,SAAS;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA0B;IAEjD,OAAO;WAEO,WAAW,IAAI,SAAS;IAOtC;;OAEG;IACI,QAAQ,IAAI,QAAQ,EAAE;IAoE7B;;OAEG;IACU,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC;IA2D9E;;OAEG;IACI,oBAAoB,IAAI,MAAM;IASrC;;OAEG;IACI,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,GAAG,IAAI;CAe7E;AAED;;;;;;;;;;;;;;;GAeG"}
|