@mastra/server 1.79.0-alpha.9 → 1.79.0

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 (402) hide show
  1. package/dist/{a2a-CHBSYHxu.js → a2a-BqLB3McP.js} +17 -16
  2. package/dist/a2a-BqLB3McP.js.map +1 -0
  3. package/dist/{a2a-B465DD1u.cjs → a2a-Uood_0DN.cjs} +19 -18
  4. package/dist/a2a-Uood_0DN.cjs.map +1 -0
  5. package/dist/agent-builder-CuBD1tpv.cjs +728 -0
  6. package/dist/agent-builder-CuBD1tpv.cjs.map +1 -0
  7. package/dist/agent-builder-VhM8ADW-.js +627 -0
  8. package/dist/agent-builder-VhM8ADW-.js.map +1 -0
  9. package/dist/{agents-X1E7fW3p.js → agents-BHLTMBff.js} +2 -2
  10. package/dist/{agents-X1E7fW3p.js.map → agents-BHLTMBff.js.map} +1 -1
  11. package/dist/agents-BOWEUKyV.cjs +3127 -0
  12. package/dist/agents-BOWEUKyV.cjs.map +1 -0
  13. package/dist/agents-DRQ3ScbX.js +2828 -0
  14. package/dist/agents-DRQ3ScbX.js.map +1 -0
  15. package/dist/{agents-DoNMSCMt.cjs → agents-T-OIM9IK.cjs} +2 -2
  16. package/dist/{agents-DoNMSCMt.cjs.map → agents-T-OIM9IK.cjs.map} +1 -1
  17. package/dist/{api-schema-manifest-CWRIJP-B.js → api-schema-manifest-CI90M4sX.js} +3 -3
  18. package/dist/{api-schema-manifest-CWRIJP-B.js.map → api-schema-manifest-CI90M4sX.js.map} +1 -1
  19. package/dist/{api-schema-manifest-DUseI2VG.cjs → api-schema-manifest-DIlNfbyw.cjs} +4 -4
  20. package/dist/{api-schema-manifest-DUseI2VG.cjs.map → api-schema-manifest-DIlNfbyw.cjs.map} +1 -1
  21. package/dist/{background-tasks-CabImVak.cjs → background-tasks-B3VAKTJh.cjs} +3 -3
  22. package/dist/{background-tasks-CabImVak.cjs.map → background-tasks-B3VAKTJh.cjs.map} +1 -1
  23. package/dist/{background-tasks-oBaLtnCn.js → background-tasks-Du2zYOPl.js} +2 -2
  24. package/dist/{background-tasks-oBaLtnCn.js.map → background-tasks-Du2zYOPl.js.map} +1 -1
  25. package/dist/{builder-registry-DOkLe8ES.js → builder-registry-DLdu9bWH.js} +3 -3
  26. package/dist/{builder-registry-DOkLe8ES.js.map → builder-registry-DLdu9bWH.js.map} +1 -1
  27. package/dist/{builder-registry-D0frV8lQ.cjs → builder-registry-DaFAaMTf.cjs} +3 -3
  28. package/dist/{builder-registry-D0frV8lQ.cjs.map → builder-registry-DaFAaMTf.cjs.map} +1 -1
  29. package/dist/{channels-CBIopVWd.cjs → channels-BnVRmnzK.cjs} +6 -3
  30. package/dist/{channels-CBIopVWd.cjs.map → channels-BnVRmnzK.cjs.map} +1 -1
  31. package/dist/{channels-BOxgHvzI.js → channels-Db-4pXVZ.js} +6 -3
  32. package/dist/{channels-BOxgHvzI.js.map → channels-Db-4pXVZ.js.map} +1 -1
  33. package/dist/conversations-8BWryNlF.js +165 -0
  34. package/dist/conversations-8BWryNlF.js.map +1 -0
  35. package/dist/conversations-C5MkQBB8.cjs +194 -0
  36. package/dist/conversations-C5MkQBB8.cjs.map +1 -0
  37. package/dist/{conversations-Bj5TLNqF.cjs → conversations-DasqEDCF.cjs} +3 -3
  38. package/dist/{conversations-Bj5TLNqF.cjs.map → conversations-DasqEDCF.cjs.map} +1 -1
  39. package/dist/{dist-9c3PXXpk.cjs → dist-B-bEVWlJ.cjs} +4733 -1251
  40. package/dist/dist-B-bEVWlJ.cjs.map +1 -0
  41. package/dist/dist-B3kC8Yd0.cjs +3 -0
  42. package/dist/{dist-CQ3FSKT-.cjs → dist-B9ery9Zw.cjs} +38 -35
  43. package/dist/{dist-CQ3FSKT-.cjs.map → dist-B9ery9Zw.cjs.map} +1 -1
  44. package/dist/{dist-BxMmGD3n.js → dist-BBOnrL_A.js} +10 -12
  45. package/dist/{dist-BxMmGD3n.js.map → dist-BBOnrL_A.js.map} +1 -1
  46. package/dist/{dist-DOWsEmo6.js → dist-BIrQLUV9.js} +20 -20
  47. package/dist/{dist-DOWsEmo6.js.map → dist-BIrQLUV9.js.map} +1 -1
  48. package/dist/dist-BM9J-PTK.js +1 -0
  49. package/dist/{dist-DC1Pewf5.cjs → dist-Bo3GdQwf.cjs} +21 -21
  50. package/dist/{dist-DC1Pewf5.cjs.map → dist-Bo3GdQwf.cjs.map} +1 -1
  51. package/dist/{dist-BwYL7Ykb.js → dist-CREG82cy.js} +37 -34
  52. package/dist/{dist-BwYL7Ykb.js.map → dist-CREG82cy.js.map} +1 -1
  53. package/dist/{dist-rDRetJVY.cjs → dist-CeTLA-e5.cjs} +2 -3
  54. package/dist/{dist-rDRetJVY.cjs.map → dist-CeTLA-e5.cjs.map} +1 -1
  55. package/dist/{dist-CBRJax5e.js → dist-DLld1qjf.js} +25 -31
  56. package/dist/{dist-CBRJax5e.js.map → dist-DLld1qjf.js.map} +1 -1
  57. package/dist/{dist-B_bet8uz.js → dist-DjkPkAzV.js} +2 -3
  58. package/dist/{dist-B_bet8uz.js.map → dist-DjkPkAzV.js.map} +1 -1
  59. package/dist/{dist-UKEksCGq.cjs → dist-DsrJXwic.cjs} +11 -13
  60. package/dist/{dist-UKEksCGq.cjs.map → dist-DsrJXwic.cjs.map} +1 -1
  61. package/dist/{dist-DGCnbhNe.js → dist-k77XQGUn.js} +4493 -1043
  62. package/dist/dist-k77XQGUn.js.map +1 -0
  63. package/dist/{dist-3FPW9nVj.cjs → dist-lT2rqyY9.cjs} +26 -32
  64. package/dist/{dist-3FPW9nVj.cjs.map → dist-lT2rqyY9.cjs.map} +1 -1
  65. package/dist/docs/SKILL.md +1 -1
  66. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  67. package/dist/docs/references/reference-server-routes.md +159 -0
  68. package/dist/{dynamic-workflows-Rr_6ac1y.js → dynamic-workflows-CTUO0SFu.js} +3 -3
  69. package/dist/{dynamic-workflows-Rr_6ac1y.js.map → dynamic-workflows-CTUO0SFu.js.map} +1 -1
  70. package/dist/{dynamic-workflows-DXlkr-jK.cjs → dynamic-workflows-HwPX3mcf.cjs} +3 -3
  71. package/dist/{dynamic-workflows-DXlkr-jK.cjs.map → dynamic-workflows-HwPX3mcf.cjs.map} +1 -1
  72. package/dist/{editor-builder-BclcHxN6.cjs → editor-builder-BDtiWw0f.cjs} +2 -2
  73. package/dist/{editor-builder-BclcHxN6.cjs.map → editor-builder-BDtiWw0f.cjs.map} +1 -1
  74. package/dist/{editor-builder-D16kc1P6.js → editor-builder-ClFlGXoX.js} +4 -4
  75. package/dist/{editor-builder-D16kc1P6.js.map → editor-builder-ClFlGXoX.js.map} +1 -1
  76. package/dist/{editor-builder-s9WqPJgA.js → editor-builder-DnLCfqnY.js} +2 -2
  77. package/dist/{editor-builder-s9WqPJgA.js.map → editor-builder-DnLCfqnY.js.map} +1 -1
  78. package/dist/{editor-builder-DXHiPX1A.cjs → editor-builder-DtpP1FtW.cjs} +5 -5
  79. package/dist/{editor-builder-DXHiPX1A.cjs.map → editor-builder-DtpP1FtW.cjs.map} +1 -1
  80. package/dist/{helpers-ElhPeCSK.cjs → helpers-CAcEhq38.cjs} +21 -17
  81. package/dist/{helpers-ElhPeCSK.cjs.map → helpers-CAcEhq38.cjs.map} +1 -1
  82. package/dist/{helpers-DLhX1fqc.js → helpers-vrqddDd5.js} +21 -17
  83. package/dist/{helpers-DLhX1fqc.js.map → helpers-vrqddDd5.js.map} +1 -1
  84. package/dist/index.cjs +1 -1
  85. package/dist/logs-CiSw7r0s.cjs +119 -0
  86. package/dist/logs-CiSw7r0s.cjs.map +1 -0
  87. package/dist/logs-CxfPk-iL.js +96 -0
  88. package/dist/logs-CxfPk-iL.js.map +1 -0
  89. package/dist/mcp-CWDfSu7w.js +474 -0
  90. package/dist/mcp-CWDfSu7w.js.map +1 -0
  91. package/dist/mcp-CWGJRqkC.cjs +563 -0
  92. package/dist/mcp-CWGJRqkC.cjs.map +1 -0
  93. package/dist/{mcp-DzpwLXEY.js → mcp-Drqt0GqD.js} +79 -4
  94. package/dist/mcp-Drqt0GqD.js.map +1 -0
  95. package/dist/{mcp-ShaKO7gA.cjs → mcp-ziWVk7Ol.cjs} +126 -3
  96. package/dist/mcp-ziWVk7Ol.cjs.map +1 -0
  97. package/dist/memory-BHtTSzvJ.js +1739 -0
  98. package/dist/memory-BHtTSzvJ.js.map +1 -0
  99. package/dist/memory-CwwkVDh1.cjs +1906 -0
  100. package/dist/memory-CwwkVDh1.cjs.map +1 -0
  101. package/dist/observability-BBMCMeT-.cjs +502 -0
  102. package/dist/observability-BBMCMeT-.cjs.map +1 -0
  103. package/dist/observability-ZRgRcvoX.js +431 -0
  104. package/dist/observability-ZRgRcvoX.js.map +1 -0
  105. package/dist/{observability-new-endpoints-BU8JYPfh.js → observability-new-endpoints-fjoZzEtk.js} +10 -9
  106. package/dist/{observability-new-endpoints-BU8JYPfh.js.map → observability-new-endpoints-fjoZzEtk.js.map} +1 -1
  107. package/dist/{observability-new-endpoints-AMp9bnMV.cjs → observability-new-endpoints-tG3-odLa.cjs} +11 -10
  108. package/dist/observability-new-endpoints-tG3-odLa.cjs.map +1 -0
  109. package/dist/plans-CiPgWBhO.cjs +68 -0
  110. package/dist/plans-CiPgWBhO.cjs.map +1 -0
  111. package/dist/plans-DCepEY7n.js +57 -0
  112. package/dist/plans-DCepEY7n.js.map +1 -0
  113. package/dist/{probe-image-size-DBGjhUtJ.cjs → probe-image-size-Alv3gwKl.cjs} +194 -184
  114. package/dist/probe-image-size-Alv3gwKl.cjs.map +1 -0
  115. package/dist/{probe-image-size-Dmoxv93t.js → probe-image-size-BdfbUHxx.js} +158 -148
  116. package/dist/probe-image-size-BdfbUHxx.js.map +1 -0
  117. package/dist/responses-4FwMNxoJ.js +628 -0
  118. package/dist/responses-4FwMNxoJ.js.map +1 -0
  119. package/dist/responses-CCRijwDF.cjs +651 -0
  120. package/dist/responses-CCRijwDF.cjs.map +1 -0
  121. package/dist/{responses-CKNdSRkS.cjs → responses-CfcIc53b.cjs} +2 -2
  122. package/dist/{responses-CKNdSRkS.cjs.map → responses-CfcIc53b.cjs.map} +1 -1
  123. package/dist/{rolldown-runtime-Bd6kNlEP.cjs → rolldown-runtime-BwC_XMyb.cjs} +2 -2
  124. package/dist/{rolldown-runtime-maW3aOIk.js → rolldown-runtime-D3Hj5m0v.js} +2 -2
  125. package/dist/{route-builder-BNZs643f.cjs → route-builder-B2Qhhd7C.cjs} +52 -66
  126. package/dist/route-builder-B2Qhhd7C.cjs.map +1 -0
  127. package/dist/{route-builder-BfQYtclb.js → route-builder-CjkWxv4E.js} +51 -65
  128. package/dist/route-builder-CjkWxv4E.js.map +1 -0
  129. package/dist/{routes-rwufkyUe.js → routes-BC20mdNN.js} +30 -26
  130. package/dist/routes-BC20mdNN.js.map +1 -0
  131. package/dist/{routes-Dl6_kWm7.js → routes-CKfXiwRc.js} +5 -3
  132. package/dist/routes-CKfXiwRc.js.map +1 -0
  133. package/dist/{routes-DPojsNf1.cjs → routes-DGLJyqjD.cjs} +203 -199
  134. package/dist/routes-DGLJyqjD.cjs.map +1 -0
  135. package/dist/{routes-BULZI-PU.cjs → routes-jXksmX9G.cjs} +5 -3
  136. package/dist/routes-jXksmX9G.cjs.map +1 -0
  137. package/dist/{schedules-Bj-giFbc.cjs → schedules-GokZKBYg.cjs} +6 -4
  138. package/dist/schedules-GokZKBYg.cjs.map +1 -0
  139. package/dist/{schedules-BQYgaz66.js → schedules-_3zPKyqm.js} +5 -3
  140. package/dist/schedules-_3zPKyqm.js.map +1 -0
  141. package/dist/{schema-e0VHpMt0-C0452jOk.cjs → schema-CzbEIyhE-20gGIWkz.cjs} +83 -88
  142. package/dist/schema-CzbEIyhE-20gGIWkz.cjs.map +1 -0
  143. package/dist/{schema-e0VHpMt0-CVP5Hnxy.js → schema-CzbEIyhE-BsMcj9Ws.js} +82 -87
  144. package/dist/schema-CzbEIyhE-BsMcj9Ws.js.map +1 -0
  145. package/dist/scores-D9UgETt_.js +288 -0
  146. package/dist/scores-D9UgETt_.js.map +1 -0
  147. package/dist/scores-DRdtS7NT.cjs +329 -0
  148. package/dist/scores-DRdtS7NT.cjs.map +1 -0
  149. package/dist/server/a2a/store.cjs +1 -1
  150. package/dist/server/auth/index.cjs +2 -2
  151. package/dist/server/auth/index.js +1 -1
  152. package/dist/server/browser-stream/index.cjs +9 -11
  153. package/dist/server/browser-stream/index.cjs.map +1 -1
  154. package/dist/server/browser-stream/index.js +8 -10
  155. package/dist/server/browser-stream/index.js.map +1 -1
  156. package/dist/server/handlers/a2a.cjs +2 -2
  157. package/dist/server/handlers/a2a.js +1 -2
  158. package/dist/server/handlers/agent-builder.cjs +18 -648
  159. package/dist/server/handlers/agent-builder.js +1 -627
  160. package/dist/server/handlers/agent-controller.cjs +5 -5
  161. package/dist/server/handlers/agent-controller.cjs.map +1 -1
  162. package/dist/server/handlers/agent-controller.js +11 -9
  163. package/dist/server/handlers/agent-controller.js.map +1 -1
  164. package/dist/server/handlers/agent-versions.cjs +15 -8
  165. package/dist/server/handlers/agent-versions.cjs.map +1 -1
  166. package/dist/server/handlers/agent-versions.js +14 -7
  167. package/dist/server/handlers/agent-versions.js.map +1 -1
  168. package/dist/server/handlers/agents.cjs +51 -2860
  169. package/dist/server/handlers/agents.js +1 -2806
  170. package/dist/server/handlers/auth.cjs +14 -12
  171. package/dist/server/handlers/auth.cjs.map +1 -1
  172. package/dist/server/handlers/auth.js +20 -16
  173. package/dist/server/handlers/auth.js.map +1 -1
  174. package/dist/server/handlers/author-enrichment.cjs +1 -1
  175. package/dist/server/handlers/authorship.cjs +1 -1
  176. package/dist/server/handlers/authorship.cjs.map +1 -1
  177. package/dist/server/handlers/background-tasks.cjs +2 -2
  178. package/dist/server/handlers/background-tasks.js +1 -2
  179. package/dist/server/handlers/builder-registry.cjs +2 -2
  180. package/dist/server/handlers/builder-registry.js +1 -2
  181. package/dist/server/handlers/channels.cjs +2 -2
  182. package/dist/server/handlers/channels.js +1 -2
  183. package/dist/server/handlers/conversations.cjs +6 -171
  184. package/dist/server/handlers/conversations.js +1 -162
  185. package/dist/server/handlers/datasets.cjs +2 -2
  186. package/dist/server/handlers/datasets.cjs.map +1 -1
  187. package/dist/server/handlers/datasets.js +1 -1
  188. package/dist/server/handlers/dynamic-workflows.cjs +2 -2
  189. package/dist/server/handlers/dynamic-workflows.js +1 -2
  190. package/dist/server/handlers/editor-builder.cjs +2 -2
  191. package/dist/server/handlers/editor-builder.js +1 -2
  192. package/dist/server/handlers/error.cjs +18 -13
  193. package/dist/server/handlers/error.cjs.map +1 -1
  194. package/dist/server/handlers/error.js +17 -12
  195. package/dist/server/handlers/error.js.map +1 -1
  196. package/dist/server/handlers/favorites-enrichment.cjs +2 -2
  197. package/dist/server/handlers/favorites-enrichment.js +1 -1
  198. package/dist/server/handlers/gateway-memory-client.cjs +1 -1
  199. package/dist/server/handlers/logs.cjs +5 -104
  200. package/dist/server/handlers/logs.js +1 -96
  201. package/dist/server/handlers/mcp-client-versions.cjs +15 -8
  202. package/dist/server/handlers/mcp-client-versions.cjs.map +1 -1
  203. package/dist/server/handlers/mcp-client-versions.js +14 -7
  204. package/dist/server/handlers/mcp-client-versions.js.map +1 -1
  205. package/dist/server/handlers/mcp.cjs +16 -289
  206. package/dist/server/handlers/mcp.d.ts +219 -0
  207. package/dist/server/handlers/mcp.d.ts.map +1 -1
  208. package/dist/server/handlers/mcp.js +1 -274
  209. package/dist/server/handlers/memory.cjs +29 -1763
  210. package/dist/server/handlers/memory.js +1 -1731
  211. package/dist/server/handlers/observability-list-query-schemas.cjs +1 -1
  212. package/dist/server/handlers/observability-new-endpoints.cjs +2 -2
  213. package/dist/server/handlers/observability-new-endpoints.js +1 -2
  214. package/dist/server/handlers/observability-shared.cjs +2 -2
  215. package/dist/server/handlers/observability-shared.js +1 -1
  216. package/dist/server/handlers/observability-storage-schemas.cjs +1 -1
  217. package/dist/server/handlers/observability.cjs +14 -445
  218. package/dist/server/handlers/observability.js +3 -429
  219. package/dist/server/handlers/plans.cjs +3 -63
  220. package/dist/server/handlers/plans.js +1 -57
  221. package/dist/server/handlers/processor-providers.cjs +2 -2
  222. package/dist/server/handlers/processor-providers.cjs.map +1 -1
  223. package/dist/server/handlers/processor-providers.js +1 -1
  224. package/dist/server/handlers/processors.cjs +13 -15
  225. package/dist/server/handlers/processors.cjs.map +1 -1
  226. package/dist/server/handlers/processors.js +12 -14
  227. package/dist/server/handlers/processors.js.map +1 -1
  228. package/dist/server/handlers/prompt-block-versions.cjs +15 -8
  229. package/dist/server/handlers/prompt-block-versions.cjs.map +1 -1
  230. package/dist/server/handlers/prompt-block-versions.js +14 -7
  231. package/dist/server/handlers/prompt-block-versions.js.map +1 -1
  232. package/dist/server/handlers/responses.adapter.cjs +1 -1
  233. package/dist/server/handlers/responses.adapter.cjs.map +1 -1
  234. package/dist/server/handlers/responses.cjs +5 -632
  235. package/dist/server/handlers/responses.js +1 -624
  236. package/dist/server/handlers/responses.storage.cjs +2 -2
  237. package/dist/server/handlers/schedules-workflows-shim.cjs +1 -1
  238. package/dist/server/handlers/schedules.cjs +2 -2
  239. package/dist/server/handlers/schedules.d.ts +16 -0
  240. package/dist/server/handlers/schedules.d.ts.map +1 -1
  241. package/dist/server/handlers/schedules.js +1 -2
  242. package/dist/server/handlers/scorer-versions.cjs +15 -8
  243. package/dist/server/handlers/scorer-versions.cjs.map +1 -1
  244. package/dist/server/handlers/scorer-versions.js +14 -7
  245. package/dist/server/handlers/scorer-versions.js.map +1 -1
  246. package/dist/server/handlers/scores.cjs +8 -299
  247. package/dist/server/handlers/scores.js +1 -288
  248. package/dist/server/handlers/skills-sh-shared.cjs +1 -1
  249. package/dist/server/handlers/stored-agent-favorites.cjs +4 -4
  250. package/dist/server/handlers/stored-agent-favorites.js +3 -3
  251. package/dist/server/handlers/stored-agents.cjs +19 -13
  252. package/dist/server/handlers/stored-agents.cjs.map +1 -1
  253. package/dist/server/handlers/stored-agents.js +18 -12
  254. package/dist/server/handlers/stored-agents.js.map +1 -1
  255. package/dist/server/handlers/stored-mcp-clients.cjs +8 -6
  256. package/dist/server/handlers/stored-mcp-clients.cjs.map +1 -1
  257. package/dist/server/handlers/stored-mcp-clients.js +7 -5
  258. package/dist/server/handlers/stored-mcp-clients.js.map +1 -1
  259. package/dist/server/handlers/stored-prompt-blocks.cjs +3 -3
  260. package/dist/server/handlers/stored-prompt-blocks.js +2 -2
  261. package/dist/server/handlers/stored-scorers.cjs +3 -3
  262. package/dist/server/handlers/stored-scorers.js +2 -2
  263. package/dist/server/handlers/stored-skill-favorites.cjs +4 -4
  264. package/dist/server/handlers/stored-skill-favorites.js +3 -3
  265. package/dist/server/handlers/stored-skills.cjs +6 -5
  266. package/dist/server/handlers/stored-skills.cjs.map +1 -1
  267. package/dist/server/handlers/stored-skills.js +5 -4
  268. package/dist/server/handlers/stored-skills.js.map +1 -1
  269. package/dist/server/handlers/stored-workspaces.cjs +3 -3
  270. package/dist/server/handlers/stored-workspaces.js +2 -2
  271. package/dist/server/handlers/system.cjs +3 -3
  272. package/dist/server/handlers/system.cjs.map +1 -1
  273. package/dist/server/handlers/system.js +2 -2
  274. package/dist/server/handlers/test-utils.cjs +1 -1
  275. package/dist/server/handlers/tool-providers.cjs +2 -2
  276. package/dist/server/handlers/tool-providers.js +1 -1
  277. package/dist/server/handlers/tool-schema-overrides.cjs +1 -1
  278. package/dist/server/handlers/tools.cjs +7 -267
  279. package/dist/server/handlers/tools.js +1 -257
  280. package/dist/server/handlers/utils.cjs +2 -2
  281. package/dist/server/handlers/utils.js +1 -2
  282. package/dist/server/handlers/validate-agent-instructions.cjs +2 -2
  283. package/dist/server/handlers/validate-agent-instructions.js +1 -1
  284. package/dist/server/handlers/validate-avatar.cjs +2 -2
  285. package/dist/server/handlers/validate-avatar.cjs.map +1 -1
  286. package/dist/server/handlers/validate-avatar.js +1 -1
  287. package/dist/server/handlers/validate-avatar.js.map +1 -1
  288. package/dist/server/handlers/vector.cjs +17 -334
  289. package/dist/server/handlers/vector.js +1 -314
  290. package/dist/server/handlers/version-helpers.cjs +1 -1
  291. package/dist/server/handlers/voice.cjs +9 -35
  292. package/dist/server/handlers/voice.js +1 -23
  293. package/dist/server/handlers/workflow-builder.cjs +2 -2
  294. package/dist/server/handlers/workflow-builder.js +1 -2
  295. package/dist/server/handlers/workflows.cjs +30 -1293
  296. package/dist/server/handlers/workflows.js +1 -1257
  297. package/dist/server/handlers/workspace.cjs +27 -1176
  298. package/dist/server/handlers/workspace.js +1 -1146
  299. package/dist/server/handlers.cjs +33 -33
  300. package/dist/server/handlers.js +17 -17
  301. package/dist/server/schemas/index.cjs +7 -7
  302. package/dist/server/schemas/index.js +4 -4
  303. package/dist/server/schemas/mcp.d.ts +102 -0
  304. package/dist/server/schemas/mcp.d.ts.map +1 -1
  305. package/dist/server/schemas/schedules.d.ts +5 -0
  306. package/dist/server/schemas/schedules.d.ts.map +1 -1
  307. package/dist/server/server-adapter/index.cjs +5 -5
  308. package/dist/server/server-adapter/index.cjs.map +1 -1
  309. package/dist/server/server-adapter/index.js +4 -4
  310. package/dist/server/server-adapter/index.js.map +1 -1
  311. package/dist/server/server-adapter/routes/mcp.d.ts +214 -0
  312. package/dist/server/server-adapter/routes/mcp.d.ts.map +1 -1
  313. package/dist/tools-CmFSfDMn.js +256 -0
  314. package/dist/tools-CmFSfDMn.js.map +1 -0
  315. package/dist/tools-SPJtxG9N.cjs +291 -0
  316. package/dist/tools-SPJtxG9N.cjs.map +1 -0
  317. package/dist/{utils-DCgeTrq2.cjs → utils-CF76qzZR.cjs} +12 -17
  318. package/dist/{utils-DCgeTrq2.cjs.map → utils-CF76qzZR.cjs.map} +1 -1
  319. package/dist/{utils-DCAUeb6M.js → utils-aoLN3Wfi.js} +11 -16
  320. package/dist/{utils-DCAUeb6M.js.map → utils-aoLN3Wfi.js.map} +1 -1
  321. package/dist/{utils-Du-EpvDs.cjs → utils-dDLIDg8O.cjs} +2 -2
  322. package/dist/{utils-Du-EpvDs.cjs.map → utils-dDLIDg8O.cjs.map} +1 -1
  323. package/dist/vector-BKDD1kwc.cjs +409 -0
  324. package/dist/vector-BKDD1kwc.cjs.map +1 -0
  325. package/dist/vector-TWv4t-4g.js +314 -0
  326. package/dist/vector-TWv4t-4g.js.map +1 -0
  327. package/dist/voice-BnGwlZ75.cjs +70 -0
  328. package/dist/voice-BnGwlZ75.cjs.map +1 -0
  329. package/dist/voice-DjG8tBAD.js +23 -0
  330. package/dist/voice-DjG8tBAD.js.map +1 -0
  331. package/dist/{workflow-builder-Brj3IArM.cjs → workflow-builder-C9-8ZOWF.cjs} +5 -5
  332. package/dist/{workflow-builder-Brj3IArM.cjs.map → workflow-builder-C9-8ZOWF.cjs.map} +1 -1
  333. package/dist/{workflow-builder-DOa1Vx6w.js → workflow-builder-CjlLoQvo.js} +10 -8
  334. package/dist/{workflow-builder-DOa1Vx6w.js.map → workflow-builder-CjlLoQvo.js.map} +1 -1
  335. package/dist/workflows-DjqeJcdJ.cjs +1446 -0
  336. package/dist/workflows-DjqeJcdJ.cjs.map +1 -0
  337. package/dist/workflows-bb-otd2o.js +1273 -0
  338. package/dist/workflows-bb-otd2o.js.map +1 -0
  339. package/dist/workspace-B6kzp-bo.js +1154 -0
  340. package/dist/workspace-B6kzp-bo.js.map +1 -0
  341. package/dist/workspace-COKR1SxH.cjs +1309 -0
  342. package/dist/workspace-COKR1SxH.cjs.map +1 -0
  343. package/package.json +9 -9
  344. package/dist/a2a-B465DD1u.cjs.map +0 -1
  345. package/dist/a2a-CHBSYHxu.js.map +0 -1
  346. package/dist/dist-9c3PXXpk.cjs.map +0 -1
  347. package/dist/dist-B5OwHWTo.cjs +0 -2294
  348. package/dist/dist-B5OwHWTo.cjs.map +0 -1
  349. package/dist/dist-DGCnbhNe.js.map +0 -1
  350. package/dist/dist-DcoIg_tp.js +0 -2293
  351. package/dist/dist-DcoIg_tp.js.map +0 -1
  352. package/dist/mcp-DzpwLXEY.js.map +0 -1
  353. package/dist/mcp-ShaKO7gA.cjs.map +0 -1
  354. package/dist/observability-new-endpoints-AMp9bnMV.cjs.map +0 -1
  355. package/dist/probe-image-size-DBGjhUtJ.cjs.map +0 -1
  356. package/dist/probe-image-size-Dmoxv93t.js.map +0 -1
  357. package/dist/route-builder-BNZs643f.cjs.map +0 -1
  358. package/dist/route-builder-BfQYtclb.js.map +0 -1
  359. package/dist/routes-BULZI-PU.cjs.map +0 -1
  360. package/dist/routes-DPojsNf1.cjs.map +0 -1
  361. package/dist/routes-Dl6_kWm7.js.map +0 -1
  362. package/dist/routes-rwufkyUe.js.map +0 -1
  363. package/dist/schedules-BQYgaz66.js.map +0 -1
  364. package/dist/schedules-Bj-giFbc.cjs.map +0 -1
  365. package/dist/schema-Drf2W04o.js +0 -2
  366. package/dist/schema-EQanefYq.cjs +0 -1
  367. package/dist/schema-e0VHpMt0-C0452jOk.cjs.map +0 -1
  368. package/dist/schema-e0VHpMt0-CVP5Hnxy.js.map +0 -1
  369. package/dist/server/handlers/agent-builder.cjs.map +0 -1
  370. package/dist/server/handlers/agent-builder.js.map +0 -1
  371. package/dist/server/handlers/agents.cjs.map +0 -1
  372. package/dist/server/handlers/agents.js.map +0 -1
  373. package/dist/server/handlers/conversations.cjs.map +0 -1
  374. package/dist/server/handlers/conversations.js.map +0 -1
  375. package/dist/server/handlers/logs.cjs.map +0 -1
  376. package/dist/server/handlers/logs.js.map +0 -1
  377. package/dist/server/handlers/mcp.cjs.map +0 -1
  378. package/dist/server/handlers/mcp.js.map +0 -1
  379. package/dist/server/handlers/memory.cjs.map +0 -1
  380. package/dist/server/handlers/memory.js.map +0 -1
  381. package/dist/server/handlers/observability.cjs.map +0 -1
  382. package/dist/server/handlers/observability.js.map +0 -1
  383. package/dist/server/handlers/plans.cjs.map +0 -1
  384. package/dist/server/handlers/plans.js.map +0 -1
  385. package/dist/server/handlers/responses.cjs.map +0 -1
  386. package/dist/server/handlers/responses.js.map +0 -1
  387. package/dist/server/handlers/scores.cjs.map +0 -1
  388. package/dist/server/handlers/scores.js.map +0 -1
  389. package/dist/server/handlers/tools.cjs.map +0 -1
  390. package/dist/server/handlers/tools.js.map +0 -1
  391. package/dist/server/handlers/vector.cjs.map +0 -1
  392. package/dist/server/handlers/vector.js.map +0 -1
  393. package/dist/server/handlers/voice.cjs.map +0 -1
  394. package/dist/server/handlers/voice.js.map +0 -1
  395. package/dist/server/handlers/workflows.cjs.map +0 -1
  396. package/dist/server/handlers/workflows.js.map +0 -1
  397. package/dist/server/handlers/workspace.cjs.map +0 -1
  398. package/dist/server/handlers/workspace.js.map +0 -1
  399. package/dist/sync-Ai_ZDz7U.js +0 -1700
  400. package/dist/sync-Ai_ZDz7U.js.map +0 -1
  401. package/dist/sync-BrO5MtSe.cjs +0 -1729
  402. package/dist/sync-BrO5MtSe.cjs.map +0 -1
@@ -1,2294 +0,0 @@
1
- require("./rolldown-runtime-Bd6kNlEP.cjs");
2
- const require_dist = require("./dist-rDRetJVY.cjs");
3
- let zod = require("zod");
4
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/openai/1.3.24/9ea9437756f1191484449f4e611ce2befb4ff9a7be92f5dfa8b1970d80a87966/node_modules/@ai-sdk/openai/dist/index.mjs
5
- function convertToOpenAIChatMessages({ prompt, useLegacyFunctionCalling = false, systemMessageMode = "system" }) {
6
- const messages = [];
7
- const warnings = [];
8
- for (const { role, content } of prompt) switch (role) {
9
- case "system":
10
- switch (systemMessageMode) {
11
- case "system":
12
- messages.push({
13
- role: "system",
14
- content
15
- });
16
- break;
17
- case "developer":
18
- messages.push({
19
- role: "developer",
20
- content
21
- });
22
- break;
23
- case "remove":
24
- warnings.push({
25
- type: "other",
26
- message: "system messages are removed for this model"
27
- });
28
- break;
29
- default: throw new Error(`Unsupported system message mode: ${systemMessageMode}`);
30
- }
31
- break;
32
- case "user":
33
- if (content.length === 1 && content[0].type === "text") {
34
- messages.push({
35
- role: "user",
36
- content: content[0].text
37
- });
38
- break;
39
- }
40
- messages.push({
41
- role: "user",
42
- content: content.map((part, index) => {
43
- var _a, _b, _c, _d;
44
- switch (part.type) {
45
- case "text": return {
46
- type: "text",
47
- text: part.text
48
- };
49
- case "image": return {
50
- type: "image_url",
51
- image_url: {
52
- url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${require_dist.convertUint8ArrayToBase64(part.image)}`,
53
- detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
54
- }
55
- };
56
- case "file":
57
- if (part.data instanceof URL) throw new require_dist.UnsupportedFunctionalityError({ functionality: "'File content parts with URL data' functionality not supported." });
58
- switch (part.mimeType) {
59
- case "audio/wav": return {
60
- type: "input_audio",
61
- input_audio: {
62
- data: part.data,
63
- format: "wav"
64
- }
65
- };
66
- case "audio/mp3":
67
- case "audio/mpeg": return {
68
- type: "input_audio",
69
- input_audio: {
70
- data: part.data,
71
- format: "mp3"
72
- }
73
- };
74
- case "application/pdf": return {
75
- type: "file",
76
- file: {
77
- filename: (_d = part.filename) != null ? _d : `part-${index}.pdf`,
78
- file_data: `data:application/pdf;base64,${part.data}`
79
- }
80
- };
81
- default: throw new require_dist.UnsupportedFunctionalityError({ functionality: `File content part type ${part.mimeType} in user messages` });
82
- }
83
- }
84
- })
85
- });
86
- break;
87
- case "assistant": {
88
- let text = "";
89
- const toolCalls = [];
90
- for (const part of content) switch (part.type) {
91
- case "text":
92
- text += part.text;
93
- break;
94
- case "tool-call":
95
- toolCalls.push({
96
- id: part.toolCallId,
97
- type: "function",
98
- function: {
99
- name: part.toolName,
100
- arguments: JSON.stringify(part.args)
101
- }
102
- });
103
- break;
104
- }
105
- if (useLegacyFunctionCalling) {
106
- if (toolCalls.length > 1) throw new require_dist.UnsupportedFunctionalityError({ functionality: "useLegacyFunctionCalling with multiple tool calls in one message" });
107
- messages.push({
108
- role: "assistant",
109
- content: text,
110
- function_call: toolCalls.length > 0 ? toolCalls[0].function : void 0
111
- });
112
- } else messages.push({
113
- role: "assistant",
114
- content: text,
115
- tool_calls: toolCalls.length > 0 ? toolCalls : void 0
116
- });
117
- break;
118
- }
119
- case "tool":
120
- for (const toolResponse of content) if (useLegacyFunctionCalling) messages.push({
121
- role: "function",
122
- name: toolResponse.toolName,
123
- content: JSON.stringify(toolResponse.result)
124
- });
125
- else messages.push({
126
- role: "tool",
127
- tool_call_id: toolResponse.toolCallId,
128
- content: JSON.stringify(toolResponse.result)
129
- });
130
- break;
131
- default: throw new Error(`Unsupported role: ${role}`);
132
- }
133
- return {
134
- messages,
135
- warnings
136
- };
137
- }
138
- function mapOpenAIChatLogProbsOutput(logprobs) {
139
- var _a, _b;
140
- return (_b = (_a = logprobs == null ? void 0 : logprobs.content) == null ? void 0 : _a.map(({ token, logprob, top_logprobs }) => ({
141
- token,
142
- logprob,
143
- topLogprobs: top_logprobs ? top_logprobs.map(({ token: token2, logprob: logprob2 }) => ({
144
- token: token2,
145
- logprob: logprob2
146
- })) : []
147
- }))) != null ? _b : void 0;
148
- }
149
- function mapOpenAIFinishReason(finishReason) {
150
- switch (finishReason) {
151
- case "stop": return "stop";
152
- case "length": return "length";
153
- case "content_filter": return "content-filter";
154
- case "function_call":
155
- case "tool_calls": return "tool-calls";
156
- default: return "unknown";
157
- }
158
- }
159
- var openaiErrorDataSchema = zod.z.object({ error: zod.z.object({
160
- message: zod.z.string(),
161
- type: zod.z.string().nullish(),
162
- param: zod.z.any().nullish(),
163
- code: zod.z.union([zod.z.string(), zod.z.number()]).nullish()
164
- }) });
165
- var openaiFailedResponseHandler = require_dist.createJsonErrorResponseHandler({
166
- errorSchema: openaiErrorDataSchema,
167
- errorToMessage: (data) => data.error.message
168
- });
169
- function getResponseMetadata({ id, model, created }) {
170
- return {
171
- id: id != null ? id : void 0,
172
- modelId: model != null ? model : void 0,
173
- timestamp: created != null ? /* @__PURE__ */ new Date(created * 1e3) : void 0
174
- };
175
- }
176
- function prepareTools({ mode, useLegacyFunctionCalling = false, structuredOutputs }) {
177
- var _a;
178
- const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
179
- const toolWarnings = [];
180
- if (tools == null) return {
181
- tools: void 0,
182
- tool_choice: void 0,
183
- toolWarnings
184
- };
185
- const toolChoice = mode.toolChoice;
186
- if (useLegacyFunctionCalling) {
187
- const openaiFunctions = [];
188
- for (const tool of tools) if (tool.type === "provider-defined") toolWarnings.push({
189
- type: "unsupported-tool",
190
- tool
191
- });
192
- else openaiFunctions.push({
193
- name: tool.name,
194
- description: tool.description,
195
- parameters: tool.parameters
196
- });
197
- if (toolChoice == null) return {
198
- functions: openaiFunctions,
199
- function_call: void 0,
200
- toolWarnings
201
- };
202
- switch (toolChoice.type) {
203
- case "auto":
204
- case "none":
205
- case void 0: return {
206
- functions: openaiFunctions,
207
- function_call: void 0,
208
- toolWarnings
209
- };
210
- case "required": throw new require_dist.UnsupportedFunctionalityError({ functionality: "useLegacyFunctionCalling and toolChoice: required" });
211
- default: return {
212
- functions: openaiFunctions,
213
- function_call: { name: toolChoice.toolName },
214
- toolWarnings
215
- };
216
- }
217
- }
218
- const openaiTools2 = [];
219
- for (const tool of tools) if (tool.type === "provider-defined") toolWarnings.push({
220
- type: "unsupported-tool",
221
- tool
222
- });
223
- else openaiTools2.push({
224
- type: "function",
225
- function: {
226
- name: tool.name,
227
- description: tool.description,
228
- parameters: tool.parameters,
229
- strict: structuredOutputs ? true : void 0
230
- }
231
- });
232
- if (toolChoice == null) return {
233
- tools: openaiTools2,
234
- tool_choice: void 0,
235
- toolWarnings
236
- };
237
- const type = toolChoice.type;
238
- switch (type) {
239
- case "auto":
240
- case "none":
241
- case "required": return {
242
- tools: openaiTools2,
243
- tool_choice: type,
244
- toolWarnings
245
- };
246
- case "tool": return {
247
- tools: openaiTools2,
248
- tool_choice: {
249
- type: "function",
250
- function: { name: toolChoice.toolName }
251
- },
252
- toolWarnings
253
- };
254
- default: throw new require_dist.UnsupportedFunctionalityError({ functionality: `Unsupported tool choice type: ${type}` });
255
- }
256
- }
257
- var OpenAIChatLanguageModel = class {
258
- constructor(modelId, settings, config) {
259
- this.specificationVersion = "v1";
260
- this.modelId = modelId;
261
- this.settings = settings;
262
- this.config = config;
263
- }
264
- get supportsStructuredOutputs() {
265
- var _a;
266
- return (_a = this.settings.structuredOutputs) != null ? _a : isReasoningModel(this.modelId);
267
- }
268
- get defaultObjectGenerationMode() {
269
- if (isAudioModel(this.modelId)) return "tool";
270
- return this.supportsStructuredOutputs ? "json" : "tool";
271
- }
272
- get provider() {
273
- return this.config.provider;
274
- }
275
- get supportsImageUrls() {
276
- return !this.settings.downloadImages;
277
- }
278
- getArgs({ mode, prompt, maxTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, providerMetadata }) {
279
- var _a, _b, _c, _d, _e, _f, _g, _h;
280
- const type = mode.type;
281
- const warnings = [];
282
- if (topK != null) warnings.push({
283
- type: "unsupported-setting",
284
- setting: "topK"
285
- });
286
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.supportsStructuredOutputs) warnings.push({
287
- type: "unsupported-setting",
288
- setting: "responseFormat",
289
- details: "JSON response format schema is only supported with structuredOutputs"
290
- });
291
- const useLegacyFunctionCalling = this.settings.useLegacyFunctionCalling;
292
- if (useLegacyFunctionCalling && this.settings.parallelToolCalls === true) throw new require_dist.UnsupportedFunctionalityError({ functionality: "useLegacyFunctionCalling with parallelToolCalls" });
293
- if (useLegacyFunctionCalling && this.supportsStructuredOutputs) throw new require_dist.UnsupportedFunctionalityError({ functionality: "structuredOutputs with useLegacyFunctionCalling" });
294
- const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages({
295
- prompt,
296
- useLegacyFunctionCalling,
297
- systemMessageMode: getSystemMessageMode(this.modelId)
298
- });
299
- warnings.push(...messageWarnings);
300
- const baseArgs = {
301
- model: this.modelId,
302
- logit_bias: this.settings.logitBias,
303
- logprobs: this.settings.logprobs === true || typeof this.settings.logprobs === "number" ? true : void 0,
304
- top_logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
305
- user: this.settings.user,
306
- parallel_tool_calls: this.settings.parallelToolCalls,
307
- max_tokens: maxTokens,
308
- temperature,
309
- top_p: topP,
310
- frequency_penalty: frequencyPenalty,
311
- presence_penalty: presencePenalty,
312
- response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs && responseFormat.schema != null ? {
313
- type: "json_schema",
314
- json_schema: {
315
- schema: responseFormat.schema,
316
- strict: true,
317
- name: (_a = responseFormat.name) != null ? _a : "response",
318
- description: responseFormat.description
319
- }
320
- } : { type: "json_object" } : void 0,
321
- stop: stopSequences,
322
- seed,
323
- max_completion_tokens: (_b = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _b.maxCompletionTokens,
324
- store: (_c = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _c.store,
325
- metadata: (_d = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _d.metadata,
326
- prediction: (_e = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _e.prediction,
327
- reasoning_effort: (_g = (_f = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _f.reasoningEffort) != null ? _g : this.settings.reasoningEffort,
328
- messages
329
- };
330
- if (isReasoningModel(this.modelId)) {
331
- if (baseArgs.temperature != null) {
332
- baseArgs.temperature = void 0;
333
- warnings.push({
334
- type: "unsupported-setting",
335
- setting: "temperature",
336
- details: "temperature is not supported for reasoning models"
337
- });
338
- }
339
- if (baseArgs.top_p != null) {
340
- baseArgs.top_p = void 0;
341
- warnings.push({
342
- type: "unsupported-setting",
343
- setting: "topP",
344
- details: "topP is not supported for reasoning models"
345
- });
346
- }
347
- if (baseArgs.frequency_penalty != null) {
348
- baseArgs.frequency_penalty = void 0;
349
- warnings.push({
350
- type: "unsupported-setting",
351
- setting: "frequencyPenalty",
352
- details: "frequencyPenalty is not supported for reasoning models"
353
- });
354
- }
355
- if (baseArgs.presence_penalty != null) {
356
- baseArgs.presence_penalty = void 0;
357
- warnings.push({
358
- type: "unsupported-setting",
359
- setting: "presencePenalty",
360
- details: "presencePenalty is not supported for reasoning models"
361
- });
362
- }
363
- if (baseArgs.logit_bias != null) {
364
- baseArgs.logit_bias = void 0;
365
- warnings.push({
366
- type: "other",
367
- message: "logitBias is not supported for reasoning models"
368
- });
369
- }
370
- if (baseArgs.logprobs != null) {
371
- baseArgs.logprobs = void 0;
372
- warnings.push({
373
- type: "other",
374
- message: "logprobs is not supported for reasoning models"
375
- });
376
- }
377
- if (baseArgs.top_logprobs != null) {
378
- baseArgs.top_logprobs = void 0;
379
- warnings.push({
380
- type: "other",
381
- message: "topLogprobs is not supported for reasoning models"
382
- });
383
- }
384
- if (baseArgs.max_tokens != null) {
385
- if (baseArgs.max_completion_tokens == null) baseArgs.max_completion_tokens = baseArgs.max_tokens;
386
- baseArgs.max_tokens = void 0;
387
- }
388
- } else if (this.modelId.startsWith("gpt-4o-search-preview") || this.modelId.startsWith("gpt-4o-mini-search-preview")) {
389
- if (baseArgs.temperature != null) {
390
- baseArgs.temperature = void 0;
391
- warnings.push({
392
- type: "unsupported-setting",
393
- setting: "temperature",
394
- details: "temperature is not supported for the search preview models and has been removed."
395
- });
396
- }
397
- }
398
- switch (type) {
399
- case "regular": {
400
- const { tools, tool_choice, functions, function_call, toolWarnings } = prepareTools({
401
- mode,
402
- useLegacyFunctionCalling,
403
- structuredOutputs: this.supportsStructuredOutputs
404
- });
405
- return {
406
- args: {
407
- ...baseArgs,
408
- tools,
409
- tool_choice,
410
- functions,
411
- function_call
412
- },
413
- warnings: [...warnings, ...toolWarnings]
414
- };
415
- }
416
- case "object-json": return {
417
- args: {
418
- ...baseArgs,
419
- response_format: this.supportsStructuredOutputs && mode.schema != null ? {
420
- type: "json_schema",
421
- json_schema: {
422
- schema: mode.schema,
423
- strict: true,
424
- name: (_h = mode.name) != null ? _h : "response",
425
- description: mode.description
426
- }
427
- } : { type: "json_object" }
428
- },
429
- warnings
430
- };
431
- case "object-tool": return {
432
- args: useLegacyFunctionCalling ? {
433
- ...baseArgs,
434
- function_call: { name: mode.tool.name },
435
- functions: [{
436
- name: mode.tool.name,
437
- description: mode.tool.description,
438
- parameters: mode.tool.parameters
439
- }]
440
- } : {
441
- ...baseArgs,
442
- tool_choice: {
443
- type: "function",
444
- function: { name: mode.tool.name }
445
- },
446
- tools: [{
447
- type: "function",
448
- function: {
449
- name: mode.tool.name,
450
- description: mode.tool.description,
451
- parameters: mode.tool.parameters,
452
- strict: this.supportsStructuredOutputs ? true : void 0
453
- }
454
- }]
455
- },
456
- warnings
457
- };
458
- default: throw new Error(`Unsupported type: ${type}`);
459
- }
460
- }
461
- async doGenerate(options) {
462
- var _a, _b, _c, _d, _e, _f, _g, _h;
463
- const { args: body, warnings } = this.getArgs(options);
464
- const { responseHeaders, value: response, rawValue: rawResponse } = await require_dist.postJsonToApi({
465
- url: this.config.url({
466
- path: "/chat/completions",
467
- modelId: this.modelId
468
- }),
469
- headers: require_dist.combineHeaders(this.config.headers(), options.headers),
470
- body,
471
- failedResponseHandler: openaiFailedResponseHandler,
472
- successfulResponseHandler: require_dist.createJsonResponseHandler(openaiChatResponseSchema),
473
- abortSignal: options.abortSignal,
474
- fetch: this.config.fetch
475
- });
476
- const { messages: rawPrompt, ...rawSettings } = body;
477
- const choice = response.choices[0];
478
- const completionTokenDetails = (_a = response.usage) == null ? void 0 : _a.completion_tokens_details;
479
- const promptTokenDetails = (_b = response.usage) == null ? void 0 : _b.prompt_tokens_details;
480
- const providerMetadata = { openai: {} };
481
- if ((completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null) providerMetadata.openai.reasoningTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens;
482
- if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
483
- if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
484
- if ((promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null) providerMetadata.openai.cachedPromptTokens = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens;
485
- return {
486
- text: (_c = choice.message.content) != null ? _c : void 0,
487
- toolCalls: this.settings.useLegacyFunctionCalling && choice.message.function_call ? [{
488
- toolCallType: "function",
489
- toolCallId: require_dist.generateId(),
490
- toolName: choice.message.function_call.name,
491
- args: choice.message.function_call.arguments
492
- }] : (_d = choice.message.tool_calls) == null ? void 0 : _d.map((toolCall) => {
493
- var _a2;
494
- return {
495
- toolCallType: "function",
496
- toolCallId: (_a2 = toolCall.id) != null ? _a2 : require_dist.generateId(),
497
- toolName: toolCall.function.name,
498
- args: toolCall.function.arguments
499
- };
500
- }),
501
- finishReason: mapOpenAIFinishReason(choice.finish_reason),
502
- usage: {
503
- promptTokens: (_f = (_e = response.usage) == null ? void 0 : _e.prompt_tokens) != null ? _f : NaN,
504
- completionTokens: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : NaN
505
- },
506
- rawCall: {
507
- rawPrompt,
508
- rawSettings
509
- },
510
- rawResponse: {
511
- headers: responseHeaders,
512
- body: rawResponse
513
- },
514
- request: { body: JSON.stringify(body) },
515
- response: getResponseMetadata(response),
516
- warnings,
517
- logprobs: mapOpenAIChatLogProbsOutput(choice.logprobs),
518
- providerMetadata
519
- };
520
- }
521
- async doStream(options) {
522
- if (this.settings.simulateStreaming) {
523
- const result = await this.doGenerate(options);
524
- return {
525
- stream: new ReadableStream({ start(controller) {
526
- controller.enqueue({
527
- type: "response-metadata",
528
- ...result.response
529
- });
530
- if (result.text) controller.enqueue({
531
- type: "text-delta",
532
- textDelta: result.text
533
- });
534
- if (result.toolCalls) for (const toolCall of result.toolCalls) {
535
- controller.enqueue({
536
- type: "tool-call-delta",
537
- toolCallType: "function",
538
- toolCallId: toolCall.toolCallId,
539
- toolName: toolCall.toolName,
540
- argsTextDelta: toolCall.args
541
- });
542
- controller.enqueue({
543
- type: "tool-call",
544
- ...toolCall
545
- });
546
- }
547
- controller.enqueue({
548
- type: "finish",
549
- finishReason: result.finishReason,
550
- usage: result.usage,
551
- logprobs: result.logprobs,
552
- providerMetadata: result.providerMetadata
553
- });
554
- controller.close();
555
- } }),
556
- rawCall: result.rawCall,
557
- rawResponse: result.rawResponse,
558
- warnings: result.warnings
559
- };
560
- }
561
- const { args, warnings } = this.getArgs(options);
562
- const body = {
563
- ...args,
564
- stream: true,
565
- stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
566
- };
567
- const { responseHeaders, value: response } = await require_dist.postJsonToApi({
568
- url: this.config.url({
569
- path: "/chat/completions",
570
- modelId: this.modelId
571
- }),
572
- headers: require_dist.combineHeaders(this.config.headers(), options.headers),
573
- body,
574
- failedResponseHandler: openaiFailedResponseHandler,
575
- successfulResponseHandler: require_dist.createEventSourceResponseHandler(openaiChatChunkSchema),
576
- abortSignal: options.abortSignal,
577
- fetch: this.config.fetch
578
- });
579
- const { messages: rawPrompt, ...rawSettings } = args;
580
- const toolCalls = [];
581
- let finishReason = "unknown";
582
- let usage = {
583
- promptTokens: void 0,
584
- completionTokens: void 0
585
- };
586
- let logprobs;
587
- let isFirstChunk = true;
588
- const { useLegacyFunctionCalling } = this.settings;
589
- const providerMetadata = { openai: {} };
590
- return {
591
- stream: response.pipeThrough(new TransformStream({
592
- transform(chunk, controller) {
593
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
594
- if (!chunk.success) {
595
- finishReason = "error";
596
- controller.enqueue({
597
- type: "error",
598
- error: chunk.error
599
- });
600
- return;
601
- }
602
- const value = chunk.value;
603
- if ("error" in value) {
604
- finishReason = "error";
605
- controller.enqueue({
606
- type: "error",
607
- error: value.error
608
- });
609
- return;
610
- }
611
- if (isFirstChunk) {
612
- isFirstChunk = false;
613
- controller.enqueue({
614
- type: "response-metadata",
615
- ...getResponseMetadata(value)
616
- });
617
- }
618
- if (value.usage != null) {
619
- const { prompt_tokens, completion_tokens, prompt_tokens_details, completion_tokens_details } = value.usage;
620
- usage = {
621
- promptTokens: prompt_tokens != null ? prompt_tokens : void 0,
622
- completionTokens: completion_tokens != null ? completion_tokens : void 0
623
- };
624
- if ((completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens) != null) providerMetadata.openai.reasoningTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens;
625
- if ((completion_tokens_details == null ? void 0 : completion_tokens_details.accepted_prediction_tokens) != null) providerMetadata.openai.acceptedPredictionTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.accepted_prediction_tokens;
626
- if ((completion_tokens_details == null ? void 0 : completion_tokens_details.rejected_prediction_tokens) != null) providerMetadata.openai.rejectedPredictionTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.rejected_prediction_tokens;
627
- if ((prompt_tokens_details == null ? void 0 : prompt_tokens_details.cached_tokens) != null) providerMetadata.openai.cachedPromptTokens = prompt_tokens_details == null ? void 0 : prompt_tokens_details.cached_tokens;
628
- }
629
- const choice = value.choices[0];
630
- if ((choice == null ? void 0 : choice.finish_reason) != null) finishReason = mapOpenAIFinishReason(choice.finish_reason);
631
- if ((choice == null ? void 0 : choice.delta) == null) return;
632
- const delta = choice.delta;
633
- if (delta.content != null) controller.enqueue({
634
- type: "text-delta",
635
- textDelta: delta.content
636
- });
637
- const mappedLogprobs = mapOpenAIChatLogProbsOutput(choice == null ? void 0 : choice.logprobs);
638
- if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
639
- if (logprobs === void 0) logprobs = [];
640
- logprobs.push(...mappedLogprobs);
641
- }
642
- const mappedToolCalls = useLegacyFunctionCalling && delta.function_call != null ? [{
643
- type: "function",
644
- id: require_dist.generateId(),
645
- function: delta.function_call,
646
- index: 0
647
- }] : delta.tool_calls;
648
- if (mappedToolCalls != null) for (const toolCallDelta of mappedToolCalls) {
649
- const index = toolCallDelta.index;
650
- if (toolCalls[index] == null) {
651
- if (toolCallDelta.type !== "function") throw new require_dist.InvalidResponseDataError({
652
- data: toolCallDelta,
653
- message: `Expected 'function' type.`
654
- });
655
- if (toolCallDelta.id == null) throw new require_dist.InvalidResponseDataError({
656
- data: toolCallDelta,
657
- message: `Expected 'id' to be a string.`
658
- });
659
- if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) throw new require_dist.InvalidResponseDataError({
660
- data: toolCallDelta,
661
- message: `Expected 'function.name' to be a string.`
662
- });
663
- toolCalls[index] = {
664
- id: toolCallDelta.id,
665
- type: "function",
666
- function: {
667
- name: toolCallDelta.function.name,
668
- arguments: (_b = toolCallDelta.function.arguments) != null ? _b : ""
669
- },
670
- hasFinished: false
671
- };
672
- const toolCall2 = toolCalls[index];
673
- if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null) {
674
- if (toolCall2.function.arguments.length > 0) controller.enqueue({
675
- type: "tool-call-delta",
676
- toolCallType: "function",
677
- toolCallId: toolCall2.id,
678
- toolName: toolCall2.function.name,
679
- argsTextDelta: toolCall2.function.arguments
680
- });
681
- if (require_dist.isParsableJson(toolCall2.function.arguments)) {
682
- controller.enqueue({
683
- type: "tool-call",
684
- toolCallType: "function",
685
- toolCallId: (_e = toolCall2.id) != null ? _e : require_dist.generateId(),
686
- toolName: toolCall2.function.name,
687
- args: toolCall2.function.arguments
688
- });
689
- toolCall2.hasFinished = true;
690
- }
691
- }
692
- continue;
693
- }
694
- const toolCall = toolCalls[index];
695
- if (toolCall.hasFinished) continue;
696
- if (((_f = toolCallDelta.function) == null ? void 0 : _f.arguments) != null) toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : "";
697
- controller.enqueue({
698
- type: "tool-call-delta",
699
- toolCallType: "function",
700
- toolCallId: toolCall.id,
701
- toolName: toolCall.function.name,
702
- argsTextDelta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
703
- });
704
- if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && require_dist.isParsableJson(toolCall.function.arguments)) {
705
- controller.enqueue({
706
- type: "tool-call",
707
- toolCallType: "function",
708
- toolCallId: (_l = toolCall.id) != null ? _l : require_dist.generateId(),
709
- toolName: toolCall.function.name,
710
- args: toolCall.function.arguments
711
- });
712
- toolCall.hasFinished = true;
713
- }
714
- }
715
- },
716
- flush(controller) {
717
- var _a, _b;
718
- controller.enqueue({
719
- type: "finish",
720
- finishReason,
721
- logprobs,
722
- usage: {
723
- promptTokens: (_a = usage.promptTokens) != null ? _a : NaN,
724
- completionTokens: (_b = usage.completionTokens) != null ? _b : NaN
725
- },
726
- ...providerMetadata != null ? { providerMetadata } : {}
727
- });
728
- }
729
- })),
730
- rawCall: {
731
- rawPrompt,
732
- rawSettings
733
- },
734
- rawResponse: { headers: responseHeaders },
735
- request: { body: JSON.stringify(body) },
736
- warnings
737
- };
738
- }
739
- };
740
- var openaiTokenUsageSchema = zod.z.object({
741
- prompt_tokens: zod.z.number().nullish(),
742
- completion_tokens: zod.z.number().nullish(),
743
- prompt_tokens_details: zod.z.object({ cached_tokens: zod.z.number().nullish() }).nullish(),
744
- completion_tokens_details: zod.z.object({
745
- reasoning_tokens: zod.z.number().nullish(),
746
- accepted_prediction_tokens: zod.z.number().nullish(),
747
- rejected_prediction_tokens: zod.z.number().nullish()
748
- }).nullish()
749
- }).nullish();
750
- var openaiChatResponseSchema = zod.z.object({
751
- id: zod.z.string().nullish(),
752
- created: zod.z.number().nullish(),
753
- model: zod.z.string().nullish(),
754
- choices: zod.z.array(zod.z.object({
755
- message: zod.z.object({
756
- role: zod.z.literal("assistant").nullish(),
757
- content: zod.z.string().nullish(),
758
- function_call: zod.z.object({
759
- arguments: zod.z.string(),
760
- name: zod.z.string()
761
- }).nullish(),
762
- tool_calls: zod.z.array(zod.z.object({
763
- id: zod.z.string().nullish(),
764
- type: zod.z.literal("function"),
765
- function: zod.z.object({
766
- name: zod.z.string(),
767
- arguments: zod.z.string()
768
- })
769
- })).nullish()
770
- }),
771
- index: zod.z.number(),
772
- logprobs: zod.z.object({ content: zod.z.array(zod.z.object({
773
- token: zod.z.string(),
774
- logprob: zod.z.number(),
775
- top_logprobs: zod.z.array(zod.z.object({
776
- token: zod.z.string(),
777
- logprob: zod.z.number()
778
- }))
779
- })).nullable() }).nullish(),
780
- finish_reason: zod.z.string().nullish()
781
- })),
782
- usage: openaiTokenUsageSchema
783
- });
784
- var openaiChatChunkSchema = zod.z.union([zod.z.object({
785
- id: zod.z.string().nullish(),
786
- created: zod.z.number().nullish(),
787
- model: zod.z.string().nullish(),
788
- choices: zod.z.array(zod.z.object({
789
- delta: zod.z.object({
790
- role: zod.z.enum(["assistant"]).nullish(),
791
- content: zod.z.string().nullish(),
792
- function_call: zod.z.object({
793
- name: zod.z.string().optional(),
794
- arguments: zod.z.string().optional()
795
- }).nullish(),
796
- tool_calls: zod.z.array(zod.z.object({
797
- index: zod.z.number(),
798
- id: zod.z.string().nullish(),
799
- type: zod.z.literal("function").nullish(),
800
- function: zod.z.object({
801
- name: zod.z.string().nullish(),
802
- arguments: zod.z.string().nullish()
803
- })
804
- })).nullish()
805
- }).nullish(),
806
- logprobs: zod.z.object({ content: zod.z.array(zod.z.object({
807
- token: zod.z.string(),
808
- logprob: zod.z.number(),
809
- top_logprobs: zod.z.array(zod.z.object({
810
- token: zod.z.string(),
811
- logprob: zod.z.number()
812
- }))
813
- })).nullable() }).nullish(),
814
- finish_reason: zod.z.string().nullish(),
815
- index: zod.z.number()
816
- })),
817
- usage: openaiTokenUsageSchema
818
- }), openaiErrorDataSchema]);
819
- function isReasoningModel(modelId) {
820
- return modelId.startsWith("o") || modelId.startsWith("gpt-5");
821
- }
822
- function isAudioModel(modelId) {
823
- return modelId.startsWith("gpt-4o-audio-preview");
824
- }
825
- function getSystemMessageMode(modelId) {
826
- var _a, _b;
827
- if (!isReasoningModel(modelId)) return "system";
828
- return (_b = (_a = reasoningModels[modelId]) == null ? void 0 : _a.systemMessageMode) != null ? _b : "developer";
829
- }
830
- var reasoningModels = {
831
- "o1-mini": { systemMessageMode: "remove" },
832
- "o1-mini-2024-09-12": { systemMessageMode: "remove" },
833
- "o1-preview": { systemMessageMode: "remove" },
834
- "o1-preview-2024-09-12": { systemMessageMode: "remove" },
835
- o3: { systemMessageMode: "developer" },
836
- "o3-2025-04-16": { systemMessageMode: "developer" },
837
- "o3-mini": { systemMessageMode: "developer" },
838
- "o3-mini-2025-01-31": { systemMessageMode: "developer" },
839
- "o4-mini": { systemMessageMode: "developer" },
840
- "o4-mini-2025-04-16": { systemMessageMode: "developer" }
841
- };
842
- function convertToOpenAICompletionPrompt({ prompt, inputFormat, user = "user", assistant = "assistant" }) {
843
- if (inputFormat === "prompt" && prompt.length === 1 && prompt[0].role === "user" && prompt[0].content.length === 1 && prompt[0].content[0].type === "text") return { prompt: prompt[0].content[0].text };
844
- let text = "";
845
- if (prompt[0].role === "system") {
846
- text += `${prompt[0].content}
847
-
848
- `;
849
- prompt = prompt.slice(1);
850
- }
851
- for (const { role, content } of prompt) switch (role) {
852
- case "system": throw new require_dist.InvalidPromptError({
853
- message: "Unexpected system message in prompt: ${content}",
854
- prompt
855
- });
856
- case "user": {
857
- const userMessage = content.map((part) => {
858
- switch (part.type) {
859
- case "text": return part.text;
860
- case "image": throw new require_dist.UnsupportedFunctionalityError({ functionality: "images" });
861
- }
862
- }).join("");
863
- text += `${user}:
864
- ${userMessage}
865
-
866
- `;
867
- break;
868
- }
869
- case "assistant": {
870
- const assistantMessage = content.map((part) => {
871
- switch (part.type) {
872
- case "text": return part.text;
873
- case "tool-call": throw new require_dist.UnsupportedFunctionalityError({ functionality: "tool-call messages" });
874
- }
875
- }).join("");
876
- text += `${assistant}:
877
- ${assistantMessage}
878
-
879
- `;
880
- break;
881
- }
882
- case "tool": throw new require_dist.UnsupportedFunctionalityError({ functionality: "tool messages" });
883
- default: throw new Error(`Unsupported role: ${role}`);
884
- }
885
- text += `${assistant}:
886
- `;
887
- return {
888
- prompt: text,
889
- stopSequences: [`
890
- ${user}:`]
891
- };
892
- }
893
- function mapOpenAICompletionLogProbs(logprobs) {
894
- return logprobs == null ? void 0 : logprobs.tokens.map((token, index) => ({
895
- token,
896
- logprob: logprobs.token_logprobs[index],
897
- topLogprobs: logprobs.top_logprobs ? Object.entries(logprobs.top_logprobs[index]).map(([token2, logprob]) => ({
898
- token: token2,
899
- logprob
900
- })) : []
901
- }));
902
- }
903
- var OpenAICompletionLanguageModel = class {
904
- constructor(modelId, settings, config) {
905
- this.specificationVersion = "v1";
906
- this.defaultObjectGenerationMode = void 0;
907
- this.modelId = modelId;
908
- this.settings = settings;
909
- this.config = config;
910
- }
911
- get provider() {
912
- return this.config.provider;
913
- }
914
- getArgs({ mode, inputFormat, prompt, maxTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences: userStopSequences, responseFormat, seed }) {
915
- var _a;
916
- const type = mode.type;
917
- const warnings = [];
918
- if (topK != null) warnings.push({
919
- type: "unsupported-setting",
920
- setting: "topK"
921
- });
922
- if (responseFormat != null && responseFormat.type !== "text") warnings.push({
923
- type: "unsupported-setting",
924
- setting: "responseFormat",
925
- details: "JSON response format is not supported."
926
- });
927
- const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({
928
- prompt,
929
- inputFormat
930
- });
931
- const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
932
- const baseArgs = {
933
- model: this.modelId,
934
- echo: this.settings.echo,
935
- logit_bias: this.settings.logitBias,
936
- logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
937
- suffix: this.settings.suffix,
938
- user: this.settings.user,
939
- max_tokens: maxTokens,
940
- temperature,
941
- top_p: topP,
942
- frequency_penalty: frequencyPenalty,
943
- presence_penalty: presencePenalty,
944
- seed,
945
- prompt: completionPrompt,
946
- stop: stop.length > 0 ? stop : void 0
947
- };
948
- switch (type) {
949
- case "regular":
950
- if ((_a = mode.tools) == null ? void 0 : _a.length) throw new require_dist.UnsupportedFunctionalityError({ functionality: "tools" });
951
- if (mode.toolChoice) throw new require_dist.UnsupportedFunctionalityError({ functionality: "toolChoice" });
952
- return {
953
- args: baseArgs,
954
- warnings
955
- };
956
- case "object-json": throw new require_dist.UnsupportedFunctionalityError({ functionality: "object-json mode" });
957
- case "object-tool": throw new require_dist.UnsupportedFunctionalityError({ functionality: "object-tool mode" });
958
- default: throw new Error(`Unsupported type: ${type}`);
959
- }
960
- }
961
- async doGenerate(options) {
962
- const { args, warnings } = this.getArgs(options);
963
- const { responseHeaders, value: response, rawValue: rawResponse } = await require_dist.postJsonToApi({
964
- url: this.config.url({
965
- path: "/completions",
966
- modelId: this.modelId
967
- }),
968
- headers: require_dist.combineHeaders(this.config.headers(), options.headers),
969
- body: args,
970
- failedResponseHandler: openaiFailedResponseHandler,
971
- successfulResponseHandler: require_dist.createJsonResponseHandler(openaiCompletionResponseSchema),
972
- abortSignal: options.abortSignal,
973
- fetch: this.config.fetch
974
- });
975
- const { prompt: rawPrompt, ...rawSettings } = args;
976
- const choice = response.choices[0];
977
- return {
978
- text: choice.text,
979
- usage: {
980
- promptTokens: response.usage.prompt_tokens,
981
- completionTokens: response.usage.completion_tokens
982
- },
983
- finishReason: mapOpenAIFinishReason(choice.finish_reason),
984
- logprobs: mapOpenAICompletionLogProbs(choice.logprobs),
985
- rawCall: {
986
- rawPrompt,
987
- rawSettings
988
- },
989
- rawResponse: {
990
- headers: responseHeaders,
991
- body: rawResponse
992
- },
993
- response: getResponseMetadata(response),
994
- warnings,
995
- request: { body: JSON.stringify(args) }
996
- };
997
- }
998
- async doStream(options) {
999
- const { args, warnings } = this.getArgs(options);
1000
- const body = {
1001
- ...args,
1002
- stream: true,
1003
- stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
1004
- };
1005
- const { responseHeaders, value: response } = await require_dist.postJsonToApi({
1006
- url: this.config.url({
1007
- path: "/completions",
1008
- modelId: this.modelId
1009
- }),
1010
- headers: require_dist.combineHeaders(this.config.headers(), options.headers),
1011
- body,
1012
- failedResponseHandler: openaiFailedResponseHandler,
1013
- successfulResponseHandler: require_dist.createEventSourceResponseHandler(openaiCompletionChunkSchema),
1014
- abortSignal: options.abortSignal,
1015
- fetch: this.config.fetch
1016
- });
1017
- const { prompt: rawPrompt, ...rawSettings } = args;
1018
- let finishReason = "unknown";
1019
- let usage = {
1020
- promptTokens: NaN,
1021
- completionTokens: NaN
1022
- };
1023
- let logprobs;
1024
- let isFirstChunk = true;
1025
- return {
1026
- stream: response.pipeThrough(new TransformStream({
1027
- transform(chunk, controller) {
1028
- if (!chunk.success) {
1029
- finishReason = "error";
1030
- controller.enqueue({
1031
- type: "error",
1032
- error: chunk.error
1033
- });
1034
- return;
1035
- }
1036
- const value = chunk.value;
1037
- if ("error" in value) {
1038
- finishReason = "error";
1039
- controller.enqueue({
1040
- type: "error",
1041
- error: value.error
1042
- });
1043
- return;
1044
- }
1045
- if (isFirstChunk) {
1046
- isFirstChunk = false;
1047
- controller.enqueue({
1048
- type: "response-metadata",
1049
- ...getResponseMetadata(value)
1050
- });
1051
- }
1052
- if (value.usage != null) usage = {
1053
- promptTokens: value.usage.prompt_tokens,
1054
- completionTokens: value.usage.completion_tokens
1055
- };
1056
- const choice = value.choices[0];
1057
- if ((choice == null ? void 0 : choice.finish_reason) != null) finishReason = mapOpenAIFinishReason(choice.finish_reason);
1058
- if ((choice == null ? void 0 : choice.text) != null) controller.enqueue({
1059
- type: "text-delta",
1060
- textDelta: choice.text
1061
- });
1062
- const mappedLogprobs = mapOpenAICompletionLogProbs(choice == null ? void 0 : choice.logprobs);
1063
- if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
1064
- if (logprobs === void 0) logprobs = [];
1065
- logprobs.push(...mappedLogprobs);
1066
- }
1067
- },
1068
- flush(controller) {
1069
- controller.enqueue({
1070
- type: "finish",
1071
- finishReason,
1072
- logprobs,
1073
- usage
1074
- });
1075
- }
1076
- })),
1077
- rawCall: {
1078
- rawPrompt,
1079
- rawSettings
1080
- },
1081
- rawResponse: { headers: responseHeaders },
1082
- warnings,
1083
- request: { body: JSON.stringify(body) }
1084
- };
1085
- }
1086
- };
1087
- var openaiCompletionResponseSchema = zod.z.object({
1088
- id: zod.z.string().nullish(),
1089
- created: zod.z.number().nullish(),
1090
- model: zod.z.string().nullish(),
1091
- choices: zod.z.array(zod.z.object({
1092
- text: zod.z.string(),
1093
- finish_reason: zod.z.string(),
1094
- logprobs: zod.z.object({
1095
- tokens: zod.z.array(zod.z.string()),
1096
- token_logprobs: zod.z.array(zod.z.number()),
1097
- top_logprobs: zod.z.array(zod.z.record(zod.z.string(), zod.z.number())).nullable()
1098
- }).nullish()
1099
- })),
1100
- usage: zod.z.object({
1101
- prompt_tokens: zod.z.number(),
1102
- completion_tokens: zod.z.number()
1103
- })
1104
- });
1105
- var openaiCompletionChunkSchema = zod.z.union([zod.z.object({
1106
- id: zod.z.string().nullish(),
1107
- created: zod.z.number().nullish(),
1108
- model: zod.z.string().nullish(),
1109
- choices: zod.z.array(zod.z.object({
1110
- text: zod.z.string(),
1111
- finish_reason: zod.z.string().nullish(),
1112
- index: zod.z.number(),
1113
- logprobs: zod.z.object({
1114
- tokens: zod.z.array(zod.z.string()),
1115
- token_logprobs: zod.z.array(zod.z.number()),
1116
- top_logprobs: zod.z.array(zod.z.record(zod.z.string(), zod.z.number())).nullable()
1117
- }).nullish()
1118
- })),
1119
- usage: zod.z.object({
1120
- prompt_tokens: zod.z.number(),
1121
- completion_tokens: zod.z.number()
1122
- }).nullish()
1123
- }), openaiErrorDataSchema]);
1124
- var OpenAIEmbeddingModel = class {
1125
- constructor(modelId, settings, config) {
1126
- this.specificationVersion = "v1";
1127
- this.modelId = modelId;
1128
- this.settings = settings;
1129
- this.config = config;
1130
- }
1131
- get provider() {
1132
- return this.config.provider;
1133
- }
1134
- get maxEmbeddingsPerCall() {
1135
- var _a;
1136
- return (_a = this.settings.maxEmbeddingsPerCall) != null ? _a : 2048;
1137
- }
1138
- get supportsParallelCalls() {
1139
- var _a;
1140
- return (_a = this.settings.supportsParallelCalls) != null ? _a : true;
1141
- }
1142
- async doEmbed({ values, headers, abortSignal }) {
1143
- if (values.length > this.maxEmbeddingsPerCall) throw new require_dist.TooManyEmbeddingValuesForCallError({
1144
- provider: this.provider,
1145
- modelId: this.modelId,
1146
- maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
1147
- values
1148
- });
1149
- const { responseHeaders, value: response } = await require_dist.postJsonToApi({
1150
- url: this.config.url({
1151
- path: "/embeddings",
1152
- modelId: this.modelId
1153
- }),
1154
- headers: require_dist.combineHeaders(this.config.headers(), headers),
1155
- body: {
1156
- model: this.modelId,
1157
- input: values,
1158
- encoding_format: "float",
1159
- dimensions: this.settings.dimensions,
1160
- user: this.settings.user
1161
- },
1162
- failedResponseHandler: openaiFailedResponseHandler,
1163
- successfulResponseHandler: require_dist.createJsonResponseHandler(openaiTextEmbeddingResponseSchema),
1164
- abortSignal,
1165
- fetch: this.config.fetch
1166
- });
1167
- return {
1168
- embeddings: response.data.map((item) => item.embedding),
1169
- usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
1170
- rawResponse: { headers: responseHeaders }
1171
- };
1172
- }
1173
- };
1174
- var openaiTextEmbeddingResponseSchema = zod.z.object({
1175
- data: zod.z.array(zod.z.object({ embedding: zod.z.array(zod.z.number()) })),
1176
- usage: zod.z.object({ prompt_tokens: zod.z.number() }).nullish()
1177
- });
1178
- var modelMaxImagesPerCall = {
1179
- "dall-e-3": 1,
1180
- "dall-e-2": 10,
1181
- "gpt-image-1": 10
1182
- };
1183
- var hasDefaultResponseFormat = /* @__PURE__ */ new Set(["gpt-image-1"]);
1184
- var OpenAIImageModel = class {
1185
- constructor(modelId, settings, config) {
1186
- this.modelId = modelId;
1187
- this.settings = settings;
1188
- this.config = config;
1189
- this.specificationVersion = "v1";
1190
- }
1191
- get maxImagesPerCall() {
1192
- var _a, _b;
1193
- return (_b = (_a = this.settings.maxImagesPerCall) != null ? _a : modelMaxImagesPerCall[this.modelId]) != null ? _b : 1;
1194
- }
1195
- get provider() {
1196
- return this.config.provider;
1197
- }
1198
- async doGenerate({ prompt, n, size, aspectRatio, seed, providerOptions, headers, abortSignal }) {
1199
- var _a, _b, _c, _d;
1200
- const warnings = [];
1201
- if (aspectRatio != null) warnings.push({
1202
- type: "unsupported-setting",
1203
- setting: "aspectRatio",
1204
- details: "This model does not support aspect ratio. Use `size` instead."
1205
- });
1206
- if (seed != null) warnings.push({
1207
- type: "unsupported-setting",
1208
- setting: "seed"
1209
- });
1210
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1211
- const { value: response, responseHeaders } = await require_dist.postJsonToApi({
1212
- url: this.config.url({
1213
- path: "/images/generations",
1214
- modelId: this.modelId
1215
- }),
1216
- headers: require_dist.combineHeaders(this.config.headers(), headers),
1217
- body: {
1218
- model: this.modelId,
1219
- prompt,
1220
- n,
1221
- size,
1222
- ...(_d = providerOptions.openai) != null ? _d : {},
1223
- ...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
1224
- },
1225
- failedResponseHandler: openaiFailedResponseHandler,
1226
- successfulResponseHandler: require_dist.createJsonResponseHandler(openaiImageResponseSchema),
1227
- abortSignal,
1228
- fetch: this.config.fetch
1229
- });
1230
- return {
1231
- images: response.data.map((item) => item.b64_json),
1232
- warnings,
1233
- response: {
1234
- timestamp: currentDate,
1235
- modelId: this.modelId,
1236
- headers: responseHeaders
1237
- }
1238
- };
1239
- }
1240
- };
1241
- var openaiImageResponseSchema = zod.z.object({ data: zod.z.array(zod.z.object({ b64_json: zod.z.string() })) });
1242
- var openAIProviderOptionsSchema = zod.z.object({
1243
- include: zod.z.array(zod.z.string()).nullish(),
1244
- language: zod.z.string().nullish(),
1245
- prompt: zod.z.string().nullish(),
1246
- temperature: zod.z.number().min(0).max(1).nullish().default(0),
1247
- timestampGranularities: zod.z.array(zod.z.enum(["word", "segment"])).nullish().default(["segment"])
1248
- });
1249
- var languageMap = {
1250
- afrikaans: "af",
1251
- arabic: "ar",
1252
- armenian: "hy",
1253
- azerbaijani: "az",
1254
- belarusian: "be",
1255
- bosnian: "bs",
1256
- bulgarian: "bg",
1257
- catalan: "ca",
1258
- chinese: "zh",
1259
- croatian: "hr",
1260
- czech: "cs",
1261
- danish: "da",
1262
- dutch: "nl",
1263
- english: "en",
1264
- estonian: "et",
1265
- finnish: "fi",
1266
- french: "fr",
1267
- galician: "gl",
1268
- german: "de",
1269
- greek: "el",
1270
- hebrew: "he",
1271
- hindi: "hi",
1272
- hungarian: "hu",
1273
- icelandic: "is",
1274
- indonesian: "id",
1275
- italian: "it",
1276
- japanese: "ja",
1277
- kannada: "kn",
1278
- kazakh: "kk",
1279
- korean: "ko",
1280
- latvian: "lv",
1281
- lithuanian: "lt",
1282
- macedonian: "mk",
1283
- malay: "ms",
1284
- marathi: "mr",
1285
- maori: "mi",
1286
- nepali: "ne",
1287
- norwegian: "no",
1288
- persian: "fa",
1289
- polish: "pl",
1290
- portuguese: "pt",
1291
- romanian: "ro",
1292
- russian: "ru",
1293
- serbian: "sr",
1294
- slovak: "sk",
1295
- slovenian: "sl",
1296
- spanish: "es",
1297
- swahili: "sw",
1298
- swedish: "sv",
1299
- tagalog: "tl",
1300
- tamil: "ta",
1301
- thai: "th",
1302
- turkish: "tr",
1303
- ukrainian: "uk",
1304
- urdu: "ur",
1305
- vietnamese: "vi",
1306
- welsh: "cy"
1307
- };
1308
- var OpenAITranscriptionModel = class {
1309
- constructor(modelId, config) {
1310
- this.modelId = modelId;
1311
- this.config = config;
1312
- this.specificationVersion = "v1";
1313
- }
1314
- get provider() {
1315
- return this.config.provider;
1316
- }
1317
- getArgs({ audio, mediaType, providerOptions }) {
1318
- var _a, _b, _c, _d, _e;
1319
- const warnings = [];
1320
- const openAIOptions = require_dist.parseProviderOptions({
1321
- provider: "openai",
1322
- providerOptions,
1323
- schema: openAIProviderOptionsSchema
1324
- });
1325
- const formData = new FormData();
1326
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([require_dist.convertBase64ToUint8Array(audio)]);
1327
- formData.append("model", this.modelId);
1328
- formData.append("file", new File([blob], "audio", { type: mediaType }));
1329
- if (openAIOptions) {
1330
- const transcriptionModelOptions = {
1331
- include: (_a = openAIOptions.include) != null ? _a : void 0,
1332
- language: (_b = openAIOptions.language) != null ? _b : void 0,
1333
- prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
1334
- temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
1335
- timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
1336
- };
1337
- for (const key in transcriptionModelOptions) {
1338
- const value = transcriptionModelOptions[key];
1339
- if (value !== void 0) formData.append(key, String(value));
1340
- }
1341
- }
1342
- return {
1343
- formData,
1344
- warnings
1345
- };
1346
- }
1347
- async doGenerate(options) {
1348
- var _a, _b, _c, _d, _e, _f;
1349
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1350
- const { formData, warnings } = this.getArgs(options);
1351
- const { value: response, responseHeaders, rawValue: rawResponse } = await require_dist.postFormDataToApi({
1352
- url: this.config.url({
1353
- path: "/audio/transcriptions",
1354
- modelId: this.modelId
1355
- }),
1356
- headers: require_dist.combineHeaders(this.config.headers(), options.headers),
1357
- formData,
1358
- failedResponseHandler: openaiFailedResponseHandler,
1359
- successfulResponseHandler: require_dist.createJsonResponseHandler(openaiTranscriptionResponseSchema),
1360
- abortSignal: options.abortSignal,
1361
- fetch: this.config.fetch
1362
- });
1363
- const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
1364
- return {
1365
- text: response.text,
1366
- segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
1367
- text: word.word,
1368
- startSecond: word.start,
1369
- endSecond: word.end
1370
- }))) != null ? _e : [],
1371
- language,
1372
- durationInSeconds: (_f = response.duration) != null ? _f : void 0,
1373
- warnings,
1374
- response: {
1375
- timestamp: currentDate,
1376
- modelId: this.modelId,
1377
- headers: responseHeaders,
1378
- body: rawResponse
1379
- }
1380
- };
1381
- }
1382
- };
1383
- var openaiTranscriptionResponseSchema = zod.z.object({
1384
- text: zod.z.string(),
1385
- language: zod.z.string().nullish(),
1386
- duration: zod.z.number().nullish(),
1387
- words: zod.z.array(zod.z.object({
1388
- word: zod.z.string(),
1389
- start: zod.z.number(),
1390
- end: zod.z.number()
1391
- })).nullish()
1392
- });
1393
- function convertToOpenAIResponsesMessages({ prompt, systemMessageMode }) {
1394
- const messages = [];
1395
- const warnings = [];
1396
- for (const { role, content } of prompt) switch (role) {
1397
- case "system":
1398
- switch (systemMessageMode) {
1399
- case "system":
1400
- messages.push({
1401
- role: "system",
1402
- content
1403
- });
1404
- break;
1405
- case "developer":
1406
- messages.push({
1407
- role: "developer",
1408
- content
1409
- });
1410
- break;
1411
- case "remove":
1412
- warnings.push({
1413
- type: "other",
1414
- message: "system messages are removed for this model"
1415
- });
1416
- break;
1417
- default: throw new Error(`Unsupported system message mode: ${systemMessageMode}`);
1418
- }
1419
- break;
1420
- case "user":
1421
- messages.push({
1422
- role: "user",
1423
- content: content.map((part, index) => {
1424
- var _a, _b, _c, _d;
1425
- switch (part.type) {
1426
- case "text": return {
1427
- type: "input_text",
1428
- text: part.text
1429
- };
1430
- case "image": return {
1431
- type: "input_image",
1432
- image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${require_dist.convertUint8ArrayToBase64(part.image)}`,
1433
- detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
1434
- };
1435
- case "file":
1436
- if (part.data instanceof URL) throw new require_dist.UnsupportedFunctionalityError({ functionality: "File URLs in user messages" });
1437
- switch (part.mimeType) {
1438
- case "application/pdf": return {
1439
- type: "input_file",
1440
- filename: (_d = part.filename) != null ? _d : `part-${index}.pdf`,
1441
- file_data: `data:application/pdf;base64,${part.data}`
1442
- };
1443
- default: throw new require_dist.UnsupportedFunctionalityError({ functionality: "Only PDF files are supported in user messages" });
1444
- }
1445
- }
1446
- })
1447
- });
1448
- break;
1449
- case "assistant":
1450
- for (const part of content) switch (part.type) {
1451
- case "text":
1452
- messages.push({
1453
- role: "assistant",
1454
- content: [{
1455
- type: "output_text",
1456
- text: part.text
1457
- }]
1458
- });
1459
- break;
1460
- case "tool-call":
1461
- messages.push({
1462
- type: "function_call",
1463
- call_id: part.toolCallId,
1464
- name: part.toolName,
1465
- arguments: JSON.stringify(part.args)
1466
- });
1467
- break;
1468
- }
1469
- break;
1470
- case "tool":
1471
- for (const part of content) messages.push({
1472
- type: "function_call_output",
1473
- call_id: part.toolCallId,
1474
- output: JSON.stringify(part.result)
1475
- });
1476
- break;
1477
- default: throw new Error(`Unsupported role: ${role}`);
1478
- }
1479
- return {
1480
- messages,
1481
- warnings
1482
- };
1483
- }
1484
- function mapOpenAIResponseFinishReason({ finishReason, hasToolCalls }) {
1485
- switch (finishReason) {
1486
- case void 0:
1487
- case null: return hasToolCalls ? "tool-calls" : "stop";
1488
- case "max_output_tokens": return "length";
1489
- case "content_filter": return "content-filter";
1490
- default: return hasToolCalls ? "tool-calls" : "unknown";
1491
- }
1492
- }
1493
- function prepareResponsesTools({ mode, strict }) {
1494
- var _a;
1495
- const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
1496
- const toolWarnings = [];
1497
- if (tools == null) return {
1498
- tools: void 0,
1499
- tool_choice: void 0,
1500
- toolWarnings
1501
- };
1502
- const toolChoice = mode.toolChoice;
1503
- const openaiTools2 = [];
1504
- for (const tool of tools) switch (tool.type) {
1505
- case "function":
1506
- openaiTools2.push({
1507
- type: "function",
1508
- name: tool.name,
1509
- description: tool.description,
1510
- parameters: tool.parameters,
1511
- strict: strict ? true : void 0
1512
- });
1513
- break;
1514
- case "provider-defined":
1515
- switch (tool.id) {
1516
- case "openai.web_search_preview":
1517
- openaiTools2.push({
1518
- type: "web_search_preview",
1519
- search_context_size: tool.args.searchContextSize,
1520
- user_location: tool.args.userLocation
1521
- });
1522
- break;
1523
- default:
1524
- toolWarnings.push({
1525
- type: "unsupported-tool",
1526
- tool
1527
- });
1528
- break;
1529
- }
1530
- break;
1531
- default:
1532
- toolWarnings.push({
1533
- type: "unsupported-tool",
1534
- tool
1535
- });
1536
- break;
1537
- }
1538
- if (toolChoice == null) return {
1539
- tools: openaiTools2,
1540
- tool_choice: void 0,
1541
- toolWarnings
1542
- };
1543
- const type = toolChoice.type;
1544
- switch (type) {
1545
- case "auto":
1546
- case "none":
1547
- case "required": return {
1548
- tools: openaiTools2,
1549
- tool_choice: type,
1550
- toolWarnings
1551
- };
1552
- case "tool":
1553
- if (toolChoice.toolName === "web_search_preview") return {
1554
- tools: openaiTools2,
1555
- tool_choice: { type: "web_search_preview" },
1556
- toolWarnings
1557
- };
1558
- return {
1559
- tools: openaiTools2,
1560
- tool_choice: {
1561
- type: "function",
1562
- name: toolChoice.toolName
1563
- },
1564
- toolWarnings
1565
- };
1566
- default: throw new require_dist.UnsupportedFunctionalityError({ functionality: `Unsupported tool choice type: ${type}` });
1567
- }
1568
- }
1569
- var OpenAIResponsesLanguageModel = class {
1570
- constructor(modelId, config) {
1571
- this.specificationVersion = "v1";
1572
- this.defaultObjectGenerationMode = "json";
1573
- this.supportsStructuredOutputs = true;
1574
- this.modelId = modelId;
1575
- this.config = config;
1576
- }
1577
- get provider() {
1578
- return this.config.provider;
1579
- }
1580
- getArgs({ mode, maxTokens, temperature, stopSequences, topP, topK, presencePenalty, frequencyPenalty, seed, prompt, providerMetadata, responseFormat }) {
1581
- var _a, _b, _c;
1582
- const warnings = [];
1583
- const modelConfig = getResponsesModelConfig(this.modelId);
1584
- const type = mode.type;
1585
- if (topK != null) warnings.push({
1586
- type: "unsupported-setting",
1587
- setting: "topK"
1588
- });
1589
- if (seed != null) warnings.push({
1590
- type: "unsupported-setting",
1591
- setting: "seed"
1592
- });
1593
- if (presencePenalty != null) warnings.push({
1594
- type: "unsupported-setting",
1595
- setting: "presencePenalty"
1596
- });
1597
- if (frequencyPenalty != null) warnings.push({
1598
- type: "unsupported-setting",
1599
- setting: "frequencyPenalty"
1600
- });
1601
- if (stopSequences != null) warnings.push({
1602
- type: "unsupported-setting",
1603
- setting: "stopSequences"
1604
- });
1605
- const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
1606
- prompt,
1607
- systemMessageMode: modelConfig.systemMessageMode
1608
- });
1609
- warnings.push(...messageWarnings);
1610
- const openaiOptions = require_dist.parseProviderOptions({
1611
- provider: "openai",
1612
- providerOptions: providerMetadata,
1613
- schema: openaiResponsesProviderOptionsSchema
1614
- });
1615
- const isStrict = (_a = openaiOptions == null ? void 0 : openaiOptions.strictSchemas) != null ? _a : true;
1616
- const baseArgs = {
1617
- model: this.modelId,
1618
- input: messages,
1619
- temperature,
1620
- top_p: topP,
1621
- max_output_tokens: maxTokens,
1622
- ...(responseFormat == null ? void 0 : responseFormat.type) === "json" && { text: { format: responseFormat.schema != null ? {
1623
- type: "json_schema",
1624
- strict: isStrict,
1625
- name: (_b = responseFormat.name) != null ? _b : "response",
1626
- description: responseFormat.description,
1627
- schema: responseFormat.schema
1628
- } : { type: "json_object" } } },
1629
- metadata: openaiOptions == null ? void 0 : openaiOptions.metadata,
1630
- parallel_tool_calls: openaiOptions == null ? void 0 : openaiOptions.parallelToolCalls,
1631
- previous_response_id: openaiOptions == null ? void 0 : openaiOptions.previousResponseId,
1632
- store: openaiOptions == null ? void 0 : openaiOptions.store,
1633
- user: openaiOptions == null ? void 0 : openaiOptions.user,
1634
- instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
1635
- ...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && { reasoning: {
1636
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && { effort: openaiOptions.reasoningEffort },
1637
- ...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && { summary: openaiOptions.reasoningSummary }
1638
- } },
1639
- ...modelConfig.requiredAutoTruncation && { truncation: "auto" }
1640
- };
1641
- if (modelConfig.isReasoningModel) {
1642
- if (baseArgs.temperature != null) {
1643
- baseArgs.temperature = void 0;
1644
- warnings.push({
1645
- type: "unsupported-setting",
1646
- setting: "temperature",
1647
- details: "temperature is not supported for reasoning models"
1648
- });
1649
- }
1650
- if (baseArgs.top_p != null) {
1651
- baseArgs.top_p = void 0;
1652
- warnings.push({
1653
- type: "unsupported-setting",
1654
- setting: "topP",
1655
- details: "topP is not supported for reasoning models"
1656
- });
1657
- }
1658
- }
1659
- switch (type) {
1660
- case "regular": {
1661
- const { tools, tool_choice, toolWarnings } = prepareResponsesTools({
1662
- mode,
1663
- strict: isStrict
1664
- });
1665
- return {
1666
- args: {
1667
- ...baseArgs,
1668
- tools,
1669
- tool_choice
1670
- },
1671
- warnings: [...warnings, ...toolWarnings]
1672
- };
1673
- }
1674
- case "object-json": return {
1675
- args: {
1676
- ...baseArgs,
1677
- text: { format: mode.schema != null ? {
1678
- type: "json_schema",
1679
- strict: isStrict,
1680
- name: (_c = mode.name) != null ? _c : "response",
1681
- description: mode.description,
1682
- schema: mode.schema
1683
- } : { type: "json_object" } }
1684
- },
1685
- warnings
1686
- };
1687
- case "object-tool": return {
1688
- args: {
1689
- ...baseArgs,
1690
- tool_choice: {
1691
- type: "function",
1692
- name: mode.tool.name
1693
- },
1694
- tools: [{
1695
- type: "function",
1696
- name: mode.tool.name,
1697
- description: mode.tool.description,
1698
- parameters: mode.tool.parameters,
1699
- strict: isStrict
1700
- }]
1701
- },
1702
- warnings
1703
- };
1704
- default: throw new Error(`Unsupported type: ${type}`);
1705
- }
1706
- }
1707
- async doGenerate(options) {
1708
- var _a, _b, _c, _d, _e, _f, _g;
1709
- const { args: body, warnings } = this.getArgs(options);
1710
- const url = this.config.url({
1711
- path: "/responses",
1712
- modelId: this.modelId
1713
- });
1714
- const { responseHeaders, value: response, rawValue: rawResponse } = await require_dist.postJsonToApi({
1715
- url,
1716
- headers: require_dist.combineHeaders(this.config.headers(), options.headers),
1717
- body,
1718
- failedResponseHandler: openaiFailedResponseHandler,
1719
- successfulResponseHandler: require_dist.createJsonResponseHandler(zod.z.object({
1720
- id: zod.z.string(),
1721
- created_at: zod.z.number(),
1722
- error: zod.z.object({
1723
- message: zod.z.string(),
1724
- code: zod.z.string()
1725
- }).nullish(),
1726
- model: zod.z.string(),
1727
- output: zod.z.array(zod.z.discriminatedUnion("type", [
1728
- zod.z.object({
1729
- type: zod.z.literal("message"),
1730
- role: zod.z.literal("assistant"),
1731
- content: zod.z.array(zod.z.object({
1732
- type: zod.z.literal("output_text"),
1733
- text: zod.z.string(),
1734
- annotations: zod.z.array(zod.z.object({
1735
- type: zod.z.literal("url_citation"),
1736
- start_index: zod.z.number(),
1737
- end_index: zod.z.number(),
1738
- url: zod.z.string(),
1739
- title: zod.z.string()
1740
- }))
1741
- }))
1742
- }),
1743
- zod.z.object({
1744
- type: zod.z.literal("function_call"),
1745
- call_id: zod.z.string(),
1746
- name: zod.z.string(),
1747
- arguments: zod.z.string()
1748
- }),
1749
- zod.z.object({ type: zod.z.literal("web_search_call") }),
1750
- zod.z.object({ type: zod.z.literal("computer_call") }),
1751
- zod.z.object({
1752
- type: zod.z.literal("reasoning"),
1753
- summary: zod.z.array(zod.z.object({
1754
- type: zod.z.literal("summary_text"),
1755
- text: zod.z.string()
1756
- }))
1757
- })
1758
- ])),
1759
- incomplete_details: zod.z.object({ reason: zod.z.string() }).nullable(),
1760
- usage: usageSchema
1761
- })),
1762
- abortSignal: options.abortSignal,
1763
- fetch: this.config.fetch
1764
- });
1765
- if (response.error) throw new require_dist.APICallError({
1766
- message: response.error.message,
1767
- url,
1768
- requestBodyValues: body,
1769
- statusCode: 400,
1770
- responseHeaders,
1771
- responseBody: rawResponse,
1772
- isRetryable: false
1773
- });
1774
- const outputTextElements = response.output.filter((output) => output.type === "message").flatMap((output) => output.content).filter((content) => content.type === "output_text");
1775
- const toolCalls = response.output.filter((output) => output.type === "function_call").map((output) => ({
1776
- toolCallType: "function",
1777
- toolCallId: output.call_id,
1778
- toolName: output.name,
1779
- args: output.arguments
1780
- }));
1781
- const reasoningSummary = (_b = (_a = response.output.find((item) => item.type === "reasoning")) == null ? void 0 : _a.summary) != null ? _b : null;
1782
- return {
1783
- text: outputTextElements.map((content) => content.text).join("\n"),
1784
- sources: outputTextElements.flatMap((content) => content.annotations.map((annotation) => {
1785
- var _a2, _b2, _c2;
1786
- return {
1787
- sourceType: "url",
1788
- id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : require_dist.generateId(),
1789
- url: annotation.url,
1790
- title: annotation.title
1791
- };
1792
- })),
1793
- finishReason: mapOpenAIResponseFinishReason({
1794
- finishReason: (_c = response.incomplete_details) == null ? void 0 : _c.reason,
1795
- hasToolCalls: toolCalls.length > 0
1796
- }),
1797
- toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
1798
- reasoning: reasoningSummary ? reasoningSummary.map((summary) => ({
1799
- type: "text",
1800
- text: summary.text
1801
- })) : void 0,
1802
- usage: {
1803
- promptTokens: response.usage.input_tokens,
1804
- completionTokens: response.usage.output_tokens
1805
- },
1806
- rawCall: {
1807
- rawPrompt: void 0,
1808
- rawSettings: {}
1809
- },
1810
- rawResponse: {
1811
- headers: responseHeaders,
1812
- body: rawResponse
1813
- },
1814
- request: { body: JSON.stringify(body) },
1815
- response: {
1816
- id: response.id,
1817
- timestamp: /* @__PURE__ */ new Date(response.created_at * 1e3),
1818
- modelId: response.model
1819
- },
1820
- providerMetadata: { openai: {
1821
- responseId: response.id,
1822
- cachedPromptTokens: (_e = (_d = response.usage.input_tokens_details) == null ? void 0 : _d.cached_tokens) != null ? _e : null,
1823
- reasoningTokens: (_g = (_f = response.usage.output_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : null
1824
- } },
1825
- warnings
1826
- };
1827
- }
1828
- async doStream(options) {
1829
- const { args: body, warnings } = this.getArgs(options);
1830
- const { responseHeaders, value: response } = await require_dist.postJsonToApi({
1831
- url: this.config.url({
1832
- path: "/responses",
1833
- modelId: this.modelId
1834
- }),
1835
- headers: require_dist.combineHeaders(this.config.headers(), options.headers),
1836
- body: {
1837
- ...body,
1838
- stream: true
1839
- },
1840
- failedResponseHandler: openaiFailedResponseHandler,
1841
- successfulResponseHandler: require_dist.createEventSourceResponseHandler(openaiResponsesChunkSchema),
1842
- abortSignal: options.abortSignal,
1843
- fetch: this.config.fetch
1844
- });
1845
- const self = this;
1846
- let finishReason = "unknown";
1847
- let promptTokens = NaN;
1848
- let completionTokens = NaN;
1849
- let cachedPromptTokens = null;
1850
- let reasoningTokens = null;
1851
- let responseId = null;
1852
- const ongoingToolCalls = {};
1853
- let hasToolCalls = false;
1854
- return {
1855
- stream: response.pipeThrough(new TransformStream({
1856
- transform(chunk, controller) {
1857
- var _a, _b, _c, _d, _e, _f, _g, _h;
1858
- if (!chunk.success) {
1859
- finishReason = "error";
1860
- controller.enqueue({
1861
- type: "error",
1862
- error: chunk.error
1863
- });
1864
- return;
1865
- }
1866
- const value = chunk.value;
1867
- if (isResponseOutputItemAddedChunk(value)) {
1868
- if (value.item.type === "function_call") {
1869
- ongoingToolCalls[value.output_index] = {
1870
- toolName: value.item.name,
1871
- toolCallId: value.item.call_id
1872
- };
1873
- controller.enqueue({
1874
- type: "tool-call-delta",
1875
- toolCallType: "function",
1876
- toolCallId: value.item.call_id,
1877
- toolName: value.item.name,
1878
- argsTextDelta: value.item.arguments
1879
- });
1880
- }
1881
- } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
1882
- const toolCall = ongoingToolCalls[value.output_index];
1883
- if (toolCall != null) controller.enqueue({
1884
- type: "tool-call-delta",
1885
- toolCallType: "function",
1886
- toolCallId: toolCall.toolCallId,
1887
- toolName: toolCall.toolName,
1888
- argsTextDelta: value.delta
1889
- });
1890
- } else if (isResponseCreatedChunk(value)) {
1891
- responseId = value.response.id;
1892
- controller.enqueue({
1893
- type: "response-metadata",
1894
- id: value.response.id,
1895
- timestamp: /* @__PURE__ */ new Date(value.response.created_at * 1e3),
1896
- modelId: value.response.model
1897
- });
1898
- } else if (isTextDeltaChunk(value)) controller.enqueue({
1899
- type: "text-delta",
1900
- textDelta: value.delta
1901
- });
1902
- else if (isResponseReasoningSummaryTextDeltaChunk(value)) controller.enqueue({
1903
- type: "reasoning",
1904
- textDelta: value.delta
1905
- });
1906
- else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
1907
- ongoingToolCalls[value.output_index] = void 0;
1908
- hasToolCalls = true;
1909
- controller.enqueue({
1910
- type: "tool-call",
1911
- toolCallType: "function",
1912
- toolCallId: value.item.call_id,
1913
- toolName: value.item.name,
1914
- args: value.item.arguments
1915
- });
1916
- } else if (isResponseFinishedChunk(value)) {
1917
- finishReason = mapOpenAIResponseFinishReason({
1918
- finishReason: (_a = value.response.incomplete_details) == null ? void 0 : _a.reason,
1919
- hasToolCalls
1920
- });
1921
- promptTokens = value.response.usage.input_tokens;
1922
- completionTokens = value.response.usage.output_tokens;
1923
- cachedPromptTokens = (_c = (_b = value.response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : cachedPromptTokens;
1924
- reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : reasoningTokens;
1925
- } else if (isResponseAnnotationAddedChunk(value)) controller.enqueue({
1926
- type: "source",
1927
- source: {
1928
- sourceType: "url",
1929
- id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : require_dist.generateId(),
1930
- url: value.annotation.url,
1931
- title: value.annotation.title
1932
- }
1933
- });
1934
- else if (isErrorChunk(value)) controller.enqueue({
1935
- type: "error",
1936
- error: value
1937
- });
1938
- },
1939
- flush(controller) {
1940
- controller.enqueue({
1941
- type: "finish",
1942
- finishReason,
1943
- usage: {
1944
- promptTokens,
1945
- completionTokens
1946
- },
1947
- ...(cachedPromptTokens != null || reasoningTokens != null) && { providerMetadata: { openai: {
1948
- responseId,
1949
- cachedPromptTokens,
1950
- reasoningTokens
1951
- } } }
1952
- });
1953
- }
1954
- })),
1955
- rawCall: {
1956
- rawPrompt: void 0,
1957
- rawSettings: {}
1958
- },
1959
- rawResponse: { headers: responseHeaders },
1960
- request: { body: JSON.stringify(body) },
1961
- warnings
1962
- };
1963
- }
1964
- };
1965
- var usageSchema = zod.z.object({
1966
- input_tokens: zod.z.number(),
1967
- input_tokens_details: zod.z.object({ cached_tokens: zod.z.number().nullish() }).nullish(),
1968
- output_tokens: zod.z.number(),
1969
- output_tokens_details: zod.z.object({ reasoning_tokens: zod.z.number().nullish() }).nullish()
1970
- });
1971
- var textDeltaChunkSchema = zod.z.object({
1972
- type: zod.z.literal("response.output_text.delta"),
1973
- delta: zod.z.string()
1974
- });
1975
- var responseFinishedChunkSchema = zod.z.object({
1976
- type: zod.z.enum(["response.completed", "response.incomplete"]),
1977
- response: zod.z.object({
1978
- incomplete_details: zod.z.object({ reason: zod.z.string() }).nullish(),
1979
- usage: usageSchema
1980
- })
1981
- });
1982
- var responseCreatedChunkSchema = zod.z.object({
1983
- type: zod.z.literal("response.created"),
1984
- response: zod.z.object({
1985
- id: zod.z.string(),
1986
- created_at: zod.z.number(),
1987
- model: zod.z.string()
1988
- })
1989
- });
1990
- var responseOutputItemDoneSchema = zod.z.object({
1991
- type: zod.z.literal("response.output_item.done"),
1992
- output_index: zod.z.number(),
1993
- item: zod.z.discriminatedUnion("type", [zod.z.object({ type: zod.z.literal("message") }), zod.z.object({
1994
- type: zod.z.literal("function_call"),
1995
- id: zod.z.string(),
1996
- call_id: zod.z.string(),
1997
- name: zod.z.string(),
1998
- arguments: zod.z.string(),
1999
- status: zod.z.literal("completed")
2000
- })])
2001
- });
2002
- var responseFunctionCallArgumentsDeltaSchema = zod.z.object({
2003
- type: zod.z.literal("response.function_call_arguments.delta"),
2004
- item_id: zod.z.string(),
2005
- output_index: zod.z.number(),
2006
- delta: zod.z.string()
2007
- });
2008
- var responseOutputItemAddedSchema = zod.z.object({
2009
- type: zod.z.literal("response.output_item.added"),
2010
- output_index: zod.z.number(),
2011
- item: zod.z.discriminatedUnion("type", [zod.z.object({ type: zod.z.literal("message") }), zod.z.object({
2012
- type: zod.z.literal("function_call"),
2013
- id: zod.z.string(),
2014
- call_id: zod.z.string(),
2015
- name: zod.z.string(),
2016
- arguments: zod.z.string()
2017
- })])
2018
- });
2019
- var responseAnnotationAddedSchema = zod.z.object({
2020
- type: zod.z.literal("response.output_text.annotation.added"),
2021
- annotation: zod.z.object({
2022
- type: zod.z.literal("url_citation"),
2023
- url: zod.z.string(),
2024
- title: zod.z.string()
2025
- })
2026
- });
2027
- var responseReasoningSummaryTextDeltaSchema = zod.z.object({
2028
- type: zod.z.literal("response.reasoning_summary_text.delta"),
2029
- item_id: zod.z.string(),
2030
- output_index: zod.z.number(),
2031
- summary_index: zod.z.number(),
2032
- delta: zod.z.string()
2033
- });
2034
- var errorChunkSchema = zod.z.object({
2035
- type: zod.z.literal("error"),
2036
- code: zod.z.string(),
2037
- message: zod.z.string(),
2038
- param: zod.z.string().nullish(),
2039
- sequence_number: zod.z.number()
2040
- });
2041
- var openaiResponsesChunkSchema = zod.z.union([
2042
- textDeltaChunkSchema,
2043
- responseFinishedChunkSchema,
2044
- responseCreatedChunkSchema,
2045
- responseOutputItemDoneSchema,
2046
- responseFunctionCallArgumentsDeltaSchema,
2047
- responseOutputItemAddedSchema,
2048
- responseAnnotationAddedSchema,
2049
- responseReasoningSummaryTextDeltaSchema,
2050
- errorChunkSchema,
2051
- zod.z.object({ type: zod.z.string() }).passthrough()
2052
- ]);
2053
- function isTextDeltaChunk(chunk) {
2054
- return chunk.type === "response.output_text.delta";
2055
- }
2056
- function isResponseOutputItemDoneChunk(chunk) {
2057
- return chunk.type === "response.output_item.done";
2058
- }
2059
- function isResponseFinishedChunk(chunk) {
2060
- return chunk.type === "response.completed" || chunk.type === "response.incomplete";
2061
- }
2062
- function isResponseCreatedChunk(chunk) {
2063
- return chunk.type === "response.created";
2064
- }
2065
- function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
2066
- return chunk.type === "response.function_call_arguments.delta";
2067
- }
2068
- function isResponseOutputItemAddedChunk(chunk) {
2069
- return chunk.type === "response.output_item.added";
2070
- }
2071
- function isResponseAnnotationAddedChunk(chunk) {
2072
- return chunk.type === "response.output_text.annotation.added";
2073
- }
2074
- function isResponseReasoningSummaryTextDeltaChunk(chunk) {
2075
- return chunk.type === "response.reasoning_summary_text.delta";
2076
- }
2077
- function isErrorChunk(chunk) {
2078
- return chunk.type === "error";
2079
- }
2080
- function getResponsesModelConfig(modelId) {
2081
- if (modelId.startsWith("o") || modelId.startsWith("gpt-5")) {
2082
- if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) return {
2083
- isReasoningModel: true,
2084
- systemMessageMode: "remove",
2085
- requiredAutoTruncation: false
2086
- };
2087
- return {
2088
- isReasoningModel: true,
2089
- systemMessageMode: "developer",
2090
- requiredAutoTruncation: false
2091
- };
2092
- }
2093
- return {
2094
- isReasoningModel: false,
2095
- systemMessageMode: "system",
2096
- requiredAutoTruncation: false
2097
- };
2098
- }
2099
- var openaiResponsesProviderOptionsSchema = zod.z.object({
2100
- metadata: zod.z.any().nullish(),
2101
- parallelToolCalls: zod.z.boolean().nullish(),
2102
- previousResponseId: zod.z.string().nullish(),
2103
- store: zod.z.boolean().nullish(),
2104
- user: zod.z.string().nullish(),
2105
- reasoningEffort: zod.z.string().nullish(),
2106
- strictSchemas: zod.z.boolean().nullish(),
2107
- instructions: zod.z.string().nullish(),
2108
- reasoningSummary: zod.z.string().nullish()
2109
- });
2110
- var WebSearchPreviewParameters = zod.z.object({});
2111
- function webSearchPreviewTool({ searchContextSize, userLocation } = {}) {
2112
- return {
2113
- type: "provider-defined",
2114
- id: "openai.web_search_preview",
2115
- args: {
2116
- searchContextSize,
2117
- userLocation
2118
- },
2119
- parameters: WebSearchPreviewParameters
2120
- };
2121
- }
2122
- var openaiTools = { webSearchPreview: webSearchPreviewTool };
2123
- var OpenAIProviderOptionsSchema = zod.z.object({
2124
- instructions: zod.z.string().nullish(),
2125
- speed: zod.z.number().min(.25).max(4).default(1).nullish()
2126
- });
2127
- var OpenAISpeechModel = class {
2128
- constructor(modelId, config) {
2129
- this.modelId = modelId;
2130
- this.config = config;
2131
- this.specificationVersion = "v1";
2132
- }
2133
- get provider() {
2134
- return this.config.provider;
2135
- }
2136
- getArgs({ text, voice = "alloy", outputFormat = "mp3", speed, instructions, providerOptions }) {
2137
- const warnings = [];
2138
- const openAIOptions = require_dist.parseProviderOptions({
2139
- provider: "openai",
2140
- providerOptions,
2141
- schema: OpenAIProviderOptionsSchema
2142
- });
2143
- const requestBody = {
2144
- model: this.modelId,
2145
- input: text,
2146
- voice,
2147
- response_format: "mp3",
2148
- speed,
2149
- instructions
2150
- };
2151
- if (outputFormat) if ([
2152
- "mp3",
2153
- "opus",
2154
- "aac",
2155
- "flac",
2156
- "wav",
2157
- "pcm"
2158
- ].includes(outputFormat)) requestBody.response_format = outputFormat;
2159
- else warnings.push({
2160
- type: "unsupported-setting",
2161
- setting: "outputFormat",
2162
- details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
2163
- });
2164
- if (openAIOptions) {
2165
- const speechModelOptions = {};
2166
- for (const key in speechModelOptions) {
2167
- const value = speechModelOptions[key];
2168
- if (value !== void 0) requestBody[key] = value;
2169
- }
2170
- }
2171
- return {
2172
- requestBody,
2173
- warnings
2174
- };
2175
- }
2176
- async doGenerate(options) {
2177
- var _a, _b, _c;
2178
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2179
- const { requestBody, warnings } = this.getArgs(options);
2180
- const { value: audio, responseHeaders, rawValue: rawResponse } = await require_dist.postJsonToApi({
2181
- url: this.config.url({
2182
- path: "/audio/speech",
2183
- modelId: this.modelId
2184
- }),
2185
- headers: require_dist.combineHeaders(this.config.headers(), options.headers),
2186
- body: requestBody,
2187
- failedResponseHandler: openaiFailedResponseHandler,
2188
- successfulResponseHandler: require_dist.createBinaryResponseHandler(),
2189
- abortSignal: options.abortSignal,
2190
- fetch: this.config.fetch
2191
- });
2192
- return {
2193
- audio,
2194
- warnings,
2195
- request: { body: JSON.stringify(requestBody) },
2196
- response: {
2197
- timestamp: currentDate,
2198
- modelId: this.modelId,
2199
- headers: responseHeaders,
2200
- body: rawResponse
2201
- }
2202
- };
2203
- }
2204
- };
2205
- function createOpenAI(options = {}) {
2206
- var _a, _b, _c;
2207
- const baseURL = (_a = require_dist.withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
2208
- const compatibility = (_b = options.compatibility) != null ? _b : "compatible";
2209
- const providerName = (_c = options.name) != null ? _c : "openai";
2210
- const getHeaders = () => ({
2211
- Authorization: `Bearer ${require_dist.loadApiKey({
2212
- apiKey: options.apiKey,
2213
- environmentVariableName: "OPENAI_API_KEY",
2214
- description: "OpenAI"
2215
- })}`,
2216
- "OpenAI-Organization": options.organization,
2217
- "OpenAI-Project": options.project,
2218
- ...options.headers
2219
- });
2220
- const createChatModel = (modelId, settings = {}) => new OpenAIChatLanguageModel(modelId, settings, {
2221
- provider: `${providerName}.chat`,
2222
- url: ({ path }) => `${baseURL}${path}`,
2223
- headers: getHeaders,
2224
- compatibility,
2225
- fetch: options.fetch
2226
- });
2227
- const createCompletionModel = (modelId, settings = {}) => new OpenAICompletionLanguageModel(modelId, settings, {
2228
- provider: `${providerName}.completion`,
2229
- url: ({ path }) => `${baseURL}${path}`,
2230
- headers: getHeaders,
2231
- compatibility,
2232
- fetch: options.fetch
2233
- });
2234
- const createEmbeddingModel = (modelId, settings = {}) => new OpenAIEmbeddingModel(modelId, settings, {
2235
- provider: `${providerName}.embedding`,
2236
- url: ({ path }) => `${baseURL}${path}`,
2237
- headers: getHeaders,
2238
- fetch: options.fetch
2239
- });
2240
- const createImageModel = (modelId, settings = {}) => new OpenAIImageModel(modelId, settings, {
2241
- provider: `${providerName}.image`,
2242
- url: ({ path }) => `${baseURL}${path}`,
2243
- headers: getHeaders,
2244
- fetch: options.fetch
2245
- });
2246
- const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
2247
- provider: `${providerName}.transcription`,
2248
- url: ({ path }) => `${baseURL}${path}`,
2249
- headers: getHeaders,
2250
- fetch: options.fetch
2251
- });
2252
- const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
2253
- provider: `${providerName}.speech`,
2254
- url: ({ path }) => `${baseURL}${path}`,
2255
- headers: getHeaders,
2256
- fetch: options.fetch
2257
- });
2258
- const createLanguageModel = (modelId, settings) => {
2259
- if (new.target) throw new Error("The OpenAI model function cannot be called with the new keyword.");
2260
- if (modelId === "gpt-3.5-turbo-instruct") return createCompletionModel(modelId, settings);
2261
- return createChatModel(modelId, settings);
2262
- };
2263
- const createResponsesModel = (modelId) => {
2264
- return new OpenAIResponsesLanguageModel(modelId, {
2265
- provider: `${providerName}.responses`,
2266
- url: ({ path }) => `${baseURL}${path}`,
2267
- headers: getHeaders,
2268
- fetch: options.fetch
2269
- });
2270
- };
2271
- const provider = function(modelId, settings) {
2272
- return createLanguageModel(modelId, settings);
2273
- };
2274
- provider.languageModel = createLanguageModel;
2275
- provider.chat = createChatModel;
2276
- provider.completion = createCompletionModel;
2277
- provider.responses = createResponsesModel;
2278
- provider.embedding = createEmbeddingModel;
2279
- provider.textEmbedding = createEmbeddingModel;
2280
- provider.textEmbeddingModel = createEmbeddingModel;
2281
- provider.image = createImageModel;
2282
- provider.imageModel = createImageModel;
2283
- provider.transcription = createTranscriptionModel;
2284
- provider.transcriptionModel = createTranscriptionModel;
2285
- provider.speech = createSpeechModel;
2286
- provider.speechModel = createSpeechModel;
2287
- provider.tools = openaiTools;
2288
- return provider;
2289
- }
2290
- var openai = createOpenAI({ compatibility: "strict" });
2291
- //#endregion
2292
- exports.openai = openai;
2293
-
2294
- //# sourceMappingURL=dist-B5OwHWTo.cjs.map