agent-loft 0.2.65 → 0.2.66
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 +3 -3
- 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 +25 -9
- 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 +41 -17
- package/src/core/task-runner.ts +3 -3
- package/src/core/tasks.ts +1 -1
- package/web/lib/ws.js +4 -0
- package/web/settings/experts.js +53 -10
- package/web/settings/feishu.js +39 -15
- package/web/views/experts.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
|
- 陌生人发消息会拿到配对码,在设置页批准后才能使用;每个机器人单独授权。
|
|
@@ -72,7 +72,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
|
|
|
72
72
|
- **授权**:允许一次 / 本会话全部允许 / 总是允许(按钮上写明放行范围)/ 拒绝。`/autoedit on` 让 Claude Code 在这条会话里改工作目录内的文件不再询问(Bash 仍询问)。超时一律按拒绝处理。
|
|
73
73
|
- **设置都在网页上**,按用途分组:**我的**(账号和密码、飞书绑定、登录设备、通知、记忆、技能、用量,每个人都有);**Agent**(运行环境、各 agent 的默认模型和思考程度、可选模型、Codex 沙箱、额度查询;工作目录、会话闲置过期、授权卡超时和 Claude 的「总是允许」名单;「/」命令);**连接**(飞书机器人、配对批准、指令面板同步;远程控制;服务器);**管理**(用户、所有人的登录设备;服务端版本和升级、重启、局域网访问和端口)。改了没保存就切页或关掉设置会先提醒。
|
|
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,8 +689,8 @@ 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,
|
|
@@ -847,11 +856,12 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
847
856
|
return;
|
|
848
857
|
}
|
|
849
858
|
if (p === "/api/conversations" && method === "POST") {
|
|
850
|
-
// expert:新对话页上选的专家(内置的 claude / codex
|
|
859
|
+
// expert:新对话页上选的专家(内置的 claude / codex,或者自己的、共享的专家 id)。agent 是以前的叫法
|
|
851
860
|
const body = await readJsonBody<{ expert?: string; agent?: string; cwd?: string }>(req);
|
|
852
861
|
const enabled = hub.enabledAgents().map((d) => d.id);
|
|
853
862
|
const wanted = body.expert ?? body.agent;
|
|
854
|
-
|
|
863
|
+
if (wanted && !canUseExpert(user.id, wanted)) throw new HttpError(400, "这个专家不存在或已取消共享");
|
|
864
|
+
const expertId = wanted || enabled[0];
|
|
855
865
|
if (!expertId) throw new HttpError(400, "没有可用的 agent");
|
|
856
866
|
const custom = isBuiltin(expertId) ? undefined : getExpert(expertId);
|
|
857
867
|
const agent = custom ? custom.engine : expertId;
|
|
@@ -1500,8 +1510,14 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1500
1510
|
return;
|
|
1501
1511
|
}
|
|
1502
1512
|
if (p === "/api/feishu/register" && method === "POST") {
|
|
1503
|
-
const body = await readJsonBody<{ name?: string; agents?: string[] }>(req);
|
|
1504
|
-
|
|
1513
|
+
const body = await readJsonBody<{ name?: string; agents?: string[]; experts?: unknown; defaultExpert?: unknown }>(req);
|
|
1514
|
+
let selection: ReturnType<typeof botExpertSelection> | undefined;
|
|
1515
|
+
try {
|
|
1516
|
+
if (body.experts !== undefined) selection = botExpertSelection(body.experts, body.defaultExpert);
|
|
1517
|
+
} catch (err) {
|
|
1518
|
+
throw new HttpError(400, err instanceof Error ? err.message : String(err));
|
|
1519
|
+
}
|
|
1520
|
+
sendJson(res, 200, await startRegistration(String(body.name ?? ""), Array.isArray(body.agents) ? body.agents : [], selection));
|
|
1505
1521
|
return;
|
|
1506
1522
|
}
|
|
1507
1523
|
const regMatch = /^\/api\/feishu\/register\/([a-f0-9]+)$/.exec(p);
|
|
@@ -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
|
|
package/src/core/experts.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// 两个内置专家 claude、codex 不存成自定义专家:保留原装提示词和工具,技能 / MCP 默认项由 builtin-agents.ts 按人保存。
|
|
6
6
|
// 对话和任务里没写 expert 的,专家就是它的 agent —— 升级前的数据不用迁移。
|
|
7
7
|
//
|
|
8
|
-
//
|
|
8
|
+
// 自定义专家由创建者维护;共享后其他账号可以使用,技能、MCP 和记忆仍按使用者分别加载。
|
|
9
9
|
import crypto from "node:crypto";
|
|
10
10
|
import { EventEmitter } from "node:events";
|
|
11
11
|
import fs from "node:fs";
|
|
@@ -34,6 +34,8 @@ export type QuickPrompt = { title: string; prompt: string };
|
|
|
34
34
|
export type Expert = {
|
|
35
35
|
id: string;
|
|
36
36
|
owner: string;
|
|
37
|
+
/** 共享给所有已登录、已绑定的账号;只有创建者能修改设定 */
|
|
38
|
+
shared?: boolean;
|
|
37
39
|
name: string;
|
|
38
40
|
description: string;
|
|
39
41
|
/** emoji(以前的图标;有头像时用头像) */
|
|
@@ -107,6 +109,10 @@ type StoredExpert = Omit<Expert, "avatar"> & { avatar?: string; avatarFile?: str
|
|
|
107
109
|
|
|
108
110
|
/** 专家改了 / 删了。owner:谁的。用着它的会话空闲下来要换上新的 */
|
|
109
111
|
export const expertEvents = new EventEmitter<{ changed: [owner: string, id: string] }>();
|
|
112
|
+
export const expertToolEvents = new EventEmitter<{ changed: [owner: string, id: string] }>();
|
|
113
|
+
export type ExpertTools = { skills: string[]; mcp: string[] };
|
|
114
|
+
const toolsPath = path.join(dataDir, "expert-tools.json");
|
|
115
|
+
type PersonalTools = Record<string, Record<string, ExpertTools>>;
|
|
110
116
|
|
|
111
117
|
let cache: Expert[] | null = null;
|
|
112
118
|
|
|
@@ -179,15 +185,70 @@ export function listExperts(owner: string): Expert[] {
|
|
|
179
185
|
.sort((a, b) => a.createdAt - b.createdAt);
|
|
180
186
|
}
|
|
181
187
|
|
|
188
|
+
/** 选择器展示自己的专家和其他人共享的专家;不改变 listExperts 的所有权语义。 */
|
|
189
|
+
export function availableExperts(owner: string): Expert[] {
|
|
190
|
+
return load().filter((e) => canUseExpert(owner, e.id)).sort((a, b) => a.createdAt - b.createdAt);
|
|
191
|
+
}
|
|
192
|
+
|
|
182
193
|
export function getExpert(id: string): Expert | undefined {
|
|
183
194
|
return load().find((e) => e.id === id);
|
|
184
195
|
}
|
|
185
196
|
|
|
186
|
-
/**
|
|
197
|
+
/** 共享只开放使用权,不转移专家、工具或会话的所有权。无身份的飞书聊天不能用。 */
|
|
187
198
|
export function canUseExpert(owner: string | undefined, id: string): boolean {
|
|
188
199
|
if (isBuiltin(id)) return true;
|
|
189
200
|
const e = getExpert(id);
|
|
190
|
-
|
|
201
|
+
if (!e || !owner) return false;
|
|
202
|
+
if (e.owner === owner) return true;
|
|
203
|
+
const creator = getUser(e.owner);
|
|
204
|
+
const user = getUser(owner);
|
|
205
|
+
return e.shared === true && !!creator && !creator.disabled && !!user && !user.disabled;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** 发布者沿用专家原有的工具选择;其他人未配置时不加载技能和 MCP。 */
|
|
209
|
+
export function expertTools(owner: string, expert: Expert): ExpertTools {
|
|
210
|
+
if (!canUseExpert(owner, expert.id)) throw new Error("这个专家不存在或已取消共享");
|
|
211
|
+
if (expert.owner === owner) return { skills: expert.skills, mcp: expert.mcp };
|
|
212
|
+
return readJson<PersonalTools>(toolsPath, {})[owner]?.[expert.id] ?? { skills: [], mcp: [] };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function setExpertTools(owner: string, id: string, input: unknown): ExpertTools {
|
|
216
|
+
const expert = getExpert(id);
|
|
217
|
+
if (!expert || !canUseExpert(owner, id)) throw new Error("这个专家不存在或已取消共享");
|
|
218
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("工具配置格式不对");
|
|
219
|
+
const raw = input as Record<string, unknown>;
|
|
220
|
+
const selection = (value: unknown): string[] => {
|
|
221
|
+
if (!Array.isArray(value) || value.length > 200 || value.some((v) => typeof v !== "string" || v.length > 100)) throw new Error("技能和 MCP 必须是列表");
|
|
222
|
+
return [...new Set(value as string[])];
|
|
223
|
+
};
|
|
224
|
+
const next = { skills: selection(raw.skills), mcp: selection(raw.mcp) };
|
|
225
|
+
const available = new Set(activeSkills(owner).map((s) => s.id));
|
|
226
|
+
if (next.skills.some((id) => !available.has(id))) throw new Error("只能选择自己已启用的技能");
|
|
227
|
+
const admin = getUser(owner)?.role === "admin";
|
|
228
|
+
const names = new Set<string>();
|
|
229
|
+
for (const id of next.mcp) {
|
|
230
|
+
const server = getMcp(id);
|
|
231
|
+
const name = isMachineId(id) ? machineName(id) : server?.name;
|
|
232
|
+
if (isMachineId(id) ? !admin || !name || !/^[A-Za-z0-9_-]{1,100}$/.test(name) : !server || server.owner !== owner) throw new Error("只能选择自己的 MCP(机器 MCP 仅管理员可选)");
|
|
233
|
+
if (names.has(name!)) throw new Error(`MCP 服务名重复:${name}`);
|
|
234
|
+
names.add(name!);
|
|
235
|
+
}
|
|
236
|
+
if (expert.owner === owner) {
|
|
237
|
+
updateExpert(owner, id, next);
|
|
238
|
+
} else {
|
|
239
|
+
const all = readJson<PersonalTools>(toolsPath, {});
|
|
240
|
+
(all[owner] ??= {})[id] = next;
|
|
241
|
+
writeJsonAtomic(toolsPath, all);
|
|
242
|
+
expertToolEvents.emit("changed", owner, id);
|
|
243
|
+
}
|
|
244
|
+
return next;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function purgeExpertTools(owner?: string, expertId?: string): void {
|
|
248
|
+
const all = readJson<PersonalTools>(toolsPath, {});
|
|
249
|
+
if (owner) delete all[owner];
|
|
250
|
+
if (expertId) for (const tools of Object.values(all)) delete tools[expertId];
|
|
251
|
+
writeJsonAtomic(toolsPath, all);
|
|
191
252
|
}
|
|
192
253
|
|
|
193
254
|
export const accessRank = (a: ExpertAccess) => ACCESS_LEVELS.indexOf(a);
|
|
@@ -208,6 +269,9 @@ function validate(owner: string, input: ExpertInput, prev?: Expert, selfId?: str
|
|
|
208
269
|
const user = getUser(owner);
|
|
209
270
|
if (!user) throw new Error("用户不存在");
|
|
210
271
|
const admin = user.role === "admin";
|
|
272
|
+
const sharedRaw = pick("shared");
|
|
273
|
+
if (sharedRaw !== undefined && typeof sharedRaw !== "boolean") throw new Error("共享开关必须是布尔值");
|
|
274
|
+
const shared = sharedRaw === true;
|
|
211
275
|
|
|
212
276
|
const name = text(pick("name"), EXPERT_LIMITS.name, "名字");
|
|
213
277
|
if (!name) throw new Error("给专家起个名字");
|
|
@@ -255,6 +319,7 @@ function validate(owner: string, input: ExpertInput, prev?: Expert, selfId?: str
|
|
|
255
319
|
if (id === selfId) throw new Error("子智能体不能是它自己");
|
|
256
320
|
const sub = getExpert(id);
|
|
257
321
|
if (!sub || sub.owner !== owner) continue;
|
|
322
|
+
if (shared && !sub.shared) throw new Error(`共享专家的子智能体「${sub.name}」也需要先共享`);
|
|
258
323
|
if (sub.engine !== "claude") throw new Error(`「${sub.name}」是 Codex 专家,子智能体只能用 Claude 专家`);
|
|
259
324
|
if (accessRank(sub.access) > accessRank(access as ExpertAccess)) {
|
|
260
325
|
throw new Error(`「${sub.name}」的权限(${ACCESS_LABEL[sub.access]})比这个专家高,子智能体的权限不能超过主专家`);
|
|
@@ -273,6 +338,7 @@ function validate(owner: string, input: ExpertInput, prev?: Expert, selfId?: str
|
|
|
273
338
|
const model = text(pick("model"), 100, "模型");
|
|
274
339
|
const effort = text(pick("effort"), 20, "思考程度");
|
|
275
340
|
return {
|
|
341
|
+
shared,
|
|
276
342
|
name,
|
|
277
343
|
description: text(pick("description"), EXPERT_LIMITS.description, "说明"),
|
|
278
344
|
icon: text(pick("icon"), 16, "图标"),
|
|
@@ -316,7 +382,13 @@ export function updateExpert(owner: string, id: string, input: ExpertInput): Exp
|
|
|
316
382
|
const next: Expert = { id, owner, ...validate(owner, input, prev, id), rev: prev.rev + 1, createdAt: prev.createdAt, updatedAt: Date.now() };
|
|
317
383
|
list[idx] = next;
|
|
318
384
|
save();
|
|
319
|
-
|
|
385
|
+
// 工具是发布者本人的选择,不需要让其他使用者重载共享设定。
|
|
386
|
+
const definitionChanged = [...new Set([...Object.keys(prev), ...Object.keys(next)])].some((key) =>
|
|
387
|
+
!["skills", "mcp", "rev", "updatedAt"].includes(key) &&
|
|
388
|
+
JSON.stringify(prev[key as keyof Expert]) !== JSON.stringify(next[key as keyof Expert]),
|
|
389
|
+
);
|
|
390
|
+
if (definitionChanged) expertEvents.emit("changed", owner, id);
|
|
391
|
+
else expertToolEvents.emit("changed", owner, id);
|
|
320
392
|
return next;
|
|
321
393
|
}
|
|
322
394
|
|
|
@@ -325,6 +397,7 @@ export function deleteExpert(owner: string, id: string): void {
|
|
|
325
397
|
const idx = list.findIndex((e) => e.id === id && e.owner === owner);
|
|
326
398
|
if (idx < 0) throw new Error("这个专家不存在");
|
|
327
399
|
list.splice(idx, 1);
|
|
400
|
+
purgeExpertTools(undefined, id);
|
|
328
401
|
// 别的专家把它当子智能体的,一并去掉
|
|
329
402
|
for (const e of list) {
|
|
330
403
|
if (e.subagents.includes(id)) {
|
|
@@ -338,11 +411,9 @@ export function deleteExpert(owner: string, id: string): void {
|
|
|
338
411
|
}
|
|
339
412
|
|
|
340
413
|
export function purgeUserExperts(owner: string): void {
|
|
414
|
+
purgeExpertTools(owner);
|
|
341
415
|
const list = load();
|
|
342
|
-
const
|
|
343
|
-
if (kept.length === list.length) return;
|
|
344
|
-
cache = kept;
|
|
345
|
-
save();
|
|
416
|
+
for (const e of [...list]) if (e.owner === owner) deleteExpert(owner, e.id);
|
|
346
417
|
}
|
|
347
418
|
|
|
348
419
|
// ---------- 开会话时 ----------
|
|
@@ -428,18 +499,23 @@ function subagentKey(name: string, taken: Set<string>): string {
|
|
|
428
499
|
* 按专家配置拼出交给 driver 的样子。prompt:子智能体的完整提示词怎么拼(core/expert-prompt.ts 给)。
|
|
429
500
|
* 子智能体的权限封顶在主专家的权限:主专家后来降了权限也不会被子智能体绕过去。
|
|
430
501
|
*/
|
|
431
|
-
export function expertRuntime(expert: Expert, subPrompt: (sub: Expert, access: ExpertAccess) => string): ExpertRuntime {
|
|
432
|
-
|
|
433
|
-
const
|
|
434
|
-
const
|
|
502
|
+
export function expertRuntime(expert: Expert, subPrompt: (sub: Expert, access: ExpertAccess) => string, owner = expert.owner): ExpertRuntime {
|
|
503
|
+
if (!canUseExpert(owner, expert.id)) throw new Error("这个专家不存在或已取消共享");
|
|
504
|
+
const tools = expertTools(owner, expert);
|
|
505
|
+
const admin = getUser(owner)?.role === "admin";
|
|
506
|
+
const active = new Map(activeSkills(owner).map((s) => [s.id, s]));
|
|
507
|
+
const { mcp, ask, machine } = resolveMcp({ owner, engine: expert.engine, mcp: tools.mcp }, admin);
|
|
435
508
|
const taken = new Set<string>();
|
|
436
509
|
const subagents: SubagentRuntime[] = [];
|
|
437
510
|
if (expert.engine === "claude") {
|
|
438
511
|
for (const id of expert.subagents) {
|
|
439
512
|
const sub = getExpert(id);
|
|
440
513
|
if (!sub || sub.owner !== expert.owner || sub.engine !== "claude" || sub.id === expert.id) continue;
|
|
514
|
+
// 共享主专家不能把未共享的私人子专家带给其他使用者。
|
|
515
|
+
if ((expert.shared && !sub.shared) || !canUseExpert(owner, sub.id)) continue;
|
|
516
|
+
const subTools = expertTools(owner, sub);
|
|
441
517
|
const access = accessRank(sub.access) > accessRank(expert.access) ? expert.access : sub.access;
|
|
442
|
-
const subMcp = resolveMcp(sub, admin).mcp;
|
|
518
|
+
const subMcp = resolveMcp({ owner, engine: sub.engine, mcp: subTools.mcp }, admin).mcp;
|
|
443
519
|
subagents.push({
|
|
444
520
|
key: subagentKey(sub.name, taken),
|
|
445
521
|
name: sub.name,
|
|
@@ -449,7 +525,7 @@ export function expertRuntime(expert: Expert, subPrompt: (sub: Expert, access: E
|
|
|
449
525
|
webSearch: sub.webSearch,
|
|
450
526
|
webFetch: sub.webFetch,
|
|
451
527
|
...(sub.model ? { model: sub.model } : {}),
|
|
452
|
-
skills:
|
|
528
|
+
skills: subTools.skills.map((s) => active.get(s)?.name).filter((n): n is string => !!n),
|
|
453
529
|
mcp: subMcp,
|
|
454
530
|
});
|
|
455
531
|
}
|
|
@@ -463,7 +539,7 @@ export function expertRuntime(expert: Expert, subPrompt: (sub: Expert, access: E
|
|
|
463
539
|
access: expert.access,
|
|
464
540
|
webSearch: expert.webSearch,
|
|
465
541
|
webFetch: expert.webFetch,
|
|
466
|
-
skills:
|
|
542
|
+
skills: tools.skills.filter((id) => active.has(id)),
|
|
467
543
|
mcp,
|
|
468
544
|
askMcp: ask,
|
|
469
545
|
machineMcp: machine,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// 飞书机器人的专家选择与兼容旧的按引擎配置。无效、删除或撤回共享的专家不能退回内置 Agent。
|
|
2
|
+
import type { FeishuBotConfig } from "./config.js";
|
|
3
|
+
import { getExpert, isBuiltin } from "./experts.js";
|
|
4
|
+
import { getUser } from "./users.js";
|
|
5
|
+
|
|
6
|
+
export function botExpertEngine(id: string): string | undefined {
|
|
7
|
+
if (isBuiltin(id)) return id;
|
|
8
|
+
const expert = getExpert(id);
|
|
9
|
+
const creator = expert && getUser(expert.owner);
|
|
10
|
+
return expert?.shared && creator && !creator.disabled ? expert.engine : undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function botExpertIds(cfg: FeishuBotConfig): string[] | undefined {
|
|
14
|
+
return cfg.experts?.filter((id) => !!botExpertEngine(id));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function botAgentIds(cfg: FeishuBotConfig): string[] {
|
|
18
|
+
return cfg.experts === undefined ? cfg.agents : [...new Set(cfg.experts.map(botExpertEngine).filter((id): id is string => !!id))];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 配置接口严格校验;引擎随专家推导,前端不需要再额外勾底层 Agent。 */
|
|
22
|
+
export function botExpertSelection(experts: unknown, defaultExpert: unknown): Pick<FeishuBotConfig, "experts" | "defaultExpert" | "agents" | "defaultAgent"> {
|
|
23
|
+
if (!Array.isArray(experts) || !experts.length || experts.length > 200 || experts.some((id) => typeof id !== "string" || !botExpertEngine(id))) throw new Error("至少选择一个内置专家或仍在共享的专家");
|
|
24
|
+
const selected = [...new Set(experts as string[])];
|
|
25
|
+
const first = typeof defaultExpert === "string" && selected.includes(defaultExpert) ? defaultExpert : selected[0]!;
|
|
26
|
+
const agents = [...new Set(selected.map((id) => botExpertEngine(id)!))];
|
|
27
|
+
return { experts: selected, defaultExpert: first, agents, defaultAgent: botExpertEngine(first)! };
|
|
28
|
+
}
|
package/src/core/hub.ts
CHANGED
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
import { attachmentInfo, ensureUploadsDir, KIND_LABEL } from "./uploads.js";
|
|
31
31
|
import { memoryOwnerOf, sessionMemory } from "./personal.js";
|
|
32
32
|
import { readMemory } from "./memory.js";
|
|
33
|
-
import { getUser } from "./users.js";
|
|
33
|
+
import { getUser, userEvents } from "./users.js";
|
|
34
34
|
import type {
|
|
35
35
|
AgentDriver,
|
|
36
36
|
AttachmentInfo,
|
|
@@ -50,7 +50,7 @@ import { buildCatalog, expandCustomCommand, type AgentCommand, type CommandEntry
|
|
|
50
50
|
import { helpText, type ParsedCommand } from "./commands.js";
|
|
51
51
|
import { listScheduled } from "./scheduled.js";
|
|
52
52
|
import { expertSystemPrompt, searchLabel, stripContext } from "./expert-prompt.js";
|
|
53
|
-
import { avatarUrl, expertEvents, expertRuntime, getExpert, isBuiltin,
|
|
53
|
+
import { availableExperts, avatarUrl, canUseExpert, expertEvents, expertToolEvents, expertRuntime, getExpert, isBuiltin, type ExpertRuntime } from "./experts.js";
|
|
54
54
|
import { builtinAgentDefaults, builtinAgentEvents, builtinAgentSession } from "./builtin-agents.js";
|
|
55
55
|
import { mcpEvents } from "./mcp.js";
|
|
56
56
|
import { isMachineCommand, sessionSkills } from "./skill-runtime.js";
|
|
@@ -280,7 +280,26 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
280
280
|
// 技能装了、改了、停用了、变量改了:受影响的人空闲的会话换上新的
|
|
281
281
|
skillEvents.on("changed", (users) => this.personalChanged(new Set(users)));
|
|
282
282
|
// 专家修改只影响自定义专家;MCP 和内置默认配置修改也更新该账号的内置会话。
|
|
283
|
-
expertEvents.on("changed", (
|
|
283
|
+
expertEvents.on("changed", (_owner, id) => {
|
|
284
|
+
for (const conv of listConversations()) {
|
|
285
|
+
if (conv.expert !== id && !(conv.expert && getExpert(conv.expert)?.subagents.includes(id))) continue;
|
|
286
|
+
const live = this.live.get(conv.key);
|
|
287
|
+
if (live) {
|
|
288
|
+
this.staleLive.add(live.id);
|
|
289
|
+
this.dropIfStale(conv.key);
|
|
290
|
+
}
|
|
291
|
+
this.emitEvent(conv.key, { type: "meta" });
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
expertToolEvents.on("changed", (owner) => this.personalChanged(new Set([owner]), true));
|
|
295
|
+
userEvents.on("changed", () => {
|
|
296
|
+
for (const [key, live] of this.live) {
|
|
297
|
+
const conv = getConversation(key);
|
|
298
|
+
if (!conv?.expert || canUseExpert(memoryOwnerOf(conv), conv.expert)) continue;
|
|
299
|
+
this.staleLive.add(live.id);
|
|
300
|
+
this.dropIfStale(key);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
284
303
|
mcpEvents.on("changed", (owner) => this.personalChanged(new Set([owner])));
|
|
285
304
|
builtinAgentEvents.on("changed", (owner) => this.personalChanged(new Set([owner])));
|
|
286
305
|
// workspaceRoot 改了:store 会把没显式 /cd 过的会话目录重置,正在跑的旧目录会话要作废
|
|
@@ -402,7 +421,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
402
421
|
expertBadge(conv: Pick<Conversation, "agent" | "expert" | "owner" | "channel">): ExpertBadge {
|
|
403
422
|
if (!conv.expert) return { id: conv.agent, name: this.label(conv.agent), builtin: true };
|
|
404
423
|
const e = getExpert(conv.expert);
|
|
405
|
-
if (!e ||
|
|
424
|
+
if (!e || !canUseExpert(memoryOwnerOf(conv), e.id)) return { id: conv.expert, name: "(专家已删除或未共享)", missing: true };
|
|
406
425
|
return {
|
|
407
426
|
id: e.id,
|
|
408
427
|
name: e.name,
|
|
@@ -417,27 +436,29 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
417
436
|
|
|
418
437
|
/**
|
|
419
438
|
* 拉起会话时交给 driver 的专家。内置专家返回 undefined(agent 原装的样子)。
|
|
420
|
-
*
|
|
439
|
+
* 专家被删了、未授权共享、引擎对不上:抛错 —— 不能悄悄换成别的专家接着聊。
|
|
421
440
|
*/
|
|
422
441
|
private expertFor(conv: Conversation): ExpertRuntime | undefined {
|
|
423
442
|
if (!conv.expert) return undefined;
|
|
424
443
|
const e = getExpert(conv.expert);
|
|
425
|
-
|
|
444
|
+
const owner = memoryOwnerOf(conv);
|
|
445
|
+
if (!e || !owner || !canUseExpert(owner, e.id)) throw new Error("这条对话用的专家已经删除或取消共享了。新开一个对话,换个专家吧。");
|
|
426
446
|
if (e.engine !== conv.agent) throw new Error(`专家「${e.name}」的引擎和这条对话的对不上,新开一个对话吧。`);
|
|
427
447
|
return expertRuntime(e, (sub, access) =>
|
|
428
448
|
expertSystemPrompt({ name: sub.name, prompt: sub.prompt, access, webSearch: sub.webSearch, webFetch: sub.webFetch }, searchLabel("claude", sub), conv.cwd),
|
|
449
|
+
owner,
|
|
429
450
|
);
|
|
430
451
|
}
|
|
431
452
|
|
|
432
453
|
/**
|
|
433
|
-
* 这个人在某个渠道能选的专家:允许的内置专家(agent
|
|
454
|
+
* 这个人在某个渠道能选的专家:允许的内置专家(agent 启用着的),加上自己的及共享的、引擎可用的专家。
|
|
434
455
|
* 没有主人的对话(飞书群聊等)只有内置专家。
|
|
435
456
|
*/
|
|
436
|
-
expertChoices(owner: string | undefined, allowedAgents: string[]): { id: string; label: string; engine: string }[] {
|
|
457
|
+
expertChoices(owner: string | undefined, allowedAgents: string[], allowedExperts?: string[]): { id: string; label: string; engine: string }[] {
|
|
437
458
|
const usable = new Set(this.enabledAgents().map((d) => d.id).filter((a) => allowedAgents.includes(a)));
|
|
438
459
|
const builtin = [...usable].map((a) => ({ id: a, label: this.label(a), engine: a }));
|
|
439
|
-
const own = owner ?
|
|
440
|
-
return [...builtin, ...own.map((e) => ({ id: e.id, label: `${e.icon ? `${e.icon} ` : ""}${e.name}`, engine: e.engine }))];
|
|
460
|
+
const own = owner ? availableExperts(owner).filter((e) => usable.has(e.engine)) : [];
|
|
461
|
+
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));
|
|
441
462
|
}
|
|
442
463
|
|
|
443
464
|
/** 已注册且在配置里启用的 agent */
|
|
@@ -617,6 +638,8 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
617
638
|
if (!conv) throw new Error(`会话不存在:${key}`);
|
|
618
639
|
// 先检查 agent 还启用着:设置里关掉了,已经打开的会话也不能再用
|
|
619
640
|
const driver = this.requireDriver(conv.agent);
|
|
641
|
+
// 撤回共享后,即使上一轮还在运行,也不能把新输入交给缓存着的会话。
|
|
642
|
+
if (conv.expert && !canUseExpert(memoryOwnerOf(conv), conv.expert)) throw new Error("这条对话用的专家已经删除或取消共享了。新开一个对话,换个专家吧。");
|
|
620
643
|
const existing = this.live.get(key);
|
|
621
644
|
if (existing && existing.agent === conv.agent && existing.cwd === conv.cwd && !opts.resumeId) {
|
|
622
645
|
return existing.session;
|
|
@@ -1352,11 +1375,11 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
1352
1375
|
* 换专家(飞书里的 /agent、/claude、/codex):对话中途不能换专家,所以换了就开新会话。
|
|
1353
1376
|
* target 可以是专家 id,也可以是名字。allowed:这个渠道允许的内置 agent。
|
|
1354
1377
|
*/
|
|
1355
|
-
private async setExpertNow(key: string, target: string, allowed: string[], op: SwitchOp): Promise<string> {
|
|
1378
|
+
private async setExpertNow(key: string, target: string, allowed: string[], op: SwitchOp, allowedExperts?: string[]): Promise<string> {
|
|
1356
1379
|
const conv = getConversation(key)!;
|
|
1357
1380
|
// 网页上的对话(包括飞书 /web 接上的)从头到尾一个专家:要换就新建对话
|
|
1358
1381
|
if (conv.channel === "web") return "网页上的对话中途不能换专家。在网页上新建一个对话,选好专家再聊。";
|
|
1359
|
-
const choices = this.expertChoices(memoryOwnerOf(conv), allowed);
|
|
1382
|
+
const choices = this.expertChoices(memoryOwnerOf(conv), allowed, allowedExperts);
|
|
1360
1383
|
const want = target.trim().toLowerCase();
|
|
1361
1384
|
const hit = choices.find((c) => c.id.toLowerCase() === want) ?? choices.find((c) => c.label.toLowerCase().includes(want));
|
|
1362
1385
|
if (!hit) return `这里没有「${target}」这个专家。可选:${choices.map((c) => c.label).join("、")}`;
|
|
@@ -1639,8 +1662,8 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
1639
1662
|
return this.serial(key, () => this.setEffortNow(key, effort));
|
|
1640
1663
|
}
|
|
1641
1664
|
|
|
1642
|
-
setExpert(key: string, target: string, allowed: string[]): Promise<string> {
|
|
1643
|
-
return this.switchOp(key, (op) => this.setExpertNow(key, target, allowed, op));
|
|
1665
|
+
setExpert(key: string, target: string, allowed: string[], allowedExperts?: string[]): Promise<string> {
|
|
1666
|
+
return this.switchOp(key, (op) => this.setExpertNow(key, target, allowed, op, allowedExperts));
|
|
1644
1667
|
}
|
|
1645
1668
|
|
|
1646
1669
|
cd(key: string, dir: string): Promise<string> {
|
|
@@ -1662,6 +1685,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
1662
1685
|
cmd: ParsedCommand,
|
|
1663
1686
|
ctx: {
|
|
1664
1687
|
allowedAgents: string[];
|
|
1688
|
+
allowedExperts?: string[];
|
|
1665
1689
|
by: string;
|
|
1666
1690
|
channel?: string;
|
|
1667
1691
|
/** 多用户:发命令的人能看到哪些 agent 会话(/sessions 列哪些、/resume 能恢复哪些) */
|
|
@@ -1686,7 +1710,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
1686
1710
|
...(channel ? { channel } : {}),
|
|
1687
1711
|
...(owner && getUser(owner)?.role !== "admin" ? { member: true } : {}),
|
|
1688
1712
|
});
|
|
1689
|
-
return { type: "commands", agent: conv.agent, commands: all.filter((c) => !c.hidden) };
|
|
1713
|
+
return { type: "commands", agent: conv.agent, commands: all.filter((c) => !c.hidden && (!["claude", "codex"].includes(c.name) || ctx.allowedExperts === undefined || ctx.allowedExperts.includes(c.name))) };
|
|
1690
1714
|
}
|
|
1691
1715
|
case "pwd":
|
|
1692
1716
|
return text(getConversation(key)!.cwd);
|
|
@@ -1719,11 +1743,11 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
1719
1743
|
const conv = getConversation(key)!;
|
|
1720
1744
|
return {
|
|
1721
1745
|
type: "agents",
|
|
1722
|
-
agents: this.expertChoices(memoryOwnerOf(conv), ctx.allowedAgents).map(({ id, label }) => ({ id, label })),
|
|
1746
|
+
agents: this.expertChoices(memoryOwnerOf(conv), ctx.allowedAgents, ctx.allowedExperts).map(({ id, label }) => ({ id, label })),
|
|
1723
1747
|
current: expertIdOf(conv),
|
|
1724
1748
|
};
|
|
1725
1749
|
}
|
|
1726
|
-
return text(await this.setExpert(key, cmd.agent, ctx.allowedAgents));
|
|
1750
|
+
return text(await this.setExpert(key, cmd.agent, ctx.allowedAgents, ctx.allowedExperts));
|
|
1727
1751
|
}
|
|
1728
1752
|
case "stop":
|
|
1729
1753
|
return text(await this.stop(key));
|
package/src/core/task-runner.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// 更不能被当成对挂着的提问的回答。
|
|
8
8
|
import crypto from "node:crypto";
|
|
9
9
|
import { resolveWorkspacePath } from "./config.js";
|
|
10
|
-
import { getExpert } from "./experts.js";
|
|
10
|
+
import { canUseExpert, getExpert } from "./experts.js";
|
|
11
11
|
import { hub, type TaskTurnEnd } from "./hub.js";
|
|
12
12
|
import { interactions } from "./interactions.js";
|
|
13
13
|
import { memoryOwnerOf } from "./personal.js";
|
|
@@ -50,8 +50,8 @@ type Resolved = { key: string } | { pause: string } | { error: string };
|
|
|
50
50
|
|
|
51
51
|
/** 这次该发到哪条对话;专用对话还没有(或者被删了)就新建一条 */
|
|
52
52
|
function resolveConv(task: Task): Resolved {
|
|
53
|
-
const missingExpert = (id: string | undefined) => !!id &&
|
|
54
|
-
const deletedExpert = { pause: "
|
|
53
|
+
const missingExpert = (id: string | undefined) => !!id && !canUseExpert(task.owner, id);
|
|
54
|
+
const deletedExpert = { pause: "任务用的专家已经删除或取消共享了,任务已暂停。编辑任务换一个专家再启用。" };
|
|
55
55
|
if (task.target.kind === "conv") {
|
|
56
56
|
const conv = getConversation(task.target.key);
|
|
57
57
|
if (!conv || conv.hidden) return { pause: "回复的那条对话已经被删除,任务已暂停。可以改成「专用对话」后再启用。" };
|
package/src/core/tasks.ts
CHANGED
|
@@ -157,7 +157,7 @@ function cleanPrompt(v: unknown): string {
|
|
|
157
157
|
return p;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
/** 选的专家 → 引擎 + 自定义专家 id
|
|
160
|
+
/** 选的专家 → 引擎 + 自定义专家 id。可选内置、自己的或共享的专家 */
|
|
161
161
|
function cleanExpert(owner: string, v: unknown): { agent: string; expert?: string } {
|
|
162
162
|
const id = str(v) || "claude";
|
|
163
163
|
if (!canUseExpert(owner, id)) throw new Error("这个专家不存在");
|
package/web/lib/ws.js
CHANGED
|
@@ -11,6 +11,7 @@ import { setBusy } from "../views/composer.js";
|
|
|
11
11
|
import { SH, shownHere } from "./shell.js";
|
|
12
12
|
import { currentPushSub } from "./push.js";
|
|
13
13
|
import { renderScheduled } from "../views/schedule.js";
|
|
14
|
+
import { reloadExperts } from "../views/experts.js";
|
|
14
15
|
|
|
15
16
|
// ---------- WebSocket ----------
|
|
16
17
|
|
|
@@ -281,6 +282,9 @@ function onWsMessage(msg) {
|
|
|
281
282
|
// 自己的终端开了 / 关了,或者远程控制的权限、设置变了:重新问一下(views/layout.js)
|
|
282
283
|
document.dispatchEvent(new Event("aim:remote"));
|
|
283
284
|
return;
|
|
285
|
+
case "experts":
|
|
286
|
+
void reloadExperts();
|
|
287
|
+
return;
|
|
284
288
|
case "skills":
|
|
285
289
|
// 技能变了:设置里的技能页开着就重新拉,@ 补全的缓存作废
|
|
286
290
|
document.dispatchEvent(new Event("aim:skills"));
|
package/web/settings/experts.js
CHANGED
|
@@ -20,6 +20,8 @@ const PERMS = [
|
|
|
20
20
|
{ id: "exec", label: "跑命令", hint: "执行命令,等于能改任何文件;需要授权时会弹卡" },
|
|
21
21
|
];
|
|
22
22
|
const FILE_LEVELS = ["read", "edit", "exec"];
|
|
23
|
+
let refreshExpertsPage = () => {};
|
|
24
|
+
document.addEventListener("aim:experts", () => refreshExpertsPage());
|
|
23
25
|
|
|
24
26
|
export async function expertsTab(panel) {
|
|
25
27
|
const box = h("div", { class: "experts-page" }, h("span", { class: "spinner" }));
|
|
@@ -35,6 +37,7 @@ export async function expertsTab(panel) {
|
|
|
35
37
|
if (!box.isConnected) return;
|
|
36
38
|
render(box, data, load);
|
|
37
39
|
};
|
|
40
|
+
refreshExpertsPage = () => { if (box.isConnected) void load(); };
|
|
38
41
|
await load();
|
|
39
42
|
}
|
|
40
43
|
|
|
@@ -48,7 +51,7 @@ function render(box, data, reload) {
|
|
|
48
51
|
h(
|
|
49
52
|
"p",
|
|
50
53
|
{ class: "skill-note" },
|
|
51
|
-
"
|
|
54
|
+
"专家决定引擎、提示词和能力。共享给所有账号后,设定由创建者维护,每个人的记忆、技能和 MCP 仍各自独立;点「我的工具」选择自己要用的工具。内置的 Claude Code、Codex 在「设置 → Agent」里选择默认技能和 MCP。",
|
|
52
55
|
),
|
|
53
56
|
h("div", { class: "skill-head-btns" }, add),
|
|
54
57
|
),
|
|
@@ -70,14 +73,15 @@ function render(box, data, reload) {
|
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
function expertCard(data, e, reload) {
|
|
76
|
+
const editable = e.editable !== false;
|
|
77
|
+
const open = () => editable ? openEditor(data, e, reload) : viewSharedExpert(e);
|
|
73
78
|
const access = data.access.find((a) => a.id === e.access)?.label ?? e.access;
|
|
74
79
|
const more = h("button", { class: "icon-btn", title: "更多" }, icon("more"));
|
|
75
80
|
more.onclick = () =>
|
|
76
81
|
showMenu(more, [
|
|
77
|
-
{ label: "编辑…"
|
|
78
|
-
{ label: "复制一份…", onclick: () => openEditor(data, null, reload, { ...e, name: `${e.name} 副本` }) },
|
|
79
|
-
"sep",
|
|
80
|
-
{ label: "删除", danger: true, onclick: () => removeExpert(e, reload) },
|
|
82
|
+
{ label: editable ? "编辑…" : "查看设定…", onclick: open },
|
|
83
|
+
{ label: "复制一份…", onclick: () => openEditor(data, null, reload, { ...e, shared: false, subagents: editable ? e.subagents : [], name: `${e.name} 副本` }) },
|
|
84
|
+
...(editable ? ["sep", { label: "删除", danger: true, onclick: () => removeExpert(e, reload) }] : []),
|
|
81
85
|
]);
|
|
82
86
|
const extras = [
|
|
83
87
|
e.skills.length ? `${e.skills.length} 个技能` : null,
|
|
@@ -91,7 +95,9 @@ function expertCard(data, e, reload) {
|
|
|
91
95
|
h(
|
|
92
96
|
"div",
|
|
93
97
|
{ class: "task-top" },
|
|
94
|
-
h("button", { class: "task-title skill-name", title: "编辑"
|
|
98
|
+
h("button", { class: "task-title skill-name", title: editable ? "编辑" : "查看设定", onclick: open }, expertIcon(e, "expert-card-icon"), e.name),
|
|
99
|
+
e.shared ? h("span", { class: "badge" }, editable ? "已共享" : "共享") : null,
|
|
100
|
+
e.shared ? h("button", { class: "btn", onclick: () => openTools(data, e, reload) }, "我的工具") : null,
|
|
95
101
|
more,
|
|
96
102
|
),
|
|
97
103
|
h("div", { class: "task-meta" }, h("span", {}, ENGINE_LABEL[e.engine]), h("span", {}, access), e.model ? h("span", {}, e.model) : null, extras.map((x) => h("span", {}, x))),
|
|
@@ -99,6 +105,40 @@ function expertCard(data, e, reload) {
|
|
|
99
105
|
);
|
|
100
106
|
}
|
|
101
107
|
|
|
108
|
+
function viewSharedExpert(e) {
|
|
109
|
+
const prompt = h("textarea", { rows: 12, readonly: true, "aria-label": "提示词" });
|
|
110
|
+
prompt.value = e.prompt;
|
|
111
|
+
modal({ title: e.name, wide: true, body: h("div", { class: "modal-body" },
|
|
112
|
+
h("p", { class: "muted" }, "这是共享专家,设定由创建者维护。你的记忆和工具独立,工具可在「我的工具」里配置。"),
|
|
113
|
+
field("说明", h("p", {}, e.description || "暂无说明")),
|
|
114
|
+
field("引擎", h("p", {}, ENGINE_LABEL[e.engine])),
|
|
115
|
+
field("提示词", prompt),
|
|
116
|
+
) });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function openTools(data, e, reload) {
|
|
120
|
+
const skills = checkList(data.skills.map((s) => ({ id: s.id, label: s.name, hint: s.description })), e.skills, "还没有启用的技能(设置 → 技能)");
|
|
121
|
+
const machine = (data.machineMcp?.[e.engine] ?? []).map((name) => ({ id: `${data.machinePrefix}${name}`, label: `${name}(本机)` }));
|
|
122
|
+
const mcp = checkList([...data.mcp.map((s) => ({ id: s.id, label: s.name, hint: s.description })), ...machine], e.mcp, "还没有 MCP(设置 → MCP)");
|
|
123
|
+
const save = h("button", { class: "btn primary" }, "保存我的工具");
|
|
124
|
+
const close = modal({ title: `${e.name} · 我的工具`, body: h("div", { class: "modal-body" },
|
|
125
|
+
h("p", { class: "muted" }, "只影响你使用这个专家时加载的工具,网页和绑定账号后的飞书私聊共用。未选择时不加载技能或 MCP;记忆使用你自己的设置。子智能体的工具需在对应专家中单独配置。"),
|
|
126
|
+
field("我的技能", skills.el), field("我的 MCP", mcp.el),
|
|
127
|
+
), foot: h("div", { class: "modal-foot" }, save) });
|
|
128
|
+
save.onclick = async () => {
|
|
129
|
+
save.disabled = true;
|
|
130
|
+
try {
|
|
131
|
+
await api(`/api/experts/${e.id}/tools`, { method: "PUT", body: { skills: skills.value(), mcp: mcp.value() } });
|
|
132
|
+
close();
|
|
133
|
+
toast("已保存,你的对话下一条消息起使用新的工具");
|
|
134
|
+
void reload();
|
|
135
|
+
} catch (err) {
|
|
136
|
+
save.disabled = false;
|
|
137
|
+
toast(err.message);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
102
142
|
async function removeExpert(e, reload) {
|
|
103
143
|
const sure = await confirmDialog({
|
|
104
144
|
title: `删除专家「${e.name}」?`,
|
|
@@ -170,6 +210,7 @@ function openEditor(data, e, reload, preset) {
|
|
|
170
210
|
},
|
|
171
211
|
});
|
|
172
212
|
const memory = h("input", { type: "checkbox", checked: src.memory !== false });
|
|
213
|
+
const shared = h("input", { type: "checkbox", checked: src.shared === true });
|
|
173
214
|
const welcome = h("input", { value: src.welcome ?? "", maxlength: "500", placeholder: "新对话页上的那句话,比如:想了解哪只股票?" });
|
|
174
215
|
const quick = h("textarea", { rows: 4, placeholder: "一行一个,新对话页上点一下就填进输入框。可以写成「标题|提示词」,提示词里的 ___ 是要用户填的空" });
|
|
175
216
|
quick.value = (src.quickPrompts ?? []).map((q) => (q.title && q.title !== q.prompt.slice(0, 20) ? `${q.title}|${q.prompt}` : q.prompt)).join("\n");
|
|
@@ -196,7 +237,7 @@ function openEditor(data, e, reload, preset) {
|
|
|
196
237
|
const keepSubs = subs.value();
|
|
197
238
|
// 子智能体只有 Claude:自己的 Claude 专家,不能是自己
|
|
198
239
|
subs = checkList(
|
|
199
|
-
data.experts.filter((x) => x.engine === "claude" && x.id !== e?.id).map((x) => ({ id: x.id, label: !x.avatar && x.icon ? `${x.icon} ${x.name}` : x.name, hint: x.description })),
|
|
240
|
+
data.experts.filter((x) => x.editable !== false && x.engine === "claude" && x.id !== e?.id).map((x) => ({ id: x.id, label: !x.avatar && x.icon ? `${x.icon} ${x.name}` : x.name, hint: x.description })),
|
|
200
241
|
keepSubs,
|
|
201
242
|
"还没有别的 Claude 专家可以当子智能体",
|
|
202
243
|
);
|
|
@@ -218,15 +259,16 @@ function openEditor(data, e, reload, preset) {
|
|
|
218
259
|
{ class: "modal-body task-form expert-form" },
|
|
219
260
|
h("div", { class: "row-fields avatar-row" }, field("头像", avatar.el), field("名字", name)),
|
|
220
261
|
field("说明", desc),
|
|
262
|
+
field("共享", h("label", { class: "check-item" }, shared, h("span", {}, "共享给所有账号")), "其他账号可在网页、飞书私聊和定时任务中使用;只有你能修改设定。取消共享后,其他人的旧对话保留但不能继续调用。子智能体也需要先共享。"),
|
|
221
263
|
h("div", { class: "row-fields" }, field("引擎", engine, e ? "建好后不能换" : null), field("模型", models.model), field("思考程度", models.effort)),
|
|
222
264
|
field("提示词", prompt, "agent-loft 会在后面自动补上:这个专家能做什么、不能做什么,今天的日期,记忆"),
|
|
223
265
|
baseField,
|
|
224
266
|
field("权限", perms.el, "改文件包含读文件,跑命令包含改文件。什么都不勾就是只能聊天"),
|
|
225
267
|
cwdField,
|
|
226
|
-
field("
|
|
227
|
-
field("MCP", mcpBox, "
|
|
268
|
+
field("我的技能", skills.el, "只影响你的工具选择;共享后其他账号单独选择自己的技能"),
|
|
269
|
+
field("我的 MCP", mcpBox, "只使用你的 MCP;共享后不会把你的 MCP 或凭据交给其他账号"),
|
|
228
270
|
subField,
|
|
229
|
-
field("记忆", h("label", { class: "check-item" }, memory, h("span", {}, "
|
|
271
|
+
field("记忆", h("label", { class: "check-item" }, memory, h("span", {}, "使用聊天者自己的个人记忆(需在设置 → 记忆开启)"))),
|
|
230
272
|
field("欢迎语", welcome),
|
|
231
273
|
field("快捷提问", quick),
|
|
232
274
|
);
|
|
@@ -246,6 +288,7 @@ function openEditor(data, e, reload, preset) {
|
|
|
246
288
|
});
|
|
247
289
|
const payload = {
|
|
248
290
|
name: name.value,
|
|
291
|
+
shared: shared.checked,
|
|
249
292
|
...avatar.payload(),
|
|
250
293
|
description: desc.value,
|
|
251
294
|
engine: engine.value,
|
package/web/settings/feishu.js
CHANGED
|
@@ -9,7 +9,17 @@ import { field, markDirty, saveButton, saveConfig } from "./common.js";
|
|
|
9
9
|
* 设置 → 飞书:机器人、谁能用(配对请求、已配对的人)、指令面板同步,都是飞书这一侧的事,放在一页。
|
|
10
10
|
* 每个机器人一张表单各自保存;存了一个,其它机器人没保存的改动原样留着(表单按机器人缓存,不重建)。
|
|
11
11
|
*/
|
|
12
|
-
export function feishuTab(cfg, page) {
|
|
12
|
+
export async function feishuTab(cfg, page) {
|
|
13
|
+
let shared;
|
|
14
|
+
try {
|
|
15
|
+
shared = (await api("/api/experts/brief")).experts.filter((e) => e.shared);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
page.append(h("div", { class: "error-text" }, `无法加载共享专家:${err.message}`));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const choices = [...S.agents.map((a) => ({ id: a.id, label: a.label, engine: a.id })), ...shared.map((e) => ({ id: e.id, label: `${e.name}(共享)`, engine: e.engine }))];
|
|
21
|
+
// 复选框各有自己的 label,外层使用分组,避免把第一项关联到整组说明。
|
|
22
|
+
const expertField = (content, hint) => h("div", { class: "field", role: "group", "aria-label": "可用专家" }, h("span", {}, "可用专家"), content, h("small", {}, hint));
|
|
13
23
|
/** 已经存进配置的机器人(以服务端为准) + 手动添加、还没保存的 */
|
|
14
24
|
let saved = structuredClone(cfg.feishu.bots);
|
|
15
25
|
let drafts = [];
|
|
@@ -42,7 +52,7 @@ export function feishuTab(cfg, page) {
|
|
|
42
52
|
"div",
|
|
43
53
|
{ class: "section" },
|
|
44
54
|
h("h4", {}, "飞书机器人"),
|
|
45
|
-
h("div", { class: "muted" }, "
|
|
55
|
+
h("div", { class: "muted" }, "勾选这个机器人可用的内置或共享专家,并选择默认专家。共享专家在每个人绑定账号后的私聊中使用各自的记忆和工具。扫码创建会自动建好飞书应用;Lark 国际版请用「手动添加」。"),
|
|
46
56
|
h(
|
|
47
57
|
"div",
|
|
48
58
|
{ class: "row" },
|
|
@@ -79,11 +89,21 @@ export function feishuTab(cfg, page) {
|
|
|
79
89
|
const allow = h("textarea", { rows: 2, placeholder: "ou_xxx,一行一个" });
|
|
80
90
|
allow.value = b.allowFrom.join("\n");
|
|
81
91
|
const enabled = h("input", { type: "checkbox", checked: b.enabled });
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
92
|
+
const selected = b.experts ?? b.agents;
|
|
93
|
+
const missing = selected.filter((id) => !choices.some((e) => e.id === id)).map((id) => ({ id, label: `${id}(已删除或未共享,请取消勾选)` }));
|
|
94
|
+
const expertChecks = [...choices, ...missing].map((e) => {
|
|
95
|
+
const box = h("input", { type: "checkbox", checked: selected.includes(e.id), value: e.id });
|
|
96
|
+
return { id: e.id, box, el: h("label", { class: "check" }, box, e.label) };
|
|
85
97
|
});
|
|
86
|
-
const def = h("select", {
|
|
98
|
+
const def = h("select", { "aria-label": "默认专家" });
|
|
99
|
+
const syncDefault = () => {
|
|
100
|
+
const preferred = def.value || b.defaultExpert || b.defaultAgent;
|
|
101
|
+
const enabled = choices.filter((e) => expertChecks.some((c) => c.id === e.id && c.box.checked));
|
|
102
|
+
fill(def, enabled.map((e) => h("option", { value: e.id }, e.label)));
|
|
103
|
+
if (enabled.some((e) => e.id === preferred)) def.value = preferred;
|
|
104
|
+
};
|
|
105
|
+
for (const c of expertChecks) c.box.addEventListener("change", syncDefault);
|
|
106
|
+
syncDefault();
|
|
87
107
|
const status = h("span", { class: "status-tag" }, b.enabled ? "…" : "未启用");
|
|
88
108
|
if (!isDraft) statusTags.set(b.id, status);
|
|
89
109
|
const collect = () => {
|
|
@@ -96,14 +116,16 @@ export function feishuTab(cfg, page) {
|
|
|
96
116
|
domain: domain.value,
|
|
97
117
|
allowFrom: allow.value.split(/[\s,]+/).filter(Boolean),
|
|
98
118
|
enabled: enabled.checked,
|
|
99
|
-
|
|
100
|
-
|
|
119
|
+
experts: expertChecks.filter((c) => c.box.checked).map((c) => c.id),
|
|
120
|
+
defaultExpert: def.value,
|
|
121
|
+
agents: [...new Set(choices.filter((e) => expertChecks.some((c) => c.id === e.id && c.box.checked)).map((e) => e.engine))],
|
|
122
|
+
defaultAgent: choices.find((e) => e.id === def.value)?.engine ?? b.defaultAgent,
|
|
101
123
|
};
|
|
102
124
|
};
|
|
103
125
|
const save = async () => {
|
|
104
126
|
const v = collect();
|
|
105
|
-
if (!v.
|
|
106
|
-
toast("
|
|
127
|
+
if (!v.experts.length) {
|
|
128
|
+
toast("至少勾选一个专家");
|
|
107
129
|
return false;
|
|
108
130
|
}
|
|
109
131
|
// 只存这一个:其它机器人按服务端现在的样子原样带上,别的草稿不跟着存
|
|
@@ -125,8 +147,8 @@ export function feishuTab(cfg, page) {
|
|
|
125
147
|
field("名称", name),
|
|
126
148
|
h("div", { class: "row" }, h("div", { style: { flex: 1 } }, field("App ID", appId)), h("div", { style: { flex: 1 } }, field("App Secret", secret))),
|
|
127
149
|
field("域名", domain),
|
|
128
|
-
|
|
129
|
-
field("
|
|
150
|
+
expertField(h("div", { class: "row" }, expertChecks.map((c) => c.el)), "只勾一个共享专家即可专用;无需再勾选底层 Agent。勾多个可用 /expert 切换。保存后按这里的名单限制可选专家"),
|
|
151
|
+
field("默认专家", def, "新聊天和绑定账号后使用;已有聊天在当前专家仍可用时继续使用原专家"),
|
|
130
152
|
field("Owner 白名单(open_id)", allow, "陌生人发消息会拿到配对码,在下面「配对请求」里批准即可,不必手填"),
|
|
131
153
|
h(
|
|
132
154
|
"div",
|
|
@@ -174,22 +196,24 @@ export function feishuTab(cfg, page) {
|
|
|
174
196
|
|
|
175
197
|
const registerBot = async () => {
|
|
176
198
|
const nameInput = h("input", { value: "Agent 助手" });
|
|
177
|
-
const checks =
|
|
199
|
+
const checks = choices.map((e) => ({ id: e.id, box: h("input", { type: "checkbox", checked: false }), label: e.label }));
|
|
178
200
|
const body = h(
|
|
179
201
|
"div",
|
|
180
202
|
{ class: "modal-body" },
|
|
181
203
|
h("div", { class: "muted" }, "用飞书扫码,会自动创建一个飞书应用(机器人),并把扫码的你设为 owner。"),
|
|
182
204
|
field("机器人名称", nameInput),
|
|
183
|
-
|
|
205
|
+
expertField(h("div", { class: "row" }, checks.map((c) => h("label", { class: "check" }, c.box, c.label))), "可直接选择共享专家;选多个时默认使用第一个,创建后可以再调整默认专家"),
|
|
184
206
|
);
|
|
185
207
|
const go = h("button", { class: "btn primary" }, "生成二维码");
|
|
186
208
|
const closeReg = modal({ title: "扫码创建飞书机器人", body, foot: h("div", { class: "modal-foot" }, go) });
|
|
187
209
|
go.onclick = async () => {
|
|
210
|
+
const selected = checks.filter((c) => c.box.checked).map((c) => c.id);
|
|
211
|
+
if (!selected.length) return toast("至少勾选一个专家");
|
|
188
212
|
go.disabled = true;
|
|
189
213
|
try {
|
|
190
214
|
const reg = await api("/api/feishu/register", {
|
|
191
215
|
method: "POST",
|
|
192
|
-
body: { name: nameInput.value,
|
|
216
|
+
body: { name: nameInput.value, experts: selected, defaultExpert: selected[0] },
|
|
193
217
|
});
|
|
194
218
|
const state = h("div", { class: "muted", style: { textAlign: "center" } }, "等待扫码确认…");
|
|
195
219
|
fill(
|
package/web/views/experts.js
CHANGED