@ai-sdk/google 4.0.78 → 4.0.80

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) {
@@ -84,6 +103,20 @@ function convertUrlToolResultPart(url) {
84
103
  }
85
104
  };
86
105
  }
106
+ function containsJSONSchemaReference(value) {
107
+ if (Array.isArray(value)) {
108
+ return value.some(containsJSONSchemaReference);
109
+ }
110
+ if (typeof value !== "object" || value === null) {
111
+ return false;
112
+ }
113
+ return Object.entries(value).some(
114
+ ([key, nestedValue]) => key === "$ref" || containsJSONSchemaReference(nestedValue)
115
+ );
116
+ }
117
+ function serializeFunctionResponseContent(value) {
118
+ return containsJSONSchemaReference(value) ? JSON.stringify(value) : value;
119
+ }
87
120
  function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
88
121
  const functionResponseParts = [];
89
122
  const responseTextParts = [];
@@ -372,6 +405,13 @@ function convertToGoogleMessages(prompt, options) {
372
405
  break;
373
406
  }
374
407
  case "tool-call": {
408
+ if (part.providerExecuted === true && part.toolName === "code_execution") {
409
+ return {
410
+ executableCode: codeExecutionInputSchema.parse(
411
+ typeof part.input === "string" ? secureJsonParse(part.input) : part.input
412
+ )
413
+ };
414
+ }
375
415
  const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
376
416
  const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
377
417
  const isServerToolCall = serverToolCallId != null && serverToolType != null;
@@ -406,6 +446,13 @@ function convertToGoogleMessages(prompt, options) {
406
446
  };
407
447
  }
408
448
  case "tool-result": {
449
+ if (part.toolName === "code_execution" && part.output.type === "json") {
450
+ return {
451
+ codeExecutionResult: codeExecutionOutputSchema.parse(
452
+ part.output.value
453
+ )
454
+ };
455
+ }
409
456
  const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
410
457
  const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
411
458
  if (serverToolCallId && serverToolType) {
@@ -478,7 +525,7 @@ function convertToGoogleMessages(prompt, options) {
478
525
  name: part.toolName,
479
526
  response: {
480
527
  name: part.toolName,
481
- content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : output.value
528
+ content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : serializeFunctionResponseContent(output.value)
482
529
  }
483
530
  }
484
531
  });
@@ -604,15 +651,15 @@ import {
604
651
  lazySchema,
605
652
  zodSchema
606
653
  } from "@ai-sdk/provider-utils";
607
- import { z } from "zod/v4";
654
+ import { z as z2 } from "zod/v4";
608
655
  var googleErrorDataSchema = lazySchema(
609
656
  () => 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()
657
+ z2.object({
658
+ error: z2.object({
659
+ code: z2.number().nullable(),
660
+ message: z2.string(),
661
+ status: z2.string(),
662
+ details: z2.array(z2.unknown()).nullish()
616
663
  })
617
664
  })
618
665
  )
@@ -665,23 +712,23 @@ import {
665
712
  lazySchema as lazySchema2,
666
713
  zodSchema as zodSchema2
667
714
  } from "@ai-sdk/provider-utils";
668
- import { z as z2 } from "zod/v4";
715
+ import { z as z3 } from "zod/v4";
669
716
  var googleLanguageModelOptions = lazySchema2(
670
717
  () => 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(),
718
+ z3.object({
719
+ responseModalities: z3.array(z3.enum(["TEXT", "IMAGE"])).optional(),
720
+ thinkingConfig: z3.object({
721
+ thinkingBudget: z3.number().optional(),
722
+ includeThoughts: z3.boolean().optional(),
676
723
  // https://ai.google.dev/gemini-api/docs/gemini-3?thinking=high#thinking_level
677
- thinkingLevel: z2.enum(["minimal", "low", "medium", "high"]).optional()
724
+ thinkingLevel: z3.enum(["minimal", "low", "medium", "high"]).optional()
678
725
  }).optional(),
679
726
  /**
680
727
  * Optional.
681
728
  * The name of the cached content used as context to serve the prediction.
682
729
  * Format: cachedContents/{cachedContent}
683
730
  */
684
- cachedContent: z2.string().optional(),
731
+ cachedContent: z3.string().optional(),
685
732
  /**
686
733
  * Optional. Enable structured output. Default is true.
687
734
  *
@@ -690,13 +737,13 @@ var googleLanguageModelOptions = lazySchema2(
690
737
  * Google uses. You can use this to disable
691
738
  * structured outputs if you need to.
692
739
  */
693
- structuredOutputs: z2.boolean().optional(),
740
+ structuredOutputs: z3.boolean().optional(),
694
741
  /**
695
742
  * Optional. A list of unique safety settings for blocking unsafe content.
696
743
  */
697
- safetySettings: z2.array(
698
- z2.object({
699
- category: z2.enum([
744
+ safetySettings: z3.array(
745
+ z3.object({
746
+ category: z3.enum([
700
747
  "HARM_CATEGORY_UNSPECIFIED",
701
748
  "HARM_CATEGORY_HATE_SPEECH",
702
749
  "HARM_CATEGORY_DANGEROUS_CONTENT",
@@ -704,7 +751,7 @@ var googleLanguageModelOptions = lazySchema2(
704
751
  "HARM_CATEGORY_SEXUALLY_EXPLICIT",
705
752
  "HARM_CATEGORY_CIVIC_INTEGRITY"
706
753
  ]),
707
- threshold: z2.enum([
754
+ threshold: z3.enum([
708
755
  "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
709
756
  "BLOCK_LOW_AND_ABOVE",
710
757
  "BLOCK_MEDIUM_AND_ABOVE",
@@ -714,7 +761,7 @@ var googleLanguageModelOptions = lazySchema2(
714
761
  ])
715
762
  })
716
763
  ).optional(),
717
- threshold: z2.enum([
764
+ threshold: z3.enum([
718
765
  "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
719
766
  "BLOCK_LOW_AND_ABOVE",
720
767
  "BLOCK_MEDIUM_AND_ABOVE",
@@ -727,19 +774,19 @@ var googleLanguageModelOptions = lazySchema2(
727
774
  *
728
775
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
729
776
  */
730
- audioTimestamp: z2.boolean().optional(),
777
+ audioTimestamp: z3.boolean().optional(),
731
778
  /**
732
779
  * Optional. Defines labels used in billing reports. Available on Vertex AI only.
733
780
  *
734
781
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
735
782
  */
736
- labels: z2.record(z2.string(), z2.string()).optional(),
783
+ labels: z3.record(z3.string(), z3.string()).optional(),
737
784
  /**
738
785
  * Optional. If specified, the media resolution specified will be used.
739
786
  *
740
787
  * https://ai.google.dev/api/generate-content#MediaResolution
741
788
  */
742
- mediaResolution: z2.enum([
789
+ mediaResolution: z3.enum([
743
790
  "MEDIA_RESOLUTION_UNSPECIFIED",
744
791
  "MEDIA_RESOLUTION_LOW",
745
792
  "MEDIA_RESOLUTION_MEDIUM",
@@ -750,8 +797,8 @@ var googleLanguageModelOptions = lazySchema2(
750
797
  *
751
798
  * https://ai.google.dev/gemini-api/docs/image-generation#aspect_ratios
752
799
  */
753
- imageConfig: z2.object({
754
- aspectRatio: z2.enum([
800
+ imageConfig: z3.object({
801
+ aspectRatio: z3.enum([
755
802
  "1:1",
756
803
  "2:3",
757
804
  "3:2",
@@ -767,12 +814,12 @@ var googleLanguageModelOptions = lazySchema2(
767
814
  "1:4",
768
815
  "4:1"
769
816
  ]).optional(),
770
- imageSize: z2.enum(["1K", "2K", "4K", "512"]).optional(),
817
+ imageSize: z3.enum(["1K", "2K", "4K", "512"]).optional(),
771
818
  /**
772
819
  * Optional. Controls the generation of people in images.
773
820
  * Vertex AI only.
774
821
  */
775
- personGeneration: z2.enum([
822
+ personGeneration: z3.enum([
776
823
  "PERSON_GENERATION_UNSPECIFIED",
777
824
  "ALLOW_ALL",
778
825
  "ALLOW_ADULT",
@@ -786,7 +833,7 @@ var googleLanguageModelOptions = lazySchema2(
786
833
  *
787
834
  * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerationConfig
788
835
  */
789
- prominentPeople: z2.enum([
836
+ prominentPeople: z3.enum([
790
837
  "PROMINENT_PEOPLE_UNSPECIFIED",
791
838
  "ALLOW_PROMINENT_PEOPLE",
792
839
  "BLOCK_PROMINENT_PEOPLE"
@@ -795,9 +842,9 @@ var googleLanguageModelOptions = lazySchema2(
795
842
  * Optional. The image output format for generated images.
796
843
  * Vertex AI only.
797
844
  */
798
- imageOutputOptions: z2.object({
799
- mimeType: z2.enum(["image/jpeg", "image/png"]).optional(),
800
- compressionQuality: z2.number().optional()
845
+ imageOutputOptions: z3.object({
846
+ mimeType: z3.enum(["image/jpeg", "image/png"]).optional(),
847
+ compressionQuality: z3.number().optional()
801
848
  }).optional()
802
849
  }).optional(),
803
850
  /**
@@ -806,10 +853,10 @@ var googleLanguageModelOptions = lazySchema2(
806
853
  *
807
854
  * https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
808
855
  */
809
- retrievalConfig: z2.object({
810
- latLng: z2.object({
811
- latitude: z2.number(),
812
- longitude: z2.number()
856
+ retrievalConfig: z3.object({
857
+ latLng: z3.object({
858
+ latitude: z3.number(),
859
+ longitude: z3.number()
813
860
  }).optional()
814
861
  }).optional(),
815
862
  /**
@@ -822,12 +869,12 @@ var googleLanguageModelOptions = lazySchema2(
822
869
  *
823
870
  * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
824
871
  */
825
- streamFunctionCallArguments: z2.boolean().optional(),
872
+ streamFunctionCallArguments: z3.boolean().optional(),
826
873
  /**
827
874
  * Optional. The service tier to use for the request. Sent as the
828
875
  * `serviceTier` body field. Gemini API only.
829
876
  */
830
- serviceTier: z2.enum(["standard", "flex", "priority"]).optional(),
877
+ serviceTier: z3.enum(["standard", "flex", "priority"]).optional(),
831
878
  /**
832
879
  * Optional. Vertex AI only. Sent as the
833
880
  * `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
@@ -838,7 +885,7 @@ var googleLanguageModelOptions = lazySchema2(
838
885
  * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
839
886
  * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/flex-paygo
840
887
  */
841
- sharedRequestType: z2.enum(["priority", "flex", "standard"]).optional(),
888
+ sharedRequestType: z3.enum(["priority", "flex", "standard"]).optional(),
842
889
  /**
843
890
  * Optional. Vertex AI only. Sent as the `X-Vertex-AI-LLM-Request-Type`
844
891
  * request header. Set to `'shared'` together with `sharedRequestType`
@@ -846,7 +893,7 @@ var googleLanguageModelOptions = lazySchema2(
846
893
  *
847
894
  * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
848
895
  */
849
- requestType: z2.enum(["shared"]).optional()
896
+ requestType: z3.enum(["shared"]).optional()
850
897
  })
851
898
  )
852
899
  );
@@ -1357,7 +1404,6 @@ function resolvePartialArgValue(arg) {
1357
1404
  const value = (_b = (_a = arg.stringValue) != null ? _a : arg.numberValue) != null ? _b : arg.boolValue;
1358
1405
  if (value != null) return { value, json: JSON.stringify(value) };
1359
1406
  if ("nullValue" in arg) return { value: null, json: "null" };
1360
- return void 0;
1361
1407
  }
1362
1408
 
1363
1409
  // src/map-google-finish-reason.ts
@@ -2465,195 +2511,195 @@ function extractSources({
2465
2511
  }
2466
2512
  return sources.length > 0 ? sources : void 0;
2467
2513
  }
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()
2514
+ var getGroundingMetadataSchema = () => z4.object({
2515
+ webSearchQueries: z4.array(z4.string()).nullish(),
2516
+ imageSearchQueries: z4.array(z4.string()).nullish(),
2517
+ retrievalQueries: z4.array(z4.string()).nullish(),
2518
+ searchEntryPoint: z4.object({ renderedContent: z4.string() }).nullish(),
2519
+ groundingChunks: z4.array(
2520
+ z4.object({
2521
+ web: z4.object({ uri: z4.string(), title: z4.string().nullish() }).nullish(),
2522
+ image: z4.object({
2523
+ sourceUri: z4.string(),
2524
+ imageUri: z4.string(),
2525
+ title: z4.string().nullish(),
2526
+ domain: z4.string().nullish()
2481
2527
  }).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()
2528
+ retrievedContext: z4.object({
2529
+ uri: z4.string().nullish(),
2530
+ title: z4.string().nullish(),
2531
+ text: z4.string().nullish(),
2532
+ fileSearchStore: z4.string().nullish()
2487
2533
  }).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()
2534
+ maps: z4.object({
2535
+ uri: z4.string().nullish(),
2536
+ title: z4.string().nullish(),
2537
+ text: z4.string().nullish(),
2538
+ placeId: z4.string().nullish()
2493
2539
  }).nullish()
2494
2540
  })
2495
2541
  ).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()
2542
+ groundingSupports: z4.array(
2543
+ z4.object({
2544
+ segment: z4.object({
2545
+ startIndex: z4.number().nullish(),
2546
+ endIndex: z4.number().nullish(),
2547
+ text: z4.string().nullish()
2502
2548
  }).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()
2549
+ segment_text: z4.string().nullish(),
2550
+ groundingChunkIndices: z4.array(z4.number()).nullish(),
2551
+ supportChunkIndices: z4.array(z4.number()).nullish(),
2552
+ confidenceScores: z4.array(z4.number()).nullish(),
2553
+ confidenceScore: z4.array(z4.number()).nullish()
2508
2554
  })
2509
2555
  ).nullish(),
2510
- retrievalMetadata: z3.union([
2511
- z3.object({
2512
- webDynamicRetrievalScore: z3.number()
2556
+ retrievalMetadata: z4.union([
2557
+ z4.object({
2558
+ webDynamicRetrievalScore: z4.number()
2513
2559
  }),
2514
- z3.object({})
2560
+ z4.object({})
2515
2561
  ]).nullish()
2516
2562
  });
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()
2563
+ var partialArgSchema = z4.object({
2564
+ jsonPath: z4.string(),
2565
+ stringValue: z4.string().nullish(),
2566
+ numberValue: z4.number().nullish(),
2567
+ boolValue: z4.boolean().nullish(),
2568
+ nullValue: z4.unknown().nullish(),
2569
+ willContinue: z4.boolean().nullish()
2524
2570
  });
2525
- var getContentSchema = () => z3.object({
2526
- parts: z3.array(
2527
- z3.union([
2571
+ var getContentSchema = () => z4.object({
2572
+ parts: z4.array(
2573
+ z4.union([
2528
2574
  // 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()
2575
+ z4.object({
2576
+ functionCall: z4.object({
2577
+ id: z4.string().nullish(),
2578
+ name: z4.string().nullish(),
2579
+ args: z4.unknown().nullish(),
2580
+ partialArgs: z4.array(partialArgSchema).nullish(),
2581
+ willContinue: z4.boolean().nullish()
2536
2582
  }),
2537
- thoughtSignature: z3.string().nullish()
2583
+ thoughtSignature: z4.string().nullish()
2538
2584
  }),
2539
- z3.object({
2540
- inlineData: z3.object({
2541
- mimeType: z3.string(),
2542
- data: z3.string()
2585
+ z4.object({
2586
+ inlineData: z4.object({
2587
+ mimeType: z4.string(),
2588
+ data: z4.string()
2543
2589
  }),
2544
- thought: z3.boolean().nullish(),
2545
- thoughtSignature: z3.string().nullish()
2590
+ thought: z4.boolean().nullish(),
2591
+ thoughtSignature: z4.string().nullish()
2546
2592
  }),
2547
- z3.object({
2548
- toolCall: z3.object({
2549
- toolType: z3.string(),
2550
- args: z3.unknown().nullish(),
2551
- id: z3.string()
2593
+ z4.object({
2594
+ toolCall: z4.object({
2595
+ toolType: z4.string(),
2596
+ args: z4.unknown().nullish(),
2597
+ id: z4.string()
2552
2598
  }),
2553
- thoughtSignature: z3.string().nullish()
2599
+ thoughtSignature: z4.string().nullish()
2554
2600
  }),
2555
- z3.object({
2556
- toolResponse: z3.object({
2557
- toolType: z3.string(),
2558
- response: z3.unknown().nullish(),
2559
- id: z3.string()
2601
+ z4.object({
2602
+ toolResponse: z4.object({
2603
+ toolType: z4.string(),
2604
+ response: z4.unknown().nullish(),
2605
+ id: z4.string()
2560
2606
  }),
2561
- thoughtSignature: z3.string().nullish()
2607
+ thoughtSignature: z4.string().nullish()
2562
2608
  }),
2563
- z3.object({
2564
- executableCode: z3.object({
2565
- language: z3.string(),
2566
- code: z3.string()
2609
+ z4.object({
2610
+ executableCode: z4.object({
2611
+ language: z4.string(),
2612
+ code: z4.string()
2567
2613
  }).nullish(),
2568
- codeExecutionResult: z3.object({
2569
- outcome: z3.string(),
2570
- output: z3.string().nullish()
2614
+ codeExecutionResult: z4.object({
2615
+ outcome: z4.string(),
2616
+ output: z4.string().nullish()
2571
2617
  }).nullish(),
2572
- text: z3.string().nullish(),
2573
- thought: z3.boolean().nullish(),
2574
- thoughtSignature: z3.string().nullish()
2618
+ text: z4.string().nullish(),
2619
+ thought: z4.boolean().nullish(),
2620
+ thoughtSignature: z4.string().nullish()
2575
2621
  })
2576
2622
  ])
2577
2623
  ).nullish()
2578
2624
  });
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()
2625
+ var getSafetyRatingSchema = () => z4.object({
2626
+ category: z4.string().nullish(),
2627
+ probability: z4.string().nullish(),
2628
+ probabilityScore: z4.number().nullish(),
2629
+ severity: z4.string().nullish(),
2630
+ severityScore: z4.number().nullish(),
2631
+ blocked: z4.boolean().nullish()
2586
2632
  });
2587
- var tokenDetailsSchema = z3.array(
2588
- z3.object({
2589
- modality: z3.string(),
2590
- tokenCount: z3.number()
2633
+ var tokenDetailsSchema = z4.array(
2634
+ z4.object({
2635
+ modality: z4.string(),
2636
+ tokenCount: z4.number()
2591
2637
  }).loose()
2592
2638
  ).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(),
2639
+ var usageSchema = z4.object({
2640
+ cachedContentTokenCount: z4.number().nullish(),
2641
+ thoughtsTokenCount: z4.number().nullish(),
2642
+ promptTokenCount: z4.number().nullish(),
2643
+ candidatesTokenCount: z4.number().nullish(),
2644
+ toolUsePromptTokenCount: z4.number().nullish(),
2645
+ totalTokenCount: z4.number().nullish(),
2600
2646
  // https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
2601
- trafficType: z3.string().nullish(),
2602
- serviceTier: z3.string().nullish(),
2647
+ trafficType: z4.string().nullish(),
2648
+ serviceTier: z4.string().nullish(),
2603
2649
  // https://ai.google.dev/api/generate-content#Modality
2604
2650
  promptTokensDetails: tokenDetailsSchema,
2605
2651
  cacheTokensDetails: tokenDetailsSchema,
2606
2652
  candidatesTokensDetails: tokenDetailsSchema,
2607
2653
  toolUsePromptTokensDetails: tokenDetailsSchema
2608
2654
  }).loose();
2609
- var getUrlContextMetadataSchema = () => z3.object({
2610
- urlMetadata: z3.array(
2611
- z3.object({
2612
- retrievedUrl: z3.string(),
2613
- urlRetrievalStatus: z3.string()
2655
+ var getUrlContextMetadataSchema = () => z4.object({
2656
+ urlMetadata: z4.array(
2657
+ z4.object({
2658
+ retrievedUrl: z4.string(),
2659
+ urlRetrievalStatus: z4.string()
2614
2660
  })
2615
2661
  ).nullish()
2616
2662
  });
2617
2663
  var responseSchema = lazySchema3(
2618
2664
  () => 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(),
2665
+ z4.object({
2666
+ responseId: z4.string().nullish(),
2667
+ candidates: z4.array(
2668
+ z4.object({
2669
+ content: getContentSchema().nullish().or(z4.object({}).strict()),
2670
+ finishReason: z4.string().nullish(),
2671
+ finishMessage: z4.string().nullish(),
2672
+ safetyRatings: z4.array(getSafetyRatingSchema()).nullish(),
2627
2673
  groundingMetadata: getGroundingMetadataSchema().nullish(),
2628
2674
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
2629
2675
  })
2630
2676
  ).nullish(),
2631
2677
  usageMetadata: usageSchema.nullish(),
2632
- promptFeedback: z3.object({
2633
- blockReason: z3.string().nullish(),
2634
- safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
2678
+ promptFeedback: z4.object({
2679
+ blockReason: z4.string().nullish(),
2680
+ safetyRatings: z4.array(getSafetyRatingSchema()).nullish()
2635
2681
  }).nullish()
2636
2682
  })
2637
2683
  )
2638
2684
  );
2639
2685
  var chunkSchema = lazySchema3(
2640
2686
  () => zodSchema3(
2641
- z3.object({
2642
- responseId: z3.string().nullish(),
2643
- candidates: z3.array(
2644
- z3.object({
2687
+ z4.object({
2688
+ responseId: z4.string().nullish(),
2689
+ candidates: z4.array(
2690
+ z4.object({
2645
2691
  content: getContentSchema().nullish(),
2646
- finishReason: z3.string().nullish(),
2647
- finishMessage: z3.string().nullish(),
2648
- safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
2692
+ finishReason: z4.string().nullish(),
2693
+ finishMessage: z4.string().nullish(),
2694
+ safetyRatings: z4.array(getSafetyRatingSchema()).nullish(),
2649
2695
  groundingMetadata: getGroundingMetadataSchema().nullish(),
2650
2696
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
2651
2697
  })
2652
2698
  ).nullish(),
2653
2699
  usageMetadata: usageSchema.nullish(),
2654
- promptFeedback: z3.object({
2655
- blockReason: z3.string().nullish(),
2656
- safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
2700
+ promptFeedback: z4.object({
2701
+ blockReason: z4.string().nullish(),
2702
+ safetyRatings: z4.array(getSafetyRatingSchema()).nullish()
2657
2703
  }).nullish()
2658
2704
  })
2659
2705
  )
@@ -2663,6 +2709,9 @@ function isConfirmedPromptBlockReason(blockReason) {
2663
2709
  }
2664
2710
 
2665
2711
  // src/google-speech-model.ts
2712
+ import {
2713
+ InvalidArgumentError
2714
+ } from "@ai-sdk/provider";
2666
2715
  import {
2667
2716
  combineHeaders as combineHeaders2,
2668
2717
  convertBase64ToUint8Array,
@@ -2677,18 +2726,18 @@ import {
2677
2726
 
2678
2727
  // src/google-speech-api.ts
2679
2728
  import { lazySchema as lazySchema4, zodSchema as zodSchema4 } from "@ai-sdk/provider-utils";
2680
- import { z as z4 } from "zod/v4";
2729
+ import { z as z5 } from "zod/v4";
2681
2730
  var googleSpeechResponseSchema = lazySchema4(
2682
2731
  () => 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()
2732
+ z5.object({
2733
+ candidates: z5.array(
2734
+ z5.object({
2735
+ content: z5.object({
2736
+ parts: z5.array(
2737
+ z5.object({
2738
+ inlineData: z5.object({
2739
+ mimeType: z5.string().nullish(),
2740
+ data: z5.string().nullish()
2692
2741
  }).nullish()
2693
2742
  })
2694
2743
  ).nullish()
@@ -2699,32 +2748,82 @@ var googleSpeechResponseSchema = lazySchema4(
2699
2748
  )
2700
2749
  );
2701
2750
 
2751
+ // src/google-speech-input.ts
2752
+ function getGoogleSpeechInput({
2753
+ text,
2754
+ voice,
2755
+ providerOptions
2756
+ }) {
2757
+ const google = providerOptions == null ? void 0 : providerOptions.google;
2758
+ const options = google != null && typeof google === "object" ? google : void 0;
2759
+ const turns = options && "turns" in options ? options.turns : void 0;
2760
+ const turnTexts = [];
2761
+ if (Array.isArray(turns) && turns.length > 0) {
2762
+ for (const turn of turns) {
2763
+ if (turn == null || typeof turn !== "object" || !("text" in turn) || typeof turn.text !== "string") {
2764
+ break;
2765
+ }
2766
+ turnTexts.push(turn.text);
2767
+ }
2768
+ if (turnTexts.length === turns.length) {
2769
+ text = turnTexts.join("");
2770
+ }
2771
+ }
2772
+ const config = options && "multiSpeakerVoiceConfig" in options ? options.multiSpeakerVoiceConfig : void 0;
2773
+ const speakers = config != null && typeof config === "object" && "speakerVoiceConfigs" in config && Array.isArray(config.speakerVoiceConfigs) ? config.speakerVoiceConfigs : [];
2774
+ return {
2775
+ text,
2776
+ usesCustomVoice: (voice == null ? void 0 : voice.startsWith("voice_")) === true || (voice == null ? void 0 : voice.startsWith("voicekey_")) === true || speakers.some(
2777
+ (speaker) => speaker != null && typeof speaker === "object" && "voiceConfig" in speaker && speaker.voiceConfig != null && typeof speaker.voiceConfig === "object" && "voice" in speaker.voiceConfig
2778
+ )
2779
+ };
2780
+ }
2781
+
2702
2782
  // src/google-speech-model-options.ts
2703
2783
  import {
2704
2784
  lazySchema as lazySchema5,
2705
2785
  zodSchema as zodSchema5
2706
2786
  } from "@ai-sdk/provider-utils";
2707
- import { z as z5 } from "zod/v4";
2708
- var prebuiltVoiceConfigSchema = z5.object({
2709
- voiceName: z5.string()
2787
+ import { z as z6 } from "zod/v4";
2788
+ var prebuiltVoiceConfigSchema = z6.object({
2789
+ voiceName: z6.string()
2790
+ });
2791
+ var voiceConfigSchema = z6.object({
2792
+ prebuiltVoiceConfig: prebuiltVoiceConfigSchema,
2793
+ voice: z6.never().optional()
2710
2794
  });
2711
- var voiceConfigSchema = z5.object({
2712
- prebuiltVoiceConfig: prebuiltVoiceConfigSchema
2795
+ var speechMetadataSchema = z6.object({
2796
+ speaker: z6.string().min(1).optional(),
2797
+ style: z6.string().optional()
2713
2798
  });
2714
2799
  var googleSpeechProviderOptionsSchema = lazySchema5(
2715
2800
  () => zodSchema5(
2716
- z5.object({
2801
+ z6.object({
2802
+ /** Turn-level directions for the top-level text, for Gemini 3.8 TTS. */
2803
+ speechMetadata: speechMetadataSchema.optional(),
2804
+ /**
2805
+ * Structured transcript for Gemini 3.8 TTS. Replaces the top-level text;
2806
+ * pass text: '' when using turns. Each multi-speaker turn must name a
2807
+ * configured speaker in speechMetadata. Per-turn styles override instructions.
2808
+ */
2809
+ turns: z6.array(
2810
+ z6.object({
2811
+ text: z6.string(),
2812
+ speechMetadata: speechMetadataSchema.optional()
2813
+ })
2814
+ ).min(1).optional(),
2717
2815
  /**
2718
2816
  * Multi-speaker configuration for dialogue audio. When provided, this
2719
2817
  * 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.
2818
+ * speakers. For Gemini 3.8, each turn's speechMetadata.speaker must match
2819
+ * a configured speaker; older models use speaker labels in the text.
2721
2820
  *
2722
2821
  * https://ai.google.dev/gemini-api/docs/speech-generation#multi-speaker
2723
2822
  */
2724
- multiSpeakerVoiceConfig: z5.object({
2725
- speakerVoiceConfigs: z5.array(
2726
- z5.object({
2727
- speaker: z5.string(),
2823
+ multiSpeakerVoiceConfig: z6.object({
2824
+ speakerVoiceConfigs: z6.array(
2825
+ z6.object({
2826
+ speaker: z6.string(),
2728
2827
  voiceConfig: voiceConfigSchema
2729
2828
  })
2730
2829
  )
@@ -2763,6 +2862,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2763
2862
  language,
2764
2863
  providerOptions
2765
2864
  }) {
2865
+ var _a;
2766
2866
  const warnings = [];
2767
2867
  const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
2768
2868
  let googleOptions;
@@ -2783,10 +2883,22 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2783
2883
  schema: googleSpeechProviderOptionsSchema
2784
2884
  });
2785
2885
  }
2886
+ const usesStructuredSpeech = !this.modelId.startsWith("gemini-2.5-") && !this.modelId.startsWith("gemini-3.1-");
2887
+ const input = getGoogleSpeechInput({
2888
+ text,
2889
+ voice,
2890
+ providerOptions: { google: googleOptions }
2891
+ });
2892
+ if (input.usesCustomVoice) {
2893
+ throw new InvalidArgumentError({
2894
+ argument: "voice",
2895
+ message: "Custom voices are not supported. Use a prebuilt voice instead."
2896
+ });
2897
+ }
2786
2898
  const multiSpeakerVoiceConfig = googleOptions == null ? void 0 : googleOptions.multiSpeakerVoiceConfig;
2787
2899
  const speechConfig = multiSpeakerVoiceConfig ? { multiSpeakerVoiceConfig } : { voiceConfig: { prebuiltVoiceConfig: { voiceName: voice } } };
2788
2900
  let promptText = text;
2789
- if (instructions != null) {
2901
+ if (instructions != null && !usesStructuredSpeech) {
2790
2902
  if (multiSpeakerVoiceConfig) {
2791
2903
  warnings.push({
2792
2904
  type: "unsupported",
@@ -2797,6 +2909,52 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2797
2909
  promptText = `${instructions}: ${text}`;
2798
2910
  }
2799
2911
  }
2912
+ let parts = [{ text: promptText }];
2913
+ if (usesStructuredSpeech) {
2914
+ if ((googleOptions == null ? void 0 : googleOptions.turns) && googleOptions.speechMetadata) {
2915
+ throw new InvalidArgumentError({
2916
+ argument: "providerOptions",
2917
+ message: "Set speechMetadata on each turn when using turns."
2918
+ });
2919
+ }
2920
+ if ((googleOptions == null ? void 0 : googleOptions.turns) && text !== "") {
2921
+ warnings.push({
2922
+ type: "unsupported",
2923
+ feature: "text",
2924
+ details: "Google TTS turns replace the top-level text."
2925
+ });
2926
+ }
2927
+ parts = ((_a = googleOptions == null ? void 0 : googleOptions.turns) != null ? _a : [
2928
+ { text, speechMetadata: googleOptions == null ? void 0 : googleOptions.speechMetadata }
2929
+ ]).map((part) => {
2930
+ var _a2, _b, _c;
2931
+ const style = (_b = (_a2 = part.speechMetadata) == null ? void 0 : _a2.style) != null ? _b : instructions;
2932
+ const speaker = (_c = part.speechMetadata) == null ? void 0 : _c.speaker;
2933
+ if (multiSpeakerVoiceConfig && !multiSpeakerVoiceConfig.speakerVoiceConfigs.some(
2934
+ (config) => config.speaker === speaker
2935
+ )) {
2936
+ throw new InvalidArgumentError({
2937
+ argument: "speechMetadata.speaker",
2938
+ message: "Every multi-speaker turn must specify a speechMetadata.speaker matching a configured speaker."
2939
+ });
2940
+ }
2941
+ return {
2942
+ text: part.text,
2943
+ ...style != null || speaker != null ? { speechMetadata: { style, speaker } } : {}
2944
+ };
2945
+ });
2946
+ } else if ((googleOptions == null ? void 0 : googleOptions.turns) || (googleOptions == null ? void 0 : googleOptions.speechMetadata)) {
2947
+ throw new InvalidArgumentError({
2948
+ argument: "providerOptions",
2949
+ message: "Structured speech metadata and turns require Gemini 3.8 TTS."
2950
+ });
2951
+ }
2952
+ if (input.text.length === 0) {
2953
+ throw new InvalidArgumentError({
2954
+ argument: "text",
2955
+ message: "Speech input must contain a non-empty transcript."
2956
+ });
2957
+ }
2800
2958
  if (speed != null) {
2801
2959
  warnings.push({
2802
2960
  type: "unsupported",
@@ -2811,10 +2969,20 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2811
2969
  details: "Google Gemini TTS models do not support the `language` option. Language is detected automatically from the input text."
2812
2970
  });
2813
2971
  }
2972
+ const formats = usesStructuredSpeech ? {
2973
+ wav: "AUDIO_WAV",
2974
+ "audio/wav": "AUDIO_WAV",
2975
+ pcm: "AUDIO_L16",
2976
+ "audio/l16": "AUDIO_L16",
2977
+ mulaw: "AUDIO_MULAW",
2978
+ "audio/mulaw": "AUDIO_MULAW",
2979
+ alaw: "AUDIO_ALAW",
2980
+ "audio/alaw": "AUDIO_ALAW"
2981
+ } : { wav: "AUDIO_WAV", pcm: "AUDIO_L16" };
2814
2982
  let resolvedOutputFormat = "wav";
2815
- if (outputFormat === "pcm") {
2816
- resolvedOutputFormat = "pcm";
2817
- } else if (outputFormat != null && outputFormat !== "wav") {
2983
+ if (outputFormat != null && Object.prototype.hasOwnProperty.call(formats, outputFormat)) {
2984
+ resolvedOutputFormat = outputFormat;
2985
+ } else if (outputFormat != null) {
2818
2986
  warnings.push({
2819
2987
  type: "unsupported",
2820
2988
  feature: "outputFormat",
@@ -2822,18 +2990,28 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2822
2990
  });
2823
2991
  }
2824
2992
  const requestBody = {
2825
- contents: [{ role: "user", parts: [{ text: promptText }] }],
2993
+ contents: [{ role: "user", parts }],
2826
2994
  generationConfig: {
2827
2995
  responseModalities: ["AUDIO"],
2828
- speechConfig
2996
+ speechConfig,
2997
+ ...usesStructuredSpeech && outputFormat != null ? {
2998
+ responseFormat: {
2999
+ audio: { mimeType: formats[resolvedOutputFormat] }
3000
+ }
3001
+ } : {}
2829
3002
  }
2830
3003
  };
2831
- return { requestBody, warnings, outputFormat: resolvedOutputFormat };
3004
+ return {
3005
+ requestBody,
3006
+ warnings,
3007
+ outputFormat: formats[resolvedOutputFormat],
3008
+ usesStructuredSpeech
3009
+ };
2832
3010
  }
2833
3011
  async doGenerate(options) {
2834
3012
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2835
3013
  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);
3014
+ const { requestBody, warnings, outputFormat, usesStructuredSpeech } = await this.getArgs(options);
2837
3015
  const {
2838
3016
  value: response,
2839
3017
  responseHeaders,
@@ -2867,9 +3045,10 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
2867
3045
  }
2868
3046
  }
2869
3047
  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) {
3048
+ const bytes = base64Audio != null ? convertBase64ToUint8Array(base64Audio) : new Uint8Array(0);
3049
+ const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType != null ? mimeType : "") || mimeType == null && !usesStructuredSpeech;
3050
+ const audio = outputFormat === "AUDIO_WAV" && isPcm && bytes.length > 0 ? addWavHeader(bytes, sampleRate) : bytes;
3051
+ if (outputFormat === "AUDIO_L16" && bytes.length > 0 && !usesStructuredSpeech) {
2873
3052
  warnings.push({
2874
3053
  type: "unsupported",
2875
3054
  feature: "outputFormat",
@@ -2935,21 +3114,6 @@ function writeAscii(view, offset, text) {
2935
3114
  }
2936
3115
  }
2937
3116
 
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
3117
  // src/tool/enterprise-web-search.ts
2954
3118
  import {
2955
3119
  createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
@@ -6201,6 +6365,7 @@ export {
6201
6365
  GoogleInteractionsLanguageModel,
6202
6366
  GoogleLanguageModel,
6203
6367
  GoogleSpeechModel,
6368
+ getGoogleSpeechInput,
6204
6369
  getGroundingMetadataSchema,
6205
6370
  getUrlContextMetadataSchema,
6206
6371
  googleTools,