@zifeng1023/dsh-bot 0.3.8 → 0.3.10

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/lib/client.js CHANGED
@@ -1,3 +1,20 @@
1
+ /*
2
+ * ⚠️ 本文件由 dev/concat-parts.mjs 自动拼接生成 —— 不要直接编辑!
3
+ * 分片清单(按文件名字典序拼接,改完分片运行: node dev/concat-parts.mjs):
4
+ * - src/client/parts/00-head.js
5
+ * - src/client/parts/10-tokens.js
6
+ * - src/client/parts/20-icons.js
7
+ * - src/client/parts/30-style.js
8
+ * - src/client/parts/40-report.js
9
+ * - src/client/parts/50-entry.js
10
+ * - src/client/parts/60-forms.js
11
+ * - src/client/parts/70-runmodal.js
12
+ * - src/client/parts/80-sidebar-icon.js
13
+ * - src/client/parts/85-dockbar.js
14
+ * - src/client/parts/90-console.js
15
+ * - src/client/parts/95-register.js
16
+ */
17
+
1
18
  /**
2
19
  * dsh-bot 面板 — 浏览器端
3
20
  *
@@ -21,7 +38,7 @@
21
38
  'use strict';
22
39
 
23
40
  // 构建时由 tsdown 替换为 package.json.version(见 tsdown.config.ts)
24
- const BOT_BUILD = '0.3.8';
41
+ const BOT_BUILD = '0.3.10';
25
42
 
26
43
  // ============================================================
27
44
  // 设计令牌
@@ -348,6 +365,16 @@ let styleInjected = false;
348
365
  function injectStyle() {
349
366
  if (styleInjected) return;
350
367
  styleInjected = true;
368
+ // ⚠️ 先移除本插件此前注入的样式标签。
369
+ // 热重载 / 升级后页面里可能同时存在多份:新版只覆盖它写到的属性,
370
+ // 旧版独有的属性(例如旧 toast 的 bottom:140px)会继续生效并叠加出新形状。
371
+ try {
372
+ for (const old of Array.from(document.querySelectorAll('style[data-plugin="' + NS + '"]'))) {
373
+ old.remove();
374
+ }
375
+ } catch {
376
+ /* 清理失败不影响注入 */
377
+ }
351
378
  const el = document.createElement('style');
352
379
  el.setAttribute('data-plugin', NS);
353
380
  el.textContent = `
@@ -720,6 +747,13 @@ function injectStyle() {
720
747
  .${NS}-c-mem p { margin: 0; font-size: 13px; line-height: 20px; color: var(--c-l1); }
721
748
  .${NS}-c-mem time { display: block; margin-top: 2px; font-size: 12px; line-height: 18px; color: var(--c-l3); }
722
749
 
750
+ /* 卡片底部说明块(通知卡的「只覆盖通知项」提示) */
751
+ .${NS}-c-hint-block {
752
+ margin-top: 10px; padding-top: 10px;
753
+ border-top: 0.5px solid var(--c-stroke);
754
+ font-size: 11px; line-height: 16px; color: var(--c-l3);
755
+ }
756
+
723
757
  /* 空态 */
724
758
  .${NS}-c-empty { padding: 12px 14px; border-radius: var(--c-r-md); border: 1px dashed var(--c-l2b); background: color-mix(in srgb, var(--c-l1) 2%, transparent); }
725
759
  .${NS}-c-empty p { margin: 0 0 10px; font-size: 13px; line-height: 20px; color: var(--c-l3); }
@@ -854,6 +888,154 @@ select.${NS}-c-input { appearance: auto; }
854
888
  .${NS}-c-stat:nth-child(3) { border-left: 0; }
855
889
  .${NS}-c-stat:nth-child(n+3) { border-top: 1px solid var(--c-stroke); }
856
890
  }
891
+
892
+ /* ---------- v0.3.9 dock 快捷条 ---------- */
893
+ /* 结构:.dockbar(定位/边框/宽度上限)
894
+ └ .dockbar-row(flex 一行,overflow:hidden —— 内容再多也绝不撑破)
895
+ └ 弹层(row 的兄弟节点,可溢出到边框之外) */
896
+ .${NS}-dockbar {
897
+ position: relative; display: flex; align-items: center;
898
+ box-sizing: border-box;
899
+ width: 100%;
900
+ max-width: calc(var(--dsh-composer-card-max-width, 748px) - var(--dsh-composer-dock-inset, 0px) * 4);
901
+ margin: 4px auto 8px;
902
+ min-height: 44px; padding: 0 8px;
903
+ border: 1px solid var(--c-stroke, var(--dsw-alias-border-l2, rgba(255,255,255,.10)));
904
+ border-radius: 12px;
905
+ background: var(--c-card, var(--dsw-alias-settings-card-fill, rgba(255,255,255,.06)));
906
+ font-family: ${FONT};
907
+ }
908
+ .${NS}-dockbar-wrap { display: block; }
909
+ .${NS}-dockbar-row {
910
+ display: flex; align-items: center; gap: 6px;
911
+ flex: 1 1 auto; min-width: 0; overflow: hidden;
912
+ height: 100%;
913
+ }
914
+ /* 主区:身份/状态/花费/模型 —— 空间不够时由它让步 */
915
+ .${NS}-dockbar-main {
916
+ display: flex; align-items: center; gap: 6px;
917
+ flex: 1 1 auto; min-width: 0; overflow: hidden;
918
+ }
919
+ /* 操作区:执行 / 管理中心 / 收起 —— 永远完整可见,先饿死主区也不压它 */
920
+ .${NS}-dockbar-actions {
921
+ display: flex; align-items: center; gap: 6px;
922
+ flex: 0 0 auto;
923
+ }
924
+ .${NS}-dockbar.${NS}-dockbar-collapsed {
925
+ min-height: 36px; padding: 0 6px; border-radius: 999px;
926
+ }
927
+
928
+ /* 统一的可收缩语义:ghost 元素可缩,按钮不可缩 */
929
+ .${NS}-db-chip, .${NS}-db-model, .${NS}-db-cost { flex: 0 1 auto; min-width: 0; overflow: hidden; }
930
+ .${NS}-db-stat, .${NS}-db-btn { flex: 0 0 auto; }
931
+ .${NS}-db-chip .nm, .${NS}-db-model .txt, .${NS}-db-cost .txt {
932
+ display: block;
933
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
934
+ }
935
+
936
+ .${NS}-db-chip, .${NS}-db-model, .${NS}-db-btn {
937
+ display: inline-flex; align-items: center; gap: 6px;
938
+ border: none; background: transparent; color: var(--c-l1, var(--dsw-alias-label-primary, #ededf0));
939
+ font-family: inherit; cursor: pointer; white-space: nowrap;
940
+ }
941
+ .${NS}-db-chip { min-width: 0; max-width: 210px; height: 30px; padding: 0 8px; border-radius: 8px; font-size: 12px; font-weight: 500; }
942
+ .${NS}-db-chip:hover { background: var(--c-hover, var(--dsw-alias-interactive-bg-hover, rgba(255,255,255,.06))); }
943
+ .${NS}-db-chip .mark { width: 16px; height: 16px; border-radius: 5px; background: rgba(224,116,92,.16); border: 0.5px solid rgba(224,116,92,.3); display: grid; place-items: center; color: var(--c-brand, var(--dsw-alias-brand-primary, #e0745c)); flex: none; }
944
+ .${NS}-db-chip .chev { color: var(--c-l3, var(--dsw-alias-label-tertiary, #76777e)); flex: none; display: inline-flex; }
945
+ .${NS}-db-iconbtn { flex: none; padding: 0 6px; color: var(--c-l3, var(--dsw-alias-label-tertiary, #76777e)); }
946
+ .${NS}-db-iconbtn:hover { color: var(--c-l1, #ededf0); }
947
+
948
+ .${NS}-db-stat {
949
+ display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px;
950
+ border-radius: 999px; border: 0.5px solid var(--c-stroke, var(--dsw-alias-border-l1, rgba(255,255,255,.06)));
951
+ font-size: 11px; font-weight: 500; background: transparent; cursor: pointer; white-space: nowrap;
952
+ font-family: inherit;
953
+ }
954
+ .${NS}-db-stat .dot { width: 7px; height: 7px; border-radius: 999px; background: var(--c-l3, #76777e); flex: none; }
955
+ .${NS}-db-stat .stat-text { overflow: hidden; text-overflow: ellipsis; }
956
+ .${NS}-db-stat-dotonly { padding: 0 7px; }
957
+ .${NS}-db-stat.ok { color: var(--c-ok, var(--dsw-alias-state-success-primary, #6cc08b)); border-color: rgba(108,192,139,.25); }
958
+ .${NS}-db-stat.ok .dot { background: var(--c-ok, #6cc08b); }
959
+ .${NS}-db-stat.err { color: var(--c-err, var(--dsw-alias-state-error-primary, #e06c75)); border-color: rgba(224,108,117,.3); }
960
+ .${NS}-db-stat.err .dot { background: var(--c-err, #e06c75); }
961
+ .${NS}-db-stat.run { color: var(--c-brand-text, var(--dsw-alias-brand-text, #ec8d78)); border-color: rgba(224,116,92,.35); }
962
+ .${NS}-db-stat.run .dot { background: var(--c-brand, #e0745c); animation: ${NS}-db-spin 1s linear infinite; }
963
+ @keyframes ${NS}-db-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
964
+
965
+ .${NS}-db-cost { flex: 0 0 auto; font-size: 11px; color: var(--c-l2, var(--dsw-alias-label-secondary, #a8a9af)); padding: 0 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
966
+ .${NS}-db-cost .lim { color: var(--c-l3, var(--dsw-alias-label-tertiary, #76777e)); }
967
+ .${NS}-db-cost b { color: var(--c-l1, var(--dsw-alias-label-primary, #ededf0)); font-weight: 500; }
968
+ .${NS}-db-space { flex: 1 1 0; min-width: 2px; }
969
+
970
+ .${NS}-db-btn { height: 30px; padding: 0 12px; border-radius: 8px; font-size: 12px; font-weight: 500; border: 1px solid var(--c-stroke, var(--dsw-alias-border-l2, rgba(255,255,255,.10))); }
971
+ .${NS}-db-btn:hover { background: var(--c-hover, var(--dsw-alias-interactive-bg-hover, rgba(255,255,255,.06))); }
972
+ .${NS}-db-btn.primary { background: var(--c-brand, var(--dsw-alias-brand-primary, #e0745c)); border-color: transparent; color: var(--dsw-alias-label-primary-foreground, #1b1210); }
973
+ .${NS}-db-btn.primary:hover { filter: brightness(1.06); }
974
+ .${NS}-db-btn.primary:disabled { opacity: .55; cursor: default; filter: none; }
975
+
976
+ .${NS}-db-model { min-width: 96px; max-width: 220px; height: 24px; padding: 0 9px; border-radius: 999px; border: 0.5px solid var(--c-stroke, var(--dsw-alias-border-l1, rgba(255,255,255,.06))); font-size: 11px; font-weight: 500; color: var(--c-l2, var(--dsw-alias-label-secondary, #a8a9af)); }
977
+ .${NS}-db-model:hover { color: var(--c-l1, #ededf0); background: var(--c-hover, rgba(255,255,255,.06)); }
978
+ .${NS}-db-model svg { flex: none; opacity: .7; }
979
+ .${NS}-db-model .sep { color: var(--c-l3, var(--dsw-alias-label-tertiary, #76777e)); }
980
+
981
+ /* 弹层:head 固定 / list 滚动 / foot 固定 —— 永不顶出屏幕 */
982
+ .${NS}-db-pop {
983
+ position: absolute; bottom: calc(100% + 8px); z-index: 10020;
984
+ width: 280px;
985
+ max-height: min(360px, calc(100vh - 180px));
986
+ display: flex; flex-direction: column;
987
+ padding: 6px;
988
+ border: 1px solid var(--c-stroke, var(--dsw-alias-border-l2, rgba(255,255,255,.10)));
989
+ border-radius: 12px;
990
+ background: var(--c-layer3, var(--dsw-alias-bg-layer-3, #242429));
991
+ box-shadow: 0 12px 32px rgba(0,0,0,.45);
992
+ color: var(--c-l1, var(--dsw-alias-label-primary, #ededf0));
993
+ font-family: ${FONT};
994
+ overflow: hidden;
995
+ }
996
+ .${NS}-db-pop.right { right: 0; }
997
+ .${NS}-db-pop .head { flex: none; font-size: 11px; font-weight: 500; color: var(--c-l3, #76777e); padding: 6px 8px 6px; letter-spacing: .02em; }
998
+ .${NS}-db-pop .list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
999
+ .${NS}-db-pop .list::-webkit-scrollbar { width: 8px; }
1000
+ .${NS}-db-pop .list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); border-radius: 8px; }
1001
+ .${NS}-db-pop .foot { flex: none; border-top: 1px solid var(--c-stroke, var(--dsw-alias-border-l1, rgba(255,255,255,.06))); margin-top: 4px; padding-top: 4px; display: flex; }
1002
+ .${NS}-db-pop .item {
1003
+ display: flex; align-items: center; gap: 8px; width: 100%;
1004
+ padding: 7px 8px; border: none; background: transparent; border-radius: 8px;
1005
+ cursor: pointer; text-align: left; color: inherit; font-family: inherit;
1006
+ }
1007
+ .${NS}-db-pop .item:hover { background: var(--c-hover, rgba(255,255,255,.06)); }
1008
+ .${NS}-db-pop .item.active { background: var(--c-hover, rgba(255,255,255,.08)); }
1009
+ .${NS}-db-pop .item .nm { font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 auto; }
1010
+ .${NS}-db-pop .item .meta { flex: none; display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--c-l3, #76777e); white-space: nowrap; }
1011
+ .${NS}-db-pop .item .chev { flex: none; color: var(--c-l3, #76777e); display: inline-flex; }
1012
+ .${NS}-db-pop .item.back { color: var(--c-l3, #76777e); font-size: 11px; }
1013
+ .${NS}-db-pop .item .dot { width: 6px; height: 6px; border-radius: 999px; background: var(--c-l3, #76777e); flex: none; }
1014
+ .${NS}-db-pop .item .dot.g { background: var(--c-ok, #6cc08b); }
1015
+ .${NS}-db-pop .item .dot.r { background: var(--c-err, #e06c75); }
1016
+ .${NS}-db-pop .desc { font-size: 12px; line-height: 18px; color: var(--c-l2, var(--dsw-alias-label-secondary, #a8a9af)); padding: 8px; }
1017
+ .${NS}-db-pop .desc b { color: var(--c-l1, #ededf0); font-weight: 500; }
1018
+ .${NS}-db-pop .acts { flex: none; display: flex; gap: 8px; justify-content: flex-end; padding: 4px 6px 6px; }
1019
+ .${NS}-db-pop .foot .mi { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; height: 30px; border: none; background: transparent; border-radius: 8px; font-size: 12px; color: var(--c-l2, var(--dsw-alias-label-secondary, #a8a9af)); cursor: pointer; font-family: inherit; }
1020
+ .${NS}-db-pop .foot .mi:hover { background: var(--c-hover, rgba(255,255,255,.06)); color: var(--c-l1, #ededf0); }
1021
+ .${NS}-db-pop .foot .mi + .mi { border-left: 1px solid var(--c-stroke, var(--dsw-alias-border-l1, rgba(255,255,255,.06))); }
1022
+
1023
+ .${NS}-db-toast {
1024
+ /* 屏幕中央(用户:不要挡住 Bot 快捷条);pointer-events:none 保证不截获点击 */
1025
+ position: fixed; top: 50%; left: 50%; bottom: auto; right: auto;
1026
+ transform: translate(-50%, -50%);
1027
+ height: auto; max-height: 60vh; overflow: hidden;
1028
+ margin: 0; box-sizing: border-box;
1029
+ padding: 8px 14px; border-radius: 10px; z-index: 10030;
1030
+ background: var(--c-layer3, var(--dsw-alias-bg-layer-3, #242429));
1031
+ border: 1px solid var(--c-stroke, rgba(255,255,255,.10));
1032
+ color: var(--c-l1, var(--dsw-alias-label-primary, #ededf0));
1033
+ font-size: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
1034
+ font-family: ${FONT};
1035
+ pointer-events: none;
1036
+ max-width: min(520px, 80vw);
1037
+ text-align: center; line-height: 18px;
1038
+ }
857
1039
  `;
858
1040
  document.head.appendChild(el);
859
1041
  }
@@ -953,7 +1135,9 @@ try {
953
1135
  window.__ModuleLoader__.load({
954
1136
  id: '@zifeng1023/dsh-bot',
955
1137
  factory: (require) => {
956
- const inject = ['slots'];
1138
+ // 刀1 v0.3.9:需要 layout.selectPanel 打开管理中心;layout 由宿主 ui-layout 提供,
1139
+ // 旧宿主没有时 ctx.layout 为 undefined(所有调用点都有 try/catch 降级)。
1140
+ const inject = ['slots', 'layout'];
957
1141
 
958
1142
  // ⭐ 在这里给模块级的 React / h 赋值。
959
1143
  // 图标组件在模块顶层定义,它们闭包引用这两个变量;
@@ -2029,2159 +2213,464 @@ window.__ModuleLoader__.load({
2029
2213
  //
2030
2214
  // 其余内容(记忆、例行、模型、预算、快照)收进「更多」。
2031
2215
  // ============================================================
2216
+ // ============================================================
2217
+ // v0.3.9 刀1:旧 dock 完整面板已删除(能力归属 0.3.8 控制台,见 PLAN-v0.3.9)。
2218
+ // 本分片只保留侧边栏图标;新的快捷条在 85-dockbar.js。
2219
+ // ============================================================
2032
2220
 
2033
- /** 判断 Bot 当前最需要注意的状态 */
2034
- function botSituation(bot, detail) {
2035
- const goal = detail?.goal;
2036
- const runs = detail?.runs ?? [];
2037
- const last = runs[0];
2038
-
2039
- if (detail?.proposals?.length) return 'proposal';
2040
- if (goal?.status === 'pending_confirmation') return 'pending';
2041
- if (goal?.status === 'blocked') return 'blocked';
2042
- if (last?.status === 'failed') return 'failed';
2043
- if (last?.status === 'budget_exceeded') return 'budget';
2044
- if (!goal) return 'no-goal';
2045
- if (goal.status === 'achieved' || goal.status === 'abandoned') return 'done';
2046
- return 'normal';
2221
+ /** 侧边栏图标(只画字形,颜色跟随 currentColor) */
2222
+ function BotSidebarIcon({ size = 16 }) {
2223
+ return h(
2224
+ 'svg',
2225
+ { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', 'aria-hidden': 'true' },
2226
+ h('rect', { x: 4, y: 6.5, width: 16, height: 12, rx: 3, stroke: 'currentColor', strokeWidth: 1.6 }),
2227
+ h('circle', { cx: 9, cy: 12.5, r: 1.4, fill: 'currentColor' }),
2228
+ h('circle', { cx: 15, cy: 12.5, r: 1.4, fill: 'currentColor' }),
2229
+ h('path', { d: 'M12 6.5V4', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' }),
2230
+ );
2047
2231
  }
2048
2232
 
2049
- /** 一行式状态摘要 —— A 方案的"摘要层" */
2050
- function renderSituation(bot, detail, act, busy) {
2051
- const sit = botSituation(bot, detail);
2052
- const goal = detail?.goal;
2053
- const last = detail?.runs?.[0];
2233
+ // ============================================================
2234
+ // v0.3.9 dock 快捷条(刀1)
2235
+ //
2236
+ // 旧 BotDock 完整面板已删除(能力归属 0.3.8 控制台,见 PLAN-v0.3.9.md)。
2237
+ // 现在对话输入框上方只有一条快捷条:
2238
+ // [Bot 切换] [状态] [今日花费·当前Bot] —— [模型快切] [执行] [管理中心] [收起]
2239
+ // 决策(2026-11-20):
2240
+ // · 会话未关联 Bot → chip 显示「未关联」,点开菜单选择即关联(记 localStorage)
2241
+ // · 花费只显示当前 Bot,全队合计在控制台
2242
+ // · 收起 = 一行胶囊(Bot 名 + 状态点 + 模型 pill + 展开)
2243
+ // · 模型快切 pill 两击换模型;完整编辑在详情页配置卡
2244
+ // ============================================================
2054
2245
 
2055
- // 统一样式的小卡片
2056
- const box = (children, tone) =>
2057
- h(
2058
- 'div',
2059
- {
2060
- style: {
2061
- margin: '0 0 8px',
2062
- padding: '8px 10px',
2063
- borderRadius: R_SM,
2064
- background: BG_L2,
2065
- border: `1px solid ${tone ?? BORDER_L1}`,
2066
- fontSize: 12,
2067
- lineHeight: 1.6,
2068
- color: LABEL_2,
2069
- },
2070
- },
2071
- children,
2072
- );
2246
+ const DOCK_COLLAPSE_KEY = NS + ':dockCollapsed';
2247
+ const DOCK_BOT_KEY = NS + ':dockBotId';
2073
2248
 
2074
- switch (sit) {
2075
- case 'no-goal':
2076
- return box(
2077
- h(
2078
- 'div',
2079
- {
2080
- style: {
2081
- display: 'flex',
2082
- alignItems: 'center',
2083
- justifyContent: 'space-between',
2084
- gap: 8,
2085
- },
2086
- },
2087
- h('span', null, '他还没有目标,不知道该守什么'),
2088
- h(
2089
- Btn,
2090
- {
2091
- onClick: () =>
2092
- act.onOpenForm?.({
2093
- kind: 'goal',
2094
- botId: bot.id,
2095
- botName: bot.name,
2096
- }),
2097
- disabled: busy,
2098
- },
2099
- '设目标',
2100
- ),
2101
- ),
2102
- );
2249
+ /** localStorage 安全读写 */
2250
+ const dockLs = {
2251
+ get(k) { try { return localStorage.getItem(k); } catch { return null; } },
2252
+ set(k, v) { try { localStorage.setItem(k, v); } catch {} },
2253
+ };
2103
2254
 
2104
- case 'pending':
2105
- return box(
2106
- h(
2107
- 'div',
2108
- null,
2109
- h(
2110
- 'div',
2111
- { style: { color: WARN, fontWeight: 600, marginBottom: 4 } },
2112
- '他自己判断做完了,等你拍板',
2113
- ),
2114
- h('div', { style: { color: LABEL_2, marginBottom: 8 } }, goal.description),
2115
- h(
2116
- 'div',
2117
- { style: { display: 'flex', gap: 6 } },
2118
- h(ConfirmBtn, {
2119
- label: '确认达成',
2120
- confirmLabel: '确认归档?',
2121
- kind: 'primary',
2122
- disabled: busy,
2123
- onConfirm: () => act('goalConfirm', bot),
2124
- }),
2125
- h(
2126
- Btn,
2127
- {
2128
- kind: 'danger',
2129
- disabled: busy,
2130
- onClick: () =>
2131
- act.onOpenForm?.({
2132
- kind: 'reject',
2133
- botId: bot.id,
2134
- botName: bot.name,
2135
- }),
2136
- },
2137
- '驳回',
2138
- ),
2139
- ),
2140
- ),
2141
- WARN,
2142
- );
2255
+ /** 状态点样式(成功/失败/部分/运行中/从未) */
2256
+ function dockStatOf(bot, running, runningDry = true) {
2257
+ if (running) return { cls: NS + '-db-stat run', label: runningDry ? '演习中' : '真跑中' };
2258
+ if (!bot) return { cls: NS + '-db-stat idle', label: '未关联' };
2259
+ const s = bot.lastRunStatus;
2260
+ if (!s) return { cls: NS + '-db-stat idle', label: '从未运行' };
2261
+ if (s === 'success') return { cls: NS + '-db-stat ok', label: '成功 · ' + fmtAgo(bot.lastRunAt) };
2262
+ if (s === 'failed') return { cls: NS + '-db-stat err', label: '失败 · ' + fmtAgo(bot.lastRunAt) };
2263
+ if (s === 'partial') return { cls: NS + '-db-stat err', label: '部分 · ' + fmtAgo(bot.lastRunAt) };
2264
+ return { cls: NS + '-db-stat', label: statusText(s) + ' · ' + fmtAgo(bot.lastRunAt) };
2265
+ }
2143
2266
 
2144
- case 'blocked':
2145
- return box(
2146
- h(
2147
- 'div',
2148
- null,
2149
- h(
2150
- 'div',
2151
- {
2152
- style: { color: ERR, fontWeight: 600, marginBottom: 4 },
2153
- },
2154
- '卡住了,需要你处理',
2155
- ),
2156
- h(
2157
- 'div',
2158
- { style: { color: LABEL_2, marginBottom: 8 } },
2159
- goal.progress || '(没有更多细节)',
2160
- ),
2161
- // ⭐ 关键:光说"需要你处理"是不够的,必须给出**能点的动作**。
2162
- // 之前这里只有一行红字,用户只能看着——
2163
- // 这是个设计漏洞,不是文案问题。
2164
- h(
2165
- 'div',
2166
- { style: { display: 'flex', gap: 6, flexWrap: 'wrap' } },
2167
- h(
2168
- Btn,
2169
- {
2170
- kind: 'primary',
2171
- disabled: busy,
2172
- onClick: () =>
2173
- act.onOpenForm?.({
2174
- kind: 'unblock',
2175
- botId: bot.id,
2176
- botName: bot.name,
2177
- }),
2178
- },
2179
- '已处理好,继续',
2180
- ),
2181
- h(
2182
- Btn,
2183
- {
2184
- disabled: busy,
2185
- onClick: () =>
2186
- act.onOpenForm?.({
2187
- kind: 'giveup',
2188
- botId: bot.id,
2189
- botName: bot.name,
2190
- }),
2191
- },
2192
- '这事做不了,放弃',
2193
- ),
2194
- ),
2195
- h(
2196
- 'div',
2197
- {
2198
- style: {
2199
- fontSize: 10,
2200
- color: LABEL_3,
2201
- marginTop: 6,
2202
- },
2203
- },
2204
- '比如:去把 /admin 的鉴权重配一下,再点「继续」。',
2205
- ),
2206
- ),
2207
- ERR,
2208
- );
2267
+ /** 机器人形小图标(复用侧边栏字形) */
2268
+ /** SVG 雪佛龙(下拉 / 上收),不再用字符 ▾ ⌃(不同字体下渲染丑陋) */
2269
+ function ChevDown({ size = 10 }) {
2270
+ return h('svg', { width: size, height: size, viewBox: '0 0 12 12', fill: 'none', 'aria-hidden': 'true' },
2271
+ h('path', { d: 'M2.5 4.5L6 8l3.5-3.5', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round' }));
2272
+ }
2273
+ function ChevUp({ size = 10 }) {
2274
+ return h('svg', { width: size, height: size, viewBox: '0 0 12 12', fill: 'none', 'aria-hidden': 'true' },
2275
+ h('path', { d: 'M2.5 7.5L6 4l3.5 3.5', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round' }));
2276
+ }
2209
2277
 
2210
- case 'failed':
2211
- return box(
2212
- h(
2213
- 'div',
2214
- null,
2215
- h(
2216
- 'div',
2217
- {
2218
- style: { color: ERR, fontWeight: 600, marginBottom: 4 },
2219
- },
2220
- '上次执行失败了',
2221
- ),
2222
- h(
2223
- 'div',
2224
- { style: { color: LABEL_2, whiteSpace: 'pre-wrap' } },
2225
- last?.error?.message ?? '没有记录到原因',
2226
- ),
2227
- ),
2228
- ERR,
2229
- );
2278
+ function DockBotMark() {
2279
+ return h('span', { className: 'mark' }, h(BotSidebarIcon, { size: 10 }));
2280
+ }
2230
2281
 
2231
- case 'budget':
2232
- return box(
2233
- h(
2234
- 'div',
2235
- { style: { color: ERR, fontWeight: 600 } },
2236
- `预算用完了:${last?.error?.message ?? '超出每日上限'}`,
2237
- ),
2238
- ERR,
2239
- );
2282
+ /** toast:短暂提示后消失(旧宿主没有 selectPanel 时的降级引导) */
2283
+ function DockToast({ text }) {
2284
+ if (!text) return null; // 空 toast 不渲染(否则输入框上方会多出一个无意义的小方块)
2285
+ return portal(h('div', { className: NS + '-db-toast' }, text));
2286
+ }
2240
2287
 
2241
- case 'proposal':
2242
- return box(
2243
- h(
2244
- 'div',
2245
- null,
2246
- h(
2247
- 'div',
2248
- { style: { color: BRAND, fontWeight: 600, marginBottom: 4 } },
2249
- `他建议了 ${detail.proposals.length} 个下一步`,
2250
- ),
2251
- h(
2252
- 'div',
2253
- { style: { color: LABEL_3, marginBottom: 8 } },
2254
- '他不会自己开张,要不要做得你定',
2255
- ),
2256
- ...detail.proposals.map((p, i) =>
2257
- h(
2258
- 'div',
2288
+ /**
2289
+ * 打开管理中心。优先 ctx.layout.selectPanel('dsh-bot')(rc.5);
2290
+ * 失败(旧宿主 / 未注册)→ toast 引导走侧边栏图标。
2291
+ */
2292
+ function openConsole(ctx) {
2293
+ try {
2294
+ if (ctx?.layout && typeof ctx.layout.selectPanel === 'function') {
2295
+ ctx.layout.selectPanel('dsh-bot');
2296
+ return true;
2297
+ }
2298
+ } catch (e) {
2299
+ report('select-panel-error', String(e?.message ?? e));
2300
+ }
2301
+ return false;
2302
+ }
2303
+
2304
+ /**
2305
+ * DockBar —— 快捷条本体。
2306
+ * 数据源:/overview(Bot 列表 + 状态 + 今日花费,10s 轮询 + 可见性感知)。
2307
+ */
2308
+ /**
2309
+ * 模型快切菜单:provider 列表 → 模型列表,两击完成切换。
2310
+ */
2311
+ /**
2312
+ * 模型快切菜单:provider 列表 → 模型列表,两击完成切换。
2313
+ * 布局:head(固定)/ list(滚动)/ foot(固定)—— provider 有 14 个时也不会顶出屏幕。
2314
+ */
2315
+ function ModelMenu({ shown, models, pickProvider, setPickProvider, setModel, openConsoleSafe }) {
2316
+ const modelsFor = (pickProvider
2317
+ ? ((models ?? []).find((x) => x && x.provider === pickProvider)?.models ?? [])
2318
+ : []);
2319
+ const providerList = (models ?? []).filter((x) => x && typeof x.provider === 'string');
2320
+ return h('div', { className: NS + '-db-pop right' },
2321
+ h('div', { className: 'head' },
2322
+ !pickProvider
2323
+ ? '切换到哪个 provider?(' + providerList.length + ')'
2324
+ : pickProvider + ' · ' + modelsFor.length + ' 个模型',
2325
+ ),
2326
+ h('div', { className: 'list' },
2327
+ !pickProvider
2328
+ ? providerList.map((x) =>
2329
+ h('button',
2259
2330
  {
2260
- key: p.id,
2261
- style: {
2262
- display: 'flex',
2263
- alignItems: 'center',
2264
- gap: 8,
2265
- paddingTop: i === 0 ? 0 : 6,
2266
- marginTop: i === 0 ? 0 : 6,
2267
- borderTop: i === 0 ? 'none' : `1px solid ${BORDER_L1}`,
2268
- },
2331
+ key: x.provider,
2332
+ className: 'item' + (x.provider === shown.model?.provider ? ' active' : ''),
2333
+ onClick: () => setPickProvider(x.provider),
2269
2334
  },
2270
- h(
2271
- 'span',
2272
- { style: { flex: 1, color: LABEL_1 } },
2273
- p.description,
2274
- ),
2275
- h(
2276
- Btn,
2335
+ h('span', { className: 'nm' }, x.provider),
2336
+ h('span', { className: 'meta' }, ((x.models ?? []).length) + ' 个'),
2337
+ h('span', { className: 'chev' }, h(ChevDown, { size: 9 })),
2338
+ ),
2339
+ )
2340
+ : [
2341
+ ...modelsFor.map((m) =>
2342
+ h('button',
2277
2343
  {
2278
- disabled: busy,
2279
- onClick: () => act('goalAccept', { ...bot, goalId: p.id }),
2344
+ key: m,
2345
+ className: 'item' + (m === shown.model?.model && pickProvider === shown.model?.provider ? ' active' : ''),
2346
+ onClick: () => void setModel(pickProvider, m),
2280
2347
  },
2281
- '接受',
2348
+ h('span', { className: 'nm' }, m),
2349
+ m === shown.model?.model && pickProvider === shown.model?.provider
2350
+ ? h('span', { className: 'meta' }, '当前')
2351
+ : null,
2282
2352
  ),
2283
2353
  ),
2284
- ),
2285
- ),
2286
- BRAND,
2287
- );
2354
+ modelsFor.length === 0
2355
+ ? h('div', { className: 'desc' }, '这个 provider 没有返回模型列表,可在详情页手动填写。')
2356
+ : null,
2357
+ h('button', { className: 'item back', onClick: () => setPickProvider(null) },
2358
+ h('span', { className: 'nm' }, '← 返回 provider'),
2359
+ ),
2360
+ ],
2361
+ ),
2362
+ h('div', { className: 'foot' },
2363
+ h('button', { className: 'mi', onClick: openConsoleSafe }, '完整编辑在详情页 →'),
2364
+ ),
2365
+ );
2366
+ }
2288
2367
 
2289
- case 'done':
2290
- return box(
2291
- h(
2292
- 'div',
2293
- { style: { color: OK, fontWeight: 600 } },
2294
- `目标已${goal.status === 'achieved' ? '达成' : '放弃'}`,
2295
- ),
2296
- OK,
2297
- );
2368
+ function DockBar({ ctx, onOpenConsole }) {
2369
+ const [bots, setBots] = React.useState(null); // null = 加载中
2370
+ const [menuOpen, setMenuOpen] = React.useState(false);
2371
+ const [runPop, setRunPop] = React.useState(false);
2372
+ const [modelPop, setModelPop] = React.useState(false);
2373
+ const [models, setModels] = React.useState(null);
2374
+ const [busy, setBusy] = React.useState(false);
2375
+ const [runningBot, setRunningBot] = React.useState(null); // 正在演习/真跑的 botId
2376
+ const [toast, setToast] = React.useState('');
2377
+ const [collapsed, setCollapsed] = React.useState(() => dockLs.get(DOCK_COLLAPSE_KEY) === '1');
2378
+ const [assocId, setAssocId] = React.useState(() => dockLs.get(DOCK_BOT_KEY) || '');
2379
+ const rootRef = React.useRef(null);
2298
2380
 
2299
- // normal
2300
- default: {
2301
- const bits = [];
2302
- if (goal) bits.push(`在守「${goal.description}」`);
2303
- if (goal?.cadence) {
2304
- bits.push(
2305
- goal.lastFiredAt
2306
- ? `上次自动跑 ${fmtAgo(goal.lastFiredAt)}`
2307
- : '还没自动跑过',
2308
- );
2381
+ // 点击空白处关闭弹层
2382
+ React.useEffect(() => {
2383
+ if (!menuOpen && !runPop && !modelPop) return undefined;
2384
+ const close = (e) => {
2385
+ if (rootRef.current && !rootRef.current.contains(e.target)) {
2386
+ setMenuOpen(false); setRunPop(false); setModelPop(false);
2387
+ }
2388
+ };
2389
+ document.addEventListener('mousedown', close);
2390
+ return () => document.removeEventListener('mousedown', close);
2391
+ }, [menuOpen, runPop, modelPop]);
2392
+
2393
+ // 轮询 overview(10s);页面隐藏时不拉
2394
+ React.useEffect(() => {
2395
+ let stop = false;
2396
+ let timer = null;
2397
+ const tick = async () => {
2398
+ if (stop || document.hidden) return;
2399
+ try {
2400
+ const r = await fetch('/_dsh-bot/overview', { headers: { accept: 'application/json' } });
2401
+ const j = await r.json();
2402
+ if (!stop && j?.ok) setBots(Array.isArray(j.value?.bots) ? j.value.bots : []);
2403
+ } catch { /* 下轮再试 */ }
2404
+ };
2405
+ void tick();
2406
+ timer = setInterval(tick, 10_000);
2407
+ return () => { stop = true; if (timer) clearInterval(timer); };
2408
+ }, []);
2409
+
2410
+ // 执行后的运行状态跟踪:30s 内每 2s 查最近一轮
2411
+ React.useEffect(() => {
2412
+ if (!runningBot) return undefined;
2413
+ const t0 = Date.now();
2414
+ const timer = setInterval(async () => {
2415
+ try {
2416
+ const r = await fetch('/_dsh-bot/runs/list?botId=' + encodeURIComponent(runningBot) + '&limit=1', { headers: { accept: 'application/json' } });
2417
+ const j = await r.json();
2418
+ const run = j?.value?.runs?.[0];
2419
+ const started = run && Date.parse(run.startedAt || '') > t0 - 2000;
2420
+ const done = run && run.status && run.status !== 'running' && started && Date.parse(run.endedAt || '') > t0;
2421
+ if (done) {
2422
+ setRunningBot(null);
2423
+ setToast((run.status === 'success' ? '演习完成' : statusText(run.status)) + ' · 详情见运行记录');
2424
+ setTimeout(() => setToast(''), 4000);
2425
+ } else if (Date.now() - t0 > 120_000) {
2426
+ setRunningBot(null);
2427
+ setToast('仍在运行,可去运行记录查看进度');
2428
+ setTimeout(() => setToast(''), 4000);
2429
+ }
2430
+ } catch { /* 下轮再试 */ }
2431
+ }, 2000);
2432
+ return () => clearInterval(timer);
2433
+ }, [runningBot]);
2434
+
2435
+ // ⚠️ 防御:overview 异常时 bots 里可能出现 null/非对象条目,任何一次 map 抛错都会让整条快捷条崩掉
2436
+ const list = (Array.isArray(bots) ? bots : []).filter((b) => b && typeof b === 'object');
2437
+ const assoc = list.find((b) => b.id === assocId) || null;
2438
+ const shown = assoc || list[0] || null;
2439
+
2440
+ /** 关联 Bot(或切换) */
2441
+ const pickBot = (b) => {
2442
+ setAssocId(b.id);
2443
+ dockLs.set(DOCK_BOT_KEY, b.id);
2444
+ setMenuOpen(false);
2445
+ };
2446
+
2447
+ /** 执行(dryRun 默认 true) */
2448
+ const doRun = async (dryRun) => {
2449
+ if (!shown || busy) return;
2450
+ setBusy(true);
2451
+ setRunPop(false);
2452
+ try {
2453
+ const r = await fetch('/_dsh-bot/run', {
2454
+ method: 'POST',
2455
+ headers: { 'content-type': 'application/json' },
2456
+ // confirm: true —— 用户已在上一步的确认浮层里显式点过(演习同样需要,
2457
+ // 这是 /run 路由的既有安全设计:任何执行都必须带显式确认)
2458
+ body: JSON.stringify({ botId: shown.id, dryRun, confirm: true }),
2459
+ });
2460
+ const j = await r.json();
2461
+ if (j?.ok) {
2462
+ setRunningDry(dryRun);
2463
+ setRunningBot(shown.id);
2464
+ setToast(dryRun ? '演习已启动' : '真实执行已启动');
2309
2465
  } else {
2310
- bits.push('没设自动节奏');
2466
+ setToast('启动失败:' + (j?.message || '未知错误'));
2311
2467
  }
2312
- if (last) bits.push(`上次 ${statusText(last.status)} ${fmtAgo(last.startedAt)}`);
2313
- return box(h('div', { style: { color: LABEL_3 } }, bits.join(' · ')));
2468
+ } catch (e) {
2469
+ setToast('启动失败:' + String(e?.message ?? e));
2470
+ } finally {
2471
+ setBusy(false);
2472
+ setTimeout(() => setToast(''), 4000);
2314
2473
  }
2315
- }
2316
- }
2474
+ };
2317
2475
 
2476
+ /** 拉模型列表(首次展开模型菜单) */
2477
+ const ensureModels = async () => {
2478
+ if (models) return;
2479
+ try {
2480
+ const r = await fetch('/_dsh-bot/models', { headers: { accept: 'application/json' } });
2481
+ const j = await r.json();
2482
+ if (j?.ok) setModels(j.value?.available ?? []);
2483
+ } catch { setModels([]); }
2484
+ };
2318
2485
 
2486
+ /** 两击换模型:选 provider → 选 model → POST /bot/model */
2487
+ const [pickProvider, setPickProvider] = React.useState(null);
2488
+ /** 当前这一轮是演习还是真跑(状态条文案要区分,否则用户以为演习在跑) */
2489
+ const [runningDry, setRunningDry] = React.useState(true);
2490
+ const setModel = async (provider, model) => {
2491
+ if (!shown) return;
2492
+ setModelPop(false); setPickProvider(null);
2493
+ try {
2494
+ const r = await fetch('/_dsh-bot/bot/model', {
2495
+ method: 'POST',
2496
+ headers: { 'content-type': 'application/json' },
2497
+ body: JSON.stringify({ botId: shown.id, provider, model }),
2498
+ });
2499
+ const j = await r.json();
2500
+ setToast(j?.ok ? '模型已切到 ' + provider + ' / ' + model : '切换失败:' + (j?.message || '?'));
2501
+ // 刷新列表(overview 里的 model 字段)
2502
+ try {
2503
+ const r2 = await fetch('/_dsh-bot/overview', { headers: { accept: 'application/json' } });
2504
+ const j2 = await r2.json();
2505
+ if (j2?.ok) setBots(Array.isArray(j2.value?.bots) ? j2.value.bots : []);
2506
+ } catch {}
2507
+ } catch (e) {
2508
+ setToast('切换失败:' + String(e?.message ?? e));
2509
+ }
2510
+ setTimeout(() => setToast(''), 4000);
2511
+ };
2319
2512
 
2320
- /** 小标题 */
2321
- function SectionTitle({ children, hint }) {
2322
- return h(
2323
- 'div',
2324
- {
2325
- style: {
2326
- display: 'flex',
2327
- alignItems: 'baseline',
2328
- gap: 6,
2329
- marginBottom: 6,
2330
- },
2331
- },
2332
- h(
2333
- 'span',
2334
- { style: { fontSize: 11, fontWeight: 600, color: LABEL_2 } },
2335
- children,
2336
- ),
2337
- hint
2338
- ? h('span', { style: { fontSize: 10, color: LABEL_3 } }, hint)
2339
- : null,
2340
- );
2341
- }
2513
+ const toggleCollapse = () => {
2514
+ setCollapsed((prev) => {
2515
+ dockLs.set(DOCK_COLLAPSE_KEY, prev ? '0' : '1');
2516
+ return !prev;
2517
+ });
2518
+ };
2342
2519
 
2343
- /** ① 目标卡:进度、下一步、待确认按钮 */
2344
- function renderGoalCard(bot, detail, act, busy) {
2345
- const goal = detail.goal;
2346
- // 没有目标 → 给一个明确的行动入口
2347
- if (!goal) {
2348
- return h(
2349
- 'div',
2350
- { style: { marginBottom: 10 } },
2351
- h(SectionTitle, null, '目标'),
2352
- h(
2353
- 'div',
2354
- {
2355
- style: {
2356
- display: 'flex',
2357
- alignItems: 'center',
2358
- justifyContent: 'space-between',
2359
- gap: 8,
2360
- fontSize: 12,
2361
- color: LABEL_2,
2362
- },
2363
- },
2364
- h('span', null, '他还没有目标,不知道该守什么'),
2365
- h(
2366
- Btn,
2367
- {
2368
- onClick: () =>
2369
- act.onOpenForm
2370
- ? act.onOpenForm({ kind: 'goal', botId: bot.id, botName: bot.name })
2371
- : null,
2372
- disabled: busy,
2373
- },
2374
- '设目标',
2375
- ),
2376
- ),
2377
- );
2378
- }
2379
-
2380
- const isPending = goal.status === 'pending_confirmation';
2381
- const isBlocked = goal.status === 'blocked';
2382
- const isStanding = goal.type === 'standing';
2383
-
2384
- return h(
2385
- 'div',
2386
- {
2387
- style: {
2388
- marginBottom: 10,
2389
- padding: '8px 10px',
2390
- borderRadius: R_SM,
2391
- background: BG_L2,
2392
- border: `1px solid ${
2393
- isPending || isBlocked ? goalStatusColor(goal.status) : BORDER_L1
2394
- }`,
2395
- },
2396
- },
2397
- h(
2398
- 'div',
2399
- {
2400
- style: {
2401
- display: 'flex',
2402
- alignItems: 'center',
2403
- gap: 7,
2404
- marginBottom: 4,
2405
- },
2406
- },
2407
- h(
2408
- 'span',
2409
- { style: { fontSize: 12, fontWeight: 600, color: LABEL_1 } },
2410
- goal.description,
2411
- ),
2412
- h(
2413
- 'span',
2414
- {
2415
- style: {
2416
- fontSize: 10,
2417
- color: goalStatusColor(goal.status),
2418
- flexShrink: 0,
2419
- },
2420
- },
2421
- goalStatusText(goal.status),
2422
- ),
2423
- h(
2424
- 'span',
2425
- { style: { fontSize: 10, color: LABEL_3, flexShrink: 0 } },
2426
- goalTypeText(goal.type),
2427
- ),
2428
- isStanding
2429
- ? h(
2430
- 'span',
2431
- { style: { fontSize: 10, color: LABEL_3, flexShrink: 0 } },
2432
- `第 ${goal.cycleCount ?? 0} 轮`,
2433
- )
2434
- : null,
2435
- ),
2436
- h(
2437
- 'div',
2438
- { style: { fontSize: 11, color: LABEL_2, lineHeight: 1.6 } },
2439
- goal.progress,
2440
- ),
2441
- goal.nextStep
2442
- ? h(
2443
- 'div',
2444
- { style: { fontSize: 11, color: LABEL_3, marginTop: 3 } },
2445
- `下一步:${goal.nextStep}`,
2446
- )
2447
- : null,
2448
-
2449
- // ⭐ 执行节奏 —— 这是"它会不会自己跑"的答案,
2450
- // 必须直接显示出来,不能藏在日志里。
2451
- h(
2452
- 'div',
2453
- {
2454
- style: {
2455
- fontSize: 10,
2456
- marginTop: 5,
2457
- color: goal.cadence ? LABEL_3 : WARN,
2458
- display: 'flex',
2459
- alignItems: 'center',
2460
- gap: 4,
2461
- },
2462
- },
2463
- goal.cadence
2464
- ? `自动执行节奏:${goal.cadence}` +
2465
- (goal.lastFiredAt
2466
- ? ` · 上次自动跑 ${fmtAgo(goal.lastFiredAt)}`
2467
- : ' · 还没自动跑过')
2468
- : '⚠️ 没有设置执行节奏 —— 它不会自己跑,只有你点「执行」才动',
2469
- ),
2470
-
2471
- // 待确认:这是「Bot 不能自己宣布胜利」的可见形态
2472
- isPending
2473
- ? h(
2474
- 'div',
2475
- {
2476
- style: {
2477
- display: 'flex',
2478
- alignItems: 'center',
2479
- gap: 6,
2480
- marginTop: 8,
2481
- paddingTop: 8,
2482
- borderTop: `1px solid ${BORDER_L1}`,
2483
- },
2484
- },
2485
- h(
2486
- 'span',
2487
- { style: { fontSize: 11, color: WARN, flex: 1 } },
2488
- '他自己判断做完了,等你拍板',
2489
- ),
2490
- h(
2491
- ConfirmBtn,
2492
- {
2493
- label: '确认达成',
2494
- confirmLabel: '确认归档?',
2495
- kind: 'primary',
2496
- onConfirm: () => act('goalConfirm', bot),
2497
- disabled: busy,
2498
- },
2499
- ),
2500
- h(
2501
- Btn,
2502
- {
2503
- kind: 'danger',
2504
- onClick: () =>
2505
- act.onOpenForm
2506
- ? act.onOpenForm({ kind: 'reject', botId: bot.id, botName: bot.name })
2507
- : null,
2508
- disabled: busy,
2509
- },
2510
- '驳回',
2511
- ),
2512
- )
2513
- : null,
2514
-
2515
- // 卡住了
2516
- isBlocked
2517
- ? h(
2518
- 'div',
2519
- {
2520
- style: {
2521
- fontSize: 11,
2522
- color: ERR,
2523
- marginTop: 8,
2524
- paddingTop: 8,
2525
- borderTop: `1px solid ${BORDER_L1}`,
2526
- },
2527
- },
2528
- '卡住了,需要你介入处理。处理好后在对话框说「解除阻塞」即可。',
2529
- )
2530
- : null,
2531
- );
2532
- }
2533
-
2534
- /** ② 接续建议:目标完成后的下一步候选 */
2535
- function renderProposals(proposals, bot, act, busy) {
2536
- return h(
2537
- 'div',
2538
- { style: { marginBottom: 10 } },
2539
- h(SectionTitle, { hint: '他不会自己开张' }, '建议接下来'),
2540
- h(
2541
- 'div',
2542
- {
2543
- style: {
2544
- padding: '8px 10px',
2545
- borderRadius: R_SM,
2546
- background: BG_L2,
2547
- border: `1px solid ${BORDER_L1}`,
2548
- },
2549
- },
2550
- ...proposals.map((p, i) =>
2551
- h(
2552
- 'div',
2553
- {
2554
- key: p.id,
2555
- style: {
2556
- display: 'flex',
2557
- alignItems: 'center',
2558
- gap: 8,
2559
- paddingTop: i === 0 ? 0 : 6,
2560
- marginTop: i === 0 ? 0 : 6,
2561
- borderTop: i === 0 ? 'none' : `1px solid ${BORDER_L1}`,
2562
- },
2563
- },
2564
- h(
2565
- 'span',
2566
- { style: { fontSize: 11, color: LABEL_1, flex: 1 } },
2567
- p.description,
2568
- ),
2569
- h(
2570
- 'span',
2571
- { style: { fontSize: 10, color: LABEL_3, flexShrink: 0 } },
2572
- goalTypeText(p.type),
2573
- ),
2574
- h(
2575
- Btn,
2576
- {
2577
- onClick: () =>
2578
- act('goalAccept', { ...bot, goalId: p.id }),
2579
- disabled: busy,
2580
- },
2581
- '接受',
2582
- ),
2583
- ),
2584
- ),
2585
- h(
2586
- 'div',
2587
- { style: { marginTop: 8, textAlign: 'right' } },
2588
- h(
2589
- Btn,
2590
- { onClick: () => act('goalDismiss', bot), disabled: busy },
2591
- '都不用',
2592
- ),
2593
- ),
2594
- ),
2595
- );
2596
- }
2597
-
2598
- /** ③ 最近运行 */
2599
- function renderRuns(runs) {
2600
- return h(
2601
- 'div',
2602
- { style: { marginBottom: 10 } },
2603
- h(SectionTitle, { hint: '全量记录,不设上限' }, '最近运行'),
2604
- h(
2605
- 'div',
2606
- { style: { display: 'flex', flexDirection: 'column', gap: 3 } },
2607
- ...runs.slice(0, 3).map((r) => {
2608
- const blocked = (r.steps || []).filter((s) => s.blocked).length;
2609
- const effect = r.goalEffect;
2610
- return h(
2611
- 'div',
2612
- {
2613
- key: r.id,
2614
- style: {
2615
- display: 'flex',
2616
- alignItems: 'center',
2617
- gap: 6,
2618
- fontSize: 11,
2619
- lineHeight: '18px',
2620
- },
2621
- },
2622
- h('span', {
2623
- style: {
2624
- width: 5,
2625
- height: 5,
2626
- borderRadius: 999,
2627
- background: statusColor(r.status),
2628
- flexShrink: 0,
2629
- },
2630
- }),
2631
- h(
2632
- 'span',
2633
- { style: { color: LABEL_3, flexShrink: 0 } },
2634
- r.startedAt.slice(5, 16).replace('T', ' '),
2635
- ),
2636
- h(
2637
- 'span',
2638
- { style: { color: statusColor(r.status), flexShrink: 0 } },
2639
- statusText(r.status),
2640
- ),
2641
- r.dryRun
2642
- ? h(
2643
- 'span',
2644
- { style: { color: LABEL_3, flexShrink: 0 } },
2645
- '演习',
2646
- )
2647
- : null,
2648
- blocked
2649
- ? h(
2650
- 'span',
2651
- { style: { color: WARN, flexShrink: 0 } },
2652
- `${blocked} 步拦截`,
2653
- )
2654
- : null,
2655
- effect === 'pending'
2656
- ? h('span', { style: { color: WARN, flexShrink: 0 } }, '待确认')
2657
- : null,
2658
- effect === 'cycle'
2659
- ? h('span', { style: { color: BRAND, flexShrink: 0 } }, '轮次+1')
2660
- : null,
2661
- h(
2662
- 'span',
2663
- { style: { color: LABEL_3, marginLeft: 'auto', flexShrink: 0 } },
2664
- fmtCost(r.usage),
2665
- ),
2666
- );
2667
- }),
2668
- ),
2669
- );
2670
- }
2671
-
2672
- /** ④ 他记得:记忆事实 */
2673
- function renderMemory(semantic) {
2674
- const items = [...(semantic.preferences || []), ...(semantic.facts || [])].slice(0, 4);
2675
- if (!items.length) return null;
2676
- return h(
2677
- 'div',
2678
- { style: { marginBottom: 10 } },
2679
- h(SectionTitle, { hint: '会被带进每一轮' }, '他记得'),
2680
- h(
2681
- 'div',
2682
- { style: { display: 'flex', flexDirection: 'column', gap: 2 } },
2683
- ...items.map((f, i) =>
2684
- h(
2685
- 'div',
2686
- {
2687
- key: i,
2688
- style: {
2689
- fontSize: 11,
2690
- color: LABEL_2,
2691
- lineHeight: 1.6,
2692
- overflow: 'hidden',
2693
- textOverflow: 'ellipsis',
2694
- whiteSpace: 'nowrap',
2695
- },
2696
- },
2697
- `· ${f}`,
2698
- ),
2699
- ),
2700
- ),
2701
- );
2702
- }
2703
-
2704
- /** ⑤ 例行流程 */
2705
- function renderRoutines(routines) {
2706
- return h(
2707
- 'div',
2708
- { style: { marginBottom: 10 } },
2709
- h(SectionTitle, { hint: '目标完成也不中断' }, '例行流程'),
2710
- h(
2711
- 'div',
2712
- { style: { display: 'flex', flexDirection: 'column', gap: 3 } },
2713
- ...routines.slice(0, 3).map((r) =>
2714
- h(
2715
- 'div',
2716
- {
2717
- key: r.id,
2718
- style: {
2719
- display: 'flex',
2720
- alignItems: 'center',
2721
- gap: 6,
2722
- fontSize: 11,
2723
- },
2724
- },
2725
- h('span', { style: { color: LABEL_1 } }, r.name || r.id),
2726
- r.trigger
2727
- ? h(
2728
- 'span',
2729
- { style: { color: LABEL_3, marginLeft: 'auto' } },
2730
- r.trigger,
2731
- )
2732
- : null,
2733
- ),
2734
- ),
2735
- ),
2736
- );
2737
- }
2738
-
2739
- // ---------- 主面板 ----------
2740
- function BotDock() {
2741
- try {
2742
- const [open, setOpen] = React.useState(false);
2743
- const [data, setData] = React.useState(null);
2744
- const [err, setErr] = React.useState('');
2745
- const [busy, setBusy] = React.useState(false);
2746
- const [notice, setNotice] = React.useState('');
2747
- const [detailId, setDetailId] = React.useState(null);
2748
- const [detail, setDetail] = React.useState(null);
2749
- const [headHover, setHeadHover] = React.useState(false);
2750
- const [expanded, setExpanded] = React.useState(false);
2751
- /** 内嵌表单:{ kind, botId, ... } —— 取代 window.prompt */
2752
- const [form, setForm] = React.useState(null);
2753
- /** 哪个 Bot 的「更多」是展开的(A 方案:第三层折叠) */
2754
- const [moreOpen, setMoreOpen] = React.useState(null);
2755
- /** 哪个 Bot 的「配置与危险操作」展开(与「他知道什么」分属两层) */
2756
- const [dangerOpen, setDangerOpen] = React.useState(null);
2757
- /** 哪个 Bot 正在编辑资料(名称 / 职责 / 附加说明) */
2758
- const [editOpen, setEditOpen] = React.useState(null);
2759
- const [editName, setEditName] = React.useState('');
2760
- const [editRole, setEditRole] = React.useState('');
2761
- const [editNote, setEditNote] = React.useState('');
2762
- const [cadenceMode, setCadenceMode] = React.useState('none');
2763
- const [cadenceHours, setCadenceHours] = React.useState(12);
2764
- const [cadenceTime, setCadenceTime] = React.useState('09:00');
2765
- const [cadenceDays, setCadenceDays] = React.useState([1]);
2766
- const [cadenceCustom, setCadenceCustom] = React.useState('');
2767
- /** 当前视图:bots 列表 / settings 设置页 */
2768
- const [view, setView] = React.useState('bots');
2769
-
2770
- const refresh = React.useCallback(async () => {
2771
- setBusy(true);
2772
- try {
2773
- const r = await fetch('/_dsh-bot/overview', {
2774
- headers: { accept: 'application/json' },
2775
- });
2776
- const j = await r.json();
2777
- if (j?.ok) {
2778
- setData(j.value);
2779
- // ⚠️ 这里曾经 setErr(''),导致刚显示的错误被刷新清空。
2780
- // 用户看到红框"闪了一下就没了"——比不显示还糟。
2781
- // 错误只能由用户主动操作(关掉 / 再次操作)清除,
2782
- // 不能被一个后台刷新顺手抹掉。
2783
- } else {
2784
- setErr(j?.message || '读取失败');
2785
- }
2786
- } catch (e) {
2787
- setErr(String(e?.message || e));
2788
- } finally {
2789
- setBusy(false);
2790
- }
2791
- }, []);
2792
-
2793
- React.useEffect(() => {
2794
- if (open && !data) void refresh();
2795
- }, [open, data, refresh]);
2796
-
2797
- // 打开编辑时填充「附加说明」:详情异步到达,只填一次,避免覆盖用户输入
2798
- const editPrefilled = React.useRef(null);
2799
- React.useEffect(() => {
2800
- if (!editOpen) {
2801
- editPrefilled.current = null;
2802
- return;
2803
- }
2804
- if (editPrefilled.current === editOpen) return;
2805
- if (detail?.bot?.id === editOpen) {
2806
- setEditNote(detail.bot.systemPromptExtra ?? '');
2807
- const parsed = parseCadence(detail.goal?.cadence);
2808
- setCadenceMode(parsed.mode);
2809
- setCadenceHours(parsed.hours);
2810
- setCadenceTime(parsed.time);
2811
- setCadenceDays(parsed.days);
2812
- setCadenceCustom(parsed.custom);
2813
- editPrefilled.current = editOpen;
2814
- }
2815
- }, [editOpen, detail]);
2816
-
2817
-
2818
- // 展开某个 Bot 的详情时,拉一次完整数据
2819
- // (目标 / 运行史 / 记忆 / 例行流程 / 快照都在这个接口里)
2820
- const loadDetail = React.useCallback(async (botId) => {
2821
- if (!botId) {
2822
- setDetail(null);
2823
- return;
2824
- }
2825
- try {
2826
- const r = await fetch(
2827
- `/_dsh-bot/bot?botId=${encodeURIComponent(botId)}`,
2828
- { headers: { accept: 'application/json' } },
2829
- );
2830
- const j = await r.json();
2831
- if (j?.ok) setDetail(j.value);
2832
- else setErr(j?.message || '读取详情失败');
2833
- } catch (e) {
2834
- setErr(String(e?.message || e));
2835
- }
2836
- }, []);
2837
-
2838
- React.useEffect(() => {
2839
- void loadDetail(detailId);
2840
- }, [detailId, loadDetail]);
2841
-
2842
- // ⭐ 运行中实时刷新:长任务(工具循环)进行时每 3s 拉一次详情,
2843
- // 结束即停。轮询而不是 WebSocket——够用,不引入新依赖。
2844
- React.useEffect(() => {
2845
- if (!busy || !detailId) return;
2846
- const t = setInterval(() => {
2847
- void loadDetail(detailId);
2848
- }, 3000);
2849
- return () => clearInterval(t);
2850
- }, [busy, detailId, loadDetail]);
2851
-
2852
- const act = React.useCallback(
2853
- async (kind, bot, extra) => {
2854
- setBusy(true);
2855
- setErr('');
2856
- setNotice('');
2857
- try {
2858
- const post = async (path, body) => {
2859
- const r = await fetch('/_dsh-bot' + path, {
2860
- method: 'POST',
2861
- headers: { 'content-type': 'application/json' },
2862
- body: JSON.stringify(body),
2863
- });
2864
- return r.json();
2865
- };
2866
-
2867
- let j;
2868
- if (kind === 'dry') {
2869
- j = await post('/dry-run', { botId: bot.id });
2870
- if (j?.ok) {
2871
- const st = j.value?.status;
2872
- const bl = (j.value.steps || []).filter((s) => s.blocked).length;
2873
- const errMsg = j.value?.error?.message;
2874
-
2875
- if (st === 'failed') {
2876
- setErr(`演习失败:${errMsg ?? '未知原因'}`);
2877
- } else {
2878
- setNotice(
2879
- `空跑完成:${bl} 步会被拦截,未产生真实影响`,
2880
- );
2881
- }
2882
- }
2883
- } else if (kind === 'run') {
2884
- // ⚠️ 不用 window.confirm:Electron 里 confirm() 是空实现,
2885
- // 永远返回 false,按钮会变成"点了没反应"。
2886
- // 真实执行的二次确认由按钮的 armed 态承担(见下方 UI)。
2887
- j = await post('/run', { botId: bot.id, confirm: true });
2888
- if (j?.ok) {
2889
- // ⚠️ 这里曾经把失败也当成成功提示显示(绿底 + "执行完成")。
2890
- // API 返回 ok:true 只代表"请求执行完了",
2891
- // 运行本身可能是 failed —— 必须分开处理。
2892
- const st = j.value?.status;
2893
- const errMsg = j.value?.error?.message;
2894
-
2895
- if (st === 'failed' || st === 'budget_exceeded') {
2896
- setErr(
2897
- `执行失败(${st})` + (errMsg ? `:${errMsg}` : ''),
2898
- );
2899
- } else if (st === 'partial') {
2900
- const bl = (j.value.steps || []).filter(
2901
- (s) => s.blocked,
2902
- ).length;
2903
- setNotice(
2904
- `执行部分完成${bl ? `,${bl} 步被跳过` : ''}`,
2905
- );
2906
- } else {
2907
- setNotice(`执行完成`);
2908
- }
2909
- } else if (j?.code === 'PRECHECK_FAILED') {
2910
- // 执行前检查没过:直接把原因显示出来,
2911
- // 不要让用户看到含糊的"执行失败"
2912
- setErr(j.message);
2913
- }
2914
- } else if (kind === 'snapshot') {
2915
- j = await post('/snapshot', { botId: bot.id });
2916
- if (j?.ok) setNotice(`已创建快照(${j.value.fileCount} 个文件)`);
2917
- } else if (kind === 'rollback') {
2918
- j = await post('/rollback', { botId: bot.id, confirm: true });
2919
- if (j?.ok) {
2920
- setNotice(
2921
- `已回滚:恢复 ${j.value.restored.length} 个,删除 ${j.value.removed.length} 个`,
2922
- );
2923
- }
2924
- } else if (kind === 'goalConfirm') {
2925
- j = await post('/goal/confirm', {
2926
- botId: bot.id,
2927
- confirm: true,
2928
- note: extra?.note,
2929
- });
2930
- if (j?.ok) setNotice('已确认达成并归档,下面看看建议的下一步');
2931
- } else if (kind === 'goalReject') {
2932
- j = await post('/goal/reject', {
2933
- botId: bot.id,
2934
- note: extra?.note ?? '还没做完',
2935
- });
2936
- if (j?.ok) setNotice('已驳回,目标回到进行中');
2937
- } else if (kind === 'goalUnblock') {
2938
- j = await post('/goal/unblock', {
2939
- botId: bot.id,
2940
- note: extra?.note,
2941
- });
2942
- if (j?.ok) setNotice('已解除阻塞,目标回到进行中');
2943
- } else if (kind === 'goalGiveup') {
2944
- j = await post('/goal/giveup', {
2945
- botId: bot.id,
2946
- note: extra?.note,
2947
- });
2948
- if (j?.ok) setNotice('已放弃并归档');
2949
- } else if (kind === 'goalAccept') {
2950
- j = await post('/goal/accept', { botId: bot.id, goalId: bot.goalId });
2951
- if (j?.ok) setNotice('已接受,Bot 开始守护新目标');
2952
- } else if (kind === 'goalDismiss') {
2953
- j = await post('/goal/dismiss', { botId: bot.id });
2954
- if (j?.ok) setNotice('已忽略建议');
2955
- } else if (kind === 'goalSet') {
2956
- // extra = { description, goalType }
2957
- j = await post('/goal/set', {
2958
- botId: bot.id,
2959
- description: extra.description,
2960
- goalType: extra.goalType,
2961
- });
2962
- if (j?.ok) setNotice('目标已设定');
2963
- } else if (kind === 'botCreate') {
2964
- j = await post('/bot/create', {
2965
- name: extra.name,
2966
- role: extra.role,
2967
- goal: extra.goal,
2968
- goalType: extra.goalType,
2969
- // ⚠️ 之前漏了这一行,导致「新建时填的节奏」被静默丢弃,
2970
- // 用户以为设好了,其实 goal.json 里根本没有 cadence。
2971
- cadence: extra.cadence,
2972
- });
2973
- if (j?.ok) setNotice(`已创建「${extra.name}」`);
2974
- } else if (kind === 'botModel') {
2975
- j = await post('/bot/model', {
2976
- botId: bot.id,
2977
- provider: extra.provider,
2978
- model: extra.model,
2979
- });
2980
- if (j?.ok) setNotice('模型已更新');
2981
- } else if (kind === 'clearRuns') {
2982
- j = await post('/runs/clear', {
2983
- botId: bot.id,
2984
- confirm: true,
2985
- });
2986
- if (j?.ok) {
2987
- setNotice(`已清空 ${j.value.removed} 条运行记录`);
2988
- }
2989
- } else if (kind === 'botDelete') {
2990
- j = await post('/bot/delete', { botId: bot.id, confirm: true });
2991
- if (j?.ok) {
2992
- setNotice(`已删除「${bot.name}」`);
2993
- setDetailId(null);
2994
- setDetail(null);
2995
- }
2996
- }
2997
- if (j && !j.ok) setErr(j.message || '操作失败');
2998
- await refresh();
2999
- // 目标操作会改变详情区内容,一并刷新
3000
- if (detailId) await loadDetail(detailId);
3001
- } catch (e) {
3002
- setErr(String(e?.message || e));
3003
- } finally {
3004
- setBusy(false);
3005
- }
3006
- },
3007
- [refresh, loadDetail, detailId],
3008
- );
3009
-
3010
- // 把「打开表单」挂到 act 上,让分区渲染函数能调用
3011
- act.onOpenForm = (f) => setForm(f);
3012
- act.onOpenModel = (f) => setForm({ kind: 'model', ...f });
3013
-
3014
- const bots = data?.bots ?? [];
3015
- const stats = data?.stats;
3016
-
3017
- // 卡片样式:贴近官方的 dock 卡片
3018
- // · radius-md(官方用 md,不是 lg)
3019
- // · 左侧内边距大、右侧小(给图标按钮留位)
3020
- const card = {
3021
- fontFamily: FONT,
3022
- border: `1px solid ${BORDER_L1}`,
3023
- borderRadius: R_MD,
3024
- background: BG_L2,
3025
- overflow: 'hidden',
3026
- };
3027
-
3028
- // ========== 收起态 ==========
3029
- if (!open) {
3030
- return h(
3031
- 'div',
3032
- { className: `${NS}-dock` },
3033
- h(
3034
- 'div',
3035
- {
3036
- className: `${NS}-dock-inner`,
3037
- style: {
3038
- ...card,
3039
- display: 'flex',
3040
- alignItems: 'center',
3041
- justifyContent: 'space-between',
3042
- padding: '7px 12px',
3043
- cursor: 'pointer',
3044
- transition: 'background .15s ease',
3045
- background: headHover ? HOVER_BG : BG_L2,
3046
- },
3047
- onClick: () => setOpen(true),
3048
- onMouseEnter: () => setHeadHover(true),
3049
- onMouseLeave: () => setHeadHover(false),
3050
- },
3051
- h(
3052
- 'div',
3053
- { style: { display: 'flex', alignItems: 'center', gap: 8 } },
3054
- h(IconBot, { size: 16, color: BRAND }),
3055
- h(
3056
- 'span',
3057
- { style: { fontSize: 13, fontWeight: 500, color: LABEL_1 } },
3058
- 'Bot',
3059
- ),
3060
- stats ? h(Badge, { tone: 'brand' }, `${stats.botCount} 个`) : null,
3061
- ),
3062
- h(
3063
- 'div',
3064
- { style: { display: 'flex', alignItems: 'center', gap: 8 } },
3065
- stats
3066
- ? h(
3067
- 'span',
3068
- { style: { fontSize: 12, color: LABEL_3 } },
3069
- `今日 ${fmtCny(stats.todayCostCny)}`,
3070
- )
3071
- : null,
3072
- h(IconChevron, { size: 13 }),
3073
- ),
3074
- ),
3075
- );
3076
- }
3077
-
3078
- // ========== 展开态 ==========
3079
- //
3080
- // 布局:头部固定 → 主体滚动
3081
- //
3082
- // ⚠️ 之前所有内容平铺在一层,详情区一展开就把面板撑得很高,
3083
- // 超出可视区域后既看不到下面、也没法滚(因为根本没有滚动容器)。
3084
- // 现在用 flex 列布局 + 中部 overflow-y:auto 解决。
3085
- return portal(h(
3086
- 'div',
3087
- {
3088
- className: `${NS}-dock`,
3089
- style: {
3090
- position: 'fixed',
3091
- inset: 0,
3092
- zIndex: 9998,
3093
- background: 'rgba(0, 0, 0, 0.45)',
3094
- display: 'flex',
3095
- alignItems: 'center',
3096
- justifyContent: 'center',
3097
- padding: 20,
3098
- },
3099
- onMouseDown: (e) => {
3100
- if (e.target === e.currentTarget) setOpen(false);
3101
- },
3102
- },
3103
- h(SidebarEntryPrompt, null),
3104
- h(
3105
- 'div',
3106
- {
3107
- className: `${NS}-dock-inner ${NS}-fade ${NS}-expanded`,
3108
- // v0.3.7 修正:展开态改为视口居中的浮层。
3109
- // 贴底面板会随输入框高度被挤压,无论怎么算 max-height 都会出现「顶部被挡」;
3110
- // 浮层用 82vh 上限 + 内部滚动,与输入框高度彻底解耦。
3111
- style: {
3112
- ...card,
3113
- position: 'relative',
3114
- width: 'min(760px, 94vw)',
3115
- maxHeight: '82vh',
3116
- display: 'flex',
3117
- flexDirection: 'column',
3118
- overflow: 'hidden',
3119
- zIndex: 9998,
3120
- boxShadow: 'var(--dsw-shadow-lv3)',
3121
- },
3122
- },
3123
- // ---------- 头部(固定) ----------
3124
- h(
3125
- 'div',
3126
- {
3127
- style: {
3128
- display: 'flex',
3129
- alignItems: 'center',
3130
- justifyContent: 'space-between',
3131
- padding: '8px 12px',
3132
- borderBottom: `1px solid ${BORDER_L1}`,
3133
- },
3134
- },
3135
- h(
3136
- 'div',
3137
- { style: { display: 'flex', alignItems: 'center', gap: 8 } },
3138
- h(IconBot, { size: 16, color: BRAND }),
3139
- h(
3140
- 'span',
3141
- { style: { fontSize: 13, fontWeight: 600, color: LABEL_1 } },
3142
- 'Bot 面板',
3143
- ),
3144
- stats ? h(Badge, { tone: 'brand' }, `${stats.botCount} 个`) : null,
3145
- // ⭐ 需要你拍板的数量(否则"他在等你"这件事永远看不见)
3146
- (() => {
3147
- const need = bots.filter(
3148
- (x) => x.pendingConfirmCount || x.blocked,
3149
- ).length;
3150
- return need > 0
3151
- ? h(Badge, { tone: 'warn' }, `${need} 项等你`)
3152
- : null;
3153
- })(),
3154
- // ⭐ 对话介入的回声:最近 48h 新接手的 Bot,提示用户回来看
3155
- (() => {
3156
- const cnt = data?.recentAdoptions?.length ?? 0;
3157
- return cnt > 0
3158
- ? h(Badge, { tone: 'ok' }, `新接手 ${cnt}`)
3159
- : null;
3160
- })(),
3161
- ),
3162
- h(
3163
- 'div',
3164
- { style: { display: 'flex', alignItems: 'center', gap: 6 } },
3165
- stats
3166
- ? h(
3167
- 'span',
3168
- { style: { fontSize: 12, color: LABEL_3, marginRight: 2 } },
3169
- `今日 ${fmtCny(stats.todayCostCny)}`,
3170
- )
3171
- : null,
3172
- h(
3173
- 'button',
3174
- {
3175
- className: `${NS}-row-btn`,
3176
- onClick: () => setForm({ kind: 'createBot' }),
3177
- title: '新建 Bot',
3178
- type: 'button',
3179
- },
3180
- '+',
3181
- ),
3182
- h(
3183
- 'button',
3184
- {
3185
- className: `${NS}-row-btn`,
3186
- onClick: refresh,
3187
- disabled: busy,
3188
- title: '刷新',
3189
- type: 'button',
3190
- style: { opacity: busy ? 0.5 : 1 },
3191
- },
3192
- h(IconRefresh, { size: 13, spinning: busy }),
3193
- ),
3194
- h(
3195
- 'button',
3196
- {
3197
- className: `${NS}-row-btn`,
3198
- onClick: () => setOpen(false),
3199
- title: '收起',
3200
- type: 'button',
3201
- },
3202
- h(IconCollapse, { size: 13 }),
3203
- ),
3204
- ),
3205
- ),
3206
-
3207
- // ---------- 主体(可滚动) ----------
3208
- h(
3209
- 'div',
3210
- { className: `${NS}-scroll` },
3211
-
3212
- // ===== 设置视图 =====
3213
- // 设置页是"另一个房间",打开时盖住 Bot 列表,
3214
- // 不再往下堆内容(否则又变成"挤成一坨")。
3215
- view === 'settings'
3216
- ? h(
3217
- 'div',
3218
- { style: { padding: '4px 12px 12px' } },
3219
- h(ConsoleSettings, { bots, busy }),
3220
- )
3221
- : null,
3222
-
3223
- // ===== Bot 列表视图 =====
3224
- // 内嵌表单(取代 prompt)—— 必须放在详情区之上,
3225
- // 因为它是"当前正在进行的操作",优先级高于展示信息
3226
- form
3227
- ? h(FormPanel, {
3228
- form,
3229
- busy,
3230
- onClose: () => setForm(null),
3231
- onSubmit: (kind, extra) => {
3232
- const target = bots.find((x) => x.id === form.botId) || {
3233
- id: form.botId,
3234
- name: form.botName,
3235
- };
3236
- setForm(null);
3237
- void act(kind, target, extra);
3238
- },
3239
- })
3240
- : null,
3241
-
3242
- // 错误提示
3243
- //
3244
- // 三个改进(都来自真实反馈):
3245
- // 1. 不再被 refresh 清空(之前会"闪一下就没了")
3246
- // 2. 加关闭按钮 —— 何时消失由用户决定
3247
- // 3. 更显眼:有色背景 + 图标,不再只是一条细边框
3248
- err
3249
- ? h(
3250
- 'div',
3251
- {
3252
- style: {
3253
- margin: '8px 12px',
3254
- padding: '8px 10px',
3255
- borderRadius: R_SM,
3256
- background: 'var(--dsw-alias-bg-layer-3)',
3257
- border: `1px solid ${ERR}`,
3258
- color: ERR,
3259
- fontSize: 12,
3260
- lineHeight: 1.6,
3261
- display: 'flex',
3262
- alignItems: 'flex-start',
3263
- gap: 8,
3264
- },
3265
- },
3266
- h(
3267
- 'span',
3268
- {
3269
- style: {
3270
- flexShrink: 0,
3271
- fontWeight: 700,
3272
- lineHeight: '18px',
3273
- },
3274
- },
3275
- '!',
3276
- ),
3277
- h(
3278
- 'span',
3279
- { style: { flex: 1, whiteSpace: 'pre-wrap' } },
3280
- err,
3281
- ),
3282
- h(
3283
- 'button',
3284
- {
3285
- className: `${NS}-row-btn`,
3286
- onClick: () => setErr(''),
3287
- title: '关闭',
3288
- type: 'button',
3289
- style: { flexShrink: 0 },
3290
- },
3291
- '×',
3292
- ),
3293
- )
3294
- : null,
3295
- notice
3296
- ? h(
3297
- 'div',
3298
- {
3299
- style: {
3300
- margin: '8px 12px',
3301
- padding: '6px 10px',
3302
- borderRadius: R_SM,
3303
- background: OK_TER,
3304
- color: OK,
3305
- fontSize: 12,
3306
- },
3307
- },
3308
- notice,
3309
- )
3310
- : null,
3311
-
3312
- // 空状态
3313
- data && bots.length === 0
3314
- ? h(
3315
- 'div',
3316
- {
3317
- style: {
3318
- padding: '20px 14px',
3319
- textAlign: 'center',
3320
- },
3321
- },
3322
- h(
3323
- 'div',
3324
- { style: { fontSize: 13, color: LABEL_1, marginBottom: 4 } },
3325
- '还没有 Bot',
3326
- ),
3327
- h(
3328
- 'div',
3329
- { style: { fontSize: 11, color: LABEL_3, marginBottom: 12 } },
3330
- 'Bot 是一个常驻的 AI 同事:有自己的目标、记忆和工作区',
3331
- ),
3332
- h(
3333
- Btn,
3334
- {
3335
- kind: 'primary',
3336
- onClick: () => setForm({ kind: 'createBot' }),
3337
- },
3338
- '新建 Bot',
3339
- ),
3340
- h(
3341
- 'div',
3342
- {
3343
- style: {
3344
- marginTop: 16,
3345
- paddingTop: 12,
3346
- borderTop: `1px solid ${BORDER_L1}`,
3347
- fontSize: 11,
3348
- color: LABEL_3,
3349
- textAlign: 'left',
3350
- },
3351
- },
3352
- h('div', { style: { marginBottom: 6, color: LABEL_2 } },
3353
- '也可以直接在对话框里说:',
3354
- ),
3355
- h(
3356
- 'div',
3357
- {
3358
- style: {
3359
- fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
3360
- lineHeight: 1.9,
3361
- color: LABEL_2,
3362
- },
3363
- },
3364
- '「创建一个 Bot,叫文件管家,把下载文件夹整理干净」',
3365
- h('br'),
3366
- '「创建一个 Bot,叫日报员,每天 9 点汇总 Git 提交」',
3367
- h('br'),
3368
- '「创建一个 Bot,叫巡检员,长期盯着构建是否变红」',
3369
- ),
3370
- ),
3371
- )
3372
- : null,
2520
+ const openConsoleSafe = () => {
2521
+ if (!onOpenConsole()) setToast('请在左侧边栏点 dsh-bot 图标打开管理中心');
2522
+ setTimeout(() => setToast(''), 4000);
2523
+ };
3373
2524
 
3374
- // 列表
3375
- bots.map((b) => {
3376
- const isOpen = detailId === b.id;
3377
- const budgetMax = b.budgetDaily ?? 5;
3378
- return h(
3379
- 'div',
3380
- { key: b.id, style: { borderTop: `1px solid ${BORDER_L1}` } },
3381
- h(
3382
- 'div',
3383
- {
3384
- style: {
3385
- display: 'flex',
3386
- alignItems: 'center',
3387
- gap: 12,
3388
- padding: '10px 12px',
3389
- },
2525
+ // ============================================================
2526
+ const stat = dockStatOf(shown, !!runningBot, runningDry);
2527
+ const running = runningBot != null;
2528
+
2529
+ // 渲染:收起态与展开态共用同一套弹层,只有行内容不同。
2530
+ // 每个控件各司其职(不再"全部跳管理中心"):
2531
+ // Bot chip → Bot 切换菜单
2532
+ // 状态 chip → 管理中心(看最近运行)
2533
+ // 模型 pill → 模型快切菜单
2534
+ // 箭头 → 收起 / 展开
2535
+ // ============================================================
2536
+ const toastEl = toast ? portal(h('div', { className: NS + '-db-toast' }, toast)) : null;
2537
+
2538
+ const botMenuEl = menuOpen
2539
+ ? h('div', { className: NS + '-db-pop', style: { left: 0 } },
2540
+ h('div', { className: 'head' }, '全部 Bot(' + list.length + ')'),
2541
+ h('div', { className: 'list' },
2542
+ ...list.map((b) => {
2543
+ const st = b.lastRunStatus === 'success' ? 'g' : b.lastRunStatus === 'failed' ? 'r' : '';
2544
+ return h('button', {
2545
+ key: b.id,
2546
+ className: 'item' + (shown?.id === b.id ? ' active' : ''),
2547
+ onClick: () => pickBot(b),
3390
2548
  },
3391
- // 信息
3392
- h(
3393
- 'div',
3394
- { style: { flex: 1, minWidth: 0 } },
3395
- h(
3396
- 'div',
3397
- { style: { display: 'flex', alignItems: 'center', gap: 7 } },
3398
- h(
3399
- 'span',
3400
- { style: { fontSize: 13, fontWeight: 500, color: LABEL_1 } },
3401
- b.name,
3402
- ),
3403
- b.lastRunStatus
3404
- ? h(
3405
- 'span',
3406
- {
3407
- style: {
3408
- fontSize: 10,
3409
- color: statusColor(b.lastRunStatus),
3410
- display: 'inline-flex',
3411
- alignItems: 'center',
3412
- gap: 3,
3413
- },
3414
- },
3415
- h('span', {
3416
- style: {
3417
- width: 5,
3418
- height: 5,
3419
- borderRadius: 999,
3420
- background: statusColor(b.lastRunStatus),
3421
- },
3422
- }),
3423
- statusText(b.lastRunStatus),
3424
- )
3425
- : null,
3426
- ),
3427
- h(
3428
- 'div',
3429
- {
3430
- style: {
3431
- fontSize: 12,
3432
- color: LABEL_2,
3433
- marginTop: 3,
3434
- overflow: 'hidden',
3435
- textOverflow: 'ellipsis',
3436
- whiteSpace: 'nowrap',
3437
- },
3438
- },
3439
- b.role,
3440
- ),
3441
- // ⭐ 「他在守什么」——一行说清,这是 Dots 那一半的可见性
3442
- b.goalDescription
3443
- ? h(
3444
- 'div',
3445
- {
3446
- style: {
3447
- display: 'flex',
3448
- alignItems: 'center',
3449
- gap: 5,
3450
- fontSize: 11,
3451
- marginTop: 4,
3452
- overflow: 'hidden',
3453
- whiteSpace: 'nowrap',
3454
- },
3455
- },
3456
- h('span', { style: { color: LABEL_3, flexShrink: 0 } }, '他在守'),
3457
- h(
3458
- 'span',
3459
- {
3460
- style: {
3461
- color: LABEL_1,
3462
- overflow: 'hidden',
3463
- textOverflow: 'ellipsis',
3464
- },
3465
- },
3466
- b.goalDescription,
3467
- ),
3468
- h(
3469
- 'span',
3470
- {
3471
- style: {
3472
- color: goalStatusColor(b.goalStatus),
3473
- flexShrink: 0,
3474
- },
3475
- },
3476
- `· ${goalStatusText(b.goalStatus)}`,
3477
- ),
3478
- b.goalType === 'standing'
3479
- ? h(
3480
- 'span',
3481
- { style: { color: LABEL_3, flexShrink: 0 } },
3482
- '· 常驻',
3483
- )
3484
- : null,
3485
- )
3486
- : h(
3487
- 'div',
3488
- { style: { fontSize: 11, color: LABEL_3, marginTop: 4 } },
3489
- '还没有目标 — 点「设目标」让他知道该守什么',
3490
- ),
3491
- h(
3492
- 'div',
3493
- { style: { fontSize: 11, color: LABEL_3, marginTop: 4 } },
3494
- `${b.runCount} 次运行 · 上次 ${fmtAgo(b.lastRunAt)}` +
3495
- (b.memoryCount ? ` · 记得 ${b.memoryCount} 条` : ''),
3496
- ),
3497
- ),
3498
- // 动作
3499
- //
3500
- // 关于「演习」按钮的取舍:
3501
- // 用户反馈"不明所以,作用不大"。
3502
- // 原因是:它把"要不要先试"这个决策推给了用户,
3503
- // 而用户并不知道试一次能看出什么。
3504
- //
3505
- // 更好的做法不是删掉它,而是**让它只在有意义时出现**:
3506
- // · 从没跑过 → 建议先演习
3507
- // · 已跑成功过 → 收起,避免干扰
3508
- // 同时把文案从"演习"改成"先跑一遍看看",
3509
- // 让人一眼知道它做什么。
3510
- h(
3511
- 'div',
3512
- { style: { display: 'flex', gap: 6, flexShrink: 0 } },
3513
- // 仅在"还没成功跑过"时显示,降低干扰
3514
- !b.lastRunStatus || b.lastRunStatus === 'failed'
3515
- ? h(
3516
- Btn,
3517
- {
3518
- onClick: () => act('dry', b),
3519
- disabled: busy,
3520
- title: '先空跑一遍:会调用模型(有少量花费),但工具不会真实执行',
3521
- icon: h(IconDryRun, { size: 13 }),
3522
- },
3523
- '先看看',
3524
- )
3525
- : null,
3526
- h(
3527
- Btn,
3528
- {
3529
- kind: 'primary',
3530
- onClick: () => act('run', b),
3531
- disabled: busy,
3532
- title: '真实执行(执行前自动打快照)',
3533
- icon: h(IconRun, { size: 13 }),
3534
- },
3535
- '执行',
3536
- ),
3537
- h(
3538
- 'button',
3539
- {
3540
- className: `${NS}-row-btn`,
3541
- onClick: () => {
3542
- const next = editOpen === b.id ? null : b.id;
3543
- setEditOpen(next);
3544
- if (next) {
3545
- setEditName(b.name ?? '');
3546
- setEditRole(b.role ?? '');
3547
- setEditNote('');
3548
- if (!detail || detail.bot?.id !== b.id) void loadDetail(b.id);
3549
- }
3550
- },
3551
- title: editOpen === b.id ? '收起编辑' : '编辑名称 / 职责 / 附加说明 / 执行周期',
3552
- type: 'button',
3553
- },
3554
- '编辑',
3555
- ),
3556
- h(
3557
- 'button',
3558
- {
3559
- className: `${NS}-row-btn`,
3560
- onClick: () => setDetailId(isOpen ? null : b.id),
3561
- title: isOpen ? '收起详情' : '查看详情',
3562
- type: 'button',
3563
- },
3564
- '详情',
3565
- h(IconChevron, { size: 12, open: isOpen }),
2549
+ h('span', { className: 'nm' }, b.name),
2550
+ h('span', { className: 'meta' },
2551
+ h('span', null, fmtCny(b.todayCostCny)),
2552
+ h('span', { className: 'dot ' + st }),
3566
2553
  ),
3567
- ),
3568
- ),
2554
+ );
2555
+ }),
2556
+ list.length === 0 ? h('div', { className: 'desc' }, '还没有 Bot') : null,
2557
+ ),
2558
+ h('div', { className: 'foot' },
2559
+ h('button', { className: 'mi', onClick: openConsoleSafe }, '+ 新建 Bot'),
2560
+ h('button', { className: 'mi', onClick: openConsoleSafe }, '管理中心'),
2561
+ ),
2562
+ )
2563
+ : null;
3569
2564
 
3570
- // 行内编辑(v0.3.7:入口就在行上,不藏在「配置与危险操作」里)
3571
- editOpen === b.id
3572
- ? h(
3573
- 'div',
3574
- {
3575
- className: `${NS}-fade`,
3576
- style: {
3577
- padding: '10px 12px 12px',
3578
- borderTop: `1px solid ${BORDER_L1}`,
3579
- background: BG_L3,
3580
- display: 'flex',
3581
- flexDirection: 'column',
3582
- gap: 6,
3583
- },
3584
- },
3585
- h('div', { style: { fontSize: 10, color: LABEL_3 } }, '名称'),
3586
- h(Input, {
3587
- value: editName,
3588
- onChange: setEditName,
3589
- placeholder: 'Bot 名称',
3590
- autoFocus: true,
3591
- }),
3592
- h('div', { style: { fontSize: 10, color: LABEL_3 } }, '职责'),
3593
- h(Input, {
3594
- value: editRole,
3595
- onChange: setEditRole,
3596
- placeholder: '职责(一句话,决定它怎么干活)',
3597
- multiline: true,
3598
- }),
3599
- h('div', { style: { fontSize: 10, color: LABEL_3 } }, '附加说明'),
3600
- h(Input, {
3601
- value: editNote,
3602
- onChange: setEditNote,
3603
- placeholder: '附加说明(可选,会写进系统提示)',
3604
- multiline: true,
3605
- }),
3606
- h('div', { style: { fontSize: 10, color: LABEL_3 } }, '执行周期'),
3607
- h(
3608
- 'div',
3609
- { style: { display: 'flex', gap: 6, flexWrap: 'wrap' } },
3610
- ...[
3611
- ['hours', '每 N 小时'],
3612
- ['daily', '每天'],
3613
- ['weekly', '每周'],
3614
- ['none', '不自动跑'],
3615
- ].map(([mode, label]) =>
3616
- h(
3617
- 'button',
3618
- {
3619
- key: mode,
3620
- type: 'button',
3621
- onClick: () => setCadenceMode(mode),
3622
- style: {
3623
- fontSize: 11,
3624
- border: `1px solid ${cadenceMode === mode ? BRAND : BORDER_L1}`,
3625
- background: cadenceMode === mode ? BG_L3 : 'transparent',
3626
- color: cadenceMode === mode ? BRAND : LABEL_3,
3627
- borderRadius: R_SM,
3628
- padding: '3px 10px',
3629
- cursor: 'pointer',
3630
- },
3631
- },
3632
- label,
3633
- ),
3634
- ),
3635
- ),
3636
- cadenceMode === 'hours'
3637
- ? h(
3638
- 'div',
3639
- { style: { display: 'flex', alignItems: 'center', gap: 8 } },
3640
- h(
3641
- 'button',
3642
- {
3643
- type: 'button',
3644
- onClick: () => setCadenceHours((v) => Math.max(1, v - 1)),
3645
- style: { width: 26, height: 26, borderRadius: R_SM, border: `1px solid ${BORDER_L1}`, background: 'transparent', color: LABEL_2, cursor: 'pointer', fontSize: 14 },
3646
- },
3647
- '−',
3648
- ),
3649
- h(
3650
- 'div',
3651
- { style: { minWidth: 92, textAlign: 'center', fontSize: 12, color: LABEL_1 } },
3652
- `每 ${cadenceHours} 小时`,
3653
- ),
3654
- h(
3655
- 'button',
3656
- {
3657
- type: 'button',
3658
- onClick: () => setCadenceHours((v) => Math.min(24, v + 1)),
3659
- style: { width: 26, height: 26, borderRadius: R_SM, border: `1px solid ${BORDER_L1}`, background: 'transparent', color: LABEL_2, cursor: 'pointer', fontSize: 14 },
3660
- },
3661
- '+',
3662
- ),
3663
- h('div', { style: { fontSize: 10, color: LABEL_3 } }, '整点触发'),
3664
- )
3665
- : null,
3666
- cadenceMode === 'daily' || cadenceMode === 'weekly'
3667
- ? h(
3668
- 'div',
3669
- { style: { display: 'flex', alignItems: 'center', gap: 8 } },
3670
- h('div', { style: { fontSize: 10, color: LABEL_3 } }, '时间'),
3671
- h('input', {
3672
- type: 'time',
3673
- value: cadenceTime,
3674
- onChange: (e) => setCadenceTime(e.target.value || '09:00'),
3675
- style: {
3676
- width: 110,
3677
- boxSizing: 'border-box',
3678
- fontFamily: FONT,
3679
- fontSize: 12,
3680
- color: LABEL_1,
3681
- background: BG_L1,
3682
- border: `1px solid ${BORDER_L2}`,
3683
- borderRadius: R_SM,
3684
- padding: '4px 8px',
3685
- outline: 'none',
3686
- },
3687
- }),
3688
- )
3689
- : null,
3690
- cadenceMode === 'weekly'
3691
- ? h(
3692
- 'div',
3693
- { style: { fontSize: 10, color: LABEL_3 } },
3694
- '星期(可多选)',
3695
- h(
3696
- 'div',
3697
- { style: { display: 'flex', gap: 4, marginTop: 4, flexWrap: 'wrap' } },
3698
- ...['日', '一', '二', '三', '四', '五', '六'].map((label, idx) =>
3699
- h(
3700
- 'button',
3701
- {
3702
- key: idx,
3703
- type: 'button',
3704
- onClick: () =>
3705
- setCadenceDays((prev) =>
3706
- prev.includes(idx)
3707
- ? prev.filter((x) => x !== idx)
3708
- : [...prev, idx].sort((a, b) => a - b),
3709
- ),
3710
- style: {
3711
- width: 26,
3712
- height: 24,
3713
- borderRadius: R_SM,
3714
- border: `1px solid ${cadenceDays.includes(idx) ? BRAND : BORDER_L1}`,
3715
- background: cadenceDays.includes(idx) ? BG_L3 : 'transparent',
3716
- color: cadenceDays.includes(idx) ? BRAND : LABEL_3,
3717
- fontSize: 11,
3718
- cursor: 'pointer',
3719
- },
3720
- },
3721
- label,
3722
- ),
3723
- ),
3724
- ),
3725
- )
3726
- : null,
3727
- cadenceMode === 'custom'
3728
- ? h(
3729
- 'div',
3730
- { style: { fontSize: 10, color: WARN } },
3731
- `当前是自定义 cron(${cadenceCustom});选择上面的模式会覆盖它。`,
3732
- )
3733
- : null,
3734
- h(
3735
- 'div',
3736
- { style: { fontSize: 10, color: LABEL_3 } },
3737
- `将执行:${describeCadence(cadenceMode, cadenceHours, cadenceTime, cadenceDays, cadenceCustom)}`,
3738
- ),
3739
- h(
3740
- 'div',
3741
- { style: { display: 'flex', gap: 6, justifyContent: 'flex-end' } },
3742
- h(Btn, { onClick: () => setEditOpen(null) }, '取消'),
3743
- h(
3744
- Btn,
3745
- {
3746
- kind: 'primary',
3747
- disabled: busy || !editName.trim() || !editRole.trim(),
3748
- onClick: async () => {
3749
- try {
3750
- const r = await fetch('/_dsh-bot/bot/update', {
3751
- method: 'POST',
3752
- headers: { 'content-type': 'application/json' },
3753
- body: JSON.stringify({
3754
- botId: b.id,
3755
- name: editName.trim(),
3756
- role: editRole.trim(),
3757
- systemPromptExtra: editNote,
3758
- cadence: buildCadence(cadenceMode, cadenceHours, cadenceTime, cadenceDays, cadenceCustom),
3759
- }),
3760
- });
3761
- const j = await r.json();
3762
- if (!j?.ok) throw new Error(j?.message || j?.code || '保存失败');
3763
- setEditOpen(null);
3764
- await loadDetail(b.id);
3765
- await refresh();
3766
- } catch (err) {
3767
- setErr(String(err?.message ?? err));
3768
- }
3769
- },
3770
- },
3771
- '保存',
3772
- ),
3773
- ),
3774
- )
3775
- : null,
2565
+ const modelMenuEl = modelPop && shown
2566
+ ? h(ModelMenu, { shown, models, pickProvider, setPickProvider, setModel, openConsoleSafe })
2567
+ : null;
3776
2568
 
3777
- // 详情
3778
- //
3779
- // A 方案(三层折叠)+ D 方案(状态驱动)
3780
- //
3781
- // 第一层:状态摘要 —— 只显示"现在需要你知道的"
3782
- // 第二层:目标一行(正常时)
3783
- // 第三层:「更多」折叠 —— 记忆/例行/模型/预算/快照
3784
- //
3785
- // 结果:常态高度 ~3 行,不再挤成一坨。
3786
- isOpen
3787
- ? h(
3788
- 'div',
3789
- {
3790
- className: `${NS}-fade`,
3791
- style: {
3792
- padding: '10px 12px 12px',
3793
- borderTop: `1px solid ${BORDER_L1}`,
3794
- background: BG_L3,
3795
- },
3796
- },
2569
+ const runConfirmEl = runPop && shown && !collapsed
2570
+ ? h('div', { className: NS + '-db-pop right' },
2571
+ h('div', { className: 'head' }, '演习「' + shown.name + '」的当前目标?'),
2572
+ h('div', { className: 'desc' },
2573
+ '演习完整走一遍流程,', h('b', null, '不写任何文件、不花钱'), ';输出满意后可在运行详情里放行。真跑会实际执行。',
2574
+ ),
2575
+ h('div', { className: 'acts' },
2576
+ h('button', { className: NS + '-db-btn', disabled: busy, onClick: () => void doRun(false) }, '真跑一次'),
2577
+ h('button', { className: NS + '-db-btn primary', disabled: busy, onClick: () => void doRun(true) }, '演习一次'),
2578
+ ),
2579
+ )
2580
+ : null;
3797
2581
 
3798
- // 没展开详情数据时给个占位,避免闪空
3799
- !detail || detail.bot?.id !== b.id
3800
- ? h(
3801
- 'div',
3802
- {
3803
- style: {
3804
- fontSize: 11,
3805
- color: LABEL_3,
3806
- padding: '4px 0',
3807
- },
3808
- },
3809
- '正在读取…',
3810
- )
3811
- : h(
3812
- 'div',
3813
- null,
3814
- // ---------- 第一层:状态摘要 ----------
3815
- renderSituation(b, detail, act, busy),
3816
-
3817
- // ---------- 第二层:目标一行 ----------
3818
- detail.goal
3819
- ? h(
3820
- 'div',
3821
- {
3822
- style: {
3823
- display: 'flex',
3824
- alignItems: 'center',
3825
- gap: 6,
3826
- fontSize: 11,
3827
- color: LABEL_3,
3828
- marginBottom: 8,
3829
- minWidth: 0,
3830
- },
3831
- },
3832
- h(
3833
- 'span',
3834
- { style: { flexShrink: 0 } },
3835
- '目标',
3836
- ),
3837
- h(
3838
- 'span',
3839
- {
3840
- style: {
3841
- color: LABEL_1,
3842
- overflow: 'hidden',
3843
- textOverflow: 'ellipsis',
3844
- whiteSpace: 'nowrap',
3845
- },
3846
- },
3847
- detail.goal.description,
3848
- ),
3849
- h(
3850
- 'span',
3851
- {
3852
- style: {
3853
- color: goalStatusColor(detail.goal.status),
3854
- flexShrink: 0,
3855
- },
3856
- },
3857
- goalStatusText(detail.goal.status),
3858
- ),
3859
- detail.goal.cadence
3860
- ? h(
3861
- 'span',
3862
- { style: { flexShrink: 0 } },
3863
- `· ${detail.goal.cadence}`,
3864
- )
3865
- : null,
3866
- )
3867
- : null,
3868
-
3869
- // ---------- 第三层:最近运行(常驻,不再藏进「更多」) ----------
3870
- //
3871
- // 用户明确要求:运行记录不该藏在折叠里。
3872
- // 但也不能全量平铺(那就是"挤成一坨")。
3873
- // 折中:**只显示最近 2 条**,完整列表和管理进设置页。
3874
- detail.runs?.length
3875
- ? h(
3876
- 'div',
3877
- { style: { marginBottom: 6 } },
3878
- h(
3879
- 'div',
3880
- {
3881
- style: {
3882
- display: 'flex',
3883
- alignItems: 'baseline',
3884
- gap: 6,
3885
- marginBottom: 4,
3886
- },
3887
- },
3888
- h(
3889
- 'span',
3890
- {
3891
- style: {
3892
- fontSize: 11,
3893
- fontWeight: 600,
3894
- color: LABEL_2,
3895
- },
3896
- },
3897
- '最近运行',
3898
- ),
3899
- h(
3900
- 'span',
3901
- { style: { fontSize: 10, color: LABEL_3 } },
3902
- `共 ${detail.runs.length} 条 · 管理在设置里`,
3903
- ),
3904
- ),
3905
- ...detail.runs.slice(0, 2).map((r) =>
3906
- h(
3907
- 'div',
3908
- {
3909
- key: r.id,
3910
- style: {
3911
- display: 'flex',
3912
- alignItems: 'center',
3913
- gap: 6,
3914
- fontSize: 11,
3915
- lineHeight: '18px',
3916
- },
3917
- },
3918
- h('span', {
3919
- style: {
3920
- width: 5,
3921
- height: 5,
3922
- borderRadius: 999,
3923
- background: statusColor(r.status),
3924
- flexShrink: 0,
3925
- },
3926
- }),
3927
- h(
3928
- 'span',
3929
- { style: { color: LABEL_3, flexShrink: 0 } },
3930
- r.startedAt.slice(5, 16).replace('T', ' '),
3931
- ),
3932
- h(
3933
- 'span',
3934
- {
3935
- style: {
3936
- color: statusColor(r.status),
3937
- flexShrink: 0,
3938
- },
3939
- },
3940
- statusText(r.status),
3941
- ),
3942
- r.dryRun
3943
- ? h(
3944
- 'span',
3945
- { style: { color: LABEL_3 } },
3946
- '演习',
3947
- )
3948
- : null,
3949
- h(
3950
- 'span',
3951
- {
3952
- style: {
3953
- color: LABEL_3,
3954
- marginLeft: 'auto',
3955
- flexShrink: 0,
3956
- },
3957
- },
3958
- fmtCost(r.usage),
3959
- ),
3960
- ),
3961
- ),
3962
- )
3963
- : null,
3964
-
3965
- // ---------- 第四层 L2:他知道什么(默认折叠) ----------
3966
- h(
3967
- 'button',
3968
- {
3969
- className: `${NS}-row-btn`,
3970
- onClick: () =>
3971
- setMoreOpen((v) => (v === b.id ? null : b.id)),
3972
- type: 'button',
3973
- style: {
3974
- fontSize: 11,
3975
- color: LABEL_3,
3976
- marginBottom: 6,
3977
- },
3978
- },
3979
- moreOpen === b.id
3980
- ? '收起「他知道什么」'
3981
- : '他知道什么 ▾(记忆 / 例行流程)',
3982
- ),
2582
+ /** 花费(收起态展示;展开态腾出空间给模型与操作) */
2583
+ const costEl = shown
2584
+ ? h('span', { className: NS + '-db-cost' },
2585
+ h('span', { className: 'txt' },
2586
+ h('b', null, fmtCny(shown.todayCostCny)),
2587
+ running ? '' : h('span', { className: 'lim' }, ' / ' + fmtCny(shown.budget?.dailyCny)),
2588
+ ),
2589
+ )
2590
+ : null;
3983
2591
 
3984
- moreOpen === b.id
3985
- ? h(
3986
- 'div',
3987
- null,
3988
- detail.semantic?.facts?.length
3989
- ? renderMemory(detail.semantic)
3990
- : null,
3991
- detail.routines?.length
3992
- ? renderRoutines(detail.routines)
3993
- : null,
3994
- !(detail.semantic?.facts?.length) && !(detail.routines?.length)
3995
- ? h(
3996
- 'div',
3997
- {
3998
- style: {
3999
- fontSize: 10, color: LABEL_3, lineHeight: 1.8,
4000
- padding: '6px 8px', borderRadius: R_SM, background: BG_L3,
4001
- marginBottom: 6,
4002
- },
4003
- },
4004
- '还没有长期记忆。从下一次定时运行起,每轮报告的首行结论会自动蒸馏到这里(上限 50 条,去重)。',
4005
- )
4006
- : null,
4007
- )
4008
- : null,
4009
-
4010
- // ---------- 第五层 L3:配置与危险操作(默认折叠,红色隔离) ----------
4011
- h(
4012
- 'button',
4013
- {
4014
- className: `${NS}-row-btn`,
4015
- onClick: () =>
4016
- setDangerOpen((v) => (v === b.id ? null : b.id)),
4017
- type: 'button',
4018
- style: {
4019
- fontSize: 11,
4020
- color: ERR,
4021
- marginBottom: 6,
4022
- },
4023
- },
4024
- dangerOpen === b.id
4025
- ? '收起「配置与危险操作」'
4026
- : '配置与危险操作 ▾(模型 / 预算 / 快照 / 回滚 / 删除)',
4027
- ),
2592
+ /** 模型 pill(两态共用,点击开模型菜单) */
2593
+ const modelEl = shown
2594
+ ? h('button', {
2595
+ className: NS + '-db-model',
2596
+ onClick: () => { setModelPop(!modelPop); setMenuOpen(false); setRunPop(false); void ensureModels(); },
2597
+ title: '当前模型:' + (shown.model?.provider || '?') + ' / ' + (shown.model?.model || '?'),
2598
+ },
2599
+ h('span', { className: 'txt' }, shown.model?.provider || '?', h('span', { className: 'sep' }, ' / '), shown.model?.model || '?'),
2600
+ h(ChevDown, { size: 9 }),
2601
+ )
2602
+ : null;
4028
2603
 
4029
- dangerOpen === b.id
4030
- ? h(
4031
- 'div',
4032
- {
4033
- style: {
4034
- border: `1px solid ${ERR}`,
4035
- borderRadius: R_SM,
4036
- padding: '8px 10px',
4037
- marginBottom: 6,
4038
- },
4039
- },
4040
- // 模型
4041
- h(
4042
- 'div',
4043
- { style: { marginBottom: 10 } },
4044
- h(
4045
- SectionTitle,
4046
- { hint: '用哪个模型干活' },
4047
- '模型',
4048
- ),
4049
- h(
4050
- 'div',
4051
- {
4052
- style: {
4053
- display: 'flex',
4054
- alignItems: 'center',
4055
- gap: 8,
4056
- fontSize: 11,
4057
- },
4058
- },
4059
- h(
4060
- 'span',
4061
- {
4062
- style: {
4063
- color: LABEL_1,
4064
- fontFamily:
4065
- 'ui-monospace, SFMono-Regular, Menlo, monospace',
4066
- overflow: 'hidden',
4067
- textOverflow: 'ellipsis',
4068
- whiteSpace: 'nowrap',
4069
- },
4070
- },
4071
- `${detail.bot.model?.provider ?? '?'} / ${
4072
- detail.bot.model?.model ?? '?'
4073
- }`,
4074
- ),
4075
- h(
4076
- Btn,
4077
- {
4078
- onClick: () =>
4079
- act.onOpenModel?.({
4080
- botId: b.id,
4081
- botName: b.name,
4082
- provider: detail.bot.model?.provider,
4083
- model: detail.bot.model?.model,
4084
- }),
4085
- disabled: busy,
4086
- },
4087
- '改',
4088
- ),
4089
- ),
4090
- ),
4091
- // 预算
4092
- h(
4093
- 'div',
4094
- { style: { marginBottom: 10 } },
4095
- h(
4096
- 'div',
4097
- {
4098
- style: {
4099
- display: 'flex',
4100
- justifyContent: 'space-between',
4101
- fontSize: 11,
4102
- color: LABEL_2,
4103
- },
4104
- },
4105
- h('span', null, '今日花费'),
4106
- h(
4107
- 'span',
4108
- { style: { color: LABEL_1 } },
4109
- `${fmtCny(b.todayCostCny)} / ¥${budgetMax.toFixed(2)}`,
4110
- ),
4111
- ),
4112
- h(Meter, {
4113
- value: b.todayCostCny,
4114
- max: budgetMax,
4115
- }),
4116
- ),
4117
- // 可撤回 + 危险操作
4118
- h(
4119
- 'div',
4120
- {
4121
- style: {
4122
- display: 'flex',
4123
- gap: 6,
4124
- flexWrap: 'wrap',
4125
- },
4126
- },
4127
- h(
4128
- Btn,
4129
- {
4130
- onClick: () => act('snapshot', b),
4131
- disabled: busy,
4132
- icon: h(IconSnapshot, { size: 13 }),
4133
- },
4134
- '打快照',
4135
- ),
4136
- h(ConfirmBtn, {
4137
- label: '回滚',
4138
- confirmLabel: '确认回滚?',
4139
- kind: 'danger',
4140
- icon: h(IconRollback, { size: 13 }),
4141
- disabled: busy,
4142
- onConfirm: () => act('rollback', b),
4143
- }),
4144
- h(ConfirmBtn, {
4145
- label: '删除',
4146
- confirmLabel: '确认删除?不可恢复',
4147
- kind: 'danger',
4148
- disabled: busy,
4149
- onConfirm: () => act('botDelete', b),
4150
- }),
4151
- ),
4152
- )
4153
- : null,
4154
- ),
4155
- )
4156
- : null,
4157
- );
4158
- }),
4159
- ),
2604
+ /** Bot chip(两态共用,点击开 Bot 菜单) */
2605
+ const botChipEl = h('button', {
2606
+ className: NS + '-db-chip',
2607
+ onClick: () => { setMenuOpen(!menuOpen); setRunPop(false); setModelPop(false); },
2608
+ title: shown ? '当前 Bot:' + shown.name + '(点击切换)' : '未关联 Bot(点击选择)',
2609
+ },
2610
+ shown ? h(DockBotMark, null) : null,
2611
+ h('span', { className: 'nm' }, shown ? shown.name : '未关联'),
2612
+ h('span', { className: 'chev' }, h(ChevDown, null)),
2613
+ );
4160
2614
 
4161
- // 关闭滚动容器
4162
- ),
4163
- ));
4164
- } catch (e) {
4165
- report('render-error', String(e?.message ?? e));
4166
- return null;
2615
+ // ---------- 收起态:一行胶囊 ----------
2616
+ // 左:身份 + 状态点 / 右:今日花费 + 模型 + 展开
2617
+ if (collapsed) {
2618
+ return h('div', { className: NS + '-dockbar-wrap' },
2619
+ toastEl,
2620
+ h('div', {
2621
+ className: NS + '-dock ' + NS + '-dockbar ' + NS + '-dockbar-collapsed',
2622
+ ref: rootRef,
2623
+ },
2624
+ h('div', { className: NS + '-dockbar-row' },
2625
+ h('div', { className: NS + '-dockbar-main' },
2626
+ botChipEl,
2627
+ h('button', { className: stat.cls + ' ' + NS + '-db-stat-dotonly', title: '最近一轮:' + stat.label + ' · 点击查看运行记录', onClick: openConsoleSafe },
2628
+ h('span', { className: 'dot' }),
2629
+ ),
2630
+ ),
2631
+ h('div', { className: NS + '-dockbar-actions' },
2632
+ costEl,
2633
+ modelEl,
2634
+ h('button', { className: NS + '-db-chip ' + NS + '-db-iconbtn', onClick: toggleCollapse, title: '展开快捷条' },
2635
+ h(ChevUp, null),
2636
+ ),
2637
+ ),
2638
+ ),
2639
+ botMenuEl,
2640
+ modelMenuEl,
2641
+ ),
2642
+ );
4167
2643
  }
4168
- }
4169
-
4170
2644
 
4171
-
4172
- /** 侧边栏图标(只画字形,颜色跟随 currentColor) */
4173
- function BotSidebarIcon({ size = 16 }) {
4174
- return h(
4175
- 'svg',
4176
- { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', 'aria-hidden': 'true' },
4177
- h('rect', { x: 4, y: 6.5, width: 16, height: 12, rx: 3, stroke: 'currentColor', strokeWidth: 1.6 }),
4178
- h('circle', { cx: 9, cy: 12.5, r: 1.4, fill: 'currentColor' }),
4179
- h('circle', { cx: 15, cy: 12.5, r: 1.4, fill: 'currentColor' }),
4180
- h('path', { d: 'M12 6.5V4', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' }),
2645
+ // ---------- 展开态 ----------
2646
+ return h('div', { className: NS + '-dockbar-wrap' },
2647
+ toastEl,
2648
+ h('div', { className: NS + '-dock ' + NS + '-dockbar', ref: rootRef },
2649
+ h('div', { className: NS + '-dockbar-row' },
2650
+ h('div', { className: NS + '-dockbar-main' },
2651
+ botChipEl,
2652
+ h('button', { className: stat.cls, onClick: openConsoleSafe, title: '最近一轮:' + stat.label + ' · 点击查看运行记录' },
2653
+ h('span', { className: 'dot' }),
2654
+ h('span', { className: 'stat-text' }, stat.label),
2655
+ ),
2656
+ h('span', { className: NS + '-db-space' }),
2657
+ modelEl,
2658
+ ),
2659
+ h('div', { className: NS + '-dockbar-actions' },
2660
+ h('button', { className: NS + '-db-btn primary', disabled: busy || running || !shown, onClick: () => { setRunPop(!runPop); setMenuOpen(false); setModelPop(false); } },
2661
+ running ? (runningDry ? '◐ 演习中' : '◐ 真跑中') : '⚡ 执行',
2662
+ ),
2663
+ h('button', { className: NS + '-db-btn', onClick: openConsoleSafe, title: '打开管理中心' }, '管理中心 →'),
2664
+ h('button', { className: NS + '-db-chip ' + NS + '-db-iconbtn', onClick: toggleCollapse, title: '收起为一行胶囊' }, h(ChevUp, null)),
2665
+ ),
2666
+ ),
2667
+ botMenuEl,
2668
+ runConfirmEl,
2669
+ modelMenuEl,
2670
+ ),
4181
2671
  );
4182
2672
  }
4183
2673
 
4184
-
4185
2674
  // ============================================================
4186
2675
  // v0.3.8 控制台
4187
2676
  //
@@ -4913,6 +3402,130 @@ window.__ModuleLoader__.load({
4913
3402
  );
4914
3403
  }
4915
3404
 
3405
+ // ---------- 通知卡(v0.3.9 刀 2:单 Bot 覆盖,清空即恢复跟随全局) ----------
3406
+ function BotNotifyCard({ bot, busy, onChanged }) {
3407
+ const [state, setState] = React.useState(null); // { effective, global, overrides }
3408
+ const [err, setErr] = React.useState('');
3409
+ const [saving, setSaving] = React.useState(false);
3410
+ const botId = bot.id;
3411
+
3412
+ const load = React.useCallback(async () => {
3413
+ try {
3414
+ const j = await cget('/settings?botId=' + encodeURIComponent(botId));
3415
+ if (!j?.ok) throw new Error(j?.message || '读取失败');
3416
+ setState(j.value ?? null);
3417
+ setErr('');
3418
+ } catch (e) {
3419
+ setErr(String(e?.message ?? e));
3420
+ }
3421
+ }, [botId]);
3422
+
3423
+ React.useEffect(() => { void load(); }, [load]);
3424
+
3425
+ /** 保存覆盖项;clear 里的键会从单 Bot 文件删除 → 恢复跟随全局 */
3426
+ const save = async (patch, clear) => {
3427
+ setSaving(true);
3428
+ try {
3429
+ const j = await cpost('/settings', { botId, settings: patch ?? {}, clear: clear ?? [] });
3430
+ if (!j?.ok) throw new Error(j?.message || '保存失败');
3431
+ await load();
3432
+ onChanged?.();
3433
+ } catch (e) {
3434
+ setErr(String(e?.message ?? e));
3435
+ } finally {
3436
+ setSaving(false);
3437
+ }
3438
+ };
3439
+
3440
+ if (err && !state) {
3441
+ return h(CCard, null,
3442
+ h(CCardHead, { title: '通知' }),
3443
+ h('div', { className: NS + '-c-card-body' }, h('div', { className: NS + '-c-err' }, err)));
3444
+ }
3445
+ if (!state) {
3446
+ return h(CCard, null,
3447
+ h(CCardHead, { title: '通知' }),
3448
+ h('div', { className: NS + '-c-card-body' }, h('div', { className: NS + '-c-empty' }, h('p', null, '正在读取通知设置…'))));
3449
+ }
3450
+
3451
+ const eff = state.effective ?? {};
3452
+ const glob = state.global ?? {};
3453
+ const overrides = state.overrides ?? [];
3454
+ const has = (k) => overrides.indexOf(k) >= 0;
3455
+ const disabled = busy || saving;
3456
+
3457
+ /** 一行:左侧标签 + 「跟随全局 / 已覆盖」,右侧开关或时段 + 恢复按钮 */
3458
+ const row = (key, label, hint, globalText, control) =>
3459
+ h(CRow, {
3460
+ label,
3461
+ hint: has(key) ? '已覆盖全局 · ' + hint : '跟随全局:' + globalText,
3462
+ }, h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
3463
+ control,
3464
+ has(key)
3465
+ ? h(CLink, { onClick: () => void save({}, [key]) }, '恢复跟随')
3466
+ : null,
3467
+ ));
3468
+
3469
+ const quiet = eff.quietHours;
3470
+
3471
+ return h(CCard, null,
3472
+ h(CCardHead, {
3473
+ title: '通知',
3474
+ right: h('span', { className: NS + '-c-card-count' }, '仅对这个 Bot 生效'),
3475
+ }),
3476
+ h('div', { className: NS + '-c-card-body' },
3477
+ row('notifySystem', '运行完成后系统通知', '关掉后这个 Bot 不再弹桌面通知',
3478
+ glob.notifySystem === false ? '关' : '开',
3479
+ h(CSwitch, {
3480
+ value: eff.notifySystem !== false,
3481
+ disabled,
3482
+ onChange: (v) => void save({ notifySystem: v }, []),
3483
+ })),
3484
+
3485
+ row('notifyOnlyOnDecision', '仅异常时打扰', '自动轮次只在失败/部分成功时提醒',
3486
+ glob.notifyOnlyOnDecision !== false ? '开' : '关',
3487
+ h(CSwitch, {
3488
+ value: eff.notifyOnlyOnDecision !== false,
3489
+ disabled,
3490
+ onChange: (v) => void save({ notifyOnlyOnDecision: v }, []),
3491
+ })),
3492
+
3493
+ h(CRow, {
3494
+ label: '免打扰时段',
3495
+ hint: has('quietHours')
3496
+ ? '已覆盖全局 · ' + (quiet ? quiet.start + ' – ' + quiet.end : '不启用')
3497
+ : '跟随全局:' + (glob.quietHours ? glob.quietHours.start + ' – ' + glob.quietHours.end : '不启用'),
3498
+ }, h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
3499
+ quiet
3500
+ ? h('div', { style: { display: 'flex', gap: 6 } },
3501
+ h('input', {
3502
+ type: 'time', className: NS + '-c-input', style: { width: 136 },
3503
+ value: quiet.start, disabled,
3504
+ onChange: (e) => void save({ quietHours: { start: e.target.value || '22:00', end: quiet.end } }, []),
3505
+ }),
3506
+ h('input', {
3507
+ type: 'time', className: NS + '-c-input', style: { width: 136 },
3508
+ value: quiet.end, disabled,
3509
+ onChange: (e) => void save({ quietHours: { start: quiet.start, end: e.target.value || '08:00' } }, []),
3510
+ }),
3511
+ )
3512
+ : null,
3513
+ h(CSwitch, {
3514
+ value: !!quiet,
3515
+ disabled,
3516
+ onChange: (v) => void save({ quietHours: v ? { start: '22:00', end: '08:00' } : null }, []),
3517
+ }),
3518
+ has('quietHours') ? h(CLink, { onClick: () => void save({}, ['quietHours']) }, '恢复跟随') : null,
3519
+ )),
3520
+
3521
+ err ? h('div', { className: NS + '-c-err', style: { marginTop: 8 } }, err) : null,
3522
+ h('div', { className: NS + '-c-hint-block' },
3523
+ '只有通知相关项可按 Bot 覆盖;其余设置(预算 / 模型 / 快照)始终针对单个 Bot。'),
3524
+ ),
3525
+ );
3526
+ }
3527
+
3528
+
4916
3529
  // ---------- 配置卡(可编辑) ----------
4917
3530
  function BotConfigCard({ bot, detail, busy, onSave }) {
4918
3531
  const [editing, setEditing] = React.useState(false);
@@ -4975,16 +3588,15 @@ window.__ModuleLoader__.load({
4975
3588
  return;
4976
3589
  }
4977
3590
  const cadence = buildCadence(mode, hours, time, days, custom);
4978
- const res = await onSave(
4979
- {
4980
- name: name.trim(),
4981
- role: role.trim(),
4982
- systemPromptExtra: note,
4983
- cadence,
4984
- budget: { dailyCny: d, monthlyCny: m, onExceed },
4985
- },
4986
- { provider, model: modelName },
4987
- );
3591
+ const res = await onSave({
3592
+ name: name.trim(),
3593
+ role: role.trim(),
3594
+ systemPromptExtra: note,
3595
+ cadence,
3596
+ budget: { dailyCny: d, monthlyCny: m, onExceed },
3597
+ // v0.3.9 刀 3:模型并入同一 POST,避免「名字改了模型没改」的半失败
3598
+ model: { provider, model: modelName },
3599
+ });
4988
3600
  if (res?.error) {
4989
3601
  setErr(res.error);
4990
3602
  return;
@@ -5489,6 +4101,7 @@ window.__ModuleLoader__.load({
5489
4101
  h(BotMemoryCard, { semantic: detail?.semantic }),
5490
4102
  h(BotRoutinesCard, { bot, routines: detail?.routines ?? [], busy, onChanged }),
5491
4103
  h(BotConfigCard, { bot: full, detail, busy, onSave: onSaveConfig }),
4104
+ h(BotNotifyCard, { bot: full, busy, onChanged }),
5492
4105
  h(BotSnapshotsCard, { bot: full, detail, busy, act }),
5493
4106
  );
5494
4107
  }
@@ -5496,6 +4109,7 @@ window.__ModuleLoader__.load({
5496
4109
  // ---------- 运行记录 tab ----------
5497
4110
  function ConsoleRuns({ bots, busy, onOpenRun }) {
5498
4111
  const [runs, setRuns] = React.useState(null);
4112
+ const [health, setHealth] = React.useState(null);
5499
4113
  const [filter, setFilter] = React.useState('all');
5500
4114
  const [page, setPage] = React.useState(0);
5501
4115
  const [err, setErr] = React.useState('');
@@ -5503,15 +4117,13 @@ window.__ModuleLoader__.load({
5503
4117
 
5504
4118
  const load = React.useCallback(async () => {
5505
4119
  try {
5506
- const all = [];
5507
- for (const b of bots) {
5508
- const j = await cget('/runs/list?botId=' + encodeURIComponent(b.id) + '&limit=20');
5509
- if (j?.ok) {
5510
- for (const r of j.value?.runs ?? []) all.push({ ...r, botName: b.name, botId: b.id });
5511
- }
5512
- }
5513
- all.sort((a, b) => Date.parse(b.startedAt) - Date.parse(a.startedAt));
5514
- setRuns(all);
4120
+ // v0.3.9 刀 3:一次聚合请求取代「每 Bot 一个 /runs/list」的 N+1
4121
+ const j = await cget('/runs/aggregate?limit=20');
4122
+ if (!j?.ok) throw new Error(j?.message || '读取失败');
4123
+ const list = (j.value?.runs ?? []).slice();
4124
+ list.sort((a, b) => Date.parse(b.startedAt) - Date.parse(a.startedAt));
4125
+ setRuns(list);
4126
+ setHealth(j.value?.health ?? null);
5515
4127
  setErr('');
5516
4128
  } catch (e) {
5517
4129
  setErr(String(e?.message ?? e));
@@ -5536,6 +4148,10 @@ window.__ModuleLoader__.load({
5536
4148
  right: h(
5537
4149
  'div',
5538
4150
  { style: { display: 'flex', gap: 8, alignItems: 'center' } },
4151
+ health
4152
+ ? h('span', { className: NS + '-c-card-count num', title: '近 N 轮成功率' },
4153
+ '成功率 ' + Math.round((health.successRate ?? 0) * 100) + '% · ' + (health.sample ?? 0) + ' 轮')
4154
+ : null,
5539
4155
  h(
5540
4156
  'select',
5541
4157
  {
@@ -5963,26 +4579,14 @@ window.__ModuleLoader__.load({
5963
4579
  );
5964
4580
 
5965
4581
  const saveConfig = React.useCallback(
5966
- async (payload, model) => {
4582
+ async (payload) => {
5967
4583
  if (!selected?.id) return { error: '没有选中的 Bot' };
5968
4584
  setBusy(true);
5969
4585
  setErr('');
5970
4586
  try {
4587
+ // v0.3.9 刀 3:资料 / 模型 / 预算 / 节奏 一次提交(服务端按段校验)
5971
4588
  const j = await cpost('/bot/update', { botId: selected.id, ...payload });
5972
4589
  if (!j?.ok) return { error: j?.message || '保存失败' };
5973
- const changed =
5974
- model?.provider &&
5975
- model?.model &&
5976
- (model.provider !== selected.model?.provider ||
5977
- model.model !== selected.model?.model);
5978
- if (changed) {
5979
- const m = await cpost('/bot/model', {
5980
- botId: selected.id,
5981
- provider: model.provider,
5982
- model: model.model,
5983
- });
5984
- if (!m?.ok) return { error: m?.message || '模型保存失败' };
5985
- }
5986
4590
  setNotice('已保存');
5987
4591
  await refresh();
5988
4592
  await loadDetail(selected.id);
@@ -6329,10 +4933,11 @@ window.__ModuleLoader__.load({
6329
4933
  }
6330
4934
  }
6331
4935
 
4936
+ // v0.3.9 刀1:快捷条取代旧完整面板;「管理中心」走 ctx.layout.selectPanel
6332
4937
  ctx.slots.inject('conversation.input.dock', () =>
6333
4938
  ctx.slots.register(
6334
4939
  { name: 'conversation.input.dock', id: 'dsh-bot', order: 20 },
6335
- BotDock,
4940
+ () => h(DockBar, { ctx, onOpenConsole: () => openConsole(ctx) }),
6336
4941
  ),
6337
4942
  );
6338
4943