@xiangyixie/dsh-superagent 0.14.2 → 0.14.3

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.
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>Superagent Console</title>
6
+ <title>Superagent 专属空间</title>
7
7
  <style>
8
8
  :root {
9
9
  color-scheme: dark;
@@ -45,6 +45,7 @@
45
45
 
46
46
  .shell { height: 100%; display: flex; flex-direction: column; }
47
47
  .topbar {
48
+ position: relative; z-index: 22;
48
49
  flex: 0 0 58px;
49
50
  display: flex; align-items: center; gap: 18px;
50
51
  padding: 0 20px;
@@ -87,11 +88,6 @@
87
88
  .btn:hover { color: var(--text); border-color: #35464f; background: #172028; }
88
89
  .btn:disabled { opacity: .45; cursor: default; }
89
90
 
90
- .grid {
91
- flex: 1; min-height: 0;
92
- display: grid; grid-template-columns: minmax(0, 1fr) 392px;
93
- gap: 14px; padding: 14px 18px 18px;
94
- }
95
91
  .panel {
96
92
  min-height: 0; display: flex; flex-direction: column;
97
93
  border: 1px solid var(--line-soft); border-radius: var(--radius);
@@ -231,12 +227,6 @@
231
227
  .send:disabled { opacity: .35; cursor: default; }
232
228
  .composer.note { color: var(--faint); font-size: 12px; text-align: center; padding: 18px; }
233
229
 
234
- .runs-head {
235
- display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
236
- padding: 16px 17px 13px; border-bottom: 1px solid var(--line-soft);
237
- }
238
- .runs-head h2 { margin: 0; font-size: 14px; }
239
- .runs-head p { margin: 3px 0 0; color: var(--faint); font-size: 11px; }
240
230
  .count {
241
231
  min-width: 24px; height: 22px; padding: 0 7px; border-radius: 999px;
242
232
  display: inline-grid; place-items: center;
@@ -244,15 +234,6 @@
244
234
  font: 11px var(--mono);
245
235
  }
246
236
  .tools:empty { display: none; }
247
- .tools-panel { border-bottom: 1px solid var(--line-soft); padding: 10px 14px; }
248
- .tools-panel summary {
249
- display: flex; align-items: center; gap: 8px; cursor: pointer;
250
- color: var(--muted); font-size: 12px; list-style: none;
251
- }
252
- .tools-panel summary::-webkit-details-marker { display: none; }
253
- .tools-panel summary::before { content: "▸"; color: var(--faint); font-size: 10px; }
254
- .tools-panel[open] summary::before { content: "▾"; }
255
- .tools-panel .count { margin-left: auto; }
256
237
  .tools-note { margin: 7px 0 0; color: var(--faint); font-size: 11px; line-height: 1.6; }
257
238
  .tool-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; max-height: 132px; overflow-y: auto; }
258
239
  .tool-name {
@@ -260,25 +241,6 @@
260
241
  background: #121a20; color: var(--muted); font: 10.5px var(--mono);
261
242
  }
262
243
  .tool-name.on { border-color: #2c5a48; color: #9fe0c2; }
263
- .run-list { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; }
264
- .run-empty { padding: 26px 18px; color: var(--faint); text-align: center; font-size: 12px; line-height: 1.7; }
265
- .run-empty .line { display: block; width: 30px; height: 1px; margin: 12px auto; background: var(--line); }
266
- .run {
267
- position: relative; margin-bottom: 10px; padding: 12px;
268
- border: 1px solid var(--line-soft); border-radius: 11px;
269
- background: #10161b;
270
- }
271
- .run::before {
272
- content: ""; position: absolute; left: 0; top: 11px; bottom: 11px; width: 2px; border-radius: 2px;
273
- background: var(--line);
274
- }
275
- .run.running::before { background: var(--amber); }
276
- .run.completed::before { background: var(--green); }
277
- .run.failed::before, .run.interrupted::before { background: var(--red); }
278
- .run-top { display: flex; align-items: flex-start; gap: 8px; }
279
- .run-title { flex: 1; min-width: 0; }
280
- .run-title h3 { margin: 0; font-size: 12.5px; font-weight: 600; line-height: 1.45; word-break: break-word; }
281
- .run-title p { margin: 3px 0 0; color: var(--faint); font: 10.5px var(--mono); }
282
244
  .status-pill {
283
245
  flex: none; padding: 2px 7px; border-radius: 999px;
284
246
  border: 1px solid var(--line); color: var(--muted); font-size: 10.5px; white-space: nowrap;
@@ -286,19 +248,8 @@
286
248
  .status-pill.running { color: var(--amber); border-color: rgba(246, 193, 119, .32); background: var(--amber-soft); }
287
249
  .status-pill.completed { color: var(--green); border-color: rgba(99, 214, 164, .32); background: rgba(99, 214, 164, .07); }
288
250
  .status-pill.failed, .status-pill.interrupted { color: var(--red); border-color: rgba(255, 123, 114, .32); background: rgba(255, 123, 114, .07); }
289
- .run-meta { display: flex; flex-wrap: wrap; gap: 10px; margin: 9px 0 0; color: var(--faint); font-size: 11px; }
290
- .run-meta b { color: var(--muted); font-weight: 600; }
291
251
  .progress { height: 3px; margin: 9px 0 0; border-radius: 999px; background: #1b252c; overflow: hidden; }
292
252
  .progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #3dc6b5, var(--accent)); transition: width .3s; }
293
- .subtasks { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
294
- .subtask {
295
- max-width: 100%; padding: 2px 7px; border-radius: 6px;
296
- border: 1px solid var(--line-soft); color: var(--faint); font-size: 10.5px;
297
- white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
298
- }
299
- .subtask.completed { color: var(--green); border-color: rgba(99, 214, 164, .22); }
300
- .subtask.running { color: var(--amber); border-color: rgba(246, 193, 119, .22); }
301
- .subtask.failed { color: var(--red); border-color: rgba(255, 123, 114, .22); }
302
253
  .attention-card {
303
254
  margin-top: 10px; padding: 10px; border-radius: 9px;
304
255
  border: 1px solid rgba(246, 193, 119, .36); background: var(--amber-soft);
@@ -308,6 +259,31 @@
308
259
  }
309
260
  .attention-card p { margin: 5px 0 0; color: #edd7b2; font-size: 12px; line-height: 1.55; white-space: pre-wrap; }
310
261
  .attention-card .reason { color: #b9a789; font-size: 11px; }
262
+ .approval-card {
263
+ margin-top: 10px; padding: 10px 12px; border-radius: 9px;
264
+ border: 1px solid rgba(246, 193, 119, .40); background: var(--amber-soft);
265
+ }
266
+ .approval-card .kicker {
267
+ color: var(--amber); font: 10px var(--mono); letter-spacing: .08em; text-transform: uppercase;
268
+ }
269
+ .approval-card .what { margin-top: 6px; color: #e9d9bd; font-size: 11.5px; }
270
+ .approval-card .what b { color: #f6e3c4; font-weight: 600; }
271
+ .approval-card .where {
272
+ margin-top: 6px; padding: 5px 7px; border-radius: 6px;
273
+ background: rgba(10, 15, 18, .5); color: #f0dcbb;
274
+ font: 11px var(--mono); word-break: break-all;
275
+ }
276
+ .approval-card .why {
277
+ margin: 6px 0 0; color: #edd7b2; font-size: 12px; line-height: 1.55; white-space: pre-wrap;
278
+ }
279
+ .approval-card .state { margin-top: 8px; color: #b9a789; font-size: 11px; }
280
+ .approval-card .options { margin-top: 8px; }
281
+ .approval-card .options button.allow {
282
+ border-color: rgba(126, 214, 160, .5); background: rgba(126, 214, 160, .12); color: #cdeed8;
283
+ }
284
+ .approval-card .options button.reject {
285
+ border-color: rgba(240, 130, 130, .5); background: rgba(240, 130, 130, .1); color: #f3cccc;
286
+ }
311
287
  .options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
312
288
  .options button {
313
289
  padding: 4px 9px; border-radius: 7px;
@@ -334,12 +310,137 @@
334
310
  border-radius: 8px; border: 1px solid var(--line-soft); background: #0a0f12;
335
311
  color: var(--muted); font: 11px/1.6 var(--mono); white-space: pre-wrap; word-break: break-word;
336
312
  }
337
- .run-actions { display: flex; gap: 8px; margin-top: 8px; }
338
- .run-actions button {
339
- height: 25px; padding: 0 8px; border-radius: 6px;
340
- border: 1px solid var(--line); background: transparent; color: var(--faint); font-size: 10.5px;
313
+ .env-bar {
314
+ flex: 0 0 auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
315
+ padding: 6px 20px; border-bottom: 1px solid var(--line-soft);
316
+ background: rgba(11, 15, 18, .55);
317
+ }
318
+ .env-bar[hidden] { display: none; }
319
+ .env-title { color: var(--faint); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; }
320
+ .env-items { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 0; }
321
+ .env-item {
322
+ display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 8px;
323
+ border-radius: 999px; border: 1px solid var(--line-soft); background: #10171c;
324
+ color: var(--muted); font-size: 11px;
325
+ cursor: pointer; font-family: inherit;
326
+ }
327
+ .env-item:hover { border-color: var(--line); }
328
+ .env-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
329
+ .env-item.ok .dot { background: var(--green); }
330
+ .env-item.bad { border-color: rgba(246, 193, 119, .34); color: #e8c690; background: var(--amber-soft); }
331
+ .env-item.bad .dot { background: var(--amber); }
332
+ .env-item .env-action { color: var(--accent); font-size: 10.5px; }
333
+ .env-item .env-value { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
334
+ .env-item.bad .env-value { color: #c9ab7f; }
335
+ .btn.tiny { height: 24px; padding: 0 9px; font-size: 11px; }
336
+
337
+ #wizardDialog { width: min(720px, calc(100vw - 32px)); }
338
+ .wiz-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px 12px; border-bottom: 1px solid var(--line-soft); }
339
+ .wiz-head h2 { margin: 2px 0 0; font-size: 16px; }
340
+ .wiz-head .kicker { color: var(--accent); font: 10px var(--mono); letter-spacing: .14em; text-transform: uppercase; }
341
+ .wiz-head button { border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; }
342
+ .wiz-steps { display: flex; gap: 6px; padding: 12px 18px 0; }
343
+ .wiz-step {
344
+ flex: 1; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line-soft);
345
+ background: #0e1418; color: var(--faint); font-size: 11px; text-align: center;
346
+ }
347
+ .wiz-step.active { border-color: rgba(94, 234, 212, .4); color: var(--text); background: rgba(94, 234, 212, .07); }
348
+ .wiz-step.done { color: var(--green); border-color: rgba(99, 214, 164, .25); }
349
+ .wiz-body { padding: 14px 18px 8px; overflow: auto; max-height: calc(100vh - 270px); }
350
+ .wiz-lead { margin: 0 0 10px; color: var(--muted); font-size: 12px; line-height: 1.7; }
351
+ .wiz-checks { display: flex; flex-direction: column; gap: 7px; }
352
+ .wiz-check {
353
+ display: flex; align-items: flex-start; gap: 9px; padding: 9px 10px;
354
+ border-radius: 9px; border: 1px solid var(--line-soft); background: #0e1418;
355
+ }
356
+ .wiz-check.bad { border-color: rgba(246, 193, 119, .3); background: var(--amber-soft); }
357
+ .wiz-check .dot { flex: none; width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--green); }
358
+ .wiz-check.bad .dot { background: var(--amber); }
359
+ .wiz-check .body { flex: 1; min-width: 0; }
360
+ .wiz-check .label { font-size: 12px; color: var(--text); }
361
+ .wiz-check .value { margin-left: 6px; color: var(--muted); font: 11px var(--mono); word-break: break-all; }
362
+ .wiz-check .hint { margin-top: 3px; color: #c9ab7f; font-size: 11px; line-height: 1.55; }
363
+ .wiz-check button {
364
+ flex: none; height: 25px; padding: 0 8px; border-radius: 6px;
365
+ border: 1px solid rgba(246, 193, 119, .4); background: rgba(246, 193, 119, .1);
366
+ color: #f3d8ac; font-size: 11px;
341
367
  }
342
- .run-actions button:hover { color: var(--text); border-color: #35464f; }
368
+ .wiz-form { display: grid; gap: 10px; }
369
+ .wiz-field label { display: block; margin-bottom: 4px; color: var(--faint); font-size: 11px; }
370
+ .wiz-field input {
371
+ width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--line);
372
+ border-radius: 8px; background: #0a1014; color: var(--text); outline: 0; font-size: 12.5px;
373
+ }
374
+ .wiz-field input:focus { border-color: rgba(94, 234, 212, .48); }
375
+ .wiz-key-row { display: flex; align-items: center; gap: 8px; }
376
+ .wiz-key-row input { flex: 1; min-width: 0; }
377
+ .wiz-key-row .wiz-badge { flex: none; }
378
+ .wiz-note { color: var(--faint); font-size: 11px; line-height: 1.6; }
379
+ .wiz-badge {
380
+ display: inline-flex; align-items: center; gap: 5px; padding: 2px 7px; border-radius: 999px;
381
+ border: 1px solid var(--line); color: var(--faint); font-size: 10.5px;
382
+ }
383
+ .wiz-badge.ok { color: var(--green); border-color: rgba(99, 214, 164, .3); background: rgba(99, 214, 164, .07); }
384
+ .wiz-badge.bad { color: var(--amber); border-color: rgba(246, 193, 119, .3); background: var(--amber-soft); }
385
+ .wiz-error {
386
+ margin-top: 10px; padding: 9px 10px; border-radius: 9px; font-size: 11.5px; line-height: 1.6;
387
+ border: 1px solid rgba(255, 123, 114, .32); background: rgba(255, 123, 114, .07); color: #ffc0bb;
388
+ }
389
+ .wiz-error b { display: block; color: #ffd6d2; font-size: 12px; }
390
+ .wiz-summary { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
391
+ .wiz-summary li { position: relative; padding-left: 16px; color: var(--muted); font-size: 12px; line-height: 1.6; }
392
+ .wiz-summary li::before { content: "✓"; position: absolute; left: 0; color: var(--green); }
393
+ .wiz-kv {
394
+ display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 10px; padding: 10px;
395
+ border-radius: 9px; border: 1px solid var(--line-soft); background: #0e1418;
396
+ color: var(--faint); font-size: 11px;
397
+ }
398
+ .wiz-kv b { color: var(--muted); font-weight: 500; }
399
+ .wiz-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--line-soft); }
400
+ .wiz-foot .spacer { flex: 1; }
401
+ .wiz-primary {
402
+ height: 32px; padding: 0 14px; border-radius: 8px; border: 1px solid rgba(94, 234, 212, .4);
403
+ background: linear-gradient(145deg, var(--accent), #35c7b5); color: var(--accent-ink);
404
+ font-weight: 700; font-size: 12px;
405
+ }
406
+ .wiz-primary:disabled { opacity: .45; cursor: default; }
407
+ .wiz-secondary {
408
+ height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line);
409
+ background: var(--panel); color: var(--muted); font-size: 12px;
410
+ }
411
+ .wiz-trial-verdict {
412
+ display: flex; align-items: center; gap: 9px; padding: 11px 12px; border-radius: 10px;
413
+ border: 1px solid var(--line-soft); background: #0e1418;
414
+ }
415
+ .wiz-trial-verdict.ok { border-color: rgba(99, 214, 164, .3); background: rgba(99, 214, 164, .06); color: #b8ecd5; }
416
+ .wiz-trial-verdict.bad { border-color: rgba(246, 193, 119, .3); background: var(--amber-soft); color: #e8c690; }
417
+ .wiz-trial-verdict .big { font-size: 20px; }
418
+ .wiz-trial-verdict .t { font-size: 12.5px; }
419
+ .wiz-trial-verdict .d { color: var(--faint); font-size: 11px; }
420
+ .wiz-steps-list { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; }
421
+ .wiz-task {
422
+ display: flex; gap: 8px; align-items: flex-start; padding: 7px 9px; border-radius: 7px;
423
+ border: 1px solid var(--line-soft); background: #0e1418; font-size: 11.5px;
424
+ }
425
+ .wiz-task .dot { flex: none; width: 7px; height: 7px; margin-top: 5px; border-radius: 50%; background: var(--amber); }
426
+ .wiz-task.completed .dot { background: var(--green); }
427
+ .wiz-task.failed .dot { background: var(--red); }
428
+ .wiz-task .name { color: var(--text); font-family: var(--mono); font-size: 11px; }
429
+ .wiz-task .detail { margin-top: 2px; color: var(--faint); font-size: 11px; word-break: break-word; }
430
+ .wiz-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
431
+ .wiz-stat { padding: 9px 10px; border-radius: 9px; border: 1px solid var(--line-soft); background: #0e1418; }
432
+ .wiz-stat .k { color: var(--faint); font-size: 10.5px; }
433
+ .wiz-stat .v { margin-top: 2px; color: var(--text); font: 13px var(--mono); word-break: break-all; }
434
+ .wiz-file {
435
+ margin-top: 10px; padding: 8px 10px; border-radius: 8px; border: 1px dashed var(--line);
436
+ color: var(--muted); font-size: 11.5px;
437
+ }
438
+ .wiz-busy { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
439
+ .wiz-busy .spin {
440
+ width: 12px; height: 12px; border: 2px solid var(--line);
441
+ border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
442
+ }
443
+ @keyframes spin { to { transform: rotate(360deg); } }
343
444
 
344
445
  .toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 30; pointer-events: none; }
345
446
  .toast {
@@ -393,13 +494,110 @@
393
494
  background: #0a0f12; font: 12px/1.65 var(--mono); white-space: pre-wrap; word-break: break-word;
394
495
  }
395
496
 
396
- @media (max-width: 980px) {
397
- .grid { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(240px, 44vh); }
398
- .topbar-mid .session-label { display: none; }
399
- }
400
- @media (max-width: 620px) {
401
- .grid { padding: 10px; gap: 10px; }
402
- .topbar { padding: 0 12px; }
497
+ /* ---- conversation-first stage ---- */
498
+ .stage { flex: 1; min-height: 0; display: flex; justify-content: center; padding: 0 18px 18px; }
499
+ .stage .panel { width: min(960px, 100%); }
500
+ .chat-head p { color: var(--faint); }
501
+
502
+ /* ---- task lanes inside the conversation ---- */
503
+ .lane-group {
504
+ margin: 0 0 18px; padding: 10px 12px 12px;
505
+ border: 1px solid var(--line-soft); border-radius: 12px;
506
+ background: rgba(16, 23, 28, .72);
507
+ animation: rise .18s ease-out;
508
+ }
509
+ .lane-group-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--faint); font-size: 11px; letter-spacing: .03em; }
510
+ .lane-group-head .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); animation: blink 1.2s infinite; }
511
+ .lane-group-head.done .dot { background: var(--green); animation: none; }
512
+ .lane {
513
+ position: relative; margin-top: 8px; padding: 10px 11px;
514
+ border: 1px solid var(--line-soft); border-radius: 10px; background: #0f1519;
515
+ }
516
+ .lane:first-of-type { margin-top: 0; }
517
+ .lane::before { content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 2px; border-radius: 2px; background: var(--line); }
518
+ .lane.running::before { background: var(--amber); }
519
+ .lane.completed::before { background: var(--green); }
520
+ .lane.failed::before { background: var(--red); }
521
+ .lane-head { display: flex; align-items: flex-start; gap: 10px; }
522
+ .lane-title { flex: 1; min-width: 0; }
523
+ .lane-goal { font-size: 12.5px; font-weight: 600; line-height: 1.45; word-break: break-word; }
524
+ .lane-now { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: var(--muted); font-size: 11px; }
525
+ .lane-now .spark { flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--amber); animation: blink 1.1s infinite; }
526
+ .steps { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
527
+ .step { display: flex; align-items: flex-start; gap: 7px; color: var(--faint); font-size: 11px; line-height: 1.5; }
528
+ .step .sdot { flex: none; width: 6px; height: 6px; margin-top: 4px; border-radius: 50%; background: #3a4a55; }
529
+ .step.completed { color: var(--muted); }
530
+ .step.completed .sdot { background: var(--green); }
531
+ .step.running .sdot { background: var(--amber); animation: blink 1.1s infinite; }
532
+ .step.failed { color: #ffb4ae; }
533
+ .step.failed .sdot { background: var(--red); }
534
+ .lane-progress-text { margin-top: 5px; color: var(--faint); font-size: 10.5px; }
535
+
536
+ .summary {
537
+ margin-top: 10px; padding: 10px 11px; border-radius: 10px;
538
+ border: 1px solid rgba(99, 214, 164, .28); background: rgba(99, 214, 164, .05);
539
+ }
540
+ .summary.bad { border-color: rgba(255, 123, 114, .3); background: rgba(255, 123, 114, .05); }
541
+ .summary .st { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; }
542
+ .summary .sd { margin-top: 3px; color: var(--faint); font-size: 11px; }
543
+ .artifacts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
544
+ .artifact {
545
+ display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
546
+ padding: 4px 9px; border-radius: 8px; text-decoration: none;
547
+ border: 1px solid rgba(94, 234, 212, .3); background: rgba(94, 234, 212, .07); color: #bdf3e8; font-size: 11.5px;
548
+ }
549
+ .artifact:hover { background: rgba(94, 234, 212, .14); }
550
+ .artifact .ak { color: var(--faint); font: 10px var(--mono); }
551
+ .artifact .an { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
552
+ .sum-run { margin-top: 8px; }
553
+ .sum-run-title { color: var(--muted); font-size: 11.5px; margin-bottom: 4px; }
554
+ .msg.flash .bubble { box-shadow: 0 0 0 3px rgba(94, 234, 212, .18); transition: box-shadow .2s; }
555
+
556
+ /* ---- drawers ---- */
557
+ .scrim { position: fixed; inset: 58px 0 0; z-index: 20; background: rgba(5, 8, 10, .55); backdrop-filter: blur(2px); }
558
+ .scrim[hidden] { display: none; }
559
+ .drawer {
560
+ position: fixed; top: 58px; right: 0; bottom: 0; z-index: 21;
561
+ width: min(430px, calc(100vw - 40px));
562
+ display: flex; flex-direction: column;
563
+ border-left: 1px solid var(--line); background: var(--panel);
564
+ box-shadow: -30px 0 80px rgba(0, 0, 0, .45);
565
+ animation: slideIn .18s ease-out;
566
+ }
567
+ .drawer[hidden] { display: none; }
568
+ @keyframes slideIn { from { transform: translateX(16px); opacity: .4; } to { transform: none; opacity: 1; } }
569
+ .drawer-head { display: flex; align-items: flex-start; gap: 10px; padding: 16px 18px 12px; border-bottom: 1px solid var(--line-soft); }
570
+ .drawer-head h2 { margin: 2px 0 0; font-size: 14px; }
571
+ .drawer-head .kicker { color: var(--accent); font: 10px var(--mono); letter-spacing: .14em; text-transform: uppercase; }
572
+ .drawer-close { margin-left: auto; border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; }
573
+ .drawer-body { flex: 1; min-height: 0; overflow: auto; padding: 14px 16px 24px; }
574
+ .adv-sec { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line-soft); }
575
+ .adv-sec:last-child { border-bottom: 0; margin-bottom: 0; }
576
+ .adv-sec h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; color: var(--muted); font-size: 12px; font-weight: 600; }
577
+ .adv-kv { display: grid; gap: 5px; }
578
+ .adv-row { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; }
579
+ .adv-label { color: var(--faint); font-size: 11px; }
580
+ .adv-row code { color: var(--muted); font: 11px var(--mono); word-break: break-all; text-align: right; }
581
+ .adv-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
582
+ .adv-note { margin: 8px 0 0; color: var(--faint); font-size: 11px; line-height: 1.6; }
583
+ .adv-runs { display: flex; flex-direction: column; gap: 8px; }
584
+ .adv-run { padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line-soft); background: #0e1418; }
585
+ .adv-run .t { color: var(--muted); font-size: 11.5px; margin-bottom: 3px; word-break: break-word; }
586
+ .adv-run .m { color: var(--faint); font: 10.5px var(--mono); word-break: break-all; }
587
+ .adv-run .btn { margin-top: 7px; }
588
+ .hist-item {
589
+ display: block; width: 100%; margin-bottom: 10px; padding: 10px 11px;
590
+ border: 1px solid var(--line-soft); border-radius: 10px; background: #0f1519;
591
+ color: var(--text); text-align: left; cursor: pointer;
592
+ }
593
+ .hist-item:hover { border-color: #35464f; }
594
+ .hist-top { display: flex; align-items: center; gap: 8px; color: var(--faint); font-size: 10.5px; }
595
+ .hist-state { margin-left: auto; }
596
+ .hist-text { margin-top: 4px; font-size: 12px; line-height: 1.55; word-break: break-word; }
597
+
598
+ @media (max-width: 720px) {
599
+ .stage { padding: 0 10px 10px; }
600
+ .topbar { padding: 0 12px; gap: 10px; }
403
601
  .topbar-actions .conn { display: none; }
404
602
  .brand { min-width: 0; }
405
603
  .brand div span { display: none; }
@@ -413,58 +611,98 @@
413
611
  <header class="topbar">
414
612
  <div class="brand">
415
613
  <div class="mark">S</div>
416
- <div><strong>Superagent</strong><span>Console</span></div>
614
+ <div><strong>Superagent</strong><span>专属空间</span></div>
417
615
  </div>
418
616
  <div class="topbar-mid">
419
617
  <span id="modeBadge" class="badge"><span class="pulse"></span><span id="modeText">连接中</span></span>
420
- <span id="sessionLabel" class="session-label mono" title="Host Session id">no session</span>
618
+ <span id="sessionLabel" class="session-label mono" hidden></span>
421
619
  </div>
422
620
  <div class="topbar-actions">
423
621
  <span id="conn" class="conn"><i></i><span id="connText">连接中</span></span>
424
- <button id="newChat" class="btn" type="button" disabled>新对话</button>
622
+ <button id="historyOpen" class="btn" type="button">历史</button>
623
+ <button id="advancedOpen" class="btn" type="button">高级</button>
425
624
  </div>
426
625
  </header>
427
626
 
428
- <main class="grid">
429
- <section class="panel" aria-label="对话">
627
+ <div id="envBar" class="env-bar" hidden>
628
+ <span class="env-title">需要处理</span>
629
+ <div id="envItems" class="env-items"></div>
630
+ <button id="envWizard" class="btn tiny" type="button">去配置</button>
631
+ </div>
632
+
633
+ <main class="stage">
634
+ <section class="panel chat" aria-label="对话">
430
635
  <div class="chat-head">
431
636
  <div>
432
- <h1>对话</h1>
433
- <p>真实 Host Session · <strong>这是对话会话,不是 run 指挥台</strong></p>
637
+ <h1>Superagent</h1>
638
+ <p>说一句就行 · 自动拆成任务线并行推进 · 跑完在这一条对话里汇总</p>
434
639
  </div>
435
640
  <div id="typing" class="typing" hidden><span></span><span></span><span></span><em id="typingText" style="font-style:normal;margin-left:3px">运行中</em></div>
436
641
  </div>
437
642
  <div id="messages" class="messages" aria-live="polite"></div>
438
643
  <form id="composer" class="composer" autocomplete="off">
439
644
  <div class="composer-box">
440
- <textarea id="input" rows="1" placeholder="和 Superagent 说话,例如:先查清登录失败的根因,再把它拆成 run 修掉" disabled></textarea>
645
+ <textarea id="input" rows="1" placeholder="直接说你想让它做什么…" disabled></textarea>
441
646
  <div class="composer-bar">
442
- <div class="segmented" role="group" aria-label="发送方式">
443
- <button type="button" data-mode="queue" class="active">排队</button>
444
- <button type="button" data-mode="steer">插话</button>
445
- </div>
446
647
  <span class="hint">Enter 发送 · Shift+Enter 换行</span>
447
648
  <button id="send" class="send" type="submit" aria-label="发送" disabled>↑</button>
448
649
  </div>
449
650
  </div>
450
651
  </form>
451
652
  </section>
452
-
453
- <aside class="panel" aria-label="派生的 runs">
454
- <div class="runs-head">
455
- <div><h2>派生的 runs</h2><p>这个对话启动的子任务</p></div>
456
- <span id="runCount" class="count">0</span>
457
- </div>
458
- <details id="toolsPanel" class="tools-panel" open>
459
- <summary><span>这个会话挂载的工具</span><span id="toolCount" class="count">—</span></summary>
460
- <p id="toolNote" class="tools-note">加载中…</p>
461
- <div id="toolList" class="tool-list"></div>
462
- </details>
463
- <div id="runs" class="run-list"></div>
464
- </aside>
465
653
  </main>
466
654
  </div>
467
655
 
656
+ <div id="scrim" class="scrim" hidden></div>
657
+
658
+ <aside id="historyDrawer" class="drawer" hidden aria-label="历史">
659
+ <div class="drawer-head">
660
+ <div>
661
+ <span class="kicker">历史</span>
662
+ <h2>这次对话的时间线</h2>
663
+ </div>
664
+ <button class="drawer-close" data-close="history" type="button" aria-label="关闭">×</button>
665
+ </div>
666
+ <div id="historyList" class="drawer-body"></div>
667
+ </aside>
668
+
669
+ <aside id="advancedDrawer" class="drawer" hidden aria-label="高级">
670
+ <div class="drawer-head">
671
+ <div>
672
+ <span class="kicker">高级</span>
673
+ <h2>运行细节</h2>
674
+ </div>
675
+ <button class="drawer-close" data-close="advanced" type="button" aria-label="关闭">×</button>
676
+ </div>
677
+ <div class="drawer-body">
678
+ <section class="adv-sec">
679
+ <h3>会话</h3>
680
+ <div id="advSession" class="adv-kv"></div>
681
+ <div class="adv-actions">
682
+ <button id="newChat" class="btn tiny" type="button" disabled>开始新对话</button>
683
+ <button id="wizardOpen" class="btn tiny" type="button">首次使用向导</button>
684
+ </div>
685
+ </section>
686
+ <section class="adv-sec">
687
+ <h3>发送方式</h3>
688
+ <div class="segmented" role="group" aria-label="发送方式">
689
+ <button type="button" data-mode="queue" class="active">排队</button>
690
+ <button type="button" data-mode="steer">插话</button>
691
+ </div>
692
+ <p class="adv-note">排队:等这一轮结束后再发。插话:立刻打断这一轮。</p>
693
+ </section>
694
+ <section class="adv-sec">
695
+ <h3>挂载的工具 <span id="toolCount" class="count">—</span></h3>
696
+ <p id="toolNote" class="tools-note">加载中…</p>
697
+ <div id="toolList" class="tool-list"></div>
698
+ </section>
699
+ <section class="adv-sec">
700
+ <h3>任务线细节</h3>
701
+ <div id="advRuns" class="adv-runs"></div>
702
+ </section>
703
+ </div>
704
+ </aside>
705
+
468
706
  <div id="gate" class="gate" hidden>
469
707
  <form id="gateForm" class="gate-card">
470
708
  <div class="mark">S</div>
@@ -479,6 +717,19 @@
479
717
 
480
718
  <div id="toasts" class="toasts" aria-live="polite"></div>
481
719
 
720
+ <dialog id="wizardDialog">
721
+ <div class="wiz-head">
722
+ <div>
723
+ <span class="kicker">首次使用向导</span>
724
+ <h2>用鼠标完成配置,并当场试跑</h2>
725
+ </div>
726
+ <button id="wizardClose" type="button" aria-label="关闭">×</button>
727
+ </div>
728
+ <div id="wizardSteps" class="wiz-steps"></div>
729
+ <div id="wizardBody" class="wiz-body"></div>
730
+ <div id="wizardFoot" class="wiz-foot"></div>
731
+ </dialog>
732
+
482
733
  <dialog id="reportDialog">
483
734
  <div class="dialog-head">
484
735
  <h2 id="dialogTitle">报告</h2>
@@ -497,7 +748,6 @@
497
748
  const TOKEN_KEY = 'dsh-superagent-console-token'
498
749
  const $ = id => document.getElementById(id)
499
750
  const messagesEl = $('messages')
500
- const runsEl = $('runs')
501
751
  const inputEl = $('input')
502
752
  const sendEl = $('send')
503
753
  const composerEl = $('composer')
@@ -509,7 +759,6 @@
509
759
  const connEl = $('conn')
510
760
  const connTextEl = $('connText')
511
761
  const newChatEl = $('newChat')
512
- const runCountEl = $('runCount')
513
762
  const gateEl = $('gate')
514
763
  const gateFormEl = $('gateForm')
515
764
  const gateErrorEl = $('gateError')
@@ -519,6 +768,18 @@
519
768
  const dialogTitleEl = $('dialogTitle')
520
769
  const dialogMetaEl = $('dialogMeta')
521
770
  const dialogReportEl = $('dialogReport')
771
+ const wizardDialogEl = $('wizardDialog')
772
+ const wizardStepsEl = $('wizardSteps')
773
+ const wizardBodyEl = $('wizardBody')
774
+ const wizardFootEl = $('wizardFoot')
775
+ const envBarEl = $('envBar')
776
+ const envItemsEl = $('envItems')
777
+ const scrimEl = $('scrim')
778
+ const historyDrawerEl = $('historyDrawer')
779
+ const historyListEl = $('historyList')
780
+ const advancedDrawerEl = $('advancedDrawer')
781
+ const advSessionEl = $('advSession')
782
+ const advRunsEl = $('advRuns')
522
783
 
523
784
  const STATE = {
524
785
  token: '',
@@ -541,6 +802,26 @@
541
802
  busyAnswers: new Set(),
542
803
  autoScroll: true,
543
804
  booted: false,
805
+ preset: null,
806
+ laneEls: new Map(),
807
+ runAnchors: new Map(),
808
+ attentionSeen: new Set(),
809
+ approvals: new Map(),
810
+ }
811
+
812
+ const WIZ = {
813
+ status: null,
814
+ step: 1,
815
+ open: false,
816
+ busy: null,
817
+ statusPending: 0,
818
+ form: { provider: '', baseURL: '', model: '', apiKey: '' },
819
+ formTouched: false,
820
+ preview: null,
821
+ saved: null,
822
+ trial: null,
823
+ error: null,
824
+ autoOpened: false,
544
825
  }
545
826
 
546
827
  function el(tag, className, text) {
@@ -624,7 +905,7 @@
624
905
  STATE.capabilities = capabilities || STATE.capabilities
625
906
  const chat = mode === 'chat'
626
907
  modeBadgeEl.className = `badge ${chat ? 'chat' : 'off'}`
627
- modeTextEl.textContent = chat ? '对话会话' : mode === 'loading' ? '连接中' : '未连接'
908
+ modeTextEl.textContent = chat ? '已就绪' : mode === 'loading' ? '连接中' : '未连接'
628
909
  newChatEl.disabled = !chat
629
910
  inputEl.disabled = !chat
630
911
  updateSend()
@@ -773,7 +1054,11 @@
773
1054
  tools: [],
774
1055
  }
775
1056
  STATE.messages.push(message)
776
- messagesEl.append(messageElement(message))
1057
+ const node = messageElement(message)
1058
+ // A task lane with no user message sits at the end; keep new turns above it.
1059
+ const orphan = STATE.laneEls.get('')
1060
+ if (orphan && orphan.parentNode === messagesEl) messagesEl.insertBefore(node, orphan)
1061
+ else messagesEl.append(node)
777
1062
  if (role === 'assistant') STATE.currentAssistant = message
778
1063
  scrollToEnd()
779
1064
  return message
@@ -783,6 +1068,7 @@
783
1068
  STATE.messages = []
784
1069
  STATE.currentAssistant = null
785
1070
  STATE.toolCalls.clear()
1071
+ resetLanes()
786
1072
  messagesEl.textContent = ''
787
1073
  }
788
1074
 
@@ -801,12 +1087,12 @@
801
1087
  }
802
1088
  wrap.append(el('div', 'orb', 'S'))
803
1089
  wrap.append(el('h1', '', '今天想推进什么?'))
804
- wrap.append(el('p', '', '这是一个真实的 Host Session,可以直接说话、追问。让它把工作拆成 run 后,右侧会实时出现子任务、成本和需要你决定的问题。'))
1090
+ wrap.append(el('p', '', '这里是 Superagent 的专属空间,和宿主的普通会话分开。直接说一句就行:它会自己判断是一步做完,还是拆成几条任务线并行推进;跑完在这一条对话里汇总,并把可以点开的产物放在这里。'))
805
1091
  const examples = el('div', 'examples')
806
1092
  const samples = [
807
- '先查清登录失败的根因,再拆成 run 修掉',
808
- '把这次重构拆成并行子任务,最后汇总',
809
- '跑一个 run 检查最近的改动有没有回归',
1093
+ '把这周的项目进度整理成一页 HTML 报告',
1094
+ '先查清登录失败的根因,再修掉',
1095
+ '把这份需求拆成并行任务,最后汇总',
810
1096
  ]
811
1097
  for (const sample of samples) {
812
1098
  const button = el('button', '', sample)
@@ -833,128 +1119,364 @@
833
1119
  inputEl.style.height = `${Math.min(180, Math.max(46, inputEl.scrollHeight))}px`
834
1120
  }
835
1121
 
836
- // ---------- rendering runs ----------
837
-
838
- function draftKey(runId, attentionId) {
839
- return `${runId}::${attentionId || 'single'}`
1122
+ // ---------- task lanes ----------
1123
+
1124
+ const TERMINAL_STATUSES = new Set(['completed', 'failed', 'cancelled', 'interrupted', 'blocked'])
1125
+
1126
+ function isTerminal(status) {
1127
+ return TERMINAL_STATUSES.has(status)
1128
+ }
1129
+
1130
+ function laneStatusText(run) {
1131
+ if (run.status === 'queued') return '排队'
1132
+ if (run.status === 'completed') return '完成'
1133
+ if (isTerminal(run.status)) return '失败'
1134
+ return '进行中'
1135
+ }
1136
+
1137
+ function formatDuration(ms) {
1138
+ if (!Number.isFinite(ms) || ms < 0) return ''
1139
+ const seconds = Math.max(1, Math.round(ms / 1000))
1140
+ if (seconds < 60) return `${seconds} 秒`
1141
+ const minutes = Math.round(seconds / 60)
1142
+ if (minutes < 60) return `${minutes} 分钟`
1143
+ return `${(minutes / 60).toFixed(1)} 小时`
1144
+ }
1145
+
1146
+ function stepLabel(subtask) {
1147
+ return subtask.title || `步骤 ${subtask.index ?? ''}`.trim()
1148
+ }
1149
+
1150
+ function currentAction(run) {
1151
+ const subtasks = Array.isArray(run.subtasks) ? run.subtasks : []
1152
+ if (run.status === 'queued') return '排队,等前一条任务线让出位置'
1153
+ if (run.status === 'planning') return '正在拆步骤'
1154
+ if (run.status === 'aggregating') return '正在汇总各步骤的结果'
1155
+ if (run.status === 'completed') return '已交付,产物见汇总'
1156
+ if (isTerminal(run.status)) return run.status === 'cancelled' ? '已取消' : '没走通,原因见汇总'
1157
+ const running = subtasks.filter(subtask => subtask.status === 'running')
1158
+ if (running.length > 1) return `同时推进 ${running.length} 个步骤`
1159
+ if (running.length === 1) return `正在做:${stepLabel(running[0])}`
1160
+ const next = subtasks.find(subtask => subtask.status !== 'completed' && subtask.status !== 'failed')
1161
+ if (next) return `准备:${stepLabel(next)}`
1162
+ return '正在推进'
1163
+ }
1164
+
1165
+ function laneSignature(run) {
1166
+ const steps = Array.isArray(run.subtasks)
1167
+ ? run.subtasks.map(subtask => `${subtask.status}:${subtask.title}`).join(',')
1168
+ : ''
1169
+ const attention = Array.isArray(run.attention)
1170
+ ? run.attention.map(item => `${item.id}:${item.question}`).join(',')
1171
+ : ''
1172
+ return [run.status, steps, attention, run.report ? run.report.length : 0, run.finishedAt || ''].join('|')
1173
+ }
1174
+
1175
+ /**
1176
+ * Files and pages a run report names. They are the only things offered as
1177
+ * "open me", and the artifact route re-checks the same report before serving
1178
+ * one, so a link can never reach a path the agent did not already report.
1179
+ */
1180
+ function artifactsOf(run) {
1181
+ const text = typeof run.report === 'string' ? run.report : ''
1182
+ if (!text) return []
1183
+ const items = []
1184
+ const seen = new Set()
1185
+ const push = value => {
1186
+ const href = value.replace(/[.,;:,。;:]+$/, '')
1187
+ if (!href || seen.has(href)) return
1188
+ seen.add(href)
1189
+ items.push({ href, runId: run.id })
1190
+ }
1191
+ for (const match of text.matchAll(/https?:\/\/[^\s"'`<>)\]}|]+/g)) push(match[0])
1192
+ for (const match of text.matchAll(/(?:[A-Za-z]:[\\/]|\.{1,2}[\\/]|~[\\/])[^\s"'`<>|]+?\.(?:html?|md|pdf|docx?|xlsx?|csv|tsv|json|ya?ml|txt|log|png|jpe?g|gif|webp|svg|zip|pptx?|py|js|mjs|css)\b/gi)) {
1193
+ push(match[0])
1194
+ }
1195
+ return items.slice(0, 12)
1196
+ }
1197
+
1198
+ function artifactElement(item) {
1199
+ const isUrl = /^https?:\/\//i.test(item.href)
1200
+ const link = el('a', 'artifact')
1201
+ link.href = isUrl
1202
+ ? item.href
1203
+ : `/api/console/artifact?path=${encodeURIComponent(item.href)}&runId=${encodeURIComponent(item.runId)}&token=${encodeURIComponent(STATE.token)}`
1204
+ link.target = '_blank'
1205
+ link.rel = 'noopener'
1206
+ link.title = item.href
1207
+ link.append(el('span', 'ak', isUrl ? '页面' : '文件'))
1208
+ link.append(el('span', 'an', item.href.replace(/[\\/]+$/, '').split(/[\\/]/).pop() || item.href))
1209
+ return link
1210
+ }
1211
+
1212
+ function resetLanes() {
1213
+ STATE.laneEls.clear()
1214
+ STATE.runAnchors.clear()
1215
+ STATE.attentionSeen.clear()
1216
+ }
1217
+
1218
+ function anchorForRun(run) {
1219
+ const at = Date.parse(run.createdAt || '')
1220
+ const limit = Number.isFinite(at) ? at : Date.now()
1221
+ for (let i = STATE.messages.length - 1; i >= 0; i -= 1) {
1222
+ const message = STATE.messages[i]
1223
+ if (message.role === 'user' && message.at <= limit + 2000) return message.id
1224
+ }
1225
+ return ''
840
1226
  }
841
1227
 
842
- function renderRuns() {
1228
+ function renderLanes() {
843
1229
  const active = document.activeElement
844
1230
  const activeKey = active && active.dataset ? active.dataset.draftKey : null
845
- const activeValue = activeKey ? active.value : null
846
- const activeStart = activeKey && typeof active.selectionStart === 'number' ? active.selectionStart : null
847
-
848
- runsEl.textContent = ''
849
- runCountEl.textContent = String(STATE.runs.length)
850
- if (STATE.runs.length === 0) {
851
- const empty = el('div', 'run-empty')
852
- empty.append(el('div', '', '还没有 run。'))
853
- empty.append(el('span', 'line'))
854
- empty.append(el('div', '', '让它把工作拆出去,例如:帮我把登录失败的根因查清楚并修复。'))
855
- runsEl.append(empty)
856
- return
857
- }
858
-
1231
+ const groups = new Map()
859
1232
  for (const run of STATE.runs) {
860
- runsEl.append(runElement(run))
1233
+ let key = STATE.runAnchors.get(run.id)
1234
+ if (key === undefined) {
1235
+ key = anchorForRun(run)
1236
+ STATE.runAnchors.set(run.id, key)
1237
+ }
1238
+ if (!groups.has(key)) groups.set(key, [])
1239
+ groups.get(key).push(run)
861
1240
  }
862
-
1241
+ for (const [key, runs] of groups) {
1242
+ const anchor = key ? STATE.messages.find(message => message.id === key) : null
1243
+ let node = STATE.laneEls.get(key)
1244
+ if (!node) {
1245
+ node = el('div', 'lane-group')
1246
+ STATE.laneEls.set(key, node)
1247
+ if (anchor && anchor.el && anchor.el.parentNode === messagesEl) {
1248
+ anchor.el.after(node)
1249
+ } else {
1250
+ removeEmpty()
1251
+ messagesEl.append(node)
1252
+ }
1253
+ }
1254
+ const signature = runs.map(run => `${run.id}:${laneSignature(run)}`).join('#')
1255
+ if (node.dataset.sig === signature) continue
1256
+ node.dataset.sig = signature
1257
+ node.replaceChildren()
1258
+ const done = runs.every(run => isTerminal(run.status))
1259
+ const head = el('div', `lane-group-head${done ? ' done' : ''}`)
1260
+ head.append(el('span', 'dot'))
1261
+ head.append(el('span', '', done ? `这一轮完成 · ${runs.length} 条任务线` : `推进中 · ${runs.length} 条任务线`))
1262
+ node.append(head)
1263
+ for (const run of runs) node.append(laneElement(run))
1264
+ if (done) node.append(summaryElement(runs))
1265
+ }
1266
+ const openAttention = STATE.runs.flatMap(run => (Array.isArray(run.attention) ? run.attention : [])
1267
+ .map(item => ({ run, item, key: `${run.id}:${item.id}` })))
1268
+ const fresh = openAttention.filter(entry => !STATE.attentionSeen.has(entry.key))
1269
+ for (const entry of openAttention) STATE.attentionSeen.add(entry.key)
1270
+ if (fresh.length > 0) {
1271
+ STATE.autoScroll = true
1272
+ pushToast('有一条任务线在等你决定。')
1273
+ const card = messagesEl.querySelector('.attention-card')
1274
+ if (card) card.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
1275
+ }
1276
+ scrollToEnd()
863
1277
  if (activeKey) {
864
- const next = runsEl.querySelector(`[data-draft-key="${cssEscape(activeKey)}"]`)
1278
+ const next = document.querySelector(`[data-draft-key="${cssEscape(activeKey)}"]`)
865
1279
  if (next) {
866
1280
  next.focus()
867
- if (activeValue !== null) next.value = activeValue
868
- if (activeStart !== null) {
869
- try { next.setSelectionRange(activeStart, activeStart) } catch {}
1281
+ try { next.setSelectionRange(next.value.length, next.value.length) } catch {}
1282
+ }
1283
+ }
1284
+ renderAdvancedRuns()
1285
+ renderHistory()
1286
+ }
1287
+
1288
+ function renderHistory() {
1289
+ if (historyDrawerEl.hidden) return
1290
+ historyListEl.replaceChildren()
1291
+ const entries = []
1292
+ for (const message of STATE.messages) {
1293
+ if (message.role !== 'user') continue
1294
+ entries.push({
1295
+ message,
1296
+ runs: STATE.runs.filter(run => STATE.runAnchors.get(run.id) === message.id),
1297
+ })
1298
+ }
1299
+ if (entries.length === 0) {
1300
+ historyListEl.append(el('p', 'adv-note', '还没有下达过任务。'))
1301
+ return
1302
+ }
1303
+ for (const entry of entries.reverse()) {
1304
+ const item = el('div', 'hist-item')
1305
+ const top = el('div', 'hist-top')
1306
+ top.append(el('span', '', timeLabel(entry.message.at)))
1307
+ if (entry.runs.length > 0) {
1308
+ const done = entry.runs.filter(run => run.status === 'completed').length
1309
+ top.append(el('span', 'hist-state', `${done}/${entry.runs.length} 条任务线完成`))
1310
+ }
1311
+ item.append(top)
1312
+ item.append(el('div', 'hist-text', entry.message.text))
1313
+ const artifacts = []
1314
+ const seen = new Set()
1315
+ for (const run of entry.runs) {
1316
+ for (const artifact of artifactsOf(run)) {
1317
+ if (seen.has(artifact.href)) continue
1318
+ seen.add(artifact.href)
1319
+ artifacts.push(artifact)
870
1320
  }
871
1321
  }
1322
+ if (artifacts.length > 0) {
1323
+ const chips = el('div', 'artifacts')
1324
+ for (const artifact of artifacts) chips.append(artifactElement(artifact))
1325
+ item.append(chips)
1326
+ }
1327
+ item.addEventListener('click', event => {
1328
+ if (event.target.closest('a')) return
1329
+ drawerClose()
1330
+ entry.message.el?.scrollIntoView({ block: 'center', behavior: 'smooth' })
1331
+ entry.message.el?.classList.add('flash')
1332
+ setTimeout(() => entry.message.el?.classList.remove('flash'), 1200)
1333
+ })
1334
+ historyListEl.append(item)
872
1335
  }
873
1336
  }
874
1337
 
1338
+ function advRow(label, value) {
1339
+ const row = el('div', 'adv-row')
1340
+ row.append(el('span', 'adv-label', label))
1341
+ row.append(el('code', '', value))
1342
+ return row
1343
+ }
1344
+
1345
+ function renderAdvancedRuns() {
1346
+ if (advancedDrawerEl.hidden) return
1347
+ advSessionEl.replaceChildren()
1348
+ advSessionEl.append(advRow('会话', STATE.sessionId ? shortId(STATE.sessionId) : '未建立'))
1349
+ advSessionEl.append(advRow('预置', STATE.preset || '默认'))
1350
+ advRunsEl.replaceChildren()
1351
+ if (STATE.runs.length === 0) {
1352
+ advRunsEl.append(el('p', 'adv-note', '还没有任务线。'))
1353
+ return
1354
+ }
1355
+ for (const run of STATE.runs) {
1356
+ const row = el('div', 'adv-run')
1357
+ row.append(el('div', 't', run.goal || '任务线'))
1358
+ row.append(el('div', 'm', run.id))
1359
+ row.append(el('div', 'm', [
1360
+ statusText(run.status),
1361
+ run.usage ? `${formatTokens(run.usage.totalTokens)} tokens` : null,
1362
+ run.cost?.text ?? null,
1363
+ `${Array.isArray(run.subtasks) ? run.subtasks.length : 0} 个步骤`,
1364
+ ].filter(Boolean).join(' · ')))
1365
+ const view = el('button', 'btn tiny', '查看完整报告')
1366
+ view.type = 'button'
1367
+ view.addEventListener('click', () => openReport(run.id))
1368
+ row.append(view)
1369
+ advRunsEl.append(row)
1370
+ }
1371
+ }
1372
+
1373
+
875
1374
  function cssEscape(value) {
876
1375
  if (window.CSS && typeof window.CSS.escape === 'function') return window.CSS.escape(value)
877
1376
  return String(value).replace(/["\\]/g, '\\$&')
878
1377
  }
879
1378
 
880
- function runElement(run) {
881
- const card = el('article', `run ${statusClass(run.status)}`)
1379
+ function laneElement(run) {
1380
+ const card = el('div', `lane ${statusClass(run.status)}`)
882
1381
  card.dataset.runId = run.id
883
1382
 
884
- const top = el('div', 'run-top')
885
- const title = el('div', 'run-title')
886
- title.append(el('h3', '', run.goal || '(no goal)'))
887
- title.append(el('p', '', `${shortId(run.id)} · ${timeLabel(run.createdAt)}`))
888
- top.append(title)
889
- top.append(el('span', `status-pill ${statusClass(run.status)}`, statusText(run.status)))
890
- card.append(top)
891
-
892
- const meta = el('div', 'run-meta')
893
- if (run.cost) {
894
- const cost = el('span')
895
- cost.append(el('b', '', run.cost.text || '—'))
896
- cost.append(document.createTextNode(` 成本${run.cost.complete ? '' : '(部分未定价)'}`))
897
- meta.append(cost)
898
- }
899
- if (run.usage) {
900
- const usage = el('span')
901
- usage.append(el('b', '', formatTokens(run.usage.totalTokens)))
902
- usage.append(document.createTextNode(' tokens'))
903
- meta.append(usage)
904
- }
905
- const total = Array.isArray(run.subtasks) ? run.subtasks.length : 0
906
- const done = Array.isArray(run.subtasks) ? run.subtasks.filter(s => s.status === 'completed').length : 0
907
- if (total > 0) {
908
- const progress = el('span')
909
- progress.append(el('b', '', `${done}/${total}`))
910
- progress.append(document.createTextNode(' 子任务'))
911
- meta.append(progress)
912
- }
913
- card.append(meta)
914
-
915
- if (total > 0) {
1383
+ const head = el('div', 'lane-head')
1384
+ const title = el('div', 'lane-title')
1385
+ title.append(el('div', 'lane-goal', run.goal || '这条任务线'))
1386
+ const action = currentAction(run)
1387
+ if (action) {
1388
+ const line = el('div', 'lane-now')
1389
+ if (!isTerminal(run.status)) line.append(el('span', 'spark'))
1390
+ line.append(el('span', '', action))
1391
+ title.append(line)
1392
+ }
1393
+ head.append(title)
1394
+ head.append(el('span', `status-pill ${statusClass(run.status)}`, laneStatusText(run)))
1395
+ card.append(head)
1396
+
1397
+ const subtasks = Array.isArray(run.subtasks) ? run.subtasks : []
1398
+ if (subtasks.length > 0) {
1399
+ const steps = el('div', 'steps')
1400
+ for (const subtask of subtasks.slice(0, 8)) {
1401
+ const row = el('div', `step ${subtask.status || ''}`.trim())
1402
+ row.append(el('span', 'sdot'))
1403
+ row.append(el('span', '', stepLabel(subtask)))
1404
+ steps.append(row)
1405
+ }
1406
+ if (subtasks.length > 8) {
1407
+ const row = el('div', 'step')
1408
+ row.append(el('span', 'sdot'))
1409
+ row.append(el('span', '', `还有 ${subtasks.length - 8} 个步骤`))
1410
+ steps.append(row)
1411
+ }
1412
+ card.append(steps)
1413
+
1414
+ const done = subtasks.filter(subtask => subtask.status === 'completed').length
916
1415
  const bar = el('div', 'progress')
917
1416
  const fill = el('i')
918
- fill.style.width = `${Math.round((done / total) * 100)}%`
1417
+ fill.style.width = `${Math.round((done / subtasks.length) * 100)}%`
919
1418
  bar.append(fill)
920
1419
  card.append(bar)
1420
+ card.append(el('div', 'lane-progress-text', `${done}/${subtasks.length} 步骤完成`))
1421
+ }
921
1422
 
922
- const subtasks = el('div', 'subtasks')
923
- for (const subtask of run.subtasks.slice(0, 8)) {
924
- const chip = el('span', `subtask ${subtask.status || ''}`.trim(), subtask.title || `subtask ${subtask.index ?? ''}`)
925
- chip.title = `${subtask.status || 'unknown'}${subtask.childId ? ` · ${subtask.childId}` : ''}`
926
- subtasks.append(chip)
927
- }
928
- if (total > 8) subtasks.append(el('span', 'subtask', `+${total - 8}`))
929
- card.append(subtasks)
1423
+ if (Array.isArray(run.attention)) {
1424
+ for (const item of run.attention) card.append(attentionElement(run, item))
930
1425
  }
931
1426
 
932
- if (Array.isArray(run.attention) && run.attention.length > 0) {
933
- for (const item of run.attention) {
934
- card.append(attentionElement(run, item))
1427
+ return card
1428
+ }
1429
+
1430
+ function summaryElement(runs) {
1431
+ const failed = runs.filter(run => isTerminal(run.status) && run.status !== 'completed')
1432
+ const box = el('div', `summary${failed.length > 0 ? ' bad' : ''}`)
1433
+ box.append(el('div', 'st', failed.length > 0
1434
+ ? `完成,${failed.length} 条任务线没走通`
1435
+ : `全部完成 · ${runs.length} 条任务线`))
1436
+
1437
+ const first = runs.map(run => Date.parse(run.createdAt)).filter(Number.isFinite).sort((a, b) => a - b)[0]
1438
+ const last = runs.map(run => Date.parse(run.finishedAt)).filter(Number.isFinite).sort((a, b) => b - a)[0]
1439
+ const facts = []
1440
+ if (Number.isFinite(first) && Number.isFinite(last)) facts.push(`用时 ${formatDuration(last - first)}`)
1441
+ if (failed.length > 0) facts.push(failed.map(run => run.goal || '一条任务线').join('、'))
1442
+ if (facts.length > 0) box.append(el('div', 'sd', facts.join(' · ')))
1443
+
1444
+ const artifacts = []
1445
+ const seen = new Set()
1446
+ for (const run of runs) {
1447
+ for (const item of artifactsOf(run)) {
1448
+ if (seen.has(item.href)) continue
1449
+ seen.add(item.href)
1450
+ artifacts.push(item)
935
1451
  }
936
1452
  }
937
-
938
- if (run.report) {
939
- const details = el('details', 'report')
940
- details.append(el('summary', '', `报告 · ${run.reportTruncated ? '前段预览' : '完整'}`))
941
- details.append(el('pre', '', run.report))
942
- card.append(details)
1453
+ if (artifacts.length > 0) {
1454
+ const list = el('div', 'artifacts')
1455
+ for (const item of artifacts) list.append(artifactElement(item))
1456
+ box.append(list)
1457
+ } else {
1458
+ box.append(el('div', 'sd', '这次没有可以点开的产物;完整汇总在下面。'))
943
1459
  }
944
1460
 
945
- const actions = el('div', 'run-actions')
946
- const reportButton = el('button', '', '查看完整报告')
947
- reportButton.type = 'button'
948
- reportButton.addEventListener('click', () => openReport(run.id))
949
- actions.append(reportButton)
950
- card.append(actions)
1461
+ const details = el('details', 'report')
1462
+ details.append(el('summary', '', '汇总'))
1463
+ for (const run of runs) {
1464
+ const block = el('div', 'sum-run')
1465
+ block.append(el('div', 'sum-run-title', `${run.goal || '任务线'} · ${laneStatusText(run)}`))
1466
+ block.append(el('pre', '', run.report || '(这条任务线没有返回报告)'))
1467
+ details.append(block)
1468
+ }
1469
+ box.append(details)
1470
+ return box
1471
+ }
951
1472
 
952
- return card
1473
+ function draftKey(runId, attentionId) {
1474
+ return `${runId}::${attentionId || 'single'}`
953
1475
  }
954
1476
 
955
1477
  function attentionElement(run, item) {
956
1478
  const card = el('div', 'attention-card')
957
- card.append(el('div', 'kicker', `需要你决定${item.id ? ` · ${item.id}` : ''}`))
1479
+ card.append(el('div', 'kicker', '需要你决定'))
958
1480
  card.append(el('p', '', item.question || '运行中的任务在等一个决定'))
959
1481
  if (item.reason) card.append(el('p', 'reason', item.reason))
960
1482
 
@@ -1004,19 +1526,139 @@
1004
1526
  async function submitAnswer(runId, attentionId, answer, key) {
1005
1527
  if (STATE.busyAnswers.has(key)) return
1006
1528
  STATE.busyAnswers.add(key)
1007
- renderRuns()
1529
+ renderLanes()
1008
1530
  try {
1009
1531
  await api('/api/console/answer', {
1010
1532
  method: 'POST',
1011
1533
  body: { sessionId: STATE.sessionId, runId, attentionId, answer },
1012
1534
  })
1013
1535
  STATE.drafts.delete(key)
1014
- pushToast('决定已提交,run 会在下一个边界应用。', 'ok')
1536
+ pushToast('决定已提交,任务线会在下一个边界应用。', 'ok')
1015
1537
  } catch (error) {
1016
1538
  pushToast(`提交失败:${messageOf(error)}`, 'err')
1017
1539
  } finally {
1018
1540
  STATE.busyAnswers.delete(key)
1019
- renderRuns()
1541
+ renderLanes()
1542
+ }
1543
+ }
1544
+
1545
+ // ---------- approvals ----------
1546
+
1547
+ /** Best-effort target of the blocked call, so the person sees what would change. */
1548
+ function approvalTarget(approval) {
1549
+ const candidates = [approval.callArguments]
1550
+ const call = approval.callId ? STATE.toolCalls.get(approval.callId) : null
1551
+ if (call && call.arguments) candidates.push(call.arguments)
1552
+ for (const raw of candidates) {
1553
+ if (typeof raw !== 'string' || !raw.trim()) continue
1554
+ try {
1555
+ const args = JSON.parse(raw)
1556
+ const target = args?.path ?? args?.file_path ?? args?.filePath ?? args?.target ?? args?.cwd
1557
+ if (typeof target === 'string' && target.trim()) return target.trim()
1558
+ } catch {
1559
+ // Streamed arguments arrive in pieces; fall back to the asker's wording.
1560
+ }
1561
+ }
1562
+ const match = `${approval.reason || ''}`.match(/[A-Za-z]:[\\/][^\s'",。)]+|\/(?:[^\s'",。)/]+\/)*[^\s'",。)/]+/)
1563
+ return match ? match[0] : ''
1564
+ }
1565
+
1566
+ /** Name the task line that asked, using the lanes the page already shows. */
1567
+ function approvalSource(approval) {
1568
+ const agentId = approval.agentId
1569
+ if (agentId) {
1570
+ for (const run of STATE.runs || []) {
1571
+ const lanes = Array.isArray(run.subtasks) ? run.subtasks : []
1572
+ const hit = lanes.find(item => item && item.childId === agentId)
1573
+ if (hit) return `${run.goal || '任务线'} · ${hit.title || '子任务'}`
1574
+ }
1575
+ }
1576
+ return approval.source || '这条对话'
1577
+ }
1578
+
1579
+ function approvalCard(approval) {
1580
+ const card = el('div', 'approval-card')
1581
+ card.dataset.approvalId = approval.id
1582
+ card.append(el('div', 'kicker', '需要你决定'))
1583
+ const what = el('div', 'what')
1584
+ what.append(el('span', '', '来源 '), el('b', '', approvalSource(approval)))
1585
+ what.append(el('span', '', ' · 工具 '), el('b', '', approval.toolName || 'tool'))
1586
+ card.append(what)
1587
+ const target = approvalTarget(approval)
1588
+ if (target) card.append(el('div', 'where', `要动的位置:${target}`))
1589
+ const reason = approval.displayReason?.zh || approval.reason
1590
+ card.append(el('p', 'why', reason || '宿主的工具调用被拦住了,需要你明确决定这一次。'))
1591
+ card.append(el('div', 'state', '等待你的决定…'))
1592
+ const options = el('div', 'options')
1593
+ const allow = el('button', 'allow', '允许这一次')
1594
+ allow.type = 'button'
1595
+ allow.addEventListener('click', () => decideApproval(approval.id, 'allow'))
1596
+ const reject = el('button', 'reject', '拒绝')
1597
+ reject.type = 'button'
1598
+ reject.addEventListener('click', () => decideApproval(approval.id, 'reject'))
1599
+ options.append(allow, reject)
1600
+ card.append(options)
1601
+ return card
1602
+ }
1603
+
1604
+ function settleApprovalNode(entry) {
1605
+ if (!entry || !entry.node) return
1606
+ entry.node.querySelector('.options')?.remove()
1607
+ const state = entry.node.querySelector('.state')
1608
+ if (!state) return
1609
+ if (entry.decided === 'allow') state.textContent = '已允许这一次(只对这一条调用生效)'
1610
+ else if (entry.decided === 'reject') state.textContent = '已拒绝'
1611
+ else if (entry.decided === 'cancelled') state.textContent = '没有回答,按拒绝处理'
1612
+ else state.textContent = '等待你的决定…'
1613
+ }
1614
+
1615
+ function seatApproval(approval) {
1616
+ if (!approval || !approval.id) return null
1617
+ const existing = STATE.approvals.get(approval.id)
1618
+ if (existing) {
1619
+ if (existing.node && existing.node.parentNode !== messagesEl) messagesEl.append(existing.node)
1620
+ return existing
1621
+ }
1622
+ removeEmpty()
1623
+ const entry = { approval, node: approvalCard(approval), decided: null }
1624
+ STATE.approvals.set(approval.id, entry)
1625
+ const orphan = STATE.laneEls.get('')
1626
+ if (orphan && orphan.parentNode === messagesEl) messagesEl.insertBefore(entry.node, orphan)
1627
+ else messagesEl.append(entry.node)
1628
+ scrollToEnd()
1629
+ return entry
1630
+ }
1631
+
1632
+ /** Re-seat approvals a snapshot cleared, without losing their decided state. */
1633
+ function renderApprovals() {
1634
+ for (const entry of STATE.approvals.values()) {
1635
+ if (!entry.node || entry.node.parentNode !== messagesEl) {
1636
+ entry.node = approvalCard(entry.approval)
1637
+ messagesEl.append(entry.node)
1638
+ }
1639
+ if (entry.decided) settleApprovalNode(entry)
1640
+ }
1641
+ if (STATE.approvals.size > 0) scrollToEnd()
1642
+ }
1643
+
1644
+ async function decideApproval(id, decision) {
1645
+ const entry = STATE.approvals.get(id)
1646
+ if (!entry || entry.decided) return
1647
+ const state = entry.node.querySelector('.state')
1648
+ for (const button of entry.node.querySelectorAll('button')) button.disabled = true
1649
+ if (state) state.textContent = decision === 'allow' ? '正在允许这一次…' : '正在拒绝…'
1650
+ try {
1651
+ await api('/api/console/approval', { method: 'POST', body: { id, decision } })
1652
+ entry.decided = decision
1653
+ settleApprovalNode(entry)
1654
+ pushToast(
1655
+ decision === 'allow' ? '已允许这一次;只对这一条调用生效。' : '已拒绝这一条调用。',
1656
+ 'ok',
1657
+ )
1658
+ } catch (error) {
1659
+ for (const button of entry.node.querySelectorAll('button')) button.disabled = false
1660
+ if (state) state.textContent = `没有提交成功:${messageOf(error)}`
1661
+ pushToast(`审批没有提交成功:${messageOf(error)}`, 'err')
1020
1662
  }
1021
1663
  }
1022
1664
 
@@ -1052,6 +1694,7 @@
1052
1694
  case 'session':
1053
1695
  if (frame.sessionId && frame.sessionId !== STATE.sessionId) {
1054
1696
  setSession(frame.sessionId)
1697
+ STATE.approvals.clear()
1055
1698
  clearMessages()
1056
1699
  renderEmpty()
1057
1700
  }
@@ -1064,6 +1707,7 @@
1064
1707
  }
1065
1708
  removeEmpty()
1066
1709
  if (STATE.messages.length === 0) renderEmpty()
1710
+ renderApprovals()
1067
1711
  scrollToEnd()
1068
1712
  break
1069
1713
  case 'session.event':
@@ -1086,9 +1730,25 @@
1086
1730
  }
1087
1731
  }
1088
1732
  break
1733
+ case 'approval': {
1734
+ const approval = frame.approval
1735
+ if (frame.action === 'asked' && approval && approval.id) {
1736
+ seatApproval(approval)
1737
+ pushToast('有一个工具调用在等你决定。', 'warn')
1738
+ } else if ((frame.action === 'decided' || frame.action === 'expired') && frame.id) {
1739
+ const entry = STATE.approvals.get(frame.id)
1740
+ if (entry) {
1741
+ entry.decided = frame.action === 'expired'
1742
+ ? 'cancelled'
1743
+ : frame.outcome === 'allowed-once' ? 'allow' : frame.outcome === 'rejected' ? 'reject' : 'cancelled'
1744
+ settleApprovalNode(entry)
1745
+ }
1746
+ }
1747
+ break
1748
+ }
1089
1749
  case 'runs':
1090
1750
  STATE.runs = Array.isArray(frame.runs) ? frame.runs : []
1091
- renderRuns()
1751
+ renderLanes()
1092
1752
  break
1093
1753
  case 'answered':
1094
1754
  pushToast(`已提交 ${frame.attentionId || '决定'}。`, 'ok')
@@ -1316,10 +1976,13 @@
1316
1976
  STATE.booted = true
1317
1977
  setMode(data.mode === 'chat' ? 'chat' : 'unavailable', data.capabilities)
1318
1978
  if (data.sessionId) setSession(data.sessionId)
1979
+ if (data.preset) STATE.preset = data.preset
1319
1980
  STATE.runs = Array.isArray(data.runs) ? data.runs : []
1320
- renderRuns()
1981
+ renderLanes()
1982
+ for (const approval of Array.isArray(data.approvals) ? data.approvals : []) seatApproval(approval)
1321
1983
  if (STATE.messages.length === 0) renderEmpty()
1322
1984
  loadTools()
1985
+ wizardLoad({ probe: false, auto: true })
1323
1986
  }
1324
1987
 
1325
1988
  const toolCountEl = $('toolCount')
@@ -1373,6 +2036,546 @@
1373
2036
  }
1374
2037
  }
1375
2038
 
2039
+ // ---------- first-use wizard ----------
2040
+
2041
+ const WIZ_STEP_LABELS = ['环境自检', 'key 与模型', '确认写入', '试跑示例']
2042
+
2043
+ function wizardBusyNode(text) {
2044
+ const row = el('div', 'wiz-busy')
2045
+ row.append(el('span', 'spin'))
2046
+ row.append(el('span', '', text))
2047
+ return row
2048
+ }
2049
+
2050
+ function wizardErrorNode() {
2051
+ if (!WIZ.error) return null
2052
+ const box = el('div', 'wiz-error')
2053
+ box.append(el('b', '', WIZ.error.message))
2054
+ if (WIZ.error.hint) box.append(el('div', '', WIZ.error.hint))
2055
+ return box
2056
+ }
2057
+
2058
+ function updateEnvBar(status) {
2059
+ const items = Array.isArray(status?.environment) ? status.environment : []
2060
+ const broken = items.filter(item => !item.ok)
2061
+ if (!status || broken.length === 0) {
2062
+ envBarEl.hidden = true
2063
+ envItemsEl.replaceChildren()
2064
+ return
2065
+ }
2066
+ envBarEl.hidden = false
2067
+ envItemsEl.replaceChildren()
2068
+ for (const item of broken) {
2069
+ const chip = el('button', `env-item ${item.ok ? 'ok' : 'bad'}`)
2070
+ chip.type = 'button'
2071
+ chip.title = item.hint || item.value || ''
2072
+ chip.append(el('span', 'dot'))
2073
+ chip.append(el('span', '', item.label))
2074
+ chip.append(el('span', 'env-value', item.value || ''))
2075
+ chip.append(el('span', 'env-action', '点这里处理'))
2076
+ chip.addEventListener('click', () => wizardOpen(item.action?.step || 1))
2077
+ envItemsEl.append(chip)
2078
+ }
2079
+ }
2080
+
2081
+ async function wizardLoad({ probe = false, auto = false } = {}) {
2082
+ if (!STATE.token) return
2083
+ // Status loads overlap (bootstrap, auto-open, retry); a counter keeps one
2084
+ // finishing load from clearing another's state or leaving a stale busy flag.
2085
+ WIZ.statusPending += 1
2086
+ if (WIZ.open) renderWizard()
2087
+ try {
2088
+ const data = await api(`/api/console/wizard/status?probe=${probe ? 1 : 0}`)
2089
+ WIZ.status = data
2090
+ if (!WIZ.formTouched) {
2091
+ WIZ.form.provider = data.provider || data.defaults.provider
2092
+ WIZ.form.baseURL = data.baseURL || data.defaults.baseURL
2093
+ WIZ.form.model = data.model || data.defaults.model
2094
+ }
2095
+ WIZ.error = null
2096
+ updateEnvBar(data)
2097
+ if (auto && data.needsSetup && !WIZ.autoOpened) {
2098
+ WIZ.autoOpened = true
2099
+ wizardOpen(1)
2100
+ }
2101
+ } catch (error) {
2102
+ if (error.status === 401) return
2103
+ if (WIZ.open) {
2104
+ WIZ.error = { message: messageOf(error), hint: error.hint, code: error.code }
2105
+ }
2106
+ } finally {
2107
+ WIZ.statusPending = Math.max(0, WIZ.statusPending - 1)
2108
+ if (WIZ.open) renderWizard()
2109
+ }
2110
+ }
2111
+
2112
+ function wizardOpen(step) {
2113
+ WIZ.open = true
2114
+ if (!wizardDialogEl.open) {
2115
+ if (typeof wizardDialogEl.showModal === 'function') wizardDialogEl.showModal()
2116
+ else wizardDialogEl.setAttribute('open', '')
2117
+ }
2118
+ if (step) WIZ.step = step
2119
+ WIZ.error = null
2120
+ renderWizard()
2121
+ if (!WIZ.status) wizardLoad({ probe: true })
2122
+ else if (WIZ.step === 1) wizardLoad({ probe: false })
2123
+ }
2124
+
2125
+ function wizardClose() {
2126
+ WIZ.open = false
2127
+ if (wizardDialogEl.open) wizardDialogEl.close()
2128
+ }
2129
+
2130
+ function wizardGo(step) {
2131
+ if (step === 3 && !WIZ.preview) return
2132
+ if (step === 4 && !WIZ.saved) return
2133
+ WIZ.step = step
2134
+ WIZ.error = null
2135
+ renderWizard()
2136
+ }
2137
+
2138
+ function wizardHandleAction(action) {
2139
+ if (!action) return
2140
+ if (action.kind === 'retry') {
2141
+ wizardLoad({ probe: true })
2142
+ return
2143
+ }
2144
+ if (action.kind === 'reload') {
2145
+ window.location.reload()
2146
+ return
2147
+ }
2148
+ wizardGo(action.step || 1)
2149
+ }
2150
+
2151
+ function keyBadgeState() {
2152
+ const failed = WIZ.error && ['key-rejected', 'model-missing', 'base-unreachable', 'base-timeout', 'endpoint-http', 'endpoint-invalid', 'base-tls'].includes(WIZ.error.code)
2153
+ if (failed) return { text: '未通过', kind: 'bad' }
2154
+ if (WIZ.preview?.key?.verified) return { text: '已验证', kind: 'ok' }
2155
+ if (WIZ.status?.key?.verified) return { text: '已验证', kind: 'ok' }
2156
+ if (WIZ.status?.key?.configured) return { text: '未验证', kind: 'bad' }
2157
+ if (WIZ.form.apiKey?.trim()) return { text: '未验证', kind: 'bad' }
2158
+ return { text: '未配置', kind: '' }
2159
+ }
2160
+
2161
+ function updateKeyBadge() {
2162
+ const badge = $('wizKeyBadge')
2163
+ if (!badge) return
2164
+ const state = keyBadgeState()
2165
+ badge.className = `wiz-badge ${state.kind}`.trim()
2166
+ badge.textContent = state.text
2167
+ }
2168
+
2169
+ function renderWizard() {
2170
+ if (!WIZ.open) return
2171
+ wizardStepsEl.replaceChildren()
2172
+ WIZ_STEP_LABELS.forEach((label, index) => {
2173
+ const number = index + 1
2174
+ const node = el(
2175
+ 'div',
2176
+ `wiz-step${number === WIZ.step ? ' active' : ''}${number < WIZ.step ? ' done' : ''}`,
2177
+ `${number} ${label}`,
2178
+ )
2179
+ wizardStepsEl.append(node)
2180
+ })
2181
+ wizardBodyEl.replaceChildren()
2182
+ if (WIZ.step === 1) renderWizardStep1()
2183
+ else if (WIZ.step === 2) renderWizardStep2()
2184
+ else if (WIZ.step === 3) renderWizardStep3()
2185
+ else renderWizardStep4()
2186
+ }
2187
+
2188
+ function renderWizardStep1() {
2189
+ wizardBodyEl.append(el('p', 'wiz-lead', '先看看宿主和环境是否准备好了。不通过的项可以直接点“点这里处理”,不需要读错误码。'))
2190
+ if (!WIZ.status) {
2191
+ wizardBodyEl.append(WIZ.statusPending > 0 ? wizardBusyNode('正在检查环境…') : el('p', 'wiz-note', '还没有读到检查结果。'))
2192
+ } else {
2193
+ const list = el('div', 'wiz-checks')
2194
+ for (const item of WIZ.status.environment || []) {
2195
+ const row = el('div', `wiz-check${item.ok ? '' : ' bad'}`)
2196
+ row.append(el('span', 'dot'))
2197
+ const body = el('div', 'body')
2198
+ const line = el('div', 'label', item.label)
2199
+ if (item.value) line.append(el('span', 'value', item.value))
2200
+ body.append(line)
2201
+ if (item.hint) body.append(el('div', 'hint', item.hint))
2202
+ row.append(body)
2203
+ if (!item.ok && item.action) {
2204
+ const button = el('button', '', '点这里处理')
2205
+ button.type = 'button'
2206
+ button.addEventListener('click', () => wizardHandleAction(item.action))
2207
+ row.append(button)
2208
+ }
2209
+ list.append(row)
2210
+ }
2211
+ wizardBodyEl.append(list)
2212
+ if (WIZ.status.profile?.patchPath) {
2213
+ wizardBodyEl.append(el('p', 'wiz-note', `配置文件:${WIZ.status.profile.patchPath}。写入前会自动备份,失败可以一键回滚。`))
2214
+ }
2215
+ }
2216
+ const error = wizardErrorNode()
2217
+ if (error) wizardBodyEl.append(error)
2218
+
2219
+ wizardFootEl.replaceChildren()
2220
+ const retry = el('button', 'wiz-secondary', WIZ.statusPending > 0 ? '检查中…' : '重新检查')
2221
+ retry.type = 'button'
2222
+ retry.disabled = WIZ.statusPending > 0
2223
+ retry.addEventListener('click', () => wizardLoad({ probe: true }))
2224
+ const next = el('button', 'wiz-primary', '下一步:填写 key')
2225
+ next.type = 'button'
2226
+ next.disabled = !WIZ.status
2227
+ next.addEventListener('click', () => wizardGo(2))
2228
+ wizardFootEl.append(retry, el('span', 'spacer'), next)
2229
+ }
2230
+
2231
+ function wizardField(key, label, type, placeholder, hint) {
2232
+ const wrap = el('div', 'wiz-field')
2233
+ const id = `wiz-${key}`
2234
+ const labelEl = el('label', '', label)
2235
+ labelEl.htmlFor = id
2236
+ const input = document.createElement('input')
2237
+ input.id = id
2238
+ input.type = type || 'text'
2239
+ input.value = WIZ.form[key] ?? ''
2240
+ if (placeholder) input.placeholder = placeholder
2241
+ if (type === 'password') input.autocomplete = 'off'
2242
+ input.spellcheck = false
2243
+ input.addEventListener('input', () => {
2244
+ WIZ.form[key] = input.value
2245
+ WIZ.formTouched = true
2246
+ if (key === 'apiKey') updateKeyBadge()
2247
+ })
2248
+ wrap.append(labelEl, input)
2249
+ if (hint) wrap.append(el('div', 'wiz-note', hint))
2250
+ return wrap
2251
+ }
2252
+
2253
+ function renderWizardStep2() {
2254
+ const status = WIZ.status
2255
+ wizardBodyEl.append(el('p', 'wiz-lead', '填你的 OpenAI 兼容端点。默认值已经填好,通常只需要粘贴 key。'))
2256
+ const form = el('div', 'wiz-form')
2257
+ form.append(wizardField('provider', '提供商名', 'text', 'haoduo', '小写字母、数字、短横线,会作为配置里的提供方 id。'))
2258
+ form.append(wizardField('baseURL', 'Base URL', 'text', 'https://byte.haoduotoken.com/v1', 'OpenAI 兼容端点,通常以 /v1 结尾。'))
2259
+ form.append(wizardField('model', '模型名', 'text', 'gpt-6.1-sol', '提供商控制台里的模型 id。'))
2260
+
2261
+ const keyWrap = el('div', 'wiz-field')
2262
+ const labelEl = el('label', '', 'API key')
2263
+ labelEl.htmlFor = 'wiz-apiKey'
2264
+ const row = el('div', 'wiz-key-row')
2265
+ const input = document.createElement('input')
2266
+ input.id = 'wiz-apiKey'
2267
+ input.type = 'password'
2268
+ input.autocomplete = 'off'
2269
+ input.spellcheck = false
2270
+ input.value = WIZ.form.apiKey ?? ''
2271
+ input.placeholder = status?.key?.configured
2272
+ ? `已保存 ${status.key.mask || '(内容不可回读)'},留空则沿用`
2273
+ : '粘贴你的 API key'
2274
+ input.addEventListener('input', () => {
2275
+ WIZ.form.apiKey = input.value
2276
+ WIZ.formTouched = true
2277
+ updateKeyBadge()
2278
+ })
2279
+ const badgeState = keyBadgeState()
2280
+ const badge = el('span', `wiz-badge ${badgeState.kind}`.trim(), badgeState.text)
2281
+ badge.id = 'wizKeyBadge'
2282
+ row.append(input, badge)
2283
+ keyWrap.append(labelEl, row)
2284
+ keyWrap.append(el('div', 'wiz-note', 'key 只写入宿主凭据库(或你已有的用户环境变量);不会写进仓库、配置或日志,页面不显示完整值。'))
2285
+ form.append(keyWrap)
2286
+ wizardBodyEl.append(form)
2287
+
2288
+ const error = wizardErrorNode()
2289
+ if (error) wizardBodyEl.append(error)
2290
+
2291
+ wizardFootEl.replaceChildren()
2292
+ const back = el('button', 'wiz-secondary', '上一步')
2293
+ back.type = 'button'
2294
+ back.addEventListener('click', () => wizardGo(1))
2295
+ const submit = el('button', 'wiz-primary', WIZ.busy === 'preview' ? '正在验证…' : '检查并预览')
2296
+ submit.type = 'button'
2297
+ submit.disabled = WIZ.busy === 'preview'
2298
+ submit.addEventListener('click', wizardPreview)
2299
+ wizardFootEl.append(back, el('span', 'spacer'), submit)
2300
+ }
2301
+
2302
+ async function wizardPreview() {
2303
+ if (WIZ.busy) return
2304
+ WIZ.busy = 'preview'
2305
+ WIZ.error = null
2306
+ WIZ.preview = null
2307
+ renderWizard()
2308
+ try {
2309
+ const body = {
2310
+ provider: WIZ.form.provider.trim(),
2311
+ baseURL: WIZ.form.baseURL.trim(),
2312
+ model: WIZ.form.model.trim(),
2313
+ }
2314
+ if (WIZ.form.apiKey.trim()) body.apiKey = WIZ.form.apiKey.trim()
2315
+ WIZ.preview = await api('/api/console/wizard/preview', { method: 'POST', body })
2316
+ WIZ.step = 3
2317
+ } catch (error) {
2318
+ WIZ.error = { message: messageOf(error), hint: error.hint, code: error.code }
2319
+ } finally {
2320
+ WIZ.busy = null
2321
+ renderWizard()
2322
+ }
2323
+ }
2324
+
2325
+ function renderWizardStep3() {
2326
+ const preview = WIZ.preview
2327
+ if (!preview) {
2328
+ wizardBodyEl.append(el('p', 'wiz-note', '先回到上一步做一次检查。'))
2329
+ wizardFootEl.replaceChildren()
2330
+ const back = el('button', 'wiz-secondary', '返回')
2331
+ back.type = 'button'
2332
+ back.addEventListener('click', () => wizardGo(2))
2333
+ wizardFootEl.append(back)
2334
+ return
2335
+ }
2336
+ wizardBodyEl.append(el('p', 'wiz-lead', '这是将要写入的摘要。你不需要看 YAML;写入前会自动备份,失败可以一键回滚。'))
2337
+ const list = el('ul', 'wiz-summary')
2338
+ for (const line of preview.summary || []) list.append(el('li', '', line))
2339
+ wizardBodyEl.append(list)
2340
+
2341
+ const kv = el('div', 'wiz-kv')
2342
+ const add = (label, value) => {
2343
+ const item = el('span')
2344
+ item.append(el('b', '', `${label}:`))
2345
+ item.append(document.createTextNode(value))
2346
+ kv.append(item)
2347
+ }
2348
+ add('提供方', `${preview.provider} · ${preview.baseURL}`)
2349
+ add('模型', preview.model)
2350
+ add('key', `${preview.key.mask || '沿用已保存的 key'}(引用 ${preview.key.ref})`)
2351
+ add('配置文件', preview.target.patchPath)
2352
+ add('备份', '写入前保存;可在下一步点“回滚上次写入”恢复')
2353
+ wizardBodyEl.append(kv)
2354
+
2355
+ const error = wizardErrorNode()
2356
+ if (error) wizardBodyEl.append(error)
2357
+ if (WIZ.busy === 'save') wizardBodyEl.append(wizardBusyNode('正在写入配置并保存 key…'))
2358
+ wizardBodyEl.append(el('p', 'wiz-note', preview.note || ''))
2359
+
2360
+ wizardFootEl.replaceChildren()
2361
+ const back = el('button', 'wiz-secondary', '返回修改')
2362
+ back.type = 'button'
2363
+ back.disabled = WIZ.busy === 'save'
2364
+ back.addEventListener('click', () => wizardGo(2))
2365
+ const save = el('button', 'wiz-primary', WIZ.busy === 'save' ? '写入中…' : '写入配置')
2366
+ save.type = 'button'
2367
+ save.disabled = WIZ.busy === 'save'
2368
+ save.addEventListener('click', wizardSave)
2369
+ wizardFootEl.append(back, el('span', 'spacer'), save)
2370
+ }
2371
+
2372
+ async function wizardSave() {
2373
+ if (WIZ.busy) return
2374
+ WIZ.busy = 'save'
2375
+ WIZ.error = null
2376
+ renderWizard()
2377
+ try {
2378
+ const body = {
2379
+ provider: WIZ.form.provider.trim(),
2380
+ baseURL: WIZ.form.baseURL.trim(),
2381
+ model: WIZ.form.model.trim(),
2382
+ }
2383
+ if (WIZ.form.apiKey.trim()) body.apiKey = WIZ.form.apiKey.trim()
2384
+ const data = await api('/api/console/wizard/save', { method: 'POST', body })
2385
+ WIZ.saved = data
2386
+ WIZ.preview = null
2387
+ WIZ.form.apiKey = ''
2388
+ WIZ.formTouched = false
2389
+ WIZ.step = 4
2390
+ pushToast(`配置已写入${data.backup ? `(备份 ${data.backup.id})` : ''}。`, 'ok')
2391
+ await wizardLoad({ probe: false })
2392
+ } catch (error) {
2393
+ await wizardLoad({ probe: false }).catch(() => {})
2394
+ WIZ.error = { message: messageOf(error), hint: error.hint, code: error.code }
2395
+ } finally {
2396
+ WIZ.busy = null
2397
+ renderWizard()
2398
+ }
2399
+ }
2400
+
2401
+ function trialStatusLabel(status) {
2402
+ if (status === 'completed') return '已完成'
2403
+ if (status === 'failed') return '失败'
2404
+ return '进行中'
2405
+ }
2406
+
2407
+ function renderWizardStep4() {
2408
+ const trial = WIZ.trial
2409
+ if (WIZ.busy === 'trial') {
2410
+ wizardBodyEl.append(wizardBusyNode('正在临时目录里跑一个小任务(建文件并读回)…'))
2411
+ wizardBodyEl.append(el('p', 'wiz-note', '不会碰你的项目目录。模型回复和工具调用会显示在下面。'))
2412
+ wizardFootEl.replaceChildren()
2413
+ const again = el('button', 'wiz-secondary', '试跑中…')
2414
+ again.type = 'button'
2415
+ again.disabled = true
2416
+ wizardFootEl.append(again, el('span', 'spacer'))
2417
+ return
2418
+ }
2419
+
2420
+ if (!trial) {
2421
+ wizardBodyEl.append(el('p', 'wiz-lead', '最后一步:在系统临时目录里建一个文件并读回。它不会碰你的真实项目。'))
2422
+ if (WIZ.saved) {
2423
+ const kv = el('div', 'wiz-kv')
2424
+ const add = (label, value) => {
2425
+ const item = el('span')
2426
+ item.append(el('b', '', `${label}:`))
2427
+ item.append(document.createTextNode(value))
2428
+ kv.append(item)
2429
+ }
2430
+ add('已写入', WIZ.saved.target.patchPath)
2431
+ add('备份', WIZ.saved.backup?.id || '无')
2432
+ add('key', WIZ.saved.key.mask || '已保存')
2433
+ wizardBodyEl.append(kv)
2434
+ if (WIZ.saved.restartHint) wizardBodyEl.append(el('p', 'wiz-note', WIZ.saved.restartHint))
2435
+ }
2436
+ const error = wizardErrorNode()
2437
+ if (error) wizardBodyEl.append(error)
2438
+ wizardFootEl.replaceChildren()
2439
+ const start = el('button', 'wiz-primary', '开始试跑')
2440
+ start.type = 'button'
2441
+ start.addEventListener('click', wizardTrial)
2442
+ wizardFootEl.append(start, el('span', 'spacer'))
2443
+ return
2444
+ }
2445
+
2446
+ const emptyRun = !trial.ok && !trial.message && !(trial.usage?.modelCalls)
2447
+ const verdict = el('div', `wiz-trial-verdict ${trial.ok ? 'ok' : 'bad'}`)
2448
+ verdict.append(el('span', 'big', trial.ok ? '✓' : '!'))
2449
+ const text = el('div')
2450
+ text.append(el('div', 't', trial.ok
2451
+ ? '试跑成功:它真的在临时目录里干了活。'
2452
+ : (emptyRun ? '试跑没有跑起来' : '试跑没有完全成功')))
2453
+ text.append(el('div', 'd', trial.ok
2454
+ ? `用时 ${(trial.elapsedMs / 1000).toFixed(1)} 秒 · 会话 ${shortId(trial.sessionId)}`
2455
+ : (emptyRun
2456
+ ? '这一轮没有模型回复。宿主可能还没切换到新模型,点“重新试跑”再来一次。'
2457
+ : (trial.hint || '看下面的步骤和提示。'))))
2458
+ verdict.append(text)
2459
+ wizardBodyEl.append(verdict)
2460
+
2461
+ wizardBodyEl.append(el('p', 'wiz-note', `子任务 / 工具步骤(${trial.subtasks?.length || 0})`))
2462
+ if (trial.subtasks?.length) {
2463
+ const list = el('div', 'wiz-steps-list')
2464
+ for (const step of trial.subtasks) {
2465
+ const row = el('div', `wiz-task ${step.status || ''}`.trim())
2466
+ row.append(el('span', 'dot'))
2467
+ const body = el('div')
2468
+ body.append(el('span', 'name', `${step.index}. ${step.title}`))
2469
+ body.append(el('span', 'env-value', ` ${trialStatusLabel(step.status)}`))
2470
+ if (step.detail) body.append(el('div', 'detail', step.detail))
2471
+ row.append(body)
2472
+ list.append(row)
2473
+ }
2474
+ wizardBodyEl.append(list)
2475
+ } else {
2476
+ wizardBodyEl.append(el('p', 'wiz-note', emptyRun
2477
+ ? '这一轮没有工具调用,也没有模型回复。'
2478
+ : '这一轮没有工具调用;模型可能直接回答了。'))
2479
+ }
2480
+
2481
+ const stats = el('div', 'wiz-stats')
2482
+ const stat = (key, value) => {
2483
+ const box = el('div', 'wiz-stat')
2484
+ box.append(el('div', 'k', key))
2485
+ box.append(el('div', 'v', value))
2486
+ stats.append(box)
2487
+ }
2488
+ stat('tokens', formatTokens(trial.usage?.totalTokens))
2489
+ stat('花费', trial.cost
2490
+ ? (trial.cost.complete
2491
+ ? trial.cost.text
2492
+ : (trial.cost.text === '$0' ? '未配置单价' : `${trial.cost.text}(部分未定价)`))
2493
+ : '未配置单价')
2494
+ stat('模型调用', String(trial.usage?.modelCalls || 0))
2495
+ wizardBodyEl.append(stats)
2496
+
2497
+ const file = trial.file
2498
+ const fileLine = file?.verified
2499
+ ? `临时文件已创建并读回:${file.name}(${file.bytes} 字节,内容包含 ok)`
2500
+ : file?.exists
2501
+ ? `临时文件存在,但内容不是约定的 ok:${file.preview ?? ''}`
2502
+ : '临时目录里没有找到约定的文件。'
2503
+ wizardBodyEl.append(el('div', 'wiz-file', fileLine))
2504
+
2505
+ if (trial.message) wizardBodyEl.append(el('p', 'wiz-note', `模型回复:${trial.message}`))
2506
+ const error = wizardErrorNode()
2507
+ if (error) wizardBodyEl.append(error)
2508
+
2509
+ wizardFootEl.replaceChildren()
2510
+ const again = el('button', 'wiz-secondary', '重新试跑')
2511
+ again.type = 'button'
2512
+ again.addEventListener('click', wizardTrial)
2513
+ wizardFootEl.append(again)
2514
+ const backup = WIZ.status?.backups?.[0]
2515
+ if (backup) {
2516
+ const rollback = el('button', 'wiz-secondary', `回滚上次写入(${backup.id})`)
2517
+ rollback.type = 'button'
2518
+ rollback.addEventListener('click', wizardRollback)
2519
+ wizardFootEl.append(rollback)
2520
+ }
2521
+ const done = el('button', 'wiz-primary', '完成')
2522
+ done.type = 'button'
2523
+ done.addEventListener('click', () => {
2524
+ wizardClose()
2525
+ inputEl.focus()
2526
+ })
2527
+ wizardFootEl.append(el('span', 'spacer'), done)
2528
+ }
2529
+
2530
+ async function wizardTrial() {
2531
+ if (WIZ.busy) return
2532
+ WIZ.busy = 'trial'
2533
+ WIZ.error = null
2534
+ WIZ.trial = null
2535
+ renderWizard()
2536
+ try {
2537
+ const data = await api('/api/console/wizard/trial', { method: 'POST', body: {} })
2538
+ WIZ.trial = data
2539
+ if (data.ok) pushToast('试跑成功:它真的在临时目录里干了活。', 'ok')
2540
+ else pushToast('试跑没成功,按提示处理。', 'err')
2541
+ await wizardLoad({ probe: false })
2542
+ } catch (error) {
2543
+ WIZ.error = {
2544
+ message: messageOf(error),
2545
+ hint: error.hint || (!error.status ? '宿主可能正在热加载配置,等两秒再点一次“开始试跑”。' : null),
2546
+ code: error.code,
2547
+ }
2548
+ } finally {
2549
+ WIZ.busy = null
2550
+ renderWizard()
2551
+ }
2552
+ }
2553
+
2554
+ async function wizardRollback() {
2555
+ const backup = WIZ.status?.backups?.[0]
2556
+ if (!backup || WIZ.busy) return
2557
+ const when = backup.createdAt ? new Date(backup.createdAt).toLocaleString('zh-CN') : backup.id
2558
+ if (!window.confirm(`回滚到 ${when} 写入前的配置?API key 不会被删除。`)) return
2559
+ WIZ.busy = 'rollback'
2560
+ WIZ.error = null
2561
+ renderWizard()
2562
+ try {
2563
+ await api('/api/console/wizard/rollback', { method: 'POST', body: { id: backup.id } })
2564
+ WIZ.saved = null
2565
+ WIZ.preview = null
2566
+ WIZ.trial = null
2567
+ WIZ.step = 1
2568
+ WIZ.formTouched = false
2569
+ pushToast('已回滚到写入前的配置。', 'ok')
2570
+ await wizardLoad({ probe: true })
2571
+ } catch (error) {
2572
+ WIZ.error = { message: messageOf(error), hint: error.hint, code: error.code }
2573
+ } finally {
2574
+ WIZ.busy = null
2575
+ renderWizard()
2576
+ }
2577
+ }
2578
+
1376
2579
  async function bootstrap() {
1377
2580
  try {
1378
2581
  const data = await api('/api/console/bootstrap', { method: 'POST' })
@@ -1493,9 +2696,10 @@
1493
2696
  const data = await api('/api/console/session', { method: 'POST' })
1494
2697
  if (STATE.streamAbort) STATE.streamAbort.abort()
1495
2698
  setSession(data.sessionId)
2699
+ STATE.approvals.clear()
1496
2700
  clearMessages()
1497
2701
  STATE.runs = []
1498
- renderRuns()
2702
+ renderLanes()
1499
2703
  renderEmpty()
1500
2704
  renderTools(null)
1501
2705
  loadTools()
@@ -1541,6 +2745,24 @@
1541
2745
  }
1542
2746
  }
1543
2747
 
2748
+ // ---------- drawers ----------
2749
+
2750
+ function drawerOpen(which) {
2751
+ const target = which === 'history' ? historyDrawerEl : advancedDrawerEl
2752
+ historyDrawerEl.hidden = target !== historyDrawerEl
2753
+ advancedDrawerEl.hidden = target !== advancedDrawerEl
2754
+ scrimEl.hidden = false
2755
+ target.hidden = false
2756
+ if (which === 'history') renderHistory()
2757
+ else renderAdvancedRuns()
2758
+ }
2759
+
2760
+ function drawerClose() {
2761
+ historyDrawerEl.hidden = true
2762
+ advancedDrawerEl.hidden = true
2763
+ scrimEl.hidden = true
2764
+ }
2765
+
1544
2766
  // ---------- wiring ----------
1545
2767
 
1546
2768
  messagesEl.addEventListener('scroll', () => {
@@ -1575,6 +2797,24 @@
1575
2797
  }
1576
2798
 
1577
2799
  newChatEl.addEventListener('click', newConversation)
2800
+ $('historyOpen').addEventListener('click', () => drawerOpen('history'))
2801
+ $('advancedOpen').addEventListener('click', () => drawerOpen('advanced'))
2802
+ for (const button of document.querySelectorAll('[data-close]')) {
2803
+ button.addEventListener('click', drawerClose)
2804
+ }
2805
+ scrimEl.addEventListener('click', drawerClose)
2806
+ document.addEventListener('keydown', event => {
2807
+ if (event.key !== 'Escape') return
2808
+ if (wizardDialogEl.open) return
2809
+ drawerClose()
2810
+ })
2811
+ $('wizardOpen').addEventListener('click', () => wizardOpen(1))
2812
+ $('envWizard').addEventListener('click', () => wizardOpen(1))
2813
+ $('wizardClose').addEventListener('click', wizardClose)
2814
+ wizardDialogEl.addEventListener('click', event => {
2815
+ if (event.target === wizardDialogEl) wizardClose()
2816
+ })
2817
+ wizardDialogEl.addEventListener('close', () => { WIZ.open = false })
1578
2818
  $('dialogClose').addEventListener('click', () => reportDialogEl.close())
1579
2819
  reportDialogEl.addEventListener('click', event => {
1580
2820
  if (event.target === reportDialogEl) reportDialogEl.close()