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

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 (367) 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/index.js +3 -3
  13. package/dist/env/agent/summary-agent.d.ts +44 -0
  14. package/dist/env/agent/types.d.ts +503 -0
  15. package/dist/env/commands/commands-component.d.ts +97 -0
  16. package/dist/env/commands/commands-config-registration.d.ts +19 -0
  17. package/dist/env/commands/index.d.ts +7 -0
  18. package/dist/env/commands/parser.d.ts +18 -0
  19. package/dist/env/commands/types.d.ts +133 -0
  20. package/dist/env/component.d.ts +186 -0
  21. package/dist/env/constants.d.ts +112 -0
  22. package/dist/env/context/env-context.d.ts +420 -0
  23. package/dist/env/context/env-event.d.ts +144 -0
  24. package/dist/env/context/index.d.ts +13 -0
  25. package/dist/env/debug/debug-component.d.ts +160 -0
  26. package/dist/env/debug/formatters/index.d.ts +8 -0
  27. package/dist/env/debug/formatters/repl-formatter.d.ts +80 -0
  28. package/dist/env/debug/formatters/trace-formatter.d.ts +43 -0
  29. package/dist/env/debug/formatters/tree-formatter.d.ts +72 -0
  30. package/dist/env/debug/index.d.ts +15 -0
  31. package/dist/env/debug/index.js +1 -1
  32. package/dist/env/debug/parser/regex-parser.d.ts +49 -0
  33. package/dist/env/debug/parser/span-builder.d.ts +79 -0
  34. package/dist/env/debug/reader/log-reader.d.ts +55 -0
  35. package/dist/env/debug/reader/span-db-reader.d.ts +70 -0
  36. package/dist/env/debug/types.d.ts +145 -0
  37. package/dist/env/environment.d.ts +185 -0
  38. package/dist/env/error-reply.d.ts +184 -0
  39. package/dist/env/errors.d.ts +120 -0
  40. package/dist/env/event-source/bounty-cli-handler.d.ts +42 -0
  41. package/dist/env/event-source/bounty-im-handler.d.ts +232 -0
  42. package/dist/env/event-source/event-source-component.d.ts +177 -0
  43. package/dist/env/event-source/event-source-config-registration.d.ts +18 -0
  44. package/dist/env/event-source/event-source-handlers.d.ts +472 -0
  45. package/dist/env/event-source/event-store.d.ts +110 -0
  46. package/dist/env/event-source/idempotency-key.d.ts +19 -0
  47. package/dist/env/event-source/index.d.ts +15 -0
  48. package/dist/env/event-source/index.js +6 -6
  49. package/dist/env/event-source/timer-handler.d.ts +74 -0
  50. package/dist/env/event-source/types.d.ts +803 -0
  51. package/dist/env/hook/global-hook-manager.d.ts +73 -0
  52. package/dist/env/hook/hook-manager.d.ts +139 -0
  53. package/dist/env/hook/index.d.ts +9 -0
  54. package/dist/env/hook/types.d.ts +107 -0
  55. package/dist/env/index.d.ts +24 -0
  56. package/dist/env/index.js +18 -18
  57. package/dist/env/interface.d.ts +156 -0
  58. package/dist/env/lark-mention-utils.d.ts +59 -0
  59. package/dist/env/llm/adapter-ai-sdk.d.ts +10 -0
  60. package/dist/env/llm/adapter-pi-ai.d.ts +184 -0
  61. package/dist/env/llm/adapter.d.ts +100 -0
  62. package/dist/env/llm/factory.d.ts +13 -0
  63. package/dist/env/llm/hooks.d.ts +150 -0
  64. package/dist/env/llm/index.d.ts +16 -0
  65. package/dist/env/llm/index.js +2 -2
  66. package/dist/env/llm/invoke.d.ts +304 -0
  67. package/dist/env/llm/llm-cache.d.ts +38 -0
  68. package/dist/env/llm/llm.d.ts +263 -0
  69. package/dist/env/llm/opencode-session.d.ts +79 -0
  70. package/dist/env/llm/provider.d.ts +40 -0
  71. package/dist/env/llm/reasoning-defense.d.ts +104 -0
  72. package/dist/env/llm/tool-args-parser.d.ts +77 -0
  73. package/dist/env/llm/tool-schema.d.ts +54 -0
  74. package/dist/env/llm/transform.d.ts +57 -0
  75. package/dist/env/llm/types.d.ts +844 -0
  76. package/dist/env/log-trace/decorator.d.ts +88 -0
  77. package/dist/env/log-trace/index.d.ts +14 -0
  78. package/dist/env/log-trace/log-trace-component.d.ts +268 -0
  79. package/dist/env/log-trace/log-trace-config-registration.d.ts +25 -0
  80. package/dist/env/log-trace/logger.d.ts +83 -0
  81. package/dist/env/log-trace/opentelemetry/cli-propagation.d.ts +105 -0
  82. package/dist/env/log-trace/opentelemetry/mod.d.ts +24 -0
  83. package/dist/env/log-trace/opentelemetry/propagation-env.d.ts +81 -0
  84. package/dist/env/log-trace/opentelemetry/propagation.d.ts +79 -0
  85. package/dist/env/log-trace/opentelemetry/tracer-provider.d.ts +157 -0
  86. package/dist/env/log-trace/span-storage.d.ts +37 -0
  87. package/dist/env/log-trace/trace-context.d.ts +28 -0
  88. package/dist/env/log-trace/types.d.ts +127 -0
  89. package/dist/env/mcp/command-resolver.d.ts +12 -0
  90. package/dist/env/mcp/config.d.ts +103 -0
  91. package/dist/env/mcp/index.d.ts +13 -0
  92. package/dist/env/mcp/loader.d.ts +78 -0
  93. package/dist/env/mcp/mcp-component.d.ts +54 -0
  94. package/dist/env/mcp/mcp-config-registration.d.ts +19 -0
  95. package/dist/env/mcp/npm-prefix/index.d.ts +17 -0
  96. package/dist/env/mcp/scanner.d.ts +38 -0
  97. package/dist/env/mcp/tool/adapter.d.ts +32 -0
  98. package/dist/env/mcp/tool/index.d.ts +4 -0
  99. package/dist/env/mcp/types.d.ts +131 -0
  100. package/dist/env/memory/built-in/index.d.ts +41 -0
  101. package/dist/env/memory/built-in/recall-memory.d.ts +29 -0
  102. package/dist/env/memory/built-in/record-memory.d.ts +44 -0
  103. package/dist/env/memory/index.d.ts +10 -0
  104. package/dist/env/memory/memory-component.d.ts +114 -0
  105. package/dist/env/memory/memory-config-registration.d.ts +18 -0
  106. package/dist/env/memory/memory-config.d.ts +18 -0
  107. package/dist/env/memory/plugin/index.d.ts +16 -0
  108. package/dist/env/memory/plugin/memory-agent.d.ts +126 -0
  109. package/dist/env/memory/plugin/memory-manager.d.ts +71 -0
  110. package/dist/env/memory/plugin/memory-plugin.d.ts +103 -0
  111. package/dist/env/memory/plugin/recall-memory.d.ts +16 -0
  112. package/dist/env/memory/plugin/types.d.ts +75 -0
  113. package/dist/env/memory/tools/memory-agent-tools.d.ts +109 -0
  114. package/dist/env/memory/types.d.ts +80 -0
  115. package/dist/env/paths.d.ts +46 -0
  116. package/dist/env/plugin/bounty-cli-notification-channel.d.ts +60 -0
  117. package/dist/env/plugin/event-bus-notification-channel.d.ts +50 -0
  118. package/dist/env/plugin/index.d.ts +13 -0
  119. package/dist/env/plugin/lark-cli-notification-channel.d.ts +61 -0
  120. package/dist/env/plugin/notification-channel.d.ts +143 -0
  121. package/dist/env/plugin/plugin-component.d.ts +232 -0
  122. package/dist/env/plugin/types.d.ts +146 -0
  123. package/dist/env/prompt/index.d.ts +7 -0
  124. package/dist/env/prompt/index.js +2 -2
  125. package/dist/env/prompt/prompt-component.d.ts +194 -0
  126. package/dist/env/prompt/prompt-config-registration.d.ts +18 -0
  127. package/dist/env/prompt/prompt-store.d.ts +26 -0
  128. package/dist/env/prompt/prompts-index.d.ts +146 -0
  129. package/dist/env/prompt/renderer.d.ts +21 -0
  130. package/dist/env/prompt/types.d.ts +176 -0
  131. package/dist/env/session/hooks.d.ts +14 -0
  132. package/dist/env/session/index.d.ts +19 -0
  133. package/dist/env/session/index.js +4 -4
  134. package/dist/env/session/search-query-parser.d.ts +41 -0
  135. package/dist/env/session/session-component.d.ts +464 -0
  136. package/dist/env/session/session-config-registration.d.ts +18 -0
  137. package/dist/env/session/session-id.d.ts +26 -0
  138. package/dist/env/session/session-message-converter.d.ts +142 -0
  139. package/dist/env/session/session-store.d.ts +188 -0
  140. package/dist/env/session/storage/index.d.ts +5 -0
  141. package/dist/env/session/storage/index.js +3 -3
  142. package/dist/env/session/storage/memory.d.ts +119 -0
  143. package/dist/env/session/storage/sqlite.d.ts +108 -0
  144. package/dist/env/session/types.d.ts +705 -0
  145. package/dist/env/session-tree-stopper.d.ts +79 -0
  146. package/dist/env/skill/config.d.ts +13 -0
  147. package/dist/env/skill/index.d.ts +6 -0
  148. package/dist/env/skill/parser.d.ts +9 -0
  149. package/dist/env/skill/scanner.d.ts +25 -0
  150. package/dist/env/skill/skill-component.d.ts +89 -0
  151. package/dist/env/skill/skill-config-registration.d.ts +18 -0
  152. package/dist/env/skill/tool/index.d.ts +1 -0
  153. package/dist/env/skill/tool/skill-tool.d.ts +15 -0
  154. package/dist/env/skill/types.d.ts +61 -0
  155. package/dist/env/task/backend/index.d.ts +24 -0
  156. package/dist/env/task/backend/index.js +702 -0
  157. package/dist/env/task/backend/roy-sidecar-task-port.d.ts +148 -0
  158. package/dist/env/task/backend/sqlite-task-port.d.ts +28 -0
  159. package/dist/env/task/backend/task-store-backend.d.ts +107 -0
  160. package/dist/env/task/backend/types.d.ts +282 -0
  161. package/dist/env/task/delegate/bg-task-id-storage.d.ts +9 -0
  162. package/dist/env/task/delegate/delegate-tool.d.ts +681 -0
  163. package/dist/env/task/delegate/index.d.ts +8 -0
  164. package/dist/env/task/delegate/index.js +2 -2
  165. package/dist/env/task/delegate/process-registry.d.ts +58 -0
  166. package/dist/env/task/delegate/stop-tool.d.ts +12 -0
  167. package/dist/env/task/delegate/subagent-resolver.d.ts +25 -0
  168. package/dist/env/task/events/index.d.ts +7 -0
  169. package/dist/env/task/events/task-event-payloads.d.ts +101 -0
  170. package/dist/env/task/events/task-event-types.d.ts +23 -0
  171. package/dist/env/task/hooks/contexts.d.ts +191 -0
  172. package/dist/env/task/hooks/index.d.ts +7 -0
  173. package/dist/env/task/hooks/task-hook-points.d.ts +42 -0
  174. package/dist/env/task/index.d.ts +7 -0
  175. package/dist/env/task/index.js +3 -3
  176. package/dist/env/task/plugins/auto-task-plugin.d.ts +38 -0
  177. package/dist/env/task/plugins/card-chat-routing.d.ts +88 -0
  178. package/dist/env/task/plugins/fake-user-message-helper.d.ts +90 -0
  179. package/dist/env/task/plugins/index.d.ts +8 -0
  180. package/dist/env/task/plugins/index.js +4 -4
  181. package/dist/env/task/plugins/lark-card-action-handler.d.ts +166 -0
  182. package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +600 -0
  183. package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +231 -0
  184. package/dist/env/task/plugins/max-iteration-reminder-plugin.d.ts +112 -0
  185. package/dist/env/task/plugins/per-task-group-chat-plugin.d.ts +561 -0
  186. package/dist/env/task/plugins/task-tag-plugin.d.ts +70 -0
  187. package/dist/env/task/plugins/workflow-extractor-agent.d.ts +43 -0
  188. package/dist/env/task/registry-hook-installer.d.ts +43 -0
  189. package/dist/env/task/storage/index.d.ts +5 -0
  190. package/dist/env/task/storage/migrations/001_add_project_path_context.d.ts +14 -0
  191. package/dist/env/task/storage/migrations/002_add_task_type.d.ts +14 -0
  192. package/dist/env/task/storage/migrations/003_add_process_description.d.ts +20 -0
  193. package/dist/env/task/storage/migrations/004_rename_action_to_milestone.d.ts +37 -0
  194. package/dist/env/task/storage/migrations/005_convert_blob_description_to_text.d.ts +51 -0
  195. package/dist/env/task/storage/sqlite-task-store.d.ts +241 -0
  196. package/dist/env/task/tag-service.d.ts +138 -0
  197. package/dist/env/task/task-child-context.d.ts +70 -0
  198. package/dist/env/task/task-component.d.ts +270 -0
  199. package/dist/env/task/task-config-registration.d.ts +19 -0
  200. package/dist/env/task/task-creation-registry.d.ts +181 -0
  201. package/dist/env/task/task-reuse-context.d.ts +52 -0
  202. package/dist/env/task/task-reuse-registry.d.ts +31 -0
  203. package/dist/env/task/tools/batch-archive-tool.d.ts +9 -0
  204. package/dist/env/task/tools/batch-delete-tool.d.ts +9 -0
  205. package/dist/env/task/tools/complete-tool.d.ts +12 -0
  206. package/dist/env/task/tools/create-tool.d.ts +6 -0
  207. package/dist/env/task/tools/delete-tool.d.ts +6 -0
  208. package/dist/env/task/tools/get-tool.d.ts +6 -0
  209. package/dist/env/task/tools/index.d.ts +13 -0
  210. package/dist/env/task/tools/list-tool.d.ts +6 -0
  211. package/dist/env/task/tools/operation/create-tool.d.ts +12 -0
  212. package/dist/env/task/tools/operation/delete-tool.d.ts +6 -0
  213. package/dist/env/task/tools/operation/get-tool.d.ts +6 -0
  214. package/dist/env/task/tools/operation/index.d.ts +8 -0
  215. package/dist/env/task/tools/operation/list-tool.d.ts +6 -0
  216. package/dist/env/task/tools/operation/operation-types.d.ts +225 -0
  217. package/dist/env/task/tools/operation/update-tool.d.ts +6 -0
  218. package/dist/env/task/tools/search-tool.d.ts +9 -0
  219. package/dist/env/task/tools/task-tree-tool.d.ts +65 -0
  220. package/dist/env/task/tools/task-types.d.ts +255 -0
  221. package/dist/env/task/tools/update-tool.d.ts +6 -0
  222. package/dist/env/task/types.d.ts +290 -0
  223. package/dist/env/tool/built-in/bash-effect.d.ts +36 -0
  224. package/dist/env/tool/built-in/bash.d.ts +16 -0
  225. package/dist/env/tool/built-in/echo.d.ts +7 -0
  226. package/dist/env/tool/built-in/edit-file.d.ts +6 -0
  227. package/dist/env/tool/built-in/glob.d.ts +6 -0
  228. package/dist/env/tool/built-in/grep.d.ts +6 -0
  229. package/dist/env/tool/built-in/index.d.ts +39 -0
  230. package/dist/env/tool/built-in/query-background-process-tool.d.ts +113 -0
  231. package/dist/env/tool/built-in/read-file.d.ts +5 -0
  232. package/dist/env/tool/built-in/understand-image.d.ts +59 -0
  233. package/dist/env/tool/built-in/write-file.d.ts +5 -0
  234. package/dist/env/tool/index.d.ts +16 -0
  235. package/dist/env/tool/registry.d.ts +61 -0
  236. package/dist/env/tool/tool-component.d.ts +242 -0
  237. package/dist/env/tool/tool-config-registration.d.ts +18 -0
  238. package/dist/env/tool/types.d.ts +274 -0
  239. package/dist/env/tool/validator.d.ts +14 -0
  240. package/dist/env/types.d.ts +184 -0
  241. package/dist/env/workflow/decorators/decorator-node.d.ts +76 -0
  242. package/dist/env/workflow/decorators/edge.d.ts +42 -0
  243. package/dist/env/workflow/decorators/index.d.ts +13 -0
  244. package/dist/env/workflow/decorators/node-as.d.ts +40 -0
  245. package/dist/env/workflow/decorators/workflow.d.ts +30 -0
  246. package/dist/env/workflow/engine/dag-manager.d.ts +176 -0
  247. package/dist/env/workflow/engine/engine.d.ts +440 -0
  248. package/dist/env/workflow/engine/event-bus.d.ts +54 -0
  249. package/dist/env/workflow/engine/executor.d.ts +122 -0
  250. package/dist/env/workflow/engine/index.d.ts +15 -0
  251. package/dist/env/workflow/engine/index.js +2 -2
  252. package/dist/env/workflow/engine/node-registry.d.ts +159 -0
  253. package/dist/env/workflow/engine/scheduler.d.ts +164 -0
  254. package/dist/env/workflow/extractor/workflow-converter.d.ts +55 -0
  255. package/dist/env/workflow/fixtures.d.ts +401 -0
  256. package/dist/env/workflow/hooks/index.d.ts +4 -0
  257. package/dist/env/workflow/hooks/workflow-hook-points.d.ts +161 -0
  258. package/dist/env/workflow/index.d.ts +30 -0
  259. package/dist/env/workflow/index.js +9 -9
  260. package/dist/env/workflow/metadata/keys.d.ts +6 -0
  261. package/dist/env/workflow/nodes/agent-component-adapter.d.ts +175 -0
  262. package/dist/env/workflow/nodes/agent-node.d.ts +206 -0
  263. package/dist/env/workflow/nodes/ask-user-node.d.ts +66 -0
  264. package/dist/env/workflow/nodes/condition-node.d.ts +39 -0
  265. package/dist/env/workflow/nodes/index.d.ts +8 -0
  266. package/dist/env/workflow/nodes/index.js +1 -1
  267. package/dist/env/workflow/nodes/merge-node.d.ts +40 -0
  268. package/dist/env/workflow/nodes/python-call-node.d.ts +95 -0
  269. package/dist/env/workflow/nodes/skill-node.d.ts +29 -0
  270. package/dist/env/workflow/nodes/tool-node.d.ts +64 -0
  271. package/dist/env/workflow/nodes/workflow-node.d.ts +118 -0
  272. package/dist/env/workflow/plugins/index.d.ts +6 -0
  273. package/dist/env/workflow/plugins/index.js +2 -2
  274. package/dist/env/workflow/plugins/lark-cli-workflow-notify-plugin.d.ts +107 -0
  275. package/dist/env/workflow/plugins/workflow-json-output-plugin.d.ts +166 -0
  276. package/dist/env/workflow/runtime/runtime-cancellation-scope.d.ts +121 -0
  277. package/dist/env/workflow/service/index.d.ts +9 -0
  278. package/dist/env/workflow/service/registry.d.ts +37 -0
  279. package/dist/env/workflow/service/workflow-service.d.ts +422 -0
  280. package/dist/env/workflow/storage/index.d.ts +11 -0
  281. package/dist/env/workflow/storage/mock-repositories.d.ts +106 -0
  282. package/dist/env/workflow/storage/safe-json.d.ts +62 -0
  283. package/dist/env/workflow/storage/sqlite.d.ts +57 -0
  284. package/dist/env/workflow/storage/tag-repo.d.ts +65 -0
  285. package/dist/env/workflow/storage/workflow-repo.d.ts +161 -0
  286. package/dist/env/workflow/tools/ask-user-tool.d.ts +35 -0
  287. package/dist/env/workflow/tools/index.d.ts +16 -0
  288. package/dist/env/workflow/tools/index.js +6 -6
  289. package/dist/env/workflow/tools/run-workflow.d.ts +130 -0
  290. package/dist/env/workflow/tools/submit-json-output-tool.d.ts +38 -0
  291. package/dist/env/workflow/tools/workflow-add-tool.d.ts +47 -0
  292. package/dist/env/workflow/tools/workflow-get-tool.d.ts +29 -0
  293. package/dist/env/workflow/tools/workflow-list-tool.d.ts +55 -0
  294. package/dist/env/workflow/tools/workflow-run-status-tool.d.ts +26 -0
  295. package/dist/env/workflow/tools/workflow-run-stop-tool.d.ts +29 -0
  296. package/dist/env/workflow/tools/workflow-search-tool.d.ts +33 -0
  297. package/dist/env/workflow/tools/workflow-tag-list-tool.d.ts +59 -0
  298. package/dist/env/workflow/tools/workflow-validate-tool.d.ts +69 -0
  299. package/dist/env/workflow/types/context.d.ts +17 -0
  300. package/dist/env/workflow/types/decorators-types.d.ts +182 -0
  301. package/dist/env/workflow/types/edge.d.ts +33 -0
  302. package/dist/env/workflow/types/event.d.ts +869 -0
  303. package/dist/env/workflow/types/index.d.ts +16 -0
  304. package/dist/env/workflow/types/run.d.ts +254 -0
  305. package/dist/env/workflow/types/workflow-error.d.ts +79 -0
  306. package/dist/env/workflow/types/workflow-hil.d.ts +57 -0
  307. package/dist/env/workflow/types/workflow-message.d.ts +193 -0
  308. package/dist/env/workflow/types/workflow-session.d.ts +17 -0
  309. package/dist/env/workflow/types/workflow.d.ts +654 -0
  310. package/dist/env/workflow/types_compat.d.ts +10 -0
  311. package/dist/env/workflow/utils/agent-session-metadata.d.ts +48 -0
  312. package/dist/env/workflow/utils/build-agent-node-output.d.ts +11 -0
  313. package/dist/env/workflow/utils/create-workflow.d.ts +35 -0
  314. package/dist/env/workflow/utils/dependency-prescan.d.ts +67 -0
  315. package/dist/env/workflow/utils/execution-state.d.ts +46 -0
  316. package/dist/env/workflow/utils/extract-agent-json-output.d.ts +6 -0
  317. package/dist/env/workflow/utils/index.d.ts +14 -0
  318. package/dist/env/workflow/utils/index.js +1 -1
  319. package/dist/env/workflow/utils/json-schema-to-zod.d.ts +23 -0
  320. package/dist/env/workflow/utils/node-id-utils.d.ts +20 -0
  321. package/dist/env/workflow/utils/node-output-contracts.d.ts +137 -0
  322. package/dist/env/workflow/utils/node-registry-helper.d.ts +36 -0
  323. package/dist/env/workflow/utils/output-schema-hint.d.ts +7 -0
  324. package/dist/env/workflow/utils/parse-agent-output-config.d.ts +9 -0
  325. package/dist/env/workflow/utils/recovery-validator.d.ts +30 -0
  326. package/dist/env/workflow/utils/redact-command-secrets.d.ts +70 -0
  327. package/dist/env/workflow/utils/sensitive-redact.d.ts +37 -0
  328. package/dist/env/workflow/utils/session-parser.d.ts +23 -0
  329. package/dist/env/workflow/utils/session-recovery.d.ts +122 -0
  330. package/dist/env/workflow/utils/shell-dialect-lint.d.ts +75 -0
  331. package/dist/env/workflow/utils/template-contract-validator.d.ts +87 -0
  332. package/dist/env/workflow/utils/template-resolver.d.ts +285 -0
  333. package/dist/env/workflow/utils/validate-workflow-definition.d.ts +79 -0
  334. package/dist/env/workflow/utils/validation-rules.d.ts +103 -0
  335. package/dist/env/workflow/utils/workflow-message-metadata.d.ts +20 -0
  336. package/dist/env/workflow/utils/workflow-sanitize.d.ts +51 -0
  337. package/dist/env/workflow/workflow-component.d.ts +138 -0
  338. package/dist/index.d.ts +59 -0
  339. package/dist/index.js +21 -21
  340. package/dist/shared/@ai-setting/{roy-agent-core-stnddvx9.js → roy-agent-core-12d2xap8.js} +1 -1
  341. package/dist/shared/@ai-setting/{roy-agent-core-pk1b3kvf.js → roy-agent-core-2b8jtv7m.js} +1 -1
  342. package/dist/shared/@ai-setting/{roy-agent-core-x8n1r7h4.js → roy-agent-core-2bscfrr1.js} +188 -7
  343. package/dist/shared/@ai-setting/{roy-agent-core-gdsqp6j8.js → roy-agent-core-6masakz4.js} +45 -0
  344. package/dist/shared/@ai-setting/{roy-agent-core-vvxb9522.js → roy-agent-core-6qxh4xrm.js} +67 -6
  345. package/dist/shared/@ai-setting/{roy-agent-core-h93v6p6y.js → roy-agent-core-7qy3nffr.js} +2 -2
  346. package/dist/shared/@ai-setting/{roy-agent-core-s214vmmd.js → roy-agent-core-8eqngasy.js} +2 -2
  347. package/dist/shared/@ai-setting/{roy-agent-core-brwzs8wf.js → roy-agent-core-9h72sk1n.js} +1 -1
  348. package/dist/shared/@ai-setting/{roy-agent-core-na73mym1.js → roy-agent-core-a4vzsn0g.js} +212 -1
  349. package/dist/shared/@ai-setting/{roy-agent-core-35s1w7tc.js → roy-agent-core-aer5kw1j.js} +142 -70
  350. package/dist/shared/@ai-setting/{roy-agent-core-j8e92gj8.js → roy-agent-core-b5ew8t0k.js} +0 -59
  351. package/dist/shared/@ai-setting/{roy-agent-core-rcfewbzr.js → roy-agent-core-cd62e9p1.js} +1 -1
  352. package/dist/shared/@ai-setting/{roy-agent-core-39xejr39.js → roy-agent-core-e2z1etk4.js} +1 -1
  353. package/dist/shared/@ai-setting/{roy-agent-core-pkpkctvf.js → roy-agent-core-g36jevrk.js} +14 -183
  354. package/dist/shared/@ai-setting/{roy-agent-core-ezgsem94.js → roy-agent-core-j2nvedt6.js} +465 -128
  355. package/dist/shared/@ai-setting/{roy-agent-core-p2r27era.js → roy-agent-core-mxdc756a.js} +1 -1
  356. package/dist/shared/@ai-setting/{roy-agent-core-p8ak03s0.js → roy-agent-core-w527pcpe.js} +293 -42
  357. package/dist/shared/@ai-setting/{roy-agent-core-3tv1q6f2.js → roy-agent-core-ytr2w0vb.js} +2 -2
  358. package/dist/shared/@ai-setting/{roy-agent-core-yd21n6c7.js → roy-agent-core-zvemdfx5.js} +1 -1
  359. package/dist/test-utils/child-process-mock.d.ts +73 -0
  360. package/dist/util/process/process-tree-killer.d.ts +67 -0
  361. package/dist/utils/id.d.ts +11 -0
  362. package/dist/utils/loose-json.d.ts +30 -0
  363. package/dist/utils/media.d.ts +70 -0
  364. package/dist/utils/temp-file-manager/index.d.ts +99 -0
  365. package/package.json +5 -3
  366. /package/dist/shared/@ai-setting/{roy-agent-core-zy3hqfwg.js → roy-agent-core-0hq21px2.js} +0 -0
  367. /package/dist/shared/@ai-setting/{roy-agent-core-0cfaqnz9.js → roy-agent-core-k25gv86p.js} +0 -0
@@ -0,0 +1,304 @@
1
+ /**
2
+ * @fileoverview LLM invocation with AI SDK integration.
3
+ *
4
+ * This module provides LLM invocation using AI SDK for better provider support.
5
+ * Stream events are published via Environment.pushEnvEvent().
6
+ */
7
+ import { type ModelMessage } from "ai";
8
+ import type { ToolInfo, ToolResult, LLMOutput, LLMMessage, ProviderCapabilities } from "./types";
9
+ import type { Environment } from "../interface";
10
+ import { __clearOpencodeSessionIdCache } from "./opencode-session";
11
+ /**
12
+ * Re-exported for backwards compatibility with existing tests
13
+ * (`packages/core/test/llm/opencode-go-interactive.test.ts`). The implementation
14
+ * now lives in `opencode-session.ts` so the default PiAiAdapter path can share it.
15
+ */
16
+ export { __clearOpencodeSessionIdCache };
17
+ /**
18
+ * Invoke LLM 配置
19
+ */
20
+ export interface InvokeConfig {
21
+ /** 模型标识符(格式: providerId/modelId) */
22
+ model: string;
23
+ /** Base URL */
24
+ baseURL?: string;
25
+ /** API Key */
26
+ apiKey: string;
27
+ /**
28
+ * Provider capabilities from config (`llm.providers.<id>.capabilities`).
29
+ *
30
+ * Task #4403: declared here so `LLMComponent.invoke()` can forward it to
31
+ * `ChatRequest.capabilities` without an `as any` cast. Typed as the full
32
+ * `ProviderCapabilities` shape (not just `{ reasoning?: boolean }`) because
33
+ * the runtime value is the whole object from config.
34
+ */
35
+ capabilities?: ProviderCapabilities;
36
+ /** 额外选项 */
37
+ options?: {
38
+ /**
39
+ * 文本内嵌思考标签处理配置
40
+ *
41
+ * 对齐 `ProviderCapabilities.thinkingInText` (`packages/core/src/env/llm/types.ts`):
42
+ * - `enabled`: 是否启用标签剥离
43
+ * - `tags`: 标签名列表(例如 `["think"]` → `""`)
44
+ * - `removeFromOutput`: 剥离后是否从返回值中移除(`false` 则保留原始含标签内容,
45
+ * 便于维持消息历史中的推理连续性,例如 MiniMax 需要看历史中的标签才会继续输出 reasoning)
46
+ */
47
+ thinkingInText?: {
48
+ enabled?: boolean;
49
+ tags?: string[];
50
+ removeFromOutput?: boolean;
51
+ };
52
+ };
53
+ }
54
+ /**
55
+ * LLM 选项
56
+ */
57
+ export interface InvokeOptions {
58
+ /** 消息列表 */
59
+ messages: LLMMessage[];
60
+ /** 工具列表 */
61
+ tools?: ToolInfo[];
62
+ /** 模型标识符(可选) */
63
+ model?: string;
64
+ /** 温度参数 */
65
+ temperature?: number;
66
+ /** 最大 Token 数 */
67
+ maxTokens?: number;
68
+ /** Environment 实例(用于发布流式事件,可选) */
69
+ env?: Environment;
70
+ /** 上下文信息(用于事件元数据) */
71
+ context?: {
72
+ /** Session ID */
73
+ sessionId?: string;
74
+ /** Message ID */
75
+ messageId?: string;
76
+ };
77
+ /**
78
+ * 工具选择策略(强制 LLM 调用特定工具)
79
+ *
80
+ * - "auto" — LLM 自主决定(默认)
81
+ * - "none" — 禁止调用任何工具
82
+ * - "required" — 必须调用至少一个工具(Issue #1694: 确保 json-extract 必须调用 workflow_submit_output)
83
+ * - { type: "function", function: { name: "..." } } — 强制调用指定工具
84
+ */
85
+ toolChoice?: "auto" | "none" | "required" | {
86
+ type: "function";
87
+ function: {
88
+ name: string;
89
+ };
90
+ };
91
+ }
92
+ /**
93
+ * LLM Tool Context - Context for tool calls during LLM invocation
94
+ */
95
+ export interface LLMToolContext {
96
+ /** Abort Signal */
97
+ abort?: AbortSignal | undefined;
98
+ /** 额外上下文 */
99
+ context?: Record<string, unknown>;
100
+ }
101
+ /**
102
+ * Usage 信息(AI SDK 格式)
103
+ * 参考: LanguageModelV3Usage from @ai-sdk/provider
104
+ */
105
+ interface AISDKUsage {
106
+ inputTokens?: {
107
+ total?: number;
108
+ noCache?: number;
109
+ cacheRead?: number;
110
+ cacheWrite?: number;
111
+ [key: string]: unknown;
112
+ };
113
+ outputTokens?: {
114
+ total?: number;
115
+ [key: string]: unknown;
116
+ };
117
+ totalTokens?: number;
118
+ promptTokens?: number;
119
+ completionTokens?: number;
120
+ inputTokenDetails?: {
121
+ tokens?: number;
122
+ [key: string]: unknown;
123
+ };
124
+ outputTokenDetails?: {
125
+ tokens?: number;
126
+ [key: string]: unknown;
127
+ };
128
+ raw?: {
129
+ total_tokens?: number;
130
+ prompt_tokens?: number;
131
+ completion_tokens?: number;
132
+ };
133
+ }
134
+ /**
135
+ * Usage 信息转换
136
+ */
137
+ export interface ConvertedUsageInfo {
138
+ /** Prompt Token 数 */
139
+ promptTokens: number;
140
+ /** Completion Token 数 */
141
+ completionTokens: number;
142
+ /** 总 Token 数 */
143
+ totalTokens: number;
144
+ /**
145
+ * Anthropic prompt cache read tokens (cache_read_input_tokens).
146
+ * `undefined` when the provider did not report a cache-read field.
147
+ * `0` means the cache was checked but no tokens hit (distinct from
148
+ * the field being absent).
149
+ */
150
+ cacheRead?: number;
151
+ /**
152
+ * Anthropic prompt cache write tokens (cache_creation_input_tokens).
153
+ * See {@link cacheRead} for semantics.
154
+ */
155
+ cacheWrite?: number;
156
+ }
157
+ /**
158
+ * 超时错误
159
+ */
160
+ export declare class TimeoutError extends Error {
161
+ readonly timeout: number;
162
+ constructor(message: string, timeout: number);
163
+ }
164
+ /**
165
+ * 带超时的 Promise 包装器
166
+ *
167
+ * @param promise 要执行的 Promise
168
+ * @param timeoutMs 超时时间(毫秒)
169
+ * @param message 自定义错误消息
170
+ * @returns Promise 结果
171
+ * @throws TimeoutError 当超时时
172
+ */
173
+ export declare function withTimeout<T>(promise: Promise<T>, timeoutMs?: number, message?: string): Promise<T>;
174
+ /**
175
+ * 解析模型字符串
176
+ * 格式: "providerId/modelId"
177
+ */
178
+ export declare function parseModelString(model?: string): {
179
+ providerId: string;
180
+ modelId: string;
181
+ };
182
+ /**
183
+ * 从 Usage 信息提取标准格式
184
+ *
185
+ * I4 (review-cache-stability.md): now exposes `cacheRead` / `cacheWrite` so
186
+ * callers can observe Anthropic prompt cache effectiveness.
187
+ *
188
+ * AI SDK v3 usage shape places cache tokens at two possible locations:
189
+ * 1. `usage.inputTokens.cacheRead` / `usage.inputTokens.cacheWrite`
190
+ * (modern LanguageModelV3Usage object form)
191
+ * 2. `usage.inputTokenDetails.cacheReadTokens` / `cacheWriteTokens`
192
+ * (legacy / MiniMax / DeepSeek form)
193
+ *
194
+ * We check the modern form first and fall back to the legacy form.
195
+ * A reported `0` is preserved (the cache was checked, no hit);
196
+ * `undefined` means the provider did not report the field at all.
197
+ */
198
+ export declare function extractUsageInfo(usage: AISDKUsage | undefined): ConvertedUsageInfo | undefined;
199
+ /**
200
+ * 计算 prompt cache 命中率(0..1)。
201
+ *
202
+ * Task #4373:这是把「roy-agent 自己的缓存命中」变成可观测量的关键 helper。
203
+ *
204
+ * ⚠️ 语义陷阱(上一轮 #4369 已经踩过一次):
205
+ *
206
+ * pi-ai 上报的 `promptTokens` 是 **已扣除缓存后的新增量**:
207
+ * `input = max(0, prompt_tokens - cacheRead - cacheWrite)`
208
+ * `totalTokens = input + output + cacheRead + cacheWrite`
209
+ * (见 `pi-ai/dist/providers/openai-completions.js::parseChunkUsage`、
210
+ * 以及 `anthropic.js` 的 message_start 分支——同样把 cacheRead /
211
+ * cacheWrite 单独累加进 totalTokens)
212
+ *
213
+ * 所以 `cacheRead / promptTokens` 在真实暖流数据下会算出 20,960%
214
+ * 这种荒谬值。正确的分母是「模型实际处理过的全部 input token」:
215
+ *
216
+ * promptTokensTotal = promptTokens + cacheRead + cacheWrite
217
+ * hitRate = cacheRead / promptTokensTotal
218
+ *
219
+ * @param usage - 至少包含 promptTokens;cache 字段可选
220
+ * @returns 0..1 之间的命中率。无缓存信息 / 无 input token 时返回 0(不是 NaN)
221
+ */
222
+ export declare function computeCacheHitRate(usage: {
223
+ promptTokens: number;
224
+ /** Cache-aware denominator; when present it wins over the derivation below. */
225
+ promptTokensTotal?: number;
226
+ cacheRead?: number;
227
+ cacheWrite?: number;
228
+ cacheMiss?: number;
229
+ }): number;
230
+ /**
231
+ * Recursively sort object keys for deterministic byte serialization.
232
+ *
233
+ * I2 (review-cache-stability.md): the LLM may emit the same tool call
234
+ * with keys in different orders across turns (e.g. `{a:1,b:2}` vs
235
+ * `{b:2,a:1}`). AI SDK internally JSON.stringifies tool-call `input`
236
+ * before forwarding to Anthropic — if the key order shifts, the cache
237
+ * prefix changes and Anthropic reports a cache miss.
238
+ *
239
+ * Sorting keys before JSON.stringify (or before handing to AI SDK)
240
+ * guarantees the bytes are deterministic regardless of LLM key order.
241
+ *
242
+ * Behavioral notes:
243
+ * - Arrays preserve their order (element order is semantically meaningful).
244
+ * - Uint8Array / Buffer are returned by identity (we don't try to sort
245
+ * their bytes — that would be lossy and impossible for binary data).
246
+ * - Primitives (string, number, boolean, null, undefined) pass through.
247
+ *
248
+ * @see https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
249
+ */
250
+ export declare function sortObjectKeysDeep<T>(obj: T, seen?: WeakSet<object>): T;
251
+ export { applyToolCacheControl, canonicalizeParts } from "./llm-cache";
252
+ /**
253
+ * 将 LLMMessage 转换为 AI SDK 格式
254
+ *
255
+ * I1 (review-cache-stability.md): inserts Anthropic prompt-cache breakpoints
256
+ * on the system message and the last user message. Without these, Anthropic
257
+ * never caches anything and we pay full input price every turn.
258
+ *
259
+ * Task #2748 §5.3: 支持 sessionId 参数,给 OpenAI-Compatible provider
260
+ * 注入 prompt_cache_key=sessionId。
261
+ */
262
+ export declare function convertToSDKMessages(messages: LLMMessage[], options?: {
263
+ sessionId?: string;
264
+ provider?: string;
265
+ }): ModelMessage[];
266
+ /**
267
+ * 从 AI SDK stream part 提取文本增量(兼容 text / delta 字段)
268
+ */
269
+ export declare function getStreamPartText(part: Record<string, unknown>): string;
270
+ /**
271
+ * 核心 LLM 调用函数
272
+ * 使用 AI SDK 的 streamText
273
+ *
274
+ * 流式事件通过 env.pushEnvEvent() 发布
275
+ *
276
+ * @param config - Invoke 配置
277
+ * @param options - LLM 选项
278
+ * @param ctx - Tool Context
279
+ * @returns ToolResult
280
+ */
281
+ export declare function invoke(config: InvokeConfig, options: InvokeOptions, ctx: LLMToolContext): Promise<ToolResult>;
282
+ /**
283
+ * 创建 Provider 实例
284
+ * 根据 providerId 创建对应的 AI SDK Provider
285
+ */
286
+ declare function createProviderInstance(providerId: string, apiKey: string, baseURL?: string, conversationId?: string): any;
287
+ /**
288
+ * Test-only re-export of createProviderInstance so that unit tests can verify
289
+ * header injection behavior without booting the full invoke() stack.
290
+ *
291
+ * This is gated by an explicit `__` prefix to make it obvious in code review
292
+ * that this surface is for tests only. Production code MUST NOT import this.
293
+ */
294
+ export declare const __createProviderInstanceForTest: typeof createProviderInstance;
295
+ /**
296
+ * 非流式 LLM 调用
297
+ *
298
+ * 使用 AI SDK 的 generateText API,返回完整响应
299
+ */
300
+ export declare function invokeNonStream(config: InvokeConfig, options: InvokeOptions, ctx: LLMToolContext): Promise<LLMOutput>;
301
+ /**
302
+ * 创建 LLM 配置
303
+ */
304
+ export declare function createInvokeConfig(model: string, apiKey: string, baseURL?: string): InvokeConfig;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @fileoverview LLM Cache Options Helpers (Task #2748 §5.3-5.5)
3
+ *
4
+ * 4 项 cache 优化相关的 helper 集中在此模块:
5
+ * - §5.3: OpenAI-Compatible prompt_cache_key
6
+ * - §5.4: Tool schema cache_control (Anthropic)
7
+ * - §5.5: parts JSON canonicalize
8
+ *
9
+ * 集中导出便于复用、单元测试、独立演进。
10
+ */
11
+ /**
12
+ * §5.3: OpenAI-Compatible provider 的 prompt_cache_key
13
+ *
14
+ * Anthropic 端用 cache_control; OpenAI 端用 prompt_cache_key。
15
+ * roy-agent 当前完全没给 OpenAI-Compatible (minimax/DeepSeek/GLM) 挂这个,
16
+ * 导致这些 provider 的 cache 完全靠隐式行为,命中率低。
17
+ *
18
+ * 参考 pi-agent: openai-completions.ts:680-695 (prompt_cache_key=sessionId)
19
+ */
20
+ export declare function isOpenAICompatibleProvider(providerName: string): boolean;
21
+ export declare function clampOpenAIPromptCacheKey(sessionId: string, maxLen?: number): string;
22
+ export declare function buildOpenAICompatProviderOptions(sessionId: string | undefined, cacheRetention?: "short" | "long" | "none"): Record<string, unknown>;
23
+ /**
24
+ * §5.4: 给工具 schema 的末 tool 挂 cache_control (Anthropic 3 层)
25
+ *
26
+ * pi-agent: anthropic-messages.ts:1005 (compat.supportsCacheControlOnTools ? cacheControl : undefined)
27
+ * 收益:工具 schema 大的 agent 多省 10-30% input cost。
28
+ */
29
+ export declare function applyToolCacheControl<T extends Record<string, unknown>>(tools: T[] | undefined, providerName: string): T[] | undefined;
30
+ /**
31
+ * §5.5: parts JSON canonicalize
32
+ *
33
+ * SQLite 存 parts 为 JSON 字符串,读出来时 JSON.parse 的 key 顺序不保证稳定。
34
+ * 在写入时对 parts 做 sortObjectKeysDeep → byte-stable 序列化。
35
+ *
36
+ * 同时也处理 tool-call arguments 字符串(如果是 string,需要 parse → sort → stringify)。
37
+ */
38
+ export declare function canonicalizeParts(parts: unknown): string;
@@ -0,0 +1,263 @@
1
+ import { BaseComponent, type ComponentConfig } from "../component";
2
+ import { type LLMConfig, type LLMInvokeRequest, type LLMInvokeResult, type ModelLimits } from "./types";
3
+ import type { LLMAdapter } from "./adapter";
4
+ import type { ConfigComponent } from "../../config/config-component";
5
+ import { ContextError } from "../errors";
6
+ /**
7
+ * Resolve fallback provider config by reading `~/.roy-agent/auth.json` and
8
+ * `~/.roy-agent/config.jsonc` directly (Task #2888 follow-up).
9
+ *
10
+ * Why this exists:
11
+ * When PiAiAdapter.stream() fails (e.g. finishReason=error, MIME 400, etc.),
12
+ * LLMComponent.invoke() falls back to AI SDK invoke(). The fallback must
13
+ * NOT reuse ctx.invokeConfig blindly — for some custom providers (e.g.
14
+ * minimax) that combination produces the wrong URL and HTTP 404. Reading
15
+ * config-driven per-provider baseURL/apiKey from auth.json is the
16
+ * user-controlled source of truth.
17
+ *
18
+ * Returned shape is just enough for the fallback path:
19
+ * - baseURL: from auth.json.providers.{name}.baseURL
20
+ * - apiKey: from auth.json.providers.{name}.apiKey
21
+ * - providerType: from config.jsonc.llm.providers.{name}.provider
22
+ * (defaults to "openai-compatible" if missing)
23
+ *
24
+ * @throws Error when auth.json has no entry for `providerId`
25
+ */
26
+ export interface FallbackProviderConfig {
27
+ baseURL: string;
28
+ apiKey: string;
29
+ providerType: string;
30
+ }
31
+ export declare function resolveFallbackProviderConfig(providerId: string): Promise<FallbackProviderConfig>;
32
+ /**
33
+ * LLMComponent 配置(通过 options.config 传递)
34
+ *
35
+ * 配置加载顺序(优先级从低到高):
36
+ * 1. File - 配置文件(通过 configPath 指定)
37
+ * 2. Env - 环境变量(通过 envPrefix 配置前缀)
38
+ * 3. Object - 直接传入的 config 对象(最高优先级)
39
+ *
40
+ * 环境变量转换规则:
41
+ * - 驼峰命名会被转换为下划线分隔的大写形式
42
+ * - 例如: "llm.defaultModel" + prefix "LLM" -> "LLM_LLM_DEFAULT_MODEL"
43
+ */
44
+ export interface LLMComponentOptions {
45
+ /** ConfigComponent 实例(必填) */
46
+ configComponent: ConfigComponent;
47
+ /** 配置文件相对路径(可选,基于 XDG_DATA_HOME) */
48
+ configPath?: string;
49
+ /** 环境变量前缀(可选,默认 "LLM") */
50
+ envPrefix?: string;
51
+ /** 直接传入的配置对象(可选,优先级最高) */
52
+ config?: Partial<LLMConfig>;
53
+ }
54
+ /**
55
+ * LLMComponent
56
+ * 管理 LLM 调用,使用 AI SDK 进行实际调用
57
+ *
58
+ * 配置通过 ConfigComponent 实时获取,支持配置热更新
59
+ *
60
+ * @example
61
+ * // 通过 ConfigComponent 加载配置
62
+ * const configComponent = new ConfigComponent();
63
+ * configComponent.setXdgDataHome(__dirname);
64
+ *
65
+ * const llmComponent = new LLMComponent();
66
+ * await llmComponent.init({
67
+ * env, // Environment 实例(必填)
68
+ * options: {
69
+ * configComponent, // ConfigComponent 实例
70
+ * configPath: "config.jsonc" // 配置文件路径
71
+ * }
72
+ * });
73
+ *
74
+ * // 配置更新后,下次调用会自动获取最新配置
75
+ * configComponent.set("llm.temperature", 0.5);
76
+ */
77
+ export declare class LLMComponent extends BaseComponent {
78
+ readonly name = "llm";
79
+ readonly version = "2.0.0";
80
+ private configComponent?;
81
+ /** 配置变更 watcher 清理函数 */
82
+ private configWatcher?;
83
+ /**
84
+ * P1-3: Cached LLM adapter instance.
85
+ *
86
+ * Instead of calling createLLMAdapter() on every invoke(), we cache the
87
+ * adapter here. The adapter is created lazily on first use and rebuilt
88
+ * only when the provider environment variable changes (via
89
+ * invalidateAdapterCache()).
90
+ */
91
+ private cachedAdapter?;
92
+ /** The provider name that was used to create the cached adapter */
93
+ private cachedAdapterProvider?;
94
+ /**
95
+ * Test-only adapter override (see `__setAdapterForTest`).
96
+ *
97
+ * Kept as an instance field rather than a module mock so the override is
98
+ * scoped to a single LLMComponent instance and cannot leak into other test
99
+ * files sharing the same Bun process.
100
+ */
101
+ private adapterOverride?;
102
+ constructor();
103
+ /**
104
+ * 初始化组件
105
+ *
106
+ * 配置加载优先级(从高到低):
107
+ * 1. Object - 直接传入的 config 对象
108
+ * 2. Env - 环境变量(通过 envPrefix 配置前缀)
109
+ * 3. File - 配置文件(通过 configPath 指定)
110
+ */
111
+ init(config: ComponentConfig): Promise<void>;
112
+ /**
113
+ * 注册配置到 ConfigComponent
114
+ *
115
+ * 配置加载顺序(优先级从低到高):
116
+ * 1. FileSource - 从配置文件加载(最低)
117
+ * 2. EnvSource - 从环境变量加载(中等)
118
+ * 3. MemorySource - 直接配置对象(最高)
119
+ */
120
+ private registerConfig;
121
+ /**
122
+ * 将配置对象展平为点号路径
123
+ *
124
+ * @example
125
+ * flattenConfig({ providers: { openai: { apiKey: "xxx" } } })
126
+ * -> { "llm.providers.openai.apiKey": "xxx" }
127
+ */
128
+ private flattenConfig;
129
+ /**
130
+ * 注册配置热更新监听
131
+ */
132
+ private registerConfigWatcher;
133
+ /**
134
+ * 处理配置变更(支持热更新)
135
+ */
136
+ protected onConfigChange(event: {
137
+ key: string;
138
+ oldValue?: unknown;
139
+ newValue?: unknown;
140
+ }): void;
141
+ /**
142
+ * 启动组件
143
+ */
144
+ onStart(): Promise<void>;
145
+ /**
146
+ * 停止组件
147
+ */
148
+ onStop(): Promise<void>;
149
+ /**
150
+ * 从配置源获取配置值
151
+ * 优先从 ConfigComponent 获取(支持热更新),否则返回默认值
152
+ */
153
+ private getLLMConfig;
154
+ /**
155
+ * 解析请求,构建调用上下文(invoke 和 invokeStream 共享)
156
+ */
157
+ private resolveRequest;
158
+ /**
159
+ * 调用 LLM
160
+ *
161
+ * 路由策略(Task 6 实现):
162
+ * - 读取 ROY_LLM_PROVIDER 环境变量(默认 pi-ai)
163
+ * - 通过 createLLMAdapter().chat() 统一接入
164
+ * - 若 PiAiAdapter 失败(如 model 不支持),保留 fallback 路径
165
+ *
166
+ * 流式事件通过 env.pushEnvEvent() 发布
167
+ */
168
+ /**
169
+ * P1-3: Get or create the cached LLM adapter.
170
+ *
171
+ * The adapter is created once and cached. If the ROY_LLM_PROVIDER
172
+ * environment variable changes, call invalidateAdapterCache() to force
173
+ * a rebuild on the next invoke().
174
+ */
175
+ private getAdapter;
176
+ /**
177
+ * Test-only: inject a fake adapter for this component instance.
178
+ *
179
+ * Preferred over `mock.module("./factory")` because it does not leak across
180
+ * test files in the same Bun process. Call `__setAdapterForTest(undefined)`
181
+ * to restore normal factory behaviour.
182
+ */
183
+ __setAdapterForTest(adapter: LLMAdapter | undefined): void;
184
+ /**
185
+ * P1-3: Invalidate the cached adapter.
186
+ *
187
+ * Call this when the LLM provider environment variable changes to force
188
+ * the adapter to be recreated on the next invoke().
189
+ */
190
+ invalidateAdapterCache(): void;
191
+ invoke(request: LLMInvokeRequest): Promise<LLMInvokeResult>;
192
+ /**
193
+ * Task #2719: 消费 adapter.stream() 返回的事件流,把 pi-ai AssistantMessageEvent
194
+ * 转成 llm.text / llm.reasoning env 事件(这样 Ink interactive 可以逐字渲染),
195
+ * 然后调用 streamHandle.result() 拿到最终 ChatResponse。
196
+ *
197
+ * 处理的事件类型(pi-ai AssistantMessageEvent):
198
+ * - text_delta → llm.text (delta + 累计 content)
199
+ * - thinking_delta → llm.reasoning (delta + 累计 content)
200
+ * - 其他事件(start/text_start/text_end/thinking_start/thinking_end/toolcall_xxx/done/error)跳过
201
+ *
202
+ * AiSdkAdapter.stream() 会 yield 单个完整 output 对象(不包含 type 字段),
203
+ * 不属于以上任意类型,所以不会被错误识别为流式事件。
204
+ */
205
+ private consumeStreamAndGetResult;
206
+ /**
207
+ * 公共收尾逻辑:threshold check + return LLMInvokeResult
208
+ */
209
+ private finalizeOutput;
210
+ /**
211
+ * Task #4396: publish the `llm.completed` env event.
212
+ *
213
+ * Payload shape must match what `StreamOutputService.handleCompleted()`
214
+ * reads (`payload.metadata.usage` + `payload.metadata.model`), otherwise the
215
+ * TUI footer silently degrades to nothing.
216
+ */
217
+ private emitCompletedEvent;
218
+ /**
219
+ * 获取 Provider API Key
220
+ */
221
+ private getApiKey;
222
+ /**
223
+ * 获取 Provider
224
+ */
225
+ getProvider(id: string): import("./types").ProviderConfig;
226
+ /**
227
+ * 列出所有 Provider
228
+ */
229
+ listProviders(): string[];
230
+ /**
231
+ * 获取模型的限制配置
232
+ *
233
+ * @param providerId - Provider ID
234
+ * @param modelId - 模型 ID(可选,默认使用 provider 的 defaultModel)
235
+ * @returns 模型限制配置,如果没有配置则返回 undefined
236
+ */
237
+ getModelLimits(providerId: string, modelId?: string): ModelLimits | undefined;
238
+ /**
239
+ * 获取上下文窗口阈值配置
240
+ *
241
+ * @param providerId - Provider ID
242
+ * @param modelId - 模型 ID
243
+ * @returns 包含 contextWindow 和 thresholdRatio 的对象
244
+ */
245
+ getContextThresholdConfig(providerId: string, modelId?: string): {
246
+ contextWindow: number;
247
+ thresholdRatio: number;
248
+ };
249
+ /**
250
+ * 检测上下文阈值是否超过
251
+ *
252
+ * @param usage - LLM 使用量信息
253
+ * @param providerId - Provider ID
254
+ * @param modelId - 模型 ID
255
+ * @param sessionId - Session ID(用于错误信息)
256
+ * @returns 如果超过阈值,返回 ContextError;否则返回 undefined
257
+ */
258
+ checkContextThreshold(usage: {
259
+ totalTokens: number;
260
+ promptTokens?: number;
261
+ completionTokens?: number;
262
+ } | undefined, providerId: string, modelId: string | undefined, sessionId?: string): ContextError | undefined;
263
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @fileoverview OpenCode Go provider helpers.
3
+ *
4
+ * The OpenCode Go inference endpoint (`https://opencode.ai/inference/go/v1`)
5
+ * requires a stable `x-opencode-session` header per conversation; without it the
6
+ * server responds `400 MissingSessionID` and the request cannot be routed:
7
+ * https://opencode.ai/docs/go/#how-it-works
8
+ *
9
+ * This module is the single source of truth for:
10
+ * 1. detecting the OpenCode Go provider id, and
11
+ * 2. generating / memoizing a stable session id per conversation.
12
+ *
13
+ * Why it lives here instead of inside `invoke.ts`:
14
+ * roy-agent has TWO LLM transports that both hit the same endpoint —
15
+ * - `PiAiAdapter` (default path, `ROY_LLM_PROVIDER=pi-ai`)
16
+ * - `invoke()` in `invoke.ts` (AI SDK fallback, `ROY_LLM_PROVIDER=ai-sdk`)
17
+ * The header injection must be shared so neither path silently regresses.
18
+ * Historically only the AI SDK path injected it, so the default pi-ai path
19
+ * always failed with `MissingSessionID` and relied on the fallback.
20
+ *
21
+ * Provider id normalization:
22
+ * Users have registered the provider under several spellings across time
23
+ * (`opencode`, `opencode-go`, `opencodego`; see Task #4168 / #4170 / #4173).
24
+ * We normalize case and strip `-`/`_` so all of them match. The Feishu
25
+ * channel's chat-keyed session ids (`oc_...`) are irrelevant here: the header
26
+ * value is always a freshly generated `ses_...` id, so any conversation id
27
+ * (including `oc_...`) works as the cache key.
28
+ */
29
+ /**
30
+ * Generate an OpenCode-compatible `x-opencode-session` id.
31
+ *
32
+ * Official client format (sst/opencode source analysis, Task #4165):
33
+ * `ses_<12 hex timestamp><14 base62 random>` = 30 chars
34
+ *
35
+ * We do not enforce the exact 30-char length (the server only validates the
36
+ * `ses_` prefix and a minimum length), but we keep the same shape so the output
37
+ * is easy to recognize alongside the official client.
38
+ *
39
+ * @param nowMs - injectable clock (for tests)
40
+ */
41
+ export declare function generateOpencodeSessionId(nowMs?: number): string;
42
+ /**
43
+ * True when `providerId` refers to the OpenCode Go provider.
44
+ *
45
+ * Recognizes `opencode`, `opencode-go`, `opencode_go` and `opencodego`
46
+ * (case-insensitive). Unrelated providers (e.g. `deepseek`, `openai`) return
47
+ * false so we never send the header to endpoints that don't understand it.
48
+ */
49
+ export declare function isOpencodeProvider(providerId: string | undefined | null): boolean;
50
+ /**
51
+ * True when `baseURL` points at the OpenCode Go inference endpoint.
52
+ *
53
+ * Id-based detection misses the case where a user points some other provider
54
+ * name at the OpenCode endpoint; endpoint detection closes that gap. Only the
55
+ * official host is matched so unrelated gateways are unaffected.
56
+ */
57
+ export declare function isOpencodeEndpoint(baseURL: string | undefined | null): boolean;
58
+ /**
59
+ * Get (or create) the stable OpenCode session id for a conversation.
60
+ *
61
+ * `x-opencode-session` must be STABLE for the lifetime of a conversation
62
+ * (the server uses it for routing/caching, see #4168). The header is injected
63
+ * once per LLM turn, so we memoize the generated id per conversation key.
64
+ *
65
+ * - `conversationId` undefined → return an ephemeral id (no stable key to
66
+ * cache under, better than poisoning a shared entry).
67
+ * - The cache is a bounded FIFO so long-lived processes cannot grow it forever.
68
+ */
69
+ export declare function getOrCreateOpencodeSessionId(conversationId: string | undefined, nowMs?: number): string;
70
+ /**
71
+ * Build the request headers for a provider.
72
+ *
73
+ * Returns `{ "x-opencode-session": "ses_..." }` for OpenCode Go providers and
74
+ * an empty object for everyone else. Match is by provider id OR endpoint, so it
75
+ * keeps working if the provider is registered under a different name.
76
+ */
77
+ export declare function buildOpencodeHeaders(providerId: string | undefined | null, conversationId?: string, baseURL?: string): Record<string, string>;
78
+ /** Test-only: reset the conversation → session id cache between cases. */
79
+ export declare function __clearOpencodeSessionIdCache(): void;