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

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
  }
@@ -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,25 @@ 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
+ const toolCallTracker = new StreamingToolCallTracker({
558
+ generateId,
559
+ typeValidation: "required"
560
+ });
545
561
  let finishReason = {
546
562
  unified: "other",
547
563
  raw: void 0
@@ -558,7 +574,7 @@ var GroqChatLanguageModel = class {
558
574
  controller.enqueue({ type: "stream-start", warnings });
559
575
  },
560
576
  transform(chunk, controller) {
561
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
577
+ var _a2;
562
578
  if (options.includeRawChunks) {
563
579
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
564
580
  }
@@ -586,7 +602,7 @@ var GroqChatLanguageModel = class {
586
602
  ...getResponseMetadata(value)
587
603
  });
588
604
  }
589
- if (((_a = value.x_groq) == null ? void 0 : _a.usage) != null) {
605
+ if (((_a2 = value.x_groq) == null ? void 0 : _a2.usage) != null) {
590
606
  usage = value.x_groq.usage;
591
607
  }
592
608
  const choice = value.choices[0];
@@ -641,90 +657,10 @@ var GroqChatLanguageModel = class {
641
657
  isActiveReasoning = false;
642
658
  }
643
659
  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
- }
660
+ toolCallTracker.processDelta(
661
+ toolCallDelta,
662
+ controller.enqueue.bind(controller)
663
+ );
728
664
  }
729
665
  }
730
666
  },
@@ -735,6 +671,7 @@ var GroqChatLanguageModel = class {
735
671
  if (isActiveText) {
736
672
  controller.enqueue({ type: "text-end", id: "txt-0" });
737
673
  }
674
+ toolCallTracker.flush(controller.enqueue.bind(controller));
738
675
  controller.enqueue({
739
676
  type: "finish",
740
677
  finishReason,
@@ -744,83 +681,83 @@ var GroqChatLanguageModel = class {
744
681
  }
745
682
  })
746
683
  ),
747
- request: { body },
684
+ request: { body: JSON.stringify(body) },
748
685
  response: { headers: responseHeaders }
749
686
  };
750
687
  }
751
688
  };
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()
689
+ var groqChatResponseSchema = z3.object({
690
+ id: z3.string().nullish(),
691
+ created: z3.number().nullish(),
692
+ model: z3.string().nullish(),
693
+ choices: z3.array(
694
+ z3.object({
695
+ message: z3.object({
696
+ content: z3.string().nullish(),
697
+ reasoning: z3.string().nullish(),
698
+ tool_calls: z3.array(
699
+ z3.object({
700
+ id: z3.string().nullish(),
701
+ type: z3.literal("function"),
702
+ function: z3.object({
703
+ name: z3.string(),
704
+ arguments: z3.string()
768
705
  })
769
706
  })
770
707
  ).nullish()
771
708
  }),
772
- index: import_v43.z.number(),
773
- finish_reason: import_v43.z.string().nullish()
709
+ index: z3.number(),
710
+ finish_reason: z3.string().nullish()
774
711
  })
775
712
  ),
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()
713
+ usage: z3.object({
714
+ prompt_tokens: z3.number().nullish(),
715
+ completion_tokens: z3.number().nullish(),
716
+ total_tokens: z3.number().nullish(),
717
+ prompt_tokens_details: z3.object({
718
+ cached_tokens: z3.number().nullish()
782
719
  }).nullish(),
783
- completion_tokens_details: import_v43.z.object({
784
- reasoning_tokens: import_v43.z.number().nullish()
720
+ completion_tokens_details: z3.object({
721
+ reasoning_tokens: z3.number().nullish()
785
722
  }).nullish()
786
723
  }).nullish()
787
724
  });
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()
725
+ var groqChatChunkSchema = z3.union([
726
+ z3.object({
727
+ id: z3.string().nullish(),
728
+ created: z3.number().nullish(),
729
+ model: z3.string().nullish(),
730
+ choices: z3.array(
731
+ z3.object({
732
+ delta: z3.object({
733
+ content: z3.string().nullish(),
734
+ reasoning: z3.string().nullish(),
735
+ tool_calls: z3.array(
736
+ z3.object({
737
+ index: z3.number(),
738
+ id: z3.string().nullish(),
739
+ type: z3.literal("function").optional(),
740
+ function: z3.object({
741
+ name: z3.string().nullish(),
742
+ arguments: z3.string().nullish()
806
743
  })
807
744
  })
808
745
  ).nullish()
809
746
  }).nullish(),
810
- finish_reason: import_v43.z.string().nullable().optional(),
811
- index: import_v43.z.number()
747
+ finish_reason: z3.string().nullable().optional(),
748
+ index: z3.number()
812
749
  })
813
750
  ),
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()
751
+ x_groq: z3.object({
752
+ usage: z3.object({
753
+ prompt_tokens: z3.number().nullish(),
754
+ completion_tokens: z3.number().nullish(),
755
+ total_tokens: z3.number().nullish(),
756
+ prompt_tokens_details: z3.object({
757
+ cached_tokens: z3.number().nullish()
821
758
  }).nullish(),
822
- completion_tokens_details: import_v43.z.object({
823
- reasoning_tokens: import_v43.z.number().nullish()
759
+ completion_tokens_details: z3.object({
760
+ reasoning_tokens: z3.number().nullish()
824
761
  }).nullish()
825
762
  }).nullish()
826
763
  }).nullish()
@@ -829,34 +766,53 @@ var groqChatChunkSchema = import_v43.z.union([
829
766
  ]);
830
767
 
831
768
  // src/groq-transcription-model.ts
832
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
833
- var import_v45 = require("zod/v4");
769
+ import {
770
+ combineHeaders as combineHeaders2,
771
+ convertBase64ToUint8Array,
772
+ createJsonResponseHandler as createJsonResponseHandler2,
773
+ mediaTypeToExtension,
774
+ parseProviderOptions as parseProviderOptions2,
775
+ postFormDataToApi,
776
+ serializeModelOptions as serializeModelOptions2,
777
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
778
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
779
+ } from "@ai-sdk/provider-utils";
780
+ import { z as z5 } from "zod/v4";
834
781
 
835
782
  // 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()
783
+ import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
784
+ import { z as z4 } from "zod/v4";
785
+ var groqTranscriptionModelOptions = lazySchema(
786
+ () => zodSchema(
787
+ z4.object({
788
+ language: z4.string().nullish(),
789
+ prompt: z4.string().nullish(),
790
+ responseFormat: z4.string().nullish(),
791
+ temperature: z4.number().min(0).max(1).nullish(),
792
+ timestampGranularities: z4.array(z4.string()).nullish()
846
793
  })
847
794
  )
848
795
  );
849
796
 
850
797
  // src/groq-transcription-model.ts
851
- var GroqTranscriptionModel = class {
798
+ var GroqTranscriptionModel = class _GroqTranscriptionModel {
852
799
  constructor(modelId, config) {
853
800
  this.modelId = modelId;
854
801
  this.config = config;
855
- this.specificationVersion = "v3";
802
+ this.specificationVersion = "v4";
856
803
  }
857
804
  get provider() {
858
805
  return this.config.provider;
859
806
  }
807
+ static [WORKFLOW_SERIALIZE2](model) {
808
+ return serializeModelOptions2({
809
+ modelId: model.modelId,
810
+ config: model.config
811
+ });
812
+ }
813
+ static [WORKFLOW_DESERIALIZE2](options) {
814
+ return new _GroqTranscriptionModel(options.modelId, options.config);
815
+ }
860
816
  async getArgs({
861
817
  audio,
862
818
  mediaType,
@@ -864,15 +820,15 @@ var GroqTranscriptionModel = class {
864
820
  }) {
865
821
  var _a, _b, _c, _d, _e;
866
822
  const warnings = [];
867
- const groqOptions = await (0, import_provider_utils5.parseProviderOptions)({
823
+ const groqOptions = await parseProviderOptions2({
868
824
  provider: "groq",
869
825
  providerOptions,
870
826
  schema: groqTranscriptionModelOptions
871
827
  });
872
828
  const formData = new FormData();
873
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils5.convertBase64ToUint8Array)(audio)]);
829
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
874
830
  formData.append("model", this.modelId);
875
- const fileExtension = (0, import_provider_utils5.mediaTypeToExtension)(mediaType);
831
+ const fileExtension = mediaTypeToExtension(mediaType);
876
832
  formData.append(
877
833
  "file",
878
834
  new File([blob], "audio", { type: mediaType }),
@@ -905,22 +861,22 @@ var GroqTranscriptionModel = class {
905
861
  };
906
862
  }
907
863
  async doGenerate(options) {
908
- var _a, _b, _c, _d, _e, _f, _g;
864
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
909
865
  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
866
  const { formData, warnings } = await this.getArgs(options);
911
867
  const {
912
868
  value: response,
913
869
  responseHeaders,
914
870
  rawValue: rawResponse
915
- } = await (0, import_provider_utils5.postFormDataToApi)({
871
+ } = await postFormDataToApi({
916
872
  url: this.config.url({
917
873
  path: "/audio/transcriptions",
918
874
  modelId: this.modelId
919
875
  }),
920
- headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
876
+ headers: combineHeaders2((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
921
877
  formData,
922
878
  failedResponseHandler: groqFailedResponseHandler,
923
- successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
879
+ successfulResponseHandler: createJsonResponseHandler2(
924
880
  groqTranscriptionResponseSchema
925
881
  ),
926
882
  abortSignal: options.abortSignal,
@@ -928,13 +884,13 @@ var GroqTranscriptionModel = class {
928
884
  });
929
885
  return {
930
886
  text: response.text,
931
- segments: (_e = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
887
+ segments: (_g = (_f = response.segments) == null ? void 0 : _f.map((segment) => ({
932
888
  text: segment.text,
933
889
  startSecond: segment.start,
934
890
  endSecond: segment.end
935
- }))) != null ? _e : [],
936
- language: (_f = response.language) != null ? _f : void 0,
937
- durationInSeconds: (_g = response.duration) != null ? _g : void 0,
891
+ }))) != null ? _g : [],
892
+ language: (_h = response.language) != null ? _h : void 0,
893
+ durationInSeconds: (_i = response.duration) != null ? _i : void 0,
938
894
  warnings,
939
895
  response: {
940
896
  timestamp: currentDate,
@@ -945,37 +901,37 @@ var GroqTranscriptionModel = class {
945
901
  };
946
902
  }
947
903
  };
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()
904
+ var groqTranscriptionResponseSchema = z5.object({
905
+ text: z5.string(),
906
+ x_groq: z5.object({
907
+ id: z5.string()
952
908
  }),
953
909
  // 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()
910
+ task: z5.string().nullish(),
911
+ language: z5.string().nullish(),
912
+ duration: z5.number().nullish(),
913
+ segments: z5.array(
914
+ z5.object({
915
+ id: z5.number(),
916
+ seek: z5.number(),
917
+ start: z5.number(),
918
+ end: z5.number(),
919
+ text: z5.string(),
920
+ tokens: z5.array(z5.number()),
921
+ temperature: z5.number(),
922
+ avg_logprob: z5.number(),
923
+ compression_ratio: z5.number(),
924
+ no_speech_prob: z5.number()
969
925
  })
970
926
  ).nullish()
971
927
  });
972
928
 
973
929
  // 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)({
930
+ import { createProviderToolFactory } from "@ai-sdk/provider-utils";
931
+ import { z as z6 } from "zod/v4";
932
+ var browserSearch = createProviderToolFactory({
977
933
  id: "groq.browser_search",
978
- inputSchema: import_v46.z.object({})
934
+ inputSchema: z6.object({})
979
935
  });
980
936
 
981
937
  // src/groq-tools.ts
@@ -984,15 +940,15 @@ var groqTools = {
984
940
  };
985
941
 
986
942
  // src/version.ts
987
- var VERSION = true ? "4.0.0-beta.3" : "0.0.0-test";
943
+ var VERSION = true ? "4.0.0-beta.30" : "0.0.0-test";
988
944
 
989
945
  // src/groq-provider.ts
990
946
  function createGroq(options = {}) {
991
947
  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)(
948
+ const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
949
+ const getHeaders = () => withUserAgentSuffix(
994
950
  {
995
- Authorization: `Bearer ${(0, import_provider_utils7.loadApiKey)({
951
+ Authorization: `Bearer ${loadApiKey({
996
952
  apiKey: options.apiKey,
997
953
  environmentVariableName: "GROQ_API_KEY",
998
954
  description: "Groq"
@@ -1026,15 +982,15 @@ function createGroq(options = {}) {
1026
982
  const provider = function(modelId) {
1027
983
  return createLanguageModel(modelId);
1028
984
  };
1029
- provider.specificationVersion = "v3";
985
+ provider.specificationVersion = "v4";
1030
986
  provider.languageModel = createLanguageModel;
1031
987
  provider.chat = createChatModel;
1032
988
  provider.embeddingModel = (modelId) => {
1033
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "embeddingModel" });
989
+ throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
1034
990
  };
1035
991
  provider.textEmbeddingModel = provider.embeddingModel;
1036
992
  provider.imageModel = (modelId) => {
1037
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
993
+ throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1038
994
  };
1039
995
  provider.transcription = createTranscriptionModel;
1040
996
  provider.transcriptionModel = createTranscriptionModel;
@@ -1042,11 +998,10 @@ function createGroq(options = {}) {
1042
998
  return provider;
1043
999
  }
1044
1000
  var groq = createGroq();
1045
- // Annotate the CommonJS export names for ESM import in node:
1046
- 0 && (module.exports = {
1001
+ export {
1047
1002
  VERSION,
1048
1003
  browserSearch,
1049
1004
  createGroq,
1050
1005
  groq
1051
- });
1006
+ };
1052
1007
  //# sourceMappingURL=index.js.map