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