agent-loft 0.2.68 → 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.
package/README.md CHANGED
@@ -28,7 +28,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
28
28
  | 🤖 | **同时管理多个 agent** | Claude Code(官方 Claude Agent SDK)和 Codex(官方 `codex app-server`)共用会话列表、工作目录和授权。新建对话时选专家:内置的 Claude Code / Codex,或者自己配的专家 |
29
29
  | 🧑‍🏫 | **专家** | 自己配专家:选引擎、写提示词,定它能做什么(只能联网 / 读文件 / 改文件 / 跑命令),挂哪些技能和 MCP,能把活派给哪些子智能体。新对话、定时任务都能选 |
30
30
  | 🔀 | **飞书机器人灵活绑定 agent** | 机器人数量不限,每个机器人可以直接勾选内置或共享专家,并选择默认专家(可在会话里切换)。网页上扫码就能创建,改完立即生效;由服务端主动连向飞书,家里没有公网 IP 也能在外面用 |
31
- | 🔗 | **飞书续接 Web 任务** | 飞书里发 `/web` 接上一条 Web 会话,或者在网页侧栏右键会话选「在飞书继续…」。之后回复、授权、提问都发到飞书,发 `/detach` 回来 |
31
+ | 🔗 | **飞书续接 Web 任务** | 飞书里发 `/web` 接上一条 Web 会话,或者在网页聊天右上角「更多」或侧栏会话右键菜单里选「在飞书继续」。之后回复、授权、提问都发到飞书,发 `/detach` 回来 |
32
32
  | 🖥️ | **完整的 Web 工作台** | 流式回复、附件、语音输入、模型和思考程度切换、上下文占用、从任意回复分叉、按项目分组的侧栏、搜索会话、全部设置,电脑和手机(PWA)都能用 |
33
33
  | 🔔 | **飞书 + 苹果系统推送** | 除了飞书消息,Web 会话还能推送到 iPhone、iPad 锁屏和 Mac 通知中心(标准 Web Push,不需要开发者账号),图标上显示未读数 |
34
34
  | 🗂️ | **桌面端同时接入多台设备** | 桌面端(macOS / Windows / Linux)同时连多台服务器,菜单栏 / 托盘一眼看完各台的额度、待处理和运行中的会话 |
@@ -47,6 +47,8 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
47
47
  - 附件:粘贴、拖拽,手机上可以拍照;可以预览和下载。附件存在服务端的专用上传目录里,发出去的都收进资料库,开新会话、切换目录也不删。
48
48
  - 回复里提到的文件(链接、`路径`、正文里的绝对路径,Claude 和 Codex 都认)点一下就能预览:图片、PDF、音视频、markdown、代码和文本直接看,网页渲染出来看(也能切到源码),其它的下载。Codex 的 visualize 插件画的图表(回复里的 `visualize{"path":…}`)和官方客户端一样直接嵌在回复里。网页和图表放在沙箱里显示,碰不到登录态和本站接口。
49
49
  - **回复里的图**:专家和 agent 在回复里写 ```` ```chart ````(一段 JSON:折线、面积、柱状、饼图、散点)就画成可悬停的图,可以切到表格看具体数字;写 ```` ```mermaid ```` 画流程图、时序图等。跟着系统深浅色走,图库用到时才加载;飞书上 chart 换成表格。写法自动附在每个专家(包括内置的 Claude Code、Codex)的提示词里。只认这条对话里 agent 回复写过的路径;私钥、`.ssh`、`.env`、各种凭据和 agent-loft 自己的配置数据一律不给看。
50
+ - **回复里的相册**:agent 用 ```` ```album ```` JSON 描述多张本地照片,网页显示缩略图网格,每页 12 张、懒加载;点开大图可左右切换,也支持方向键和 Esc。可附名称、拍摄日期、说明和查询总数,每个相册最多 200 张;飞书显示简短摘要。写法自动附在所有专家的提示词里,图片沿用会话文件权限。
51
+ - 聊天右上角「更多」和侧栏会话右键菜单共用分叉、重命名、在飞书继续、删除操作,按会话类型和可用机器人显示。
50
52
  - 语音输入:用浏览器自带的语音识别(Chrome / Edge / Safari,需要 HTTPS)。
51
53
  - 新对话页:点大标题里的目录名,在固定高度的目录弹窗里逐层选工作目录,也能新建文件夹;输入框上方选专家,鼠标停在专家上看简介,右下角选模型和思考程度。对话从头到尾一个专家,要换专家就新建对话;模型和思考程度随时可换。
52
54
  - 输入框里的小圆环显示上下文窗口占用;模型按钮显示实际的模型和思考程度(如「Opus 5.5 high」)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-loft",
3
- "version": "0.2.68",
3
+ "version": "0.2.69",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -8,6 +8,7 @@ import { createEnvelope, type CardCtx, type EnvelopeAction } from "./envelope.js
8
8
  import { answerTextOf, SETTLEMENT_LABEL, type Interaction } from "../../core/interactions.js";
9
9
  import { usageOf, type CommandEntry } from "../../core/command-catalog.js";
10
10
  import { chartsToTables } from "../../core/charts.js";
11
+ import { albumsToText } from "../../core/albums.js";
11
12
  import type { ModelInfo, SessionSummary } from "../../core/types.js";
12
13
 
13
14
  function button(
@@ -174,9 +175,9 @@ export function progressCard(params: { steps: string[]; done?: boolean; footer?:
174
175
  ]);
175
176
  }
176
177
 
177
- /** 回复卡:飞书纯文本不渲染 markdown,所以回复必须走卡片。刻意做到最简。```chart 画不了,换成表格 */
178
+ /** 回复卡:飞书纯文本不渲染 markdown,所以回复走卡片。图表换成表格,相册换成摘要。 */
178
179
  export function replyCard(text: string) {
179
- return card([{ tag: "markdown", content: clip(chartsToTables(text), 4000) }]);
180
+ return card([{ tag: "markdown", content: clip(chartsToTables(albumsToText(text)), 4000) }]);
180
181
  }
181
182
 
182
183
  // ---------- 命令结果 ----------
@@ -0,0 +1,49 @@
1
+ // 回复里的 ```album:网页显示为相册;飞书降级为摘要。JSON 里的文件路径也算显式引用。
2
+ const FENCE = /^ {0,3}(`{3,}|~{3,})[ \t]*album[ \t]*\r?\n([\s\S]*?)\r?\n {0,3}\1[ \t]*$/gim;
3
+ type Photo = { src: string; preview?: string; name?: string; date?: string; caption?: string };
4
+ type Album = { title?: string; total: number; items: Photo[] };
5
+ const localPath = (p: unknown): p is string => typeof p === "string" && p.startsWith("/") && !p.startsWith("//") && !/[\0\r\n]/.test(p);
6
+ const str = (v: unknown): string | undefined => typeof v === "string" ? v : undefined;
7
+
8
+ function parseAlbum(json: string): Album | undefined {
9
+ try {
10
+ const raw = JSON.parse(json);
11
+ if (!raw || !Array.isArray(raw.items) || raw.items.length > 200) return;
12
+ const items: Photo[] = [];
13
+ for (const item of raw.items) {
14
+ if (!item || !localPath(item.src) || (item.preview !== undefined && !localPath(item.preview))) return;
15
+ items.push({ src: item.src, preview: item.preview, name: str(item.name), date: str(item.date), caption: str(item.caption) });
16
+ }
17
+ return { title: str(raw.title), total: Number.isSafeInteger(raw.total) && raw.total >= items.length ? raw.total : items.length, items };
18
+ } catch { return; }
19
+ }
20
+
21
+ /** JSON 转义过的中文、反斜杠等路径也能匹配;不放宽原有的会话文件权限。 */
22
+ export function albumReferences(text: string): { text: string; paths: string[] } {
23
+ const paths: string[] = [];
24
+ if (!/album/i.test(text)) return { text, paths };
25
+ const rest = text.replace(FENCE, (whole, _fence: string, json: string) => {
26
+ const album = parseAlbum(json);
27
+ if (!album) return whole;
28
+ for (const item of album.items) paths.push(item.src, ...(item.preview ? [item.preview] : []));
29
+ return "";
30
+ });
31
+ return { text: rest, paths };
32
+ }
33
+
34
+ const plain = (s: string) => s.replace(/[\r\n]/g, " ").replace(/[\\`*_{}[\]()<>!|#]/g, "\\$&").slice(0, 200);
35
+
36
+ /** 飞书不展示整段 JSON、服务器路径或数百条图片,只保留相册概况。 */
37
+ export function albumsToText(text: string): string {
38
+ if (!/album/i.test(text)) return text;
39
+ return text.replace(FENCE, (whole, _fence: string, json: string) => {
40
+ const album = parseAlbum(json);
41
+ if (!album) return whole;
42
+ const { items, total } = album;
43
+ const lines = [`**${plain(album.title || "相册")}** · 共 ${total} 张${total > items.length ? `(已载入 ${items.length} 张)` : ""}`];
44
+ for (const [i, item] of items.slice(0, 12).entries()) lines.push(`${i + 1}. ${[item.name || `照片 ${i + 1}`, item.date, item.caption].filter(Boolean).map((v) => plain(v!)).join(" · ")}`);
45
+ if (items.length > 12) lines.push(`还有 ${items.length - 12} 张。`);
46
+ lines.push(items.length ? "请在 Web 中打开相册查看照片。" : "没有照片。");
47
+ return lines.join("\n");
48
+ });
49
+ }
@@ -65,8 +65,8 @@ function persona(expert: PromptExpert): string[] {
65
65
  }
66
66
 
67
67
  /**
68
- * 回复里能画的图:网页把 ```chart / ```mermaid 画出来(web/lib/diagrams.js),飞书把 chart 换成表格(core/charts.ts)。
69
- * 所有专家、内置的 Claude Code / Codex 都给。格式改了这三处要一起改。
68
+ * 回复里的富内容:网页画图表和相册,飞书把图表换成表格、相册换成摘要。
69
+ * 所有专家、内置的 Claude Code / Codex 都给;格式改了,对应的 Web 渲染和飞书降级也要一起改。
70
70
  */
71
71
  export const RICH_REPLY_LINES = [
72
72
  "## 回复里的图表",
@@ -80,6 +80,16 @@ export const RICH_REPLY_LINES = [
80
80
  " - 一张图最多 8 组数据,饼图最多 8 块;量级差很多的两种数据分成两张图;缺的数据写 null。只写合法 JSON,不要注释,不要省略号。",
81
81
  "- 流程、时序、状态、结构关系可以用 ```mermaid 代码块画图。",
82
82
  "- 只在图比文字更清楚时才画;几个数字用文字或表格就够了。",
83
+ "",
84
+ "## 回复里的相册",
85
+ "",
86
+ "- 展示多张照片、图片搜索结果时,用 ```album JSON 代码块,Web 会显示缩略图网格、分页和大图预览,飞书显示摘要。例如:",
87
+ " ```album",
88
+ ' {"title":"家庭相片","total":30,"items":[{"src":"/tmp/photos/thumb.webp","preview":"/tmp/photos/preview.jpg","name":"海边合影","date":"2026-10-31","caption":"香港"}]}',
89
+ " ```",
90
+ "- items 每项 src 是已下载缩略图的本地绝对路径;preview 是可选的已下载大图路径,省略时预览缩略图。name、date、caption 可选。total 可选,表示查询结果总数,不能小于 items 数量。",
91
+ "- 每个相册最多 200 张,Web 每页 12 张。只填实际取得的照片和路径,不编造;不要批量下载原图。需要清晰预览时,只为相关照片下载 preview。",
92
+ "- 路径直接写在 JSON 字符串里,不做 URL 编码;不要填远程 URL、API 密钥或 auth_code。图片仍受当前会话的文件权限控制。多张照片优先用相册,单张图片可继续用 Markdown。",
83
93
  ];
84
94
 
85
95
  /** Claude 自定义专家的整段系统提示(lean:换掉 Claude Code 原装的) */
@@ -7,6 +7,7 @@ import os from "node:os";
7
7
  import path from "node:path";
8
8
  import { home } from "../home.js";
9
9
  import { uploadsRoot } from "./uploads.js";
10
+ import { albumReferences } from "./albums.js";
10
11
 
11
12
  /** 路径里出现这些目录名就不给看(私钥、云凭据、密码库…) */
12
13
  const SENSITIVE_DIRS = new Set([".ssh", ".gnupg", ".aws", ".azure", ".kube", ".docker", ".password-store", ".gcloud"]);
@@ -100,7 +101,9 @@ const PATH_CHAR = /[\p{L}\p{N}_\-./~@+]/u;
100
101
  export function mentions(text: string, p: string): boolean {
101
102
  const needle = p.trim();
102
103
  if (!needle) return false;
103
- const hay = withDecoded(text);
104
+ const refs = albumReferences(text);
105
+ if (refs.paths.includes(needle)) return true;
106
+ const hay = withDecoded(refs.text);
104
107
  for (let i = hay.indexOf(needle); i >= 0; i = hay.indexOf(needle, i + 1)) {
105
108
  const before = hay[i - 1];
106
109
  const after = hay[i + needle.length];
@@ -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
+ }
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
 
@@ -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);
@@ -146,6 +146,8 @@ function topMenuItems() {
146
146
  const items = [];
147
147
  if (!S.view) {
148
148
  items.push({ id: "schedule", label: "定时发送", icon: "clock", onclick: () => openSchedule() });
149
+ const actions = convMenuItems(S.current);
150
+ if (actions.length) items.push("sep", ...actions);
149
151
  }
150
152
  return items;
151
153
  }
@@ -163,7 +165,7 @@ function openTopMore(anchor) {
163
165
  ? h("div", { class: "sep" })
164
166
  : h(
165
167
  "button",
166
- { class: `pop-item${it.checked ? " on" : ""}`, onclick: () => (closeMenu(), it.onclick()) },
168
+ { class: `pop-item${it.checked ? " on" : ""}${it.danger ? " danger" : ""}`, onclick: () => (closeMenu(), it.onclick()) },
167
169
  icon(it.icon),
168
170
  h("span", { class: "grow" }, it.label),
169
171
  it.checked ? h("span", { class: "check" }, "✓") : null,
@@ -473,13 +475,15 @@ export function updateCtxVisibility() {
473
475
  if (ui.ctxBar) ui.ctxBar.hidden = !!S.current && (S.items.length > 0 || sentKeys.has(S.current));
474
476
  }
475
477
 
476
- /** 侧栏会话的右键菜单:分叉 / 重命名 / 删除 */
477
- export function openConvContextMenu(key, at) {
478
+ /** 顶栏和侧栏共用的会话操作,显示条件和行为保持一致。 */
479
+ function convMenuItems(key) {
478
480
  const c = S.convs.get(key);
479
- if (!c) return;
480
- showMenu(at, [
481
+ if (!c) return [];
482
+ return [
481
483
  {
484
+ id: "fork",
482
485
  label: "分叉",
486
+ icon: "fork",
483
487
  onclick: async () => {
484
488
  if (c.canFork) return forkConversation(undefined, key);
485
489
  // 不支持另开一条的:只能在原对话里分叉,先切过去
@@ -487,10 +491,16 @@ export function openConvContextMenu(key, at) {
487
491
  await doAction("fork");
488
492
  },
489
493
  },
490
- { label: "重命名", onclick: () => renameConv(key) },
491
- ...(c.channel === "web" && S.bots.length > 0 ? [{ label: "在飞书继续…", onclick: () => continueInFeishu(key) }] : []),
492
- ...(c.channel === "web" ? [{ label: "删除", danger: true, onclick: () => deleteConv(key) }] : []),
493
- ]);
494
+ { id: "rename", label: "重命名", icon: "edit", onclick: () => renameConv(key) },
495
+ ...(c.channel === "web" && S.bots.length > 0 ? [{ id: "feishu", label: "在飞书继续", icon: "feishu", onclick: () => continueInFeishu(key) }] : []),
496
+ ...(c.channel === "web" ? [{ id: "delete", label: "删除", icon: "trash", danger: true, onclick: () => deleteConv(key) }] : []),
497
+ ];
498
+ }
499
+
500
+ /** 侧栏会话的右键菜单 */
501
+ export function openConvContextMenu(key, at) {
502
+ const items = convMenuItems(key);
503
+ if (items.length) showMenu(at, items);
494
504
  }
495
505
 
496
506
  /**