personal-bot 0.1.1 → 0.2.0

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.
@@ -0,0 +1,58 @@
1
+ import type { Static } from "typebox";
2
+ import { defineTool, type ExtensionContext } from "@earendil-works/pi-coding-agent";
3
+ import type { TeamService } from "../../services/agents/team-service.js";
4
+ import type { AgentService } from "../../services/agents/agent-service.js";
5
+ import type { TeamActor } from "../../model/team.js";
6
+ import { agentOwner } from "../../integrations/pi/agent-context.js";
7
+ import { teamMessagesMarkdown } from "../../integrations/pi/team-context.js";
8
+ import { requireThat, schema } from "../../common/validation.js";
9
+ import type { CallAccess } from "../access.js";
10
+ import { markdownResult, result } from "../result.js";
11
+ import { teamParametersSchema, teamActionSchema, teamResultSchema, teamMessageParametersSchema, teamMessageActionSchema, teamMessageResultSchema } from "./contract.js";
12
+
13
+ export function teamTool(service: TeamService, agents: AgentService, access: Pick<CallAccess, "check">) {
14
+ const valid = schema(teamActionSchema);
15
+ return defineTool({ name: "pbot_team", label: "团队",
16
+ description: "主会话管理固定成员团队。create 不启动模型;run 在空闲成员间运行有限 roundRobin 轮流讨论或 parallel 并行轮次,默认 2 轮、15 分钟。成员直接取得公共原文。团队运行时占用成员;pause 不杀死在途工作,收尾后可私人 send。close 不停止 agent。恢复不重跑旧请求;继续须明确 run 新批次。完成仍需业务验收。",
17
+ parameters: teamParametersSchema, outputSchema: teamResultSchema,
18
+ async execute(_id, args, signal, _update, ctx) {
19
+ access.check(); signal?.throwIfAborted();
20
+ requireThat(valid(args), "团队参数不符合所选 action。");
21
+ const input = args as Static<typeof teamParametersSchema>, owner = agentOwner(ctx), views = agents.list(owner);
22
+ service.recover(owner);
23
+ let id = input.teamId!;
24
+ switch (input.action) {
25
+ case "create": id = service.create(owner, { name: input.name!, brief: input.brief!, members: input.members! }, views).teamId; break;
26
+ case "list": return markdownResult({ teams: service.list(owner, views) }, "团队列表");
27
+ case "read": {
28
+ const page = service.read(id, { kind: "coordinator", owner }, input);
29
+ return result(page, false, teamMessagesMarkdown(page));
30
+ }
31
+ case "run": service.run(id, owner, { instruction: input.instruction!, mode: input.mode!,
32
+ ...(input.rounds === undefined ? {} : { rounds: input.rounds }),
33
+ ...(input.maxConcurrent === undefined ? {} : { maxConcurrent: input.maxConcurrent }),
34
+ ...(input.timeoutSeconds === undefined ? {} : { timeoutSeconds: input.timeoutSeconds }) }, views); break;
35
+ case "pause": service.pause(id, owner); break;
36
+ case "close": service.close(id, owner, views); break;
37
+ }
38
+ return markdownResult(service.status(id, owner, views), "团队状态");
39
+ },
40
+ });
41
+ }
42
+ export function teamMessageTool(service: TeamService, access: Pick<CallAccess, "check">, actor: (ctx: ExtensionContext) => TeamActor) {
43
+ const valid = schema(teamMessageActionSchema);
44
+ return defineTool({ name: "pbot_team_message", label: "团队消息",
45
+ description: "直接读取/发布团队公共原文。post 不唤醒模型、不增加轮次,所有成员可见,不提供私信或递归委派。成员只能在自己的团队工作中 post。read 用 afterSeq 分页;长消息用 seq/offset/limit 继续,nextOffset 非空表示该条正文不完整。保存成功不是模型已读或业务完成。",
46
+ parameters: teamMessageParametersSchema, outputSchema: teamMessageResultSchema,
47
+ async execute(id, args, signal, _update, ctx) {
48
+ access.check(); signal?.throwIfAborted(); requireThat(valid(args), "团队消息参数无效。");
49
+ const input = args as Static<typeof teamMessageParametersSchema>, sender = actor(ctx);
50
+ if (input.action === "read") {
51
+ const page = service.read(input.teamId, sender, input);
52
+ return result(page, false, teamMessagesMarkdown(page));
53
+ }
54
+ const message = service.post(input.teamId, sender, id, input.text!, input.replyTo);
55
+ return markdownResult({ teamId: input.teamId, seq: message.seq, status: "stored" }, "团队消息已保存");
56
+ },
57
+ });
58
+ }