@ai-sdk/groq 4.0.0-beta.4 → 4.0.0-beta.54

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.
package/dist/index.js CHANGED
@@ -1,40 +1,29 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- VERSION: () => VERSION,
24
- browserSearch: () => browserSearch,
25
- createGroq: () => createGroq,
26
- groq: () => groq
27
- });
28
- module.exports = __toCommonJS(index_exports);
29
-
30
1
  // src/groq-provider.ts
31
- var import_provider4 = require("@ai-sdk/provider");
32
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
2
+ import {
3
+ NoSuchModelError
4
+ } from "@ai-sdk/provider";
5
+ import {
6
+ loadApiKey,
7
+ withoutTrailingSlash,
8
+ withUserAgentSuffix
9
+ } from "@ai-sdk/provider-utils";
33
10
 
34
11
  // src/groq-chat-language-model.ts
35
- var import_provider3 = require("@ai-sdk/provider");
36
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
37
- var import_v43 = require("zod/v4");
12
+ import {
13
+ StreamingToolCallTracker,
14
+ combineHeaders,
15
+ createEventSourceResponseHandler,
16
+ createJsonResponseHandler,
17
+ generateId,
18
+ isCustomReasoning,
19
+ mapReasoningToProviderEffort,
20
+ parseProviderOptions,
21
+ postJsonToApi,
22
+ serializeModelOptions,
23
+ WORKFLOW_SERIALIZE,
24
+ WORKFLOW_DESERIALIZE
25
+ } from "@ai-sdk/provider-utils";
26
+ import { z as z3 } from "zod/v4";
38
27
 
39
28
  // src/convert-groq-usage.ts
40
29
  function convertGroqUsage(usage) {
@@ -76,8 +65,14 @@ function convertGroqUsage(usage) {
76
65
  }
77
66
 
78
67
  // src/convert-to-groq-chat-messages.ts
79
- var import_provider = require("@ai-sdk/provider");
80
- var import_provider_utils = require("@ai-sdk/provider-utils");
68
+ import {
69
+ UnsupportedFunctionalityError
70
+ } from "@ai-sdk/provider";
71
+ import {
72
+ convertToBase64,
73
+ getTopLevelMediaType,
74
+ resolveFullMediaType
75
+ } from "@ai-sdk/provider-utils";
81
76
  function convertToGroqChatMessages(prompt) {
82
77
  var _a;
83
78
  const messages = [];
@@ -100,18 +95,32 @@ function convertToGroqChatMessages(prompt) {
100
95
  return { type: "text", text: part.text };
101
96
  }
102
97
  case "file": {
103
- if (!part.mediaType.startsWith("image/")) {
104
- throw new import_provider.UnsupportedFunctionalityError({
105
- functionality: "Non-image file content parts"
106
- });
107
- }
108
- const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
109
- return {
110
- type: "image_url",
111
- image_url: {
112
- url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`
98
+ switch (part.data.type) {
99
+ case "reference": {
100
+ throw new UnsupportedFunctionalityError({
101
+ functionality: "file parts with provider references"
102
+ });
103
+ }
104
+ case "text": {
105
+ throw new UnsupportedFunctionalityError({
106
+ functionality: "text file parts"
107
+ });
113
108
  }
114
- };
109
+ case "url":
110
+ case "data": {
111
+ if (getTopLevelMediaType(part.mediaType) !== "image") {
112
+ throw new UnsupportedFunctionalityError({
113
+ functionality: "Non-image file content parts"
114
+ });
115
+ }
116
+ return {
117
+ type: "image_url",
118
+ image_url: {
119
+ url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`
120
+ }
121
+ };
122
+ }
123
+ }
115
124
  }
116
125
  }
117
126
  })
@@ -168,7 +177,7 @@ function convertToGroqChatMessages(prompt) {
168
177
  contentValue = output.value;
169
178
  break;
170
179
  case "execution-denied":
171
- contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
180
+ contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
172
181
  break;
173
182
  case "content":
174
183
  case "json":
@@ -206,30 +215,30 @@ function getResponseMetadata({
206
215
  };
207
216
  }
208
217
 
209
- // src/groq-chat-options.ts
210
- var import_v4 = require("zod/v4");
211
- var groqLanguageModelOptions = import_v4.z.object({
212
- reasoningFormat: import_v4.z.enum(["parsed", "raw", "hidden"]).optional(),
218
+ // src/groq-chat-language-model-options.ts
219
+ import { z } from "zod/v4";
220
+ var groqLanguageModelChatOptions = z.object({
221
+ reasoningFormat: z.enum(["parsed", "raw", "hidden"]).optional(),
213
222
  /**
214
223
  * Specifies the reasoning effort level for model inference.
215
224
  * @see https://console.groq.com/docs/reasoning#reasoning-effort
216
225
  */
217
- reasoningEffort: import_v4.z.enum(["none", "default", "low", "medium", "high"]).optional(),
226
+ reasoningEffort: z.enum(["none", "default", "low", "medium", "high"]).optional(),
218
227
  /**
219
228
  * Whether to enable parallel function calling during tool use. Default to true.
220
229
  */
221
- parallelToolCalls: import_v4.z.boolean().optional(),
230
+ parallelToolCalls: z.boolean().optional(),
222
231
  /**
223
232
  * A unique identifier representing your end-user, which can help OpenAI to
224
233
  * monitor and detect abuse. Learn more.
225
234
  */
226
- user: import_v4.z.string().optional(),
235
+ user: z.string().optional(),
227
236
  /**
228
237
  * Whether to use structured outputs.
229
238
  *
230
239
  * @default true
231
240
  */
232
- structuredOutputs: import_v4.z.boolean().optional(),
241
+ structuredOutputs: z.boolean().optional(),
233
242
  /**
234
243
  * Whether to use strict JSON schema validation.
235
244
  * When true, the model uses constrained decoding to guarantee schema compliance.
@@ -237,34 +246,37 @@ var groqLanguageModelOptions = import_v4.z.object({
237
246
  *
238
247
  * @default true
239
248
  */
240
- strictJsonSchema: import_v4.z.boolean().optional(),
249
+ strictJsonSchema: z.boolean().optional(),
241
250
  /**
242
251
  * Service tier for the request.
243
252
  * - 'on_demand': Default tier with consistent performance and fairness
253
+ * - 'performance': Prioritized tier for latency-sensitive workloads
244
254
  * - 'flex': Higher throughput tier optimized for workloads that can handle occasional request failures
245
255
  * - 'auto': Uses on_demand rate limits, then falls back to flex tier if exceeded
246
256
  *
247
257
  * @default 'on_demand'
248
258
  */
249
- serviceTier: import_v4.z.enum(["on_demand", "flex", "auto"]).optional()
259
+ serviceTier: z.enum(["on_demand", "performance", "flex", "auto"]).optional()
250
260
  });
251
261
 
252
262
  // src/groq-error.ts
253
- var import_v42 = require("zod/v4");
254
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
255
- var groqErrorDataSchema = import_v42.z.object({
256
- error: import_v42.z.object({
257
- message: import_v42.z.string(),
258
- type: import_v42.z.string()
263
+ import { z as z2 } from "zod/v4";
264
+ import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
265
+ var groqErrorDataSchema = z2.object({
266
+ error: z2.object({
267
+ message: z2.string(),
268
+ type: z2.string()
259
269
  })
260
270
  });
261
- var groqFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
271
+ var groqFailedResponseHandler = createJsonErrorResponseHandler({
262
272
  errorSchema: groqErrorDataSchema,
263
273
  errorToMessage: (data) => data.error.message
264
274
  });
265
275
 
266
276
  // src/groq-prepare-tools.ts
267
- var import_provider2 = require("@ai-sdk/provider");
277
+ import {
278
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError2
279
+ } from "@ai-sdk/provider";
268
280
 
269
281
  // src/groq-browser-search-models.ts
270
282
  var BROWSER_SEARCH_SUPPORTED_MODELS = [
@@ -344,7 +356,7 @@ function prepareTools({
344
356
  };
345
357
  default: {
346
358
  const _exhaustiveCheck = type;
347
- throw new import_provider2.UnsupportedFunctionalityError({
359
+ throw new UnsupportedFunctionalityError2({
348
360
  functionality: `tool choice type: ${_exhaustiveCheck}`
349
361
  });
350
362
  }
@@ -369,15 +381,24 @@ function mapGroqFinishReason(finishReason) {
369
381
  }
370
382
 
371
383
  // src/groq-chat-language-model.ts
372
- var GroqChatLanguageModel = class {
384
+ var GroqChatLanguageModel = class _GroqChatLanguageModel {
373
385
  constructor(modelId, config) {
374
- this.specificationVersion = "v3";
386
+ this.specificationVersion = "v4";
375
387
  this.supportedUrls = {
376
388
  "image/*": [/^https?:\/\/.*$/]
377
389
  };
378
390
  this.modelId = modelId;
379
391
  this.config = config;
380
392
  }
393
+ static [WORKFLOW_SERIALIZE](model) {
394
+ return serializeModelOptions({
395
+ modelId: model.modelId,
396
+ config: model.config
397
+ });
398
+ }
399
+ static [WORKFLOW_DESERIALIZE](options) {
400
+ return new _GroqChatLanguageModel(options.modelId, options.config);
401
+ }
381
402
  get provider() {
382
403
  return this.config.provider;
383
404
  }
@@ -392,17 +413,17 @@ var GroqChatLanguageModel = class {
392
413
  stopSequences,
393
414
  responseFormat,
394
415
  seed,
395
- stream,
416
+ reasoning,
396
417
  tools,
397
418
  toolChoice,
398
419
  providerOptions
399
420
  }) {
400
- var _a, _b, _c;
421
+ var _a, _b, _c, _d;
401
422
  const warnings = [];
402
- const groqOptions = await (0, import_provider_utils3.parseProviderOptions)({
423
+ const groqOptions = await parseProviderOptions({
403
424
  provider: "groq",
404
425
  providerOptions,
405
- schema: groqLanguageModelOptions
426
+ schema: groqLanguageModelChatOptions
406
427
  });
407
428
  const structuredOutputs = (_a = groqOptions == null ? void 0 : groqOptions.structuredOutputs) != null ? _a : true;
408
429
  const strictJsonSchema = (_b = groqOptions == null ? void 0 : groqOptions.strictJsonSchema) != null ? _b : true;
@@ -448,7 +469,17 @@ var GroqChatLanguageModel = class {
448
469
  } : { type: "json_object" } : void 0,
449
470
  // provider options:
450
471
  reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
451
- reasoning_effort: groqOptions == null ? void 0 : groqOptions.reasoningEffort,
472
+ reasoning_effort: (_d = groqOptions == null ? void 0 : groqOptions.reasoningEffort) != null ? _d : isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
473
+ reasoning,
474
+ effortMap: {
475
+ minimal: "low",
476
+ low: "low",
477
+ medium: "medium",
478
+ high: "high",
479
+ xhigh: "high"
480
+ },
481
+ warnings
482
+ }) : void 0,
452
483
  service_tier: groqOptions == null ? void 0 : groqOptions.serviceTier,
453
484
  // messages:
454
485
  messages: convertToGroqChatMessages(prompt),
@@ -460,25 +491,22 @@ var GroqChatLanguageModel = class {
460
491
  };
461
492
  }
462
493
  async doGenerate(options) {
463
- var _a, _b;
464
- const { args, warnings } = await this.getArgs({
465
- ...options,
466
- stream: false
467
- });
494
+ var _a, _b, _c, _d;
495
+ const { args, warnings } = await this.getArgs(options);
468
496
  const body = JSON.stringify(args);
469
497
  const {
470
498
  responseHeaders,
471
499
  value: response,
472
500
  rawValue: rawResponse
473
- } = await (0, import_provider_utils3.postJsonToApi)({
501
+ } = await postJsonToApi({
474
502
  url: this.config.url({
475
503
  path: "/chat/completions",
476
504
  modelId: this.modelId
477
505
  }),
478
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
506
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
479
507
  body: args,
480
508
  failedResponseHandler: groqFailedResponseHandler,
481
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
509
+ successfulResponseHandler: createJsonResponseHandler(
482
510
  groqChatResponseSchema
483
511
  ),
484
512
  abortSignal: options.abortSignal,
@@ -501,7 +529,7 @@ var GroqChatLanguageModel = class {
501
529
  for (const toolCall of choice.message.tool_calls) {
502
530
  content.push({
503
531
  type: "tool-call",
504
- toolCallId: (_a = toolCall.id) != null ? _a : (0, import_provider_utils3.generateId)(),
532
+ toolCallId: (_c = toolCall.id) != null ? _c : generateId(),
505
533
  toolName: toolCall.function.name,
506
534
  input: toolCall.function.arguments
507
535
  });
@@ -511,7 +539,7 @@ var GroqChatLanguageModel = class {
511
539
  content,
512
540
  finishReason: {
513
541
  unified: mapGroqFinishReason(choice.finish_reason),
514
- raw: (_b = choice.finish_reason) != null ? _b : void 0
542
+ raw: (_d = choice.finish_reason) != null ? _d : void 0
515
543
  },
516
544
  usage: convertGroqUsage(response.usage),
517
545
  response: {
@@ -524,24 +552,22 @@ var GroqChatLanguageModel = class {
524
552
  };
525
553
  }
526
554
  async doStream(options) {
527
- const { args, warnings } = await this.getArgs({ ...options, stream: true });
528
- const body = JSON.stringify({ ...args, stream: true });
529
- const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
555
+ var _a, _b;
556
+ const { args, warnings } = await this.getArgs(options);
557
+ const body = { ...args, stream: true };
558
+ const { responseHeaders, value: response } = await postJsonToApi({
530
559
  url: this.config.url({
531
560
  path: "/chat/completions",
532
561
  modelId: this.modelId
533
562
  }),
534
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
535
- body: {
536
- ...args,
537
- stream: true
538
- },
563
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
564
+ body,
539
565
  failedResponseHandler: groqFailedResponseHandler,
540
- successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(groqChatChunkSchema),
566
+ successfulResponseHandler: createEventSourceResponseHandler(groqChatChunkSchema),
541
567
  abortSignal: options.abortSignal,
542
568
  fetch: this.config.fetch
543
569
  });
544
- const toolCalls = [];
570
+ let toolCallTracker;
545
571
  let finishReason = {
546
572
  unified: "other",
547
573
  raw: void 0
@@ -555,10 +581,14 @@ var GroqChatLanguageModel = class {
555
581
  stream: response.pipeThrough(
556
582
  new TransformStream({
557
583
  start(controller) {
584
+ toolCallTracker = new StreamingToolCallTracker(controller, {
585
+ generateId,
586
+ typeValidation: "required"
587
+ });
558
588
  controller.enqueue({ type: "stream-start", warnings });
559
589
  },
560
590
  transform(chunk, controller) {
561
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
591
+ var _a2;
562
592
  if (options.includeRawChunks) {
563
593
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
564
594
  }
@@ -586,7 +616,7 @@ var GroqChatLanguageModel = class {
586
616
  ...getResponseMetadata(value)
587
617
  });
588
618
  }
589
- if (((_a = value.x_groq) == null ? void 0 : _a.usage) != null) {
619
+ if (((_a2 = value.x_groq) == null ? void 0 : _a2.usage) != null) {
590
620
  usage = value.x_groq.usage;
591
621
  }
592
622
  const choice = value.choices[0];
@@ -641,90 +671,7 @@ var GroqChatLanguageModel = class {
641
671
  isActiveReasoning = false;
642
672
  }
643
673
  for (const toolCallDelta of delta.tool_calls) {
644
- const index = toolCallDelta.index;
645
- if (toolCalls[index] == null) {
646
- if (toolCallDelta.type !== "function") {
647
- throw new import_provider3.InvalidResponseDataError({
648
- data: toolCallDelta,
649
- message: `Expected 'function' type.`
650
- });
651
- }
652
- if (toolCallDelta.id == null) {
653
- throw new import_provider3.InvalidResponseDataError({
654
- data: toolCallDelta,
655
- message: `Expected 'id' to be a string.`
656
- });
657
- }
658
- if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
659
- throw new import_provider3.InvalidResponseDataError({
660
- data: toolCallDelta,
661
- message: `Expected 'function.name' to be a string.`
662
- });
663
- }
664
- controller.enqueue({
665
- type: "tool-input-start",
666
- id: toolCallDelta.id,
667
- toolName: toolCallDelta.function.name
668
- });
669
- toolCalls[index] = {
670
- id: toolCallDelta.id,
671
- type: "function",
672
- function: {
673
- name: toolCallDelta.function.name,
674
- arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
675
- },
676
- hasFinished: false
677
- };
678
- const toolCall2 = toolCalls[index];
679
- if (((_d = toolCall2.function) == null ? void 0 : _d.name) != null && ((_e = toolCall2.function) == null ? void 0 : _e.arguments) != null) {
680
- if (toolCall2.function.arguments.length > 0) {
681
- controller.enqueue({
682
- type: "tool-input-delta",
683
- id: toolCall2.id,
684
- delta: toolCall2.function.arguments
685
- });
686
- }
687
- if ((0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) {
688
- controller.enqueue({
689
- type: "tool-input-end",
690
- id: toolCall2.id
691
- });
692
- controller.enqueue({
693
- type: "tool-call",
694
- toolCallId: (_f = toolCall2.id) != null ? _f : (0, import_provider_utils3.generateId)(),
695
- toolName: toolCall2.function.name,
696
- input: toolCall2.function.arguments
697
- });
698
- toolCall2.hasFinished = true;
699
- }
700
- }
701
- continue;
702
- }
703
- const toolCall = toolCalls[index];
704
- if (toolCall.hasFinished) {
705
- continue;
706
- }
707
- if (((_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null) {
708
- toolCall.function.arguments += (_i = (_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null ? _i : "";
709
- }
710
- controller.enqueue({
711
- type: "tool-input-delta",
712
- id: toolCall.id,
713
- delta: (_j = toolCallDelta.function.arguments) != null ? _j : ""
714
- });
715
- if (((_k = toolCall.function) == null ? void 0 : _k.name) != null && ((_l = toolCall.function) == null ? void 0 : _l.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) {
716
- controller.enqueue({
717
- type: "tool-input-end",
718
- id: toolCall.id
719
- });
720
- controller.enqueue({
721
- type: "tool-call",
722
- toolCallId: (_m = toolCall.id) != null ? _m : (0, import_provider_utils3.generateId)(),
723
- toolName: toolCall.function.name,
724
- input: toolCall.function.arguments
725
- });
726
- toolCall.hasFinished = true;
727
- }
674
+ toolCallTracker.processDelta(toolCallDelta);
728
675
  }
729
676
  }
730
677
  },
@@ -735,6 +682,7 @@ var GroqChatLanguageModel = class {
735
682
  if (isActiveText) {
736
683
  controller.enqueue({ type: "text-end", id: "txt-0" });
737
684
  }
685
+ toolCallTracker.flush();
738
686
  controller.enqueue({
739
687
  type: "finish",
740
688
  finishReason,
@@ -744,83 +692,83 @@ var GroqChatLanguageModel = class {
744
692
  }
745
693
  })
746
694
  ),
747
- request: { body },
695
+ request: { body: JSON.stringify(body) },
748
696
  response: { headers: responseHeaders }
749
697
  };
750
698
  }
751
699
  };
752
- var groqChatResponseSchema = import_v43.z.object({
753
- id: import_v43.z.string().nullish(),
754
- created: import_v43.z.number().nullish(),
755
- model: import_v43.z.string().nullish(),
756
- choices: import_v43.z.array(
757
- import_v43.z.object({
758
- message: import_v43.z.object({
759
- content: import_v43.z.string().nullish(),
760
- reasoning: import_v43.z.string().nullish(),
761
- tool_calls: import_v43.z.array(
762
- import_v43.z.object({
763
- id: import_v43.z.string().nullish(),
764
- type: import_v43.z.literal("function"),
765
- function: import_v43.z.object({
766
- name: import_v43.z.string(),
767
- arguments: import_v43.z.string()
700
+ var groqChatResponseSchema = z3.object({
701
+ id: z3.string().nullish(),
702
+ created: z3.number().nullish(),
703
+ model: z3.string().nullish(),
704
+ choices: z3.array(
705
+ z3.object({
706
+ message: z3.object({
707
+ content: z3.string().nullish(),
708
+ reasoning: z3.string().nullish(),
709
+ tool_calls: z3.array(
710
+ z3.object({
711
+ id: z3.string().nullish(),
712
+ type: z3.literal("function"),
713
+ function: z3.object({
714
+ name: z3.string(),
715
+ arguments: z3.string()
768
716
  })
769
717
  })
770
718
  ).nullish()
771
719
  }),
772
- index: import_v43.z.number(),
773
- finish_reason: import_v43.z.string().nullish()
720
+ index: z3.number(),
721
+ finish_reason: z3.string().nullish()
774
722
  })
775
723
  ),
776
- usage: import_v43.z.object({
777
- prompt_tokens: import_v43.z.number().nullish(),
778
- completion_tokens: import_v43.z.number().nullish(),
779
- total_tokens: import_v43.z.number().nullish(),
780
- prompt_tokens_details: import_v43.z.object({
781
- cached_tokens: import_v43.z.number().nullish()
724
+ usage: z3.object({
725
+ prompt_tokens: z3.number().nullish(),
726
+ completion_tokens: z3.number().nullish(),
727
+ total_tokens: z3.number().nullish(),
728
+ prompt_tokens_details: z3.object({
729
+ cached_tokens: z3.number().nullish()
782
730
  }).nullish(),
783
- completion_tokens_details: import_v43.z.object({
784
- reasoning_tokens: import_v43.z.number().nullish()
731
+ completion_tokens_details: z3.object({
732
+ reasoning_tokens: z3.number().nullish()
785
733
  }).nullish()
786
734
  }).nullish()
787
735
  });
788
- var groqChatChunkSchema = import_v43.z.union([
789
- import_v43.z.object({
790
- id: import_v43.z.string().nullish(),
791
- created: import_v43.z.number().nullish(),
792
- model: import_v43.z.string().nullish(),
793
- choices: import_v43.z.array(
794
- import_v43.z.object({
795
- delta: import_v43.z.object({
796
- content: import_v43.z.string().nullish(),
797
- reasoning: import_v43.z.string().nullish(),
798
- tool_calls: import_v43.z.array(
799
- import_v43.z.object({
800
- index: import_v43.z.number(),
801
- id: import_v43.z.string().nullish(),
802
- type: import_v43.z.literal("function").optional(),
803
- function: import_v43.z.object({
804
- name: import_v43.z.string().nullish(),
805
- arguments: import_v43.z.string().nullish()
736
+ var groqChatChunkSchema = z3.union([
737
+ z3.object({
738
+ id: z3.string().nullish(),
739
+ created: z3.number().nullish(),
740
+ model: z3.string().nullish(),
741
+ choices: z3.array(
742
+ z3.object({
743
+ delta: z3.object({
744
+ content: z3.string().nullish(),
745
+ reasoning: z3.string().nullish(),
746
+ tool_calls: z3.array(
747
+ z3.object({
748
+ index: z3.number(),
749
+ id: z3.string().nullish(),
750
+ type: z3.literal("function").optional(),
751
+ function: z3.object({
752
+ name: z3.string().nullish(),
753
+ arguments: z3.string().nullish()
806
754
  })
807
755
  })
808
756
  ).nullish()
809
757
  }).nullish(),
810
- finish_reason: import_v43.z.string().nullable().optional(),
811
- index: import_v43.z.number()
758
+ finish_reason: z3.string().nullable().optional(),
759
+ index: z3.number()
812
760
  })
813
761
  ),
814
- x_groq: import_v43.z.object({
815
- usage: import_v43.z.object({
816
- prompt_tokens: import_v43.z.number().nullish(),
817
- completion_tokens: import_v43.z.number().nullish(),
818
- total_tokens: import_v43.z.number().nullish(),
819
- prompt_tokens_details: import_v43.z.object({
820
- cached_tokens: import_v43.z.number().nullish()
762
+ x_groq: z3.object({
763
+ usage: z3.object({
764
+ prompt_tokens: z3.number().nullish(),
765
+ completion_tokens: z3.number().nullish(),
766
+ total_tokens: z3.number().nullish(),
767
+ prompt_tokens_details: z3.object({
768
+ cached_tokens: z3.number().nullish()
821
769
  }).nullish(),
822
- completion_tokens_details: import_v43.z.object({
823
- reasoning_tokens: import_v43.z.number().nullish()
770
+ completion_tokens_details: z3.object({
771
+ reasoning_tokens: z3.number().nullish()
824
772
  }).nullish()
825
773
  }).nullish()
826
774
  }).nullish()
@@ -829,34 +777,56 @@ var groqChatChunkSchema = import_v43.z.union([
829
777
  ]);
830
778
 
831
779
  // src/groq-transcription-model.ts
832
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
833
- var import_v45 = require("zod/v4");
780
+ import {
781
+ combineHeaders as combineHeaders2,
782
+ convertBase64ToUint8Array,
783
+ createJsonResponseHandler as createJsonResponseHandler2,
784
+ mediaTypeToExtension,
785
+ parseProviderOptions as parseProviderOptions2,
786
+ postFormDataToApi,
787
+ serializeModelOptions as serializeModelOptions2,
788
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
789
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
790
+ } from "@ai-sdk/provider-utils";
791
+ import { z as z5 } from "zod/v4";
834
792
 
835
- // src/groq-transcription-options.ts
836
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
837
- var import_v44 = require("zod/v4");
838
- var groqTranscriptionModelOptions = (0, import_provider_utils4.lazySchema)(
839
- () => (0, import_provider_utils4.zodSchema)(
840
- import_v44.z.object({
841
- language: import_v44.z.string().nullish(),
842
- prompt: import_v44.z.string().nullish(),
843
- responseFormat: import_v44.z.string().nullish(),
844
- temperature: import_v44.z.number().min(0).max(1).nullish(),
845
- timestampGranularities: import_v44.z.array(import_v44.z.string()).nullish()
793
+ // src/groq-transcription-model-options.ts
794
+ import {
795
+ lazySchema,
796
+ zodSchema
797
+ } from "@ai-sdk/provider-utils";
798
+ import { z as z4 } from "zod/v4";
799
+ var groqTranscriptionModelOptions = lazySchema(
800
+ () => zodSchema(
801
+ z4.object({
802
+ language: z4.string().nullish(),
803
+ prompt: z4.string().nullish(),
804
+ responseFormat: z4.string().nullish(),
805
+ temperature: z4.number().min(0).max(1).nullish(),
806
+ timestampGranularities: z4.array(z4.string()).nullish()
846
807
  })
847
808
  )
848
809
  );
849
810
 
850
811
  // src/groq-transcription-model.ts
851
- var GroqTranscriptionModel = class {
812
+ var GroqTranscriptionModel = class _GroqTranscriptionModel {
852
813
  constructor(modelId, config) {
853
814
  this.modelId = modelId;
854
815
  this.config = config;
855
- this.specificationVersion = "v3";
816
+ this.specificationVersion = "v4";
856
817
  }
857
818
  get provider() {
858
819
  return this.config.provider;
859
820
  }
821
+ static [WORKFLOW_SERIALIZE2](model) {
822
+ return serializeModelOptions2({
823
+ modelId: model.modelId,
824
+ config: model.config
825
+ });
826
+ }
827
+ static [WORKFLOW_DESERIALIZE2](options) {
828
+ return new _GroqTranscriptionModel(options.modelId, options.config);
829
+ }
860
830
  async getArgs({
861
831
  audio,
862
832
  mediaType,
@@ -864,15 +834,15 @@ var GroqTranscriptionModel = class {
864
834
  }) {
865
835
  var _a, _b, _c, _d, _e;
866
836
  const warnings = [];
867
- const groqOptions = await (0, import_provider_utils5.parseProviderOptions)({
837
+ const groqOptions = await parseProviderOptions2({
868
838
  provider: "groq",
869
839
  providerOptions,
870
840
  schema: groqTranscriptionModelOptions
871
841
  });
872
842
  const formData = new FormData();
873
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils5.convertBase64ToUint8Array)(audio)]);
843
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
874
844
  formData.append("model", this.modelId);
875
- const fileExtension = (0, import_provider_utils5.mediaTypeToExtension)(mediaType);
845
+ const fileExtension = mediaTypeToExtension(mediaType);
876
846
  formData.append(
877
847
  "file",
878
848
  new File([blob], "audio", { type: mediaType }),
@@ -905,22 +875,22 @@ var GroqTranscriptionModel = class {
905
875
  };
906
876
  }
907
877
  async doGenerate(options) {
908
- var _a, _b, _c, _d, _e, _f, _g;
878
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
909
879
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
910
880
  const { formData, warnings } = await this.getArgs(options);
911
881
  const {
912
882
  value: response,
913
883
  responseHeaders,
914
884
  rawValue: rawResponse
915
- } = await (0, import_provider_utils5.postFormDataToApi)({
885
+ } = await postFormDataToApi({
916
886
  url: this.config.url({
917
887
  path: "/audio/transcriptions",
918
888
  modelId: this.modelId
919
889
  }),
920
- headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
890
+ headers: combineHeaders2((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
921
891
  formData,
922
892
  failedResponseHandler: groqFailedResponseHandler,
923
- successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
893
+ successfulResponseHandler: createJsonResponseHandler2(
924
894
  groqTranscriptionResponseSchema
925
895
  ),
926
896
  abortSignal: options.abortSignal,
@@ -928,13 +898,13 @@ var GroqTranscriptionModel = class {
928
898
  });
929
899
  return {
930
900
  text: response.text,
931
- segments: (_e = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
901
+ segments: (_g = (_f = response.segments) == null ? void 0 : _f.map((segment) => ({
932
902
  text: segment.text,
933
903
  startSecond: segment.start,
934
904
  endSecond: segment.end
935
- }))) != null ? _e : [],
936
- language: (_f = response.language) != null ? _f : void 0,
937
- durationInSeconds: (_g = response.duration) != null ? _g : void 0,
905
+ }))) != null ? _g : [],
906
+ language: (_h = response.language) != null ? _h : void 0,
907
+ durationInSeconds: (_i = response.duration) != null ? _i : void 0,
938
908
  warnings,
939
909
  response: {
940
910
  timestamp: currentDate,
@@ -945,37 +915,42 @@ var GroqTranscriptionModel = class {
945
915
  };
946
916
  }
947
917
  };
948
- var groqTranscriptionResponseSchema = import_v45.z.object({
949
- text: import_v45.z.string(),
950
- x_groq: import_v45.z.object({
951
- id: import_v45.z.string()
918
+ var groqTranscriptionResponseSchema = z5.object({
919
+ text: z5.string(),
920
+ x_groq: z5.object({
921
+ id: z5.string()
952
922
  }),
953
923
  // additional properties are returned when `response_format: 'verbose_json'` is
954
- task: import_v45.z.string().nullish(),
955
- language: import_v45.z.string().nullish(),
956
- duration: import_v45.z.number().nullish(),
957
- segments: import_v45.z.array(
958
- import_v45.z.object({
959
- id: import_v45.z.number(),
960
- seek: import_v45.z.number(),
961
- start: import_v45.z.number(),
962
- end: import_v45.z.number(),
963
- text: import_v45.z.string(),
964
- tokens: import_v45.z.array(import_v45.z.number()),
965
- temperature: import_v45.z.number(),
966
- avg_logprob: import_v45.z.number(),
967
- compression_ratio: import_v45.z.number(),
968
- no_speech_prob: import_v45.z.number()
924
+ task: z5.string().nullish(),
925
+ language: z5.string().nullish(),
926
+ duration: z5.number().nullish(),
927
+ segments: z5.array(
928
+ z5.object({
929
+ id: z5.number(),
930
+ seek: z5.number(),
931
+ start: z5.number(),
932
+ end: z5.number(),
933
+ text: z5.string(),
934
+ tokens: z5.array(z5.number()),
935
+ temperature: z5.number(),
936
+ avg_logprob: z5.number(),
937
+ compression_ratio: z5.number(),
938
+ no_speech_prob: z5.number()
969
939
  })
970
940
  ).nullish()
971
941
  });
972
942
 
973
943
  // src/tool/browser-search.ts
974
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
975
- var import_v46 = require("zod/v4");
976
- var browserSearch = (0, import_provider_utils6.createProviderToolFactory)({
944
+ import {
945
+ createProviderExecutedToolFactory,
946
+ lazySchema as lazySchema2,
947
+ zodSchema as zodSchema2
948
+ } from "@ai-sdk/provider-utils";
949
+ import { z as z6 } from "zod/v4";
950
+ var browserSearch = createProviderExecutedToolFactory({
977
951
  id: "groq.browser_search",
978
- inputSchema: import_v46.z.object({})
952
+ inputSchema: lazySchema2(() => zodSchema2(z6.object({}))),
953
+ outputSchema: lazySchema2(() => zodSchema2(z6.object({})))
979
954
  });
980
955
 
981
956
  // src/groq-tools.ts
@@ -984,15 +959,15 @@ var groqTools = {
984
959
  };
985
960
 
986
961
  // src/version.ts
987
- var VERSION = true ? "4.0.0-beta.4" : "0.0.0-test";
962
+ var VERSION = true ? "4.0.0-beta.54" : "0.0.0-test";
988
963
 
989
964
  // src/groq-provider.ts
990
965
  function createGroq(options = {}) {
991
966
  var _a;
992
- const baseURL = (_a = (0, import_provider_utils7.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
993
- const getHeaders = () => (0, import_provider_utils7.withUserAgentSuffix)(
967
+ const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
968
+ const getHeaders = () => withUserAgentSuffix(
994
969
  {
995
- Authorization: `Bearer ${(0, import_provider_utils7.loadApiKey)({
970
+ Authorization: `Bearer ${loadApiKey({
996
971
  apiKey: options.apiKey,
997
972
  environmentVariableName: "GROQ_API_KEY",
998
973
  description: "Groq"
@@ -1026,15 +1001,15 @@ function createGroq(options = {}) {
1026
1001
  const provider = function(modelId) {
1027
1002
  return createLanguageModel(modelId);
1028
1003
  };
1029
- provider.specificationVersion = "v3";
1004
+ provider.specificationVersion = "v4";
1030
1005
  provider.languageModel = createLanguageModel;
1031
1006
  provider.chat = createChatModel;
1032
1007
  provider.embeddingModel = (modelId) => {
1033
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "embeddingModel" });
1008
+ throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
1034
1009
  };
1035
1010
  provider.textEmbeddingModel = provider.embeddingModel;
1036
1011
  provider.imageModel = (modelId) => {
1037
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
1012
+ throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1038
1013
  };
1039
1014
  provider.transcription = createTranscriptionModel;
1040
1015
  provider.transcriptionModel = createTranscriptionModel;
@@ -1042,11 +1017,10 @@ function createGroq(options = {}) {
1042
1017
  return provider;
1043
1018
  }
1044
1019
  var groq = createGroq();
1045
- // Annotate the CommonJS export names for ESM import in node:
1046
- 0 && (module.exports = {
1020
+ export {
1047
1021
  VERSION,
1048
1022
  browserSearch,
1049
1023
  createGroq,
1050
1024
  groq
1051
- });
1025
+ };
1052
1026
  //# sourceMappingURL=index.js.map