-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
708 lines (642 loc) · 29.8 KB
/
Copy pathdashboard.html
File metadata and controls
708 lines (642 loc) · 29.8 KB
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hackathon Agent Dashboard</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, 'Segoe UI', Roboto, monospace; background: #0d1117; color: #c9d1d9; padding: 20px; }
h1 { color: #58a6ff; margin-bottom: 8px; font-size: 1.4em; }
.subtitle { color: #8b949e; margin-bottom: 20px; font-size: 0.9em; }
.status-bar { display: flex; gap: 16px; margin-bottom: 20px; padding: 12px 16px; background: #161b22; border: 1px solid #30363d; border-radius: 8px; }
.status-bar .stat { display: flex; flex-direction: column; }
.status-bar .stat-label { font-size: 0.75em; color: #8b949e; text-transform: uppercase; }
.status-bar .stat-value { font-size: 1.3em; font-weight: bold; }
.columns { display: flex; gap: 20px; }
.col-sessions { flex: 2; }
.col-events { flex: 1; }
.section-title { font-size: 0.85em; color: #8b949e; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
/* Session cards */
.session { background: #161b22; border: 1px solid #30363d; border-radius: 8px; margin-bottom: 10px; overflow: hidden; }
.session-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; cursor: pointer; user-select: none; }
.session-header:hover { background: #1c2128; }
.session-id { font-weight: 600; font-size: 0.95em; }
.session-badge { font-size: 0.75em; padding: 2px 8px; border-radius: 12px; font-weight: 600; }
.badge-running { background: #1f6feb33; color: #58a6ff; }
.badge-completed { background: #23863533; color: #3fb950; }
.badge-failed { background: #da363333; color: #f85149; }
.badge-pending { background: #30363d; color: #8b949e; }
.badge-retrying { background: #9e6a0333; color: #d29922; }
.session-body { display: none; padding: 0 14px 10px; }
.session-body.open { display: block; }
.session-activity { font-size: 0.85em; color: #8b949e; padding: 0 14px 8px; }
.log-line { font-size: 0.8em; color: #8b949e; padding: 2px 0; border-bottom: 1px solid #21262d; font-family: monospace; }
.log-line .ts { color: #484f58; margin-right: 8px; }
/* Event stream */
.event-stream { background: #161b22; border: 1px solid #30363d; border-radius: 8px; padding: 10px 14px; max-height: 80vh; overflow-y: auto; }
.event-item { font-size: 0.8em; padding: 4px 0; border-bottom: 1px solid #21262d; }
.event-item .ev-time { color: #484f58; margin-right: 6px; }
.event-item .ev-type { color: #d2a8ff; margin-right: 6px; }
.disconnected { color: #f85149; font-style: italic; margin-bottom: 12px; }
.connected { color: #3fb950; margin-bottom: 12px; font-size: 0.85em; }
/* Review panel */
#review-panel { display: none; margin-bottom: 20px; padding: 16px; background: #161b22; border: 2px solid #d29922; border-radius: 8px; }
#review-panel.active { display: block; }
#review-panel h2 { color: #d29922; font-size: 1.1em; margin-bottom: 4px; }
#review-panel .review-subtitle { color: #8b949e; font-size: 0.85em; margin-bottom: 14px; }
.review-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; margin-bottom: 16px; }
.review-card { background: #0d1117; border: 1px solid #30363d; border-radius: 8px; padding: 12px; cursor: pointer; transition: border-color 0.15s; position: relative; }
.review-card:hover { border-color: #58a6ff; }
.review-card.selected { border-color: #3fb950; background: #3fb95008; }
.review-card .rc-checkbox { position: absolute; top: 12px; right: 12px; width: 18px; height: 18px; border: 2px solid #30363d; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 12px; }
.review-card.selected .rc-checkbox { border-color: #3fb950; background: #3fb950; color: #0d1117; }
.review-card .rc-title { font-weight: 600; font-size: 0.95em; color: #c9d1d9; padding-right: 28px; margin-bottom: 6px; }
.review-card .rc-scenario { font-size: 0.8em; color: #8b949e; margin-bottom: 8px; line-height: 1.4; }
.review-card .rc-meta { font-size: 0.75em; color: #484f58; }
.review-card .rc-meta span { margin-right: 12px; }
.review-actions { display: flex; gap: 10px; align-items: center; }
.review-actions button { padding: 8px 20px; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; font-size: 0.9em; }
#btn-confirm { background: #238636; color: #fff; }
#btn-confirm:hover { background: #2ea043; }
#btn-select-all { background: #30363d; color: #c9d1d9; }
#btn-select-all:hover { background: #484f58; }
#btn-select-none { background: #30363d; color: #c9d1d9; }
#btn-select-none:hover { background: #484f58; }
.review-count { color: #8b949e; font-size: 0.85em; margin-left: 8px; }
#review-panel.confirmed { border-color: #3fb950; opacity: 0.6; pointer-events: none; }
#review-panel.confirmed h2 { color: #3fb950; }
/* Per-card review queue */
.review-queue { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.queue-card { display: flex; align-items: center; gap: 12px; background: #0d1117; border: 1px solid #30363d; border-radius: 8px; padding: 10px 14px; transition: border-color 0.15s, opacity 0.2s; }
.queue-card.active { border-color: #d29922; background: #d299220a; }
.queue-card.approved { border-color: #3fb950; opacity: 0.7; }
.queue-card.approved .qc-status { color: #3fb950; }
.queue-card.rejected { border-color: #f85149; opacity: 0.5; }
.queue-card.rejected .qc-status { color: #f85149; }
.queue-card.pending { opacity: 0.5; }
.qc-index { font-weight: 700; color: #8b949e; min-width: 24px; text-align: center; }
.qc-info { flex: 1; min-width: 0; }
.qc-title { font-weight: 600; font-size: 0.9em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qc-snippet { font-size: 0.78em; color: #8b949e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qc-status { font-size: 0.75em; font-weight: 600; text-transform: uppercase; min-width: 60px; text-align: right; }
.queue-actions { display: flex; gap: 8px; margin-top: 4px; }
.queue-actions button { padding: 7px 18px; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; font-size: 0.88em; }
#btn-approve { background: #238636; color: #fff; }
#btn-approve:hover { background: #2ea043; }
#btn-reject { background: #da3633; color: #fff; }
#btn-reject:hover { background: #f85149; }
#btn-approve-all { background: #1f6feb; color: #fff; }
#btn-approve-all:hover { background: #388bfd; }
.queue-actions button:disabled { opacity: 0.4; cursor: not-allowed; }
/* ConfigGate panel */
#config-panel { display: none; margin-bottom: 20px; padding: 16px; background: #161b22; border: 2px solid #1f6feb; border-radius: 8px; }
#config-panel.active { display: block; }
#config-panel h2 { color: #58a6ff; font-size: 1.1em; margin-bottom: 4px; }
#config-panel .config-subtitle { color: #8b949e; font-size: 0.85em; margin-bottom: 14px; }
.config-section { margin-bottom: 16px; }
.config-section-title { font-size: 0.85em; font-weight: 600; margin-bottom: 8px; padding: 4px 0; }
.config-section-title.carrier { color: #f0883e; }
.config-section-title.functional { color: #8b949e; }
.config-section-title.satisfied { color: #3fb950; }
.cred-item { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; margin-bottom: 10px; padding: 10px 12px; background: #0d1117; border: 1px solid #30363d; border-radius: 6px; }
.cred-item.satisfied { opacity: 0.6; }
.cred-label { flex: 1; min-width: 200px; }
.cred-var { font-weight: 600; font-size: 0.9em; color: #c9d1d9; font-family: monospace; }
.cred-desc { font-size: 0.78em; color: #8b949e; margin-top: 2px; }
.cred-obtain { font-size: 0.75em; color: #484f58; margin-top: 2px; }
.cred-projects { font-size: 0.72em; color: #6e7681; margin-top: 2px; }
.cred-input { flex: 1; min-width: 250px; }
.cred-input input { width: 100%; padding: 6px 10px; background: #0d1117; border: 1px solid #30363d; border-radius: 4px; color: #c9d1d9; font-family: monospace; font-size: 0.85em; }
.cred-input input:focus { border-color: #58a6ff; outline: none; }
.cred-input input::placeholder { color: #484f58; }
.config-actions { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.config-actions button { padding: 8px 20px; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; font-size: 0.9em; }
#btn-config-confirm { background: #238636; color: #fff; }
#btn-config-confirm:hover { background: #2ea043; }
#btn-config-skip { background: #30363d; color: #c9d1d9; }
#btn-config-skip:hover { background: #484f58; }
.config-count { color: #8b949e; font-size: 0.85em; margin-left: 8px; }
#config-panel.confirmed { border-color: #3fb950; opacity: 0.6; pointer-events: none; }
#config-panel.confirmed h2 { color: #3fb950; }
/* Validation status indicators */
.cred-validation { display: flex; align-items: center; gap: 6px; margin-top: 4px; min-height: 20px; }
.cred-validation .val-spinner { width: 14px; height: 14px; border: 2px solid #30363d; border-top-color: #58a6ff; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.cred-validation .val-ok { color: #3fb950; font-size: 0.82em; }
.cred-validation .val-err { color: #f85149; font-size: 0.82em; }
.cred-validation .val-warn { color: #d29922; font-size: 0.82em; }
.cred-validation .val-skip { color: #8b949e; font-size: 0.82em; }
.btn-validate { padding: 4px 10px; background: #30363d; color: #c9d1d9; border: 1px solid #484f58; border-radius: 4px; cursor: pointer; font-size: 0.78em; margin-top: 4px; }
.btn-validate:hover { background: #484f58; }
.config-warning-count { color: #d29922; font-size: 0.82em; margin-left: 8px; }
</style>
</head>
<body>
<h1>Hackathon Agent Dashboard</h1>
<div class="subtitle">Real-time monitoring for autonomous hackathon ideation</div>
<div id="conn-status" class="disconnected">Connecting to ws://localhost:8765...</div>
<div class="status-bar">
<div class="stat"><span class="stat-label">Stage</span><span class="stat-value" id="s-stage">—</span></div>
<div class="stat"><span class="stat-label">Sessions</span><span class="stat-value" id="s-sessions">0</span></div>
<div class="stat"><span class="stat-label">Completed</span><span class="stat-value" id="s-completed" style="color:#3fb950">0</span></div>
<div class="stat"><span class="stat-label">Failed</span><span class="stat-value" id="s-failed" style="color:#f85149">0</span></div>
<div class="stat"><span class="stat-label">Idea Cards</span><span class="stat-value" id="s-cards" style="color:#d2a8ff">0</span></div>
</div>
<!-- Review Gate Panel (hidden by default) -->
<div id="review-panel">
<h2>Review Gate: Approve Idea Cards</h2>
<div class="review-subtitle">Review each card one at a time. Approved cards immediately start building.</div>
<div class="review-queue" id="review-queue"></div>
<div class="queue-actions" id="queue-actions" style="display:none;">
<button id="btn-approve" onclick="respondCard('approve')">Approve</button>
<button id="btn-reject" onclick="respondCard('reject')">Reject</button>
<button id="btn-approve-all" onclick="respondCard('approve_all')">Approve All Remaining</button>
<span class="review-count" id="review-count"></span>
</div>
</div>
<!-- ConfigGate Panel (hidden by default) -->
<div id="config-panel">
<h2>ConfigGate: API Credentials</h2>
<div class="config-subtitle">Fill in the required API keys. Projects missing carrier dependencies will be blocked.</div>
<div id="config-satisfied" class="config-section" style="display:none;">
<div class="config-section-title satisfied">✅ Already Satisfied</div>
<div id="config-satisfied-list"></div>
</div>
<div id="config-carrier" class="config-section" style="display:none;">
<div class="config-section-title carrier">🔑 Required (carrier) — projects blocked without these</div>
<div id="config-carrier-list"></div>
</div>
<div id="config-functional" class="config-section" style="display:none;">
<div class="config-section-title functional">🔧 Optional (functional) — features skipped if missing</div>
<div id="config-functional-list"></div>
</div>
<div class="config-actions">
<button id="btn-config-confirm" onclick="submitConfig()">Confirm & Continue</button>
<button id="btn-config-skip" onclick="submitConfig(true)">Skip All</button>
<span class="config-count" id="config-count"></span>
<span class="config-warning-count" id="config-warning-count" style="display:none"></span>
</div>
</div>
<div class="columns">
<div class="col-sessions">
<div class="section-title">Sessions</div>
<div id="sessions-container"></div>
</div>
<div class="col-events">
<div class="section-title">Event Stream</div>
<div class="event-stream" id="event-stream"></div>
</div>
</div>
<script>
const WS_URL = 'ws://localhost:8765';
const sessions = {}; // session_id -> {status, activity, logs[]}
let totalCompleted = 0, totalFailed = 0, totalCards = 0;
let wsConnection = null;
let reviewCards = []; // card summaries from review_requested
function fmtTime(ts) {
const d = new Date(ts * 1000);
return d.toLocaleTimeString('en-US', {hour12: false, hour:'2-digit', minute:'2-digit', second:'2-digit'});
}
function getOrCreateSession(id) {
if (!sessions[id]) {
sessions[id] = { status: 'pending', activity: '', logs: [] };
renderSession(id);
}
return sessions[id];
}
function renderSession(id) {
const container = document.getElementById('sessions-container');
let el = document.getElementById('sess-' + id);
if (!el) {
el = document.createElement('div');
el.className = 'session';
el.id = 'sess-' + id;
el.innerHTML = `
<div class="session-header" onclick="toggleSession('${id}')">
<span class="session-id">${id}</span>
<span class="session-badge badge-pending" id="badge-${id}">pending</span>
</div>
<div class="session-activity" id="activity-${id}"></div>
<div class="session-body" id="body-${id}"></div>
`;
container.prepend(el);
}
const s = sessions[id];
const badge = document.getElementById('badge-' + id);
badge.textContent = s.status;
badge.className = 'session-badge badge-' + s.status;
document.getElementById('activity-' + id).textContent = s.activity;
document.getElementById('s-sessions').textContent = Object.keys(sessions).length;
}
function appendLog(id, text, ts) {
const s = getOrCreateSession(id);
s.logs.push({ text, ts });
const body = document.getElementById('body-' + id);
if (body) {
const line = document.createElement('div');
line.className = 'log-line';
line.innerHTML = `<span class="ts">${fmtTime(ts)}</span>${escHtml(text)}`;
body.appendChild(line);
}
}
function toggleSession(id) {
const body = document.getElementById('body-' + id);
if (body) body.classList.toggle('open');
}
function addEvent(type, text, ts) {
const stream = document.getElementById('event-stream');
const item = document.createElement('div');
item.className = 'event-item';
item.innerHTML = `<span class="ev-time">${fmtTime(ts)}</span><span class="ev-type">${escHtml(type)}</span>${escHtml(text)}`;
stream.prepend(item);
// Keep max 200 events
while (stream.children.length > 200) stream.removeChild(stream.lastChild);
}
function escHtml(s) { const d = document.createElement('div'); d.textContent = s; return d.innerHTML; }
// ---- Per-card Review Queue Logic ----
let reviewQueueCards = [];
let activeCardIndex = -1;
let approvedCount = 0, rejectedCount = 0;
function showReviewQueue(cards) {
reviewQueueCards = cards;
approvedCount = 0;
rejectedCount = 0;
activeCardIndex = -1;
const container = document.getElementById('review-queue');
container.innerHTML = '';
cards.forEach((card, i) => {
const el = document.createElement('div');
el.className = 'queue-card pending';
el.id = 'qcard-' + card.index;
el.innerHTML = `
<div class="qc-index">${i + 1}</div>
<div class="qc-info">
<div class="qc-title">${escHtml(card.title)}</div>
<div class="qc-snippet">${escHtml(card.scenario_excerpt || '')}</div>
</div>
<div class="qc-status">pending</div>
`;
container.appendChild(el);
});
document.getElementById('review-panel').classList.add('active');
updateQueueCount();
}
function highlightCard(index) {
activeCardIndex = index;
// Remove active from all, set on current
document.querySelectorAll('.queue-card.active').forEach(el => el.classList.remove('active'));
const el = document.getElementById('qcard-' + index);
if (el) {
el.classList.remove('pending');
el.classList.add('active');
el.querySelector('.qc-status').textContent = 'reviewing';
}
// Show action buttons
document.getElementById('queue-actions').style.display = 'flex';
// Enable buttons
document.querySelectorAll('.queue-actions button').forEach(b => b.disabled = false);
updateQueueCount();
}
function markCard(index, action) {
const el = document.getElementById('qcard-' + index);
if (!el) return;
// Skip if already in final state (avoid double-counting from approve_all echo)
if (el.classList.contains('approved') || el.classList.contains('rejected')) return;
el.classList.remove('active', 'pending');
el.classList.add(action === 'approved' ? 'approved' : 'rejected');
el.querySelector('.qc-status').textContent = action;
if (action === 'approved') approvedCount++;
else rejectedCount++;
updateQueueCount();
}
function respondCard(action) {
if (activeCardIndex < 0) return;
const respondingIndex = activeCardIndex;
// Disable buttons while waiting for next card
document.querySelectorAll('.queue-actions button').forEach(b => b.disabled = true);
// Optimistically mark the current card locally for immediate feedback
if (action === 'approve') {
markCard(respondingIndex, 'approved');
} else if (action === 'reject') {
markCard(respondingIndex, 'rejected');
} else if (action === 'approve_all') {
// Mark current and all remaining pending cards
reviewQueueCards.forEach(card => {
markCard(card.index, 'approved');
});
activeCardIndex = -1;
document.getElementById('queue-actions').style.display = 'none';
}
// Send response to server
if (wsConnection && wsConnection.readyState === WebSocket.OPEN) {
wsConnection.send(JSON.stringify({
type: 'card_review_response',
card_index: respondingIndex,
action: action,
}));
}
}
function finishReviewQueue(data) {
activeCardIndex = -1;
document.getElementById('queue-actions').style.display = 'none';
document.getElementById('review-panel').classList.add('confirmed');
const approved = data.approved ?? approvedCount;
const rejected = data.rejected ?? rejectedCount;
document.querySelector('#review-panel h2').textContent =
`Review Complete: ${approved} approved, ${rejected} rejected`;
}
function updateQueueCount() {
const total = reviewQueueCards.length;
const remaining = total - approvedCount - rejectedCount;
document.getElementById('review-count').textContent =
`${approvedCount} approved, ${rejectedCount} rejected, ${remaining} remaining`;
}
// ---- ConfigGate Logic ----
let configCredentials = []; // [{env_var, name, obtain, projects, category}]
function showConfigPanel(data) {
const panel = document.getElementById('config-panel');
panel.classList.add('active');
configCredentials = [];
// Satisfied
const satisfiedList = document.getElementById('config-satisfied-list');
const satisfiedSection = document.getElementById('config-satisfied');
satisfiedList.innerHTML = '';
if (data.satisfied && data.satisfied.length > 0) {
satisfiedSection.style.display = 'block';
data.satisfied.forEach(s => {
const el = document.createElement('div');
el.className = 'cred-item satisfied';
el.innerHTML = `<div class="cred-label"><span class="cred-var">${escHtml(s.env_var)}</span></div>`;
satisfiedList.appendChild(el);
});
}
// Carrier
const carrierList = document.getElementById('config-carrier-list');
const carrierSection = document.getElementById('config-carrier');
carrierList.innerHTML = '';
if (data.carrier && data.carrier.length > 0) {
carrierSection.style.display = 'block';
data.carrier.forEach(c => {
configCredentials.push({...c, category: 'carrier'});
carrierList.appendChild(createCredInput(c));
});
}
// Functional
const funcList = document.getElementById('config-functional-list');
const funcSection = document.getElementById('config-functional');
funcList.innerHTML = '';
if (data.functional && data.functional.length > 0) {
funcSection.style.display = 'block';
data.functional.forEach(f => {
configCredentials.push({...f, category: 'functional'});
funcList.appendChild(createCredInput(f));
});
}
updateConfigCount();
}
function createCredInput(cred) {
const el = document.createElement('div');
el.className = 'cred-item';
el.innerHTML = `
<div class="cred-label">
<div class="cred-var">${escHtml(cred.env_var)}</div>
<div class="cred-desc">${escHtml(cred.name)}</div>
${cred.obtain ? `<div class="cred-obtain">Obtain: ${escHtml(cred.obtain)}</div>` : ''}
<div class="cred-projects">Used by: ${(cred.projects || []).map(escHtml).join(', ')}</div>
</div>
<div class="cred-input">
<input type="text" id="cred-${cred.env_var}" placeholder="${cred.env_var}"
oninput="updateConfigCount(); clearValidation('${cred.env_var}')"
onblur="validateCredField('${cred.env_var}')">
<div class="cred-validation" id="val-${cred.env_var}"></div>
</div>
`;
return el;
}
function updateConfigCount() {
let filled = 0;
configCredentials.forEach(c => {
const input = document.getElementById('cred-' + c.env_var);
if (input && input.value.trim()) filled++;
});
document.getElementById('config-count').textContent =
`${filled} / ${configCredentials.length} filled`;
}
// Track validation state per field
let validationResults = {}; // env_var -> {valid, error, warning, skipped}
function validateCredField(envVar) {
const input = document.getElementById('cred-' + envVar);
if (!input || !input.value.trim()) return;
const valEl = document.getElementById('val-' + envVar);
if (!valEl) return;
// Show spinner
valEl.innerHTML = '<div class="val-spinner"></div>';
// Send validation request to server
if (wsConnection && wsConnection.readyState === WebSocket.OPEN) {
wsConnection.send(JSON.stringify({
type: 'config_validate_request',
env_var: envVar,
value: input.value.trim(),
}));
} else {
valEl.innerHTML = '<span class="val-warn">⚠️ Not connected</span>';
}
}
function clearValidation(envVar) {
const valEl = document.getElementById('val-' + envVar);
if (valEl) valEl.innerHTML = '';
delete validationResults[envVar];
updateConfigWarnings();
}
function handleValidateResponse(data) {
const envVar = data.env_var;
const valEl = document.getElementById('val-' + envVar);
if (!valEl) return;
validationResults[envVar] = data;
if (data.skipped) {
valEl.innerHTML = '<span class="val-skip">— no validator</span>';
} else if (data.valid) {
if (data.warning) {
valEl.innerHTML = `<span class="val-warn">⚠️ ${escHtml(data.warning)}</span>`;
} else {
valEl.innerHTML = '<span class="val-ok">✅ Valid</span>';
}
} else {
valEl.innerHTML = `<span class="val-err">❌ ${escHtml(data.error)}</span>`;
}
updateConfigWarnings();
}
function updateConfigWarnings() {
const failures = Object.values(validationResults).filter(r => !r.valid && !r.skipped);
const warnEl = document.getElementById('config-warning-count');
if (!warnEl) return;
if (failures.length > 0) {
warnEl.textContent = `⚠️ ${failures.length} validation failure${failures.length > 1 ? 's' : ''}`;
warnEl.style.display = 'inline';
} else {
warnEl.textContent = '';
warnEl.style.display = 'none';
}
}
function submitConfig(skipAll) {
const credentials = {};
if (!skipAll) {
configCredentials.forEach(c => {
const input = document.getElementById('cred-' + c.env_var);
if (input && input.value.trim()) {
credentials[c.env_var] = input.value.trim();
}
});
}
// Send to server
if (wsConnection && wsConnection.readyState === WebSocket.OPEN) {
wsConnection.send(JSON.stringify({
type: 'config_response',
credentials: credentials,
}));
}
// Mark panel as confirmed
const panel = document.getElementById('config-panel');
panel.classList.add('confirmed');
const count = Object.keys(credentials).length;
document.querySelector('#config-panel h2').textContent =
skipAll ? 'ConfigGate: Skipped' : `ConfigGate: ${count} credentials submitted`;
}
// ---- Event Handling ----
function handleEvent(ev) {
const { type, data, timestamp } = ev;
const ts = timestamp || Date.now() / 1000;
addEvent(type, JSON.stringify(data).slice(0, 120), ts);
if (type === 'session_started') {
const s = getOrCreateSession(data.session_id);
s.status = 'running';
s.activity = `Starting (${data.model || 'sonnet'})`;
renderSession(data.session_id);
appendLog(data.session_id, 'Session started', ts);
}
else if (type === 'session_progress') {
const s = getOrCreateSession(data.session_id);
s.activity = data.activity || '';
renderSession(data.session_id);
appendLog(data.session_id, data.activity || 'progress', ts);
}
else if (type === 'session_completed') {
const s = getOrCreateSession(data.session_id);
s.status = 'completed';
s.activity = `Done in ${data.duration || '?'}s — ${(data.files||[]).length} files`;
totalCompleted++;
document.getElementById('s-completed').textContent = totalCompleted;
renderSession(data.session_id);
appendLog(data.session_id, `Completed: ${(data.files||[]).join(', ')}`, ts);
}
else if (type === 'session_failed') {
const s = getOrCreateSession(data.session_id);
s.status = 'failed';
s.activity = data.error || 'Unknown error';
totalFailed++;
document.getElementById('s-failed').textContent = totalFailed;
renderSession(data.session_id);
appendLog(data.session_id, `Failed: ${data.error}`, ts);
}
else if (type === 'session_retrying') {
const s = getOrCreateSession(data.session_id);
s.status = 'retrying';
s.activity = `Retry attempt ${data.attempt}`;
renderSession(data.session_id);
}
else if (type === 'stage_started') {
document.getElementById('s-stage').textContent = `Stage ${data.stage}`;
}
else if (type === 'stage_completed') {
document.getElementById('s-stage').textContent = `Stage ${data.stage} ✓`;
if (data.cards !== undefined) {
totalCards = data.cards;
document.getElementById('s-cards').textContent = totalCards;
}
}
else if (type === 'directions_found') {
addEvent('info', `Found ${data.count} crowd directions: ${(data.directions||[]).join(', ')}`, ts);
}
else if (type === 'review_requested') {
// Legacy batch review (kept for backward compat)
showReviewQueue(data.cards || []);
}
else if (type === 'review_queue_started') {
showReviewQueue(data.cards || []);
}
else if (type === 'card_review_requested') {
highlightCard(data.index);
}
else if (type === 'card_reviewed') {
markCard(data.index, data.action);
}
else if (type === 'review_queue_completed') {
finishReviewQueue(data);
}
else if (type === 'review_completed') {
// Legacy batch review completed
finishReviewQueue({ approved: data.selected, rejected: (data.total || 0) - (data.selected || 0) });
}
else if (type === 'config_requested') {
showConfigPanel(data);
}
else if (type === 'config_validate_response') {
handleValidateResponse(data);
}
else if (type === 'config_collected') {
addEvent('config', `Collected ${data.count} credentials`, ts);
}
else if (type === 'config_blocked') {
addEvent('config', `BLOCKED ${data.slug}: missing ${(data.missing || []).join(', ')}`, ts);
}
else if (type === 'dev_completed') {
const s = getOrCreateSession(data.session_id);
s.activity = `Project built${data.has_readme ? ' (README)' : ''}`;
renderSession(data.session_id);
appendLog(data.session_id, `Project: ${data.project_dir}`, ts);
}
else if (type === 'dev_failed') {
const s = getOrCreateSession(data.session_id);
s.activity = `Build failed: ${(data.error || 'unknown').slice(0, 80)}`;
renderSession(data.session_id);
appendLog(data.session_id, `Dev failed: ${data.error}`, ts);
}
else if (type === 'publish_started') {
addEvent('publish', `Publishing ${data.repo_name}...`, ts);
}
else if (type === 'publish_completed') {
addEvent('publish', `Published: ${data.repo_url}`, ts);
}
else if (type === 'publish_failed') {
addEvent('publish', `Failed to publish ${data.repo_name}: ${(data.error || '').slice(0, 80)}`, ts);
}
else if (type === 'pitch_started') {
addEvent('pitch', `Generating pitch for ${data.slug}...`, ts);
}
else if (type === 'pitch_script_completed') {
addEvent('pitch', `Pitch script ready: ${data.slug}`, ts);
}
else if (type === 'pitch_deck_completed') {
addEvent('pitch', `Pitch deck ready: ${data.slug}`, ts);
}
else if (type === 'pitch_deck_failed') {
addEvent('pitch', `Pitch failed: ${(data.error || '').slice(0, 80)}`, ts);
}
}
// WebSocket connection with auto-reconnect
function connect() {
const ws = new WebSocket(WS_URL);
wsConnection = ws;
const connEl = document.getElementById('conn-status');
ws.onopen = () => { connEl.className = 'connected'; connEl.textContent = 'Connected to control server'; };
ws.onclose = () => { connEl.className = 'disconnected'; connEl.textContent = 'Disconnected — reconnecting...'; setTimeout(connect, 2000); };
ws.onerror = () => { ws.close(); };
ws.onmessage = (msg) => {
try { handleEvent(JSON.parse(msg.data)); } catch(e) { console.error('Parse error:', e); }
};
}
connect();
</script>
</body>
</html>