@mastra/server 0.0.0-vector-sources-20250516175436 → 0.0.0-vector-extension-schema-20250922130418

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 (333) hide show
  1. package/CHANGELOG.md +3745 -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-57HWW2TY.cjs +587 -0
  9. package/dist/chunk-57HWW2TY.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-743UIDHI.cjs +2013 -0
  17. package/dist/chunk-743UIDHI.cjs.map +1 -0
  18. package/dist/chunk-7JYXPDM4.js +15712 -0
  19. package/dist/chunk-7JYXPDM4.js.map +1 -0
  20. package/dist/{chunk-OCWPVYNI.cjs → chunk-7NADHFD2.cjs} +3 -0
  21. package/dist/chunk-7NADHFD2.cjs.map +1 -0
  22. package/dist/chunk-7QEJ5QG5.js +151 -0
  23. package/dist/chunk-7QEJ5QG5.js.map +1 -0
  24. package/dist/chunk-A3AL7EWJ.js +83 -0
  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-5SN4U5AC.cjs → chunk-AVEPEUN4.cjs} +115 -138
  29. package/dist/chunk-AVEPEUN4.cjs.map +1 -0
  30. package/dist/chunk-CNU4A2XU.js +129 -0
  31. package/dist/chunk-CNU4A2XU.js.map +1 -0
  32. package/dist/chunk-CY4TP3FK.js +16 -0
  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-G662L2YZ.js +568 -0
  47. package/dist/chunk-G662L2YZ.js.map +1 -0
  48. package/dist/chunk-GDWMF6SB.cjs +133 -0
  49. package/dist/chunk-GDWMF6SB.cjs.map +1 -0
  50. package/dist/chunk-GU4EWMZB.cjs +769 -0
  51. package/dist/chunk-GU4EWMZB.cjs.map +1 -0
  52. package/dist/chunk-GUI3CROV.cjs +159 -0
  53. package/dist/chunk-GUI3CROV.cjs.map +1 -0
  54. package/dist/chunk-HJQKWRKQ.cjs +764 -0
  55. package/dist/chunk-HJQKWRKQ.cjs.map +1 -0
  56. package/dist/{chunk-YWLUOY3D.cjs → chunk-HVBBFCDH.cjs} +1110 -793
  57. package/dist/chunk-HVBBFCDH.cjs.map +1 -0
  58. package/dist/chunk-HZJRQ5L3.cjs +1411 -0
  59. package/dist/chunk-HZJRQ5L3.cjs.map +1 -0
  60. package/dist/chunk-IGFMAZZ5.cjs +1150 -0
  61. package/dist/chunk-IGFMAZZ5.cjs.map +1 -0
  62. package/dist/chunk-ILESGJ6N.js +524 -0
  63. package/dist/chunk-ILESGJ6N.js.map +1 -0
  64. package/dist/chunk-IOQGI4ML.js +931 -0
  65. package/dist/chunk-IOQGI4ML.js.map +1 -0
  66. package/dist/chunk-J7BPKKOG.cjs +163 -0
  67. package/dist/chunk-J7BPKKOG.cjs.map +1 -0
  68. package/dist/{chunk-HFWCEP5S.js → chunk-JRDEOHAJ.js} +47 -14
  69. package/dist/chunk-JRDEOHAJ.js.map +1 -0
  70. package/dist/chunk-KNGXRN26.cjs +335 -0
  71. package/dist/chunk-KNGXRN26.cjs.map +1 -0
  72. package/dist/{chunk-OR3CIE2H.js → chunk-KV6VHX4V.js} +29 -7
  73. package/dist/chunk-KV6VHX4V.js.map +1 -0
  74. package/dist/chunk-L265APUD.cjs +69 -0
  75. package/dist/chunk-L265APUD.cjs.map +1 -0
  76. package/dist/chunk-LF2ZLOFP.js +767 -0
  77. package/dist/chunk-LF2ZLOFP.js.map +1 -0
  78. package/dist/chunk-LYPU75T6.js +1147 -0
  79. package/dist/chunk-LYPU75T6.js.map +1 -0
  80. package/dist/{chunk-NYN7KFXL.js → chunk-MMROOK5J.js} +3 -0
  81. package/dist/chunk-MMROOK5J.js.map +1 -0
  82. package/dist/chunk-N35YCWQ5.cjs +540 -0
  83. package/dist/chunk-N35YCWQ5.cjs.map +1 -0
  84. package/dist/{chunk-LIVAK2DM.js → chunk-N7F33WAD.js} +1083 -794
  85. package/dist/chunk-N7F33WAD.js.map +1 -0
  86. package/dist/chunk-NG5IVLEZ.js +1012 -0
  87. package/dist/chunk-NG5IVLEZ.js.map +1 -0
  88. package/dist/chunk-NLWACBE7.cjs +128 -0
  89. package/dist/chunk-NLWACBE7.cjs.map +1 -0
  90. package/dist/chunk-OGW6HHVI.js +1408 -0
  91. package/dist/chunk-OGW6HHVI.js.map +1 -0
  92. package/dist/chunk-OJQOYXHU.cjs +15748 -0
  93. package/dist/chunk-OJQOYXHU.cjs.map +1 -0
  94. package/dist/chunk-OZLRIVC4.cjs +588 -0
  95. package/dist/chunk-OZLRIVC4.cjs.map +1 -0
  96. package/dist/chunk-P7CIEIJ3.js +925 -0
  97. package/dist/chunk-P7CIEIJ3.js.map +1 -0
  98. package/dist/chunk-P7RBMCBE.cjs +934 -0
  99. package/dist/chunk-P7RBMCBE.cjs.map +1 -0
  100. package/dist/chunk-PPYGWINI.cjs +2777 -0
  101. package/dist/chunk-PPYGWINI.cjs.map +1 -0
  102. package/dist/{chunk-P6SCPDYW.js → chunk-PUYSH3IL.js} +114 -137
  103. package/dist/chunk-PUYSH3IL.js.map +1 -0
  104. package/dist/{chunk-MHKNLNAN.cjs → chunk-PWTXZZTR.cjs} +33 -10
  105. package/dist/chunk-PWTXZZTR.cjs.map +1 -0
  106. package/dist/chunk-R7NOGUZG.js +65 -0
  107. package/dist/chunk-R7NOGUZG.js.map +1 -0
  108. package/dist/chunk-RCHEPTZZ.js +2006 -0
  109. package/dist/chunk-RCHEPTZZ.js.map +1 -0
  110. package/dist/chunk-RE4RPXT2.cjs +18 -0
  111. package/dist/chunk-RE4RPXT2.cjs.map +1 -0
  112. package/dist/chunk-SIGXR3JT.cjs +1043 -0
  113. package/dist/chunk-SIGXR3JT.cjs.map +1 -0
  114. package/dist/chunk-SPLSYTYW.cjs +88 -0
  115. package/dist/chunk-SPLSYTYW.cjs.map +1 -0
  116. package/dist/chunk-SQY4T6EJ.js +571 -0
  117. package/dist/chunk-SQY4T6EJ.js.map +1 -0
  118. package/dist/{chunk-TJKLBTFB.js → chunk-SYRRSBGL.js} +51 -27
  119. package/dist/chunk-SYRRSBGL.js.map +1 -0
  120. package/dist/{chunk-BNEY4P4P.cjs → chunk-T3TIA3O6.cjs} +20 -18
  121. package/dist/chunk-T3TIA3O6.cjs.map +1 -0
  122. package/dist/{chunk-EJO45KYT.js → chunk-TTHEEIZ3.js} +53 -50
  123. package/dist/chunk-TTHEEIZ3.js.map +1 -0
  124. package/dist/chunk-TVSIG4JE.cjs +940 -0
  125. package/dist/chunk-TVSIG4JE.cjs.map +1 -0
  126. package/dist/{chunk-55DOQLP6.js → chunk-WHN4VX55.js} +5 -3
  127. package/dist/chunk-WHN4VX55.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 +88 -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 +41 -7
  197. package/dist/server/handlers/agents.cjs.map +1 -0
  198. package/dist/server/handlers/agents.d.ts +139 -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/observability.cjs +16 -0
  227. package/dist/server/handlers/observability.cjs.map +1 -0
  228. package/dist/server/handlers/observability.d.ts +23 -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 +49 -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 +220 -0
  257. package/dist/server/handlers/vNextNetwork.cjs.map +1 -0
  258. package/dist/server/handlers/vNextNetwork.d.ts +246 -0
  259. package/dist/server/handlers/vNextNetwork.d.ts.map +1 -0
  260. package/dist/server/handlers/vNextNetwork.js +213 -0
  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 +10 -4
  269. package/dist/server/handlers/voice.cjs.map +1 -0
  270. package/dist/server/handlers/voice.d.ts +41 -3
  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 +43 -13
  275. package/dist/server/handlers/workflows.cjs.map +1 -0
  276. package/dist/server/handlers/workflows.d.ts +82 -10
  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 +51 -21
  293. package/dist/_tsup-dts-rollup.d.cts +0 -816
  294. package/dist/_tsup-dts-rollup.d.ts +0 -816
  295. package/dist/chunk-57CJTIPW.cjs +0 -18
  296. package/dist/chunk-64U3UDTH.cjs +0 -13
  297. package/dist/chunk-75ZPJI57.cjs +0 -9
  298. package/dist/chunk-C7564HUT.js +0 -142
  299. package/dist/chunk-D4IRYCUI.cjs +0 -235
  300. package/dist/chunk-DJJIUEL2.js +0 -211
  301. package/dist/chunk-HWZVAG3H.js +0 -49
  302. package/dist/chunk-I2B73Y4I.cjs +0 -332
  303. package/dist/chunk-M5ABIP7D.js +0 -11
  304. package/dist/chunk-MIQYDLLM.js +0 -329
  305. package/dist/chunk-MLKGABMK.js +0 -7
  306. package/dist/chunk-OGCNNUHF.cjs +0 -54
  307. package/dist/chunk-UCTEMO2Q.cjs +0 -341
  308. package/dist/chunk-VPNDC2DI.cjs +0 -148
  309. package/dist/chunk-WUC6LSTW.js +0 -227
  310. package/dist/chunk-Y7UWRW5X.cjs +0 -221
  311. package/dist/chunk-YBVOQN4M.cjs +0 -94
  312. package/dist/chunk-ZE5AAC4I.cjs +0 -138
  313. package/dist/index.d.cts +0 -1
  314. package/dist/server/handlers/a2a.d.cts +0 -6
  315. package/dist/server/handlers/agents.d.cts +0 -6
  316. package/dist/server/handlers/error.d.cts +0 -1
  317. package/dist/server/handlers/logs.d.cts +0 -3
  318. package/dist/server/handlers/memory.d.cts +0 -8
  319. package/dist/server/handlers/network.cjs +0 -22
  320. package/dist/server/handlers/network.d.cts +0 -4
  321. package/dist/server/handlers/network.d.ts +0 -4
  322. package/dist/server/handlers/network.js +0 -1
  323. package/dist/server/handlers/telemetry.d.cts +0 -2
  324. package/dist/server/handlers/tools.d.cts +0 -4
  325. package/dist/server/handlers/utils.d.cts +0 -1
  326. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  327. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  328. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  329. package/dist/server/handlers/vNextWorkflows.js +0 -1
  330. package/dist/server/handlers/vector.d.cts +0 -6
  331. package/dist/server/handlers/voice.d.cts +0 -3
  332. package/dist/server/handlers/workflows.d.cts +0 -10
  333. package/dist/server/handlers.d.cts +0 -11
@@ -0,0 +1,931 @@
1
+ import { createJsonErrorResponseHandler, withoutTrailingSlash, generateId, loadApiKey, parseProviderOptions, postJsonToApi, createJsonResponseHandler, combineHeaders, createEventSourceResponseHandler, convertToBase64, UnsupportedFunctionalityError, NoSuchModelError } from './chunk-N7F33WAD.js';
2
+ import { z } from 'zod/v4';
3
+
4
+ z.object({
5
+ /**
6
+ * A unique identifier representing your end-user, which can help the provider to
7
+ * monitor and detect abuse.
8
+ */
9
+ user: z.string().optional(),
10
+ /**
11
+ * Reasoning effort for reasoning models. Defaults to `medium`.
12
+ */
13
+ reasoningEffort: z.string().optional()
14
+ });
15
+ var openaiCompatibleErrorDataSchema = z.object({
16
+ error: z.object({
17
+ message: z.string(),
18
+ // The additional information below is handled loosely to support
19
+ // OpenAI-compatible providers that have slightly different error
20
+ // responses:
21
+ type: z.string().nullish(),
22
+ param: z.any().nullish(),
23
+ code: z.union([z.string(), z.number()]).nullish()
24
+ })
25
+ });
26
+ var defaultOpenAICompatibleErrorStructure = {
27
+ errorSchema: openaiCompatibleErrorDataSchema,
28
+ errorToMessage: (data) => data.error.message
29
+ };
30
+ var openaiCompatibleTokenUsageSchema = z.object({
31
+ prompt_tokens: z.number().nullish(),
32
+ completion_tokens: z.number().nullish(),
33
+ total_tokens: z.number().nullish(),
34
+ prompt_tokens_details: z.object({
35
+ cached_tokens: z.number().nullish()
36
+ }).nullish(),
37
+ completion_tokens_details: z.object({
38
+ reasoning_tokens: z.number().nullish(),
39
+ accepted_prediction_tokens: z.number().nullish(),
40
+ rejected_prediction_tokens: z.number().nullish()
41
+ }).nullish()
42
+ }).nullish();
43
+ z.object({
44
+ id: z.string().nullish(),
45
+ created: z.number().nullish(),
46
+ model: z.string().nullish(),
47
+ choices: z.array(
48
+ z.object({
49
+ message: z.object({
50
+ role: z.literal("assistant").nullish(),
51
+ content: z.string().nullish(),
52
+ reasoning_content: z.string().nullish(),
53
+ reasoning: z.string().nullish(),
54
+ tool_calls: z.array(
55
+ z.object({
56
+ id: z.string().nullish(),
57
+ function: z.object({
58
+ name: z.string(),
59
+ arguments: z.string()
60
+ })
61
+ })
62
+ ).nullish()
63
+ }),
64
+ finish_reason: z.string().nullish()
65
+ })
66
+ ),
67
+ usage: openaiCompatibleTokenUsageSchema
68
+ });
69
+ z.object({
70
+ /**
71
+ * Echo back the prompt in addition to the completion.
72
+ */
73
+ echo: z.boolean().optional(),
74
+ /**
75
+ * Modify the likelihood of specified tokens appearing in the completion.
76
+ *
77
+ * Accepts a JSON object that maps tokens (specified by their token ID in
78
+ * the GPT tokenizer) to an associated bias value from -100 to 100.
79
+ */
80
+ logitBias: z.record(z.string(), z.number()).optional(),
81
+ /**
82
+ * The suffix that comes after a completion of inserted text.
83
+ */
84
+ suffix: z.string().optional(),
85
+ /**
86
+ * A unique identifier representing your end-user, which can help providers to
87
+ * monitor and detect abuse.
88
+ */
89
+ user: z.string().optional()
90
+ });
91
+ var usageSchema = z.object({
92
+ prompt_tokens: z.number(),
93
+ completion_tokens: z.number(),
94
+ total_tokens: z.number()
95
+ });
96
+ z.object({
97
+ id: z.string().nullish(),
98
+ created: z.number().nullish(),
99
+ model: z.string().nullish(),
100
+ choices: z.array(
101
+ z.object({
102
+ text: z.string(),
103
+ finish_reason: z.string()
104
+ })
105
+ ),
106
+ usage: usageSchema.nullish()
107
+ });
108
+ z.object({
109
+ /**
110
+ * The number of dimensions the resulting output embeddings should have.
111
+ * Only supported in text-embedding-3 and later models.
112
+ */
113
+ dimensions: z.number().optional(),
114
+ /**
115
+ * A unique identifier representing your end-user, which can help providers to
116
+ * monitor and detect abuse.
117
+ */
118
+ user: z.string().optional()
119
+ });
120
+ z.object({
121
+ data: z.array(z.object({ embedding: z.array(z.number()) })),
122
+ usage: z.object({ prompt_tokens: z.number() }).nullish(),
123
+ providerMetadata: z.record(z.string(), z.record(z.string(), z.any())).optional()
124
+ });
125
+ var OpenAICompatibleImageModel = class {
126
+ constructor(modelId, config) {
127
+ this.modelId = modelId;
128
+ this.config = config;
129
+ this.specificationVersion = "v2";
130
+ this.maxImagesPerCall = 10;
131
+ }
132
+ get provider() {
133
+ return this.config.provider;
134
+ }
135
+ async doGenerate({
136
+ prompt,
137
+ n,
138
+ size,
139
+ aspectRatio,
140
+ seed,
141
+ providerOptions,
142
+ headers,
143
+ abortSignal
144
+ }) {
145
+ var _a, _b, _c, _d, _e;
146
+ const warnings = [];
147
+ if (aspectRatio != null) {
148
+ warnings.push({
149
+ type: "unsupported-setting",
150
+ setting: "aspectRatio",
151
+ details: "This model does not support aspect ratio. Use `size` instead."
152
+ });
153
+ }
154
+ if (seed != null) {
155
+ warnings.push({ type: "unsupported-setting", setting: "seed" });
156
+ }
157
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
158
+ const { value: response, responseHeaders } = await postJsonToApi({
159
+ url: this.config.url({
160
+ path: "/images/generations",
161
+ modelId: this.modelId
162
+ }),
163
+ headers: combineHeaders(this.config.headers(), headers),
164
+ body: {
165
+ model: this.modelId,
166
+ prompt,
167
+ n,
168
+ size,
169
+ ...(_d = providerOptions.openai) != null ? _d : {},
170
+ response_format: "b64_json"
171
+ },
172
+ failedResponseHandler: createJsonErrorResponseHandler(
173
+ (_e = this.config.errorStructure) != null ? _e : defaultOpenAICompatibleErrorStructure
174
+ ),
175
+ successfulResponseHandler: createJsonResponseHandler(
176
+ openaiCompatibleImageResponseSchema
177
+ ),
178
+ abortSignal,
179
+ fetch: this.config.fetch
180
+ });
181
+ return {
182
+ images: response.data.map((item) => item.b64_json),
183
+ warnings,
184
+ response: {
185
+ timestamp: currentDate,
186
+ modelId: this.modelId,
187
+ headers: responseHeaders
188
+ }
189
+ };
190
+ }
191
+ };
192
+ var openaiCompatibleImageResponseSchema = z.object({
193
+ data: z.array(z.object({ b64_json: z.string() }))
194
+ });
195
+ function convertToXaiChatMessages(prompt) {
196
+ const messages = [];
197
+ const warnings = [];
198
+ for (const { role, content } of prompt) {
199
+ switch (role) {
200
+ case "system": {
201
+ messages.push({ role: "system", content });
202
+ break;
203
+ }
204
+ case "user": {
205
+ if (content.length === 1 && content[0].type === "text") {
206
+ messages.push({ role: "user", content: content[0].text });
207
+ break;
208
+ }
209
+ messages.push({
210
+ role: "user",
211
+ content: content.map((part) => {
212
+ switch (part.type) {
213
+ case "text": {
214
+ return { type: "text", text: part.text };
215
+ }
216
+ case "file": {
217
+ if (part.mediaType.startsWith("image/")) {
218
+ const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
219
+ return {
220
+ type: "image_url",
221
+ image_url: {
222
+ url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
223
+ }
224
+ };
225
+ } else {
226
+ throw new UnsupportedFunctionalityError({
227
+ functionality: `file part media type ${part.mediaType}`
228
+ });
229
+ }
230
+ }
231
+ }
232
+ })
233
+ });
234
+ break;
235
+ }
236
+ case "assistant": {
237
+ let text = "";
238
+ const toolCalls = [];
239
+ for (const part of content) {
240
+ switch (part.type) {
241
+ case "text": {
242
+ text += part.text;
243
+ break;
244
+ }
245
+ case "tool-call": {
246
+ toolCalls.push({
247
+ id: part.toolCallId,
248
+ type: "function",
249
+ function: {
250
+ name: part.toolName,
251
+ arguments: JSON.stringify(part.input)
252
+ }
253
+ });
254
+ break;
255
+ }
256
+ }
257
+ }
258
+ messages.push({
259
+ role: "assistant",
260
+ content: text,
261
+ tool_calls: toolCalls.length > 0 ? toolCalls : void 0
262
+ });
263
+ break;
264
+ }
265
+ case "tool": {
266
+ for (const toolResponse of content) {
267
+ const output = toolResponse.output;
268
+ let contentValue;
269
+ switch (output.type) {
270
+ case "text":
271
+ case "error-text":
272
+ contentValue = output.value;
273
+ break;
274
+ case "content":
275
+ case "json":
276
+ case "error-json":
277
+ contentValue = JSON.stringify(output.value);
278
+ break;
279
+ }
280
+ messages.push({
281
+ role: "tool",
282
+ tool_call_id: toolResponse.toolCallId,
283
+ content: contentValue
284
+ });
285
+ }
286
+ break;
287
+ }
288
+ default: {
289
+ const _exhaustiveCheck = role;
290
+ throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
291
+ }
292
+ }
293
+ }
294
+ return { messages, warnings };
295
+ }
296
+ function getResponseMetadata({
297
+ id,
298
+ model,
299
+ created
300
+ }) {
301
+ return {
302
+ id: id != null ? id : void 0,
303
+ modelId: model != null ? model : void 0,
304
+ timestamp: created != null ? new Date(created * 1e3) : void 0
305
+ };
306
+ }
307
+ function mapXaiFinishReason(finishReason) {
308
+ switch (finishReason) {
309
+ case "stop":
310
+ return "stop";
311
+ case "length":
312
+ return "length";
313
+ case "tool_calls":
314
+ case "function_call":
315
+ return "tool-calls";
316
+ case "content_filter":
317
+ return "content-filter";
318
+ default:
319
+ return "unknown";
320
+ }
321
+ }
322
+ var webSourceSchema = z.object({
323
+ type: z.literal("web"),
324
+ country: z.string().length(2).optional(),
325
+ excludedWebsites: z.array(z.string()).max(5).optional(),
326
+ allowedWebsites: z.array(z.string()).max(5).optional(),
327
+ safeSearch: z.boolean().optional()
328
+ });
329
+ var xSourceSchema = z.object({
330
+ type: z.literal("x"),
331
+ xHandles: z.array(z.string()).optional()
332
+ });
333
+ var newsSourceSchema = z.object({
334
+ type: z.literal("news"),
335
+ country: z.string().length(2).optional(),
336
+ excludedWebsites: z.array(z.string()).max(5).optional(),
337
+ safeSearch: z.boolean().optional()
338
+ });
339
+ var rssSourceSchema = z.object({
340
+ type: z.literal("rss"),
341
+ links: z.array(z.string().url()).max(1)
342
+ // currently only supports one RSS link
343
+ });
344
+ var searchSourceSchema = z.discriminatedUnion("type", [
345
+ webSourceSchema,
346
+ xSourceSchema,
347
+ newsSourceSchema,
348
+ rssSourceSchema
349
+ ]);
350
+ var xaiProviderOptions = z.object({
351
+ /**
352
+ * reasoning effort for reasoning models
353
+ * only supported by grok-3-mini and grok-3-mini-fast models
354
+ */
355
+ reasoningEffort: z.enum(["low", "high"]).optional(),
356
+ searchParameters: z.object({
357
+ /**
358
+ * search mode preference
359
+ * - "off": disables search completely
360
+ * - "auto": model decides whether to search (default)
361
+ * - "on": always enables search
362
+ */
363
+ mode: z.enum(["off", "auto", "on"]),
364
+ /**
365
+ * whether to return citations in the response
366
+ * defaults to true
367
+ */
368
+ returnCitations: z.boolean().optional(),
369
+ /**
370
+ * start date for search data (ISO8601 format: YYYY-MM-DD)
371
+ */
372
+ fromDate: z.string().optional(),
373
+ /**
374
+ * end date for search data (ISO8601 format: YYYY-MM-DD)
375
+ */
376
+ toDate: z.string().optional(),
377
+ /**
378
+ * maximum number of search results to consider
379
+ * defaults to 20
380
+ */
381
+ maxSearchResults: z.number().min(1).max(50).optional(),
382
+ /**
383
+ * data sources to search from
384
+ * defaults to ["web", "x"] if not specified
385
+ */
386
+ sources: z.array(searchSourceSchema).optional()
387
+ }).optional()
388
+ });
389
+ var xaiErrorDataSchema = z.object({
390
+ error: z.object({
391
+ message: z.string(),
392
+ type: z.string().nullish(),
393
+ param: z.any().nullish(),
394
+ code: z.union([z.string(), z.number()]).nullish()
395
+ })
396
+ });
397
+ var xaiFailedResponseHandler = createJsonErrorResponseHandler({
398
+ errorSchema: xaiErrorDataSchema,
399
+ errorToMessage: (data) => data.error.message
400
+ });
401
+ function prepareTools({
402
+ tools,
403
+ toolChoice
404
+ }) {
405
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
406
+ const toolWarnings = [];
407
+ if (tools == null) {
408
+ return { tools: void 0, toolChoice: void 0, toolWarnings };
409
+ }
410
+ const xaiTools = [];
411
+ for (const tool of tools) {
412
+ if (tool.type === "provider-defined") {
413
+ toolWarnings.push({ type: "unsupported-tool", tool });
414
+ } else {
415
+ xaiTools.push({
416
+ type: "function",
417
+ function: {
418
+ name: tool.name,
419
+ description: tool.description,
420
+ parameters: tool.inputSchema
421
+ }
422
+ });
423
+ }
424
+ }
425
+ if (toolChoice == null) {
426
+ return { tools: xaiTools, toolChoice: void 0, toolWarnings };
427
+ }
428
+ const type = toolChoice.type;
429
+ switch (type) {
430
+ case "auto":
431
+ case "none":
432
+ return { tools: xaiTools, toolChoice: type, toolWarnings };
433
+ case "required":
434
+ return { tools: xaiTools, toolChoice: "required", toolWarnings };
435
+ case "tool":
436
+ return {
437
+ tools: xaiTools,
438
+ toolChoice: {
439
+ type: "function",
440
+ function: { name: toolChoice.toolName }
441
+ },
442
+ toolWarnings
443
+ };
444
+ default: {
445
+ const _exhaustiveCheck = type;
446
+ throw new UnsupportedFunctionalityError({
447
+ functionality: `tool choice type: ${_exhaustiveCheck}`
448
+ });
449
+ }
450
+ }
451
+ }
452
+ var XaiChatLanguageModel = class {
453
+ constructor(modelId, config) {
454
+ this.specificationVersion = "v2";
455
+ this.supportedUrls = {
456
+ "image/*": [/^https?:\/\/.*$/]
457
+ };
458
+ this.modelId = modelId;
459
+ this.config = config;
460
+ }
461
+ get provider() {
462
+ return this.config.provider;
463
+ }
464
+ async getArgs({
465
+ prompt,
466
+ maxOutputTokens,
467
+ temperature,
468
+ topP,
469
+ topK,
470
+ frequencyPenalty,
471
+ presencePenalty,
472
+ stopSequences,
473
+ seed,
474
+ responseFormat,
475
+ providerOptions,
476
+ tools,
477
+ toolChoice
478
+ }) {
479
+ var _a, _b, _c;
480
+ const warnings = [];
481
+ const options = (_a = await parseProviderOptions({
482
+ provider: "xai",
483
+ providerOptions,
484
+ schema: xaiProviderOptions
485
+ })) != null ? _a : {};
486
+ if (topK != null) {
487
+ warnings.push({
488
+ type: "unsupported-setting",
489
+ setting: "topK"
490
+ });
491
+ }
492
+ if (frequencyPenalty != null) {
493
+ warnings.push({
494
+ type: "unsupported-setting",
495
+ setting: "frequencyPenalty"
496
+ });
497
+ }
498
+ if (presencePenalty != null) {
499
+ warnings.push({
500
+ type: "unsupported-setting",
501
+ setting: "presencePenalty"
502
+ });
503
+ }
504
+ if (stopSequences != null) {
505
+ warnings.push({
506
+ type: "unsupported-setting",
507
+ setting: "stopSequences"
508
+ });
509
+ }
510
+ if (responseFormat != null && responseFormat.type === "json" && responseFormat.schema != null) {
511
+ warnings.push({
512
+ type: "unsupported-setting",
513
+ setting: "responseFormat",
514
+ details: "JSON response format schema is not supported"
515
+ });
516
+ }
517
+ const { messages, warnings: messageWarnings } = convertToXaiChatMessages(prompt);
518
+ warnings.push(...messageWarnings);
519
+ const {
520
+ tools: xaiTools,
521
+ toolChoice: xaiToolChoice,
522
+ toolWarnings
523
+ } = prepareTools({
524
+ tools,
525
+ toolChoice
526
+ });
527
+ warnings.push(...toolWarnings);
528
+ const baseArgs = {
529
+ // model id
530
+ model: this.modelId,
531
+ // standard generation settings
532
+ max_tokens: maxOutputTokens,
533
+ temperature,
534
+ top_p: topP,
535
+ seed,
536
+ reasoning_effort: options.reasoningEffort,
537
+ // response format
538
+ response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
539
+ type: "json_schema",
540
+ json_schema: {
541
+ name: (_b = responseFormat.name) != null ? _b : "response",
542
+ schema: responseFormat.schema,
543
+ strict: true
544
+ }
545
+ } : { type: "json_object" } : void 0,
546
+ // search parameters
547
+ search_parameters: options.searchParameters ? {
548
+ mode: options.searchParameters.mode,
549
+ return_citations: options.searchParameters.returnCitations,
550
+ from_date: options.searchParameters.fromDate,
551
+ to_date: options.searchParameters.toDate,
552
+ max_search_results: options.searchParameters.maxSearchResults,
553
+ sources: (_c = options.searchParameters.sources) == null ? void 0 : _c.map((source) => ({
554
+ type: source.type,
555
+ ...source.type === "web" && {
556
+ country: source.country,
557
+ excluded_websites: source.excludedWebsites,
558
+ allowed_websites: source.allowedWebsites,
559
+ safe_search: source.safeSearch
560
+ },
561
+ ...source.type === "x" && {
562
+ x_handles: source.xHandles
563
+ },
564
+ ...source.type === "news" && {
565
+ country: source.country,
566
+ excluded_websites: source.excludedWebsites,
567
+ safe_search: source.safeSearch
568
+ },
569
+ ...source.type === "rss" && {
570
+ links: source.links
571
+ }
572
+ }))
573
+ } : void 0,
574
+ // messages in xai format
575
+ messages,
576
+ // tools in xai format
577
+ tools: xaiTools,
578
+ tool_choice: xaiToolChoice
579
+ };
580
+ return {
581
+ args: baseArgs,
582
+ warnings
583
+ };
584
+ }
585
+ async doGenerate(options) {
586
+ var _a, _b, _c;
587
+ const { args: body, warnings } = await this.getArgs(options);
588
+ const {
589
+ responseHeaders,
590
+ value: response,
591
+ rawValue: rawResponse
592
+ } = await postJsonToApi({
593
+ url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`,
594
+ headers: combineHeaders(this.config.headers(), options.headers),
595
+ body,
596
+ failedResponseHandler: xaiFailedResponseHandler,
597
+ successfulResponseHandler: createJsonResponseHandler(
598
+ xaiChatResponseSchema
599
+ ),
600
+ abortSignal: options.abortSignal,
601
+ fetch: this.config.fetch
602
+ });
603
+ const choice = response.choices[0];
604
+ const content = [];
605
+ if (choice.message.content != null && choice.message.content.length > 0) {
606
+ let text = choice.message.content;
607
+ const lastMessage = body.messages[body.messages.length - 1];
608
+ if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && text === lastMessage.content) {
609
+ text = "";
610
+ }
611
+ if (text.length > 0) {
612
+ content.push({ type: "text", text });
613
+ }
614
+ }
615
+ if (choice.message.reasoning_content != null && choice.message.reasoning_content.length > 0) {
616
+ content.push({
617
+ type: "reasoning",
618
+ text: choice.message.reasoning_content
619
+ });
620
+ }
621
+ if (choice.message.tool_calls != null) {
622
+ for (const toolCall of choice.message.tool_calls) {
623
+ content.push({
624
+ type: "tool-call",
625
+ toolCallId: toolCall.id,
626
+ toolName: toolCall.function.name,
627
+ input: toolCall.function.arguments
628
+ });
629
+ }
630
+ }
631
+ if (response.citations != null) {
632
+ for (const url of response.citations) {
633
+ content.push({
634
+ type: "source",
635
+ sourceType: "url",
636
+ id: this.config.generateId(),
637
+ url
638
+ });
639
+ }
640
+ }
641
+ return {
642
+ content,
643
+ finishReason: mapXaiFinishReason(choice.finish_reason),
644
+ usage: {
645
+ inputTokens: response.usage.prompt_tokens,
646
+ outputTokens: response.usage.completion_tokens,
647
+ totalTokens: response.usage.total_tokens,
648
+ reasoningTokens: (_c = (_b = response.usage.completion_tokens_details) == null ? void 0 : _b.reasoning_tokens) != null ? _c : void 0
649
+ },
650
+ request: { body },
651
+ response: {
652
+ ...getResponseMetadata(response),
653
+ headers: responseHeaders,
654
+ body: rawResponse
655
+ },
656
+ warnings
657
+ };
658
+ }
659
+ async doStream(options) {
660
+ var _a;
661
+ const { args, warnings } = await this.getArgs(options);
662
+ const body = {
663
+ ...args,
664
+ stream: true,
665
+ stream_options: {
666
+ include_usage: true
667
+ }
668
+ };
669
+ const { responseHeaders, value: response } = await postJsonToApi({
670
+ url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`,
671
+ headers: combineHeaders(this.config.headers(), options.headers),
672
+ body,
673
+ failedResponseHandler: xaiFailedResponseHandler,
674
+ successfulResponseHandler: createEventSourceResponseHandler(xaiChatChunkSchema),
675
+ abortSignal: options.abortSignal,
676
+ fetch: this.config.fetch
677
+ });
678
+ let finishReason = "unknown";
679
+ const usage = {
680
+ inputTokens: void 0,
681
+ outputTokens: void 0,
682
+ totalTokens: void 0
683
+ };
684
+ let isFirstChunk = true;
685
+ const contentBlocks = {};
686
+ const lastReasoningDeltas = {};
687
+ const self = this;
688
+ return {
689
+ stream: response.pipeThrough(
690
+ new TransformStream({
691
+ start(controller) {
692
+ controller.enqueue({ type: "stream-start", warnings });
693
+ },
694
+ transform(chunk, controller) {
695
+ var _a2, _b;
696
+ if (options.includeRawChunks) {
697
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
698
+ }
699
+ if (!chunk.success) {
700
+ controller.enqueue({ type: "error", error: chunk.error });
701
+ return;
702
+ }
703
+ const value = chunk.value;
704
+ if (isFirstChunk) {
705
+ controller.enqueue({
706
+ type: "response-metadata",
707
+ ...getResponseMetadata(value)
708
+ });
709
+ isFirstChunk = false;
710
+ }
711
+ if (value.citations != null) {
712
+ for (const url of value.citations) {
713
+ controller.enqueue({
714
+ type: "source",
715
+ sourceType: "url",
716
+ id: self.config.generateId(),
717
+ url
718
+ });
719
+ }
720
+ }
721
+ if (value.usage != null) {
722
+ usage.inputTokens = value.usage.prompt_tokens;
723
+ usage.outputTokens = value.usage.completion_tokens;
724
+ usage.totalTokens = value.usage.total_tokens;
725
+ usage.reasoningTokens = (_b = (_a2 = value.usage.completion_tokens_details) == null ? void 0 : _a2.reasoning_tokens) != null ? _b : void 0;
726
+ }
727
+ const choice = value.choices[0];
728
+ if ((choice == null ? void 0 : choice.finish_reason) != null) {
729
+ finishReason = mapXaiFinishReason(choice.finish_reason);
730
+ }
731
+ if ((choice == null ? void 0 : choice.delta) == null) {
732
+ return;
733
+ }
734
+ const delta = choice.delta;
735
+ const choiceIndex = choice.index;
736
+ if (delta.content != null && delta.content.length > 0) {
737
+ const textContent = delta.content;
738
+ const lastMessage = body.messages[body.messages.length - 1];
739
+ if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && textContent === lastMessage.content) {
740
+ return;
741
+ }
742
+ const blockId = `text-${value.id || choiceIndex}`;
743
+ if (contentBlocks[blockId] == null) {
744
+ contentBlocks[blockId] = { type: "text" };
745
+ controller.enqueue({
746
+ type: "text-start",
747
+ id: blockId
748
+ });
749
+ }
750
+ controller.enqueue({
751
+ type: "text-delta",
752
+ id: blockId,
753
+ delta: textContent
754
+ });
755
+ }
756
+ if (delta.reasoning_content != null && delta.reasoning_content.length > 0) {
757
+ const blockId = `reasoning-${value.id || choiceIndex}`;
758
+ if (lastReasoningDeltas[blockId] === delta.reasoning_content) {
759
+ return;
760
+ }
761
+ lastReasoningDeltas[blockId] = delta.reasoning_content;
762
+ if (contentBlocks[blockId] == null) {
763
+ contentBlocks[blockId] = { type: "reasoning" };
764
+ controller.enqueue({
765
+ type: "reasoning-start",
766
+ id: blockId
767
+ });
768
+ }
769
+ controller.enqueue({
770
+ type: "reasoning-delta",
771
+ id: blockId,
772
+ delta: delta.reasoning_content
773
+ });
774
+ }
775
+ if (delta.tool_calls != null) {
776
+ for (const toolCall of delta.tool_calls) {
777
+ const toolCallId = toolCall.id;
778
+ controller.enqueue({
779
+ type: "tool-input-start",
780
+ id: toolCallId,
781
+ toolName: toolCall.function.name
782
+ });
783
+ controller.enqueue({
784
+ type: "tool-input-delta",
785
+ id: toolCallId,
786
+ delta: toolCall.function.arguments
787
+ });
788
+ controller.enqueue({
789
+ type: "tool-input-end",
790
+ id: toolCallId
791
+ });
792
+ controller.enqueue({
793
+ type: "tool-call",
794
+ toolCallId,
795
+ toolName: toolCall.function.name,
796
+ input: toolCall.function.arguments
797
+ });
798
+ }
799
+ }
800
+ },
801
+ flush(controller) {
802
+ for (const [blockId, block] of Object.entries(contentBlocks)) {
803
+ controller.enqueue({
804
+ type: block.type === "text" ? "text-end" : "reasoning-end",
805
+ id: blockId
806
+ });
807
+ }
808
+ controller.enqueue({ type: "finish", finishReason, usage });
809
+ }
810
+ })
811
+ ),
812
+ request: { body },
813
+ response: { headers: responseHeaders }
814
+ };
815
+ }
816
+ };
817
+ var xaiUsageSchema = z.object({
818
+ prompt_tokens: z.number(),
819
+ completion_tokens: z.number(),
820
+ total_tokens: z.number(),
821
+ completion_tokens_details: z.object({
822
+ reasoning_tokens: z.number().nullish()
823
+ }).nullish()
824
+ });
825
+ var xaiChatResponseSchema = z.object({
826
+ id: z.string().nullish(),
827
+ created: z.number().nullish(),
828
+ model: z.string().nullish(),
829
+ choices: z.array(
830
+ z.object({
831
+ message: z.object({
832
+ role: z.literal("assistant"),
833
+ content: z.string().nullish(),
834
+ reasoning_content: z.string().nullish(),
835
+ tool_calls: z.array(
836
+ z.object({
837
+ id: z.string(),
838
+ type: z.literal("function"),
839
+ function: z.object({
840
+ name: z.string(),
841
+ arguments: z.string()
842
+ })
843
+ })
844
+ ).nullish()
845
+ }),
846
+ index: z.number(),
847
+ finish_reason: z.string().nullish()
848
+ })
849
+ ),
850
+ object: z.literal("chat.completion"),
851
+ usage: xaiUsageSchema,
852
+ citations: z.array(z.string().url()).nullish()
853
+ });
854
+ var xaiChatChunkSchema = z.object({
855
+ id: z.string().nullish(),
856
+ created: z.number().nullish(),
857
+ model: z.string().nullish(),
858
+ choices: z.array(
859
+ z.object({
860
+ delta: z.object({
861
+ role: z.enum(["assistant"]).optional(),
862
+ content: z.string().nullish(),
863
+ reasoning_content: z.string().nullish(),
864
+ tool_calls: z.array(
865
+ z.object({
866
+ id: z.string(),
867
+ type: z.literal("function"),
868
+ function: z.object({
869
+ name: z.string(),
870
+ arguments: z.string()
871
+ })
872
+ })
873
+ ).nullish()
874
+ }),
875
+ finish_reason: z.string().nullish(),
876
+ index: z.number()
877
+ })
878
+ ),
879
+ usage: xaiUsageSchema.nullish(),
880
+ citations: z.array(z.string().url()).nullish()
881
+ });
882
+ var xaiErrorStructure = {
883
+ errorSchema: xaiErrorDataSchema,
884
+ errorToMessage: (data) => data.error.message
885
+ };
886
+ function createXai(options = {}) {
887
+ var _a;
888
+ const baseURL = withoutTrailingSlash(
889
+ (_a = options.baseURL) != null ? _a : "https://api.x.ai/v1"
890
+ );
891
+ const getHeaders = () => ({
892
+ Authorization: `Bearer ${loadApiKey({
893
+ apiKey: options.apiKey,
894
+ environmentVariableName: "XAI_API_KEY",
895
+ description: "xAI API key"
896
+ })}`,
897
+ ...options.headers
898
+ });
899
+ const createLanguageModel = (modelId) => {
900
+ return new XaiChatLanguageModel(modelId, {
901
+ provider: "xai.chat",
902
+ baseURL,
903
+ headers: getHeaders,
904
+ generateId,
905
+ fetch: options.fetch
906
+ });
907
+ };
908
+ const createImageModel = (modelId) => {
909
+ return new OpenAICompatibleImageModel(modelId, {
910
+ provider: "xai.image",
911
+ url: ({ path }) => `${baseURL}${path}`,
912
+ headers: getHeaders,
913
+ fetch: options.fetch,
914
+ errorStructure: xaiErrorStructure
915
+ });
916
+ };
917
+ const provider = (modelId) => createLanguageModel(modelId);
918
+ provider.languageModel = createLanguageModel;
919
+ provider.chat = createLanguageModel;
920
+ provider.textEmbeddingModel = (modelId) => {
921
+ throw new NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
922
+ };
923
+ provider.imageModel = createImageModel;
924
+ provider.image = createImageModel;
925
+ return provider;
926
+ }
927
+ var xai = createXai();
928
+
929
+ export { createXai, xai };
930
+ //# sourceMappingURL=chunk-IOQGI4ML.js.map
931
+ //# sourceMappingURL=chunk-IOQGI4ML.js.map