agent-loft 0.2.66 → 0.2.68
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 +5 -3
- package/package.json +1 -1
- package/src/channels/web/api.ts +35 -13
- package/src/channels/web/conv-pages.ts +1 -1
- package/src/channels/web/experts-api.ts +12 -4
- package/src/core/experts.ts +3 -3
- package/src/core/hub.ts +34 -6
- package/src/core/servers.ts +5 -3
- package/src/core/task-runner.ts +4 -4
- package/src/core/ui-prefs.ts +3 -3
- package/src/core/users.ts +32 -8
- package/web/css/settings.css +26 -0
- package/web/css/sidebar.css +43 -1
- package/web/lib/overlay.js +6 -9
- package/web/settings/agents.js +2 -1
- package/web/settings/security.js +11 -2
- package/web/settings/users.js +56 -4
- package/web/views/conv-actions.js +3 -6
- package/web/views/experts.js +5 -1
- package/web/views/layout.js +12 -15
- package/web/views/sidebar-nav.js +0 -4
- package/web/views/sidebar.js +154 -91
- package/web/views/topbar.js +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
|
|
|
52
52
|
- 输入框里的小圆环显示上下文窗口占用;模型按钮显示实际的模型和思考程度(如「Opus 5.5 high」)。
|
|
53
53
|
- 滚动和 ChatGPT 一样:发出的问题顶到最上面、下面留白,回复长到屏幕底部才跟着往下滚;回复过程中自己滚动了就不再自动滚,下次发消息再恢复。
|
|
54
54
|
- 定时发送:右上角「更多」→「定时发送」,默认排在 5 小时额度重置后 5 分钟(弹窗里提示 5 小时 / 7 天额度的重置时间),由服务端到点发出,关掉页面也会发。适合额度用完、要等刷新才能接着干活的时候。
|
|
55
|
-
- 侧栏直接显示各个文件夹,Web
|
|
55
|
+
- 侧栏直接显示各个文件夹,Web 会话按工作目录归类(目录可以拖动排序,右键可置顶;排好的顺序跟着账号走、各设备一致,新消息不会打乱),飞书会话按机器人分组,也能展开 / 折叠并记住状态(右键仍可看历史会话)。机器人行右侧平时显示飞书图标,鼠标悬停时切成加号;点击加号在 Web 开新对话,沿用最近飞书会话的专家和工作目录。项目名、机器人名和有分叉的会话后面有个小三角,点一下折叠 / 展开(分叉折叠后显示「N 个嵌套会话」);分叉出来的会话缩进挂在原会话下面,用一条细线连着;标题放不下时尾巴淡出;Web 和飞书会话都先用首条消息命名,再同步 agent 自动生成的标题,旧飞书会话会从历史记录补名,双击可手动重命名;鼠标移到会话上,行尾显示对应的专家图标;定时任务的时钟图标始终放在最右侧。
|
|
56
56
|
- **搜索**:侧栏「搜索」弹窗,搜全部会话的标题、目录名和聊天内容(不开记忆也能搜),可以按专家筛;电脑和手机上弹窗都固定高度,结果在内部滚动,手机上从底部展开;↑↓ 选、回车打开。
|
|
57
57
|
- **侧栏菜单**:项目上方的「更多」支持点击或鼠标悬停展开,设置入口也在这里。「编辑侧边栏」可勾选直接显示的菜单、拖动调整顺序,未勾选的收进「更多」;配置跟着账号走,电脑和手机共用。
|
|
58
58
|
- 会话页顶部标题前是专家的头像,鼠标停上去或点一下,看专家的说明、模型、能力和当前工作目录。
|
|
@@ -61,7 +61,8 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
|
|
|
61
61
|
- 用户消息的复制按钮后有「回退到此处」图标:把这条消息及附件放回输入框,并删除它及之后的聊天内容,重新发送时从之前的上下文继续。
|
|
62
62
|
- 太长的消息先收起,点「展开显示」看全文;对话里有至少 3 条用户消息时,右侧显示快速定位尺,电脑上鼠标移入查看消息开头、点击跳转;手机上手动滚动时显示短轨道,按住拖动可预览问题和位置,松手跳转,停止操作约 1.6 秒后隐藏。
|
|
63
63
|
- 回复底部的 token 数自动按大小显示为 K、M 等单位。
|
|
64
|
-
-
|
|
64
|
+
- 侧栏按页加载:每个项目目录和飞书机器人分组先显示 5 条,点「展开显示」每次再拉 10 条。
|
|
65
|
+
- 项目和飞书分组可混合拖拽排序,飞书可以放在项目前面或项目之间;右键(触屏长按)可置顶、上移、下移或按最近活跃重排。顺序按账号保存,刷新、换设备后保留,新消息不会改变已排好的位置。
|
|
65
66
|
- 侧栏底部显示 Claude / Codex 的订阅额度(5 小时 / 7 天窗口,以及多久后重置);关了额度查询就整块不显示。
|
|
66
67
|
- 右上角「更多」最下面显示当前会话累计消耗的 token 分布(输入 / 缓存写入 / 缓存读取 / 输出,Claude 还有按 API 价格估算的费用)。设置也在「更多」里。
|
|
67
68
|
- 设置 → 用量:按日 / 月 / 年(默认按月)统计 token 和金额,有每天(每月)的柱状图,按 agent、模型、用户(管理员才有)分开看;成员只看到自己的。管理员还可查看服务端本机直接使用的 Claude Code、Codex 桌面端和 CLI 用量,和 Agent Loft 的用量分开显示、避免重复计算。金额都是按 API 价格算的参考值:Agent Loft 的 Claude 用它自己报的费用,Codex 和直接用的 Claude Code 按模型单价 × token 估算(OpenAI 单价来自 LiteLLM 公开价格表,内置快照、联网时每天更新)。Agent Loft 的账从 0.2.34 开始记录;本机直接使用的用量可回溯已有会话记录。
|
|
@@ -70,7 +71,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
|
|
|
70
71
|
- **系统通知**:Web 会话回复完成、出错、需要授权或提问时推送到手机 / 电脑(设置 → 通知 → 「在此设备开启通知」,可以发测试通知)。飞书会话由飞书提醒,正在前台看着的会话不推。需要 HTTPS 访问,iPhone 需 iOS 16.4+ 且从主屏幕图标打开。
|
|
71
72
|
- **跨渠道同步**:飞书里的会话在 Web 上也能打开接着聊。同一个授权请求同时出现在飞书卡片和网页上,哪边先点算哪边,另一边自动变成「已处理」。
|
|
72
73
|
- **授权**:允许一次 / 本会话全部允许 / 总是允许(按钮上写明放行范围)/ 拒绝。`/autoedit on` 让 Claude Code 在这条会话里改工作目录内的文件不再询问(Bash 仍询问)。超时一律按拒绝处理。
|
|
73
|
-
- **设置都在网页上**,按用途分组:**我的**(账号和密码、飞书绑定、登录设备、通知、记忆、技能、用量,每个人都有);**Agent**(运行环境、各 agent 的默认模型和思考程度、可选模型、Codex 沙箱、额度查询;工作目录、会话闲置过期、授权卡超时和 Claude
|
|
74
|
+
- **设置都在网页上**,按用途分组:**我的**(账号和密码、飞书绑定、登录设备、通知、记忆、技能、用量,每个人都有);**Agent**(运行环境、各 agent 的默认模型和思考程度、可选模型、Codex 沙箱、额度查询;工作目录、会话闲置过期、授权卡超时和 Claude 的「总是允许」名单;「/」命令);**连接**(飞书机器人、配对批准、指令面板同步;远程控制;服务器);**管理**(用户、所有人的登录设备;服务端版本和升级、重启、局域网访问和端口)。设置、新建 / 编辑专家、重命名等编辑弹窗不会因点击外部或按 Esc 关闭;通过关闭、取消或保存 / 完成按钮退出。改了没保存就切页或关掉设置会先提醒。
|
|
74
75
|
- **多用户**(信任型):管理员在 设置 → 用户 里给别人建账号。每个人只看得到自己的对话、授权和通知,设置只有管理员能改,见下面「安全」。
|
|
75
76
|
- **专家**:设置 → 专家。专家是一份配置,新建对话、定时任务时选一个,对话从头到尾都是它(中途不能换;飞书里 `/expert 名字`、`/claude`、`/codex` 换专家会开新会话)。**内置专家**:Claude Code、Codex,保留原装提示词和所有工具,默认技能与 MCP 在「设置 → Agent」中按账号、按引擎分别选择。**自定义专家**由创建者管理,可以勾选「共享给所有账号」。共享后,其他人能在网页、绑定账号后的飞书私聊和定时任务中选择它;只有创建者能修改设定。每个人在该专家的「我的工具」里选择自己的技能和 MCP,使用各自的变量、凭据、记忆和聊天记录;创建者沿用原有工具选择,其他人未配置时不加载技能或 MCP。取消共享后,其他人的历史对话保留,后续消息不能继续调用该专家,相关定时任务在下次运行时暂停。可以配:
|
|
76
77
|
- 头像(点头像区域的加号上传;未上传时,会话中用引擎的图标)、引擎(Claude / Codex,建好后不能换)、默认模型和思考程度(从模型列表里选);
|
|
@@ -172,6 +173,7 @@ agent-loft service install
|
|
|
172
173
|
这个服务能让 agent 在你的机器上执行命令,等于一个远程 shell。
|
|
173
174
|
|
|
174
175
|
- Web 登录密码用 scrypt 哈希保存。首次建管理员必须用启动日志里的一次性设置码,防止「谁先打开页面谁就成了主人」。
|
|
176
|
+
- 管理员在 设置 → 用户 添加成员时,或点已有成员的「使用权限」,可以分别设置共享专家、内置 Agent、服务器切换为「全部允许(含以后新增)」或指定列表(可全部取消);旧账号沿用全部允许。共享专家和内置 Agent 分别授权,成员自己创建的专家仍可使用;收回权限后旧对话可查看,但不能继续调用,相关定时任务会暂停。服务器权限控制本机切换列表,当前服务器保持可用,各台服务器仍各自登录和管理账号。每个用户都可以在 设置 → 账号 修改自己的账号名称(也是登录名),修改不影响原有对话和登录设备。
|
|
175
177
|
- 多用户只隔开**界面上**的东西:会话列表、授权 / 提问卡、通知、记忆、`/sessions` 能列出和恢复的 agent 会话;设置、飞书机器人和飞书会话只给管理员(绑定了账号的飞书私聊除外,它归绑定的人);会落盘、对所有人生效的「总是允许」(Claude 的总是允许名单、Codex 的 execpolicy)只有管理员能点。**它不是安全边界**:所有 agent 都以同一个系统用户运行,任何用户都能让 agent 读到这台机器上的文件(别人的对话记录、配置里的密钥),用的也是同一个 Claude / Codex 订阅。只给信任的人开账号;要真正隔离,就每人用自己的系统用户各跑一份 agent-loft。
|
|
176
178
|
- 从老版本升级:原来的登录密码自动变成管理员 `admin`,已登录的设备不用重新登录。
|
|
177
179
|
- 登录态通过 HttpOnly cookie 保存,服务端只存它的哈希。同一 IP 连续输错 5 次锁 15 分钟。所有写请求和 WebSocket 都校验 Origin。页面开启了严格的 CSP。
|
package/package.json
CHANGED
package/src/channels/web/api.ts
CHANGED
|
@@ -499,7 +499,7 @@ function adminOnly(p: string): boolean {
|
|
|
499
499
|
);
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
-
function publicMe(user: User) {
|
|
502
|
+
function publicMe(user: Pick<User, "id" | "name" | "role">) {
|
|
503
503
|
return { id: user.id, name: user.name, role: user.role };
|
|
504
504
|
}
|
|
505
505
|
|
|
@@ -680,6 +680,7 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
680
680
|
id,
|
|
681
681
|
label: d?.label ?? id,
|
|
682
682
|
enabled: hub.enabledAgents().some((e) => e.id === id),
|
|
683
|
+
allowed: canUseExpert(user.id, id),
|
|
683
684
|
capabilities: d?.capabilities ?? {},
|
|
684
685
|
// 输入框模型列表里显示哪些,空 = 全部
|
|
685
686
|
models: config().agents[id].models.filter((m) => typeof m === "string"),
|
|
@@ -694,26 +695,26 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
694
695
|
workspaceRoot: config().workspaceRoot,
|
|
695
696
|
quotaRefreshMin: config().web.quotaRefreshMin,
|
|
696
697
|
quotaEnabled: config().web.quotaEnabled,
|
|
697
|
-
conversations: [...keep.values()],
|
|
698
|
+
conversations: await hub.backfillFeishuTitles([...keep.values()]),
|
|
698
699
|
sidebar: {
|
|
699
700
|
recent: { next: recent.next },
|
|
700
701
|
// 展开着的目录带上翻页游标(没带 next 的目录前端还没拉过)
|
|
701
702
|
dirs: dirsOf(all).map((d) => (dirPages.has(d.dir) ? { ...d, next: dirPages.get(d.dir)!.next } : d)),
|
|
702
703
|
},
|
|
703
|
-
//
|
|
704
|
+
// 项目和飞书分组的混合顺序,跟着账号走;沿用目录排序字段兼容旧数据
|
|
704
705
|
dirOrder: getDirOrder(user.id) ?? null,
|
|
705
706
|
sidebarNav: getSidebarNav(user.id),
|
|
706
707
|
pending,
|
|
707
708
|
user: publicMe(user),
|
|
708
709
|
remote: remoteStatus(user),
|
|
709
710
|
// 左上角切换服务器:没加别的服务器是 null
|
|
710
|
-
servers: shellInfo(config().servers),
|
|
711
|
+
servers: shellInfo(config().servers, user),
|
|
711
712
|
serverTime: Date.now(),
|
|
712
713
|
});
|
|
713
714
|
return;
|
|
714
715
|
}
|
|
715
716
|
|
|
716
|
-
// -----
|
|
717
|
+
// ----- 侧栏分组顺序:order 整份换掉,append 只把新分组接在最后 -----
|
|
717
718
|
if (p === "/api/ui/dir-order" && method === "PUT") {
|
|
718
719
|
const body = await readJsonBody<{ order?: unknown; append?: unknown }>(req);
|
|
719
720
|
const order = body.order !== undefined ? setDirOrder(user.id, body.order) : appendDirOrder(user.id, body.append);
|
|
@@ -746,7 +747,7 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
746
747
|
// 多服务器(core/servers.ts):外壳把这个浏览器的订阅连同签名密钥转给嵌着的各台(web/lib/shell.js),
|
|
747
748
|
// 各台直接推到手机上,不经过外壳。密钥只在加了别的服务器时给
|
|
748
749
|
if (p === "/api/push/relay-key" && method === "GET") {
|
|
749
|
-
if (!config().servers
|
|
750
|
+
if (!shellInfo(config().servers, user)) throw new HttpError(404, "没有可用的其他服务器");
|
|
750
751
|
sendJson(res, 200, vapidKeyPair());
|
|
751
752
|
return;
|
|
752
753
|
}
|
|
@@ -813,13 +814,19 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
813
814
|
}
|
|
814
815
|
|
|
815
816
|
// ----- 会话 -----
|
|
816
|
-
// 侧栏按页拉:
|
|
817
|
+
// 侧栏按页拉:recent / dir / bot 按树分页;bot 不传 limit 时保留历史弹窗的平铺列表。
|
|
817
818
|
if (p === "/api/conversations/page" && method === "GET") {
|
|
818
819
|
const all = hub.list(visible).filter((c) => !c.hidden);
|
|
819
820
|
const scope = url.searchParams.get("scope");
|
|
820
821
|
if (scope === "bot") {
|
|
821
822
|
const bot = url.searchParams.get("bot") ?? "";
|
|
822
|
-
|
|
823
|
+
const list = all.filter((c) => c.channel === "feishu" && c.channelId === bot);
|
|
824
|
+
const before = parseCursor(url.searchParams.get("at"), url.searchParams.get("key"));
|
|
825
|
+
const page = url.searchParams.has("limit")
|
|
826
|
+
? pageOf(list, before, clampLimit(url.searchParams.get("limit"), 5))
|
|
827
|
+
: { conversations: list.slice(0, 200), next: null };
|
|
828
|
+
page.conversations = await hub.backfillFeishuTitles(page.conversations);
|
|
829
|
+
sendJson(res, 200, page);
|
|
823
830
|
return;
|
|
824
831
|
}
|
|
825
832
|
if (scope !== "recent" && scope !== "dir") throw new HttpError(400, "scope 只能是 recent / dir / bot");
|
|
@@ -860,8 +867,8 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
860
867
|
const body = await readJsonBody<{ expert?: string; agent?: string; cwd?: string }>(req);
|
|
861
868
|
const enabled = hub.enabledAgents().map((d) => d.id);
|
|
862
869
|
const wanted = body.expert ?? body.agent;
|
|
863
|
-
if (wanted && !canUseExpert(user.id, wanted)) throw new HttpError(400, "
|
|
864
|
-
const expertId = wanted || enabled[0];
|
|
870
|
+
if (wanted && !canUseExpert(user.id, wanted)) throw new HttpError(400, "这个专家或 Agent 不存在、已取消共享或未获授权");
|
|
871
|
+
const expertId = wanted || hub.expertChoices(user.id, enabled)[0]?.id;
|
|
865
872
|
if (!expertId) throw new HttpError(400, "没有可用的 agent");
|
|
866
873
|
const custom = isBuiltin(expertId) ? undefined : getExpert(expertId);
|
|
867
874
|
const agent = custom ? custom.engine : expertId;
|
|
@@ -1373,6 +1380,15 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1373
1380
|
return;
|
|
1374
1381
|
}
|
|
1375
1382
|
|
|
1383
|
+
// 修改自己的登录名:只允许改名称,沿用现有设备和会话归属。
|
|
1384
|
+
if (p === "/api/account" && method === "PATCH") {
|
|
1385
|
+
const body = await readJsonBody<{ name?: unknown }>(req);
|
|
1386
|
+
if (typeof body.name !== "string") throw new HttpError(400, "请填写账号名称");
|
|
1387
|
+
const updated = userOp(() => patchUser(user.id, { name: body.name as string }));
|
|
1388
|
+
sendJson(res, 200, { user: publicMe(updated) });
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1376
1392
|
// ----- 用户管理(管理员) -----
|
|
1377
1393
|
if (p === "/api/users" && method === "GET") {
|
|
1378
1394
|
const devices = listWebSessions();
|
|
@@ -1384,6 +1400,11 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1384
1400
|
feishuLinks: listLinks(u.id).length,
|
|
1385
1401
|
})),
|
|
1386
1402
|
me: user.id,
|
|
1403
|
+
resources: {
|
|
1404
|
+
experts: availableExperts(user.id).filter((e) => e.shared).map((e) => ({ id: e.id, name: e.name })),
|
|
1405
|
+
agents: [...AGENT_IDS].map((id) => ({ id, name: hub.label(id) })),
|
|
1406
|
+
servers: config().servers.list.map(({ id, name }) => ({ id, name })),
|
|
1407
|
+
},
|
|
1387
1408
|
});
|
|
1388
1409
|
return;
|
|
1389
1410
|
}
|
|
@@ -1406,11 +1427,11 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1406
1427
|
}
|
|
1407
1428
|
}
|
|
1408
1429
|
if (p === "/api/users" && method === "POST") {
|
|
1409
|
-
const body = await readJsonBody<{ name?: string; password?: string; role?: Role }>(req);
|
|
1430
|
+
const body = await readJsonBody<{ name?: string; password?: string; role?: Role; remote?: boolean; permissions?: unknown }>(req);
|
|
1410
1431
|
sendJson(
|
|
1411
1432
|
res,
|
|
1412
1433
|
200,
|
|
1413
|
-
userOp(() => createUser({ name: String(body.name ?? ""), password: String(body.password ?? ""), role: body.role === "admin" ? "admin" : "member" })),
|
|
1434
|
+
userOp(() => createUser({ name: String(body.name ?? ""), password: String(body.password ?? ""), role: body.role === "admin" ? "admin" : "member", ...(typeof body.remote === "boolean" ? { remote: body.remote } : {}), ...(body.permissions !== undefined ? { permissions: body.permissions } : {}) })),
|
|
1414
1435
|
);
|
|
1415
1436
|
return;
|
|
1416
1437
|
}
|
|
@@ -1419,7 +1440,7 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1419
1440
|
const id = userMatch[1]!;
|
|
1420
1441
|
if (!getUser(id)) throw new HttpError(404, "用户不存在");
|
|
1421
1442
|
if (method === "PATCH") {
|
|
1422
|
-
const body = await readJsonBody<{ name?: string; role?: Role; disabled?: boolean; password?: string; remote?: boolean }>(req);
|
|
1443
|
+
const body = await readJsonBody<{ name?: string; role?: Role; disabled?: boolean; password?: string; remote?: boolean; permissions?: unknown }>(req);
|
|
1423
1444
|
if (id === user.id && (body.disabled === true || (body.role !== undefined && body.role !== "admin"))) {
|
|
1424
1445
|
throw new HttpError(400, "不能停用自己,也不能取消自己的管理员");
|
|
1425
1446
|
}
|
|
@@ -1431,6 +1452,7 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1431
1452
|
...(typeof body.disabled === "boolean" ? { disabled: body.disabled } : {}),
|
|
1432
1453
|
...(typeof body.password === "string" ? { password: body.password } : {}),
|
|
1433
1454
|
...(typeof body.remote === "boolean" ? { remote: body.remote } : {}),
|
|
1455
|
+
...(body.permissions !== undefined ? { permissions: body.permissions } : {}),
|
|
1434
1456
|
}),
|
|
1435
1457
|
);
|
|
1436
1458
|
// 管理员在用户列表里重置了自己的密码:当前这台换个新登录态,别把自己踢出去
|
|
@@ -9,7 +9,7 @@ export type Cursor = { at: number; key: string };
|
|
|
9
9
|
export type Page = { conversations: ConversationInfo[]; next: Cursor | null };
|
|
10
10
|
type Tree = { root: ConversationInfo; convs: ConversationInfo[]; at: number };
|
|
11
11
|
|
|
12
|
-
/**
|
|
12
|
+
/** 最近:飞书以外的会话(飞书单独按机器人分组) */
|
|
13
13
|
export const inRecent = (c: ConversationInfo): boolean => c.channel !== "feishu";
|
|
14
14
|
/** 项目:Web 会话按工作目录分组 */
|
|
15
15
|
export const inDir = (dir: string) => (c: ConversationInfo): boolean => c.channel === "web" && c.cwd === dir;
|
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
} from "../../core/experts.js";
|
|
22
22
|
import { builtinAgentDefaults, setBuiltinAgentDefaults } from "../../core/builtin-agents.js";
|
|
23
23
|
import { hub } from "../../core/hub.js";
|
|
24
|
+
import { config } from "../../core/config.js";
|
|
25
|
+
import { shellInfo } from "../../core/servers.js";
|
|
24
26
|
import { claudeMachineMcp, createMcp, deleteMcp, getMcp, listMcp, MACHINE_PREFIX, MCP_LIMITS, mcpView, updateMcp, type McpInput } from "../../core/mcp.js";
|
|
25
27
|
import { activeSkills } from "../../core/skills.js";
|
|
26
28
|
import { isAdmin, type User } from "../../core/users.js";
|
|
@@ -95,7 +97,7 @@ export async function handleExpertsApi(req: IncomingMessage, res: ServerResponse
|
|
|
95
97
|
|
|
96
98
|
if (p === "/api/agents/defaults" && method === "GET") {
|
|
97
99
|
sendJson(res, 200, {
|
|
98
|
-
agents: builtinAgentDefaults(user.id),
|
|
100
|
+
agents: Object.fromEntries(Object.entries(builtinAgentDefaults(user.id)).filter(([id]) => canUseExpert(user.id, id))),
|
|
99
101
|
skills: activeSkills(user.id).map((s) => ({ id: s.id, name: s.name, description: s.description })),
|
|
100
102
|
mcp: listMcp(user.id).map((s) => ({ id: s.id, name: s.name, description: s.description })),
|
|
101
103
|
...(await machineMcp(user).then((m) => m ? { machineMcp: m, machinePrefix: MACHINE_PREFIX } : {})),
|
|
@@ -104,8 +106,9 @@ export async function handleExpertsApi(req: IncomingMessage, res: ServerResponse
|
|
|
104
106
|
}
|
|
105
107
|
if (p === "/api/agents/defaults" && method === "PUT") {
|
|
106
108
|
const body = await readJsonBody<{ agents?: unknown }>(req);
|
|
109
|
+
if (body.agents && typeof body.agents === "object" && Object.keys(body.agents).some((id) => !canUseExpert(user.id, id))) throw new HttpError(403, "没有使用这个内置 Agent 的权限");
|
|
107
110
|
try {
|
|
108
|
-
sendJson(res, 200, { agents: setBuiltinAgentDefaults(user.id, body.agents) });
|
|
111
|
+
sendJson(res, 200, { agents: Object.fromEntries(Object.entries(setBuiltinAgentDefaults(user.id, body.agents)).filter(([id]) => canUseExpert(user.id, id))) });
|
|
109
112
|
} catch (err) {
|
|
110
113
|
throw bad(err);
|
|
111
114
|
}
|
|
@@ -116,7 +119,7 @@ export async function handleExpertsApi(req: IncomingMessage, res: ServerResponse
|
|
|
116
119
|
const enabled = hub.enabledAgents().map((d) => d.id);
|
|
117
120
|
sendJson(res, 200, {
|
|
118
121
|
experts: availableExperts(user.id).map((e) => expertView(e, user.id)),
|
|
119
|
-
builtin: enabled.map((id) => ({ id, name: hub.label(id), engine: id })),
|
|
122
|
+
builtin: enabled.filter((id) => canUseExpert(user.id, id)).map((id) => ({ id, name: hub.label(id), engine: id })),
|
|
120
123
|
engines: enabled,
|
|
121
124
|
templates: EXPERT_TEMPLATES.map((t) => ({ id: t.id, label: t.label, expert: t.expert })),
|
|
122
125
|
access: ACCESS_LEVELS.map((id) => ({ id, label: ACCESS_LABEL[id] })),
|
|
@@ -129,7 +132,12 @@ export async function handleExpertsApi(req: IncomingMessage, res: ServerResponse
|
|
|
129
132
|
}
|
|
130
133
|
|
|
131
134
|
if (p === "/api/experts/brief" && method === "GET") {
|
|
132
|
-
sendJson(res, 200, {
|
|
135
|
+
sendJson(res, 200, {
|
|
136
|
+
experts: availableExperts(user.id).map(expertBrief),
|
|
137
|
+
builtin: hub.enabledAgents().filter((d) => canUseExpert(user.id, d.id)).map((d) => d.id),
|
|
138
|
+
user: { id: user.id, name: user.name, role: user.role },
|
|
139
|
+
servers: shellInfo(config().servers, user),
|
|
140
|
+
});
|
|
133
141
|
return true;
|
|
134
142
|
}
|
|
135
143
|
|
package/src/core/experts.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { dataDir, readJson, writeJsonAtomic } from "../home.js";
|
|
|
14
14
|
import { resolveWorkspacePath } from "./config.js";
|
|
15
15
|
import { claudeMachineMcp, getMcp, isMachineId, machineName, specOf, type McpSpec } from "./mcp.js";
|
|
16
16
|
import { activeSkills, canSee, getSkill } from "./skills.js";
|
|
17
|
-
import { getUser } from "./users.js";
|
|
17
|
+
import { canUseResource, getUser } from "./users.js";
|
|
18
18
|
|
|
19
19
|
export type Engine = "claude" | "codex";
|
|
20
20
|
export const ENGINES: readonly Engine[] = ["claude", "codex"];
|
|
@@ -196,13 +196,13 @@ export function getExpert(id: string): Expert | undefined {
|
|
|
196
196
|
|
|
197
197
|
/** 共享只开放使用权,不转移专家、工具或会话的所有权。无身份的飞书聊天不能用。 */
|
|
198
198
|
export function canUseExpert(owner: string | undefined, id: string): boolean {
|
|
199
|
-
if (isBuiltin(id)) return
|
|
199
|
+
if (isBuiltin(id)) return !owner || canUseResource(getUser(owner), "agents", id);
|
|
200
200
|
const e = getExpert(id);
|
|
201
201
|
if (!e || !owner) return false;
|
|
202
202
|
if (e.owner === owner) return true;
|
|
203
203
|
const creator = getUser(e.owner);
|
|
204
204
|
const user = getUser(owner);
|
|
205
|
-
return e.shared === true && !!creator && !creator.disabled &&
|
|
205
|
+
return e.shared === true && !!creator && !creator.disabled && canUseResource(user, "experts", id);
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
/** 发布者沿用专家原有的工具选择;其他人未配置时不加载技能和 MCP。 */
|
package/src/core/hub.ts
CHANGED
|
@@ -292,10 +292,12 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
292
292
|
}
|
|
293
293
|
});
|
|
294
294
|
expertToolEvents.on("changed", (owner) => this.personalChanged(new Set([owner]), true));
|
|
295
|
-
userEvents.on("changed", () => {
|
|
295
|
+
userEvents.on("changed", (accessChanged) => {
|
|
296
|
+
if (!accessChanged) return;
|
|
297
|
+
// 自定义专家还可能加载了权限已变更的子智能体;空闲后重新构建工具。
|
|
296
298
|
for (const [key, live] of this.live) {
|
|
297
299
|
const conv = getConversation(key);
|
|
298
|
-
if (!conv
|
|
300
|
+
if (!conv || (!conv.expert && canUseExpert(memoryOwnerOf(conv), conv.agent))) continue;
|
|
299
301
|
this.staleLive.add(live.id);
|
|
300
302
|
this.dropIfStale(key);
|
|
301
303
|
}
|
|
@@ -419,7 +421,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
419
421
|
|
|
420
422
|
/** 对话的专家,给顶栏和列表看 */
|
|
421
423
|
expertBadge(conv: Pick<Conversation, "agent" | "expert" | "owner" | "channel">): ExpertBadge {
|
|
422
|
-
if (!conv.expert) return { id: conv.agent, name: this.label(conv.agent), builtin: true };
|
|
424
|
+
if (!conv.expert) return { id: conv.agent, name: this.label(conv.agent), builtin: true, ...(!canUseExpert(memoryOwnerOf(conv), conv.agent) ? { missing: true } : {}) };
|
|
423
425
|
const e = getExpert(conv.expert);
|
|
424
426
|
if (!e || !canUseExpert(memoryOwnerOf(conv), e.id)) return { id: conv.expert, name: "(专家已删除或未共享)", missing: true };
|
|
425
427
|
return {
|
|
@@ -456,7 +458,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
456
458
|
*/
|
|
457
459
|
expertChoices(owner: string | undefined, allowedAgents: string[], allowedExperts?: string[]): { id: string; label: string; engine: string }[] {
|
|
458
460
|
const usable = new Set(this.enabledAgents().map((d) => d.id).filter((a) => allowedAgents.includes(a)));
|
|
459
|
-
const builtin = [...usable].map((a) => ({ id: a, label: this.label(a), engine: a }));
|
|
461
|
+
const builtin = [...usable].filter((a) => canUseExpert(owner, a)).map((a) => ({ id: a, label: this.label(a), engine: a }));
|
|
460
462
|
const own = owner ? availableExperts(owner).filter((e) => usable.has(e.engine)) : [];
|
|
461
463
|
return [...builtin, ...own.map((e) => ({ id: e.id, label: `${e.icon ? `${e.icon} ` : ""}${e.name}`, engine: e.engine }))].filter((e) => allowedExperts === undefined || allowedExperts.includes(e.id));
|
|
462
464
|
}
|
|
@@ -632,6 +634,32 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
632
634
|
.sort((a, b) => b.activeAt - a.activeAt);
|
|
633
635
|
}
|
|
634
636
|
|
|
637
|
+
/** 旧版飞书会话没有自动命名;只为当前要显示的会话从已有记录补首条消息。 */
|
|
638
|
+
async backfillFeishuTitles(list: ConversationInfo[]): Promise<ConversationInfo[]> {
|
|
639
|
+
return Promise.all(list.map(async (info) => {
|
|
640
|
+
const conv = getConversation(info.key);
|
|
641
|
+
if (!conv || conv.channel !== "feishu" || conv.title || conv.titleAuto === false) return info;
|
|
642
|
+
const { agent, cwd } = conv;
|
|
643
|
+
const sessionId = agentBinding(conv).sessionId;
|
|
644
|
+
const driver = this.enabledAgents().find((d) => d.id === agent);
|
|
645
|
+
if (!sessionId || !driver) return info;
|
|
646
|
+
try {
|
|
647
|
+
const messages = await withTimeout(driver.readHistory(sessionId, cwd), "读取会话标题", 3000);
|
|
648
|
+
const first = messages.find((m) => m.role === "user" && m.text.trim());
|
|
649
|
+
const now = getConversation(info.key);
|
|
650
|
+
// 读记录期间用户可能改名、切专家或切目录,不能把旧标题写进新会话。
|
|
651
|
+
if (first && now && !now.title && now.titleAuto !== false && now.agent === agent && now.cwd === cwd && agentBinding(now).sessionId === sessionId) {
|
|
652
|
+
updateConversation(info.key, { title: first.text.trim().replace(/\s+/g, " ").slice(0, 40), titleAuto: true });
|
|
653
|
+
this.emitEvent(info.key, { type: "meta" });
|
|
654
|
+
this.syncTitle(info.key, agent);
|
|
655
|
+
}
|
|
656
|
+
} catch (err) {
|
|
657
|
+
console.warn(`[${agent}] 补齐飞书会话标题失败:`, err instanceof Error ? err.message : err);
|
|
658
|
+
}
|
|
659
|
+
return this.info(info.key) ?? info;
|
|
660
|
+
}));
|
|
661
|
+
}
|
|
662
|
+
|
|
635
663
|
/** 取活着的 agent 会话,没有就按绑定拉起(默认续用上次的会话)。 */
|
|
636
664
|
session(key: string, opts: { resumeId?: string; fork?: boolean } = {}): AgentSession {
|
|
637
665
|
const conv = getConversation(key);
|
|
@@ -639,7 +667,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
639
667
|
// 先检查 agent 还启用着:设置里关掉了,已经打开的会话也不能再用
|
|
640
668
|
const driver = this.requireDriver(conv.agent);
|
|
641
669
|
// 撤回共享后,即使上一轮还在运行,也不能把新输入交给缓存着的会话。
|
|
642
|
-
if (
|
|
670
|
+
if (!canUseExpert(memoryOwnerOf(conv), conv.expert ?? conv.agent)) throw new Error("这条对话用的专家或 Agent 已删除、取消共享或未获授权。新开一个对话,换个专家吧。");
|
|
643
671
|
const existing = this.live.get(key);
|
|
644
672
|
if (existing && existing.agent === conv.agent && existing.cwd === conv.cwd && !opts.resumeId) {
|
|
645
673
|
return existing.session;
|
|
@@ -1016,7 +1044,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
1016
1044
|
// 闲置过期要按这次说话之前的活跃时间判断,所以先记下、后 touch
|
|
1017
1045
|
const lastActive = conv.activeAt;
|
|
1018
1046
|
touchConversation(key);
|
|
1019
|
-
if (!conv.title && conv.channel === "web" && shown.text.trim()) {
|
|
1047
|
+
if (!conv.title && conv.titleAuto !== false && (conv.channel === "web" || conv.channel === "feishu") && shown.text.trim()) {
|
|
1020
1048
|
// 先用首条消息占位,第一轮结束后换成 agent 自己生成的短标题(syncTitle)
|
|
1021
1049
|
updateConversation(key, { title: shown.text.trim().replace(/\s+/g, " ").slice(0, 40), titleAuto: true });
|
|
1022
1050
|
this.emitEvent(key, { type: "meta" });
|
package/src/core/servers.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import crypto from "node:crypto";
|
|
12
12
|
import os from "node:os";
|
|
13
13
|
import type { AppConfig } from "./config.js";
|
|
14
|
+
import { canUseResource, type User } from "./users.js";
|
|
14
15
|
|
|
15
16
|
export type ServerEntry = AppConfig["servers"]["list"][number];
|
|
16
17
|
|
|
@@ -106,11 +107,12 @@ export function selfName(cfg: AppConfig["servers"]): string {
|
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
/** 页面要的:左上角的切换列表。没加别的服务器就是 null(不显示切换) */
|
|
109
|
-
export function shellInfo(cfg: AppConfig["servers"]) {
|
|
110
|
-
|
|
110
|
+
export function shellInfo(cfg: AppConfig["servers"], user?: User) {
|
|
111
|
+
const list = cfg.list.filter((s) => !user || canUseResource(user, "servers", s.id));
|
|
112
|
+
if (list.length === 0) return null;
|
|
111
113
|
return {
|
|
112
114
|
self: { id: SELF_ID, name: selfName(cfg), icon: cfg.selfIcon },
|
|
113
|
-
list:
|
|
115
|
+
list: list.map(({ id, name, icon, url }) => ({ id, name, icon, url })),
|
|
114
116
|
};
|
|
115
117
|
}
|
|
116
118
|
|
package/src/core/task-runner.ts
CHANGED
|
@@ -51,18 +51,18 @@ type Resolved = { key: string } | { pause: string } | { error: string };
|
|
|
51
51
|
/** 这次该发到哪条对话;专用对话还没有(或者被删了)就新建一条 */
|
|
52
52
|
function resolveConv(task: Task): Resolved {
|
|
53
53
|
const missingExpert = (id: string | undefined) => !!id && !canUseExpert(task.owner, id);
|
|
54
|
-
const deletedExpert = { pause: "
|
|
54
|
+
const deletedExpert = { pause: "任务用的专家已经删除、取消共享,或专家 / Agent 未获授权,任务已暂停。编辑任务换一个专家再启用。" };
|
|
55
55
|
if (task.target.kind === "conv") {
|
|
56
56
|
const conv = getConversation(task.target.key);
|
|
57
57
|
if (!conv || conv.hidden) return { pause: "回复的那条对话已经被删除,任务已暂停。可以改成「专用对话」后再启用。" };
|
|
58
58
|
if (ownerOf(conv) !== task.owner) return { pause: "回复的那条对话已经不属于你了,任务已暂停。" };
|
|
59
|
-
if (missingExpert(conv.expert)) return deletedExpert;
|
|
59
|
+
if (missingExpert(conv.expert ?? conv.agent)) return deletedExpert;
|
|
60
60
|
return { key: conv.key };
|
|
61
61
|
}
|
|
62
62
|
// 复用专用对话前也要检查,不能等到新建对话时才发现专家已删除。
|
|
63
|
-
if (missingExpert(task.expert)) return deletedExpert;
|
|
63
|
+
if (missingExpert(task.expert ?? task.agent)) return deletedExpert;
|
|
64
64
|
const existing = task.target.key ? getConversation(task.target.key) : undefined;
|
|
65
|
-
if (existing && !existing.hidden && existing.taskId === task.id && ownerOf(existing) === task.owner) return missingExpert(existing.expert) ? deletedExpert : { key: existing.key };
|
|
65
|
+
if (existing && !existing.hidden && existing.taskId === task.id && ownerOf(existing) === task.owner) return missingExpert(existing.expert ?? existing.agent) ? deletedExpert : { key: existing.key };
|
|
66
66
|
|
|
67
67
|
// 专家被删了:不能换成别的专家去跑(权限可能大得多),暂停等用户改
|
|
68
68
|
const expert = task.expert ? getExpert(task.expert) : undefined;
|
package/src/core/ui-prefs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 每个用户的界面偏好,跟着账号走(换手机、换浏览器、桌面端都一样)。
|
|
2
|
-
//
|
|
2
|
+
// 侧栏菜单的显示、顺序,以及项目和飞书分组的混合顺序。
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { dataDir, readJson, writeJsonAtomic } from "../home.js";
|
|
5
5
|
|
|
@@ -29,7 +29,7 @@ function cleanDirs(list: unknown): string[] {
|
|
|
29
29
|
return [...new Set(list.filter((d): d is string => typeof d === "string" && d.length > 0 && d.length < 4096))].slice(0, MAX_DIRS);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/**
|
|
32
|
+
/** 分组顺序:项目用目录路径,飞书用 feishu:<机器人 id>。沿用旧字段,兼容已有项目排序。 */
|
|
33
33
|
export function getDirOrder(userId: string): string[] | undefined {
|
|
34
34
|
return load()[userId]?.dirOrder;
|
|
35
35
|
}
|
|
@@ -43,7 +43,7 @@ export function setDirOrder(userId: string, order: unknown): string[] {
|
|
|
43
43
|
return dirOrder;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
/**
|
|
46
|
+
/** 新分组接在最后。只追加没有的,不动已有的名次 —— 别的设备同时在拖也不会被盖掉 */
|
|
47
47
|
export function appendDirOrder(userId: string, dirs: unknown): string[] {
|
|
48
48
|
const all = load();
|
|
49
49
|
const cur = all[userId]?.dirOrder ?? [];
|
package/src/core/users.ts
CHANGED
|
@@ -16,6 +16,9 @@ import { dataDir, readJson, writeJsonAtomic } from "../home.js";
|
|
|
16
16
|
import { config } from "./config.js";
|
|
17
17
|
|
|
18
18
|
export type Role = "admin" | "member";
|
|
19
|
+
export type ResourceKind = "experts" | "agents" | "servers";
|
|
20
|
+
/** 未设置 / null = 全部(含以后新增);[] = 不允许使用。只限制成员。 */
|
|
21
|
+
export type ResourcePermissions = Partial<Record<ResourceKind, string[] | null>>;
|
|
19
22
|
|
|
20
23
|
export type User = {
|
|
21
24
|
id: string;
|
|
@@ -27,6 +30,7 @@ export type User = {
|
|
|
27
30
|
disabled?: boolean;
|
|
28
31
|
/** 成员能不能用远程控制(终端、桌面)。管理员一直能用,不看这个 */
|
|
29
32
|
remote?: boolean;
|
|
33
|
+
permissions?: ResourcePermissions;
|
|
30
34
|
};
|
|
31
35
|
|
|
32
36
|
export type PublicUser = Omit<User, "passwordHash">;
|
|
@@ -34,8 +38,8 @@ export type PublicUser = Omit<User, "passwordHash">;
|
|
|
34
38
|
type StoreShape = { users: User[] };
|
|
35
39
|
|
|
36
40
|
const usersPath = path.join(dataDir, "users.json");
|
|
37
|
-
/**
|
|
38
|
-
export const userEvents = new EventEmitter<{ changed: [] }>();
|
|
41
|
+
/** 登录态总要重新校验;accessChanged 只在使用权限、角色或可用账号发生变化时为 true。 */
|
|
42
|
+
export const userEvents = new EventEmitter<{ changed: [accessChanged: boolean] }>();
|
|
39
43
|
|
|
40
44
|
let cache: User[] | null = null;
|
|
41
45
|
let loadedMtime = 0;
|
|
@@ -67,11 +71,11 @@ function load(): User[] {
|
|
|
67
71
|
return cache;
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
function save(list: User[]): void {
|
|
74
|
+
function save(list: User[], accessChanged = true): void {
|
|
71
75
|
cache = list;
|
|
72
76
|
writeJsonAtomic(usersPath, { users: list });
|
|
73
77
|
loadedMtime = mtimeOf(usersPath);
|
|
74
|
-
userEvents.emit("changed");
|
|
78
|
+
userEvents.emit("changed", accessChanged);
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
/**
|
|
@@ -99,7 +103,7 @@ function newId(): string {
|
|
|
99
103
|
|
|
100
104
|
function publicUser(u: User): PublicUser {
|
|
101
105
|
const { passwordHash: _hidden, ...rest } = u;
|
|
102
|
-
return
|
|
106
|
+
return structuredClone(rest);
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
// ---------- 密码 ----------
|
|
@@ -173,6 +177,23 @@ export function canUseRemote(user: Pick<User, "role" | "disabled" | "remote"> |
|
|
|
173
177
|
return user.role === "admin" || user.remote === true;
|
|
174
178
|
}
|
|
175
179
|
|
|
180
|
+
export function canUseResource(user: Pick<User, "role" | "disabled" | "permissions"> | undefined, kind: ResourceKind, id: string): boolean {
|
|
181
|
+
if (!user || user.disabled) return false;
|
|
182
|
+
return user.role === "admin" || user.permissions?.[kind] == null || user.permissions[kind]!.includes(id);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function cleanPermissions(value: unknown, current: ResourcePermissions = {}): ResourcePermissions {
|
|
186
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("使用权限格式不对");
|
|
187
|
+
const next = structuredClone(current);
|
|
188
|
+
for (const [kind, ids] of Object.entries(value)) {
|
|
189
|
+
if (!["experts", "agents", "servers"].includes(kind)) throw new Error("未知的使用权限");
|
|
190
|
+
if (ids !== null && (!Array.isArray(ids) || ids.length > 200 || ids.some((id) => typeof id !== "string" || !/^[\w-]{1,100}$/.test(id)))) throw new Error("使用权限必须是 ID 列表或 null");
|
|
191
|
+
if (kind === "agents" && ids?.some((id: string) => !["claude", "codex"].includes(id))) throw new Error("未知的内置 Agent");
|
|
192
|
+
next[kind as ResourceKind] = ids === null ? null : [...new Set(ids as string[])];
|
|
193
|
+
}
|
|
194
|
+
return next;
|
|
195
|
+
}
|
|
196
|
+
|
|
176
197
|
/**
|
|
177
198
|
* 升级前的登录态、推送订阅没有记是谁的:都算最早的那个管理员的(就是迁移出来的 admin)。
|
|
178
199
|
*/
|
|
@@ -212,7 +233,7 @@ function assertAdminLeft(list: User[]): void {
|
|
|
212
233
|
if (!list.some((u) => u.role === "admin" && !u.disabled)) throw new Error("至少要保留一个能登录的管理员");
|
|
213
234
|
}
|
|
214
235
|
|
|
215
|
-
export function createUser(params: { name: string; password: string; role?: Role }): PublicUser {
|
|
236
|
+
export function createUser(params: { name: string; password: string; role?: Role; remote?: boolean; permissions?: unknown }): PublicUser {
|
|
216
237
|
const list = load();
|
|
217
238
|
const name = checkName(params.name);
|
|
218
239
|
if (list.some((u) => u.name.toLowerCase() === name.toLowerCase())) throw new Error(`用户名「${name}」已经有人用了`);
|
|
@@ -223,6 +244,8 @@ export function createUser(params: { name: string; password: string; role?: Role
|
|
|
223
244
|
role: params.role === "admin" ? "admin" : "member",
|
|
224
245
|
passwordHash: hashPassword(params.password),
|
|
225
246
|
createdAt: Date.now(),
|
|
247
|
+
...(params.remote === true ? { remote: true } : {}),
|
|
248
|
+
...(params.permissions !== undefined ? { permissions: cleanPermissions(params.permissions) } : {}),
|
|
226
249
|
};
|
|
227
250
|
save([...list, user]);
|
|
228
251
|
return publicUser(user);
|
|
@@ -230,7 +253,7 @@ export function createUser(params: { name: string; password: string; role?: Role
|
|
|
230
253
|
|
|
231
254
|
export function updateUser(
|
|
232
255
|
id: string,
|
|
233
|
-
patch: { name?: string; role?: Role; disabled?: boolean; password?: string; remote?: boolean },
|
|
256
|
+
patch: { name?: string; role?: Role; disabled?: boolean; password?: string; remote?: boolean; permissions?: unknown },
|
|
234
257
|
): PublicUser {
|
|
235
258
|
const list = load().map((u) => ({ ...u }));
|
|
236
259
|
const user = list.find((u) => u.id === id);
|
|
@@ -249,12 +272,13 @@ export function updateUser(
|
|
|
249
272
|
if (patch.remote) user.remote = true;
|
|
250
273
|
else delete user.remote;
|
|
251
274
|
}
|
|
275
|
+
if (patch.permissions !== undefined) user.permissions = cleanPermissions(patch.permissions, user.permissions);
|
|
252
276
|
if (patch.password !== undefined) {
|
|
253
277
|
checkPassword(patch.password);
|
|
254
278
|
user.passwordHash = hashPassword(patch.password);
|
|
255
279
|
}
|
|
256
280
|
assertAdminLeft(list);
|
|
257
|
-
save(list);
|
|
281
|
+
save(list, patch.permissions !== undefined || patch.role !== undefined || patch.disabled !== undefined);
|
|
258
282
|
return publicUser(user);
|
|
259
283
|
}
|
|
260
284
|
|
package/web/css/settings.css
CHANGED
|
@@ -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;
|