@zhin.js/agent 0.1.30 → 0.1.32

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 (371) hide show
  1. package/README.md +89 -24
  2. package/lib/builtin/memory-search-tool.d.ts +2 -0
  3. package/lib/builtin/memory-search-tool.d.ts.map +1 -0
  4. package/lib/builtin/memory-search-tool.js +61 -0
  5. package/lib/builtin/memory-search-tool.js.map +1 -0
  6. package/lib/builtin/memory-upsert-tool.d.ts +2 -0
  7. package/lib/builtin/memory-upsert-tool.d.ts.map +1 -0
  8. package/lib/builtin/memory-upsert-tool.js +75 -0
  9. package/lib/builtin/memory-upsert-tool.js.map +1 -0
  10. package/lib/builtin/orchestration-tools.d.ts +7 -0
  11. package/lib/builtin/orchestration-tools.d.ts.map +1 -0
  12. package/lib/builtin/orchestration-tools.js +283 -0
  13. package/lib/builtin/orchestration-tools.js.map +1 -0
  14. package/lib/builtin/run-deferred-task-tool.d.ts +1 -1
  15. package/lib/builtin/run-deferred-task-tool.d.ts.map +1 -1
  16. package/lib/builtin/run-deferred-task-tool.js +1 -1
  17. package/lib/builtin/run-deferred-task-tool.js.map +1 -1
  18. package/lib/builtin/run-spec-dry-run-tool.d.ts +6 -0
  19. package/lib/builtin/run-spec-dry-run-tool.d.ts.map +1 -0
  20. package/lib/builtin/run-spec-dry-run-tool.js +51 -0
  21. package/lib/builtin/run-spec-dry-run-tool.js.map +1 -0
  22. package/lib/builtin/run-validation-spec-tool.d.ts +8 -0
  23. package/lib/builtin/run-validation-spec-tool.d.ts.map +1 -0
  24. package/lib/builtin/run-validation-spec-tool.js +44 -0
  25. package/lib/builtin/run-validation-spec-tool.js.map +1 -0
  26. package/lib/builtin/spawn-task-tool.d.ts +1 -1
  27. package/lib/builtin/spawn-task-tool.d.ts.map +1 -1
  28. package/lib/builtin/spawn-task-tool.js +53 -1
  29. package/lib/builtin/spawn-task-tool.js.map +1 -1
  30. package/lib/builtin-tools.d.ts +2 -0
  31. package/lib/builtin-tools.d.ts.map +1 -1
  32. package/lib/builtin-tools.js +6 -0
  33. package/lib/builtin-tools.js.map +1 -1
  34. package/lib/config/normalize-ai-config.d.ts +4 -0
  35. package/lib/config/normalize-ai-config.d.ts.map +1 -1
  36. package/lib/config/normalize-ai-config.js +23 -6
  37. package/lib/config/normalize-ai-config.js.map +1 -1
  38. package/lib/config/provider-instance.d.ts.map +1 -1
  39. package/lib/config/provider-instance.js +26 -7
  40. package/lib/config/provider-instance.js.map +1 -1
  41. package/lib/config/types.d.ts +2 -1
  42. package/lib/config/types.d.ts.map +1 -1
  43. package/lib/config/types.js.map +1 -1
  44. package/lib/config/validate-ai-config.d.ts.map +1 -1
  45. package/lib/config/validate-ai-config.js +5 -0
  46. package/lib/config/validate-ai-config.js.map +1 -1
  47. package/lib/create-agent-session.d.ts +16 -0
  48. package/lib/create-agent-session.d.ts.map +1 -0
  49. package/lib/create-agent-session.js +15 -0
  50. package/lib/create-agent-session.js.map +1 -0
  51. package/lib/deferred-worker-runner.d.ts +2 -0
  52. package/lib/deferred-worker-runner.d.ts.map +1 -1
  53. package/lib/deferred-worker-runner.js +17 -34
  54. package/lib/deferred-worker-runner.js.map +1 -1
  55. package/lib/discovery/agents.d.ts +5 -0
  56. package/lib/discovery/agents.d.ts.map +1 -1
  57. package/lib/discovery/agents.js +7 -0
  58. package/lib/discovery/agents.js.map +1 -1
  59. package/lib/discovery/skills.d.ts +1 -1
  60. package/lib/discovery/skills.d.ts.map +1 -1
  61. package/lib/discovery/skills.js +2 -9
  62. package/lib/discovery/skills.js.map +1 -1
  63. package/lib/discovery/utils.d.ts +7 -1
  64. package/lib/discovery/utils.d.ts.map +1 -1
  65. package/lib/discovery/utils.js +66 -5
  66. package/lib/discovery/utils.js.map +1 -1
  67. package/lib/index.d.ts +19 -2
  68. package/lib/index.d.ts.map +1 -1
  69. package/lib/index.js +12 -2
  70. package/lib/index.js.map +1 -1
  71. package/lib/init/activate-ai-database-storage.d.ts +1 -1
  72. package/lib/init/activate-ai-database-storage.d.ts.map +1 -1
  73. package/lib/init/activate-ai-database-storage.js +38 -13
  74. package/lib/init/activate-ai-database-storage.js.map +1 -1
  75. package/lib/init/create-zhin-agent.d.ts.map +1 -1
  76. package/lib/init/create-zhin-agent.js +86 -9
  77. package/lib/init/create-zhin-agent.js.map +1 -1
  78. package/lib/init/introspection-args.d.ts +34 -0
  79. package/lib/init/introspection-args.d.ts.map +1 -0
  80. package/lib/init/introspection-args.js +71 -0
  81. package/lib/init/introspection-args.js.map +1 -0
  82. package/lib/init/introspection-collectors.d.ts +21 -0
  83. package/lib/init/introspection-collectors.d.ts.map +1 -0
  84. package/lib/init/introspection-collectors.js +74 -0
  85. package/lib/init/introspection-collectors.js.map +1 -0
  86. package/lib/init/introspection-commands-format.d.ts +1 -1
  87. package/lib/init/introspection-commands-format.js +4 -4
  88. package/lib/init/introspection-commands-format.js.map +1 -1
  89. package/lib/init/introspection-output.d.ts +6 -0
  90. package/lib/init/introspection-output.d.ts.map +1 -0
  91. package/lib/init/introspection-output.js +52 -0
  92. package/lib/init/introspection-output.js.map +1 -0
  93. package/lib/init/introspection-pagination.d.ts +14 -0
  94. package/lib/init/introspection-pagination.d.ts.map +1 -0
  95. package/lib/init/introspection-pagination.js +33 -0
  96. package/lib/init/introspection-pagination.js.map +1 -0
  97. package/lib/init/introspection-rest.d.ts +24 -0
  98. package/lib/init/introspection-rest.d.ts.map +1 -0
  99. package/lib/init/introspection-rest.js +65 -0
  100. package/lib/init/introspection-rest.js.map +1 -0
  101. package/lib/init/register-agent-mesh-mcp.d.ts +2 -0
  102. package/lib/init/register-agent-mesh-mcp.d.ts.map +1 -0
  103. package/lib/init/register-agent-mesh-mcp.js +13 -0
  104. package/lib/init/register-agent-mesh-mcp.js.map +1 -0
  105. package/lib/init/register-ai-trigger.d.ts.map +1 -1
  106. package/lib/init/register-ai-trigger.js +29 -4
  107. package/lib/init/register-ai-trigger.js.map +1 -1
  108. package/lib/init/register-builtin-tools.d.ts.map +1 -1
  109. package/lib/init/register-builtin-tools.js +4 -0
  110. package/lib/init/register-builtin-tools.js.map +1 -1
  111. package/lib/init/register-db-models.d.ts.map +1 -1
  112. package/lib/init/register-db-models.js +10 -8
  113. package/lib/init/register-db-models.js.map +1 -1
  114. package/lib/init/register-db-upgrade.d.ts +1 -1
  115. package/lib/init/register-db-upgrade.d.ts.map +1 -1
  116. package/lib/init/register-db-upgrade.js +22 -3
  117. package/lib/init/register-db-upgrade.js.map +1 -1
  118. package/lib/init/register-group-session-passive.d.ts +3 -0
  119. package/lib/init/register-group-session-passive.d.ts.map +1 -0
  120. package/lib/init/register-group-session-passive.js +55 -0
  121. package/lib/init/register-group-session-passive.js.map +1 -0
  122. package/lib/init/register-introspection-commands.d.ts.map +1 -1
  123. package/lib/init/register-introspection-commands.js +5 -6
  124. package/lib/init/register-introspection-commands.js.map +1 -1
  125. package/lib/init/register-management-tools.d.ts +1 -1
  126. package/lib/init/register-management-tools.d.ts.map +1 -1
  127. package/lib/init/register-management-tools.js +57 -36
  128. package/lib/init/register-management-tools.js.map +1 -1
  129. package/lib/init/upgrade-agent-db-schema.d.ts +41 -0
  130. package/lib/init/upgrade-agent-db-schema.d.ts.map +1 -0
  131. package/lib/init/upgrade-agent-db-schema.js +170 -0
  132. package/lib/init/upgrade-agent-db-schema.js.map +1 -0
  133. package/lib/init.d.ts.map +1 -1
  134. package/lib/init.js +4 -0
  135. package/lib/init.js.map +1 -1
  136. package/lib/mcp-server/agent-mesh-tools.d.ts +8 -0
  137. package/lib/mcp-server/agent-mesh-tools.d.ts.map +1 -0
  138. package/lib/mcp-server/agent-mesh-tools.js +138 -0
  139. package/lib/mcp-server/agent-mesh-tools.js.map +1 -0
  140. package/lib/media/deliver-subagent-result.d.ts +7 -0
  141. package/lib/media/deliver-subagent-result.d.ts.map +1 -1
  142. package/lib/media/deliver-subagent-result.js +3 -1
  143. package/lib/media/deliver-subagent-result.js.map +1 -1
  144. package/lib/media/media-normalize.d.ts +2 -0
  145. package/lib/media/media-normalize.d.ts.map +1 -1
  146. package/lib/media/media-normalize.js +89 -0
  147. package/lib/media/media-normalize.js.map +1 -1
  148. package/lib/media/subagent-user-delivery.d.ts +2 -9
  149. package/lib/media/subagent-user-delivery.d.ts.map +1 -1
  150. package/lib/media/subagent-user-delivery.js.map +1 -1
  151. package/lib/memory-entry-registry.d.ts +7 -0
  152. package/lib/memory-entry-registry.d.ts.map +1 -0
  153. package/lib/memory-entry-registry.js +8 -0
  154. package/lib/memory-entry-registry.js.map +1 -0
  155. package/lib/orchestration-memory-hook.d.ts +3 -0
  156. package/lib/orchestration-memory-hook.d.ts.map +1 -0
  157. package/lib/orchestration-memory-hook.js +22 -0
  158. package/lib/orchestration-memory-hook.js.map +1 -0
  159. package/lib/orchestration-runtime-registry.d.ts +14 -0
  160. package/lib/orchestration-runtime-registry.d.ts.map +1 -0
  161. package/lib/orchestration-runtime-registry.js +15 -0
  162. package/lib/orchestration-runtime-registry.js.map +1 -0
  163. package/lib/orchestrator/agent-dispatcher.d.ts +36 -3
  164. package/lib/orchestrator/agent-dispatcher.d.ts.map +1 -1
  165. package/lib/orchestrator/agent-dispatcher.js +203 -13
  166. package/lib/orchestrator/agent-dispatcher.js.map +1 -1
  167. package/lib/orchestrator/delegation-processor.d.ts +33 -0
  168. package/lib/orchestrator/delegation-processor.d.ts.map +1 -0
  169. package/lib/orchestrator/delegation-processor.js +140 -0
  170. package/lib/orchestrator/delegation-processor.js.map +1 -0
  171. package/lib/orchestrator/mission-milestone-notify.d.ts +17 -0
  172. package/lib/orchestrator/mission-milestone-notify.d.ts.map +1 -0
  173. package/lib/orchestrator/mission-milestone-notify.js +49 -0
  174. package/lib/orchestrator/mission-milestone-notify.js.map +1 -0
  175. package/lib/orchestrator/mission-negotiation.d.ts +17 -0
  176. package/lib/orchestrator/mission-negotiation.d.ts.map +1 -0
  177. package/lib/orchestrator/mission-negotiation.js +89 -0
  178. package/lib/orchestrator/mission-negotiation.js.map +1 -0
  179. package/lib/orchestrator/mission-patch-acl.d.ts +9 -0
  180. package/lib/orchestrator/mission-patch-acl.d.ts.map +1 -0
  181. package/lib/orchestrator/mission-patch-acl.js +29 -0
  182. package/lib/orchestrator/mission-patch-acl.js.map +1 -0
  183. package/lib/orchestrator/mission-runner.d.ts +24 -0
  184. package/lib/orchestrator/mission-runner.d.ts.map +1 -0
  185. package/lib/orchestrator/mission-runner.js +179 -0
  186. package/lib/orchestrator/mission-runner.js.map +1 -0
  187. package/lib/orchestrator/mission-spec.d.ts +44 -0
  188. package/lib/orchestrator/mission-spec.d.ts.map +1 -0
  189. package/lib/orchestrator/mission-spec.js +121 -0
  190. package/lib/orchestrator/mission-spec.js.map +1 -0
  191. package/lib/orchestrator/mission-state.d.ts +48 -0
  192. package/lib/orchestrator/mission-state.d.ts.map +1 -0
  193. package/lib/orchestrator/mission-state.js +66 -0
  194. package/lib/orchestrator/mission-state.js.map +1 -0
  195. package/lib/orchestrator/orchestration-repository.d.ts +85 -0
  196. package/lib/orchestrator/orchestration-repository.d.ts.map +1 -0
  197. package/lib/orchestrator/orchestration-repository.js +325 -0
  198. package/lib/orchestrator/orchestration-repository.js.map +1 -0
  199. package/lib/orchestrator/orchestration-service.d.ts +58 -0
  200. package/lib/orchestrator/orchestration-service.d.ts.map +1 -0
  201. package/lib/orchestrator/orchestration-service.js +221 -0
  202. package/lib/orchestrator/orchestration-service.js.map +1 -0
  203. package/lib/orchestrator/remote-agent-registry.d.ts +32 -0
  204. package/lib/orchestrator/remote-agent-registry.d.ts.map +1 -0
  205. package/lib/orchestrator/remote-agent-registry.js +120 -0
  206. package/lib/orchestrator/remote-agent-registry.js.map +1 -0
  207. package/lib/orchestrator/remote-task-executor.d.ts +10 -0
  208. package/lib/orchestrator/remote-task-executor.d.ts.map +1 -0
  209. package/lib/orchestrator/remote-task-executor.js +142 -0
  210. package/lib/orchestrator/remote-task-executor.js.map +1 -0
  211. package/lib/orchestrator/remote-task-poller.d.ts +16 -0
  212. package/lib/orchestrator/remote-task-poller.d.ts.map +1 -0
  213. package/lib/orchestrator/remote-task-poller.js +75 -0
  214. package/lib/orchestrator/remote-task-poller.js.map +1 -0
  215. package/lib/plugin-loop-hooks.d.ts +32 -0
  216. package/lib/plugin-loop-hooks.d.ts.map +1 -0
  217. package/lib/plugin-loop-hooks.js +69 -0
  218. package/lib/plugin-loop-hooks.js.map +1 -0
  219. package/lib/service.d.ts +38 -22
  220. package/lib/service.d.ts.map +1 -1
  221. package/lib/service.js +61 -19
  222. package/lib/service.js.map +1 -1
  223. package/lib/session-tree-runtime-registry.d.ts +20 -0
  224. package/lib/session-tree-runtime-registry.d.ts.map +1 -0
  225. package/lib/session-tree-runtime-registry.js +25 -0
  226. package/lib/session-tree-runtime-registry.js.map +1 -0
  227. package/lib/subagent-ai-events.d.ts +2 -2
  228. package/lib/subagent-ai-events.d.ts.map +1 -1
  229. package/lib/subagent-ai-events.js +17 -21
  230. package/lib/subagent-ai-events.js.map +1 -1
  231. package/lib/subagent-artifact.d.ts +7 -0
  232. package/lib/subagent-artifact.d.ts.map +1 -0
  233. package/lib/subagent-artifact.js +26 -0
  234. package/lib/subagent-artifact.js.map +1 -0
  235. package/lib/subagent-parent-context.d.ts +9 -0
  236. package/lib/subagent-parent-context.d.ts.map +1 -0
  237. package/lib/subagent-parent-context.js +50 -0
  238. package/lib/subagent-parent-context.js.map +1 -0
  239. package/lib/subagent-preset.d.ts +10 -0
  240. package/lib/subagent-preset.d.ts.map +1 -0
  241. package/lib/subagent-preset.js +44 -0
  242. package/lib/subagent-preset.js.map +1 -0
  243. package/lib/subagent-prompt.d.ts +7 -0
  244. package/lib/subagent-prompt.d.ts.map +1 -0
  245. package/lib/subagent-prompt.js +14 -0
  246. package/lib/subagent-prompt.js.map +1 -0
  247. package/lib/subagent.d.ts +19 -0
  248. package/lib/subagent.d.ts.map +1 -1
  249. package/lib/subagent.js +175 -92
  250. package/lib/subagent.js.map +1 -1
  251. package/lib/typing-indicator/adapter-integration.d.ts +7 -3
  252. package/lib/typing-indicator/adapter-integration.d.ts.map +1 -1
  253. package/lib/typing-indicator/adapter-integration.js +30 -6
  254. package/lib/typing-indicator/adapter-integration.js.map +1 -1
  255. package/lib/typing-indicator/index.d.ts +26 -3
  256. package/lib/typing-indicator/index.d.ts.map +1 -1
  257. package/lib/typing-indicator/index.js +94 -6
  258. package/lib/typing-indicator/index.js.map +1 -1
  259. package/lib/typing-indicator/integration.d.ts.map +1 -1
  260. package/lib/typing-indicator/integration.js +7 -2
  261. package/lib/typing-indicator/integration.js.map +1 -1
  262. package/lib/zhin-agent/agent-loop-standalone.d.ts +32 -0
  263. package/lib/zhin-agent/agent-loop-standalone.d.ts.map +1 -0
  264. package/lib/zhin-agent/agent-loop-standalone.js +144 -0
  265. package/lib/zhin-agent/agent-loop-standalone.js.map +1 -0
  266. package/lib/zhin-agent/agent-loop-turn.d.ts +52 -0
  267. package/lib/zhin-agent/agent-loop-turn.d.ts.map +1 -0
  268. package/lib/zhin-agent/agent-loop-turn.js +328 -0
  269. package/lib/zhin-agent/agent-loop-turn.js.map +1 -0
  270. package/lib/zhin-agent/branch-summarization-runtime.d.ts +16 -0
  271. package/lib/zhin-agent/branch-summarization-runtime.d.ts.map +1 -0
  272. package/lib/zhin-agent/branch-summarization-runtime.js +58 -0
  273. package/lib/zhin-agent/branch-summarization-runtime.js.map +1 -0
  274. package/lib/zhin-agent/builtin-tools.d.ts +3 -2
  275. package/lib/zhin-agent/builtin-tools.d.ts.map +1 -1
  276. package/lib/zhin-agent/builtin-tools.js +15 -16
  277. package/lib/zhin-agent/builtin-tools.js.map +1 -1
  278. package/lib/zhin-agent/compaction-runtime.d.ts +25 -0
  279. package/lib/zhin-agent/compaction-runtime.d.ts.map +1 -0
  280. package/lib/zhin-agent/compaction-runtime.js +78 -0
  281. package/lib/zhin-agent/compaction-runtime.js.map +1 -0
  282. package/lib/zhin-agent/config.d.ts +22 -2
  283. package/lib/zhin-agent/config.d.ts.map +1 -1
  284. package/lib/zhin-agent/config.js +25 -2
  285. package/lib/zhin-agent/config.js.map +1 -1
  286. package/lib/zhin-agent/deferred-auto-continue.d.ts +11 -0
  287. package/lib/zhin-agent/deferred-auto-continue.d.ts.map +1 -0
  288. package/lib/zhin-agent/deferred-auto-continue.js +41 -0
  289. package/lib/zhin-agent/deferred-auto-continue.js.map +1 -0
  290. package/lib/zhin-agent/deferred-delivery.d.ts +9 -0
  291. package/lib/zhin-agent/deferred-delivery.d.ts.map +1 -0
  292. package/lib/zhin-agent/deferred-delivery.js +35 -0
  293. package/lib/zhin-agent/deferred-delivery.js.map +1 -0
  294. package/lib/zhin-agent/index.d.ts +60 -11
  295. package/lib/zhin-agent/index.d.ts.map +1 -1
  296. package/lib/zhin-agent/index.js +264 -22
  297. package/lib/zhin-agent/index.js.map +1 -1
  298. package/lib/zhin-agent/model-resolver.d.ts +0 -1
  299. package/lib/zhin-agent/model-resolver.d.ts.map +1 -1
  300. package/lib/zhin-agent/model-resolver.js.map +1 -1
  301. package/lib/zhin-agent/multimodal-message.d.ts +9 -0
  302. package/lib/zhin-agent/multimodal-message.d.ts.map +1 -0
  303. package/lib/zhin-agent/multimodal-message.js +69 -0
  304. package/lib/zhin-agent/multimodal-message.js.map +1 -0
  305. package/lib/zhin-agent/persist-deferred-context.d.ts +5 -0
  306. package/lib/zhin-agent/persist-deferred-context.d.ts.map +1 -0
  307. package/lib/zhin-agent/persist-deferred-context.js +40 -0
  308. package/lib/zhin-agent/persist-deferred-context.js.map +1 -0
  309. package/lib/zhin-agent/prompt-access.d.ts +4 -0
  310. package/lib/zhin-agent/prompt-access.d.ts.map +1 -0
  311. package/lib/zhin-agent/prompt-access.js +7 -0
  312. package/lib/zhin-agent/prompt-access.js.map +1 -0
  313. package/lib/zhin-agent/prompt-builder.d.ts.map +1 -1
  314. package/lib/zhin-agent/prompt-builder.js +5 -0
  315. package/lib/zhin-agent/prompt-builder.js.map +1 -1
  316. package/lib/zhin-agent/prompt-controller.d.ts +53 -0
  317. package/lib/zhin-agent/prompt-controller.d.ts.map +1 -0
  318. package/lib/zhin-agent/prompt-controller.js +165 -0
  319. package/lib/zhin-agent/prompt-controller.js.map +1 -0
  320. package/lib/zhin-agent/prompt-input.d.ts +3 -0
  321. package/lib/zhin-agent/prompt-input.d.ts.map +1 -0
  322. package/lib/zhin-agent/prompt-input.js +8 -0
  323. package/lib/zhin-agent/prompt-input.js.map +1 -0
  324. package/lib/zhin-agent/prompt.d.ts.map +1 -1
  325. package/lib/zhin-agent/prompt.js +4 -0
  326. package/lib/zhin-agent/prompt.js.map +1 -1
  327. package/lib/zhin-agent/session-io.d.ts +28 -11
  328. package/lib/zhin-agent/session-io.d.ts.map +1 -1
  329. package/lib/zhin-agent/session-io.js +64 -28
  330. package/lib/zhin-agent/session-io.js.map +1 -1
  331. package/lib/zhin-agent/session-message-queue.d.ts +20 -0
  332. package/lib/zhin-agent/session-message-queue.d.ts.map +1 -0
  333. package/lib/zhin-agent/session-message-queue.js +52 -0
  334. package/lib/zhin-agent/session-message-queue.js.map +1 -0
  335. package/lib/zhin-agent/session-tree-commands.d.ts +5 -0
  336. package/lib/zhin-agent/session-tree-commands.d.ts.map +1 -0
  337. package/lib/zhin-agent/session-tree-commands.js +44 -0
  338. package/lib/zhin-agent/session-tree-commands.js.map +1 -0
  339. package/lib/zhin-agent/tool-calls-user-format.d.ts.map +1 -1
  340. package/lib/zhin-agent/tool-calls-user-format.js +3 -0
  341. package/lib/zhin-agent/tool-calls-user-format.js.map +1 -1
  342. package/lib/zhin-agent/tool-orchestration.d.ts.map +1 -1
  343. package/lib/zhin-agent/tool-orchestration.js +25 -6
  344. package/lib/zhin-agent/tool-orchestration.js.map +1 -1
  345. package/lib/zhin-agent/tool-runtime.d.ts +2 -2
  346. package/lib/zhin-agent/tool-runtime.d.ts.map +1 -1
  347. package/lib/zhin-agent/tool-runtime.js +4 -4
  348. package/lib/zhin-agent/tool-runtime.js.map +1 -1
  349. package/lib/zhin-agent/tool-search-orchestrator.d.ts.map +1 -1
  350. package/lib/zhin-agent/tool-search-orchestrator.js +13 -0
  351. package/lib/zhin-agent/tool-search-orchestrator.js.map +1 -1
  352. package/lib/zhin-agent/turn-context.d.ts +9 -0
  353. package/lib/zhin-agent/turn-context.d.ts.map +1 -0
  354. package/lib/zhin-agent/turn-context.js +12 -0
  355. package/lib/zhin-agent/turn-context.js.map +1 -0
  356. package/lib/zhin-agent/turn-pipeline.d.ts +7 -1
  357. package/lib/zhin-agent/turn-pipeline.d.ts.map +1 -1
  358. package/lib/zhin-agent/turn-pipeline.js +136 -450
  359. package/lib/zhin-agent/turn-pipeline.js.map +1 -1
  360. package/lib/zhin-agent/turn-user-message.d.ts +8 -0
  361. package/lib/zhin-agent/turn-user-message.d.ts.map +1 -0
  362. package/lib/zhin-agent/turn-user-message.js +10 -0
  363. package/lib/zhin-agent/turn-user-message.js.map +1 -0
  364. package/lib/zhin-agent/zhin-agent-private.d.ts +17 -4
  365. package/lib/zhin-agent/zhin-agent-private.d.ts.map +1 -1
  366. package/lib/zhin-agent/zhin-agent-private.js.map +1 -1
  367. package/package.json +4 -3
  368. package/lib/zhin-agent/llm-runner.d.ts +0 -18
  369. package/lib/zhin-agent/llm-runner.d.ts.map +0 -1
  370. package/lib/zhin-agent/llm-runner.js +0 -163
  371. package/lib/zhin-agent/llm-runner.js.map +0 -1
package/README.md CHANGED
@@ -6,19 +6,20 @@ Zhin AI Agent 组合层:在 `@zhin.js/core` 的类型与 Provider 之上,提
6
6
 
7
7
  ## 功能特性
8
8
 
9
- - 🤖 **Agent 循环**:`Agent` / `createAgent`,支持工具调用、迭代与事件
9
+ - 🤖 **agentLoop 统一路径**:ZhinAgent、Subagent、Deferred Worker、AIService 均经 `agentLoop`(legacy `Agent.run` 仅保留在 `@zhin.js/ai` 供单测)
10
10
  - 📝 **会话管理**:`SessionManager`、内存/数据库会话、`SessionManager.generateId`
11
11
  - 🧠 **ZhinAgent**:与 Zhin 消息流集成的智能体(SOUL/TOOLS/AGENTS、工具收集、执行策略)
12
- - 🔍 **模型自动发现**:通过 `@zhin.js/ai` `ModelRegistry`(本包 re-export AI 原语,不单独导出 Registry)
13
- - 🔄 **模型自动降级**:首选模型失败时自动切换到次优模型,支持 Chat / Vision / Agent 三条路径
12
+ - 🔍 **模型自动发现**:`ModelRegistry` 调用 `listModels()`(OpenAI 兼容 `/v1/models`、Ollama `/api/tags`);结果写入 `provider.models` 并供 `getModel()` 校验;yaml 显式 `models` 时以配置为准
13
+ - 🔄 **模型自动降级**:首选模型失败时按 `resolveModelCandidates` 候选链 fallback(文本 / 多模态 / standalone 均走 agentLoop)
14
14
  - 🛡️ **6 层 Bash 安全**:`ExecPolicy` 纵深防御(危险黑名单、环境变量剥离、wrapper 剥离、复合命令拆分、只读放行、交互式审批)
15
15
  - 📂 **文件访问安全**:`FilePolicy` 路径检查、设备路径拦截、命令读写分类
16
16
  - 📋 **精简系统提示词**:`PromptBuilder` 组装 Context、Style、Tools、Safety,并按需注入 Platform、Skills、Memory、Bootstrap
17
17
  - 🔌 **框架挂载**:`initAgentModule()` 注册 `ctx.ai`、`ctx.agent`、定时任务、DB 模型等
18
- - 📦 **上下文与记忆**:`ContextManager`、`ConversationMemory`、`UserProfileStore`
18
+ - 📦 **上下文与记忆**:`ContextRepository`(`agent_messages`)、`AgentSessionStore`、`ImTranscriptStore`(`im_transcripts` + `chat_history`);辅助:`ContextManager`、`ConversationMemory`、`UserProfileStore`
19
19
  - ⏰ **跟进与定时**:`FollowUpManager`、`PersistentCronEngine`、cron 工具
20
- - 🔧 **内置工具**:bash、read_file、write_file、ask_user、web_searchchat_history
21
- - 📐 **会话压缩**:`compactSession`、token 估算、总结与裁剪
20
+ - 🔧 **内置工具**:bash、read_file、write_file、ask_user、web_search、`chat_history`(按关键词/最近条数查 `im_transcripts`)等
21
+ - 📐 **Compaction(ADR 0010)**:生产 `agentLoop` 接线 L1 micro + L2 LLM;IM `/compact`;yaml `ai.agent.compaction`
22
+ - 🌳 **会话树**:`parent_id` + `active_leaf`;IM `/tree`、`/reset`;branch summarization;Console `GET/POST /api/agent/sessions/...`
22
23
  - 🪝 **Hook 系统**:`registerAIHook`、`triggerAIHook` 等
23
24
 
24
25
  ## 依赖关系
@@ -44,8 +45,6 @@ npm install zhin.js
44
45
  import {
45
46
  initAgentModule,
46
47
  ZhinAgent,
47
- Agent,
48
- createAgent,
49
48
  AIService,
50
49
  SessionManager,
51
50
  registerAIHook,
@@ -64,16 +63,19 @@ useContext('ai', async (ai) => {
64
63
  仅在需要单独集成 Agent 能力时使用:
65
64
 
66
65
  ```javascript
67
- import { initAgentModule, createAgent, AIService } from '@zhin.js/agent'
66
+ import { initAgentModule, AIService } from '@zhin.js/agent'
68
67
  import { OllamaProvider } from '@zhin.js/core'
69
68
 
70
- // 初始化(需先有 DatabaseFeature 等)
71
69
  initAgentModule()
72
70
 
73
- // 低层 Agent
74
- const provider = new OllamaProvider({ baseUrl: 'http://localhost:11434' })
75
- const agent = createAgent(provider, { tools: [], systemPrompt: '你是一个助手' })
76
- const result = await agent.run('你好')
71
+ // 程序化 Agent(agentLoop 隔离 context)
72
+ useContext('ai', async (ai) => {
73
+ const result = await ai.runAgent('你好', {
74
+ provider: 'ollama',
75
+ systemPrompt: '你是一个助手',
76
+ })
77
+ console.log(result.content)
78
+ })
77
79
  ```
78
80
 
79
81
  ## 核心导出
@@ -81,13 +83,13 @@ const result = await agent.run('你好')
81
83
  | 类别 | 导出 |
82
84
  |------|------|
83
85
  | 初始化 | `initAgentModule` |
84
- | Agent | `Agent`, `createAgent`, `formatToolTitle` |
86
+ | Agent | `ServiceAgent`、`CreateServiceAgentOptions`(`AIService.createAgent`);legacy `Agent` / `createAgent` re-export 自 `@zhin.js/ai` |
85
87
  | Model harness | `MODEL_HARNESS_DEFAULTS`, `resolveModelHarness`, `mergeModelHarnessValues` |
86
88
  | 服务与会话 | `AIService`, `SessionManager`, `MemorySessionManager`, `DatabaseSessionManager`, `createMemorySessionManager`, `createDatabaseSessionManager` |
87
89
  | ZhinAgent | `ZhinAgent`,以及 config / exec-policy / file-policy / tool-runtime / prompt / builtin-tools 等子模块 |
88
90
  | 安全策略 | `checkExecPolicy`, `applyExecPolicyToTools`, `isDangerousCommand`, `stripEnvVarPrefix`, `stripSafeWrappers`, `splitCompoundCommand`, `extractCommandName`, `ExecPolicyResult`, `checkFileAccess`, `classifyBashCommand`, `isBlockedDevicePath` |
89
91
  | 提示词构建 | `buildRichSystemPrompt`, `buildEnhancedPersona`, `buildUserMessageWithHistory`, `buildContextHint` |
90
- | 上下文与记忆 | `ContextManager`, `createContextManager`, `ConversationMemory`, `UserProfileStore` |
92
+ | 上下文与记忆 | `ContextRepository`, `AgentSessionStore`, `ImTranscriptStore`(经 ZhinAgent 注入);`ContextManager`, `ConversationMemory`, `UserProfileStore` |
91
93
  | 跟进与定时 | `FollowUpManager`, `PersistentCronEngine`, `createCronTools`, `setCronManager`, `getCronManager` |
92
94
  | 压缩与 Bootstrap | `compactSession`, `estimateTokens`, `loadBootstrapFiles`, `loadSoulPersona`, `loadToolsGuide`, `loadAgentsMemory` |
93
95
  | Hook | `registerAIHook`, `unregisterAIHook`, `triggerAIHook`, `createAIHookEvent` |
@@ -118,7 +120,7 @@ declare module '@zhin.js/core' {
118
120
 
119
121
  | Context | 用途 |
120
122
  |---------|------|
121
- | `ctx.ai` | 业务侧 AI 服务:会话、`createAgent` / `runAgent`、全局 ZhinAgent |
123
+ | `ctx.ai` | 业务侧 AI 服务:会话、`createAgent`(→ `ServiceAgent`)/ `runAgent`、全局 ZhinAgent |
122
124
  | `ctx.agent` | 扩展编排资源:`orchestrator.addTool`、`addSkill`、`addMcp` 等;内置注册走 `root.inject('agent')` |
123
125
 
124
126
  主包 `zhin.js` 的 `Plugin.Contexts` 类型已包含上述两项。
@@ -127,7 +129,7 @@ declare module '@zhin.js/core' {
127
129
 
128
130
  默认**不**注册 `@modelcontextprotocol/server-memory`;设 `ai.memoryMcp: true` 启用(`data/knowledge-graph.jsonl`)。另可通过 `ai.mcpServers`(或 `ctx.agent.addMcp`)注册更多 Server;每次 AI 回合前懒连接,`mcp_{server}_{tool}` 并入 ZhinAgent 工具池。需可选安装 `@modelcontextprotocol/sdk`(peer dependency)。
129
131
 
130
- **记忆**:内置 `read_memory` / `write_memory` 已移除,请使用 `mcp_memory_read_graph`、`mcp_memory_create_entities` 等。工作区 `AGENTS.md` 仍由 bootstrap 注入。
132
+ **记忆**:默认 **文件三层**(`ai.memory` → `data/memory/`);内置 `read_memory` / `write_memory` 已移除。`ai.memoryMcp: true` 时另注册 MCP 图谱(弃用路径)。工作区 `AGENTS.md` / `TOOLS.md` 由 bootstrap 注入。
131
133
 
132
134
  ```yaml
133
135
  ai:
@@ -155,23 +157,20 @@ ai:
155
157
 
156
158
  ### 2. 用 AIService 创建多个不同配置的 Agent
157
159
 
158
- `ctx.ai`(AIService)可以按需创建**多个互不共享状态的 Agent**,每个可指定不同 provider、model、systemPrompt、tools
160
+ `ctx.ai`(AIService)可以按需创建**多个互不共享状态的 Agent**(`ServiceAgent`),每个可指定不同 provider、model、systemPrompt、tools;底层均为 **`runAgentLoopStandaloneTurn`**:
159
161
 
160
162
  ```javascript
161
163
  import { useContext } from 'zhin.js'
162
164
 
163
165
  useContext('ai', async (ai) => {
164
- // 专用「代码助手」Agent
165
166
  const codeAgent = ai.createAgent({
166
167
  provider: 'openai',
167
168
  model: 'gpt-4o',
168
169
  systemPrompt: '你只负责代码审查与建议,不闲聊。',
169
170
  useBuiltinTools: true,
170
- tools: [/* 可选:额外工具 */],
171
171
  })
172
172
  const codeResult = await codeAgent.run('审查这段 TypeScript 的类型安全')
173
173
 
174
- // 专用「翻译」Agent,不用内置工具
175
174
  const translateAgent = ai.createAgent({
176
175
  provider: 'ollama',
177
176
  model: 'qwen2.5',
@@ -201,7 +200,7 @@ useContext('ai', async (ai) => {
201
200
 
202
201
  ### 4. 多 Agent 协作/编排(由 zhin.js 层实现)
203
202
 
204
- 本包只提供基础能力:`createAgent`、`ZhinAgent`、`ai.createAgent` 等。**多 Agent 串联/并联编排**(例如 A 的输出作为 B 的输入、按条件路由到不同专业 Agent)以及**按 bot / 按群组配置多个 ZhinAgent** 的调度与路由,将在 **zhin.js 主包**实现;插件侧通过 zhin.js 暴露的 API 使用即可,无需在业务里手写多实例维护与路由逻辑。
203
+ 本包只提供基础能力:`ZhinAgent`、`ai.createAgent`(`ServiceAgent`)、`ai.runAgent` 等。**多 Agent 串联/并联编排**(例如 A 的输出作为 B 的输入、按条件路由到不同专业 Agent)在 **zhin.js 主包** `runPipeline` / `runParallel` / `route` 实现;插件侧通过 zhin.js 暴露的 API 使用即可。
205
204
 
206
205
  ## 工具命名策略
207
206
 
@@ -209,6 +208,60 @@ useContext('ai', async (ai) => {
209
208
  - 非保留工具同名时采用 **后注册覆盖前注册**。
210
209
  - 冲突统一以 warn 记录:包含 `name`、`source`、`action`(`ignored`/`overridden`)。
211
210
 
211
+ ## Provider 与模型列表
212
+
213
+ `AIService` 构造时:
214
+
215
+ 1. 按 `ai.providers.<别名>` 实例化 Provider(须配置 `api`,如 `openai-completions`)。
216
+ 2. `registerLlmApiFromProviders`:**未写 `models` 的 provider** 在 ApiRegistry 注册为空白名单,由后台 `ModelRegistry.discover()` 填充 `provider.models`;**写了 `models`** 则用 yaml 白名单。
217
+ 3. `createZhinAgent` 启动时 `loadCache()` 先恢复上次发现结果,再异步刷新 `/v1/models`。
218
+
219
+ `agents.<name>.model`(如 `mimo-v2.5-pro`)须在发现列表中,或在中转 API 的 `/v1/models` 响应里出现;无需为每个模型手写 yaml,除非要锁定白名单。
220
+
221
+ ```yaml
222
+ ai:
223
+ providers:
224
+ openai-main:
225
+ api: openai-completions
226
+ baseUrl: ${OPENAI_BASE_URL}
227
+ apiKey: ${OPENAI_API_KEY}
228
+ # models 省略 → 自动 GET /v1/models
229
+ cloudflare-flash:
230
+ api: cloudflare-workers-ai
231
+ models: ["@cf/zai-org/glm-4.7-flash"] # 显式列表
232
+ agents:
233
+ zhin:
234
+ provider: openai-main
235
+ model: mimo-v2.5-pro
236
+ ```
237
+
238
+ ## Provider 与模型列表
239
+
240
+ `AIService` 构造时:
241
+
242
+ 1. 按 `ai.providers.<别名>` 实例化 Provider(须配置 `api`,如 `openai-completions`)。
243
+ 2. `registerLlmApiFromProviders`:**未写 `models` 的 provider** 在 ApiRegistry 注册为空白名单,由后台 `ModelRegistry.discover()` 填充 `provider.models`;**写了 `models`** 则用 yaml 白名单。
244
+ 3. `createZhinAgent` 启动时 `loadCache()` 先恢复上次发现结果,再异步刷新 `/v1/models`。
245
+
246
+ `agents.<name>.model`(如 `mimo-v2.5-pro`)须在发现列表中,或在中转 API 的 `/v1/models` 响应里出现;无需为每个模型手写 yaml,除非要锁定白名单。
247
+
248
+ ```yaml
249
+ ai:
250
+ providers:
251
+ openai-main:
252
+ api: openai-completions
253
+ baseUrl: ${OPENAI_BASE_URL}
254
+ apiKey: ${OPENAI_API_KEY}
255
+ # models 省略 → 自动 GET /v1/models
256
+ cloudflare-flash:
257
+ api: cloudflare-workers-ai
258
+ models: ["@cf/zai-org/glm-4.7-flash"] # 显式列表
259
+ agents:
260
+ zhin:
261
+ provider: openai-main
262
+ model: mimo-v2.5-pro
263
+ ```
264
+
212
265
  ## Model harness
213
266
 
214
267
  按 provider / model 覆盖 Agent 循环默认参数(当前主要为 **`maxIterations`**)。
@@ -237,6 +290,18 @@ ai:
237
290
 
238
291
  增补内置默认值:在 `model-harness.ts` 增加 `ModelHarnessRow` 并附测试;YAML 只做覆盖,不替代 TS 约定层。
239
292
 
293
+ ## IM 管理命令
294
+
295
+ 由 `register-management-tools.ts` / `register-introspection-commands.ts` 注册(master / 有权限用户):
296
+
297
+ | 类别 | 命令 |
298
+ |------|------|
299
+ | 会话 | `/compact` · `/tree` · `/tree N` · `/reset` |
300
+ | 运维 | `/models` · `/health` |
301
+ | 内省 | `/cmd` · `/bots` · `/bindings` · `/tools` · `/mcp` |
302
+
303
+ zhin-package CLI:`zhin packages`(`basic/cli`)。详见 [ADR 0010](../../docs/adr/0010-pi-coding-agent-harness-alignment.md)。
304
+
240
305
  ## 开发
241
306
 
242
307
  ### 项目结构
@@ -267,7 +332,7 @@ src/
267
332
  │ ├── config.ts
268
333
  │ ├── prompt.ts
269
334
  │ ├── tool-runtime.ts # 运行时工具收集与执行路径规划
270
- │ └── context-tools.ts # chat_history, user_profile, spawn_task
335
+ │ └── builtin-tools.ts # chat_history(im_transcripts), user_profile, spawn_task
271
336
 
272
337
  ├── discovery/ # ★ 文件化资源发现
273
338
  │ ├── index.ts
@@ -0,0 +1,2 @@
1
+ export declare function createMemorySearchTool(): import("@zhin.js/core").Tool<Record<string, any>>;
2
+ //# sourceMappingURL=memory-search-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-search-tool.d.ts","sourceRoot":"","sources":["../../src/builtin/memory-search-tool.ts"],"names":[],"mappings":"AAoEA,wBAAgB,sBAAsB,sDAErC"}
@@ -0,0 +1,61 @@
1
+ import { resolveIMSessionIdFromToolContext } from '@zhin.js/ai';
2
+ import { parseMemoryTags } from '@zhin.js/ai';
3
+ import { BuiltinBaseTool } from './builtin-base-tool.js';
4
+ import { getMemoryEntryRepository } from '../memory-entry-registry.js';
5
+ const PARAMS = {
6
+ type: 'object',
7
+ properties: {
8
+ query: { type: 'string', description: '检索关键词或短语' },
9
+ scope: {
10
+ type: 'string',
11
+ enum: ['global', 'platform', 'session', 'user'],
12
+ description: '可选:限定记忆范围',
13
+ },
14
+ limit: { type: 'number', description: '最多返回条数(默认 5)' },
15
+ },
16
+ required: ['query'],
17
+ };
18
+ function sessionScopeKey(ctx) {
19
+ return resolveIMSessionIdFromToolContext({
20
+ platform: ctx.platform || '',
21
+ botId: ctx.botId || '',
22
+ scope: ctx.scope,
23
+ sceneId: ctx.sceneId || '',
24
+ senderId: ctx.senderId || '',
25
+ });
26
+ }
27
+ class MemorySearchTool extends BuiltinBaseTool {
28
+ name = 'memory_search';
29
+ description = '在语义记忆库中检索与 query 相关的事实条目(memory_entries)。';
30
+ parameters = PARAMS;
31
+ keywords = ['memory', 'recall', 'remember', '记忆', '回忆'];
32
+ async run(args, context) {
33
+ const repo = getMemoryEntryRepository();
34
+ if (!repo)
35
+ return '语义记忆未启用(ai.memory.semantic.enabled)或未初始化数据库。';
36
+ const query = String(args.query ?? '').trim();
37
+ if (!query)
38
+ return '请提供 query';
39
+ const scope = typeof args.scope === 'string' ? args.scope : undefined;
40
+ const limit = typeof args.limit === 'number' ? args.limit : 5;
41
+ const scopeKey = scope === 'session' && context ? sessionScopeKey(context) : undefined;
42
+ const hits = await repo.search({
43
+ query,
44
+ scope: scope,
45
+ scope_key: scopeKey,
46
+ limit,
47
+ });
48
+ if (!hits.length)
49
+ return `未找到与 "${query}" 相关的记忆条目。`;
50
+ const lines = hits.map((e) => {
51
+ const tags = parseMemoryTags(e.tags);
52
+ return `- [${e.scope}${e.scope_key ? `:${e.scope_key}` : ''}] ${e.key}=${e.content}`
53
+ + (tags.length ? ` (tags: ${tags.join(', ')})` : '');
54
+ });
55
+ return `找到 ${hits.length} 条记忆:\n${lines.join('\n')}`;
56
+ }
57
+ }
58
+ export function createMemorySearchTool() {
59
+ return new MemorySearchTool().toTool();
60
+ }
61
+ //# sourceMappingURL=memory-search-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-search-tool.js","sourceRoot":"","sources":["../../src/builtin/memory-search-tool.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAEvE,MAAM,MAAM,GAAyB;IACnC,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE;QAClD,KAAK,EAAE;YACL,IAAI,EAAE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upsert-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-upsert-tool.d.ts","sourceRoot":"","sources":["../../src/builtin/memory-upsert-tool.ts"],"names":[],"mappings":"AAkFA,wBAAgB,sBAAsB,sDAErC"}
@@ -0,0 +1,75 @@
1
+ import { resolveIMSessionIdFromToolContext } from '@zhin.js/ai';
2
+ import { BuiltinBaseTool } from './builtin-base-tool.js';
3
+ import { getMemoryEntryRepository } from '../memory-entry-registry.js';
4
+ const PARAMS = {
5
+ type: 'object',
6
+ properties: {
7
+ key: { type: 'string', description: '记忆键(如 capability:hard_orchestration_v1)' },
8
+ content: { type: 'string', description: '记忆内容(简短事实陈述)' },
9
+ scope: {
10
+ type: 'string',
11
+ enum: ['global', 'platform', 'session', 'user'],
12
+ description: '范围,默认 global',
13
+ },
14
+ tags: {
15
+ type: 'array',
16
+ items: { type: 'string' },
17
+ description: '可选标签',
18
+ },
19
+ source: { type: 'string', description: '来源说明(如 skill:memory-consolidate)' },
20
+ confidence: { type: 'number', description: '置信度 0–1,默认 1' },
21
+ },
22
+ required: ['key', 'content'],
23
+ };
24
+ function sessionScopeKey(ctx) {
25
+ return resolveIMSessionIdFromToolContext({
26
+ platform: ctx.platform || '',
27
+ botId: ctx.botId || '',
28
+ scope: ctx.scope,
29
+ sceneId: ctx.sceneId || '',
30
+ senderId: ctx.senderId || '',
31
+ });
32
+ }
33
+ class MemoryUpsertTool extends BuiltinBaseTool {
34
+ name = 'memory_upsert';
35
+ description = '写入或更新一条语义记忆(memory_entries),供 memory_search 召回。';
36
+ parameters = PARAMS;
37
+ keywords = ['memory', 'remember', 'store', '记忆', '记住'];
38
+ async run(args, context) {
39
+ const repo = getMemoryEntryRepository();
40
+ if (!repo)
41
+ return '语义记忆未启用(ai.memory.semantic.enabled)或未初始化数据库。';
42
+ const key = String(args.key ?? '').trim();
43
+ const content = String(args.content ?? '').trim();
44
+ if (!key || !content)
45
+ return '请提供 key 与 content';
46
+ const scope = (typeof args.scope === 'string' ? args.scope : 'global');
47
+ let scopeKey = '';
48
+ if (scope === 'session' && context) {
49
+ scopeKey = sessionScopeKey(context);
50
+ }
51
+ else if (scope === 'platform' && context?.platform) {
52
+ scopeKey = context.platform;
53
+ }
54
+ else if (scope === 'user' && context?.senderId) {
55
+ scopeKey = context.senderId;
56
+ }
57
+ const tags = Array.isArray(args.tags) ? args.tags.map(String) : undefined;
58
+ const source = typeof args.source === 'string' ? args.source : 'tool:memory_upsert';
59
+ const confidence = typeof args.confidence === 'number' ? args.confidence : 1;
60
+ const record = await repo.upsert({
61
+ scope,
62
+ scope_key: scopeKey,
63
+ key,
64
+ content,
65
+ tags,
66
+ source,
67
+ confidence,
68
+ });
69
+ return `已写入记忆 ${record.id}: [${record.scope}] ${record.key}=${record.content}`;
70
+ }
71
+ }
72
+ export function createMemoryUpsertTool() {
73
+ return new MemoryUpsertTool().toTool();
74
+ }
75
+ //# sourceMappingURL=memory-upsert-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-upsert-tool.js","sourceRoot":"","sources":["../../src/builtin/memory-upsert-tool.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAGvE,MAAM,MAAM,GAAyB;IACnC,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,yCAAyC,EAAE;QAC/E,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE;QACxD,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC;YAC/C,WAAW,EAAE,cAAc;SAC5B;QACD,IAAI,EAAE;YAC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KAAK,KAAK,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;IACjF,CAAC;CACF;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,IAAI,gBAAgB,EAAE,CAAC,MAAM,EAAE,CAAC;AACzC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Project director orchestration tools — Agent Mesh hard orchestration v1.
3
+ */
4
+ import type { AgentTool, ToolContext } from '@zhin.js/core';
5
+ export declare function createOrchestrationTools(context: ToolContext): AgentTool[];
6
+ export declare const ORCHESTRATION_TOOL_NAMES: readonly ["orchestration_start", "orchestration_add_task", "orchestration_status", "orchestration_complete", "orchestration_retry_task", "orchestration_skip_task", "orchestration_patch_state"];
7
+ //# sourceMappingURL=orchestration-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestration-tools.d.ts","sourceRoot":"","sources":["../../src/builtin/orchestration-tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAoC,MAAM,eAAe,CAAC;AAyR9F,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,CAU1E;AAED,eAAO,MAAM,wBAAwB,kMAQ3B,CAAC"}