agent-loft 0.2.67 → 0.2.69

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.
@@ -0,0 +1,40 @@
1
+ .photo-album {
2
+ margin: 14px 0;
3
+ padding: 14px;
4
+ border: 1px solid var(--border);
5
+ border-radius: var(--radius);
6
+ background: var(--bg);
7
+ min-width: 0;
8
+ }
9
+ .album-head, .album-pager { display: flex; align-items: center; gap: 12px; }
10
+ .album-head { justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; }
11
+ .album-head span, .album-page, .album-date, .album-empty, .album-pending { color: var(--fg-soft); font-size: 13px; }
12
+ .album-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
13
+ .album-tile { padding: 0; min-width: 0; text-align: left; border-radius: 8px; }
14
+ .album-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
15
+ .album-pic { display: grid; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--bg-soft); }
16
+ .md .album-pic img { display: block; width: 100%; height: 100%; max-height: none; margin: 0; border-radius: 0; object-fit: cover; }
17
+ .album-missing { align-self: center; text-align: center; color: var(--fg-faint); font-size: 12px; }
18
+ .album-name, .album-date { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
19
+ .album-name { margin-top: 5px; font-size: 12px; }
20
+ .album-date { font-size: 11px; }
21
+ .album-pager { justify-content: center; margin-top: 14px; }
22
+ .album-pager .btn, .photo-controls .btn { font-size: 13px; }
23
+ .album-error { color: var(--danger); font-size: 13px; }
24
+ .photo-viewer { position: fixed; inset: 0; padding: 0; margin: auto; width: min(1100px, calc(100% - 32px)); max-width: none; max-height: calc(100dvh - 32px); border: 1px solid var(--border); border-radius: 14px; background: var(--bg); color: var(--fg); }
25
+ .photo-viewer::backdrop { background: rgb(0 0 0 / 75%); }
26
+ .photo-panel { display: flex; flex-direction: column; max-height: calc(100dvh - 34px); }
27
+ .photo-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; }
28
+ .photo-stage { display: flex; align-items: center; justify-content: center; min-height: 0; height: 65dvh; background: #111; }
29
+ .md .photo-stage img { display: block; width: 100%; height: 100%; object-fit: contain; margin: 0; border-radius: 0; max-height: none; }
30
+ .photo-info { display: grid; gap: 2px; padding: 10px 16px 0; min-width: 0; overflow: auto; }
31
+ .photo-name, .photo-detail { overflow-wrap: anywhere; }
32
+ .photo-detail, .photo-status { color: var(--fg-soft); font-size: 13px; }
33
+ .photo-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; }
34
+ @media (max-width: 600px) {
35
+ .photo-album { padding: 10px; }
36
+ .album-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
37
+ .photo-viewer { width: calc(100% - 16px); max-height: calc(100dvh - 16px); }
38
+ .photo-panel { max-height: calc(100dvh - 18px); }
39
+ .photo-stage { height: 55dvh; }
40
+ }
@@ -95,6 +95,32 @@
95
95
  flex-wrap: wrap;
96
96
  }
97
97
 
98
+ /* 用户权限表单在整行下方展开,手机上也有足够的宽度。 */
99
+ .user-entry {
100
+ flex-direction: column;
101
+ align-items: stretch;
102
+ }
103
+
104
+ .user-entry-head {
105
+ display: flex;
106
+ align-items: center;
107
+ gap: 10px;
108
+ }
109
+
110
+ .user-entry-head > .row {
111
+ flex-shrink: 0;
112
+ }
113
+
114
+ .user-entry > div:empty {
115
+ display: none;
116
+ }
117
+
118
+ .user-permissions {
119
+ display: flex;
120
+ flex-direction: column;
121
+ gap: 12px;
122
+ }
123
+
98
124
  /* 用户列表:重置密码就地展开的输入框 */
99
125
  .user-reset {
100
126
  margin-top: 8px;
@@ -201,7 +201,7 @@ button.conv-group:hover {
201
201
  color: var(--fg);
202
202
  }
203
203
 
204
- /* 拖动目录排序:被拖的行变淡,落点处画一条横线 */
204
+ /* 项目 / 飞书分组拖动排序:被拖的行变淡,落点处画一条横线 */
205
205
  .proj-row.dragging {
206
206
  opacity: 0.4;
207
207
  }
package/web/index.html CHANGED
@@ -19,6 +19,7 @@
19
19
  <link rel="stylesheet" href="/css/sidebar.css" />
20
20
  <link rel="stylesheet" href="/css/topbar.css" />
21
21
  <link rel="stylesheet" href="/css/messages.css" />
22
+ <link rel="stylesheet" href="/css/albums.css" />
22
23
  <link rel="stylesheet" href="/css/loader.css" />
23
24
  <link rel="stylesheet" href="/css/composer.css" />
24
25
  <link rel="stylesheet" href="/css/overlay.css?v=2" />
@@ -0,0 +1,128 @@
1
+ import { h, icon } from "./dom.js";
2
+
3
+ // 相册只接收本地文件路径,沿用会话文件接口的授权、敏感路径检查;不接收远程地址或 HTML。
4
+ const PAGE_SIZE = 12;
5
+ const MAX_ITEMS = 200;
6
+ const fileUrl = (key, path) => `/api/conversations/${encodeURIComponent(key)}/file?path=${encodeURIComponent(path)}`;
7
+ const localPath = (p) => typeof p === "string" && p.startsWith("/") && !p.startsWith("//") && !/[\0\r\n]/.test(p);
8
+ const text = (v) => typeof v === "string" ? v : "";
9
+
10
+ function parseAlbum(source) {
11
+ let spec;
12
+ try { spec = JSON.parse(source); } catch { return "相册格式不完整或 JSON 有误"; }
13
+ if (!spec || !Array.isArray(spec.items) || spec.items.length > MAX_ITEMS) return `相册需要 items 列表,每次最多 ${MAX_ITEMS} 张`;
14
+ const items = [];
15
+ for (const item of spec.items) {
16
+ if (!item || !localPath(item.src) || (item.preview !== undefined && !localPath(item.preview))) return "相册图片需要使用已下载的本地绝对路径";
17
+ items.push({ src: item.src, preview: item.preview || item.src, name: text(item.name) || item.src.split("/").pop(), date: text(item.date), caption: text(item.caption) });
18
+ }
19
+ return { title: text(spec.title) || "相册", items, total: Number.isSafeInteger(spec.total) && spec.total >= items.length ? spec.total : items.length };
20
+ }
21
+
22
+ /** 回复里的 ```album:流式输出先占位,块完整后再渲染;key 固定为这条消息所属的会话。 */
23
+ export function mountAlbums(root, key, final) {
24
+ for (const code of root.querySelectorAll("pre > code.language-album")) {
25
+ const pre = code.parentElement;
26
+ if (!final) {
27
+ pre.replaceWith(h("div", { class: "photo-album album-pending", role: "status" }, "正在整理相册…"));
28
+ continue;
29
+ }
30
+ const spec = parseAlbum(code.textContent);
31
+ if (typeof spec === "string") {
32
+ pre.before(h("div", { class: "album-error", role: "status" }, spec));
33
+ continue;
34
+ }
35
+ pre.replaceWith(renderAlbum(spec, key));
36
+ }
37
+ }
38
+
39
+ function renderAlbum(spec, key) {
40
+ const { items, total } = spec;
41
+ const box = h("section", { class: "photo-album", "aria-label": spec.title });
42
+ const grid = h("div", { class: "album-grid" });
43
+ const status = h("span", { class: "album-page", "aria-live": "polite" });
44
+ let page = 0;
45
+ const pages = Math.ceil(items.length / PAGE_SIZE);
46
+ const prev = h("button", { class: "btn ghost", "aria-label": "相册上一页", onclick: () => showPage(page - 1) }, "上一页");
47
+ const next = h("button", { class: "btn ghost", "aria-label": "相册下一页", onclick: () => showPage(page + 1) }, "下一页");
48
+ const showPage = (n) => {
49
+ page = Math.max(0, Math.min(n, pages - 1));
50
+ grid.replaceChildren(...items.slice(page * PAGE_SIZE, (page + 1) * PAGE_SIZE).map((item, offset) => {
51
+ const index = page * PAGE_SIZE + offset;
52
+ const img = h("img", { src: fileUrl(key, item.src), alt: item.name, loading: "lazy", decoding: "async", width: "240", height: "240" });
53
+ const pic = h("span", { class: "album-pic" }, img);
54
+ img.onerror = () => pic.replaceChildren(h("span", { class: "album-missing" }, "图片无法加载"));
55
+ return h("button", {
56
+ class: "album-tile", "aria-label": `查看第 ${index + 1} 张:${item.name}`, title: [item.name, item.date, item.caption].filter(Boolean).join("\n"),
57
+ onclick: (e) => openPhoto(box, spec, key, index, e.currentTarget),
58
+ }, pic, h("span", { class: "album-name" }, item.name), item.date ? h("span", { class: "album-date" }, item.date) : null);
59
+ }));
60
+ status.textContent = `第 ${page + 1} / ${pages} 页`;
61
+ prev.disabled = page === 0;
62
+ next.disabled = page >= pages - 1;
63
+ // 切页后按钮仍然留在原位置,键盘焦点也留在原按钮上。
64
+ };
65
+ box.append(h("div", { class: "album-head" }, h("strong", {}, spec.title), h("span", {}, total > items.length ? `已载入 ${items.length} / 共 ${total} 张` : `共 ${items.length} 张`)));
66
+ if (!items.length) box.append(h("div", { class: "album-empty" }, "没有照片"));
67
+ else {
68
+ box.append(grid);
69
+ if (pages > 1) box.append(h("div", { class: "album-pager" }, prev, status, next));
70
+ showPage(0);
71
+ }
72
+ return box;
73
+ }
74
+
75
+ function openPhoto(album, spec, key, start, trigger) {
76
+ let index = start;
77
+ const dialog = h("dialog", { class: "photo-viewer", "aria-label": "照片预览" });
78
+ const image = h("img", { alt: "" });
79
+ const stage = h("div", { class: "photo-stage" }, image);
80
+ const name = h("strong", { class: "photo-name" });
81
+ const detail = h("span", { class: "photo-detail" });
82
+ const status = h("span", { class: "photo-status", role: "status" });
83
+ const count = h("span", { class: "photo-count", "aria-live": "polite" });
84
+ const open = h("a", { target: "_blank", rel: "noopener noreferrer" }, "打开图片");
85
+ const close = () => dialog.close();
86
+ const prev = h("button", { class: "btn ghost", "aria-label": "上一张照片", onclick: () => show(index - 1) }, "上一张");
87
+ const next = h("button", { class: "btn ghost", "aria-label": "下一张照片", onclick: () => show(index + 1) }, "下一张");
88
+ const show = (n) => {
89
+ index = Math.max(0, Math.min(n, spec.items.length - 1));
90
+ const item = spec.items[index];
91
+ const thumb = fileUrl(key, item.src);
92
+ const preview = fileUrl(key, item.preview);
93
+ status.textContent = "";
94
+ image.onerror = () => {
95
+ if (image.getAttribute("src") !== thumb) {
96
+ status.textContent = "预览不可用,显示缩略图";
97
+ image.src = thumb;
98
+ } else status.textContent = "图片无法加载,文件可能已被清理";
99
+ };
100
+ image.src = preview;
101
+ image.alt = item.name;
102
+ name.textContent = item.name;
103
+ detail.textContent = [item.date, item.caption].filter(Boolean).join(" · ");
104
+ count.textContent = `${index + 1} / ${spec.items.length}`;
105
+ open.href = preview;
106
+ prev.disabled = index === 0;
107
+ next.disabled = index === spec.items.length - 1;
108
+ };
109
+ dialog.append(h("div", { class: "photo-panel" },
110
+ h("div", { class: "photo-head" }, count, h("button", { class: "icon-btn", "aria-label": "关闭照片预览", onclick: close }, icon("x"))),
111
+ stage,
112
+ h("div", { class: "photo-info" }, name, detail, status),
113
+ h("div", { class: "photo-controls" }, prev, open, next),
114
+ ));
115
+ dialog.addEventListener("click", (e) => { if (e.target === dialog) close(); });
116
+ dialog.addEventListener("keydown", (e) => {
117
+ if (["ArrowLeft", "ArrowRight", "Escape"].includes(e.key)) e.stopPropagation();
118
+ if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
119
+ e.preventDefault();
120
+ show(index + (e.key === "ArrowRight" ? 1 : -1));
121
+ }
122
+ });
123
+ dialog.addEventListener("close", () => { dialog.remove(); if (trigger.isConnected) trigger.focus({ preventScroll: true }); });
124
+ // dialog 随相册一起移除,切换会话、重画流式块时不会留下全局监听器或悬空弹层。
125
+ album.append(dialog);
126
+ show(index);
127
+ dialog.showModal();
128
+ }
@@ -18,7 +18,7 @@ export function renderMarkdown(text, opts) {
18
18
  * 把 div 里的 markdown 更新成 text,只重画变了的块(段落、列表、代码块…)。
19
19
  * 流式输出时前面的块不再变,每帧只需重画最后一两块;选中的文字、代码块的横向滚动也不会被冲掉。
20
20
  * live = 还在输出:最后一块随时会变,先不高亮,等它定下来再高亮。
21
- * enhance(box):每块画好后再加工一下(比如把回复里的文件路径变成能点开的)。
21
+ * enhance(box, { final }):每块画好后再加工一下(比如把文件路径变成链接、完整相册块变成网格)。
22
22
  * 按块拼起来和整段解析的结果一样(marked 的 parser 本来就是逐块拼接的)。
23
23
  */
24
24
  export function patchMarkdown(div, text, { live = false, enhance } = {}) {
@@ -55,7 +55,7 @@ export function patchMarkdown(div, text, { live = false, enhance } = {}) {
55
55
  const box = document.createElement("div");
56
56
  box.innerHTML = DOMPurify.sanitize(marked.parser(chunk), { ADD_ATTR: ["target"] });
57
57
  decorate(box, final);
58
- enhance?.(box);
58
+ enhance?.(box, { final });
59
59
  const nodes = [...box.childNodes];
60
60
  div.append(...nodes);
61
61
  blocks.push({ raw: raws[i], final, nodes });
@@ -76,7 +76,7 @@ function decorate(root, highlight) {
76
76
  pre.prepend(h("div", { class: "code-head" }, h("span", {}, lang || "code"), copy));
77
77
  const diagram = diagramLang(code);
78
78
  if (diagram) mountDiagram(pre, code, diagram, highlight);
79
- else if (highlight) lazyHighlight.observe(code);
79
+ else if (highlight && lang !== "album") lazyHighlight.observe(code);
80
80
  }
81
81
  }
82
82
 
@@ -183,7 +183,7 @@ function builtinDefaultsSection() {
183
183
  sync();
184
184
  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
185
  };
186
- const panels = ["claude", "codex"].map((engine) => {
186
+ const panels = ["claude", "codex"].filter((engine) => data.agents[engine]).map((engine) => {
187
187
  const label = engine === "claude" ? "Claude Code" : "Codex";
188
188
  const prefs = data.agents[engine];
189
189
  const skills = picker(`${label} 技能`, data.skills, prefs.skills, "全部已启用的个人技能(含以后新增)");
@@ -198,6 +198,7 @@ function builtinDefaultsSection() {
198
198
  fill(section, h("h4", {}, "内置 Agent 默认加载"),
199
199
  h("p", { class: "skill-note" }, "仅影响你当前账号使用的内置 Agent;自定义专家继续使用各自的配置。保存后,下次发消息生效,正在执行的任务不受影响。"),
200
200
  ...panels,
201
+ !panels.length ? h("p", { class: "muted" }, "没有获授权的内置 Agent,请联系管理员配置使用权限。") : null,
201
202
  h("small", {}, "技能和 MCP 可分别全部取消。记忆、定时任务、技能管理等系统工具仍按功能设置提供。"),
202
203
  h("div", { class: "row" }, saveButton(async () => {
203
204
  const agents = Object.fromEntries(Object.entries(choices).map(([engine, c]) => [engine, { skills: c.skills.value(), machineSkills: c.machineSkills.checked, mcp: c.mcp.value() }]));
@@ -23,11 +23,13 @@ export async function accountTab(page) {
23
23
  };
24
24
  const old = h("input", { type: "password", autocomplete: "current-password" });
25
25
  const pw = h("input", { type: "password", autocomplete: "new-password" });
26
+ const name = h("input", { value: S.user?.name ?? "", autocomplete: "username", autocapitalize: "off", spellcheck: "false", maxlength: "32" });
27
+ const currentName = h("span", {}, S.user?.name ?? "");
26
28
  const devicesBox = h("div", { class: "section" }, h("h4", {}, "已登录的设备"), h("span", { class: "spinner" }));
27
29
  page.append(
28
30
  h(
29
31
  "div",
30
- { class: "section" },
32
+ { class: "section", "data-form": "" },
31
33
  h(
32
34
  "h4",
33
35
  {},
@@ -35,7 +37,14 @@ export async function accountTab(page) {
35
37
  h("span", { class: "grow" }),
36
38
  logout,
37
39
  ),
38
- S.user ? h("div", {}, S.user.name, " ", h("span", { class: "status-tag" }, S.user.role === "admin" ? "管理员" : "成员")) : null,
40
+ S.user ? h("div", {}, currentName, " ", h("span", { class: "status-tag" }, S.user.role === "admin" ? "管理员" : "成员")) : null,
41
+ field("账号名称", name, "也是登录时使用的用户名。1~32 个字符,可用文字、数字和 _ . @ -;修改后请用新名称登录。"),
42
+ h("div", { class: "row" }, saveButton(async () => {
43
+ const data = await api("/api/account", { method: "PATCH", body: { name: name.value.trim() } });
44
+ S.user = data.user;
45
+ name.value = currentName.textContent = data.user.name;
46
+ toast("账号名称已修改");
47
+ }, "保存账号名称")),
39
48
  ),
40
49
  h(
41
50
  "div",
@@ -6,6 +6,32 @@ import { field, saveButton } from "./common.js";
6
6
  import { networkSection } from "./general.js";
7
7
  import { deviceList } from "./security.js";
8
8
 
9
+ /** null 沿用全部;指定列表可以全部取消,新增资源不会自动加入。 */
10
+ function permissionFields(resources, permissions = {}) {
11
+ const pickers = {};
12
+ const el = h("div", { class: "user-permissions" });
13
+ for (const [kind, label] of [["experts", "共享专家"], ["agents", "内置 Agent"], ["servers", "服务器切换"]]) {
14
+ const selected = permissions[kind];
15
+ const items = resources?.[kind] ?? [];
16
+ const known = new Set(items.map((item) => item.id));
17
+ const missing = (selected ?? []).filter((id) => !known.has(id)).map((id) => ({ id, name: `${id}(暂不可用)` }));
18
+ const mode = h("select", { "aria-label": `${label}范围` },
19
+ h("option", { value: "all", selected: selected == null }, "全部允许(含以后新增)"),
20
+ h("option", { value: "pick", selected: selected != null }, "仅允许勾选项(可全部取消)"));
21
+ const inputs = [...items, ...missing].map((item) => ({ id: item.id, input: h("input", { type: "checkbox", checked: selected == null || selected.includes(item.id) }), name: item.name }));
22
+ const list = h("div", { class: "check-list" }, inputs.length
23
+ ? inputs.map(({ input, name }) => h("label", { class: "check-item" }, input, h("span", {}, name)))
24
+ : h("small", {}, kind === "servers" ? "尚未添加其他服务器" : "暂无可选项"));
25
+ const sync = () => { list.hidden = mode.value !== "pick"; };
26
+ mode.onchange = sync;
27
+ sync();
28
+ pickers[kind] = () => mode.value === "all" ? null : inputs.filter((x) => x.input.checked).map((x) => x.id);
29
+ el.append(h("div", { class: "field" }, h("span", {}, label), mode, list));
30
+ }
31
+ el.append(h("small", {}, "自己创建的专家仍可使用。内置 Agent 权限只控制直接使用 Claude Code / Codex,不影响已获授权的专家。当前服务器保持可用;其他服务器仍需各自登录,由对应服务器管理账号权限。"));
32
+ return { el, value: () => Object.fromEntries(Object.entries(pickers).map(([kind, value]) => [kind, value()])) };
33
+ }
34
+
9
35
  // ---------- 用户(管理员) ----------
10
36
 
11
37
  export async function usersTab(page) {
@@ -34,6 +60,17 @@ export async function usersTab(page) {
34
60
  };
35
61
  const patch = (u, body) => api(`/api/users/${encodeURIComponent(u.id)}`, { method: "PATCH", body });
36
62
 
63
+ const permissionsRow = (u, holder) => {
64
+ const picker = permissionFields(data.resources, u.permissions);
65
+ const save = saveButton(async () => {
66
+ await patch(u, { permissions: picker.value() });
67
+ toast(`已更新「${u.name}」的使用权限`);
68
+ reload();
69
+ }, "保存使用权限");
70
+ fill(holder, h("div", { "data-form": "" }, h("h4", {}, "使用权限"), picker.el,
71
+ h("div", { class: "row" }, save, h("button", { class: "btn", onclick: () => fill(holder) }, "取消"))));
72
+ };
73
+
37
74
  /** 重置密码:就地展开一个输入框 */
38
75
  const resetRow = (u, holder) => {
39
76
  const pw = h("input", { type: "password", autocomplete: "new-password", placeholder: "新密码(至少 8 位)" });
@@ -158,7 +195,8 @@ export async function usersTab(page) {
158
195
  const extra = h("div");
159
196
  return h(
160
197
  "div",
161
- { class: "list-item" },
198
+ { class: "list-item user-entry" },
199
+ h("div", { class: "user-entry-head" },
162
200
  h(
163
201
  "div",
164
202
  { class: "grow" },
@@ -173,9 +211,11 @@ export async function usersTab(page) {
173
211
  u.role !== "admin" && u.remote ? h("span", { class: "status-tag" }, "远程控制") : null,
174
212
  ),
175
213
  h("div", { class: "s" }, `创建于 ${relTime(u.createdAt)} · ${u.devices} 台设备已登录${u.feishuLinks ? ` · 绑定了 ${u.feishuLinks} 个飞书账号` : ""}`),
176
- extra,
177
214
  ),
178
- actions(u, self, extra),
215
+ h("div", { class: "row" },
216
+ u.role !== "admin" ? h("button", { class: "btn small", onclick: () => permissionsRow(u, extra) }, "使用权限") : null,
217
+ actions(u, self, extra))),
218
+ extra,
179
219
  );
180
220
  }),
181
221
  );
@@ -183,17 +223,29 @@ export async function usersTab(page) {
183
223
  const name = h("input", { autocomplete: "off", autocapitalize: "off", spellcheck: "false", placeholder: "登录用的名字" });
184
224
  const pw = h("input", { type: "password", autocomplete: "new-password", placeholder: "至少 8 位" });
185
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"; };
186
231
  fill(
187
232
  addBox,
188
233
  h("h4", {}, "添加用户"),
189
234
  field("用户名", name),
190
235
  field("密码", pw, "告诉对方,让他登录后在 设置 →「账号」里自己改掉"),
191
236
  field("角色", role, "成员只能用自己的对话;管理员能改所有设置、管理用户"),
237
+ memberOptions,
192
238
  h(
193
239
  "div",
194
240
  { class: "row" },
195
241
  saveButton(async () => {
196
- await api("/api/users", { method: "POST", body: { name: name.value.trim(), password: pw.value, role: role.value } });
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() } : {}) } });
197
249
  toast(`已添加「${name.value.trim()}」`);
198
250
  // 先标成已保存再刷新,免得离开提醒
199
251
  addBox.removeAttribute("data-dirty");
@@ -2,6 +2,7 @@ import { agentIcon, h } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { S } from "../state.js";
4
4
  import { agentLabel } from "./sidebar.js";
5
+ import { applyShellInfo } from "../lib/shell.js";
5
6
 
6
7
  // ---------- 专家:新对话、定时任务里选 ----------
7
8
  // 内置专家就是能用的 agent(Claude Code / Codex),自定义专家在「设置 → 专家」里建。
@@ -18,7 +19,7 @@ function usableEngines() {
18
19
  export function expertChoices() {
19
20
  const engines = usableEngines();
20
21
  return [
21
- ...engines.map((id) => ({ id, name: agentLabel(id), engine: id, builtin: true })),
22
+ ...engines.filter((id) => S.agents.find((a) => a.id === id)?.allowed !== false).map((id) => ({ id, name: agentLabel(id), engine: id, builtin: true })),
22
23
  ...S.experts.filter((e) => engines.includes(e.engine)),
23
24
  ];
24
25
  }
@@ -66,6 +67,9 @@ export async function reloadExperts() {
66
67
  try {
67
68
  const d = await api("/api/experts/brief");
68
69
  S.experts = d.experts ?? [];
70
+ if (Array.isArray(d.builtin)) for (const a of S.agents) a.allowed = d.builtin.includes(a.id);
71
+ if (d.user) S.user = d.user;
72
+ if ("servers" in d) applyShellInfo(d.servers);
69
73
  } catch {
70
74
  // 拉不到就先用旧的
71
75
  }
@@ -5,6 +5,7 @@ import { h, icon, starsLoader, toast } from "../lib/dom.js";
5
5
  import { api } from "../lib/api.js";
6
6
  import { renderMarkdown } from "../lib/markdown.js";
7
7
  import { S } from "../state.js";
8
+ import { mountAlbums } from "../lib/albums.js";
8
9
 
9
10
  const fileUrl = (key, p, extra = "") =>
10
11
  `/api/conversations/${encodeURIComponent(key)}/file?path=${encodeURIComponent(p)}${extra}`;
@@ -80,11 +81,13 @@ function fileLink(key, p, ...children) {
80
81
  }
81
82
 
82
83
  /** patchMarkdown 的 enhance:把一块回复里的文件路径(链接、行内代码、正文里的绝对路径、图片)变成能点开的 */
83
- export function linkReplyFiles(box) {
84
+ export function linkReplyFiles(box, { final = true } = {}) {
84
85
  const key = S.current;
85
86
  if (!key) return;
87
+ mountAlbums(box, key, final);
86
88
  embedVisualizations(box, key);
87
89
  for (const a of box.querySelectorAll("a[href]")) {
90
+ if (a.closest(".photo-album")) continue;
88
91
  const p = hrefPath(a.getAttribute("href"));
89
92
  if (!p) continue;
90
93
  a.replaceWith(fileLink(key, p, ...a.childNodes));
@@ -95,6 +98,7 @@ export function linkReplyFiles(box) {
95
98
  if (p) code.replaceWith(fileLink(key, p, code.cloneNode(true)));
96
99
  }
97
100
  for (const img of box.querySelectorAll("img[src]")) {
101
+ if (img.closest(".photo-album")) continue;
98
102
  const p = hrefPath(img.getAttribute("src"));
99
103
  if (!p) continue;
100
104
  const alt = img.getAttribute("alt") || p.split("/").pop();
@@ -110,7 +114,7 @@ export function linkReplyFiles(box) {
110
114
 
111
115
  function linkTextPaths(box, key) {
112
116
  const walker = document.createTreeWalker(box, NodeFilter.SHOW_TEXT, {
113
- acceptNode: (n) => (n.parentElement?.closest("pre, code, a") ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT),
117
+ acceptNode: (n) => (n.parentElement?.closest("pre, code, a, .photo-album") ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT),
114
118
  });
115
119
  const nodes = [];
116
120
  for (let n = walker.nextNode(); n; n = walker.nextNode()) if (n.nodeValue.includes("/")) nodes.push(n);
@@ -8,11 +8,12 @@ import {
8
8
  bootstrapQuery,
9
9
  closeSide,
10
10
  marquee,
11
- moveProjectDir,
12
- projDirs,
11
+ botGroupId,
12
+ moveSidebarGroup,
13
+ sidebarGroups,
13
14
  renderSidebar,
14
15
  reportDesktop,
15
- resetProjectOrder,
16
+ resetSidebarGroupOrder,
16
17
  setSideWidth,
17
18
  startMarquee,
18
19
  startSideResize,
@@ -232,23 +233,19 @@ function renderLayout() {
232
233
  lastDown = { key, at: now };
233
234
  });
234
235
  ui.convList.addEventListener("contextmenu", (e) => {
235
- // 飞书机器人那一行:右键看这个机器人的所有聊天
236
+ // 项目和飞书共用移动菜单;触屏也可以通过长按调整混合顺序。
236
237
  const bot = e.target.closest?.("[data-bot]")?.dataset.bot;
237
- if (bot) {
238
- e.preventDefault();
239
- showMenu({ x: e.clientX, y: e.clientY }, [{ label: "历史会话…", onclick: () => openBotConversations(bot) }]);
240
- return;
241
- }
242
- // 项目目录那一行:调整顺序(触屏上拖不动,靠这个菜单)
243
238
  const dir = e.target.closest?.("[data-dir]")?.dataset.dir;
244
- if (dir) {
245
- const i = projDirs.indexOf(dir);
239
+ const group = bot ? botGroupId(bot) : dir;
240
+ if (group) {
241
+ const i = sidebarGroups.indexOf(group);
246
242
  const moves = [
247
- ...(i > 0 ? [{ label: "置顶", onclick: () => moveProjectDir(dir, null) }, { label: "上移", onclick: () => moveProjectDir(dir, projDirs[i - 1]) }] : []),
248
- ...(i >= 0 && i < projDirs.length - 1 ? [{ label: "下移", onclick: () => moveProjectDir(dir, projDirs[i + 1], true) }] : []),
243
+ ...(i > 0 ? [{ label: "置顶", onclick: () => moveSidebarGroup(group, null) }, { label: "上移", onclick: () => moveSidebarGroup(group, sidebarGroups[i - 1]) }] : []),
244
+ ...(i >= 0 && i < sidebarGroups.length - 1 ? [{ label: "下移", onclick: () => moveSidebarGroup(group, sidebarGroups[i + 1], true) }] : []),
249
245
  ];
250
- const reset = projDirs.length > 1 ? [{ label: "按最近活跃重排", onclick: resetProjectOrder }] : [];
246
+ const reset = sidebarGroups.length > 1 ? [{ label: "按最近活跃重排", onclick: resetSidebarGroupOrder }] : [];
251
247
  const items = moves.length && reset.length ? [...moves, "sep", ...reset] : [...moves, ...reset];
248
+ if (bot) items.push(...(items.length ? ["sep"] : []), { label: "历史会话…", onclick: () => openBotConversations(bot) });
252
249
  if (!items.length) return;
253
250
  e.preventDefault();
254
251
  showMenu({ x: e.clientX, y: e.clientY }, items);