@fgv/ts-extras 5.1.0-4 → 5.1.0-40

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 (368) hide show
  1. package/dist/index.browser.js +4 -2
  2. package/dist/index.browser.js.map +1 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/packlets/ai-assist/apiClient.js +886 -158
  5. package/dist/packlets/ai-assist/apiClient.js.map +1 -0
  6. package/dist/packlets/ai-assist/chatRequestBuilders.js +282 -0
  7. package/dist/packlets/ai-assist/chatRequestBuilders.js.map +1 -0
  8. package/dist/packlets/ai-assist/converters.js +47 -3
  9. package/dist/packlets/ai-assist/converters.js.map +1 -0
  10. package/dist/packlets/ai-assist/embeddingClient.js +345 -0
  11. package/dist/packlets/ai-assist/embeddingClient.js.map +1 -0
  12. package/dist/packlets/ai-assist/endpoint.js +78 -0
  13. package/dist/packlets/ai-assist/endpoint.js.map +1 -0
  14. package/dist/packlets/ai-assist/http.js +75 -0
  15. package/dist/packlets/ai-assist/http.js.map +1 -0
  16. package/dist/packlets/ai-assist/imageOptionsResolver.js +193 -0
  17. package/dist/packlets/ai-assist/imageOptionsResolver.js.map +1 -0
  18. package/dist/packlets/ai-assist/index.js +10 -4
  19. package/dist/packlets/ai-assist/index.js.map +1 -0
  20. package/dist/packlets/ai-assist/jsonCompletion.js +93 -0
  21. package/dist/packlets/ai-assist/jsonCompletion.js.map +1 -0
  22. package/dist/packlets/ai-assist/jsonResponse.js +149 -0
  23. package/dist/packlets/ai-assist/jsonResponse.js.map +1 -0
  24. package/dist/packlets/ai-assist/model.js +193 -9
  25. package/dist/packlets/ai-assist/model.js.map +1 -0
  26. package/dist/packlets/ai-assist/registry.js +314 -12
  27. package/dist/packlets/ai-assist/registry.js.map +1 -0
  28. package/dist/packlets/ai-assist/sseParser.js +123 -0
  29. package/dist/packlets/ai-assist/sseParser.js.map +1 -0
  30. package/dist/packlets/ai-assist/streamingAdapters/anthropic.js +368 -0
  31. package/dist/packlets/ai-assist/streamingAdapters/anthropic.js.map +1 -0
  32. package/dist/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.js +687 -0
  33. package/dist/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.js.map +1 -0
  34. package/dist/packlets/ai-assist/streamingAdapters/common.js +187 -0
  35. package/dist/packlets/ai-assist/streamingAdapters/common.js.map +1 -0
  36. package/dist/packlets/ai-assist/streamingAdapters/gemini.js +204 -0
  37. package/dist/packlets/ai-assist/streamingAdapters/gemini.js.map +1 -0
  38. package/dist/packlets/ai-assist/streamingAdapters/openaiChat.js +170 -0
  39. package/dist/packlets/ai-assist/streamingAdapters/openaiChat.js.map +1 -0
  40. package/dist/packlets/ai-assist/streamingAdapters/openaiResponses.js +386 -0
  41. package/dist/packlets/ai-assist/streamingAdapters/openaiResponses.js.map +1 -0
  42. package/dist/packlets/ai-assist/streamingAdapters/proxy.js +173 -0
  43. package/dist/packlets/ai-assist/streamingAdapters/proxy.js.map +1 -0
  44. package/dist/packlets/ai-assist/streamingClient.js +140 -0
  45. package/dist/packlets/ai-assist/streamingClient.js.map +1 -0
  46. package/dist/packlets/ai-assist/thinkingOptionsResolver.js +288 -0
  47. package/dist/packlets/ai-assist/thinkingOptionsResolver.js.map +1 -0
  48. package/dist/packlets/ai-assist/toolFormats.js +106 -10
  49. package/dist/packlets/ai-assist/toolFormats.js.map +1 -0
  50. package/dist/packlets/conversion/converters.js +35 -1
  51. package/dist/packlets/conversion/converters.js.map +1 -0
  52. package/dist/packlets/conversion/index.js.map +1 -0
  53. package/dist/packlets/crypto-utils/constants.js.map +1 -0
  54. package/dist/packlets/crypto-utils/converters.js +42 -4
  55. package/dist/packlets/crypto-utils/converters.js.map +1 -0
  56. package/dist/packlets/crypto-utils/directEncryptionProvider.js.map +1 -0
  57. package/dist/packlets/crypto-utils/encryptedFile.js.map +1 -0
  58. package/dist/packlets/crypto-utils/hpkeProvider.js +333 -0
  59. package/dist/packlets/crypto-utils/hpkeProvider.js.map +1 -0
  60. package/dist/packlets/crypto-utils/index.browser.js +10 -2
  61. package/dist/packlets/crypto-utils/index.browser.js.map +1 -0
  62. package/dist/packlets/crypto-utils/index.js +6 -0
  63. package/dist/packlets/crypto-utils/index.js.map +1 -0
  64. package/dist/packlets/crypto-utils/keyPairAlgorithmParams.js +71 -0
  65. package/dist/packlets/crypto-utils/keyPairAlgorithmParams.js.map +1 -0
  66. package/dist/packlets/crypto-utils/keystore/converters.js +103 -11
  67. package/dist/packlets/crypto-utils/keystore/converters.js.map +1 -0
  68. package/dist/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.js +287 -0
  69. package/dist/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.js.map +1 -0
  70. package/dist/packlets/crypto-utils/keystore/index.browser.js +36 -0
  71. package/dist/packlets/crypto-utils/keystore/index.browser.js.map +1 -0
  72. package/dist/packlets/crypto-utils/keystore/index.js +3 -0
  73. package/dist/packlets/crypto-utils/keystore/index.js.map +1 -0
  74. package/dist/packlets/crypto-utils/keystore/keyStore.js +633 -118
  75. package/dist/packlets/crypto-utils/keystore/keyStore.js.map +1 -0
  76. package/dist/packlets/crypto-utils/keystore/model.js +22 -1
  77. package/dist/packlets/crypto-utils/keystore/model.js.map +1 -0
  78. package/dist/packlets/crypto-utils/keystore/privateKeyStorage.js +21 -0
  79. package/dist/packlets/crypto-utils/keystore/privateKeyStorage.js.map +1 -0
  80. package/dist/packlets/crypto-utils/model.js +32 -0
  81. package/dist/packlets/crypto-utils/model.js.map +1 -0
  82. package/dist/packlets/crypto-utils/nodeCryptoProvider.js +270 -1
  83. package/dist/packlets/crypto-utils/nodeCryptoProvider.js.map +1 -0
  84. package/dist/packlets/crypto-utils/spkiHelpers.js +209 -0
  85. package/dist/packlets/crypto-utils/spkiHelpers.js.map +1 -0
  86. package/dist/packlets/csv/csvFileHelpers.js +0 -14
  87. package/dist/packlets/csv/csvFileHelpers.js.map +1 -0
  88. package/dist/packlets/csv/csvHelpers.js +14 -0
  89. package/dist/packlets/csv/csvHelpers.js.map +1 -0
  90. package/dist/packlets/csv/index.browser.js +1 -3
  91. package/dist/packlets/csv/index.browser.js.map +1 -0
  92. package/dist/packlets/csv/index.js.map +1 -0
  93. package/dist/packlets/experimental/extendedArray.js.map +1 -0
  94. package/dist/packlets/experimental/formatter.js.map +1 -0
  95. package/dist/packlets/experimental/index.js.map +1 -0
  96. package/dist/packlets/experimental/rangeOf.js.map +1 -0
  97. package/dist/packlets/hash/index.browser.js.map +1 -0
  98. package/dist/packlets/hash/index.js.map +1 -0
  99. package/dist/packlets/hash/index.node.js.map +1 -0
  100. package/dist/packlets/hash/md5Normalizer.browser.js.map +1 -0
  101. package/dist/packlets/hash/md5Normalizer.js.map +1 -0
  102. package/dist/packlets/mustache/index.js.map +1 -0
  103. package/dist/packlets/mustache/interfaces.js.map +1 -0
  104. package/dist/packlets/mustache/mustacheTemplate.js +42 -4
  105. package/dist/packlets/mustache/mustacheTemplate.js.map +1 -0
  106. package/dist/packlets/record-jar/index.browser.js +1 -3
  107. package/dist/packlets/record-jar/index.browser.js.map +1 -0
  108. package/dist/packlets/record-jar/index.js.map +1 -0
  109. package/dist/packlets/record-jar/recordJarFileHelpers.js +0 -18
  110. package/dist/packlets/record-jar/recordJarFileHelpers.js.map +1 -0
  111. package/dist/packlets/record-jar/recordJarHelpers.js +18 -0
  112. package/dist/packlets/record-jar/recordJarHelpers.js.map +1 -0
  113. package/dist/packlets/yaml/converters.js.map +1 -0
  114. package/dist/packlets/yaml/index.js +1 -0
  115. package/dist/packlets/yaml/index.js.map +1 -0
  116. package/dist/packlets/yaml/serializers.js +48 -0
  117. package/dist/packlets/yaml/serializers.js.map +1 -0
  118. package/dist/packlets/zip-file-tree/index.js.map +1 -0
  119. package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js +2 -2
  120. package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js.map +1 -0
  121. package/dist/packlets/zip-file-tree/zipFileTreeWriter.js.map +1 -0
  122. package/dist/ts-extras.d.ts +3880 -105
  123. package/dist/tsdoc-metadata.json +1 -1
  124. package/lib/index.browser.d.ts +4 -2
  125. package/lib/index.browser.d.ts.map +1 -0
  126. package/lib/index.browser.js +8 -3
  127. package/lib/index.browser.js.map +1 -0
  128. package/lib/index.d.ts.map +1 -0
  129. package/lib/index.js.map +1 -0
  130. package/lib/packlets/ai-assist/apiClient.d.ts +115 -32
  131. package/lib/packlets/ai-assist/apiClient.d.ts.map +1 -0
  132. package/lib/packlets/ai-assist/apiClient.js +888 -156
  133. package/lib/packlets/ai-assist/apiClient.js.map +1 -0
  134. package/lib/packlets/ai-assist/chatRequestBuilders.d.ts +149 -0
  135. package/lib/packlets/ai-assist/chatRequestBuilders.d.ts.map +1 -0
  136. package/lib/packlets/ai-assist/chatRequestBuilders.js +293 -0
  137. package/lib/packlets/ai-assist/chatRequestBuilders.js.map +1 -0
  138. package/lib/packlets/ai-assist/converters.d.ts +15 -1
  139. package/lib/packlets/ai-assist/converters.d.ts.map +1 -0
  140. package/lib/packlets/ai-assist/converters.js +47 -3
  141. package/lib/packlets/ai-assist/converters.js.map +1 -0
  142. package/lib/packlets/ai-assist/embeddingClient.d.ts +69 -0
  143. package/lib/packlets/ai-assist/embeddingClient.d.ts.map +1 -0
  144. package/lib/packlets/ai-assist/embeddingClient.js +349 -0
  145. package/lib/packlets/ai-assist/embeddingClient.js.map +1 -0
  146. package/lib/packlets/ai-assist/endpoint.d.ts +28 -0
  147. package/lib/packlets/ai-assist/endpoint.d.ts.map +1 -0
  148. package/lib/packlets/ai-assist/endpoint.js +82 -0
  149. package/lib/packlets/ai-assist/endpoint.js.map +1 -0
  150. package/lib/packlets/ai-assist/http.d.ts +24 -0
  151. package/lib/packlets/ai-assist/http.d.ts.map +1 -0
  152. package/lib/packlets/ai-assist/http.js +78 -0
  153. package/lib/packlets/ai-assist/http.js.map +1 -0
  154. package/lib/packlets/ai-assist/imageOptionsResolver.d.ts +66 -0
  155. package/lib/packlets/ai-assist/imageOptionsResolver.d.ts.map +1 -0
  156. package/lib/packlets/ai-assist/imageOptionsResolver.js +197 -0
  157. package/lib/packlets/ai-assist/imageOptionsResolver.js.map +1 -0
  158. package/lib/packlets/ai-assist/index.d.ts +10 -4
  159. package/lib/packlets/ai-assist/index.d.ts.map +1 -0
  160. package/lib/packlets/ai-assist/index.js +36 -1
  161. package/lib/packlets/ai-assist/index.js.map +1 -0
  162. package/lib/packlets/ai-assist/jsonCompletion.d.ts +93 -0
  163. package/lib/packlets/ai-assist/jsonCompletion.d.ts.map +1 -0
  164. package/lib/packlets/ai-assist/jsonCompletion.js +97 -0
  165. package/lib/packlets/ai-assist/jsonCompletion.js.map +1 -0
  166. package/lib/packlets/ai-assist/jsonResponse.d.ts +91 -0
  167. package/lib/packlets/ai-assist/jsonResponse.d.ts.map +1 -0
  168. package/lib/packlets/ai-assist/jsonResponse.js +154 -0
  169. package/lib/packlets/ai-assist/jsonResponse.js.map +1 -0
  170. package/lib/packlets/ai-assist/model.d.ts +1202 -12
  171. package/lib/packlets/ai-assist/model.d.ts.map +1 -0
  172. package/lib/packlets/ai-assist/model.js +198 -10
  173. package/lib/packlets/ai-assist/model.js.map +1 -0
  174. package/lib/packlets/ai-assist/registry.d.ts +56 -1
  175. package/lib/packlets/ai-assist/registry.d.ts.map +1 -0
  176. package/lib/packlets/ai-assist/registry.js +319 -13
  177. package/lib/packlets/ai-assist/registry.js.map +1 -0
  178. package/lib/packlets/ai-assist/sseParser.d.ts +45 -0
  179. package/lib/packlets/ai-assist/sseParser.d.ts.map +1 -0
  180. package/lib/packlets/ai-assist/sseParser.js +128 -0
  181. package/lib/packlets/ai-assist/sseParser.js.map +1 -0
  182. package/lib/packlets/ai-assist/streamingAdapters/anthropic.d.ts +72 -0
  183. package/lib/packlets/ai-assist/streamingAdapters/anthropic.d.ts.map +1 -0
  184. package/lib/packlets/ai-assist/streamingAdapters/anthropic.js +371 -0
  185. package/lib/packlets/ai-assist/streamingAdapters/anthropic.js.map +1 -0
  186. package/lib/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.d.ts +260 -0
  187. package/lib/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.d.ts.map +1 -0
  188. package/lib/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.js +694 -0
  189. package/lib/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.js.map +1 -0
  190. package/lib/packlets/ai-assist/streamingAdapters/common.d.ts +154 -0
  191. package/lib/packlets/ai-assist/streamingAdapters/common.d.ts.map +1 -0
  192. package/lib/packlets/ai-assist/streamingAdapters/common.js +193 -0
  193. package/lib/packlets/ai-assist/streamingAdapters/common.js.map +1 -0
  194. package/lib/packlets/ai-assist/streamingAdapters/gemini.d.ts +43 -0
  195. package/lib/packlets/ai-assist/streamingAdapters/gemini.d.ts.map +1 -0
  196. package/lib/packlets/ai-assist/streamingAdapters/gemini.js +207 -0
  197. package/lib/packlets/ai-assist/streamingAdapters/gemini.js.map +1 -0
  198. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.d.ts +19 -0
  199. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.d.ts.map +1 -0
  200. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.js +173 -0
  201. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.js.map +1 -0
  202. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.d.ts +33 -0
  203. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.d.ts.map +1 -0
  204. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.js +389 -0
  205. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.js.map +1 -0
  206. package/lib/packlets/ai-assist/streamingAdapters/proxy.d.ts +34 -0
  207. package/lib/packlets/ai-assist/streamingAdapters/proxy.d.ts.map +1 -0
  208. package/lib/packlets/ai-assist/streamingAdapters/proxy.js +176 -0
  209. package/lib/packlets/ai-assist/streamingAdapters/proxy.js.map +1 -0
  210. package/lib/packlets/ai-assist/streamingClient.d.ts +50 -0
  211. package/lib/packlets/ai-assist/streamingClient.d.ts.map +1 -0
  212. package/lib/packlets/ai-assist/streamingClient.js +146 -0
  213. package/lib/packlets/ai-assist/streamingClient.js.map +1 -0
  214. package/lib/packlets/ai-assist/thinkingOptionsResolver.d.ts +87 -0
  215. package/lib/packlets/ai-assist/thinkingOptionsResolver.d.ts.map +1 -0
  216. package/lib/packlets/ai-assist/thinkingOptionsResolver.js +294 -0
  217. package/lib/packlets/ai-assist/thinkingOptionsResolver.js.map +1 -0
  218. package/lib/packlets/ai-assist/toolFormats.d.ts +40 -9
  219. package/lib/packlets/ai-assist/toolFormats.d.ts.map +1 -0
  220. package/lib/packlets/ai-assist/toolFormats.js +107 -10
  221. package/lib/packlets/ai-assist/toolFormats.js.map +1 -0
  222. package/lib/packlets/conversion/converters.d.ts +8 -1
  223. package/lib/packlets/conversion/converters.d.ts.map +1 -0
  224. package/lib/packlets/conversion/converters.js +36 -2
  225. package/lib/packlets/conversion/converters.js.map +1 -0
  226. package/lib/packlets/conversion/index.d.ts.map +1 -0
  227. package/lib/packlets/conversion/index.js.map +1 -0
  228. package/lib/packlets/crypto-utils/constants.d.ts.map +1 -0
  229. package/lib/packlets/crypto-utils/constants.js.map +1 -0
  230. package/lib/packlets/crypto-utils/converters.d.ts +20 -1
  231. package/lib/packlets/crypto-utils/converters.d.ts.map +1 -0
  232. package/lib/packlets/crypto-utils/converters.js +43 -5
  233. package/lib/packlets/crypto-utils/converters.js.map +1 -0
  234. package/lib/packlets/crypto-utils/directEncryptionProvider.d.ts.map +1 -0
  235. package/lib/packlets/crypto-utils/directEncryptionProvider.js.map +1 -0
  236. package/lib/packlets/crypto-utils/encryptedFile.d.ts.map +1 -0
  237. package/lib/packlets/crypto-utils/encryptedFile.js.map +1 -0
  238. package/lib/packlets/crypto-utils/hpkeProvider.d.ts +142 -0
  239. package/lib/packlets/crypto-utils/hpkeProvider.d.ts.map +1 -0
  240. package/lib/packlets/crypto-utils/hpkeProvider.js +337 -0
  241. package/lib/packlets/crypto-utils/hpkeProvider.js.map +1 -0
  242. package/lib/packlets/crypto-utils/index.browser.d.ts +4 -1
  243. package/lib/packlets/crypto-utils/index.browser.d.ts.map +1 -0
  244. package/lib/packlets/crypto-utils/index.browser.js +21 -3
  245. package/lib/packlets/crypto-utils/index.browser.js.map +1 -0
  246. package/lib/packlets/crypto-utils/index.d.ts +3 -0
  247. package/lib/packlets/crypto-utils/index.d.ts.map +1 -0
  248. package/lib/packlets/crypto-utils/index.js +17 -1
  249. package/lib/packlets/crypto-utils/index.js.map +1 -0
  250. package/lib/packlets/crypto-utils/keyPairAlgorithmParams.d.ts +54 -0
  251. package/lib/packlets/crypto-utils/keyPairAlgorithmParams.d.ts.map +1 -0
  252. package/lib/packlets/crypto-utils/keyPairAlgorithmParams.js +74 -0
  253. package/lib/packlets/crypto-utils/keyPairAlgorithmParams.js.map +1 -0
  254. package/lib/packlets/crypto-utils/keystore/converters.d.ts +68 -6
  255. package/lib/packlets/crypto-utils/keystore/converters.d.ts.map +1 -0
  256. package/lib/packlets/crypto-utils/keystore/converters.js +101 -9
  257. package/lib/packlets/crypto-utils/keystore/converters.js.map +1 -0
  258. package/lib/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.d.ts +148 -0
  259. package/lib/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.d.ts.map +1 -0
  260. package/lib/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.js +324 -0
  261. package/lib/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.js.map +1 -0
  262. package/lib/packlets/crypto-utils/keystore/index.browser.d.ts +10 -0
  263. package/lib/packlets/crypto-utils/keystore/index.browser.d.ts.map +1 -0
  264. package/lib/packlets/crypto-utils/keystore/index.browser.js +76 -0
  265. package/lib/packlets/crypto-utils/keystore/index.browser.js.map +1 -0
  266. package/lib/packlets/crypto-utils/keystore/index.d.ts +2 -0
  267. package/lib/packlets/crypto-utils/keystore/index.d.ts.map +1 -0
  268. package/lib/packlets/crypto-utils/keystore/index.js +5 -1
  269. package/lib/packlets/crypto-utils/keystore/index.js.map +1 -0
  270. package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +205 -13
  271. package/lib/packlets/crypto-utils/keystore/keyStore.d.ts.map +1 -0
  272. package/lib/packlets/crypto-utils/keystore/keyStore.js +639 -124
  273. package/lib/packlets/crypto-utils/keystore/keyStore.js.map +1 -0
  274. package/lib/packlets/crypto-utils/keystore/model.d.ts +275 -19
  275. package/lib/packlets/crypto-utils/keystore/model.d.ts.map +1 -0
  276. package/lib/packlets/crypto-utils/keystore/model.js +24 -2
  277. package/lib/packlets/crypto-utils/keystore/model.js.map +1 -0
  278. package/lib/packlets/crypto-utils/keystore/privateKeyStorage.d.ts +53 -0
  279. package/lib/packlets/crypto-utils/keystore/privateKeyStorage.d.ts.map +1 -0
  280. package/lib/packlets/crypto-utils/keystore/privateKeyStorage.js +22 -0
  281. package/lib/packlets/crypto-utils/keystore/privateKeyStorage.js.map +1 -0
  282. package/lib/packlets/crypto-utils/model.d.ts +348 -10
  283. package/lib/packlets/crypto-utils/model.d.ts.map +1 -0
  284. package/lib/packlets/crypto-utils/model.js +33 -1
  285. package/lib/packlets/crypto-utils/model.js.map +1 -0
  286. package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +110 -2
  287. package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts.map +1 -0
  288. package/lib/packlets/crypto-utils/nodeCryptoProvider.js +269 -0
  289. package/lib/packlets/crypto-utils/nodeCryptoProvider.js.map +1 -0
  290. package/lib/packlets/crypto-utils/spkiHelpers.d.ts +110 -0
  291. package/lib/packlets/crypto-utils/spkiHelpers.d.ts.map +1 -0
  292. package/lib/packlets/crypto-utils/spkiHelpers.js +219 -0
  293. package/lib/packlets/crypto-utils/spkiHelpers.js.map +1 -0
  294. package/lib/packlets/csv/csvFileHelpers.d.ts +0 -10
  295. package/lib/packlets/csv/csvFileHelpers.d.ts.map +1 -0
  296. package/lib/packlets/csv/csvFileHelpers.js +0 -15
  297. package/lib/packlets/csv/csvFileHelpers.js.map +1 -0
  298. package/lib/packlets/csv/csvHelpers.d.ts +10 -0
  299. package/lib/packlets/csv/csvHelpers.d.ts.map +1 -0
  300. package/lib/packlets/csv/csvHelpers.js +15 -0
  301. package/lib/packlets/csv/csvHelpers.js.map +1 -0
  302. package/lib/packlets/csv/index.browser.d.ts +0 -1
  303. package/lib/packlets/csv/index.browser.d.ts.map +1 -0
  304. package/lib/packlets/csv/index.browser.js +1 -5
  305. package/lib/packlets/csv/index.browser.js.map +1 -0
  306. package/lib/packlets/csv/index.d.ts.map +1 -0
  307. package/lib/packlets/csv/index.js.map +1 -0
  308. package/lib/packlets/experimental/extendedArray.d.ts.map +1 -0
  309. package/lib/packlets/experimental/extendedArray.js.map +1 -0
  310. package/lib/packlets/experimental/formatter.d.ts.map +1 -0
  311. package/lib/packlets/experimental/formatter.js.map +1 -0
  312. package/lib/packlets/experimental/index.d.ts.map +1 -0
  313. package/lib/packlets/experimental/index.js.map +1 -0
  314. package/lib/packlets/experimental/rangeOf.d.ts.map +1 -0
  315. package/lib/packlets/experimental/rangeOf.js.map +1 -0
  316. package/lib/packlets/hash/index.browser.d.ts.map +1 -0
  317. package/lib/packlets/hash/index.browser.js.map +1 -0
  318. package/lib/packlets/hash/index.d.ts.map +1 -0
  319. package/lib/packlets/hash/index.js.map +1 -0
  320. package/lib/packlets/hash/index.node.d.ts.map +1 -0
  321. package/lib/packlets/hash/index.node.js.map +1 -0
  322. package/lib/packlets/hash/md5Normalizer.browser.d.ts.map +1 -0
  323. package/lib/packlets/hash/md5Normalizer.browser.js.map +1 -0
  324. package/lib/packlets/hash/md5Normalizer.d.ts.map +1 -0
  325. package/lib/packlets/hash/md5Normalizer.js.map +1 -0
  326. package/lib/packlets/mustache/index.d.ts +1 -1
  327. package/lib/packlets/mustache/index.d.ts.map +1 -0
  328. package/lib/packlets/mustache/index.js.map +1 -0
  329. package/lib/packlets/mustache/interfaces.d.ts +34 -0
  330. package/lib/packlets/mustache/interfaces.d.ts.map +1 -0
  331. package/lib/packlets/mustache/interfaces.js.map +1 -0
  332. package/lib/packlets/mustache/mustacheTemplate.d.ts +2 -0
  333. package/lib/packlets/mustache/mustacheTemplate.d.ts.map +1 -0
  334. package/lib/packlets/mustache/mustacheTemplate.js +42 -4
  335. package/lib/packlets/mustache/mustacheTemplate.js.map +1 -0
  336. package/lib/packlets/record-jar/index.browser.d.ts +0 -1
  337. package/lib/packlets/record-jar/index.browser.d.ts.map +1 -0
  338. package/lib/packlets/record-jar/index.browser.js +1 -5
  339. package/lib/packlets/record-jar/index.browser.js.map +1 -0
  340. package/lib/packlets/record-jar/index.d.ts.map +1 -0
  341. package/lib/packlets/record-jar/index.js.map +1 -0
  342. package/lib/packlets/record-jar/recordJarFileHelpers.d.ts +0 -11
  343. package/lib/packlets/record-jar/recordJarFileHelpers.d.ts.map +1 -0
  344. package/lib/packlets/record-jar/recordJarFileHelpers.js +0 -19
  345. package/lib/packlets/record-jar/recordJarFileHelpers.js.map +1 -0
  346. package/lib/packlets/record-jar/recordJarHelpers.d.ts +11 -0
  347. package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +1 -0
  348. package/lib/packlets/record-jar/recordJarHelpers.js +19 -0
  349. package/lib/packlets/record-jar/recordJarHelpers.js.map +1 -0
  350. package/lib/packlets/yaml/converters.d.ts.map +1 -0
  351. package/lib/packlets/yaml/converters.js.map +1 -0
  352. package/lib/packlets/yaml/index.d.ts +1 -0
  353. package/lib/packlets/yaml/index.d.ts.map +1 -0
  354. package/lib/packlets/yaml/index.js +1 -0
  355. package/lib/packlets/yaml/index.js.map +1 -0
  356. package/lib/packlets/yaml/serializers.d.ts +45 -0
  357. package/lib/packlets/yaml/serializers.d.ts.map +1 -0
  358. package/lib/packlets/yaml/serializers.js +84 -0
  359. package/lib/packlets/yaml/serializers.js.map +1 -0
  360. package/lib/packlets/zip-file-tree/index.d.ts.map +1 -0
  361. package/lib/packlets/zip-file-tree/index.js.map +1 -0
  362. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +2 -2
  363. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts.map +1 -0
  364. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +2 -2
  365. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js.map +1 -0
  366. package/lib/packlets/zip-file-tree/zipFileTreeWriter.d.ts.map +1 -0
  367. package/lib/packlets/zip-file-tree/zipFileTreeWriter.js.map +1 -0
  368. package/package.json +20 -15
@@ -0,0 +1,694 @@
1
+ "use strict";
2
+ // Copyright (c) 2026 Erik Fortune
3
+ //
4
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ // of this software and associated documentation files (the "Software"), to deal
6
+ // in the Software without restriction, including without limitation the rights
7
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ // copies of the Software, and to permit persons to whom the Software is
9
+ // furnished to do so, subject to the following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included in all
12
+ // copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ // SOFTWARE.
21
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
22
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
23
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
24
+ var m = o[Symbol.asyncIterator], i;
25
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
26
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
27
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
28
+ };
29
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
30
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
31
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
32
+ return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
33
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
34
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
35
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
36
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
37
+ function fulfill(value) { resume("next", value); }
38
+ function reject(value) { resume("throw", value); }
39
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.buildAnthropicContinuation = buildAnthropicContinuation;
43
+ exports.buildOpenAiContinuation = buildOpenAiContinuation;
44
+ exports.buildGeminiContinuation = buildGeminiContinuation;
45
+ exports.hasGeminiToolConflict = hasGeminiToolConflict;
46
+ exports.executeClientToolTurn = executeClientToolTurn;
47
+ /**
48
+ * Per-provider continuation message builders and the `executeClientToolTurn`
49
+ * helper for orchestrating a single client-tool round-trip.
50
+ *
51
+ * Each provider requires a different wire format for the follow-up request:
52
+ * - **Anthropic**: assistant turn reconstructed from the ordered accumulation
53
+ * buffer (thinking / redacted_thinking / text / tool_use in original stream
54
+ * order) + user turn with `tool_result` blocks. When thinking is active, the
55
+ * follow-up request must NOT set `tool_choice: { type: 'any' }` or
56
+ * `tool_choice: { type: 'tool', ... }` (E3 / §5.4 of b4-spike-findings).
57
+ * - **OpenAI / xAI Responses API**: `function_call` input items +
58
+ * `function_call_output` input items.
59
+ * - **Gemini**: model turn with `functionCall` parts + user turn with
60
+ * `functionResponse` parts (correlation by tool name).
61
+ *
62
+ * @packageDocumentation
63
+ */
64
+ const ts_utils_1 = require("@fgv/ts-utils");
65
+ const model_1 = require("../model");
66
+ const chatRequestBuilders_1 = require("../chatRequestBuilders");
67
+ const endpoint_1 = require("../endpoint");
68
+ const anthropic_1 = require("./anthropic");
69
+ const openaiResponses_1 = require("./openaiResponses");
70
+ const gemini_1 = require("./gemini");
71
+ // ============================================================================
72
+ // Anthropic continuation builder
73
+ // ============================================================================
74
+ /**
75
+ * Returns `true` when `id` is a usable correlation id — present and non-empty.
76
+ *
77
+ * `??` is NOT sufficient for this check: an empty string is a *bad* id (a
78
+ * `tool_use_id: ''` is rejected by Anthropic as a "malformed identifier") but
79
+ * `'' ?? fallback` yields `''`, silently passing the empty id through. Every id
80
+ * correlation in this module must use this predicate, never `??`.
81
+ *
82
+ * @internal
83
+ */
84
+ function isUsableId(id) {
85
+ return id !== undefined && id.length > 0;
86
+ }
87
+ /**
88
+ * Builds the Anthropic follow-up messages for a client-tool round-trip.
89
+ *
90
+ * Reconstructs the assistant turn from the ordered accumulation buffer
91
+ * (all block types in original stream order) and appends a user turn
92
+ * with `tool_result` blocks for each executed tool call.
93
+ *
94
+ * **Single source of truth for the id (id-correlation fix).** Each
95
+ * `tool_result.tool_use_id` is drawn from — and validated against — the set of
96
+ * assistant `tool_use.id`s actually present in the accumulation buffer. The id
97
+ * is NEVER derived from the tool name: a tool name can never match a `toolu_*`
98
+ * id, so a name fallback produces exactly the "malformed identifier" the
99
+ * provider rejects. If any tool result cannot be correlated to a buffered
100
+ * `tool_use` block with a non-empty id, the build fails loud (naming the tool)
101
+ * rather than emitting a malformed continuation.
102
+ *
103
+ * **Constraint (E3):** The returned continuation does NOT include a forced
104
+ * `tool_choice` field. When thinking is active, Anthropic rejects
105
+ * `tool_choice: { type: 'any' }` and `tool_choice: { type: 'tool', ... }`
106
+ * with an HTTP 400 error. Only `tool_choice: { type: 'auto' }` (the default,
107
+ * i.e. omitted) is compatible with extended thinking.
108
+ *
109
+ * @internal
110
+ */
111
+ function buildAnthropicContinuation(accBuffer, toolResults, logger) {
112
+ // Reconstruct the assistant turn from the ordered accumulation buffer.
113
+ // Sort by buffer key (SSE index) to restore original stream order.
114
+ const sortedKeys = Array.from(accBuffer.keys()).sort((a, b) => a - b);
115
+ const assistantContent = [];
116
+ // The set of assistant tool_use ids — the single source of truth every
117
+ // tool_result.tool_use_id must be drawn from.
118
+ const bufferedToolUseIds = new Set();
119
+ for (const key of sortedKeys) {
120
+ const block = accBuffer.get(key);
121
+ /* c8 ignore next 1 - defensive: key always exists in map since we iterate its keys */
122
+ if (!block)
123
+ continue;
124
+ if (block.type === 'thinking') {
125
+ assistantContent.push({
126
+ type: 'thinking',
127
+ thinking: block.thinking,
128
+ signature: block.signature
129
+ });
130
+ }
131
+ else if (block.type === 'redacted_thinking') {
132
+ assistantContent.push({
133
+ type: 'redacted_thinking',
134
+ data: block.data
135
+ });
136
+ }
137
+ else if (block.type === 'text') {
138
+ if (block.text.length > 0) {
139
+ assistantContent.push({ type: 'text', text: block.text });
140
+ }
141
+ }
142
+ else if (block.type === 'tool_use') {
143
+ // A buffered tool_use with an empty id can never be referenced by a valid
144
+ // tool_result; emitting it would corrupt the assistant turn. Fail loud.
145
+ if (!isUsableId(block.id)) {
146
+ return (0, ts_utils_1.fail)(`Anthropic continuation: buffered tool_use block for tool '${block.name}' has an empty id; ` +
147
+ `cannot build a valid continuation`);
148
+ }
149
+ let parsedInput;
150
+ try {
151
+ /* c8 ignore next 1 - defensive: argsBuffer is JSON-parsed in the adapter before emitting client-tool-call-done */
152
+ parsedInput = JSON.parse(block.argsBuffer || '{}');
153
+ /* c8 ignore start - defensive: malformed argsBuffer defaults to empty object */
154
+ }
155
+ catch (_a) {
156
+ parsedInput = {};
157
+ }
158
+ /* c8 ignore stop */
159
+ bufferedToolUseIds.add(block.id);
160
+ assistantContent.push({
161
+ type: 'tool_use',
162
+ id: block.id,
163
+ name: block.name,
164
+ input: parsedInput
165
+ });
166
+ }
167
+ }
168
+ // Build user turn with tool_result blocks for each tool call. Correlate each
169
+ // result to a buffered tool_use id — the SAME id that keys the assistant
170
+ // tool_use block — and fail loud on a missing / empty / mismatched id. A
171
+ // missing callId is a bug to surface, not paper over with a name fallback.
172
+ const userContent = [];
173
+ for (const r of toolResults) {
174
+ if (!isUsableId(r.callId)) {
175
+ return (0, ts_utils_1.fail)(`Anthropic continuation: tool '${r.toolName}' result has no call id (missing or empty); ` +
176
+ `cannot correlate it to an assistant tool_use block`);
177
+ }
178
+ if (!bufferedToolUseIds.has(r.callId)) {
179
+ return (0, ts_utils_1.fail)(`Anthropic continuation: tool '${r.toolName}' call id '${r.callId}' does not match any ` +
180
+ `buffered assistant tool_use block id`);
181
+ }
182
+ const block = {
183
+ type: 'tool_result',
184
+ // eslint-disable-next-line @typescript-eslint/naming-convention
185
+ tool_use_id: r.callId,
186
+ content: r.result
187
+ };
188
+ userContent.push(r.isError ? Object.assign(Object.assign({}, block), { is_error: true }) : block);
189
+ }
190
+ // Decisive diagnostic: the tool_use.id ↔ tool_result.tool_use_id pairing for
191
+ // the outgoing continuation. A failing turn is field-confirmable by capturing
192
+ // this line (the pairing is by construction matched here — divergence fails
193
+ // loud above, before reaching this point).
194
+ if (logger) {
195
+ const pairing = toolResults.map((r) => `${r.toolName}:${r.callId}`).join(', ');
196
+ logger.detail(`ai-assist:anthropic-continuation tool_use.id↔tool_result.tool_use_id [${pairing}]`);
197
+ }
198
+ const assistantMessage = {
199
+ role: 'assistant',
200
+ content: assistantContent
201
+ };
202
+ const userMessage = {
203
+ role: 'user',
204
+ content: userContent
205
+ };
206
+ return (0, ts_utils_1.succeed)({
207
+ messages: [assistantMessage, userMessage],
208
+ toolCallsSummary: toolResults.map((r) => ({
209
+ toolName: r.toolName,
210
+ callId: r.callId,
211
+ args: r.args,
212
+ result: r.result,
213
+ isError: r.isError
214
+ }))
215
+ });
216
+ }
217
+ // ============================================================================
218
+ // OpenAI / xAI Responses API continuation builder
219
+ // ============================================================================
220
+ /**
221
+ * Builds the OpenAI / xAI Responses API follow-up input items for a
222
+ * client-tool round-trip.
223
+ *
224
+ * Emits `function_call` items (the model's call) followed by
225
+ * `function_call_output` items (the harness execution result), one pair
226
+ * per executed tool call.
227
+ *
228
+ * **Single source of truth for the id (id-correlation fix).** Each
229
+ * `function_call_output.call_id` is drawn from — and validated against — the
230
+ * set of `function_call.call_id`s in the accumulation map. It is NEVER derived
231
+ * from the tool name (the OpenAI parity of the Anthropic `tool_use_id` fix). A
232
+ * missing / empty / unmatched call id fails the build loud rather than emitting
233
+ * a continuation the provider would reject.
234
+ *
235
+ * @internal
236
+ */
237
+ function buildOpenAiContinuation(calls, toolResults, logger) {
238
+ const items = [];
239
+ // Emit function_call items for each call (model's side). Per the Responses API spec
240
+ // (ResponseFunctionToolCall), `call_id` is the required correlation field — it must
241
+ // match the matching function_call_output's `call_id` below. The optional `id` field
242
+ // is the output-item id (`fc_*`) used to reference the streamed item; we omit it
243
+ // because it is not load-bearing for input items.
244
+ const bufferedCallIds = new Set();
245
+ for (const [callId, call] of calls) {
246
+ bufferedCallIds.add(callId);
247
+ items.push({
248
+ type: 'function_call',
249
+ call_id: callId,
250
+ name: call.name,
251
+ arguments: call.argsBuffer
252
+ });
253
+ }
254
+ // Emit function_call_output items (harness execution results). Correlate each
255
+ // to a buffered function_call call_id — never the tool name — and fail loud on
256
+ // a missing / empty / mismatched id.
257
+ for (const r of toolResults) {
258
+ if (!isUsableId(r.callId)) {
259
+ return (0, ts_utils_1.fail)(`OpenAI continuation: tool '${r.toolName}' result has no call id (missing or empty); ` +
260
+ `cannot correlate it to a function_call item`);
261
+ }
262
+ if (!bufferedCallIds.has(r.callId)) {
263
+ return (0, ts_utils_1.fail)(`OpenAI continuation: tool '${r.toolName}' call id '${r.callId}' does not match any ` +
264
+ `accumulated function_call call_id`);
265
+ }
266
+ items.push({
267
+ type: 'function_call_output',
268
+ call_id: r.callId,
269
+ output: r.result
270
+ });
271
+ }
272
+ // Decisive diagnostic: the function_call.call_id ↔ function_call_output.call_id
273
+ // pairing for the outgoing continuation (matched by construction here).
274
+ if (logger) {
275
+ const pairing = toolResults.map((r) => `${r.toolName}:${r.callId}`).join(', ');
276
+ logger.detail(`ai-assist:openai-continuation function_call.call_id↔output.call_id [${pairing}]`);
277
+ }
278
+ return (0, ts_utils_1.succeed)({
279
+ messages: items,
280
+ toolCallsSummary: toolResults.map((r) => ({
281
+ toolName: r.toolName,
282
+ callId: r.callId,
283
+ args: r.args,
284
+ result: r.result,
285
+ isError: r.isError
286
+ }))
287
+ });
288
+ }
289
+ // ============================================================================
290
+ // Gemini continuation builder
291
+ // ============================================================================
292
+ /**
293
+ * Builds the Gemini follow-up contents for a client-tool round-trip.
294
+ *
295
+ * Emits a model turn with `functionCall` parts (one per tool call) and a
296
+ * user turn with `functionResponse` parts (correlation by tool name, since
297
+ * Gemini does not assign call IDs).
298
+ *
299
+ * When thinking is enabled, Gemini stamps an opaque `thoughtSignature` on each
300
+ * `functionCall` part and requires it echoed back, verbatim, as a sibling of
301
+ * `functionCall` on the continuation's model turn — otherwise the follow-up is
302
+ * rejected with "Function call is missing a thought_signature in functionCall
303
+ * parts". The captured signature (see {@link IAccumulatedGeminiFunctionCall})
304
+ * is replayed here only when present; the key is omitted entirely when thinking
305
+ * was disabled. See https://ai.google.dev/gemini-api/docs/thought-signatures.
306
+ *
307
+ * @internal
308
+ */
309
+ function buildGeminiContinuation(calls, toolResults) {
310
+ // Model turn: functionCall parts for each call. Replay the part-level
311
+ // thoughtSignature as a sibling of functionCall only when present.
312
+ const modelParts = calls.map((call) => (Object.assign({ functionCall: {
313
+ name: call.name,
314
+ args: call.args
315
+ } }, (call.thoughtSignature !== undefined ? { thoughtSignature: call.thoughtSignature } : {}))));
316
+ // User turn: functionResponse parts for each executed result.
317
+ // Correlation is by name since Gemini has no call IDs.
318
+ const userParts = toolResults.map((r) => ({
319
+ functionResponse: {
320
+ name: r.toolName,
321
+ response: Object.assign({ content: r.result }, (r.isError ? { error: true } : {}))
322
+ }
323
+ }));
324
+ const modelMessage = {
325
+ role: 'model',
326
+ parts: modelParts
327
+ };
328
+ const userMessage = {
329
+ role: 'user',
330
+ parts: userParts
331
+ };
332
+ return {
333
+ messages: [modelMessage, userMessage],
334
+ toolCallsSummary: toolResults.map((r) => ({
335
+ toolName: r.toolName,
336
+ callId: r.callId,
337
+ args: r.args,
338
+ result: r.result,
339
+ isError: r.isError
340
+ }))
341
+ };
342
+ }
343
+ // ============================================================================
344
+ // executeClientToolTurn
345
+ // ============================================================================
346
+ /**
347
+ * True when a request would combine Gemini built-in grounding (a `web_search`
348
+ * server tool) with client (function) tools — a combination Gemini's
349
+ * `generateContent` API rejects with HTTP 400 (`INVALID_ARGUMENT`). Callers gate
350
+ * on `descriptor.apiFormat === 'gemini'` before consulting this; other providers
351
+ * accept the mix. Kept as a pure predicate so the conflict rule is unit-testable
352
+ * without a live stream.
353
+ *
354
+ * @internal
355
+ */
356
+ function hasGeminiToolConflict(tools, clientTools) {
357
+ var _a;
358
+ return clientTools.length > 0 && ((_a = tools === null || tools === void 0 ? void 0 : tools.some((t) => t.type === 'web_search')) !== null && _a !== void 0 ? _a : false);
359
+ }
360
+ /**
361
+ * Orchestrates a single client-tool streaming turn for any supported provider.
362
+ *
363
+ * Starts a streaming request, iterates the underlying provider stream, and:
364
+ * - Forwards `text-delta`, `tool-event`, `client-tool-call-start`, and
365
+ * `client-tool-call-done` events through to the consumer.
366
+ * - For each `client-tool-call-done` event: validates the raw args against the
367
+ * tool's `parametersSchema`, invokes `execute(typedArgs)`, and emits a
368
+ * `client-tool-result` event.
369
+ * - After stream completion: builds the per-provider continuation (or
370
+ * `{ continuation: undefined }` when no tool calls occurred) and resolves
371
+ * `nextTurn`.
372
+ *
373
+ * **Anthropic constraint (E3):** The continuation for Anthropic does not set
374
+ * a forced `tool_choice`. Only `tool_choice: 'auto'` (the default, i.e.
375
+ * omitted) is compatible with extended thinking.
376
+ *
377
+ * @param params - Turn parameters
378
+ * @returns `{ events, nextTurn }` — stream iterable + completion promise
379
+ * @public
380
+ */
381
+ function executeClientToolTurn(params) {
382
+ const { descriptor, apiKey, system, messages, continuationMessages, temperature, tools, clientTools, signal, logger, resolvedThinking, model, endpoint, onBeforeToolExecute } = params;
383
+ const splitResult = (0, chatRequestBuilders_1.splitChatRequest)(system, messages);
384
+ if (splitResult.isFailure()) {
385
+ return (0, ts_utils_1.fail)(splitResult.message);
386
+ }
387
+ const { prompt, head } = splitResult.value;
388
+ if (prompt.attachments.length > 0 && !descriptor.acceptsImageInput) {
389
+ return (0, ts_utils_1.fail)(`provider "${descriptor.id}" does not accept image input`);
390
+ }
391
+ // Build a lookup map of client tools by name for fast access.
392
+ // Fail fast on duplicate names — silently overwriting would cause one tool
393
+ // to shadow another with no observable signal.
394
+ const toolsByName = new Map();
395
+ for (const tool of clientTools) {
396
+ if (toolsByName.has(tool.config.name)) {
397
+ return (0, ts_utils_1.fail)(`executeClientToolTurn: duplicate client tool name '${tool.config.name}'`);
398
+ }
399
+ toolsByName.set(tool.config.name, tool);
400
+ }
401
+ // Merge server tools and client tool configs into a single array for the provider.
402
+ // This is the fix for P1-1: client tools were never sent to the provider because
403
+ // the adapters only received `tools` (server tools). Both must coexist per design §2.5.
404
+ const effectiveTools = clientTools.length > 0 ? [...(tools !== null && tools !== void 0 ? tools : []), ...clientTools.map((t) => t.config)] : tools;
405
+ // Gemini pre-flight: its generateContent API HTTP-400s (INVALID_ARGUMENT) when
406
+ // built-in grounding (`web_search`) and function calling (client tools) are
407
+ // combined in one request. Fail fast with a clear, actionable message rather
408
+ // than letting the opaque wire 400 surface. Other providers accept the mix.
409
+ if (descriptor.apiFormat === 'gemini' && hasGeminiToolConflict(tools, clientTools)) {
410
+ return (0, ts_utils_1.fail)('executeClientToolTurn: Gemini cannot combine web_search grounding with client (function) tools in the same request; send one or the other');
411
+ }
412
+ const modelResult = (0, model_1.resolveProviderModel)(descriptor, model);
413
+ if (modelResult.isFailure()) {
414
+ return (0, ts_utils_1.fail)(modelResult.message);
415
+ }
416
+ const resolvedModel = modelResult.value;
417
+ const baseUrlResult = (0, endpoint_1.resolveEffectiveBaseUrl)(descriptor, endpoint);
418
+ if (baseUrlResult.isFailure()) {
419
+ return (0, ts_utils_1.fail)(baseUrlResult.message);
420
+ }
421
+ const config = {
422
+ baseUrl: baseUrlResult.value,
423
+ apiKey,
424
+ model: resolvedModel
425
+ };
426
+ // Accumulation buffers — populated by the adapter, read by the builder.
427
+ const anthropicBuffer = new Map();
428
+ const openAiCallMap = new Map();
429
+ const geminiCalls = [];
430
+ // Collected tool results, populated as each client-tool-call-done is processed.
431
+ const toolResults = [];
432
+ // Stream start: open the underlying adapter stream.
433
+ const streamPromise = (() => {
434
+ switch (descriptor.apiFormat) {
435
+ case 'anthropic':
436
+ return (0, anthropic_1.callAnthropicStream)(config, prompt, head, temperature, effectiveTools, logger, signal, resolvedThinking, anthropicBuffer, continuationMessages);
437
+ case 'openai':
438
+ return (0, openaiResponses_1.callOpenAiResponsesStream)(config, prompt,
439
+ /* c8 ignore next 1 - defensive: openai path requires tools; empty array fallback unreachable in practice */
440
+ effectiveTools !== null && effectiveTools !== void 0 ? effectiveTools : [], head, temperature, logger, signal, resolvedThinking, openAiCallMap, continuationMessages);
441
+ case 'gemini':
442
+ return (0, gemini_1.callGeminiStream)(config, prompt, head, temperature, effectiveTools, logger, signal, resolvedThinking, geminiCalls, continuationMessages);
443
+ /* c8 ignore next 4 - defensive coding: exhaustive switch guaranteed by TypeScript */
444
+ default: {
445
+ const _exhaustive = descriptor.apiFormat;
446
+ return Promise.resolve((0, ts_utils_1.fail)(`unsupported API format: ${String(_exhaustive)}`));
447
+ }
448
+ }
449
+ })();
450
+ // Resolve controls for `nextTurn`.
451
+ let resolveNextTurn;
452
+ const nextTurn = new Promise((resolve) => {
453
+ resolveNextTurn = resolve;
454
+ });
455
+ // The unified-event generator: opens the stream, proxies events, executes tools.
456
+ function eventGenerator() {
457
+ return __asyncGenerator(this, arguments, function* eventGenerator_1() {
458
+ var _a, e_1, _b, _c;
459
+ const streamResult = yield __await(streamPromise);
460
+ if (streamResult.isFailure()) {
461
+ resolveNextTurn((0, ts_utils_1.fail)(streamResult.message));
462
+ yield yield __await({ type: 'error', message: streamResult.message });
463
+ return yield __await(void 0);
464
+ }
465
+ let truncated = false;
466
+ let fullText = '';
467
+ let streamError;
468
+ try {
469
+ for (var _d = true, _e = __asyncValues(streamResult.value), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
470
+ _c = _f.value;
471
+ _d = false;
472
+ const event = _c;
473
+ if (event.type === 'done') {
474
+ truncated = event.truncated;
475
+ fullText = event.fullText;
476
+ yield yield __await(event);
477
+ continue;
478
+ }
479
+ if (event.type === 'error') {
480
+ streamError = event.message;
481
+ yield yield __await(event);
482
+ continue;
483
+ }
484
+ if (event.type === 'text-delta') {
485
+ yield yield __await(event);
486
+ continue;
487
+ }
488
+ if (event.type === 'tool-event') {
489
+ yield yield __await(event);
490
+ continue;
491
+ }
492
+ if (event.type === 'client-tool-call-start') {
493
+ yield yield __await(event);
494
+ continue;
495
+ }
496
+ if (event.type === 'client-tool-call-done') {
497
+ yield yield __await(event);
498
+ const { toolName, callId, args } = event;
499
+ const tool = toolsByName.get(toolName);
500
+ if (!tool) {
501
+ const errMsg = `model called unknown tool: ${toolName}`;
502
+ const resultEvent = {
503
+ type: 'client-tool-result',
504
+ toolName,
505
+ callId,
506
+ result: errMsg,
507
+ isError: true
508
+ };
509
+ yield yield __await(resultEvent);
510
+ toolResults.push({ toolName, callId, args, result: errMsg, isError: true });
511
+ resolveNextTurn((0, ts_utils_1.fail)(errMsg));
512
+ return yield __await(void 0);
513
+ }
514
+ const validationResult = tool.config.parametersSchema.validate(args);
515
+ if (validationResult.isFailure()) {
516
+ const errMsg = `${toolName} (callId=${callId}): ${validationResult.message}`;
517
+ const resultEvent = {
518
+ type: 'client-tool-result',
519
+ toolName,
520
+ callId,
521
+ result: errMsg,
522
+ isError: true
523
+ };
524
+ yield yield __await(resultEvent);
525
+ toolResults.push({ toolName, callId, args, result: errMsg, isError: true });
526
+ continue;
527
+ }
528
+ // Host gate: run after arg-validation, before execute. A `deny` decision
529
+ // synthesizes a denial tool-result and continues the turn; a `fail`/reject
530
+ // from the gate itself is a hard error (mirrors an execute failure), never
531
+ // a silent deny.
532
+ if (onBeforeToolExecute !== undefined) {
533
+ const decisionResult = (yield __await((0, ts_utils_1.captureAsyncResult)(async () => onBeforeToolExecute(tool, validationResult.value)))).onSuccess((decision) => decision);
534
+ if (decisionResult.isFailure()) {
535
+ const errMsg = `${toolName} (callId=${callId}): ${decisionResult.message}`;
536
+ const resultEvent = {
537
+ type: 'client-tool-result',
538
+ toolName,
539
+ callId,
540
+ result: errMsg,
541
+ isError: true
542
+ };
543
+ yield yield __await(resultEvent);
544
+ // Gate-fail is a hard, turn-terminating error (unlike a non-fatal `deny`, whose
545
+ // generator continues). Emit an explicit `error` event so a consumer watching only
546
+ // `events` sees the fatal failure inline and can distinguish it from a deny — matching
547
+ // the stream-open / continuation hard-error paths.
548
+ yield yield __await({ type: 'error', message: errMsg });
549
+ toolResults.push({ toolName, callId, args, result: errMsg, isError: true });
550
+ resolveNextTurn((0, ts_utils_1.fail)(errMsg));
551
+ return yield __await(void 0);
552
+ }
553
+ if (decisionResult.value.action === 'deny') {
554
+ const denialMsg = `${toolName} (callId=${callId}): tool execution denied: ${decisionResult.value.reason}`;
555
+ const resultEvent = {
556
+ type: 'client-tool-result',
557
+ toolName,
558
+ callId,
559
+ result: denialMsg,
560
+ isError: true
561
+ };
562
+ yield yield __await(resultEvent);
563
+ toolResults.push({ toolName, callId, args, result: denialMsg, isError: true });
564
+ continue;
565
+ }
566
+ }
567
+ const executeResult = yield __await((0, ts_utils_1.captureAsyncResult)(async () => tool.execute(validationResult.value)));
568
+ const executionResult = executeResult.isSuccess()
569
+ ? executeResult.value
570
+ : executeResult;
571
+ if (executionResult.isFailure()) {
572
+ const errMsg = `${toolName} (callId=${callId}): ${executionResult.message}`;
573
+ const resultEvent = {
574
+ type: 'client-tool-result',
575
+ toolName,
576
+ callId,
577
+ result: errMsg,
578
+ isError: true
579
+ };
580
+ yield yield __await(resultEvent);
581
+ toolResults.push({ toolName, callId, args, result: errMsg, isError: true });
582
+ continue;
583
+ }
584
+ // JSON.stringify can throw (circular references) or return undefined
585
+ // (e.g. for a bare `undefined` value, or a value of type `function`).
586
+ // Either outcome violates the client-tool-result event contract, so
587
+ // emit an isError result with diagnostic context instead.
588
+ let resultStr;
589
+ try {
590
+ const stringified = JSON.stringify(executionResult.value);
591
+ if (stringified === undefined) {
592
+ const errMsg = `${toolName} (callId=${callId}): tool returned a non-serializable value (JSON.stringify produced undefined)`;
593
+ const resultEvent = {
594
+ type: 'client-tool-result',
595
+ toolName,
596
+ callId,
597
+ result: errMsg,
598
+ isError: true
599
+ };
600
+ yield yield __await(resultEvent);
601
+ toolResults.push({ toolName, callId, args, result: errMsg, isError: true });
602
+ continue;
603
+ }
604
+ resultStr = stringified;
605
+ }
606
+ catch (e) {
607
+ const errMsg = `${toolName} (callId=${callId}): failed to serialize tool result: ${e.message}`;
608
+ const resultEvent = {
609
+ type: 'client-tool-result',
610
+ toolName,
611
+ callId,
612
+ result: errMsg,
613
+ isError: true
614
+ };
615
+ yield yield __await(resultEvent);
616
+ toolResults.push({ toolName, callId, args, result: errMsg, isError: true });
617
+ continue;
618
+ }
619
+ const resultEvent = {
620
+ type: 'client-tool-result',
621
+ toolName,
622
+ callId,
623
+ result: resultStr,
624
+ isError: false
625
+ };
626
+ yield yield __await(resultEvent);
627
+ toolResults.push({ toolName, callId, args, result: resultStr, isError: false });
628
+ continue;
629
+ }
630
+ }
631
+ }
632
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
633
+ finally {
634
+ try {
635
+ if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
636
+ }
637
+ finally { if (e_1) throw e_1.error; }
638
+ }
639
+ // Stream has ended. Build the continuation.
640
+ if (streamError !== undefined) {
641
+ resolveNextTurn((0, ts_utils_1.fail)(streamError));
642
+ return yield __await(void 0);
643
+ }
644
+ if (toolResults.length === 0) {
645
+ resolveNextTurn((0, ts_utils_1.succeed)({ continuation: undefined, truncated, fullText }));
646
+ return yield __await(void 0);
647
+ }
648
+ let continuationResult;
649
+ switch (descriptor.apiFormat) {
650
+ case 'anthropic':
651
+ continuationResult = buildAnthropicContinuation(anthropicBuffer, toolResults, logger);
652
+ break;
653
+ case 'openai':
654
+ continuationResult = buildOpenAiContinuation(openAiCallMap, toolResults, logger);
655
+ break;
656
+ case 'gemini':
657
+ // Gemini correlates by tool name by design (no call ids) — its builder
658
+ // cannot mis-key and stays non-fallible.
659
+ continuationResult = (0, ts_utils_1.succeed)(buildGeminiContinuation(geminiCalls, toolResults));
660
+ break;
661
+ /* c8 ignore next 5 - defensive coding: exhaustive switch guaranteed by TypeScript */
662
+ default: {
663
+ const _exhaustive = descriptor.apiFormat;
664
+ resolveNextTurn((0, ts_utils_1.fail)(`unsupported API format: ${String(_exhaustive)}`));
665
+ return yield __await(void 0);
666
+ }
667
+ }
668
+ // A bad id-correlation fails loud here rather than emitting a malformed
669
+ // continuation the provider would reject as a "malformed identifier". Mirror
670
+ // the stream-open-failure path above: surface an `error` event so a consumer
671
+ // iterating `events` sees the failure inline, not only via `nextTurn`.
672
+ if (continuationResult.isFailure()) {
673
+ resolveNextTurn((0, ts_utils_1.fail)(continuationResult.message));
674
+ yield yield __await({ type: 'error', message: continuationResult.message });
675
+ return yield __await(void 0);
676
+ }
677
+ let continuation = continuationResult.value;
678
+ // Prepend inbound continuationMessages so the returned continuation is cumulative.
679
+ // A consumer that does `tail = outcome.continuation.messages` (replace) is then
680
+ // correct for all N rounds — messages always contains the full wire tail from
681
+ // round 1 through the current round. toolCallsSummary stays per-round (this
682
+ // round's calls only); messages is the accumulated tail to re-send.
683
+ if (continuationMessages && continuationMessages.length > 0) {
684
+ continuation = Object.assign(Object.assign({}, continuation), { messages: [...continuationMessages, ...continuation.messages] });
685
+ }
686
+ resolveNextTurn((0, ts_utils_1.succeed)({ continuation, truncated, fullText }));
687
+ });
688
+ }
689
+ return (0, ts_utils_1.succeed)({
690
+ events: { [Symbol.asyncIterator]: () => eventGenerator() },
691
+ nextTurn
692
+ });
693
+ }
694
+ //# sourceMappingURL=clientToolContinuationBuilder.js.map