@agentxjs/portagent 0.1.9 → 1.0.1
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 +357 -0
- package/dist/public/Portagent.gif +0 -0
- package/dist/public/assets/{index-CNC7DxMj.js → index-Cc0Cei9e.js} +62 -62
- package/dist/public/assets/index-Cc0Cei9e.js.map +1 -0
- package/dist/public/assets/reconnecting-websocket-mjs-Dd04wD44.js +20 -0
- package/dist/public/assets/reconnecting-websocket-mjs-Dd04wD44.js.map +1 -0
- package/dist/public/index.html +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/public/assets/index-CNC7DxMj.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
# Portagent
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Portagent is a multi-user AI Agent gateway powered by [AgentX](https://github.com/Deepractice/AgentX). It provides a web-based interface for interacting with Claude AI agents, with built-in user authentication and session management.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Multi-User Support**: User registration and authentication with JWT tokens
|
|
10
|
+
- **WebSocket Communication**: Real-time bidirectional communication with AI agents
|
|
11
|
+
- **Invite Code System**: Optional invite code for controlled access
|
|
12
|
+
- **Persistent Storage**: SQLite-based storage for users, sessions, and agent data
|
|
13
|
+
- **Docker Ready**: Pre-built Docker images for easy deployment
|
|
14
|
+
- **Claude Integration**: Powered by Anthropic's Claude API via Claude Agent SDK
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
### Using Docker (Recommended)
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
docker run -d \
|
|
22
|
+
--name portagent \
|
|
23
|
+
-p 5200:5200 \
|
|
24
|
+
-e LLM_PROVIDER_KEY=sk-ant-xxxxx \
|
|
25
|
+
-v ./data:/home/agentx/.agentx \
|
|
26
|
+
deepracticexs/portagent:latest
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Then open <http://localhost:5200> in your browser.
|
|
30
|
+
|
|
31
|
+
### Using Docker Compose
|
|
32
|
+
|
|
33
|
+
Create a `.env` file:
|
|
34
|
+
|
|
35
|
+
```env
|
|
36
|
+
LLM_PROVIDER_KEY=sk-ant-xxxxx
|
|
37
|
+
JWT_SECRET=your-secure-random-secret
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Create `docker-compose.yml`:
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
services:
|
|
44
|
+
portagent:
|
|
45
|
+
image: deepracticexs/portagent:latest
|
|
46
|
+
container_name: portagent
|
|
47
|
+
restart: unless-stopped
|
|
48
|
+
ports:
|
|
49
|
+
- "5200:5200"
|
|
50
|
+
environment:
|
|
51
|
+
- LLM_PROVIDER_KEY=${LLM_PROVIDER_KEY}
|
|
52
|
+
- LLM_PROVIDER_URL=${LLM_PROVIDER_URL:-https://api.anthropic.com}
|
|
53
|
+
- LLM_PROVIDER_MODEL=${LLM_PROVIDER_MODEL:-claude-sonnet-4-20250514}
|
|
54
|
+
- JWT_SECRET=${JWT_SECRET}
|
|
55
|
+
- INVITE_CODE_REQUIRED=${INVITE_CODE_REQUIRED:-false}
|
|
56
|
+
- LOG_LEVEL=${LOG_LEVEL:-info}
|
|
57
|
+
volumes:
|
|
58
|
+
- ./data:/home/agentx/.agentx
|
|
59
|
+
healthcheck:
|
|
60
|
+
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:5200/health"]
|
|
61
|
+
interval: 30s
|
|
62
|
+
timeout: 10s
|
|
63
|
+
start_period: 5s
|
|
64
|
+
retries: 3
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Run:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
docker compose up -d
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Using npm
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Install globally
|
|
77
|
+
npm install -g @agentxjs/portagent
|
|
78
|
+
|
|
79
|
+
# Run with required API key
|
|
80
|
+
export LLM_PROVIDER_KEY=sk-ant-xxxxx
|
|
81
|
+
portagent
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Configuration
|
|
85
|
+
|
|
86
|
+
### Environment Variables
|
|
87
|
+
|
|
88
|
+
| Variable | Required | Default | Description |
|
|
89
|
+
| ---------------------- | -------- | --------------------------- | ------------------------------------------- |
|
|
90
|
+
| `LLM_PROVIDER_KEY` | **Yes** | - | Anthropic API key (starts with `sk-ant-`) |
|
|
91
|
+
| `LLM_PROVIDER_URL` | No | `https://api.anthropic.com` | API base URL |
|
|
92
|
+
| `LLM_PROVIDER_MODEL` | No | `claude-sonnet-4-20250514` | Claude model to use |
|
|
93
|
+
| `PORT` | No | `5200` | Server port |
|
|
94
|
+
| `DATA_DIR` | No | `~/.agentx` | Data directory path |
|
|
95
|
+
| `JWT_SECRET` | No | Auto-generated | Secret for JWT token signing |
|
|
96
|
+
| `INVITE_CODE_REQUIRED` | No | `false` | Require invite code for registration |
|
|
97
|
+
| `LOG_LEVEL` | No | `info` | Log level: `debug`, `info`, `warn`, `error` |
|
|
98
|
+
| `NODE_ENV` | No | `production` | Environment mode |
|
|
99
|
+
|
|
100
|
+
### CLI Options
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
portagent [options]
|
|
104
|
+
|
|
105
|
+
Options:
|
|
106
|
+
-p, --port <port> Port to listen on (default: 5200)
|
|
107
|
+
-d, --data-dir <path> Data directory (default: ~/.agentx)
|
|
108
|
+
-e, --env-file <path> Path to environment file
|
|
109
|
+
--jwt-secret <secret> JWT secret for token signing
|
|
110
|
+
--api-key <key> LLM provider API key
|
|
111
|
+
--api-url <url> LLM provider base URL
|
|
112
|
+
--model <model> LLM model name
|
|
113
|
+
-h, --help Display help
|
|
114
|
+
-V, --version Display version
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Data Directory Structure
|
|
118
|
+
|
|
119
|
+
```text
|
|
120
|
+
~/.agentx/ # Default data directory (configurable via DATA_DIR)
|
|
121
|
+
├── data/ # Database files
|
|
122
|
+
│ ├── agentx.db # AgentX data (containers, images, sessions)
|
|
123
|
+
│ └── portagent.db # User authentication data
|
|
124
|
+
└── logs/ # Log files
|
|
125
|
+
└── portagent.log
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Invite Code System
|
|
129
|
+
|
|
130
|
+
Portagent uses a daily rotating invite code for registration security. The invite code is the **Unix timestamp (in seconds) of today's 00:00:01** in the server's timezone.
|
|
131
|
+
|
|
132
|
+
### Calculating the Invite Code
|
|
133
|
+
|
|
134
|
+
**Linux/macOS:**
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
# For server's local timezone
|
|
138
|
+
date -d "today 00:00:01" +%s
|
|
139
|
+
|
|
140
|
+
# For UTC (Docker default)
|
|
141
|
+
TZ=UTC date -d "today 00:00:01" +%s
|
|
142
|
+
|
|
143
|
+
# macOS syntax
|
|
144
|
+
date -j -f "%Y-%m-%d %H:%M:%S" "$(date +%Y-%m-%d) 00:00:01" "+%s"
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**JavaScript:**
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
// Server's local timezone
|
|
151
|
+
const now = new Date();
|
|
152
|
+
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 1);
|
|
153
|
+
const inviteCode = Math.floor(todayStart.getTime() / 1000);
|
|
154
|
+
console.log(inviteCode);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Note:** Docker containers typically run in UTC timezone. Make sure to calculate the invite code for the correct timezone.
|
|
158
|
+
|
|
159
|
+
### Enabling Invite Codes
|
|
160
|
+
|
|
161
|
+
Set `INVITE_CODE_REQUIRED=true` to require invite codes for registration:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
docker run -e INVITE_CODE_REQUIRED=true ...
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## API Endpoints
|
|
168
|
+
|
|
169
|
+
| Method | Path | Auth | Description |
|
|
170
|
+
| ------ | -------------------- | ---- | ---------------------- |
|
|
171
|
+
| GET | `/health` | No | Health check |
|
|
172
|
+
| GET | `/api/auth/config` | No | Get auth configuration |
|
|
173
|
+
| POST | `/api/auth/register` | No | Register new user |
|
|
174
|
+
| POST | `/api/auth/login` | No | Login |
|
|
175
|
+
| GET | `/api/auth/verify` | Yes | Verify token |
|
|
176
|
+
| POST | `/api/auth/logout` | No | Logout (client-side) |
|
|
177
|
+
| GET | `/agentx/info` | Yes | Get platform info |
|
|
178
|
+
| WS | `/ws` | Yes | WebSocket connection |
|
|
179
|
+
|
|
180
|
+
### Authentication
|
|
181
|
+
|
|
182
|
+
All protected endpoints require a JWT token in the Authorization header:
|
|
183
|
+
|
|
184
|
+
```text
|
|
185
|
+
Authorization: Bearer <token>
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
For WebSocket connections (which don't support headers), pass the token as a query parameter:
|
|
189
|
+
|
|
190
|
+
```text
|
|
191
|
+
ws://localhost:5200/ws?token=<token>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Register
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
curl -X POST http://localhost:5200/api/auth/register \
|
|
198
|
+
-H "Content-Type: application/json" \
|
|
199
|
+
-d '{
|
|
200
|
+
"username": "john",
|
|
201
|
+
"password": "secret123",
|
|
202
|
+
"inviteCode": "1765152001",
|
|
203
|
+
"email": "john@example.com",
|
|
204
|
+
"displayName": "John Doe"
|
|
205
|
+
}'
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Login
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
curl -X POST http://localhost:5200/api/auth/login \
|
|
212
|
+
-H "Content-Type: application/json" \
|
|
213
|
+
-d '{
|
|
214
|
+
"usernameOrEmail": "john",
|
|
215
|
+
"password": "secret123"
|
|
216
|
+
}'
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Docker Images
|
|
220
|
+
|
|
221
|
+
Pre-built images are available on Docker Hub:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# Latest version
|
|
225
|
+
docker pull deepracticexs/portagent:latest
|
|
226
|
+
|
|
227
|
+
# Specific version
|
|
228
|
+
docker pull deepracticexs/portagent:0.1.9
|
|
229
|
+
|
|
230
|
+
# Available architectures: linux/amd64, linux/arm64
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Building Locally
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# From repository root
|
|
237
|
+
docker build -t portagent:local -f apps/portagent/Dockerfile .
|
|
238
|
+
|
|
239
|
+
# Run local build
|
|
240
|
+
docker run -d \
|
|
241
|
+
--name portagent \
|
|
242
|
+
-p 5200:5200 \
|
|
243
|
+
-e LLM_PROVIDER_KEY=sk-ant-xxxxx \
|
|
244
|
+
portagent:local
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Production Deployment
|
|
248
|
+
|
|
249
|
+
### Recommended Settings
|
|
250
|
+
|
|
251
|
+
```yaml
|
|
252
|
+
services:
|
|
253
|
+
portagent:
|
|
254
|
+
image: deepracticexs/portagent:0.1.9 # Pin to specific version
|
|
255
|
+
restart: unless-stopped
|
|
256
|
+
environment:
|
|
257
|
+
- LLM_PROVIDER_KEY=${LLM_PROVIDER_KEY}
|
|
258
|
+
- JWT_SECRET=${JWT_SECRET} # Use a strong, persistent secret
|
|
259
|
+
- INVITE_CODE_REQUIRED=true # Enable for production
|
|
260
|
+
- LOG_LEVEL=info
|
|
261
|
+
volumes:
|
|
262
|
+
- ./data:/home/agentx/.agentx # Persist data
|
|
263
|
+
ports:
|
|
264
|
+
- "5200:5200"
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Security Considerations
|
|
268
|
+
|
|
269
|
+
1. **API Key**: Never expose `LLM_PROVIDER_KEY` in client-side code or logs
|
|
270
|
+
2. **JWT Secret**: Use a strong, random secret and keep it consistent across restarts
|
|
271
|
+
3. **Invite Codes**: Enable invite codes in production to control access
|
|
272
|
+
4. **HTTPS**: Use a reverse proxy (nginx, Caddy) with TLS in production
|
|
273
|
+
5. **Volume Permissions**: The container runs as non-root user (uid 1001)
|
|
274
|
+
|
|
275
|
+
### Reverse Proxy (nginx example)
|
|
276
|
+
|
|
277
|
+
```nginx
|
|
278
|
+
server {
|
|
279
|
+
listen 443 ssl;
|
|
280
|
+
server_name portagent.example.com;
|
|
281
|
+
|
|
282
|
+
ssl_certificate /path/to/cert.pem;
|
|
283
|
+
ssl_certificate_key /path/to/key.pem;
|
|
284
|
+
|
|
285
|
+
location / {
|
|
286
|
+
proxy_pass http://localhost:5200;
|
|
287
|
+
proxy_http_version 1.1;
|
|
288
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
289
|
+
proxy_set_header Connection "upgrade";
|
|
290
|
+
proxy_set_header Host $host;
|
|
291
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Troubleshooting
|
|
297
|
+
|
|
298
|
+
### "LLM_PROVIDER_KEY is required"
|
|
299
|
+
|
|
300
|
+
- Ensure `LLM_PROVIDER_KEY` environment variable is set
|
|
301
|
+
- For Docker, use `-e LLM_PROVIDER_KEY=xxx` or `environment:` in compose
|
|
302
|
+
|
|
303
|
+
### "Invalid invite code"
|
|
304
|
+
|
|
305
|
+
- Invite code changes daily at midnight (server timezone)
|
|
306
|
+
- Docker uses UTC by default
|
|
307
|
+
- Calculate code for correct timezone (see Invite Code section)
|
|
308
|
+
- Set `INVITE_CODE_REQUIRED=false` to disable
|
|
309
|
+
|
|
310
|
+
### Permission denied errors
|
|
311
|
+
|
|
312
|
+
- Docker container runs as user `agentx` (uid 1001)
|
|
313
|
+
- Ensure mounted volumes have correct permissions:
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
sudo chown -R 1001:1001 ./data
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### WebSocket connection fails
|
|
320
|
+
|
|
321
|
+
- Ensure token is passed as query parameter for WS connections
|
|
322
|
+
- Check reverse proxy WebSocket configuration
|
|
323
|
+
|
|
324
|
+
### Viewing Logs
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
# Docker logs
|
|
328
|
+
docker logs portagent
|
|
329
|
+
|
|
330
|
+
# Follow logs
|
|
331
|
+
docker logs -f portagent
|
|
332
|
+
|
|
333
|
+
# Log files inside container
|
|
334
|
+
docker exec portagent cat /home/agentx/.agentx/logs/portagent.log
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## Development
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
# Clone repository
|
|
341
|
+
git clone https://github.com/Deepractice/AgentX.git
|
|
342
|
+
cd AgentX
|
|
343
|
+
|
|
344
|
+
# Install dependencies
|
|
345
|
+
pnpm install
|
|
346
|
+
|
|
347
|
+
# Build all packages
|
|
348
|
+
pnpm build
|
|
349
|
+
|
|
350
|
+
# Start development server
|
|
351
|
+
cd apps/portagent
|
|
352
|
+
pnpm dev
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## License
|
|
356
|
+
|
|
357
|
+
MIT License - see [LICENSE](./LICENSE) for details.
|
|
Binary file
|