agent-loft 0.2.133 → 0.2.135

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.
Files changed (50) hide show
  1. package/README.md +31 -31
  2. package/package.json +1 -1
  3. package/src/agents/dsh/errors.ts +2 -2
  4. package/src/agents/pi/constants.ts +1 -1
  5. package/src/agents/pi/errors.ts +2 -2
  6. package/src/agents/workbuddy/errors.ts +2 -2
  7. package/src/agents/workbuddy/sdk.ts +1 -1
  8. package/src/channels/feishu/bot.ts +3 -3
  9. package/src/channels/feishu/cards.ts +2 -2
  10. package/src/channels/web/api.ts +3 -1
  11. package/src/channels/web/desktop.ts +1 -1
  12. package/src/channels/web/terminal.ts +1 -1
  13. package/src/channels/web/workspace-api.ts +2 -2
  14. package/src/channels/weixin/bot.ts +1 -1
  15. package/src/core/command-catalog.ts +1 -1
  16. package/src/core/commands.ts +1 -1
  17. package/src/core/feishu-links.ts +1 -1
  18. package/src/core/hub.ts +3 -3
  19. package/src/core/memory-curator.ts +1 -1
  20. package/src/core/ui-prefs.ts +10 -4
  21. package/src/mcp/memory-server.ts +1 -1
  22. package/web/css/mobile.css +19 -31
  23. package/web/css/settings.css +66 -37
  24. package/web/lib/overlay.js +15 -2
  25. package/web/lib/push.js +1 -1
  26. package/web/lib/shell.js +1 -1
  27. package/web/settings/agent-defaults.js +3 -16
  28. package/web/settings/agents.js +118 -95
  29. package/web/settings/commands.js +32 -29
  30. package/web/settings/experts.js +14 -12
  31. package/web/settings/feishu.js +6 -6
  32. package/web/settings/general.js +22 -17
  33. package/web/settings/index.js +193 -112
  34. package/web/settings/memory-sync.js +1 -1
  35. package/web/settings/memory.js +63 -73
  36. package/web/settings/notify.js +2 -2
  37. package/web/settings/security.js +14 -6
  38. package/web/settings/servers.js +6 -5
  39. package/web/settings/skills.js +9 -4
  40. package/web/settings/tabs.js +67 -51
  41. package/web/settings/usage.js +3 -3
  42. package/web/settings/users.js +25 -8
  43. package/web/settings/weixin.js +1 -1
  44. package/web/state.js +2 -2
  45. package/web/views/layout.js +2 -2
  46. package/web/views/memo-dialogs.js +1 -1
  47. package/web/views/sidebar-gestures.js +1 -1
  48. package/web/views/sidebar-nav.js +2 -2
  49. package/web/views/tasks.js +1 -1
  50. package/web/views/topbar.js +1 -1
@@ -56,16 +56,22 @@ export function appendDirOrder(userId: string, dirs: unknown): string[] {
56
56
  return dirOrder;
57
57
  }
58
58
 
59
- /** 新菜单接在最后;未配置过的菜单沿用默认显示方式(设置默认收进「更多」)。 */
59
+ /** 新菜单接在最后;未配置过的菜单沿用默认显示方式。 */
60
60
  function cleanSidebarNav(value: unknown): SidebarNavItem[] {
61
61
  const items: SidebarNavItem[] = [];
62
62
  const seen = new Set<string>();
63
- for (const item of Array.isArray(value) ? value : []) {
63
+ const saved = Array.isArray(value) ? value : [];
64
+ const oldHub = saved.find(it => it?.id === "assistants");
65
+ const oldSettings = saved.find(it => it?.id === "settings");
66
+ const useHub = oldHub && (!oldSettings || (oldSettings.visible === false && oldHub.visible !== false));
67
+ for (const entry of saved) {
68
+ if (useHub && entry?.id === "settings") continue;
69
+ const item = useHub && entry === oldHub ? { ...entry, id: "settings" } : entry;
64
70
  if (!item || typeof item !== "object" || !NAV_IDS.includes(item.id) || seen.has(item.id)) continue;
65
71
  seen.add(item.id);
66
- items.push({ id: item.id, visible: typeof item.visible === "boolean" ? item.visible : item.id !== "settings" });
72
+ items.push({ id: item.id, visible: item.visible !== false });
67
73
  }
68
- for (const id of NAV_IDS) if (!seen.has(id)) items.push({ id, visible: id !== "settings" });
74
+ for (const id of NAV_IDS) if (!seen.has(id)) items.push({ id, visible: true });
69
75
  return items;
70
76
  }
71
77
 
@@ -275,7 +275,7 @@ function guard(id: string, args: Record<string, unknown>): string | undefined {
275
275
  const all = [...readMemory(userId).items, ...listMemoryItems(userId, "archive")];
276
276
  const item = all.find((i) => i.id === id);
277
277
  if (item && isProtected(item) && args.user_requested !== true) {
278
- return `这条是用户自己加的或者明确要求记的,受保护(${item.text})。只有用户在当前对话里明确要求时才能改,那样要带 user_requested: true;否则告诉用户可以到设置 → 记忆里改。`;
278
+ return `这条是用户自己加的或者明确要求记的,受保护(${item.text})。只有用户在当前对话里明确要求时才能改,那样要带 user_requested: true;否则告诉用户可以到设置 → 个人 → 记忆里改。`;
279
279
  }
280
280
  return undefined;
281
281
  }
@@ -185,37 +185,25 @@
185
185
  padding-bottom: env(safe-area-inset-bottom);
186
186
  }
187
187
 
188
- .settings {
189
- flex-direction: column;
190
- }
191
-
192
- .settings-nav {
193
- width: auto;
194
- flex-direction: row;
195
- overflow-x: auto;
196
- border-right: none;
197
- border-bottom: 1px solid var(--border);
198
- }
199
-
200
- .settings-nav button {
201
- white-space: nowrap;
202
- flex-shrink: 0;
203
- }
204
-
205
- /* 横排时分组标题换成一道竖线 */
206
- .settings-group {
207
- flex-shrink: 0;
208
- width: 1px;
209
- margin: 6px 4px;
210
- padding: 0;
211
- font-size: 0;
212
- background: var(--border);
213
- }
214
-
215
- .settings-group:first-child {
216
- display: none;
217
- }
218
-
188
+ .settings-editor .modal { width: 100%; height: 100%; max-height: 100%; border-radius: 0; padding-top: env(safe-area-inset-top); }
189
+ .settings-editor .modal-body { min-height: 0; overflow-y: auto; }
190
+ .settings { flex-direction: column; }
191
+ .settings-header { padding-block: env(safe-area-inset-top) 0; border: 0; }
192
+ .settings-header .icon-btn { display: inline-flex; min-height: 44px; min-width: 44px; }
193
+ .settings-primary, .settings-secondary { display: flex; flex: none; align-items: stretch; }
194
+ .settings-primary { padding-inline: 12px; border-bottom: 1px solid var(--border); }
195
+ .settings-primary button { flex: 1; min-height: 44px; color: var(--fg-soft); }
196
+ .settings-primary [aria-pressed="true"] { color: var(--fg); font-weight: 700; position: relative; }
197
+ .settings-primary [aria-pressed="true"]::after { content: ""; position: absolute; bottom: 0; inset-inline: 30%; height: 2px; background: currentColor; }
198
+ .settings-secondary { align-self: flex-start; margin: 8px 12px 0; max-width: calc(100% - 24px); overflow-x: auto; overscroll-behavior-x: contain; background: var(--bg-hover); border-radius: 12px; padding: 3px; gap: 2px; }
199
+ .settings-secondary[hidden] { display: none; }
200
+ .settings-secondary button { flex: none; min-height: 44px; min-width: 44px; padding-inline: 12px; border-radius: 9px; font-size: 14px; }
201
+ .settings-secondary [aria-current="page"] { background: var(--fg); color: var(--bg); font-weight: 650; }
202
+ .settings-nav { display: none; flex: 1; border: 0; padding: 12px 16px; }
203
+ .settings-view.searching .settings-nav { display: block; }
204
+ .settings-view.searching :is(.settings-body,.settings-primary,.settings-secondary) { display: none; }
205
+ .settings-nav-link { min-height: 44px; padding-inline: 12px; }
206
+ .settings-search input[type="search"] { min-height: 44px; font-size: 16px; }
219
207
  .settings-body {
220
208
  padding: 12px;
221
209
  }
@@ -68,48 +68,68 @@ body:has(.settings) > :is(.overlay, .menu) {
68
68
  }
69
69
 
70
70
  .settings-nav {
71
- width: 160px;
72
- border-right: 1px solid var(--border);
73
- padding: 8px;
74
- display: flex;
75
- flex-direction: column;
76
- gap: 2px;
77
- flex-shrink: 0;
71
+ flex: 0 0 clamp(178px, 19%, 246px);
72
+ min-width: 0;
73
+ border-inline-end: 1px solid var(--border);
74
+ padding: 14px 10px;
78
75
  overflow-y: auto;
76
+ overscroll-behavior: contain;
79
77
  }
80
78
 
81
- /* 导航里的分组标题:我的 / Agent / 连接 / 管理 */
82
- .settings-group {
83
- padding: 12px 10px 4px;
84
- font-size: 12px;
85
- color: var(--fg-faint);
86
- }
87
-
88
- .settings-group:first-child {
89
- padding-top: 4px;
90
- }
91
-
92
- .settings-nav button {
93
- text-align: left;
94
- padding: 7px 10px;
95
- border-radius: 8px;
96
- font-size: 14px;
79
+ .settings-search {
80
+ display: flex;
81
+ align-items: center;
82
+ gap: 8px;
83
+ border: 1px solid var(--border);
84
+ border-radius: 9px;
85
+ padding-inline: 10px;
86
+ color: var(--fg-soft);
97
87
  }
98
88
 
99
- .settings-nav button:hover {
100
- background: var(--bg-hover);
89
+ .settings-search input[type="search"] {
90
+ flex: 1;
91
+ width: 0;
92
+ min-width: 0;
93
+ border: 0;
94
+ background: transparent;
95
+ color: var(--fg);
96
+ padding: 9px 0;
101
97
  }
102
98
 
103
- .settings-nav button.on {
104
- background: var(--bg-hover);
99
+ .settings-search:focus-within { outline: 2px solid var(--fg-soft); }
100
+ .settings-search input:focus-visible { outline: 0; }
101
+ .settings-links { display: grid; gap: 2px; margin-top: 10px; }
102
+ .settings-group {
103
+ margin: 12px 9px 4px;
104
+ font-size: 12px;
105
105
  font-weight: 600;
106
+ color: var(--fg-soft);
106
107
  }
107
-
108
- .settings-body {
109
- flex: 1;
108
+ .settings-nav-link {
109
+ display: flex;
110
+ align-items: center;
111
+ gap: 10px;
110
112
  min-width: 0;
111
- overflow-y: auto;
112
- padding: 16px;
113
+ text-align: start;
114
+ padding: 9px;
115
+ border-radius: 7px;
116
+ font-size: 14px;
117
+ }
118
+ .settings-nav-link small { display: block; color: var(--fg-soft); font-weight: normal; }
119
+ .settings-nav-link:hover, .settings-nav-link[aria-current="page"] { background: var(--bg-hover); }
120
+ .settings-nav-link[aria-current="page"] { font-weight: 650; box-shadow: inset 2px 0 var(--fg); }
121
+ .settings-nav-link svg, .settings-search svg { display: block; width: 17px; height: 17px; }
122
+ .settings-body { flex: 1; min-width: 0; overflow-y: auto; padding: 20px clamp(16px, 3vw, 40px); }
123
+ .settings-page .muted, .settings-page .field > small { color: var(--fg-soft); }
124
+ .engine-model-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 12px; }
125
+ .engine-advanced summary { cursor: pointer; font-weight: 600; }
126
+ .engine-advanced > .field { margin-top: 12px; }
127
+ .settings-page-title { max-width: 1100px; margin: 0 auto 16px; font-size: 21px; line-height: 1.4; }
128
+ .settings-header .grow { flex: 1; }
129
+ .settings-sr { position: absolute; inline-size: 1px; block-size: 1px; clip-path: inset(50%); overflow: hidden; }
130
+ .settings-header button:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
131
+ @media (forced-colors: active) {
132
+ .settings-nav-link[aria-current="page"] { outline: 2px solid Highlight; }
113
133
  }
114
134
 
115
135
  /* 一页的内容,和一组一起保存的几节(Agent 页的 Claude Code + Codex) */
@@ -749,12 +769,8 @@ body:has(.settings) > :is(.overlay, .menu) {
749
769
  gap: 8px;
750
770
  margin-top: 8px;
751
771
  }
752
- /* 一条记忆的按钮多,窄屏上文字占一整行,按钮换到下面 */
753
- .memory-item {
754
- flex-wrap: wrap;
755
- }
756
772
  .memory-item > .grow {
757
- flex: 1 1 280px;
773
+ flex: 1;
758
774
  min-width: 0;
759
775
  overflow-wrap: anywhere;
760
776
  }
@@ -763,3 +779,16 @@ a.memory-link {
763
779
  color: inherit;
764
780
  text-decoration: none;
765
781
  }
782
+
783
+ .settings-primary, .settings-secondary, .settings-find { display: none; }
784
+ .memory-text { text-align: start; white-space: pre-wrap; overflow-wrap: anywhere; min-height: 44px; width: 100%; }
785
+ .memory-item .icon-btn { min-width: 44px; min-height: 44px; }
786
+
787
+ .settings-record > summary, .srv-edit > summary {
788
+ min-height: 44px;
789
+ padding: 12px 8px;
790
+ cursor: pointer;
791
+ font-weight: 600;
792
+ overflow-wrap: anywhere;
793
+ }
794
+ .settings-record .status-tag { margin-inline-start: 8px; }
@@ -156,10 +156,13 @@ export function closeMenu() {
156
156
  }
157
157
 
158
158
  /** 弹窗只通过按钮关闭,点击遮罩不关闭。beforeClose:点 × 前先问它,false 就不关。返回的 close 直接关 */
159
- export function modal({ title, body, foot, wide, tall, className = "", beforeClose }) {
159
+ export function modal({ title, body, foot, wide, tall, className = "", beforeClose, editor = false }) {
160
+ let dirty = false;
160
161
  const close = () => overlay.remove();
161
162
  const tryClose = async () => {
162
- if (!beforeClose || (await beforeClose()) !== false) close();
163
+ if (beforeClose && (await beforeClose()) === false) return;
164
+ if (!beforeClose && dirty && !(await confirmDialog({ title: "有修改还没保存", message: "离开后将丢弃当前表单的修改。", confirmText: "不保存", danger: true }))) return;
165
+ close();
163
166
  };
164
167
  const overlay = h(
165
168
  "div",
@@ -172,6 +175,16 @@ export function modal({ title, body, foot, wide, tall, className = "", beforeClo
172
175
  foot ?? null,
173
176
  ),
174
177
  );
178
+ if (ui.settings) overlay.addEventListener("settings-back", tryClose);
179
+ if (ui.settings && editor) {
180
+ overlay.classList.add("settings-editor");
181
+ if (!beforeClose) {
182
+ for (const type of ["input", "change"]) body.addEventListener(type, () => {
183
+ dirty = true;
184
+ overlay.dataset.edited = "";
185
+ });
186
+ }
187
+ }
175
188
  document.body.append(overlay);
176
189
  return close;
177
190
  }
package/web/lib/push.js CHANGED
@@ -7,7 +7,7 @@ export function pushSupport() {
7
7
  const ios = /iPhone|iPad|iPod/.test(navigator.userAgent);
8
8
  const standalone = window.matchMedia("(display-mode: standalone)").matches || navigator.standalone === true;
9
9
  if (desktop) return { ok: false, why: "桌面端会直接弹出 macOS 系统通知,不需要在这里开启。" };
10
- if (framed) return { ok: false, framed: true, why: "这台是在别的服务器的页面里打开的:通知跟着外层那台走,在那边的 设置 → 通知 里开启,这台的提醒也会推过去。" };
10
+ if (framed) return { ok: false, framed: true, why: "这台是在别的服务器的页面里打开的:通知跟着外层那台走,在那边的 设置 → 个人 → 通知 里开启,这台的提醒也会推过去。" };
11
11
  if (!window.isSecureContext) return { ok: false, why: "通知需要 HTTPS 访问(localhost 除外)。请通过 HTTPS 的反向代理地址打开。" };
12
12
  if (ios && !standalone) {
13
13
  return { ok: false, why: "iPhone / iPad 上要先在 Safari 里点「分享 → 添加到主屏幕」,再从桌面图标打开,才能开启通知(需 iOS 16.4+)。" };
package/web/lib/shell.js CHANGED
@@ -669,7 +669,7 @@ export async function handleAllowEmbed(confirmDialog, toast) {
669
669
  if (!embedders.includes(origin)) {
670
670
  const ok = await confirmDialog({
671
671
  title: "允许在别的服务器上切换到这台?",
672
- message: `${origin} 的页面左上角会多出这台,切过来时这台的页面嵌在那边显示(照样要登录这台的账号,聊天内容不经过那台)。以后不想要了,在 设置 → 服务器 里移除。`,
672
+ message: `${origin} 的页面左上角会多出这台,切过来时这台的页面嵌在那边显示(照样要登录这台的账号,聊天内容不经过那台)。以后不想要了,在 设置 → 连接 → 服务器切换 里移除。`,
673
673
  confirmText: "允许",
674
674
  });
675
675
  if (!ok) return;
@@ -5,8 +5,7 @@ import { modal, confirmDialog } from "../lib/overlay.js";
5
5
  import { isAdmin, S } from "../state.js";
6
6
  import { renderContext } from "../views/topbar.js";
7
7
  import { DEFAULT_LEVELS, engineSupports, PERMISSIONS } from "../lib/permission.js";
8
- import { field, hasDirty, markDirty, saveButton, saveConfig } from "./common.js";
9
- import { modelPicker } from "./commands.js";
8
+ import { field, hasDirty, markDirty, saveButton } from "./common.js";
10
9
 
11
10
  // ---------- 内置 Agent 的默认设置(设置 → 专家 → 内置卡片上的「设置」) ----------
12
11
  // 默认模型 / 思考程度:整台服务器的(config),只有管理员能改;
@@ -14,7 +13,6 @@ import { modelPicker } from "./commands.js";
14
13
 
15
14
  /** 设置里的默认权限「跟随」时实际是什么 */
16
15
  const FOLLOW_LABEL = { claude: "跟随 Claude Code(逐次询问)", codex: "跟随沙箱设置", workbuddy: "跟随 WorkBuddy(逐次询问)", dsh: "跟随 dsh(工作区可写,越界才问)", pi: "跟随 pi(逐次询问)" };
17
- const DEFAULT_MODEL_LABEL = { claude: "跟随 Claude Code 默认", codex: "跟随 config.toml", workbuddy: "跟随 WorkBuddy 默认", dsh: "跟随 dsh 默认", pi: "pi 自动挑一个能用的" };
18
16
 
19
17
  /** 技能 / MCP:「跟随」或者「指定加载」+ 勾选 */
20
18
  function loadPicker(label, items, selected, inheritLabel) {
@@ -50,6 +48,7 @@ export function openAgentDefaults(engine, label) {
50
48
  const foot = h("div", { class: "modal-foot" });
51
49
  // 改了没保存就关:问一句(和设置页切标签一样)
52
50
  const close = modal({
51
+ editor: true,
53
52
  title: `${label} 默认设置`,
54
53
  body: form,
55
54
  foot,
@@ -68,9 +67,8 @@ export function openAgentDefaults(engine, label) {
68
67
 
69
68
  const load = async () => {
70
69
  let data;
71
- let cfg = null;
72
70
  try {
73
- [data, cfg] = await Promise.all([api("/api/agents/defaults"), isAdmin() ? api("/api/config") : null]);
71
+ data = await api("/api/agents/defaults");
74
72
  } catch (err) {
75
73
  fill(form, h("div", { class: "error-text" }, err.message), h("button", { class: "btn small", onclick: load }, "重试"));
76
74
  return;
@@ -80,8 +78,6 @@ export function openAgentDefaults(engine, label) {
80
78
  fill(form, h("p", { class: "muted" }, `没有 ${label} 的使用权限,请联系管理员。`));
81
79
  return;
82
80
  }
83
- const server = cfg?.agents?.[engine];
84
- const pick = server ? modelPicker(engine, server.defaultModel ?? "", server.defaultEffort ?? "", DEFAULT_MODEL_LABEL[engine] ?? "跟随默认") : null;
85
81
 
86
82
  const skills = loadPicker(`${label} 技能`, data.skills, prefs.skills, "全部已启用的个人技能(含以后新增)");
87
83
  const memos = expertMemoField(data.memoLibraries, engine);
@@ -99,13 +95,6 @@ export function openAgentDefaults(engine, label) {
99
95
 
100
96
  fill(
101
97
  form,
102
- pick
103
- ? [
104
- h("h4", {}, "默认模型"),
105
- h("p", { class: "skill-note" }, "整台服务器的默认值,对所有成员生效;对话里可以随时换。自定义专家自己选了模型的按专家的来。"),
106
- h("div", { class: "row-fields" }, field("模型", pick.modelEl), engine === "workbuddy" ? null : field("思考程度", pick.effortEl)),
107
- ]
108
- : null,
109
98
  h("h4", {}, "默认权限"),
110
99
  field(
111
100
  "新对话的权限",
@@ -128,8 +117,6 @@ export function openAgentDefaults(engine, label) {
128
117
  body: { agents: { [engine]: { permission: permission.value || null, skills: skills.value(), machineSkills: machineSkills.checked, mcp: mcp.value(), memoAccess: memos.changes() } } },
129
118
  });
130
119
  S.defaultPermission = { ...S.defaultPermission, [engine]: res.agents?.[engine]?.permission ?? null };
131
- const changed = pick && (pick.model() !== (server.defaultModel ?? "") || pick.effort() !== (server.defaultEffort ?? ""));
132
- if (changed && !(await saveConfig(cfg, { agents: { [engine]: { defaultModel: pick.model(), defaultEffort: pick.effort() } } }))) return false;
133
120
  renderContext();
134
121
  toast("已保存,下次发消息生效");
135
122
  close();
@@ -1,7 +1,7 @@
1
1
  import { fill, h, icon, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { copyText } from "../lib/markdown.js";
4
- import { desktopQuota, S } from "../state.js";
4
+ import { desktopQuota, S, ui } from "../state.js";
5
5
  import { defaultEntryName, usableAgents } from "../views/topbar.js";
6
6
  import { renderEmpty } from "../views/messages.js";
7
7
  import { field, saveButton, saveConfig } from "./common.js";
@@ -21,7 +21,7 @@ const WORKBUDDY_SITES = [
21
21
  * 全部勾上存成空数组 = 「全部显示」,以后 agent 新增的模型也会自动出现;
22
22
  * 只勾了一部分就只显示这些。一个都不勾不允许保存。
23
23
  */
24
- function modelChecklist(agent, selected) {
24
+ function modelChecklist(modelList, selected) {
25
25
  const box = h("div", { class: "model-checks" }, h("small", {}, "正在读取模型列表…"));
26
26
  const summaryText = h("span", {}, "正在读取模型列表…");
27
27
  const summary = h("summary", { class: "input model-check-summary" }, summaryText, icon("down"));
@@ -40,7 +40,7 @@ function modelChecklist(agent, selected) {
40
40
  summary.focus();
41
41
  }
42
42
  });
43
- api(`/api/agents/${agent}/models`)
43
+ modelList
44
44
  .then((data) => {
45
45
  const models = data?.models ?? [];
46
46
  if (!models.length) {
@@ -81,7 +81,7 @@ function modelChecklist(agent, selected) {
81
81
  }
82
82
 
83
83
  /** Agent 运行环境:装没装、登没登录;没好的给出在终端里执行的命令 */
84
- function agentHealthSection() {
84
+ function agentHealthSection(engine) {
85
85
  const box = h("div", { class: "section" });
86
86
  const load = async (refresh) => {
87
87
  const recheck = h("button", { class: "btn small", onclick: () => load(true) }, "重新检查");
@@ -103,7 +103,7 @@ function agentHealthSection() {
103
103
  fill(
104
104
  box,
105
105
  h("h4", {}, "运行环境", h("span", { class: "grow" }), recheck),
106
- ...data.agents.map((a) => {
106
+ ...data.agents.filter(a => a.id === engine).map((a) => {
107
107
  const ok = a.installed && a.loggedIn === true;
108
108
  const state = !a.installed ? "未安装" : a.loggedIn === false ? "未登录" : a.loggedIn === null ? "无法确认" : "正常";
109
109
  return h(
@@ -219,95 +219,114 @@ function workbuddyLoginButton(after) {
219
219
  return h("div", {}, btn, status);
220
220
  }
221
221
 
222
- /** 设置 → Agent(管理员):运行环境、启用、引擎自己的配置、输入框可选模型。默认模型 / 权限 / 加载在「专家」里各内置 Agent 的「设置」 */
223
- export function agentsTab(cfg, page) {
224
- page.append(agentHealthSection());
225
- page.append(h("p", { class: "muted" }, "路径支持 ~ 和 ~/,代表运行 agent-loft 服务的用户家目录。"));
226
- const a = structuredClone(cfg.agents);
227
- for (const engine of ENGINES) {
228
- const label = ENGINE_LABEL[engine];
229
- const settings = a[engine];
230
- if (!settings) continue;
231
- const on = h("input", { type: "checkbox", checked: settings.enabled });
232
- const models = modelChecklist(engine, settings.models ?? []);
233
- const config = h("div", { class: "agent-config", "data-form": "" },
234
- h("h4", {}, label, h("span", { class: "grow" }), h("label", { class: "check" }, on, "启用")));
235
- let codex = null;
236
- if (engine === "codex") {
237
- const path = h("input", { value: settings.path });
238
- const home = h("input", { value: settings.home, placeholder: "留空用 ~/.codex" });
239
- const sandbox = h("select", {}, ["read-only", "workspace-write", "danger-full-access"].map((mode) => h("option", { value: mode, selected: mode === settings.sandbox }, mode)));
240
- codex = { path, home, sandbox };
241
- config.append(field("codex 可执行文件", path, "以系统服务运行时 PATH 很短,建议写绝对路径"), field("CODEX_HOME", home), field("沙箱", sandbox, "workspace-write:目录内可读写,越界才弹授权。danger-full-access 等于关掉沙箱"));
242
- }
243
- let titles = null;
244
- if (engine === "codex" || engine === "pi") {
245
- const on = h("input", { type: "checkbox", checked: settings.autoTitle ?? engine === "pi" });
246
- const pick = modelPicker(engine, settings.titleModel ?? "", "", engine === "pi" ? "跟随会话模型" : "跟随 config.toml");
247
- const model = h("div", { class: "grow field" }, pick.modelEl);
248
- const sync = () => { model.hidden = !on.checked; };
249
- on.addEventListener("change", sync);
250
- sync();
251
- titles = { on, pick, model };
252
- }
253
- let site = null;
254
- let cliPath = null;
255
- if (engine === "workbuddy") {
256
- site = h("select", {}, WORKBUDDY_SITES.map(([value, name]) => h("option", { value, selected: value === (settings.environment || "workbuddy") }, name)));
257
- cliPath = h("input", { value: settings.cliPath ?? "", placeholder: "留空自动找(如 /opt/WorkBuddy/resources/app.asar.unpacked/cli/bin/codebuddy)" });
258
- const cliField = field("WorkBuddy CLI 路径", cliPath, "WorkBuddy 桌面版里自带的 CLI,装在常见位置时不用填");
259
- const syncSite = () => { cliField.hidden = site.value !== "workbuddy"; };
260
- site.addEventListener("change", syncSite);
261
- syncSite();
262
- config.append(
263
- h("p", { class: "muted" }, "腾讯 WorkBuddy:调用这台服务器上 WorkBuddy 桌面版自带的 CLI;也可以改用 CodeBuddy 的账号(用 agent-loft 自带的 CLI)。启用并保存后,到上面「运行环境」里登录——桌面版里登录过也要在这里再登一次,同一个账号就行。暂不支持自定义专家和分叉。"),
264
- field("账号站点", site, "登录和对话都走这个站点。换了站点要重新登录"),
265
- cliField,
266
- );
267
- }
268
- if (engine === "pi") {
269
- config.append(
270
- h("p", { class: "muted" }, "pi(pi.dev):开源的编程 agent,用官方 SDK 在 agent-loft 进程里运行。不用登录账号,按模型服务商填 API Key(DeepSeek、智谱、Kimi、通义、MiniMax、OpenRouter……),整台服务器共用。凭据和会话记录都存在 agent-loft 的 data/pi/ 下,不读机器上的 ~/.pi。pi 本身没有权限系统,授权卡、计划模式、提问卡是 agent-loft 补上的;跑命令(bash)没有沙箱。暂不支持自定义专家。"),
271
- piProvidersSection(),
272
- piCustomSection(),
273
- );
274
- }
275
- let dsh = null;
276
- if (engine === "dsh") {
277
- const path = h("input", { value: settings.path ?? "dsh", placeholder: "dsh" });
278
- const home = h("input", { value: settings.home ?? "", placeholder: "留空用 ~/.dsh" });
279
- const patch = h("input", { value: settings.patch ?? "", placeholder: "留空不加(如 ~/.dsh/loft.patch.yml)" });
280
- dsh = { path, home, patch };
281
- config.append(
282
- h("p", { class: "muted" }, "dsh(DeepSeek Harness):DeepSeek 官方的编程 agent,通过标准 ACP 协议接入,每个会话一个 dsh 进程(第一条消息要等 4~5 秒拉起)。用 dsh 自己的凭据(~/.dsh/.credentials.yaml 里的 DeepSeek API Key)和会话记录,dsh 网页里建的会话这里也能接着聊。权限用 dsh 的沙箱:逐次询问 = 只读、自动改文件 = 工作区可写、完全允许 = 不设沙箱;越界时弹授权卡。不支持自定义专家、分叉 / 回退、提问卡和图片直传(附件给路径);设成「调用前询问」的 MCP 不会挂上。"),
283
- field("dsh 可执行文件", path, "npm install -g @deepseek-ai/dsh 装的;以系统服务运行时 PATH 很短,建议写绝对路径"),
284
- field("DSH_HOME", home),
285
- field("额外的 patch 文件", patch, "每个 dsh 进程都加 --patch 这个文件。dsh 的 ACP 模式默认只有官方 DeepSeek 模型,要接别家模型(llm-pi-ai)就写在这里"),
286
- );
287
- }
288
- config.append(h("small", { class: "muted" }, "默认模型、思考程度、权限和默认加载的技能 / MCP,在「设置 → 专家」里这个 Agent 的「设置」中修改。"));
289
- config.append(h("div", { class: "field" }, h("span", {}, "输入框可选模型"), models.el));
290
- if (titles) {
291
- config.append(h("div", { class: "row title-row" }, h("label", { class: "check" }, titles.on, "自动生成会话名称"), titles.model));
292
- if (engine === "pi") config.append(h("small", { class: "muted" }, "第一轮回复后在后台生成一次,会额外调用模型;留空跟随会话模型,可另选低成本模型。手动改名不会被覆盖。"));
293
- }
294
- config.append(h("div", { class: "row" }, saveButton(() => {
295
- const selected = models.value();
296
- if (!selected) {
297
- toast(`${label} 至少勾选一个模型`);
298
- return false;
299
- }
300
- return saveConfig(cfg, { agents: { [engine]: {
301
- enabled: on.checked, models: selected,
302
- ...(site ? { environment: site.value, cliPath: cliPath.value.trim() } : {}),
303
- ...(dsh ? { path: dsh.path.value.trim() || "dsh", home: dsh.home.value.trim(), patch: dsh.patch.value.trim() } : {}),
304
- ...(codex ? { path: codex.path.value.trim() || "codex", home: codex.home.value.trim(), sandbox: codex.sandbox.value } : {}),
305
- ...(titles ? { autoTitle: titles.on.checked, titleModel: titles.pick.model() } : {}),
306
- } } });
307
- }, `保存 ${label} 设置`)));
308
- page.append(h("div", { class: "section", "data-agent": engine }, config));
222
+ /** 设置 → Agent(管理员):运行环境、启用、引擎自己的配置、输入框可选模型。默认权限和工具在内置专家的个人设置 */
223
+ export function agentsTab(cfg, page, section) {
224
+ const engines = ENGINES.filter(id => cfg.agents?.[id]);
225
+ const requested = section?.split("-")[0];
226
+ const selected = engines.includes(requested) ? requested : engines[0];
227
+ if (!selected) { page.append(h("p", { class: "muted" }, "没有可配置的引擎")); return; }
228
+ const picker = h("select", { "aria-label": "选择引擎" },
229
+ engines.map(id => h("option", { value: id }, ENGINE_LABEL[id])));
230
+ picker.value = selected;
231
+ picker.onchange = () => {
232
+ const target = picker.value;
233
+ picker.value = selected;
234
+ void ui.settings.selectTab("engines/" + target);
235
+ };
236
+ page.append(field("配置对象", picker));
237
+ const engine = selected;
238
+ const label = ENGINE_LABEL[engine];
239
+ const settings = cfg.agents[engine];
240
+ page.append(agentHealthSection(engine));
241
+ const modelList = api(`/api/agents/${engine}/models`);
242
+ const defaults = modelPicker(engine, settings.defaultModel ?? "", settings.defaultEffort ?? "", "跟随引擎默认", modelList);
243
+ page.append(h("div", { class: "section", "data-form": "", "data-section": engine },
244
+ h("h4", {}, "实例默认模型"),
245
+ h("p", { class: "muted" }, "适用于本实例的所有成员。专家或对话单独选择的模型优先。"),
246
+ h("div", { class: "engine-model-fields" }, field("模型", defaults.modelEl), engine === "workbuddy" ? null : field("思考程度", defaults.effortEl)),
247
+ h("div", { class: "row" }, saveButton(() => saveConfig(cfg, { agents: { [engine]: {
248
+ defaultModel: defaults.model(), defaultEffort: defaults.effort(),
249
+ } } }), "保存默认模型"))));
250
+ const on = h("input", { type: "checkbox", checked: settings.enabled });
251
+ const models = modelChecklist(modelList, settings.models ?? []);
252
+ const config = h("div", { class: "agent-config", "data-form": "" },
253
+ h("h4", {}, label, h("span", { class: "grow" }), h("label", { class: "check" }, on, "启用")));
254
+ let codex = null;
255
+ if (engine === "codex") {
256
+ const path = h("input", { "data-section": "codex-path", value: settings.path });
257
+ const home = h("input", { value: settings.home, placeholder: "留空用 ~/.codex" });
258
+ const sandbox = h("select", { "data-section": "codex-sandbox" }, ["read-only", "workspace-write", "danger-full-access"].map((mode) => h("option", { value: mode, selected: mode === settings.sandbox }, mode)));
259
+ codex = { path, home, sandbox };
260
+ config.append(h("details", { class: "engine-advanced" }, h("summary", {}, "运行路径与沙箱"),
261
+ field("codex 可执行文件", path, "以系统服务运行时 PATH 很短,建议写绝对路径"),
262
+ field("CODEX_HOME", home), field("沙箱", sandbox, "workspace-write:目录内可读写,越界才弹授权。danger-full-access 等于关掉沙箱")));
309
263
  }
310
- page.append(quotaSection(cfg));
264
+ let titles = null;
265
+ if (engine === "codex" || engine === "pi") {
266
+ const on = h("input", { type: "checkbox", checked: settings.autoTitle ?? engine === "pi" });
267
+ const pick = modelPicker(engine, settings.titleModel ?? "", "", engine === "pi" ? "跟随会话模型" : "跟随 config.toml", modelList);
268
+ const model = h("div", { class: "grow field" }, pick.modelEl);
269
+ const sync = () => { model.hidden = !on.checked; };
270
+ on.addEventListener("change", sync);
271
+ sync();
272
+ titles = { on, pick, model };
273
+ }
274
+ let site = null;
275
+ let cliPath = null;
276
+ if (engine === "workbuddy") {
277
+ site = h("select", { "data-section": "workbuddy-site" }, WORKBUDDY_SITES.map(([value, name]) => h("option", { value, selected: value === (settings.environment || "workbuddy") }, name)));
278
+ cliPath = h("input", { value: settings.cliPath ?? "", placeholder: "留空自动找(如 /opt/WorkBuddy/resources/app.asar.unpacked/cli/bin/codebuddy)" });
279
+ const cliField = field("WorkBuddy CLI 路径", cliPath, "WorkBuddy 桌面版里自带的 CLI,装在常见位置时不用填");
280
+ const syncSite = () => { cliField.hidden = site.value !== "workbuddy"; };
281
+ site.addEventListener("change", syncSite);
282
+ syncSite();
283
+ config.append(
284
+ h("p", { class: "muted" }, "腾讯 WorkBuddy:调用这台服务器上 WorkBuddy 桌面版自带的 CLI;也可以改用 CodeBuddy 的账号(用 agent-loft 自带的 CLI)。启用并保存后,到上面「运行环境」里登录——桌面版里登录过也要在这里再登一次,同一个账号就行。暂不支持自定义专家和分叉。"),
285
+ field("账号站点", site, "登录和对话都走这个站点。换了站点要重新登录"),
286
+ cliField,
287
+ );
288
+ }
289
+ if (engine === "pi") {
290
+ config.append(
291
+ h("p", { class: "muted" }, "pi(pi.dev):开源的编程 agent,用官方 SDK 在 agent-loft 进程里运行。不用登录账号,按模型服务商填 API Key(DeepSeek、智谱、Kimi、通义、MiniMax、OpenRouter……),整台服务器共用。凭据和会话记录都存在 agent-loft 的 data/pi/ 下,不读机器上的 ~/.pi。pi 本身没有权限系统,授权卡、计划模式、提问卡是 agent-loft 补上的;跑命令(bash)没有沙箱。暂不支持自定义专家。"),
292
+ piProvidersSection(),
293
+ piCustomSection(),
294
+ );
295
+ }
296
+ let dsh = null;
297
+ if (engine === "dsh") {
298
+ const path = h("input", { value: settings.path ?? "dsh", placeholder: "dsh" });
299
+ const home = h("input", { value: settings.home ?? "", placeholder: "留空用 ~/.dsh" });
300
+ const patch = h("input", { "data-section": "dsh-patch", value: settings.patch ?? "", placeholder: "留空不加(如 ~/.dsh/loft.patch.yml)" });
301
+ dsh = { path, home, patch };
302
+ config.append(
303
+ h("p", { class: "muted" }, "dsh(DeepSeek Harness):DeepSeek 官方的编程 agent,通过标准 ACP 协议接入,每个会话一个 dsh 进程(第一条消息要等 4~5 秒拉起)。用 dsh 自己的凭据(~/.dsh/.credentials.yaml 里的 DeepSeek API Key)和会话记录,dsh 网页里建的会话这里也能接着聊。权限用 dsh 的沙箱:逐次询问 = 只读、自动改文件 = 工作区可写、完全允许 = 不设沙箱;越界时弹授权卡。不支持自定义专家、分叉 / 回退、提问卡和图片直传(附件给路径);设成「调用前询问」的 MCP 不会挂上。"),
304
+ field("dsh 可执行文件", path, "npm install -g @deepseek-ai/dsh 装的;以系统服务运行时 PATH 很短,建议写绝对路径"),
305
+ field("DSH_HOME", home),
306
+ field("额外的 patch 文件", patch, "每个 dsh 进程都加 --patch 这个文件。dsh 的 ACP 模式默认只有官方 DeepSeek 模型,要接别家模型(llm-pi-ai)就写在这里"),
307
+ );
308
+ }
309
+
310
+ config.append(h("div", { class: "field" }, h("span", {}, "输入框可选模型"), models.el));
311
+ if (titles) {
312
+ config.append(h("div", { class: "row title-row" }, h("label", { class: "check" }, titles.on, "自动生成会话名称"), titles.model));
313
+ if (engine === "pi") config.append(h("small", { class: "muted" }, "第一轮回复后在后台生成一次,会额外调用模型;留空跟随会话模型,可另选低成本模型。手动改名不会被覆盖。"));
314
+ }
315
+ config.append(h("div", { class: "row" }, saveButton(() => {
316
+ const selected = models.value();
317
+ if (!selected) {
318
+ toast(`${label} 至少勾选一个模型`);
319
+ return false;
320
+ }
321
+ return saveConfig(cfg, { agents: { [engine]: {
322
+ enabled: on.checked, models: selected,
323
+ ...(site ? { environment: site.value, cliPath: cliPath.value.trim() } : {}),
324
+ ...(dsh ? { path: dsh.path.value.trim() || "dsh", home: dsh.home.value.trim(), patch: dsh.patch.value.trim() } : {}),
325
+ ...(codex ? { path: codex.path.value.trim() || "codex", home: codex.home.value.trim(), sandbox: codex.sandbox.value } : {}),
326
+ ...(titles ? { autoTitle: titles.on.checked, titleModel: titles.pick.model() } : {}),
327
+ } } });
328
+ }, `保存 ${label} 设置`)));
329
+ page.append(h("div", { class: "section", "data-agent": engine }, config));
311
330
  }
312
331
 
313
332
  /** 常用的排前面:国内能直接用的几家、再是 OpenRouter 和海外几家 */
@@ -318,7 +337,7 @@ const PI_PROVIDER_ORDER = ["deepseek", "zai-coding-cn", "kimi-coding", "moonshot
318
337
  * Key 只往服务端写,不回显;存在 data/pi/auth.json(0600)
319
338
  */
320
339
  function piProvidersSection() {
321
- const box = h("div", { class: "field pi-providers", "data-nodirty": "" }, h("span", {}, "模型服务商"), h("small", {}, "正在读取…"));
340
+ const box = h("div", { class: "field pi-providers", "data-section": "pi-providers", "data-nodirty": "" }, h("span", {}, "模型服务商"), h("small", {}, "正在读取…"));
322
341
  const load = async () => {
323
342
  let data;
324
343
  try {
@@ -602,7 +621,11 @@ function quotaSection(cfg) {
602
621
  h(
603
622
  "div",
604
623
  { class: "row" },
605
- saveButton(() => saveConfig(cfg, { web: { quotaRefreshMin: Number(quotaMin.value), quotaEnabled: quotaOn.checked } })),
624
+ saveButton(() => saveConfig(cfg, { web: { quotaRefreshMin: Number(quotaMin.value), quotaEnabled: quotaOn.checked } }), "保存额度设置"),
606
625
  ),
607
626
  );
608
627
  }
628
+
629
+ export function quotaTab(cfg, page) {
630
+ page.append(quotaSection(cfg));
631
+ }