agent-loft 0.2.111 → 0.2.113
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 -3
- package/package.json +1 -1
- package/src/agents/codex/protocol.ts +10 -0
- package/src/agents/codex/session.ts +201 -5
- package/src/agents/dsh/acp.ts +193 -0
- package/src/agents/dsh/driver.ts +126 -0
- package/src/agents/dsh/errors.ts +43 -0
- package/src/agents/dsh/history.ts +346 -0
- package/src/agents/dsh/sdk.ts +191 -0
- package/src/agents/dsh/session.ts +454 -0
- package/src/agents/dsh/steps.ts +22 -0
- package/src/agents/dsh/which.ts +23 -0
- package/src/agents/health.ts +51 -2
- package/src/channels/feishu/bot.ts +1 -1
- package/src/channels/web/api.ts +14 -0
- package/src/channels/web/experts-api.ts +1 -0
- package/src/channels/web/server.ts +28 -1
- package/src/core/builtin-agents.ts +1 -1
- package/src/core/command-catalog.ts +2 -1
- package/src/core/commands.ts +2 -1
- package/src/core/config.ts +23 -3
- package/src/core/expert-prompt.ts +15 -0
- package/src/core/experts.ts +22 -3
- package/src/core/hub.ts +60 -3
- package/src/core/memory-curator.ts +2 -2
- package/src/core/memory.ts +2 -2
- package/src/core/permission.ts +1 -1
- package/src/core/types.ts +19 -0
- package/src/core/users.ts +1 -1
- package/src/main.ts +5 -1
- package/web/css/composer.css +164 -0
- package/web/css/experts.css +66 -0
- package/web/lib/dom.js +2 -0
- package/web/lib/ws.js +4 -0
- package/web/settings/agent-defaults.js +2 -2
- package/web/settings/agents.js +15 -1
- package/web/settings/commands.js +1 -1
- package/web/settings/experts.js +86 -17
- package/web/settings/memory.js +2 -1
- package/web/views/composer.js +3 -1
- package/web/views/messages.js +1 -1
- package/web/views/sidebar.js +1 -1
- package/web/views/topbar.js +3 -1
- package/web/views/voice-call.js +293 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// ACP 的 stdio MCP 要绝对路径的命令:按 PATH 找出来
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export function resolveCommand(cmd: string, pathEnv = process.env.PATH ?? ""): string | undefined {
|
|
6
|
+
if (!cmd) return undefined;
|
|
7
|
+
if (path.isAbsolute(cmd)) return fs.existsSync(cmd) ? cmd : undefined;
|
|
8
|
+
if (cmd.includes("/")) {
|
|
9
|
+
const abs = path.resolve(cmd);
|
|
10
|
+
return fs.existsSync(abs) ? abs : undefined;
|
|
11
|
+
}
|
|
12
|
+
for (const dir of pathEnv.split(path.delimiter)) {
|
|
13
|
+
if (!dir) continue;
|
|
14
|
+
const full = path.join(dir, cmd);
|
|
15
|
+
try {
|
|
16
|
+
fs.accessSync(full, fs.constants.X_OK);
|
|
17
|
+
if (fs.statSync(full).isFile()) return full;
|
|
18
|
+
} catch {
|
|
19
|
+
// 这个目录没有
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
package/src/agents/health.ts
CHANGED
|
@@ -13,6 +13,8 @@ import { onLoginDone, readAccount } from "./workbuddy/account.js";
|
|
|
13
13
|
import { desktopCli, ENVIRONMENT_LABEL, environment } from "./workbuddy/sdk.js";
|
|
14
14
|
import { listProviders, MIN_NODE, nodeOk } from "./pi/sdk.js";
|
|
15
15
|
import { onOAuthDone } from "./pi/oauth.js";
|
|
16
|
+
import { dshHome } from "./dsh/sdk.js";
|
|
17
|
+
import fs from "node:fs";
|
|
16
18
|
|
|
17
19
|
const require = createRequire(import.meta.url);
|
|
18
20
|
|
|
@@ -27,7 +29,7 @@ export type AgentFix = {
|
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
export type AgentHealth = {
|
|
30
|
-
id: "claude" | "codex" | "workbuddy" | "pi";
|
|
32
|
+
id: "claude" | "codex" | "workbuddy" | "pi" | "dsh";
|
|
31
33
|
label: string;
|
|
32
34
|
enabled: boolean;
|
|
33
35
|
installed: boolean;
|
|
@@ -250,6 +252,51 @@ let cache: { at: number; value: AgentHealth[] } | null = null;
|
|
|
250
252
|
onLoginDone(() => {
|
|
251
253
|
cache = null;
|
|
252
254
|
});
|
|
255
|
+
/** dsh:全局装的 npm 命令;「登录」= DSH_HOME 的凭据里有 DeepSeek API Key,或服务进程有 DEEPSEEK_API_KEY */
|
|
256
|
+
async function dshHealth(): Promise<AgentHealth> {
|
|
257
|
+
const cfg = config().agents.dsh;
|
|
258
|
+
const base = { id: "dsh" as const, label: "dsh", enabled: cfg.enabled };
|
|
259
|
+
const ver = await run(cfg.path || "dsh", ["--version"], 15_000);
|
|
260
|
+
if (ver.code !== 0) {
|
|
261
|
+
return {
|
|
262
|
+
...base,
|
|
263
|
+
installed: false,
|
|
264
|
+
loggedIn: null,
|
|
265
|
+
problem: `找不到 ${cfg.path || "dsh"}`,
|
|
266
|
+
fix: {
|
|
267
|
+
action: "install",
|
|
268
|
+
title: "安装 dsh",
|
|
269
|
+
commands: ["npm install -g @deepseek-ai/dsh"],
|
|
270
|
+
note: "需要 Node.js 22 以上。agent-loft 以系统服务运行时 PATH 很短,装好后在下面把「dsh 可执行文件」填成绝对路径(终端里 command -v dsh 可以查到)。升级也是这条命令。",
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const version = ver.out.trim().split("\n").pop()?.trim();
|
|
275
|
+
let stored = false;
|
|
276
|
+
try {
|
|
277
|
+
stored = /^\s+DEEPSEEK_API_KEY:/m.test(fs.readFileSync(path.join(dshHome(), ".credentials.yaml"), "utf8"));
|
|
278
|
+
} catch {
|
|
279
|
+
// 还没有凭据文件
|
|
280
|
+
}
|
|
281
|
+
const loggedIn = stored || !!process.env.DEEPSEEK_API_KEY;
|
|
282
|
+
return {
|
|
283
|
+
...base,
|
|
284
|
+
installed: true,
|
|
285
|
+
...(version ? { version } : {}),
|
|
286
|
+
loggedIn,
|
|
287
|
+
...(loggedIn
|
|
288
|
+
? { account: stored ? "DeepSeek API Key(dsh 凭据)" : "DeepSeek API Key(环境变量)" }
|
|
289
|
+
: {
|
|
290
|
+
fix: {
|
|
291
|
+
action: "login" as const,
|
|
292
|
+
title: "配 DeepSeek API Key",
|
|
293
|
+
commands: [`${quote(cfg.path || "dsh")} web`],
|
|
294
|
+
note: "在服务器上运行这条命令,打开它给出的网页,在设置里填 DeepSeek API Key(存进 ~/.dsh/.credentials.yaml);也可以给 agent-loft 服务设 DEEPSEEK_API_KEY 环境变量。填好后点「重新检查」。",
|
|
295
|
+
},
|
|
296
|
+
}),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
253
300
|
onOAuthDone(() => {
|
|
254
301
|
cache = null;
|
|
255
302
|
});
|
|
@@ -285,7 +332,9 @@ export function agentHealth(refresh = false): Promise<AgentHealth[]> {
|
|
|
285
332
|
// pi 没启用就不加载它的 SDK
|
|
286
333
|
const pi = () =>
|
|
287
334
|
config().agents.pi.enabled ? piHealth() : Promise.resolve<AgentHealth>({ id: "pi", label: "pi", enabled: false, installed: true, loggedIn: null });
|
|
288
|
-
|
|
335
|
+
const dsh = () =>
|
|
336
|
+
config().agents.dsh.enabled ? dshHealth() : Promise.resolve<AgentHealth>({ id: "dsh", label: "dsh", enabled: false, installed: true, loggedIn: null });
|
|
337
|
+
inflight ??= Promise.all([claudeHealth(), codexHealth(), workbuddy(), pi(), dsh()])
|
|
289
338
|
.then((value) => {
|
|
290
339
|
cache = { at: Date.now(), value };
|
|
291
340
|
return value;
|
|
@@ -102,7 +102,7 @@ export class FeishuBot {
|
|
|
102
102
|
const out: CommandEntry[] = [];
|
|
103
103
|
for (const agent of agents) {
|
|
104
104
|
if (!hub.driver(agent)) continue;
|
|
105
|
-
out.push(...(await hub.commandCatalog(agent, { allowedAgents: allowed, channel: "feishu" })).filter((c) => !["claude", "codex", "workbuddy", "pi"].includes(c.name) || this.cfg.experts === undefined || this.cfg.experts.includes(c.name)));
|
|
105
|
+
out.push(...(await hub.commandCatalog(agent, { allowedAgents: allowed, channel: "feishu" })).filter((c) => !["claude", "codex", "workbuddy", "pi", "dsh"].includes(c.name) || this.cfg.experts === undefined || this.cfg.experts.includes(c.name)));
|
|
106
106
|
}
|
|
107
107
|
return out;
|
|
108
108
|
}
|
package/src/channels/web/api.ts
CHANGED
|
@@ -359,6 +359,20 @@ function applyConfig(input: Partial<AppConfig>, selfOrigin?: string): void {
|
|
|
359
359
|
throw new HttpError(400, "pi 的思考程度只能是 off / minimal / low / medium / high / xhigh / max");
|
|
360
360
|
}
|
|
361
361
|
if (id === "pi" && "defaultModel" in patch && (typeof patch.defaultModel !== "string" || patch.defaultModel.length > 300)) throw new HttpError(400, "默认模型不对");
|
|
362
|
+
if (id === "dsh") {
|
|
363
|
+
const p = patch as Record<string, unknown>;
|
|
364
|
+
for (const key of ["path", "home", "patch"] as const) {
|
|
365
|
+
if (!(key in p)) continue;
|
|
366
|
+
const v = p[key];
|
|
367
|
+
if (typeof v !== "string" || v.length > 500) throw new HttpError(400, "路径不对");
|
|
368
|
+
const t = v.trim();
|
|
369
|
+
// dsh 可执行文件可以只写命令名(按 PATH 找),另外两个要么留空、要么绝对路径
|
|
370
|
+
if (t && key !== "path" && !path.isAbsolute(t)) throw new HttpError(400, key === "home" ? "DSH_HOME 要写绝对路径,留空用 ~/.dsh" : "patch 文件要写绝对路径,留空不加");
|
|
371
|
+
p[key] = key === "path" ? t || "dsh" : t;
|
|
372
|
+
}
|
|
373
|
+
if ("defaultEffort" in p && !["", "off", "low", "high", "max"].includes(String(p.defaultEffort))) throw new HttpError(400, "dsh 的思考程度只能是 off / low / high / max");
|
|
374
|
+
if ("defaultModel" in p && (typeof p.defaultModel !== "string" || p.defaultModel.length > 300)) throw new HttpError(400, "默认模型不对");
|
|
375
|
+
}
|
|
362
376
|
Object.assign(next.agents[id], patch);
|
|
363
377
|
}
|
|
364
378
|
}
|
|
@@ -19,7 +19,7 @@ import { skillEvents } from "../../core/skills.js";
|
|
|
19
19
|
import { expertEvents } from "../../core/experts.js";
|
|
20
20
|
import { enforceTerminalAccess, killAllTerminals, terminalEvents, watchTerminalAccess } from "../../core/terminals.js";
|
|
21
21
|
import { RUNNING_VERSION } from "../../core/upgrade.js";
|
|
22
|
-
import type { Settlement } from "../../core/types.js";
|
|
22
|
+
import type { RealtimeEvent, Settlement } from "../../core/types.js";
|
|
23
23
|
import { getUser, isAdmin, legacyOwnerId, userEvents, type User } from "../../core/users.js";
|
|
24
24
|
import { currentUser, handleApi, takeUploads } from "./api.js";
|
|
25
25
|
import { authEvents, ensureSetupToken, sessionUser } from "./auth.js";
|
|
@@ -303,6 +303,11 @@ function broadcastEvent(env: EventEnvelope): void {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
+
/** 语音对话的字幕和状态:只推给订阅了这条对话的页面(不进缓冲区,刷新后不重放) */
|
|
307
|
+
function broadcastRealtime({ key, ev }: { key: string; ev: RealtimeEvent }): void {
|
|
308
|
+
for (const client of clients) if (client.subs.has(key) && canSeeKey(client.user, key)) send(client, { t: "rt", key, ev });
|
|
309
|
+
}
|
|
310
|
+
|
|
306
311
|
function broadcastInteraction(i: Interaction): void {
|
|
307
312
|
for (const client of clients) if (canSeeKey(client.user, i.convKey)) send(client, { t: "ix", interaction: i });
|
|
308
313
|
}
|
|
@@ -527,6 +532,26 @@ function handleClientMessage(client: Client, raw: string): void {
|
|
|
527
532
|
return ack(true);
|
|
528
533
|
}
|
|
529
534
|
|
|
535
|
+
case "rt": {
|
|
536
|
+
// 实时语音对话:start 带浏览器的 SDP offer,ack 回对端 answer;stop 挂断
|
|
537
|
+
if (!getConversation(key) || !canSeeKey(user, key)) return ack(false, { error: "会话不存在" });
|
|
538
|
+
if (msg.op === "start") {
|
|
539
|
+
const sdp = typeof msg.sdp === "string" ? msg.sdp : "";
|
|
540
|
+
if (!sdp || sdp.length > 50_000) return ack(false, { error: "SDP 不对" });
|
|
541
|
+
client.subs.add(key);
|
|
542
|
+
void hub
|
|
543
|
+
.realtimeStart(key, sdp)
|
|
544
|
+
.then((answer) => ack(true, { sdp: answer }))
|
|
545
|
+
.catch((err) => ack(false, { error: err instanceof Error ? err.message : String(err) }));
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (msg.op === "stop") {
|
|
549
|
+
void hub.realtimeStop(key).then(() => ack(true), (err) => ack(false, { error: err instanceof Error ? err.message : String(err) }));
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
return ack(false, { error: "未知操作" });
|
|
553
|
+
}
|
|
554
|
+
|
|
530
555
|
case "ix": {
|
|
531
556
|
const id = String(msg.id ?? "");
|
|
532
557
|
const target = interactions.get(id);
|
|
@@ -665,6 +690,7 @@ export async function startWeb(): Promise<void> {
|
|
|
665
690
|
heartbeat.unref();
|
|
666
691
|
|
|
667
692
|
hub.on("event", broadcastEvent);
|
|
693
|
+
hub.on("realtime", broadcastRealtime);
|
|
668
694
|
hub.on("project-deleted", broadcastProjectDeleted);
|
|
669
695
|
hub.on("event", pushEvent);
|
|
670
696
|
interactions.on("created", broadcastInteraction);
|
|
@@ -717,6 +743,7 @@ function onRevoked(): void {
|
|
|
717
743
|
export async function stopWeb(): Promise<void> {
|
|
718
744
|
authEvents.off("revoked", onRevoked);
|
|
719
745
|
hub.off("event", broadcastEvent);
|
|
746
|
+
hub.off("realtime", broadcastRealtime);
|
|
720
747
|
hub.off("project-deleted", broadcastProjectDeleted);
|
|
721
748
|
hub.off("event", pushEvent);
|
|
722
749
|
interactions.off("created", broadcastInteraction);
|
|
@@ -53,7 +53,7 @@ export function builtinAgentDefaults(owner: string): Defaults {
|
|
|
53
53
|
mcp: stored?.[engine]?.mcp ?? (admin ? null : []),
|
|
54
54
|
permission: storedPermission(stored?.[engine]?.permission, engine, admin),
|
|
55
55
|
});
|
|
56
|
-
return { claude: defaults("claude"), codex: defaults("codex"), workbuddy: defaults("workbuddy"), pi: defaults("pi") };
|
|
56
|
+
return { claude: defaults("claude"), codex: defaults("codex"), workbuddy: defaults("workbuddy"), pi: defaults("pi"), dsh: defaults("dsh") };
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
function selection(value: unknown, what: string): string[] | null {
|
|
@@ -39,6 +39,7 @@ export const BUILTIN_COMMANDS: BuiltinSpec[] = [
|
|
|
39
39
|
{ name: "codex", description: "换成 Codex 专家(开新会话)", multiAgentOnly: true, chatOnly: true },
|
|
40
40
|
{ name: "workbuddy", description: "换成 WorkBuddy 专家(开新会话)", multiAgentOnly: true, chatOnly: true },
|
|
41
41
|
{ name: "pi", description: "换成 pi 专家(开新会话)", multiAgentOnly: true, chatOnly: true },
|
|
42
|
+
{ name: "dsh", description: "换成 dsh 专家(开新会话)", multiAgentOnly: true, chatOnly: true },
|
|
42
43
|
{ name: "web", description: "接上一条 Web 会话,在飞书里查看和回复", feishuOnly: true },
|
|
43
44
|
{ name: "detach", description: "不再接着 Web 会话,回到这个聊天自己的会话", feishuOnly: true },
|
|
44
45
|
{ name: "bind", args: "<绑定码>", description: "把这个飞书账号绑定到你的 agent-loft 用户(绑定码在 Web 的「设置 → 账号」里生成)", feishuOnly: true },
|
|
@@ -166,7 +167,7 @@ export function buildCatalog(params: {
|
|
|
166
167
|
(!c.feishuOnly || params.channel === undefined || params.channel === "feishu") &&
|
|
167
168
|
(!c.chatOnly || params.channel !== "web") &&
|
|
168
169
|
// /claude /codex 只在这个渠道能用对应 agent 时才有意义
|
|
169
|
-
(!["claude", "codex", "workbuddy", "pi"].includes(c.name) || params.allowedAgents.includes(c.name)),
|
|
170
|
+
(!["claude", "codex", "workbuddy", "pi", "dsh"].includes(c.name) || params.allowedAgents.includes(c.name)),
|
|
170
171
|
).map((c) => ({
|
|
171
172
|
name: c.name,
|
|
172
173
|
...(c.args ? { args: c.args } : {}),
|
package/src/core/commands.ts
CHANGED
|
@@ -70,6 +70,7 @@ export function parseCommand(raw: string): ParsedCommand {
|
|
|
70
70
|
case "codex":
|
|
71
71
|
case "workbuddy":
|
|
72
72
|
case "pi":
|
|
73
|
+
case "dsh":
|
|
73
74
|
return arg ? { kind: "chat", text } : { kind: "agent", agent: head.toLowerCase() };
|
|
74
75
|
case "stop":
|
|
75
76
|
return { kind: "stop" };
|
|
@@ -128,7 +129,7 @@ export function helpText(agents: string[], channel?: string): string {
|
|
|
128
129
|
...BUILTIN_COMMANDS.filter((c) => !c.multiAgentOnly || multi)
|
|
129
130
|
.filter((c) => !c.feishuOnly || channel === "feishu")
|
|
130
131
|
.filter((c) => !c.chatOnly || channel === "feishu" || channel === "weixin")
|
|
131
|
-
.filter((c) => !["claude", "codex", "workbuddy", "pi"].includes(c.name))
|
|
132
|
+
.filter((c) => !["claude", "codex", "workbuddy", "pi", "dsh"].includes(c.name))
|
|
132
133
|
.map((c) =>
|
|
133
134
|
c.name === "expert"
|
|
134
135
|
? `\`${usageOf(c)}\` ${c.description}${multi ? `,也可以直接发 ${agents.map((a) => `\`/${a}\``).join(" ")}` : ""}`
|
package/src/core/config.ts
CHANGED
|
@@ -88,6 +88,24 @@ export type AppConfig = {
|
|
|
88
88
|
defaultEffort: string;
|
|
89
89
|
models: string[];
|
|
90
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* dsh(DeepSeek Harness,npm i -g @deepseek-ai/dsh):每个会话一个 `dsh --profile acp` 进程。
|
|
93
|
+
* 凭据、会话记录都在 dsh 自己的 DSH_HOME(默认 ~/.dsh)里,见 agents/dsh/sdk.ts
|
|
94
|
+
*/
|
|
95
|
+
dsh: {
|
|
96
|
+
enabled: boolean;
|
|
97
|
+
/** dsh 可执行文件,以系统服务运行时 PATH 很短,建议写绝对路径 */
|
|
98
|
+
path: string;
|
|
99
|
+
/** DSH_HOME,空 = ~/.dsh */
|
|
100
|
+
home: string;
|
|
101
|
+
/** 每个进程都加上的 --patch 文件(比如接别家模型的 llm-pi-ai 配置),空 = 不加 */
|
|
102
|
+
patch: string;
|
|
103
|
+
/** 「服务商/模型」,如 deepseek-official/deepseek-v4-pro;空 = dsh 默认 */
|
|
104
|
+
defaultModel: string;
|
|
105
|
+
/** 思考程度(off / low / high / max),空 = dsh 默认 */
|
|
106
|
+
defaultEffort: string;
|
|
107
|
+
models: string[];
|
|
108
|
+
};
|
|
91
109
|
};
|
|
92
110
|
web: {
|
|
93
111
|
enabled: boolean;
|
|
@@ -107,7 +125,7 @@ export type AppConfig = {
|
|
|
107
125
|
quotaEnabled: boolean;
|
|
108
126
|
};
|
|
109
127
|
/** 输入「/」时命令列表的顺序和隐藏项,按 agent 分开(设置 → 命令) */
|
|
110
|
-
commands: { claude: CommandPrefs; codex: CommandPrefs; workbuddy: CommandPrefs; pi: CommandPrefs };
|
|
128
|
+
commands: { claude: CommandPrefs; codex: CommandPrefs; workbuddy: CommandPrefs; pi: CommandPrefs; dsh: CommandPrefs };
|
|
111
129
|
/** 远程控制:网页终端和远程桌面。管理员能用;成员要在 设置 → 用户 里单独开(users.json 的 remote) */
|
|
112
130
|
remote: {
|
|
113
131
|
terminal: boolean;
|
|
@@ -144,7 +162,7 @@ export type AppConfig = {
|
|
|
144
162
|
};
|
|
145
163
|
};
|
|
146
164
|
|
|
147
|
-
export const AGENT_IDS = ["claude", "codex", "workbuddy", "pi"] as const;
|
|
165
|
+
export const AGENT_IDS = ["claude", "codex", "workbuddy", "pi", "dsh"] as const;
|
|
148
166
|
|
|
149
167
|
export function defaultConfig(): AppConfig {
|
|
150
168
|
return {
|
|
@@ -168,9 +186,11 @@ export function defaultConfig(): AppConfig {
|
|
|
168
186
|
workbuddy: { enabled: false, environment: "workbuddy", cliPath: "", defaultModel: "", defaultEffort: "", models: [] },
|
|
169
187
|
// 默认不开:要先填一家服务商的 API Key
|
|
170
188
|
pi: { enabled: false, defaultModel: "", defaultEffort: "", models: [] },
|
|
189
|
+
// 默认不开:要先装 dsh、配 DeepSeek API Key
|
|
190
|
+
dsh: { enabled: false, path: "dsh", home: "", patch: "", defaultModel: "", defaultEffort: "", models: [] },
|
|
171
191
|
},
|
|
172
192
|
web: { enabled: true, host: "0.0.0.0", port: 8800, passwordHash: "", trustedProxies: ["127.0.0.1", "::1"], quotaRefreshMin: 10, quotaEnabled: true },
|
|
173
|
-
commands: { claude: { order: [], hidden: [], custom: [] }, codex: { order: [], hidden: [], custom: [] }, workbuddy: { order: [], hidden: [], custom: [] }, pi: { order: [], hidden: [], custom: [] } },
|
|
193
|
+
commands: { claude: { order: [], hidden: [], custom: [] }, codex: { order: [], hidden: [], custom: [] }, workbuddy: { order: [], hidden: [], custom: [] }, pi: { order: [], hidden: [], custom: [] }, dsh: { order: [], hidden: [], custom: [] } },
|
|
174
194
|
remote: {
|
|
175
195
|
terminal: true,
|
|
176
196
|
desktop: true,
|
|
@@ -140,7 +140,22 @@ export function wrapContext(lines: string[]): string {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/** 剥掉 contextBlock(读历史、列会话标题时用)。一条消息里可能有好几段(定时任务的说明 + Codex 的专家说明) */
|
|
143
|
+
/** 语音对话转交给 Codex 的那一轮,用户消息长这样:<realtime_delegation><input>说的话</input>…</realtime_delegation> */
|
|
144
|
+
const REALTIME_RE = /^\s*<realtime_delegation>[\s\S]*?<input>([\s\S]*?)<\/input>[\s\S]*<\/realtime_delegation>\s*$/;
|
|
145
|
+
const XML_ENTITIES: Record<string, string> = { "<": "<", ">": ">", """: '"', "'": "'", "&": "&" };
|
|
146
|
+
|
|
147
|
+
/** 语音转交的那一轮用户说了什么;不是语音转交的返回 undefined */
|
|
148
|
+
export function realtimeInput(text: string): string | undefined {
|
|
149
|
+
const m = REALTIME_RE.exec(text);
|
|
150
|
+
return m ? m[1]!.replace(/&(lt|gt|quot|apos|amp);/g, (e) => XML_ENTITIES[e] ?? e).trim() : undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 显示时语音说的话前面加个麦克风,和打字发的区分开 */
|
|
154
|
+
export const VOICE_MARK = "🎙️ ";
|
|
155
|
+
|
|
143
156
|
export function stripContext(text: string): string {
|
|
157
|
+
const voice = realtimeInput(text);
|
|
158
|
+
if (voice !== undefined) return `${VOICE_MARK}${voice}`;
|
|
144
159
|
let out = text;
|
|
145
160
|
for (let start = out.indexOf(OPEN); start >= 0; start = out.indexOf(OPEN)) {
|
|
146
161
|
const end = out.indexOf(CLOSE, start);
|
package/src/core/experts.ts
CHANGED
|
@@ -16,8 +16,8 @@ import { canUseMcp, claudeMachineMcp, getMcp, isMachineId, machineName, specOf,
|
|
|
16
16
|
import { activeSkills, canSee, getSkill } from "./skills.js";
|
|
17
17
|
import { canUseResource, getUser } from "./users.js";
|
|
18
18
|
|
|
19
|
-
export type Engine = "claude" | "codex" | "workbuddy" | "pi";
|
|
20
|
-
export const ENGINES: readonly Engine[] = ["claude", "codex", "workbuddy", "pi"];
|
|
19
|
+
export type Engine = "claude" | "codex" | "workbuddy" | "pi" | "dsh";
|
|
20
|
+
export const ENGINES: readonly Engine[] = ["claude", "codex", "workbuddy", "pi", "dsh"];
|
|
21
21
|
/** 能建自定义专家的引擎。WorkBuddy 目前只有内置专家(工具名、子智能体还没对齐) */
|
|
22
22
|
export const EXPERT_ENGINES: readonly Engine[] = ["claude", "codex", "pi"];
|
|
23
23
|
|
|
@@ -64,6 +64,8 @@ export type Expert = {
|
|
|
64
64
|
mcp: string[];
|
|
65
65
|
/** 子智能体:别的专家的 id。只有 Claude 支持 */
|
|
66
66
|
subagents: string[];
|
|
67
|
+
/** Codex 自带、专家默认关掉的能力,勾了才开(只有 Codex 专家)。老数据没有这一项 = 都不开 */
|
|
68
|
+
codexTools?: CodexTool[];
|
|
67
69
|
/** 带不带主人的个人记忆 */
|
|
68
70
|
memory: boolean;
|
|
69
71
|
/** 每存一次加一 */
|
|
@@ -74,6 +76,19 @@ export type Expert = {
|
|
|
74
76
|
|
|
75
77
|
export const BUILTIN_IDS: readonly Engine[] = ENGINES;
|
|
76
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Codex 专家可以单独打开的自带能力(agents/codex/session.ts 的 expertConfig 按它开 feature)。
|
|
81
|
+
* browser = browser_use + in_app_browser;apps = plugins + apps + 应用说明提示词。
|
|
82
|
+
*/
|
|
83
|
+
export const CODEX_TOOLS = ["image_generation", "multi_agent", "browser", "computer_use", "apps"] as const;
|
|
84
|
+
export type CodexTool = (typeof CODEX_TOOLS)[number];
|
|
85
|
+
/**
|
|
86
|
+
* 用的是这台机器上的东西:浏览器的登录状态、桌面、Codex 登录账号连的应用(邮箱、网盘……)。
|
|
87
|
+
* 和机器上的 MCP 一样只给管理员:只有管理员能勾,共享出去后别人用时也不开。
|
|
88
|
+
*/
|
|
89
|
+
export const CODEX_ADMIN_TOOLS: readonly CodexTool[] = ["browser", "computer_use", "apps"];
|
|
90
|
+
const isCodexTool = (t: string): t is CodexTool => (CODEX_TOOLS as readonly string[]).includes(t);
|
|
91
|
+
|
|
77
92
|
export function isBuiltin(id: string): id is Engine {
|
|
78
93
|
return (BUILTIN_IDS as readonly string[]).includes(id);
|
|
79
94
|
}
|
|
@@ -285,7 +300,7 @@ function validate(owner: string, input: ExpertInput, prev?: Expert, selfId?: str
|
|
|
285
300
|
const name = text(pick("name"), EXPERT_LIMITS.name, "名字");
|
|
286
301
|
if (!name) throw new Error("给专家起个名字");
|
|
287
302
|
const engine = pick("engine");
|
|
288
|
-
if (engine !== "claude" && engine !== "codex" && engine !== "pi") throw new Error(engine === "workbuddy" ? "WorkBuddy 暂不支持自定义专家,用内置的 WorkBuddy 就好" : "引擎只能是 Claude、Codex 或 pi");
|
|
303
|
+
if (engine !== "claude" && engine !== "codex" && engine !== "pi") throw new Error(engine === "workbuddy" ? "WorkBuddy 暂不支持自定义专家,用内置的 WorkBuddy 就好" : engine === "dsh" ? "dsh 暂不支持自定义专家,用内置的 dsh 就好" : "引擎只能是 Claude、Codex 或 pi");
|
|
289
304
|
if (prev && prev.engine !== engine) throw new Error("建好之后不能换引擎(用这个专家的对话都是这个引擎的会话)");
|
|
290
305
|
const access = pick("access");
|
|
291
306
|
if (!ACCESS_LEVELS.includes(access as ExpertAccess)) throw new Error("权限不对");
|
|
@@ -369,6 +384,7 @@ function validate(owner: string, input: ExpertInput, prev?: Expert, selfId?: str
|
|
|
369
384
|
skills,
|
|
370
385
|
mcp,
|
|
371
386
|
subagents,
|
|
387
|
+
codexTools: engine === "codex" ? ids(pick("codexTools")).filter(isCodexTool).filter((t) => admin || !CODEX_ADMIN_TOOLS.includes(t)) : [],
|
|
372
388
|
memory: pick("memory") !== false,
|
|
373
389
|
};
|
|
374
390
|
}
|
|
@@ -467,6 +483,8 @@ export type ExpertRuntime = {
|
|
|
467
483
|
/** 选中的机器上的 MCP 名字(Codex:除了这些,机器上的都关掉) */
|
|
468
484
|
machineMcp: string[];
|
|
469
485
|
subagents: SubagentRuntime[];
|
|
486
|
+
/** 要打开的 Codex 自带能力(只有 Codex 专家;本机能力只在用的人是管理员时给) */
|
|
487
|
+
codexTools: CodexTool[];
|
|
470
488
|
memory: boolean;
|
|
471
489
|
};
|
|
472
490
|
|
|
@@ -557,6 +575,7 @@ export function expertRuntime(expert: Expert, subPrompt: (sub: Expert, access: E
|
|
|
557
575
|
askMcp: ask,
|
|
558
576
|
machineMcp: machine,
|
|
559
577
|
subagents,
|
|
578
|
+
codexTools: expert.engine === "codex" ? (expert.codexTools ?? []).filter((t) => isCodexTool(t) && (admin || !CODEX_ADMIN_TOOLS.includes(t))) : [],
|
|
560
579
|
memory: expert.memory,
|
|
561
580
|
};
|
|
562
581
|
}
|
package/src/core/hub.ts
CHANGED
|
@@ -49,6 +49,7 @@ import type {
|
|
|
49
49
|
HistoryMessage,
|
|
50
50
|
InteractionSpec,
|
|
51
51
|
ModelInfo,
|
|
52
|
+
RealtimeEvent,
|
|
52
53
|
RuntimeInfo,
|
|
53
54
|
SessionSummary,
|
|
54
55
|
StepKind,
|
|
@@ -59,7 +60,7 @@ import type {
|
|
|
59
60
|
import { buildCatalog, expandCustomCommand, type AgentCommand, type CommandEntry, type CommandPrefs } from "./command-catalog.js";
|
|
60
61
|
import { helpText, type ParsedCommand } from "./commands.js";
|
|
61
62
|
import { listScheduled } from "./scheduled.js";
|
|
62
|
-
import { expertSystemPrompt, searchLabel, stripContext, wrapContext } from "./expert-prompt.js";
|
|
63
|
+
import { expertSystemPrompt, searchLabel, stripContext, VOICE_MARK, wrapContext } from "./expert-prompt.js";
|
|
63
64
|
import { availableExperts, avatarUrl, canUseExpert, expertEvents, expertToolEvents, expertRuntime, getExpert, isBuiltin, type ExpertRuntime } from "./experts.js";
|
|
64
65
|
import { builtinAgentDefaults, builtinAgentEvents, builtinAgentSession, defaultPermissionOf } from "./builtin-agents.js";
|
|
65
66
|
import { mcpEvents } from "./mcp.js";
|
|
@@ -289,7 +290,13 @@ function mergeSessionHistory(blocks: HistoryMessage[][], main: HistoryMessage[])
|
|
|
289
290
|
return out;
|
|
290
291
|
}
|
|
291
292
|
|
|
292
|
-
class Hub extends EventEmitter<{
|
|
293
|
+
class Hub extends EventEmitter<{
|
|
294
|
+
event: [EventEnvelope];
|
|
295
|
+
task: [TaskTurnEnd];
|
|
296
|
+
"project-deleted": [{ owner: string; path: string; keys: string[] }];
|
|
297
|
+
/** 实时语音对话的动静:只推给正看着这条对话的页面,不进会话记录 */
|
|
298
|
+
realtime: [{ key: string; ev: RealtimeEvent }];
|
|
299
|
+
}> {
|
|
293
300
|
private drivers = new Map<string, AgentDriver>();
|
|
294
301
|
private live = new Map<string, Live>();
|
|
295
302
|
/**
|
|
@@ -833,6 +840,12 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
833
840
|
if (!alive()) return;
|
|
834
841
|
this.emitEvent(key, { type: "turn_start" });
|
|
835
842
|
},
|
|
843
|
+
onExternalTurn: (text, anchor) => {
|
|
844
|
+
if (!alive()) return;
|
|
845
|
+
this.externalTurn(key, text, anchor);
|
|
846
|
+
},
|
|
847
|
+
// 不看 alive:会话被换下去时发的「通话结束」也要让页面知道
|
|
848
|
+
onRealtime: (ev) => this.emit("realtime", { key, ev }),
|
|
836
849
|
onStep: (kind, text) => alive() && this.emitEvent(key, { type: "step", kind, text }),
|
|
837
850
|
onTodos: (todos) => alive() && this.emitEvent(key, { type: "todos", todos }),
|
|
838
851
|
onTextDelta: (text) => alive() && this.emitEvent(key, { type: "delta", text }),
|
|
@@ -2041,6 +2054,50 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
2041
2054
|
}
|
|
2042
2055
|
}
|
|
2043
2056
|
|
|
2057
|
+
// ---------- 实时语音对话(只有 Codex) ----------
|
|
2058
|
+
|
|
2059
|
+
/** 开始通话:offer 是浏览器的 WebRTC SDP,返回对端 answer。会话没拉起来就按绑定拉起 */
|
|
2060
|
+
async realtimeStart(key: string, offer: string): Promise<string> {
|
|
2061
|
+
const conv = getConversation(key);
|
|
2062
|
+
if (!conv) throw new Error("会话不存在");
|
|
2063
|
+
if (conv.agent !== "codex") throw new Error("只有 Codex 的对话能语音对话");
|
|
2064
|
+
if (this.rewinding.has(key)) throw new Error("会话正在回退,请稍后再试");
|
|
2065
|
+
const session = this.session(key);
|
|
2066
|
+
if (!session.startRealtime) throw new Error("这个 agent 不支持语音对话");
|
|
2067
|
+
touchConversation(key);
|
|
2068
|
+
return session.startRealtime(offer);
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
async realtimeStop(key: string): Promise<void> {
|
|
2072
|
+
await this.live.get(key)?.session.stopRealtime?.();
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
/**
|
|
2076
|
+
* 语音对话转交给 Codex 的一轮:像收到一条用户消息那样记账 —— 显示说的话、进忙碌、排进轮次队列、拍改动快照。
|
|
2077
|
+
* 之后的 onResult / onError 照常收尾。
|
|
2078
|
+
*/
|
|
2079
|
+
private externalTurn(key: string, text: string, anchor?: string): void {
|
|
2080
|
+
const conv = getConversation(key);
|
|
2081
|
+
if (!conv) return;
|
|
2082
|
+
const id = crypto.randomUUID();
|
|
2083
|
+
touchConversation(key);
|
|
2084
|
+
const shown = stripContext(text);
|
|
2085
|
+
if (!conv.title && conv.titleAuto !== false && shown.trim()) {
|
|
2086
|
+
updateConversation(key, { title: shown.replace(VOICE_MARK, "").trim().replace(/\s+/g, " ").slice(0, 40), titleAuto: true });
|
|
2087
|
+
this.emitEvent(key, { type: "meta" });
|
|
2088
|
+
}
|
|
2089
|
+
this.emitEvent(key, { type: "user", text: shown, attachments: [], files: [], origin: { channel: "voice", channelId: "voice", name: "语音" }, id, queued: false });
|
|
2090
|
+
if (anchor) this.emitEvent(key, { type: "user_anchor", id, anchor });
|
|
2091
|
+
if (!this.isBusy(key)) void this.snapshotBeforeTurn(key).catch(() => {});
|
|
2092
|
+
this.setInflight(key, (this.inflight.get(key) ?? 0) + 1);
|
|
2093
|
+
const tags = this.turnTags.get(key) ?? [];
|
|
2094
|
+
tags.push(null);
|
|
2095
|
+
this.turnTags.set(key, tags);
|
|
2096
|
+
const fifo = this.turnFifo.get(key) ?? [];
|
|
2097
|
+
fifo.push({ id, input: { text: shown, attachments: [], id }, queued: false });
|
|
2098
|
+
this.turnFifo.set(key, fifo);
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2044
2101
|
async stop(key: string): Promise<string> {
|
|
2045
2102
|
// 不进串行队列:停止要立刻生效。排队中还没送出的消息靠代次作废
|
|
2046
2103
|
this.stopGen.set(key, (this.stopGen.get(key) ?? 0) + 1);
|
|
@@ -2364,7 +2421,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd]; "p
|
|
|
2364
2421
|
...(channel ? { channel } : {}),
|
|
2365
2422
|
...(owner && getUser(owner)?.role !== "admin" ? { member: true } : {}),
|
|
2366
2423
|
});
|
|
2367
|
-
return { type: "commands", agent: conv.agent, commands: all.filter((c) => !c.hidden && (!["claude", "codex", "workbuddy", "pi"].includes(c.name) || ctx.allowedExperts === undefined || ctx.allowedExperts.includes(c.name))) };
|
|
2424
|
+
return { type: "commands", agent: conv.agent, commands: all.filter((c) => !c.hidden && (!["claude", "codex", "workbuddy", "pi", "dsh"].includes(c.name) || ctx.allowedExperts === undefined || ctx.allowedExperts.includes(c.name))) };
|
|
2368
2425
|
}
|
|
2369
2426
|
case "pwd":
|
|
2370
2427
|
return text(getConversation(key)!.cwd);
|
|
@@ -480,7 +480,7 @@ export function describeResult(r: CurateResult): string | undefined {
|
|
|
480
480
|
|
|
481
481
|
/** 按用户的设置挑 agent。指定的那个用不了就是 undefined(不悄悄换成另一个,免得用到他没想用的额度) */
|
|
482
482
|
export function pickDriver(settings: Pick<CurateSettings, "agent">): AgentDriver | undefined {
|
|
483
|
-
const usable = hub.enabledAgents().filter((d) => d.complete && agentAvailability(d.id as "claude" | "codex" | "workbuddy" | "pi")?.available !== false);
|
|
483
|
+
const usable = hub.enabledAgents().filter((d) => d.complete && agentAvailability(d.id as "claude" | "codex" | "workbuddy" | "pi" | "dsh")?.available !== false);
|
|
484
484
|
if (settings.agent !== "auto") return usable.find((d) => d.id === settings.agent);
|
|
485
485
|
return usable.find((d) => d.id === "claude") ?? usable[0];
|
|
486
486
|
}
|
|
@@ -525,7 +525,7 @@ export async function curateBatch(
|
|
|
525
525
|
const driver = opts.driver ?? pickDriver(memory.curate);
|
|
526
526
|
if (!driver) {
|
|
527
527
|
// 没有能用的 agent:留着,等它能用了再整理
|
|
528
|
-
log.error = memory.curate.agent === "auto" ? "没有能用的 agent" : `${({ claude: "Claude", codex: "Codex", workbuddy: "WorkBuddy", pi: "pi" } as Record<string, string>)[memory.curate.agent] ?? memory.curate.agent} 现在用不了(没启用、没装或没登录)`;
|
|
528
|
+
log.error = memory.curate.agent === "auto" ? "没有能用的 agent" : `${({ claude: "Claude", codex: "Codex", workbuddy: "WorkBuddy", pi: "pi", dsh: "dsh" } as Record<string, string>)[memory.curate.agent] ?? memory.curate.agent} 现在用不了(没启用、没装或没登录)`;
|
|
529
529
|
patchMeta(userId, { lastCuration: log });
|
|
530
530
|
return log;
|
|
531
531
|
}
|
package/src/core/memory.ts
CHANGED
|
@@ -102,7 +102,7 @@ export type CurateSettings = {
|
|
|
102
102
|
idleMinutes: number;
|
|
103
103
|
dailyHour: number;
|
|
104
104
|
/** auto:Claude 能用就用 Claude,否则 Codex */
|
|
105
|
-
agent: "auto" | "claude" | "codex" | "workbuddy" | "pi";
|
|
105
|
+
agent: "auto" | "claude" | "codex" | "workbuddy" | "pi" | "dsh";
|
|
106
106
|
/** 空 = 这个 agent 最省的默认(Claude 用 Haiku,Codex 用默认模型、思考程度 low) */
|
|
107
107
|
model: string;
|
|
108
108
|
};
|
|
@@ -120,7 +120,7 @@ function cleanCurate(raw: Partial<CurateSettings> | undefined, base: CurateSetti
|
|
|
120
120
|
: base.experts;
|
|
121
121
|
const idle = Math.round(Number(r.idleMinutes ?? base.idleMinutes));
|
|
122
122
|
const hour = Math.round(Number(r.dailyHour ?? base.dailyHour));
|
|
123
|
-
const agent = (["auto", "claude", "codex", "workbuddy", "pi"] as const).find((a) => a === r.agent) ?? base.agent;
|
|
123
|
+
const agent = (["auto", "claude", "codex", "workbuddy", "pi", "dsh"] as const).find((a) => a === r.agent) ?? base.agent;
|
|
124
124
|
const model = typeof r.model === "string" ? r.model.trim().slice(0, 100) : base.model;
|
|
125
125
|
return {
|
|
126
126
|
when,
|
package/src/core/permission.ts
CHANGED
|
@@ -31,7 +31,7 @@ export function isPermissionLevel(v: unknown): v is PermissionLevel {
|
|
|
31
31
|
return typeof v === "string" && (PERMISSION_LEVELS as readonly string[]).includes(v);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
/** 这个引擎认不认这一级:自动判断只有 Claude 有(WorkBuddy、pi 也按自动改文件算) */
|
|
34
|
+
/** 这个引擎认不认这一级:自动判断只有 Claude 有(WorkBuddy、pi、dsh 也按自动改文件算) */
|
|
35
35
|
export function engineSupports(agent: string, level: PermissionLevel): boolean {
|
|
36
36
|
return level !== "auto" || agent === "claude";
|
|
37
37
|
}
|
package/src/core/types.ts
CHANGED
|
@@ -135,8 +135,23 @@ export type AgentEvents = {
|
|
|
135
135
|
* 否则是新增的量(Codex,每次模型请求报一次),由核心累加
|
|
136
136
|
*/
|
|
137
137
|
onUsage?: (usage: TokenUsage, cumulative?: boolean) => void;
|
|
138
|
+
/**
|
|
139
|
+
* 不是从这边发起的一轮开始了(Codex 语音对话把事情转交给它):text 是用户说的话,anchor 是轮次 id。
|
|
140
|
+
* 核心据此像收到一条用户消息那样记账(显示、忙碌、排队、改动快照),之后照常有 onResult / onError
|
|
141
|
+
*/
|
|
142
|
+
onExternalTurn?: (text: string, anchor?: string) => void;
|
|
143
|
+
/** 实时语音对话的动静(只有 Codex):字幕、开始、结束、出错 */
|
|
144
|
+
onRealtime?: (ev: RealtimeEvent) => void;
|
|
138
145
|
};
|
|
139
146
|
|
|
147
|
+
/** 实时语音对话的事件(Codex 的 thread/realtime/*) */
|
|
148
|
+
export type RealtimeEvent =
|
|
149
|
+
| { type: "started" }
|
|
150
|
+
| { type: "transcript"; role: "user" | "assistant"; delta: string }
|
|
151
|
+
| { type: "transcript_done"; role: "user" | "assistant"; text: string }
|
|
152
|
+
| { type: "error"; message: string }
|
|
153
|
+
| { type: "closed"; reason?: string };
|
|
154
|
+
|
|
140
155
|
/** 上下文窗口占用:used / window 都是 token 数,percent 是 0-100(可能略超 100) */
|
|
141
156
|
export type ContextUsage = { used: number; window: number; percent: number };
|
|
142
157
|
|
|
@@ -299,6 +314,10 @@ export interface AgentSession {
|
|
|
299
314
|
setPermission?(level: PermissionLevel | undefined): Promise<void>;
|
|
300
315
|
/** 开关计划模式。Claude 立即生效,Codex 下一轮生效 */
|
|
301
316
|
setPlan?(on: boolean): Promise<void>;
|
|
317
|
+
/** 开始实时语音对话(只有 Codex):offer 是浏览器的 WebRTC SDP,返回对端的 answer */
|
|
318
|
+
startRealtime?(offer: string): Promise<string>;
|
|
319
|
+
/** 挂断实时语音对话;没在通话就什么都不做 */
|
|
320
|
+
stopRealtime?(): Promise<void>;
|
|
302
321
|
}
|
|
303
322
|
|
|
304
323
|
export type Diagnosis = {
|
package/src/core/users.ts
CHANGED
|
@@ -204,7 +204,7 @@ function cleanPermissions(value: unknown, current: ResourcePermissions = {}): Re
|
|
|
204
204
|
for (const [kind, ids] of Object.entries(value)) {
|
|
205
205
|
if (!["experts", "agents", "servers"].includes(kind)) throw new Error("未知的使用权限");
|
|
206
206
|
if (ids !== null && (!Array.isArray(ids) || ids.length > 200 || ids.some((id) => typeof id !== "string" || !/^[\w-]{1,100}$/.test(id)))) throw new Error("使用权限必须是 ID 列表或 null");
|
|
207
|
-
if (kind === "agents" && ids?.some((id: string) => !["claude", "codex", "workbuddy", "pi"].includes(id))) throw new Error("未知的内置 Agent");
|
|
207
|
+
if (kind === "agents" && ids?.some((id: string) => !["claude", "codex", "workbuddy", "pi", "dsh"].includes(id))) throw new Error("未知的内置 Agent");
|
|
208
208
|
next[kind as ResourceKind] = ids === null ? null : [...new Set(ids as string[])];
|
|
209
209
|
}
|
|
210
210
|
return next;
|
package/src/main.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { ClaudeDriver } from "./agents/claude/driver.js";
|
|
|
7
7
|
import { CodexDriver } from "./agents/codex/driver.js";
|
|
8
8
|
import { WorkBuddyDriver } from "./agents/workbuddy/driver.js";
|
|
9
9
|
import { PiDriver } from "./agents/pi/driver.js";
|
|
10
|
+
import { DshDriver } from "./agents/dsh/driver.js";
|
|
10
11
|
import { agentHealth } from "./agents/health.js";
|
|
11
12
|
import { startFeishu, stopFeishu } from "./channels/feishu/index.js";
|
|
12
13
|
import { startWeixin, stopWeixin } from "./channels/weixin/index.js";
|
|
@@ -22,7 +23,7 @@ import { startScheduler, stopScheduler } from "./core/scheduled.js";
|
|
|
22
23
|
import { startTaskRunner, stopTaskRunner } from "./core/task-runner.js";
|
|
23
24
|
import { startTasksBridge, stopTasksBridge } from "./core/tasks-bridge.js";
|
|
24
25
|
|
|
25
|
-
async function startDriver(id: "claude" | "codex" | "workbuddy" | "pi"): Promise<void> {
|
|
26
|
+
async function startDriver(id: "claude" | "codex" | "workbuddy" | "pi" | "dsh"): Promise<void> {
|
|
26
27
|
const driver = hub.driver(id);
|
|
27
28
|
if (!driver) return;
|
|
28
29
|
try {
|
|
@@ -41,15 +42,18 @@ async function main(): Promise<void> {
|
|
|
41
42
|
hub.registerDriver(new CodexDriver());
|
|
42
43
|
hub.registerDriver(new WorkBuddyDriver());
|
|
43
44
|
hub.registerDriver(new PiDriver());
|
|
45
|
+
hub.registerDriver(new DshDriver());
|
|
44
46
|
if (config().agents.claude.enabled) await startDriver("claude");
|
|
45
47
|
if (config().agents.codex.enabled) await startDriver("codex");
|
|
46
48
|
if (config().agents.workbuddy.enabled) void startDriver("workbuddy");
|
|
47
49
|
if (config().agents.pi.enabled) void startDriver("pi");
|
|
50
|
+
if (config().agents.dsh.enabled) void startDriver("dsh");
|
|
48
51
|
// Web 上新启用了 Codex:现拉 app-server;WorkBuddy、pi 预先加载 SDK
|
|
49
52
|
onConfigChange((next, prev) => {
|
|
50
53
|
if (next.agents.codex.enabled && !prev.agents.codex.enabled) void startDriver("codex");
|
|
51
54
|
if (next.agents.workbuddy.enabled && !prev.agents.workbuddy.enabled) void startDriver("workbuddy");
|
|
52
55
|
if (next.agents.pi.enabled && !prev.agents.pi.enabled) void startDriver("pi");
|
|
56
|
+
if (next.agents.dsh.enabled && !prev.agents.dsh.enabled) void startDriver("dsh");
|
|
53
57
|
});
|
|
54
58
|
|
|
55
59
|
// 资料库:升级时把已有的附件收进来(只一次),再清掉对话没了的、上传了一直没发的
|