@ai-sdk/groq 4.0.0-beta.3 → 4.0.0-beta.31

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,10 @@ 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 { convertToBase64, isProviderReference } from "@ai-sdk/provider-utils";
81
72
  function convertToGroqChatMessages(prompt) {
82
73
  var _a;
83
74
  const messages = [];
@@ -100,8 +91,13 @@ function convertToGroqChatMessages(prompt) {
100
91
  return { type: "text", text: part.text };
101
92
  }
102
93
  case "file": {
94
+ if (isProviderReference(part.data)) {
95
+ throw new UnsupportedFunctionalityError({
96
+ functionality: "file parts with provider references"
97
+ });
98
+ }
103
99
  if (!part.mediaType.startsWith("image/")) {
104
- throw new import_provider.UnsupportedFunctionalityError({
100
+ throw new UnsupportedFunctionalityError({
105
101
  functionality: "Non-image file content parts"
106
102
  });
107
103
  }
@@ -109,7 +105,7 @@ function convertToGroqChatMessages(prompt) {
109
105
  return {
110
106
  type: "image_url",
111
107
  image_url: {
112
- url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`
108
+ url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
113
109
  }
114
110
  };
115
111
  }
@@ -168,7 +164,7 @@ function convertToGroqChatMessages(prompt) {
168
164
  contentValue = output.value;
169
165
  break;
170
166
  case "execution-denied":
171
- contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
167
+ contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
172
168
  break;
173
169
  case "content":
174
170
  case "json":
@@ -207,29 +203,29 @@ function getResponseMetadata({
207
203
  }
208
204
 
209
205
  // 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(),
206
+ import { z } from "zod/v4";
207
+ var groqLanguageModelOptions = z.object({
208
+ reasoningFormat: z.enum(["parsed", "raw", "hidden"]).optional(),
213
209
  /**
214
210
  * Specifies the reasoning effort level for model inference.
215
211
  * @see https://console.groq.com/docs/reasoning#reasoning-effort
216
212
  */
217
- reasoningEffort: import_v4.z.enum(["none", "default", "low", "medium", "high"]).optional(),
213
+ reasoningEffort: z.enum(["none", "default", "low", "medium", "high"]).optional(),
218
214
  /**
219
215
  * Whether to enable parallel function calling during tool use. Default to true.
220
216
  */
221
- parallelToolCalls: import_v4.z.boolean().optional(),
217
+ parallelToolCalls: z.boolean().optional(),
222
218
  /**
223
219
  * A unique identifier representing your end-user, which can help OpenAI to
224
220
  * monitor and detect abuse. Learn more.
225
221
  */
226
- user: import_v4.z.string().optional(),
222
+ user: z.string().optional(),
227
223
  /**
228
224
  * Whether to use structured outputs.
229
225
  *
230
226
  * @default true
231
227
  */
232
- structuredOutputs: import_v4.z.boolean().optional(),
228
+ structuredOutputs: z.boolean().optional(),
233
229
  /**
234
230
  * Whether to use strict JSON schema validation.
235
231
  * When true, the model uses constrained decoding to guarantee schema compliance.
@@ -237,34 +233,37 @@ var groqLanguageModelOptions = import_v4.z.object({
237
233
  *
238
234
  * @default true
239
235
  */
240
- strictJsonSchema: import_v4.z.boolean().optional(),
236
+ strictJsonSchema: z.boolean().optional(),
241
237
  /**
242
238
  * Service tier for the request.
243
239
  * - 'on_demand': Default tier with consistent performance and fairness
240
+ * - 'performance': Prioritized tier for latency-sensitive workloads
244
241
  * - 'flex': Higher throughput tier optimized for workloads that can handle occasional request failures
245
242
  * - 'auto': Uses on_demand rate limits, then falls back to flex tier if exceeded
246
243
  *
247
244
  * @default 'on_demand'
248
245
  */
249
- serviceTier: import_v4.z.enum(["on_demand", "flex", "auto"]).optional()
246
+ serviceTier: z.enum(["on_demand", "performance", "flex", "auto"]).optional()
250
247
  });
251
248
 
252
249
  // 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()
250
+ import { z as z2 } from "zod/v4";
251
+ import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
252
+ var groqErrorDataSchema = z2.object({
253
+ error: z2.object({
254
+ message: z2.string(),
255
+ type: z2.string()
259
256
  })
260
257
  });
261
- var groqFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
258
+ var groqFailedResponseHandler = createJsonErrorResponseHandler({
262
259
  errorSchema: groqErrorDataSchema,
263
260
  errorToMessage: (data) => data.error.message
264
261
  });
265
262
 
266
263
  // src/groq-prepare-tools.ts
267
- var import_provider2 = require("@ai-sdk/provider");
264
+ import {
265
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError2
266
+ } from "@ai-sdk/provider";
268
267
 
269
268
  // src/groq-browser-search-models.ts
270
269
  var BROWSER_SEARCH_SUPPORTED_MODELS = [
@@ -344,7 +343,7 @@ function prepareTools({
344
343
  };
345
344
  default: {
346
345
  const _exhaustiveCheck = type;
347
- throw new import_provider2.UnsupportedFunctionalityError({
346
+ throw new UnsupportedFunctionalityError2({
348
347
  functionality: `tool choice type: ${_exhaustiveCheck}`
349
348
  });
350
349
  }
@@ -369,15 +368,24 @@ function mapGroqFinishReason(finishReason) {
369
368
  }
370
369
 
371
370
  // src/groq-chat-language-model.ts
372
- var GroqChatLanguageModel = class {
371
+ var GroqChatLanguageModel = class _GroqChatLanguageModel {
373
372
  constructor(modelId, config) {
374
- this.specificationVersion = "v3";
373
+ this.specificationVersion = "v4";
375
374
  this.supportedUrls = {
376
375
  "image/*": [/^https?:\/\/.*$/]
377
376
  };
378
377
  this.modelId = modelId;
379
378
  this.config = config;
380
379
  }
380
+ static [WORKFLOW_SERIALIZE](model) {
381
+ return serializeModelOptions({
382
+ modelId: model.modelId,
383
+ config: model.config
384
+ });
385
+ }
386
+ static [WORKFLOW_DESERIALIZE](options) {
387
+ return new _GroqChatLanguageModel(options.modelId, options.config);
388
+ }
381
389
  get provider() {
382
390
  return this.config.provider;
383
391
  }
@@ -392,14 +400,14 @@ var GroqChatLanguageModel = class {
392
400
  stopSequences,
393
401
  responseFormat,
394
402
  seed,
395
- stream,
403
+ reasoning,
396
404
  tools,
397
405
  toolChoice,
398
406
  providerOptions
399
407
  }) {
400
- var _a, _b, _c;
408
+ var _a, _b, _c, _d;
401
409
  const warnings = [];
402
- const groqOptions = await (0, import_provider_utils3.parseProviderOptions)({
410
+ const groqOptions = await parseProviderOptions({
403
411
  provider: "groq",
404
412
  providerOptions,
405
413
  schema: groqLanguageModelOptions
@@ -448,7 +456,17 @@ var GroqChatLanguageModel = class {
448
456
  } : { type: "json_object" } : void 0,
449
457
  // provider options:
450
458
  reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
451
- reasoning_effort: groqOptions == null ? void 0 : groqOptions.reasoningEffort,
459
+ reasoning_effort: (_d = groqOptions == null ? void 0 : groqOptions.reasoningEffort) != null ? _d : isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
460
+ reasoning,
461
+ effortMap: {
462
+ minimal: "low",
463
+ low: "low",
464
+ medium: "medium",
465
+ high: "high",
466
+ xhigh: "high"
467
+ },
468
+ warnings
469
+ }) : void 0,
452
470
  service_tier: groqOptions == null ? void 0 : groqOptions.serviceTier,
453
471
  // messages:
454
472
  messages: convertToGroqChatMessages(prompt),
@@ -460,25 +478,22 @@ var GroqChatLanguageModel = class {
460
478
  };
461
479
  }
462
480
  async doGenerate(options) {
463
- var _a, _b;
464
- const { args, warnings } = await this.getArgs({
465
- ...options,
466
- stream: false
467
- });
481
+ var _a, _b, _c, _d;
482
+ const { args, warnings } = await this.getArgs(options);
468
483
  const body = JSON.stringify(args);
469
484
  const {
470
485
  responseHeaders,
471
486
  value: response,
472
487
  rawValue: rawResponse
473
- } = await (0, import_provider_utils3.postJsonToApi)({
488
+ } = await postJsonToApi({
474
489
  url: this.config.url({
475
490
  path: "/chat/completions",
476
491
  modelId: this.modelId
477
492
  }),
478
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
493
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
479
494
  body: args,
480
495
  failedResponseHandler: groqFailedResponseHandler,
481
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
496
+ successfulResponseHandler: createJsonResponseHandler(
482
497
  groqChatResponseSchema
483
498
  ),
484
499
  abortSignal: options.abortSignal,
@@ -501,7 +516,7 @@ var GroqChatLanguageModel = class {
501
516
  for (const toolCall of choice.message.tool_calls) {
502
517
  content.push({
503
518
  type: "tool-call",
504
- toolCallId: (_a = toolCall.id) != null ? _a : (0, import_provider_utils3.generateId)(),
519
+ toolCallId: (_c = toolCall.id) != null ? _c : generateId(),
505
520
  toolName: toolCall.function.name,
506
521
  input: toolCall.function.arguments
507
522
  });
@@ -511,7 +526,7 @@ var GroqChatLanguageModel = class {
511
526
  content,
512
527
  finishReason: {
513
528
  unified: mapGroqFinishReason(choice.finish_reason),
514
- raw: (_b = choice.finish_reason) != null ? _b : void 0
529
+ raw: (_d = choice.finish_reason) != null ? _d : void 0
515
530
  },
516
531
  usage: convertGroqUsage(response.usage),
517
532
  response: {
@@ -524,24 +539,22 @@ var GroqChatLanguageModel = class {
524
539
  };
525
540
  }
526
541
  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)({
542
+ var _a, _b;
543
+ const { args, warnings } = await this.getArgs(options);
544
+ const body = { ...args, stream: true };
545
+ const { responseHeaders, value: response } = await postJsonToApi({
530
546
  url: this.config.url({
531
547
  path: "/chat/completions",
532
548
  modelId: this.modelId
533
549
  }),
534
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
535
- body: {
536
- ...args,
537
- stream: true
538
- },
550
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
551
+ body,
539
552
  failedResponseHandler: groqFailedResponseHandler,
540
- successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(groqChatChunkSchema),
553
+ successfulResponseHandler: createEventSourceResponseHandler(groqChatChunkSchema),
541
554
  abortSignal: options.abortSignal,
542
555
  fetch: this.config.fetch
543
556
  });
544
- const toolCalls = [];
557
+ let toolCallTracker;
545
558
  let finishReason = {
546
559
  unified: "other",
547
560
  raw: void 0
@@ -555,10 +568,14 @@ var GroqChatLanguageModel = class {
555
568
  stream: response.pipeThrough(
556
569
  new TransformStream({
557
570
  start(controller) {
571
+ toolCallTracker = new StreamingToolCallTracker(controller, {
572
+ generateId,
573
+ typeValidation: "required"
574
+ });
558
575
  controller.enqueue({ type: "stream-start", warnings });
559
576
  },
560
577
  transform(chunk, controller) {
561
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
578
+ var _a2;
562
579
  if (options.includeRawChunks) {
563
580
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
564
581
  }
@@ -586,7 +603,7 @@ var GroqChatLanguageModel = class {
586
603
  ...getResponseMetadata(value)
587
604
  });
588
605
  }
589
- if (((_a = value.x_groq) == null ? void 0 : _a.usage) != null) {
606
+ if (((_a2 = value.x_groq) == null ? void 0 : _a2.usage) != null) {
590
607
  usage = value.x_groq.usage;
591
608
  }
592
609
  const choice = value.choices[0];
@@ -641,90 +658,7 @@ var GroqChatLanguageModel = class {
641
658
  isActiveReasoning = false;
642
659
  }
643
660
  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
- }
661
+ toolCallTracker.processDelta(toolCallDelta);
728
662
  }
729
663
  }
730
664
  },
@@ -735,6 +669,7 @@ var GroqChatLanguageModel = class {
735
669
  if (isActiveText) {
736
670
  controller.enqueue({ type: "text-end", id: "txt-0" });
737
671
  }
672
+ toolCallTracker.flush();
738
673
  controller.enqueue({
739
674
  type: "finish",
740
675
  finishReason,
@@ -744,83 +679,83 @@ var GroqChatLanguageModel = class {
744
679
  }
745
680
  })
746
681
  ),
747
- request: { body },
682
+ request: { body: JSON.stringify(body) },
748
683
  response: { headers: responseHeaders }
749
684
  };
750
685
  }
751
686
  };
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()
687
+ var groqChatResponseSchema = z3.object({
688
+ id: z3.string().nullish(),
689
+ created: z3.number().nullish(),
690
+ model: z3.string().nullish(),
691
+ choices: z3.array(
692
+ z3.object({
693
+ message: z3.object({
694
+ content: z3.string().nullish(),
695
+ reasoning: z3.string().nullish(),
696
+ tool_calls: z3.array(
697
+ z3.object({
698
+ id: z3.string().nullish(),
699
+ type: z3.literal("function"),
700
+ function: z3.object({
701
+ name: z3.string(),
702
+ arguments: z3.string()
768
703
  })
769
704
  })
770
705
  ).nullish()
771
706
  }),
772
- index: import_v43.z.number(),
773
- finish_reason: import_v43.z.string().nullish()
707
+ index: z3.number(),
708
+ finish_reason: z3.string().nullish()
774
709
  })
775
710
  ),
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()
711
+ usage: z3.object({
712
+ prompt_tokens: z3.number().nullish(),
713
+ completion_tokens: z3.number().nullish(),
714
+ total_tokens: z3.number().nullish(),
715
+ prompt_tokens_details: z3.object({
716
+ cached_tokens: z3.number().nullish()
782
717
  }).nullish(),
783
- completion_tokens_details: import_v43.z.object({
784
- reasoning_tokens: import_v43.z.number().nullish()
718
+ completion_tokens_details: z3.object({
719
+ reasoning_tokens: z3.number().nullish()
785
720
  }).nullish()
786
721
  }).nullish()
787
722
  });
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()
723
+ var groqChatChunkSchema = z3.union([
724
+ z3.object({
725
+ id: z3.string().nullish(),
726
+ created: z3.number().nullish(),
727
+ model: z3.string().nullish(),
728
+ choices: z3.array(
729
+ z3.object({
730
+ delta: z3.object({
731
+ content: z3.string().nullish(),
732
+ reasoning: z3.string().nullish(),
733
+ tool_calls: z3.array(
734
+ z3.object({
735
+ index: z3.number(),
736
+ id: z3.string().nullish(),
737
+ type: z3.literal("function").optional(),
738
+ function: z3.object({
739
+ name: z3.string().nullish(),
740
+ arguments: z3.string().nullish()
806
741
  })
807
742
  })
808
743
  ).nullish()
809
744
  }).nullish(),
810
- finish_reason: import_v43.z.string().nullable().optional(),
811
- index: import_v43.z.number()
745
+ finish_reason: z3.string().nullable().optional(),
746
+ index: z3.number()
812
747
  })
813
748
  ),
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()
749
+ x_groq: z3.object({
750
+ usage: z3.object({
751
+ prompt_tokens: z3.number().nullish(),
752
+ completion_tokens: z3.number().nullish(),
753
+ total_tokens: z3.number().nullish(),
754
+ prompt_tokens_details: z3.object({
755
+ cached_tokens: z3.number().nullish()
821
756
  }).nullish(),
822
- completion_tokens_details: import_v43.z.object({
823
- reasoning_tokens: import_v43.z.number().nullish()
757
+ completion_tokens_details: z3.object({
758
+ reasoning_tokens: z3.number().nullish()
824
759
  }).nullish()
825
760
  }).nullish()
826
761
  }).nullish()
@@ -829,34 +764,53 @@ var groqChatChunkSchema = import_v43.z.union([
829
764
  ]);
830
765
 
831
766
  // src/groq-transcription-model.ts
832
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
833
- var import_v45 = require("zod/v4");
767
+ import {
768
+ combineHeaders as combineHeaders2,
769
+ convertBase64ToUint8Array,
770
+ createJsonResponseHandler as createJsonResponseHandler2,
771
+ mediaTypeToExtension,
772
+ parseProviderOptions as parseProviderOptions2,
773
+ postFormDataToApi,
774
+ serializeModelOptions as serializeModelOptions2,
775
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
776
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
777
+ } from "@ai-sdk/provider-utils";
778
+ import { z as z5 } from "zod/v4";
834
779
 
835
780
  // 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()
781
+ import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
782
+ import { z as z4 } from "zod/v4";
783
+ var groqTranscriptionModelOptions = lazySchema(
784
+ () => zodSchema(
785
+ z4.object({
786
+ language: z4.string().nullish(),
787
+ prompt: z4.string().nullish(),
788
+ responseFormat: z4.string().nullish(),
789
+ temperature: z4.number().min(0).max(1).nullish(),
790
+ timestampGranularities: z4.array(z4.string()).nullish()
846
791
  })
847
792
  )
848
793
  );
849
794
 
850
795
  // src/groq-transcription-model.ts
851
- var GroqTranscriptionModel = class {
796
+ var GroqTranscriptionModel = class _GroqTranscriptionModel {
852
797
  constructor(modelId, config) {
853
798
  this.modelId = modelId;
854
799
  this.config = config;
855
- this.specificationVersion = "v3";
800
+ this.specificationVersion = "v4";
856
801
  }
857
802
  get provider() {
858
803
  return this.config.provider;
859
804
  }
805
+ static [WORKFLOW_SERIALIZE2](model) {
806
+ return serializeModelOptions2({
807
+ modelId: model.modelId,
808
+ config: model.config
809
+ });
810
+ }
811
+ static [WORKFLOW_DESERIALIZE2](options) {
812
+ return new _GroqTranscriptionModel(options.modelId, options.config);
813
+ }
860
814
  async getArgs({
861
815
  audio,
862
816
  mediaType,
@@ -864,15 +818,15 @@ var GroqTranscriptionModel = class {
864
818
  }) {
865
819
  var _a, _b, _c, _d, _e;
866
820
  const warnings = [];
867
- const groqOptions = await (0, import_provider_utils5.parseProviderOptions)({
821
+ const groqOptions = await parseProviderOptions2({
868
822
  provider: "groq",
869
823
  providerOptions,
870
824
  schema: groqTranscriptionModelOptions
871
825
  });
872
826
  const formData = new FormData();
873
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils5.convertBase64ToUint8Array)(audio)]);
827
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
874
828
  formData.append("model", this.modelId);
875
- const fileExtension = (0, import_provider_utils5.mediaTypeToExtension)(mediaType);
829
+ const fileExtension = mediaTypeToExtension(mediaType);
876
830
  formData.append(
877
831
  "file",
878
832
  new File([blob], "audio", { type: mediaType }),
@@ -905,22 +859,22 @@ var GroqTranscriptionModel = class {
905
859
  };
906
860
  }
907
861
  async doGenerate(options) {
908
- var _a, _b, _c, _d, _e, _f, _g;
862
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
909
863
  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
864
  const { formData, warnings } = await this.getArgs(options);
911
865
  const {
912
866
  value: response,
913
867
  responseHeaders,
914
868
  rawValue: rawResponse
915
- } = await (0, import_provider_utils5.postFormDataToApi)({
869
+ } = await postFormDataToApi({
916
870
  url: this.config.url({
917
871
  path: "/audio/transcriptions",
918
872
  modelId: this.modelId
919
873
  }),
920
- headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
874
+ headers: combineHeaders2((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
921
875
  formData,
922
876
  failedResponseHandler: groqFailedResponseHandler,
923
- successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
877
+ successfulResponseHandler: createJsonResponseHandler2(
924
878
  groqTranscriptionResponseSchema
925
879
  ),
926
880
  abortSignal: options.abortSignal,
@@ -928,13 +882,13 @@ var GroqTranscriptionModel = class {
928
882
  });
929
883
  return {
930
884
  text: response.text,
931
- segments: (_e = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
885
+ segments: (_g = (_f = response.segments) == null ? void 0 : _f.map((segment) => ({
932
886
  text: segment.text,
933
887
  startSecond: segment.start,
934
888
  endSecond: segment.end
935
- }))) != null ? _e : [],
936
- language: (_f = response.language) != null ? _f : void 0,
937
- durationInSeconds: (_g = response.duration) != null ? _g : void 0,
889
+ }))) != null ? _g : [],
890
+ language: (_h = response.language) != null ? _h : void 0,
891
+ durationInSeconds: (_i = response.duration) != null ? _i : void 0,
938
892
  warnings,
939
893
  response: {
940
894
  timestamp: currentDate,
@@ -945,37 +899,42 @@ var GroqTranscriptionModel = class {
945
899
  };
946
900
  }
947
901
  };
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()
902
+ var groqTranscriptionResponseSchema = z5.object({
903
+ text: z5.string(),
904
+ x_groq: z5.object({
905
+ id: z5.string()
952
906
  }),
953
907
  // 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()
908
+ task: z5.string().nullish(),
909
+ language: z5.string().nullish(),
910
+ duration: z5.number().nullish(),
911
+ segments: z5.array(
912
+ z5.object({
913
+ id: z5.number(),
914
+ seek: z5.number(),
915
+ start: z5.number(),
916
+ end: z5.number(),
917
+ text: z5.string(),
918
+ tokens: z5.array(z5.number()),
919
+ temperature: z5.number(),
920
+ avg_logprob: z5.number(),
921
+ compression_ratio: z5.number(),
922
+ no_speech_prob: z5.number()
969
923
  })
970
924
  ).nullish()
971
925
  });
972
926
 
973
927
  // 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)({
928
+ import {
929
+ createProviderExecutedToolFactory,
930
+ lazySchema as lazySchema2,
931
+ zodSchema as zodSchema2
932
+ } from "@ai-sdk/provider-utils";
933
+ import { z as z6 } from "zod/v4";
934
+ var browserSearch = createProviderExecutedToolFactory({
977
935
  id: "groq.browser_search",
978
- inputSchema: import_v46.z.object({})
936
+ inputSchema: lazySchema2(() => zodSchema2(z6.object({}))),
937
+ outputSchema: lazySchema2(() => zodSchema2(z6.object({})))
979
938
  });
980
939
 
981
940
  // src/groq-tools.ts
@@ -984,15 +943,15 @@ var groqTools = {
984
943
  };
985
944
 
986
945
  // src/version.ts
987
- var VERSION = true ? "4.0.0-beta.3" : "0.0.0-test";
946
+ var VERSION = true ? "4.0.0-beta.31" : "0.0.0-test";
988
947
 
989
948
  // src/groq-provider.ts
990
949
  function createGroq(options = {}) {
991
950
  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)(
951
+ const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
952
+ const getHeaders = () => withUserAgentSuffix(
994
953
  {
995
- Authorization: `Bearer ${(0, import_provider_utils7.loadApiKey)({
954
+ Authorization: `Bearer ${loadApiKey({
996
955
  apiKey: options.apiKey,
997
956
  environmentVariableName: "GROQ_API_KEY",
998
957
  description: "Groq"
@@ -1026,15 +985,15 @@ function createGroq(options = {}) {
1026
985
  const provider = function(modelId) {
1027
986
  return createLanguageModel(modelId);
1028
987
  };
1029
- provider.specificationVersion = "v3";
988
+ provider.specificationVersion = "v4";
1030
989
  provider.languageModel = createLanguageModel;
1031
990
  provider.chat = createChatModel;
1032
991
  provider.embeddingModel = (modelId) => {
1033
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "embeddingModel" });
992
+ throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
1034
993
  };
1035
994
  provider.textEmbeddingModel = provider.embeddingModel;
1036
995
  provider.imageModel = (modelId) => {
1037
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
996
+ throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1038
997
  };
1039
998
  provider.transcription = createTranscriptionModel;
1040
999
  provider.transcriptionModel = createTranscriptionModel;
@@ -1042,11 +1001,10 @@ function createGroq(options = {}) {
1042
1001
  return provider;
1043
1002
  }
1044
1003
  var groq = createGroq();
1045
- // Annotate the CommonJS export names for ESM import in node:
1046
- 0 && (module.exports = {
1004
+ export {
1047
1005
  VERSION,
1048
1006
  browserSearch,
1049
1007
  createGroq,
1050
1008
  groq
1051
- });
1009
+ };
1052
1010
  //# sourceMappingURL=index.js.map