cladogram 0.6.0-beta.2 → 0.6.0-beta.4
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/bin/clado.js +34 -2
- package/docs/agent-context.md +62 -0
- package/docs/agent-reference.md +126 -0
- package/docs/release.md +15 -0
- package/package.json +3 -1
- package/plugins/agent/index.js +974 -124
- package/plugins/agent/style.css +502 -52
- package/src/agent/clado-tools.js +437 -103
- package/src/agent/pi-bridge.js +588 -43
- package/src/agent/pi-config.js +411 -35
- package/src/html/app-css.js +65 -1
- package/src/html/canvas-chain.js +26 -2
- package/src/html/canvas-focus.js +19 -13
- package/src/html/canvas-live-diff.js +1256 -0
- package/src/html/canvas-ui.css +508 -0
- package/src/html/canvas-wires.js +5 -1
- package/src/html/page.js +4 -2
- package/src/html/runtime-api.js +146 -10
- package/src/html/runtime.js +432 -29
- package/src/server/agent.js +55 -8
- package/src/server/assets/library-canvas.js +252 -9
- package/src/server/assets/library.css +416 -0
- package/src/server/assets/library.html +2 -0
- package/src/server/assets/library.js +744 -14
- package/src/server/code-inspect.js +183 -0
- package/src/server/mcp.js +4 -4
- package/src/server/workspace.js +266 -19
- package/src/workspace/graph-snapshot.js +695 -0
- package/src/workspace/service.js +11 -1
package/plugins/agent/index.js
CHANGED
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
const TONE_CHIP = { sky: 'clado-chip-sky', emerald: 'clado-chip-mint', violet: 'clado-chip-violet', amber: 'clado-chip-amber' };
|
|
21
21
|
|
|
22
22
|
const CODE_ANALYSIS_PROMPTS = {
|
|
23
|
-
arch: '请先扫描当前项目源码目录结构,识别核心模块、入口文件与数据流边界,然后调用 clado_create 创建一张名为 architecture-overview.md
|
|
24
|
-
req: '请结合当前仓库现状,帮我创建一张名为 feature-design.md
|
|
25
|
-
qa: '
|
|
23
|
+
arch: '请先扫描当前项目源码目录结构,识别核心模块、入口文件与数据流边界,然后调用 clado_create 创建一张名为 architecture-overview.md 的卡片模式网状架构画布:让入口契约、编排路由、并行模块与底层存储从左到右连成完整网状结构并标注语义 Tag;写完后必须调用 clado_graph 复核零孤立卡与零断链,并用 canvas_focus 聚焦入口卡。',
|
|
24
|
+
req: '请结合当前仓库现状,帮我创建一张名为 feature-design.md 的新需求拆解画布,包含入口契约、核心分支、状态流转与数据落点卡片,用跨卡内链与语义 Tag 连成端到端网状图,写完后用 clado_graph 复核连线健康度。',
|
|
25
|
+
qa: '请阅读当前仓库核心模块与已有测试,使用 test-cases 模板创建一张名为 test-matrix.md 的测试与压测矩阵画布,列出主链路、并发边界与异常回归检查项并连成清晰网络,最后用 clado_graph 复核。',
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
// ===========================================================================
|
|
@@ -91,11 +91,12 @@
|
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
// Headings
|
|
95
|
-
const hMatch = line.match(/^\s{0,3}(#{1,
|
|
94
|
+
// Headings (allow empty/partial heading text during live token streaming like "### ")
|
|
95
|
+
const hMatch = line.match(/^\s{0,3}(#{1,6})\s+(.*)$/);
|
|
96
96
|
if (hMatch) {
|
|
97
|
-
const lvl = hMatch[1].length;
|
|
98
|
-
|
|
97
|
+
const lvl = Math.min(4, hMatch[1].length);
|
|
98
|
+
const headingText = hMatch[2].replace(/\s+#*\s*$/, '').trim();
|
|
99
|
+
out.push(`<h${lvl}>${headingText ? renderInline(headingText) : ' '}</h${lvl}>`);
|
|
99
100
|
i++;
|
|
100
101
|
continue;
|
|
101
102
|
}
|
|
@@ -163,7 +164,7 @@
|
|
|
163
164
|
i < lines.length
|
|
164
165
|
&& lines[i].trim()
|
|
165
166
|
&& !/^\u0000FENCE\d+\u0000$/.test(lines[i].trim())
|
|
166
|
-
&& !/^\s{0,3}#{1,
|
|
167
|
+
&& !/^\s{0,3}#{1,6}\s+/.test(lines[i])
|
|
167
168
|
&& !/^\s{0,3}([-*_])(?:\s*\1){2,}\s*$/.test(lines[i])
|
|
168
169
|
&& !/^\s*>\s?/.test(lines[i])
|
|
169
170
|
&& !/^\s*[-*+]\s+/.test(lines[i])
|
|
@@ -175,6 +176,10 @@
|
|
|
175
176
|
}
|
|
176
177
|
if (pLines.length) {
|
|
177
178
|
out.push(`<p>${pLines.map(renderInline).join('<br/>')}</p>`);
|
|
179
|
+
} else {
|
|
180
|
+
// Hard invariant: ALWAYS advance cursor so partial streaming markdown can never infinite-loop
|
|
181
|
+
out.push(`<p>${renderInline(lines[i])}</p>`);
|
|
182
|
+
i++;
|
|
178
183
|
}
|
|
179
184
|
}
|
|
180
185
|
|
|
@@ -208,8 +213,8 @@
|
|
|
208
213
|
dock.innerHTML = `
|
|
209
214
|
<div class="clado-dock-drawer collapsed" data-drawer>
|
|
210
215
|
<div class="clado-resize-nw" data-resize="nw" title="拖动调整对话窗口宽高(双击恢复默认)"></div>
|
|
211
|
-
<div class="clado-resize-n" data-resize="n" title="
|
|
212
|
-
<div class="clado-resize-w" data-resize="w" title="
|
|
216
|
+
<div class="clado-resize-n" data-resize="n" title="上下拖动调整对话高度(双击恢复默认)"><span class="clado-resize-grip"></span></div>
|
|
217
|
+
<div class="clado-resize-w" data-resize="w" title="左右拖动调整对话宽度"><span class="clado-resize-grip-v"></span></div>
|
|
213
218
|
<div class="clado-dock-aura"></div>
|
|
214
219
|
<div class="clado-dock-inner">
|
|
215
220
|
<div class="clado-dock-head">
|
|
@@ -242,14 +247,20 @@
|
|
|
242
247
|
|
|
243
248
|
<div class="clado-composer">
|
|
244
249
|
<div class="clado-dock-popover clado-scroll" data-popover hidden></div>
|
|
250
|
+
<div class="clado-ctx-bar" data-ctx-bar hidden></div>
|
|
245
251
|
<textarea class="clado-composer-input clado-scroll" data-input rows="1" placeholder="输入需求、敲 / 调命令(Enter 换行,Ctrl+Enter 发送)…"></textarea>
|
|
246
252
|
<div class="clado-composer-bar">
|
|
247
253
|
<div class="clado-composer-left">
|
|
248
254
|
<button type="button" class="clado-ui-button" data-toggle-drawer style="width:26px;height:26px;padding:0;min-height:26px;color:var(--clado-ui-brand);" title="展开或收起角色会话">${ICONS.sparkle}</button>
|
|
249
255
|
<button type="button" class="clado-model-chip" data-model-chip title="切换模型或配置供应商">配置模型 ▾</button>
|
|
256
|
+
<button type="button" class="clado-ctx-meter" data-ctx-meter title="查看模型上下文余量、思考强度与自动压缩策略">
|
|
257
|
+
<span class="clado-ctx-meter-track"><span class="clado-ctx-meter-fill" style="width:0%;"></span></span>
|
|
258
|
+
<span data-ctx-meter-txt>剩 100%</span>
|
|
259
|
+
</button>
|
|
250
260
|
</div>
|
|
251
261
|
<div class="clado-composer-right">
|
|
252
262
|
<button type="button" class="clado-sendmode-btn" data-sendmode title="点击切换发送快捷键">Ctrl↵ 发送</button>
|
|
263
|
+
<button type="button" class="clado-stop-btn" data-stop hidden title="停止当前 AI 执行并保留已生成内容">停止</button>
|
|
253
264
|
<button type="button" class="clado-ui-button clado-ui-button-primary" data-send style="min-height:26px;padding:3px 13px;font-size:12px;">发送</button>
|
|
254
265
|
</div>
|
|
255
266
|
</div>
|
|
@@ -264,18 +275,31 @@
|
|
|
264
275
|
const stripEl = dock.querySelector('[data-role-strip]');
|
|
265
276
|
const inputEl = dock.querySelector('[data-input]');
|
|
266
277
|
const sendBtn = dock.querySelector('[data-send]');
|
|
278
|
+
const stopBtn = dock.querySelector('[data-stop]');
|
|
279
|
+
const ctxBarEl = dock.querySelector('[data-ctx-bar]');
|
|
267
280
|
const sendModeBtn = dock.querySelector('[data-sendmode]');
|
|
268
281
|
const modelChip = dock.querySelector('[data-model-chip]');
|
|
282
|
+
const ctxMeterBtn = dock.querySelector('[data-ctx-meter]');
|
|
269
283
|
const popoverEl = dock.querySelector('[data-popover]');
|
|
270
284
|
const sessionPopEl = dock.querySelector('[data-session-pop]');
|
|
271
285
|
const sessionTriggerEl = dock.querySelector('[data-session-trigger]');
|
|
286
|
+
let pinnedSnippet = null; // { file, node, text }
|
|
287
|
+
|
|
288
|
+
function syncRootDockWidth(w) {
|
|
289
|
+
if (Number.isFinite(w)) {
|
|
290
|
+
document.documentElement.style.setProperty('--clado-dock-w', Math.round(w) + 'px');
|
|
291
|
+
} else {
|
|
292
|
+
document.documentElement.style.removeProperty('--clado-dock-w');
|
|
293
|
+
}
|
|
294
|
+
}
|
|
272
295
|
|
|
273
296
|
// Restore persisted dock dimensions
|
|
274
297
|
function applyDockSize(w, h) {
|
|
275
|
-
if (Number.isFinite(w) && w >= 350 && w <=
|
|
298
|
+
if (Number.isFinite(w) && w >= 350 && w <= 880) {
|
|
276
299
|
dock.style.setProperty('--clado-dock-w', Math.round(w) + 'px');
|
|
300
|
+
syncRootDockWidth(w);
|
|
277
301
|
}
|
|
278
|
-
if (Number.isFinite(h) && h >= 160 && h <=
|
|
302
|
+
if (Number.isFinite(h) && h >= 160 && h <= 820) {
|
|
279
303
|
dock.style.setProperty('--clado-dock-stream-h', Math.round(h) + 'px');
|
|
280
304
|
}
|
|
281
305
|
}
|
|
@@ -291,15 +315,16 @@
|
|
|
291
315
|
return rect.width > 0 ? (rect.width / stage.offsetWidth) : 1;
|
|
292
316
|
}
|
|
293
317
|
|
|
294
|
-
// Bind NW / N / W Resize Handles
|
|
318
|
+
// Bind NW / N / W Resize Handles (with iframe pointer-event isolation for smooth dragging)
|
|
295
319
|
dock.querySelectorAll('[data-resize]').forEach(handle => {
|
|
296
320
|
const mode = handle.dataset.resize;
|
|
297
|
-
if (mode === 'nw') {
|
|
321
|
+
if (mode === 'nw' || mode === 'n') {
|
|
298
322
|
handle.addEventListener('dblclick', e => {
|
|
299
323
|
e.preventDefault();
|
|
300
324
|
e.stopPropagation();
|
|
301
325
|
dock.style.removeProperty('--clado-dock-w');
|
|
302
326
|
dock.style.removeProperty('--clado-dock-stream-h');
|
|
327
|
+
syncRootDockWidth(NaN);
|
|
303
328
|
localStorage.removeItem('clado-dock-size');
|
|
304
329
|
showToast('已恢复默认对话窗口尺寸');
|
|
305
330
|
});
|
|
@@ -310,8 +335,10 @@
|
|
|
310
335
|
e.stopPropagation();
|
|
311
336
|
const scale = getStageScale();
|
|
312
337
|
const stage = stageRoot();
|
|
313
|
-
const
|
|
314
|
-
const
|
|
338
|
+
const stageW = stage.offsetWidth || window.innerWidth;
|
|
339
|
+
const stageH = stage.offsetHeight || window.innerHeight;
|
|
340
|
+
const maxW = Math.min(880, Math.max(420, stageW - 48));
|
|
341
|
+
const maxH = Math.min(820, Math.max(260, stageH - 200));
|
|
315
342
|
const startX = e.clientX;
|
|
316
343
|
const startY = e.clientY;
|
|
317
344
|
const startW = dock.offsetWidth || 412;
|
|
@@ -319,7 +346,8 @@
|
|
|
319
346
|
let lastW = startW;
|
|
320
347
|
let lastH = startH;
|
|
321
348
|
drawerEl.classList.add('resizing');
|
|
322
|
-
|
|
349
|
+
document.body.classList.add('clado-dock-resizing');
|
|
350
|
+
try { handle.setPointerCapture?.(e.pointerId); } catch {}
|
|
323
351
|
|
|
324
352
|
const onMove = ev => {
|
|
325
353
|
const dx = (ev.clientX - startX) / scale;
|
|
@@ -327,14 +355,17 @@
|
|
|
327
355
|
if (mode === 'w' || mode === 'nw') {
|
|
328
356
|
lastW = Math.max(350, Math.min(maxW, startW - dx));
|
|
329
357
|
dock.style.setProperty('--clado-dock-w', Math.round(lastW) + 'px');
|
|
358
|
+
syncRootDockWidth(lastW);
|
|
330
359
|
}
|
|
331
360
|
if (mode === 'n' || mode === 'nw') {
|
|
332
361
|
lastH = Math.max(160, Math.min(maxH, startH - dy));
|
|
333
362
|
dock.style.setProperty('--clado-dock-stream-h', Math.round(lastH) + 'px');
|
|
334
363
|
}
|
|
335
364
|
};
|
|
336
|
-
const onUp =
|
|
365
|
+
const onUp = ev => {
|
|
337
366
|
drawerEl.classList.remove('resizing');
|
|
367
|
+
document.body.classList.remove('clado-dock-resizing');
|
|
368
|
+
try { if (ev?.pointerId != null) handle.releasePointerCapture?.(ev.pointerId); } catch {}
|
|
338
369
|
window.removeEventListener('pointermove', onMove);
|
|
339
370
|
window.removeEventListener('pointerup', onUp);
|
|
340
371
|
window.removeEventListener('pointercancel', onUp);
|
|
@@ -352,6 +383,28 @@
|
|
|
352
383
|
window.dispatchEvent(new CustomEvent('clado:toast', { detail: { message: msg } }));
|
|
353
384
|
}
|
|
354
385
|
|
|
386
|
+
function renderContextChips() {
|
|
387
|
+
if (!ctxBarEl) return;
|
|
388
|
+
const ctx = actions.readContext ? (actions.readContext() || {}) : {};
|
|
389
|
+
const chips = [];
|
|
390
|
+
if (ctx.file) {
|
|
391
|
+
chips.push(`<span class="clado-ctx-chip"><span class="clado-ctx-chip-txt">${esc(ctx.file)}</span></span>`);
|
|
392
|
+
}
|
|
393
|
+
if (Array.isArray(ctx.selection) && ctx.selection.length) {
|
|
394
|
+
chips.push(`<span class="clado-ctx-chip"><span class="clado-ctx-chip-txt">已选 ${ctx.selection.length} 张卡片</span></span>`);
|
|
395
|
+
}
|
|
396
|
+
if (pinnedSnippet && pinnedSnippet.text) {
|
|
397
|
+
const nodeTag = Array.isArray(pinnedSnippet.node) && pinnedSnippet.node.length ? pinnedSnippet.node[pinnedSnippet.node.length - 1] + ' · ' : '';
|
|
398
|
+
chips.push(`<span class="clado-ctx-chip is-snippet"><span class="clado-ctx-chip-txt">${esc(nodeTag + '「' + pinnedSnippet.text.slice(0, 32) + '」')}</span><button type="button" class="clado-ctx-chip-x" data-clear-snippet title="移除片段上下文">×</button></span>`);
|
|
399
|
+
}
|
|
400
|
+
ctxBarEl.innerHTML = chips.join('');
|
|
401
|
+
ctxBarEl.hidden = chips.length === 0;
|
|
402
|
+
const clearBtn = ctxBarEl.querySelector('[data-clear-snippet]');
|
|
403
|
+
if (clearBtn) {
|
|
404
|
+
clearBtn.onclick = () => { pinnedSnippet = null; renderContextChips(); };
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
355
408
|
function autoGrowInput() {
|
|
356
409
|
inputEl.style.height = 'auto';
|
|
357
410
|
const next = Math.min(132, Math.max(22, inputEl.scrollHeight));
|
|
@@ -359,6 +412,10 @@
|
|
|
359
412
|
}
|
|
360
413
|
|
|
361
414
|
function syncSendModeUi() {
|
|
415
|
+
if (runningSessionId) {
|
|
416
|
+
inputEl.placeholder = 'AI 正在运行,输入内容可随时中途插话纠偏…';
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
362
419
|
if (sendMode === 'ctrl-enter') {
|
|
363
420
|
sendModeBtn.textContent = 'Ctrl↵ 发送';
|
|
364
421
|
sendModeBtn.title = '当前:Enter 换行,Ctrl/⌘+Enter 发送(点击切换为 Enter 发送)';
|
|
@@ -375,6 +432,7 @@
|
|
|
375
432
|
drawerOpen = Boolean(open);
|
|
376
433
|
drawerEl.classList.toggle('collapsed', !drawerOpen);
|
|
377
434
|
document.body.dataset.agentDock = drawerOpen ? 'open' : 'closed';
|
|
435
|
+
if (drawerOpen) renderContextChips();
|
|
378
436
|
if (!drawerOpen) closeSessionPop();
|
|
379
437
|
}
|
|
380
438
|
|
|
@@ -384,6 +442,7 @@
|
|
|
384
442
|
if (openDrawer) setDrawerOpen(true);
|
|
385
443
|
renderRoleStrip();
|
|
386
444
|
renderStream();
|
|
445
|
+
renderContextChips();
|
|
387
446
|
if (!sessionPopEl.hidden) renderSessionPop();
|
|
388
447
|
}
|
|
389
448
|
|
|
@@ -393,11 +452,21 @@
|
|
|
393
452
|
|
|
394
453
|
function renderRoleStrip() {
|
|
395
454
|
stripEl.replaceChildren();
|
|
396
|
-
const visible = sessions
|
|
455
|
+
const visible = sessions
|
|
456
|
+
.filter(s => !s.archived)
|
|
457
|
+
.slice()
|
|
458
|
+
.sort((a, b) => {
|
|
459
|
+
const aRun = a.status === 'running' ? 1 : 0;
|
|
460
|
+
const bRun = b.status === 'running' ? 1 : 0;
|
|
461
|
+
if (aRun !== bRun) return bRun - aRun;
|
|
462
|
+
return String(b.updatedAt || '').localeCompare(String(a.updatedAt || ''));
|
|
463
|
+
});
|
|
397
464
|
for (const s of visible) {
|
|
398
465
|
const btn = document.createElement('button');
|
|
399
466
|
btn.type = 'button';
|
|
400
|
-
btn.className = 'clado-role-pill'
|
|
467
|
+
btn.className = 'clado-role-pill'
|
|
468
|
+
+ (s.id === activeSessionId ? ' active' : '')
|
|
469
|
+
+ (s.status === 'running' ? ' running' : '');
|
|
401
470
|
btn.dataset.tone = s.tone || 'sky';
|
|
402
471
|
const badge = s.status === 'running' ? ' · 运行中' : (s.summaryBadge ? ' · ' + s.summaryBadge : '');
|
|
403
472
|
btn.textContent = s.title + badge;
|
|
@@ -418,14 +487,122 @@
|
|
|
418
487
|
stripEl.append(addBtn);
|
|
419
488
|
}
|
|
420
489
|
|
|
490
|
+
function appendMessageThinking(msg, delta) {
|
|
491
|
+
if (!delta) return;
|
|
492
|
+
if (!Array.isArray(msg.blocks)) msg.blocks = [];
|
|
493
|
+
const last = msg.blocks[msg.blocks.length - 1];
|
|
494
|
+
if (last && last.type === 'thinking') {
|
|
495
|
+
last.text += delta;
|
|
496
|
+
} else {
|
|
497
|
+
msg.blocks.push({ type: 'thinking', text: delta });
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function appendMessageText(msg, delta) {
|
|
502
|
+
if (!delta) return;
|
|
503
|
+
if (!Array.isArray(msg.blocks)) msg.blocks = [];
|
|
504
|
+
const last = msg.blocks[msg.blocks.length - 1];
|
|
505
|
+
if (last && last.type === 'text') {
|
|
506
|
+
last.text += delta;
|
|
507
|
+
msg.text = (msg.text || '') + delta;
|
|
508
|
+
} else {
|
|
509
|
+
msg.blocks.push({ type: 'text', text: delta });
|
|
510
|
+
const prev = msg.text || '';
|
|
511
|
+
const sep = prev && !prev.endsWith('\n\n') && !delta.startsWith('\n') ? '\n\n' : '';
|
|
512
|
+
msg.text = prev + sep + delta;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function upsertMessageTool(msg, ev) {
|
|
517
|
+
if (!Array.isArray(msg.tools)) msg.tools = [];
|
|
518
|
+
if (!Array.isArray(msg.blocks)) msg.blocks = [];
|
|
519
|
+
const existing = msg.tools.find(t => t.id === ev.id);
|
|
520
|
+
if (existing) {
|
|
521
|
+
if (ev.status) existing.status = ev.status;
|
|
522
|
+
if (ev.isError !== undefined) existing.isError = Boolean(ev.isError);
|
|
523
|
+
if (ev.argsSummary) existing.argsSummary = ev.argsSummary;
|
|
524
|
+
if (ev.resultPreview !== undefined) existing.resultPreview = ev.resultPreview;
|
|
525
|
+
return existing;
|
|
526
|
+
}
|
|
527
|
+
const entry = {
|
|
528
|
+
id: ev.id,
|
|
529
|
+
name: ev.name || ev.title || 'tool',
|
|
530
|
+
argsSummary: ev.argsSummary || '',
|
|
531
|
+
resultPreview: ev.resultPreview || '',
|
|
532
|
+
status: ev.status || 'running',
|
|
533
|
+
isError: Boolean(ev.isError || ev.status === 'failed'),
|
|
534
|
+
};
|
|
535
|
+
msg.tools.push(entry);
|
|
536
|
+
const last = msg.blocks[msg.blocks.length - 1];
|
|
537
|
+
if (last && last.type === 'tools') {
|
|
538
|
+
last.tools.push(entry);
|
|
539
|
+
} else {
|
|
540
|
+
msg.blocks.push({ type: 'tools', tools: [entry] });
|
|
541
|
+
}
|
|
542
|
+
return entry;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
function buildThinkingTrace(msgKey, text) {
|
|
546
|
+
const details = document.createElement('details');
|
|
547
|
+
details.className = 'clado-thinking-trace';
|
|
548
|
+
if (traceOpenState.get(msgKey)) details.open = true;
|
|
549
|
+
details.addEventListener('toggle', () => { traceOpenState.set(msgKey, details.open); });
|
|
550
|
+
const chars = String(text || '').trim().length;
|
|
551
|
+
const summary = document.createElement('summary');
|
|
552
|
+
summary.innerHTML = `<span>思考过程 (${chars} 字)</span><span style="font-size:10px;opacity:.72;">${details.open ? '收起' : '展开'}</span>`;
|
|
553
|
+
details.addEventListener('toggle', () => {
|
|
554
|
+
if (summary.lastElementChild) summary.lastElementChild.textContent = details.open ? '收起' : '展开';
|
|
555
|
+
});
|
|
556
|
+
const body = document.createElement('div');
|
|
557
|
+
body.className = 'clado-thinking-body clado-scroll';
|
|
558
|
+
body.textContent = String(text || '').trim();
|
|
559
|
+
details.append(summary, body);
|
|
560
|
+
return details;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function decorateCanvasRefs(containerEl) {
|
|
564
|
+
const entities = actions.getCanvasEntities ? actions.getCanvasEntities() : null;
|
|
565
|
+
if (!entities) return;
|
|
566
|
+
const cardSet = new Set();
|
|
567
|
+
(entities.cards || []).forEach(c => { if (c?.title) cardSet.add(c.title); });
|
|
568
|
+
(entities.sections || []).forEach(sec => { if (sec?.title) cardSet.add(sec.title); });
|
|
569
|
+
const tagSet = new Set((entities.tags || []).map(t => t.id).filter(Boolean));
|
|
570
|
+
if (!cardSet.size && !tagSet.size) return;
|
|
571
|
+
|
|
572
|
+
containerEl.querySelectorAll('code').forEach(codeEl => {
|
|
573
|
+
if (codeEl.closest('pre')) return;
|
|
574
|
+
const raw = (codeEl.textContent || '').trim();
|
|
575
|
+
if (!raw) return;
|
|
576
|
+
if (raw.startsWith('#') && tagSet.has(raw.slice(1))) {
|
|
577
|
+
const btn = document.createElement('button');
|
|
578
|
+
btn.type = 'button';
|
|
579
|
+
btn.className = 'clado-chat-ref is-tag';
|
|
580
|
+
btn.dataset.refTag = raw.slice(1);
|
|
581
|
+
btn.title = '点击定位到画布语义锚点 ' + raw;
|
|
582
|
+
btn.textContent = raw;
|
|
583
|
+
codeEl.replaceWith(btn);
|
|
584
|
+
} else if (cardSet.has(raw)) {
|
|
585
|
+
const btn = document.createElement('button');
|
|
586
|
+
btn.type = 'button';
|
|
587
|
+
btn.className = 'clado-chat-ref is-card';
|
|
588
|
+
btn.dataset.refCard = raw;
|
|
589
|
+
btn.title = '点击飞向画布卡片「' + raw + '」';
|
|
590
|
+
btn.textContent = raw;
|
|
591
|
+
codeEl.replaceWith(btn);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
|
|
421
596
|
function buildToolTrace(msgKey, tools, isRunningMsg) {
|
|
422
597
|
const details = document.createElement('details');
|
|
423
598
|
details.className = 'clado-tool-trace';
|
|
424
599
|
const anyRunning = tools.some(t => t.status === 'running');
|
|
425
|
-
const
|
|
600
|
+
const failedCount = tools.filter(t => t.status === 'failed' || t.isError).length;
|
|
601
|
+
const anyFailed = failedCount > 0;
|
|
426
602
|
const doneCount = tools.filter(t => t.status === 'completed' || t.status === 'failed').length;
|
|
427
|
-
const shouldOpen = traceOpenState.has(msgKey) ? traceOpenState.get(msgKey) : (anyRunning || isRunningMsg);
|
|
603
|
+
const shouldOpen = traceOpenState.has(msgKey) ? traceOpenState.get(msgKey) : (anyRunning || anyFailed || isRunningMsg);
|
|
428
604
|
if (shouldOpen) details.open = true;
|
|
605
|
+
if (anyFailed && !anyRunning) details.classList.add('clado-tool-trace-err');
|
|
429
606
|
details.addEventListener('toggle', () => {
|
|
430
607
|
traceOpenState.set(msgKey, details.open);
|
|
431
608
|
});
|
|
@@ -435,7 +612,9 @@
|
|
|
435
612
|
const namesPreview = [...new Set(tools.map(t => t.name).filter(Boolean))].slice(0, 3).join(' · ');
|
|
436
613
|
const label = anyRunning
|
|
437
614
|
? `正在执行 ${currentTool?.name || '工具'}${currentTool?.argsSummary ? ' · ' + currentTool.argsSummary : ''} (${doneCount}/${tools.length})`
|
|
438
|
-
:
|
|
615
|
+
: anyFailed
|
|
616
|
+
? `工具调用 (${tools.length} · ${failedCount} 项失败) · ${namesPreview}`
|
|
617
|
+
: `工具调用 (${tools.length}) · ${namesPreview}`;
|
|
439
618
|
|
|
440
619
|
const summary = document.createElement('summary');
|
|
441
620
|
summary.innerHTML = `
|
|
@@ -453,30 +632,103 @@
|
|
|
453
632
|
|
|
454
633
|
const list = document.createElement('div');
|
|
455
634
|
list.className = 'clado-tool-list';
|
|
635
|
+
const CANVAS_TOOLS = new Set(['clado_create', 'clado_update', 'clado_nodes', 'clado_links', 'clado_graph', 'clado_read']);
|
|
636
|
+
const CODE_TOOLS = new Set(['edit', 'write', 'read']);
|
|
456
637
|
for (const t of tools) {
|
|
638
|
+
const isErr = t.status === 'failed' || t.isError;
|
|
457
639
|
const step = document.createElement('div');
|
|
458
|
-
|
|
459
|
-
const
|
|
460
|
-
const
|
|
640
|
+
const isCanvasTool = CANVAS_TOOLS.has(t.name) && t.argsSummary;
|
|
641
|
+
const isCodeTool = CODE_TOOLS.has(t.name) && t.argsSummary && !/\.mdc?$/i.test(t.argsSummary);
|
|
642
|
+
const clickable = isCanvasTool || isCodeTool;
|
|
643
|
+
step.className = 'clado-tool-step' + (isErr ? ' clado-tool-step-err' : '') + (clickable ? ' is-clickable' : '');
|
|
644
|
+
if (isCodeTool) step.title = '点击在右侧代码抽屉查看 ' + t.argsSummary;
|
|
645
|
+
else if (isCanvasTool) step.title = '点击在画布定位 ' + t.argsSummary;
|
|
646
|
+
const stepDot = t.status === 'running' ? 'clado-dot-pulse' : (isErr ? 'clado-dot-err' : 'clado-dot-ok');
|
|
647
|
+
const statusTxt = t.status === 'running' ? '执行中' : (isErr ? '失败' : '完成');
|
|
648
|
+
const statusCls = isErr ? 'clado-tool-status-err' : 'clado-tool-status-muted';
|
|
461
649
|
step.innerHTML = `
|
|
462
650
|
<div class="clado-tool-step-head">
|
|
463
651
|
<span class="${stepDot}"></span>
|
|
464
652
|
<span class="clado-tool-name">${esc(t.name || 'tool')}</span>
|
|
465
653
|
<span class="clado-tool-args" title="${esc(t.argsSummary || '')}">${esc(t.argsSummary || '')}</span>
|
|
466
|
-
<span
|
|
654
|
+
<span class="${statusCls}">${statusTxt}</span>
|
|
467
655
|
</div>
|
|
468
656
|
${t.resultPreview ? `<div class="clado-tool-preview clado-scroll">${esc(t.resultPreview)}</div>` : ''}
|
|
469
657
|
`;
|
|
658
|
+
if (clickable) {
|
|
659
|
+
step.onclick = () => {
|
|
660
|
+
if (isCodeTool) {
|
|
661
|
+
actions.openCodeFile?.(t.argsSummary);
|
|
662
|
+
} else if (isCanvasTool) {
|
|
663
|
+
if (/\.mdc?$/i.test(t.argsSummary)) actions.focusCanvas?.(t.argsSummary, '');
|
|
664
|
+
else actions.focusCanvas?.(null, t.argsSummary);
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
}
|
|
470
668
|
list.append(step);
|
|
471
669
|
}
|
|
472
670
|
details.append(list);
|
|
473
671
|
return details;
|
|
474
672
|
}
|
|
475
673
|
|
|
674
|
+
function dismissPendingQuestions(session) {
|
|
675
|
+
if (!session || !Array.isArray(session.messages)) return false;
|
|
676
|
+
let changed = false;
|
|
677
|
+
for (const m of session.messages) {
|
|
678
|
+
if (Array.isArray(m.questions)) {
|
|
679
|
+
for (const q of m.questions) {
|
|
680
|
+
if (q && !q.answered && !q.dismissed) {
|
|
681
|
+
q.dismissed = true;
|
|
682
|
+
changed = true;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
if (m.question && !m.question.answered && !m.question.dismissed) {
|
|
687
|
+
m.question.dismissed = true;
|
|
688
|
+
changed = true;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return changed;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function getActivePendingQuestion(session) {
|
|
695
|
+
if (!session || session.status !== 'running' || !Array.isArray(session.messages) || !session.messages.length) return null;
|
|
696
|
+
const last = session.messages[session.messages.length - 1];
|
|
697
|
+
if (!last || last.role !== 'assistant') return null;
|
|
698
|
+
if (Array.isArray(last.questions)) {
|
|
699
|
+
for (let i = last.questions.length - 1; i >= 0; i--) {
|
|
700
|
+
const q = last.questions[i];
|
|
701
|
+
if (q && !q.answered && !q.dismissed) return q;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
if (last.question && !last.question.answered && !last.question.dismissed) return last.question;
|
|
705
|
+
return null;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
async function submitQuestionAnswer(sessionId, q, answerText) {
|
|
709
|
+
const ans = String(answerText || '').trim();
|
|
710
|
+
if (!ans || !q || q.answered || q.dismissed) return false;
|
|
711
|
+
q.answered = true;
|
|
712
|
+
q.answer = ans;
|
|
713
|
+
renderStream();
|
|
714
|
+
try {
|
|
715
|
+
await fetch(withWs('/library/agent'), {
|
|
716
|
+
method: 'POST',
|
|
717
|
+
headers: { 'content-type': 'application/json' },
|
|
718
|
+
body: JSON.stringify({ action: 'answer', session: sessionId, questionId: q.questionId, answer: ans }),
|
|
719
|
+
});
|
|
720
|
+
showToast('已确认:' + (ans.length > 28 ? ans.slice(0, 28) + '…' : ans));
|
|
721
|
+
return true;
|
|
722
|
+
} catch {
|
|
723
|
+
showToast('回答提交失败,请重试');
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
476
728
|
function buildDecisionCard(sessionId, q) {
|
|
477
729
|
const box = document.createElement('div');
|
|
478
730
|
box.className = 'clado-decision-card';
|
|
479
|
-
box.innerHTML = `<div class="clado-decision-q">${esc(q.question)}</div><div class="clado-decision-opts"></div>`;
|
|
731
|
+
box.innerHTML = `<div class="clado-decision-q">${esc(q.question)}</div><div class="clado-decision-opts"></div><div class="clado-decision-custom"><input type="text" class="clado-decision-input" placeholder="或直接输入你的自定义回答(回车提交)…" /><button type="button" class="clado-ui-button clado-decision-submit">回答</button></div>`;
|
|
480
732
|
const optsWrap = box.querySelector('.clado-decision-opts');
|
|
481
733
|
const opts = Array.isArray(q.options) && q.options.length ? q.options : [{ id: 'confirm', label: '确认继续' }];
|
|
482
734
|
for (let i = 0; i < opts.length; i++) {
|
|
@@ -486,23 +738,108 @@
|
|
|
486
738
|
btn.className = 'clado-ui-button ' + (i === 0 ? 'clado-ui-button-primary' : '');
|
|
487
739
|
btn.style.cssText = 'min-height:28px;padding:4px 12px;font-size:11.5px;' + (i > 0 ? 'border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);color:var(--clado-ui-text);' : '');
|
|
488
740
|
btn.textContent = opt.label;
|
|
489
|
-
btn.onclick =
|
|
490
|
-
q.answered = true;
|
|
491
|
-
q.answer = opt.label;
|
|
492
|
-
renderStream();
|
|
493
|
-
await fetch(withWs('/library/agent'), {
|
|
494
|
-
method: 'POST',
|
|
495
|
-
headers: { 'content-type': 'application/json' },
|
|
496
|
-
body: JSON.stringify({ action: 'answer', session: sessionId, questionId: q.questionId, answer: opt.label }),
|
|
497
|
-
});
|
|
498
|
-
showToast('已确认:' + opt.label);
|
|
499
|
-
};
|
|
741
|
+
btn.onclick = () => submitQuestionAnswer(sessionId, q, opt.label);
|
|
500
742
|
optsWrap.append(btn);
|
|
501
743
|
}
|
|
744
|
+
const customInput = box.querySelector('.clado-decision-input');
|
|
745
|
+
const customBtn = box.querySelector('.clado-decision-submit');
|
|
746
|
+
const submitCustom = () => {
|
|
747
|
+
const val = customInput.value.trim();
|
|
748
|
+
if (!val) {
|
|
749
|
+
customInput.focus();
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
submitQuestionAnswer(sessionId, q, val);
|
|
753
|
+
};
|
|
754
|
+
customBtn.onclick = submitCustom;
|
|
755
|
+
customInput.addEventListener('keydown', e => {
|
|
756
|
+
if (e.key === 'Enter' && !e.isComposing) {
|
|
757
|
+
e.preventDefault();
|
|
758
|
+
e.stopPropagation();
|
|
759
|
+
submitCustom();
|
|
760
|
+
}
|
|
761
|
+
});
|
|
502
762
|
return box;
|
|
503
763
|
}
|
|
504
764
|
|
|
765
|
+
function formatTokenCount(n) {
|
|
766
|
+
const v = Number(n) || 0;
|
|
767
|
+
if (v >= 1_000_000) {
|
|
768
|
+
const m = v / 1_000_000;
|
|
769
|
+
return (m >= 10 || Math.abs(m - Math.round(m)) < 0.05 ? Math.round(m) : m.toFixed(1)) + 'M';
|
|
770
|
+
}
|
|
771
|
+
if (v >= 1000) {
|
|
772
|
+
const k = v / 1000;
|
|
773
|
+
return (k >= 100 ? Math.round(k) : k.toFixed(1)) + 'K';
|
|
774
|
+
}
|
|
775
|
+
return String(Math.round(v));
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
function resolveContextSnapshot(session) {
|
|
779
|
+
const s = session || currentSession();
|
|
780
|
+
const rt = meta?.runtimeSettings || {};
|
|
781
|
+
const modelSpec = s?.model || (meta?.defaultProvider && meta?.defaultModel ? `${meta.defaultProvider}/${meta.defaultModel}` : '');
|
|
782
|
+
const matchedModel = (meta?.configuredModels || []).find(m => m.id === modelSpec || m.model === modelSpec);
|
|
783
|
+
const fallbackTotal = matchedModel?.contextWindow || meta?.activeContextWindow || 128000;
|
|
784
|
+
const u = s?.contextUsage;
|
|
785
|
+
const contextWindow = u?.contextWindow || fallbackTotal;
|
|
786
|
+
const tokens = typeof u?.tokens === 'number' ? u.tokens : 0;
|
|
787
|
+
const usedPercent = typeof u?.usedPercent === 'number'
|
|
788
|
+
? Math.min(100, Math.max(0, u.usedPercent))
|
|
789
|
+
: Math.min(100, Math.max(0, Number(((tokens / Math.max(1, contextWindow)) * 100).toFixed(1))));
|
|
790
|
+
const remainingTokens = typeof u?.remainingTokens === 'number'
|
|
791
|
+
? u.remainingTokens
|
|
792
|
+
: Math.max(0, contextWindow - tokens);
|
|
793
|
+
const remainingPercent = typeof u?.remainingPercent === 'number'
|
|
794
|
+
? Math.max(0, Math.min(100, u.remainingPercent))
|
|
795
|
+
: Number(Math.max(0, 100 - usedPercent).toFixed(1));
|
|
796
|
+
return {
|
|
797
|
+
tokens,
|
|
798
|
+
contextWindow,
|
|
799
|
+
maxTokens: u?.maxTokens || matchedModel?.maxTokens || meta?.activeMaxTokens || 16384,
|
|
800
|
+
remainingTokens,
|
|
801
|
+
usedPercent,
|
|
802
|
+
remainingPercent,
|
|
803
|
+
compactionEnabled: rt.compactionEnabled !== false,
|
|
804
|
+
compactAtPercent: rt.compactionTriggerPercent || u?.compactAtPercent || 85,
|
|
805
|
+
keepRecentTokens: rt.keepRecentTokens || u?.keepRecentTokens || 20000,
|
|
806
|
+
thinkingLevel: rt.thinkingLevel || u?.thinkingLevel || 'medium',
|
|
807
|
+
transport: rt.transport || u?.transport || 'auto',
|
|
808
|
+
cost: u?.cost || 0,
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
function renderContextMeter() {
|
|
813
|
+
if (!ctxMeterBtn) return;
|
|
814
|
+
const snap = resolveContextSnapshot();
|
|
815
|
+
const fill = ctxMeterBtn.querySelector('.clado-ctx-meter-fill');
|
|
816
|
+
const txt = ctxMeterBtn.querySelector('[data-ctx-meter-txt]');
|
|
817
|
+
const pct = Math.max(0, Math.min(100, snap.usedPercent));
|
|
818
|
+
if (fill) fill.style.width = pct + '%';
|
|
819
|
+
ctxMeterBtn.classList.toggle('is-warn', pct >= 65 && pct < snap.compactAtPercent);
|
|
820
|
+
ctxMeterBtn.classList.toggle('is-danger', pct >= snap.compactAtPercent);
|
|
821
|
+
if (txt) {
|
|
822
|
+
txt.textContent = snap.tokens > 0
|
|
823
|
+
? `${formatTokenCount(snap.tokens)}/${formatTokenCount(snap.contextWindow)} · 剩${Math.round(snap.remainingPercent)}%`
|
|
824
|
+
: `${formatTokenCount(snap.contextWindow)} · 剩100%`;
|
|
825
|
+
}
|
|
826
|
+
ctxMeterBtn.title = `上下文:已用 ${snap.tokens.toLocaleString()} / 总计 ${snap.contextWindow.toLocaleString()} tokens(剩余 ${snap.remainingTokens.toLocaleString()},${snap.remainingPercent}%)· 思考:${snap.thinkingLevel} · 自动压缩:${snap.compactionEnabled ? snap.compactAtPercent + '%' : '关闭'}(点击查看与调整)`;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
let renderStreamTimer = 0;
|
|
830
|
+
function scheduleRenderStream() {
|
|
831
|
+
if (renderStreamTimer) return;
|
|
832
|
+
renderStreamTimer = setTimeout(() => {
|
|
833
|
+
renderStreamTimer = 0;
|
|
834
|
+
requestAnimationFrame(() => renderStream());
|
|
835
|
+
}, 48);
|
|
836
|
+
}
|
|
837
|
+
|
|
505
838
|
function renderStream() {
|
|
839
|
+
if (renderStreamTimer) {
|
|
840
|
+
clearTimeout(renderStreamTimer);
|
|
841
|
+
renderStreamTimer = 0;
|
|
842
|
+
}
|
|
506
843
|
const s = currentSession();
|
|
507
844
|
if (!s) return;
|
|
508
845
|
roleTitleEl.textContent = s.title || '主架构师';
|
|
@@ -511,6 +848,7 @@
|
|
|
511
848
|
|
|
512
849
|
const modelLabel = s.model || meta?.activeModelLabel || '配置模型';
|
|
513
850
|
modelChip.textContent = (modelLabel.includes('/') ? modelLabel.split('/').pop() : modelLabel) + ' ▾';
|
|
851
|
+
renderContextMeter();
|
|
514
852
|
|
|
515
853
|
const wasNearBottom = (streamEl.scrollHeight - streamEl.scrollTop - streamEl.clientHeight) < 60;
|
|
516
854
|
|
|
@@ -519,7 +857,7 @@
|
|
|
519
857
|
if (!msgs.length) {
|
|
520
858
|
const empty = document.createElement('div');
|
|
521
859
|
empty.className = 'clado-dock-empty';
|
|
522
|
-
empty.innerHTML = `当前会话:<strong>${esc(s.title)}</strong>(Pi 1.0 引擎)<br/>可直接描述架构修改、输入 <code>/</code> 调命令,或在画布选中卡片派活交付。<br
|
|
860
|
+
empty.innerHTML = `当前会话:<strong>${esc(s.title)}</strong>(Pi 1.0 引擎)<br/>可直接描述架构修改、输入 <code>/</code> 调命令,或在画布选中卡片派活交付。<br/>拖动顶部居中横条可调整窗口高度,点击标题可切换或新建会话。`;
|
|
523
861
|
streamEl.append(empty);
|
|
524
862
|
return;
|
|
525
863
|
}
|
|
@@ -531,28 +869,46 @@
|
|
|
531
869
|
const isLast = idx === msgs.length - 1;
|
|
532
870
|
if (m.role === 'user') {
|
|
533
871
|
const div = document.createElement('div');
|
|
534
|
-
div.className = 'clado-msg-user';
|
|
535
|
-
const prefix = m.handoffFrom ? `[交接自 ${m.handoffFrom}]\n` : '';
|
|
872
|
+
div.className = 'clado-msg-user' + (m.isSteer ? ' is-steer' : '');
|
|
873
|
+
const prefix = m.isSteer ? '[中途纠偏] ' : (m.handoffFrom ? `[交接自 ${m.handoffFrom}]\n` : '');
|
|
536
874
|
div.textContent = prefix + (m.text || '');
|
|
537
875
|
streamEl.append(div);
|
|
538
876
|
} else {
|
|
539
877
|
const msgKey = m.id || `${s.id}_${idx}`;
|
|
540
878
|
const isRunningMsg = isLast && s.status === 'running';
|
|
541
879
|
|
|
542
|
-
// 1.
|
|
543
|
-
if (Array.isArray(m.
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
880
|
+
// 1. Render ordered interleaved blocks (thinking -> text -> tools -> text -> ...)
|
|
881
|
+
if (Array.isArray(m.blocks) && m.blocks.length) {
|
|
882
|
+
for (let bIdx = 0; bIdx < m.blocks.length; bIdx++) {
|
|
883
|
+
const block = m.blocks[bIdx];
|
|
884
|
+
const isLastBlock = bIdx === m.blocks.length - 1;
|
|
885
|
+
if (block?.type === 'thinking' && block.text && block.text.trim()) {
|
|
886
|
+
streamEl.append(buildThinkingTrace(`${msgKey}_th${bIdx}`, block.text));
|
|
887
|
+
} else if (block?.type === 'tools' && Array.isArray(block.tools) && block.tools.length) {
|
|
888
|
+
streamEl.append(buildToolTrace(`${msgKey}_b${bIdx}`, block.tools, isRunningMsg && isLastBlock));
|
|
889
|
+
} else if (block?.type === 'text' && block.text && block.text.trim()) {
|
|
890
|
+
const div = document.createElement('div');
|
|
891
|
+
div.className = 'clado-msg-assistant clado-md';
|
|
892
|
+
div.innerHTML = renderMarkdown(block.text);
|
|
893
|
+
decorateCanvasRefs(div);
|
|
894
|
+
streamEl.append(div);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
} else {
|
|
898
|
+
// Backward-compatible fallback for older persisted sessions without blocks
|
|
899
|
+
if (Array.isArray(m.tools) && m.tools.length) {
|
|
900
|
+
streamEl.append(buildToolTrace(msgKey, m.tools, isRunningMsg));
|
|
901
|
+
}
|
|
902
|
+
if (m.text) {
|
|
903
|
+
const div = document.createElement('div');
|
|
904
|
+
div.className = 'clado-msg-assistant clado-md';
|
|
905
|
+
div.innerHTML = renderMarkdown(m.text);
|
|
906
|
+
decorateCanvasRefs(div);
|
|
907
|
+
streamEl.append(div);
|
|
908
|
+
}
|
|
553
909
|
}
|
|
554
910
|
|
|
555
|
-
//
|
|
911
|
+
// 2. Collect questions: answered ones show as compact receipt pill; unanswered ones ONLY show while this turn is actively running
|
|
556
912
|
const qList = [];
|
|
557
913
|
if (Array.isArray(m.questions)) qList.push(...m.questions);
|
|
558
914
|
if (m.question && !qList.some(q => q.questionId === m.question.questionId)) qList.push(m.question);
|
|
@@ -563,12 +919,12 @@
|
|
|
563
919
|
donePill.className = 'clado-decision-done';
|
|
564
920
|
donePill.textContent = '已确认:' + (q.answer || q.question);
|
|
565
921
|
streamEl.append(donePill);
|
|
566
|
-
} else {
|
|
922
|
+
} else if (isRunningMsg && !q.dismissed) {
|
|
567
923
|
pendingDecisionCards.push(q);
|
|
568
924
|
}
|
|
569
925
|
}
|
|
570
926
|
|
|
571
|
-
//
|
|
927
|
+
// 3. Live activity status pill while running
|
|
572
928
|
if (isRunningMsg) {
|
|
573
929
|
const act = document.createElement('div');
|
|
574
930
|
act.className = 'clado-live-activity';
|
|
@@ -578,18 +934,32 @@
|
|
|
578
934
|
}
|
|
579
935
|
}
|
|
580
936
|
|
|
581
|
-
//
|
|
937
|
+
// 4. Pending ask_user decision cards ALWAYS render at the very bottom (only while running)
|
|
582
938
|
for (const q of pendingDecisionCards) {
|
|
583
939
|
streamEl.append(buildDecisionCard(s.id, q));
|
|
584
940
|
}
|
|
585
941
|
|
|
942
|
+
if (runningSessionId === s.id) {
|
|
943
|
+
sendBtn.textContent = pendingDecisionCards.length ? '回复' : '插话';
|
|
944
|
+
}
|
|
945
|
+
|
|
586
946
|
if (wasNearBottom || s.status === 'running' || pendingDecisionCards.length) {
|
|
587
947
|
streamEl.scrollTop = streamEl.scrollHeight;
|
|
588
948
|
}
|
|
589
949
|
}
|
|
590
950
|
|
|
591
|
-
// Copy code button delegation inside stream
|
|
951
|
+
// Copy code button & clickable card/tag chip delegation inside stream
|
|
592
952
|
streamEl.addEventListener('click', e => {
|
|
953
|
+
const refTag = e.target.closest?.('[data-ref-tag]');
|
|
954
|
+
if (refTag) {
|
|
955
|
+
actions.focusTag?.(refTag.dataset.refTag);
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
const refCard = e.target.closest?.('[data-ref-card]');
|
|
959
|
+
if (refCard) {
|
|
960
|
+
actions.focusCanvas?.(null, refCard.dataset.refCard);
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
593
963
|
const btn = e.target.closest?.('[data-copy-code]');
|
|
594
964
|
if (!btn) return;
|
|
595
965
|
const code = btn.closest('.clado-md-pre')?.querySelector('pre code')?.textContent || '';
|
|
@@ -621,6 +991,7 @@
|
|
|
621
991
|
});
|
|
622
992
|
const data = await res.json();
|
|
623
993
|
if (data?.session) {
|
|
994
|
+
data.session.updatedAt = data.session.updatedAt || new Date().toISOString();
|
|
624
995
|
sessions.push(data.session);
|
|
625
996
|
closeSessionPop();
|
|
626
997
|
selectSession(data.session.id, true);
|
|
@@ -809,6 +1180,117 @@
|
|
|
809
1180
|
popoverEl.hidden = false;
|
|
810
1181
|
}
|
|
811
1182
|
|
|
1183
|
+
function openContextPopover() {
|
|
1184
|
+
popoverEl.replaceChildren();
|
|
1185
|
+
const s = currentSession();
|
|
1186
|
+
const snap = resolveContextSnapshot(s);
|
|
1187
|
+
const barColor = snap.usedPercent >= snap.compactAtPercent
|
|
1188
|
+
? '#ef4444'
|
|
1189
|
+
: (snap.usedPercent >= 65 ? '#f59e0b' : '#10b981');
|
|
1190
|
+
const THINK_LABELS = [
|
|
1191
|
+
['off', '关闭'],
|
|
1192
|
+
['low', '低'],
|
|
1193
|
+
['medium', '中'],
|
|
1194
|
+
['high', '高'],
|
|
1195
|
+
['xhigh', '极高'],
|
|
1196
|
+
['max', '极限'],
|
|
1197
|
+
];
|
|
1198
|
+
const TRANS_LABELS = [
|
|
1199
|
+
['auto', '自动流式'],
|
|
1200
|
+
['sse', 'SSE 流式'],
|
|
1201
|
+
['websocket', 'WebSocket'],
|
|
1202
|
+
];
|
|
1203
|
+
|
|
1204
|
+
const card = document.createElement('div');
|
|
1205
|
+
card.className = 'clado-ctx-pop-card';
|
|
1206
|
+
card.innerHTML = `
|
|
1207
|
+
<div class="clado-ctx-pop-head">
|
|
1208
|
+
<strong>上下文窗口与运行参数</strong>
|
|
1209
|
+
<span style="font-family:ui-monospace,monospace;font-size:11px;color:var(--clado-ui-muted);">已用 ${snap.usedPercent}% · 剩 ${snap.remainingPercent}%</span>
|
|
1210
|
+
</div>
|
|
1211
|
+
<div class="clado-ctx-pop-bar"><i style="width:${Math.min(100, snap.usedPercent)}%;background:${barColor};"></i></div>
|
|
1212
|
+
<div class="clado-ctx-pop-stats">
|
|
1213
|
+
<div class="clado-ctx-stat"><div class="clado-ctx-stat-k">已用</div><div class="clado-ctx-stat-v">${esc(formatTokenCount(snap.tokens))}</div></div>
|
|
1214
|
+
<div class="clado-ctx-stat"><div class="clado-ctx-stat-k">剩余</div><div class="clado-ctx-stat-v">${esc(formatTokenCount(snap.remainingTokens))}</div></div>
|
|
1215
|
+
<div class="clado-ctx-stat"><div class="clado-ctx-stat-k">总容量</div><div class="clado-ctx-stat-v">${esc(formatTokenCount(snap.contextWindow))}</div></div>
|
|
1216
|
+
</div>
|
|
1217
|
+
<div style="font-size:11px;color:var(--clado-ui-subtle);">
|
|
1218
|
+
自动压缩:${snap.compactionEnabled ? `开启(达到 <strong>${snap.compactAtPercent}%</strong> 触发,保留最近 ${formatTokenCount(snap.keepRecentTokens)})` : '已关闭'} · 最大输出 ${formatTokenCount(snap.maxTokens)}
|
|
1219
|
+
</div>
|
|
1220
|
+
<div>
|
|
1221
|
+
<div style="font-size:10.5px;color:var(--clado-ui-subtle);margin-bottom:4px;">思考强度(Reasoning Effort)</div>
|
|
1222
|
+
<div class="clado-ctx-pills" data-quick-think>
|
|
1223
|
+
${THINK_LABELS.map(([id, label]) => `<button type="button" class="clado-ctx-pill-btn ${snap.thinkingLevel === id ? 'active' : ''}" data-think="${id}">${label}</button>`).join('')}
|
|
1224
|
+
</div>
|
|
1225
|
+
</div>
|
|
1226
|
+
<div>
|
|
1227
|
+
<div style="font-size:10.5px;color:var(--clado-ui-subtle);margin-bottom:4px;">流式传输方式</div>
|
|
1228
|
+
<div class="clado-ctx-pills" data-quick-trans>
|
|
1229
|
+
${TRANS_LABELS.map(([id, label]) => `<button type="button" class="clado-ctx-pill-btn ${snap.transport === id ? 'active' : ''}" data-trans="${id}">${label}</button>`).join('')}
|
|
1230
|
+
</div>
|
|
1231
|
+
</div>
|
|
1232
|
+
<div style="display:flex;align-items:center;justify-content:space-between;gap:6px;padding-top:4px;border-top:1px solid var(--clado-ui-edge);">
|
|
1233
|
+
<button type="button" class="clado-ui-button" data-compact-now style="min-height:26px;padding:3px 10px;font-size:11px;border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);">立即压缩上下文</button>
|
|
1234
|
+
<button type="button" class="clado-ui-button clado-ui-button-primary" data-open-rt style="min-height:26px;padding:3px 10px;font-size:11px;">完整模型与压缩设置 →</button>
|
|
1235
|
+
</div>
|
|
1236
|
+
`;
|
|
1237
|
+
|
|
1238
|
+
card.querySelectorAll('[data-think]').forEach(btn => {
|
|
1239
|
+
btn.onclick = async e => {
|
|
1240
|
+
e.stopPropagation();
|
|
1241
|
+
try {
|
|
1242
|
+
await apiConfig({ action: 'save_runtime_settings', thinkingLevel: btn.dataset.think });
|
|
1243
|
+
renderContextMeter();
|
|
1244
|
+
openContextPopover();
|
|
1245
|
+
showToast('思考强度已切换为:' + btn.textContent);
|
|
1246
|
+
} catch (err) { showToast(err.message); }
|
|
1247
|
+
};
|
|
1248
|
+
});
|
|
1249
|
+
card.querySelectorAll('[data-trans]').forEach(btn => {
|
|
1250
|
+
btn.onclick = async e => {
|
|
1251
|
+
e.stopPropagation();
|
|
1252
|
+
try {
|
|
1253
|
+
await apiConfig({ action: 'save_runtime_settings', transport: btn.dataset.trans });
|
|
1254
|
+
renderContextMeter();
|
|
1255
|
+
openContextPopover();
|
|
1256
|
+
showToast('流式传输已切换为:' + btn.textContent);
|
|
1257
|
+
} catch (err) { showToast(err.message); }
|
|
1258
|
+
};
|
|
1259
|
+
});
|
|
1260
|
+
card.querySelector('[data-compact-now]').onclick = async e => {
|
|
1261
|
+
e.stopPropagation();
|
|
1262
|
+
if (!s) return;
|
|
1263
|
+
const btn = e.currentTarget;
|
|
1264
|
+
btn.disabled = true;
|
|
1265
|
+
btn.textContent = '压缩中…';
|
|
1266
|
+
try {
|
|
1267
|
+
const res = await fetch(withWs('/library/agent/sessions'), {
|
|
1268
|
+
method: 'POST',
|
|
1269
|
+
headers: { 'content-type': 'application/json' },
|
|
1270
|
+
body: JSON.stringify({ action: 'compact', id: s.id }),
|
|
1271
|
+
});
|
|
1272
|
+
const data = await res.json();
|
|
1273
|
+
if (!res.ok) throw new Error(data.error || '压缩失败');
|
|
1274
|
+
if (data.contextUsage) s.contextUsage = data.contextUsage;
|
|
1275
|
+
renderContextMeter();
|
|
1276
|
+
showToast(data.skipped ? (data.reason || '暂无历史需要压缩') : '上下文压缩完成');
|
|
1277
|
+
closePopover();
|
|
1278
|
+
} catch (err) {
|
|
1279
|
+
showToast(err.message || '压缩失败');
|
|
1280
|
+
btn.disabled = false;
|
|
1281
|
+
btn.textContent = '立即压缩上下文';
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
card.querySelector('[data-open-rt]').onclick = e => {
|
|
1285
|
+
e.stopPropagation();
|
|
1286
|
+
closePopover();
|
|
1287
|
+
openSettings('models');
|
|
1288
|
+
};
|
|
1289
|
+
|
|
1290
|
+
popoverEl.append(card);
|
|
1291
|
+
popoverEl.hidden = false;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
812
1294
|
function openNewRoleSessionPopover() {
|
|
813
1295
|
popoverEl.replaceChildren();
|
|
814
1296
|
const roles = meta?.roles || [];
|
|
@@ -876,6 +1358,7 @@
|
|
|
876
1358
|
stoppingTurn = false;
|
|
877
1359
|
pendingCancelPromise = null;
|
|
878
1360
|
s.status = 'running';
|
|
1361
|
+
s.updatedAt = new Date().toISOString();
|
|
879
1362
|
s.messages = Array.isArray(s.messages) ? s.messages : [];
|
|
880
1363
|
const userPromptMsg = {
|
|
881
1364
|
id: 'local_u_' + Date.now(),
|
|
@@ -888,13 +1371,18 @@
|
|
|
888
1371
|
role: 'assistant',
|
|
889
1372
|
text: '',
|
|
890
1373
|
tools: [],
|
|
1374
|
+
blocks: [],
|
|
891
1375
|
questions: [],
|
|
892
1376
|
activity: '正在思考并准备上下文…',
|
|
893
1377
|
};
|
|
894
1378
|
s.messages.push(userPromptMsg, liveAssistant);
|
|
895
1379
|
const localSnapshotMsgs = s.messages.slice();
|
|
896
1380
|
|
|
897
|
-
sendBtn.textContent = '
|
|
1381
|
+
sendBtn.textContent = '插话';
|
|
1382
|
+
stopBtn.hidden = false;
|
|
1383
|
+
stopBtn.disabled = false;
|
|
1384
|
+
stopBtn.textContent = '停止';
|
|
1385
|
+
syncSendModeUi();
|
|
898
1386
|
renderRoleStrip();
|
|
899
1387
|
renderStream();
|
|
900
1388
|
|
|
@@ -926,32 +1414,41 @@
|
|
|
926
1414
|
let ev;
|
|
927
1415
|
try { ev = JSON.parse(line); } catch { continue; }
|
|
928
1416
|
if (ev.type === 'thinking') {
|
|
1417
|
+
appendMessageThinking(liveAssistant, ev.text || '');
|
|
929
1418
|
liveAssistant.activity = '正在深度思考…';
|
|
930
|
-
|
|
1419
|
+
scheduleRenderStream();
|
|
931
1420
|
} else if (ev.type === 'text') {
|
|
932
|
-
liveAssistant
|
|
1421
|
+
appendMessageText(liveAssistant, ev.text || '');
|
|
933
1422
|
liveAssistant.activity = '正在生成回复…';
|
|
934
|
-
|
|
935
|
-
} else if (ev.type === '
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1423
|
+
scheduleRenderStream();
|
|
1424
|
+
} else if (ev.type === 'usage' && ev.usage) {
|
|
1425
|
+
s.contextUsage = ev.usage;
|
|
1426
|
+
renderContextMeter();
|
|
1427
|
+
} else if (ev.type === 'model') {
|
|
1428
|
+
if (ev.contextWindow && !s.contextUsage) {
|
|
1429
|
+
s.contextUsage = {
|
|
1430
|
+
tokens: 0,
|
|
1431
|
+
contextWindow: ev.contextWindow,
|
|
1432
|
+
maxTokens: ev.maxTokens || 16384,
|
|
1433
|
+
remainingTokens: ev.contextWindow,
|
|
1434
|
+
usedPercent: 0,
|
|
1435
|
+
remainingPercent: 100,
|
|
1436
|
+
thinkingLevel: ev.thinkingLevel || meta?.runtimeSettings?.thinkingLevel || 'medium',
|
|
1437
|
+
transport: ev.transport || meta?.runtimeSettings?.transport || 'auto',
|
|
1438
|
+
compactionEnabled: meta?.runtimeSettings?.compactionEnabled !== false,
|
|
1439
|
+
compactAtPercent: meta?.runtimeSettings?.compactionTriggerPercent || 85,
|
|
1440
|
+
};
|
|
1441
|
+
renderContextMeter();
|
|
949
1442
|
}
|
|
1443
|
+
} else if (ev.type === 'tool') {
|
|
1444
|
+
const entry = upsertMessageTool(liveAssistant, ev);
|
|
950
1445
|
const stillRunning = [...liveAssistant.tools].reverse().find(t => t.status === 'running');
|
|
951
1446
|
if (stillRunning) {
|
|
952
1447
|
liveAssistant.activity = `正在执行 ${stillRunning.name}${stillRunning.argsSummary ? ' · ' + stillRunning.argsSummary : ''}`;
|
|
1448
|
+
} else if (entry.status === 'failed' || entry.isError) {
|
|
1449
|
+
liveAssistant.activity = `${entry.name || '工具'} 执行失败,正在诊断并修复…`;
|
|
953
1450
|
} else {
|
|
954
|
-
liveAssistant.activity = '
|
|
1451
|
+
liveAssistant.activity = '工具执行完成,正在继续…';
|
|
955
1452
|
}
|
|
956
1453
|
renderStream();
|
|
957
1454
|
} else if (ev.type === 'ask_user') {
|
|
@@ -973,14 +1470,17 @@
|
|
|
973
1470
|
showToast(ev.text);
|
|
974
1471
|
renderStream();
|
|
975
1472
|
} else if (ev.type === 'done') {
|
|
1473
|
+
if (ev.usage) s.contextUsage = ev.usage;
|
|
976
1474
|
if (ev.stopped && !liveAssistant.text.includes('已手动停止')) {
|
|
977
|
-
|
|
1475
|
+
appendMessageText(liveAssistant, '_(已手动停止,以上内容已保留)_');
|
|
978
1476
|
}
|
|
979
1477
|
liveAssistant.activity = '';
|
|
1478
|
+
dismissPendingQuestions(s);
|
|
980
1479
|
renderStream();
|
|
981
1480
|
} else if (ev.type === 'error') {
|
|
982
|
-
|
|
1481
|
+
appendMessageText(liveAssistant, '提示:' + (ev.message || '执行失败'));
|
|
983
1482
|
liveAssistant.activity = '';
|
|
1483
|
+
dismissPendingQuestions(s);
|
|
984
1484
|
renderStream();
|
|
985
1485
|
}
|
|
986
1486
|
}
|
|
@@ -988,11 +1488,13 @@
|
|
|
988
1488
|
} catch (err) {
|
|
989
1489
|
if (err.name === 'AbortError' || stoppingTurn) {
|
|
990
1490
|
if (!liveAssistant.text.includes('已手动停止')) {
|
|
991
|
-
|
|
1491
|
+
appendMessageText(liveAssistant, '_(已手动停止,以上内容已保留)_');
|
|
992
1492
|
}
|
|
1493
|
+
dismissPendingQuestions(s);
|
|
993
1494
|
renderStream();
|
|
994
1495
|
} else {
|
|
995
|
-
|
|
1496
|
+
appendMessageText(liveAssistant, err.message || '执行中断');
|
|
1497
|
+
dismissPendingQuestions(s);
|
|
996
1498
|
renderStream();
|
|
997
1499
|
}
|
|
998
1500
|
} finally {
|
|
@@ -1001,12 +1503,17 @@
|
|
|
1001
1503
|
}
|
|
1002
1504
|
s.status = 'idle';
|
|
1003
1505
|
liveAssistant.activity = '';
|
|
1506
|
+
dismissPendingQuestions(s);
|
|
1004
1507
|
runningSessionId = '';
|
|
1005
1508
|
activeAbort = null;
|
|
1006
1509
|
stoppingTurn = false;
|
|
1007
1510
|
pendingCancelPromise = null;
|
|
1008
1511
|
sendBtn.textContent = '发送';
|
|
1009
1512
|
sendBtn.disabled = false;
|
|
1513
|
+
stopBtn.hidden = true;
|
|
1514
|
+
stopBtn.disabled = false;
|
|
1515
|
+
stopBtn.textContent = '停止';
|
|
1516
|
+
syncSendModeUi();
|
|
1010
1517
|
|
|
1011
1518
|
// Sync from server, but NEVER lose local messages if server hasn't flushed yet
|
|
1012
1519
|
const prevCount = localSnapshotMsgs.length;
|
|
@@ -1015,6 +1522,7 @@
|
|
|
1015
1522
|
const synced = sessions.find(x => x.id === s.id);
|
|
1016
1523
|
if (synced && (!Array.isArray(synced.messages) || synced.messages.length < prevCount)) {
|
|
1017
1524
|
synced.messages = localSnapshotMsgs;
|
|
1525
|
+
dismissPendingQuestions(synced);
|
|
1018
1526
|
renderStream();
|
|
1019
1527
|
}
|
|
1020
1528
|
} else {
|
|
@@ -1024,43 +1532,95 @@
|
|
|
1024
1532
|
}
|
|
1025
1533
|
}
|
|
1026
1534
|
|
|
1535
|
+
async function handleStop() {
|
|
1536
|
+
if (!runningSessionId || stoppingTurn) return;
|
|
1537
|
+
stoppingTurn = true;
|
|
1538
|
+
stopBtn.textContent = '停止中…';
|
|
1539
|
+
stopBtn.disabled = true;
|
|
1540
|
+
const targetId = runningSessionId;
|
|
1541
|
+
const s = sessions.find(x => x.id === targetId);
|
|
1542
|
+
dismissPendingQuestions(s);
|
|
1543
|
+
const lastMsg = s?.messages?.[s.messages.length - 1];
|
|
1544
|
+
if (lastMsg && lastMsg.role === 'assistant') {
|
|
1545
|
+
lastMsg.activity = '正在停止并保留已生成内容…';
|
|
1546
|
+
renderStream();
|
|
1547
|
+
}
|
|
1548
|
+
pendingCancelPromise = fetch(withWs('/library/agent'), {
|
|
1549
|
+
method: 'POST',
|
|
1550
|
+
headers: { 'content-type': 'application/json' },
|
|
1551
|
+
body: JSON.stringify({ action: 'cancel', session: targetId }),
|
|
1552
|
+
}).catch(() => {});
|
|
1553
|
+
await pendingCancelPromise;
|
|
1554
|
+
setTimeout(() => {
|
|
1555
|
+
if (runningSessionId === targetId && activeAbort) {
|
|
1556
|
+
activeAbort.abort();
|
|
1557
|
+
}
|
|
1558
|
+
}, 1200);
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1027
1561
|
async function handleSend() {
|
|
1562
|
+
const text = inputEl.value.trim();
|
|
1028
1563
|
if (runningSessionId) {
|
|
1029
|
-
if (stoppingTurn) return;
|
|
1030
|
-
stoppingTurn = true;
|
|
1031
|
-
sendBtn.textContent = '停止中…';
|
|
1032
|
-
sendBtn.disabled = true;
|
|
1033
1564
|
const targetId = runningSessionId;
|
|
1034
|
-
const
|
|
1035
|
-
const
|
|
1036
|
-
if (
|
|
1037
|
-
|
|
1038
|
-
|
|
1565
|
+
const runningSession = sessions.find(x => x.id === targetId);
|
|
1566
|
+
const pendingQ = getActivePendingQuestion(runningSession);
|
|
1567
|
+
if (pendingQ) {
|
|
1568
|
+
if (!text) {
|
|
1569
|
+
showToast('请点击上方选项,或直接输入你的自定义回答后发送');
|
|
1570
|
+
inputEl.focus();
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
inputEl.value = '';
|
|
1574
|
+
autoGrowInput();
|
|
1575
|
+
closePopover();
|
|
1576
|
+
await submitQuestionAnswer(targetId, pendingQ, text);
|
|
1577
|
+
return;
|
|
1039
1578
|
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1579
|
+
if (!text) {
|
|
1580
|
+
showToast('输入内容可中途插话纠偏,或点击左侧「停止」中止执行');
|
|
1581
|
+
inputEl.focus();
|
|
1582
|
+
return;
|
|
1583
|
+
}
|
|
1584
|
+
inputEl.value = '';
|
|
1585
|
+
autoGrowInput();
|
|
1586
|
+
closePopover();
|
|
1587
|
+
try {
|
|
1588
|
+
const res = await fetch(withWs('/library/agent'), {
|
|
1589
|
+
method: 'POST',
|
|
1590
|
+
headers: { 'content-type': 'application/json' },
|
|
1591
|
+
body: JSON.stringify({ action: 'steer', session: targetId, text }),
|
|
1592
|
+
});
|
|
1593
|
+
if (!res.ok) throw new Error('插话失败');
|
|
1594
|
+
if (runningSession && Array.isArray(runningSession.messages)) {
|
|
1595
|
+
const insertAt = Math.max(0, runningSession.messages.length - 1);
|
|
1596
|
+
runningSession.messages.splice(insertAt, 0, {
|
|
1597
|
+
id: 'local_steer_' + Date.now(),
|
|
1598
|
+
role: 'user',
|
|
1599
|
+
text,
|
|
1600
|
+
isSteer: true,
|
|
1601
|
+
});
|
|
1602
|
+
renderStream();
|
|
1051
1603
|
}
|
|
1052
|
-
|
|
1604
|
+
showToast('已发送中途纠偏指令');
|
|
1605
|
+
} catch {
|
|
1606
|
+
showToast('当前回合暂不支持插话,可稍候或点击停止');
|
|
1607
|
+
}
|
|
1053
1608
|
return;
|
|
1054
1609
|
}
|
|
1055
1610
|
|
|
1056
|
-
const text = inputEl.value.trim();
|
|
1057
1611
|
if (!text) return;
|
|
1058
1612
|
inputEl.value = '';
|
|
1059
1613
|
autoGrowInput();
|
|
1060
1614
|
closePopover();
|
|
1061
1615
|
const s = currentSession();
|
|
1062
1616
|
if (!s) return;
|
|
1063
|
-
|
|
1617
|
+
dismissPendingQuestions(s);
|
|
1618
|
+
const canvas = actions.readContext ? (actions.readContext() || {}) : {};
|
|
1619
|
+
if (pinnedSnippet && pinnedSnippet.text) {
|
|
1620
|
+
canvas.textSnippet = { ...pinnedSnippet };
|
|
1621
|
+
pinnedSnippet = null;
|
|
1622
|
+
renderContextChips();
|
|
1623
|
+
}
|
|
1064
1624
|
await streamAgentRequest({
|
|
1065
1625
|
action: 'prompt',
|
|
1066
1626
|
session: s.id,
|
|
@@ -1136,6 +1696,14 @@
|
|
|
1136
1696
|
if (!popoverEl.hidden && popoverEl.dataset.kind === 'model') closePopover();
|
|
1137
1697
|
else { popoverEl.dataset.kind = 'model'; openModelPopover(); }
|
|
1138
1698
|
};
|
|
1699
|
+
if (ctxMeterBtn) {
|
|
1700
|
+
ctxMeterBtn.onclick = e => {
|
|
1701
|
+
e.stopPropagation();
|
|
1702
|
+
closeSessionPop();
|
|
1703
|
+
if (!popoverEl.hidden && popoverEl.dataset.kind === 'context') closePopover();
|
|
1704
|
+
else { popoverEl.dataset.kind = 'context'; openContextPopover(); }
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1139
1707
|
sendModeBtn.onclick = e => {
|
|
1140
1708
|
e.stopPropagation();
|
|
1141
1709
|
sendMode = sendMode === 'ctrl-enter' ? 'enter' : 'ctrl-enter';
|
|
@@ -1143,6 +1711,7 @@
|
|
|
1143
1711
|
syncSendModeUi();
|
|
1144
1712
|
showToast(sendMode === 'ctrl-enter' ? '已切换:Enter 换行,Ctrl+Enter 发送' : '已切换:Enter 发送,Shift+Enter 换行');
|
|
1145
1713
|
};
|
|
1714
|
+
inputEl.addEventListener('focus', () => renderContextChips());
|
|
1146
1715
|
inputEl.addEventListener('input', () => {
|
|
1147
1716
|
autoGrowInput();
|
|
1148
1717
|
updateSlashPopover();
|
|
@@ -1169,6 +1738,34 @@
|
|
|
1169
1738
|
}
|
|
1170
1739
|
});
|
|
1171
1740
|
sendBtn.onclick = handleSend;
|
|
1741
|
+
stopBtn.onclick = handleStop;
|
|
1742
|
+
|
|
1743
|
+
window.addEventListener('clado:agent-prefill', ev => {
|
|
1744
|
+
const d = ev.detail || {};
|
|
1745
|
+
setDrawerOpen(true);
|
|
1746
|
+
if (d.selectedText) {
|
|
1747
|
+
pinnedSnippet = { file: d.file || '', node: d.node || null, text: d.selectedText };
|
|
1748
|
+
}
|
|
1749
|
+
renderContextChips();
|
|
1750
|
+
if (d.prompt) {
|
|
1751
|
+
inputEl.value = d.prompt;
|
|
1752
|
+
} else if (d.mode === 'edit' && d.selectedText) {
|
|
1753
|
+
inputEl.value = '请优化或重写我框选的这段内容,使其更清晰准确:';
|
|
1754
|
+
} else if (d.mode === 'ask' && d.selectedText) {
|
|
1755
|
+
inputEl.value = '请结合上下游卡片解释我框选的这段内容:';
|
|
1756
|
+
}
|
|
1757
|
+
autoGrowInput();
|
|
1758
|
+
inputEl.focus();
|
|
1759
|
+
inputEl.setSelectionRange?.(inputEl.value.length, inputEl.value.length);
|
|
1760
|
+
});
|
|
1761
|
+
window.addEventListener('clado:focus-session', ev => {
|
|
1762
|
+
const d = ev.detail || {};
|
|
1763
|
+
const byId = d.sessionId ? sessions.find(s => s.id === d.sessionId) : null;
|
|
1764
|
+
const byRole = !byId && d.roleId ? sessions.find(s => !s.archived && s.roleId === d.roleId) : null;
|
|
1765
|
+
const target = byId || byRole;
|
|
1766
|
+
if (target) selectSession(target.id, true);
|
|
1767
|
+
else setDrawerOpen(true);
|
|
1768
|
+
});
|
|
1172
1769
|
document.addEventListener('click', e => {
|
|
1173
1770
|
if (!dock.contains(e.target)) {
|
|
1174
1771
|
closePopover();
|
|
@@ -1249,35 +1846,164 @@
|
|
|
1249
1846
|
}
|
|
1250
1847
|
|
|
1251
1848
|
function renderModelsTab() {
|
|
1849
|
+
const rt = meta.runtimeSettings || {
|
|
1850
|
+
thinkingLevel: 'medium',
|
|
1851
|
+
transport: 'auto',
|
|
1852
|
+
hideThinkingBlock: false,
|
|
1853
|
+
compactionEnabled: true,
|
|
1854
|
+
compactionTriggerPercent: 85,
|
|
1855
|
+
keepRecentTokens: 20000,
|
|
1856
|
+
retryEnabled: true,
|
|
1857
|
+
maxRetries: 3,
|
|
1858
|
+
cacheWarming: 'off',
|
|
1859
|
+
};
|
|
1860
|
+
const activeCtx = meta.activeContextWindow || 128000;
|
|
1861
|
+
const calcReserve = pct => Math.max(4096, Math.round(activeCtx * (1 - pct / 100)));
|
|
1862
|
+
|
|
1252
1863
|
sBody.innerHTML = `
|
|
1253
1864
|
<div>
|
|
1254
1865
|
<div style="font-size:18px;font-weight:630;">模型与供应商</div>
|
|
1255
|
-
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">直写 Pi 原生 <code style="font-family:ui-monospace,monospace;">auth.json</code> 与 <code style="font-family:ui-monospace,monospace;">
|
|
1866
|
+
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">直写 Pi 原生 <code style="font-family:ui-monospace,monospace;">auth.json</code>、<code style="font-family:ui-monospace,monospace;">models.json</code> 与 <code style="font-family:ui-monospace,monospace;">settings.json</code>,统一配置官方模型、上下文压缩、思考强度与流式传输。</div>
|
|
1867
|
+
</div>
|
|
1868
|
+
|
|
1869
|
+
<div class="clado-well-box" data-runtime-box style="display:flex;flex-direction:column;gap:12px;">
|
|
1870
|
+
<div class="clado-setting-row">
|
|
1871
|
+
<div>
|
|
1872
|
+
<div style="font-size:13.5px;font-weight:610;">运行参数与上下文策略</div>
|
|
1873
|
+
<div style="font-size:11.5px;color:var(--clado-ui-muted);margin-top:2px;">当前默认模型上下文上限:<strong>${esc(formatTokenCount(activeCtx))}</strong>(${activeCtx.toLocaleString()} tokens)</div>
|
|
1874
|
+
</div>
|
|
1875
|
+
<button type="button" class="clado-ui-button clado-ui-button-primary" data-rt-save style="min-height:28px;padding:4px 12px;font-size:12px;">保存运行参数</button>
|
|
1876
|
+
</div>
|
|
1877
|
+
|
|
1878
|
+
<div class="clado-rt-grid">
|
|
1879
|
+
<div class="clado-rt-field">
|
|
1880
|
+
<div class="clado-rt-label"><span>思考强度(Thinking Level)</span></div>
|
|
1881
|
+
<select class="clado-field" data-rt-think>
|
|
1882
|
+
<option value="off" ${rt.thinkingLevel === 'off' ? 'selected' : ''}>off · 关闭思考</option>
|
|
1883
|
+
<option value="minimal" ${rt.thinkingLevel === 'minimal' ? 'selected' : ''}>minimal · 极简思考</option>
|
|
1884
|
+
<option value="low" ${rt.thinkingLevel === 'low' ? 'selected' : ''}>low · 轻量思考</option>
|
|
1885
|
+
<option value="medium" ${rt.thinkingLevel === 'medium' ? 'selected' : ''}>medium · 均衡(默认)</option>
|
|
1886
|
+
<option value="high" ${rt.thinkingLevel === 'high' ? 'selected' : ''}>high · 深度思考</option>
|
|
1887
|
+
<option value="xhigh" ${rt.thinkingLevel === 'xhigh' ? 'selected' : ''}>xhigh · 超高强度</option>
|
|
1888
|
+
<option value="max" ${rt.thinkingLevel === 'max' ? 'selected' : ''}>max · 极限推理</option>
|
|
1889
|
+
</select>
|
|
1890
|
+
</div>
|
|
1891
|
+
<div class="clado-rt-field">
|
|
1892
|
+
<div class="clado-rt-label"><span>流式传输模式(Transport)</span></div>
|
|
1893
|
+
<select class="clado-field" data-rt-trans>
|
|
1894
|
+
<option value="auto" ${rt.transport === 'auto' ? 'selected' : ''}>auto · 自动流式(推荐)</option>
|
|
1895
|
+
<option value="sse" ${rt.transport === 'sse' ? 'selected' : ''}>sse · 强制 SSE 流式返回</option>
|
|
1896
|
+
<option value="websocket" ${rt.transport === 'websocket' ? 'selected' : ''}>websocket · WebSocket 持久流</option>
|
|
1897
|
+
<option value="websocket-cached" ${rt.transport === 'websocket-cached' ? 'selected' : ''}>websocket-cached · WS 缓存流</option>
|
|
1898
|
+
</select>
|
|
1899
|
+
</div>
|
|
1900
|
+
<div class="clado-rt-field">
|
|
1901
|
+
<div class="clado-rt-label">
|
|
1902
|
+
<span>自动压缩触发阈值</span>
|
|
1903
|
+
<span data-rt-pct-lbl style="font-family:ui-monospace,monospace;color:var(--clado-ui-text);">${rt.compactionTriggerPercent}%(约预留 ${formatTokenCount(calcReserve(rt.compactionTriggerPercent))})</span>
|
|
1904
|
+
</div>
|
|
1905
|
+
<input class="clado-field" data-rt-pct type="range" min="50" max="95" step="5" value="${rt.compactionTriggerPercent}" style="padding:4px 0;accent-color:var(--clado-ui-brand);" />
|
|
1906
|
+
</div>
|
|
1907
|
+
<div class="clado-rt-field">
|
|
1908
|
+
<div class="clado-rt-label"><span>压缩保留最近 Tokens</span></div>
|
|
1909
|
+
<input class="clado-field" data-rt-keep type="number" min="2048" max="256000" step="1024" value="${rt.keepRecentTokens}" />
|
|
1910
|
+
</div>
|
|
1911
|
+
<div class="clado-rt-field">
|
|
1912
|
+
<div class="clado-rt-label"><span>缓存预热策略(Cache Warming)</span></div>
|
|
1913
|
+
<select class="clado-field" data-rt-cache>
|
|
1914
|
+
<option value="off" ${rt.cacheWarming === 'off' ? 'selected' : ''}>off · 关闭(省费用)</option>
|
|
1915
|
+
<option value="streaming" ${rt.cacheWarming === 'streaming' ? 'selected' : ''}>streaming · 流式保活</option>
|
|
1916
|
+
<option value="idle" ${rt.cacheWarming === 'idle' ? 'selected' : ''}>idle · 空闲持续预热</option>
|
|
1917
|
+
</select>
|
|
1918
|
+
</div>
|
|
1919
|
+
<div class="clado-rt-field">
|
|
1920
|
+
<div class="clado-rt-label"><span>网络异常最大重试次数</span></div>
|
|
1921
|
+
<input class="clado-field" data-rt-retries type="number" min="0" max="10" step="1" value="${rt.maxRetries}" />
|
|
1922
|
+
</div>
|
|
1923
|
+
</div>
|
|
1924
|
+
|
|
1925
|
+
<div class="clado-rt-checks">
|
|
1926
|
+
<label><input type="checkbox" data-rt-comp-on ${rt.compactionEnabled ? 'checked' : ''} /> 启用自动上下文压缩</label>
|
|
1927
|
+
<label><input type="checkbox" data-rt-retry-on ${rt.retryEnabled ? 'checked' : ''} /> 启用网络波动自动重试</label>
|
|
1928
|
+
<label><input type="checkbox" data-rt-hide-think ${rt.hideThinkingBlock ? 'checked' : ''} /> 默认隐藏思考过程块</label>
|
|
1929
|
+
</div>
|
|
1256
1930
|
</div>
|
|
1931
|
+
|
|
1257
1932
|
<div data-provider-list style="display:flex;flex-direction:column;gap:10px;"></div>
|
|
1258
1933
|
`;
|
|
1934
|
+
|
|
1935
|
+
const rtBox = sBody.querySelector('[data-runtime-box]');
|
|
1936
|
+
const pctInput = rtBox.querySelector('[data-rt-pct]');
|
|
1937
|
+
const pctLbl = rtBox.querySelector('[data-rt-pct-lbl]');
|
|
1938
|
+
pctInput.addEventListener('input', () => {
|
|
1939
|
+
const v = Number(pctInput.value) || 85;
|
|
1940
|
+
pctLbl.textContent = `${v}%(约预留 ${formatTokenCount(calcReserve(v))})`;
|
|
1941
|
+
});
|
|
1942
|
+
rtBox.querySelector('[data-rt-save]').onclick = async () => {
|
|
1943
|
+
try {
|
|
1944
|
+
await apiConfig({
|
|
1945
|
+
action: 'save_runtime_settings',
|
|
1946
|
+
thinkingLevel: rtBox.querySelector('[data-rt-think]').value,
|
|
1947
|
+
transport: rtBox.querySelector('[data-rt-trans]').value,
|
|
1948
|
+
compactionEnabled: rtBox.querySelector('[data-rt-comp-on]').checked,
|
|
1949
|
+
compactionTriggerPercent: Number(pctInput.value) || 85,
|
|
1950
|
+
keepRecentTokens: Number(rtBox.querySelector('[data-rt-keep]').value) || 20000,
|
|
1951
|
+
cacheWarming: rtBox.querySelector('[data-rt-cache]').value,
|
|
1952
|
+
retryEnabled: rtBox.querySelector('[data-rt-retry-on]').checked,
|
|
1953
|
+
maxRetries: Number(rtBox.querySelector('[data-rt-retries]').value) || 3,
|
|
1954
|
+
hideThinkingBlock: rtBox.querySelector('[data-rt-hide-think]').checked,
|
|
1955
|
+
});
|
|
1956
|
+
renderContextMeter();
|
|
1957
|
+
renderSettings();
|
|
1958
|
+
showToast('已保存运行参数并写入 Pi 原生 settings.json');
|
|
1959
|
+
} catch (e) { showToast(e.message); }
|
|
1960
|
+
};
|
|
1961
|
+
|
|
1259
1962
|
const list = sBody.querySelector('[data-provider-list]');
|
|
1260
1963
|
for (const p of meta.providers || []) {
|
|
1261
1964
|
const card = document.createElement('div');
|
|
1262
1965
|
card.className = 'clado-well-box';
|
|
1263
1966
|
const isEditing = editingProviderId === p.id;
|
|
1967
|
+
const recs = Array.isArray(p.recommendedModels) ? p.recommendedModels : [];
|
|
1264
1968
|
card.innerHTML = `
|
|
1265
1969
|
<div class="clado-setting-row">
|
|
1266
1970
|
<div>
|
|
1267
|
-
<div style="display:flex;align-items:center;gap:8px;">
|
|
1971
|
+
<div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">
|
|
1268
1972
|
<span style="font-size:13.5px;font-weight:610;">${esc(p.name)}</span>
|
|
1269
1973
|
${p.configured ? `<span class="clado-chip clado-chip-mint">已连接${p.maskedKey ? ' · ' + esc(p.maskedKey) : ''}</span>` : '<span class="clado-chip clado-chip-neutral">未配置</span>'}
|
|
1270
1974
|
${meta.defaultProvider === p.id ? `<span class="clado-chip clado-chip-sky">默认 · ${esc(meta.defaultModel)}</span>` : ''}
|
|
1975
|
+
${p.contextWindow ? `<span class="clado-chip clado-chip-neutral">${esc(formatTokenCount(p.contextWindow))} 上下文</span>` : ''}
|
|
1271
1976
|
</div>
|
|
1272
1977
|
<div style="font-family:ui-monospace,monospace;font-size:11.5px;color:var(--clado-ui-muted);margin-top:3px;">${esc(p.baseUrl || p.hint)}</div>
|
|
1273
1978
|
</div>
|
|
1274
1979
|
<button type="button" class="clado-ui-button" data-edit style="border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);">${isEditing ? '收起' : '配置'}</button>
|
|
1275
1980
|
</div>
|
|
1276
1981
|
${isEditing ? `
|
|
1277
|
-
<div style="margin-top:12px;padding-top:12px;border-top:1px solid var(--clado-ui-edge);display:grid;gap:
|
|
1982
|
+
<div style="margin-top:12px;padding-top:12px;border-top:1px solid var(--clado-ui-edge);display:grid;gap:9px;">
|
|
1983
|
+
${recs.length ? `
|
|
1984
|
+
<div>
|
|
1985
|
+
<div style="font-size:11px;color:var(--clado-ui-subtle);margin-bottom:5px;">官方最新模型快选(点击自动填充模型 ID 与官方上下文容量)</div>
|
|
1986
|
+
<div class="clado-model-presets">
|
|
1987
|
+
${recs.map(rm => `<button type="button" class="clado-model-preset-chip ${rm.id === p.defaultModel ? 'active' : ''}" data-pick-model="${esc(rm.id)}" data-pick-ctx="${rm.contextWindow || 128000}" data-pick-max="${rm.maxTokens || 16384}" data-pick-reas="${rm.reasoning ? '1' : '0'}" title="${esc(rm.label)}">${esc(rm.id)} · ${esc(formatTokenCount(rm.contextWindow || 128000))}</button>`).join('')}
|
|
1988
|
+
</div>
|
|
1989
|
+
</div>
|
|
1990
|
+
` : ''}
|
|
1278
1991
|
${!p.keyless ? `<input class="clado-field" data-f-key type="password" placeholder="API Key(留空保持不变)" value="${esc(p.maskedKey)}" />` : ''}
|
|
1279
1992
|
<input class="clado-field" data-f-url type="text" placeholder="Base URL(可选自定义代理地址)" value="${esc(p.baseUrl)}" />
|
|
1280
|
-
<input class="clado-field" data-f-model type="text" placeholder="默认模型 ID(如 ${esc(p.defaultModel || '
|
|
1993
|
+
<input class="clado-field" data-f-model type="text" placeholder="默认模型 ID(如 ${esc(p.defaultModel || 'deepseek-flash')})" value="${esc(p.defaultModel)}" />
|
|
1994
|
+
<div class="clado-rt-grid">
|
|
1995
|
+
<div class="clado-rt-field">
|
|
1996
|
+
<div class="clado-rt-label"><span>最大上下文窗口(Context Window)</span></div>
|
|
1997
|
+
<input class="clado-field" data-f-ctx type="number" min="4096" max="4000000" step="1000" value="${p.contextWindow || 128000}" />
|
|
1998
|
+
</div>
|
|
1999
|
+
<div class="clado-rt-field">
|
|
2000
|
+
<div class="clado-rt-label"><span>最大单次输出(Max Tokens)</span></div>
|
|
2001
|
+
<input class="clado-field" data-f-maxout type="number" min="1024" max="512000" step="1024" value="${p.maxTokens || 16384}" />
|
|
2002
|
+
</div>
|
|
2003
|
+
</div>
|
|
2004
|
+
<div class="clado-rt-checks">
|
|
2005
|
+
<label><input type="checkbox" data-f-reas ${p.reasoning ? 'checked' : ''} /> 该模型支持思考/推理模式(Thinking / Reasoning)</label>
|
|
2006
|
+
</div>
|
|
1281
2007
|
<div style="display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:4px;">
|
|
1282
2008
|
${p.configured ? '<button type="button" class="clado-ui-button" data-del style="color:#be123c;">清除凭据</button>' : '<span></span>'}
|
|
1283
2009
|
<button type="button" class="clado-ui-button clado-ui-button-primary" data-save>保存并设为默认</button>
|
|
@@ -1290,6 +2016,15 @@
|
|
|
1290
2016
|
renderSettings();
|
|
1291
2017
|
};
|
|
1292
2018
|
if (isEditing) {
|
|
2019
|
+
card.querySelectorAll('[data-pick-model]').forEach(btn => {
|
|
2020
|
+
btn.onclick = () => {
|
|
2021
|
+
card.querySelector('[data-f-model]').value = btn.dataset.pickModel;
|
|
2022
|
+
card.querySelector('[data-f-ctx]').value = btn.dataset.pickCtx;
|
|
2023
|
+
card.querySelector('[data-f-maxout]').value = btn.dataset.pickMax;
|
|
2024
|
+
card.querySelector('[data-f-reas]').checked = btn.dataset.pickReas === '1';
|
|
2025
|
+
card.querySelectorAll('[data-pick-model]').forEach(b => b.classList.toggle('active', b === btn));
|
|
2026
|
+
};
|
|
2027
|
+
});
|
|
1293
2028
|
card.querySelector('[data-save]').onclick = async () => {
|
|
1294
2029
|
try {
|
|
1295
2030
|
await apiConfig({
|
|
@@ -1299,9 +2034,13 @@
|
|
|
1299
2034
|
apiKey: card.querySelector('[data-f-key]')?.value || '',
|
|
1300
2035
|
baseUrl: card.querySelector('[data-f-url]')?.value || '',
|
|
1301
2036
|
defaultModel: card.querySelector('[data-f-model]')?.value || '',
|
|
2037
|
+
contextWindow: Number(card.querySelector('[data-f-ctx]')?.value) || undefined,
|
|
2038
|
+
maxTokens: Number(card.querySelector('[data-f-maxout]')?.value) || undefined,
|
|
2039
|
+
reasoning: Boolean(card.querySelector('[data-f-reas]')?.checked),
|
|
1302
2040
|
setAsDefault: true,
|
|
1303
2041
|
});
|
|
1304
2042
|
editingProviderId = '';
|
|
2043
|
+
renderContextMeter();
|
|
1305
2044
|
renderSettings();
|
|
1306
2045
|
showToast('已保存 ' + p.name + ' 并写入 Pi 原生配置');
|
|
1307
2046
|
} catch (e) { showToast(e.message); }
|
|
@@ -1310,6 +2049,7 @@
|
|
|
1310
2049
|
if (delBtn) delBtn.onclick = async () => {
|
|
1311
2050
|
await apiConfig({ action: 'delete_provider', providerId: p.id });
|
|
1312
2051
|
editingProviderId = '';
|
|
2052
|
+
renderContextMeter();
|
|
1313
2053
|
renderSettings();
|
|
1314
2054
|
showToast('已清除 ' + p.name + ' 配置');
|
|
1315
2055
|
};
|
|
@@ -1323,17 +2063,17 @@
|
|
|
1323
2063
|
<div class="clado-setting-row">
|
|
1324
2064
|
<div>
|
|
1325
2065
|
<div style="font-size:18px;font-weight:630;">角色与模板</div>
|
|
1326
|
-
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;"
|
|
2066
|
+
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">人设只需专注专业流程与质量标准(如单测规范、代码审查);Clado 会自动注入画布与工具上下文,无需在人设中重复编写工具说明。</div>
|
|
1327
2067
|
</div>
|
|
1328
2068
|
<button type="button" class="clado-ui-button clado-ui-button-primary" data-add-role>+ 新建角色</button>
|
|
1329
2069
|
</div>
|
|
1330
2070
|
<div data-role-form class="clado-well-box" hidden style="display:none;flex-direction:column;gap:8px;">
|
|
1331
2071
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:8px;">
|
|
1332
|
-
<input class="clado-field" data-r-name placeholder="
|
|
1333
|
-
<input class="clado-field" data-r-phase placeholder="
|
|
2072
|
+
<input class="clado-field" data-r-name placeholder="角色名称(如:单元测试专家)" />
|
|
2073
|
+
<input class="clado-field" data-r-phase placeholder="阶段标签(如:单测阶段)" />
|
|
1334
2074
|
</div>
|
|
1335
|
-
<input class="clado-field" data-r-desc placeholder="
|
|
1336
|
-
<textarea class="clado-field clado-scroll" data-r-prompt rows="3" placeholder="
|
|
2075
|
+
<input class="clado-field" data-r-desc placeholder="一句话专业职责描述" />
|
|
2076
|
+
<textarea class="clado-field clado-scroll" data-r-prompt rows="3" placeholder="只需写该角色的专业工作流与细节要求(Clado 平台工具与画布用法会自动注入)"></textarea>
|
|
1337
2077
|
<div style="display:flex;justify-content:flex-end;gap:8px;">
|
|
1338
2078
|
<button type="button" class="clado-ui-button" data-r-cancel>取消</button>
|
|
1339
2079
|
<button type="button" class="clado-ui-button clado-ui-button-primary" data-r-save>保存角色</button>
|
|
@@ -1542,32 +2282,123 @@
|
|
|
1542
2282
|
}
|
|
1543
2283
|
}
|
|
1544
2284
|
|
|
2285
|
+
let memorySubTab = 'agents';
|
|
1545
2286
|
function renderMemoryTab() {
|
|
1546
2287
|
const content = meta.memory?.content || '';
|
|
2288
|
+
const pdocs = meta.platformDocs || {};
|
|
2289
|
+
const ctxPath = pdocs.contextPath || ((meta.agentDir || '~/.pi/agent') + '/clado-context.md');
|
|
2290
|
+
const refPath = pdocs.referencePath || ((meta.agentDir || '~/.pi/agent') + '/clado-reference.md');
|
|
2291
|
+
const ctxContent = pdocs.contextContent || '';
|
|
2292
|
+
const refContent = pdocs.referenceContent || '';
|
|
2293
|
+
|
|
2294
|
+
const isAgents = memorySubTab === 'agents';
|
|
2295
|
+
const isPlatform = memorySubTab === 'platform';
|
|
2296
|
+
const isReference = memorySubTab === 'reference';
|
|
2297
|
+
|
|
1547
2298
|
sBody.innerHTML = `
|
|
1548
2299
|
<div class="clado-setting-row">
|
|
1549
2300
|
<div>
|
|
1550
|
-
<div style="font-size:18px;font-weight:630;"
|
|
1551
|
-
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;"
|
|
2301
|
+
<div style="font-size:18px;font-weight:630;">工作区与平台上下文</div>
|
|
2302
|
+
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">项目记忆 <code style="font-family:ui-monospace,monospace;">AGENTS.md</code> 与自动注入所有角色的 Clado 平台文档。</div>
|
|
1552
2303
|
</div>
|
|
1553
|
-
<
|
|
2304
|
+
<div style="display:flex;gap:6px;">
|
|
2305
|
+
${isAgents ? '<button type="button" class="clado-ui-button clado-ui-button-primary" data-save-mem>保存 AGENTS.md</button>' : ''}
|
|
2306
|
+
${isPlatform ? '<button type="button" class="clado-ui-button" data-reset-pctx style="border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);">恢复默认</button><button type="button" class="clado-ui-button clado-ui-button-primary" data-save-pctx>保存注入文档</button>' : ''}
|
|
2307
|
+
</div>
|
|
2308
|
+
</div>
|
|
2309
|
+
<div class="clado-ctx-pills" style="margin-bottom:2px;">
|
|
2310
|
+
<button type="button" class="clado-ctx-pill-btn ${isAgents ? 'active' : ''}" data-mtab="agents">项目记忆 (AGENTS.md)</button>
|
|
2311
|
+
<button type="button" class="clado-ctx-pill-btn ${isPlatform ? 'active' : ''}" data-mtab="platform">自动注入上下文 (clado-context.md)${pdocs.customized ? ' · 已自定义' : ''}</button>
|
|
2312
|
+
<button type="button" class="clado-ctx-pill-btn ${isReference ? 'active' : ''}" data-mtab="reference">完整参考手册 (clado-reference.md)</button>
|
|
1554
2313
|
</div>
|
|
1555
|
-
|
|
2314
|
+
${isAgents ? `
|
|
2315
|
+
<div class="clado-well-box clado-setting-row" style="padding:9px 12px;font-size:11.5px;color:var(--clado-ui-muted);">
|
|
2316
|
+
<span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">文件路径:<code style="font-family:ui-monospace,monospace;color:var(--clado-ui-text);">${esc(meta.memory?.path || 'AGENTS.md')}</code></span>
|
|
2317
|
+
</div>
|
|
2318
|
+
<textarea class="clado-field clado-scroll" data-mem-text style="flex:1;min-height:320px;font-family:ui-monospace,monospace;line-height:1.65;resize:none;" placeholder="# AGENTS.md - 写下本项目的代码约定、测试命令与架构约束…">${esc(content)}</textarea>
|
|
2319
|
+
` : isPlatform ? `
|
|
2320
|
+
<div class="clado-well-box clado-setting-row" style="padding:9px 12px;font-size:11.5px;color:var(--clado-ui-muted);gap:8px;">
|
|
2321
|
+
<span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">自动注入所有内置/自定义角色:<code style="font-family:ui-monospace,monospace;color:var(--clado-ui-text);">${esc(ctxPath)}</code></span>
|
|
2322
|
+
<button type="button" class="clado-dock-mini-btn" data-copy-path="${esc(ctxPath)}">复制路径</button>
|
|
2323
|
+
</div>
|
|
2324
|
+
<textarea class="clado-field clado-scroll" data-pctx-text style="flex:1;min-height:320px;font-family:ui-monospace,monospace;line-height:1.65;resize:none;">${esc(ctxContent)}</textarea>
|
|
2325
|
+
` : `
|
|
2326
|
+
<div class="clado-well-box clado-setting-row" style="padding:9px 12px;font-size:11.5px;color:var(--clado-ui-muted);gap:8px;">
|
|
2327
|
+
<span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">AI 按需 read 查阅的完整手册:<code style="font-family:ui-monospace,monospace;color:var(--clado-ui-text);">${esc(refPath)}</code></span>
|
|
2328
|
+
<button type="button" class="clado-dock-mini-btn" data-copy-path="${esc(refPath)}">复制路径</button>
|
|
2329
|
+
</div>
|
|
2330
|
+
<textarea class="clado-field clado-scroll" readonly style="flex:1;min-height:320px;font-family:ui-monospace,monospace;line-height:1.65;resize:none;opacity:.92;">${esc(refContent)}</textarea>
|
|
2331
|
+
`}
|
|
1556
2332
|
`;
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
2333
|
+
|
|
2334
|
+
sBody.querySelectorAll('[data-mtab]').forEach(btn => {
|
|
2335
|
+
btn.onclick = () => {
|
|
2336
|
+
memorySubTab = btn.dataset.mtab;
|
|
2337
|
+
renderMemoryTab();
|
|
2338
|
+
};
|
|
2339
|
+
});
|
|
2340
|
+
sBody.querySelectorAll('[data-copy-path]').forEach(btn => {
|
|
2341
|
+
btn.onclick = () => {
|
|
2342
|
+
navigator.clipboard?.writeText(btn.dataset.copyPath || '').catch(() => {});
|
|
2343
|
+
showToast('已复制文件路径');
|
|
2344
|
+
};
|
|
2345
|
+
});
|
|
2346
|
+
const saveMemBtn = sBody.querySelector('[data-save-mem]');
|
|
2347
|
+
if (saveMemBtn) {
|
|
2348
|
+
saveMemBtn.onclick = async () => {
|
|
2349
|
+
try {
|
|
2350
|
+
await apiConfig({ action: 'save_memory', content: sBody.querySelector('[data-mem-text]').value });
|
|
2351
|
+
showToast('已保存项目 AGENTS.md');
|
|
2352
|
+
} catch (e) { showToast(e.message); }
|
|
2353
|
+
};
|
|
2354
|
+
}
|
|
2355
|
+
const savePctxBtn = sBody.querySelector('[data-save-pctx]');
|
|
2356
|
+
if (savePctxBtn) {
|
|
2357
|
+
savePctxBtn.onclick = async () => {
|
|
2358
|
+
try {
|
|
2359
|
+
await apiConfig({ action: 'save_platform_context', content: sBody.querySelector('[data-pctx-text]').value });
|
|
2360
|
+
renderMemoryTab();
|
|
2361
|
+
showToast('已保存 Clado 平台注入上下文');
|
|
2362
|
+
} catch (e) { showToast(e.message); }
|
|
2363
|
+
};
|
|
2364
|
+
}
|
|
2365
|
+
const resetPctxBtn = sBody.querySelector('[data-reset-pctx]');
|
|
2366
|
+
if (resetPctxBtn) {
|
|
2367
|
+
resetPctxBtn.onclick = async () => {
|
|
2368
|
+
try {
|
|
2369
|
+
await apiConfig({ action: 'reset_platform_context' });
|
|
2370
|
+
renderMemoryTab();
|
|
2371
|
+
showToast('已恢复默认平台注入文档与参考手册');
|
|
2372
|
+
} catch (e) { showToast(e.message); }
|
|
2373
|
+
};
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
function readPresenceTtlSeconds() {
|
|
2378
|
+
try {
|
|
2379
|
+
const raw = localStorage.getItem('clado-presence-ttl');
|
|
2380
|
+
if (raw !== null && raw !== '') {
|
|
2381
|
+
const n = Number(raw);
|
|
2382
|
+
if (Number.isFinite(n) && n >= 0) return Math.round(n);
|
|
2383
|
+
}
|
|
2384
|
+
} catch {}
|
|
2385
|
+
return 15;
|
|
1563
2386
|
}
|
|
1564
2387
|
|
|
1565
2388
|
function renderAppearanceTab() {
|
|
1566
2389
|
const isDark = document.documentElement.dataset.theme === 'dark';
|
|
2390
|
+
const curTtl = readPresenceTtlSeconds();
|
|
2391
|
+
const ttlOptions = [
|
|
2392
|
+
[0, '立即关闭 (0s)'],
|
|
2393
|
+
[10, '10 秒'],
|
|
2394
|
+
[15, '15 秒 (默认)'],
|
|
2395
|
+
[30, '30 秒'],
|
|
2396
|
+
[60, '60 秒'],
|
|
2397
|
+
];
|
|
1567
2398
|
sBody.innerHTML = `
|
|
1568
2399
|
<div>
|
|
1569
2400
|
<div style="font-size:18px;font-weight:630;">外观与连接</div>
|
|
1570
|
-
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;"
|
|
2401
|
+
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">液态冰晶玻璃主题、卡片协同呼吸余韵、画布导出与外部 /mcp 互联端点。</div>
|
|
1571
2402
|
</div>
|
|
1572
2403
|
<div class="clado-well-box clado-setting-row">
|
|
1573
2404
|
<div>
|
|
@@ -1576,6 +2407,15 @@
|
|
|
1576
2407
|
</div>
|
|
1577
2408
|
<button type="button" class="clado-ui-button clado-ui-button-primary" data-toggle-theme>${isDark ? '切换浅色' : '切换暗色'}</button>
|
|
1578
2409
|
</div>
|
|
2410
|
+
<div class="clado-well-box" style="display:flex;flex-direction:column;gap:10px;">
|
|
2411
|
+
<div>
|
|
2412
|
+
<div style="font-size:13.5px;font-weight:610;">卡片协同呼吸余韵</div>
|
|
2413
|
+
<div style="font-size:12px;color:var(--clado-ui-muted);margin-top:2px;">AI 执行期间卡片底部呼吸自动常亮,回合结束/停止后自动释放并保留短暂余韵(无需手动解锁)。</div>
|
|
2414
|
+
</div>
|
|
2415
|
+
<div class="clado-ctx-pills" data-presence-ttl-group>
|
|
2416
|
+
${ttlOptions.map(([sec, label]) => `<button type="button" class="clado-ctx-pill-btn ${curTtl === sec ? 'active' : ''}" data-presence-ttl="${sec}">${label}</button>`).join('')}
|
|
2417
|
+
</div>
|
|
2418
|
+
</div>
|
|
1579
2419
|
${actions.capture ? `
|
|
1580
2420
|
<div class="clado-well-box clado-setting-row">
|
|
1581
2421
|
<div>
|
|
@@ -1597,6 +2437,16 @@
|
|
|
1597
2437
|
actions.setTheme?.(next);
|
|
1598
2438
|
renderAppearanceTab();
|
|
1599
2439
|
};
|
|
2440
|
+
sBody.querySelectorAll('[data-presence-ttl]').forEach(btn => {
|
|
2441
|
+
btn.onclick = () => {
|
|
2442
|
+
const sec = Number(btn.dataset.presenceTtl);
|
|
2443
|
+
if (!Number.isFinite(sec) || sec < 0) return;
|
|
2444
|
+
try { localStorage.setItem('clado-presence-ttl', String(sec)); } catch {}
|
|
2445
|
+
window.dispatchEvent(new CustomEvent('clado:presence-config', { detail: { afterglowMs: sec * 1000 } }));
|
|
2446
|
+
renderAppearanceTab();
|
|
2447
|
+
showToast(sec === 0 ? '卡片呼吸余韵已设为结束后立即关闭' : `卡片呼吸余韵已设为 ${sec} 秒`);
|
|
2448
|
+
};
|
|
2449
|
+
});
|
|
1600
2450
|
const cap = sBody.querySelector('[data-cap-shot]');
|
|
1601
2451
|
if (cap) cap.onclick = () => { settingsMask.hidden = true; actions.capture?.(); };
|
|
1602
2452
|
sBody.querySelector('[data-copy-mcp]').onclick = () => {
|