@mastra/server 0.0.0-support-d1-client-20250701191943 → 0.0.0-suspendRuntimeContextTypeFix-20250930142630

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 (326) hide show
  1. package/CHANGELOG.md +3812 -0
  2. package/LICENSE.md +11 -42
  3. package/README.md +0 -5
  4. package/dist/{chunk-H5PTF3Y4.js → chunk-4QCXUEAT.js} +11 -2
  5. package/dist/chunk-4QCXUEAT.js.map +1 -0
  6. package/dist/chunk-4RRMWXQ2.js +3522 -0
  7. package/dist/chunk-4RRMWXQ2.js.map +1 -0
  8. package/dist/chunk-52UP7DFT.cjs +130 -0
  9. package/dist/chunk-52UP7DFT.cjs.map +1 -0
  10. package/dist/chunk-5DP5XZH6.cjs +928 -0
  11. package/dist/chunk-5DP5XZH6.cjs.map +1 -0
  12. package/dist/chunk-66YYHFGF.js +761 -0
  13. package/dist/chunk-66YYHFGF.js.map +1 -0
  14. package/dist/chunk-6GMFZ5LK.js +2774 -0
  15. package/dist/chunk-6GMFZ5LK.js.map +1 -0
  16. package/dist/{chunk-GHC4YV6R.js → chunk-6IJWRJZE.js} +109 -136
  17. package/dist/chunk-6IJWRJZE.js.map +1 -0
  18. package/dist/chunk-743UIDHI.cjs +2013 -0
  19. package/dist/chunk-743UIDHI.cjs.map +1 -0
  20. package/dist/chunk-7ESQBAXS.cjs +18023 -0
  21. package/dist/chunk-7ESQBAXS.cjs.map +1 -0
  22. package/dist/{chunk-OCWPVYNI.cjs → chunk-7NADHFD2.cjs} +3 -0
  23. package/dist/chunk-7NADHFD2.cjs.map +1 -0
  24. package/dist/{chunk-BOXE6WSV.js → chunk-A3AL7EWJ.js} +5 -3
  25. package/dist/chunk-A3AL7EWJ.js.map +1 -0
  26. package/dist/chunk-AK2FXLLB.cjs +849 -0
  27. package/dist/chunk-AK2FXLLB.cjs.map +1 -0
  28. package/dist/chunk-BKCWZLEL.cjs +197 -0
  29. package/dist/chunk-BKCWZLEL.cjs.map +1 -0
  30. package/dist/chunk-BOVFMBXY.js +607 -0
  31. package/dist/chunk-BOVFMBXY.js.map +1 -0
  32. package/dist/{chunk-QDOJJCS4.js → chunk-CY4TP3FK.js} +6 -2
  33. package/dist/chunk-CY4TP3FK.js.map +1 -0
  34. package/dist/chunk-EMMSS5I5.cjs +37 -0
  35. package/dist/chunk-EMMSS5I5.cjs.map +1 -0
  36. package/dist/chunk-EMNGA4R4.js +845 -0
  37. package/dist/chunk-EMNGA4R4.js.map +1 -0
  38. package/dist/chunk-FALVL2VV.cjs +3525 -0
  39. package/dist/chunk-FALVL2VV.cjs.map +1 -0
  40. package/dist/chunk-FQNT7PI4.js +937 -0
  41. package/dist/chunk-FQNT7PI4.js.map +1 -0
  42. package/dist/chunk-G3PMV62Z.js +33 -0
  43. package/dist/chunk-G3PMV62Z.js.map +1 -0
  44. package/dist/chunk-G4PUALCE.cjs +28 -0
  45. package/dist/chunk-G4PUALCE.cjs.map +1 -0
  46. package/dist/chunk-GU4EWMZB.cjs +769 -0
  47. package/dist/chunk-GU4EWMZB.cjs.map +1 -0
  48. package/dist/chunk-HJQKWRKQ.cjs +764 -0
  49. package/dist/chunk-HJQKWRKQ.cjs.map +1 -0
  50. package/dist/{chunk-LI436ITD.cjs → chunk-HVBBFCDH.cjs} +1041 -762
  51. package/dist/chunk-HVBBFCDH.cjs.map +1 -0
  52. package/dist/chunk-HZJRQ5L3.cjs +1411 -0
  53. package/dist/chunk-HZJRQ5L3.cjs.map +1 -0
  54. package/dist/chunk-IGFMAZZ5.cjs +1150 -0
  55. package/dist/chunk-IGFMAZZ5.cjs.map +1 -0
  56. package/dist/chunk-IOQGI4ML.js +931 -0
  57. package/dist/chunk-IOQGI4ML.js.map +1 -0
  58. package/dist/chunk-JQ74G5IO.js +17987 -0
  59. package/dist/chunk-JQ74G5IO.js.map +1 -0
  60. package/dist/{chunk-G37NVEDX.js → chunk-JRDEOHAJ.js} +23 -13
  61. package/dist/chunk-JRDEOHAJ.js.map +1 -0
  62. package/dist/chunk-JSMP6GVP.cjs +595 -0
  63. package/dist/chunk-JSMP6GVP.cjs.map +1 -0
  64. package/dist/{chunk-DFJUGWNU.js → chunk-KM7EJKXV.js} +50 -12
  65. package/dist/chunk-KM7EJKXV.js.map +1 -0
  66. package/dist/{chunk-TGZIR6AK.cjs → chunk-KNGXRN26.cjs} +48 -45
  67. package/dist/chunk-KNGXRN26.cjs.map +1 -0
  68. package/dist/{chunk-BP24Z4WG.js → chunk-KV6VHX4V.js} +24 -5
  69. package/dist/chunk-KV6VHX4V.js.map +1 -0
  70. package/dist/chunk-LF2ZLOFP.js +767 -0
  71. package/dist/chunk-LF2ZLOFP.js.map +1 -0
  72. package/dist/chunk-LJFAAEU7.cjs +167 -0
  73. package/dist/chunk-LJFAAEU7.cjs.map +1 -0
  74. package/dist/chunk-LYPU75T6.js +1147 -0
  75. package/dist/chunk-LYPU75T6.js.map +1 -0
  76. package/dist/{chunk-NYN7KFXL.js → chunk-MMROOK5J.js} +3 -0
  77. package/dist/chunk-MMROOK5J.js.map +1 -0
  78. package/dist/{chunk-MEGCYGBU.js → chunk-N7F33WAD.js} +1013 -762
  79. package/dist/chunk-N7F33WAD.js.map +1 -0
  80. package/dist/chunk-NG5IVLEZ.js +1012 -0
  81. package/dist/chunk-NG5IVLEZ.js.map +1 -0
  82. package/dist/chunk-NLWACBE7.cjs +128 -0
  83. package/dist/chunk-NLWACBE7.cjs.map +1 -0
  84. package/dist/chunk-OGW6HHVI.js +1408 -0
  85. package/dist/chunk-OGW6HHVI.js.map +1 -0
  86. package/dist/{chunk-SDPGVWQJ.cjs → chunk-OPI3FZYH.cjs} +110 -137
  87. package/dist/chunk-OPI3FZYH.cjs.map +1 -0
  88. package/dist/chunk-OZLRIVC4.cjs +588 -0
  89. package/dist/chunk-OZLRIVC4.cjs.map +1 -0
  90. package/dist/chunk-P7CIEIJ3.js +925 -0
  91. package/dist/chunk-P7CIEIJ3.js.map +1 -0
  92. package/dist/chunk-P7RBMCBE.cjs +934 -0
  93. package/dist/chunk-P7RBMCBE.cjs.map +1 -0
  94. package/dist/chunk-PPYGWINI.cjs +2777 -0
  95. package/dist/chunk-PPYGWINI.cjs.map +1 -0
  96. package/dist/{chunk-ULFULEW4.cjs → chunk-PWTXZZTR.cjs} +28 -8
  97. package/dist/chunk-PWTXZZTR.cjs.map +1 -0
  98. package/dist/chunk-RCHEPTZZ.js +2006 -0
  99. package/dist/chunk-RCHEPTZZ.js.map +1 -0
  100. package/dist/chunk-RE4RPXT2.cjs +18 -0
  101. package/dist/chunk-RE4RPXT2.cjs.map +1 -0
  102. package/dist/chunk-SIGXR3JT.cjs +1043 -0
  103. package/dist/chunk-SIGXR3JT.cjs.map +1 -0
  104. package/dist/{chunk-CNVDCLSY.cjs → chunk-SPLSYTYW.cjs} +11 -9
  105. package/dist/chunk-SPLSYTYW.cjs.map +1 -0
  106. package/dist/chunk-SQY4T6EJ.js +571 -0
  107. package/dist/chunk-SQY4T6EJ.js.map +1 -0
  108. package/dist/chunk-SXENNNR7.cjs +625 -0
  109. package/dist/chunk-SXENNNR7.cjs.map +1 -0
  110. package/dist/{chunk-TVBPFPTN.cjs → chunk-T3TIA3O6.cjs} +20 -18
  111. package/dist/chunk-T3TIA3O6.cjs.map +1 -0
  112. package/dist/{chunk-7GQJAMTA.js → chunk-TTHEEIZ3.js} +13 -10
  113. package/dist/chunk-TTHEEIZ3.js.map +1 -0
  114. package/dist/chunk-TVSIG4JE.cjs +940 -0
  115. package/dist/chunk-TVSIG4JE.cjs.map +1 -0
  116. package/dist/chunk-VY4ENABS.cjs +135 -0
  117. package/dist/chunk-VY4ENABS.cjs.map +1 -0
  118. package/dist/{chunk-FVMGZKFD.js → chunk-WHN4VX55.js} +5 -3
  119. package/dist/chunk-WHN4VX55.js.map +1 -0
  120. package/dist/chunk-WUJLVNLU.js +124 -0
  121. package/dist/chunk-WUJLVNLU.js.map +1 -0
  122. package/dist/chunk-XJOYGRTN.js +189 -0
  123. package/dist/chunk-XJOYGRTN.js.map +1 -0
  124. package/dist/chunk-YWOK4F5A.js +131 -0
  125. package/dist/chunk-YWOK4F5A.js.map +1 -0
  126. package/dist/{chunk-Z5TH5F35.js → chunk-ZAYTLC6C.js} +188 -80
  127. package/dist/chunk-ZAYTLC6C.js.map +1 -0
  128. package/dist/dist-26HWEQY6.js +3 -0
  129. package/dist/dist-26HWEQY6.js.map +1 -0
  130. package/dist/dist-3A5DXB37.cjs +20 -0
  131. package/dist/dist-3A5DXB37.cjs.map +1 -0
  132. package/dist/dist-3SJKQJGY.cjs +16 -0
  133. package/dist/dist-3SJKQJGY.cjs.map +1 -0
  134. package/dist/dist-4ZQSPE5K.js +3 -0
  135. package/dist/dist-4ZQSPE5K.js.map +1 -0
  136. package/dist/dist-5W5QNRTD.js +3 -0
  137. package/dist/dist-5W5QNRTD.js.map +1 -0
  138. package/dist/dist-653SRMPL.js +3 -0
  139. package/dist/dist-653SRMPL.js.map +1 -0
  140. package/dist/dist-6U6EFC5C.cjs +16 -0
  141. package/dist/dist-6U6EFC5C.cjs.map +1 -0
  142. package/dist/dist-7IHNNYMF.cjs +16 -0
  143. package/dist/dist-7IHNNYMF.cjs.map +1 -0
  144. package/dist/dist-B5IPRF6W.js +3 -0
  145. package/dist/dist-B5IPRF6W.js.map +1 -0
  146. package/dist/dist-EOMYFT4Y.cjs +16 -0
  147. package/dist/dist-EOMYFT4Y.cjs.map +1 -0
  148. package/dist/dist-EZZMMMNT.cjs +16 -0
  149. package/dist/dist-EZZMMMNT.cjs.map +1 -0
  150. package/dist/dist-F2ET4MNO.cjs +16 -0
  151. package/dist/dist-F2ET4MNO.cjs.map +1 -0
  152. package/dist/dist-H64VX6DE.js +3 -0
  153. package/dist/dist-H64VX6DE.js.map +1 -0
  154. package/dist/dist-HY7RMLJQ.cjs +16 -0
  155. package/dist/dist-HY7RMLJQ.cjs.map +1 -0
  156. package/dist/dist-M6S4P3FJ.js +3 -0
  157. package/dist/dist-M6S4P3FJ.js.map +1 -0
  158. package/dist/dist-NR7QSCQT.js +3 -0
  159. package/dist/dist-NR7QSCQT.js.map +1 -0
  160. package/dist/dist-QLFMCMCX.js +3 -0
  161. package/dist/dist-QLFMCMCX.js.map +1 -0
  162. package/dist/dist-UY46BFRP.js +3 -0
  163. package/dist/dist-UY46BFRP.js.map +1 -0
  164. package/dist/dist-WCQDRTIV.cjs +16 -0
  165. package/dist/dist-WCQDRTIV.cjs.map +1 -0
  166. package/dist/dist-WKYB3LTJ.cjs +16 -0
  167. package/dist/dist-WKYB3LTJ.cjs.map +1 -0
  168. package/dist/index.cjs +6 -0
  169. package/dist/index.cjs.map +1 -0
  170. package/dist/index.d.ts +1 -0
  171. package/dist/index.d.ts.map +1 -0
  172. package/dist/index.js +5 -0
  173. package/dist/index.js.map +1 -0
  174. package/dist/server/a2a/protocol.d.ts +8 -0
  175. package/dist/server/a2a/protocol.d.ts.map +1 -0
  176. package/dist/server/a2a/store.cjs +25 -0
  177. package/dist/server/a2a/store.cjs.map +1 -0
  178. package/dist/server/a2a/store.d.ts +14 -0
  179. package/dist/server/a2a/store.d.ts.map +1 -0
  180. package/dist/server/a2a/store.js +23 -0
  181. package/dist/server/a2a/store.js.map +1 -0
  182. package/dist/server/a2a/tasks.d.ts +20 -0
  183. package/dist/server/a2a/tasks.d.ts.map +1 -0
  184. package/dist/server/handlers/a2a.cjs +13 -11
  185. package/dist/server/handlers/a2a.cjs.map +1 -0
  186. package/dist/server/handlers/a2a.d.ts +68 -6
  187. package/dist/server/handlers/a2a.d.ts.map +1 -0
  188. package/dist/server/handlers/a2a.js +3 -1
  189. package/dist/server/handlers/a2a.js.map +1 -0
  190. package/dist/server/handlers/agent-builder.cjs +68 -0
  191. package/dist/server/handlers/agent-builder.cjs.map +1 -0
  192. package/dist/server/handlers/agent-builder.d.ts +92 -0
  193. package/dist/server/handlers/agent-builder.d.ts.map +1 -0
  194. package/dist/server/handlers/agent-builder.js +3 -0
  195. package/dist/server/handlers/agent-builder.js.map +1 -0
  196. package/dist/server/handlers/agents.cjs +49 -7
  197. package/dist/server/handlers/agents.cjs.map +1 -0
  198. package/dist/server/handlers/agents.d.ts +185 -6
  199. package/dist/server/handlers/agents.d.ts.map +1 -0
  200. package/dist/server/handlers/agents.js +3 -1
  201. package/dist/server/handlers/agents.js.map +1 -0
  202. package/dist/server/handlers/error.cjs +4 -2
  203. package/dist/server/handlers/error.cjs.map +1 -0
  204. package/dist/server/handlers/error.d.ts +2 -1
  205. package/dist/server/handlers/error.d.ts.map +1 -0
  206. package/dist/server/handlers/error.js +3 -1
  207. package/dist/server/handlers/error.js.map +1 -0
  208. package/dist/server/handlers/legacyWorkflows.cjs +13 -11
  209. package/dist/server/handlers/legacyWorkflows.cjs.map +1 -0
  210. package/dist/server/handlers/legacyWorkflows.d.ts +59 -10
  211. package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -0
  212. package/dist/server/handlers/legacyWorkflows.js +3 -1
  213. package/dist/server/handlers/legacyWorkflows.js.map +1 -0
  214. package/dist/server/handlers/logs.cjs +6 -4
  215. package/dist/server/handlers/logs.cjs.map +1 -0
  216. package/dist/server/handlers/logs.d.ts +34 -3
  217. package/dist/server/handlers/logs.d.ts.map +1 -0
  218. package/dist/server/handlers/logs.js +3 -1
  219. package/dist/server/handlers/logs.js.map +1 -0
  220. package/dist/server/handlers/memory.cjs +39 -9
  221. package/dist/server/handlers/memory.cjs.map +1 -0
  222. package/dist/server/handlers/memory.d.ts +118 -8
  223. package/dist/server/handlers/memory.d.ts.map +1 -0
  224. package/dist/server/handlers/memory.js +3 -1
  225. package/dist/server/handlers/memory.js.map +1 -0
  226. package/dist/server/handlers/observability.cjs +24 -0
  227. package/dist/server/handlers/observability.cjs.map +1 -0
  228. package/dist/server/handlers/observability.d.ts +49 -0
  229. package/dist/server/handlers/observability.d.ts.map +1 -0
  230. package/dist/server/handlers/observability.js +3 -0
  231. package/dist/server/handlers/observability.js.map +1 -0
  232. package/dist/server/handlers/scores.cjs +32 -0
  233. package/dist/server/handlers/scores.cjs.map +1 -0
  234. package/dist/server/handlers/scores.d.ts +251 -0
  235. package/dist/server/handlers/scores.d.ts.map +1 -0
  236. package/dist/server/handlers/scores.js +3 -0
  237. package/dist/server/handlers/scores.js.map +1 -0
  238. package/dist/server/handlers/telemetry.cjs +9 -3
  239. package/dist/server/handlers/telemetry.cjs.map +1 -0
  240. package/dist/server/handlers/telemetry.d.ts +33 -2
  241. package/dist/server/handlers/telemetry.d.ts.map +1 -0
  242. package/dist/server/handlers/telemetry.js +3 -1
  243. package/dist/server/handlers/telemetry.js.map +1 -0
  244. package/dist/server/handlers/tools.cjs +11 -5
  245. package/dist/server/handlers/tools.cjs.map +1 -0
  246. package/dist/server/handlers/tools.d.ts +25 -4
  247. package/dist/server/handlers/tools.d.ts.map +1 -0
  248. package/dist/server/handlers/tools.js +3 -1
  249. package/dist/server/handlers/tools.js.map +1 -0
  250. package/dist/server/handlers/utils.cjs +8 -2
  251. package/dist/server/handlers/utils.cjs.map +1 -0
  252. package/dist/server/handlers/utils.d.ts +8 -1
  253. package/dist/server/handlers/utils.d.ts.map +1 -0
  254. package/dist/server/handlers/utils.js +3 -1
  255. package/dist/server/handlers/utils.js.map +1 -0
  256. package/dist/server/handlers/vNextNetwork.cjs +26 -24
  257. package/dist/server/handlers/vNextNetwork.cjs.map +1 -0
  258. package/dist/server/handlers/vNextNetwork.d.ts +246 -6
  259. package/dist/server/handlers/vNextNetwork.d.ts.map +1 -0
  260. package/dist/server/handlers/vNextNetwork.js +11 -9
  261. package/dist/server/handlers/vNextNetwork.js.map +1 -0
  262. package/dist/server/handlers/vector.cjs +9 -7
  263. package/dist/server/handlers/vector.cjs.map +1 -0
  264. package/dist/server/handlers/vector.d.ts +51 -6
  265. package/dist/server/handlers/vector.d.ts.map +1 -0
  266. package/dist/server/handlers/vector.js +3 -1
  267. package/dist/server/handlers/vector.js.map +1 -0
  268. package/dist/server/handlers/voice.cjs +7 -5
  269. package/dist/server/handlers/voice.cjs.map +1 -0
  270. package/dist/server/handlers/voice.d.ts +41 -4
  271. package/dist/server/handlers/voice.d.ts.map +1 -0
  272. package/dist/server/handlers/voice.js +3 -1
  273. package/dist/server/handlers/voice.js.map +1 -0
  274. package/dist/server/handlers/workflows.cjs +32 -14
  275. package/dist/server/handlers/workflows.cjs.map +1 -0
  276. package/dist/server/handlers/workflows.d.ts +87 -13
  277. package/dist/server/handlers/workflows.d.ts.map +1 -0
  278. package/dist/server/handlers/workflows.js +3 -1
  279. package/dist/server/handlers/workflows.js.map +1 -0
  280. package/dist/server/handlers.cjs +44 -32
  281. package/dist/server/handlers.cjs.map +1 -0
  282. package/dist/server/handlers.d.ts +14 -11
  283. package/dist/server/handlers.d.ts.map +1 -0
  284. package/dist/server/handlers.js +15 -11
  285. package/dist/server/handlers.js.map +1 -0
  286. package/dist/server/http-exception.d.ts +87 -0
  287. package/dist/server/http-exception.d.ts.map +1 -0
  288. package/dist/server/types.d.ts +10 -0
  289. package/dist/server/types.d.ts.map +1 -0
  290. package/dist/server/utils.d.ts +44 -0
  291. package/dist/server/utils.d.ts.map +1 -0
  292. package/package.json +46 -15
  293. package/dist/_tsup-dts-rollup.d.cts +0 -1068
  294. package/dist/_tsup-dts-rollup.d.ts +0 -1068
  295. package/dist/chunk-3DKDT264.cjs +0 -251
  296. package/dist/chunk-4QBIUKVY.js +0 -270
  297. package/dist/chunk-57CJTIPW.cjs +0 -18
  298. package/dist/chunk-7524QH7G.cjs +0 -483
  299. package/dist/chunk-75ZPJI57.cjs +0 -9
  300. package/dist/chunk-BWHGBV3K.cjs +0 -278
  301. package/dist/chunk-DPRB3R7Y.cjs +0 -148
  302. package/dist/chunk-FGGMQCPP.cjs +0 -128
  303. package/dist/chunk-L3N7ST2Z.cjs +0 -118
  304. package/dist/chunk-LTJNMM2Y.js +0 -241
  305. package/dist/chunk-MLKGABMK.js +0 -7
  306. package/dist/chunk-MTR2B27E.cjs +0 -14
  307. package/dist/chunk-VMXLEF54.js +0 -142
  308. package/dist/index.d.cts +0 -1
  309. package/dist/server/handlers/a2a.d.cts +0 -6
  310. package/dist/server/handlers/agents.d.cts +0 -6
  311. package/dist/server/handlers/error.d.cts +0 -1
  312. package/dist/server/handlers/legacyWorkflows.d.cts +0 -10
  313. package/dist/server/handlers/logs.d.cts +0 -3
  314. package/dist/server/handlers/memory.d.cts +0 -8
  315. package/dist/server/handlers/network.cjs +0 -22
  316. package/dist/server/handlers/network.d.cts +0 -4
  317. package/dist/server/handlers/network.d.ts +0 -4
  318. package/dist/server/handlers/network.js +0 -1
  319. package/dist/server/handlers/telemetry.d.cts +0 -2
  320. package/dist/server/handlers/tools.d.cts +0 -4
  321. package/dist/server/handlers/utils.d.cts +0 -1
  322. package/dist/server/handlers/vNextNetwork.d.cts +0 -6
  323. package/dist/server/handlers/vector.d.cts +0 -6
  324. package/dist/server/handlers/voice.d.cts +0 -4
  325. package/dist/server/handlers/workflows.d.cts +0 -13
  326. package/dist/server/handlers.d.cts +0 -11
@@ -0,0 +1,2013 @@
1
+ 'use strict';
2
+
3
+ var chunkHVBBFCDH_cjs = require('./chunk-HVBBFCDH.cjs');
4
+ var z6 = require('zod/v4');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var z6__default = /*#__PURE__*/_interopDefault(z6);
9
+
10
+ var anthropicErrorDataSchema = z6.z.object({
11
+ type: z6.z.literal("error"),
12
+ error: z6.z.object({
13
+ type: z6.z.string(),
14
+ message: z6.z.string()
15
+ })
16
+ });
17
+ var anthropicFailedResponseHandler = chunkHVBBFCDH_cjs.createJsonErrorResponseHandler({
18
+ errorSchema: anthropicErrorDataSchema,
19
+ errorToMessage: (data) => data.error.message
20
+ });
21
+ var anthropicFilePartProviderOptions = z6.z.object({
22
+ /**
23
+ * Citation configuration for this document.
24
+ * When enabled, this document will generate citations in the response.
25
+ */
26
+ citations: z6.z.object({
27
+ /**
28
+ * Enable citations for this document
29
+ */
30
+ enabled: z6.z.boolean()
31
+ }).optional(),
32
+ /**
33
+ * Custom title for the document.
34
+ * If not provided, the filename will be used.
35
+ */
36
+ title: z6.z.string().optional(),
37
+ /**
38
+ * Context about the document that will be passed to the model
39
+ * but not used towards cited content.
40
+ * Useful for storing document metadata as text or stringified JSON.
41
+ */
42
+ context: z6.z.string().optional()
43
+ });
44
+ var anthropicProviderOptions = z6.z.object({
45
+ sendReasoning: z6.z.boolean().optional(),
46
+ thinking: z6.z.object({
47
+ type: z6.z.union([z6.z.literal("enabled"), z6.z.literal("disabled")]),
48
+ budgetTokens: z6.z.number().optional()
49
+ }).optional(),
50
+ /**
51
+ * Whether to disable parallel function calling during tool use. Default is false.
52
+ * When set to true, Claude will use at most one tool per response.
53
+ */
54
+ disableParallelToolUse: z6.z.boolean().optional()
55
+ });
56
+ function getCacheControl(providerMetadata) {
57
+ var _a;
58
+ const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
59
+ const cacheControlValue = (_a = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a : anthropic2 == null ? void 0 : anthropic2.cache_control;
60
+ return cacheControlValue;
61
+ }
62
+ var webSearch_20250305ArgsSchema = z6.z.object({
63
+ /**
64
+ * Maximum number of web searches Claude can perform during the conversation.
65
+ */
66
+ maxUses: z6.z.number().optional(),
67
+ /**
68
+ * Optional list of domains that Claude is allowed to search.
69
+ */
70
+ allowedDomains: z6.z.array(z6.z.string()).optional(),
71
+ /**
72
+ * Optional list of domains that Claude should avoid when searching.
73
+ */
74
+ blockedDomains: z6.z.array(z6.z.string()).optional(),
75
+ /**
76
+ * Optional user location information to provide geographically relevant search results.
77
+ */
78
+ userLocation: z6.z.object({
79
+ type: z6.z.literal("approximate"),
80
+ city: z6.z.string().optional(),
81
+ region: z6.z.string().optional(),
82
+ country: z6.z.string().optional(),
83
+ timezone: z6.z.string().optional()
84
+ }).optional()
85
+ });
86
+ var webSearch_20250305OutputSchema = z6.z.array(
87
+ z6.z.object({
88
+ url: z6.z.string(),
89
+ title: z6.z.string(),
90
+ pageAge: z6.z.string().nullable(),
91
+ encryptedContent: z6.z.string(),
92
+ type: z6.z.string()
93
+ })
94
+ );
95
+ var factory = chunkHVBBFCDH_cjs.createProviderDefinedToolFactoryWithOutputSchema({
96
+ id: "anthropic.web_search_20250305",
97
+ name: "web_search",
98
+ inputSchema: z6.z.object({
99
+ query: z6.z.string()
100
+ }),
101
+ outputSchema: webSearch_20250305OutputSchema
102
+ });
103
+ var webSearch_20250305 = (args = {}) => {
104
+ return factory(args);
105
+ };
106
+ function isWebSearchTool(tool) {
107
+ return typeof tool === "object" && tool !== null && "type" in tool && tool.type === "web_search_20250305";
108
+ }
109
+ function prepareTools({
110
+ tools,
111
+ toolChoice,
112
+ disableParallelToolUse
113
+ }) {
114
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
115
+ const toolWarnings = [];
116
+ const betas = /* @__PURE__ */ new Set();
117
+ if (tools == null) {
118
+ return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
119
+ }
120
+ const anthropicTools2 = [];
121
+ for (const tool of tools) {
122
+ if (isWebSearchTool(tool)) {
123
+ anthropicTools2.push(tool);
124
+ continue;
125
+ }
126
+ switch (tool.type) {
127
+ case "function":
128
+ const cacheControl = getCacheControl(tool.providerOptions);
129
+ anthropicTools2.push({
130
+ name: tool.name,
131
+ description: tool.description,
132
+ input_schema: tool.inputSchema,
133
+ cache_control: cacheControl
134
+ });
135
+ break;
136
+ case "provider-defined":
137
+ switch (tool.id) {
138
+ case "anthropic.computer_20250124":
139
+ betas.add("computer-use-2025-01-24");
140
+ anthropicTools2.push({
141
+ name: "computer",
142
+ type: "computer_20250124",
143
+ display_width_px: tool.args.displayWidthPx,
144
+ display_height_px: tool.args.displayHeightPx,
145
+ display_number: tool.args.displayNumber
146
+ });
147
+ break;
148
+ case "anthropic.computer_20241022":
149
+ betas.add("computer-use-2024-10-22");
150
+ anthropicTools2.push({
151
+ name: "computer",
152
+ type: "computer_20241022",
153
+ display_width_px: tool.args.displayWidthPx,
154
+ display_height_px: tool.args.displayHeightPx,
155
+ display_number: tool.args.displayNumber
156
+ });
157
+ break;
158
+ case "anthropic.text_editor_20250124":
159
+ betas.add("computer-use-2025-01-24");
160
+ anthropicTools2.push({
161
+ name: "str_replace_editor",
162
+ type: "text_editor_20250124"
163
+ });
164
+ break;
165
+ case "anthropic.text_editor_20241022":
166
+ betas.add("computer-use-2024-10-22");
167
+ anthropicTools2.push({
168
+ name: "str_replace_editor",
169
+ type: "text_editor_20241022"
170
+ });
171
+ break;
172
+ case "anthropic.text_editor_20250429":
173
+ betas.add("computer-use-2025-01-24");
174
+ anthropicTools2.push({
175
+ name: "str_replace_based_edit_tool",
176
+ type: "text_editor_20250429"
177
+ });
178
+ break;
179
+ case "anthropic.bash_20250124":
180
+ betas.add("computer-use-2025-01-24");
181
+ anthropicTools2.push({
182
+ name: "bash",
183
+ type: "bash_20250124"
184
+ });
185
+ break;
186
+ case "anthropic.bash_20241022":
187
+ betas.add("computer-use-2024-10-22");
188
+ anthropicTools2.push({
189
+ name: "bash",
190
+ type: "bash_20241022"
191
+ });
192
+ break;
193
+ case "anthropic.web_search_20250305": {
194
+ const args = webSearch_20250305ArgsSchema.parse(tool.args);
195
+ anthropicTools2.push({
196
+ type: "web_search_20250305",
197
+ name: "web_search",
198
+ max_uses: args.maxUses,
199
+ allowed_domains: args.allowedDomains,
200
+ blocked_domains: args.blockedDomains,
201
+ user_location: args.userLocation
202
+ });
203
+ break;
204
+ }
205
+ case "anthropic.code_execution_20250522": {
206
+ betas.add("code-execution-2025-05-22");
207
+ anthropicTools2.push({
208
+ type: "code_execution_20250522",
209
+ name: "code_execution"
210
+ });
211
+ break;
212
+ }
213
+ default:
214
+ toolWarnings.push({ type: "unsupported-tool", tool });
215
+ break;
216
+ }
217
+ break;
218
+ default:
219
+ toolWarnings.push({ type: "unsupported-tool", tool });
220
+ break;
221
+ }
222
+ }
223
+ if (toolChoice == null) {
224
+ return {
225
+ tools: anthropicTools2,
226
+ toolChoice: disableParallelToolUse ? { type: "auto", disable_parallel_tool_use: disableParallelToolUse } : void 0,
227
+ toolWarnings,
228
+ betas
229
+ };
230
+ }
231
+ const type = toolChoice.type;
232
+ switch (type) {
233
+ case "auto":
234
+ return {
235
+ tools: anthropicTools2,
236
+ toolChoice: {
237
+ type: "auto",
238
+ disable_parallel_tool_use: disableParallelToolUse
239
+ },
240
+ toolWarnings,
241
+ betas
242
+ };
243
+ case "required":
244
+ return {
245
+ tools: anthropicTools2,
246
+ toolChoice: {
247
+ type: "any",
248
+ disable_parallel_tool_use: disableParallelToolUse
249
+ },
250
+ toolWarnings,
251
+ betas
252
+ };
253
+ case "none":
254
+ return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
255
+ case "tool":
256
+ return {
257
+ tools: anthropicTools2,
258
+ toolChoice: {
259
+ type: "tool",
260
+ name: toolChoice.toolName,
261
+ disable_parallel_tool_use: disableParallelToolUse
262
+ },
263
+ toolWarnings,
264
+ betas
265
+ };
266
+ default: {
267
+ const _exhaustiveCheck = type;
268
+ throw new chunkHVBBFCDH_cjs.UnsupportedFunctionalityError({
269
+ functionality: `tool choice type: ${_exhaustiveCheck}`
270
+ });
271
+ }
272
+ }
273
+ }
274
+ var codeExecution_20250522OutputSchema = z6.z.object({
275
+ type: z6.z.literal("code_execution_result"),
276
+ stdout: z6.z.string(),
277
+ stderr: z6.z.string(),
278
+ return_code: z6.z.number()
279
+ });
280
+ var factory2 = chunkHVBBFCDH_cjs.createProviderDefinedToolFactoryWithOutputSchema({
281
+ id: "anthropic.code_execution_20250522",
282
+ name: "code_execution",
283
+ inputSchema: z6.z.object({
284
+ code: z6.z.string()
285
+ }),
286
+ outputSchema: codeExecution_20250522OutputSchema
287
+ });
288
+ var codeExecution_20250522 = (args = {}) => {
289
+ return factory2(args);
290
+ };
291
+ function convertToString(data) {
292
+ if (typeof data === "string") {
293
+ return Buffer.from(data, "base64").toString("utf-8");
294
+ }
295
+ if (data instanceof Uint8Array) {
296
+ return new TextDecoder().decode(data);
297
+ }
298
+ if (data instanceof URL) {
299
+ throw new chunkHVBBFCDH_cjs.UnsupportedFunctionalityError({
300
+ functionality: "URL-based text documents are not supported for citations"
301
+ });
302
+ }
303
+ throw new chunkHVBBFCDH_cjs.UnsupportedFunctionalityError({
304
+ functionality: `unsupported data type for text documents: ${typeof data}`
305
+ });
306
+ }
307
+ async function convertToAnthropicMessagesPrompt({
308
+ prompt,
309
+ sendReasoning,
310
+ warnings
311
+ }) {
312
+ var _a, _b, _c, _d, _e;
313
+ const betas = /* @__PURE__ */ new Set();
314
+ const blocks = groupIntoBlocks(prompt);
315
+ let system = void 0;
316
+ const messages = [];
317
+ async function shouldEnableCitations(providerMetadata) {
318
+ var _a2, _b2;
319
+ const anthropicOptions = await chunkHVBBFCDH_cjs.parseProviderOptions({
320
+ provider: "anthropic",
321
+ providerOptions: providerMetadata,
322
+ schema: anthropicFilePartProviderOptions
323
+ });
324
+ return (_b2 = (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a2.enabled) != null ? _b2 : false;
325
+ }
326
+ async function getDocumentMetadata(providerMetadata) {
327
+ const anthropicOptions = await chunkHVBBFCDH_cjs.parseProviderOptions({
328
+ provider: "anthropic",
329
+ providerOptions: providerMetadata,
330
+ schema: anthropicFilePartProviderOptions
331
+ });
332
+ return {
333
+ title: anthropicOptions == null ? void 0 : anthropicOptions.title,
334
+ context: anthropicOptions == null ? void 0 : anthropicOptions.context
335
+ };
336
+ }
337
+ for (let i = 0; i < blocks.length; i++) {
338
+ const block = blocks[i];
339
+ const isLastBlock = i === blocks.length - 1;
340
+ const type = block.type;
341
+ switch (type) {
342
+ case "system": {
343
+ if (system != null) {
344
+ throw new chunkHVBBFCDH_cjs.UnsupportedFunctionalityError({
345
+ functionality: "Multiple system messages that are separated by user/assistant messages"
346
+ });
347
+ }
348
+ system = block.messages.map(({ content, providerOptions }) => ({
349
+ type: "text",
350
+ text: content,
351
+ cache_control: getCacheControl(providerOptions)
352
+ }));
353
+ break;
354
+ }
355
+ case "user": {
356
+ const anthropicContent = [];
357
+ for (const message of block.messages) {
358
+ const { role, content } = message;
359
+ switch (role) {
360
+ case "user": {
361
+ for (let j = 0; j < content.length; j++) {
362
+ const part = content[j];
363
+ const isLastPart = j === content.length - 1;
364
+ const cacheControl = (_a = getCacheControl(part.providerOptions)) != null ? _a : isLastPart ? getCacheControl(message.providerOptions) : void 0;
365
+ switch (part.type) {
366
+ case "text": {
367
+ anthropicContent.push({
368
+ type: "text",
369
+ text: part.text,
370
+ cache_control: cacheControl
371
+ });
372
+ break;
373
+ }
374
+ case "file": {
375
+ if (part.mediaType.startsWith("image/")) {
376
+ anthropicContent.push({
377
+ type: "image",
378
+ source: part.data instanceof URL ? {
379
+ type: "url",
380
+ url: part.data.toString()
381
+ } : {
382
+ type: "base64",
383
+ media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
384
+ data: chunkHVBBFCDH_cjs.convertToBase64(part.data)
385
+ },
386
+ cache_control: cacheControl
387
+ });
388
+ } else if (part.mediaType === "application/pdf") {
389
+ betas.add("pdfs-2024-09-25");
390
+ const enableCitations = await shouldEnableCitations(
391
+ part.providerOptions
392
+ );
393
+ const metadata = await getDocumentMetadata(
394
+ part.providerOptions
395
+ );
396
+ anthropicContent.push({
397
+ type: "document",
398
+ source: part.data instanceof URL ? {
399
+ type: "url",
400
+ url: part.data.toString()
401
+ } : {
402
+ type: "base64",
403
+ media_type: "application/pdf",
404
+ data: chunkHVBBFCDH_cjs.convertToBase64(part.data)
405
+ },
406
+ title: (_b = metadata.title) != null ? _b : part.filename,
407
+ ...metadata.context && { context: metadata.context },
408
+ ...enableCitations && {
409
+ citations: { enabled: true }
410
+ },
411
+ cache_control: cacheControl
412
+ });
413
+ } else if (part.mediaType === "text/plain") {
414
+ const enableCitations = await shouldEnableCitations(
415
+ part.providerOptions
416
+ );
417
+ const metadata = await getDocumentMetadata(
418
+ part.providerOptions
419
+ );
420
+ anthropicContent.push({
421
+ type: "document",
422
+ source: part.data instanceof URL ? {
423
+ type: "url",
424
+ url: part.data.toString()
425
+ } : {
426
+ type: "text",
427
+ media_type: "text/plain",
428
+ data: convertToString(part.data)
429
+ },
430
+ title: (_c = metadata.title) != null ? _c : part.filename,
431
+ ...metadata.context && { context: metadata.context },
432
+ ...enableCitations && {
433
+ citations: { enabled: true }
434
+ },
435
+ cache_control: cacheControl
436
+ });
437
+ } else {
438
+ throw new chunkHVBBFCDH_cjs.UnsupportedFunctionalityError({
439
+ functionality: `media type: ${part.mediaType}`
440
+ });
441
+ }
442
+ break;
443
+ }
444
+ }
445
+ }
446
+ break;
447
+ }
448
+ case "tool": {
449
+ for (let i2 = 0; i2 < content.length; i2++) {
450
+ const part = content[i2];
451
+ const isLastPart = i2 === content.length - 1;
452
+ const cacheControl = (_d = getCacheControl(part.providerOptions)) != null ? _d : isLastPart ? getCacheControl(message.providerOptions) : void 0;
453
+ const output = part.output;
454
+ let contentValue;
455
+ switch (output.type) {
456
+ case "content":
457
+ contentValue = output.value.map((contentPart) => {
458
+ switch (contentPart.type) {
459
+ case "text":
460
+ return {
461
+ type: "text",
462
+ text: contentPart.text,
463
+ cache_control: void 0
464
+ };
465
+ case "media": {
466
+ if (contentPart.mediaType.startsWith("image/")) {
467
+ return {
468
+ type: "image",
469
+ source: {
470
+ type: "base64",
471
+ media_type: contentPart.mediaType,
472
+ data: contentPart.data
473
+ },
474
+ cache_control: void 0
475
+ };
476
+ }
477
+ throw new chunkHVBBFCDH_cjs.UnsupportedFunctionalityError({
478
+ functionality: `media type: ${contentPart.mediaType}`
479
+ });
480
+ }
481
+ }
482
+ });
483
+ break;
484
+ case "text":
485
+ case "error-text":
486
+ contentValue = output.value;
487
+ break;
488
+ case "json":
489
+ case "error-json":
490
+ default:
491
+ contentValue = JSON.stringify(output.value);
492
+ break;
493
+ }
494
+ anthropicContent.push({
495
+ type: "tool_result",
496
+ tool_use_id: part.toolCallId,
497
+ content: contentValue,
498
+ is_error: output.type === "error-text" || output.type === "error-json" ? true : void 0,
499
+ cache_control: cacheControl
500
+ });
501
+ }
502
+ break;
503
+ }
504
+ default: {
505
+ const _exhaustiveCheck = role;
506
+ throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
507
+ }
508
+ }
509
+ }
510
+ messages.push({ role: "user", content: anthropicContent });
511
+ break;
512
+ }
513
+ case "assistant": {
514
+ const anthropicContent = [];
515
+ for (let j = 0; j < block.messages.length; j++) {
516
+ const message = block.messages[j];
517
+ const isLastMessage = j === block.messages.length - 1;
518
+ const { content } = message;
519
+ for (let k = 0; k < content.length; k++) {
520
+ const part = content[k];
521
+ const isLastContentPart = k === content.length - 1;
522
+ const cacheControl = (_e = getCacheControl(part.providerOptions)) != null ? _e : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
523
+ switch (part.type) {
524
+ case "text": {
525
+ anthropicContent.push({
526
+ type: "text",
527
+ text: (
528
+ // trim the last text part if it's the last message in the block
529
+ // because Anthropic does not allow trailing whitespace
530
+ // in pre-filled assistant responses
531
+ isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
532
+ ),
533
+ cache_control: cacheControl
534
+ });
535
+ break;
536
+ }
537
+ case "reasoning": {
538
+ if (sendReasoning) {
539
+ const reasoningMetadata = await chunkHVBBFCDH_cjs.parseProviderOptions({
540
+ provider: "anthropic",
541
+ providerOptions: part.providerOptions,
542
+ schema: anthropicReasoningMetadataSchema
543
+ });
544
+ if (reasoningMetadata != null) {
545
+ if (reasoningMetadata.signature != null) {
546
+ anthropicContent.push({
547
+ type: "thinking",
548
+ thinking: part.text,
549
+ signature: reasoningMetadata.signature,
550
+ cache_control: cacheControl
551
+ });
552
+ } else if (reasoningMetadata.redactedData != null) {
553
+ anthropicContent.push({
554
+ type: "redacted_thinking",
555
+ data: reasoningMetadata.redactedData,
556
+ cache_control: cacheControl
557
+ });
558
+ } else {
559
+ warnings.push({
560
+ type: "other",
561
+ message: "unsupported reasoning metadata"
562
+ });
563
+ }
564
+ } else {
565
+ warnings.push({
566
+ type: "other",
567
+ message: "unsupported reasoning metadata"
568
+ });
569
+ }
570
+ } else {
571
+ warnings.push({
572
+ type: "other",
573
+ message: "sending reasoning content is disabled for this model"
574
+ });
575
+ }
576
+ break;
577
+ }
578
+ case "tool-call": {
579
+ if (part.providerExecuted) {
580
+ if (part.toolName === "web_search") {
581
+ anthropicContent.push({
582
+ type: "server_tool_use",
583
+ id: part.toolCallId,
584
+ name: "web_search",
585
+ input: part.input,
586
+ cache_control: cacheControl
587
+ });
588
+ break;
589
+ }
590
+ if (part.toolName === "code_execution") {
591
+ anthropicContent.push({
592
+ type: "server_tool_use",
593
+ id: part.toolCallId,
594
+ name: "code_execution",
595
+ input: part.input,
596
+ cache_control: cacheControl
597
+ });
598
+ break;
599
+ }
600
+ warnings.push({
601
+ type: "other",
602
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
603
+ });
604
+ break;
605
+ }
606
+ anthropicContent.push({
607
+ type: "tool_use",
608
+ id: part.toolCallId,
609
+ name: part.toolName,
610
+ input: part.input,
611
+ cache_control: cacheControl
612
+ });
613
+ break;
614
+ }
615
+ case "tool-result": {
616
+ if (part.toolName === "web_search") {
617
+ const output = part.output;
618
+ if (output.type !== "json") {
619
+ warnings.push({
620
+ type: "other",
621
+ message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
622
+ });
623
+ break;
624
+ }
625
+ const webSearchOutput = webSearch_20250305OutputSchema.parse(
626
+ output.value
627
+ );
628
+ anthropicContent.push({
629
+ type: "web_search_tool_result",
630
+ tool_use_id: part.toolCallId,
631
+ content: webSearchOutput.map((result) => ({
632
+ url: result.url,
633
+ title: result.title,
634
+ page_age: result.pageAge,
635
+ encrypted_content: result.encryptedContent,
636
+ type: result.type
637
+ })),
638
+ cache_control: cacheControl
639
+ });
640
+ break;
641
+ }
642
+ if (part.toolName === "code_execution") {
643
+ const output = part.output;
644
+ if (output.type !== "json") {
645
+ warnings.push({
646
+ type: "other",
647
+ message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
648
+ });
649
+ break;
650
+ }
651
+ const codeExecutionOutput = codeExecution_20250522OutputSchema.parse(output.value);
652
+ anthropicContent.push({
653
+ type: "code_execution_tool_result",
654
+ tool_use_id: part.toolCallId,
655
+ content: {
656
+ type: codeExecutionOutput.type,
657
+ stdout: codeExecutionOutput.stdout,
658
+ stderr: codeExecutionOutput.stderr,
659
+ return_code: codeExecutionOutput.return_code
660
+ },
661
+ cache_control: cacheControl
662
+ });
663
+ break;
664
+ }
665
+ warnings.push({
666
+ type: "other",
667
+ message: `provider executed tool result for tool ${part.toolName} is not supported`
668
+ });
669
+ break;
670
+ }
671
+ }
672
+ }
673
+ }
674
+ messages.push({ role: "assistant", content: anthropicContent });
675
+ break;
676
+ }
677
+ default: {
678
+ const _exhaustiveCheck = type;
679
+ throw new Error(`content type: ${_exhaustiveCheck}`);
680
+ }
681
+ }
682
+ }
683
+ return {
684
+ prompt: { system, messages },
685
+ betas
686
+ };
687
+ }
688
+ function groupIntoBlocks(prompt) {
689
+ const blocks = [];
690
+ let currentBlock = void 0;
691
+ for (const message of prompt) {
692
+ const { role } = message;
693
+ switch (role) {
694
+ case "system": {
695
+ if ((currentBlock == null ? void 0 : currentBlock.type) !== "system") {
696
+ currentBlock = { type: "system", messages: [] };
697
+ blocks.push(currentBlock);
698
+ }
699
+ currentBlock.messages.push(message);
700
+ break;
701
+ }
702
+ case "assistant": {
703
+ if ((currentBlock == null ? void 0 : currentBlock.type) !== "assistant") {
704
+ currentBlock = { type: "assistant", messages: [] };
705
+ blocks.push(currentBlock);
706
+ }
707
+ currentBlock.messages.push(message);
708
+ break;
709
+ }
710
+ case "user": {
711
+ if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
712
+ currentBlock = { type: "user", messages: [] };
713
+ blocks.push(currentBlock);
714
+ }
715
+ currentBlock.messages.push(message);
716
+ break;
717
+ }
718
+ case "tool": {
719
+ if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
720
+ currentBlock = { type: "user", messages: [] };
721
+ blocks.push(currentBlock);
722
+ }
723
+ currentBlock.messages.push(message);
724
+ break;
725
+ }
726
+ default: {
727
+ const _exhaustiveCheck = role;
728
+ throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
729
+ }
730
+ }
731
+ }
732
+ return blocks;
733
+ }
734
+ function mapAnthropicStopReason({
735
+ finishReason,
736
+ isJsonResponseFromTool
737
+ }) {
738
+ switch (finishReason) {
739
+ case "end_turn":
740
+ case "stop_sequence":
741
+ return "stop";
742
+ case "tool_use":
743
+ return isJsonResponseFromTool ? "stop" : "tool-calls";
744
+ case "max_tokens":
745
+ return "length";
746
+ default:
747
+ return "unknown";
748
+ }
749
+ }
750
+ var citationSchemas = {
751
+ webSearchResult: z6.z.object({
752
+ type: z6.z.literal("web_search_result_location"),
753
+ cited_text: z6.z.string(),
754
+ url: z6.z.string(),
755
+ title: z6.z.string(),
756
+ encrypted_index: z6.z.string()
757
+ }),
758
+ pageLocation: z6.z.object({
759
+ type: z6.z.literal("page_location"),
760
+ cited_text: z6.z.string(),
761
+ document_index: z6.z.number(),
762
+ document_title: z6.z.string().nullable(),
763
+ start_page_number: z6.z.number(),
764
+ end_page_number: z6.z.number()
765
+ }),
766
+ charLocation: z6.z.object({
767
+ type: z6.z.literal("char_location"),
768
+ cited_text: z6.z.string(),
769
+ document_index: z6.z.number(),
770
+ document_title: z6.z.string().nullable(),
771
+ start_char_index: z6.z.number(),
772
+ end_char_index: z6.z.number()
773
+ })
774
+ };
775
+ var citationSchema = z6.z.discriminatedUnion("type", [
776
+ citationSchemas.webSearchResult,
777
+ citationSchemas.pageLocation,
778
+ citationSchemas.charLocation
779
+ ]);
780
+ z6.z.discriminatedUnion("type", [
781
+ citationSchemas.pageLocation,
782
+ citationSchemas.charLocation
783
+ ]);
784
+ function processCitation(citation, citationDocuments, generateId3, onSource) {
785
+ if (citation.type === "page_location" || citation.type === "char_location") {
786
+ const source = createCitationSource(
787
+ citation,
788
+ citationDocuments,
789
+ generateId3
790
+ );
791
+ if (source) {
792
+ onSource(source);
793
+ }
794
+ }
795
+ }
796
+ function createCitationSource(citation, citationDocuments, generateId3) {
797
+ var _a;
798
+ const documentInfo = citationDocuments[citation.document_index];
799
+ if (!documentInfo) {
800
+ return null;
801
+ }
802
+ const providerMetadata = citation.type === "page_location" ? {
803
+ citedText: citation.cited_text,
804
+ startPageNumber: citation.start_page_number,
805
+ endPageNumber: citation.end_page_number
806
+ } : {
807
+ citedText: citation.cited_text,
808
+ startCharIndex: citation.start_char_index,
809
+ endCharIndex: citation.end_char_index
810
+ };
811
+ return {
812
+ type: "source",
813
+ sourceType: "document",
814
+ id: generateId3(),
815
+ mediaType: documentInfo.mediaType,
816
+ title: (_a = citation.document_title) != null ? _a : documentInfo.title,
817
+ filename: documentInfo.filename,
818
+ providerMetadata: {
819
+ anthropic: providerMetadata
820
+ }
821
+ };
822
+ }
823
+ var AnthropicMessagesLanguageModel = class {
824
+ constructor(modelId, config) {
825
+ this.specificationVersion = "v2";
826
+ var _a;
827
+ this.modelId = modelId;
828
+ this.config = config;
829
+ this.generateId = (_a = config.generateId) != null ? _a : chunkHVBBFCDH_cjs.generateId;
830
+ }
831
+ supportsUrl(url) {
832
+ return url.protocol === "https:";
833
+ }
834
+ get provider() {
835
+ return this.config.provider;
836
+ }
837
+ get supportedUrls() {
838
+ var _a, _b, _c;
839
+ return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
840
+ }
841
+ async getArgs({
842
+ prompt,
843
+ maxOutputTokens = 4096,
844
+ // 4096: max model output tokens TODO update default in v5
845
+ temperature,
846
+ topP,
847
+ topK,
848
+ frequencyPenalty,
849
+ presencePenalty,
850
+ stopSequences,
851
+ responseFormat,
852
+ seed,
853
+ tools,
854
+ toolChoice,
855
+ providerOptions
856
+ }) {
857
+ var _a, _b, _c;
858
+ const warnings = [];
859
+ if (frequencyPenalty != null) {
860
+ warnings.push({
861
+ type: "unsupported-setting",
862
+ setting: "frequencyPenalty"
863
+ });
864
+ }
865
+ if (presencePenalty != null) {
866
+ warnings.push({
867
+ type: "unsupported-setting",
868
+ setting: "presencePenalty"
869
+ });
870
+ }
871
+ if (seed != null) {
872
+ warnings.push({
873
+ type: "unsupported-setting",
874
+ setting: "seed"
875
+ });
876
+ }
877
+ if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
878
+ if (responseFormat.schema == null) {
879
+ warnings.push({
880
+ type: "unsupported-setting",
881
+ setting: "responseFormat",
882
+ details: "JSON response format requires a schema. The response format is ignored."
883
+ });
884
+ } else if (tools != null) {
885
+ warnings.push({
886
+ type: "unsupported-setting",
887
+ setting: "tools",
888
+ details: "JSON response format does not support tools. The provided tools are ignored."
889
+ });
890
+ }
891
+ }
892
+ const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
893
+ type: "function",
894
+ name: "json",
895
+ description: "Respond with a JSON object.",
896
+ inputSchema: responseFormat.schema
897
+ } : void 0;
898
+ const anthropicOptions = await chunkHVBBFCDH_cjs.parseProviderOptions({
899
+ provider: "anthropic",
900
+ providerOptions,
901
+ schema: anthropicProviderOptions
902
+ });
903
+ const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
904
+ prompt,
905
+ sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
906
+ warnings
907
+ });
908
+ const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
909
+ const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
910
+ const baseArgs = {
911
+ // model id:
912
+ model: this.modelId,
913
+ // standardized settings:
914
+ max_tokens: maxOutputTokens,
915
+ temperature,
916
+ top_k: topK,
917
+ top_p: topP,
918
+ stop_sequences: stopSequences,
919
+ // provider specific settings:
920
+ ...isThinking && {
921
+ thinking: { type: "enabled", budget_tokens: thinkingBudget }
922
+ },
923
+ // prompt:
924
+ system: messagesPrompt.system,
925
+ messages: messagesPrompt.messages
926
+ };
927
+ if (isThinking) {
928
+ if (thinkingBudget == null) {
929
+ throw new chunkHVBBFCDH_cjs.UnsupportedFunctionalityError({
930
+ functionality: "thinking requires a budget"
931
+ });
932
+ }
933
+ if (baseArgs.temperature != null) {
934
+ baseArgs.temperature = void 0;
935
+ warnings.push({
936
+ type: "unsupported-setting",
937
+ setting: "temperature",
938
+ details: "temperature is not supported when thinking is enabled"
939
+ });
940
+ }
941
+ if (topK != null) {
942
+ baseArgs.top_k = void 0;
943
+ warnings.push({
944
+ type: "unsupported-setting",
945
+ setting: "topK",
946
+ details: "topK is not supported when thinking is enabled"
947
+ });
948
+ }
949
+ if (topP != null) {
950
+ baseArgs.top_p = void 0;
951
+ warnings.push({
952
+ type: "unsupported-setting",
953
+ setting: "topP",
954
+ details: "topP is not supported when thinking is enabled"
955
+ });
956
+ }
957
+ baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
958
+ }
959
+ const {
960
+ tools: anthropicTools2,
961
+ toolChoice: anthropicToolChoice,
962
+ toolWarnings,
963
+ betas: toolsBetas
964
+ } = prepareTools(
965
+ jsonResponseTool != null ? {
966
+ tools: [jsonResponseTool],
967
+ toolChoice: { type: "tool", toolName: jsonResponseTool.name },
968
+ disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
969
+ } : {
970
+ tools: tools != null ? tools : [],
971
+ toolChoice,
972
+ disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
973
+ }
974
+ );
975
+ return {
976
+ args: {
977
+ ...baseArgs,
978
+ tools: anthropicTools2,
979
+ tool_choice: anthropicToolChoice
980
+ },
981
+ warnings: [...warnings, ...toolWarnings],
982
+ betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas]),
983
+ usesJsonResponseTool: jsonResponseTool != null
984
+ };
985
+ }
986
+ async getHeaders({
987
+ betas,
988
+ headers
989
+ }) {
990
+ return chunkHVBBFCDH_cjs.combineHeaders(
991
+ await chunkHVBBFCDH_cjs.resolve(this.config.headers),
992
+ betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
993
+ headers
994
+ );
995
+ }
996
+ buildRequestUrl(isStreaming) {
997
+ var _a, _b, _c;
998
+ return (_c = (_b = (_a = this.config).buildRequestUrl) == null ? void 0 : _b.call(_a, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
999
+ }
1000
+ transformRequestBody(args) {
1001
+ var _a, _b, _c;
1002
+ return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
1003
+ }
1004
+ extractCitationDocuments(prompt) {
1005
+ const isCitationPart = (part) => {
1006
+ var _a, _b;
1007
+ if (part.type !== "file") {
1008
+ return false;
1009
+ }
1010
+ if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") {
1011
+ return false;
1012
+ }
1013
+ const anthropic2 = (_a = part.providerOptions) == null ? void 0 : _a.anthropic;
1014
+ const citationsConfig = anthropic2 == null ? void 0 : anthropic2.citations;
1015
+ return (_b = citationsConfig == null ? void 0 : citationsConfig.enabled) != null ? _b : false;
1016
+ };
1017
+ return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
1018
+ var _a;
1019
+ const filePart = part;
1020
+ return {
1021
+ title: (_a = filePart.filename) != null ? _a : "Untitled Document",
1022
+ filename: filePart.filename,
1023
+ mediaType: filePart.mediaType
1024
+ };
1025
+ });
1026
+ }
1027
+ async doGenerate(options) {
1028
+ var _a, _b, _c, _d, _e;
1029
+ const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
1030
+ const citationDocuments = this.extractCitationDocuments(options.prompt);
1031
+ const {
1032
+ responseHeaders,
1033
+ value: response,
1034
+ rawValue: rawResponse
1035
+ } = await chunkHVBBFCDH_cjs.postJsonToApi({
1036
+ url: this.buildRequestUrl(false),
1037
+ headers: await this.getHeaders({ betas, headers: options.headers }),
1038
+ body: this.transformRequestBody(args),
1039
+ failedResponseHandler: anthropicFailedResponseHandler,
1040
+ successfulResponseHandler: chunkHVBBFCDH_cjs.createJsonResponseHandler(
1041
+ anthropicMessagesResponseSchema
1042
+ ),
1043
+ abortSignal: options.abortSignal,
1044
+ fetch: this.config.fetch
1045
+ });
1046
+ const content = [];
1047
+ for (const part of response.content) {
1048
+ switch (part.type) {
1049
+ case "text": {
1050
+ if (!usesJsonResponseTool) {
1051
+ content.push({ type: "text", text: part.text });
1052
+ if (part.citations) {
1053
+ for (const citation of part.citations) {
1054
+ processCitation(
1055
+ citation,
1056
+ citationDocuments,
1057
+ this.generateId,
1058
+ (source) => content.push(source)
1059
+ );
1060
+ }
1061
+ }
1062
+ }
1063
+ break;
1064
+ }
1065
+ case "thinking": {
1066
+ content.push({
1067
+ type: "reasoning",
1068
+ text: part.thinking,
1069
+ providerMetadata: {
1070
+ anthropic: {
1071
+ signature: part.signature
1072
+ }
1073
+ }
1074
+ });
1075
+ break;
1076
+ }
1077
+ case "redacted_thinking": {
1078
+ content.push({
1079
+ type: "reasoning",
1080
+ text: "",
1081
+ providerMetadata: {
1082
+ anthropic: {
1083
+ redactedData: part.data
1084
+ }
1085
+ }
1086
+ });
1087
+ break;
1088
+ }
1089
+ case "tool_use": {
1090
+ content.push(
1091
+ // when a json response tool is used, the tool call becomes the text:
1092
+ usesJsonResponseTool ? {
1093
+ type: "text",
1094
+ text: JSON.stringify(part.input)
1095
+ } : {
1096
+ type: "tool-call",
1097
+ toolCallId: part.id,
1098
+ toolName: part.name,
1099
+ input: JSON.stringify(part.input)
1100
+ }
1101
+ );
1102
+ break;
1103
+ }
1104
+ case "server_tool_use": {
1105
+ if (part.name === "web_search" || part.name === "code_execution") {
1106
+ content.push({
1107
+ type: "tool-call",
1108
+ toolCallId: part.id,
1109
+ toolName: part.name,
1110
+ input: JSON.stringify(part.input),
1111
+ providerExecuted: true
1112
+ });
1113
+ }
1114
+ break;
1115
+ }
1116
+ case "web_search_tool_result": {
1117
+ if (Array.isArray(part.content)) {
1118
+ content.push({
1119
+ type: "tool-result",
1120
+ toolCallId: part.tool_use_id,
1121
+ toolName: "web_search",
1122
+ result: part.content.map((result) => {
1123
+ var _a2;
1124
+ return {
1125
+ url: result.url,
1126
+ title: result.title,
1127
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null,
1128
+ encryptedContent: result.encrypted_content,
1129
+ type: result.type
1130
+ };
1131
+ }),
1132
+ providerExecuted: true
1133
+ });
1134
+ for (const result of part.content) {
1135
+ content.push({
1136
+ type: "source",
1137
+ sourceType: "url",
1138
+ id: this.generateId(),
1139
+ url: result.url,
1140
+ title: result.title,
1141
+ providerMetadata: {
1142
+ anthropic: {
1143
+ pageAge: (_a = result.page_age) != null ? _a : null
1144
+ }
1145
+ }
1146
+ });
1147
+ }
1148
+ } else {
1149
+ content.push({
1150
+ type: "tool-result",
1151
+ toolCallId: part.tool_use_id,
1152
+ toolName: "web_search",
1153
+ isError: true,
1154
+ result: {
1155
+ type: "web_search_tool_result_error",
1156
+ errorCode: part.content.error_code
1157
+ },
1158
+ providerExecuted: true
1159
+ });
1160
+ }
1161
+ break;
1162
+ }
1163
+ case "code_execution_tool_result": {
1164
+ if (part.content.type === "code_execution_result") {
1165
+ content.push({
1166
+ type: "tool-result",
1167
+ toolCallId: part.tool_use_id,
1168
+ toolName: "code_execution",
1169
+ result: {
1170
+ type: part.content.type,
1171
+ stdout: part.content.stdout,
1172
+ stderr: part.content.stderr,
1173
+ return_code: part.content.return_code
1174
+ },
1175
+ providerExecuted: true
1176
+ });
1177
+ } else if (part.content.type === "code_execution_tool_result_error") {
1178
+ content.push({
1179
+ type: "tool-result",
1180
+ toolCallId: part.tool_use_id,
1181
+ toolName: "code_execution",
1182
+ isError: true,
1183
+ result: {
1184
+ type: "code_execution_tool_result_error",
1185
+ errorCode: part.content.error_code
1186
+ },
1187
+ providerExecuted: true
1188
+ });
1189
+ }
1190
+ break;
1191
+ }
1192
+ }
1193
+ }
1194
+ return {
1195
+ content,
1196
+ finishReason: mapAnthropicStopReason({
1197
+ finishReason: response.stop_reason,
1198
+ isJsonResponseFromTool: usesJsonResponseTool
1199
+ }),
1200
+ usage: {
1201
+ inputTokens: response.usage.input_tokens,
1202
+ outputTokens: response.usage.output_tokens,
1203
+ totalTokens: response.usage.input_tokens + response.usage.output_tokens,
1204
+ cachedInputTokens: (_b = response.usage.cache_read_input_tokens) != null ? _b : void 0
1205
+ },
1206
+ request: { body: args },
1207
+ response: {
1208
+ id: (_c = response.id) != null ? _c : void 0,
1209
+ modelId: (_d = response.model) != null ? _d : void 0,
1210
+ headers: responseHeaders,
1211
+ body: rawResponse
1212
+ },
1213
+ warnings,
1214
+ providerMetadata: {
1215
+ anthropic: {
1216
+ usage: response.usage,
1217
+ cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null
1218
+ }
1219
+ }
1220
+ };
1221
+ }
1222
+ async doStream(options) {
1223
+ const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
1224
+ const citationDocuments = this.extractCitationDocuments(options.prompt);
1225
+ const body = { ...args, stream: true };
1226
+ const { responseHeaders, value: response } = await chunkHVBBFCDH_cjs.postJsonToApi({
1227
+ url: this.buildRequestUrl(true),
1228
+ headers: await this.getHeaders({ betas, headers: options.headers }),
1229
+ body: this.transformRequestBody(body),
1230
+ failedResponseHandler: anthropicFailedResponseHandler,
1231
+ successfulResponseHandler: chunkHVBBFCDH_cjs.createEventSourceResponseHandler(
1232
+ anthropicMessagesChunkSchema
1233
+ ),
1234
+ abortSignal: options.abortSignal,
1235
+ fetch: this.config.fetch
1236
+ });
1237
+ let finishReason = "unknown";
1238
+ const usage = {
1239
+ inputTokens: void 0,
1240
+ outputTokens: void 0,
1241
+ totalTokens: void 0
1242
+ };
1243
+ const contentBlocks = {};
1244
+ let providerMetadata = void 0;
1245
+ let blockType = void 0;
1246
+ const generateId3 = this.generateId;
1247
+ return {
1248
+ stream: response.pipeThrough(
1249
+ new TransformStream({
1250
+ start(controller) {
1251
+ controller.enqueue({ type: "stream-start", warnings });
1252
+ },
1253
+ transform(chunk, controller) {
1254
+ var _a, _b, _c, _d, _e, _f, _g;
1255
+ if (options.includeRawChunks) {
1256
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1257
+ }
1258
+ if (!chunk.success) {
1259
+ controller.enqueue({ type: "error", error: chunk.error });
1260
+ return;
1261
+ }
1262
+ const value = chunk.value;
1263
+ switch (value.type) {
1264
+ case "ping": {
1265
+ return;
1266
+ }
1267
+ case "content_block_start": {
1268
+ const contentBlockType = value.content_block.type;
1269
+ blockType = contentBlockType;
1270
+ switch (contentBlockType) {
1271
+ case "text": {
1272
+ contentBlocks[value.index] = { type: "text" };
1273
+ controller.enqueue({
1274
+ type: "text-start",
1275
+ id: String(value.index)
1276
+ });
1277
+ return;
1278
+ }
1279
+ case "thinking": {
1280
+ contentBlocks[value.index] = { type: "reasoning" };
1281
+ controller.enqueue({
1282
+ type: "reasoning-start",
1283
+ id: String(value.index)
1284
+ });
1285
+ return;
1286
+ }
1287
+ case "redacted_thinking": {
1288
+ contentBlocks[value.index] = { type: "reasoning" };
1289
+ controller.enqueue({
1290
+ type: "reasoning-start",
1291
+ id: String(value.index),
1292
+ providerMetadata: {
1293
+ anthropic: {
1294
+ redactedData: value.content_block.data
1295
+ }
1296
+ }
1297
+ });
1298
+ return;
1299
+ }
1300
+ case "tool_use": {
1301
+ contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
1302
+ type: "tool-call",
1303
+ toolCallId: value.content_block.id,
1304
+ toolName: value.content_block.name,
1305
+ input: ""
1306
+ };
1307
+ controller.enqueue(
1308
+ usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
1309
+ type: "tool-input-start",
1310
+ id: value.content_block.id,
1311
+ toolName: value.content_block.name
1312
+ }
1313
+ );
1314
+ return;
1315
+ }
1316
+ case "server_tool_use": {
1317
+ if (value.content_block.name === "web_search" || value.content_block.name === "code_execution") {
1318
+ contentBlocks[value.index] = {
1319
+ type: "tool-call",
1320
+ toolCallId: value.content_block.id,
1321
+ toolName: value.content_block.name,
1322
+ input: "",
1323
+ providerExecuted: true
1324
+ };
1325
+ controller.enqueue({
1326
+ type: "tool-input-start",
1327
+ id: value.content_block.id,
1328
+ toolName: value.content_block.name,
1329
+ providerExecuted: true
1330
+ });
1331
+ }
1332
+ return;
1333
+ }
1334
+ case "web_search_tool_result": {
1335
+ const part = value.content_block;
1336
+ if (Array.isArray(part.content)) {
1337
+ controller.enqueue({
1338
+ type: "tool-result",
1339
+ toolCallId: part.tool_use_id,
1340
+ toolName: "web_search",
1341
+ result: part.content.map((result) => {
1342
+ var _a2;
1343
+ return {
1344
+ url: result.url,
1345
+ title: result.title,
1346
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null,
1347
+ encryptedContent: result.encrypted_content,
1348
+ type: result.type
1349
+ };
1350
+ }),
1351
+ providerExecuted: true
1352
+ });
1353
+ for (const result of part.content) {
1354
+ controller.enqueue({
1355
+ type: "source",
1356
+ sourceType: "url",
1357
+ id: generateId3(),
1358
+ url: result.url,
1359
+ title: result.title,
1360
+ providerMetadata: {
1361
+ anthropic: {
1362
+ pageAge: (_a = result.page_age) != null ? _a : null
1363
+ }
1364
+ }
1365
+ });
1366
+ }
1367
+ } else {
1368
+ controller.enqueue({
1369
+ type: "tool-result",
1370
+ toolCallId: part.tool_use_id,
1371
+ toolName: "web_search",
1372
+ isError: true,
1373
+ result: {
1374
+ type: "web_search_tool_result_error",
1375
+ errorCode: part.content.error_code
1376
+ },
1377
+ providerExecuted: true
1378
+ });
1379
+ }
1380
+ return;
1381
+ }
1382
+ case "code_execution_tool_result": {
1383
+ const part = value.content_block;
1384
+ if (part.content.type === "code_execution_result") {
1385
+ controller.enqueue({
1386
+ type: "tool-result",
1387
+ toolCallId: part.tool_use_id,
1388
+ toolName: "code_execution",
1389
+ result: {
1390
+ type: part.content.type,
1391
+ stdout: part.content.stdout,
1392
+ stderr: part.content.stderr,
1393
+ return_code: part.content.return_code
1394
+ },
1395
+ providerExecuted: true
1396
+ });
1397
+ } else if (part.content.type === "code_execution_tool_result_error") {
1398
+ controller.enqueue({
1399
+ type: "tool-result",
1400
+ toolCallId: part.tool_use_id,
1401
+ toolName: "code_execution",
1402
+ isError: true,
1403
+ result: {
1404
+ type: "code_execution_tool_result_error",
1405
+ errorCode: part.content.error_code
1406
+ },
1407
+ providerExecuted: true
1408
+ });
1409
+ }
1410
+ return;
1411
+ }
1412
+ default: {
1413
+ const _exhaustiveCheck = contentBlockType;
1414
+ throw new Error(
1415
+ `Unsupported content block type: ${_exhaustiveCheck}`
1416
+ );
1417
+ }
1418
+ }
1419
+ }
1420
+ case "content_block_stop": {
1421
+ if (contentBlocks[value.index] != null) {
1422
+ const contentBlock = contentBlocks[value.index];
1423
+ switch (contentBlock.type) {
1424
+ case "text": {
1425
+ controller.enqueue({
1426
+ type: "text-end",
1427
+ id: String(value.index)
1428
+ });
1429
+ break;
1430
+ }
1431
+ case "reasoning": {
1432
+ controller.enqueue({
1433
+ type: "reasoning-end",
1434
+ id: String(value.index)
1435
+ });
1436
+ break;
1437
+ }
1438
+ case "tool-call":
1439
+ if (!usesJsonResponseTool) {
1440
+ controller.enqueue({
1441
+ type: "tool-input-end",
1442
+ id: contentBlock.toolCallId
1443
+ });
1444
+ controller.enqueue(contentBlock);
1445
+ }
1446
+ break;
1447
+ }
1448
+ delete contentBlocks[value.index];
1449
+ }
1450
+ blockType = void 0;
1451
+ return;
1452
+ }
1453
+ case "content_block_delta": {
1454
+ const deltaType = value.delta.type;
1455
+ switch (deltaType) {
1456
+ case "text_delta": {
1457
+ if (usesJsonResponseTool) {
1458
+ return;
1459
+ }
1460
+ controller.enqueue({
1461
+ type: "text-delta",
1462
+ id: String(value.index),
1463
+ delta: value.delta.text
1464
+ });
1465
+ return;
1466
+ }
1467
+ case "thinking_delta": {
1468
+ controller.enqueue({
1469
+ type: "reasoning-delta",
1470
+ id: String(value.index),
1471
+ delta: value.delta.thinking
1472
+ });
1473
+ return;
1474
+ }
1475
+ case "signature_delta": {
1476
+ if (blockType === "thinking") {
1477
+ controller.enqueue({
1478
+ type: "reasoning-delta",
1479
+ id: String(value.index),
1480
+ delta: "",
1481
+ providerMetadata: {
1482
+ anthropic: {
1483
+ signature: value.delta.signature
1484
+ }
1485
+ }
1486
+ });
1487
+ }
1488
+ return;
1489
+ }
1490
+ case "input_json_delta": {
1491
+ const contentBlock = contentBlocks[value.index];
1492
+ const delta = value.delta.partial_json;
1493
+ if (usesJsonResponseTool) {
1494
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
1495
+ return;
1496
+ }
1497
+ controller.enqueue({
1498
+ type: "text-delta",
1499
+ id: String(value.index),
1500
+ delta
1501
+ });
1502
+ } else {
1503
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
1504
+ return;
1505
+ }
1506
+ controller.enqueue({
1507
+ type: "tool-input-delta",
1508
+ id: contentBlock.toolCallId,
1509
+ delta
1510
+ });
1511
+ contentBlock.input += delta;
1512
+ }
1513
+ return;
1514
+ }
1515
+ case "citations_delta": {
1516
+ const citation = value.delta.citation;
1517
+ processCitation(
1518
+ citation,
1519
+ citationDocuments,
1520
+ generateId3,
1521
+ (source) => controller.enqueue(source)
1522
+ );
1523
+ return;
1524
+ }
1525
+ default: {
1526
+ const _exhaustiveCheck = deltaType;
1527
+ throw new Error(
1528
+ `Unsupported delta type: ${_exhaustiveCheck}`
1529
+ );
1530
+ }
1531
+ }
1532
+ }
1533
+ case "message_start": {
1534
+ usage.inputTokens = value.message.usage.input_tokens;
1535
+ usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
1536
+ providerMetadata = {
1537
+ anthropic: {
1538
+ usage: value.message.usage,
1539
+ cacheCreationInputTokens: (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null
1540
+ }
1541
+ };
1542
+ controller.enqueue({
1543
+ type: "response-metadata",
1544
+ id: (_d = value.message.id) != null ? _d : void 0,
1545
+ modelId: (_e = value.message.model) != null ? _e : void 0
1546
+ });
1547
+ return;
1548
+ }
1549
+ case "message_delta": {
1550
+ usage.outputTokens = value.usage.output_tokens;
1551
+ usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
1552
+ finishReason = mapAnthropicStopReason({
1553
+ finishReason: value.delta.stop_reason,
1554
+ isJsonResponseFromTool: usesJsonResponseTool
1555
+ });
1556
+ return;
1557
+ }
1558
+ case "message_stop": {
1559
+ controller.enqueue({
1560
+ type: "finish",
1561
+ finishReason,
1562
+ usage,
1563
+ providerMetadata
1564
+ });
1565
+ return;
1566
+ }
1567
+ case "error": {
1568
+ controller.enqueue({ type: "error", error: value.error });
1569
+ return;
1570
+ }
1571
+ default: {
1572
+ const _exhaustiveCheck = value;
1573
+ throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
1574
+ }
1575
+ }
1576
+ }
1577
+ })
1578
+ ),
1579
+ request: { body },
1580
+ response: { headers: responseHeaders }
1581
+ };
1582
+ }
1583
+ };
1584
+ var anthropicMessagesResponseSchema = z6.z.object({
1585
+ type: z6.z.literal("message"),
1586
+ id: z6.z.string().nullish(),
1587
+ model: z6.z.string().nullish(),
1588
+ content: z6.z.array(
1589
+ z6.z.discriminatedUnion("type", [
1590
+ z6.z.object({
1591
+ type: z6.z.literal("text"),
1592
+ text: z6.z.string(),
1593
+ citations: z6.z.array(citationSchema).optional()
1594
+ }),
1595
+ z6.z.object({
1596
+ type: z6.z.literal("thinking"),
1597
+ thinking: z6.z.string(),
1598
+ signature: z6.z.string()
1599
+ }),
1600
+ z6.z.object({
1601
+ type: z6.z.literal("redacted_thinking"),
1602
+ data: z6.z.string()
1603
+ }),
1604
+ z6.z.object({
1605
+ type: z6.z.literal("tool_use"),
1606
+ id: z6.z.string(),
1607
+ name: z6.z.string(),
1608
+ input: z6.z.unknown()
1609
+ }),
1610
+ z6.z.object({
1611
+ type: z6.z.literal("server_tool_use"),
1612
+ id: z6.z.string(),
1613
+ name: z6.z.string(),
1614
+ input: z6.z.record(z6.z.string(), z6.z.unknown()).nullish()
1615
+ }),
1616
+ z6.z.object({
1617
+ type: z6.z.literal("web_search_tool_result"),
1618
+ tool_use_id: z6.z.string(),
1619
+ content: z6.z.union([
1620
+ z6.z.array(
1621
+ z6.z.object({
1622
+ type: z6.z.literal("web_search_result"),
1623
+ url: z6.z.string(),
1624
+ title: z6.z.string(),
1625
+ encrypted_content: z6.z.string(),
1626
+ page_age: z6.z.string().nullish()
1627
+ })
1628
+ ),
1629
+ z6.z.object({
1630
+ type: z6.z.literal("web_search_tool_result_error"),
1631
+ error_code: z6.z.string()
1632
+ })
1633
+ ])
1634
+ }),
1635
+ z6.z.object({
1636
+ type: z6.z.literal("code_execution_tool_result"),
1637
+ tool_use_id: z6.z.string(),
1638
+ content: z6.z.union([
1639
+ z6.z.object({
1640
+ type: z6.z.literal("code_execution_result"),
1641
+ stdout: z6.z.string(),
1642
+ stderr: z6.z.string(),
1643
+ return_code: z6.z.number()
1644
+ }),
1645
+ z6.z.object({
1646
+ type: z6.z.literal("code_execution_tool_result_error"),
1647
+ error_code: z6.z.string()
1648
+ })
1649
+ ])
1650
+ })
1651
+ ])
1652
+ ),
1653
+ stop_reason: z6.z.string().nullish(),
1654
+ usage: z6.z.looseObject({
1655
+ input_tokens: z6.z.number(),
1656
+ output_tokens: z6.z.number(),
1657
+ cache_creation_input_tokens: z6.z.number().nullish(),
1658
+ cache_read_input_tokens: z6.z.number().nullish()
1659
+ })
1660
+ });
1661
+ var anthropicMessagesChunkSchema = z6.z.discriminatedUnion("type", [
1662
+ z6.z.object({
1663
+ type: z6.z.literal("message_start"),
1664
+ message: z6.z.object({
1665
+ id: z6.z.string().nullish(),
1666
+ model: z6.z.string().nullish(),
1667
+ usage: z6.z.looseObject({
1668
+ input_tokens: z6.z.number(),
1669
+ output_tokens: z6.z.number(),
1670
+ cache_creation_input_tokens: z6.z.number().nullish(),
1671
+ cache_read_input_tokens: z6.z.number().nullish()
1672
+ })
1673
+ })
1674
+ }),
1675
+ z6.z.object({
1676
+ type: z6.z.literal("content_block_start"),
1677
+ index: z6.z.number(),
1678
+ content_block: z6.z.discriminatedUnion("type", [
1679
+ z6.z.object({
1680
+ type: z6.z.literal("text"),
1681
+ text: z6.z.string()
1682
+ }),
1683
+ z6.z.object({
1684
+ type: z6.z.literal("thinking"),
1685
+ thinking: z6.z.string()
1686
+ }),
1687
+ z6.z.object({
1688
+ type: z6.z.literal("tool_use"),
1689
+ id: z6.z.string(),
1690
+ name: z6.z.string()
1691
+ }),
1692
+ z6.z.object({
1693
+ type: z6.z.literal("redacted_thinking"),
1694
+ data: z6.z.string()
1695
+ }),
1696
+ z6.z.object({
1697
+ type: z6.z.literal("server_tool_use"),
1698
+ id: z6.z.string(),
1699
+ name: z6.z.string(),
1700
+ input: z6.z.record(z6.z.string(), z6.z.unknown()).nullish()
1701
+ }),
1702
+ z6.z.object({
1703
+ type: z6.z.literal("web_search_tool_result"),
1704
+ tool_use_id: z6.z.string(),
1705
+ content: z6.z.union([
1706
+ z6.z.array(
1707
+ z6.z.object({
1708
+ type: z6.z.literal("web_search_result"),
1709
+ url: z6.z.string(),
1710
+ title: z6.z.string(),
1711
+ encrypted_content: z6.z.string(),
1712
+ page_age: z6.z.string().nullish()
1713
+ })
1714
+ ),
1715
+ z6.z.object({
1716
+ type: z6.z.literal("web_search_tool_result_error"),
1717
+ error_code: z6.z.string()
1718
+ })
1719
+ ])
1720
+ }),
1721
+ z6.z.object({
1722
+ type: z6.z.literal("code_execution_tool_result"),
1723
+ tool_use_id: z6.z.string(),
1724
+ content: z6.z.union([
1725
+ z6.z.object({
1726
+ type: z6.z.literal("code_execution_result"),
1727
+ stdout: z6.z.string(),
1728
+ stderr: z6.z.string(),
1729
+ return_code: z6.z.number()
1730
+ }),
1731
+ z6.z.object({
1732
+ type: z6.z.literal("code_execution_tool_result_error"),
1733
+ error_code: z6.z.string()
1734
+ })
1735
+ ])
1736
+ })
1737
+ ])
1738
+ }),
1739
+ z6.z.object({
1740
+ type: z6.z.literal("content_block_delta"),
1741
+ index: z6.z.number(),
1742
+ delta: z6.z.discriminatedUnion("type", [
1743
+ z6.z.object({
1744
+ type: z6.z.literal("input_json_delta"),
1745
+ partial_json: z6.z.string()
1746
+ }),
1747
+ z6.z.object({
1748
+ type: z6.z.literal("text_delta"),
1749
+ text: z6.z.string()
1750
+ }),
1751
+ z6.z.object({
1752
+ type: z6.z.literal("thinking_delta"),
1753
+ thinking: z6.z.string()
1754
+ }),
1755
+ z6.z.object({
1756
+ type: z6.z.literal("signature_delta"),
1757
+ signature: z6.z.string()
1758
+ }),
1759
+ z6.z.object({
1760
+ type: z6.z.literal("citations_delta"),
1761
+ citation: citationSchema
1762
+ })
1763
+ ])
1764
+ }),
1765
+ z6.z.object({
1766
+ type: z6.z.literal("content_block_stop"),
1767
+ index: z6.z.number()
1768
+ }),
1769
+ z6.z.object({
1770
+ type: z6.z.literal("error"),
1771
+ error: z6.z.object({
1772
+ type: z6.z.string(),
1773
+ message: z6.z.string()
1774
+ })
1775
+ }),
1776
+ z6.z.object({
1777
+ type: z6.z.literal("message_delta"),
1778
+ delta: z6.z.object({ stop_reason: z6.z.string().nullish() }),
1779
+ usage: z6.z.object({ output_tokens: z6.z.number() })
1780
+ }),
1781
+ z6.z.object({
1782
+ type: z6.z.literal("message_stop")
1783
+ }),
1784
+ z6.z.object({
1785
+ type: z6.z.literal("ping")
1786
+ })
1787
+ ]);
1788
+ var anthropicReasoningMetadataSchema = z6.z.object({
1789
+ signature: z6.z.string().optional(),
1790
+ redactedData: z6.z.string().optional()
1791
+ });
1792
+ var bash_20241022 = chunkHVBBFCDH_cjs.createProviderDefinedToolFactory({
1793
+ id: "anthropic.bash_20241022",
1794
+ name: "bash",
1795
+ inputSchema: z6__default.default.object({
1796
+ command: z6__default.default.string(),
1797
+ restart: z6__default.default.boolean().optional()
1798
+ })
1799
+ });
1800
+ var bash_20250124 = chunkHVBBFCDH_cjs.createProviderDefinedToolFactory({
1801
+ id: "anthropic.bash_20250124",
1802
+ name: "bash",
1803
+ inputSchema: z6__default.default.object({
1804
+ command: z6__default.default.string(),
1805
+ restart: z6__default.default.boolean().optional()
1806
+ })
1807
+ });
1808
+ var computer_20241022 = chunkHVBBFCDH_cjs.createProviderDefinedToolFactory({
1809
+ id: "anthropic.computer_20241022",
1810
+ name: "computer",
1811
+ inputSchema: z6.z.object({
1812
+ action: z6.z.enum([
1813
+ "key",
1814
+ "type",
1815
+ "mouse_move",
1816
+ "left_click",
1817
+ "left_click_drag",
1818
+ "right_click",
1819
+ "middle_click",
1820
+ "double_click",
1821
+ "screenshot",
1822
+ "cursor_position"
1823
+ ]),
1824
+ coordinate: z6.z.array(z6.z.number().int()).optional(),
1825
+ text: z6.z.string().optional()
1826
+ })
1827
+ });
1828
+ var computer_20250124 = chunkHVBBFCDH_cjs.createProviderDefinedToolFactory({
1829
+ id: "anthropic.computer_20250124",
1830
+ name: "computer",
1831
+ inputSchema: z6.z.object({
1832
+ action: z6.z.enum([
1833
+ "key",
1834
+ "hold_key",
1835
+ "type",
1836
+ "cursor_position",
1837
+ "mouse_move",
1838
+ "left_mouse_down",
1839
+ "left_mouse_up",
1840
+ "left_click",
1841
+ "left_click_drag",
1842
+ "right_click",
1843
+ "middle_click",
1844
+ "double_click",
1845
+ "triple_click",
1846
+ "scroll",
1847
+ "wait",
1848
+ "screenshot"
1849
+ ]),
1850
+ coordinate: z6.z.tuple([z6.z.number().int(), z6.z.number().int()]).optional(),
1851
+ duration: z6.z.number().optional(),
1852
+ scroll_amount: z6.z.number().optional(),
1853
+ scroll_direction: z6.z.enum(["up", "down", "left", "right"]).optional(),
1854
+ start_coordinate: z6.z.tuple([z6.z.number().int(), z6.z.number().int()]).optional(),
1855
+ text: z6.z.string().optional()
1856
+ })
1857
+ });
1858
+ var textEditor_20241022 = chunkHVBBFCDH_cjs.createProviderDefinedToolFactory({
1859
+ id: "anthropic.text_editor_20241022",
1860
+ name: "str_replace_editor",
1861
+ inputSchema: z6.z.object({
1862
+ command: z6.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1863
+ path: z6.z.string(),
1864
+ file_text: z6.z.string().optional(),
1865
+ insert_line: z6.z.number().int().optional(),
1866
+ new_str: z6.z.string().optional(),
1867
+ old_str: z6.z.string().optional(),
1868
+ view_range: z6.z.array(z6.z.number().int()).optional()
1869
+ })
1870
+ });
1871
+ var textEditor_20250124 = chunkHVBBFCDH_cjs.createProviderDefinedToolFactory({
1872
+ id: "anthropic.text_editor_20250124",
1873
+ name: "str_replace_editor",
1874
+ inputSchema: z6.z.object({
1875
+ command: z6.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1876
+ path: z6.z.string(),
1877
+ file_text: z6.z.string().optional(),
1878
+ insert_line: z6.z.number().int().optional(),
1879
+ new_str: z6.z.string().optional(),
1880
+ old_str: z6.z.string().optional(),
1881
+ view_range: z6.z.array(z6.z.number().int()).optional()
1882
+ })
1883
+ });
1884
+ var textEditor_20250429 = chunkHVBBFCDH_cjs.createProviderDefinedToolFactory({
1885
+ id: "anthropic.text_editor_20250429",
1886
+ name: "str_replace_based_edit_tool",
1887
+ inputSchema: z6.z.object({
1888
+ command: z6.z.enum(["view", "create", "str_replace", "insert"]),
1889
+ path: z6.z.string(),
1890
+ file_text: z6.z.string().optional(),
1891
+ insert_line: z6.z.number().int().optional(),
1892
+ new_str: z6.z.string().optional(),
1893
+ old_str: z6.z.string().optional(),
1894
+ view_range: z6.z.array(z6.z.number().int()).optional()
1895
+ })
1896
+ });
1897
+ var anthropicTools = {
1898
+ /**
1899
+ * Creates a tool for running a bash command. Must have name "bash".
1900
+ *
1901
+ * Image results are supported.
1902
+ *
1903
+ * @param execute - The function to execute the tool. Optional.
1904
+ */
1905
+ bash_20241022,
1906
+ /**
1907
+ * Creates a tool for running a bash command. Must have name "bash".
1908
+ *
1909
+ * Image results are supported.
1910
+ *
1911
+ * @param execute - The function to execute the tool. Optional.
1912
+ */
1913
+ bash_20250124,
1914
+ /**
1915
+ * Creates a tool for editing text. Must have name "str_replace_editor".
1916
+ */
1917
+ textEditor_20241022,
1918
+ /**
1919
+ * Creates a tool for editing text. Must have name "str_replace_editor".
1920
+ */
1921
+ textEditor_20250124,
1922
+ /**
1923
+ * Creates a tool for editing text. Must have name "str_replace_based_edit_tool".
1924
+ * Note: This version does not support the "undo_edit" command.
1925
+ */
1926
+ textEditor_20250429,
1927
+ /**
1928
+ * Creates a tool for executing actions on a computer. Must have name "computer".
1929
+ *
1930
+ * Image results are supported.
1931
+ *
1932
+ * @param displayWidthPx - The width of the display being controlled by the model in pixels.
1933
+ * @param displayHeightPx - The height of the display being controlled by the model in pixels.
1934
+ * @param displayNumber - The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
1935
+ */
1936
+ computer_20241022,
1937
+ /**
1938
+ * Creates a tool for executing actions on a computer. Must have name "computer".
1939
+ *
1940
+ * Image results are supported.
1941
+ *
1942
+ * @param displayWidthPx - The width of the display being controlled by the model in pixels.
1943
+ * @param displayHeightPx - The height of the display being controlled by the model in pixels.
1944
+ * @param displayNumber - The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
1945
+ * @param execute - The function to execute the tool. Optional.
1946
+ */
1947
+ computer_20250124,
1948
+ /**
1949
+ * Creates a web search tool that gives Claude direct access to real-time web content.
1950
+ * Must have name "web_search".
1951
+ *
1952
+ * @param maxUses - Maximum number of web searches Claude can perform during the conversation.
1953
+ * @param allowedDomains - Optional list of domains that Claude is allowed to search.
1954
+ * @param blockedDomains - Optional list of domains that Claude should avoid when searching.
1955
+ * @param userLocation - Optional user location information to provide geographically relevant search results.
1956
+ */
1957
+ webSearch_20250305,
1958
+ /**
1959
+ * Creates a tool for executing Python code. Must have name "code_execution".
1960
+ */
1961
+ codeExecution_20250522
1962
+ };
1963
+ function createAnthropic(options = {}) {
1964
+ var _a;
1965
+ const baseURL = (_a = chunkHVBBFCDH_cjs.withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
1966
+ const getHeaders = () => ({
1967
+ "anthropic-version": "2023-06-01",
1968
+ "x-api-key": chunkHVBBFCDH_cjs.loadApiKey({
1969
+ apiKey: options.apiKey,
1970
+ environmentVariableName: "ANTHROPIC_API_KEY",
1971
+ description: "Anthropic"
1972
+ }),
1973
+ ...options.headers
1974
+ });
1975
+ const createChatModel = (modelId) => {
1976
+ var _a2;
1977
+ return new AnthropicMessagesLanguageModel(modelId, {
1978
+ provider: "anthropic.messages",
1979
+ baseURL,
1980
+ headers: getHeaders,
1981
+ fetch: options.fetch,
1982
+ generateId: (_a2 = options.generateId) != null ? _a2 : chunkHVBBFCDH_cjs.generateId,
1983
+ supportedUrls: () => ({
1984
+ "image/*": [/^https?:\/\/.*$/]
1985
+ })
1986
+ });
1987
+ };
1988
+ const provider = function(modelId) {
1989
+ if (new.target) {
1990
+ throw new Error(
1991
+ "The Anthropic model function cannot be called with the new keyword."
1992
+ );
1993
+ }
1994
+ return createChatModel(modelId);
1995
+ };
1996
+ provider.languageModel = createChatModel;
1997
+ provider.chat = createChatModel;
1998
+ provider.messages = createChatModel;
1999
+ provider.textEmbeddingModel = (modelId) => {
2000
+ throw new chunkHVBBFCDH_cjs.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
2001
+ };
2002
+ provider.imageModel = (modelId) => {
2003
+ throw new chunkHVBBFCDH_cjs.NoSuchModelError({ modelId, modelType: "imageModel" });
2004
+ };
2005
+ provider.tools = anthropicTools;
2006
+ return provider;
2007
+ }
2008
+ var anthropic = createAnthropic();
2009
+
2010
+ exports.anthropic = anthropic;
2011
+ exports.createAnthropic = createAnthropic;
2012
+ //# sourceMappingURL=chunk-743UIDHI.cjs.map
2013
+ //# sourceMappingURL=chunk-743UIDHI.cjs.map