@vincentbanana/bananacli 0.6.1 → 0.7.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.
- package/dist/agent/loop.js +8 -5
- package/dist/server/ui-server.js +22 -6
- package/dist/ui/app.js +511 -73
- package/dist/ui/index.html +8 -4
- package/dist/ui/style.css +317 -0
- package/package.json +1 -1
package/dist/ui/app.js
CHANGED
|
@@ -8,6 +8,7 @@ const ICONS = {
|
|
|
8
8
|
send: '<path d="M12 19V5M6 11l6-6 6 6"/>',
|
|
9
9
|
stop: '<rect x="7" y="7" width="10" height="10" rx="1.5"/>',
|
|
10
10
|
chip: '<rect x="7" y="7" width="10" height="10" rx="2"/><path d="M10 4v3M14 4v3M10 17v3M14 17v3M4 10h3M4 14h3M17 10h3M17 14h3"/>',
|
|
11
|
+
chevronDown: '<path d="M6 9l6 6 6-6"/>',
|
|
11
12
|
sliders: '<path d="M4 8h8M16 8h4M4 16h4M12 16h8"/><circle cx="14" cy="8" r="2"/><circle cx="10" cy="16" r="2"/>',
|
|
12
13
|
undo: '<path d="M9 8H4m0 0 3.5-3.5M4 8h9a6 6 0 0 1 0 12h-4"/>',
|
|
13
14
|
trash: '<path d="M5 7h14M10 7V5h4v2M7 7l1 13h8l1-13"/>',
|
|
@@ -42,6 +43,9 @@ const ICONS = {
|
|
|
42
43
|
restore: '<rect x="5" y="8" width="9" height="9" rx="1"/><path d="M9 5h9v9"/>',
|
|
43
44
|
diff: '<path d="M6 4v16M18 4v16M3 8h6M15 16h6M3 16h6M15 8h6"/>',
|
|
44
45
|
refresh: '<path d="M20 11a8 8 0 1 0-2.3 5.7"/><path d="M20 5v6h-6"/>',
|
|
46
|
+
history: '<path d="M3.5 12a8.5 8.5 0 1 0 2.8-6.3"/><path d="M3.5 4.5v5h5"/><path d="M12 8v4.5l3 1.8"/>',
|
|
47
|
+
attach: '<path d="M20 11.5l-7.8 7.8a5 5 0 0 1-7-7L13 4.5a3.4 3.4 0 0 1 4.8 4.8L10 17a1.8 1.8 0 0 1-2.5-2.5l6.7-6.7"/>',
|
|
48
|
+
arrowDown: '<path d="M12 5v14M6 13l6 6 6-6"/>',
|
|
45
49
|
};
|
|
46
50
|
|
|
47
51
|
const TOOL_ICON = {
|
|
@@ -181,6 +185,8 @@ const state = {
|
|
|
181
185
|
review: { open: false, mode: 'changes', width: 520 },
|
|
182
186
|
sidebar: { open: true, width: 344 },
|
|
183
187
|
sessionQuery: '',
|
|
188
|
+
status: '',
|
|
189
|
+
stickToBottom: true,
|
|
184
190
|
dock: { open: false, height: 280 },
|
|
185
191
|
changes: null,
|
|
186
192
|
changesFile: null,
|
|
@@ -221,7 +227,7 @@ function relativeTime(iso) {
|
|
|
221
227
|
|
|
222
228
|
/** 窄屏下侧边栏是覆盖层,选完会话必须收起来,否则挡住对话。 */
|
|
223
229
|
function closeSidebarIfOverlay() {
|
|
224
|
-
if (window.matchMedia('(max-width: 900px)').matches
|
|
230
|
+
if (window.matchMedia('(max-width: 900px)').matches && state.sidebar.open) setSidebar(false);
|
|
225
231
|
}
|
|
226
232
|
|
|
227
233
|
let switching = false;
|
|
@@ -298,8 +304,10 @@ function renderTabs() {
|
|
|
298
304
|
node.draggable = true;
|
|
299
305
|
node.dataset.id = tab.id;
|
|
300
306
|
const title = tabTitleFor(tab.id) || tab.title || '新对话';
|
|
307
|
+
const isNew = title === '新对话';
|
|
308
|
+
node.classList.toggle('is-running', state.busy && tab.id === state.activeTab);
|
|
301
309
|
node.innerHTML =
|
|
302
|
-
`<span class="tab-avatar">${escapeHtml(title.slice(0, 1))}</span>` +
|
|
310
|
+
`<span class="tab-avatar${isNew ? ' is-new' : ''}">${isNew ? '' : escapeHtml(title.slice(0, 1))}</span>` +
|
|
303
311
|
`<span class="tab-title">${escapeHtml(title)}</span>` +
|
|
304
312
|
`<span class="tab-close" title="关闭标签"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18"/></svg></span>`;
|
|
305
313
|
node.addEventListener('pointerdown', (event) => {
|
|
@@ -523,6 +531,50 @@ function downloadSession(format, id) {
|
|
|
523
531
|
toast(`已导出 ${format === 'json' ? 'JSON' : 'Markdown'}`);
|
|
524
532
|
}
|
|
525
533
|
|
|
534
|
+
function toolSummaryText(call) {
|
|
535
|
+
const input = call.input ?? {};
|
|
536
|
+
if (typeof input.command === 'string') return input.command;
|
|
537
|
+
return JSON.stringify(input).slice(0, 110);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function ensureToolOutput(row, initial = '', isError = false) {
|
|
541
|
+
let out = row.nextElementSibling;
|
|
542
|
+
if (!out || !out.classList.contains('tool-output')) {
|
|
543
|
+
out = document.createElement('div');
|
|
544
|
+
out.className = 'tool-output';
|
|
545
|
+
out.hidden = true;
|
|
546
|
+
row.after(out);
|
|
547
|
+
}
|
|
548
|
+
out.classList.toggle('is-error', isError);
|
|
549
|
+
if (initial) out.textContent = initial;
|
|
550
|
+
row.classList.add('is-clickable');
|
|
551
|
+
row.title = '点击展开命令输出';
|
|
552
|
+
if (!row.dataset.bound) {
|
|
553
|
+
row.dataset.bound = '1';
|
|
554
|
+
row.addEventListener('click', () => {
|
|
555
|
+
const box = row.nextElementSibling;
|
|
556
|
+
if (!box?.classList.contains('tool-output')) return;
|
|
557
|
+
const open = box.hidden;
|
|
558
|
+
box.hidden = !open;
|
|
559
|
+
row.classList.toggle('is-open', open);
|
|
560
|
+
row.title = open ? '点击收起命令输出' : '点击展开命令输出';
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
return out;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function toolRowNode(name, detail, stateHtml, ms) {
|
|
567
|
+
const row = document.createElement('div');
|
|
568
|
+
row.className = 'tool-row';
|
|
569
|
+
row.innerHTML =
|
|
570
|
+
`<span class="t-ico">${svg(TOOL_ICON[name] ?? 'file')}</span>` +
|
|
571
|
+
`<span class="t-name">${escapeHtml(name)}</span>` +
|
|
572
|
+
`<span class="t-detail">${escapeHtml(detail)}</span>` +
|
|
573
|
+
`<span class="t-state">${stateHtml}</span>` +
|
|
574
|
+
(ms ? `<span class="t-time">${(ms / 1000).toFixed(1)}s</span>` : '');
|
|
575
|
+
return row;
|
|
576
|
+
}
|
|
577
|
+
|
|
526
578
|
function toolGroup(calls, results) {
|
|
527
579
|
const wrap = document.createElement('details');
|
|
528
580
|
wrap.className = 'work-group';
|
|
@@ -537,19 +589,13 @@ function toolGroup(calls, results) {
|
|
|
537
589
|
body.className = 'tool-group-body';
|
|
538
590
|
for (const call of calls) {
|
|
539
591
|
const result = results.get(call.id);
|
|
540
|
-
const row =
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
`<span class="t-state">${result ? (result.isError ? '失败' : escapeHtml(result.content?.slice(0, 40) ?? '完成')) : '已调用'}</span>`;
|
|
548
|
-
if (result?.content) {
|
|
549
|
-
row.classList.add('is-clickable');
|
|
550
|
-
row.title = '点击展开输出';
|
|
551
|
-
row.addEventListener('click', () => toggleToolOutput(row, result.content, Boolean(result.isError)));
|
|
552
|
-
}
|
|
592
|
+
const row = toolRowNode(
|
|
593
|
+
call.name,
|
|
594
|
+
toolSummaryText(call),
|
|
595
|
+
result ? (result.isError ? '失败' : '完成') : '已调用',
|
|
596
|
+
);
|
|
597
|
+
row.classList.toggle('is-error', Boolean(result?.isError));
|
|
598
|
+
if (result?.content) ensureToolOutput(row, result.content, Boolean(result.isError));
|
|
553
599
|
body.appendChild(row);
|
|
554
600
|
}
|
|
555
601
|
wrap.append(summary, body);
|
|
@@ -560,10 +606,12 @@ function reasoningDetails(text) {
|
|
|
560
606
|
const details = document.createElement('details');
|
|
561
607
|
details.className = 'think';
|
|
562
608
|
const summary = document.createElement('summary');
|
|
563
|
-
summary.innerHTML =
|
|
609
|
+
summary.innerHTML =
|
|
610
|
+
'<span class="think-title">思考</span>' +
|
|
611
|
+
`<span class="think-len">${Math.max(1, Math.round(text.length / 1000))}k 字</span>`;
|
|
564
612
|
const body = document.createElement('div');
|
|
565
613
|
body.className = 'think-body';
|
|
566
|
-
body.
|
|
614
|
+
body.innerHTML = markdown(text);
|
|
567
615
|
details.append(summary, body);
|
|
568
616
|
return details;
|
|
569
617
|
}
|
|
@@ -654,6 +702,8 @@ function renderEmpty() {
|
|
|
654
702
|
|
|
655
703
|
function renderThread() {
|
|
656
704
|
THREAD.innerHTML = '';
|
|
705
|
+
state.stickToBottom = true;
|
|
706
|
+
$('jumpLatest').hidden = true;
|
|
657
707
|
const messages = state.info?.session?.messages ?? [];
|
|
658
708
|
if (messages.length === 0) THREAD.appendChild(renderEmpty());
|
|
659
709
|
else {
|
|
@@ -673,6 +723,7 @@ function renderThread() {
|
|
|
673
723
|
|
|
674
724
|
function renderTurnMeta() {
|
|
675
725
|
const meta = $('threadMeta');
|
|
726
|
+
if (state.busy && state.status) { meta.textContent = state.status; return; }
|
|
676
727
|
const usage = state.info?.session?.usage;
|
|
677
728
|
if (!usage || (!usage.inputTokens && !usage.outputTokens)) { meta.textContent = ''; return; }
|
|
678
729
|
const parts = [`↑${usage.inputTokens} ↓${usage.outputTokens}`];
|
|
@@ -680,19 +731,37 @@ function renderTurnMeta() {
|
|
|
680
731
|
meta.textContent = parts.join(' · ');
|
|
681
732
|
}
|
|
682
733
|
|
|
683
|
-
function scrollToEnd(smooth = true) {
|
|
734
|
+
function scrollToEnd(smooth = true, force = false) {
|
|
735
|
+
if (!force && state.busy && !state.stickToBottom) return;
|
|
684
736
|
requestAnimationFrame(() => {
|
|
685
737
|
THREAD.scrollTo({ top: THREAD.scrollHeight, behavior: smooth ? 'smooth' : 'auto' });
|
|
686
738
|
});
|
|
687
739
|
}
|
|
688
740
|
|
|
741
|
+
function setStatus(text) {
|
|
742
|
+
state.status = text || '';
|
|
743
|
+
const hint = $('composerHint');
|
|
744
|
+
if (hint) {
|
|
745
|
+
hint.textContent = text || workspaceHint();
|
|
746
|
+
hint.dataset.kind = text ? 'live' : 'idle';
|
|
747
|
+
}
|
|
748
|
+
const meta = $('threadMeta');
|
|
749
|
+
if (meta && text && state.busy) meta.textContent = text;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
function workspaceHint() {
|
|
753
|
+
const info = state.info;
|
|
754
|
+
if (!info) return '';
|
|
755
|
+
return `工作区 ${info.workspace} · ${info.tools.length} 个工具 · shell=${info.permissions.shell} write=${info.permissions.write} network=${info.permissions.network}`;
|
|
756
|
+
}
|
|
757
|
+
|
|
689
758
|
function renderHeader() {
|
|
690
759
|
const info = state.info;
|
|
691
760
|
if (!info) return;
|
|
692
761
|
$('threadTitle').textContent = info.session.title || '新对话';
|
|
693
762
|
$('modelLabel').textContent = `${info.provider.name} / ${info.provider.model}`;
|
|
694
|
-
$('composerHint').textContent =
|
|
695
|
-
|
|
763
|
+
if (!state.busy) $('composerHint').textContent = workspaceHint();
|
|
764
|
+
else if (state.status) $('composerHint').textContent = state.status;
|
|
696
765
|
renderTurnMeta();
|
|
697
766
|
}
|
|
698
767
|
|
|
@@ -883,14 +952,31 @@ function grow() {
|
|
|
883
952
|
const input = $('input');
|
|
884
953
|
input.style.height = 'auto';
|
|
885
954
|
input.style.height = Math.min(input.scrollHeight, 220) + 'px';
|
|
886
|
-
$('sendBtn')
|
|
955
|
+
const send = $('sendBtn');
|
|
956
|
+
if (!state.busy) send.disabled = input.value.trim() === '';
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
function stopTurn() {
|
|
960
|
+
if (!state.busy) return;
|
|
961
|
+
setStatus('正在停止…');
|
|
962
|
+
controller?.abort();
|
|
963
|
+
void post('abort').catch(() => {});
|
|
887
964
|
}
|
|
888
965
|
|
|
889
966
|
function setBusy(busy) {
|
|
890
967
|
state.busy = busy;
|
|
891
|
-
$('
|
|
892
|
-
$('
|
|
968
|
+
const send = $('sendBtn');
|
|
969
|
+
const composer = $('composer');
|
|
970
|
+
composer?.classList.toggle('is-busy', busy);
|
|
971
|
+
// 发送键在原位切换成停止键,不再让用户去右上角找
|
|
972
|
+
send.innerHTML = busy ? svg('stop') : svg('send');
|
|
973
|
+
send.title = busy ? '停止生成' : '发送';
|
|
974
|
+
send.setAttribute('aria-label', busy ? '停止生成' : '发送');
|
|
975
|
+
send.dataset.mode = busy ? 'stop' : 'send';
|
|
976
|
+
send.disabled = busy ? false : $('input').value.trim() === '';
|
|
977
|
+
$('abortBtn').hidden = true;
|
|
893
978
|
document.body.style.cursor = busy ? 'progress' : '';
|
|
979
|
+
if (state.tabs?.length) renderTabs();
|
|
894
980
|
}
|
|
895
981
|
|
|
896
982
|
function askApproval(payload) {
|
|
@@ -917,6 +1003,7 @@ async function send() {
|
|
|
917
1003
|
const input = $('input');
|
|
918
1004
|
const text = input.value.trim();
|
|
919
1005
|
if (!text || state.busy) return;
|
|
1006
|
+
if (!state.info?.session) return;
|
|
920
1007
|
input.value = '';
|
|
921
1008
|
grow();
|
|
922
1009
|
closePalette();
|
|
@@ -927,11 +1014,17 @@ async function send() {
|
|
|
927
1014
|
return;
|
|
928
1015
|
}
|
|
929
1016
|
|
|
930
|
-
|
|
1017
|
+
const messages = state.info.session.messages ?? (state.info.session.messages = []);
|
|
1018
|
+
if (messages.length === 0 && state.info.session.title === '新对话') {
|
|
931
1019
|
state.info.session.title = text.slice(0, 40);
|
|
932
1020
|
renderHeader();
|
|
933
1021
|
}
|
|
934
|
-
|
|
1022
|
+
|
|
1023
|
+
// 首页空状态整块移除,否则第一条消息会被追加在 wordmark 下面
|
|
1024
|
+
THREAD.querySelector('.empty')?.remove();
|
|
1025
|
+
$('chatCard').classList.remove('home-mode');
|
|
1026
|
+
$('homeTips').hidden = true;
|
|
1027
|
+
messages.push({ role: 'user', content: text });
|
|
935
1028
|
|
|
936
1029
|
const userMsg = document.createElement('article');
|
|
937
1030
|
userMsg.className = 'msg user enter';
|
|
@@ -940,8 +1033,12 @@ async function send() {
|
|
|
940
1033
|
userBody.className = 'msg-body';
|
|
941
1034
|
userBody.textContent = text;
|
|
942
1035
|
userMsg.appendChild(userBody);
|
|
1036
|
+
messageActions(userMsg, text, 'user');
|
|
1037
|
+
const divider = document.createElement('div');
|
|
1038
|
+
divider.className = 'thread-divider';
|
|
1039
|
+
if (!THREAD.querySelector('.thread-divider')) THREAD.appendChild(divider);
|
|
943
1040
|
THREAD.appendChild(userMsg);
|
|
944
|
-
|
|
1041
|
+
scrollToEnd(false);
|
|
945
1042
|
|
|
946
1043
|
const botMsg = document.createElement('article');
|
|
947
1044
|
botMsg.className = 'msg assistant enter';
|
|
@@ -959,38 +1056,72 @@ async function send() {
|
|
|
959
1056
|
work.append(workSummary, workBody);
|
|
960
1057
|
work.classList.add('is-running');
|
|
961
1058
|
|
|
962
|
-
//
|
|
1059
|
+
// 思考过程:流式时就保持结构化,随时可折叠
|
|
963
1060
|
const reasoning = document.createElement('details');
|
|
964
|
-
reasoning.className = 'think';
|
|
1061
|
+
reasoning.className = 'think is-live';
|
|
965
1062
|
reasoning.hidden = true;
|
|
966
1063
|
reasoning.open = true;
|
|
967
1064
|
const reasonSummary = document.createElement('summary');
|
|
968
|
-
reasonSummary.innerHTML = '<span class="think-title">思考中…</span>';
|
|
1065
|
+
reasonSummary.innerHTML = '<span class="think-title">思考中…</span><span class="think-len"></span>';
|
|
969
1066
|
const reasonBody = document.createElement('div');
|
|
970
1067
|
reasonBody.className = 'think-body';
|
|
971
1068
|
reasoning.append(reasonSummary, reasonBody);
|
|
1069
|
+
// 用户手动收起后,后续流式内容不再强行展开
|
|
1070
|
+
reasonSummary.addEventListener('click', () => {
|
|
1071
|
+
reasoning.dataset.user = '1';
|
|
1072
|
+
});
|
|
972
1073
|
|
|
973
1074
|
const body = document.createElement('div');
|
|
974
1075
|
body.className = 'msg-body caret';
|
|
1076
|
+
body.setAttribute('aria-live', 'polite');
|
|
975
1077
|
const meta = document.createElement('div');
|
|
976
1078
|
meta.className = 'turn-meta';
|
|
977
1079
|
const working = document.createElement('div');
|
|
978
1080
|
working.className = 'working-row';
|
|
979
|
-
working.innerHTML = '<span class="wg-dot"></span><span class="shimmer">Banana 正在运行</span>';
|
|
1081
|
+
working.innerHTML = '<span class="wg-dot"></span><span class="shimmer working-text">Banana 正在运行</span>';
|
|
980
1082
|
botMsg.append(working, work, reasoning, body, meta);
|
|
981
1083
|
THREAD.appendChild(botMsg);
|
|
982
1084
|
|
|
983
1085
|
let reasoningStarted = 0;
|
|
1086
|
+
let reasoningText = '';
|
|
1087
|
+
let reasonPending = 0;
|
|
984
1088
|
let toolStarted = 0;
|
|
985
1089
|
let toolCount = 0;
|
|
986
1090
|
let toolErrors = false;
|
|
1091
|
+
const toolRows = new Map();
|
|
1092
|
+
|
|
1093
|
+
const paintReasoning = (final = false) => {
|
|
1094
|
+
reasonPending = 0;
|
|
1095
|
+
const text = reasoningText;
|
|
1096
|
+
reasonBody.innerHTML = markdown(text);
|
|
1097
|
+
const len = reasonSummary.querySelector('.think-len');
|
|
1098
|
+
if (len) len.textContent = text.length > 999 ? `${(text.length / 1000).toFixed(1)}k 字` : `${text.length} 字`;
|
|
1099
|
+
if (final) reasoning.classList.remove('is-live');
|
|
1100
|
+
// 只有用户没有上滚时才跟随最新思考
|
|
1101
|
+
const nearBottom = reasonBody.scrollHeight - reasonBody.scrollTop - reasonBody.clientHeight < 40;
|
|
1102
|
+
if (nearBottom) reasonBody.scrollTop = reasonBody.scrollHeight;
|
|
1103
|
+
};
|
|
1104
|
+
const scheduleReasoning = () => {
|
|
1105
|
+
if (!reasonPending) reasonPending = requestAnimationFrame(() => paintReasoning(false));
|
|
1106
|
+
};
|
|
1107
|
+
|
|
987
1108
|
const finishReasoning = () => {
|
|
988
1109
|
if (reasoning.hidden || reasoning.dataset.done === '1') return;
|
|
989
1110
|
reasoning.dataset.done = '1';
|
|
990
|
-
reasoning.
|
|
1111
|
+
reasoning.classList.remove('is-live');
|
|
1112
|
+
if (reasonPending) cancelAnimationFrame(reasonPending);
|
|
1113
|
+
paintReasoning(true);
|
|
1114
|
+
if (reasoning.dataset.user !== '1') reasoning.open = false;
|
|
991
1115
|
const seconds = reasoningStarted ? ((Date.now() - reasoningStarted) / 1000).toFixed(1) : '0';
|
|
992
1116
|
reasonSummary.querySelector('.think-title').textContent = `思考 · ${seconds}s`;
|
|
993
1117
|
};
|
|
1118
|
+
|
|
1119
|
+
const setWorking = (text) => {
|
|
1120
|
+
const node = working.querySelector('.working-text');
|
|
1121
|
+
if (node) node.textContent = text;
|
|
1122
|
+
working.hidden = false;
|
|
1123
|
+
};
|
|
1124
|
+
|
|
994
1125
|
const finishWork = () => {
|
|
995
1126
|
if (work.hidden || work.dataset.done === '1') return;
|
|
996
1127
|
work.dataset.done = '1';
|
|
@@ -1008,17 +1139,33 @@ async function send() {
|
|
|
1008
1139
|
|
|
1009
1140
|
let buffer = '';
|
|
1010
1141
|
let pending = 0;
|
|
1142
|
+
let lastPaint = 0;
|
|
1011
1143
|
let streamEnded = false;
|
|
1144
|
+
const renderStream = () => markdown(buffer);
|
|
1145
|
+
|
|
1012
1146
|
const paint = () => {
|
|
1013
1147
|
pending = 0;
|
|
1014
|
-
|
|
1015
|
-
|
|
1148
|
+
const now = performance.now();
|
|
1149
|
+
// 流式 markdown 限制到约 12fps,避免长回答每帧重排 + 高亮
|
|
1150
|
+
if (!streamEnded && now - lastPaint < 80) {
|
|
1151
|
+
schedule();
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
lastPaint = now;
|
|
1155
|
+
const atBottom = THREAD.scrollHeight - THREAD.scrollTop - THREAD.clientHeight < 90;
|
|
1156
|
+
body.innerHTML = renderStream();
|
|
1157
|
+
// 流式过程中保持光标
|
|
1158
|
+
if (!streamEnded) body.classList.add('caret');
|
|
1159
|
+
if (atBottom) scrollToEnd(false);
|
|
1016
1160
|
};
|
|
1017
1161
|
const schedule = () => {
|
|
1018
1162
|
if (!pending) pending = requestAnimationFrame(paint);
|
|
1019
1163
|
};
|
|
1020
1164
|
|
|
1021
1165
|
setBusy(true);
|
|
1166
|
+
const composer = $('composer');
|
|
1167
|
+
composer.classList.add('is-busy');
|
|
1168
|
+
setStatus('正在连接模型…');
|
|
1022
1169
|
controller = new AbortController();
|
|
1023
1170
|
const metaLine = (label, value) => {
|
|
1024
1171
|
const span = document.createElement('span');
|
|
@@ -1053,6 +1200,7 @@ async function send() {
|
|
|
1053
1200
|
if (event.type === 'text') {
|
|
1054
1201
|
finishReasoning();
|
|
1055
1202
|
working.hidden = true;
|
|
1203
|
+
setStatus('正在输出…');
|
|
1056
1204
|
buffer += event.chunk;
|
|
1057
1205
|
schedule();
|
|
1058
1206
|
} else if (event.type === 'reasoning') {
|
|
@@ -1062,7 +1210,12 @@ async function send() {
|
|
|
1062
1210
|
reasoning.open = true;
|
|
1063
1211
|
}
|
|
1064
1212
|
reasoning.hidden = false;
|
|
1065
|
-
|
|
1213
|
+
if (reasoning.dataset.user !== '1') reasoning.open = true;
|
|
1214
|
+
reasoningText += event.chunk;
|
|
1215
|
+
setWorking('正在思考…');
|
|
1216
|
+
setStatus('思考中…');
|
|
1217
|
+
working.hidden = false;
|
|
1218
|
+
scheduleReasoning();
|
|
1066
1219
|
} else if (event.type === 'tool_start') {
|
|
1067
1220
|
if (!toolStarted) toolStarted = Date.now();
|
|
1068
1221
|
toolCount += 1;
|
|
@@ -1072,40 +1225,78 @@ async function send() {
|
|
|
1072
1225
|
workSummary.querySelector('.wg-state').textContent = '';
|
|
1073
1226
|
work.classList.add('is-updating');
|
|
1074
1227
|
setTimeout(() => work.classList.remove('is-updating'), 220);
|
|
1075
|
-
const
|
|
1076
|
-
row
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1228
|
+
const command = typeof event.input?.command === 'string' ? event.input.command : event.detail;
|
|
1229
|
+
const row = toolRowNode(
|
|
1230
|
+
event.name,
|
|
1231
|
+
command,
|
|
1232
|
+
'<span class="spin"></span>',
|
|
1233
|
+
);
|
|
1234
|
+
row.dataset.id = event.id;
|
|
1235
|
+
row.dataset.started = String(Date.now());
|
|
1236
|
+
const time = document.createElement('span');
|
|
1237
|
+
time.className = 't-time';
|
|
1238
|
+
time.textContent = '0.0s';
|
|
1239
|
+
row.appendChild(time);
|
|
1240
|
+
row._timer = setInterval(() => {
|
|
1241
|
+
const began = Number(row.dataset.started);
|
|
1242
|
+
time.textContent = `${((Date.now() - began) / 1000).toFixed(1)}s`;
|
|
1243
|
+
}, 400);
|
|
1244
|
+
toolRows.set(event.id, row);
|
|
1082
1245
|
workBody.appendChild(row);
|
|
1246
|
+
if (command) ensureToolOutput(row, `$ ${command}\n`, false);
|
|
1247
|
+
setWorking(`正在运行 ${event.name}…`);
|
|
1248
|
+
setStatus(`运行工具 ${event.name}…`);
|
|
1249
|
+
working.hidden = false;
|
|
1083
1250
|
scrollToEnd(false);
|
|
1251
|
+
} else if (event.type === 'tool_output') {
|
|
1252
|
+
const row = toolRows.get(event.id);
|
|
1253
|
+
if (row) {
|
|
1254
|
+
row._out = `${row._out ?? ''}${event.chunk}`;
|
|
1255
|
+
if (row._out.length > 12000) row._out = row._out.slice(-12000);
|
|
1256
|
+
const out = ensureToolOutput(row, row._out);
|
|
1257
|
+
if (out.hidden) {
|
|
1258
|
+
out.hidden = false;
|
|
1259
|
+
row.classList.add('is-open');
|
|
1260
|
+
}
|
|
1261
|
+
out.scrollTop = out.scrollHeight;
|
|
1262
|
+
const state = row.querySelector('.t-state');
|
|
1263
|
+
if (state && !state.querySelector('.spin')) state.innerHTML = '<span class="spin"></span>';
|
|
1264
|
+
setStatus(`输出中 · ${row.querySelector('.t-name')?.textContent ?? ''}`);
|
|
1265
|
+
}
|
|
1084
1266
|
} else if (event.type === 'tool_end') {
|
|
1085
|
-
const
|
|
1086
|
-
const row = rows[rows.length - 1];
|
|
1267
|
+
const row = toolRows.get(event.id) ?? [...toolRows.values()].pop();
|
|
1087
1268
|
if (row) {
|
|
1269
|
+
clearInterval(row._timer);
|
|
1270
|
+
row.dataset.done = '1';
|
|
1088
1271
|
row.querySelector('.t-state').innerHTML = event.ok ? svg('check') : svg('x');
|
|
1089
1272
|
row.classList.toggle('is-error', !event.ok);
|
|
1090
1273
|
if (!event.ok) toolErrors = true;
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
row.
|
|
1274
|
+
const time = row.querySelector('.t-time');
|
|
1275
|
+
if (time && event.ms) time.textContent = `${(event.ms / 1000).toFixed(1)}s`;
|
|
1276
|
+
const outText = row._out || event.detail || '';
|
|
1277
|
+
if (outText) {
|
|
1278
|
+
const out = ensureToolOutput(row, outText, !event.ok);
|
|
1279
|
+
if (!event.ok) {
|
|
1280
|
+
out.hidden = false;
|
|
1281
|
+
row.classList.add('is-open');
|
|
1282
|
+
}
|
|
1096
1283
|
}
|
|
1097
|
-
if (event.
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1284
|
+
if (!event.ok) {
|
|
1285
|
+
work.open = true;
|
|
1286
|
+
setWorking('工具执行失败,已展开输出');
|
|
1287
|
+
} else {
|
|
1288
|
+
setWorking('正在继续…');
|
|
1101
1289
|
}
|
|
1102
1290
|
}
|
|
1103
1291
|
} else if (event.type === 'step') {
|
|
1104
|
-
|
|
1292
|
+
setStatus(`第 ${event.step} 步 · 处理中`);
|
|
1293
|
+
setWorking(`第 ${event.step} 步 · 处理中`);
|
|
1294
|
+
working.hidden = false;
|
|
1105
1295
|
} else if (event.type === 'status') {
|
|
1106
1296
|
if (event.message) {
|
|
1107
|
-
|
|
1108
|
-
|
|
1297
|
+
setStatus(event.message);
|
|
1298
|
+
setWorking(event.message);
|
|
1299
|
+
working.hidden = false;
|
|
1109
1300
|
}
|
|
1110
1301
|
} else if (event.type === 'approval') {
|
|
1111
1302
|
const allowed = await askApproval(event);
|
|
@@ -1122,12 +1313,18 @@ async function send() {
|
|
|
1122
1313
|
} else if (event.type === 'done') {
|
|
1123
1314
|
finishReasoning();
|
|
1124
1315
|
finishWork();
|
|
1316
|
+
if (pending) {
|
|
1317
|
+
cancelAnimationFrame(pending);
|
|
1318
|
+
pending = 0;
|
|
1319
|
+
}
|
|
1125
1320
|
body.classList.remove('caret');
|
|
1126
1321
|
streamEnded = true;
|
|
1127
1322
|
if (event.error) body.innerHTML = markdown(`**请求失败** ${escapeHtml(event.error)}`);
|
|
1128
1323
|
else if (!buffer.trim()) body.innerHTML = markdown('这一轮没有返回内容。');
|
|
1129
1324
|
else body.innerHTML = markdown(buffer);
|
|
1130
|
-
if (buffer.trim()
|
|
1325
|
+
if (buffer.trim() && !botMsg.querySelector('.msg-actions')) {
|
|
1326
|
+
messageActions(botMsg, buffer, 'assistant');
|
|
1327
|
+
}
|
|
1131
1328
|
metaLine('步数', event.steps);
|
|
1132
1329
|
metaLine('用时', (event.ms / 1000).toFixed(1) + 's');
|
|
1133
1330
|
if (event.cost && event.cost !== '≈$0') metaLine('花费', event.cost);
|
|
@@ -1136,7 +1333,7 @@ async function send() {
|
|
|
1136
1333
|
state.info.session.messages[state.info.session.messages.length - 1] = {
|
|
1137
1334
|
role: 'assistant',
|
|
1138
1335
|
content: buffer,
|
|
1139
|
-
reasoning:
|
|
1336
|
+
reasoning: reasoningText || undefined,
|
|
1140
1337
|
};
|
|
1141
1338
|
const { sessions } = await get('sessions');
|
|
1142
1339
|
state.sessions = sessions;
|
|
@@ -1160,16 +1357,20 @@ async function send() {
|
|
|
1160
1357
|
}
|
|
1161
1358
|
} catch (error) {
|
|
1162
1359
|
body.classList.remove('caret');
|
|
1163
|
-
body.innerHTML = markdown(`**中断** ${escapeHtml(error.message)}`);
|
|
1360
|
+
if (!buffer.trim()) body.innerHTML = markdown(`**中断** ${escapeHtml(error.message)}`);
|
|
1164
1361
|
await refresh();
|
|
1165
1362
|
} finally {
|
|
1166
1363
|
finishReasoning();
|
|
1167
1364
|
finishWork();
|
|
1365
|
+
for (const row of toolRows.values()) clearInterval(row._timer);
|
|
1168
1366
|
working.hidden = true;
|
|
1367
|
+
body.classList.remove('caret');
|
|
1169
1368
|
controller = null;
|
|
1170
1369
|
setBusy(false);
|
|
1171
|
-
|
|
1370
|
+
$('composer').classList.remove('is-busy');
|
|
1371
|
+
setStatus(null);
|
|
1172
1372
|
renderHeader();
|
|
1373
|
+
scrollToEnd();
|
|
1173
1374
|
if (state.review.open && state.review.mode === 'changes') void loadChanges(true);
|
|
1174
1375
|
}
|
|
1175
1376
|
}
|
|
@@ -1417,9 +1618,130 @@ const SETTINGS_NAV = [
|
|
|
1417
1618
|
{ id: 'about', label: '关于', icon: 'info' },
|
|
1418
1619
|
];
|
|
1419
1620
|
|
|
1621
|
+
function closeModelPop() {
|
|
1622
|
+
const pop = $('modelPop');
|
|
1623
|
+
if (!pop) return;
|
|
1624
|
+
pop.remove();
|
|
1625
|
+
document.removeEventListener('click', onModelPopOutside, true);
|
|
1626
|
+
document.removeEventListener('keydown', onModelPopKey, true);
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
function onModelPopOutside(event) {
|
|
1630
|
+
if (event.target.closest('#modelPop, #modelBtn')) return;
|
|
1631
|
+
closeModelPop();
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
function onModelPopKey(event) {
|
|
1635
|
+
if (event.key === 'Escape') {
|
|
1636
|
+
event.preventDefault();
|
|
1637
|
+
closeModelPop();
|
|
1638
|
+
$('modelBtn')?.focus();
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
function toggleModelPop() {
|
|
1643
|
+
if ($('modelPop')) return closeModelPop();
|
|
1644
|
+
const info = state.info;
|
|
1645
|
+
if (!info) return;
|
|
1646
|
+
const pop = document.createElement('div');
|
|
1647
|
+
pop.className = 'model-pop';
|
|
1648
|
+
pop.id = 'modelPop';
|
|
1649
|
+
pop.setAttribute('role', 'dialog');
|
|
1650
|
+
pop.setAttribute('aria-label', '切换模型');
|
|
1651
|
+
const head = document.createElement('div');
|
|
1652
|
+
head.className = 'mp-head';
|
|
1653
|
+
head.innerHTML = '<span>模型</span><span class="mp-sub">切换后新消息生效</span>';
|
|
1654
|
+
pop.appendChild(head);
|
|
1655
|
+
|
|
1656
|
+
for (const provider of info.providers ?? []) {
|
|
1657
|
+
const row = document.createElement('button');
|
|
1658
|
+
row.type = 'button';
|
|
1659
|
+
row.className = `mp-row${provider.current ? ' is-on' : ''}`;
|
|
1660
|
+
row.innerHTML =
|
|
1661
|
+
`<span class="mp-name">${escapeHtml(provider.name)}</span>` +
|
|
1662
|
+
`<span class="mp-model">${escapeHtml(provider.model)}</span>` +
|
|
1663
|
+
(provider.current ? `<span class="mp-check">${svg('check')}</span>` : '');
|
|
1664
|
+
row.addEventListener('click', async () => {
|
|
1665
|
+
if (provider.current) return closeModelPop();
|
|
1666
|
+
try {
|
|
1667
|
+
await saveSetting('provider', { name: provider.name });
|
|
1668
|
+
await refresh(false);
|
|
1669
|
+
closeModelPop();
|
|
1670
|
+
toast(`已切换到 ${provider.name}`);
|
|
1671
|
+
} catch (error) {
|
|
1672
|
+
toast('切换失败:' + error.message);
|
|
1673
|
+
}
|
|
1674
|
+
});
|
|
1675
|
+
pop.appendChild(row);
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
const form = document.createElement('div');
|
|
1679
|
+
form.className = 'mp-form';
|
|
1680
|
+
const input = document.createElement('input');
|
|
1681
|
+
input.type = 'text';
|
|
1682
|
+
input.value = info.provider.model;
|
|
1683
|
+
input.placeholder = '模型名';
|
|
1684
|
+
input.setAttribute('aria-label', '模型名');
|
|
1685
|
+
const save = document.createElement('button');
|
|
1686
|
+
save.type = 'button';
|
|
1687
|
+
save.className = 'btn tiny primary';
|
|
1688
|
+
save.textContent = '保存';
|
|
1689
|
+
save.addEventListener('click', async () => {
|
|
1690
|
+
const value = input.value.trim();
|
|
1691
|
+
if (!value) return toast('请填写模型名');
|
|
1692
|
+
try {
|
|
1693
|
+
await saveSetting('model', { value });
|
|
1694
|
+
await refresh(false);
|
|
1695
|
+
closeModelPop();
|
|
1696
|
+
toast('模型已更新');
|
|
1697
|
+
} catch (error) {
|
|
1698
|
+
toast('保存失败:' + error.message);
|
|
1699
|
+
}
|
|
1700
|
+
});
|
|
1701
|
+
input.addEventListener('keydown', (event) => {
|
|
1702
|
+
if (event.key === 'Enter') {
|
|
1703
|
+
event.preventDefault();
|
|
1704
|
+
save.click();
|
|
1705
|
+
}
|
|
1706
|
+
});
|
|
1707
|
+
form.append(input, save);
|
|
1708
|
+
pop.appendChild(form);
|
|
1709
|
+
|
|
1710
|
+
const more = document.createElement('button');
|
|
1711
|
+
more.type = 'button';
|
|
1712
|
+
more.className = 'mp-more';
|
|
1713
|
+
more.textContent = '更多模型与 Key 设置';
|
|
1714
|
+
more.addEventListener('click', () => {
|
|
1715
|
+
closeModelPop();
|
|
1716
|
+
openSettings('model');
|
|
1717
|
+
});
|
|
1718
|
+
pop.appendChild(more);
|
|
1719
|
+
document.body.appendChild(pop);
|
|
1720
|
+
|
|
1721
|
+
const rect = $('modelBtn').getBoundingClientRect();
|
|
1722
|
+
const width = Math.min(340, window.innerWidth - 16);
|
|
1723
|
+
pop.style.width = `${width}px`;
|
|
1724
|
+
pop.style.left = `${Math.max(8, Math.min(rect.left, window.innerWidth - width - 8))}px`;
|
|
1725
|
+
if (rect.top > 300) {
|
|
1726
|
+
pop.style.bottom = `${Math.max(8, window.innerHeight - rect.top + 8)}px`;
|
|
1727
|
+
pop.style.maxHeight = `${Math.max(180, rect.top - 16)}px`;
|
|
1728
|
+
} else {
|
|
1729
|
+
pop.style.top = `${Math.max(8, rect.bottom + 8)}px`;
|
|
1730
|
+
pop.style.maxHeight = `${Math.max(180, window.innerHeight - rect.bottom - 16)}px`;
|
|
1731
|
+
}
|
|
1732
|
+
pop.style.overflowY = 'auto';
|
|
1733
|
+
void pop.offsetHeight;
|
|
1734
|
+
pop.classList.add('is-on');
|
|
1735
|
+
setTimeout(() => {
|
|
1736
|
+
document.addEventListener('click', onModelPopOutside, true);
|
|
1737
|
+
document.addEventListener('keydown', onModelPopKey, true);
|
|
1738
|
+
}, 0);
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1420
1741
|
function openSettings(category) {
|
|
1421
1742
|
if (category) state.settingsCategory = category;
|
|
1422
1743
|
state.settingsScroll = 0;
|
|
1744
|
+
state.settingsReturn = document.activeElement;
|
|
1423
1745
|
renderSettings();
|
|
1424
1746
|
const sheet = $('settingsSheet');
|
|
1425
1747
|
sheet.classList.remove('is-closing');
|
|
@@ -1436,7 +1758,32 @@ function closeSettings() {
|
|
|
1436
1758
|
if (sheet.hidden) return;
|
|
1437
1759
|
state.settingsScroll = $('settingsBody').scrollTop;
|
|
1438
1760
|
void hideAnimated(sheet, 'is-closing', 170).then(syncOverlayState);
|
|
1439
|
-
|
|
1761
|
+
const back = state.settingsReturn;
|
|
1762
|
+
state.settingsReturn = null;
|
|
1763
|
+
if (back && back.isConnected) back.focus();
|
|
1764
|
+
else $('input')?.focus();
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
function trapSettingsFocus(event) {
|
|
1768
|
+
const sheet = $('settingsSheet');
|
|
1769
|
+
if (sheet.hidden) return false;
|
|
1770
|
+
const focusable = [...sheet.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')]
|
|
1771
|
+
.filter((node) => !node.disabled && node.offsetParent !== null);
|
|
1772
|
+
if (!focusable.length) return false;
|
|
1773
|
+
const first = focusable[0];
|
|
1774
|
+
const last = focusable[focusable.length - 1];
|
|
1775
|
+
const active = document.activeElement;
|
|
1776
|
+
if (event.shiftKey && (active === first || !sheet.contains(active))) {
|
|
1777
|
+
event.preventDefault();
|
|
1778
|
+
last.focus();
|
|
1779
|
+
return true;
|
|
1780
|
+
}
|
|
1781
|
+
if (!event.shiftKey && (active === last || !sheet.contains(active))) {
|
|
1782
|
+
event.preventDefault();
|
|
1783
|
+
first.focus();
|
|
1784
|
+
return true;
|
|
1785
|
+
}
|
|
1786
|
+
return false;
|
|
1440
1787
|
}
|
|
1441
1788
|
|
|
1442
1789
|
function settingsCard() {
|
|
@@ -2000,7 +2347,7 @@ function renderAboutSettings(body) {
|
|
|
2000
2347
|
// ---------------- 外壳:侧栏 / Review / 终端 dock ----------------
|
|
2001
2348
|
const SHELL_STORAGE = {
|
|
2002
2349
|
sidebarWidth: 'banana.sidebar.width',
|
|
2003
|
-
sidebarOpen: 'banana.sidebar.open',
|
|
2350
|
+
sidebarOpen: 'banana.sidebar.open.v2',
|
|
2004
2351
|
reviewWidth: 'banana.review.width',
|
|
2005
2352
|
reviewMode: 'banana.review.mode',
|
|
2006
2353
|
tabState: 'banana.tabs.v1',
|
|
@@ -2016,16 +2363,23 @@ function applySidebarWidth(width) {
|
|
|
2016
2363
|
|
|
2017
2364
|
function setSidebar(open) {
|
|
2018
2365
|
state.sidebar.open = Boolean(open);
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2366
|
+
const narrow = window.matchMedia('(max-width: 900px)').matches;
|
|
2367
|
+
const sidebar = $('sidebar');
|
|
2368
|
+
sidebar.classList.toggle('open', state.sidebar.open && narrow);
|
|
2369
|
+
// 桌面端收起 = 真正隐藏;窄屏收起 = 平移出屏,但仍需 inert
|
|
2370
|
+
sidebar.hidden = !state.sidebar.open && !narrow;
|
|
2371
|
+
sidebar.inert = !state.sidebar.open;
|
|
2372
|
+
sidebar.setAttribute('aria-hidden', String(!state.sidebar.open));
|
|
2373
|
+
$('toggleSidebar').classList.toggle('is-on', state.sidebar.open);
|
|
2374
|
+
$('toggleSidebar').setAttribute('aria-expanded', String(state.sidebar.open));
|
|
2022
2375
|
try {
|
|
2023
2376
|
localStorage.setItem(SHELL_STORAGE.sidebarOpen, state.sidebar.open ? '1' : '0');
|
|
2024
2377
|
} catch {}
|
|
2025
2378
|
}
|
|
2026
2379
|
|
|
2027
2380
|
function toggleSidebar() {
|
|
2028
|
-
|
|
2381
|
+
const narrow = window.matchMedia('(max-width: 900px)').matches;
|
|
2382
|
+
setSidebar(!state.sidebar.open || (narrow && !$('sidebar').classList.contains('open')));
|
|
2029
2383
|
}
|
|
2030
2384
|
|
|
2031
2385
|
function applyReviewWidth(width) {
|
|
@@ -2052,13 +2406,22 @@ function setReviewMode(mode) {
|
|
|
2052
2406
|
}
|
|
2053
2407
|
}
|
|
2054
2408
|
|
|
2409
|
+
function syncReviewScrim() {
|
|
2410
|
+
const scrim = $('reviewScrim');
|
|
2411
|
+
if (!scrim) return;
|
|
2412
|
+
const overlay = window.matchMedia('(max-width: 1180px)').matches;
|
|
2413
|
+
scrim.hidden = !(state.review.open && overlay);
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2055
2416
|
function openReview(mode = 'changes') {
|
|
2056
2417
|
state.review.open = true;
|
|
2418
|
+
state.reviewRestore = document.activeElement;
|
|
2057
2419
|
const panel = $('reviewPanel');
|
|
2058
2420
|
panel.classList.remove('is-closing');
|
|
2059
2421
|
panel.hidden = false;
|
|
2060
2422
|
applyReviewWidth(state.review.width);
|
|
2061
2423
|
setReviewMode(mode);
|
|
2424
|
+
syncReviewScrim();
|
|
2062
2425
|
syncOverlayState();
|
|
2063
2426
|
}
|
|
2064
2427
|
|
|
@@ -2067,12 +2430,16 @@ function closeReview() {
|
|
|
2067
2430
|
if (!state.review.open) return;
|
|
2068
2431
|
state.review.open = false;
|
|
2069
2432
|
panel.classList.add('is-closing');
|
|
2433
|
+
$('reviewScrim').hidden = true;
|
|
2070
2434
|
setTimeout(() => {
|
|
2071
2435
|
if (state.review.open) return;
|
|
2072
2436
|
panel.hidden = true;
|
|
2073
2437
|
panel.classList.remove('is-closing');
|
|
2074
2438
|
syncOverlayState();
|
|
2075
|
-
|
|
2439
|
+
const back = state.reviewRestore;
|
|
2440
|
+
state.reviewRestore = null;
|
|
2441
|
+
if (back && back.isConnected) back.focus();
|
|
2442
|
+
else $('input')?.focus();
|
|
2076
2443
|
termFitActive();
|
|
2077
2444
|
}, 200);
|
|
2078
2445
|
}
|
|
@@ -2088,7 +2455,8 @@ function initShell() {
|
|
|
2088
2455
|
const dh = Number(localStorage.getItem(SHELL_STORAGE.dockHeight));
|
|
2089
2456
|
if (dh) state.dock.height = Math.max(120, Math.min(dh, window.innerHeight * 0.6));
|
|
2090
2457
|
const openSidebar = localStorage.getItem(SHELL_STORAGE.sidebarOpen);
|
|
2091
|
-
|
|
2458
|
+
// 历史栏默认收起:顶部标签才是主入口
|
|
2459
|
+
state.sidebar.open = openSidebar === '1';
|
|
2092
2460
|
} catch {
|
|
2093
2461
|
applySidebarWidth(344);
|
|
2094
2462
|
applyReviewWidth(520);
|
|
@@ -2097,6 +2465,7 @@ function initShell() {
|
|
|
2097
2465
|
$('reviewTabChanges').addEventListener('click', () => setReviewMode('changes'));
|
|
2098
2466
|
$('reviewTabFiles').addEventListener('click', () => setReviewMode('files'));
|
|
2099
2467
|
$('reviewClose').addEventListener('click', closeReview);
|
|
2468
|
+
$('reviewScrim').addEventListener('click', closeReview);
|
|
2100
2469
|
$('reviewRefresh').addEventListener('click', () => {
|
|
2101
2470
|
state.changes = null;
|
|
2102
2471
|
if (state.review.mode === 'changes') void loadChanges(true);
|
|
@@ -2134,6 +2503,8 @@ function initShell() {
|
|
|
2134
2503
|
});
|
|
2135
2504
|
window.addEventListener('resize', () => {
|
|
2136
2505
|
applyReviewWidth(state.review.width);
|
|
2506
|
+
syncReviewScrim();
|
|
2507
|
+
setSidebar(state.sidebar.open);
|
|
2137
2508
|
termFitActive();
|
|
2138
2509
|
});
|
|
2139
2510
|
}
|
|
@@ -2798,7 +3169,30 @@ function bindTerminal() {
|
|
|
2798
3169
|
});
|
|
2799
3170
|
$('termMore').addEventListener('click', (event) => {
|
|
2800
3171
|
event.stopPropagation();
|
|
2801
|
-
|
|
3172
|
+
const menu = $('termMenu');
|
|
3173
|
+
const willOpen = menu.hidden;
|
|
3174
|
+
menu.hidden = !willOpen;
|
|
3175
|
+
if (willOpen) {
|
|
3176
|
+
// fixed 定位:终端 dock 有 overflow:hidden,菜单贴着头部放会被裁掉
|
|
3177
|
+
const rect = $('termMore').getBoundingClientRect();
|
|
3178
|
+
const below = window.innerHeight - rect.bottom - 12;
|
|
3179
|
+
const above = rect.top - 12;
|
|
3180
|
+
menu.style.position = 'fixed';
|
|
3181
|
+
menu.style.right = `${Math.max(8, window.innerWidth - rect.right)}px`;
|
|
3182
|
+
if (below >= 150 || below >= above) {
|
|
3183
|
+
menu.style.top = `${Math.round(rect.bottom + 4)}px`;
|
|
3184
|
+
menu.style.bottom = 'auto';
|
|
3185
|
+
menu.style.maxHeight = `${Math.max(90, below)}px`;
|
|
3186
|
+
} else {
|
|
3187
|
+
menu.style.top = 'auto';
|
|
3188
|
+
menu.style.bottom = `${Math.max(8, Math.round(window.innerHeight - rect.top + 4))}px`;
|
|
3189
|
+
menu.style.maxHeight = `${Math.max(90, above)}px`;
|
|
3190
|
+
}
|
|
3191
|
+
menu.style.overflowY = 'auto';
|
|
3192
|
+
$('termMore').setAttribute('aria-expanded', 'true');
|
|
3193
|
+
} else {
|
|
3194
|
+
$('termMore').setAttribute('aria-expanded', 'false');
|
|
3195
|
+
}
|
|
2802
3196
|
});
|
|
2803
3197
|
$('termAnalyze').addEventListener('click', () => {
|
|
2804
3198
|
closeTermMenu();
|
|
@@ -3181,8 +3575,21 @@ function bind() {
|
|
|
3181
3575
|
$('searchBtn').innerHTML = svg('search');
|
|
3182
3576
|
$('sendBtn').innerHTML = svg('send');
|
|
3183
3577
|
$('abortBtn').innerHTML = svg('stop');
|
|
3184
|
-
$('toggleSidebar').innerHTML = '<svg class="brand-mark" viewBox="0 0 24 24" aria-hidden="true"><path d="M7 4.6c2.6-.4 4.9.5 6.3 2.6M12.3 7.2c1.4-2.1 3.7-3 6.3-2.6-1.1 1.6-1.2 3.1-.4 4.6.8 1.5.8 3-.1 4.5-1.1 2-3.3 3.5-5.9 4.3-2.3.7-4.7.7-7.1 0"/><path d="M7.2 18c-1.1-2-1.2-4-.4-6 .9-2.3 2.5-3.7 4.7-4.2"/></svg>';
|
|
3185
3578
|
$('closeSettings').innerHTML = svg('x');
|
|
3579
|
+
$('toggleSidebar').innerHTML = svg('history');
|
|
3580
|
+
$('toggleSidebar').title = '历史会话(Ctrl+B)';
|
|
3581
|
+
$('attachBtn').innerHTML = svg('attach');
|
|
3582
|
+
$('jumpLatest').innerHTML = svg('arrowDown');
|
|
3583
|
+
$('abortBtn').addEventListener('click', stopTurn);
|
|
3584
|
+
$('modelBtn').addEventListener('click', (event) => {
|
|
3585
|
+
event.stopPropagation();
|
|
3586
|
+
toggleModelPop();
|
|
3587
|
+
});
|
|
3588
|
+
$('attachBtn').addEventListener('click', () => $('attachInput').click());
|
|
3589
|
+
$('attachInput').addEventListener('change', async () => {
|
|
3590
|
+
for (const file of $('attachInput').files ?? []) await attach(file);
|
|
3591
|
+
$('attachInput').value = '';
|
|
3592
|
+
});
|
|
3186
3593
|
$('reviewClose').innerHTML = svg('x');
|
|
3187
3594
|
$('reviewRefresh').innerHTML = svg('refresh');
|
|
3188
3595
|
$('filesBtn').innerHTML = svg('panel');
|
|
@@ -3207,14 +3614,14 @@ function bind() {
|
|
|
3207
3614
|
renderHeader();
|
|
3208
3615
|
renderSidebar();
|
|
3209
3616
|
renderThread();
|
|
3617
|
+
if (state.dock.open) termClose();
|
|
3618
|
+
closeSidebarIfOverlay();
|
|
3210
3619
|
setActiveTab(state.info?.session?.id ?? null);
|
|
3211
3620
|
$('input').focus();
|
|
3212
3621
|
} catch (error) {
|
|
3213
3622
|
toast('新建对话失败:' + (error?.message ?? error));
|
|
3214
3623
|
}
|
|
3215
3624
|
});
|
|
3216
|
-
$('abortBtn').addEventListener('click', async () => { controller?.abort(); await post('abort'); });
|
|
3217
|
-
$('modelBtn').addEventListener('click', () => openSettings());
|
|
3218
3625
|
$('openSettings').addEventListener('click', () => openSettings());
|
|
3219
3626
|
$('closeSettings').addEventListener('click', closeSettings);
|
|
3220
3627
|
$('settingsSheet').addEventListener('click', (event) => {
|
|
@@ -3270,6 +3677,20 @@ function bind() {
|
|
|
3270
3677
|
});
|
|
3271
3678
|
|
|
3272
3679
|
$('composer').addEventListener('submit', (event) => { event.preventDefault(); send(); });
|
|
3680
|
+
$('sendBtn').addEventListener('click', () => {
|
|
3681
|
+
if (state.busy) stopTurn();
|
|
3682
|
+
else send();
|
|
3683
|
+
});
|
|
3684
|
+
$('jumpLatest').addEventListener('click', () => {
|
|
3685
|
+
state.stickToBottom = true;
|
|
3686
|
+
scrollToEnd(true);
|
|
3687
|
+
});
|
|
3688
|
+
THREAD.addEventListener('scroll', () => {
|
|
3689
|
+
const atBottom = THREAD.scrollHeight - THREAD.scrollTop - THREAD.clientHeight < 90;
|
|
3690
|
+
state.stickToBottom = atBottom;
|
|
3691
|
+
const hasMessages = Boolean(THREAD.querySelector('.msg'));
|
|
3692
|
+
$('jumpLatest').hidden = atBottom || !hasMessages;
|
|
3693
|
+
});
|
|
3273
3694
|
$('input').addEventListener('input', () => {
|
|
3274
3695
|
grow();
|
|
3275
3696
|
const value = $('input').value;
|
|
@@ -3319,12 +3740,28 @@ function bind() {
|
|
|
3319
3740
|
});
|
|
3320
3741
|
|
|
3321
3742
|
document.addEventListener('keydown', (event) => {
|
|
3743
|
+
if (event.key === 'Tab' && trapSettingsFocus(event)) return;
|
|
3322
3744
|
if ((event.ctrlKey || event.metaKey) && String(event.key).toLowerCase() === 'k') {
|
|
3323
3745
|
event.preventDefault();
|
|
3324
3746
|
if ($('commandCenter').hidden) openCommandCenter();
|
|
3325
3747
|
else closeCommandCenter();
|
|
3326
3748
|
return;
|
|
3327
3749
|
}
|
|
3750
|
+
if ((event.ctrlKey || event.metaKey) && !event.shiftKey && String(event.key).toLowerCase() === 'b') {
|
|
3751
|
+
event.preventDefault();
|
|
3752
|
+
toggleSidebar();
|
|
3753
|
+
return;
|
|
3754
|
+
}
|
|
3755
|
+
if (event.ctrlKey && event.key === 'Tab') {
|
|
3756
|
+
event.preventDefault();
|
|
3757
|
+
const list = state.tabs ?? [];
|
|
3758
|
+
if (list.length > 1) {
|
|
3759
|
+
const index = list.findIndex((tab) => tab.id === state.activeTab);
|
|
3760
|
+
const next = list[(index + (event.shiftKey ? -1 : 1) + list.length) % list.length];
|
|
3761
|
+
if (next) void switchSession(next.id);
|
|
3762
|
+
}
|
|
3763
|
+
return;
|
|
3764
|
+
}
|
|
3328
3765
|
if ((event.ctrlKey || event.metaKey) && event.shiftKey) {
|
|
3329
3766
|
const key = String(event.key).toLowerCase();
|
|
3330
3767
|
if (key === 'f') { event.preventDefault(); openFiles(); return; }
|
|
@@ -3345,7 +3782,7 @@ function bind() {
|
|
|
3345
3782
|
if (!window.matchMedia('(max-width: 900px)').matches) return;
|
|
3346
3783
|
if (!$('sidebar').classList.contains('open')) return;
|
|
3347
3784
|
if (event.target.closest('#sidebar, #toggleSidebar')) return;
|
|
3348
|
-
|
|
3785
|
+
setSidebar(false);
|
|
3349
3786
|
});
|
|
3350
3787
|
|
|
3351
3788
|
$('input').addEventListener('paste', (event) => {
|
|
@@ -3371,7 +3808,8 @@ async function boot() {
|
|
|
3371
3808
|
$('workspaceLabel').textContent = state.info?.workspace ?? '';
|
|
3372
3809
|
updateHomeMode();
|
|
3373
3810
|
try {
|
|
3374
|
-
|
|
3811
|
+
const hasMessages = Boolean(state.info?.session?.messages?.length);
|
|
3812
|
+
if (hasMessages && localStorage.getItem(SHELL_STORAGE.dockOpen) === '1') termOpen();
|
|
3375
3813
|
} catch {}
|
|
3376
3814
|
grow();
|
|
3377
3815
|
$('input').focus();
|