@xiangyixie/dsh-superagent 0.14.7 → 0.14.9
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.
- package/CHANGELOG.md +31 -0
- package/README.en.md +4 -4
- package/README.md +4 -4
- package/README.zh.md +4 -4
- package/lib/console.js +383 -9
- package/lib/index.js +266 -0
- package/lib/workbench.js +11 -2
- package/package.json +1 -1
- package/public/console.html +970 -65
package/public/console.html
CHANGED
|
@@ -87,6 +87,8 @@
|
|
|
87
87
|
}
|
|
88
88
|
.btn:hover { color: var(--text); border-color: #35464f; background: #172028; }
|
|
89
89
|
.btn:disabled { opacity: .45; cursor: default; }
|
|
90
|
+
.btn.danger { color: var(--red); border-color: rgba(255, 123, 114, .3); }
|
|
91
|
+
.btn.danger:hover { background: rgba(255, 123, 114, .08); border-color: rgba(255, 123, 114, .45); }
|
|
90
92
|
|
|
91
93
|
.panel {
|
|
92
94
|
min-height: 0; display: flex; flex-direction: column;
|
|
@@ -148,6 +150,14 @@
|
|
|
148
150
|
@keyframes caret { 50% { opacity: 0; } }
|
|
149
151
|
.msg .meta { margin: 5px 4px 0; color: var(--faint); font-size: 11px; }
|
|
150
152
|
.msg .meta .failed { color: var(--red); }
|
|
153
|
+
.msg-actions { display: flex; gap: 4px; margin: 5px 4px 0; }
|
|
154
|
+
.msg.user .msg-actions { justify-content: flex-end; }
|
|
155
|
+
.msg-actions[hidden] { display: none; }
|
|
156
|
+
.msg-actions button {
|
|
157
|
+
padding: 1px 4px; border: 0; border-radius: 5px; background: transparent;
|
|
158
|
+
color: var(--faint); font: 11px var(--sans); cursor: pointer;
|
|
159
|
+
}
|
|
160
|
+
.msg-actions button:hover { color: var(--text); background: rgba(255, 255, 255, .06); }
|
|
151
161
|
.reasoning { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 7px; }
|
|
152
162
|
.reasoning summary { color: var(--faint); font-size: 11px; cursor: pointer; }
|
|
153
163
|
.reasoning pre { margin: 6px 0 0; color: var(--muted); font: 12px/1.6 var(--mono); white-space: pre-wrap; }
|
|
@@ -292,6 +302,26 @@
|
|
|
292
302
|
}
|
|
293
303
|
.options button:hover { background: rgba(246, 193, 119, .18); }
|
|
294
304
|
.options button:disabled { opacity: .45; }
|
|
305
|
+
.approval-card .options button.allow-tool {
|
|
306
|
+
border-color: rgba(94, 234, 212, .38); background: rgba(94, 234, 212, .1); color: #c2efe7;
|
|
307
|
+
}
|
|
308
|
+
.approval-card .call { margin-top: 7px; }
|
|
309
|
+
.approval-card .call summary {
|
|
310
|
+
color: #cbb794; font-size: 11px; cursor: pointer; list-style: none;
|
|
311
|
+
}
|
|
312
|
+
.approval-card .call summary::-webkit-details-marker { display: none; }
|
|
313
|
+
.approval-card .call summary::before { content: '▸ '; }
|
|
314
|
+
.approval-card .call[open] summary::before { content: '▾ '; }
|
|
315
|
+
.approval-card .call pre {
|
|
316
|
+
max-height: 240px; overflow: auto; margin: 6px 0 0; padding: 8px 9px;
|
|
317
|
+
border-radius: 7px; border: 1px solid rgba(246, 193, 119, .22);
|
|
318
|
+
background: rgba(10, 15, 18, .62); color: #e9dcc4;
|
|
319
|
+
font: 11px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word;
|
|
320
|
+
}
|
|
321
|
+
.approval-card .call .note { margin: 5px 0 0; color: #b9a789; font-size: 10.5px; }
|
|
322
|
+
.approval-card .expiry { margin-top: 6px; color: #b9a789; font-size: 11px; }
|
|
323
|
+
.approval-card .expiry.soon { color: var(--amber); }
|
|
324
|
+
.approval-card .expiry.over { color: var(--red); }
|
|
295
325
|
.free { display: flex; gap: 6px; margin-top: 7px; }
|
|
296
326
|
.free input {
|
|
297
327
|
flex: 1; min-width: 0; height: 29px; padding: 0 8px;
|
|
@@ -451,6 +481,41 @@
|
|
|
451
481
|
}
|
|
452
482
|
.toast.err { border-color: rgba(255, 123, 114, .4); color: #ffc0bb; }
|
|
453
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
|
+
}
|
|
454
519
|
|
|
455
520
|
.gate {
|
|
456
521
|
position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
|
|
@@ -493,6 +558,26 @@
|
|
|
493
558
|
margin: 0; padding: 13px; border-radius: 9px; border: 1px solid var(--line-soft);
|
|
494
559
|
background: #0a0f12; font: 12px/1.65 var(--mono); white-space: pre-wrap; word-break: break-word;
|
|
495
560
|
}
|
|
561
|
+
.dialog-report { font-size: 12.5px; line-height: 1.7; }
|
|
562
|
+
.dialog-report h1, .dialog-report h2, .dialog-report h3, .dialog-report h4 {
|
|
563
|
+
margin: 16px 0 8px; font-size: 14px; line-height: 1.45; color: var(--text);
|
|
564
|
+
}
|
|
565
|
+
.dialog-report h1 { font-size: 17px; }
|
|
566
|
+
.dialog-report h2 { font-size: 15px; }
|
|
567
|
+
.dialog-report p { margin: 0 0 9px; }
|
|
568
|
+
.dialog-report ul, .dialog-report ol { margin: 0 0 10px; padding-left: 22px; }
|
|
569
|
+
.dialog-report li { margin: 3px 0; }
|
|
570
|
+
.dialog-report code {
|
|
571
|
+
padding: 1px 5px; border-radius: 5px; background: rgba(94, 234, 212, .1);
|
|
572
|
+
font: 11.5px var(--mono); color: var(--text);
|
|
573
|
+
}
|
|
574
|
+
.dialog-report pre { margin: 10px 0; }
|
|
575
|
+
.dialog-report pre code { padding: 0; background: transparent; font-size: 11.5px; }
|
|
576
|
+
.dialog-report a { color: var(--teal); }
|
|
577
|
+
.dialog-report iframe { width: 100%; height: min(62vh, 620px); border: 1px solid var(--line-soft); border-radius: 10px; background: #fff; }
|
|
578
|
+
.dialog-report .image-preview { max-width: 100%; border-radius: 10px; border: 1px solid var(--line-soft); }
|
|
579
|
+
.dialog-actions { display: flex; gap: 8px; margin-top: 14px; }
|
|
580
|
+
.dialog-actions .btn { text-decoration: none; }
|
|
496
581
|
|
|
497
582
|
/* ---- conversation-first stage ---- */
|
|
498
583
|
.stage { flex: 1; min-height: 0; display: flex; justify-content: center; padding: 0 18px 18px; }
|
|
@@ -523,6 +608,15 @@
|
|
|
523
608
|
.lane-goal { font-size: 12.5px; font-weight: 600; line-height: 1.45; word-break: break-word; }
|
|
524
609
|
.lane-now { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: var(--muted); font-size: 11px; }
|
|
525
610
|
.lane-now .spark { flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--amber); animation: blink 1.1s infinite; }
|
|
611
|
+
.lane-now .lane-tool { color: var(--faint); font-family: var(--mono); font-size: 10.5px; }
|
|
612
|
+
.lane-time { flex: none; padding-top: 1px; color: var(--faint); font: 10.5px var(--mono); white-space: nowrap; }
|
|
613
|
+
.lane-stop {
|
|
614
|
+
flex: none; height: 22px; padding: 0 9px; border-radius: 999px; cursor: pointer;
|
|
615
|
+
border: 1px solid rgba(255, 123, 114, .3); background: rgba(255, 123, 114, .06);
|
|
616
|
+
color: var(--red); font-size: 10.5px;
|
|
617
|
+
}
|
|
618
|
+
.lane-stop:hover { background: rgba(255, 123, 114, .13); }
|
|
619
|
+
.lane-stop:disabled { opacity: .55; cursor: default; }
|
|
526
620
|
.steps { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
|
|
527
621
|
.step { display: flex; align-items: flex-start; gap: 7px; color: var(--faint); font-size: 11px; line-height: 1.5; }
|
|
528
622
|
.step .sdot { flex: none; width: 6px; height: 6px; margin-top: 4px; border-radius: 50%; background: #3a4a55; }
|
|
@@ -544,7 +638,8 @@
|
|
|
544
638
|
.artifact {
|
|
545
639
|
display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
|
|
546
640
|
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;
|
|
641
|
+
border: 1px solid rgba(94, 234, 212, .3); background: rgba(94, 234, 212, .07); color: #bdf3e8;
|
|
642
|
+
font-size: 11.5px; font-family: inherit; text-align: left; cursor: pointer;
|
|
548
643
|
}
|
|
549
644
|
.artifact:hover { background: rgba(94, 234, 212, .14); }
|
|
550
645
|
.artifact .ak { color: var(--faint); font: 10px var(--mono); }
|
|
@@ -591,6 +686,8 @@
|
|
|
591
686
|
color: var(--text); text-align: left; cursor: pointer;
|
|
592
687
|
}
|
|
593
688
|
.hist-item:hover { border-color: #35464f; }
|
|
689
|
+
.hist-item.current { border-color: #3a5a52; background: #101b1a; cursor: default; }
|
|
690
|
+
.hist-state + .hist-state { margin-left: 6px; }
|
|
594
691
|
.hist-top { display: flex; align-items: center; gap: 8px; color: var(--faint); font-size: 10.5px; }
|
|
595
692
|
.hist-state { margin-left: auto; }
|
|
596
693
|
.hist-text { margin-top: 4px; font-size: 12px; line-height: 1.55; word-break: break-word; }
|
|
@@ -619,6 +716,9 @@
|
|
|
619
716
|
</div>
|
|
620
717
|
<div class="topbar-actions">
|
|
621
718
|
<span id="conn" class="conn"><i></i><span id="connText">连接中</span></span>
|
|
719
|
+
<button id="stopAll" class="btn danger" type="button" hidden>停止这一轮</button>
|
|
720
|
+
<button id="noticeOpen" class="btn notice-btn" type="button" hidden>提醒<span id="noticeCount" class="count">0</span></button>
|
|
721
|
+
<button id="newChatTop" class="btn" type="button" disabled>新对话</button>
|
|
622
722
|
<button id="historyOpen" class="btn" type="button">历史</button>
|
|
623
723
|
<button id="advancedOpen" class="btn" type="button">高级</button>
|
|
624
724
|
</div>
|
|
@@ -655,11 +755,19 @@
|
|
|
655
755
|
|
|
656
756
|
<div id="scrim" class="scrim" hidden></div>
|
|
657
757
|
|
|
758
|
+
<div id="noticePanel" class="notice-panel" hidden>
|
|
759
|
+
<div class="notice-head">
|
|
760
|
+
<span class="kicker">提醒</span>
|
|
761
|
+
<button id="noticeReadAll" class="btn tiny" type="button">全部已读</button>
|
|
762
|
+
</div>
|
|
763
|
+
<div id="noticeList" class="notice-list"></div>
|
|
764
|
+
</div>
|
|
765
|
+
|
|
658
766
|
<aside id="historyDrawer" class="drawer" hidden aria-label="历史">
|
|
659
767
|
<div class="drawer-head">
|
|
660
768
|
<div>
|
|
661
769
|
<span class="kicker">历史</span>
|
|
662
|
-
<h2
|
|
770
|
+
<h2>你的对话</h2>
|
|
663
771
|
</div>
|
|
664
772
|
<button class="drawer-close" data-close="history" type="button" aria-label="关闭">×</button>
|
|
665
773
|
</div>
|
|
@@ -679,7 +787,6 @@
|
|
|
679
787
|
<h3>会话</h3>
|
|
680
788
|
<div id="advSession" class="adv-kv"></div>
|
|
681
789
|
<div class="adv-actions">
|
|
682
|
-
<button id="newChat" class="btn tiny" type="button" disabled>开始新对话</button>
|
|
683
790
|
<button id="wizardOpen" class="btn tiny" type="button">首次使用向导</button>
|
|
684
791
|
</div>
|
|
685
792
|
</section>
|
|
@@ -737,7 +844,8 @@
|
|
|
737
844
|
</div>
|
|
738
845
|
<div class="dialog-body">
|
|
739
846
|
<div id="dialogMeta" class="dialog-meta"></div>
|
|
740
|
-
<
|
|
847
|
+
<div id="dialogReport" class="dialog-report"></div>
|
|
848
|
+
<div id="dialogActions" class="dialog-actions" hidden></div>
|
|
741
849
|
</div>
|
|
742
850
|
</dialog>
|
|
743
851
|
|
|
@@ -758,7 +866,8 @@
|
|
|
758
866
|
const sessionLabelEl = $('sessionLabel')
|
|
759
867
|
const connEl = $('conn')
|
|
760
868
|
const connTextEl = $('connText')
|
|
761
|
-
const newChatEl = $('
|
|
869
|
+
const newChatEl = $('newChatTop')
|
|
870
|
+
const stopAllEl = $('stopAll')
|
|
762
871
|
const gateEl = $('gate')
|
|
763
872
|
const gateFormEl = $('gateForm')
|
|
764
873
|
const gateErrorEl = $('gateError')
|
|
@@ -768,6 +877,7 @@
|
|
|
768
877
|
const dialogTitleEl = $('dialogTitle')
|
|
769
878
|
const dialogMetaEl = $('dialogMeta')
|
|
770
879
|
const dialogReportEl = $('dialogReport')
|
|
880
|
+
const dialogActionsEl = $('dialogActions')
|
|
771
881
|
const wizardDialogEl = $('wizardDialog')
|
|
772
882
|
const wizardStepsEl = $('wizardSteps')
|
|
773
883
|
const wizardBodyEl = $('wizardBody')
|
|
@@ -780,6 +890,23 @@
|
|
|
780
890
|
const advancedDrawerEl = $('advancedDrawer')
|
|
781
891
|
const advSessionEl = $('advSession')
|
|
782
892
|
const advRunsEl = $('advRuns')
|
|
893
|
+
const noticeOpenEl = $('noticeOpen')
|
|
894
|
+
const noticeCountEl = $('noticeCount')
|
|
895
|
+
const noticePanelEl = $('noticePanel')
|
|
896
|
+
const noticeListEl = $('noticeList')
|
|
897
|
+
|
|
898
|
+
// Upload rules mirror the server's: the page refuses early with a readable
|
|
899
|
+
// sentence, and the server refuses again because a page is not a gate.
|
|
900
|
+
const UPLOAD_MAX = 8 * 1024 * 1024
|
|
901
|
+
const UPLOAD_EXTS = new Set([
|
|
902
|
+
'.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.bmp',
|
|
903
|
+
'.pdf', '.md', '.markdown', '.txt', '.log', '.csv', '.tsv', '.json', '.yml', '.yaml', '.xml',
|
|
904
|
+
'.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.rtf',
|
|
905
|
+
'.zip', '.tar', '.gz', '.7z',
|
|
906
|
+
'.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.py', '.css', '.html', '.htm', '.sql', '.sh',
|
|
907
|
+
'.ps1', '.toml', '.ini', '.ipynb',
|
|
908
|
+
])
|
|
909
|
+
const UPLOAD_HINT = '图片、PDF、Markdown/文本、CSV/JSON、Office 文档、压缩包或代码文件'
|
|
783
910
|
|
|
784
911
|
const STATE = {
|
|
785
912
|
token: '',
|
|
@@ -807,6 +934,17 @@
|
|
|
807
934
|
runAnchors: new Map(),
|
|
808
935
|
attentionSeen: new Set(),
|
|
809
936
|
approvals: new Map(),
|
|
937
|
+
sessions: [],
|
|
938
|
+
sessionsLoadedAt: 0,
|
|
939
|
+
sessionsBusy: false,
|
|
940
|
+
sessionNote: null,
|
|
941
|
+
cancelRequested: new Set(),
|
|
942
|
+
stopAllBusy: false,
|
|
943
|
+
notices: [],
|
|
944
|
+
readNotices: new Set(),
|
|
945
|
+
noticeOpen: false,
|
|
946
|
+
noticesPrimed: false,
|
|
947
|
+
dragDepth: 0,
|
|
810
948
|
}
|
|
811
949
|
|
|
812
950
|
const WIZ = {
|
|
@@ -908,6 +1046,7 @@
|
|
|
908
1046
|
modeTextEl.textContent = chat ? '已就绪' : mode === 'loading' ? '连接中' : '未连接'
|
|
909
1047
|
newChatEl.disabled = !chat
|
|
910
1048
|
inputEl.disabled = !chat
|
|
1049
|
+
syncStopAll()
|
|
911
1050
|
updateSend()
|
|
912
1051
|
}
|
|
913
1052
|
|
|
@@ -987,15 +1126,82 @@
|
|
|
987
1126
|
if (message.failed) meta.append(el('span', 'failed', ' · 发送失败'))
|
|
988
1127
|
if (message.interrupted) meta.append(el('span', '', ' · 已中断'))
|
|
989
1128
|
|
|
990
|
-
|
|
1129
|
+
const actions = el('div', 'msg-actions')
|
|
1130
|
+
actions.hidden = !message.text
|
|
1131
|
+
if (message.role === 'assistant') {
|
|
1132
|
+
const copy = el('button', '', '复制')
|
|
1133
|
+
copy.type = 'button'
|
|
1134
|
+
copy.title = '复制这条回复的完整文本'
|
|
1135
|
+
copy.addEventListener('click', () => copyMessage(message, copy))
|
|
1136
|
+
actions.append(copy)
|
|
1137
|
+
} else {
|
|
1138
|
+
const edit = el('button', '', '编辑并重发')
|
|
1139
|
+
edit.type = 'button'
|
|
1140
|
+
edit.title = '把这条原文放回输入框,改完再发送'
|
|
1141
|
+
edit.addEventListener('click', () => editMessage(message))
|
|
1142
|
+
actions.append(edit)
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
article.append(who, bubble, meta, actions)
|
|
991
1146
|
message.el = article
|
|
992
1147
|
message.textEl = text
|
|
993
1148
|
message.bubbleEl = bubble
|
|
994
1149
|
message.toolsEl = tools
|
|
995
1150
|
message.metaEl = meta
|
|
1151
|
+
message.actionsEl = actions
|
|
996
1152
|
return article
|
|
997
1153
|
}
|
|
998
1154
|
|
|
1155
|
+
function formatTextOf(message) {
|
|
1156
|
+
return typeof message.text === 'string' ? message.text : ''
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
async function copyText(value) {
|
|
1160
|
+
const text = typeof value === 'string' ? value : ''
|
|
1161
|
+
if (!text) return false
|
|
1162
|
+
if (navigator.clipboard?.writeText) {
|
|
1163
|
+
try {
|
|
1164
|
+
await navigator.clipboard.writeText(text)
|
|
1165
|
+
return true
|
|
1166
|
+
} catch {
|
|
1167
|
+
// The page may not be a secure context; fall through to the old path.
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
const area = document.createElement('textarea')
|
|
1171
|
+
area.value = text
|
|
1172
|
+
area.setAttribute('readonly', '')
|
|
1173
|
+
area.style.position = 'fixed'
|
|
1174
|
+
area.style.top = '-1000px'
|
|
1175
|
+
document.body.append(area)
|
|
1176
|
+
area.select()
|
|
1177
|
+
let copied = false
|
|
1178
|
+
try { copied = document.execCommand('copy') } catch { copied = false }
|
|
1179
|
+
area.remove()
|
|
1180
|
+
return copied
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
async function copyMessage(message, button) {
|
|
1184
|
+
const copied = await copyText(formatTextOf(message))
|
|
1185
|
+
if (!copied) {
|
|
1186
|
+
pushToast('复制失败,可以手动选中文字。', 'err')
|
|
1187
|
+
return
|
|
1188
|
+
}
|
|
1189
|
+
pushToast('已复制这条回复。', 'ok')
|
|
1190
|
+
button.textContent = '已复制'
|
|
1191
|
+
setTimeout(() => { button.textContent = '复制' }, 1600)
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/** Put the original text back in the composer; sending stays the person's call. */
|
|
1195
|
+
function editMessage(message) {
|
|
1196
|
+
const text = formatTextOf(message)
|
|
1197
|
+
if (!text) return
|
|
1198
|
+
inputEl.value = text
|
|
1199
|
+
inputEl.dispatchEvent(new Event('input'))
|
|
1200
|
+
inputEl.focus()
|
|
1201
|
+
try { inputEl.setSelectionRange(text.length, text.length) } catch { /* not focusable yet */ }
|
|
1202
|
+
pushToast('原文已放回输入框,改完点发送。', 'ok')
|
|
1203
|
+
}
|
|
1204
|
+
|
|
999
1205
|
function summarizeArgs(value) {
|
|
1000
1206
|
if (value === undefined || value === null) return ''
|
|
1001
1207
|
let text
|
|
@@ -1038,6 +1244,7 @@
|
|
|
1038
1244
|
if (message.failed) message.metaEl.append(el('span', 'failed', ' · 发送失败'))
|
|
1039
1245
|
if (message.interrupted) message.metaEl.append(el('span', '', ' · 已中断'))
|
|
1040
1246
|
}
|
|
1247
|
+
if (message.actionsEl) message.actionsEl.hidden = !message.text
|
|
1041
1248
|
}
|
|
1042
1249
|
|
|
1043
1250
|
function addMessage(role, text, options = {}) {
|
|
@@ -1119,6 +1326,225 @@
|
|
|
1119
1326
|
inputEl.style.height = `${Math.min(180, Math.max(46, inputEl.scrollHeight))}px`
|
|
1120
1327
|
}
|
|
1121
1328
|
|
|
1329
|
+
// ---------- notices ----------
|
|
1330
|
+
//
|
|
1331
|
+
// A finished run, a failure and a pending decision are all durable on the
|
|
1332
|
+
// host. The page turns them into the same short list every time it loads, so
|
|
1333
|
+
// closing the tab loses nothing: reopening shows "跑完了" or "要你批准" again.
|
|
1334
|
+
// Only the ids a person has already read travel back to the server.
|
|
1335
|
+
|
|
1336
|
+
function noticeWhen(at) {
|
|
1337
|
+
const ms = typeof at === 'number' ? at : Date.parse(at)
|
|
1338
|
+
if (!Number.isFinite(ms)) return ''
|
|
1339
|
+
const diff = Date.now() - ms
|
|
1340
|
+
if (diff < 60_000) return '刚刚'
|
|
1341
|
+
if (diff < 3_600_000) return `${Math.max(1, Math.floor(diff / 60000))} 分钟前`
|
|
1342
|
+
return timeLabel(ms)
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
function collectNotices() {
|
|
1346
|
+
const out = []
|
|
1347
|
+
for (const run of Array.isArray(STATE.runs) ? STATE.runs : []) {
|
|
1348
|
+
if (!run || typeof run.id !== 'string') continue
|
|
1349
|
+
const goal = String(run.goal || '这条任务线').replace(/\s+/g, ' ').slice(0, 64)
|
|
1350
|
+
const question = Array.isArray(run.attention) && run.attention.length > 0 ? run.attention[0] : null
|
|
1351
|
+
if (question) {
|
|
1352
|
+
out.push({
|
|
1353
|
+
id: `run:${run.id}:attention`,
|
|
1354
|
+
kind: 'approval',
|
|
1355
|
+
runId: run.id,
|
|
1356
|
+
title: '要你批准',
|
|
1357
|
+
detail: `${goal} · ${question.question || '在等一个决定'}`,
|
|
1358
|
+
at: question.askedAt || run.finishedAt || run.createdAt,
|
|
1359
|
+
})
|
|
1360
|
+
}
|
|
1361
|
+
if (!isTerminal(run.status)) continue
|
|
1362
|
+
const failed = run.status !== 'completed'
|
|
1363
|
+
out.push({
|
|
1364
|
+
id: `run:${run.id}:${run.status}`,
|
|
1365
|
+
kind: failed ? 'failed' : 'done',
|
|
1366
|
+
runId: run.id,
|
|
1367
|
+
title: failed ? (run.status === 'cancelled' ? '已取消' : '没走通') : '跑完了',
|
|
1368
|
+
detail: `${goal} · ${statusText(run.status)}`,
|
|
1369
|
+
at: run.finishedAt || run.createdAt,
|
|
1370
|
+
})
|
|
1371
|
+
}
|
|
1372
|
+
for (const entry of STATE.approvals.values()) {
|
|
1373
|
+
const approval = entry.approval || {}
|
|
1374
|
+
if (!approval.id) continue
|
|
1375
|
+
out.push({
|
|
1376
|
+
id: `approval:${approval.id}`,
|
|
1377
|
+
kind: 'approval',
|
|
1378
|
+
title: '要你批准',
|
|
1379
|
+
detail: `工具 ${approval.toolName || 'tool'} 在等你决定`,
|
|
1380
|
+
at: approval.askedAt,
|
|
1381
|
+
})
|
|
1382
|
+
}
|
|
1383
|
+
out.sort((left, right) => (Date.parse(right.at) || 0) - (Date.parse(left.at) || 0))
|
|
1384
|
+
return out.slice(0, 30)
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
function unreadNotices() {
|
|
1388
|
+
return STATE.notices.filter(notice => !STATE.readNotices.has(notice.id))
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
function renderNoticeBadge() {
|
|
1392
|
+
const unread = unreadNotices().length
|
|
1393
|
+
noticeOpenEl.hidden = STATE.notices.length === 0
|
|
1394
|
+
noticeCountEl.textContent = unread > 99 ? '99+' : String(unread)
|
|
1395
|
+
noticeOpenEl.classList.toggle('has-unread', unread > 0)
|
|
1396
|
+
noticeOpenEl.title = unread > 0 ? `${unread} 条没看过的提醒` : '提醒'
|
|
1397
|
+
const base = 'Superagent 专属空间'
|
|
1398
|
+
document.title = unread > 0 ? `(${unread}) ${base}` : base
|
|
1399
|
+
if (!noticePanelEl.hidden) renderNoticeList()
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
function renderNoticeList() {
|
|
1403
|
+
noticeListEl.textContent = ''
|
|
1404
|
+
if (STATE.notices.length === 0) {
|
|
1405
|
+
noticeListEl.append(el('div', 'notice-empty', '还没有提醒。任务跑完、没走通或等你批准时会出现在这里。'))
|
|
1406
|
+
return
|
|
1407
|
+
}
|
|
1408
|
+
for (const notice of STATE.notices) {
|
|
1409
|
+
const unread = !STATE.readNotices.has(notice.id)
|
|
1410
|
+
const item = el('div', `notice-item${unread ? ' unread' : ''}`)
|
|
1411
|
+
item.dataset.id = notice.id
|
|
1412
|
+
item.append(el('span', 'dot'))
|
|
1413
|
+
const body = el('div', 'body')
|
|
1414
|
+
body.append(el('div', 'title', notice.title))
|
|
1415
|
+
body.append(el('div', 'detail', notice.detail))
|
|
1416
|
+
body.append(el('div', 'when', noticeWhen(notice.at)))
|
|
1417
|
+
item.append(body)
|
|
1418
|
+
item.addEventListener('click', () => {
|
|
1419
|
+
markNoticesRead([notice.id])
|
|
1420
|
+
if (notice.runId) openReport(notice.runId)
|
|
1421
|
+
closeNoticePanel()
|
|
1422
|
+
})
|
|
1423
|
+
noticeListEl.append(item)
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
function refreshNotices({ toastNew = false } = {}) {
|
|
1428
|
+
const previous = new Set(STATE.notices.map(notice => notice.id))
|
|
1429
|
+
// The first pass only paints what already happened; a toast is for a
|
|
1430
|
+
// change that arrives while the page is open.
|
|
1431
|
+
const primed = STATE.noticesPrimed === true
|
|
1432
|
+
STATE.notices = collectNotices()
|
|
1433
|
+
STATE.noticesPrimed = true
|
|
1434
|
+
if (toastNew && primed) {
|
|
1435
|
+
for (const notice of STATE.notices) {
|
|
1436
|
+
if (previous.has(notice.id)) continue
|
|
1437
|
+
if (notice.kind === 'done') pushToast(`跑完了:${notice.detail}`, 'ok')
|
|
1438
|
+
else if (notice.kind === 'failed') pushToast(`${notice.title}:${notice.detail}`, 'err')
|
|
1439
|
+
else if (notice.kind === 'approval') pushToast(`要你批准:${notice.detail}`, 'warn')
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
renderNoticeBadge()
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
function markNoticesRead(ids) {
|
|
1446
|
+
const fresh = (Array.isArray(ids) ? ids : []).filter(id => id && !STATE.readNotices.has(id))
|
|
1447
|
+
if (fresh.length === 0) return
|
|
1448
|
+
for (const id of fresh) STATE.readNotices.add(id)
|
|
1449
|
+
renderNoticeBadge()
|
|
1450
|
+
api('/api/console/notices/read', { method: 'POST', body: { ids: fresh } }).catch(() => {})
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
function openNoticePanel() {
|
|
1454
|
+
STATE.noticeOpen = true
|
|
1455
|
+
noticePanelEl.hidden = false
|
|
1456
|
+
renderNoticeList()
|
|
1457
|
+
// Opening the list is reading it: the badge clears, the lines stay.
|
|
1458
|
+
markNoticesRead(STATE.notices.map(notice => notice.id))
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
function closeNoticePanel() {
|
|
1462
|
+
STATE.noticeOpen = false
|
|
1463
|
+
noticePanelEl.hidden = true
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
// ---------- files ----------
|
|
1467
|
+
//
|
|
1468
|
+
// A dropped or pasted file is copied into the conversation's workspace by
|
|
1469
|
+
// the host, and the path it returns is what the message carries. Nothing is
|
|
1470
|
+
// uploaded to a third party, and nothing outside the workspace is written.
|
|
1471
|
+
|
|
1472
|
+
function uploadExtOf(name) {
|
|
1473
|
+
const text = typeof name === 'string' ? name : ''
|
|
1474
|
+
const dot = text.lastIndexOf('.')
|
|
1475
|
+
return dot >= 0 ? text.slice(dot).toLowerCase() : ''
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
function uploadSizeText(bytes) {
|
|
1479
|
+
const size = Number(bytes) || 0
|
|
1480
|
+
if (size >= 1024 * 1024) return `${(size / (1024 * 1024)).toFixed(1)}MB`
|
|
1481
|
+
if (size >= 1024) return `${Math.round(size / 1024)}KB`
|
|
1482
|
+
return `${size}B`
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
function base64OfBytes(bytes) {
|
|
1486
|
+
let binary = ''
|
|
1487
|
+
const chunk = 0x8000
|
|
1488
|
+
for (let index = 0; index < bytes.length; index += chunk) {
|
|
1489
|
+
binary += String.fromCharCode.apply(null, bytes.subarray(index, index + chunk))
|
|
1490
|
+
}
|
|
1491
|
+
return btoa(binary)
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
function insertUploadPath(filePath) {
|
|
1495
|
+
if (!filePath) return
|
|
1496
|
+
const current = inputEl.value
|
|
1497
|
+
const separator = current.length === 0 || current.endsWith('\n') ? '' : '\n'
|
|
1498
|
+
inputEl.value = `${current}${separator}${filePath}\n`
|
|
1499
|
+
autoGrow()
|
|
1500
|
+
updateSend()
|
|
1501
|
+
inputEl.focus()
|
|
1502
|
+
try { inputEl.setSelectionRange(inputEl.value.length, inputEl.value.length) } catch { /* not focusable yet */ }
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
async function uploadFiles(files) {
|
|
1506
|
+
const list = Array.from(files || []).filter(Boolean)
|
|
1507
|
+
if (list.length === 0) return
|
|
1508
|
+
if (STATE.mode !== 'chat') {
|
|
1509
|
+
pushToast('还没连上,等对话就绪再放文件。', 'err')
|
|
1510
|
+
return
|
|
1511
|
+
}
|
|
1512
|
+
for (const file of list) {
|
|
1513
|
+
const ext = uploadExtOf(file.name)
|
|
1514
|
+
if (!UPLOAD_EXTS.has(ext)) {
|
|
1515
|
+
pushToast(`不能放 ${ext || '没有扩展名的'} 文件;可以放:${UPLOAD_HINT}。`, 'err')
|
|
1516
|
+
continue
|
|
1517
|
+
}
|
|
1518
|
+
if (file.size > UPLOAD_MAX) {
|
|
1519
|
+
pushToast(`${file.name} 有 ${uploadSizeText(file.size)},超过 ${uploadSizeText(UPLOAD_MAX)} 的上限。`, 'err')
|
|
1520
|
+
continue
|
|
1521
|
+
}
|
|
1522
|
+
if (file.size === 0) {
|
|
1523
|
+
pushToast(`${file.name} 是空文件,没有放进去。`, 'err')
|
|
1524
|
+
continue
|
|
1525
|
+
}
|
|
1526
|
+
try {
|
|
1527
|
+
const bytes = new Uint8Array(await file.arrayBuffer())
|
|
1528
|
+
const data = await api('/api/console/upload', {
|
|
1529
|
+
method: 'POST',
|
|
1530
|
+
body: { sessionId: STATE.sessionId, name: file.name, data: base64OfBytes(bytes) },
|
|
1531
|
+
})
|
|
1532
|
+
insertUploadPath(data.path)
|
|
1533
|
+
pushToast(`已放进工作区:${data.name}(路径已写进消息)。`, 'ok')
|
|
1534
|
+
} catch (error) {
|
|
1535
|
+
const hint = error.hint ? `。${error.hint}` : ''
|
|
1536
|
+
pushToast(`放不进去:${messageOf(error)}${hint}`, 'err')
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
function dragHasFiles(event) {
|
|
1542
|
+
const transfer = event.dataTransfer
|
|
1543
|
+
if (!transfer) return false
|
|
1544
|
+
if (transfer.files && transfer.files.length > 0) return true
|
|
1545
|
+
return Array.from(transfer.types || []).includes('Files')
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1122
1548
|
// ---------- task lanes ----------
|
|
1123
1549
|
|
|
1124
1550
|
const TERMINAL_STATUSES = new Set(['completed', 'failed', 'cancelled', 'interrupted', 'blocked'])
|
|
@@ -1128,9 +1554,10 @@
|
|
|
1128
1554
|
}
|
|
1129
1555
|
|
|
1130
1556
|
function laneStatusText(run) {
|
|
1557
|
+
if (STATE.cancelRequested.has(run.id) && !isTerminal(run.status)) return '停止中'
|
|
1131
1558
|
if (run.status === 'queued') return '排队'
|
|
1132
1559
|
if (run.status === 'completed') return '完成'
|
|
1133
|
-
if (isTerminal(run.status)) return '失败'
|
|
1560
|
+
if (isTerminal(run.status)) return run.status === 'cancelled' ? '已取消' : '失败'
|
|
1134
1561
|
return '进行中'
|
|
1135
1562
|
}
|
|
1136
1563
|
|
|
@@ -1143,12 +1570,81 @@
|
|
|
1143
1570
|
return `${(minutes / 60).toFixed(1)} 小时`
|
|
1144
1571
|
}
|
|
1145
1572
|
|
|
1573
|
+
/** Per-lane clock, fine-grained enough to visibly tick. */
|
|
1574
|
+
function formatClock(ms) {
|
|
1575
|
+
if (!Number.isFinite(ms) || ms < 0) return ''
|
|
1576
|
+
const total = Math.floor(ms / 1000)
|
|
1577
|
+
const minutes = Math.floor(total / 60)
|
|
1578
|
+
const seconds = total % 60
|
|
1579
|
+
return minutes > 0 ? `${minutes}分${String(seconds).padStart(2, '0')}秒` : `${seconds}秒`
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
function laneElapsed(run) {
|
|
1583
|
+
const start = Date.parse(run.createdAt)
|
|
1584
|
+
const end = isTerminal(run.status) ? Date.parse(run.finishedAt) : Date.now()
|
|
1585
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) return ''
|
|
1586
|
+
return formatClock(end - start)
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
function tickLaneClocks() {
|
|
1590
|
+
for (const node of messagesEl.querySelectorAll('.lane-time')) {
|
|
1591
|
+
const started = Number(node.dataset.started)
|
|
1592
|
+
if (!Number.isFinite(started) || node.dataset.started === '') continue
|
|
1593
|
+
const finished = node.dataset.finished ? Number(node.dataset.finished) : Date.now()
|
|
1594
|
+
if (!Number.isFinite(finished)) continue
|
|
1595
|
+
node.textContent = formatClock(finished - started)
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
function syncStopAll() {
|
|
1600
|
+
const active = STATE.runs.filter(run => !isTerminal(run.status))
|
|
1601
|
+
stopAllEl.hidden = active.length === 0
|
|
1602
|
+
stopAllEl.disabled = STATE.mode !== 'chat' || active.length === 0 || STATE.stopAllBusy
|
|
1603
|
+
stopAllEl.textContent = STATE.stopAllBusy ? '正在停止…' : '停止这一轮'
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
async function stopRun(runId) {
|
|
1607
|
+
if (!runId || STATE.cancelRequested.has(runId)) return
|
|
1608
|
+
STATE.cancelRequested.add(runId)
|
|
1609
|
+
renderLanes()
|
|
1610
|
+
try {
|
|
1611
|
+
await api(`/api/console/runs/${encodeURIComponent(runId)}/cancel`, { method: 'POST' })
|
|
1612
|
+
pushToast('已请求停止,等宿主确认。', 'ok')
|
|
1613
|
+
} catch (error) {
|
|
1614
|
+
STATE.cancelRequested.delete(runId)
|
|
1615
|
+
renderLanes()
|
|
1616
|
+
pushToast(`无法停止这条任务线:${messageOf(error)}`, 'err')
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
async function stopAllRuns() {
|
|
1621
|
+
const active = STATE.runs.filter(run => !isTerminal(run.status) && !STATE.cancelRequested.has(run.id))
|
|
1622
|
+
if (active.length === 0) return
|
|
1623
|
+
STATE.stopAllBusy = true
|
|
1624
|
+
syncStopAll()
|
|
1625
|
+
for (const run of active) STATE.cancelRequested.add(run.id)
|
|
1626
|
+
renderLanes()
|
|
1627
|
+
for (const run of active) {
|
|
1628
|
+
try {
|
|
1629
|
+
await api(`/api/console/runs/${encodeURIComponent(run.id)}/cancel`, { method: 'POST' })
|
|
1630
|
+
} catch (error) {
|
|
1631
|
+
STATE.cancelRequested.delete(run.id)
|
|
1632
|
+
pushToast(`有任务线没停下来:${messageOf(error)}`, 'err')
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
STATE.stopAllBusy = false
|
|
1636
|
+
renderLanes()
|
|
1637
|
+
syncStopAll()
|
|
1638
|
+
pushToast('已请求停止这一轮。', 'ok')
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1146
1641
|
function stepLabel(subtask) {
|
|
1147
1642
|
return subtask.title || `步骤 ${subtask.index ?? ''}`.trim()
|
|
1148
1643
|
}
|
|
1149
1644
|
|
|
1150
1645
|
function currentAction(run) {
|
|
1151
1646
|
const subtasks = Array.isArray(run.subtasks) ? run.subtasks : []
|
|
1647
|
+
if (STATE.cancelRequested.has(run.id) && !isTerminal(run.status)) return '已请求停止,等宿主确认'
|
|
1152
1648
|
if (run.status === 'queued') return '排队,等前一条任务线让出位置'
|
|
1153
1649
|
if (run.status === 'planning') return '正在拆步骤'
|
|
1154
1650
|
if (run.status === 'aggregating') return '正在汇总各步骤的结果'
|
|
@@ -1162,14 +1658,22 @@
|
|
|
1162
1658
|
return '正在推进'
|
|
1163
1659
|
}
|
|
1164
1660
|
|
|
1661
|
+
/** Tools the running steps report right now; empty when unknown, never guessed. */
|
|
1662
|
+
function runningToolsOf(run) {
|
|
1663
|
+
const subtasks = Array.isArray(run.subtasks) ? run.subtasks : []
|
|
1664
|
+
return [...new Set(subtasks
|
|
1665
|
+
.filter(subtask => subtask.status === 'running' && typeof subtask.tool === 'string' && subtask.tool)
|
|
1666
|
+
.map(subtask => subtask.tool))]
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1165
1669
|
function laneSignature(run) {
|
|
1166
1670
|
const steps = Array.isArray(run.subtasks)
|
|
1167
|
-
? run.subtasks.map(subtask => `${subtask.status}:${subtask.title}`).join(',')
|
|
1671
|
+
? run.subtasks.map(subtask => `${subtask.status}:${subtask.title}:${subtask.tool || ''}`).join(',')
|
|
1168
1672
|
: ''
|
|
1169
1673
|
const attention = Array.isArray(run.attention)
|
|
1170
1674
|
? run.attention.map(item => `${item.id}:${item.question}`).join(',')
|
|
1171
1675
|
: ''
|
|
1172
|
-
return [run.status, steps, attention, run.report ? run.report.length : 0, run.finishedAt || ''].join('|')
|
|
1676
|
+
return [run.status, steps, attention, run.report ? run.report.length : 0, run.finishedAt || '', STATE.cancelRequested.has(run.id) ? 'stopping' : ''].join('|')
|
|
1173
1677
|
}
|
|
1174
1678
|
|
|
1175
1679
|
/**
|
|
@@ -1195,20 +1699,203 @@
|
|
|
1195
1699
|
return items.slice(0, 12)
|
|
1196
1700
|
}
|
|
1197
1701
|
|
|
1702
|
+
function artifactName(item) {
|
|
1703
|
+
return item.href.replace(/[\\/]+$/, '').split(/[\\/]/).pop() || item.href
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
function artifactUrl(item) {
|
|
1707
|
+
if (/^https?:\/\//i.test(item.href)) return item.href
|
|
1708
|
+
return `/api/console/artifact?path=${encodeURIComponent(item.href)}&runId=${encodeURIComponent(item.runId)}&token=${encodeURIComponent(STATE.token)}`
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1198
1711
|
function artifactElement(item) {
|
|
1199
1712
|
const isUrl = /^https?:\/\//i.test(item.href)
|
|
1200
|
-
const
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1713
|
+
const button = el('button', 'artifact')
|
|
1714
|
+
button.type = 'button'
|
|
1715
|
+
button.title = item.href
|
|
1716
|
+
button.append(el('span', 'ak', isUrl ? '页面' : '文件'))
|
|
1717
|
+
button.append(el('span', 'an', artifactName(item)))
|
|
1718
|
+
button.addEventListener('click', () => previewArtifact(item))
|
|
1719
|
+
return button
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
function escapeHtml(value) {
|
|
1723
|
+
return String(value).replace(/[&<>"']/g, ch => (
|
|
1724
|
+
{ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[ch]
|
|
1725
|
+
))
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
/** Inline spans a report actually uses: code, bold, http links. */
|
|
1729
|
+
function inlineMarkdown(text) {
|
|
1730
|
+
return escapeHtml(text)
|
|
1731
|
+
.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
1732
|
+
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
1733
|
+
.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noopener">$1</a>')
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
/**
|
|
1737
|
+
* Minimal Markdown for run reports: headings, lists, fenced code, paragraphs.
|
|
1738
|
+
* Everything is escaped before markup is added, so a report cannot inject HTML.
|
|
1739
|
+
*/
|
|
1740
|
+
function renderMarkdownInto(container, text) {
|
|
1741
|
+
container.textContent = ''
|
|
1742
|
+
const lines = String(text || '').replace(/\r\n?/g, '\n').split('\n')
|
|
1743
|
+
let list = null
|
|
1744
|
+
let listTag = ''
|
|
1745
|
+
let buffer = []
|
|
1746
|
+
const closeList = () => { list = null; listTag = '' }
|
|
1747
|
+
const flushParagraph = () => {
|
|
1748
|
+
if (buffer.length === 0) return
|
|
1749
|
+
const para = el('p')
|
|
1750
|
+
para.innerHTML = inlineMarkdown(buffer.join('\n')).replace(/\n/g, '<br>')
|
|
1751
|
+
container.append(para)
|
|
1752
|
+
buffer = []
|
|
1753
|
+
}
|
|
1754
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
1755
|
+
const line = lines[i]
|
|
1756
|
+
const fence = line.match(/^\s*```(\S*)\s*$/)
|
|
1757
|
+
if (fence) {
|
|
1758
|
+
flushParagraph()
|
|
1759
|
+
closeList()
|
|
1760
|
+
const code = []
|
|
1761
|
+
i += 1
|
|
1762
|
+
while (i < lines.length && !/^\s*```\s*$/.test(lines[i])) {
|
|
1763
|
+
code.push(lines[i])
|
|
1764
|
+
i += 1
|
|
1765
|
+
}
|
|
1766
|
+
const pre = el('pre')
|
|
1767
|
+
pre.append(el('code', '', code.join('\n')))
|
|
1768
|
+
container.append(pre)
|
|
1769
|
+
continue
|
|
1770
|
+
}
|
|
1771
|
+
if (!line.trim()) {
|
|
1772
|
+
flushParagraph()
|
|
1773
|
+
closeList()
|
|
1774
|
+
continue
|
|
1775
|
+
}
|
|
1776
|
+
if (/^\s*(?:---+|\*\*\*+)\s*$/.test(line)) {
|
|
1777
|
+
flushParagraph()
|
|
1778
|
+
closeList()
|
|
1779
|
+
container.append(el('hr'))
|
|
1780
|
+
continue
|
|
1781
|
+
}
|
|
1782
|
+
const heading = line.match(/^(#{1,4})\s+(.*)$/)
|
|
1783
|
+
if (heading) {
|
|
1784
|
+
flushParagraph()
|
|
1785
|
+
closeList()
|
|
1786
|
+
const node = el(`h${heading[1].length}`)
|
|
1787
|
+
node.innerHTML = inlineMarkdown(heading[2])
|
|
1788
|
+
container.append(node)
|
|
1789
|
+
continue
|
|
1790
|
+
}
|
|
1791
|
+
const bullet = line.match(/^\s*[-*+]\s+(.*)$/)
|
|
1792
|
+
const ordered = line.match(/^\s*\d+[.)]\s+(.*)$/)
|
|
1793
|
+
if (bullet || ordered) {
|
|
1794
|
+
flushParagraph()
|
|
1795
|
+
const tag = bullet ? 'ul' : 'ol'
|
|
1796
|
+
if (!list || listTag !== tag) {
|
|
1797
|
+
list = el(tag)
|
|
1798
|
+
listTag = tag
|
|
1799
|
+
container.append(list)
|
|
1800
|
+
}
|
|
1801
|
+
const item = el('li')
|
|
1802
|
+
item.innerHTML = inlineMarkdown((bullet || ordered)[1])
|
|
1803
|
+
list.append(item)
|
|
1804
|
+
continue
|
|
1805
|
+
}
|
|
1806
|
+
buffer.push(line)
|
|
1807
|
+
}
|
|
1808
|
+
flushParagraph()
|
|
1809
|
+
closeList()
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
function previewFrame(src) {
|
|
1813
|
+
const frame = el('iframe')
|
|
1814
|
+
frame.setAttribute('sandbox', 'allow-scripts allow-popups allow-forms')
|
|
1815
|
+
frame.setAttribute('referrerpolicy', 'no-referrer')
|
|
1816
|
+
frame.src = src
|
|
1817
|
+
return frame
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
function setDialogActions(nodes) {
|
|
1821
|
+
dialogActionsEl.textContent = ''
|
|
1822
|
+
const items = Array.isArray(nodes) ? nodes : []
|
|
1823
|
+
for (const node of items) dialogActionsEl.append(node)
|
|
1824
|
+
dialogActionsEl.hidden = items.length === 0
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
function externalArtifactLink(item) {
|
|
1828
|
+
const link = el('a', 'btn', '新标签打开')
|
|
1829
|
+
link.href = artifactUrl(item)
|
|
1204
1830
|
link.target = '_blank'
|
|
1205
1831
|
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
1832
|
return link
|
|
1210
1833
|
}
|
|
1211
1834
|
|
|
1835
|
+
/**
|
|
1836
|
+
* Show an artifact in place. Markdown is rendered, HTML runs in a sandboxed
|
|
1837
|
+
* frame (the route already ships a sandbox CSP), images and PDFs render
|
|
1838
|
+
* natively, and anything else falls back to its text. The original file stays
|
|
1839
|
+
* one click away from the dialog footer.
|
|
1840
|
+
*/
|
|
1841
|
+
async function previewArtifact(item) {
|
|
1842
|
+
const isUrl = /^https?:\/\//i.test(item.href)
|
|
1843
|
+
const name = artifactName(item)
|
|
1844
|
+
const ext = (name.split('.').pop() || '').toLowerCase()
|
|
1845
|
+
dialogTitleEl.textContent = name
|
|
1846
|
+
dialogMetaEl.textContent = ''
|
|
1847
|
+
dialogMetaEl.append(el('span', '', isUrl ? item.href : `产物 · ${item.href}`))
|
|
1848
|
+
dialogReportEl.textContent = ''
|
|
1849
|
+
setDialogActions([externalArtifactLink(item)])
|
|
1850
|
+
const url = artifactUrl(item)
|
|
1851
|
+
if (isUrl) {
|
|
1852
|
+
dialogReportEl.append(previewFrame(url))
|
|
1853
|
+
reportDialogEl.showModal()
|
|
1854
|
+
return
|
|
1855
|
+
}
|
|
1856
|
+
if (ext === 'html' || ext === 'htm') {
|
|
1857
|
+
dialogReportEl.append(previewFrame(url))
|
|
1858
|
+
reportDialogEl.showModal()
|
|
1859
|
+
return
|
|
1860
|
+
}
|
|
1861
|
+
if (['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg'].includes(ext)) {
|
|
1862
|
+
const image = el('img', 'image-preview')
|
|
1863
|
+
image.src = url
|
|
1864
|
+
image.alt = name
|
|
1865
|
+
dialogReportEl.append(image)
|
|
1866
|
+
reportDialogEl.showModal()
|
|
1867
|
+
return
|
|
1868
|
+
}
|
|
1869
|
+
if (ext === 'pdf') {
|
|
1870
|
+
dialogReportEl.append(previewFrame(url))
|
|
1871
|
+
reportDialogEl.showModal()
|
|
1872
|
+
return
|
|
1873
|
+
}
|
|
1874
|
+
const loading = el('p', '', '正在读取…')
|
|
1875
|
+
dialogReportEl.append(loading)
|
|
1876
|
+
reportDialogEl.showModal()
|
|
1877
|
+
let text = ''
|
|
1878
|
+
try {
|
|
1879
|
+
const response = await fetch(url)
|
|
1880
|
+
if (!response.ok) {
|
|
1881
|
+
throw new Error(response.status === 415
|
|
1882
|
+
? '这个类型不能在控制台里预览'
|
|
1883
|
+
: `读取失败(HTTP ${response.status})`)
|
|
1884
|
+
}
|
|
1885
|
+
text = await response.text()
|
|
1886
|
+
} catch (error) {
|
|
1887
|
+
dialogReportEl.textContent = `读取失败:${messageOf(error)}`
|
|
1888
|
+
return
|
|
1889
|
+
}
|
|
1890
|
+
dialogReportEl.textContent = ''
|
|
1891
|
+
if (ext === 'md' || ext === 'markdown') renderMarkdownInto(dialogReportEl, text)
|
|
1892
|
+
else {
|
|
1893
|
+
const pre = el('pre')
|
|
1894
|
+
pre.append(el('code', '', text))
|
|
1895
|
+
dialogReportEl.append(pre)
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1212
1899
|
function resetLanes() {
|
|
1213
1900
|
STATE.laneEls.clear()
|
|
1214
1901
|
STATE.runAnchors.clear()
|
|
@@ -1280,57 +1967,91 @@
|
|
|
1280
1967
|
next.focus()
|
|
1281
1968
|
try { next.setSelectionRange(next.value.length, next.value.length) } catch {}
|
|
1282
1969
|
}
|
|
1970
|
+
if (artifacts.length > 0) {
|
|
1971
|
+
const chips = el('div', 'artifacts')
|
|
1972
|
+
for (const artifact of artifacts) chips.append(artifactElement(artifact))
|
|
1973
|
+
item.append(chips)
|
|
1974
|
+
}
|
|
1975
|
+
item.addEventListener('click', event => {
|
|
1976
|
+
if (event.target.closest('a')) return
|
|
1977
|
+
drawerClose()
|
|
1978
|
+
entry.message.el?.scrollIntoView({ block: 'center', behavior: 'smooth' })
|
|
1979
|
+
entry.message.el?.classList.add('flash')
|
|
1980
|
+
setTimeout(() => entry.message.el?.classList.remove('flash'), 1200)
|
|
1981
|
+
})
|
|
1982
|
+
historyListEl.append(item)
|
|
1283
1983
|
}
|
|
1284
1984
|
renderAdvancedRuns()
|
|
1985
|
+
for (const id of [...STATE.cancelRequested]) {
|
|
1986
|
+
const run = STATE.runs.find(item => item.id === id)
|
|
1987
|
+
if (!run || isTerminal(run.status)) STATE.cancelRequested.delete(id)
|
|
1988
|
+
}
|
|
1989
|
+
syncStopAll()
|
|
1285
1990
|
renderHistory()
|
|
1286
1991
|
}
|
|
1287
1992
|
|
|
1993
|
+
async function loadSessions() {
|
|
1994
|
+
if (STATE.sessionsBusy) return
|
|
1995
|
+
STATE.sessionsBusy = true
|
|
1996
|
+
renderHistory()
|
|
1997
|
+
try {
|
|
1998
|
+
const data = await api('/api/console/sessions')
|
|
1999
|
+
STATE.sessions = Array.isArray(data.sessions) ? data.sessions : []
|
|
2000
|
+
STATE.sessionsLoadedAt = Date.now()
|
|
2001
|
+
STATE.sessionNote = data.reason || null
|
|
2002
|
+
} catch (error) {
|
|
2003
|
+
STATE.sessions = []
|
|
2004
|
+
STATE.sessionNote = messageOf(error)
|
|
2005
|
+
} finally {
|
|
2006
|
+
STATE.sessionsBusy = false
|
|
2007
|
+
renderHistory()
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
/**
|
|
2012
|
+
* Reopen a conversation the host already has. The page reloads so the normal
|
|
2013
|
+
* bootstrap/follow path rebuilds the thread, cards and artifacts — the same
|
|
2014
|
+
* code that serves a fresh page load, not a second renderer.
|
|
2015
|
+
*/
|
|
2016
|
+
async function switchToSession(sessionId) {
|
|
2017
|
+
if (!sessionId || sessionId === STATE.sessionId) {
|
|
2018
|
+
drawerClose()
|
|
2019
|
+
return
|
|
2020
|
+
}
|
|
2021
|
+
try {
|
|
2022
|
+
await api('/api/console/session/switch', { method: 'POST', body: { sessionId } })
|
|
2023
|
+
window.location.reload()
|
|
2024
|
+
} catch (error) {
|
|
2025
|
+
pushToast(`无法打开那条对话:${messageOf(error)}`, 'err')
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
|
|
1288
2029
|
function renderHistory() {
|
|
1289
2030
|
if (historyDrawerEl.hidden) return
|
|
1290
2031
|
historyListEl.replaceChildren()
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
})
|
|
2032
|
+
if (STATE.sessionsBusy && STATE.sessions.length === 0) {
|
|
2033
|
+
historyListEl.append(el('p', 'adv-note', '正在读取对话…'))
|
|
2034
|
+
return
|
|
2035
|
+
}
|
|
2036
|
+
if (STATE.sessionNote) {
|
|
2037
|
+
historyListEl.append(el('p', 'adv-note', `无法读取历史:${STATE.sessionNote}`))
|
|
1298
2038
|
}
|
|
1299
|
-
if (
|
|
1300
|
-
historyListEl.append(el('p', 'adv-note', '
|
|
2039
|
+
if (STATE.sessions.length === 0) {
|
|
2040
|
+
historyListEl.append(el('p', 'adv-note', '还没有可回看的对话。'))
|
|
1301
2041
|
return
|
|
1302
2042
|
}
|
|
1303
|
-
for (const
|
|
1304
|
-
const
|
|
2043
|
+
for (const session of STATE.sessions) {
|
|
2044
|
+
const current = session.sessionId === STATE.sessionId
|
|
2045
|
+
const item = el('div', `hist-item${current ? ' current' : ''}`)
|
|
1305
2046
|
const top = el('div', 'hist-top')
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
}
|
|
2047
|
+
const when = session.updatedAt ? timeLabel(new Date(session.updatedAt).toISOString()) : '时间未知'
|
|
2048
|
+
top.append(el('span', '', when))
|
|
2049
|
+
if (current) top.append(el('span', 'hist-state', '当前'))
|
|
2050
|
+
else if (session.running) top.append(el('span', 'hist-state', '进行中'))
|
|
2051
|
+
if (session.runs > 0) top.append(el('span', 'hist-state', `${session.runs} 轮 · ${session.artifacts} 个产物`))
|
|
1311
2052
|
item.append(top)
|
|
1312
|
-
item.append(el('div', 'hist-text',
|
|
1313
|
-
|
|
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)
|
|
1320
|
-
}
|
|
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
|
-
})
|
|
2053
|
+
item.append(el('div', 'hist-text', session.first || session.title || '(这条对话还没有内容)'))
|
|
2054
|
+
item.addEventListener('click', () => switchToSession(session.sessionId))
|
|
1334
2055
|
historyListEl.append(item)
|
|
1335
2056
|
}
|
|
1336
2057
|
}
|
|
@@ -1386,11 +2107,31 @@
|
|
|
1386
2107
|
const action = currentAction(run)
|
|
1387
2108
|
if (action) {
|
|
1388
2109
|
const line = el('div', 'lane-now')
|
|
1389
|
-
if (!isTerminal(run.status)) line.append(el('span', 'spark'))
|
|
2110
|
+
if (!isTerminal(run.status) && !STATE.cancelRequested.has(run.id)) line.append(el('span', 'spark'))
|
|
1390
2111
|
line.append(el('span', '', action))
|
|
2112
|
+
const tools = runningToolsOf(run)
|
|
2113
|
+
if (tools.length > 0) line.append(el('span', 'lane-tool', ` · 工具 ${tools.join('、')}`))
|
|
1391
2114
|
title.append(line)
|
|
1392
2115
|
}
|
|
1393
2116
|
head.append(title)
|
|
2117
|
+
const clock = el('span', 'lane-time', laneElapsed(run))
|
|
2118
|
+
clock.dataset.started = Number.isFinite(Date.parse(run.createdAt)) ? String(Date.parse(run.createdAt)) : ''
|
|
2119
|
+
clock.dataset.finished = isTerminal(run.status) && Number.isFinite(Date.parse(run.finishedAt))
|
|
2120
|
+
? String(Date.parse(run.finishedAt))
|
|
2121
|
+
: ''
|
|
2122
|
+
if (!clock.textContent) clock.hidden = true
|
|
2123
|
+
head.append(clock)
|
|
2124
|
+
if (!isTerminal(run.status)) {
|
|
2125
|
+
const stopping = STATE.cancelRequested.has(run.id)
|
|
2126
|
+
const stop = el('button', `lane-stop${stopping ? ' stopping' : ''}`, stopping ? '停止中…' : '停止')
|
|
2127
|
+
stop.type = 'button'
|
|
2128
|
+
stop.disabled = stopping
|
|
2129
|
+
stop.addEventListener('click', event => {
|
|
2130
|
+
event.stopPropagation()
|
|
2131
|
+
stopRun(run.id)
|
|
2132
|
+
})
|
|
2133
|
+
head.append(stop)
|
|
2134
|
+
}
|
|
1394
2135
|
head.append(el('span', `status-pill ${statusClass(run.status)}`, laneStatusText(run)))
|
|
1395
2136
|
card.append(head)
|
|
1396
2137
|
|
|
@@ -1576,6 +2317,56 @@
|
|
|
1576
2317
|
return approval.source || '这条对话'
|
|
1577
2318
|
}
|
|
1578
2319
|
|
|
2320
|
+
/** Raw arguments of the blocked call, from the request or the streamed chip. */
|
|
2321
|
+
function approvalArguments(approval) {
|
|
2322
|
+
const candidates = [approval.callArguments]
|
|
2323
|
+
const call = approval.callId ? STATE.toolCalls.get(approval.callId) : null
|
|
2324
|
+
if (call && call.arguments) candidates.push(call.arguments)
|
|
2325
|
+
for (const raw of candidates) {
|
|
2326
|
+
if (typeof raw !== 'string' || !raw.trim()) continue
|
|
2327
|
+
try {
|
|
2328
|
+
return { parsed: JSON.parse(raw), text: raw }
|
|
2329
|
+
} catch {
|
|
2330
|
+
return { parsed: null, text: raw }
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
return null
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
const CALL_PREVIEW_LIMIT = 4000
|
|
2337
|
+
|
|
2338
|
+
/**
|
|
2339
|
+
* Spell out what the blocked call would actually do: a write shows the text
|
|
2340
|
+
* it would put on disk, a shell call shows the full command, everything else
|
|
2341
|
+
* shows the raw arguments.
|
|
2342
|
+
*/
|
|
2343
|
+
function approvalCallPreview(approval) {
|
|
2344
|
+
const args = approvalArguments(approval)
|
|
2345
|
+
if (!args) return null
|
|
2346
|
+
const parsed = args.parsed && typeof args.parsed === 'object' ? args.parsed : null
|
|
2347
|
+
const pick = (...keys) => {
|
|
2348
|
+
if (!parsed) return ''
|
|
2349
|
+
for (const key of keys) {
|
|
2350
|
+
if (typeof parsed[key] === 'string' && parsed[key].trim()) return parsed[key]
|
|
2351
|
+
}
|
|
2352
|
+
return ''
|
|
2353
|
+
}
|
|
2354
|
+
const tool = `${approval.toolName || ''}`.toLowerCase()
|
|
2355
|
+
const clip = value => (value.length > CALL_PREVIEW_LIMIT
|
|
2356
|
+
? { text: `${value.slice(0, CALL_PREVIEW_LIMIT)}\n…`, note: `共 ${value.length} 字符,这里先看前 ${CALL_PREVIEW_LIMIT} 字符。` }
|
|
2357
|
+
: { text: value, note: '' })
|
|
2358
|
+
if (/write|edit|patch|apply|create|append/.test(tool)) {
|
|
2359
|
+
const body = pick('content', 'contents', 'text', 'new_string', 'newText', 'patch', 'diff')
|
|
2360
|
+
if (body) return { label: '要写入的内容', ...clip(body) }
|
|
2361
|
+
}
|
|
2362
|
+
if (/shell|bash|command|exec|terminal|cmd|powershell|run/.test(tool)) {
|
|
2363
|
+
const command = pick('command', 'cmd', 'script', 'input')
|
|
2364
|
+
|| (typeof args.parsed === 'string' ? args.parsed : '')
|
|
2365
|
+
if (command) return { label: '要执行的命令', ...clip(command) }
|
|
2366
|
+
}
|
|
2367
|
+
return { label: '调用参数', ...clip(args.text) }
|
|
2368
|
+
}
|
|
2369
|
+
|
|
1579
2370
|
function approvalCard(approval) {
|
|
1580
2371
|
const card = el('div', 'approval-card')
|
|
1581
2372
|
card.dataset.approvalId = approval.id
|
|
@@ -1588,28 +2379,65 @@
|
|
|
1588
2379
|
if (target) card.append(el('div', 'where', `要动的位置:${target}`))
|
|
1589
2380
|
const reason = approval.displayReason?.zh || approval.reason
|
|
1590
2381
|
card.append(el('p', 'why', reason || '宿主的工具调用被拦住了,需要你明确决定这一次。'))
|
|
2382
|
+
const preview = approvalCallPreview(approval)
|
|
2383
|
+
if (preview) {
|
|
2384
|
+
const details = el('details', 'call')
|
|
2385
|
+
details.append(el('summary', '', preview.label))
|
|
2386
|
+
details.append(el('pre', '', preview.text))
|
|
2387
|
+
if (preview.note) details.append(el('div', 'note', preview.note))
|
|
2388
|
+
card.append(details)
|
|
2389
|
+
}
|
|
2390
|
+
const expiresAt = Date.parse(approval.expiresAt || '')
|
|
2391
|
+
if (Number.isFinite(expiresAt)) {
|
|
2392
|
+
const expiry = el('div', 'expiry')
|
|
2393
|
+
expiry.dataset.expiresAt = String(expiresAt)
|
|
2394
|
+
card.append(expiry)
|
|
2395
|
+
updateApprovalClock(expiry)
|
|
2396
|
+
}
|
|
1591
2397
|
card.append(el('div', 'state', '等待你的决定…'))
|
|
1592
2398
|
const options = el('div', 'options')
|
|
1593
2399
|
const allow = el('button', 'allow', '允许这一次')
|
|
1594
2400
|
allow.type = 'button'
|
|
1595
2401
|
allow.addEventListener('click', () => decideApproval(approval.id, 'allow'))
|
|
2402
|
+
const allowTool = el('button', 'allow-tool', `本会话内允许 ${approval.toolName || '这个工具'}`)
|
|
2403
|
+
allowTool.type = 'button'
|
|
2404
|
+
allowTool.title = '这一轮对话里同一个工具不再逐次询问;换对话或新对话后恢复询问。'
|
|
2405
|
+
allowTool.addEventListener('click', () => decideApproval(approval.id, 'allow-tool'))
|
|
1596
2406
|
const reject = el('button', 'reject', '拒绝')
|
|
1597
2407
|
reject.type = 'button'
|
|
1598
2408
|
reject.addEventListener('click', () => decideApproval(approval.id, 'reject'))
|
|
1599
|
-
options.append(allow, reject)
|
|
2409
|
+
options.append(allow, allowTool, reject)
|
|
1600
2410
|
card.append(options)
|
|
1601
2411
|
return card
|
|
1602
2412
|
}
|
|
1603
2413
|
|
|
2414
|
+
/** Keeping the deadline visible beats letting the ask silently expire. */
|
|
2415
|
+
function updateApprovalClock(node) {
|
|
2416
|
+
const expiresAt = Number(node.dataset.expiresAt)
|
|
2417
|
+
if (!Number.isFinite(expiresAt)) return
|
|
2418
|
+
const left = expiresAt - Date.now()
|
|
2419
|
+
node.classList.toggle('soon', left > 0 && left <= 60_000)
|
|
2420
|
+
node.classList.toggle('over', left <= 0)
|
|
2421
|
+
if (left <= 0) node.textContent = `已超过有效期(${timeLabel(expiresAt)}),宿主会按拒绝处理;再发起会重新询问。`
|
|
2422
|
+
else node.textContent = `剩余有效时间 ${formatClock(left)}(约到 ${timeLabel(expiresAt)})`
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
function updateApprovalClocks() {
|
|
2426
|
+
for (const node of messagesEl.querySelectorAll('.approval-card .expiry')) updateApprovalClock(node)
|
|
2427
|
+
}
|
|
2428
|
+
|
|
1604
2429
|
function settleApprovalNode(entry) {
|
|
1605
2430
|
if (!entry || !entry.node) return
|
|
1606
2431
|
entry.node.querySelector('.options')?.remove()
|
|
1607
2432
|
const state = entry.node.querySelector('.state')
|
|
1608
2433
|
if (!state) return
|
|
1609
2434
|
if (entry.decided === 'allow') state.textContent = '已允许这一次(只对这一条调用生效)'
|
|
2435
|
+
else if (entry.decided === 'allow-tool') state.textContent = `已允许,并在本会话内放行 ${entry.approval?.toolName || '这个工具'}(换对话后恢复询问)`
|
|
1610
2436
|
else if (entry.decided === 'reject') state.textContent = '已拒绝'
|
|
2437
|
+
else if (entry.decided === 'expired') state.textContent = '已过有效期,宿主按拒绝处理'
|
|
1611
2438
|
else if (entry.decided === 'cancelled') state.textContent = '没有回答,按拒绝处理'
|
|
1612
2439
|
else state.textContent = '等待你的决定…'
|
|
2440
|
+
if (entry.decided) entry.node.querySelector('.expiry')?.remove()
|
|
1613
2441
|
}
|
|
1614
2442
|
|
|
1615
2443
|
function seatApproval(approval) {
|
|
@@ -1646,15 +2474,18 @@
|
|
|
1646
2474
|
if (!entry || entry.decided) return
|
|
1647
2475
|
const state = entry.node.querySelector('.state')
|
|
1648
2476
|
for (const button of entry.node.querySelectorAll('button')) button.disabled = true
|
|
1649
|
-
|
|
2477
|
+
const pending = { allow: '正在允许这一次…', 'allow-tool': '正在允许这个工具…', reject: '正在拒绝…' }
|
|
2478
|
+
if (state) state.textContent = pending[decision] || '正在提交…'
|
|
1650
2479
|
try {
|
|
1651
2480
|
await api('/api/console/approval', { method: 'POST', body: { id, decision } })
|
|
1652
2481
|
entry.decided = decision
|
|
1653
2482
|
settleApprovalNode(entry)
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
'
|
|
1657
|
-
|
|
2483
|
+
const done = {
|
|
2484
|
+
allow: '已允许这一次;只对这一条调用生效。',
|
|
2485
|
+
'allow-tool': '已允许:本会话内同一个工具不再询问(换对话后恢复)。',
|
|
2486
|
+
reject: '已拒绝这一条调用。',
|
|
2487
|
+
}
|
|
2488
|
+
pushToast(done[decision] || '已提交。', 'ok')
|
|
1658
2489
|
} catch (error) {
|
|
1659
2490
|
for (const button of entry.node.querySelectorAll('button')) button.disabled = false
|
|
1660
2491
|
if (state) state.textContent = `没有提交成功:${messageOf(error)}`
|
|
@@ -1674,7 +2505,12 @@
|
|
|
1674
2505
|
data.finishedAt ? `结束 ${timeLabel(data.finishedAt)}` : null,
|
|
1675
2506
|
].filter(Boolean)
|
|
1676
2507
|
for (const value of meta) dialogMetaEl.append(el('span', '', value))
|
|
1677
|
-
|
|
2508
|
+
setDialogActions([])
|
|
2509
|
+
if (data.report) renderMarkdownInto(dialogReportEl, data.report)
|
|
2510
|
+
else {
|
|
2511
|
+
dialogReportEl.textContent = ''
|
|
2512
|
+
dialogReportEl.append(el('p', '', '(这个 run 还没有报告)'))
|
|
2513
|
+
}
|
|
1678
2514
|
reportDialogEl.showModal()
|
|
1679
2515
|
} catch (error) {
|
|
1680
2516
|
pushToast(`读取报告失败:${messageOf(error)}`, 'err')
|
|
@@ -1734,14 +2570,20 @@
|
|
|
1734
2570
|
const approval = frame.approval
|
|
1735
2571
|
if (frame.action === 'asked' && approval && approval.id) {
|
|
1736
2572
|
seatApproval(approval)
|
|
2573
|
+
refreshNotices({ toastNew: true })
|
|
1737
2574
|
pushToast('有一个工具调用在等你决定。', 'warn')
|
|
2575
|
+
} else if (frame.action === 'auto') {
|
|
2576
|
+
pushToast(`已按本会话的许可放行 ${frame.toolName || '这个工具'},没有再打断你。`, 'ok')
|
|
1738
2577
|
} else if ((frame.action === 'decided' || frame.action === 'expired') && frame.id) {
|
|
1739
2578
|
const entry = STATE.approvals.get(frame.id)
|
|
1740
2579
|
if (entry) {
|
|
1741
2580
|
entry.decided = frame.action === 'expired'
|
|
1742
|
-
? '
|
|
1743
|
-
: frame.
|
|
2581
|
+
? 'expired'
|
|
2582
|
+
: frame.scope === 'tool' ? 'allow-tool'
|
|
2583
|
+
: frame.outcome === 'allowed-once' ? 'allow'
|
|
2584
|
+
: frame.outcome === 'rejected' ? 'reject' : 'cancelled'
|
|
1744
2585
|
settleApprovalNode(entry)
|
|
2586
|
+
refreshNotices()
|
|
1745
2587
|
}
|
|
1746
2588
|
}
|
|
1747
2589
|
break
|
|
@@ -1749,10 +2591,17 @@
|
|
|
1749
2591
|
case 'runs':
|
|
1750
2592
|
STATE.runs = Array.isArray(frame.runs) ? frame.runs : []
|
|
1751
2593
|
renderLanes()
|
|
2594
|
+
refreshNotices({ toastNew: true })
|
|
1752
2595
|
break
|
|
1753
2596
|
case 'answered':
|
|
1754
2597
|
pushToast(`已提交 ${frame.attentionId || '决定'}。`, 'ok')
|
|
1755
2598
|
break
|
|
2599
|
+
case 'canceling':
|
|
2600
|
+
if (frame.runId) {
|
|
2601
|
+
STATE.cancelRequested.add(frame.runId)
|
|
2602
|
+
renderLanes()
|
|
2603
|
+
}
|
|
2604
|
+
break
|
|
1756
2605
|
case 'error':
|
|
1757
2606
|
if (frame.code === 'follow-failed' || frame.code === 'state-failed') {
|
|
1758
2607
|
setConn('warn', '流中断')
|
|
@@ -1978,8 +2827,10 @@
|
|
|
1978
2827
|
if (data.sessionId) setSession(data.sessionId)
|
|
1979
2828
|
if (data.preset) STATE.preset = data.preset
|
|
1980
2829
|
STATE.runs = Array.isArray(data.runs) ? data.runs : []
|
|
2830
|
+
STATE.readNotices = new Set(Array.isArray(data.readNoticeIds) ? data.readNoticeIds : [])
|
|
1981
2831
|
renderLanes()
|
|
1982
2832
|
for (const approval of Array.isArray(data.approvals) ? data.approvals : []) seatApproval(approval)
|
|
2833
|
+
refreshNotices()
|
|
1983
2834
|
if (STATE.messages.length === 0) renderEmpty()
|
|
1984
2835
|
loadTools()
|
|
1985
2836
|
wizardLoad({ probe: false, auto: true })
|
|
@@ -2697,9 +3548,11 @@
|
|
|
2697
3548
|
if (STATE.streamAbort) STATE.streamAbort.abort()
|
|
2698
3549
|
setSession(data.sessionId)
|
|
2699
3550
|
STATE.approvals.clear()
|
|
3551
|
+
STATE.cancelRequested.clear()
|
|
2700
3552
|
clearMessages()
|
|
2701
3553
|
STATE.runs = []
|
|
2702
3554
|
renderLanes()
|
|
3555
|
+
refreshNotices()
|
|
2703
3556
|
renderEmpty()
|
|
2704
3557
|
renderTools(null)
|
|
2705
3558
|
loadTools()
|
|
@@ -2753,7 +3606,10 @@
|
|
|
2753
3606
|
advancedDrawerEl.hidden = target !== advancedDrawerEl
|
|
2754
3607
|
scrimEl.hidden = false
|
|
2755
3608
|
target.hidden = false
|
|
2756
|
-
if (which === 'history')
|
|
3609
|
+
if (which === 'history') {
|
|
3610
|
+
renderHistory()
|
|
3611
|
+
loadSessions()
|
|
3612
|
+
}
|
|
2757
3613
|
else renderAdvancedRuns()
|
|
2758
3614
|
}
|
|
2759
3615
|
|
|
@@ -2787,6 +3643,50 @@
|
|
|
2787
3643
|
sendMessage()
|
|
2788
3644
|
})
|
|
2789
3645
|
|
|
3646
|
+
// A file can be dropped anywhere on the composer, or pasted into the text
|
|
3647
|
+
// box; both end up copied into the conversation's workspace, with the path
|
|
3648
|
+
// written into the message so the agent can read it.
|
|
3649
|
+
for (const type of ['dragenter', 'dragover']) {
|
|
3650
|
+
composerEl.addEventListener(type, event => {
|
|
3651
|
+
if (!dragHasFiles(event)) return
|
|
3652
|
+
event.preventDefault()
|
|
3653
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy'
|
|
3654
|
+
STATE.dragDepth += 1
|
|
3655
|
+
composerEl.classList.add('dragover')
|
|
3656
|
+
})
|
|
3657
|
+
}
|
|
3658
|
+
composerEl.addEventListener('dragleave', () => {
|
|
3659
|
+
STATE.dragDepth = Math.max(0, STATE.dragDepth - 1)
|
|
3660
|
+
if (STATE.dragDepth === 0) composerEl.classList.remove('dragover')
|
|
3661
|
+
})
|
|
3662
|
+
composerEl.addEventListener('drop', event => {
|
|
3663
|
+
if (!dragHasFiles(event)) return
|
|
3664
|
+
event.preventDefault()
|
|
3665
|
+
STATE.dragDepth = 0
|
|
3666
|
+
composerEl.classList.remove('dragover')
|
|
3667
|
+
uploadFiles(event.dataTransfer ? event.dataTransfer.files : null)
|
|
3668
|
+
})
|
|
3669
|
+
inputEl.addEventListener('paste', event => {
|
|
3670
|
+
const files = event.clipboardData ? event.clipboardData.files : null
|
|
3671
|
+
if (!files || files.length === 0) return
|
|
3672
|
+
event.preventDefault()
|
|
3673
|
+
uploadFiles(files)
|
|
3674
|
+
})
|
|
3675
|
+
|
|
3676
|
+
noticeOpenEl.addEventListener('click', event => {
|
|
3677
|
+
event.stopPropagation()
|
|
3678
|
+
if (STATE.noticeOpen) closeNoticePanel()
|
|
3679
|
+
else openNoticePanel()
|
|
3680
|
+
})
|
|
3681
|
+
$('noticeReadAll').addEventListener('click', event => {
|
|
3682
|
+
event.stopPropagation()
|
|
3683
|
+
markNoticesRead(STATE.notices.map(notice => notice.id))
|
|
3684
|
+
})
|
|
3685
|
+
noticePanelEl.addEventListener('click', event => event.stopPropagation())
|
|
3686
|
+
document.addEventListener('click', () => {
|
|
3687
|
+
if (STATE.noticeOpen) closeNoticePanel()
|
|
3688
|
+
})
|
|
3689
|
+
|
|
2790
3690
|
for (const button of document.querySelectorAll('.segmented button')) {
|
|
2791
3691
|
button.addEventListener('click', () => {
|
|
2792
3692
|
STATE.sendMode = button.dataset.mode === 'steer' ? 'steer' : 'queue'
|
|
@@ -2797,6 +3697,11 @@
|
|
|
2797
3697
|
}
|
|
2798
3698
|
|
|
2799
3699
|
newChatEl.addEventListener('click', newConversation)
|
|
3700
|
+
stopAllEl.addEventListener('click', stopAllRuns)
|
|
3701
|
+
setInterval(() => {
|
|
3702
|
+
tickLaneClocks()
|
|
3703
|
+
updateApprovalClocks()
|
|
3704
|
+
}, 1000)
|
|
2800
3705
|
$('historyOpen').addEventListener('click', () => drawerOpen('history'))
|
|
2801
3706
|
$('advancedOpen').addEventListener('click', () => drawerOpen('advanced'))
|
|
2802
3707
|
for (const button of document.querySelectorAll('[data-close]')) {
|