@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.
- package/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +588 -398
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +26 -2
- package/dist/internal/index.js +385 -220
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +96 -25
- package/package.json +2 -2
- package/src/convert-to-google-messages.ts +54 -1
- package/src/google-embedding-model.ts +39 -8
- package/src/google-json-accumulator.ts +0 -1
- package/src/google-prompt.ts +12 -0
- package/src/google-speech-api.ts +2 -1
- package/src/google-speech-input.ts +64 -0
- package/src/google-speech-model-options.ts +28 -1
- package/src/google-speech-model.ts +137 -25
- package/src/internal/index.ts +1 -0
- package/src/tool/code-execution.ts +14 -10
package/dist/internal/index.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
611
|
-
error:
|
|
612
|
-
code:
|
|
613
|
-
message:
|
|
614
|
-
status:
|
|
615
|
-
details:
|
|
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
|
|
715
|
+
import { z as z3 } from "zod/v4";
|
|
669
716
|
var googleLanguageModelOptions = lazySchema2(
|
|
670
717
|
() => zodSchema2(
|
|
671
|
-
|
|
672
|
-
responseModalities:
|
|
673
|
-
thinkingConfig:
|
|
674
|
-
thinkingBudget:
|
|
675
|
-
includeThoughts:
|
|
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:
|
|
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:
|
|
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:
|
|
740
|
+
structuredOutputs: z3.boolean().optional(),
|
|
694
741
|
/**
|
|
695
742
|
* Optional. A list of unique safety settings for blocking unsafe content.
|
|
696
743
|
*/
|
|
697
|
-
safetySettings:
|
|
698
|
-
|
|
699
|
-
category:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
754
|
-
aspectRatio:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
799
|
-
mimeType:
|
|
800
|
-
compressionQuality:
|
|
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:
|
|
810
|
-
latLng:
|
|
811
|
-
latitude:
|
|
812
|
-
longitude:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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 = () =>
|
|
2469
|
-
webSearchQueries:
|
|
2470
|
-
imageSearchQueries:
|
|
2471
|
-
retrievalQueries:
|
|
2472
|
-
searchEntryPoint:
|
|
2473
|
-
groundingChunks:
|
|
2474
|
-
|
|
2475
|
-
web:
|
|
2476
|
-
image:
|
|
2477
|
-
sourceUri:
|
|
2478
|
-
imageUri:
|
|
2479
|
-
title:
|
|
2480
|
-
domain:
|
|
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:
|
|
2483
|
-
uri:
|
|
2484
|
-
title:
|
|
2485
|
-
text:
|
|
2486
|
-
fileSearchStore:
|
|
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:
|
|
2489
|
-
uri:
|
|
2490
|
-
title:
|
|
2491
|
-
text:
|
|
2492
|
-
placeId:
|
|
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:
|
|
2497
|
-
|
|
2498
|
-
segment:
|
|
2499
|
-
startIndex:
|
|
2500
|
-
endIndex:
|
|
2501
|
-
text:
|
|
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:
|
|
2504
|
-
groundingChunkIndices:
|
|
2505
|
-
supportChunkIndices:
|
|
2506
|
-
confidenceScores:
|
|
2507
|
-
confidenceScore:
|
|
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:
|
|
2511
|
-
|
|
2512
|
-
webDynamicRetrievalScore:
|
|
2556
|
+
retrievalMetadata: z4.union([
|
|
2557
|
+
z4.object({
|
|
2558
|
+
webDynamicRetrievalScore: z4.number()
|
|
2513
2559
|
}),
|
|
2514
|
-
|
|
2560
|
+
z4.object({})
|
|
2515
2561
|
]).nullish()
|
|
2516
2562
|
});
|
|
2517
|
-
var partialArgSchema =
|
|
2518
|
-
jsonPath:
|
|
2519
|
-
stringValue:
|
|
2520
|
-
numberValue:
|
|
2521
|
-
boolValue:
|
|
2522
|
-
nullValue:
|
|
2523
|
-
willContinue:
|
|
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 = () =>
|
|
2526
|
-
parts:
|
|
2527
|
-
|
|
2571
|
+
var getContentSchema = () => z4.object({
|
|
2572
|
+
parts: z4.array(
|
|
2573
|
+
z4.union([
|
|
2528
2574
|
// note: order matters since text can be fully empty
|
|
2529
|
-
|
|
2530
|
-
functionCall:
|
|
2531
|
-
id:
|
|
2532
|
-
name:
|
|
2533
|
-
args:
|
|
2534
|
-
partialArgs:
|
|
2535
|
-
willContinue:
|
|
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:
|
|
2583
|
+
thoughtSignature: z4.string().nullish()
|
|
2538
2584
|
}),
|
|
2539
|
-
|
|
2540
|
-
inlineData:
|
|
2541
|
-
mimeType:
|
|
2542
|
-
data:
|
|
2585
|
+
z4.object({
|
|
2586
|
+
inlineData: z4.object({
|
|
2587
|
+
mimeType: z4.string(),
|
|
2588
|
+
data: z4.string()
|
|
2543
2589
|
}),
|
|
2544
|
-
thought:
|
|
2545
|
-
thoughtSignature:
|
|
2590
|
+
thought: z4.boolean().nullish(),
|
|
2591
|
+
thoughtSignature: z4.string().nullish()
|
|
2546
2592
|
}),
|
|
2547
|
-
|
|
2548
|
-
toolCall:
|
|
2549
|
-
toolType:
|
|
2550
|
-
args:
|
|
2551
|
-
id:
|
|
2593
|
+
z4.object({
|
|
2594
|
+
toolCall: z4.object({
|
|
2595
|
+
toolType: z4.string(),
|
|
2596
|
+
args: z4.unknown().nullish(),
|
|
2597
|
+
id: z4.string()
|
|
2552
2598
|
}),
|
|
2553
|
-
thoughtSignature:
|
|
2599
|
+
thoughtSignature: z4.string().nullish()
|
|
2554
2600
|
}),
|
|
2555
|
-
|
|
2556
|
-
toolResponse:
|
|
2557
|
-
toolType:
|
|
2558
|
-
response:
|
|
2559
|
-
id:
|
|
2601
|
+
z4.object({
|
|
2602
|
+
toolResponse: z4.object({
|
|
2603
|
+
toolType: z4.string(),
|
|
2604
|
+
response: z4.unknown().nullish(),
|
|
2605
|
+
id: z4.string()
|
|
2560
2606
|
}),
|
|
2561
|
-
thoughtSignature:
|
|
2607
|
+
thoughtSignature: z4.string().nullish()
|
|
2562
2608
|
}),
|
|
2563
|
-
|
|
2564
|
-
executableCode:
|
|
2565
|
-
language:
|
|
2566
|
-
code:
|
|
2609
|
+
z4.object({
|
|
2610
|
+
executableCode: z4.object({
|
|
2611
|
+
language: z4.string(),
|
|
2612
|
+
code: z4.string()
|
|
2567
2613
|
}).nullish(),
|
|
2568
|
-
codeExecutionResult:
|
|
2569
|
-
outcome:
|
|
2570
|
-
output:
|
|
2614
|
+
codeExecutionResult: z4.object({
|
|
2615
|
+
outcome: z4.string(),
|
|
2616
|
+
output: z4.string().nullish()
|
|
2571
2617
|
}).nullish(),
|
|
2572
|
-
text:
|
|
2573
|
-
thought:
|
|
2574
|
-
thoughtSignature:
|
|
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 = () =>
|
|
2580
|
-
category:
|
|
2581
|
-
probability:
|
|
2582
|
-
probabilityScore:
|
|
2583
|
-
severity:
|
|
2584
|
-
severityScore:
|
|
2585
|
-
blocked:
|
|
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 =
|
|
2588
|
-
|
|
2589
|
-
modality:
|
|
2590
|
-
tokenCount:
|
|
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 =
|
|
2594
|
-
cachedContentTokenCount:
|
|
2595
|
-
thoughtsTokenCount:
|
|
2596
|
-
promptTokenCount:
|
|
2597
|
-
candidatesTokenCount:
|
|
2598
|
-
toolUsePromptTokenCount:
|
|
2599
|
-
totalTokenCount:
|
|
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:
|
|
2602
|
-
serviceTier:
|
|
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 = () =>
|
|
2610
|
-
urlMetadata:
|
|
2611
|
-
|
|
2612
|
-
retrievedUrl:
|
|
2613
|
-
urlRetrievalStatus:
|
|
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
|
-
|
|
2620
|
-
responseId:
|
|
2621
|
-
candidates:
|
|
2622
|
-
|
|
2623
|
-
content: getContentSchema().nullish().or(
|
|
2624
|
-
finishReason:
|
|
2625
|
-
finishMessage:
|
|
2626
|
-
safetyRatings:
|
|
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:
|
|
2633
|
-
blockReason:
|
|
2634
|
-
safetyRatings:
|
|
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
|
-
|
|
2642
|
-
responseId:
|
|
2643
|
-
candidates:
|
|
2644
|
-
|
|
2687
|
+
z4.object({
|
|
2688
|
+
responseId: z4.string().nullish(),
|
|
2689
|
+
candidates: z4.array(
|
|
2690
|
+
z4.object({
|
|
2645
2691
|
content: getContentSchema().nullish(),
|
|
2646
|
-
finishReason:
|
|
2647
|
-
finishMessage:
|
|
2648
|
-
safetyRatings:
|
|
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:
|
|
2655
|
-
blockReason:
|
|
2656
|
-
safetyRatings:
|
|
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
|
|
2729
|
+
import { z as z5 } from "zod/v4";
|
|
2681
2730
|
var googleSpeechResponseSchema = lazySchema4(
|
|
2682
2731
|
() => zodSchema4(
|
|
2683
|
-
|
|
2684
|
-
candidates:
|
|
2685
|
-
|
|
2686
|
-
content:
|
|
2687
|
-
parts:
|
|
2688
|
-
|
|
2689
|
-
inlineData:
|
|
2690
|
-
mimeType:
|
|
2691
|
-
data:
|
|
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
|
|
2708
|
-
var prebuiltVoiceConfigSchema =
|
|
2709
|
-
voiceName:
|
|
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
|
|
2712
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
2725
|
-
speakerVoiceConfigs:
|
|
2726
|
-
|
|
2727
|
-
speaker:
|
|
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
|
|
2816
|
-
resolvedOutputFormat =
|
|
2817
|
-
} else if (outputFormat != null
|
|
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
|
|
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 {
|
|
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
|
|
2871
|
-
const
|
|
2872
|
-
|
|
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,
|