agent-loft 0.2.84 → 0.2.86

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.
@@ -156,18 +156,16 @@ function installCodexButton(after) {
156
156
  return h("div", {}, btn);
157
157
  }
158
158
 
159
- /** 内置 Agent 的个人默认项;普通成员也能设置自己的,不需要服务器管理权限。 */
160
- function builtinDefaultsSection() {
161
- const section = h("div", { class: "section", "data-form": "" }, h("h4", {}, "内置 Agent 默认加载"), h("span", { class: "spinner" }));
159
+ /** 个人默认工具单独保存,避免改服务器配置时覆盖尚未保存的个人选择。 */
160
+ function builtinDefaultsSections(targets) {
162
161
  const load = async () => {
163
162
  let data;
164
163
  try {
165
164
  data = await api("/api/agents/defaults");
166
165
  } catch (err) {
167
- fill(section, h("h4", {}, "内置 Agent 默认加载"), h("div", { class: "error-text" }, err.message), h("button", { class: "btn small", onclick: load }, "重试"));
166
+ for (const section of Object.values(targets)) fill(section, h("div", { class: "error-text" }, err.message), h("button", { class: "btn small", onclick: load }, "重试"));
168
167
  return;
169
168
  }
170
- const choices = {};
171
169
  const picker = (label, items, selected, inheritLabel) => {
172
170
  const mode = h("select", { "aria-label": label },
173
171
  ...(inheritLabel ? [h("option", { value: "inherit", selected: selected === null }, inheritLabel)] : []),
@@ -176,128 +174,96 @@ function builtinDefaultsSection() {
176
174
  const missing = (selected ?? []).filter((id) => !known.has(id)).map((id) => ({ id, name: `${id}(暂不可用,可取消)` }));
177
175
  const inputs = [...items, ...missing].map((item) => ({ id: item.id, input: h("input", { type: "checkbox", checked: (selected ?? []).includes(item.id) }), item }));
178
176
  const list = h("div", { class: "check-list" }, inputs.length
179
- ? inputs.map(({ input, item }) => h("label", { class: "check-item", title: item.description ?? "" }, input, h("span", {}, item.name)))
177
+ ? inputs.map(({ input, item }) => h("label", { class: "check-item tool-check-item", title: item.description ?? item.name }, input, h("span", {}, item.name)))
180
178
  : h("small", {}, "暂无可选项,请先在设置中添加"));
181
179
  const sync = () => { list.hidden = mode.value !== "pick"; };
182
180
  mode.addEventListener("change", sync);
183
181
  sync();
184
182
  return { el: h("div", { class: "field" }, h("span", {}, label), mode, list), value: () => mode.value === "inherit" ? null : inputs.filter((x) => x.input.checked).map((x) => x.id) };
185
183
  };
186
- const panels = ["claude", "codex"].filter((engine) => data.agents[engine]).map((engine) => {
187
- const label = engine === "claude" ? "Claude Code" : "Codex";
184
+ for (const [engine, section] of Object.entries(targets)) {
188
185
  const prefs = data.agents[engine];
186
+ if (!prefs) {
187
+ section.hidden = true;
188
+ if (section.parentElement?.dataset.personal) section.parentElement.hidden = true;
189
+ continue;
190
+ }
191
+ const label = engine === "claude" ? "Claude Code" : "Codex";
189
192
  const skills = picker(`${label} 技能`, data.skills, prefs.skills, "全部已启用的个人技能(含以后新增)");
190
193
  const machine = (data.machineMcp?.[engine] ?? []).map((name) => ({ id: `${data.machinePrefix}${name}`, name: `${name}(本机)` }));
191
194
  const mcp = picker(`${label} MCP`, [...data.mcp, ...machine], prefs.mcp, data.machineMcp ? "沿用机器上的 MCP 配置" : null);
192
195
  const machineSkills = h("input", { type: "checkbox", checked: prefs.machineSkills });
193
- choices[engine] = { skills, mcp, machineSkills };
194
- return h("div", { class: "builtin-agent-defaults" }, h("h4", {}, label), skills.el,
196
+ fill(section, h("h4", {}, "默认加载"),
197
+ h("p", { class: "skill-note" }, "仅影响你当前账号使用的这个内置 Agent,自定义专家使用各自的配置。保存后,下次发消息生效。"),
198
+ skills.el,
195
199
  data.machineMcp ? h("label", { class: "check-item" }, machineSkills, "同时加载机器上的技能") : null,
196
- mcp.el);
197
- });
198
- fill(section, h("h4", {}, "内置 Agent 默认加载"),
199
- h("p", { class: "skill-note" }, "仅影响你当前账号使用的内置 Agent;自定义专家继续使用各自的配置。保存后,下次发消息生效,正在执行的任务不受影响。"),
200
- ...panels,
201
- !panels.length ? h("p", { class: "muted" }, "没有获授权的内置 Agent,请联系管理员配置使用权限。") : null,
202
- h("small", {}, "技能和 MCP 可分别全部取消。记忆、定时任务、技能管理等系统工具仍按功能设置提供。"),
203
- h("div", { class: "row" }, saveButton(async () => {
204
- const agents = Object.fromEntries(Object.entries(choices).map(([engine, c]) => [engine, { skills: c.skills.value(), machineSkills: c.machineSkills.checked, mcp: c.mcp.value() }]));
205
- await api("/api/agents/defaults", { method: "PUT", body: { agents } });
206
- toast("已保存,下次发消息生效");
207
- }, "保存默认加载设置")));
200
+ mcp.el,
201
+ h("small", {}, "技能和 MCP 可分别全部取消。记忆、定时任务、技能管理等系统工具仍按功能设置提供。"),
202
+ h("div", { class: "row" }, saveButton(async () => {
203
+ await api("/api/agents/defaults", { method: "PUT", body: { agents: { [engine]: { skills: skills.value(), machineSkills: machineSkills.checked, mcp: mcp.value() } } } });
204
+ toast("已保存,下次发消息生效");
205
+ }, `保存 ${label} 默认加载`)));
206
+ }
207
+ if (!Object.keys(data.agents).length) {
208
+ const section = Object.values(targets)[0];
209
+ section.hidden = false;
210
+ section.parentElement.hidden = false;
211
+ const message = h("p", { class: "muted" }, "没有获授权的内置 Agent,请联系管理员配置使用权限。");
212
+ if (section.parentElement.dataset.personal) fill(section.parentElement, h("h4", {}, "内置 Agent"), message);
213
+ else fill(section, message);
214
+ }
208
215
  };
209
216
  void load();
210
- return section;
211
217
  }
212
218
 
213
219
  export function agentsTab(cfg, page) {
214
- page.append(builtinDefaultsSection());
215
- if (!cfg) return;
220
+ const targets = Object.fromEntries(["claude", "codex"].map((engine) => [engine, h("div", { class: "builtin-agent-defaults", "data-form": "" }, h("span", { class: "spinner" }))]));
221
+ if (!cfg) {
222
+ for (const [engine, target] of Object.entries(targets)) page.append(h("div", { class: "section", "data-personal": "true", "data-agent": engine }, h("h4", {}, engine === "claude" ? "Claude Code" : "Codex"), target));
223
+ builtinDefaultsSections(targets);
224
+ return;
225
+ }
216
226
  page.append(agentHealthSection());
217
227
  const a = structuredClone(cfg.agents);
218
- const claudeOn = h("input", { type: "checkbox", checked: a.claude.enabled });
219
- const claudePick = modelPicker("claude", a.claude.defaultModel, a.claude.defaultEffort, "跟随 Claude Code 默认");
220
- const claudeModels = modelChecklist("claude", a.claude.models ?? []);
221
- const codexOn = h("input", { type: "checkbox", checked: a.codex.enabled });
222
- const codexPath = h("input", { value: a.codex.path });
223
- const codexHome = h("input", { value: a.codex.home, placeholder: "留空用 ~/.codex" });
224
- const sandbox = h(
225
- "select",
226
- {},
227
- ["read-only", "workspace-write", "danger-full-access"].map((m) => h("option", { value: m, selected: m === a.codex.sandbox }, m)),
228
- );
229
- const codexPick = modelPicker("codex", a.codex.defaultModel, a.codex.defaultEffort, "跟随 config.toml");
230
- const codexModels = modelChecklist("codex", a.codex.models ?? []);
231
- // 自动生成会话名称:一行,勾上才显示后面的模型选择
232
- const titleOn = h("input", { type: "checkbox", checked: !!a.codex.autoTitle });
233
- const titlePick = modelPicker("codex", a.codex.titleModel ?? "", "", "跟随 config.toml");
234
- const titleModelEl = h("div", { class: "grow field" }, titlePick.modelEl);
235
- const syncTitle = () => (titleModelEl.hidden = !titleOn.checked);
236
- titleOn.addEventListener("change", syncTitle);
237
- syncTitle();
238
- // 一组勾选框不能放进 <label>(点哪都会切到第一个),所以不用 field()
239
- const checksField = (list) => h("div", { class: "field" }, h("span", {}, "输入框可选模型"), list.el);
240
- // 两个 agent 一起保存:整组算一张表单
241
- page.append(
242
- h(
243
- "div",
244
- { class: "settings-stack", "data-form": "" },
245
- h(
246
- "div",
247
- { class: "section" },
248
- h("h4", {}, "Claude Code", h("span", { class: "grow" }), h("label", { class: "check" }, claudeOn, "启用")),
249
- field("默认模型", claudePick.modelEl),
250
- field("默认思考程度", claudePick.effortEl),
251
- checksField(claudeModels),
252
- ),
253
- h(
254
- "div",
255
- { class: "section" },
256
- h("h4", {}, "Codex", h("span", { class: "grow" }), h("label", { class: "check" }, codexOn, "启用")),
257
- field("codex 可执行文件", codexPath, "以系统服务运行时 PATH 很短,建议写绝对路径"),
258
- field("CODEX_HOME", codexHome),
259
- field("沙箱", sandbox, "workspace-write:目录内可读写,越界才弹授权。danger-full-access 等于关掉沙箱"),
260
- field("默认模型", codexPick.modelEl),
261
- field("默认思考程度", codexPick.effortEl),
262
- checksField(codexModels),
263
- h("div", { class: "row title-row" }, h("label", { class: "check" }, titleOn, "自动生成会话名称"), titleModelEl),
264
- ),
265
- h(
266
- "div",
267
- { class: "row" },
268
- saveButton(() => {
269
- const claudeList = claudeModels.value();
270
- const codexList = codexModels.value();
271
- if (!claudeList || !codexList) {
272
- toast(`${!claudeList ? "Claude Code" : "Codex"} 至少勾选一个模型`);
273
- return false;
274
- }
275
- return saveConfig(cfg, {
276
- agents: {
277
- claude: {
278
- enabled: claudeOn.checked,
279
- defaultModel: claudePick.model(),
280
- defaultEffort: claudePick.effort(),
281
- models: claudeList,
282
- },
283
- codex: {
284
- enabled: codexOn.checked,
285
- path: codexPath.value.trim() || "codex",
286
- home: codexHome.value.trim(),
287
- sandbox: sandbox.value,
288
- defaultModel: codexPick.model(),
289
- defaultEffort: codexPick.effort(),
290
- models: codexList,
291
- autoTitle: titleOn.checked,
292
- titleModel: titlePick.model(),
293
- },
294
- },
295
- });
296
- }, "保存 Agent 设置"),
297
- ),
298
- ),
299
- quotaSection(cfg),
300
- );
228
+ for (const engine of ["claude", "codex"]) {
229
+ const label = engine === "claude" ? "Claude Code" : "Codex";
230
+ const settings = a[engine];
231
+ const on = h("input", { type: "checkbox", checked: settings.enabled });
232
+ const pick = modelPicker(engine, settings.defaultModel, settings.defaultEffort, engine === "claude" ? "跟随 Claude Code 默认" : "跟随 config.toml");
233
+ const models = modelChecklist(engine, settings.models ?? []);
234
+ const config = h("div", { class: "agent-config", "data-form": "" },
235
+ h("h4", {}, label, h("span", { class: "grow" }), h("label", { class: "check" }, on, "启用")));
236
+ let codex = null;
237
+ if (engine === "codex") {
238
+ const path = h("input", { value: settings.path });
239
+ const home = h("input", { value: settings.home, placeholder: "留空用 ~/.codex" });
240
+ const sandbox = h("select", {}, ["read-only", "workspace-write", "danger-full-access"].map((mode) => h("option", { value: mode, selected: mode === settings.sandbox }, mode)));
241
+ const titleOn = h("input", { type: "checkbox", checked: !!settings.autoTitle });
242
+ const titlePick = modelPicker("codex", settings.titleModel ?? "", "", "跟随 config.toml");
243
+ const titleModel = h("div", { class: "grow field" }, titlePick.modelEl);
244
+ const syncTitle = () => { titleModel.hidden = !titleOn.checked; };
245
+ titleOn.addEventListener("change", syncTitle);
246
+ syncTitle();
247
+ codex = { path, home, sandbox, titleOn, titlePick, titleModel };
248
+ config.append(field("codex 可执行文件", path, "以系统服务运行时 PATH 很短,建议写绝对路径"), field("CODEX_HOME", home), field("沙箱", sandbox, "workspace-write:目录内可读写,越界才弹授权。danger-full-access 等于关掉沙箱"));
249
+ }
250
+ config.append(field("默认模型", pick.modelEl), field("默认思考程度", pick.effortEl), h("div", { class: "field" }, h("span", {}, "输入框可选模型"), models.el));
251
+ if (codex) config.append(h("div", { class: "row title-row" }, h("label", { class: "check" }, codex.titleOn, "自动生成会话名称"), codex.titleModel));
252
+ config.append(h("div", { class: "row" }, saveButton(() => {
253
+ const selected = models.value();
254
+ if (!selected) {
255
+ toast(`${label} 至少勾选一个模型`);
256
+ return false;
257
+ }
258
+ return saveConfig(cfg, { agents: { [engine]: {
259
+ enabled: on.checked, defaultModel: pick.model(), defaultEffort: pick.effort(), models: selected,
260
+ ...(codex ? { path: codex.path.value.trim() || "codex", home: codex.home.value.trim(), sandbox: codex.sandbox.value, autoTitle: codex.titleOn.checked, titleModel: codex.titlePick.model() } : {}),
261
+ } } });
262
+ }, `保存 ${label} 设置`)));
263
+ page.append(h("div", { class: "section", "data-agent": engine }, config, targets[engine]));
264
+ }
265
+ page.append(quotaSection(cfg));
266
+ builtinDefaultsSections(targets);
301
267
  }
302
268
 
303
269
  /** 账号额度:侧栏底部、/status、桌面端显示的 Claude / Codex 订阅额度,查不查、多久查一次 */
@@ -51,7 +51,7 @@ function render(box, data, reload) {
51
51
  h(
52
52
  "p",
53
53
  { class: "skill-note" },
54
- "专家决定引擎、提示词和能力。共享给所有账号后,设定由创建者维护,每个人的记忆、技能和 MCP 仍各自独立;点「我的工具」选择自己要用的工具。内置的 Claude Code、Codex 在「设置 → Agent」里选择默认技能和 MCP。",
54
+ "专家决定引擎、提示词和能力。共享给所有账号后,设定由创建者维护,每个人的记忆、技能和 MCP 仍各自独立;点「我的工具」选择自己要用的工具。内置的 Claude Code、Codex 在「设置 → Agent」各自卡片的「默认加载」中选择技能和 MCP。",
55
55
  ),
56
56
  h("div", { class: "skill-head-btns" }, add),
57
57
  ),
@@ -165,7 +165,7 @@ function field(label, input, hint) {
165
165
  function checkList(items, picked, empty) {
166
166
  const boxes = items.map((it) => {
167
167
  const box = h("input", { type: "checkbox", checked: picked.includes(it.id) });
168
- return { id: it.id, box, el: h("label", { class: "check-item", title: it.hint ?? "" }, box, h("span", {}, it.label), it.hint ? h("small", {}, it.hint) : null) };
168
+ return { id: it.id, box, el: h("label", { class: "check-item tool-check-item", title: [it.label, it.hint].filter(Boolean).join(" · ") }, box, h("span", {}, it.label), it.hint ? h("small", {}, it.hint) : null) };
169
169
  });
170
170
  return {
171
171
  el: boxes.length ? h("div", { class: "check-list" }, boxes.map((b) => b.el)) : h("div", { class: "muted" }, empty),
@@ -531,7 +531,7 @@ function renderMcp(box, data, reload) {
531
531
  h(
532
532
  "p",
533
533
  { class: "skill-note" },
534
- "MCP 服务给专家提供工具(查数据、调接口)。这里加好,再到「专家」里给专家勾上。只给你自己的专家用;内置的 Claude Code / Codex 照旧用机器上配的。",
534
+ "MCP 服务提供查数据、调接口等工具,只供你自己的账号使用。这里加好后,自定义专家在「专家」里勾选;内置的 Claude Code / Codex 在「Agent」各自卡片的「默认加载」中选择。",
535
535
  ),
536
536
  h("div", { class: "skill-head-btns" }, h("button", { class: "btn primary", onclick: () => openMcpEditor(null, reload) }, icon("plus"), "添加")),
537
537
  ),
@@ -2,7 +2,6 @@ import { fill, h } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { isAdmin } from "../state.js";
4
4
  import { confirmDialog, modal } from "../lib/overlay.js";
5
- import { notifyTab } from "./notify.js";
6
5
  import { conversationTab, remoteTab } from "./general.js";
7
6
  import { commandsTab } from "./commands.js";
8
7
  import { agentsTab } from "./agents.js";
@@ -23,14 +22,13 @@ import { hasDirty, markDirty } from "./common.js";
23
22
  const LAST_TAB = "aim.settingsTab";
24
23
 
25
24
  /** 以前的标签名:外面(地址、别处的按钮)传进来的旧名字照样能打开对应的页 */
26
- const RENAMED = { 通用: "对话", 授权: "对话", 飞书机器人: "飞书", 我的账号: "账号" };
25
+ const RENAMED = { 通用: "对话", 授权: "对话", 飞书机器人: "飞书", 我的账号: "账号", 通知: "系统" };
27
26
 
28
27
  function groupsFor(cfg) {
29
28
  const mine = {
30
29
  name: "我的",
31
30
  tabs: [
32
31
  ["账号", (p) => accountTab(p)],
33
- ["通知", (p) => notifyTab(p)],
34
32
  ["记忆", (p) => memoryTab(p)],
35
33
  ["专家", (p) => expertsTab(p)],
36
34
  ["技能", (p) => skillsTab(p)],
@@ -38,7 +36,7 @@ function groupsFor(cfg) {
38
36
  ["用量", (p) => usageTab(p)],
39
37
  ],
40
38
  };
41
- if (!cfg) return [mine, { name: "Agent", tabs: [["Agent", (p) => agentsTab(null, p)]] }];
39
+ if (!cfg) return [mine, { name: "Agent", tabs: [["Agent", (p) => agentsTab(null, p)]] }, { name: "系统", tabs: [["系统", (p) => systemTab(null, p)]] }];
42
40
  return [
43
41
  mine,
44
42
  {
@@ -129,6 +127,7 @@ export async function openSettings(tab) {
129
127
  nav.append(b);
130
128
  }
131
129
  }
132
- const want = tab ? (RENAMED[tab] ?? tab) : localStorage.getItem(LAST_TAB);
130
+ const requested = tab || localStorage.getItem(LAST_TAB);
131
+ const want = RENAMED[requested] ?? requested;
133
132
  void select(Math.max(0, tabs.findIndex(([name]) => name === want)));
134
133
  }
@@ -95,6 +95,7 @@ export async function memoryTab(panel, refresh = false) {
95
95
  const edit = h("button", { class: "btn small" }, "编辑");
96
96
  const del = h("button", { class: "btn small danger" }, "删除");
97
97
  edit.onclick = () => {
98
+ edit.hidden = del.hidden = true;
98
99
  const input = h("textarea", { class: "input", rows: 2, maxlength: mem.limits.item });
99
100
  input.value = it.text;
100
101
  const ok = h("button", { class: "btn small primary" }, "保存");
@@ -8,7 +8,7 @@ import { WS } from "../lib/ws.js";
8
8
  export async function notifyTab(panel) {
9
9
  const support = pushSupport();
10
10
  const box = h("div", { class: "section" }, h("h4", {}, "系统通知"), h("span", { class: "spinner" }));
11
- fill(panel, box);
11
+ panel.append(box);
12
12
  const render = async () => {
13
13
  let data = { subscriptions: [] };
14
14
  try {
@@ -4,7 +4,7 @@ import { relTime } from "../lib/time.js";
4
4
  import { copyText } from "../lib/markdown.js";
5
5
  import { isAdmin, S } from "../state.js";
6
6
  import { dropPushSub } from "../lib/push.js";
7
- import { field, saveButton } from "./common.js";
7
+ import { field, markClean, saveButton } from "./common.js";
8
8
  import { weixinLinkSection } from "./weixin.js";
9
9
 
10
10
  /** 设置 → 账号:我是谁、改密码、绑定飞书、我登录着的设备。别人的设备在 管理 →「用户」里 */
@@ -27,42 +27,52 @@ export async function accountTab(page) {
27
27
  const name = h("input", { value: S.user?.name ?? "", autocomplete: "username", autocapitalize: "off", spellcheck: "false", maxlength: "32" });
28
28
  const currentName = h("span", {}, S.user?.name ?? "");
29
29
  const devicesBox = h("div", { class: "section" }, h("h4", {}, "已登录的设备"), h("span", { class: "spinner" }));
30
+ const nameForm = h("div", { class: "account-edit", "data-form": "", hidden: true });
31
+ const passwordForm = h("div", { class: "account-edit", "data-form": "", hidden: true });
32
+ const hideForms = () => {
33
+ nameForm.hidden = passwordForm.hidden = true;
34
+ old.value = pw.value = "";
35
+ markClean(nameForm);
36
+ markClean(passwordForm);
37
+ };
38
+ const rename = h("button", { class: "btn small", onclick: () => {
39
+ hideForms();
40
+ name.value = S.user?.name ?? "";
41
+ nameForm.hidden = false;
42
+ name.focus();
43
+ } }, "修改名称");
44
+ const password = h("button", { class: "btn small", onclick: () => {
45
+ hideForms();
46
+ passwordForm.hidden = false;
47
+ old.focus();
48
+ } }, "修改密码");
49
+ nameForm.append(
50
+ field("账号名称", name, "也是登录时使用的用户名。1~32 个字符,可用文字、数字和 _ . @ -;修改后请用新名称登录。"),
51
+ h("div", { class: "row" }, saveButton(async () => {
52
+ const data = await api("/api/account", { method: "PATCH", body: { name: name.value.trim() } });
53
+ S.user = data.user;
54
+ name.value = currentName.textContent = data.user.name;
55
+ hideForms();
56
+ toast("账号名称已修改");
57
+ }, "保存账号名称"), h("button", { class: "btn", onclick: hideForms }, "取消")),
58
+ );
59
+ passwordForm.append(
60
+ field("原密码", old),
61
+ field("新密码(至少 8 位)", pw),
62
+ h("div", { class: "row" }, saveButton(async () => {
63
+ await api("/api/password", { method: "POST", body: { old: old.value, password: pw.value } });
64
+ hideForms();
65
+ toast("密码已修改,你的其它设备已下线");
66
+ void loadDevices();
67
+ }, "保存密码"), h("button", { class: "btn", onclick: hideForms }, "取消")),
68
+ );
30
69
  page.append(
31
- h(
32
- "div",
33
- { class: "section", "data-form": "" },
34
- h(
35
- "h4",
36
- {},
37
- "当前账号",
38
- h("span", { class: "grow" }),
39
- logout,
40
- ),
70
+ h("div", { class: "section" },
71
+ h("h4", {}, "当前账号"),
41
72
  S.user ? h("div", {}, currentName, " ", h("span", { class: "status-tag" }, S.user.role === "admin" ? "管理员" : "成员")) : null,
42
- field("账号名称", name, "也是登录时使用的用户名。1~32 个字符,可用文字、数字和 _ . @ -;修改后请用新名称登录。"),
43
- h("div", { class: "row" }, saveButton(async () => {
44
- const data = await api("/api/account", { method: "PATCH", body: { name: name.value.trim() } });
45
- S.user = data.user;
46
- name.value = currentName.textContent = data.user.name;
47
- toast("账号名称已修改");
48
- }, "保存账号名称")),
49
- ),
50
- h(
51
- "div",
52
- { class: "section", "data-form": "" },
53
- h("h4", {}, "修改登录密码"),
54
- field("原密码", old),
55
- field("新密码(至少 8 位)", pw),
56
- h(
57
- "div",
58
- { class: "row" },
59
- saveButton(async () => {
60
- await api("/api/password", { method: "POST", body: { old: old.value, password: pw.value } });
61
- toast("密码已修改,你的其它设备已下线");
62
- old.value = pw.value = "";
63
- void loadDevices();
64
- }, "修改"),
65
- ),
73
+ h("div", { class: "row account-actions" }, rename, password, logout),
74
+ nameForm,
75
+ passwordForm,
66
76
  ),
67
77
  feishuLinkSection(),
68
78
  weixinLinkSection(),
@@ -160,7 +170,7 @@ function feishuLinkSection() {
160
170
  };
161
171
  fill(
162
172
  box,
163
- h("h4", {}, "飞书账号"),
173
+ h("h4", {}, "飞书账号", h("span", { class: "grow" }), gen),
164
174
  h("div", { class: "muted" }, "绑定后,你和飞书机器人的私聊就是你的个人会话:用你的记忆,/sessions 只列你的会话,/web 能接上你自己的 Web 会话。群聊不受影响。"),
165
175
  data.links.map((l) => {
166
176
  const rm = h("button", { class: "btn small danger" }, "解除绑定");
@@ -182,7 +192,6 @@ function feishuLinkSection() {
182
192
  rm,
183
193
  );
184
194
  }),
185
- h("div", { class: "row" }, gen),
186
195
  codeBox,
187
196
  );
188
197
  };
@@ -1,10 +1,11 @@
1
1
  import { fill, h, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { relTime } from "../lib/time.js";
4
- import { confirmDialog, showMenu } from "../lib/overlay.js";
5
- import { field, saveButton } from "./common.js";
4
+ import { confirmDialog, modal, showMenu } from "../lib/overlay.js";
5
+ import { field, markDirty, saveButton } from "./common.js";
6
6
  import { networkSection } from "./general.js";
7
7
  import { deviceList } from "./security.js";
8
+ import { notifyTab } from "./notify.js";
8
9
 
9
10
  /** null 沿用全部;指定列表可以全部取消,新增资源不会自动加入。 */
10
11
  function permissionFields(resources, permissions = {}) {
@@ -36,9 +37,7 @@ function permissionFields(resources, permissions = {}) {
36
37
 
37
38
  export async function usersTab(page) {
38
39
  const box = h("div", { class: "section" }, h("h4", {}, "用户"), h("span", { class: "spinner" }));
39
- const addBox = h("div", { class: "section", "data-form": "" });
40
- const devicesBox = h("div", { class: "section" });
41
- fill(page, box, addBox, devicesBox);
40
+ fill(page, box);
42
41
  const reload = () => {
43
42
  fill(page);
44
43
  void usersTab(page);
@@ -94,7 +93,7 @@ export async function usersTab(page) {
94
93
 
95
94
  /** 一个用户能做的事:常用的直接放在行上,其余收进「⋯」 */
96
95
  const actions = (u, self, extra) => {
97
- const items = [{ label: "重置密码", onclick: () => resetRow(u, extra) }];
96
+ const items = [{ label: "登录设备", onclick: () => showDevices(u) }, { label: "重置密码", onclick: () => resetRow(u, extra) }];
98
97
  if (!self) {
99
98
  items.push({ label: u.role === "admin" ? "设为成员" : "设为管理员", onclick: act(() => patch(u, { role: u.role === "admin" ? "member" : "admin" })) });
100
99
  items.push({
@@ -183,7 +182,7 @@ export async function usersTab(page) {
183
182
 
184
183
  fill(
185
184
  box,
186
- h("h4", {}, `用户(${data.users.length})`),
185
+ h("h4", {}, `用户(${data.users.length})`, h("span", { class: "grow" }), h("button", { class: "btn small", onclick: () => openAddUser() }, "添加用户")),
187
186
  h("div", { class: "muted" }, "每个人只看得到自己的对话、授权和通知。管理员能改所有设置,还能看到飞书机器人的对话。"),
188
187
  h(
189
188
  "div",
@@ -220,62 +219,68 @@ export async function usersTab(page) {
220
219
  }),
221
220
  );
222
221
 
223
- const name = h("input", { autocomplete: "off", autocapitalize: "off", spellcheck: "false", placeholder: "登录用的名字" });
224
- const pw = h("input", { type: "password", autocomplete: "new-password", placeholder: "至少 8 位" });
225
- const role = h("select", {}, h("option", { value: "member" }, "成员"), h("option", { value: "admin" }, "管理员"));
226
- const permissions = permissionFields(data.resources);
227
- const remote = h("input", { type: "checkbox" });
228
- const memberOptions = h("div", { class: "user-permissions" }, permissions.el,
229
- h("div", { class: "field" }, h("span", {}, "远程权限"), h("label", { class: "check-item" }, remote, h("span", {}, "允许使用终端和桌面"))));
230
- role.onchange = () => { memberOptions.hidden = role.value === "admin"; };
231
- fill(
232
- addBox,
233
- h("h4", {}, "添加用户"),
234
- field("用户名", name),
235
- field("密码", pw, "告诉对方,让他登录后在 设置 →「账号」里自己改掉"),
236
- field("角色", role, "成员只能用自己的对话;管理员能改所有设置、管理用户"),
237
- memberOptions,
238
- h(
239
- "div",
240
- { class: "row" },
241
- saveButton(async () => {
242
- if (role.value === "member" && remote.checked && !(await confirmDialog({
243
- title: `给「${name.value.trim()}」开通远程控制?`,
244
- message: "他能以运行 agent-loft 的系统用户直接使用终端和桌面,读写服务器上的文件、安装软件、停止服务,不经过授权卡。只开给完全信任的人。",
245
- confirmText: "开通并添加", danger: true,
246
- }))) return false;
247
- await api("/api/users", { method: "POST", body: { name: name.value.trim(), password: pw.value, role: role.value,
248
- ...(role.value === "member" ? { remote: remote.checked, permissions: permissions.value() } : {}) } });
249
- toast(`已添加「${name.value.trim()}」`);
250
- // 先标成已保存再刷新,免得离开提醒
251
- addBox.removeAttribute("data-dirty");
252
- reload();
253
- }, "添加"),
254
- ),
255
- );
256
-
257
- // 所有人登录着的设备:哪台不认识就让它下线
258
- const loadDevices = async () => {
259
- let sessions;
260
- try {
261
- sessions = await api("/api/web-sessions");
262
- } catch (err) {
263
- fill(devicesBox, h("h4", {}, "所有已登录的设备"), h("div", { class: "error-text" }, err.message));
264
- return;
265
- }
222
+ const openAddUser = () => {
223
+ const addBox = h("div", { class: "modal-body settings-stack", "data-form": "" });
224
+ for (const event of ["input", "change"]) addBox.addEventListener(event, () => markDirty(addBox));
225
+ const name = h("input", { autocomplete: "off", autocapitalize: "off", spellcheck: "false", placeholder: "登录用的名字" });
226
+ const pw = h("input", { type: "password", autocomplete: "new-password", placeholder: "至少 8 位" });
227
+ const role = h("select", {}, h("option", { value: "member" }, "成员"), h("option", { value: "admin" }, "管理员"));
228
+ const permissions = permissionFields(data.resources);
229
+ const remote = h("input", { type: "checkbox" });
230
+ const memberOptions = h("div", { class: "user-permissions" }, permissions.el,
231
+ h("div", { class: "field" }, h("span", {}, "远程权限"), h("label", { class: "check-item" }, remote, h("span", {}, "允许使用终端和桌面"))));
232
+ role.onchange = () => { memberOptions.hidden = role.value === "admin"; };
266
233
  fill(
267
- devicesBox,
268
- h("h4", {}, `所有已登录的设备(${sessions.length})`),
269
- deviceList(sessions, { showOwner: true, onChange: loadDevices }),
234
+ addBox,
235
+ field("用户名", name),
236
+ field("密码", pw, "告诉对方,让他登录后在 设置 →「账号」里自己改掉"),
237
+ field("角色", role, "成员只能用自己的对话;管理员能改所有设置、管理用户"),
238
+ memberOptions,
239
+ h(
240
+ "div",
241
+ { class: "row" },
242
+ saveButton(async () => {
243
+ if (role.value === "member" && remote.checked && !(await confirmDialog({
244
+ title: `给「${name.value.trim()}」开通远程控制?`,
245
+ message: "他能以运行 agent-loft 的系统用户直接使用终端和桌面,读写服务器上的文件、安装软件、停止服务,不经过授权卡。只开给完全信任的人。",
246
+ confirmText: "开通并添加", danger: true,
247
+ }))) return false;
248
+ await api("/api/users", { method: "POST", body: { name: name.value.trim(), password: pw.value, role: role.value,
249
+ ...(role.value === "member" ? { remote: remote.checked, permissions: permissions.value() } : {}) } });
250
+ toast(`已添加「${name.value.trim()}」`);
251
+ close();
252
+ reload();
253
+ }, "添加"),
254
+ h("button", { class: "btn", onclick: () => close() }, "取消"),
255
+ ),
270
256
  );
257
+
258
+ const close = modal({ title: "添加用户", body: addBox, wide: true });
259
+ name.focus();
260
+ };
261
+
262
+ const showDevices = (user) => {
263
+ const body = h("div", { class: "modal-body settings-stack" });
264
+ modal({ title: `${user.name} · 登录设备`, body, wide: true });
265
+ const load = async () => {
266
+ try {
267
+ const sessions = await api("/api/web-sessions");
268
+ const mine = sessions.filter((session) => session.userId === user.id || (!session.userId && user.id === data.me));
269
+ fill(body, h("div", { class: "muted" }, `已登录的设备(${mine.length})`), deviceList(mine, { onChange: load }));
270
+ } catch (err) {
271
+ fill(body, h("div", { class: "error-text" }, err.message), h("button", { class: "btn", onclick: load }, "重试"));
272
+ }
273
+ };
274
+ void load();
271
275
  };
272
- void loadDevices();
273
276
  }
274
277
 
275
278
  /** 设置 → 系统:服务端运行状态、版本和升级、重启,网络访问 */
276
279
  export async function systemTab(cfg, page) {
280
+ if (!cfg) return notifyTab(page);
277
281
  const sysBox = h("div", { class: "section" }, h("h4", {}, "服务端", h("span", { class: "grow" }), h("span", { class: "spinner" })));
278
282
  page.append(sysBox, networkSection(cfg));
283
+ void notifyTab(page);
279
284
 
280
285
  const restart = async () => {
281
286
  if (!(await confirmDialog({ title: "重启 agent-loft?", message: "进行中的对话会被中断。", confirmText: "重启", danger: true }))) return;
@@ -86,15 +86,14 @@ export function weixinLinkSection() {
86
86
  change.disabled = !expert.value || expert.value === data.expert;
87
87
  }
88
88
  };
89
- rows.push(field("微信使用的专家", h("div", { class: "row" }, expert, change), "切换会结束当前会话并开启新会话,之后的微信消息使用所选专家。也可以在微信里发 /expert 切换。"));
89
+ rows.push(field("微信使用的专家", h("div", { class: "row weixin-expert-row" }, expert, change), "切换会结束当前会话并开启新会话,之后的微信消息使用所选专家。也可以在微信里发 /expert 切换。"));
90
90
  }
91
91
  fill(
92
92
  box,
93
- h("h4", {}, "微信"),
93
+ h("h4", {}, "微信", h("span", { class: "grow" }), scan),
94
94
  h("div", { class: "muted" }, "连接后可以在微信的 ClawBot 里和 agent 聊天。"),
95
95
  h("ul", { class: "muted" }, NOTES.map((n) => h("li", {}, n))),
96
96
  rows,
97
- h("div", { class: "row" }, scan),
98
97
  );
99
98
  };
100
99
  void load();