agent-loft 0.2.68 → 0.2.70
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 +4 -2
- package/package.json +1 -1
- package/src/channels/feishu/cards.ts +3 -2
- package/src/channels/web/skills-api.ts +1 -0
- package/src/core/albums.ts +49 -0
- package/src/core/expert-prompt.ts +12 -2
- package/src/core/reply-files.ts +4 -1
- package/src/core/skills.ts +1 -2
- package/web/css/albums.css +40 -0
- package/web/css/skills.css +4 -1
- package/web/index.html +1 -0
- package/web/lib/albums.js +128 -0
- package/web/lib/markdown.js +3 -3
- package/web/settings/skills.js +129 -21
- package/web/views/file-preview.js +6 -2
- package/web/views/topbar.js +19 -9
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
|
|
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」)。
|
|
@@ -86,7 +88,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
|
|
|
86
88
|
- **MCP**:设置 → MCP,每人管自己的:本机进程(命令 + 参数 + 环境变量)或 HTTP 地址(+ 请求头),值可以标成密钥(网页上不回显,只交给 MCP 进程或请求头,不进提示词)。可以设「调用前询问」,不设就直接用。自定义专家加载各自勾选的服务;内置专家在「设置 → Agent → 内置 Agent 默认加载」里选择,支持个人 MCP、管理员可选的机器 MCP,也可全部取消;不指定时管理员沿用机器配置。
|
|
87
89
|
- **记忆**:像 ChatGPT 的记忆,设置 → 记忆(默认关)。「关于我」加上一条条记住的事,每次对话都带上;agent 在聊天里遇到长期有用的信息会自己用 `remember` 记一条(回复里会说),记错了用 `forget` 删。**自动整理**:把上次整理之后新说的话交给模型(不留会话记录的一次性调用),补充、更新或删掉过时的记忆,用户自己加的条目它不动。什么时候整理每个人自己定:每天一次(默认凌晨 2 点,把当天的对话合起来一次整理,最省)/每段对话聊完后(停多久可选,改了什么会在对话里说一声)/只在点「现在整理」时/不整理;整理哪些对话也能选:全部/只整理选中专家的对话;用哪个 agent 的哪个模型也能选,默认 Claude Haiku,没有 Claude 就用 Codex 的默认模型、思考程度 low。**参考以前的聊天**:agent 遇到「上次说的那个……」会用 `search_past_chats` 搜你以前的对话(关键词搜索,只有你自己的、没被删掉的对话)。聊天记录索引不开记忆也会记(侧栏的「搜索」也用它),升级后会把已有对话收录进来一次;没开记忆时记进来的不拿去整理。两项都能在设置里单独关。每个用户一份,Claude 和 Codex、Web 和飞书共用。只用在有主人的对话里:你的 Web 对话,以及绑定了飞书账号后和机器人的私聊;飞书群聊不用。别人(包括管理员)看不到你的记忆,管理员只能清空它;删用户时记忆一起删,不转给管理员。
|
|
88
90
|
- **定时任务**:像 ChatGPT 的 Tasks,侧栏的「定时任务」。到点把一段提示词交给 agent,结果发回对话:一次 / 每天 / 工作日 / 每周 / 每月 / 每隔几小时 / 自定义 cron,按服务端时区,两次至少隔 15 分钟。**有需要才提醒**(默认):agent 自己判断这次有没有要告诉你的事(比如「有新版本才告诉我」),没有就在回复第一行写 `[[静默]]`,推送、飞书都不发,对话里折叠成一行;没写暗号一律照常提醒。结果发到**专用对话**(任务自己的一条对话,第一次运行时新建、之后续用,可选专家和目录),或者**原来的对话**。也能直接在对话里说「每天早上 9 点帮我……」:agent 用 `create_task` / `update_task` / `delete_task` / `list_tasks` 工具管理,新建、修改、删除都会先弹授权卡让你确认(只有暂停不用;没有「总是允许」),任务自己运行的那一轮里不能再建、改、删任务。按人隔离:每人只看得到、改得了自己的任务(最多 30 个),删用户时一起删;到点再核对一次对话还是不是他的,对话被删或换了主人就暂停任务。到点对话在忙(正在回复或挂着授权)就等它,最多 30 分钟;服务停着时错过 2 小时以内的启动后补跑一次。工具和记忆一样只给有主人的对话,飞书群聊里没有。
|
|
89
|
-
- **技能(skills)**:设置 → 技能。技能就是 Claude Code / Codex 用的那种 SKILL.md(可以带脚本和资料),由 agent-loft 按人管理,两个 agent 都能用。**来源**:在页面上写、上传技能包(`.zip` / `.skill` / 单个 SKILL.md / 整个文件夹),或者在对话里让 agent「把刚才的做法存成技能」(agent 用 `create_skill` / `update_skill
|
|
91
|
+
- **技能(skills)**:设置 → 技能。技能就是 Claude Code / Codex 用的那种 SKILL.md(可以带脚本和资料),由 agent-loft 按人管理,两个 agent 都能用。**来源**:在页面上写、上传技能包(`.zip` / `.skill` / 单个 SKILL.md / 整个文件夹),或者在对话里让 agent「把刚才的做法存成技能」(agent 用 `create_skill` / `update_skill`,先弹授权卡)。**共享**:新建、编辑时选择「仅自己可见」「指定用户」或「所有人可见」,也可在自己技能的「更多 → 共享」里调整;默认仅自己可见。其他用户在「共享技能」中查看正文和附带文件、安装;安装后出现在「我的技能」,可停用、卸载或重新安装。安装的是作者的同一份技能,更新自动跟随;作者撤回共享后,范围外用户不再可用。只有作者能编辑,管理员可下架自己看得到的共享技能。共享不包含作者填写的变量和密钥,每人使用自己的配置。**使用**:内置专家默认使用你启用的全部技能,也可以在「设置 → Agent」中分别指定 Claude Code / Codex 加载哪些技能;自定义专家只用它选中的;agent 遇到对得上的事自己用。**变量**:技能可以声明要用的环境变量(接口地址、密钥),每个人填自己的值,只注入自己的会话;密钥再写上「只允许发往」的地址就成了**受保护的密钥**——不进环境变量,agent 看不到值,只能用 `skill_request` 工具让 agent-loft 代发请求(在地址、请求头、请求体里写 `{{变量名}}`),只发往你确认过的地址、不跟随跳转、响应里出现的值会被抹掉;作者后来改了地址,要你再确认一次才放行。**机器上原有的技能**(`~/.claude/skills`、`~/.agents/skills`、插件市场和 claude.ai 同步的)只给管理员:成员的会话里看不到、调不了(Claude 用技能白名单,`/技能名` 也会被拦下;Codex 关掉它自己的技能清单),管理员在「设置 → 技能 → 本机技能」里能看到。
|
|
90
92
|
- **资料库**:像 ChatGPT 的资料库,侧栏的「资料库」。对话里发过的附件、agent 回复里给出的、这一轮新写出来的图片 / 文档 / 音视频(复制一份收进来,之后原文件改了删了不影响)都汇总在这里:按图片 / 文档 / 音视频筛、按文件名搜,点开看大图或下载,「在新对话里用」,单个或批量删除(文件从磁盘上删掉)。输入框的「+」也能「从资料库选」。从资料库拿到对话里的文件硬链接进那条对话的上传目录,不占双份空间,agent 照常能读。按人隔离,规则同对话:自己的;没主人的对话(飞书群聊等)的归管理员。上传了一直没发出去的一天后清掉,对话被删的连同文件一起删。
|
|
91
93
|
- **远程控制**:侧栏「定时任务」下面的「远程控制」,直接操作这台机器的**桌面**和**终端**,上面一键切换;切回对话时连接留在后台(侧栏入口上亮个小绿点),再进来接着用。这台机器没有图形桌面(服务器、NAS)时只有终端。
|
|
92
94
|
- 桌面:走 VNC 协议,网页里用 noVNC 显示,鼠标、键盘、剪贴板都能用,进来时不自动连、点「连接桌面」才连,工具栏上选画质:流畅 / 标准(默认)/ 高清由服务端把画面缩小到长边 1280 / 1920 / 2560、只把变了的地方压成 JPEG 发过来(macOS 屏幕共享只给无损的 ZRLE,5K 屏一整屏 30MB,原样转发隔着公网几秒一帧),原画是原样转发、只适合局域网;远程那边接了几块屏时可以只看其中一块(按系统里的显示器名称选,服务端只截那块再缩,比几块屏拼在一起缩小清楚得多;macOS 的各块屏位置要从屏幕共享发来的画面里学,第一次连上要几秒,原画下不能选);可以缩放到窗口或按原始大小看、全屏(手机上也能,iPhone 上是铺满页面)、「只看不控制」、发送 Ctrl+Alt+Del 之类的组合键。手机上有两种手势(右上角切换,「?」看说明):**触控板模式**(默认)屏幕上有个指针,单指滑动移动、轻点单击、双指轻点右键、长按后拖动是按住左键拖、双指滑动滚动;**触摸模式**点哪就点哪。两种模式都能双指捏合在本地放大画面(放大后小按钮也点得准,右下角「还原」),画面下面一排 Esc / Tab / Ctrl / Alt / Win / 方向键,Ctrl、Alt、Win 点一下会粘住,带给下一个按键或点击;键盘按钮弹出软键盘打字,中文输入法也能用。Linux 上 agent-loft 在有人连时用 x11vnc 共享当前的桌面(Xorg 会话;只听 127.0.0.1、随机端口、每次随机密码,需要 `sudo apt install x11vnc`),没人连着 30 分钟后停掉;macOS 上在 设置 → 远程控制 里改用「已有的 VNC 服务」,接系统自带的屏幕共享:填 VNC 密码,或者屏幕共享没开 VNC 密码时填 Mac 的用户名和登录密码(苹果认证,由服务端登录)。
|
package/package.json
CHANGED
|
@@ -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
|
|
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
|
// ---------- 命令结果 ----------
|
|
@@ -194,6 +194,7 @@ export async function handleSkillsApi(req: IncomingMessage, res: ServerResponse,
|
|
|
194
194
|
return true;
|
|
195
195
|
}
|
|
196
196
|
if (!m[2] && method === "PATCH") {
|
|
197
|
+
if (skill.owner !== user.id) throw new HttpError(403, "只有作者能修改技能内容和共享范围");
|
|
197
198
|
const body = await readJsonBody<SkillInput & { upload?: UploadBody }>(req, 16 * 1024 * 1024);
|
|
198
199
|
let updated: Skill;
|
|
199
200
|
try {
|
|
@@ -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
|
-
*
|
|
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 原装的) */
|
package/src/core/reply-files.ts
CHANGED
|
@@ -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
|
|
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];
|
package/src/core/skills.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// 技能(skill):一份 SKILL.md 加上它附带的脚本、资料,agent 需要时照着做。和 Claude Code / Codex 自己的
|
|
2
2
|
// skill 是同一种格式,只是由 agent-loft 按人管理:
|
|
3
3
|
// - 谁都能建(网页上写、上传技能包,或者让 agent 在对话里生成),建的人是作者;
|
|
4
|
-
// - 作者决定谁看得到:只有自己 / 指定的几个人 /
|
|
5
|
-
// (新建的都是仅自己),这套数据留着是为了以前分享、安装过的照常能用;
|
|
4
|
+
// - 作者决定谁看得到:只有自己 / 指定的几个人 / 所有人,看得到的人可在网页「共享技能」中安装;
|
|
6
5
|
// - 安装的是作者那一份本身,不是副本:作者改了,装了的人下一条消息起就用上新的;
|
|
7
6
|
// - 技能可以声明要用的环境变量(API 地址、密钥之类),值由每个用户自己填,只注入到他自己的会话里。
|
|
8
7
|
//
|
|
@@ -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/css/skills.css
CHANGED
|
@@ -318,6 +318,8 @@
|
|
|
318
318
|
display: flex;
|
|
319
319
|
flex-wrap: wrap;
|
|
320
320
|
gap: 6px 14px;
|
|
321
|
+
max-height: 220px;
|
|
322
|
+
overflow: auto;
|
|
321
323
|
}
|
|
322
324
|
|
|
323
325
|
.skill-people[hidden] {
|
|
@@ -329,6 +331,7 @@
|
|
|
329
331
|
align-items: center;
|
|
330
332
|
gap: 5px;
|
|
331
333
|
font-size: 14px;
|
|
334
|
+
overflow-wrap: anywhere;
|
|
332
335
|
}
|
|
333
336
|
|
|
334
337
|
.skill-upload-btns {
|
|
@@ -338,7 +341,7 @@
|
|
|
338
341
|
}
|
|
339
342
|
|
|
340
343
|
@media (max-width: 640px) {
|
|
341
|
-
.skills-
|
|
344
|
+
.skills-head {
|
|
342
345
|
flex-direction: column;
|
|
343
346
|
gap: 12px;
|
|
344
347
|
}
|
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
|
+
}
|
package/web/lib/markdown.js
CHANGED
|
@@ -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
|
|
package/web/settings/skills.js
CHANGED
|
@@ -4,13 +4,12 @@ import { renderMarkdown } from "../lib/markdown.js";
|
|
|
4
4
|
import { confirmDialog, modal, showMenu } from "../lib/overlay.js";
|
|
5
5
|
|
|
6
6
|
// ---------- 技能(设置里的一页) ----------
|
|
7
|
-
//
|
|
7
|
+
// 我的技能:自己建的和安装的;共享技能:别人分享给自己的,可查看、安装;管理员另有「本机技能」。
|
|
8
8
|
// 技能有变化时服务端推 { t: "skills" }(lib/ws.js 转成 aim:skills 事件),这一页开着就重新拉。
|
|
9
9
|
|
|
10
10
|
const K = { data: null, tab: "mine", query: "", token: 0, reloadTimer: 0, box: null };
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
const SHARED = { users: "分享给了指定的人", all: "所有人可见" };
|
|
12
|
+
const SHARED = { private: "仅自己可见", users: "共享给指定用户", all: "所有人可见" };
|
|
14
13
|
|
|
15
14
|
export async function skillsTab(panel) {
|
|
16
15
|
K.tab = "mine";
|
|
@@ -45,18 +44,21 @@ function mine() {
|
|
|
45
44
|
return K.data.skills.filter((s) => s.installed).sort((a, b) => a.name.localeCompare(b.name));
|
|
46
45
|
}
|
|
47
46
|
|
|
47
|
+
function shared() {
|
|
48
|
+
return K.data.skills.filter((s) => !s.mine).sort((a, b) => a.name.localeCompare(b.name));
|
|
49
|
+
}
|
|
50
|
+
|
|
48
51
|
function matches(s) {
|
|
49
52
|
const q = K.query.trim().toLowerCase();
|
|
50
53
|
return !q || s.name.includes(q) || s.description.toLowerCase().includes(q) || (s.ownerName ?? "").toLowerCase().includes(q);
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
function render() {
|
|
54
|
-
const tabs =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
: [];
|
|
57
|
+
const tabs = [
|
|
58
|
+
["mine", `我的技能 ${mine().length}`],
|
|
59
|
+
["shared", `共享技能 ${shared().length}`],
|
|
60
|
+
...(K.data.machine ? [["machine", `本机技能 ${K.data.machine.length}`]] : []),
|
|
61
|
+
];
|
|
60
62
|
const search = h("input", { class: "skill-search", type: "search", placeholder: "搜索名字、说明", value: K.query });
|
|
61
63
|
search.oninput = () => {
|
|
62
64
|
K.query = search.value;
|
|
@@ -71,7 +73,7 @@ function render() {
|
|
|
71
73
|
h(
|
|
72
74
|
"p",
|
|
73
75
|
{ class: "skill-note" },
|
|
74
|
-
"技能是一份写给 agent 的做事方法(SKILL.md),可以带脚本和资料,Claude 和 Codex
|
|
76
|
+
"技能是一份写给 agent 的做事方法(SKILL.md),可以带脚本和资料,Claude 和 Codex 都能用。自己建的技能可共享给指定用户或所有人;别人共享的技能安装后可用,变量由每个人自己填写。内置专家默认使用你启用的技能,自定义专家只用它选中的(设置 → 专家)。",
|
|
75
77
|
),
|
|
76
78
|
h(
|
|
77
79
|
"div",
|
|
@@ -112,10 +114,17 @@ function renderList() {
|
|
|
112
114
|
if (K.tab === "machine") {
|
|
113
115
|
const list = K.data.machine.filter((m) => matches({ ...m, ownerName: "" }));
|
|
114
116
|
return [
|
|
115
|
-
h("p", { class: "skill-note" }, "这台机器上原有的技能(~/.claude/skills、~/.agents/skills
|
|
117
|
+
h("p", { class: "skill-note" }, "这台机器上原有的技能(~/.claude/skills、~/.agents/skills 等)。只有管理员的会话能用。要共享给别人,请在「我的技能」中新建或上传技能包,再设置共享范围。"),
|
|
116
118
|
list.length ? h("div", { class: "task-list" }, list.map(machineCard)) : h("div", { class: "skill-empty" }, "没有找到"),
|
|
117
119
|
];
|
|
118
120
|
}
|
|
121
|
+
if (K.tab === "shared") {
|
|
122
|
+
const list = shared().filter(matches);
|
|
123
|
+
return [
|
|
124
|
+
h("p", { class: "skill-note" }, "这里是其他用户共享给你的技能。安装前可点开查看说明和附带文件;安装后跟随作者更新,撤回共享后将无法再用。变量和密钥使用你自己填写的值。"),
|
|
125
|
+
list.length ? h("div", { class: "task-list" }, list.map(sharedCard)) : h("div", { class: "skill-empty" }, K.query ? "没有找到" : "还没有别人共享给你的技能"),
|
|
126
|
+
];
|
|
127
|
+
}
|
|
119
128
|
const list = mine().filter(matches);
|
|
120
129
|
if (list.length) return h("div", { class: "task-list" }, list.map(mineCard));
|
|
121
130
|
if (K.query) return h("div", { class: "skill-empty" }, "没有找到");
|
|
@@ -164,6 +173,7 @@ function mineCard(s) {
|
|
|
164
173
|
...(s.mine
|
|
165
174
|
? [
|
|
166
175
|
{ label: "编辑…", onclick: () => openEditor(s) },
|
|
176
|
+
{ label: "共享…", onclick: () => openSharing(s) },
|
|
167
177
|
{ label: "用文件替换…", onclick: () => pickUpload(s) },
|
|
168
178
|
]
|
|
169
179
|
: []),
|
|
@@ -198,6 +208,21 @@ function mineCard(s) {
|
|
|
198
208
|
);
|
|
199
209
|
}
|
|
200
210
|
|
|
211
|
+
function sharedCard(s) {
|
|
212
|
+
const install = h("button", { class: "btn primary", onclick: () => installShared(s, install) }, "安装");
|
|
213
|
+
return h(
|
|
214
|
+
"div",
|
|
215
|
+
{ class: "task-card skill-card" },
|
|
216
|
+
h("div", { class: "task-top" },
|
|
217
|
+
h("button", { class: "task-title skill-name", title: "查看", onclick: () => openDetail(s) }, s.name),
|
|
218
|
+
s.installed ? h("span", { class: "badge" }, s.enabled ? "已安装" : "已安装 · 已停用") : install,
|
|
219
|
+
s.canDelete ? h("button", { class: "btn", onclick: () => removeSkill(s) }, "下架") : null,
|
|
220
|
+
),
|
|
221
|
+
h("div", { class: "task-meta" }, h("span", {}, `${s.ownerName} 建的`), h("span", {}, SHARED[s.visibility]), s.vars.length ? h("span", {}, `${s.vars.length} 个变量`) : null),
|
|
222
|
+
h("div", { class: "task-prompt" }, s.description),
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
201
226
|
function machineCard(m) {
|
|
202
227
|
return h(
|
|
203
228
|
"div",
|
|
@@ -210,11 +235,25 @@ function machineCard(m) {
|
|
|
210
235
|
|
|
211
236
|
// ---------- 操作 ----------
|
|
212
237
|
|
|
213
|
-
|
|
238
|
+
async function installShared(s, button) {
|
|
239
|
+
button.disabled = true;
|
|
240
|
+
try {
|
|
241
|
+
const installed = await api(`/api/skills/${s.id}/install`, { method: "POST", body: { on: true } });
|
|
242
|
+
toast(`已安装 ${s.name}`);
|
|
243
|
+
await reload();
|
|
244
|
+
if (varsNeedAttention(installed)) openVars(installed);
|
|
245
|
+
return true;
|
|
246
|
+
} catch (err) {
|
|
247
|
+
button.disabled = false;
|
|
248
|
+
toast(err.message);
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
214
253
|
async function uninstall(s) {
|
|
215
254
|
const sure = await confirmDialog({
|
|
216
255
|
title: `卸载「${s.name}」?`,
|
|
217
|
-
message: `这是 ${s.ownerName}
|
|
256
|
+
message: `这是 ${s.ownerName} 建的技能。卸载后不再加载;只要作者仍共享给你,就可以在「共享技能」中重新安装。`,
|
|
218
257
|
confirmText: "卸载",
|
|
219
258
|
danger: true,
|
|
220
259
|
});
|
|
@@ -230,9 +269,9 @@ async function uninstall(s) {
|
|
|
230
269
|
|
|
231
270
|
async function removeSkill(s) {
|
|
232
271
|
const sure = await confirmDialog({
|
|
233
|
-
title:
|
|
234
|
-
message: `删除后找不回来${s.installs ? `,装了它的 ${s.installs} 个人也用不了了` : ""}。`,
|
|
235
|
-
confirmText: "删除",
|
|
272
|
+
title: `${s.mine ? "删除" : "下架"}技能「${s.name}」?`,
|
|
273
|
+
message: `删除后找不回来${s.mine ? s.installs ? `,装了它的 ${s.installs} 个人也用不了了` : "" : ",作者和安装它的用户也将无法使用"}。`,
|
|
274
|
+
confirmText: s.mine ? "删除" : "下架",
|
|
236
275
|
danger: true,
|
|
237
276
|
});
|
|
238
277
|
if (!sure) return;
|
|
@@ -249,7 +288,8 @@ async function removeSkill(s) {
|
|
|
249
288
|
|
|
250
289
|
async function openDetail(s) {
|
|
251
290
|
const body = h("div", { class: "modal-body skill-detail" }, starsLoader());
|
|
252
|
-
|
|
291
|
+
const foot = h("div", { class: "modal-foot" });
|
|
292
|
+
const close = modal({ title: s.name, body, foot, wide: true });
|
|
253
293
|
let d;
|
|
254
294
|
try {
|
|
255
295
|
d = await api(`/api/skills/${s.id}`);
|
|
@@ -257,6 +297,11 @@ async function openDetail(s) {
|
|
|
257
297
|
fill(body, h("div", { class: "error-text" }, err.message));
|
|
258
298
|
return;
|
|
259
299
|
}
|
|
300
|
+
if (d.mine) foot.append(h("button", { class: "btn", onclick: () => (close(), openSharing(d)) }, "共享…"));
|
|
301
|
+
else if (!d.installed) {
|
|
302
|
+
const install = h("button", { class: "btn primary", onclick: async () => { if (await installShared(d, install)) close(); } }, "安装");
|
|
303
|
+
foot.append(install);
|
|
304
|
+
}
|
|
260
305
|
const filePreview = h("div", { class: "skill-file-preview" });
|
|
261
306
|
fill(
|
|
262
307
|
body,
|
|
@@ -264,7 +309,7 @@ async function openDetail(s) {
|
|
|
264
309
|
"div",
|
|
265
310
|
{ class: "task-meta" },
|
|
266
311
|
h("span", {}, d.mine ? "我建的" : `${d.ownerName} 建的`),
|
|
267
|
-
|
|
312
|
+
h("span", {}, SHARED[d.visibility]),
|
|
268
313
|
h("span", {}, `更新于 ${new Date(d.updatedAt).toLocaleString()}`),
|
|
269
314
|
),
|
|
270
315
|
h("p", { class: "skill-desc" }, d.description),
|
|
@@ -414,6 +459,67 @@ function openVars(s) {
|
|
|
414
459
|
|
|
415
460
|
// ---------- 新建 / 编辑 ----------
|
|
416
461
|
|
|
462
|
+
function visibilityEditor(skill = {}) {
|
|
463
|
+
const select = h("select", { "aria-label": "共享范围" },
|
|
464
|
+
h("option", { value: "private" }, "仅自己可见"),
|
|
465
|
+
h("option", { value: "users" }, "指定用户"),
|
|
466
|
+
h("option", { value: "all" }, "所有人可见"),
|
|
467
|
+
);
|
|
468
|
+
select.value = skill.visibility ?? "private";
|
|
469
|
+
const selected = new Set(skill.sharedWith ?? []);
|
|
470
|
+
// 已停用或删除的接收者也保留,让编辑正文不会意外改变共享名单。
|
|
471
|
+
const users = [...K.data.users];
|
|
472
|
+
for (const id of selected) if (!users.some((u) => u.id === id)) users.push({ id, name: `${id}(当前不可登录)` });
|
|
473
|
+
const checks = users.map((u) => {
|
|
474
|
+
const input = h("input", { type: "checkbox", checked: selected.has(u.id) });
|
|
475
|
+
return { id: u.id, input, el: h("label", { class: "skill-person" }, input, u.name) };
|
|
476
|
+
});
|
|
477
|
+
const people = h("div", { class: "skill-people" }, checks.length ? checks.map((c) => c.el) : h("small", {}, "暂无其他用户,请先添加用户或选择所有人可见。"));
|
|
478
|
+
const sync = () => (people.hidden = select.value !== "users");
|
|
479
|
+
select.onchange = sync;
|
|
480
|
+
sync();
|
|
481
|
+
return {
|
|
482
|
+
el: h("div", { class: "skill-visibility" }, select, people),
|
|
483
|
+
value: () => {
|
|
484
|
+
const sharedWith = select.value === "users" ? checks.filter((c) => c.input.checked).map((c) => c.id) : [];
|
|
485
|
+
if (select.value === "users" && !sharedWith.length) throw new Error("选「指定用户」时至少勾一个人");
|
|
486
|
+
return { visibility: select.value, sharedWith };
|
|
487
|
+
},
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
async function openSharing(s) {
|
|
492
|
+
let d;
|
|
493
|
+
try {
|
|
494
|
+
d = await api(`/api/skills/${s.id}`);
|
|
495
|
+
} catch (err) {
|
|
496
|
+
return toast(err.message);
|
|
497
|
+
}
|
|
498
|
+
const visibility = visibilityEditor(d);
|
|
499
|
+
const save = h("button", { class: "btn primary" }, "保存");
|
|
500
|
+
const close = modal({
|
|
501
|
+
title: `共享 ${d.name}`,
|
|
502
|
+
body: h("div", { class: "modal-body task-form" },
|
|
503
|
+
field("共享范围", visibility.el),
|
|
504
|
+
h("p", { class: "skill-note" }, "其他用户在「共享技能」中查看和安装。共享的是技能正文和附带文件,安装后跟随你的更新;变量和密钥由每个人自己填写。缩小范围或改为仅自己可见后,不在范围内的用户将无法再使用。"),
|
|
505
|
+
),
|
|
506
|
+
foot: h("div", { class: "modal-foot" }, save),
|
|
507
|
+
});
|
|
508
|
+
save.onclick = async () => {
|
|
509
|
+
try {
|
|
510
|
+
const payload = visibility.value();
|
|
511
|
+
save.disabled = true;
|
|
512
|
+
await api(`/api/skills/${d.id}`, { method: "PATCH", body: payload });
|
|
513
|
+
close();
|
|
514
|
+
toast("已更新共享范围");
|
|
515
|
+
void reload();
|
|
516
|
+
} catch (err) {
|
|
517
|
+
save.disabled = false;
|
|
518
|
+
toast(err.message);
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
|
|
417
523
|
/** 变量声明的编辑器:一行一个 */
|
|
418
524
|
function varsEditor(list) {
|
|
419
525
|
const rows = [];
|
|
@@ -482,7 +588,7 @@ const BODY_TEMPLATE = `## 什么时候用
|
|
|
482
588
|
|
|
483
589
|
- 不要把密钥打印出来`;
|
|
484
590
|
|
|
485
|
-
/** s
|
|
591
|
+
/** s:编辑这个(自己的);不给就是新建。上传后也用这个确认。 */
|
|
486
592
|
async function openEditor(s) {
|
|
487
593
|
let d = null;
|
|
488
594
|
if (s) {
|
|
@@ -498,6 +604,7 @@ async function openEditor(s) {
|
|
|
498
604
|
const body = h("textarea", { rows: 14, class: "skill-body-input", spellcheck: "false", placeholder: "写给 agent 的操作说明(Markdown)" });
|
|
499
605
|
body.value = d?.body ?? (s ? "" : BODY_TEMPLATE);
|
|
500
606
|
const vars = varsEditor(d?.vars);
|
|
607
|
+
const visibility = visibilityEditor(d ?? {});
|
|
501
608
|
const save = h("button", { class: "btn primary" }, d ? "保存" : "创建");
|
|
502
609
|
const close = modal({
|
|
503
610
|
title: d ? `编辑 ${d.name}` : "新建技能",
|
|
@@ -508,6 +615,7 @@ async function openEditor(s) {
|
|
|
508
615
|
{ class: "modal-body task-form" },
|
|
509
616
|
field("名字", name, d ? "建好后不能改。" : "全站唯一,建好后不能改。"),
|
|
510
617
|
field("说明", desc),
|
|
618
|
+
field("共享范围", visibility.el, "其他用户可在「共享技能」中安装,正文和附带文件跟随你的更新;变量和密钥由每个人自己填写。"),
|
|
511
619
|
field("正文(SKILL.md)", body, d?.files?.length ? `另有 ${d.files.length} 个附带文件,要改的话用「用文件替换」上传整个包。` : "可以引用同目录下的脚本、资料(上传技能包时一起带上)。"),
|
|
512
620
|
field(
|
|
513
621
|
"变量",
|
|
@@ -519,9 +627,9 @@ async function openEditor(s) {
|
|
|
519
627
|
});
|
|
520
628
|
(d ? desc : name).focus();
|
|
521
629
|
save.onclick = async () => {
|
|
522
|
-
const payload = { description: desc.value, body: body.value, vars: vars.value() };
|
|
523
|
-
save.disabled = true;
|
|
524
630
|
try {
|
|
631
|
+
const payload = { description: desc.value, body: body.value, vars: vars.value(), ...visibility.value() };
|
|
632
|
+
save.disabled = true;
|
|
525
633
|
if (d) await api(`/api/skills/${d.id}`, { method: "PATCH", body: payload });
|
|
526
634
|
else await api("/api/skills", { method: "POST", body: { name: name.value.trim().toLowerCase(), ...payload } });
|
|
527
635
|
close();
|
|
@@ -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);
|
package/web/views/topbar.js
CHANGED
|
@@ -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
|
-
|
|
478
|
+
/** 顶栏和侧栏共用的会话操作,显示条件和行为保持一致。 */
|
|
479
|
+
function convMenuItems(key) {
|
|
478
480
|
const c = S.convs.get(key);
|
|
479
|
-
if (!c) return;
|
|
480
|
-
|
|
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: "
|
|
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
|
/**
|