@ai-sdk/groq 2.0.0-alpha.9 → 2.0.0-beta.10

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
@@ -32,7 +32,7 @@ var import_provider_utils4 = require("@ai-sdk/provider-utils");
32
32
  // src/groq-chat-language-model.ts
33
33
  var import_provider3 = require("@ai-sdk/provider");
34
34
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
35
- var import_zod3 = require("zod");
35
+ var import_v43 = require("zod/v4");
36
36
 
37
37
  // src/convert-to-groq-chat-messages.ts
38
38
  var import_provider = require("@ai-sdk/provider");
@@ -90,7 +90,7 @@ function convertToGroqChatMessages(prompt) {
90
90
  type: "function",
91
91
  function: {
92
92
  name: part.toolName,
93
- arguments: JSON.stringify(part.args)
93
+ arguments: JSON.stringify(part.input)
94
94
  }
95
95
  });
96
96
  break;
@@ -106,10 +106,23 @@ function convertToGroqChatMessages(prompt) {
106
106
  }
107
107
  case "tool": {
108
108
  for (const toolResponse of content) {
109
+ const output = toolResponse.output;
110
+ let contentValue;
111
+ switch (output.type) {
112
+ case "text":
113
+ case "error-text":
114
+ contentValue = output.value;
115
+ break;
116
+ case "content":
117
+ case "json":
118
+ case "error-json":
119
+ contentValue = JSON.stringify(output.value);
120
+ break;
121
+ }
109
122
  messages.push({
110
123
  role: "tool",
111
124
  tool_call_id: toolResponse.toolCallId,
112
- content: JSON.stringify(toolResponse.result)
125
+ content: contentValue
113
126
  });
114
127
  }
115
128
  break;
@@ -137,27 +150,33 @@ function getResponseMetadata({
137
150
  }
138
151
 
139
152
  // src/groq-chat-options.ts
140
- var import_zod = require("zod");
141
- var groqProviderOptions = import_zod.z.object({
142
- reasoningFormat: import_zod.z.enum(["parsed", "raw", "hidden"]).optional(),
153
+ var import_v4 = require("zod/v4");
154
+ var groqProviderOptions = import_v4.z.object({
155
+ reasoningFormat: import_v4.z.enum(["parsed", "raw", "hidden"]).optional(),
143
156
  /**
144
157
  * Whether to enable parallel function calling during tool use. Default to true.
145
158
  */
146
- parallelToolCalls: import_zod.z.boolean().optional(),
159
+ parallelToolCalls: import_v4.z.boolean().optional(),
147
160
  /**
148
161
  * A unique identifier representing your end-user, which can help OpenAI to
149
162
  * monitor and detect abuse. Learn more.
150
163
  */
151
- user: import_zod.z.string().optional()
164
+ user: import_v4.z.string().optional(),
165
+ /**
166
+ * Whether to use structured outputs.
167
+ *
168
+ * @default true
169
+ */
170
+ structuredOutputs: import_v4.z.boolean().optional()
152
171
  });
153
172
 
154
173
  // src/groq-error.ts
155
- var import_zod2 = require("zod");
174
+ var import_v42 = require("zod/v4");
156
175
  var import_provider_utils = require("@ai-sdk/provider-utils");
157
- var groqErrorDataSchema = import_zod2.z.object({
158
- error: import_zod2.z.object({
159
- message: import_zod2.z.string(),
160
- type: import_zod2.z.string()
176
+ var groqErrorDataSchema = import_v42.z.object({
177
+ error: import_v42.z.object({
178
+ message: import_v42.z.string(),
179
+ type: import_v42.z.string()
161
180
  })
162
181
  });
163
182
  var groqFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
@@ -186,7 +205,7 @@ function prepareTools({
186
205
  function: {
187
206
  name: tool.name,
188
207
  description: tool.description,
189
- parameters: tool.parameters
208
+ parameters: tool.inputSchema
190
209
  }
191
210
  });
192
211
  }
@@ -266,25 +285,27 @@ var GroqChatLanguageModel = class {
266
285
  toolChoice,
267
286
  providerOptions
268
287
  }) {
288
+ var _a, _b;
269
289
  const warnings = [];
290
+ const groqOptions = await (0, import_provider_utils2.parseProviderOptions)({
291
+ provider: "groq",
292
+ providerOptions,
293
+ schema: groqProviderOptions
294
+ });
295
+ const structuredOutputs = (_a = groqOptions == null ? void 0 : groqOptions.structuredOutputs) != null ? _a : true;
270
296
  if (topK != null) {
271
297
  warnings.push({
272
298
  type: "unsupported-setting",
273
299
  setting: "topK"
274
300
  });
275
301
  }
276
- if (responseFormat != null && responseFormat.type === "json" && responseFormat.schema != null) {
302
+ if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !structuredOutputs) {
277
303
  warnings.push({
278
304
  type: "unsupported-setting",
279
305
  setting: "responseFormat",
280
- details: "JSON response format schema is not supported"
306
+ details: "JSON response format schema is only supported with structuredOutputs"
281
307
  });
282
308
  }
283
- const groqOptions = await (0, import_provider_utils2.parseProviderOptions)({
284
- provider: "groq",
285
- providerOptions,
286
- schema: groqProviderOptions
287
- });
288
309
  const {
289
310
  tools: groqTools,
290
311
  toolChoice: groqToolChoice,
@@ -306,10 +327,14 @@ var GroqChatLanguageModel = class {
306
327
  stop: stopSequences,
307
328
  seed,
308
329
  // response format:
309
- response_format: (
310
- // json object response format is not supported for streaming:
311
- stream === false && (responseFormat == null ? void 0 : responseFormat.type) === "json" ? { type: "json_object" } : void 0
312
- ),
330
+ response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && responseFormat.schema != null ? {
331
+ type: "json_schema",
332
+ json_schema: {
333
+ schema: responseFormat.schema,
334
+ name: (_b = responseFormat.name) != null ? _b : "response",
335
+ description: responseFormat.description
336
+ }
337
+ } : { type: "json_object" } : void 0,
313
338
  // provider options:
314
339
  reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
315
340
  // messages:
@@ -363,10 +388,9 @@ var GroqChatLanguageModel = class {
363
388
  for (const toolCall of choice.message.tool_calls) {
364
389
  content.push({
365
390
  type: "tool-call",
366
- toolCallType: "function",
367
391
  toolCallId: (_a = toolCall.id) != null ? _a : (0, import_provider_utils2.generateId)(),
368
392
  toolName: toolCall.function.name,
369
- args: toolCall.function.arguments
393
+ input: toolCall.function.arguments
370
394
  });
371
395
  }
372
396
  }
@@ -413,6 +437,8 @@ var GroqChatLanguageModel = class {
413
437
  totalTokens: void 0
414
438
  };
415
439
  let isFirstChunk = true;
440
+ let isActiveText = false;
441
+ let isActiveReasoning = false;
416
442
  let providerMetadata;
417
443
  return {
418
444
  stream: response.pipeThrough(
@@ -422,6 +448,9 @@ var GroqChatLanguageModel = class {
422
448
  },
423
449
  transform(chunk, controller) {
424
450
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
451
+ if (options.includeRawChunks) {
452
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
453
+ }
425
454
  if (!chunk.success) {
426
455
  finishReason = "error";
427
456
  controller.enqueue({ type: "error", error: chunk.error });
@@ -454,15 +483,28 @@ var GroqChatLanguageModel = class {
454
483
  }
455
484
  const delta = choice.delta;
456
485
  if (delta.reasoning != null && delta.reasoning.length > 0) {
486
+ if (!isActiveReasoning) {
487
+ controller.enqueue({
488
+ type: "reasoning-start",
489
+ id: "reasoning-0"
490
+ });
491
+ isActiveReasoning = true;
492
+ }
457
493
  controller.enqueue({
458
- type: "reasoning",
459
- text: delta.reasoning
494
+ type: "reasoning-delta",
495
+ id: "reasoning-0",
496
+ delta: delta.reasoning
460
497
  });
461
498
  }
462
499
  if (delta.content != null && delta.content.length > 0) {
500
+ if (!isActiveText) {
501
+ controller.enqueue({ type: "text-start", id: "txt-0" });
502
+ isActiveText = true;
503
+ }
463
504
  controller.enqueue({
464
- type: "text",
465
- text: delta.content
505
+ type: "text-delta",
506
+ id: "txt-0",
507
+ delta: delta.content
466
508
  });
467
509
  }
468
510
  if (delta.tool_calls != null) {
@@ -487,6 +529,11 @@ var GroqChatLanguageModel = class {
487
529
  message: `Expected 'function.name' to be a string.`
488
530
  });
489
531
  }
532
+ controller.enqueue({
533
+ type: "tool-input-start",
534
+ id: toolCallDelta.id,
535
+ toolName: toolCallDelta.function.name
536
+ });
490
537
  toolCalls[index] = {
491
538
  id: toolCallDelta.id,
492
539
  type: "function",
@@ -500,20 +547,21 @@ var GroqChatLanguageModel = class {
500
547
  if (((_g = toolCall2.function) == null ? void 0 : _g.name) != null && ((_h = toolCall2.function) == null ? void 0 : _h.arguments) != null) {
501
548
  if (toolCall2.function.arguments.length > 0) {
502
549
  controller.enqueue({
503
- type: "tool-call-delta",
504
- toolCallType: "function",
505
- toolCallId: toolCall2.id,
506
- toolName: toolCall2.function.name,
507
- argsTextDelta: toolCall2.function.arguments
550
+ type: "tool-input-delta",
551
+ id: toolCall2.id,
552
+ delta: toolCall2.function.arguments
508
553
  });
509
554
  }
510
555
  if ((0, import_provider_utils2.isParsableJson)(toolCall2.function.arguments)) {
556
+ controller.enqueue({
557
+ type: "tool-input-end",
558
+ id: toolCall2.id
559
+ });
511
560
  controller.enqueue({
512
561
  type: "tool-call",
513
- toolCallType: "function",
514
562
  toolCallId: (_i = toolCall2.id) != null ? _i : (0, import_provider_utils2.generateId)(),
515
563
  toolName: toolCall2.function.name,
516
- args: toolCall2.function.arguments
564
+ input: toolCall2.function.arguments
517
565
  });
518
566
  toolCall2.hasFinished = true;
519
567
  }
@@ -528,19 +576,20 @@ var GroqChatLanguageModel = class {
528
576
  toolCall.function.arguments += (_l = (_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null ? _l : "";
529
577
  }
530
578
  controller.enqueue({
531
- type: "tool-call-delta",
532
- toolCallType: "function",
533
- toolCallId: toolCall.id,
534
- toolName: toolCall.function.name,
535
- argsTextDelta: (_m = toolCallDelta.function.arguments) != null ? _m : ""
579
+ type: "tool-input-delta",
580
+ id: toolCall.id,
581
+ delta: (_m = toolCallDelta.function.arguments) != null ? _m : ""
536
582
  });
537
583
  if (((_n = toolCall.function) == null ? void 0 : _n.name) != null && ((_o = toolCall.function) == null ? void 0 : _o.arguments) != null && (0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
584
+ controller.enqueue({
585
+ type: "tool-input-end",
586
+ id: toolCall.id
587
+ });
538
588
  controller.enqueue({
539
589
  type: "tool-call",
540
- toolCallType: "function",
541
590
  toolCallId: (_p = toolCall.id) != null ? _p : (0, import_provider_utils2.generateId)(),
542
591
  toolName: toolCall.function.name,
543
- args: toolCall.function.arguments
592
+ input: toolCall.function.arguments
544
593
  });
545
594
  toolCall.hasFinished = true;
546
595
  }
@@ -548,6 +597,12 @@ var GroqChatLanguageModel = class {
548
597
  }
549
598
  },
550
599
  flush(controller) {
600
+ if (isActiveReasoning) {
601
+ controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
602
+ }
603
+ if (isActiveText) {
604
+ controller.enqueue({ type: "text-end", id: "txt-0" });
605
+ }
551
606
  controller.enqueue({
552
607
  type: "finish",
553
608
  finishReason,
@@ -562,67 +617,67 @@ var GroqChatLanguageModel = class {
562
617
  };
563
618
  }
564
619
  };
565
- var groqChatResponseSchema = import_zod3.z.object({
566
- id: import_zod3.z.string().nullish(),
567
- created: import_zod3.z.number().nullish(),
568
- model: import_zod3.z.string().nullish(),
569
- choices: import_zod3.z.array(
570
- import_zod3.z.object({
571
- message: import_zod3.z.object({
572
- content: import_zod3.z.string().nullish(),
573
- reasoning: import_zod3.z.string().nullish(),
574
- tool_calls: import_zod3.z.array(
575
- import_zod3.z.object({
576
- id: import_zod3.z.string().nullish(),
577
- type: import_zod3.z.literal("function"),
578
- function: import_zod3.z.object({
579
- name: import_zod3.z.string(),
580
- arguments: import_zod3.z.string()
620
+ var groqChatResponseSchema = import_v43.z.object({
621
+ id: import_v43.z.string().nullish(),
622
+ created: import_v43.z.number().nullish(),
623
+ model: import_v43.z.string().nullish(),
624
+ choices: import_v43.z.array(
625
+ import_v43.z.object({
626
+ message: import_v43.z.object({
627
+ content: import_v43.z.string().nullish(),
628
+ reasoning: import_v43.z.string().nullish(),
629
+ tool_calls: import_v43.z.array(
630
+ import_v43.z.object({
631
+ id: import_v43.z.string().nullish(),
632
+ type: import_v43.z.literal("function"),
633
+ function: import_v43.z.object({
634
+ name: import_v43.z.string(),
635
+ arguments: import_v43.z.string()
581
636
  })
582
637
  })
583
638
  ).nullish()
584
639
  }),
585
- index: import_zod3.z.number(),
586
- finish_reason: import_zod3.z.string().nullish()
640
+ index: import_v43.z.number(),
641
+ finish_reason: import_v43.z.string().nullish()
587
642
  })
588
643
  ),
589
- usage: import_zod3.z.object({
590
- prompt_tokens: import_zod3.z.number().nullish(),
591
- completion_tokens: import_zod3.z.number().nullish(),
592
- total_tokens: import_zod3.z.number().nullish()
644
+ usage: import_v43.z.object({
645
+ prompt_tokens: import_v43.z.number().nullish(),
646
+ completion_tokens: import_v43.z.number().nullish(),
647
+ total_tokens: import_v43.z.number().nullish()
593
648
  }).nullish()
594
649
  });
595
- var groqChatChunkSchema = import_zod3.z.union([
596
- import_zod3.z.object({
597
- id: import_zod3.z.string().nullish(),
598
- created: import_zod3.z.number().nullish(),
599
- model: import_zod3.z.string().nullish(),
600
- choices: import_zod3.z.array(
601
- import_zod3.z.object({
602
- delta: import_zod3.z.object({
603
- content: import_zod3.z.string().nullish(),
604
- reasoning: import_zod3.z.string().nullish(),
605
- tool_calls: import_zod3.z.array(
606
- import_zod3.z.object({
607
- index: import_zod3.z.number(),
608
- id: import_zod3.z.string().nullish(),
609
- type: import_zod3.z.literal("function").optional(),
610
- function: import_zod3.z.object({
611
- name: import_zod3.z.string().nullish(),
612
- arguments: import_zod3.z.string().nullish()
650
+ var groqChatChunkSchema = import_v43.z.union([
651
+ import_v43.z.object({
652
+ id: import_v43.z.string().nullish(),
653
+ created: import_v43.z.number().nullish(),
654
+ model: import_v43.z.string().nullish(),
655
+ choices: import_v43.z.array(
656
+ import_v43.z.object({
657
+ delta: import_v43.z.object({
658
+ content: import_v43.z.string().nullish(),
659
+ reasoning: import_v43.z.string().nullish(),
660
+ tool_calls: import_v43.z.array(
661
+ import_v43.z.object({
662
+ index: import_v43.z.number(),
663
+ id: import_v43.z.string().nullish(),
664
+ type: import_v43.z.literal("function").optional(),
665
+ function: import_v43.z.object({
666
+ name: import_v43.z.string().nullish(),
667
+ arguments: import_v43.z.string().nullish()
613
668
  })
614
669
  })
615
670
  ).nullish()
616
671
  }).nullish(),
617
- finish_reason: import_zod3.z.string().nullable().optional(),
618
- index: import_zod3.z.number()
672
+ finish_reason: import_v43.z.string().nullable().optional(),
673
+ index: import_v43.z.number()
619
674
  })
620
675
  ),
621
- x_groq: import_zod3.z.object({
622
- usage: import_zod3.z.object({
623
- prompt_tokens: import_zod3.z.number().nullish(),
624
- completion_tokens: import_zod3.z.number().nullish(),
625
- total_tokens: import_zod3.z.number().nullish()
676
+ x_groq: import_v43.z.object({
677
+ usage: import_v43.z.object({
678
+ prompt_tokens: import_v43.z.number().nullish(),
679
+ completion_tokens: import_v43.z.number().nullish(),
680
+ total_tokens: import_v43.z.number().nullish()
626
681
  }).nullish()
627
682
  }).nullish()
628
683
  }),
@@ -631,19 +686,19 @@ var groqChatChunkSchema = import_zod3.z.union([
631
686
 
632
687
  // src/groq-transcription-model.ts
633
688
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
634
- var import_zod4 = require("zod");
635
- var groqProviderOptionsSchema = import_zod4.z.object({
636
- language: import_zod4.z.string().nullish(),
637
- prompt: import_zod4.z.string().nullish(),
638
- responseFormat: import_zod4.z.string().nullish(),
639
- temperature: import_zod4.z.number().min(0).max(1).nullish(),
640
- timestampGranularities: import_zod4.z.array(import_zod4.z.string()).nullish()
689
+ var import_v44 = require("zod/v4");
690
+ var groqProviderOptionsSchema = import_v44.z.object({
691
+ language: import_v44.z.string().nullish(),
692
+ prompt: import_v44.z.string().nullish(),
693
+ responseFormat: import_v44.z.string().nullish(),
694
+ temperature: import_v44.z.number().min(0).max(1).nullish(),
695
+ timestampGranularities: import_v44.z.array(import_v44.z.string()).nullish()
641
696
  });
642
697
  var GroqTranscriptionModel = class {
643
698
  constructor(modelId, config) {
644
699
  this.modelId = modelId;
645
700
  this.config = config;
646
- this.specificationVersion = "v1";
701
+ this.specificationVersion = "v2";
647
702
  }
648
703
  get provider() {
649
704
  return this.config.provider;
@@ -725,27 +780,27 @@ var GroqTranscriptionModel = class {
725
780
  };
726
781
  }
727
782
  };
728
- var groqTranscriptionResponseSchema = import_zod4.z.object({
729
- task: import_zod4.z.string(),
730
- language: import_zod4.z.string(),
731
- duration: import_zod4.z.number(),
732
- text: import_zod4.z.string(),
733
- segments: import_zod4.z.array(
734
- import_zod4.z.object({
735
- id: import_zod4.z.number(),
736
- seek: import_zod4.z.number(),
737
- start: import_zod4.z.number(),
738
- end: import_zod4.z.number(),
739
- text: import_zod4.z.string(),
740
- tokens: import_zod4.z.array(import_zod4.z.number()),
741
- temperature: import_zod4.z.number(),
742
- avg_logprob: import_zod4.z.number(),
743
- compression_ratio: import_zod4.z.number(),
744
- no_speech_prob: import_zod4.z.number()
783
+ var groqTranscriptionResponseSchema = import_v44.z.object({
784
+ task: import_v44.z.string(),
785
+ language: import_v44.z.string(),
786
+ duration: import_v44.z.number(),
787
+ text: import_v44.z.string(),
788
+ segments: import_v44.z.array(
789
+ import_v44.z.object({
790
+ id: import_v44.z.number(),
791
+ seek: import_v44.z.number(),
792
+ start: import_v44.z.number(),
793
+ end: import_v44.z.number(),
794
+ text: import_v44.z.string(),
795
+ tokens: import_v44.z.array(import_v44.z.number()),
796
+ temperature: import_v44.z.number(),
797
+ avg_logprob: import_v44.z.number(),
798
+ compression_ratio: import_v44.z.number(),
799
+ no_speech_prob: import_v44.z.number()
745
800
  })
746
801
  ),
747
- x_groq: import_zod4.z.object({
748
- id: import_zod4.z.string()
802
+ x_groq: import_v44.z.object({
803
+ id: import_v44.z.string()
749
804
  })
750
805
  });
751
806