agent-loft 0.2.65 → 0.2.67
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 +6 -6
- package/package.json +1 -1
- package/src/channels/feishu/bot.ts +59 -16
- package/src/channels/feishu/index.ts +3 -1
- package/src/channels/web/api.ts +34 -12
- package/src/channels/web/conv-pages.ts +1 -1
- package/src/channels/web/experts-api.ts +34 -14
- package/src/channels/web/server.ts +8 -0
- package/src/core/config.ts +6 -0
- package/src/core/experts.ts +91 -15
- package/src/core/feishu-experts.ts +28 -0
- package/src/core/hub.ts +68 -18
- package/src/core/task-runner.ts +3 -3
- package/src/core/tasks.ts +1 -1
- package/web/css/sidebar.css +42 -0
- package/web/lib/overlay.js +6 -9
- package/web/lib/ws.js +4 -0
- package/web/settings/experts.js +53 -10
- package/web/settings/feishu.js +39 -15
- package/web/views/conv-actions.js +3 -6
- package/web/views/experts.js +1 -1
- package/web/views/sidebar-nav.js +0 -4
- package/web/views/sidebar.js +69 -15
- package/web/views/topbar.js +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
|
|
|
27
27
|
|---|---|---|
|
|
28
28
|
| 🤖 | **同时管理多个 agent** | Claude Code(官方 Claude Agent SDK)和 Codex(官方 `codex app-server`)共用会话列表、工作目录和授权。新建对话时选专家:内置的 Claude Code / Codex,或者自己配的专家 |
|
|
29
29
|
| 🧑🏫 | **专家** | 自己配专家:选引擎、写提示词,定它能做什么(只能联网 / 读文件 / 改文件 / 跑命令),挂哪些技能和 MCP,能把活派给哪些子智能体。新对话、定时任务都能选 |
|
|
30
|
-
| 🔀 | **飞书机器人灵活绑定 agent** |
|
|
30
|
+
| 🔀 | **飞书机器人灵活绑定 agent** | 机器人数量不限,每个机器人可以直接勾选内置或共享专家,并选择默认专家(可在会话里切换)。网页上扫码就能创建,改完立即生效;由服务端主动连向飞书,家里没有公网 IP 也能在外面用 |
|
|
31
31
|
| 🔗 | **飞书续接 Web 任务** | 飞书里发 `/web` 接上一条 Web 会话,或者在网页侧栏右键会话选「在飞书继续…」。之后回复、授权、提问都发到飞书,发 `/detach` 回来 |
|
|
32
32
|
| 🖥️ | **完整的 Web 工作台** | 流式回复、附件、语音输入、模型和思考程度切换、上下文占用、从任意回复分叉、按项目分组的侧栏、搜索会话、全部设置,电脑和手机(PWA)都能用 |
|
|
33
33
|
| 🔔 | **飞书 + 苹果系统推送** | 除了飞书消息,Web 会话还能推送到 iPhone、iPad 锁屏和 Mac 通知中心(标准 Web Push,不需要开发者账号),图标上显示未读数 |
|
|
@@ -36,7 +36,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
|
|
|
36
36
|
## 能做什么
|
|
37
37
|
|
|
38
38
|
- **多个 agent**:Claude Code、Codex。两个 agent 共用工作目录,能看到对方改过的文件,但聊天记录各自独立。
|
|
39
|
-
-
|
|
39
|
+
- **多个飞书机器人**:设置 → 飞书 →「可用专家」直接勾选内置或共享专家,并选择「默认专家」。只勾一个共享专家即可专用,不用再勾选底层 Agent;每个人绑定自己的账号后,直接私聊就是这个专家,使用各自的记忆和工具。机器人能在 Web 上扫码创建(Lark 国际版用「手动添加」),改完配置立即生效,不用重启。
|
|
40
40
|
- 群聊里要 @ 机器人;不同话题是各自独立的会话;支持文字、富文本、图片、文件、语音和视频。
|
|
41
41
|
- 思考和工具调用显示在实时刷新的过程卡片里,最终回复是普通消息。
|
|
42
42
|
- 陌生人发消息会拿到配对码,在设置页批准后才能使用;每个机器人单独授权。
|
|
@@ -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,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
|
|
|
61
61
|
- 用户消息的复制按钮后有「回退到此处」图标:把这条消息及附件放回输入框,并删除它及之后的聊天内容,重新发送时从之前的上下文继续。
|
|
62
62
|
- 太长的消息先收起,点「展开显示」看全文;对话里有至少 3 条用户消息时,右侧显示快速定位尺,电脑上鼠标移入查看消息开头、点击跳转;手机上手动滚动时显示短轨道,按住拖动可预览问题和位置,松手跳转,停止操作约 1.6 秒后隐藏。
|
|
63
63
|
- 回复底部的 token 数自动按大小显示为 K、M 等单位。
|
|
64
|
-
-
|
|
64
|
+
- 侧栏按页加载:每个项目目录和飞书机器人分组先显示 5 条,点「展开显示」每次再拉 10 条。
|
|
65
65
|
- 侧栏底部显示 Claude / Codex 的订阅额度(5 小时 / 7 天窗口,以及多久后重置);关了额度查询就整块不显示。
|
|
66
66
|
- 右上角「更多」最下面显示当前会话累计消耗的 token 分布(输入 / 缓存写入 / 缓存读取 / 输出,Claude 还有按 API 价格估算的费用)。设置也在「更多」里。
|
|
67
67
|
- 设置 → 用量:按日 / 月 / 年(默认按月)统计 token 和金额,有每天(每月)的柱状图,按 agent、模型、用户(管理员才有)分开看;成员只看到自己的。管理员还可查看服务端本机直接使用的 Claude Code、Codex 桌面端和 CLI 用量,和 Agent Loft 的用量分开显示、避免重复计算。金额都是按 API 价格算的参考值:Agent Loft 的 Claude 用它自己报的费用,Codex 和直接用的 Claude Code 按模型单价 × token 估算(OpenAI 单价来自 LiteLLM 公开价格表,内置快照、联网时每天更新)。Agent Loft 的账从 0.2.34 开始记录;本机直接使用的用量可回溯已有会话记录。
|
|
@@ -70,9 +70,9 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
|
|
|
70
70
|
- **系统通知**:Web 会话回复完成、出错、需要授权或提问时推送到手机 / 电脑(设置 → 通知 → 「在此设备开启通知」,可以发测试通知)。飞书会话由飞书提醒,正在前台看着的会话不推。需要 HTTPS 访问,iPhone 需 iOS 16.4+ 且从主屏幕图标打开。
|
|
71
71
|
- **跨渠道同步**:飞书里的会话在 Web 上也能打开接着聊。同一个授权请求同时出现在飞书卡片和网页上,哪边先点算哪边,另一边自动变成「已处理」。
|
|
72
72
|
- **授权**:允许一次 / 本会话全部允许 / 总是允许(按钮上写明放行范围)/ 拒绝。`/autoedit on` 让 Claude Code 在这条会话里改工作目录内的文件不再询问(Bash 仍询问)。超时一律按拒绝处理。
|
|
73
|
-
- **设置都在网页上**,按用途分组:**我的**(账号和密码、飞书绑定、登录设备、通知、记忆、技能、用量,每个人都有);**Agent**(运行环境、各 agent 的默认模型和思考程度、可选模型、Codex 沙箱、额度查询;工作目录、会话闲置过期、授权卡超时和 Claude
|
|
73
|
+
- **设置都在网页上**,按用途分组:**我的**(账号和密码、飞书绑定、登录设备、通知、记忆、技能、用量,每个人都有);**Agent**(运行环境、各 agent 的默认模型和思考程度、可选模型、Codex 沙箱、额度查询;工作目录、会话闲置过期、授权卡超时和 Claude 的「总是允许」名单;「/」命令);**连接**(飞书机器人、配对批准、指令面板同步;远程控制;服务器);**管理**(用户、所有人的登录设备;服务端版本和升级、重启、局域网访问和端口)。设置、新建 / 编辑专家、重命名等编辑弹窗不会因点击外部或按 Esc 关闭;通过关闭、取消或保存 / 完成按钮退出。改了没保存就切页或关掉设置会先提醒。
|
|
74
74
|
- **多用户**(信任型):管理员在 设置 → 用户 里给别人建账号。每个人只看得到自己的对话、授权和通知,设置只有管理员能改,见下面「安全」。
|
|
75
|
-
- **专家**:设置 → 专家。专家是一份配置,新建对话、定时任务时选一个,对话从头到尾都是它(中途不能换;飞书里 `/expert 名字`、`/claude`、`/codex` 换专家会开新会话)。**内置专家**:Claude Code、Codex,保留原装提示词和所有工具,默认技能与 MCP 在「设置 → Agent
|
|
75
|
+
- **专家**:设置 → 专家。专家是一份配置,新建对话、定时任务时选一个,对话从头到尾都是它(中途不能换;飞书里 `/expert 名字`、`/claude`、`/codex` 换专家会开新会话)。**内置专家**:Claude Code、Codex,保留原装提示词和所有工具,默认技能与 MCP 在「设置 → Agent」中按账号、按引擎分别选择。**自定义专家**由创建者管理,可以勾选「共享给所有账号」。共享后,其他人能在网页、绑定账号后的飞书私聊和定时任务中选择它;只有创建者能修改设定。每个人在该专家的「我的工具」里选择自己的技能和 MCP,使用各自的变量、凭据、记忆和聊天记录;创建者沿用原有工具选择,其他人未配置时不加载技能或 MCP。取消共享后,其他人的历史对话保留,后续消息不能继续调用该专家,相关定时任务在下次运行时暂停。可以配:
|
|
76
76
|
- 头像(点头像区域的加号上传;未上传时,会话中用引擎的图标)、引擎(Claude / Codex,建好后不能换)、默认模型和思考程度(从模型列表里选);
|
|
77
77
|
- 提示词:人设、规则、输出格式。agent-loft 在后面自动补上这个专家能做什么、今天的日期、记忆。Claude 专家默认只用这段提示词(一句话约 2 千 token),也可以选「追加在 Claude Code 原装提示词后面」(干活更稳,每轮多约 1.6 万);Codex 的基础指令改不了,专家的提示词附在第一条消息后面,约束力弱一些;
|
|
78
78
|
- 权限,勾选:联网搜索、读网页,以及文件权限(一级包含一级):都不勾就是**只能联网**(不碰本机文件、不弹授权,文本附件内容直接放进消息)/**能读文件**/**能改文件**/**能跑命令**(跑命令就等于能改任何文件,需要授权时弹卡)。Claude 按权限给工具;Codex 按权限开 shell、apply_patch,沙箱只读或 workspace-write;
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ import os from "node:os";
|
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import * as Lark from "@larksuiteoapi/node-sdk";
|
|
10
10
|
import { config, type FeishuBotConfig } from "../../core/config.js";
|
|
11
|
+
import { botAgentIds, botExpertIds } from "../../core/feishu-experts.js";
|
|
11
12
|
import { hub, type CommandReply, type EventEnvelope } from "../../core/hub.js";
|
|
12
13
|
import { interactions, type Interaction } from "../../core/interactions.js";
|
|
13
14
|
import { parseCommand } from "../../core/commands.js";
|
|
@@ -96,11 +97,12 @@ export class FeishuBot {
|
|
|
96
97
|
* 飞书的指令面板是整个应用一份,不分会话,没法跟着每个会话当前的 agent 变。
|
|
97
98
|
*/
|
|
98
99
|
private async slashCommands(): Promise<CommandEntry[]> {
|
|
99
|
-
const
|
|
100
|
+
const allowed = this.allowedAgents();
|
|
101
|
+
const agents = [this.cfg.defaultAgent, ...allowed.filter((a) => a !== this.cfg.defaultAgent)].filter((a) => allowed.includes(a));
|
|
100
102
|
const out: CommandEntry[] = [];
|
|
101
103
|
for (const agent of agents) {
|
|
102
104
|
if (!hub.driver(agent)) continue;
|
|
103
|
-
out.push(...(await hub.commandCatalog(agent, { allowedAgents:
|
|
105
|
+
out.push(...(await hub.commandCatalog(agent, { allowedAgents: allowed, channel: "feishu" })).filter((c) => !["claude", "codex"].includes(c.name) || this.cfg.experts === undefined || this.cfg.experts.includes(c.name)));
|
|
104
106
|
}
|
|
105
107
|
return out;
|
|
106
108
|
}
|
|
@@ -132,7 +134,7 @@ export class FeishuBot {
|
|
|
132
134
|
/** 这个机器人能用的 agent:配置里勾选的 ∩ 已启用的 */
|
|
133
135
|
allowedAgents(): string[] {
|
|
134
136
|
const enabled = new Set(hub.enabledAgents().map((d) => d.id));
|
|
135
|
-
return this.cfg.
|
|
137
|
+
return botAgentIds(this.cfg).filter((a) => enabled.has(a));
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
/** 某条会话能切到哪些 agent:自己的会话按机器人的勾选;接着的 Web 会话和 Web 上一样,启用的都行 */
|
|
@@ -140,6 +142,22 @@ export class FeishuBot {
|
|
|
140
142
|
return this.mine(key) ? this.allowedAgents() : hub.enabledAgents().map((d) => d.id);
|
|
141
143
|
}
|
|
142
144
|
|
|
145
|
+
private expertsFor(key: string): string[] | undefined {
|
|
146
|
+
return this.mine(key) ? botExpertIds(this.cfg) : undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** 下载附件、旧卡片点击期间配置可能变化,真正发送前再核对一次。 */
|
|
150
|
+
private send(...args: Parameters<typeof hub.send>): void {
|
|
151
|
+
const [key] = args;
|
|
152
|
+
const selected = this.expertsFor(key);
|
|
153
|
+
const conv = getConversation(key);
|
|
154
|
+
if (selected !== undefined && (!conv || !selected.includes(conv.expert ?? conv.agent))) {
|
|
155
|
+
hub.notice(key, "这个聊天的专家已不在机器人的可用列表中,请重新发消息以选择默认专家。");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
hub.send(...args);
|
|
159
|
+
}
|
|
160
|
+
|
|
143
161
|
// ---------- 这个聊天能碰哪些东西 ----------
|
|
144
162
|
//
|
|
145
163
|
// 飞书聊天自己的会话有主人(绑定了账号的私聊,见 core/feishu-links.ts):按主人算,和他在 Web 上一样;
|
|
@@ -629,20 +647,21 @@ export class FeishuBot {
|
|
|
629
647
|
if (!text && attachments.length === 0) return;
|
|
630
648
|
|
|
631
649
|
const allowed = this.allowedAgents();
|
|
632
|
-
if (allowed.length === 0) {
|
|
633
|
-
await this.client.sendText(chatId, "
|
|
650
|
+
if (allowed.length === 0 && feishuCommandOf(text)?.kind !== "bind") {
|
|
651
|
+
await this.client.sendText(chatId, "这个机器人没有可用的专家。所选专家可能已取消共享、删除,或引擎已停用;请在设置 → 飞书中重新选择。");
|
|
634
652
|
return;
|
|
635
653
|
}
|
|
636
654
|
|
|
637
655
|
const ownKey = this.keyOf(chatId, message.thread_id);
|
|
656
|
+
const fresh = !getConversation(ownKey);
|
|
638
657
|
const conv = hub.ensure({
|
|
639
658
|
key: ownKey,
|
|
640
659
|
channel: "feishu",
|
|
641
660
|
channelId: this.cfg.id,
|
|
642
|
-
defaultAgent: allowed.includes(this.cfg.defaultAgent) ? this.cfg.defaultAgent : allowed[0]
|
|
661
|
+
defaultAgent: allowed.includes(this.cfg.defaultAgent) ? this.cfg.defaultAgent : allowed[0] ?? this.cfg.defaultAgent,
|
|
643
662
|
});
|
|
644
|
-
//
|
|
645
|
-
if (!allowed.includes(conv.agent)) {
|
|
663
|
+
// 旧配置按引擎选择;明确选择专家的新配置在下面通过 setExpert 切换,清掉旧上下文。
|
|
664
|
+
if (this.cfg.experts === undefined && !allowed.includes(conv.agent)) {
|
|
646
665
|
updateConversation(ownKey, { agent: allowed.includes(this.cfg.defaultAgent) ? this.cfg.defaultAgent : allowed[0]! });
|
|
647
666
|
}
|
|
648
667
|
const operator = openId!.trim().toLowerCase();
|
|
@@ -651,7 +670,8 @@ export class FeishuBot {
|
|
|
651
670
|
// 私聊的主人跟着发消息的人的绑定走:绑定了就是他的个人会话(用他的记忆),解绑了就回到管理员的地盘。
|
|
652
671
|
// 群聊不动:群里不止一个人
|
|
653
672
|
const p2p = message.chat_type === "p2p";
|
|
654
|
-
|
|
673
|
+
const ownerChanged = p2p && hub.reassignOwner(ownKey, linkedUser(this.cfg.id, operator)?.id);
|
|
674
|
+
if (ownerChanged) {
|
|
655
675
|
const owner = this.viewerOf(ownKey);
|
|
656
676
|
console.log(`${this.tag} 私聊 ${ownKey} 的主人变为 ${owner?.name ?? "(无,归管理员)"}`);
|
|
657
677
|
}
|
|
@@ -667,11 +687,23 @@ export class FeishuBot {
|
|
|
667
687
|
const key = this.attachedWeb(ownKey) ?? ownKey;
|
|
668
688
|
this.operators.set(pairKey(key, chatId), operator);
|
|
669
689
|
|
|
690
|
+
const selected = this.expertsFor(key);
|
|
691
|
+
let noExpert = false;
|
|
692
|
+
if (selected !== undefined) {
|
|
693
|
+
const choices = hub.expertChoices(this.viewerOf(ownKey)?.id, allowed, selected);
|
|
694
|
+
noExpert = choices.length === 0;
|
|
695
|
+
if (!noExpert && (fresh || ownerChanged || !choices.some((e) => e.id === (conv.expert ?? conv.agent)))) {
|
|
696
|
+
const preferred = choices.find((e) => e.id === this.cfg.defaultExpert) ?? choices[0]!;
|
|
697
|
+
await hub.setExpert(ownKey, preferred.id, allowed, selected);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
670
701
|
const command = attachments.length > 0 ? ({ kind: "chat", text } as const) : parseCommand(text);
|
|
671
702
|
if (command.kind !== "chat") {
|
|
672
703
|
try {
|
|
673
704
|
const reply = await hub.command(key, command, {
|
|
674
705
|
allowedAgents: this.allowedFor(key),
|
|
706
|
+
allowedExperts: this.expertsFor(key),
|
|
675
707
|
by: "飞书命令",
|
|
676
708
|
channel: "feishu",
|
|
677
709
|
// 别人的 agent 会话、挂着的请求,这个聊天里都碰不到
|
|
@@ -684,13 +716,18 @@ export class FeishuBot {
|
|
|
684
716
|
return;
|
|
685
717
|
}
|
|
686
718
|
|
|
719
|
+
if (noExpert) {
|
|
720
|
+
await this.client.sendText(chatId, p2p ? "这个机器人使用共享专家。请先在网页「设置 → 账号 → 飞书账号」生成绑定码,再私聊发送 /bind 绑定码,即可使用你自己的记忆和工具。" : "这个机器人只选择了共享专家,请在私聊中绑定你自己的账号后使用。");
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
|
|
687
724
|
void this.markTyping(key, message.message_id);
|
|
688
725
|
const origin = { channel: "feishu", channelId: this.cfg.id, name: "飞书", chatId };
|
|
689
726
|
// 收到消息这一刻的代次:下载附件期间点了 /stop、或者 /cd /new 换了会话,这条就作废
|
|
690
727
|
const gen = hub.generation(key);
|
|
691
728
|
this.enqueue(key, async () => {
|
|
692
729
|
if (attachments.length === 0) {
|
|
693
|
-
|
|
730
|
+
this.send(key, { text: command.text, attachments: [] }, origin, gen);
|
|
694
731
|
return;
|
|
695
732
|
}
|
|
696
733
|
const { saved, failed } = await this.download(key, message.message_id, attachments);
|
|
@@ -704,7 +741,7 @@ export class FeishuBot {
|
|
|
704
741
|
this.clearTyping(key);
|
|
705
742
|
return;
|
|
706
743
|
}
|
|
707
|
-
|
|
744
|
+
this.send(key, { text: command.text, attachments: saved }, origin, gen);
|
|
708
745
|
});
|
|
709
746
|
}
|
|
710
747
|
|
|
@@ -746,19 +783,25 @@ export class FeishuBot {
|
|
|
746
783
|
try {
|
|
747
784
|
if (cmd.kind === "web") await this.sendWebList(ownKey, chatId);
|
|
748
785
|
else if (cmd.kind === "detach") await this.client.sendCard(chatId, replyCard(this.detachFrom(ownKey)));
|
|
749
|
-
else await this.client.sendCard(chatId, replyCard(this.bind(cmd.code, ownKey, sender)));
|
|
786
|
+
else await this.client.sendCard(chatId, replyCard(await this.bind(cmd.code, ownKey, sender)));
|
|
750
787
|
} catch (err) {
|
|
751
788
|
await this.client.sendText(chatId, `出错了:${err instanceof Error ? err.message : String(err)}`);
|
|
752
789
|
}
|
|
753
790
|
}
|
|
754
791
|
|
|
755
792
|
/** /bind 绑定码:把发消息的人的飞书账号绑到生成这个码的 agent-loft 用户上 */
|
|
756
|
-
private bind(code: string, ownKey: string, sender: { openId: string; p2p: boolean } | undefined): string {
|
|
793
|
+
private async bind(code: string, ownKey: string, sender: { openId: string; p2p: boolean } | undefined): Promise<string> {
|
|
757
794
|
if (!sender) return "请直接在聊天里发 `/bind 绑定码`。";
|
|
758
795
|
// 群里发的码别人也看得见,而且群聊本来就不归个人:只在私聊里绑
|
|
759
796
|
if (!sender.p2p) return "请在和我的私聊里发 `/bind 绑定码`(群里别人也看得到绑定码)。绑定码已经露出来了的话,到 Web 上重新生成一个。";
|
|
760
797
|
const user = redeemLinkCode(code, this.cfg.id, sender.openId);
|
|
761
798
|
hub.reassignOwner(ownKey, user.id);
|
|
799
|
+
const selected = this.expertsFor(ownKey);
|
|
800
|
+
if (selected !== undefined) {
|
|
801
|
+
const choices = hub.expertChoices(user.id, this.allowedAgents(), selected);
|
|
802
|
+
const preferred = choices.find((e) => e.id === this.cfg.defaultExpert) ?? choices[0];
|
|
803
|
+
if (preferred) await hub.setExpert(ownKey, preferred.id, this.allowedAgents(), selected);
|
|
804
|
+
}
|
|
762
805
|
console.log(`${this.tag} ${sender.openId} 绑定到用户 ${user.name}`);
|
|
763
806
|
return [
|
|
764
807
|
`已绑定到 agent-loft 用户 **${user.name}**。`,
|
|
@@ -917,7 +960,7 @@ export class FeishuBot {
|
|
|
917
960
|
case "effort":
|
|
918
961
|
return this.background(envelope.k, chatId, `思考程度设为 ${envelope.f}`, () => hub.setEffort(envelope.k, envelope.f));
|
|
919
962
|
case "agent":
|
|
920
|
-
return this.background(envelope.k, chatId, "正在换专家…", () => hub.setExpert(envelope.k, envelope.g, this.allowedFor(envelope.k)));
|
|
963
|
+
return this.background(envelope.k, chatId, "正在换专家…", () => hub.setExpert(envelope.k, envelope.g, this.allowedFor(envelope.k), this.expertsFor(envelope.k)));
|
|
921
964
|
case "cmd":
|
|
922
965
|
return this.runCardCommand(envelope.k, chatId, operatorOpenId, `/${envelope.c}`);
|
|
923
966
|
case "attach": {
|
|
@@ -966,11 +1009,11 @@ export class FeishuBot {
|
|
|
966
1009
|
if (command.kind === "chat") {
|
|
967
1010
|
const origin = { channel: "feishu", channelId: this.cfg.id, name: "飞书", chatId: chat };
|
|
968
1011
|
const gen = hub.generation(key);
|
|
969
|
-
this.enqueue(key, async () =>
|
|
1012
|
+
this.enqueue(key, async () => this.send(key, { text, attachments: [] }, origin, gen));
|
|
970
1013
|
return { toast: { type: "success", content: `已发送 ${text}` } };
|
|
971
1014
|
}
|
|
972
1015
|
void hub
|
|
973
|
-
.command(key, command, { allowedAgents: this.allowedFor(key), by: "飞书命令", channel: "feishu", ...this.commandScope(ownKey) })
|
|
1016
|
+
.command(key, command, { allowedAgents: this.allowedFor(key), allowedExperts: this.expertsFor(key), by: "飞书命令", channel: "feishu", ...this.commandScope(ownKey) })
|
|
974
1017
|
.then((reply) => this.renderReply(key, chat, reply))
|
|
975
1018
|
.catch((err) => this.client.sendText(chat, `出错了:${err instanceof Error ? err.message : String(err)}`));
|
|
976
1019
|
return { toast: { type: "info", content: `正在执行 ${text}` } };
|
|
@@ -23,6 +23,8 @@ function reconcile(list: FeishuBotConfig[]): void {
|
|
|
23
23
|
for (const [id, cfg] of wanted) {
|
|
24
24
|
const existing = bots.get(id);
|
|
25
25
|
if (existing) {
|
|
26
|
+
delete existing.cfg.experts;
|
|
27
|
+
delete existing.cfg.defaultExpert;
|
|
26
28
|
Object.assign(existing.cfg, cfg);
|
|
27
29
|
continue;
|
|
28
30
|
}
|
|
@@ -42,7 +44,7 @@ export function startFeishu(): void {
|
|
|
42
44
|
for (const bot of bots.values()) {
|
|
43
45
|
const before = prev.feishu.bots.find((b) => b.id === bot.id);
|
|
44
46
|
const agentsChanged =
|
|
45
|
-
!before || JSON.stringify([before.agents, before.defaultAgent]) !== JSON.stringify([bot.cfg.agents, bot.cfg.defaultAgent]);
|
|
47
|
+
!before || JSON.stringify([before.agents, before.defaultAgent, before.experts, before.defaultExpert]) !== JSON.stringify([bot.cfg.agents, bot.cfg.defaultAgent, bot.cfg.experts, bot.cfg.defaultExpert]);
|
|
46
48
|
if (commandsChanged || agentsChanged) bot.slash.request();
|
|
47
49
|
}
|
|
48
50
|
});
|
package/src/channels/web/api.ts
CHANGED
|
@@ -75,7 +75,8 @@ import { handleLibraryApi } from "./library-api.js";
|
|
|
75
75
|
import { attachToConversation, canSeeFile, getLibraryFile } from "../../core/library.js";
|
|
76
76
|
import { handleSkillsApi } from "./skills-api.js";
|
|
77
77
|
import { handleExpertsApi } from "./experts-api.js";
|
|
78
|
-
import { canUseExpert, getExpert, isBuiltin
|
|
78
|
+
import { availableExperts, canUseExpert, getExpert, isBuiltin } from "../../core/experts.js";
|
|
79
|
+
import { botExpertSelection } from "../../core/feishu-experts.js";
|
|
79
80
|
import { expertBrief } from "./experts-api.js";
|
|
80
81
|
import { handleTerminalApi } from "./terminal.js";
|
|
81
82
|
import { handleDesktopApi, remoteStatus } from "./desktop.js";
|
|
@@ -265,7 +266,7 @@ type Registration = {
|
|
|
265
266
|
};
|
|
266
267
|
const registrations = new Map<string, Registration>();
|
|
267
268
|
|
|
268
|
-
async function startRegistration(name: string, agents: string[]): Promise<{ id: string } & Registration> {
|
|
269
|
+
async function startRegistration(name: string, agents: string[], selection?: ReturnType<typeof botExpertSelection>): Promise<{ id: string } & Registration> {
|
|
269
270
|
await initRegistration("feishu");
|
|
270
271
|
const begin = await beginRegistration("feishu");
|
|
271
272
|
const id = crypto.randomBytes(8).toString("hex");
|
|
@@ -291,6 +292,7 @@ async function startRegistration(name: string, agents: string[]): Promise<{ id:
|
|
|
291
292
|
allowFrom: outcome.result.openId ? [outcome.result.openId.toLowerCase()] : [],
|
|
292
293
|
agents: list.length ? list : ["claude"],
|
|
293
294
|
defaultAgent: list[0] ?? "claude",
|
|
295
|
+
...selection,
|
|
294
296
|
});
|
|
295
297
|
saveConfig(cfg);
|
|
296
298
|
reg.status = "success";
|
|
@@ -407,7 +409,14 @@ function applyConfig(input: Partial<AppConfig>, selfOrigin?: string): void {
|
|
|
407
409
|
const old = current.feishu.bots.find((o) => o.id === b.id);
|
|
408
410
|
// 前端拿到的是打码后的密钥,原样传回来表示「没改」
|
|
409
411
|
const secret = !b.appSecret || b.appSecret.startsWith(MASK) ? (old?.appSecret ?? "") : b.appSecret;
|
|
410
|
-
|
|
412
|
+
try {
|
|
413
|
+
if (old?.experts && JSON.stringify([b.experts, b.defaultExpert]) === JSON.stringify([old.experts, old.defaultExpert])) {
|
|
414
|
+
return { ...b, appSecret: secret, agents: old.agents, defaultAgent: old.defaultAgent };
|
|
415
|
+
}
|
|
416
|
+
return { ...b, appSecret: secret, ...(b.experts === undefined ? {} : botExpertSelection(b.experts, b.defaultExpert)) };
|
|
417
|
+
} catch (err) {
|
|
418
|
+
throw new HttpError(400, err instanceof Error ? err.message : String(err));
|
|
419
|
+
}
|
|
411
420
|
});
|
|
412
421
|
}
|
|
413
422
|
}
|
|
@@ -680,12 +689,12 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
680
689
|
}),
|
|
681
690
|
// 飞书机器人是管理员配的,飞书会话也只给管理员看
|
|
682
691
|
bots: admin ? config().feishu.bots.map((b) => ({ id: b.id, name: b.name, agents: b.agents, enabled: b.enabled })) : [],
|
|
683
|
-
//
|
|
684
|
-
experts:
|
|
692
|
+
// 自己的和共享的专家(新对话、定时任务里选)。内置的 Claude Code / Codex 就是上面的 agents
|
|
693
|
+
experts: availableExperts(user.id).map(expertBrief),
|
|
685
694
|
workspaceRoot: config().workspaceRoot,
|
|
686
695
|
quotaRefreshMin: config().web.quotaRefreshMin,
|
|
687
696
|
quotaEnabled: config().web.quotaEnabled,
|
|
688
|
-
conversations: [...keep.values()],
|
|
697
|
+
conversations: await hub.backfillFeishuTitles([...keep.values()]),
|
|
689
698
|
sidebar: {
|
|
690
699
|
recent: { next: recent.next },
|
|
691
700
|
// 展开着的目录带上翻页游标(没带 next 的目录前端还没拉过)
|
|
@@ -804,13 +813,19 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
804
813
|
}
|
|
805
814
|
|
|
806
815
|
// ----- 会话 -----
|
|
807
|
-
// 侧栏按页拉:
|
|
816
|
+
// 侧栏按页拉:recent / dir / bot 按树分页;bot 不传 limit 时保留历史弹窗的平铺列表。
|
|
808
817
|
if (p === "/api/conversations/page" && method === "GET") {
|
|
809
818
|
const all = hub.list(visible).filter((c) => !c.hidden);
|
|
810
819
|
const scope = url.searchParams.get("scope");
|
|
811
820
|
if (scope === "bot") {
|
|
812
821
|
const bot = url.searchParams.get("bot") ?? "";
|
|
813
|
-
|
|
822
|
+
const list = all.filter((c) => c.channel === "feishu" && c.channelId === bot);
|
|
823
|
+
const before = parseCursor(url.searchParams.get("at"), url.searchParams.get("key"));
|
|
824
|
+
const page = url.searchParams.has("limit")
|
|
825
|
+
? pageOf(list, before, clampLimit(url.searchParams.get("limit"), 5))
|
|
826
|
+
: { conversations: list.slice(0, 200), next: null };
|
|
827
|
+
page.conversations = await hub.backfillFeishuTitles(page.conversations);
|
|
828
|
+
sendJson(res, 200, page);
|
|
814
829
|
return;
|
|
815
830
|
}
|
|
816
831
|
if (scope !== "recent" && scope !== "dir") throw new HttpError(400, "scope 只能是 recent / dir / bot");
|
|
@@ -847,11 +862,12 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
847
862
|
return;
|
|
848
863
|
}
|
|
849
864
|
if (p === "/api/conversations" && method === "POST") {
|
|
850
|
-
// expert:新对话页上选的专家(内置的 claude / codex
|
|
865
|
+
// expert:新对话页上选的专家(内置的 claude / codex,或者自己的、共享的专家 id)。agent 是以前的叫法
|
|
851
866
|
const body = await readJsonBody<{ expert?: string; agent?: string; cwd?: string }>(req);
|
|
852
867
|
const enabled = hub.enabledAgents().map((d) => d.id);
|
|
853
868
|
const wanted = body.expert ?? body.agent;
|
|
854
|
-
|
|
869
|
+
if (wanted && !canUseExpert(user.id, wanted)) throw new HttpError(400, "这个专家不存在或已取消共享");
|
|
870
|
+
const expertId = wanted || enabled[0];
|
|
855
871
|
if (!expertId) throw new HttpError(400, "没有可用的 agent");
|
|
856
872
|
const custom = isBuiltin(expertId) ? undefined : getExpert(expertId);
|
|
857
873
|
const agent = custom ? custom.engine : expertId;
|
|
@@ -1500,8 +1516,14 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1500
1516
|
return;
|
|
1501
1517
|
}
|
|
1502
1518
|
if (p === "/api/feishu/register" && method === "POST") {
|
|
1503
|
-
const body = await readJsonBody<{ name?: string; agents?: string[] }>(req);
|
|
1504
|
-
|
|
1519
|
+
const body = await readJsonBody<{ name?: string; agents?: string[]; experts?: unknown; defaultExpert?: unknown }>(req);
|
|
1520
|
+
let selection: ReturnType<typeof botExpertSelection> | undefined;
|
|
1521
|
+
try {
|
|
1522
|
+
if (body.experts !== undefined) selection = botExpertSelection(body.experts, body.defaultExpert);
|
|
1523
|
+
} catch (err) {
|
|
1524
|
+
throw new HttpError(400, err instanceof Error ? err.message : String(err));
|
|
1525
|
+
}
|
|
1526
|
+
sendJson(res, 200, await startRegistration(String(body.name ?? ""), Array.isArray(body.agents) ? body.agents : [], selection));
|
|
1505
1527
|
return;
|
|
1506
1528
|
}
|
|
1507
1529
|
const regMatch = /^\/api\/feishu\/register\/([a-f0-9]+)$/.exec(p);
|
|
@@ -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;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 专家由创建者管理,可共享使用;工具选择和 MCP 配置按登录账号隔离。
|
|
2
2
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
3
3
|
import { userMcpServers } from "../../agents/codex/session.js";
|
|
4
4
|
import {
|
|
5
5
|
ACCESS_LABEL,
|
|
6
6
|
ACCESS_LEVELS,
|
|
7
|
+
availableExperts,
|
|
7
8
|
avatarImage,
|
|
8
9
|
avatarUrl,
|
|
9
10
|
createExpert,
|
|
11
|
+
canUseExpert,
|
|
10
12
|
deleteExpert,
|
|
11
13
|
EXPERT_LIMITS,
|
|
12
14
|
EXPERT_TEMPLATES,
|
|
13
15
|
getExpert,
|
|
14
|
-
|
|
16
|
+
expertTools,
|
|
15
17
|
updateExpert,
|
|
18
|
+
setExpertTools,
|
|
16
19
|
type Expert,
|
|
17
20
|
type ExpertInput,
|
|
18
21
|
} from "../../core/experts.js";
|
|
@@ -25,7 +28,8 @@ import { HttpError, readJsonBody, sendJson } from "./http.js";
|
|
|
25
28
|
|
|
26
29
|
const bad = (err: unknown) => (err instanceof HttpError ? err : new HttpError(400, err instanceof Error ? err.message : String(err)));
|
|
27
30
|
|
|
28
|
-
function expertView(e: Expert) {
|
|
31
|
+
function expertView(e: Expert, viewer: string) {
|
|
32
|
+
const tools = expertTools(viewer, e);
|
|
29
33
|
return {
|
|
30
34
|
id: e.id,
|
|
31
35
|
name: e.name,
|
|
@@ -44,9 +48,11 @@ function expertView(e: Expert) {
|
|
|
44
48
|
cwd: e.cwd ?? "",
|
|
45
49
|
webSearch: e.webSearch,
|
|
46
50
|
webFetch: e.webFetch,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
shared: e.shared === true,
|
|
52
|
+
editable: e.owner === viewer,
|
|
53
|
+
skills: tools.skills,
|
|
54
|
+
mcp: tools.mcp,
|
|
55
|
+
subagents: e.subagents.filter((id) => canUseExpert(viewer, id)),
|
|
50
56
|
memory: e.memory,
|
|
51
57
|
updatedAt: e.updatedAt,
|
|
52
58
|
};
|
|
@@ -55,6 +61,7 @@ function expertView(e: Expert) {
|
|
|
55
61
|
/** 选专家时要的那点信息(bootstrap 里给,/api/experts/brief 刷新) */
|
|
56
62
|
export function expertBrief(e: Expert) {
|
|
57
63
|
return {
|
|
64
|
+
shared: e.shared === true,
|
|
58
65
|
id: e.id,
|
|
59
66
|
name: e.name,
|
|
60
67
|
description: e.description,
|
|
@@ -108,7 +115,7 @@ export async function handleExpertsApi(req: IncomingMessage, res: ServerResponse
|
|
|
108
115
|
if (p === "/api/experts" && method === "GET") {
|
|
109
116
|
const enabled = hub.enabledAgents().map((d) => d.id);
|
|
110
117
|
sendJson(res, 200, {
|
|
111
|
-
experts:
|
|
118
|
+
experts: availableExperts(user.id).map((e) => expertView(e, user.id)),
|
|
112
119
|
builtin: enabled.map((id) => ({ id, name: hub.label(id), engine: id })),
|
|
113
120
|
engines: enabled,
|
|
114
121
|
templates: EXPERT_TEMPLATES.map((t) => ({ id: t.id, label: t.label, expert: t.expert })),
|
|
@@ -122,14 +129,14 @@ export async function handleExpertsApi(req: IncomingMessage, res: ServerResponse
|
|
|
122
129
|
}
|
|
123
130
|
|
|
124
131
|
if (p === "/api/experts/brief" && method === "GET") {
|
|
125
|
-
sendJson(res, 200, { experts:
|
|
132
|
+
sendJson(res, 200, { experts: availableExperts(user.id).map(expertBrief) });
|
|
126
133
|
return true;
|
|
127
134
|
}
|
|
128
135
|
|
|
129
136
|
if (p === "/api/experts" && method === "POST") {
|
|
130
137
|
const body = await readJsonBody<ExpertInput>(req, 1024 * 1024);
|
|
131
138
|
try {
|
|
132
|
-
sendJson(res, 200, expertView(createExpert(user.id, body)));
|
|
139
|
+
sendJson(res, 200, expertView(createExpert(user.id, body), user.id));
|
|
133
140
|
} catch (err) {
|
|
134
141
|
throw bad(err);
|
|
135
142
|
}
|
|
@@ -147,18 +154,31 @@ export async function handleExpertsApi(req: IncomingMessage, res: ServerResponse
|
|
|
147
154
|
return true;
|
|
148
155
|
}
|
|
149
156
|
|
|
157
|
+
const tm = /^\/api\/experts\/(e_[a-f0-9]+)\/tools$/.exec(p);
|
|
158
|
+
if (tm && method === "PUT") {
|
|
159
|
+
if (!canUseExpert(user.id, tm[1]!)) throw new HttpError(404, "这个专家不存在");
|
|
160
|
+
const body = await readJsonBody<unknown>(req);
|
|
161
|
+
try {
|
|
162
|
+
sendJson(res, 200, setExpertTools(user.id, tm[1]!, body));
|
|
163
|
+
} catch (err) {
|
|
164
|
+
throw bad(err);
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
|
|
150
169
|
const em = /^\/api\/experts\/(e_[a-f0-9]+)$/.exec(p);
|
|
151
170
|
if (em) {
|
|
152
171
|
const expert = getExpert(em[1]!);
|
|
153
|
-
if (!expert ||
|
|
172
|
+
if (!expert || !canUseExpert(user.id, expert.id)) throw new HttpError(404, "这个专家不存在");
|
|
154
173
|
if (method === "GET") {
|
|
155
|
-
sendJson(res, 200, expertView(expert));
|
|
174
|
+
sendJson(res, 200, expertView(expert, user.id));
|
|
156
175
|
return true;
|
|
157
176
|
}
|
|
177
|
+
if (expert.owner !== user.id) throw new HttpError(403, "只有创建者能修改或删除共享专家;你的工具可单独配置");
|
|
158
178
|
if (method === "PATCH") {
|
|
159
179
|
const body = await readJsonBody<ExpertInput>(req, 1024 * 1024);
|
|
160
180
|
try {
|
|
161
|
-
sendJson(res, 200, expertView(updateExpert(user.id, expert.id, body)));
|
|
181
|
+
sendJson(res, 200, expertView(updateExpert(user.id, expert.id, body), user.id));
|
|
162
182
|
} catch (err) {
|
|
163
183
|
throw bad(err);
|
|
164
184
|
}
|
|
@@ -177,9 +197,9 @@ export async function handleExpertsApi(req: IncomingMessage, res: ServerResponse
|
|
|
177
197
|
}
|
|
178
198
|
|
|
179
199
|
if (p === "/api/mcp" && method === "GET") {
|
|
180
|
-
const experts =
|
|
200
|
+
const experts = availableExperts(user.id);
|
|
181
201
|
sendJson(res, 200, {
|
|
182
|
-
servers: listMcp(user.id).map((s) => ({ ...mcpView(s), usedBy: experts.filter((e) => e.mcp.includes(s.id)).map((e) => e.name) })),
|
|
202
|
+
servers: listMcp(user.id).map((s) => ({ ...mcpView(s), usedBy: experts.filter((e) => expertTools(user.id, e).mcp.includes(s.id)).map((e) => e.name) })),
|
|
183
203
|
limits: MCP_LIMITS,
|
|
184
204
|
});
|
|
185
205
|
return true;
|
|
@@ -15,6 +15,7 @@ import { interactions, type Interaction } from "../../core/interactions.js";
|
|
|
15
15
|
import { getConversation } from "../../core/store.js";
|
|
16
16
|
import { taskEvents } from "../../core/tasks.js";
|
|
17
17
|
import { skillEvents } from "../../core/skills.js";
|
|
18
|
+
import { expertEvents } from "../../core/experts.js";
|
|
18
19
|
import { enforceTerminalAccess, killAllTerminals, terminalEvents, watchTerminalAccess } from "../../core/terminals.js";
|
|
19
20
|
import { RUNNING_VERSION } from "../../core/upgrade.js";
|
|
20
21
|
import type { Settlement } from "../../core/types.js";
|
|
@@ -239,6 +240,11 @@ function broadcastTerminals(owner: string): void {
|
|
|
239
240
|
/** 用户改了(比如远程控制权限被开通 / 收回)、远程控制的设置改了:页面重新问一下能用什么 */
|
|
240
241
|
function broadcastUsersChanged(): void {
|
|
241
242
|
for (const client of clients) send(client, { t: "remote" });
|
|
243
|
+
broadcastExperts();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function broadcastExperts(): void {
|
|
247
|
+
for (const client of clients) send(client, { t: "experts" });
|
|
242
248
|
}
|
|
243
249
|
|
|
244
250
|
/** 技能变了:以前装过别人技能的人也受影响,通知所有人重新拉(列表很小) */
|
|
@@ -571,6 +577,7 @@ export async function startWeb(): Promise<void> {
|
|
|
571
577
|
interactions.on("settled", broadcastInteraction);
|
|
572
578
|
taskEvents.on("changed", broadcastTasks);
|
|
573
579
|
skillEvents.on("changed", broadcastSkills);
|
|
580
|
+
expertEvents.on("changed", broadcastExperts);
|
|
574
581
|
terminalEvents.on("changed", broadcastTerminals);
|
|
575
582
|
userEvents.on("changed", broadcastUsersChanged);
|
|
576
583
|
watchTerminalAccess();
|
|
@@ -619,6 +626,7 @@ export async function stopWeb(): Promise<void> {
|
|
|
619
626
|
interactions.off("settled", broadcastInteraction);
|
|
620
627
|
taskEvents.off("changed", broadcastTasks);
|
|
621
628
|
skillEvents.off("changed", broadcastSkills);
|
|
629
|
+
expertEvents.off("changed", broadcastExperts);
|
|
622
630
|
terminalEvents.off("changed", broadcastTerminals);
|
|
623
631
|
userEvents.off("changed", broadcastUsersChanged);
|
|
624
632
|
stopWatchingRemote?.();
|
package/src/core/config.ts
CHANGED
|
@@ -26,6 +26,10 @@ export type FeishuBotConfig = {
|
|
|
26
26
|
agents: string[];
|
|
27
27
|
/** 新会话默认用哪个 agent,必须在 agents 里 */
|
|
28
28
|
defaultAgent: string;
|
|
29
|
+
/** 明确选择可用专家(内置 id 或共享专家 id);未设置时兼容旧的按引擎配置 */
|
|
30
|
+
experts?: string[];
|
|
31
|
+
/** 新聊天默认使用的专家,必须在 experts 中 */
|
|
32
|
+
defaultExpert?: string;
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
export type AppConfig = {
|
|
@@ -167,6 +171,7 @@ function mergeDefaults<T>(base: T, value: unknown): T {
|
|
|
167
171
|
function normalizeBot(raw: Partial<FeishuBotConfig>): FeishuBotConfig {
|
|
168
172
|
const agents = (raw.agents ?? []).filter((a) => (AGENT_IDS as readonly string[]).includes(a));
|
|
169
173
|
const list = agents.length > 0 ? agents : ["claude"];
|
|
174
|
+
const experts = Array.isArray(raw.experts) ? [...new Set(raw.experts.filter((id) => typeof id === "string" && (AGENT_IDS.includes(id as typeof AGENT_IDS[number]) || /^e_[a-f0-9]+$/.test(id))))] : undefined;
|
|
170
175
|
return {
|
|
171
176
|
id: raw.id?.trim() || `bot_${crypto.randomBytes(3).toString("hex")}`,
|
|
172
177
|
name: raw.name?.trim() || "飞书机器人",
|
|
@@ -179,6 +184,7 @@ function normalizeBot(raw: Partial<FeishuBotConfig>): FeishuBotConfig {
|
|
|
179
184
|
.filter((s) => s.startsWith("ou_")),
|
|
180
185
|
agents: list,
|
|
181
186
|
defaultAgent: raw.defaultAgent && list.includes(raw.defaultAgent) ? raw.defaultAgent : list[0]!,
|
|
187
|
+
...(experts ? { experts, defaultExpert: raw.defaultExpert && experts.includes(raw.defaultExpert) ? raw.defaultExpert : experts[0] ?? "" } : {}),
|
|
182
188
|
};
|
|
183
189
|
}
|
|
184
190
|
|