personal-bot 0.2.3 → 0.2.5

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.
Files changed (234) hide show
  1. package/CONTEXT.md +13 -7
  2. package/README.md +46 -9
  3. package/README.zh-CN.md +46 -9
  4. package/bin/pbot.mjs +3 -0
  5. package/docs/README.md +4 -1
  6. package/docs/agent-collaboration.md +26 -12
  7. package/docs/architecture-guidelines.md +2 -2
  8. package/docs/capability-design.md +6 -4
  9. package/docs/dsh-implementation-plan.md +158 -0
  10. package/docs/dsh-support-proposal.md +314 -0
  11. package/docs/dsh.md +103 -0
  12. package/docs/file-storage.md +14 -9
  13. package/docs/history.md +29 -18
  14. package/docs/installation-design.md +226 -0
  15. package/docs/interaction-design.md +13 -0
  16. package/docs/release.md +5 -5
  17. package/docs/technical-design.md +29 -15
  18. package/docs/validation.md +53 -3
  19. package/lib/client.js +1071 -0
  20. package/lib/common/files.d.ts +2 -0
  21. package/lib/common/files.js +44 -0
  22. package/lib/common/json.d.ts +6 -0
  23. package/lib/common/json.js +16 -0
  24. package/lib/common/markdown.d.ts +5 -0
  25. package/lib/common/markdown.js +26 -0
  26. package/lib/common/package-source.js +16 -0
  27. package/lib/common/paths.d.ts +1 -0
  28. package/lib/common/paths.js +2 -0
  29. package/lib/common/validation.d.ts +3 -0
  30. package/lib/common/validation.js +14 -0
  31. package/lib/common/version.d.ts +3 -0
  32. package/lib/common/version.js +13 -0
  33. package/lib/dsh.d.ts +4 -0
  34. package/lib/dsh.js +22 -0
  35. package/lib/extension/dsh/agent-events.d.ts +24 -0
  36. package/lib/extension/dsh/agent-events.js +242 -0
  37. package/lib/extension/dsh/agent-runtime.d.ts +49 -0
  38. package/lib/extension/dsh/agent-runtime.js +348 -0
  39. package/lib/extension/dsh/command.d.ts +4 -0
  40. package/lib/extension/dsh/command.js +83 -0
  41. package/lib/extension/dsh/files.d.ts +5 -0
  42. package/lib/extension/dsh/files.js +67 -0
  43. package/lib/extension/dsh/history.d.ts +15 -0
  44. package/lib/extension/dsh/history.js +88 -0
  45. package/lib/extension/dsh/management.d.ts +21 -0
  46. package/lib/extension/dsh/management.js +217 -0
  47. package/lib/extension/dsh/workspace.d.ts +48 -0
  48. package/lib/extension/dsh/workspace.js +290 -0
  49. package/lib/extension/setup-cli.js +136 -0
  50. package/lib/extension/setup-guard.js +11 -0
  51. package/lib/integrations/agent-resources.d.ts +1 -0
  52. package/lib/integrations/agent-resources.js +18 -0
  53. package/lib/integrations/dsh/dsh-agents.d.ts +30 -0
  54. package/lib/integrations/dsh/dsh-agents.js +104 -0
  55. package/lib/integrations/dsh/history-summary.d.ts +11 -0
  56. package/lib/integrations/dsh/history-summary.js +40 -0
  57. package/lib/integrations/dsh/history.d.ts +16 -0
  58. package/lib/integrations/dsh/history.js +156 -0
  59. package/lib/integrations/dsh/input.d.ts +21 -0
  60. package/lib/integrations/dsh/input.js +62 -0
  61. package/lib/integrations/dsh/messages.d.ts +36 -0
  62. package/lib/integrations/dsh/messages.js +11 -0
  63. package/lib/integrations/dsh/notifications.d.ts +8 -0
  64. package/lib/integrations/dsh/notifications.js +55 -0
  65. package/lib/integrations/dsh/resources.d.ts +10 -0
  66. package/lib/integrations/dsh/resources.js +41 -0
  67. package/lib/integrations/dsh/schema.d.ts +7 -0
  68. package/lib/integrations/dsh/schema.js +28 -0
  69. package/lib/integrations/dsh/session.d.ts +14 -0
  70. package/lib/integrations/dsh/session.js +59 -0
  71. package/lib/integrations/history-summary.d.ts +2 -0
  72. package/lib/integrations/history-summary.js +21 -0
  73. package/lib/integrations/installation/pi-bridge.js +131 -0
  74. package/lib/integrations/installation/pi-setup.js +193 -0
  75. package/lib/integrations/installation/processes.js +155 -0
  76. package/lib/integrations/installation/workspace.js +21 -0
  77. package/lib/integrations/process.d.ts +14 -0
  78. package/lib/integrations/process.js +48 -0
  79. package/lib/integrations/python-activation.d.ts +2 -0
  80. package/lib/integrations/python-activation.js +29 -0
  81. package/lib/integrations/team-context.d.ts +18 -0
  82. package/lib/integrations/team-context.js +57 -0
  83. package/lib/model/agent.d.ts +92 -0
  84. package/lib/model/agent.js +1 -0
  85. package/lib/model/history.d.ts +43 -0
  86. package/lib/model/history.js +1 -0
  87. package/lib/model/team.d.ts +85 -0
  88. package/lib/model/team.js +1 -0
  89. package/lib/services/agents/agent-notices.d.ts +13 -0
  90. package/lib/services/agents/agent-notices.js +25 -0
  91. package/lib/services/agents/agent-run.d.ts +39 -0
  92. package/lib/services/agents/agent-run.js +138 -0
  93. package/lib/services/agents/agent-service.d.ts +166 -0
  94. package/lib/services/agents/agent-service.js +325 -0
  95. package/lib/services/agents/team-service.d.ts +168 -0
  96. package/lib/services/agents/team-service.js +343 -0
  97. package/lib/services/history/history-service.d.ts +103 -0
  98. package/lib/services/history/history-service.js +269 -0
  99. package/lib/services/installation/setup-service.js +121 -0
  100. package/lib/services/workspace/python-environment-service.d.ts +15 -0
  101. package/lib/services/workspace/python-environment-service.js +50 -0
  102. package/lib/services/workspace/workspace-files.d.ts +2 -0
  103. package/lib/services/workspace/workspace-files.js +17 -0
  104. package/lib/services/workspace/workspace-preparation.d.ts +2 -0
  105. package/lib/services/workspace/workspace-preparation.js +18 -0
  106. package/lib/storage/agent-files.d.ts +30 -0
  107. package/lib/storage/agent-files.js +166 -0
  108. package/lib/storage/atomic-json.d.ts +11 -0
  109. package/lib/storage/atomic-json.js +101 -0
  110. package/lib/storage/file-access.d.ts +2 -0
  111. package/lib/storage/file-access.js +26 -0
  112. package/lib/storage/history-files.d.ts +10 -0
  113. package/lib/storage/history-files.js +63 -0
  114. package/lib/storage/team-files.d.ts +16 -0
  115. package/lib/storage/team-files.js +111 -0
  116. package/lib/tools/agents/actions.d.ts +52 -0
  117. package/lib/tools/agents/actions.js +49 -0
  118. package/lib/tools/agents/contract.d.ts +163 -0
  119. package/lib/tools/agents/contract.js +56 -0
  120. package/lib/tools/agents/dsh-contract.d.ts +52 -0
  121. package/lib/tools/agents/dsh-contract.js +15 -0
  122. package/lib/tools/agents/dsh-tool.d.ts +5 -0
  123. package/lib/tools/agents/dsh-tool.js +38 -0
  124. package/lib/tools/history/actions.d.ts +70 -0
  125. package/lib/tools/history/actions.js +7 -0
  126. package/lib/tools/history/contract.d.ts +81 -0
  127. package/lib/tools/history/contract.js +32 -0
  128. package/lib/tools/history/dsh-tool.d.ts +4 -0
  129. package/lib/tools/history/dsh-tool.js +22 -0
  130. package/lib/tools/result.d.ts +18 -0
  131. package/lib/tools/result.js +10 -0
  132. package/lib/tools/teams/actions.d.ts +24 -0
  133. package/lib/tools/teams/actions.js +38 -0
  134. package/lib/tools/teams/contract.d.ts +232 -0
  135. package/lib/tools/teams/contract.js +67 -0
  136. package/lib/tools/teams/dsh-tool.d.ts +8 -0
  137. package/lib/tools/teams/dsh-tool.js +49 -0
  138. package/lib/ui/dsh/attachments.d.ts +5 -0
  139. package/lib/ui/dsh/attachments.js +39 -0
  140. package/lib/ui/dsh/elements.d.ts +17 -0
  141. package/lib/ui/dsh/elements.js +79 -0
  142. package/lib/ui/dsh/index.d.ts +4 -0
  143. package/lib/ui/dsh/index.js +13 -0
  144. package/lib/ui/dsh/management.d.ts +4 -0
  145. package/lib/ui/dsh/management.js +711 -0
  146. package/lib/ui/dsh/remote.d.ts +15 -0
  147. package/lib/ui/dsh/remote.js +11 -0
  148. package/lib/ui/dsh/styles.d.ts +1 -0
  149. package/lib/ui/dsh/styles.js +132 -0
  150. package/lib/ui/presentation.d.ts +3 -0
  151. package/lib/ui/presentation.js +12 -0
  152. package/lib/ui/setup.js +52 -0
  153. package/npm-shrinkwrap.json +11118 -783
  154. package/package.json +113 -9
  155. package/python/README.md +6 -6
  156. package/resources/agents/coordinator.md +1 -1
  157. package/resources/dsh/cordis.patch.yml +3 -0
  158. package/resources/installer/plugins.json +16 -0
  159. package/resources/prompts/workspace.md +1 -1
  160. package/resources/references/compute.md +1 -1
  161. package/resources/references/task-conductor.md +6 -4
  162. package/resources/skills/provider-connections/SKILL.md +10 -0
  163. package/scripts/README.md +13 -1
  164. package/src/common/package-source.ts +16 -0
  165. package/src/dsh.ts +22 -0
  166. package/src/extension/agent-events.ts +51 -46
  167. package/src/extension/agents-command.ts +48 -34
  168. package/src/extension/command.ts +42 -23
  169. package/src/extension/dsh/agent-events.ts +148 -0
  170. package/src/extension/dsh/agent-runtime.ts +251 -0
  171. package/src/extension/dsh/command.ts +78 -0
  172. package/src/extension/dsh/files.ts +61 -0
  173. package/src/extension/dsh/history.ts +69 -0
  174. package/src/extension/dsh/management.ts +108 -0
  175. package/src/extension/dsh/workspace.ts +206 -0
  176. package/src/extension/events.ts +6 -4
  177. package/src/extension/history.ts +15 -12
  178. package/src/extension/setup-cli.ts +109 -0
  179. package/src/extension/setup-guard.ts +12 -0
  180. package/src/extension/subagent-entry.ts +34 -63
  181. package/src/extension/teams-command.ts +53 -46
  182. package/src/integrations/{pi/agent-resources.ts → agent-resources.ts} +2 -2
  183. package/src/integrations/dsh/dsh-agents.ts +97 -0
  184. package/src/integrations/dsh/history-summary.ts +43 -0
  185. package/src/integrations/dsh/history.ts +76 -0
  186. package/src/integrations/dsh/input.ts +66 -0
  187. package/src/integrations/dsh/messages.ts +22 -0
  188. package/src/integrations/dsh/notifications.ts +46 -0
  189. package/src/integrations/dsh/resources.ts +44 -0
  190. package/src/integrations/dsh/schema.ts +26 -0
  191. package/src/integrations/dsh/session.ts +67 -0
  192. package/src/integrations/history-summary.ts +20 -0
  193. package/src/integrations/installation/pi-bridge.ts +107 -0
  194. package/src/integrations/installation/pi-setup.ts +162 -0
  195. package/src/integrations/installation/processes.ts +124 -0
  196. package/src/integrations/installation/workspace.ts +18 -0
  197. package/src/integrations/pi/history.ts +4 -14
  198. package/src/integrations/pi/pi-agents.ts +17 -6
  199. package/src/integrations/pi/team-context.ts +6 -58
  200. package/src/integrations/team-context.ts +60 -0
  201. package/src/model/agent.ts +2 -0
  202. package/src/model/history.ts +3 -1
  203. package/src/pbot.ts +1 -1
  204. package/src/services/agents/agent-notices.ts +28 -0
  205. package/src/services/agents/agent-run.ts +114 -0
  206. package/src/services/agents/agent-service.ts +127 -64
  207. package/src/services/history/history-service.ts +120 -59
  208. package/src/services/installation/setup-service.ts +145 -0
  209. package/src/storage/agent-files.ts +17 -4
  210. package/src/storage/history-files.ts +30 -5
  211. package/src/tools/agents/actions.ts +47 -0
  212. package/src/tools/agents/contract.ts +8 -5
  213. package/src/tools/agents/dsh-contract.ts +16 -0
  214. package/src/tools/agents/dsh-tool.ts +41 -0
  215. package/src/tools/agents/tool.ts +7 -43
  216. package/src/tools/history/actions.ts +9 -0
  217. package/src/tools/history/contract.ts +34 -0
  218. package/src/tools/history/dsh-tool.ts +22 -0
  219. package/src/tools/history/tool.ts +7 -30
  220. package/src/tools/teams/actions.ts +38 -0
  221. package/src/tools/teams/contract.ts +7 -3
  222. package/src/tools/teams/dsh-tool.ts +55 -0
  223. package/src/tools/teams/tool.ts +6 -31
  224. package/src/ui/agent-display.ts +7 -4
  225. package/src/ui/dsh/attachments.ts +42 -0
  226. package/src/ui/dsh/elements.ts +50 -0
  227. package/src/ui/dsh/index.ts +18 -0
  228. package/src/ui/dsh/management.ts +412 -0
  229. package/src/ui/dsh/remote.ts +20 -0
  230. package/src/ui/dsh/styles.ts +132 -0
  231. package/src/ui/pi/menu.ts +37 -0
  232. package/src/ui/pi/reader.ts +46 -0
  233. package/src/ui/presentation.ts +12 -0
  234. package/src/ui/setup.ts +40 -0
@@ -0,0 +1,163 @@
1
+ import { Type } from "typebox";
2
+ export declare const agentDescription = "\u72EC\u7ACB\u4E13\u5BB6\u4F1A\u8BDD\uFF0C\u4E0D\u7EE7\u627F\u7236\u804A\u5929\u5386\u53F2\u3002start \u5B8C\u6210\u542F\u52A8\u540E\u8FD4\u56DE\uFF0C\u4E0D\u7B49\u5F85\u5DE5\u4F5C\u5B8C\u6210\uFF1B\u672A\u63D0\u4F9B message/prompts/files \u65F6\u53EA\u542F\u52A8\u5F85\u547D\u4F1A\u8BDD\uFF0C\u4E0D\u8C03\u7528\u6A21\u578B\u3002\u5B8C\u6210\u81EA\u52A8\u901A\u77E5\uFF0C\u65E0\u9700\u8F6E\u8BE2\u3002\u56E2\u961F\u5360\u7528\u671F\u95F4\u4E0D\u80FD\u79C1\u4EBA send\u3002send \u7EE7\u7EED\u5BF9\u8BDD\uFF0Crename \u6539\u540D\uFF0Cstatus/list \u67E5\u770B\u72B6\u6001\uFF0Cstatus \u8FD4\u56DE\u6700\u8FD1\u5468\u671F\u4E14\u4E0D\u8BFB\u53D6\u62A5\u544A\u6B63\u6587\u3002read \u975E\u963B\u585E\u8BFB\u53D6\u62A5\u544A\uFF1B\u8BFB\u53D6\u5DF2\u7ED3\u675F\u5468\u671F\u4F1A\u9886\u53D6\u8BE5\u5468\u671F\u7684\u5B8C\u6210\u901A\u77E5\uFF08\u5305\u62EC\u90E8\u5206\u8BFB\u53D6\uFF09\uFF0C\u540E\u7EED\u4E0D\u518D\u91CD\u590D\u901A\u77E5\u3002nextOffset \u975E\u7A7A\u65F6\u4EE5\u8FD4\u56DE\u7684 cycle.cycleId \u56FA\u5B9A\u5468\u671F\u7EED\u8BFB\u3002state \u662F\u6267\u884C\u72B6\u6001\uFF0Ccycle.state \u662F\u5DE5\u4F5C\u7ED3\u679C\uFF0Cqueued \u4EC5\u8868\u793A\u5165\u961F\u3002stop \u505C\u6B62\u5E76\u4FDD\u7559\u5386\u53F2\uFF0Cresume \u643A\u65B0 message \u6062\u590D\uFF0C\u4E0D\u91CD\u653E\u65E7\u5DE5\u4F5C\u3002\u72EC\u7ACB\u590D\u6838\u987B start \u65B0\u4E0A\u4E0B\u6587\u3002\u5B50\u4F1A\u8BDD\u4F7F\u7528\u539F\u751F CLI/MCP\uFF0C\u6309\u59D4\u6D3E\u8303\u56F4\u5DE5\u4F5C\uFF0C\u4E0D\u9012\u5F52\u59D4\u6D3E\u3002\u6BCF\u4E2A\u7236\u4F1A\u8BDD\u6700\u591A 50 \u4E2A\u5B58\u6D3B\u5B50\u4F1A\u8BDD\uFF0C\u7A7A\u95F2\u4E5F\u8BA1\u5165\u3002";
3
+ export declare const agentStartOptions: {
4
+ name: Type.TOptional<Type.TString>;
5
+ message: Type.TOptional<Type.TString>;
6
+ files: Type.TOptional<Type.TArray<Type.TString>>;
7
+ prompts: Type.TOptional<Type.TArray<Type.TString>>;
8
+ provider: Type.TOptional<Type.TString>;
9
+ model: Type.TOptional<Type.TString>;
10
+ thinking: Type.TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>>;
11
+ cwd: Type.TOptional<Type.TString>;
12
+ tools: Type.TOptional<Type.TArray<Type.TString>>;
13
+ noExtensions: Type.TOptional<Type.TBoolean>;
14
+ noSkills: Type.TOptional<Type.TBoolean>;
15
+ noPromptTemplates: Type.TOptional<Type.TBoolean>;
16
+ noContextFiles: Type.TOptional<Type.TBoolean>;
17
+ };
18
+ export declare const agentParametersSchema: Type.TObject<{
19
+ delivery: Type.TOptional<Type.TUnion<[Type.TLiteral<"steer">, Type.TLiteral<"followUp">]>>;
20
+ cycleId: Type.TOptional<Type.TString>;
21
+ offset: Type.TOptional<Type.TInteger>;
22
+ limit: Type.TOptional<Type.TInteger>;
23
+ name: Type.TOptional<Type.TString>;
24
+ message: Type.TOptional<Type.TString>;
25
+ files: Type.TOptional<Type.TArray<Type.TString>>;
26
+ prompts: Type.TOptional<Type.TArray<Type.TString>>;
27
+ provider: Type.TOptional<Type.TString>;
28
+ model: Type.TOptional<Type.TString>;
29
+ thinking: Type.TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>>;
30
+ cwd: Type.TOptional<Type.TString>;
31
+ tools: Type.TOptional<Type.TArray<Type.TString>>;
32
+ noExtensions: Type.TOptional<Type.TBoolean>;
33
+ noSkills: Type.TOptional<Type.TBoolean>;
34
+ noPromptTemplates: Type.TOptional<Type.TBoolean>;
35
+ noContextFiles: Type.TOptional<Type.TBoolean>;
36
+ action: Type.TUnion<[Type.TLiteral<"start">, Type.TLiteral<"send">, Type.TLiteral<"rename">, Type.TLiteral<"status">, Type.TLiteral<"list">, Type.TLiteral<"read">, Type.TLiteral<"stop">, Type.TLiteral<"resume">]>;
37
+ agentId: Type.TOptional<Type.TString>;
38
+ }>;
39
+ export declare const agentActionSchema: Type.TUnion<[Type.TObject<{
40
+ name: Type.TOptional<Type.TString>;
41
+ message: Type.TOptional<Type.TString>;
42
+ files: Type.TOptional<Type.TArray<Type.TString>>;
43
+ prompts: Type.TOptional<Type.TArray<Type.TString>>;
44
+ provider: Type.TOptional<Type.TString>;
45
+ model: Type.TOptional<Type.TString>;
46
+ thinking: Type.TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>>;
47
+ cwd: Type.TOptional<Type.TString>;
48
+ tools: Type.TOptional<Type.TArray<Type.TString>>;
49
+ noExtensions: Type.TOptional<Type.TBoolean>;
50
+ noSkills: Type.TOptional<Type.TBoolean>;
51
+ noPromptTemplates: Type.TOptional<Type.TBoolean>;
52
+ noContextFiles: Type.TOptional<Type.TBoolean>;
53
+ action: Type.TLiteral<"start">;
54
+ }>, Type.TObject<{
55
+ action: Type.TLiteral<"send">;
56
+ agentId: Type.TString;
57
+ message: Type.TString;
58
+ delivery: Type.TOptional<Type.TUnion<[Type.TLiteral<"steer">, Type.TLiteral<"followUp">]>>;
59
+ }>, Type.TObject<{
60
+ action: Type.TLiteral<"rename">;
61
+ agentId: Type.TString;
62
+ name: Type.TString;
63
+ }>, Type.TObject<{
64
+ action: Type.TLiteral<"resume">;
65
+ agentId: Type.TString;
66
+ message: Type.TString;
67
+ }>, Type.TObject<{
68
+ action: Type.TLiteral<"list">;
69
+ }>, ...Type.TObject<{
70
+ action: Type.TLiteral<string>;
71
+ agentId: Type.TString;
72
+ }>[], Type.TObject<{
73
+ cycleId: Type.TOptional<Type.TString>;
74
+ offset: Type.TOptional<Type.TInteger>;
75
+ limit: Type.TOptional<Type.TInteger>;
76
+ action: Type.TLiteral<"read">;
77
+ agentId: Type.TString;
78
+ }>]>;
79
+ export declare const agentViewSchema: Type.TObject<{
80
+ agentId: Type.TString;
81
+ name: Type.TString;
82
+ cwd: Type.TString;
83
+ createdAt: Type.TNumber;
84
+ owned: Type.TBoolean;
85
+ state: Type.TUnion<[Type.TLiteral<"starting">, Type.TLiteral<"busy">, Type.TLiteral<"idle">, Type.TLiteral<"stopping">, Type.TLiteral<"stopped">, Type.TLiteral<"error">]>;
86
+ activity: Type.TString;
87
+ cycle: Type.TOptional<Type.TObject<{
88
+ cycleId: Type.TString;
89
+ startedAt: Type.TNumber;
90
+ finishedAt: Type.TOptional<Type.TNumber>;
91
+ state: Type.TUnion<[Type.TLiteral<"running">, Type.TLiteral<"completed">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">, Type.TLiteral<"interrupted">]>;
92
+ requestIds: Type.TArray<Type.TString>;
93
+ source: Type.TUnion<[Type.TLiteral<"parent">, Type.TLiteral<"interactive">, Type.TLiteral<"mixed">]>;
94
+ error: Type.TOptional<Type.TString>;
95
+ }>>;
96
+ error: Type.TOptional<Type.TString>;
97
+ requestId: Type.TOptional<Type.TString>;
98
+ messageStatus: Type.TOptional<Type.TLiteral<"queued">>;
99
+ cycles: Type.TOptional<Type.TArray<Type.TObject<{
100
+ cycleId: Type.TString;
101
+ state: Type.TString;
102
+ }>>>;
103
+ report: Type.TOptional<Type.TString>;
104
+ totalLength: Type.TOptional<Type.TInteger>;
105
+ nextOffset: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
106
+ }>;
107
+ export declare const agentResultSchema: Type.TUnion<[Type.TObject<{
108
+ agentId: Type.TString;
109
+ name: Type.TString;
110
+ cwd: Type.TString;
111
+ createdAt: Type.TNumber;
112
+ owned: Type.TBoolean;
113
+ state: Type.TUnion<[Type.TLiteral<"starting">, Type.TLiteral<"busy">, Type.TLiteral<"idle">, Type.TLiteral<"stopping">, Type.TLiteral<"stopped">, Type.TLiteral<"error">]>;
114
+ activity: Type.TString;
115
+ cycle: Type.TOptional<Type.TObject<{
116
+ cycleId: Type.TString;
117
+ startedAt: Type.TNumber;
118
+ finishedAt: Type.TOptional<Type.TNumber>;
119
+ state: Type.TUnion<[Type.TLiteral<"running">, Type.TLiteral<"completed">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">, Type.TLiteral<"interrupted">]>;
120
+ requestIds: Type.TArray<Type.TString>;
121
+ source: Type.TUnion<[Type.TLiteral<"parent">, Type.TLiteral<"interactive">, Type.TLiteral<"mixed">]>;
122
+ error: Type.TOptional<Type.TString>;
123
+ }>>;
124
+ error: Type.TOptional<Type.TString>;
125
+ requestId: Type.TOptional<Type.TString>;
126
+ messageStatus: Type.TOptional<Type.TLiteral<"queued">>;
127
+ cycles: Type.TOptional<Type.TArray<Type.TObject<{
128
+ cycleId: Type.TString;
129
+ state: Type.TString;
130
+ }>>>;
131
+ report: Type.TOptional<Type.TString>;
132
+ totalLength: Type.TOptional<Type.TInteger>;
133
+ nextOffset: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
134
+ }>, Type.TObject<{
135
+ agents: Type.TArray<Type.TObject<{
136
+ agentId: Type.TString;
137
+ name: Type.TString;
138
+ cwd: Type.TString;
139
+ createdAt: Type.TNumber;
140
+ owned: Type.TBoolean;
141
+ state: Type.TUnion<[Type.TLiteral<"starting">, Type.TLiteral<"busy">, Type.TLiteral<"idle">, Type.TLiteral<"stopping">, Type.TLiteral<"stopped">, Type.TLiteral<"error">]>;
142
+ activity: Type.TString;
143
+ cycle: Type.TOptional<Type.TObject<{
144
+ cycleId: Type.TString;
145
+ startedAt: Type.TNumber;
146
+ finishedAt: Type.TOptional<Type.TNumber>;
147
+ state: Type.TUnion<[Type.TLiteral<"running">, Type.TLiteral<"completed">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">, Type.TLiteral<"interrupted">]>;
148
+ requestIds: Type.TArray<Type.TString>;
149
+ source: Type.TUnion<[Type.TLiteral<"parent">, Type.TLiteral<"interactive">, Type.TLiteral<"mixed">]>;
150
+ error: Type.TOptional<Type.TString>;
151
+ }>>;
152
+ error: Type.TOptional<Type.TString>;
153
+ requestId: Type.TOptional<Type.TString>;
154
+ messageStatus: Type.TOptional<Type.TLiteral<"queued">>;
155
+ cycles: Type.TOptional<Type.TArray<Type.TObject<{
156
+ cycleId: Type.TString;
157
+ state: Type.TString;
158
+ }>>>;
159
+ report: Type.TOptional<Type.TString>;
160
+ totalLength: Type.TOptional<Type.TInteger>;
161
+ nextOffset: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
162
+ }>>;
163
+ }>]>;
@@ -0,0 +1,56 @@
1
+ import { Type } from "typebox";
2
+ export const agentDescription = "独立专家会话,不继承父聊天历史。start 完成启动后返回,不等待工作完成;未提供 message/prompts/files 时只启动待命会话,不调用模型。完成自动通知,无需轮询。团队占用期间不能私人 send。send 继续对话,rename 改名,status/list 查看状态,status 返回最近周期且不读取报告正文。read 非阻塞读取报告;读取已结束周期会领取该周期的完成通知(包括部分读取),后续不再重复通知。nextOffset 非空时以返回的 cycle.cycleId 固定周期续读。state 是执行状态,cycle.state 是工作结果,queued 仅表示入队。stop 停止并保留历史,resume 携新 message 恢复,不重放旧工作。独立复核须 start 新上下文。子会话使用原生 CLI/MCP,按委派范围工作,不递归委派。每个父会话最多 50 个存活子会话,空闲也计入。";
3
+ const id = Type.String({ minLength: 1, maxLength: 128 });
4
+ const message = Type.String({ minLength: 1, maxLength: 24000, description: "本次目标、交付要求、资料依据与约束。" });
5
+ const name = Type.String({ minLength: 1, maxLength: 64, pattern: "^[^\\r\\n\\x00-\\x1f]+$" });
6
+ export const agentStartOptions = {
7
+ name: Type.Optional(name), message: Type.Optional(message),
8
+ files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32, description: "随初始消息读取的文件;相对路径基于原工作区根目录。" })),
9
+ prompts: Type.Optional(Type.Array(message, { maxItems: 32, description: "与 message 按顺序合并为同一初始消息,不是多个执行轮次。" })),
10
+ provider: Type.Optional(Type.String({ ...id, description: "Pi 模型提供方,默认继承主会话。" })),
11
+ model: Type.Optional(Type.String({ ...id, description: "子进程可用的 Pi 模型 ID,默认继承主会话。" })),
12
+ thinking: Type.Optional(Type.Union([Type.Literal("off"), Type.Literal("minimal"), Type.Literal("low"), Type.Literal("medium"), Type.Literal("high"), Type.Literal("xhigh"), Type.Literal("max")], { description: "默认继承主会话思考级别。" })),
13
+ cwd: Type.Optional(Type.String({ minLength: 1, description: "执行目录,相对原工作区根目录;省略时使用工作区根目录。" })),
14
+ tools: Type.Optional(Type.Array(id, { minItems: 1, description: "按 Pi 原生规则选择工具,省略时沿用原生默认工具;MCP 工具遵循原生暴露设置。不提供递归委派;这不是宿主隔离。" })),
15
+ noExtensions: Type.Optional(Type.Boolean({ description: "默认 true,不发现其他扩展。" })),
16
+ noSkills: Type.Optional(Type.Boolean({ description: "关闭技能发现,默认 false。" })),
17
+ noPromptTemplates: Type.Optional(Type.Boolean({ description: "关闭提示模板发现,默认 false。" })),
18
+ noContextFiles: Type.Optional(Type.Boolean({ description: "关闭 Pi 原生上下文文件加载,默认 false。" })),
19
+ };
20
+ const page = {
21
+ cycleId: Type.Optional(Type.String({ ...id, description: "仅 read:省略时读取最近周期;按 nextOffset 续读时须固定为上页返回的 cycle.cycleId,避免切换到新周期。" })),
22
+ offset: Type.Optional(Type.Integer({ minimum: 0, description: "仅 read:报告正文的 UTF-16 字符偏移,默认 0;续读使用上页 nextOffset。" })),
23
+ limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 16000, description: "仅 read:最多返回的正文 UTF-16 字符数,默认 16000,不是消息数或 token 数。" })),
24
+ };
25
+ const delivery = Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("followUp")], { description: "send 默认 steer 补充当前工作;followUp 排到当前工作之后。" }));
26
+ export const agentParametersSchema = Type.Object({
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")], {
28
+ description: "start 仅接受启动选项,可省略 message/prompts/files 创建待命会话,禁止 agentId/delivery/分页字段;list 只接受 action;status/stop 只接受并必填 agentId;send 必填 agentId/message,仅可选 delivery;resume 必填 agentId/message;rename 必填 agentId/name;read 必填 agentId,仅可选 cycleId/offset/limit。禁止携带其他 action 的字段。",
29
+ }),
30
+ agentId: Type.Optional(id), ...agentStartOptions, ...page, delivery,
31
+ }, { additionalProperties: false });
32
+ export const agentActionSchema = Type.Union([
33
+ Type.Object({ action: Type.Literal("start"), ...agentStartOptions }, { additionalProperties: false }),
34
+ Type.Object({ action: Type.Literal("send"), agentId: id, message, delivery }, { additionalProperties: false }),
35
+ Type.Object({ action: Type.Literal("rename"), agentId: id, name }, { additionalProperties: false }),
36
+ Type.Object({ action: Type.Literal("resume"), agentId: id, message }, { additionalProperties: false }),
37
+ Type.Object({ action: Type.Literal("list") }, { additionalProperties: false }),
38
+ ...["stop", "status"].map(action => Type.Object({ action: Type.Literal(action), agentId: id }, { additionalProperties: false })),
39
+ Type.Object({ action: Type.Literal("read"), agentId: id, ...page }, { additionalProperties: false }),
40
+ ]);
41
+ const cycle = Type.Object({ cycleId: Type.String(), startedAt: Type.Number(), finishedAt: Type.Optional(Type.Number()),
42
+ state: Type.Union([Type.Literal("running"), Type.Literal("completed"), Type.Literal("failed"), Type.Literal("cancelled"), Type.Literal("interrupted")], { description: "本周期的工作结果;completed 仍须核验实际交付。" }),
43
+ requestIds: Type.Array(Type.String()),
44
+ source: Type.Union([Type.Literal("parent"), Type.Literal("interactive"), Type.Literal("mixed")]), error: Type.Optional(Type.String()),
45
+ }, { additionalProperties: false });
46
+ export const agentViewSchema = Type.Object({ agentId: Type.String(), name: Type.String(), cwd: Type.String(), createdAt: Type.Number(),
47
+ owned: Type.Boolean({ description: "是否属于当前父会话分支;false 时须回到所属分支操作。" }),
48
+ state: Type.Union([Type.Literal("starting"), Type.Literal("busy"), Type.Literal("idle"), Type.Literal("stopping"), Type.Literal("stopped"), Type.Literal("error")], { description: "执行状态;idle 不代表上轮工作成功,结果见 cycle.state。" }),
49
+ activity: Type.String(), cycle: Type.Optional(cycle), error: Type.Optional(Type.String()),
50
+ requestId: Type.Optional(Type.String()), messageStatus: Type.Optional(Type.Literal("queued", { description: "消息已入队,不代表模型已阅读或完成。" })),
51
+ cycles: Type.Optional(Type.Array(Type.Object({ cycleId: Type.String(), state: Type.String() }), { description: "仅 read 返回:可读取的周期索引。" })),
52
+ report: Type.Optional(Type.String({ description: "仅 read 返回:选定周期的报告正文片段。已结束周期的读取结果持久化后领取该周期通知,即使本页未读完。" })),
53
+ totalLength: Type.Optional(Type.Integer({ description: "仅 read 返回:完整报告的 UTF-16 字符数。" })),
54
+ nextOffset: Type.Optional(Type.Union([Type.Integer(), Type.Null()], { description: "仅 read 返回:null 表示本报告已读完;否则以相同 agentId、cycle.cycleId 和此 offset 继续。" })),
55
+ }, { additionalProperties: false });
56
+ export const agentResultSchema = Type.Union([agentViewSchema, Type.Object({ agents: Type.Array(agentViewSchema) }, { additionalProperties: false })]);
@@ -0,0 +1,52 @@
1
+ import { Type } from "typebox";
2
+ export declare const dshAgentParametersSchema: Type.TObject<{
3
+ provider: Type.TOptional<Type.TString>;
4
+ model: Type.TOptional<Type.TString>;
5
+ thinking: Type.TOptional<Type.TString>;
6
+ files: Type.TOptional<Type.TArray<Type.TString>>;
7
+ tools: Type.TOptional<Type.TArray<Type.TString>>;
8
+ noSkills: Type.TOptional<Type.TBoolean>;
9
+ agentId: Type.TOptional<Type.TString>;
10
+ cwd: Type.TOptional<Type.TString>;
11
+ name: Type.TOptional<Type.TString>;
12
+ message: Type.TOptional<Type.TString>;
13
+ delivery: Type.TOptional<Type.TUnion<[Type.TLiteral<"steer">, Type.TLiteral<"followUp">]>>;
14
+ cycleId: Type.TOptional<Type.TString>;
15
+ prompts: Type.TOptional<Type.TArray<Type.TString>>;
16
+ action: Type.TUnion<[Type.TLiteral<"start">, Type.TLiteral<"send">, Type.TLiteral<"rename">, Type.TLiteral<"status">, Type.TLiteral<"list">, Type.TLiteral<"read">, Type.TLiteral<"stop">, Type.TLiteral<"resume">]>;
17
+ offset: Type.TOptional<Type.TInteger>;
18
+ limit: Type.TOptional<Type.TInteger>;
19
+ }>;
20
+ export declare const dshAgentActionSchema: Type.TUnion<(Type.TObject<{
21
+ name: Type.TOptional<Type.TString>;
22
+ message: Type.TOptional<Type.TString>;
23
+ files: Type.TOptional<Type.TArray<Type.TString>>;
24
+ prompts: Type.TOptional<Type.TArray<Type.TString>>;
25
+ provider: Type.TOptional<Type.TString>;
26
+ model: Type.TOptional<Type.TString>;
27
+ thinking: Type.TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>>;
28
+ cwd: Type.TOptional<Type.TString>;
29
+ tools: Type.TOptional<Type.TArray<Type.TString>>;
30
+ noExtensions: Type.TOptional<Type.TBoolean>;
31
+ noSkills: Type.TOptional<Type.TBoolean>;
32
+ noPromptTemplates: Type.TOptional<Type.TBoolean>;
33
+ noContextFiles: Type.TOptional<Type.TBoolean>;
34
+ action: Type.TLiteral<"start">;
35
+ }> | Type.TObject<{
36
+ action: Type.TLiteral<"list">;
37
+ }> | Type.TObject<{
38
+ action: Type.TLiteral<string>;
39
+ agentId: Type.TString;
40
+ }> | Type.TObject<{
41
+ provider: Type.TOptional<Type.TString>;
42
+ model: Type.TOptional<Type.TString>;
43
+ thinking: Type.TOptional<Type.TString>;
44
+ files: Type.TOptional<Type.TArray<Type.TString>>;
45
+ tools: Type.TOptional<Type.TArray<Type.TString>>;
46
+ noSkills: Type.TOptional<Type.TBoolean>;
47
+ cwd: Type.TOptional<Type.TString>;
48
+ name: Type.TOptional<Type.TString>;
49
+ message: Type.TOptional<Type.TString>;
50
+ prompts: Type.TOptional<Type.TArray<Type.TString>>;
51
+ action: Type.TLiteral<"start">;
52
+ }>)[]>;
@@ -0,0 +1,15 @@
1
+ import { Type } from "typebox";
2
+ import { agentActionSchema, agentParametersSchema, agentStartOptions } from "./contract.js";
3
+ const options = Type.Omit(Type.Object(agentStartOptions), ["provider", "model", "thinking", "files", "tools", "noExtensions", "noPromptTemplates", "noContextFiles", "noSkills"]).properties;
4
+ const native = {
5
+ provider: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "dsh 原生 provider route,默认继承父会话。" })),
6
+ model: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "该 dsh provider 的模型 ID,默认继承父会话。" })),
7
+ thinking: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "该 dsh 模型的原生 reasoning effort ID,默认继承父会话;不转换 Pi 思考等级。" })),
8
+ files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32, description: "作为原生附件保存的文件;相对原工作区根目录。图片遵循宿主准入规则,其他文件保留原始字节供模型读取。" })),
9
+ tools: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1, description: "原生能力工具名;不填写 run_code 传输名,不支持递归委派。省略时使用原生工具和 pbot_team_message。" })),
10
+ noSkills: Type.Optional(Type.Boolean({ description: "关闭该专家的模型技能目录和原生 skill 工具;不改变其他会话的技能配置。" })),
11
+ };
12
+ const omitted = ["noExtensions", "noPromptTemplates", "noContextFiles", "provider", "model", "thinking", "files", "tools", "noSkills"];
13
+ export const dshAgentParametersSchema = Type.Object({ ...Type.Omit(agentParametersSchema, omitted).properties, ...native }, { additionalProperties: false });
14
+ export const dshAgentActionSchema = Type.Union(agentActionSchema.anyOf.map(row => row.properties.action.const === "start"
15
+ ? Type.Object({ action: Type.Literal("start"), ...options, ...native }, { additionalProperties: false }) : row));
@@ -0,0 +1,5 @@
1
+ import type { Context } from "@deepseek-ai/cordis";
2
+ import type { Agent } from "@deepseek-ai/dsh-agent";
3
+ import type { AgentService } from "../../services/agents/agent-service.js";
4
+ import type { AgentOwner } from "../../model/agent.js";
5
+ export declare function registerDshAgentTool(ctx: Context, agent: Agent, service: AgentService, owner: AgentOwner, check: () => void): void;
@@ -0,0 +1,38 @@
1
+ import { dshParameters, dshOutputSchema } from "../../integrations/dsh/schema.js";
2
+ import { object, json } from "../../common/json.js";
3
+ import { requireThat, schema } from "../../common/validation.js";
4
+ import { markdownFields } from "../../common/markdown.js";
5
+ import { executeAgent } from "./actions.js";
6
+ import { agentDescription, agentResultSchema } from "./contract.js";
7
+ import { dshAgentActionSchema, dshAgentParametersSchema } from "./dsh-contract.js";
8
+ export function registerDshAgentTool(ctx, agent, service, owner, check) {
9
+ const validators = new Map(dshAgentActionSchema.anyOf.map(row => [row.properties.action.const, schema(row)]));
10
+ const validOutput = schema(agentResultSchema);
11
+ ctx.tools.register({ name: "pbot_agent", description: agentDescription,
12
+ parameters: dshParameters(dshAgentParametersSchema),
13
+ output: {
14
+ schema: dshOutputSchema(agentResultSchema),
15
+ render: (_args, value) => [{ type: "text", text: "# 专家\n\n" + markdownFields(value) }],
16
+ presentationMeta: (args, value) => {
17
+ if (!object(args) || args.action !== "read" || !object(value) || !object(value.cycle) || value.cycle.state === "running")
18
+ return {};
19
+ return json({ pbotAgentReadKeys: [String(value.agentId) + ":" + String(value.cycle.cycleId)] });
20
+ },
21
+ },
22
+ async execute(args, exec) {
23
+ check();
24
+ exec.signal.throwIfAborted();
25
+ requireThat(exec.agent === agent && object(args) && typeof args.action === "string", "专家工具会话或参数无效。");
26
+ const valid = validators.get(args.action);
27
+ requireThat(valid && valid(args), "dsh 专家参数无效或包含不支持的宿主选项。");
28
+ const selection = agent.model.current();
29
+ const output = await executeAgent(service, args, owner, selection ? {
30
+ provider: selection.provider, model: selection.model,
31
+ ...(selection.reasoningEffort && (!args.provider || args.provider === selection.provider) && (!args.model || args.model === selection.model)
32
+ ? { thinking: selection.reasoningEffort } : {}),
33
+ } : {});
34
+ requireThat(validOutput(output.structuredContent), "专家输出不符合契约。");
35
+ return output.structuredContent;
36
+ },
37
+ });
38
+ }
@@ -0,0 +1,70 @@
1
+ import type { HistoryLocation } from "../../model/history.js";
2
+ import type { HistoryService } from "../../services/history/history-service.js";
3
+ import type { HistoryInput } from "./contract.js";
4
+ export declare function executeHistory(service: HistoryService, args: HistoryInput, location: HistoryLocation, signal?: AbortSignal): Promise<{
5
+ matches: {
6
+ parents: string[];
7
+ snippet: string;
8
+ host: import("../../model/history.js").HistoryHost;
9
+ id: string;
10
+ kind: "session" | "exchange" | "summary";
11
+ sessionId: string;
12
+ name: string;
13
+ preview: string;
14
+ from: string;
15
+ to: string;
16
+ ready: boolean;
17
+ completed: boolean;
18
+ }[];
19
+ total: number;
20
+ nextOffset: number | null;
21
+ warnings: string[];
22
+ } | {
23
+ node: {
24
+ text: string;
25
+ totalLength: number;
26
+ nextOffset: number | null;
27
+ parents: {
28
+ host: import("../../model/history.js").HistoryHost;
29
+ id: string;
30
+ kind: "session" | "exchange" | "summary";
31
+ sessionId: string;
32
+ name: string;
33
+ preview: string;
34
+ from: string;
35
+ to: string;
36
+ ready: boolean;
37
+ completed: boolean;
38
+ }[];
39
+ children: {
40
+ host: import("../../model/history.js").HistoryHost;
41
+ id: string;
42
+ kind: "session" | "exchange" | "summary";
43
+ sessionId: string;
44
+ name: string;
45
+ preview: string;
46
+ from: string;
47
+ to: string;
48
+ ready: boolean;
49
+ completed: boolean;
50
+ }[];
51
+ nextChildrenOffset: number | null;
52
+ source: {
53
+ host: import("../../model/history.js").HistoryHost;
54
+ sessionId: string;
55
+ entryIds: string[];
56
+ };
57
+ warnings: string[];
58
+ host: import("../../model/history.js").HistoryHost;
59
+ id: string;
60
+ kind: "session" | "exchange" | "summary";
61
+ sessionId: string;
62
+ name: string;
63
+ preview: string;
64
+ from: string;
65
+ to: string;
66
+ ready: boolean;
67
+ completed: boolean;
68
+ };
69
+ warnings: string[];
70
+ }>;
@@ -0,0 +1,7 @@
1
+ export async function executeHistory(service, args, location, signal) {
2
+ signal?.throwIfAborted();
3
+ await service.refresh(location, signal);
4
+ signal?.throwIfAborted();
5
+ return args.action === "search" ? service.search(args) :
6
+ { node: service.read(args.id, args.offset, args.limit, args.childrenOffset, args.host), warnings: service.warnings };
7
+ }
@@ -0,0 +1,81 @@
1
+ import { Type, type Static } from "typebox";
2
+ export declare const historyResultSchema: Type.TObject<{
3
+ matches: Type.TOptional<Type.TArray<Type.TObject<{
4
+ snippet: Type.TString;
5
+ parents: Type.TArray<Type.TString>;
6
+ host: Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">]>;
7
+ id: Type.TString;
8
+ kind: Type.TUnion<[Type.TLiteral<"session">, Type.TLiteral<"exchange">, Type.TLiteral<"summary">]>;
9
+ sessionId: Type.TString;
10
+ name: Type.TString;
11
+ preview: Type.TString;
12
+ from: Type.TString;
13
+ to: Type.TString;
14
+ ready: Type.TBoolean;
15
+ completed: Type.TBoolean;
16
+ }>>>;
17
+ total: Type.TOptional<Type.TInteger>;
18
+ nextOffset: Type.TOptional<Type.TUnion<[Type.TInteger, Type.TNull]>>;
19
+ node: Type.TOptional<Type.TObject<{
20
+ text: Type.TString;
21
+ totalLength: Type.TInteger;
22
+ nextOffset: Type.TUnion<[Type.TInteger, Type.TNull]>;
23
+ parents: Type.TArray<Type.TObject<{
24
+ host: Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">]>;
25
+ id: Type.TString;
26
+ kind: Type.TUnion<[Type.TLiteral<"session">, Type.TLiteral<"exchange">, Type.TLiteral<"summary">]>;
27
+ sessionId: Type.TString;
28
+ name: Type.TString;
29
+ preview: Type.TString;
30
+ from: Type.TString;
31
+ to: Type.TString;
32
+ ready: Type.TBoolean;
33
+ completed: Type.TBoolean;
34
+ }>>;
35
+ children: Type.TArray<Type.TObject<{
36
+ host: Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">]>;
37
+ id: Type.TString;
38
+ kind: Type.TUnion<[Type.TLiteral<"session">, Type.TLiteral<"exchange">, Type.TLiteral<"summary">]>;
39
+ sessionId: Type.TString;
40
+ name: Type.TString;
41
+ preview: Type.TString;
42
+ from: Type.TString;
43
+ to: Type.TString;
44
+ ready: Type.TBoolean;
45
+ completed: Type.TBoolean;
46
+ }>>;
47
+ nextChildrenOffset: Type.TUnion<[Type.TInteger, Type.TNull]>;
48
+ source: Type.TObject<{
49
+ host: Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">]>;
50
+ sessionId: Type.TString;
51
+ entryIds: Type.TArray<Type.TString>;
52
+ }>;
53
+ warnings: Type.TArray<Type.TString>;
54
+ host: Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">]>;
55
+ id: Type.TString;
56
+ kind: Type.TUnion<[Type.TLiteral<"session">, Type.TLiteral<"exchange">, Type.TLiteral<"summary">]>;
57
+ sessionId: Type.TString;
58
+ name: Type.TString;
59
+ preview: Type.TString;
60
+ from: Type.TString;
61
+ to: Type.TString;
62
+ ready: Type.TBoolean;
63
+ completed: Type.TBoolean;
64
+ }>>;
65
+ warnings: Type.TArray<Type.TString>;
66
+ }>;
67
+ export declare const historyDescription = "\u67E5\u8BE2\u5F53\u524D\u5DE5\u4F5C\u533A\u7684 Pi \u4E0E dsh \u5386\u53F2\u5F52\u6863\uFF0C\u53EF\u7528 host \u7B5B\u9009\u6765\u6E90\u3002search \u5BF9\u95EE\u7B54\u539F\u6587\u548C\u5404\u5C42\u6458\u8981\u505A\u4E0D\u533A\u5206\u5927\u5C0F\u5199\u7684\u8FDE\u7EED\u6587\u672C\u5339\u914D\uFF1B\u7701\u7565 query \u5217\u51FA\u4F1A\u8BDD\u3002\u5FD8\u8BB0\u539F\u8BCD\u65F6\u6362\u51E0\u7EC4\u8BCD\u67E5\u8BE2\u3002read \u8BFB\u53D6\u547D\u4E2D\u8282\u70B9\u5E76\u8FD4\u56DE\u7236\u5B50\u8282\u70B9\uFF1B\u6CBF parents/children \u7684 id \u5C55\u5F00\uFF0CnextOffset \u7EED\u8BFB\u6B63\u6587\uFF0CnextChildrenOffset \u7EED\u8BFB\u5B50\u8282\u70B9\u3002\u6458\u8981\u662F\u68C0\u7D22\u7EBF\u7D22\uFF0C\u91CD\u8981\u7ED3\u8BBA\u56DE\u5230 exchange \u539F\u6587\u6838\u5BF9\u3002\u5171\u4EAB\u524D\u7F00\u53EF\u80FD\u6709\u591A\u4E2A\u7236\u8282\u70B9\u3002\u67E5\u8BE2\u4E0D\u8C03\u7528\u6A21\u578B\uFF0C\u4E0D\u6062\u590D\u6216\u91CD\u653E\u65E7\u4EFB\u52A1\uFF1B\u53EA\u66F4\u65B0\u5F53\u524D\u5BBF\u4E3B\u7684\u539F\u751F\u5386\u53F2\u7D22\u5F15\u3002\u95EE\u7B54\u5F52\u6863\u4E0D\u4EE3\u66FF\u4E13\u5BB6\u7684\u5B8C\u6574\u5DE5\u5177\u65E5\u5FD7\u3002";
68
+ export declare const historyParameters: Type.TObject<{
69
+ action: Type.TUnion<[Type.TLiteral<"search">, Type.TLiteral<"read">]>;
70
+ host: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">]>>;
71
+ query: Type.TOptional<Type.TString>;
72
+ sessionId: Type.TOptional<Type.TString>;
73
+ from: Type.TOptional<Type.TString>;
74
+ to: Type.TOptional<Type.TString>;
75
+ id: Type.TOptional<Type.TString>;
76
+ offset: Type.TOptional<Type.TInteger>;
77
+ limit: Type.TOptional<Type.TInteger>;
78
+ childrenOffset: Type.TOptional<Type.TInteger>;
79
+ }>;
80
+ export type HistoryInput = Static<typeof historyParameters>;
81
+ export declare function historyInput(value: unknown): HistoryInput;
@@ -0,0 +1,32 @@
1
+ import { Type } from "typebox";
2
+ import { requireThat, schema } from "../../common/validation.js";
3
+ const host = Type.Union([Type.Literal("pi"), Type.Literal("dsh")]);
4
+ const nullableOffset = Type.Union([Type.Integer(), Type.Null()]);
5
+ const node = Type.Object({ host, id: Type.String(), kind: Type.Union([Type.Literal("session"), Type.Literal("exchange"), Type.Literal("summary")]),
6
+ sessionId: Type.String(), name: Type.String(), preview: Type.String(), from: Type.String(), to: Type.String(), ready: Type.Boolean(), completed: Type.Boolean() });
7
+ export const historyResultSchema = Type.Object({
8
+ matches: Type.Optional(Type.Array(Type.Object({ ...node.properties, snippet: Type.String(), parents: Type.Array(Type.String()) }))),
9
+ total: Type.Optional(Type.Integer()), nextOffset: Type.Optional(nullableOffset),
10
+ node: Type.Optional(Type.Object({ ...node.properties, text: Type.String(), totalLength: Type.Integer(), nextOffset: nullableOffset,
11
+ parents: Type.Array(node), children: Type.Array(node), nextChildrenOffset: nullableOffset,
12
+ source: Type.Object({ host, sessionId: Type.String({ description: "原始宿主会话 ID;来源不保存文件路径。" }), entryIds: Type.Array(Type.String()) }), warnings: Type.Array(Type.String()) })),
13
+ warnings: Type.Array(Type.String()),
14
+ });
15
+ export const historyDescription = "查询当前工作区的 Pi 与 dsh 历史归档,可用 host 筛选来源。search 对问答原文和各层摘要做不区分大小写的连续文本匹配;省略 query 列出会话。忘记原词时换几组词查询。read 读取命中节点并返回父子节点;沿 parents/children 的 id 展开,nextOffset 续读正文,nextChildrenOffset 续读子节点。摘要是检索线索,重要结论回到 exchange 原文核对。共享前缀可能有多个父节点。查询不调用模型,不恢复或重放旧任务;只更新当前宿主的原生历史索引。问答归档不代替专家的完整工具日志。";
16
+ export const historyParameters = Type.Object({ action: Type.Union([Type.Literal("search"), Type.Literal("read")]),
17
+ host: Type.Optional(host), query: Type.Optional(Type.String()), sessionId: Type.Optional(Type.String()),
18
+ from: Type.Optional(Type.String({ description: "search:ISO 日期或时间,下界。" })),
19
+ to: Type.Optional(Type.String({ description: "search:ISO 日期或时间,上界。" })),
20
+ id: Type.Optional(Type.String({ description: "read 必填:返回的节点 id。" })),
21
+ offset: Type.Optional(Type.Integer({ minimum: 0 })),
22
+ limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 24000, description: "search:最多 50 条,默认 20;read:字符数,默认 12000。" })),
23
+ childrenOffset: Type.Optional(Type.Integer({ minimum: 0 })),
24
+ }, { additionalProperties: false });
25
+ const valid = schema(historyParameters);
26
+ export function historyInput(value) {
27
+ requireThat(valid(value), "历史参数无效。");
28
+ const args = value;
29
+ requireThat(args.action !== "read" || args.id, "read 需要节点 id。");
30
+ requireThat(args.action !== "search" || (args.limit ?? 20) <= 50, "search limit 最多 50。");
31
+ return args;
32
+ }
@@ -0,0 +1,4 @@
1
+ import type { Context } from "@deepseek-ai/cordis";
2
+ import type { Agent } from "@deepseek-ai/dsh-agent";
3
+ import type { HistoryService } from "../../services/history/history-service.js";
4
+ export declare function registerDshHistoryTool(ctx: Context, agent: Agent, service: HistoryService, lifetime: AbortSignal, check: () => void): void;
@@ -0,0 +1,22 @@
1
+ import { dshParameters, dshOutputSchema } from "../../integrations/dsh/schema.js";
2
+ import { requireThat, schema } from "../../common/validation.js";
3
+ import { json } from "../../common/json.js";
4
+ import { markdownFields } from "../../common/markdown.js";
5
+ import { historyDescription, historyInput, historyParameters, historyResultSchema } from "./contract.js";
6
+ import { executeHistory } from "./actions.js";
7
+ export function registerDshHistoryTool(ctx, agent, service, lifetime, check) {
8
+ const valid = schema(historyResultSchema);
9
+ ctx.tools.register({ name: "pbot_history", description: historyDescription, parameters: dshParameters(historyParameters),
10
+ output: { schema: dshOutputSchema(historyResultSchema), render: (_args, value) => [{ type: "text", text: "# 历史\n\n" + markdownFields(value) }] },
11
+ async execute(value, exec) {
12
+ check();
13
+ requireThat(exec.agent === agent, "历史工具不属于当前会话。");
14
+ const signal = AbortSignal.any([exec.signal, lifetime]);
15
+ const result = await executeHistory(service, historyInput(value), { host: "dsh", sessionId: agent.id }, signal);
16
+ check();
17
+ signal.throwIfAborted();
18
+ requireThat(valid(result), "历史输出不符合契约。");
19
+ return json(result);
20
+ },
21
+ });
22
+ }
@@ -0,0 +1,18 @@
1
+ export declare function markdownResult(value: unknown, title: string): {
2
+ isError?: boolean;
3
+ content: {
4
+ type: "text";
5
+ text: string;
6
+ }[];
7
+ details: import("../common/json.js").Json;
8
+ structuredContent: import("../common/json.js").Json;
9
+ };
10
+ export declare function result(value: unknown, isError?: boolean, text?: string): {
11
+ isError?: boolean;
12
+ content: {
13
+ type: "text";
14
+ text: string;
15
+ }[];
16
+ details: import("../common/json.js").Json;
17
+ structuredContent: import("../common/json.js").Json;
18
+ };
@@ -0,0 +1,10 @@
1
+ import { json } from "../common/json.js";
2
+ import { markdownFields } from "../common/markdown.js";
3
+ export function markdownResult(value, title) {
4
+ return result(value, false, "# " + title + "\n\n" + markdownFields(json(value)));
5
+ }
6
+ export function result(value, isError = false, text) {
7
+ const data = json(value);
8
+ return { content: [{ type: "text", text: text ?? JSON.stringify(data) }],
9
+ details: data, structuredContent: data, ...(isError ? { isError: true } : {}) };
10
+ }
@@ -0,0 +1,24 @@
1
+ import type { Static } from "typebox";
2
+ import type { TeamService } from "../../services/agents/team-service.js";
3
+ import type { AgentService } from "../../services/agents/agent-service.js";
4
+ import type { TeamActor } from "../../model/team.js";
5
+ import type { AgentOwner } from "../../model/agent.js";
6
+ import type { teamParametersSchema, teamMessageParametersSchema } from "./contract.js";
7
+ export declare function executeTeam(service: TeamService, agents: AgentService, input: Static<typeof teamParametersSchema>, owner: AgentOwner): {
8
+ isError?: boolean;
9
+ content: {
10
+ type: "text";
11
+ text: string;
12
+ }[];
13
+ details: import("../../common/json.js").Json;
14
+ structuredContent: import("../../common/json.js").Json;
15
+ };
16
+ export declare function executeTeamMessage(service: TeamService, input: Static<typeof teamMessageParametersSchema>, actor: TeamActor, requestId: string): {
17
+ isError?: boolean;
18
+ content: {
19
+ type: "text";
20
+ text: string;
21
+ }[];
22
+ details: import("../../common/json.js").Json;
23
+ structuredContent: import("../../common/json.js").Json;
24
+ };