@mastra/server 0.0.0-remove-cloud-span-transform-20250425214156 → 0.0.0-remove-unused-import-20250909212718

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 (334) hide show
  1. package/CHANGELOG.md +3541 -0
  2. package/LICENSE.md +11 -42
  3. package/README.md +48 -135
  4. package/dist/chunk-3THIIWWW.cjs +484 -0
  5. package/dist/chunk-3THIIWWW.cjs.map +1 -0
  6. package/dist/{chunk-L7XE5QTW.js → chunk-4QCXUEAT.js} +11 -2
  7. package/dist/chunk-4QCXUEAT.js.map +1 -0
  8. package/dist/chunk-4RRMWXQ2.js +3522 -0
  9. package/dist/chunk-4RRMWXQ2.js.map +1 -0
  10. package/dist/chunk-5DP5XZH6.cjs +928 -0
  11. package/dist/chunk-5DP5XZH6.cjs.map +1 -0
  12. package/dist/chunk-5QUKZCEF.js +476 -0
  13. package/dist/chunk-5QUKZCEF.js.map +1 -0
  14. package/dist/chunk-66YYHFGF.js +761 -0
  15. package/dist/chunk-66YYHFGF.js.map +1 -0
  16. package/dist/chunk-6GMFZ5LK.js +2774 -0
  17. package/dist/chunk-6GMFZ5LK.js.map +1 -0
  18. package/dist/chunk-6LUKYSWE.cjs +610 -0
  19. package/dist/chunk-6LUKYSWE.cjs.map +1 -0
  20. package/dist/chunk-743UIDHI.cjs +2013 -0
  21. package/dist/chunk-743UIDHI.cjs.map +1 -0
  22. package/dist/{chunk-FV45V6WC.cjs → chunk-7NADHFD2.cjs} +3 -7
  23. package/dist/chunk-7NADHFD2.cjs.map +1 -0
  24. package/dist/chunk-7QEJ5QG5.js +151 -0
  25. package/dist/chunk-7QEJ5QG5.js.map +1 -0
  26. package/dist/chunk-A3AL7EWJ.js +83 -0
  27. package/dist/chunk-A3AL7EWJ.js.map +1 -0
  28. package/dist/{chunk-Q6SHQECN.js → chunk-A75S4TDD.js} +36 -10
  29. package/dist/chunk-A75S4TDD.js.map +1 -0
  30. package/dist/chunk-AK2FXLLB.cjs +849 -0
  31. package/dist/chunk-AK2FXLLB.cjs.map +1 -0
  32. package/dist/chunk-B2V3PUB7.js +591 -0
  33. package/dist/chunk-B2V3PUB7.js.map +1 -0
  34. package/dist/chunk-CY4TP3FK.js +16 -0
  35. package/dist/chunk-CY4TP3FK.js.map +1 -0
  36. package/dist/chunk-EMMSS5I5.cjs +37 -0
  37. package/dist/chunk-EMMSS5I5.cjs.map +1 -0
  38. package/dist/chunk-EMNGA4R4.js +845 -0
  39. package/dist/chunk-EMNGA4R4.js.map +1 -0
  40. package/dist/chunk-FALVL2VV.cjs +3525 -0
  41. package/dist/chunk-FALVL2VV.cjs.map +1 -0
  42. package/dist/chunk-FQNT7PI4.js +937 -0
  43. package/dist/chunk-FQNT7PI4.js.map +1 -0
  44. package/dist/chunk-G3PMV62Z.js +33 -0
  45. package/dist/chunk-G3PMV62Z.js.map +1 -0
  46. package/dist/chunk-G4PUALCE.cjs +28 -0
  47. package/dist/chunk-G4PUALCE.cjs.map +1 -0
  48. package/dist/chunk-GU4EWMZB.cjs +769 -0
  49. package/dist/chunk-GU4EWMZB.cjs.map +1 -0
  50. package/dist/chunk-GUI3CROV.cjs +159 -0
  51. package/dist/chunk-GUI3CROV.cjs.map +1 -0
  52. package/dist/chunk-HJQKWRKQ.cjs +764 -0
  53. package/dist/chunk-HJQKWRKQ.cjs.map +1 -0
  54. package/dist/chunk-HVBBFCDH.cjs +2321 -0
  55. package/dist/chunk-HVBBFCDH.cjs.map +1 -0
  56. package/dist/chunk-HZJRQ5L3.cjs +1411 -0
  57. package/dist/chunk-HZJRQ5L3.cjs.map +1 -0
  58. package/dist/chunk-IGFMAZZ5.cjs +1150 -0
  59. package/dist/chunk-IGFMAZZ5.cjs.map +1 -0
  60. package/dist/chunk-IOQGI4ML.js +931 -0
  61. package/dist/chunk-IOQGI4ML.js.map +1 -0
  62. package/dist/chunk-IY34NOLA.cjs +150 -0
  63. package/dist/chunk-IY34NOLA.cjs.map +1 -0
  64. package/dist/chunk-J7BPKKOG.cjs +163 -0
  65. package/dist/chunk-J7BPKKOG.cjs.map +1 -0
  66. package/dist/chunk-KNGXRN26.cjs +335 -0
  67. package/dist/chunk-KNGXRN26.cjs.map +1 -0
  68. package/dist/{chunk-WTHDCRMY.js → chunk-KV6VHX4V.js} +33 -8
  69. package/dist/chunk-KV6VHX4V.js.map +1 -0
  70. package/dist/chunk-L265APUD.cjs +69 -0
  71. package/dist/chunk-L265APUD.cjs.map +1 -0
  72. package/dist/chunk-LF2ZLOFP.js +767 -0
  73. package/dist/chunk-LF2ZLOFP.js.map +1 -0
  74. package/dist/chunk-LYPU75T6.js +1147 -0
  75. package/dist/chunk-LYPU75T6.js.map +1 -0
  76. package/dist/chunk-M2YFWHSB.js +455 -0
  77. package/dist/chunk-M2YFWHSB.js.map +1 -0
  78. package/dist/chunk-MLGHQDZZ.js +15671 -0
  79. package/dist/chunk-MLGHQDZZ.js.map +1 -0
  80. package/dist/{chunk-TRDNDNGQ.js → chunk-MMROOK5J.js} +4 -7
  81. package/dist/chunk-MMROOK5J.js.map +1 -0
  82. package/dist/chunk-N7F33WAD.js +2290 -0
  83. package/dist/chunk-N7F33WAD.js.map +1 -0
  84. package/dist/chunk-NG5IVLEZ.js +1012 -0
  85. package/dist/chunk-NG5IVLEZ.js.map +1 -0
  86. package/dist/chunk-OGW6HHVI.js +1408 -0
  87. package/dist/chunk-OGW6HHVI.js.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-7IWQE76Z.cjs → chunk-PWTXZZTR.cjs} +37 -11
  97. package/dist/chunk-PWTXZZTR.cjs.map +1 -0
  98. package/dist/chunk-R7NOGUZG.js +65 -0
  99. package/dist/chunk-R7NOGUZG.js.map +1 -0
  100. package/dist/chunk-RCHEPTZZ.js +2006 -0
  101. package/dist/chunk-RCHEPTZZ.js.map +1 -0
  102. package/dist/chunk-RE4RPXT2.cjs +18 -0
  103. package/dist/chunk-RE4RPXT2.cjs.map +1 -0
  104. package/dist/chunk-RW2D3G4K.cjs +470 -0
  105. package/dist/chunk-RW2D3G4K.cjs.map +1 -0
  106. package/dist/chunk-SIGXR3JT.cjs +1043 -0
  107. package/dist/chunk-SIGXR3JT.cjs.map +1 -0
  108. package/dist/chunk-SPLSYTYW.cjs +88 -0
  109. package/dist/chunk-SPLSYTYW.cjs.map +1 -0
  110. package/dist/chunk-SQY4T6EJ.js +571 -0
  111. package/dist/chunk-SQY4T6EJ.js.map +1 -0
  112. package/dist/{chunk-5JNVY6DU.js → chunk-SYRRSBGL.js} +48 -12
  113. package/dist/chunk-SYRRSBGL.js.map +1 -0
  114. package/dist/{chunk-M56ECCHK.cjs → chunk-T3TIA3O6.cjs} +22 -19
  115. package/dist/chunk-T3TIA3O6.cjs.map +1 -0
  116. package/dist/{chunk-LFOBHRFO.js → chunk-TTHEEIZ3.js} +83 -65
  117. package/dist/chunk-TTHEEIZ3.js.map +1 -0
  118. package/dist/chunk-TVSIG4JE.cjs +940 -0
  119. package/dist/chunk-TVSIG4JE.cjs.map +1 -0
  120. package/dist/{chunk-RE6YL32K.js → chunk-U46VIX2V.js} +54 -30
  121. package/dist/chunk-U46VIX2V.js.map +1 -0
  122. package/dist/{chunk-4JINXASC.js → chunk-WHN4VX55.js} +7 -4
  123. package/dist/chunk-WHN4VX55.js.map +1 -0
  124. package/dist/chunk-WZC6CIVD.cjs +120 -0
  125. package/dist/chunk-WZC6CIVD.cjs.map +1 -0
  126. package/dist/chunk-YITREQVN.cjs +15707 -0
  127. package/dist/chunk-YITREQVN.cjs.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 +2 -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 +2 -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 +32 -0
  185. package/dist/server/handlers/a2a.cjs.map +1 -0
  186. package/dist/server/handlers/a2a.d.ts +68 -0
  187. package/dist/server/handlers/a2a.d.ts.map +1 -0
  188. package/dist/server/handlers/a2a.js +3 -0
  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 +87 -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 +37 -7
  197. package/dist/server/handlers/agents.cjs.map +1 -0
  198. package/dist/server/handlers/agents.d.ts +129 -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 +48 -0
  209. package/dist/server/handlers/legacyWorkflows.cjs.map +1 -0
  210. package/dist/server/handlers/legacyWorkflows.d.ts +59 -0
  211. package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -0
  212. package/dist/server/handlers/legacyWorkflows.js +3 -0
  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/network.cjs +7 -5
  227. package/dist/server/handlers/network.cjs.map +1 -0
  228. package/dist/server/handlers/network.d.ts +50 -4
  229. package/dist/server/handlers/network.d.ts.map +1 -0
  230. package/dist/server/handlers/network.js +3 -1
  231. package/dist/server/handlers/network.js.map +1 -0
  232. package/dist/server/handlers/observability.cjs +16 -0
  233. package/dist/server/handlers/observability.cjs.map +1 -0
  234. package/dist/server/handlers/observability.d.ts +23 -0
  235. package/dist/server/handlers/observability.d.ts.map +1 -0
  236. package/dist/server/handlers/observability.js +3 -0
  237. package/dist/server/handlers/observability.js.map +1 -0
  238. package/dist/server/handlers/scores.cjs +32 -0
  239. package/dist/server/handlers/scores.cjs.map +1 -0
  240. package/dist/server/handlers/scores.d.ts +49 -0
  241. package/dist/server/handlers/scores.d.ts.map +1 -0
  242. package/dist/server/handlers/scores.js +3 -0
  243. package/dist/server/handlers/scores.js.map +1 -0
  244. package/dist/server/handlers/telemetry.cjs +9 -3
  245. package/dist/server/handlers/telemetry.cjs.map +1 -0
  246. package/dist/server/handlers/telemetry.d.ts +33 -2
  247. package/dist/server/handlers/telemetry.d.ts.map +1 -0
  248. package/dist/server/handlers/telemetry.js +3 -1
  249. package/dist/server/handlers/telemetry.js.map +1 -0
  250. package/dist/server/handlers/tools.cjs +11 -5
  251. package/dist/server/handlers/tools.cjs.map +1 -0
  252. package/dist/server/handlers/tools.d.ts +25 -4
  253. package/dist/server/handlers/tools.d.ts.map +1 -0
  254. package/dist/server/handlers/tools.js +3 -1
  255. package/dist/server/handlers/tools.js.map +1 -0
  256. package/dist/server/handlers/utils.cjs +8 -2
  257. package/dist/server/handlers/utils.cjs.map +1 -0
  258. package/dist/server/handlers/utils.d.ts +8 -1
  259. package/dist/server/handlers/utils.d.ts.map +1 -0
  260. package/dist/server/handlers/utils.js +3 -1
  261. package/dist/server/handlers/utils.js.map +1 -0
  262. package/dist/server/handlers/vNextNetwork.cjs +220 -0
  263. package/dist/server/handlers/vNextNetwork.cjs.map +1 -0
  264. package/dist/server/handlers/vNextNetwork.d.ts +179 -0
  265. package/dist/server/handlers/vNextNetwork.d.ts.map +1 -0
  266. package/dist/server/handlers/vNextNetwork.js +213 -0
  267. package/dist/server/handlers/vNextNetwork.js.map +1 -0
  268. package/dist/server/handlers/vector.cjs +9 -7
  269. package/dist/server/handlers/vector.cjs.map +1 -0
  270. package/dist/server/handlers/vector.d.ts +51 -6
  271. package/dist/server/handlers/vector.d.ts.map +1 -0
  272. package/dist/server/handlers/vector.js +3 -1
  273. package/dist/server/handlers/vector.js.map +1 -0
  274. package/dist/server/handlers/voice.cjs +10 -4
  275. package/dist/server/handlers/voice.cjs.map +1 -0
  276. package/dist/server/handlers/voice.d.ts +39 -3
  277. package/dist/server/handlers/voice.d.ts.map +1 -0
  278. package/dist/server/handlers/voice.js +3 -1
  279. package/dist/server/handlers/voice.js.map +1 -0
  280. package/dist/server/handlers/workflows.cjs +35 -13
  281. package/dist/server/handlers/workflows.cjs.map +1 -0
  282. package/dist/server/handlers/workflows.d.ts +73 -10
  283. package/dist/server/handlers/workflows.d.ts.map +1 -0
  284. package/dist/server/handlers/workflows.js +3 -1
  285. package/dist/server/handlers/workflows.js.map +1 -0
  286. package/dist/server/handlers.cjs +52 -30
  287. package/dist/server/handlers.cjs.map +1 -0
  288. package/dist/server/handlers.d.ts +15 -10
  289. package/dist/server/handlers.d.ts.map +1 -0
  290. package/dist/server/handlers.js +16 -10
  291. package/dist/server/handlers.js.map +1 -0
  292. package/dist/server/http-exception.d.ts +87 -0
  293. package/dist/server/http-exception.d.ts.map +1 -0
  294. package/dist/server/types.d.ts +10 -0
  295. package/dist/server/types.d.ts.map +1 -0
  296. package/dist/server/utils.d.ts +42 -0
  297. package/dist/server/utils.d.ts.map +1 -0
  298. package/package.json +51 -19
  299. package/dist/_tsup-dts-rollup.d.cts +0 -648
  300. package/dist/_tsup-dts-rollup.d.ts +0 -648
  301. package/dist/chunk-2FJURXCL.cjs +0 -213
  302. package/dist/chunk-3AHQ5RGN.js +0 -11
  303. package/dist/chunk-3EJZQ6TQ.js +0 -49
  304. package/dist/chunk-55HTWX4C.cjs +0 -93
  305. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  306. package/dist/chunk-B66WVPGJ.js +0 -297
  307. package/dist/chunk-D3G23FP3.cjs +0 -126
  308. package/dist/chunk-FPIWDH5Y.cjs +0 -126
  309. package/dist/chunk-HCOPJZ4A.cjs +0 -164
  310. package/dist/chunk-OMN3UI6X.js +0 -5576
  311. package/dist/chunk-QN4KF3BH.cjs +0 -18
  312. package/dist/chunk-R4J7XQYU.js +0 -156
  313. package/dist/chunk-RBQASTUP.js +0 -203
  314. package/dist/chunk-SKBVVI24.cjs +0 -54
  315. package/dist/chunk-TZK63M5N.cjs +0 -317
  316. package/dist/chunk-ZHNKYTNS.cjs +0 -309
  317. package/dist/chunk-ZLBRQFDD.cjs +0 -13
  318. package/dist/index.d.cts +0 -1
  319. package/dist/server/handlers/agents.d.cts +0 -6
  320. package/dist/server/handlers/error.d.cts +0 -1
  321. package/dist/server/handlers/logs.d.cts +0 -3
  322. package/dist/server/handlers/memory.d.cts +0 -8
  323. package/dist/server/handlers/network.d.cts +0 -4
  324. package/dist/server/handlers/telemetry.d.cts +0 -2
  325. package/dist/server/handlers/tools.d.cts +0 -4
  326. package/dist/server/handlers/utils.d.cts +0 -1
  327. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  328. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  329. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  330. package/dist/server/handlers/vNextWorkflows.js +0 -1
  331. package/dist/server/handlers/vector.d.cts +0 -6
  332. package/dist/server/handlers/voice.d.cts +0 -3
  333. package/dist/server/handlers/workflows.d.cts +0 -10
  334. package/dist/server/handlers.d.cts +0 -10
@@ -0,0 +1,1408 @@
1
+ import { createJsonErrorResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, withoutTrailingSlash, generateId, loadApiKey, parseProviderOptions, combineHeaders, resolve, postJsonToApi, createJsonResponseHandler, createEventSourceResponseHandler, UnsupportedFunctionalityError, convertToBase64, TooManyEmbeddingValuesForCallError } from './chunk-N7F33WAD.js';
2
+ import { z } from 'zod/v4';
3
+
4
+ var googleErrorDataSchema = z.object({
5
+ error: z.object({
6
+ code: z.number().nullable(),
7
+ message: z.string(),
8
+ status: z.string()
9
+ })
10
+ });
11
+ var googleFailedResponseHandler = createJsonErrorResponseHandler({
12
+ errorSchema: googleErrorDataSchema,
13
+ errorToMessage: (data) => data.error.message
14
+ });
15
+ var googleGenerativeAIEmbeddingProviderOptions = z.object({
16
+ /**
17
+ * Optional. Optional reduced dimension for the output embedding.
18
+ * If set, excessive values in the output embedding are truncated from the end.
19
+ */
20
+ outputDimensionality: z.number().optional(),
21
+ /**
22
+ * Optional. Specifies the task type for generating embeddings.
23
+ * Supported task types:
24
+ * - SEMANTIC_SIMILARITY: Optimized for text similarity.
25
+ * - CLASSIFICATION: Optimized for text classification.
26
+ * - CLUSTERING: Optimized for clustering texts based on similarity.
27
+ * - RETRIEVAL_DOCUMENT: Optimized for document retrieval.
28
+ * - RETRIEVAL_QUERY: Optimized for query-based retrieval.
29
+ * - QUESTION_ANSWERING: Optimized for answering questions.
30
+ * - FACT_VERIFICATION: Optimized for verifying factual information.
31
+ * - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
32
+ */
33
+ taskType: z.enum([
34
+ "SEMANTIC_SIMILARITY",
35
+ "CLASSIFICATION",
36
+ "CLUSTERING",
37
+ "RETRIEVAL_DOCUMENT",
38
+ "RETRIEVAL_QUERY",
39
+ "QUESTION_ANSWERING",
40
+ "FACT_VERIFICATION",
41
+ "CODE_RETRIEVAL_QUERY"
42
+ ]).optional()
43
+ });
44
+ var GoogleGenerativeAIEmbeddingModel = class {
45
+ constructor(modelId, config) {
46
+ this.specificationVersion = "v2";
47
+ this.maxEmbeddingsPerCall = 2048;
48
+ this.supportsParallelCalls = true;
49
+ this.modelId = modelId;
50
+ this.config = config;
51
+ }
52
+ get provider() {
53
+ return this.config.provider;
54
+ }
55
+ async doEmbed({
56
+ values,
57
+ headers,
58
+ abortSignal,
59
+ providerOptions
60
+ }) {
61
+ const googleOptions = await parseProviderOptions({
62
+ provider: "google",
63
+ providerOptions,
64
+ schema: googleGenerativeAIEmbeddingProviderOptions
65
+ });
66
+ if (values.length > this.maxEmbeddingsPerCall) {
67
+ throw new TooManyEmbeddingValuesForCallError({
68
+ provider: this.provider,
69
+ modelId: this.modelId,
70
+ maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
71
+ values
72
+ });
73
+ }
74
+ const mergedHeaders = combineHeaders(
75
+ await resolve(this.config.headers),
76
+ headers
77
+ );
78
+ if (values.length === 1) {
79
+ const {
80
+ responseHeaders: responseHeaders2,
81
+ value: response2,
82
+ rawValue: rawValue2
83
+ } = await postJsonToApi({
84
+ url: `${this.config.baseURL}/models/${this.modelId}:embedContent`,
85
+ headers: mergedHeaders,
86
+ body: {
87
+ model: `models/${this.modelId}`,
88
+ content: {
89
+ parts: [{ text: values[0] }]
90
+ },
91
+ outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
92
+ taskType: googleOptions == null ? void 0 : googleOptions.taskType
93
+ },
94
+ failedResponseHandler: googleFailedResponseHandler,
95
+ successfulResponseHandler: createJsonResponseHandler(
96
+ googleGenerativeAISingleEmbeddingResponseSchema
97
+ ),
98
+ abortSignal,
99
+ fetch: this.config.fetch
100
+ });
101
+ return {
102
+ embeddings: [response2.embedding.values],
103
+ usage: void 0,
104
+ response: { headers: responseHeaders2, body: rawValue2 }
105
+ };
106
+ }
107
+ const {
108
+ responseHeaders,
109
+ value: response,
110
+ rawValue
111
+ } = await postJsonToApi({
112
+ url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
113
+ headers: mergedHeaders,
114
+ body: {
115
+ requests: values.map((value) => ({
116
+ model: `models/${this.modelId}`,
117
+ content: { role: "user", parts: [{ text: value }] },
118
+ outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
119
+ taskType: googleOptions == null ? void 0 : googleOptions.taskType
120
+ }))
121
+ },
122
+ failedResponseHandler: googleFailedResponseHandler,
123
+ successfulResponseHandler: createJsonResponseHandler(
124
+ googleGenerativeAITextEmbeddingResponseSchema
125
+ ),
126
+ abortSignal,
127
+ fetch: this.config.fetch
128
+ });
129
+ return {
130
+ embeddings: response.embeddings.map((item) => item.values),
131
+ usage: void 0,
132
+ response: { headers: responseHeaders, body: rawValue }
133
+ };
134
+ }
135
+ };
136
+ var googleGenerativeAITextEmbeddingResponseSchema = z.object({
137
+ embeddings: z.array(z.object({ values: z.array(z.number()) }))
138
+ });
139
+ var googleGenerativeAISingleEmbeddingResponseSchema = z.object({
140
+ embedding: z.object({ values: z.array(z.number()) })
141
+ });
142
+ function convertJSONSchemaToOpenAPISchema(jsonSchema) {
143
+ if (jsonSchema == null || isEmptyObjectSchema(jsonSchema)) {
144
+ return void 0;
145
+ }
146
+ if (typeof jsonSchema === "boolean") {
147
+ return { type: "boolean", properties: {} };
148
+ }
149
+ const {
150
+ type,
151
+ description,
152
+ required,
153
+ properties,
154
+ items,
155
+ allOf,
156
+ anyOf,
157
+ oneOf,
158
+ format,
159
+ const: constValue,
160
+ minLength,
161
+ enum: enumValues
162
+ } = jsonSchema;
163
+ const result = {};
164
+ if (description)
165
+ result.description = description;
166
+ if (required)
167
+ result.required = required;
168
+ if (format)
169
+ result.format = format;
170
+ if (constValue !== void 0) {
171
+ result.enum = [constValue];
172
+ }
173
+ if (type) {
174
+ if (Array.isArray(type)) {
175
+ if (type.includes("null")) {
176
+ result.type = type.filter((t) => t !== "null")[0];
177
+ result.nullable = true;
178
+ } else {
179
+ result.type = type;
180
+ }
181
+ } else if (type === "null") {
182
+ result.type = "null";
183
+ } else {
184
+ result.type = type;
185
+ }
186
+ }
187
+ if (enumValues !== void 0) {
188
+ result.enum = enumValues;
189
+ }
190
+ if (properties != null) {
191
+ result.properties = Object.entries(properties).reduce(
192
+ (acc, [key, value]) => {
193
+ acc[key] = convertJSONSchemaToOpenAPISchema(value);
194
+ return acc;
195
+ },
196
+ {}
197
+ );
198
+ }
199
+ if (items) {
200
+ result.items = Array.isArray(items) ? items.map(convertJSONSchemaToOpenAPISchema) : convertJSONSchemaToOpenAPISchema(items);
201
+ }
202
+ if (allOf) {
203
+ result.allOf = allOf.map(convertJSONSchemaToOpenAPISchema);
204
+ }
205
+ if (anyOf) {
206
+ if (anyOf.some(
207
+ (schema) => typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null"
208
+ )) {
209
+ const nonNullSchemas = anyOf.filter(
210
+ (schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
211
+ );
212
+ if (nonNullSchemas.length === 1) {
213
+ const converted = convertJSONSchemaToOpenAPISchema(nonNullSchemas[0]);
214
+ if (typeof converted === "object") {
215
+ result.nullable = true;
216
+ Object.assign(result, converted);
217
+ }
218
+ } else {
219
+ result.anyOf = nonNullSchemas.map(convertJSONSchemaToOpenAPISchema);
220
+ result.nullable = true;
221
+ }
222
+ } else {
223
+ result.anyOf = anyOf.map(convertJSONSchemaToOpenAPISchema);
224
+ }
225
+ }
226
+ if (oneOf) {
227
+ result.oneOf = oneOf.map(convertJSONSchemaToOpenAPISchema);
228
+ }
229
+ if (minLength !== void 0) {
230
+ result.minLength = minLength;
231
+ }
232
+ return result;
233
+ }
234
+ function isEmptyObjectSchema(jsonSchema) {
235
+ return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
236
+ }
237
+ function convertToGoogleGenerativeAIMessages(prompt, options) {
238
+ var _a;
239
+ const systemInstructionParts = [];
240
+ const contents = [];
241
+ let systemMessagesAllowed = true;
242
+ const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
243
+ for (const { role, content } of prompt) {
244
+ switch (role) {
245
+ case "system": {
246
+ if (!systemMessagesAllowed) {
247
+ throw new UnsupportedFunctionalityError({
248
+ functionality: "system messages are only supported at the beginning of the conversation"
249
+ });
250
+ }
251
+ systemInstructionParts.push({ text: content });
252
+ break;
253
+ }
254
+ case "user": {
255
+ systemMessagesAllowed = false;
256
+ const parts = [];
257
+ for (const part of content) {
258
+ switch (part.type) {
259
+ case "text": {
260
+ parts.push({ text: part.text });
261
+ break;
262
+ }
263
+ case "file": {
264
+ const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
265
+ parts.push(
266
+ part.data instanceof URL ? {
267
+ fileData: {
268
+ mimeType: mediaType,
269
+ fileUri: part.data.toString()
270
+ }
271
+ } : {
272
+ inlineData: {
273
+ mimeType: mediaType,
274
+ data: convertToBase64(part.data)
275
+ }
276
+ }
277
+ );
278
+ break;
279
+ }
280
+ }
281
+ }
282
+ contents.push({ role: "user", parts });
283
+ break;
284
+ }
285
+ case "assistant": {
286
+ systemMessagesAllowed = false;
287
+ contents.push({
288
+ role: "model",
289
+ parts: content.map((part) => {
290
+ var _a2, _b, _c, _d, _e, _f;
291
+ switch (part.type) {
292
+ case "text": {
293
+ return part.text.length === 0 ? void 0 : {
294
+ text: part.text,
295
+ thoughtSignature: (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.thoughtSignature
296
+ };
297
+ }
298
+ case "reasoning": {
299
+ return part.text.length === 0 ? void 0 : {
300
+ text: part.text,
301
+ thought: true,
302
+ thoughtSignature: (_d = (_c = part.providerOptions) == null ? void 0 : _c.google) == null ? void 0 : _d.thoughtSignature
303
+ };
304
+ }
305
+ case "file": {
306
+ if (part.mediaType !== "image/png") {
307
+ throw new UnsupportedFunctionalityError({
308
+ functionality: "Only PNG images are supported in assistant messages"
309
+ });
310
+ }
311
+ if (part.data instanceof URL) {
312
+ throw new UnsupportedFunctionalityError({
313
+ functionality: "File data URLs in assistant messages are not supported"
314
+ });
315
+ }
316
+ return {
317
+ inlineData: {
318
+ mimeType: part.mediaType,
319
+ data: convertToBase64(part.data)
320
+ }
321
+ };
322
+ }
323
+ case "tool-call": {
324
+ return {
325
+ functionCall: {
326
+ name: part.toolName,
327
+ args: part.input
328
+ },
329
+ thoughtSignature: (_f = (_e = part.providerOptions) == null ? void 0 : _e.google) == null ? void 0 : _f.thoughtSignature
330
+ };
331
+ }
332
+ }
333
+ }).filter((part) => part !== void 0)
334
+ });
335
+ break;
336
+ }
337
+ case "tool": {
338
+ systemMessagesAllowed = false;
339
+ contents.push({
340
+ role: "user",
341
+ parts: content.map((part) => ({
342
+ functionResponse: {
343
+ name: part.toolName,
344
+ response: {
345
+ name: part.toolName,
346
+ content: part.output.value
347
+ }
348
+ }
349
+ }))
350
+ });
351
+ break;
352
+ }
353
+ }
354
+ }
355
+ if (isGemmaModel && systemInstructionParts.length > 0 && contents.length > 0 && contents[0].role === "user") {
356
+ const systemText = systemInstructionParts.map((part) => part.text).join("\n\n");
357
+ contents[0].parts.unshift({ text: systemText + "\n\n" });
358
+ }
359
+ return {
360
+ systemInstruction: systemInstructionParts.length > 0 && !isGemmaModel ? { parts: systemInstructionParts } : void 0,
361
+ contents
362
+ };
363
+ }
364
+ function getModelPath(modelId) {
365
+ return modelId.includes("/") ? modelId : `models/${modelId}`;
366
+ }
367
+ var googleGenerativeAIProviderOptions = z.object({
368
+ responseModalities: z.array(z.enum(["TEXT", "IMAGE"])).optional(),
369
+ thinkingConfig: z.object({
370
+ thinkingBudget: z.number().optional(),
371
+ includeThoughts: z.boolean().optional()
372
+ }).optional(),
373
+ /**
374
+ Optional.
375
+ The name of the cached content used as context to serve the prediction.
376
+ Format: cachedContents/{cachedContent}
377
+ */
378
+ cachedContent: z.string().optional(),
379
+ /**
380
+ * Optional. Enable structured output. Default is true.
381
+ *
382
+ * This is useful when the JSON Schema contains elements that are
383
+ * not supported by the OpenAPI schema version that
384
+ * Google Generative AI uses. You can use this to disable
385
+ * structured outputs if you need to.
386
+ */
387
+ structuredOutputs: z.boolean().optional(),
388
+ /**
389
+ Optional. A list of unique safety settings for blocking unsafe content.
390
+ */
391
+ safetySettings: z.array(
392
+ z.object({
393
+ category: z.enum([
394
+ "HARM_CATEGORY_UNSPECIFIED",
395
+ "HARM_CATEGORY_HATE_SPEECH",
396
+ "HARM_CATEGORY_DANGEROUS_CONTENT",
397
+ "HARM_CATEGORY_HARASSMENT",
398
+ "HARM_CATEGORY_SEXUALLY_EXPLICIT",
399
+ "HARM_CATEGORY_CIVIC_INTEGRITY"
400
+ ]),
401
+ threshold: z.enum([
402
+ "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
403
+ "BLOCK_LOW_AND_ABOVE",
404
+ "BLOCK_MEDIUM_AND_ABOVE",
405
+ "BLOCK_ONLY_HIGH",
406
+ "BLOCK_NONE",
407
+ "OFF"
408
+ ])
409
+ })
410
+ ).optional(),
411
+ threshold: z.enum([
412
+ "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
413
+ "BLOCK_LOW_AND_ABOVE",
414
+ "BLOCK_MEDIUM_AND_ABOVE",
415
+ "BLOCK_ONLY_HIGH",
416
+ "BLOCK_NONE",
417
+ "OFF"
418
+ ]).optional(),
419
+ /**
420
+ * Optional. Enables timestamp understanding for audio-only files.
421
+ *
422
+ * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
423
+ */
424
+ audioTimestamp: z.boolean().optional(),
425
+ /**
426
+ * Optional. Defines labels used in billing reports. Available on Vertex AI only.
427
+ *
428
+ * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
429
+ */
430
+ labels: z.record(z.string(), z.string()).optional()
431
+ });
432
+ function prepareTools({
433
+ tools,
434
+ toolChoice,
435
+ modelId
436
+ }) {
437
+ var _a;
438
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
439
+ const toolWarnings = [];
440
+ const isGemini2 = modelId.includes("gemini-2");
441
+ const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
442
+ if (tools == null) {
443
+ return { tools: void 0, toolConfig: void 0, toolWarnings };
444
+ }
445
+ const hasFunctionTools = tools.some((tool) => tool.type === "function");
446
+ const hasProviderDefinedTools = tools.some(
447
+ (tool) => tool.type === "provider-defined"
448
+ );
449
+ if (hasFunctionTools && hasProviderDefinedTools) {
450
+ toolWarnings.push({
451
+ type: "unsupported-tool",
452
+ tool: tools.find((tool) => tool.type === "function"),
453
+ details: "Cannot mix function tools with provider-defined tools in the same request. Please use either function tools or provider-defined tools, but not both."
454
+ });
455
+ }
456
+ if (hasProviderDefinedTools) {
457
+ const googleTools2 = {};
458
+ const providerDefinedTools = tools.filter(
459
+ (tool) => tool.type === "provider-defined"
460
+ );
461
+ providerDefinedTools.forEach((tool) => {
462
+ switch (tool.id) {
463
+ case "google.google_search":
464
+ if (isGemini2) {
465
+ googleTools2.googleSearch = {};
466
+ } else if (supportsDynamicRetrieval) {
467
+ googleTools2.googleSearchRetrieval = {
468
+ dynamicRetrievalConfig: {
469
+ mode: tool.args.mode,
470
+ dynamicThreshold: tool.args.dynamicThreshold
471
+ }
472
+ };
473
+ } else {
474
+ googleTools2.googleSearchRetrieval = {};
475
+ }
476
+ break;
477
+ case "google.url_context":
478
+ if (isGemini2) {
479
+ googleTools2.urlContext = {};
480
+ } else {
481
+ toolWarnings.push({
482
+ type: "unsupported-tool",
483
+ tool,
484
+ details: "The URL context tool is not supported with other Gemini models than Gemini 2."
485
+ });
486
+ }
487
+ break;
488
+ case "google.code_execution":
489
+ if (isGemini2) {
490
+ googleTools2.codeExecution = {};
491
+ } else {
492
+ toolWarnings.push({
493
+ type: "unsupported-tool",
494
+ tool,
495
+ details: "The code execution tools is not supported with other Gemini models than Gemini 2."
496
+ });
497
+ }
498
+ break;
499
+ default:
500
+ toolWarnings.push({ type: "unsupported-tool", tool });
501
+ break;
502
+ }
503
+ });
504
+ return {
505
+ tools: Object.keys(googleTools2).length > 0 ? googleTools2 : void 0,
506
+ toolConfig: void 0,
507
+ toolWarnings
508
+ };
509
+ }
510
+ const functionDeclarations = [];
511
+ for (const tool of tools) {
512
+ switch (tool.type) {
513
+ case "function":
514
+ functionDeclarations.push({
515
+ name: tool.name,
516
+ description: (_a = tool.description) != null ? _a : "",
517
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
518
+ });
519
+ break;
520
+ default:
521
+ toolWarnings.push({ type: "unsupported-tool", tool });
522
+ break;
523
+ }
524
+ }
525
+ if (toolChoice == null) {
526
+ return {
527
+ tools: { functionDeclarations },
528
+ toolConfig: void 0,
529
+ toolWarnings
530
+ };
531
+ }
532
+ const type = toolChoice.type;
533
+ switch (type) {
534
+ case "auto":
535
+ return {
536
+ tools: { functionDeclarations },
537
+ toolConfig: { functionCallingConfig: { mode: "AUTO" } },
538
+ toolWarnings
539
+ };
540
+ case "none":
541
+ return {
542
+ tools: { functionDeclarations },
543
+ toolConfig: { functionCallingConfig: { mode: "NONE" } },
544
+ toolWarnings
545
+ };
546
+ case "required":
547
+ return {
548
+ tools: { functionDeclarations },
549
+ toolConfig: { functionCallingConfig: { mode: "ANY" } },
550
+ toolWarnings
551
+ };
552
+ case "tool":
553
+ return {
554
+ tools: { functionDeclarations },
555
+ toolConfig: {
556
+ functionCallingConfig: {
557
+ mode: "ANY",
558
+ allowedFunctionNames: [toolChoice.toolName]
559
+ }
560
+ },
561
+ toolWarnings
562
+ };
563
+ default: {
564
+ const _exhaustiveCheck = type;
565
+ throw new UnsupportedFunctionalityError({
566
+ functionality: `tool choice type: ${_exhaustiveCheck}`
567
+ });
568
+ }
569
+ }
570
+ }
571
+ function mapGoogleGenerativeAIFinishReason({
572
+ finishReason,
573
+ hasToolCalls
574
+ }) {
575
+ switch (finishReason) {
576
+ case "STOP":
577
+ return hasToolCalls ? "tool-calls" : "stop";
578
+ case "MAX_TOKENS":
579
+ return "length";
580
+ case "IMAGE_SAFETY":
581
+ case "RECITATION":
582
+ case "SAFETY":
583
+ case "BLOCKLIST":
584
+ case "PROHIBITED_CONTENT":
585
+ case "SPII":
586
+ return "content-filter";
587
+ case "FINISH_REASON_UNSPECIFIED":
588
+ case "OTHER":
589
+ return "other";
590
+ case "MALFORMED_FUNCTION_CALL":
591
+ return "error";
592
+ default:
593
+ return "unknown";
594
+ }
595
+ }
596
+ var groundingChunkSchema = z.object({
597
+ web: z.object({ uri: z.string(), title: z.string() }).nullish(),
598
+ retrievedContext: z.object({ uri: z.string(), title: z.string() }).nullish()
599
+ });
600
+ var groundingMetadataSchema = z.object({
601
+ webSearchQueries: z.array(z.string()).nullish(),
602
+ retrievalQueries: z.array(z.string()).nullish(),
603
+ searchEntryPoint: z.object({ renderedContent: z.string() }).nullish(),
604
+ groundingChunks: z.array(groundingChunkSchema).nullish(),
605
+ groundingSupports: z.array(
606
+ z.object({
607
+ segment: z.object({
608
+ startIndex: z.number().nullish(),
609
+ endIndex: z.number().nullish(),
610
+ text: z.string().nullish()
611
+ }),
612
+ segment_text: z.string().nullish(),
613
+ groundingChunkIndices: z.array(z.number()).nullish(),
614
+ supportChunkIndices: z.array(z.number()).nullish(),
615
+ confidenceScores: z.array(z.number()).nullish(),
616
+ confidenceScore: z.array(z.number()).nullish()
617
+ })
618
+ ).nullish(),
619
+ retrievalMetadata: z.union([
620
+ z.object({
621
+ webDynamicRetrievalScore: z.number()
622
+ }),
623
+ z.object({})
624
+ ]).nullish()
625
+ });
626
+ var googleSearch = createProviderDefinedToolFactory({
627
+ id: "google.google_search",
628
+ name: "google_search",
629
+ inputSchema: z.object({
630
+ mode: z.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
631
+ dynamicThreshold: z.number().default(1)
632
+ })
633
+ });
634
+ var urlMetadataSchema = z.object({
635
+ retrievedUrl: z.string(),
636
+ urlRetrievalStatus: z.string()
637
+ });
638
+ var urlContextMetadataSchema = z.object({
639
+ urlMetadata: z.array(urlMetadataSchema)
640
+ });
641
+ var urlContext = createProviderDefinedToolFactory({
642
+ id: "google.url_context",
643
+ name: "url_context",
644
+ inputSchema: z.object({})
645
+ });
646
+ var GoogleGenerativeAILanguageModel = class {
647
+ constructor(modelId, config) {
648
+ this.specificationVersion = "v2";
649
+ var _a;
650
+ this.modelId = modelId;
651
+ this.config = config;
652
+ this.generateId = (_a = config.generateId) != null ? _a : generateId;
653
+ }
654
+ get provider() {
655
+ return this.config.provider;
656
+ }
657
+ get supportedUrls() {
658
+ var _a, _b, _c;
659
+ return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
660
+ }
661
+ async getArgs({
662
+ prompt,
663
+ maxOutputTokens,
664
+ temperature,
665
+ topP,
666
+ topK,
667
+ frequencyPenalty,
668
+ presencePenalty,
669
+ stopSequences,
670
+ responseFormat,
671
+ seed,
672
+ tools,
673
+ toolChoice,
674
+ providerOptions
675
+ }) {
676
+ var _a, _b;
677
+ const warnings = [];
678
+ const googleOptions = await parseProviderOptions({
679
+ provider: "google",
680
+ providerOptions,
681
+ schema: googleGenerativeAIProviderOptions
682
+ });
683
+ if (((_a = googleOptions == null ? void 0 : googleOptions.thinkingConfig) == null ? void 0 : _a.includeThoughts) === true && !this.config.provider.startsWith("google.vertex.")) {
684
+ warnings.push({
685
+ type: "other",
686
+ message: `The 'includeThoughts' option is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
687
+ });
688
+ }
689
+ const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
690
+ const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
691
+ prompt,
692
+ { isGemmaModel }
693
+ );
694
+ const {
695
+ tools: googleTools2,
696
+ toolConfig: googleToolConfig,
697
+ toolWarnings
698
+ } = prepareTools({
699
+ tools,
700
+ toolChoice,
701
+ modelId: this.modelId
702
+ });
703
+ return {
704
+ args: {
705
+ generationConfig: {
706
+ // standardized settings:
707
+ maxOutputTokens,
708
+ temperature,
709
+ topK,
710
+ topP,
711
+ frequencyPenalty,
712
+ presencePenalty,
713
+ stopSequences,
714
+ seed,
715
+ // response format:
716
+ responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
717
+ responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
718
+ // so this is needed as an escape hatch:
719
+ // TODO convert into provider option
720
+ ((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
721
+ ...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
722
+ audioTimestamp: googleOptions.audioTimestamp
723
+ },
724
+ // provider options:
725
+ responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
726
+ thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig
727
+ },
728
+ contents,
729
+ systemInstruction: isGemmaModel ? void 0 : systemInstruction,
730
+ safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
731
+ tools: googleTools2,
732
+ toolConfig: googleToolConfig,
733
+ cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
734
+ labels: googleOptions == null ? void 0 : googleOptions.labels
735
+ },
736
+ warnings: [...warnings, ...toolWarnings]
737
+ };
738
+ }
739
+ async doGenerate(options) {
740
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
741
+ const { args, warnings } = await this.getArgs(options);
742
+ const body = JSON.stringify(args);
743
+ const mergedHeaders = combineHeaders(
744
+ await resolve(this.config.headers),
745
+ options.headers
746
+ );
747
+ const {
748
+ responseHeaders,
749
+ value: response,
750
+ rawValue: rawResponse
751
+ } = await postJsonToApi({
752
+ url: `${this.config.baseURL}/${getModelPath(
753
+ this.modelId
754
+ )}:generateContent`,
755
+ headers: mergedHeaders,
756
+ body: args,
757
+ failedResponseHandler: googleFailedResponseHandler,
758
+ successfulResponseHandler: createJsonResponseHandler(responseSchema),
759
+ abortSignal: options.abortSignal,
760
+ fetch: this.config.fetch
761
+ });
762
+ const candidate = response.candidates[0];
763
+ const content = [];
764
+ const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
765
+ const usageMetadata = response.usageMetadata;
766
+ let lastCodeExecutionToolCallId;
767
+ for (const part of parts) {
768
+ if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
769
+ const toolCallId = this.config.generateId();
770
+ lastCodeExecutionToolCallId = toolCallId;
771
+ content.push({
772
+ type: "tool-call",
773
+ toolCallId,
774
+ toolName: "code_execution",
775
+ input: JSON.stringify(part.executableCode),
776
+ providerExecuted: true
777
+ });
778
+ } else if ("codeExecutionResult" in part && part.codeExecutionResult) {
779
+ content.push({
780
+ type: "tool-result",
781
+ // Assumes a result directly follows its corresponding call part.
782
+ toolCallId: lastCodeExecutionToolCallId,
783
+ toolName: "code_execution",
784
+ result: {
785
+ outcome: part.codeExecutionResult.outcome,
786
+ output: part.codeExecutionResult.output
787
+ },
788
+ providerExecuted: true
789
+ });
790
+ lastCodeExecutionToolCallId = void 0;
791
+ } else if ("text" in part && part.text != null && part.text.length > 0) {
792
+ content.push({
793
+ type: part.thought === true ? "reasoning" : "text",
794
+ text: part.text,
795
+ providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
796
+ });
797
+ } else if ("functionCall" in part) {
798
+ content.push({
799
+ type: "tool-call",
800
+ toolCallId: this.config.generateId(),
801
+ toolName: part.functionCall.name,
802
+ input: JSON.stringify(part.functionCall.args),
803
+ providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
804
+ });
805
+ } else if ("inlineData" in part) {
806
+ content.push({
807
+ type: "file",
808
+ data: part.inlineData.data,
809
+ mediaType: part.inlineData.mimeType
810
+ });
811
+ }
812
+ }
813
+ const sources = (_d = extractSources({
814
+ groundingMetadata: candidate.groundingMetadata,
815
+ generateId: this.config.generateId
816
+ })) != null ? _d : [];
817
+ for (const source of sources) {
818
+ content.push(source);
819
+ }
820
+ return {
821
+ content,
822
+ finishReason: mapGoogleGenerativeAIFinishReason({
823
+ finishReason: candidate.finishReason,
824
+ hasToolCalls: content.some((part) => part.type === "tool-call")
825
+ }),
826
+ usage: {
827
+ inputTokens: (_e = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _e : void 0,
828
+ outputTokens: (_f = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _f : void 0,
829
+ totalTokens: (_g = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _g : void 0,
830
+ reasoningTokens: (_h = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _h : void 0,
831
+ cachedInputTokens: (_i = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _i : void 0
832
+ },
833
+ warnings,
834
+ providerMetadata: {
835
+ google: {
836
+ groundingMetadata: (_j = candidate.groundingMetadata) != null ? _j : null,
837
+ urlContextMetadata: (_k = candidate.urlContextMetadata) != null ? _k : null,
838
+ safetyRatings: (_l = candidate.safetyRatings) != null ? _l : null,
839
+ usageMetadata: usageMetadata != null ? usageMetadata : null
840
+ }
841
+ },
842
+ request: { body },
843
+ response: {
844
+ // TODO timestamp, model id, id
845
+ headers: responseHeaders,
846
+ body: rawResponse
847
+ }
848
+ };
849
+ }
850
+ async doStream(options) {
851
+ const { args, warnings } = await this.getArgs(options);
852
+ const body = JSON.stringify(args);
853
+ const headers = combineHeaders(
854
+ await resolve(this.config.headers),
855
+ options.headers
856
+ );
857
+ const { responseHeaders, value: response } = await postJsonToApi({
858
+ url: `${this.config.baseURL}/${getModelPath(
859
+ this.modelId
860
+ )}:streamGenerateContent?alt=sse`,
861
+ headers,
862
+ body: args,
863
+ failedResponseHandler: googleFailedResponseHandler,
864
+ successfulResponseHandler: createEventSourceResponseHandler(chunkSchema),
865
+ abortSignal: options.abortSignal,
866
+ fetch: this.config.fetch
867
+ });
868
+ let finishReason = "unknown";
869
+ const usage = {
870
+ inputTokens: void 0,
871
+ outputTokens: void 0,
872
+ totalTokens: void 0
873
+ };
874
+ let providerMetadata = void 0;
875
+ const generateId3 = this.config.generateId;
876
+ let hasToolCalls = false;
877
+ let currentTextBlockId = null;
878
+ let currentReasoningBlockId = null;
879
+ let blockCounter = 0;
880
+ const emittedSourceUrls = /* @__PURE__ */ new Set();
881
+ let lastCodeExecutionToolCallId;
882
+ return {
883
+ stream: response.pipeThrough(
884
+ new TransformStream({
885
+ start(controller) {
886
+ controller.enqueue({ type: "stream-start", warnings });
887
+ },
888
+ transform(chunk, controller) {
889
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
890
+ if (options.includeRawChunks) {
891
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
892
+ }
893
+ if (!chunk.success) {
894
+ controller.enqueue({ type: "error", error: chunk.error });
895
+ return;
896
+ }
897
+ const value = chunk.value;
898
+ const usageMetadata = value.usageMetadata;
899
+ if (usageMetadata != null) {
900
+ usage.inputTokens = (_a = usageMetadata.promptTokenCount) != null ? _a : void 0;
901
+ usage.outputTokens = (_b = usageMetadata.candidatesTokenCount) != null ? _b : void 0;
902
+ usage.totalTokens = (_c = usageMetadata.totalTokenCount) != null ? _c : void 0;
903
+ usage.reasoningTokens = (_d = usageMetadata.thoughtsTokenCount) != null ? _d : void 0;
904
+ usage.cachedInputTokens = (_e = usageMetadata.cachedContentTokenCount) != null ? _e : void 0;
905
+ }
906
+ const candidate = (_f = value.candidates) == null ? void 0 : _f[0];
907
+ if (candidate == null) {
908
+ return;
909
+ }
910
+ const content = candidate.content;
911
+ const sources = extractSources({
912
+ groundingMetadata: candidate.groundingMetadata,
913
+ generateId: generateId3
914
+ });
915
+ if (sources != null) {
916
+ for (const source of sources) {
917
+ if (source.sourceType === "url" && !emittedSourceUrls.has(source.url)) {
918
+ emittedSourceUrls.add(source.url);
919
+ controller.enqueue(source);
920
+ }
921
+ }
922
+ }
923
+ if (content != null) {
924
+ const parts = (_g = content.parts) != null ? _g : [];
925
+ for (const part of parts) {
926
+ if ("executableCode" in part && ((_h = part.executableCode) == null ? void 0 : _h.code)) {
927
+ const toolCallId = generateId3();
928
+ lastCodeExecutionToolCallId = toolCallId;
929
+ controller.enqueue({
930
+ type: "tool-call",
931
+ toolCallId,
932
+ toolName: "code_execution",
933
+ input: JSON.stringify(part.executableCode),
934
+ providerExecuted: true
935
+ });
936
+ hasToolCalls = true;
937
+ } else if ("codeExecutionResult" in part && part.codeExecutionResult) {
938
+ const toolCallId = lastCodeExecutionToolCallId;
939
+ if (toolCallId) {
940
+ controller.enqueue({
941
+ type: "tool-result",
942
+ toolCallId,
943
+ toolName: "code_execution",
944
+ result: {
945
+ outcome: part.codeExecutionResult.outcome,
946
+ output: part.codeExecutionResult.output
947
+ },
948
+ providerExecuted: true
949
+ });
950
+ lastCodeExecutionToolCallId = void 0;
951
+ }
952
+ } else if ("text" in part && part.text != null && part.text.length > 0) {
953
+ if (part.thought === true) {
954
+ if (currentTextBlockId !== null) {
955
+ controller.enqueue({
956
+ type: "text-end",
957
+ id: currentTextBlockId
958
+ });
959
+ currentTextBlockId = null;
960
+ }
961
+ if (currentReasoningBlockId === null) {
962
+ currentReasoningBlockId = String(blockCounter++);
963
+ controller.enqueue({
964
+ type: "reasoning-start",
965
+ id: currentReasoningBlockId,
966
+ providerMetadata: part.thoughtSignature ? {
967
+ google: {
968
+ thoughtSignature: part.thoughtSignature
969
+ }
970
+ } : void 0
971
+ });
972
+ }
973
+ controller.enqueue({
974
+ type: "reasoning-delta",
975
+ id: currentReasoningBlockId,
976
+ delta: part.text,
977
+ providerMetadata: part.thoughtSignature ? {
978
+ google: { thoughtSignature: part.thoughtSignature }
979
+ } : void 0
980
+ });
981
+ } else {
982
+ if (currentReasoningBlockId !== null) {
983
+ controller.enqueue({
984
+ type: "reasoning-end",
985
+ id: currentReasoningBlockId
986
+ });
987
+ currentReasoningBlockId = null;
988
+ }
989
+ if (currentTextBlockId === null) {
990
+ currentTextBlockId = String(blockCounter++);
991
+ controller.enqueue({
992
+ type: "text-start",
993
+ id: currentTextBlockId,
994
+ providerMetadata: part.thoughtSignature ? {
995
+ google: {
996
+ thoughtSignature: part.thoughtSignature
997
+ }
998
+ } : void 0
999
+ });
1000
+ }
1001
+ controller.enqueue({
1002
+ type: "text-delta",
1003
+ id: currentTextBlockId,
1004
+ delta: part.text,
1005
+ providerMetadata: part.thoughtSignature ? {
1006
+ google: { thoughtSignature: part.thoughtSignature }
1007
+ } : void 0
1008
+ });
1009
+ }
1010
+ }
1011
+ }
1012
+ const inlineDataParts = getInlineDataParts(content.parts);
1013
+ if (inlineDataParts != null) {
1014
+ for (const part of inlineDataParts) {
1015
+ controller.enqueue({
1016
+ type: "file",
1017
+ mediaType: part.inlineData.mimeType,
1018
+ data: part.inlineData.data
1019
+ });
1020
+ }
1021
+ }
1022
+ const toolCallDeltas = getToolCallsFromParts({
1023
+ parts: content.parts,
1024
+ generateId: generateId3
1025
+ });
1026
+ if (toolCallDeltas != null) {
1027
+ for (const toolCall of toolCallDeltas) {
1028
+ controller.enqueue({
1029
+ type: "tool-input-start",
1030
+ id: toolCall.toolCallId,
1031
+ toolName: toolCall.toolName,
1032
+ providerMetadata: toolCall.providerMetadata
1033
+ });
1034
+ controller.enqueue({
1035
+ type: "tool-input-delta",
1036
+ id: toolCall.toolCallId,
1037
+ delta: toolCall.args,
1038
+ providerMetadata: toolCall.providerMetadata
1039
+ });
1040
+ controller.enqueue({
1041
+ type: "tool-input-end",
1042
+ id: toolCall.toolCallId,
1043
+ providerMetadata: toolCall.providerMetadata
1044
+ });
1045
+ controller.enqueue({
1046
+ type: "tool-call",
1047
+ toolCallId: toolCall.toolCallId,
1048
+ toolName: toolCall.toolName,
1049
+ input: toolCall.args,
1050
+ providerMetadata: toolCall.providerMetadata
1051
+ });
1052
+ hasToolCalls = true;
1053
+ }
1054
+ }
1055
+ }
1056
+ if (candidate.finishReason != null) {
1057
+ finishReason = mapGoogleGenerativeAIFinishReason({
1058
+ finishReason: candidate.finishReason,
1059
+ hasToolCalls
1060
+ });
1061
+ providerMetadata = {
1062
+ google: {
1063
+ groundingMetadata: (_i = candidate.groundingMetadata) != null ? _i : null,
1064
+ urlContextMetadata: (_j = candidate.urlContextMetadata) != null ? _j : null,
1065
+ safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null
1066
+ }
1067
+ };
1068
+ if (usageMetadata != null) {
1069
+ providerMetadata.google.usageMetadata = usageMetadata;
1070
+ }
1071
+ }
1072
+ },
1073
+ flush(controller) {
1074
+ if (currentTextBlockId !== null) {
1075
+ controller.enqueue({
1076
+ type: "text-end",
1077
+ id: currentTextBlockId
1078
+ });
1079
+ }
1080
+ if (currentReasoningBlockId !== null) {
1081
+ controller.enqueue({
1082
+ type: "reasoning-end",
1083
+ id: currentReasoningBlockId
1084
+ });
1085
+ }
1086
+ controller.enqueue({
1087
+ type: "finish",
1088
+ finishReason,
1089
+ usage,
1090
+ providerMetadata
1091
+ });
1092
+ }
1093
+ })
1094
+ ),
1095
+ response: { headers: responseHeaders },
1096
+ request: { body }
1097
+ };
1098
+ }
1099
+ };
1100
+ function getToolCallsFromParts({
1101
+ parts,
1102
+ generateId: generateId3
1103
+ }) {
1104
+ const functionCallParts = parts == null ? void 0 : parts.filter(
1105
+ (part) => "functionCall" in part
1106
+ );
1107
+ return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
1108
+ type: "tool-call",
1109
+ toolCallId: generateId3(),
1110
+ toolName: part.functionCall.name,
1111
+ args: JSON.stringify(part.functionCall.args),
1112
+ providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
1113
+ }));
1114
+ }
1115
+ function getInlineDataParts(parts) {
1116
+ return parts == null ? void 0 : parts.filter(
1117
+ (part) => "inlineData" in part
1118
+ );
1119
+ }
1120
+ function extractSources({
1121
+ groundingMetadata,
1122
+ generateId: generateId3
1123
+ }) {
1124
+ var _a;
1125
+ return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
1126
+ (chunk) => chunk.web != null
1127
+ ).map((chunk) => ({
1128
+ type: "source",
1129
+ sourceType: "url",
1130
+ id: generateId3(),
1131
+ url: chunk.web.uri,
1132
+ title: chunk.web.title
1133
+ }));
1134
+ }
1135
+ var contentSchema = z.object({
1136
+ parts: z.array(
1137
+ z.union([
1138
+ // note: order matters since text can be fully empty
1139
+ z.object({
1140
+ functionCall: z.object({
1141
+ name: z.string(),
1142
+ args: z.unknown()
1143
+ }),
1144
+ thoughtSignature: z.string().nullish()
1145
+ }),
1146
+ z.object({
1147
+ inlineData: z.object({
1148
+ mimeType: z.string(),
1149
+ data: z.string()
1150
+ })
1151
+ }),
1152
+ z.object({
1153
+ executableCode: z.object({
1154
+ language: z.string(),
1155
+ code: z.string()
1156
+ }).nullish(),
1157
+ codeExecutionResult: z.object({
1158
+ outcome: z.string(),
1159
+ output: z.string()
1160
+ }).nullish(),
1161
+ text: z.string().nullish(),
1162
+ thought: z.boolean().nullish(),
1163
+ thoughtSignature: z.string().nullish()
1164
+ })
1165
+ ])
1166
+ ).nullish()
1167
+ });
1168
+ var safetyRatingSchema = z.object({
1169
+ category: z.string().nullish(),
1170
+ probability: z.string().nullish(),
1171
+ probabilityScore: z.number().nullish(),
1172
+ severity: z.string().nullish(),
1173
+ severityScore: z.number().nullish(),
1174
+ blocked: z.boolean().nullish()
1175
+ });
1176
+ var usageSchema = z.object({
1177
+ cachedContentTokenCount: z.number().nullish(),
1178
+ thoughtsTokenCount: z.number().nullish(),
1179
+ promptTokenCount: z.number().nullish(),
1180
+ candidatesTokenCount: z.number().nullish(),
1181
+ totalTokenCount: z.number().nullish()
1182
+ });
1183
+ var responseSchema = z.object({
1184
+ candidates: z.array(
1185
+ z.object({
1186
+ content: contentSchema.nullish().or(z.object({}).strict()),
1187
+ finishReason: z.string().nullish(),
1188
+ safetyRatings: z.array(safetyRatingSchema).nullish(),
1189
+ groundingMetadata: groundingMetadataSchema.nullish(),
1190
+ urlContextMetadata: urlContextMetadataSchema.nullish()
1191
+ })
1192
+ ),
1193
+ usageMetadata: usageSchema.nullish()
1194
+ });
1195
+ var chunkSchema = z.object({
1196
+ candidates: z.array(
1197
+ z.object({
1198
+ content: contentSchema.nullish(),
1199
+ finishReason: z.string().nullish(),
1200
+ safetyRatings: z.array(safetyRatingSchema).nullish(),
1201
+ groundingMetadata: groundingMetadataSchema.nullish(),
1202
+ urlContextMetadata: urlContextMetadataSchema.nullish()
1203
+ })
1204
+ ).nullish(),
1205
+ usageMetadata: usageSchema.nullish()
1206
+ });
1207
+ var codeExecution = createProviderDefinedToolFactoryWithOutputSchema({
1208
+ id: "google.code_execution",
1209
+ name: "code_execution",
1210
+ inputSchema: z.object({
1211
+ language: z.string().describe("The programming language of the code."),
1212
+ code: z.string().describe("The code to be executed.")
1213
+ }),
1214
+ outputSchema: z.object({
1215
+ outcome: z.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
1216
+ output: z.string().describe("The output from the code execution.")
1217
+ })
1218
+ });
1219
+ var googleTools = {
1220
+ /**
1221
+ * Creates a Google search tool that gives Google direct access to real-time web content.
1222
+ * Must have name "google_search".
1223
+ */
1224
+ googleSearch,
1225
+ /**
1226
+ * Creates a URL context tool that gives Google direct access to real-time web content.
1227
+ * Must have name "url_context".
1228
+ */
1229
+ urlContext,
1230
+ /**
1231
+ * A tool that enables the model to generate and run Python code.
1232
+ * Must have name "code_execution".
1233
+ *
1234
+ * @note Ensure the selected model supports Code Execution.
1235
+ * Multi-tool usage with the code execution tool is typically compatible with Gemini >=2 models.
1236
+ *
1237
+ * @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
1238
+ * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
1239
+ */
1240
+ codeExecution
1241
+ };
1242
+ var GoogleGenerativeAIImageModel = class {
1243
+ constructor(modelId, settings, config) {
1244
+ this.modelId = modelId;
1245
+ this.settings = settings;
1246
+ this.config = config;
1247
+ this.specificationVersion = "v2";
1248
+ }
1249
+ get maxImagesPerCall() {
1250
+ var _a;
1251
+ return (_a = this.settings.maxImagesPerCall) != null ? _a : 4;
1252
+ }
1253
+ get provider() {
1254
+ return this.config.provider;
1255
+ }
1256
+ async doGenerate(options) {
1257
+ var _a, _b, _c;
1258
+ const {
1259
+ prompt,
1260
+ n = 1,
1261
+ size = "1024x1024",
1262
+ aspectRatio = "1:1",
1263
+ seed,
1264
+ providerOptions,
1265
+ headers,
1266
+ abortSignal
1267
+ } = options;
1268
+ const warnings = [];
1269
+ if (size != null) {
1270
+ warnings.push({
1271
+ type: "unsupported-setting",
1272
+ setting: "size",
1273
+ details: "This model does not support the `size` option. Use `aspectRatio` instead."
1274
+ });
1275
+ }
1276
+ if (seed != null) {
1277
+ warnings.push({
1278
+ type: "unsupported-setting",
1279
+ setting: "seed",
1280
+ details: "This model does not support the `seed` option through this provider."
1281
+ });
1282
+ }
1283
+ const googleOptions = await parseProviderOptions({
1284
+ provider: "google",
1285
+ providerOptions,
1286
+ schema: googleImageProviderOptionsSchema
1287
+ });
1288
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1289
+ const parameters = {
1290
+ sampleCount: n
1291
+ };
1292
+ if (aspectRatio != null) {
1293
+ parameters.aspectRatio = aspectRatio;
1294
+ }
1295
+ if (googleOptions) {
1296
+ Object.assign(parameters, googleOptions);
1297
+ }
1298
+ const body = {
1299
+ instances: [{ prompt }],
1300
+ parameters
1301
+ };
1302
+ const { responseHeaders, value: response } = await postJsonToApi({
1303
+ url: `${this.config.baseURL}/models/${this.modelId}:predict`,
1304
+ headers: combineHeaders(await resolve(this.config.headers), headers),
1305
+ body,
1306
+ failedResponseHandler: googleFailedResponseHandler,
1307
+ successfulResponseHandler: createJsonResponseHandler(
1308
+ googleImageResponseSchema
1309
+ ),
1310
+ abortSignal,
1311
+ fetch: this.config.fetch
1312
+ });
1313
+ return {
1314
+ images: response.predictions.map(
1315
+ (p) => p.bytesBase64Encoded
1316
+ ),
1317
+ warnings: warnings != null ? warnings : [],
1318
+ providerMetadata: {
1319
+ google: {
1320
+ images: response.predictions.map((prediction) => ({
1321
+ // Add any prediction-specific metadata here
1322
+ }))
1323
+ }
1324
+ },
1325
+ response: {
1326
+ timestamp: currentDate,
1327
+ modelId: this.modelId,
1328
+ headers: responseHeaders
1329
+ }
1330
+ };
1331
+ }
1332
+ };
1333
+ var googleImageResponseSchema = z.object({
1334
+ predictions: z.array(z.object({ bytesBase64Encoded: z.string() })).default([])
1335
+ });
1336
+ var googleImageProviderOptionsSchema = z.object({
1337
+ personGeneration: z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
1338
+ aspectRatio: z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
1339
+ });
1340
+ function createGoogleGenerativeAI(options = {}) {
1341
+ var _a;
1342
+ const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
1343
+ const getHeaders = () => ({
1344
+ "x-goog-api-key": loadApiKey({
1345
+ apiKey: options.apiKey,
1346
+ environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
1347
+ description: "Google Generative AI"
1348
+ }),
1349
+ ...options.headers
1350
+ });
1351
+ const createChatModel = (modelId) => {
1352
+ var _a2;
1353
+ return new GoogleGenerativeAILanguageModel(modelId, {
1354
+ provider: "google.generative-ai",
1355
+ baseURL,
1356
+ headers: getHeaders,
1357
+ generateId: (_a2 = options.generateId) != null ? _a2 : generateId,
1358
+ supportedUrls: () => ({
1359
+ "*": [
1360
+ // Google Generative Language "files" endpoint
1361
+ // e.g. https://generativelanguage.googleapis.com/v1beta/files/...
1362
+ new RegExp(`^${baseURL}/files/.*$`),
1363
+ // YouTube URLs (public or unlisted videos)
1364
+ new RegExp(
1365
+ `^https://(?:www\\.)?youtube\\.com/watch\\?v=[\\w-]+(?:&[\\w=&.-]*)?$`
1366
+ ),
1367
+ new RegExp(`^https://youtu\\.be/[\\w-]+(?:\\?[\\w=&.-]*)?$`)
1368
+ ]
1369
+ }),
1370
+ fetch: options.fetch
1371
+ });
1372
+ };
1373
+ const createEmbeddingModel = (modelId) => new GoogleGenerativeAIEmbeddingModel(modelId, {
1374
+ provider: "google.generative-ai",
1375
+ baseURL,
1376
+ headers: getHeaders,
1377
+ fetch: options.fetch
1378
+ });
1379
+ const createImageModel = (modelId, settings = {}) => new GoogleGenerativeAIImageModel(modelId, settings, {
1380
+ provider: "google.generative-ai",
1381
+ baseURL,
1382
+ headers: getHeaders,
1383
+ fetch: options.fetch
1384
+ });
1385
+ const provider = function(modelId) {
1386
+ if (new.target) {
1387
+ throw new Error(
1388
+ "The Google Generative AI model function cannot be called with the new keyword."
1389
+ );
1390
+ }
1391
+ return createChatModel(modelId);
1392
+ };
1393
+ provider.languageModel = createChatModel;
1394
+ provider.chat = createChatModel;
1395
+ provider.generativeAI = createChatModel;
1396
+ provider.embedding = createEmbeddingModel;
1397
+ provider.textEmbedding = createEmbeddingModel;
1398
+ provider.textEmbeddingModel = createEmbeddingModel;
1399
+ provider.image = createImageModel;
1400
+ provider.imageModel = createImageModel;
1401
+ provider.tools = googleTools;
1402
+ return provider;
1403
+ }
1404
+ var google = createGoogleGenerativeAI();
1405
+
1406
+ export { createGoogleGenerativeAI, google };
1407
+ //# sourceMappingURL=chunk-OGW6HHVI.js.map
1408
+ //# sourceMappingURL=chunk-OGW6HHVI.js.map