@xiangyixie/dsh-superagent 0.14.8 → 0.15.0

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 专属空间</title>
6
+ <title>Superagent 控制台</title>
7
7
  <style>
8
8
  :root {
9
9
  color-scheme: dark;
@@ -481,6 +481,41 @@
481
481
  }
482
482
  .toast.err { border-color: rgba(255, 123, 114, .4); color: #ffc0bb; }
483
483
  .toast.ok { border-color: rgba(99, 214, 164, .35); }
484
+ .toast.warn { border-color: rgba(246, 193, 119, .4); color: #ffd8a1; }
485
+
486
+ .notice-btn { position: relative; }
487
+ .notice-btn.has-unread { border-color: rgba(246, 193, 119, .5); color: var(--amber); }
488
+ .notice-btn .count {
489
+ display: inline-block; min-width: 16px; margin-left: 6px; padding: 0 4px;
490
+ border-radius: 8px; background: rgba(246, 193, 119, .18); color: var(--amber);
491
+ font-size: 11px; text-align: center;
492
+ }
493
+ .notice-panel {
494
+ position: fixed; top: 58px; right: 14px; z-index: 26; width: 322px; max-height: 62vh;
495
+ display: flex; flex-direction: column; padding: 10px 10px 8px;
496
+ border: 1px solid var(--line); border-radius: 12px; background: #111a1f;
497
+ box-shadow: 0 18px 44px rgba(0, 0, 0, .45);
498
+ }
499
+ .notice-panel[hidden] { display: none; }
500
+ .notice-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 8px; }
501
+ .notice-head .kicker { color: var(--accent); font: 10px var(--mono); letter-spacing: .14em; text-transform: uppercase; }
502
+ .notice-list { display: flex; flex-direction: column; gap: 6px; overflow: auto; }
503
+ .notice-item {
504
+ display: flex; gap: 8px; align-items: flex-start; padding: 8px 9px; border-radius: 9px;
505
+ border: 1px solid var(--line-soft); background: #0e1418; font-size: 12px; cursor: pointer;
506
+ }
507
+ .notice-item.unread { border-color: rgba(246, 193, 119, .35); background: rgba(246, 193, 119, .06); }
508
+ .notice-item .dot { width: 6px; height: 6px; margin-top: 5px; border-radius: 50%; background: var(--faint); flex: none; }
509
+ .notice-item.unread .dot { background: var(--amber); }
510
+ .notice-item .body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
511
+ .notice-item .title { font-weight: 600; color: var(--text); }
512
+ .notice-item .detail { color: var(--faint); line-height: 1.4; word-break: break-word; }
513
+ .notice-item .when { color: var(--faint); font-size: 11px; }
514
+ .notice-empty { padding: 14px 6px; color: var(--faint); font-size: 12px; text-align: center; }
515
+ .composer.dragover .composer-box {
516
+ border-color: rgba(94, 234, 212, .7); background: rgba(94, 234, 212, .06);
517
+ box-shadow: 0 0 0 4px rgba(94, 234, 212, .12);
518
+ }
484
519
 
485
520
  .gate {
486
521
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
@@ -592,6 +627,56 @@
592
627
  .step.failed .sdot { background: var(--red); }
593
628
  .lane-progress-text { margin-top: 5px; color: var(--faint); font-size: 10.5px; }
594
629
 
630
+ /* ---- schedule board: what runs now, what waits, on one time axis ---- */
631
+ .schedule-wrap { flex: none; padding: 0 22px 10px; max-height: 38vh; overflow: auto; }
632
+ .schedule-wrap[hidden] { display: none; }
633
+ .sched {
634
+ margin: 0 0 10px; padding: 9px 10px 10px;
635
+ border: 1px solid var(--line-soft); border-radius: 10px; background: #0c1217;
636
+ }
637
+ .sched-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 3px 10px; margin-bottom: 7px; }
638
+ .sched-title { color: var(--muted); font-size: 11px; font-weight: 600; }
639
+ .sched-facts { color: var(--faint); font-size: 10.5px; }
640
+ .sched-axis { margin-left: auto; color: var(--faint); font: 10px var(--mono); white-space: nowrap; }
641
+ .sched-run { min-width: 0; padding: 6px 0 2px; border-top: 1px dashed var(--line-soft); }
642
+ .sched-run:first-of-type { border-top: 0; padding-top: 0; }
643
+ .sched-run-head { display: flex; align-items: center; gap: 7px; min-width: 0; margin-bottom: 4px; }
644
+ .sched-goal {
645
+ flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
646
+ color: var(--muted); font-size: 11.5px;
647
+ }
648
+ .sched-time { flex: none; color: var(--faint); font: 10px var(--mono); white-space: nowrap; }
649
+ .sched-row {
650
+ display: grid; grid-template-columns: minmax(0, 180px) minmax(0, 1fr);
651
+ gap: 8px; align-items: center; min-width: 0; padding: 2px 0;
652
+ }
653
+ .sched-label {
654
+ min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
655
+ color: var(--muted); font-size: 10.5px;
656
+ }
657
+ .sched-label .n { color: var(--faint); font-family: var(--mono); margin-right: 4px; }
658
+ .sched-note { color: var(--faint); font-size: 10px; }
659
+ .sched-track {
660
+ position: relative; height: 9px; min-width: 0;
661
+ border-radius: 999px; background: #131c22; overflow: hidden;
662
+ }
663
+ .sched-bar {
664
+ position: absolute; top: 0; bottom: 0; min-width: 2px; border-radius: 999px;
665
+ background: #3a4a55;
666
+ }
667
+ .sched-bar.running { background: var(--amber); }
668
+ .sched-bar.completed { background: var(--green); }
669
+ .sched-bar.failed, .sched-bar.cancelled { background: var(--red); }
670
+ .sched-bar.waiting {
671
+ left: 0; right: 0; background: transparent;
672
+ border: 1px dashed rgba(246, 193, 119, .45);
673
+ }
674
+ .sched-bar.pending { left: 0; right: 0; background: #1d272e; }
675
+ .sched-bar.skipped { left: 0; right: 0; background: repeating-linear-gradient(90deg, #2a3740 0 6px, transparent 6px 11px); }
676
+ .sched-empty { color: var(--faint); font-size: 10.5px; padding: 2px 0 3px; }
677
+ .sched-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 6px; color: var(--faint); font-size: 10px; }
678
+ .sched-legend i { display: inline-block; width: 7px; height: 7px; margin-right: 3px; border-radius: 2px; vertical-align: -1px; }
679
+
595
680
  .summary {
596
681
  margin-top: 10px; padding: 10px 11px; border-radius: 10px;
597
682
  border: 1px solid rgba(99, 214, 164, .28); background: rgba(99, 214, 164, .05);
@@ -664,7 +749,14 @@
664
749
  .brand { min-width: 0; }
665
750
  .brand div span { display: none; }
666
751
  .hint { display: none; }
667
- .messages { padding: 16px 14px 22px; }
752
+ .messages { padding: 16px 14px 22px; }
753
+ .schedule-wrap { padding: 0 14px 10px; max-height: 44vh; }
754
+ /* One column per step: the label sits above its bar, so a narrow screen
755
+ keeps the order and the durations instead of squeezing both sideways. */
756
+ .sched-row { grid-template-columns: minmax(0, 1fr); gap: 3px; }
757
+ .sched-label { white-space: normal; overflow: visible; text-overflow: clip; }
758
+ .sched-axis { margin-left: 0; }
759
+ .sched-goal { white-space: normal; }
668
760
  }
669
761
  </style>
670
762
  </head>
@@ -673,7 +765,7 @@
673
765
  <header class="topbar">
674
766
  <div class="brand">
675
767
  <div class="mark">S</div>
676
- <div><strong>Superagent</strong><span>专属空间</span></div>
768
+ <div><strong>Superagent</strong><span>控制台</span></div>
677
769
  </div>
678
770
  <div class="topbar-mid">
679
771
  <span id="modeBadge" class="badge"><span class="pulse"></span><span id="modeText">连接中</span></span>
@@ -682,6 +774,7 @@
682
774
  <div class="topbar-actions">
683
775
  <span id="conn" class="conn"><i></i><span id="connText">连接中</span></span>
684
776
  <button id="stopAll" class="btn danger" type="button" hidden>停止这一轮</button>
777
+ <button id="noticeOpen" class="btn notice-btn" type="button" hidden>提醒<span id="noticeCount" class="count">0</span></button>
685
778
  <button id="newChatTop" class="btn" type="button" disabled>新对话</button>
686
779
  <button id="historyOpen" class="btn" type="button">历史</button>
687
780
  <button id="advancedOpen" class="btn" type="button">高级</button>
@@ -699,14 +792,14 @@
699
792
  <div class="chat-head">
700
793
  <div>
701
794
  <h1>Superagent</h1>
702
- <p>说一句就行 · 自动拆成任务线并行推进 · 跑完在这一条对话里汇总</p>
795
+ <p>说一句要做什么;它自己决定一步做完还是拆开并行,跑完在这里汇总</p>
703
796
  </div>
704
797
  <div id="typing" class="typing" hidden><span></span><span></span><span></span><em id="typingText" style="font-style:normal;margin-left:3px">运行中</em></div>
705
798
  </div>
706
- <div id="messages" class="messages" aria-live="polite"></div>
707
- <form id="composer" class="composer" autocomplete="off">
799
+ <section id="scheduleWrap" class="schedule-wrap" aria-label="调度" hidden></section>
800
+ <div id="messages" class="messages" aria-live="polite"></div> <form id="composer" class="composer" autocomplete="off">
708
801
  <div class="composer-box">
709
- <textarea id="input" rows="1" placeholder="直接说你想让它做什么…" disabled></textarea>
802
+ <textarea id="input" rows="1" placeholder="要做什么…" disabled></textarea>
710
803
  <div class="composer-bar">
711
804
  <span class="hint">Enter 发送 · Shift+Enter 换行</span>
712
805
  <button id="send" class="send" type="submit" aria-label="发送" disabled>↑</button>
@@ -719,6 +812,14 @@
719
812
 
720
813
  <div id="scrim" class="scrim" hidden></div>
721
814
 
815
+ <div id="noticePanel" class="notice-panel" hidden>
816
+ <div class="notice-head">
817
+ <span class="kicker">提醒</span>
818
+ <button id="noticeReadAll" class="btn tiny" type="button">全部已读</button>
819
+ </div>
820
+ <div id="noticeList" class="notice-list"></div>
821
+ </div>
822
+
722
823
  <aside id="historyDrawer" class="drawer" hidden aria-label="历史">
723
824
  <div class="drawer-head">
724
825
  <div>
@@ -743,7 +844,7 @@
743
844
  <h3>会话</h3>
744
845
  <div id="advSession" class="adv-kv"></div>
745
846
  <div class="adv-actions">
746
- <button id="wizardOpen" class="btn tiny" type="button">首次使用向导</button>
847
+ <button id="wizardOpen" class="btn tiny" type="button">配置向导</button>
747
848
  </div>
748
849
  </section>
749
850
  <section class="adv-sec">
@@ -769,9 +870,9 @@
769
870
  <div id="gate" class="gate" hidden>
770
871
  <form id="gateForm" class="gate-card">
771
872
  <div class="mark">S</div>
772
- <h1>连接 Superagent Console</h1>
773
- <p>从宿主状态目录的 <code>console.json</code> 读取一次性 token。控制台只监听 127.0.0.1,token 每次启动都会重新生成。</p>
774
- <label for="tokenInput">访问令牌</label>
873
+ <h1>连接 Superagent 控制台</h1>
874
+ <p>token 在宿主状态目录的 <code>console.json</code> 里,每次启动都会换。控制台只监听 127.0.0.1。</p>
875
+ <label for="tokenInput">token</label>
775
876
  <input id="tokenInput" type="password" autocomplete="off" spellcheck="false" placeholder="粘贴 token">
776
877
  <button type="submit">连接</button>
777
878
  <p id="gateError" class="error"></p>
@@ -783,8 +884,8 @@
783
884
  <dialog id="wizardDialog">
784
885
  <div class="wiz-head">
785
886
  <div>
786
- <span class="kicker">首次使用向导</span>
787
- <h2>用鼠标完成配置,并当场试跑</h2>
887
+ <span class="kicker">首次配置</span>
888
+ <h2>填好配置,当场试跑</h2>
788
889
  </div>
789
890
  <button id="wizardClose" type="button" aria-label="关闭">×</button>
790
891
  </div>
@@ -811,7 +912,8 @@
811
912
 
812
913
  const TOKEN_KEY = 'dsh-superagent-console-token'
813
914
  const $ = id => document.getElementById(id)
814
- const messagesEl = $('messages')
915
+ const messagesEl = $('messages')
916
+ const scheduleWrapEl = $('scheduleWrap')
815
917
  const inputEl = $('input')
816
918
  const sendEl = $('send')
817
919
  const composerEl = $('composer')
@@ -846,6 +948,23 @@
846
948
  const advancedDrawerEl = $('advancedDrawer')
847
949
  const advSessionEl = $('advSession')
848
950
  const advRunsEl = $('advRuns')
951
+ const noticeOpenEl = $('noticeOpen')
952
+ const noticeCountEl = $('noticeCount')
953
+ const noticePanelEl = $('noticePanel')
954
+ const noticeListEl = $('noticeList')
955
+
956
+ // Upload rules mirror the server's: the page refuses early with a readable
957
+ // sentence, and the server refuses again because a page is not a gate.
958
+ const UPLOAD_MAX = 8 * 1024 * 1024
959
+ const UPLOAD_EXTS = new Set([
960
+ '.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.bmp',
961
+ '.pdf', '.md', '.markdown', '.txt', '.log', '.csv', '.tsv', '.json', '.yml', '.yaml', '.xml',
962
+ '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.rtf',
963
+ '.zip', '.tar', '.gz', '.7z',
964
+ '.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.py', '.css', '.html', '.htm', '.sql', '.sh',
965
+ '.ps1', '.toml', '.ini', '.ipynb',
966
+ ])
967
+ const UPLOAD_HINT = '图片、PDF、Markdown/文本、CSV/JSON、Office 文档、压缩包或代码文件'
849
968
 
850
969
  const STATE = {
851
970
  token: '',
@@ -871,6 +990,7 @@
871
990
  preset: null,
872
991
  laneEls: new Map(),
873
992
  runAnchors: new Map(),
993
+ scheduleSig: '',
874
994
  attentionSeen: new Set(),
875
995
  approvals: new Map(),
876
996
  sessions: [],
@@ -879,6 +999,11 @@
879
999
  sessionNote: null,
880
1000
  cancelRequested: new Set(),
881
1001
  stopAllBusy: false,
1002
+ notices: [],
1003
+ readNotices: new Set(),
1004
+ noticeOpen: false,
1005
+ noticesPrimed: false,
1006
+ dragDepth: 0,
882
1007
  }
883
1008
 
884
1009
  const WIZ = {
@@ -933,7 +1058,7 @@
933
1058
 
934
1059
  function statusText(status) {
935
1060
  const map = {
936
- queued: '排队中', planning: '规划中', running: '运行中', aggregating: '汇总中',
1061
+ queued: '排队中', planning: '拆步骤中', running: '运行中', aggregating: '汇总中',
937
1062
  completed: '已完成', failed: '失败', cancelled: '已取消', interrupted: '已中断',
938
1063
  blocked: '已阻塞',
939
1064
  }
@@ -997,8 +1122,8 @@
997
1122
 
998
1123
  function setSession(sessionId) {
999
1124
  STATE.sessionId = sessionId
1000
- sessionLabelEl.textContent = sessionId ? `session ${shortId(sessionId)}` : 'no session'
1001
- sessionLabelEl.title = sessionId || 'Host Session id'
1125
+ sessionLabelEl.textContent = sessionId ? `session ${shortId(sessionId)}` : '没有会话'
1126
+ sessionLabelEl.title = sessionId || '宿主会话 id'
1002
1127
  }
1003
1128
 
1004
1129
  function scrollToEnd() {
@@ -1065,13 +1190,13 @@
1065
1190
  if (message.role === 'assistant') {
1066
1191
  const copy = el('button', '', '复制')
1067
1192
  copy.type = 'button'
1068
- copy.title = '复制这条回复的完整文本'
1193
+ copy.title = '复制这条回复的全文'
1069
1194
  copy.addEventListener('click', () => copyMessage(message, copy))
1070
1195
  actions.append(copy)
1071
1196
  } else {
1072
1197
  const edit = el('button', '', '编辑并重发')
1073
1198
  edit.type = 'button'
1074
- edit.title = '把这条原文放回输入框,改完再发送'
1199
+ edit.title = '把原文放回输入框,改完再发'
1075
1200
  edit.addEventListener('click', () => editMessage(message))
1076
1201
  actions.append(edit)
1077
1202
  }
@@ -1117,10 +1242,10 @@
1117
1242
  async function copyMessage(message, button) {
1118
1243
  const copied = await copyText(formatTextOf(message))
1119
1244
  if (!copied) {
1120
- pushToast('复制失败,可以手动选中文字。', 'err')
1245
+ pushToast('复制失败。手动选中文字再复制。', 'err')
1121
1246
  return
1122
1247
  }
1123
- pushToast('已复制这条回复。', 'ok')
1248
+ pushToast('已复制。', 'ok')
1124
1249
  button.textContent = '已复制'
1125
1250
  setTimeout(() => { button.textContent = '复制' }, 1600)
1126
1251
  }
@@ -1133,7 +1258,7 @@
1133
1258
  inputEl.dispatchEvent(new Event('input'))
1134
1259
  inputEl.focus()
1135
1260
  try { inputEl.setSelectionRange(text.length, text.length) } catch { /* not focusable yet */ }
1136
- pushToast('原文已放回输入框,改完点发送。', 'ok')
1261
+ pushToast('已放回输入框,改完点发送。', 'ok')
1137
1262
  }
1138
1263
 
1139
1264
  function summarizeArgs(value) {
@@ -1161,7 +1286,7 @@
1161
1286
  if (tool.done) {
1162
1287
  const details = el('details')
1163
1288
  details.append(el('summary', failed ? 'err-mark' : '', failed ? '失败原因' : '结果'))
1164
- details.append(el('pre', '', tool.result || (failed ? '工具没有返回错误文本。' : '')))
1289
+ details.append(el('pre', '', tool.result || (failed ? '工具没有给出错误说明。' : '')))
1165
1290
  chip.append(details)
1166
1291
  }
1167
1292
  return chip
@@ -1220,15 +1345,15 @@
1220
1345
  if (STATE.mode !== 'chat') {
1221
1346
  wrap.classList.add('unavailable')
1222
1347
  wrap.append(el('div', 'orb', '!'))
1223
- wrap.append(el('h1', '', '对话不可用'))
1224
- wrap.append(el('p', '', '这个宿主没有提供可对话的 Session。控制台不会画一个假聊天框。'))
1348
+ wrap.append(el('h1', '', '这里不能对话'))
1349
+ wrap.append(el('p', '', '宿主没有可用的会话,所以这里不能开始对话。'))
1225
1350
  if (STATE.capabilities?.reason) wrap.append(el('div', 'reason', STATE.capabilities.reason))
1226
1351
  messagesEl.append(wrap)
1227
1352
  return
1228
1353
  }
1229
1354
  wrap.append(el('div', 'orb', 'S'))
1230
- wrap.append(el('h1', '', '今天想推进什么?'))
1231
- wrap.append(el('p', '', '这里是 Superagent 的专属空间,和宿主的普通会话分开。直接说一句就行:它会自己判断是一步做完,还是拆成几条任务线并行推进;跑完在这一条对话里汇总,并把可以点开的产物放在这里。'))
1355
+ wrap.append(el('h1', '', '要做什么?'))
1356
+ wrap.append(el('p', '', '写下要做的事。它自己决定一步做完,还是拆成几条同时做;跑完在这里汇总,能点开的产物也放在这里。'))
1232
1357
  const examples = el('div', 'examples')
1233
1358
  const samples = [
1234
1359
  '把这周的项目进度整理成一页 HTML 报告',
@@ -1260,6 +1385,225 @@
1260
1385
  inputEl.style.height = `${Math.min(180, Math.max(46, inputEl.scrollHeight))}px`
1261
1386
  }
1262
1387
 
1388
+ // ---------- notices ----------
1389
+ //
1390
+ // A finished run, a failure and a pending decision are all durable on the
1391
+ // host. The page turns them into the same short list every time it loads, so
1392
+ // closing the tab loses nothing: reopening shows "跑完了" or "要你批准" again.
1393
+ // Only the ids a person has already read travel back to the server.
1394
+
1395
+ function noticeWhen(at) {
1396
+ const ms = typeof at === 'number' ? at : Date.parse(at)
1397
+ if (!Number.isFinite(ms)) return ''
1398
+ const diff = Date.now() - ms
1399
+ if (diff < 60_000) return '刚刚'
1400
+ if (diff < 3_600_000) return `${Math.max(1, Math.floor(diff / 60000))} 分钟前`
1401
+ return timeLabel(ms)
1402
+ }
1403
+
1404
+ function collectNotices() {
1405
+ const out = []
1406
+ for (const run of Array.isArray(STATE.runs) ? STATE.runs : []) {
1407
+ if (!run || typeof run.id !== 'string') continue
1408
+ const goal = String(run.goal || '这条任务线').replace(/\s+/g, ' ').slice(0, 64)
1409
+ const question = Array.isArray(run.attention) && run.attention.length > 0 ? run.attention[0] : null
1410
+ if (question) {
1411
+ out.push({
1412
+ id: `run:${run.id}:attention`,
1413
+ kind: 'approval',
1414
+ runId: run.id,
1415
+ title: '要你批准',
1416
+ detail: `${goal} · ${question.question || '在等一个决定'}`,
1417
+ at: question.askedAt || run.finishedAt || run.createdAt,
1418
+ })
1419
+ }
1420
+ if (!isTerminal(run.status)) continue
1421
+ const failed = run.status !== 'completed'
1422
+ out.push({
1423
+ id: `run:${run.id}:${run.status}`,
1424
+ kind: failed ? 'failed' : 'done',
1425
+ runId: run.id,
1426
+ title: failed ? (run.status === 'cancelled' ? '已取消' : '没走通') : '跑完了',
1427
+ detail: `${goal} · ${statusText(run.status)}`,
1428
+ at: run.finishedAt || run.createdAt,
1429
+ })
1430
+ }
1431
+ for (const entry of STATE.approvals.values()) {
1432
+ const approval = entry.approval || {}
1433
+ if (!approval.id) continue
1434
+ out.push({
1435
+ id: `approval:${approval.id}`,
1436
+ kind: 'approval',
1437
+ title: '要你批准',
1438
+ detail: `工具 ${approval.toolName || 'tool'} 在等你决定`,
1439
+ at: approval.askedAt,
1440
+ })
1441
+ }
1442
+ out.sort((left, right) => (Date.parse(right.at) || 0) - (Date.parse(left.at) || 0))
1443
+ return out.slice(0, 30)
1444
+ }
1445
+
1446
+ function unreadNotices() {
1447
+ return STATE.notices.filter(notice => !STATE.readNotices.has(notice.id))
1448
+ }
1449
+
1450
+ function renderNoticeBadge() {
1451
+ const unread = unreadNotices().length
1452
+ noticeOpenEl.hidden = STATE.notices.length === 0
1453
+ noticeCountEl.textContent = unread > 99 ? '99+' : String(unread)
1454
+ noticeOpenEl.classList.toggle('has-unread', unread > 0)
1455
+ noticeOpenEl.title = unread > 0 ? `${unread} 条没看过的提醒` : '提醒'
1456
+ const base = 'Superagent 控制台'
1457
+ document.title = unread > 0 ? `(${unread}) ${base}` : base
1458
+ if (!noticePanelEl.hidden) renderNoticeList()
1459
+ }
1460
+
1461
+ function renderNoticeList() {
1462
+ noticeListEl.textContent = ''
1463
+ if (STATE.notices.length === 0) {
1464
+ noticeListEl.append(el('div', 'notice-empty', '没有提醒。任务跑完、失败或等你批准时会出现在这里。'))
1465
+ return
1466
+ }
1467
+ for (const notice of STATE.notices) {
1468
+ const unread = !STATE.readNotices.has(notice.id)
1469
+ const item = el('div', `notice-item${unread ? ' unread' : ''}`)
1470
+ item.dataset.id = notice.id
1471
+ item.append(el('span', 'dot'))
1472
+ const body = el('div', 'body')
1473
+ body.append(el('div', 'title', notice.title))
1474
+ body.append(el('div', 'detail', notice.detail))
1475
+ body.append(el('div', 'when', noticeWhen(notice.at)))
1476
+ item.append(body)
1477
+ item.addEventListener('click', () => {
1478
+ markNoticesRead([notice.id])
1479
+ if (notice.runId) openReport(notice.runId)
1480
+ closeNoticePanel()
1481
+ })
1482
+ noticeListEl.append(item)
1483
+ }
1484
+ }
1485
+
1486
+ function refreshNotices({ toastNew = false } = {}) {
1487
+ const previous = new Set(STATE.notices.map(notice => notice.id))
1488
+ // The first pass only paints what already happened; a toast is for a
1489
+ // change that arrives while the page is open.
1490
+ const primed = STATE.noticesPrimed === true
1491
+ STATE.notices = collectNotices()
1492
+ STATE.noticesPrimed = true
1493
+ if (toastNew && primed) {
1494
+ for (const notice of STATE.notices) {
1495
+ if (previous.has(notice.id)) continue
1496
+ if (notice.kind === 'done') pushToast(`跑完了:${notice.detail}`, 'ok')
1497
+ else if (notice.kind === 'failed') pushToast(`${notice.title}:${notice.detail}`, 'err')
1498
+ else if (notice.kind === 'approval') pushToast(`要你批准:${notice.detail}`, 'warn')
1499
+ }
1500
+ }
1501
+ renderNoticeBadge()
1502
+ }
1503
+
1504
+ function markNoticesRead(ids) {
1505
+ const fresh = (Array.isArray(ids) ? ids : []).filter(id => id && !STATE.readNotices.has(id))
1506
+ if (fresh.length === 0) return
1507
+ for (const id of fresh) STATE.readNotices.add(id)
1508
+ renderNoticeBadge()
1509
+ api('/api/console/notices/read', { method: 'POST', body: { ids: fresh } }).catch(() => {})
1510
+ }
1511
+
1512
+ function openNoticePanel() {
1513
+ STATE.noticeOpen = true
1514
+ noticePanelEl.hidden = false
1515
+ renderNoticeList()
1516
+ // Opening the list is reading it: the badge clears, the lines stay.
1517
+ markNoticesRead(STATE.notices.map(notice => notice.id))
1518
+ }
1519
+
1520
+ function closeNoticePanel() {
1521
+ STATE.noticeOpen = false
1522
+ noticePanelEl.hidden = true
1523
+ }
1524
+
1525
+ // ---------- files ----------
1526
+ //
1527
+ // A dropped or pasted file is copied into the conversation's workspace by
1528
+ // the host, and the path it returns is what the message carries. Nothing is
1529
+ // uploaded to a third party, and nothing outside the workspace is written.
1530
+
1531
+ function uploadExtOf(name) {
1532
+ const text = typeof name === 'string' ? name : ''
1533
+ const dot = text.lastIndexOf('.')
1534
+ return dot >= 0 ? text.slice(dot).toLowerCase() : ''
1535
+ }
1536
+
1537
+ function uploadSizeText(bytes) {
1538
+ const size = Number(bytes) || 0
1539
+ if (size >= 1024 * 1024) return `${(size / (1024 * 1024)).toFixed(1)}MB`
1540
+ if (size >= 1024) return `${Math.round(size / 1024)}KB`
1541
+ return `${size}B`
1542
+ }
1543
+
1544
+ function base64OfBytes(bytes) {
1545
+ let binary = ''
1546
+ const chunk = 0x8000
1547
+ for (let index = 0; index < bytes.length; index += chunk) {
1548
+ binary += String.fromCharCode.apply(null, bytes.subarray(index, index + chunk))
1549
+ }
1550
+ return btoa(binary)
1551
+ }
1552
+
1553
+ function insertUploadPath(filePath) {
1554
+ if (!filePath) return
1555
+ const current = inputEl.value
1556
+ const separator = current.length === 0 || current.endsWith('\n') ? '' : '\n'
1557
+ inputEl.value = `${current}${separator}${filePath}\n`
1558
+ autoGrow()
1559
+ updateSend()
1560
+ inputEl.focus()
1561
+ try { inputEl.setSelectionRange(inputEl.value.length, inputEl.value.length) } catch { /* not focusable yet */ }
1562
+ }
1563
+
1564
+ async function uploadFiles(files) {
1565
+ const list = Array.from(files || []).filter(Boolean)
1566
+ if (list.length === 0) return
1567
+ if (STATE.mode !== 'chat') {
1568
+ pushToast('还没连上,等对话准备好再放文件。', 'err')
1569
+ return
1570
+ }
1571
+ for (const file of list) {
1572
+ const ext = uploadExtOf(file.name)
1573
+ if (!UPLOAD_EXTS.has(ext)) {
1574
+ pushToast(`不能放 ${ext || '没有扩展名的'} 文件。可以放:${UPLOAD_HINT}。`, 'err')
1575
+ continue
1576
+ }
1577
+ if (file.size > UPLOAD_MAX) {
1578
+ pushToast(`${file.name} 有 ${uploadSizeText(file.size)},超过 ${uploadSizeText(UPLOAD_MAX)} 上限。`, 'err')
1579
+ continue
1580
+ }
1581
+ if (file.size === 0) {
1582
+ pushToast(`${file.name} 是空文件,没放进去。`, 'err')
1583
+ continue
1584
+ }
1585
+ try {
1586
+ const bytes = new Uint8Array(await file.arrayBuffer())
1587
+ const data = await api('/api/console/upload', {
1588
+ method: 'POST',
1589
+ body: { sessionId: STATE.sessionId, name: file.name, data: base64OfBytes(bytes) },
1590
+ })
1591
+ insertUploadPath(data.path)
1592
+ pushToast(`已放进工作区:${data.name}。路径写进了消息。`, 'ok')
1593
+ } catch (error) {
1594
+ const hint = error.hint ? `。${error.hint}` : ''
1595
+ pushToast(`放不进去:${messageOf(error)}${hint}`, 'err')
1596
+ }
1597
+ }
1598
+ }
1599
+
1600
+ function dragHasFiles(event) {
1601
+ const transfer = event.dataTransfer
1602
+ if (!transfer) return false
1603
+ if (transfer.files && transfer.files.length > 0) return true
1604
+ return Array.from(transfer.types || []).includes('Files')
1605
+ }
1606
+
1263
1607
  // ---------- task lanes ----------
1264
1608
 
1265
1609
  const TERMINAL_STATUSES = new Set(['completed', 'failed', 'cancelled', 'interrupted', 'blocked'])
@@ -1311,11 +1655,214 @@
1311
1655
  }
1312
1656
  }
1313
1657
 
1658
+ // ---------- schedule board ----------
1659
+ //
1660
+ // The board is a projection of the run records the host already writes: run
1661
+ // status, each step's status/startedAt/finishedAt, the waitingOn keys the
1662
+ // graph scheduler sets, and the run's own maxParallel/queue. Nothing here
1663
+ // invents a second queue or recomputes progress.
1664
+
1665
+ function timeOf(value) {
1666
+ const ms = typeof value === 'number' ? value : Date.parse(value)
1667
+ return Number.isFinite(ms) ? ms : null
1668
+ }
1669
+
1670
+ function scheduleAxis(runs) {
1671
+ let start = Infinity
1672
+ let end = 0
1673
+ for (const run of runs) {
1674
+ const created = timeOf(run.createdAt)
1675
+ if (created !== null) {
1676
+ start = Math.min(start, created)
1677
+ end = Math.max(end, created)
1678
+ }
1679
+ for (const subtask of Array.isArray(run.subtasks) ? run.subtasks : []) {
1680
+ const began = timeOf(subtask.startedAt)
1681
+ if (began !== null) {
1682
+ start = Math.min(start, began)
1683
+ end = Math.max(end, began)
1684
+ }
1685
+ const ended = timeOf(subtask.finishedAt)
1686
+ if (ended !== null) end = Math.max(end, ended)
1687
+ }
1688
+ const finished = timeOf(run.finishedAt)
1689
+ if (finished !== null) end = Math.max(end, finished)
1690
+ }
1691
+ if (!Number.isFinite(start)) start = Date.now()
1692
+ const live = runs.some(run => !isTerminal(run.status))
1693
+ const right = Math.max(end, live ? Date.now() : 0, start + 1000)
1694
+ return { start, end: right, live }
1695
+ }
1696
+
1697
+ function scheduleStats(runs) {
1698
+ const active = runs.filter(run => !isTerminal(run.status) && run.status !== 'queued')
1699
+ const queued = runs.filter(run => run.status === 'queued')
1700
+ const steps = runs.flatMap(run => (Array.isArray(run.subtasks) ? run.subtasks : []))
1701
+ const running = steps.filter(subtask => subtask.status === 'running').length
1702
+ const waiting = steps.filter(subtask => subtask.status === 'waiting').length
1703
+ const cap = runs.reduce((best, run) => Math.max(best, Number(run.limits?.maxParallel) || 0), 0)
1704
+ return { active, queued, running, waiting, cap }
1705
+ }
1706
+
1707
+ function stepTitleOf(run, key) {
1708
+ const hit = (Array.isArray(run.subtasks) ? run.subtasks : []).find(subtask => subtask.key === key)
1709
+ return hit ? stepLabel(hit) : String(key)
1710
+ }
1711
+
1712
+ function scheduleBar(subtask, run, axis) {
1713
+ const began = timeOf(subtask.startedAt) ?? timeOf(run.startedAt) ?? timeOf(run.createdAt)
1714
+ if (began === null) return null
1715
+ const ended = timeOf(subtask.finishedAt) ?? (subtask.status === 'running' ? Date.now() : null)
1716
+ if (ended === null) return null
1717
+ const span = Math.max(1000, axis.end - axis.start)
1718
+ const left = Math.max(0, Math.min(99, ((began - axis.start) / span) * 100))
1719
+ const width = Math.max(1.2, Math.min(100 - left, ((ended - began) / span) * 100))
1720
+ return { left, width }
1721
+ }
1722
+
1723
+ function scheduleRow(run, subtask, axis) {
1724
+ const row = el('div', 'sched-row')
1725
+ const label = el('div', 'sched-label')
1726
+ label.title = stepLabel(subtask)
1727
+ label.append(el('span', 'n', subtask.key || String(subtask.index ?? '·')))
1728
+ label.append(document.createTextNode(stepLabel(subtask)))
1729
+ const notes = []
1730
+ if (subtask.status === 'running' && subtask.tool) notes.push(`工具 ${subtask.tool}`)
1731
+ const waits = Array.isArray(subtask.waitingOn) ? subtask.waitingOn : []
1732
+ if (waits.length > 0) notes.push(`等「${waits.map(key => stepTitleOf(run, key)).join('」「')}」`)
1733
+ else if (subtask.status === 'waiting') notes.push('等前一步')
1734
+ if (subtask.status === 'skipped') notes.push('跳过')
1735
+ if (notes.length > 0) label.append(el('span', 'sched-note', ` · ${notes.join(' · ')}`))
1736
+ row.append(label)
1737
+
1738
+ const track = el('div', 'sched-track')
1739
+ const range = scheduleBar(subtask, run, axis)
1740
+ const status = subtask.status || 'pending'
1741
+ const bar = el('i', `sched-bar ${status}`)
1742
+ if (range) {
1743
+ bar.style.left = `${range.left}%`
1744
+ bar.style.width = `${range.width}%`
1745
+ if (status === 'running') {
1746
+ const began = timeOf(subtask.startedAt) ?? timeOf(run.startedAt) ?? timeOf(run.createdAt)
1747
+ if (began !== null) bar.dataset.start = String(began)
1748
+ }
1749
+ }
1750
+ track.append(bar)
1751
+ row.append(track)
1752
+ return row
1753
+ }
1754
+
1755
+ function scheduleElement(runs) {
1756
+ const stats = scheduleStats(runs)
1757
+ const axis = scheduleAxis(runs)
1758
+ const box = el('div', 'sched')
1759
+ box.dataset.axisStart = String(axis.start)
1760
+ box.dataset.live = axis.live ? '1' : ''
1761
+
1762
+ const head = el('div', 'sched-head')
1763
+ head.append(el('span', 'sched-title', '调度'))
1764
+ const facts = []
1765
+ if (stats.running > 0) facts.push(`并行 ${stats.running}${stats.cap > 0 ? `/${stats.cap}` : ''} 步`)
1766
+ if (stats.active.length > 0) facts.push(`${stats.active.length} 条任务线在跑`)
1767
+ if (stats.waiting > 0) facts.push(`${stats.waiting} 步等前一步`)
1768
+ if (stats.queued.length > 0) facts.push(`${stats.queued.length} 条排队`)
1769
+ if (facts.length === 0) facts.push(runs.every(run => isTerminal(run.status)) ? '这一轮已结束' : '还没有步骤在跑')
1770
+ head.append(el('span', 'sched-facts', facts.join(' · ')))
1771
+ head.append(el('span', 'sched-axis', formatClock(axis.end - axis.start)))
1772
+ box.append(head)
1773
+
1774
+ for (const run of runs) {
1775
+ const section = el('div', 'sched-run')
1776
+ const runHead = el('div', 'sched-run-head')
1777
+ runHead.append(el('span', 'sched-goal', run.goal || '这条任务线'))
1778
+ runHead.append(el('span', `status-pill ${statusClass(run.status)}`, laneStatusText(run)))
1779
+ if (run.status === 'queued') {
1780
+ const queue = run.queue || {}
1781
+ runHead.append(el('span', 'sched-time', queue.position
1782
+ ? `排第 ${queue.position}${queue.of ? ` / ${queue.of}` : ''}`
1783
+ : '排队中'))
1784
+ } else {
1785
+ runHead.append(el('span', 'sched-time', laneElapsed(run)))
1786
+ }
1787
+ section.append(runHead)
1788
+
1789
+ const subtasks = Array.isArray(run.subtasks) ? run.subtasks : []
1790
+ if (subtasks.length === 0) {
1791
+ section.append(el('div', 'sched-empty', run.status === 'queued'
1792
+ ? '等前面的任务线跑完再开始'
1793
+ : run.status === 'planning' ? '拆步骤中,还没有步骤时间' : '还没有步骤记录'))
1794
+ } else {
1795
+ for (const subtask of subtasks.slice(0, 10)) section.append(scheduleRow(run, subtask, axis))
1796
+ if (subtasks.length > 10) section.append(el('div', 'sched-empty', `还有 ${subtasks.length - 10} 个步骤`))
1797
+ }
1798
+ box.append(section)
1799
+ }
1800
+
1801
+ const legend = el('div', 'sched-legend')
1802
+ for (const [kind, text] of [
1803
+ ['running', '在跑'],
1804
+ ['waiting', '等前一步'],
1805
+ ['completed', '完成'],
1806
+ ['failed', '失败'],
1807
+ ]) {
1808
+ const item = el('span')
1809
+ const dot = el('i')
1810
+ dot.style.background = kind === 'running' ? 'var(--amber)'
1811
+ : kind === 'completed' ? 'var(--green)'
1812
+ : kind === 'failed' ? 'var(--red)' : 'transparent'
1813
+ if (kind === 'waiting') dot.style.border = '1px dashed rgba(246, 193, 119, .55)'
1814
+ item.append(dot, document.createTextNode(text))
1815
+ legend.append(item)
1816
+ }
1817
+ box.append(legend)
1818
+ return box
1819
+ }
1820
+
1821
+ /** One board for every line the host is still working on. */
1822
+ function renderSchedule() {
1823
+ const runs = STATE.runs.filter(run => !isTerminal(run.status))
1824
+ if (runs.length === 0) {
1825
+ scheduleWrapEl.hidden = true
1826
+ if (STATE.scheduleSig !== '') {
1827
+ STATE.scheduleSig = ''
1828
+ scheduleWrapEl.replaceChildren()
1829
+ }
1830
+ return
1831
+ }
1832
+ const signature = runs.map(run => [
1833
+ run.id, laneSignature(run), run.queue?.position ?? '', run.queue?.waiting ? 'queued' : '',
1834
+ ].join(':')).join('#')
1835
+ if (signature === STATE.scheduleSig) return
1836
+ STATE.scheduleSig = signature
1837
+ scheduleWrapEl.hidden = false
1838
+ scheduleWrapEl.replaceChildren(scheduleElement(runs))
1839
+ }
1840
+
1841
+ /** Running bars grow with the clock between run frames. */
1842
+ function tickSchedule() {
1843
+ const now = Date.now()
1844
+ for (const box of document.querySelectorAll('.sched')) {
1845
+ const start = Number(box.dataset.axisStart)
1846
+ if (!Number.isFinite(start)) continue
1847
+ for (const bar of box.querySelectorAll('.sched-bar[data-start]')) {
1848
+ const began = Number(bar.dataset.start)
1849
+ if (!Number.isFinite(began)) continue
1850
+ const span = Math.max(1000, now - start)
1851
+ const left = Math.max(0, Math.min(99, ((began - start) / span) * 100))
1852
+ const width = Math.max(1.2, Math.min(100 - left, ((now - began) / span) * 100))
1853
+ bar.style.left = `${left}%`
1854
+ bar.style.width = `${width}%`
1855
+ }
1856
+ const label = box.querySelector('.sched-axis')
1857
+ if (label && box.dataset.live === '1') label.textContent = formatClock(now - start)
1858
+ }
1859
+ }
1860
+
1314
1861
  function syncStopAll() {
1315
1862
  const active = STATE.runs.filter(run => !isTerminal(run.status))
1316
1863
  stopAllEl.hidden = active.length === 0
1317
1864
  stopAllEl.disabled = STATE.mode !== 'chat' || active.length === 0 || STATE.stopAllBusy
1318
- stopAllEl.textContent = STATE.stopAllBusy ? '正在停止…' : '停止这一轮'
1865
+ stopAllEl.textContent = STATE.stopAllBusy ? '停止中…' : '停止这一轮'
1319
1866
  }
1320
1867
 
1321
1868
  async function stopRun(runId) {
@@ -1360,17 +1907,17 @@
1360
1907
  function currentAction(run) {
1361
1908
  const subtasks = Array.isArray(run.subtasks) ? run.subtasks : []
1362
1909
  if (STATE.cancelRequested.has(run.id) && !isTerminal(run.status)) return '已请求停止,等宿主确认'
1363
- if (run.status === 'queued') return '排队,等前一条任务线让出位置'
1364
- if (run.status === 'planning') return '正在拆步骤'
1365
- if (run.status === 'aggregating') return '正在汇总各步骤的结果'
1910
+ if (run.status === 'queued') return '排队,等前面的任务线跑完'
1911
+ if (run.status === 'planning') return '拆分步骤中'
1912
+ if (run.status === 'aggregating') return '汇总各步骤的结果'
1366
1913
  if (run.status === 'completed') return '已交付,产物见汇总'
1367
1914
  if (isTerminal(run.status)) return run.status === 'cancelled' ? '已取消' : '没走通,原因见汇总'
1368
1915
  const running = subtasks.filter(subtask => subtask.status === 'running')
1369
1916
  if (running.length > 1) return `同时推进 ${running.length} 个步骤`
1370
- if (running.length === 1) return `正在做:${stepLabel(running[0])}`
1917
+ if (running.length === 1) return `正在做 ${stepLabel(running[0])}`
1371
1918
  const next = subtasks.find(subtask => subtask.status !== 'completed' && subtask.status !== 'failed')
1372
- if (next) return `准备:${stepLabel(next)}`
1373
- return '正在推进'
1919
+ if (next) return `接下来 ${stepLabel(next)}`
1920
+ return '进行中'
1374
1921
  }
1375
1922
 
1376
1923
  /** Tools the running steps report right now; empty when unknown, never guessed. */
@@ -1383,12 +1930,20 @@
1383
1930
 
1384
1931
  function laneSignature(run) {
1385
1932
  const steps = Array.isArray(run.subtasks)
1386
- ? run.subtasks.map(subtask => `${subtask.status}:${subtask.title}:${subtask.tool || ''}`).join(',')
1933
+ ? run.subtasks.map(subtask => [
1934
+ subtask.status, subtask.key || '', subtask.title, subtask.tool || '',
1935
+ subtask.startedAt || '', subtask.finishedAt || '',
1936
+ (subtask.waitingOn || []).join('.'), (subtask.dependsOn || []).join('.'),
1937
+ ].join(':')).join(',')
1387
1938
  : ''
1388
1939
  const attention = Array.isArray(run.attention)
1389
1940
  ? run.attention.map(item => `${item.id}:${item.question}`).join(',')
1390
1941
  : ''
1391
- return [run.status, steps, attention, run.report ? run.report.length : 0, run.finishedAt || '', STATE.cancelRequested.has(run.id) ? 'stopping' : ''].join('|')
1942
+ return [
1943
+ run.status, steps, attention, run.report ? run.report.length : 0, run.finishedAt || '',
1944
+ STATE.cancelRequested.has(run.id) ? 'stopping' : '',
1945
+ run.limits?.maxParallel ?? '', run.queue?.position ?? '', run.queue?.waiting ? 'queued' : '',
1946
+ ].join('|')
1392
1947
  }
1393
1948
 
1394
1949
  /**
@@ -1660,7 +2215,7 @@
1660
2215
  const done = runs.every(run => isTerminal(run.status))
1661
2216
  const head = el('div', `lane-group-head${done ? ' done' : ''}`)
1662
2217
  head.append(el('span', 'dot'))
1663
- head.append(el('span', '', done ? `这一轮完成 · ${runs.length} 条任务线` : `推进中 · ${runs.length} 条任务线`))
2218
+ head.append(el('span', '', done ? `这一轮完成 · ${runs.length} 条任务线` : `进行中 · ${runs.length} 条任务线`))
1664
2219
  node.append(head)
1665
2220
  for (const run of runs) node.append(laneElement(run))
1666
2221
  if (done) node.append(summaryElement(runs))
@@ -1702,6 +2257,7 @@
1702
2257
  if (!run || isTerminal(run.status)) STATE.cancelRequested.delete(id)
1703
2258
  }
1704
2259
  syncStopAll()
2260
+ renderSchedule()
1705
2261
  renderHistory()
1706
2262
  }
1707
2263
 
@@ -1745,7 +2301,7 @@
1745
2301
  if (historyDrawerEl.hidden) return
1746
2302
  historyListEl.replaceChildren()
1747
2303
  if (STATE.sessionsBusy && STATE.sessions.length === 0) {
1748
- historyListEl.append(el('p', 'adv-note', '正在读取对话…'))
2304
+ historyListEl.append(el('p', 'adv-note', '读取中…'))
1749
2305
  return
1750
2306
  }
1751
2307
  if (STATE.sessionNote) {
@@ -1887,7 +2443,7 @@
1887
2443
  const failed = runs.filter(run => isTerminal(run.status) && run.status !== 'completed')
1888
2444
  const box = el('div', `summary${failed.length > 0 ? ' bad' : ''}`)
1889
2445
  box.append(el('div', 'st', failed.length > 0
1890
- ? `完成,${failed.length} 条任务线没走通`
2446
+ ? `完成 · ${failed.length} 条任务线失败`
1891
2447
  : `全部完成 · ${runs.length} 条任务线`))
1892
2448
 
1893
2449
  const first = runs.map(run => Date.parse(run.createdAt)).filter(Number.isFinite).sort((a, b) => a - b)[0]
@@ -1911,7 +2467,7 @@
1911
2467
  for (const item of artifacts) list.append(artifactElement(item))
1912
2468
  box.append(list)
1913
2469
  } else {
1914
- box.append(el('div', 'sd', '这次没有可以点开的产物;完整汇总在下面。'))
2470
+ box.append(el('div', 'sd', '这次没有能点开的产物,完整汇总在下面。'))
1915
2471
  }
1916
2472
 
1917
2473
  const details = el('details', 'report')
@@ -1919,7 +2475,7 @@
1919
2475
  for (const run of runs) {
1920
2476
  const block = el('div', 'sum-run')
1921
2477
  block.append(el('div', 'sum-run-title', `${run.goal || '任务线'} · ${laneStatusText(run)}`))
1922
- block.append(el('pre', '', run.report || '(这条任务线没有返回报告)'))
2478
+ block.append(el('pre', '', run.report || '(这条任务线没有报告)'))
1923
2479
  details.append(block)
1924
2480
  }
1925
2481
  box.append(details)
@@ -1933,7 +2489,7 @@
1933
2489
  function attentionElement(run, item) {
1934
2490
  const card = el('div', 'attention-card')
1935
2491
  card.append(el('div', 'kicker', '需要你决定'))
1936
- card.append(el('p', '', item.question || '运行中的任务在等一个决定'))
2492
+ card.append(el('p', '', item.question || '任务在等一个决定'))
1937
2493
  if (item.reason) card.append(el('p', 'reason', item.reason))
1938
2494
 
1939
2495
  const key = draftKey(run.id, item.id)
@@ -1989,7 +2545,7 @@
1989
2545
  body: { sessionId: STATE.sessionId, runId, attentionId, answer },
1990
2546
  })
1991
2547
  STATE.drafts.delete(key)
1992
- pushToast('决定已提交,任务线会在下一个边界应用。', 'ok')
2548
+ pushToast('已提交。任务线会在下一步用上这个决定。', 'ok')
1993
2549
  } catch (error) {
1994
2550
  pushToast(`提交失败:${messageOf(error)}`, 'err')
1995
2551
  } finally {
@@ -2068,7 +2624,7 @@
2068
2624
  }
2069
2625
  const tool = `${approval.toolName || ''}`.toLowerCase()
2070
2626
  const clip = value => (value.length > CALL_PREVIEW_LIMIT
2071
- ? { text: `${value.slice(0, CALL_PREVIEW_LIMIT)}\n…`, note: `共 ${value.length} 字符,这里先看前 ${CALL_PREVIEW_LIMIT} 字符。` }
2627
+ ? { text: `${value.slice(0, CALL_PREVIEW_LIMIT)}\n…`, note: `共 ${value.length} 字符,这里显示前 ${CALL_PREVIEW_LIMIT} 字符。` }
2072
2628
  : { text: value, note: '' })
2073
2629
  if (/write|edit|patch|apply|create|append/.test(tool)) {
2074
2630
  const body = pick('content', 'contents', 'text', 'new_string', 'newText', 'patch', 'diff')
@@ -2093,7 +2649,7 @@
2093
2649
  const target = approvalTarget(approval)
2094
2650
  if (target) card.append(el('div', 'where', `要动的位置:${target}`))
2095
2651
  const reason = approval.displayReason?.zh || approval.reason
2096
- card.append(el('p', 'why', reason || '宿主的工具调用被拦住了,需要你明确决定这一次。'))
2652
+ card.append(el('p', 'why', reason || '宿主拦住了这次工具调用,需要你决定。'))
2097
2653
  const preview = approvalCallPreview(approval)
2098
2654
  if (preview) {
2099
2655
  const details = el('details', 'call')
@@ -2133,8 +2689,8 @@
2133
2689
  const left = expiresAt - Date.now()
2134
2690
  node.classList.toggle('soon', left > 0 && left <= 60_000)
2135
2691
  node.classList.toggle('over', left <= 0)
2136
- if (left <= 0) node.textContent = `已超过有效期(${timeLabel(expiresAt)}),宿主会按拒绝处理;再发起会重新询问。`
2137
- else node.textContent = `剩余有效时间 ${formatClock(left)}(约到 ${timeLabel(expiresAt)})`
2692
+ if (left <= 0) node.textContent = `已过有效期(${timeLabel(expiresAt)}),宿主按拒绝处理。再发起会重新询问。`
2693
+ else node.textContent = `还剩 ${formatClock(left)}(约到 ${timeLabel(expiresAt)})`
2138
2694
  }
2139
2695
 
2140
2696
  function updateApprovalClocks() {
@@ -2146,8 +2702,8 @@
2146
2702
  entry.node.querySelector('.options')?.remove()
2147
2703
  const state = entry.node.querySelector('.state')
2148
2704
  if (!state) return
2149
- if (entry.decided === 'allow') state.textContent = '已允许这一次(只对这一条调用生效)'
2150
- else if (entry.decided === 'allow-tool') state.textContent = `已允许,并在本会话内放行 ${entry.approval?.toolName || '这个工具'}(换对话后恢复询问)`
2705
+ if (entry.decided === 'allow') state.textContent = '已允许这一次。只对这一条调用生效。'
2706
+ else if (entry.decided === 'allow-tool') state.textContent = `已允许,本会话内 ${entry.approval?.toolName || '这个工具'} 不再询问;换对话后恢复。`
2151
2707
  else if (entry.decided === 'reject') state.textContent = '已拒绝'
2152
2708
  else if (entry.decided === 'expired') state.textContent = '已过有效期,宿主按拒绝处理'
2153
2709
  else if (entry.decided === 'cancelled') state.textContent = '没有回答,按拒绝处理'
@@ -2189,22 +2745,22 @@
2189
2745
  if (!entry || entry.decided) return
2190
2746
  const state = entry.node.querySelector('.state')
2191
2747
  for (const button of entry.node.querySelectorAll('button')) button.disabled = true
2192
- const pending = { allow: '正在允许这一次…', 'allow-tool': '正在允许这个工具…', reject: '正在拒绝…' }
2193
- if (state) state.textContent = pending[decision] || '正在提交…'
2748
+ const pending = { allow: '允许中…', 'allow-tool': '放行中…', reject: '拒绝中…' }
2749
+ if (state) state.textContent = pending[decision] || '提交中…'
2194
2750
  try {
2195
2751
  await api('/api/console/approval', { method: 'POST', body: { id, decision } })
2196
2752
  entry.decided = decision
2197
2753
  settleApprovalNode(entry)
2198
2754
  const done = {
2199
- allow: '已允许这一次;只对这一条调用生效。',
2200
- 'allow-tool': '已允许:本会话内同一个工具不再询问(换对话后恢复)。',
2755
+ allow: '已允许这一次,只对这一条调用生效。',
2756
+ 'allow-tool': '已允许。本会话内这个工具不再询问,换对话后恢复。',
2201
2757
  reject: '已拒绝这一条调用。',
2202
2758
  }
2203
2759
  pushToast(done[decision] || '已提交。', 'ok')
2204
2760
  } catch (error) {
2205
2761
  for (const button of entry.node.querySelectorAll('button')) button.disabled = false
2206
- if (state) state.textContent = `没有提交成功:${messageOf(error)}`
2207
- pushToast(`审批没有提交成功:${messageOf(error)}`, 'err')
2762
+ if (state) state.textContent = `提交失败:${messageOf(error)}`
2763
+ pushToast(`审批没提交上:${messageOf(error)}`, 'err')
2208
2764
  }
2209
2765
  }
2210
2766
 
@@ -2224,7 +2780,7 @@
2224
2780
  if (data.report) renderMarkdownInto(dialogReportEl, data.report)
2225
2781
  else {
2226
2782
  dialogReportEl.textContent = ''
2227
- dialogReportEl.append(el('p', '', '(这个 run 还没有报告)'))
2783
+ dialogReportEl.append(el('p', '', '(这条任务线还没有报告)'))
2228
2784
  }
2229
2785
  reportDialogEl.showModal()
2230
2786
  } catch (error) {
@@ -2285,9 +2841,10 @@
2285
2841
  const approval = frame.approval
2286
2842
  if (frame.action === 'asked' && approval && approval.id) {
2287
2843
  seatApproval(approval)
2288
- pushToast('有一个工具调用在等你决定。', 'warn')
2844
+ refreshNotices({ toastNew: true })
2845
+ pushToast('有工具调用等你决定。', 'warn')
2289
2846
  } else if (frame.action === 'auto') {
2290
- pushToast(`已按本会话的许可放行 ${frame.toolName || '这个工具'},没有再打断你。`, 'ok')
2847
+ pushToast(`已放行 ${frame.toolName || '这个工具'},本会话内不再询问。`, 'ok')
2291
2848
  } else if ((frame.action === 'decided' || frame.action === 'expired') && frame.id) {
2292
2849
  const entry = STATE.approvals.get(frame.id)
2293
2850
  if (entry) {
@@ -2297,6 +2854,7 @@
2297
2854
  : frame.outcome === 'allowed-once' ? 'allow'
2298
2855
  : frame.outcome === 'rejected' ? 'reject' : 'cancelled'
2299
2856
  settleApprovalNode(entry)
2857
+ refreshNotices()
2300
2858
  }
2301
2859
  }
2302
2860
  break
@@ -2304,6 +2862,7 @@
2304
2862
  case 'runs':
2305
2863
  STATE.runs = Array.isArray(frame.runs) ? frame.runs : []
2306
2864
  renderLanes()
2865
+ refreshNotices({ toastNew: true })
2307
2866
  break
2308
2867
  case 'answered':
2309
2868
  pushToast(`已提交 ${frame.attentionId || '决定'}。`, 'ok')
@@ -2318,10 +2877,10 @@
2318
2877
  if (frame.code === 'follow-failed' || frame.code === 'state-failed') {
2319
2878
  setConn('warn', '流中断')
2320
2879
  }
2321
- pushToast(frame.message || '控制台流发生错误', 'err')
2880
+ pushToast(frame.message || '控制台连接出错', 'err')
2322
2881
  break
2323
2882
  case 'truncated':
2324
- pushToast('有一段历史过大,已截断显示。', 'err')
2883
+ pushToast('历史太长,只显示了一部分。', 'err')
2325
2884
  break
2326
2885
  case 'closed':
2327
2886
  setConn('warn', '已关闭')
@@ -2539,8 +3098,10 @@
2539
3098
  if (data.sessionId) setSession(data.sessionId)
2540
3099
  if (data.preset) STATE.preset = data.preset
2541
3100
  STATE.runs = Array.isArray(data.runs) ? data.runs : []
3101
+ STATE.readNotices = new Set(Array.isArray(data.readNoticeIds) ? data.readNoticeIds : [])
2542
3102
  renderLanes()
2543
3103
  for (const approval of Array.isArray(data.approvals) ? data.approvals : []) seatApproval(approval)
3104
+ refreshNotices()
2544
3105
  if (STATE.messages.length === 0) renderEmpty()
2545
3106
  loadTools()
2546
3107
  wizardLoad({ probe: false, auto: true })
@@ -2633,7 +3194,7 @@
2633
3194
  chip.append(el('span', 'dot'))
2634
3195
  chip.append(el('span', '', item.label))
2635
3196
  chip.append(el('span', 'env-value', item.value || ''))
2636
- chip.append(el('span', 'env-action', '点这里处理'))
3197
+ chip.append(el('span', 'env-action', '去处理'))
2637
3198
  chip.addEventListener('click', () => wizardOpen(item.action?.step || 1))
2638
3199
  envItemsEl.append(chip)
2639
3200
  }
@@ -2747,9 +3308,9 @@
2747
3308
  }
2748
3309
 
2749
3310
  function renderWizardStep1() {
2750
- wizardBodyEl.append(el('p', 'wiz-lead', '先看看宿主和环境是否准备好了。不通过的项可以直接点“点这里处理”,不需要读错误码。'))
3311
+ wizardBodyEl.append(el('p', 'wiz-lead', '先检查宿主和环境。没通过的项直接点“去处理”。'))
2751
3312
  if (!WIZ.status) {
2752
- wizardBodyEl.append(WIZ.statusPending > 0 ? wizardBusyNode('正在检查环境…') : el('p', 'wiz-note', '还没有读到检查结果。'))
3313
+ wizardBodyEl.append(WIZ.statusPending > 0 ? wizardBusyNode('检查中…') : el('p', 'wiz-note', '还没有读到检查结果。'))
2753
3314
  } else {
2754
3315
  const list = el('div', 'wiz-checks')
2755
3316
  for (const item of WIZ.status.environment || []) {
@@ -2762,7 +3323,7 @@
2762
3323
  if (item.hint) body.append(el('div', 'hint', item.hint))
2763
3324
  row.append(body)
2764
3325
  if (!item.ok && item.action) {
2765
- const button = el('button', '', '点这里处理')
3326
+ const button = el('button', '', '去处理')
2766
3327
  button.type = 'button'
2767
3328
  button.addEventListener('click', () => wizardHandleAction(item.action))
2768
3329
  row.append(button)
@@ -2771,7 +3332,7 @@
2771
3332
  }
2772
3333
  wizardBodyEl.append(list)
2773
3334
  if (WIZ.status.profile?.patchPath) {
2774
- wizardBodyEl.append(el('p', 'wiz-note', `配置文件:${WIZ.status.profile.patchPath}。写入前会自动备份,失败可以一键回滚。`))
3335
+ wizardBodyEl.append(el('p', 'wiz-note', `配置文件:${WIZ.status.profile.patchPath}。写入前会备份,出问题可以回滚。`))
2775
3336
  }
2776
3337
  }
2777
3338
  const error = wizardErrorNode()
@@ -2813,7 +3374,7 @@
2813
3374
 
2814
3375
  function renderWizardStep2() {
2815
3376
  const status = WIZ.status
2816
- wizardBodyEl.append(el('p', 'wiz-lead', '填你的 OpenAI 兼容端点。默认值已经填好,通常只需要粘贴 key。'))
3377
+ wizardBodyEl.append(el('p', 'wiz-lead', '填 OpenAI 兼容端点。默认值已经填好,一般只要粘贴 key。'))
2817
3378
  const form = el('div', 'wiz-form')
2818
3379
  form.append(wizardField('provider', '提供商名', 'text', 'haoduo', '小写字母、数字、短横线,会作为配置里的提供方 id。'))
2819
3380
  form.append(wizardField('baseURL', 'Base URL', 'text', 'https://byte.haoduotoken.com/v1', 'OpenAI 兼容端点,通常以 /v1 结尾。'))
@@ -2831,7 +3392,7 @@
2831
3392
  input.value = WIZ.form.apiKey ?? ''
2832
3393
  input.placeholder = status?.key?.configured
2833
3394
  ? `已保存 ${status.key.mask || '(内容不可回读)'},留空则沿用`
2834
- : '粘贴你的 API key'
3395
+ : '粘贴 API key'
2835
3396
  input.addEventListener('input', () => {
2836
3397
  WIZ.form.apiKey = input.value
2837
3398
  WIZ.formTouched = true
@@ -2842,7 +3403,7 @@
2842
3403
  badge.id = 'wizKeyBadge'
2843
3404
  row.append(input, badge)
2844
3405
  keyWrap.append(labelEl, row)
2845
- keyWrap.append(el('div', 'wiz-note', 'key 只写入宿主凭据库(或你已有的用户环境变量);不会写进仓库、配置或日志,页面不显示完整值。'))
3406
+ keyWrap.append(el('div', 'wiz-note', 'key 只写入宿主凭据库(或你已有的用户环境变量),不写进仓库、配置和日志,页面也不显示完整值。'))
2846
3407
  form.append(keyWrap)
2847
3408
  wizardBodyEl.append(form)
2848
3409
 
@@ -2886,7 +3447,7 @@
2886
3447
  function renderWizardStep3() {
2887
3448
  const preview = WIZ.preview
2888
3449
  if (!preview) {
2889
- wizardBodyEl.append(el('p', 'wiz-note', '先回到上一步做一次检查。'))
3450
+ wizardBodyEl.append(el('p', 'wiz-note', '回到上一步检查一次。'))
2890
3451
  wizardFootEl.replaceChildren()
2891
3452
  const back = el('button', 'wiz-secondary', '返回')
2892
3453
  back.type = 'button'
@@ -2894,7 +3455,7 @@
2894
3455
  wizardFootEl.append(back)
2895
3456
  return
2896
3457
  }
2897
- wizardBodyEl.append(el('p', 'wiz-lead', '这是将要写入的摘要。你不需要看 YAML;写入前会自动备份,失败可以一键回滚。'))
3458
+ wizardBodyEl.append(el('p', 'wiz-lead', '这是要写入的内容。不用看 YAML;写入前会备份,出问题可以回滚。'))
2898
3459
  const list = el('ul', 'wiz-summary')
2899
3460
  for (const line of preview.summary || []) list.append(el('li', '', line))
2900
3461
  wizardBodyEl.append(list)
@@ -2910,12 +3471,12 @@
2910
3471
  add('模型', preview.model)
2911
3472
  add('key', `${preview.key.mask || '沿用已保存的 key'}(引用 ${preview.key.ref})`)
2912
3473
  add('配置文件', preview.target.patchPath)
2913
- add('备份', '写入前保存;可在下一步点“回滚上次写入”恢复')
3474
+ add('备份', '写入前保存,下一步可以回滚')
2914
3475
  wizardBodyEl.append(kv)
2915
3476
 
2916
3477
  const error = wizardErrorNode()
2917
3478
  if (error) wizardBodyEl.append(error)
2918
- if (WIZ.busy === 'save') wizardBodyEl.append(wizardBusyNode('正在写入配置并保存 key…'))
3479
+ if (WIZ.busy === 'save') wizardBodyEl.append(wizardBusyNode('写入中…'))
2919
3480
  wizardBodyEl.append(el('p', 'wiz-note', preview.note || ''))
2920
3481
 
2921
3482
  wizardFootEl.replaceChildren()
@@ -2968,7 +3529,7 @@
2968
3529
  function renderWizardStep4() {
2969
3530
  const trial = WIZ.trial
2970
3531
  if (WIZ.busy === 'trial') {
2971
- wizardBodyEl.append(wizardBusyNode('正在临时目录里跑一个小任务(建文件并读回)…'))
3532
+ wizardBodyEl.append(wizardBusyNode('在临时目录建一个文件再读回来…'))
2972
3533
  wizardBodyEl.append(el('p', 'wiz-note', '不会碰你的项目目录。模型回复和工具调用会显示在下面。'))
2973
3534
  wizardFootEl.replaceChildren()
2974
3535
  const again = el('button', 'wiz-secondary', '试跑中…')
@@ -2979,7 +3540,7 @@
2979
3540
  }
2980
3541
 
2981
3542
  if (!trial) {
2982
- wizardBodyEl.append(el('p', 'wiz-lead', '最后一步:在系统临时目录里建一个文件并读回。它不会碰你的真实项目。'))
3543
+ wizardBodyEl.append(el('p', 'wiz-lead', '最后一步:在系统临时目录建一个文件再读回来,不碰你的项目。'))
2983
3544
  if (WIZ.saved) {
2984
3545
  const kv = el('div', 'wiz-kv')
2985
3546
  const add = (label, value) => {
@@ -3009,12 +3570,12 @@
3009
3570
  verdict.append(el('span', 'big', trial.ok ? '✓' : '!'))
3010
3571
  const text = el('div')
3011
3572
  text.append(el('div', 't', trial.ok
3012
- ? '试跑成功:它真的在临时目录里干了活。'
3573
+ ? '试跑通过:文件建好,也读回来了。'
3013
3574
  : (emptyRun ? '试跑没有跑起来' : '试跑没有完全成功')))
3014
3575
  text.append(el('div', 'd', trial.ok
3015
3576
  ? `用时 ${(trial.elapsedMs / 1000).toFixed(1)} 秒 · 会话 ${shortId(trial.sessionId)}`
3016
3577
  : (emptyRun
3017
- ? '这一轮没有模型回复。宿主可能还没切换到新模型,点“重新试跑”再来一次。'
3578
+ ? '这一轮没有模型回复。宿主可能还没换到新模型,点“重新试跑”再试。'
3018
3579
  : (trial.hint || '看下面的步骤和提示。'))))
3019
3580
  verdict.append(text)
3020
3581
  wizardBodyEl.append(verdict)
@@ -3097,13 +3658,13 @@
3097
3658
  try {
3098
3659
  const data = await api('/api/console/wizard/trial', { method: 'POST', body: {} })
3099
3660
  WIZ.trial = data
3100
- if (data.ok) pushToast('试跑成功:它真的在临时目录里干了活。', 'ok')
3661
+ if (data.ok) pushToast('试跑通过:文件建好,也读回来了。', 'ok')
3101
3662
  else pushToast('试跑没成功,按提示处理。', 'err')
3102
3663
  await wizardLoad({ probe: false })
3103
3664
  } catch (error) {
3104
3665
  WIZ.error = {
3105
3666
  message: messageOf(error),
3106
- hint: error.hint || (!error.status ? '宿主可能正在热加载配置,等两秒再点一次“开始试跑”。' : null),
3667
+ hint: error.hint || (!error.status ? '宿主可能在热加载配置,等两秒再点“开始试跑”。' : null),
3107
3668
  code: error.code,
3108
3669
  }
3109
3670
  } finally {
@@ -3145,7 +3706,7 @@
3145
3706
  else setConn('warn', '未连接')
3146
3707
  } catch (error) {
3147
3708
  if (error.status === 401) {
3148
- showGate('令牌无效或已轮换,请重新读取 console.json。')
3709
+ showGate('token 无效或已换新,重新读一次 console.json。')
3149
3710
  return
3150
3711
  }
3151
3712
  setMode('unavailable', { chat: false, reason: `${messageOf(error)}${error.hint ? `\n${error.hint}` : ''}` })
@@ -3204,7 +3765,7 @@
3204
3765
  } catch (error) {
3205
3766
  if (controller.signal.aborted) return
3206
3767
  if (error.status === 401) {
3207
- showGate('令牌无效或已轮换,请重新读取 console.json。')
3768
+ showGate('token 无效或已换新,重新读一次 console.json。')
3208
3769
  return
3209
3770
  }
3210
3771
  setConn('warn', '重连中')
@@ -3262,6 +3823,7 @@
3262
3823
  clearMessages()
3263
3824
  STATE.runs = []
3264
3825
  renderLanes()
3826
+ refreshNotices()
3265
3827
  renderEmpty()
3266
3828
  renderTools(null)
3267
3829
  loadTools()
@@ -3352,6 +3914,50 @@
3352
3914
  sendMessage()
3353
3915
  })
3354
3916
 
3917
+ // A file can be dropped anywhere on the composer, or pasted into the text
3918
+ // box; both end up copied into the conversation's workspace, with the path
3919
+ // written into the message so the agent can read it.
3920
+ for (const type of ['dragenter', 'dragover']) {
3921
+ composerEl.addEventListener(type, event => {
3922
+ if (!dragHasFiles(event)) return
3923
+ event.preventDefault()
3924
+ if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy'
3925
+ STATE.dragDepth += 1
3926
+ composerEl.classList.add('dragover')
3927
+ })
3928
+ }
3929
+ composerEl.addEventListener('dragleave', () => {
3930
+ STATE.dragDepth = Math.max(0, STATE.dragDepth - 1)
3931
+ if (STATE.dragDepth === 0) composerEl.classList.remove('dragover')
3932
+ })
3933
+ composerEl.addEventListener('drop', event => {
3934
+ if (!dragHasFiles(event)) return
3935
+ event.preventDefault()
3936
+ STATE.dragDepth = 0
3937
+ composerEl.classList.remove('dragover')
3938
+ uploadFiles(event.dataTransfer ? event.dataTransfer.files : null)
3939
+ })
3940
+ inputEl.addEventListener('paste', event => {
3941
+ const files = event.clipboardData ? event.clipboardData.files : null
3942
+ if (!files || files.length === 0) return
3943
+ event.preventDefault()
3944
+ uploadFiles(files)
3945
+ })
3946
+
3947
+ noticeOpenEl.addEventListener('click', event => {
3948
+ event.stopPropagation()
3949
+ if (STATE.noticeOpen) closeNoticePanel()
3950
+ else openNoticePanel()
3951
+ })
3952
+ $('noticeReadAll').addEventListener('click', event => {
3953
+ event.stopPropagation()
3954
+ markNoticesRead(STATE.notices.map(notice => notice.id))
3955
+ })
3956
+ noticePanelEl.addEventListener('click', event => event.stopPropagation())
3957
+ document.addEventListener('click', () => {
3958
+ if (STATE.noticeOpen) closeNoticePanel()
3959
+ })
3960
+
3355
3961
  for (const button of document.querySelectorAll('.segmented button')) {
3356
3962
  button.addEventListener('click', () => {
3357
3963
  STATE.sendMode = button.dataset.mode === 'steer' ? 'steer' : 'queue'
@@ -3365,6 +3971,7 @@
3365
3971
  stopAllEl.addEventListener('click', stopAllRuns)
3366
3972
  setInterval(() => {
3367
3973
  tickLaneClocks()
3974
+ tickSchedule()
3368
3975
  updateApprovalClocks()
3369
3976
  }, 1000)
3370
3977
  $('historyOpen').addEventListener('click', () => drawerOpen('history'))