cladogram 0.5.5-beta.9 → 0.6.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -79
- package/bin/clado.js +1 -1
- package/docs/release.md +7 -0
- package/package.json +3 -3
- package/plugins/agent/index.js +928 -3131
- package/plugins/agent/style.css +404 -1511
- package/plugins/brand/index.js +84 -466
- package/plugins/brand/style.css +39 -172
- package/plugins/directory/index.js +10 -10
- package/plugins/view-controls/index.js +17 -1
- package/plugins/view-controls/style.css +47 -29
- package/src/agent/clado-tools.js +299 -0
- package/src/agent/pi-bridge.js +487 -0
- package/src/agent/pi-config.js +630 -0
- package/src/html/plugin-ui.css +159 -134
- package/src/html/plugin-ui.js +3 -2
- package/src/server/agent.js +329 -1590
- package/src/server/assets/library.css +396 -11
- package/src/server/assets/library.html +37 -4
- package/src/server/assets/library.js +428 -203
- package/src/server/plugin-registry.js +7 -7
- package/src/server/plugins.js +1 -1
- package/src/server/workspace-hub.js +50 -0
- package/src/server/workspace.js +4 -15
- package/src/agent/commands.js +0 -204
- package/src/agent/context.js +0 -445
- package/src/agent/executors.js +0 -213
- package/src/agent/mcp-client.js +0 -308
- package/src/agent/probe.js +0 -234
- package/src/agent/providers/anthropic.js +0 -220
- package/src/agent/providers/index.js +0 -235
- package/src/agent/providers/openai.js +0 -146
- package/src/agent/runtime.js +0 -995
- package/src/agent/sessions.js +0 -336
- package/src/agent/skills.js +0 -190
package/plugins/agent/index.js
CHANGED
|
@@ -1,3239 +1,1036 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
const esc = s => String(s ?? '').replace(/[&<>"']/g, m => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[m]));
|
|
3
|
+
const ico = (d, sz = 14) => `<svg class="clado-svg-ico" style="width:${sz}px;height:${sz}px" aria-hidden="true" viewBox="0 0 24 24">${d}</svg>`;
|
|
4
|
+
const ICONS = {
|
|
5
|
+
sparkle: ico('<path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z"/>'),
|
|
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
|
+
plus: ico('<path d="M12 5v14M5 12h14"/>'),
|
|
8
|
+
close: ico('<path d="M18 6 6 18M6 6l12 12"/>'),
|
|
9
|
+
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
|
+
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
|
+
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"/>'),
|
|
12
|
+
book: ico('<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>'),
|
|
13
|
+
palette: ico('<circle cx="12" cy="12" r="9"/><path d="M12 3v18M12 8l6-2M12 14l6-2"/>'),
|
|
9
14
|
};
|
|
10
15
|
|
|
11
|
-
const
|
|
12
|
-
architect: { label: '研发架构师', pal: 'blue', defaultMode: 'design' },
|
|
13
|
-
coder: { label: '后端实现者', pal: 'teal', defaultMode: 'design' },
|
|
14
|
-
qa: { label: 'QA 测试专家', pal: 'violet', defaultMode: 'qa' },
|
|
15
|
-
auditor: { label: '验收审计官', pal: 'amber', defaultMode: 'audit' },
|
|
16
|
-
custom: { label: '自定义分身', pal: 'cyan', defaultMode: 'general' },
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const CANVAS_MEM_CYCLE = [
|
|
20
|
-
['delta', '智能增量'],
|
|
21
|
-
['outline', '仅大纲'],
|
|
22
|
-
['full', '每次全量'],
|
|
23
|
-
['off', '关闭'],
|
|
24
|
-
];
|
|
25
|
-
const TIME_MODE_CYCLE = [
|
|
26
|
-
['none', '不注入'],
|
|
27
|
-
['date_only', '仅日期'],
|
|
28
|
-
['tail_exact', '尾部精确时间'],
|
|
29
|
-
['system_head', '系统头时间'],
|
|
30
|
-
];
|
|
31
|
-
const TTL_CYCLE = [
|
|
32
|
-
[6, '6 小时'],
|
|
33
|
-
[24, '24 小时'],
|
|
34
|
-
[0, '不自动归档'],
|
|
35
|
-
];
|
|
36
|
-
const PERM_CYCLE = [
|
|
37
|
-
['readonly_free', '只读免审'],
|
|
38
|
-
['ask_always', '每次询问'],
|
|
39
|
-
['allow_all', '自动允许'],
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
window.CladoAgentPlugin = (host, {
|
|
43
|
-
readCanvas,
|
|
44
|
-
viewId,
|
|
45
|
-
placeholder,
|
|
46
|
-
agentName = 'ZCode',
|
|
47
|
-
endpoint = '/library/agent',
|
|
48
|
-
followAi: initialFollowAi = true,
|
|
49
|
-
setFollowAi = () => {},
|
|
50
|
-
focusTarget = () => {},
|
|
51
|
-
}) => {
|
|
52
|
-
const subEndpoint = suffix => endpoint.replace(/(\/library\/agent)(?=\?|$)/, '$1' + suffix);
|
|
53
|
-
const metaEndpoint = subEndpoint('/meta');
|
|
54
|
-
const sessionsEndpoint = subEndpoint('/sessions');
|
|
55
|
-
const configEndpoint = subEndpoint('/config');
|
|
56
|
-
const withParams = (base, params) => {
|
|
57
|
-
const entries = Object.entries(params || {}).filter(([, v]) => v !== undefined && v !== null && v !== '');
|
|
58
|
-
if (!entries.length) return base;
|
|
59
|
-
const qs = new URLSearchParams(entries).toString();
|
|
60
|
-
return base + (base.includes('?') ? '&' : '?') + qs;
|
|
61
|
-
};
|
|
62
|
-
const sessionUrl = (id, extra = {}) => withParams(sessionsEndpoint, { ...(id ? { id } : {}), ...extra });
|
|
16
|
+
const TONE_CHIP = { sky: 'clado-chip-sky', emerald: 'clado-chip-mint', violet: 'clado-chip-violet', amber: 'clado-chip-amber' };
|
|
63
17
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
<span class="clado-agent-orb-star" aria-hidden="true">✦</span>
|
|
70
|
-
<span class="clado-agent-orb-text">灵感</span>
|
|
71
|
-
</button>`;
|
|
72
|
-
host.mount('bottom-right', orbWrap, 'clado.agent');
|
|
18
|
+
const CODE_ANALYSIS_PROMPTS = {
|
|
19
|
+
arch: '请先扫描当前项目源码目录结构,识别核心模块、入口文件与数据流边界,然后调用 clado_create 创建一张名为 architecture-overview.md 的空间画布,把模块梳理成清晰的卡片、语义标签与依赖连线,方便我一眼看懂并继续微调设计。',
|
|
20
|
+
req: '请结合当前仓库现状,帮我创建一张名为 feature-design.md 的新需求拆解画布,包含核心入口契约、状态流转、风险清单与待确认决策卡片。',
|
|
21
|
+
qa: '请阅读当前仓库核心模块与已有测试,创建一张名为 test-matrix.md 的测试与压测矩阵画布,列出主链路、并发边界与异常回归检查项。',
|
|
22
|
+
};
|
|
73
23
|
|
|
74
|
-
|
|
24
|
+
window.CladoAgentPlugin = (host, actions = {}) => {
|
|
25
|
+
const withWs = actions.withWorkspace || (p => p);
|
|
26
|
+
const stageRoot = () => document.getElementById('clado-stage') || document.body;
|
|
27
|
+
|
|
28
|
+
let meta = null;
|
|
29
|
+
let sessions = [];
|
|
30
|
+
let activeSessionId = '';
|
|
31
|
+
let drawerOpen = false;
|
|
32
|
+
let runningSessionId = '';
|
|
33
|
+
let activeAbort = null;
|
|
34
|
+
let settingsTab = 'extensions';
|
|
35
|
+
let editingProviderId = '';
|
|
36
|
+
|
|
37
|
+
// =========================================================================
|
|
38
|
+
// 1. Bottom-Right Role Dock
|
|
39
|
+
// =========================================================================
|
|
75
40
|
const dock = document.createElement('div');
|
|
76
|
-
dock.className = 'clado-
|
|
41
|
+
dock.className = 'clado-vnext-dock';
|
|
77
42
|
dock.innerHTML = `
|
|
78
|
-
<div class="clado-
|
|
79
|
-
<div class="clado-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
43
|
+
<div class="clado-dock-drawer collapsed" data-drawer>
|
|
44
|
+
<div class="clado-dock-aura"></div>
|
|
45
|
+
<div class="clado-dock-inner">
|
|
46
|
+
<div class="clado-dock-head">
|
|
47
|
+
<div class="clado-dock-head-left">
|
|
48
|
+
<span class="clado-dock-title" data-role-title>主架构师</span>
|
|
49
|
+
<span class="clado-chip clado-chip-sky" data-role-phase>设计阶段</span>
|
|
83
50
|
</div>
|
|
84
|
-
<div class="clado-
|
|
85
|
-
<button type="button" class="clado-
|
|
86
|
-
<button type="button" class="clado-
|
|
87
|
-
<button type="button" class="clado-cmd-btn deny" data-cmd-decision="deny">拒绝</button>
|
|
51
|
+
<div class="clado-dock-actions">
|
|
52
|
+
<button type="button" class="clado-dock-mini-btn" data-rollback title="回退画布至上一轮快照">${ICONS.undo}<span>回退</span></button>
|
|
53
|
+
<button type="button" class="clado-dock-mini-btn" data-collapse>收起</button>
|
|
88
54
|
</div>
|
|
89
55
|
</div>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
<span class="clado-ai-aura" aria-hidden="true"></span>
|
|
97
|
-
<div class="clado-sp-body-fade" data-role="sp-inner">
|
|
98
|
-
<div class="clado-sp-header">
|
|
99
|
-
<div class="clado-sp-title-group">
|
|
100
|
-
<strong class="clado-sp-name" data-role="sp-name">架构师</strong>
|
|
101
|
-
<span class="clado-tag-pill clado-tag-blue" data-role="sp-persona-tag">研发架构师</span>
|
|
102
|
-
</div>
|
|
103
|
-
<div class="clado-sp-actions">
|
|
104
|
-
<div class="clado-tab-group" role="group" aria-label="规划或执行模式">
|
|
105
|
-
<button type="button" class="clado-tab-btn" data-exec-mode="plan">规划</button>
|
|
106
|
-
<button type="button" class="clado-tab-btn active" data-exec-mode="act">执行</button>
|
|
107
|
-
</div>
|
|
108
|
-
<button type="button" class="clado-icon-act" data-role="follow-btn" aria-pressed="${initialFollowAi ? 'true' : 'false'}" title="AI 修改卡片时自动跟随镜头">跟随</button>
|
|
109
|
-
<button type="button" class="clado-icon-act" data-role="open-settings" title="Agent 设置与记忆调试">设置</button>
|
|
110
|
-
<button type="button" class="clado-icon-act" data-role="archive-btn" title="归档当前会话">归档</button>
|
|
111
|
-
<button type="button" class="clado-icon-act del" data-role="delete-btn" title="删除当前会话">删除</button>
|
|
112
|
-
<button type="button" class="clado-icon-act" data-role="close-single" aria-label="收起详情">收起 ⌄</button>
|
|
113
|
-
</div>
|
|
114
|
-
</div>
|
|
115
|
-
|
|
116
|
-
<div class="clado-sp-subbar">
|
|
117
|
-
<div class="clado-sp-workflows" role="group" aria-label="协作工作流">
|
|
118
|
-
<button type="button" class="clado-tab-btn active" data-workflow="design">架构设计</button>
|
|
119
|
-
<button type="button" class="clado-tab-btn" data-workflow="qa">测试用例</button>
|
|
120
|
-
<button type="button" class="clado-tab-btn" data-workflow="audit">Diff 验收</button>
|
|
121
|
-
<button type="button" class="clado-tab-btn" data-workflow="dispatch">派发开发</button>
|
|
122
|
-
</div>
|
|
123
|
-
<div class="clado-sp-executor-wrap" data-role="executor-wrap" hidden>
|
|
124
|
-
<select class="clado-agent-select" data-role="executor-select" aria-label="ACP 执行器"></select>
|
|
125
|
-
</div>
|
|
126
|
-
</div>
|
|
127
|
-
|
|
128
|
-
<div class="clado-collapse-wrap closed" data-role="plan-banner-wrap">
|
|
129
|
-
<div class="clado-collapse-inner">
|
|
130
|
-
<div class="clado-plan-banner">只读规划中:已拦截写画布与写命令,仅允许探针读取与拆解步骤。</div>
|
|
131
|
-
</div>
|
|
132
|
-
</div>
|
|
133
|
-
|
|
134
|
-
<div class="clado-todo-box" data-role="todo-box" hidden>
|
|
135
|
-
<div class="clado-todo-head">
|
|
136
|
-
<span class="clado-todo-summary" data-role="todo-summary"></span>
|
|
137
|
-
<span class="clado-todo-arrow" data-role="todo-arrow">展开 ▾</span>
|
|
138
|
-
</div>
|
|
139
|
-
<div class="clado-collapse-wrap closed" data-role="todo-collapse">
|
|
140
|
-
<div class="clado-collapse-inner">
|
|
141
|
-
<div class="clado-todo-list" data-role="todo-list"></div>
|
|
142
|
-
</div>
|
|
143
|
-
</div>
|
|
144
|
-
</div>
|
|
145
|
-
|
|
146
|
-
<div class="clado-agent-log" role="log" aria-label="会话消息" aria-live="off"></div>
|
|
147
|
-
<p class="clado-agent-status" role="status" hidden></p>
|
|
56
|
+
<div class="clado-dock-stream" data-stream></div>
|
|
57
|
+
<div class="clado-dock-handoff">
|
|
58
|
+
<span style="color:var(--clado-ui-subtle);">流转至下一阶段</span>
|
|
59
|
+
<div style="display:flex;align-items:center;gap:6px;">
|
|
60
|
+
<button type="button" class="clado-dock-mini-btn" style="border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);" data-quick-handoff="developer">交给开发落地</button>
|
|
61
|
+
<button type="button" class="clado-dock-mini-btn" style="border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);" data-quick-handoff="tester">交给测试验证</button>
|
|
148
62
|
</div>
|
|
149
|
-
</
|
|
63
|
+
</div>
|
|
150
64
|
</div>
|
|
151
65
|
</div>
|
|
152
66
|
|
|
153
|
-
<div class="clado-
|
|
67
|
+
<div class="clado-role-strip" data-role-strip></div>
|
|
154
68
|
|
|
155
|
-
<
|
|
156
|
-
<
|
|
157
|
-
<button type="button" class="clado-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
<button type="submit" class="clado-agent-send-btn" data-role="send-btn" disabled>发送</button>
|
|
164
|
-
<div class="clado-edge-aura" aria-hidden="true">
|
|
165
|
-
<div class="clado-edge-aura-bloom"></div>
|
|
166
|
-
<div class="clado-edge-aura-line"><div class="clado-edge-aura-runner"></div></div>
|
|
167
|
-
</div>
|
|
168
|
-
</form>`;
|
|
69
|
+
<div class="clado-composer">
|
|
70
|
+
<div class="clado-dock-popover" data-popover hidden></div>
|
|
71
|
+
<button type="button" class="clado-ui-button" data-toggle-drawer style="width:28px;height:28px;padding:0;min-height:28px;color:var(--clado-ui-brand);" title="展开或收起角色会话">${ICONS.sparkle}</button>
|
|
72
|
+
<button type="button" class="clado-model-chip" data-model-chip title="切换模型或配置供应商">配置模型 ▾</button>
|
|
73
|
+
<input type="text" class="clado-composer-input" data-input placeholder="改设计、敲 / 调命令,或选中卡片派活…" />
|
|
74
|
+
<button type="button" class="clado-ui-button clado-ui-button-primary" data-send style="min-height:28px;padding:4px 13px;font-size:12px;">发送</button>
|
|
75
|
+
</div>
|
|
76
|
+
`;
|
|
169
77
|
host.mount('bottom-right', dock, 'clado.agent');
|
|
170
78
|
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const slashMenu = document.createElement('div');
|
|
181
|
-
slashMenu.className = 'clado-slash-menu';
|
|
182
|
-
document.body.append(slashMenu);
|
|
183
|
-
|
|
184
|
-
const configView = document.createElement('div');
|
|
185
|
-
configView.className = 'clado-agent-overlay';
|
|
186
|
-
configView.innerHTML = `
|
|
187
|
-
<div class="clado-panel-container clado-agent-glass clado-cfg-stage">
|
|
188
|
-
<div class="clado-cfg-page" data-role="cfg-home">
|
|
189
|
-
<div style="display:flex;align-items:center;justify-content:space-between;padding:0 4px 10px;">
|
|
190
|
-
<span style="font-size:16px;font-weight:700;">Agent 设置</span>
|
|
191
|
-
<button type="button" class="clado-tab-btn active" data-cfg-act="close-settings" style="padding:5px 12px;font-size:12px;">完成</button>
|
|
192
|
-
</div>
|
|
193
|
-
|
|
194
|
-
<div class="clado-group-title">主力模型与供应商</div>
|
|
195
|
-
<div class="clado-settings-group" style="margin-bottom:13px;">
|
|
196
|
-
<div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="llm">
|
|
197
|
-
<span class="clado-s-title">供应商与模型配置</span>
|
|
198
|
-
<span class="clado-s-val"><span data-cfg-val="llm" style="color:var(--clado-ui-brand);font-weight:620;">未配置 · 点击设置</span> <span style="opacity:.45;">›</span></span>
|
|
199
|
-
</div>
|
|
200
|
-
</div>
|
|
201
|
-
|
|
202
|
-
<div class="clado-group-title">扩展能力:MCP · 技能库 · 斜杠命令</div>
|
|
203
|
-
<div class="clado-settings-group" style="margin-bottom:13px;">
|
|
204
|
-
<div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="mcp">
|
|
205
|
-
<span class="clado-s-title">MCP 服务(外部工具 & 本机画布)</span>
|
|
206
|
-
<span class="clado-s-val"><span data-cfg-val="mcp">0 个外部服务</span> <span style="opacity:.45;">›</span></span>
|
|
207
|
-
</div>
|
|
208
|
-
<div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="skills">
|
|
209
|
-
<span class="clado-s-title">技能库 (SKILL.md)</span>
|
|
210
|
-
<span class="clado-s-val"><span data-cfg-val="skills">0 个技能</span> <span style="opacity:.45;">›</span></span>
|
|
211
|
-
</div>
|
|
212
|
-
<div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="commands">
|
|
213
|
-
<span class="clado-s-title">斜杠命令 (/Commands)</span>
|
|
214
|
-
<span class="clado-s-val"><span data-cfg-val="commands">4 条命令</span> <span style="opacity:.45;">›</span></span>
|
|
215
|
-
</div>
|
|
216
|
-
</div>
|
|
217
|
-
|
|
218
|
-
<div class="clado-group-title">人设与会话生命周期</div>
|
|
219
|
-
<div class="clado-settings-group" style="margin-bottom:13px;">
|
|
220
|
-
<div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="persona">
|
|
221
|
-
<span class="clado-s-title">人设与分身角色</span>
|
|
222
|
-
<span class="clado-s-val"><span data-cfg-val="persona">4 套模板</span> <span style="opacity:.45;">›</span></span>
|
|
223
|
-
</div>
|
|
224
|
-
<div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="compact">
|
|
225
|
-
<span class="clado-s-title">上下文压缩提示词</span>
|
|
226
|
-
<span class="clado-s-val"><span data-cfg-val="compact">75% 触发 · 编辑</span> <span style="opacity:.45;">›</span></span>
|
|
227
|
-
</div>
|
|
228
|
-
<div class="clado-s-row clickable" data-cfg-act="cycle" data-cfg-kind="ttl">
|
|
229
|
-
<span class="clado-s-title">空闲会话自动归档</span>
|
|
230
|
-
<span class="clado-s-val"><span data-cfg-val="ttl">24 小时</span> <span style="opacity:.45;">›</span></span>
|
|
231
|
-
</div>
|
|
232
|
-
</div>
|
|
233
|
-
|
|
234
|
-
<div class="clado-group-title">上下文与记忆</div>
|
|
235
|
-
<div class="clado-settings-group" style="margin-bottom:13px;">
|
|
236
|
-
<div class="clado-s-row clickable" data-cfg-act="cycle" data-cfg-kind="canvas">
|
|
237
|
-
<span class="clado-s-title">画布实时记忆</span>
|
|
238
|
-
<span class="clado-s-val"><span data-cfg-val="canvas">智能增量</span> <span style="opacity:.45;">›</span></span>
|
|
239
|
-
</div>
|
|
240
|
-
<div class="clado-s-row clickable" data-cfg-act="cycle" data-cfg-kind="time">
|
|
241
|
-
<span class="clado-s-title">时间信息注入</span>
|
|
242
|
-
<span class="clado-s-val"><span data-cfg-val="time">仅日期</span> <span style="opacity:.45;">›</span></span>
|
|
243
|
-
</div>
|
|
244
|
-
<div class="clado-s-row">
|
|
245
|
-
<span class="clado-s-title">工作区全局目录索引</span>
|
|
246
|
-
<button type="button" class="clado-switch-btn on" data-cfg-act="toggle-map" aria-label="工作区全局目录索引"><i></i></button>
|
|
247
|
-
</div>
|
|
248
|
-
<div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="memory">
|
|
249
|
-
<span class="clado-s-title">持久记忆 (memory.md)</span>
|
|
250
|
-
<span class="clado-s-val"><span data-cfg-val="memory">已开启 · 编辑</span> <span style="opacity:.45;">›</span></span>
|
|
251
|
-
</div>
|
|
252
|
-
</div>
|
|
253
|
-
|
|
254
|
-
<div class="clado-group-title">安全、缓存与外部子代理</div>
|
|
255
|
-
<div class="clado-settings-group">
|
|
256
|
-
<div class="clado-s-row clickable" data-cfg-act="cycle" data-cfg-kind="perm">
|
|
257
|
-
<span class="clado-s-title">命令行执行权限</span>
|
|
258
|
-
<span class="clado-s-val"><span data-cfg-val="perm">只读免审</span> <span style="opacity:.45;">›</span></span>
|
|
259
|
-
</div>
|
|
260
|
-
<div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="cache">
|
|
261
|
-
<span class="clado-s-title">前缀缓存命中状态</span>
|
|
262
|
-
<span class="clado-s-val"><span data-cfg-val="cache" style="color:#059669;font-weight:600;">99.4% 命中</span> <span style="opacity:.45;">›</span></span>
|
|
263
|
-
</div>
|
|
264
|
-
<div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="acp">
|
|
265
|
-
<span class="clado-s-title">外部 ACP 子代理(可选)</span>
|
|
266
|
-
<span class="clado-s-val"><span data-cfg-val="acp">低优备用</span> <span style="opacity:.45;">›</span></span>
|
|
267
|
-
</div>
|
|
268
|
-
</div>
|
|
269
|
-
</div>
|
|
79
|
+
const drawerEl = dock.querySelector('[data-drawer]');
|
|
80
|
+
const roleTitleEl = dock.querySelector('[data-role-title]');
|
|
81
|
+
const rolePhaseEl = dock.querySelector('[data-role-phase]');
|
|
82
|
+
const streamEl = dock.querySelector('[data-stream]');
|
|
83
|
+
const stripEl = dock.querySelector('[data-role-strip]');
|
|
84
|
+
const inputEl = dock.querySelector('[data-input]');
|
|
85
|
+
const sendBtn = dock.querySelector('[data-send]');
|
|
86
|
+
const modelChip = dock.querySelector('[data-model-chip]');
|
|
87
|
+
const popoverEl = dock.querySelector('[data-popover]');
|
|
270
88
|
|
|
271
|
-
<div class="clado-cfg-sub-page" data-role="cfg-sub">
|
|
272
|
-
<div style="display:flex;align-items:center;justify-content:space-between;padding:0 2px;">
|
|
273
|
-
<button type="button" class="clado-tab-btn active" data-cfg-act="close-sub" style="padding:5px 10px;font-size:12px;">← 返回</button>
|
|
274
|
-
<strong data-role="sub-title" style="font-size:14px;">编辑</strong>
|
|
275
|
-
<button type="button" class="clado-tab-btn active" data-role="sub-reset" data-cfg-act="reset-sub" style="padding:5px 10px;font-size:12px;">恢复默认</button>
|
|
276
|
-
</div>
|
|
277
|
-
<div class="clado-settings-group" data-role="sub-body" style="padding:14px;display:flex;flex-direction:column;gap:12px;"></div>
|
|
278
|
-
</div>
|
|
279
|
-
</div>`;
|
|
280
|
-
document.body.append(configView);
|
|
281
|
-
|
|
282
|
-
const toastEl = document.createElement('div');
|
|
283
|
-
toastEl.className = 'clado-agent-toast';
|
|
284
|
-
document.body.append(toastEl);
|
|
285
|
-
|
|
286
|
-
// 4. DOM 引用与基础工具函数
|
|
287
|
-
const orbBtn = orbWrap.querySelector('.clado-agent-orb');
|
|
288
|
-
const orbText = orbWrap.querySelector('.clado-agent-orb-text');
|
|
289
|
-
const cmdWrap = dock.querySelector('[data-role="cmd-wrap"]');
|
|
290
|
-
const cmdWho = dock.querySelector('[data-role="cmd-who"]');
|
|
291
|
-
const cmdCode = dock.querySelector('[data-role="cmd-code"]');
|
|
292
|
-
const singleWrap = dock.querySelector('[data-role="single-wrap"]');
|
|
293
|
-
const panel = dock.querySelector('#clado-agent-panel');
|
|
294
|
-
const spInner = dock.querySelector('[data-role="sp-inner"]');
|
|
295
|
-
const spName = dock.querySelector('[data-role="sp-name"]');
|
|
296
|
-
const spPersonaTag = dock.querySelector('[data-role="sp-persona-tag"]');
|
|
297
|
-
const modelChip = dock.querySelector('[data-role="model-chip"]');
|
|
298
|
-
const modelChipLabel = dock.querySelector('[data-role="model-chip-label"]');
|
|
299
|
-
const execModeBtns = [...dock.querySelectorAll('[data-exec-mode]')];
|
|
300
|
-
const workflowBtns = [...dock.querySelectorAll('[data-workflow]')];
|
|
301
|
-
const followBtn = dock.querySelector('[data-role="follow-btn"]');
|
|
302
|
-
const executorWrap = dock.querySelector('[data-role="executor-wrap"]');
|
|
303
|
-
const executorSelect = dock.querySelector('[data-role="executor-select"]');
|
|
304
|
-
const planBannerWrap = dock.querySelector('[data-role="plan-banner-wrap"]');
|
|
305
|
-
const todoBox = dock.querySelector('[data-role="todo-box"]');
|
|
306
|
-
const todoSummary = dock.querySelector('[data-role="todo-summary"]');
|
|
307
|
-
const todoArrow = dock.querySelector('[data-role="todo-arrow"]');
|
|
308
|
-
const todoCollapse = dock.querySelector('[data-role="todo-collapse"]');
|
|
309
|
-
const todoList = dock.querySelector('[data-role="todo-list"]');
|
|
310
|
-
const log = dock.querySelector('.clado-agent-log');
|
|
311
|
-
const statusEl = dock.querySelector('.clado-agent-status');
|
|
312
|
-
const peerClusterEl = dock.querySelector('[data-role="peer-cluster"]');
|
|
313
|
-
const shell = dock.querySelector('[data-role="agent-shell"]');
|
|
314
|
-
const input = dock.querySelector('.clado-agent-input');
|
|
315
|
-
const stopBtn = dock.querySelector('[data-role="stop-btn"]');
|
|
316
|
-
const sendBtn = dock.querySelector('[data-role="send-btn"]');
|
|
317
|
-
|
|
318
|
-
let toastTimer = null;
|
|
319
89
|
function showToast(msg) {
|
|
320
|
-
|
|
321
|
-
toastEl.textContent = msg;
|
|
322
|
-
toastEl.classList.add('show');
|
|
323
|
-
if (toastTimer) clearTimeout(toastTimer);
|
|
324
|
-
toastTimer = setTimeout(() => toastEl.classList.remove('show'), 2300);
|
|
90
|
+
window.dispatchEvent(new CustomEvent('clado:toast', { detail: { message: msg } }));
|
|
325
91
|
}
|
|
326
92
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
selectEl.tabIndex = -1;
|
|
332
|
-
selectEl.setAttribute('aria-hidden', 'true');
|
|
333
|
-
const wrap = document.createElement('div');
|
|
334
|
-
wrap.className = 'clado-glass-dropdown';
|
|
335
|
-
const trigger = document.createElement('button');
|
|
336
|
-
trigger.type = 'button';
|
|
337
|
-
trigger.className = 'clado-glass-dropdown-trigger';
|
|
338
|
-
trigger.setAttribute('aria-haspopup', 'listbox');
|
|
339
|
-
trigger.setAttribute('aria-expanded', 'false');
|
|
340
|
-
trigger.innerHTML =
|
|
341
|
-
'<span class="clado-glass-dropdown-value"><span class="clado-glass-dropdown-dot"></span><span class="clado-glass-dropdown-label"></span></span>' +
|
|
342
|
-
'<svg class="clado-glass-dropdown-chevron" aria-hidden="true" viewBox="0 0 24 24"><path d="m6 9 6 6 6-6"/></svg>';
|
|
343
|
-
const menu = document.createElement('div');
|
|
344
|
-
menu.className = 'clado-glass-dropdown-menu';
|
|
345
|
-
menu.setAttribute('role', 'listbox');
|
|
346
|
-
menu.hidden = true;
|
|
347
|
-
wrap.append(trigger, menu);
|
|
348
|
-
selectEl.after(wrap);
|
|
349
|
-
|
|
350
|
-
const dotEl = trigger.querySelector('.clado-glass-dropdown-dot');
|
|
351
|
-
const labelEl = trigger.querySelector('.clado-glass-dropdown-label');
|
|
352
|
-
|
|
353
|
-
const setDropdownOpen = open => {
|
|
354
|
-
if (open && selectEl.disabled) return;
|
|
355
|
-
if (open) {
|
|
356
|
-
for (const other of glassDropdowns) {
|
|
357
|
-
if (other.menu !== menu && !other.menu.hidden) other.setOpen(false);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
menu.hidden = !open;
|
|
361
|
-
wrap.classList.toggle('open', open);
|
|
362
|
-
trigger.setAttribute('aria-expanded', String(open));
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
const sync = () => {
|
|
366
|
-
trigger.disabled = selectEl.disabled;
|
|
367
|
-
const opts = [...selectEl.options];
|
|
368
|
-
const activeVal = selectEl.value;
|
|
369
|
-
const currentOpt = opts.find(o => o.value === activeVal) || opts[0];
|
|
370
|
-
dotEl.style.background = (currentOpt && dotColors[currentOpt.value]) || defaultDot;
|
|
371
|
-
labelEl.textContent = currentOpt ? currentOpt.textContent : '默认执行器';
|
|
372
|
-
menu.replaceChildren();
|
|
373
|
-
for (const opt of opts) {
|
|
374
|
-
const item = document.createElement('button');
|
|
375
|
-
item.type = 'button';
|
|
376
|
-
item.className = 'clado-ui-button clado-glass-dropdown-option';
|
|
377
|
-
item.setAttribute('role', 'option');
|
|
378
|
-
const selected = opt.value === activeVal;
|
|
379
|
-
item.setAttribute('aria-selected', String(selected));
|
|
380
|
-
const itemDot = document.createElement('span');
|
|
381
|
-
itemDot.className = 'clado-glass-dropdown-dot';
|
|
382
|
-
itemDot.style.background = dotColors[opt.value] || defaultDot;
|
|
383
|
-
const copy = document.createElement('span');
|
|
384
|
-
copy.className = 'clado-glass-dropdown-copy';
|
|
385
|
-
const title = document.createElement('strong');
|
|
386
|
-
title.textContent = opt.textContent;
|
|
387
|
-
copy.append(title);
|
|
388
|
-
const descText = opt.title || fallbackSummaries[opt.value] || '';
|
|
389
|
-
if (descText) {
|
|
390
|
-
const desc = document.createElement('small');
|
|
391
|
-
desc.textContent = descText;
|
|
392
|
-
copy.append(desc);
|
|
393
|
-
}
|
|
394
|
-
const check = document.createElement('span');
|
|
395
|
-
check.className = 'clado-glass-dropdown-check';
|
|
396
|
-
check.textContent = '✓';
|
|
397
|
-
item.append(itemDot, copy, check);
|
|
398
|
-
item.onclick = () => {
|
|
399
|
-
if (selectEl.value !== opt.value) {
|
|
400
|
-
selectEl.value = opt.value;
|
|
401
|
-
selectEl.dispatchEvent(new Event('change', { bubbles: true }));
|
|
402
|
-
}
|
|
403
|
-
sync();
|
|
404
|
-
setDropdownOpen(false);
|
|
405
|
-
};
|
|
406
|
-
menu.append(item);
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
trigger.onclick = ev => {
|
|
411
|
-
ev.stopPropagation();
|
|
412
|
-
setDropdownOpen(menu.hidden);
|
|
413
|
-
};
|
|
414
|
-
const api = { wrap, menu, sync, setOpen: setDropdownOpen };
|
|
415
|
-
glassDropdowns.push(api);
|
|
416
|
-
sync();
|
|
417
|
-
return api;
|
|
93
|
+
function setDrawerOpen(open) {
|
|
94
|
+
drawerOpen = Boolean(open);
|
|
95
|
+
drawerEl.classList.toggle('collapsed', !drawerOpen);
|
|
96
|
+
document.body.dataset.agentDock = drawerOpen ? 'open' : 'closed';
|
|
418
97
|
}
|
|
419
98
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
// 5. 核心状态
|
|
423
|
-
const defaultPlaceholder = placeholder || '写下一个想法…(长按上方会话可新建/归档)';
|
|
424
|
-
const workflowHints = {
|
|
425
|
-
design: defaultPlaceholder,
|
|
426
|
-
qa: '描述需要补充或评审的测试用例范围…',
|
|
427
|
-
audit: '输入要核对的变更点,或直接回车核对当前 Git Diff…',
|
|
428
|
-
dispatch: '可选补充开发要求;留空将按当前画布规格派发给 ACP 执行器…',
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
let minimized = false;
|
|
432
|
-
try { minimized = sessionStorage.getItem('clado-agent-minimized') === '1'; } catch {}
|
|
433
|
-
let singlePanelOpen = false;
|
|
434
|
-
let todoExpanded = false;
|
|
435
|
-
let followAi = !!initialFollowAi;
|
|
436
|
-
|
|
437
|
-
let session = crypto.randomUUID();
|
|
438
|
-
let running = false;
|
|
439
|
-
let stopping = false;
|
|
440
|
-
let streamingSessionId = '';
|
|
441
|
-
let workflow = 'design';
|
|
442
|
-
let persona = 'architect';
|
|
443
|
-
let execMode = 'act';
|
|
444
|
-
|
|
445
|
-
let meta = {
|
|
446
|
-
engine: 'builtin',
|
|
447
|
-
provider: 'openai',
|
|
448
|
-
providerId: 'openai',
|
|
449
|
-
providerLabel: 'OpenAI',
|
|
450
|
-
builtinConfigured: false,
|
|
451
|
-
model: '',
|
|
452
|
-
mcpUrl: '',
|
|
453
|
-
llm: null,
|
|
454
|
-
executors: [],
|
|
455
|
-
personas: [],
|
|
456
|
-
sessions: [],
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
// 会话列表与完整记录缓存
|
|
460
|
-
let sessionsList = [];
|
|
461
|
-
let archivedList = [];
|
|
462
|
-
const sessionRecords = new Map();
|
|
463
|
-
const pillDomMap = new Map();
|
|
464
|
-
// 记录同伴呼叫高亮过期时间 id -> { pal, until, seenAt }
|
|
465
|
-
const calledFlashMap = new Map();
|
|
466
|
-
let activePendingCmd = null; // { sessionId, sessionTitle, cmd }
|
|
467
|
-
|
|
468
|
-
const toolStates = { pending: '等待中', in_progress: '运行中', completed: '已完成', failed: '失败' };
|
|
469
|
-
const request = (data, keepalive = false) => fetch(endpoint, {
|
|
470
|
-
method: 'POST',
|
|
471
|
-
headers: { 'content-type': 'application/json' },
|
|
472
|
-
body: JSON.stringify(data),
|
|
473
|
-
keepalive,
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
function closeModelMenu() {
|
|
477
|
-
modelMenu.classList.remove('open');
|
|
99
|
+
function currentSession() {
|
|
100
|
+
return sessions.find(s => s.id === activeSessionId) || sessions[0] || null;
|
|
478
101
|
}
|
|
479
102
|
|
|
480
|
-
function
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
103
|
+
function renderRoleStrip() {
|
|
104
|
+
stripEl.replaceChildren();
|
|
105
|
+
for (const s of sessions) {
|
|
106
|
+
if (s.archived) continue;
|
|
107
|
+
const btn = document.createElement('button');
|
|
108
|
+
btn.type = 'button';
|
|
109
|
+
btn.className = 'clado-role-pill' + (s.id === activeSessionId ? ' active' : '');
|
|
110
|
+
btn.dataset.tone = s.tone || 'sky';
|
|
111
|
+
const badge = s.status === 'running' ? ' · 运行中' : (s.summaryBadge ? ' · ' + s.summaryBadge : '');
|
|
112
|
+
btn.textContent = s.title + badge;
|
|
113
|
+
btn.onclick = () => {
|
|
114
|
+
activeSessionId = s.id;
|
|
115
|
+
setDrawerOpen(true);
|
|
116
|
+
renderRoleStrip();
|
|
117
|
+
renderStream();
|
|
118
|
+
};
|
|
119
|
+
stripEl.append(btn);
|
|
120
|
+
}
|
|
121
|
+
const addBtn = document.createElement('button');
|
|
122
|
+
addBtn.type = 'button';
|
|
123
|
+
addBtn.className = 'clado-role-pill clado-role-add';
|
|
124
|
+
addBtn.title = '新建角色会话';
|
|
125
|
+
addBtn.innerHTML = ICONS.plus;
|
|
126
|
+
addBtn.onclick = () => openNewRoleSessionPopover();
|
|
127
|
+
stripEl.append(addBtn);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function renderStream() {
|
|
131
|
+
const s = currentSession();
|
|
132
|
+
if (!s) return;
|
|
133
|
+
roleTitleEl.textContent = s.title || '主架构师';
|
|
134
|
+
rolePhaseEl.textContent = s.phase || '设计阶段';
|
|
135
|
+
rolePhaseEl.className = 'clado-chip ' + (TONE_CHIP[s.tone] || 'clado-chip-sky');
|
|
136
|
+
|
|
137
|
+
const modelLabel = s.model || meta?.activeModelLabel || '配置模型';
|
|
138
|
+
modelChip.textContent = (modelLabel.includes('/') ? modelLabel.split('/').pop() : modelLabel) + ' ▾';
|
|
139
|
+
|
|
140
|
+
const msgs = Array.isArray(s.messages) ? s.messages : [];
|
|
141
|
+
streamEl.replaceChildren();
|
|
142
|
+
if (!msgs.length) {
|
|
143
|
+
const empty = document.createElement('div');
|
|
144
|
+
empty.className = 'clado-dock-empty';
|
|
145
|
+
empty.innerHTML = `当前角色:<strong>${esc(s.title)}</strong>(Pi 1.0 引擎)<br/>可直接描述架构修改、输入 <code>/</code> 调命令,或在画布选中卡片派活交付。`;
|
|
146
|
+
streamEl.append(empty);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
487
149
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
150
|
+
for (const m of msgs) {
|
|
151
|
+
if (m.role === 'user') {
|
|
152
|
+
const div = document.createElement('div');
|
|
153
|
+
div.className = 'clado-msg-user';
|
|
154
|
+
const prefix = m.handoffFrom ? `[交接自 ${m.handoffFrom}]\n` : '';
|
|
155
|
+
div.textContent = prefix + (m.text || '');
|
|
156
|
+
streamEl.append(div);
|
|
157
|
+
} else {
|
|
158
|
+
if (Array.isArray(m.tools) && m.tools.length) {
|
|
159
|
+
const toolLine = document.createElement('div');
|
|
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));
|
|
168
|
+
}
|
|
169
|
+
if (m.text) {
|
|
170
|
+
const div = document.createElement('div');
|
|
171
|
+
div.className = 'clado-msg-assistant';
|
|
172
|
+
div.textContent = m.text;
|
|
173
|
+
streamEl.append(div);
|
|
174
|
+
}
|
|
494
175
|
}
|
|
495
|
-
closeCtxMenu();
|
|
496
|
-
closeModelMenu();
|
|
497
|
-
slashMenu.classList.remove('open');
|
|
498
|
-
for (const dd of glassDropdowns) dd.setOpen(false);
|
|
499
|
-
}
|
|
500
|
-
syncDockPresence();
|
|
501
|
-
if (!minimized) {
|
|
502
|
-
renderPeerCluster(false);
|
|
503
|
-
requestAnimationFrame(() => updatePeerEdgeFade());
|
|
504
176
|
}
|
|
177
|
+
streamEl.scrollTop = streamEl.scrollHeight;
|
|
505
178
|
}
|
|
506
179
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
180
|
+
function buildDecisionCard(sessionId, q) {
|
|
181
|
+
const box = document.createElement('div');
|
|
182
|
+
box.className = 'clado-decision-card';
|
|
183
|
+
box.innerHTML = `<div class="clado-decision-q">${esc(q.question)}</div><div class="clado-decision-opts"></div>`;
|
|
184
|
+
const optsWrap = box.querySelector('.clado-decision-opts');
|
|
185
|
+
const opts = Array.isArray(q.options) && q.options.length ? q.options : [{ id: 'confirm', label: '确认继续' }];
|
|
186
|
+
for (let i = 0; i < opts.length; i++) {
|
|
187
|
+
const opt = opts[i];
|
|
188
|
+
const btn = document.createElement('button');
|
|
189
|
+
btn.type = 'button';
|
|
190
|
+
btn.className = 'clado-ui-button ' + (i === 0 ? 'clado-ui-button-primary' : '');
|
|
191
|
+
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);' : '');
|
|
192
|
+
btn.textContent = opt.label;
|
|
193
|
+
btn.onclick = async () => {
|
|
194
|
+
q.answered = true;
|
|
195
|
+
box.remove();
|
|
196
|
+
await fetch(withWs('/library/agent'), {
|
|
197
|
+
method: 'POST',
|
|
198
|
+
headers: { 'content-type': 'application/json' },
|
|
199
|
+
body: JSON.stringify({ action: 'answer', session: sessionId, questionId: q.questionId, answer: opt.label }),
|
|
200
|
+
});
|
|
201
|
+
showToast('已确认:' + opt.label);
|
|
202
|
+
};
|
|
203
|
+
optsWrap.append(btn);
|
|
527
204
|
}
|
|
528
|
-
|
|
529
|
-
if (secs < 3600) return `${Math.floor(secs / 60)}m 前`;
|
|
530
|
-
if (secs < 86400) return `${Math.floor(secs / 3600)}h 前`;
|
|
531
|
-
return `${Math.floor(secs / 86400)}d 前`;
|
|
205
|
+
return box;
|
|
532
206
|
}
|
|
533
207
|
|
|
534
|
-
function
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
.slice()
|
|
538
|
-
.sort((a, b) => {
|
|
539
|
-
const actA = isSessionActive(a);
|
|
540
|
-
const actB = isSessionActive(b);
|
|
541
|
-
if (actA !== actB) return actA ? -1 : 1;
|
|
542
|
-
const tA = toEpochMs(a.lastActiveAt) || toEpochMs(a.updatedAt);
|
|
543
|
-
const tB = toEpochMs(b.lastActiveAt) || toEpochMs(b.updatedAt);
|
|
544
|
-
return tB - tA;
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
let peerScrollX = 0;
|
|
549
|
-
let stripDown = false;
|
|
550
|
-
let stripMoved = false;
|
|
551
|
-
let stripStartX = 0;
|
|
552
|
-
let stripStartScroll = 0;
|
|
553
|
-
let edgeFadeRaf = 0;
|
|
554
|
-
|
|
555
|
-
function getPeerMaxScroll() {
|
|
556
|
-
const pills = [...peerClusterEl.querySelectorAll('.clado-peer-pill')];
|
|
557
|
-
if (!pills.length) return 0;
|
|
558
|
-
let totalW = 0;
|
|
559
|
-
for (const p of pills) totalW += p.offsetWidth;
|
|
560
|
-
totalW += 6 * Math.max(0, pills.length - 1);
|
|
561
|
-
return Math.max(0, totalW - peerClusterEl.clientWidth);
|
|
208
|
+
function closePopover() {
|
|
209
|
+
popoverEl.hidden = true;
|
|
210
|
+
popoverEl.replaceChildren();
|
|
562
211
|
}
|
|
563
212
|
|
|
564
|
-
function
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
213
|
+
function openModelPopover() {
|
|
214
|
+
popoverEl.replaceChildren();
|
|
215
|
+
const models = meta?.configuredModels || [];
|
|
216
|
+
if (!models.length) {
|
|
217
|
+
const empty = document.createElement('button');
|
|
218
|
+
empty.type = 'button';
|
|
219
|
+
empty.className = 'clado-pop-item';
|
|
220
|
+
empty.innerHTML = '<span>尚未配置供应商密钥</span><span class="clado-chip clado-chip-sky">去设置 →</span>';
|
|
221
|
+
empty.onclick = () => { closePopover(); openSettings('models'); };
|
|
222
|
+
popoverEl.append(empty);
|
|
223
|
+
} else {
|
|
224
|
+
for (const m of models.slice(0, 12)) {
|
|
225
|
+
const item = document.createElement('button');
|
|
226
|
+
item.type = 'button';
|
|
227
|
+
item.className = 'clado-pop-item';
|
|
228
|
+
const active = (meta?.defaultProvider === m.provider && meta?.defaultModel === m.model);
|
|
229
|
+
item.innerHTML = `<span style="font-family:ui-monospace,monospace;">${esc(m.model)}</span><span class="clado-chip ${active ? 'clado-chip-sky' : 'clado-chip-neutral'}">${esc(m.provider)}</span>`;
|
|
230
|
+
item.onclick = async () => {
|
|
231
|
+
closePopover();
|
|
232
|
+
await apiConfig({ action: 'set_default_model', provider: m.provider, model: m.model });
|
|
233
|
+
const s = currentSession();
|
|
234
|
+
if (s) s.model = m.id;
|
|
235
|
+
renderStream();
|
|
236
|
+
showToast('默认模型已切换为 ' + m.model);
|
|
237
|
+
};
|
|
238
|
+
popoverEl.append(item);
|
|
239
|
+
}
|
|
240
|
+
const cfg = document.createElement('button');
|
|
241
|
+
cfg.type = 'button';
|
|
242
|
+
cfg.className = 'clado-pop-item';
|
|
243
|
+
cfg.style.borderTop = '1px solid var(--clado-ui-edge)';
|
|
244
|
+
cfg.innerHTML = '<span>管理供应商与更多模型…</span><span>→</span>';
|
|
245
|
+
cfg.onclick = () => { closePopover(); openSettings('models'); };
|
|
246
|
+
popoverEl.append(cfg);
|
|
247
|
+
}
|
|
248
|
+
popoverEl.hidden = false;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function openNewRoleSessionPopover() {
|
|
252
|
+
popoverEl.replaceChildren();
|
|
253
|
+
const roles = meta?.roles || [];
|
|
254
|
+
for (const r of roles) {
|
|
255
|
+
const item = document.createElement('button');
|
|
256
|
+
item.type = 'button';
|
|
257
|
+
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'}">新建</span>`;
|
|
259
|
+
item.onclick = async () => {
|
|
260
|
+
closePopover();
|
|
261
|
+
const res = await fetch(withWs('/library/agent/sessions'), {
|
|
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
|
+
}
|
|
274
|
+
};
|
|
275
|
+
popoverEl.append(item);
|
|
276
|
+
}
|
|
277
|
+
const manage = document.createElement('button');
|
|
278
|
+
manage.type = 'button';
|
|
279
|
+
manage.className = 'clado-pop-item';
|
|
280
|
+
manage.style.borderTop = '1px solid var(--clado-ui-edge)';
|
|
281
|
+
manage.innerHTML = '<span>自定义更多角色…</span><span>→</span>';
|
|
282
|
+
manage.onclick = () => { closePopover(); openSettings('roles'); };
|
|
283
|
+
popoverEl.append(manage);
|
|
284
|
+
popoverEl.hidden = false;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function updateSlashPopover() {
|
|
288
|
+
const val = inputEl.value;
|
|
289
|
+
if (!val.startsWith('/')) {
|
|
290
|
+
if (!popoverEl.hidden && popoverEl.dataset.kind === 'slash') closePopover();
|
|
291
|
+
return;
|
|
584
292
|
}
|
|
293
|
+
const q = val.slice(1).toLowerCase();
|
|
294
|
+
const prompts = (meta?.ecosystem?.prompts || []).filter(p => !q || p.name.toLowerCase().includes(q));
|
|
295
|
+
if (!prompts.length) { closePopover(); return; }
|
|
296
|
+
popoverEl.dataset.kind = 'slash';
|
|
297
|
+
popoverEl.replaceChildren();
|
|
298
|
+
for (const p of prompts.slice(0, 8)) {
|
|
299
|
+
const btn = document.createElement('button');
|
|
300
|
+
btn.type = 'button';
|
|
301
|
+
btn.className = 'clado-pop-item';
|
|
302
|
+
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
|
+
btn.onclick = () => {
|
|
304
|
+
inputEl.value = '/' + p.name + ' ';
|
|
305
|
+
closePopover();
|
|
306
|
+
inputEl.focus();
|
|
307
|
+
};
|
|
308
|
+
popoverEl.append(btn);
|
|
309
|
+
}
|
|
310
|
+
popoverEl.hidden = false;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// =========================================================================
|
|
314
|
+
// 2. Streaming Pi Turn & Handoff Execution
|
|
315
|
+
// =========================================================================
|
|
316
|
+
async function streamAgentRequest(payload, targetSession) {
|
|
317
|
+
setDrawerOpen(true);
|
|
318
|
+
const s = targetSession || currentSession();
|
|
319
|
+
if (!s) return;
|
|
320
|
+
activeSessionId = s.id;
|
|
321
|
+
runningSessionId = s.id;
|
|
322
|
+
s.status = 'running';
|
|
323
|
+
s.messages = Array.isArray(s.messages) ? s.messages : [];
|
|
324
|
+
s.messages.push({
|
|
325
|
+
role: 'user',
|
|
326
|
+
text: payload.text || (payload.action === 'handoff' ? '按画布定稿契约开始执行' : ''),
|
|
327
|
+
handoffFrom: payload.fromRoleName || '',
|
|
328
|
+
});
|
|
329
|
+
const liveAssistant = { role: 'assistant', text: '', tools: [], question: null };
|
|
330
|
+
s.messages.push(liveAssistant);
|
|
331
|
+
sendBtn.textContent = '停止';
|
|
332
|
+
renderRoleStrip();
|
|
333
|
+
renderStream();
|
|
585
334
|
|
|
586
|
-
const
|
|
587
|
-
|
|
588
|
-
const leftZone = 36;
|
|
589
|
-
const rightZone = 44;
|
|
590
|
-
|
|
591
|
-
peerClusterEl.querySelectorAll('.clado-peer-pill').forEach(pill => {
|
|
592
|
-
const r = pill.getBoundingClientRect();
|
|
593
|
-
if (r.width <= 0) return;
|
|
594
|
-
const relLeft = r.left - boxRect.left;
|
|
595
|
-
const relRight = r.right - boxRect.left;
|
|
335
|
+
const ctrl = new AbortController();
|
|
336
|
+
activeAbort = ctrl;
|
|
596
337
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
338
|
+
try {
|
|
339
|
+
const res = await fetch(withWs('/library/agent'), {
|
|
340
|
+
method: 'POST',
|
|
341
|
+
headers: { 'content-type': 'application/json' },
|
|
342
|
+
body: JSON.stringify(payload),
|
|
343
|
+
signal: ctrl.signal,
|
|
344
|
+
});
|
|
345
|
+
if (!res.ok) {
|
|
346
|
+
const err = await res.json().catch(() => ({}));
|
|
347
|
+
throw new Error(err.error || '请求失败');
|
|
605
348
|
}
|
|
606
|
-
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
349
|
+
const reader = res.body.getReader();
|
|
350
|
+
const decoder = new TextDecoder();
|
|
351
|
+
let buf = '';
|
|
352
|
+
while (true) {
|
|
353
|
+
const { done, value } = await reader.read();
|
|
354
|
+
if (done) break;
|
|
355
|
+
buf += decoder.decode(value, { stream: true });
|
|
356
|
+
const lines = buf.split('\n');
|
|
357
|
+
buf = lines.pop() || '';
|
|
358
|
+
for (const line of lines) {
|
|
359
|
+
if (!line.trim()) continue;
|
|
360
|
+
let ev;
|
|
361
|
+
try { ev = JSON.parse(line); } catch { continue; }
|
|
362
|
+
if (ev.type === 'text') {
|
|
363
|
+
liveAssistant.text += ev.text || '';
|
|
364
|
+
renderStream();
|
|
365
|
+
} else if (ev.type === 'tool') {
|
|
366
|
+
const existing = liveAssistant.tools.find(t => t.id === ev.id);
|
|
367
|
+
if (existing) existing.status = ev.status;
|
|
368
|
+
else liveAssistant.tools.push({ id: ev.id, name: ev.name || ev.title, status: ev.status });
|
|
369
|
+
renderStream();
|
|
370
|
+
} else if (ev.type === 'ask_user') {
|
|
371
|
+
liveAssistant.question = { questionId: ev.questionId, question: ev.question, options: ev.options || [], answered: false };
|
|
372
|
+
renderStream();
|
|
373
|
+
} else if (ev.type === 'focus') {
|
|
374
|
+
actions.focusCanvas?.(ev.file, ev.heading);
|
|
375
|
+
} else if (ev.type === 'status') {
|
|
376
|
+
showToast(ev.text);
|
|
377
|
+
} else if (ev.type === 'error') {
|
|
378
|
+
liveAssistant.text += (liveAssistant.text ? '\n\n' : '') + '提示:' + (ev.message || '执行失败');
|
|
379
|
+
renderStream();
|
|
380
|
+
}
|
|
613
381
|
}
|
|
614
|
-
return;
|
|
615
382
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const r1 = (W - relLeft).toFixed(1);
|
|
621
|
-
let grad;
|
|
622
|
-
if (touchLeft && touchRight) {
|
|
623
|
-
grad = `linear-gradient(90deg, transparent ${l0}px, #000 ${l1}px, #000 ${r0}px, transparent ${r1}px)`;
|
|
624
|
-
} else if (touchLeft) {
|
|
625
|
-
grad = `linear-gradient(90deg, transparent ${l0}px, #000 ${l1}px)`;
|
|
626
|
-
} else {
|
|
627
|
-
grad = `linear-gradient(90deg, #000 ${r0}px, transparent ${r1}px)`;
|
|
383
|
+
} catch (err) {
|
|
384
|
+
if (err.name !== 'AbortError') {
|
|
385
|
+
liveAssistant.text += (liveAssistant.text ? '\n\n' : '') + (err.message || '执行中断');
|
|
386
|
+
renderStream();
|
|
628
387
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
388
|
+
} finally {
|
|
389
|
+
s.status = 'idle';
|
|
390
|
+
runningSessionId = '';
|
|
391
|
+
activeAbort = null;
|
|
392
|
+
sendBtn.textContent = '发送';
|
|
393
|
+
await refreshMeta();
|
|
394
|
+
}
|
|
632
395
|
}
|
|
633
396
|
|
|
634
|
-
function
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
397
|
+
async function handleSend() {
|
|
398
|
+
if (runningSessionId) {
|
|
399
|
+
activeAbort?.abort();
|
|
400
|
+
await fetch(withWs('/library/agent'), {
|
|
401
|
+
method: 'POST',
|
|
402
|
+
headers: { 'content-type': 'application/json' },
|
|
403
|
+
body: JSON.stringify({ action: 'cancel', session: runningSessionId }),
|
|
404
|
+
}).catch(() => {});
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const text = inputEl.value.trim();
|
|
408
|
+
if (!text) return;
|
|
409
|
+
inputEl.value = '';
|
|
410
|
+
closePopover();
|
|
411
|
+
const s = currentSession();
|
|
412
|
+
if (!s) return;
|
|
413
|
+
const canvas = actions.readContext ? actions.readContext() : {};
|
|
414
|
+
await streamAgentRequest({
|
|
415
|
+
action: 'prompt',
|
|
416
|
+
session: s.id,
|
|
417
|
+
roleId: s.roleId,
|
|
418
|
+
model: s.model || undefined,
|
|
419
|
+
text,
|
|
420
|
+
canvas,
|
|
421
|
+
}, s);
|
|
642
422
|
}
|
|
643
423
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
if (
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
424
|
+
async function triggerHandoff(targetRoleId, customNote = '') {
|
|
425
|
+
const from = currentSession();
|
|
426
|
+
const targetRole = (meta?.roles || []).find(r => r.id === targetRoleId) || { id: targetRoleId, name: targetRoleId };
|
|
427
|
+
let targetSession = sessions.find(s => !s.archived && s.roleId === targetRole.id);
|
|
428
|
+
if (!targetSession) {
|
|
429
|
+
const res = await fetch(withWs('/library/agent/sessions'), {
|
|
430
|
+
method: 'POST',
|
|
431
|
+
headers: { 'content-type': 'application/json' },
|
|
432
|
+
body: JSON.stringify({ roleId: targetRole.id, title: targetRole.name }),
|
|
433
|
+
});
|
|
434
|
+
const data = await res.json();
|
|
435
|
+
targetSession = data.session;
|
|
436
|
+
if (targetSession) sessions.push(targetSession);
|
|
437
|
+
}
|
|
438
|
+
const canvas = actions.readContext ? actions.readContext() : {};
|
|
439
|
+
showToast(`已交接给「${targetRole.name}」执行`);
|
|
440
|
+
await streamAgentRequest({
|
|
441
|
+
action: 'handoff',
|
|
442
|
+
fromSession: from?.id,
|
|
443
|
+
fromRoleName: from?.title || '画布定稿',
|
|
444
|
+
targetRoleId: targetRole.id,
|
|
445
|
+
targetSession: targetSession?.id,
|
|
446
|
+
text: customNote,
|
|
447
|
+
canvas,
|
|
448
|
+
}, targetSession);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// Bind dock events
|
|
452
|
+
dock.querySelector('[data-toggle-drawer]').onclick = () => setDrawerOpen(!drawerOpen);
|
|
453
|
+
dock.querySelector('[data-collapse]').onclick = () => setDrawerOpen(false);
|
|
454
|
+
dock.querySelector('[data-rollback]').onclick = async () => {
|
|
455
|
+
const s = currentSession();
|
|
456
|
+
if (!s) return;
|
|
457
|
+
const res = await fetch(withWs('/library/agent/sessions'), {
|
|
458
|
+
method: 'POST',
|
|
459
|
+
headers: { 'content-type': 'application/json' },
|
|
460
|
+
body: JSON.stringify({ action: 'rollback', id: s.id }),
|
|
461
|
+
});
|
|
462
|
+
const data = await res.json();
|
|
463
|
+
if (!res.ok) showToast(data.error || '暂无可回退快照');
|
|
464
|
+
else showToast('已回退画布 ' + data.file);
|
|
465
|
+
};
|
|
466
|
+
dock.querySelectorAll('[data-quick-handoff]').forEach(btn => {
|
|
467
|
+
btn.onclick = () => triggerHandoff(btn.dataset.quickHandoff);
|
|
659
468
|
});
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
469
|
+
modelChip.onclick = e => {
|
|
470
|
+
e.stopPropagation();
|
|
471
|
+
if (!popoverEl.hidden && popoverEl.dataset.kind !== 'slash') closePopover();
|
|
472
|
+
else { popoverEl.dataset.kind = 'model'; openModelPopover(); }
|
|
663
473
|
};
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
474
|
+
inputEl.addEventListener('input', updateSlashPopover);
|
|
475
|
+
inputEl.addEventListener('keydown', e => {
|
|
476
|
+
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); }
|
|
477
|
+
if (e.key === 'Escape') closePopover();
|
|
478
|
+
});
|
|
479
|
+
sendBtn.onclick = handleSend;
|
|
480
|
+
document.addEventListener('click', e => { if (!dock.contains(e.target)) closePopover(); });
|
|
481
|
+
|
|
482
|
+
// =========================================================================
|
|
483
|
+
// 3. Unified 5-Tab Settings Center Modal
|
|
484
|
+
// =========================================================================
|
|
485
|
+
const settingsMask = document.createElement('div');
|
|
486
|
+
settingsMask.className = 'clado-vnext-mask';
|
|
487
|
+
settingsMask.id = 'clado-settings-modal';
|
|
488
|
+
settingsMask.hidden = true;
|
|
489
|
+
settingsMask.innerHTML = `
|
|
490
|
+
<div class="clado-settings-shell">
|
|
491
|
+
<aside class="clado-settings-nav">
|
|
492
|
+
<div>
|
|
493
|
+
<div style="padding:4px 10px 14px;">
|
|
494
|
+
<div style="font-size:14.5px;font-weight:630;">设置中心</div>
|
|
495
|
+
<div style="font-family:ui-monospace,monospace;font-size:11px;color:var(--clado-ui-subtle);margin-top:2px;">Pi 1.0 + Clado</div>
|
|
496
|
+
</div>
|
|
497
|
+
<div class="clado-snav-list">
|
|
498
|
+
<button type="button" class="clado-snav-btn" data-stab="models">${ICONS.cpu}<span>模型与供应商</span></button>
|
|
499
|
+
<button type="button" class="clado-snav-btn" data-stab="roles">${ICONS.users}<span>角色与模板</span></button>
|
|
500
|
+
<button type="button" class="clado-snav-btn" data-stab="extensions">${ICONS.box}<span>扩展与能力</span></button>
|
|
501
|
+
<button type="button" class="clado-snav-btn" data-stab="memory">${ICONS.book}<span>工作区与记忆</span></button>
|
|
502
|
+
<button type="button" class="clado-snav-btn" data-stab="appearance">${ICONS.palette}<span>外观与连接</span></button>
|
|
503
|
+
</div>
|
|
504
|
+
</div>
|
|
505
|
+
<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
|
+
</aside>
|
|
507
|
+
<main class="clado-settings-body" data-sbody></main>
|
|
508
|
+
</div>
|
|
509
|
+
`;
|
|
510
|
+
stageRoot().append(settingsMask);
|
|
511
|
+
const sBody = settingsMask.querySelector('[data-sbody]');
|
|
512
|
+
|
|
513
|
+
settingsMask.addEventListener('click', e => { if (e.target === settingsMask) settingsMask.hidden = true; });
|
|
514
|
+
settingsMask.querySelector('[data-close-settings]').onclick = () => { settingsMask.hidden = true; };
|
|
515
|
+
settingsMask.querySelectorAll('[data-stab]').forEach(btn => {
|
|
516
|
+
btn.onclick = () => { settingsTab = btn.dataset.stab; renderSettings(); };
|
|
517
|
+
});
|
|
673
518
|
|
|
674
|
-
function
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
});
|
|
680
|
-
let pTimer = null;
|
|
681
|
-
let pStartX = 0;
|
|
682
|
-
btn.addEventListener('pointerdown', e => {
|
|
683
|
-
if (e.button === 2) return;
|
|
684
|
-
pStartX = e.clientX;
|
|
685
|
-
pTimer = setTimeout(() => {
|
|
686
|
-
pTimer = null;
|
|
687
|
-
openSessionContextMenu(getSessionItem(), e.clientX, e.clientY);
|
|
688
|
-
}, 440);
|
|
689
|
-
});
|
|
690
|
-
btn.addEventListener('pointermove', e => {
|
|
691
|
-
if (pTimer && Math.abs(e.clientX - pStartX) > 6) {
|
|
692
|
-
clearTimeout(pTimer);
|
|
693
|
-
pTimer = null;
|
|
694
|
-
}
|
|
519
|
+
async function apiConfig(body) {
|
|
520
|
+
const res = await fetch(withWs('/library/agent/config'), {
|
|
521
|
+
method: 'POST',
|
|
522
|
+
headers: { 'content-type': 'application/json' },
|
|
523
|
+
body: JSON.stringify(body),
|
|
695
524
|
});
|
|
696
|
-
|
|
697
|
-
|
|
525
|
+
const data = await res.json();
|
|
526
|
+
if (!res.ok) throw new Error(data.error || '保存失败');
|
|
527
|
+
if (data.meta) applyMeta(data.meta);
|
|
528
|
+
return data;
|
|
698
529
|
}
|
|
699
530
|
|
|
700
|
-
function
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
btn.dataset.sessionId = s.id;
|
|
707
|
-
btn.setAttribute('role', 'tab');
|
|
708
|
-
btn.innerHTML = '<span class="p-name"></span><span class="p-live"></span>';
|
|
709
|
-
bindPillGestures(btn, () => sessionsList.find(x => x.id === s.id) || s);
|
|
710
|
-
btn.addEventListener('click', () => {
|
|
711
|
-
if (stripMoved) return;
|
|
712
|
-
if (singlePanelOpen && session === s.id) closeSinglePanel();
|
|
713
|
-
else openSinglePanel(s.id);
|
|
714
|
-
});
|
|
715
|
-
pillDomMap.set(s.id, btn);
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
const pMeta = PERSONA_META[s.persona] || PERSONA_META.architect;
|
|
719
|
-
const pal = PALETTES[s.pal || pMeta.pal] || PALETTES.blue;
|
|
720
|
-
btn.style.setProperty('--c-muted', pal.muted);
|
|
721
|
-
btn.style.setProperty('--c-vivid', pal.vivid);
|
|
722
|
-
btn.style.setProperty('--c-glow', pal.glow);
|
|
531
|
+
function openSettings(tab = 'extensions') {
|
|
532
|
+
settingsTab = tab || settingsTab;
|
|
533
|
+
settingsMask.hidden = false;
|
|
534
|
+
renderSettings();
|
|
535
|
+
refreshMeta().then(() => { if (!settingsMask.hidden) renderSettings(); });
|
|
536
|
+
}
|
|
723
537
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
538
|
+
function renderSettings() {
|
|
539
|
+
settingsMask.querySelectorAll('[data-stab]').forEach(b => b.classList.toggle('active', b.dataset.stab === settingsTab));
|
|
540
|
+
sBody.replaceChildren();
|
|
541
|
+
if (!meta) {
|
|
542
|
+
sBody.innerHTML = '<div style="color:var(--clado-ui-muted);padding:24px;">正在同步 Pi 1.0 配置…</div>';
|
|
543
|
+
return;
|
|
730
544
|
}
|
|
545
|
+
if (settingsTab === 'models') renderModelsTab();
|
|
546
|
+
else if (settingsTab === 'roles') renderRolesTab();
|
|
547
|
+
else if (settingsTab === 'extensions') renderExtensionsTab();
|
|
548
|
+
else if (settingsTab === 'memory') renderMemoryTab();
|
|
549
|
+
else renderAppearanceTab();
|
|
550
|
+
}
|
|
731
551
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
552
|
+
function renderModelsTab() {
|
|
553
|
+
sBody.innerHTML = `
|
|
554
|
+
<div>
|
|
555
|
+
<div style="font-size:18px;font-weight:630;">模型与供应商</div>
|
|
556
|
+
<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>,统一管理官方模型、中转站与本地 Ollama。</div>
|
|
557
|
+
</div>
|
|
558
|
+
<div data-provider-list style="display:flex;flex-direction:column;gap:10px;"></div>
|
|
559
|
+
`;
|
|
560
|
+
const list = sBody.querySelector('[data-provider-list]');
|
|
561
|
+
for (const p of meta.providers || []) {
|
|
562
|
+
const card = document.createElement('div');
|
|
563
|
+
card.className = 'clado-well-box';
|
|
564
|
+
const isEditing = editingProviderId === p.id;
|
|
565
|
+
card.innerHTML = `
|
|
566
|
+
<div class="clado-setting-row">
|
|
567
|
+
<div>
|
|
568
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
569
|
+
<span style="font-size:13.5px;font-weight:610;">${esc(p.name)}</span>
|
|
570
|
+
${p.configured ? `<span class="clado-chip clado-chip-mint">已连接${p.maskedKey ? ' · ' + esc(p.maskedKey) : ''}</span>` : '<span class="clado-chip clado-chip-neutral">未配置</span>'}
|
|
571
|
+
${meta.defaultProvider === p.id ? `<span class="clado-chip clado-chip-sky">默认 · ${esc(meta.defaultModel)}</span>` : ''}
|
|
572
|
+
</div>
|
|
573
|
+
<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>
|
|
574
|
+
</div>
|
|
575
|
+
<button type="button" class="clado-ui-button" data-edit style="border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);">${isEditing ? '收起' : '配置'}</button>
|
|
576
|
+
</div>
|
|
577
|
+
${isEditing ? `
|
|
578
|
+
<div style="margin-top:12px;padding-top:12px;border-top:1px solid var(--clado-ui-edge);display:grid;gap:8px;">
|
|
579
|
+
${!p.keyless ? `<input class="clado-field" data-f-key type="password" placeholder="API Key(留空保持不变)" value="${esc(p.maskedKey)}" />` : ''}
|
|
580
|
+
<input class="clado-field" data-f-url type="text" placeholder="Base URL(可选自定义代理地址)" value="${esc(p.baseUrl)}" />
|
|
581
|
+
<input class="clado-field" data-f-model type="text" placeholder="默认模型 ID(如 ${esc(p.defaultModel || 'claude-sonnet-4-5')})" value="${esc(p.defaultModel)}" />
|
|
582
|
+
<div style="display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:4px;">
|
|
583
|
+
${p.configured ? '<button type="button" class="clado-ui-button" data-del style="color:#be123c;">清除凭据</button>' : '<span></span>'}
|
|
584
|
+
<button type="button" class="clado-ui-button clado-ui-button-primary" data-save>保存并设为默认</button>
|
|
585
|
+
</div>
|
|
586
|
+
</div>
|
|
587
|
+
` : ''}
|
|
588
|
+
`;
|
|
589
|
+
card.querySelector('[data-edit]').onclick = () => {
|
|
590
|
+
editingProviderId = isEditing ? '' : p.id;
|
|
591
|
+
renderSettings();
|
|
592
|
+
};
|
|
593
|
+
if (isEditing) {
|
|
594
|
+
card.querySelector('[data-save]').onclick = async () => {
|
|
595
|
+
try {
|
|
596
|
+
await apiConfig({
|
|
597
|
+
action: 'save_provider',
|
|
598
|
+
providerId: p.id,
|
|
599
|
+
api: p.api,
|
|
600
|
+
apiKey: card.querySelector('[data-f-key]')?.value || '',
|
|
601
|
+
baseUrl: card.querySelector('[data-f-url]')?.value || '',
|
|
602
|
+
defaultModel: card.querySelector('[data-f-model]')?.value || '',
|
|
603
|
+
setAsDefault: true,
|
|
604
|
+
});
|
|
605
|
+
editingProviderId = '';
|
|
606
|
+
renderSettings();
|
|
607
|
+
showToast('已保存 ' + p.name + ' 并写入 Pi 原生配置');
|
|
608
|
+
} catch (e) { showToast(e.message); }
|
|
609
|
+
};
|
|
610
|
+
const delBtn = card.querySelector('[data-del]');
|
|
611
|
+
if (delBtn) delBtn.onclick = async () => {
|
|
612
|
+
await apiConfig({ action: 'delete_provider', providerId: p.id });
|
|
613
|
+
editingProviderId = '';
|
|
614
|
+
renderSettings();
|
|
615
|
+
showToast('已清除 ' + p.name + ' 配置');
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
list.append(card);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
739
621
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
622
|
+
function renderRolesTab() {
|
|
623
|
+
sBody.innerHTML = `
|
|
624
|
+
<div class="clado-setting-row">
|
|
625
|
+
<div>
|
|
626
|
+
<div style="font-size:18px;font-weight:630;">角色与模板</div>
|
|
627
|
+
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">定义各阶段的专业角色(系统提示词、阶段标签、可选专属模型)。</div>
|
|
628
|
+
</div>
|
|
629
|
+
<button type="button" class="clado-ui-button clado-ui-button-primary" data-add-role>+ 新建角色</button>
|
|
630
|
+
</div>
|
|
631
|
+
<div data-role-form class="clado-well-box" hidden style="display:none;flex-direction:column;gap:8px;">
|
|
632
|
+
<div style="display:grid;grid-template-columns:1fr 1fr;gap:8px;">
|
|
633
|
+
<input class="clado-field" data-r-name placeholder="角色名称(如:安全审计专家)" />
|
|
634
|
+
<input class="clado-field" data-r-phase placeholder="阶段标签(如:审计阶段)" />
|
|
635
|
+
</div>
|
|
636
|
+
<input class="clado-field" data-r-desc placeholder="一句话职责描述" />
|
|
637
|
+
<textarea class="clado-field" data-r-prompt rows="3" placeholder="系统提示词(决定该角色如何协作修改画布或执行代码)"></textarea>
|
|
638
|
+
<div style="display:flex;justify-content:flex-end;gap:8px;">
|
|
639
|
+
<button type="button" class="clado-ui-button" data-r-cancel>取消</button>
|
|
640
|
+
<button type="button" class="clado-ui-button clado-ui-button-primary" data-r-save>保存角色</button>
|
|
641
|
+
</div>
|
|
642
|
+
</div>
|
|
643
|
+
<div data-role-grid style="display:grid;grid-template-columns:1fr 1fr;gap:12px;"></div>
|
|
644
|
+
`;
|
|
645
|
+
const form = sBody.querySelector('[data-role-form]');
|
|
646
|
+
sBody.querySelector('[data-add-role]').onclick = () => { form.hidden = false; form.style.display = 'flex'; };
|
|
647
|
+
sBody.querySelector('[data-r-cancel]').onclick = () => { form.hidden = true; form.style.display = 'none'; };
|
|
648
|
+
sBody.querySelector('[data-r-save]').onclick = async () => {
|
|
649
|
+
try {
|
|
650
|
+
await apiConfig({
|
|
651
|
+
action: 'save_role',
|
|
652
|
+
name: form.querySelector('[data-r-name]').value,
|
|
653
|
+
phase: form.querySelector('[data-r-phase]').value,
|
|
654
|
+
description: form.querySelector('[data-r-desc]').value,
|
|
655
|
+
systemPrompt: form.querySelector('[data-r-prompt]').value,
|
|
656
|
+
});
|
|
657
|
+
renderSettings();
|
|
658
|
+
showToast('已保存自定义角色');
|
|
659
|
+
} catch (e) { showToast(e.message); }
|
|
660
|
+
};
|
|
661
|
+
const grid = sBody.querySelector('[data-role-grid]');
|
|
662
|
+
for (const r of meta.roles || []) {
|
|
663
|
+
const card = document.createElement('div');
|
|
664
|
+
card.className = 'clado-well-box';
|
|
665
|
+
card.innerHTML = `
|
|
666
|
+
<div style="display:flex;align-items:center;justify-content:space-between;gap:8px;">
|
|
667
|
+
<span style="font-weight:610;font-size:13.5px;">${esc(r.name)}</span>
|
|
668
|
+
<span class="clado-chip ${TONE_CHIP[r.tone] || 'clado-chip-sky'}">${esc(r.phase)}</span>
|
|
669
|
+
</div>
|
|
670
|
+
<div style="font-size:12px;color:var(--clado-ui-muted);margin-top:6px;line-height:1.55;">${esc(r.description)}</div>
|
|
671
|
+
${!r.builtin ? '<div style="margin-top:10px;text-align:right;"><button type="button" class="clado-ui-button" data-del-role style="font-size:11.5px;color:#be123c;min-height:26px;">删除</button></div>' : ''}
|
|
672
|
+
`;
|
|
673
|
+
const del = card.querySelector('[data-del-role]');
|
|
674
|
+
if (del) del.onclick = async () => { await apiConfig({ action: 'delete_role', id: r.id }); renderSettings(); showToast('已删除角色'); };
|
|
675
|
+
grid.append(card);
|
|
676
|
+
}
|
|
743
677
|
}
|
|
744
678
|
|
|
745
|
-
function
|
|
746
|
-
const
|
|
747
|
-
|
|
679
|
+
function renderExtensionsTab() {
|
|
680
|
+
const eco = meta.ecosystem || { packages: [], mcpServers: [], skills: [], prompts: [] };
|
|
681
|
+
const comps = meta.canvasComponents || [];
|
|
682
|
+
sBody.innerHTML = `
|
|
683
|
+
<div class="clado-setting-row">
|
|
684
|
+
<div>
|
|
685
|
+
<div style="font-size:18px;font-weight:630;">扩展与能力</div>
|
|
686
|
+
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">原生融合 Pi 1.0 插件生态(Pi Packages / MCP / Skills / Commands)与 Clado 空间画布组件。</div>
|
|
687
|
+
</div>
|
|
688
|
+
<div style="display:flex;gap:7px;">
|
|
689
|
+
<button type="button" class="clado-ui-button" data-add-mcp style="border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);">+ MCP</button>
|
|
690
|
+
<button type="button" class="clado-ui-button clado-ui-button-primary" data-add-pkg>+ 安装 Pi 扩展</button>
|
|
691
|
+
</div>
|
|
692
|
+
</div>
|
|
693
|
+
<div class="clado-well-box clado-setting-row" style="padding:10px 14px;font-size:11.5px;color:var(--clado-ui-muted);">
|
|
694
|
+
<span>自动同步目录:<code style="font-family:ui-monospace,monospace;color:var(--clado-ui-text);">${esc(meta.agentDir)}</code> 与项目 <code style="font-family:ui-monospace,monospace;color:var(--clado-ui-text);">.pi/</code></span>
|
|
695
|
+
<button type="button" class="clado-dock-mini-btn" data-rescan>刷新扫描</button>
|
|
696
|
+
</div>
|
|
697
|
+
<div data-ext-list style="display:flex;flex-direction:column;gap:10px;"></div>
|
|
698
|
+
`;
|
|
748
699
|
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
700
|
+
sBody.querySelector('[data-rescan]').onclick = async () => { await refreshMeta(); renderSettings(); showToast('已重新扫描 Pi 扩展与 MCP'); };
|
|
701
|
+
sBody.querySelector('[data-add-pkg]').onclick = async () => {
|
|
702
|
+
const src = window.prompt('输入 Pi Package 地址(支持 npm:包名 或 git:仓库地址):', 'npm:');
|
|
703
|
+
if (!src || src === 'npm:') return;
|
|
704
|
+
try {
|
|
705
|
+
showToast('正在安装 Pi 扩展…');
|
|
706
|
+
await apiConfig({ action: 'install_pi_package', source: src });
|
|
707
|
+
renderSettings();
|
|
708
|
+
showToast('已安装 Pi 扩展:' + src);
|
|
709
|
+
} catch (e) { showToast(e.message); }
|
|
710
|
+
};
|
|
711
|
+
sBody.querySelector('[data-add-mcp]').onclick = async () => {
|
|
712
|
+
const raw = window.prompt('粘贴 mcp.json 中的服务器 JSON(或输入单个服务器名称,稍后在 ~/.pi/agent/mcp.json 编辑):', '{"github":{"command":"npx","args":["-y","@modelcontextprotocol/server-github"]}}');
|
|
713
|
+
if (!raw) return;
|
|
714
|
+
try {
|
|
715
|
+
await apiConfig({ action: 'import_mcp_json', json: raw });
|
|
716
|
+
renderSettings();
|
|
717
|
+
showToast('已导入至 Pi 原生 mcp.json');
|
|
718
|
+
} catch (e) { showToast(e.message); }
|
|
719
|
+
};
|
|
755
720
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
721
|
+
const list = sBody.querySelector('[data-ext-list]');
|
|
722
|
+
// Built-in Clado Bridge
|
|
723
|
+
const bridgeRow = document.createElement('div');
|
|
724
|
+
bridgeRow.className = 'clado-well-box clado-setting-row';
|
|
725
|
+
bridgeRow.innerHTML = `
|
|
726
|
+
<div>
|
|
727
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
728
|
+
<span style="font-size:13.5px;font-weight:610;">clado-canvas-bridge</span>
|
|
729
|
+
<span class="clado-chip clado-chip-sky">内置</span>
|
|
730
|
+
<span class="clado-chip clado-chip-neutral">Pi Extension</span>
|
|
731
|
+
</div>
|
|
732
|
+
<div style="font-size:12px;color:var(--clado-ui-muted);margin-top:4px;">向 Pi 暴露 clado_* 画布读写、便签、决策卡与镜头聚焦工具。</div>
|
|
733
|
+
</div>
|
|
734
|
+
<div class="clado-switch on" style="pointer-events:none;opacity:0.85;"></div>
|
|
735
|
+
`;
|
|
736
|
+
list.append(bridgeRow);
|
|
759
737
|
|
|
760
|
-
|
|
761
|
-
[
|
|
762
|
-
|
|
763
|
-
|
|
738
|
+
// Pi Packages
|
|
739
|
+
for (const pkg of eco.packages || []) {
|
|
740
|
+
const row = document.createElement('div');
|
|
741
|
+
row.className = 'clado-well-box clado-setting-row';
|
|
742
|
+
row.innerHTML = `
|
|
743
|
+
<div>
|
|
744
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
745
|
+
<span style="font-size:13.5px;font-weight:610;">${esc(pkg.source)}</span>
|
|
746
|
+
<span class="clado-chip clado-chip-sky">Pi Package</span>
|
|
747
|
+
<span class="clado-chip clado-chip-neutral">${esc(pkg.scope)}</span>
|
|
748
|
+
</div>
|
|
749
|
+
<div style="font-size:11.5px;color:var(--clado-ui-muted);margin-top:4px;font-family:ui-monospace,monospace;">${esc(pkg.installedPath || 'Pi 托管扩展包')}</div>
|
|
750
|
+
</div>
|
|
751
|
+
<button type="button" class="clado-ui-button" data-rm style="color:#be123c;font-size:12px;">移除</button>
|
|
752
|
+
`;
|
|
753
|
+
row.querySelector('[data-rm]').onclick = async () => {
|
|
754
|
+
await apiConfig({ action: 'remove_pi_package', source: pkg.source, local: pkg.scope === 'project' });
|
|
755
|
+
renderSettings();
|
|
756
|
+
showToast('已移除扩展包');
|
|
757
|
+
};
|
|
758
|
+
list.append(row);
|
|
759
|
+
}
|
|
764
760
|
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
761
|
+
// Pi MCP Servers
|
|
762
|
+
for (const m of eco.mcpServers || []) {
|
|
763
|
+
const row = document.createElement('div');
|
|
764
|
+
row.className = 'clado-well-box clado-setting-row';
|
|
765
|
+
row.innerHTML = `
|
|
766
|
+
<div>
|
|
767
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
768
|
+
<span style="font-size:13.5px;font-weight:610;">${esc(m.name)}</span>
|
|
769
|
+
<span class="clado-chip clado-chip-mint">MCP · ${esc(m.type)}</span>
|
|
770
|
+
<span class="clado-chip clado-chip-neutral">mcp.json</span>
|
|
771
|
+
</div>
|
|
772
|
+
<div style="font-size:12px;color:var(--clado-ui-muted);margin-top:4px;font-family:ui-monospace,monospace;">${esc(m.url || (m.command + ' ' + (m.args || []).join(' ')))}</div>
|
|
773
|
+
</div>
|
|
774
|
+
<div style="display:flex;align-items:center;gap:10px;">
|
|
775
|
+
<button type="button" class="clado-dock-mini-btn" data-del-mcp style="color:#be123c;">删除</button>
|
|
776
|
+
<div class="clado-switch ${m.enabled ? 'on' : ''}" data-tog-mcp></div>
|
|
777
|
+
</div>
|
|
778
|
+
`;
|
|
779
|
+
row.querySelector('[data-tog-mcp]').onclick = async () => {
|
|
780
|
+
await apiConfig({ action: 'toggle_mcp', name: m.name, enabled: !m.enabled });
|
|
781
|
+
renderSettings();
|
|
779
782
|
};
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
if (isSessionActive(s)) activeCount++;
|
|
784
|
-
const btn = ensurePillElement(s);
|
|
785
|
-
peerClusterEl.append(btn);
|
|
786
|
-
}
|
|
787
|
-
const addBtn = document.createElement('button');
|
|
788
|
-
addBtn.type = 'button';
|
|
789
|
-
addBtn.className = 'clado-peer-add-btn';
|
|
790
|
-
addBtn.title = '新建分身或管理会话';
|
|
791
|
-
addBtn.setAttribute('aria-label', '新建分身或管理会话');
|
|
792
|
-
addBtn.textContent = '+';
|
|
793
|
-
addBtn.onclick = ev => {
|
|
794
|
-
ev.stopPropagation();
|
|
795
|
-
if (stripMoved) return;
|
|
796
|
-
const r = addBtn.getBoundingClientRect();
|
|
797
|
-
openSessionContextMenu(null, r.left + r.width / 2, r.top);
|
|
783
|
+
row.querySelector('[data-del-mcp]').onclick = async () => {
|
|
784
|
+
await apiConfig({ action: 'delete_mcp', name: m.name });
|
|
785
|
+
renderSettings();
|
|
798
786
|
};
|
|
799
|
-
|
|
787
|
+
list.append(row);
|
|
800
788
|
}
|
|
801
789
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
setPeerScrollX(peerScrollX);
|
|
790
|
+
// Pi Skills
|
|
791
|
+
for (const sk of eco.skills || []) {
|
|
792
|
+
const row = document.createElement('div');
|
|
793
|
+
row.className = 'clado-well-box clado-setting-row';
|
|
794
|
+
row.innerHTML = `
|
|
795
|
+
<div>
|
|
796
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
797
|
+
<span style="font-size:13.5px;font-weight:610;">${esc(sk.name)}</span>
|
|
798
|
+
<span class="clado-chip clado-chip-violet">SKILL.md</span>
|
|
799
|
+
<span class="clado-chip clado-chip-neutral">${esc(sk.scope)}</span>
|
|
800
|
+
</div>
|
|
801
|
+
<div style="font-size:12px;color:var(--clado-ui-muted);margin-top:4px;">${esc(sk.description || sk.filePath)}</div>
|
|
802
|
+
</div>
|
|
803
|
+
<button type="button" class="clado-dock-mini-btn" data-del-sk style="color:#be123c;">删除</button>
|
|
804
|
+
`;
|
|
805
|
+
row.querySelector('[data-del-sk]').onclick = async () => { await apiConfig({ action: 'delete_skill', name: sk.name }); renderSettings(); };
|
|
806
|
+
list.append(row);
|
|
820
807
|
}
|
|
821
808
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
calledFlashMap.set(item.id, {
|
|
840
|
-
pal: item.calledBy.pal || 'blue',
|
|
841
|
-
until,
|
|
842
|
-
seenAt: item.calledBy.at,
|
|
843
|
-
});
|
|
844
|
-
scheduledClear = Math.max(scheduledClear, 3650);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
sessionsList = incoming;
|
|
849
|
-
renderPeerCluster(animate);
|
|
850
|
-
if (scheduledClear > 0) {
|
|
851
|
-
setTimeout(() => renderPeerCluster(false), scheduledClear);
|
|
809
|
+
// Pi /Prompts
|
|
810
|
+
for (const pr of eco.prompts || []) {
|
|
811
|
+
const row = document.createElement('div');
|
|
812
|
+
row.className = 'clado-well-box clado-setting-row';
|
|
813
|
+
row.innerHTML = `
|
|
814
|
+
<div>
|
|
815
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
816
|
+
<span style="font-size:13.5px;font-weight:610;">/${esc(pr.name)}</span>
|
|
817
|
+
<span class="clado-chip clado-chip-sky">Prompt 命令</span>
|
|
818
|
+
<span class="clado-chip clado-chip-neutral">${esc(pr.scope)}</span>
|
|
819
|
+
</div>
|
|
820
|
+
<div style="font-size:12px;color:var(--clado-ui-muted);margin-top:4px;">${esc(pr.description || pr.filePath)}</div>
|
|
821
|
+
</div>
|
|
822
|
+
<button type="button" class="clado-dock-mini-btn" data-del-pr style="color:#be123c;">删除</button>
|
|
823
|
+
`;
|
|
824
|
+
row.querySelector('[data-del-pr]').onclick = async () => { await apiConfig({ action: 'delete_command', name: pr.name }); renderSettings(); };
|
|
825
|
+
list.append(row);
|
|
852
826
|
}
|
|
853
|
-
}
|
|
854
827
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
828
|
+
// Optional Canvas Components (e.g. Lo-Fi widget)
|
|
829
|
+
for (const c of comps) {
|
|
830
|
+
const row = document.createElement('div');
|
|
831
|
+
row.className = 'clado-well-box clado-setting-row';
|
|
832
|
+
row.innerHTML = `
|
|
833
|
+
<div>
|
|
834
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
835
|
+
<span style="font-size:13.5px;font-weight:610;">${esc(c.name)}</span>
|
|
836
|
+
<span class="clado-chip clado-chip-amber">${esc(c.label || '画布组件')}</span>
|
|
837
|
+
<span class="clado-chip clado-chip-neutral">可选插件</span>
|
|
838
|
+
</div>
|
|
839
|
+
<div style="font-size:12px;color:var(--clado-ui-muted);margin-top:4px;">${esc(c.description)}</div>
|
|
840
|
+
</div>
|
|
841
|
+
<div class="clado-switch ${c.enabled ? 'on' : ''}" data-tog-comp></div>
|
|
842
|
+
`;
|
|
843
|
+
row.querySelector('[data-tog-comp]').onclick = async () => {
|
|
844
|
+
await apiConfig({ action: 'toggle_canvas_component', id: c.id, enabled: !c.enabled });
|
|
845
|
+
renderSettings();
|
|
846
|
+
showToast(c.name + (!c.enabled ? ' 已启用' : ' 已关闭'));
|
|
847
|
+
};
|
|
848
|
+
list.append(row);
|
|
876
849
|
}
|
|
850
|
+
}
|
|
877
851
|
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
cmdWrap.dataset.commandId = candidate.cmd.id;
|
|
886
|
-
cmdWrap.classList.remove('closed');
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
dock.querySelectorAll('[data-cmd-decision]').forEach(btn => {
|
|
890
|
-
btn.onclick = () => {
|
|
891
|
-
if (running) return;
|
|
892
|
-
const targetSid = cmdWrap.dataset.sessionId || session;
|
|
893
|
-
const commandId = cmdWrap.dataset.commandId;
|
|
894
|
-
const cmdText = cmdCode.textContent || '';
|
|
895
|
-
const decision = btn.dataset.cmdDecision;
|
|
896
|
-
if (!commandId) return;
|
|
897
|
-
activePendingCmd = null;
|
|
898
|
-
const rec = sessionRecords.get(targetSid);
|
|
899
|
-
if (rec) rec.pendingCommand = null;
|
|
900
|
-
cmdWrap.classList.add('closed');
|
|
901
|
-
session = targetSid;
|
|
902
|
-
openSinglePanel(targetSid);
|
|
903
|
-
const labelMap = { allow: '允许执行', session_allow: '本会话免审执行', deny: '拒绝执行' };
|
|
904
|
-
streamTurn({
|
|
905
|
-
action: 'command_decision',
|
|
906
|
-
session: targetSid,
|
|
907
|
-
commandId,
|
|
908
|
-
decision,
|
|
909
|
-
mode: workflow === 'dispatch' ? 'design' : workflow,
|
|
910
|
-
execMode,
|
|
911
|
-
persona,
|
|
912
|
-
canvas: readCanvas(),
|
|
913
|
-
viewId,
|
|
914
|
-
}, {
|
|
915
|
-
humanText: `${labelMap[decision] || decision}:${cmdText}`,
|
|
916
|
-
humanLabel: '你(命令审批)',
|
|
917
|
-
});
|
|
918
|
-
};
|
|
919
|
-
});
|
|
920
|
-
|
|
921
|
-
// 8. 长按 / 右键会话菜单(新建、重命名、归档、恢复归档、删除、设置、低优 ACP 分身)
|
|
922
|
-
function closeCtxMenu() {
|
|
923
|
-
ctxMenu.classList.remove('open');
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
function positionCtxMenu(x, y) {
|
|
927
|
-
ctxMenu.style.left = '-999px';
|
|
928
|
-
ctxMenu.style.top = '-999px';
|
|
929
|
-
ctxMenu.classList.add('open');
|
|
930
|
-
const rect = ctxMenu.getBoundingClientRect();
|
|
931
|
-
const left = Math.min(window.innerWidth - rect.width - 10, Math.max(10, x - rect.width / 2));
|
|
932
|
-
const top = Math.max(12, y - rect.height - 12);
|
|
933
|
-
ctxMenu.style.left = left + 'px';
|
|
934
|
-
ctxMenu.style.top = top + 'px';
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
function addCtxHeader(label, sub) {
|
|
938
|
-
const d = document.createElement('div');
|
|
939
|
-
d.className = 'clado-ctx-badge';
|
|
940
|
-
const l = document.createElement('span');
|
|
941
|
-
l.textContent = label;
|
|
942
|
-
const r = document.createElement('span');
|
|
943
|
-
r.style.opacity = '.75';
|
|
944
|
-
r.textContent = sub || '';
|
|
945
|
-
d.append(l, r);
|
|
946
|
-
ctxMenu.append(d);
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
function addCtxItem(text, fn, danger = false) {
|
|
950
|
-
const b = document.createElement('button');
|
|
951
|
-
b.type = 'button';
|
|
952
|
-
b.className = 'clado-ctx-btn' + (danger ? ' danger' : '');
|
|
953
|
-
b.textContent = text;
|
|
954
|
-
b.onclick = ev => {
|
|
955
|
-
ev.stopPropagation();
|
|
956
|
-
closeCtxMenu();
|
|
957
|
-
fn();
|
|
958
|
-
};
|
|
959
|
-
ctxMenu.append(b);
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
async function refreshArchivedSessions() {
|
|
963
|
-
try {
|
|
964
|
-
const res = await fetch(sessionUrl('', { includeArchived: '1' }), { cache: 'no-store' });
|
|
965
|
-
if (!res.ok) return;
|
|
966
|
-
const data = await res.json();
|
|
967
|
-
const all = Array.isArray(data.sessions) ? data.sessions : [];
|
|
968
|
-
archivedList = all.filter(s => s.archived);
|
|
969
|
-
} catch {}
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
async function renameSessionById(id, oldTitle = '') {
|
|
973
|
-
if (!id) return;
|
|
974
|
-
const next = window.prompt('重命名会话:', oldTitle || '新会话');
|
|
975
|
-
if (!next || !next.trim() || next.trim() === oldTitle) return;
|
|
976
|
-
try {
|
|
977
|
-
const res = await fetch(sessionsEndpoint, {
|
|
978
|
-
method: 'POST',
|
|
979
|
-
headers: { 'content-type': 'application/json' },
|
|
980
|
-
body: JSON.stringify({ action: 'rename', id, title: next.trim() }),
|
|
981
|
-
});
|
|
982
|
-
if (res.ok) {
|
|
983
|
-
const { session: updated } = await res.json();
|
|
984
|
-
if (updated) {
|
|
985
|
-
sessionRecords.set(updated.id, updated);
|
|
986
|
-
if (singlePanelOpen && session === updated.id) spName.textContent = updated.title;
|
|
987
|
-
}
|
|
988
|
-
await refreshSessionsList(false);
|
|
989
|
-
showToast('已更新会话名称');
|
|
990
|
-
}
|
|
991
|
-
} catch {}
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
function openSessionContextMenu(targetSession, x, y) {
|
|
995
|
-
ctxMenu.replaceChildren();
|
|
996
|
-
addCtxHeader('会话菜单', targetSession ? (targetSession.title || '当前会话') : '新建与管理');
|
|
997
|
-
addCtxItem('+ 新建架构师分身', () => createNewSession('architect'));
|
|
998
|
-
addCtxItem('+ 新建实现者分身', () => createNewSession('coder'));
|
|
999
|
-
addCtxItem('+ 新建 QA 测试分身', () => createNewSession('qa'));
|
|
1000
|
-
addCtxItem('+ 新建审计官分身', () => createNewSession('auditor'));
|
|
1001
|
-
addCtxItem('⚙ 供应商与模型设置', () => openSettingsOverlay('llm'));
|
|
1002
|
-
addCtxItem('🧩 插件市场', () => window.dispatchEvent(new CustomEvent('clado:open-market')));
|
|
1003
|
-
addCtxItem('⚡ 新建 ACP 子代理(特殊机制)', () => createNewSession('custom', { engine: 'acp', title: 'ACP 子代理' }));
|
|
1004
|
-
|
|
1005
|
-
if (targetSession && targetSession.id) {
|
|
1006
|
-
addCtxItem('✎ 重命名此会话', () => renameSessionById(targetSession.id, targetSession.title));
|
|
1007
|
-
addCtxItem('归档此会话', () => archiveSessionById(targetSession.id));
|
|
1008
|
-
}
|
|
1009
|
-
for (const arch of archivedList.slice(0, 4)) {
|
|
1010
|
-
addCtxItem(`恢复归档:${arch.title || '历史会话'}`, () => unarchiveSessionById(arch.id));
|
|
1011
|
-
}
|
|
1012
|
-
if (targetSession && targetSession.id) {
|
|
1013
|
-
addCtxItem('删除此会话', () => deleteSessionById(targetSession.id), true);
|
|
1014
|
-
}
|
|
1015
|
-
positionCtxMenu(x, y);
|
|
1016
|
-
|
|
1017
|
-
// 异步刷新归档列表供下次或即时使用
|
|
1018
|
-
refreshArchivedSessions();
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
peerClusterEl.addEventListener('contextmenu', e => {
|
|
1022
|
-
if (e.target.closest('.clado-peer-pill')) return;
|
|
1023
|
-
e.preventDefault();
|
|
1024
|
-
openSessionContextMenu(null, e.clientX, e.clientY);
|
|
1025
|
-
});
|
|
1026
|
-
|
|
1027
|
-
async function createNewSession(nextPersona = 'architect', extra = {}) {
|
|
1028
|
-
const pMeta = PERSONA_META[nextPersona] || PERSONA_META.architect;
|
|
1029
|
-
try {
|
|
1030
|
-
const res = await fetch(sessionsEndpoint, {
|
|
1031
|
-
method: 'POST',
|
|
1032
|
-
headers: { 'content-type': 'application/json' },
|
|
1033
|
-
body: JSON.stringify({
|
|
1034
|
-
action: 'create',
|
|
1035
|
-
persona: nextPersona,
|
|
1036
|
-
pal: extra.engine === 'acp' ? 'cyan' : pMeta.pal,
|
|
1037
|
-
engine: extra.engine === 'acp' ? 'acp' : 'builtin',
|
|
1038
|
-
title: extra.title || undefined,
|
|
1039
|
-
mode: pMeta.defaultMode,
|
|
1040
|
-
execMode: nextPersona === 'auditor' ? 'plan' : 'act',
|
|
1041
|
-
}),
|
|
1042
|
-
});
|
|
1043
|
-
if (res.ok) {
|
|
1044
|
-
const { session: created } = await res.json();
|
|
1045
|
-
if (created?.id) {
|
|
1046
|
-
sessionRecords.set(created.id, created);
|
|
1047
|
-
session = created.id;
|
|
1048
|
-
persona = created.persona || nextPersona;
|
|
1049
|
-
execMode = created.execMode || 'act';
|
|
1050
|
-
selectWorkflow(created.mode || pMeta.defaultMode);
|
|
1051
|
-
await refreshSessionsList(true);
|
|
1052
|
-
openSinglePanel(created.id);
|
|
1053
|
-
showToast(`已新建「${created.title}」`);
|
|
1054
|
-
input.focus();
|
|
1055
|
-
return;
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
} catch {}
|
|
1059
|
-
// 离线/兜底本地新建
|
|
1060
|
-
session = crypto.randomUUID();
|
|
1061
|
-
persona = nextPersona;
|
|
1062
|
-
execMode = nextPersona === 'auditor' ? 'plan' : 'act';
|
|
1063
|
-
selectWorkflow(pMeta.defaultMode);
|
|
1064
|
-
log.replaceChildren();
|
|
1065
|
-
openSinglePanel(session);
|
|
1066
|
-
input.focus();
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
async function archiveSessionById(id) {
|
|
1070
|
-
if (!id) return;
|
|
1071
|
-
const target = sessionsList.find(s => s.id === id);
|
|
1072
|
-
try {
|
|
1073
|
-
const res = await fetch(sessionsEndpoint, {
|
|
1074
|
-
method: 'POST',
|
|
1075
|
-
headers: { 'content-type': 'application/json' },
|
|
1076
|
-
body: JSON.stringify({ action: 'archive', id }),
|
|
1077
|
-
});
|
|
1078
|
-
if (res.ok) {
|
|
1079
|
-
if (singlePanelOpen && session === id) closeSinglePanel();
|
|
1080
|
-
await Promise.all([refreshSessionsList(true), refreshArchivedSessions()]);
|
|
1081
|
-
showToast(`已归档「${target?.title || '会话'}」(长按胶囊可恢复)`);
|
|
1082
|
-
}
|
|
1083
|
-
} catch {}
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
async function unarchiveSessionById(id) {
|
|
1087
|
-
if (!id) return;
|
|
1088
|
-
try {
|
|
1089
|
-
const res = await fetch(sessionsEndpoint, {
|
|
1090
|
-
method: 'POST',
|
|
1091
|
-
headers: { 'content-type': 'application/json' },
|
|
1092
|
-
body: JSON.stringify({ action: 'unarchive', id }),
|
|
1093
|
-
});
|
|
1094
|
-
if (res.ok) {
|
|
1095
|
-
const { session: restored } = await res.json();
|
|
1096
|
-
await Promise.all([refreshSessionsList(true), refreshArchivedSessions()]);
|
|
1097
|
-
if (restored?.id) openSinglePanel(restored.id);
|
|
1098
|
-
showToast(`已恢复「${restored?.title || '会话'}」`);
|
|
1099
|
-
}
|
|
1100
|
-
} catch {}
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
async function deleteSessionById(id) {
|
|
1104
|
-
if (!id) return;
|
|
1105
|
-
const target = sessionsList.find(s => s.id === id);
|
|
1106
|
-
try {
|
|
1107
|
-
const res = await fetch(sessionUrl(id), { method: 'DELETE' });
|
|
1108
|
-
if (res.ok) {
|
|
1109
|
-
sessionRecords.delete(id);
|
|
1110
|
-
pillDomMap.delete(id);
|
|
1111
|
-
if (singlePanelOpen && session === id) closeSinglePanel();
|
|
1112
|
-
if (session === id) session = crypto.randomUUID();
|
|
1113
|
-
await refreshSessionsList(true);
|
|
1114
|
-
showToast(`已删除「${target?.title || '会话'}」`);
|
|
1115
|
-
}
|
|
1116
|
-
} catch {}
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
// 9. 单人视角详情抽屉与消息渲染
|
|
1120
|
-
function syncExecModeUI(nextMode) {
|
|
1121
|
-
execMode = nextMode === 'plan' ? 'plan' : 'act';
|
|
1122
|
-
for (const b of execModeBtns) {
|
|
1123
|
-
b.classList.toggle('active', b.dataset.execMode === execMode);
|
|
1124
|
-
}
|
|
1125
|
-
planBannerWrap.classList.toggle('closed', execMode !== 'plan');
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
function renderTodos(todos) {
|
|
1129
|
-
const list = Array.isArray(todos) ? todos : [];
|
|
1130
|
-
if (!list.length) {
|
|
1131
|
-
todoBox.hidden = true;
|
|
1132
|
-
return;
|
|
1133
|
-
}
|
|
1134
|
-
todoBox.hidden = false;
|
|
1135
|
-
const doneCount = list.filter(t => t.status === 'completed').length;
|
|
1136
|
-
const current = list.find(t => t.status === 'in_progress') || list.find(t => t.status !== 'completed') || list.at(-1);
|
|
1137
|
-
const curLabel = current?.text || current?.content || '执行中';
|
|
1138
|
-
todoSummary.textContent = `步骤 ${doneCount}/${list.length} · ${curLabel}`;
|
|
1139
|
-
todoList.replaceChildren();
|
|
1140
|
-
list.forEach((t, i) => {
|
|
1141
|
-
const row = document.createElement('div');
|
|
1142
|
-
const mark = t.status === 'completed' ? '✓' : t.status === 'in_progress' ? '●' : '○';
|
|
1143
|
-
row.textContent = `${mark} ${i + 1}. ${t.text || t.content || ''}`;
|
|
1144
|
-
todoList.append(row);
|
|
1145
|
-
});
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
todoBox.onclick = () => {
|
|
1149
|
-
todoExpanded = !todoExpanded;
|
|
1150
|
-
todoCollapse.classList.toggle('closed', !todoExpanded);
|
|
1151
|
-
todoArrow.textContent = todoExpanded ? '收起 ▴' : '展开 ▾';
|
|
1152
|
-
};
|
|
1153
|
-
|
|
1154
|
-
function showStatus(text) {
|
|
1155
|
-
if (statusEl.textContent !== text) statusEl.textContent = text;
|
|
1156
|
-
statusEl.hidden = !text;
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
|
-
function scrollLog() {
|
|
1160
|
-
log.scrollTop = log.scrollHeight;
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
function canSubmit() {
|
|
1164
|
-
const curRunning = running && streamingSessionId === session;
|
|
1165
|
-
if (curRunning) {
|
|
1166
|
-
// 内置运行时支持实时插话纠偏(Steer)
|
|
1167
|
-
return meta.engine === 'builtin' && Boolean(input.value.trim());
|
|
1168
|
-
}
|
|
1169
|
-
if (running) return false;
|
|
1170
|
-
return workflow === 'dispatch' || workflow === 'audit' || Boolean(input.value.trim());
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
function syncActions() {
|
|
1174
|
-
const anyRunning = running || sessionsList.some(s => !s.archived && s.running);
|
|
1175
|
-
const curSummary = sessionsList.find(s => s.id === session);
|
|
1176
|
-
const curRunning = (running && streamingSessionId === session) || Boolean(curSummary?.running);
|
|
1177
|
-
|
|
1178
|
-
panel.classList.toggle('clado-ai-working', anyRunning);
|
|
1179
|
-
shell.classList.toggle('working', anyRunning);
|
|
1180
|
-
|
|
1181
|
-
stopBtn.hidden = !curRunning;
|
|
1182
|
-
stopBtn.disabled = stopping;
|
|
1183
|
-
|
|
1184
|
-
sendBtn.disabled = !canSubmit();
|
|
1185
|
-
if (curRunning && meta.engine === 'builtin') {
|
|
1186
|
-
sendBtn.textContent = '插话';
|
|
1187
|
-
} else if (workflow === 'dispatch') {
|
|
1188
|
-
sendBtn.textContent = '派发';
|
|
1189
|
-
} else {
|
|
1190
|
-
sendBtn.textContent = '发送';
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
const isDispatch = workflow === 'dispatch';
|
|
1194
|
-
executorWrap.hidden = !isDispatch;
|
|
1195
|
-
executorSelect.disabled = running;
|
|
1196
|
-
executorDropdown.sync();
|
|
1197
|
-
|
|
1198
|
-
const curName = curSummary?.title || PERSONA_META[persona]?.label || '灵感';
|
|
1199
|
-
if (curRunning && meta.engine === 'builtin') {
|
|
1200
|
-
input.placeholder = `向「${curName}」插话纠偏(下一步立即生效)…`;
|
|
1201
|
-
} else if (workflow !== 'design') {
|
|
1202
|
-
input.placeholder = workflowHints[workflow] || defaultPlaceholder;
|
|
1203
|
-
} else if (curSummary) {
|
|
1204
|
-
input.placeholder = `继续与「${curName}」对话(长按会话管理)…`;
|
|
1205
|
-
} else {
|
|
1206
|
-
input.placeholder = defaultPlaceholder;
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
function selectWorkflow(nextWorkflow) {
|
|
1211
|
-
workflow = workflowHints[nextWorkflow] ? nextWorkflow : 'design';
|
|
1212
|
-
for (const b of workflowBtns) {
|
|
1213
|
-
b.classList.toggle('active', b.dataset.workflow === workflow);
|
|
1214
|
-
}
|
|
1215
|
-
syncActions();
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
function createThinkingBlock(initialText = '') {
|
|
1219
|
-
const details = document.createElement('details');
|
|
1220
|
-
details.className = 'clado-agent-thinking';
|
|
1221
|
-
const summary = document.createElement('summary');
|
|
1222
|
-
summary.textContent = '思考过程';
|
|
1223
|
-
const pre = document.createElement('pre');
|
|
1224
|
-
pre.textContent = initialText;
|
|
1225
|
-
details.append(summary, pre);
|
|
1226
|
-
return details;
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
function createChangesRow(items, checkpointId, targetSessionId, rolledBack = false) {
|
|
1230
|
-
const row = document.createElement('div');
|
|
1231
|
-
row.className = 'clado-changes-row';
|
|
1232
|
-
const chips = document.createElement('div');
|
|
1233
|
-
chips.className = 'clado-changes-chips';
|
|
1234
|
-
for (const change of items || []) {
|
|
1235
|
-
const btn = document.createElement('button');
|
|
1236
|
-
btn.type = 'button';
|
|
1237
|
-
btn.className = 'clado-tool-chip';
|
|
1238
|
-
btn.textContent = (change.label || change.file || '画布更新') + ' ↗';
|
|
1239
|
-
btn.onclick = () => focusTarget(change.file, change.node, change.label);
|
|
1240
|
-
chips.append(btn);
|
|
1241
|
-
}
|
|
1242
|
-
row.append(chips);
|
|
1243
|
-
|
|
1244
|
-
if (checkpointId) {
|
|
1245
|
-
const rb = document.createElement('button');
|
|
1246
|
-
rb.type = 'button';
|
|
1247
|
-
rb.className = 'clado-tool-chip rollback' + (rolledBack ? ' done' : '');
|
|
1248
|
-
rb.textContent = rolledBack ? '已回退' : '↺ 回退此轮';
|
|
1249
|
-
rb.disabled = rolledBack;
|
|
1250
|
-
rb.onclick = async () => {
|
|
1251
|
-
if (rb.disabled || running) return;
|
|
1252
|
-
rb.disabled = true;
|
|
1253
|
-
try {
|
|
1254
|
-
const res = await fetch(sessionsEndpoint, {
|
|
1255
|
-
method: 'POST',
|
|
1256
|
-
headers: { 'content-type': 'application/json' },
|
|
1257
|
-
body: JSON.stringify({ action: 'rollback', id: targetSessionId || session, checkpointId }),
|
|
1258
|
-
});
|
|
1259
|
-
if (!res.ok) {
|
|
1260
|
-
const err = await res.json().catch(() => ({}));
|
|
1261
|
-
throw new Error(err.error || '回退失败');
|
|
1262
|
-
}
|
|
1263
|
-
rb.classList.add('done');
|
|
1264
|
-
rb.textContent = '已回退';
|
|
1265
|
-
showToast('已回退此轮画布修改');
|
|
1266
|
-
refreshSessionsList(false);
|
|
1267
|
-
} catch (err) {
|
|
1268
|
-
rb.disabled = false;
|
|
1269
|
-
showToast(err.message || '回退失败');
|
|
1270
|
-
}
|
|
1271
|
-
};
|
|
1272
|
-
row.append(rb);
|
|
1273
|
-
}
|
|
1274
|
-
return row;
|
|
1275
|
-
}
|
|
1276
|
-
|
|
1277
|
-
function createQuestionCard(q, targetSessionId) {
|
|
1278
|
-
const card = document.createElement('div');
|
|
1279
|
-
card.className = 'clado-agent-question' + (q.answered ? ' answered' : '');
|
|
1280
|
-
const badge = document.createElement('div');
|
|
1281
|
-
badge.className = 'clado-agent-question-badge';
|
|
1282
|
-
badge.textContent = q.answered ? '已确认方案' : '需要你拍板';
|
|
1283
|
-
const prompt = document.createElement('div');
|
|
1284
|
-
prompt.className = 'clado-agent-question-text';
|
|
1285
|
-
prompt.textContent = q.question || '请选择下一步方案:';
|
|
1286
|
-
card.append(badge, prompt);
|
|
1287
|
-
|
|
1288
|
-
if (q.answered) {
|
|
1289
|
-
const chosen = document.createElement('div');
|
|
1290
|
-
chosen.className = 'clado-agent-question-answered';
|
|
1291
|
-
chosen.textContent = '已选:' + q.answered;
|
|
1292
|
-
card.append(chosen);
|
|
1293
|
-
return card;
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
const controls = [];
|
|
1297
|
-
const submitChoice = (choiceId, answerText) => {
|
|
1298
|
-
if (running) return;
|
|
1299
|
-
const clean = String(answerText || '').trim();
|
|
1300
|
-
if (!clean) return;
|
|
1301
|
-
for (const el of controls) el.disabled = true;
|
|
1302
|
-
card.classList.add('answered');
|
|
1303
|
-
badge.textContent = '已确认方案';
|
|
1304
|
-
const chosen = document.createElement('div');
|
|
1305
|
-
chosen.className = 'clado-agent-question-answered';
|
|
1306
|
-
chosen.textContent = '已选:' + clean;
|
|
1307
|
-
card.append(chosen);
|
|
1308
|
-
const sid = targetSessionId || session;
|
|
1309
|
-
session = sid;
|
|
1310
|
-
streamTurn({
|
|
1311
|
-
action: 'answer',
|
|
1312
|
-
session: sid,
|
|
1313
|
-
questionId: q.id,
|
|
1314
|
-
choiceId: choiceId || undefined,
|
|
1315
|
-
answer: clean,
|
|
1316
|
-
mode: workflow === 'dispatch' ? 'design' : workflow,
|
|
1317
|
-
execMode,
|
|
1318
|
-
persona,
|
|
1319
|
-
canvas: readCanvas(),
|
|
1320
|
-
viewId,
|
|
1321
|
-
}, {
|
|
1322
|
-
humanText: clean,
|
|
1323
|
-
humanLabel: '你(已确认)',
|
|
1324
|
-
});
|
|
1325
|
-
};
|
|
1326
|
-
|
|
1327
|
-
if (Array.isArray(q.options) && q.options.length) {
|
|
1328
|
-
const optsWrap = document.createElement('div');
|
|
1329
|
-
optsWrap.className = 'clado-agent-question-options';
|
|
1330
|
-
for (const opt of q.options) {
|
|
1331
|
-
const btn = document.createElement('button');
|
|
1332
|
-
btn.type = 'button';
|
|
1333
|
-
btn.className = 'clado-agent-option-btn';
|
|
1334
|
-
const lbl = document.createElement('span');
|
|
1335
|
-
lbl.className = 'clado-agent-option-label';
|
|
1336
|
-
lbl.textContent = opt.label;
|
|
1337
|
-
btn.append(lbl);
|
|
1338
|
-
if (opt.detail) {
|
|
1339
|
-
const det = document.createElement('small');
|
|
1340
|
-
det.textContent = opt.detail;
|
|
1341
|
-
btn.append(det);
|
|
1342
|
-
}
|
|
1343
|
-
btn.onclick = () => submitChoice(opt.id, opt.label);
|
|
1344
|
-
controls.push(btn);
|
|
1345
|
-
optsWrap.append(btn);
|
|
1346
|
-
}
|
|
1347
|
-
card.append(optsWrap);
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
if (q.allowCustom !== false) {
|
|
1351
|
-
const customRow = document.createElement('div');
|
|
1352
|
-
customRow.className = 'clado-agent-question-custom';
|
|
1353
|
-
const field = document.createElement('input');
|
|
1354
|
-
field.type = 'text';
|
|
1355
|
-
field.placeholder = '或输入你的补充决策…';
|
|
1356
|
-
const okBtn = document.createElement('button');
|
|
1357
|
-
okBtn.type = 'button';
|
|
1358
|
-
okBtn.className = 'clado-tab-btn active';
|
|
1359
|
-
okBtn.textContent = '确认';
|
|
1360
|
-
okBtn.onclick = () => submitChoice('custom', field.value);
|
|
1361
|
-
field.onkeydown = ev => {
|
|
1362
|
-
if (ev.key === 'Enter' && !ev.isComposing) {
|
|
1363
|
-
ev.preventDefault();
|
|
1364
|
-
submitChoice('custom', field.value);
|
|
1365
|
-
}
|
|
1366
|
-
};
|
|
1367
|
-
controls.push(field, okBtn);
|
|
1368
|
-
customRow.append(field, okBtn);
|
|
1369
|
-
card.append(customRow);
|
|
1370
|
-
}
|
|
1371
|
-
return card;
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
function appendMessageBubble(author, text, labelOverride) {
|
|
1375
|
-
const empty = log.querySelector('.clado-agent-log-empty');
|
|
1376
|
-
if (empty) empty.remove();
|
|
1377
|
-
const item = document.createElement('div');
|
|
1378
|
-
item.className = 'clado-agent-message ' + author;
|
|
1379
|
-
if (author === 'human') {
|
|
1380
|
-
if (labelOverride && labelOverride !== '你') {
|
|
1381
|
-
const label = document.createElement('strong');
|
|
1382
|
-
label.textContent = labelOverride;
|
|
1383
|
-
item.append(label);
|
|
1384
|
-
}
|
|
1385
|
-
} else if (labelOverride) {
|
|
1386
|
-
const label = document.createElement('strong');
|
|
1387
|
-
label.textContent = labelOverride;
|
|
1388
|
-
item.append(label);
|
|
1389
|
-
}
|
|
1390
|
-
const body = document.createElement('p');
|
|
1391
|
-
body.textContent = text;
|
|
1392
|
-
item.append(body);
|
|
1393
|
-
log.append(item);
|
|
1394
|
-
return { item, body };
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
function renderRecordIntoDrawer(record) {
|
|
1398
|
-
const pKey = record.persona || persona || 'architect';
|
|
1399
|
-
const pMeta = PERSONA_META[pKey] || PERSONA_META.architect;
|
|
1400
|
-
const pal = PALETTES[record.pal || pMeta.pal] || PALETTES.blue;
|
|
1401
|
-
|
|
1402
|
-
persona = pKey;
|
|
1403
|
-
spName.textContent = record.title || pMeta.label;
|
|
1404
|
-
spPersonaTag.textContent = pMeta.label;
|
|
1405
|
-
spPersonaTag.className = 'clado-tag-pill ' + pal.tagClass;
|
|
1406
|
-
|
|
1407
|
-
syncExecModeUI(record.execMode || 'act');
|
|
1408
|
-
if (record.mode && workflowHints[record.mode]) selectWorkflow(record.mode);
|
|
1409
|
-
renderTodos(record.todos || []);
|
|
1410
|
-
|
|
1411
|
-
// 若当前正流式输出该会话,不覆盖正在流式追加的实时 DOM
|
|
1412
|
-
if (running && streamingSessionId === record.id) return;
|
|
1413
|
-
|
|
1414
|
-
log.replaceChildren();
|
|
1415
|
-
const uiMsgs = Array.isArray(record.uiMessages) ? record.uiMessages : [];
|
|
1416
|
-
const checkpointsMap = new Map((record.checkpoints || []).map(c => [c.id, c]));
|
|
1417
|
-
|
|
1418
|
-
if (!uiMsgs.length) {
|
|
1419
|
-
const empty = document.createElement('div');
|
|
1420
|
-
empty.className = 'clado-agent-log-empty';
|
|
1421
|
-
empty.textContent = '会话已就绪,在下方输入想法即可开始协作(长按会话胶囊可新建分身或归档)。';
|
|
1422
|
-
log.append(empty);
|
|
1423
|
-
} else {
|
|
1424
|
-
for (const msg of uiMsgs) {
|
|
1425
|
-
if (msg.role === 'peer_in' || msg.role === 'peer_out') {
|
|
1426
|
-
const card = document.createElement('div');
|
|
1427
|
-
card.className = 'clado-peer-call-card';
|
|
1428
|
-
const head = document.createElement('div');
|
|
1429
|
-
head.className = 'clado-peer-call-head';
|
|
1430
|
-
head.textContent = msg.role === 'peer_in'
|
|
1431
|
-
? `来自「${msg.fromName || '同伴'}」的${msg.kind === 'notify' ? '通知' : '呼叫'}`
|
|
1432
|
-
: `已呼叫「${msg.toName || '同伴'}」`;
|
|
1433
|
-
const body = document.createElement('div');
|
|
1434
|
-
body.textContent = msg.text || '';
|
|
1435
|
-
card.append(head, body);
|
|
1436
|
-
log.append(card);
|
|
1437
|
-
} else if (msg.role === 'human') {
|
|
1438
|
-
const lbl = msg.isSteer ? '你 · 插话纠偏' : msg.isAnswer ? '你 · 已确认' : '';
|
|
1439
|
-
const bubble = appendMessageBubble('human', msg.text || '', lbl);
|
|
1440
|
-
if (msg.canvas?.file) {
|
|
1441
|
-
const ctx = document.createElement('small');
|
|
1442
|
-
ctx.textContent = [
|
|
1443
|
-
msg.canvas.file.split('/').pop(),
|
|
1444
|
-
msg.canvas.selectionCount ? `${msg.canvas.selectionCount} 个选中标题` : '',
|
|
1445
|
-
].filter(Boolean).join(' · ');
|
|
1446
|
-
bubble.item.append(ctx);
|
|
1447
|
-
}
|
|
1448
|
-
} else if (msg.role === 'assistant') {
|
|
1449
|
-
const bubble = appendMessageBubble('assistant', msg.text || '');
|
|
1450
|
-
if (msg.thinking) {
|
|
1451
|
-
const details = createThinkingBlock(msg.thinking);
|
|
1452
|
-
bubble.item.insertBefore(details, bubble.body);
|
|
1453
|
-
}
|
|
1454
|
-
if (!msg.text) bubble.body.hidden = true;
|
|
1455
|
-
if ((Array.isArray(msg.changes) && msg.changes.length) || msg.checkpointId) {
|
|
1456
|
-
const cp = msg.checkpointId ? checkpointsMap.get(msg.checkpointId) : null;
|
|
1457
|
-
bubble.item.append(createChangesRow(msg.changes || [], msg.checkpointId, record.id, Boolean(cp?.rolledBack)));
|
|
1458
|
-
}
|
|
1459
|
-
if (msg.question) {
|
|
1460
|
-
bubble.item.append(createQuestionCard(msg.question, record.id));
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
showStatus(
|
|
1467
|
-
record.pendingCommand
|
|
1468
|
-
? `等待审批命令:${record.pendingCommand.command}`
|
|
1469
|
-
: record.pendingQuestion
|
|
1470
|
-
? '等待你的确认后继续执行'
|
|
1471
|
-
: ''
|
|
1472
|
-
);
|
|
1473
|
-
scrollLog();
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
async function fetchSessionDetail(id) {
|
|
1477
|
-
if (!id) return null;
|
|
1478
|
-
try {
|
|
1479
|
-
const res = await fetch(sessionUrl(id), { cache: 'no-store' });
|
|
1480
|
-
if (!res.ok) return null;
|
|
1481
|
-
const { session: record } = await res.json();
|
|
1482
|
-
if (record) sessionRecords.set(record.id, record);
|
|
1483
|
-
return record || null;
|
|
1484
|
-
} catch {
|
|
1485
|
-
return null;
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
async function openSinglePanel(targetId) {
|
|
1490
|
-
const switching = singlePanelOpen && session !== targetId;
|
|
1491
|
-
session = targetId;
|
|
1492
|
-
singlePanelOpen = true;
|
|
1493
|
-
singleWrap.classList.add('open');
|
|
1494
|
-
renderPeerCluster(false);
|
|
1495
|
-
|
|
1496
|
-
const summary = sessionsList.find(s => s.id === targetId);
|
|
1497
|
-
const cached = sessionRecords.get(targetId);
|
|
1498
|
-
|
|
1499
|
-
const applyView = rec => {
|
|
1500
|
-
if (rec) {
|
|
1501
|
-
renderRecordIntoDrawer(rec);
|
|
1502
|
-
} else {
|
|
1503
|
-
renderRecordIntoDrawer({
|
|
1504
|
-
id: targetId,
|
|
1505
|
-
title: summary?.title || PERSONA_META[persona]?.label || '新会话',
|
|
1506
|
-
persona: summary?.persona || persona,
|
|
1507
|
-
pal: summary?.pal || PERSONA_META[persona]?.pal || 'blue',
|
|
1508
|
-
mode: summary?.mode || workflow,
|
|
1509
|
-
execMode: summary?.execMode || execMode,
|
|
1510
|
-
todos: [],
|
|
1511
|
-
uiMessages: [],
|
|
1512
|
-
});
|
|
1513
|
-
}
|
|
1514
|
-
};
|
|
1515
|
-
|
|
1516
|
-
if (switching) {
|
|
1517
|
-
spInner.classList.add('switching');
|
|
1518
|
-
setTimeout(() => {
|
|
1519
|
-
applyView(cached);
|
|
1520
|
-
spInner.classList.remove('switching');
|
|
1521
|
-
}, 110);
|
|
1522
|
-
} else {
|
|
1523
|
-
applyView(cached);
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
|
-
if (summary) {
|
|
1527
|
-
const latest = await fetchSessionDetail(targetId);
|
|
1528
|
-
if (latest && singlePanelOpen && session === targetId) {
|
|
1529
|
-
renderRecordIntoDrawer(latest);
|
|
1530
|
-
syncCommandBanner();
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
syncActions();
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
|
-
function closeSinglePanel() {
|
|
1537
|
-
singlePanelOpen = false;
|
|
1538
|
-
singleWrap.classList.remove('open');
|
|
1539
|
-
renderPeerCluster(false);
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
// 10. 详情抽屉按钮交互
|
|
1543
|
-
dock.querySelector('[data-role="close-single"]').onclick = () => closeSinglePanel();
|
|
1544
|
-
dock.querySelector('[data-role="archive-btn"]').onclick = () => archiveSessionById(session);
|
|
1545
|
-
dock.querySelector('[data-role="delete-btn"]').onclick = () => deleteSessionById(session);
|
|
1546
|
-
dock.querySelector('[data-role="open-settings"]').onclick = () => openSettingsOverlay();
|
|
1547
|
-
dock.querySelector('[data-role="minimize-btn"]').onclick = () => setMinimized(true);
|
|
1548
|
-
orbBtn.onclick = () => setMinimized(false);
|
|
1549
|
-
|
|
1550
|
-
followBtn.onclick = () => {
|
|
1551
|
-
followAi = !followAi;
|
|
1552
|
-
followBtn.setAttribute('aria-pressed', String(followAi));
|
|
1553
|
-
setFollowAi(followAi);
|
|
1554
|
-
showToast(followAi ? '已开启镜头跟随 AI' : '已关闭镜头跟随');
|
|
1555
|
-
};
|
|
1556
|
-
|
|
1557
|
-
execModeBtns.forEach(btn => {
|
|
1558
|
-
btn.onclick = async () => {
|
|
1559
|
-
const next = btn.dataset.execMode === 'plan' ? 'plan' : 'act';
|
|
1560
|
-
syncExecModeUI(next);
|
|
1561
|
-
const rec = sessionRecords.get(session);
|
|
1562
|
-
if (rec) rec.execMode = next;
|
|
1563
|
-
try {
|
|
1564
|
-
await fetch(sessionsEndpoint, {
|
|
1565
|
-
method: 'POST',
|
|
1566
|
-
headers: { 'content-type': 'application/json' },
|
|
1567
|
-
body: JSON.stringify({ action: 'exec_mode', id: session, execMode: next }),
|
|
1568
|
-
});
|
|
1569
|
-
} catch {}
|
|
1570
|
-
};
|
|
1571
|
-
});
|
|
1572
|
-
|
|
1573
|
-
workflowBtns.forEach(btn => {
|
|
1574
|
-
btn.onclick = () => {
|
|
1575
|
-
if (running) return;
|
|
1576
|
-
selectWorkflow(btn.dataset.workflow);
|
|
1577
|
-
if (workflow === 'dispatch') loadMeta();
|
|
1578
|
-
};
|
|
1579
|
-
});
|
|
1580
|
-
|
|
1581
|
-
stopBtn.onclick = async () => {
|
|
1582
|
-
if (stopping) return;
|
|
1583
|
-
stopping = true;
|
|
1584
|
-
syncActions();
|
|
1585
|
-
try {
|
|
1586
|
-
await request({ action: 'cancel', session });
|
|
1587
|
-
} catch {
|
|
1588
|
-
showStatus('暂时无法停止,请重试。');
|
|
1589
|
-
} finally {
|
|
1590
|
-
stopping = false;
|
|
1591
|
-
syncActions();
|
|
1592
|
-
}
|
|
1593
|
-
};
|
|
1594
|
-
|
|
1595
|
-
// 11. 流式对话与插话(Steer)闭环
|
|
1596
|
-
async function streamTurn(payload, { humanText, humanLabel, canvas, assistantLabel, isDispatch = false } = {}) {
|
|
1597
|
-
const targetSid = payload.session || session;
|
|
1598
|
-
running = true;
|
|
1599
|
-
streamingSessionId = targetSid;
|
|
1600
|
-
session = targetSid;
|
|
1601
|
-
|
|
1602
|
-
if (!singlePanelOpen) {
|
|
1603
|
-
singlePanelOpen = true;
|
|
1604
|
-
singleWrap.classList.add('open');
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
// 乐观确保胶囊出现在会话条第 1 位
|
|
1608
|
-
if (!sessionsList.some(s => s.id === targetSid)) {
|
|
1609
|
-
const pMeta = PERSONA_META[persona] || PERSONA_META.architect;
|
|
1610
|
-
sessionsList.unshift({
|
|
1611
|
-
id: targetSid,
|
|
1612
|
-
title: (humanText || pMeta.label).slice(0, 22),
|
|
1613
|
-
persona,
|
|
1614
|
-
pal: pMeta.pal,
|
|
1615
|
-
mode: workflow,
|
|
1616
|
-
execMode,
|
|
1617
|
-
running: true,
|
|
1618
|
-
liveStatus: '处理中…',
|
|
1619
|
-
lastActiveAt: new Date().toISOString(),
|
|
1620
|
-
});
|
|
1621
|
-
} else {
|
|
1622
|
-
const hit = sessionsList.find(s => s.id === targetSid);
|
|
1623
|
-
if (hit) {
|
|
1624
|
-
hit.running = true;
|
|
1625
|
-
hit.liveStatus = '处理中…';
|
|
1626
|
-
hit.lastActiveAt = new Date().toISOString();
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
renderPeerCluster(true);
|
|
1630
|
-
|
|
1631
|
-
const userBubble = appendMessageBubble('human', humanText || '', humanLabel);
|
|
1632
|
-
if (canvas?.file) {
|
|
1633
|
-
const ctx = document.createElement('small');
|
|
1634
|
-
ctx.textContent = [
|
|
1635
|
-
canvas.file.split('/').pop(),
|
|
1636
|
-
canvas.selection?.length ? `${canvas.selection.length} 个选中标题` : '',
|
|
1637
|
-
].filter(Boolean).join(' · ');
|
|
1638
|
-
userBubble.item.append(ctx);
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
const reply = appendMessageBubble('assistant', '', assistantLabel);
|
|
1642
|
-
reply.item.hidden = true;
|
|
1643
|
-
reply.body.hidden = true;
|
|
1644
|
-
const replyText = reply.body.appendChild(document.createTextNode(''));
|
|
1645
|
-
let thinkingPre = null;
|
|
1646
|
-
let pendingChanges = [];
|
|
1647
|
-
let turnCheckpointId = null;
|
|
1648
|
-
const tools = new Map();
|
|
1649
|
-
let finished = false;
|
|
1650
|
-
|
|
1651
|
-
const apply = update => {
|
|
1652
|
-
const nearBottom = log.scrollHeight - log.scrollTop - log.clientHeight < 56;
|
|
1653
|
-
if (update.type === 'thinking' && update.text) {
|
|
1654
|
-
reply.item.hidden = false;
|
|
1655
|
-
if (!thinkingPre) {
|
|
1656
|
-
const details = createThinkingBlock('');
|
|
1657
|
-
reply.item.insertBefore(details, reply.body);
|
|
1658
|
-
thinkingPre = details.querySelector('pre');
|
|
1659
|
-
}
|
|
1660
|
-
thinkingPre.textContent += update.text;
|
|
1661
|
-
} else if (update.type === 'text' && update.text) {
|
|
1662
|
-
reply.item.hidden = false;
|
|
1663
|
-
reply.body.hidden = false;
|
|
1664
|
-
replyText.appendData(update.text);
|
|
1665
|
-
} else if (update.type === 'todos' && Array.isArray(update.todos)) {
|
|
1666
|
-
renderTodos(update.todos);
|
|
1667
|
-
} else if (update.type === 'changes' && Array.isArray(update.items)) {
|
|
1668
|
-
pendingChanges = update.items;
|
|
1669
|
-
} else if (update.type === 'checkpoint' && update.checkpoint?.id) {
|
|
1670
|
-
turnCheckpointId = update.checkpoint.id;
|
|
1671
|
-
} else if (update.type === 'question' && update.question) {
|
|
1672
|
-
reply.item.hidden = false;
|
|
1673
|
-
reply.item.append(createQuestionCard(update.question, targetSid));
|
|
1674
|
-
} else if (update.type === 'command_approval' && (update.approval || update.command)) {
|
|
1675
|
-
const curTitle = sessionsList.find(s => s.id === targetSid)?.title || spName.textContent || '当前会话';
|
|
1676
|
-
activePendingCmd = {
|
|
1677
|
-
sessionId: targetSid,
|
|
1678
|
-
sessionTitle: curTitle,
|
|
1679
|
-
cmd: update.approval || update.command,
|
|
1680
|
-
};
|
|
1681
|
-
syncCommandBanner();
|
|
1682
|
-
} else if (update.type === 'peer_event') {
|
|
1683
|
-
reply.item.hidden = false;
|
|
1684
|
-
const card = document.createElement('div');
|
|
1685
|
-
card.className = 'clado-peer-call-card';
|
|
1686
|
-
const head = document.createElement('div');
|
|
1687
|
-
head.className = 'clado-peer-call-head';
|
|
1688
|
-
head.textContent = `已呼叫「${update.toName || update.name || '同伴分身'}」`;
|
|
1689
|
-
const body = document.createElement('div');
|
|
1690
|
-
body.textContent = update.text || update.task || '';
|
|
1691
|
-
card.append(head, body);
|
|
1692
|
-
reply.item.append(card);
|
|
1693
|
-
} else if (update.type === 'status') {
|
|
1694
|
-
showStatus(update.text);
|
|
1695
|
-
const hit = sessionsList.find(s => s.id === targetSid);
|
|
1696
|
-
if (hit && update.text) {
|
|
1697
|
-
hit.liveStatus = update.text;
|
|
1698
|
-
const pill = pillDomMap.get(targetSid);
|
|
1699
|
-
if (pill) pill.querySelector('.p-live').textContent = '· ' + update.text;
|
|
1700
|
-
}
|
|
1701
|
-
} else if (update.type === 'tool') {
|
|
1702
|
-
const title = update.title || tools.get(update.id);
|
|
1703
|
-
if (title) {
|
|
1704
|
-
tools.set(update.id, title);
|
|
1705
|
-
const line = [title.split('.').pop(), toolStates[update.status]].filter(Boolean).join(' · ');
|
|
1706
|
-
showStatus(line);
|
|
1707
|
-
}
|
|
1708
|
-
} else if (update.type === 'error') {
|
|
1709
|
-
throw new Error(update.text);
|
|
1710
|
-
} else if (update.type === 'done') {
|
|
1711
|
-
finished = true;
|
|
1712
|
-
if (pendingChanges.length || turnCheckpointId) {
|
|
1713
|
-
reply.item.hidden = false;
|
|
1714
|
-
reply.item.append(createChangesRow(pendingChanges, turnCheckpointId, targetSid, false));
|
|
1715
|
-
}
|
|
1716
|
-
const labels = {
|
|
1717
|
-
cancelled: '已停止',
|
|
1718
|
-
awaiting_user: '等待你的确认后继续执行',
|
|
1719
|
-
awaiting_command: '等待你审批命令后继续执行',
|
|
1720
|
-
max_tokens: '已达到本轮输出上限',
|
|
1721
|
-
max_turn_requests: '已达到本轮请求上限',
|
|
1722
|
-
refusal: '已拒绝执行本轮请求',
|
|
1723
|
-
};
|
|
1724
|
-
showStatus(labels[update.reason] || (isDispatch ? '执行器已完成,可切到「Diff 验收」核对代码变更' : ''));
|
|
1725
|
-
}
|
|
1726
|
-
if (nearBottom) scrollLog();
|
|
1727
|
-
};
|
|
1728
|
-
|
|
1729
|
-
showStatus(isDispatch ? `正在派发给 ${assistantLabel || agentName}…` : '正在连接 灵感…');
|
|
1730
|
-
scrollLog();
|
|
1731
|
-
|
|
1732
|
-
try {
|
|
1733
|
-
const response = await request(payload);
|
|
1734
|
-
if (!response.ok) {
|
|
1735
|
-
const failure = await response.json().catch(() => ({}));
|
|
1736
|
-
throw new Error(failure.error || '发送失败。');
|
|
1737
|
-
}
|
|
1738
|
-
const reader = response.body.getReader();
|
|
1739
|
-
const decoder = new TextDecoder();
|
|
1740
|
-
let buffer = '';
|
|
1741
|
-
try {
|
|
1742
|
-
while (true) {
|
|
1743
|
-
const { value, done } = await reader.read();
|
|
1744
|
-
if (done) break;
|
|
1745
|
-
buffer += decoder.decode(value, { stream: true });
|
|
1746
|
-
const records = buffer.split('\n');
|
|
1747
|
-
buffer = records.pop();
|
|
1748
|
-
for (const record of records) {
|
|
1749
|
-
if (record.trim()) apply(JSON.parse(record));
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
buffer += decoder.decode();
|
|
1753
|
-
if (buffer.trim()) apply(JSON.parse(buffer));
|
|
1754
|
-
} finally {
|
|
1755
|
-
if (!finished) await reader.cancel().catch(() => {});
|
|
1756
|
-
reader.releaseLock();
|
|
1757
|
-
}
|
|
1758
|
-
if (!finished) throw new Error('连接中断,未收到本轮结束消息。');
|
|
1759
|
-
} catch (error) {
|
|
1760
|
-
showStatus(error.message || '运行失败。');
|
|
1761
|
-
} finally {
|
|
1762
|
-
if (reply.item.hidden) reply.item.remove();
|
|
1763
|
-
running = false;
|
|
1764
|
-
stopping = false;
|
|
1765
|
-
streamingSessionId = '';
|
|
1766
|
-
await Promise.all([
|
|
1767
|
-
refreshSessionsList(false),
|
|
1768
|
-
fetchSessionDetail(targetSid),
|
|
1769
|
-
]);
|
|
1770
|
-
if (singlePanelOpen && session === targetSid && sessionRecords.has(targetSid)) {
|
|
1771
|
-
renderRecordIntoDrawer(sessionRecords.get(targetSid));
|
|
1772
|
-
}
|
|
1773
|
-
syncCommandBanner();
|
|
1774
|
-
syncActions();
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
|
|
1778
|
-
let slashMatches = [];
|
|
1779
|
-
let slashIndex = 0;
|
|
1780
|
-
|
|
1781
|
-
function closeSlashMenu() {
|
|
1782
|
-
slashMenu.classList.remove('open');
|
|
1783
|
-
slashMatches = [];
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
|
-
function applySlashSelection(cmd) {
|
|
1787
|
-
if (!cmd) return;
|
|
1788
|
-
input.value = `/${cmd.name} `;
|
|
1789
|
-
closeSlashMenu();
|
|
1790
|
-
syncActions();
|
|
1791
|
-
input.focus();
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
function updateSlashAutocomplete() {
|
|
1795
|
-
const val = input.value || '';
|
|
1796
|
-
const m = val.match(/^\/([a-zA-Z0-9_-]*)$/);
|
|
1797
|
-
if (!m || dock.classList.contains('minimized')) {
|
|
1798
|
-
closeSlashMenu();
|
|
1799
|
-
return;
|
|
1800
|
-
}
|
|
1801
|
-
const needle = m[1].toLowerCase();
|
|
1802
|
-
const cmds = Array.isArray(meta.commands) && meta.commands.length
|
|
1803
|
-
? meta.commands
|
|
1804
|
-
: [
|
|
1805
|
-
{ name: 'arch', description: '读取源码并在画布中梳理系统架构与调用链', scope: 'builtin' },
|
|
1806
|
-
{ name: 'test', description: '基于当前画布或源码生成脑图测试用例', scope: 'builtin' },
|
|
1807
|
-
{ name: 'diff', description: '读取本地 Git Diff,对照画布设计逐项验收与归档', scope: 'builtin' },
|
|
1808
|
-
{ name: 'dispatch', description: '打包当前架构规格并派发给外部 ACP 执行器落地编码', scope: 'builtin' },
|
|
1809
|
-
];
|
|
1810
|
-
slashMatches = cmds.filter(c => !needle || c.name.toLowerCase().includes(needle) || (c.description || '').toLowerCase().includes(needle)).slice(0, 10);
|
|
1811
|
-
if (!slashMatches.length) {
|
|
1812
|
-
closeSlashMenu();
|
|
1813
|
-
return;
|
|
1814
|
-
}
|
|
1815
|
-
if (slashIndex >= slashMatches.length) slashIndex = 0;
|
|
1816
|
-
slashMenu.replaceChildren();
|
|
1817
|
-
const hdr = document.createElement('div');
|
|
1818
|
-
hdr.className = 'clado-ctx-badge';
|
|
1819
|
-
hdr.innerHTML = '<span>斜杠命令 (/Commands)</span><span style="opacity:.65;">↵ 选择</span>';
|
|
1820
|
-
slashMenu.append(hdr);
|
|
1821
|
-
|
|
1822
|
-
slashMatches.forEach((cmd, idx) => {
|
|
1823
|
-
const btn = document.createElement('button');
|
|
1824
|
-
btn.type = 'button';
|
|
1825
|
-
btn.className = 'clado-slash-item' + (idx === slashIndex ? ' active' : '');
|
|
1826
|
-
const scopeLabel = cmd.scope === 'builtin' ? '内置' : cmd.scope === 'plugin' ? '插件' : cmd.scope === 'global' ? '全局' : '工作区';
|
|
1827
|
-
btn.innerHTML = `
|
|
1828
|
-
<div class="clado-slash-item-head">
|
|
1829
|
-
<span class="clado-slash-item-name">/${cmd.name}</span>
|
|
1830
|
-
<span class="clado-slash-item-scope">${cmd.skill ? `⚡ ${cmd.skill} · ` : ''}${scopeLabel}</span>
|
|
1831
|
-
</div>
|
|
1832
|
-
<div class="clado-slash-item-desc">${cmd.description || ''}</div>`;
|
|
1833
|
-
btn.onmousedown = ev => {
|
|
1834
|
-
ev.preventDefault();
|
|
1835
|
-
applySlashSelection(cmd);
|
|
1836
|
-
};
|
|
1837
|
-
slashMenu.append(btn);
|
|
1838
|
-
});
|
|
1839
|
-
|
|
1840
|
-
const r = shell.getBoundingClientRect();
|
|
1841
|
-
slashMenu.style.left = '-999px';
|
|
1842
|
-
slashMenu.style.top = '-999px';
|
|
1843
|
-
slashMenu.classList.add('open');
|
|
1844
|
-
const mr = slashMenu.getBoundingClientRect();
|
|
1845
|
-
const left = Math.max(10, Math.min(r.left, window.innerWidth - mr.width - 10));
|
|
1846
|
-
const top = Math.max(12, r.top - mr.height - 8);
|
|
1847
|
-
slashMenu.style.left = left + 'px';
|
|
1848
|
-
slashMenu.style.top = top + 'px';
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
input.addEventListener('input', () => {
|
|
1852
|
-
syncActions();
|
|
1853
|
-
updateSlashAutocomplete();
|
|
1854
|
-
});
|
|
1855
|
-
input.addEventListener('keydown', event => {
|
|
1856
|
-
if (slashMenu.classList.contains('open') && slashMatches.length) {
|
|
1857
|
-
if (event.key === 'ArrowDown') {
|
|
1858
|
-
event.preventDefault();
|
|
1859
|
-
slashIndex = (slashIndex + 1) % slashMatches.length;
|
|
1860
|
-
updateSlashAutocomplete();
|
|
1861
|
-
return;
|
|
1862
|
-
}
|
|
1863
|
-
if (event.key === 'ArrowUp') {
|
|
1864
|
-
event.preventDefault();
|
|
1865
|
-
slashIndex = (slashIndex - 1 + slashMatches.length) % slashMatches.length;
|
|
1866
|
-
updateSlashAutocomplete();
|
|
1867
|
-
return;
|
|
1868
|
-
}
|
|
1869
|
-
if (event.key === 'Tab' || (event.key === 'Enter' && !event.shiftKey && !event.isComposing && event.keyCode !== 229)) {
|
|
1870
|
-
event.preventDefault();
|
|
1871
|
-
applySlashSelection(slashMatches[slashIndex]);
|
|
1872
|
-
return;
|
|
1873
|
-
}
|
|
1874
|
-
if (event.key === 'Escape') {
|
|
1875
|
-
event.preventDefault();
|
|
1876
|
-
closeSlashMenu();
|
|
1877
|
-
return;
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing && event.keyCode !== 229) {
|
|
1881
|
-
event.preventDefault();
|
|
1882
|
-
if (!sendBtn.disabled) shell.requestSubmit();
|
|
1883
|
-
}
|
|
1884
|
-
});
|
|
1885
|
-
|
|
1886
|
-
function isLlmConfigured() {
|
|
1887
|
-
return Boolean(meta.llm?.configured || meta.builtinConfigured);
|
|
1888
|
-
}
|
|
1889
|
-
|
|
1890
|
-
function currentSessionEngine() {
|
|
1891
|
-
const curSummary = sessionsList.find(s => s.id === session);
|
|
1892
|
-
const curRec = sessionRecords.get(session);
|
|
1893
|
-
if (curSummary?.engine === 'acp' || curRec?.engine === 'acp') return 'acp';
|
|
1894
|
-
return 'builtin';
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
function syncModelChip() {
|
|
1898
|
-
if (!modelChip || !modelChipLabel) return;
|
|
1899
|
-
if (currentSessionEngine() === 'acp') {
|
|
1900
|
-
modelChip.classList.remove('unconfigured');
|
|
1901
|
-
modelChipLabel.textContent = '⚡ ACP 子代理';
|
|
1902
|
-
modelChip.title = '当前胶囊使用外部 ACP 子代理机制';
|
|
1903
|
-
return;
|
|
1904
|
-
}
|
|
1905
|
-
if (!isLlmConfigured()) {
|
|
1906
|
-
modelChip.classList.add('unconfigured');
|
|
1907
|
-
modelChipLabel.textContent = '配置模型';
|
|
1908
|
-
modelChip.title = '点击配置供应商、API Key 与主力模型';
|
|
1909
|
-
return;
|
|
1910
|
-
}
|
|
1911
|
-
modelChip.classList.remove('unconfigured');
|
|
1912
|
-
const shortModel = (meta.llm?.model || meta.model || '已配置').split('/').pop();
|
|
1913
|
-
modelChipLabel.textContent = shortModel;
|
|
1914
|
-
modelChip.title = `${meta.llm?.providerLabel || meta.providerLabel || '当前模型'} · ${meta.llm?.model || meta.model}`;
|
|
1915
|
-
}
|
|
1916
|
-
|
|
1917
|
-
async function quickSwitchModel(providerId, model) {
|
|
1918
|
-
try {
|
|
1919
|
-
const res = await fetch(configEndpoint, {
|
|
1920
|
-
method: 'POST',
|
|
1921
|
-
headers: { 'content-type': 'application/json' },
|
|
1922
|
-
body: JSON.stringify({ action: 'switch_model', providerId, model }),
|
|
1923
|
-
});
|
|
1924
|
-
if (!res.ok) return;
|
|
1925
|
-
const data = await res.json();
|
|
1926
|
-
if (data.llm) {
|
|
1927
|
-
meta.llm = data.llm;
|
|
1928
|
-
meta.builtinConfigured = Boolean(data.llm.configured);
|
|
1929
|
-
meta.model = data.llm.model;
|
|
1930
|
-
meta.providerId = data.llm.providerId;
|
|
1931
|
-
meta.providerLabel = data.llm.providerLabel;
|
|
1932
|
-
}
|
|
1933
|
-
syncModelChip();
|
|
1934
|
-
syncConfigSummaryUI();
|
|
1935
|
-
showToast(`已切换模型:${model}`);
|
|
1936
|
-
} catch {}
|
|
1937
|
-
}
|
|
1938
|
-
|
|
1939
|
-
function openModelQuickMenu() {
|
|
1940
|
-
if (!isLlmConfigured() && currentSessionEngine() !== 'acp') {
|
|
1941
|
-
openSettingsOverlay('llm');
|
|
1942
|
-
return;
|
|
1943
|
-
}
|
|
1944
|
-
if (modelMenu.classList.contains('open')) {
|
|
1945
|
-
closeModelMenu();
|
|
1946
|
-
return;
|
|
1947
|
-
}
|
|
1948
|
-
modelMenu.replaceChildren();
|
|
1949
|
-
const hdr = document.createElement('div');
|
|
1950
|
-
hdr.className = 'clado-ctx-badge';
|
|
1951
|
-
hdr.innerHTML = `<span>切换主力模型</span><span style="opacity:.7;">${meta.llm?.providerLabel || ''}</span>`;
|
|
1952
|
-
modelMenu.append(hdr);
|
|
1953
|
-
|
|
1954
|
-
const quickList = Array.isArray(meta.llm?.quickModels) ? meta.llm.quickModels : [];
|
|
1955
|
-
for (const item of quickList) {
|
|
1956
|
-
const active = item.providerId === meta.llm?.providerId && item.model === meta.llm?.model;
|
|
1957
|
-
const btn = document.createElement('button');
|
|
1958
|
-
btn.type = 'button';
|
|
1959
|
-
btn.className = 'clado-ctx-btn';
|
|
1960
|
-
btn.style.display = 'flex';
|
|
1961
|
-
btn.style.justifyContent = 'space-between';
|
|
1962
|
-
btn.style.alignItems = 'center';
|
|
1963
|
-
btn.style.gap = '8px';
|
|
1964
|
-
btn.innerHTML = `<span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">${item.providerLabel} · <strong>${item.model.split('/').pop()}</strong></span><span style="color:var(--clado-ui-brand);font-weight:700;">${active ? '✓' : ''}</span>`;
|
|
1965
|
-
btn.onclick = () => {
|
|
1966
|
-
closeModelMenu();
|
|
1967
|
-
quickSwitchModel(item.providerId, item.model);
|
|
1968
|
-
};
|
|
1969
|
-
modelMenu.append(btn);
|
|
1970
|
-
}
|
|
1971
|
-
|
|
1972
|
-
const sep = document.createElement('div');
|
|
1973
|
-
sep.style.cssText = 'height:1px;background:var(--clado-agent-edge);margin:3px 6px;';
|
|
1974
|
-
modelMenu.append(sep);
|
|
1975
|
-
|
|
1976
|
-
const cfgBtn = document.createElement('button');
|
|
1977
|
-
cfgBtn.type = 'button';
|
|
1978
|
-
cfgBtn.className = 'clado-ctx-btn';
|
|
1979
|
-
cfgBtn.textContent = '⚙ 配置供应商与模型…';
|
|
1980
|
-
cfgBtn.onclick = () => {
|
|
1981
|
-
closeModelMenu();
|
|
1982
|
-
openSettingsOverlay('llm');
|
|
1983
|
-
};
|
|
1984
|
-
modelMenu.append(cfgBtn);
|
|
1985
|
-
|
|
1986
|
-
const r = modelChip.getBoundingClientRect();
|
|
1987
|
-
modelMenu.style.left = '-999px';
|
|
1988
|
-
modelMenu.style.top = '-999px';
|
|
1989
|
-
modelMenu.classList.add('open');
|
|
1990
|
-
const mr = modelMenu.getBoundingClientRect();
|
|
1991
|
-
const left = Math.max(10, Math.min(r.left, window.innerWidth - mr.width - 10));
|
|
1992
|
-
const top = Math.max(12, r.top - mr.height - 8);
|
|
1993
|
-
modelMenu.style.left = left + 'px';
|
|
1994
|
-
modelMenu.style.top = top + 'px';
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
|
-
modelChip.onclick = ev => {
|
|
1998
|
-
ev.stopPropagation();
|
|
1999
|
-
closeCtxMenu();
|
|
2000
|
-
openModelQuickMenu();
|
|
2001
|
-
};
|
|
2002
|
-
|
|
2003
|
-
spPersonaTag.style.cursor = 'pointer';
|
|
2004
|
-
spPersonaTag.title = '点击切换当前会话人设或编辑人设提示词';
|
|
2005
|
-
spPersonaTag.onclick = ev => {
|
|
2006
|
-
ev.stopPropagation();
|
|
2007
|
-
ctxMenu.replaceChildren();
|
|
2008
|
-
addCtxHeader('切换当前会话人设', spName.textContent);
|
|
2009
|
-
for (const [k, info] of Object.entries(PERSONA_META)) {
|
|
2010
|
-
if (k === 'custom') continue;
|
|
2011
|
-
addCtxItem(`${k === persona ? '✓ ' : ''}${info.label}`, async () => {
|
|
2012
|
-
persona = k;
|
|
2013
|
-
try {
|
|
2014
|
-
const res = await fetch(sessionsEndpoint, {
|
|
2015
|
-
method: 'POST',
|
|
2016
|
-
headers: { 'content-type': 'application/json' },
|
|
2017
|
-
body: JSON.stringify({ action: 'set_persona', id: session, persona: k }),
|
|
2018
|
-
});
|
|
2019
|
-
if (res.ok) {
|
|
2020
|
-
const { session: updated } = await res.json();
|
|
2021
|
-
if (updated) {
|
|
2022
|
-
sessionRecords.set(updated.id, updated);
|
|
2023
|
-
renderRecordIntoDrawer(updated);
|
|
2024
|
-
}
|
|
2025
|
-
await refreshSessionsList(false);
|
|
2026
|
-
}
|
|
2027
|
-
} catch {}
|
|
2028
|
-
});
|
|
2029
|
-
}
|
|
2030
|
-
addCtxItem('✎ 编辑人设提示词模板…', () => {
|
|
2031
|
-
activePersonaTab = persona === 'custom' ? 'architect' : persona;
|
|
2032
|
-
openSettingsOverlay('persona');
|
|
2033
|
-
});
|
|
2034
|
-
const r = spPersonaTag.getBoundingClientRect();
|
|
2035
|
-
positionCtxMenu(r.left + r.width / 2, r.top);
|
|
2036
|
-
};
|
|
2037
|
-
|
|
2038
|
-
shell.onsubmit = async event => {
|
|
2039
|
-
event.preventDefault();
|
|
2040
|
-
if (!canSubmit()) return;
|
|
2041
|
-
const rawText = input.value.trim();
|
|
2042
|
-
|
|
2043
|
-
// 运行中实时插话(Steer)
|
|
2044
|
-
if (running && streamingSessionId === session && currentSessionEngine() === 'builtin' && rawText) {
|
|
2045
|
-
input.value = '';
|
|
2046
|
-
syncActions();
|
|
2047
|
-
try {
|
|
2048
|
-
const res = await request({ action: 'steer', session, text: rawText });
|
|
2049
|
-
if (res.ok) {
|
|
2050
|
-
appendMessageBubble('human', rawText, '你 · 插话纠偏');
|
|
2051
|
-
scrollLog();
|
|
2052
|
-
showToast('已插话,将在当前步骤完成后立即生效');
|
|
2053
|
-
}
|
|
2054
|
-
} catch {}
|
|
2055
|
-
return;
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
const isDispatch = workflow === 'dispatch';
|
|
2059
|
-
const curEngine = currentSessionEngine();
|
|
2060
|
-
// 若当前为主力原生 Agent 且尚未配置任何供应商/模型,不报底层错误,直接平滑打开供应商与模型配置页并保留输入文字
|
|
2061
|
-
if (!isDispatch && curEngine === 'builtin' && !isLlmConfigured()) {
|
|
2062
|
-
openSettingsOverlay('llm');
|
|
2063
|
-
showToast('请先选择供应商并填写 API Key(或启用本地 Ollama)');
|
|
2064
|
-
return;
|
|
2065
|
-
}
|
|
2066
|
-
|
|
2067
|
-
const text = rawText || (workflow === 'audit' ? '请核对当前本地 Git Diff 与画布设计契约、测试用例的差异,并给出验收结论。' : '');
|
|
2068
|
-
const canvas = readCanvas();
|
|
2069
|
-
input.value = '';
|
|
2070
|
-
const executorName = executorSelect.selectedOptions?.[0]?.textContent || agentName;
|
|
2071
|
-
const payload = isDispatch
|
|
2072
|
-
? { action: 'dispatch', session, executorId: executorSelect.value || undefined, text: rawText, canvas, viewId }
|
|
2073
|
-
: { action: 'prompt', session, engine: curEngine, mode: workflow, execMode, persona, text, canvas, viewId };
|
|
2074
|
-
await streamTurn(payload, {
|
|
2075
|
-
humanText: isDispatch ? `[派发开发 → ${executorName}] ${rawText || '按当前画布规格实现代码并运行测试'}` : text,
|
|
2076
|
-
canvas,
|
|
2077
|
-
assistantLabel: isDispatch ? executorName : undefined,
|
|
2078
|
-
isDispatch,
|
|
2079
|
-
});
|
|
2080
|
-
};
|
|
2081
|
-
|
|
2082
|
-
// 12. 一等「供应商与模型」+「Agent 设置」面板(对接 /library/agent/config)
|
|
2083
|
-
let debugState = {
|
|
2084
|
-
config: {
|
|
2085
|
-
canvasMemory: 'delta',
|
|
2086
|
-
timeInjection: 'date_only',
|
|
2087
|
-
workspaceMap: true,
|
|
2088
|
-
memoryEnabled: true,
|
|
2089
|
-
autoArchiveHours: 24,
|
|
2090
|
-
commandPermission: 'readonly_free',
|
|
2091
|
-
compactThresholdPct: 75,
|
|
2092
|
-
compactPrompt: '',
|
|
2093
|
-
personas: {},
|
|
2094
|
-
},
|
|
2095
|
-
memory: { text: '', inherited: [] },
|
|
2096
|
-
telemetry: null,
|
|
2097
|
-
};
|
|
2098
|
-
let currentSub = null;
|
|
2099
|
-
let activePersonaTab = 'architect';
|
|
2100
|
-
let activeProviderDraft = 'openai';
|
|
2101
|
-
const cfgHomeEl = configView.querySelector('[data-role="cfg-home"]');
|
|
2102
|
-
const cfgSubEl = configView.querySelector('[data-role="cfg-sub"]');
|
|
2103
|
-
const subTitleEl = configView.querySelector('[data-role="sub-title"]');
|
|
2104
|
-
const subResetBtn = configView.querySelector('[data-role="sub-reset"]');
|
|
2105
|
-
const subBodyEl = configView.querySelector('[data-role="sub-body"]');
|
|
2106
|
-
|
|
2107
|
-
function syncConfigSummaryUI() {
|
|
2108
|
-
const c = debugState.config;
|
|
2109
|
-
const findLabel = (arr, val, fallback) => (arr.find(([k]) => k === val) || [null, fallback])[1];
|
|
2110
|
-
configView.querySelector('[data-cfg-val="canvas"]').textContent = findLabel(CANVAS_MEM_CYCLE, c.canvasMemory, '智能增量');
|
|
2111
|
-
configView.querySelector('[data-cfg-val="time"]').textContent = findLabel(TIME_MODE_CYCLE, c.timeInjection, '仅日期');
|
|
2112
|
-
configView.querySelector('[data-cfg-val="ttl"]').textContent = findLabel(TTL_CYCLE, c.autoArchiveHours, '24 小时');
|
|
2113
|
-
configView.querySelector('[data-cfg-val="perm"]').textContent = findLabel(PERM_CYCLE, c.commandPermission, '只读免审');
|
|
2114
|
-
configView.querySelector('[data-cfg-val="memory"]').textContent = c.memoryEnabled ? '已开启 · 编辑' : '已关闭';
|
|
2115
|
-
configView.querySelector('[data-cfg-val="compact"]').textContent = `${c.compactThresholdPct || 75}% 触发 · 编辑`;
|
|
2116
|
-
configView.querySelector('[data-cfg-act="toggle-map"]').classList.toggle('on', c.workspaceMap !== false);
|
|
2117
|
-
|
|
2118
|
-
const llmSummaryEl = configView.querySelector('[data-cfg-val="llm"]');
|
|
2119
|
-
if (llmSummaryEl) {
|
|
2120
|
-
if (isLlmConfigured()) {
|
|
2121
|
-
llmSummaryEl.textContent = `${meta.llm?.providerLabel || '已配置'} · ${(meta.llm?.model || meta.model || '').split('/').pop()}`;
|
|
2122
|
-
llmSummaryEl.style.color = '#059669';
|
|
2123
|
-
} else {
|
|
2124
|
-
llmSummaryEl.textContent = '未配置 · 点击设置';
|
|
2125
|
-
llmSummaryEl.style.color = 'var(--clado-ui-brand)';
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
|
|
2129
|
-
const acpSummaryEl = configView.querySelector('[data-cfg-val="acp"]');
|
|
2130
|
-
if (acpSummaryEl) {
|
|
2131
|
-
acpSummaryEl.textContent = meta.llm?.acpCommand || '低优备用';
|
|
2132
|
-
}
|
|
2133
|
-
|
|
2134
|
-
const mcpSummaryEl = configView.querySelector('[data-cfg-val="mcp"]');
|
|
2135
|
-
if (mcpSummaryEl) {
|
|
2136
|
-
const mcps = Array.isArray(meta.mcpServers) ? meta.mcpServers : [];
|
|
2137
|
-
const enabledCnt = mcps.filter(m => m.enabled !== false).length;
|
|
2138
|
-
mcpSummaryEl.textContent = mcps.length ? `${enabledCnt}/${mcps.length} 已启用` : '接入外部工具 / 复制';
|
|
2139
|
-
}
|
|
2140
|
-
const skillsSummaryEl = configView.querySelector('[data-cfg-val="skills"]');
|
|
2141
|
-
if (skillsSummaryEl) {
|
|
2142
|
-
const sks = Array.isArray(meta.skills) ? meta.skills : [];
|
|
2143
|
-
skillsSummaryEl.textContent = `${sks.length} 个技能`;
|
|
2144
|
-
}
|
|
2145
|
-
const cmdsSummaryEl = configView.querySelector('[data-cfg-val="commands"]');
|
|
2146
|
-
if (cmdsSummaryEl) {
|
|
2147
|
-
const cmds = Array.isArray(meta.commands) ? meta.commands : [];
|
|
2148
|
-
cmdsSummaryEl.textContent = `${cmds.length || 4} 条命令`;
|
|
2149
|
-
}
|
|
2150
|
-
const personaSummaryEl = configView.querySelector('[data-cfg-val="persona"]');
|
|
2151
|
-
if (personaSummaryEl) {
|
|
2152
|
-
const pCount = new Set([
|
|
2153
|
-
'architect', 'coder', 'qa', 'auditor',
|
|
2154
|
-
...Object.keys(c.personas || {}),
|
|
2155
|
-
...(Array.isArray(meta.pluginPersonas) ? meta.pluginPersonas.map(p => p.id) : []),
|
|
2156
|
-
]).size;
|
|
2157
|
-
personaSummaryEl.textContent = `${pCount} 套角色`;
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
const cacheEl = configView.querySelector('[data-cfg-val="cache"]');
|
|
2161
|
-
const rate = debugState.telemetry?.hitRatePct ?? (c.timeInjection === 'system_head' ? 0 : c.canvasMemory === 'full' ? 78.8 : 99.4);
|
|
2162
|
-
if (c.timeInjection === 'system_head') {
|
|
2163
|
-
cacheEl.textContent = `${rate}% (系统头破缓存)`;
|
|
2164
|
-
cacheEl.style.color = 'var(--clado-agent-danger)';
|
|
2165
|
-
} else if (c.canvasMemory === 'full') {
|
|
2166
|
-
cacheEl.textContent = `${rate}% 命中`;
|
|
2167
|
-
cacheEl.style.color = '#d97706';
|
|
2168
|
-
} else {
|
|
2169
|
-
cacheEl.textContent = `${rate}% 命中`;
|
|
2170
|
-
cacheEl.style.color = '#059669';
|
|
2171
|
-
}
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
|
-
async function loadDebugConfig() {
|
|
2175
|
-
try {
|
|
2176
|
-
const res = await fetch(configEndpoint, { cache: 'no-store' });
|
|
2177
|
-
if (!res.ok) return;
|
|
2178
|
-
const data = await res.json();
|
|
2179
|
-
if (data.llm) {
|
|
2180
|
-
meta.llm = data.llm;
|
|
2181
|
-
meta.builtinConfigured = Boolean(data.llm.configured);
|
|
2182
|
-
meta.model = data.llm.model;
|
|
2183
|
-
meta.providerId = data.llm.providerId;
|
|
2184
|
-
meta.providerLabel = data.llm.providerLabel;
|
|
2185
|
-
}
|
|
2186
|
-
if (data.mcpUrl) meta.mcpUrl = data.mcpUrl;
|
|
2187
|
-
if (Array.isArray(data.mcpServers)) meta.mcpServers = data.mcpServers;
|
|
2188
|
-
if (Array.isArray(data.skills)) meta.skills = data.skills;
|
|
2189
|
-
if (Array.isArray(data.commands)) meta.commands = data.commands;
|
|
2190
|
-
if (Array.isArray(data.pluginPersonas)) meta.pluginPersonas = data.pluginPersonas;
|
|
2191
|
-
if (data.config) debugState.config = data.config;
|
|
2192
|
-
if (data.memory) debugState.memory = data.memory;
|
|
2193
|
-
if (data.telemetry) debugState.telemetry = data.telemetry;
|
|
2194
|
-
syncModelChip();
|
|
2195
|
-
syncConfigSummaryUI();
|
|
2196
|
-
} catch {}
|
|
2197
|
-
}
|
|
2198
|
-
|
|
2199
|
-
async function saveDebugPatch(patch) {
|
|
2200
|
-
debugState.config = { ...debugState.config, ...patch };
|
|
2201
|
-
syncConfigSummaryUI();
|
|
2202
|
-
try {
|
|
2203
|
-
const res = await fetch(configEndpoint, {
|
|
2204
|
-
method: 'POST',
|
|
2205
|
-
headers: { 'content-type': 'application/json' },
|
|
2206
|
-
body: JSON.stringify({ action: 'save_config', patch }),
|
|
2207
|
-
});
|
|
2208
|
-
if (res.ok) {
|
|
2209
|
-
const data = await res.json();
|
|
2210
|
-
if (data.config) debugState.config = data.config;
|
|
2211
|
-
if (data.telemetry) debugState.telemetry = data.telemetry;
|
|
2212
|
-
syncConfigSummaryUI();
|
|
2213
|
-
}
|
|
2214
|
-
} catch {}
|
|
2215
|
-
}
|
|
2216
|
-
|
|
2217
|
-
async function openSettingsOverlay(initialSub = '') {
|
|
2218
|
-
closeCfgSub();
|
|
2219
|
-
closeModelMenu();
|
|
2220
|
-
closeSlashMenu();
|
|
2221
|
-
closeCtxMenu();
|
|
2222
|
-
configView.classList.add('show');
|
|
2223
|
-
dock.hidden = true;
|
|
2224
|
-
await loadDebugConfig();
|
|
2225
|
-
if (initialSub) {
|
|
2226
|
-
if (initialSub === 'llm' && meta.llm?.providerId) activeProviderDraft = meta.llm.providerId;
|
|
2227
|
-
openCfgSub(initialSub);
|
|
2228
|
-
}
|
|
2229
|
-
}
|
|
2230
|
-
|
|
2231
|
-
function closeSettingsOverlay() {
|
|
2232
|
-
configView.classList.remove('show');
|
|
2233
|
-
dock.hidden = false;
|
|
2234
|
-
requestAnimationFrame(() => updatePeerEdgeFade());
|
|
2235
|
-
}
|
|
2236
|
-
|
|
2237
|
-
function closeCfgSub() {
|
|
2238
|
-
currentSub = null;
|
|
2239
|
-
cfgSubEl.classList.remove('active');
|
|
2240
|
-
cfgHomeEl.classList.remove('pushed-out');
|
|
2241
|
-
}
|
|
2242
|
-
|
|
2243
|
-
function renderLlmSubBody() {
|
|
2244
|
-
const presets = Array.isArray(meta.llm?.presets) && meta.llm.presets.length
|
|
2245
|
-
? meta.llm.presets
|
|
2246
|
-
: [
|
|
2247
|
-
{ id: 'openai', label: 'OpenAI', protocol: 'openai', defaultBaseUrl: 'https://api.openai.com/v1', defaultModel: 'gpt-4.1', models: ['gpt-4.1', 'gpt-4.1-mini', 'gpt-4o'], requiresKey: true },
|
|
2248
|
-
{ id: 'anthropic', label: 'Anthropic', protocol: 'anthropic', defaultBaseUrl: 'https://api.anthropic.com/v1', defaultModel: 'claude-sonnet-4-5', models: ['claude-sonnet-4-5', 'claude-opus-4-5'], requiresKey: true },
|
|
2249
|
-
{ id: 'deepseek', label: 'DeepSeek', protocol: 'openai', defaultBaseUrl: 'https://api.deepseek.com/v1', defaultModel: 'deepseek-chat', models: ['deepseek-chat', 'deepseek-reasoner'], requiresKey: true },
|
|
2250
|
-
{ id: 'openrouter', label: 'OpenRouter', protocol: 'openai', defaultBaseUrl: 'https://openrouter.ai/api/v1', defaultModel: 'anthropic/claude-sonnet-4', models: ['anthropic/claude-sonnet-4', 'openai/gpt-4.1'], requiresKey: true },
|
|
2251
|
-
{ id: 'ollama', label: 'Ollama 本地', protocol: 'openai', defaultBaseUrl: 'http://127.0.0.1:11434/v1', defaultModel: 'qwen2.5-coder:14b', models: ['qwen2.5-coder:14b', 'llama3.3'], requiresKey: false },
|
|
2252
|
-
{ id: 'custom', label: '自定义接口', protocol: 'openai', defaultBaseUrl: 'https://api.openai.com/v1', defaultModel: 'gpt-4.1-mini', models: [], requiresKey: true },
|
|
2253
|
-
];
|
|
2254
|
-
if (!presets.some(p => p.id === activeProviderDraft)) activeProviderDraft = presets[0].id;
|
|
2255
|
-
const preset = presets.find(p => p.id === activeProviderDraft) || presets[0];
|
|
2256
|
-
const prof = meta.llm?.profiles?.[preset.id] || {};
|
|
2257
|
-
const curProtocol = prof.protocol || preset.protocol || 'openai';
|
|
2258
|
-
const curBaseUrl = prof.baseUrl || preset.defaultBaseUrl || '';
|
|
2259
|
-
const curModel = prof.model || preset.defaultModel || '';
|
|
2260
|
-
const modelCandidates = [...new Set([...(prof.models || []), ...(preset.models || [])])].slice(0, 18);
|
|
2261
|
-
const keyPlaceholder = preset.requiresKey === false
|
|
2262
|
-
? '本地模型免 API Key,可直接留空保存'
|
|
2263
|
-
: (prof.hasApiKey ? `已保存 ${prof.maskedKey || '密钥'}(留空保持不变,输入新值则覆盖)` : '输入该供应商的 API Key (如 sk-...)');
|
|
2264
|
-
|
|
2265
|
-
subBodyEl.innerHTML = `
|
|
2266
|
-
<div style="display:flex;flex-wrap:wrap;gap:5px;">
|
|
2267
|
-
${presets.map(p => {
|
|
2268
|
-
const pHas = Boolean(meta.llm?.profiles?.[p.id]?.hasApiKey);
|
|
2269
|
-
const active = p.id === activeProviderDraft;
|
|
2270
|
-
return `<button type="button" class="clado-tab-btn ${active ? 'active' : ''}" data-pick-provider="${p.id}" style="padding:5px 9px;font-size:11.5px;">${p.label.split(' ')[0]}${pHas ? ' · ✓' : ''}</button>`;
|
|
2271
|
-
}).join('')}
|
|
2272
|
-
</div>
|
|
2273
|
-
|
|
2274
|
-
<div style="display:flex;align-items:center;justify-content:space-between;gap:8px;">
|
|
2275
|
-
<span style="font-size:12px;color:var(--clado-ui-muted);">接口协议</span>
|
|
2276
|
-
<div class="clado-tab-group">
|
|
2277
|
-
<button type="button" class="clado-tab-btn ${curProtocol === 'openai' ? 'active' : ''}" data-llm-proto="openai" style="font-size:11.5px;padding:4px 9px;">OpenAI 兼容</button>
|
|
2278
|
-
<button type="button" class="clado-tab-btn ${curProtocol === 'anthropic' ? 'active' : ''}" data-llm-proto="anthropic" style="font-size:11.5px;padding:4px 9px;">Anthropic 原生</button>
|
|
2279
|
-
</div>
|
|
2280
|
-
</div>
|
|
2281
|
-
|
|
2282
|
-
<div>
|
|
2283
|
-
<div style="font-size:12px;color:var(--clado-ui-muted);margin-bottom:4px;">API 地址 (Base URL)</div>
|
|
2284
|
-
<input type="text" class="clado-clean-input" data-llm-base value="${curBaseUrl.replace(/"/g, '"')}" placeholder="https://api.openai.com/v1" />
|
|
2285
|
-
</div>
|
|
2286
|
-
|
|
2287
|
-
<div>
|
|
2288
|
-
<div style="display:flex;justify-content:space-between;font-size:12px;color:var(--clado-ui-muted);margin-bottom:4px;">
|
|
2289
|
-
<span>API Key</span>
|
|
2290
|
-
${prof.hasApiKey ? `<span style="color:#059669;font-weight:600;">已配置 (${prof.maskedKey})</span>` : ''}
|
|
2291
|
-
</div>
|
|
2292
|
-
<input type="password" class="clado-clean-input" data-llm-key autocomplete="off" placeholder="${keyPlaceholder.replace(/"/g, '"')}" />
|
|
2293
|
-
</div>
|
|
2294
|
-
|
|
2295
|
-
<div>
|
|
2296
|
-
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:4px;">
|
|
2297
|
-
<span style="font-size:12px;color:var(--clado-ui-muted);">模型 ID (可手填或拉取)</span>
|
|
2298
|
-
<button type="button" class="clado-tab-btn active" data-llm-fetch style="font-size:11px;padding:3px 8px;">↻ 拉取模型列表</button>
|
|
852
|
+
function renderMemoryTab() {
|
|
853
|
+
const content = meta.memory?.content || '';
|
|
854
|
+
sBody.innerHTML = `
|
|
855
|
+
<div class="clado-setting-row">
|
|
856
|
+
<div>
|
|
857
|
+
<div style="font-size:18px;font-weight:630;">工作区与记忆</div>
|
|
858
|
+
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">直接编辑项目根目录的 <code style="font-family:ui-monospace,monospace;">AGENTS.md</code>,Pi 会话启动时自动加载规范。</div>
|
|
2299
859
|
</div>
|
|
2300
|
-
<
|
|
2301
|
-
${modelCandidates.length ? `
|
|
2302
|
-
<div data-llm-chips style="display:flex;flex-wrap:wrap;gap:5px;margin-top:7px;">
|
|
2303
|
-
${modelCandidates.map(m => `<button type="button" class="clado-tool-chip" data-pick-model="${m.replace(/"/g, '"')}" style="font-size:11px;">${m}</button>`).join('')}
|
|
2304
|
-
</div>` : '<div data-llm-chips style="display:flex;flex-wrap:wrap;gap:5px;margin-top:7px;"></div>'}
|
|
860
|
+
<button type="button" class="clado-ui-button clado-ui-button-primary" data-save-mem>保存 AGENTS.md</button>
|
|
2305
861
|
</div>
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
let selectedProto = curProtocol;
|
|
2310
|
-
subBodyEl.querySelectorAll('[data-pick-provider]').forEach(btn => {
|
|
2311
|
-
btn.onclick = () => {
|
|
2312
|
-
activeProviderDraft = btn.dataset.pickProvider;
|
|
2313
|
-
renderLlmSubBody();
|
|
2314
|
-
};
|
|
2315
|
-
});
|
|
2316
|
-
subBodyEl.querySelectorAll('[data-llm-proto]').forEach(btn => {
|
|
2317
|
-
btn.onclick = () => {
|
|
2318
|
-
selectedProto = btn.dataset.llmProto;
|
|
2319
|
-
subBodyEl.querySelectorAll('[data-llm-proto]').forEach(b => b.classList.toggle('active', b === btn));
|
|
2320
|
-
};
|
|
2321
|
-
});
|
|
2322
|
-
const baseInput = subBodyEl.querySelector('[data-llm-base]');
|
|
2323
|
-
const keyInput = subBodyEl.querySelector('[data-llm-key]');
|
|
2324
|
-
const modelInput = subBodyEl.querySelector('[data-llm-model]');
|
|
2325
|
-
const chipsWrap = subBodyEl.querySelector('[data-llm-chips]');
|
|
2326
|
-
|
|
2327
|
-
const bindModelChips = () => {
|
|
2328
|
-
chipsWrap?.querySelectorAll('[data-pick-model]').forEach(chip => {
|
|
2329
|
-
chip.onclick = () => { modelInput.value = chip.dataset.pickModel; };
|
|
2330
|
-
});
|
|
2331
|
-
};
|
|
2332
|
-
bindModelChips();
|
|
2333
|
-
|
|
2334
|
-
subBodyEl.querySelector('[data-llm-fetch]').onclick = async ev => {
|
|
2335
|
-
const btn = ev.currentTarget;
|
|
2336
|
-
btn.disabled = true;
|
|
2337
|
-
btn.textContent = '拉取中…';
|
|
2338
|
-
try {
|
|
2339
|
-
const res = await fetch(configEndpoint, {
|
|
2340
|
-
method: 'POST',
|
|
2341
|
-
headers: { 'content-type': 'application/json' },
|
|
2342
|
-
body: JSON.stringify({
|
|
2343
|
-
action: 'fetch_models',
|
|
2344
|
-
providerId: activeProviderDraft,
|
|
2345
|
-
protocol: selectedProto,
|
|
2346
|
-
baseUrl: baseInput.value.trim(),
|
|
2347
|
-
apiKey: keyInput.value.trim(),
|
|
2348
|
-
}),
|
|
2349
|
-
});
|
|
2350
|
-
const data = await res.json();
|
|
2351
|
-
if (!res.ok) throw new Error(data.error || '拉取失败');
|
|
2352
|
-
const fetched = Array.isArray(data.models) ? data.models : [];
|
|
2353
|
-
if (fetched.length) {
|
|
2354
|
-
if (!modelInput.value.trim()) modelInput.value = fetched[0];
|
|
2355
|
-
chipsWrap.innerHTML = fetched.slice(0, 24).map(m => `<button type="button" class="clado-tool-chip" data-pick-model="${m.replace(/"/g, '"')}" style="font-size:11px;">${m}</button>`).join('');
|
|
2356
|
-
bindModelChips();
|
|
2357
|
-
showToast(`已拉取 ${fetched.length} 个可用模型`);
|
|
2358
|
-
} else {
|
|
2359
|
-
showToast('接口未返回模型列表,可直接手动输入模型 ID');
|
|
2360
|
-
}
|
|
2361
|
-
} catch (err) {
|
|
2362
|
-
showToast(err.message || '拉取模型失败');
|
|
2363
|
-
} finally {
|
|
2364
|
-
btn.disabled = false;
|
|
2365
|
-
btn.textContent = '↻ 拉取模型列表';
|
|
2366
|
-
}
|
|
2367
|
-
};
|
|
2368
|
-
|
|
2369
|
-
subBodyEl.querySelector('[data-llm-save]').onclick = async ev => {
|
|
2370
|
-
const btn = ev.currentTarget;
|
|
2371
|
-
const typedKey = keyInput.value.trim();
|
|
2372
|
-
if (preset.requiresKey !== false && !prof.hasApiKey && !typedKey) {
|
|
2373
|
-
showToast('请填写 API Key 后保存');
|
|
2374
|
-
keyInput.focus();
|
|
2375
|
-
return;
|
|
2376
|
-
}
|
|
2377
|
-
btn.disabled = true;
|
|
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>
|
|
863
|
+
`;
|
|
864
|
+
sBody.querySelector('[data-save-mem]').onclick = async () => {
|
|
2378
865
|
try {
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
body: JSON.stringify({
|
|
2383
|
-
action: 'save_llm',
|
|
2384
|
-
providerId: activeProviderDraft,
|
|
2385
|
-
label: preset.label,
|
|
2386
|
-
protocol: selectedProto,
|
|
2387
|
-
baseUrl: baseInput.value.trim(),
|
|
2388
|
-
apiKey: typedKey,
|
|
2389
|
-
model: modelInput.value.trim() || preset.defaultModel,
|
|
2390
|
-
}),
|
|
2391
|
-
});
|
|
2392
|
-
const data = await res.json();
|
|
2393
|
-
if (!res.ok) throw new Error(data.error || '保存失败');
|
|
2394
|
-
if (data.llm) {
|
|
2395
|
-
meta.llm = data.llm;
|
|
2396
|
-
meta.builtinConfigured = Boolean(data.llm.configured);
|
|
2397
|
-
meta.model = data.llm.model;
|
|
2398
|
-
meta.providerId = data.llm.providerId;
|
|
2399
|
-
meta.providerLabel = data.llm.providerLabel;
|
|
2400
|
-
}
|
|
2401
|
-
syncModelChip();
|
|
2402
|
-
syncConfigSummaryUI();
|
|
2403
|
-
showToast(`已启用 ${meta.providerLabel} · ${meta.model}`);
|
|
2404
|
-
closeSettingsOverlay();
|
|
2405
|
-
input.focus();
|
|
2406
|
-
} catch (err) {
|
|
2407
|
-
showToast(err.message || '保存失败');
|
|
2408
|
-
} finally {
|
|
2409
|
-
btn.disabled = false;
|
|
2410
|
-
}
|
|
866
|
+
await apiConfig({ action: 'save_memory', content: sBody.querySelector('[data-mem-text]').value });
|
|
867
|
+
showToast('已保存项目 AGENTS.md');
|
|
868
|
+
} catch (e) { showToast(e.message); }
|
|
2411
869
|
};
|
|
2412
870
|
}
|
|
2413
871
|
|
|
2414
|
-
function
|
|
2415
|
-
const
|
|
2416
|
-
|
|
2417
|
-
const customKeys = Object.keys(personas).filter(k => !builtinKeys.includes(k));
|
|
2418
|
-
const allKeys = [...builtinKeys, ...customKeys];
|
|
2419
|
-
if (!allKeys.includes(activePersonaTab)) activePersonaTab = 'architect';
|
|
2420
|
-
const isCustom = !builtinKeys.includes(activePersonaTab);
|
|
2421
|
-
const cur = personas[activePersonaTab] || { name: PERSONA_META[activePersonaTab]?.label || activePersonaTab, prompt: '', initContext: '' };
|
|
2422
|
-
|
|
2423
|
-
subBodyEl.innerHTML = `
|
|
2424
|
-
<div style="display:flex;flex-wrap:wrap;gap:5px;align-items:center;">
|
|
2425
|
-
${allKeys.map(k => {
|
|
2426
|
-
const label = personas[k]?.name || PERSONA_META[k]?.label || k;
|
|
2427
|
-
return `<button type="button" class="clado-tab-btn ${k === activePersonaTab ? 'active' : ''}" data-pick-persona="${k}" style="padding:5px 9px;font-size:11.5px;">${label.slice(0, 8)}</button>`;
|
|
2428
|
-
}).join('')}
|
|
2429
|
-
<button type="button" class="clado-tab-btn" data-add-persona style="padding:5px 9px;font-size:11.5px;color:var(--clado-ui-brand);">+ 新建人设</button>
|
|
2430
|
-
</div>
|
|
2431
|
-
<div>
|
|
2432
|
-
<div style="font-size:12px;color:var(--clado-ui-muted);margin-bottom:4px;">显示名称</div>
|
|
2433
|
-
<input type="text" class="clado-clean-input" data-field="persona-name" />
|
|
2434
|
-
</div>
|
|
2435
|
-
<div>
|
|
2436
|
-
<div style="font-size:12px;color:var(--clado-ui-muted);margin-bottom:4px;">角色提示词</div>
|
|
2437
|
-
<textarea class="clado-clean-textarea" data-field="persona-prompt" rows="4"></textarea>
|
|
2438
|
-
</div>
|
|
872
|
+
function renderAppearanceTab() {
|
|
873
|
+
const isDark = document.documentElement.dataset.theme === 'dark';
|
|
874
|
+
sBody.innerHTML = `
|
|
2439
875
|
<div>
|
|
2440
|
-
<div style="font-size:
|
|
2441
|
-
<
|
|
2442
|
-
</div>
|
|
2443
|
-
<div style="display:flex;gap:8px;">
|
|
2444
|
-
<button type="button" class="clado-cmd-btn allow" data-save-persona style="flex:1;height:34px;font-size:12.5px;border-radius:10px;">保存当前人设</button>
|
|
2445
|
-
${isCustom ? '<button type="button" class="clado-tab-btn active" data-del-persona style="height:34px;padding:0 12px;font-size:12px;color:var(--clado-agent-danger);">删除</button>' : ''}
|
|
2446
|
-
</div>`;
|
|
2447
|
-
|
|
2448
|
-
const nameInput = subBodyEl.querySelector('[data-field="persona-name"]');
|
|
2449
|
-
const promptArea = subBodyEl.querySelector('[data-field="persona-prompt"]');
|
|
2450
|
-
const ctxArea = subBodyEl.querySelector('[data-field="persona-ctx"]');
|
|
2451
|
-
nameInput.value = cur.name || PERSONA_META[activePersonaTab]?.label || activePersonaTab;
|
|
2452
|
-
promptArea.value = cur.prompt || '';
|
|
2453
|
-
ctxArea.value = cur.initContext || '';
|
|
2454
|
-
|
|
2455
|
-
subBodyEl.querySelectorAll('[data-pick-persona]').forEach(b => {
|
|
2456
|
-
b.onclick = () => {
|
|
2457
|
-
activePersonaTab = b.dataset.pickPersona;
|
|
2458
|
-
renderPersonaSubBody();
|
|
2459
|
-
};
|
|
2460
|
-
});
|
|
2461
|
-
subBodyEl.querySelector('[data-add-persona]').onclick = () => {
|
|
2462
|
-
const raw = window.prompt('输入新人设标识(英文字母/数字/连字符,如 pm、dba、reviewer):', 'reviewer');
|
|
2463
|
-
if (!raw || !raw.trim()) return;
|
|
2464
|
-
const slug = raw.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 31);
|
|
2465
|
-
if (!slug) { showToast('标识格式无效'); return; }
|
|
2466
|
-
if (!debugState.config.personas) debugState.config.personas = {};
|
|
2467
|
-
if (!debugState.config.personas[slug]) {
|
|
2468
|
-
debugState.config.personas[slug] = { name: raw.trim(), prompt: '', initContext: '' };
|
|
2469
|
-
}
|
|
2470
|
-
activePersonaTab = slug;
|
|
2471
|
-
renderPersonaSubBody();
|
|
2472
|
-
};
|
|
2473
|
-
subBodyEl.querySelector('[data-save-persona]').onclick = async () => {
|
|
2474
|
-
const nextPersonas = {
|
|
2475
|
-
...(debugState.config.personas || {}),
|
|
2476
|
-
[activePersonaTab]: {
|
|
2477
|
-
...cur,
|
|
2478
|
-
name: nameInput.value.trim() || activePersonaTab,
|
|
2479
|
-
prompt: promptArea.value,
|
|
2480
|
-
initContext: ctxArea.value,
|
|
2481
|
-
},
|
|
2482
|
-
};
|
|
2483
|
-
await saveDebugPatch({ personas: nextPersonas });
|
|
2484
|
-
await loadMeta();
|
|
2485
|
-
showToast('已保存人设与分身角色');
|
|
2486
|
-
renderPersonaSubBody();
|
|
2487
|
-
};
|
|
2488
|
-
subBodyEl.querySelector('[data-del-persona]')?.addEventListener('click', async () => {
|
|
2489
|
-
try {
|
|
2490
|
-
const res = await fetch(configEndpoint, {
|
|
2491
|
-
method: 'POST',
|
|
2492
|
-
headers: { 'content-type': 'application/json' },
|
|
2493
|
-
body: JSON.stringify({ action: 'delete_persona', id: activePersonaTab }),
|
|
2494
|
-
});
|
|
2495
|
-
if (res.ok) {
|
|
2496
|
-
const data = await res.json();
|
|
2497
|
-
if (data.config) debugState.config = data.config;
|
|
2498
|
-
activePersonaTab = 'architect';
|
|
2499
|
-
await loadMeta();
|
|
2500
|
-
syncConfigSummaryUI();
|
|
2501
|
-
renderPersonaSubBody();
|
|
2502
|
-
showToast('已删除自定义人设');
|
|
2503
|
-
}
|
|
2504
|
-
} catch {}
|
|
2505
|
-
});
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2508
|
-
let mcpModeTab = 'client';
|
|
2509
|
-
let mcpAddMode = 'form';
|
|
2510
|
-
let mcpAddType = 'stdio';
|
|
2511
|
-
let mcpScope = 'workspace';
|
|
2512
|
-
|
|
2513
|
-
function renderMcpSubBody() {
|
|
2514
|
-
const servers = Array.isArray(meta.mcpServers) ? meta.mcpServers : [];
|
|
2515
|
-
const liveMcp = meta.mcpUrl || (location.origin + '/mcp');
|
|
2516
|
-
const mcpSnippet = JSON.stringify({ mcpServers: { clado: { type: 'http', url: liveMcp } } }, null, 2);
|
|
2517
|
-
|
|
2518
|
-
subBodyEl.innerHTML = `
|
|
2519
|
-
<div class="clado-tab-group" style="display:grid;grid-template-columns:1fr 1fr;width:100%;">
|
|
2520
|
-
<button type="button" class="clado-tab-btn ${mcpModeTab === 'client' ? 'active' : ''}" data-mcp-tab="client" style="font-size:12px;">接入外部 MCP (${servers.length})</button>
|
|
2521
|
-
<button type="button" class="clado-tab-btn ${mcpModeTab === 'server' ? 'active' : ''}" data-mcp-tab="server" style="font-size:12px;">暴露本机画布 MCP</button>
|
|
876
|
+
<div style="font-size:18px;font-weight:630;">外观与连接</div>
|
|
877
|
+
<div style="font-size:12.5px;color:var(--clado-ui-muted);margin-top:4px;">液态冰晶玻璃主题、画布导出与外部 /mcp 互联端点。</div>
|
|
2522
878
|
</div>
|
|
2523
|
-
|
|
2524
|
-
<div style="display:flex;flex-direction:column;gap:7px;">
|
|
2525
|
-
${servers.length ? servers.map(s => `
|
|
2526
|
-
<div class="clado-eco-card">
|
|
2527
|
-
<div class="clado-eco-row">
|
|
2528
|
-
<div style="min-width:0;">
|
|
2529
|
-
<strong style="font-size:12.5px;">${s.name}</strong>
|
|
2530
|
-
<span class="clado-eco-badge" style="margin-left:5px;">${s.type.toUpperCase()} · ${s.scope === 'global' ? '全局' : s.scope === 'plugin' ? '插件' : '工作区'}</span>
|
|
2531
|
-
</div>
|
|
2532
|
-
<div style="display:flex;gap:5px;align-items:center;">
|
|
2533
|
-
<button type="button" class="clado-tab-btn active" data-mcp-test="${s.name}" style="font-size:11px;padding:3px 7px;">测试</button>
|
|
2534
|
-
${s.scope !== 'plugin' ? `<button type="button" class="clado-switch-btn ${s.enabled !== false ? 'on' : ''}" data-mcp-toggle="${s.name}" data-mcp-scope="${s.scope}"><i></i></button>` : ''}
|
|
2535
|
-
${s.scope !== 'plugin' ? `<button type="button" class="clado-tab-btn" data-mcp-del="${s.name}" data-mcp-scope="${s.scope}" style="font-size:11px;padding:3px 6px;color:var(--clado-agent-danger);">删</button>` : ''}
|
|
2536
|
-
</div>
|
|
2537
|
-
</div>
|
|
2538
|
-
<div style="font-size:11px;color:var(--clado-ui-muted);font-family:ui-monospace,SFMono-Regular,Menlo,monospace;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">
|
|
2539
|
-
${s.type === 'http' ? s.url : [s.command, ...(s.args || [])].join(' ')}
|
|
2540
|
-
</div>
|
|
2541
|
-
</div>
|
|
2542
|
-
`).join('') : '<div style="font-size:12px;color:var(--clado-ui-muted);padding:6px 2px;">尚未挂载外部 MCP Server。添加后,Clado 原生 Agent 将自动发现并调用外部工具(GitHub / DB / 浏览器等)。</div>'}
|
|
2543
|
-
</div>
|
|
2544
|
-
|
|
2545
|
-
<div class="clado-eco-card">
|
|
2546
|
-
<div class="clado-eco-row">
|
|
2547
|
-
<strong style="font-size:12px;">+ 添加外部 MCP Server</strong>
|
|
2548
|
-
<div style="display:flex;gap:4px;">
|
|
2549
|
-
<button type="button" class="clado-tab-btn ${mcpAddMode === 'form' ? 'active' : ''}" data-mcp-add-mode="form" style="font-size:11px;padding:2px 7px;">表单</button>
|
|
2550
|
-
<button type="button" class="clado-tab-btn ${mcpAddMode === 'json' ? 'active' : ''}" data-mcp-add-mode="json" style="font-size:11px;padding:2px 7px;">粘贴 JSON</button>
|
|
2551
|
-
</div>
|
|
2552
|
-
</div>
|
|
2553
|
-
<div class="clado-eco-row" style="font-size:11.5px;color:var(--clado-ui-muted);">
|
|
2554
|
-
<span>保存范围</span>
|
|
2555
|
-
<div class="clado-tab-group">
|
|
2556
|
-
<button type="button" class="clado-tab-btn ${mcpScope === 'workspace' ? 'active' : ''}" data-mcp-pick-scope="workspace" style="font-size:11px;padding:2px 8px;">当前工作区</button>
|
|
2557
|
-
<button type="button" class="clado-tab-btn ${mcpScope === 'global' ? 'active' : ''}" data-mcp-pick-scope="global" style="font-size:11px;padding:2px 8px;">全局通用</button>
|
|
2558
|
-
</div>
|
|
2559
|
-
</div>
|
|
2560
|
-
${mcpAddMode === 'form' ? `
|
|
2561
|
-
<div style="display:flex;gap:6px;">
|
|
2562
|
-
<input type="text" class="clado-clean-input" data-mcp-name placeholder="服务名(如 github / playwright)" style="flex:1.2;" />
|
|
2563
|
-
<button type="button" class="clado-tab-btn ${mcpAddType === 'stdio' ? 'active' : ''}" data-mcp-type="stdio" style="font-size:11px;padding:0 8px;">Stdio</button>
|
|
2564
|
-
<button type="button" class="clado-tab-btn ${mcpAddType === 'http' ? 'active' : ''}" data-mcp-type="http" style="font-size:11px;padding:0 8px;">HTTP</button>
|
|
2565
|
-
</div>
|
|
2566
|
-
${mcpAddType === 'stdio' ? `
|
|
2567
|
-
<input type="text" class="clado-clean-input" data-mcp-cmd placeholder="启动命令(如 npx / node / uvx)" />
|
|
2568
|
-
<input type="text" class="clado-clean-input" data-mcp-args placeholder="参数,空格分隔(如 -y @modelcontextprotocol/server-github)" />
|
|
2569
|
-
` : `
|
|
2570
|
-
<input type="text" class="clado-clean-input" data-mcp-url placeholder="HTTP MCP 地址(如 http://127.0.0.1:4318/mcp)" />
|
|
2571
|
-
`}
|
|
2572
|
-
<button type="button" class="clado-cmd-btn allow" data-mcp-save style="height:33px;font-size:12px;border-radius:10px;">保存并启用 MCP Server</button>
|
|
2573
|
-
` : `
|
|
2574
|
-
<textarea class="clado-clean-textarea" data-mcp-json rows="5" placeholder='{"mcpServers":{"demo":{"type":"http","url":"http://127.0.0.1:4318/mcp"}}}'></textarea>
|
|
2575
|
-
<button type="button" class="clado-cmd-btn allow" data-mcp-import style="height:33px;font-size:12px;border-radius:10px;">导入 mcpServers JSON</button>
|
|
2576
|
-
`}
|
|
2577
|
-
</div>
|
|
2578
|
-
` : `
|
|
2579
|
-
<div style="font-size:12px;color:var(--clado-ui-muted);line-height:1.5;">
|
|
2580
|
-
<strong>Clado 内置原生工具集(已自动挂载)</strong><br/>
|
|
2581
|
-
画布文档与节点(<code>clado_workspace / documents / nodes / links / batch / templates</code>)、本地代码探针(<code>probe_tree / search / read / git_diff / command</code>)、画布多实例组件(<code>canvas_objects_read / write</code>)、技能按需加载(<code>load_skill</code>)及同伴分身协作(<code>spawn_peer / message_peer</code>)。
|
|
2582
|
-
</div>
|
|
879
|
+
<div class="clado-well-box clado-setting-row">
|
|
2583
880
|
<div>
|
|
2584
|
-
<div style="
|
|
2585
|
-
|
|
2586
|
-
<button type="button" class="clado-cmd-btn allow" data-copy-mcp style="font-size:11px;padding:4px 9px;">复制 MCP JSON</button>
|
|
2587
|
-
</div>
|
|
2588
|
-
<pre class="clado-clean-textarea" style="margin:0;white-space:pre-wrap;font-size:11.5px;">${mcpSnippet}</pre>
|
|
881
|
+
<div style="font-size:13.5px;font-weight:610;">明暗主题</div>
|
|
882
|
+
<div style="font-size:12px;color:var(--clado-ui-muted);margin-top:2px;">浅色通透液态玻璃 / 深色暗夜烟熏玻璃。</div>
|
|
2589
883
|
</div>
|
|
2590
|
-
<button type="button" class="clado-
|
|
2591
|
-
`}`;
|
|
2592
|
-
|
|
2593
|
-
subBodyEl.querySelectorAll('[data-mcp-tab]').forEach(b => {
|
|
2594
|
-
b.onclick = () => { mcpModeTab = b.dataset.mcpTab; renderMcpSubBody(); };
|
|
2595
|
-
});
|
|
2596
|
-
subBodyEl.querySelectorAll('[data-mcp-add-mode]').forEach(b => {
|
|
2597
|
-
b.onclick = () => { mcpAddMode = b.dataset.mcpAddMode; renderMcpSubBody(); };
|
|
2598
|
-
});
|
|
2599
|
-
subBodyEl.querySelectorAll('[data-mcp-type]').forEach(b => {
|
|
2600
|
-
b.onclick = () => { mcpAddType = b.dataset.mcpType; renderMcpSubBody(); };
|
|
2601
|
-
});
|
|
2602
|
-
subBodyEl.querySelectorAll('[data-mcp-pick-scope]').forEach(b => {
|
|
2603
|
-
b.onclick = () => { mcpScope = b.dataset.mcpPickScope; renderMcpSubBody(); };
|
|
2604
|
-
});
|
|
2605
|
-
subBodyEl.querySelectorAll('[data-mcp-toggle]').forEach(sw => {
|
|
2606
|
-
sw.onclick = async () => {
|
|
2607
|
-
const next = !sw.classList.contains('on');
|
|
2608
|
-
const res = await fetch(configEndpoint, {
|
|
2609
|
-
method: 'POST',
|
|
2610
|
-
headers: { 'content-type': 'application/json' },
|
|
2611
|
-
body: JSON.stringify({ action: 'toggle_mcp', name: sw.dataset.mcpToggle, scope: sw.dataset.mcpScope, enabled: next }),
|
|
2612
|
-
});
|
|
2613
|
-
if (res.ok) {
|
|
2614
|
-
const data = await res.json();
|
|
2615
|
-
if (Array.isArray(data.mcpServers)) meta.mcpServers = data.mcpServers;
|
|
2616
|
-
syncConfigSummaryUI();
|
|
2617
|
-
renderMcpSubBody();
|
|
2618
|
-
}
|
|
2619
|
-
};
|
|
2620
|
-
});
|
|
2621
|
-
subBodyEl.querySelectorAll('[data-mcp-del]').forEach(btn => {
|
|
2622
|
-
btn.onclick = async () => {
|
|
2623
|
-
const res = await fetch(configEndpoint, {
|
|
2624
|
-
method: 'POST',
|
|
2625
|
-
headers: { 'content-type': 'application/json' },
|
|
2626
|
-
body: JSON.stringify({ action: 'delete_mcp', name: btn.dataset.mcpDel, scope: btn.dataset.mcpScope }),
|
|
2627
|
-
});
|
|
2628
|
-
if (res.ok) {
|
|
2629
|
-
const data = await res.json();
|
|
2630
|
-
if (Array.isArray(data.mcpServers)) meta.mcpServers = data.mcpServers;
|
|
2631
|
-
syncConfigSummaryUI();
|
|
2632
|
-
renderMcpSubBody();
|
|
2633
|
-
showToast(`已移除 MCP 服务 ${btn.dataset.mcpDel}`);
|
|
2634
|
-
}
|
|
2635
|
-
};
|
|
2636
|
-
});
|
|
2637
|
-
subBodyEl.querySelectorAll('[data-mcp-test]').forEach(btn => {
|
|
2638
|
-
btn.onclick = async () => {
|
|
2639
|
-
btn.disabled = true;
|
|
2640
|
-
btn.textContent = '测试中…';
|
|
2641
|
-
try {
|
|
2642
|
-
const res = await fetch(configEndpoint, {
|
|
2643
|
-
method: 'POST',
|
|
2644
|
-
headers: { 'content-type': 'application/json' },
|
|
2645
|
-
body: JSON.stringify({ action: 'test_mcp', name: btn.dataset.mcpTest }),
|
|
2646
|
-
});
|
|
2647
|
-
const r = await res.json();
|
|
2648
|
-
showToast(r.ok ? `连通成功:发现 ${r.toolCount} 个工具 (${r.latencyMs}ms)` : `连接失败:${r.error || '未知错误'}`);
|
|
2649
|
-
} catch {
|
|
2650
|
-
showToast('测试请求失败');
|
|
2651
|
-
} finally {
|
|
2652
|
-
btn.disabled = false;
|
|
2653
|
-
btn.textContent = '测试';
|
|
2654
|
-
}
|
|
2655
|
-
};
|
|
2656
|
-
});
|
|
2657
|
-
subBodyEl.querySelector('[data-mcp-save]')?.addEventListener('click', async () => {
|
|
2658
|
-
const name = subBodyEl.querySelector('[data-mcp-name]')?.value.trim() || '';
|
|
2659
|
-
const cfg = mcpAddType === 'http'
|
|
2660
|
-
? { type: 'http', url: subBodyEl.querySelector('[data-mcp-url]')?.value.trim() || '' }
|
|
2661
|
-
: { type: 'stdio', command: subBodyEl.querySelector('[data-mcp-cmd]')?.value.trim() || '', args: subBodyEl.querySelector('[data-mcp-args]')?.value.trim() || '' };
|
|
2662
|
-
try {
|
|
2663
|
-
const res = await fetch(configEndpoint, {
|
|
2664
|
-
method: 'POST',
|
|
2665
|
-
headers: { 'content-type': 'application/json' },
|
|
2666
|
-
body: JSON.stringify({ action: 'save_mcp', name, scope: mcpScope, config: cfg }),
|
|
2667
|
-
});
|
|
2668
|
-
const data = await res.json();
|
|
2669
|
-
if (!res.ok) throw new Error(data.error || '保存失败');
|
|
2670
|
-
if (Array.isArray(data.mcpServers)) meta.mcpServers = data.mcpServers;
|
|
2671
|
-
syncConfigSummaryUI();
|
|
2672
|
-
renderMcpSubBody();
|
|
2673
|
-
showToast(`已保存 MCP 服务 ${name}`);
|
|
2674
|
-
} catch (err) {
|
|
2675
|
-
showToast(err.message || '保存失败');
|
|
2676
|
-
}
|
|
2677
|
-
});
|
|
2678
|
-
subBodyEl.querySelector('[data-mcp-import]')?.addEventListener('click', async () => {
|
|
2679
|
-
const jsonText = subBodyEl.querySelector('[data-mcp-json]')?.value || '';
|
|
2680
|
-
try {
|
|
2681
|
-
const res = await fetch(configEndpoint, {
|
|
2682
|
-
method: 'POST',
|
|
2683
|
-
headers: { 'content-type': 'application/json' },
|
|
2684
|
-
body: JSON.stringify({ action: 'import_mcp_json', scope: mcpScope, jsonText }),
|
|
2685
|
-
});
|
|
2686
|
-
const data = await res.json();
|
|
2687
|
-
if (!res.ok) throw new Error(data.error || '导入失败');
|
|
2688
|
-
if (Array.isArray(data.mcpServers)) meta.mcpServers = data.mcpServers;
|
|
2689
|
-
syncConfigSummaryUI();
|
|
2690
|
-
renderMcpSubBody();
|
|
2691
|
-
showToast(`已导入 ${(data.imported || []).length} 个 MCP 服务`);
|
|
2692
|
-
} catch (err) {
|
|
2693
|
-
showToast(err.message || '导入失败');
|
|
2694
|
-
}
|
|
2695
|
-
});
|
|
2696
|
-
subBodyEl.querySelector('[data-copy-mcp]')?.addEventListener('click', async () => {
|
|
2697
|
-
try { await navigator.clipboard.writeText(mcpSnippet); showToast('已复制 MCP 配置 JSON'); }
|
|
2698
|
-
catch { showToast(liveMcp); }
|
|
2699
|
-
});
|
|
2700
|
-
subBodyEl.querySelector('[data-open-market-from-mcp]')?.addEventListener('click', () => {
|
|
2701
|
-
closeSettingsOverlay();
|
|
2702
|
-
window.dispatchEvent(new CustomEvent('clado:open-market'));
|
|
2703
|
-
});
|
|
2704
|
-
}
|
|
2705
|
-
|
|
2706
|
-
let skillDraft = { slug: '', name: '', description: '', body: '', scope: 'workspace' };
|
|
2707
|
-
function renderSkillsSubBody() {
|
|
2708
|
-
const skills = Array.isArray(meta.skills) ? meta.skills : [];
|
|
2709
|
-
subBodyEl.innerHTML = `
|
|
2710
|
-
<div style="font-size:12px;color:var(--clado-ui-muted);line-height:1.45;">
|
|
2711
|
-
标准 <code>SKILL.md</code> 技能库:平时仅向 Agent 暴露名称与简介(极低 Token 占用),任务匹配时通过 <code>load_skill</code> 按需读取全文。
|
|
2712
|
-
</div>
|
|
2713
|
-
<div style="display:flex;flex-direction:column;gap:6px;">
|
|
2714
|
-
${skills.length ? skills.map(s => `
|
|
2715
|
-
<div class="clado-eco-card">
|
|
2716
|
-
<div class="clado-eco-row">
|
|
2717
|
-
<div><strong>${s.name}</strong> <span class="clado-eco-badge">${s.slug} · ${s.scope === 'global' ? '全局' : s.scope === 'plugin' ? '插件' : '工作区'}</span></div>
|
|
2718
|
-
<div style="display:flex;gap:4px;">
|
|
2719
|
-
${s.scope !== 'plugin' ? `<button type="button" class="clado-tab-btn active" data-skill-edit="${s.slug}" style="font-size:11px;padding:2px 7px;">编辑</button>` : ''}
|
|
2720
|
-
${s.scope !== 'plugin' ? `<button type="button" class="clado-tab-btn" data-skill-del="${s.slug}" data-skill-scope="${s.scope}" style="font-size:11px;padding:2px 6px;color:var(--clado-agent-danger);">删</button>` : ''}
|
|
2721
|
-
</div>
|
|
2722
|
-
</div>
|
|
2723
|
-
<div style="font-size:11.5px;color:var(--clado-ui-muted);">${s.description || ''}</div>
|
|
2724
|
-
</div>
|
|
2725
|
-
`).join('') : '<div style="font-size:12px;color:var(--clado-ui-muted);padding:4px 2px;">暂无技能,可在下方新建第一条 SKILL.md,或从插件市场一键安装。</div>'}
|
|
884
|
+
<button type="button" class="clado-ui-button clado-ui-button-primary" data-toggle-theme>${isDark ? '切换浅色' : '切换暗色'}</button>
|
|
2726
885
|
</div>
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
<div
|
|
2731
|
-
|
|
2732
|
-
<button type="button" class="clado-tab-btn ${skillDraft.scope === 'global' ? 'active' : ''}" data-skill-scope-pick="global" style="font-size:11px;padding:2px 7px;">全局</button>
|
|
2733
|
-
</div>
|
|
886
|
+
${actions.capture ? `
|
|
887
|
+
<div class="clado-well-box clado-setting-row">
|
|
888
|
+
<div>
|
|
889
|
+
<div style="font-size:13.5px;font-weight:610;">导出高清画布截图</div>
|
|
890
|
+
<div style="font-size:12px;color:var(--clado-ui-muted);margin-top:2px;">将当前空间画布保存为 PNG 图片分享给团队。</div>
|
|
2734
891
|
</div>
|
|
2735
|
-
<
|
|
2736
|
-
|
|
2737
|
-
|
|
892
|
+
<button type="button" class="clado-ui-button" data-cap-shot style="border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);">立即截图</button>
|
|
893
|
+
</div>` : ''}
|
|
894
|
+
<div class="clado-well-box clado-setting-row">
|
|
895
|
+
<div>
|
|
896
|
+
<div style="font-size:13.5px;font-weight:610;">对外暴露 Clado MCP 端点</div>
|
|
897
|
+
<div style="font-family:ui-monospace,monospace;font-size:11.5px;color:var(--clado-ui-muted);margin-top:2px;">${esc(meta.mcpUrl || location.origin + '/mcp')}</div>
|
|
2738
898
|
</div>
|
|
2739
|
-
<
|
|
2740
|
-
<textarea class="clado-clean-textarea" data-skill-body rows="5" placeholder="# 操作指南 1. 先检查… 2. 再核对…"></textarea>
|
|
2741
|
-
<button type="button" class="clado-cmd-btn allow" data-skill-save style="height:33px;font-size:12px;border-radius:10px;">保存 SKILL.md</button>
|
|
2742
|
-
</div>`;
|
|
2743
|
-
|
|
2744
|
-
subBodyEl.querySelector('[data-skill-slug]').value = skillDraft.slug || '';
|
|
2745
|
-
subBodyEl.querySelector('[data-skill-name]').value = skillDraft.name || '';
|
|
2746
|
-
subBodyEl.querySelector('[data-skill-desc]').value = skillDraft.description || '';
|
|
2747
|
-
subBodyEl.querySelector('[data-skill-body]').value = skillDraft.body || '';
|
|
2748
|
-
|
|
2749
|
-
subBodyEl.querySelectorAll('[data-skill-scope-pick]').forEach(b => {
|
|
2750
|
-
b.onclick = () => { skillDraft.scope = b.dataset.skillScopePick; renderSkillsSubBody(); };
|
|
2751
|
-
});
|
|
2752
|
-
subBodyEl.querySelectorAll('[data-skill-edit]').forEach(b => {
|
|
2753
|
-
b.onclick = () => {
|
|
2754
|
-
const hit = skills.find(s => s.slug === b.dataset.skillEdit);
|
|
2755
|
-
if (hit) {
|
|
2756
|
-
skillDraft = { slug: hit.slug, name: hit.name, description: hit.description, body: hit.body || '', scope: hit.scope === 'global' ? 'global' : 'workspace' };
|
|
2757
|
-
renderSkillsSubBody();
|
|
2758
|
-
}
|
|
2759
|
-
};
|
|
2760
|
-
});
|
|
2761
|
-
subBodyEl.querySelectorAll('[data-skill-del]').forEach(b => {
|
|
2762
|
-
b.onclick = async () => {
|
|
2763
|
-
const res = await fetch(configEndpoint, {
|
|
2764
|
-
method: 'POST',
|
|
2765
|
-
headers: { 'content-type': 'application/json' },
|
|
2766
|
-
body: JSON.stringify({ action: 'delete_skill', slug: b.dataset.skillDel, scope: b.dataset.skillScope }),
|
|
2767
|
-
});
|
|
2768
|
-
if (res.ok) {
|
|
2769
|
-
const data = await res.json();
|
|
2770
|
-
if (Array.isArray(data.skills)) meta.skills = data.skills;
|
|
2771
|
-
syncConfigSummaryUI();
|
|
2772
|
-
renderSkillsSubBody();
|
|
2773
|
-
showToast(`已删除技能 ${b.dataset.skillDel}`);
|
|
2774
|
-
}
|
|
2775
|
-
};
|
|
2776
|
-
});
|
|
2777
|
-
subBodyEl.querySelector('[data-skill-save]').onclick = async () => {
|
|
2778
|
-
const payload = {
|
|
2779
|
-
action: 'save_skill',
|
|
2780
|
-
slug: subBodyEl.querySelector('[data-skill-slug]').value.trim(),
|
|
2781
|
-
name: subBodyEl.querySelector('[data-skill-name]').value.trim(),
|
|
2782
|
-
description: subBodyEl.querySelector('[data-skill-desc]').value.trim(),
|
|
2783
|
-
body: subBodyEl.querySelector('[data-skill-body]').value,
|
|
2784
|
-
scope: skillDraft.scope,
|
|
2785
|
-
};
|
|
2786
|
-
try {
|
|
2787
|
-
const res = await fetch(configEndpoint, {
|
|
2788
|
-
method: 'POST',
|
|
2789
|
-
headers: { 'content-type': 'application/json' },
|
|
2790
|
-
body: JSON.stringify(payload),
|
|
2791
|
-
});
|
|
2792
|
-
const data = await res.json();
|
|
2793
|
-
if (!res.ok) throw new Error(data.error || '保存失败');
|
|
2794
|
-
if (Array.isArray(data.skills)) meta.skills = data.skills;
|
|
2795
|
-
skillDraft = { slug: '', name: '', description: '', body: '', scope: skillDraft.scope };
|
|
2796
|
-
syncConfigSummaryUI();
|
|
2797
|
-
renderSkillsSubBody();
|
|
2798
|
-
showToast(`已保存技能 ${data.skill?.slug || ''}`);
|
|
2799
|
-
} catch (err) {
|
|
2800
|
-
showToast(err.message || '保存技能失败');
|
|
2801
|
-
}
|
|
2802
|
-
};
|
|
2803
|
-
}
|
|
2804
|
-
|
|
2805
|
-
let cmdDraft = { name: '', description: '', skill: '', prompt: '', scope: 'workspace' };
|
|
2806
|
-
function renderCommandsSubBody() {
|
|
2807
|
-
const commands = Array.isArray(meta.commands) ? meta.commands : [];
|
|
2808
|
-
subBodyEl.innerHTML = `
|
|
2809
|
-
<div style="font-size:12px;color:var(--clado-ui-muted);line-height:1.45;">
|
|
2810
|
-
在右下角输入框敲 <code>/</code> 即可自动补全并一键触发命令;支持 <code>{{args}}</code> 占位符和自动预加载关联技能。
|
|
2811
|
-
</div>
|
|
2812
|
-
<div style="display:flex;flex-direction:column;gap:6px;">
|
|
2813
|
-
${commands.map(c => `
|
|
2814
|
-
<div class="clado-eco-card">
|
|
2815
|
-
<div class="clado-eco-row">
|
|
2816
|
-
<div><strong style="font-family:ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--clado-ui-brand);">/${c.name}</strong> <span class="clado-eco-badge">${c.scope === 'builtin' ? '内置' : c.scope === 'plugin' ? '插件' : c.scope === 'global' ? '全局' : '工作区'}</span></div>
|
|
2817
|
-
<div style="display:flex;gap:4px;">
|
|
2818
|
-
${c.scope !== 'builtin' && c.scope !== 'plugin' ? `<button type="button" class="clado-tab-btn active" data-cmd-edit="${c.name}" style="font-size:11px;padding:2px 7px;">编辑</button>` : ''}
|
|
2819
|
-
${c.scope !== 'builtin' && c.scope !== 'plugin' ? `<button type="button" class="clado-tab-btn" data-cmd-del="${c.name}" data-cmd-scope="${c.scope}" style="font-size:11px;padding:2px 6px;color:var(--clado-agent-danger);">删</button>` : ''}
|
|
2820
|
-
</div>
|
|
2821
|
-
</div>
|
|
2822
|
-
<div style="font-size:11.5px;color:var(--clado-ui-muted);">${c.description || ''}${c.skill ? ` · 关联技能 ${c.skill}` : ''}</div>
|
|
2823
|
-
</div>
|
|
2824
|
-
`).join('')}
|
|
899
|
+
<button type="button" class="clado-ui-button" data-copy-mcp style="border-color:var(--clado-ui-well-border);background:var(--clado-ui-well);">复制地址</button>
|
|
2825
900
|
</div>
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
</div>
|
|
2838
|
-
<input type="text" class="clado-clean-input" data-cmd-desc placeholder="命令简介(如 代码审查与边界核验)" />
|
|
2839
|
-
<textarea class="clado-clean-textarea" data-cmd-prompt rows="4" placeholder="请针对 {{args}} 进行全面审查,输出风险与修改建议…"></textarea>
|
|
2840
|
-
<button type="button" class="clado-cmd-btn allow" data-cmd-save style="height:33px;font-size:12px;border-radius:10px;">保存斜杠命令</button>
|
|
2841
|
-
</div>`;
|
|
2842
|
-
|
|
2843
|
-
subBodyEl.querySelector('[data-cmd-name]').value = cmdDraft.name || '';
|
|
2844
|
-
subBodyEl.querySelector('[data-cmd-skill]').value = cmdDraft.skill || '';
|
|
2845
|
-
subBodyEl.querySelector('[data-cmd-desc]').value = cmdDraft.description || '';
|
|
2846
|
-
subBodyEl.querySelector('[data-cmd-prompt]').value = cmdDraft.prompt || '';
|
|
2847
|
-
|
|
2848
|
-
subBodyEl.querySelectorAll('[data-cmd-scope-pick]').forEach(b => {
|
|
2849
|
-
b.onclick = () => { cmdDraft.scope = b.dataset.cmdScopePick; renderCommandsSubBody(); };
|
|
2850
|
-
});
|
|
2851
|
-
subBodyEl.querySelectorAll('[data-cmd-edit]').forEach(b => {
|
|
2852
|
-
b.onclick = () => {
|
|
2853
|
-
const hit = commands.find(c => c.name === b.dataset.cmdEdit);
|
|
2854
|
-
if (hit) {
|
|
2855
|
-
cmdDraft = { name: hit.name, description: hit.description || '', skill: hit.skill || '', prompt: hit.prompt || '', scope: hit.scope === 'global' ? 'global' : 'workspace' };
|
|
2856
|
-
renderCommandsSubBody();
|
|
2857
|
-
}
|
|
2858
|
-
};
|
|
2859
|
-
});
|
|
2860
|
-
subBodyEl.querySelectorAll('[data-cmd-del]').forEach(b => {
|
|
2861
|
-
b.onclick = async () => {
|
|
2862
|
-
const res = await fetch(configEndpoint, {
|
|
2863
|
-
method: 'POST',
|
|
2864
|
-
headers: { 'content-type': 'application/json' },
|
|
2865
|
-
body: JSON.stringify({ action: 'delete_command', name: b.dataset.cmdDel, scope: b.dataset.cmdScope }),
|
|
2866
|
-
});
|
|
2867
|
-
if (res.ok) {
|
|
2868
|
-
const data = await res.json();
|
|
2869
|
-
if (Array.isArray(data.commands)) meta.commands = data.commands;
|
|
2870
|
-
syncConfigSummaryUI();
|
|
2871
|
-
renderCommandsSubBody();
|
|
2872
|
-
showToast(`已删除命令 /${b.dataset.cmdDel}`);
|
|
2873
|
-
}
|
|
2874
|
-
};
|
|
2875
|
-
});
|
|
2876
|
-
subBodyEl.querySelector('[data-cmd-save]').onclick = async () => {
|
|
2877
|
-
const payload = {
|
|
2878
|
-
action: 'save_command',
|
|
2879
|
-
name: subBodyEl.querySelector('[data-cmd-name]').value.trim(),
|
|
2880
|
-
skill: subBodyEl.querySelector('[data-cmd-skill]').value.trim(),
|
|
2881
|
-
description: subBodyEl.querySelector('[data-cmd-desc]').value.trim(),
|
|
2882
|
-
prompt: subBodyEl.querySelector('[data-cmd-prompt]').value,
|
|
2883
|
-
scope: cmdDraft.scope,
|
|
2884
|
-
};
|
|
2885
|
-
try {
|
|
2886
|
-
const res = await fetch(configEndpoint, {
|
|
2887
|
-
method: 'POST',
|
|
2888
|
-
headers: { 'content-type': 'application/json' },
|
|
2889
|
-
body: JSON.stringify(payload),
|
|
2890
|
-
});
|
|
2891
|
-
const data = await res.json();
|
|
2892
|
-
if (!res.ok) throw new Error(data.error || '保存失败');
|
|
2893
|
-
if (Array.isArray(data.commands)) meta.commands = data.commands;
|
|
2894
|
-
cmdDraft = { name: '', description: '', skill: '', prompt: '', scope: cmdDraft.scope };
|
|
2895
|
-
syncConfigSummaryUI();
|
|
2896
|
-
renderCommandsSubBody();
|
|
2897
|
-
showToast(`已保存命令 /${data.command?.name || ''}`);
|
|
2898
|
-
} catch (err) {
|
|
2899
|
-
showToast(err.message || '保存命令失败');
|
|
2900
|
-
}
|
|
901
|
+
`;
|
|
902
|
+
sBody.querySelector('[data-toggle-theme]').onclick = () => {
|
|
903
|
+
const next = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark';
|
|
904
|
+
actions.setTheme?.(next);
|
|
905
|
+
renderAppearanceTab();
|
|
906
|
+
};
|
|
907
|
+
const cap = sBody.querySelector('[data-cap-shot]');
|
|
908
|
+
if (cap) cap.onclick = () => { settingsMask.hidden = true; actions.capture?.(); };
|
|
909
|
+
sBody.querySelector('[data-copy-mcp]').onclick = () => {
|
|
910
|
+
navigator.clipboard?.writeText(meta.mcpUrl || (location.origin + '/mcp')).catch(() => {});
|
|
911
|
+
showToast('已复制 MCP 端点地址');
|
|
2901
912
|
};
|
|
2902
913
|
}
|
|
2903
914
|
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
const curArgs = (meta.llm?.acpArgs || []).join(' ');
|
|
2924
|
-
subBodyEl.innerHTML = `
|
|
2925
|
-
<div style="font-size:12px;color:var(--clado-ui-muted);line-height:1.5;">
|
|
2926
|
-
Clado 默认使用上方配置的<strong>主力模型原生 Agent</strong>。仅当你在会话菜单中主动点击「⚡ 新建 ACP 子代理」时,才会启动下方外部进程作为特殊子代理分身。
|
|
2927
|
-
</div>
|
|
2928
|
-
<div>
|
|
2929
|
-
<div style="font-size:12px;color:var(--clado-ui-muted);margin-bottom:4px;">启动命令 (Command)</div>
|
|
2930
|
-
<input type="text" class="clado-clean-input" data-acp-cmd value="${curCmd.replace(/"/g, '"')}" />
|
|
2931
|
-
</div>
|
|
2932
|
-
<div>
|
|
2933
|
-
<div style="font-size:12px;color:var(--clado-ui-muted);margin-bottom:4px;">参数 (Args,空格分隔,可留空)</div>
|
|
2934
|
-
<input type="text" class="clado-clean-input" data-acp-args value="${curArgs.replace(/"/g, '"')}" placeholder="--stdio" />
|
|
2935
|
-
</div>
|
|
2936
|
-
<button type="button" class="clado-tab-btn active" data-acp-save style="height:34px;font-size:12.5px;">保存外部子代理命令</button>`;
|
|
2937
|
-
subBodyEl.querySelector('[data-acp-save]').onclick = async () => {
|
|
2938
|
-
const cmd = subBodyEl.querySelector('[data-acp-cmd]').value.trim();
|
|
2939
|
-
const args = subBodyEl.querySelector('[data-acp-args]').value.trim();
|
|
2940
|
-
if (!cmd) return;
|
|
2941
|
-
try {
|
|
2942
|
-
const res = await fetch(configEndpoint, {
|
|
2943
|
-
method: 'POST',
|
|
2944
|
-
headers: { 'content-type': 'application/json' },
|
|
2945
|
-
body: JSON.stringify({ action: 'save_acp', command: cmd, args }),
|
|
2946
|
-
});
|
|
2947
|
-
if (res.ok) {
|
|
2948
|
-
const data = await res.json();
|
|
2949
|
-
if (data.llm) meta.llm = data.llm;
|
|
2950
|
-
syncConfigSummaryUI();
|
|
2951
|
-
showToast('已保存外部 ACP 子代理命令');
|
|
2952
|
-
}
|
|
2953
|
-
} catch {}
|
|
2954
|
-
};
|
|
2955
|
-
} else if (sub === 'memory') {
|
|
2956
|
-
subTitleEl.textContent = '持久记忆 (memory.md)';
|
|
2957
|
-
const inheritedFiles = Array.isArray(debugState.memory?.inherited) ? debugState.memory.inherited.map(i => i.file) : [];
|
|
2958
|
-
const inheritedHint = inheritedFiles.length
|
|
2959
|
-
? `已检测到根目录 ${inheritedFiles.join(' / ')} 并自动只读继承。`
|
|
2960
|
-
: '保存于当前工作区 .clado/memory.md,同时支持只读继承根目录 AGENTS.md。';
|
|
2961
|
-
subBodyEl.innerHTML = `
|
|
915
|
+
// =========================================================================
|
|
916
|
+
// 4. Design-to-Delivery Handoff Modal
|
|
917
|
+
// =========================================================================
|
|
918
|
+
const handoffMask = document.createElement('div');
|
|
919
|
+
handoffMask.className = 'clado-vnext-mask';
|
|
920
|
+
handoffMask.id = 'clado-handoff-modal';
|
|
921
|
+
handoffMask.hidden = true;
|
|
922
|
+
stageRoot().append(handoffMask);
|
|
923
|
+
handoffMask.addEventListener('click', e => { if (e.target === handoffMask) handoffMask.hidden = true; });
|
|
924
|
+
|
|
925
|
+
function openHandoff() {
|
|
926
|
+
const ctx = actions.readContext ? actions.readContext() : {};
|
|
927
|
+
const selCount = ctx.selection?.length || 0;
|
|
928
|
+
const scopeText = selCount
|
|
929
|
+
? `当前已选中 ${selCount} 项画布卡片(${ctx.file || '当前画布'}),将作为结构化设计契约交接给目标角色。`
|
|
930
|
+
: `将当前画布(${ctx.file || '当前工作区'})的完整设计交接给目标角色落地执行。`;
|
|
931
|
+
const roles = (meta?.roles || []).filter(r => r.id !== 'architect');
|
|
932
|
+
handoffMask.innerHTML = `
|
|
933
|
+
<div class="clado-handoff-card">
|
|
2962
934
|
<div style="display:flex;align-items:center;justify-content:space-between;">
|
|
2963
|
-
<
|
|
2964
|
-
<button type="button" class="clado-
|
|
935
|
+
<div style="font-size:16.5px;font-weight:630;">将画布设计交付为实际产物</div>
|
|
936
|
+
<button type="button" class="clado-ui-button" data-close-ho style="width:28px;height:28px;padding:0;min-height:28px;">${ICONS.close}</button>
|
|
2965
937
|
</div>
|
|
2966
|
-
<
|
|
2967
|
-
<
|
|
2968
|
-
<
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
method: 'POST',
|
|
2981
|
-
headers: { 'content-type': 'application/json' },
|
|
2982
|
-
body: JSON.stringify({ action: 'save_memory', text: area.value }),
|
|
2983
|
-
});
|
|
2984
|
-
if (res.ok) {
|
|
2985
|
-
const data = await res.json();
|
|
2986
|
-
if (data.memory) debugState.memory = data.memory;
|
|
2987
|
-
if (data.telemetry) debugState.telemetry = data.telemetry;
|
|
2988
|
-
syncConfigSummaryUI();
|
|
2989
|
-
showToast('已保存工作区 memory.md');
|
|
2990
|
-
}
|
|
2991
|
-
} catch {}
|
|
2992
|
-
};
|
|
2993
|
-
} else if (sub === 'persona') {
|
|
2994
|
-
subTitleEl.textContent = '人设与初始上下文';
|
|
2995
|
-
renderPersonaSubBody();
|
|
2996
|
-
} else if (sub === 'compact') {
|
|
2997
|
-
subTitleEl.textContent = '上下文压缩';
|
|
2998
|
-
const pct = debugState.config.compactThresholdPct || 75;
|
|
2999
|
-
subBodyEl.innerHTML = `
|
|
3000
|
-
<div style="display:flex;align-items:center;justify-content:space-between;">
|
|
3001
|
-
<span style="font-size:13px;font-weight:550;">触发阈值:<span data-compact-pct>${pct}%</span></span>
|
|
3002
|
-
<input data-compact-range type="range" min="50" max="90" step="5" value="${pct}" style="width:130px;accent-color:var(--clado-ui-brand);" />
|
|
938
|
+
<p style="font-size:12.5px;color:var(--clado-ui-muted);margin:6px 0 14px;line-height:1.58;">${esc(scopeText)}</p>
|
|
939
|
+
<input class="clado-field" data-ho-note placeholder="补充交付要求(可选,例如:补齐并发重放单测)" style="margin-bottom:12px;" />
|
|
940
|
+
<div data-ho-list style="display:flex;flex-direction:column;gap:9px;"></div>
|
|
941
|
+
</div>
|
|
942
|
+
`;
|
|
943
|
+
handoffMask.querySelector('[data-close-ho]').onclick = () => { handoffMask.hidden = true; };
|
|
944
|
+
const list = handoffMask.querySelector('[data-ho-list]');
|
|
945
|
+
for (const r of roles) {
|
|
946
|
+
const row = document.createElement('div');
|
|
947
|
+
row.className = 'clado-well-box clado-setting-row clado-handoff-opt';
|
|
948
|
+
row.innerHTML = `
|
|
949
|
+
<div>
|
|
950
|
+
<div style="font-size:13px;font-weight:610;">交给「${esc(r.name)}」执行</div>
|
|
951
|
+
<div style="font-size:11.5px;color:var(--clado-ui-muted);margin-top:2px;">${esc(r.description)}</div>
|
|
3003
952
|
</div>
|
|
3004
|
-
<
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
const pctSpan = subBodyEl.querySelector('[data-compact-pct]');
|
|
3011
|
-
const area = subBodyEl.querySelector('[data-compact-area]');
|
|
3012
|
-
area.value = debugState.config.compactPrompt || '';
|
|
3013
|
-
rng.oninput = () => { pctSpan.textContent = rng.value + '%'; };
|
|
3014
|
-
subBodyEl.querySelector('[data-compact-save]').onclick = async () => {
|
|
3015
|
-
await saveDebugPatch({
|
|
3016
|
-
compactThresholdPct: Number(rng.value),
|
|
3017
|
-
compactPrompt: area.value,
|
|
3018
|
-
});
|
|
3019
|
-
showToast('已保存上下文压缩策略');
|
|
3020
|
-
};
|
|
3021
|
-
subBodyEl.querySelector('[data-compact-test]').onclick = async () => {
|
|
3022
|
-
try {
|
|
3023
|
-
const res = await fetch(configEndpoint, {
|
|
3024
|
-
method: 'POST',
|
|
3025
|
-
headers: { 'content-type': 'application/json' },
|
|
3026
|
-
body: JSON.stringify({ action: 'test_compact', sessionId: session }),
|
|
3027
|
-
});
|
|
3028
|
-
if (res.ok) {
|
|
3029
|
-
const r = await res.json();
|
|
3030
|
-
showToast(`压缩测试:${r.beforeTurns} 轮 → ${r.afterTurns} 轮(${r.beforeTokens} → ${r.afterTokens} tok)`);
|
|
3031
|
-
}
|
|
3032
|
-
} catch {}
|
|
953
|
+
<span class="clado-chip ${TONE_CHIP[r.tone] || 'clado-chip-mint'}">${esc(r.phase)}</span>
|
|
954
|
+
`;
|
|
955
|
+
row.onclick = () => {
|
|
956
|
+
const note = handoffMask.querySelector('[data-ho-note]').value.trim();
|
|
957
|
+
handoffMask.hidden = true;
|
|
958
|
+
triggerHandoff(r.id, note);
|
|
3033
959
|
};
|
|
3034
|
-
|
|
3035
|
-
subTitleEl.textContent = '缓存分段明细';
|
|
3036
|
-
const t = debugState.telemetry;
|
|
3037
|
-
const sysBroken = Boolean(t?.brokenBySystemTime || debugState.config.timeInjection === 'system_head');
|
|
3038
|
-
if (t) {
|
|
3039
|
-
subBodyEl.innerHTML = [
|
|
3040
|
-
['第 1 段 · 冰封静态头', t.seg1Tokens, sysBroken ? '失效' : '命中'],
|
|
3041
|
-
['第 2 段 · 工作区目录索引', t.seg2Tokens, sysBroken ? '失效' : '命中'],
|
|
3042
|
-
['第 3 段 · 历史与画布基线', t.seg3Tokens, sysBroken ? '失效' : '命中'],
|
|
3043
|
-
['第 4 段 · 尾部增量与状态', t.seg4Tokens, '新增'],
|
|
3044
|
-
].map(([label, tok, st]) => `<div style="display:flex;justify-content:space-between;font-size:13px;"><span>${label}</span><strong>${tok} tok (${st})</strong></div>`).join('');
|
|
3045
|
-
} else {
|
|
3046
|
-
subBodyEl.innerHTML = '<div style="font-size:12.5px;color:var(--clado-ui-muted);">暂无分段采样数据。</div>';
|
|
3047
|
-
}
|
|
960
|
+
list.append(row);
|
|
3048
961
|
}
|
|
3049
|
-
|
|
3050
|
-
cfgHomeEl.classList.add('pushed-out');
|
|
3051
|
-
cfgSubEl.classList.add('active');
|
|
962
|
+
handoffMask.hidden = false;
|
|
3052
963
|
}
|
|
3053
964
|
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
if (!
|
|
3061
|
-
|
|
3062
|
-
if (act === 'close-settings') {
|
|
3063
|
-
closeSettingsOverlay();
|
|
3064
|
-
} else if (act === 'cycle') {
|
|
3065
|
-
const kind = el.dataset.cfgKind;
|
|
3066
|
-
const cycleNext = (arr, cur) => {
|
|
3067
|
-
const i = arr.findIndex(([k]) => k === cur);
|
|
3068
|
-
return arr[(i + 1) % arr.length][0];
|
|
3069
|
-
};
|
|
3070
|
-
if (kind === 'canvas') await saveDebugPatch({ canvasMemory: cycleNext(CANVAS_MEM_CYCLE, debugState.config.canvasMemory) });
|
|
3071
|
-
else if (kind === 'time') await saveDebugPatch({ timeInjection: cycleNext(TIME_MODE_CYCLE, debugState.config.timeInjection) });
|
|
3072
|
-
else if (kind === 'ttl') await saveDebugPatch({ autoArchiveHours: cycleNext(TTL_CYCLE, debugState.config.autoArchiveHours) });
|
|
3073
|
-
else if (kind === 'perm') await saveDebugPatch({ commandPermission: cycleNext(PERM_CYCLE, debugState.config.commandPermission) });
|
|
3074
|
-
} else if (act === 'toggle-map') {
|
|
3075
|
-
const next = !el.classList.contains('on');
|
|
3076
|
-
await saveDebugPatch({ workspaceMap: next });
|
|
3077
|
-
} else if (act === 'open-sub') {
|
|
3078
|
-
if (el.dataset.sub === 'llm' && meta.llm?.providerId) activeProviderDraft = meta.llm.providerId;
|
|
3079
|
-
openCfgSub(el.dataset.sub);
|
|
3080
|
-
} else if (act === 'close-sub') {
|
|
3081
|
-
closeCfgSub();
|
|
3082
|
-
} else if (act === 'reset-sub') {
|
|
3083
|
-
if (!currentSub) return;
|
|
3084
|
-
const section = currentSub === 'persona' ? 'personas' : currentSub;
|
|
3085
|
-
try {
|
|
3086
|
-
if (currentSub === 'memory') {
|
|
3087
|
-
await fetch(configEndpoint, {
|
|
3088
|
-
method: 'POST',
|
|
3089
|
-
headers: { 'content-type': 'application/json' },
|
|
3090
|
-
body: JSON.stringify({ action: 'save_memory', text: '' }),
|
|
3091
|
-
});
|
|
3092
|
-
} else {
|
|
3093
|
-
const res = await fetch(configEndpoint, {
|
|
3094
|
-
method: 'POST',
|
|
3095
|
-
headers: { 'content-type': 'application/json' },
|
|
3096
|
-
body: JSON.stringify({ action: 'reset', section }),
|
|
3097
|
-
});
|
|
3098
|
-
if (res.ok) {
|
|
3099
|
-
const data = await res.json();
|
|
3100
|
-
if (data.config) debugState.config = data.config;
|
|
3101
|
-
if (data.telemetry) debugState.telemetry = data.telemetry;
|
|
3102
|
-
}
|
|
3103
|
-
}
|
|
3104
|
-
await loadDebugConfig();
|
|
3105
|
-
openCfgSub(currentSub);
|
|
3106
|
-
showToast('已恢复默认设置');
|
|
3107
|
-
} catch {}
|
|
965
|
+
// =========================================================================
|
|
966
|
+
// 5. Bootstrap & Public API
|
|
967
|
+
// =========================================================================
|
|
968
|
+
function applyMeta(data) {
|
|
969
|
+
meta = data;
|
|
970
|
+
sessions = Array.isArray(data.sessions) ? data.sessions : [];
|
|
971
|
+
if (!activeSessionId || !sessions.some(s => s.id === activeSessionId)) {
|
|
972
|
+
activeSessionId = sessions[0]?.id || '';
|
|
3108
973
|
}
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
async function loadMeta() {
|
|
3113
|
-
try {
|
|
3114
|
-
const res = await fetch(metaEndpoint, { cache: 'no-store' });
|
|
3115
|
-
if (!res.ok) return;
|
|
3116
|
-
meta = await res.json();
|
|
3117
|
-
if (meta.defaultPersona && PERSONA_META[meta.defaultPersona]) {
|
|
3118
|
-
persona = meta.defaultPersona;
|
|
3119
|
-
}
|
|
3120
|
-
syncModelChip();
|
|
3121
|
-
syncConfigSummaryUI();
|
|
3122
|
-
const list = Array.isArray(meta.executors) ? meta.executors : [];
|
|
3123
|
-
const prev = executorSelect.value;
|
|
3124
|
-
executorSelect.replaceChildren();
|
|
3125
|
-
if (!list.length) {
|
|
3126
|
-
const opt = document.createElement('option');
|
|
3127
|
-
opt.value = '';
|
|
3128
|
-
opt.textContent = '未配置 ACP 执行器';
|
|
3129
|
-
executorSelect.append(opt);
|
|
3130
|
-
} else {
|
|
3131
|
-
for (const item of list) {
|
|
3132
|
-
const opt = document.createElement('option');
|
|
3133
|
-
opt.value = item.id;
|
|
3134
|
-
opt.textContent = item.name + (item.source === 'plugin' ? '(插件)' : '');
|
|
3135
|
-
executorSelect.append(opt);
|
|
3136
|
-
}
|
|
3137
|
-
if (prev && list.some(item => item.id === prev)) executorSelect.value = prev;
|
|
3138
|
-
}
|
|
3139
|
-
executorDropdown.sync();
|
|
3140
|
-
|
|
3141
|
-
if (Array.isArray(meta.sessions)) {
|
|
3142
|
-
ingestSessionList(meta.sessions, false);
|
|
3143
|
-
}
|
|
3144
|
-
} catch {}
|
|
974
|
+
renderRoleStrip();
|
|
975
|
+
renderStream();
|
|
976
|
+
window.dispatchEvent(new CustomEvent('clado:meta-updated', { detail: data }));
|
|
3145
977
|
}
|
|
3146
978
|
|
|
3147
|
-
async function
|
|
979
|
+
async function refreshMeta() {
|
|
3148
980
|
try {
|
|
3149
|
-
const res = await fetch(
|
|
3150
|
-
if (!res.ok) return;
|
|
981
|
+
const res = await fetch(withWs('/library/agent/meta'), { cache: 'no-store' });
|
|
982
|
+
if (!res.ok) return null;
|
|
3151
983
|
const data = await res.json();
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
}
|
|
3157
|
-
|
|
3158
|
-
window.addEventListener('clado:agent-sessions', ev => {
|
|
3159
|
-
const incoming = ev.detail?.sessions;
|
|
3160
|
-
if (Array.isArray(incoming)) {
|
|
3161
|
-
ingestSessionList(incoming, true);
|
|
3162
|
-
if (singlePanelOpen && session) {
|
|
3163
|
-
fetchSessionDetail(session).then(rec => {
|
|
3164
|
-
if (rec && singlePanelOpen && session === rec.id && !(running && streamingSessionId === rec.id)) {
|
|
3165
|
-
renderRecordIntoDrawer(rec);
|
|
3166
|
-
}
|
|
3167
|
-
});
|
|
3168
|
-
}
|
|
3169
|
-
}
|
|
3170
|
-
});
|
|
3171
|
-
|
|
3172
|
-
window.addEventListener('clado:send-selection', ev => {
|
|
3173
|
-
const names = ev.detail?.names || '';
|
|
3174
|
-
setMinimized(false);
|
|
3175
|
-
openSinglePanel(session);
|
|
3176
|
-
if (names && !input.value.trim()) {
|
|
3177
|
-
input.value = `结合 [${names}] 优化设计:`;
|
|
3178
|
-
}
|
|
3179
|
-
syncActions();
|
|
3180
|
-
input.focus();
|
|
3181
|
-
});
|
|
3182
|
-
|
|
3183
|
-
window.addEventListener('clado:open-llm-settings', () => {
|
|
3184
|
-
setMinimized(false);
|
|
3185
|
-
openSettingsOverlay('llm');
|
|
3186
|
-
});
|
|
3187
|
-
|
|
3188
|
-
// 每秒检查是否有会话跨越 30s 活跃/静息分界线,平滑收缩状态字与重排
|
|
3189
|
-
const idleTick = setInterval(() => {
|
|
3190
|
-
if (!sessionsList.length) return;
|
|
3191
|
-
let crossedBoundary = false;
|
|
3192
|
-
for (const s of sessionsList) {
|
|
3193
|
-
if (s.archived) continue;
|
|
3194
|
-
const pill = pillDomMap.get(s.id);
|
|
3195
|
-
if (!pill) continue;
|
|
3196
|
-
const wasActive = pill.classList.contains('is-active');
|
|
3197
|
-
const nowActive = isSessionActive(s);
|
|
3198
|
-
if (wasActive !== nowActive) crossedBoundary = true;
|
|
984
|
+
applyMeta(data);
|
|
985
|
+
return data;
|
|
986
|
+
} catch {
|
|
987
|
+
return null;
|
|
3199
988
|
}
|
|
3200
|
-
|
|
3201
|
-
}, 1000);
|
|
989
|
+
}
|
|
3202
990
|
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
if (!
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
991
|
+
async function startCodeAnalysis(templateKey = 'arch') {
|
|
992
|
+
const promptText = CODE_ANALYSIS_PROMPTS[templateKey] || CODE_ANALYSIS_PROMPTS.arch;
|
|
993
|
+
if (!sessions.length) await refreshMeta();
|
|
994
|
+
const arch = sessions.find(s => s.roleId === 'architect') || sessions[0];
|
|
995
|
+
if (!arch) return;
|
|
996
|
+
await streamAgentRequest({
|
|
997
|
+
action: 'prompt',
|
|
998
|
+
session: arch.id,
|
|
999
|
+
roleId: arch.roleId,
|
|
1000
|
+
text: promptText,
|
|
1001
|
+
canvas: actions.readContext ? actions.readContext() : {},
|
|
1002
|
+
}, arch);
|
|
1003
|
+
}
|
|
3211
1004
|
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
closeSlashMenu();
|
|
3217
|
-
for (const dd of glassDropdowns) {
|
|
3218
|
-
if (!dd.menu.hidden) dd.setOpen(false);
|
|
3219
|
-
}
|
|
3220
|
-
if (configView.classList.contains('show')) {
|
|
3221
|
-
if (currentSub) closeCfgSub();
|
|
3222
|
-
else closeSettingsOverlay();
|
|
3223
|
-
} else if (singlePanelOpen) {
|
|
3224
|
-
closeSinglePanel();
|
|
3225
|
-
}
|
|
3226
|
-
}
|
|
3227
|
-
});
|
|
1005
|
+
function isComponentEnabled(id) {
|
|
1006
|
+
const comps = meta?.canvasComponents || [];
|
|
1007
|
+
return Boolean(comps.find(c => c.id === id)?.enabled);
|
|
1008
|
+
}
|
|
3228
1009
|
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
1010
|
+
window.CladoVNext = {
|
|
1011
|
+
openSettings,
|
|
1012
|
+
openHandoff,
|
|
1013
|
+
triggerHandoff,
|
|
1014
|
+
startCodeAnalysis,
|
|
1015
|
+
refreshMeta,
|
|
1016
|
+
getMeta: () => meta,
|
|
1017
|
+
isComponentEnabled,
|
|
1018
|
+
setDrawerOpen,
|
|
1019
|
+
};
|
|
3233
1020
|
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
1021
|
+
refreshMeta();
|
|
1022
|
+
|
|
1023
|
+
return {
|
|
1024
|
+
openSettings,
|
|
1025
|
+
openHandoff,
|
|
1026
|
+
triggerHandoff,
|
|
1027
|
+
startCodeAnalysis,
|
|
1028
|
+
refreshMeta,
|
|
1029
|
+
focusComposer(prefill = '') {
|
|
1030
|
+
setDrawerOpen(true);
|
|
1031
|
+
if (prefill) inputEl.value = prefill;
|
|
1032
|
+
inputEl.focus();
|
|
1033
|
+
},
|
|
1034
|
+
};
|
|
3238
1035
|
};
|
|
3239
1036
|
})();
|