File size: 6,288 Bytes
4e909c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# Laddr Dashboard

The official Laddr dashboard, distributed as a Docker image for seamless integration with Laddr projects.

## ๐ŸŽฏ Overview

This directory contains the React-based dashboard that provides comprehensive observability for Laddr agent systems. The dashboard is built and distributed as a Docker image (`laddr/dashboard:latest`) so users never need to touch frontend code.

## ๐Ÿ—๏ธ Architecture

```
dashboard/
โ”œโ”€โ”€ src/                  # React application source
โ”‚   โ”œโ”€โ”€ App.tsx          # Main application component
โ”‚   โ”œโ”€โ”€ main.tsx         # Application entry point
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ public/              # Static assets
โ”œโ”€โ”€ Dockerfile           # Development Dockerfile
โ”œโ”€โ”€ Dockerfile.prod      # Production Dockerfile (multi-stage)
โ”œโ”€โ”€ nginx.conf           # Nginx configuration for production
โ”œโ”€โ”€ vite.config.ts       # Vite build configuration
โ”œโ”€โ”€ package.json         # Dependencies and scripts
โ””โ”€โ”€ build-dashboard.sh   # Build script for Docker image
```

## ๐Ÿ“ฆ Distribution Model

### For Users
- Dashboard is **NOT** copied to user projects
- Distributed as pre-built Docker image
- Automatically pulled when running `laddr run dev`
- Zero frontend setup required

### For Maintainers
- Build and publish Docker images to Docker Hub
- Multi-stage build: Node.js โ†’ Nginx
- Optimized for production (~40MB final size)

## ๐Ÿš€ Building the Dashboard

### Development

```bash
# Install dependencies
npm install

# Run development server
npm run dev
# Dashboard available at http://localhost:5173

# Build for production
npm run build
# Output in dist/
```

### Production Docker Image

```bash
# Build Docker image
./build-dashboard.sh v1.0.0

# Or manually
docker build -f Dockerfile.prod -t laddr/dashboard:latest .

# Test locally
docker run -p 5173:5173 laddr/dashboard:latest

# Push to Docker Hub
docker push laddr/dashboard:latest
docker push laddr/dashboard:v1.0.0
```

## ๐Ÿ”ง Technical Details

### Multi-Stage Build

**Stage 1: Builder**
- Base: `node:20-alpine`
- Installs dependencies with `npm ci`
- Builds React app with Vite
- Output: Optimized static files

**Stage 2: Server**
- Base: `nginx:alpine`
- Copies built files from builder
- Includes custom nginx configuration
- Final size: ~40MB

### Nginx Configuration

The production image uses nginx to:
- Serve static files with caching and compression
- Proxy `/api/*` requests to API container
- Proxy `/ws/*` WebSocket connections
- Handle React Router client-side routing
- Optimize with gzip compression

```nginx
location /api/ {
    proxy_pass http://api:8000/api/;
    # ... proxy headers
}

location /ws/ {
    proxy_pass http://api:8000/ws/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
```

### Environment Variables

The dashboard uses environment variables for configuration:

- `VITE_API_URL`: API server URL (default: `http://api:8000`)
- `VITE_WS_URL`: WebSocket URL (default: `ws://api:8000`)

## ๐Ÿ“Š Features

The dashboard provides:

1. **System Overview**
   - Active agents count
   - Job queue status
   - System health metrics

2. **Agent Management**
   - View all registered agents
   - Check agent status and queue depth
   - Agent details (role, goal, tools)
   - Chat with individual agents

3. **Observability**
   - View distributed traces
   - Monitor metrics and performance
   - Real-time logs via WebSocket
   - Token usage tracking

4. **Job Management**
   - Submit new jobs
   - Monitor job status
   - View results
   - Cancel running jobs

5. **Real-time Updates**
   - WebSocket for live logs
   - System event streaming
   - Agent status updates

## ๐Ÿ”— API Integration

The dashboard communicates with the Laddr API server:

### REST Endpoints
- `GET /api/agents` - List agents
- `GET /api/agents/{name}` - Get agent details
- `POST /api/agents/{name}/chat` - Chat with agent
- `GET /api/jobs` - List jobs
- `POST /api/jobs` - Submit job
- `GET /api/traces` - Get traces
- `GET /api/metrics` - Get metrics

### WebSocket Endpoints
- `WS /ws/logs/{agent}` - Stream agent logs
- `WS /ws/events` - Stream system events

## ๐Ÿงช Testing

```bash
# Run tests
npm test

# Run linting
npm run lint

# Type checking
npm run type-check

# Preview production build
npm run build
npm run preview
```

## ๐Ÿ“ฆ Dependencies

### Core
- React 18.3 - UI framework
- React Router 6 - Client-side routing
- TypeScript - Type safety

### Data Fetching
- TanStack Query 5 - Server state management
- Axios - HTTP client

### UI Components
- Recharts - Data visualization
- Lucide React - Icons

### Build Tools
- Vite 5 - Build tool and dev server
- TypeScript - Type checking

## ๐Ÿ”„ Release Process

1. **Update version** in `package.json`
2. **Build image**: `./build-dashboard.sh v1.x.x`
3. **Test locally**: `docker run -p 5173:5173 laddr/dashboard:v1.x.x`
4. **Push to Docker Hub**: `docker push laddr/dashboard:v1.x.x`
5. **Tag as latest**: `docker push laddr/dashboard:latest`
6. **Update docs**: Note version in changelog

## ๐Ÿ› Troubleshooting

### Build fails
```bash
# Clean and rebuild
rm -rf node_modules dist
npm install
npm run build
```

### Docker image too large
- Check multi-stage build is working
- Verify `node_modules` not copied to final image
- Use `docker images` to check size

### API connection fails
- Verify nginx proxy configuration
- Check CORS settings in API server
- Ensure API container is running
- Check network connectivity between containers

## ๐Ÿ“š Resources

- [Vite Documentation](https://vitejs.dev/)
- [React Documentation](https://react.dev/)
- [Nginx Documentation](https://nginx.org/en/docs/)
- [Docker Multi-stage Builds](https://docs.docker.com/build/building/multi-stage/)

## ๐Ÿค Contributing

For maintainers working on the dashboard:

1. Make changes in `src/`
2. Test locally with `npm run dev`
3. Build production image
4. Test Docker image locally
5. Push to Docker Hub
6. Update documentation

## ๐Ÿ“„ License

Same as Laddr project license.

---

**Note**: This dashboard is designed to be distributed as a Docker image. Users should never need to modify or build it themselves. All customization is done via environment variables and API configuration.