@ai-setting/roy-agent-core 1.7.52 → 1.7.53

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 (334) hide show
  1. package/dist/config/config-component.d.ts +346 -0
  2. package/dist/config/config-parser.d.ts +45 -0
  3. package/dist/config/env-key.d.ts +97 -0
  4. package/dist/config/env-source.d.ts +113 -0
  5. package/dist/config/file-source.d.ts +90 -0
  6. package/dist/config/index.d.ts +4 -0
  7. package/dist/config/protocol-resolver.d.ts +94 -0
  8. package/dist/env/agent/agent-component.d.ts +646 -0
  9. package/dist/env/agent/agent-config-registration.d.ts +18 -0
  10. package/dist/env/agent/agent-registry.d.ts +500 -0
  11. package/dist/env/agent/index.d.ts +9 -0
  12. package/dist/env/agent/summary-agent.d.ts +44 -0
  13. package/dist/env/agent/types.d.ts +503 -0
  14. package/dist/env/commands/commands-component.d.ts +97 -0
  15. package/dist/env/commands/commands-config-registration.d.ts +19 -0
  16. package/dist/env/commands/index.d.ts +7 -0
  17. package/dist/env/commands/parser.d.ts +18 -0
  18. package/dist/env/commands/types.d.ts +133 -0
  19. package/dist/env/component.d.ts +186 -0
  20. package/dist/env/constants.d.ts +112 -0
  21. package/dist/env/context/env-context.d.ts +420 -0
  22. package/dist/env/context/env-event.d.ts +144 -0
  23. package/dist/env/context/index.d.ts +13 -0
  24. package/dist/env/debug/debug-component.d.ts +160 -0
  25. package/dist/env/debug/formatters/index.d.ts +8 -0
  26. package/dist/env/debug/formatters/repl-formatter.d.ts +80 -0
  27. package/dist/env/debug/formatters/trace-formatter.d.ts +43 -0
  28. package/dist/env/debug/formatters/tree-formatter.d.ts +72 -0
  29. package/dist/env/debug/index.d.ts +15 -0
  30. package/dist/env/debug/index.js +1 -1
  31. package/dist/env/debug/parser/regex-parser.d.ts +49 -0
  32. package/dist/env/debug/parser/span-builder.d.ts +79 -0
  33. package/dist/env/debug/reader/log-reader.d.ts +55 -0
  34. package/dist/env/debug/reader/span-db-reader.d.ts +70 -0
  35. package/dist/env/debug/types.d.ts +145 -0
  36. package/dist/env/environment.d.ts +185 -0
  37. package/dist/env/errors.d.ts +120 -0
  38. package/dist/env/event-source/bounty-cli-handler.d.ts +42 -0
  39. package/dist/env/event-source/bounty-im-handler.d.ts +232 -0
  40. package/dist/env/event-source/event-source-component.d.ts +177 -0
  41. package/dist/env/event-source/event-source-config-registration.d.ts +18 -0
  42. package/dist/env/event-source/event-source-handlers.d.ts +486 -0
  43. package/dist/env/event-source/event-store.d.ts +110 -0
  44. package/dist/env/event-source/idempotency-key.d.ts +19 -0
  45. package/dist/env/event-source/index.d.ts +15 -0
  46. package/dist/env/event-source/index.js +2 -2
  47. package/dist/env/event-source/timer-handler.d.ts +74 -0
  48. package/dist/env/event-source/types.d.ts +803 -0
  49. package/dist/env/hook/global-hook-manager.d.ts +73 -0
  50. package/dist/env/hook/hook-manager.d.ts +139 -0
  51. package/dist/env/hook/index.d.ts +9 -0
  52. package/dist/env/hook/types.d.ts +107 -0
  53. package/dist/env/index.d.ts +24 -0
  54. package/dist/env/index.js +4 -4
  55. package/dist/env/interface.d.ts +156 -0
  56. package/dist/env/lark-mention-utils.d.ts +59 -0
  57. package/dist/env/llm/adapter-ai-sdk.d.ts +10 -0
  58. package/dist/env/llm/adapter-pi-ai.d.ts +39 -0
  59. package/dist/env/llm/adapter.d.ts +80 -0
  60. package/dist/env/llm/factory.d.ts +13 -0
  61. package/dist/env/llm/hooks.d.ts +150 -0
  62. package/dist/env/llm/index.d.ts +16 -0
  63. package/dist/env/llm/invoke.d.ts +264 -0
  64. package/dist/env/llm/llm-cache.d.ts +38 -0
  65. package/dist/env/llm/llm.d.ts +238 -0
  66. package/dist/env/llm/opencode-session.d.ts +79 -0
  67. package/dist/env/llm/provider.d.ts +40 -0
  68. package/dist/env/llm/tool-args-parser.d.ts +77 -0
  69. package/dist/env/llm/tool-schema.d.ts +54 -0
  70. package/dist/env/llm/transform.d.ts +57 -0
  71. package/dist/env/llm/types.d.ts +818 -0
  72. package/dist/env/log-trace/decorator.d.ts +88 -0
  73. package/dist/env/log-trace/index.d.ts +14 -0
  74. package/dist/env/log-trace/log-trace-component.d.ts +268 -0
  75. package/dist/env/log-trace/log-trace-config-registration.d.ts +25 -0
  76. package/dist/env/log-trace/logger.d.ts +83 -0
  77. package/dist/env/log-trace/opentelemetry/cli-propagation.d.ts +105 -0
  78. package/dist/env/log-trace/opentelemetry/mod.d.ts +24 -0
  79. package/dist/env/log-trace/opentelemetry/propagation-env.d.ts +81 -0
  80. package/dist/env/log-trace/opentelemetry/propagation.d.ts +79 -0
  81. package/dist/env/log-trace/opentelemetry/tracer-provider.d.ts +157 -0
  82. package/dist/env/log-trace/span-storage.d.ts +37 -0
  83. package/dist/env/log-trace/trace-context.d.ts +28 -0
  84. package/dist/env/log-trace/types.d.ts +127 -0
  85. package/dist/env/mcp/command-resolver.d.ts +12 -0
  86. package/dist/env/mcp/config.d.ts +103 -0
  87. package/dist/env/mcp/index.d.ts +13 -0
  88. package/dist/env/mcp/loader.d.ts +78 -0
  89. package/dist/env/mcp/mcp-component.d.ts +54 -0
  90. package/dist/env/mcp/mcp-config-registration.d.ts +19 -0
  91. package/dist/env/mcp/npm-prefix/index.d.ts +17 -0
  92. package/dist/env/mcp/scanner.d.ts +38 -0
  93. package/dist/env/mcp/tool/adapter.d.ts +32 -0
  94. package/dist/env/mcp/tool/index.d.ts +4 -0
  95. package/dist/env/mcp/types.d.ts +131 -0
  96. package/dist/env/memory/built-in/index.d.ts +41 -0
  97. package/dist/env/memory/built-in/recall-memory.d.ts +29 -0
  98. package/dist/env/memory/built-in/record-memory.d.ts +44 -0
  99. package/dist/env/memory/index.d.ts +10 -0
  100. package/dist/env/memory/memory-component.d.ts +114 -0
  101. package/dist/env/memory/memory-config-registration.d.ts +18 -0
  102. package/dist/env/memory/memory-config.d.ts +18 -0
  103. package/dist/env/memory/plugin/index.d.ts +16 -0
  104. package/dist/env/memory/plugin/memory-agent.d.ts +126 -0
  105. package/dist/env/memory/plugin/memory-manager.d.ts +71 -0
  106. package/dist/env/memory/plugin/memory-plugin.d.ts +103 -0
  107. package/dist/env/memory/plugin/recall-memory.d.ts +16 -0
  108. package/dist/env/memory/plugin/types.d.ts +75 -0
  109. package/dist/env/memory/tools/memory-agent-tools.d.ts +109 -0
  110. package/dist/env/memory/types.d.ts +80 -0
  111. package/dist/env/paths.d.ts +46 -0
  112. package/dist/env/plugin/bounty-cli-notification-channel.d.ts +60 -0
  113. package/dist/env/plugin/event-bus-notification-channel.d.ts +50 -0
  114. package/dist/env/plugin/index.d.ts +13 -0
  115. package/dist/env/plugin/lark-cli-notification-channel.d.ts +61 -0
  116. package/dist/env/plugin/notification-channel.d.ts +143 -0
  117. package/dist/env/plugin/plugin-component.d.ts +232 -0
  118. package/dist/env/plugin/types.d.ts +146 -0
  119. package/dist/env/prompt/index.d.ts +7 -0
  120. package/dist/env/prompt/prompt-component.d.ts +194 -0
  121. package/dist/env/prompt/prompt-config-registration.d.ts +18 -0
  122. package/dist/env/prompt/prompt-store.d.ts +26 -0
  123. package/dist/env/prompt/prompts-index.d.ts +146 -0
  124. package/dist/env/prompt/renderer.d.ts +21 -0
  125. package/dist/env/prompt/types.d.ts +176 -0
  126. package/dist/env/session/hooks.d.ts +14 -0
  127. package/dist/env/session/index.d.ts +19 -0
  128. package/dist/env/session/search-query-parser.d.ts +41 -0
  129. package/dist/env/session/session-component.d.ts +464 -0
  130. package/dist/env/session/session-config-registration.d.ts +18 -0
  131. package/dist/env/session/session-id.d.ts +26 -0
  132. package/dist/env/session/session-message-converter.d.ts +142 -0
  133. package/dist/env/session/session-store.d.ts +188 -0
  134. package/dist/env/session/storage/index.d.ts +5 -0
  135. package/dist/env/session/storage/memory.d.ts +119 -0
  136. package/dist/env/session/storage/sqlite.d.ts +108 -0
  137. package/dist/env/session/types.d.ts +705 -0
  138. package/dist/env/session-tree-stopper.d.ts +79 -0
  139. package/dist/env/skill/config.d.ts +13 -0
  140. package/dist/env/skill/index.d.ts +6 -0
  141. package/dist/env/skill/parser.d.ts +9 -0
  142. package/dist/env/skill/scanner.d.ts +25 -0
  143. package/dist/env/skill/skill-component.d.ts +89 -0
  144. package/dist/env/skill/skill-config-registration.d.ts +18 -0
  145. package/dist/env/skill/tool/index.d.ts +1 -0
  146. package/dist/env/skill/tool/skill-tool.d.ts +15 -0
  147. package/dist/env/skill/types.d.ts +61 -0
  148. package/dist/env/task/backend/index.d.ts +24 -0
  149. package/dist/env/task/backend/index.js +704 -0
  150. package/dist/env/task/backend/roy-sidecar-task-port.d.ts +148 -0
  151. package/dist/env/task/backend/sqlite-task-port.d.ts +28 -0
  152. package/dist/env/task/backend/task-store-backend.d.ts +107 -0
  153. package/dist/env/task/backend/types.d.ts +293 -0
  154. package/dist/env/task/delegate/bg-task-id-storage.d.ts +9 -0
  155. package/dist/env/task/delegate/delegate-tool.d.ts +681 -0
  156. package/dist/env/task/delegate/index.d.ts +8 -0
  157. package/dist/env/task/delegate/process-registry.d.ts +58 -0
  158. package/dist/env/task/delegate/stop-tool.d.ts +12 -0
  159. package/dist/env/task/delegate/subagent-resolver.d.ts +25 -0
  160. package/dist/env/task/events/index.d.ts +7 -0
  161. package/dist/env/task/events/task-event-payloads.d.ts +101 -0
  162. package/dist/env/task/events/task-event-types.d.ts +23 -0
  163. package/dist/env/task/hooks/contexts.d.ts +191 -0
  164. package/dist/env/task/hooks/index.d.ts +7 -0
  165. package/dist/env/task/hooks/task-hook-points.d.ts +42 -0
  166. package/dist/env/task/index.d.ts +7 -0
  167. package/dist/env/task/plugins/auto-task-plugin.d.ts +38 -0
  168. package/dist/env/task/plugins/card-chat-routing.d.ts +135 -0
  169. package/dist/env/task/plugins/fake-user-message-helper.d.ts +90 -0
  170. package/dist/env/task/plugins/index.d.ts +8 -0
  171. package/dist/env/task/plugins/index.js +1 -1
  172. package/dist/env/task/plugins/lark-card-action-handler.d.ts +166 -0
  173. package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +651 -0
  174. package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +248 -0
  175. package/dist/env/task/plugins/max-iteration-reminder-plugin.d.ts +112 -0
  176. package/dist/env/task/plugins/per-task-group-chat-plugin.d.ts +561 -0
  177. package/dist/env/task/plugins/task-tag-plugin.d.ts +70 -0
  178. package/dist/env/task/plugins/workflow-extractor-agent.d.ts +43 -0
  179. package/dist/env/task/registry-hook-installer.d.ts +43 -0
  180. package/dist/env/task/storage/index.d.ts +5 -0
  181. package/dist/env/task/storage/migrations/001_add_project_path_context.d.ts +14 -0
  182. package/dist/env/task/storage/migrations/002_add_task_type.d.ts +14 -0
  183. package/dist/env/task/storage/migrations/003_add_process_description.d.ts +20 -0
  184. package/dist/env/task/storage/migrations/004_rename_action_to_milestone.d.ts +37 -0
  185. package/dist/env/task/storage/migrations/005_convert_blob_description_to_text.d.ts +51 -0
  186. package/dist/env/task/storage/sqlite-task-store.d.ts +241 -0
  187. package/dist/env/task/tag-service.d.ts +138 -0
  188. package/dist/env/task/task-child-context.d.ts +70 -0
  189. package/dist/env/task/task-component.d.ts +270 -0
  190. package/dist/env/task/task-config-registration.d.ts +19 -0
  191. package/dist/env/task/task-creation-registry.d.ts +181 -0
  192. package/dist/env/task/task-reuse-context.d.ts +52 -0
  193. package/dist/env/task/task-reuse-registry.d.ts +31 -0
  194. package/dist/env/task/tools/batch-archive-tool.d.ts +9 -0
  195. package/dist/env/task/tools/batch-delete-tool.d.ts +9 -0
  196. package/dist/env/task/tools/complete-tool.d.ts +12 -0
  197. package/dist/env/task/tools/create-tool.d.ts +6 -0
  198. package/dist/env/task/tools/delete-tool.d.ts +6 -0
  199. package/dist/env/task/tools/get-tool.d.ts +6 -0
  200. package/dist/env/task/tools/index.d.ts +13 -0
  201. package/dist/env/task/tools/list-tool.d.ts +6 -0
  202. package/dist/env/task/tools/operation/create-tool.d.ts +12 -0
  203. package/dist/env/task/tools/operation/delete-tool.d.ts +6 -0
  204. package/dist/env/task/tools/operation/get-tool.d.ts +6 -0
  205. package/dist/env/task/tools/operation/index.d.ts +8 -0
  206. package/dist/env/task/tools/operation/list-tool.d.ts +6 -0
  207. package/dist/env/task/tools/operation/operation-types.d.ts +225 -0
  208. package/dist/env/task/tools/operation/update-tool.d.ts +6 -0
  209. package/dist/env/task/tools/search-tool.d.ts +9 -0
  210. package/dist/env/task/tools/task-tree-tool.d.ts +65 -0
  211. package/dist/env/task/tools/task-types.d.ts +255 -0
  212. package/dist/env/task/tools/update-tool.d.ts +6 -0
  213. package/dist/env/task/types.d.ts +290 -0
  214. package/dist/env/tool/built-in/bash-effect.d.ts +36 -0
  215. package/dist/env/tool/built-in/bash.d.ts +16 -0
  216. package/dist/env/tool/built-in/echo.d.ts +7 -0
  217. package/dist/env/tool/built-in/edit-file.d.ts +6 -0
  218. package/dist/env/tool/built-in/glob.d.ts +6 -0
  219. package/dist/env/tool/built-in/grep.d.ts +6 -0
  220. package/dist/env/tool/built-in/index.d.ts +39 -0
  221. package/dist/env/tool/built-in/query-background-process-tool.d.ts +113 -0
  222. package/dist/env/tool/built-in/read-file.d.ts +5 -0
  223. package/dist/env/tool/built-in/understand-image.d.ts +59 -0
  224. package/dist/env/tool/built-in/write-file.d.ts +5 -0
  225. package/dist/env/tool/index.d.ts +16 -0
  226. package/dist/env/tool/registry.d.ts +61 -0
  227. package/dist/env/tool/tool-component.d.ts +242 -0
  228. package/dist/env/tool/tool-config-registration.d.ts +18 -0
  229. package/dist/env/tool/types.d.ts +274 -0
  230. package/dist/env/tool/validator.d.ts +14 -0
  231. package/dist/env/types.d.ts +184 -0
  232. package/dist/env/workflow/decorators/decorator-node.d.ts +76 -0
  233. package/dist/env/workflow/decorators/edge.d.ts +42 -0
  234. package/dist/env/workflow/decorators/index.d.ts +13 -0
  235. package/dist/env/workflow/decorators/node-as.d.ts +40 -0
  236. package/dist/env/workflow/decorators/workflow.d.ts +30 -0
  237. package/dist/env/workflow/engine/dag-manager.d.ts +176 -0
  238. package/dist/env/workflow/engine/engine.d.ts +375 -0
  239. package/dist/env/workflow/engine/event-bus.d.ts +54 -0
  240. package/dist/env/workflow/engine/executor.d.ts +122 -0
  241. package/dist/env/workflow/engine/index.d.ts +15 -0
  242. package/dist/env/workflow/engine/node-registry.d.ts +159 -0
  243. package/dist/env/workflow/engine/scheduler.d.ts +164 -0
  244. package/dist/env/workflow/extractor/workflow-converter.d.ts +55 -0
  245. package/dist/env/workflow/fixtures.d.ts +401 -0
  246. package/dist/env/workflow/hooks/index.d.ts +4 -0
  247. package/dist/env/workflow/hooks/workflow-hook-points.d.ts +161 -0
  248. package/dist/env/workflow/index.d.ts +30 -0
  249. package/dist/env/workflow/index.js +1 -1
  250. package/dist/env/workflow/metadata/keys.d.ts +6 -0
  251. package/dist/env/workflow/nodes/agent-component-adapter.d.ts +175 -0
  252. package/dist/env/workflow/nodes/agent-node.d.ts +206 -0
  253. package/dist/env/workflow/nodes/ask-user-node.d.ts +66 -0
  254. package/dist/env/workflow/nodes/condition-node.d.ts +39 -0
  255. package/dist/env/workflow/nodes/index.d.ts +8 -0
  256. package/dist/env/workflow/nodes/merge-node.d.ts +40 -0
  257. package/dist/env/workflow/nodes/python-call-node.d.ts +95 -0
  258. package/dist/env/workflow/nodes/skill-node.d.ts +29 -0
  259. package/dist/env/workflow/nodes/tool-node.d.ts +58 -0
  260. package/dist/env/workflow/nodes/workflow-node.d.ts +118 -0
  261. package/dist/env/workflow/plugins/index.d.ts +6 -0
  262. package/dist/env/workflow/plugins/lark-cli-workflow-notify-plugin.d.ts +107 -0
  263. package/dist/env/workflow/plugins/workflow-json-output-plugin.d.ts +166 -0
  264. package/dist/env/workflow/runtime/runtime-cancellation-scope.d.ts +121 -0
  265. package/dist/env/workflow/service/index.d.ts +9 -0
  266. package/dist/env/workflow/service/registry.d.ts +37 -0
  267. package/dist/env/workflow/service/workflow-service.d.ts +422 -0
  268. package/dist/env/workflow/storage/index.d.ts +11 -0
  269. package/dist/env/workflow/storage/mock-repositories.d.ts +106 -0
  270. package/dist/env/workflow/storage/safe-json.d.ts +62 -0
  271. package/dist/env/workflow/storage/sqlite.d.ts +57 -0
  272. package/dist/env/workflow/storage/tag-repo.d.ts +65 -0
  273. package/dist/env/workflow/storage/workflow-repo.d.ts +161 -0
  274. package/dist/env/workflow/tools/ask-user-tool.d.ts +35 -0
  275. package/dist/env/workflow/tools/index.d.ts +16 -0
  276. package/dist/env/workflow/tools/run-workflow.d.ts +130 -0
  277. package/dist/env/workflow/tools/submit-json-output-tool.d.ts +38 -0
  278. package/dist/env/workflow/tools/workflow-add-tool.d.ts +47 -0
  279. package/dist/env/workflow/tools/workflow-get-tool.d.ts +29 -0
  280. package/dist/env/workflow/tools/workflow-list-tool.d.ts +55 -0
  281. package/dist/env/workflow/tools/workflow-run-status-tool.d.ts +26 -0
  282. package/dist/env/workflow/tools/workflow-run-stop-tool.d.ts +29 -0
  283. package/dist/env/workflow/tools/workflow-search-tool.d.ts +33 -0
  284. package/dist/env/workflow/tools/workflow-tag-list-tool.d.ts +59 -0
  285. package/dist/env/workflow/tools/workflow-validate-tool.d.ts +60 -0
  286. package/dist/env/workflow/types/context.d.ts +17 -0
  287. package/dist/env/workflow/types/decorators-types.d.ts +182 -0
  288. package/dist/env/workflow/types/edge.d.ts +33 -0
  289. package/dist/env/workflow/types/event.d.ts +869 -0
  290. package/dist/env/workflow/types/index.d.ts +16 -0
  291. package/dist/env/workflow/types/run.d.ts +235 -0
  292. package/dist/env/workflow/types/workflow-error.d.ts +79 -0
  293. package/dist/env/workflow/types/workflow-hil.d.ts +57 -0
  294. package/dist/env/workflow/types/workflow-message.d.ts +193 -0
  295. package/dist/env/workflow/types/workflow-session.d.ts +17 -0
  296. package/dist/env/workflow/types/workflow.d.ts +654 -0
  297. package/dist/env/workflow/types_compat.d.ts +10 -0
  298. package/dist/env/workflow/utils/agent-session-metadata.d.ts +35 -0
  299. package/dist/env/workflow/utils/build-agent-node-output.d.ts +11 -0
  300. package/dist/env/workflow/utils/create-workflow.d.ts +35 -0
  301. package/dist/env/workflow/utils/dependency-prescan.d.ts +67 -0
  302. package/dist/env/workflow/utils/execution-state.d.ts +46 -0
  303. package/dist/env/workflow/utils/extract-agent-json-output.d.ts +6 -0
  304. package/dist/env/workflow/utils/index.d.ts +14 -0
  305. package/dist/env/workflow/utils/json-schema-to-zod.d.ts +23 -0
  306. package/dist/env/workflow/utils/node-id-utils.d.ts +20 -0
  307. package/dist/env/workflow/utils/node-output-contracts.d.ts +137 -0
  308. package/dist/env/workflow/utils/node-registry-helper.d.ts +36 -0
  309. package/dist/env/workflow/utils/output-schema-hint.d.ts +7 -0
  310. package/dist/env/workflow/utils/parse-agent-output-config.d.ts +9 -0
  311. package/dist/env/workflow/utils/recovery-validator.d.ts +30 -0
  312. package/dist/env/workflow/utils/sensitive-redact.d.ts +37 -0
  313. package/dist/env/workflow/utils/session-parser.d.ts +23 -0
  314. package/dist/env/workflow/utils/session-recovery.d.ts +122 -0
  315. package/dist/env/workflow/utils/template-contract-validator.d.ts +87 -0
  316. package/dist/env/workflow/utils/template-resolver.d.ts +285 -0
  317. package/dist/env/workflow/utils/validate-workflow-definition.d.ts +57 -0
  318. package/dist/env/workflow/utils/validation-rules.d.ts +103 -0
  319. package/dist/env/workflow/utils/workflow-message-metadata.d.ts +20 -0
  320. package/dist/env/workflow/utils/workflow-sanitize.d.ts +51 -0
  321. package/dist/env/workflow/workflow-component.d.ts +138 -0
  322. package/dist/index.d.ts +59 -0
  323. package/dist/index.js +5 -5
  324. package/dist/shared/@ai-setting/{roy-agent-core-rcfewbzr.js → roy-agent-core-4sx6sdb2.js} +1 -1
  325. package/dist/shared/@ai-setting/{roy-agent-core-ezgsem94.js → roy-agent-core-ph5qbqcx.js} +1 -1
  326. package/dist/util/process/process-tree-killer.d.ts +67 -0
  327. package/dist/utils/id.d.ts +11 -0
  328. package/dist/utils/loose-json.d.ts +30 -0
  329. package/dist/utils/media.d.ts +70 -0
  330. package/dist/utils/temp-file-manager/index.d.ts +99 -0
  331. package/package.json +4 -2
  332. /package/dist/shared/@ai-setting/{roy-agent-core-s214vmmd.js → roy-agent-core-4vpk40ss.js} +0 -0
  333. /package/dist/shared/@ai-setting/{roy-agent-core-pkpkctvf.js → roy-agent-core-hch2geta.js} +0 -0
  334. /package/dist/shared/@ai-setting/{roy-agent-core-0cfaqnz9.js → roy-agent-core-k25gv86p.js} +0 -0
@@ -0,0 +1,646 @@
1
+ /**
2
+ * @fileoverview AgentComponent - Agent执行核心组件
3
+ *
4
+ * 基于 roy-agent docs/agent-component-design.md
5
+ * 参考 agent-core Agent.run 实现
6
+ *
7
+ * 核心功能:
8
+ * - ReAct 循环编排
9
+ * - Hook 机制和 Plugin 扩展
10
+ * - 多 Agent 管理
11
+ * - 工具调用
12
+ *
13
+ * 依赖:
14
+ * - ../llm - LLMComponent 用于 LLM 调用
15
+ * - ../log-trace/logger - createLogger 用于日志
16
+ */
17
+ import { BaseComponent, type ComponentConfig } from "../component";
18
+ import type { AgentInstance, AgentInstanceConfig, AgentRunResult, AgentContext, Plugin, Tool } from "./types";
19
+ import type { ModelMessage } from "ai";
20
+ import type { LLMMessage } from "../llm/types";
21
+ import type { ContentPart } from "../llm/types";
22
+ import { z } from "zod";
23
+ import type { ConfigComponent } from "../../config/config-component";
24
+ import { type EnvContext } from "../context";
25
+ import { AgentRegistry, type AgentDefinition } from "./agent-registry";
26
+ /**
27
+ * Parse a tool list (allowedTools / deniedTools) from heterogeneous config sources.
28
+ *
29
+ * Task #2024 follow-up: EnvSource has no transform; when allowedTools/deniedTools
30
+ * is set via env var (e.g. AGENT_AGENT_DEFAULT_AGENT_ALLOWED_TOOLS=tool_a,tool_b),
31
+ * ConfigComponent.get() returns the raw string "tool_a,tool_b" rather than an array.
32
+ * The previous `as string[] | undefined` cast was a TypeScript lie: at runtime
33
+ * `allowedTools.includes(t.name)` became `String.prototype.includes` (substring match),
34
+ * not `Array.prototype.includes` (element match).
35
+ *
36
+ * Behavior:
37
+ * - undefined / null → undefined (no filter)
38
+ * - Array → returned as-is (after filtering out non-string entries defensively)
39
+ * - String → split on ',', trim each entry, drop empty strings
40
+ * - Anything else → undefined (defensive default)
41
+ *
42
+ * @param v - The raw value from constructor, config, env, or file source
43
+ * @returns Normalized string[] | undefined
44
+ */
45
+ export declare function parseToolList(v: unknown): string[] | undefined;
46
+ /**
47
+ * Task #2391 — v0.7.3 unknown-error hardening.
48
+ *
49
+ * Compose the LLM-facing tool-output string from a `ToolResult`. The
50
+ * previous code used `result.error || "Unknown error"` which silently
51
+ * dropped the runId + recovery hint whenever the tool's error field was
52
+ * empty. This helper produces a structured diagnostic instead, using
53
+ * whatever runId / status / metadata bits are present.
54
+ *
55
+ * Behavior:
56
+ * - `success: true` → returns `output` (string or JSON-stringified record)
57
+ * - `success: false` with non-empty `error` → returns `error`
58
+ * - `success: false` with empty/missing `error` AND a runId →
59
+ * returns `[ErrorType=EmptyErrorField] tool=<name> status=<s> runId=<id>
60
+ * (no error message provided by tool — query workflow_run_status)`
61
+ * - `success: false` with empty/missing `error` AND no runId →
62
+ * returns `[ErrorType=EmptyErrorField] tool=<name> status=<s>
63
+ * (no error message and no runId — tool did not surface a diagnostic)`
64
+ *
65
+ * Exported for testability (so the fallback string can be asserted
66
+ * directly without spinning up the full agent + LLM stack).
67
+ */
68
+ export declare function composeToolOutputForLLM(toolName: string, result: {
69
+ success: boolean;
70
+ output: string | Record<string, unknown>;
71
+ error?: string;
72
+ metadata?: {
73
+ run_id?: string | number;
74
+ [k: string]: unknown;
75
+ };
76
+ } | null | undefined): string;
77
+ /**
78
+ * 将 ModelMessage 转换为 LLMMessage
79
+ *
80
+ * ModelMessage 来自 ai SDK,LLMMessage 是内部格式
81
+ */
82
+ export declare function toLLMMessage(msg: ModelMessage): LLMMessage;
83
+ /**
84
+ * AgentComponent 配置 Schema
85
+ */
86
+ export declare const AgentComponentConfigSchema: z.ZodObject<{
87
+ defaultAgent: z.ZodObject<{
88
+ type: z.ZodDefault<z.ZodEnum<["primary", "sub"]>>;
89
+ systemPrompt: z.ZodOptional<z.ZodString>;
90
+ behaviorSpecId: z.ZodOptional<z.ZodString>;
91
+ model: z.ZodOptional<z.ZodString>;
92
+ maxIterations: z.ZodDefault<z.ZodNumber>;
93
+ maxErrorRetries: z.ZodDefault<z.ZodNumber>;
94
+ doomLoopThreshold: z.ZodDefault<z.ZodNumber>;
95
+ allowedTools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
96
+ deniedTools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
97
+ toolTimeout: z.ZodDefault<z.ZodNumber>;
98
+ toolRetries: z.ZodDefault<z.ZodNumber>;
99
+ /** 是否过滤 history 中的 tool 消息(默认不过滤,保留完整上下文) */
100
+ filterHistory: z.ZodDefault<z.ZodBoolean>;
101
+ }, "strip", z.ZodTypeAny, {
102
+ type: "primary" | "sub";
103
+ maxIterations: number;
104
+ maxErrorRetries: number;
105
+ toolTimeout: number;
106
+ toolRetries: number;
107
+ doomLoopThreshold: number;
108
+ filterHistory: boolean;
109
+ systemPrompt?: string | undefined;
110
+ model?: string | undefined;
111
+ allowedTools?: string[] | undefined;
112
+ deniedTools?: string[] | undefined;
113
+ behaviorSpecId?: string | undefined;
114
+ }, {
115
+ type?: "primary" | "sub" | undefined;
116
+ systemPrompt?: string | undefined;
117
+ model?: string | undefined;
118
+ maxIterations?: number | undefined;
119
+ maxErrorRetries?: number | undefined;
120
+ allowedTools?: string[] | undefined;
121
+ deniedTools?: string[] | undefined;
122
+ toolTimeout?: number | undefined;
123
+ toolRetries?: number | undefined;
124
+ doomLoopThreshold?: number | undefined;
125
+ filterHistory?: boolean | undefined;
126
+ behaviorSpecId?: string | undefined;
127
+ }>;
128
+ }, "strip", z.ZodTypeAny, {
129
+ defaultAgent: {
130
+ type: "primary" | "sub";
131
+ maxIterations: number;
132
+ maxErrorRetries: number;
133
+ toolTimeout: number;
134
+ toolRetries: number;
135
+ doomLoopThreshold: number;
136
+ filterHistory: boolean;
137
+ systemPrompt?: string | undefined;
138
+ model?: string | undefined;
139
+ allowedTools?: string[] | undefined;
140
+ deniedTools?: string[] | undefined;
141
+ behaviorSpecId?: string | undefined;
142
+ };
143
+ }, {
144
+ defaultAgent: {
145
+ type?: "primary" | "sub" | undefined;
146
+ systemPrompt?: string | undefined;
147
+ model?: string | undefined;
148
+ maxIterations?: number | undefined;
149
+ maxErrorRetries?: number | undefined;
150
+ allowedTools?: string[] | undefined;
151
+ deniedTools?: string[] | undefined;
152
+ toolTimeout?: number | undefined;
153
+ toolRetries?: number | undefined;
154
+ doomLoopThreshold?: number | undefined;
155
+ filterHistory?: boolean | undefined;
156
+ behaviorSpecId?: string | undefined;
157
+ };
158
+ }>;
159
+ export type AgentComponentConfig = z.infer<typeof AgentComponentConfigSchema>;
160
+ /**
161
+ * AgentComponent 配置选项(通过 options 传递)
162
+ *
163
+ * 配置加载顺序(优先级从低到高):
164
+ * 1. File - 配置文件(通过 configPath 指定)
165
+ * 2. Env - 环境变量(通过 envPrefix 配置前缀)
166
+ * 3. Object - 直接传入的 config 对象(最高优先级)
167
+ */
168
+ export interface AgentComponentOptions {
169
+ /** ConfigComponent 实例(必填) */
170
+ configComponent: ConfigComponent;
171
+ /** 配置文件相对路径(可选,基于 XDG_DATA_HOME) */
172
+ configPath?: string;
173
+ /** 环境变量前缀(可选,默认 "AGENT") */
174
+ envPrefix?: string;
175
+ /** 直接传入的配置对象(可选,优先级最高) */
176
+ config?: Partial<AgentComponentConfig>;
177
+ }
178
+ /**
179
+ * 按 agent 的 `allowedAgentTypes` 工具级可见性过滤工具列表。
180
+ *
181
+ * 应用规则(与 ToolRegistry.listTools({ allowedAgent }) 保持一致):
182
+ * - `metadata.allowedAgentTypes` 未设置 / 空数组 → 工具对所有 agent 可见
183
+ * - 非空数组 → 仅当 agent.name 命中任一元素时工具可见
184
+ * - 字符串精确匹配,大小写敏感
185
+ *
186
+ * 用途(2026-07-15 修复 review #14143 Medium #3):
187
+ * - 统一在 AgentComponent.getAvailableTools 的三个入口(defaultTools / componentTools
188
+ * / extraTools)都调用一次,避免某些路径绕过此过滤
189
+ * - ToolComponent.listTools 已经过滤过 componentTools 一次,此处再过滤属于
190
+ * 防御性二次保险
191
+ *
192
+ * @param tools 待过滤的工具列表(不会修改入参)
193
+ * @param agent 当前请求工具列表的 agent
194
+ * @returns 过滤后的新数组(保留原数组的相对顺序)
195
+ */
196
+ export declare function filterToolsByAgent(tools: Tool[], agent: AgentInstance): Tool[];
197
+ /**
198
+ * 构建一次 Agent run 的 EnvContext(effectiveContext + 父级 ALS 继承)。
199
+ *
200
+ * ★ Blocker 1(Task #4111 P0-2 / #4108 v2 根因):把原先内联在
201
+ * `AgentComponent._run()` 里的 EnvContext 构建抽为**纯函数**,便于用真实生产
202
+ * 代码做回归测试(此前测试 inline 复刻优先级,revert 生产代码后测试仍全绿 =
203
+ * tautological,无法捕获回归)。
204
+ *
205
+ * 继承策略:
206
+ * - 大部分字段沿用 `...parentEnvContext` 展开(父级 ALS 兜底)
207
+ * - `envEvent` / `replyChannel`:**effective(当前事件)优先**,parent 兜底
208
+ * —— 修复 #4106 → #3990 群送错群(parent ALS 缓存的上一事件 replyChannel
209
+ * 污染了当前事件的 replyChannel)
210
+ * - 兼容:effective.envEvent.metadata 无 replyChannel(老 API 直接传 envEvent)时
211
+ * 仍回落 parent ALS,保证子 Agent 可用父级 replyChannel 发通知
212
+ */
213
+ export declare function buildRunEnvContext(inputs: {
214
+ effectiveContext: AgentContext;
215
+ parentEnvContext: EnvContext | undefined;
216
+ envBoundParentTaskId: number | undefined;
217
+ }): EnvContext;
218
+ /**
219
+ * AgentComponent
220
+ *
221
+ * 提供 Agent 执行能力和 Hook 扩展机制
222
+ */
223
+ export declare class AgentComponent extends BaseComponent {
224
+ readonly name = "agent";
225
+ readonly version = "1.0.0";
226
+ private agents;
227
+ private config;
228
+ private llmComponent;
229
+ private toolComponent;
230
+ private aborted;
231
+ private abortControllers;
232
+ private defaultTools;
233
+ private doomLoopCaches;
234
+ /** ConfigComponent 用于配置管理 */
235
+ private configComponent?;
236
+ /** 配置变更 watcher 清理函数 */
237
+ private configWatcher?;
238
+ /** Session 消息转换器 */
239
+ private messageConverter;
240
+ /** 构造函数传入的配置(最高优先级) */
241
+ private _constructorConfig?;
242
+ /** Run ID 计数器(用于生成唯一的 runId) */
243
+ /** AgentRegistry 用于持久化 agent 配置 */
244
+ private registry?;
245
+ private runCounter;
246
+ constructor(options?: {
247
+ config?: Partial<AgentComponentConfig>;
248
+ });
249
+ /**
250
+ * 初始化组件
251
+ *
252
+ * 配置加载优先级(从高到低):
253
+ * 1. Object - 直接传入的 config 对象
254
+ * 2. Env - 环境变量(通过 envPrefix 配置前缀)
255
+ * 3. File - 配置文件(通过 configPath 指定)
256
+ */
257
+ init(config: ComponentConfig): Promise<void>;
258
+ /**
259
+ * 注册配置到 ConfigComponent
260
+ *
261
+ * 配置加载顺序(优先级从低到高):
262
+ * 1. Defaults - 默认值(最低)
263
+ * 2. FileSource - 从配置文件加载
264
+ * 3. EnvSource - 从环境变量加载
265
+ * 4. config 对象 - 直接传入的配置(最高)
266
+ */
267
+ private registerConfig;
268
+ /**
269
+ * 将配置对象展平为点号路径
270
+ */
271
+ private flattenConfig;
272
+ /**
273
+ * 注册配置热更新监听
274
+ */
275
+ private registerConfigWatcher;
276
+ /**
277
+ * 处理配置变更
278
+ */
279
+ protected onConfigChange(event: {
280
+ key: string;
281
+ oldValue?: unknown;
282
+ newValue?: unknown;
283
+ }): void;
284
+ /**
285
+ * 初始化 AgentRegistry
286
+ *
287
+ * 从 agent config folder 加载 agent 配置
288
+ */
289
+ private initRegistry;
290
+ /**
291
+ * 在 PromptComponent 就绪后,重新同步 registry agent 的 systemPrompt
292
+ */
293
+ syncRegistryAgentsFromConfig(): Promise<void>;
294
+ /**
295
+ * 获取 AgentRegistry
296
+ */
297
+ getRegistry(): AgentRegistry | undefined;
298
+ /**
299
+ * 从 Registry 获取 agent 定义
300
+ */
301
+ getAgentFromRegistry(name: string): AgentDefinition | undefined;
302
+ /**
303
+ * 列出 Registry 中所有 agent 定义
304
+ */
305
+ listAgentsFromRegistry(): AgentDefinition[];
306
+ /**
307
+ * 组件停止时的清理逻辑
308
+ *
309
+ * 清理内容:
310
+ * 1. 终止所有正在运行的 Agent(调用 abort() 以中断 LLM 调用)
311
+ * 2. 清空 AbortController 注册表
312
+ * 3. 清空 Doom Loop 缓存
313
+ * 4. 取消配置变更监听
314
+ * 5. 清空 Agent 注册表
315
+ */
316
+ protected onStop(): Promise<void>;
317
+ /**
318
+ * 刷新依赖组件引用
319
+ *
320
+ * 当组件被添加到 Environment 后调用,以确保获取到最新的组件引用
321
+ */
322
+ refreshDependencies(): Promise<void>;
323
+ /**
324
+ * 解析 agent 的 systemPrompt
325
+ *
326
+ * 处理 PromptComponent 延迟初始化的情况:
327
+ * - 若 agent 有 systemPromptRef 但尚无 systemPrompt,从 registry 延迟解析
328
+ * - 若已有 systemPrompt 则跳过(sync 或上次 run 已解析)
329
+ */
330
+ private resolveSystemPrompt;
331
+ /**
332
+ * 获取 Agent 实例
333
+ */
334
+ getAgent(agentName: string): AgentInstance | undefined;
335
+ /**
336
+ * 获取所有 Agent 实例
337
+ */
338
+ listAgents(): AgentInstance[];
339
+ /**
340
+ * Add placeholder tool results for remaining unprocessed tool calls
341
+ *
342
+ * This ensures that the message history maintains a 1:1 correspondence
343
+ * between tool-calls and tool-results, which is required by AI SDK v6.
344
+ *
345
+ * @param ctx - Hook context containing messages
346
+ * @param allToolCalls - All tool calls from the LLM response
347
+ * @param processedCount - Number of tool calls that have been processed
348
+ * @param reason - Reason for the abort/interruption
349
+ */
350
+ private addRemainingToolResults;
351
+ /**
352
+ * 注册 Agent
353
+ *
354
+ * 配置优先级(从高到低):
355
+ * 1. registerAgent 传入的 config(来自 PromptComponent)
356
+ * 2. defaultAgent 配置(来自 ConfigComponent,作为 fallback)
357
+ */
358
+ registerAgent(name: string, config: Partial<AgentInstanceConfig>): AgentInstance;
359
+ /**
360
+ * 注销 Agent
361
+ */
362
+ unregisterAgent(name: string): boolean;
363
+ /**
364
+ * 注册 Plugin 到指定 Agent
365
+ */
366
+ registerPlugin(agentName: string, plugin: Plugin): void;
367
+ /**
368
+ * 注销 Plugin
369
+ */
370
+ unregisterPlugin(agentName: string, pluginName: string): boolean;
371
+ /**
372
+ * 设置默认工具列表
373
+ */
374
+ setDefaultTools(tools: Tool[]): void;
375
+ /**
376
+ * 获取可用工具
377
+ */
378
+ getAvailableTools(agent: AgentInstance, context?: AgentContext): Tool[];
379
+ /**
380
+ * 执行 Agent
381
+ *
382
+ * @param agentName Agent 名称
383
+ * @param query 用户查询
384
+ * @param context 执行上下文
385
+ * @returns Agent 执行结果
386
+ */
387
+ run(agentName: string, query: string | ContentPart[], context?: AgentContext): Promise<AgentRunResult>;
388
+ private pushMessage;
389
+ /**
390
+ * ✅ META PROTOCOL helper #1 — Task #2170.
391
+ * Captures (reads-and-deletes) the `toAddFakeUserMessage` metadata set by plugins
392
+ * such as `AutoTaskPlugin`. Idempotent: subsequent calls return undefined.
393
+ *
394
+ * Returns the captured `ModelMessage` (or undefined). The caller is responsible
395
+ * for storing it in `pendingFakeUserMessage` and pushing it AFTER all
396
+ * tool-results in the iteration complete (see `flushPendingFakeUserMessage`).
397
+ *
398
+ * Span: `agent.meta-protocol.consumeUserMessage`
399
+ */
400
+ private consumeMetaProtocolUserMessage;
401
+ /**
402
+ * ✅ META PROTOCOL helper #2 — Task #2170.
403
+ * Pushes the previously-captured `toAddFakeUserMessage` to `ctx.messages`.
404
+ * Called ONCE per ReAct iteration AFTER the for-loop ends, so the user message
405
+ * is appended after ALL tool-results (not between them), preserving AI SDK v6's
406
+ * strict `tool_call` ↔ `tool_result` adjacency requirement.
407
+ *
408
+ * Span: `agent.meta-protocol.flushPendingUserMessage`
409
+ */
410
+ private flushPendingFakeUserMessage;
411
+ /**
412
+ * 执行 Agent(核心方法,内部实现)
413
+ */
414
+ private _run;
415
+ /**
416
+ * 中止 Agent
417
+ *
418
+ * 调用此方法会:
419
+ * 1. 设置 aborted 标志(用于 ReAct 循环检查)
420
+ * 2. 触发 AbortController.abort()(用于中断正在进行的 LLM 调用)
421
+ *
422
+ * 注意:不直接修改 agent.status,由 _run() 的 finally 统一处理
423
+ */
424
+ abort(agentName: string): void;
425
+ /**
426
+ * Task #2590 follow-up — run-scoped abort.
427
+ *
428
+ * Abort a single agent run by its runId, rather than by agent name. The
429
+ * agent-name-scoped `abort(agentName)` is "every concurrent run of the
430
+ * same type" — silent-fail root cause when invoked from a sub-agent's
431
+ * signal listener that escaped after the sub-agent already finished.
432
+ *
433
+ * Caller contract: pass a runId that was either pre-allocated via
434
+ * `AgentContext.runId` and stored on the caller's task record, or
435
+ * otherwise observed through normal AgentComponent logging.
436
+ *
437
+ * Idempotent: aborting an already-aborted or already-finalized run is a
438
+ * no-op. The AbortController itself is also idempotent.
439
+ *
440
+ * @returns true if the runId was found and the abort signal was issued,
441
+ * false if the runId had already finalized and was removed from
442
+ * the registry.
443
+ */
444
+ abortRun(runId: string, reason?: string): boolean;
445
+ /**
446
+ * 中止所有正在运行的 Agent
447
+ *
448
+ * 与 abort(name) 不同,此方法会终止全部 Agent run,
449
+ * 包括父 agent 通过 delegate_task 创建的子 agent。
450
+ * 用于 ESC/abort 等用户主动中断场景。
451
+ */
452
+ abortAll(): void;
453
+ /**
454
+ * 构建消息列表
455
+ *
456
+ * 注意:ctx.messages 已经包含了历史消息(包括 system prompt 和 user query)
457
+ * 这里只需要构建当前请求的消息,不重复添加
458
+ */
459
+ /**
460
+ * 【Task #2744】session-scope cache snapshot 加载/创建/持久化
461
+ *
462
+ * 设计目标:把 systemPrompt({{memory}} 已替换)和 additionInfo 绑定到 session 生命周期,
463
+ * first-run 计算一次并持久化到 session.metadata.cacheSnapshot,后续 _run 直接复用
464
+ * → 字节级一致 → LLM prompt cache 命中。
465
+ *
466
+ * @returns
467
+ * - snapshot: 冻结的 { systemPrompt, additionInfo, snapshotAt } 快照
468
+ * - systemPromptOverride: 如果 snapshot 命中,覆盖调用方的 resolvedSystemPrompt
469
+ * (值是 snapshot.systemPrompt,命中时与 snapshot.systemPrompt 相同)
470
+ *
471
+ * 错误处理:所有 I/O 失败均降级为"返回 null"(调用方走 fallback 路径),
472
+ * 不阻塞 run。
473
+ */
474
+ private _loadOrCreateCacheSnapshot;
475
+ /**
476
+ * 【Task #2744】无 sessionId 时的 {{memory}} fallback 替换
477
+ *
478
+ * 场景:sub-agent 或单元测试不传 sessionId → 走原 P1-1 行为(每 run 重新 recallMemory)。
479
+ * 这是为了保持对无 session 路径的向后兼容,不影响 cache 路径。
480
+ */
481
+ private _fallbackReplaceMemory;
482
+ /**
483
+ * 构建 additionInfo(含 currentTaskId 上下文注入)
484
+ *
485
+ * 通过 @TracedAs 追踪,可在 debug trace / debug span 中查看
486
+ * currentTaskId 是否成功注入到 LLM 上下文
487
+ *
488
+ * Task #2744 (session-scope cache optimization):
489
+ * 如果 ctx._cacheSnapshot 存在(由 AgentComponent._run 在 first-run 时持久化到
490
+ * session.metadata.cacheSnapshot),则返回 snapshot 的 additionInfo,**跨多轮
491
+ * 保持字节级一致** —— 这是 LLM prompt cache 命中的前提。
492
+ *
493
+ * 否则降级到当前行为:从 ctx.context.additionInfo 读取(每次 buildMessages 都
494
+ * 重读,可能因 caller 传入不同值而变化 → cache miss)。
495
+ */
496
+ private _buildAdditionInfo;
497
+ private buildMessages;
498
+ /**
499
+ * 【Task #2760 Dim 6】把 ctx.tools 格式化为 toolDefinitions 字符串
500
+ *
501
+ * 目的:让 buildMultiBlockSystem 输出一段独立的 toolDefinitions 段(挂 cache_control),
502
+ * 这样 OpenAI-Compatible provider 也可以通过 prompt_cache_key 命中工具 schema 前缀。
503
+ * Anthropic 已经有 applyToolCacheControl 在 tool 字段挂 cache_control(独立 cache),
504
+ * 但 system prompt 内的 toolDefinitions 段是冗余但无害的(AI SDK 会去重)。
505
+ *
506
+ * 格式化策略:每行 `name: description` 的紧凑列表。JSON 序列化参数过于详细,
507
+ * 紧凑列表足以让 LLM 列出可用工具。
508
+ *
509
+ * 内容稳定性:相同 ctx.tools 跨 run 输出 byte-equal → 缓存命中。
510
+ * (按 name 排序,确保多 run 工具顺序变化也 byte-stable)
511
+ */
512
+ private _formatToolDefinitions;
513
+ /**
514
+ * 调用 LLM
515
+ *
516
+ * 流式事件由 LLMComponent 通过 env.pushEnvEvent() 发布
517
+ */
518
+ private invokeLLM;
519
+ /**
520
+ * Task #2723: 归一化上游 tool-call shape → 内部 `Record<string, unknown>`。
521
+ *
522
+ * 两种上游 shape 都会在调用前被转换成 JSON object:
523
+ * - AI SDK 兼容:`{ id, function: { name, arguments: string } }`
524
+ * - pi-ai 顶层:`{ id, name, arguments: string }` (无 `function` 包装)
525
+ *
526
+ * `safeParseToolArgs()` 递归处理 normal / double-stringified / already-object /
527
+ * malformed 输入,失败 fallback 到 `{}`,避免把 `_raw` 泄漏到 session。
528
+ *
529
+ * Trace 维度只记录 source / type / keys(不记录 raw value),以免污染 span store。
530
+ */
531
+ private parseToolCallArguments;
532
+ /**
533
+ * 严格版参数解析(Task #4231)
534
+ *
535
+ * 与 `parseToolCallArguments` 的差别:失败时返回 `ok:false` 而不是空对象,
536
+ * 让调用方能把错误回给模型、并**拒绝执行**这条工具调用。
537
+ * 会先尝试抢救上游退化格式(GLM 的 `<arg_key>/<arg_value>` 文本标记)。
538
+ */
539
+ private parseToolCallArgumentsStrict;
540
+ /**
541
+ * 执行工具
542
+ *
543
+ * errorIf:只有「工具根本不存在」(未注册 / 被 allowedTools|deniedTools 过滤掉)
544
+ * 才把 span 标成 ERROR —— 这是 prompt 承诺与实际工具表不一致的**配置错误**,
545
+ * 属于必须显式可见的 bug。
546
+ *
547
+ * 刻意不覆盖「工具执行失败」(`success:false` 且有真实 error,如 bash exit!=0):
548
+ * 那是正常运行时结果,全标 ERROR 会让 trace 里遍布红色噪音、反而掩盖真问题。
549
+ */
550
+ private executeTool;
551
+ /**
552
+ * 执行 Plugin Hooks (Agent 特有的 Hook 执行机制)
553
+ *
554
+ * 执行顺序:
555
+ * 1. Agent 自己的 plugins(通过 agent.plugins)
556
+ * 2. EventSource 加载的 plugins(通过 globalHookManager + pluginEnabled 检查)
557
+ */
558
+ private executePluginHooks;
559
+ /**
560
+ * 处理 Hook 动作
561
+ */
562
+ private handleHookAction;
563
+ /**
564
+ * 通知消息添加(扩展点)
565
+ */
566
+ protected notifyMessageAdded(message: ModelMessage): void;
567
+ /**
568
+ * 结束结果
569
+ */
570
+ private finalizeResult;
571
+ /**
572
+ * Record messages to session
573
+ *
574
+ * 存储策略:
575
+ * 1. 存储 allMessages 中的所有 user、assistant、tool 消息
576
+ * 2. 跳过 system 消息
577
+ * 3. 跳过空内容的 assistant/tool 消息
578
+ *
579
+ * Layer 3 wiring (sessions.db fix): instead of N individual addMessage
580
+ * calls (each = INSERT message + UPDATE session.message_count = 2
581
+ * statements per row), we filter first and dispatch ONCE per React
582
+ * iteration through sessionComponent.addMessages, which performs the
583
+ * whole batch in a single BEGIN/COMMIT. This eliminates the lock
584
+ * amplification that turned short contentions into full SQLITE_BUSY
585
+ * storms (the root cause of the 2026-07-07 incident).
586
+ */
587
+ private recordSessionMessages;
588
+ /**
589
+ * 检查消息内容是否为空
590
+ *
591
+ * 空内容定义:
592
+ * - 空字符串 ""
593
+ * - 空数组 []
594
+ * - null
595
+ * - undefined
596
+ *
597
+ * @param content - 消息内容
598
+ * @returns 是否为空
599
+ */
600
+ private isEmptyMessage;
601
+ /**
602
+ * 通过 Environment 发送事件
603
+ */
604
+ private pushEnvEvent;
605
+ /**
606
+ * 获取会话对话历史
607
+ *
608
+ * 核心逻辑:
609
+ * 1. 使用 sessionComponent.getContext() 获取消息(自动从 checkpoint 开始)
610
+ * 2. 根据 messageLimit 限制消息数量(向后兼容 minUserMessages)
611
+ * 3. 过滤掉 tool_call/tool_result 消息(如果 filterHistory=true)
612
+ *
613
+ * 关键改进:利用 checkpoint 概念,避免重复获取已压缩的历史消息,
614
+ * 从而减少重复触发压缩的问题。
615
+ *
616
+ * @param sessionComponent - SessionComponent 实例
617
+ * @param sessionId - 会话 ID
618
+ * @param options - 配置选项
619
+ * @param options.minUserMessages - 最少包含的 user 消息数量(默认 100)
620
+ * @param options.filterHistory - 是否过滤 tool 消息(默认 true)
621
+ * @returns 过滤后的会话消息列表
622
+ */
623
+ private getConversationHistory;
624
+ }
625
+ /**
626
+ * 【Task #2748 §5.6】Multi-block system prompt 构造(顶层 helper,可独立测试)
627
+ *
628
+ * 把 system prompt 拆分为 4 段独立 cache 块(每段独立 cache_control):
629
+ * - [0] characterSheet: 角色设定(极少变,独立 cache 长期命中)
630
+ * - [1] toolDefinitions: 工具定义(config 不变就不变)
631
+ * - [2] memoryBlock: 记忆块(变化频率低)
632
+ * - [3] dynamicContext: 动态上下文(currentTaskId 等,可能变)
633
+ *
634
+ * 设计依据(参考 pi-agent multi-block system):
635
+ * - Anthropic 端原生支持多 system block + 每 block 独立 cache_control
636
+ * - 拆段后,dynamic 段变化只让 [3] 段 cache 失效,[0][1][2] 仍命中
637
+ *
638
+ * 当前 buildMessages 仍使用单段 system message(向后兼容)。
639
+ * 本函数作为 helper 暴露,便于测试 + 未来切到 multi-block 模式时复用。
640
+ */
641
+ export declare function buildMultiBlockSystem(ctx: {
642
+ characterSheet: string;
643
+ toolDefinitions?: string;
644
+ memoryBlock?: string;
645
+ dynamicContext?: string;
646
+ }): ModelMessage[];
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @fileoverview Agent Component 配置注册
3
+ *
4
+ * 使用 ConfigComponent.registerComponent() 机制统一管理配置
5
+ */
6
+ import type { ComponentRegistration } from "../../config/config-component";
7
+ /**
8
+ * Agent Component 默认配置值
9
+ *
10
+ * 注意:键使用完整格式(带 "agent." 前缀),在 registerConfig 中手动设置
11
+ */
12
+ export declare const AGENT_DEFAULTS: Record<string, unknown>;
13
+ /**
14
+ * Agent Component 配置注册常量
15
+ *
16
+ * 定义了所有 Agent 相关的配置项和来源
17
+ */
18
+ export declare const AGENT_CONFIG_REGISTRATION: ComponentRegistration;