@ai-setting/roy-agent-core 1.3.10 → 1.3.14

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 (379) hide show
  1. package/dist/config/index.js +1647 -0
  2. package/dist/index.js +12579 -89691
  3. package/package.json +19 -56
  4. package/src/config/config-component.test.ts +0 -627
  5. package/src/config/config-component.ts +0 -906
  6. package/src/config/config-parser.test.ts +0 -319
  7. package/src/config/config-parser.ts +0 -203
  8. package/src/config/decentralized-config.test.ts +0 -740
  9. package/src/config/env-key.ts +0 -210
  10. package/src/config/env-source.test.ts +0 -252
  11. package/src/config/env-source.ts +0 -301
  12. package/src/config/file-source.test.ts +0 -357
  13. package/src/config/file-source.ts +0 -421
  14. package/src/config/index.ts +0 -24
  15. package/src/config/protocol-resolver.test.ts +0 -217
  16. package/src/config/protocol-resolver.ts +0 -228
  17. package/src/env/agent/agent-component.abort.test.ts +0 -511
  18. package/src/env/agent/agent-component.record-session.test.ts +0 -349
  19. package/src/env/agent/agent-component.test.ts +0 -1389
  20. package/src/env/agent/agent-component.tool-error.test.ts +0 -327
  21. package/src/env/agent/agent-component.ts +0 -1711
  22. package/src/env/agent/agent-config-registration.test.ts +0 -226
  23. package/src/env/agent/agent-config-registration.ts +0 -46
  24. package/src/env/agent/agent-reminder-plugin.integration.test.ts +0 -243
  25. package/src/env/agent/index.ts +0 -10
  26. package/src/env/agent/summary-agent.parse-hint.test.ts +0 -360
  27. package/src/env/agent/summary-agent.ts +0 -508
  28. package/src/env/agent/types.ts +0 -536
  29. package/src/env/commands/commands-component.test.ts +0 -364
  30. package/src/env/commands/commands-component.ts +0 -604
  31. package/src/env/commands/commands-config-registration.test.ts +0 -198
  32. package/src/env/commands/commands-config-registration.ts +0 -38
  33. package/src/env/commands/index.ts +0 -21
  34. package/src/env/commands/parser.test.ts +0 -203
  35. package/src/env/commands/parser.ts +0 -115
  36. package/src/env/commands/types.ts +0 -184
  37. package/src/env/commands-prompt-integration.test.ts +0 -243
  38. package/src/env/component-env.test.ts +0 -119
  39. package/src/env/component.ts +0 -335
  40. package/src/env/constants.test.ts +0 -72
  41. package/src/env/constants.ts +0 -123
  42. package/src/env/debug/debug-component.test.ts +0 -114
  43. package/src/env/debug/debug-component.ts +0 -547
  44. package/src/env/debug/formatters/index.ts +0 -9
  45. package/src/env/debug/formatters/repl-formatter.test.ts +0 -139
  46. package/src/env/debug/formatters/repl-formatter.ts +0 -358
  47. package/src/env/debug/formatters/trace-formatter.test.ts +0 -119
  48. package/src/env/debug/formatters/trace-formatter.ts +0 -191
  49. package/src/env/debug/formatters/tree-formatter.test.ts +0 -107
  50. package/src/env/debug/formatters/tree-formatter.ts +0 -325
  51. package/src/env/debug/index.ts +0 -38
  52. package/src/env/debug/parser/regex-parser.test.ts +0 -201
  53. package/src/env/debug/parser/regex-parser.ts +0 -196
  54. package/src/env/debug/parser/span-builder.test.ts +0 -241
  55. package/src/env/debug/parser/span-builder.ts +0 -386
  56. package/src/env/debug/reader/log-reader.test.ts +0 -170
  57. package/src/env/debug/reader/log-reader.ts +0 -186
  58. package/src/env/debug/reader/span-db-reader.test.ts +0 -118
  59. package/src/env/debug/reader/span-db-reader.ts +0 -201
  60. package/src/env/debug/types.test.ts +0 -187
  61. package/src/env/debug/types.ts +0 -171
  62. package/src/env/environment-init.test.ts +0 -183
  63. package/src/env/environment-lifecycle.test.ts +0 -516
  64. package/src/env/environment-service.test.ts +0 -332
  65. package/src/env/environment.handle-query.test.ts +0 -96
  66. package/src/env/environment.test.ts +0 -232
  67. package/src/env/environment.ts +0 -708
  68. package/src/env/errors.test.ts +0 -165
  69. package/src/env/errors.ts +0 -157
  70. package/src/env/event-source/event-source-agent-handler.test.ts +0 -193
  71. package/src/env/event-source/event-source-agent-handler.ts +0 -111
  72. package/src/env/event-source/event-source-component.process-cleanup.test.ts +0 -236
  73. package/src/env/event-source/event-source-component.stop.test.ts +0 -346
  74. package/src/env/event-source/event-source-component.test.ts +0 -1207
  75. package/src/env/event-source/event-source-component.ts +0 -1379
  76. package/src/env/event-source/event-source-config-registration.test.ts +0 -242
  77. package/src/env/event-source/event-source-config-registration.ts +0 -37
  78. package/src/env/event-source/event-source-integration.test.ts +0 -320
  79. package/src/env/event-source/event-source-platform.test.ts +0 -630
  80. package/src/env/event-source/types.ts +0 -298
  81. package/src/env/hook/global-hook-manager.ts +0 -162
  82. package/src/env/hook/hook-manager.test.ts +0 -374
  83. package/src/env/hook/hook-manager.ts +0 -309
  84. package/src/env/hook/index.ts +0 -38
  85. package/src/env/hook/types.ts +0 -138
  86. package/src/env/index.ts +0 -144
  87. package/src/env/interface.ts +0 -203
  88. package/src/env/llm/hooks.test.ts +0 -293
  89. package/src/env/llm/hooks.ts +0 -316
  90. package/src/env/llm/index.ts +0 -61
  91. package/src/env/llm/invoke-threshold-check.test.ts +0 -88
  92. package/src/env/llm/invoke-timeout.test.ts +0 -54
  93. package/src/env/llm/invoke.test.ts +0 -71
  94. package/src/env/llm/invoke.ts +0 -1039
  95. package/src/env/llm/llm-config.test.ts +0 -523
  96. package/src/env/llm/llm.test.ts +0 -233
  97. package/src/env/llm/llm.ts +0 -568
  98. package/src/env/llm/provider.test.ts +0 -182
  99. package/src/env/llm/provider.ts +0 -108
  100. package/src/env/llm/transform.test.ts +0 -251
  101. package/src/env/llm/transform.ts +0 -286
  102. package/src/env/llm/types.test.ts +0 -580
  103. package/src/env/llm/types.ts +0 -424
  104. package/src/env/log-trace/decorator-otel.test.ts +0 -182
  105. package/src/env/log-trace/decorator.ts +0 -230
  106. package/src/env/log-trace/index.ts +0 -79
  107. package/src/env/log-trace/log-trace-component.test.ts +0 -242
  108. package/src/env/log-trace/log-trace-component.ts +0 -497
  109. package/src/env/log-trace/log-trace-config-registration.test.ts +0 -348
  110. package/src/env/log-trace/log-trace-config-registration.ts +0 -45
  111. package/src/env/log-trace/logger.test.ts +0 -149
  112. package/src/env/log-trace/logger.ts +0 -522
  113. package/src/env/log-trace/opentelemetry/cli-propagation.test.ts +0 -147
  114. package/src/env/log-trace/opentelemetry/cli-propagation.ts +0 -194
  115. package/src/env/log-trace/opentelemetry/integration.test.ts +0 -668
  116. package/src/env/log-trace/opentelemetry/mod.ts +0 -25
  117. package/src/env/log-trace/opentelemetry/propagation-env.test.ts +0 -181
  118. package/src/env/log-trace/opentelemetry/propagation-env.ts +0 -136
  119. package/src/env/log-trace/opentelemetry/propagation.test.ts +0 -259
  120. package/src/env/log-trace/opentelemetry/propagation.ts +0 -215
  121. package/src/env/log-trace/opentelemetry/tracer-provider-context.test.ts +0 -166
  122. package/src/env/log-trace/opentelemetry/tracer-provider.test.ts +0 -379
  123. package/src/env/log-trace/opentelemetry/tracer-provider.ts +0 -612
  124. package/src/env/log-trace/span-storage.test.ts +0 -145
  125. package/src/env/log-trace/span-storage.ts +0 -230
  126. package/src/env/log-trace/trace-context.test.ts +0 -187
  127. package/src/env/log-trace/trace-context.ts +0 -162
  128. package/src/env/log-trace/types.test.ts +0 -63
  129. package/src/env/log-trace/types.ts +0 -172
  130. package/src/env/mcp/README.md +0 -244
  131. package/src/env/mcp/__integration__/mcp-component.integration.test.ts +0 -373
  132. package/src/env/mcp/config.test.ts +0 -74
  133. package/src/env/mcp/config.ts +0 -116
  134. package/src/env/mcp/index.ts +0 -41
  135. package/src/env/mcp/loader.test.ts +0 -161
  136. package/src/env/mcp/loader.ts +0 -209
  137. package/src/env/mcp/mcp-component.test.ts +0 -111
  138. package/src/env/mcp/mcp-component.ts +0 -358
  139. package/src/env/mcp/mcp-config-registration.test.ts +0 -304
  140. package/src/env/mcp/mcp-config-registration.ts +0 -50
  141. package/src/env/mcp/scanner.test.ts +0 -170
  142. package/src/env/mcp/scanner.ts +0 -246
  143. package/src/env/mcp/tool/adapter.test.ts +0 -520
  144. package/src/env/mcp/tool/adapter.ts +0 -521
  145. package/src/env/mcp/tool/index.ts +0 -5
  146. package/src/env/mcp/types.test.ts +0 -171
  147. package/src/env/mcp/types.ts +0 -79
  148. package/src/env/memory/README.md +0 -177
  149. package/src/env/memory/built-in/index.ts +0 -59
  150. package/src/env/memory/built-in/recall-memory.ts +0 -103
  151. package/src/env/memory/built-in/record-memory.ts +0 -148
  152. package/src/env/memory/index.ts +0 -20
  153. package/src/env/memory/memory-component.test.ts +0 -239
  154. package/src/env/memory/memory-component.ts +0 -503
  155. package/src/env/memory/memory-config-registration.test.ts +0 -67
  156. package/src/env/memory/memory-config-registration.ts +0 -48
  157. package/src/env/memory/memory-config.ts +0 -45
  158. package/src/env/memory/memory-file.test.ts +0 -268
  159. package/src/env/memory/plugin/index.ts +0 -48
  160. package/src/env/memory/plugin/memory-agent.test.ts +0 -249
  161. package/src/env/memory/plugin/memory-agent.ts +0 -365
  162. package/src/env/memory/plugin/memory-manager.ts +0 -198
  163. package/src/env/memory/plugin/memory-plugin-agent.test.ts +0 -145
  164. package/src/env/memory/plugin/memory-plugin.ts +0 -210
  165. package/src/env/memory/plugin/plugin-simplified.test.ts +0 -51
  166. package/src/env/memory/plugin/recall-memory.test.ts +0 -106
  167. package/src/env/memory/plugin/recall-memory.ts +0 -53
  168. package/src/env/memory/plugin/types.ts +0 -101
  169. package/src/env/memory/tools/memory-agent-tools.ts +0 -228
  170. package/src/env/memory/types.ts +0 -85
  171. package/src/env/paths.ts +0 -118
  172. package/src/env/prompt/index.ts +0 -18
  173. package/src/env/prompt/memory-prompts.test.ts +0 -91
  174. package/src/env/prompt/prompt-component.test.ts +0 -491
  175. package/src/env/prompt/prompt-component.ts +0 -619
  176. package/src/env/prompt/prompt-config-registration.test.ts +0 -213
  177. package/src/env/prompt/prompt-config-registration.ts +0 -39
  178. package/src/env/prompt/prompts-index.ts +0 -504
  179. package/src/env/prompt/renderer.ts +0 -67
  180. package/src/env/prompt/types.ts +0 -136
  181. package/src/env/session/hooks.ts +0 -18
  182. package/src/env/session/index.ts +0 -37
  183. package/src/env/session/search-query-parser.test.ts +0 -425
  184. package/src/env/session/search-query-parser.ts +0 -171
  185. package/src/env/session/session-checkpoint.test.ts +0 -523
  186. package/src/env/session/session-component.extract-recent-messages.test.ts +0 -209
  187. package/src/env/session/session-component.test.ts +0 -132
  188. package/src/env/session/session-component.ts +0 -1249
  189. package/src/env/session/session-config-registration.test.ts +0 -138
  190. package/src/env/session/session-config-registration.ts +0 -52
  191. package/src/env/session/session-message-converter.test.ts +0 -763
  192. package/src/env/session/session-message-converter.ts +0 -415
  193. package/src/env/session/session-message-e2e.test.ts +0 -448
  194. package/src/env/session/session-search.test.ts +0 -391
  195. package/src/env/session/session-store.test.ts +0 -362
  196. package/src/env/session/session-store.ts +0 -141
  197. package/src/env/session/storage/index.ts +0 -6
  198. package/src/env/session/storage/memory.ts +0 -502
  199. package/src/env/session/storage/sqlite.ts +0 -794
  200. package/src/env/session/types.ts +0 -742
  201. package/src/env/skill/config.ts +0 -39
  202. package/src/env/skill/index.ts +0 -6
  203. package/src/env/skill/parser.test.ts +0 -116
  204. package/src/env/skill/parser.ts +0 -77
  205. package/src/env/skill/scanner.test.ts +0 -211
  206. package/src/env/skill/scanner.ts +0 -119
  207. package/src/env/skill/skill-component.test.ts +0 -234
  208. package/src/env/skill/skill-component.ts +0 -352
  209. package/src/env/skill/skill-config-registration.test.ts +0 -60
  210. package/src/env/skill/skill-config-registration.ts +0 -43
  211. package/src/env/skill/tool/index.ts +0 -1
  212. package/src/env/skill/tool/skill-tool.test.ts +0 -100
  213. package/src/env/skill/tool/skill-tool.ts +0 -72
  214. package/src/env/skill/types.ts +0 -64
  215. package/src/env/task/delegate/delegate-tool.test.ts +0 -498
  216. package/src/env/task/delegate/delegate-tool.ts +0 -1014
  217. package/src/env/task/delegate/index.ts +0 -18
  218. package/src/env/task/delegate/stop-tool.test.ts +0 -140
  219. package/src/env/task/delegate/stop-tool.ts +0 -119
  220. package/src/env/task/delegate/task-events.test.ts +0 -178
  221. package/src/env/task/delegate/task-events.ts +0 -143
  222. package/src/env/task/hooks/contexts.test.ts +0 -92
  223. package/src/env/task/hooks/contexts.ts +0 -192
  224. package/src/env/task/hooks/index.ts +0 -23
  225. package/src/env/task/hooks/task-hook-points.test.ts +0 -32
  226. package/src/env/task/hooks/task-hook-points.ts +0 -54
  227. package/src/env/task/index.ts +0 -7
  228. package/src/env/task/plugins/index.ts +0 -13
  229. package/src/env/task/plugins/task-plugin.test.ts +0 -74
  230. package/src/env/task/plugins/task-plugin.ts +0 -89
  231. package/src/env/task/plugins/task-tag-plugin.test.ts +0 -377
  232. package/src/env/task/plugins/task-tag-plugin.ts +0 -319
  233. package/src/env/task/plugins/task-workflow-extractor.integration.test.ts +0 -226
  234. package/src/env/task/plugins/workflow-extractor-agent.test.ts +0 -107
  235. package/src/env/task/plugins/workflow-extractor-agent.ts +0 -225
  236. package/src/env/task/storage/index.ts +0 -6
  237. package/src/env/task/storage/sqlite-task-store.test.ts +0 -283
  238. package/src/env/task/storage/sqlite-task-store.ts +0 -903
  239. package/src/env/task/storage/task-search.test.ts +0 -291
  240. package/src/env/task/tag-service.test.ts +0 -198
  241. package/src/env/task/tag-service.ts +0 -264
  242. package/src/env/task/task-component.test.ts +0 -193
  243. package/src/env/task/task-component.ts +0 -658
  244. package/src/env/task/task-config-registration.test.ts +0 -57
  245. package/src/env/task/task-config-registration.ts +0 -37
  246. package/src/env/task/task-types.test.ts +0 -137
  247. package/src/env/task/tools/complete-tool.ts +0 -44
  248. package/src/env/task/tools/create-tool.ts +0 -49
  249. package/src/env/task/tools/delete-tool.ts +0 -43
  250. package/src/env/task/tools/get-tool.ts +0 -59
  251. package/src/env/task/tools/index.ts +0 -10
  252. package/src/env/task/tools/list-tool.ts +0 -40
  253. package/src/env/task/tools/operation/create-tool.ts +0 -48
  254. package/src/env/task/tools/operation/delete-tool.ts +0 -43
  255. package/src/env/task/tools/operation/get-tool.ts +0 -43
  256. package/src/env/task/tools/operation/index.ts +0 -9
  257. package/src/env/task/tools/operation/list-tool.ts +0 -40
  258. package/src/env/task/tools/operation/operation-tools.test.ts +0 -274
  259. package/src/env/task/tools/operation/operation-types.ts +0 -75
  260. package/src/env/task/tools/operation/update-tool.ts +0 -47
  261. package/src/env/task/tools/task-tools.test.ts +0 -203
  262. package/src/env/task/tools/task-types.test.ts +0 -75
  263. package/src/env/task/tools/task-types.ts +0 -68
  264. package/src/env/task/tools/update-tool.ts +0 -70
  265. package/src/env/task/types.ts +0 -160
  266. package/src/env/tool/built-in/bash.ts +0 -201
  267. package/src/env/tool/built-in/echo.ts +0 -29
  268. package/src/env/tool/built-in/edit-file.test.ts +0 -136
  269. package/src/env/tool/built-in/edit-file.ts +0 -92
  270. package/src/env/tool/built-in/glob.test.ts +0 -94
  271. package/src/env/tool/built-in/glob.ts +0 -65
  272. package/src/env/tool/built-in/grep.test.ts +0 -122
  273. package/src/env/tool/built-in/grep.ts +0 -108
  274. package/src/env/tool/built-in/index.ts +0 -44
  275. package/src/env/tool/built-in/read-file.test.ts +0 -84
  276. package/src/env/tool/built-in/read-file.ts +0 -75
  277. package/src/env/tool/built-in/write-file.test.ts +0 -119
  278. package/src/env/tool/built-in/write-file.ts +0 -68
  279. package/src/env/tool/index.ts +0 -24
  280. package/src/env/tool/registry.test.ts +0 -257
  281. package/src/env/tool/registry.ts +0 -167
  282. package/src/env/tool/tool-component.test.ts +0 -559
  283. package/src/env/tool/tool-component.ts +0 -563
  284. package/src/env/tool/tool-config-registration.test.ts +0 -249
  285. package/src/env/tool/tool-config-registration.ts +0 -46
  286. package/src/env/tool/types.ts +0 -267
  287. package/src/env/tool/validator.test.ts +0 -143
  288. package/src/env/tool/validator.ts +0 -44
  289. package/src/env/types.ts +0 -180
  290. package/src/env/workflow/ask-user-tool-registration.test.ts +0 -216
  291. package/src/env/workflow/complex-workflow.integration.test.ts +0 -1900
  292. package/src/env/workflow/decorators/decorator-node.ts +0 -229
  293. package/src/env/workflow/decorators/decorator.test.ts +0 -196
  294. package/src/env/workflow/decorators/edge.ts +0 -82
  295. package/src/env/workflow/decorators/index.ts +0 -31
  296. package/src/env/workflow/decorators/node-as.ts +0 -98
  297. package/src/env/workflow/decorators/workflow.ts +0 -54
  298. package/src/env/workflow/engine/dag-manager.test.ts +0 -570
  299. package/src/env/workflow/engine/dag-manager.ts +0 -594
  300. package/src/env/workflow/engine/engine.ts +0 -1422
  301. package/src/env/workflow/engine/event-bus.test.ts +0 -359
  302. package/src/env/workflow/engine/event-bus.ts +0 -156
  303. package/src/env/workflow/engine/executor-agent-session.test.ts +0 -84
  304. package/src/env/workflow/engine/executor.test.ts +0 -619
  305. package/src/env/workflow/engine/executor.ts +0 -593
  306. package/src/env/workflow/engine/index.ts +0 -24
  307. package/src/env/workflow/engine/node-registry.test.ts +0 -560
  308. package/src/env/workflow/engine/node-registry.ts +0 -289
  309. package/src/env/workflow/engine/resume-removed.test.ts +0 -22
  310. package/src/env/workflow/engine/scheduler.test.ts +0 -715
  311. package/src/env/workflow/engine/scheduler.ts +0 -318
  312. package/src/env/workflow/engine/workflow-engine.test.ts +0 -815
  313. package/src/env/workflow/extractor/workflow-converter.ts +0 -306
  314. package/src/env/workflow/fixtures.ts +0 -380
  315. package/src/env/workflow/index.ts +0 -38
  316. package/src/env/workflow/integration/run-resume-unified.test.ts +0 -186
  317. package/src/env/workflow/integration/service-integration.test.ts +0 -267
  318. package/src/env/workflow/metadata/keys.ts +0 -12
  319. package/src/env/workflow/nodes/agent-component-adapter.test.ts +0 -318
  320. package/src/env/workflow/nodes/agent-component-adapter.ts +0 -448
  321. package/src/env/workflow/nodes/agent-node.test.ts +0 -371
  322. package/src/env/workflow/nodes/agent-node.ts +0 -598
  323. package/src/env/workflow/nodes/ask-user-node.ts +0 -113
  324. package/src/env/workflow/nodes/condition-node.ts +0 -200
  325. package/src/env/workflow/nodes/index.ts +0 -9
  326. package/src/env/workflow/nodes/merge-node.ts +0 -141
  327. package/src/env/workflow/nodes/skill-node.test.ts +0 -253
  328. package/src/env/workflow/nodes/skill-node.ts +0 -393
  329. package/src/env/workflow/nodes/tool-node.test.ts +0 -251
  330. package/src/env/workflow/nodes/tool-node.ts +0 -493
  331. package/src/env/workflow/nodes/workflow-llm-history.test.ts +0 -455
  332. package/src/env/workflow/nodes/workflow-node.test.ts +0 -315
  333. package/src/env/workflow/nodes/workflow-node.ts +0 -311
  334. package/src/env/workflow/service/index.ts +0 -27
  335. package/src/env/workflow/service/registry.test.ts +0 -133
  336. package/src/env/workflow/service/registry.ts +0 -71
  337. package/src/env/workflow/service/workflow-service.test.ts +0 -310
  338. package/src/env/workflow/service/workflow-service.ts +0 -393
  339. package/src/env/workflow/storage/index.ts +0 -28
  340. package/src/env/workflow/storage/mock-repositories.ts +0 -385
  341. package/src/env/workflow/storage/sqlite.test.ts +0 -179
  342. package/src/env/workflow/storage/sqlite.ts +0 -163
  343. package/src/env/workflow/storage/workflow-repo.test.ts +0 -780
  344. package/src/env/workflow/storage/workflow-repo.ts +0 -342
  345. package/src/env/workflow/tools/ask-user-tool.ts +0 -82
  346. package/src/env/workflow/tools/index.ts +0 -26
  347. package/src/env/workflow/tools/run-workflow.test.ts +0 -352
  348. package/src/env/workflow/tools/run-workflow.ts +0 -214
  349. package/src/env/workflow/types/context.ts +0 -18
  350. package/src/env/workflow/types/decorators-types.ts +0 -198
  351. package/src/env/workflow/types/event.test.ts +0 -515
  352. package/src/env/workflow/types/event.ts +0 -193
  353. package/src/env/workflow/types/index.ts +0 -49
  354. package/src/env/workflow/types/run.test.ts +0 -437
  355. package/src/env/workflow/types/run.ts +0 -173
  356. package/src/env/workflow/types/workflow-hil.ts +0 -114
  357. package/src/env/workflow/types/workflow-message.test.ts +0 -138
  358. package/src/env/workflow/types/workflow-message.ts +0 -196
  359. package/src/env/workflow/types/workflow-session.test.ts +0 -95
  360. package/src/env/workflow/types/workflow-session.ts +0 -59
  361. package/src/env/workflow/types/workflow.test.ts +0 -495
  362. package/src/env/workflow/types/workflow.ts +0 -195
  363. package/src/env/workflow/types_compat.ts +0 -51
  364. package/src/env/workflow/utils/create-workflow.ts +0 -47
  365. package/src/env/workflow/utils/execution-state.ts +0 -245
  366. package/src/env/workflow/utils/index.ts +0 -18
  367. package/src/env/workflow/utils/node-registry-helper.ts +0 -58
  368. package/src/env/workflow/utils/recovery-validator.test.ts +0 -460
  369. package/src/env/workflow/utils/recovery-validator.ts +0 -377
  370. package/src/env/workflow/utils/session-parser.test.ts +0 -111
  371. package/src/env/workflow/utils/session-parser.ts +0 -94
  372. package/src/env/workflow/utils/session-recovery.test.ts +0 -334
  373. package/src/env/workflow/utils/session-recovery.ts +0 -188
  374. package/src/env/workflow/utils/template-resolver.test.ts +0 -258
  375. package/src/env/workflow/utils/template-resolver.ts +0 -436
  376. package/src/env/workflow/utils/validation-rules.ts +0 -149
  377. package/src/env/workflow/workflow-component.ts +0 -544
  378. package/src/index.ts +0 -422
  379. package/src/utils/id.ts +0 -21
@@ -1,455 +0,0 @@
1
- /**
2
- * @fileoverview Workflow LLM History Tests
3
- *
4
- * TDD 测试:验证 workflow 节点之间 LLM history 共享功能
5
- */
6
-
7
- import { describe, it, expect, beforeEach, vi } from 'bun:test';
8
- import type { ModelMessage } from "ai";
9
- import type { WorkflowHistoryMessage } from '../../agent/types';
10
-
11
- // Mock AgentComponent
12
- const createMockAgentComponent = () => ({
13
- registerAgent: vi.fn(),
14
- getAgent: vi.fn().mockReturnValue({ name: 'test-agent' }),
15
- listAgents: vi.fn().mockReturnValue([{ name: 'test-agent' }]),
16
- run: vi.fn().mockResolvedValue({
17
- finalText: 'test response',
18
- iterations: 1,
19
- toolCalls: [],
20
- }),
21
- });
22
-
23
- // Mock SessionComponent
24
- const createMockSessionComponent = () => ({
25
- create: vi.fn().mockResolvedValue({ id: 'agent_session_123' }),
26
- addMessage: vi.fn().mockResolvedValue('msg_123'),
27
- getMessages: vi.fn().mockResolvedValue([]),
28
- });
29
-
30
- describe('Workflow LLM History', () => {
31
- describe('AgentContext with workflowHistory', () => {
32
- it('should accept workflowHistory in AgentContext', () => {
33
- // 模拟 AgentContext 接口应该接受 workflowHistory 字段
34
- const context = {
35
- sessionId: 'test-session',
36
- workflowHistory: [
37
- { role: 'user', content: 'Hello from previous node' },
38
- { role: 'assistant', content: 'Response from previous node' },
39
- ] as WorkflowHistoryMessage[],
40
- };
41
-
42
- expect(context.workflowHistory).toBeDefined();
43
- expect(context.workflowHistory).toHaveLength(2);
44
- expect(context.workflowHistory![0].role).toBe('user');
45
- expect(context.workflowHistory![1].role).toBe('assistant');
46
- });
47
-
48
- it('should be optional in AgentContext', () => {
49
- // workflowHistory 应该是可选的
50
- const context: { sessionId: string; workflowHistory?: WorkflowHistoryMessage[] } = {
51
- sessionId: 'test-session',
52
- };
53
-
54
- expect(context.workflowHistory).toBeUndefined();
55
- });
56
-
57
- it('should have correct WorkflowHistoryMessage structure', () => {
58
- const message: WorkflowHistoryMessage = {
59
- role: 'user',
60
- content: 'Test message',
61
- toolCallId: 'call_123',
62
- toolName: 'test-tool',
63
- nodeId: 'node1',
64
- };
65
-
66
- expect(message.role).toBe('user');
67
- expect(message.content).toBe('Test message');
68
- expect(message.toolCallId).toBe('call_123');
69
- expect(message.toolName).toBe('test-tool');
70
- expect(message.nodeId).toBe('node1');
71
- });
72
- });
73
-
74
- describe('AgentComponentAdapter workflowHistory handling', () => {
75
- let mockAgentComponent: ReturnType<typeof createMockAgentComponent>;
76
- let mockSessionComponent: ReturnType<typeof createMockSessionComponent>;
77
- let AgentComponentAdapter: any;
78
-
79
- beforeEach(async () => {
80
- vi.clearAllMocks();
81
- mockAgentComponent = createMockAgentComponent();
82
- mockSessionComponent = createMockSessionComponent();
83
-
84
- // 动态导入以避免循环依赖问题
85
- const module = await import('./agent-component-adapter');
86
- AgentComponentAdapter = module.AgentComponentAdapter;
87
- });
88
-
89
- it('should receive workflowHistory in context when provided via config', async () => {
90
- const adapter = new AgentComponentAdapter(
91
- mockAgentComponent as any,
92
- {},
93
- mockSessionComponent as any
94
- );
95
-
96
- // 设置初始历史
97
- const workflowHistory: WorkflowHistoryMessage[] = [
98
- { role: 'user', content: 'Message 1' },
99
- { role: 'assistant', content: 'Response 1' },
100
- ];
101
-
102
- const config = {
103
- type: 'test-agent',
104
- prompt: 'Current task',
105
- nodeId: 'node1',
106
- runId: 'run1',
107
- workflowSessionId: 'workflow_run_1',
108
- workflowHistory, // 通过 config 传递 history
109
- };
110
-
111
- await adapter.run(config as any);
112
-
113
- // 验证 AgentComponent.run 被调用
114
- expect(mockAgentComponent.run).toHaveBeenCalled();
115
-
116
- // 验证 workflowHistory 被传递(通过检查 mock 被调用时的参数)
117
- const callArgs = mockAgentComponent.run.mock.calls[0];
118
- // AgentComponent.run(agentName, query, context) - 第三个参数是 context
119
- const context = callArgs[2];
120
- expect(context).toBeDefined();
121
- });
122
-
123
- it('should accumulate messages after agent execution', async () => {
124
- const adapter = new AgentComponentAdapter(
125
- mockAgentComponent as any,
126
- {},
127
- mockSessionComponent as any
128
- );
129
-
130
- // 模拟 agent 执行后产生的消息
131
- mockAgentComponent.run.mockResolvedValue({
132
- finalText: 'Agent response',
133
- iterations: 1,
134
- toolCalls: [],
135
- messages: [
136
- { role: 'user', content: 'Task 1' },
137
- { role: 'assistant', content: 'Agent response' },
138
- ],
139
- });
140
-
141
- const workflowHistory: WorkflowHistoryMessage[] = [
142
- { role: 'user', content: 'Previous task' },
143
- { role: 'assistant', content: 'Previous response' },
144
- ];
145
-
146
- const config = {
147
- type: 'test-agent',
148
- prompt: 'Current task',
149
- nodeId: 'node1',
150
- runId: 'run1',
151
- workflowHistory,
152
- };
153
-
154
- await adapter.run(config as any);
155
-
156
- // 验证返回结果包含生成的消息
157
- // 注意:这需要适配器从 agent 结果中提取消息并追加到 history
158
- // 这个测试验证了消息应该被累积的概念
159
- expect(mockAgentComponent.run).toHaveBeenCalled();
160
- });
161
- });
162
-
163
- describe('WorkflowEngine workflowHistory integration', () => {
164
- it('should maintain workflowHistory in ActiveRunState', () => {
165
- // 验证 ActiveRunState 应该包含 workflowHistory 字段
166
- // 这个测试描述了期望的设计
167
- const mockRunState = {
168
- runId: 'run_1',
169
- workflowHistory: [] as WorkflowHistoryMessage[],
170
- nodeOutputs: new Map(),
171
- };
172
-
173
- expect(mockRunState.workflowHistory).toBeDefined();
174
- expect(Array.isArray(mockRunState.workflowHistory)).toBe(true);
175
- });
176
-
177
- it('should add node messages to workflowHistory after execution', () => {
178
- // 模拟节点执行完成后的消息
179
- const workflowHistory: WorkflowHistoryMessage[] = [];
180
-
181
- const nodeResultMessages: WorkflowHistoryMessage[] = [
182
- { role: 'user', content: 'Node 1 task', nodeId: 'node1' },
183
- { role: 'assistant', content: 'Node 1 response', nodeId: 'node1' },
184
- ];
185
-
186
- // 累积到 workflowHistory
187
- workflowHistory.push(...nodeResultMessages);
188
-
189
- expect(workflowHistory).toHaveLength(2);
190
- expect(workflowHistory[0].nodeId).toBe('node1');
191
- });
192
-
193
- it('should pass accumulated history to next agent node', () => {
194
- // 模拟两个连续 agent 节点之间的 history 传递
195
- const historyAfterNode1: WorkflowHistoryMessage[] = [
196
- { role: 'user', content: 'Node 1 task' },
197
- { role: 'assistant', content: 'Node 1 response' },
198
- ];
199
-
200
- // Node 2 应该接收 Node 1 的历史
201
- const node2Context = {
202
- sessionId: 'workflow_run_1',
203
- workflowHistory: historyAfterNode1,
204
- };
205
-
206
- expect(node2Context.workflowHistory).toHaveLength(2);
207
- expect(node2Context.workflowHistory![0].content).toBe('Node 1 task');
208
- expect(node2Context.workflowHistory![1].content).toBe('Node 1 response');
209
- });
210
- });
211
-
212
- describe('Message transformation to LLM format', () => {
213
- it('should transform workflow messages to LLM format', () => {
214
- // Workflow 消息格式转换为 LLM 消息格式
215
- const workflowMessage: WorkflowHistoryMessage = {
216
- role: 'user',
217
- content: 'Test message',
218
- nodeId: 'node1',
219
- };
220
-
221
- const llmMessage: ModelMessage = {
222
- role: 'user',
223
- content: workflowMessage.content,
224
- };
225
-
226
- expect(llmMessage.role).toBe('user');
227
- expect(llmMessage.content).toBe('Test message');
228
- });
229
-
230
- it('should handle tool messages in LLM format', () => {
231
- const workflowToolMessage: WorkflowHistoryMessage = {
232
- role: 'tool',
233
- content: '{"result": "tool output"}',
234
- toolCallId: 'call_123',
235
- toolName: 'test-tool',
236
- };
237
-
238
- // 转换为 LLM 格式
239
- const llmMessage: ModelMessage = {
240
- role: 'tool',
241
- content: workflowToolMessage.content,
242
- };
243
-
244
- expect(llmMessage.role).toBe('tool');
245
- });
246
-
247
- it('should preserve message order in history', () => {
248
- const messages: WorkflowHistoryMessage[] = [
249
- { role: 'user', content: 'Message 1' },
250
- { role: 'assistant', content: 'Message 2' },
251
- { role: 'user', content: 'Message 3' },
252
- { role: 'tool', content: 'Tool result', toolCallId: 'call_1' },
253
- { role: 'assistant', content: 'Message 5' },
254
- ];
255
-
256
- // 验证顺序保持
257
- expect(messages[0].role).toBe('user');
258
- expect(messages[1].role).toBe('assistant');
259
- expect(messages[2].role).toBe('user');
260
- expect(messages[3].role).toBe('tool');
261
- expect(messages[4].role).toBe('assistant');
262
- });
263
- });
264
- });
265
-
266
- describe('Workflow LLM History - Integration Scenario', () => {
267
- it('should simulate full workflow with history accumulation', async () => {
268
- // 模拟完整 workflow 执行场景:
269
- // Node A (agent) -> Node B (agent) -> Node C (agent)
270
-
271
- const workflowHistory: WorkflowHistoryMessage[] = [];
272
-
273
- // Node A 执行
274
- const nodeAMessages: WorkflowHistoryMessage[] = [
275
- { role: 'user', content: 'Task for Node A', nodeId: 'nodeA' },
276
- { role: 'assistant', content: 'Response from Node A', nodeId: 'nodeA' },
277
- ];
278
- workflowHistory.push(...nodeAMessages);
279
-
280
- // Node B 执行(应该看到 Node A 的历史)
281
- expect(workflowHistory).toHaveLength(2);
282
- const nodeBContext = { workflowHistory };
283
- expect(nodeBContext.workflowHistory).toHaveLength(2);
284
-
285
- const nodeBMessages: WorkflowHistoryMessage[] = [
286
- { role: 'user', content: 'Task for Node B', nodeId: 'nodeB' },
287
- { role: 'assistant', content: 'Response from Node B', nodeId: 'nodeB' },
288
- ];
289
- workflowHistory.push(...nodeBMessages);
290
-
291
- // Node C 执行(应该看到 Node A 和 Node B 的历史)
292
- expect(workflowHistory).toHaveLength(4);
293
- const nodeCContext = { workflowHistory };
294
- expect(nodeCContext.workflowHistory).toHaveLength(4);
295
- expect(nodeCContext.workflowHistory![0].nodeId).toBe('nodeA');
296
- expect(nodeCContext.workflowHistory![2].nodeId).toBe('nodeB');
297
-
298
- const nodeCMessages: WorkflowHistoryMessage[] = [
299
- { role: 'user', content: 'Task for Node C', nodeId: 'nodeC' },
300
- { role: 'assistant', content: 'Response from Node C', nodeId: 'nodeC' },
301
- ];
302
- workflowHistory.push(...nodeCMessages);
303
-
304
- // 最终历史应该包含所有消息
305
- expect(workflowHistory).toHaveLength(6);
306
- expect(workflowHistory[5].nodeId).toBe('nodeC');
307
- });
308
-
309
- it('should pass workflowHistory through AgentNode execution', async () => {
310
- // 模拟 AgentNode 接收 workflowHistory 并传递给 agentRunner
311
- const mockRunner = {
312
- run: vi.fn().mockResolvedValue({
313
- output: 'agent output',
314
- messages: [
315
- { role: 'user', content: 'prompt' },
316
- { role: 'assistant', content: 'agent output' },
317
- ],
318
- }),
319
- };
320
-
321
- // 模拟 AgentNode
322
- const definition = {
323
- id: 'agent-node-1',
324
- type: 'agent',
325
- config: {
326
- agent_type: 'general',
327
- prompt: 'Do something',
328
- },
329
- };
330
-
331
- const context = {
332
- runId: 'run_1',
333
- sessionId: 'session_1',
334
- workflowName: 'test-workflow',
335
- nodeId: 'agent-node-1',
336
- input: {},
337
- previousOutputs: new Map(),
338
- nodeOutputs: new Map(),
339
- config: {},
340
- debug: false,
341
- eventBus: { publish: vi.fn() },
342
- workflowHistory: [
343
- { role: 'user' as const, content: 'Previous task', nodeId: 'previous-node' },
344
- { role: 'assistant' as const, content: 'Previous response', nodeId: 'previous-node' },
345
- ],
346
- };
347
-
348
- // 执行 AgentNode
349
- const { AgentNode } = await import('./agent-node');
350
- const node = new AgentNode(definition as any, mockRunner as any);
351
- const result = await node.execute(context as any);
352
-
353
- // 验证 runner 被调用时传入了 workflowHistory
354
- expect(mockRunner.run).toHaveBeenCalled();
355
- const callArgs = mockRunner.run.mock.calls[0][0];
356
- expect(callArgs.workflowHistory).toBe(context.workflowHistory);
357
- expect(callArgs.nodeId).toBe('agent-node-1');
358
-
359
- // 验证返回结果包含生成的消息
360
- expect(result.output).toBeDefined();
361
- expect(result.output.workflowHistory).toBeDefined();
362
- expect(result.output.workflowHistory).toHaveLength(2);
363
- });
364
-
365
- it('should convert workflow messages to LLM format in AgentComponent', () => {
366
- // 模拟 AgentComponent 将 workflowHistory 转换为 LLM 消息格式
367
- const workflowMessages: WorkflowHistoryMessage[] = [
368
- { role: 'user', content: 'Message 1', nodeId: 'node1' },
369
- { role: 'assistant', content: 'Message 2', nodeId: 'node1' },
370
- { role: 'tool', content: '{"result": "ok"}', toolCallId: 'call_1', toolName: 'test-tool', nodeId: 'node1' },
371
- { role: 'assistant', content: 'Message 3', nodeId: 'node1' },
372
- ];
373
-
374
- // 转换为 ModelMessage 格式(模拟 AgentComponent 的转换逻辑)
375
- const llmMessages = workflowMessages.map(msg => ({
376
- role: msg.role,
377
- content: msg.content,
378
- ...(msg.toolCallId ? { toolCallId: msg.toolCallId } : {}),
379
- ...(msg.toolName ? { toolName: msg.toolName } : {}),
380
- }));
381
-
382
- expect(llmMessages).toHaveLength(4);
383
- expect(llmMessages[0].role).toBe('user');
384
- expect(llmMessages[1].role).toBe('assistant');
385
- expect(llmMessages[2].role).toBe('tool');
386
- expect(llmMessages[2].toolCallId).toBe('call_1');
387
- expect(llmMessages[3].role).toBe('assistant');
388
- });
389
-
390
- it('should accumulate workflow history from node outputs in WorkflowEngine', () => {
391
- // 模拟 WorkflowEngine 的 node.completed 事件处理
392
- const workflowHistory: WorkflowHistoryMessage[] = [];
393
-
394
- // 模拟 Node A 完成,输出包含 workflowHistory
395
- const nodeAOutput = {
396
- result: 'Node A result',
397
- workflowHistory: [
398
- { role: 'user' as const, content: 'Task A' },
399
- { role: 'assistant' as const, content: 'Response A' },
400
- ],
401
- };
402
-
403
- // 模拟事件处理逻辑
404
- if (nodeAOutput && typeof nodeAOutput === 'object' && 'workflowHistory' in nodeAOutput) {
405
- const messages = (nodeAOutput as any).workflowHistory;
406
- if (Array.isArray(messages)) {
407
- workflowHistory.push(...messages);
408
- }
409
- }
410
-
411
- expect(workflowHistory).toHaveLength(2);
412
-
413
- // 模拟 Node B 完成,输出包含 workflowHistory
414
- const nodeBOutput = {
415
- result: 'Node B result',
416
- workflowHistory: [
417
- { role: 'user' as const, content: 'Task B' },
418
- { role: 'assistant' as const, content: 'Response B' },
419
- ],
420
- };
421
-
422
- // 模拟事件处理逻辑
423
- if (nodeBOutput && typeof nodeBOutput === 'object' && 'workflowHistory' in nodeBOutput) {
424
- const messages = (nodeBOutput as any).workflowHistory;
425
- if (Array.isArray(messages)) {
426
- workflowHistory.push(...messages);
427
- }
428
- }
429
-
430
- expect(workflowHistory).toHaveLength(4);
431
- expect(workflowHistory[0].content).toBe('Task A');
432
- expect(workflowHistory[2].content).toBe('Task B');
433
- });
434
-
435
- it('should skip workflowHistory accumulation for non-agent nodes', () => {
436
- // 模拟非 agent 节点(如 tool 节点)完成
437
- const workflowHistory: WorkflowHistoryMessage[] = [];
438
-
439
- // Tool 节点的输出不包含 workflowHistory
440
- const toolNodeOutput = {
441
- result: 'tool result',
442
- };
443
-
444
- // 模拟事件处理逻辑 - 不应该累积
445
- if (toolNodeOutput && typeof toolNodeOutput === 'object' && 'workflowHistory' in toolNodeOutput) {
446
- const messages = (toolNodeOutput as any).workflowHistory;
447
- if (Array.isArray(messages)) {
448
- workflowHistory.push(...messages);
449
- }
450
- }
451
-
452
- // workflowHistory 应该保持为空
453
- expect(workflowHistory).toHaveLength(0);
454
- });
455
- });