@mastra/server 0.0.0-message-list-update-20250715150321 → 0.0.0-monorepo-binary-20251013210052

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 (279) hide show
  1. package/CHANGELOG.md +4009 -0
  2. package/README.md +0 -5
  3. package/dist/chunk-2PLXW4ZX.cjs +2777 -0
  4. package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
  5. package/dist/chunk-2S4IMB6E.cjs +130 -0
  6. package/dist/chunk-2S4IMB6E.cjs.map +1 -0
  7. package/dist/chunk-3LGGSMCC.cjs +256 -0
  8. package/dist/chunk-3LGGSMCC.cjs.map +1 -0
  9. package/dist/chunk-3LTO44EP.cjs +570 -0
  10. package/dist/chunk-3LTO44EP.cjs.map +1 -0
  11. package/dist/chunk-3SNGNFUJ.cjs +128 -0
  12. package/dist/chunk-3SNGNFUJ.cjs.map +1 -0
  13. package/dist/{chunk-RSEO4XPX.js → chunk-4QCXUEAT.js} +11 -2
  14. package/dist/chunk-4QCXUEAT.js.map +1 -0
  15. package/dist/chunk-5BNQIYQN.js +189 -0
  16. package/dist/chunk-5BNQIYQN.js.map +1 -0
  17. package/dist/{chunk-RG473F6Y.js → chunk-67GYDFSB.js} +24 -5
  18. package/dist/chunk-67GYDFSB.js.map +1 -0
  19. package/dist/chunk-6BMOC6SA.cjs +48 -0
  20. package/dist/chunk-6BMOC6SA.cjs.map +1 -0
  21. package/dist/{chunk-G7KH752Y.cjs → chunk-6ZR275MD.cjs} +28 -8
  22. package/dist/chunk-6ZR275MD.cjs.map +1 -0
  23. package/dist/{chunk-2KZFMI6P.cjs → chunk-7NADHFD2.cjs} +2 -0
  24. package/dist/chunk-7NADHFD2.cjs.map +1 -0
  25. package/dist/{chunk-4D66QEKC.js → chunk-ABRFV4XP.js} +5 -3
  26. package/dist/chunk-ABRFV4XP.js.map +1 -0
  27. package/dist/{chunk-LRCAAFUA.js → chunk-AHB4JCIQ.js} +50 -12
  28. package/dist/chunk-AHB4JCIQ.js.map +1 -0
  29. package/dist/chunk-BATEJLED.js +124 -0
  30. package/dist/chunk-BATEJLED.js.map +1 -0
  31. package/dist/chunk-BZLZFHAT.cjs +682 -0
  32. package/dist/chunk-BZLZFHAT.cjs.map +1 -0
  33. package/dist/{chunk-LF7P5PLR.js → chunk-CY4TP3FK.js} +3 -1
  34. package/dist/chunk-CY4TP3FK.js.map +1 -0
  35. package/dist/{chunk-H7DMHBKY.js → chunk-DB63UMTV.js} +249 -87
  36. package/dist/chunk-DB63UMTV.js.map +1 -0
  37. package/dist/chunk-DTBJ3D22.js +19480 -0
  38. package/dist/chunk-DTBJ3D22.js.map +1 -0
  39. package/dist/{chunk-7TP2LX5L.cjs → chunk-EP3JQDPD.cjs} +20 -18
  40. package/dist/chunk-EP3JQDPD.cjs.map +1 -0
  41. package/dist/chunk-G4PUALCE.cjs +28 -0
  42. package/dist/chunk-G4PUALCE.cjs.map +1 -0
  43. package/dist/chunk-GU4EWMZB.cjs +769 -0
  44. package/dist/chunk-GU4EWMZB.cjs.map +1 -0
  45. package/dist/chunk-H2CO44WB.js +46 -0
  46. package/dist/chunk-H2CO44WB.js.map +1 -0
  47. package/dist/{chunk-GHC4YV6R.js → chunk-HPXAM2PG.js} +109 -136
  48. package/dist/chunk-HPXAM2PG.js.map +1 -0
  49. package/dist/{chunk-JMLYCXMK.cjs → chunk-I3C4ODGV.cjs} +48 -45
  50. package/dist/chunk-I3C4ODGV.cjs.map +1 -0
  51. package/dist/chunk-JSLAYFEW.js +662 -0
  52. package/dist/chunk-JSLAYFEW.js.map +1 -0
  53. package/dist/chunk-KQZPT7AO.js +254 -0
  54. package/dist/chunk-KQZPT7AO.js.map +1 -0
  55. package/dist/chunk-LF2ZLOFP.js +767 -0
  56. package/dist/chunk-LF2ZLOFP.js.map +1 -0
  57. package/dist/{chunk-5PQQ42EZ.js → chunk-LLUOPR3J.js} +13 -10
  58. package/dist/chunk-LLUOPR3J.js.map +1 -0
  59. package/dist/chunk-LNT5N7XW.cjs +197 -0
  60. package/dist/chunk-LNT5N7XW.cjs.map +1 -0
  61. package/dist/chunk-LPM6BBAX.cjs +1043 -0
  62. package/dist/chunk-LPM6BBAX.cjs.map +1 -0
  63. package/dist/{chunk-LCM566I4.js → chunk-MMROOK5J.js} +2 -0
  64. package/dist/chunk-MMROOK5J.js.map +1 -0
  65. package/dist/chunk-MQDBNHBT.cjs +680 -0
  66. package/dist/chunk-MQDBNHBT.cjs.map +1 -0
  67. package/dist/{chunk-WNVFNNWN.js → chunk-MYR4PVGN.js} +5 -3
  68. package/dist/chunk-MYR4PVGN.js.map +1 -0
  69. package/dist/chunk-O7I5CWRX.cjs +44 -0
  70. package/dist/chunk-O7I5CWRX.cjs.map +1 -0
  71. package/dist/chunk-OEOGYAQC.js +553 -0
  72. package/dist/chunk-OEOGYAQC.js.map +1 -0
  73. package/dist/chunk-PR4QN5HX.js +39 -0
  74. package/dist/chunk-PR4QN5HX.js.map +1 -0
  75. package/dist/{chunk-KHZKYUNR.js → chunk-QQXMIP6C.js} +23 -13
  76. package/dist/chunk-QQXMIP6C.js.map +1 -0
  77. package/dist/{chunk-PZQDCRPV.cjs → chunk-RE4RPXT2.cjs} +4 -2
  78. package/dist/chunk-RE4RPXT2.cjs.map +1 -0
  79. package/dist/chunk-RQK4FQUD.js +1012 -0
  80. package/dist/chunk-RQK4FQUD.js.map +1 -0
  81. package/dist/chunk-SBWOUCO3.cjs +19516 -0
  82. package/dist/chunk-SBWOUCO3.cjs.map +1 -0
  83. package/dist/{chunk-SDPGVWQJ.cjs → chunk-TOP25AIO.cjs} +110 -137
  84. package/dist/chunk-TOP25AIO.cjs.map +1 -0
  85. package/dist/chunk-TRGAMKHX.cjs +167 -0
  86. package/dist/chunk-TRGAMKHX.cjs.map +1 -0
  87. package/dist/chunk-VY4ENABS.cjs +135 -0
  88. package/dist/chunk-VY4ENABS.cjs.map +1 -0
  89. package/dist/{chunk-QGX47B5D.cjs → chunk-XN74I6VW.cjs} +11 -9
  90. package/dist/chunk-XN74I6VW.cjs.map +1 -0
  91. package/dist/chunk-YWOK4F5A.js +131 -0
  92. package/dist/chunk-YWOK4F5A.js.map +1 -0
  93. package/dist/chunk-ZULZ2752.js +2774 -0
  94. package/dist/chunk-ZULZ2752.js.map +1 -0
  95. package/dist/dist-4MVGNSRL.cjs +1150 -0
  96. package/dist/dist-4MVGNSRL.cjs.map +1 -0
  97. package/dist/dist-FZYCV3VB.cjs +940 -0
  98. package/dist/dist-FZYCV3VB.cjs.map +1 -0
  99. package/dist/dist-G2BYZJOC.cjs +928 -0
  100. package/dist/dist-G2BYZJOC.cjs.map +1 -0
  101. package/dist/dist-P4MXBQ3U.cjs +16 -0
  102. package/dist/dist-P4MXBQ3U.cjs.map +1 -0
  103. package/dist/dist-PQZUVLPC.js +937 -0
  104. package/dist/dist-PQZUVLPC.js.map +1 -0
  105. package/dist/dist-R7WYX6LC.js +925 -0
  106. package/dist/dist-R7WYX6LC.js.map +1 -0
  107. package/dist/dist-RFMYFILX.cjs +764 -0
  108. package/dist/dist-RFMYFILX.cjs.map +1 -0
  109. package/dist/dist-X7XR3M3Z.js +1147 -0
  110. package/dist/dist-X7XR3M3Z.js.map +1 -0
  111. package/dist/dist-XVBSOGFK.js +761 -0
  112. package/dist/dist-XVBSOGFK.js.map +1 -0
  113. package/dist/dist-YREX2TJT.js +3 -0
  114. package/dist/dist-YREX2TJT.js.map +1 -0
  115. package/dist/index.cjs +6 -0
  116. package/dist/index.cjs.map +1 -0
  117. package/dist/index.d.ts +1 -0
  118. package/dist/index.d.ts.map +1 -0
  119. package/dist/index.js +5 -0
  120. package/dist/index.js.map +1 -0
  121. package/dist/server/a2a/protocol.d.ts +8 -0
  122. package/dist/server/a2a/protocol.d.ts.map +1 -0
  123. package/dist/server/a2a/store.cjs +25 -0
  124. package/dist/server/a2a/store.cjs.map +1 -0
  125. package/dist/server/a2a/store.d.ts +14 -0
  126. package/dist/server/a2a/store.d.ts.map +1 -0
  127. package/dist/server/a2a/store.js +23 -0
  128. package/dist/server/a2a/store.js.map +1 -0
  129. package/dist/server/a2a/tasks.d.ts +20 -0
  130. package/dist/server/a2a/tasks.d.ts.map +1 -0
  131. package/dist/server/handlers/a2a.cjs +13 -11
  132. package/dist/server/handlers/a2a.cjs.map +1 -0
  133. package/dist/server/handlers/a2a.d.ts +68 -6
  134. package/dist/server/handlers/a2a.d.ts.map +1 -0
  135. package/dist/server/handlers/a2a.js +3 -1
  136. package/dist/server/handlers/a2a.js.map +1 -0
  137. package/dist/server/handlers/agent-builder.cjs +68 -0
  138. package/dist/server/handlers/agent-builder.cjs.map +1 -0
  139. package/dist/server/handlers/agent-builder.d.ts +94 -0
  140. package/dist/server/handlers/agent-builder.d.ts.map +1 -0
  141. package/dist/server/handlers/agent-builder.js +3 -0
  142. package/dist/server/handlers/agent-builder.js.map +1 -0
  143. package/dist/server/handlers/agents.cjs +57 -7
  144. package/dist/server/handlers/agents.cjs.map +1 -0
  145. package/dist/server/handlers/agents.d.ts +204 -6
  146. package/dist/server/handlers/agents.d.ts.map +1 -0
  147. package/dist/server/handlers/agents.js +3 -1
  148. package/dist/server/handlers/agents.js.map +1 -0
  149. package/dist/server/handlers/error.cjs +4 -2
  150. package/dist/server/handlers/error.cjs.map +1 -0
  151. package/dist/server/handlers/error.d.ts +2 -1
  152. package/dist/server/handlers/error.d.ts.map +1 -0
  153. package/dist/server/handlers/error.js +3 -1
  154. package/dist/server/handlers/error.js.map +1 -0
  155. package/dist/server/handlers/legacyWorkflows.cjs +13 -11
  156. package/dist/server/handlers/legacyWorkflows.cjs.map +1 -0
  157. package/dist/server/handlers/legacyWorkflows.d.ts +59 -10
  158. package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -0
  159. package/dist/server/handlers/legacyWorkflows.js +3 -1
  160. package/dist/server/handlers/legacyWorkflows.js.map +1 -0
  161. package/dist/server/handlers/logs.cjs +6 -4
  162. package/dist/server/handlers/logs.cjs.map +1 -0
  163. package/dist/server/handlers/logs.d.ts +34 -3
  164. package/dist/server/handlers/logs.d.ts.map +1 -0
  165. package/dist/server/handlers/logs.js +3 -1
  166. package/dist/server/handlers/logs.js.map +1 -0
  167. package/dist/server/handlers/memory.cjs +33 -11
  168. package/dist/server/handlers/memory.cjs.map +1 -0
  169. package/dist/server/handlers/memory.d.ts +118 -10
  170. package/dist/server/handlers/memory.d.ts.map +1 -0
  171. package/dist/server/handlers/memory.js +3 -1
  172. package/dist/server/handlers/memory.js.map +1 -0
  173. package/dist/server/handlers/observability.cjs +24 -0
  174. package/dist/server/handlers/observability.cjs.map +1 -0
  175. package/dist/server/handlers/observability.d.ts +49 -0
  176. package/dist/server/handlers/observability.d.ts.map +1 -0
  177. package/dist/server/handlers/observability.js +3 -0
  178. package/dist/server/handlers/observability.js.map +1 -0
  179. package/dist/server/handlers/scores.cjs +32 -0
  180. package/dist/server/handlers/scores.cjs.map +1 -0
  181. package/dist/server/handlers/scores.d.ts +251 -0
  182. package/dist/server/handlers/scores.d.ts.map +1 -0
  183. package/dist/server/handlers/scores.js +3 -0
  184. package/dist/server/handlers/scores.js.map +1 -0
  185. package/dist/server/handlers/telemetry.cjs +9 -3
  186. package/dist/server/handlers/telemetry.cjs.map +1 -0
  187. package/dist/server/handlers/telemetry.d.ts +33 -2
  188. package/dist/server/handlers/telemetry.d.ts.map +1 -0
  189. package/dist/server/handlers/telemetry.js +3 -1
  190. package/dist/server/handlers/telemetry.js.map +1 -0
  191. package/dist/server/handlers/tools.cjs +11 -5
  192. package/dist/server/handlers/tools.cjs.map +1 -0
  193. package/dist/server/handlers/tools.d.ts +25 -4
  194. package/dist/server/handlers/tools.d.ts.map +1 -0
  195. package/dist/server/handlers/tools.js +3 -1
  196. package/dist/server/handlers/tools.js.map +1 -0
  197. package/dist/server/handlers/utils.cjs +8 -2
  198. package/dist/server/handlers/utils.cjs.map +1 -0
  199. package/dist/server/handlers/utils.d.ts +8 -1
  200. package/dist/server/handlers/utils.d.ts.map +1 -0
  201. package/dist/server/handlers/utils.js +3 -1
  202. package/dist/server/handlers/utils.js.map +1 -0
  203. package/dist/server/handlers/vector.cjs +9 -7
  204. package/dist/server/handlers/vector.cjs.map +1 -0
  205. package/dist/server/handlers/vector.d.ts +51 -6
  206. package/dist/server/handlers/vector.d.ts.map +1 -0
  207. package/dist/server/handlers/vector.js +3 -1
  208. package/dist/server/handlers/vector.js.map +1 -0
  209. package/dist/server/handlers/voice.cjs +7 -5
  210. package/dist/server/handlers/voice.cjs.map +1 -0
  211. package/dist/server/handlers/voice.d.ts +41 -4
  212. package/dist/server/handlers/voice.d.ts.map +1 -0
  213. package/dist/server/handlers/voice.js +3 -1
  214. package/dist/server/handlers/voice.js.map +1 -0
  215. package/dist/server/handlers/workflows.cjs +33 -15
  216. package/dist/server/handlers/workflows.cjs.map +1 -0
  217. package/dist/server/handlers/workflows.d.ts +91 -14
  218. package/dist/server/handlers/workflows.d.ts.map +1 -0
  219. package/dist/server/handlers/workflows.js +3 -1
  220. package/dist/server/handlers/workflows.js.map +1 -0
  221. package/dist/server/handlers.cjs +44 -32
  222. package/dist/server/handlers.cjs.map +1 -0
  223. package/dist/server/handlers.d.ts +14 -11
  224. package/dist/server/handlers.d.ts.map +1 -0
  225. package/dist/server/handlers.js +15 -11
  226. package/dist/server/handlers.js.map +1 -0
  227. package/dist/server/http-exception.d.ts +87 -0
  228. package/dist/server/http-exception.d.ts.map +1 -0
  229. package/dist/server/types.d.ts +10 -0
  230. package/dist/server/types.d.ts.map +1 -0
  231. package/dist/server/utils.d.ts +44 -0
  232. package/dist/server/utils.d.ts.map +1 -0
  233. package/dist/token-352SFL4N.js +62 -0
  234. package/dist/token-352SFL4N.js.map +1 -0
  235. package/dist/token-JT637FZG.cjs +64 -0
  236. package/dist/token-JT637FZG.cjs.map +1 -0
  237. package/dist/token-util-75OQWZ4W.js +7 -0
  238. package/dist/token-util-75OQWZ4W.js.map +1 -0
  239. package/dist/token-util-WGALAXWM.cjs +9 -0
  240. package/dist/token-util-WGALAXWM.cjs.map +1 -0
  241. package/package.json +37 -14
  242. package/dist/_tsup-dts-rollup.d.cts +0 -1107
  243. package/dist/_tsup-dts-rollup.d.ts +0 -1107
  244. package/dist/chunk-2SLFAFTR.cjs +0 -148
  245. package/dist/chunk-3CNDE7QY.cjs +0 -308
  246. package/dist/chunk-75ZPJI57.cjs +0 -9
  247. package/dist/chunk-B2PAS2IB.cjs +0 -514
  248. package/dist/chunk-BK4XT6EG.js +0 -270
  249. package/dist/chunk-CCGRCYWJ.cjs +0 -18
  250. package/dist/chunk-CRCR3ZUK.js +0 -142
  251. package/dist/chunk-FRVBFMO2.cjs +0 -128
  252. package/dist/chunk-KOHWJYJT.js +0 -296
  253. package/dist/chunk-LI436ITD.cjs +0 -2042
  254. package/dist/chunk-LZ3VJXSO.cjs +0 -278
  255. package/dist/chunk-MEGCYGBU.js +0 -2039
  256. package/dist/chunk-MLKGABMK.js +0 -7
  257. package/dist/chunk-RHSWAXKB.cjs +0 -118
  258. package/dist/index.d.cts +0 -1
  259. package/dist/server/handlers/a2a.d.cts +0 -6
  260. package/dist/server/handlers/agents.d.cts +0 -6
  261. package/dist/server/handlers/error.d.cts +0 -1
  262. package/dist/server/handlers/legacyWorkflows.d.cts +0 -10
  263. package/dist/server/handlers/logs.d.cts +0 -3
  264. package/dist/server/handlers/memory.d.cts +0 -10
  265. package/dist/server/handlers/network.cjs +0 -22
  266. package/dist/server/handlers/network.d.cts +0 -4
  267. package/dist/server/handlers/network.d.ts +0 -4
  268. package/dist/server/handlers/network.js +0 -1
  269. package/dist/server/handlers/telemetry.d.cts +0 -2
  270. package/dist/server/handlers/tools.d.cts +0 -4
  271. package/dist/server/handlers/utils.d.cts +0 -1
  272. package/dist/server/handlers/vNextNetwork.cjs +0 -218
  273. package/dist/server/handlers/vNextNetwork.d.cts +0 -6
  274. package/dist/server/handlers/vNextNetwork.d.ts +0 -6
  275. package/dist/server/handlers/vNextNetwork.js +0 -211
  276. package/dist/server/handlers/vector.d.cts +0 -6
  277. package/dist/server/handlers/voice.d.cts +0 -4
  278. package/dist/server/handlers/workflows.d.cts +0 -14
  279. package/dist/server/handlers.d.cts +0 -11
@@ -0,0 +1,764 @@
1
+ 'use strict';
2
+
3
+ var chunkLPM6BBAX_cjs = require('./chunk-LPM6BBAX.cjs');
4
+ var zod = require('zod');
5
+
6
+ function convertToGroqChatMessages(prompt) {
7
+ const messages = [];
8
+ for (const { role, content } of prompt) {
9
+ switch (role) {
10
+ case "system": {
11
+ messages.push({ role: "system", content });
12
+ break;
13
+ }
14
+ case "user": {
15
+ if (content.length === 1 && content[0].type === "text") {
16
+ messages.push({ role: "user", content: content[0].text });
17
+ break;
18
+ }
19
+ messages.push({
20
+ role: "user",
21
+ content: content.map((part) => {
22
+ var _a;
23
+ switch (part.type) {
24
+ case "text": {
25
+ return { type: "text", text: part.text };
26
+ }
27
+ case "image": {
28
+ return {
29
+ type: "image_url",
30
+ image_url: {
31
+ url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${chunkLPM6BBAX_cjs.convertUint8ArrayToBase64(part.image)}`
32
+ }
33
+ };
34
+ }
35
+ case "file": {
36
+ throw new chunkLPM6BBAX_cjs.UnsupportedFunctionalityError({
37
+ functionality: "File content parts in user messages"
38
+ });
39
+ }
40
+ }
41
+ })
42
+ });
43
+ break;
44
+ }
45
+ case "assistant": {
46
+ let text = "";
47
+ const toolCalls = [];
48
+ for (const part of content) {
49
+ switch (part.type) {
50
+ case "text": {
51
+ text += part.text;
52
+ break;
53
+ }
54
+ case "tool-call": {
55
+ toolCalls.push({
56
+ id: part.toolCallId,
57
+ type: "function",
58
+ function: {
59
+ name: part.toolName,
60
+ arguments: JSON.stringify(part.args)
61
+ }
62
+ });
63
+ break;
64
+ }
65
+ }
66
+ }
67
+ messages.push({
68
+ role: "assistant",
69
+ content: text,
70
+ tool_calls: toolCalls.length > 0 ? toolCalls : void 0
71
+ });
72
+ break;
73
+ }
74
+ case "tool": {
75
+ for (const toolResponse of content) {
76
+ messages.push({
77
+ role: "tool",
78
+ tool_call_id: toolResponse.toolCallId,
79
+ content: JSON.stringify(toolResponse.result)
80
+ });
81
+ }
82
+ break;
83
+ }
84
+ default: {
85
+ const _exhaustiveCheck = role;
86
+ throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
87
+ }
88
+ }
89
+ }
90
+ return messages;
91
+ }
92
+ function getResponseMetadata({
93
+ id,
94
+ model,
95
+ created
96
+ }) {
97
+ return {
98
+ id: id != null ? id : void 0,
99
+ modelId: model != null ? model : void 0,
100
+ timestamp: created != null ? new Date(created * 1e3) : void 0
101
+ };
102
+ }
103
+ var groqErrorDataSchema = zod.z.object({
104
+ error: zod.z.object({
105
+ message: zod.z.string(),
106
+ type: zod.z.string()
107
+ })
108
+ });
109
+ var groqFailedResponseHandler = chunkLPM6BBAX_cjs.createJsonErrorResponseHandler({
110
+ errorSchema: groqErrorDataSchema,
111
+ errorToMessage: (data) => data.error.message
112
+ });
113
+ function prepareTools({
114
+ mode
115
+ }) {
116
+ var _a;
117
+ const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
118
+ const toolWarnings = [];
119
+ if (tools == null) {
120
+ return { tools: void 0, tool_choice: void 0, toolWarnings };
121
+ }
122
+ const toolChoice = mode.toolChoice;
123
+ const groqTools = [];
124
+ for (const tool of tools) {
125
+ if (tool.type === "provider-defined") {
126
+ toolWarnings.push({ type: "unsupported-tool", tool });
127
+ } else {
128
+ groqTools.push({
129
+ type: "function",
130
+ function: {
131
+ name: tool.name,
132
+ description: tool.description,
133
+ parameters: tool.parameters
134
+ }
135
+ });
136
+ }
137
+ }
138
+ if (toolChoice == null) {
139
+ return { tools: groqTools, tool_choice: void 0, toolWarnings };
140
+ }
141
+ const type = toolChoice.type;
142
+ switch (type) {
143
+ case "auto":
144
+ case "none":
145
+ case "required":
146
+ return { tools: groqTools, tool_choice: type, toolWarnings };
147
+ case "tool":
148
+ return {
149
+ tools: groqTools,
150
+ tool_choice: {
151
+ type: "function",
152
+ function: {
153
+ name: toolChoice.toolName
154
+ }
155
+ },
156
+ toolWarnings
157
+ };
158
+ default: {
159
+ const _exhaustiveCheck = type;
160
+ throw new chunkLPM6BBAX_cjs.UnsupportedFunctionalityError({
161
+ functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
162
+ });
163
+ }
164
+ }
165
+ }
166
+ function mapGroqFinishReason(finishReason) {
167
+ switch (finishReason) {
168
+ case "stop":
169
+ return "stop";
170
+ case "length":
171
+ return "length";
172
+ case "content_filter":
173
+ return "content-filter";
174
+ case "function_call":
175
+ case "tool_calls":
176
+ return "tool-calls";
177
+ default:
178
+ return "unknown";
179
+ }
180
+ }
181
+ var GroqChatLanguageModel = class {
182
+ constructor(modelId, settings, config) {
183
+ this.specificationVersion = "v1";
184
+ this.supportsStructuredOutputs = false;
185
+ this.defaultObjectGenerationMode = "json";
186
+ this.modelId = modelId;
187
+ this.settings = settings;
188
+ this.config = config;
189
+ }
190
+ get provider() {
191
+ return this.config.provider;
192
+ }
193
+ get supportsImageUrls() {
194
+ return !this.settings.downloadImages;
195
+ }
196
+ getArgs({
197
+ mode,
198
+ prompt,
199
+ maxTokens,
200
+ temperature,
201
+ topP,
202
+ topK,
203
+ frequencyPenalty,
204
+ presencePenalty,
205
+ stopSequences,
206
+ responseFormat,
207
+ seed,
208
+ stream,
209
+ providerMetadata
210
+ }) {
211
+ const type = mode.type;
212
+ const warnings = [];
213
+ if (topK != null) {
214
+ warnings.push({
215
+ type: "unsupported-setting",
216
+ setting: "topK"
217
+ });
218
+ }
219
+ if (responseFormat != null && responseFormat.type === "json" && responseFormat.schema != null) {
220
+ warnings.push({
221
+ type: "unsupported-setting",
222
+ setting: "responseFormat",
223
+ details: "JSON response format schema is not supported"
224
+ });
225
+ }
226
+ const groqOptions = chunkLPM6BBAX_cjs.parseProviderOptions({
227
+ provider: "groq",
228
+ providerOptions: providerMetadata,
229
+ schema: zod.z.object({
230
+ reasoningFormat: zod.z.enum(["parsed", "raw", "hidden"]).nullish()
231
+ })
232
+ });
233
+ const baseArgs = {
234
+ // model id:
235
+ model: this.modelId,
236
+ // model specific settings:
237
+ user: this.settings.user,
238
+ parallel_tool_calls: this.settings.parallelToolCalls,
239
+ // standardized settings:
240
+ max_tokens: maxTokens,
241
+ temperature,
242
+ top_p: topP,
243
+ frequency_penalty: frequencyPenalty,
244
+ presence_penalty: presencePenalty,
245
+ stop: stopSequences,
246
+ seed,
247
+ // response format:
248
+ response_format: (
249
+ // json object response format is not supported for streaming:
250
+ stream === false && (responseFormat == null ? void 0 : responseFormat.type) === "json" ? { type: "json_object" } : void 0
251
+ ),
252
+ // provider options:
253
+ reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
254
+ // messages:
255
+ messages: convertToGroqChatMessages(prompt)
256
+ };
257
+ switch (type) {
258
+ case "regular": {
259
+ const { tools, tool_choice, toolWarnings } = prepareTools({ mode });
260
+ return {
261
+ args: {
262
+ ...baseArgs,
263
+ tools,
264
+ tool_choice
265
+ },
266
+ warnings: [...warnings, ...toolWarnings]
267
+ };
268
+ }
269
+ case "object-json": {
270
+ return {
271
+ args: {
272
+ ...baseArgs,
273
+ response_format: (
274
+ // json object response format is not supported for streaming:
275
+ stream === false ? { type: "json_object" } : void 0
276
+ )
277
+ },
278
+ warnings
279
+ };
280
+ }
281
+ case "object-tool": {
282
+ return {
283
+ args: {
284
+ ...baseArgs,
285
+ tool_choice: {
286
+ type: "function",
287
+ function: { name: mode.tool.name }
288
+ },
289
+ tools: [
290
+ {
291
+ type: "function",
292
+ function: {
293
+ name: mode.tool.name,
294
+ description: mode.tool.description,
295
+ parameters: mode.tool.parameters
296
+ }
297
+ }
298
+ ]
299
+ },
300
+ warnings
301
+ };
302
+ }
303
+ default: {
304
+ const _exhaustiveCheck = type;
305
+ throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
306
+ }
307
+ }
308
+ }
309
+ async doGenerate(options) {
310
+ var _a, _b, _c, _d, _e, _f, _g;
311
+ const { args, warnings } = this.getArgs({ ...options, stream: false });
312
+ const body = JSON.stringify(args);
313
+ const {
314
+ responseHeaders,
315
+ value: response,
316
+ rawValue: rawResponse
317
+ } = await chunkLPM6BBAX_cjs.postJsonToApi({
318
+ url: this.config.url({
319
+ path: "/chat/completions",
320
+ modelId: this.modelId
321
+ }),
322
+ headers: chunkLPM6BBAX_cjs.combineHeaders(this.config.headers(), options.headers),
323
+ body: args,
324
+ failedResponseHandler: groqFailedResponseHandler,
325
+ successfulResponseHandler: chunkLPM6BBAX_cjs.createJsonResponseHandler(
326
+ groqChatResponseSchema
327
+ ),
328
+ abortSignal: options.abortSignal,
329
+ fetch: this.config.fetch
330
+ });
331
+ const { messages: rawPrompt, ...rawSettings } = args;
332
+ const choice = response.choices[0];
333
+ return {
334
+ text: (_a = choice.message.content) != null ? _a : void 0,
335
+ reasoning: (_b = choice.message.reasoning) != null ? _b : void 0,
336
+ toolCalls: (_c = choice.message.tool_calls) == null ? void 0 : _c.map((toolCall) => {
337
+ var _a2;
338
+ return {
339
+ toolCallType: "function",
340
+ toolCallId: (_a2 = toolCall.id) != null ? _a2 : chunkLPM6BBAX_cjs.generateId(),
341
+ toolName: toolCall.function.name,
342
+ args: toolCall.function.arguments
343
+ };
344
+ }),
345
+ finishReason: mapGroqFinishReason(choice.finish_reason),
346
+ usage: {
347
+ promptTokens: (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens) != null ? _e : NaN,
348
+ completionTokens: (_g = (_f = response.usage) == null ? void 0 : _f.completion_tokens) != null ? _g : NaN
349
+ },
350
+ rawCall: { rawPrompt, rawSettings },
351
+ rawResponse: { headers: responseHeaders, body: rawResponse },
352
+ response: getResponseMetadata(response),
353
+ warnings,
354
+ request: { body }
355
+ };
356
+ }
357
+ async doStream(options) {
358
+ const { args, warnings } = this.getArgs({ ...options, stream: true });
359
+ const body = JSON.stringify({ ...args, stream: true });
360
+ const { responseHeaders, value: response } = await chunkLPM6BBAX_cjs.postJsonToApi({
361
+ url: this.config.url({
362
+ path: "/chat/completions",
363
+ modelId: this.modelId
364
+ }),
365
+ headers: chunkLPM6BBAX_cjs.combineHeaders(this.config.headers(), options.headers),
366
+ body: {
367
+ ...args,
368
+ stream: true
369
+ },
370
+ failedResponseHandler: groqFailedResponseHandler,
371
+ successfulResponseHandler: chunkLPM6BBAX_cjs.createEventSourceResponseHandler(groqChatChunkSchema),
372
+ abortSignal: options.abortSignal,
373
+ fetch: this.config.fetch
374
+ });
375
+ const { messages: rawPrompt, ...rawSettings } = args;
376
+ const toolCalls = [];
377
+ let finishReason = "unknown";
378
+ let usage = {
379
+ promptTokens: void 0,
380
+ completionTokens: void 0
381
+ };
382
+ let isFirstChunk = true;
383
+ return {
384
+ stream: response.pipeThrough(
385
+ new TransformStream({
386
+ transform(chunk, controller) {
387
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
388
+ if (!chunk.success) {
389
+ finishReason = "error";
390
+ controller.enqueue({ type: "error", error: chunk.error });
391
+ return;
392
+ }
393
+ const value = chunk.value;
394
+ if ("error" in value) {
395
+ finishReason = "error";
396
+ controller.enqueue({ type: "error", error: value.error });
397
+ return;
398
+ }
399
+ if (isFirstChunk) {
400
+ isFirstChunk = false;
401
+ controller.enqueue({
402
+ type: "response-metadata",
403
+ ...getResponseMetadata(value)
404
+ });
405
+ }
406
+ if (((_a = value.x_groq) == null ? void 0 : _a.usage) != null) {
407
+ usage = {
408
+ promptTokens: (_b = value.x_groq.usage.prompt_tokens) != null ? _b : void 0,
409
+ completionTokens: (_c = value.x_groq.usage.completion_tokens) != null ? _c : void 0
410
+ };
411
+ }
412
+ const choice = value.choices[0];
413
+ if ((choice == null ? void 0 : choice.finish_reason) != null) {
414
+ finishReason = mapGroqFinishReason(choice.finish_reason);
415
+ }
416
+ if ((choice == null ? void 0 : choice.delta) == null) {
417
+ return;
418
+ }
419
+ const delta = choice.delta;
420
+ if (delta.reasoning != null && delta.reasoning.length > 0) {
421
+ controller.enqueue({
422
+ type: "reasoning",
423
+ textDelta: delta.reasoning
424
+ });
425
+ }
426
+ if (delta.content != null && delta.content.length > 0) {
427
+ controller.enqueue({
428
+ type: "text-delta",
429
+ textDelta: delta.content
430
+ });
431
+ }
432
+ if (delta.tool_calls != null) {
433
+ for (const toolCallDelta of delta.tool_calls) {
434
+ const index = toolCallDelta.index;
435
+ if (toolCalls[index] == null) {
436
+ if (toolCallDelta.type !== "function") {
437
+ throw new chunkLPM6BBAX_cjs.InvalidResponseDataError({
438
+ data: toolCallDelta,
439
+ message: `Expected 'function' type.`
440
+ });
441
+ }
442
+ if (toolCallDelta.id == null) {
443
+ throw new chunkLPM6BBAX_cjs.InvalidResponseDataError({
444
+ data: toolCallDelta,
445
+ message: `Expected 'id' to be a string.`
446
+ });
447
+ }
448
+ if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
449
+ throw new chunkLPM6BBAX_cjs.InvalidResponseDataError({
450
+ data: toolCallDelta,
451
+ message: `Expected 'function.name' to be a string.`
452
+ });
453
+ }
454
+ toolCalls[index] = {
455
+ id: toolCallDelta.id,
456
+ type: "function",
457
+ function: {
458
+ name: toolCallDelta.function.name,
459
+ arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
460
+ },
461
+ hasFinished: false
462
+ };
463
+ const toolCall2 = toolCalls[index];
464
+ if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null) {
465
+ if (toolCall2.function.arguments.length > 0) {
466
+ controller.enqueue({
467
+ type: "tool-call-delta",
468
+ toolCallType: "function",
469
+ toolCallId: toolCall2.id,
470
+ toolName: toolCall2.function.name,
471
+ argsTextDelta: toolCall2.function.arguments
472
+ });
473
+ }
474
+ if (chunkLPM6BBAX_cjs.isParsableJson(toolCall2.function.arguments)) {
475
+ controller.enqueue({
476
+ type: "tool-call",
477
+ toolCallType: "function",
478
+ toolCallId: (_h = toolCall2.id) != null ? _h : chunkLPM6BBAX_cjs.generateId(),
479
+ toolName: toolCall2.function.name,
480
+ args: toolCall2.function.arguments
481
+ });
482
+ toolCall2.hasFinished = true;
483
+ }
484
+ }
485
+ continue;
486
+ }
487
+ const toolCall = toolCalls[index];
488
+ if (toolCall.hasFinished) {
489
+ continue;
490
+ }
491
+ if (((_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null) {
492
+ toolCall.function.arguments += (_k = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null ? _k : "";
493
+ }
494
+ controller.enqueue({
495
+ type: "tool-call-delta",
496
+ toolCallType: "function",
497
+ toolCallId: toolCall.id,
498
+ toolName: toolCall.function.name,
499
+ argsTextDelta: (_l = toolCallDelta.function.arguments) != null ? _l : ""
500
+ });
501
+ if (((_m = toolCall.function) == null ? void 0 : _m.name) != null && ((_n = toolCall.function) == null ? void 0 : _n.arguments) != null && chunkLPM6BBAX_cjs.isParsableJson(toolCall.function.arguments)) {
502
+ controller.enqueue({
503
+ type: "tool-call",
504
+ toolCallType: "function",
505
+ toolCallId: (_o = toolCall.id) != null ? _o : chunkLPM6BBAX_cjs.generateId(),
506
+ toolName: toolCall.function.name,
507
+ args: toolCall.function.arguments
508
+ });
509
+ toolCall.hasFinished = true;
510
+ }
511
+ }
512
+ }
513
+ },
514
+ flush(controller) {
515
+ var _a, _b;
516
+ controller.enqueue({
517
+ type: "finish",
518
+ finishReason,
519
+ usage: {
520
+ promptTokens: (_a = usage.promptTokens) != null ? _a : NaN,
521
+ completionTokens: (_b = usage.completionTokens) != null ? _b : NaN
522
+ },
523
+ ...{}
524
+ });
525
+ }
526
+ })
527
+ ),
528
+ rawCall: { rawPrompt, rawSettings },
529
+ rawResponse: { headers: responseHeaders },
530
+ warnings,
531
+ request: { body }
532
+ };
533
+ }
534
+ };
535
+ var groqChatResponseSchema = zod.z.object({
536
+ id: zod.z.string().nullish(),
537
+ created: zod.z.number().nullish(),
538
+ model: zod.z.string().nullish(),
539
+ choices: zod.z.array(
540
+ zod.z.object({
541
+ message: zod.z.object({
542
+ content: zod.z.string().nullish(),
543
+ reasoning: zod.z.string().nullish(),
544
+ tool_calls: zod.z.array(
545
+ zod.z.object({
546
+ id: zod.z.string().nullish(),
547
+ type: zod.z.literal("function"),
548
+ function: zod.z.object({
549
+ name: zod.z.string(),
550
+ arguments: zod.z.string()
551
+ })
552
+ })
553
+ ).nullish()
554
+ }),
555
+ index: zod.z.number(),
556
+ finish_reason: zod.z.string().nullish()
557
+ })
558
+ ),
559
+ usage: zod.z.object({
560
+ prompt_tokens: zod.z.number().nullish(),
561
+ completion_tokens: zod.z.number().nullish()
562
+ }).nullish()
563
+ });
564
+ var groqChatChunkSchema = zod.z.union([
565
+ zod.z.object({
566
+ id: zod.z.string().nullish(),
567
+ created: zod.z.number().nullish(),
568
+ model: zod.z.string().nullish(),
569
+ choices: zod.z.array(
570
+ zod.z.object({
571
+ delta: zod.z.object({
572
+ content: zod.z.string().nullish(),
573
+ reasoning: zod.z.string().nullish(),
574
+ tool_calls: zod.z.array(
575
+ zod.z.object({
576
+ index: zod.z.number(),
577
+ id: zod.z.string().nullish(),
578
+ type: zod.z.literal("function").optional(),
579
+ function: zod.z.object({
580
+ name: zod.z.string().nullish(),
581
+ arguments: zod.z.string().nullish()
582
+ })
583
+ })
584
+ ).nullish()
585
+ }).nullish(),
586
+ finish_reason: zod.z.string().nullable().optional(),
587
+ index: zod.z.number()
588
+ })
589
+ ),
590
+ x_groq: zod.z.object({
591
+ usage: zod.z.object({
592
+ prompt_tokens: zod.z.number().nullish(),
593
+ completion_tokens: zod.z.number().nullish()
594
+ }).nullish()
595
+ }).nullish()
596
+ }),
597
+ groqErrorDataSchema
598
+ ]);
599
+ var groqProviderOptionsSchema = zod.z.object({
600
+ language: zod.z.string().nullish(),
601
+ prompt: zod.z.string().nullish(),
602
+ responseFormat: zod.z.string().nullish(),
603
+ temperature: zod.z.number().min(0).max(1).nullish(),
604
+ timestampGranularities: zod.z.array(zod.z.string()).nullish()
605
+ });
606
+ var GroqTranscriptionModel = class {
607
+ constructor(modelId, config) {
608
+ this.modelId = modelId;
609
+ this.config = config;
610
+ this.specificationVersion = "v1";
611
+ }
612
+ get provider() {
613
+ return this.config.provider;
614
+ }
615
+ getArgs({
616
+ audio,
617
+ mediaType,
618
+ providerOptions
619
+ }) {
620
+ var _a, _b, _c, _d, _e;
621
+ const warnings = [];
622
+ const groqOptions = chunkLPM6BBAX_cjs.parseProviderOptions({
623
+ provider: "groq",
624
+ providerOptions,
625
+ schema: groqProviderOptionsSchema
626
+ });
627
+ const formData = new FormData();
628
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([chunkLPM6BBAX_cjs.convertBase64ToUint8Array(audio)]);
629
+ formData.append("model", this.modelId);
630
+ formData.append("file", new File([blob], "audio", { type: mediaType }));
631
+ if (groqOptions) {
632
+ const transcriptionModelOptions = {
633
+ language: (_a = groqOptions.language) != null ? _a : void 0,
634
+ prompt: (_b = groqOptions.prompt) != null ? _b : void 0,
635
+ response_format: (_c = groqOptions.responseFormat) != null ? _c : void 0,
636
+ temperature: (_d = groqOptions.temperature) != null ? _d : void 0,
637
+ timestamp_granularities: (_e = groqOptions.timestampGranularities) != null ? _e : void 0
638
+ };
639
+ for (const key in transcriptionModelOptions) {
640
+ const value = transcriptionModelOptions[key];
641
+ if (value !== void 0) {
642
+ formData.append(key, String(value));
643
+ }
644
+ }
645
+ }
646
+ return {
647
+ formData,
648
+ warnings
649
+ };
650
+ }
651
+ async doGenerate(options) {
652
+ var _a, _b, _c, _d, _e;
653
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
654
+ const { formData, warnings } = this.getArgs(options);
655
+ const {
656
+ value: response,
657
+ responseHeaders,
658
+ rawValue: rawResponse
659
+ } = await chunkLPM6BBAX_cjs.postFormDataToApi({
660
+ url: this.config.url({
661
+ path: "/audio/transcriptions",
662
+ modelId: this.modelId
663
+ }),
664
+ headers: chunkLPM6BBAX_cjs.combineHeaders(this.config.headers(), options.headers),
665
+ formData,
666
+ failedResponseHandler: groqFailedResponseHandler,
667
+ successfulResponseHandler: chunkLPM6BBAX_cjs.createJsonResponseHandler(
668
+ groqTranscriptionResponseSchema
669
+ ),
670
+ abortSignal: options.abortSignal,
671
+ fetch: this.config.fetch
672
+ });
673
+ return {
674
+ text: response.text,
675
+ segments: (_e = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
676
+ text: segment.text,
677
+ startSecond: segment.start,
678
+ endSecond: segment.end
679
+ }))) != null ? _e : [],
680
+ language: response.language,
681
+ durationInSeconds: response.duration,
682
+ warnings,
683
+ response: {
684
+ timestamp: currentDate,
685
+ modelId: this.modelId,
686
+ headers: responseHeaders,
687
+ body: rawResponse
688
+ }
689
+ };
690
+ }
691
+ };
692
+ var groqTranscriptionResponseSchema = zod.z.object({
693
+ task: zod.z.string(),
694
+ language: zod.z.string(),
695
+ duration: zod.z.number(),
696
+ text: zod.z.string(),
697
+ segments: zod.z.array(
698
+ zod.z.object({
699
+ id: zod.z.number(),
700
+ seek: zod.z.number(),
701
+ start: zod.z.number(),
702
+ end: zod.z.number(),
703
+ text: zod.z.string(),
704
+ tokens: zod.z.array(zod.z.number()),
705
+ temperature: zod.z.number(),
706
+ avg_logprob: zod.z.number(),
707
+ compression_ratio: zod.z.number(),
708
+ no_speech_prob: zod.z.number()
709
+ })
710
+ ),
711
+ x_groq: zod.z.object({
712
+ id: zod.z.string()
713
+ })
714
+ });
715
+ function createGroq(options = {}) {
716
+ var _a;
717
+ const baseURL = (_a = chunkLPM6BBAX_cjs.withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
718
+ const getHeaders = () => ({
719
+ Authorization: `Bearer ${chunkLPM6BBAX_cjs.loadApiKey({
720
+ apiKey: options.apiKey,
721
+ environmentVariableName: "GROQ_API_KEY",
722
+ description: "Groq"
723
+ })}`,
724
+ ...options.headers
725
+ });
726
+ const createChatModel = (modelId, settings = {}) => new GroqChatLanguageModel(modelId, settings, {
727
+ provider: "groq.chat",
728
+ url: ({ path }) => `${baseURL}${path}`,
729
+ headers: getHeaders,
730
+ fetch: options.fetch
731
+ });
732
+ const createLanguageModel = (modelId, settings) => {
733
+ if (new.target) {
734
+ throw new Error(
735
+ "The Groq model function cannot be called with the new keyword."
736
+ );
737
+ }
738
+ return createChatModel(modelId, settings);
739
+ };
740
+ const createTranscriptionModel = (modelId) => {
741
+ return new GroqTranscriptionModel(modelId, {
742
+ provider: "groq.transcription",
743
+ url: ({ path }) => `${baseURL}${path}`,
744
+ headers: getHeaders,
745
+ fetch: options.fetch
746
+ });
747
+ };
748
+ const provider = function(modelId, settings) {
749
+ return createLanguageModel(modelId, settings);
750
+ };
751
+ provider.languageModel = createLanguageModel;
752
+ provider.chat = createChatModel;
753
+ provider.textEmbeddingModel = (modelId) => {
754
+ throw new chunkLPM6BBAX_cjs.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
755
+ };
756
+ provider.transcription = createTranscriptionModel;
757
+ return provider;
758
+ }
759
+ var groq = createGroq();
760
+
761
+ exports.createGroq = createGroq;
762
+ exports.groq = groq;
763
+ //# sourceMappingURL=dist-RFMYFILX.cjs.map
764
+ //# sourceMappingURL=dist-RFMYFILX.cjs.map