@donkeylabs/server 2.0.7 → 2.0.10

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.
@@ -0,0 +1,717 @@
1
+ /**
2
+ * Admin Dashboard HTML Templates
3
+ * Uses htmx for dynamic content and SSE for real-time updates
4
+ */
5
+
6
+ import { adminStyles } from "./styles";
7
+
8
+ // Icon SVGs (inline to avoid external dependencies)
9
+ const icons = {
10
+ dashboard: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"/></svg>`,
11
+ jobs: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"/></svg>`,
12
+ processes: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>`,
13
+ workflows: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/></svg>`,
14
+ audit: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>`,
15
+ sse: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.141 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0"/></svg>`,
16
+ websocket: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"/></svg>`,
17
+ events: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"/></svg>`,
18
+ cache: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"/></svg>`,
19
+ plugins: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 4a2 2 0 114 0v1a1 1 0 001 1h3a1 1 0 011 1v3a1 1 0 01-1 1h-1a2 2 0 100 4h1a1 1 0 011 1v3a1 1 0 01-1 1h-3a1 1 0 01-1-1v-1a2 2 0 10-4 0v1a1 1 0 01-1 1H7a1 1 0 01-1-1v-3a1 1 0 00-1-1H4a2 2 0 110-4h1a1 1 0 001-1V7a1 1 0 011-1h3a1 1 0 001-1V4z"/></svg>`,
20
+ routes: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 20l-5.447-2.724A1 1 0 013 16.382V5.618a1 1 0 011.447-.894L9 7m0 13l6-3m-6 3V7m6 10l4.553 2.276A1 1 0 0021 18.382V7.618a1 1 0 00-.553-.894L15 4m0 13V4m0 0L9 7"/></svg>`,
21
+ refresh: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>`,
22
+ server: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"/></svg>`,
23
+ };
24
+
25
+ export interface DashboardData {
26
+ prefix: string;
27
+ stats: {
28
+ uptime: number;
29
+ memory: { heapUsed: number; heapTotal: number };
30
+ jobs: { pending: number; running: number; completed: number; failed: number };
31
+ processes: { running: number; total: number };
32
+ workflows: { running: number; total: number };
33
+ sse: { clients: number };
34
+ websocket: { clients: number };
35
+ };
36
+ }
37
+
38
+ function formatBytes(bytes: number): string {
39
+ if (bytes < 1024) return `${bytes} B`;
40
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
41
+ if (bytes < 1024 * 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
42
+ return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`;
43
+ }
44
+
45
+ function formatUptime(seconds: number): string {
46
+ const days = Math.floor(seconds / 86400);
47
+ const hours = Math.floor((seconds % 86400) / 3600);
48
+ const minutes = Math.floor((seconds % 3600) / 60);
49
+ if (days > 0) return `${days}d ${hours}h`;
50
+ if (hours > 0) return `${hours}h ${minutes}m`;
51
+ return `${minutes}m`;
52
+ }
53
+
54
+ function formatRelativeTime(date: Date | string | undefined): string {
55
+ if (!date) return "-";
56
+ const d = typeof date === "string" ? new Date(date) : date;
57
+ const seconds = Math.floor((Date.now() - d.getTime()) / 1000);
58
+ if (seconds < 60) return "just now";
59
+ if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`;
60
+ if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`;
61
+ return `${Math.floor(seconds / 86400)}d ago`;
62
+ }
63
+
64
+ export function renderDashboardLayout(
65
+ prefix: string,
66
+ content: string,
67
+ activeNav: string = "overview"
68
+ ): string {
69
+ const navItems = [
70
+ { id: "overview", label: "Overview", icon: icons.dashboard },
71
+ { id: "jobs", label: "Jobs", icon: icons.jobs },
72
+ { id: "processes", label: "Processes", icon: icons.processes },
73
+ { id: "workflows", label: "Workflows", icon: icons.workflows },
74
+ { id: "audit", label: "Audit Logs", icon: icons.audit },
75
+ { id: "sse", label: "SSE Clients", icon: icons.sse },
76
+ { id: "websocket", label: "WebSocket", icon: icons.websocket },
77
+ { id: "events", label: "Events", icon: icons.events },
78
+ { id: "cache", label: "Cache", icon: icons.cache },
79
+ { id: "plugins", label: "Plugins", icon: icons.plugins },
80
+ { id: "routes", label: "Routes", icon: icons.routes },
81
+ ];
82
+
83
+ return `<!DOCTYPE html>
84
+ <html lang="en">
85
+ <head>
86
+ <meta charset="UTF-8">
87
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
88
+ <title>Admin Dashboard | @donkeylabs/server</title>
89
+ <script src="https://unpkg.com/htmx.org@2.0.4"></script>
90
+ <script src="https://unpkg.com/htmx-ext-sse@2.2.2/sse.js"></script>
91
+ <style>${adminStyles}</style>
92
+ </head>
93
+ <body>
94
+ <div class="admin-container">
95
+ <aside class="sidebar">
96
+ <div class="sidebar-header">
97
+ <h1 class="sidebar-title">
98
+ ${icons.server}
99
+ Admin
100
+ </h1>
101
+ </div>
102
+ <nav class="nav-section">
103
+ <div class="nav-section-title">Dashboard</div>
104
+ ${navItems
105
+ .slice(0, 1)
106
+ .map(
107
+ (item) => `
108
+ <a href="/${prefix}.dashboard?view=${item.id}"
109
+ class="nav-item ${activeNav === item.id ? "active" : ""}"
110
+ hx-get="/${prefix}.dashboard?view=${item.id}&partial=1"
111
+ hx-target="#main-content"
112
+ hx-push-url="/${prefix}.dashboard?view=${item.id}">
113
+ ${item.icon}
114
+ <span>${item.label}</span>
115
+ </a>
116
+ `
117
+ )
118
+ .join("")}
119
+ </nav>
120
+ <nav class="nav-section">
121
+ <div class="nav-section-title">Core Services</div>
122
+ ${navItems
123
+ .slice(1, 5)
124
+ .map(
125
+ (item) => `
126
+ <a href="/${prefix}.dashboard?view=${item.id}"
127
+ class="nav-item ${activeNav === item.id ? "active" : ""}"
128
+ hx-get="/${prefix}.dashboard?view=${item.id}&partial=1"
129
+ hx-target="#main-content"
130
+ hx-push-url="/${prefix}.dashboard?view=${item.id}">
131
+ ${item.icon}
132
+ <span>${item.label}</span>
133
+ </a>
134
+ `
135
+ )
136
+ .join("")}
137
+ </nav>
138
+ <nav class="nav-section">
139
+ <div class="nav-section-title">Connections</div>
140
+ ${navItems
141
+ .slice(5, 8)
142
+ .map(
143
+ (item) => `
144
+ <a href="/${prefix}.dashboard?view=${item.id}"
145
+ class="nav-item ${activeNav === item.id ? "active" : ""}"
146
+ hx-get="/${prefix}.dashboard?view=${item.id}&partial=1"
147
+ hx-target="#main-content"
148
+ hx-push-url="/${prefix}.dashboard?view=${item.id}">
149
+ ${item.icon}
150
+ <span>${item.label}</span>
151
+ </a>
152
+ `
153
+ )
154
+ .join("")}
155
+ </nav>
156
+ <nav class="nav-section">
157
+ <div class="nav-section-title">Configuration</div>
158
+ ${navItems
159
+ .slice(8)
160
+ .map(
161
+ (item) => `
162
+ <a href="/${prefix}.dashboard?view=${item.id}"
163
+ class="nav-item ${activeNav === item.id ? "active" : ""}"
164
+ hx-get="/${prefix}.dashboard?view=${item.id}&partial=1"
165
+ hx-target="#main-content"
166
+ hx-push-url="/${prefix}.dashboard?view=${item.id}">
167
+ ${item.icon}
168
+ <span>${item.label}</span>
169
+ </a>
170
+ `
171
+ )
172
+ .join("")}
173
+ </nav>
174
+ </aside>
175
+ <main class="main-content" id="main-content">
176
+ ${content}
177
+ </main>
178
+ </div>
179
+ </body>
180
+ </html>`;
181
+ }
182
+
183
+ export function renderOverview(prefix: string, stats: DashboardData["stats"]): string {
184
+ return `
185
+ <div class="page-header">
186
+ <h2 class="page-title">Overview</h2>
187
+ <button class="btn" hx-get="/${prefix}.dashboard?view=overview&partial=1" hx-target="#main-content">
188
+ ${icons.refresh}
189
+ Refresh
190
+ </button>
191
+ </div>
192
+
193
+ <div class="stats-grid" hx-ext="sse" sse-connect="/${prefix}.live" sse-swap="stats">
194
+ <div class="stat-card">
195
+ <div class="stat-label">Uptime</div>
196
+ <div class="stat-value blue">${formatUptime(stats.uptime)}</div>
197
+ </div>
198
+ <div class="stat-card">
199
+ <div class="stat-label">Memory (Heap)</div>
200
+ <div class="stat-value">${formatBytes(stats.memory.heapUsed)} / ${formatBytes(stats.memory.heapTotal)}</div>
201
+ </div>
202
+ <div class="stat-card">
203
+ <div class="stat-label">Jobs Running</div>
204
+ <div class="stat-value blue">${stats.jobs.running}</div>
205
+ </div>
206
+ <div class="stat-card">
207
+ <div class="stat-label">Jobs Pending</div>
208
+ <div class="stat-value yellow">${stats.jobs.pending}</div>
209
+ </div>
210
+ <div class="stat-card">
211
+ <div class="stat-label">Jobs Completed</div>
212
+ <div class="stat-value green">${stats.jobs.completed}</div>
213
+ </div>
214
+ <div class="stat-card">
215
+ <div class="stat-label">Jobs Failed</div>
216
+ <div class="stat-value red">${stats.jobs.failed}</div>
217
+ </div>
218
+ <div class="stat-card">
219
+ <div class="stat-label">Processes</div>
220
+ <div class="stat-value purple">${stats.processes.running}/${stats.processes.total}</div>
221
+ </div>
222
+ <div class="stat-card">
223
+ <div class="stat-label">Workflows Running</div>
224
+ <div class="stat-value blue">${stats.workflows.running}</div>
225
+ </div>
226
+ <div class="stat-card">
227
+ <div class="stat-label">SSE Clients</div>
228
+ <div class="stat-value green">${stats.sse.clients}</div>
229
+ </div>
230
+ <div class="stat-card">
231
+ <div class="stat-label">WebSocket Clients</div>
232
+ <div class="stat-value green">${stats.websocket.clients}</div>
233
+ </div>
234
+ </div>
235
+ `;
236
+ }
237
+
238
+ export function renderJobsList(prefix: string, jobs: any[]): string {
239
+ return `
240
+ <div class="page-header">
241
+ <h2 class="page-title">Jobs</h2>
242
+ <button class="btn" hx-get="/${prefix}.dashboard?view=jobs&partial=1" hx-target="#main-content">
243
+ ${icons.refresh}
244
+ Refresh
245
+ </button>
246
+ </div>
247
+
248
+ <div class="filters">
249
+ <select class="filter-select" hx-get="/${prefix}.dashboard?view=jobs&partial=1" hx-target="#main-content" hx-include="this" name="status">
250
+ <option value="">All Status</option>
251
+ <option value="pending">Pending</option>
252
+ <option value="running">Running</option>
253
+ <option value="completed">Completed</option>
254
+ <option value="failed">Failed</option>
255
+ <option value="scheduled">Scheduled</option>
256
+ </select>
257
+ </div>
258
+
259
+ <div class="card">
260
+ <div class="table-container">
261
+ <table>
262
+ <thead>
263
+ <tr>
264
+ <th>ID</th>
265
+ <th>Name</th>
266
+ <th>Status</th>
267
+ <th>Attempts</th>
268
+ <th>Created</th>
269
+ <th>Actions</th>
270
+ </tr>
271
+ </thead>
272
+ <tbody>
273
+ ${
274
+ jobs.length === 0
275
+ ? '<tr><td colspan="6" class="empty-state">No jobs found</td></tr>'
276
+ : jobs
277
+ .map(
278
+ (job) => `
279
+ <tr>
280
+ <td class="mono truncate" title="${job.id}">${job.id.slice(0, 20)}...</td>
281
+ <td>${job.name}</td>
282
+ <td><span class="badge badge-${job.status}">${job.status}</span></td>
283
+ <td>${job.attempts}/${job.maxAttempts}</td>
284
+ <td class="relative-time">${formatRelativeTime(job.createdAt)}</td>
285
+ <td class="action-btns">
286
+ ${
287
+ job.status === "pending" || job.status === "running"
288
+ ? `<button class="btn btn-sm btn-danger"
289
+ hx-post="/${prefix}.jobs.cancel"
290
+ hx-vals='{"jobId": "${job.id}"}'
291
+ hx-target="#main-content"
292
+ hx-confirm="Cancel this job?">Cancel</button>`
293
+ : ""
294
+ }
295
+ </td>
296
+ </tr>
297
+ `
298
+ )
299
+ .join("")
300
+ }
301
+ </tbody>
302
+ </table>
303
+ </div>
304
+ </div>
305
+ `;
306
+ }
307
+
308
+ export function renderProcessesList(prefix: string, processes: any[]): string {
309
+ return `
310
+ <div class="page-header">
311
+ <h2 class="page-title">Processes</h2>
312
+ <button class="btn" hx-get="/${prefix}.dashboard?view=processes&partial=1" hx-target="#main-content">
313
+ ${icons.refresh}
314
+ Refresh
315
+ </button>
316
+ </div>
317
+
318
+ <div class="card">
319
+ <div class="table-container">
320
+ <table>
321
+ <thead>
322
+ <tr>
323
+ <th>Name</th>
324
+ <th>Status</th>
325
+ <th>PID</th>
326
+ <th>Restarts</th>
327
+ <th>Started</th>
328
+ <th>Actions</th>
329
+ </tr>
330
+ </thead>
331
+ <tbody>
332
+ ${
333
+ processes.length === 0
334
+ ? '<tr><td colspan="6" class="empty-state">No processes found</td></tr>'
335
+ : processes
336
+ .map(
337
+ (proc) => `
338
+ <tr>
339
+ <td>${proc.name}</td>
340
+ <td><span class="badge badge-${proc.status}">${proc.status}</span></td>
341
+ <td class="mono">${proc.pid ?? "-"}</td>
342
+ <td>${proc.restarts ?? 0}</td>
343
+ <td class="relative-time">${formatRelativeTime(proc.startedAt)}</td>
344
+ <td class="action-btns">
345
+ ${
346
+ proc.status === "running"
347
+ ? `<button class="btn btn-sm btn-danger"
348
+ hx-post="/${prefix}.processes.stop"
349
+ hx-vals='{"name": "${proc.name}"}'
350
+ hx-target="#main-content"
351
+ hx-confirm="Stop this process?">Stop</button>`
352
+ : `<button class="btn btn-sm btn-primary"
353
+ hx-post="/${prefix}.processes.restart"
354
+ hx-vals='{"name": "${proc.name}"}'
355
+ hx-target="#main-content">Restart</button>`
356
+ }
357
+ </td>
358
+ </tr>
359
+ `
360
+ )
361
+ .join("")
362
+ }
363
+ </tbody>
364
+ </table>
365
+ </div>
366
+ </div>
367
+ `;
368
+ }
369
+
370
+ export function renderWorkflowsList(prefix: string, workflows: any[]): string {
371
+ return `
372
+ <div class="page-header">
373
+ <h2 class="page-title">Workflows</h2>
374
+ <button class="btn" hx-get="/${prefix}.dashboard?view=workflows&partial=1" hx-target="#main-content">
375
+ ${icons.refresh}
376
+ Refresh
377
+ </button>
378
+ </div>
379
+
380
+ <div class="filters">
381
+ <select class="filter-select" hx-get="/${prefix}.dashboard?view=workflows&partial=1" hx-target="#main-content" hx-include="this" name="status">
382
+ <option value="">All Status</option>
383
+ <option value="pending">Pending</option>
384
+ <option value="running">Running</option>
385
+ <option value="completed">Completed</option>
386
+ <option value="failed">Failed</option>
387
+ <option value="cancelled">Cancelled</option>
388
+ </select>
389
+ </div>
390
+
391
+ <div class="card">
392
+ <div class="table-container">
393
+ <table>
394
+ <thead>
395
+ <tr>
396
+ <th>ID</th>
397
+ <th>Workflow</th>
398
+ <th>Status</th>
399
+ <th>Current Step</th>
400
+ <th>Created</th>
401
+ <th>Actions</th>
402
+ </tr>
403
+ </thead>
404
+ <tbody>
405
+ ${
406
+ workflows.length === 0
407
+ ? '<tr><td colspan="6" class="empty-state">No workflow instances found</td></tr>'
408
+ : workflows
409
+ .map(
410
+ (wf) => `
411
+ <tr>
412
+ <td class="mono truncate" title="${wf.id}">${wf.id.slice(0, 20)}...</td>
413
+ <td>${wf.workflowName}</td>
414
+ <td><span class="badge badge-${wf.status}">${wf.status}</span></td>
415
+ <td>${wf.currentStep ?? "-"}</td>
416
+ <td class="relative-time">${formatRelativeTime(wf.createdAt)}</td>
417
+ <td class="action-btns">
418
+ ${
419
+ wf.status === "running"
420
+ ? `<button class="btn btn-sm btn-danger"
421
+ hx-post="/${prefix}.workflows.cancel"
422
+ hx-vals='{"instanceId": "${wf.id}"}'
423
+ hx-target="#main-content"
424
+ hx-confirm="Cancel this workflow?">Cancel</button>`
425
+ : ""
426
+ }
427
+ </td>
428
+ </tr>
429
+ `
430
+ )
431
+ .join("")
432
+ }
433
+ </tbody>
434
+ </table>
435
+ </div>
436
+ </div>
437
+ `;
438
+ }
439
+
440
+ export function renderAuditLogs(prefix: string, logs: any[]): string {
441
+ return `
442
+ <div class="page-header">
443
+ <h2 class="page-title">Audit Logs</h2>
444
+ <button class="btn" hx-get="/${prefix}.dashboard?view=audit&partial=1" hx-target="#main-content">
445
+ ${icons.refresh}
446
+ Refresh
447
+ </button>
448
+ </div>
449
+
450
+ <div class="card">
451
+ <div class="table-container">
452
+ <table>
453
+ <thead>
454
+ <tr>
455
+ <th>Action</th>
456
+ <th>Actor</th>
457
+ <th>Resource</th>
458
+ <th>Resource ID</th>
459
+ <th>Timestamp</th>
460
+ </tr>
461
+ </thead>
462
+ <tbody>
463
+ ${
464
+ logs.length === 0
465
+ ? '<tr><td colspan="5" class="empty-state">No audit logs found</td></tr>'
466
+ : logs
467
+ .map(
468
+ (log) => `
469
+ <tr>
470
+ <td>${log.action}</td>
471
+ <td>${log.actor}</td>
472
+ <td>${log.resource}</td>
473
+ <td>${log.resourceId ?? "-"}</td>
474
+ <td class="relative-time">${formatRelativeTime(log.timestamp)}</td>
475
+ </tr>
476
+ `
477
+ )
478
+ .join("")
479
+ }
480
+ </tbody>
481
+ </table>
482
+ </div>
483
+ </div>
484
+ `;
485
+ }
486
+
487
+ export function renderSSEClients(prefix: string, clients: any[]): string {
488
+ return `
489
+ <div class="page-header">
490
+ <h2 class="page-title">SSE Clients</h2>
491
+ <button class="btn" hx-get="/${prefix}.dashboard?view=sse&partial=1" hx-target="#main-content">
492
+ ${icons.refresh}
493
+ Refresh
494
+ </button>
495
+ </div>
496
+
497
+ <div class="card">
498
+ <div class="table-container">
499
+ <table>
500
+ <thead>
501
+ <tr>
502
+ <th>Client ID</th>
503
+ <th>Channels</th>
504
+ <th>Connected</th>
505
+ </tr>
506
+ </thead>
507
+ <tbody>
508
+ ${
509
+ clients.length === 0
510
+ ? '<tr><td colspan="3" class="empty-state">No SSE clients connected</td></tr>'
511
+ : clients
512
+ .map(
513
+ (client) => `
514
+ <tr>
515
+ <td class="mono truncate" title="${client.id}">${client.id.slice(0, 20)}...</td>
516
+ <td>${client.channels?.join(", ") || "-"}</td>
517
+ <td class="relative-time">${formatRelativeTime(client.connectedAt)}</td>
518
+ </tr>
519
+ `
520
+ )
521
+ .join("")
522
+ }
523
+ </tbody>
524
+ </table>
525
+ </div>
526
+ </div>
527
+ `;
528
+ }
529
+
530
+ export function renderWebSocketClients(prefix: string, clients: any[]): string {
531
+ return `
532
+ <div class="page-header">
533
+ <h2 class="page-title">WebSocket Clients</h2>
534
+ <button class="btn" hx-get="/${prefix}.dashboard?view=websocket&partial=1" hx-target="#main-content">
535
+ ${icons.refresh}
536
+ Refresh
537
+ </button>
538
+ </div>
539
+
540
+ <div class="card">
541
+ <div class="table-container">
542
+ <table>
543
+ <thead>
544
+ <tr>
545
+ <th>Client ID</th>
546
+ <th>Connected</th>
547
+ </tr>
548
+ </thead>
549
+ <tbody>
550
+ ${
551
+ clients.length === 0
552
+ ? '<tr><td colspan="2" class="empty-state">No WebSocket clients connected</td></tr>'
553
+ : clients
554
+ .map(
555
+ (client) => `
556
+ <tr>
557
+ <td class="mono truncate" title="${client.id}">${client.id.slice(0, 20)}...</td>
558
+ <td class="relative-time">${formatRelativeTime(client.connectedAt)}</td>
559
+ </tr>
560
+ `
561
+ )
562
+ .join("")
563
+ }
564
+ </tbody>
565
+ </table>
566
+ </div>
567
+ </div>
568
+ `;
569
+ }
570
+
571
+ export function renderEvents(prefix: string, events: any[]): string {
572
+ return `
573
+ <div class="page-header">
574
+ <h2 class="page-title">Recent Events</h2>
575
+ <button class="btn" hx-get="/${prefix}.dashboard?view=events&partial=1" hx-target="#main-content">
576
+ ${icons.refresh}
577
+ Refresh
578
+ </button>
579
+ </div>
580
+
581
+ <div class="card">
582
+ <div class="table-container">
583
+ <table>
584
+ <thead>
585
+ <tr>
586
+ <th>Event</th>
587
+ <th>Data</th>
588
+ <th>Timestamp</th>
589
+ </tr>
590
+ </thead>
591
+ <tbody>
592
+ ${
593
+ events.length === 0
594
+ ? '<tr><td colspan="3" class="empty-state">No events recorded</td></tr>'
595
+ : events
596
+ .map(
597
+ (event) => `
598
+ <tr>
599
+ <td class="mono">${event.event}</td>
600
+ <td class="truncate">${JSON.stringify(event.data).slice(0, 50)}...</td>
601
+ <td class="relative-time">${formatRelativeTime(event.timestamp)}</td>
602
+ </tr>
603
+ `
604
+ )
605
+ .join("")
606
+ }
607
+ </tbody>
608
+ </table>
609
+ </div>
610
+ </div>
611
+ `;
612
+ }
613
+
614
+ export function renderCache(prefix: string, keys: string[]): string {
615
+ return `
616
+ <div class="page-header">
617
+ <h2 class="page-title">Cache</h2>
618
+ <button class="btn" hx-get="/${prefix}.dashboard?view=cache&partial=1" hx-target="#main-content">
619
+ ${icons.refresh}
620
+ Refresh
621
+ </button>
622
+ </div>
623
+
624
+ <div class="card">
625
+ <div class="card-header">
626
+ <span class="card-title">Cache Keys (${keys.length})</span>
627
+ </div>
628
+ <div class="card-body">
629
+ ${
630
+ keys.length === 0
631
+ ? '<div class="empty-state">No cached keys</div>'
632
+ : `<div class="code-block">${keys.map((k) => k).join("\n")}</div>`
633
+ }
634
+ </div>
635
+ </div>
636
+ `;
637
+ }
638
+
639
+ export function renderPlugins(prefix: string, plugins: any[]): string {
640
+ return `
641
+ <div class="page-header">
642
+ <h2 class="page-title">Plugins</h2>
643
+ </div>
644
+
645
+ <div class="card">
646
+ <div class="table-container">
647
+ <table>
648
+ <thead>
649
+ <tr>
650
+ <th>Name</th>
651
+ <th>Dependencies</th>
652
+ <th>Has Schema</th>
653
+ </tr>
654
+ </thead>
655
+ <tbody>
656
+ ${
657
+ plugins.length === 0
658
+ ? '<tr><td colspan="3" class="empty-state">No plugins registered</td></tr>'
659
+ : plugins
660
+ .map(
661
+ (plugin) => `
662
+ <tr>
663
+ <td><strong>${plugin.name}</strong></td>
664
+ <td>${plugin.dependencies?.join(", ") || "-"}</td>
665
+ <td>${plugin.hasSchema ? "Yes" : "No"}</td>
666
+ </tr>
667
+ `
668
+ )
669
+ .join("")
670
+ }
671
+ </tbody>
672
+ </table>
673
+ </div>
674
+ </div>
675
+ `;
676
+ }
677
+
678
+ export function renderRoutes(prefix: string, routes: any[]): string {
679
+ return `
680
+ <div class="page-header">
681
+ <h2 class="page-title">Routes</h2>
682
+ </div>
683
+
684
+ <div class="card">
685
+ <div class="table-container">
686
+ <table>
687
+ <thead>
688
+ <tr>
689
+ <th>Route Name</th>
690
+ <th>Handler</th>
691
+ <th>Has Input</th>
692
+ <th>Has Output</th>
693
+ </tr>
694
+ </thead>
695
+ <tbody>
696
+ ${
697
+ routes.length === 0
698
+ ? '<tr><td colspan="4" class="empty-state">No routes registered</td></tr>'
699
+ : routes
700
+ .map(
701
+ (route) => `
702
+ <tr>
703
+ <td class="mono">${route.name}</td>
704
+ <td><span class="badge badge-${route.handler === "typed" ? "completed" : "running"}">${route.handler || "typed"}</span></td>
705
+ <td>${route.hasInput ? "Yes" : "No"}</td>
706
+ <td>${route.hasOutput ? "Yes" : "No"}</td>
707
+ </tr>
708
+ `
709
+ )
710
+ .join("")
711
+ }
712
+ </tbody>
713
+ </table>
714
+ </div>
715
+ </div>
716
+ `;
717
+ }