cladogram 0.5.5-beta.7 → 0.5.5-beta.8

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.
@@ -154,6 +154,10 @@
154
154
 
155
155
  <form class="clado-agent-shell clado-agent-glass" data-role="agent-shell">
156
156
  <button type="button" class="clado-agent-min-btn" data-role="minimize-btn" title="收起灵感" aria-label="收起灵感">✦</button>
157
+ <button type="button" class="clado-model-chip unconfigured" data-role="model-chip" title="切换模型或配置供应商">
158
+ <span class="clado-model-chip-label" data-role="model-chip-label">配置模型</span>
159
+ <span class="clado-model-chip-caret" aria-hidden="true">▾</span>
160
+ </button>
157
161
  <input type="text" class="clado-agent-input" aria-label="给 灵感 的消息" maxlength="12000" autocomplete="off" />
158
162
  <button type="button" class="clado-agent-stop-btn" data-role="stop-btn" hidden>停止</button>
159
163
  <button type="submit" class="clado-agent-send-btn" data-role="send-btn" disabled>发送</button>
@@ -162,13 +166,17 @@
162
166
  <div class="clado-edge-aura-line"><div class="clado-edge-aura-runner"></div></div>
163
167
  </div>
164
168
  </form>`;
165
- host.mount('bottom-center', dock, 'clado.agent');
169
+ host.mount('bottom-right', dock, 'clado.agent');
166
170
 
167
- // 3. 顶层上下文菜单、设置调试面板与轻提示气泡(直挂 body,零祖先裁剪)
171
+ // 3. 顶层上下文菜单、模型快切菜单、设置面板与轻提示气泡(直挂 body,零祖先裁剪)
168
172
  const ctxMenu = document.createElement('div');
169
173
  ctxMenu.className = 'clado-agent-ctx-menu';
170
174
  document.body.append(ctxMenu);
171
175
 
176
+ const modelMenu = document.createElement('div');
177
+ modelMenu.className = 'clado-model-menu';
178
+ document.body.append(modelMenu);
179
+
172
180
  const configView = document.createElement('div');
173
181
  configView.className = 'clado-agent-overlay';
174
182
  configView.innerHTML = `
@@ -179,23 +187,11 @@
179
187
  <button type="button" class="clado-tab-btn active" data-cfg-act="close-settings" style="padding:5px 12px;font-size:12px;">完成</button>
180
188
  </div>
181
189
 
182
- <div class="clado-group-title">上下文与记忆</div>
190
+ <div class="clado-group-title">主力模型与供应商</div>
183
191
  <div class="clado-settings-group" style="margin-bottom:13px;">
184
- <div class="clado-s-row clickable" data-cfg-act="cycle" data-cfg-kind="canvas">
185
- <span class="clado-s-title">画布实时记忆</span>
186
- <span class="clado-s-val"><span data-cfg-val="canvas">智能增量</span> <span style="opacity:.45;">›</span></span>
187
- </div>
188
- <div class="clado-s-row clickable" data-cfg-act="cycle" data-cfg-kind="time">
189
- <span class="clado-s-title">时间信息注入</span>
190
- <span class="clado-s-val"><span data-cfg-val="time">仅日期</span> <span style="opacity:.45;">›</span></span>
191
- </div>
192
- <div class="clado-s-row">
193
- <span class="clado-s-title">工作区全局目录索引</span>
194
- <button type="button" class="clado-switch-btn on" data-cfg-act="toggle-map" aria-label="工作区全局目录索引"><i></i></button>
195
- </div>
196
- <div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="memory">
197
- <span class="clado-s-title">持久记忆 (memory.md)</span>
198
- <span class="clado-s-val"><span data-cfg-val="memory">已开启 · 编辑</span> <span style="opacity:.45;">›</span></span>
192
+ <div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="llm">
193
+ <span class="clado-s-title">供应商与模型配置</span>
194
+ <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
195
  </div>
200
196
  </div>
201
197
 
@@ -215,8 +211,32 @@
215
211
  </div>
216
212
  </div>
217
213
 
218
- <div class="clado-group-title">安全与调试</div>
214
+ <div class="clado-group-title">上下文与记忆</div>
215
+ <div class="clado-settings-group" style="margin-bottom:13px;">
216
+ <div class="clado-s-row clickable" data-cfg-act="cycle" data-cfg-kind="canvas">
217
+ <span class="clado-s-title">画布实时记忆</span>
218
+ <span class="clado-s-val"><span data-cfg-val="canvas">智能增量</span> <span style="opacity:.45;">›</span></span>
219
+ </div>
220
+ <div class="clado-s-row clickable" data-cfg-act="cycle" data-cfg-kind="time">
221
+ <span class="clado-s-title">时间信息注入</span>
222
+ <span class="clado-s-val"><span data-cfg-val="time">仅日期</span> <span style="opacity:.45;">›</span></span>
223
+ </div>
224
+ <div class="clado-s-row">
225
+ <span class="clado-s-title">工作区全局目录索引</span>
226
+ <button type="button" class="clado-switch-btn on" data-cfg-act="toggle-map" aria-label="工作区全局目录索引"><i></i></button>
227
+ </div>
228
+ <div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="memory">
229
+ <span class="clado-s-title">持久记忆 (memory.md)</span>
230
+ <span class="clado-s-val"><span data-cfg-val="memory">已开启 · 编辑</span> <span style="opacity:.45;">›</span></span>
231
+ </div>
232
+ </div>
233
+
234
+ <div class="clado-group-title">MCP 接入、安全与外部子代理</div>
219
235
  <div class="clado-settings-group">
236
+ <div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="mcp">
237
+ <span class="clado-s-title">MCP 服务与工具能力</span>
238
+ <span class="clado-s-val"><span>一键复制配置</span> <span style="opacity:.45;">›</span></span>
239
+ </div>
220
240
  <div class="clado-s-row clickable" data-cfg-act="cycle" data-cfg-kind="perm">
221
241
  <span class="clado-s-title">命令行执行权限</span>
222
242
  <span class="clado-s-val"><span data-cfg-val="perm">只读免审</span> <span style="opacity:.45;">›</span></span>
@@ -225,6 +245,10 @@
225
245
  <span class="clado-s-title">前缀缓存命中状态</span>
226
246
  <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>
227
247
  </div>
248
+ <div class="clado-s-row clickable" data-cfg-act="open-sub" data-sub="acp">
249
+ <span class="clado-s-title">外部 ACP 子代理(可选)</span>
250
+ <span class="clado-s-val"><span data-cfg-val="acp">低优备用</span> <span style="opacity:.45;">›</span></span>
251
+ </div>
228
252
  </div>
229
253
  </div>
230
254
 
@@ -254,6 +278,8 @@
254
278
  const spInner = dock.querySelector('[data-role="sp-inner"]');
255
279
  const spName = dock.querySelector('[data-role="sp-name"]');
256
280
  const spPersonaTag = dock.querySelector('[data-role="sp-persona-tag"]');
281
+ const modelChip = dock.querySelector('[data-role="model-chip"]');
282
+ const modelChipLabel = dock.querySelector('[data-role="model-chip-label"]');
257
283
  const execModeBtns = [...dock.querySelectorAll('[data-exec-mode]')];
258
284
  const workflowBtns = [...dock.querySelectorAll('[data-workflow]')];
259
285
  const followBtn = dock.querySelector('[data-role="follow-btn"]');
@@ -401,10 +427,14 @@
401
427
  let execMode = 'act';
402
428
 
403
429
  let meta = {
404
- engine: 'acp',
430
+ engine: 'builtin',
405
431
  provider: 'openai',
432
+ providerId: 'openai',
433
+ providerLabel: 'OpenAI',
406
434
  builtinConfigured: false,
407
435
  model: '',
436
+ mcpUrl: '',
437
+ llm: null,
408
438
  executors: [],
409
439
  personas: [],
410
440
  sessions: [],
@@ -427,6 +457,10 @@
427
457
  keepalive,
428
458
  });
429
459
 
460
+ function closeModelMenu() {
461
+ modelMenu.classList.remove('open');
462
+ }
463
+
430
464
  function syncDockPresence() {
431
465
  dock.classList.toggle('minimized', minimized);
432
466
  orbBtn.classList.toggle('show', minimized);
@@ -437,9 +471,18 @@
437
471
 
438
472
  function setMinimized(next) {
439
473
  minimized = !!next;
440
- if (minimized) closeCtxMenu();
474
+ if (minimized) {
475
+ if (singlePanelOpen) {
476
+ singlePanelOpen = false;
477
+ singleWrap.classList.remove('open');
478
+ }
479
+ closeCtxMenu();
480
+ closeModelMenu();
481
+ for (const dd of glassDropdowns) dd.setOpen(false);
482
+ }
441
483
  syncDockPresence();
442
484
  if (!minimized) {
485
+ renderPeerCluster(false);
443
486
  requestAnimationFrame(() => updatePeerEdgeFade());
444
487
  }
445
488
  }
@@ -711,9 +754,11 @@
711
754
  emptyBtn.style.setProperty('--c-glow', PALETTES.blue.glow);
712
755
  emptyBtn.innerHTML = '<span class="p-name">+ 新建会话</span>';
713
756
  bindPillGestures(emptyBtn, () => null);
714
- emptyBtn.onclick = () => {
757
+ emptyBtn.onclick = ev => {
715
758
  if (stripMoved) return;
716
- createNewSession('architect');
759
+ const r = emptyBtn.getBoundingClientRect();
760
+ openSessionContextMenu(null, r.left + r.width / 2, r.top);
761
+ ev.stopPropagation();
717
762
  };
718
763
  peerClusterEl.append(emptyBtn);
719
764
  } else {
@@ -722,6 +767,19 @@
722
767
  const btn = ensurePillElement(s);
723
768
  peerClusterEl.append(btn);
724
769
  }
770
+ const addBtn = document.createElement('button');
771
+ addBtn.type = 'button';
772
+ addBtn.className = 'clado-peer-add-btn';
773
+ addBtn.title = '新建分身或管理会话';
774
+ addBtn.setAttribute('aria-label', '新建分身或管理会话');
775
+ addBtn.textContent = '+';
776
+ addBtn.onclick = ev => {
777
+ ev.stopPropagation();
778
+ if (stripMoved) return;
779
+ const r = addBtn.getBoundingClientRect();
780
+ openSessionContextMenu(null, r.left + r.width / 2, r.top);
781
+ };
782
+ peerClusterEl.append(addBtn);
725
783
  }
726
784
 
727
785
  if (animateReorder && firstRects.size > 0) {
@@ -748,6 +806,7 @@
748
806
  orbText.textContent = activeCount > 0 ? `灵感 · ${activeCount} 活跃` : '灵感';
749
807
  syncCommandBanner();
750
808
  syncActions();
809
+ syncModelChip();
751
810
  }
752
811
 
753
812
  function ingestSessionList(incoming, animate = false) {
@@ -842,7 +901,7 @@
842
901
  };
843
902
  });
844
903
 
845
- // 8. 长按 / 右键会话菜单(新建、归档、恢复归档、删除、设置)
904
+ // 8. 长按 / 右键会话菜单(新建、重命名、归档、恢复归档、删除、设置、低优 ACP 分身)
846
905
  function closeCtxMenu() {
847
906
  ctxMenu.classList.remove('open');
848
907
  }
@@ -893,17 +952,41 @@
893
952
  } catch {}
894
953
  }
895
954
 
955
+ async function renameSessionById(id, oldTitle = '') {
956
+ if (!id) return;
957
+ const next = window.prompt('重命名会话:', oldTitle || '新会话');
958
+ if (!next || !next.trim() || next.trim() === oldTitle) return;
959
+ try {
960
+ const res = await fetch(sessionsEndpoint, {
961
+ method: 'POST',
962
+ headers: { 'content-type': 'application/json' },
963
+ body: JSON.stringify({ action: 'rename', id, title: next.trim() }),
964
+ });
965
+ if (res.ok) {
966
+ const { session: updated } = await res.json();
967
+ if (updated) {
968
+ sessionRecords.set(updated.id, updated);
969
+ if (singlePanelOpen && session === updated.id) spName.textContent = updated.title;
970
+ }
971
+ await refreshSessionsList(false);
972
+ showToast('已更新会话名称');
973
+ }
974
+ } catch {}
975
+ }
976
+
896
977
  function openSessionContextMenu(targetSession, x, y) {
897
978
  ctxMenu.replaceChildren();
898
- addCtxHeader('会话菜单', targetSession ? (targetSession.title || '当前会话') : '会话管理');
899
- addCtxItem('+ 新建架构会话', () => createNewSession('architect'));
900
- addCtxItem('+ 新建实现分身', () => createNewSession('coder'));
901
- addCtxItem('+ 新建测试分身', () => createNewSession('qa'));
902
- addCtxItem('+ 新建审计分身', () => createNewSession('auditor'));
903
- addCtxItem('⚙ Agent 设置与记忆', () => openSettingsOverlay());
979
+ addCtxHeader('会话菜单', targetSession ? (targetSession.title || '当前会话') : '新建与管理');
980
+ addCtxItem('+ 新建架构师分身', () => createNewSession('architect'));
981
+ addCtxItem('+ 新建实现者分身', () => createNewSession('coder'));
982
+ addCtxItem('+ 新建 QA 测试分身', () => createNewSession('qa'));
983
+ addCtxItem('+ 新建审计官分身', () => createNewSession('auditor'));
984
+ addCtxItem('⚙ 供应商与模型设置', () => openSettingsOverlay('llm'));
904
985
  addCtxItem('🧩 插件市场', () => window.dispatchEvent(new CustomEvent('clado:open-market')));
986
+ addCtxItem('⚡ 新建 ACP 子代理(特殊机制)', () => createNewSession('custom', { engine: 'acp', title: 'ACP 子代理' }));
905
987
 
906
988
  if (targetSession && targetSession.id) {
989
+ addCtxItem('✎ 重命名此会话', () => renameSessionById(targetSession.id, targetSession.title));
907
990
  addCtxItem('归档此会话', () => archiveSessionById(targetSession.id));
908
991
  }
909
992
  for (const arch of archivedList.slice(0, 4)) {
@@ -924,7 +1007,7 @@
924
1007
  openSessionContextMenu(null, e.clientX, e.clientY);
925
1008
  });
926
1009
 
927
- async function createNewSession(nextPersona = 'architect') {
1010
+ async function createNewSession(nextPersona = 'architect', extra = {}) {
928
1011
  const pMeta = PERSONA_META[nextPersona] || PERSONA_META.architect;
929
1012
  try {
930
1013
  const res = await fetch(sessionsEndpoint, {
@@ -933,7 +1016,9 @@
933
1016
  body: JSON.stringify({
934
1017
  action: 'create',
935
1018
  persona: nextPersona,
936
- pal: pMeta.pal,
1019
+ pal: extra.engine === 'acp' ? 'cyan' : pMeta.pal,
1020
+ engine: extra.engine === 'acp' ? 'acp' : 'builtin',
1021
+ title: extra.title || undefined,
937
1022
  mode: pMeta.defaultMode,
938
1023
  execMode: nextPersona === 'auditor' ? 'plan' : 'act',
939
1024
  }),
@@ -1681,13 +1766,165 @@
1681
1766
  }
1682
1767
  });
1683
1768
 
1769
+ function isLlmConfigured() {
1770
+ return Boolean(meta.llm?.configured || meta.builtinConfigured);
1771
+ }
1772
+
1773
+ function currentSessionEngine() {
1774
+ const curSummary = sessionsList.find(s => s.id === session);
1775
+ const curRec = sessionRecords.get(session);
1776
+ if (curSummary?.engine === 'acp' || curRec?.engine === 'acp') return 'acp';
1777
+ return 'builtin';
1778
+ }
1779
+
1780
+ function syncModelChip() {
1781
+ if (!modelChip || !modelChipLabel) return;
1782
+ if (currentSessionEngine() === 'acp') {
1783
+ modelChip.classList.remove('unconfigured');
1784
+ modelChipLabel.textContent = '⚡ ACP 子代理';
1785
+ modelChip.title = '当前胶囊使用外部 ACP 子代理机制';
1786
+ return;
1787
+ }
1788
+ if (!isLlmConfigured()) {
1789
+ modelChip.classList.add('unconfigured');
1790
+ modelChipLabel.textContent = '配置模型';
1791
+ modelChip.title = '点击配置供应商、API Key 与主力模型';
1792
+ return;
1793
+ }
1794
+ modelChip.classList.remove('unconfigured');
1795
+ const shortModel = (meta.llm?.model || meta.model || '已配置').split('/').pop();
1796
+ modelChipLabel.textContent = shortModel;
1797
+ modelChip.title = `${meta.llm?.providerLabel || meta.providerLabel || '当前模型'} · ${meta.llm?.model || meta.model}`;
1798
+ }
1799
+
1800
+ async function quickSwitchModel(providerId, model) {
1801
+ try {
1802
+ const res = await fetch(configEndpoint, {
1803
+ method: 'POST',
1804
+ headers: { 'content-type': 'application/json' },
1805
+ body: JSON.stringify({ action: 'switch_model', providerId, model }),
1806
+ });
1807
+ if (!res.ok) return;
1808
+ const data = await res.json();
1809
+ if (data.llm) {
1810
+ meta.llm = data.llm;
1811
+ meta.builtinConfigured = Boolean(data.llm.configured);
1812
+ meta.model = data.llm.model;
1813
+ meta.providerId = data.llm.providerId;
1814
+ meta.providerLabel = data.llm.providerLabel;
1815
+ }
1816
+ syncModelChip();
1817
+ syncConfigSummaryUI();
1818
+ showToast(`已切换模型:${model}`);
1819
+ } catch {}
1820
+ }
1821
+
1822
+ function openModelQuickMenu() {
1823
+ if (!isLlmConfigured() && currentSessionEngine() !== 'acp') {
1824
+ openSettingsOverlay('llm');
1825
+ return;
1826
+ }
1827
+ if (modelMenu.classList.contains('open')) {
1828
+ closeModelMenu();
1829
+ return;
1830
+ }
1831
+ modelMenu.replaceChildren();
1832
+ const hdr = document.createElement('div');
1833
+ hdr.className = 'clado-ctx-badge';
1834
+ hdr.innerHTML = `<span>切换主力模型</span><span style="opacity:.7;">${meta.llm?.providerLabel || ''}</span>`;
1835
+ modelMenu.append(hdr);
1836
+
1837
+ const quickList = Array.isArray(meta.llm?.quickModels) ? meta.llm.quickModels : [];
1838
+ for (const item of quickList) {
1839
+ const active = item.providerId === meta.llm?.providerId && item.model === meta.llm?.model;
1840
+ const btn = document.createElement('button');
1841
+ btn.type = 'button';
1842
+ btn.className = 'clado-ctx-btn';
1843
+ btn.style.display = 'flex';
1844
+ btn.style.justifyContent = 'space-between';
1845
+ btn.style.alignItems = 'center';
1846
+ btn.style.gap = '8px';
1847
+ 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>`;
1848
+ btn.onclick = () => {
1849
+ closeModelMenu();
1850
+ quickSwitchModel(item.providerId, item.model);
1851
+ };
1852
+ modelMenu.append(btn);
1853
+ }
1854
+
1855
+ const sep = document.createElement('div');
1856
+ sep.style.cssText = 'height:1px;background:var(--clado-agent-edge);margin:3px 6px;';
1857
+ modelMenu.append(sep);
1858
+
1859
+ const cfgBtn = document.createElement('button');
1860
+ cfgBtn.type = 'button';
1861
+ cfgBtn.className = 'clado-ctx-btn';
1862
+ cfgBtn.textContent = '⚙ 配置供应商与模型…';
1863
+ cfgBtn.onclick = () => {
1864
+ closeModelMenu();
1865
+ openSettingsOverlay('llm');
1866
+ };
1867
+ modelMenu.append(cfgBtn);
1868
+
1869
+ const r = modelChip.getBoundingClientRect();
1870
+ modelMenu.style.left = '-999px';
1871
+ modelMenu.style.top = '-999px';
1872
+ modelMenu.classList.add('open');
1873
+ const mr = modelMenu.getBoundingClientRect();
1874
+ const left = Math.max(10, Math.min(r.left, window.innerWidth - mr.width - 10));
1875
+ const top = Math.max(12, r.top - mr.height - 8);
1876
+ modelMenu.style.left = left + 'px';
1877
+ modelMenu.style.top = top + 'px';
1878
+ }
1879
+
1880
+ modelChip.onclick = ev => {
1881
+ ev.stopPropagation();
1882
+ closeCtxMenu();
1883
+ openModelQuickMenu();
1884
+ };
1885
+
1886
+ spPersonaTag.style.cursor = 'pointer';
1887
+ spPersonaTag.title = '点击切换当前会话人设或编辑人设提示词';
1888
+ spPersonaTag.onclick = ev => {
1889
+ ev.stopPropagation();
1890
+ ctxMenu.replaceChildren();
1891
+ addCtxHeader('切换当前会话人设', spName.textContent);
1892
+ for (const [k, info] of Object.entries(PERSONA_META)) {
1893
+ if (k === 'custom') continue;
1894
+ addCtxItem(`${k === persona ? '✓ ' : ''}${info.label}`, async () => {
1895
+ persona = k;
1896
+ try {
1897
+ const res = await fetch(sessionsEndpoint, {
1898
+ method: 'POST',
1899
+ headers: { 'content-type': 'application/json' },
1900
+ body: JSON.stringify({ action: 'set_persona', id: session, persona: k }),
1901
+ });
1902
+ if (res.ok) {
1903
+ const { session: updated } = await res.json();
1904
+ if (updated) {
1905
+ sessionRecords.set(updated.id, updated);
1906
+ renderRecordIntoDrawer(updated);
1907
+ }
1908
+ await refreshSessionsList(false);
1909
+ }
1910
+ } catch {}
1911
+ });
1912
+ }
1913
+ addCtxItem('✎ 编辑人设提示词模板…', () => {
1914
+ activePersonaTab = persona === 'custom' ? 'architect' : persona;
1915
+ openSettingsOverlay('persona');
1916
+ });
1917
+ const r = spPersonaTag.getBoundingClientRect();
1918
+ positionCtxMenu(r.left + r.width / 2, r.top);
1919
+ };
1920
+
1684
1921
  shell.onsubmit = async event => {
1685
1922
  event.preventDefault();
1686
1923
  if (!canSubmit()) return;
1687
1924
  const rawText = input.value.trim();
1688
1925
 
1689
1926
  // 运行中实时插话(Steer)
1690
- if (running && streamingSessionId === session && meta.engine === 'builtin' && rawText) {
1927
+ if (running && streamingSessionId === session && currentSessionEngine() === 'builtin' && rawText) {
1691
1928
  input.value = '';
1692
1929
  syncActions();
1693
1930
  try {
@@ -1702,13 +1939,21 @@
1702
1939
  }
1703
1940
 
1704
1941
  const isDispatch = workflow === 'dispatch';
1942
+ const curEngine = currentSessionEngine();
1943
+ // 若当前为主力原生 Agent 且尚未配置任何供应商/模型,不报底层错误,直接平滑打开供应商与模型配置页并保留输入文字
1944
+ if (!isDispatch && curEngine === 'builtin' && !isLlmConfigured()) {
1945
+ openSettingsOverlay('llm');
1946
+ showToast('请先选择供应商并填写 API Key(或启用本地 Ollama)');
1947
+ return;
1948
+ }
1949
+
1705
1950
  const text = rawText || (workflow === 'audit' ? '请核对当前本地 Git Diff 与画布设计契约、测试用例的差异,并给出验收结论。' : '');
1706
1951
  const canvas = readCanvas();
1707
1952
  input.value = '';
1708
1953
  const executorName = executorSelect.selectedOptions?.[0]?.textContent || agentName;
1709
1954
  const payload = isDispatch
1710
1955
  ? { action: 'dispatch', session, executorId: executorSelect.value || undefined, text: rawText, canvas, viewId }
1711
- : { action: 'prompt', session, mode: workflow, execMode, persona, text, canvas, viewId };
1956
+ : { action: 'prompt', session, engine: curEngine, mode: workflow, execMode, persona, text, canvas, viewId };
1712
1957
  await streamTurn(payload, {
1713
1958
  humanText: isDispatch ? `[派发开发 → ${executorName}] ${rawText || '按当前画布规格实现代码并运行测试'}` : text,
1714
1959
  canvas,
@@ -1717,7 +1962,7 @@
1717
1962
  });
1718
1963
  };
1719
1964
 
1720
- // 12. 极简「Agent 设置」与上下文调试面板(对接 /library/agent/config)
1965
+ // 12. 一等「供应商与模型」+「Agent 设置」面板(对接 /library/agent/config)
1721
1966
  let debugState = {
1722
1967
  config: {
1723
1968
  canvasMemory: 'delta',
@@ -1735,6 +1980,7 @@
1735
1980
  };
1736
1981
  let currentSub = null;
1737
1982
  let activePersonaTab = 'architect';
1983
+ let activeProviderDraft = 'openai';
1738
1984
  const cfgHomeEl = configView.querySelector('[data-role="cfg-home"]');
1739
1985
  const cfgSubEl = configView.querySelector('[data-role="cfg-sub"]');
1740
1986
  const subTitleEl = configView.querySelector('[data-role="sub-title"]');
@@ -1752,6 +1998,22 @@
1752
1998
  configView.querySelector('[data-cfg-val="compact"]').textContent = `${c.compactThresholdPct || 75}% 触发 · 编辑`;
1753
1999
  configView.querySelector('[data-cfg-act="toggle-map"]').classList.toggle('on', c.workspaceMap !== false);
1754
2000
 
2001
+ const llmSummaryEl = configView.querySelector('[data-cfg-val="llm"]');
2002
+ if (llmSummaryEl) {
2003
+ if (isLlmConfigured()) {
2004
+ llmSummaryEl.textContent = `${meta.llm?.providerLabel || '已配置'} · ${(meta.llm?.model || meta.model || '').split('/').pop()}`;
2005
+ llmSummaryEl.style.color = '#059669';
2006
+ } else {
2007
+ llmSummaryEl.textContent = '未配置 · 点击设置';
2008
+ llmSummaryEl.style.color = 'var(--clado-ui-brand)';
2009
+ }
2010
+ }
2011
+
2012
+ const acpSummaryEl = configView.querySelector('[data-cfg-val="acp"]');
2013
+ if (acpSummaryEl) {
2014
+ acpSummaryEl.textContent = meta.llm?.acpCommand || '低优备用';
2015
+ }
2016
+
1755
2017
  const cacheEl = configView.querySelector('[data-cfg-val="cache"]');
1756
2018
  const rate = debugState.telemetry?.hitRatePct ?? (c.timeInjection === 'system_head' ? 0 : c.canvasMemory === 'full' ? 78.8 : 99.4);
1757
2019
  if (c.timeInjection === 'system_head') {
@@ -1771,9 +2033,18 @@
1771
2033
  const res = await fetch(configEndpoint, { cache: 'no-store' });
1772
2034
  if (!res.ok) return;
1773
2035
  const data = await res.json();
2036
+ if (data.llm) {
2037
+ meta.llm = data.llm;
2038
+ meta.builtinConfigured = Boolean(data.llm.configured);
2039
+ meta.model = data.llm.model;
2040
+ meta.providerId = data.llm.providerId;
2041
+ meta.providerLabel = data.llm.providerLabel;
2042
+ }
2043
+ if (data.mcpUrl) meta.mcpUrl = data.mcpUrl;
1774
2044
  if (data.config) debugState.config = data.config;
1775
2045
  if (data.memory) debugState.memory = data.memory;
1776
2046
  if (data.telemetry) debugState.telemetry = data.telemetry;
2047
+ syncModelChip();
1777
2048
  syncConfigSummaryUI();
1778
2049
  } catch {}
1779
2050
  }
@@ -1796,11 +2067,17 @@
1796
2067
  } catch {}
1797
2068
  }
1798
2069
 
1799
- function openSettingsOverlay() {
2070
+ async function openSettingsOverlay(initialSub = '') {
1800
2071
  closeCfgSub();
2072
+ closeModelMenu();
2073
+ closeCtxMenu();
1801
2074
  configView.classList.add('show');
1802
2075
  dock.hidden = true;
1803
- loadDebugConfig();
2076
+ await loadDebugConfig();
2077
+ if (initialSub) {
2078
+ if (initialSub === 'llm' && meta.llm?.providerId) activeProviderDraft = meta.llm.providerId;
2079
+ openCfgSub(initialSub);
2080
+ }
1804
2081
  }
1805
2082
 
1806
2083
  function closeSettingsOverlay() {
@@ -1815,6 +2092,177 @@
1815
2092
  cfgHomeEl.classList.remove('pushed-out');
1816
2093
  }
1817
2094
 
2095
+ function renderLlmSubBody() {
2096
+ const presets = Array.isArray(meta.llm?.presets) && meta.llm.presets.length
2097
+ ? meta.llm.presets
2098
+ : [
2099
+ { 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 },
2100
+ { 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 },
2101
+ { id: 'deepseek', label: 'DeepSeek', protocol: 'openai', defaultBaseUrl: 'https://api.deepseek.com/v1', defaultModel: 'deepseek-chat', models: ['deepseek-chat', 'deepseek-reasoner'], requiresKey: true },
2102
+ { 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 },
2103
+ { 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 },
2104
+ { id: 'custom', label: '自定义接口', protocol: 'openai', defaultBaseUrl: 'https://api.openai.com/v1', defaultModel: 'gpt-4.1-mini', models: [], requiresKey: true },
2105
+ ];
2106
+ if (!presets.some(p => p.id === activeProviderDraft)) activeProviderDraft = presets[0].id;
2107
+ const preset = presets.find(p => p.id === activeProviderDraft) || presets[0];
2108
+ const prof = meta.llm?.profiles?.[preset.id] || {};
2109
+ const curProtocol = prof.protocol || preset.protocol || 'openai';
2110
+ const curBaseUrl = prof.baseUrl || preset.defaultBaseUrl || '';
2111
+ const curModel = prof.model || preset.defaultModel || '';
2112
+ const modelCandidates = [...new Set([...(prof.models || []), ...(preset.models || [])])].slice(0, 18);
2113
+ const keyPlaceholder = preset.requiresKey === false
2114
+ ? '本地模型免 API Key,可直接留空保存'
2115
+ : (prof.hasApiKey ? `已保存 ${prof.maskedKey || '密钥'}(留空保持不变,输入新值则覆盖)` : '输入该供应商的 API Key (如 sk-...)');
2116
+
2117
+ subBodyEl.innerHTML = `
2118
+ <div style="display:flex;flex-wrap:wrap;gap:5px;">
2119
+ ${presets.map(p => {
2120
+ const pHas = Boolean(meta.llm?.profiles?.[p.id]?.hasApiKey);
2121
+ const active = p.id === activeProviderDraft;
2122
+ 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>`;
2123
+ }).join('')}
2124
+ </div>
2125
+
2126
+ <div style="display:flex;align-items:center;justify-content:space-between;gap:8px;">
2127
+ <span style="font-size:12px;color:var(--clado-ui-muted);">接口协议</span>
2128
+ <div class="clado-tab-group">
2129
+ <button type="button" class="clado-tab-btn ${curProtocol === 'openai' ? 'active' : ''}" data-llm-proto="openai" style="font-size:11.5px;padding:4px 9px;">OpenAI 兼容</button>
2130
+ <button type="button" class="clado-tab-btn ${curProtocol === 'anthropic' ? 'active' : ''}" data-llm-proto="anthropic" style="font-size:11.5px;padding:4px 9px;">Anthropic 原生</button>
2131
+ </div>
2132
+ </div>
2133
+
2134
+ <div>
2135
+ <div style="font-size:12px;color:var(--clado-ui-muted);margin-bottom:4px;">API 地址 (Base URL)</div>
2136
+ <input type="text" class="clado-clean-input" data-llm-base value="${curBaseUrl.replace(/"/g, '&quot;')}" placeholder="https://api.openai.com/v1" />
2137
+ </div>
2138
+
2139
+ <div>
2140
+ <div style="display:flex;justify-content:space-between;font-size:12px;color:var(--clado-ui-muted);margin-bottom:4px;">
2141
+ <span>API Key</span>
2142
+ ${prof.hasApiKey ? `<span style="color:#059669;font-weight:600;">已配置 (${prof.maskedKey})</span>` : ''}
2143
+ </div>
2144
+ <input type="password" class="clado-clean-input" data-llm-key autocomplete="off" placeholder="${keyPlaceholder.replace(/"/g, '&quot;')}" />
2145
+ </div>
2146
+
2147
+ <div>
2148
+ <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:4px;">
2149
+ <span style="font-size:12px;color:var(--clado-ui-muted);">模型 ID (可手填或拉取)</span>
2150
+ <button type="button" class="clado-tab-btn active" data-llm-fetch style="font-size:11px;padding:3px 8px;">↻ 拉取模型列表</button>
2151
+ </div>
2152
+ <input type="text" class="clado-clean-input" data-llm-model value="${curModel.replace(/"/g, '&quot;')}" placeholder="例如 gpt-4.1 / claude-sonnet-4-5 / deepseek-chat" />
2153
+ ${modelCandidates.length ? `
2154
+ <div data-llm-chips style="display:flex;flex-wrap:wrap;gap:5px;margin-top:7px;">
2155
+ ${modelCandidates.map(m => `<button type="button" class="clado-tool-chip" data-pick-model="${m.replace(/"/g, '&quot;')}" style="font-size:11px;">${m}</button>`).join('')}
2156
+ </div>` : '<div data-llm-chips style="display:flex;flex-wrap:wrap;gap:5px;margin-top:7px;"></div>'}
2157
+ </div>
2158
+
2159
+ <button type="button" class="clado-cmd-btn allow" data-llm-save style="height:36px;font-size:13px;border-radius:11px;">保存并设为当前主力模型</button>`;
2160
+
2161
+ let selectedProto = curProtocol;
2162
+ subBodyEl.querySelectorAll('[data-pick-provider]').forEach(btn => {
2163
+ btn.onclick = () => {
2164
+ activeProviderDraft = btn.dataset.pickProvider;
2165
+ renderLlmSubBody();
2166
+ };
2167
+ });
2168
+ subBodyEl.querySelectorAll('[data-llm-proto]').forEach(btn => {
2169
+ btn.onclick = () => {
2170
+ selectedProto = btn.dataset.llmProto;
2171
+ subBodyEl.querySelectorAll('[data-llm-proto]').forEach(b => b.classList.toggle('active', b === btn));
2172
+ };
2173
+ });
2174
+ const baseInput = subBodyEl.querySelector('[data-llm-base]');
2175
+ const keyInput = subBodyEl.querySelector('[data-llm-key]');
2176
+ const modelInput = subBodyEl.querySelector('[data-llm-model]');
2177
+ const chipsWrap = subBodyEl.querySelector('[data-llm-chips]');
2178
+
2179
+ const bindModelChips = () => {
2180
+ chipsWrap?.querySelectorAll('[data-pick-model]').forEach(chip => {
2181
+ chip.onclick = () => { modelInput.value = chip.dataset.pickModel; };
2182
+ });
2183
+ };
2184
+ bindModelChips();
2185
+
2186
+ subBodyEl.querySelector('[data-llm-fetch]').onclick = async ev => {
2187
+ const btn = ev.currentTarget;
2188
+ btn.disabled = true;
2189
+ btn.textContent = '拉取中…';
2190
+ try {
2191
+ const res = await fetch(configEndpoint, {
2192
+ method: 'POST',
2193
+ headers: { 'content-type': 'application/json' },
2194
+ body: JSON.stringify({
2195
+ action: 'fetch_models',
2196
+ providerId: activeProviderDraft,
2197
+ protocol: selectedProto,
2198
+ baseUrl: baseInput.value.trim(),
2199
+ apiKey: keyInput.value.trim(),
2200
+ }),
2201
+ });
2202
+ const data = await res.json();
2203
+ if (!res.ok) throw new Error(data.error || '拉取失败');
2204
+ const fetched = Array.isArray(data.models) ? data.models : [];
2205
+ if (fetched.length) {
2206
+ if (!modelInput.value.trim()) modelInput.value = fetched[0];
2207
+ chipsWrap.innerHTML = fetched.slice(0, 24).map(m => `<button type="button" class="clado-tool-chip" data-pick-model="${m.replace(/"/g, '&quot;')}" style="font-size:11px;">${m}</button>`).join('');
2208
+ bindModelChips();
2209
+ showToast(`已拉取 ${fetched.length} 个可用模型`);
2210
+ } else {
2211
+ showToast('接口未返回模型列表,可直接手动输入模型 ID');
2212
+ }
2213
+ } catch (err) {
2214
+ showToast(err.message || '拉取模型失败');
2215
+ } finally {
2216
+ btn.disabled = false;
2217
+ btn.textContent = '↻ 拉取模型列表';
2218
+ }
2219
+ };
2220
+
2221
+ subBodyEl.querySelector('[data-llm-save]').onclick = async ev => {
2222
+ const btn = ev.currentTarget;
2223
+ const typedKey = keyInput.value.trim();
2224
+ if (preset.requiresKey !== false && !prof.hasApiKey && !typedKey) {
2225
+ showToast('请填写 API Key 后保存');
2226
+ keyInput.focus();
2227
+ return;
2228
+ }
2229
+ btn.disabled = true;
2230
+ try {
2231
+ const res = await fetch(configEndpoint, {
2232
+ method: 'POST',
2233
+ headers: { 'content-type': 'application/json' },
2234
+ body: JSON.stringify({
2235
+ action: 'save_llm',
2236
+ providerId: activeProviderDraft,
2237
+ label: preset.label,
2238
+ protocol: selectedProto,
2239
+ baseUrl: baseInput.value.trim(),
2240
+ apiKey: typedKey,
2241
+ model: modelInput.value.trim() || preset.defaultModel,
2242
+ }),
2243
+ });
2244
+ const data = await res.json();
2245
+ if (!res.ok) throw new Error(data.error || '保存失败');
2246
+ if (data.llm) {
2247
+ meta.llm = data.llm;
2248
+ meta.builtinConfigured = Boolean(data.llm.configured);
2249
+ meta.model = data.llm.model;
2250
+ meta.providerId = data.llm.providerId;
2251
+ meta.providerLabel = data.llm.providerLabel;
2252
+ }
2253
+ syncModelChip();
2254
+ syncConfigSummaryUI();
2255
+ showToast(`已启用 ${meta.providerLabel} · ${meta.model}`);
2256
+ closeSettingsOverlay();
2257
+ input.focus();
2258
+ } catch (err) {
2259
+ showToast(err.message || '保存失败');
2260
+ } finally {
2261
+ btn.disabled = false;
2262
+ }
2263
+ };
2264
+ }
2265
+
1818
2266
  function renderPersonaSubBody() {
1819
2267
  const personas = debugState.config.personas || {};
1820
2268
  const cur = personas[activePersonaTab] || { name: PERSONA_META[activePersonaTab]?.label || activePersonaTab, prompt: '', initContext: '' };
@@ -1859,9 +2307,80 @@
1859
2307
 
1860
2308
  function openCfgSub(sub) {
1861
2309
  currentSub = sub;
1862
- subResetBtn.style.visibility = sub === 'cache' ? 'hidden' : 'visible';
1863
-
1864
- if (sub === 'memory') {
2310
+ subResetBtn.style.visibility = ['cache', 'llm', 'mcp', 'acp'].includes(sub) ? 'hidden' : 'visible';
2311
+
2312
+ if (sub === 'llm') {
2313
+ subTitleEl.textContent = '供应商与模型';
2314
+ renderLlmSubBody();
2315
+ } else if (sub === 'mcp') {
2316
+ subTitleEl.textContent = 'MCP 接入与内置工具';
2317
+ const liveMcp = meta.mcpUrl || (location.origin + '/mcp');
2318
+ const mcpSnippet = JSON.stringify({
2319
+ mcpServers: {
2320
+ clado: { type: 'http', url: liveMcp },
2321
+ },
2322
+ }, null, 2);
2323
+ subBodyEl.innerHTML = `
2324
+ <div style="font-size:12px;color:var(--clado-ui-muted);line-height:1.5;">
2325
+ <strong>1. Clado 内置原生工具集(已自动挂载)</strong><br/>
2326
+ 画布文档与节点(<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>spawn_peer / message_peer</code>)及工作区插件能力桥。
2327
+ </div>
2328
+ <div>
2329
+ <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:5px;">
2330
+ <span style="font-size:12px;font-weight:600;">2. 外部 IDE / 客户端接入当前画布 MCP</span>
2331
+ <button type="button" class="clado-cmd-btn allow" data-copy-mcp style="font-size:11px;padding:4px 9px;">复制 MCP JSON</button>
2332
+ </div>
2333
+ <pre class="clado-clean-textarea" style="margin:0;white-space:pre-wrap;font-size:11.5px;">${mcpSnippet}</pre>
2334
+ </div>
2335
+ <button type="button" class="clado-tab-btn active" data-open-market-from-mcp style="height:34px;font-size:12.5px;">🧩 打开插件市场扩展更多能力</button>`;
2336
+ subBodyEl.querySelector('[data-copy-mcp]').onclick = async () => {
2337
+ try {
2338
+ await navigator.clipboard.writeText(mcpSnippet);
2339
+ showToast('已复制 MCP 配置 JSON');
2340
+ } catch {
2341
+ showToast(liveMcp);
2342
+ }
2343
+ };
2344
+ subBodyEl.querySelector('[data-open-market-from-mcp]').onclick = () => {
2345
+ closeSettingsOverlay();
2346
+ window.dispatchEvent(new CustomEvent('clado:open-market'));
2347
+ };
2348
+ } else if (sub === 'acp') {
2349
+ subTitleEl.textContent = '外部 ACP 子代理(可选)';
2350
+ const curCmd = meta.llm?.acpCommand || 'zcode-acp-server';
2351
+ const curArgs = (meta.llm?.acpArgs || []).join(' ');
2352
+ subBodyEl.innerHTML = `
2353
+ <div style="font-size:12px;color:var(--clado-ui-muted);line-height:1.5;">
2354
+ Clado 默认使用上方配置的<strong>主力模型原生 Agent</strong>。仅当你在会话菜单中主动点击「⚡ 新建 ACP 子代理」时,才会启动下方外部进程作为特殊子代理分身。
2355
+ </div>
2356
+ <div>
2357
+ <div style="font-size:12px;color:var(--clado-ui-muted);margin-bottom:4px;">启动命令 (Command)</div>
2358
+ <input type="text" class="clado-clean-input" data-acp-cmd value="${curCmd.replace(/"/g, '&quot;')}" />
2359
+ </div>
2360
+ <div>
2361
+ <div style="font-size:12px;color:var(--clado-ui-muted);margin-bottom:4px;">参数 (Args,空格分隔,可留空)</div>
2362
+ <input type="text" class="clado-clean-input" data-acp-args value="${curArgs.replace(/"/g, '&quot;')}" placeholder="--stdio" />
2363
+ </div>
2364
+ <button type="button" class="clado-tab-btn active" data-acp-save style="height:34px;font-size:12.5px;">保存外部子代理命令</button>`;
2365
+ subBodyEl.querySelector('[data-acp-save]').onclick = async () => {
2366
+ const cmd = subBodyEl.querySelector('[data-acp-cmd]').value.trim();
2367
+ const args = subBodyEl.querySelector('[data-acp-args]').value.trim();
2368
+ if (!cmd) return;
2369
+ try {
2370
+ const res = await fetch(configEndpoint, {
2371
+ method: 'POST',
2372
+ headers: { 'content-type': 'application/json' },
2373
+ body: JSON.stringify({ action: 'save_acp', command: cmd, args }),
2374
+ });
2375
+ if (res.ok) {
2376
+ const data = await res.json();
2377
+ if (data.llm) meta.llm = data.llm;
2378
+ syncConfigSummaryUI();
2379
+ showToast('已保存外部 ACP 子代理命令');
2380
+ }
2381
+ } catch {}
2382
+ };
2383
+ } else if (sub === 'memory') {
1865
2384
  subTitleEl.textContent = '持久记忆 (memory.md)';
1866
2385
  const inheritedFiles = Array.isArray(debugState.memory?.inherited) ? debugState.memory.inherited.map(i => i.file) : [];
1867
2386
  const inheritedHint = inheritedFiles.length
@@ -1984,6 +2503,7 @@
1984
2503
  const next = !el.classList.contains('on');
1985
2504
  await saveDebugPatch({ workspaceMap: next });
1986
2505
  } else if (act === 'open-sub') {
2506
+ if (el.dataset.sub === 'llm' && meta.llm?.providerId) activeProviderDraft = meta.llm.providerId;
1987
2507
  openCfgSub(el.dataset.sub);
1988
2508
  } else if (act === 'close-sub') {
1989
2509
  closeCfgSub();
@@ -2025,6 +2545,8 @@
2025
2545
  if (meta.defaultPersona && PERSONA_META[meta.defaultPersona]) {
2026
2546
  persona = meta.defaultPersona;
2027
2547
  }
2548
+ syncModelChip();
2549
+ syncConfigSummaryUI();
2028
2550
  const list = Array.isArray(meta.executors) ? meta.executors : [];
2029
2551
  const prev = executorSelect.value;
2030
2552
  executorSelect.replaceChildren();
@@ -2086,6 +2608,11 @@
2086
2608
  input.focus();
2087
2609
  });
2088
2610
 
2611
+ window.addEventListener('clado:open-llm-settings', () => {
2612
+ setMinimized(false);
2613
+ openSettingsOverlay('llm');
2614
+ });
2615
+
2089
2616
  // 每秒检查是否有会话跨越 30s 活跃/静息分界线,平滑收缩状态字与重排
2090
2617
  const idleTick = setInterval(() => {
2091
2618
  if (!sessionsList.length) return;
@@ -2103,6 +2630,7 @@
2103
2630
 
2104
2631
  document.addEventListener('pointerdown', event => {
2105
2632
  if (!ctxMenu.contains(event.target)) closeCtxMenu();
2633
+ if (!modelMenu.contains(event.target) && !modelChip.contains(event.target)) closeModelMenu();
2106
2634
  for (const dd of glassDropdowns) {
2107
2635
  if (!dd.menu.hidden && !dd.wrap.contains(event.target)) dd.setOpen(false);
2108
2636
  }
@@ -2111,6 +2639,7 @@
2111
2639
  document.addEventListener('keydown', event => {
2112
2640
  if (event.key === 'Escape') {
2113
2641
  closeCtxMenu();
2642
+ closeModelMenu();
2114
2643
  for (const dd of glassDropdowns) {
2115
2644
  if (!dd.menu.hidden) dd.setOpen(false);
2116
2645
  }