@ai-sdk/google 4.0.78 → 4.0.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +588 -398
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +26 -2
- package/dist/internal/index.js +385 -220
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +96 -25
- package/package.json +2 -2
- package/src/convert-to-google-messages.ts +54 -1
- package/src/google-embedding-model.ts +39 -8
- package/src/google-json-accumulator.ts +0 -1
- package/src/google-prompt.ts +12 -0
- package/src/google-speech-api.ts +2 -1
- package/src/google-speech-input.ts +64 -0
- package/src/google-speech-model-options.ts +28 -1
- package/src/google-speech-model.ts +137 -25
- package/src/internal/index.ts +1 -0
- package/src/tool/code-execution.ts +14 -10
package/dist/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.80" : "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) {
|
|
@@ -368,6 +413,20 @@ function convertUrlToolResultPart(url) {
|
|
|
368
413
|
}
|
|
369
414
|
};
|
|
370
415
|
}
|
|
416
|
+
function containsJSONSchemaReference(value) {
|
|
417
|
+
if (Array.isArray(value)) {
|
|
418
|
+
return value.some(containsJSONSchemaReference);
|
|
419
|
+
}
|
|
420
|
+
if (typeof value !== "object" || value === null) {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
return Object.entries(value).some(
|
|
424
|
+
([key, nestedValue]) => key === "$ref" || containsJSONSchemaReference(nestedValue)
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
function serializeFunctionResponseContent(value) {
|
|
428
|
+
return containsJSONSchemaReference(value) ? JSON.stringify(value) : value;
|
|
429
|
+
}
|
|
371
430
|
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
372
431
|
const functionResponseParts = [];
|
|
373
432
|
const responseTextParts = [];
|
|
@@ -458,11 +517,11 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, i
|
|
|
458
517
|
}
|
|
459
518
|
}
|
|
460
519
|
function convertToGoogleMessages(prompt, options) {
|
|
461
|
-
var
|
|
520
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
462
521
|
const systemInstructionParts = [];
|
|
463
522
|
const contents = [];
|
|
464
523
|
let systemMessagesAllowed = true;
|
|
465
|
-
const isGemmaModel = (
|
|
524
|
+
const isGemmaModel = (_a2 = options == null ? void 0 : options.isGemmaModel) != null ? _a2 : false;
|
|
466
525
|
const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
|
|
467
526
|
const onWarning = options == null ? void 0 : options.onWarning;
|
|
468
527
|
const providerOptionsNames = (_c = options == null ? void 0 : options.providerOptionsNames) != null ? _c : ["google"];
|
|
@@ -477,9 +536,9 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
477
536
|
return SKIP_THOUGHT_SIGNATURE_VALIDATOR;
|
|
478
537
|
};
|
|
479
538
|
const readProviderOpts = (part) => {
|
|
480
|
-
var
|
|
539
|
+
var _a3, _b2, _c2, _d2, _e2;
|
|
481
540
|
for (const name of providerOptionsNames) {
|
|
482
|
-
const v = (
|
|
541
|
+
const v = (_a3 = part.providerOptions) == null ? void 0 : _a3[name];
|
|
483
542
|
if (v != null) return v;
|
|
484
543
|
}
|
|
485
544
|
if (isVertexLike) {
|
|
@@ -656,6 +715,13 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
656
715
|
break;
|
|
657
716
|
}
|
|
658
717
|
case "tool-call": {
|
|
718
|
+
if (part.providerExecuted === true && part.toolName === "code_execution") {
|
|
719
|
+
return {
|
|
720
|
+
executableCode: codeExecutionInputSchema.parse(
|
|
721
|
+
typeof part.input === "string" ? secureJsonParse(part.input) : part.input
|
|
722
|
+
)
|
|
723
|
+
};
|
|
724
|
+
}
|
|
659
725
|
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
660
726
|
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
661
727
|
const isServerToolCall = serverToolCallId != null && serverToolType != null;
|
|
@@ -690,6 +756,13 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
690
756
|
};
|
|
691
757
|
}
|
|
692
758
|
case "tool-result": {
|
|
759
|
+
if (part.toolName === "code_execution" && part.output.type === "json") {
|
|
760
|
+
return {
|
|
761
|
+
codeExecutionResult: codeExecutionOutputSchema.parse(
|
|
762
|
+
part.output.value
|
|
763
|
+
)
|
|
764
|
+
};
|
|
765
|
+
}
|
|
693
766
|
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
694
767
|
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
695
768
|
if (serverToolCallId && serverToolType) {
|
|
@@ -762,7 +835,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
762
835
|
name: part.toolName,
|
|
763
836
|
response: {
|
|
764
837
|
name: part.toolName,
|
|
765
|
-
content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : output.value
|
|
838
|
+
content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : serializeFunctionResponseContent(output.value)
|
|
766
839
|
}
|
|
767
840
|
}
|
|
768
841
|
});
|
|
@@ -920,23 +993,23 @@ import {
|
|
|
920
993
|
lazySchema as lazySchema4,
|
|
921
994
|
zodSchema as zodSchema4
|
|
922
995
|
} from "@ai-sdk/provider-utils";
|
|
923
|
-
import { z as
|
|
996
|
+
import { z as z5 } from "zod/v4";
|
|
924
997
|
var googleLanguageModelOptions = lazySchema4(
|
|
925
998
|
() => zodSchema4(
|
|
926
|
-
|
|
927
|
-
responseModalities:
|
|
928
|
-
thinkingConfig:
|
|
929
|
-
thinkingBudget:
|
|
930
|
-
includeThoughts:
|
|
999
|
+
z5.object({
|
|
1000
|
+
responseModalities: z5.array(z5.enum(["TEXT", "IMAGE"])).optional(),
|
|
1001
|
+
thinkingConfig: z5.object({
|
|
1002
|
+
thinkingBudget: z5.number().optional(),
|
|
1003
|
+
includeThoughts: z5.boolean().optional(),
|
|
931
1004
|
// https://ai.google.dev/gemini-api/docs/gemini-3?thinking=high#thinking_level
|
|
932
|
-
thinkingLevel:
|
|
1005
|
+
thinkingLevel: z5.enum(["minimal", "low", "medium", "high"]).optional()
|
|
933
1006
|
}).optional(),
|
|
934
1007
|
/**
|
|
935
1008
|
* Optional.
|
|
936
1009
|
* The name of the cached content used as context to serve the prediction.
|
|
937
1010
|
* Format: cachedContents/{cachedContent}
|
|
938
1011
|
*/
|
|
939
|
-
cachedContent:
|
|
1012
|
+
cachedContent: z5.string().optional(),
|
|
940
1013
|
/**
|
|
941
1014
|
* Optional. Enable structured output. Default is true.
|
|
942
1015
|
*
|
|
@@ -945,13 +1018,13 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
945
1018
|
* Google uses. You can use this to disable
|
|
946
1019
|
* structured outputs if you need to.
|
|
947
1020
|
*/
|
|
948
|
-
structuredOutputs:
|
|
1021
|
+
structuredOutputs: z5.boolean().optional(),
|
|
949
1022
|
/**
|
|
950
1023
|
* Optional. A list of unique safety settings for blocking unsafe content.
|
|
951
1024
|
*/
|
|
952
|
-
safetySettings:
|
|
953
|
-
|
|
954
|
-
category:
|
|
1025
|
+
safetySettings: z5.array(
|
|
1026
|
+
z5.object({
|
|
1027
|
+
category: z5.enum([
|
|
955
1028
|
"HARM_CATEGORY_UNSPECIFIED",
|
|
956
1029
|
"HARM_CATEGORY_HATE_SPEECH",
|
|
957
1030
|
"HARM_CATEGORY_DANGEROUS_CONTENT",
|
|
@@ -959,7 +1032,7 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
959
1032
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
960
1033
|
"HARM_CATEGORY_CIVIC_INTEGRITY"
|
|
961
1034
|
]),
|
|
962
|
-
threshold:
|
|
1035
|
+
threshold: z5.enum([
|
|
963
1036
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
|
964
1037
|
"BLOCK_LOW_AND_ABOVE",
|
|
965
1038
|
"BLOCK_MEDIUM_AND_ABOVE",
|
|
@@ -969,7 +1042,7 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
969
1042
|
])
|
|
970
1043
|
})
|
|
971
1044
|
).optional(),
|
|
972
|
-
threshold:
|
|
1045
|
+
threshold: z5.enum([
|
|
973
1046
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
|
974
1047
|
"BLOCK_LOW_AND_ABOVE",
|
|
975
1048
|
"BLOCK_MEDIUM_AND_ABOVE",
|
|
@@ -982,19 +1055,19 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
982
1055
|
*
|
|
983
1056
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
|
984
1057
|
*/
|
|
985
|
-
audioTimestamp:
|
|
1058
|
+
audioTimestamp: z5.boolean().optional(),
|
|
986
1059
|
/**
|
|
987
1060
|
* Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
|
988
1061
|
*
|
|
989
1062
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
|
|
990
1063
|
*/
|
|
991
|
-
labels:
|
|
1064
|
+
labels: z5.record(z5.string(), z5.string()).optional(),
|
|
992
1065
|
/**
|
|
993
1066
|
* Optional. If specified, the media resolution specified will be used.
|
|
994
1067
|
*
|
|
995
1068
|
* https://ai.google.dev/api/generate-content#MediaResolution
|
|
996
1069
|
*/
|
|
997
|
-
mediaResolution:
|
|
1070
|
+
mediaResolution: z5.enum([
|
|
998
1071
|
"MEDIA_RESOLUTION_UNSPECIFIED",
|
|
999
1072
|
"MEDIA_RESOLUTION_LOW",
|
|
1000
1073
|
"MEDIA_RESOLUTION_MEDIUM",
|
|
@@ -1005,8 +1078,8 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1005
1078
|
*
|
|
1006
1079
|
* https://ai.google.dev/gemini-api/docs/image-generation#aspect_ratios
|
|
1007
1080
|
*/
|
|
1008
|
-
imageConfig:
|
|
1009
|
-
aspectRatio:
|
|
1081
|
+
imageConfig: z5.object({
|
|
1082
|
+
aspectRatio: z5.enum([
|
|
1010
1083
|
"1:1",
|
|
1011
1084
|
"2:3",
|
|
1012
1085
|
"3:2",
|
|
@@ -1022,12 +1095,12 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1022
1095
|
"1:4",
|
|
1023
1096
|
"4:1"
|
|
1024
1097
|
]).optional(),
|
|
1025
|
-
imageSize:
|
|
1098
|
+
imageSize: z5.enum(["1K", "2K", "4K", "512"]).optional(),
|
|
1026
1099
|
/**
|
|
1027
1100
|
* Optional. Controls the generation of people in images.
|
|
1028
1101
|
* Vertex AI only.
|
|
1029
1102
|
*/
|
|
1030
|
-
personGeneration:
|
|
1103
|
+
personGeneration: z5.enum([
|
|
1031
1104
|
"PERSON_GENERATION_UNSPECIFIED",
|
|
1032
1105
|
"ALLOW_ALL",
|
|
1033
1106
|
"ALLOW_ADULT",
|
|
@@ -1041,7 +1114,7 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1041
1114
|
*
|
|
1042
1115
|
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerationConfig
|
|
1043
1116
|
*/
|
|
1044
|
-
prominentPeople:
|
|
1117
|
+
prominentPeople: z5.enum([
|
|
1045
1118
|
"PROMINENT_PEOPLE_UNSPECIFIED",
|
|
1046
1119
|
"ALLOW_PROMINENT_PEOPLE",
|
|
1047
1120
|
"BLOCK_PROMINENT_PEOPLE"
|
|
@@ -1050,9 +1123,9 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1050
1123
|
* Optional. The image output format for generated images.
|
|
1051
1124
|
* Vertex AI only.
|
|
1052
1125
|
*/
|
|
1053
|
-
imageOutputOptions:
|
|
1054
|
-
mimeType:
|
|
1055
|
-
compressionQuality:
|
|
1126
|
+
imageOutputOptions: z5.object({
|
|
1127
|
+
mimeType: z5.enum(["image/jpeg", "image/png"]).optional(),
|
|
1128
|
+
compressionQuality: z5.number().optional()
|
|
1056
1129
|
}).optional()
|
|
1057
1130
|
}).optional(),
|
|
1058
1131
|
/**
|
|
@@ -1061,10 +1134,10 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1061
1134
|
*
|
|
1062
1135
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
|
|
1063
1136
|
*/
|
|
1064
|
-
retrievalConfig:
|
|
1065
|
-
latLng:
|
|
1066
|
-
latitude:
|
|
1067
|
-
longitude:
|
|
1137
|
+
retrievalConfig: z5.object({
|
|
1138
|
+
latLng: z5.object({
|
|
1139
|
+
latitude: z5.number(),
|
|
1140
|
+
longitude: z5.number()
|
|
1068
1141
|
}).optional()
|
|
1069
1142
|
}).optional(),
|
|
1070
1143
|
/**
|
|
@@ -1077,12 +1150,12 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1077
1150
|
*
|
|
1078
1151
|
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
|
|
1079
1152
|
*/
|
|
1080
|
-
streamFunctionCallArguments:
|
|
1153
|
+
streamFunctionCallArguments: z5.boolean().optional(),
|
|
1081
1154
|
/**
|
|
1082
1155
|
* Optional. The service tier to use for the request. Sent as the
|
|
1083
1156
|
* `serviceTier` body field. Gemini API only.
|
|
1084
1157
|
*/
|
|
1085
|
-
serviceTier:
|
|
1158
|
+
serviceTier: z5.enum(["standard", "flex", "priority"]).optional(),
|
|
1086
1159
|
/**
|
|
1087
1160
|
* Optional. Vertex AI only. Sent as the
|
|
1088
1161
|
* `X-Vertex-AI-LLM-Shared-Request-Type` request header to select a
|
|
@@ -1093,7 +1166,7 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1093
1166
|
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
|
|
1094
1167
|
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/flex-paygo
|
|
1095
1168
|
*/
|
|
1096
|
-
sharedRequestType:
|
|
1169
|
+
sharedRequestType: z5.enum(["priority", "flex", "standard"]).optional(),
|
|
1097
1170
|
/**
|
|
1098
1171
|
* Optional. Vertex AI only. Sent as the `X-Vertex-AI-LLM-Request-Type`
|
|
1099
1172
|
* request header. Set to `'shared'` together with `sharedRequestType`
|
|
@@ -1101,7 +1174,7 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1101
1174
|
*
|
|
1102
1175
|
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/priority-paygo
|
|
1103
1176
|
*/
|
|
1104
|
-
requestType:
|
|
1177
|
+
requestType: z5.enum(["shared"]).optional()
|
|
1105
1178
|
})
|
|
1106
1179
|
)
|
|
1107
1180
|
);
|
|
@@ -1366,10 +1439,10 @@ function prepareTools({
|
|
|
1366
1439
|
}
|
|
1367
1440
|
}
|
|
1368
1441
|
function prepareFunctionDeclaration(tool) {
|
|
1369
|
-
var
|
|
1442
|
+
var _a2;
|
|
1370
1443
|
return {
|
|
1371
1444
|
name: tool.name,
|
|
1372
|
-
description: (
|
|
1445
|
+
description: (_a2 = tool.description) != null ? _a2 : "",
|
|
1373
1446
|
parametersJsonSchema: tool.inputSchema
|
|
1374
1447
|
};
|
|
1375
1448
|
}
|
|
@@ -1608,11 +1681,10 @@ function setNestedValue(obj, segments, value) {
|
|
|
1608
1681
|
defineOwnProperty(current, segments[segments.length - 1], value);
|
|
1609
1682
|
}
|
|
1610
1683
|
function resolvePartialArgValue(arg) {
|
|
1611
|
-
var
|
|
1612
|
-
const value = (_b = (
|
|
1684
|
+
var _a2, _b;
|
|
1685
|
+
const value = (_b = (_a2 = arg.stringValue) != null ? _a2 : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1613
1686
|
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1614
1687
|
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1615
|
-
return void 0;
|
|
1616
1688
|
}
|
|
1617
1689
|
|
|
1618
1690
|
// src/map-google-finish-reason.ts
|
|
@@ -1652,10 +1724,10 @@ var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
|
1652
1724
|
var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
1653
1725
|
constructor(modelId, config) {
|
|
1654
1726
|
this.specificationVersion = "v4";
|
|
1655
|
-
var
|
|
1727
|
+
var _a2;
|
|
1656
1728
|
this.modelId = modelId;
|
|
1657
1729
|
this.config = config;
|
|
1658
|
-
this.generateId = (
|
|
1730
|
+
this.generateId = (_a2 = config.generateId) != null ? _a2 : generateId;
|
|
1659
1731
|
}
|
|
1660
1732
|
static [WORKFLOW_SERIALIZE2](model) {
|
|
1661
1733
|
return serializeModelOptions2({
|
|
@@ -1670,8 +1742,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1670
1742
|
return this.config.provider;
|
|
1671
1743
|
}
|
|
1672
1744
|
get supportedUrls() {
|
|
1673
|
-
var
|
|
1674
|
-
return (_c = (_b = (
|
|
1745
|
+
var _a2, _b, _c;
|
|
1746
|
+
return (_c = (_b = (_a2 = this.config).supportedUrls) == null ? void 0 : _b.call(_a2)) != null ? _c : {};
|
|
1675
1747
|
}
|
|
1676
1748
|
static async prepareRequest({
|
|
1677
1749
|
modelId,
|
|
@@ -1695,7 +1767,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1695
1767
|
},
|
|
1696
1768
|
isStreaming = false
|
|
1697
1769
|
}) {
|
|
1698
|
-
var
|
|
1770
|
+
var _a2, _b, _c;
|
|
1699
1771
|
const warnings = [];
|
|
1700
1772
|
const providerOptionsNames = config.provider.includes(
|
|
1701
1773
|
"vertex"
|
|
@@ -1825,7 +1897,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1825
1897
|
warnings
|
|
1826
1898
|
});
|
|
1827
1899
|
const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
|
|
1828
|
-
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (
|
|
1900
|
+
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a2 = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a2 : false : void 0;
|
|
1829
1901
|
const safetyThreshold = googleOptions == null ? void 0 : googleOptions.threshold;
|
|
1830
1902
|
const safetySettings = (_b = googleOptions == null ? void 0 : googleOptions.safetySettings) != null ? _b : safetyThreshold != null ? configurableSafetySettingCategories.map((category) => ({
|
|
1831
1903
|
category,
|
|
@@ -1902,11 +1974,11 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1902
1974
|
providerOptionsNames,
|
|
1903
1975
|
toolNameMapping
|
|
1904
1976
|
}) {
|
|
1905
|
-
var
|
|
1977
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1906
1978
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1907
1979
|
providerOptionsNames.map((name) => [name, payload])
|
|
1908
1980
|
);
|
|
1909
|
-
const candidate = (
|
|
1981
|
+
const candidate = (_a2 = response.candidates) == null ? void 0 : _a2[0];
|
|
1910
1982
|
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1911
1983
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
1912
1984
|
promptBlockReason
|
|
@@ -2179,7 +2251,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2179
2251
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2180
2252
|
},
|
|
2181
2253
|
transform(chunk, controller) {
|
|
2182
|
-
var
|
|
2254
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
2183
2255
|
if (options.includeRawChunks) {
|
|
2184
2256
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2185
2257
|
}
|
|
@@ -2209,7 +2281,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2209
2281
|
};
|
|
2210
2282
|
}
|
|
2211
2283
|
}
|
|
2212
|
-
const candidate = (
|
|
2284
|
+
const candidate = (_a2 = value.candidates) == null ? void 0 : _a2[0];
|
|
2213
2285
|
if (candidate != null) {
|
|
2214
2286
|
if (candidate.groundingMetadata != null) {
|
|
2215
2287
|
lastGroundingMetadata = candidate.groundingMetadata;
|
|
@@ -2507,7 +2579,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2507
2579
|
}
|
|
2508
2580
|
},
|
|
2509
2581
|
flush(controller) {
|
|
2510
|
-
var
|
|
2582
|
+
var _a2;
|
|
2511
2583
|
if (currentTextBlockId !== null) {
|
|
2512
2584
|
controller.enqueue({
|
|
2513
2585
|
type: "text-end",
|
|
@@ -2531,7 +2603,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2531
2603
|
safetyRatings: lastSafetyRatings,
|
|
2532
2604
|
usageMetadata: usage != null ? usage : null,
|
|
2533
2605
|
finishMessage: lastFinishMessage,
|
|
2534
|
-
serviceTier: (
|
|
2606
|
+
serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null
|
|
2535
2607
|
})
|
|
2536
2608
|
});
|
|
2537
2609
|
}
|
|
@@ -2591,8 +2663,8 @@ function resolveGemini3ThinkingConfig({
|
|
|
2591
2663
|
return { thinkingLevel };
|
|
2592
2664
|
}
|
|
2593
2665
|
function getMinimumThinkingLevelForGemini3Model(modelId) {
|
|
2594
|
-
var
|
|
2595
|
-
const modelName = (
|
|
2666
|
+
var _a2;
|
|
2667
|
+
const modelName = (_a2 = modelId.split("/").at(-1)) == null ? void 0 : _a2.toLowerCase();
|
|
2596
2668
|
if (modelName === "gemini-flash-latest") {
|
|
2597
2669
|
return "low";
|
|
2598
2670
|
}
|
|
@@ -2630,7 +2702,7 @@ function extractSources({
|
|
|
2630
2702
|
groundingMetadata,
|
|
2631
2703
|
generateId: generateId4
|
|
2632
2704
|
}) {
|
|
2633
|
-
var
|
|
2705
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2634
2706
|
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
2635
2707
|
return void 0;
|
|
2636
2708
|
}
|
|
@@ -2642,7 +2714,7 @@ function extractSources({
|
|
|
2642
2714
|
sourceType: "url",
|
|
2643
2715
|
id: generateId4(),
|
|
2644
2716
|
url: chunk.web.uri,
|
|
2645
|
-
title: (
|
|
2717
|
+
title: (_a2 = chunk.web.title) != null ? _a2 : void 0
|
|
2646
2718
|
});
|
|
2647
2719
|
} else if (chunk.image != null) {
|
|
2648
2720
|
sources.push({
|
|
@@ -2720,195 +2792,195 @@ function extractSources({
|
|
|
2720
2792
|
}
|
|
2721
2793
|
return sources.length > 0 ? sources : void 0;
|
|
2722
2794
|
}
|
|
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:
|
|
2795
|
+
var getGroundingMetadataSchema = () => z6.object({
|
|
2796
|
+
webSearchQueries: z6.array(z6.string()).nullish(),
|
|
2797
|
+
imageSearchQueries: z6.array(z6.string()).nullish(),
|
|
2798
|
+
retrievalQueries: z6.array(z6.string()).nullish(),
|
|
2799
|
+
searchEntryPoint: z6.object({ renderedContent: z6.string() }).nullish(),
|
|
2800
|
+
groundingChunks: z6.array(
|
|
2801
|
+
z6.object({
|
|
2802
|
+
web: z6.object({ uri: z6.string(), title: z6.string().nullish() }).nullish(),
|
|
2803
|
+
image: z6.object({
|
|
2804
|
+
sourceUri: z6.string(),
|
|
2805
|
+
imageUri: z6.string(),
|
|
2806
|
+
title: z6.string().nullish(),
|
|
2807
|
+
domain: z6.string().nullish()
|
|
2736
2808
|
}).nullish(),
|
|
2737
|
-
retrievedContext:
|
|
2738
|
-
uri:
|
|
2739
|
-
title:
|
|
2740
|
-
text:
|
|
2741
|
-
fileSearchStore:
|
|
2809
|
+
retrievedContext: z6.object({
|
|
2810
|
+
uri: z6.string().nullish(),
|
|
2811
|
+
title: z6.string().nullish(),
|
|
2812
|
+
text: z6.string().nullish(),
|
|
2813
|
+
fileSearchStore: z6.string().nullish()
|
|
2742
2814
|
}).nullish(),
|
|
2743
|
-
maps:
|
|
2744
|
-
uri:
|
|
2745
|
-
title:
|
|
2746
|
-
text:
|
|
2747
|
-
placeId:
|
|
2815
|
+
maps: z6.object({
|
|
2816
|
+
uri: z6.string().nullish(),
|
|
2817
|
+
title: z6.string().nullish(),
|
|
2818
|
+
text: z6.string().nullish(),
|
|
2819
|
+
placeId: z6.string().nullish()
|
|
2748
2820
|
}).nullish()
|
|
2749
2821
|
})
|
|
2750
2822
|
).nullish(),
|
|
2751
|
-
groundingSupports:
|
|
2752
|
-
|
|
2753
|
-
segment:
|
|
2754
|
-
startIndex:
|
|
2755
|
-
endIndex:
|
|
2756
|
-
text:
|
|
2823
|
+
groundingSupports: z6.array(
|
|
2824
|
+
z6.object({
|
|
2825
|
+
segment: z6.object({
|
|
2826
|
+
startIndex: z6.number().nullish(),
|
|
2827
|
+
endIndex: z6.number().nullish(),
|
|
2828
|
+
text: z6.string().nullish()
|
|
2757
2829
|
}).nullish(),
|
|
2758
|
-
segment_text:
|
|
2759
|
-
groundingChunkIndices:
|
|
2760
|
-
supportChunkIndices:
|
|
2761
|
-
confidenceScores:
|
|
2762
|
-
confidenceScore:
|
|
2830
|
+
segment_text: z6.string().nullish(),
|
|
2831
|
+
groundingChunkIndices: z6.array(z6.number()).nullish(),
|
|
2832
|
+
supportChunkIndices: z6.array(z6.number()).nullish(),
|
|
2833
|
+
confidenceScores: z6.array(z6.number()).nullish(),
|
|
2834
|
+
confidenceScore: z6.array(z6.number()).nullish()
|
|
2763
2835
|
})
|
|
2764
2836
|
).nullish(),
|
|
2765
|
-
retrievalMetadata:
|
|
2766
|
-
|
|
2767
|
-
webDynamicRetrievalScore:
|
|
2837
|
+
retrievalMetadata: z6.union([
|
|
2838
|
+
z6.object({
|
|
2839
|
+
webDynamicRetrievalScore: z6.number()
|
|
2768
2840
|
}),
|
|
2769
|
-
|
|
2841
|
+
z6.object({})
|
|
2770
2842
|
]).nullish()
|
|
2771
2843
|
});
|
|
2772
|
-
var partialArgSchema =
|
|
2773
|
-
jsonPath:
|
|
2774
|
-
stringValue:
|
|
2775
|
-
numberValue:
|
|
2776
|
-
boolValue:
|
|
2777
|
-
nullValue:
|
|
2778
|
-
willContinue:
|
|
2844
|
+
var partialArgSchema = z6.object({
|
|
2845
|
+
jsonPath: z6.string(),
|
|
2846
|
+
stringValue: z6.string().nullish(),
|
|
2847
|
+
numberValue: z6.number().nullish(),
|
|
2848
|
+
boolValue: z6.boolean().nullish(),
|
|
2849
|
+
nullValue: z6.unknown().nullish(),
|
|
2850
|
+
willContinue: z6.boolean().nullish()
|
|
2779
2851
|
});
|
|
2780
|
-
var getContentSchema = () =>
|
|
2781
|
-
parts:
|
|
2782
|
-
|
|
2852
|
+
var getContentSchema = () => z6.object({
|
|
2853
|
+
parts: z6.array(
|
|
2854
|
+
z6.union([
|
|
2783
2855
|
// note: order matters since text can be fully empty
|
|
2784
|
-
|
|
2785
|
-
functionCall:
|
|
2786
|
-
id:
|
|
2787
|
-
name:
|
|
2788
|
-
args:
|
|
2789
|
-
partialArgs:
|
|
2790
|
-
willContinue:
|
|
2856
|
+
z6.object({
|
|
2857
|
+
functionCall: z6.object({
|
|
2858
|
+
id: z6.string().nullish(),
|
|
2859
|
+
name: z6.string().nullish(),
|
|
2860
|
+
args: z6.unknown().nullish(),
|
|
2861
|
+
partialArgs: z6.array(partialArgSchema).nullish(),
|
|
2862
|
+
willContinue: z6.boolean().nullish()
|
|
2791
2863
|
}),
|
|
2792
|
-
thoughtSignature:
|
|
2864
|
+
thoughtSignature: z6.string().nullish()
|
|
2793
2865
|
}),
|
|
2794
|
-
|
|
2795
|
-
inlineData:
|
|
2796
|
-
mimeType:
|
|
2797
|
-
data:
|
|
2866
|
+
z6.object({
|
|
2867
|
+
inlineData: z6.object({
|
|
2868
|
+
mimeType: z6.string(),
|
|
2869
|
+
data: z6.string()
|
|
2798
2870
|
}),
|
|
2799
|
-
thought:
|
|
2800
|
-
thoughtSignature:
|
|
2871
|
+
thought: z6.boolean().nullish(),
|
|
2872
|
+
thoughtSignature: z6.string().nullish()
|
|
2801
2873
|
}),
|
|
2802
|
-
|
|
2803
|
-
toolCall:
|
|
2804
|
-
toolType:
|
|
2805
|
-
args:
|
|
2806
|
-
id:
|
|
2874
|
+
z6.object({
|
|
2875
|
+
toolCall: z6.object({
|
|
2876
|
+
toolType: z6.string(),
|
|
2877
|
+
args: z6.unknown().nullish(),
|
|
2878
|
+
id: z6.string()
|
|
2807
2879
|
}),
|
|
2808
|
-
thoughtSignature:
|
|
2880
|
+
thoughtSignature: z6.string().nullish()
|
|
2809
2881
|
}),
|
|
2810
|
-
|
|
2811
|
-
toolResponse:
|
|
2812
|
-
toolType:
|
|
2813
|
-
response:
|
|
2814
|
-
id:
|
|
2882
|
+
z6.object({
|
|
2883
|
+
toolResponse: z6.object({
|
|
2884
|
+
toolType: z6.string(),
|
|
2885
|
+
response: z6.unknown().nullish(),
|
|
2886
|
+
id: z6.string()
|
|
2815
2887
|
}),
|
|
2816
|
-
thoughtSignature:
|
|
2888
|
+
thoughtSignature: z6.string().nullish()
|
|
2817
2889
|
}),
|
|
2818
|
-
|
|
2819
|
-
executableCode:
|
|
2820
|
-
language:
|
|
2821
|
-
code:
|
|
2890
|
+
z6.object({
|
|
2891
|
+
executableCode: z6.object({
|
|
2892
|
+
language: z6.string(),
|
|
2893
|
+
code: z6.string()
|
|
2822
2894
|
}).nullish(),
|
|
2823
|
-
codeExecutionResult:
|
|
2824
|
-
outcome:
|
|
2825
|
-
output:
|
|
2895
|
+
codeExecutionResult: z6.object({
|
|
2896
|
+
outcome: z6.string(),
|
|
2897
|
+
output: z6.string().nullish()
|
|
2826
2898
|
}).nullish(),
|
|
2827
|
-
text:
|
|
2828
|
-
thought:
|
|
2829
|
-
thoughtSignature:
|
|
2899
|
+
text: z6.string().nullish(),
|
|
2900
|
+
thought: z6.boolean().nullish(),
|
|
2901
|
+
thoughtSignature: z6.string().nullish()
|
|
2830
2902
|
})
|
|
2831
2903
|
])
|
|
2832
2904
|
).nullish()
|
|
2833
2905
|
});
|
|
2834
|
-
var getSafetyRatingSchema = () =>
|
|
2835
|
-
category:
|
|
2836
|
-
probability:
|
|
2837
|
-
probabilityScore:
|
|
2838
|
-
severity:
|
|
2839
|
-
severityScore:
|
|
2840
|
-
blocked:
|
|
2906
|
+
var getSafetyRatingSchema = () => z6.object({
|
|
2907
|
+
category: z6.string().nullish(),
|
|
2908
|
+
probability: z6.string().nullish(),
|
|
2909
|
+
probabilityScore: z6.number().nullish(),
|
|
2910
|
+
severity: z6.string().nullish(),
|
|
2911
|
+
severityScore: z6.number().nullish(),
|
|
2912
|
+
blocked: z6.boolean().nullish()
|
|
2841
2913
|
});
|
|
2842
|
-
var tokenDetailsSchema =
|
|
2843
|
-
|
|
2844
|
-
modality:
|
|
2845
|
-
tokenCount:
|
|
2914
|
+
var tokenDetailsSchema = z6.array(
|
|
2915
|
+
z6.object({
|
|
2916
|
+
modality: z6.string(),
|
|
2917
|
+
tokenCount: z6.number()
|
|
2846
2918
|
}).loose()
|
|
2847
2919
|
).nullish();
|
|
2848
|
-
var usageSchema =
|
|
2849
|
-
cachedContentTokenCount:
|
|
2850
|
-
thoughtsTokenCount:
|
|
2851
|
-
promptTokenCount:
|
|
2852
|
-
candidatesTokenCount:
|
|
2853
|
-
toolUsePromptTokenCount:
|
|
2854
|
-
totalTokenCount:
|
|
2920
|
+
var usageSchema = z6.object({
|
|
2921
|
+
cachedContentTokenCount: z6.number().nullish(),
|
|
2922
|
+
thoughtsTokenCount: z6.number().nullish(),
|
|
2923
|
+
promptTokenCount: z6.number().nullish(),
|
|
2924
|
+
candidatesTokenCount: z6.number().nullish(),
|
|
2925
|
+
toolUsePromptTokenCount: z6.number().nullish(),
|
|
2926
|
+
totalTokenCount: z6.number().nullish(),
|
|
2855
2927
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
2856
|
-
trafficType:
|
|
2857
|
-
serviceTier:
|
|
2928
|
+
trafficType: z6.string().nullish(),
|
|
2929
|
+
serviceTier: z6.string().nullish(),
|
|
2858
2930
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2859
2931
|
promptTokensDetails: tokenDetailsSchema,
|
|
2860
2932
|
cacheTokensDetails: tokenDetailsSchema,
|
|
2861
2933
|
candidatesTokensDetails: tokenDetailsSchema,
|
|
2862
2934
|
toolUsePromptTokensDetails: tokenDetailsSchema
|
|
2863
2935
|
}).loose();
|
|
2864
|
-
var getUrlContextMetadataSchema = () =>
|
|
2865
|
-
urlMetadata:
|
|
2866
|
-
|
|
2867
|
-
retrievedUrl:
|
|
2868
|
-
urlRetrievalStatus:
|
|
2936
|
+
var getUrlContextMetadataSchema = () => z6.object({
|
|
2937
|
+
urlMetadata: z6.array(
|
|
2938
|
+
z6.object({
|
|
2939
|
+
retrievedUrl: z6.string(),
|
|
2940
|
+
urlRetrievalStatus: z6.string()
|
|
2869
2941
|
})
|
|
2870
2942
|
).nullish()
|
|
2871
2943
|
});
|
|
2872
2944
|
var responseSchema = lazySchema5(
|
|
2873
2945
|
() => zodSchema5(
|
|
2874
|
-
|
|
2875
|
-
responseId:
|
|
2876
|
-
candidates:
|
|
2877
|
-
|
|
2878
|
-
content: getContentSchema().nullish().or(
|
|
2879
|
-
finishReason:
|
|
2880
|
-
finishMessage:
|
|
2881
|
-
safetyRatings:
|
|
2946
|
+
z6.object({
|
|
2947
|
+
responseId: z6.string().nullish(),
|
|
2948
|
+
candidates: z6.array(
|
|
2949
|
+
z6.object({
|
|
2950
|
+
content: getContentSchema().nullish().or(z6.object({}).strict()),
|
|
2951
|
+
finishReason: z6.string().nullish(),
|
|
2952
|
+
finishMessage: z6.string().nullish(),
|
|
2953
|
+
safetyRatings: z6.array(getSafetyRatingSchema()).nullish(),
|
|
2882
2954
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2883
2955
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2884
2956
|
})
|
|
2885
2957
|
).nullish(),
|
|
2886
2958
|
usageMetadata: usageSchema.nullish(),
|
|
2887
|
-
promptFeedback:
|
|
2888
|
-
blockReason:
|
|
2889
|
-
safetyRatings:
|
|
2959
|
+
promptFeedback: z6.object({
|
|
2960
|
+
blockReason: z6.string().nullish(),
|
|
2961
|
+
safetyRatings: z6.array(getSafetyRatingSchema()).nullish()
|
|
2890
2962
|
}).nullish()
|
|
2891
2963
|
})
|
|
2892
2964
|
)
|
|
2893
2965
|
);
|
|
2894
2966
|
var chunkSchema = lazySchema5(
|
|
2895
2967
|
() => zodSchema5(
|
|
2896
|
-
|
|
2897
|
-
responseId:
|
|
2898
|
-
candidates:
|
|
2899
|
-
|
|
2968
|
+
z6.object({
|
|
2969
|
+
responseId: z6.string().nullish(),
|
|
2970
|
+
candidates: z6.array(
|
|
2971
|
+
z6.object({
|
|
2900
2972
|
content: getContentSchema().nullish(),
|
|
2901
|
-
finishReason:
|
|
2902
|
-
finishMessage:
|
|
2903
|
-
safetyRatings:
|
|
2973
|
+
finishReason: z6.string().nullish(),
|
|
2974
|
+
finishMessage: z6.string().nullish(),
|
|
2975
|
+
safetyRatings: z6.array(getSafetyRatingSchema()).nullish(),
|
|
2904
2976
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2905
2977
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2906
2978
|
})
|
|
2907
2979
|
).nullish(),
|
|
2908
2980
|
usageMetadata: usageSchema.nullish(),
|
|
2909
|
-
promptFeedback:
|
|
2910
|
-
blockReason:
|
|
2911
|
-
safetyRatings:
|
|
2981
|
+
promptFeedback: z6.object({
|
|
2982
|
+
blockReason: z6.string().nullish(),
|
|
2983
|
+
safetyRatings: z6.array(getSafetyRatingSchema()).nullish()
|
|
2912
2984
|
}).nullish()
|
|
2913
2985
|
})
|
|
2914
2986
|
)
|
|
@@ -2919,35 +2991,35 @@ function isConfirmedPromptBlockReason(blockReason) {
|
|
|
2919
2991
|
|
|
2920
2992
|
// src/google-image-model-options.ts
|
|
2921
2993
|
import { lazySchema as lazySchema7, zodSchema as zodSchema7 } from "@ai-sdk/provider-utils";
|
|
2922
|
-
import { z as
|
|
2994
|
+
import { z as z8 } from "zod/v4";
|
|
2923
2995
|
|
|
2924
2996
|
// src/tool/google-search.ts
|
|
2925
2997
|
import {
|
|
2926
|
-
createProviderExecutedToolFactory,
|
|
2998
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
|
|
2927
2999
|
lazySchema as lazySchema6,
|
|
2928
3000
|
zodSchema as zodSchema6
|
|
2929
3001
|
} from "@ai-sdk/provider-utils";
|
|
2930
|
-
import { z as
|
|
2931
|
-
var googleSearchToolArgsBaseSchema =
|
|
2932
|
-
searchTypes:
|
|
2933
|
-
webSearch:
|
|
2934
|
-
imageSearch:
|
|
3002
|
+
import { z as z7 } from "zod/v4";
|
|
3003
|
+
var googleSearchToolArgsBaseSchema = z7.looseObject({
|
|
3004
|
+
searchTypes: z7.object({
|
|
3005
|
+
webSearch: z7.object({}).optional(),
|
|
3006
|
+
imageSearch: z7.object({}).optional()
|
|
2935
3007
|
}).optional(),
|
|
2936
|
-
timeRangeFilter:
|
|
2937
|
-
startTime:
|
|
2938
|
-
endTime:
|
|
3008
|
+
timeRangeFilter: z7.object({
|
|
3009
|
+
startTime: z7.string(),
|
|
3010
|
+
endTime: z7.string()
|
|
2939
3011
|
}).optional()
|
|
2940
3012
|
});
|
|
2941
|
-
var googleSearch =
|
|
3013
|
+
var googleSearch = createProviderExecutedToolFactory2({
|
|
2942
3014
|
id: "google.google_search",
|
|
2943
|
-
inputSchema: lazySchema6(() => zodSchema6(
|
|
2944
|
-
outputSchema: lazySchema6(() => zodSchema6(
|
|
3015
|
+
inputSchema: lazySchema6(() => zodSchema6(z7.object({}))),
|
|
3016
|
+
outputSchema: lazySchema6(() => zodSchema6(z7.object({})))
|
|
2945
3017
|
});
|
|
2946
3018
|
|
|
2947
3019
|
// src/google-image-model-options.ts
|
|
2948
3020
|
var googleImageModelOptionsSchema = lazySchema7(
|
|
2949
3021
|
() => zodSchema7(
|
|
2950
|
-
|
|
3022
|
+
z8.object({
|
|
2951
3023
|
/**
|
|
2952
3024
|
* Enable Google Search grounding for Gemini image models. The value is
|
|
2953
3025
|
* forwarded as the args of the `google.tools.googleSearch` provider
|
|
@@ -2977,40 +3049,40 @@ function assertSupportedBatchRequests(requests) {
|
|
|
2977
3049
|
}
|
|
2978
3050
|
}
|
|
2979
3051
|
}
|
|
2980
|
-
var googleRpcStatusSchema =
|
|
2981
|
-
code:
|
|
2982
|
-
message:
|
|
2983
|
-
status:
|
|
3052
|
+
var googleRpcStatusSchema = z9.object({
|
|
3053
|
+
code: z9.union([z9.number(), z9.string()]).nullish(),
|
|
3054
|
+
message: z9.string().nullish(),
|
|
3055
|
+
status: z9.string().nullish()
|
|
2984
3056
|
});
|
|
2985
|
-
var googleBatchStatsSchema =
|
|
2986
|
-
requestCount:
|
|
2987
|
-
successfulRequestCount:
|
|
2988
|
-
failedRequestCount:
|
|
2989
|
-
pendingRequestCount:
|
|
3057
|
+
var googleBatchStatsSchema = z9.object({
|
|
3058
|
+
requestCount: z9.union([z9.string(), z9.number()]).nullish(),
|
|
3059
|
+
successfulRequestCount: z9.union([z9.string(), z9.number()]).nullish(),
|
|
3060
|
+
failedRequestCount: z9.union([z9.string(), z9.number()]).nullish(),
|
|
3061
|
+
pendingRequestCount: z9.union([z9.string(), z9.number()]).nullish()
|
|
2990
3062
|
});
|
|
2991
|
-
var googleBatchOutputSchema =
|
|
2992
|
-
responsesFile:
|
|
2993
|
-
inlinedResponses:
|
|
2994
|
-
inlinedResponses:
|
|
2995
|
-
|
|
2996
|
-
metadata:
|
|
2997
|
-
key:
|
|
3063
|
+
var googleBatchOutputSchema = z9.object({
|
|
3064
|
+
responsesFile: z9.string().nullish(),
|
|
3065
|
+
inlinedResponses: z9.object({
|
|
3066
|
+
inlinedResponses: z9.array(
|
|
3067
|
+
z9.object({
|
|
3068
|
+
metadata: z9.object({
|
|
3069
|
+
key: z9.string()
|
|
2998
3070
|
}),
|
|
2999
|
-
response:
|
|
3071
|
+
response: z9.unknown().nullish(),
|
|
3000
3072
|
error: googleRpcStatusSchema.nullish()
|
|
3001
3073
|
})
|
|
3002
3074
|
)
|
|
3003
3075
|
}).nullish()
|
|
3004
3076
|
});
|
|
3005
|
-
var googleBatchOperationZodSchema = () =>
|
|
3006
|
-
name:
|
|
3007
|
-
metadata:
|
|
3008
|
-
state:
|
|
3009
|
-
createTime:
|
|
3077
|
+
var googleBatchOperationZodSchema = () => z9.object({
|
|
3078
|
+
name: z9.string(),
|
|
3079
|
+
metadata: z9.object({
|
|
3080
|
+
state: z9.string().nullish(),
|
|
3081
|
+
createTime: z9.string().nullish(),
|
|
3010
3082
|
batchStats: googleBatchStatsSchema.nullish(),
|
|
3011
3083
|
output: googleBatchOutputSchema.nullish()
|
|
3012
3084
|
}).nullish(),
|
|
3013
|
-
done:
|
|
3085
|
+
done: z9.boolean().nullish(),
|
|
3014
3086
|
error: googleRpcStatusSchema.nullish(),
|
|
3015
3087
|
response: googleBatchOutputSchema.nullish()
|
|
3016
3088
|
});
|
|
@@ -3019,40 +3091,40 @@ var googleBatchOperationSchema = lazySchema8(
|
|
|
3019
3091
|
);
|
|
3020
3092
|
var googleBatchListResponseSchema = lazySchema8(
|
|
3021
3093
|
() => zodSchema8(
|
|
3022
|
-
|
|
3023
|
-
operations:
|
|
3024
|
-
nextPageToken:
|
|
3094
|
+
z9.object({
|
|
3095
|
+
operations: z9.array(googleBatchOperationZodSchema()).nullish(),
|
|
3096
|
+
nextPageToken: z9.string().nullish()
|
|
3025
3097
|
})
|
|
3026
3098
|
)
|
|
3027
3099
|
);
|
|
3028
3100
|
var googleBatchCancelResponseSchema = lazySchema8(
|
|
3029
|
-
() => zodSchema8(
|
|
3101
|
+
() => zodSchema8(z9.object({}))
|
|
3030
3102
|
);
|
|
3031
3103
|
var googleFileUploadResponseSchema = lazySchema8(
|
|
3032
3104
|
() => zodSchema8(
|
|
3033
|
-
|
|
3034
|
-
file:
|
|
3035
|
-
name:
|
|
3036
|
-
expirationTime:
|
|
3105
|
+
z9.object({
|
|
3106
|
+
file: z9.object({
|
|
3107
|
+
name: z9.string(),
|
|
3108
|
+
expirationTime: z9.string().nullish()
|
|
3037
3109
|
})
|
|
3038
3110
|
})
|
|
3039
3111
|
)
|
|
3040
3112
|
);
|
|
3041
3113
|
var googleBatchResultLineSchema = lazySchema8(
|
|
3042
3114
|
() => zodSchema8(
|
|
3043
|
-
|
|
3044
|
-
key:
|
|
3045
|
-
response:
|
|
3115
|
+
z9.object({
|
|
3116
|
+
key: z9.string(),
|
|
3117
|
+
response: z9.unknown().nullish(),
|
|
3046
3118
|
error: googleRpcStatusSchema.nullish()
|
|
3047
3119
|
})
|
|
3048
3120
|
)
|
|
3049
3121
|
);
|
|
3050
3122
|
var googleBatchResponsePreviewSchema = lazySchema8(
|
|
3051
3123
|
() => zodSchema8(
|
|
3052
|
-
|
|
3053
|
-
candidates:
|
|
3054
|
-
promptFeedback:
|
|
3055
|
-
blockReason:
|
|
3124
|
+
z9.object({
|
|
3125
|
+
candidates: z9.array(z9.unknown()).nullish(),
|
|
3126
|
+
promptFeedback: z9.object({
|
|
3127
|
+
blockReason: z9.string().nullish()
|
|
3056
3128
|
}).nullish()
|
|
3057
3129
|
})
|
|
3058
3130
|
)
|
|
@@ -3060,11 +3132,11 @@ var googleBatchResponsePreviewSchema = lazySchema8(
|
|
|
3060
3132
|
var GoogleBatch = class {
|
|
3061
3133
|
constructor(options) {
|
|
3062
3134
|
this.specificationVersion = "v4";
|
|
3063
|
-
var
|
|
3135
|
+
var _a2;
|
|
3064
3136
|
this.provider = options.provider;
|
|
3065
3137
|
this.batchConfig = options.config;
|
|
3066
3138
|
this.supportedUrls = options.supportedUrls;
|
|
3067
|
-
this.batchGenerateId = (
|
|
3139
|
+
this.batchGenerateId = (_a2 = options.config.generateId) != null ? _a2 : generateId2;
|
|
3068
3140
|
}
|
|
3069
3141
|
async doStartBatch(options) {
|
|
3070
3142
|
assertSupportedBatchRequests(options.requests);
|
|
@@ -3259,7 +3331,7 @@ var GoogleBatch = class {
|
|
|
3259
3331
|
return {};
|
|
3260
3332
|
}
|
|
3261
3333
|
async doListBatches(options) {
|
|
3262
|
-
var
|
|
3334
|
+
var _a2;
|
|
3263
3335
|
const url = new URL(`${this.batchConfig.baseURL}/batches`);
|
|
3264
3336
|
if (options.limit != null) {
|
|
3265
3337
|
url.searchParams.set("pageSize", String(options.limit));
|
|
@@ -3279,7 +3351,7 @@ var GoogleBatch = class {
|
|
|
3279
3351
|
validateUrl: false
|
|
3280
3352
|
});
|
|
3281
3353
|
return {
|
|
3282
|
-
batches: ((
|
|
3354
|
+
batches: ((_a2 = page.operations) != null ? _a2 : []).map((operation) => ({
|
|
3283
3355
|
batchId: operation.name,
|
|
3284
3356
|
...convertGoogleBatchStatus(operation)
|
|
3285
3357
|
})),
|
|
@@ -3287,7 +3359,7 @@ var GoogleBatch = class {
|
|
|
3287
3359
|
};
|
|
3288
3360
|
}
|
|
3289
3361
|
async doGetBatchResults(options) {
|
|
3290
|
-
var
|
|
3362
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3291
3363
|
const operation = await this.retrieveBatch(options);
|
|
3292
3364
|
const batchStatus = convertGoogleBatchStatus(operation);
|
|
3293
3365
|
if (batchStatus.status === "pending") {
|
|
@@ -3296,7 +3368,7 @@ var GoogleBatch = class {
|
|
|
3296
3368
|
message: `Google batch "${options.batchId}" is not complete.`
|
|
3297
3369
|
});
|
|
3298
3370
|
}
|
|
3299
|
-
const inlinedResponses = (_f = (_c = (_b = (
|
|
3371
|
+
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
3372
|
if (inlinedResponses != null) {
|
|
3301
3373
|
return convertAsyncIteratorToReadableStream(
|
|
3302
3374
|
this.iterateBatchResults(
|
|
@@ -3353,7 +3425,7 @@ var GoogleBatch = class {
|
|
|
3353
3425
|
return operation;
|
|
3354
3426
|
}
|
|
3355
3427
|
async *iterateBatchResults(results) {
|
|
3356
|
-
var
|
|
3428
|
+
var _a2, _b, _c;
|
|
3357
3429
|
for await (const line of results) {
|
|
3358
3430
|
if (line.error != null) {
|
|
3359
3431
|
const error = convertGoogleRpcError(
|
|
@@ -3381,7 +3453,7 @@ var GoogleBatch = class {
|
|
|
3381
3453
|
schema: googleBatchResponsePreviewSchema
|
|
3382
3454
|
});
|
|
3383
3455
|
if (preview.success && (preview.value.candidates == null || preview.value.candidates.length === 0)) {
|
|
3384
|
-
const promptFeedback = (
|
|
3456
|
+
const promptFeedback = (_a2 = preview.value.promptFeedback) != null ? _a2 : void 0;
|
|
3385
3457
|
const blockReason = (_b = promptFeedback == null ? void 0 : promptFeedback.blockReason) != null ? _b : void 0;
|
|
3386
3458
|
yield {
|
|
3387
3459
|
type: "text",
|
|
@@ -3455,7 +3527,7 @@ var GoogleBatch = class {
|
|
|
3455
3527
|
}
|
|
3456
3528
|
}
|
|
3457
3529
|
async prepareImageRequest(request) {
|
|
3458
|
-
var
|
|
3530
|
+
var _a2;
|
|
3459
3531
|
const { prompt, n, size, aspectRatio, seed, files, mask, providerOptions } = request.options;
|
|
3460
3532
|
const warnings = [];
|
|
3461
3533
|
if (mask != null) {
|
|
@@ -3499,11 +3571,11 @@ var GoogleBatch = class {
|
|
|
3499
3571
|
responseModalities: _responseModalities,
|
|
3500
3572
|
imageConfig: userImageConfig,
|
|
3501
3573
|
...passthroughGoogleOptions
|
|
3502
|
-
} = (
|
|
3574
|
+
} = (_a2 = await parseProviderOptions3({
|
|
3503
3575
|
provider: "google",
|
|
3504
3576
|
providerOptions,
|
|
3505
3577
|
schema: googleLanguageModelOptions
|
|
3506
|
-
})) != null ?
|
|
3578
|
+
})) != null ? _a2 : {};
|
|
3507
3579
|
const preparedGoogleOptions = await parseProviderOptions3({
|
|
3508
3580
|
provider: "google",
|
|
3509
3581
|
providerOptions: {
|
|
@@ -3550,8 +3622,8 @@ var GoogleBatch = class {
|
|
|
3550
3622
|
}
|
|
3551
3623
|
};
|
|
3552
3624
|
function convertGoogleBatchStatus(operation) {
|
|
3553
|
-
var
|
|
3554
|
-
const rawStatus = (_b = (
|
|
3625
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
3626
|
+
const rawStatus = (_b = (_a2 = operation.metadata) == null ? void 0 : _a2.state) != null ? _b : void 0;
|
|
3555
3627
|
const requestCounts = convertGoogleRequestCounts(
|
|
3556
3628
|
(_c = operation.metadata) == null ? void 0 : _c.batchStats
|
|
3557
3629
|
);
|
|
@@ -3596,9 +3668,9 @@ function mapGoogleBatchStatus({
|
|
|
3596
3668
|
}
|
|
3597
3669
|
}
|
|
3598
3670
|
function convertGoogleRequestCounts(counts) {
|
|
3599
|
-
var
|
|
3671
|
+
var _a2, _b, _c;
|
|
3600
3672
|
const total = parseCount(counts == null ? void 0 : counts.requestCount);
|
|
3601
|
-
const completed = parseCount((
|
|
3673
|
+
const completed = parseCount((_a2 = counts == null ? void 0 : counts.successfulRequestCount) != null ? _a2 : 0);
|
|
3602
3674
|
const failed = parseCount((_b = counts == null ? void 0 : counts.failedRequestCount) != null ? _b : 0);
|
|
3603
3675
|
const pending = parseCount((_c = counts == null ? void 0 : counts.pendingRequestCount) != null ? _c : 0);
|
|
3604
3676
|
return normalizeBatchRequestCounts({
|
|
@@ -3613,9 +3685,9 @@ function parseCount(value) {
|
|
|
3613
3685
|
return typeof count === "number" && Number.isSafeInteger(count) && count >= 0 ? count : void 0;
|
|
3614
3686
|
}
|
|
3615
3687
|
function convertGoogleRpcError(error, fallbackMessage) {
|
|
3616
|
-
var
|
|
3688
|
+
var _a2;
|
|
3617
3689
|
return {
|
|
3618
|
-
message: (
|
|
3690
|
+
message: (_a2 = error.message) != null ? _a2 : fallbackMessage,
|
|
3619
3691
|
...error.status != null ? { type: error.status } : {},
|
|
3620
3692
|
...error.code != null ? { code: String(error.code) } : {}
|
|
3621
3693
|
};
|
|
@@ -3633,8 +3705,8 @@ var googleUploadUrlResponseHandler = async ({
|
|
|
3633
3705
|
return { value: uploadUrl };
|
|
3634
3706
|
};
|
|
3635
3707
|
function getGoogleBatchModelId(requests) {
|
|
3636
|
-
var
|
|
3637
|
-
const modelId = (
|
|
3708
|
+
var _a2;
|
|
3709
|
+
const modelId = (_a2 = requests[0]) == null ? void 0 : _a2.modelId;
|
|
3638
3710
|
if (modelId == null) {
|
|
3639
3711
|
throw new InvalidArgumentError({
|
|
3640
3712
|
argument: "requests",
|
|
@@ -3652,12 +3724,12 @@ function getGoogleBatchModelId(requests) {
|
|
|
3652
3724
|
return modelId;
|
|
3653
3725
|
}
|
|
3654
3726
|
function convertGoogleImageBatchResult(result) {
|
|
3655
|
-
var
|
|
3727
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
3656
3728
|
const images = result.content.flatMap(
|
|
3657
3729
|
(part) => part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data" ? [convertToBase642(part.data.data)] : []
|
|
3658
3730
|
);
|
|
3659
3731
|
if (images.length === 0) return void 0;
|
|
3660
|
-
const googleMetadata = (_b = (
|
|
3732
|
+
const googleMetadata = (_b = (_a2 = result.providerMetadata) == null ? void 0 : _a2.google) != null ? _b : {};
|
|
3661
3733
|
return {
|
|
3662
3734
|
images,
|
|
3663
3735
|
warnings: result.warnings,
|
|
@@ -3677,21 +3749,6 @@ function convertGoogleImageBatchResult(result) {
|
|
|
3677
3749
|
};
|
|
3678
3750
|
}
|
|
3679
3751
|
|
|
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
3752
|
// src/tool/enterprise-web-search.ts
|
|
3696
3753
|
import {
|
|
3697
3754
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory3,
|
|
@@ -3868,7 +3925,7 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
3868
3925
|
return this.config.provider;
|
|
3869
3926
|
}
|
|
3870
3927
|
async doGenerate(options) {
|
|
3871
|
-
var
|
|
3928
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3872
3929
|
if (!this.modelId.startsWith("gemini-")) {
|
|
3873
3930
|
throw new Error(
|
|
3874
3931
|
"Google image models other than Gemini are no longer supported. Use a model ID that starts with `gemini-`."
|
|
@@ -3935,7 +3992,7 @@ var GoogleImageModel = class _GoogleImageModel {
|
|
|
3935
3992
|
responseModalities: _strippedResponseModalities,
|
|
3936
3993
|
imageConfig: userImageConfig,
|
|
3937
3994
|
...passthroughGoogleOptions
|
|
3938
|
-
} = (
|
|
3995
|
+
} = (_a2 = providerOptions == null ? void 0 : providerOptions.google) != null ? _a2 : {};
|
|
3939
3996
|
const languageModel = new GoogleLanguageModel(this.modelId, {
|
|
3940
3997
|
provider: this.config.provider,
|
|
3941
3998
|
baseURL: this.config.baseURL,
|
|
@@ -4030,7 +4087,7 @@ var GoogleFiles = class {
|
|
|
4030
4087
|
return this.config.provider;
|
|
4031
4088
|
}
|
|
4032
4089
|
async uploadFile(options) {
|
|
4033
|
-
var
|
|
4090
|
+
var _a2, _b, _c, _d;
|
|
4034
4091
|
const googleOptions = await parseProviderOptions5({
|
|
4035
4092
|
provider: "google",
|
|
4036
4093
|
providerOptions: options.providerOptions,
|
|
@@ -4040,7 +4097,7 @@ var GoogleFiles = class {
|
|
|
4040
4097
|
this.config.headers(),
|
|
4041
4098
|
options.headers
|
|
4042
4099
|
);
|
|
4043
|
-
const fetchFn = (
|
|
4100
|
+
const fetchFn = (_a2 = this.config.fetch) != null ? _a2 : globalThis.fetch;
|
|
4044
4101
|
const warnings = [];
|
|
4045
4102
|
if (options.filename != null) {
|
|
4046
4103
|
warnings.push({ type: "unsupported", feature: "filename" });
|
|
@@ -4221,16 +4278,16 @@ var googleVideoModelOptionsSchema = lazySchema15(
|
|
|
4221
4278
|
|
|
4222
4279
|
// src/google-video-model.ts
|
|
4223
4280
|
function getFirstFrameImage(options) {
|
|
4224
|
-
var
|
|
4225
|
-
return (_b = (
|
|
4281
|
+
var _a2, _b;
|
|
4282
|
+
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
4226
4283
|
}
|
|
4227
4284
|
function resolveStartImage(options) {
|
|
4228
|
-
var
|
|
4229
|
-
return (
|
|
4285
|
+
var _a2;
|
|
4286
|
+
return (_a2 = getFirstFrameImage(options)) != null ? _a2 : options.image;
|
|
4230
4287
|
}
|
|
4231
4288
|
function getLastFrameImage(options) {
|
|
4232
|
-
var
|
|
4233
|
-
return (_b = (
|
|
4289
|
+
var _a2, _b;
|
|
4290
|
+
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
4234
4291
|
}
|
|
4235
4292
|
function getInputReferences(options) {
|
|
4236
4293
|
if (options.frameImages != null && options.frameImages.length > 0) {
|
|
@@ -4376,9 +4433,9 @@ var GoogleVideoModel = class {
|
|
|
4376
4433
|
return { instances, parameters, warnings, googleOptions };
|
|
4377
4434
|
}
|
|
4378
4435
|
async buildCompletedResult(finalOperation, responseHeaders, warnings, currentDate) {
|
|
4379
|
-
var
|
|
4436
|
+
var _a2, _b;
|
|
4380
4437
|
const response = finalOperation.response;
|
|
4381
|
-
if (!((
|
|
4438
|
+
if (!((_a2 = response == null ? void 0 : response.generateVideoResponse) == null ? void 0 : _a2.generatedSamples) || response.generateVideoResponse.generatedSamples.length === 0) {
|
|
4382
4439
|
throw new AISDKError2({
|
|
4383
4440
|
name: "GOOGLE_VIDEO_GENERATION_ERROR",
|
|
4384
4441
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
@@ -4424,8 +4481,8 @@ var GoogleVideoModel = class {
|
|
|
4424
4481
|
};
|
|
4425
4482
|
}
|
|
4426
4483
|
async doStart(options) {
|
|
4427
|
-
var
|
|
4428
|
-
const currentDate = (_c = (_b = (
|
|
4484
|
+
var _a2, _b, _c;
|
|
4485
|
+
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
4486
|
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
4430
4487
|
const { value: operation, responseHeaders } = await postJsonToApi4({
|
|
4431
4488
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
@@ -4462,8 +4519,8 @@ var GoogleVideoModel = class {
|
|
|
4462
4519
|
};
|
|
4463
4520
|
}
|
|
4464
4521
|
async doStatus(options) {
|
|
4465
|
-
var
|
|
4466
|
-
const currentDate = (_c = (_b = (
|
|
4522
|
+
var _a2, _b, _c;
|
|
4523
|
+
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
4524
|
const { operationName } = options.operation;
|
|
4468
4525
|
const { value: statusOperation, responseHeaders } = await getFromApi3({
|
|
4469
4526
|
url: `${this.config.baseURL}/${operationName}`,
|
|
@@ -4530,6 +4587,9 @@ var googleOperationSchema = z17.object({
|
|
|
4530
4587
|
});
|
|
4531
4588
|
|
|
4532
4589
|
// src/google-speech-model.ts
|
|
4590
|
+
import {
|
|
4591
|
+
InvalidArgumentError as InvalidArgumentError2
|
|
4592
|
+
} from "@ai-sdk/provider";
|
|
4533
4593
|
import {
|
|
4534
4594
|
combineHeaders as combineHeaders6,
|
|
4535
4595
|
convertBase64ToUint8Array,
|
|
@@ -4566,6 +4626,37 @@ var googleSpeechResponseSchema = lazySchema16(
|
|
|
4566
4626
|
)
|
|
4567
4627
|
);
|
|
4568
4628
|
|
|
4629
|
+
// src/google-speech-input.ts
|
|
4630
|
+
function getGoogleSpeechInput({
|
|
4631
|
+
text,
|
|
4632
|
+
voice,
|
|
4633
|
+
providerOptions
|
|
4634
|
+
}) {
|
|
4635
|
+
const google2 = providerOptions == null ? void 0 : providerOptions.google;
|
|
4636
|
+
const options = google2 != null && typeof google2 === "object" ? google2 : void 0;
|
|
4637
|
+
const turns = options && "turns" in options ? options.turns : void 0;
|
|
4638
|
+
const turnTexts = [];
|
|
4639
|
+
if (Array.isArray(turns) && turns.length > 0) {
|
|
4640
|
+
for (const turn of turns) {
|
|
4641
|
+
if (turn == null || typeof turn !== "object" || !("text" in turn) || typeof turn.text !== "string") {
|
|
4642
|
+
break;
|
|
4643
|
+
}
|
|
4644
|
+
turnTexts.push(turn.text);
|
|
4645
|
+
}
|
|
4646
|
+
if (turnTexts.length === turns.length) {
|
|
4647
|
+
text = turnTexts.join("");
|
|
4648
|
+
}
|
|
4649
|
+
}
|
|
4650
|
+
const config = options && "multiSpeakerVoiceConfig" in options ? options.multiSpeakerVoiceConfig : void 0;
|
|
4651
|
+
const speakers = config != null && typeof config === "object" && "speakerVoiceConfigs" in config && Array.isArray(config.speakerVoiceConfigs) ? config.speakerVoiceConfigs : [];
|
|
4652
|
+
return {
|
|
4653
|
+
text,
|
|
4654
|
+
usesCustomVoice: (voice == null ? void 0 : voice.startsWith("voice_")) === true || (voice == null ? void 0 : voice.startsWith("voicekey_")) === true || speakers.some(
|
|
4655
|
+
(speaker) => speaker != null && typeof speaker === "object" && "voiceConfig" in speaker && speaker.voiceConfig != null && typeof speaker.voiceConfig === "object" && "voice" in speaker.voiceConfig
|
|
4656
|
+
)
|
|
4657
|
+
};
|
|
4658
|
+
}
|
|
4659
|
+
|
|
4569
4660
|
// src/google-speech-model-options.ts
|
|
4570
4661
|
import {
|
|
4571
4662
|
lazySchema as lazySchema17,
|
|
@@ -4576,15 +4667,34 @@ var prebuiltVoiceConfigSchema = z19.object({
|
|
|
4576
4667
|
voiceName: z19.string()
|
|
4577
4668
|
});
|
|
4578
4669
|
var voiceConfigSchema = z19.object({
|
|
4579
|
-
prebuiltVoiceConfig: prebuiltVoiceConfigSchema
|
|
4670
|
+
prebuiltVoiceConfig: prebuiltVoiceConfigSchema,
|
|
4671
|
+
voice: z19.never().optional()
|
|
4672
|
+
});
|
|
4673
|
+
var speechMetadataSchema = z19.object({
|
|
4674
|
+
speaker: z19.string().min(1).optional(),
|
|
4675
|
+
style: z19.string().optional()
|
|
4580
4676
|
});
|
|
4581
4677
|
var googleSpeechProviderOptionsSchema = lazySchema17(
|
|
4582
4678
|
() => zodSchema17(
|
|
4583
4679
|
z19.object({
|
|
4680
|
+
/** Turn-level directions for the top-level text, for Gemini 3.8 TTS. */
|
|
4681
|
+
speechMetadata: speechMetadataSchema.optional(),
|
|
4682
|
+
/**
|
|
4683
|
+
* Structured transcript for Gemini 3.8 TTS. Replaces the top-level text;
|
|
4684
|
+
* pass text: '' when using turns. Each multi-speaker turn must name a
|
|
4685
|
+
* configured speaker in speechMetadata. Per-turn styles override instructions.
|
|
4686
|
+
*/
|
|
4687
|
+
turns: z19.array(
|
|
4688
|
+
z19.object({
|
|
4689
|
+
text: z19.string(),
|
|
4690
|
+
speechMetadata: speechMetadataSchema.optional()
|
|
4691
|
+
})
|
|
4692
|
+
).min(1).optional(),
|
|
4584
4693
|
/**
|
|
4585
4694
|
* Multi-speaker configuration for dialogue audio. When provided, this
|
|
4586
4695
|
* overrides the top-level `voice`. The Gemini TTS API supports up to two
|
|
4587
|
-
* speakers
|
|
4696
|
+
* speakers. For Gemini 3.8, each turn's speechMetadata.speaker must match
|
|
4697
|
+
* a configured speaker; older models use speaker labels in the text.
|
|
4588
4698
|
*
|
|
4589
4699
|
* https://ai.google.dev/gemini-api/docs/speech-generation#multi-speaker
|
|
4590
4700
|
*/
|
|
@@ -4630,6 +4740,7 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4630
4740
|
language,
|
|
4631
4741
|
providerOptions
|
|
4632
4742
|
}) {
|
|
4743
|
+
var _a2;
|
|
4633
4744
|
const warnings = [];
|
|
4634
4745
|
const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
|
|
4635
4746
|
let googleOptions;
|
|
@@ -4650,10 +4761,22 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4650
4761
|
schema: googleSpeechProviderOptionsSchema
|
|
4651
4762
|
});
|
|
4652
4763
|
}
|
|
4764
|
+
const usesStructuredSpeech = !this.modelId.startsWith("gemini-2.5-") && !this.modelId.startsWith("gemini-3.1-");
|
|
4765
|
+
const input = getGoogleSpeechInput({
|
|
4766
|
+
text,
|
|
4767
|
+
voice,
|
|
4768
|
+
providerOptions: { google: googleOptions }
|
|
4769
|
+
});
|
|
4770
|
+
if (input.usesCustomVoice) {
|
|
4771
|
+
throw new InvalidArgumentError2({
|
|
4772
|
+
argument: "voice",
|
|
4773
|
+
message: "Custom voices are not supported. Use a prebuilt voice instead."
|
|
4774
|
+
});
|
|
4775
|
+
}
|
|
4653
4776
|
const multiSpeakerVoiceConfig = googleOptions == null ? void 0 : googleOptions.multiSpeakerVoiceConfig;
|
|
4654
4777
|
const speechConfig = multiSpeakerVoiceConfig ? { multiSpeakerVoiceConfig } : { voiceConfig: { prebuiltVoiceConfig: { voiceName: voice } } };
|
|
4655
4778
|
let promptText = text;
|
|
4656
|
-
if (instructions != null) {
|
|
4779
|
+
if (instructions != null && !usesStructuredSpeech) {
|
|
4657
4780
|
if (multiSpeakerVoiceConfig) {
|
|
4658
4781
|
warnings.push({
|
|
4659
4782
|
type: "unsupported",
|
|
@@ -4664,6 +4787,52 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4664
4787
|
promptText = `${instructions}: ${text}`;
|
|
4665
4788
|
}
|
|
4666
4789
|
}
|
|
4790
|
+
let parts = [{ text: promptText }];
|
|
4791
|
+
if (usesStructuredSpeech) {
|
|
4792
|
+
if ((googleOptions == null ? void 0 : googleOptions.turns) && googleOptions.speechMetadata) {
|
|
4793
|
+
throw new InvalidArgumentError2({
|
|
4794
|
+
argument: "providerOptions",
|
|
4795
|
+
message: "Set speechMetadata on each turn when using turns."
|
|
4796
|
+
});
|
|
4797
|
+
}
|
|
4798
|
+
if ((googleOptions == null ? void 0 : googleOptions.turns) && text !== "") {
|
|
4799
|
+
warnings.push({
|
|
4800
|
+
type: "unsupported",
|
|
4801
|
+
feature: "text",
|
|
4802
|
+
details: "Google TTS turns replace the top-level text."
|
|
4803
|
+
});
|
|
4804
|
+
}
|
|
4805
|
+
parts = ((_a2 = googleOptions == null ? void 0 : googleOptions.turns) != null ? _a2 : [
|
|
4806
|
+
{ text, speechMetadata: googleOptions == null ? void 0 : googleOptions.speechMetadata }
|
|
4807
|
+
]).map((part) => {
|
|
4808
|
+
var _a3, _b, _c;
|
|
4809
|
+
const style = (_b = (_a3 = part.speechMetadata) == null ? void 0 : _a3.style) != null ? _b : instructions;
|
|
4810
|
+
const speaker = (_c = part.speechMetadata) == null ? void 0 : _c.speaker;
|
|
4811
|
+
if (multiSpeakerVoiceConfig && !multiSpeakerVoiceConfig.speakerVoiceConfigs.some(
|
|
4812
|
+
(config) => config.speaker === speaker
|
|
4813
|
+
)) {
|
|
4814
|
+
throw new InvalidArgumentError2({
|
|
4815
|
+
argument: "speechMetadata.speaker",
|
|
4816
|
+
message: "Every multi-speaker turn must specify a speechMetadata.speaker matching a configured speaker."
|
|
4817
|
+
});
|
|
4818
|
+
}
|
|
4819
|
+
return {
|
|
4820
|
+
text: part.text,
|
|
4821
|
+
...style != null || speaker != null ? { speechMetadata: { style, speaker } } : {}
|
|
4822
|
+
};
|
|
4823
|
+
});
|
|
4824
|
+
} else if ((googleOptions == null ? void 0 : googleOptions.turns) || (googleOptions == null ? void 0 : googleOptions.speechMetadata)) {
|
|
4825
|
+
throw new InvalidArgumentError2({
|
|
4826
|
+
argument: "providerOptions",
|
|
4827
|
+
message: "Structured speech metadata and turns require Gemini 3.8 TTS."
|
|
4828
|
+
});
|
|
4829
|
+
}
|
|
4830
|
+
if (input.text.length === 0) {
|
|
4831
|
+
throw new InvalidArgumentError2({
|
|
4832
|
+
argument: "text",
|
|
4833
|
+
message: "Speech input must contain a non-empty transcript."
|
|
4834
|
+
});
|
|
4835
|
+
}
|
|
4667
4836
|
if (speed != null) {
|
|
4668
4837
|
warnings.push({
|
|
4669
4838
|
type: "unsupported",
|
|
@@ -4678,10 +4847,20 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4678
4847
|
details: "Google Gemini TTS models do not support the `language` option. Language is detected automatically from the input text."
|
|
4679
4848
|
});
|
|
4680
4849
|
}
|
|
4850
|
+
const formats = usesStructuredSpeech ? {
|
|
4851
|
+
wav: "AUDIO_WAV",
|
|
4852
|
+
"audio/wav": "AUDIO_WAV",
|
|
4853
|
+
pcm: "AUDIO_L16",
|
|
4854
|
+
"audio/l16": "AUDIO_L16",
|
|
4855
|
+
mulaw: "AUDIO_MULAW",
|
|
4856
|
+
"audio/mulaw": "AUDIO_MULAW",
|
|
4857
|
+
alaw: "AUDIO_ALAW",
|
|
4858
|
+
"audio/alaw": "AUDIO_ALAW"
|
|
4859
|
+
} : { wav: "AUDIO_WAV", pcm: "AUDIO_L16" };
|
|
4681
4860
|
let resolvedOutputFormat = "wav";
|
|
4682
|
-
if (outputFormat
|
|
4683
|
-
resolvedOutputFormat =
|
|
4684
|
-
} else if (outputFormat != null
|
|
4861
|
+
if (outputFormat != null && Object.prototype.hasOwnProperty.call(formats, outputFormat)) {
|
|
4862
|
+
resolvedOutputFormat = outputFormat;
|
|
4863
|
+
} else if (outputFormat != null) {
|
|
4685
4864
|
warnings.push({
|
|
4686
4865
|
type: "unsupported",
|
|
4687
4866
|
feature: "outputFormat",
|
|
@@ -4689,18 +4868,28 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4689
4868
|
});
|
|
4690
4869
|
}
|
|
4691
4870
|
const requestBody = {
|
|
4692
|
-
contents: [{ role: "user", parts
|
|
4871
|
+
contents: [{ role: "user", parts }],
|
|
4693
4872
|
generationConfig: {
|
|
4694
4873
|
responseModalities: ["AUDIO"],
|
|
4695
|
-
speechConfig
|
|
4874
|
+
speechConfig,
|
|
4875
|
+
...usesStructuredSpeech && outputFormat != null ? {
|
|
4876
|
+
responseFormat: {
|
|
4877
|
+
audio: { mimeType: formats[resolvedOutputFormat] }
|
|
4878
|
+
}
|
|
4879
|
+
} : {}
|
|
4696
4880
|
}
|
|
4697
4881
|
};
|
|
4698
|
-
return {
|
|
4882
|
+
return {
|
|
4883
|
+
requestBody,
|
|
4884
|
+
warnings,
|
|
4885
|
+
outputFormat: formats[resolvedOutputFormat],
|
|
4886
|
+
usesStructuredSpeech
|
|
4887
|
+
};
|
|
4699
4888
|
}
|
|
4700
4889
|
async doGenerate(options) {
|
|
4701
|
-
var
|
|
4702
|
-
const currentDate = (_c = (_b = (
|
|
4703
|
-
const { requestBody, warnings, outputFormat } = await this.getArgs(options);
|
|
4890
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4891
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4892
|
+
const { requestBody, warnings, outputFormat, usesStructuredSpeech } = await this.getArgs(options);
|
|
4704
4893
|
const {
|
|
4705
4894
|
value: response,
|
|
4706
4895
|
responseHeaders,
|
|
@@ -4734,9 +4923,10 @@ var GoogleSpeechModel = class _GoogleSpeechModel {
|
|
|
4734
4923
|
}
|
|
4735
4924
|
}
|
|
4736
4925
|
const sampleRate = (_i = parseSampleRate(mimeType)) != null ? _i : DEFAULT_SAMPLE_RATE;
|
|
4737
|
-
const
|
|
4738
|
-
const
|
|
4739
|
-
|
|
4926
|
+
const bytes = base64Audio != null ? convertBase64ToUint8Array(base64Audio) : new Uint8Array(0);
|
|
4927
|
+
const isPcm = /^audio\/(?:l16|pcm)(?:;|$)/i.test(mimeType != null ? mimeType : "") || mimeType == null && !usesStructuredSpeech;
|
|
4928
|
+
const audio = outputFormat === "AUDIO_WAV" && isPcm && bytes.length > 0 ? addWavHeader(bytes, sampleRate) : bytes;
|
|
4929
|
+
if (outputFormat === "AUDIO_L16" && bytes.length > 0 && !usesStructuredSpeech) {
|
|
4740
4930
|
warnings.push({
|
|
4741
4931
|
type: "unsupported",
|
|
4742
4932
|
feature: "outputFormat",
|
|
@@ -4824,11 +5014,11 @@ import {
|
|
|
4824
5014
|
// src/interactions/convert-google-interactions-usage.ts
|
|
4825
5015
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
|
|
4826
5016
|
function convertGoogleInteractionsUsage(usage) {
|
|
4827
|
-
var
|
|
5017
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
4828
5018
|
if (usage == null) {
|
|
4829
5019
|
return createNullLanguageModelUsage2();
|
|
4830
5020
|
}
|
|
4831
|
-
const totalInput = (
|
|
5021
|
+
const totalInput = (_a2 = usage.total_input_tokens) != null ? _a2 : 0;
|
|
4832
5022
|
const totalOutput = (_b = usage.total_output_tokens) != null ? _b : 0;
|
|
4833
5023
|
const totalThought = (_c = usage.total_thought_tokens) != null ? _c : 0;
|
|
4834
5024
|
const totalCached = (_d = usage.total_cached_tokens) != null ? _d : 0;
|
|
@@ -4886,7 +5076,7 @@ function annotationToSource({
|
|
|
4886
5076
|
annotation,
|
|
4887
5077
|
generateId: generateId4
|
|
4888
5078
|
}) {
|
|
4889
|
-
var
|
|
5079
|
+
var _a2, _b, _c, _d, _e;
|
|
4890
5080
|
switch (annotation.type) {
|
|
4891
5081
|
case "url_citation": {
|
|
4892
5082
|
const urlCitation = annotation;
|
|
@@ -4903,7 +5093,7 @@ function annotationToSource({
|
|
|
4903
5093
|
}
|
|
4904
5094
|
case "file_citation": {
|
|
4905
5095
|
const fileCitation = annotation;
|
|
4906
|
-
const uri = (_b = (
|
|
5096
|
+
const uri = (_b = (_a2 = fileCitation.url) != null ? _a2 : fileCitation.document_uri) != null ? _b : fileCitation.file_name;
|
|
4907
5097
|
if (uri == null || uri.length === 0) return void 0;
|
|
4908
5098
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
4909
5099
|
return {
|
|
@@ -4946,11 +5136,11 @@ function builtinToolResultToSources({
|
|
|
4946
5136
|
block,
|
|
4947
5137
|
generateId: generateId4
|
|
4948
5138
|
}) {
|
|
4949
|
-
var
|
|
5139
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4950
5140
|
const sources = [];
|
|
4951
5141
|
switch (block.type) {
|
|
4952
5142
|
case "url_context_result": {
|
|
4953
|
-
const result = (
|
|
5143
|
+
const result = (_a2 = block.result) != null ? _a2 : [];
|
|
4954
5144
|
for (const entry of result) {
|
|
4955
5145
|
if ((entry == null ? void 0 : entry.url) == null || entry.url.length === 0) continue;
|
|
4956
5146
|
if (entry.status != null && entry.status !== "success") continue;
|
|
@@ -5033,14 +5223,14 @@ function annotationsToSources({
|
|
|
5033
5223
|
annotations,
|
|
5034
5224
|
generateId: generateId4
|
|
5035
5225
|
}) {
|
|
5036
|
-
var
|
|
5226
|
+
var _a2;
|
|
5037
5227
|
if (annotations == null) return [];
|
|
5038
5228
|
const seen = /* @__PURE__ */ new Set();
|
|
5039
5229
|
const sources = [];
|
|
5040
5230
|
for (const annotation of annotations) {
|
|
5041
5231
|
const source = annotationToSource({ annotation, generateId: generateId4 });
|
|
5042
5232
|
if (source == null) continue;
|
|
5043
|
-
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(
|
|
5233
|
+
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
5044
5234
|
if (seen.has(key)) continue;
|
|
5045
5235
|
seen.add(key);
|
|
5046
5236
|
sources.push(source);
|
|
@@ -5107,15 +5297,15 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5107
5297
|
const openBlocks = /* @__PURE__ */ new Map();
|
|
5108
5298
|
const emittedSourceKeys = /* @__PURE__ */ new Set();
|
|
5109
5299
|
function sourceKey(source) {
|
|
5110
|
-
var
|
|
5111
|
-
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(
|
|
5300
|
+
var _a2;
|
|
5301
|
+
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
5112
5302
|
}
|
|
5113
5303
|
return new TransformStream({
|
|
5114
5304
|
start(controller) {
|
|
5115
5305
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5116
5306
|
},
|
|
5117
5307
|
transform(chunk, controller) {
|
|
5118
|
-
var
|
|
5308
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
5119
5309
|
if (includeRawChunks) {
|
|
5120
5310
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
5121
5311
|
}
|
|
@@ -5154,7 +5344,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
5154
5344
|
const blockId = `${interactionId != null ? interactionId : "interaction"}:${index}`;
|
|
5155
5345
|
const stepType = step == null ? void 0 : step.type;
|
|
5156
5346
|
if (stepType === "model_output") {
|
|
5157
|
-
const initial = (
|
|
5347
|
+
const initial = (_a2 = step == null ? void 0 : step.content) == null ? void 0 : _a2[0];
|
|
5158
5348
|
if ((initial == null ? void 0 : initial.type) === "text") {
|
|
5159
5349
|
openBlocks.set(index, {
|
|
5160
5350
|
kind: "text",
|
|
@@ -5612,7 +5802,7 @@ function convertToGoogleInteractionsInput({
|
|
|
5612
5802
|
store,
|
|
5613
5803
|
mediaResolution
|
|
5614
5804
|
}) {
|
|
5615
|
-
var
|
|
5805
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
5616
5806
|
const warnings = [];
|
|
5617
5807
|
const incoherentCombo = previousInteractionId != null && store === false;
|
|
5618
5808
|
const shouldCompact = previousInteractionId != null && store !== false;
|
|
@@ -5669,7 +5859,7 @@ function convertToGoogleInteractionsInput({
|
|
|
5669
5859
|
pendingModelOutput.push({ type: "text", text: part.text });
|
|
5670
5860
|
} else if (part.type === "reasoning") {
|
|
5671
5861
|
flushModelOutput();
|
|
5672
|
-
const signature = (_b = (
|
|
5862
|
+
const signature = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.signature;
|
|
5673
5863
|
steps.push({
|
|
5674
5864
|
type: "thought",
|
|
5675
5865
|
...signature != null ? { signature } : {},
|
|
@@ -5834,8 +6024,8 @@ function getVideoProcessingField({
|
|
|
5834
6024
|
part,
|
|
5835
6025
|
warnings
|
|
5836
6026
|
}) {
|
|
5837
|
-
var
|
|
5838
|
-
const processing = (_b = (
|
|
6027
|
+
var _a2, _b;
|
|
6028
|
+
const processing = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.processing;
|
|
5839
6029
|
if (processing == null) {
|
|
5840
6030
|
return {};
|
|
5841
6031
|
}
|
|
@@ -5868,8 +6058,8 @@ function compactPromptForPreviousInteraction({
|
|
|
5868
6058
|
for (const message of prompt) {
|
|
5869
6059
|
if (message.role === "assistant") {
|
|
5870
6060
|
const matchesLinkedInteraction = message.content.some((part) => {
|
|
5871
|
-
var
|
|
5872
|
-
const partInteractionId = (_b = (
|
|
6061
|
+
var _a2, _b;
|
|
6062
|
+
const partInteractionId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.interactionId;
|
|
5873
6063
|
return partInteractionId === previousInteractionId;
|
|
5874
6064
|
});
|
|
5875
6065
|
if (matchesLinkedInteraction) {
|
|
@@ -5921,7 +6111,7 @@ function convertToolResultPart({
|
|
|
5921
6111
|
signature,
|
|
5922
6112
|
warnings
|
|
5923
6113
|
}) {
|
|
5924
|
-
var
|
|
6114
|
+
var _a2;
|
|
5925
6115
|
const base = {
|
|
5926
6116
|
type: "function_result",
|
|
5927
6117
|
call_id: toolCallId,
|
|
@@ -5941,7 +6131,7 @@ function convertToolResultPart({
|
|
|
5941
6131
|
return {
|
|
5942
6132
|
...base,
|
|
5943
6133
|
is_error: true,
|
|
5944
|
-
result: (
|
|
6134
|
+
result: (_a2 = output.reason) != null ? _a2 : "Tool execution denied by user."
|
|
5945
6135
|
};
|
|
5946
6136
|
case "content": {
|
|
5947
6137
|
const blocks = [];
|
|
@@ -6632,7 +6822,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
6632
6822
|
generateId: generateId4,
|
|
6633
6823
|
interactionId
|
|
6634
6824
|
}) {
|
|
6635
|
-
var
|
|
6825
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
6636
6826
|
const content = [];
|
|
6637
6827
|
let hasFunctionCall = false;
|
|
6638
6828
|
if (steps == null) {
|
|
@@ -6647,7 +6837,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
6647
6837
|
break;
|
|
6648
6838
|
}
|
|
6649
6839
|
case "model_output": {
|
|
6650
|
-
const blocks = (
|
|
6840
|
+
const blocks = (_a2 = step.content) != null ? _a2 : [];
|
|
6651
6841
|
for (const block of blocks) {
|
|
6652
6842
|
if (block == null || typeof block !== "object") continue;
|
|
6653
6843
|
const blockType = block.type;
|
|
@@ -6910,7 +7100,7 @@ function prepareGoogleInteractionsTools({
|
|
|
6910
7100
|
tools,
|
|
6911
7101
|
toolChoice
|
|
6912
7102
|
}) {
|
|
6913
|
-
var
|
|
7103
|
+
var _a2, _b, _c, _d;
|
|
6914
7104
|
const toolWarnings = [];
|
|
6915
7105
|
const normalized = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
6916
7106
|
if (normalized == null) {
|
|
@@ -6922,7 +7112,7 @@ function prepareGoogleInteractionsTools({
|
|
|
6922
7112
|
interactionsTools.push({
|
|
6923
7113
|
type: "function",
|
|
6924
7114
|
name: tool.name,
|
|
6925
|
-
description: (
|
|
7115
|
+
description: (_a2 = tool.description) != null ? _a2 : "",
|
|
6926
7116
|
parameters: tool.inputSchema
|
|
6927
7117
|
});
|
|
6928
7118
|
continue;
|
|
@@ -7232,7 +7422,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7232
7422
|
}) {
|
|
7233
7423
|
return new ReadableStream({
|
|
7234
7424
|
start(controller) {
|
|
7235
|
-
var
|
|
7425
|
+
var _a2, _b, _c;
|
|
7236
7426
|
controller.enqueue({ type: "stream-start", warnings });
|
|
7237
7427
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
7238
7428
|
let timestamp;
|
|
@@ -7246,7 +7436,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
7246
7436
|
controller.enqueue({
|
|
7247
7437
|
type: "response-metadata",
|
|
7248
7438
|
...interactionId != null ? { id: interactionId } : {},
|
|
7249
|
-
modelId: (
|
|
7439
|
+
modelId: (_a2 = response.model) != null ? _a2 : void 0,
|
|
7250
7440
|
...timestamp ? { timestamp } : {}
|
|
7251
7441
|
});
|
|
7252
7442
|
if (includeRawChunks) {
|
|
@@ -7413,7 +7603,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7413
7603
|
};
|
|
7414
7604
|
}
|
|
7415
7605
|
async getArgs(options) {
|
|
7416
|
-
var
|
|
7606
|
+
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
7607
|
const warnings = [];
|
|
7418
7608
|
const googleOptions = await parseProviderOptions8({
|
|
7419
7609
|
provider: "google",
|
|
@@ -7448,7 +7638,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7448
7638
|
warnings.push(...prepared.toolWarnings);
|
|
7449
7639
|
}
|
|
7450
7640
|
const responseFormatEntries = [];
|
|
7451
|
-
if (((
|
|
7641
|
+
if (((_a2 = options.responseFormat) == null ? void 0 : _a2.type) === "json") {
|
|
7452
7642
|
if (isAgent) {
|
|
7453
7643
|
warnings.push({
|
|
7454
7644
|
type: "other",
|
|
@@ -7609,7 +7799,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7609
7799
|
} else {
|
|
7610
7800
|
const environmentOptions = googleOptions.environment;
|
|
7611
7801
|
const sources = (_A = environmentOptions.sources) == null ? void 0 : _A.map((source) => {
|
|
7612
|
-
var
|
|
7802
|
+
var _a3;
|
|
7613
7803
|
if (source.type === "inline") {
|
|
7614
7804
|
return {
|
|
7615
7805
|
type: "inline",
|
|
@@ -7620,7 +7810,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7620
7810
|
return pruneUndefined({
|
|
7621
7811
|
type: source.type,
|
|
7622
7812
|
source: source.source,
|
|
7623
|
-
target: (
|
|
7813
|
+
target: (_a3 = source.target) != null ? _a3 : void 0
|
|
7624
7814
|
});
|
|
7625
7815
|
});
|
|
7626
7816
|
let network;
|
|
@@ -7630,10 +7820,10 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7630
7820
|
network = {
|
|
7631
7821
|
allowlist: environmentOptions.network.allowlist.map(
|
|
7632
7822
|
(entry) => {
|
|
7633
|
-
var
|
|
7823
|
+
var _a3;
|
|
7634
7824
|
return pruneUndefined({
|
|
7635
7825
|
domain: entry.domain,
|
|
7636
|
-
transform: (
|
|
7826
|
+
transform: (_a3 = entry.transform) != null ? _a3 : void 0
|
|
7637
7827
|
});
|
|
7638
7828
|
}
|
|
7639
7829
|
)
|
|
@@ -7670,7 +7860,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7670
7860
|
};
|
|
7671
7861
|
}
|
|
7672
7862
|
async doGenerate(options) {
|
|
7673
|
-
var
|
|
7863
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
7674
7864
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
7675
7865
|
const url = `${this.config.baseURL}/interactions`;
|
|
7676
7866
|
const mergedHeaders = combineHeaders8(
|
|
@@ -7704,7 +7894,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7704
7894
|
});
|
|
7705
7895
|
response = polled.response;
|
|
7706
7896
|
rawResponse = polled.rawResponse;
|
|
7707
|
-
responseHeaders = (
|
|
7897
|
+
responseHeaders = (_a2 = polled.responseHeaders) != null ? _a2 : responseHeaders;
|
|
7708
7898
|
}
|
|
7709
7899
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
7710
7900
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
@@ -7754,7 +7944,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7754
7944
|
};
|
|
7755
7945
|
}
|
|
7756
7946
|
async doStream(options) {
|
|
7757
|
-
var
|
|
7947
|
+
var _a2;
|
|
7758
7948
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
7759
7949
|
const url = `${this.config.baseURL}/interactions`;
|
|
7760
7950
|
const mergedHeaders = combineHeaders8(
|
|
@@ -7786,7 +7976,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7786
7976
|
const headerServiceTier = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"];
|
|
7787
7977
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
7788
7978
|
warnings,
|
|
7789
|
-
generateId: (
|
|
7979
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : defaultGenerateId2,
|
|
7790
7980
|
includeRawChunks: options.includeRawChunks,
|
|
7791
7981
|
serviceTier: headerServiceTier
|
|
7792
7982
|
});
|
|
@@ -7822,7 +8012,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7822
8012
|
options,
|
|
7823
8013
|
pollingTimeoutMs
|
|
7824
8014
|
}) {
|
|
7825
|
-
var
|
|
8015
|
+
var _a2, _b;
|
|
7826
8016
|
const postResult = await postJsonToApi6({
|
|
7827
8017
|
url,
|
|
7828
8018
|
headers: mergedHeaders,
|
|
@@ -7846,7 +8036,7 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
|
|
|
7846
8036
|
const synthesized = synthesizeGoogleInteractionsAgentStream({
|
|
7847
8037
|
response: postResponse,
|
|
7848
8038
|
warnings,
|
|
7849
|
-
generateId: (
|
|
8039
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : defaultGenerateId2,
|
|
7850
8040
|
includeRawChunks: options.includeRawChunks,
|
|
7851
8041
|
headerServiceTier
|
|
7852
8042
|
});
|
|
@@ -7938,17 +8128,17 @@ var GoogleRealtimeEventMapper = class {
|
|
|
7938
8128
|
this.turnClosed = false;
|
|
7939
8129
|
}
|
|
7940
8130
|
parseServerEvent(raw) {
|
|
7941
|
-
var
|
|
8131
|
+
var _a2, _b;
|
|
7942
8132
|
const data = raw;
|
|
7943
8133
|
if (data.setupComplete != null) {
|
|
7944
8134
|
return { type: "session-created", raw };
|
|
7945
8135
|
}
|
|
7946
8136
|
if (data.toolCall != null) {
|
|
7947
8137
|
this.beginTurnIfClosed();
|
|
7948
|
-
const functionCalls = (
|
|
8138
|
+
const functionCalls = (_a2 = data.toolCall.functionCalls) != null ? _a2 : [];
|
|
7949
8139
|
return functionCalls.flatMap((functionCall) => {
|
|
7950
|
-
var
|
|
7951
|
-
const args = JSON.stringify((
|
|
8140
|
+
var _a3;
|
|
8141
|
+
const args = JSON.stringify((_a3 = functionCall.args) != null ? _a3 : {});
|
|
7952
8142
|
return [
|
|
7953
8143
|
{
|
|
7954
8144
|
type: "function-call-arguments-delta",
|
|
@@ -8005,7 +8195,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8005
8195
|
return { type: "custom", rawType: String(Object.keys(data)[0]), raw };
|
|
8006
8196
|
}
|
|
8007
8197
|
parseServerContent(serverContent, raw) {
|
|
8008
|
-
var
|
|
8198
|
+
var _a2, _b, _c, _d;
|
|
8009
8199
|
const events = [];
|
|
8010
8200
|
if (serverContent.interrupted) {
|
|
8011
8201
|
events.push({
|
|
@@ -8013,7 +8203,7 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8013
8203
|
raw
|
|
8014
8204
|
});
|
|
8015
8205
|
}
|
|
8016
|
-
if ((
|
|
8206
|
+
if ((_a2 = serverContent.modelTurn) == null ? void 0 : _a2.parts) {
|
|
8017
8207
|
this.beginTurnIfClosed();
|
|
8018
8208
|
for (const part of serverContent.modelTurn.parts) {
|
|
8019
8209
|
if ((_b = part.inlineData) == null ? void 0 : _b.data) {
|
|
@@ -8116,10 +8306,10 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8116
8306
|
return events.length === 1 ? events[0] : events;
|
|
8117
8307
|
}
|
|
8118
8308
|
serializeClientEvent(event, modelId) {
|
|
8119
|
-
var
|
|
8309
|
+
var _a2;
|
|
8120
8310
|
switch (event.type) {
|
|
8121
8311
|
case "session-update":
|
|
8122
|
-
if (((
|
|
8312
|
+
if (((_a2 = event.config.inputAudioFormat) == null ? void 0 : _a2.rate) != null) {
|
|
8123
8313
|
this.inputAudioRate = event.config.inputAudioFormat.rate;
|
|
8124
8314
|
}
|
|
8125
8315
|
return {
|
|
@@ -8188,16 +8378,16 @@ async function serializeFunctionCallOutput(item) {
|
|
|
8188
8378
|
};
|
|
8189
8379
|
}
|
|
8190
8380
|
function isThinkingLiveModel(modelId) {
|
|
8191
|
-
var
|
|
8192
|
-
const modelName = (_b = (
|
|
8381
|
+
var _a2, _b;
|
|
8382
|
+
const modelName = (_b = (_a2 = modelId.split("/").at(-1)) == null ? void 0 : _a2.toLowerCase()) != null ? _b : "";
|
|
8193
8383
|
return /^gemini-\d+\.\d+-live\b.*thinking/.test(modelName);
|
|
8194
8384
|
}
|
|
8195
8385
|
function buildGoogleSessionConfig(config, modelId) {
|
|
8196
|
-
var
|
|
8386
|
+
var _a2, _b;
|
|
8197
8387
|
const setup = {
|
|
8198
8388
|
model: getModelPath(modelId)
|
|
8199
8389
|
};
|
|
8200
|
-
const { google: google2, ...restProviderOptions } = (
|
|
8390
|
+
const { google: google2, ...restProviderOptions } = (_a2 = config == null ? void 0 : config.providerOptions) != null ? _a2 : {};
|
|
8201
8391
|
const googleOptions = isRecord(google2) ? google2 : void 0;
|
|
8202
8392
|
const generationConfig = {};
|
|
8203
8393
|
if ((config == null ? void 0 : config.outputModalities) != null) {
|
|
@@ -8281,8 +8471,8 @@ var GoogleRealtimeModel = class {
|
|
|
8281
8471
|
this.config = config;
|
|
8282
8472
|
}
|
|
8283
8473
|
async doCreateClientSecret(options) {
|
|
8284
|
-
var
|
|
8285
|
-
const fetchFn = (
|
|
8474
|
+
var _a2, _b;
|
|
8475
|
+
const fetchFn = (_a2 = this.config.fetch) != null ? _a2 : fetch;
|
|
8286
8476
|
const headers = this.config.headers();
|
|
8287
8477
|
const apiKey = headers["x-goog-api-key"];
|
|
8288
8478
|
if (!apiKey) {
|
|
@@ -8347,7 +8537,7 @@ var GoogleRealtimeModel = class {
|
|
|
8347
8537
|
|
|
8348
8538
|
// src/transcription/google-transcription-model.ts
|
|
8349
8539
|
import {
|
|
8350
|
-
InvalidArgumentError as
|
|
8540
|
+
InvalidArgumentError as InvalidArgumentError3
|
|
8351
8541
|
} from "@ai-sdk/provider";
|
|
8352
8542
|
import {
|
|
8353
8543
|
combineHeaders as combineHeaders9,
|
|
@@ -8435,14 +8625,14 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8435
8625
|
});
|
|
8436
8626
|
}
|
|
8437
8627
|
async doGenerate(options) {
|
|
8438
|
-
var
|
|
8628
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
8439
8629
|
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
8440
|
-
throw new
|
|
8630
|
+
throw new InvalidArgumentError3({
|
|
8441
8631
|
argument: "modelId",
|
|
8442
8632
|
message: `Model '${this.modelId}' only supports streaming transcription. Use experimental_streamTranscribe, or a unary model such as 'gemini-3.5-transcribe'.`
|
|
8443
8633
|
});
|
|
8444
8634
|
}
|
|
8445
|
-
const currentDate = (_c = (_b = (
|
|
8635
|
+
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
8636
|
const warnings = [];
|
|
8447
8637
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
8448
8638
|
const transcriptionConfig = buildTranscriptionConfig(googleOptions);
|
|
@@ -8512,14 +8702,14 @@ var GoogleTranscriptionModel = class _GoogleTranscriptionModel {
|
|
|
8512
8702
|
};
|
|
8513
8703
|
}
|
|
8514
8704
|
async doStream(options) {
|
|
8515
|
-
var
|
|
8705
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
8516
8706
|
if (!isLiveTranscriptionModelId(this.modelId)) {
|
|
8517
|
-
throw new
|
|
8707
|
+
throw new InvalidArgumentError3({
|
|
8518
8708
|
argument: "modelId",
|
|
8519
8709
|
message: `Model '${this.modelId}' does not support streaming transcription. Use a live model such as 'gemini-3.5-transcribe-live'.`
|
|
8520
8710
|
});
|
|
8521
8711
|
}
|
|
8522
|
-
const currentDate = (_c = (_b = (
|
|
8712
|
+
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
8713
|
const warnings = [];
|
|
8524
8714
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
8525
8715
|
validateLiveInputAudioFormat(options.inputAudioFormat);
|
|
@@ -8704,7 +8894,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8704
8894
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
8705
8895
|
},
|
|
8706
8896
|
onMessageText: async (text) => {
|
|
8707
|
-
var
|
|
8897
|
+
var _a2, _b;
|
|
8708
8898
|
if (finished) return;
|
|
8709
8899
|
const parsed = await safeParseJSON2({ text });
|
|
8710
8900
|
if (!parsed.success) return;
|
|
@@ -8720,7 +8910,7 @@ function createGoogleLiveTranscriptionStream({
|
|
|
8720
8910
|
}
|
|
8721
8911
|
if (message.error != null) {
|
|
8722
8912
|
finishWithError(
|
|
8723
|
-
new Error((
|
|
8913
|
+
new Error((_a2 = message.error.message) != null ? _a2 : "Google Live API error")
|
|
8724
8914
|
);
|
|
8725
8915
|
return;
|
|
8726
8916
|
}
|
|
@@ -8807,7 +8997,7 @@ function buildAudioTranscriptionConfig(options) {
|
|
|
8807
8997
|
return Object.keys(config).length > 0 ? config : void 0;
|
|
8808
8998
|
}
|
|
8809
8999
|
function buildTranscriptionConfig(options) {
|
|
8810
|
-
var
|
|
9000
|
+
var _a2;
|
|
8811
9001
|
if (options == null) return void 0;
|
|
8812
9002
|
const config = {};
|
|
8813
9003
|
if (options.languageCodes != null) {
|
|
@@ -8818,7 +9008,7 @@ function buildTranscriptionConfig(options) {
|
|
|
8818
9008
|
}
|
|
8819
9009
|
if (options.mode != null || options.diarization === true || options.wordTimestamp === true) {
|
|
8820
9010
|
config.mode = {
|
|
8821
|
-
type: ((
|
|
9011
|
+
type: ((_a2 = options.mode) != null ? _a2 : "VERBATIM").toLowerCase(),
|
|
8822
9012
|
...options.diarization === true ? { diarization_mode: "speaker" } : {},
|
|
8823
9013
|
...options.wordTimestamp === true ? { timestamp_granularities: ["word"] } : {}
|
|
8824
9014
|
};
|
|
@@ -8832,7 +9022,7 @@ function parseOffsetSeconds(offset) {
|
|
|
8832
9022
|
}
|
|
8833
9023
|
function validateLiveInputAudioFormat(inputAudioFormat) {
|
|
8834
9024
|
if (inputAudioFormat.type !== "audio/pcm" || inputAudioFormat.rate != null && inputAudioFormat.rate !== 16e3) {
|
|
8835
|
-
throw new
|
|
9025
|
+
throw new InvalidArgumentError3({
|
|
8836
9026
|
argument: "inputAudioFormat",
|
|
8837
9027
|
message: "The Gemini Live transcription API only supports 16kHz 16-bit PCM input audio."
|
|
8838
9028
|
});
|
|
@@ -8864,7 +9054,7 @@ var googleInteractionsTranscriptionResponseSchema = z23.object({
|
|
|
8864
9054
|
|
|
8865
9055
|
// src/speech-translation/google-speech-translation-model.ts
|
|
8866
9056
|
import {
|
|
8867
|
-
InvalidArgumentError as
|
|
9057
|
+
InvalidArgumentError as InvalidArgumentError4
|
|
8868
9058
|
} from "@ai-sdk/provider";
|
|
8869
9059
|
import {
|
|
8870
9060
|
connectToWebSocket as connectToWebSocket2,
|
|
@@ -8926,14 +9116,14 @@ var GoogleSpeechTranslationModel = class _GoogleSpeechTranslationModel {
|
|
|
8926
9116
|
return this.config.provider;
|
|
8927
9117
|
}
|
|
8928
9118
|
async doStream(options) {
|
|
8929
|
-
var
|
|
9119
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
8930
9120
|
if (options.targetLanguage == null) {
|
|
8931
|
-
throw new
|
|
9121
|
+
throw new InvalidArgumentError4({
|
|
8932
9122
|
argument: "targetLanguage",
|
|
8933
9123
|
message: `targetLanguage is required for translation model '${this.modelId}'.`
|
|
8934
9124
|
});
|
|
8935
9125
|
}
|
|
8936
|
-
const currentDate = (_c = (_b = (
|
|
9126
|
+
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
9127
|
const googleOptions = await parseProviderOptions10({
|
|
8938
9128
|
provider: "google",
|
|
8939
9129
|
providerOptions: options.providerOptions,
|
|
@@ -9149,7 +9339,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9149
9339
|
void setupComplete.then(() => finished ? void 0 : sendAudio(socket)).catch(finishWithError);
|
|
9150
9340
|
},
|
|
9151
9341
|
onMessageText: async (text) => {
|
|
9152
|
-
var
|
|
9342
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
9153
9343
|
if (finished) return;
|
|
9154
9344
|
const parsed = await safeParseJSON3({ text });
|
|
9155
9345
|
if (!parsed.success) return;
|
|
@@ -9165,7 +9355,7 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9165
9355
|
}
|
|
9166
9356
|
if (message.error != null) {
|
|
9167
9357
|
finishWithError(
|
|
9168
|
-
new Error((
|
|
9358
|
+
new Error((_a2 = message.error.message) != null ? _a2 : "Google Live API error")
|
|
9169
9359
|
);
|
|
9170
9360
|
return;
|
|
9171
9361
|
}
|
|
@@ -9247,10 +9437,10 @@ function createGoogleLiveSpeechTranslationStream({
|
|
|
9247
9437
|
});
|
|
9248
9438
|
}
|
|
9249
9439
|
function accumulateGoogleLiveUsage(usage, usageMetadata) {
|
|
9250
|
-
var
|
|
9440
|
+
var _a2, _b;
|
|
9251
9441
|
let inputAudioTokens = usage == null ? void 0 : usage.inputAudioTokens;
|
|
9252
9442
|
let outputAudioTokens = usage == null ? void 0 : usage.outputAudioTokens;
|
|
9253
|
-
for (const detail of (
|
|
9443
|
+
for (const detail of (_a2 = usageMetadata.promptTokensDetails) != null ? _a2 : []) {
|
|
9254
9444
|
if (detail.modality === "AUDIO" && detail.tokenCount != null) {
|
|
9255
9445
|
inputAudioTokens = (inputAudioTokens != null ? inputAudioTokens : 0) + detail.tokenCount;
|
|
9256
9446
|
}
|
|
@@ -9308,7 +9498,7 @@ function buildGoogleLiveSpeechTranslationSetup({
|
|
|
9308
9498
|
}
|
|
9309
9499
|
function validateGoogleSpeechTranslationInputAudioFormat(inputAudioFormat) {
|
|
9310
9500
|
if (inputAudioFormat.type !== "audio/pcm" || inputAudioFormat.rate != null && inputAudioFormat.rate !== 16e3) {
|
|
9311
|
-
throw new
|
|
9501
|
+
throw new InvalidArgumentError4({
|
|
9312
9502
|
argument: "inputAudioFormat",
|
|
9313
9503
|
message: "The Gemini Live translation API only supports 16kHz 16-bit PCM input audio."
|
|
9314
9504
|
});
|
|
@@ -9347,8 +9537,8 @@ function supportsExternalFileUrls(modelId) {
|
|
|
9347
9537
|
return /(^|\/)gemini-/.test(modelId) && !/(^|\/)gemini-2\.0/.test(modelId);
|
|
9348
9538
|
}
|
|
9349
9539
|
function createGoogle(options = {}) {
|
|
9350
|
-
var
|
|
9351
|
-
const baseURL = (
|
|
9540
|
+
var _a2, _b, _c;
|
|
9541
|
+
const baseURL = (_a2 = withoutTrailingSlash(options.baseURL)) != null ? _a2 : DEFAULT_BASE_URL;
|
|
9352
9542
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
9353
9543
|
const getHeaders = () => withUserAgentSuffix2(
|
|
9354
9544
|
{
|
|
@@ -9414,13 +9604,13 @@ function createGoogle(options = {}) {
|
|
|
9414
9604
|
fetch: options.fetch
|
|
9415
9605
|
});
|
|
9416
9606
|
const createVideoModel = (modelId) => {
|
|
9417
|
-
var
|
|
9607
|
+
var _a3;
|
|
9418
9608
|
return new GoogleVideoModel(modelId, {
|
|
9419
9609
|
provider: providerName,
|
|
9420
9610
|
baseURL,
|
|
9421
9611
|
headers: getHeaders,
|
|
9422
9612
|
fetch: options.fetch,
|
|
9423
|
-
generateId: (
|
|
9613
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : generateId3
|
|
9424
9614
|
});
|
|
9425
9615
|
};
|
|
9426
9616
|
const createRealtimeModel = (modelId) => new GoogleRealtimeModel(modelId, {
|
|
@@ -9466,14 +9656,14 @@ function createGoogle(options = {}) {
|
|
|
9466
9656
|
}
|
|
9467
9657
|
);
|
|
9468
9658
|
const createInteractionsModel = (modelIdOrAgent) => {
|
|
9469
|
-
var
|
|
9659
|
+
var _a3;
|
|
9470
9660
|
return new GoogleInteractionsLanguageModel(
|
|
9471
9661
|
modelIdOrAgent,
|
|
9472
9662
|
{
|
|
9473
9663
|
provider: `${providerName}.interactions`,
|
|
9474
9664
|
baseURL,
|
|
9475
9665
|
headers: getHeaders,
|
|
9476
|
-
generateId: (
|
|
9666
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : generateId3,
|
|
9477
9667
|
fetch: options.fetch
|
|
9478
9668
|
}
|
|
9479
9669
|
);
|