veryfront 0.1.324 → 0.1.327

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 (277) hide show
  1. package/esm/cli/commands/extension/init-command.js +2 -2
  2. package/esm/cli/commands/extension/validate-command.js +1 -1
  3. package/esm/deno.d.ts +7 -0
  4. package/esm/deno.js +8 -1
  5. package/esm/deps/esm.sh/react-dom@19.2.4/client.d.ts +2 -0
  6. package/esm/deps/esm.sh/react-dom@19.2.4/client.d.ts.map +1 -0
  7. package/esm/deps/esm.sh/react-dom@19.2.4/client.js +5 -0
  8. package/esm/deps/esm.sh/scheduler@^0.27.0.d.ts +2 -0
  9. package/esm/deps/esm.sh/scheduler@^0.27.0.d.ts.map +1 -0
  10. package/esm/deps/esm.sh/scheduler@^0.27.0.js +3 -0
  11. package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.d.ts +30 -0
  12. package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.d.ts.map +1 -0
  13. package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.js +47 -0
  14. package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.d.ts +29 -0
  15. package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.d.ts.map +1 -0
  16. package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.js +65 -0
  17. package/esm/deps/jsr.io/@std/assert/1.0.19/assert.d.ts +17 -0
  18. package/esm/deps/jsr.io/@std/assert/1.0.19/assert.d.ts.map +1 -0
  19. package/esm/deps/jsr.io/@std/assert/1.0.19/assert.js +23 -0
  20. package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.d.ts +26 -0
  21. package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.d.ts.map +1 -0
  22. package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.js +30 -0
  23. package/esm/deps/jsr.io/@std/assert/1.0.19/equal.d.ts +25 -0
  24. package/esm/deps/jsr.io/@std/assert/1.0.19/equal.d.ts.map +1 -0
  25. package/esm/deps/jsr.io/@std/assert/1.0.19/equal.js +194 -0
  26. package/esm/deps/jsr.io/@std/assert/1.0.19/equals.d.ts +37 -0
  27. package/esm/deps/jsr.io/@std/assert/1.0.19/equals.d.ts.map +1 -0
  28. package/esm/deps/jsr.io/@std/assert/1.0.19/equals.js +61 -0
  29. package/esm/deps/jsr.io/@std/assert/1.0.19/exists.d.ts +18 -0
  30. package/esm/deps/jsr.io/@std/assert/1.0.19/exists.d.ts.map +1 -0
  31. package/esm/deps/jsr.io/@std/assert/1.0.19/exists.js +27 -0
  32. package/esm/deps/jsr.io/@std/assert/1.0.19/fail.d.ts +15 -0
  33. package/esm/deps/jsr.io/@std/assert/1.0.19/fail.d.ts.map +1 -0
  34. package/esm/deps/jsr.io/@std/assert/1.0.19/fail.js +20 -0
  35. package/esm/deps/jsr.io/@std/assert/1.0.19/false.d.ts +19 -0
  36. package/esm/deps/jsr.io/@std/assert/1.0.19/false.d.ts.map +1 -0
  37. package/esm/deps/jsr.io/@std/assert/1.0.19/false.js +23 -0
  38. package/esm/deps/jsr.io/@std/assert/1.0.19/greater.d.ts +20 -0
  39. package/esm/deps/jsr.io/@std/assert/1.0.19/greater.d.ts.map +1 -0
  40. package/esm/deps/jsr.io/@std/assert/1.0.19/greater.js +29 -0
  41. package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.d.ts +20 -0
  42. package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.d.ts.map +1 -0
  43. package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.js +29 -0
  44. package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.d.ts +23 -0
  45. package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.d.ts.map +1 -0
  46. package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.js +52 -0
  47. package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.d.ts +25 -0
  48. package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.d.ts.map +1 -0
  49. package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.js +53 -0
  50. package/esm/deps/jsr.io/@std/assert/1.0.19/less.d.ts +19 -0
  51. package/esm/deps/jsr.io/@std/assert/1.0.19/less.d.ts.map +1 -0
  52. package/esm/deps/jsr.io/@std/assert/1.0.19/less.js +28 -0
  53. package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.d.ts +20 -0
  54. package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.d.ts.map +1 -0
  55. package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.js +29 -0
  56. package/esm/deps/jsr.io/@std/assert/1.0.19/match.d.ts +18 -0
  57. package/esm/deps/jsr.io/@std/assert/1.0.19/match.d.ts.map +1 -0
  58. package/esm/deps/jsr.io/@std/assert/1.0.19/match.js +26 -0
  59. package/esm/deps/jsr.io/@std/assert/1.0.19/mod.d.ts +44 -0
  60. package/esm/deps/jsr.io/@std/assert/1.0.19/mod.d.ts.map +1 -0
  61. package/esm/deps/jsr.io/@std/assert/1.0.19/mod.js +45 -0
  62. package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.d.ts +27 -0
  63. package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.d.ts.map +1 -0
  64. package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.js +39 -0
  65. package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.d.ts +20 -0
  66. package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.d.ts.map +1 -0
  67. package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.js +29 -0
  68. package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.d.ts +18 -0
  69. package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.d.ts.map +1 -0
  70. package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.js +26 -0
  71. package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.d.ts +23 -0
  72. package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.d.ts.map +1 -0
  73. package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.js +32 -0
  74. package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.d.ts +29 -0
  75. package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.d.ts.map +1 -0
  76. package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.js +177 -0
  77. package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.d.ts +42 -0
  78. package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.d.ts.map +1 -0
  79. package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.js +53 -0
  80. package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.d.ts +24 -0
  81. package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.d.ts.map +1 -0
  82. package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.js +58 -0
  83. package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.d.ts +18 -0
  84. package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.d.ts.map +1 -0
  85. package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.js +26 -0
  86. package/esm/deps/jsr.io/@std/assert/1.0.19/throws.d.ts +45 -0
  87. package/esm/deps/jsr.io/@std/assert/1.0.19/throws.d.ts.map +1 -0
  88. package/esm/deps/jsr.io/@std/assert/1.0.19/throws.js +44 -0
  89. package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.d.ts +15 -0
  90. package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.d.ts.map +1 -0
  91. package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.js +20 -0
  92. package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.d.ts +15 -0
  93. package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.d.ts.map +1 -0
  94. package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.js +20 -0
  95. package/esm/deps/jsr.io/@std/internal/1.0.13/assertion_state.d.ts +150 -0
  96. package/esm/deps/jsr.io/@std/internal/1.0.13/assertion_state.d.ts.map +1 -0
  97. package/esm/deps/jsr.io/@std/internal/1.0.13/assertion_state.js +224 -0
  98. package/esm/deps/jsr.io/@std/internal/1.0.13/build_message.d.ts +80 -0
  99. package/esm/deps/jsr.io/@std/internal/1.0.13/build_message.d.ts.map +1 -0
  100. package/esm/deps/jsr.io/@std/internal/1.0.13/build_message.js +116 -0
  101. package/esm/deps/jsr.io/@std/internal/1.0.13/diff.d.ts +140 -0
  102. package/esm/deps/jsr.io/@std/internal/1.0.13/diff.d.ts.map +1 -0
  103. package/esm/deps/jsr.io/@std/internal/1.0.13/diff.js +276 -0
  104. package/esm/deps/jsr.io/@std/internal/1.0.13/diff_str.d.ts +99 -0
  105. package/esm/deps/jsr.io/@std/internal/1.0.13/diff_str.d.ts.map +1 -0
  106. package/esm/deps/jsr.io/@std/internal/1.0.13/diff_str.js +182 -0
  107. package/esm/deps/jsr.io/@std/internal/1.0.13/format.d.ts +29 -0
  108. package/esm/deps/jsr.io/@std/internal/1.0.13/format.d.ts.map +1 -0
  109. package/esm/deps/jsr.io/@std/internal/1.0.13/format.js +70 -0
  110. package/esm/deps/jsr.io/@std/internal/1.0.13/styles.d.ts +159 -0
  111. package/esm/deps/jsr.io/@std/internal/1.0.13/styles.d.ts.map +1 -0
  112. package/esm/deps/jsr.io/@std/internal/1.0.13/styles.js +207 -0
  113. package/esm/deps/jsr.io/@std/internal/1.0.13/types.d.ts +25 -0
  114. package/esm/deps/jsr.io/@std/internal/1.0.13/types.d.ts.map +1 -0
  115. package/esm/deps/jsr.io/@std/internal/1.0.13/types.js +3 -0
  116. package/esm/deps/jsr.io/@std/testing/1.0.18/_test_suite.d.ts +80 -0
  117. package/esm/deps/jsr.io/@std/testing/1.0.18/_test_suite.d.ts.map +1 -0
  118. package/esm/deps/jsr.io/@std/testing/1.0.18/_test_suite.js +348 -0
  119. package/esm/deps/jsr.io/@std/testing/1.0.18/bdd.d.ts +738 -0
  120. package/esm/deps/jsr.io/@std/testing/1.0.18/bdd.d.ts.map +1 -0
  121. package/esm/deps/jsr.io/@std/testing/1.0.18/bdd.js +656 -0
  122. package/esm/src/agent/fork-runtime-stream.d.ts +143 -0
  123. package/esm/src/agent/fork-runtime-stream.d.ts.map +1 -0
  124. package/esm/src/agent/fork-runtime-stream.js +505 -0
  125. package/esm/src/agent/hosted-child-fork-stream-execution.d.ts +130 -0
  126. package/esm/src/agent/hosted-child-fork-stream-execution.d.ts.map +1 -0
  127. package/esm/src/agent/hosted-child-fork-stream-execution.js +391 -0
  128. package/esm/src/agent/index.d.ts +2 -0
  129. package/esm/src/agent/index.d.ts.map +1 -1
  130. package/esm/src/agent/index.js +2 -0
  131. package/esm/src/chat/conversation.d.ts +5 -5
  132. package/esm/src/chat/final-step-fallback.js +2 -2
  133. package/esm/src/modules/index.d.ts +12 -0
  134. package/esm/src/modules/index.d.ts.map +1 -0
  135. package/esm/src/modules/index.js +10 -0
  136. package/esm/src/modules/module-resolver.d.ts +28 -0
  137. package/esm/src/modules/module-resolver.d.ts.map +1 -0
  138. package/esm/src/modules/module-resolver.js +106 -0
  139. package/esm/src/rendering/cleanup.d.ts +7 -0
  140. package/esm/src/rendering/cleanup.d.ts.map +1 -0
  141. package/esm/src/rendering/cleanup.js +22 -0
  142. package/esm/src/rendering/ssr/index.d.ts +10 -0
  143. package/esm/src/rendering/ssr/index.d.ts.map +1 -0
  144. package/esm/src/rendering/ssr/index.js +8 -0
  145. package/esm/src/rendering/ssr/mdx-module-loader.d.ts +5 -0
  146. package/esm/src/rendering/ssr/mdx-module-loader.d.ts.map +1 -0
  147. package/esm/src/rendering/ssr/mdx-module-loader.js +150 -0
  148. package/esm/src/rendering/ssr/mdx-renderer.d.ts +4 -0
  149. package/esm/src/rendering/ssr/mdx-renderer.d.ts.map +1 -0
  150. package/esm/src/rendering/ssr/mdx-renderer.js +44 -0
  151. package/esm/src/rendering/ssr/types.d.ts +13 -0
  152. package/esm/src/rendering/ssr/types.d.ts.map +1 -0
  153. package/esm/src/rendering/ssr/types.js +1 -0
  154. package/esm/src/sandbox/index.d.ts +1 -0
  155. package/esm/src/sandbox/index.d.ts.map +1 -1
  156. package/esm/src/sandbox/index.js +1 -0
  157. package/esm/src/sandbox/shell-tools.d.ts +39 -0
  158. package/esm/src/sandbox/shell-tools.d.ts.map +1 -0
  159. package/esm/src/sandbox/shell-tools.js +177 -0
  160. package/esm/src/server/shared/index.d.ts +7 -0
  161. package/esm/src/server/shared/index.d.ts.map +1 -0
  162. package/esm/src/server/shared/index.js +6 -0
  163. package/esm/src/testing/assert.d.ts +22 -0
  164. package/esm/src/testing/assert.d.ts.map +1 -0
  165. package/esm/src/testing/assert.js +217 -0
  166. package/esm/src/testing/bdd.d.ts +67 -0
  167. package/esm/src/testing/bdd.d.ts.map +1 -0
  168. package/esm/src/testing/bdd.js +401 -0
  169. package/esm/src/testing/deno-compat.d.ts +26 -0
  170. package/esm/src/testing/deno-compat.d.ts.map +1 -0
  171. package/esm/src/testing/deno-compat.js +146 -0
  172. package/esm/src/testing/index.d.ts +28 -0
  173. package/esm/src/testing/index.d.ts.map +1 -0
  174. package/esm/src/testing/index.js +27 -0
  175. package/esm/src/testing/init.d.ts +2 -0
  176. package/esm/src/testing/init.d.ts.map +1 -0
  177. package/esm/src/testing/init.js +18 -0
  178. package/esm/src/testing/isolation.d.ts +30 -0
  179. package/esm/src/testing/isolation.d.ts.map +1 -0
  180. package/esm/src/testing/isolation.js +151 -0
  181. package/esm/src/testing/timing.d.ts +4 -0
  182. package/esm/src/testing/timing.d.ts.map +1 -0
  183. package/esm/src/testing/timing.js +22 -0
  184. package/esm/src/testing/utils.d.ts +6 -0
  185. package/esm/src/testing/utils.d.ts.map +1 -0
  186. package/esm/src/testing/utils.js +49 -0
  187. package/esm/src/types/global-guards.d.ts +11 -0
  188. package/esm/src/types/global-guards.d.ts.map +1 -0
  189. package/esm/src/types/global-guards.js +12 -0
  190. package/esm/src/utils/cache/keys/namespace.d.ts +3 -0
  191. package/esm/src/utils/cache/keys/namespace.d.ts.map +1 -0
  192. package/esm/src/utils/cache/keys/namespace.js +19 -0
  193. package/esm/src/utils/clsx.d.ts +3 -3
  194. package/esm/src/utils/clsx.d.ts.map +1 -1
  195. package/esm/src/utils/clsx.js +2 -3
  196. package/esm/src/utils/mime-types.d.ts +0 -6
  197. package/esm/src/utils/mime-types.d.ts.map +1 -1
  198. package/esm/src/utils/mime-types.js +0 -1
  199. package/esm/src/utils/version-constant.d.ts +1 -1
  200. package/esm/src/utils/version-constant.js +1 -1
  201. package/package.json +14 -1
  202. package/src/cli/commands/extension/init-command.ts +2 -2
  203. package/src/cli/commands/extension/validate-command.ts +1 -1
  204. package/src/deno.js +8 -1
  205. package/src/deps/esm.sh/@types/react-dom@19.2.3/client.d.ts +105 -0
  206. package/src/deps/esm.sh/@types/react@19.2.14/global.d.ts +166 -0
  207. package/src/deps/esm.sh/@types/react@19.2.14/index.d.ts +4370 -0
  208. package/src/deps/esm.sh/@types/scheduler@0.26.0/index.d.ts +30 -0
  209. package/src/deps/esm.sh/csstype@3.2.3/index.d.ts +22569 -0
  210. package/src/deps/esm.sh/react-dom@19.2.4/client.d.ts +105 -0
  211. package/src/deps/esm.sh/react-dom@19.2.4/client.js +5 -0
  212. package/src/deps/esm.sh/scheduler@^0.27.0.d.ts +30 -0
  213. package/src/deps/esm.sh/scheduler@^0.27.0.js +3 -0
  214. package/src/deps/jsr.io/@std/assert/1.0.19/almost_equals.ts +56 -0
  215. package/src/deps/jsr.io/@std/assert/1.0.19/array_includes.ts +76 -0
  216. package/src/deps/jsr.io/@std/assert/1.0.19/assert.ts +24 -0
  217. package/src/deps/jsr.io/@std/assert/1.0.19/assertion_error.ts +31 -0
  218. package/src/deps/jsr.io/@std/assert/1.0.19/equal.ts +226 -0
  219. package/src/deps/jsr.io/@std/assert/1.0.19/equals.ts +68 -0
  220. package/src/deps/jsr.io/@std/assert/1.0.19/exists.ts +31 -0
  221. package/src/deps/jsr.io/@std/assert/1.0.19/fail.ts +21 -0
  222. package/src/deps/jsr.io/@std/assert/1.0.19/false.ts +27 -0
  223. package/src/deps/jsr.io/@std/assert/1.0.19/greater.ts +30 -0
  224. package/src/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.ts +36 -0
  225. package/src/deps/jsr.io/@std/assert/1.0.19/instance_of.ts +64 -0
  226. package/src/deps/jsr.io/@std/assert/1.0.19/is_error.ts +65 -0
  227. package/src/deps/jsr.io/@std/assert/1.0.19/less.ts +29 -0
  228. package/src/deps/jsr.io/@std/assert/1.0.19/less_or_equal.ts +36 -0
  229. package/src/deps/jsr.io/@std/assert/1.0.19/match.ts +30 -0
  230. package/src/deps/jsr.io/@std/assert/1.0.19/mod.ts +47 -0
  231. package/src/deps/jsr.io/@std/assert/1.0.19/not_equals.ts +43 -0
  232. package/src/deps/jsr.io/@std/assert/1.0.19/not_instance_of.ts +33 -0
  233. package/src/deps/jsr.io/@std/assert/1.0.19/not_match.ts +30 -0
  234. package/src/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.ts +42 -0
  235. package/src/deps/jsr.io/@std/assert/1.0.19/object_match.ts +224 -0
  236. package/src/deps/jsr.io/@std/assert/1.0.19/rejects.ts +123 -0
  237. package/src/deps/jsr.io/@std/assert/1.0.19/strict_equals.ts +68 -0
  238. package/src/deps/jsr.io/@std/assert/1.0.19/string_includes.ts +30 -0
  239. package/src/deps/jsr.io/@std/assert/1.0.19/throws.ts +111 -0
  240. package/src/deps/jsr.io/@std/assert/1.0.19/unimplemented.ts +21 -0
  241. package/src/deps/jsr.io/@std/assert/1.0.19/unreachable.ts +21 -0
  242. package/src/deps/jsr.io/@std/internal/1.0.13/assertion_state.ts +248 -0
  243. package/src/deps/jsr.io/@std/internal/1.0.13/build_message.ts +147 -0
  244. package/src/deps/jsr.io/@std/internal/1.0.13/diff.ts +317 -0
  245. package/src/deps/jsr.io/@std/internal/1.0.13/diff_str.ts +208 -0
  246. package/src/deps/jsr.io/@std/internal/1.0.13/format.ts +89 -0
  247. package/src/deps/jsr.io/@std/internal/1.0.13/styles.ts +233 -0
  248. package/src/deps/jsr.io/@std/internal/1.0.13/types.ts +30 -0
  249. package/src/deps/jsr.io/@std/testing/1.0.18/_test_suite.ts +461 -0
  250. package/src/deps/jsr.io/@std/testing/1.0.18/bdd.ts +1294 -0
  251. package/src/src/agent/fork-runtime-stream.ts +780 -0
  252. package/src/src/agent/hosted-child-fork-stream-execution.ts +579 -0
  253. package/src/src/agent/index.ts +26 -0
  254. package/src/src/chat/final-step-fallback.ts +2 -2
  255. package/src/src/modules/index.ts +43 -0
  256. package/src/src/modules/module-resolver.ts +145 -0
  257. package/src/src/rendering/cleanup.ts +27 -0
  258. package/src/src/rendering/ssr/index.ts +10 -0
  259. package/src/src/rendering/ssr/mdx-module-loader.ts +185 -0
  260. package/src/src/rendering/ssr/mdx-renderer.ts +66 -0
  261. package/src/src/rendering/ssr/types.ts +14 -0
  262. package/src/src/sandbox/index.ts +9 -0
  263. package/src/src/sandbox/shell-tools.ts +242 -0
  264. package/src/src/server/shared/index.ts +12 -0
  265. package/src/src/testing/assert.ts +352 -0
  266. package/src/src/testing/bdd.ts +618 -0
  267. package/src/src/testing/deno-compat.ts +206 -0
  268. package/src/src/testing/index.ts +92 -0
  269. package/src/src/testing/init.ts +21 -0
  270. package/src/src/testing/isolation.ts +177 -0
  271. package/src/src/testing/timing.ts +27 -0
  272. package/src/src/testing/utils.ts +44 -0
  273. package/src/src/types/global-guards.ts +21 -0
  274. package/src/src/utils/cache/keys/namespace.ts +25 -0
  275. package/src/src/utils/clsx.ts +2 -4
  276. package/src/src/utils/mime-types.ts +0 -2
  277. package/src/src/utils/version-constant.ts +1 -1
@@ -0,0 +1,143 @@
1
+ import type { Tool } from "../tool/index.js";
2
+ import type { AgUiRuntimeStreamEvent } from "./ag-ui-browser-encoder.js";
3
+ import type { AgentResponse, Message as AgentMessage } from "./schemas/index.js";
4
+ interface ForkStreamPart {
5
+ type: "reasoning-delta" | "text-delta";
6
+ text: string;
7
+ }
8
+ interface ForkToolInputStartPart {
9
+ type: "tool-input-start";
10
+ toolCallId: string;
11
+ toolName: string;
12
+ }
13
+ interface ForkToolInputDeltaPart {
14
+ type: "tool-input-delta";
15
+ toolCallId: string;
16
+ delta: string;
17
+ }
18
+ interface ForkToolCallPart {
19
+ type: "tool-call";
20
+ toolName: string;
21
+ toolCallId: string;
22
+ input: unknown;
23
+ }
24
+ interface ForkToolResultPart {
25
+ type: "tool-result";
26
+ toolName: string;
27
+ toolCallId: string;
28
+ input: unknown;
29
+ output: unknown;
30
+ }
31
+ interface ForkToolErrorPart {
32
+ type: "tool-error";
33
+ toolName: string;
34
+ toolCallId: string;
35
+ input: unknown;
36
+ error: Error;
37
+ }
38
+ interface ForkErrorPart {
39
+ type: "error";
40
+ error: Error;
41
+ }
42
+ export interface ForkRuntimeStep {
43
+ text: string;
44
+ messages: unknown[];
45
+ toolCalls: Array<{
46
+ toolCallId: string;
47
+ toolName: string;
48
+ input: unknown;
49
+ }>;
50
+ toolResults: Array<{
51
+ toolCallId: string;
52
+ toolName: string;
53
+ input: unknown;
54
+ output: unknown;
55
+ }>;
56
+ finishReason: string | null;
57
+ }
58
+ interface RecoveredToolObservation {
59
+ sawInputStart: boolean;
60
+ sawInputDelta: boolean;
61
+ sawInputAvailable: boolean;
62
+ sawOutputAvailable: boolean;
63
+ sawOutputError: boolean;
64
+ }
65
+ export interface ForkRecoveredPartsState {
66
+ toolCalls: Map<string, RecoveredToolObservation>;
67
+ emittedToolCallIds: Set<string>;
68
+ emittedToolResultIds: Set<string>;
69
+ logger?: ForkRuntimeStreamLogger;
70
+ }
71
+ type FrameworkToolCallState = RecoveredToolObservation & {
72
+ toolName: string;
73
+ inputText: string;
74
+ input: Record<string, unknown>;
75
+ };
76
+ type StreamedToolCallState = {
77
+ toolCallId: string;
78
+ toolName: string;
79
+ inputText: string;
80
+ input: unknown;
81
+ status: "pending" | "completed" | "error";
82
+ output?: unknown;
83
+ errorText?: string;
84
+ };
85
+ type StreamedMessage = {
86
+ role: "assistant" | "tool";
87
+ parts: AgentMessage["parts"];
88
+ };
89
+ type StreamedStepState = {
90
+ text: string;
91
+ toolCalls: Map<string, StreamedToolCallState>;
92
+ messages: StreamedMessage[];
93
+ };
94
+ export type FrameworkStreamState = {
95
+ toolCalls: Map<string, FrameworkToolCallState>;
96
+ emittedToolCallIds: Set<string>;
97
+ emittedToolResultIds: Set<string>;
98
+ logger?: ForkRuntimeStreamLogger;
99
+ };
100
+ export type ForkPart = ForkStreamPart | ForkToolInputStartPart | ForkToolInputDeltaPart | ForkToolCallPart | ForkToolResultPart | ForkToolErrorPart | ForkErrorPart;
101
+ export type ForkRuntimeStreamLogger = {
102
+ warn: (message: string, metadata?: Record<string, unknown>) => void;
103
+ };
104
+ export interface ForkRuntimeStreamResult {
105
+ fullStream: AsyncIterable<ForkPart>;
106
+ steps: PromiseLike<readonly ForkRuntimeStep[]>;
107
+ totalUsage: PromiseLike<{
108
+ inputTokens?: number;
109
+ outputTokens?: number;
110
+ } | undefined>;
111
+ }
112
+ export declare const DEFAULT_FORK_RESPONSE_PROMISE_TIMEOUT_MS = 1000;
113
+ export declare function runFrameworkForkStep(input: {
114
+ apiUrl: string;
115
+ authToken: string;
116
+ projectId: string | null;
117
+ model: string;
118
+ messages: AgentMessage[];
119
+ system: string;
120
+ abortSignal?: AbortSignal;
121
+ forkToolNames: string[];
122
+ frameworkTools: Record<string, Tool | boolean>;
123
+ providerOptions?: Record<string, unknown>;
124
+ }): Promise<{
125
+ stream: ReadableStream<Uint8Array>;
126
+ responsePromise: Promise<AgentResponse>;
127
+ }>;
128
+ export declare function createStreamedStepState(): StreamedStepState;
129
+ export declare function applyPartToStreamedStepState(state: StreamedStepState, part: ForkPart): void;
130
+ export declare function resolveForkStepResponse(input: {
131
+ responsePromise: Promise<AgentResponse>;
132
+ responseTimeoutMs: number;
133
+ abortSignal?: AbortSignal;
134
+ currentMessages: readonly AgentMessage[];
135
+ streamedStepState: StreamedStepState;
136
+ }): Promise<AgentResponse>;
137
+ export declare function buildRecoveredStepParts(step: ForkRuntimeStep, state: ForkRecoveredPartsState): Array<ForkToolCallPart | ForkToolResultPart>;
138
+ export declare function createFrameworkStreamState(input?: {
139
+ logger?: ForkRuntimeStreamLogger;
140
+ }): FrameworkStreamState;
141
+ export declare function mapFrameworkEventToForkParts(event: AgUiRuntimeStreamEvent, state: FrameworkStreamState): ForkPart[];
142
+ export {};
143
+ //# sourceMappingURL=fork-runtime-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fork-runtime-stream.d.ts","sourceRoot":"","sources":["../../../src/src/agent/fork-runtime-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAI7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAWzE,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEjF,UAAU,cAAc;IACtB,IAAI,EAAE,iBAAiB,GAAG,YAAY,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,sBAAsB;IAC9B,IAAI,EAAE,kBAAkB,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,sBAAsB;IAC9B,IAAI,EAAE,kBAAkB,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,UAAU,kBAAkB;IAC1B,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EA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;IACzC,iBAAiB,EAAE,iBAAiB,CAAC;CACtC,GAAG,OAAO,CAAC,aAAa,CAAC,CA0BzB;AAUD,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,uBAAuB,GAC7B,KAAK,CAAC,gBAAgB,GAAG,kBAAkB,CAAC,CAyD9C;AA2CD,wBAAgB,0BAA0B,CACxC,KAAK,GAAE;IAAE,MAAM,CAAC,EAAE,uBAAuB,CAAA;CAAO,GAC/C,oBAAoB,CAOtB;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,sBAAsB,EAC7B,KAAK,EAAE,oBAAoB,GAC1B,QAAQ,EAAE,CAqJZ"}
@@ -0,0 +1,505 @@
1
+ import * as dntShim from "../../_dnt.shims.js";
2
+ import { isRecord } from "../chat/conversation.js";
3
+ import { safeJsonParse } from "../chat/provider-errors.js";
4
+ import { runWithVeryfrontCloudContextAsync } from "../provider/veryfront-cloud/context.js";
5
+ import { mergeToolInputDelta, parseToolInputObject, stripLeadingEmptyObjectPlaceholder, } from "./data-stream.js";
6
+ import { HOSTED_CHILD_STREAM_TIMEOUT_TOKEN, resolveHostedChildPromiseWithTimeout, } from "./hosted-child-stream-watchdog.js";
7
+ import { AgentRuntime } from "./runtime/index.js";
8
+ export const DEFAULT_FORK_RESPONSE_PROMISE_TIMEOUT_MS = 1_000;
9
+ function createFrameworkForkAbortError(abortSignal) {
10
+ if (abortSignal?.reason instanceof Error) {
11
+ return abortSignal.reason;
12
+ }
13
+ return new DOMException("Framework fork aborted before completion.", "AbortError");
14
+ }
15
+ export async function runFrameworkForkStep(input) {
16
+ let resolveResponsePromise;
17
+ let rejectResponsePromise;
18
+ const responsePromise = new Promise((resolve, reject) => {
19
+ resolveResponsePromise = resolve;
20
+ rejectResponsePromise = reject;
21
+ });
22
+ const abortHandler = () => {
23
+ rejectResponsePromise(createFrameworkForkAbortError(input.abortSignal));
24
+ };
25
+ if (input.abortSignal) {
26
+ if (input.abortSignal.aborted) {
27
+ abortHandler();
28
+ }
29
+ else {
30
+ input.abortSignal.addEventListener("abort", abortHandler, { once: true });
31
+ }
32
+ }
33
+ const runtimeConfig = {
34
+ model: input.model,
35
+ system: input.system,
36
+ tools: input.frameworkTools,
37
+ maxSteps: 1,
38
+ ...(input.providerOptions
39
+ ? { resolveModelTransport: () => ({ providerOptions: input.providerOptions }) }
40
+ : {}),
41
+ __vfAllowedRemoteTools: input.forkToolNames,
42
+ };
43
+ const runtime = new AgentRuntime("invoke-agent-child-framework", runtimeConfig);
44
+ const stream = await runWithVeryfrontCloudContextAsync({
45
+ apiBaseUrl: input.apiUrl,
46
+ apiToken: input.authToken,
47
+ serviceLayer: "cloud",
48
+ }, () => runtime.stream(input.messages, input.projectId ? { projectId: input.projectId } : undefined, {
49
+ onFinish: (response) => {
50
+ input.abortSignal?.removeEventListener("abort", abortHandler);
51
+ resolveResponsePromise(response);
52
+ },
53
+ }, input.model, undefined, input.abortSignal));
54
+ return {
55
+ stream,
56
+ responsePromise,
57
+ };
58
+ }
59
+ export function createStreamedStepState() {
60
+ return {
61
+ text: "",
62
+ toolCalls: new Map(),
63
+ messages: [],
64
+ };
65
+ }
66
+ function appendStreamedMessagePart(state, role, part) {
67
+ const lastMessage = state.messages.at(-1);
68
+ if (lastMessage?.role === role) {
69
+ lastMessage.parts.push(part);
70
+ return;
71
+ }
72
+ state.messages.push({
73
+ role,
74
+ parts: [part],
75
+ });
76
+ }
77
+ function isFrameworkTextPart(part) {
78
+ return part.type === "text";
79
+ }
80
+ export function applyPartToStreamedStepState(state, part) {
81
+ switch (part.type) {
82
+ case "tool-input-start": {
83
+ const existing = state.toolCalls.get(part.toolCallId);
84
+ state.toolCalls.set(part.toolCallId, {
85
+ toolCallId: part.toolCallId,
86
+ toolName: part.toolName,
87
+ inputText: existing?.inputText ?? "",
88
+ input: existing?.input ?? {},
89
+ status: existing?.status ?? "pending",
90
+ ...(existing?.output !== undefined ? { output: existing.output } : {}),
91
+ ...(existing?.errorText ? { errorText: existing.errorText } : {}),
92
+ });
93
+ break;
94
+ }
95
+ case "text-delta": {
96
+ state.text += part.text;
97
+ const lastAssistantMessage = state.messages.at(-1);
98
+ const lastAssistantPart = lastAssistantMessage?.role === "assistant"
99
+ ? lastAssistantMessage.parts.at(-1)
100
+ : null;
101
+ if (lastAssistantMessage && lastAssistantPart && isFrameworkTextPart(lastAssistantPart)) {
102
+ lastAssistantPart.text += part.text;
103
+ }
104
+ else {
105
+ appendStreamedMessagePart(state, "assistant", {
106
+ type: "text",
107
+ text: part.text,
108
+ });
109
+ }
110
+ break;
111
+ }
112
+ case "tool-input-delta": {
113
+ const existing = state.toolCalls.get(part.toolCallId);
114
+ if (!existing) {
115
+ break;
116
+ }
117
+ existing.inputText = mergeToolInputDelta(existing.inputText, part.delta);
118
+ const parsedInput = getParsedStreamedToolInput(existing.inputText);
119
+ if (parsedInput) {
120
+ existing.input = parsedInput;
121
+ }
122
+ break;
123
+ }
124
+ case "tool-call": {
125
+ const existing = state.toolCalls.get(part.toolCallId);
126
+ state.toolCalls.set(part.toolCallId, {
127
+ toolCallId: part.toolCallId,
128
+ toolName: part.toolName,
129
+ input: part.input,
130
+ inputText: existing?.inputText ?? "",
131
+ status: "pending",
132
+ ...(existing?.output !== undefined ? { output: existing.output } : {}),
133
+ ...(existing?.errorText ? { errorText: existing.errorText } : {}),
134
+ });
135
+ appendStreamedMessagePart(state, "assistant", {
136
+ type: `tool-${part.toolName}`,
137
+ toolCallId: part.toolCallId,
138
+ toolName: part.toolName,
139
+ args: parseToolInputObject(part.input),
140
+ });
141
+ break;
142
+ }
143
+ case "tool-result": {
144
+ const existing = state.toolCalls.get(part.toolCallId);
145
+ state.toolCalls.set(part.toolCallId, {
146
+ toolCallId: part.toolCallId,
147
+ toolName: part.toolName,
148
+ input: part.input,
149
+ inputText: existing?.inputText ?? "",
150
+ status: "completed",
151
+ output: part.output,
152
+ ...(existing?.errorText ? { errorText: existing.errorText } : {}),
153
+ });
154
+ appendStreamedMessagePart(state, "tool", {
155
+ type: "tool-result",
156
+ toolCallId: part.toolCallId,
157
+ toolName: part.toolName,
158
+ result: part.output,
159
+ });
160
+ break;
161
+ }
162
+ case "tool-error": {
163
+ const existing = state.toolCalls.get(part.toolCallId);
164
+ state.toolCalls.set(part.toolCallId, {
165
+ toolCallId: part.toolCallId,
166
+ toolName: part.toolName,
167
+ input: part.input,
168
+ inputText: existing?.inputText ?? "",
169
+ status: "error",
170
+ ...(existing?.output !== undefined ? { output: existing.output } : {}),
171
+ errorText: part.error.message,
172
+ });
173
+ break;
174
+ }
175
+ default:
176
+ break;
177
+ }
178
+ }
179
+ function buildFallbackFrameworkMessages(baseMessages, state) {
180
+ const messages = baseMessages.map((message) => ({
181
+ ...message,
182
+ parts: [...message.parts],
183
+ }));
184
+ if (state.messages.length > 0) {
185
+ messages.push(...state.messages.map((message) => ({
186
+ id: dntShim.crypto.randomUUID(),
187
+ role: message.role,
188
+ timestamp: Date.now(),
189
+ parts: structuredClone(message.parts),
190
+ })));
191
+ }
192
+ else if (state.text.trim().length > 0) {
193
+ messages.push({
194
+ id: dntShim.crypto.randomUUID(),
195
+ role: "assistant",
196
+ timestamp: Date.now(),
197
+ parts: [{ type: "text", text: state.text }],
198
+ });
199
+ }
200
+ return messages;
201
+ }
202
+ function collectToolResultPaths(messages) {
203
+ const paths = new Set();
204
+ for (const message of messages) {
205
+ for (const part of message.parts) {
206
+ if (part.type !== "tool-result") {
207
+ continue;
208
+ }
209
+ const partResult = "result" in part ? part.result : null;
210
+ const result = isRecord(partResult) ? partResult : null;
211
+ const path = typeof result?.path === "string" ? result.path : null;
212
+ if (path) {
213
+ paths.add(path);
214
+ }
215
+ }
216
+ }
217
+ return [...paths];
218
+ }
219
+ function buildRecoverablePriorWorkState(messages) {
220
+ const paths = collectToolResultPaths(messages);
221
+ if (paths.length === 0) {
222
+ return null;
223
+ }
224
+ const previewPaths = paths.slice(0, 8);
225
+ const suffix = paths.length > previewPaths.length
226
+ ? ` and ${paths.length - previewPaths.length} more`
227
+ : "";
228
+ const text = `Completed child tool work. Project artifact(s): ${previewPaths.join(", ")}${suffix}.`;
229
+ return {
230
+ text,
231
+ toolCalls: new Map(),
232
+ messages: [
233
+ {
234
+ role: "assistant",
235
+ parts: [{ type: "text", text }],
236
+ },
237
+ ],
238
+ };
239
+ }
240
+ function hasFallbackStepContent(state) {
241
+ return state.text.trim().length > 0 || state.toolCalls.size > 0;
242
+ }
243
+ function buildFallbackAgentResponse(input) {
244
+ return {
245
+ text: input.state.text,
246
+ messages: buildFallbackFrameworkMessages(input.baseMessages, input.state),
247
+ toolCalls: [...input.state.toolCalls.values()].map((toolCall) => ({
248
+ id: toolCall.toolCallId,
249
+ name: toolCall.toolName,
250
+ args: parseToolInputObject(toolCall.input),
251
+ status: toolCall.status,
252
+ ...(toolCall.status === "completed" ? { result: toolCall.output } : {}),
253
+ ...(toolCall.status === "error" && toolCall.errorText ? { error: toolCall.errorText } : {}),
254
+ })),
255
+ metadata: {},
256
+ status: "completed",
257
+ };
258
+ }
259
+ export async function resolveForkStepResponse(input) {
260
+ const resolvedResponse = await resolveHostedChildPromiseWithTimeout(input.responsePromise, input.responseTimeoutMs);
261
+ if (resolvedResponse !== HOSTED_CHILD_STREAM_TIMEOUT_TOKEN) {
262
+ return resolvedResponse;
263
+ }
264
+ if (input.abortSignal?.aborted) {
265
+ throw createFrameworkForkAbortError(input.abortSignal);
266
+ }
267
+ const fallbackState = hasFallbackStepContent(input.streamedStepState)
268
+ ? input.streamedStepState
269
+ : buildRecoverablePriorWorkState(input.currentMessages);
270
+ if (!fallbackState) {
271
+ throw new Error("Framework fork stream ended without onFinish and without recoverable output.");
272
+ }
273
+ return buildFallbackAgentResponse({
274
+ baseMessages: input.currentMessages,
275
+ state: fallbackState,
276
+ });
277
+ }
278
+ function warnForkRuntimeStream(logger, message, metadata) {
279
+ logger?.warn(message, metadata);
280
+ }
281
+ export function buildRecoveredStepParts(step, state) {
282
+ const recoveredParts = [];
283
+ for (const toolCall of step.toolCalls) {
284
+ if (state.emittedToolCallIds.has(toolCall.toolCallId)) {
285
+ continue;
286
+ }
287
+ const streamedCall = state.toolCalls.get(toolCall.toolCallId);
288
+ warnForkRuntimeStream(state.logger, "Child fork recovered missing tool-call from final step", {
289
+ toolCallId: toolCall.toolCallId,
290
+ toolName: toolCall.toolName,
291
+ sawInputStart: streamedCall?.sawInputStart ?? false,
292
+ sawInputDelta: streamedCall?.sawInputDelta ?? false,
293
+ sawInputAvailable: streamedCall?.sawInputAvailable ?? false,
294
+ sawOutputAvailable: streamedCall?.sawOutputAvailable ?? false,
295
+ sawOutputError: streamedCall?.sawOutputError ?? false,
296
+ });
297
+ state.emittedToolCallIds.add(toolCall.toolCallId);
298
+ recoveredParts.push({
299
+ type: "tool-call",
300
+ toolCallId: toolCall.toolCallId,
301
+ toolName: toolCall.toolName,
302
+ input: toolCall.input,
303
+ });
304
+ }
305
+ for (const toolResult of step.toolResults) {
306
+ if (state.emittedToolResultIds.has(toolResult.toolCallId)) {
307
+ continue;
308
+ }
309
+ const streamedCall = state.toolCalls.get(toolResult.toolCallId);
310
+ warnForkRuntimeStream(state.logger, "Child fork recovered missing tool-result from final step", {
311
+ toolCallId: toolResult.toolCallId,
312
+ toolName: toolResult.toolName,
313
+ sawInputStart: streamedCall?.sawInputStart ?? false,
314
+ sawInputDelta: streamedCall?.sawInputDelta ?? false,
315
+ sawInputAvailable: streamedCall?.sawInputAvailable ?? false,
316
+ sawOutputAvailable: streamedCall?.sawOutputAvailable ?? false,
317
+ sawOutputError: streamedCall?.sawOutputError ?? false,
318
+ });
319
+ state.emittedToolResultIds.add(toolResult.toolCallId);
320
+ recoveredParts.push({
321
+ type: "tool-result",
322
+ toolCallId: toolResult.toolCallId,
323
+ toolName: toolResult.toolName,
324
+ input: toolResult.input,
325
+ output: toolResult.output,
326
+ });
327
+ }
328
+ return recoveredParts;
329
+ }
330
+ function isEmptyRecord(value) {
331
+ return Object.keys(value).length === 0;
332
+ }
333
+ function getParsedStreamedToolInput(inputText) {
334
+ const strippedInputText = stripLeadingEmptyObjectPlaceholder(inputText).trim();
335
+ const normalizedInputText = strippedInputText.startsWith('"')
336
+ ? `{${strippedInputText}`
337
+ : strippedInputText;
338
+ if (normalizedInputText.length === 0) {
339
+ return {};
340
+ }
341
+ const parsed = safeJsonParse(normalizedInputText);
342
+ if (!parsed.ok) {
343
+ return null;
344
+ }
345
+ return isRecord(parsed.value) ? Object.fromEntries(Object.entries(parsed.value)) : {};
346
+ }
347
+ function buildToolCallPartIfNeeded(toolCallId, state) {
348
+ const toolCall = state.toolCalls.get(toolCallId);
349
+ if (!toolCall || state.emittedToolCallIds.has(toolCallId)) {
350
+ return [];
351
+ }
352
+ state.emittedToolCallIds.add(toolCallId);
353
+ return [
354
+ {
355
+ type: "tool-call",
356
+ toolCallId,
357
+ toolName: toolCall.toolName,
358
+ input: toolCall.input,
359
+ },
360
+ ];
361
+ }
362
+ export function createFrameworkStreamState(input = {}) {
363
+ return {
364
+ toolCalls: new Map(),
365
+ emittedToolCallIds: new Set(),
366
+ emittedToolResultIds: new Set(),
367
+ ...(input.logger ? { logger: input.logger } : {}),
368
+ };
369
+ }
370
+ export function mapFrameworkEventToForkParts(event, state) {
371
+ switch (event.type) {
372
+ case "reasoning-delta":
373
+ return typeof event.delta === "string"
374
+ ? [{ type: "reasoning-delta", text: event.delta }]
375
+ : [];
376
+ case "text-delta":
377
+ return typeof event.delta === "string" ? [{ type: "text-delta", text: event.delta }] : [];
378
+ case "tool-input-start": {
379
+ const toolCallId = typeof event.toolCallId === "string" ? event.toolCallId : null;
380
+ const toolName = typeof event.toolName === "string" ? event.toolName : null;
381
+ if (!toolCallId || !toolName) {
382
+ return [];
383
+ }
384
+ const existing = state.toolCalls.get(toolCallId);
385
+ state.toolCalls.set(toolCallId, {
386
+ toolName,
387
+ inputText: existing?.inputText ?? "",
388
+ input: existing?.input ?? {},
389
+ sawInputStart: true,
390
+ sawInputDelta: existing?.sawInputDelta ?? false,
391
+ sawInputAvailable: existing?.sawInputAvailable ?? false,
392
+ sawOutputAvailable: existing?.sawOutputAvailable ?? false,
393
+ sawOutputError: existing?.sawOutputError ?? false,
394
+ });
395
+ return [{ type: "tool-input-start", toolCallId, toolName }];
396
+ }
397
+ case "tool-input-delta": {
398
+ const inputToolCallId = typeof event.toolCallId === "string" ? event.toolCallId : null;
399
+ const inputDelta = typeof event.inputTextDelta === "string" ? event.inputTextDelta : null;
400
+ if (!inputToolCallId || !inputDelta) {
401
+ return [];
402
+ }
403
+ const existing = state.toolCalls.get(inputToolCallId);
404
+ if (existing) {
405
+ existing.inputText = mergeToolInputDelta(existing.inputText, inputDelta);
406
+ existing.sawInputDelta = true;
407
+ const parsedInput = getParsedStreamedToolInput(existing.inputText);
408
+ if (parsedInput) {
409
+ existing.input = parsedInput;
410
+ }
411
+ }
412
+ else {
413
+ warnForkRuntimeStream(state.logger, "Child fork received tool-input-delta before tool-input-start", {
414
+ toolCallId: inputToolCallId,
415
+ deltaLength: inputDelta.length,
416
+ });
417
+ }
418
+ return [{ type: "tool-input-delta", toolCallId: inputToolCallId, delta: inputDelta }];
419
+ }
420
+ case "tool-input-available": {
421
+ const toolCallId = typeof event.toolCallId === "string" ? event.toolCallId : null;
422
+ const toolName = typeof event.toolName === "string" ? event.toolName : null;
423
+ if (!toolCallId || !toolName) {
424
+ return [];
425
+ }
426
+ const input = parseToolInputObject(event.input);
427
+ const existing = state.toolCalls.get(toolCallId);
428
+ const resolvedInput = existing && isEmptyRecord(input) && !isEmptyRecord(existing.input)
429
+ ? existing.input
430
+ : input;
431
+ state.toolCalls.set(toolCallId, {
432
+ toolName,
433
+ inputText: "",
434
+ input: resolvedInput,
435
+ sawInputStart: existing?.sawInputStart ?? false,
436
+ sawInputDelta: existing?.sawInputDelta ?? false,
437
+ sawInputAvailable: true,
438
+ sawOutputAvailable: existing?.sawOutputAvailable ?? false,
439
+ sawOutputError: existing?.sawOutputError ?? false,
440
+ });
441
+ return buildToolCallPartIfNeeded(toolCallId, state);
442
+ }
443
+ case "tool-output-available": {
444
+ if (event.preliminary === true) {
445
+ return [];
446
+ }
447
+ const toolCallId = typeof event.toolCallId === "string" ? event.toolCallId : null;
448
+ if (!toolCallId) {
449
+ return [];
450
+ }
451
+ const call = state.toolCalls.get(toolCallId);
452
+ if (!call) {
453
+ return [];
454
+ }
455
+ call.sawOutputAvailable = true;
456
+ const parts = [
457
+ ...buildToolCallPartIfNeeded(toolCallId, state),
458
+ ];
459
+ state.emittedToolResultIds.add(toolCallId);
460
+ parts.push({
461
+ type: "tool-result",
462
+ toolCallId,
463
+ toolName: call.toolName,
464
+ input: call.input,
465
+ output: Object.hasOwn(event, "output") ? event.output : null,
466
+ });
467
+ return parts;
468
+ }
469
+ case "tool-output-error":
470
+ case "tool-input-error": {
471
+ const toolCallId = typeof event.toolCallId === "string" ? event.toolCallId : null;
472
+ if (!toolCallId) {
473
+ return [];
474
+ }
475
+ const call = state.toolCalls.get(toolCallId);
476
+ const errorText = typeof event.errorText === "string"
477
+ ? event.errorText
478
+ : typeof event.error === "string"
479
+ ? event.error
480
+ : "Tool execution failed";
481
+ if (call) {
482
+ call.sawOutputError = true;
483
+ }
484
+ const parts = [
485
+ ...buildToolCallPartIfNeeded(toolCallId, state),
486
+ ];
487
+ parts.push({
488
+ type: "tool-error",
489
+ toolCallId,
490
+ toolName: call?.toolName ?? "unknown",
491
+ input: call?.input ?? {},
492
+ error: new Error(errorText),
493
+ });
494
+ return parts;
495
+ }
496
+ case "error": {
497
+ const errorText = typeof event.errorText === "string"
498
+ ? event.errorText
499
+ : "Framework stream failed";
500
+ return [{ type: "error", error: new Error(errorText) }];
501
+ }
502
+ default:
503
+ return [];
504
+ }
505
+ }