@ai-sdk/google 4.0.77 → 4.0.79

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.
@@ -17,7 +17,7 @@ import {
17
17
  WORKFLOW_DESERIALIZE,
18
18
  zodSchema as zodSchema3
19
19
  } from "@ai-sdk/provider-utils";
20
- import { z as z3 } from "zod/v4";
20
+ import { z as z4 } from "zod/v4";
21
21
 
22
22
  // src/convert-google-usage.ts
23
23
  import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
@@ -60,6 +60,25 @@ import {
60
60
  resolveProviderReference,
61
61
  secureJsonParse
62
62
  } from "@ai-sdk/provider-utils";
63
+
64
+ // src/tool/code-execution.ts
65
+ import { createProviderExecutedToolFactory } from "@ai-sdk/provider-utils";
66
+ import { z } from "zod/v4";
67
+ var codeExecutionInputSchema = z.object({
68
+ language: z.string().describe("The programming language of the code."),
69
+ code: z.string().describe("The code to be executed.")
70
+ });
71
+ var codeExecutionOutputSchema = z.object({
72
+ outcome: z.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
73
+ output: z.string().describe("The output from the code execution.")
74
+ });
75
+ var codeExecution = createProviderExecutedToolFactory({
76
+ id: "google.code_execution",
77
+ inputSchema: codeExecutionInputSchema,
78
+ outputSchema: codeExecutionOutputSchema
79
+ });
80
+
81
+ // src/convert-to-google-messages.ts
63
82
  var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
64
83
  var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
65
84
  function parseBase64DataUrl(value) {
@@ -229,7 +248,7 @@ function convertToGoogleMessages(prompt, options) {
229
248
  parts.push({
230
249
  fileData: {
231
250
  mimeType: resolveFullMediaType({ part }),
232
- fileUri: part.data.url.toString()
251
+ fileUri: part.data.url.protocol === "gs:" && part.data.originalUrl != null ? part.data.originalUrl : part.data.url.toString()
233
252
  }
234
253
  });
235
254
  break;
@@ -372,6 +391,13 @@ function convertToGoogleMessages(prompt, options) {
372
391
  break;
373
392
  }
374
393
  case "tool-call": {
394
+ if (part.providerExecuted === true && part.toolName === "code_execution") {
395
+ return {
396
+ executableCode: codeExecutionInputSchema.parse(
397
+ typeof part.input === "string" ? secureJsonParse(part.input) : part.input
398
+ )
399
+ };
400
+ }
375
401
  const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
376
402
  const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
377
403
  const isServerToolCall = serverToolCallId != null && serverToolType != null;
@@ -406,6 +432,13 @@ function convertToGoogleMessages(prompt, options) {
406
432
  };
407
433
  }
408
434
  case "tool-result": {
435
+ if (part.toolName === "code_execution" && part.output.type === "json") {
436
+ return {
437
+ codeExecutionResult: codeExecutionOutputSchema.parse(
438
+ part.output.value
439
+ )
440
+ };
441
+ }
409
442
  const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
410
443
  const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
411
444
  if (serverToolCallId && serverToolType) {
@@ -604,15 +637,15 @@ import {
604
637
  lazySchema,
605
638
  zodSchema
606
639
  } from "@ai-sdk/provider-utils";
607
- import { z } from "zod/v4";
640
+ import { z as z2 } from "zod/v4";
608
641
  var googleErrorDataSchema = lazySchema(
609
642
  () => zodSchema(
610
- z.object({
611
- error: z.object({
612
- code: z.number().nullable(),
613
- message: z.string(),
614
- status: z.string(),
615
- details: z.array(z.unknown()).nullish()
643
+ z2.object({
644
+ error: z2.object({
645
+ code: z2.number().nullable(),
646
+ message: z2.string(),
647
+ status: z2.string(),
648
+ details: z2.array(z2.unknown()).nullish()
616
649
  })
617
650
  })
618
651
  )
@@ -665,23 +698,23 @@ import {
665
698
  lazySchema as lazySchema2,
666
699
  zodSchema as zodSchema2
667
700
  } from "@ai-sdk/provider-utils";
668
- import { z as z2 } from "zod/v4";
701
+ import { z as z3 } from "zod/v4";
669
702
  var googleLanguageModelOptions = lazySchema2(
670
703
  () => zodSchema2(
671
- z2.object({
672
- responseModalities: z2.array(z2.enum(["TEXT", "IMAGE"])).optional(),
673
- thinkingConfig: z2.object({
674
- thinkingBudget: z2.number().optional(),
675
- includeThoughts: z2.boolean().optional(),
704
+ z3.object({
705
+ responseModalities: z3.array(z3.enum(["TEXT", "IMAGE"])).optional(),
706
+ thinkingConfig: z3.object({
707
+ thinkingBudget: z3.number().optional(),
708
+ includeThoughts: z3.boolean().optional(),
676
709
  // https://ai.google.dev/gemini-api/docs/gemini-3?thinking=high#thinking_level
677
- thinkingLevel: z2.enum(["minimal", "low", "medium", "high"]).optional()
710
+ thinkingLevel: z3.enum(["minimal", "low", "medium", "high"]).optional()
678
711
  }).optional(),
679
712
  /**
680
713
  * Optional.
681
714
  * The name of the cached content used as context to serve the prediction.
682
715
  * Format: cachedContents/{cachedContent}
683
716
  */
684
- cachedContent: z2.string().optional(),
717
+ cachedContent: z3.string().optional(),
685
718
  /**
686
719
  * Optional. Enable structured output. Default is true.
687
720
  *
@@ -690,13 +723,13 @@ var googleLanguageModelOptions = lazySchema2(
690
723
  * Google uses. You can use this to disable
691
724
  * structured outputs if you need to.
692
725
  */
693
- structuredOutputs: z2.boolean().optional(),
726
+ structuredOutputs: z3.boolean().optional(),
694
727
  /**
695
728
  * Optional. A list of unique safety settings for blocking unsafe content.
696
729
  */
697
- safetySettings: z2.array(
698
- z2.object({
699
- category: z2.enum([
730
+ safetySettings: z3.array(
731
+ z3.object({
732
+ category: z3.enum([
700
733
  "HARM_CATEGORY_UNSPECIFIED",
701
734
  "HARM_CATEGORY_HATE_SPEECH",
702
735
  "HARM_CATEGORY_DANGEROUS_CONTENT",
@@ -704,7 +737,7 @@ var googleLanguageModelOptions = lazySchema2(
704
737
  "HARM_CATEGORY_SEXUALLY_EXPLICIT",
705
738
  "HARM_CATEGORY_CIVIC_INTEGRITY"
706
739
  ]),
707
- threshold: z2.enum([
740
+ threshold: z3.enum([
708
741
  "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
709
742
  "BLOCK_LOW_AND_ABOVE",
710
743
  "BLOCK_MEDIUM_AND_ABOVE",
@@ -714,7 +747,7 @@ var googleLanguageModelOptions = lazySchema2(
714
747
  ])
715
748
  })
716
749
  ).optional(),
717
- threshold: z2.enum([
750
+ threshold: z3.enum([
718
751
  "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
719
752
  "BLOCK_LOW_AND_ABOVE",
720
753
  "BLOCK_MEDIUM_AND_ABOVE",
@@ -727,19 +760,19 @@ var googleLanguageModelOptions = lazySchema2(
727
760
  *
728
761
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
729
762
  */
730
- audioTimestamp: z2.boolean().optional(),
763
+ audioTimestamp: z3.boolean().optional(),
731
764
  /**
732
765
  * Optional. Defines labels used in billing reports. Available on Vertex AI only.
733
766
  *
734
767
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
735
768
  */
736
- labels: z2.record(z2.string(), z2.string()).optional(),
769
+ labels: z3.record(z3.string(), z3.string()).optional(),
737
770
  /**
738
771
  * Optional. If specified, the media resolution specified will be used.
739
772
  *
740
773
  * https://ai.google.dev/api/generate-content#MediaResolution
741
774
  */
742
- mediaResolution: z2.enum([
775
+ mediaResolution: z3.enum([
743
776
  "MEDIA_RESOLUTION_UNSPECIFIED",
744
777
  "MEDIA_RESOLUTION_LOW",
745
778
  "MEDIA_RESOLUTION_MEDIUM",
@@ -750,8 +783,8 @@ var googleLanguageModelOptions = lazySchema2(
750
783
  *
751
784
  * https://ai.google.dev/gemini-api/docs/image-generation#aspect_ratios
752
785
  */
753
- imageConfig: z2.object({
754
- aspectRatio: z2.enum([
786
+ imageConfig: z3.object({
787
+ aspectRatio: z3.enum([
755
788
  "1:1",
756
789
  "2:3",
757
790
  "3:2",
@@ -767,12 +800,12 @@ var googleLanguageModelOptions = lazySchema2(
767
800
  "1:4",
768
801
  "4:1"
769
802
  ]).optional(),
770
- imageSize: z2.enum(["1K", "2K", "4K", "512"]).optional(),
803
+ imageSize: z3.enum(["1K", "2K", "4K", "512"]).optional(),
771
804
  /**
772
805
  * Optional. Controls the generation of people in images.
773
806
  * Vertex AI only.
774
807
  */
775
- personGeneration: z2.enum([
808
+ personGeneration: z3.enum([
776
809
  "PERSON_GENERATION_UNSPECIFIED",
777
810
  "ALLOW_ALL",
778
811
  "ALLOW_ADULT",
@@ -786,7 +819,7 @@ var googleLanguageModelOptions = lazySchema2(
786
819
  *
787
820
  * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerationConfig
788
821
  */
789
- prominentPeople: z2.enum([
822
+ prominentPeople: z3.enum([
790
823
  "PROMINENT_PEOPLE_UNSPECIFIED",
791
824
  "ALLOW_PROMINENT_PEOPLE",
792
825
  "BLOCK_PROMINENT_PEOPLE"
@@ -795,9 +828,9 @@ var googleLanguageModelOptions = lazySchema2(
795
828
  * Optional. The image output format for generated images.
796
829
  * Vertex AI only.
797
830
  */
798
- imageOutputOptions: z2.object({
799
- mimeType: z2.enum(["image/jpeg", "image/png"]).optional(),
800
- compressionQuality: z2.number().optional()
831
+ imageOutputOptions: z3.object({
832
+ mimeType: z3.enum(["image/jpeg", "image/png"]).optional(),
833
+ compressionQuality: z3.number().optional()
801
834
  }).optional()
802
835
  }).optional(),
803
836
  /**
@@ -806,10 +839,10 @@ var googleLanguageModelOptions = lazySchema2(
806
839
  *
807
840
  * https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
808
841
  */
809
- retrievalConfig: z2.object({
810
- latLng: z2.object({
811
- latitude: z2.number(),
812
- longitude: z2.number()
842
+ retrievalConfig: z3.object({
843
+ latLng: z3.object({
844
+ latitude: z3.number(),
845
+ longitude: z3.number()
813
846
  }).optional()
814
847
  }).optional(),
815
848
  /**
@@ -822,12 +855,12 @@ var googleLanguageModelOptions = lazySchema2(
822
855
  *
823
856
  * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
824
857
  */
825
- streamFunctionCallArguments: z2.boolean().optional(),
858
+ streamFunctionCallArguments: z3.boolean().optional(),
826
859
  /**
827
860
  * Optional. The service tier to use for the request. Sent as the
828
861
  * `serviceTier` body field. Gemini API only.
829
862
  */
830
- serviceTier: z2.enum(["standard", "flex", "priority"]).optional(),
863
+ serviceTier: z3.enum(["standard", "flex", "priority"]).optional(),
831
864
  /**
832
865
  * Optional. Vertex AI only. Sent as the
833
866
  * `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
@@ -838,7 +871,7 @@ var googleLanguageModelOptions = lazySchema2(
838
871
  * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
839
872
  * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/flex-paygo
840
873
  */
841
- sharedRequestType: z2.enum(["priority", "flex", "standard"]).optional(),
874
+ sharedRequestType: z3.enum(["priority", "flex", "standard"]).optional(),
842
875
  /**
843
876
  * Optional. Vertex AI only. Sent as the `X-Vertex-AI-LLM-Request-Type`
844
877
  * request header. Set to `'shared'` together with `sharedRequestType`
@@ -846,7 +879,7 @@ var googleLanguageModelOptions = lazySchema2(
846
879
  *
847
880
  * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
848
881
  */
849
- requestType: z2.enum(["shared"]).optional()
882
+ requestType: z3.enum(["shared"]).optional()
850
883
  })
851
884
  )
852
885
  );
@@ -1357,7 +1390,6 @@ function resolvePartialArgValue(arg) {
1357
1390
  const value = (_b = (_a = arg.stringValue) != null ? _a : arg.numberValue) != null ? _b : arg.boolValue;
1358
1391
  if (value != null) return { value, json: JSON.stringify(value) };
1359
1392
  if ("nullValue" in arg) return { value: null, json: "null" };
1360
- return void 0;
1361
1393
  }
1362
1394
 
1363
1395
  // src/map-google-finish-reason.ts
@@ -2465,195 +2497,195 @@ function extractSources({
2465
2497
  }
2466
2498
  return sources.length > 0 ? sources : void 0;
2467
2499
  }
2468
- var getGroundingMetadataSchema = () => z3.object({
2469
- webSearchQueries: z3.array(z3.string()).nullish(),
2470
- imageSearchQueries: z3.array(z3.string()).nullish(),
2471
- retrievalQueries: z3.array(z3.string()).nullish(),
2472
- searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
2473
- groundingChunks: z3.array(
2474
- z3.object({
2475
- web: z3.object({ uri: z3.string(), title: z3.string().nullish() }).nullish(),
2476
- image: z3.object({
2477
- sourceUri: z3.string(),
2478
- imageUri: z3.string(),
2479
- title: z3.string().nullish(),
2480
- domain: z3.string().nullish()
2500
+ var getGroundingMetadataSchema = () => z4.object({
2501
+ webSearchQueries: z4.array(z4.string()).nullish(),
2502
+ imageSearchQueries: z4.array(z4.string()).nullish(),
2503
+ retrievalQueries: z4.array(z4.string()).nullish(),
2504
+ searchEntryPoint: z4.object({ renderedContent: z4.string() }).nullish(),
2505
+ groundingChunks: z4.array(
2506
+ z4.object({
2507
+ web: z4.object({ uri: z4.string(), title: z4.string().nullish() }).nullish(),
2508
+ image: z4.object({
2509
+ sourceUri: z4.string(),
2510
+ imageUri: z4.string(),
2511
+ title: z4.string().nullish(),
2512
+ domain: z4.string().nullish()
2481
2513
  }).nullish(),
2482
- retrievedContext: z3.object({
2483
- uri: z3.string().nullish(),
2484
- title: z3.string().nullish(),
2485
- text: z3.string().nullish(),
2486
- fileSearchStore: z3.string().nullish()
2514
+ retrievedContext: z4.object({
2515
+ uri: z4.string().nullish(),
2516
+ title: z4.string().nullish(),
2517
+ text: z4.string().nullish(),
2518
+ fileSearchStore: z4.string().nullish()
2487
2519
  }).nullish(),
2488
- maps: z3.object({
2489
- uri: z3.string().nullish(),
2490
- title: z3.string().nullish(),
2491
- text: z3.string().nullish(),
2492
- placeId: z3.string().nullish()
2520
+ maps: z4.object({
2521
+ uri: z4.string().nullish(),
2522
+ title: z4.string().nullish(),
2523
+ text: z4.string().nullish(),
2524
+ placeId: z4.string().nullish()
2493
2525
  }).nullish()
2494
2526
  })
2495
2527
  ).nullish(),
2496
- groundingSupports: z3.array(
2497
- z3.object({
2498
- segment: z3.object({
2499
- startIndex: z3.number().nullish(),
2500
- endIndex: z3.number().nullish(),
2501
- text: z3.string().nullish()
2528
+ groundingSupports: z4.array(
2529
+ z4.object({
2530
+ segment: z4.object({
2531
+ startIndex: z4.number().nullish(),
2532
+ endIndex: z4.number().nullish(),
2533
+ text: z4.string().nullish()
2502
2534
  }).nullish(),
2503
- segment_text: z3.string().nullish(),
2504
- groundingChunkIndices: z3.array(z3.number()).nullish(),
2505
- supportChunkIndices: z3.array(z3.number()).nullish(),
2506
- confidenceScores: z3.array(z3.number()).nullish(),
2507
- confidenceScore: z3.array(z3.number()).nullish()
2535
+ segment_text: z4.string().nullish(),
2536
+ groundingChunkIndices: z4.array(z4.number()).nullish(),
2537
+ supportChunkIndices: z4.array(z4.number()).nullish(),
2538
+ confidenceScores: z4.array(z4.number()).nullish(),
2539
+ confidenceScore: z4.array(z4.number()).nullish()
2508
2540
  })
2509
2541
  ).nullish(),
2510
- retrievalMetadata: z3.union([
2511
- z3.object({
2512
- webDynamicRetrievalScore: z3.number()
2542
+ retrievalMetadata: z4.union([
2543
+ z4.object({
2544
+ webDynamicRetrievalScore: z4.number()
2513
2545
  }),
2514
- z3.object({})
2546
+ z4.object({})
2515
2547
  ]).nullish()
2516
2548
  });
2517
- var partialArgSchema = z3.object({
2518
- jsonPath: z3.string(),
2519
- stringValue: z3.string().nullish(),
2520
- numberValue: z3.number().nullish(),
2521
- boolValue: z3.boolean().nullish(),
2522
- nullValue: z3.unknown().nullish(),
2523
- willContinue: z3.boolean().nullish()
2549
+ var partialArgSchema = z4.object({
2550
+ jsonPath: z4.string(),
2551
+ stringValue: z4.string().nullish(),
2552
+ numberValue: z4.number().nullish(),
2553
+ boolValue: z4.boolean().nullish(),
2554
+ nullValue: z4.unknown().nullish(),
2555
+ willContinue: z4.boolean().nullish()
2524
2556
  });
2525
- var getContentSchema = () => z3.object({
2526
- parts: z3.array(
2527
- z3.union([
2557
+ var getContentSchema = () => z4.object({
2558
+ parts: z4.array(
2559
+ z4.union([
2528
2560
  // note: order matters since text can be fully empty
2529
- z3.object({
2530
- functionCall: z3.object({
2531
- id: z3.string().nullish(),
2532
- name: z3.string().nullish(),
2533
- args: z3.unknown().nullish(),
2534
- partialArgs: z3.array(partialArgSchema).nullish(),
2535
- willContinue: z3.boolean().nullish()
2561
+ z4.object({
2562
+ functionCall: z4.object({
2563
+ id: z4.string().nullish(),
2564
+ name: z4.string().nullish(),
2565
+ args: z4.unknown().nullish(),
2566
+ partialArgs: z4.array(partialArgSchema).nullish(),
2567
+ willContinue: z4.boolean().nullish()
2536
2568
  }),
2537
- thoughtSignature: z3.string().nullish()
2569
+ thoughtSignature: z4.string().nullish()
2538
2570
  }),
2539
- z3.object({
2540
- inlineData: z3.object({
2541
- mimeType: z3.string(),
2542
- data: z3.string()
2571
+ z4.object({
2572
+ inlineData: z4.object({
2573
+ mimeType: z4.string(),
2574
+ data: z4.string()
2543
2575
  }),
2544
- thought: z3.boolean().nullish(),
2545
- thoughtSignature: z3.string().nullish()
2576
+ thought: z4.boolean().nullish(),
2577
+ thoughtSignature: z4.string().nullish()
2546
2578
  }),
2547
- z3.object({
2548
- toolCall: z3.object({
2549
- toolType: z3.string(),
2550
- args: z3.unknown().nullish(),
2551
- id: z3.string()
2579
+ z4.object({
2580
+ toolCall: z4.object({
2581
+ toolType: z4.string(),
2582
+ args: z4.unknown().nullish(),
2583
+ id: z4.string()
2552
2584
  }),
2553
- thoughtSignature: z3.string().nullish()
2585
+ thoughtSignature: z4.string().nullish()
2554
2586
  }),
2555
- z3.object({
2556
- toolResponse: z3.object({
2557
- toolType: z3.string(),
2558
- response: z3.unknown().nullish(),
2559
- id: z3.string()
2587
+ z4.object({
2588
+ toolResponse: z4.object({
2589
+ toolType: z4.string(),
2590
+ response: z4.unknown().nullish(),
2591
+ id: z4.string()
2560
2592
  }),
2561
- thoughtSignature: z3.string().nullish()
2593
+ thoughtSignature: z4.string().nullish()
2562
2594
  }),
2563
- z3.object({
2564
- executableCode: z3.object({
2565
- language: z3.string(),
2566
- code: z3.string()
2595
+ z4.object({
2596
+ executableCode: z4.object({
2597
+ language: z4.string(),
2598
+ code: z4.string()
2567
2599
  }).nullish(),
2568
- codeExecutionResult: z3.object({
2569
- outcome: z3.string(),
2570
- output: z3.string().nullish()
2600
+ codeExecutionResult: z4.object({
2601
+ outcome: z4.string(),
2602
+ output: z4.string().nullish()
2571
2603
  }).nullish(),
2572
- text: z3.string().nullish(),
2573
- thought: z3.boolean().nullish(),
2574
- thoughtSignature: z3.string().nullish()
2604
+ text: z4.string().nullish(),
2605
+ thought: z4.boolean().nullish(),
2606
+ thoughtSignature: z4.string().nullish()
2575
2607
  })
2576
2608
  ])
2577
2609
  ).nullish()
2578
2610
  });
2579
- var getSafetyRatingSchema = () => z3.object({
2580
- category: z3.string().nullish(),
2581
- probability: z3.string().nullish(),
2582
- probabilityScore: z3.number().nullish(),
2583
- severity: z3.string().nullish(),
2584
- severityScore: z3.number().nullish(),
2585
- blocked: z3.boolean().nullish()
2611
+ var getSafetyRatingSchema = () => z4.object({
2612
+ category: z4.string().nullish(),
2613
+ probability: z4.string().nullish(),
2614
+ probabilityScore: z4.number().nullish(),
2615
+ severity: z4.string().nullish(),
2616
+ severityScore: z4.number().nullish(),
2617
+ blocked: z4.boolean().nullish()
2586
2618
  });
2587
- var tokenDetailsSchema = z3.array(
2588
- z3.object({
2589
- modality: z3.string(),
2590
- tokenCount: z3.number()
2619
+ var tokenDetailsSchema = z4.array(
2620
+ z4.object({
2621
+ modality: z4.string(),
2622
+ tokenCount: z4.number()
2591
2623
  }).loose()
2592
2624
  ).nullish();
2593
- var usageSchema = z3.object({
2594
- cachedContentTokenCount: z3.number().nullish(),
2595
- thoughtsTokenCount: z3.number().nullish(),
2596
- promptTokenCount: z3.number().nullish(),
2597
- candidatesTokenCount: z3.number().nullish(),
2598
- toolUsePromptTokenCount: z3.number().nullish(),
2599
- totalTokenCount: z3.number().nullish(),
2625
+ var usageSchema = z4.object({
2626
+ cachedContentTokenCount: z4.number().nullish(),
2627
+ thoughtsTokenCount: z4.number().nullish(),
2628
+ promptTokenCount: z4.number().nullish(),
2629
+ candidatesTokenCount: z4.number().nullish(),
2630
+ toolUsePromptTokenCount: z4.number().nullish(),
2631
+ totalTokenCount: z4.number().nullish(),
2600
2632
  // https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
2601
- trafficType: z3.string().nullish(),
2602
- serviceTier: z3.string().nullish(),
2633
+ trafficType: z4.string().nullish(),
2634
+ serviceTier: z4.string().nullish(),
2603
2635
  // https://ai.google.dev/api/generate-content#Modality
2604
2636
  promptTokensDetails: tokenDetailsSchema,
2605
2637
  cacheTokensDetails: tokenDetailsSchema,
2606
2638
  candidatesTokensDetails: tokenDetailsSchema,
2607
2639
  toolUsePromptTokensDetails: tokenDetailsSchema
2608
2640
  }).loose();
2609
- var getUrlContextMetadataSchema = () => z3.object({
2610
- urlMetadata: z3.array(
2611
- z3.object({
2612
- retrievedUrl: z3.string(),
2613
- urlRetrievalStatus: z3.string()
2641
+ var getUrlContextMetadataSchema = () => z4.object({
2642
+ urlMetadata: z4.array(
2643
+ z4.object({
2644
+ retrievedUrl: z4.string(),
2645
+ urlRetrievalStatus: z4.string()
2614
2646
  })
2615
2647
  ).nullish()
2616
2648
  });
2617
2649
  var responseSchema = lazySchema3(
2618
2650
  () => zodSchema3(
2619
- z3.object({
2620
- responseId: z3.string().nullish(),
2621
- candidates: z3.array(
2622
- z3.object({
2623
- content: getContentSchema().nullish().or(z3.object({}).strict()),
2624
- finishReason: z3.string().nullish(),
2625
- finishMessage: z3.string().nullish(),
2626
- safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
2651
+ z4.object({
2652
+ responseId: z4.string().nullish(),
2653
+ candidates: z4.array(
2654
+ z4.object({
2655
+ content: getContentSchema().nullish().or(z4.object({}).strict()),
2656
+ finishReason: z4.string().nullish(),
2657
+ finishMessage: z4.string().nullish(),
2658
+ safetyRatings: z4.array(getSafetyRatingSchema()).nullish(),
2627
2659
  groundingMetadata: getGroundingMetadataSchema().nullish(),
2628
2660
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
2629
2661
  })
2630
2662
  ).nullish(),
2631
2663
  usageMetadata: usageSchema.nullish(),
2632
- promptFeedback: z3.object({
2633
- blockReason: z3.string().nullish(),
2634
- safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
2664
+ promptFeedback: z4.object({
2665
+ blockReason: z4.string().nullish(),
2666
+ safetyRatings: z4.array(getSafetyRatingSchema()).nullish()
2635
2667
  }).nullish()
2636
2668
  })
2637
2669
  )
2638
2670
  );
2639
2671
  var chunkSchema = lazySchema3(
2640
2672
  () => zodSchema3(
2641
- z3.object({
2642
- responseId: z3.string().nullish(),
2643
- candidates: z3.array(
2644
- z3.object({
2673
+ z4.object({
2674
+ responseId: z4.string().nullish(),
2675
+ candidates: z4.array(
2676
+ z4.object({
2645
2677
  content: getContentSchema().nullish(),
2646
- finishReason: z3.string().nullish(),
2647
- finishMessage: z3.string().nullish(),
2648
- safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
2678
+ finishReason: z4.string().nullish(),
2679
+ finishMessage: z4.string().nullish(),
2680
+ safetyRatings: z4.array(getSafetyRatingSchema()).nullish(),
2649
2681
  groundingMetadata: getGroundingMetadataSchema().nullish(),
2650
2682
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
2651
2683
  })
2652
2684
  ).nullish(),
2653
2685
  usageMetadata: usageSchema.nullish(),
2654
- promptFeedback: z3.object({
2655
- blockReason: z3.string().nullish(),
2656
- safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
2686
+ promptFeedback: z4.object({
2687
+ blockReason: z4.string().nullish(),
2688
+ safetyRatings: z4.array(getSafetyRatingSchema()).nullish()
2657
2689
  }).nullish()
2658
2690
  })
2659
2691
  )
@@ -2663,6 +2695,9 @@ function isConfirmedPromptBlockReason(blockReason) {
2663
2695
  }
2664
2696
 
2665
2697
  // src/google-speech-model.ts
2698
+ import {
2699
+ InvalidArgumentError
2700
+ } from "@ai-sdk/provider";
2666
2701
  import {
2667
2702
  combineHeaders as combineHeaders2,
2668
2703
  convertBase64ToUint8Array,
@@ -2677,18 +2712,18 @@ import {
2677
2712
 
2678
2713
  // src/google-speech-api.ts
2679
2714
  import { lazySchema as lazySchema4, zodSchema as zodSchema4 } from "@ai-sdk/provider-utils";
2680
- import { z as z4 } from "zod/v4";
2715
+ import { z as z5 } from "zod/v4";
2681
2716
  var googleSpeechResponseSchema = lazySchema4(
2682
2717
  () => zodSchema4(
2683
- z4.object({
2684
- candidates: z4.array(
2685
- z4.object({
2686
- content: z4.object({
2687
- parts: z4.array(
2688
- z4.object({
2689
- inlineData: z4.object({
2690
- mimeType: z4.string().nullish(),
2691
- data: z4.string().nullish()
2718
+ z5.object({
2719
+ candidates: z5.array(
2720
+ z5.object({
2721
+ content: z5.object({
2722
+ parts: z5.array(
2723
+ z5.object({
2724
+ inlineData: z5.object({
2725
+ mimeType: z5.string().nullish(),
2726
+ data: z5.string().nullish()
2692
2727
  }).nullish()
2693
2728
  })
2694
2729
  ).nullish()
@@ -2699,32 +2734,82 @@ var googleSpeechResponseSchema = lazySchema4(
2699
2734
  )
2700
2735
  );
2701
2736
 
2737
+ // src/google-speech-input.ts
2738
+ function getGoogleSpeechInput({
2739
+ text,
2740
+ voice,
2741
+ providerOptions
2742
+ }) {
2743
+ const google = providerOptions == null ? void 0 : providerOptions.google;
2744
+ const options = google != null && typeof google === "object" ? google : void 0;
2745
+ const turns = options && "turns" in options ? options.turns : void 0;
2746
+ const turnTexts = [];
2747
+ if (Array.isArray(turns) && turns.length > 0) {
2748
+ for (const turn of turns) {
2749
+ if (turn == null || typeof turn !== "object" || !("text" in turn) || typeof turn.text !== "string") {
2750
+ break;
2751
+ }
2752
+ turnTexts.push(turn.text);
2753
+ }
2754
+ if (turnTexts.length === turns.length) {
2755
+ text = turnTexts.join("");
2756
+ }
2757
+ }
2758
+ const config = options && "multiSpeakerVoiceConfig" in options ? options.multiSpeakerVoiceConfig : void 0;
2759
+ const speakers = config != null && typeof config === "object" && "speakerVoiceConfigs" in config && Array.isArray(config.speakerVoiceConfigs) ? config.speakerVoiceConfigs : [];
2760
+ return {
2761
+ text,
2762
+ usesCustomVoice: (voice == null ? void 0 : voice.startsWith("voice_")) === true || (voice == null ? void 0 : voice.startsWith("voicekey_")) === true || speakers.some(
2763
+ (speaker) => speaker != null && typeof speaker === "object" && "voiceConfig" in speaker && speaker.voiceConfig != null && typeof speaker.voiceConfig === "object" && "voice" in speaker.voiceConfig
2764
+ )
2765
+ };
2766
+ }
2767
+
2702
2768
  // src/google-speech-model-options.ts
2703
2769
  import {
2704
2770
  lazySchema as lazySchema5,
2705
2771
  zodSchema as zodSchema5
2706
2772
  } from "@ai-sdk/provider-utils";
2707
- import { z as z5 } from "zod/v4";
2708
- var prebuiltVoiceConfigSchema = z5.object({
2709
- voiceName: z5.string()
2773
+ import { z as z6 } from "zod/v4";
2774
+ var prebuiltVoiceConfigSchema = z6.object({
2775
+ voiceName: z6.string()
2776
+ });
2777
+ var voiceConfigSchema = z6.object({
2778
+ prebuiltVoiceConfig: prebuiltVoiceConfigSchema,
2779
+ voice: z6.never().optional()
2710
2780
  });
2711
- var voiceConfigSchema = z5.object({
2712
- prebuiltVoiceConfig: prebuiltVoiceConfigSchema
2781
+ var speechMetadataSchema = z6.object({
2782
+ speaker: z6.string().min(1).optional(),
2783
+ style: z6.string().optional()
2713
2784
  });
2714
2785
  var googleSpeechProviderOptionsSchema = lazySchema5(
2715
2786
  () => zodSchema5(
2716
- z5.object({
2787
+ z6.object({
2788
+ /** Turn-level directions for the top-level text, for Gemini 3.8 TTS. */
2789
+ speechMetadata: speechMetadataSchema.optional(),
2790
+ /**
2791
+ * Structured transcript for Gemini 3.8 TTS. Replaces the top-level text;
2792
+ * pass text: '' when using turns. Each multi-speaker turn must name a
2793
+ * configured speaker in speechMetadata. Per-turn styles override instructions.
2794
+ */
2795
+ turns: z6.array(
2796
+ z6.object({
2797
+ text: z6.string(),
2798
+ speechMetadata: speechMetadataSchema.optional()
2799
+ })
2800
+ ).min(1).optional(),
2717
2801
  /**
2718
2802
  * Multi-speaker configuration for dialogue audio. When provided, this
2719
2803
  * overrides the top-level `voice`. The Gemini TTS API supports up to two
2720
- * speakers; each speaker name must match a name used in the input text.
2804
+ * speakers. For Gemini 3.8, each turn's speechMetadata.speaker must match
2805
+ * a configured speaker; older models use speaker labels in the text.
2721
2806
  *
2722
2807
  * https://ai.google.dev/gemini-api/docs/speech-generation#multi-speaker
2723
2808
  */
2724
- multiSpeakerVoiceConfig: z5.object({
2725
- speakerVoiceConfigs: z5.array(
2726
- z5.object({
2727
- speaker: z5.string(),
2809
+ multiSpeakerVoiceConfig: z6.object({
2810
+ speakerVoiceConfigs: z6.array(
2811
+ z6.object({
2812
+ speaker: z6.string(),
2728
2813
  voiceConfig: voiceConfigSchema
2729
2814
  })
2730
2815
  )
@@ -2763,6 +2848,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2763
2848
  language,
2764
2849
  providerOptions
2765
2850
  }) {
2851
+ var _a;
2766
2852
  const warnings = [];
2767
2853
  const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
2768
2854
  let googleOptions;
@@ -2783,10 +2869,22 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2783
2869
  schema: googleSpeechProviderOptionsSchema
2784
2870
  });
2785
2871
  }
2872
+ const usesStructuredSpeech = !this.modelId.startsWith("gemini-2.5-") && !this.modelId.startsWith("gemini-3.1-");
2873
+ const input = getGoogleSpeechInput({
2874
+ text,
2875
+ voice,
2876
+ providerOptions: { google: googleOptions }
2877
+ });
2878
+ if (input.usesCustomVoice) {
2879
+ throw new InvalidArgumentError({
2880
+ argument: "voice",
2881
+ message: "Custom voices are not supported. Use a prebuilt voice instead."
2882
+ });
2883
+ }
2786
2884
  const multiSpeakerVoiceConfig = googleOptions == null ? void 0 : googleOptions.multiSpeakerVoiceConfig;
2787
2885
  const speechConfig = multiSpeakerVoiceConfig ? { multiSpeakerVoiceConfig } : { voiceConfig: { prebuiltVoiceConfig: { voiceName: voice } } };
2788
2886
  let promptText = text;
2789
- if (instructions != null) {
2887
+ if (instructions != null && !usesStructuredSpeech) {
2790
2888
  if (multiSpeakerVoiceConfig) {
2791
2889
  warnings.push({
2792
2890
  type: "unsupported",
@@ -2797,6 +2895,52 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2797
2895
  promptText = `${instructions}: ${text}`;
2798
2896
  }
2799
2897
  }
2898
+ let parts = [{ text: promptText }];
2899
+ if (usesStructuredSpeech) {
2900
+ if ((googleOptions == null ? void 0 : googleOptions.turns) && googleOptions.speechMetadata) {
2901
+ throw new InvalidArgumentError({
2902
+ argument: "providerOptions",
2903
+ message: "Set speechMetadata on each turn when using turns."
2904
+ });
2905
+ }
2906
+ if ((googleOptions == null ? void 0 : googleOptions.turns) && text !== "") {
2907
+ warnings.push({
2908
+ type: "unsupported",
2909
+ feature: "text",
2910
+ details: "Google TTS turns replace the top-level text."
2911
+ });
2912
+ }
2913
+ parts = ((_a = googleOptions == null ? void 0 : googleOptions.turns) != null ? _a : [
2914
+ { text, speechMetadata: googleOptions == null ? void 0 : googleOptions.speechMetadata }
2915
+ ]).map((part) => {
2916
+ var _a2, _b, _c;
2917
+ const style = (_b = (_a2 = part.speechMetadata) == null ? void 0 : _a2.style) != null ? _b : instructions;
2918
+ const speaker = (_c = part.speechMetadata) == null ? void 0 : _c.speaker;
2919
+ if (multiSpeakerVoiceConfig && !multiSpeakerVoiceConfig.speakerVoiceConfigs.some(
2920
+ (config) => config.speaker === speaker
2921
+ )) {
2922
+ throw new InvalidArgumentError({
2923
+ argument: "speechMetadata.speaker",
2924
+ message: "Every multi-speaker turn must specify a speechMetadata.speaker matching a configured speaker."
2925
+ });
2926
+ }
2927
+ return {
2928
+ text: part.text,
2929
+ ...style != null || speaker != null ? { speechMetadata: { style, speaker } } : {}
2930
+ };
2931
+ });
2932
+ } else if ((googleOptions == null ? void 0 : googleOptions.turns) || (googleOptions == null ? void 0 : googleOptions.speechMetadata)) {
2933
+ throw new InvalidArgumentError({
2934
+ argument: "providerOptions",
2935
+ message: "Structured speech metadata and turns require Gemini 3.8 TTS."
2936
+ });
2937
+ }
2938
+ if (input.text.length === 0) {
2939
+ throw new InvalidArgumentError({
2940
+ argument: "text",
2941
+ message: "Speech input must contain a non-empty transcript."
2942
+ });
2943
+ }
2800
2944
  if (speed != null) {
2801
2945
  warnings.push({
2802
2946
  type: "unsupported",
@@ -2811,10 +2955,20 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2811
2955
  details: "Google Gemini TTS models do not support the `language` option. Language is detected automatically from the input text."
2812
2956
  });
2813
2957
  }
2958
+ const formats = usesStructuredSpeech ? {
2959
+ wav: "AUDIO_WAV",
2960
+ "audio/wav": "AUDIO_WAV",
2961
+ pcm: "AUDIO_L16",
2962
+ "audio/l16": "AUDIO_L16",
2963
+ mulaw: "AUDIO_MULAW",
2964
+ "audio/mulaw": "AUDIO_MULAW",
2965
+ alaw: "AUDIO_ALAW",
2966
+ "audio/alaw": "AUDIO_ALAW"
2967
+ } : { wav: "AUDIO_WAV", pcm: "AUDIO_L16" };
2814
2968
  let resolvedOutputFormat = "wav";
2815
- if (outputFormat === "pcm") {
2816
- resolvedOutputFormat = "pcm";
2817
- } else if (outputFormat != null && outputFormat !== "wav") {
2969
+ if (outputFormat != null && Object.prototype.hasOwnProperty.call(formats, outputFormat)) {
2970
+ resolvedOutputFormat = outputFormat;
2971
+ } else if (outputFormat != null) {
2818
2972
  warnings.push({
2819
2973
  type: "unsupported",
2820
2974
  feature: "outputFormat",
@@ -2822,18 +2976,28 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2822
2976
  });
2823
2977
  }
2824
2978
  const requestBody = {
2825
- contents: [{ role: "user", parts: [{ text: promptText }] }],
2979
+ contents: [{ role: "user", parts }],
2826
2980
  generationConfig: {
2827
2981
  responseModalities: ["AUDIO"],
2828
- speechConfig
2982
+ speechConfig,
2983
+ ...usesStructuredSpeech && outputFormat != null ? {
2984
+ responseFormat: {
2985
+ audio: { mimeType: formats[resolvedOutputFormat] }
2986
+ }
2987
+ } : {}
2829
2988
  }
2830
2989
  };
2831
- return { requestBody, warnings, outputFormat: resolvedOutputFormat };
2990
+ return {
2991
+ requestBody,
2992
+ warnings,
2993
+ outputFormat: formats[resolvedOutputFormat],
2994
+ usesStructuredSpeech
2995
+ };
2832
2996
  }
2833
2997
  async doGenerate(options) {
2834
2998
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2835
2999
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2836
- const { requestBody, warnings, outputFormat } = await this.getArgs(options);
3000
+ const { requestBody, warnings, outputFormat, usesStructuredSpeech } = await this.getArgs(options);
2837
3001
  const {
2838
3002
  value: response,
2839
3003
  responseHeaders,
@@ -2867,9 +3031,10 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2867
3031
  }
2868
3032
  }
2869
3033
  const sampleRate = (_i = parseSampleRate(mimeType)) != null ? _i : DEFAULT_SAMPLE_RATE;
2870
- const pcm = base64Audio != null ? convertBase64ToUint8Array(base64Audio) : new Uint8Array(0);
2871
- const audio = outputFormat === "pcm" || pcm.length === 0 ? pcm : addWavHeader(pcm, sampleRate);
2872
- if (outputFormat === "pcm" && pcm.length > 0) {
3034
+ const bytes = base64Audio != null ? convertBase64ToUint8Array(base64Audio) : new Uint8Array(0);
3035
+ const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType != null ? mimeType : "") || mimeType == null && !usesStructuredSpeech;
3036
+ const audio = outputFormat === "AUDIO_WAV" && isPcm && bytes.length > 0 ? addWavHeader(bytes, sampleRate) : bytes;
3037
+ if (outputFormat === "AUDIO_L16" && bytes.length > 0 && !usesStructuredSpeech) {
2873
3038
  warnings.push({
2874
3039
  type: "unsupported",
2875
3040
  feature: "outputFormat",
@@ -2935,21 +3100,6 @@ function writeAscii(view, offset, text) {
2935
3100
  }
2936
3101
  }
2937
3102
 
2938
- // src/tool/code-execution.ts
2939
- import { createProviderExecutedToolFactory } from "@ai-sdk/provider-utils";
2940
- import { z as z6 } from "zod/v4";
2941
- var codeExecution = createProviderExecutedToolFactory({
2942
- id: "google.code_execution",
2943
- inputSchema: z6.object({
2944
- language: z6.string().describe("The programming language of the code."),
2945
- code: z6.string().describe("The code to be executed.")
2946
- }),
2947
- outputSchema: z6.object({
2948
- outcome: z6.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
2949
- output: z6.string().describe("The output from the code execution.")
2950
- })
2951
- });
2952
-
2953
3103
  // src/tool/enterprise-web-search.ts
2954
3104
  import {
2955
3105
  createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
@@ -6201,6 +6351,7 @@ export {
6201
6351
  GoogleInteractionsLanguageModel,
6202
6352
  GoogleLanguageModel,
6203
6353
  GoogleSpeechModel,
6354
+ getGoogleSpeechInput,
6204
6355
  getGroundingMetadataSchema,
6205
6356
  getUrlContextMetadataSchema,
6206
6357
  googleTools,