@mastra/server 0.20.1-alpha.3 → 0.20.1

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 (48) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{chunk-TMU7NSW7.js → chunk-HKW2536J.js} +5852 -2557
  3. package/dist/chunk-HKW2536J.js.map +1 -0
  4. package/dist/{chunk-AFJBHPHA.cjs → chunk-KJJA7GPJ.cjs} +6308 -2994
  5. package/dist/chunk-KJJA7GPJ.cjs.map +1 -0
  6. package/dist/server/handlers/agent-builder.cjs +16 -16
  7. package/dist/server/handlers/agent-builder.js +1 -1
  8. package/dist/server/handlers.cjs +2 -2
  9. package/dist/server/handlers.js +1 -1
  10. package/package.json +6 -6
  11. package/dist/chunk-44GFD2TF.js +0 -419
  12. package/dist/chunk-44GFD2TF.js.map +0 -1
  13. package/dist/chunk-75KU7JB6.cjs +0 -588
  14. package/dist/chunk-75KU7JB6.cjs.map +0 -1
  15. package/dist/chunk-77TGJGDW.cjs +0 -1279
  16. package/dist/chunk-77TGJGDW.cjs.map +0 -1
  17. package/dist/chunk-AFJBHPHA.cjs.map +0 -1
  18. package/dist/chunk-CHDN4NEY.js +0 -1277
  19. package/dist/chunk-CHDN4NEY.js.map +0 -1
  20. package/dist/chunk-EAIAF7Z6.js +0 -571
  21. package/dist/chunk-EAIAF7Z6.js.map +0 -1
  22. package/dist/chunk-TMU7NSW7.js.map +0 -1
  23. package/dist/chunk-WO2SYFUI.js +0 -5945
  24. package/dist/chunk-WO2SYFUI.js.map +0 -1
  25. package/dist/chunk-XCR65STK.cjs +0 -433
  26. package/dist/chunk-XCR65STK.cjs.map +0 -1
  27. package/dist/chunk-YWACVZRO.cjs +0 -5985
  28. package/dist/chunk-YWACVZRO.cjs.map +0 -1
  29. package/dist/dist-36GPHJSB.cjs +0 -2014
  30. package/dist/dist-36GPHJSB.cjs.map +0 -1
  31. package/dist/dist-3WEYC4YO.js +0 -2007
  32. package/dist/dist-3WEYC4YO.js.map +0 -1
  33. package/dist/dist-7MBYKZSM.js +0 -846
  34. package/dist/dist-7MBYKZSM.js.map +0 -1
  35. package/dist/dist-FGYSUA65.cjs +0 -935
  36. package/dist/dist-FGYSUA65.cjs.map +0 -1
  37. package/dist/dist-FNKPY5I5.cjs +0 -1412
  38. package/dist/dist-FNKPY5I5.cjs.map +0 -1
  39. package/dist/dist-H5ZHQKYG.js +0 -3
  40. package/dist/dist-H5ZHQKYG.js.map +0 -1
  41. package/dist/dist-HBUYSRRO.cjs +0 -850
  42. package/dist/dist-HBUYSRRO.cjs.map +0 -1
  43. package/dist/dist-IUCBLZK6.js +0 -1409
  44. package/dist/dist-IUCBLZK6.js.map +0 -1
  45. package/dist/dist-M4HXCUXC.cjs +0 -20
  46. package/dist/dist-M4HXCUXC.cjs.map +0 -1
  47. package/dist/dist-P32YPL35.js +0 -932
  48. package/dist/dist-P32YPL35.js.map +0 -1
@@ -1,850 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk75KU7JB6_cjs = require('./chunk-75KU7JB6.cjs');
4
- var chunkXCR65STK_cjs = require('./chunk-XCR65STK.cjs');
5
- var v4 = require('zod/v4');
6
-
7
- function convertToGroqChatMessages(prompt) {
8
- const messages = [];
9
- for (const { role, content } of prompt) {
10
- switch (role) {
11
- case "system": {
12
- messages.push({ role: "system", content });
13
- break;
14
- }
15
- case "user": {
16
- if (content.length === 1 && content[0].type === "text") {
17
- messages.push({ role: "user", content: content[0].text });
18
- break;
19
- }
20
- messages.push({
21
- role: "user",
22
- content: content.map((part) => {
23
- switch (part.type) {
24
- case "text": {
25
- return { type: "text", text: part.text };
26
- }
27
- case "file": {
28
- if (!part.mediaType.startsWith("image/")) {
29
- throw new chunkXCR65STK_cjs.UnsupportedFunctionalityError({
30
- functionality: "Non-image file content parts"
31
- });
32
- }
33
- const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
34
- return {
35
- type: "image_url",
36
- image_url: {
37
- url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${chunk75KU7JB6_cjs.convertToBase64(part.data)}`
38
- }
39
- };
40
- }
41
- }
42
- })
43
- });
44
- break;
45
- }
46
- case "assistant": {
47
- let text = "";
48
- let reasoning = "";
49
- const toolCalls = [];
50
- for (const part of content) {
51
- switch (part.type) {
52
- // groq supports reasoning for tool-calls in multi-turn conversations
53
- // https://github.com/vercel/ai/issues/7860
54
- case "reasoning": {
55
- reasoning += part.text;
56
- break;
57
- }
58
- case "text": {
59
- text += part.text;
60
- break;
61
- }
62
- case "tool-call": {
63
- toolCalls.push({
64
- id: part.toolCallId,
65
- type: "function",
66
- function: {
67
- name: part.toolName,
68
- arguments: JSON.stringify(part.input)
69
- }
70
- });
71
- break;
72
- }
73
- }
74
- }
75
- messages.push({
76
- role: "assistant",
77
- content: text,
78
- ...reasoning.length > 0 ? { reasoning } : null,
79
- ...toolCalls.length > 0 ? { tool_calls: toolCalls } : null
80
- });
81
- break;
82
- }
83
- case "tool": {
84
- for (const toolResponse of content) {
85
- const output = toolResponse.output;
86
- let contentValue;
87
- switch (output.type) {
88
- case "text":
89
- case "error-text":
90
- contentValue = output.value;
91
- break;
92
- case "content":
93
- case "json":
94
- case "error-json":
95
- contentValue = JSON.stringify(output.value);
96
- break;
97
- }
98
- messages.push({
99
- role: "tool",
100
- tool_call_id: toolResponse.toolCallId,
101
- content: contentValue
102
- });
103
- }
104
- break;
105
- }
106
- default: {
107
- const _exhaustiveCheck = role;
108
- throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
109
- }
110
- }
111
- }
112
- return messages;
113
- }
114
- function getResponseMetadata({
115
- id,
116
- model,
117
- created
118
- }) {
119
- return {
120
- id: id != null ? id : void 0,
121
- modelId: model != null ? model : void 0,
122
- timestamp: created != null ? new Date(created * 1e3) : void 0
123
- };
124
- }
125
- var groqProviderOptions = v4.z.object({
126
- reasoningFormat: v4.z.enum(["parsed", "raw", "hidden"]).optional(),
127
- reasoningEffort: v4.z.string().optional(),
128
- /**
129
- * Whether to enable parallel function calling during tool use. Default to true.
130
- */
131
- parallelToolCalls: v4.z.boolean().optional(),
132
- /**
133
- * A unique identifier representing your end-user, which can help OpenAI to
134
- * monitor and detect abuse. Learn more.
135
- */
136
- user: v4.z.string().optional(),
137
- /**
138
- * Whether to use structured outputs.
139
- *
140
- * @default true
141
- */
142
- structuredOutputs: v4.z.boolean().optional()
143
- });
144
- var groqErrorDataSchema = v4.z.object({
145
- error: v4.z.object({
146
- message: v4.z.string(),
147
- type: v4.z.string()
148
- })
149
- });
150
- var groqFailedResponseHandler = chunk75KU7JB6_cjs.createJsonErrorResponseHandler({
151
- errorSchema: groqErrorDataSchema,
152
- errorToMessage: (data) => data.error.message
153
- });
154
- var BROWSER_SEARCH_SUPPORTED_MODELS = [
155
- "openai/gpt-oss-20b",
156
- "openai/gpt-oss-120b"
157
- ];
158
- function isBrowserSearchSupportedModel(modelId) {
159
- return BROWSER_SEARCH_SUPPORTED_MODELS.includes(modelId);
160
- }
161
- function getSupportedModelsString() {
162
- return BROWSER_SEARCH_SUPPORTED_MODELS.join(", ");
163
- }
164
- function prepareTools({
165
- tools,
166
- toolChoice,
167
- modelId
168
- }) {
169
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
170
- const toolWarnings = [];
171
- if (tools == null) {
172
- return { tools: void 0, toolChoice: void 0, toolWarnings };
173
- }
174
- const groqTools2 = [];
175
- for (const tool of tools) {
176
- if (tool.type === "provider-defined") {
177
- if (tool.id === "groq.browser_search") {
178
- if (!isBrowserSearchSupportedModel(modelId)) {
179
- toolWarnings.push({
180
- type: "unsupported-tool",
181
- tool,
182
- details: `Browser search is only supported on the following models: ${getSupportedModelsString()}. Current model: ${modelId}`
183
- });
184
- } else {
185
- groqTools2.push({
186
- type: "browser_search"
187
- });
188
- }
189
- } else {
190
- toolWarnings.push({ type: "unsupported-tool", tool });
191
- }
192
- } else {
193
- groqTools2.push({
194
- type: "function",
195
- function: {
196
- name: tool.name,
197
- description: tool.description,
198
- parameters: tool.inputSchema
199
- }
200
- });
201
- }
202
- }
203
- if (toolChoice == null) {
204
- return { tools: groqTools2, toolChoice: void 0, toolWarnings };
205
- }
206
- const type = toolChoice.type;
207
- switch (type) {
208
- case "auto":
209
- case "none":
210
- case "required":
211
- return { tools: groqTools2, toolChoice: type, toolWarnings };
212
- case "tool":
213
- return {
214
- tools: groqTools2,
215
- toolChoice: {
216
- type: "function",
217
- function: {
218
- name: toolChoice.toolName
219
- }
220
- },
221
- toolWarnings
222
- };
223
- default: {
224
- const _exhaustiveCheck = type;
225
- throw new chunkXCR65STK_cjs.UnsupportedFunctionalityError({
226
- functionality: `tool choice type: ${_exhaustiveCheck}`
227
- });
228
- }
229
- }
230
- }
231
- function mapGroqFinishReason(finishReason) {
232
- switch (finishReason) {
233
- case "stop":
234
- return "stop";
235
- case "length":
236
- return "length";
237
- case "content_filter":
238
- return "content-filter";
239
- case "function_call":
240
- case "tool_calls":
241
- return "tool-calls";
242
- default:
243
- return "unknown";
244
- }
245
- }
246
- var GroqChatLanguageModel = class {
247
- constructor(modelId, config) {
248
- this.specificationVersion = "v2";
249
- this.supportedUrls = {
250
- "image/*": [/^https?:\/\/.*$/]
251
- };
252
- this.modelId = modelId;
253
- this.config = config;
254
- }
255
- get provider() {
256
- return this.config.provider;
257
- }
258
- async getArgs({
259
- prompt,
260
- maxOutputTokens,
261
- temperature,
262
- topP,
263
- topK,
264
- frequencyPenalty,
265
- presencePenalty,
266
- stopSequences,
267
- responseFormat,
268
- seed,
269
- stream,
270
- tools,
271
- toolChoice,
272
- providerOptions
273
- }) {
274
- var _a, _b;
275
- const warnings = [];
276
- const groqOptions = await chunk75KU7JB6_cjs.parseProviderOptions({
277
- provider: "groq",
278
- providerOptions,
279
- schema: groqProviderOptions
280
- });
281
- const structuredOutputs = (_a = groqOptions == null ? void 0 : groqOptions.structuredOutputs) != null ? _a : true;
282
- if (topK != null) {
283
- warnings.push({
284
- type: "unsupported-setting",
285
- setting: "topK"
286
- });
287
- }
288
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !structuredOutputs) {
289
- warnings.push({
290
- type: "unsupported-setting",
291
- setting: "responseFormat",
292
- details: "JSON response format schema is only supported with structuredOutputs"
293
- });
294
- }
295
- const {
296
- tools: groqTools2,
297
- toolChoice: groqToolChoice,
298
- toolWarnings
299
- } = prepareTools({ tools, toolChoice, modelId: this.modelId });
300
- return {
301
- args: {
302
- // model id:
303
- model: this.modelId,
304
- // model specific settings:
305
- user: groqOptions == null ? void 0 : groqOptions.user,
306
- parallel_tool_calls: groqOptions == null ? void 0 : groqOptions.parallelToolCalls,
307
- // standardized settings:
308
- max_tokens: maxOutputTokens,
309
- temperature,
310
- top_p: topP,
311
- frequency_penalty: frequencyPenalty,
312
- presence_penalty: presencePenalty,
313
- stop: stopSequences,
314
- seed,
315
- // response format:
316
- response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && responseFormat.schema != null ? {
317
- type: "json_schema",
318
- json_schema: {
319
- schema: responseFormat.schema,
320
- name: (_b = responseFormat.name) != null ? _b : "response",
321
- description: responseFormat.description
322
- }
323
- } : { type: "json_object" } : void 0,
324
- // provider options:
325
- reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
326
- reasoning_effort: groqOptions == null ? void 0 : groqOptions.reasoningEffort,
327
- // messages:
328
- messages: convertToGroqChatMessages(prompt),
329
- // tools:
330
- tools: groqTools2,
331
- tool_choice: groqToolChoice
332
- },
333
- warnings: [...warnings, ...toolWarnings]
334
- };
335
- }
336
- async doGenerate(options) {
337
- var _a, _b, _c, _d, _e, _f, _g;
338
- const { args, warnings } = await this.getArgs({
339
- ...options,
340
- stream: false
341
- });
342
- const body = JSON.stringify(args);
343
- const {
344
- responseHeaders,
345
- value: response,
346
- rawValue: rawResponse
347
- } = await chunk75KU7JB6_cjs.postJsonToApi({
348
- url: this.config.url({
349
- path: "/chat/completions",
350
- modelId: this.modelId
351
- }),
352
- headers: chunk75KU7JB6_cjs.combineHeaders(this.config.headers(), options.headers),
353
- body: args,
354
- failedResponseHandler: groqFailedResponseHandler,
355
- successfulResponseHandler: chunk75KU7JB6_cjs.createJsonResponseHandler(
356
- groqChatResponseSchema
357
- ),
358
- abortSignal: options.abortSignal,
359
- fetch: this.config.fetch
360
- });
361
- const choice = response.choices[0];
362
- const content = [];
363
- const text = choice.message.content;
364
- if (text != null && text.length > 0) {
365
- content.push({ type: "text", text });
366
- }
367
- const reasoning = choice.message.reasoning;
368
- if (reasoning != null && reasoning.length > 0) {
369
- content.push({
370
- type: "reasoning",
371
- text: reasoning
372
- });
373
- }
374
- if (choice.message.tool_calls != null) {
375
- for (const toolCall of choice.message.tool_calls) {
376
- content.push({
377
- type: "tool-call",
378
- toolCallId: (_a = toolCall.id) != null ? _a : chunk75KU7JB6_cjs.generateId(),
379
- toolName: toolCall.function.name,
380
- input: toolCall.function.arguments
381
- });
382
- }
383
- }
384
- return {
385
- content,
386
- finishReason: mapGroqFinishReason(choice.finish_reason),
387
- usage: {
388
- inputTokens: (_c = (_b = response.usage) == null ? void 0 : _b.prompt_tokens) != null ? _c : void 0,
389
- outputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : void 0,
390
- totalTokens: (_g = (_f = response.usage) == null ? void 0 : _f.total_tokens) != null ? _g : void 0
391
- },
392
- response: {
393
- ...getResponseMetadata(response),
394
- headers: responseHeaders,
395
- body: rawResponse
396
- },
397
- warnings,
398
- request: { body }
399
- };
400
- }
401
- async doStream(options) {
402
- const { args, warnings } = await this.getArgs({ ...options, stream: true });
403
- const body = JSON.stringify({ ...args, stream: true });
404
- const { responseHeaders, value: response } = await chunk75KU7JB6_cjs.postJsonToApi({
405
- url: this.config.url({
406
- path: "/chat/completions",
407
- modelId: this.modelId
408
- }),
409
- headers: chunk75KU7JB6_cjs.combineHeaders(this.config.headers(), options.headers),
410
- body: {
411
- ...args,
412
- stream: true
413
- },
414
- failedResponseHandler: groqFailedResponseHandler,
415
- successfulResponseHandler: chunk75KU7JB6_cjs.createEventSourceResponseHandler(groqChatChunkSchema),
416
- abortSignal: options.abortSignal,
417
- fetch: this.config.fetch
418
- });
419
- const toolCalls = [];
420
- let finishReason = "unknown";
421
- const usage = {
422
- inputTokens: void 0,
423
- outputTokens: void 0,
424
- totalTokens: void 0
425
- };
426
- let isFirstChunk = true;
427
- let isActiveText = false;
428
- let isActiveReasoning = false;
429
- return {
430
- stream: response.pipeThrough(
431
- new TransformStream({
432
- start(controller) {
433
- controller.enqueue({ type: "stream-start", warnings });
434
- },
435
- transform(chunk, controller) {
436
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
437
- if (options.includeRawChunks) {
438
- controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
439
- }
440
- if (!chunk.success) {
441
- finishReason = "error";
442
- controller.enqueue({ type: "error", error: chunk.error });
443
- return;
444
- }
445
- const value = chunk.value;
446
- if ("error" in value) {
447
- finishReason = "error";
448
- controller.enqueue({ type: "error", error: value.error });
449
- return;
450
- }
451
- if (isFirstChunk) {
452
- isFirstChunk = false;
453
- controller.enqueue({
454
- type: "response-metadata",
455
- ...getResponseMetadata(value)
456
- });
457
- }
458
- if (((_a = value.x_groq) == null ? void 0 : _a.usage) != null) {
459
- usage.inputTokens = (_b = value.x_groq.usage.prompt_tokens) != null ? _b : void 0;
460
- usage.outputTokens = (_c = value.x_groq.usage.completion_tokens) != null ? _c : void 0;
461
- usage.totalTokens = (_d = value.x_groq.usage.total_tokens) != null ? _d : void 0;
462
- }
463
- const choice = value.choices[0];
464
- if ((choice == null ? void 0 : choice.finish_reason) != null) {
465
- finishReason = mapGroqFinishReason(choice.finish_reason);
466
- }
467
- if ((choice == null ? void 0 : choice.delta) == null) {
468
- return;
469
- }
470
- const delta = choice.delta;
471
- if (delta.reasoning != null && delta.reasoning.length > 0) {
472
- if (!isActiveReasoning) {
473
- controller.enqueue({
474
- type: "reasoning-start",
475
- id: "reasoning-0"
476
- });
477
- isActiveReasoning = true;
478
- }
479
- controller.enqueue({
480
- type: "reasoning-delta",
481
- id: "reasoning-0",
482
- delta: delta.reasoning
483
- });
484
- }
485
- if (delta.content != null && delta.content.length > 0) {
486
- if (!isActiveText) {
487
- controller.enqueue({ type: "text-start", id: "txt-0" });
488
- isActiveText = true;
489
- }
490
- controller.enqueue({
491
- type: "text-delta",
492
- id: "txt-0",
493
- delta: delta.content
494
- });
495
- }
496
- if (delta.tool_calls != null) {
497
- for (const toolCallDelta of delta.tool_calls) {
498
- const index = toolCallDelta.index;
499
- if (toolCalls[index] == null) {
500
- if (toolCallDelta.type !== "function") {
501
- throw new chunkXCR65STK_cjs.InvalidResponseDataError({
502
- data: toolCallDelta,
503
- message: `Expected 'function' type.`
504
- });
505
- }
506
- if (toolCallDelta.id == null) {
507
- throw new chunkXCR65STK_cjs.InvalidResponseDataError({
508
- data: toolCallDelta,
509
- message: `Expected 'id' to be a string.`
510
- });
511
- }
512
- if (((_e = toolCallDelta.function) == null ? void 0 : _e.name) == null) {
513
- throw new chunkXCR65STK_cjs.InvalidResponseDataError({
514
- data: toolCallDelta,
515
- message: `Expected 'function.name' to be a string.`
516
- });
517
- }
518
- controller.enqueue({
519
- type: "tool-input-start",
520
- id: toolCallDelta.id,
521
- toolName: toolCallDelta.function.name
522
- });
523
- toolCalls[index] = {
524
- id: toolCallDelta.id,
525
- type: "function",
526
- function: {
527
- name: toolCallDelta.function.name,
528
- arguments: (_f = toolCallDelta.function.arguments) != null ? _f : ""
529
- },
530
- hasFinished: false
531
- };
532
- const toolCall2 = toolCalls[index];
533
- if (((_g = toolCall2.function) == null ? void 0 : _g.name) != null && ((_h = toolCall2.function) == null ? void 0 : _h.arguments) != null) {
534
- if (toolCall2.function.arguments.length > 0) {
535
- controller.enqueue({
536
- type: "tool-input-delta",
537
- id: toolCall2.id,
538
- delta: toolCall2.function.arguments
539
- });
540
- }
541
- if (chunk75KU7JB6_cjs.isParsableJson(toolCall2.function.arguments)) {
542
- controller.enqueue({
543
- type: "tool-input-end",
544
- id: toolCall2.id
545
- });
546
- controller.enqueue({
547
- type: "tool-call",
548
- toolCallId: (_i = toolCall2.id) != null ? _i : chunk75KU7JB6_cjs.generateId(),
549
- toolName: toolCall2.function.name,
550
- input: toolCall2.function.arguments
551
- });
552
- toolCall2.hasFinished = true;
553
- }
554
- }
555
- continue;
556
- }
557
- const toolCall = toolCalls[index];
558
- if (toolCall.hasFinished) {
559
- continue;
560
- }
561
- if (((_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null) {
562
- toolCall.function.arguments += (_l = (_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null ? _l : "";
563
- }
564
- controller.enqueue({
565
- type: "tool-input-delta",
566
- id: toolCall.id,
567
- delta: (_m = toolCallDelta.function.arguments) != null ? _m : ""
568
- });
569
- if (((_n = toolCall.function) == null ? void 0 : _n.name) != null && ((_o = toolCall.function) == null ? void 0 : _o.arguments) != null && chunk75KU7JB6_cjs.isParsableJson(toolCall.function.arguments)) {
570
- controller.enqueue({
571
- type: "tool-input-end",
572
- id: toolCall.id
573
- });
574
- controller.enqueue({
575
- type: "tool-call",
576
- toolCallId: (_p = toolCall.id) != null ? _p : chunk75KU7JB6_cjs.generateId(),
577
- toolName: toolCall.function.name,
578
- input: toolCall.function.arguments
579
- });
580
- toolCall.hasFinished = true;
581
- }
582
- }
583
- }
584
- },
585
- flush(controller) {
586
- if (isActiveReasoning) {
587
- controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
588
- }
589
- if (isActiveText) {
590
- controller.enqueue({ type: "text-end", id: "txt-0" });
591
- }
592
- controller.enqueue({
593
- type: "finish",
594
- finishReason,
595
- usage,
596
- ...{}
597
- });
598
- }
599
- })
600
- ),
601
- request: { body },
602
- response: { headers: responseHeaders }
603
- };
604
- }
605
- };
606
- var groqChatResponseSchema = v4.z.object({
607
- id: v4.z.string().nullish(),
608
- created: v4.z.number().nullish(),
609
- model: v4.z.string().nullish(),
610
- choices: v4.z.array(
611
- v4.z.object({
612
- message: v4.z.object({
613
- content: v4.z.string().nullish(),
614
- reasoning: v4.z.string().nullish(),
615
- tool_calls: v4.z.array(
616
- v4.z.object({
617
- id: v4.z.string().nullish(),
618
- type: v4.z.literal("function"),
619
- function: v4.z.object({
620
- name: v4.z.string(),
621
- arguments: v4.z.string()
622
- })
623
- })
624
- ).nullish()
625
- }),
626
- index: v4.z.number(),
627
- finish_reason: v4.z.string().nullish()
628
- })
629
- ),
630
- usage: v4.z.object({
631
- prompt_tokens: v4.z.number().nullish(),
632
- completion_tokens: v4.z.number().nullish(),
633
- total_tokens: v4.z.number().nullish()
634
- }).nullish()
635
- });
636
- var groqChatChunkSchema = v4.z.union([
637
- v4.z.object({
638
- id: v4.z.string().nullish(),
639
- created: v4.z.number().nullish(),
640
- model: v4.z.string().nullish(),
641
- choices: v4.z.array(
642
- v4.z.object({
643
- delta: v4.z.object({
644
- content: v4.z.string().nullish(),
645
- reasoning: v4.z.string().nullish(),
646
- tool_calls: v4.z.array(
647
- v4.z.object({
648
- index: v4.z.number(),
649
- id: v4.z.string().nullish(),
650
- type: v4.z.literal("function").optional(),
651
- function: v4.z.object({
652
- name: v4.z.string().nullish(),
653
- arguments: v4.z.string().nullish()
654
- })
655
- })
656
- ).nullish()
657
- }).nullish(),
658
- finish_reason: v4.z.string().nullable().optional(),
659
- index: v4.z.number()
660
- })
661
- ),
662
- x_groq: v4.z.object({
663
- usage: v4.z.object({
664
- prompt_tokens: v4.z.number().nullish(),
665
- completion_tokens: v4.z.number().nullish(),
666
- total_tokens: v4.z.number().nullish()
667
- }).nullish()
668
- }).nullish()
669
- }),
670
- groqErrorDataSchema
671
- ]);
672
- var groqProviderOptionsSchema = v4.z.object({
673
- language: v4.z.string().nullish(),
674
- prompt: v4.z.string().nullish(),
675
- responseFormat: v4.z.string().nullish(),
676
- temperature: v4.z.number().min(0).max(1).nullish(),
677
- timestampGranularities: v4.z.array(v4.z.string()).nullish()
678
- });
679
- var GroqTranscriptionModel = class {
680
- constructor(modelId, config) {
681
- this.modelId = modelId;
682
- this.config = config;
683
- this.specificationVersion = "v2";
684
- }
685
- get provider() {
686
- return this.config.provider;
687
- }
688
- async getArgs({
689
- audio,
690
- mediaType,
691
- providerOptions
692
- }) {
693
- var _a, _b, _c, _d, _e;
694
- const warnings = [];
695
- const groqOptions = await chunk75KU7JB6_cjs.parseProviderOptions({
696
- provider: "groq",
697
- providerOptions,
698
- schema: groqProviderOptionsSchema
699
- });
700
- const formData = new FormData();
701
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([chunk75KU7JB6_cjs.convertBase64ToUint8Array(audio)]);
702
- formData.append("model", this.modelId);
703
- formData.append("file", new File([blob], "audio", { type: mediaType }));
704
- if (groqOptions) {
705
- const transcriptionModelOptions = {
706
- language: (_a = groqOptions.language) != null ? _a : void 0,
707
- prompt: (_b = groqOptions.prompt) != null ? _b : void 0,
708
- response_format: (_c = groqOptions.responseFormat) != null ? _c : void 0,
709
- temperature: (_d = groqOptions.temperature) != null ? _d : void 0,
710
- timestamp_granularities: (_e = groqOptions.timestampGranularities) != null ? _e : void 0
711
- };
712
- for (const key in transcriptionModelOptions) {
713
- const value = transcriptionModelOptions[key];
714
- if (value !== void 0) {
715
- formData.append(key, String(value));
716
- }
717
- }
718
- }
719
- return {
720
- formData,
721
- warnings
722
- };
723
- }
724
- async doGenerate(options) {
725
- var _a, _b, _c, _d, _e;
726
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
727
- const { formData, warnings } = await this.getArgs(options);
728
- const {
729
- value: response,
730
- responseHeaders,
731
- rawValue: rawResponse
732
- } = await chunk75KU7JB6_cjs.postFormDataToApi({
733
- url: this.config.url({
734
- path: "/audio/transcriptions",
735
- modelId: this.modelId
736
- }),
737
- headers: chunk75KU7JB6_cjs.combineHeaders(this.config.headers(), options.headers),
738
- formData,
739
- failedResponseHandler: groqFailedResponseHandler,
740
- successfulResponseHandler: chunk75KU7JB6_cjs.createJsonResponseHandler(
741
- groqTranscriptionResponseSchema
742
- ),
743
- abortSignal: options.abortSignal,
744
- fetch: this.config.fetch
745
- });
746
- return {
747
- text: response.text,
748
- segments: (_e = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
749
- text: segment.text,
750
- startSecond: segment.start,
751
- endSecond: segment.end
752
- }))) != null ? _e : [],
753
- language: response.language,
754
- durationInSeconds: response.duration,
755
- warnings,
756
- response: {
757
- timestamp: currentDate,
758
- modelId: this.modelId,
759
- headers: responseHeaders,
760
- body: rawResponse
761
- }
762
- };
763
- }
764
- };
765
- var groqTranscriptionResponseSchema = v4.z.object({
766
- task: v4.z.string(),
767
- language: v4.z.string(),
768
- duration: v4.z.number(),
769
- text: v4.z.string(),
770
- segments: v4.z.array(
771
- v4.z.object({
772
- id: v4.z.number(),
773
- seek: v4.z.number(),
774
- start: v4.z.number(),
775
- end: v4.z.number(),
776
- text: v4.z.string(),
777
- tokens: v4.z.array(v4.z.number()),
778
- temperature: v4.z.number(),
779
- avg_logprob: v4.z.number(),
780
- compression_ratio: v4.z.number(),
781
- no_speech_prob: v4.z.number()
782
- })
783
- ),
784
- x_groq: v4.z.object({
785
- id: v4.z.string()
786
- })
787
- });
788
- var browserSearch = chunk75KU7JB6_cjs.createProviderDefinedToolFactory({
789
- id: "groq.browser_search",
790
- name: "browser_search",
791
- inputSchema: v4.z.object({})
792
- });
793
- var groqTools = {
794
- browserSearch
795
- };
796
- function createGroq(options = {}) {
797
- var _a;
798
- const baseURL = (_a = chunk75KU7JB6_cjs.withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
799
- const getHeaders = () => ({
800
- Authorization: `Bearer ${chunk75KU7JB6_cjs.loadApiKey({
801
- apiKey: options.apiKey,
802
- environmentVariableName: "GROQ_API_KEY",
803
- description: "Groq"
804
- })}`,
805
- ...options.headers
806
- });
807
- const createChatModel = (modelId) => new GroqChatLanguageModel(modelId, {
808
- provider: "groq.chat",
809
- url: ({ path }) => `${baseURL}${path}`,
810
- headers: getHeaders,
811
- fetch: options.fetch
812
- });
813
- const createLanguageModel = (modelId) => {
814
- if (new.target) {
815
- throw new Error(
816
- "The Groq model function cannot be called with the new keyword."
817
- );
818
- }
819
- return createChatModel(modelId);
820
- };
821
- const createTranscriptionModel = (modelId) => {
822
- return new GroqTranscriptionModel(modelId, {
823
- provider: "groq.transcription",
824
- url: ({ path }) => `${baseURL}${path}`,
825
- headers: getHeaders,
826
- fetch: options.fetch
827
- });
828
- };
829
- const provider = function(modelId) {
830
- return createLanguageModel(modelId);
831
- };
832
- provider.languageModel = createLanguageModel;
833
- provider.chat = createChatModel;
834
- provider.textEmbeddingModel = (modelId) => {
835
- throw new chunkXCR65STK_cjs.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
836
- };
837
- provider.imageModel = (modelId) => {
838
- throw new chunkXCR65STK_cjs.NoSuchModelError({ modelId, modelType: "imageModel" });
839
- };
840
- provider.transcription = createTranscriptionModel;
841
- provider.tools = groqTools;
842
- return provider;
843
- }
844
- var groq = createGroq();
845
-
846
- exports.browserSearch = browserSearch;
847
- exports.createGroq = createGroq;
848
- exports.groq = groq;
849
- //# sourceMappingURL=dist-HBUYSRRO.cjs.map
850
- //# sourceMappingURL=dist-HBUYSRRO.cjs.map