@vincentbanana/banana-gui 1.0.0 → 1.0.1
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/package.json +2 -2
- package/ui/app.js +255 -45
- package/ui/style.css +118 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vincentbanana/banana-gui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Banana 的图形界面:本地服务 + 浏览器。黑白主题,自绘图标,无第三方 UI 依赖",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"electron-builder": "^25.0.0"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@vincentbanana/bananacli": "^0.8.
|
|
75
|
+
"@vincentbanana/bananacli": "^0.8.1"
|
|
76
76
|
},
|
|
77
77
|
"license": "MIT",
|
|
78
78
|
"publishConfig": {
|
package/ui/app.js
CHANGED
|
@@ -54,6 +54,24 @@ const TOOL_ICON = {
|
|
|
54
54
|
web_fetch: 'globe', todo_write: 'listCheck', todo_read: 'listCheck',
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
+
const TOOL_LABEL = {
|
|
58
|
+
read_file: '读取文件',
|
|
59
|
+
write_file: '写入文件',
|
|
60
|
+
edit_file: '修改文件',
|
|
61
|
+
list_dir: '查看目录',
|
|
62
|
+
glob: '查找文件',
|
|
63
|
+
grep: '搜索代码',
|
|
64
|
+
shell: '运行命令',
|
|
65
|
+
web_search: '搜索网页',
|
|
66
|
+
web_fetch: '读取网页',
|
|
67
|
+
todo_write: '更新任务',
|
|
68
|
+
todo_read: '读取任务',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function toolLabel(name) {
|
|
72
|
+
return TOOL_LABEL[name] ?? name;
|
|
73
|
+
}
|
|
74
|
+
|
|
57
75
|
function svg(name) {
|
|
58
76
|
return `<svg viewBox="0 0 24 24" aria-hidden="true">${ICONS[name] ?? ICONS.file}</svg>`;
|
|
59
77
|
}
|
|
@@ -72,6 +90,60 @@ function inline(text) {
|
|
|
72
90
|
.replace(/\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noreferrer">$1</a>');
|
|
73
91
|
}
|
|
74
92
|
|
|
93
|
+
/**
|
|
94
|
+
* 流式 Markdown 的稳定切分:空白行之前已经完成的内容不再重绘,
|
|
95
|
+
* 只更新最后一段未完成内容,避免思考/回答在流式时整体高度反复跳。
|
|
96
|
+
*/
|
|
97
|
+
function splitStableMarkdown(source) {
|
|
98
|
+
const lines = source.replace(/\r\n/g, '\n').split('\n');
|
|
99
|
+
let inFence = false;
|
|
100
|
+
let offset = 0;
|
|
101
|
+
let boundary = 0;
|
|
102
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
103
|
+
const line = lines[index];
|
|
104
|
+
if (/^```/.test(line)) inFence = !inFence;
|
|
105
|
+
offset += line.length + (index < lines.length - 1 ? 1 : 0);
|
|
106
|
+
if (!inFence && /^\s*$/.test(line)) boundary = offset;
|
|
107
|
+
}
|
|
108
|
+
return [source.slice(0, boundary), source.slice(boundary)];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function createMarkdownStream(container) {
|
|
112
|
+
const stable = document.createElement('div');
|
|
113
|
+
stable.className = 'stream-stable';
|
|
114
|
+
const tail = document.createElement('div');
|
|
115
|
+
tail.className = 'stream-tail';
|
|
116
|
+
container.replaceChildren(stable, tail);
|
|
117
|
+
let lastHead = '';
|
|
118
|
+
let lastTail = '';
|
|
119
|
+
let finished = false;
|
|
120
|
+
const paint = (text) => {
|
|
121
|
+
const [head, tailText] = splitStableMarkdown(text);
|
|
122
|
+
if (head !== lastHead) {
|
|
123
|
+
stable.innerHTML = markdown(head);
|
|
124
|
+
lastHead = head;
|
|
125
|
+
}
|
|
126
|
+
if (tailText !== lastTail) {
|
|
127
|
+
tail.innerHTML = markdown(tailText);
|
|
128
|
+
lastTail = tailText;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
render(text) {
|
|
133
|
+
if (!finished) paint(text);
|
|
134
|
+
},
|
|
135
|
+
finish(text) {
|
|
136
|
+
if (finished) return;
|
|
137
|
+
paint(text);
|
|
138
|
+
finished = true;
|
|
139
|
+
},
|
|
140
|
+
setError(html) {
|
|
141
|
+
finished = true;
|
|
142
|
+
container.innerHTML = html;
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
75
147
|
function markdown(source) {
|
|
76
148
|
const lines = source.replace(/\r\n/g, '\n').split('\n');
|
|
77
149
|
const out = [];
|
|
@@ -196,6 +268,65 @@ const state = {
|
|
|
196
268
|
|
|
197
269
|
const THREAD = $('thread');
|
|
198
270
|
|
|
271
|
+
// 单一滚动相机:始终追底,用缓动逼近,避免每个 chunk 都重启 smooth 动画。
|
|
272
|
+
const camera = {
|
|
273
|
+
raf: 0,
|
|
274
|
+
running: false,
|
|
275
|
+
follow: true,
|
|
276
|
+
lastTop: 0,
|
|
277
|
+
programmaticAt: 0,
|
|
278
|
+
lastUserScroll: 0,
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
function prefersReducedMotion() {
|
|
282
|
+
return (
|
|
283
|
+
document.documentElement.dataset.reduceMotion === '1' ||
|
|
284
|
+
window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function stopCamera() {
|
|
289
|
+
camera.running = false;
|
|
290
|
+
if (camera.raf) cancelAnimationFrame(camera.raf);
|
|
291
|
+
camera.raf = 0;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function cameraMax() {
|
|
295
|
+
return Math.max(0, THREAD.scrollHeight - THREAD.clientHeight);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function cameraTick() {
|
|
299
|
+
if (!camera.running) return;
|
|
300
|
+
if (!camera.follow) {
|
|
301
|
+
stopCamera();
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const target = cameraMax();
|
|
305
|
+
const current = THREAD.scrollTop;
|
|
306
|
+
const distance = target - current;
|
|
307
|
+
if (distance <= 0.8) {
|
|
308
|
+
THREAD.scrollTop = target;
|
|
309
|
+
camera.lastTop = target;
|
|
310
|
+
camera.programmaticAt = Date.now();
|
|
311
|
+
stopCamera();
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const step = Math.min(64, Math.max(1, distance * 0.12));
|
|
315
|
+
THREAD.scrollTop = current + step;
|
|
316
|
+
camera.lastTop = THREAD.scrollTop;
|
|
317
|
+
camera.programmaticAt = Date.now();
|
|
318
|
+
camera.raf = requestAnimationFrame(cameraTick);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function setCameraFollow(follow) {
|
|
322
|
+
camera.follow = Boolean(follow);
|
|
323
|
+
state.stickToBottom = camera.follow;
|
|
324
|
+
if (!camera.follow) {
|
|
325
|
+
stopCamera();
|
|
326
|
+
if (THREAD.querySelector('.msg')) $('jumpLatest').hidden = false;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
199
330
|
// 历史消息 / 新回复渲染完成后统一高亮,避免流式过程中反复解析
|
|
200
331
|
let highlightFrame = 0;
|
|
201
332
|
const highlightObserver = new MutationObserver(() => {
|
|
@@ -570,7 +701,7 @@ function toolRowNode(name, detail, stateHtml, ms) {
|
|
|
570
701
|
row.className = 'tool-row';
|
|
571
702
|
row.innerHTML =
|
|
572
703
|
`<span class="t-ico">${svg(TOOL_ICON[name] ?? 'file')}</span>` +
|
|
573
|
-
`<span class="t-name">${escapeHtml(name)}</span>` +
|
|
704
|
+
`<span class="t-name">${escapeHtml(toolLabel(name))}</span>` +
|
|
574
705
|
`<span class="t-detail">${escapeHtml(detail)}</span>` +
|
|
575
706
|
`<span class="t-state">${stateHtml}</span>` +
|
|
576
707
|
(ms ? `<span class="t-time">${(ms / 1000).toFixed(1)}s</span>` : '');
|
|
@@ -585,7 +716,7 @@ function toolGroup(calls, results) {
|
|
|
585
716
|
wrap.classList.toggle('has-error', hasError);
|
|
586
717
|
const summary = document.createElement('summary');
|
|
587
718
|
summary.innerHTML =
|
|
588
|
-
`<span class="wg-dot"></span><span class="wg-title"
|
|
719
|
+
`<span class="wg-dot"></span><span class="wg-title">完成 ${calls.length} 个操作</span>` +
|
|
589
720
|
`<span class="wg-state">${hasError ? '有失败' : ''}</span>`;
|
|
590
721
|
const body = document.createElement('div');
|
|
591
722
|
body.className = 'tool-group-body';
|
|
@@ -711,7 +842,9 @@ function renderEmpty() {
|
|
|
711
842
|
}
|
|
712
843
|
|
|
713
844
|
function renderThread() {
|
|
845
|
+
stopCamera();
|
|
714
846
|
THREAD.innerHTML = '';
|
|
847
|
+
camera.follow = true;
|
|
715
848
|
state.stickToBottom = true;
|
|
716
849
|
$('jumpLatest').hidden = true;
|
|
717
850
|
const messages = state.info?.session?.messages ?? [];
|
|
@@ -731,7 +864,7 @@ function renderThread() {
|
|
|
731
864
|
renderTodos();
|
|
732
865
|
updateHomeMode();
|
|
733
866
|
// 切换会话时瞬间定位到底部;平滑滚动只用于新消息
|
|
734
|
-
scrollToEnd(false);
|
|
867
|
+
scrollToEnd(false, true);
|
|
735
868
|
}
|
|
736
869
|
|
|
737
870
|
function renderTurnMeta() {
|
|
@@ -739,16 +872,29 @@ function renderTurnMeta() {
|
|
|
739
872
|
if (state.busy && state.status) { meta.textContent = state.status; return; }
|
|
740
873
|
const usage = state.info?.session?.usage;
|
|
741
874
|
if (!usage || (!usage.inputTokens && !usage.outputTokens)) { meta.textContent = ''; return; }
|
|
742
|
-
const
|
|
743
|
-
|
|
875
|
+
const total = usage.inputTokens + usage.outputTokens;
|
|
876
|
+
const parts = [total >= 1000 ? `${(total / 1000).toFixed(1)}k tokens` : `${total} tokens`];
|
|
877
|
+
if (usage.costUsd) parts.push(`$${usage.costUsd.toFixed(4)}`);
|
|
744
878
|
meta.textContent = parts.join(' · ');
|
|
745
879
|
}
|
|
746
880
|
|
|
747
881
|
function scrollToEnd(smooth = true, force = false) {
|
|
748
|
-
if (
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
}
|
|
882
|
+
if (force) {
|
|
883
|
+
camera.follow = true;
|
|
884
|
+
state.stickToBottom = true;
|
|
885
|
+
}
|
|
886
|
+
if (!camera.follow) return;
|
|
887
|
+
if (!smooth || prefersReducedMotion()) {
|
|
888
|
+
stopCamera();
|
|
889
|
+
THREAD.scrollTop = cameraMax();
|
|
890
|
+
camera.lastTop = THREAD.scrollTop;
|
|
891
|
+
camera.programmaticAt = Date.now();
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
if (!camera.running) {
|
|
895
|
+
camera.running = true;
|
|
896
|
+
camera.raf = requestAnimationFrame(cameraTick);
|
|
897
|
+
}
|
|
752
898
|
}
|
|
753
899
|
|
|
754
900
|
function setStatus(text) {
|
|
@@ -765,7 +911,7 @@ function setStatus(text) {
|
|
|
765
911
|
function workspaceHint() {
|
|
766
912
|
const info = state.info;
|
|
767
913
|
if (!info) return '';
|
|
768
|
-
return `工作区 ${info.workspace}
|
|
914
|
+
return `工作区 ${info.workspace}`;
|
|
769
915
|
}
|
|
770
916
|
|
|
771
917
|
function renderHeader() {
|
|
@@ -1353,6 +1499,9 @@ async function send() {
|
|
|
1353
1499
|
const text = input.value.trim();
|
|
1354
1500
|
if (!text || state.busy) return;
|
|
1355
1501
|
if (!state.info?.session) return;
|
|
1502
|
+
stopCamera();
|
|
1503
|
+
camera.follow = true;
|
|
1504
|
+
state.stickToBottom = true;
|
|
1356
1505
|
input.value = '';
|
|
1357
1506
|
grow();
|
|
1358
1507
|
closePalette();
|
|
@@ -1403,7 +1552,7 @@ async function send() {
|
|
|
1403
1552
|
work.hidden = true;
|
|
1404
1553
|
const workSummary = document.createElement('summary');
|
|
1405
1554
|
workSummary.innerHTML =
|
|
1406
|
-
'<span class="wg-dot"></span><span class="wg-title"
|
|
1555
|
+
'<span class="wg-dot"></span><span class="wg-title">正在处理</span><span class="wg-state"></span>';
|
|
1407
1556
|
const workBody = document.createElement('div');
|
|
1408
1557
|
workBody.className = 'tool-group-body';
|
|
1409
1558
|
work.append(workSummary, workBody);
|
|
@@ -1418,6 +1567,7 @@ async function send() {
|
|
|
1418
1567
|
reasonSummary.innerHTML = '<span class="think-title">思考中…</span><span class="think-len"></span>';
|
|
1419
1568
|
const reasonBody = document.createElement('div');
|
|
1420
1569
|
reasonBody.className = 'think-body';
|
|
1570
|
+
const reasoningStream = createMarkdownStream(reasonBody);
|
|
1421
1571
|
reasoning.append(reasonSummary, reasonBody);
|
|
1422
1572
|
// 用户手动收起后,后续流式内容不再强行展开
|
|
1423
1573
|
reasonSummary.addEventListener('click', () => {
|
|
@@ -1427,17 +1577,20 @@ async function send() {
|
|
|
1427
1577
|
const body = document.createElement('div');
|
|
1428
1578
|
body.className = 'msg-body caret';
|
|
1429
1579
|
body.setAttribute('aria-live', 'polite');
|
|
1580
|
+
const answerStream = createMarkdownStream(body);
|
|
1430
1581
|
const meta = document.createElement('div');
|
|
1431
1582
|
meta.className = 'turn-meta';
|
|
1432
1583
|
const working = document.createElement('div');
|
|
1433
1584
|
working.className = 'working-row';
|
|
1434
|
-
working.innerHTML = '<span class="wg-dot"></span><span class="shimmer working-text"
|
|
1585
|
+
working.innerHTML = '<span class="wg-dot"></span><span class="shimmer working-text">正在准备…</span>';
|
|
1435
1586
|
botMsg.append(working, work, reasoning, body, meta);
|
|
1436
1587
|
THREAD.appendChild(botMsg);
|
|
1588
|
+
scrollToEnd(false);
|
|
1437
1589
|
|
|
1438
1590
|
let reasoningStarted = 0;
|
|
1439
1591
|
let reasoningText = '';
|
|
1440
1592
|
let reasonPending = 0;
|
|
1593
|
+
let lastReasonPaint = 0;
|
|
1441
1594
|
let toolStarted = 0;
|
|
1442
1595
|
let toolCount = 0;
|
|
1443
1596
|
let toolErrors = false;
|
|
@@ -1446,16 +1599,29 @@ async function send() {
|
|
|
1446
1599
|
const paintReasoning = (final = false) => {
|
|
1447
1600
|
reasonPending = 0;
|
|
1448
1601
|
const text = reasoningText;
|
|
1449
|
-
|
|
1602
|
+
if (final) reasoningStream.finish(text);
|
|
1603
|
+
else reasoningStream.render(text);
|
|
1450
1604
|
const len = reasonSummary.querySelector('.think-len');
|
|
1451
1605
|
if (len) len.textContent = text.length > 999 ? `${(text.length / 1000).toFixed(1)}k 字` : `${text.length} 字`;
|
|
1452
1606
|
if (final) reasoning.classList.remove('is-live');
|
|
1453
1607
|
// 只有用户没有上滚时才跟随最新思考
|
|
1454
|
-
const nearBottom = reasonBody.scrollHeight - reasonBody.scrollTop - reasonBody.clientHeight <
|
|
1608
|
+
const nearBottom = reasonBody.scrollHeight - reasonBody.scrollTop - reasonBody.clientHeight < 48;
|
|
1455
1609
|
if (nearBottom) reasonBody.scrollTop = reasonBody.scrollHeight;
|
|
1610
|
+
scrollToEnd(false);
|
|
1456
1611
|
};
|
|
1457
1612
|
const scheduleReasoning = () => {
|
|
1458
|
-
if (!reasonPending)
|
|
1613
|
+
if (!reasonPending) {
|
|
1614
|
+
reasonPending = requestAnimationFrame(() => {
|
|
1615
|
+
// 思考也限速,避免每个 token 都重排
|
|
1616
|
+
if (Date.now() - lastReasonPaint < 60) {
|
|
1617
|
+
reasonPending = 0;
|
|
1618
|
+
scheduleReasoning();
|
|
1619
|
+
return;
|
|
1620
|
+
}
|
|
1621
|
+
lastReasonPaint = Date.now();
|
|
1622
|
+
paintReasoning(false);
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1459
1625
|
};
|
|
1460
1626
|
|
|
1461
1627
|
const finishReasoning = () => {
|
|
@@ -1466,7 +1632,7 @@ async function send() {
|
|
|
1466
1632
|
paintReasoning(true);
|
|
1467
1633
|
if (reasoning.dataset.user !== '1') reasoning.open = false;
|
|
1468
1634
|
const seconds = reasoningStarted ? ((Date.now() - reasoningStarted) / 1000).toFixed(1) : '0';
|
|
1469
|
-
reasonSummary.querySelector('.think-title').textContent =
|
|
1635
|
+
reasonSummary.querySelector('.think-title').textContent = `思考了 ${seconds}s`;
|
|
1470
1636
|
};
|
|
1471
1637
|
|
|
1472
1638
|
const setWorking = (text) => {
|
|
@@ -1480,7 +1646,8 @@ async function send() {
|
|
|
1480
1646
|
work.dataset.done = '1';
|
|
1481
1647
|
work.classList.remove('is-running');
|
|
1482
1648
|
const seconds = toolStarted ? ((Date.now() - toolStarted) / 1000).toFixed(1) : '0';
|
|
1483
|
-
workSummary.querySelector('.wg-title').textContent =
|
|
1649
|
+
workSummary.querySelector('.wg-title').textContent =
|
|
1650
|
+
toolCount === 1 ? '完成 1 个操作' : `完成 ${toolCount} 个操作`;
|
|
1484
1651
|
workSummary.querySelector('.wg-state').textContent = `${seconds}s${toolErrors ? ' · 有失败' : ''}`;
|
|
1485
1652
|
work.classList.toggle('has-error', toolErrors);
|
|
1486
1653
|
if (!toolErrors) work.open = false;
|
|
@@ -1493,22 +1660,20 @@ async function send() {
|
|
|
1493
1660
|
let pending = 0;
|
|
1494
1661
|
let lastPaint = 0;
|
|
1495
1662
|
let streamEnded = false;
|
|
1496
|
-
const renderStream = () => markdown(buffer);
|
|
1497
1663
|
|
|
1498
1664
|
const paint = () => {
|
|
1499
1665
|
pending = 0;
|
|
1500
1666
|
const now = performance.now();
|
|
1501
1667
|
// 流式 markdown 限制到约 12fps,避免长回答每帧重排 + 高亮
|
|
1502
|
-
if (!streamEnded && now - lastPaint <
|
|
1668
|
+
if (!streamEnded && now - lastPaint < 50) {
|
|
1503
1669
|
schedule();
|
|
1504
1670
|
return;
|
|
1505
1671
|
}
|
|
1506
1672
|
lastPaint = now;
|
|
1507
|
-
|
|
1508
|
-
body.innerHTML = renderStream();
|
|
1673
|
+
answerStream.render(buffer);
|
|
1509
1674
|
// 流式过程中保持光标
|
|
1510
1675
|
if (!streamEnded) body.classList.add('caret');
|
|
1511
|
-
|
|
1676
|
+
scrollToEnd(false);
|
|
1512
1677
|
};
|
|
1513
1678
|
const schedule = () => {
|
|
1514
1679
|
if (!pending) pending = requestAnimationFrame(paint);
|
|
@@ -1557,7 +1722,7 @@ async function send() {
|
|
|
1557
1722
|
if (event.type === 'text') {
|
|
1558
1723
|
finishReasoning();
|
|
1559
1724
|
working.hidden = true;
|
|
1560
|
-
setStatus('
|
|
1725
|
+
setStatus('正在回答…');
|
|
1561
1726
|
buffer += event.chunk;
|
|
1562
1727
|
schedule();
|
|
1563
1728
|
} else if (event.type === 'reasoning') {
|
|
@@ -1578,7 +1743,8 @@ async function send() {
|
|
|
1578
1743
|
toolCount += 1;
|
|
1579
1744
|
work.hidden = false;
|
|
1580
1745
|
work.open = true;
|
|
1581
|
-
workSummary.querySelector('.wg-title').textContent =
|
|
1746
|
+
workSummary.querySelector('.wg-title').textContent =
|
|
1747
|
+
toolCount === 1 ? '正在执行 1 个操作' : `正在执行 ${toolCount} 个操作`;
|
|
1582
1748
|
workSummary.querySelector('.wg-state').textContent = '';
|
|
1583
1749
|
work.classList.add('is-updating');
|
|
1584
1750
|
setTimeout(() => work.classList.remove('is-updating'), 220);
|
|
@@ -1601,8 +1767,8 @@ async function send() {
|
|
|
1601
1767
|
toolRows.set(event.id, row);
|
|
1602
1768
|
workBody.appendChild(row);
|
|
1603
1769
|
if (command) ensureToolOutput(row, `$ ${command}\n`, false);
|
|
1604
|
-
setWorking(
|
|
1605
|
-
setStatus(
|
|
1770
|
+
setWorking(`正在${toolLabel(event.name)}…`);
|
|
1771
|
+
setStatus(`正在${toolLabel(event.name)}…`);
|
|
1606
1772
|
working.hidden = false;
|
|
1607
1773
|
scrollToEnd(false);
|
|
1608
1774
|
} else if (event.type === 'tool_output') {
|
|
@@ -1618,7 +1784,8 @@ async function send() {
|
|
|
1618
1784
|
out.scrollTop = out.scrollHeight;
|
|
1619
1785
|
const state = row.querySelector('.t-state');
|
|
1620
1786
|
if (state && !state.querySelector('.spin')) state.innerHTML = '<span class="spin"></span>';
|
|
1621
|
-
setStatus(
|
|
1787
|
+
setStatus(`${row.querySelector('.t-name')?.textContent ?? '命令'} · 正在输出…`);
|
|
1788
|
+
scrollToEnd(false);
|
|
1622
1789
|
}
|
|
1623
1790
|
} else if (event.type === 'tool_end') {
|
|
1624
1791
|
const row = toolRows.get(event.id) ?? [...toolRows.values()].pop();
|
|
@@ -1640,14 +1807,15 @@ async function send() {
|
|
|
1640
1807
|
}
|
|
1641
1808
|
if (!event.ok) {
|
|
1642
1809
|
work.open = true;
|
|
1643
|
-
setWorking('
|
|
1810
|
+
setWorking('有个步骤失败了,已展开详情');
|
|
1644
1811
|
} else {
|
|
1645
|
-
setWorking('
|
|
1812
|
+
setWorking('正在整理结果…');
|
|
1646
1813
|
}
|
|
1814
|
+
scrollToEnd(false);
|
|
1647
1815
|
}
|
|
1648
1816
|
} else if (event.type === 'step') {
|
|
1649
|
-
setStatus(
|
|
1650
|
-
setWorking(
|
|
1817
|
+
setStatus('正在处理…');
|
|
1818
|
+
setWorking('正在处理…');
|
|
1651
1819
|
working.hidden = false;
|
|
1652
1820
|
} else if (event.type === 'status') {
|
|
1653
1821
|
if (event.message) {
|
|
@@ -1658,6 +1826,7 @@ async function send() {
|
|
|
1658
1826
|
} else if (event.type === 'todos') {
|
|
1659
1827
|
if (state.info?.session) state.info.session.todos = event.todos ?? [];
|
|
1660
1828
|
renderTodos();
|
|
1829
|
+
scrollToEnd(false);
|
|
1661
1830
|
} else if (event.type === 'approval') {
|
|
1662
1831
|
const allowed = await askApproval(event);
|
|
1663
1832
|
await post('approve', { id: event.id, allowed });
|
|
@@ -1666,7 +1835,7 @@ async function send() {
|
|
|
1666
1835
|
finishReasoning();
|
|
1667
1836
|
finishWork();
|
|
1668
1837
|
body.classList.remove('caret');
|
|
1669
|
-
|
|
1838
|
+
answerStream.setError(markdown(`**${escapeHtml(event.message ?? '出错了')}**`));
|
|
1670
1839
|
if (event.hint) metaLine('提示', event.hint);
|
|
1671
1840
|
if (event.code === 'no_api_key') openSettings();
|
|
1672
1841
|
streamEnded = true;
|
|
@@ -1679,14 +1848,14 @@ async function send() {
|
|
|
1679
1848
|
}
|
|
1680
1849
|
body.classList.remove('caret');
|
|
1681
1850
|
streamEnded = true;
|
|
1682
|
-
if (event.error)
|
|
1683
|
-
else if (!buffer.trim())
|
|
1684
|
-
else
|
|
1851
|
+
if (event.error) answerStream.setError(markdown(`**请求失败** ${escapeHtml(event.error)}`));
|
|
1852
|
+
else if (!buffer.trim()) answerStream.setError(markdown('这一轮没有返回内容。'));
|
|
1853
|
+
else answerStream.finish(buffer);
|
|
1685
1854
|
if (buffer.trim() && !botMsg.querySelector('.msg-actions')) {
|
|
1686
1855
|
messageActions(botMsg, buffer, 'assistant');
|
|
1687
1856
|
}
|
|
1688
|
-
metaLine('步数', event.steps);
|
|
1689
1857
|
metaLine('用时', (event.ms / 1000).toFixed(1) + 's');
|
|
1858
|
+
if (event.steps > 0) metaLine('过程', `${event.steps} 步`);
|
|
1690
1859
|
if (event.cost && event.cost !== '≈$0') metaLine('花费', event.cost);
|
|
1691
1860
|
state.info = event.info;
|
|
1692
1861
|
if (event.todos) state.info.session.todos = event.todos;
|
|
@@ -1708,8 +1877,8 @@ async function send() {
|
|
|
1708
1877
|
finishReasoning();
|
|
1709
1878
|
finishWork();
|
|
1710
1879
|
body.classList.remove('caret');
|
|
1711
|
-
if (
|
|
1712
|
-
|
|
1880
|
+
if (!buffer.trim() && workBody.childElementCount === 0) {
|
|
1881
|
+
answerStream.setError(markdown('这一轮没有返回内容。可以重试,或点「停止」后换个说法。'));
|
|
1713
1882
|
}
|
|
1714
1883
|
await refresh();
|
|
1715
1884
|
}
|
|
@@ -1717,11 +1886,11 @@ async function send() {
|
|
|
1717
1886
|
body.classList.remove('caret');
|
|
1718
1887
|
const aborted = controller?.signal.aborted || /abort/i.test(String(error?.message ?? ''));
|
|
1719
1888
|
if (aborted) {
|
|
1720
|
-
|
|
1889
|
+
answerStream.setError(markdown(buffer.trim() || '已停止生成。'));
|
|
1721
1890
|
metaLine('状态', '已停止');
|
|
1722
1891
|
streamEnded = true;
|
|
1723
1892
|
} else if (!buffer.trim()) {
|
|
1724
|
-
|
|
1893
|
+
answerStream.setError(markdown(`**中断** ${escapeHtml(error.message)}`));
|
|
1725
1894
|
}
|
|
1726
1895
|
await refresh();
|
|
1727
1896
|
} finally {
|
|
@@ -4117,14 +4286,55 @@ function bind() {
|
|
|
4117
4286
|
});
|
|
4118
4287
|
$('attachmentCopyPath').addEventListener('click', () => copyText(state.attachmentPath ?? '', '已复制附件路径'));
|
|
4119
4288
|
$('jumpLatest').addEventListener('click', () => {
|
|
4120
|
-
|
|
4121
|
-
|
|
4289
|
+
setCameraFollow(true);
|
|
4290
|
+
$('jumpLatest').hidden = true;
|
|
4291
|
+
scrollToEnd(true, true);
|
|
4122
4292
|
});
|
|
4293
|
+
THREAD.addEventListener(
|
|
4294
|
+
'wheel',
|
|
4295
|
+
(event) => {
|
|
4296
|
+
if (event.deltaY < 0) {
|
|
4297
|
+
setCameraFollow(false);
|
|
4298
|
+
camera.lastUserScroll = Date.now();
|
|
4299
|
+
return;
|
|
4300
|
+
}
|
|
4301
|
+
const atBottom = cameraMax() - THREAD.scrollTop < 90;
|
|
4302
|
+
if (atBottom) {
|
|
4303
|
+
setCameraFollow(true);
|
|
4304
|
+
$('jumpLatest').hidden = true;
|
|
4305
|
+
}
|
|
4306
|
+
},
|
|
4307
|
+
{ passive: true },
|
|
4308
|
+
);
|
|
4309
|
+
let touchY = 0;
|
|
4310
|
+
THREAD.addEventListener(
|
|
4311
|
+
'touchstart',
|
|
4312
|
+
(event) => {
|
|
4313
|
+
touchY = event.touches[0]?.clientY ?? 0;
|
|
4314
|
+
},
|
|
4315
|
+
{ passive: true },
|
|
4316
|
+
);
|
|
4317
|
+
THREAD.addEventListener(
|
|
4318
|
+
'touchmove',
|
|
4319
|
+
(event) => {
|
|
4320
|
+
const nextY = event.touches[0]?.clientY ?? touchY;
|
|
4321
|
+
if (nextY > touchY + 4) {
|
|
4322
|
+
setCameraFollow(false);
|
|
4323
|
+
camera.lastUserScroll = Date.now();
|
|
4324
|
+
}
|
|
4325
|
+
touchY = nextY;
|
|
4326
|
+
},
|
|
4327
|
+
{ passive: true },
|
|
4328
|
+
);
|
|
4123
4329
|
THREAD.addEventListener('scroll', () => {
|
|
4124
|
-
const
|
|
4125
|
-
|
|
4330
|
+
const top = THREAD.scrollTop;
|
|
4331
|
+
camera.lastTop = top;
|
|
4332
|
+
const atBottom = cameraMax() - top < 70;
|
|
4333
|
+
if (atBottom && !camera.follow && Date.now() - camera.lastUserScroll > 300) {
|
|
4334
|
+
setCameraFollow(true);
|
|
4335
|
+
}
|
|
4126
4336
|
const hasMessages = Boolean(THREAD.querySelector('.msg'));
|
|
4127
|
-
$('jumpLatest').hidden =
|
|
4337
|
+
$('jumpLatest').hidden = camera.follow || !hasMessages;
|
|
4128
4338
|
});
|
|
4129
4339
|
$('input').addEventListener('input', () => {
|
|
4130
4340
|
grow();
|
package/ui/style.css
CHANGED
|
@@ -3996,3 +3996,121 @@ input:focus-visible, textarea:focus-visible { outline: none; }
|
|
|
3996
3996
|
.plan-actions { flex-wrap: wrap; }
|
|
3997
3997
|
}
|
|
3998
3998
|
.msg.user .msg-attachments { align-self: flex-end; justify-content: flex-end; max-width: 100%; margin: 7px 0 0; }
|
|
3999
|
+
|
|
4000
|
+
/* ---------- v1.1:阅读优先的对话排版 / 平滑追底 ---------- */
|
|
4001
|
+
.thread {
|
|
4002
|
+
scroll-behavior: auto !important;
|
|
4003
|
+
overflow-anchor: none;
|
|
4004
|
+
padding: 18px 0 26px;
|
|
4005
|
+
scrollbar-gutter: stable;
|
|
4006
|
+
}
|
|
4007
|
+
|
|
4008
|
+
.msg {
|
|
4009
|
+
max-width: 780px;
|
|
4010
|
+
padding: 0 32px;
|
|
4011
|
+
content-visibility: visible;
|
|
4012
|
+
contain-intrinsic-size: none;
|
|
4013
|
+
}
|
|
4014
|
+
.msg + .msg { margin-top: 30px; }
|
|
4015
|
+
.msg-body {
|
|
4016
|
+
font-size: 15px;
|
|
4017
|
+
line-height: 1.72;
|
|
4018
|
+
letter-spacing: 0.002em;
|
|
4019
|
+
}
|
|
4020
|
+
.msg.user .msg-body {
|
|
4021
|
+
max-width: min(82%, 68ch);
|
|
4022
|
+
padding: 10px 14px;
|
|
4023
|
+
border-radius: 12px;
|
|
4024
|
+
font-size: 14.5px;
|
|
4025
|
+
line-height: 1.62;
|
|
4026
|
+
}
|
|
4027
|
+
.msg.assistant .msg-body { width: 100%; }
|
|
4028
|
+
.msg-body p { margin: 0 0 14px; }
|
|
4029
|
+
.msg-body p:last-child { margin-bottom: 0; }
|
|
4030
|
+
.msg-body ul, .msg-body ol { margin: 10px 0 14px; padding-left: 28px; }
|
|
4031
|
+
.msg-body li { margin-bottom: 6px; }
|
|
4032
|
+
.msg-body h1 { font-size: 18px; line-height: 1.45; margin: 28px 0 12px; }
|
|
4033
|
+
.msg-body h2 { font-size: 16px; line-height: 1.45; margin: 24px 0 10px; }
|
|
4034
|
+
.msg-body h3 { font-size: 14px; line-height: 1.5; margin: 20px 0 8px; }
|
|
4035
|
+
.msg-body pre.code {
|
|
4036
|
+
margin: 12px 0 16px;
|
|
4037
|
+
padding: 12px 14px;
|
|
4038
|
+
border-radius: 8px;
|
|
4039
|
+
line-height: 1.62;
|
|
4040
|
+
font-size: 12.5px;
|
|
4041
|
+
}
|
|
4042
|
+
.msg-body code { font-size: 12.5px; }
|
|
4043
|
+
|
|
4044
|
+
.stream-stable, .stream-tail { display: contents; }
|
|
4045
|
+
|
|
4046
|
+
.thinking-row, .working-row {
|
|
4047
|
+
max-width: 780px;
|
|
4048
|
+
padding: 0 32px;
|
|
4049
|
+
margin: 2px auto 0;
|
|
4050
|
+
font-size: 12.5px;
|
|
4051
|
+
font-weight: 450;
|
|
4052
|
+
line-height: 1.5;
|
|
4053
|
+
color: var(--text-3);
|
|
4054
|
+
}
|
|
4055
|
+
.msg .working-row { margin-bottom: 10px; }
|
|
4056
|
+
|
|
4057
|
+
.work-group, .think {
|
|
4058
|
+
margin: 10px 0 14px;
|
|
4059
|
+
border: 0;
|
|
4060
|
+
border-radius: 8px;
|
|
4061
|
+
background: transparent;
|
|
4062
|
+
}
|
|
4063
|
+
.work-group > summary, .think > summary {
|
|
4064
|
+
min-height: 32px;
|
|
4065
|
+
padding: 0 7px;
|
|
4066
|
+
border-radius: 7px;
|
|
4067
|
+
font-size: 12.5px;
|
|
4068
|
+
font-weight: 450;
|
|
4069
|
+
color: var(--text-3);
|
|
4070
|
+
}
|
|
4071
|
+
.work-group > summary:hover, .think > summary:hover { background: var(--panel); }
|
|
4072
|
+
.work-group .tool-group-body { padding: 2px 0 6px; }
|
|
4073
|
+
.tool-row {
|
|
4074
|
+
min-height: 32px;
|
|
4075
|
+
padding: 2px 7px;
|
|
4076
|
+
border-radius: 7px;
|
|
4077
|
+
font-size: 12.5px;
|
|
4078
|
+
}
|
|
4079
|
+
.msg .tool-row:hover { transform: none; }
|
|
4080
|
+
.tool-row .t-name { font-weight: 520; }
|
|
4081
|
+
.tool-row .t-detail { font-size: 11.5px; }
|
|
4082
|
+
.tool-row .t-state { font-size: 10.5px; }
|
|
4083
|
+
.tool-output {
|
|
4084
|
+
max-height: 300px;
|
|
4085
|
+
margin: 3px 0 8px;
|
|
4086
|
+
padding: 10px 12px;
|
|
4087
|
+
border-radius: 8px;
|
|
4088
|
+
font-size: 12px;
|
|
4089
|
+
line-height: 1.62;
|
|
4090
|
+
}
|
|
4091
|
+
.think-body {
|
|
4092
|
+
max-height: 300px;
|
|
4093
|
+
padding: 8px 12px 12px;
|
|
4094
|
+
border-top: 1px solid var(--line);
|
|
4095
|
+
white-space: normal;
|
|
4096
|
+
font-size: 12.5px;
|
|
4097
|
+
line-height: 1.72;
|
|
4098
|
+
}
|
|
4099
|
+
.think-body p { margin: 0 0 10px; }
|
|
4100
|
+
.think-body p:last-child { margin-bottom: 0; }
|
|
4101
|
+
.turn-meta {
|
|
4102
|
+
margin-top: 12px;
|
|
4103
|
+
font-size: 11px;
|
|
4104
|
+
color: var(--text-3);
|
|
4105
|
+
opacity: 0.78;
|
|
4106
|
+
}
|
|
4107
|
+
.msg.user .turn-meta { opacity: 0.65; }
|
|
4108
|
+
.plan-card { max-width: 780px; margin-top: 8px; }
|
|
4109
|
+
|
|
4110
|
+
@media (max-width: 720px) {
|
|
4111
|
+
.thread { padding-top: 12px; }
|
|
4112
|
+
.msg { padding: 0 20px; }
|
|
4113
|
+
.thinking-row, .working-row { padding: 0 20px; }
|
|
4114
|
+
.msg-body { font-size: 14.5px; line-height: 1.68; }
|
|
4115
|
+
.msg + .msg { margin-top: 24px; }
|
|
4116
|
+
}
|