@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/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import { Experimental_EvaluationLanguageModel as EvaluationLanguageModel } from "@ai-sdk/provider-utils/experimental-evaluation";
|
|
9
9
|
|
|
10
10
|
// src/version.ts
|
|
11
|
-
var VERSION = true ? "4.0.
|
|
11
|
+
var VERSION = true ? "4.0.79" : "0.0.0-test";
|
|
12
12
|
|
|
13
13
|
// src/google-embedding-model.ts
|
|
14
14
|
import {
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import {
|
|
18
18
|
combineHeaders,
|
|
19
19
|
createJsonResponseHandler,
|
|
20
|
+
EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER,
|
|
20
21
|
lazySchema as lazySchema3,
|
|
21
22
|
parseProviderOptions,
|
|
22
23
|
postJsonToApi,
|
|
@@ -118,15 +119,34 @@ var googleEmbeddingModelOptions = lazySchema2(
|
|
|
118
119
|
);
|
|
119
120
|
|
|
120
121
|
// src/google-embedding-model.ts
|
|
122
|
+
var _a;
|
|
121
123
|
var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
122
124
|
constructor(modelId, config) {
|
|
123
125
|
this.specificationVersion = "v4";
|
|
124
126
|
this.maxEmbeddingsPerCall = 100;
|
|
125
127
|
this.supportsParallelCalls = true;
|
|
128
|
+
this[_a] = ({ providerOptions, values, startIndex, endIndex }) => {
|
|
129
|
+
var _a2;
|
|
130
|
+
const multimodalContent = (_a2 = providerOptions == null ? void 0 : providerOptions.google) == null ? void 0 : _a2.content;
|
|
131
|
+
if (!Array.isArray(multimodalContent)) {
|
|
132
|
+
return providerOptions;
|
|
133
|
+
}
|
|
134
|
+
validateMultimodalContentLength({
|
|
135
|
+
multimodalContent,
|
|
136
|
+
values
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
...providerOptions,
|
|
140
|
+
google: {
|
|
141
|
+
...providerOptions == null ? void 0 : providerOptions.google,
|
|
142
|
+
content: multimodalContent.slice(startIndex, endIndex)
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
};
|
|
126
146
|
this.modelId = modelId;
|
|
127
147
|
this.config = config;
|
|
128
148
|
}
|
|
129
|
-
static [WORKFLOW_SERIALIZE](model) {
|
|
149
|
+
static [(_a = EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, WORKFLOW_SERIALIZE)](model) {
|
|
130
150
|
return serializeModelOptions({
|
|
131
151
|
modelId: model.modelId,
|
|
132
152
|
config: model.config
|
|
@@ -162,11 +182,7 @@ var GoogleEmbeddingModel = class _GoogleEmbeddingModel {
|
|
|
162
182
|
headers
|
|
163
183
|
);
|
|
164
184
|
const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
|
|
165
|
-
|
|
166
|
-
throw new Error(
|
|
167
|
-
`The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
|
|
168
|
-
);
|
|
169
|
-
}
|
|
185
|
+
validateMultimodalContentLength({ multimodalContent, values });
|
|
170
186
|
if (values.length === 1) {
|
|
171
187
|
const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
|
|
172
188
|
const textPart = values[0] ? [{ text: values[0] }] : [];
|
|
@@ -251,6 +267,16 @@ var googleGenerativeAISingleEmbeddingResponseSchema = lazySchema3(
|
|
|
251
267
|
})
|
|
252
268
|
)
|
|
253
269
|
);
|
|
270
|
+
function validateMultimodalContentLength({
|
|
271
|
+
multimodalContent,
|
|
272
|
+
values
|
|
273
|
+
}) {
|
|
274
|
+
if (multimodalContent != null && multimodalContent.length !== values.length) {
|
|
275
|
+
throw new Error(
|
|
276
|
+
`The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
254
280
|
|
|
255
281
|
// src/google-batch.ts
|
|
256
282
|
import {
|
|
@@ -275,7 +301,7 @@ import {
|
|
|
275
301
|
zodSchema as zodSchema8,
|
|
276
302
|
convertToBase64 as convertToBase642
|
|
277
303
|
} from "@ai-sdk/provider-utils";
|
|
278
|
-
import { z as
|
|
304
|
+
import { z as z9 } from "zod/v4";
|
|
279
305
|
|
|
280
306
|
// src/get-model-path.ts
|
|
281
307
|
function getModelPath(modelId) {
|
|
@@ -301,16 +327,16 @@ import {
|
|
|
301
327
|
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2,
|
|
302
328
|
zodSchema as zodSchema5
|
|
303
329
|
} from "@ai-sdk/provider-utils";
|
|
304
|
-
import { z as
|
|
330
|
+
import { z as z6 } from "zod/v4";
|
|
305
331
|
|
|
306
332
|
// src/convert-google-usage.ts
|
|
307
333
|
import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
|
|
308
334
|
function convertGoogleUsage(usage) {
|
|
309
|
-
var
|
|
335
|
+
var _a2, _b, _c, _d, _e;
|
|
310
336
|
if (usage == null) {
|
|
311
337
|
return createNullLanguageModelUsage();
|
|
312
338
|
}
|
|
313
|
-
const promptTokens = (
|
|
339
|
+
const promptTokens = (_a2 = usage.promptTokenCount) != null ? _a2 : 0;
|
|
314
340
|
const candidatesTokens = (_b = usage.candidatesTokenCount) != null ? _b : 0;
|
|
315
341
|
const toolUsePromptTokens = (_c = usage.toolUsePromptTokenCount) != null ? _c : 0;
|
|
316
342
|
const cachedContentTokens = (_d = usage.cachedContentTokenCount) != null ? _d : 0;
|
|
@@ -344,6 +370,25 @@ import {
|
|
|
344
370
|
resolveProviderReference,
|
|
345
371
|
secureJsonParse
|
|
346
372
|
} from "@ai-sdk/provider-utils";
|
|
373
|
+
|
|
374
|
+
// src/tool/code-execution.ts
|
|
375
|
+
import { createProviderExecutedToolFactory } from "@ai-sdk/provider-utils";
|
|
376
|
+
import { z as z4 } from "zod/v4";
|
|
377
|
+
var codeExecutionInputSchema = z4.object({
|
|
378
|
+
language: z4.string().describe("The programming language of the code."),
|
|
379
|
+
code: z4.string().describe("The code to be executed.")
|
|
380
|
+
});
|
|
381
|
+
var codeExecutionOutputSchema = z4.object({
|
|
382
|
+
outcome: z4.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
|
|
383
|
+
output: z4.string().describe("The output from the code execution.")
|
|
384
|
+
});
|
|
385
|
+
var codeExecution = createProviderExecutedToolFactory({
|
|
386
|
+
id: "google.code_execution",
|
|
387
|
+
inputSchema: codeExecutionInputSchema,
|
|
388
|
+
outputSchema: codeExecutionOutputSchema
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// src/convert-to-google-messages.ts
|
|
347
392
|
var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
|
|
348
393
|
var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
|
|
349
394
|
function parseBase64DataUrl(value) {
|
|
@@ -458,11 +503,11 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, i
|
|
|
458
503
|
}
|
|
459
504
|
}
|
|
460
505
|
function convertToGoogleMessages(prompt, options) {
|
|
461
|
-
var
|
|
506
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
462
507
|
const systemInstructionParts = [];
|
|
463
508
|
const contents = [];
|
|
464
509
|
let systemMessagesAllowed = true;
|
|
465
|
-
const isGemmaModel = (
|
|
510
|
+
const isGemmaModel = (_a2 = options == null ? void 0 : options.isGemmaModel) != null ? _a2 : false;
|
|
466
511
|
const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
|
|
467
512
|
const onWarning = options == null ? void 0 : options.onWarning;
|
|
468
513
|
const providerOptionsNames = (_c = options == null ? void 0 : options.providerOptionsNames) != null ? _c : ["google"];
|
|
@@ -477,9 +522,9 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
477
522
|
return SKIP_THOUGHT_SIGNATURE_VALIDATOR;
|
|
478
523
|
};
|
|
479
524
|
const readProviderOpts = (part) => {
|
|
480
|
-
var
|
|
525
|
+
var _a3, _b2, _c2, _d2, _e2;
|
|
481
526
|
for (const name of providerOptionsNames) {
|
|
482
|
-
const v = (
|
|
527
|
+
const v = (_a3 = part.providerOptions) == null ? void 0 : _a3[name];
|
|
483
528
|
if (v != null) return v;
|
|
484
529
|
}
|
|
485
530
|
if (isVertexLike) {
|
|
@@ -656,6 +701,13 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
656
701
|
break;
|
|
657
702
|
}
|
|
658
703
|
case "tool-call": {
|
|
704
|
+
if (part.providerExecuted === true && part.toolName === "code_execution") {
|
|
705
|
+
return {
|
|
706
|
+
executableCode: codeExecutionInputSchema.parse(
|
|
707
|
+
typeof part.input === "string" ? secureJsonParse(part.input) : part.input
|
|
708
|
+
)
|
|
709
|
+
};
|
|
710
|
+
}
|
|
659
711
|
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
660
712
|
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
661
713
|
const isServerToolCall = serverToolCallId != null && serverToolType != null;
|
|
@@ -690,6 +742,13 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
690
742
|
};
|
|
691
743
|
}
|
|
692
744
|
case "tool-result": {
|
|
745
|
+
if (part.toolName === "code_execution" && part.output.type === "json") {
|
|
746
|
+
return {
|
|
747
|
+
codeExecutionResult: codeExecutionOutputSchema.parse(
|
|
748
|
+
part.output.value
|
|
749
|
+
)
|
|
750
|
+
};
|
|
751
|
+
}
|
|
693
752
|
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
694
753
|
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
695
754
|
if (serverToolCallId && serverToolType) {
|
|
@@ -920,23 +979,23 @@ import {
|
|
|
920
979
|
lazySchema as lazySchema4,
|
|
921
980
|
zodSchema as zodSchema4
|
|
922
981
|
} from "@ai-sdk/provider-utils";
|
|
923
|
-
import { z as
|
|
982
|
+
import { z as z5 } from "zod/v4";
|
|
924
983
|
var googleLanguageModelOptions = lazySchema4(
|
|
925
984
|
() => zodSchema4(
|
|
926
|
-
|
|
927
|
-
responseModalities:
|
|
928
|
-
thinkingConfig:
|
|
929
|
-
thinkingBudget:
|
|
930
|
-
includeThoughts:
|
|
985
|
+
z5.object({
|
|
986
|
+
responseModalities: z5.array(z5.enum(["TEXT", "IMAGE"])).optional(),
|
|
987
|
+
thinkingConfig: z5.object({
|
|
988
|
+
thinkingBudget: z5.number().optional(),
|
|
989
|
+
includeThoughts: z5.boolean().optional(),
|
|
931
990
|
// https://ai.google.dev/gemini-api/docs/gemini-3?thinking=high#thinking_level
|
|
932
|
-
thinkingLevel:
|
|
991
|
+
thinkingLevel: z5.enum(["minimal", "low", "medium", "high"]).optional()
|
|
933
992
|
}).optional(),
|
|
934
993
|
/**
|
|
935
994
|
* Optional.
|
|
936
995
|
* The name of the cached content used as context to serve the prediction.
|
|
937
996
|
* Format: cachedContents/{cachedContent}
|
|
938
997
|
*/
|
|
939
|
-
cachedContent:
|
|
998
|
+
cachedContent: z5.string().optional(),
|
|
940
999
|
/**
|
|
941
1000
|
* Optional. Enable structured output. Default is true.
|
|
942
1001
|
*
|
|
@@ -945,13 +1004,13 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
945
1004
|
* Google uses. You can use this to disable
|
|
946
1005
|
* structured outputs if you need to.
|
|
947
1006
|
*/
|
|
948
|
-
structuredOutputs:
|
|
1007
|
+
structuredOutputs: z5.boolean().optional(),
|
|
949
1008
|
/**
|
|
950
1009
|
* Optional. A list of unique safety settings for blocking unsafe content.
|
|
951
1010
|
*/
|
|
952
|
-
safetySettings:
|
|
953
|
-
|
|
954
|
-
category:
|
|
1011
|
+
safetySettings: z5.array(
|
|
1012
|
+
z5.object({
|
|
1013
|
+
category: z5.enum([
|
|
955
1014
|
"HARM_CATEGORY_UNSPECIFIED",
|
|
956
1015
|
"HARM_CATEGORY_HATE_SPEECH",
|
|
957
1016
|
"HARM_CATEGORY_DANGEROUS_CONTENT",
|
|
@@ -959,7 +1018,7 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
959
1018
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
960
1019
|
"HARM_CATEGORY_CIVIC_INTEGRITY"
|
|
961
1020
|
]),
|
|
962
|
-
threshold:
|
|
1021
|
+
threshold: z5.enum([
|
|
963
1022
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
|
964
1023
|
"BLOCK_LOW_AND_ABOVE",
|
|
965
1024
|
"BLOCK_MEDIUM_AND_ABOVE",
|
|
@@ -969,7 +1028,7 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
969
1028
|
])
|
|
970
1029
|
})
|
|
971
1030
|
).optional(),
|
|
972
|
-
threshold:
|
|
1031
|
+
threshold: z5.enum([
|
|
973
1032
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
|
974
1033
|
"BLOCK_LOW_AND_ABOVE",
|
|
975
1034
|
"BLOCK_MEDIUM_AND_ABOVE",
|
|
@@ -982,19 +1041,19 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
982
1041
|
*
|
|
983
1042
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
|
984
1043
|
*/
|
|
985
|
-
audioTimestamp:
|
|
1044
|
+
audioTimestamp: z5.boolean().optional(),
|
|
986
1045
|
/**
|
|
987
1046
|
* Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
|
988
1047
|
*
|
|
989
1048
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
|
|
990
1049
|
*/
|
|
991
|
-
labels:
|
|
1050
|
+
labels: z5.record(z5.string(), z5.string()).optional(),
|
|
992
1051
|
/**
|
|
993
1052
|
* Optional. If specified, the media resolution specified will be used.
|
|
994
1053
|
*
|
|
995
1054
|
* https://ai.google.dev/api/generate-content#MediaResolution
|
|
996
1055
|
*/
|
|
997
|
-
mediaResolution:
|
|
1056
|
+
mediaResolution: z5.enum([
|
|
998
1057
|
"MEDIA_RESOLUTION_UNSPECIFIED",
|
|
999
1058
|
"MEDIA_RESOLUTION_LOW",
|
|
1000
1059
|
"MEDIA_RESOLUTION_MEDIUM",
|
|
@@ -1005,8 +1064,8 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1005
1064
|
*
|
|
1006
1065
|
* https://ai.google.dev/gemini-api/docs/image-generation#aspect_ratios
|
|
1007
1066
|
*/
|
|
1008
|
-
imageConfig:
|
|
1009
|
-
aspectRatio:
|
|
1067
|
+
imageConfig: z5.object({
|
|
1068
|
+
aspectRatio: z5.enum([
|
|
1010
1069
|
"1:1",
|
|
1011
1070
|
"2:3",
|
|
1012
1071
|
"3:2",
|
|
@@ -1022,12 +1081,12 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1022
1081
|
"1:4",
|
|
1023
1082
|
"4:1"
|
|
1024
1083
|
]).optional(),
|
|
1025
|
-
imageSize:
|
|
1084
|
+
imageSize: z5.enum(["1K", "2K", "4K", "512"]).optional(),
|
|
1026
1085
|
/**
|
|
1027
1086
|
* Optional. Controls the generation of people in images.
|
|
1028
1087
|
* Vertex AI only.
|
|
1029
1088
|
*/
|
|
1030
|
-
personGeneration:
|
|
1089
|
+
personGeneration: z5.enum([
|
|
1031
1090
|
"PERSON_GENERATION_UNSPECIFIED",
|
|
1032
1091
|
"ALLOW_ALL",
|
|
1033
1092
|
"ALLOW_ADULT",
|
|
@@ -1041,7 +1100,7 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1041
1100
|
*
|
|
1042
1101
|
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerationConfig
|
|
1043
1102
|
*/
|
|
1044
|
-
prominentPeople:
|
|
1103
|
+
prominentPeople: z5.enum([
|
|
1045
1104
|
"PROMINENT_PEOPLE_UNSPECIFIED",
|
|
1046
1105
|
"ALLOW_PROMINENT_PEOPLE",
|
|
1047
1106
|
"BLOCK_PROMINENT_PEOPLE"
|
|
@@ -1050,9 +1109,9 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1050
1109
|
* Optional. The image output format for generated images.
|
|
1051
1110
|
* Vertex AI only.
|
|
1052
1111
|
*/
|
|
1053
|
-
imageOutputOptions:
|
|
1054
|
-
mimeType:
|
|
1055
|
-
compressionQuality:
|
|
1112
|
+
imageOutputOptions: z5.object({
|
|
1113
|
+
mimeType: z5.enum(["image/jpeg", "image/png"]).optional(),
|
|
1114
|
+
compressionQuality: z5.number().optional()
|
|
1056
1115
|
}).optional()
|
|
1057
1116
|
}).optional(),
|
|
1058
1117
|
/**
|
|
@@ -1061,10 +1120,10 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1061
1120
|
*
|
|
1062
1121
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
|
|
1063
1122
|
*/
|
|
1064
|
-
retrievalConfig:
|
|
1065
|
-
latLng:
|
|
1066
|
-
latitude:
|
|
1067
|
-
longitude:
|
|
1123
|
+
retrievalConfig: z5.object({
|
|
1124
|
+
latLng: z5.object({
|
|
1125
|
+
latitude: z5.number(),
|
|
1126
|
+
longitude: z5.number()
|
|
1068
1127
|
}).optional()
|
|
1069
1128
|
}).optional(),
|
|
1070
1129
|
/**
|
|
@@ -1077,12 +1136,12 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1077
1136
|
*
|
|
1078
1137
|
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
|
|
1079
1138
|
*/
|
|
1080
|
-
streamFunctionCallArguments:
|
|
1139
|
+
streamFunctionCallArguments: z5.boolean().optional(),
|
|
1081
1140
|
/**
|
|
1082
1141
|
* Optional. The service tier to use for the request. Sent as the
|
|
1083
1142
|
* `serviceTier` body field. Gemini API only.
|
|
1084
1143
|
*/
|
|
1085
|
-
serviceTier:
|
|
1144
|
+
serviceTier: z5.enum(["standard", "flex", "priority"]).optional(),
|
|
1086
1145
|
/**
|
|
1087
1146
|
* Optional. Vertex AI only. Sent as the
|
|
1088
1147
|
* `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
|
|
@@ -1093,7 +1152,7 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1093
1152
|
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
|
|
1094
1153
|
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/flex-paygo
|
|
1095
1154
|
*/
|
|
1096
|
-
sharedRequestType:
|
|
1155
|
+
sharedRequestType: z5.enum(["priority", "flex", "standard"]).optional(),
|
|
1097
1156
|
/**
|
|
1098
1157
|
* Optional. Vertex AI only. Sent as the `X-Vertex-AI-LLM-Request-Type`
|
|
1099
1158
|
* request header. Set to `'shared'` together with `sharedRequestType`
|
|
@@ -1101,7 +1160,7 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1101
1160
|
*
|
|
1102
1161
|
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
|
|
1103
1162
|
*/
|
|
1104
|
-
requestType:
|
|
1163
|
+
requestType: z5.enum(["shared"]).optional()
|
|
1105
1164
|
})
|
|
1106
1165
|
)
|
|
1107
1166
|
);
|
|
@@ -1366,10 +1425,10 @@ function prepareTools({
|
|
|
1366
1425
|
}
|
|
1367
1426
|
}
|
|
1368
1427
|
function prepareFunctionDeclaration(tool) {
|
|
1369
|
-
var
|
|
1428
|
+
var _a2;
|
|
1370
1429
|
return {
|
|
1371
1430
|
name: tool.name,
|
|
1372
|
-
description: (
|
|
1431
|
+
description: (_a2 = tool.description) != null ? _a2 : "",
|
|
1373
1432
|
parametersJsonSchema: tool.inputSchema
|
|
1374
1433
|
};
|
|
1375
1434
|
}
|
|
@@ -1608,11 +1667,10 @@ function setNestedValue(obj, segments, value) {
|
|
|
1608
1667
|
defineOwnProperty(current, segments[segments.length - 1], value);
|
|
1609
1668
|
}
|
|
1610
1669
|
function resolvePartialArgValue(arg) {
|
|
1611
|
-
var
|
|
1612
|
-
const value = (_b = (
|
|
1670
|
+
var _a2, _b;
|
|
1671
|
+
const value = (_b = (_a2 = arg.stringValue) != null ? _a2 : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1613
1672
|
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1614
1673
|
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1615
|
-
return void 0;
|
|
1616
1674
|
}
|
|
1617
1675
|
|
|
1618
1676
|
// src/map-google-finish-reason.ts
|
|
@@ -1652,10 +1710,10 @@ var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
|
1652
1710
|
var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
1653
1711
|
constructor(modelId, config) {
|
|
1654
1712
|
this.specificationVersion = "v4";
|
|
1655
|
-
var
|
|
1713
|
+
var _a2;
|
|
1656
1714
|
this.modelId = modelId;
|
|
1657
1715
|
this.config = config;
|
|
1658
|
-
this.generateId = (
|
|
1716
|
+
this.generateId = (_a2 = config.generateId) != null ? _a2 : generateId;
|
|
1659
1717
|
}
|
|
1660
1718
|
static [WORKFLOW_SERIALIZE2](model) {
|
|
1661
1719
|
return serializeModelOptions2({
|
|
@@ -1670,8 +1728,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1670
1728
|
return this.config.provider;
|
|
1671
1729
|
}
|
|
1672
1730
|
get supportedUrls() {
|
|
1673
|
-
var
|
|
1674
|
-
return (_c = (_b = (
|
|
1731
|
+
var _a2, _b, _c;
|
|
1732
|
+
return (_c = (_b = (_a2 = this.config).supportedUrls) == null ? void 0 : _b.call(_a2)) != null ? _c : {};
|
|
1675
1733
|
}
|
|
1676
1734
|
static async prepareRequest({
|
|
1677
1735
|
modelId,
|
|
@@ -1695,7 +1753,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1695
1753
|
},
|
|
1696
1754
|
isStreaming = false
|
|
1697
1755
|
}) {
|
|
1698
|
-
var
|
|
1756
|
+
var _a2, _b, _c;
|
|
1699
1757
|
const warnings = [];
|
|
1700
1758
|
const providerOptionsNames = config.provider.includes(
|
|
1701
1759
|
"vertex"
|
|
@@ -1825,7 +1883,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1825
1883
|
warnings
|
|
1826
1884
|
});
|
|
1827
1885
|
const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
|
|
1828
|
-
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (
|
|
1886
|
+
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a2 = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a2 : false : void 0;
|
|
1829
1887
|
const safetyThreshold = googleOptions == null ? void 0 : googleOptions.threshold;
|
|
1830
1888
|
const safetySettings = (_b = googleOptions == null ? void 0 : googleOptions.safetySettings) != null ? _b : safetyThreshold != null ? configurableSafetySettingCategories.map((category) => ({
|
|
1831
1889
|
category,
|
|
@@ -1902,11 +1960,11 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1902
1960
|
providerOptionsNames,
|
|
1903
1961
|
toolNameMapping
|
|
1904
1962
|
}) {
|
|
1905
|
-
var
|
|
1963
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1906
1964
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1907
1965
|
providerOptionsNames.map((name) => [name, payload])
|
|
1908
1966
|
);
|
|
1909
|
-
const candidate = (
|
|
1967
|
+
const candidate = (_a2 = response.candidates) == null ? void 0 : _a2[0];
|
|
1910
1968
|
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1911
1969
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
1912
1970
|
promptBlockReason
|
|
@@ -2179,7 +2237,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2179
2237
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2180
2238
|
},
|
|
2181
2239
|
transform(chunk, controller) {
|
|
2182
|
-
var
|
|
2240
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
2183
2241
|
if (options.includeRawChunks) {
|
|
2184
2242
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2185
2243
|
}
|
|
@@ -2209,7 +2267,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2209
2267
|
};
|
|
2210
2268
|
}
|
|
2211
2269
|
}
|
|
2212
|
-
const candidate = (
|
|
2270
|
+
const candidate = (_a2 = value.candidates) == null ? void 0 : _a2[0];
|
|
2213
2271
|
if (candidate != null) {
|
|
2214
2272
|
if (candidate.groundingMetadata != null) {
|
|
2215
2273
|
lastGroundingMetadata = candidate.groundingMetadata;
|
|
@@ -2507,7 +2565,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2507
2565
|
}
|
|
2508
2566
|
},
|
|
2509
2567
|
flush(controller) {
|
|
2510
|
-
var
|
|
2568
|
+
var _a2;
|
|
2511
2569
|
if (currentTextBlockId !== null) {
|
|
2512
2570
|
controller.enqueue({
|
|
2513
2571
|
type: "text-end",
|
|
@@ -2531,7 +2589,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2531
2589
|
safetyRatings: lastSafetyRatings,
|
|
2532
2590
|
usageMetadata: usage != null ? usage : null,
|
|
2533
2591
|
finishMessage: lastFinishMessage,
|
|
2534
|
-
serviceTier: (
|
|
2592
|
+
serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null
|
|
2535
2593
|
})
|
|
2536
2594
|
});
|
|
2537
2595
|
}
|
|
@@ -2591,8 +2649,8 @@ function resolveGemini3ThinkingConfig({
|
|
|
2591
2649
|
return { thinkingLevel };
|
|
2592
2650
|
}
|
|
2593
2651
|
function getMinimumThinkingLevelForGemini3Model(modelId) {
|
|
2594
|
-
var
|
|
2595
|
-
const modelName = (
|
|
2652
|
+
var _a2;
|
|
2653
|
+
const modelName = (_a2 = modelId.split("/").at(-1)) == null ? void 0 : _a2.toLowerCase();
|
|
2596
2654
|
if (modelName === "gemini-flash-latest") {
|
|
2597
2655
|
return "low";
|
|
2598
2656
|
}
|
|
@@ -2630,7 +2688,7 @@ function extractSources({
|
|
|
2630
2688
|
groundingMetadata,
|
|
2631
2689
|
generateId: generateId4
|
|
2632
2690
|
}) {
|
|
2633
|
-
var
|
|
2691
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2634
2692
|
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
2635
2693
|
return void 0;
|
|
2636
2694
|
}
|
|
@@ -2642,7 +2700,7 @@ function extractSources({
|
|
|
2642
2700
|
sourceType: "url",
|
|
2643
2701
|
id: generateId4(),
|
|
2644
2702
|
url: chunk.web.uri,
|
|
2645
|
-
title: (
|
|
2703
|
+
title: (_a2 = chunk.web.title) != null ? _a2 : void 0
|
|
2646
2704
|
});
|
|
2647
2705
|
} else if (chunk.image != null) {
|
|
2648
2706
|
sources.push({
|
|
@@ -2720,195 +2778,195 @@ function extractSources({
|
|
|
2720
2778
|
}
|
|
2721
2779
|
return sources.length > 0 ? sources : void 0;
|
|
2722
2780
|
}
|
|
2723
|
-
var getGroundingMetadataSchema = () =>
|
|
2724
|
-
webSearchQueries:
|
|
2725
|
-
imageSearchQueries:
|
|
2726
|
-
retrievalQueries:
|
|
2727
|
-
searchEntryPoint:
|
|
2728
|
-
groundingChunks:
|
|
2729
|
-
|
|
2730
|
-
web:
|
|
2731
|
-
image:
|
|
2732
|
-
sourceUri:
|
|
2733
|
-
imageUri:
|
|
2734
|
-
title:
|
|
2735
|
-
domain:
|
|
2781
|
+
var getGroundingMetadataSchema = () => z6.object({
|
|
2782
|
+
webSearchQueries: z6.array(z6.string()).nullish(),
|
|
2783
|
+
imageSearchQueries: z6.array(z6.string()).nullish(),
|
|
2784
|
+
retrievalQueries: z6.array(z6.string()).nullish(),
|
|
2785
|
+
searchEntryPoint: z6.object({ renderedContent: z6.string() }).nullish(),
|
|
2786
|
+
groundingChunks: z6.array(
|
|
2787
|
+
z6.object({
|
|
2788
|
+
web: z6.object({ uri: z6.string(), title: z6.string().nullish() }).nullish(),
|
|
2789
|
+
image: z6.object({
|
|
2790
|
+
sourceUri: z6.string(),
|
|
2791
|
+
imageUri: z6.string(),
|
|
2792
|
+
title: z6.string().nullish(),
|
|
2793
|
+
domain: z6.string().nullish()
|
|
2736
2794
|
}).nullish(),
|
|
2737
|
-
retrievedContext:
|
|
2738
|
-
uri:
|
|
2739
|
-
title:
|
|
2740
|
-
text:
|
|
2741
|
-
fileSearchStore:
|
|
2795
|
+
retrievedContext: z6.object({
|
|
2796
|
+
uri: z6.string().nullish(),
|
|
2797
|
+
title: z6.string().nullish(),
|
|
2798
|
+
text: z6.string().nullish(),
|
|
2799
|
+
fileSearchStore: z6.string().nullish()
|
|
2742
2800
|
}).nullish(),
|
|
2743
|
-
maps:
|
|
2744
|
-
uri:
|
|
2745
|
-
title:
|
|
2746
|
-
text:
|
|
2747
|
-
placeId:
|
|
2801
|
+
maps: z6.object({
|
|
2802
|
+
uri: z6.string().nullish(),
|
|
2803
|
+
title: z6.string().nullish(),
|
|
2804
|
+
text: z6.string().nullish(),
|
|
2805
|
+
placeId: z6.string().nullish()
|
|
2748
2806
|
}).nullish()
|
|
2749
2807
|
})
|
|
2750
2808
|
).nullish(),
|
|
2751
|
-
groundingSupports:
|
|
2752
|
-
|
|
2753
|
-
segment:
|
|
2754
|
-
startIndex:
|
|
2755
|
-
endIndex:
|
|
2756
|
-
text:
|
|
2809
|
+
groundingSupports: z6.array(
|
|
2810
|
+
z6.object({
|
|
2811
|
+
segment: z6.object({
|
|
2812
|
+
startIndex: z6.number().nullish(),
|
|
2813
|
+
endIndex: z6.number().nullish(),
|
|
2814
|
+
text: z6.string().nullish()
|
|
2757
2815
|
}).nullish(),
|
|
2758
|
-
segment_text:
|
|
2759
|
-
groundingChunkIndices:
|
|
2760
|
-
supportChunkIndices:
|
|
2761
|
-
confidenceScores:
|
|
2762
|
-
confidenceScore:
|
|
2816
|
+
segment_text: z6.string().nullish(),
|
|
2817
|
+
groundingChunkIndices: z6.array(z6.number()).nullish(),
|
|
2818
|
+
supportChunkIndices: z6.array(z6.number()).nullish(),
|
|
2819
|
+
confidenceScores: z6.array(z6.number()).nullish(),
|
|
2820
|
+
confidenceScore: z6.array(z6.number()).nullish()
|
|
2763
2821
|
})
|
|
2764
2822
|
).nullish(),
|
|
2765
|
-
retrievalMetadata:
|
|
2766
|
-
|
|
2767
|
-
webDynamicRetrievalScore:
|
|
2823
|
+
retrievalMetadata: z6.union([
|
|
2824
|
+
z6.object({
|
|
2825
|
+
webDynamicRetrievalScore: z6.number()
|
|
2768
2826
|
}),
|
|
2769
|
-
|
|
2827
|
+
z6.object({})
|
|
2770
2828
|
]).nullish()
|
|
2771
2829
|
});
|
|
2772
|
-
var partialArgSchema =
|
|
2773
|
-
jsonPath:
|
|
2774
|
-
stringValue:
|
|
2775
|
-
numberValue:
|
|
2776
|
-
boolValue:
|
|
2777
|
-
nullValue:
|
|
2778
|
-
willContinue:
|
|
2830
|
+
var partialArgSchema = z6.object({
|
|
2831
|
+
jsonPath: z6.string(),
|
|
2832
|
+
stringValue: z6.string().nullish(),
|
|
2833
|
+
numberValue: z6.number().nullish(),
|
|
2834
|
+
boolValue: z6.boolean().nullish(),
|
|
2835
|
+
nullValue: z6.unknown().nullish(),
|
|
2836
|
+
willContinue: z6.boolean().nullish()
|
|
2779
2837
|
});
|
|
2780
|
-
var getContentSchema = () =>
|
|
2781
|
-
parts:
|
|
2782
|
-
|
|
2838
|
+
var getContentSchema = () => z6.object({
|
|
2839
|
+
parts: z6.array(
|
|
2840
|
+
z6.union([
|
|
2783
2841
|
// note: order matters since text can be fully empty
|
|
2784
|
-
|
|
2785
|
-
functionCall:
|
|
2786
|
-
id:
|
|
2787
|
-
name:
|
|
2788
|
-
args:
|
|
2789
|
-
partialArgs:
|
|
2790
|
-
willContinue:
|
|
2842
|
+
z6.object({
|
|
2843
|
+
functionCall: z6.object({
|
|
2844
|
+
id: z6.string().nullish(),
|
|
2845
|
+
name: z6.string().nullish(),
|
|
2846
|
+
args: z6.unknown().nullish(),
|
|
2847
|
+
partialArgs: z6.array(partialArgSchema).nullish(),
|
|
2848
|
+
willContinue: z6.boolean().nullish()
|
|
2791
2849
|
}),
|
|
2792
|
-
thoughtSignature:
|
|
2850
|
+
thoughtSignature: z6.string().nullish()
|
|
2793
2851
|
}),
|
|
2794
|
-
|
|
2795
|
-
inlineData:
|
|
2796
|
-
mimeType:
|
|
2797
|
-
data:
|
|
2852
|
+
z6.object({
|
|
2853
|
+
inlineData: z6.object({
|
|
2854
|
+
mimeType: z6.string(),
|
|
2855
|
+
data: z6.string()
|
|
2798
2856
|
}),
|
|
2799
|
-
thought:
|
|
2800
|
-
thoughtSignature:
|
|
2857
|
+
thought: z6.boolean().nullish(),
|
|
2858
|
+
thoughtSignature: z6.string().nullish()
|
|
2801
2859
|
}),
|
|
2802
|
-
|
|
2803
|
-
toolCall:
|
|
2804
|
-
toolType:
|
|
2805
|
-
args:
|
|
2806
|
-
id:
|
|
2860
|
+
z6.object({
|
|
2861
|
+
toolCall: z6.object({
|
|
2862
|
+
toolType: z6.string(),
|
|
2863
|
+
args: z6.unknown().nullish(),
|
|
2864
|
+
id: z6.string()
|
|
2807
2865
|
}),
|
|
2808
|
-
thoughtSignature:
|
|
2866
|
+
thoughtSignature: z6.string().nullish()
|
|
2809
2867
|
}),
|
|
2810
|
-
|
|
2811
|
-
toolResponse:
|
|
2812
|
-
toolType:
|
|
2813
|
-
response:
|
|
2814
|
-
id:
|
|
2868
|
+
z6.object({
|
|
2869
|
+
toolResponse: z6.object({
|
|
2870
|
+
toolType: z6.string(),
|
|
2871
|
+
response: z6.unknown().nullish(),
|
|
2872
|
+
id: z6.string()
|
|
2815
2873
|
}),
|
|
2816
|
-
thoughtSignature:
|
|
2874
|
+
thoughtSignature: z6.string().nullish()
|
|
2817
2875
|
}),
|
|
2818
|
-
|
|
2819
|
-
executableCode:
|
|
2820
|
-
language:
|
|
2821
|
-
code:
|
|
2876
|
+
z6.object({
|
|
2877
|
+
executableCode: z6.object({
|
|
2878
|
+
language: z6.string(),
|
|
2879
|
+
code: z6.string()
|
|
2822
2880
|
}).nullish(),
|
|
2823
|
-
codeExecutionResult:
|
|
2824
|
-
outcome:
|
|
2825
|
-
output:
|
|
2881
|
+
codeExecutionResult: z6.object({
|
|
2882
|
+
outcome: z6.string(),
|
|
2883
|
+
output: z6.string().nullish()
|
|
2826
2884
|
}).nullish(),
|
|
2827
|
-
text:
|
|
2828
|
-
thought:
|
|
2829
|
-
thoughtSignature:
|
|
2885
|
+
text: z6.string().nullish(),
|
|
2886
|
+
thought: z6.boolean().nullish(),
|
|
2887
|
+
thoughtSignature: z6.string().nullish()
|
|
2830
2888
|
})
|
|
2831
2889
|
])
|
|
2832
2890
|
).nullish()
|
|
2833
2891
|
});
|
|
2834
|
-
var getSafetyRatingSchema = () =>
|
|
2835
|
-
category:
|
|
2836
|
-
probability:
|
|
2837
|
-
probabilityScore:
|
|
2838
|
-
severity:
|
|
2839
|
-
severityScore:
|
|
2840
|
-
blocked:
|
|
2892
|
+
var getSafetyRatingSchema = () => z6.object({
|
|
2893
|
+
category: z6.string().nullish(),
|
|
2894
|
+
probability: z6.string().nullish(),
|
|
2895
|
+
probabilityScore: z6.number().nullish(),
|
|
2896
|
+
severity: z6.string().nullish(),
|
|
2897
|
+
severityScore: z6.number().nullish(),
|
|
2898
|
+
blocked: z6.boolean().nullish()
|
|
2841
2899
|
});
|
|
2842
|
-
var tokenDetailsSchema =
|
|
2843
|
-
|
|
2844
|
-
modality:
|
|
2845
|
-
tokenCount:
|
|
2900
|
+
var tokenDetailsSchema = z6.array(
|
|
2901
|
+
z6.object({
|
|
2902
|
+
modality: z6.string(),
|
|
2903
|
+
tokenCount: z6.number()
|
|
2846
2904
|
}).loose()
|
|
2847
2905
|
).nullish();
|
|
2848
|
-
var usageSchema =
|
|
2849
|
-
cachedContentTokenCount:
|
|
2850
|
-
thoughtsTokenCount:
|
|
2851
|
-
promptTokenCount:
|
|
2852
|
-
candidatesTokenCount:
|
|
2853
|
-
toolUsePromptTokenCount:
|
|
2854
|
-
totalTokenCount:
|
|
2906
|
+
var usageSchema = z6.object({
|
|
2907
|
+
cachedContentTokenCount: z6.number().nullish(),
|
|
2908
|
+
thoughtsTokenCount: z6.number().nullish(),
|
|
2909
|
+
promptTokenCount: z6.number().nullish(),
|
|
2910
|
+
candidatesTokenCount: z6.number().nullish(),
|
|
2911
|
+
toolUsePromptTokenCount: z6.number().nullish(),
|
|
2912
|
+
totalTokenCount: z6.number().nullish(),
|
|
2855
2913
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
2856
|
-
trafficType:
|
|
2857
|
-
serviceTier:
|
|
2914
|
+
trafficType: z6.string().nullish(),
|
|
2915
|
+
serviceTier: z6.string().nullish(),
|
|
2858
2916
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2859
2917
|
promptTokensDetails: tokenDetailsSchema,
|
|
2860
2918
|
cacheTokensDetails: tokenDetailsSchema,
|
|
2861
2919
|
candidatesTokensDetails: tokenDetailsSchema,
|
|
2862
2920
|
toolUsePromptTokensDetails: tokenDetailsSchema
|
|
2863
2921
|
}).loose();
|
|
2864
|
-
var getUrlContextMetadataSchema = () =>
|
|
2865
|
-
urlMetadata:
|
|
2866
|
-
|
|
2867
|
-
retrievedUrl:
|
|
2868
|
-
urlRetrievalStatus:
|
|
2922
|
+
var getUrlContextMetadataSchema = () => z6.object({
|
|
2923
|
+
urlMetadata: z6.array(
|
|
2924
|
+
z6.object({
|
|
2925
|
+
retrievedUrl: z6.string(),
|
|
2926
|
+
urlRetrievalStatus: z6.string()
|
|
2869
2927
|
})
|
|
2870
2928
|
).nullish()
|
|
2871
2929
|
});
|
|
2872
2930
|
var responseSchema = lazySchema5(
|
|
2873
2931
|
() => zodSchema5(
|
|
2874
|
-
|
|
2875
|
-
responseId:
|
|
2876
|
-
candidates:
|
|
2877
|
-
|
|
2878
|
-
content: getContentSchema().nullish().or(
|
|
2879
|
-
finishReason:
|
|
2880
|
-
finishMessage:
|
|
2881
|
-
safetyRatings:
|
|
2932
|
+
z6.object({
|
|
2933
|
+
responseId: z6.string().nullish(),
|
|
2934
|
+
candidates: z6.array(
|
|
2935
|
+
z6.object({
|
|
2936
|
+
content: getContentSchema().nullish().or(z6.object({}).strict()),
|
|
2937
|
+
finishReason: z6.string().nullish(),
|
|
2938
|
+
finishMessage: z6.string().nullish(),
|
|
2939
|
+
safetyRatings: z6.array(getSafetyRatingSchema()).nullish(),
|
|
2882
2940
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2883
2941
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2884
2942
|
})
|
|
2885
2943
|
).nullish(),
|
|
2886
2944
|
usageMetadata: usageSchema.nullish(),
|
|
2887
|
-
promptFeedback:
|
|
2888
|
-
blockReason:
|
|
2889
|
-
safetyRatings:
|
|
2945
|
+
promptFeedback: z6.object({
|
|
2946
|
+
blockReason: z6.string().nullish(),
|
|
2947
|
+
safetyRatings: z6.array(getSafetyRatingSchema()).nullish()
|
|
2890
2948
|
}).nullish()
|
|
2891
2949
|
})
|
|
2892
2950
|
)
|
|
2893
2951
|
);
|
|
2894
2952
|
var chunkSchema = lazySchema5(
|
|
2895
2953
|
() => zodSchema5(
|
|
2896
|
-
|
|
2897
|
-
responseId:
|
|
2898
|
-
candidates:
|
|
2899
|
-
|
|
2954
|
+
z6.object({
|
|
2955
|
+
responseId: z6.string().nullish(),
|
|
2956
|
+
candidates: z6.array(
|
|
2957
|
+
z6.object({
|
|
2900
2958
|
content: getContentSchema().nullish(),
|
|
2901
|
-
finishReason:
|
|
2902
|
-
finishMessage:
|
|
2903
|
-
safetyRatings:
|
|
2959
|
+
finishReason: z6.string().nullish(),
|
|
2960
|
+
finishMessage: z6.string().nullish(),
|
|
2961
|
+
safetyRatings: z6.array(getSafetyRatingSchema()).nullish(),
|
|
2904
2962
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2905
2963
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2906
2964
|
})
|
|
2907
2965
|
).nullish(),
|
|
2908
2966
|
usageMetadata: usageSchema.nullish(),
|
|
2909
|
-
promptFeedback:
|
|
2910
|
-
blockReason:
|
|
2911
|
-
safetyRatings:
|
|
2967
|
+
promptFeedback: z6.object({
|
|
2968
|
+
blockReason: z6.string().nullish(),
|
|
2969
|
+
safetyRatings: z6.array(getSafetyRatingSchema()).nullish()
|
|
2912
2970
|
}).nullish()
|
|
2913
2971
|
})
|
|
2914
2972
|
)
|
|
@@ -2919,35 +2977,35 @@ function isConfirmedPromptBlockReason(blockReason) {
|
|
|
2919
2977
|
|
|
2920
2978
|
// src/google-image-model-options.ts
|
|
2921
2979
|
import { lazySchema as lazySchema7, zodSchema as zodSchema7 } from "@ai-sdk/provider-utils";
|
|
2922
|
-
import { z as
|
|
2980
|
+
import { z as z8 } from "zod/v4";
|
|
2923
2981
|
|
|
2924
2982
|
// src/tool/google-search.ts
|
|
2925
2983
|
import {
|
|
2926
|
-
createProviderExecutedToolFactory,
|
|
2984
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
|
|
2927
2985
|
lazySchema as lazySchema6,
|
|
2928
2986
|
zodSchema as zodSchema6
|
|
2929
2987
|
} from "@ai-sdk/provider-utils";
|
|
2930
|
-
import { z as
|
|
2931
|
-
var googleSearchToolArgsBaseSchema =
|
|
2932
|
-
searchTypes:
|
|
2933
|
-
webSearch:
|
|
2934
|
-
imageSearch:
|
|
2988
|
+
import { z as z7 } from "zod/v4";
|
|
2989
|
+
var googleSearchToolArgsBaseSchema = z7.looseObject({
|
|
2990
|
+
searchTypes: z7.object({
|
|
2991
|
+
webSearch: z7.object({}).optional(),
|
|
2992
|
+
imageSearch: z7.object({}).optional()
|
|
2935
2993
|
}).optional(),
|
|
2936
|
-
timeRangeFilter:
|
|
2937
|
-
startTime:
|
|
2938
|
-
endTime:
|
|
2994
|
+
timeRangeFilter: z7.object({
|
|
2995
|
+
startTime: z7.string(),
|
|
2996
|
+
endTime: z7.string()
|
|
2939
2997
|
}).optional()
|
|
2940
2998
|
});
|
|
2941
|
-
var googleSearch =
|
|
2999
|
+
var googleSearch = createProviderExecutedToolFactory2({
|
|
2942
3000
|
id: "google.google_search",
|
|
2943
|
-
inputSchema: lazySchema6(() => zodSchema6(
|
|
2944
|
-
outputSchema: lazySchema6(() => zodSchema6(
|
|
3001
|
+
inputSchema: lazySchema6(() => zodSchema6(z7.object({}))),
|
|
3002
|
+
outputSchema: lazySchema6(() => zodSchema6(z7.object({})))
|
|
2945
3003
|
});
|
|
2946
3004
|
|
|
2947
3005
|
// src/google-image-model-options.ts
|
|
2948
3006
|
var googleImageModelOptionsSchema = lazySchema7(
|
|
2949
3007
|
() => zodSchema7(
|
|
2950
|
-
|
|
3008
|
+
z8.object({
|
|
2951
3009
|
/**
|
|
2952
3010
|
* Enable Google Search grounding for Gemini image models. The value is
|
|
2953
3011
|
* forwarded as the args of the `google.tools.googleSearch` provider
|
|
@@ -2977,40 +3035,40 @@ function assertSupportedBatchRequests(requests) {
|
|
|
2977
3035
|
}
|
|
2978
3036
|
}
|
|
2979
3037
|
}
|
|
2980
|
-
var googleRpcStatusSchema =
|
|
2981
|
-
code:
|
|
2982
|
-
message:
|
|
2983
|
-
status:
|
|
3038
|
+
var googleRpcStatusSchema = z9.object({
|
|
3039
|
+
code: z9.union([z9.number(), z9.string()]).nullish(),
|
|
3040
|
+
message: z9.string().nullish(),
|
|
3041
|
+
status: z9.string().nullish()
|
|
2984
3042
|
});
|
|
2985
|
-
var googleBatchStatsSchema =
|
|
2986
|
-
requestCount:
|
|
2987
|
-
successfulRequestCount:
|
|
2988
|
-
failedRequestCount:
|
|
2989
|
-
pendingRequestCount:
|
|
3043
|
+
var googleBatchStatsSchema = z9.object({
|
|
3044
|
+
requestCount: z9.union([z9.string(), z9.number()]).nullish(),
|
|
3045
|
+
successfulRequestCount: z9.union([z9.string(), z9.number()]).nullish(),
|
|
3046
|
+
failedRequestCount: z9.union([z9.string(), z9.number()]).nullish(),
|
|
3047
|
+
pendingRequestCount: z9.union([z9.string(), z9.number()]).nullish()
|
|
2990
3048
|
});
|
|
2991
|
-
var googleBatchOutputSchema =
|
|
2992
|
-
responsesFile:
|
|
2993
|
-
inlinedResponses:
|
|
2994
|
-
inlinedResponses:
|
|
2995
|
-
|
|
2996
|
-
metadata:
|
|
2997
|
-
key:
|
|
3049
|
+
var googleBatchOutputSchema = z9.object({
|
|
3050
|
+
responsesFile: z9.string().nullish(),
|
|
3051
|
+
inlinedResponses: z9.object({
|
|
3052
|
+
inlinedResponses: z9.array(
|
|
3053
|
+
z9.object({
|
|
3054
|
+
metadata: z9.object({
|
|
3055
|
+
key: z9.string()
|
|
2998
3056
|
}),
|
|
2999
|
-
response:
|
|
3057
|
+
response: z9.unknown().nullish(),
|
|
3000
3058
|
error: googleRpcStatusSchema.nullish()
|
|
3001
3059
|
})
|
|
3002
3060
|
)
|
|
3003
3061
|
}).nullish()
|
|
3004
3062
|
});
|
|
3005
|
-
var googleBatchOperationZodSchema = () =>
|
|
3006
|
-
name:
|
|
3007
|
-
metadata:
|
|
3008
|
-
state:
|
|
3009
|
-
createTime:
|
|
3063
|
+
var googleBatchOperationZodSchema = () => z9.object({
|
|
3064
|
+
name: z9.string(),
|
|
3065
|
+
metadata: z9.object({
|
|
3066
|
+
state: z9.string().nullish(),
|
|
3067
|
+
createTime: z9.string().nullish(),
|
|
3010
3068
|
batchStats: googleBatchStatsSchema.nullish(),
|
|
3011
3069
|
output: googleBatchOutputSchema.nullish()
|
|
3012
3070
|
}).nullish(),
|
|
3013
|
-
done:
|
|
3071
|
+
done: z9.boolean().nullish(),
|
|
3014
3072
|
error: googleRpcStatusSchema.nullish(),
|
|
3015
3073
|
response: googleBatchOutputSchema.nullish()
|
|
3016
3074
|
});
|
|
@@ -3019,40 +3077,40 @@ var googleBatchOperationSchema = lazySchema8(
|
|
|
3019
3077
|
);
|
|
3020
3078
|
var googleBatchListResponseSchema = lazySchema8(
|
|
3021
3079
|
() => zodSchema8(
|
|
3022
|
-
|
|
3023
|
-
operations:
|
|
3024
|
-
nextPageToken:
|
|
3080
|
+
z9.object({
|
|
3081
|
+
operations: z9.array(googleBatchOperationZodSchema()).nullish(),
|
|
3082
|
+
nextPageToken: z9.string().nullish()
|
|
3025
3083
|
})
|
|
3026
3084
|
)
|
|
3027
3085
|
);
|
|
3028
3086
|
var googleBatchCancelResponseSchema = lazySchema8(
|
|
3029
|
-
() => zodSchema8(
|
|
3087
|
+
() => zodSchema8(z9.object({}))
|
|
3030
3088
|
);
|
|
3031
3089
|
var googleFileUploadResponseSchema = lazySchema8(
|
|
3032
3090
|
() => zodSchema8(
|
|
3033
|
-
|
|
3034
|
-
file:
|
|
3035
|
-
name:
|
|
3036
|
-
expirationTime:
|
|
3091
|
+
z9.object({
|
|
3092
|
+
file: z9.object({
|
|
3093
|
+
name: z9.string(),
|
|
3094
|
+
expirationTime: z9.string().nullish()
|
|
3037
3095
|
})
|
|
3038
3096
|
})
|
|
3039
3097
|
)
|
|
3040
3098
|
);
|
|
3041
3099
|
var googleBatchResultLineSchema = lazySchema8(
|
|
3042
3100
|
() => zodSchema8(
|
|
3043
|
-
|
|
3044
|
-
key:
|
|
3045
|
-
response:
|
|
3101
|
+
z9.object({
|
|
3102
|
+
key: z9.string(),
|
|
3103
|
+
response: z9.unknown().nullish(),
|
|
3046
3104
|
error: googleRpcStatusSchema.nullish()
|
|
3047
3105
|
})
|
|
3048
3106
|
)
|
|
3049
3107
|
);
|
|
3050
3108
|
var googleBatchResponsePreviewSchema = lazySchema8(
|
|
3051
3109
|
() => zodSchema8(
|
|
3052
|
-
|
|
3053
|
-
candidates:
|
|
3054
|
-
promptFeedback:
|
|
3055
|
-
blockReason:
|
|
3110
|
+
z9.object({
|
|
3111
|
+
candidates: z9.array(z9.unknown()).nullish(),
|
|
3112
|
+
promptFeedback: z9.object({
|
|
3113
|
+
blockReason: z9.string().nullish()
|
|
3056
3114
|
}).nullish()
|
|
3057
3115
|
})
|
|
3058
3116
|
)
|
|
@@ -3060,11 +3118,11 @@ var googleBatchResponsePreviewSchema = lazySchema8(
|
|
|
3060
3118
|
var GoogleBatch = class {
|
|
3061
3119
|
constructor(options) {
|
|
3062
3120
|
this.specificationVersion = "v4";
|
|
3063
|
-
var
|
|
3121
|
+
var _a2;
|
|
3064
3122
|
this.provider = options.provider;
|
|
3065
3123
|
this.batchConfig = options.config;
|
|
3066
3124
|
this.supportedUrls = options.supportedUrls;
|
|
3067
|
-
this.batchGenerateId = (
|
|
3125
|
+
this.batchGenerateId = (_a2 = options.config.generateId) != null ? _a2 : generateId2;
|
|
3068
3126
|
}
|
|
3069
3127
|
async doStartBatch(options) {
|
|
3070
3128
|
assertSupportedBatchRequests(options.requests);
|
|
@@ -3259,7 +3317,7 @@ var GoogleBatch = class {
|
|
|
3259
3317
|
return {};
|
|
3260
3318
|
}
|
|
3261
3319
|
async doListBatches(options) {
|
|
3262
|
-
var
|
|
3320
|
+
var _a2;
|
|
3263
3321
|
const url = new URL(`${this.batchConfig.baseURL}/batches`);
|
|
3264
3322
|
if (options.limit != null) {
|
|
3265
3323
|
url.searchParams.set("pageSize", String(options.limit));
|
|
@@ -3279,7 +3337,7 @@ var GoogleBatch = class {
|
|
|
3279
3337
|
validateUrl: false
|
|
3280
3338
|
});
|
|
3281
3339
|
return {
|
|
3282
|
-
batches: ((
|
|
3340
|
+
batches: ((_a2 = page.operations) != null ? _a2 : []).map((operation) => ({
|
|
3283
3341
|
batchId: operation.name,
|
|
3284
3342
|
...convertGoogleBatchStatus(operation)
|
|
3285
3343
|
})),
|
|
@@ -3287,7 +3345,7 @@ var GoogleBatch = class {
|
|
|
3287
3345
|
};
|
|
3288
3346
|
}
|
|
3289
3347
|
async doGetBatchResults(options) {
|
|
3290
|
-
var
|
|
3348
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3291
3349
|
const operation = await this.retrieveBatch(options);
|
|
3292
3350
|
const batchStatus = convertGoogleBatchStatus(operation);
|
|
3293
3351
|
if (batchStatus.status === "pending") {
|
|
@@ -3296,7 +3354,7 @@ var GoogleBatch = class {
|
|
|
3296
3354
|
message: `Google batch "${options.batchId}" is not complete.`
|
|
3297
3355
|
});
|
|
3298
3356
|
}
|
|
3299
|
-
const inlinedResponses = (_f = (_c = (_b = (
|
|
3357
|
+
const inlinedResponses = (_f = (_c = (_b = (_a2 = operation.metadata) == null ? void 0 : _a2.output) == null ? void 0 : _b.inlinedResponses) == null ? void 0 : _c.inlinedResponses) != null ? _f : (_e = (_d = operation.response) == null ? void 0 : _d.inlinedResponses) == null ? void 0 : _e.inlinedResponses;
|
|
3300
3358
|
if (inlinedResponses != null) {
|
|
3301
3359
|
return convertAsyncIteratorToReadableStream(
|
|
3302
3360
|
this.iterateBatchResults(
|
|
@@ -3353,7 +3411,7 @@ var GoogleBatch = class {
|
|
|
3353
3411
|
return operation;
|
|
3354
3412
|
}
|
|
3355
3413
|
async *iterateBatchResults(results) {
|
|
3356
|
-
var
|
|
3414
|
+
var _a2, _b, _c;
|
|
3357
3415
|
for await (const line of results) {
|
|
3358
3416
|
if (line.error != null) {
|
|
3359
3417
|
const error = convertGoogleRpcError(
|
|
@@ -3381,7 +3439,7 @@ var GoogleBatch = class {
|
|
|
3381
3439
|
schema: googleBatchResponsePreviewSchema
|
|
3382
3440
|
});
|
|
3383
3441
|
if (preview.success && (preview.value.candidates == null || preview.value.candidates.length === 0)) {
|
|
3384
|
-
const promptFeedback = (
|
|
3442
|
+
const promptFeedback = (_a2 = preview.value.promptFeedback) != null ? _a2 : void 0;
|
|
3385
3443
|
const blockReason = (_b = promptFeedback == null ? void 0 : promptFeedback.blockReason) != null ? _b : void 0;
|
|
3386
3444
|
yield {
|
|
3387
3445
|
type: "text",
|
|
@@ -3455,7 +3513,7 @@ var GoogleBatch = class {
|
|
|
3455
3513
|
}
|
|
3456
3514
|
}
|
|
3457
3515
|
async prepareImageRequest(request) {
|
|
3458
|
-
var
|
|
3516
|
+
var _a2;
|
|
3459
3517
|
const { prompt, n, size, aspectRatio, seed, files, mask, providerOptions } = request.options;
|
|
3460
3518
|
const warnings = [];
|
|
3461
3519
|
if (mask != null) {
|
|
@@ -3499,11 +3557,11 @@ var GoogleBatch = class {
|
|
|
3499
3557
|
responseModalities: _responseModalities,
|
|
3500
3558
|
imageConfig: userImageConfig,
|
|
3501
3559
|
...passthroughGoogleOptions
|
|
3502
|
-
} = (
|
|
3560
|
+
} = (_a2 = await parseProviderOptions3({
|
|
3503
3561
|
provider: "google",
|
|
3504
3562
|
providerOptions,
|
|
3505
3563
|
schema: googleLanguageModelOptions
|
|
3506
|
-
})) != null ?
|
|
3564
|
+
})) != null ? _a2 : {};
|
|
3507
3565
|
const preparedGoogleOptions = await parseProviderOptions3({
|
|
3508
3566
|
provider: "google",
|
|
3509
3567
|
providerOptions: {
|
|
@@ -3550,8 +3608,8 @@ var GoogleBatch = class {
|
|
|
3550
3608
|
}
|
|
3551
3609
|
};
|
|
3552
3610
|
function convertGoogleBatchStatus(operation) {
|
|
3553
|
-
var
|
|
3554
|
-
const rawStatus = (_b = (
|
|
3611
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
3612
|
+
const rawStatus = (_b = (_a2 = operation.metadata) == null ? void 0 : _a2.state) != null ? _b : void 0;
|
|
3555
3613
|
const requestCounts = convertGoogleRequestCounts(
|
|
3556
3614
|
(_c = operation.metadata) == null ? void 0 : _c.batchStats
|
|
3557
3615
|
);
|
|
@@ -3596,9 +3654,9 @@ function mapGoogleBatchStatus({
|
|
|
3596
3654
|
}
|
|
3597
3655
|
}
|
|
3598
3656
|
function convertGoogleRequestCounts(counts) {
|
|
3599
|
-
var
|
|
3657
|
+
var _a2, _b, _c;
|
|
3600
3658
|
const total = parseCount(counts == null ? void 0 : counts.requestCount);
|
|
3601
|
-
const completed = parseCount((
|
|
3659
|
+
const completed = parseCount((_a2 = counts == null ? void 0 : counts.successfulRequestCount) != null ? _a2 : 0);
|
|
3602
3660
|
const failed = parseCount((_b = counts == null ? void 0 : counts.failedRequestCount) != null ? _b : 0);
|
|
3603
3661
|
const pending = parseCount((_c = counts == null ? void 0 : counts.pendingRequestCount) != null ? _c : 0);
|
|
3604
3662
|
return normalizeBatchRequestCounts({
|
|
@@ -3613,9 +3671,9 @@ function parseCount(value) {
|
|
|
3613
3671
|
return typeof count === "number" && Number.isSafeInteger(count) && count >= 0 ? count : void 0;
|
|
3614
3672
|
}
|
|
3615
3673
|
function convertGoogleRpcError(error, fallbackMessage) {
|
|
3616
|
-
var
|
|
3674
|
+
var _a2;
|
|
3617
3675
|
return {
|
|
3618
|
-
message: (
|
|
3676
|
+
message: (_a2 = error.message) != null ? _a2 : fallbackMessage,
|
|
3619
3677
|
...error.status != null ? { type: error.status } : {},
|
|
3620
3678
|
...error.code != null ? { code: String(error.code) } : {}
|
|
3621
3679
|
};
|
|
@@ -3633,8 +3691,8 @@ var googleUploadUrlResponseHandler = async ({
|
|
|
3633
3691
|
return { value: uploadUrl };
|
|
3634
3692
|
};
|
|
3635
3693
|
function getGoogleBatchModelId(requests) {
|
|
3636
|
-
var
|
|
3637
|
-
const modelId = (
|
|
3694
|
+
var _a2;
|
|
3695
|
+
const modelId = (_a2 = requests[0]) == null ? void 0 : _a2.modelId;
|
|
3638
3696
|
if (modelId == null) {
|
|
3639
3697
|
throw new InvalidArgumentError({
|
|
3640
3698
|
argument: "requests",
|
|
@@ -3652,12 +3710,12 @@ function getGoogleBatchModelId(requests) {
|
|
|
3652
3710
|
return modelId;
|
|
3653
3711
|
}
|
|
3654
3712
|
function convertGoogleImageBatchResult(result) {
|
|
3655
|
-
var
|
|
3713
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
3656
3714
|
const images = result.content.flatMap(
|
|
3657
3715
|
(part) => part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data" ? [convertToBase642(part.data.data)] : []
|
|
3658
3716
|
);
|
|
3659
3717
|
if (images.length === 0) return void 0;
|
|
3660
|
-
const googleMetadata = (_b = (
|
|
3718
|
+
const googleMetadata = (_b = (_a2 = result.providerMetadata) == null ? void 0 : _a2.google) != null ? _b : {};
|
|
3661
3719
|
return {
|
|
3662
3720
|
images,
|
|
3663
3721
|
warnings: result.warnings,
|
|
@@ -3677,21 +3735,6 @@ function convertGoogleImageBatchResult(result) {
|
|
|
3677
3735
|
};
|
|
3678
3736
|
}
|
|
3679
3737
|
|
|
3680
|
-
// src/tool/code-execution.ts
|
|
3681
|
-
import { createProviderExecutedToolFactory as createProviderExecutedToolFactory2 } from "@ai-sdk/provider-utils";
|
|
3682
|
-
import { z as z9 } from "zod/v4";
|
|
3683
|
-
var codeExecution = createProviderExecutedToolFactory2({
|
|
3684
|
-
id: "google.code_execution",
|
|
3685
|
-
inputSchema: z9.object({
|
|
3686
|
-
language: z9.string().describe("The programming language of the code."),
|
|
3687
|
-
code: z9.string().describe("The code to be executed.")
|
|
3688
|
-
}),
|
|
3689
|
-
outputSchema: z9.object({
|
|
3690
|
-
outcome: z9.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
|
|
3691
|
-
output: z9.string().describe("The output from the code execution.")
|
|
3692
|
-
})
|
|
3693
|
-
});
|
|
3694
|
-
|
|
3695
3738
|
// src/tool/enterprise-web-search.ts
|
|
3696
3739
|
import {
|
|
3697
3740
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory3,
|
|
@@ -3868,7 +3911,7 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
3868
3911
|
return this.config.provider;
|
|
3869
3912
|
}
|
|
3870
3913
|
async doGenerate(options) {
|
|
3871
|
-
var
|
|
3914
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3872
3915
|
if (!this.modelId.startsWith("gemini-")) {
|
|
3873
3916
|
throw new Error(
|
|
3874
3917
|
"Google image models other than Gemini are no longer supported. Use a model ID that starts with `gemini-`."
|
|
@@ -3935,7 +3978,7 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
3935
3978
|
responseModalities: _strippedResponseModalities,
|
|
3936
3979
|
imageConfig: userImageConfig,
|
|
3937
3980
|
...passthroughGoogleOptions
|
|
3938
|
-
} = (
|
|
3981
|
+
} = (_a2 = providerOptions == null ? void 0 : providerOptions.google) != null ? _a2 : {};
|
|
3939
3982
|
const languageModel = new GoogleLanguageModel(this.modelId, {
|
|
3940
3983
|
provider: this.config.provider,
|
|
3941
3984
|
baseURL: this.config.baseURL,
|
|
@@ -4030,7 +4073,7 @@ var GoogleFiles = class {
|
|
|
4030
4073
|
return this.config.provider;
|
|
4031
4074
|
}
|
|
4032
4075
|
async uploadFile(options) {
|
|
4033
|
-
var
|
|
4076
|
+
var _a2, _b, _c, _d;
|
|
4034
4077
|
const googleOptions = await parseProviderOptions5({
|
|
4035
4078
|
provider: "google",
|
|
4036
4079
|
providerOptions: options.providerOptions,
|
|
@@ -4040,7 +4083,7 @@ var GoogleFiles = class {
|
|
|
4040
4083
|
this.config.headers(),
|
|
4041
4084
|
options.headers
|
|
4042
4085
|
);
|
|
4043
|
-
const fetchFn = (
|
|
4086
|
+
const fetchFn = (_a2 = this.config.fetch) != null ? _a2 : globalThis.fetch;
|
|
4044
4087
|
const warnings = [];
|
|
4045
4088
|
if (options.filename != null) {
|
|
4046
4089
|
warnings.push({ type: "unsupported", feature: "filename" });
|
|
@@ -4221,16 +4264,16 @@ var googleVideoModelOptionsSchema = lazySchema15(
|
|
|
4221
4264
|
|
|
4222
4265
|
// src/google-video-model.ts
|
|
4223
4266
|
function getFirstFrameImage(options) {
|
|
4224
|
-
var
|
|
4225
|
-
return (_b = (
|
|
4267
|
+
var _a2, _b;
|
|
4268
|
+
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
4226
4269
|
}
|
|
4227
4270
|
function resolveStartImage(options) {
|
|
4228
|
-
var
|
|
4229
|
-
return (
|
|
4271
|
+
var _a2;
|
|
4272
|
+
return (_a2 = getFirstFrameImage(options)) != null ? _a2 : options.image;
|
|
4230
4273
|
}
|
|
4231
4274
|
function getLastFrameImage(options) {
|
|
4232
|
-
var
|
|
4233
|
-
return (_b = (
|
|
4275
|
+
var _a2, _b;
|
|
4276
|
+
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
4234
4277
|
}
|
|
4235
4278
|
function getInputReferences(options) {
|
|
4236
4279
|
if (options.frameImages != null && options.frameImages.length > 0) {
|
|
@@ -4376,9 +4419,9 @@ var GoogleVideoModel = class {
|
|
|
4376
4419
|
return { instances, parameters, warnings, googleOptions };
|
|
4377
4420
|
}
|
|
4378
4421
|
async buildCompletedResult(finalOperation, responseHeaders, warnings, currentDate) {
|
|
4379
|
-
var
|
|
4422
|
+
var _a2, _b;
|
|
4380
4423
|
const response = finalOperation.response;
|
|
4381
|
-
if (!((
|
|
4424
|
+
if (!((_a2 = response == null ? void 0 : response.generateVideoResponse) == null ? void 0 : _a2.generatedSamples) || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
4382
4425
|
throw new AISDKError2({
|
|
4383
4426
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
4384
4427
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
@@ -4424,8 +4467,8 @@ var GoogleVideoModel = class {
|
|
|
4424
4467
|
};
|
|
4425
4468
|
}
|
|
4426
4469
|
async doStart(options) {
|
|
4427
|
-
var
|
|
4428
|
-
const currentDate = (_c = (_b = (
|
|
4470
|
+
var _a2, _b, _c;
|
|
4471
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4429
4472
|
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
4430
4473
|
const { value: operation, responseHeaders } = await postJsonToApi4({
|
|
4431
4474
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
@@ -4462,8 +4505,8 @@ var GoogleVideoModel = class {
|
|
|
4462
4505
|
};
|
|
4463
4506
|
}
|
|
4464
4507
|
async doStatus(options) {
|
|
4465
|
-
var
|
|
4466
|
-
const currentDate = (_c = (_b = (
|
|
4508
|
+
var _a2, _b, _c;
|
|
4509
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4467
4510
|
const { operationName } = options.operation;
|
|
4468
4511
|
const { value: statusOperation, responseHeaders } = await getFromApi3({
|
|
4469
4512
|
url: `${this.config.baseURL}/${operationName}`,
|
|
@@ -4530,6 +4573,9 @@ var googleOperationSchema = z17.object({
|
|
|
4530
4573
|
});
|
|
4531
4574
|
|
|
4532
4575
|
// src/google-speech-model.ts
|
|
4576
|
+
import {
|
|
4577
|
+
InvalidArgumentError as InvalidArgumentError2
|
|
4578
|
+
} from "@ai-sdk/provider";
|
|
4533
4579
|
import {
|
|
4534
4580
|
combineHeaders as combineHeaders6,
|
|
4535
4581
|
convertBase64ToUint8Array,
|
|
@@ -4566,6 +4612,37 @@ var googleSpeechResponseSchema = lazySchema16(
|
|
|
4566
4612
|
)
|
|
4567
4613
|
);
|
|
4568
4614
|
|
|
4615
|
+
// src/google-speech-input.ts
|
|
4616
|
+
function getGoogleSpeechInput({
|
|
4617
|
+
text,
|
|
4618
|
+
voice,
|
|
4619
|
+
providerOptions
|
|
4620
|
+
}) {
|
|
4621
|
+
const google2 = providerOptions == null ? void 0 : providerOptions.google;
|
|
4622
|
+
const options = google2 != null && typeof google2 === "object" ? google2 : void 0;
|
|
4623
|
+
const turns = options && "turns" in options ? options.turns : void 0;
|
|
4624
|
+
const turnTexts = [];
|
|
4625
|
+
if (Array.isArray(turns) && turns.length > 0) {
|
|
4626
|
+
for (const turn of turns) {
|
|
4627
|
+
if (turn == null || typeof turn !== "object" || !("text" in turn) || typeof turn.text !== "string") {
|
|
4628
|
+
break;
|
|
4629
|
+
}
|
|
4630
|
+
turnTexts.push(turn.text);
|
|
4631
|
+
}
|
|
4632
|
+
if (turnTexts.length === turns.length) {
|
|
4633
|
+
text = turnTexts.join("");
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
const config = options && "multiSpeakerVoiceConfig" in options ? options.multiSpeakerVoiceConfig : void 0;
|
|
4637
|
+
const speakers = config != null && typeof config === "object" && "speakerVoiceConfigs" in config && Array.isArray(config.speakerVoiceConfigs) ? config.speakerVoiceConfigs : [];
|
|
4638
|
+
return {
|
|
4639
|
+
text,
|
|
4640
|
+
usesCustomVoice: (voice == null ? void 0 : voice.startsWith("voice_")) === true || (voice == null ? void 0 : voice.startsWith("voicekey_")) === true || speakers.some(
|
|
4641
|
+
(speaker) => speaker != null && typeof speaker === "object" && "voiceConfig" in speaker && speaker.voiceConfig != null && typeof speaker.voiceConfig === "object" && "voice" in speaker.voiceConfig
|
|
4642
|
+
)
|
|
4643
|
+
};
|
|
4644
|
+
}
|
|
4645
|
+
|
|
4569
4646
|
// src/google-speech-model-options.ts
|
|
4570
4647
|
import {
|
|
4571
4648
|
lazySchema as lazySchema17,
|
|
@@ -4576,15 +4653,34 @@ var prebuiltVoiceConfigSchema = z19.object({
|
|
|
4576
4653
|
voiceName: z19.string()
|
|
4577
4654
|
});
|
|
4578
4655
|
var voiceConfigSchema = z19.object({
|
|
4579
|
-
prebuiltVoiceConfig: prebuiltVoiceConfigSchema
|
|
4656
|
+
prebuiltVoiceConfig: prebuiltVoiceConfigSchema,
|
|
4657
|
+
voice: z19.never().optional()
|
|
4658
|
+
});
|
|
4659
|
+
var speechMetadataSchema = z19.object({
|
|
4660
|
+
speaker: z19.string().min(1).optional(),
|
|
4661
|
+
style: z19.string().optional()
|
|
4580
4662
|
});
|
|
4581
4663
|
var googleSpeechProviderOptionsSchema = lazySchema17(
|
|
4582
4664
|
() => zodSchema17(
|
|
4583
4665
|
z19.object({
|
|
4666
|
+
/** Turn-level directions for the top-level text, for Gemini 3.8 TTS. */
|
|
4667
|
+
speechMetadata: speechMetadataSchema.optional(),
|
|
4668
|
+
/**
|
|
4669
|
+
* Structured transcript for Gemini 3.8 TTS. Replaces the top-level text;
|
|
4670
|
+
* pass text: '' when using turns. Each multi-speaker turn must name a
|
|
4671
|
+
* configured speaker in speechMetadata. Per-turn styles override instructions.
|
|
4672
|
+
*/
|
|
4673
|
+
turns: z19.array(
|
|
4674
|
+
z19.object({
|
|
4675
|
+
text: z19.string(),
|
|
4676
|
+
speechMetadata: speechMetadataSchema.optional()
|
|
4677
|
+
})
|
|
4678
|
+
).min(1).optional(),
|
|
4584
4679
|
/**
|
|
4585
4680
|
* Multi-speaker configuration for dialogue audio. When provided, this
|
|
4586
4681
|
* overrides the top-level `voice`. The Gemini TTS API supports up to two
|
|
4587
|
-
* speakers
|
|
4682
|
+
* speakers. For Gemini 3.8, each turn's speechMetadata.speaker must match
|
|
4683
|
+
* a configured speaker; older models use speaker labels in the text.
|
|
4588
4684
|
*
|
|
4589
4685
|
* https://ai.google.dev/gemini-api/docs/speech-generation#multi-speaker
|
|
4590
4686
|
*/
|
|
@@ -4630,6 +4726,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4630
4726
|
language,
|
|
4631
4727
|
providerOptions
|
|
4632
4728
|
}) {
|
|
4729
|
+
var _a2;
|
|
4633
4730
|
const warnings = [];
|
|
4634
4731
|
const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
|
|
4635
4732
|
let googleOptions;
|
|
@@ -4650,10 +4747,22 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4650
4747
|
schema: googleSpeechProviderOptionsSchema
|
|
4651
4748
|
});
|
|
4652
4749
|
}
|
|
4750
|
+
const usesStructuredSpeech = !this.modelId.startsWith("gemini-2.5-") && !this.modelId.startsWith("gemini-3.1-");
|
|
4751
|
+
const input = getGoogleSpeechInput({
|
|
4752
|
+
text,
|
|
4753
|
+
voice,
|
|
4754
|
+
providerOptions: { google: googleOptions }
|
|
4755
|
+
});
|
|
4756
|
+
if (input.usesCustomVoice) {
|
|
4757
|
+
throw new InvalidArgumentError2({
|
|
4758
|
+
argument: "voice",
|
|
4759
|
+
message: "Custom voices are not supported. Use a prebuilt voice instead."
|
|
4760
|
+
});
|
|
4761
|
+
}
|
|
4653
4762
|
const multiSpeakerVoiceConfig = googleOptions == null ? void 0 : googleOptions.multiSpeakerVoiceConfig;
|
|
4654
4763
|
const speechConfig = multiSpeakerVoiceConfig ? { multiSpeakerVoiceConfig } : { voiceConfig: { prebuiltVoiceConfig: { voiceName: voice } } };
|
|
4655
4764
|
let promptText = text;
|
|
4656
|
-
if (instructions != null) {
|
|
4765
|
+
if (instructions != null && !usesStructuredSpeech) {
|
|
4657
4766
|
if (multiSpeakerVoiceConfig) {
|
|
4658
4767
|
warnings.push({
|
|
4659
4768
|
type: "unsupported",
|
|
@@ -4664,6 +4773,52 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4664
4773
|
promptText = `${instructions}: ${text}`;
|
|
4665
4774
|
}
|
|
4666
4775
|
}
|
|
4776
|
+
let parts = [{ text: promptText }];
|
|
4777
|
+
if (usesStructuredSpeech) {
|
|
4778
|
+
if ((googleOptions == null ? void 0 : googleOptions.turns) && googleOptions.speechMetadata) {
|
|
4779
|
+
throw new InvalidArgumentError2({
|
|
4780
|
+
argument: "providerOptions",
|
|
4781
|
+
message: "Set speechMetadata on each turn when using turns."
|
|
4782
|
+
});
|
|
4783
|
+
}
|
|
4784
|
+
if ((googleOptions == null ? void 0 : googleOptions.turns) && text !== "") {
|
|
4785
|
+
warnings.push({
|
|
4786
|
+
type: "unsupported",
|
|
4787
|
+
feature: "text",
|
|
4788
|
+
details: "Google TTS turns replace the top-level text."
|
|
4789
|
+
});
|
|
4790
|
+
}
|
|
4791
|
+
parts = ((_a2 = googleOptions == null ? void 0 : googleOptions.turns) != null ? _a2 : [
|
|
4792
|
+
{ text, speechMetadata: googleOptions == null ? void 0 : googleOptions.speechMetadata }
|
|
4793
|
+
]).map((part) => {
|
|
4794
|
+
var _a3, _b, _c;
|
|
4795
|
+
const style = (_b = (_a3 = part.speechMetadata) == null ? void 0 : _a3.style) != null ? _b : instructions;
|
|
4796
|
+
const speaker = (_c = part.speechMetadata) == null ? void 0 : _c.speaker;
|
|
4797
|
+
if (multiSpeakerVoiceConfig && !multiSpeakerVoiceConfig.speakerVoiceConfigs.some(
|
|
4798
|
+
(config) => config.speaker === speaker
|
|
4799
|
+
)) {
|
|
4800
|
+
throw new InvalidArgumentError2({
|
|
4801
|
+
argument: "speechMetadata.speaker",
|
|
4802
|
+
message: "Every multi-speaker turn must specify a speechMetadata.speaker matching a configured speaker."
|
|
4803
|
+
});
|
|
4804
|
+
}
|
|
4805
|
+
return {
|
|
4806
|
+
text: part.text,
|
|
4807
|
+
...style != null || speaker != null ? { speechMetadata: { style, speaker } } : {}
|
|
4808
|
+
};
|
|
4809
|
+
});
|
|
4810
|
+
} else if ((googleOptions == null ? void 0 : googleOptions.turns) || (googleOptions == null ? void 0 : googleOptions.speechMetadata)) {
|
|
4811
|
+
throw new InvalidArgumentError2({
|
|
4812
|
+
argument: "providerOptions",
|
|
4813
|
+
message: "Structured speech metadata and turns require Gemini 3.8 TTS."
|
|
4814
|
+
});
|
|
4815
|
+
}
|
|
4816
|
+
if (input.text.length === 0) {
|
|
4817
|
+
throw new InvalidArgumentError2({
|
|
4818
|
+
argument: "text",
|
|
4819
|
+
message: "Speech input must contain a non-empty transcript."
|
|
4820
|
+
});
|
|
4821
|
+
}
|
|
4667
4822
|
if (speed != null) {
|
|
4668
4823
|
warnings.push({
|
|
4669
4824
|
type: "unsupported",
|
|
@@ -4678,10 +4833,20 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4678
4833
|
details: "Google Gemini TTS models do not support the `language` option. Language is detected automatically from the input text."
|
|
4679
4834
|
});
|
|
4680
4835
|
}
|
|
4836
|
+
const formats = usesStructuredSpeech ? {
|
|
4837
|
+
wav: "AUDIO_WAV",
|
|
4838
|
+
"audio/wav": "AUDIO_WAV",
|
|
4839
|
+
pcm: "AUDIO_L16",
|
|
4840
|
+
"audio/l16": "AUDIO_L16",
|
|
4841
|
+
mulaw: "AUDIO_MULAW",
|
|
4842
|
+
"audio/mulaw": "AUDIO_MULAW",
|
|
4843
|
+
alaw: "AUDIO_ALAW",
|
|
4844
|
+
"audio/alaw": "AUDIO_ALAW"
|
|
4845
|
+
} : { wav: "AUDIO_WAV", pcm: "AUDIO_L16" };
|
|
4681
4846
|
let resolvedOutputFormat = "wav";
|
|
4682
|
-
if (outputFormat
|
|
4683
|
-
resolvedOutputFormat =
|
|
4684
|
-
} else if (outputFormat != null
|
|
4847
|
+
if (outputFormat != null && Object.prototype.hasOwnProperty.call(formats, outputFormat)) {
|
|
4848
|
+
resolvedOutputFormat = outputFormat;
|
|
4849
|
+
} else if (outputFormat != null) {
|
|
4685
4850
|
warnings.push({
|
|
4686
4851
|
type: "unsupported",
|
|
4687
4852
|
feature: "outputFormat",
|
|
@@ -4689,18 +4854,28 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4689
4854
|
});
|
|
4690
4855
|
}
|
|
4691
4856
|
const requestBody = {
|
|
4692
|
-
contents: [{ role: "user", parts
|
|
4857
|
+
contents: [{ role: "user", parts }],
|
|
4693
4858
|
generationConfig: {
|
|
4694
4859
|
responseModalities: ["AUDIO"],
|
|
4695
|
-
speechConfig
|
|
4860
|
+
speechConfig,
|
|
4861
|
+
...usesStructuredSpeech && outputFormat != null ? {
|
|
4862
|
+
responseFormat: {
|
|
4863
|
+
audio: { mimeType: formats[resolvedOutputFormat] }
|
|
4864
|
+
}
|
|
4865
|
+
} : {}
|
|
4696
4866
|
}
|
|
4697
4867
|
};
|
|
4698
|
-
return {
|
|
4868
|
+
return {
|
|
4869
|
+
requestBody,
|
|
4870
|
+
warnings,
|
|
4871
|
+
outputFormat: formats[resolvedOutputFormat],
|
|
4872
|
+
usesStructuredSpeech
|
|
4873
|
+
};
|
|
4699
4874
|
}
|
|
4700
4875
|
async doGenerate(options) {
|
|
4701
|
-
var
|
|
4702
|
-
const currentDate = (_c = (_b = (
|
|
4703
|
-
const { requestBody, warnings, outputFormat } = await this.getArgs(options);
|
|
4876
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4877
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4878
|
+
const { requestBody, warnings, outputFormat, usesStructuredSpeech } = await this.getArgs(options);
|
|
4704
4879
|
const {
|
|
4705
4880
|
value: response,
|
|
4706
4881
|
responseHeaders,
|
|
@@ -4734,9 +4909,10 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4734
4909
|
}
|
|
4735
4910
|
}
|
|
4736
4911
|
const sampleRate = (_i = parseSampleRate(mimeType)) != null ? _i : DEFAULT_SAMPLE_RATE;
|
|
4737
|
-
const
|
|
4738
|
-
const
|
|
4739
|
-
|
|
4912
|
+
const bytes = base64Audio != null ? convertBase64ToUint8Array(base64Audio) : new Uint8Array(0);
|
|
4913
|
+
const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType != null ? mimeType : "") || mimeType == null && !usesStructuredSpeech;
|
|
4914
|
+
const audio = outputFormat === "AUDIO_WAV" && isPcm && bytes.length > 0 ? addWavHeader(bytes, sampleRate) : bytes;
|
|
4915
|
+
if (outputFormat === "AUDIO_L16" && bytes.length > 0 && !usesStructuredSpeech) {
|
|
4740
4916
|
warnings.push({
|
|
4741
4917
|
type: "unsupported",
|
|
4742
4918
|
feature: "outputFormat",
|
|
@@ -4824,11 +5000,11 @@ import {
|
|
|
4824
5000
|
// src/interactions/convert-google-interactions-usage.ts
|
|
4825
5001
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
|
|
4826
5002
|
function convertGoogleInteractionsUsage(usage) {
|
|
4827
|
-
var
|
|
5003
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
4828
5004
|
if (usage == null) {
|
|
4829
5005
|
return createNullLanguageModelUsage2();
|
|
4830
5006
|
}
|
|
4831
|
-
const totalInput = (
|
|
5007
|
+
const totalInput = (_a2 = usage.total_input_tokens) != null ? _a2 : 0;
|
|
4832
5008
|
const totalOutput = (_b = usage.total_output_tokens) != null ? _b : 0;
|
|
4833
5009
|
const totalThought = (_c = usage.total_thought_tokens) != null ? _c : 0;
|
|
4834
5010
|
const totalCached = (_d = usage.total_cached_tokens) != null ? _d : 0;
|
|
@@ -4886,7 +5062,7 @@ function annotationToSource({
|
|
|
4886
5062
|
annotation,
|
|
4887
5063
|
generateId: generateId4
|
|
4888
5064
|
}) {
|
|
4889
|
-
var
|
|
5065
|
+
var _a2, _b, _c, _d, _e;
|
|
4890
5066
|
switch (annotation.type) {
|
|
4891
5067
|
case "url_citation": {
|
|
4892
5068
|
const urlCitation = annotation;
|
|
@@ -4903,7 +5079,7 @@ function annotationToSource({
|
|
|
4903
5079
|
}
|
|
4904
5080
|
case "file_citation": {
|
|
4905
5081
|
const fileCitation = annotation;
|
|
4906
|
-
const uri = (_b = (
|
|
5082
|
+
const uri = (_b = (_a2 = fileCitation.url) != null ? _a2 : fileCitation.document_uri) != null ? _b : fileCitation.file_name;
|
|
4907
5083
|
if (uri == null || uri.length === 0) return void 0;
|
|
4908
5084
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
4909
5085
|
return {
|
|
@@ -4946,11 +5122,11 @@ function builtinToolResultToSources({
|
|
|
4946
5122
|
block,
|
|
4947
5123
|
generateId: generateId4
|
|
4948
5124
|
}) {
|
|
4949
|
-
var
|
|
5125
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4950
5126
|
const sources = [];
|
|
4951
5127
|
switch (block.type) {
|
|
4952
5128
|
case "url_context_result": {
|
|
4953
|
-
const result = (
|
|
5129
|
+
const result = (_a2 = block.result) != null ? _a2 : [];
|
|
4954
5130
|
for (const entry of result) {
|
|
4955
5131
|
if ((entry == null ? void 0 : entry.url) == null || entry.url.length === 0) continue;
|
|
4956
5132
|
if (entry.status != null && entry.status !== "success") continue;
|
|
@@ -5033,14 +5209,14 @@ function annotationsToSources({
|
|
|
5033
5209
|
annotations,
|
|
5034
5210
|
generateId: generateId4
|
|
5035
5211
|
}) {
|
|
5036
|
-
var
|
|
5212
|
+
var _a2;
|
|
5037
5213
|
if (annotations == null) return [];
|
|
5038
5214
|
const seen = /* @__PURE__ */ new Set();
|
|
5039
5215
|
const sources = [];
|
|
5040
5216
|
for (const annotation of annotations) {
|
|
5041
5217
|
const source = annotationToSource({ annotation, generateId: generateId4 });
|
|
5042
5218
|
if (source == null) continue;
|
|
5043
|
-
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(
|
|
5219
|
+
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
5044
5220
|
if (seen.has(key)) continue;
|
|
5045
5221
|
seen.add(key);
|
|
5046
5222
|
sources.push(source);
|
|
@@ -5107,15 +5283,15 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5107
5283
|
const openBlocks = /* @__PURE__ */ new Map();
|
|
5108
5284
|
const emittedSourceKeys = /* @__PURE__ */ new Set();
|
|
5109
5285
|
function sourceKey(source) {
|
|
5110
|
-
var
|
|
5111
|
-
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(
|
|
5286
|
+
var _a2;
|
|
5287
|
+
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
5112
5288
|
}
|
|
5113
5289
|
return new TransformStream({
|
|
5114
5290
|
start(controller) {
|
|
5115
5291
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5116
5292
|
},
|
|
5117
5293
|
transform(chunk, controller) {
|
|
5118
|
-
var
|
|
5294
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
5119
5295
|
if (includeRawChunks) {
|
|
5120
5296
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
5121
5297
|
}
|
|
@@ -5154,7 +5330,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5154
5330
|
const blockId = `${interactionId != null ? interactionId : "interaction"}:${index}`;
|
|
5155
5331
|
const stepType = step == null ? void 0 : step.type;
|
|
5156
5332
|
if (stepType === "model_output") {
|
|
5157
|
-
const initial = (
|
|
5333
|
+
const initial = (_a2 = step == null ? void 0 : step.content) == null ? void 0 : _a2[0];
|
|
5158
5334
|
if ((initial == null ? void 0 : initial.type) === "text") {
|
|
5159
5335
|
openBlocks.set(index, {
|
|
5160
5336
|
kind: "text",
|
|
@@ -5612,7 +5788,7 @@ function convertToGoogleInteractionsInput({
|
|
|
5612
5788
|
store,
|
|
5613
5789
|
mediaResolution
|
|
5614
5790
|
}) {
|
|
5615
|
-
var
|
|
5791
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
5616
5792
|
const warnings = [];
|
|
5617
5793
|
const incoherentCombo = previousInteractionId != null && store === false;
|
|
5618
5794
|
const shouldCompact = previousInteractionId != null && store !== false;
|
|
@@ -5669,7 +5845,7 @@ function convertToGoogleInteractionsInput({
|
|
|
5669
5845
|
pendingModelOutput.push({ type: "text", text: part.text });
|
|
5670
5846
|
} else if (part.type === "reasoning") {
|
|
5671
5847
|
flushModelOutput();
|
|
5672
|
-
const signature = (_b = (
|
|
5848
|
+
const signature = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.signature;
|
|
5673
5849
|
steps.push({
|
|
5674
5850
|
type: "thought",
|
|
5675
5851
|
...signature != null ? { signature } : {},
|
|
@@ -5834,8 +6010,8 @@ function getVideoProcessingField({
|
|
|
5834
6010
|
part,
|
|
5835
6011
|
warnings
|
|
5836
6012
|
}) {
|
|
5837
|
-
var
|
|
5838
|
-
const processing = (_b = (
|
|
6013
|
+
var _a2, _b;
|
|
6014
|
+
const processing = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.processing;
|
|
5839
6015
|
if (processing == null) {
|
|
5840
6016
|
return {};
|
|
5841
6017
|
}
|
|
@@ -5868,8 +6044,8 @@ function compactPromptForPreviousInteraction({
|
|
|
5868
6044
|
for (const message of prompt) {
|
|
5869
6045
|
if (message.role === "assistant") {
|
|
5870
6046
|
const matchesLinkedInteraction = message.content.some((part) => {
|
|
5871
|
-
var
|
|
5872
|
-
const partInteractionId = (_b = (
|
|
6047
|
+
var _a2, _b;
|
|
6048
|
+
const partInteractionId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.interactionId;
|
|
5873
6049
|
return partInteractionId === previousInteractionId;
|
|
5874
6050
|
});
|
|
5875
6051
|
if (matchesLinkedInteraction) {
|
|
@@ -5921,7 +6097,7 @@ function convertToolResultPart({
|
|
|
5921
6097
|
signature,
|
|
5922
6098
|
warnings
|
|
5923
6099
|
}) {
|
|
5924
|
-
var
|
|
6100
|
+
var _a2;
|
|
5925
6101
|
const base = {
|
|
5926
6102
|
type: "function_result",
|
|
5927
6103
|
call_id: toolCallId,
|
|
@@ -5941,7 +6117,7 @@ function convertToolResultPart({
|
|
|
5941
6117
|
return {
|
|
5942
6118
|
...base,
|
|
5943
6119
|
is_error: true,
|
|
5944
|
-
result: (
|
|
6120
|
+
result: (_a2 = output.reason) != null ? _a2 : "Tool execution denied by user."
|
|
5945
6121
|
};
|
|
5946
6122
|
case "content": {
|
|
5947
6123
|
const blocks = [];
|
|
@@ -6632,7 +6808,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
6632
6808
|
generateId: generateId4,
|
|
6633
6809
|
interactionId
|
|
6634
6810
|
}) {
|
|
6635
|
-
var
|
|
6811
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
6636
6812
|
const content = [];
|
|
6637
6813
|
let hasFunctionCall = false;
|
|
6638
6814
|
if (steps == null) {
|
|
@@ -6647,7 +6823,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
6647
6823
|
break;
|
|
6648
6824
|
}
|
|
6649
6825
|
case "model_output": {
|
|
6650
|
-
const blocks = (
|
|
6826
|
+
const blocks = (_a2 = step.content) != null ? _a2 : [];
|
|
6651
6827
|
for (const block of blocks) {
|
|
6652
6828
|
if (block == null || typeof block !== "object") continue;
|
|
6653
6829
|
const blockType = block.type;
|
|
@@ -6910,7 +7086,7 @@ function prepareGoogleInteractionsTools({
|
|
|
6910
7086
|
tools,
|
|
6911
7087
|
toolChoice
|
|
6912
7088
|
}) {
|
|
6913
|
-
var
|
|
7089
|
+
var _a2, _b, _c, _d;
|
|
6914
7090
|
const toolWarnings = [];
|
|
6915
7091
|
const normalized = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
6916
7092
|
if (normalized == null) {
|
|
@@ -6922,7 +7098,7 @@ function prepareGoogleInteractionsTools({
|
|
|
6922
7098
|
interactionsTools.push({
|
|
6923
7099
|
type: "function",
|
|
6924
7100
|
name: tool.name,
|
|
6925
|
-
description: (
|
|
7101
|
+
description: (_a2 = tool.description) != null ? _a2 : "",
|
|
6926
7102
|
parameters: tool.inputSchema
|
|
6927
7103
|
});
|
|
6928
7104
|
continue;
|
|
@@ -7232,7 +7408,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7232
7408
|
}) {
|
|
7233
7409
|
return new ReadableStream({
|
|
7234
7410
|
start(controller) {
|
|
7235
|
-
var
|
|
7411
|
+
var _a2, _b, _c;
|
|
7236
7412
|
controller.enqueue({ type: "stream-start", warnings });
|
|
7237
7413
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
7238
7414
|
let timestamp;
|
|
@@ -7246,7 +7422,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7246
7422
|
controller.enqueue({
|
|
7247
7423
|
type: "response-metadata",
|
|
7248
7424
|
...interactionId != null ? { id: interactionId } : {},
|
|
7249
|
-
modelId: (
|
|
7425
|
+
modelId: (_a2 = response.model) != null ? _a2 : void 0,
|
|
7250
7426
|
...timestamp ? { timestamp } : {}
|
|
7251
7427
|
});
|
|
7252
7428
|
if (includeRawChunks) {
|
|
@@ -7413,7 +7589,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7413
7589
|
};
|
|
7414
7590
|
}
|
|
7415
7591
|
async getArgs(options) {
|
|
7416
|
-
var
|
|
7592
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
7417
7593
|
const warnings = [];
|
|
7418
7594
|
const googleOptions = await parseProviderOptions8({
|
|
7419
7595
|
provider: "google",
|
|
@@ -7448,7 +7624,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7448
7624
|
warnings.push(...prepared.toolWarnings);
|
|
7449
7625
|
}
|
|
7450
7626
|
const responseFormatEntries = [];
|
|
7451
|
-
if (((
|
|
7627
|
+
if (((_a2 = options.responseFormat) == null ? void 0 : _a2.type) === "json") {
|
|
7452
7628
|
if (isAgent) {
|
|
7453
7629
|
warnings.push({
|
|
7454
7630
|
type: "other",
|
|
@@ -7609,7 +7785,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7609
7785
|
} else {
|
|
7610
7786
|
const environmentOptions = googleOptions.environment;
|
|
7611
7787
|
const sources = (_A = environmentOptions.sources) == null ? void 0 : _A.map((source) => {
|
|
7612
|
-
var
|
|
7788
|
+
var _a3;
|
|
7613
7789
|
if (source.type === "inline") {
|
|
7614
7790
|
return {
|
|
7615
7791
|
type: "inline",
|
|
@@ -7620,7 +7796,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7620
7796
|
return pruneUndefined({
|
|
7621
7797
|
type: source.type,
|
|
7622
7798
|
source: source.source,
|
|
7623
|
-
target: (
|
|
7799
|
+
target: (_a3 = source.target) != null ? _a3 : void 0
|
|
7624
7800
|
});
|
|
7625
7801
|
});
|
|
7626
7802
|
let network;
|
|
@@ -7630,10 +7806,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7630
7806
|
network = {
|
|
7631
7807
|
allowlist: environmentOptions.network.allowlist.map(
|
|
7632
7808
|
(entry) => {
|
|
7633
|
-
var
|
|
7809
|
+
var _a3;
|
|
7634
7810
|
return pruneUndefined({
|
|
7635
7811
|
domain: entry.domain,
|
|
7636
|
-
transform: (
|
|
7812
|
+
transform: (_a3 = entry.transform) != null ? _a3 : void 0
|
|
7637
7813
|
});
|
|
7638
7814
|
}
|
|
7639
7815
|
)
|
|
@@ -7670,7 +7846,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7670
7846
|
};
|
|
7671
7847
|
}
|
|
7672
7848
|
async doGenerate(options) {
|
|
7673
|
-
var
|
|
7849
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
7674
7850
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
7675
7851
|
const url = `${this.config.baseURL}/interactions`;
|
|
7676
7852
|
const mergedHeaders = combineHeaders8(
|
|
@@ -7704,7 +7880,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7704
7880
|
});
|
|
7705
7881
|
response = polled.response;
|
|
7706
7882
|
rawResponse = polled.rawResponse;
|
|
7707
|
-
responseHeaders = (
|
|
7883
|
+
responseHeaders = (_a2 = polled.responseHeaders) != null ? _a2 : responseHeaders;
|
|
7708
7884
|
}
|
|
7709
7885
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
7710
7886
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
@@ -7754,7 +7930,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7754
7930
|
};
|
|
7755
7931
|
}
|
|
7756
7932
|
async doStream(options) {
|
|
7757
|
-
var
|
|
7933
|
+
var _a2;
|
|
7758
7934
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
7759
7935
|
const url = `${this.config.baseURL}/interactions`;
|
|
7760
7936
|
const mergedHeaders = combineHeaders8(
|
|
@@ -7786,7 +7962,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7786
7962
|
const headerServiceTier = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"];
|
|
7787
7963
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
7788
7964
|
warnings,
|
|
7789
|
-
generateId: (
|
|
7965
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : defaultGenerateId2,
|
|
7790
7966
|
includeRawChunks: options.includeRawChunks,
|
|
7791
7967
|
serviceTier: headerServiceTier
|
|
7792
7968
|
});
|
|
@@ -7822,7 +7998,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7822
7998
|
options,
|
|
7823
7999
|
pollingTimeoutMs
|
|
7824
8000
|
}) {
|
|
7825
|
-
var
|
|
8001
|
+
var _a2, _b;
|
|
7826
8002
|
const postResult = await postJsonToApi6({
|
|
7827
8003
|
url,
|
|
7828
8004
|
headers: mergedHeaders,
|
|
@@ -7846,7 +8022,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7846
8022
|
const synthesized = synthesizeGoogleInteractionsAgentStream({
|
|
7847
8023
|
response: postResponse,
|
|
7848
8024
|
warnings,
|
|
7849
|
-
generateId: (
|
|
8025
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : defaultGenerateId2,
|
|
7850
8026
|
includeRawChunks: options.includeRawChunks,
|
|
7851
8027
|
headerServiceTier
|
|
7852
8028
|
});
|
|
@@ -7938,17 +8114,17 @@ var GoogleRealtimeEventMapper = class {
|
|
|
7938
8114
|
this.turnClosed = false;
|
|
7939
8115
|
}
|
|
7940
8116
|
parseServerEvent(raw) {
|
|
7941
|
-
var
|
|
8117
|
+
var _a2, _b;
|
|
7942
8118
|
const data = raw;
|
|
7943
8119
|
if (data.setupComplete != null) {
|
|
7944
8120
|
return { type: "session-created", raw };
|
|
7945
8121
|
}
|
|
7946
8122
|
if (data.toolCall != null) {
|
|
7947
8123
|
this.beginTurnIfClosed();
|
|
7948
|
-
const functionCalls = (
|
|
8124
|
+
const functionCalls = (_a2 = data.toolCall.functionCalls) != null ? _a2 : [];
|
|
7949
8125
|
return functionCalls.flatMap((functionCall) => {
|
|
7950
|
-
var
|
|
7951
|
-
const args = JSON.stringify((
|
|
8126
|
+
var _a3;
|
|
8127
|
+
const args = JSON.stringify((_a3 = functionCall.args) != null ? _a3 : {});
|
|
7952
8128
|
return [
|
|
7953
8129
|
{
|
|
7954
8130
|
type: "function-call-arguments-delta",
|
|
@@ -8005,7 +8181,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8005
8181
|
return { type: "custom", rawType: String(Object.keys(data)[0]), raw };
|
|
8006
8182
|
}
|
|
8007
8183
|
parseServerContent(serverContent, raw) {
|
|
8008
|
-
var
|
|
8184
|
+
var _a2, _b, _c, _d;
|
|
8009
8185
|
const events = [];
|
|
8010
8186
|
if (serverContent.interrupted) {
|
|
8011
8187
|
events.push({
|
|
@@ -8013,7 +8189,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8013
8189
|
raw
|
|
8014
8190
|
});
|
|
8015
8191
|
}
|
|
8016
|
-
if ((
|
|
8192
|
+
if ((_a2 = serverContent.modelTurn) == null ? void 0 : _a2.parts) {
|
|
8017
8193
|
this.beginTurnIfClosed();
|
|
8018
8194
|
for (const part of serverContent.modelTurn.parts) {
|
|
8019
8195
|
if ((_b = part.inlineData) == null ? void 0 : _b.data) {
|
|
@@ -8116,10 +8292,10 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8116
8292
|
return events.length === 1 ? events[0] : events;
|
|
8117
8293
|
}
|
|
8118
8294
|
serializeClientEvent(event, modelId) {
|
|
8119
|
-
var
|
|
8295
|
+
var _a2;
|
|
8120
8296
|
switch (event.type) {
|
|
8121
8297
|
case "session-update":
|
|
8122
|
-
if (((
|
|
8298
|
+
if (((_a2 = event.config.inputAudioFormat) == null ? void 0 : _a2.rate) != null) {
|
|
8123
8299
|
this.inputAudioRate = event.config.inputAudioFormat.rate;
|
|
8124
8300
|
}
|
|
8125
8301
|
return {
|
|
@@ -8188,16 +8364,16 @@ async function serializeFunctionCallOutput(item) {
|
|
|
8188
8364
|
};
|
|
8189
8365
|
}
|
|
8190
8366
|
function isThinkingLiveModel(modelId) {
|
|
8191
|
-
var
|
|
8192
|
-
const modelName = (_b = (
|
|
8367
|
+
var _a2, _b;
|
|
8368
|
+
const modelName = (_b = (_a2 = modelId.split("/").at(-1)) == null ? void 0 : _a2.toLowerCase()) != null ? _b : "";
|
|
8193
8369
|
return /^gemini-\d+\.\d+-live\b.*thinking/.test(modelName);
|
|
8194
8370
|
}
|
|
8195
8371
|
function buildGoogleSessionConfig(config, modelId) {
|
|
8196
|
-
var
|
|
8372
|
+
var _a2, _b;
|
|
8197
8373
|
const setup = {
|
|
8198
8374
|
model: getModelPath(modelId)
|
|
8199
8375
|
};
|
|
8200
|
-
const { google: google2, ...restProviderOptions } = (
|
|
8376
|
+
const { google: google2, ...restProviderOptions } = (_a2 = config == null ? void 0 : config.providerOptions) != null ? _a2 : {};
|
|
8201
8377
|
const googleOptions = isRecord(google2) ? google2 : void 0;
|
|
8202
8378
|
const generationConfig = {};
|
|
8203
8379
|
if ((config == null ? void 0 : config.outputModalities) != null) {
|
|
@@ -8281,8 +8457,8 @@ var GoogleRealtimeModel = class {
|
|
|
8281
8457
|
this.config = config;
|
|
8282
8458
|
}
|
|
8283
8459
|
async doCreateClientSecret(options) {
|
|
8284
|
-
var
|
|
8285
|
-
const fetchFn = (
|
|
8460
|
+
var _a2, _b;
|
|
8461
|
+
const fetchFn = (_a2 = this.config.fetch) != null ? _a2 : fetch;
|
|
8286
8462
|
const headers = this.config.headers();
|
|
8287
8463
|
const apiKey = headers["x-goog-api-key"];
|
|
8288
8464
|
if (!apiKey) {
|
|
@@ -8347,7 +8523,7 @@ var GoogleRealtimeModel = class {
|
|
|
8347
8523
|
|
|
8348
8524
|
// src/transcription/google-transcription-model.ts
|
|
8349
8525
|
import {
|
|
8350
|
-
InvalidArgumentError as
|
|
8526
|
+
InvalidArgumentError as InvalidArgumentError3
|
|
8351
8527
|
} from "@ai-sdk/provider";
|
|
8352
8528
|
import {
|
|
8353
8529
|
combineHeaders as combineHeaders9,
|
|
@@ -8435,14 +8611,14 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8435
8611
|
});
|
|
8436
8612
|
}
|
|
8437
8613
|
async doGenerate(options) {
|
|
8438
|
-
var
|
|
8614
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
8439
8615
|
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
8440
|
-
throw new
|
|
8616
|
+
throw new InvalidArgumentError3({
|
|
8441
8617
|
argument: "modelId",
|
|
8442
8618
|
message: `Model '${this.modelId}' only supports streaming transcription. Use experimental_streamTranscribe, or a unary model such as 'gemini-3.5-transcribe'.`
|
|
8443
8619
|
});
|
|
8444
8620
|
}
|
|
8445
|
-
const currentDate = (_c = (_b = (
|
|
8621
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
8446
8622
|
const warnings = [];
|
|
8447
8623
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
8448
8624
|
const transcriptionConfig = buildTranscriptionConfig(googleOptions);
|
|
@@ -8512,14 +8688,14 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8512
8688
|
};
|
|
8513
8689
|
}
|
|
8514
8690
|
async doStream(options) {
|
|
8515
|
-
var
|
|
8691
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
8516
8692
|
if (!isLiveTranscriptionModelId(this.modelId)) {
|
|
8517
|
-
throw new
|
|
8693
|
+
throw new InvalidArgumentError3({
|
|
8518
8694
|
argument: "modelId",
|
|
8519
8695
|
message: `Model '${this.modelId}' does not support streaming transcription. Use a live model such as 'gemini-3.5-transcribe-live'.`
|
|
8520
8696
|
});
|
|
8521
8697
|
}
|
|
8522
|
-
const currentDate = (_c = (_b = (
|
|
8698
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
8523
8699
|
const warnings = [];
|
|
8524
8700
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
8525
8701
|
validateLiveInputAudioFormat(options.inputAudioFormat);
|
|
@@ -8704,7 +8880,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8704
8880
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
8705
8881
|
},
|
|
8706
8882
|
onMessageText: async (text) => {
|
|
8707
|
-
var
|
|
8883
|
+
var _a2, _b;
|
|
8708
8884
|
if (finished) return;
|
|
8709
8885
|
const parsed = await safeParseJSON2({ text });
|
|
8710
8886
|
if (!parsed.success) return;
|
|
@@ -8720,7 +8896,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8720
8896
|
}
|
|
8721
8897
|
if (message.error != null) {
|
|
8722
8898
|
finishWithError(
|
|
8723
|
-
new Error((
|
|
8899
|
+
new Error((_a2 = message.error.message) != null ? _a2 : "Google Live API error")
|
|
8724
8900
|
);
|
|
8725
8901
|
return;
|
|
8726
8902
|
}
|
|
@@ -8807,7 +8983,7 @@ function buildAudioTranscriptionConfig(options) {
|
|
|
8807
8983
|
return Object.keys(config).length > 0 ? config : void 0;
|
|
8808
8984
|
}
|
|
8809
8985
|
function buildTranscriptionConfig(options) {
|
|
8810
|
-
var
|
|
8986
|
+
var _a2;
|
|
8811
8987
|
if (options == null) return void 0;
|
|
8812
8988
|
const config = {};
|
|
8813
8989
|
if (options.languageCodes != null) {
|
|
@@ -8818,7 +8994,7 @@ function buildTranscriptionConfig(options) {
|
|
|
8818
8994
|
}
|
|
8819
8995
|
if (options.mode != null || options.diarization === true || options.wordTimestamp === true) {
|
|
8820
8996
|
config.mode = {
|
|
8821
|
-
type: ((
|
|
8997
|
+
type: ((_a2 = options.mode) != null ? _a2 : "VERBATIM").toLowerCase(),
|
|
8822
8998
|
...options.diarization === true ? { diarization_mode: "speaker" } : {},
|
|
8823
8999
|
...options.wordTimestamp === true ? { timestamp_granularities: ["word"] } : {}
|
|
8824
9000
|
};
|
|
@@ -8832,7 +9008,7 @@ function parseOffsetSeconds(offset) {
|
|
|
8832
9008
|
}
|
|
8833
9009
|
function validateLiveInputAudioFormat(inputAudioFormat) {
|
|
8834
9010
|
if (inputAudioFormat.type !== "audio/pcm" || inputAudioFormat.rate != null && inputAudioFormat.rate !== 16e3) {
|
|
8835
|
-
throw new
|
|
9011
|
+
throw new InvalidArgumentError3({
|
|
8836
9012
|
argument: "inputAudioFormat",
|
|
8837
9013
|
message: "The Gemini Live transcription API only supports 16kHz 16-bit PCM input audio."
|
|
8838
9014
|
});
|
|
@@ -8864,7 +9040,7 @@ var googleInteractionsTranscriptionResponseSchema = z23.object({
|
|
|
8864
9040
|
|
|
8865
9041
|
// src/speech-translation/google-speech-translation-model.ts
|
|
8866
9042
|
import {
|
|
8867
|
-
InvalidArgumentError as
|
|
9043
|
+
InvalidArgumentError as InvalidArgumentError4
|
|
8868
9044
|
} from "@ai-sdk/provider";
|
|
8869
9045
|
import {
|
|
8870
9046
|
connectToWebSocket as connectToWebSocket2,
|
|
@@ -8926,14 +9102,14 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
|
|
|
8926
9102
|
return this.config.provider;
|
|
8927
9103
|
}
|
|
8928
9104
|
async doStream(options) {
|
|
8929
|
-
var
|
|
9105
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
8930
9106
|
if (options.targetLanguage == null) {
|
|
8931
|
-
throw new
|
|
9107
|
+
throw new InvalidArgumentError4({
|
|
8932
9108
|
argument: "targetLanguage",
|
|
8933
9109
|
message: `targetLanguage is required for translation model '${this.modelId}'.`
|
|
8934
9110
|
});
|
|
8935
9111
|
}
|
|
8936
|
-
const currentDate = (_c = (_b = (
|
|
9112
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
8937
9113
|
const googleOptions = await parseProviderOptions10({
|
|
8938
9114
|
provider: "google",
|
|
8939
9115
|
providerOptions: options.providerOptions,
|
|
@@ -9149,7 +9325,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9149
9325
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
9150
9326
|
},
|
|
9151
9327
|
onMessageText: async (text) => {
|
|
9152
|
-
var
|
|
9328
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
9153
9329
|
if (finished) return;
|
|
9154
9330
|
const parsed = await safeParseJSON3({ text });
|
|
9155
9331
|
if (!parsed.success) return;
|
|
@@ -9165,7 +9341,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9165
9341
|
}
|
|
9166
9342
|
if (message.error != null) {
|
|
9167
9343
|
finishWithError(
|
|
9168
|
-
new Error((
|
|
9344
|
+
new Error((_a2 = message.error.message) != null ? _a2 : "Google Live API error")
|
|
9169
9345
|
);
|
|
9170
9346
|
return;
|
|
9171
9347
|
}
|
|
@@ -9247,10 +9423,10 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9247
9423
|
});
|
|
9248
9424
|
}
|
|
9249
9425
|
function accumulateGoogleLiveUsage(usage, usageMetadata) {
|
|
9250
|
-
var
|
|
9426
|
+
var _a2, _b;
|
|
9251
9427
|
let inputAudioTokens = usage == null ? void 0 : usage.inputAudioTokens;
|
|
9252
9428
|
let outputAudioTokens = usage == null ? void 0 : usage.outputAudioTokens;
|
|
9253
|
-
for (const detail of (
|
|
9429
|
+
for (const detail of (_a2 = usageMetadata.promptTokensDetails) != null ? _a2 : []) {
|
|
9254
9430
|
if (detail.modality === "AUDIO" && detail.tokenCount != null) {
|
|
9255
9431
|
inputAudioTokens = (inputAudioTokens != null ? inputAudioTokens : 0) + detail.tokenCount;
|
|
9256
9432
|
}
|
|
@@ -9308,7 +9484,7 @@ function buildGoogleLiveSpeechTranslationSetup({
|
|
|
9308
9484
|
}
|
|
9309
9485
|
function validateGoogleSpeechTranslationInputAudioFormat(inputAudioFormat) {
|
|
9310
9486
|
if (inputAudioFormat.type !== "audio/pcm" || inputAudioFormat.rate != null && inputAudioFormat.rate !== 16e3) {
|
|
9311
|
-
throw new
|
|
9487
|
+
throw new InvalidArgumentError4({
|
|
9312
9488
|
argument: "inputAudioFormat",
|
|
9313
9489
|
message: "The Gemini Live translation API only supports 16kHz 16-bit PCM input audio."
|
|
9314
9490
|
});
|
|
@@ -9347,8 +9523,8 @@ function supportsExternalFileUrls(modelId) {
|
|
|
9347
9523
|
return /(^|\/)gemini-/.test(modelId) && !/(^|\/)gemini-2\.0/.test(modelId);
|
|
9348
9524
|
}
|
|
9349
9525
|
function createGoogle(options = {}) {
|
|
9350
|
-
var
|
|
9351
|
-
const baseURL = (
|
|
9526
|
+
var _a2, _b, _c;
|
|
9527
|
+
const baseURL = (_a2 = withoutTrailingSlash(options.baseURL)) != null ? _a2 : DEFAULT_BASE_URL;
|
|
9352
9528
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
9353
9529
|
const getHeaders = () => withUserAgentSuffix2(
|
|
9354
9530
|
{
|
|
@@ -9414,13 +9590,13 @@ function createGoogle(options = {}) {
|
|
|
9414
9590
|
fetch: options.fetch
|
|
9415
9591
|
});
|
|
9416
9592
|
const createVideoModel = (modelId) => {
|
|
9417
|
-
var
|
|
9593
|
+
var _a3;
|
|
9418
9594
|
return new GoogleVideoModel(modelId, {
|
|
9419
9595
|
provider: providerName,
|
|
9420
9596
|
baseURL,
|
|
9421
9597
|
headers: getHeaders,
|
|
9422
9598
|
fetch: options.fetch,
|
|
9423
|
-
generateId: (
|
|
9599
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : generateId3
|
|
9424
9600
|
});
|
|
9425
9601
|
};
|
|
9426
9602
|
const createRealtimeModel = (modelId) => new GoogleRealtimeModel(modelId, {
|
|
@@ -9466,14 +9642,14 @@ function createGoogle(options = {}) {
|
|
|
9466
9642
|
}
|
|
9467
9643
|
);
|
|
9468
9644
|
const createInteractionsModel = (modelIdOrAgent) => {
|
|
9469
|
-
var
|
|
9645
|
+
var _a3;
|
|
9470
9646
|
return new GoogleInteractionsLanguageModel(
|
|
9471
9647
|
modelIdOrAgent,
|
|
9472
9648
|
{
|
|
9473
9649
|
provider: `${providerName}.interactions`,
|
|
9474
9650
|
baseURL,
|
|
9475
9651
|
headers: getHeaders,
|
|
9476
|
-
generateId: (
|
|
9652
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : generateId3,
|
|
9477
9653
|
fetch: options.fetch
|
|
9478
9654
|
}
|
|
9479
9655
|
);
|