personal-bot 0.2.15 → 0.2.16
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/docs/agent-collaboration.md +5 -6
- package/docs/dsh.md +11 -11
- package/lib/common/schema.d.ts +2 -0
- package/lib/common/schema.js +9 -0
- package/lib/extension/dsh/command.js +13 -18
- package/lib/extension/dsh/workspace.js +0 -2
- package/lib/integrations/dsh/dsh-agents.d.ts +1 -2
- package/lib/integrations/dsh/dsh-agents.js +0 -4
- package/lib/model/agent.d.ts +0 -1
- package/lib/services/agents/agent-notices.js +1 -1
- package/lib/services/agents/agent-service.js +3 -2
- package/lib/services/agents/start-options.d.ts +4 -0
- package/lib/services/agents/start-options.js +20 -0
- package/lib/tools/agents/actions.d.ts +1 -5
- package/lib/tools/agents/actions.js +12 -1
- package/lib/tools/agents/contract.d.ts +50 -77
- package/lib/tools/agents/contract.js +54 -32
- package/lib/tools/agents/dsh-tool.js +6 -11
- package/lib/tools/history/contract.d.ts +28 -11
- package/lib/tools/history/contract.js +18 -12
- package/lib/tools/input.d.ts +11 -0
- package/lib/tools/input.js +23 -0
- package/lib/tools/teams/actions.d.ts +3 -4
- package/lib/tools/teams/actions.js +7 -5
- package/lib/tools/teams/contract.d.ts +56 -87
- package/lib/tools/teams/contract.js +55 -31
- package/lib/tools/teams/dsh-tool.js +7 -18
- package/package.json +1 -1
- package/resources/prompts/native-coordinator.md +1 -1
- package/src/common/schema.ts +10 -0
- package/src/extension/agent-events.ts +1 -1
- package/src/extension/dsh/command.ts +14 -19
- package/src/extension/dsh/workspace.ts +0 -1
- package/src/integrations/dsh/dsh-agents.ts +1 -4
- package/src/model/agent.ts +1 -1
- package/src/services/agents/agent-notices.ts +1 -1
- package/src/services/agents/agent-service.ts +4 -2
- package/src/services/agents/start-options.ts +19 -0
- package/src/tools/agents/actions.ts +18 -10
- package/src/tools/agents/contract.ts +68 -33
- package/src/tools/agents/dsh-tool.ts +7 -12
- package/src/tools/agents/tool.ts +2 -8
- package/src/tools/history/actions.ts +1 -1
- package/src/tools/history/contract.ts +27 -14
- package/src/tools/input.ts +29 -0
- package/src/tools/teams/actions.ts +10 -14
- package/src/tools/teams/contract.ts +71 -33
- package/src/tools/teams/dsh-tool.ts +7 -18
- package/src/tools/teams/tool.ts +3 -13
- package/lib/tools/agents/dsh-contract.d.ts +0 -45
- package/lib/tools/agents/dsh-contract.js +0 -19
- package/src/tools/agents/dsh-contract.ts +0 -20
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Type } from "../../common/typebox.js";
|
|
2
|
-
|
|
2
|
+
import { schema } from "../../common/schema.js";
|
|
3
|
+
import { inputObject, need, nullable, pick } from "../input.js";
|
|
4
|
+
export const teamDescription = "组织固定成员协作。create 建立团队,run 开始一批讨论。运行时占用成员;pause 停止新安排,允许在途工作收尾,之后可私人 send;中止成员用 pbot_agent stop。close 保留成员和历史;换成员须关闭旧团队再创建。继续讨论用 run 提交新要求。团队状态与批次用 status;公共原文用 pbot_team_message read/post。";
|
|
3
5
|
export const teamMessageDescription = "读写团队公共原文。post 向全体成员发布信息,需要安排回答时由主会话调用 pbot_team run;成员只能在自己的团队工作中 post。read 用 afterSeq 翻页,长正文按 seq/offset 续读,先补完 nextOffset 非空的消息。";
|
|
4
6
|
const id = Type.String({ minLength: 1, maxLength: 128 });
|
|
5
7
|
const text = Type.String({ minLength: 1, maxLength: 24000 });
|
|
@@ -8,43 +10,65 @@ const mode = Type.Union([Type.Literal("roundRobin"), Type.Literal("parallel")],
|
|
|
8
10
|
const members = Type.Array(Type.Object({ agentId: id, role: Type.String({ minLength: 1, maxLength: 4000 }) }, { additionalProperties: false }), {
|
|
9
11
|
minItems: 1, maxItems: 50, description: "仅 create,必填:当前分支中的固定成员及职责;成员须版本兼容且未加入其他未关闭团队。",
|
|
10
12
|
});
|
|
11
|
-
const
|
|
12
|
-
instruction: Type.String({ ...text, description: "仅 run,必填:本批次的任务、约束与交付要求。" }),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
const page = {
|
|
18
|
-
afterSeq: Type.Optional(Type.Integer({ minimum: 0, description: "仅 read:读取序号大于此值的消息,默认 0,不得超过 lastSeq。返回 nextAfterSeq 用于继续消息列表;单条续读使用 seq/offset,省略 afterSeq。先补完被截断的正文,再继续列表。" })),
|
|
19
|
-
seq: Type.Optional(Type.Integer({ minimum: 1, description: "仅 read:指定一条消息,配合该消息的 nextOffset 续读。未指定时从 afterSeq 后顺序读取。" })),
|
|
20
|
-
offset: Type.Optional(Type.Integer({ minimum: 0, description: "仅 read:指定 seq 的正文 UTF-16 字符偏移,默认 0;非零时必须同时提供 seq。" })),
|
|
21
|
-
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 16000, description: "仅 read:本页所有消息正文合计的 UTF-16 字符上限,默认 16000,不是消息条数或 token 数;不含元数据和 Markdown 格式开销。" })),
|
|
13
|
+
const runFields = {
|
|
14
|
+
instruction: nullable(Type.String({ ...text, description: "仅 run,必填:本批次的任务、约束与交付要求。" })),
|
|
15
|
+
mode: nullable(mode),
|
|
16
|
+
rounds: nullable(Type.Integer({ minimum: 1, maximum: 10, description: "仅 run:每位成员的轮数,默认 2。" })),
|
|
17
|
+
maxConcurrent: nullable(Type.Integer({ minimum: 1, maximum: 50, description: "仅 run:roundRobin 默认且只允许 1;parallel 默认 min(2, 成员数)。不得超过成员数;待处理和执行中的发言都计入上限。" })),
|
|
18
|
+
timeoutSeconds: nullable(Type.Integer({ minimum: 1, maximum: 86400, description: "仅 run:整批期限,默认 900 秒,包含所有轮次和等待。到期停止安排并尝试中止尚未人工接管的工作,之后仍须核对实际状态;pause 则允许在途工作收尾。" })),
|
|
22
19
|
};
|
|
23
20
|
const object = (fields) => Type.Object(fields, { additionalProperties: false });
|
|
24
21
|
export const teamParametersSchema = object({
|
|
25
|
-
action: Type.Union(["create", "list", "status", "
|
|
26
|
-
description: "create 必填 name/brief/members;list
|
|
22
|
+
action: Type.Union(["create", "list", "status", "run", "pause", "close"].map(value => Type.Literal(value)), {
|
|
23
|
+
description: "create 必填 name/brief/members;list 只需 action;status/pause/close 必填 teamId;run 必填 teamId/instruction/mode,可选 rounds/maxConcurrent/timeoutSeconds。动作只读取自己的字段;其他已声明字段忽略。run 前须确认所有成员存活、idle、可参与团队且无待处理私人输入,团队未关闭,也无运行批次或在途工作。close 前先暂停并等待在途工作结束。",
|
|
27
24
|
}),
|
|
28
|
-
teamId:
|
|
29
|
-
instruction: Type.Optional(run.instruction), mode: Type.Optional(mode), rounds: run.rounds, maxConcurrent: run.maxConcurrent, timeoutSeconds: run.timeoutSeconds, ...page,
|
|
25
|
+
teamId: nullable(id), name: nullable(name), brief: nullable(text), members: nullable(members), ...runFields,
|
|
30
26
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
const validTeam = schema(teamParametersSchema);
|
|
28
|
+
export function teamInput(value) {
|
|
29
|
+
const args = inputObject(value, validTeam, "团队参数格式无效");
|
|
30
|
+
const action = args.action;
|
|
31
|
+
switch (action) {
|
|
32
|
+
case "create":
|
|
33
|
+
return { action, name: need("create", args, "name"), brief: need("create", args, "brief"), members: need("create", args, "members") };
|
|
34
|
+
case "list":
|
|
35
|
+
return { action };
|
|
36
|
+
case "status":
|
|
37
|
+
case "pause":
|
|
38
|
+
case "close":
|
|
39
|
+
return { action, teamId: need(action, args, "teamId") };
|
|
40
|
+
case "run":
|
|
41
|
+
return { action, teamId: need("run", args, "teamId"), instruction: need("run", args, "instruction"), mode: need("run", args, "mode"),
|
|
42
|
+
...(args.rounds === undefined ? {} : { rounds: args.rounds }),
|
|
43
|
+
...(args.maxConcurrent === undefined ? {} : { maxConcurrent: args.maxConcurrent }),
|
|
44
|
+
...(args.timeoutSeconds === undefined ? {} : { timeoutSeconds: args.timeoutSeconds }) };
|
|
45
|
+
default:
|
|
46
|
+
throw new Error("未知的团队 action。");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const page = {
|
|
50
|
+
afterSeq: nullable(Type.Integer({ minimum: 0, description: "仅 read:读取序号大于此值的消息,默认 0,不得超过 lastSeq。返回 nextAfterSeq 用于继续消息列表;单条续读使用 seq/offset,省略 afterSeq。先补完被截断的正文,再继续列表。" })),
|
|
51
|
+
seq: nullable(Type.Integer({ minimum: 1, description: "仅 read:指定一条消息,配合该消息的 nextOffset 续读。未指定时从 afterSeq 后顺序读取。" })),
|
|
52
|
+
offset: nullable(Type.Integer({ minimum: 0, description: "仅 read:指定 seq 的正文 UTF-16 字符偏移,默认 0;非零时必须同时提供 seq。" })),
|
|
53
|
+
limit: nullable(Type.Integer({ minimum: 1, maximum: 16000, description: "仅 read:本页所有消息正文合计的 UTF-16 字符上限,默认 16000,不是消息条数或 token 数;不含元数据和 Markdown 格式开销。" })),
|
|
54
|
+
};
|
|
38
55
|
export const teamMessageParametersSchema = object({
|
|
39
56
|
action: Type.Union([Type.Literal("read"), Type.Literal("post")], {
|
|
40
|
-
description: "read 必填 teamId
|
|
41
|
-
}), teamId: id, text:
|
|
42
|
-
replyTo:
|
|
57
|
+
description: "read 必填 teamId,可选 afterSeq/seq/offset/limit;post 必填 teamId/text,可选 replyTo。动作只读取自己的字段;其他已声明字段忽略。",
|
|
58
|
+
}), teamId: nullable(id), text: nullable(Type.String({ ...text, description: "仅 post,必填:向全体成员公开的原文。" })),
|
|
59
|
+
replyTo: nullable(Type.Integer({ minimum: 1, description: "仅 post:回复已有消息的 seq。" })), ...page,
|
|
43
60
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
const validMessage = schema(teamMessageParametersSchema);
|
|
62
|
+
export function teamMessageInput(value) {
|
|
63
|
+
const args = inputObject(value, validMessage, "团队消息参数格式无效");
|
|
64
|
+
if (args.action === "read")
|
|
65
|
+
return { action: "read", teamId: need("read", args, "teamId"),
|
|
66
|
+
...pick(args, ["afterSeq", "seq", "offset", "limit"]) };
|
|
67
|
+
if (args.action === "post")
|
|
68
|
+
return { action: "post", teamId: need("post", args, "teamId"), text: need("post", args, "text"),
|
|
69
|
+
...(args.replyTo === undefined ? {} : { replyTo: args.replyTo }) };
|
|
70
|
+
throw new Error("未知的团队消息 action。");
|
|
71
|
+
}
|
|
48
72
|
const message = object({ seq: Type.Integer(), operationId: Type.String(),
|
|
49
73
|
author: object({ kind: Type.Union([Type.Literal("user"), Type.Literal("coordinator"), Type.Literal("member")]), agentId: Type.Optional(id), name: Type.String() }),
|
|
50
74
|
text: Type.String(), replyTo: Type.Optional(Type.Integer()), runId: Type.Optional(id),
|
|
@@ -63,5 +87,5 @@ const ownedView = object({ teamId: id, name: Type.String(), brief: Type.String()
|
|
|
63
87
|
run: Type.Optional(object({ runId: id, instruction: Type.String(), mode, state: Type.Union([Type.Literal("running"), Type.Literal("paused"), Type.Literal("finished")]),
|
|
64
88
|
rounds: Type.Integer(), maxConcurrent: Type.Integer(), deadlineAt: Type.Number(), scheduled: Type.Integer(), published: Type.Integer(), reason: Type.Optional(Type.String()) })) });
|
|
65
89
|
const view = Type.Union([ownedView, object({ teamId: id, name: Type.String(), closed: Type.Boolean(), owned: Type.Literal(false) })]);
|
|
66
|
-
export const teamResultSchema = Type.Union([view, object({ teams: Type.Array(view) })
|
|
90
|
+
export const teamResultSchema = Type.Union([view, object({ teams: Type.Array(view) })]);
|
|
67
91
|
export const teamMessageResultSchema = Type.Union([teamPageSchema, object({ teamId: id, seq: Type.Integer(), status: Type.Literal("stored") })]);
|
|
@@ -5,30 +5,22 @@ import { schema } from "../../common/schema.js";
|
|
|
5
5
|
import { markdownFields } from "../../common/markdown.js";
|
|
6
6
|
import { teamMessagesMarkdown } from "../../integrations/team-context.js";
|
|
7
7
|
import { executeTeam, executeTeamMessage } from "./actions.js";
|
|
8
|
-
import { teamDescription, teamMessageDescription,
|
|
8
|
+
import { teamDescription, teamMessageDescription, teamInput, teamMessageInput, teamParametersSchema, teamResultSchema, teamMessageParametersSchema, teamMessageResultSchema } from "./contract.js";
|
|
9
9
|
export function registerDshTeamTool(ctx, agent, service, agents, owner, check) {
|
|
10
|
-
const validators = new Map(teamActionSchema.anyOf.map(row => [row.properties.action.const, schema(row)]));
|
|
11
10
|
const validOutput = schema(teamResultSchema);
|
|
12
11
|
ctx.tools.register({ name: "pbot_team", description: teamDescription, parameters: dshParameters(teamParametersSchema),
|
|
13
|
-
output: {
|
|
14
|
-
schema: dshOutputSchema(teamResultSchema),
|
|
15
|
-
render: (args, value) => [{ type: "text", text: object(args) && args.action === "read"
|
|
16
|
-
? teamMessagesMarkdown(value) : "# 团队\n\n" + markdownFields(value) }],
|
|
17
|
-
},
|
|
12
|
+
output: { schema: dshOutputSchema(teamResultSchema), render: (_args, value) => [{ type: "text", text: "# 团队\n\n" + markdownFields(value) }] },
|
|
18
13
|
async execute(args, exec) {
|
|
19
14
|
check();
|
|
20
15
|
exec.signal.throwIfAborted();
|
|
21
|
-
requireThat(exec.agent === agent
|
|
22
|
-
const
|
|
23
|
-
requireThat(valid && valid(args), "团队参数无效。");
|
|
24
|
-
const value = executeTeam(service, agents, args, owner).structuredContent;
|
|
16
|
+
requireThat(exec.agent === agent, "团队工具不属于当前会话。");
|
|
17
|
+
const value = executeTeam(service, agents, teamInput(args), owner).structuredContent;
|
|
25
18
|
requireThat(validOutput(value), "团队输出不符合契约。");
|
|
26
19
|
return value;
|
|
27
20
|
},
|
|
28
21
|
});
|
|
29
22
|
}
|
|
30
23
|
export function registerDshTeamMessageTool(ctx, agent, service, actor, check) {
|
|
31
|
-
const validators = new Map(teamMessageActionSchema.anyOf.map(row => [row.properties.action.const, schema(row)]));
|
|
32
24
|
const validOutput = schema(teamMessageResultSchema);
|
|
33
25
|
ctx.tools.register({ name: "pbot_team_message", description: teamMessageDescription, parameters: dshParameters(teamMessageParametersSchema),
|
|
34
26
|
output: {
|
|
@@ -39,12 +31,9 @@ export function registerDshTeamMessageTool(ctx, agent, service, actor, check) {
|
|
|
39
31
|
async execute(args, exec) {
|
|
40
32
|
check();
|
|
41
33
|
exec.signal.throwIfAborted();
|
|
42
|
-
requireThat(exec.agent === agent
|
|
43
|
-
const
|
|
44
|
-
requireThat(valid && valid(args), "团队消息参数无效。");
|
|
45
|
-
const value = executeTeamMessage(service, args, actor(), exec.callId).structuredContent;
|
|
34
|
+
requireThat(exec.agent === agent, "团队消息工具不属于当前会话。");
|
|
35
|
+
const value = executeTeamMessage(service, teamMessageInput(args), actor(), exec.callId).structuredContent;
|
|
46
36
|
requireThat(validOutput(value), "团队消息输出不符合契约。");
|
|
47
37
|
return value;
|
|
48
|
-
},
|
|
49
|
-
});
|
|
38
|
+
}, });
|
|
50
39
|
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
需要专家协助时用 pbot_agent
|
|
1
|
+
需要专家协助时用 pbot_agent;团队组织与批次用 pbot_team,团队公共原文用 pbot_team_message read/post。回溯旧讨论用 pbot_history。
|
package/src/common/schema.ts
CHANGED
|
@@ -9,3 +9,13 @@ export function schema(value: unknown): ValidateFunction {
|
|
|
9
9
|
addFormats.default(ajv);
|
|
10
10
|
return ajv.compile(value);
|
|
11
11
|
}
|
|
12
|
+
|
|
13
|
+
/** Name the concrete shape violation so the caller can correct the same field. */
|
|
14
|
+
export function schemaDetail(validate: ValidateFunction): string {
|
|
15
|
+
return (validate.errors ?? []).map(error => {
|
|
16
|
+
const params = error.params as Record<string, unknown>;
|
|
17
|
+
const field = typeof params.additionalProperty === "string" ? params.additionalProperty
|
|
18
|
+
: error.instancePath ? error.instancePath.slice(1).replaceAll("/", ".") : "参数";
|
|
19
|
+
return field + " " + (error.message ?? "不符合 schema");
|
|
20
|
+
}).join(";") || "不符合 schema";
|
|
21
|
+
}
|
|
@@ -111,7 +111,7 @@ export function registerAgentEvents(pi: ExtensionAPI, lifecycle: Lifecycle, conf
|
|
|
111
111
|
if (sent !== undefined && now - sent < 5000) return;
|
|
112
112
|
submitting.set(failure.key, now);
|
|
113
113
|
const recovery = failure.recovery === "reload"
|
|
114
|
-
? "团队服务或协作存储已停用,修复文件后当前实例仍不可用。先按错误信息排障,再请用户在当前 Pi 会话执行 /reload;重载前不要反复调用 pbot_team。重载后用 pbot_team status
|
|
114
|
+
? "团队服务或协作存储已停用,修复文件后当前实例仍不可用。先按错误信息排障,再请用户在当前 Pi 会话执行 /reload;重载前不要反复调用 pbot_team。重载后用 pbot_team status 与 pbot_team_message read 核对团队状态与公共原文。"
|
|
115
115
|
: failure.recovery === "retry"
|
|
116
116
|
? "团队控制锁持续被占用,后台会继续重试;锁释放后自动恢复扫描,不自动删除锁或重新提交任务。"
|
|
117
117
|
: "报告或控制记录读取失败。先按错误信息排障;修复后后台扫描会重试。";
|
|
@@ -4,14 +4,13 @@ import { Type, type Static } from "typebox";
|
|
|
4
4
|
import { object, json } from "../../common/json.js";
|
|
5
5
|
import { requireThat } from "../../common/validation.js";
|
|
6
6
|
import { schema } from "../../common/schema.js";
|
|
7
|
-
import { executeAgent
|
|
8
|
-
import {
|
|
7
|
+
import { executeAgent } from "../../tools/agents/actions.js";
|
|
8
|
+
import { agentInput } from "../../tools/agents/contract.js";
|
|
9
9
|
import { executeTeam, executeTeamMessage } from "../../tools/teams/actions.js";
|
|
10
|
-
import {
|
|
10
|
+
import { teamInput, teamMessageInput } from "../../tools/teams/contract.js";
|
|
11
11
|
import { dshWorkspaceStatus, type PbotManagement } from "./management.js";
|
|
12
12
|
import type { DshWorkspaces } from "./workspace.js";
|
|
13
13
|
|
|
14
|
-
const validAgent = schema(dshAgentActionSchema), validTeam = schema(teamActionSchema), validMessage = schema(teamMessageActionSchema);
|
|
15
14
|
const chatSchema = Type.Object({ agentId: Type.String({ minLength: 1 }), text: Type.Optional(Type.String({ maxLength: 24000 })),
|
|
16
15
|
delivery: Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("followUp")])),
|
|
17
16
|
files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32 })) }, { additionalProperties: false });
|
|
@@ -19,11 +18,11 @@ const validChat = schema(chatSchema);
|
|
|
19
18
|
const approvalSchema = Type.Object({ agentId: Type.String({ minLength: 1 }), requestId: Type.String({ minLength: 1 }),
|
|
20
19
|
optionId: Type.Union([Type.String({ minLength: 1 }), Type.Null()]) }, { additionalProperties: false });
|
|
21
20
|
const validApproval = schema(approvalSchema);
|
|
22
|
-
const usage = '用法:/pbot status | init | agent {"action":…} | chat {"agentId":…,"text":…} | team {"action":…} | post {"teamId":…,"text":…} | history {"action":…} | records {"agentId":…}';
|
|
21
|
+
const usage = '用法:/pbot status | init | agent {"action":…} | chat {"agentId":…,"text":…} | team {"action":…} | messages {"teamId":…} | post {"teamId":…,"text":…} | history {"action":…} | records {"agentId":…}';
|
|
23
22
|
|
|
24
23
|
export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, management: PbotManagement) {
|
|
25
24
|
ctx.commands.register({ name: "pbot", description: "Personal Bot 工作区与协作管理", recordInput: false,
|
|
26
|
-
input: { hint: "status | init | agent/chat/team/post/history/records JSON", attachments: true },
|
|
25
|
+
input: { hint: "status | init | agent/chat/team/messages/post/history/records JSON", attachments: true },
|
|
27
26
|
async handler({ agent, rawInput, signal, attachments, commandId }) {
|
|
28
27
|
signal.throwIfAborted();
|
|
29
28
|
const command = rawInput.trim(), split = command.search(/\s/);
|
|
@@ -48,12 +47,10 @@ export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, mana
|
|
|
48
47
|
let result: unknown;
|
|
49
48
|
switch (verb) {
|
|
50
49
|
case "agent": {
|
|
51
|
-
requireThat(validAgent(input), "dsh 专家参数无效或包含不支持的宿主选项。");
|
|
52
50
|
const selection = agent.model.current();
|
|
53
|
-
const output = await executeAgent(workspace.agents, input
|
|
51
|
+
const output = await executeAgent(workspace.agents, agentInput(input), workspace.owner, selection ? {
|
|
54
52
|
provider: selection.provider, model: selection.model,
|
|
55
|
-
...(selection.reasoningEffort
|
|
56
|
-
? { thinking: selection.reasoningEffort } : {}),
|
|
53
|
+
...(selection.reasoningEffort ? { thinking: selection.reasoningEffort } : {}),
|
|
57
54
|
} : {});
|
|
58
55
|
result = output.structuredContent; break;
|
|
59
56
|
}
|
|
@@ -68,16 +65,14 @@ export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, mana
|
|
|
68
65
|
workspace.agents.answerPermission(args.agentId, args.requestId, args.optionId, workspace.owner);
|
|
69
66
|
result = { answered: true }; break;
|
|
70
67
|
}
|
|
71
|
-
case "team":
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
result = executeTeamMessage(workspace.teams, args as Static<typeof teamMessageParametersSchema>,
|
|
68
|
+
case "team":
|
|
69
|
+
result = executeTeam(workspace.teams, workspace.agents, teamInput(input), workspace.owner).structuredContent; break;
|
|
70
|
+
case "messages":
|
|
71
|
+
result = executeTeamMessage(workspace.teams, teamMessageInput({ ...input, action: "read" }),
|
|
72
|
+
{ kind: "coordinator", owner: workspace.owner }, commandId).structuredContent; break;
|
|
73
|
+
case "post":
|
|
74
|
+
result = executeTeamMessage(workspace.teams, teamMessageInput({ ...input, action: "post" }),
|
|
79
75
|
{ kind: "user", owner: workspace.owner }, commandId).structuredContent; break;
|
|
80
|
-
}
|
|
81
76
|
case "history": result = await management.history({ parentSessionId: agent.id, input: json(input) }, signal); break;
|
|
82
77
|
case "records": result = await management.expert({ parentSessionId: agent.id, input: json(input) }, signal); break;
|
|
83
78
|
default: throw new Error(usage);
|
|
@@ -44,7 +44,6 @@ export class DshWorkspace {
|
|
|
44
44
|
this.owner = { sessionId: agent.id, leaf: null, branch: [] };
|
|
45
45
|
this.host = new DshAgents(ctx, agent, {
|
|
46
46
|
setup: (d, _directory, generation) => async (agentCtx, child) => {
|
|
47
|
-
for (const key of ["noExtensions", "noPromptTemplates", "noContextFiles"] as const) requireThat(d.options[key] === undefined, "dsh 不支持宿主选项:" + key);
|
|
48
47
|
await agentCtx.plugin({ name: "pbot-expert", inject: dshDependencies, apply: async scope => {
|
|
49
48
|
const runtime = new DshAgentRuntime(scope, child, d, generation, this.agents.files, this.teams,
|
|
50
49
|
{ check: this.check, release: () => this.host.release(d.agentId, generation) });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import type { Agent, AgentHandle, AgentSetup } from "@deepseek-ai/dsh-agent";
|
|
3
3
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
4
|
-
import type { AgentDescriptor,
|
|
4
|
+
import type { AgentDescriptor, AgentSessionReference } from "../../model/agent.js";
|
|
5
5
|
import type { AgentHost } from "../../services/agents/agent-service.js";
|
|
6
6
|
import { requireThat } from "../../common/validation.js";
|
|
7
7
|
import { openDshAgent, readDshAgentSession, readDshReport } from "./session.js";
|
|
@@ -25,9 +25,6 @@ export class DshAgents implements AgentHost {
|
|
|
25
25
|
ready(agent: Agent, generation: string): void;
|
|
26
26
|
stopping(agent: Agent, generation: string): Promise<void>;
|
|
27
27
|
}, readonly lifetime: AbortSignal) {}
|
|
28
|
-
validateOptions(options: AgentOptions) {
|
|
29
|
-
for (const key of ["noExtensions", "noPromptTemplates", "noContextFiles"] as const) requireThat(options[key] === undefined, "dsh 不支持宿主选项:" + key);
|
|
30
|
-
}
|
|
31
28
|
available() {
|
|
32
29
|
this.lifetime.throwIfAborted();
|
|
33
30
|
requireThat(!this.#closed && this.ctx.agents.get(this.parent.id) === this.parent, "dsh 父会话或执行组件已关闭。");
|
package/src/model/agent.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AcpBackend, AcpModelSelection, AcpSessionReference } from "./acp.j
|
|
|
2
2
|
|
|
3
3
|
export interface AgentStartOptions extends AgentOptions { backend?: AcpBackend }
|
|
4
4
|
export interface AgentOptions {
|
|
5
|
-
name?: string; message?: string; files?: string[];
|
|
5
|
+
name?: string; message?: string; files?: string[];
|
|
6
6
|
provider?: string; model?: string; thinking?: string; cwd?: string; tools?: string[];
|
|
7
7
|
noExtensions?: boolean; noSkills?: boolean; noPromptTemplates?: boolean; noContextFiles?: boolean;
|
|
8
8
|
}
|
|
@@ -8,7 +8,7 @@ export function teamNotice(values: ReturnType<TeamService["notifications"]>, kno
|
|
|
8
8
|
const notes = values.filter(value => !known.has(value.key)).slice(0, 8);
|
|
9
9
|
if (!notes.length) return;
|
|
10
10
|
return { kind: "teams" as const, keys: notes.map(value => value.key), content: ["# 团队批次状态", "",
|
|
11
|
-
"团队批次状态已变化,用 pbot_team status
|
|
11
|
+
"团队批次状态已变化,用 pbot_team status 与 pbot_team_message read 查看状态和结果。暂停时可能仍有在途工作,重跑前先查看原请求结果。", "",
|
|
12
12
|
notes.map(value => ["## " + value.name, "", "- `teamId`: `" + value.teamId + "`", "- `runId`: `" + value.runId + "`",
|
|
13
13
|
"- 状态:" + value.state, "- 在途工作:" + value.activeCount, ...(value.reason ? ["", "### 原因", "", value.reason] : [])].join("\n")).join("\n\n")].join("\n") };
|
|
14
14
|
}
|
|
@@ -9,6 +9,7 @@ import type { TeamAgent, TeamInput } from "../../model/team.js";
|
|
|
9
9
|
import type { AgentOwner, AgentOptions, AgentStartOptions, AgentDescriptor, AgentCycle, AgentCompletion, AgentSessionReference, NativeAgentHost } from "../../model/agent.js";
|
|
10
10
|
import type { AcpBackend, AcpSessionReference } from "../../model/acp.js";
|
|
11
11
|
import { acpModelState, acpPermission, acpPermissionReply, acpReference } from "../../storage/acp-files.js";
|
|
12
|
+
import { applicableStartOptions } from "./start-options.js";
|
|
12
13
|
|
|
13
14
|
export interface AgentHost {
|
|
14
15
|
readonly kind: NativeAgentHost;
|
|
@@ -72,7 +73,8 @@ export class AgentService {
|
|
|
72
73
|
this.check();
|
|
73
74
|
const { backend, ...supplied } = input;
|
|
74
75
|
this.host.available(backend);
|
|
75
|
-
const options: AgentOptions =
|
|
76
|
+
const options: AgentOptions = applicableStartOptions(this.host.kind, backend,
|
|
77
|
+
Object.fromEntries(Object.entries(supplied).filter(([, v]) => v !== undefined)));
|
|
76
78
|
this.host.validateOptions?.(options, backend);
|
|
77
79
|
requireThat(backend || options.provider && options.model, "请选择可在专家会话使用的模型。");
|
|
78
80
|
const reference = backend ? this.host.prepare?.(backend, options) : undefined;
|
|
@@ -86,7 +88,7 @@ export class AgentService {
|
|
|
86
88
|
parentSessionId: owner.sessionId, parentLeaf: owner.leaf, createdAt: Date.now(), options: { ...options, files, cwd } };
|
|
87
89
|
const run = { generation: randomUUID(), name: options.name ?? agentId.slice(0, 8), sequence: 0, stop: false, startedAt: Date.now() };
|
|
88
90
|
this.files.create(d, run, reference);
|
|
89
|
-
const initial =
|
|
91
|
+
const initial = options.message ?? "";
|
|
90
92
|
const request = initial || files.length ? this.files.enqueue(agentId, initial, "steer", files) : undefined;
|
|
91
93
|
this.#starting.set(agentId, { generation: run.generation, controller: new AbortController(), stage: "launch" });
|
|
92
94
|
return { d, run, request };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AcpBackend } from "../../model/acp.js";
|
|
2
|
+
import type { AgentOptions, NativeAgentHost } from "../../model/agent.js";
|
|
3
|
+
|
|
4
|
+
const piOnly = ["noExtensions", "noPromptTemplates", "noContextFiles"] as const;
|
|
5
|
+
|
|
6
|
+
/** Keep only options the effective target can use; declared-but-inapplicable fields are inert. */
|
|
7
|
+
export function applicableStartOptions(kind: NativeAgentHost, backend: AcpBackend | undefined, options: AgentOptions): AgentOptions {
|
|
8
|
+
const result = { ...options };
|
|
9
|
+
if (backend) {
|
|
10
|
+
if (backend !== "pi") {
|
|
11
|
+
for (const key of piOnly) delete result[key];
|
|
12
|
+
delete result.noSkills; delete result.tools;
|
|
13
|
+
}
|
|
14
|
+
if (backend === "claude") delete result.provider;
|
|
15
|
+
} else if (kind !== "pi") {
|
|
16
|
+
for (const key of piOnly) delete result[key];
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Static } from "typebox";
|
|
2
2
|
import type { AgentService } from "../../services/agents/agent-service.js";
|
|
3
|
-
import type { AgentOptions,
|
|
3
|
+
import type { AgentOptions, AgentOwner, AgentView } from "../../model/agent.js";
|
|
4
4
|
import { markdownResult } from "../result.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { AgentInput, agentViewSchema } from "./contract.js";
|
|
6
6
|
|
|
7
|
-
export type AgentInput = Omit<Static<typeof agentParametersSchema>, "thinking"> & { thinking?: string };
|
|
8
7
|
type AgentOutput = Static<typeof agentViewSchema>;
|
|
9
8
|
function agentOutput(view: AgentView & Partial<AgentOutput>): AgentOutput {
|
|
10
9
|
const c = view.cycle;
|
|
@@ -25,22 +24,31 @@ function agentOutput(view: AgentView & Partial<AgentOutput>): AgentOutput {
|
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
26
|
|
|
27
|
+
/** Parent selection is inherited only for a native expert; a chosen model drops the thinking default. */
|
|
28
|
+
function inherited(input: AgentInput, defaults: AgentOptions) {
|
|
29
|
+
if (input.action !== "start" || input.backend) return {};
|
|
30
|
+
const changed = Boolean(input.provider && defaults.provider && input.provider !== defaults.provider) ||
|
|
31
|
+
Boolean(input.model && defaults.model && input.model !== defaults.model);
|
|
32
|
+
const options = { ...defaults };
|
|
33
|
+
if (changed) delete options.thinking;
|
|
34
|
+
return options;
|
|
35
|
+
}
|
|
28
36
|
|
|
29
37
|
export async function executeAgent(service: AgentService, input: AgentInput, owner: AgentOwner, defaults: AgentOptions = {}) {
|
|
30
38
|
let value: AgentView & Partial<AgentOutput>;
|
|
31
39
|
switch (input.action) {
|
|
32
40
|
case "start": {
|
|
33
41
|
const { action: _action, ...supplied } = input;
|
|
34
|
-
value = await service.start({ ...(
|
|
42
|
+
value = await service.start({ ...inherited(input, defaults), ...supplied }, owner); break;
|
|
35
43
|
}
|
|
36
44
|
case "list": return markdownResult({ agents: service.list(owner).map(agentOutput) }, "子会话列表");
|
|
37
|
-
case "send": value = service.send(input.agentId
|
|
38
|
-
case "rename": value = service.rename(input.agentId
|
|
39
|
-
case "resume": value = await service.resume(input.agentId
|
|
40
|
-
case "stop": value = service.stop(input.agentId
|
|
41
|
-
case "status": value = service.status(input.agentId
|
|
45
|
+
case "send": value = service.send(input.agentId, input.message, input.delivery ?? "steer", owner); break;
|
|
46
|
+
case "rename": value = service.rename(input.agentId, input.name, owner); break;
|
|
47
|
+
case "resume": value = await service.resume(input.agentId, input.message, owner); break;
|
|
48
|
+
case "stop": value = service.stop(input.agentId, owner); break;
|
|
49
|
+
case "status": value = service.status(input.agentId, owner); break;
|
|
42
50
|
case "read": {
|
|
43
|
-
const page = await service.read(input.agentId
|
|
51
|
+
const page = await service.read(input.agentId, owner, input.cycleId, input.offset, input.limit);
|
|
44
52
|
const data = agentOutput(page), output = markdownResult(data, "子会话报告");
|
|
45
53
|
return { ...output, details: { ...data, ...(page.cycle && page.cycle.state !== "running" ? { agentReadKeys: [page.agentId + ":" + page.cycle.cycleId] } : {}) } };
|
|
46
54
|
}
|
|
@@ -1,46 +1,81 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
+
import type { AgentStartOptions } from "../../model/agent.js";
|
|
3
|
+
import { requireThat } from "../../common/validation.js";
|
|
4
|
+
import { schema } from "../../common/schema.js";
|
|
5
|
+
import { inputObject, need, nullable, pick } from "../input.js";
|
|
2
6
|
|
|
3
|
-
export const agentDescription = "委派专家并继续对话。start 启动后即返回,完成自动通知,无需轮询;省略初始输入时待命。send 继续对话,团队占用期间不可私人 send。status 查看状态,read 读取报告;读取已结束周期即领取其通知,包括部分读取。续读固定 cycle.cycleId 并使用 nextOffset。state 表示执行状态,cycle.state 表示工作结果,queued 只表示入队。stop 保留历史,resume 携新 message 继续。每个父会话最多 50
|
|
7
|
+
export const agentDescription = "委派专家并继续对话。start 启动后即返回,完成自动通知,无需轮询;省略初始输入时待命。send 继续对话,团队占用期间不可私人 send。status 查看状态,read 读取报告;读取已结束周期即领取其通知,包括部分读取。续读固定 cycle.cycleId 并使用 nextOffset。state 表示执行状态,cycle.state 表示工作结果,queued 只表示入队。stop 保留历史,resume 携新 message 继续。每个父会话最多 50 个存活专家,空闲也计入。动作只读取自己的字段;其他已声明字段忽略。";
|
|
4
8
|
|
|
5
9
|
const id = Type.String({ minLength: 1, maxLength: 128 });
|
|
6
10
|
const message = Type.String({ minLength: 1, maxLength: 24000, description: "本次目标、相关资料、约束和交付要求。" });
|
|
7
11
|
const name = Type.String({ minLength: 1, maxLength: 64, pattern: "^[^\\r\\n\\x00-\\x1f]+$" });
|
|
8
|
-
|
|
9
|
-
backend:
|
|
10
|
-
name:
|
|
11
|
-
files:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
const page = {
|
|
24
|
-
cycleId: Type.Optional(Type.String({ ...id, description: "仅 read:省略时读取最近周期;按 nextOffset 续读时须固定为上页返回的 cycle.cycleId,避免切换到新周期。" })),
|
|
25
|
-
offset: Type.Optional(Type.Integer({ minimum: 0, description: "仅 read:报告正文的 UTF-16 字符偏移,默认 0;续读使用上页 nextOffset。" })),
|
|
26
|
-
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 16000, description: "仅 read:最多返回的正文 UTF-16 字符数,默认 16000,不是消息数或 token 数。" })),
|
|
27
|
-
};
|
|
28
|
-
const delivery = Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("followUp")], { description: "send 默认 steer 补充当前工作;followUp 排到当前工作之后。capabilities.steer 为 false 的成员运行中使用 followUp。" }));
|
|
12
|
+
const startFields = {
|
|
13
|
+
backend: nullable(Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")], { description: "选择 ACP 子代理程序:pi、dsh 或 claude(Claude Code)。省略时使用当前宿主的原生专家;指定时使用目标程序自己的配置。" })),
|
|
14
|
+
name: nullable(name), message: nullable(message),
|
|
15
|
+
files: nullable(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32, description: "随初始消息读取的文件;相对路径基于原工作区根目录。" })),
|
|
16
|
+
provider: nullable(Type.String({ ...id, description: "模型提供方覆盖项;省略时继承主会话或使用 ACP 目标配置。指定时须同时指定 model。" })),
|
|
17
|
+
model: nullable(Type.String({ ...id, description: "模型 ID 覆盖项;省略时继承主会话或使用 ACP 目标配置。Pi/dsh 同名模型可用 provider 区分。" })),
|
|
18
|
+
thinking: nullable(Type.String({ minLength: 1, maxLength: 128, description: "思考等级覆盖项;省略时继承主会话或使用 ACP 目标配置。Pi 使用 off/minimal/low/medium/high/xhigh/max,其他程序使用其原生等级 ID。" })),
|
|
19
|
+
cwd: nullable(Type.String({ minLength: 1, description: "执行目录,相对原工作区根目录;省略时使用工作区根目录。" })),
|
|
20
|
+
tools: nullable(Type.Array(id, { minItems: 1, description: "Pi/dsh 子代理的工具名;省略时使用所选程序默认工具。Claude 子代理忽略此项并沿用原生配置。" })),
|
|
21
|
+
noExtensions: nullable(Type.Boolean({ description: "仅用于 Pi 子代理:关闭其他扩展的自动发现,默认 true。" })),
|
|
22
|
+
noSkills: nullable(Type.Boolean({ description: "Pi/dsh 子代理关闭技能发现,默认 false;Claude 子代理忽略此项并沿用原生配置。" })),
|
|
23
|
+
noPromptTemplates: nullable(Type.Boolean({ description: "仅用于 Pi 子代理:关闭提示模板发现,默认 false。" })),
|
|
24
|
+
noContextFiles: nullable(Type.Boolean({ description: "仅用于 Pi 子代理:关闭原生上下文文件加载,默认 false。" })),
|
|
25
|
+
} as const;
|
|
29
26
|
export const agentParametersSchema = Type.Object({
|
|
30
27
|
action: Type.Union([Type.Literal("start"), Type.Literal("send"), Type.Literal("rename"), Type.Literal("status"), Type.Literal("list"), Type.Literal("read"), Type.Literal("stop"), Type.Literal("resume")], {
|
|
31
|
-
description: "start
|
|
28
|
+
description: "start 创建专家;省略 message/files 即待命。send 必填 agentId/message,可选 delivery。resume 必填 agentId/message。stop/status 必填 agentId。rename 必填 agentId/name。read 必填 agentId,可选 cycleId/offset/limit。list 只需 action。动作只读取自己的字段;其他已声明字段忽略。",
|
|
32
29
|
}),
|
|
33
|
-
agentId:
|
|
30
|
+
agentId: nullable(id), ...startFields,
|
|
31
|
+
cycleId: nullable(Type.String({ ...id, description: "仅 read:省略时读取最近周期;按 nextOffset 续读时须固定为上页返回的 cycle.cycleId,避免切换到新周期。" })),
|
|
32
|
+
offset: nullable(Type.Integer({ minimum: 0, description: "仅 read:报告正文的 UTF-16 字符偏移,默认 0;续读使用上页 nextOffset。" })),
|
|
33
|
+
limit: nullable(Type.Integer({ minimum: 1, maximum: 16000, description: "仅 read:最多返回的正文 UTF-16 字符数,默认 16000,不是消息数或 token 数。" })),
|
|
34
|
+
delivery: nullable(Type.Union([Type.Literal("steer"), Type.Literal("followUp")], { description: "仅 send:默认 steer 补充当前工作;followUp 排到当前工作之后。capabilities.steer 为 false 的成员运行中使用 followUp。" })),
|
|
34
35
|
}, { additionalProperties: false });
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
|
|
37
|
+
export type AgentAction = "start" | "send" | "rename" | "status" | "list" | "read" | "stop" | "resume";
|
|
38
|
+
export type AgentInput =
|
|
39
|
+
| ({ action: "start" } & AgentStartOptions)
|
|
40
|
+
| { action: "send"; agentId: string; message: string; delivery?: "steer" | "followUp" }
|
|
41
|
+
| { action: "resume"; agentId: string; message: string }
|
|
42
|
+
| { action: "rename"; agentId: string; name: string }
|
|
43
|
+
| { action: "stop" | "status"; agentId: string }
|
|
44
|
+
| { action: "list" }
|
|
45
|
+
| { action: "read"; agentId: string; cycleId?: string; offset?: number; limit?: number };
|
|
46
|
+
|
|
47
|
+
const startKeys = Object.keys(startFields);
|
|
48
|
+
const valid = schema(agentParametersSchema);
|
|
49
|
+
|
|
50
|
+
/** One flat record, one interpreter. Fields outside the selected action are inert. */
|
|
51
|
+
export function agentInput(value: unknown): AgentInput {
|
|
52
|
+
const args = inputObject(value, valid, "专家参数格式无效");
|
|
53
|
+
const action = args.action as AgentAction;
|
|
54
|
+
switch (action) {
|
|
55
|
+
case "start":
|
|
56
|
+
requireThat(!args.provider || args.model !== undefined, "start 需要同时提供 provider 与 model。");
|
|
57
|
+
return { action, ...(pick(args, startKeys) as AgentStartOptions) };
|
|
58
|
+
case "send":
|
|
59
|
+
return { action, agentId: need("send", args, "agentId"), message: need("send", args, "message"),
|
|
60
|
+
...(args.delivery === undefined ? {} : { delivery: args.delivery as "steer" | "followUp" }) };
|
|
61
|
+
case "resume":
|
|
62
|
+
return { action, agentId: need("resume", args, "agentId"), message: need("resume", args, "message") };
|
|
63
|
+
case "rename":
|
|
64
|
+
return { action, agentId: need("rename", args, "agentId"), name: need("rename", args, "name") };
|
|
65
|
+
case "stop":
|
|
66
|
+
case "status":
|
|
67
|
+
return { action, agentId: need(action, args, "agentId") };
|
|
68
|
+
case "list":
|
|
69
|
+
return { action };
|
|
70
|
+
case "read":
|
|
71
|
+
return { action, agentId: need("read", args, "agentId"),
|
|
72
|
+
...(args.cycleId === undefined ? {} : { cycleId: args.cycleId as string }),
|
|
73
|
+
...(args.offset === undefined ? {} : { offset: args.offset as number }),
|
|
74
|
+
...(args.limit === undefined ? {} : { limit: args.limit as number }) };
|
|
75
|
+
default:
|
|
76
|
+
throw new Error("未知的专家 action。");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
44
79
|
|
|
45
80
|
const cycle = Type.Object({ cycleId: Type.String(), startedAt: Type.Number(), finishedAt: Type.Optional(Type.Number()),
|
|
46
81
|
state: Type.Union([Type.Literal("running"), Type.Literal("completed"), Type.Literal("failed"), Type.Literal("cancelled"), Type.Literal("interrupted")], { description: "本周期的工作结果,正文用 read 读取。" }),
|
|
@@ -7,15 +7,13 @@ import { object, json } from "../../common/json.js";
|
|
|
7
7
|
import { requireThat } from "../../common/validation.js";
|
|
8
8
|
import { schema } from "../../common/schema.js";
|
|
9
9
|
import { markdownFields } from "../../common/markdown.js";
|
|
10
|
-
import { executeAgent
|
|
11
|
-
import { agentDescription, agentResultSchema } from "./contract.js";
|
|
12
|
-
import { dshAgentActionSchema, dshAgentParametersSchema } from "./dsh-contract.js";
|
|
10
|
+
import { executeAgent } from "./actions.js";
|
|
11
|
+
import { agentDescription, agentInput, agentParametersSchema, agentResultSchema } from "./contract.js";
|
|
13
12
|
|
|
14
13
|
export function registerDshAgentTool(ctx: Context, agent: Agent, service: AgentService, owner: AgentOwner, check: () => void) {
|
|
15
|
-
const validators = new Map(dshAgentActionSchema.anyOf.map(row => [row.properties.action.const, schema(row)]));
|
|
16
14
|
const validOutput = schema(agentResultSchema);
|
|
17
15
|
ctx.tools.register({ name: "pbot_agent", description: agentDescription,
|
|
18
|
-
parameters: dshParameters(
|
|
16
|
+
parameters: dshParameters(agentParametersSchema),
|
|
19
17
|
output: {
|
|
20
18
|
schema: dshOutputSchema(agentResultSchema),
|
|
21
19
|
render: (_args, value) => [{ type: "text", text: "# 专家\n\n" + markdownFields(value) }],
|
|
@@ -26,14 +24,11 @@ export function registerDshAgentTool(ctx: Context, agent: Agent, service: AgentS
|
|
|
26
24
|
},
|
|
27
25
|
async execute(args, exec) {
|
|
28
26
|
check(); exec.signal.throwIfAborted();
|
|
29
|
-
requireThat(exec.agent === agent
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const selection = agent.model.current();
|
|
33
|
-
const output = await executeAgent(service, args as AgentInput, owner, selection ? {
|
|
27
|
+
requireThat(exec.agent === agent, "专家工具不属于当前会话。");
|
|
28
|
+
const input = agentInput(args), selection = agent.model.current();
|
|
29
|
+
const output = await executeAgent(service, input, owner, selection ? {
|
|
34
30
|
provider: selection.provider, model: selection.model,
|
|
35
|
-
...(selection.reasoningEffort
|
|
36
|
-
? { thinking: selection.reasoningEffort } : {}),
|
|
31
|
+
...(selection.reasoningEffort ? { thinking: selection.reasoningEffort } : {}),
|
|
37
32
|
} : {});
|
|
38
33
|
requireThat(validOutput(output.structuredContent), "专家输出不符合契约。");
|
|
39
34
|
return output.structuredContent;
|