cladogram 0.6.0-beta.1 → 0.6.0-beta.2
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/docs/release.md +8 -0
- package/package.json +1 -1
- package/plugins/agent/index.js +801 -104
- package/plugins/agent/style.css +449 -56
- package/plugins/view-controls/style.css +7 -7
- package/src/agent/pi-bridge.js +187 -53
- package/src/html/plugin-ui.css +1 -1
- package/src/server/agent.js +6 -0
- package/src/server/assets/library.css +12 -12
package/plugins/agent/index.js
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
undo: ico('<path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/>', 12.5),
|
|
7
7
|
plus: ico('<path d="M12 5v14M5 12h14"/>'),
|
|
8
8
|
close: ico('<path d="M18 6 6 18M6 6l12 12"/>'),
|
|
9
|
+
chevDown: ico('<path d="m6 9 6 6 6-6"/>', 12),
|
|
10
|
+
edit: ico('<path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z"/>', 12),
|
|
11
|
+
archive: ico('<rect x="3" y="4" width="18" height="4" rx="1"/><path d="M5 8v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8"/><path d="M10 12h4"/>', 12),
|
|
12
|
+
trash: ico('<path d="M3 6h18"/><path d="M8 6V4h8v2"/><path d="M6 6l1 14a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-14"/>', 12),
|
|
9
13
|
cpu: ico('<rect x="4" y="4" width="16" height="16" rx="2"/><rect x="9" y="9" width="6" height="6"/><path d="M9 1v3M15 1v3M9 20v3M15 20v3M20 9h3M20 14h3M1 9h3M1 14h3"/>'),
|
|
10
14
|
users: ico('<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75"/>'),
|
|
11
15
|
box: ico('<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><path d="M3.27 6.96 12 12.01l8.73-5.05M12 22.08V12"/>'),
|
|
@@ -21,39 +25,209 @@
|
|
|
21
25
|
qa: '请阅读当前仓库核心模块与已有测试,创建一张名为 test-matrix.md 的测试与压测矩阵画布,列出主链路、并发边界与异常回归检查项。',
|
|
22
26
|
};
|
|
23
27
|
|
|
28
|
+
// ===========================================================================
|
|
29
|
+
// Safe Rich Markdown Renderer (zero external dependencies, strict HTML escape)
|
|
30
|
+
// ===========================================================================
|
|
31
|
+
function renderInline(raw) {
|
|
32
|
+
const codeSlots = [];
|
|
33
|
+
let s = String(raw ?? '').replace(/`([^`\n]+)`/g, (_, inner) => {
|
|
34
|
+
const idx = codeSlots.length;
|
|
35
|
+
codeSlots.push(`<code>${esc(inner)}</code>`);
|
|
36
|
+
return `\u0000CODE${idx}\u0000`;
|
|
37
|
+
});
|
|
38
|
+
s = esc(s);
|
|
39
|
+
// Safe links [label](url)
|
|
40
|
+
s = s.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_, label, url) => {
|
|
41
|
+
const cleanUrl = url.replace(/&/g, '&');
|
|
42
|
+
if (/^(https?:\/\/|\/)/i.test(cleanUrl)) {
|
|
43
|
+
return `<a href="${esc(cleanUrl)}" target="_blank" rel="noopener noreferrer">${label}</a>`;
|
|
44
|
+
}
|
|
45
|
+
return `${label} (${url})`;
|
|
46
|
+
});
|
|
47
|
+
// Bold, strikethrough, italic (avoiding snake_case underscores inside words)
|
|
48
|
+
s = s.replace(/\*\*([^*]+?)\*\*/g, '<strong>$1</strong>');
|
|
49
|
+
s = s.replace(/~~([^~]+?)~~/g, '<del>$1</del>');
|
|
50
|
+
s = s.replace(/(^|[\s((【「“',。;:])\*([^*\n]+?)\*(?=[\s))】」”',。;:.,!?]|$)/g, '$1<em>$2</em>');
|
|
51
|
+
s = s.replace(/(^|[\s((【「“',。;:])_([^_\n]+?)_(?=[\s))】」”',。;:.,!?]|$)/g, '$1<em>$2</em>');
|
|
52
|
+
s = s.replace(/\u0000CODE(\d+)\u0000/g, (_, idx) => codeSlots[Number(idx)] || '');
|
|
53
|
+
return s;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function renderMarkdown(raw) {
|
|
57
|
+
const normalized = String(raw ?? '').replace(/\r\n?/g, '\n');
|
|
58
|
+
if (!normalized.trim()) return '';
|
|
59
|
+
|
|
60
|
+
// 1. Extract fenced code blocks (including unclosed trailing fence during streaming)
|
|
61
|
+
const fences = [];
|
|
62
|
+
let text = normalized.replace(/```([a-zA-Z0-9_+-]*)[ \t]*\n([\s\S]*?)(?:```|$)/g, (_, lang, code) => {
|
|
63
|
+
const idx = fences.length;
|
|
64
|
+
const cleanCode = code.replace(/\n$/, '');
|
|
65
|
+
fences.push(
|
|
66
|
+
`<div class="clado-md-pre">`
|
|
67
|
+
+ `<div class="clado-md-pre-head"><span>${esc(lang || 'code')}</span>`
|
|
68
|
+
+ `<button type="button" class="clado-dock-mini-btn" data-copy-code style="padding:1px 6px;font-size:10.5px;">复制</button></div>`
|
|
69
|
+
+ `<pre class="clado-scroll"><code>${esc(cleanCode)}</code></pre></div>`
|
|
70
|
+
);
|
|
71
|
+
return `\n\u0000FENCE${idx}\u0000\n`;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const lines = text.split('\n');
|
|
75
|
+
const out = [];
|
|
76
|
+
let i = 0;
|
|
77
|
+
|
|
78
|
+
const isTableSep = line => /^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*:?-{3,}:?\s*\|?\s*$/.test(line);
|
|
79
|
+
const parseTableRow = line => line.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map(c => c.trim());
|
|
80
|
+
|
|
81
|
+
while (i < lines.length) {
|
|
82
|
+
const line = lines[i];
|
|
83
|
+
const trimmed = line.trim();
|
|
84
|
+
if (!trimmed) { i++; continue; }
|
|
85
|
+
|
|
86
|
+
// Fenced code placeholder
|
|
87
|
+
const fenceMatch = trimmed.match(/^\u0000FENCE(\d+)\u0000$/);
|
|
88
|
+
if (fenceMatch) {
|
|
89
|
+
out.push(fences[Number(fenceMatch[1])] || '');
|
|
90
|
+
i++;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Headings
|
|
95
|
+
const hMatch = line.match(/^\s{0,3}(#{1,4})\s+(.+?)\s*#*$/);
|
|
96
|
+
if (hMatch) {
|
|
97
|
+
const lvl = hMatch[1].length;
|
|
98
|
+
out.push(`<h${lvl}>${renderInline(hMatch[2])}</h${lvl}>`);
|
|
99
|
+
i++;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Horizontal rule
|
|
104
|
+
if (/^\s{0,3}([-*_])(?:\s*\1){2,}\s*$/.test(line)) {
|
|
105
|
+
out.push('<hr/>');
|
|
106
|
+
i++;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// GFM Table
|
|
111
|
+
if (line.includes('|') && i + 1 < lines.length && isTableSep(lines[i + 1])) {
|
|
112
|
+
const headerCells = parseTableRow(line);
|
|
113
|
+
i += 2;
|
|
114
|
+
const bodyRows = [];
|
|
115
|
+
while (i < lines.length && lines[i].trim() && lines[i].includes('|')) {
|
|
116
|
+
bodyRows.push(parseTableRow(lines[i]));
|
|
117
|
+
i++;
|
|
118
|
+
}
|
|
119
|
+
const thead = `<thead><tr>${headerCells.map(c => `<th>${renderInline(c)}</th>`).join('')}</tr></thead>`;
|
|
120
|
+
const tbody = bodyRows.length
|
|
121
|
+
? `<tbody>${bodyRows.map(r => `<tr>${headerCells.map((_, ci) => `<td>${renderInline(r[ci] || '')}</td>`).join('')}</tr>`).join('')}</tbody>`
|
|
122
|
+
: '';
|
|
123
|
+
out.push(`<div class="clado-scroll" style="overflow-x:auto;"><table>${thead}${tbody}</table></div>`);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Blockquote
|
|
128
|
+
if (/^\s*>\s?/.test(line)) {
|
|
129
|
+
const quoteLines = [];
|
|
130
|
+
while (i < lines.length && /^\s*>\s?/.test(lines[i])) {
|
|
131
|
+
quoteLines.push(lines[i].replace(/^\s*>\s?/, ''));
|
|
132
|
+
i++;
|
|
133
|
+
}
|
|
134
|
+
out.push(`<blockquote>${quoteLines.map(renderInline).join('<br/>')}</blockquote>`);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Unordered list
|
|
139
|
+
if (/^\s*[-*+]\s+/.test(line)) {
|
|
140
|
+
const items = [];
|
|
141
|
+
while (i < lines.length && /^\s*[-*+]\s+/.test(lines[i])) {
|
|
142
|
+
items.push(lines[i].replace(/^\s*[-*+]\s+/, ''));
|
|
143
|
+
i++;
|
|
144
|
+
}
|
|
145
|
+
out.push(`<ul>${items.map(it => `<li>${renderInline(it)}</li>`).join('')}</ul>`);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Ordered list
|
|
150
|
+
if (/^\s*\d+\.\s+/.test(line)) {
|
|
151
|
+
const items = [];
|
|
152
|
+
while (i < lines.length && /^\s*\d+\.\s+/.test(lines[i])) {
|
|
153
|
+
items.push(lines[i].replace(/^\s*\d+\.\s+/, ''));
|
|
154
|
+
i++;
|
|
155
|
+
}
|
|
156
|
+
out.push(`<ol>${items.map(it => `<li>${renderInline(it)}</li>`).join('')}</ol>`);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Paragraph
|
|
161
|
+
const pLines = [];
|
|
162
|
+
while (
|
|
163
|
+
i < lines.length
|
|
164
|
+
&& lines[i].trim()
|
|
165
|
+
&& !/^\u0000FENCE\d+\u0000$/.test(lines[i].trim())
|
|
166
|
+
&& !/^\s{0,3}#{1,4}\s+/.test(lines[i])
|
|
167
|
+
&& !/^\s{0,3}([-*_])(?:\s*\1){2,}\s*$/.test(lines[i])
|
|
168
|
+
&& !/^\s*>\s?/.test(lines[i])
|
|
169
|
+
&& !/^\s*[-*+]\s+/.test(lines[i])
|
|
170
|
+
&& !/^\s*\d+\.\s+/.test(lines[i])
|
|
171
|
+
&& !(lines[i].includes('|') && i + 1 < lines.length && isTableSep(lines[i + 1]))
|
|
172
|
+
) {
|
|
173
|
+
pLines.push(lines[i]);
|
|
174
|
+
i++;
|
|
175
|
+
}
|
|
176
|
+
if (pLines.length) {
|
|
177
|
+
out.push(`<p>${pLines.map(renderInline).join('<br/>')}</p>`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return out.join('');
|
|
182
|
+
}
|
|
183
|
+
|
|
24
184
|
window.CladoAgentPlugin = (host, actions = {}) => {
|
|
25
185
|
const withWs = actions.withWorkspace || (p => p);
|
|
26
186
|
const stageRoot = () => document.getElementById('clado-stage') || document.body;
|
|
27
187
|
|
|
28
188
|
let meta = null;
|
|
29
189
|
let sessions = [];
|
|
30
|
-
let activeSessionId = '';
|
|
190
|
+
let activeSessionId = localStorage.getItem('clado-active-session') || '';
|
|
31
191
|
let drawerOpen = false;
|
|
32
192
|
let runningSessionId = '';
|
|
33
193
|
let activeAbort = null;
|
|
194
|
+
let stoppingTurn = false;
|
|
195
|
+
let pendingCancelPromise = null;
|
|
34
196
|
let settingsTab = 'extensions';
|
|
35
197
|
let editingProviderId = '';
|
|
198
|
+
let sessionFilter = 'active'; // 'active' | 'archived'
|
|
199
|
+
let renamingSessionId = '';
|
|
200
|
+
let sendMode = localStorage.getItem('clado-send-mode') === 'enter' ? 'enter' : 'ctrl-enter';
|
|
201
|
+
const traceOpenState = new Map(); // msgKey -> boolean
|
|
36
202
|
|
|
37
203
|
// =========================================================================
|
|
38
|
-
// 1. Bottom-Right Role Dock
|
|
204
|
+
// 1. Bottom-Right Role Dock (Resizable + Session Manager + Multiline Composer)
|
|
39
205
|
// =========================================================================
|
|
40
206
|
const dock = document.createElement('div');
|
|
41
207
|
dock.className = 'clado-vnext-dock';
|
|
42
208
|
dock.innerHTML = `
|
|
43
209
|
<div class="clado-dock-drawer collapsed" data-drawer>
|
|
210
|
+
<div class="clado-resize-nw" data-resize="nw" title="拖动调整对话窗口宽高(双击恢复默认)"></div>
|
|
211
|
+
<div class="clado-resize-n" data-resize="n" title="拖动调整窗口高度"></div>
|
|
212
|
+
<div class="clado-resize-w" data-resize="w" title="拖动调整窗口宽度"></div>
|
|
44
213
|
<div class="clado-dock-aura"></div>
|
|
45
214
|
<div class="clado-dock-inner">
|
|
46
215
|
<div class="clado-dock-head">
|
|
47
216
|
<div class="clado-dock-head-left">
|
|
48
|
-
<
|
|
217
|
+
<button type="button" class="clado-dock-session-trigger" data-session-trigger title="切换、新建、重命名或归档会话">
|
|
218
|
+
<span data-role-title>主架构师</span>
|
|
219
|
+
${ICONS.chevDown}
|
|
220
|
+
</button>
|
|
49
221
|
<span class="clado-chip clado-chip-sky" data-role-phase>设计阶段</span>
|
|
50
222
|
</div>
|
|
51
223
|
<div class="clado-dock-actions">
|
|
224
|
+
<button type="button" class="clado-dock-mini-btn" data-new-session title="在当前角色下开启新会话">${ICONS.plus}<span>新会话</span></button>
|
|
52
225
|
<button type="button" class="clado-dock-mini-btn" data-rollback title="回退画布至上一轮快照">${ICONS.undo}<span>回退</span></button>
|
|
53
226
|
<button type="button" class="clado-dock-mini-btn" data-collapse>收起</button>
|
|
54
227
|
</div>
|
|
55
228
|
</div>
|
|
56
|
-
<div class="clado-
|
|
229
|
+
<div class="clado-session-pop" data-session-pop hidden></div>
|
|
230
|
+
<div class="clado-dock-stream clado-scroll" data-stream></div>
|
|
57
231
|
<div class="clado-dock-handoff">
|
|
58
232
|
<span style="color:var(--clado-ui-subtle);">流转至下一阶段</span>
|
|
59
233
|
<div style="display:flex;align-items:center;gap:6px;">
|
|
@@ -67,11 +241,18 @@
|
|
|
67
241
|
<div class="clado-role-strip" data-role-strip></div>
|
|
68
242
|
|
|
69
243
|
<div class="clado-composer">
|
|
70
|
-
<div class="clado-dock-popover" data-popover hidden></div>
|
|
71
|
-
<
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
244
|
+
<div class="clado-dock-popover clado-scroll" data-popover hidden></div>
|
|
245
|
+
<textarea class="clado-composer-input clado-scroll" data-input rows="1" placeholder="输入需求、敲 / 调命令(Enter 换行,Ctrl+Enter 发送)…"></textarea>
|
|
246
|
+
<div class="clado-composer-bar">
|
|
247
|
+
<div class="clado-composer-left">
|
|
248
|
+
<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
|
+
<button type="button" class="clado-model-chip" data-model-chip title="切换模型或配置供应商">配置模型 ▾</button>
|
|
250
|
+
</div>
|
|
251
|
+
<div class="clado-composer-right">
|
|
252
|
+
<button type="button" class="clado-sendmode-btn" data-sendmode title="点击切换发送快捷键">Ctrl↵ 发送</button>
|
|
253
|
+
<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
|
+
</div>
|
|
255
|
+
</div>
|
|
75
256
|
</div>
|
|
76
257
|
`;
|
|
77
258
|
host.mount('bottom-right', dock, 'clado.agent');
|
|
@@ -83,39 +264,144 @@
|
|
|
83
264
|
const stripEl = dock.querySelector('[data-role-strip]');
|
|
84
265
|
const inputEl = dock.querySelector('[data-input]');
|
|
85
266
|
const sendBtn = dock.querySelector('[data-send]');
|
|
267
|
+
const sendModeBtn = dock.querySelector('[data-sendmode]');
|
|
86
268
|
const modelChip = dock.querySelector('[data-model-chip]');
|
|
87
269
|
const popoverEl = dock.querySelector('[data-popover]');
|
|
270
|
+
const sessionPopEl = dock.querySelector('[data-session-pop]');
|
|
271
|
+
const sessionTriggerEl = dock.querySelector('[data-session-trigger]');
|
|
272
|
+
|
|
273
|
+
// Restore persisted dock dimensions
|
|
274
|
+
function applyDockSize(w, h) {
|
|
275
|
+
if (Number.isFinite(w) && w >= 350 && w <= 840) {
|
|
276
|
+
dock.style.setProperty('--clado-dock-w', Math.round(w) + 'px');
|
|
277
|
+
}
|
|
278
|
+
if (Number.isFinite(h) && h >= 160 && h <= 640) {
|
|
279
|
+
dock.style.setProperty('--clado-dock-stream-h', Math.round(h) + 'px');
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
const saved = JSON.parse(localStorage.getItem('clado-dock-size') || 'null');
|
|
284
|
+
if (saved) applyDockSize(saved.w, saved.h);
|
|
285
|
+
} catch {}
|
|
286
|
+
|
|
287
|
+
function getStageScale() {
|
|
288
|
+
const stage = stageRoot();
|
|
289
|
+
if (!stage || !stage.offsetWidth) return 1;
|
|
290
|
+
const rect = stage.getBoundingClientRect();
|
|
291
|
+
return rect.width > 0 ? (rect.width / stage.offsetWidth) : 1;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Bind NW / N / W Resize Handles
|
|
295
|
+
dock.querySelectorAll('[data-resize]').forEach(handle => {
|
|
296
|
+
const mode = handle.dataset.resize;
|
|
297
|
+
if (mode === 'nw') {
|
|
298
|
+
handle.addEventListener('dblclick', e => {
|
|
299
|
+
e.preventDefault();
|
|
300
|
+
e.stopPropagation();
|
|
301
|
+
dock.style.removeProperty('--clado-dock-w');
|
|
302
|
+
dock.style.removeProperty('--clado-dock-stream-h');
|
|
303
|
+
localStorage.removeItem('clado-dock-size');
|
|
304
|
+
showToast('已恢复默认对话窗口尺寸');
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
handle.addEventListener('pointerdown', e => {
|
|
308
|
+
if (e.button !== 0) return;
|
|
309
|
+
e.preventDefault();
|
|
310
|
+
e.stopPropagation();
|
|
311
|
+
const scale = getStageScale();
|
|
312
|
+
const stage = stageRoot();
|
|
313
|
+
const maxW = Math.min(840, Math.max(420, (stage.offsetWidth || window.innerWidth) - 48));
|
|
314
|
+
const maxH = Math.min(640, Math.max(260, (stage.offsetHeight || window.innerHeight) - 240));
|
|
315
|
+
const startX = e.clientX;
|
|
316
|
+
const startY = e.clientY;
|
|
317
|
+
const startW = dock.offsetWidth || 412;
|
|
318
|
+
const startH = streamEl.offsetHeight || 300;
|
|
319
|
+
let lastW = startW;
|
|
320
|
+
let lastH = startH;
|
|
321
|
+
drawerEl.classList.add('resizing');
|
|
322
|
+
handle.setPointerCapture?.(e.pointerId);
|
|
323
|
+
|
|
324
|
+
const onMove = ev => {
|
|
325
|
+
const dx = (ev.clientX - startX) / scale;
|
|
326
|
+
const dy = (ev.clientY - startY) / scale;
|
|
327
|
+
if (mode === 'w' || mode === 'nw') {
|
|
328
|
+
lastW = Math.max(350, Math.min(maxW, startW - dx));
|
|
329
|
+
dock.style.setProperty('--clado-dock-w', Math.round(lastW) + 'px');
|
|
330
|
+
}
|
|
331
|
+
if (mode === 'n' || mode === 'nw') {
|
|
332
|
+
lastH = Math.max(160, Math.min(maxH, startH - dy));
|
|
333
|
+
dock.style.setProperty('--clado-dock-stream-h', Math.round(lastH) + 'px');
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
const onUp = () => {
|
|
337
|
+
drawerEl.classList.remove('resizing');
|
|
338
|
+
window.removeEventListener('pointermove', onMove);
|
|
339
|
+
window.removeEventListener('pointerup', onUp);
|
|
340
|
+
window.removeEventListener('pointercancel', onUp);
|
|
341
|
+
try {
|
|
342
|
+
localStorage.setItem('clado-dock-size', JSON.stringify({ w: Math.round(lastW), h: Math.round(lastH) }));
|
|
343
|
+
} catch {}
|
|
344
|
+
};
|
|
345
|
+
window.addEventListener('pointermove', onMove);
|
|
346
|
+
window.addEventListener('pointerup', onUp);
|
|
347
|
+
window.addEventListener('pointercancel', onUp);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
88
350
|
|
|
89
351
|
function showToast(msg) {
|
|
90
352
|
window.dispatchEvent(new CustomEvent('clado:toast', { detail: { message: msg } }));
|
|
91
353
|
}
|
|
92
354
|
|
|
355
|
+
function autoGrowInput() {
|
|
356
|
+
inputEl.style.height = 'auto';
|
|
357
|
+
const next = Math.min(132, Math.max(22, inputEl.scrollHeight));
|
|
358
|
+
inputEl.style.height = next + 'px';
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function syncSendModeUi() {
|
|
362
|
+
if (sendMode === 'ctrl-enter') {
|
|
363
|
+
sendModeBtn.textContent = 'Ctrl↵ 发送';
|
|
364
|
+
sendModeBtn.title = '当前:Enter 换行,Ctrl/⌘+Enter 发送(点击切换为 Enter 发送)';
|
|
365
|
+
inputEl.placeholder = '输入需求、敲 / 调命令(Enter 换行,Ctrl+Enter 发送)…';
|
|
366
|
+
} else {
|
|
367
|
+
sendModeBtn.textContent = '↵ 发送';
|
|
368
|
+
sendModeBtn.title = '当前:Enter 发送,Shift+Enter 换行(点击切换为 Ctrl+Enter 发送)';
|
|
369
|
+
inputEl.placeholder = '输入需求、敲 / 调命令(Enter 发送,Shift+Enter 换行)…';
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
syncSendModeUi();
|
|
373
|
+
|
|
93
374
|
function setDrawerOpen(open) {
|
|
94
375
|
drawerOpen = Boolean(open);
|
|
95
376
|
drawerEl.classList.toggle('collapsed', !drawerOpen);
|
|
96
377
|
document.body.dataset.agentDock = drawerOpen ? 'open' : 'closed';
|
|
378
|
+
if (!drawerOpen) closeSessionPop();
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function selectSession(id, openDrawer = true) {
|
|
382
|
+
activeSessionId = id;
|
|
383
|
+
try { localStorage.setItem('clado-active-session', id); } catch {}
|
|
384
|
+
if (openDrawer) setDrawerOpen(true);
|
|
385
|
+
renderRoleStrip();
|
|
386
|
+
renderStream();
|
|
387
|
+
if (!sessionPopEl.hidden) renderSessionPop();
|
|
97
388
|
}
|
|
98
389
|
|
|
99
390
|
function currentSession() {
|
|
100
|
-
return sessions.find(s => s.id === activeSessionId) || sessions[0] || null;
|
|
391
|
+
return sessions.find(s => s.id === activeSessionId) || sessions.find(s => !s.archived) || sessions[0] || null;
|
|
101
392
|
}
|
|
102
393
|
|
|
103
394
|
function renderRoleStrip() {
|
|
104
395
|
stripEl.replaceChildren();
|
|
105
|
-
|
|
106
|
-
|
|
396
|
+
const visible = sessions.filter(s => !s.archived);
|
|
397
|
+
for (const s of visible) {
|
|
107
398
|
const btn = document.createElement('button');
|
|
108
399
|
btn.type = 'button';
|
|
109
400
|
btn.className = 'clado-role-pill' + (s.id === activeSessionId ? ' active' : '');
|
|
110
401
|
btn.dataset.tone = s.tone || 'sky';
|
|
111
402
|
const badge = s.status === 'running' ? ' · 运行中' : (s.summaryBadge ? ' · ' + s.summaryBadge : '');
|
|
112
403
|
btn.textContent = s.title + badge;
|
|
113
|
-
btn.onclick = () =>
|
|
114
|
-
activeSessionId = s.id;
|
|
115
|
-
setDrawerOpen(true);
|
|
116
|
-
renderRoleStrip();
|
|
117
|
-
renderStream();
|
|
118
|
-
};
|
|
404
|
+
btn.onclick = () => selectSession(s.id, true);
|
|
119
405
|
stripEl.append(btn);
|
|
120
406
|
}
|
|
121
407
|
const addBtn = document.createElement('button');
|
|
@@ -123,10 +409,99 @@
|
|
|
123
409
|
addBtn.className = 'clado-role-pill clado-role-add';
|
|
124
410
|
addBtn.title = '新建角色会话';
|
|
125
411
|
addBtn.innerHTML = ICONS.plus;
|
|
126
|
-
addBtn.onclick =
|
|
412
|
+
addBtn.onclick = e => {
|
|
413
|
+
e.stopPropagation();
|
|
414
|
+
closeSessionPop();
|
|
415
|
+
popoverEl.dataset.kind = 'new-role';
|
|
416
|
+
openNewRoleSessionPopover();
|
|
417
|
+
};
|
|
127
418
|
stripEl.append(addBtn);
|
|
128
419
|
}
|
|
129
420
|
|
|
421
|
+
function buildToolTrace(msgKey, tools, isRunningMsg) {
|
|
422
|
+
const details = document.createElement('details');
|
|
423
|
+
details.className = 'clado-tool-trace';
|
|
424
|
+
const anyRunning = tools.some(t => t.status === 'running');
|
|
425
|
+
const anyFailed = tools.some(t => t.status === 'failed');
|
|
426
|
+
const doneCount = tools.filter(t => t.status === 'completed' || t.status === 'failed').length;
|
|
427
|
+
const shouldOpen = traceOpenState.has(msgKey) ? traceOpenState.get(msgKey) : (anyRunning || isRunningMsg);
|
|
428
|
+
if (shouldOpen) details.open = true;
|
|
429
|
+
details.addEventListener('toggle', () => {
|
|
430
|
+
traceOpenState.set(msgKey, details.open);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
const dotCls = anyRunning ? 'clado-dot-pulse' : (anyFailed ? 'clado-dot-err' : 'clado-dot-ok');
|
|
434
|
+
const currentTool = [...tools].reverse().find(t => t.status === 'running') || tools[tools.length - 1];
|
|
435
|
+
const namesPreview = [...new Set(tools.map(t => t.name).filter(Boolean))].slice(0, 3).join(' · ');
|
|
436
|
+
const label = anyRunning
|
|
437
|
+
? `正在执行 ${currentTool?.name || '工具'}${currentTool?.argsSummary ? ' · ' + currentTool.argsSummary : ''} (${doneCount}/${tools.length})`
|
|
438
|
+
: `工具调用 (${tools.length}) · ${namesPreview}`;
|
|
439
|
+
|
|
440
|
+
const summary = document.createElement('summary');
|
|
441
|
+
summary.innerHTML = `
|
|
442
|
+
<span style="display:inline-flex;align-items:center;gap:7px;min-width:0;overflow:hidden;">
|
|
443
|
+
<span class="${dotCls}"></span>
|
|
444
|
+
<span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">${esc(label)}</span>
|
|
445
|
+
</span>
|
|
446
|
+
<span style="font-size:10.5px;color:var(--clado-ui-subtle);flex:none;">${details.open ? '收起' : '详情'}</span>
|
|
447
|
+
`;
|
|
448
|
+
details.addEventListener('toggle', () => {
|
|
449
|
+
const rightSpan = summary.lastElementChild;
|
|
450
|
+
if (rightSpan) rightSpan.textContent = details.open ? '收起' : '详情';
|
|
451
|
+
});
|
|
452
|
+
details.append(summary);
|
|
453
|
+
|
|
454
|
+
const list = document.createElement('div');
|
|
455
|
+
list.className = 'clado-tool-list';
|
|
456
|
+
for (const t of tools) {
|
|
457
|
+
const step = document.createElement('div');
|
|
458
|
+
step.className = 'clado-tool-step';
|
|
459
|
+
const stepDot = t.status === 'running' ? 'clado-dot-pulse' : (t.status === 'failed' ? 'clado-dot-err' : 'clado-dot-ok');
|
|
460
|
+
const statusTxt = t.status === 'running' ? '执行中' : (t.status === 'failed' ? '失败' : '完成');
|
|
461
|
+
step.innerHTML = `
|
|
462
|
+
<div class="clado-tool-step-head">
|
|
463
|
+
<span class="${stepDot}"></span>
|
|
464
|
+
<span class="clado-tool-name">${esc(t.name || 'tool')}</span>
|
|
465
|
+
<span class="clado-tool-args" title="${esc(t.argsSummary || '')}">${esc(t.argsSummary || '')}</span>
|
|
466
|
+
<span style="font-size:10px;color:var(--clado-ui-subtle);flex:none;">${statusTxt}</span>
|
|
467
|
+
</div>
|
|
468
|
+
${t.resultPreview ? `<div class="clado-tool-preview clado-scroll">${esc(t.resultPreview)}</div>` : ''}
|
|
469
|
+
`;
|
|
470
|
+
list.append(step);
|
|
471
|
+
}
|
|
472
|
+
details.append(list);
|
|
473
|
+
return details;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function buildDecisionCard(sessionId, q) {
|
|
477
|
+
const box = document.createElement('div');
|
|
478
|
+
box.className = 'clado-decision-card';
|
|
479
|
+
box.innerHTML = `<div class="clado-decision-q">${esc(q.question)}</div><div class="clado-decision-opts"></div>`;
|
|
480
|
+
const optsWrap = box.querySelector('.clado-decision-opts');
|
|
481
|
+
const opts = Array.isArray(q.options) && q.options.length ? q.options : [{ id: 'confirm', label: '确认继续' }];
|
|
482
|
+
for (let i = 0; i < opts.length; i++) {
|
|
483
|
+
const opt = opts[i];
|
|
484
|
+
const btn = document.createElement('button');
|
|
485
|
+
btn.type = 'button';
|
|
486
|
+
btn.className = 'clado-ui-button ' + (i === 0 ? 'clado-ui-button-primary' : '');
|
|
487
|
+
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
|
+
btn.textContent = opt.label;
|
|
489
|
+
btn.onclick = async () => {
|
|
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
|
+
};
|
|
500
|
+
optsWrap.append(btn);
|
|
501
|
+
}
|
|
502
|
+
return box;
|
|
503
|
+
}
|
|
504
|
+
|
|
130
505
|
function renderStream() {
|
|
131
506
|
const s = currentSession();
|
|
132
507
|
if (!s) return;
|
|
@@ -137,17 +512,23 @@
|
|
|
137
512
|
const modelLabel = s.model || meta?.activeModelLabel || '配置模型';
|
|
138
513
|
modelChip.textContent = (modelLabel.includes('/') ? modelLabel.split('/').pop() : modelLabel) + ' ▾';
|
|
139
514
|
|
|
515
|
+
const wasNearBottom = (streamEl.scrollHeight - streamEl.scrollTop - streamEl.clientHeight) < 60;
|
|
516
|
+
|
|
140
517
|
const msgs = Array.isArray(s.messages) ? s.messages : [];
|
|
141
518
|
streamEl.replaceChildren();
|
|
142
519
|
if (!msgs.length) {
|
|
143
520
|
const empty = document.createElement('div');
|
|
144
521
|
empty.className = 'clado-dock-empty';
|
|
145
|
-
empty.innerHTML =
|
|
522
|
+
empty.innerHTML = `当前会话:<strong>${esc(s.title)}</strong>(Pi 1.0 引擎)<br/>可直接描述架构修改、输入 <code>/</code> 调命令,或在画布选中卡片派活交付。<br/>支持拖拽左上角或边缘缩放窗口,点击标题切换或新建会话。`;
|
|
146
523
|
streamEl.append(empty);
|
|
147
524
|
return;
|
|
148
525
|
}
|
|
149
526
|
|
|
150
|
-
|
|
527
|
+
const pendingDecisionCards = [];
|
|
528
|
+
|
|
529
|
+
for (let idx = 0; idx < msgs.length; idx++) {
|
|
530
|
+
const m = msgs[idx];
|
|
531
|
+
const isLast = idx === msgs.length - 1;
|
|
151
532
|
if (m.role === 'user') {
|
|
152
533
|
const div = document.createElement('div');
|
|
153
534
|
div.className = 'clado-msg-user';
|
|
@@ -155,54 +536,234 @@
|
|
|
155
536
|
div.textContent = prefix + (m.text || '');
|
|
156
537
|
streamEl.append(div);
|
|
157
538
|
} else {
|
|
539
|
+
const msgKey = m.id || `${s.id}_${idx}`;
|
|
540
|
+
const isRunningMsg = isLast && s.status === 'running';
|
|
541
|
+
|
|
542
|
+
// 1. Expandable Tool Execution Trace
|
|
158
543
|
if (Array.isArray(m.tools) && m.tools.length) {
|
|
159
|
-
|
|
160
|
-
toolLine.className = 'clado-tool-chip';
|
|
161
|
-
const names = [...new Set(m.tools.map(t => t.name || t.title).filter(Boolean))];
|
|
162
|
-
const anyRunning = m.tools.some(t => t.status === 'running');
|
|
163
|
-
toolLine.innerHTML = `<span class="${anyRunning ? 'clado-dot-sky' : 'clado-dot-ok'}"></span><span>Pi · ${esc(names.join(' · '))}</span>`;
|
|
164
|
-
streamEl.append(toolLine);
|
|
165
|
-
}
|
|
166
|
-
if (m.question && !m.question.answered) {
|
|
167
|
-
streamEl.append(buildDecisionCard(s.id, m.question));
|
|
544
|
+
streamEl.append(buildToolTrace(msgKey, m.tools, isRunningMsg));
|
|
168
545
|
}
|
|
546
|
+
|
|
547
|
+
// 2. Rendered Markdown Assistant Reply
|
|
169
548
|
if (m.text) {
|
|
170
549
|
const div = document.createElement('div');
|
|
171
|
-
div.className = 'clado-msg-assistant';
|
|
172
|
-
div.
|
|
550
|
+
div.className = 'clado-msg-assistant clado-md';
|
|
551
|
+
div.innerHTML = renderMarkdown(m.text);
|
|
173
552
|
streamEl.append(div);
|
|
174
553
|
}
|
|
554
|
+
|
|
555
|
+
// 3. Collect questions: answered ones show as compact receipt pill, unanswered ones pin at the very bottom
|
|
556
|
+
const qList = [];
|
|
557
|
+
if (Array.isArray(m.questions)) qList.push(...m.questions);
|
|
558
|
+
if (m.question && !qList.some(q => q.questionId === m.question.questionId)) qList.push(m.question);
|
|
559
|
+
|
|
560
|
+
for (const q of qList) {
|
|
561
|
+
if (q.answered) {
|
|
562
|
+
const donePill = document.createElement('div');
|
|
563
|
+
donePill.className = 'clado-decision-done';
|
|
564
|
+
donePill.textContent = '已确认:' + (q.answer || q.question);
|
|
565
|
+
streamEl.append(donePill);
|
|
566
|
+
} else {
|
|
567
|
+
pendingDecisionCards.push(q);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// 4. Live activity status pill while running
|
|
572
|
+
if (isRunningMsg) {
|
|
573
|
+
const act = document.createElement('div');
|
|
574
|
+
act.className = 'clado-live-activity';
|
|
575
|
+
act.innerHTML = `<span class="clado-dot-pulse"></span><span>${esc(m.activity || 'Pi 正在思考与执行…')}</span>`;
|
|
576
|
+
streamEl.append(act);
|
|
577
|
+
}
|
|
175
578
|
}
|
|
176
579
|
}
|
|
177
|
-
|
|
580
|
+
|
|
581
|
+
// 5. Pending ask_user decision cards ALWAYS render at the very bottom
|
|
582
|
+
for (const q of pendingDecisionCards) {
|
|
583
|
+
streamEl.append(buildDecisionCard(s.id, q));
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
if (wasNearBottom || s.status === 'running' || pendingDecisionCards.length) {
|
|
587
|
+
streamEl.scrollTop = streamEl.scrollHeight;
|
|
588
|
+
}
|
|
178
589
|
}
|
|
179
590
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
591
|
+
// Copy code button delegation inside stream
|
|
592
|
+
streamEl.addEventListener('click', e => {
|
|
593
|
+
const btn = e.target.closest?.('[data-copy-code]');
|
|
594
|
+
if (!btn) return;
|
|
595
|
+
const code = btn.closest('.clado-md-pre')?.querySelector('pre code')?.textContent || '';
|
|
596
|
+
navigator.clipboard?.writeText(code).catch(() => {});
|
|
597
|
+
const prev = btn.textContent;
|
|
598
|
+
btn.textContent = '已复制';
|
|
599
|
+
setTimeout(() => { btn.textContent = prev; }, 1200);
|
|
600
|
+
showToast('已复制代码块');
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
// =========================================================================
|
|
604
|
+
// Session Manager Popover (Switch / Create / Inline Rename / Archive / Delete)
|
|
605
|
+
// =========================================================================
|
|
606
|
+
function closeSessionPop() {
|
|
607
|
+
sessionPopEl.hidden = true;
|
|
608
|
+
renamingSessionId = '';
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
async function createNewSessionForCurrentRole(roleOverride = null) {
|
|
612
|
+
const cur = currentSession();
|
|
613
|
+
const targetRoleId = roleOverride?.id || cur?.roleId || 'architect';
|
|
614
|
+
const roleObj = roleOverride || (meta?.roles || []).find(r => r.id === targetRoleId) || { id: targetRoleId, name: cur?.title || '主架构师' };
|
|
615
|
+
const sameRoleCount = sessions.filter(s => s.roleId === targetRoleId).length;
|
|
616
|
+
const defaultTitle = `${roleObj.name} · 会话 ${sameRoleCount + 1}`;
|
|
617
|
+
const res = await fetch(withWs('/library/agent/sessions'), {
|
|
618
|
+
method: 'POST',
|
|
619
|
+
headers: { 'content-type': 'application/json' },
|
|
620
|
+
body: JSON.stringify({ roleId: roleObj.id, title: defaultTitle }),
|
|
621
|
+
});
|
|
622
|
+
const data = await res.json();
|
|
623
|
+
if (data?.session) {
|
|
624
|
+
sessions.push(data.session);
|
|
625
|
+
closeSessionPop();
|
|
626
|
+
selectSession(data.session.id, true);
|
|
627
|
+
showToast('已新建会话:' + data.session.title);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function renderSessionPop() {
|
|
632
|
+
const activeCount = sessions.filter(s => !s.archived).length;
|
|
633
|
+
const archivedCount = sessions.filter(s => s.archived).length;
|
|
634
|
+
const list = sessions
|
|
635
|
+
.filter(s => (sessionFilter === 'archived' ? s.archived : !s.archived))
|
|
636
|
+
.slice()
|
|
637
|
+
.sort((a, b) => String(b.updatedAt || '').localeCompare(String(a.updatedAt || '')));
|
|
638
|
+
|
|
639
|
+
sessionPopEl.innerHTML = `
|
|
640
|
+
<div style="display:flex;align-items:center;justify-content:space-between;gap:6px;">
|
|
641
|
+
<div style="display:inline-flex;gap:4px;">
|
|
642
|
+
<button type="button" class="clado-dock-mini-btn" data-sf="active" style="${sessionFilter === 'active' ? 'background:var(--clado-ui-prism-bg);border-color:var(--clado-ui-prism-border);color:var(--clado-ui-prism-text);' : ''}">进行中 (${activeCount})</button>
|
|
643
|
+
<button type="button" class="clado-dock-mini-btn" data-sf="archived" style="${sessionFilter === 'archived' ? 'background:var(--clado-ui-prism-bg);border-color:var(--clado-ui-prism-border);color:var(--clado-ui-prism-text);' : ''}">已归档 (${archivedCount})</button>
|
|
644
|
+
</div>
|
|
645
|
+
<button type="button" class="clado-ui-button clado-ui-button-primary" data-sp-new style="min-height:24px;padding:2px 9px;font-size:11px;">+ 新建会话</button>
|
|
646
|
+
</div>
|
|
647
|
+
<div class="clado-session-list clado-scroll" data-sp-list></div>
|
|
648
|
+
`;
|
|
649
|
+
|
|
650
|
+
sessionPopEl.querySelectorAll('[data-sf]').forEach(btn => {
|
|
651
|
+
btn.onclick = e => {
|
|
652
|
+
e.stopPropagation();
|
|
653
|
+
sessionFilter = btn.dataset.sf;
|
|
654
|
+
renderSessionPop();
|
|
202
655
|
};
|
|
203
|
-
|
|
656
|
+
});
|
|
657
|
+
sessionPopEl.querySelector('[data-sp-new]').onclick = e => {
|
|
658
|
+
e.stopPropagation();
|
|
659
|
+
createNewSessionForCurrentRole();
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
const listEl = sessionPopEl.querySelector('[data-sp-list]');
|
|
663
|
+
if (!list.length) {
|
|
664
|
+
listEl.innerHTML = `<div style="padding:14px 8px;text-align:center;font-size:11.5px;color:var(--clado-ui-subtle);">${sessionFilter === 'archived' ? '暂无已归档会话' : '暂无进行中会话'}</div>`;
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
for (const item of list) {
|
|
669
|
+
const row = document.createElement('div');
|
|
670
|
+
row.className = 'clado-session-row' + (item.id === activeSessionId ? ' active' : '');
|
|
671
|
+
const msgCount = Array.isArray(item.messages) ? item.messages.length : 0;
|
|
672
|
+
|
|
673
|
+
if (renamingSessionId === item.id) {
|
|
674
|
+
row.innerHTML = `
|
|
675
|
+
<input type="text" class="clado-field" data-rename-in value="${esc(item.title)}" style="padding:4px 8px;font-size:12px;border-radius:8px;flex:1;" />
|
|
676
|
+
<button type="button" class="clado-dock-mini-btn" data-rename-ok style="color:var(--clado-ui-brand);">保存</button>
|
|
677
|
+
<button type="button" class="clado-dock-mini-btn" data-rename-cancel>取消</button>
|
|
678
|
+
`;
|
|
679
|
+
const inp = row.querySelector('[data-rename-in]');
|
|
680
|
+
const commitRename = async () => {
|
|
681
|
+
const nextTitle = inp.value.trim();
|
|
682
|
+
if (!nextTitle) { renamingSessionId = ''; renderSessionPop(); return; }
|
|
683
|
+
const res = await fetch(withWs('/library/agent/sessions'), {
|
|
684
|
+
method: 'POST',
|
|
685
|
+
headers: { 'content-type': 'application/json' },
|
|
686
|
+
body: JSON.stringify({ action: 'rename', id: item.id, title: nextTitle }),
|
|
687
|
+
});
|
|
688
|
+
if (res.ok) {
|
|
689
|
+
item.title = nextTitle;
|
|
690
|
+
showToast('已重命名为「' + nextTitle + '」');
|
|
691
|
+
}
|
|
692
|
+
renamingSessionId = '';
|
|
693
|
+
renderRoleStrip();
|
|
694
|
+
renderStream();
|
|
695
|
+
renderSessionPop();
|
|
696
|
+
};
|
|
697
|
+
row.onclick = e => e.stopPropagation();
|
|
698
|
+
row.querySelector('[data-rename-ok]').onclick = e => { e.stopPropagation(); commitRename(); };
|
|
699
|
+
row.querySelector('[data-rename-cancel]').onclick = e => { e.stopPropagation(); renamingSessionId = ''; renderSessionPop(); };
|
|
700
|
+
inp.addEventListener('keydown', e => {
|
|
701
|
+
if (e.key === 'Enter' && !e.isComposing) { e.preventDefault(); commitRename(); }
|
|
702
|
+
if (e.key === 'Escape') { e.preventDefault(); renamingSessionId = ''; renderSessionPop(); }
|
|
703
|
+
});
|
|
704
|
+
setTimeout(() => { inp.focus(); inp.select(); }, 0);
|
|
705
|
+
} else {
|
|
706
|
+
row.innerHTML = `
|
|
707
|
+
<div style="min-width:0;flex:1;">
|
|
708
|
+
<div style="font-size:12px;font-weight:580;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">${esc(item.title)}</div>
|
|
709
|
+
<div style="display:flex;align-items:center;gap:6px;margin-top:2px;font-size:10.5px;color:var(--clado-ui-subtle);">
|
|
710
|
+
<span class="clado-chip ${TONE_CHIP[item.tone] || 'clado-chip-sky'}" style="padding:1px 6px;font-size:10px;">${esc(item.phase || '对话')}</span>
|
|
711
|
+
<span>${msgCount} 条消息</span>
|
|
712
|
+
</div>
|
|
713
|
+
</div>
|
|
714
|
+
<div class="clado-session-ops">
|
|
715
|
+
<button type="button" class="clado-dock-mini-btn" data-op="rename" title="重命名" style="padding:3px 5px;">${ICONS.edit}</button>
|
|
716
|
+
<button type="button" class="clado-dock-mini-btn" data-op="archive" title="${item.archived ? '恢复到进行中' : '归档会话'}" style="padding:3px 5px;">${ICONS.archive}</button>
|
|
717
|
+
<button type="button" class="clado-dock-mini-btn" data-op="delete" title="删除会话" style="padding:3px 5px;color:#be123c;">${ICONS.trash}</button>
|
|
718
|
+
</div>
|
|
719
|
+
`;
|
|
720
|
+
row.onclick = e => {
|
|
721
|
+
e.stopPropagation();
|
|
722
|
+
if (item.archived) {
|
|
723
|
+
// Unarchive if user clicks an archived session directly, or let them view it
|
|
724
|
+
selectSession(item.id, true);
|
|
725
|
+
} else {
|
|
726
|
+
selectSession(item.id, true);
|
|
727
|
+
}
|
|
728
|
+
closeSessionPop();
|
|
729
|
+
};
|
|
730
|
+
row.querySelector('[data-op="rename"]').onclick = e => {
|
|
731
|
+
e.stopPropagation();
|
|
732
|
+
renamingSessionId = item.id;
|
|
733
|
+
renderSessionPop();
|
|
734
|
+
};
|
|
735
|
+
row.querySelector('[data-op="archive"]').onclick = async e => {
|
|
736
|
+
e.stopPropagation();
|
|
737
|
+
const nextArch = !item.archived;
|
|
738
|
+
await fetch(withWs('/library/agent/sessions'), {
|
|
739
|
+
method: 'POST',
|
|
740
|
+
headers: { 'content-type': 'application/json' },
|
|
741
|
+
body: JSON.stringify({ action: 'archive', id: item.id, archived: nextArch }),
|
|
742
|
+
});
|
|
743
|
+
item.archived = nextArch;
|
|
744
|
+
if (nextArch && activeSessionId === item.id) {
|
|
745
|
+
const fallback = sessions.find(x => !x.archived);
|
|
746
|
+
if (fallback) activeSessionId = fallback.id;
|
|
747
|
+
}
|
|
748
|
+
showToast(nextArch ? '已归档会话' : '已恢复会话');
|
|
749
|
+
renderRoleStrip();
|
|
750
|
+
renderStream();
|
|
751
|
+
renderSessionPop();
|
|
752
|
+
};
|
|
753
|
+
row.querySelector('[data-op="delete"]').onclick = async e => {
|
|
754
|
+
e.stopPropagation();
|
|
755
|
+
await fetch(withWs('/library/agent/sessions?id=' + encodeURIComponent(item.id)), { method: 'DELETE' });
|
|
756
|
+
sessions = sessions.filter(x => x.id !== item.id);
|
|
757
|
+
if (activeSessionId === item.id) {
|
|
758
|
+
activeSessionId = sessions.find(x => !x.archived)?.id || sessions[0]?.id || '';
|
|
759
|
+
}
|
|
760
|
+
showToast('已删除会话');
|
|
761
|
+
await refreshMeta();
|
|
762
|
+
renderSessionPop();
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
listEl.append(row);
|
|
204
766
|
}
|
|
205
|
-
return box;
|
|
206
767
|
}
|
|
207
768
|
|
|
208
769
|
function closePopover() {
|
|
@@ -255,22 +816,10 @@
|
|
|
255
816
|
const item = document.createElement('button');
|
|
256
817
|
item.type = 'button';
|
|
257
818
|
item.className = 'clado-pop-item';
|
|
258
|
-
item.innerHTML = `<span><strong>${esc(r.name)}</strong> · ${esc(r.phase)}</span><span class="clado-chip ${TONE_CHIP[r.tone] || 'clado-chip-sky'}"
|
|
819
|
+
item.innerHTML = `<span><strong>${esc(r.name)}</strong> · ${esc(r.phase)}</span><span class="clado-chip ${TONE_CHIP[r.tone] || 'clado-chip-sky'}">新建会话</span>`;
|
|
259
820
|
item.onclick = async () => {
|
|
260
821
|
closePopover();
|
|
261
|
-
|
|
262
|
-
method: 'POST',
|
|
263
|
-
headers: { 'content-type': 'application/json' },
|
|
264
|
-
body: JSON.stringify({ roleId: r.id, title: r.name }),
|
|
265
|
-
});
|
|
266
|
-
const data = await res.json();
|
|
267
|
-
if (data?.session) {
|
|
268
|
-
sessions.push(data.session);
|
|
269
|
-
activeSessionId = data.session.id;
|
|
270
|
-
setDrawerOpen(true);
|
|
271
|
-
renderRoleStrip();
|
|
272
|
-
renderStream();
|
|
273
|
-
}
|
|
822
|
+
await createNewSessionForCurrentRole(r);
|
|
274
823
|
};
|
|
275
824
|
popoverEl.append(item);
|
|
276
825
|
}
|
|
@@ -286,13 +835,16 @@
|
|
|
286
835
|
|
|
287
836
|
function updateSlashPopover() {
|
|
288
837
|
const val = inputEl.value;
|
|
289
|
-
if (!val.startsWith('/')) {
|
|
838
|
+
if (!val.startsWith('/') || val.includes('\n')) {
|
|
290
839
|
if (!popoverEl.hidden && popoverEl.dataset.kind === 'slash') closePopover();
|
|
291
840
|
return;
|
|
292
841
|
}
|
|
293
842
|
const q = val.slice(1).toLowerCase();
|
|
294
843
|
const prompts = (meta?.ecosystem?.prompts || []).filter(p => !q || p.name.toLowerCase().includes(q));
|
|
295
|
-
if (!prompts.length) {
|
|
844
|
+
if (!prompts.length) {
|
|
845
|
+
if (popoverEl.dataset.kind === 'slash') closePopover();
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
296
848
|
popoverEl.dataset.kind = 'slash';
|
|
297
849
|
popoverEl.replaceChildren();
|
|
298
850
|
for (const p of prompts.slice(0, 8)) {
|
|
@@ -302,6 +854,7 @@
|
|
|
302
854
|
btn.innerHTML = `<span style="font-family:ui-monospace,monospace;">/${esc(p.name)}</span><span style="color:var(--clado-ui-subtle);font-size:11px;">${esc(p.description || p.scope)}</span>`;
|
|
303
855
|
btn.onclick = () => {
|
|
304
856
|
inputEl.value = '/' + p.name + ' ';
|
|
857
|
+
autoGrowInput();
|
|
305
858
|
closePopover();
|
|
306
859
|
inputEl.focus();
|
|
307
860
|
};
|
|
@@ -311,23 +864,36 @@
|
|
|
311
864
|
}
|
|
312
865
|
|
|
313
866
|
// =========================================================================
|
|
314
|
-
// 2. Streaming Pi Turn &
|
|
867
|
+
// 2. Streaming Pi Turn, Live Tool Calls & Safe Cancel (Preserving History!)
|
|
315
868
|
// =========================================================================
|
|
316
869
|
async function streamAgentRequest(payload, targetSession) {
|
|
317
870
|
setDrawerOpen(true);
|
|
318
871
|
const s = targetSession || currentSession();
|
|
319
872
|
if (!s) return;
|
|
320
873
|
activeSessionId = s.id;
|
|
874
|
+
try { localStorage.setItem('clado-active-session', s.id); } catch {}
|
|
321
875
|
runningSessionId = s.id;
|
|
876
|
+
stoppingTurn = false;
|
|
877
|
+
pendingCancelPromise = null;
|
|
322
878
|
s.status = 'running';
|
|
323
879
|
s.messages = Array.isArray(s.messages) ? s.messages : [];
|
|
324
|
-
|
|
880
|
+
const userPromptMsg = {
|
|
881
|
+
id: 'local_u_' + Date.now(),
|
|
325
882
|
role: 'user',
|
|
326
883
|
text: payload.text || (payload.action === 'handoff' ? '按画布定稿契约开始执行' : ''),
|
|
327
884
|
handoffFrom: payload.fromRoleName || '',
|
|
328
|
-
}
|
|
329
|
-
const liveAssistant = {
|
|
330
|
-
|
|
885
|
+
};
|
|
886
|
+
const liveAssistant = {
|
|
887
|
+
id: 'local_a_' + Date.now(),
|
|
888
|
+
role: 'assistant',
|
|
889
|
+
text: '',
|
|
890
|
+
tools: [],
|
|
891
|
+
questions: [],
|
|
892
|
+
activity: '正在思考并准备上下文…',
|
|
893
|
+
};
|
|
894
|
+
s.messages.push(userPromptMsg, liveAssistant);
|
|
895
|
+
const localSnapshotMsgs = s.messages.slice();
|
|
896
|
+
|
|
331
897
|
sendBtn.textContent = '停止';
|
|
332
898
|
renderRoleStrip();
|
|
333
899
|
renderStream();
|
|
@@ -359,54 +925,138 @@
|
|
|
359
925
|
if (!line.trim()) continue;
|
|
360
926
|
let ev;
|
|
361
927
|
try { ev = JSON.parse(line); } catch { continue; }
|
|
362
|
-
if (ev.type === '
|
|
928
|
+
if (ev.type === 'thinking') {
|
|
929
|
+
liveAssistant.activity = '正在深度思考…';
|
|
930
|
+
renderStream();
|
|
931
|
+
} else if (ev.type === 'text') {
|
|
363
932
|
liveAssistant.text += ev.text || '';
|
|
933
|
+
liveAssistant.activity = '正在生成回复…';
|
|
364
934
|
renderStream();
|
|
365
935
|
} else if (ev.type === 'tool') {
|
|
366
936
|
const existing = liveAssistant.tools.find(t => t.id === ev.id);
|
|
367
|
-
if (existing)
|
|
368
|
-
|
|
937
|
+
if (existing) {
|
|
938
|
+
existing.status = ev.status || existing.status;
|
|
939
|
+
if (ev.argsSummary) existing.argsSummary = ev.argsSummary;
|
|
940
|
+
if (ev.resultPreview !== undefined) existing.resultPreview = ev.resultPreview;
|
|
941
|
+
} else {
|
|
942
|
+
liveAssistant.tools.push({
|
|
943
|
+
id: ev.id,
|
|
944
|
+
name: ev.name || ev.title || 'tool',
|
|
945
|
+
argsSummary: ev.argsSummary || '',
|
|
946
|
+
resultPreview: ev.resultPreview || '',
|
|
947
|
+
status: ev.status || 'running',
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
const stillRunning = [...liveAssistant.tools].reverse().find(t => t.status === 'running');
|
|
951
|
+
if (stillRunning) {
|
|
952
|
+
liveAssistant.activity = `正在执行 ${stillRunning.name}${stillRunning.argsSummary ? ' · ' + stillRunning.argsSummary : ''}`;
|
|
953
|
+
} else {
|
|
954
|
+
liveAssistant.activity = '工具执行完成,正在汇总回复…';
|
|
955
|
+
}
|
|
369
956
|
renderStream();
|
|
370
957
|
} else if (ev.type === 'ask_user') {
|
|
371
|
-
liveAssistant.
|
|
958
|
+
if (!liveAssistant.questions.some(q => q.questionId === ev.questionId)) {
|
|
959
|
+
liveAssistant.questions.push({
|
|
960
|
+
questionId: ev.questionId,
|
|
961
|
+
question: ev.question,
|
|
962
|
+
options: ev.options || [],
|
|
963
|
+
answered: false,
|
|
964
|
+
answer: '',
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
liveAssistant.activity = '等待你的确认…';
|
|
372
968
|
renderStream();
|
|
373
969
|
} else if (ev.type === 'focus') {
|
|
374
970
|
actions.focusCanvas?.(ev.file, ev.heading);
|
|
375
971
|
} else if (ev.type === 'status') {
|
|
972
|
+
liveAssistant.activity = ev.text || liveAssistant.activity;
|
|
376
973
|
showToast(ev.text);
|
|
974
|
+
renderStream();
|
|
975
|
+
} else if (ev.type === 'done') {
|
|
976
|
+
if (ev.stopped && !liveAssistant.text.includes('已手动停止')) {
|
|
977
|
+
liveAssistant.text += (liveAssistant.text ? '\n\n' : '') + '_(已手动停止,以上内容已保留)_';
|
|
978
|
+
}
|
|
979
|
+
liveAssistant.activity = '';
|
|
980
|
+
renderStream();
|
|
377
981
|
} else if (ev.type === 'error') {
|
|
378
982
|
liveAssistant.text += (liveAssistant.text ? '\n\n' : '') + '提示:' + (ev.message || '执行失败');
|
|
983
|
+
liveAssistant.activity = '';
|
|
379
984
|
renderStream();
|
|
380
985
|
}
|
|
381
986
|
}
|
|
382
987
|
}
|
|
383
988
|
} catch (err) {
|
|
384
|
-
if (err.name
|
|
989
|
+
if (err.name === 'AbortError' || stoppingTurn) {
|
|
990
|
+
if (!liveAssistant.text.includes('已手动停止')) {
|
|
991
|
+
liveAssistant.text += (liveAssistant.text ? '\n\n' : '') + '_(已手动停止,以上内容已保留)_';
|
|
992
|
+
}
|
|
993
|
+
renderStream();
|
|
994
|
+
} else {
|
|
385
995
|
liveAssistant.text += (liveAssistant.text ? '\n\n' : '') + (err.message || '执行中断');
|
|
386
996
|
renderStream();
|
|
387
997
|
}
|
|
388
998
|
} finally {
|
|
999
|
+
if (pendingCancelPromise) {
|
|
1000
|
+
await pendingCancelPromise.catch(() => {});
|
|
1001
|
+
}
|
|
389
1002
|
s.status = 'idle';
|
|
1003
|
+
liveAssistant.activity = '';
|
|
390
1004
|
runningSessionId = '';
|
|
391
1005
|
activeAbort = null;
|
|
1006
|
+
stoppingTurn = false;
|
|
1007
|
+
pendingCancelPromise = null;
|
|
392
1008
|
sendBtn.textContent = '发送';
|
|
393
|
-
|
|
1009
|
+
sendBtn.disabled = false;
|
|
1010
|
+
|
|
1011
|
+
// Sync from server, but NEVER lose local messages if server hasn't flushed yet
|
|
1012
|
+
const prevCount = localSnapshotMsgs.length;
|
|
1013
|
+
const fresh = await refreshMeta();
|
|
1014
|
+
if (fresh) {
|
|
1015
|
+
const synced = sessions.find(x => x.id === s.id);
|
|
1016
|
+
if (synced && (!Array.isArray(synced.messages) || synced.messages.length < prevCount)) {
|
|
1017
|
+
synced.messages = localSnapshotMsgs;
|
|
1018
|
+
renderStream();
|
|
1019
|
+
}
|
|
1020
|
+
} else {
|
|
1021
|
+
renderRoleStrip();
|
|
1022
|
+
renderStream();
|
|
1023
|
+
}
|
|
394
1024
|
}
|
|
395
1025
|
}
|
|
396
1026
|
|
|
397
1027
|
async function handleSend() {
|
|
398
1028
|
if (runningSessionId) {
|
|
399
|
-
|
|
400
|
-
|
|
1029
|
+
if (stoppingTurn) return;
|
|
1030
|
+
stoppingTurn = true;
|
|
1031
|
+
sendBtn.textContent = '停止中…';
|
|
1032
|
+
sendBtn.disabled = true;
|
|
1033
|
+
const targetId = runningSessionId;
|
|
1034
|
+
const s = sessions.find(x => x.id === targetId);
|
|
1035
|
+
const lastMsg = s?.messages?.[s.messages.length - 1];
|
|
1036
|
+
if (lastMsg && lastMsg.role === 'assistant') {
|
|
1037
|
+
lastMsg.activity = '正在停止并保留已生成内容…';
|
|
1038
|
+
renderStream();
|
|
1039
|
+
}
|
|
1040
|
+
// Ask server to abort cleanly FIRST so pi-bridge saves partial output to disk
|
|
1041
|
+
pendingCancelPromise = fetch(withWs('/library/agent'), {
|
|
401
1042
|
method: 'POST',
|
|
402
1043
|
headers: { 'content-type': 'application/json' },
|
|
403
|
-
body: JSON.stringify({ action: 'cancel', session:
|
|
1044
|
+
body: JSON.stringify({ action: 'cancel', session: targetId }),
|
|
404
1045
|
}).catch(() => {});
|
|
1046
|
+
await pendingCancelPromise;
|
|
1047
|
+
// Fallback client abort only if stream hasn't closed after server cancel
|
|
1048
|
+
setTimeout(() => {
|
|
1049
|
+
if (runningSessionId === targetId && activeAbort) {
|
|
1050
|
+
activeAbort.abort();
|
|
1051
|
+
}
|
|
1052
|
+
}, 1200);
|
|
405
1053
|
return;
|
|
406
1054
|
}
|
|
1055
|
+
|
|
407
1056
|
const text = inputEl.value.trim();
|
|
408
1057
|
if (!text) return;
|
|
409
1058
|
inputEl.value = '';
|
|
1059
|
+
autoGrowInput();
|
|
410
1060
|
closePopover();
|
|
411
1061
|
const s = currentSession();
|
|
412
1062
|
if (!s) return;
|
|
@@ -451,6 +1101,20 @@
|
|
|
451
1101
|
// Bind dock events
|
|
452
1102
|
dock.querySelector('[data-toggle-drawer]').onclick = () => setDrawerOpen(!drawerOpen);
|
|
453
1103
|
dock.querySelector('[data-collapse]').onclick = () => setDrawerOpen(false);
|
|
1104
|
+
dock.querySelector('[data-new-session]').onclick = e => {
|
|
1105
|
+
e.stopPropagation();
|
|
1106
|
+
createNewSessionForCurrentRole();
|
|
1107
|
+
};
|
|
1108
|
+
sessionTriggerEl.onclick = e => {
|
|
1109
|
+
e.stopPropagation();
|
|
1110
|
+
closePopover();
|
|
1111
|
+
if (!sessionPopEl.hidden) {
|
|
1112
|
+
closeSessionPop();
|
|
1113
|
+
} else {
|
|
1114
|
+
renderSessionPop();
|
|
1115
|
+
sessionPopEl.hidden = false;
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
454
1118
|
dock.querySelector('[data-rollback]').onclick = async () => {
|
|
455
1119
|
const s = currentSession();
|
|
456
1120
|
if (!s) return;
|
|
@@ -468,16 +1132,51 @@
|
|
|
468
1132
|
});
|
|
469
1133
|
modelChip.onclick = e => {
|
|
470
1134
|
e.stopPropagation();
|
|
471
|
-
|
|
1135
|
+
closeSessionPop();
|
|
1136
|
+
if (!popoverEl.hidden && popoverEl.dataset.kind === 'model') closePopover();
|
|
472
1137
|
else { popoverEl.dataset.kind = 'model'; openModelPopover(); }
|
|
473
1138
|
};
|
|
474
|
-
|
|
1139
|
+
sendModeBtn.onclick = e => {
|
|
1140
|
+
e.stopPropagation();
|
|
1141
|
+
sendMode = sendMode === 'ctrl-enter' ? 'enter' : 'ctrl-enter';
|
|
1142
|
+
try { localStorage.setItem('clado-send-mode', sendMode); } catch {}
|
|
1143
|
+
syncSendModeUi();
|
|
1144
|
+
showToast(sendMode === 'ctrl-enter' ? '已切换:Enter 换行,Ctrl+Enter 发送' : '已切换:Enter 发送,Shift+Enter 换行');
|
|
1145
|
+
};
|
|
1146
|
+
inputEl.addEventListener('input', () => {
|
|
1147
|
+
autoGrowInput();
|
|
1148
|
+
updateSlashPopover();
|
|
1149
|
+
});
|
|
475
1150
|
inputEl.addEventListener('keydown', e => {
|
|
476
|
-
if (e.key === '
|
|
477
|
-
|
|
1151
|
+
if (e.key === 'Escape') {
|
|
1152
|
+
closePopover();
|
|
1153
|
+
closeSessionPop();
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
if (e.key === 'Enter' && !e.isComposing) {
|
|
1157
|
+
if (sendMode === 'ctrl-enter') {
|
|
1158
|
+
if (e.ctrlKey || e.metaKey) {
|
|
1159
|
+
e.preventDefault();
|
|
1160
|
+
handleSend();
|
|
1161
|
+
}
|
|
1162
|
+
// plain Enter inserts newline naturally
|
|
1163
|
+
} else {
|
|
1164
|
+
if (!e.shiftKey) {
|
|
1165
|
+
e.preventDefault();
|
|
1166
|
+
handleSend();
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
478
1170
|
});
|
|
479
1171
|
sendBtn.onclick = handleSend;
|
|
480
|
-
document.addEventListener('click', e => {
|
|
1172
|
+
document.addEventListener('click', e => {
|
|
1173
|
+
if (!dock.contains(e.target)) {
|
|
1174
|
+
closePopover();
|
|
1175
|
+
closeSessionPop();
|
|
1176
|
+
} else if (!sessionPopEl.contains(e.target) && !sessionTriggerEl.contains(e.target)) {
|
|
1177
|
+
closeSessionPop();
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
481
1180
|
|
|
482
1181
|
// =========================================================================
|
|
483
1182
|
// 3. Unified 5-Tab Settings Center Modal
|
|
@@ -504,7 +1203,7 @@
|
|
|
504
1203
|
</div>
|
|
505
1204
|
<button type="button" class="clado-ui-button" data-close-settings style="width:100%;border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);border-radius:12px;">← 返回画布</button>
|
|
506
1205
|
</aside>
|
|
507
|
-
<main class="clado-settings-body" data-sbody></main>
|
|
1206
|
+
<main class="clado-settings-body clado-scroll" data-sbody></main>
|
|
508
1207
|
</div>
|
|
509
1208
|
`;
|
|
510
1209
|
stageRoot().append(settingsMask);
|
|
@@ -634,7 +1333,7 @@
|
|
|
634
1333
|
<input class="clado-field" data-r-phase placeholder="阶段标签(如:审计阶段)" />
|
|
635
1334
|
</div>
|
|
636
1335
|
<input class="clado-field" data-r-desc placeholder="一句话职责描述" />
|
|
637
|
-
<textarea class="clado-field" data-r-prompt rows="3" placeholder="系统提示词(决定该角色如何协作修改画布或执行代码)"></textarea>
|
|
1336
|
+
<textarea class="clado-field clado-scroll" data-r-prompt rows="3" placeholder="系统提示词(决定该角色如何协作修改画布或执行代码)"></textarea>
|
|
638
1337
|
<div style="display:flex;justify-content:flex-end;gap:8px;">
|
|
639
1338
|
<button type="button" class="clado-ui-button" data-r-cancel>取消</button>
|
|
640
1339
|
<button type="button" class="clado-ui-button clado-ui-button-primary" data-r-save>保存角色</button>
|
|
@@ -719,7 +1418,6 @@
|
|
|
719
1418
|
};
|
|
720
1419
|
|
|
721
1420
|
const list = sBody.querySelector('[data-ext-list]');
|
|
722
|
-
// Built-in Clado Bridge
|
|
723
1421
|
const bridgeRow = document.createElement('div');
|
|
724
1422
|
bridgeRow.className = 'clado-well-box clado-setting-row';
|
|
725
1423
|
bridgeRow.innerHTML = `
|
|
@@ -735,7 +1433,6 @@
|
|
|
735
1433
|
`;
|
|
736
1434
|
list.append(bridgeRow);
|
|
737
1435
|
|
|
738
|
-
// Pi Packages
|
|
739
1436
|
for (const pkg of eco.packages || []) {
|
|
740
1437
|
const row = document.createElement('div');
|
|
741
1438
|
row.className = 'clado-well-box clado-setting-row';
|
|
@@ -758,7 +1455,6 @@
|
|
|
758
1455
|
list.append(row);
|
|
759
1456
|
}
|
|
760
1457
|
|
|
761
|
-
// Pi MCP Servers
|
|
762
1458
|
for (const m of eco.mcpServers || []) {
|
|
763
1459
|
const row = document.createElement('div');
|
|
764
1460
|
row.className = 'clado-well-box clado-setting-row';
|
|
@@ -787,7 +1483,6 @@
|
|
|
787
1483
|
list.append(row);
|
|
788
1484
|
}
|
|
789
1485
|
|
|
790
|
-
// Pi Skills
|
|
791
1486
|
for (const sk of eco.skills || []) {
|
|
792
1487
|
const row = document.createElement('div');
|
|
793
1488
|
row.className = 'clado-well-box clado-setting-row';
|
|
@@ -806,7 +1501,6 @@
|
|
|
806
1501
|
list.append(row);
|
|
807
1502
|
}
|
|
808
1503
|
|
|
809
|
-
// Pi /Prompts
|
|
810
1504
|
for (const pr of eco.prompts || []) {
|
|
811
1505
|
const row = document.createElement('div');
|
|
812
1506
|
row.className = 'clado-well-box clado-setting-row';
|
|
@@ -825,7 +1519,6 @@
|
|
|
825
1519
|
list.append(row);
|
|
826
1520
|
}
|
|
827
1521
|
|
|
828
|
-
// Optional Canvas Components (e.g. Lo-Fi widget)
|
|
829
1522
|
for (const c of comps) {
|
|
830
1523
|
const row = document.createElement('div');
|
|
831
1524
|
row.className = 'clado-well-box clado-setting-row';
|
|
@@ -859,7 +1552,7 @@
|
|
|
859
1552
|
</div>
|
|
860
1553
|
<button type="button" class="clado-ui-button clado-ui-button-primary" data-save-mem>保存 AGENTS.md</button>
|
|
861
1554
|
</div>
|
|
862
|
-
<textarea class="clado-field" data-mem-text style="flex:1;min-height:360px;font-family:ui-monospace,monospace;line-height:1.65;resize:none;" placeholder="# AGENTS.md - 写下本项目的代码约定、测试命令与架构约束…">${esc(content)}</textarea>
|
|
1555
|
+
<textarea class="clado-field clado-scroll" data-mem-text style="flex:1;min-height:360px;font-family:ui-monospace,monospace;line-height:1.65;resize:none;" placeholder="# AGENTS.md - 写下本项目的代码约定、测试命令与架构约束…">${esc(content)}</textarea>
|
|
863
1556
|
`;
|
|
864
1557
|
sBody.querySelector('[data-save-mem]').onclick = async () => {
|
|
865
1558
|
try {
|
|
@@ -969,7 +1662,7 @@
|
|
|
969
1662
|
meta = data;
|
|
970
1663
|
sessions = Array.isArray(data.sessions) ? data.sessions : [];
|
|
971
1664
|
if (!activeSessionId || !sessions.some(s => s.id === activeSessionId)) {
|
|
972
|
-
activeSessionId = sessions[0]?.id || '';
|
|
1665
|
+
activeSessionId = sessions.find(s => !s.archived)?.id || sessions[0]?.id || '';
|
|
973
1666
|
}
|
|
974
1667
|
renderRoleStrip();
|
|
975
1668
|
renderStream();
|
|
@@ -991,7 +1684,7 @@
|
|
|
991
1684
|
async function startCodeAnalysis(templateKey = 'arch') {
|
|
992
1685
|
const promptText = CODE_ANALYSIS_PROMPTS[templateKey] || CODE_ANALYSIS_PROMPTS.arch;
|
|
993
1686
|
if (!sessions.length) await refreshMeta();
|
|
994
|
-
const arch = sessions.find(s => s.roleId === 'architect') || sessions[0];
|
|
1687
|
+
const arch = sessions.find(s => !s.archived && s.roleId === 'architect') || sessions[0];
|
|
995
1688
|
if (!arch) return;
|
|
996
1689
|
await streamAgentRequest({
|
|
997
1690
|
action: 'prompt',
|
|
@@ -1016,6 +1709,7 @@
|
|
|
1016
1709
|
getMeta: () => meta,
|
|
1017
1710
|
isComponentEnabled,
|
|
1018
1711
|
setDrawerOpen,
|
|
1712
|
+
renderMarkdown,
|
|
1019
1713
|
};
|
|
1020
1714
|
|
|
1021
1715
|
refreshMeta();
|
|
@@ -1028,7 +1722,10 @@
|
|
|
1028
1722
|
refreshMeta,
|
|
1029
1723
|
focusComposer(prefill = '') {
|
|
1030
1724
|
setDrawerOpen(true);
|
|
1031
|
-
if (prefill)
|
|
1725
|
+
if (prefill) {
|
|
1726
|
+
inputEl.value = prefill;
|
|
1727
|
+
autoGrowInput();
|
|
1728
|
+
}
|
|
1032
1729
|
inputEl.focus();
|
|
1033
1730
|
},
|
|
1034
1731
|
};
|